@drecchia/tom-select 2.5.2-virtual-scroll.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +104 -0
  3. package/dist/css/tom-select.bootstrap4.css +573 -0
  4. package/dist/css/tom-select.bootstrap5.css +612 -0
  5. package/dist/css/tom-select.css +405 -0
  6. package/dist/css/tom-select.default.css +497 -0
  7. package/dist/css/tom-select.default.css.map +1 -0
  8. package/dist/esm/plugins/caret_position/plugin.js +163 -0
  9. package/dist/esm/plugins/caret_position/plugin.js.map +1 -0
  10. package/dist/esm/plugins/change_listener/plugin.js +51 -0
  11. package/dist/esm/plugins/change_listener/plugin.js.map +1 -0
  12. package/dist/esm/plugins/checkbox_options/plugin.js +179 -0
  13. package/dist/esm/plugins/checkbox_options/plugin.js.map +1 -0
  14. package/dist/esm/plugins/clear_button/plugin.js +76 -0
  15. package/dist/esm/plugins/clear_button/plugin.js.map +1 -0
  16. package/dist/esm/plugins/drag_drop/plugin.js +220 -0
  17. package/dist/esm/plugins/drag_drop/plugin.js.map +1 -0
  18. package/dist/esm/plugins/dropdown_header/plugin.js +102 -0
  19. package/dist/esm/plugins/dropdown_header/plugin.js.map +1 -0
  20. package/dist/esm/plugins/dropdown_input/plugin.js +224 -0
  21. package/dist/esm/plugins/dropdown_input/plugin.js.map +1 -0
  22. package/dist/esm/plugins/input_autogrow/plugin.js +74 -0
  23. package/dist/esm/plugins/input_autogrow/plugin.js.map +1 -0
  24. package/dist/esm/plugins/local_virtual_scroll/plugin.js +305 -0
  25. package/dist/esm/plugins/local_virtual_scroll/plugin.js.map +1 -0
  26. package/dist/esm/plugins/no_active_items/plugin.js +26 -0
  27. package/dist/esm/plugins/no_active_items/plugin.js.map +1 -0
  28. package/dist/esm/plugins/no_backspace_delete/plugin.js +32 -0
  29. package/dist/esm/plugins/no_backspace_delete/plugin.js.map +1 -0
  30. package/dist/esm/plugins/optgroup_columns/plugin.js +86 -0
  31. package/dist/esm/plugins/optgroup_columns/plugin.js.map +1 -0
  32. package/dist/esm/plugins/remove_button/plugin.js +134 -0
  33. package/dist/esm/plugins/remove_button/plugin.js.map +1 -0
  34. package/dist/esm/plugins/restore_on_backspace/plugin.js +42 -0
  35. package/dist/esm/plugins/restore_on_backspace/plugin.js.map +1 -0
  36. package/dist/esm/plugins/virtual_scroll/plugin.js +272 -0
  37. package/dist/esm/plugins/virtual_scroll/plugin.js.map +1 -0
  38. package/dist/js/plugins/caret_position.js +171 -0
  39. package/dist/js/plugins/caret_position.js.map +1 -0
  40. package/dist/js/plugins/change_listener.js +59 -0
  41. package/dist/js/plugins/change_listener.js.map +1 -0
  42. package/dist/js/plugins/checkbox_options.js +187 -0
  43. package/dist/js/plugins/checkbox_options.js.map +1 -0
  44. package/dist/js/plugins/clear_button.js +84 -0
  45. package/dist/js/plugins/clear_button.js.map +1 -0
  46. package/dist/js/plugins/drag_drop.js +228 -0
  47. package/dist/js/plugins/drag_drop.js.map +1 -0
  48. package/dist/js/plugins/dropdown_header.js +110 -0
  49. package/dist/js/plugins/dropdown_header.js.map +1 -0
  50. package/dist/js/plugins/dropdown_input.js +232 -0
  51. package/dist/js/plugins/dropdown_input.js.map +1 -0
  52. package/dist/js/plugins/input_autogrow.js +82 -0
  53. package/dist/js/plugins/input_autogrow.js.map +1 -0
  54. package/dist/js/plugins/local_virtual_scroll.js +313 -0
  55. package/dist/js/plugins/local_virtual_scroll.js.map +1 -0
  56. package/dist/js/plugins/no_active_items.js +34 -0
  57. package/dist/js/plugins/no_active_items.js.map +1 -0
  58. package/dist/js/plugins/no_backspace_delete.js +40 -0
  59. package/dist/js/plugins/no_backspace_delete.js.map +1 -0
  60. package/dist/js/plugins/optgroup_columns.js +94 -0
  61. package/dist/js/plugins/optgroup_columns.js.map +1 -0
  62. package/dist/js/plugins/remove_button.js +142 -0
  63. package/dist/js/plugins/remove_button.js.map +1 -0
  64. package/dist/js/plugins/restore_on_backspace.js +50 -0
  65. package/dist/js/plugins/restore_on_backspace.js.map +1 -0
  66. package/dist/js/plugins/virtual_scroll.js +280 -0
  67. package/dist/js/plugins/virtual_scroll.js.map +1 -0
  68. package/dist/js/tom-select.base.js +4167 -0
  69. package/dist/js/tom-select.base.js.map +1 -0
  70. package/dist/js/tom-select.base.min.js +373 -0
  71. package/dist/js/tom-select.base.min.js.map +1 -0
  72. package/dist/js/tom-select.complete.js +5364 -0
  73. package/dist/js/tom-select.complete.js.map +1 -0
  74. package/dist/js/tom-select.complete.min.js +489 -0
  75. package/dist/js/tom-select.complete.min.js.map +1 -0
  76. package/dist/js/tom-select.popular.js +4436 -0
  77. package/dist/js/tom-select.popular.js.map +1 -0
  78. package/dist/js/tom-select.popular.min.js +396 -0
  79. package/dist/js/tom-select.popular.min.js.map +1 -0
  80. package/dist/types/constants.d.ts +12 -0
  81. package/dist/types/contrib/highlight.d.ts +13 -0
  82. package/dist/types/contrib/microevent.d.ts +20 -0
  83. package/dist/types/contrib/microplugin.d.ts +71 -0
  84. package/dist/types/defaults.d.ts +53 -0
  85. package/dist/types/getSettings.d.ts +3 -0
  86. package/dist/types/plugins/caret_position/plugin.d.ts +16 -0
  87. package/dist/types/plugins/change_listener/plugin.d.ts +16 -0
  88. package/dist/types/plugins/checkbox_options/plugin.d.ts +17 -0
  89. package/dist/types/plugins/checkbox_options/types.d.ts +14 -0
  90. package/dist/types/plugins/clear_button/plugin.d.ts +17 -0
  91. package/dist/types/plugins/clear_button/types.d.ts +7 -0
  92. package/dist/types/plugins/drag_drop/plugin.d.ts +16 -0
  93. package/dist/types/plugins/dropdown_header/plugin.d.ts +17 -0
  94. package/dist/types/plugins/dropdown_header/types.d.ts +8 -0
  95. package/dist/types/plugins/dropdown_input/plugin.d.ts +16 -0
  96. package/dist/types/plugins/input_autogrow/plugin.d.ts +15 -0
  97. package/dist/types/plugins/local_virtual_scroll/plugin.d.ts +19 -0
  98. package/dist/types/plugins/local_virtual_scroll/types.d.ts +14 -0
  99. package/dist/types/plugins/no_active_items/plugin.d.ts +15 -0
  100. package/dist/types/plugins/no_backspace_delete/plugin.d.ts +15 -0
  101. package/dist/types/plugins/optgroup_columns/plugin.d.ts +16 -0
  102. package/dist/types/plugins/remove_button/plugin.d.ts +17 -0
  103. package/dist/types/plugins/remove_button/types.d.ts +6 -0
  104. package/dist/types/plugins/restore_on_backspace/plugin.d.ts +21 -0
  105. package/dist/types/plugins/virtual_scroll/plugin.d.ts +16 -0
  106. package/dist/types/tom-select.complete.d.ts +2 -0
  107. package/dist/types/tom-select.d.ts +594 -0
  108. package/dist/types/tom-select.popular.d.ts +2 -0
  109. package/dist/types/types/core.d.ts +50 -0
  110. package/dist/types/types/index.d.ts +2 -0
  111. package/dist/types/types/settings.d.ts +81 -0
  112. package/dist/types/utils.d.ts +95 -0
  113. package/dist/types/vanilla.d.ts +76 -0
  114. package/package.json +156 -0
  115. package/src/constants.ts +13 -0
  116. package/src/contrib/highlight.ts +81 -0
  117. package/src/contrib/microevent.ts +73 -0
  118. package/src/contrib/microplugin.ts +137 -0
  119. package/src/defaults.ts +95 -0
  120. package/src/getSettings.ts +176 -0
  121. package/src/plugins/caret_position/plugin.ts +73 -0
  122. package/src/plugins/change_listener/plugin.ts +23 -0
  123. package/src/plugins/checkbox_options/plugin.scss +11 -0
  124. package/src/plugins/checkbox_options/plugin.ts +130 -0
  125. package/src/plugins/checkbox_options/types.ts +15 -0
  126. package/src/plugins/clear_button/plugin.scss +33 -0
  127. package/src/plugins/clear_button/plugin.ts +54 -0
  128. package/src/plugins/clear_button/types.ts +8 -0
  129. package/src/plugins/drag_drop/plugin.scss +10 -0
  130. package/src/plugins/drag_drop/plugin.ts +143 -0
  131. package/src/plugins/dropdown_header/plugin.scss +24 -0
  132. package/src/plugins/dropdown_header/plugin.ts +57 -0
  133. package/src/plugins/dropdown_header/types.ts +9 -0
  134. package/src/plugins/dropdown_input/plugin.scss +43 -0
  135. package/src/plugins/dropdown_input/plugin.ts +97 -0
  136. package/src/plugins/input_autogrow/plugin.scss +15 -0
  137. package/src/plugins/input_autogrow/plugin.ts +56 -0
  138. package/src/plugins/local_virtual_scroll/plugin.ts +309 -0
  139. package/src/plugins/local_virtual_scroll/types.ts +9 -0
  140. package/src/plugins/no_active_items/plugin.ts +20 -0
  141. package/src/plugins/no_backspace_delete/plugin.ts +30 -0
  142. package/src/plugins/optgroup_columns/plugin.scss +25 -0
  143. package/src/plugins/optgroup_columns/plugin.ts +59 -0
  144. package/src/plugins/remove_button/plugin.scss +70 -0
  145. package/src/plugins/remove_button/plugin.ts +78 -0
  146. package/src/plugins/remove_button/types.ts +7 -0
  147. package/src/plugins/restore_on_backspace/plugin.ts +44 -0
  148. package/src/plugins/virtual_scroll/plugin.ts +219 -0
  149. package/src/scss/-tom-select.bootstrap4.scss +4 -0
  150. package/src/scss/-tom-select.bootstrap5.scss +4 -0
  151. package/src/scss/_dropdown.scss +99 -0
  152. package/src/scss/_items.scss +114 -0
  153. package/src/scss/tom-select.bootstrap4.scss +218 -0
  154. package/src/scss/tom-select.bootstrap5.scss +270 -0
  155. package/src/scss/tom-select.default.scss +89 -0
  156. package/src/scss/tom-select.scss +179 -0
  157. package/src/tom-select.complete.ts +35 -0
  158. package/src/tom-select.popular.ts +15 -0
  159. package/src/tom-select.ts +2807 -0
  160. package/src/types/core.ts +68 -0
  161. package/src/types/index.ts +3 -0
  162. package/src/types/settings.ts +98 -0
  163. package/src/utils.ts +230 -0
  164. package/src/vanilla.ts +210 -0
