@symfony/ux-autocomplete 2.26.0 → 2.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controller.js +29 -8
- package/package.json +1 -1
package/dist/controller.js
CHANGED
|
@@ -29,7 +29,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
29
29
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
var _default_1_instances, _default_1_getCommonConfig, _default_1_createAutocomplete, _default_1_createAutocompleteWithHtmlContents, _default_1_createAutocompleteWithRemoteData, _default_1_stripTags,
|
|
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;
|
|
33
33
|
class default_1 extends Controller {
|
|
34
34
|
constructor() {
|
|
35
35
|
super(...arguments);
|
|
@@ -37,6 +37,20 @@ class default_1 extends Controller {
|
|
|
37
37
|
this.isObserving = false;
|
|
38
38
|
this.hasLoadedChoicesPreviously = false;
|
|
39
39
|
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
|
+
});
|
|
40
54
|
}
|
|
41
55
|
initialize() {
|
|
42
56
|
if (!this.mutationObserver) {
|
|
@@ -223,7 +237,7 @@ class default_1 extends Controller {
|
|
|
223
237
|
[...originalOptionsSet].every((option) => newOptionsSet.has(option)));
|
|
224
238
|
}
|
|
225
239
|
}
|
|
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() {
|
|
227
241
|
const plugins = {};
|
|
228
242
|
const isMultiple = !this.selectElement || this.selectElement.multiple;
|
|
229
243
|
if (!this.formElement.disabled && !isMultiple) {
|
|
@@ -288,16 +302,16 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
|
|
|
288
302
|
if (!this.selectElement && !this.urlValue) {
|
|
289
303
|
config.shouldLoad = () => false;
|
|
290
304
|
}
|
|
291
|
-
return __classPrivateFieldGet(this, _default_1_instances, "m",
|
|
305
|
+
return __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_mergeConfigs).call(this, config, this.tomSelectOptionsValue);
|
|
292
306
|
}, _default_1_createAutocomplete = function _default_1_createAutocomplete() {
|
|
293
|
-
const config = __classPrivateFieldGet(this, _default_1_instances, "m",
|
|
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), {
|
|
294
308
|
maxOptions: this.getMaxOptions(),
|
|
295
309
|
});
|
|
296
310
|
return __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createTomSelect).call(this, config);
|
|
297
311
|
}, _default_1_createAutocompleteWithHtmlContents = function _default_1_createAutocompleteWithHtmlContents() {
|
|
298
312
|
const commonConfig = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_getCommonConfig).call(this);
|
|
299
313
|
const labelField = commonConfig.labelField ?? 'text';
|
|
300
|
-
const config = __classPrivateFieldGet(this, _default_1_instances, "m",
|
|
314
|
+
const config = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_mergeConfigs).call(this, commonConfig, {
|
|
301
315
|
maxOptions: this.getMaxOptions(),
|
|
302
316
|
score: (search) => {
|
|
303
317
|
const scoringFunction = this.tomSelect.getScoreFunction(search);
|
|
@@ -314,7 +328,7 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
|
|
|
314
328
|
}, _default_1_createAutocompleteWithRemoteData = function _default_1_createAutocompleteWithRemoteData(autocompleteEndpointUrl, minCharacterLength) {
|
|
315
329
|
const commonConfig = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_getCommonConfig).call(this);
|
|
316
330
|
const labelField = commonConfig.labelField ?? 'text';
|
|
317
|
-
const config = __classPrivateFieldGet(this, _default_1_instances, "m",
|
|
331
|
+
const config = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_mergeConfigs).call(this, commonConfig, {
|
|
318
332
|
firstUrl: (query) => {
|
|
319
333
|
const separator = autocompleteEndpointUrl.includes('?') ? '&' : '?';
|
|
320
334
|
return `${autocompleteEndpointUrl}${separator}query=${encodeURIComponent(query)}`;
|
|
@@ -364,8 +378,15 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
|
|
|
364
378
|
return __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createTomSelect).call(this, config);
|
|
365
379
|
}, _default_1_stripTags = function _default_1_stripTags(string) {
|
|
366
380
|
return string.replace(/(<([^>]+)>)/gi, '');
|
|
367
|
-
},
|
|
368
|
-
return {
|
|
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
|
+
};
|
|
369
390
|
}, _default_1_createTomSelect = function _default_1_createTomSelect(options) {
|
|
370
391
|
const preConnectPayload = { options };
|
|
371
392
|
this.dispatchEvent('pre-connect', preConnectPayload);
|