Fix id types (#743)

* Set ids to be numbers

* Split out _setLoading into start/stop methods

* Build
This commit is contained in:
Josh Johnson 2019-11-08 09:19:18 +00:00 committed by GitHub
parent 7dcc155b8f
commit d04031e02f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 117 additions and 151 deletions

60
package-lock.json generated
View file

@ -1944,7 +1944,7 @@
}, },
"browserify-aes": { "browserify-aes": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz",
"integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -1981,7 +1981,7 @@
}, },
"browserify-rsa": { "browserify-rsa": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz", "resolved": "http://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz",
"integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=", "integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -2026,7 +2026,7 @@
}, },
"buffer": { "buffer": {
"version": "4.9.1", "version": "4.9.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz", "resolved": "http://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
"integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=", "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -2213,7 +2213,7 @@
}, },
"camelcase-keys": { "camelcase-keys": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz", "resolved": "http://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
"integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=", "integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -2807,7 +2807,7 @@
}, },
"create-hash": { "create-hash": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
"integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -2820,7 +2820,7 @@
}, },
"create-hmac": { "create-hmac": {
"version": "1.1.7", "version": "1.1.7",
"resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", "resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
"integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -3350,7 +3350,7 @@
}, },
"diffie-hellman": { "diffie-hellman": {
"version": "5.0.3", "version": "5.0.3",
"resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", "resolved": "http://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
"integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==", "integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -3420,7 +3420,7 @@
}, },
"duplexer": { "duplexer": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
"integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=",
"dev": true "dev": true
}, },
@ -4092,7 +4092,7 @@
"dependencies": { "dependencies": {
"pify": { "pify": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true "dev": true
} }
@ -5873,7 +5873,7 @@
}, },
"get-stream": { "get-stream": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz",
"integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=",
"dev": true "dev": true
}, },
@ -6038,7 +6038,7 @@
}, },
"got": { "got": {
"version": "6.7.1", "version": "6.7.1",
"resolved": "https://registry.npmjs.org/got/-/got-6.7.1.tgz", "resolved": "http://registry.npmjs.org/got/-/got-6.7.1.tgz",
"integrity": "sha1-JAzQV4WpoY5WHcG0S0HHY+8ejbA=", "integrity": "sha1-JAzQV4WpoY5WHcG0S0HHY+8ejbA=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -6903,7 +6903,7 @@
}, },
"is-obj": { "is-obj": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
"integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=",
"dev": true "dev": true
}, },
@ -7866,7 +7866,7 @@
}, },
"load-json-file": { "load-json-file": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
"integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -7887,7 +7887,7 @@
}, },
"pify": { "pify": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true "dev": true
} }
@ -8145,7 +8145,7 @@
}, },
"media-typer": { "media-typer": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=",
"dev": true "dev": true
}, },
@ -8186,7 +8186,7 @@
}, },
"meow": { "meow": {
"version": "3.7.0", "version": "3.7.0",
"resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz", "resolved": "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
"integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=", "integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -8214,7 +8214,7 @@
}, },
"load-json-file": { "load-json-file": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -8256,7 +8256,7 @@
}, },
"pify": { "pify": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true "dev": true
}, },
@ -8454,7 +8454,7 @@
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -8724,7 +8724,7 @@
"dependencies": { "dependencies": {
"semver": { "semver": {
"version": "5.3.0", "version": "5.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz", "resolved": "http://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
"integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=", "integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=",
"dev": true "dev": true
} }
@ -9603,7 +9603,7 @@
}, },
"onetime": { "onetime": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=",
"dev": true "dev": true
}, },
@ -9653,7 +9653,7 @@
}, },
"ora": { "ora": {
"version": "0.2.3", "version": "0.2.3",
"resolved": "https://registry.npmjs.org/ora/-/ora-0.2.3.tgz", "resolved": "http://registry.npmjs.org/ora/-/ora-0.2.3.tgz",
"integrity": "sha1-N1J9Igrc1Tw5tzVx11QVbV22V6Q=", "integrity": "sha1-N1J9Igrc1Tw5tzVx11QVbV22V6Q=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -9704,7 +9704,7 @@
}, },
"os-locale": { "os-locale": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
"integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -9940,7 +9940,7 @@
"dependencies": { "dependencies": {
"pify": { "pify": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true "dev": true
} }
@ -11770,7 +11770,7 @@
}, },
"safe-regex": { "safe-regex": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", "resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -12134,7 +12134,7 @@
}, },
"sha.js": { "sha.js": {
"version": "2.4.11", "version": "2.4.11",
"resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
"integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -12215,7 +12215,7 @@
}, },
"slice-ansi": { "slice-ansi": {
"version": "0.0.4", "version": "0.0.4",
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz", "resolved": "http://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz",
"integrity": "sha1-7b+JA/ZvfOL46v1s7tZeJkyDGzU=", "integrity": "sha1-7b+JA/ZvfOL46v1s7tZeJkyDGzU=",
"dev": true "dev": true
}, },
@ -12635,7 +12635,7 @@
}, },
"strip-ansi": { "strip-ansi": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -12650,7 +12650,7 @@
}, },
"strip-eof": { "strip-eof": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
"dev": true "dev": true
}, },
@ -12983,7 +12983,7 @@
}, },
"through": { "through": {
"version": "2.3.8", "version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
"dev": true "dev": true
}, },

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<browserconfig> <browserconfig>
<msapplication> <msapplication>
<tile> <tile>
<square150x150logo src="/assets/images/mstile-150x150.png"/> <square150x150logo src="/assets/images/mstile-150x150.png"/>
<TileColor>#ffffff</TileColor> <TileColor>#ffffff</TileColor>
</tile> </tile>
</msapplication> </msapplication>
</browserconfig> </browserconfig>

