Skip to content

Commit

Permalink
Compile JS files
Browse files Browse the repository at this point in the history
  • Loading branch information
Xon committed Sep 5, 2024
1 parent d0a7e70 commit 1fdcf37
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 163 deletions.
55 changes: 30 additions & 25 deletions public/assets/scripts/choices.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
highlighted: highlighted,
}); };

/* eslint-disable @typescript-eslint/no-explicit-any */
var getRandomNumber = function (min, max) { return Math.floor(Math.random() * (max - min) + min); };
var generateChars = function (length) {
return Array.from({ length: length }, function () { return getRandomNumber(0, 36).toString(36); }).join('');
Expand Down Expand Up @@ -268,6 +267,7 @@
/**
* Returns an array of keys present on the first but missing on the second object
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var diff = function (a, b) {
var aKeys = Object.keys(a).sort();
var bKeys = Object.keys(b).sort();
Expand Down Expand Up @@ -773,7 +773,7 @@
var choice = groupOrChoice;
var result = {
id: 0, // actual ID will be assigned during _addChoice
groupId: 0, // actual ID will be assigned during _addGroup but before _addChoice
group: null, // actual group will be assigned during _addGroup but before _addChoice
score: 0, // used in search
rank: 0, // used in search, stable sort order
value: choice.value,
Expand Down Expand Up @@ -850,7 +850,7 @@
}
return {
id: 0,
groupId: 0,
group: null,
score: 0,
rank: 0,
value: option.value,
Expand Down Expand Up @@ -1011,8 +1011,8 @@
break;
}
case ActionType.REMOVE_CHOICE: {
state = state.filter(function (item) { return item.id !== action.choice.id; });
removeItem(action.choice);
state = state.filter(function (item) { return item.id !== action.choice.id; });
break;
}
case ActionType.HIGHLIGHT_ITEM: {
Expand Down Expand Up @@ -1065,6 +1065,9 @@
}
case ActionType.REMOVE_CHOICE: {
action.choice.choiceEl = undefined;
if (action.choice.group) {
action.choice.group.choices = action.choice.group.choices.filter(function (obj) { return obj.id !== action.choice.id; });
}
state = state.filter(function (obj) { return obj.id !== action.choice.id; });
break;
}
Expand Down Expand Up @@ -3168,7 +3171,6 @@
label = escapeForTemplate(allowHTML, label);
label += " (".concat(groupName, ")");
label = { trusted: label };
div.dataset.groupId = "".concat(choice.groupId);
}
var describedBy = div;
if (choice.labelClass) {
Expand Down Expand Up @@ -3196,13 +3198,16 @@
if (choice.placeholder) {
addClassesToElement(div, placeholder);
}
div.setAttribute('role', choice.groupId ? 'treeitem' : 'option');
div.setAttribute('role', choice.group ? 'treeitem' : 'option');
div.dataset.choice = '';
div.dataset.id = choice.id;
div.dataset.value = rawValue;
if (selectText) {
div.dataset.selectText = selectText;
}
if (choice.group) {
div.dataset.groupId = "".concat(choice.group.id);
}
assignCustomProperties(div, choice, false);
if (choice.disabled) {
addClassesToElement(div, itemDisabled);
Expand Down Expand Up @@ -3637,12 +3642,9 @@
};
Choices.prototype.getValue = function (valueOnly) {
var _this = this;
if (valueOnly === void 0) { valueOnly = false; }
var values = this._store.items.reduce(function (selectedItems, item) {
var itemValue = valueOnly ? item.value : _this._getChoiceForOutput(item);
selectedItems.push(itemValue);
return selectedItems;
}, []);
var values = this._store.items.map(function (item) {
return (valueOnly ? item.value : _this._getChoiceForOutput(item));
});
return this._isSelectOneElement || this.config.singleModeForMultiSelect ? values[0] : values;
};
Choices.prototype.setValue = function (items) {
Expand Down Expand Up @@ -3846,17 +3848,20 @@
});
}
_this.clearStore(false);
choicesFromOptions.forEach(function (groupOrChoice) {
if ('choices' in groupOrChoice) {
return;
}
var choice = groupOrChoice;
var updateChoice = function (choice) {
if (deselectAll) {
_this._store.dispatch(removeItem$1(choice));
}
else if (existingItems[choice.value]) {
choice.selected = true;
}
};
choicesFromOptions.forEach(function (groupOrChoice) {
if ('choices' in groupOrChoice) {
groupOrChoice.choices.forEach(updateChoice);
return;
}
updateChoice(groupOrChoice);
});
/* @todo only generate add events for the added options instead of all
if (withEvents) {
Expand Down Expand Up @@ -4012,13 +4017,16 @@
}
if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) {
// If we have a placeholder choice along with groups
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false, undefined);
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.group; }), false, undefined);
}
// If we have grouped options
if (activeGroups.length && !isSearching) {
if (config.shouldSort) {
activeGroups.sort(config.sorter);
}
// render Choices without group first, regardless of sort, otherwise they won't be distinguishable
// from the last group
renderChoices(activeChoices.filter(function (choice) { return !choice.placeholder && !choice.group; }), false, undefined);
activeGroups.forEach(function (group) {
var groupChoices = renderableChoices(group.choices);
if (groupChoices.length) {
Expand Down Expand Up @@ -4159,11 +4167,8 @@
}
}
};
// eslint-disable-next-line class-methods-use-this
Choices.prototype._getChoiceForOutput = function (choice, keyCode) {
if (!choice) {
return undefined;
}
var group = choice.groupId ? this._store.getGroupById(choice.groupId) : null;
return {
id: choice.id,
highlighted: choice.highlighted,
Expand All @@ -4175,7 +4180,7 @@
label: choice.label,
placeholder: choice.placeholder,
value: choice.value,
groupValue: group && group.label ? group.label : undefined,
groupValue: choice.group ? choice.group.label : undefined,
element: choice.element,
keyCode: keyCode,
};
Expand All @@ -4194,7 +4199,7 @@
if (!items.length || !this.config.removeItems || !this.config.removeItemButton) {
return;
}
var id = element && parseDataSetId(element.parentNode);
var id = element && parseDataSetId(element.parentElement);
var itemToRemove = id && items.find(function (item) { return item.id === id; });
if (!itemToRemove) {
return;
Expand Down Expand Up @@ -5000,7 +5005,7 @@
this._lastAddedGroupId++;
group.id = this._lastAddedGroupId;
group.choices.forEach(function (item) {
item.groupId = group.id;
item.group = group;
if (group.disabled) {
item.disabled = true;
}
Expand Down
2 changes: 1 addition & 1 deletion public/assets/scripts/choices.min.js

Large diffs are not rendered by default.

55 changes: 30 additions & 25 deletions public/assets/scripts/choices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ var highlightItem = function (item, highlighted) { return ({
highlighted: highlighted,
}); };

/* eslint-disable @typescript-eslint/no-explicit-any */
var getRandomNumber = function (min, max) { return Math.floor(Math.random() * (max - min) + min); };
var generateChars = function (length) {
return Array.from({ length: length }, function () { return getRandomNumber(0, 36).toString(36); }).join('');
Expand Down Expand Up @@ -262,6 +261,7 @@ var dispatchEvent = function (element, type, customArgs) {
/**
* Returns an array of keys present on the first but missing on the second object
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var diff = function (a, b) {
var aKeys = Object.keys(a).sort();
var bKeys = Object.keys(b).sort();
Expand Down Expand Up @@ -767,7 +767,7 @@ var mapInputToChoice = function (value, allowGroup) {
var choice = groupOrChoice;
var result = {
id: 0, // actual ID will be assigned during _addChoice
groupId: 0, // actual ID will be assigned during _addGroup but before _addChoice
group: null, // actual group will be assigned during _addGroup but before _addChoice
score: 0, // used in search
rank: 0, // used in search, stable sort order
value: choice.value,
Expand Down Expand Up @@ -844,7 +844,7 @@ var WrappedSelect = /** @class */ (function (_super) {
}
return {
id: 0,
groupId: 0,
group: null,
score: 0,
rank: 0,
value: option.value,
Expand Down Expand Up @@ -1005,8 +1005,8 @@ function items(s, action, context) {
break;
}
case ActionType.REMOVE_CHOICE: {
state = state.filter(function (item) { return item.id !== action.choice.id; });
removeItem(action.choice);
state = state.filter(function (item) { return item.id !== action.choice.id; });
break;
}
case ActionType.HIGHLIGHT_ITEM: {
Expand Down Expand Up @@ -1059,6 +1059,9 @@ function choices(s, action, context) {
}
case ActionType.REMOVE_CHOICE: {
action.choice.choiceEl = undefined;
if (action.choice.group) {
action.choice.group.choices = action.choice.group.choices.filter(function (obj) { return obj.id !== action.choice.id; });
}
state = state.filter(function (obj) { return obj.id !== action.choice.id; });
break;
}
Expand Down Expand Up @@ -3162,7 +3165,6 @@ var templates = {
label = escapeForTemplate(allowHTML, label);
label += " (".concat(groupName, ")");
label = { trusted: label };
div.dataset.groupId = "".concat(choice.groupId);
}
var describedBy = div;
if (choice.labelClass) {
Expand Down Expand Up @@ -3190,13 +3192,16 @@ var templates = {
if (choice.placeholder) {
addClassesToElement(div, placeholder);
}
div.setAttribute('role', choice.groupId ? 'treeitem' : 'option');
div.setAttribute('role', choice.group ? 'treeitem' : 'option');
div.dataset.choice = '';
div.dataset.id = choice.id;
div.dataset.value = rawValue;
if (selectText) {
div.dataset.selectText = selectText;
}
if (choice.group) {
div.dataset.groupId = "".concat(choice.group.id);
}
assignCustomProperties(div, choice, false);
if (choice.disabled) {
addClassesToElement(div, itemDisabled);
Expand Down Expand Up @@ -3631,12 +3636,9 @@ var Choices = /** @class */ (function () {
};
Choices.prototype.getValue = function (valueOnly) {
var _this = this;
if (valueOnly === void 0) { valueOnly = false; }
var values = this._store.items.reduce(function (selectedItems, item) {
var itemValue = valueOnly ? item.value : _this._getChoiceForOutput(item);
selectedItems.push(itemValue);
return selectedItems;
}, []);
var values = this._store.items.map(function (item) {
return (valueOnly ? item.value : _this._getChoiceForOutput(item));
});
return this._isSelectOneElement || this.config.singleModeForMultiSelect ? values[0] : values;
};
Choices.prototype.setValue = function (items) {
Expand Down Expand Up @@ -3840,17 +3842,20 @@ var Choices = /** @class */ (function () {
});
}
_this.clearStore(false);
choicesFromOptions.forEach(function (groupOrChoice) {
if ('choices' in groupOrChoice) {
return;
}
var choice = groupOrChoice;
var updateChoice = function (choice) {
if (deselectAll) {
_this._store.dispatch(removeItem$1(choice));
}
else if (existingItems[choice.value]) {
choice.selected = true;
}
};
choicesFromOptions.forEach(function (groupOrChoice) {
if ('choices' in groupOrChoice) {
groupOrChoice.choices.forEach(updateChoice);
return;
}
updateChoice(groupOrChoice);
});
/* @todo only generate add events for the added options instead of all
if (withEvents) {
Expand Down Expand Up @@ -4006,13 +4011,16 @@ var Choices = /** @class */ (function () {
}
if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) {
// If we have a placeholder choice along with groups
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false, undefined);
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.group; }), false, undefined);
}
// If we have grouped options
if (activeGroups.length && !isSearching) {
if (config.shouldSort) {
activeGroups.sort(config.sorter);
}
// render Choices without group first, regardless of sort, otherwise they won't be distinguishable
// from the last group
renderChoices(activeChoices.filter(function (choice) { return !choice.placeholder && !choice.group; }), false, undefined);
activeGroups.forEach(function (group) {
var groupChoices = renderableChoices(group.choices);
if (groupChoices.length) {
Expand Down Expand Up @@ -4153,11 +4161,8 @@ var Choices = /** @class */ (function () {
}
}
};
// eslint-disable-next-line class-methods-use-this
Choices.prototype._getChoiceForOutput = function (choice, keyCode) {
if (!choice) {
return undefined;
}
var group = choice.groupId ? this._store.getGroupById(choice.groupId) : null;
return {
id: choice.id,
highlighted: choice.highlighted,
Expand All @@ -4169,7 +4174,7 @@ var Choices = /** @class */ (function () {
label: choice.label,
placeholder: choice.placeholder,
value: choice.value,
groupValue: group && group.label ? group.label : undefined,
groupValue: choice.group ? choice.group.label : undefined,
element: choice.element,
keyCode: keyCode,
};
Expand All @@ -4188,7 +4193,7 @@ var Choices = /** @class */ (function () {
if (!items.length || !this.config.removeItems || !this.config.removeItemButton) {
return;
}
var id = element && parseDataSetId(element.parentNode);
var id = element && parseDataSetId(element.parentElement);
var itemToRemove = id && items.find(function (item) { return item.id === id; });
if (!itemToRemove) {
return;
Expand Down Expand Up @@ -4994,7 +4999,7 @@ var Choices = /** @class */ (function () {
this._lastAddedGroupId++;
group.id = this._lastAddedGroupId;
group.choices.forEach(function (item) {
item.groupId = group.id;
item.group = group;
if (group.disabled) {
item.disabled = true;
}
Expand Down
Loading

0 comments on commit 1fdcf37

Please sign in to comment.