@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,54 @@
1
+ /**
2
+ * Plugin: "dropdown_header" (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 { CBOptions } from './types.ts';
19
+
20
+ export default function(this:TomSelect, userOptions:CBOptions) {
21
+ const self = this;
22
+
23
+ const options = Object.assign({
24
+ className: 'clear-button',
25
+ title: 'Clear All',
26
+ role: 'button',
27
+ tabindex: 0,
28
+ html: (data:CBOptions) => {
29
+
30
+ return `<div class="${data.className}" title="${data.title}" role="${data.role}" tabindex="${data.tabindex}">&times;</div>`;
31
+ }
32
+ }, userOptions);
33
+
34
+ self.on('initialize',()=>{
35
+ var button = getDom(options.html(options));
36
+ button.addEventListener('click',(evt)=>{
37
+
38
+ if( self.isLocked ) return;
39
+
40
+ self.clear();
41
+
42
+ if( self.settings.mode === 'single' && self.settings.allowEmptyOption ){
43
+ self.addItem('');
44
+ }
45
+
46
+ self.refreshOptions(false);
47
+
48
+ evt.preventDefault();
49
+ evt.stopPropagation();
50
+ });
51
+ self.control.appendChild(button);
52
+ });
53
+
54
+ };
@@ -0,0 +1,8 @@
1
+
2
+ export type CBOptions = {
3
+ className ?:string,
4
+ title ?:string,
5
+ role ?:string,
6
+ tabindex ?:number
7
+ html ?: (data:CBOptions) => string,
8
+ }
@@ -0,0 +1,10 @@
1
+ .#{$select-ns}-wrapper.plugin-drag_drop {
2
+ .ts-dragging{
3
+ color:transparent !important;
4
+ }
5
+
6
+ .ts-dragging > * {
7
+ visibility:hidden !important;
8
+ }
9
+
10
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Plugin: "drag_drop" (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 { TomOption, TomItem } from '../../types/index.ts';
18
+ import { escape_html, preventDefault, addEvent } from '../../utils.ts';
19
+ import { getDom, setAttr } from '../../vanilla.ts';
20
+
21
+
22
+ const insertAfter = (referenceNode:Element, newNode:Element) => {
23
+ referenceNode.parentNode?.insertBefore(newNode, referenceNode.nextSibling);
24
+ }
25
+
26
+ const insertBefore = (referenceNode:Element, newNode:Element) => {
27
+ referenceNode.parentNode?.insertBefore(newNode, referenceNode);
28
+ }
29
+
30
+ const isBefore = (referenceNode:Element|undefined|null, newNode:Element|undefined|null) =>{
31
+
32
+ do{
33
+ newNode = newNode?.previousElementSibling;
34
+
35
+ if( referenceNode == newNode ){
36
+ return true;
37
+ }
38
+
39
+ }while( newNode && newNode.previousElementSibling );
40
+
41
+ return false;
42
+ }
43
+
44
+ export default function(this:TomSelect) {
45
+ var self = this;
46
+ if (self.settings.mode !== 'multi') return;
47
+
48
+ var orig_lock = self.lock;
49
+ var orig_unlock = self.unlock;
50
+ let sortable = true;
51
+ let drag_item:TomItem|undefined;
52
+
53
+
54
+ /**
55
+ * Add draggable attribute to item
56
+ */
57
+ self.hook('after','setupTemplates',() => {
58
+
59
+ var orig_render_item = self.settings.render.item;
60
+
61
+ self.settings.render.item = (data:TomOption, escape:typeof escape_html) => {
62
+ const item = getDom(orig_render_item.call(self, data, escape)) as TomItem;
63
+ setAttr(item,{'draggable':'true'});
64
+
65
+
66
+ // prevent doc_mousedown (see tom-select.ts)
67
+ const mousedown = (evt:Event) => {
68
+ if( !sortable ) preventDefault(evt);
69
+ evt.stopPropagation();
70
+ }
71
+
72
+ const dragStart = (evt:Event) => {
73
+ drag_item = item;
74
+
75
+ setTimeout(() => {
76
+ item.classList.add('ts-dragging');
77
+ }, 0);
78
+
79
+ }
80
+
81
+ const dragOver = (evt:Event) =>{
82
+ evt.preventDefault();
83
+ item.classList.add('ts-drag-over');
84
+ moveitem(item,drag_item);
85
+ }
86
+
87
+ const dragLeave = () => {
88
+ item.classList.remove('ts-drag-over');
89
+ }
90
+
91
+ const moveitem = (targetitem:TomItem, dragitem:TomItem|undefined) => {
92
+ if( dragitem === undefined ) return;
93
+
94
+ if( isBefore(dragitem,item) ){
95
+ insertAfter(targetitem,dragitem);
96
+ }else{
97
+ insertBefore(targetitem,dragitem);
98
+ }
99
+ }
100
+
101
+ const dragend = () => {
102
+ document.querySelectorAll('.ts-drag-over').forEach(el=> el.classList.remove('ts-drag-over'));
103
+ drag_item?.classList.remove('ts-dragging');
104
+ drag_item = undefined;
105
+
106
+ var values:string[] = [];
107
+ self.control.querySelectorAll(`[data-value]`).forEach((el:Element)=> {
108
+ if( (<HTMLOptionElement>el).dataset.value ){
109
+ let value = (<HTMLOptionElement>el).dataset.value;
110
+ if( value ){
111
+ values.push(value);
112
+ }
113
+ }
114
+ });
115
+
116
+ self.setValue(values);
117
+ }
118
+
119
+
120
+ addEvent(item,'mousedown', mousedown);
121
+ addEvent(item,'dragstart', dragStart);
122
+ addEvent(item,'dragenter', dragOver)
123
+ addEvent(item,'dragover', dragOver);
124
+ addEvent(item,'dragleave', dragLeave);
125
+ addEvent(item,'dragend', dragend);
126
+
127
+ return item;
128
+ }
129
+ });
130
+
131
+
132
+
133
+ self.hook('instead','lock',()=>{
134
+ sortable = false;
135
+ return orig_lock.call(self);
136
+ });
137
+
138
+ self.hook('instead','unlock',()=>{
139
+ sortable = true;
140
+ return orig_unlock.call(self);
141
+ });
142
+
143
+ };
@@ -0,0 +1,24 @@
1
+ .#{$select-ns}-wrapper{
2
+ .dropdown-header {
3
+ position: relative;
4
+ padding: ($select-padding-dropdown-item-y * 2) $select-padding-dropdown-item-x;
5
+ border-bottom: 1px solid $select-color-border;
6
+ background: color-mix($select-color-dropdown, $select-color-border, 85%);
7
+ border-radius: $select-border-radius $select-border-radius 0 0;
8
+ }
9
+
10
+ .dropdown-header-close {
11
+ position: absolute;
12
+ right: $select-padding-dropdown-item-x;
13
+ top: 50%;
14
+ color: $select-color-text;
15
+ opacity: 0.4;
16
+ margin-top: -12px;
17
+ line-height: 20px;
18
+ font-size: 20px !important;
19
+ }
20
+
21
+ .dropdown-header-close:hover {
22
+ color: darken($select-color-text, 25%);
23
+ }
24
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Plugin: "dropdown_header" (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 { preventDefault } from '../../utils.ts';
19
+ import { DHOptions } from './types.ts';
20
+
21
+ export default function(this:TomSelect, userOptions:DHOptions) {
22
+ const self = this;
23
+
24
+ const options = Object.assign({
25
+ title : 'Untitled',
26
+ headerClass : 'dropdown-header',
27
+ titleRowClass : 'dropdown-header-title',
28
+ labelClass : 'dropdown-header-label',
29
+ closeClass : 'dropdown-header-close',
30
+
31
+ html: (data:DHOptions) => {
32
+ return (
33
+ '<div class="' + data.headerClass + '">' +
34
+ '<div class="' + data.titleRowClass + '">' +
35
+ '<span class="' + data.labelClass + '">' + data.title + '</span>' +
36
+ '<a class="' + data.closeClass + '">&times;</a>' +
37
+ '</div>' +
38
+ '</div>'
39
+ );
40
+ }
41
+ }, userOptions);
42
+
43
+ self.on('initialize',()=>{
44
+ var header = getDom(options.html(options));
45
+
46
+ var close_link = header.querySelector('.'+options.closeClass);
47
+ if( close_link ){
48
+ close_link.addEventListener('click',(evt)=>{
49
+ preventDefault(evt,true);
50
+ self.close();
51
+ });
52
+ }
53
+
54
+ self.dropdown.insertBefore(header, self.dropdown.firstChild);
55
+ });
56
+
57
+ };
@@ -0,0 +1,9 @@
1
+
2
+ export type DHOptions = {
3
+ title ?: string,
4
+ headerClass ?: string,
5
+ titleRowClass ?: string,
6
+ labelClass ?: string,
7
+ closeClass ?: string,
8
+ html ?: (data:DHOptions) => string,
9
+ };
@@ -0,0 +1,43 @@
1
+ .plugin-dropdown_input{
2
+
3
+ &.focus.dropdown-active .#{$select-ns}-control{
4
+ box-shadow: none;
5
+ border: $select-border;
6
+ @if variable-exists(input-box-shadow) {
7
+ box-shadow: $input-box-shadow;
8
+ }
9
+ }
10
+
11
+ .dropdown-input {
12
+ border: 1px solid $select-color-border;
13
+ border-width: 0 0 1px;
14
+ display: block;
15
+ padding: $select-padding-y $select-padding-x;
16
+ box-shadow: $select-shadow-input;
17
+ width: 100%;
18
+ background: transparent;
19
+ }
20
+
21
+ &.focus .#{$select-ns}-dropdown .dropdown-input{
22
+ @if variable-exists(input-focus-border-color) {
23
+ border-color: $input-focus-border-color;
24
+ outline: 0;
25
+ @if $enable-shadows {
26
+ box-shadow: $input-box-shadow, $input-focus-box-shadow;
27
+ } @else {
28
+ box-shadow: $input-focus-box-shadow;
29
+ }
30
+ }
31
+ }
32
+
33
+ .items-placeholder{
34
+ border: 0 none !important;
35
+ box-shadow: none !important;
36
+ width: 100%;
37
+ }
38
+
39
+ &.has-items .items-placeholder,
40
+ &.dropdown-active .items-placeholder{
41
+ display: none !important;
42
+ }
43
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Plugin: "dropdown_input" (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 * as constants from '../../constants.ts';
18
+ import { getDom, addClasses } from '../../vanilla.ts';
19
+ import { addEvent, preventDefault } from '../../utils.ts';
20
+
21
+
22
+ export default function(this:TomSelect) {
23
+ const self = this;
24
+
25
+ self.settings.shouldOpen = true; // make sure the input is shown even if there are no options to display in the dropdown
26
+
27
+ self.hook('before','setup',()=>{
28
+ self.focus_node = self.control;
29
+
30
+ addClasses( self.control_input, 'dropdown-input');
31
+
32
+ const div = getDom('<div class="dropdown-input-wrap">');
33
+ div.append(self.control_input);
34
+ self.dropdown.insertBefore(div, self.dropdown.firstChild);
35
+
36
+ // set a placeholder in the select control
37
+ const placeholder = getDom('<input class="items-placeholder" tabindex="-1" />') as HTMLInputElement;
38
+ placeholder.placeholder = self.settings.placeholder ||'';
39
+ self.control.append(placeholder);
40
+ /**
41
+ * TomSelect renders a custom control with a focusable <input class="items-placeholder">.
42
+ * The source <select>'s aria-label is not automatically propagated to that input,
43
+ * which triggers "Missing form label" accessibility warnings.
44
+ * This helper copies the label from the <select> onto the generated input.
45
+ */
46
+ const label = self.input?.getAttribute('aria-label');
47
+ if (!label) return;
48
+ placeholder.setAttribute('aria-label', label);
49
+ });
50
+
51
+ self.on('initialize',()=>{
52
+ // set tabIndex on control to -1, otherwise [shift+tab] will put focus right back on control_input
53
+ self.control_input.addEventListener('keydown',(evt:KeyboardEvent) =>{
54
+ //addEvent(self.control_input,'keydown' as const,(evt:KeyboardEvent) =>{
55
+ switch( evt.keyCode ){
56
+ case constants.KEY_ESC:
57
+ if (self.isOpen) {
58
+ preventDefault(evt,true);
59
+ self.close();
60
+ }
61
+ self.clearActiveItems();
62
+ return;
63
+ case constants.KEY_TAB:
64
+ self.focus_node.tabIndex = -1;
65
+ break;
66
+ }
67
+ return self.onKeyDown.call(self,evt);
68
+ });
69
+
70
+ self.on('blur',()=>{
71
+ self.focus_node.tabIndex = self.isDisabled ? -1 : self.tabIndex;
72
+ });
73
+
74
+
75
+ // give the control_input focus when the dropdown is open
76
+ self.on('dropdown_open',() =>{
77
+ self.control_input.focus();
78
+ });
79
+
80
+ // prevent onBlur from closing when focus is on the control_input
81
+ const orig_onBlur = self.onBlur;
82
+ self.hook('instead','onBlur',(evt?:FocusEvent)=>{
83
+ if( evt && evt.relatedTarget == self.control_input ) return;
84
+ return orig_onBlur.call(self);
85
+ });
86
+
87
+ addEvent(self.control_input,'blur', () => self.onBlur() );
88
+
89
+ // return focus to control to allow further keyboard input
90
+ self.hook('before','close',() =>{
91
+
92
+ if( !self.isOpen ) return;
93
+ self.focus_node.focus({preventScroll: true});
94
+ });
95
+
96
+ });
97
+ };
@@ -0,0 +1,15 @@
1
+ .#{$select-ns}-wrapper.plugin-input_autogrow{
2
+
3
+ &.has-items .#{$select-ns}-control > input {
4
+ min-width: 0;
5
+ }
6
+
7
+ &.has-items.focus .#{$select-ns}-control > input {
8
+ flex: none;
9
+ min-width: 4px;
10
+
11
+ &::placeholder {
12
+ color:transparent;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,56 @@
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
+ import { addEvent } from '../../utils.ts';
17
+
18
+ export default function(this:TomSelect) {
19
+ var self = this;
20
+
21
+ self.on('initialize',()=>{
22
+
23
+
24
+ var test_input = document.createElement('span');
25
+ var control = self.control_input;
26
+ test_input.style.cssText = 'position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ';
27
+
28
+ self.wrapper.appendChild(test_input);
29
+
30
+
31
+ var transfer_styles = [ 'letterSpacing', 'fontSize', 'fontFamily', 'fontWeight', 'textTransform' ];
32
+
33
+ for( const style_name of transfer_styles ){
34
+ // @ts-ignore TS7015 https://stackoverflow.com/a/50506154/697576
35
+ test_input.style[style_name] = control.style[style_name];
36
+ }
37
+
38
+
39
+ /**
40
+ * Set the control width
41
+ *
42
+ */
43
+ var resize = ()=>{
44
+ test_input.textContent = control.value;
45
+ control.style.width = test_input.clientWidth+'px';
46
+ };
47
+
48
+ resize();
49
+ self.on('update item_add item_remove',resize);
50
+ addEvent(control,'input', resize );
51
+ addEvent(control,'keyup', resize );
52
+ addEvent(control,'blur', resize );
53
+ addEvent(control,'update', resize );
54
+ });
55
+
56
+ };