tom-select-rails 0.2.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tom-select-rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.complete.js +761 -273
  4. data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.complete.js.map +1 -1
  5. data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.js +756 -272
  6. data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.js.map +1 -1
  7. data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.popular.js +753 -269
  8. data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.popular.js.map +1 -1
  9. data/vendor/assets/javascripts/tom-select-rails/cjs/utils.js +1 -1
  10. data/vendor/assets/javascripts/tom-select-rails/cjs/utils.js.map +1 -1
  11. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/caret_position/plugin.js +9 -5
  12. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/caret_position/plugin.js.map +1 -1
  13. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/change_listener/plugin.js +1 -1
  14. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/change_listener/plugin.js.map +1 -1
  15. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/checkbox_options/plugin.js +12 -7
  16. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/checkbox_options/plugin.js.map +1 -1
  17. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/clear_button/plugin.js +13 -8
  18. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/clear_button/plugin.js.map +1 -1
  19. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/drag_drop/plugin.js +1 -1
  20. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/drag_drop/plugin.js.map +1 -1
  21. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_header/plugin.js +12 -7
  22. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_header/plugin.js.map +1 -1
  23. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_input/plugin.js +12 -8
  24. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_input/plugin.js.map +1 -1
  25. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/input_autogrow/plugin.js +1 -1
  26. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/input_autogrow/plugin.js.map +1 -1
  27. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_active_items/plugin.js +1 -1
  28. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_active_items/plugin.js.map +1 -1
  29. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_backspace_delete/plugin.js +1 -1
  30. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_backspace_delete/plugin.js.map +1 -1
  31. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/optgroup_columns/plugin.js +9 -4
  32. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/optgroup_columns/plugin.js.map +1 -1
  33. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/remove_button/plugin.js +12 -7
  34. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/remove_button/plugin.js.map +1 -1
  35. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/restore_on_backspace/plugin.js +1 -1
  36. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/restore_on_backspace/plugin.js.map +1 -1
  37. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/virtual_scroll/plugin.js +16 -8
  38. data/vendor/assets/javascripts/tom-select-rails/esm/plugins/virtual_scroll/plugin.js.map +1 -1
  39. data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.complete.js +761 -273
  40. data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.complete.js.map +1 -1
  41. data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.js +756 -272
  42. data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.js.map +1 -1
  43. data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.popular.js +753 -269
  44. data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.popular.js.map +1 -1
  45. data/vendor/assets/javascripts/tom-select-rails/esm/utils.js +1 -1
  46. data/vendor/assets/javascripts/tom-select-rails/esm/utils.js.map +1 -1
  47. data/vendor/assets/javascripts/tom-select-rails/js/plugins/caret_position.js +164 -160
  48. data/vendor/assets/javascripts/tom-select-rails/js/plugins/caret_position.js.map +1 -1
  49. data/vendor/assets/javascripts/tom-select-rails/js/plugins/change_listener.js +1 -1
  50. data/vendor/assets/javascripts/tom-select-rails/js/plugins/change_listener.js.map +1 -1
  51. data/vendor/assets/javascripts/tom-select-rails/js/plugins/checkbox_options.js +12 -7
  52. data/vendor/assets/javascripts/tom-select-rails/js/plugins/checkbox_options.js.map +1 -1
  53. data/vendor/assets/javascripts/tom-select-rails/js/plugins/clear_button.js +94 -89
  54. data/vendor/assets/javascripts/tom-select-rails/js/plugins/clear_button.js.map +1 -1
  55. data/vendor/assets/javascripts/tom-select-rails/js/plugins/drag_drop.js +1 -1
  56. data/vendor/assets/javascripts/tom-select-rails/js/plugins/drag_drop.js.map +1 -1
  57. data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_header.js +121 -116
  58. data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_header.js.map +1 -1
  59. data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_input.js +234 -230
  60. data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_input.js.map +1 -1
  61. data/vendor/assets/javascripts/tom-select-rails/js/plugins/input_autogrow.js +1 -1
  62. data/vendor/assets/javascripts/tom-select-rails/js/plugins/input_autogrow.js.map +1 -1
  63. data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_active_items.js +1 -1
  64. data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_active_items.js.map +1 -1
  65. data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_backspace_delete.js +1 -1
  66. data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_backspace_delete.js.map +1 -1
  67. data/vendor/assets/javascripts/tom-select-rails/js/plugins/optgroup_columns.js +112 -107
  68. data/vendor/assets/javascripts/tom-select-rails/js/plugins/optgroup_columns.js.map +1 -1
  69. data/vendor/assets/javascripts/tom-select-rails/js/plugins/remove_button.js +149 -144
  70. data/vendor/assets/javascripts/tom-select-rails/js/plugins/remove_button.js.map +1 -1
  71. data/vendor/assets/javascripts/tom-select-rails/js/plugins/restore_on_backspace.js +1 -1
  72. data/vendor/assets/javascripts/tom-select-rails/js/plugins/restore_on_backspace.js.map +1 -1
  73. data/vendor/assets/javascripts/tom-select-rails/js/plugins/virtual_scroll.js +277 -269
  74. data/vendor/assets/javascripts/tom-select-rails/js/plugins/virtual_scroll.js.map +1 -1
  75. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.js +756 -272
  76. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.js.map +1 -1
  77. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.min.js +329 -272
  78. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.min.js.map +1 -1
  79. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.js +761 -273
  80. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.js.map +1 -1
  81. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.min.js +268 -209
  82. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.min.js.map +1 -1
  83. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.js +753 -269
  84. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.js.map +1 -1
  85. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.min.js +348 -291
  86. data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.min.js.map +1 -1
  87. data/vendor/assets/javascripts/tom-select-rails/types/tom-select.d.ts +6 -6
  88. data/vendor/assets/javascripts/tom-select-rails/types/types/settings.d.ts +19 -22
  89. data/vendor/assets/javascripts/tom-select-rails/types/utils.d.ts +5 -5
  90. data/vendor/assets/javascripts/tom-select-rails/types/vanilla.d.ts +2 -2
  91. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.css +41 -19
  92. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.css.map +1 -1
  93. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.min.css +1 -1
  94. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.min.css.map +1 -1
  95. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.css +61 -34
  96. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.css.map +1 -1
  97. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.min.css +1 -1
  98. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.min.css.map +1 -1
  99. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.css +39 -17
  100. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.css.map +1 -1
  101. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.css +41 -19
  102. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.css.map +1 -1
  103. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.min.css +1 -1
  104. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.min.css.map +1 -1
  105. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.min.css +1 -1
  106. data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.min.css.map +1 -1
  107. data/vendor/assets/stylesheets/tom-select-rails/scss/plugins/clear_button.scss +12 -5
  108. data/vendor/assets/stylesheets/tom-select-rails/scss/plugins/remove_button.scss +34 -8
  109. data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.bootstrap4.scss +1 -1
  110. data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.bootstrap5.scss +20 -10
  111. data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.default.scss +1 -1
  112. data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.scss +11 -2
  113. metadata +3 -3
