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,200 @@
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
+ * Escapes a string for use within HTML.
117
+ *
118
+ */
119
+
120
+const escape_html = str => {
121
+  return (str + '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
122
+};
123
+/**
124
+ * Prevent default
125
+ *
126
+ */
127
+
128
+const preventDefault = (evt, stop = false) => {
129
+  if (evt) {
130
+    evt.preventDefault();
131
+
132
+    if (stop) {
133
+      evt.stopPropagation();
134
+    }
135
+  }
136
+};
137
+/**
138
+ * Add event helper
139
+ *
140
+ */
141
+
142
+const addEvent = (target, type, callback, options) => {
143
+  target.addEventListener(type, callback, options);
144
+};
145
+
146
+/**
147
+ * Plugin: "remove_button" (Tom Select)
148
+ * Copyright (c) contributors
149
+ *
150
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
151
+ * file except in compliance with the License. You may obtain a copy of the License at:
152
+ * http://www.apache.org/licenses/LICENSE-2.0
153
+ *
154
+ * Unless required by applicable law or agreed to in writing, software distributed under
155
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
156
+ * ANY KIND, either express or implied. See the License for the specific language
157
+ * governing permissions and limitations under the License.
158
+ *
159
+ */
160
+function plugin (userOptions) {
161
+  const options = Object.assign({
162
+    label: '&times;',
163
+    title: 'Remove',
164
+    className: 'remove',
165
+    append: true
166
+  }, userOptions); //options.className = 'remove-single';
167
+
168
+  var self = this; // override the render method to add remove button to each item
169
+
170
+  if (!options.append) {
171
+    return;
172
+  }
173
+
174
+  var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>';
175
+  self.hook('after', 'setupTemplates', () => {
176
+    var orig_render_item = self.settings.render.item;
177
+
178
+    self.settings.render.item = (data, escape) => {
179
+      var item = getDom(orig_render_item.call(self, data, escape));
180
+      var close_button = getDom(html);
181
+      item.appendChild(close_button);
182
+      addEvent(close_button, 'mousedown', evt => {
183
+        preventDefault(evt, true);
184
+      });
185
+      addEvent(close_button, 'click', evt => {
186
+        // propagating will trigger the dropdown to show for single mode
187
+        preventDefault(evt, true);
188
+        if (self.isLocked) return;
189
+        if (!self.shouldDelete([item], evt)) return;
190
+        self.removeItem(item);
191
+        self.refreshOptions(false);
192
+        self.inputState();
193
+      });
194
+      return item;
195
+    };
196
+  });
197
+}
198
+
199
+export { plugin as default };
200
+//# sourceMappingURL=plugin.js.map