@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,59 @@
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.change_listener = factory());
10
+ })(this, (function () { 'use strict';
11
+
12
+ /**
13
+ * Converts a scalar to its best string representation
14
+ * for hash keys and HTML attribute values.
15
+ *
16
+ * Transformations:
17
+ * 'str' -> 'str'
18
+ * null -> ''
19
+ * undefined -> ''
20
+ * true -> '1'
21
+ * false -> '0'
22
+ * 0 -> '0'
23
+ * 1 -> '1'
24
+ *
25
+ */
26
+
27
+ /**
28
+ * Add event helper
29
+ *
30
+ */
31
+ const addEvent = (target, type, callback, options) => {
32
+ target.addEventListener(type, callback, options);
33
+ };
34
+
35
+ /**
36
+ * Plugin: "change_listener" (Tom Select)
37
+ * Copyright (c) contributors
38
+ *
39
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
40
+ * file except in compliance with the License. You may obtain a copy of the License at:
41
+ * http://www.apache.org/licenses/LICENSE-2.0
42
+ *
43
+ * Unless required by applicable law or agreed to in writing, software distributed under
44
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
45
+ * ANY KIND, either express or implied. See the License for the specific language
46
+ * governing permissions and limitations under the License.
47
+ *
48
+ */
49
+
50
+ function plugin () {
51
+ addEvent(this.input, 'change', () => {
52
+ this.sync();
53
+ });
54
+ }
55
+
56
+ return plugin;
57
+
58
+ }));
59
+ //# sourceMappingURL=change_listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change_listener.js","sources":["../../../src/utils.ts","../../../src/plugins/change_listener/plugin.ts"],"sourcesContent":["\nimport type TomSelect from './tom-select.ts';\nimport { TomLoadCallback } from './types/index.ts';\n\n\n/**\n * Converts a scalar to its best string representation\n * for hash keys and HTML attribute values.\n *\n * Transformations:\n * 'str' -> 'str'\n * null -> ''\n * undefined -> ''\n * true -> '1'\n * false -> '0'\n * 0 -> '0'\n * 1 -> '1'\n *\n */\nexport const hash_key = (value:undefined|null|boolean|string|number):string|null => {\n\tif (typeof value === 'undefined' || value === null) return null;\n\treturn get_hash(value);\n};\n\nexport const get_hash = (value:boolean|string|number):string => {\n\tif (typeof value === 'boolean') return value ? '1' : '0';\n\treturn value + '';\n};\n\n/**\n * Escapes a string for use within HTML.\n *\n */\nexport const escape_html = (str:string):string => {\n\treturn (str + '')\n\t\t.replace(/&/g, '&amp;')\n\t\t.replace(/</g, '&lt;')\n\t\t.replace(/>/g, '&gt;')\n\t\t.replace(/\"/g, '&quot;');\n};\n\n\n/**\n * use setTimeout if timeout > 0 \n */\nexport const timeout = (fn:()=>void,timeout:number): number | null => {\n\tif( timeout > 0 ){\n\t\treturn window.setTimeout(fn,timeout);\n\t}\n\n\tfn.call(null);\n\treturn null;\n}\n\n/**\n * Debounce the user provided load function\n *\n */\nexport const loadDebounce = (fn:(value:string,callback:TomLoadCallback) => void,delay:number) => {\n\tvar timeout: null|ReturnType<typeof setTimeout>;\n\treturn function(this:TomSelect, value:string,callback:TomLoadCallback) {\n\t\tvar self = this;\n\n\t\tif( timeout ){\n\t\t\tself.loading = Math.max(self.loading - 1, 0);\n\t\t\tclearTimeout(timeout);\n\t\t}\n\t\ttimeout = setTimeout(function() {\n\t\t\ttimeout = null;\n\t\t\tself.loadedSearches[value] = true;\n\t\t\tfn.call(self, value, callback);\n\n\t\t}, delay);\n\t};\n};\n\n\n/**\n * Debounce all fired events types listed in `types`\n * while executing the provided `fn`.\n *\n */\nexport const debounce_events = ( self:TomSelect, types:string[], fn:() => void ) => {\n\tvar type:string;\n\tvar trigger = self.trigger;\n\tvar event_args:{ [key: string]: any } = {};\n\n\t// override trigger method\n\tself.trigger = function(){\n\t\tvar type = arguments[0];\n\t\tif (types.indexOf(type) !== -1) {\n\t\t\tevent_args[type] = arguments;\n\t\t} else {\n\t\t\treturn trigger.apply(self, arguments);\n\t\t}\n\t};\n\n\t// invoke provided function\n\tfn.apply(self, []);\n\tself.trigger = trigger;\n\n\t// trigger queued events\n\tfor( type of types ){\n\t\tif( type in event_args ){\n\t\t\ttrigger.apply(self, event_args[type]);\n\t\t}\n\t}\n};\n\n\n/**\n * Determines the current selection within a text input control.\n * Returns an object containing:\n * - start\n * - length\n *\n * Note: \"selectionStart, selectionEnd ... apply only to inputs of types text, search, URL, tel and password\"\n * \t- https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange\n */\nexport const getSelection = (input:HTMLInputElement):{ start: number; length: number } => {\n\treturn {\n\t\tstart\t: input.selectionStart || 0,\n\t\tlength\t: (input.selectionEnd||0) - (input.selectionStart||0),\n\t};\n};\n\n\n/**\n * Prevent default\n *\n */\nexport const preventDefault = (evt?:Event, stop:boolean=false):void => {\n\tif( evt ){\n\t\tevt.preventDefault();\n\t\tif( stop ){\n\t\t\tevt.stopPropagation();\n\t\t}\n\t}\n}\n\n\n/**\n * Add event helper\n *\n */\nexport const addEvent = (target:EventTarget, type:string, callback:EventListenerOrEventListenerObject, options?:object):void => {\n\ttarget.addEventListener(type,callback,options);\n};\n\n\n/**\n * Return true if the requested key is down\n * Will return false if more than one control character is pressed ( when [ctrl+shift+a] != [ctrl+a] )\n * The current evt may not always set ( eg calling advanceSelection() )\n *\n */\nexport const isKeyDown = ( key_name:keyof (KeyboardEvent|MouseEvent), evt?:KeyboardEvent|MouseEvent ) => {\n\n\tif( !evt ){\n\t\treturn false;\n\t}\n\n\tif( !evt[key_name] ){\n\t\treturn false;\n\t}\n\n\tvar count = (evt.altKey?1:0) + (evt.ctrlKey?1:0) + (evt.shiftKey?1:0) + (evt.metaKey?1:0);\n\n\tif( count === 1 ){\n\t\treturn true;\n\t}\n\n\treturn false;\n};\n\n\n/**\n * Get the id of an element\n * If the id attribute is not set, set the attribute with the given id\n *\n */\nexport const getId = (el:Element,id:string) => {\n\tconst existing_id = el.getAttribute('id');\n\tif( existing_id ){\n\t\treturn existing_id;\n\t}\n\n\tel.setAttribute('id',id);\n\treturn id;\n};\n\n\n/**\n * Returns a string with backslashes added before characters that need to be escaped.\n */\nexport const addSlashes = (str:string):string => {\n\treturn str.replace(/[\\\\\"']/g, '\\\\$&');\n};\n\n/**\n *\n */\nexport const append = ( parent:Element|DocumentFragment, node: string|Node|null|undefined ):void =>{\n\tif( node ) parent.append(node);\n};\n\n/**\n * Iterates over arrays and hashes.\n *\n * ```\n * iterate(this.items, function(item, id) {\n * // invoked for each item\n * });\n * ```\n *\n */\nexport const iterate = (object:[]|{[key:string]:any}, callback:(value:any,key:any)=>any) => {\n\n\tif ( Array.isArray(object)) {\n\t\tobject.forEach(callback);\n\n\t}else{\n\n\t\tfor (var key in object) {\n\t\t\tif (object.hasOwnProperty(key)) {\n\t\t\t\tcallback(object[key], key);\n\t\t\t}\n\t\t}\n\t}\n};\n","/**\n * Plugin: \"change_listener\" (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 * 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 { addEvent } from '../../utils.ts';\n\nexport default function(this:TomSelect) {\n\taddEvent(this.input,'change',()=>{\n\t\tthis.sync();\n\t});\n};\n"],"names":["addEvent","target","type","callback","options","addEventListener","input","sync"],"mappings":";;;;;;;;;;;CAKA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CA2HA;CACA;CACA;CACA;CACO,MAAMA,QAAQ,GAAGA,CAACC,MAAkB,EAAEC,IAAW,EAAEC,QAA2C,EAAEC,OAAe,KAAU;GAC/HH,MAAM,CAACI,gBAAgB,CAACH,IAAI,EAACC,QAAQ,EAACC,OAAO,CAAC;CAC/C,CAAC;;CCnJD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAKe,eAAA,IAAyB;CACvCJ,EAAAA,QAAQ,CAAC,IAAI,CAACM,KAAK,EAAC,QAAQ,EAAC,MAAI;KAChC,IAAI,CAACC,IAAI,EAAE;CACZ,EAAA,CAAC,CAAC;CACH;;;;;;;;"}
@@ -0,0 +1,187 @@
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.checkbox_options = factory());
10
+ })(this, (function () { 'use strict';
11
+
12
+ /**
13
+ * Converts a scalar to its best string representation
14
+ * for hash keys and HTML attribute values.
15
+ *
16
+ * Transformations:
17
+ * 'str' -> 'str'
18
+ * null -> ''
19
+ * undefined -> ''
20
+ * true -> '1'
21
+ * false -> '0'
22
+ * 0 -> '0'
23
+ * 1 -> '1'
24
+ *
25
+ */
26
+ const hash_key = value => {
27
+ if (typeof value === 'undefined' || value === null) return null;
28
+ return get_hash(value);
29
+ };
30
+ const get_hash = value => {
31
+ if (typeof value === 'boolean') return value ? '1' : '0';
32
+ return value + '';
33
+ };
34
+
35
+ /**
36
+ * Prevent default
37
+ *
38
+ */
39
+ const preventDefault = (evt, stop = false) => {
40
+ if (evt) {
41
+ evt.preventDefault();
42
+ if (stop) {
43
+ evt.stopPropagation();
44
+ }
45
+ }
46
+ };
47
+
48
+ /**
49
+ * Return a dom element from either a dom query string, jQuery object, a dom element or html string
50
+ * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
51
+ *
52
+ * param query should be {}
53
+ */
54
+ const getDom = query => {
55
+ if (query.jquery) {
56
+ return query[0];
57
+ }
58
+ if (query instanceof HTMLElement) {
59
+ return query;
60
+ }
61
+ if (isHtmlString(query)) {
62
+ var tpl = document.createElement('template');
63
+ tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
64
+ return tpl.content.firstChild;
65
+ }
66
+ return document.querySelector(query);
67
+ };
68
+ const isHtmlString = arg => {
69
+ if (typeof arg === 'string' && arg.indexOf('<') > -1) {
70
+ return true;
71
+ }
72
+ return false;
73
+ };
74
+
75
+ /**
76
+ * Plugin: "checkbox_options" (Tom Select)
77
+ * Copyright (c) contributors
78
+ *
79
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
80
+ * file except in compliance with the License. You may obtain a copy of the License at:
81
+ * http://www.apache.org/licenses/LICENSE-2.0
82
+ *
83
+ * Unless required by applicable law or agreed to in writing, software distributed under
84
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
85
+ * ANY KIND, either express or implied. See the License for the specific language
86
+ * governing permissions and limitations under the License.
87
+ *
88
+ */
89
+
90
+ function plugin (userOptions) {
91
+ var self = this;
92
+ var orig_onOptionSelect = self.onOptionSelect;
93
+ self.settings.hideSelected = false;
94
+ const cbOptions = Object.assign({
95
+ // so that the user may add different ones as well
96
+ className: "tomselect-checkbox",
97
+ // the following default to the historic plugin's values
98
+ checkedClassNames: undefined,
99
+ uncheckedClassNames: undefined
100
+ }, userOptions);
101
+ var UpdateChecked = function UpdateChecked(checkbox, toCheck) {
102
+ if (toCheck) {
103
+ checkbox.checked = true;
104
+ if (cbOptions.uncheckedClassNames) {
105
+ checkbox.classList.remove(...cbOptions.uncheckedClassNames);
106
+ }
107
+ if (cbOptions.checkedClassNames) {
108
+ checkbox.classList.add(...cbOptions.checkedClassNames);
109
+ }
110
+ } else {
111
+ checkbox.checked = false;
112
+ if (cbOptions.checkedClassNames) {
113
+ checkbox.classList.remove(...cbOptions.checkedClassNames);
114
+ }
115
+ if (cbOptions.uncheckedClassNames) {
116
+ checkbox.classList.add(...cbOptions.uncheckedClassNames);
117
+ }
118
+ }
119
+ };
120
+
121
+ // update the checkbox for an option
122
+ var UpdateCheckbox = function UpdateCheckbox(option) {
123
+ setTimeout(() => {
124
+ var checkbox = option.querySelector('input.' + cbOptions.className);
125
+ if (checkbox instanceof HTMLInputElement) {
126
+ UpdateChecked(checkbox, option.classList.contains('selected'));
127
+ }
128
+ }, 1);
129
+ };
130
+
131
+ // add checkbox to option template
132
+ self.hook('after', 'setupTemplates', () => {
133
+ var orig_render_option = self.settings.render.option;
134
+ self.settings.render.option = (data, escape_html) => {
135
+ var rendered = getDom(orig_render_option.call(self, data, escape_html));
136
+ var checkbox = document.createElement('input');
137
+ if (cbOptions.className) {
138
+ checkbox.classList.add(cbOptions.className);
139
+ }
140
+ checkbox.addEventListener('click', function (evt) {
141
+ preventDefault(evt);
142
+ });
143
+ checkbox.type = 'checkbox';
144
+ const hashed = hash_key(data[self.settings.valueField]);
145
+ UpdateChecked(checkbox, !!(hashed && self.items.indexOf(hashed) > -1));
146
+ rendered.prepend(checkbox);
147
+ return rendered;
148
+ };
149
+ });
150
+
151
+ // uncheck when item removed
152
+ self.on('item_remove', value => {
153
+ var option = self.getOption(value);
154
+ if (option) {
155
+ // if dropdown hasn't been opened yet, the option won't exist
156
+ option.classList.remove('selected'); // selected class won't be removed yet
157
+ UpdateCheckbox(option);
158
+ }
159
+ });
160
+
161
+ // check when item added
162
+ self.on('item_add', value => {
163
+ var option = self.getOption(value);
164
+ if (option) {
165
+ // if dropdown hasn't been opened yet, the option won't exist
166
+ UpdateCheckbox(option);
167
+ }
168
+ });
169
+
170
+ // remove items when selected option is clicked
171
+ self.hook('instead', 'onOptionSelect', (evt, option) => {
172
+ if (option.classList.contains('selected')) {
173
+ option.classList.remove('selected');
174
+ self.removeItem(option.dataset.value);
175
+ self.refreshOptions();
176
+ preventDefault(evt, true);
177
+ return;
178
+ }
179
+ orig_onOptionSelect.call(self, evt, option);
180
+ UpdateCheckbox(option);
181
+ });
182
+ }
183
+
184
+ return plugin;
185
+
186
+ }));
187
+ //# sourceMappingURL=checkbox_options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkbox_options.js","sources":["../../../src/utils.ts","../../../src/vanilla.ts","../../../src/plugins/checkbox_options/plugin.ts"],"sourcesContent":["\nimport type TomSelect from './tom-select.ts';\nimport { TomLoadCallback } from './types/index.ts';\n\n\n/**\n * Converts a scalar to its best string representation\n * for hash keys and HTML attribute values.\n *\n * Transformations:\n * 'str' -> 'str'\n * null -> ''\n * undefined -> ''\n * true -> '1'\n * false -> '0'\n * 0 -> '0'\n * 1 -> '1'\n *\n */\nexport const hash_key = (value:undefined|null|boolean|string|number):string|null => {\n\tif (typeof value === 'undefined' || value === null) return null;\n\treturn get_hash(value);\n};\n\nexport const get_hash = (value:boolean|string|number):string => {\n\tif (typeof value === 'boolean') return value ? '1' : '0';\n\treturn value + '';\n};\n\n/**\n * Escapes a string for use within HTML.\n *\n */\nexport const escape_html = (str:string):string => {\n\treturn (str + '')\n\t\t.replace(/&/g, '&amp;')\n\t\t.replace(/</g, '&lt;')\n\t\t.replace(/>/g, '&gt;')\n\t\t.replace(/\"/g, '&quot;');\n};\n\n\n/**\n * use setTimeout if timeout > 0 \n */\nexport const timeout = (fn:()=>void,timeout:number): number | null => {\n\tif( timeout > 0 ){\n\t\treturn window.setTimeout(fn,timeout);\n\t}\n\n\tfn.call(null);\n\treturn null;\n}\n\n/**\n * Debounce the user provided load function\n *\n */\nexport const loadDebounce = (fn:(value:string,callback:TomLoadCallback) => void,delay:number) => {\n\tvar timeout: null|ReturnType<typeof setTimeout>;\n\treturn function(this:TomSelect, value:string,callback:TomLoadCallback) {\n\t\tvar self = this;\n\n\t\tif( timeout ){\n\t\t\tself.loading = Math.max(self.loading - 1, 0);\n\t\t\tclearTimeout(timeout);\n\t\t}\n\t\ttimeout = setTimeout(function() {\n\t\t\ttimeout = null;\n\t\t\tself.loadedSearches[value] = true;\n\t\t\tfn.call(self, value, callback);\n\n\t\t}, delay);\n\t};\n};\n\n\n/**\n * Debounce all fired events types listed in `types`\n * while executing the provided `fn`.\n *\n */\nexport const debounce_events = ( self:TomSelect, types:string[], fn:() => void ) => {\n\tvar type:string;\n\tvar trigger = self.trigger;\n\tvar event_args:{ [key: string]: any } = {};\n\n\t// override trigger method\n\tself.trigger = function(){\n\t\tvar type = arguments[0];\n\t\tif (types.indexOf(type) !== -1) {\n\t\t\tevent_args[type] = arguments;\n\t\t} else {\n\t\t\treturn trigger.apply(self, arguments);\n\t\t}\n\t};\n\n\t// invoke provided function\n\tfn.apply(self, []);\n\tself.trigger = trigger;\n\n\t// trigger queued events\n\tfor( type of types ){\n\t\tif( type in event_args ){\n\t\t\ttrigger.apply(self, event_args[type]);\n\t\t}\n\t}\n};\n\n\n/**\n * Determines the current selection within a text input control.\n * Returns an object containing:\n * - start\n * - length\n *\n * Note: \"selectionStart, selectionEnd ... apply only to inputs of types text, search, URL, tel and password\"\n * \t- https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange\n */\nexport const getSelection = (input:HTMLInputElement):{ start: number; length: number } => {\n\treturn {\n\t\tstart\t: input.selectionStart || 0,\n\t\tlength\t: (input.selectionEnd||0) - (input.selectionStart||0),\n\t};\n};\n\n\n/**\n * Prevent default\n *\n */\nexport const preventDefault = (evt?:Event, stop:boolean=false):void => {\n\tif( evt ){\n\t\tevt.preventDefault();\n\t\tif( stop ){\n\t\t\tevt.stopPropagation();\n\t\t}\n\t}\n}\n\n\n/**\n * Add event helper\n *\n */\nexport const addEvent = (target:EventTarget, type:string, callback:EventListenerOrEventListenerObject, options?:object):void => {\n\ttarget.addEventListener(type,callback,options);\n};\n\n\n/**\n * Return true if the requested key is down\n * Will return false if more than one control character is pressed ( when [ctrl+shift+a] != [ctrl+a] )\n * The current evt may not always set ( eg calling advanceSelection() )\n *\n */\nexport const isKeyDown = ( key_name:keyof (KeyboardEvent|MouseEvent), evt?:KeyboardEvent|MouseEvent ) => {\n\n\tif( !evt ){\n\t\treturn false;\n\t}\n\n\tif( !evt[key_name] ){\n\t\treturn false;\n\t}\n\n\tvar count = (evt.altKey?1:0) + (evt.ctrlKey?1:0) + (evt.shiftKey?1:0) + (evt.metaKey?1:0);\n\n\tif( count === 1 ){\n\t\treturn true;\n\t}\n\n\treturn false;\n};\n\n\n/**\n * Get the id of an element\n * If the id attribute is not set, set the attribute with the given id\n *\n */\nexport const getId = (el:Element,id:string) => {\n\tconst existing_id = el.getAttribute('id');\n\tif( existing_id ){\n\t\treturn existing_id;\n\t}\n\n\tel.setAttribute('id',id);\n\treturn id;\n};\n\n\n/**\n * Returns a string with backslashes added before characters that need to be escaped.\n */\nexport const addSlashes = (str:string):string => {\n\treturn str.replace(/[\\\\\"']/g, '\\\\$&');\n};\n\n/**\n *\n */\nexport const append = ( parent:Element|DocumentFragment, node: string|Node|null|undefined ):void =>{\n\tif( node ) parent.append(node);\n};\n\n/**\n * Iterates over arrays and hashes.\n *\n * ```\n * iterate(this.items, function(item, id) {\n * // invoked for each item\n * });\n * ```\n *\n */\nexport const iterate = (object:[]|{[key:string]:any}, callback:(value:any,key:any)=>any) => {\n\n\tif ( Array.isArray(object)) {\n\t\tobject.forEach(callback);\n\n\t}else{\n\n\t\tfor (var key in object) {\n\t\t\tif (object.hasOwnProperty(key)) {\n\t\t\t\tcallback(object[key], key);\n\t\t\t}\n\t\t}\n\t}\n};\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: \"checkbox_options\" (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 * 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 { TomTemplate } from '../../types/index.ts';\nimport { preventDefault, hash_key } from '../../utils.ts';\nimport { getDom } from '../../vanilla.ts';\nimport { CBOptions } from './types.ts';\n\n\nexport default function(this:TomSelect, userOptions:CBOptions) {\n\tvar self = this;\n\tvar orig_onOptionSelect = self.onOptionSelect;\n\n\tself.settings.hideSelected = false;\n\n\tconst cbOptions : CBOptions = Object.assign({\n\t\t// so that the user may add different ones as well\n\t\tclassName : \"tomselect-checkbox\",\n\n\t\t// the following default to the historic plugin's values\n\t\tcheckedClassNames : undefined,\n\t\tuncheckedClassNames : undefined,\n\t}, userOptions);\n\n\n\tvar UpdateChecked = function(checkbox:HTMLInputElement, toCheck : boolean) {\n\t\tif( toCheck ){\n\t\t\tcheckbox.checked = true;\n\t\t\tif (cbOptions.uncheckedClassNames) {\n\t\t\t\tcheckbox.classList.remove(...cbOptions.uncheckedClassNames);\n\t\t\t}\n\t\t\tif (cbOptions.checkedClassNames) {\n\t\t\t\tcheckbox.classList.add(...cbOptions.checkedClassNames);\n\t\t\t}\n\t\t}else{\n\t\t\tcheckbox.checked = false;\n\t\t\tif (cbOptions.checkedClassNames) {\n\t\t\t\tcheckbox.classList.remove(...cbOptions.checkedClassNames);\n\t\t\t}\n\t\t\tif (cbOptions.uncheckedClassNames) {\n\t\t\t\tcheckbox.classList.add(...cbOptions.uncheckedClassNames);\n\t\t\t}\n\t\t}\n\t}\n\n\t// update the checkbox for an option\n\tvar UpdateCheckbox = function(option:HTMLElement){\n\t\tsetTimeout(()=>{\n\t\t\tvar checkbox = option.querySelector('input.' + cbOptions.className);\n\t\t\tif( checkbox instanceof HTMLInputElement ){\n\t\t\t\tUpdateChecked(checkbox, option.classList.contains('selected'));\n\t\t\t}\n\t\t},1);\n\t};\n\n\t// add checkbox to option template\n\tself.hook('after','setupTemplates',() => {\n\n\t\tvar orig_render_option = self.settings.render.option;\n\n\t\tself.settings.render.option = ((data, escape_html) => {\n\t\t\tvar rendered = getDom(orig_render_option.call(self, data, escape_html));\n\t\t\tvar checkbox = document.createElement('input');\n\t\t\tif (cbOptions.className) {\n\t\t\t\tcheckbox.classList.add(cbOptions.className);\n\t\t\t}\n\t\t\tcheckbox.addEventListener('click',function(evt){\n\t\t\t\tpreventDefault(evt);\n\t\t\t});\n\n\t\t\tcheckbox.type = 'checkbox';\n\t\t\tconst hashed = hash_key(data[self.settings.valueField]);\n\n\t\t\tUpdateChecked(checkbox, !!(hashed && self.items.indexOf(hashed) > -1) );\n\n\t\t\trendered.prepend(checkbox);\n\t\t\treturn rendered;\n\t\t}) satisfies TomTemplate;\n\t});\n\n\t// uncheck when item removed\n\tself.on('item_remove',(value:string) => {\n\t\tvar option = self.getOption(value);\n\n\t\tif( option ){ // if dropdown hasn't been opened yet, the option won't exist\n\t\t\toption.classList.remove('selected'); // selected class won't be removed yet\n\t\t\tUpdateCheckbox(option);\n\t\t}\n\t});\n\n\t// check when item added\n\tself.on('item_add',(value:string) => {\n\t\tvar option = self.getOption(value);\n\n\t\tif( option ){ // if dropdown hasn't been opened yet, the option won't exist\n\t\t\tUpdateCheckbox(option);\n\t\t}\n\t});\n\n\n\t// remove items when selected option is clicked\n\tself.hook('instead','onOptionSelect',( evt:KeyboardEvent, option:HTMLElement )=>{\n\n\t\tif( option.classList.contains('selected') ){\n\t\t\toption.classList.remove('selected')\n\t\t\tself.removeItem(option.dataset.value);\n\t\t\tself.refreshOptions();\n\t\t\tpreventDefault(evt,true);\n\t\t\treturn;\n }\n\n\t\torig_onOptionSelect.call(self, evt, option);\n\n\t\tUpdateCheckbox(option);\n\t});\n\n};\n"],"names":["hash_key","value","get_hash","preventDefault","evt","stop","stopPropagation","getDom","query","jquery","HTMLElement","isHtmlString","tpl","document","createElement","innerHTML","trim","content","firstChild","querySelector","arg","indexOf","userOptions","self","orig_onOptionSelect","onOptionSelect","settings","hideSelected","cbOptions","Object","assign","className","checkedClassNames","undefined","uncheckedClassNames","UpdateChecked","checkbox","toCheck","checked","classList","remove","add","UpdateCheckbox","option","setTimeout","HTMLInputElement","contains","hook","orig_render_option","render","data","escape_html","rendered","call","addEventListener","type","hashed","valueField","items","prepend","on","getOption","removeItem","dataset","refreshOptions"],"mappings":";;;;;;;;;;;CAKA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACO,MAAMA,QAAQ,GAAIC,KAA0C,IAAiB;GACnF,IAAI,OAAOA,KAAK,KAAK,WAAW,IAAIA,KAAK,KAAK,IAAI,EAAE,OAAO,IAAI;GAC/D,OAAOC,QAAQ,CAACD,KAAK,CAAC;CACvB,CAAC;CAEM,MAAMC,QAAQ,GAAID,KAA2B,IAAY;GAC/D,IAAI,OAAOA,KAAK,KAAK,SAAS,EAAE,OAAOA,KAAK,GAAG,GAAG,GAAG,GAAG;GACxD,OAAOA,KAAK,GAAG,EAAE;CAClB,CAAC;;CAoGD;CACA;CACA;CACA;CACO,MAAME,cAAc,GAAGA,CAACC,GAAU,EAAEC,IAAY,GAAC,KAAK,KAAU;CACtE,EAAA,IAAID,GAAG,EAAE;KACRA,GAAG,CAACD,cAAc,EAAE;CACpB,IAAA,IAAIE,IAAI,EAAE;OACTD,GAAG,CAACE,eAAe,EAAE;CACtB,IAAA;CACD,EAAA;CACD,CAAC;;CCvID;CACA;CACA;CACA;CACA;CACA;CACO,MAAMC,MAAM,GAAKC,KAAS,IAAkB;GAElD,IAAIA,KAAK,CAACC,MAAM,EAAE;KACjB,OAAOD,KAAK,CAAC,CAAC,CAAC;CAChB,EAAA;GAEA,IAAIA,KAAK,YAAYE,WAAW,EAAE;CACjC,IAAA,OAAOF,KAAK;CACb,EAAA;CAEA,EAAA,IAAIG,YAAY,CAACH,KAAK,CAAC,EAAE;CACxB,IAAA,IAAII,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,UAAU,CAAC;KAC5CF,GAAG,CAACG,SAAS,GAAGP,KAAK,CAACQ,IAAI,EAAE,CA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,KAAI;KAE/E,IAAIA,MAAM,CAACJ,SAAS,CAACO,QAAQ,CAAC,UAAU,CAAC,EAAE;CAC1CH,MAAAA,MAAM,CAACJ,SAAS,CAACC,MAAM,CAAC,UAAU,CAAC;OACnCjB,IAAI,CAACuC,UAAU,CAACnB,MAAM,CAACoB,OAAO,CAAC9D,KAAK,CAAC;OACrCsB,IAAI,CAACyC,cAAc,EAAE;CACrB7D,MAAAA,cAAc,CAACC,GAAG,EAAC,IAAI,CAAC;CACxB,MAAA;CACK,IAAA;KAENoB,mBAAmB,CAAC6B,IAAI,CAAC9B,IAAI,EAAEnB,GAAG,EAAEuC,MAAM,CAAC;KAE3CD,cAAc,CAACC,MAAM,CAAC;CACvB,EAAA,CAAC,CAAC;CAEH;;;;;;;;"}
@@ -0,0 +1,84 @@
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.clear_button = factory());
10
+ })(this, (function () { 'use strict';
11
+
12
+ /**
13
+ * Return a dom element from either a dom query string, jQuery object, a dom element or html string
14
+ * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
15
+ *
16
+ * param query should be {}
17
+ */
18
+ const getDom = query => {
19
+ if (query.jquery) {
20
+ return query[0];
21
+ }
22
+ if (query instanceof HTMLElement) {
23
+ return query;
24
+ }
25
+ if (isHtmlString(query)) {
26
+ var tpl = document.createElement('template');
27
+ tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
28
+ return tpl.content.firstChild;
29
+ }
30
+ return document.querySelector(query);
31
+ };
32
+ const isHtmlString = arg => {
33
+ if (typeof arg === 'string' && arg.indexOf('<') > -1) {
34
+ return true;
35
+ }
36
+ return false;
37
+ };
38
+
39
+ /**
40
+ * Plugin: "dropdown_header" (Tom Select)
41
+ * Copyright (c) contributors
42
+ *
43
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
44
+ * file except in compliance with the License. You may obtain a copy of the License at:
45
+ * http://www.apache.org/licenses/LICENSE-2.0
46
+ *
47
+ * Unless required by applicable law or agreed to in writing, software distributed under
48
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
49
+ * ANY KIND, either express or implied. See the License for the specific language
50
+ * governing permissions and limitations under the License.
51
+ *
52
+ */
53
+
54
+ function plugin (userOptions) {
55
+ const self = this;
56
+ const options = Object.assign({
57
+ className: 'clear-button',
58
+ title: 'Clear All',
59
+ role: 'button',
60
+ tabindex: 0,
61
+ html: data => {
62
+ return `<div class="${data.className}" title="${data.title}" role="${data.role}" tabindex="${data.tabindex}">&times;</div>`;
63
+ }
64
+ }, userOptions);
65
+ self.on('initialize', () => {
66
+ var button = getDom(options.html(options));
67
+ button.addEventListener('click', evt => {
68
+ if (self.isLocked) return;
69
+ self.clear();
70
+ if (self.settings.mode === 'single' && self.settings.allowEmptyOption) {
71
+ self.addItem('');
72
+ }
73
+ self.refreshOptions(false);
74
+ evt.preventDefault();
75
+ evt.stopPropagation();
76
+ });
77
+ self.control.appendChild(button);
78
+ });
79
+ }
80
+
81
+ return plugin;
82
+
83
+ }));
84
+ //# sourceMappingURL=clear_button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clear_button.js","sources":["../../../src/vanilla.ts","../../../src/plugins/clear_button/plugin.ts"],"sourcesContent":["\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: \"dropdown_header\" (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 * 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 { getDom } from '../../vanilla.ts';\nimport { CBOptions } from './types.ts';\n\nexport default function(this:TomSelect, userOptions:CBOptions) {\n\tconst self = this;\n\n\tconst options = Object.assign({\n\t\tclassName: 'clear-button',\n\t\ttitle: 'Clear All',\n\t\trole: 'button',\n\t\ttabindex: 0,\n\t\thtml: (data:CBOptions) => {\n\n\t\treturn `<div class=\"${data.className}\" title=\"${data.title}\" role=\"${data.role}\" tabindex=\"${data.tabindex}\">&times;</div>`;\n\t\t}\n\t}, userOptions);\n\n\tself.on('initialize',()=>{\n\t\tvar button = getDom(options.html(options));\n\t\tbutton.addEventListener('click',(evt)=>{\n\n\t\t\tif( self.isLocked ) return;\n\n\t\t\tself.clear();\n\n\t\t\tif( self.settings.mode === 'single' && self.settings.allowEmptyOption ){\n\t\t\t\tself.addItem('');\n\t\t\t}\n\t\t\t\n\t\t\tself.refreshOptions(false);\n\n\t\t\tevt.preventDefault();\n\t\t\tevt.stopPropagation();\n\t\t});\n\t\tself.control.appendChild(button);\n\t});\n\n};\n"],"names":["getDom","query","jquery","HTMLElement","isHtmlString","tpl","document","createElement","innerHTML","trim","content","firstChild","querySelector","arg","indexOf","userOptions","self","options","Object","assign","className","title","role","tabindex","html","data","on","button","addEventListener","evt","isLocked","clear","settings","mode","allowEmptyOption","addItem","refreshOptions","preventDefault","stopPropagation","control","appendChild"],"mappings":";;;;;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AI,CAACH,IAAI,CAAA,YAAA,EAAeG,IAAI,CAACF,QAAQ,CAAA,eAAA,CAAiB;CAC3H,IAAA;IACA,EAAER,WAAW,CAAC;CAEfC,EAAAA,IAAI,CAACU,EAAE,CAAC,YAAY,EAAC,MAAI;KACxB,IAAIC,MAAM,GAAG3B,MAAM,CAACiB,OAAO,CAACO,IAAI,CAACP,OAAO,CAAC,CAAC;CAC1CU,IAAAA,MAAM,CAACC,gBAAgB,CAAC,OAAO,EAAEC,GAAG,IAAG;OAEtC,IAAIb,IAAI,CAACc,QAAQ,EAAG;OAEpBd,IAAI,CAACe,KAAK,EAAE;CAEZ,MAAA,IAAIf,IAAI,CAACgB,QAAQ,CAACC,IAAI,KAAK,QAAQ,IAAIjB,IAAI,CAACgB,QAAQ,CAACE,gBAAgB,EAAE;CACtElB,QAAAA,IAAI,CAACmB,OAAO,CAAC,EAAE,CAAC;CACjB,MAAA;CAEAnB,MAAAA,IAAI,CAACoB,cAAc,CAAC,KAAK,CAAC;OAE1BP,GAAG,CAACQ,cAAc,EAAE;OACpBR,GAAG,CAACS,eAAe,EAAE;CACtB,IAAA,CAAC,CAAC;CACFtB,IAAAA,IAAI,CAACuB,OAAO,CAACC,WAAW,CAACb,MAAM,CAAC;CACjC,EAAA,CAAC,CAAC;CAEH;;;;;;;;"}
@@ -0,0 +1,228 @@
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.drag_drop = factory());
10
+ })(this, (function () { 'use strict';
11
+
12
+ /**
13
+ * Converts a scalar to its best string representation
14
+ * for hash keys and HTML attribute values.
15
+ *
16
+ * Transformations:
17
+ * 'str' -> 'str'
18
+ * null -> ''
19
+ * undefined -> ''
20
+ * true -> '1'
21
+ * false -> '0'
22
+ * 0 -> '0'
23
+ * 1 -> '1'
24
+ *
25
+ */
26
+
27
+ /**
28
+ * Prevent default
29
+ *
30
+ */
31
+ const preventDefault = (evt, stop = false) => {
32
+ if (evt) {
33
+ evt.preventDefault();
34
+ if (stop) {
35
+ evt.stopPropagation();
36
+ }
37
+ }
38
+ };
39
+
40
+ /**
41
+ * Add event helper
42
+ *
43
+ */
44
+ const addEvent = (target, type, callback, options) => {
45
+ target.addEventListener(type, callback, options);
46
+ };
47
+
48
+ /**
49
+ * Iterates over arrays and hashes.
50
+ *
51
+ * ```
52
+ * iterate(this.items, function(item, id) {
53
+ * // invoked for each item
54
+ * });
55
+ * ```
56
+ *
57
+ */
58
+ const iterate = (object, callback) => {
59
+ if (Array.isArray(object)) {
60
+ object.forEach(callback);
61
+ } else {
62
+ for (var key in object) {
63
+ if (object.hasOwnProperty(key)) {
64
+ callback(object[key], key);
65
+ }
66
+ }
67
+ }
68
+ };
69
+
70
+ /**
71
+ * Return a dom element from either a dom query string, jQuery object, a dom element or html string
72
+ * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
73
+ *
74
+ * param query should be {}
75
+ */
76
+ const getDom = query => {
77
+ if (query.jquery) {
78
+ return query[0];
79
+ }
80
+ if (query instanceof HTMLElement) {
81
+ return query;
82
+ }
83
+ if (isHtmlString(query)) {
84
+ var tpl = document.createElement('template');
85
+ tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
86
+ return tpl.content.firstChild;
87
+ }
88
+ return document.querySelector(query);
89
+ };
90
+ const isHtmlString = arg => {
91
+ if (typeof arg === 'string' && arg.indexOf('<') > -1) {
92
+ return true;
93
+ }
94
+ return false;
95
+ };
96
+
97
+ /**
98
+ * Set attributes of an element
99
+ *
100
+ */
101
+ const setAttr = (el, attrs) => {
102
+ iterate(attrs, (val, attr) => {
103
+ if (val == null) {
104
+ el.removeAttribute(attr);
105
+ } else {
106
+ el.setAttribute(attr, '' + val);
107
+ }
108
+ });
109
+ };
110
+
111
+ /**
112
+ * Plugin: "drag_drop" (Tom Select)
113
+ * Copyright (c) contributors
114
+ *
115
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
116
+ * file except in compliance with the License. You may obtain a copy of the License at:
117
+ * http://www.apache.org/licenses/LICENSE-2.0
118
+ *
119
+ * Unless required by applicable law or agreed to in writing, software distributed under
120
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
121
+ * ANY KIND, either express or implied. See the License for the specific language
122
+ * governing permissions and limitations under the License.
123
+ *
124
+ */
125
+
126
+ const insertAfter = (referenceNode, newNode) => {
127
+ var _referenceNode$parent;
128
+ (_referenceNode$parent = referenceNode.parentNode) == null || _referenceNode$parent.insertBefore(newNode, referenceNode.nextSibling);
129
+ };
130
+ const insertBefore = (referenceNode, newNode) => {
131
+ var _referenceNode$parent2;
132
+ (_referenceNode$parent2 = referenceNode.parentNode) == null || _referenceNode$parent2.insertBefore(newNode, referenceNode);
133
+ };
134
+ const isBefore = (referenceNode, newNode) => {
135
+ do {
136
+ var _newNode;
137
+ newNode = (_newNode = newNode) == null ? void 0 : _newNode.previousElementSibling;
138
+ if (referenceNode == newNode) {
139
+ return true;
140
+ }
141
+ } while (newNode && newNode.previousElementSibling);
142
+ return false;
143
+ };
144
+ function plugin () {
145
+ var self = this;
146
+ if (self.settings.mode !== 'multi') return;
147
+ var orig_lock = self.lock;
148
+ var orig_unlock = self.unlock;
149
+ let sortable = true;
150
+ let drag_item;
151
+
152
+ /**
153
+ * Add draggable attribute to item
154
+ */
155
+ self.hook('after', 'setupTemplates', () => {
156
+ var orig_render_item = self.settings.render.item;
157
+ self.settings.render.item = (data, escape) => {
158
+ const item = getDom(orig_render_item.call(self, data, escape));
159
+ setAttr(item, {
160
+ 'draggable': 'true'
161
+ });
162
+
163
+ // prevent doc_mousedown (see tom-select.ts)
164
+ const mousedown = evt => {
165
+ if (!sortable) preventDefault(evt);
166
+ evt.stopPropagation();
167
+ };
168
+ const dragStart = evt => {
169
+ drag_item = item;
170
+ setTimeout(() => {
171
+ item.classList.add('ts-dragging');
172
+ }, 0);
173
+ };
174
+ const dragOver = evt => {
175
+ evt.preventDefault();
176
+ item.classList.add('ts-drag-over');
177
+ moveitem(item, drag_item);
178
+ };
179
+ const dragLeave = () => {
180
+ item.classList.remove('ts-drag-over');
181
+ };
182
+ const moveitem = (targetitem, dragitem) => {
183
+ if (dragitem === undefined) return;
184
+ if (isBefore(dragitem, item)) {
185
+ insertAfter(targetitem, dragitem);
186
+ } else {
187
+ insertBefore(targetitem, dragitem);
188
+ }
189
+ };
190
+ const dragend = () => {
191
+ var _drag_item;
192
+ document.querySelectorAll('.ts-drag-over').forEach(el => el.classList.remove('ts-drag-over'));
193
+ (_drag_item = drag_item) == null || _drag_item.classList.remove('ts-dragging');
194
+ drag_item = undefined;
195
+ var values = [];
196
+ self.control.querySelectorAll(`[data-value]`).forEach(el => {
197
+ if (el.dataset.value) {
198
+ let value = el.dataset.value;
199
+ if (value) {
200
+ values.push(value);
201
+ }
202
+ }
203
+ });
204
+ self.setValue(values);
205
+ };
206
+ addEvent(item, 'mousedown', mousedown);
207
+ addEvent(item, 'dragstart', dragStart);
208
+ addEvent(item, 'dragenter', dragOver);
209
+ addEvent(item, 'dragover', dragOver);
210
+ addEvent(item, 'dragleave', dragLeave);
211
+ addEvent(item, 'dragend', dragend);
212
+ return item;
213
+ };
214
+ });
215
+ self.hook('instead', 'lock', () => {
216
+ sortable = false;
217
+ return orig_lock.call(self);
218
+ });
219
+ self.hook('instead', 'unlock', () => {
220
+ sortable = true;
221
+ return orig_unlock.call(self);
222
+ });
223
+ }
224
+
225
+ return plugin;
226
+
227
+ }));
228
+ //# sourceMappingURL=drag_drop.js.map