Skip to content

Commit 1fdcf37

Browse files
committed
Compile JS files
1 parent d0a7e70 commit 1fdcf37

14 files changed

Lines changed: 197 additions & 163 deletions

public/assets/scripts/choices.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@
135135
highlighted: highlighted,
136136
}); };
137137

138-
/* eslint-disable @typescript-eslint/no-explicit-any */
139138
var getRandomNumber = function (min, max) { return Math.floor(Math.random() * (max - min) + min); };
140139
var generateChars = function (length) {
141140
return Array.from({ length: length }, function () { return getRandomNumber(0, 36).toString(36); }).join('');
@@ -268,6 +267,7 @@
268267
/**
269268
* Returns an array of keys present on the first but missing on the second object
270269
*/
270+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
271271
var diff = function (a, b) {
272272
var aKeys = Object.keys(a).sort();
273273
var bKeys = Object.keys(b).sort();
@@ -773,7 +773,7 @@
773773
var choice = groupOrChoice;
774774
var result = {
775775
id: 0, // actual ID will be assigned during _addChoice
776-
groupId: 0, // actual ID will be assigned during _addGroup but before _addChoice
776+
group: null, // actual group will be assigned during _addGroup but before _addChoice
777777
score: 0, // used in search
778778
rank: 0, // used in search, stable sort order
779779
value: choice.value,
@@ -850,7 +850,7 @@
850850
}
851851
return {
852852
id: 0,
853-
groupId: 0,
853+
group: null,
854854
score: 0,
855855
rank: 0,
856856
value: option.value,
@@ -1011,8 +1011,8 @@
10111011
break;
10121012
}
10131013
case ActionType.REMOVE_CHOICE: {
1014-
state = state.filter(function (item) { return item.id !== action.choice.id; });
10151014
removeItem(action.choice);
1015+
state = state.filter(function (item) { return item.id !== action.choice.id; });
10161016
break;
10171017
}
10181018
case ActionType.HIGHLIGHT_ITEM: {
@@ -1065,6 +1065,9 @@
10651065
}
10661066
case ActionType.REMOVE_CHOICE: {
10671067
action.choice.choiceEl = undefined;
1068+
if (action.choice.group) {
1069+
action.choice.group.choices = action.choice.group.choices.filter(function (obj) { return obj.id !== action.choice.id; });
1070+
}
10681071
state = state.filter(function (obj) { return obj.id !== action.choice.id; });
10691072
break;
10701073
}
@@ -3168,7 +3171,6 @@
31683171
label = escapeForTemplate(allowHTML, label);
31693172
label += " (".concat(groupName, ")");
31703173
label = { trusted: label };
3171-
div.dataset.groupId = "".concat(choice.groupId);
31723174
}
31733175
var describedBy = div;
31743176
if (choice.labelClass) {
@@ -3196,13 +3198,16 @@
31963198
if (choice.placeholder) {
31973199
addClassesToElement(div, placeholder);
31983200
}
3199-
div.setAttribute('role', choice.groupId ? 'treeitem' : 'option');
3201+
div.setAttribute('role', choice.group ? 'treeitem' : 'option');
32003202
div.dataset.choice = '';
32013203
div.dataset.id = choice.id;
32023204
div.dataset.value = rawValue;
32033205
if (selectText) {
32043206
div.dataset.selectText = selectText;
32053207
}
3208+
if (choice.group) {
3209+
div.dataset.groupId = "".concat(choice.group.id);
3210+
}
32063211
assignCustomProperties(div, choice, false);
32073212
if (choice.disabled) {
32083213
addClassesToElement(div, itemDisabled);
@@ -3637,12 +3642,9 @@
36373642
};
36383643
Choices.prototype.getValue = function (valueOnly) {
36393644
var _this = this;
3640-
if (valueOnly === void 0) { valueOnly = false; }
3641-
var values = this._store.items.reduce(function (selectedItems, item) {
3642-
var itemValue = valueOnly ? item.value : _this._getChoiceForOutput(item);
3643-
selectedItems.push(itemValue);
3644-
return selectedItems;
3645-
}, []);
3645+
var values = this._store.items.map(function (item) {
3646+
return (valueOnly ? item.value : _this._getChoiceForOutput(item));
3647+
});
36463648
return this._isSelectOneElement || this.config.singleModeForMultiSelect ? values[0] : values;
36473649
};
36483650
Choices.prototype.setValue = function (items) {
@@ -3846,17 +3848,20 @@
38463848
});
38473849
}
38483850
_this.clearStore(false);
3849-
choicesFromOptions.forEach(function (groupOrChoice) {
3850-
if ('choices' in groupOrChoice) {
3851-
return;
3852-
}
3853-
var choice = groupOrChoice;
3851+
var updateChoice = function (choice) {
38543852
if (deselectAll) {
38553853
_this._store.dispatch(removeItem$1(choice));
38563854
}
38573855
else if (existingItems[choice.value]) {
38583856
choice.selected = true;
38593857
}
3858+
};
3859+
choicesFromOptions.forEach(function (groupOrChoice) {
3860+
if ('choices' in groupOrChoice) {
3861+
groupOrChoice.choices.forEach(updateChoice);
3862+
return;
3863+
}
3864+
updateChoice(groupOrChoice);
38603865
});
38613866
/* @todo only generate add events for the added options instead of all
38623867
if (withEvents) {
@@ -4012,13 +4017,16 @@
40124017
}
40134018
if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) {
40144019
// If we have a placeholder choice along with groups
4015-
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false, undefined);
4020+
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.group; }), false, undefined);
40164021
}
40174022
// If we have grouped options
40184023
if (activeGroups.length && !isSearching) {
40194024
if (config.shouldSort) {
40204025
activeGroups.sort(config.sorter);
40214026
}
4027+
// render Choices without group first, regardless of sort, otherwise they won't be distinguishable
4028+
// from the last group
4029+
renderChoices(activeChoices.filter(function (choice) { return !choice.placeholder && !choice.group; }), false, undefined);
40224030
activeGroups.forEach(function (group) {
40234031
var groupChoices = renderableChoices(group.choices);
40244032
if (groupChoices.length) {
@@ -4159,11 +4167,8 @@
41594167
}
41604168
}
41614169
};
4170+
// eslint-disable-next-line class-methods-use-this
41624171
Choices.prototype._getChoiceForOutput = function (choice, keyCode) {
4163-
if (!choice) {
4164-
return undefined;
4165-
}
4166-
var group = choice.groupId ? this._store.getGroupById(choice.groupId) : null;
41674172
return {
41684173
id: choice.id,
41694174
highlighted: choice.highlighted,
@@ -4175,7 +4180,7 @@
41754180
label: choice.label,
41764181
placeholder: choice.placeholder,
41774182
value: choice.value,
4178-
groupValue: group && group.label ? group.label : undefined,
4183+
groupValue: choice.group ? choice.group.label : undefined,
41794184
element: choice.element,
41804185
keyCode: keyCode,
41814186
};
@@ -4194,7 +4199,7 @@
41944199
if (!items.length || !this.config.removeItems || !this.config.removeItemButton) {
41954200
return;
41964201
}
4197-
var id = element && parseDataSetId(element.parentNode);
4202+
var id = element && parseDataSetId(element.parentElement);
41984203
var itemToRemove = id && items.find(function (item) { return item.id === id; });
41994204
if (!itemToRemove) {
42004205
return;
@@ -5000,7 +5005,7 @@
50005005
this._lastAddedGroupId++;
50015006
group.id = this._lastAddedGroupId;
50025007
group.choices.forEach(function (item) {
5003-
item.groupId = group.id;
5008+
item.group = group;
50045009
if (group.disabled) {
50055010
item.disabled = true;
50065011
}

public/assets/scripts/choices.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/scripts/choices.mjs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ var highlightItem = function (item, highlighted) { return ({
129129
highlighted: highlighted,
130130
}); };
131131

132-
/* eslint-disable @typescript-eslint/no-explicit-any */
133132
var getRandomNumber = function (min, max) { return Math.floor(Math.random() * (max - min) + min); };
134133
var generateChars = function (length) {
135134
return Array.from({ length: length }, function () { return getRandomNumber(0, 36).toString(36); }).join('');
@@ -262,6 +261,7 @@ var dispatchEvent = function (element, type, customArgs) {
262261
/**
263262
* Returns an array of keys present on the first but missing on the second object
264263
*/
264+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
265265
var diff = function (a, b) {
266266
var aKeys = Object.keys(a).sort();
267267
var bKeys = Object.keys(b).sort();
@@ -767,7 +767,7 @@ var mapInputToChoice = function (value, allowGroup) {
767767
var choice = groupOrChoice;
768768
var result = {
769769
id: 0, // actual ID will be assigned during _addChoice
770-
groupId: 0, // actual ID will be assigned during _addGroup but before _addChoice
770+
group: null, // actual group will be assigned during _addGroup but before _addChoice
771771
score: 0, // used in search
772772
rank: 0, // used in search, stable sort order
773773
value: choice.value,
@@ -844,7 +844,7 @@ var WrappedSelect = /** @class */ (function (_super) {
844844
}
845845
return {
846846
id: 0,
847-
groupId: 0,
847+
group: null,
848848
score: 0,
849849
rank: 0,
850850
value: option.value,
@@ -1005,8 +1005,8 @@ function items(s, action, context) {
10051005
break;
10061006
}
10071007
case ActionType.REMOVE_CHOICE: {
1008-
state = state.filter(function (item) { return item.id !== action.choice.id; });
10091008
removeItem(action.choice);
1009+
state = state.filter(function (item) { return item.id !== action.choice.id; });
10101010
break;
10111011
}
10121012
case ActionType.HIGHLIGHT_ITEM: {
@@ -1059,6 +1059,9 @@ function choices(s, action, context) {
10591059
}
10601060
case ActionType.REMOVE_CHOICE: {
10611061
action.choice.choiceEl = undefined;
1062+
if (action.choice.group) {
1063+
action.choice.group.choices = action.choice.group.choices.filter(function (obj) { return obj.id !== action.choice.id; });
1064+
}
10621065
state = state.filter(function (obj) { return obj.id !== action.choice.id; });
10631066
break;
10641067
}
@@ -3162,7 +3165,6 @@ var templates = {
31623165
label = escapeForTemplate(allowHTML, label);
31633166
label += " (".concat(groupName, ")");
31643167
label = { trusted: label };
3165-
div.dataset.groupId = "".concat(choice.groupId);
31663168
}
31673169
var describedBy = div;
31683170
if (choice.labelClass) {
@@ -3190,13 +3192,16 @@ var templates = {
31903192
if (choice.placeholder) {
31913193
addClassesToElement(div, placeholder);
31923194
}
3193-
div.setAttribute('role', choice.groupId ? 'treeitem' : 'option');
3195+
div.setAttribute('role', choice.group ? 'treeitem' : 'option');
31943196
div.dataset.choice = '';
31953197
div.dataset.id = choice.id;
31963198
div.dataset.value = rawValue;
31973199
if (selectText) {
31983200
div.dataset.selectText = selectText;
31993201
}
3202+
if (choice.group) {
3203+
div.dataset.groupId = "".concat(choice.group.id);
3204+
}
32003205
assignCustomProperties(div, choice, false);
32013206
if (choice.disabled) {
32023207
addClassesToElement(div, itemDisabled);
@@ -3631,12 +3636,9 @@ var Choices = /** @class */ (function () {
36313636
};
36323637
Choices.prototype.getValue = function (valueOnly) {
36333638
var _this = this;
3634-
if (valueOnly === void 0) { valueOnly = false; }
3635-
var values = this._store.items.reduce(function (selectedItems, item) {
3636-
var itemValue = valueOnly ? item.value : _this._getChoiceForOutput(item);
3637-
selectedItems.push(itemValue);
3638-
return selectedItems;
3639-
}, []);
3639+
var values = this._store.items.map(function (item) {
3640+
return (valueOnly ? item.value : _this._getChoiceForOutput(item));
3641+
});
36403642
return this._isSelectOneElement || this.config.singleModeForMultiSelect ? values[0] : values;
36413643
};
36423644
Choices.prototype.setValue = function (items) {
@@ -3840,17 +3842,20 @@ var Choices = /** @class */ (function () {
38403842
});
38413843
}
38423844
_this.clearStore(false);
3843-
choicesFromOptions.forEach(function (groupOrChoice) {
3844-
if ('choices' in groupOrChoice) {
3845-
return;
3846-
}
3847-
var choice = groupOrChoice;
3845+
var updateChoice = function (choice) {
38483846
if (deselectAll) {
38493847
_this._store.dispatch(removeItem$1(choice));
38503848
}
38513849
else if (existingItems[choice.value]) {
38523850
choice.selected = true;
38533851
}
3852+
};
3853+
choicesFromOptions.forEach(function (groupOrChoice) {
3854+
if ('choices' in groupOrChoice) {
3855+
groupOrChoice.choices.forEach(updateChoice);
3856+
return;
3857+
}
3858+
updateChoice(groupOrChoice);
38543859
});
38553860
/* @todo only generate add events for the added options instead of all
38563861
if (withEvents) {
@@ -4006,13 +4011,16 @@ var Choices = /** @class */ (function () {
40064011
}
40074012
if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) {
40084013
// If we have a placeholder choice along with groups
4009-
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false, undefined);
4014+
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.group; }), false, undefined);
40104015
}
40114016
// If we have grouped options
40124017
if (activeGroups.length && !isSearching) {
40134018
if (config.shouldSort) {
40144019
activeGroups.sort(config.sorter);
40154020
}
4021+
// render Choices without group first, regardless of sort, otherwise they won't be distinguishable
4022+
// from the last group
4023+
renderChoices(activeChoices.filter(function (choice) { return !choice.placeholder && !choice.group; }), false, undefined);
40164024
activeGroups.forEach(function (group) {
40174025
var groupChoices = renderableChoices(group.choices);
40184026
if (groupChoices.length) {
@@ -4153,11 +4161,8 @@ var Choices = /** @class */ (function () {
41534161
}
41544162
}
41554163
};
4164+
// eslint-disable-next-line class-methods-use-this
41564165
Choices.prototype._getChoiceForOutput = function (choice, keyCode) {
4157-
if (!choice) {
4158-
return undefined;
4159-
}
4160-
var group = choice.groupId ? this._store.getGroupById(choice.groupId) : null;
41614166
return {
41624167
id: choice.id,
41634168
highlighted: choice.highlighted,
@@ -4169,7 +4174,7 @@ var Choices = /** @class */ (function () {
41694174
label: choice.label,
41704175
placeholder: choice.placeholder,
41714176
value: choice.value,
4172-
groupValue: group && group.label ? group.label : undefined,
4177+
groupValue: choice.group ? choice.group.label : undefined,
41734178
element: choice.element,
41744179
keyCode: keyCode,
41754180
};
@@ -4188,7 +4193,7 @@ var Choices = /** @class */ (function () {
41884193
if (!items.length || !this.config.removeItems || !this.config.removeItemButton) {
41894194
return;
41904195
}
4191-
var id = element && parseDataSetId(element.parentNode);
4196+
var id = element && parseDataSetId(element.parentElement);
41924197
var itemToRemove = id && items.find(function (item) { return item.id === id; });
41934198
if (!itemToRemove) {
41944199
return;
@@ -4994,7 +4999,7 @@ var Choices = /** @class */ (function () {
49944999
this._lastAddedGroupId++;
49955000
group.id = this._lastAddedGroupId;
49965001
group.choices.forEach(function (item) {
4997-
item.groupId = group.id;
5002+
item.group = group;
49985003
if (group.disabled) {
49995004
item.disabled = true;
50005005
}

0 commit comments

Comments
 (0)