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,163 @@
1
+/**
2
+* Tom Select v2.2.2
3
+* Licensed under the Apache License, Version 2.0 (the "License");
4
+*/
5
+
6
+const KEY_LEFT = 37;
7
+const KEY_RIGHT = 39;
8
+typeof navigator === 'undefined' ? false : /Mac/.test(navigator.userAgent);
9
+ // ctrl key or apple key for ma
10
+
11
+/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
12
+const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}\u{2bc}]';
13
+/** @type {TUnicodeMap} */
14
+
15
+const latin_convert = {};
16
+/** @type {TUnicodeMap} */
17
+
18
+const latin_condensed = {
19
+  '/': '⁄∕',
20
+  '0': '߀',
21
+  "a": "ⱥɐɑ",
22
+  "aa": "ꜳ",
23
+  "ae": "æǽǣ",
24
+  "ao": "ꜵ",
25
+  "au": "ꜷ",
26
+  "av": "ꜹꜻ",
27
+  "ay": "ꜽ",
28
+  "b": "ƀɓƃ",
29
+  "c": "ꜿƈȼↄ",
30
+  "d": "đɗɖᴅƌꮷԁɦ",
31
+  "e": "ɛǝᴇɇ",
32
+  "f": "ꝼƒ",
33
+  "g": "ǥɠꞡᵹꝿɢ",
34
+  "h": "ħⱨⱶɥ",
35
+  "i": "ɨı",
36
+  "j": "ɉȷ",
37
+  "k": "ƙⱪꝁꝃꝅꞣ",
38
+  "l": "łƚɫⱡꝉꝇꞁɭ",
39
+  "m": "ɱɯϻ",
40
+  "n": "ꞥƞɲꞑᴎлԉ",
41
+  "o": "øǿɔɵꝋꝍᴑ",
42
+  "oe": "œ",
43
+  "oi": "ƣ",
44
+  "oo": "ꝏ",
45
+  "ou": "ȣ",
46
+  "p": "ƥᵽꝑꝓꝕρ",
47
+  "q": "ꝗꝙɋ",
48
+  "r": "ɍɽꝛꞧꞃ",
49
+  "s": "ßȿꞩꞅʂ",
50
+  "t": "ŧƭʈⱦꞇ",
51
+  "th": "þ",
52
+  "tz": "ꜩ",
53
+  "u": "ʉ",
54
+  "v": "ʋꝟʌ",
55
+  "vy": "ꝡ",
56
+  "w": "ⱳ",
57
+  "y": "ƴɏỿ",
58
+  "z": "ƶȥɀⱬꝣ",
59
+  "hv": "ƕ"
60
+};
61
+
62
+for (let latin in latin_condensed) {
63
+  let unicode = latin_condensed[latin] || '';
64
+
65
+  for (let i = 0; i < unicode.length; i++) {
66
+    let char = unicode.substring(i, i + 1);
67
+    latin_convert[char] = latin;
68
+  }
69
+}
70
+
71
+new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu');
72
+
73
+/**
74
+ * Get the closest node to the evt.target matching the selector
75
+ * Stops at wrapper
76
+ *
77
+ */
78
+
79
+const parentMatch = (target, selector, wrapper) => {
80
+  if (wrapper && !wrapper.contains(target)) {
81
+    return;
82
+  }
83
+
84
+  while (target && target.matches) {
85
+    if (target.matches(selector)) {
86
+      return target;
87
+    }
88
+
89
+    target = target.parentNode;
90
+  }
91
+};
92
+/**
93
+ * Get the index of an element amongst sibling nodes of the same type
94
+ *
95
+ */
96
+
97
+const nodeIndex = (el, amongst) => {
98
+  if (!el) return -1;
99
+  amongst = amongst || el.nodeName;
100
+  var i = 0;
101
+
102
+  while (el = el.previousElementSibling) {
103
+    if (el.matches(amongst)) {
104
+      i++;
105
+    }
106
+  }
107
+
108
+  return i;
109
+};
110
+
111
+/**
112
+ * Plugin: "optgroup_columns" (Tom Select.js)
113
+ * Copyright (c) contributors
114
+ *
115
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
116
+ * file except in compliance with the License. You may obtain a copy of the License at:
117
+ * http://www.apache.org/licenses/LICENSE-2.0
118
+ *
119
+ * Unless required by applicable law or agreed to in writing, software distributed under
120
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
121
+ * ANY KIND, either express or implied. See the License for the specific language
122
+ * governing permissions and limitations under the License.
123
+ *
124
+ */
125
+function plugin () {
126
+  var self = this;
127
+  var orig_keydown = self.onKeyDown;
128
+  self.hook('instead', 'onKeyDown', evt => {
129
+    var index, option, options, optgroup;
130
+
131
+    if (!self.isOpen || !(evt.keyCode === KEY_LEFT || evt.keyCode === KEY_RIGHT)) {
132
+      return orig_keydown.call(self, evt);
133
+    }
134
+
135
+    self.ignoreHover = true;
136
+    optgroup = parentMatch(self.activeOption, '[data-group]');
137
+    index = nodeIndex(self.activeOption, '[data-selectable]');
138
+
139
+    if (!optgroup) {
140
+      return;
141
+    }
142
+
143
+    if (evt.keyCode === KEY_LEFT) {
144
+      optgroup = optgroup.previousSibling;
145
+    } else {
146
+      optgroup = optgroup.nextSibling;
147
+    }
148
+
149
+    if (!optgroup) {
150
+      return;
151
+    }
152
+
153
+    options = optgroup.querySelectorAll('[data-selectable]');
154
+    option = options[Math.min(options.length - 1, index)];
155
+
156
+    if (option) {
157
+      self.setActiveOption(option);
158
+    }
159
+  });
160
+}
161
+
162
+export { plugin as default };
163
+//# sourceMappingURL=plugin.js.map