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,279 +1,287 @@
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.virtual_scroll = 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.virtual_scroll = factory());
10
10
  })(this, (function () { 'use strict';
11
11
 
12
- // @ts-ignore TS2691 "An import path cannot end with a '.ts' extension"
13
- const latin_convert = {
14
- 'æ': 'ae',
15
- 'ⱥ': 'a',
16
- 'ø': 'o'
17
- };
18
- new RegExp(Object.keys(latin_convert).join('|'), 'gu');
19
-
20
- // @ts-ignore TS2691 "An import path cannot end with a '.ts' extension"
21
- /**
22
- * Iterates over arrays and hashes.
23
- *
24
- * ```
25
- * iterate(this.items, function(item, id) {
26
- * // invoked for each item
27
- * });
28
- * ```
29
- *
30
- */
31
-
32
- const iterate = (object, callback) => {
33
- if (Array.isArray(object)) {
34
- object.forEach(callback);
35
- } else {
36
- for (var key in object) {
37
- if (object.hasOwnProperty(key)) {
38
- callback(object[key], key);
39
- }
40
- }
41
- }
42
- };
43
-
44
- /**
45
- * Add css classes
46
- *
47
- */
48
-
49
- const addClasses = (elmts, ...classes) => {
50
- var norm_classes = classesArray(classes);
51
- elmts = castAsArray(elmts);
52
- elmts.map(el => {
53
- norm_classes.map(cls => {
54
- el.classList.add(cls);
55
- });
56
- });
57
- };
58
- /**
59
- * Return arguments
60
- *
61
- */
62
-
63
- const classesArray = args => {
64
- var classes = [];
65
- iterate(args, _classes => {
66
- if (typeof _classes === 'string') {
67
- _classes = _classes.trim().split(/[\11\12\14\15\40]/);
68
- }
69
-
70
- if (Array.isArray(_classes)) {
71
- classes = classes.concat(_classes);
72
- }
73
- });
74
- return classes.filter(Boolean);
75
- };
76
- /**
77
- * Create an array from arg if it's not already an array
78
- *
79
- */
80
-
81
- const castAsArray = arg => {
82
- if (!Array.isArray(arg)) {
83
- arg = [arg];
84
- }
85
-
86
- return arg;
87
- };
88
-
89
- /**
90
- * Plugin: "restore_on_backspace" (Tom Select)
91
- * Copyright (c) contributors
92
- *
93
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
94
- * file except in compliance with the License. You may obtain a copy of the License at:
95
- * http://www.apache.org/licenses/LICENSE-2.0
96
- *
97
- * Unless required by applicable law or agreed to in writing, software distributed under
98
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
99
- * ANY KIND, either express or implied. See the License for the specific language
100
- * governing permissions and limitations under the License.
101
- *
102
- */
103
- function plugin () {
104
- const self = this;
105
- const orig_canLoad = self.canLoad;
106
- const orig_clearActiveOption = self.clearActiveOption;
107
- const orig_loadCallback = self.loadCallback;
108
- var pagination = {};
109
- var dropdown_content;
110
- var loading_more = false;
111
- var load_more_opt;
112
- var default_values = [];
113
-
114
- if (!self.settings.shouldLoadMore) {
115
- // return true if additional results should be loaded
116
- self.settings.shouldLoadMore = () => {
117
- const scroll_percent = dropdown_content.clientHeight / (dropdown_content.scrollHeight - dropdown_content.scrollTop);
118
-
119
- if (scroll_percent > 0.9) {
120
- return true;
121
- }
122
-
123
- if (self.activeOption) {
124
- var selectable = self.selectable();
125
- var index = [...selectable].indexOf(self.activeOption);
126
-
127
- if (index >= selectable.length - 2) {
128
- return true;
129
- }
130
- }
131
-
132
- return false;
133
- };
134
- }
135
-
136
- if (!self.settings.firstUrl) {
137
- throw 'virtual_scroll plugin requires a firstUrl() method';
138
- } // in order for virtual scrolling to work,
139
- // options need to be ordered the same way they're returned from the remote data source
140
-
141
-
142
- self.settings.sortField = [{
143
- field: '$order'
144
- }, {
145
- field: '$score'
146
- }]; // can we load more results for given query?
147
-
148
- const canLoadMore = query => {
149
- if (typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) {
150
- return false;
151
- }
152
-
153
- if (query in pagination && pagination[query]) {
154
- return true;
155
- }
156
-
157
- return false;
158
- };
159
-
160
- const clearFilter = (option, value) => {
161
- if (self.items.indexOf(value) >= 0 || default_values.indexOf(value) >= 0) {
162
- return true;
163
- }
164
-
165
- return false;
166
- }; // set the next url that will be
167
-
168
-
169
- self.setNextUrl = (value, next_url) => {
170
- pagination[value] = next_url;
171
- }; // getUrl() to be used in settings.load()
172
-
173
-
174
- self.getUrl = query => {
175
- if (query in pagination) {
176
- const next_url = pagination[query];
177
- pagination[query] = false;
178
- return next_url;
179
- } // if the user goes back to a previous query
180
- // we need to load the first page again
181
-
182
-
183
- pagination = {};
184
- return self.settings.firstUrl.call(self, query);
185
- }; // don't clear the active option (and cause unwanted dropdown scroll)
186
- // while loading more results
187
-
188
-
189
- self.hook('instead', 'clearActiveOption', () => {
190
- if (loading_more) {
191
- return;
192
- }
193
-
194
- return orig_clearActiveOption.call(self);
195
- }); // override the canLoad method
196
-
197
- self.hook('instead', 'canLoad', query => {
198
- // first time the query has been seen
199
- if (!(query in pagination)) {
200
- return orig_canLoad.call(self, query);
201
- }
202
-
203
- return canLoadMore(query);
204
- }); // wrap the load
205
-
206
- self.hook('instead', 'loadCallback', (options, optgroups) => {
207
- if (!loading_more) {
208
- self.clearOptions(clearFilter);
209
- } else if (load_more_opt && options.length > 0) {
210
- load_more_opt.dataset.value = options[0][self.settings.valueField];
211
- }
212
-
213
- orig_loadCallback.call(self, options, optgroups);
214
- loading_more = false;
215
- }); // add templates to dropdown
216
- // loading_more if we have another url in the queue
217
- // no_more_results if we don't have another url in the queue
218
-
219
- self.hook('after', 'refreshOptions', () => {
220
- const query = self.lastValue;
221
- var option;
222
-
223
- if (canLoadMore(query)) {
224
- option = self.render('loading_more', {
225
- query: query
226
- });
227
-
228
- if (option) {
229
- option.setAttribute('data-selectable', ''); // so that navigating dropdown with [down] keypresses can navigate to this node
230
-
231
- load_more_opt = option;
232
- }
233
- } else if (query in pagination && !dropdown_content.querySelector('.no-results')) {
234
- option = self.render('no_more_results', {
235
- query: query
236
- });
237
- }
238
-
239
- if (option) {
240
- addClasses(option, self.settings.optionClass);
241
- dropdown_content.append(option);
242
- }
243
- }); // add scroll listener and default templates
244
-
245
- self.on('initialize', () => {
246
- default_values = Object.keys(self.options);
247
- dropdown_content = self.dropdown_content; // default templates
248
-
249
- self.settings.render = Object.assign({}, {
250
- loading_more: () => {
251
- return `<div class="loading-more-results">Loading more results ... </div>`;
252
- },
253
- no_more_results: () => {
254
- return `<div class="no-more-results">No more results</div>`;
255
- }
256
- }, self.settings.render); // watch dropdown content scroll position
257
-
258
- dropdown_content.addEventListener('scroll', () => {
259
- if (!self.settings.shouldLoadMore.call(self)) {
260
- return;
261
- } // !important: this will get checked again in load() but we still need to check here otherwise loading_more will be set to true
262
-
263
-
264
- if (!canLoadMore(self.lastValue)) {
265
- return;
266
- } // don't call load() too much
267
-
268
-
269
- if (loading_more) return;
270
- loading_more = true;
271
- self.load.call(self, self.lastValue);
272
- });
273
- });
274
- }
275
-
276
- return plugin;
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
+ 'æ': 'ae',
18
+ '': 'a',
19
+ 'ø': 'o',
20
+ '⁄': '/',
21
+ '∕': '/'
22
+ };
23
+ new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu');
24
+
25
+ /**
26
+ * Iterates over arrays and hashes.
27
+ *
28
+ * ```
29
+ * iterate(this.items, function(item, id) {
30
+ * // invoked for each item
31
+ * });
32
+ * ```
33
+ *
34
+ */
35
+
36
+ const iterate = (object, callback) => {
37
+ if (Array.isArray(object)) {
38
+ object.forEach(callback);
39
+ } else {
40
+ for (var key in object) {
41
+ if (object.hasOwnProperty(key)) {
42
+ callback(object[key], key);
43
+ }
44
+ }
45
+ }
46
+ };
47
+
48
+ /**
49
+ * Add css classes
50
+ *
51
+ */
52
+
53
+ const addClasses = (elmts, ...classes) => {
54
+ var norm_classes = classesArray(classes);
55
+ elmts = castAsArray(elmts);
56
+ elmts.map(el => {
57
+ norm_classes.map(cls => {
58
+ el.classList.add(cls);
59
+ });
60
+ });
61
+ };
62
+ /**
63
+ * Return arguments
64
+ *
65
+ */
66
+
67
+ const classesArray = args => {
68
+ var classes = [];
69
+ iterate(args, _classes => {
70
+ if (typeof _classes === 'string') {
71
+ _classes = _classes.trim().split(/[\11\12\14\15\40]/);
72
+ }
73
+
74
+ if (Array.isArray(_classes)) {
75
+ classes = classes.concat(_classes);
76
+ }
77
+ });
78
+ return classes.filter(Boolean);
79
+ };
80
+ /**
81
+ * Create an array from arg if it's not already an array
82
+ *
83
+ */
84
+
85
+ const castAsArray = arg => {
86
+ if (!Array.isArray(arg)) {
87
+ arg = [arg];
88
+ }
89
+
90
+ return arg;
91
+ };
92
+
93
+ /**
94
+ * Plugin: "restore_on_backspace" (Tom Select)
95
+ * Copyright (c) contributors
96
+ *
97
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
98
+ * file except in compliance with the License. You may obtain a copy of the License at:
99
+ * http://www.apache.org/licenses/LICENSE-2.0
100
+ *
101
+ * Unless required by applicable law or agreed to in writing, software distributed under
102
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
103
+ * ANY KIND, either express or implied. See the License for the specific language
104
+ * governing permissions and limitations under the License.
105
+ *
106
+ */
107
+ function plugin () {
108
+ const self = this;
109
+ const orig_canLoad = self.canLoad;
110
+ const orig_clearActiveOption = self.clearActiveOption;
111
+ const orig_loadCallback = self.loadCallback;
112
+ var pagination = {};
113
+ var dropdown_content;
114
+ var loading_more = false;
115
+ var load_more_opt;
116
+ var default_values = [];
117
+
118
+ if (!self.settings.shouldLoadMore) {
119
+ // return true if additional results should be loaded
120
+ self.settings.shouldLoadMore = () => {
121
+ const scroll_percent = dropdown_content.clientHeight / (dropdown_content.scrollHeight - dropdown_content.scrollTop);
122
+
123
+ if (scroll_percent > 0.9) {
124
+ return true;
125
+ }
126
+
127
+ if (self.activeOption) {
128
+ var selectable = self.selectable();
129
+ var index = Array.from(selectable).indexOf(self.activeOption);
130
+
131
+ if (index >= selectable.length - 2) {
132
+ return true;
133
+ }
134
+ }
135
+
136
+ return false;
137
+ };
138
+ }
139
+
140
+ if (!self.settings.firstUrl) {
141
+ throw 'virtual_scroll plugin requires a firstUrl() method';
142
+ } // in order for virtual scrolling to work,
143
+ // options need to be ordered the same way they're returned from the remote data source
144
+
145
+
146
+ self.settings.sortField = [{
147
+ field: '$order'
148
+ }, {
149
+ field: '$score'
150
+ }]; // can we load more results for given query?
151
+
152
+ const canLoadMore = query => {
153
+ if (typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) {
154
+ return false;
155
+ }
156
+
157
+ if (query in pagination && pagination[query]) {
158
+ return true;
159
+ }
160
+
161
+ return false;
162
+ };
163
+
164
+ const clearFilter = (option, value) => {
165
+ if (self.items.indexOf(value) >= 0 || default_values.indexOf(value) >= 0) {
166
+ return true;
167
+ }
168
+
169
+ return false;
170
+ }; // set the next url that will be
171
+
172
+
173
+ self.setNextUrl = (value, next_url) => {
174
+ pagination[value] = next_url;
175
+ }; // getUrl() to be used in settings.load()
176
+
177
+
178
+ self.getUrl = query => {
179
+ if (query in pagination) {
180
+ const next_url = pagination[query];
181
+ pagination[query] = false;
182
+ return next_url;
183
+ } // if the user goes back to a previous query
184
+ // we need to load the first page again
185
+
186
+
187
+ pagination = {};
188
+ return self.settings.firstUrl.call(self, query);
189
+ }; // don't clear the active option (and cause unwanted dropdown scroll)
190
+ // while loading more results
191
+
192
+
193
+ self.hook('instead', 'clearActiveOption', () => {
194
+ if (loading_more) {
195
+ return;
196
+ }
197
+
198
+ return orig_clearActiveOption.call(self);
199
+ }); // override the canLoad method
200
+
201
+ self.hook('instead', 'canLoad', query => {
202
+ // first time the query has been seen
203
+ if (!(query in pagination)) {
204
+ return orig_canLoad.call(self, query);
205
+ }
206
+
207
+ return canLoadMore(query);
208
+ }); // wrap the load
209
+
210
+ self.hook('instead', 'loadCallback', (options, optgroups) => {
211
+ if (!loading_more) {
212
+ self.clearOptions(clearFilter);
213
+ } else if (load_more_opt) {
214
+ const first_option = options[0];
215
+
216
+ if (first_option !== undefined) {
217
+ load_more_opt.dataset.value = first_option[self.settings.valueField];
218
+ }
219
+ }
220
+
221
+ orig_loadCallback.call(self, options, optgroups);
222
+ loading_more = false;
223
+ }); // add templates to dropdown
224
+ // loading_more if we have another url in the queue
225
+ // no_more_results if we don't have another url in the queue
226
+
227
+ self.hook('after', 'refreshOptions', () => {
228
+ const query = self.lastValue;
229
+ var option;
230
+
231
+ if (canLoadMore(query)) {
232
+ option = self.render('loading_more', {
233
+ query: query
234
+ });
235
+
236
+ if (option) {
237
+ option.setAttribute('data-selectable', ''); // so that navigating dropdown with [down] keypresses can navigate to this node
238
+
239
+ load_more_opt = option;
240
+ }
241
+ } else if (query in pagination && !dropdown_content.querySelector('.no-results')) {
242
+ option = self.render('no_more_results', {
243
+ query: query
244
+ });
245
+ }
246
+
247
+ if (option) {
248
+ addClasses(option, self.settings.optionClass);
249
+ dropdown_content.append(option);
250
+ }
251
+ }); // add scroll listener and default templates
252
+
253
+ self.on('initialize', () => {
254
+ default_values = Object.keys(self.options);
255
+ dropdown_content = self.dropdown_content; // default templates
256
+
257
+ self.settings.render = Object.assign({}, {
258
+ loading_more: () => {
259
+ return `<div class="loading-more-results">Loading more results ... </div>`;
260
+ },
261
+ no_more_results: () => {
262
+ return `<div class="no-more-results">No more results</div>`;
263
+ }
264
+ }, self.settings.render); // watch dropdown content scroll position
265
+
266
+ dropdown_content.addEventListener('scroll', () => {
267
+ if (!self.settings.shouldLoadMore.call(self)) {
268
+ return;
269
+ } // !important: this will get checked again in load() but we still need to check here otherwise loading_more will be set to true
270
+
271
+
272
+ if (!canLoadMore(self.lastValue)) {
273
+ return;
274
+ } // don't call load() too much
275
+
276
+
277
+ if (loading_more) return;
278
+ loading_more = true;
279
+ self.load.call(self, self.lastValue);
280
+ });
281
+ });
282
+ }
283
+
284
+ return plugin;
277
285
 
278
286
  }));
279
287
  //# sourceMappingURL=virtual_scroll.js.map