View file

@ -1372,8 +1372,8 @@ var getAdjacentEl = function getAdjacentEl(startEl, selector, direction) {
return sibling; return sibling;
}; };
/** /**
* @param {HTMLElement} element * @param {Element} element
* @param {HTMLElement} parent * @param {Element} parent
* @param {-1 | 1} direction * @param {-1 | 1} direction
* @returns {boolean} * @returns {boolean}
*/ */
@ -1412,7 +1412,7 @@ var sanitise = function sanitise(value) {
return value.replace(/&/g, '&amp;').replace(/>/g, '&rt;').replace(/</g, '&lt;').replace(/"/g, '&quot;'); return value.replace(/&/g, '&amp;').replace(/>/g, '&rt;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
}; };
/** /**
* @returns {function} * @returns {() => (str: string) => Element}
*/ */
var strToEl = function () { var strToEl = function () {
@ -1622,14 +1622,14 @@ function () {
} }
/** /**
* Get group by group id * Get group by group id
* @param {string} id Group ID * @param {number} id Group ID
* @returns {Group | undefined} Group data * @returns {Group | undefined} Group data
*/ */
; ;
_proto.getGroupById = function getGroupById(id) { _proto.getGroupById = function getGroupById(id) {
return this.groups.find(function (group) { return this.groups.find(function (group) {
return group.id === parseInt(id, 10); return group.id === id;
}); });
}; };
@ -2411,7 +2411,7 @@ function () {
this.element.scrollTop = 0; this.element.scrollTop = 0;
} }
/** /**
* @param {HTMLElement} element * @param {Element} element
* @param {1 | -1} direction * @param {1 | -1} direction
*/ */
; ;
@ -3886,13 +3886,13 @@ function () {
this.containerOuter.removeLoadingState(); this.containerOuter.removeLoadingState();
this._setLoading(true); this._startLoading();
choicesArrayOrFetcher.forEach(function (groupOrChoice) { choicesArrayOrFetcher.forEach(function (groupOrChoice) {
if (groupOrChoice.choices) { if (groupOrChoice.choices) {
_this11._addGroup({ _this11._addGroup({
id: parseInt(groupOrChoice.id, 10) || null,
group: groupOrChoice, group: groupOrChoice,
id: groupOrChoice.id || null,
valueKey: value, valueKey: value,
labelKey: label labelKey: label
}); });
@ -3908,7 +3908,7 @@ function () {
} }
}); });
this._setLoading(false); this._stopLoading();
return this; return this;
}; };
@ -4339,8 +4339,12 @@ function () {
} }
}; };
_proto._setLoading = function _setLoading(isLoading) { _proto._startLoading = function _startLoading() {
this._store.dispatch(setIsLoading(isLoading)); this._store.dispatch(setIsLoading(true));
};
_proto._stopLoading = function _stopLoading() {
this._store.dispatch(setIsLoading(false));
}; };
_proto._handleLoadingState = function _handleLoadingState(setLoading) { _proto._handleLoadingState = function _handleLoadingState(setLoading) {
@ -4513,39 +4517,21 @@ function () {
documentElement.removeEventListener('keydown', this._onKeyDown, true); documentElement.removeEventListener('keydown', this._onKeyDown, true);
documentElement.removeEventListener('touchend', this._onTouchEnd, true); documentElement.removeEventListener('touchend', this._onTouchEnd, true);
documentElement.removeEventListener('mousedown', this._onMouseDown, true); documentElement.removeEventListener('mousedown', this._onMouseDown, true);
documentElement.removeEventListener('keyup', this._onKeyUp, { documentElement.removeEventListener('keyup', this._onKeyUp);
passive: true documentElement.removeEventListener('click', this._onClick);
}); documentElement.removeEventListener('touchmove', this._onTouchMove);
documentElement.removeEventListener('click', this._onClick, { documentElement.removeEventListener('mouseover', this._onMouseOver);
passive: true
});
documentElement.removeEventListener('touchmove', this._onTouchMove, {
passive: true
});
documentElement.removeEventListener('mouseover', this._onMouseOver, {
passive: true
});
if (this._isSelectOneElement) { if (this._isSelectOneElement) {
this.containerOuter.element.removeEventListener('focus', this._onFocus, { this.containerOuter.element.removeEventListener('focus', this._onFocus);
passive: true this.containerOuter.element.removeEventListener('blur', this._onBlur);
});
this.containerOuter.element.removeEventListener('blur', this._onBlur, {
passive: true
});
} }
this.input.element.removeEventListener('focus', this._onFocus, { this.input.element.removeEventListener('focus', this._onFocus);
passive: true this.input.element.removeEventListener('blur', this._onBlur);
});
this.input.element.removeEventListener('blur', this._onBlur, {
passive: true
});
if (this.input.element.form) { if (this.input.element.form) {
this.input.element.form.removeEventListener('reset', this._onFormReset, { this.input.element.form.removeEventListener('reset', this._onFormReset);
passive: true
});
} }
this.input.removeEventListeners(); this.input.removeEventListeners();
@ -5035,7 +5021,7 @@ function () {
var passedCustomProperties = customProperties; var passedCustomProperties = customProperties;
var items = this._store.items; var items = this._store.items;
var passedLabel = label || passedValue; var passedLabel = label || passedValue;
var passedOptionId = parseInt(choiceId, 10) || -1; var passedOptionId = choiceId || -1;
var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; var group = groupId >= 0 ? this._store.getGroupById(groupId) : null;
var id = items ? items.length + 1 : 1; // If a prepended value has been passed, prepend it var id = items ? items.length + 1 : 1; // If a prepended value has been passed, prepend it
@ -5135,12 +5121,12 @@ function () {
var choiceElementId = this._baseId + "-" + this._idNames.itemChoice + "-" + choiceId; var choiceElementId = this._baseId + "-" + this._idNames.itemChoice + "-" + choiceId;
this._store.dispatch(choices_addChoice({ this._store.dispatch(choices_addChoice({
value: value,
label: choiceLabel,
id: choiceId, id: choiceId,
groupId: groupId, groupId: groupId,
disabled: isDisabled,
elementId: choiceElementId, elementId: choiceElementId,
value: value,
label: choiceLabel,
disabled: isDisabled,
customProperties: customProperties, customProperties: customProperties,
placeholder: placeholder, placeholder: placeholder,
keyCode: keyCode keyCode: keyCode
@ -5296,7 +5282,7 @@ function () {
this._highlightPosition = 0; this._highlightPosition = 0;
this._isSearching = false; this._isSearching = false;
this._setLoading(true); this._startLoading();
if (this._presetGroups.length) { if (this._presetGroups.length) {
this._addPredefinedGroups(this._presetGroups); this._addPredefinedGroups(this._presetGroups);
@ -5304,7 +5290,7 @@ function () {
this._addPredefinedChoices(this._presetChoices); this._addPredefinedChoices(this._presetChoices);
} }
this._setLoading(false); this._stopLoading();
} }
if (this._isTextElement) { if (this._isTextElement) {
@ -5342,16 +5328,14 @@ function () {
// If sorting is enabled or the user is searching, filter choices // If sorting is enabled or the user is searching, filter choices
if (this.config.shouldSort) { if (this.config.shouldSort) {
choices.sort(this.config.sorter); choices.sort(this.config.sorter);
} // Determine whether there is a selected choice }
var hasSelectedChoice = choices.some(function (choice) { var hasSelectedChoice = choices.some(function (choice) {
return choice.selected; return choice.selected;
}); });
var firstEnabledChoiceIndex = choices.findIndex(function (_choice) { var firstEnabledChoiceIndex = choices.findIndex(function (choice) {
return _choice.disabled === undefined || !_choice.disabled; return choice.disabled === undefined || !choice.disabled;
}); // Add each choice });
choices.forEach(function (choice, index) { choices.forEach(function (choice, index) {
var value = choice.value, var value = choice.value,
label = choice.label, label = choice.label,

File diff suppressed because one or more lines are too long

View file

@ -611,13 +611,13 @@ class Choices {
this.containerOuter.removeLoadingState(); this.containerOuter.removeLoadingState();
this._setLoading(true); this._startLoading();
choicesArrayOrFetcher.forEach(groupOrChoice => { choicesArrayOrFetcher.forEach(groupOrChoice => {
if (groupOrChoice.choices) { if (groupOrChoice.choices) {
this._addGroup({ this._addGroup({
id: parseInt(groupOrChoice.id, 10) || null,
group: groupOrChoice, group: groupOrChoice,
id: groupOrChoice.id || null,
valueKey: value, valueKey: value,
labelKey: label, labelKey: label,
}); });
@ -633,7 +633,7 @@ class Choices {
} }
}); });
this._setLoading(false); this._stopLoading();
return this; return this;
} }
@ -1073,8 +1073,12 @@ class Choices {
} }
} }
_setLoading(isLoading) { _startLoading() {
this._store.dispatch(setIsLoading(isLoading)); this._store.dispatch(setIsLoading(true));
}
_stopLoading() {
this._store.dispatch(setIsLoading(false));
} }
_handleLoadingState(setLoading = true) { _handleLoadingState(setLoading = true) {
@ -1271,39 +1275,21 @@ class Choices {
documentElement.removeEventListener('touchend', this._onTouchEnd, true); documentElement.removeEventListener('touchend', this._onTouchEnd, true);
documentElement.removeEventListener('mousedown', this._onMouseDown, true); documentElement.removeEventListener('mousedown', this._onMouseDown, true);
documentElement.removeEventListener('keyup', this._onKeyUp, { documentElement.removeEventListener('keyup', this._onKeyUp);
passive: true, documentElement.removeEventListener('click', this._onClick);
}); documentElement.removeEventListener('touchmove', this._onTouchMove);
documentElement.removeEventListener('click', this._onClick, { documentElement.removeEventListener('mouseover', this._onMouseOver);
passive: true,
});
documentElement.removeEventListener('touchmove', this._onTouchMove, {
passive: true,
});
documentElement.removeEventListener('mouseover', this._onMouseOver, {
passive: true,
});
if (this._isSelectOneElement) { if (this._isSelectOneElement) {
this.containerOuter.element.removeEventListener('focus', this._onFocus, { this.containerOuter.element.removeEventListener('focus', this._onFocus);
passive: true, this.containerOuter.element.removeEventListener('blur', this._onBlur);
});
this.containerOuter.element.removeEventListener('blur', this._onBlur, {
passive: true,
});
} }
this.input.element.removeEventListener('focus', this._onFocus, { this.input.element.removeEventListener('focus', this._onFocus);
passive: true, this.input.element.removeEventListener('blur', this._onBlur);
});
this.input.element.removeEventListener('blur', this._onBlur, {
passive: true,
});
if (this.input.element.form) { if (this.input.element.form) {
this.input.element.form.removeEventListener('reset', this._onFormReset, { this.input.element.form.removeEventListener('reset', this._onFormReset);
passive: true,
});
} }
this.input.removeEventListeners(); this.input.removeEventListeners();
@ -1801,7 +1787,7 @@ class Choices {
const passedCustomProperties = customProperties; const passedCustomProperties = customProperties;
const { items } = this._store; const { items } = this._store;
const passedLabel = label || passedValue; const passedLabel = label || passedValue;
const passedOptionId = parseInt(choiceId, 10) || -1; const passedOptionId = choiceId || -1;
const group = groupId >= 0 ? this._store.getGroupById(groupId) : null; const group = groupId >= 0 ? this._store.getGroupById(groupId) : null;
const id = items ? items.length + 1 : 1; const id = items ? items.length + 1 : 1;
@ -1895,12 +1881,12 @@ class Choices {
this._store.dispatch( this._store.dispatch(
addChoice({ addChoice({
value,
label: choiceLabel,
id: choiceId, id: choiceId,
groupId, groupId,
disabled: isDisabled,
elementId: choiceElementId, elementId: choiceElementId,
value,
label: choiceLabel,
disabled: isDisabled,
customProperties, customProperties,
placeholder, placeholder,
keyCode, keyCode,
@ -2067,7 +2053,7 @@ class Choices {
if (this._isSelectElement) { if (this._isSelectElement) {
this._highlightPosition = 0; this._highlightPosition = 0;
this._isSearching = false; this._isSearching = false;
this._setLoading(true); this._startLoading();
if (this._presetGroups.length) { if (this._presetGroups.length) {
this._addPredefinedGroups(this._presetGroups); this._addPredefinedGroups(this._presetGroups);
@ -2075,7 +2061,7 @@ class Choices {
this._addPredefinedChoices(this._presetChoices); this._addPredefinedChoices(this._presetChoices);
} }
this._setLoading(false); this._stopLoading();
} }
if (this._isTextElement) { if (this._isTextElement) {
@ -2113,13 +2099,11 @@ class Choices {
choices.sort(this.config.sorter); choices.sort(this.config.sorter);
} }
// Determine whether there is a selected choice
const hasSelectedChoice = choices.some(choice => choice.selected); const hasSelectedChoice = choices.some(choice => choice.selected);
const firstEnabledChoiceIndex = choices.findIndex( const firstEnabledChoiceIndex = choices.findIndex(
_choice => _choice.disabled === undefined || !_choice.disabled, choice => choice.disabled === undefined || !choice.disabled,
); );
// Add each choice
choices.forEach((choice, index) => { choices.forEach((choice, index) => {
const { value, label, customProperties, placeholder } = choice; const { value, label, customProperties, placeholder } = choice;

View file

@ -1539,12 +1539,12 @@ describe('choices', () => {
const label = 'label'; const label = 'label';
const choices = [ const choices = [
{ {
id: '1', id: 1,
value: '1', value: '1',
label: 'Test 1', label: 'Test 1',
}, },
{ {
id: '2', id: 2,
value: '2', value: '2',
label: 'Test 2', label: 'Test 2',
}, },

View file

@ -44,7 +44,7 @@ export default class List {
} }
/** /**
* @param {HTMLElement} element * @param {Element} element
* @param {1 | -1} direction * @param {1 | -1} direction
*/ */
scrollToChildElement(element, direction) { scrollToChildElement(element, direction) {

View file

@ -89,8 +89,8 @@ export const getAdjacentEl = (startEl, selector, direction = 1) => {
}; };
/** /**
* @param {HTMLElement} element * @param {Element} element
* @param {HTMLElement} parent * @param {Element} parent
* @param {-1 | 1} direction * @param {-1 | 1} direction
* @returns {boolean} * @returns {boolean}
*/ */
@ -131,7 +131,7 @@ export const sanitise = value => {
}; };
/** /**
* @returns {function} * @returns {() => (str: string) => Element}
*/ */
export const strToEl = (() => { export const strToEl = (() => {
const tmpEl = document.createElement('div'); const tmpEl = document.createElement('div');

View file

@ -152,10 +152,10 @@ export default class Store {
/** /**
* Get group by group id * Get group by group id
* @param {string} id Group ID * @param {number} id Group ID
* @returns {Group | undefined} Group data * @returns {Group | undefined} Group data
*/ */
getGroupById(id) { getGroupById(id) {
return this.groups.find(group => group.id === parseInt(id, 10)); return this.groups.find(group => group.id === id);
} }
} }

View file

@ -245,10 +245,8 @@ describe('reducers/store', () => {
describe('getGroupById', () => { describe('getGroupById', () => {
it('returns group by id', () => { it('returns group by id', () => {
const id = '1'; const id = 1;
const expectedResponse = state.groups.find( const expectedResponse = state.groups.find(group => group.id === id);
group => group.id === parseInt(id, 10),
);
const actualResponse = instance.getGroupById(id); const actualResponse = instance.getGroupById(id);
expect(actualResponse).to.eql(expectedResponse); expect(actualResponse).to.eql(expectedResponse);
}); });

16
types/index.d.ts vendored
View file

@ -23,12 +23,12 @@ declare namespace Choices {
} }
interface Choice { interface Choice {
id?: string; id?: number;
customProperties?: Record<string, any>; customProperties?: Record<string, any>;
disabled?: boolean; disabled?: boolean;
active?: boolean; active?: boolean;
elementId?: string; elementId?: string;
groupId?: string; groupId?: number;
keyCode?: number; keyCode?: number;
label: string; label: string;
placeholder?: boolean; placeholder?: boolean;
@ -37,14 +37,14 @@ declare namespace Choices {
} }
interface Group { interface Group {
id?: string; id?: number;
active?: boolean; active?: boolean;
disabled?: boolean; disabled?: boolean;
value: any; value: any;
} }
interface Item extends Choice { interface Item extends Choice {
choiceId?: string; choiceId?: number;
keyCode?: number; keyCode?: number;
highlighted?: boolean; highlighted?: boolean;
} }
@ -61,7 +61,7 @@ declare namespace Choices {
* Arguments: id, value, label, groupValue, keyCode * Arguments: id, value, label, groupValue, keyCode
*/ */
addItem: CustomEvent<{ addItem: CustomEvent<{
id: string; id: number;
value: string; value: string;
label: string; label: string;
groupValue: string; groupValue: string;
@ -76,7 +76,7 @@ declare namespace Choices {
* Arguments: id, value, label, groupValue * Arguments: id, value, label, groupValue
*/ */
removeItem: CustomEvent<{ removeItem: CustomEvent<{
id: string; id: number;
value: string; value: string;
label: string; label: string;
groupValue: string; groupValue: string;
@ -90,7 +90,7 @@ declare namespace Choices {
* Arguments: id, value, label, groupValue * Arguments: id, value, label, groupValue
*/ */
highlightItem: CustomEvent<{ highlightItem: CustomEvent<{
id: string; id: number;
value: string; value: string;
label: string; label: string;
groupValue: string; groupValue: string;
@ -104,7 +104,7 @@ declare namespace Choices {
* Arguments: id, value, label, groupValue * Arguments: id, value, label, groupValue
*/ */
unhighlightItem: CustomEvent<{ unhighlightItem: CustomEvent<{
id: string; id: number;
value: string; value: string;
label: string; label: string;
groupValue: string; groupValue: string;