@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.
- package/LICENSE +202 -0
- package/README.md +104 -0
- package/dist/css/tom-select.bootstrap4.css +573 -0
- package/dist/css/tom-select.bootstrap5.css +612 -0
- package/dist/css/tom-select.css +405 -0
- package/dist/css/tom-select.default.css +497 -0
- package/dist/css/tom-select.default.css.map +1 -0
- package/dist/esm/plugins/caret_position/plugin.js +163 -0
- package/dist/esm/plugins/caret_position/plugin.js.map +1 -0
- package/dist/esm/plugins/change_listener/plugin.js +51 -0
- package/dist/esm/plugins/change_listener/plugin.js.map +1 -0
- package/dist/esm/plugins/checkbox_options/plugin.js +179 -0
- package/dist/esm/plugins/checkbox_options/plugin.js.map +1 -0
- package/dist/esm/plugins/clear_button/plugin.js +76 -0
- package/dist/esm/plugins/clear_button/plugin.js.map +1 -0
- package/dist/esm/plugins/drag_drop/plugin.js +220 -0
- package/dist/esm/plugins/drag_drop/plugin.js.map +1 -0
- package/dist/esm/plugins/dropdown_header/plugin.js +102 -0
- package/dist/esm/plugins/dropdown_header/plugin.js.map +1 -0
- package/dist/esm/plugins/dropdown_input/plugin.js +224 -0
- package/dist/esm/plugins/dropdown_input/plugin.js.map +1 -0
- package/dist/esm/plugins/input_autogrow/plugin.js +74 -0
- package/dist/esm/plugins/input_autogrow/plugin.js.map +1 -0
- package/dist/esm/plugins/local_virtual_scroll/plugin.js +305 -0
- package/dist/esm/plugins/local_virtual_scroll/plugin.js.map +1 -0
- package/dist/esm/plugins/no_active_items/plugin.js +26 -0
- package/dist/esm/plugins/no_active_items/plugin.js.map +1 -0
- package/dist/esm/plugins/no_backspace_delete/plugin.js +32 -0
- package/dist/esm/plugins/no_backspace_delete/plugin.js.map +1 -0
- package/dist/esm/plugins/optgroup_columns/plugin.js +86 -0
- package/dist/esm/plugins/optgroup_columns/plugin.js.map +1 -0
- package/dist/esm/plugins/remove_button/plugin.js +134 -0
- package/dist/esm/plugins/remove_button/plugin.js.map +1 -0
- package/dist/esm/plugins/restore_on_backspace/plugin.js +42 -0
- package/dist/esm/plugins/restore_on_backspace/plugin.js.map +1 -0
- package/dist/esm/plugins/virtual_scroll/plugin.js +272 -0
- package/dist/esm/plugins/virtual_scroll/plugin.js.map +1 -0
- package/dist/js/plugins/caret_position.js +171 -0
- package/dist/js/plugins/caret_position.js.map +1 -0
- package/dist/js/plugins/change_listener.js +59 -0
- package/dist/js/plugins/change_listener.js.map +1 -0
- package/dist/js/plugins/checkbox_options.js +187 -0
- package/dist/js/plugins/checkbox_options.js.map +1 -0
- package/dist/js/plugins/clear_button.js +84 -0
- package/dist/js/plugins/clear_button.js.map +1 -0
- package/dist/js/plugins/drag_drop.js +228 -0
- package/dist/js/plugins/drag_drop.js.map +1 -0
- package/dist/js/plugins/dropdown_header.js +110 -0
- package/dist/js/plugins/dropdown_header.js.map +1 -0
- package/dist/js/plugins/dropdown_input.js +232 -0
- package/dist/js/plugins/dropdown_input.js.map +1 -0
- package/dist/js/plugins/input_autogrow.js +82 -0
- package/dist/js/plugins/input_autogrow.js.map +1 -0
- package/dist/js/plugins/local_virtual_scroll.js +313 -0
- package/dist/js/plugins/local_virtual_scroll.js.map +1 -0
- package/dist/js/plugins/no_active_items.js +34 -0
- package/dist/js/plugins/no_active_items.js.map +1 -0
- package/dist/js/plugins/no_backspace_delete.js +40 -0
- package/dist/js/plugins/no_backspace_delete.js.map +1 -0
- package/dist/js/plugins/optgroup_columns.js +94 -0
- package/dist/js/plugins/optgroup_columns.js.map +1 -0
- package/dist/js/plugins/remove_button.js +142 -0
- package/dist/js/plugins/remove_button.js.map +1 -0
- package/dist/js/plugins/restore_on_backspace.js +50 -0
- package/dist/js/plugins/restore_on_backspace.js.map +1 -0
- package/dist/js/plugins/virtual_scroll.js +280 -0
- package/dist/js/plugins/virtual_scroll.js.map +1 -0
- package/dist/js/tom-select.base.js +4167 -0
- package/dist/js/tom-select.base.js.map +1 -0
- package/dist/js/tom-select.base.min.js +373 -0
- package/dist/js/tom-select.base.min.js.map +1 -0
- package/dist/js/tom-select.complete.js +5364 -0
- package/dist/js/tom-select.complete.js.map +1 -0
- package/dist/js/tom-select.complete.min.js +489 -0
- package/dist/js/tom-select.complete.min.js.map +1 -0
- package/dist/js/tom-select.popular.js +4436 -0
- package/dist/js/tom-select.popular.js.map +1 -0
- package/dist/js/tom-select.popular.min.js +396 -0
- package/dist/js/tom-select.popular.min.js.map +1 -0
- package/dist/types/constants.d.ts +12 -0
- package/dist/types/contrib/highlight.d.ts +13 -0
- package/dist/types/contrib/microevent.d.ts +20 -0
- package/dist/types/contrib/microplugin.d.ts +71 -0
- package/dist/types/defaults.d.ts +53 -0
- package/dist/types/getSettings.d.ts +3 -0
- package/dist/types/plugins/caret_position/plugin.d.ts +16 -0
- package/dist/types/plugins/change_listener/plugin.d.ts +16 -0
- package/dist/types/plugins/checkbox_options/plugin.d.ts +17 -0
- package/dist/types/plugins/checkbox_options/types.d.ts +14 -0
- package/dist/types/plugins/clear_button/plugin.d.ts +17 -0
- package/dist/types/plugins/clear_button/types.d.ts +7 -0
- package/dist/types/plugins/drag_drop/plugin.d.ts +16 -0
- package/dist/types/plugins/dropdown_header/plugin.d.ts +17 -0
- package/dist/types/plugins/dropdown_header/types.d.ts +8 -0
- package/dist/types/plugins/dropdown_input/plugin.d.ts +16 -0
- package/dist/types/plugins/input_autogrow/plugin.d.ts +15 -0
- package/dist/types/plugins/local_virtual_scroll/plugin.d.ts +19 -0
- package/dist/types/plugins/local_virtual_scroll/types.d.ts +14 -0
- package/dist/types/plugins/no_active_items/plugin.d.ts +15 -0
- package/dist/types/plugins/no_backspace_delete/plugin.d.ts +15 -0
- package/dist/types/plugins/optgroup_columns/plugin.d.ts +16 -0
- package/dist/types/plugins/remove_button/plugin.d.ts +17 -0
- package/dist/types/plugins/remove_button/types.d.ts +6 -0
- package/dist/types/plugins/restore_on_backspace/plugin.d.ts +21 -0
- package/dist/types/plugins/virtual_scroll/plugin.d.ts +16 -0
- package/dist/types/tom-select.complete.d.ts +2 -0
- package/dist/types/tom-select.d.ts +594 -0
- package/dist/types/tom-select.popular.d.ts +2 -0
- package/dist/types/types/core.d.ts +50 -0
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/settings.d.ts +81 -0
- package/dist/types/utils.d.ts +95 -0
- package/dist/types/vanilla.d.ts +76 -0
- package/package.json +156 -0
- package/src/constants.ts +13 -0
- package/src/contrib/highlight.ts +81 -0
- package/src/contrib/microevent.ts +73 -0
- package/src/contrib/microplugin.ts +137 -0
- package/src/defaults.ts +95 -0
- package/src/getSettings.ts +176 -0
- package/src/plugins/caret_position/plugin.ts +73 -0
- package/src/plugins/change_listener/plugin.ts +23 -0
- package/src/plugins/checkbox_options/plugin.scss +11 -0
- package/src/plugins/checkbox_options/plugin.ts +130 -0
- package/src/plugins/checkbox_options/types.ts +15 -0
- package/src/plugins/clear_button/plugin.scss +33 -0
- package/src/plugins/clear_button/plugin.ts +54 -0
- package/src/plugins/clear_button/types.ts +8 -0
- package/src/plugins/drag_drop/plugin.scss +10 -0
- package/src/plugins/drag_drop/plugin.ts +143 -0
- package/src/plugins/dropdown_header/plugin.scss +24 -0
- package/src/plugins/dropdown_header/plugin.ts +57 -0
- package/src/plugins/dropdown_header/types.ts +9 -0
- package/src/plugins/dropdown_input/plugin.scss +43 -0
- package/src/plugins/dropdown_input/plugin.ts +97 -0
- package/src/plugins/input_autogrow/plugin.scss +15 -0
- package/src/plugins/input_autogrow/plugin.ts +56 -0
- package/src/plugins/local_virtual_scroll/plugin.ts +309 -0
- package/src/plugins/local_virtual_scroll/types.ts +9 -0
- package/src/plugins/no_active_items/plugin.ts +20 -0
- package/src/plugins/no_backspace_delete/plugin.ts +30 -0
- package/src/plugins/optgroup_columns/plugin.scss +25 -0
- package/src/plugins/optgroup_columns/plugin.ts +59 -0
- package/src/plugins/remove_button/plugin.scss +70 -0
- package/src/plugins/remove_button/plugin.ts +78 -0
- package/src/plugins/remove_button/types.ts +7 -0
- package/src/plugins/restore_on_backspace/plugin.ts +44 -0
- package/src/plugins/virtual_scroll/plugin.ts +219 -0
- package/src/scss/-tom-select.bootstrap4.scss +4 -0
- package/src/scss/-tom-select.bootstrap5.scss +4 -0
- package/src/scss/_dropdown.scss +99 -0
- package/src/scss/_items.scss +114 -0
- package/src/scss/tom-select.bootstrap4.scss +218 -0
- package/src/scss/tom-select.bootstrap5.scss +270 -0
- package/src/scss/tom-select.default.scss +89 -0
- package/src/scss/tom-select.scss +179 -0
- package/src/tom-select.complete.ts +35 -0
- package/src/tom-select.popular.ts +15 -0
- package/src/tom-select.ts +2807 -0
- package/src/types/core.ts +68 -0
- package/src/types/index.ts +3 -0
- package/src/types/settings.ts +98 -0
- package/src/utils.ts +230 -0
- package/src/vanilla.ts +210 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tom Select v2.5.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.local_virtual_scroll = factory());
|
|
10
|
+
})(this, (function () { 'use strict';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Plugin: "local_virtual_scroll" (Tom Select)
|
|
14
|
+
* Copyright (c) contributors
|
|
15
|
+
*
|
|
16
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
|
17
|
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
|
18
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
+
*
|
|
20
|
+
* Virtual scroll for locally-loaded (non-AJAX) datasets.
|
|
21
|
+
* Maintains a sliding DOM window of pageSize * 3 items maximum.
|
|
22
|
+
* Supports optGroups via a flat list with interleaved headers.
|
|
23
|
+
*
|
|
24
|
+
* When the search query matches an optGroup label, all children of that
|
|
25
|
+
* group are included in the results — even if the individual options don't
|
|
26
|
+
* match the query text.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
function plugin (userOptions) {
|
|
30
|
+
var _userOptions$pageSize, _userOptions$maxDomIt, _userOptions$scrollTh;
|
|
31
|
+
const self = this;
|
|
32
|
+
const page_size = (_userOptions$pageSize = userOptions == null ? void 0 : userOptions.pageSize) != null ? _userOptions$pageSize : 50;
|
|
33
|
+
const max_dom = (_userOptions$maxDomIt = userOptions == null ? void 0 : userOptions.maxDomItems) != null ? _userOptions$maxDomIt : page_size * 3;
|
|
34
|
+
const threshold = (_userOptions$scrollTh = userOptions == null ? void 0 : userOptions.scrollThreshold) != null ? _userOptions$scrollTh : 0.9;
|
|
35
|
+
let dropdown_content;
|
|
36
|
+
let flat_list = [];
|
|
37
|
+
let visible_start = 0;
|
|
38
|
+
let visible_end = 0;
|
|
39
|
+
let is_loading = false;
|
|
40
|
+
let sentinel = null;
|
|
41
|
+
|
|
42
|
+
// RAF handle + flag to skip the scroll event caused by our own scrollTop writes
|
|
43
|
+
let raf_id = null;
|
|
44
|
+
let skip_programmatic = false;
|
|
45
|
+
|
|
46
|
+
// Plugin controls maxOptions (first page only; we manage the rest)
|
|
47
|
+
self.settings.maxOptions = page_size;
|
|
48
|
+
|
|
49
|
+
// ─── Build flat list: Sifter results + optgroup headers interleaved ───
|
|
50
|
+
//
|
|
51
|
+
// When the query matches an optGroup label, ALL options from that group
|
|
52
|
+
// are included regardless of whether the individual option text matches.
|
|
53
|
+
|
|
54
|
+
const buildFlatList = () => {
|
|
55
|
+
const flat = [];
|
|
56
|
+
const results = self.search(self.lastValue);
|
|
57
|
+
const og_field = self.settings.optgroupField;
|
|
58
|
+
const og_label_field = self.settings.optgroupLabelField || 'label';
|
|
59
|
+
const query = (self.lastValue || '').trim().toLowerCase();
|
|
60
|
+
|
|
61
|
+
// Helper: extract first optgroup value from an option
|
|
62
|
+
const getOg = option => {
|
|
63
|
+
var _og$;
|
|
64
|
+
let og = option[og_field] || '';
|
|
65
|
+
if (Array.isArray(og)) og = (_og$ = og[0]) != null ? _og$ : '';
|
|
66
|
+
return String(og);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Find optgroups whose label matches the query
|
|
70
|
+
const matching_og_labels = new Set();
|
|
71
|
+
if (query) {
|
|
72
|
+
for (const key of Object.keys(self.optgroups)) {
|
|
73
|
+
const label = String(self.optgroups[key][og_label_field] || '').toLowerCase();
|
|
74
|
+
if (label.includes(query)) matching_og_labels.add(key);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Build ordered groups + their item sets from Sifter results
|
|
79
|
+
const group_order = [];
|
|
80
|
+
const group_items = new Map();
|
|
81
|
+
for (const item of results.items) {
|
|
82
|
+
const option = self.options[item.id];
|
|
83
|
+
if (!option) continue;
|
|
84
|
+
const og = getOg(option);
|
|
85
|
+
if (!group_items.has(og)) {
|
|
86
|
+
group_items.set(og, new Set());
|
|
87
|
+
group_order.push(og);
|
|
88
|
+
}
|
|
89
|
+
group_items.get(og).add(String(item.id));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Ensure matching optgroups appear in group_order (even with no Sifter hits)
|
|
93
|
+
for (const og of matching_og_labels) {
|
|
94
|
+
if (!group_items.has(og)) {
|
|
95
|
+
group_items.set(og, new Set());
|
|
96
|
+
group_order.push(og);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Expand matching optgroups: add ALL their options (Set deduplicates)
|
|
101
|
+
if (matching_og_labels.size > 0) {
|
|
102
|
+
for (const id of Object.keys(self.options)) {
|
|
103
|
+
const option = self.options[id];
|
|
104
|
+
const og = getOg(option);
|
|
105
|
+
if (matching_og_labels.has(og)) {
|
|
106
|
+
group_items.get(og).add(id);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Emit flat list in group order
|
|
112
|
+
for (const og of group_order) {
|
|
113
|
+
const ids = group_items.get(og);
|
|
114
|
+
if (ids.size === 0) continue;
|
|
115
|
+
if (og && self.optgroups[og]) {
|
|
116
|
+
flat.push({
|
|
117
|
+
type: 'header',
|
|
118
|
+
optgroup: og
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
for (const id of ids) {
|
|
122
|
+
flat.push({
|
|
123
|
+
type: 'option',
|
|
124
|
+
id,
|
|
125
|
+
optgroup: og
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return flat;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// ─── Render a single flat item to its DOM element ─────────────────────
|
|
133
|
+
|
|
134
|
+
const renderFlatItem = item => {
|
|
135
|
+
if (item.type === 'header') {
|
|
136
|
+
var _item$el;
|
|
137
|
+
if (!item.el) {
|
|
138
|
+
item.el = self.render('optgroup_header', self.optgroups[item.optgroup]);
|
|
139
|
+
}
|
|
140
|
+
return (_item$el = item.el) != null ? _item$el : null;
|
|
141
|
+
}
|
|
142
|
+
return self.getOption(item.id, true);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// ─── Helpers ─────────────────────────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
const measureHeight = elements => elements.reduce((h, el) => {
|
|
148
|
+
var _el$offsetHeight;
|
|
149
|
+
return h + ((_el$offsetHeight = el.offsetHeight) != null ? _el$offsetHeight : 0);
|
|
150
|
+
}, 0);
|
|
151
|
+
const updateSentinel = () => {
|
|
152
|
+
// dropdown_content is set only after 'initialize' fires;
|
|
153
|
+
// refreshOptions runs during construction before that — skip silently.
|
|
154
|
+
if (!dropdown_content) return;
|
|
155
|
+
if (sentinel) {
|
|
156
|
+
sentinel.remove();
|
|
157
|
+
sentinel = null;
|
|
158
|
+
}
|
|
159
|
+
if (visible_end < flat_list.length) {
|
|
160
|
+
sentinel = self.render('loading_more', {});
|
|
161
|
+
if (sentinel) dropdown_content.append(sentinel);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const renderRange = (from, to) => {
|
|
165
|
+
const els = [];
|
|
166
|
+
for (let i = from; i < to; i++) {
|
|
167
|
+
const item = flat_list[i];
|
|
168
|
+
if (!item) continue;
|
|
169
|
+
const el = renderFlatItem(item);
|
|
170
|
+
if (el) els.push(el);
|
|
171
|
+
}
|
|
172
|
+
return els;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** Write scrollTop without triggering our own scroll handler logic */
|
|
176
|
+
const setScrollTop = value => {
|
|
177
|
+
skip_programmatic = true;
|
|
178
|
+
dropdown_content.scrollTop = value;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// ─── Load N pages forward (scroll down) ──────────────────────────────
|
|
182
|
+
|
|
183
|
+
const loadNext = pages => {
|
|
184
|
+
if (is_loading || visible_end >= flat_list.length) return;
|
|
185
|
+
is_loading = true;
|
|
186
|
+
if (sentinel) {
|
|
187
|
+
sentinel.remove();
|
|
188
|
+
sentinel = null;
|
|
189
|
+
}
|
|
190
|
+
const from = visible_end;
|
|
191
|
+
const to = Math.min(flat_list.length, visible_end + page_size * pages);
|
|
192
|
+
const new_els = renderRange(from, to);
|
|
193
|
+
for (const el of new_els) dropdown_content.append(el);
|
|
194
|
+
visible_end = to;
|
|
195
|
+
|
|
196
|
+
// Recycle items from top to stay within max_dom
|
|
197
|
+
const dom_count = visible_end - visible_start;
|
|
198
|
+
if (dom_count > max_dom) {
|
|
199
|
+
const n = dom_count - max_dom;
|
|
200
|
+
const remove_els = renderRange(visible_start, visible_start + n);
|
|
201
|
+
const removed_h = measureHeight(remove_els);
|
|
202
|
+
for (const el of remove_els) el.remove();
|
|
203
|
+
visible_start += n;
|
|
204
|
+
setScrollTop(dropdown_content.scrollTop + removed_h);
|
|
205
|
+
}
|
|
206
|
+
is_loading = false;
|
|
207
|
+
updateSentinel();
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// ─── Load N pages backward (scroll up) ───────────────────────────────
|
|
211
|
+
|
|
212
|
+
const loadPrev = pages => {
|
|
213
|
+
if (is_loading || visible_start <= 0) return;
|
|
214
|
+
is_loading = true;
|
|
215
|
+
const from = Math.max(0, visible_start - page_size * pages);
|
|
216
|
+
const to = visible_start;
|
|
217
|
+
const new_els = renderRange(from, to);
|
|
218
|
+
|
|
219
|
+
// Prepend before current first child
|
|
220
|
+
const first_child = dropdown_content.firstChild;
|
|
221
|
+
for (const el of new_els) dropdown_content.insertBefore(el, first_child);
|
|
222
|
+
|
|
223
|
+
// Compensate scrollTop so existing content stays in place
|
|
224
|
+
setScrollTop(dropdown_content.scrollTop + measureHeight(new_els));
|
|
225
|
+
visible_start = from;
|
|
226
|
+
|
|
227
|
+
// Recycle items from bottom to stay within max_dom
|
|
228
|
+
const dom_count = visible_end - visible_start;
|
|
229
|
+
if (dom_count > max_dom) {
|
|
230
|
+
const n = dom_count - max_dom;
|
|
231
|
+
const remove_els = renderRange(visible_end - n, visible_end);
|
|
232
|
+
for (const el of remove_els) el.remove();
|
|
233
|
+
visible_end -= n;
|
|
234
|
+
}
|
|
235
|
+
is_loading = false;
|
|
236
|
+
updateSentinel();
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// ─── Scroll handler with RAF debounce ─────────────────────────────────
|
|
240
|
+
|
|
241
|
+
const handleScroll = () => {
|
|
242
|
+
const {
|
|
243
|
+
scrollTop,
|
|
244
|
+
scrollHeight,
|
|
245
|
+
clientHeight
|
|
246
|
+
} = dropdown_content;
|
|
247
|
+
const pct_bottom = (scrollTop + clientHeight) / scrollHeight;
|
|
248
|
+
const pct_top = scrollTop / scrollHeight;
|
|
249
|
+
|
|
250
|
+
// Always load exactly 1 page per RAF frame.
|
|
251
|
+
// The RAF debounce already coalesces rapid scroll events, so there is no
|
|
252
|
+
// need to load multiple pages at once — that only causes long DOM operations.
|
|
253
|
+
if (pct_bottom >= threshold) {
|
|
254
|
+
loadNext(1);
|
|
255
|
+
} else if (pct_top <= 1 - threshold) {
|
|
256
|
+
loadPrev(1);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// ─── Reset virtual state on each refreshOptions ───────────────────────
|
|
261
|
+
|
|
262
|
+
self.hook('before', 'refreshOptions', () => {
|
|
263
|
+
self.settings.maxOptions = page_size;
|
|
264
|
+
});
|
|
265
|
+
self.hook('after', 'refreshOptions', () => {
|
|
266
|
+
flat_list = buildFlatList();
|
|
267
|
+
visible_start = 0;
|
|
268
|
+
visible_end = Math.min(flat_list.length, page_size);
|
|
269
|
+
is_loading = false;
|
|
270
|
+
if (raf_id !== null) {
|
|
271
|
+
cancelAnimationFrame(raf_id);
|
|
272
|
+
raf_id = null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Re-render first page from flat_list to keep DOM in sync.
|
|
276
|
+
// refreshOptions may render items in optgroup wrappers or a different
|
|
277
|
+
// order than our flat list; clearing and re-rendering ensures consistency.
|
|
278
|
+
if (dropdown_content && flat_list.length > 0) {
|
|
279
|
+
dropdown_content.innerHTML = '';
|
|
280
|
+
const first_page = renderRange(0, visible_end);
|
|
281
|
+
for (const el of first_page) dropdown_content.append(el);
|
|
282
|
+
}
|
|
283
|
+
updateSentinel();
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// ─── Initialize: set templates and attach scroll listener ────────────
|
|
287
|
+
|
|
288
|
+
self.on('initialize', () => {
|
|
289
|
+
dropdown_content = self.dropdown_content;
|
|
290
|
+
// Disable overflow-anchor so the browser doesn't auto-compensate scrollTop
|
|
291
|
+
// when we insert/remove items — we handle the compensation manually.
|
|
292
|
+
dropdown_content.style['overflow-anchor'] = 'none';
|
|
293
|
+
self.settings.render = Object.assign({}, {
|
|
294
|
+
loading_more: () => '<div class="loading-more-results">Carregando mais resultados...</div>'
|
|
295
|
+
}, self.settings.render);
|
|
296
|
+
dropdown_content.addEventListener('scroll', () => {
|
|
297
|
+
if (skip_programmatic) {
|
|
298
|
+
skip_programmatic = false;
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (raf_id !== null) cancelAnimationFrame(raf_id);
|
|
302
|
+
raf_id = requestAnimationFrame(() => {
|
|
303
|
+
raf_id = null;
|
|
304
|
+
handleScroll();
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return plugin;
|
|
311
|
+
|
|
312
|
+
}));
|
|
313
|
+
//# sourceMappingURL=local_virtual_scroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local_virtual_scroll.js","sources":["../../../src/plugins/local_virtual_scroll/plugin.ts"],"sourcesContent":["/**\n * Plugin: \"local_virtual_scroll\" (Tom Select)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Virtual scroll for locally-loaded (non-AJAX) datasets.\n * Maintains a sliding DOM window of pageSize * 3 items maximum.\n * Supports optGroups via a flat list with interleaved headers.\n *\n * When the search query matches an optGroup label, all children of that\n * group are included in the results — even if the individual options don't\n * match the query text.\n */\n\nimport type TomSelect from '../../tom-select.ts';\nimport type { LVSOptions, FlatItem } from './types.ts';\n\nexport default function (this: TomSelect, userOptions: LVSOptions) {\n\tconst self = this;\n\tconst page_size = userOptions?.pageSize ?? 50;\n\tconst max_dom = userOptions?.maxDomItems ?? page_size * 3;\n\tconst threshold = userOptions?.scrollThreshold ?? 0.9;\n\n\tlet dropdown_content: HTMLElement;\n\tlet flat_list: FlatItem[] = [];\n\tlet visible_start = 0;\n\tlet visible_end = 0;\n\tlet is_loading = false;\n\tlet sentinel: HTMLElement | null = null;\n\n\t// RAF handle + flag to skip the scroll event caused by our own scrollTop writes\n\tlet raf_id: number | null = null;\n\tlet skip_programmatic = false;\n\n\t// Plugin controls maxOptions (first page only; we manage the rest)\n\tself.settings.maxOptions = page_size;\n\n\t// ─── Build flat list: Sifter results + optgroup headers interleaved ───\n\t//\n\t// When the query matches an optGroup label, ALL options from that group\n\t// are included regardless of whether the individual option text matches.\n\n\tconst buildFlatList = (): FlatItem[] => {\n\t\tconst flat: FlatItem[] = [];\n\t\tconst results = self.search(self.lastValue);\n\t\tconst og_field = self.settings.optgroupField;\n\t\tconst og_label_field =\n\t\t\t(self.settings as any).optgroupLabelField || 'label';\n\t\tconst query = (self.lastValue || '').trim().toLowerCase();\n\n\t\t// Helper: extract first optgroup value from an option\n\t\tconst getOg = (option: any): string => {\n\t\t\tlet og = option[og_field] || '';\n\t\t\tif (Array.isArray(og)) og = og[0] ?? '';\n\t\t\treturn String(og);\n\t\t};\n\n\t\t// Find optgroups whose label matches the query\n\t\tconst matching_og_labels = new Set<string>();\n\t\tif (query) {\n\t\t\tfor (const key of Object.keys(self.optgroups)) {\n\t\t\t\tconst label = String(\n\t\t\t\t\t(self.optgroups[key] as any)[og_label_field] || '',\n\t\t\t\t).toLowerCase();\n\t\t\t\tif (label.includes(query)) matching_og_labels.add(key);\n\t\t\t}\n\t\t}\n\n\t\t// Build ordered groups + their item sets from Sifter results\n\t\tconst group_order: string[] = [];\n\t\tconst group_items = new Map<string, Set<string>>();\n\n\t\tfor (const item of results.items) {\n\t\t\tconst option = self.options[item.id];\n\t\t\tif (!option) continue;\n\t\t\tconst og = getOg(option);\n\t\t\tif (!group_items.has(og)) {\n\t\t\t\tgroup_items.set(og, new Set());\n\t\t\t\tgroup_order.push(og);\n\t\t\t}\n\t\t\tgroup_items.get(og)!.add(String(item.id));\n\t\t}\n\n\t\t// Ensure matching optgroups appear in group_order (even with no Sifter hits)\n\t\tfor (const og of matching_og_labels) {\n\t\t\tif (!group_items.has(og)) {\n\t\t\t\tgroup_items.set(og, new Set());\n\t\t\t\tgroup_order.push(og);\n\t\t\t}\n\t\t}\n\n\t\t// Expand matching optgroups: add ALL their options (Set deduplicates)\n\t\tif (matching_og_labels.size > 0) {\n\t\t\tfor (const id of Object.keys(self.options)) {\n\t\t\t\tconst option = self.options[id];\n\t\t\t\tconst og = getOg(option);\n\t\t\t\tif (matching_og_labels.has(og)) {\n\t\t\t\t\tgroup_items.get(og)!.add(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Emit flat list in group order\n\t\tfor (const og of group_order) {\n\t\t\tconst ids = group_items.get(og)!;\n\t\t\tif (ids.size === 0) continue;\n\t\t\tif (og && self.optgroups[og]) {\n\t\t\t\tflat.push({ type: 'header', optgroup: og });\n\t\t\t}\n\t\t\tfor (const id of ids) {\n\t\t\t\tflat.push({ type: 'option', id, optgroup: og });\n\t\t\t}\n\t\t}\n\n\t\treturn flat;\n\t};\n\n\t// ─── Render a single flat item to its DOM element ─────────────────────\n\n\tconst renderFlatItem = (item: FlatItem): HTMLElement | null => {\n\t\tif (item.type === 'header') {\n\t\t\tif (!item.el) {\n\t\t\t\titem.el = self.render(\n\t\t\t\t\t'optgroup_header',\n\t\t\t\t\tself.optgroups[item.optgroup],\n\t\t\t\t) as HTMLElement;\n\t\t\t}\n\t\t\treturn item.el ?? null;\n\t\t}\n\t\treturn self.getOption(item.id, true) as HTMLElement;\n\t};\n\n\t// ─── Helpers ─────────────────────────────────────────────────────────\n\n\tconst measureHeight = (elements: HTMLElement[]): number =>\n\t\telements.reduce((h, el) => h + (el.offsetHeight ?? 0), 0);\n\n\tconst updateSentinel = () => {\n\t\t// dropdown_content is set only after 'initialize' fires;\n\t\t// refreshOptions runs during construction before that — skip silently.\n\t\tif (!dropdown_content) return;\n\t\tif (sentinel) {\n\t\t\tsentinel.remove();\n\t\t\tsentinel = null;\n\t\t}\n\t\tif (visible_end < flat_list.length) {\n\t\t\tsentinel = self.render('loading_more', {}) as HTMLElement;\n\t\t\tif (sentinel) dropdown_content.append(sentinel);\n\t\t}\n\t};\n\n\tconst renderRange = (from: number, to: number): HTMLElement[] => {\n\t\tconst els: HTMLElement[] = [];\n\t\tfor (let i = from; i < to; i++) {\n\t\t\tconst item = flat_list[i];\n\t\t\tif (!item) continue;\n\t\t\tconst el = renderFlatItem(item);\n\t\t\tif (el) els.push(el);\n\t\t}\n\t\treturn els;\n\t};\n\n\t/** Write scrollTop without triggering our own scroll handler logic */\n\tconst setScrollTop = (value: number) => {\n\t\tskip_programmatic = true;\n\t\tdropdown_content.scrollTop = value;\n\t};\n\n\t// ─── Load N pages forward (scroll down) ──────────────────────────────\n\n\tconst loadNext = (pages: number) => {\n\t\tif (is_loading || visible_end >= flat_list.length) return;\n\t\tis_loading = true;\n\t\tif (sentinel) {\n\t\t\tsentinel.remove();\n\t\t\tsentinel = null;\n\t\t}\n\n\t\tconst from = visible_end;\n\t\tconst to = Math.min(flat_list.length, visible_end + page_size * pages);\n\t\tconst new_els = renderRange(from, to);\n\t\tfor (const el of new_els) dropdown_content.append(el);\n\t\tvisible_end = to;\n\n\t\t// Recycle items from top to stay within max_dom\n\t\tconst dom_count = visible_end - visible_start;\n\t\tif (dom_count > max_dom) {\n\t\t\tconst n = dom_count - max_dom;\n\t\t\tconst remove_els = renderRange(visible_start, visible_start + n);\n\t\t\tconst removed_h = measureHeight(remove_els);\n\t\t\tfor (const el of remove_els) el.remove();\n\t\t\tvisible_start += n;\n\t\t\tsetScrollTop(dropdown_content.scrollTop + removed_h);\n\t\t}\n\n\t\tis_loading = false;\n\t\tupdateSentinel();\n\t};\n\n\t// ─── Load N pages backward (scroll up) ───────────────────────────────\n\n\tconst loadPrev = (pages: number) => {\n\t\tif (is_loading || visible_start <= 0) return;\n\t\tis_loading = true;\n\n\t\tconst from = Math.max(0, visible_start - page_size * pages);\n\t\tconst to = visible_start;\n\t\tconst new_els = renderRange(from, to);\n\n\t\t// Prepend before current first child\n\t\tconst first_child = dropdown_content.firstChild;\n\t\tfor (const el of new_els)\n\t\t\tdropdown_content.insertBefore(el, first_child);\n\n\t\t// Compensate scrollTop so existing content stays in place\n\t\tsetScrollTop(dropdown_content.scrollTop + measureHeight(new_els));\n\t\tvisible_start = from;\n\n\t\t// Recycle items from bottom to stay within max_dom\n\t\tconst dom_count = visible_end - visible_start;\n\t\tif (dom_count > max_dom) {\n\t\t\tconst n = dom_count - max_dom;\n\t\t\tconst remove_els = renderRange(visible_end - n, visible_end);\n\t\t\tfor (const el of remove_els) el.remove();\n\t\t\tvisible_end -= n;\n\t\t}\n\n\t\tis_loading = false;\n\t\tupdateSentinel();\n\t};\n\n\t// ─── Scroll handler with RAF debounce ─────────────────────────────────\n\n\tconst handleScroll = () => {\n\t\tconst { scrollTop, scrollHeight, clientHeight } = dropdown_content;\n\t\tconst pct_bottom = (scrollTop + clientHeight) / scrollHeight;\n\t\tconst pct_top = scrollTop / scrollHeight;\n\n\t\t// Always load exactly 1 page per RAF frame.\n\t\t// The RAF debounce already coalesces rapid scroll events, so there is no\n\t\t// need to load multiple pages at once — that only causes long DOM operations.\n\t\tif (pct_bottom >= threshold) {\n\t\t\tloadNext(1);\n\t\t} else if (pct_top <= 1 - threshold) {\n\t\t\tloadPrev(1);\n\t\t}\n\t};\n\n\t// ─── Reset virtual state on each refreshOptions ───────────────────────\n\n\tself.hook('before', 'refreshOptions', () => {\n\t\tself.settings.maxOptions = page_size;\n\t});\n\n\tself.hook('after', 'refreshOptions', () => {\n\t\tflat_list = buildFlatList();\n\t\tvisible_start = 0;\n\t\tvisible_end = Math.min(flat_list.length, page_size);\n\t\tis_loading = false;\n\t\tif (raf_id !== null) {\n\t\t\tcancelAnimationFrame(raf_id);\n\t\t\traf_id = null;\n\t\t}\n\n\t\t// Re-render first page from flat_list to keep DOM in sync.\n\t\t// refreshOptions may render items in optgroup wrappers or a different\n\t\t// order than our flat list; clearing and re-rendering ensures consistency.\n\t\tif (dropdown_content && flat_list.length > 0) {\n\t\t\tdropdown_content.innerHTML = '';\n\t\t\tconst first_page = renderRange(0, visible_end);\n\t\t\tfor (const el of first_page) dropdown_content.append(el);\n\t\t}\n\n\t\tupdateSentinel();\n\t});\n\n\t// ─── Initialize: set templates and attach scroll listener ────────────\n\n\tself.on('initialize', () => {\n\t\tdropdown_content = self.dropdown_content;\n\t\t// Disable overflow-anchor so the browser doesn't auto-compensate scrollTop\n\t\t// when we insert/remove items — we handle the compensation manually.\n\t\t(dropdown_content.style as any)['overflow-anchor'] = 'none';\n\n\t\tself.settings.render = Object.assign(\n\t\t\t{},\n\t\t\t{\n\t\t\t\tloading_more: () =>\n\t\t\t\t\t'<div class=\"loading-more-results\">Carregando mais resultados...</div>',\n\t\t\t},\n\t\t\tself.settings.render,\n\t\t);\n\n\t\tdropdown_content.addEventListener('scroll', () => {\n\t\t\tif (skip_programmatic) {\n\t\t\t\tskip_programmatic = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (raf_id !== null) cancelAnimationFrame(raf_id);\n\t\t\traf_id = requestAnimationFrame(() => {\n\t\t\t\traf_id = null;\n\t\t\t\thandleScroll();\n\t\t\t});\n\t\t});\n\t});\n}\n"],"names":["userOptions","_userOptions$pageSize","_userOptions$maxDomIt","_userOptions$scrollTh","self","page_size","pageSize","max_dom","maxDomItems","threshold","scrollThreshold","dropdown_content","flat_list","visible_start","visible_end","is_loading","sentinel","raf_id","skip_programmatic","settings","maxOptions","buildFlatList","flat","results","search","lastValue","og_field","optgroupField","og_label_field","optgroupLabelField","query","trim","toLowerCase","getOg","option","_og$","og","Array","isArray","String","matching_og_labels","Set","key","Object","keys","optgroups","label","includes","add","group_order","group_items","Map","item","items","options","id","has","set","push","get","size","ids","type","optgroup","renderFlatItem","_item$el","el","render","getOption","measureHeight","elements","reduce","h","_el$offsetHeight","offsetHeight","updateSentinel","remove","length","append","renderRange","from","to","els","i","setScrollTop","value","scrollTop","loadNext","pages","Math","min","new_els","dom_count","n","remove_els","removed_h","loadPrev","max","first_child","firstChild","insertBefore","handleScroll","scrollHeight","clientHeight","pct_bottom","pct_top","hook","cancelAnimationFrame","innerHTML","first_page","on","style","assign","loading_more","addEventListener","requestAnimationFrame"],"mappings":";;;;;;;;;;;CAAA;CACA;CAC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AAC,GAAG,MAAM;KAE3D3G,IAAI,CAACe,QAAQ,CAACgD,MAAM,GAAGxB,MAAM,CAACqE,MAAM,CACnC,EAAE,EACF;OACCC,YAAY,EAAEA,MACb;CACF,KAAC,EACD7G,IAAI,CAACe,QAAQ,CAACgD,MACf,CAAC;CAEDxD,IAAAA,gBAAgB,CAACuG,gBAAgB,CAAC,QAAQ,EAAE,MAAM;CACjD,MAAA,IAAIhG,iBAAiB,EAAE;CACtBA,QAAAA,iBAAiB,GAAG,KAAK;CACzB,QAAA;CACD,MAAA;CACA,MAAA,IAAID,MAAM,KAAK,IAAI,EAAE0F,oBAAoB,CAAC1F,MAAM,CAAC;OACjDA,MAAM,GAAGkG,qBAAqB,CAAC,MAAM;CACpClG,QAAAA,MAAM,GAAG,IAAI;CACboF,QAAAA,YAAY,EAAE;CACf,MAAA,CAAC,CAAC;CACH,IAAA,CAAC,CAAC;CACH,EAAA,CAAC,CAAC;CACH;;;;;;;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tom Select v2.5.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.no_active_items = factory());
|
|
10
|
+
})(this, (function () { 'use strict';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Plugin: "no_active_items" (Tom Select)
|
|
14
|
+
*
|
|
15
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
|
16
|
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
20
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
21
|
+
* ANY KIND, either express or implied. See the License for the specific language
|
|
22
|
+
* governing permissions and limitations under the License.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
function plugin () {
|
|
27
|
+
this.hook('instead', 'setActiveItem', () => {});
|
|
28
|
+
this.hook('instead', 'selectAll', () => {});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return plugin;
|
|
32
|
+
|
|
33
|
+
}));
|
|
34
|
+
//# sourceMappingURL=no_active_items.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no_active_items.js","sources":["../../../src/plugins/no_active_items/plugin.ts"],"sourcesContent":["/**\n * Plugin: \"no_active_items\" (Tom Select)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport type TomSelect from '../../tom-select.ts';\n\nexport default function(this:TomSelect) {\n\tthis.hook('instead','setActiveItem',() => {});\n\tthis.hook('instead','selectAll',() => {});\n};\n"],"names":["hook"],"mappings":";;;;;;;;;;;CAAA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAIe,eAAA,IAAyB;GACvC,IAAI,CAACA,IAAI,CAAC,SAAS,EAAC,eAAe,EAAC,MAAM,CAAC,CAAC,CAAC;GAC7C,IAAI,CAACA,IAAI,CAAC,SAAS,EAAC,WAAW,EAAC,MAAM,CAAC,CAAC,CAAC;CAC1C;;;;;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tom Select v2.5.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.no_backspace_delete = factory());
|
|
10
|
+
})(this, (function () { 'use strict';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Plugin: "input_autogrow" (Tom Select)
|
|
14
|
+
*
|
|
15
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
|
16
|
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
20
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
21
|
+
* ANY KIND, either express or implied. See the License for the specific language
|
|
22
|
+
* governing permissions and limitations under the License.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
function plugin () {
|
|
27
|
+
var self = this;
|
|
28
|
+
var orig_deleteSelection = self.deleteSelection;
|
|
29
|
+
this.hook('instead', 'deleteSelection', evt => {
|
|
30
|
+
if (self.activeItems.length) {
|
|
31
|
+
return orig_deleteSelection.call(self, evt);
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return plugin;
|
|
38
|
+
|
|
39
|
+
}));
|
|
40
|
+
//# sourceMappingURL=no_backspace_delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no_backspace_delete.js","sources":["../../../src/plugins/no_backspace_delete/plugin.ts"],"sourcesContent":["/**\n * Plugin: \"input_autogrow\" (Tom Select)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport type TomSelect from '../../tom-select.ts';\n\nexport default function(this:TomSelect) {\n\tvar self = this;\n\tvar orig_deleteSelection = self.deleteSelection;\n\n\tthis.hook('instead','deleteSelection',(evt:KeyboardEvent) => {\n\n\t\tif( self.activeItems.length ){\n\t\t\treturn orig_deleteSelection.call(self, evt);\n\t\t}\n\n\t\treturn false;\n\t});\n\n};\n"],"names":["self","orig_deleteSelection","deleteSelection","hook","evt","activeItems","length","call"],"mappings":";;;;;;;;;;;CAAA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAIe,eAAA,IAAyB;GACvC,IAAIA,IAAI,GAAG,IAAI;CACf,EAAA,IAAIC,oBAAoB,GAAGD,IAAI,CAACE,eAAe;GAE/C,IAAI,CAACC,IAAI,CAAC,SAAS,EAAC,iBAAiB,EAAEC,GAAiB,IAAK;CAE5D,IAAA,IAAIJ,IAAI,CAACK,WAAW,CAACC,MAAM,EAAE;CAC5B,MAAA,OAAOL,oBAAoB,CAACM,IAAI,CAACP,IAAI,EAAEI,GAAG,CAAC;CAC5C,IAAA;CAEA,IAAA,OAAO,KAAK;CACb,EAAA,CAAC,CAAC;CAEH;;;;;;;;"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tom Select v2.5.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.optgroup_columns = factory());
|
|
10
|
+
})(this, (function () { 'use strict';
|
|
11
|
+
|
|
12
|
+
const KEY_LEFT = 37;
|
|
13
|
+
const KEY_RIGHT = 39;
|
|
14
|
+
// ctrl key or apple key for ma
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get the closest node to the evt.target matching the selector
|
|
18
|
+
* Stops at wrapper
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
const parentMatch = (target, selector, wrapper) => {
|
|
22
|
+
while (target && target.matches) {
|
|
23
|
+
if (target.matches(selector)) {
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
target = target.parentNode;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get the index of an element amongst sibling nodes of the same type
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
const nodeIndex = (el, amongst) => {
|
|
35
|
+
if (!el) return -1;
|
|
36
|
+
amongst = amongst || el.nodeName;
|
|
37
|
+
var i = 0;
|
|
38
|
+
while (el = el.previousElementSibling) {
|
|
39
|
+
if (el.matches(amongst)) {
|
|
40
|
+
i++;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return i;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Plugin: "optgroup_columns" (Tom Select.js)
|
|
48
|
+
* Copyright (c) contributors
|
|
49
|
+
*
|
|
50
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
|
51
|
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
|
52
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
53
|
+
*
|
|
54
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
55
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
56
|
+
* ANY KIND, either express or implied. See the License for the specific language
|
|
57
|
+
* governing permissions and limitations under the License.
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
function plugin () {
|
|
62
|
+
var self = this;
|
|
63
|
+
var orig_keydown = self.onKeyDown;
|
|
64
|
+
self.hook('instead', 'onKeyDown', evt => {
|
|
65
|
+
var index, option, options, optgroup;
|
|
66
|
+
if (!self.isOpen || !(evt.keyCode === KEY_LEFT || evt.keyCode === KEY_RIGHT)) {
|
|
67
|
+
return orig_keydown.call(self, evt);
|
|
68
|
+
}
|
|
69
|
+
self.ignoreHover = true;
|
|
70
|
+
optgroup = parentMatch(self.activeOption, '[data-group]');
|
|
71
|
+
index = nodeIndex(self.activeOption, '[data-selectable]');
|
|
72
|
+
if (!optgroup) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (evt.keyCode === KEY_LEFT) {
|
|
76
|
+
optgroup = optgroup.previousSibling;
|
|
77
|
+
} else {
|
|
78
|
+
optgroup = optgroup.nextSibling;
|
|
79
|
+
}
|
|
80
|
+
if (!optgroup) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
options = optgroup.querySelectorAll('[data-selectable]');
|
|
84
|
+
option = options[Math.min(options.length - 1, index)];
|
|
85
|
+
if (option) {
|
|
86
|
+
self.setActiveOption(option);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return plugin;
|
|
92
|
+
|
|
93
|
+
}));
|
|
94
|
+
//# sourceMappingURL=optgroup_columns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optgroup_columns.js","sources":["../../../src/constants.ts","../../../src/vanilla.ts","../../../src/plugins/optgroup_columns/plugin.ts"],"sourcesContent":["export const KEY_A\t\t\t\t= 65;\nexport const KEY_RETURN\t\t\t= 13;\nexport const KEY_ESC\t\t\t= 27;\nexport const KEY_LEFT\t\t\t= 37;\nexport const KEY_UP\t\t\t\t= 38;\nexport const KEY_RIGHT\t\t\t= 39;\nexport const KEY_DOWN\t\t\t= 40;\nexport const KEY_BACKSPACE\t\t= 8;\nexport const KEY_DELETE\t\t\t= 46;\nexport const KEY_TAB\t\t\t= 9;\n\nexport const IS_MAC \t\t= typeof navigator === 'undefined' ? false : /Mac/.test(navigator.userAgent);\nexport const KEY_SHORTCUT\t\t= IS_MAC ? 'metaKey' : 'ctrlKey'; // ctrl key or apple key for ma\n","\nimport { iterate } from './utils.ts';\n\n/**\n * Return a dom element from either a dom query string, jQuery object, a dom element or html string\n * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518\n *\n * param query should be {}\n */\nexport const getDom = ( query:any ):HTMLElement => {\n\n\tif( query.jquery ){\n\t\treturn query[0];\n\t}\n\n\tif( query instanceof HTMLElement ){\n\t\treturn query;\n\t}\n\n\tif( isHtmlString(query) ){\n\t\tvar tpl = document.createElement('template');\n\t\ttpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result\n\t\treturn tpl.content.firstChild as HTMLElement;\n\t}\n\n\treturn document.querySelector(query);\n};\n\nexport const isHtmlString = (arg:any): boolean => {\n\tif( typeof arg === 'string' && arg.indexOf('<') > -1 ){\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nexport const escapeQuery = (query:string):string => {\n\treturn query.replace(/['\"\\\\]/g, '\\\\$&');\n}\n\n/**\n * Dispatch an event\n *\n */\nexport const triggerEvent = ( dom_el:HTMLElement, event_name:string ):void => {\n\tvar event = document.createEvent('HTMLEvents');\n\tevent.initEvent(event_name, true, false);\n\tdom_el.dispatchEvent(event)\n};\n\n/**\n * Apply CSS rules to a dom element\n *\n */\nexport const applyCSS = ( dom_el:HTMLElement, css:{ [key: string]: string|number }):void => {\n\tObject.assign(dom_el.style, css);\n}\n\n\n/**\n * Add css classes\n *\n */\nexport const addClasses = ( elmts:HTMLElement|HTMLElement[], ...classes:string[]|string[][] ) => {\n\n\tvar norm_classes \t= classesArray(classes);\n\telmts\t\t\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tnorm_classes.map( cls => {\n\t\t\tel.classList.add( cls );\n\t\t});\n\t});\n}\n\n/**\n * Remove css classes\n *\n */\n export const removeClasses = ( elmts:HTMLElement|HTMLElement[], ...classes:string[]|string[][] ) => {\n\n \tvar norm_classes \t= classesArray(classes);\n\telmts\t\t\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tnorm_classes.map(cls => {\n\t \t\tel.classList.remove( cls );\n\t\t});\n \t});\n }\n\n\n/**\n * Return arguments\n *\n */\nexport const classesArray = (args:string[]|string[][]):string[] => {\n\tvar classes:string[] = [];\n\titerate( args, (_classes) =>{\n\t\tif( typeof _classes === 'string' ){\n\t\t\t_classes = _classes.trim().split(/[\\t\\n\\f\\r\\s]/);\n\t\t}\n\t\tif( Array.isArray(_classes) ){\n\t\t\tclasses = classes.concat(_classes);\n\t\t}\n\t});\n\n\treturn classes.filter(Boolean);\n}\n\n\n/**\n * Create an array from arg if it's not already an array\n *\n */\nexport const castAsArray = (arg:any):Array<any> => {\n\tif( !Array.isArray(arg) ){\n \t\targ = [arg];\n \t}\n\treturn arg;\n}\n\n\n/**\n * Get the closest node to the evt.target matching the selector\n * Stops at wrapper\n *\n */\nexport const parentMatch = ( target:null|HTMLElement, selector:string, wrapper?:HTMLElement ):HTMLElement|void => {\n\n\tif( wrapper && !wrapper.contains(target) ){\n\t\treturn;\n\t}\n\n\twhile( target && target.matches ){\n\n\t\tif( target.matches(selector) ){\n\t\t\treturn target;\n\t\t}\n\n\t\ttarget = target.parentNode as HTMLElement;\n\t}\n}\n\n\n/**\n * Get the first or last item from an array\n *\n * > 0 - right (last)\n * <= 0 - left (first)\n *\n */\nexport const getTail = ( list:Array<any>|NodeList, direction:number=0 ):any => {\n\n\tif( direction > 0 ){\n\t\treturn list[list.length-1];\n\t}\n\n\treturn list[0];\n}\n\n/**\n * Return true if an object is empty\n *\n */\nexport const isEmptyObject = (obj:object):boolean => {\n\treturn (Object.keys(obj).length === 0);\n}\n\n\n/**\n * Get the index of an element amongst sibling nodes of the same type\n *\n */\nexport const nodeIndex = ( el:null|Element, amongst?:string ):number => {\n\tif (!el) return -1;\n\n\tamongst = amongst || el.nodeName;\n\n\tvar i = 0;\n\twhile( el = el.previousElementSibling ){\n\n\t\tif( el.matches(amongst) ){\n\t\t\ti++;\n\t\t}\n\t}\n\treturn i;\n}\n\n\n/**\n * Set attributes of an element\n *\n */\nexport const setAttr = (el:Element,attrs:{ [key: string]: null|string|number }) => {\n\titerate( attrs,(val,attr) => {\n\t\tif( val == null ){\n\t\t\tel.removeAttribute(attr as string);\n\t\t}else{\n\t\t\tel.setAttribute(attr as string, ''+val);\n\t\t}\n\t});\n}\n\n\n/**\n * Replace a node\n */\nexport const replaceNode = ( existing:Node, replacement:Node ) => {\n\tif( existing.parentNode ) existing.parentNode.replaceChild(replacement, existing);\n}\n","/**\n * Plugin: \"optgroup_columns\" (Tom Select.js)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport type TomSelect from '../../tom-select.ts';\nimport * as constants from '../../constants.ts';\nimport { parentMatch, nodeIndex } from '../../vanilla.ts';\n\nexport default function(this:TomSelect) {\n\tvar self = this;\n\n\tvar orig_keydown = self.onKeyDown;\n\n\tself.hook('instead','onKeyDown',(evt:KeyboardEvent)=>{\n\t\tvar index, option, options, optgroup;\n\n\t\tif( !self.isOpen || !(evt.keyCode === constants.KEY_LEFT || evt.keyCode === constants.KEY_RIGHT)) {\n\t\t\treturn orig_keydown.call(self,evt);\n\t\t}\n\n\t\tself.ignoreHover\t= true;\n\t\toptgroup\t\t\t= parentMatch(self.activeOption,'[data-group]');\n\t\tindex\t\t\t\t= nodeIndex(self.activeOption,'[data-selectable]');\n\n\t\tif( !optgroup ){\n\t\t\treturn;\n\t\t}\n\n\t\tif( evt.keyCode === constants.KEY_LEFT ){\n\t\t\toptgroup = optgroup.previousSibling;\n\t\t} else {\n\t\t\toptgroup = optgroup.nextSibling;\n\t\t}\n\n\t\tif( !optgroup ){\n\t\t\treturn;\n\t\t}\n\n\t\toptions\t\t\t\t= (<HTMLOptGroupElement>optgroup).querySelectorAll('[data-selectable]');\n\t\toption\t\t\t\t= options[ Math.min(options.length - 1, index) ] as HTMLElement;\n\n\t\tif( option ){\n\t\t\tself.setActiveOption(option);\n\t\t}\n\n\t});\n\n};\n"],"names":["KEY_LEFT","KEY_RIGHT","parentMatch","target","selector","wrapper","matches","parentNode","nodeIndex","el","amongst","nodeName","i","previousElementSibling","self","orig_keydown","onKeyDown","hook","evt","index","option","options","optgroup","isOpen","keyCode","constants","call","ignoreHover","activeOption","previousSibling","nextSibling","querySelectorAll","Math","min","length","setActiveOption"],"mappings":";;;;;;;;;;;CAGO,MAAMA,QAAQ,GAAK,EAAE;CAErB,MAAMC,SAAS,GAAK,EAAE;CAO+B;;CC8G5D;CACA;CACA;CACA;CACA;CACO,MAAMC,WAAW,GAAGA,CAAEC,MAAuB,EAAEC,QAAe,EAAEC,OAAoB,KAAuB;CAMjH,EAAA,OAAOF,MAAM,IAAIA,MAAM,CAACG,OAAO,EAAE;CAEhC,IAAA,IAAIH,MAAM,CAACG,OAAO,CAACF,QAAQ,CAAC,EAAE;CAC7B,MAAA,OAAOD,MAAM;CACd,IAAA;KAEAA,MAAM,GAAGA,MAAM,CAACI,UAAyB;CAC1C,EAAA;CACD,CAAC;;CA4BD;CACA;CACA;CACA;CACO,MAAMC,SAAS,GAAGA,CAAEC,EAAe,EAAEC,OAAe,KAAa;CACvE,EAAA,IAAI,CAACD,EAAE,EAAE,OAAO,EAAE;CAElBC,EAAAA,OAA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