mirror of
https://github.com/Choices-js/Choices.git
synced 2026-03-14 14:45:47 +01:00
Compile JS files
This commit is contained in:
parent
d0a7e7017c
commit
1fdcf37065
14 changed files with 197 additions and 163 deletions
|
|
@ -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('');
|
||||
|
|
@ -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();
|
||||
|
|
@ -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,
|
||||
|
|
@ -850,7 +850,7 @@
|
|||
}
|
||||
return {
|
||||
id: 0,
|
||||
groupId: 0,
|
||||
group: null,
|
||||
score: 0,
|
||||
rank: 0,
|
||||
value: option.value,
|
||||
|
|
@ -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: {
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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);
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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,
|
||||
|
|
@ -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,
|
||||
};
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
2
public/assets/scripts/choices.min.js
vendored
2
public/assets/scripts/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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('');
|
||||
|
|
@ -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();
|
||||
|
|
@ -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,
|
||||
|
|
@ -844,7 +844,7 @@ var WrappedSelect = /** @class */ (function (_super) {
|
|||
}
|
||||
return {
|
||||
id: 0,
|
||||
groupId: 0,
|
||||
group: null,
|
||||
score: 0,
|
||||
rank: 0,
|
||||
value: option.value,
|
||||
|
|
@ -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: {
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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);
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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,
|
||||
|
|
@ -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,
|
||||
};
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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('');
|
||||
|
|
@ -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();
|
||||
|
|
@ -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,
|
||||
|
|
@ -850,7 +850,7 @@
|
|||
}
|
||||
return {
|
||||
id: 0,
|
||||
groupId: 0,
|
||||
group: null,
|
||||
score: 0,
|
||||
rank: 0,
|
||||
value: option.value,
|
||||
|
|
@ -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: {
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -2686,7 +2689,6 @@
|
|||
label = escapeForTemplate(allowHTML, label);
|
||||
label += " (".concat(groupName, ")");
|
||||
label = { trusted: label };
|
||||
div.dataset.groupId = "".concat(choice.groupId);
|
||||
}
|
||||
var describedBy = div;
|
||||
if (choice.labelClass) {
|
||||
|
|
@ -2714,13 +2716,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);
|
||||
|
|
@ -3155,12 +3160,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) {
|
||||
|
|
@ -3364,17 +3366,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) {
|
||||
|
|
@ -3530,13 +3535,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) {
|
||||
|
|
@ -3677,11 +3685,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,
|
||||
|
|
@ -3693,7 +3698,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,
|
||||
};
|
||||
|
|
@ -3712,7 +3717,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;
|
||||
|
|
@ -4518,7 +4523,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;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -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('');
|
||||
|
|
@ -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();
|
||||
|
|
@ -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,
|
||||
|
|
@ -844,7 +844,7 @@ var WrappedSelect = /** @class */ (function (_super) {
|
|||
}
|
||||
return {
|
||||
id: 0,
|
||||
groupId: 0,
|
||||
group: null,
|
||||
score: 0,
|
||||
rank: 0,
|
||||
value: option.value,
|
||||
|
|
@ -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: {
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -2680,7 +2683,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) {
|
||||
|
|
@ -2708,13 +2710,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);
|
||||
|
|
@ -3149,12 +3154,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) {
|
||||
|
|
@ -3358,17 +3360,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) {
|
||||
|
|
@ -3524,13 +3529,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) {
|
||||
|
|
@ -3671,11 +3679,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,
|
||||
|
|
@ -3687,7 +3692,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,
|
||||
};
|
||||
|
|
@ -3706,7 +3711,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;
|
||||
|
|
@ -4512,7 +4517,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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,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('');
|
||||
|
|
@ -259,6 +258,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();
|
||||
|
|
@ -764,7 +764,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,
|
||||
|
|
@ -841,7 +841,7 @@
|
|||
}
|
||||
return {
|
||||
id: 0,
|
||||
groupId: 0,
|
||||
group: null,
|
||||
score: 0,
|
||||
rank: 0,
|
||||
value: option.value,
|
||||
|
|
@ -1002,8 +1002,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: {
|
||||
|
|
@ -1056,6 +1056,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;
|
||||
}
|
||||
|
|
@ -1528,7 +1531,6 @@
|
|||
label = escapeForTemplate(allowHTML, label);
|
||||
label += " (".concat(groupName, ")");
|
||||
label = { trusted: label };
|
||||
div.dataset.groupId = "".concat(choice.groupId);
|
||||
}
|
||||
var describedBy = div;
|
||||
if (choice.labelClass) {
|
||||
|
|
@ -1556,13 +1558,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);
|
||||
|
|
@ -1997,12 +2002,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) {
|
||||
|
|
@ -2206,17 +2208,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) {
|
||||
|
|
@ -2372,13 +2377,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) {
|
||||
|
|
@ -2519,11 +2527,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,
|
||||
|
|
@ -2535,7 +2540,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,
|
||||
};
|
||||
|
|
@ -2554,7 +2559,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;
|
||||
|
|
@ -3360,7 +3365,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;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -120,7 +120,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('');
|
||||
|
|
@ -253,6 +252,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();
|
||||
|
|
@ -758,7 +758,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,
|
||||
|
|
@ -835,7 +835,7 @@ var WrappedSelect = /** @class */ (function (_super) {
|
|||
}
|
||||
return {
|
||||
id: 0,
|
||||
groupId: 0,
|
||||
group: null,
|
||||
score: 0,
|
||||
rank: 0,
|
||||
value: option.value,
|
||||
|
|
@ -996,8 +996,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: {
|
||||
|
|
@ -1050,6 +1050,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;
|
||||
}
|
||||
|
|
@ -1522,7 +1525,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) {
|
||||
|
|
@ -1550,13 +1552,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);
|
||||
|
|
@ -1991,12 +1996,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) {
|
||||
|
|
@ -2200,17 +2202,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) {
|
||||
|
|
@ -2366,13 +2371,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) {
|
||||
|
|
@ -2513,11 +2521,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,
|
||||
|
|
@ -2529,7 +2534,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,
|
||||
};
|
||||
|
|
@ -2548,7 +2553,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;
|
||||
|
|
@ -3354,7 +3359,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;
|
||||
}
|
||||
|
|
|
|||
12
public/types/src/scripts/choices.d.ts
vendored
12
public/types/src/scripts/choices.d.ts
vendored
|
|
@ -6,7 +6,7 @@ import { StateChangeSet } from './interfaces/state';
|
|||
import Store from './store/store';
|
||||
import { ChoiceFull } from './interfaces/choice-full';
|
||||
import { GroupFull } from './interfaces/group-full';
|
||||
import { PassedElementType } from './interfaces';
|
||||
import { EventChoiceValueType, PassedElementType } from './interfaces';
|
||||
import { EventChoice } from './interfaces/event-choice';
|
||||
import { NoticeType, Templates } from './interfaces/templates';
|
||||
import { Searcher } from './interfaces/search';
|
||||
|
|
@ -76,7 +76,7 @@ declare class Choices {
|
|||
removeHighlightedItems(runEvent?: boolean): this;
|
||||
showDropdown(preventInputFocus?: boolean): this;
|
||||
hideDropdown(preventInputBlur?: boolean): this;
|
||||
getValue(valueOnly?: boolean): string[] | EventChoice[] | EventChoice | string;
|
||||
getValue<B extends boolean = false>(valueOnly?: B): EventChoiceValueType<B> | EventChoiceValueType<B>[];
|
||||
setValue(items: string[] | InputChoice[]): this;
|
||||
setChoiceByValue(value: string | string[]): this;
|
||||
/**
|
||||
|
|
@ -155,11 +155,11 @@ declare class Choices {
|
|||
_displayNotice(text: string, type: NoticeType, openDropdown?: boolean): void;
|
||||
_clearNotice(): void;
|
||||
_renderNotice(fragment?: DocumentFragment): void;
|
||||
_getChoiceForOutput(choice?: ChoiceFull, keyCode?: number): EventChoice | undefined;
|
||||
_getChoiceForOutput(choice: ChoiceFull, keyCode?: number): EventChoice;
|
||||
_triggerChange(value: any): void;
|
||||
_handleButtonAction(element?: HTMLElement): void;
|
||||
_handleItemAction(element?: HTMLElement, hasShiftKey?: boolean): void;
|
||||
_handleChoiceAction(element?: HTMLElement): boolean;
|
||||
_handleButtonAction(element: HTMLElement): void;
|
||||
_handleItemAction(element: HTMLElement, hasShiftKey?: boolean): void;
|
||||
_handleChoiceAction(element: HTMLElement): boolean;
|
||||
_handleBackspace(items: ChoiceFull[]): void;
|
||||
_loadChoices(): void;
|
||||
_handleLoadingState(setLoading?: boolean): void;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { StringUntrusted } from './string-untrusted';
|
||||
export type CustomProperties = Record<string, any> | string;
|
||||
import { Types } from './types';
|
||||
import { GroupFull } from './group-full';
|
||||
export interface ChoiceFull {
|
||||
id: number;
|
||||
highlighted: boolean;
|
||||
|
|
@ -8,11 +9,11 @@ export interface ChoiceFull {
|
|||
choiceEl?: HTMLElement;
|
||||
labelClass?: Array<string>;
|
||||
labelDescription?: string;
|
||||
customProperties?: CustomProperties;
|
||||
customProperties?: Types.CustomProperties;
|
||||
disabled: boolean;
|
||||
active: boolean;
|
||||
elementId?: string;
|
||||
groupId: number;
|
||||
group: GroupFull | null;
|
||||
label: StringUntrusted | string;
|
||||
placeholder: boolean;
|
||||
selected: boolean;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { InputChoice } from './input-choice';
|
||||
export type EventChoiceValueType<B extends boolean> = B extends true ? string : EventChoice;
|
||||
export interface EventChoice extends InputChoice {
|
||||
element?: HTMLOptionElement | HTMLOptGroupElement;
|
||||
groupValue?: string;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { StringUntrusted } from './string-untrusted';
|
||||
import { Types } from './types';
|
||||
export interface InputChoice {
|
||||
id?: number;
|
||||
highlighted?: boolean;
|
||||
labelClass?: string | Array<string>;
|
||||
labelDescription?: string;
|
||||
customProperties?: Record<string, any> | string;
|
||||
customProperties?: Types.CustomProperties;
|
||||
disabled?: boolean;
|
||||
active?: boolean;
|
||||
label: StringUntrusted | string;
|
||||
|
|
|
|||
|
|
@ -14,4 +14,5 @@ export declare namespace Types {
|
|||
label?: StringUntrusted | string;
|
||||
}
|
||||
type ValueOf<T extends object> = T[keyof T];
|
||||
type CustomProperties = Record<string, any> | string;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue