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