@@ -1,240 +1,244 @@
1
1
  /**
2
- * Tom Select v2.1.0
2
+ * Tom Select v2.2.0
3
3
  * Licensed under the Apache License, Version 2.0 (the "License");
4
4
  */
5
5
 
6
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.dropdown_input = 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.dropdown_input = factory());
10
10
  })(this, (function () { 'use strict';
11
11
 
12
- const KEY_ESC = 27;
13
- const KEY_TAB = 9;
14
- typeof navigator === 'undefined' ? false : /Mac/.test(navigator.userAgent);
15
- // ctrl key or apple key for ma
16
-
17
- // @ts-ignore TS2691 "An import path cannot end with a '.ts' extension"
18
- const latin_convert = {
19
- 'æ': 'ae',
20
- 'ⱥ': 'a',
21
- 'ø': 'o'
22
- };
23
- new RegExp(Object.keys(latin_convert).join('|'), 'gu');
24
-
25
- // @ts-ignore TS2691 "An import path cannot end with a '.ts' extension"
26
- /**
27
- * Iterates over arrays and hashes.
28
- *
29
- * ```
30
- * iterate(this.items, function(item, id) {
31
- * // invoked for each item
32
- * });
33
- * ```
34
- *
35
- */
36
-
37
- const iterate = (object, callback) => {
38
- if (Array.isArray(object)) {
39
- object.forEach(callback);
40
- } else {
41
- for (var key in object) {
42
- if (object.hasOwnProperty(key)) {
43
- callback(object[key], key);
44
- }
45
- }
46
- }
47
- };
48
-
49
- /**
50
- * Return a dom element from either a dom query string, jQuery object, a dom element or html string
51
- * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
52
- *
53
- * param query should be {}
54
- */
55
-
56
- const getDom = query => {
57
- if (query.jquery) {
58
- return query[0];
59
- }
60
-
61
- if (query instanceof HTMLElement) {
62
- return query;
63
- }
64
-
65
- if (isHtmlString(query)) {
66
- let div = document.createElement('div');
67
- div.innerHTML = query.trim(); // Never return a text node of whitespace as the result
68
-
69
- return div.firstChild;
70
- }
71
-
72
- return document.querySelector(query);
73
- };
74
- const isHtmlString = arg => {
75
- if (typeof arg === 'string' && arg.indexOf('<') > -1) {
76
- return true;
77
- }
78
-
79
- return false;
80
- };
81
- /**
82
- * Add css classes
83
- *
84
- */
85
-
86
- const addClasses = (elmts, ...classes) => {
87
- var norm_classes = classesArray(classes);
88
- elmts = castAsArray(elmts);
89
- elmts.map(el => {
90
- norm_classes.map(cls => {
91
- el.classList.add(cls);
92
- });
93
- });
94
- };
95
- /**
96
- * Return arguments
97
- *
98
- */
99
-
100
- const classesArray = args => {
101
- var classes = [];
102
- iterate(args, _classes => {
103
- if (typeof _classes === 'string') {
104
- _classes = _classes.trim().split(/[\11\12\14\15\40]/);
105
- }
106
-
107
- if (Array.isArray(_classes)) {
108
- classes = classes.concat(_classes);
109
- }
110
- });
111
- return classes.filter(Boolean);
112
- };
113
- /**
114
- * Create an array from arg if it's not already an array
115
- *
116
- */
117
-
118
- const castAsArray = arg => {
119
- if (!Array.isArray(arg)) {
120
- arg = [arg];
121
- }
122
-
123
- return arg;
124
- };
125
-
126
- /**
127
- * Converts a scalar to its best string representation
128
- * for hash keys and HTML attribute values.
129
- *
130
- * Transformations:
131
- * 'str' -> 'str'
132
- * null -> ''
133
- * undefined -> ''
134
- * true -> '1'
135
- * false -> '0'
136
- * 0 -> '0'
137
- * 1 -> '1'
138
- *
139
- */
140
- /**
141
- * Prevent default
142
- *
143
- */
144
-
145
- const preventDefault = (evt, stop = false) => {
146
- if (evt) {
147
- evt.preventDefault();
148
-
149
- if (stop) {
150
- evt.stopPropagation();
151
- }
152
- }
153
- };
154
- /**
155
- * Prevent default
156
- *
157
- */
158
-
159
- const addEvent = (target, type, callback, options) => {
160
- target.addEventListener(type, callback, options);
161
- };
162
-
163
- /**
164
- * Plugin: "dropdown_input" (Tom Select)
165
- * Copyright (c) contributors
166
- *
167
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
168
- * file except in compliance with the License. You may obtain a copy of the License at:
169
- * http://www.apache.org/licenses/LICENSE-2.0
170
- *
171
- * Unless required by applicable law or agreed to in writing, software distributed under
172
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
173
- * ANY KIND, either express or implied. See the License for the specific language
174
- * governing permissions and limitations under the License.
175
- *
176
- */
177
- function plugin () {
178
- const self = this;
179
- self.settings.shouldOpen = true; // make sure the input is shown even if there are no options to display in the dropdown
180
-
181
- self.hook('before', 'setup', () => {
182
- self.focus_node = self.control;
183
- addClasses(self.control_input, 'dropdown-input');
184
- const div = getDom('<div class="dropdown-input-wrap">');
185
- div.append(self.control_input);
186
- self.dropdown.insertBefore(div, self.dropdown.firstChild); // set a placeholder in the select control
187
-
188
- const placeholder = getDom('<input class="items-placeholder" tabindex="-1" />');
189
- placeholder.placeholder = self.settings.placeholder || '';
190
- self.control.append(placeholder);
191
- });
192
- self.on('initialize', () => {
193
- // set tabIndex on control to -1, otherwise [shift+tab] will put focus right back on control_input
194
- self.control_input.addEventListener('keydown', evt => {
195
- //addEvent(self.control_input,'keydown' as const,(evt:KeyboardEvent) =>{
196
- switch (evt.keyCode) {
197
- case KEY_ESC:
198
- if (self.isOpen) {
199
- preventDefault(evt, true);
200
- self.close();
201
- }
202
-
203
- self.clearActiveItems();
204
- return;
205
-
206
- case KEY_TAB:
207
- self.focus_node.tabIndex = -1;
208
- break;
209
- }
210
-
211
- return self.onKeyDown.call(self, evt);
212
- });
213
- self.on('blur', () => {
214
- self.focus_node.tabIndex = self.isDisabled ? -1 : self.tabIndex;
215
- }); // give the control_input focus when the dropdown is open
216
-
217
- self.on('dropdown_open', () => {
218
- self.control_input.focus();
219
- }); // prevent onBlur from closing when focus is on the control_input
220
-
221
- const orig_onBlur = self.onBlur;
222
- self.hook('instead', 'onBlur', evt => {
223
- if (evt && evt.relatedTarget == self.control_input) return;
224
- return orig_onBlur.call(self);
225
- });
226
- addEvent(self.control_input, 'blur', () => self.onBlur()); // return focus to control to allow further keyboard input
227
-
228
- self.hook('before', 'close', () => {
229
- if (!self.isOpen) return;
230
- self.focus_node.focus({
231
- preventScroll: true
232
- });
233
- });
234
- });
235
- }
236
-
237
- return plugin;
12
+ const KEY_ESC = 27;
13
+ const KEY_TAB = 9;
14
+ typeof navigator === 'undefined' ? false : /Mac/.test(navigator.userAgent);
15
+ // ctrl key or apple key for ma
16
+
17
+ /*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
18
+ const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}]'; // \u{2bc}
19
+ /** @type {TUnicodeMap} */
20
+
21
+ const latin_convert = {
22
+ 'æ': 'ae',
23
+ '': 'a',
24
+ 'ø': 'o',
25
+ '⁄': '/',
26
+ '∕': '/'
27
+ };
28
+ new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu');
29
+
30
+ /**
31
+ * Iterates over arrays and hashes.
32
+ *
33
+ * ```
34
+ * iterate(this.items, function(item, id) {
35
+ * // invoked for each item
36
+ * });
37
+ * ```
38
+ *
39
+ */
40
+
41
+ const iterate = (object, callback) => {
42
+ if (Array.isArray(object)) {
43
+ object.forEach(callback);
44
+ } else {
45
+ for (var key in object) {
46
+ if (object.hasOwnProperty(key)) {
47
+ callback(object[key], key);
48
+ }
49
+ }
50
+ }
51
+ };
52
+
53
+ /**
54
+ * Return a dom element from either a dom query string, jQuery object, a dom element or html string
55
+ * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
56
+ *
57
+ * param query should be {}
58
+ */
59
+
60
+ const getDom = query => {
61
+ if (query.jquery) {
62
+ return query[0];
63
+ }
64
+
65
+ if (query instanceof HTMLElement) {
66
+ return query;
67
+ }
68
+
69
+ if (isHtmlString(query)) {
70
+ var tpl = document.createElement('template');
71
+ tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
72
+
73
+ return tpl.content.firstChild;
74
+ }
75
+
76
+ return document.querySelector(query);
77
+ };
78
+ const isHtmlString = arg => {
79
+ if (typeof arg === 'string' && arg.indexOf('<') > -1) {
80
+ return true;
81
+ }
82
+
83
+ return false;
84
+ };
85
+ /**
86
+ * Add css classes
87
+ *
88
+ */
89
+
90
+ const addClasses = (elmts, ...classes) => {
91
+ var norm_classes = classesArray(classes);
92
+ elmts = castAsArray(elmts);
93
+ elmts.map(el => {
94
+ norm_classes.map(cls => {
95
+ el.classList.add(cls);
96
+ });
97
+ });
98
+ };
99
+ /**
100
+ * Return arguments
101
+ *
102
+ */
103
+
104
+ const classesArray = args => {
105
+ var classes = [];
106
+ iterate(args, _classes => {
107
+ if (typeof _classes === 'string') {
108
+ _classes = _classes.trim().split(/[\11\12\14\15\40]/);
109
+ }
110
+
111
+ if (Array.isArray(_classes)) {
112
+ classes = classes.concat(_classes);
113
+ }
114
+ });
115
+ return classes.filter(Boolean);
116
+ };
117
+ /**
118
+ * Create an array from arg if it's not already an array
119
+ *
120
+ */
121
+
122
+ const castAsArray = arg => {
123
+ if (!Array.isArray(arg)) {
124
+ arg = [arg];
125
+ }
126
+
127
+ return arg;
128
+ };
129
+
130
+ /**
131
+ * Converts a scalar to its best string representation
132
+ * for hash keys and HTML attribute values.
133
+ *
134
+ * Transformations:
135
+ * 'str' -> 'str'
136
+ * null -> ''
137
+ * undefined -> ''
138
+ * true -> '1'
139
+ * false -> '0'
140
+ * 0 -> '0'
141
+ * 1 -> '1'
142
+ *
143
+ */
144
+ /**
145
+ * Prevent default
146
+ *
147
+ */
148
+
149
+ const preventDefault = (evt, stop = false) => {
150
+ if (evt) {
151
+ evt.preventDefault();
152
+
153
+ if (stop) {
154
+ evt.stopPropagation();
155
+ }
156
+ }
157
+ };
158
+ /**
159
+ * Prevent default
160
+ *
161
+ */
162
+
163
+ const addEvent = (target, type, callback, options) => {
164
+ target.addEventListener(type, callback, options);
165
+ };
166
+
167
+ /**
168
+ * Plugin: "dropdown_input" (Tom Select)
169
+ * Copyright (c) contributors
170
+ *
171
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
172
+ * file except in compliance with the License. You may obtain a copy of the License at:
173
+ * http://www.apache.org/licenses/LICENSE-2.0
174
+ *
175
+ * Unless required by applicable law or agreed to in writing, software distributed under
176
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
177
+ * ANY KIND, either express or implied. See the License for the specific language
178
+ * governing permissions and limitations under the License.
179
+ *
180
+ */
181
+ function plugin () {
182
+ const self = this;
183
+ self.settings.shouldOpen = true; // make sure the input is shown even if there are no options to display in the dropdown
184
+
185
+ self.hook('before', 'setup', () => {
186
+ self.focus_node = self.control;
187
+ addClasses(self.control_input, 'dropdown-input');
188
+ const div = getDom('<div class="dropdown-input-wrap">');
189
+ div.append(self.control_input);
190
+ self.dropdown.insertBefore(div, self.dropdown.firstChild); // set a placeholder in the select control
191
+
192
+ const placeholder = getDom('<input class="items-placeholder" tabindex="-1" />');
193
+ placeholder.placeholder = self.settings.placeholder || '';
194
+ self.control.append(placeholder);
195
+ });
196
+ self.on('initialize', () => {
197
+ // set tabIndex on control to -1, otherwise [shift+tab] will put focus right back on control_input
198
+ self.control_input.addEventListener('keydown', evt => {
199
+ //addEvent(self.control_input,'keydown' as const,(evt:KeyboardEvent) =>{
200
+ switch (evt.keyCode) {
201
+ case KEY_ESC:
202
+ if (self.isOpen) {
203
+ preventDefault(evt, true);
204
+ self.close();
205
+ }
206
+
207
+ self.clearActiveItems();
208
+ return;
209
+
210
+ case KEY_TAB:
211
+ self.focus_node.tabIndex = -1;
212
+ break;
213
+ }
214
+
215
+ return self.onKeyDown.call(self, evt);
216
+ });
217
+ self.on('blur', () => {
218
+ self.focus_node.tabIndex = self.isDisabled ? -1 : self.tabIndex;
219
+ }); // give the control_input focus when the dropdown is open
220
+
221
+ self.on('dropdown_open', () => {
222
+ self.control_input.focus();
223
+ }); // prevent onBlur from closing when focus is on the control_input
224
+
225
+ const orig_onBlur = self.onBlur;
226
+ self.hook('instead', 'onBlur', evt => {
227
+ if (evt && evt.relatedTarget == self.control_input) return;
228
+ return orig_onBlur.call(self);
229
+ });
230
+ addEvent(self.control_input, 'blur', () => self.onBlur()); // return focus to control to allow further keyboard input
231
+
232
+ self.hook('before', 'close', () => {
233
+ if (!self.isOpen) return;
234
+ self.focus_node.focus({
235
+ preventScroll: true
236
+ });
237
+ });
238
+ });
239
+ }
240
+
241
+ return plugin;
238
242
 
239
243
  }));
240
244
  //# sourceMappingURL=dropdown_input.js.map