diff --git a/build/build-modules-js/settings.json b/build/build-modules-js/settings.json index bd6d67ad4670..008e602afcaa 100644 --- a/build/build-modules-js/settings.json +++ b/build/build-modules-js/settings.json @@ -158,12 +158,12 @@ "choices.js": { "name": "choicesjs", "js": { - "assets/scripts/dist/choices.js": "js/choices.js", - "assets/scripts/dist/choices.min.js": "js/choices.min.js" + "public/assets/scripts/choices.js": "js/choices.js", + "public/assets/scripts/choices.min.js": "js/choices.min.js" }, "css": { - "assets/styles/css/choices.css": "css/choices.css", - "assets/styles/css/choices.min.css": "css/choices.min.css" + "public/assets/styles/choices.css": "css/choices.css", + "public/assets/styles/choices.min.css": "css/choices.min.css" }, "provideAssets": [ { diff --git a/build/media/webcomponents/js/field-fancy-select/field-fancy-select.js b/build/media/webcomponents/js/field-fancy-select/field-fancy-select.js index e35a5ad3e33c..4239034eca42 100644 --- a/build/media/webcomponents/js/field-fancy-select/field-fancy-select.js +++ b/build/media/webcomponents/js/field-fancy-select/field-fancy-select.js @@ -1,5 +1,5 @@ /** - * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ @@ -42,6 +42,24 @@ set value($val) { this.choicesInstance.setValueByChoice('' + $val); } connectedCallback() { + // Make sure Choices are loaded + if (window.Choices || document.readyState === 'complete') { + this._doConnect(); + } else { + const callback = () => { + this._doConnect(); + window.removeEventListener('load', callback); + }; + window.addEventListener('load', callback); + } + } + + _doConnect() { + // The element was already initialised previously and perhaps was detached from DOM + if (this.choicesInstance) { + return; + } + if (!window.Choices) { throw new Error('JoomlaFieldFancySelect require Choices.js to work'); } @@ -111,7 +129,7 @@ // Handle remote search if (this.remoteSearch && this.url) { // Cache existing - this.choicesInstance.presetChoices.forEach((choiceItem) => { + this.choicesInstance.config.choices.forEach((choiceItem) => { this.choicesCache[choiceItem.value] = choiceItem.label; }); @@ -126,14 +144,8 @@ } disconnectedCallback() { - // Destroy Choices instance, to unbind an event listeners - if (this.choicesInstance) { - this.choicesInstance.destroy(); - this.choicesInstance = null; - } - if (this.activeXHR){ + if (this.activeXHR) { this.activeXHR.abort(); - this.activeXHR = null; } } @@ -158,8 +170,12 @@ let item; for(let i = items.length - 1; i >= 0; i--) { item = items[i]; + item.value = '' + item.value; // Make sure the value is a string, choices.js expect a string. + if (this.choicesCache[item.value]) { items.splice(i, 1); + } else { + this.choicesCache[item.value] = item.text; } } diff --git a/package-lock.json b/package-lock.json index 9bf5acf2851f..9a0a605fcd82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2228,13 +2228,15 @@ "dev": true }, "choices.js": { - "version": "3.0.4", - "resolved": "http://registry.npmjs.org/choices.js/-/choices.js-3.0.4.tgz", - "integrity": "sha512-0krE5N99xyjjCcBg2XuTXkEf+RqF2JQ6Si3iMV0HNggmvR5ZF5wTzpISZaB5ln6k1B2K28BGAnvKrX6sqa7Ymw==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/choices.js/-/choices.js-4.1.3.tgz", + "integrity": "sha512-DWbAyJ5+1izvqszUrvSKbyZ6AP34oobbVW6s/5LF6WqTBhXhcivwYFsY3R8AIcQ09w3AVn7d0/QEHVTTWLGKEw==", "requires": { "classnames": "^2.2.5", - "fuse.js": "^2.2.2", - "opn": "^5.1.0", + "core-js": "^2.5.6", + "custom-event-polyfill": "^0.3.0", + "deepmerge": "^2.2.1", + "fuse.js": "^3.1.0", "redux": "^3.3.1" } }, @@ -2613,8 +2615,7 @@ "core-js": { "version": "2.5.7", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz", - "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==", - "dev": true + "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==" }, "core-util-is": { "version": "1.0.2", @@ -2913,6 +2914,11 @@ "resolved": "https://registry.npmjs.org/custom-event/-/custom-event-1.0.0.tgz", "integrity": "sha1-LkYovhncSyFLXAJjDFlx6BFhgGI=" }, + "custom-event-polyfill": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/custom-event-polyfill/-/custom-event-polyfill-0.3.0.tgz", + "integrity": "sha1-mYB4Ob5i7bRGtkWDLg2A6tb6GIg=" + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -2970,6 +2976,11 @@ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, + "deepmerge": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-2.2.1.tgz", + "integrity": "sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA==" + }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -4672,9 +4683,9 @@ "dev": true }, "fuse.js": { - "version": "2.7.4", - "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-2.7.4.tgz", - "integrity": "sha1-luQg/efvARrEnCWKYhMU/ldlNvk=" + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-3.3.0.tgz", + "integrity": "sha512-ESBRkGLWMuVkapqYCcNO1uqMg5qbCKkgb+VS6wsy17Rix0/cMS9kSOZoYkjH8Ko//pgJ/EEGu0GTjk2mjX2LGQ==" }, "gauge": { "version": "2.7.4", @@ -5611,11 +5622,6 @@ "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==", "dev": true }, - "is-wsl": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-1.1.0.tgz", - "integrity": "sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0=" - }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -5752,13 +5758,13 @@ }, "jasmine-core": { "version": "2.99.1", - "resolved": "http://registry.npmjs.org/jasmine-core/-/jasmine-core-2.99.1.tgz", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-2.99.1.tgz", "integrity": "sha1-5kAN8ea1bhMLYcS80JPap/boyhU=", "dev": true }, "karma": { "version": "0.13.22", - "resolved": "http://registry.npmjs.org/karma/-/karma-0.13.22.tgz", + "resolved": "https://registry.npmjs.org/karma/-/karma-0.13.22.tgz", "integrity": "sha1-B3ULG9Bj1+fnuRvNLmNU2PKqh0Q=", "dev": true, "requires": { @@ -5795,7 +5801,7 @@ }, "karma-jasmine": { "version": "0.3.8", - "resolved": "http://registry.npmjs.org/karma-jasmine/-/karma-jasmine-0.3.8.tgz", + "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-0.3.8.tgz", "integrity": "sha1-W2RXeRrZuJqhc/B54+vhuMgFI2w=", "dev": true }, @@ -6136,7 +6142,7 @@ }, "engine.io-client": { "version": "3.2.1", - "resolved": "http://registry.npmjs.org/engine.io-client/-/engine.io-client-3.2.1.tgz", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-3.2.1.tgz", "integrity": "sha512-y5AbkytWeM4jQr7m/koQLc5AxpRKC1hEVUb/s1FUAWEJq5AzJJ4NLvzuKPuxtDi5Mq755WuDvZ6Iv2rXj4PTzw==", "dev": true, "requires": { @@ -6463,7 +6469,7 @@ }, "lru-cache": { "version": "2.2.4", - "resolved": "http://registry.npmjs.org/lru-cache/-/lru-cache-2.2.4.tgz", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.2.4.tgz", "integrity": "sha1-bGWGGb7PFAMdDQtZSxYELOTcBj0=", "dev": true }, @@ -6566,7 +6572,7 @@ }, "socket.io-parser": { "version": "3.2.0", - "resolved": "http://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.2.0.tgz", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.2.0.tgz", "integrity": "sha512-FYiBx7rc/KORMJlgsXysflWx/RIvtqZbyGLlHZvjfmPTPeuD/I8MaW7cfFrj5tRltICJdgwflhfZ3NVVbVLFQA==", "dev": true, "requires": { @@ -7617,14 +7623,6 @@ "mimic-fn": "^1.0.0" } }, - "opn": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/opn/-/opn-5.4.0.tgz", - "integrity": "sha512-YF9MNdVy/0qvJvDtunAOzFw9iasOQHpVthTCvGzxt61Il64AYSGdK+rYwld7NAfk9qJ7dt+hymBNSc9LNYS+Sw==", - "requires": { - "is-wsl": "^1.1.0" - } - }, "optimist": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", diff --git a/package.json b/package.json index 0fd3ae18b9ee..a27d47c72d73 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@webcomponents/webcomponentsjs": "2.1.2", "awesomplete": "github:LeaVerou/awesomplete", "bootstrap": "4.1.3", - "choices.js": "^3.0.4", + "choices.js": "^4.1.0", "chosen-js": "1.6.2", "codemirror": "5.38.0", "cropperjs": "1.2.2",