@@ -0,0 +1,309 @@
1
+ /**
2
+ * Plugin: "local_virtual_scroll" (Tom Select)
3
+ * Copyright (c) contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of the License at:
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Virtual scroll for locally-loaded (non-AJAX) datasets.
10
+ * Maintains a sliding DOM window of pageSize * 3 items maximum.
11
+ * Supports optGroups via a flat list with interleaved headers.
12
+ *
13
+ * When the search query matches an optGroup label, all children of that
14
+ * group are included in the results — even if the individual options don't
15
+ * match the query text.
16
+ */
17
+
18
+ import type TomSelect from '../../tom-select.ts';
19
+ import type { LVSOptions, FlatItem } from './types.ts';
20
+
21
+ export default function (this: TomSelect, userOptions: LVSOptions) {
22
+ const self = this;
23
+ const page_size = userOptions?.pageSize ?? 50;
24
+ const max_dom = userOptions?.maxDomItems ?? page_size * 3;
25
+ const threshold = userOptions?.scrollThreshold ?? 0.9;
26
+
27
+ let dropdown_content: HTMLElement;
28
+ let flat_list: FlatItem[] = [];
29
+ let visible_start = 0;
30
+ let visible_end = 0;
31
+ let is_loading = false;
32
+ let sentinel: HTMLElement | null = null;
33
+
34
+ // RAF handle + flag to skip the scroll event caused by our own scrollTop writes
35
+ let raf_id: number | null = null;
36
+ let skip_programmatic = false;
37
+
38
+ // Plugin controls maxOptions (first page only; we manage the rest)
39
+ self.settings.maxOptions = page_size;
40
+
41
+ // ─── Build flat list: Sifter results + optgroup headers interleaved ───
42
+ //
43
+ // When the query matches an optGroup label, ALL options from that group
44
+ // are included regardless of whether the individual option text matches.
45
+
46
+ const buildFlatList = (): FlatItem[] => {
47
+ const flat: FlatItem[] = [];
48
+ const results = self.search(self.lastValue);
49
+ const og_field = self.settings.optgroupField;
50
+ const og_label_field =
51
+ (self.settings as any).optgroupLabelField || 'label';
52
+ const query = (self.lastValue || '').trim().toLowerCase();
53
+
54
+ // Helper: extract first optgroup value from an option
55
+ const getOg = (option: any): string => {
56
+ let og = option[og_field] || '';
57
+ if (Array.isArray(og)) og = og[0] ?? '';
58
+ return String(og);
59
+ };
60
+
61
+ // Find optgroups whose label matches the query
62
+ const matching_og_labels = new Set<string>();
63
+ if (query) {
64
+ for (const key of Object.keys(self.optgroups)) {
65
+ const label = String(
66
+ (self.optgroups[key] as any)[og_label_field] || '',
67
+ ).toLowerCase();
68
+ if (label.includes(query)) matching_og_labels.add(key);
69
+ }
70
+ }
71
+
72
+ // Build ordered groups + their item sets from Sifter results
73
+ const group_order: string[] = [];
74
+ const group_items = new Map<string, Set<string>>();
75
+
76
+ for (const item of results.items) {
77
+ const option = self.options[item.id];
78
+ if (!option) continue;
79
+ const og = getOg(option);
80
+ if (!group_items.has(og)) {
81
+ group_items.set(og, new Set());
82
+ group_order.push(og);
83
+ }
84
+ group_items.get(og)!.add(String(item.id));
85
+ }
86
+
87
+ // Ensure matching optgroups appear in group_order (even with no Sifter hits)
88
+ for (const og of matching_og_labels) {
89
+ if (!group_items.has(og)) {
90
+ group_items.set(og, new Set());
91
+ group_order.push(og);
92
+ }
93
+ }
94
+
95
+ // Expand matching optgroups: add ALL their options (Set deduplicates)
96
+ if (matching_og_labels.size > 0) {
97
+ for (const id of Object.keys(self.options)) {
98
+ const option = self.options[id];
99
+ const og = getOg(option);
100
+ if (matching_og_labels.has(og)) {
101
+ group_items.get(og)!.add(id);
102
+ }
103
+ }
104
+ }
105
+
106
+ // Emit flat list in group order
107
+ for (const og of group_order) {
108
+ const ids = group_items.get(og)!;
109
+ if (ids.size === 0) continue;
110
+ if (og && self.optgroups[og]) {
111
+ flat.push({ type: 'header', optgroup: og });
112
+ }
113
+ for (const id of ids) {
114
+ flat.push({ type: 'option', id, optgroup: og });
115
+ }
116
+ }
117
+
118
+ return flat;
119
+ };
120
+
121
+ // ─── Render a single flat item to its DOM element ─────────────────────
122
+
123
+ const renderFlatItem = (item: FlatItem): HTMLElement | null => {
124
+ if (item.type === 'header') {
125
+ if (!item.el) {
126
+ item.el = self.render(
127
+ 'optgroup_header',
128
+ self.optgroups[item.optgroup],
129
+ ) as HTMLElement;
130
+ }
131
+ return item.el ?? null;
132
+ }
133
+ return self.getOption(item.id, true) as HTMLElement;
134
+ };
135
+
136
+ // ─── Helpers ─────────────────────────────────────────────────────────
137
+
138
+ const measureHeight = (elements: HTMLElement[]): number =>
139
+ elements.reduce((h, el) => h + (el.offsetHeight ?? 0), 0);
140
+
141
+ const updateSentinel = () => {
142
+ // dropdown_content is set only after 'initialize' fires;
143
+ // refreshOptions runs during construction before that — skip silently.
144
+ if (!dropdown_content) return;
145
+ if (sentinel) {
146
+ sentinel.remove();
147
+ sentinel = null;
148
+ }
149
+ if (visible_end < flat_list.length) {
150
+ sentinel = self.render('loading_more', {}) as HTMLElement;
151
+ if (sentinel) dropdown_content.append(sentinel);
152
+ }
153
+ };
154
+
155
+ const renderRange = (from: number, to: number): HTMLElement[] => {
156
+ const els: HTMLElement[] = [];
157
+ for (let i = from; i < to; i++) {
158
+ const item = flat_list[i];
159
+ if (!item) continue;
160
+ const el = renderFlatItem(item);
161
+ if (el) els.push(el);
162
+ }
163
+ return els;
164
+ };
165
+
166
+ /** Write scrollTop without triggering our own scroll handler logic */
167
+ const setScrollTop = (value: number) => {
168
+ skip_programmatic = true;
169
+ dropdown_content.scrollTop = value;
170
+ };
171
+
172
+ // ─── Load N pages forward (scroll down) ──────────────────────────────
173
+
174
+ const loadNext = (pages: number) => {
175
+ if (is_loading || visible_end >= flat_list.length) return;
176
+ is_loading = true;
177
+ if (sentinel) {
178
+ sentinel.remove();
179
+ sentinel = null;
180
+ }
181
+
182
+ const from = visible_end;
183
+ const to = Math.min(flat_list.length, visible_end + page_size * pages);
184
+ const new_els = renderRange(from, to);
185
+ for (const el of new_els) dropdown_content.append(el);
186
+ visible_end = to;
187
+
188
+ // Recycle items from top to stay within max_dom
189
+ const dom_count = visible_end - visible_start;
190
+ if (dom_count > max_dom) {
191
+ const n = dom_count - max_dom;
192
+ const remove_els = renderRange(visible_start, visible_start + n);
193
+ const removed_h = measureHeight(remove_els);
194
+ for (const el of remove_els) el.remove();
195
+ visible_start += n;
196
+ setScrollTop(dropdown_content.scrollTop + removed_h);
197
+ }
198
+
199
+ is_loading = false;
200
+ updateSentinel();
201
+ };
202
+
203
+ // ─── Load N pages backward (scroll up) ───────────────────────────────
204
+
205
+ const loadPrev = (pages: number) => {
206
+ if (is_loading || visible_start <= 0) return;
207
+ is_loading = true;
208
+
209
+ const from = Math.max(0, visible_start - page_size * pages);
210
+ const to = visible_start;
211
+ const new_els = renderRange(from, to);
212
+
213
+ // Prepend before current first child
214
+ const first_child = dropdown_content.firstChild;
215
+ for (const el of new_els)
216
+ dropdown_content.insertBefore(el, first_child);
217
+
218
+ // Compensate scrollTop so existing content stays in place
219
+ setScrollTop(dropdown_content.scrollTop + measureHeight(new_els));
220
+ visible_start = from;
221
+
222
+ // Recycle items from bottom to stay within max_dom
223
+ const dom_count = visible_end - visible_start;
224
+ if (dom_count > max_dom) {
225
+ const n = dom_count - max_dom;
226
+ const remove_els = renderRange(visible_end - n, visible_end);
227
+ for (const el of remove_els) el.remove();
228
+ visible_end -= n;
229
+ }
230
+
231
+ is_loading = false;
232
+ updateSentinel();
233
+ };
234
+
235
+ // ─── Scroll handler with RAF debounce ─────────────────────────────────
236
+
237
+ const handleScroll = () => {
238
+ const { scrollTop, scrollHeight, clientHeight } = dropdown_content;
239
+ const pct_bottom = (scrollTop + clientHeight) / scrollHeight;
240
+ const pct_top = scrollTop / scrollHeight;
241
+
242
+ // Always load exactly 1 page per RAF frame.
243
+ // The RAF debounce already coalesces rapid scroll events, so there is no
244
+ // need to load multiple pages at once — that only causes long DOM operations.
245
+ if (pct_bottom >= threshold) {
246
+ loadNext(1);
247
+ } else if (pct_top <= 1 - threshold) {
248
+ loadPrev(1);
249
+ }
250
+ };
251
+
252
+ // ─── Reset virtual state on each refreshOptions ───────────────────────
253
+
254
+ self.hook('before', 'refreshOptions', () => {
255
+ self.settings.maxOptions = page_size;
256
+ });
257
+
258
+ self.hook('after', 'refreshOptions', () => {
259
+ flat_list = buildFlatList();
260
+ visible_start = 0;
261
+ visible_end = Math.min(flat_list.length, page_size);
262
+ is_loading = false;
263
+ if (raf_id !== null) {
264
+ cancelAnimationFrame(raf_id);
265
+ raf_id = null;
266
+ }
267
+
268
+ // Re-render first page from flat_list to keep DOM in sync.
269
+ // refreshOptions may render items in optgroup wrappers or a different
270
+ // order than our flat list; clearing and re-rendering ensures consistency.
271
+ if (dropdown_content && flat_list.length > 0) {
272
+ dropdown_content.innerHTML = '';
273
+ const first_page = renderRange(0, visible_end);
274
+ for (const el of first_page) dropdown_content.append(el);
275
+ }
276
+
277
+ updateSentinel();
278
+ });
279
+
280
+ // ─── Initialize: set templates and attach scroll listener ────────────
281
+
282
+ self.on('initialize', () => {
283
+ dropdown_content = self.dropdown_content;
284
+ // Disable overflow-anchor so the browser doesn't auto-compensate scrollTop
285
+ // when we insert/remove items — we handle the compensation manually.
286
+ (dropdown_content.style as any)['overflow-anchor'] = 'none';
287
+
288
+ self.settings.render = Object.assign(
289
+ {},
290
+ {
291
+ loading_more: () =>
292
+ '<div class="loading-more-results">Carregando mais resultados...</div>',
293
+ },
294
+ self.settings.render,
295
+ );
296
+
297
+ dropdown_content.addEventListener('scroll', () => {
298
+ if (skip_programmatic) {
299
+ skip_programmatic = false;
300
+ return;
301
+ }
302
+ if (raf_id !== null) cancelAnimationFrame(raf_id);
303
+ raf_id = requestAnimationFrame(() => {
304
+ raf_id = null;
305
+ handleScroll();
306
+ });
307
+ });
308
+ });
309
+ }
@@ -0,0 +1,9 @@
1
+ export type LVSOptions = {
2
+ pageSize?: number; // items per page, default: 50
3
+ maxDomItems?: number; // max items in DOM, default: pageSize * 3
4
+ scrollThreshold?: number; // 0-1, default: 0.9
5
+ };
6
+
7
+ export type FlatItem =
8
+ | { type: 'header'; optgroup: string; el?: HTMLElement }
9
+ | { type: 'option'; id: string; optgroup: string };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Plugin: "no_active_items" (Tom Select)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
5
+ * file except in compliance with the License. You may obtain a copy of the License at:
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software distributed under
9
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
10
+ * ANY KIND, either express or implied. See the License for the specific language
11
+ * governing permissions and limitations under the License.
12
+ *
13
+ */
14
+
15
+ import type TomSelect from '../../tom-select.ts';
16
+
17
+ export default function(this:TomSelect) {
18
+ this.hook('instead','setActiveItem',() => {});
19
+ this.hook('instead','selectAll',() => {});
20
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Plugin: "input_autogrow" (Tom Select)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
5
+ * file except in compliance with the License. You may obtain a copy of the License at:
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software distributed under
9
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
10
+ * ANY KIND, either express or implied. See the License for the specific language
11
+ * governing permissions and limitations under the License.
12
+ *
13
+ */
14
+
15
+ import type TomSelect from '../../tom-select.ts';
16
+
17
+ export default function(this:TomSelect) {
18
+ var self = this;
19
+ var orig_deleteSelection = self.deleteSelection;
20
+
21
+ this.hook('instead','deleteSelection',(evt:KeyboardEvent) => {
22
+
23
+ if( self.activeItems.length ){
24
+ return orig_deleteSelection.call(self, evt);
25
+ }
26
+
27
+ return false;
28
+ });
29
+
30
+ };
@@ -0,0 +1,25 @@
1
+ .#{$select-ns}-dropdown.plugin-optgroup_columns {
2
+ .ts-dropdown-content{
3
+ display: flex;
4
+ }
5
+
6
+ .optgroup {
7
+ border-right: 1px solid #f2f2f2;
8
+ border-top: 0 none;
9
+ flex-grow: 1;
10
+ flex-basis: 0;
11
+ min-width: 0;
12
+ }
13
+
14
+ .optgroup:last-child {
15
+ border-right: 0 none;
16
+ }
17
+
18
+ .optgroup::before {
19
+ display: none;
20
+ }
21
+
22
+ .optgroup-header {
23
+ border-top: 0 none;
24
+ }
25
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Plugin: "optgroup_columns" (Tom Select.js)
3
+ * Copyright (c) contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of the License at:
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ * ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ *
14
+ */
15
+
16
+ import type TomSelect from '../../tom-select.ts';
17
+ import * as constants from '../../constants.ts';
18
+ import { parentMatch, nodeIndex } from '../../vanilla.ts';
19
+
20
+ export default function(this:TomSelect) {
21
+ var self = this;
22
+
23
+ var orig_keydown = self.onKeyDown;
24
+
25
+ self.hook('instead','onKeyDown',(evt:KeyboardEvent)=>{
26
+ var index, option, options, optgroup;
27
+
28
+ if( !self.isOpen || !(evt.keyCode === constants.KEY_LEFT || evt.keyCode === constants.KEY_RIGHT)) {
29
+ return orig_keydown.call(self,evt);
30
+ }
31
+
32
+ self.ignoreHover = true;
33
+ optgroup = parentMatch(self.activeOption,'[data-group]');
34
+ index = nodeIndex(self.activeOption,'[data-selectable]');
35
+
36
+ if( !optgroup ){
37
+ return;
38
+ }
39
+
40
+ if( evt.keyCode === constants.KEY_LEFT ){
41
+ optgroup = optgroup.previousSibling;
42
+ } else {
43
+ optgroup = optgroup.nextSibling;
44
+ }
45
+
46
+ if( !optgroup ){
47
+ return;
48
+ }
49
+
50
+ options = (<HTMLOptGroupElement>optgroup).querySelectorAll('[data-selectable]');
51
+ option = options[ Math.min(options.length - 1, index) ] as HTMLElement;
52
+
53
+ if( option ){
54
+ self.setActiveOption(option);
55
+ }
56
+
57
+ });
58
+
59
+ };
@@ -0,0 +1,70 @@
1
+ .#{$select-ns}-wrapper.plugin-remove_button{
2
+ .item {
3
+ display: inline-flex;
4
+ align-items: center;
5
+ }
6
+
7
+ .item .remove {
8
+ color: inherit;
9
+ text-decoration: none;
10
+ vertical-align: middle;
11
+ display: inline-block;
12
+ padding: 0 $select-padding-item-x;
13
+ border-radius: 0 2px 2px 0;
14
+ box-sizing: border-box;
15
+ }
16
+
17
+ .item .remove:hover {
18
+ background: rgba(0, 0, 0, 5%);
19
+ }
20
+
21
+ &.disabled .item .remove:hover {
22
+ background: none;
23
+ }
24
+
25
+
26
+ .remove-single {
27
+ position: absolute;
28
+ right: 0;
29
+ top: 0;
30
+ font-size: 23px;
31
+ }
32
+ }
33
+
34
+ .#{$select-ns}-wrapper.plugin-remove_button:not(.rtl){
35
+ .item {
36
+ padding-right: 0 !important;
37
+ }
38
+
39
+ .item .remove {
40
+ border-left: 1px solid $select-color-item-border;
41
+ margin-left: $select-padding-item-x;
42
+ }
43
+
44
+ .item.active .remove {
45
+ border-left-color: $select-color-item-active-border;
46
+ }
47
+
48
+ &.disabled .item .remove {
49
+ border-left-color: lighten(desaturate($select-color-item-border, 100%), $select-lighten-disabled-item-border);
50
+ }
51
+ }
52
+
53
+ .#{$select-ns}-wrapper.plugin-remove_button.rtl {
54
+ .item {
55
+ padding-left: 0 !important;
56
+ }
57
+
58
+ .item .remove {
59
+ border-right: 1px solid $select-color-item-border;
60
+ margin-right: $select-padding-item-x;
61
+ }
62
+
63
+ .item.active .remove {
64
+ border-right-color: $select-color-item-active-border;
65
+ }
66
+
67
+ &.disabled .item .remove {
68
+ border-right-color: lighten(desaturate($select-color-item-border, 100%), $select-lighten-disabled-item-border);
69
+ }
70
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Plugin: "remove_button" (Tom Select)
3
+ * Copyright (c) contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of the License at:
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ * ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ *
14
+ */
15
+
16
+ import type TomSelect from '../../tom-select.ts';
17
+ import { getDom } from '../../vanilla.ts';
18
+ import { escape_html, preventDefault, addEvent } from '../../utils.ts';
19
+ import { TomOption, TomItem } from '../../types/index.ts';
20
+ import { RBOptions } from './types.ts';
21
+
22
+ export default function(this:TomSelect, userOptions:RBOptions) {
23
+
24
+ const options = Object.assign({
25
+ label : '&times;',
26
+ title : 'Remove',
27
+ className : 'remove',
28
+ append : true
29
+ }, userOptions);
30
+
31
+
32
+ //options.className = 'remove-single';
33
+ var self = this;
34
+
35
+ // override the render method to add remove button to each item
36
+ if( !options.append ){
37
+ return;
38
+ }
39
+
40
+ var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>';
41
+
42
+ self.hook('after','setupTemplates',() => {
43
+
44
+ var orig_render_item = self.settings.render.item;
45
+
46
+ self.settings.render.item = (data:TomOption, escape:typeof escape_html) => {
47
+
48
+ var item = getDom(orig_render_item.call(self, data, escape)) as TomItem;
49
+
50
+ var close_button = getDom(html);
51
+ item.appendChild(close_button);
52
+
53
+ addEvent(close_button,'mousedown',(evt) => {
54
+ preventDefault(evt,true);
55
+ });
56
+
57
+ addEvent(close_button,'click',(evt) => {
58
+
59
+ if( self.isLocked ) return;
60
+
61
+ // propagating will trigger the dropdown to show for single mode
62
+ preventDefault(evt,true);
63
+
64
+ if( self.isLocked ) return;
65
+ if( !self.shouldDelete([item],evt as MouseEvent) ) return;
66
+
67
+ self.removeItem(item);
68
+ self.refreshOptions(false);
69
+ self.inputState();
70
+ });
71
+
72
+ return item;
73
+ };
74
+
75
+ });
76
+
77
+
78
+ };
@@ -0,0 +1,7 @@
1
+
2
+ export type RBOptions = {
3
+ label ?: string,
4
+ title ?: string,
5
+ className ?: string,
6
+ append ?: boolean
7
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Plugin: "restore_on_backspace" (Tom Select)
3
+ * Copyright (c) contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of the License at:
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ * ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ *
14
+ */
15
+ import type TomSelect from '../../tom-select.ts';
16
+ import { TomOption } from '../../types/index.ts';
17
+
18
+ type TPluginOptions = {
19
+ text?:(option:TomOption)=>string,
20
+ };
21
+
22
+ export default function(this:TomSelect, userOptions:TPluginOptions) {
23
+ const self = this;
24
+
25
+ const options = Object.assign({
26
+ text: (option:TomOption) => {
27
+ return option[self.settings.labelField];
28
+ }
29
+ },userOptions);
30
+
31
+ self.on('item_remove',function(value:string){
32
+ if( !self.isFocused ){
33
+ return;
34
+ }
35
+
36
+ if( self.control_input.value.trim() === '' ){
37
+ var option = self.options[value];
38
+ if( option ){
39
+ self.setTextboxValue(options.text.call(self, option));
40
+ }
41
+ }
42
+ });
43
+
44
+ };