@@ -29,14 +29,28 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
2929 return e . name = "SuppressedError" , e . error = error , e . suppressed = suppressed , e ;
3030} ;
3131
32- 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 ;
32+ var _default_1_instances , _default_1_getCommonConfig , _default_1_createAutocomplete , _default_1_createAutocompleteWithHtmlContents , _default_1_createAutocompleteWithRemoteData , _default_1_stripTags , _default_1_mergeConfigs , _default_1_normalizePluginsToHash , _default_1_createTomSelect ;
3333class default_1 extends Controller {
3434 constructor ( ) {
3535 super ( ...arguments ) ;
3636 _default_1_instances . add ( this ) ;
3737 this . isObserving = false ;
3838 this . hasLoadedChoicesPreviously = false ;
3939 this . originalOptions = [ ] ;
40+ _default_1_normalizePluginsToHash . set ( this , ( plugins ) => {
41+ if ( Array . isArray ( plugins ) ) {
42+ return plugins . reduce ( ( acc , plugin ) => {
43+ if ( typeof plugin === 'string' ) {
44+ acc [ plugin ] = { } ;
45+ }
46+ if ( typeof plugin === 'object' && plugin . name ) {
47+ acc [ plugin . name ] = plugin . options || { } ;
48+ }
49+ return acc ;
50+ } , { } ) ;
51+ }
52+ return plugins ;
53+ } ) ;
4054 }
4155 initialize ( ) {
4256 if ( ! this . mutationObserver ) {
@@ -223,7 +237,7 @@ class default_1 extends Controller {
223237 [ ...originalOptionsSet ] . every ( ( option ) => newOptionsSet . has ( option ) ) ) ;
224238 }
225239}
226- _default_1_instances = new WeakSet ( ) , _default_1_getCommonConfig = function _default_1_getCommonConfig ( ) {
240+ _default_1_normalizePluginsToHash = new WeakMap ( ) , _default_1_instances = new WeakSet ( ) , _default_1_getCommonConfig = function _default_1_getCommonConfig ( ) {
227241 const plugins = { } ;
228242 const isMultiple = ! this . selectElement || this . selectElement . multiple ;
229243 if ( ! this . formElement . disabled && ! isMultiple ) {
@@ -288,16 +302,16 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
288302 if ( ! this . selectElement && ! this . urlValue ) {
289303 config . shouldLoad = ( ) => false ;
290304 }
291- return __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeObjects ) . call ( this , config , this . tomSelectOptionsValue ) ;
305+ return __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeConfigs ) . call ( this , config , this . tomSelectOptionsValue ) ;
292306} , _default_1_createAutocomplete = function _default_1_createAutocomplete ( ) {
293- const config = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeObjects ) . call ( this , __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_getCommonConfig ) . call ( this ) , {
307+ const config = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeConfigs ) . call ( this , __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_getCommonConfig ) . call ( this ) , {
294308 maxOptions : this . getMaxOptions ( ) ,
295309 } ) ;
296310 return __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_createTomSelect ) . call ( this , config ) ;
297311} , _default_1_createAutocompleteWithHtmlContents = function _default_1_createAutocompleteWithHtmlContents ( ) {
298312 const commonConfig = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_getCommonConfig ) . call ( this ) ;
299313 const labelField = commonConfig . labelField ?? 'text' ;
300- const config = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeObjects ) . call ( this , commonConfig , {
314+ const config = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeConfigs ) . call ( this , commonConfig , {
301315 maxOptions : this . getMaxOptions ( ) ,
302316 score : ( search ) => {
303317 const scoringFunction = this . tomSelect . getScoreFunction ( search ) ;
@@ -314,7 +328,7 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
314328} , _default_1_createAutocompleteWithRemoteData = function _default_1_createAutocompleteWithRemoteData ( autocompleteEndpointUrl , minCharacterLength ) {
315329 const commonConfig = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_getCommonConfig ) . call ( this ) ;
316330 const labelField = commonConfig . labelField ?? 'text' ;
317- const config = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeObjects ) . call ( this , commonConfig , {
331+ const config = __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_mergeConfigs ) . call ( this , commonConfig , {
318332 firstUrl : ( query ) => {
319333 const separator = autocompleteEndpointUrl . includes ( '?' ) ? '&' : '?' ;
320334 return `${ autocompleteEndpointUrl } ${ separator } query=${ encodeURIComponent ( query ) } ` ;
@@ -364,8 +378,15 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
364378 return __classPrivateFieldGet ( this , _default_1_instances , "m" , _default_1_createTomSelect ) . call ( this , config ) ;
365379} , _default_1_stripTags = function _default_1_stripTags ( string ) {
366380 return string . replace ( / ( < ( [ ^ > ] + ) > ) / gi, '' ) ;
367- } , _default_1_mergeObjects = function _default_1_mergeObjects ( object1 , object2 ) {
368- return { ...object1 , ...object2 } ;
381+ } , _default_1_mergeConfigs = function _default_1_mergeConfigs ( config1 , config2 ) {
382+ return {
383+ ...config1 ,
384+ ...config2 ,
385+ plugins : {
386+ ...__classPrivateFieldGet ( this , _default_1_normalizePluginsToHash , "f" ) . call ( this , config1 . plugins || { } ) ,
387+ ...__classPrivateFieldGet ( this , _default_1_normalizePluginsToHash , "f" ) . call ( this , config2 . plugins || { } ) ,
388+ } ,
389+ } ;
369390} , _default_1_createTomSelect = function _default_1_createTomSelect ( options ) {
370391 const preConnectPayload = { options } ;
371392 this . dispatchEvent ( 'pre-connect' , preConnectPayload ) ;
0 commit comments