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,215 @@
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
+ * Iterates over arrays and hashes.
70
+ *
71
+ * ```
72
+ * iterate(this.items, function(item, id) {
73
+ *    // invoked for each item
74
+ * });
75
+ * ```
76
+ *
77
+ */
78
+
79
+const iterate = (object, callback) => {
80
+  if (Array.isArray(object)) {
81
+    object.forEach(callback);
82
+  } else {
83
+    for (var key in object) {
84
+      if (object.hasOwnProperty(key)) {
85
+        callback(object[key], key);
86
+      }
87
+    }
88
+  }
89
+};
90
+
91
+/**
92
+ * Remove css classes
93
+ *
94
+ */
95
+
96
+const removeClasses = (elmts, ...classes) => {
97
+  var norm_classes = classesArray(classes);
98
+  elmts = castAsArray(elmts);
99
+  elmts.map(el => {
100
+    norm_classes.map(cls => {
101
+      el.classList.remove(cls);
102
+    });
103
+  });
104
+};
105
+/**
106
+ * Return arguments
107
+ *
108
+ */
109
+
110
+const classesArray = args => {
111
+  var classes = [];
112
+  iterate(args, _classes => {
113
+    if (typeof _classes === 'string') {
114
+      _classes = _classes.trim().split(/[\11\12\14\15\40]/);
115
+    }
116
+
117
+    if (Array.isArray(_classes)) {
118
+      classes = classes.concat(_classes);
119
+    }
120
+  });
121
+  return classes.filter(Boolean);
122
+};
123
+/**
124
+ * Create an array from arg if it's not already an array
125
+ *
126
+ */
127
+
128
+const castAsArray = arg => {
129
+  if (!Array.isArray(arg)) {
130
+    arg = [arg];
131
+  }
132
+
133
+  return arg;
134
+};
135
+/**
136
+ * Get the index of an element amongst sibling nodes of the same type
137
+ *
138
+ */
139
+
140
+const nodeIndex = (el, amongst) => {
141
+  if (!el) return -1;
142
+  amongst = amongst || el.nodeName;
143
+  var i = 0;
144
+
145
+  while (el = el.previousElementSibling) {
146
+    if (el.matches(amongst)) {
147
+      i++;
148
+    }
149
+  }
150
+
151
+  return i;
152
+};
153
+
154
+/**
155
+ * Plugin: "dropdown_input" (Tom Select)
156
+ * Copyright (c) contributors
157
+ *
158
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
159
+ * file except in compliance with the License. You may obtain a copy of the License at:
160
+ * http://www.apache.org/licenses/LICENSE-2.0
161
+ *
162
+ * Unless required by applicable law or agreed to in writing, software distributed under
163
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
164
+ * ANY KIND, either express or implied. See the License for the specific language
165
+ * governing permissions and limitations under the License.
166
+ *
167
+ */
168
+function plugin () {
169
+  var self = this;
170
+  /**
171
+   * Moves the caret to the specified index.
172
+   *
173
+   * The input must be moved by leaving it in place and moving the
174
+   * siblings, due to the fact that focus cannot be restored once lost
175
+   * on mobile webkit devices
176
+   *
177
+   */
178
+
179
+  self.hook('instead', 'setCaret', new_pos => {
180
+    if (self.settings.mode === 'single' || !self.control.contains(self.control_input)) {
181
+      new_pos = self.items.length;
182
+    } else {
183
+      new_pos = Math.max(0, Math.min(self.items.length, new_pos));
184
+
185
+      if (new_pos != self.caretPos && !self.isPending) {
186
+        self.controlChildren().forEach((child, j) => {
187
+          if (j < new_pos) {
188
+            self.control_input.insertAdjacentElement('beforebegin', child);
189
+          } else {
190
+            self.control.appendChild(child);
191
+          }
192
+        });
193
+      }
194
+    }
195
+
196
+    self.caretPos = new_pos;
197
+  });
198
+  self.hook('instead', 'moveCaret', direction => {
199
+    if (!self.isFocused) return; // move caret before or after selected items
200
+
201
+    const last_active = self.getLastActive(direction);
202
+
203
+    if (last_active) {
204
+      const idx = nodeIndex(last_active);
205
+      self.setCaret(direction > 0 ? idx + 1 : idx);
206
+      self.setActiveItem();
207
+      removeClasses(last_active, 'last-active'); // move caret left or right of current position
208
+    } else {
209
+      self.setCaret(self.caretPos + direction);
210
+    }
211
+  });
212
+}
213
+
214
+export { plugin as default };
215
+//# sourceMappingURL=plugin.js.map