@@ -22,11 +22,11 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
22
22
return kind === "m" ? f : kind === "a" ? f . call ( receiver ) : f ? f . value : state . get ( receiver ) ;
23
23
}
24
24
25
- var _default_1_instances , _default_1_getCommonConfig , _default_1_createAutocomplete , _default_1_createAutocompleteWithHtmlContents , _default_1_createAutocompleteWithRemoteData , _default_1_stripTags , _default_1_mergeObjects , _default_1_createTomSelect , _default_1_dispatchEvent ;
25
+ var _instances , _getCommonConfig , _createAutocomplete , _createAutocompleteWithHtmlContents , _createAutocompleteWithRemoteData , _stripTags , _mergeObjects , _createTomSelect , _dispatchEvent ;
26
26
class default_1 extends Controller {
27
27
constructor ( ) {
28
28
super ( ...arguments ) ;
29
- _default_1_instances . add ( this ) ;
29
+ _instances . add ( this ) ;
30
30
}
31
31
initialize ( ) {
32
32
this . element . setAttribute ( 'data-live-ignore' , '' ) ;
@@ -39,14 +39,14 @@ class default_1 extends Controller {
39
39
}
40
40
connect ( ) {
41
41
if ( this . urlValue ) {
42
- this . tomSelect = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_createAutocompleteWithRemoteData ) . call ( this , this . urlValue , this . minCharactersValue ) ;
42
+ this . tomSelect = __classPrivateFieldGet ( this , _instances , "m" , _createAutocompleteWithRemoteData ) . call ( this , this . urlValue , this . minCharactersValue ) ;
43
43
return ;
44
44
}
45
45
if ( this . optionsAsHtmlValue ) {
46
- this . tomSelect = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_createAutocompleteWithHtmlContents ) . call ( this ) ;
46
+ this . tomSelect = __classPrivateFieldGet ( this , _instances , "m" , _createAutocompleteWithHtmlContents ) . call ( this ) ;
47
47
return ;
48
48
}
49
- this . tomSelect = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_createAutocomplete ) . call ( this ) ;
49
+ this . tomSelect = __classPrivateFieldGet ( this , _instances , "m" , _createAutocomplete ) . call ( this ) ;
50
50
}
51
51
disconnect ( ) {
52
52
this . tomSelect . revertSettings . innerHTML = this . element . innerHTML ;
@@ -65,14 +65,19 @@ class default_1 extends Controller {
65
65
return this . element ;
66
66
}
67
67
get preload ( ) {
68
- if ( this . preloadValue == 'false' )
68
+ if ( ! this . hasPreloadValue ) {
69
+ return 'focus' ;
70
+ }
71
+ if ( this . preloadValue == 'false' ) {
69
72
return false ;
70
- if ( this . preloadValue == 'true' )
73
+ }
74
+ if ( this . preloadValue == 'true' ) {
71
75
return true ;
76
+ }
72
77
return this . preloadValue ;
73
78
}
74
79
}
75
- _default_1_instances = new WeakSet ( ) , _default_1_getCommonConfig = function _default_1_getCommonConfig ( ) {
80
+ _instances = new WeakSet ( ) , _getCommonConfig = function _getCommonConfig ( ) {
76
81
const plugins = { } ;
77
82
const isMultiple = ! this . selectElement || this . selectElement . multiple ;
78
83
if ( ! this . formElement . disabled && ! isMultiple ) {
@@ -87,7 +92,7 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
87
92
const render = {
88
93
no_results : ( ) => {
89
94
return `<div class="no-results">${ this . noResultsFoundTextValue } </div>` ;
90
- }
95
+ } ,
91
96
} ;
92
97
const config = {
93
98
render : render ,
@@ -104,19 +109,19 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
104
109
if ( ! this . selectElement && ! this . urlValue ) {
105
110
config . shouldLoad = ( ) => false ;
106
111
}
107
- return __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeObjects ) . call ( this , config , this . tomSelectOptionsValue ) ;
108
- } , _default_1_createAutocomplete = function _default_1_createAutocomplete ( ) {
109
- const config = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeObjects ) . call ( this , __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_getCommonConfig ) . call ( this ) , {
112
+ return __classPrivateFieldGet ( this , _instances , "m" , _mergeObjects ) . call ( this , config , this . tomSelectOptionsValue ) ;
113
+ } , _createAutocomplete = function _createAutocomplete ( ) {
114
+ const config = __classPrivateFieldGet ( this , _instances , "m" , _mergeObjects ) . call ( this , __classPrivateFieldGet ( this , _instances , "m" , _getCommonConfig ) . call ( this ) , {
110
115
maxOptions : this . selectElement ? this . selectElement . options . length : 50 ,
111
116
} ) ;
112
- return __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_createTomSelect ) . call ( this , config ) ;
113
- } , _default_1_createAutocompleteWithHtmlContents = function _default_1_createAutocompleteWithHtmlContents ( ) {
114
- const config = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeObjects ) . call ( this , __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_getCommonConfig ) . call ( this ) , {
117
+ return __classPrivateFieldGet ( this , _instances , "m" , _createTomSelect ) . call ( this , config ) ;
118
+ } , _createAutocompleteWithHtmlContents = function _createAutocompleteWithHtmlContents ( ) {
119
+ const config = __classPrivateFieldGet ( this , _instances , "m" , _mergeObjects ) . call ( this , __classPrivateFieldGet ( this , _instances , "m" , _getCommonConfig ) . call ( this ) , {
115
120
maxOptions : this . selectElement ? this . selectElement . options . length : 50 ,
116
121
score : ( search ) => {
117
122
const scoringFunction = this . tomSelect . getScoreFunction ( search ) ;
118
123
return ( item ) => {
119
- return scoringFunction ( Object . assign ( Object . assign ( { } , item ) , { text : __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_stripTags ) . call ( this , item . text ) } ) ) ;
124
+ return scoringFunction ( Object . assign ( Object . assign ( { } , item ) , { text : __classPrivateFieldGet ( this , _instances , "m" , _stripTags ) . call ( this , item . text ) } ) ) ;
120
125
} ;
121
126
} ,
122
127
render : {
@@ -125,21 +130,24 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
125
130
} ,
126
131
option : function ( item ) {
127
132
return `<div>${ item . text } </div>` ;
128
- }
133
+ } ,
129
134
} ,
130
135
} ) ;
131
- return __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_createTomSelect ) . call ( this , config ) ;
132
- } , _default_1_createAutocompleteWithRemoteData = function _default_1_createAutocompleteWithRemoteData ( autocompleteEndpointUrl , minCharacterLength ) {
133
- const config = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeObjects ) . call ( this , __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_getCommonConfig ) . call ( this ) , {
136
+ return __classPrivateFieldGet ( this , _instances , "m" , _createTomSelect ) . call ( this , config ) ;
137
+ } , _createAutocompleteWithRemoteData = function _createAutocompleteWithRemoteData ( autocompleteEndpointUrl , minCharacterLength ) {
138
+ const config = __classPrivateFieldGet ( this , _instances , "m" , _mergeObjects ) . call ( this , __classPrivateFieldGet ( this , _instances , "m" , _getCommonConfig ) . call ( this ) , {
134
139
firstUrl : ( query ) => {
135
140
const separator = autocompleteEndpointUrl . includes ( '?' ) ? '&' : '?' ;
136
141
return `${ autocompleteEndpointUrl } ${ separator } query=${ encodeURIComponent ( query ) } ` ;
137
142
} ,
138
143
load : function ( query , callback ) {
139
144
const url = this . getUrl ( query ) ;
140
145
fetch ( url )
141
- . then ( response => response . json ( ) )
142
- . then ( json => { this . setNextUrl ( query , json . next_page ) ; callback ( json . results ) ; } )
146
+ . then ( ( response ) => response . json ( ) )
147
+ . then ( ( json ) => {
148
+ this . setNextUrl ( query , json . next_page ) ;
149
+ callback ( json . results ) ;
150
+ } )
143
151
. catch ( ( ) => callback ( ) ) ;
144
152
} ,
145
153
shouldLoad : function ( query ) {
@@ -167,17 +175,17 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
167
175
} ,
168
176
preload : this . preload ,
169
177
} ) ;
170
- return __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_createTomSelect ) . call ( this , config ) ;
171
- } , _default_1_stripTags = function _default_1_stripTags ( string ) {
178
+ return __classPrivateFieldGet ( this , _instances , "m" , _createTomSelect ) . call ( this , config ) ;
179
+ } , _stripTags = function _stripTags ( string ) {
172
180
return string . replace ( / ( < ( [ ^ > ] + ) > ) / gi, '' ) ;
173
- } , _default_1_mergeObjects = function _default_1_mergeObjects ( object1 , object2 ) {
181
+ } , _mergeObjects = function _mergeObjects ( object1 , object2 ) {
174
182
return Object . assign ( Object . assign ( { } , object1 ) , object2 ) ;
175
- } , _default_1_createTomSelect = function _default_1_createTomSelect ( options ) {
176
- __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_dispatchEvent ) . call ( this , 'autocomplete:pre-connect' , { options } ) ;
183
+ } , _createTomSelect = function _createTomSelect ( options ) {
184
+ __classPrivateFieldGet ( this , _instances , "m" , _dispatchEvent ) . call ( this , 'autocomplete:pre-connect' , { options } ) ;
177
185
const tomSelect = new TomSelect ( this . formElement , options ) ;
178
- __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_dispatchEvent ) . call ( this , 'autocomplete:connect' , { tomSelect, options } ) ;
186
+ __classPrivateFieldGet ( this , _instances , "m" , _dispatchEvent ) . call ( this , 'autocomplete:connect' , { tomSelect, options } ) ;
179
187
return tomSelect ;
180
- } , _default_1_dispatchEvent = function _default_1_dispatchEvent ( name , payload ) {
188
+ } , _dispatchEvent = function _dispatchEvent ( name , payload ) {
181
189
this . element . dispatchEvent ( new CustomEvent ( name , { detail : payload , bubbles : true } ) ) ;
182
190
} ;
183
191
default_1 . values = {
0 commit comments