Skip to content

Commit

Permalink
regenerate assets
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Jul 25, 2023
1 parent 561a61d commit 774eee1
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 40 deletions.
124 changes: 92 additions & 32 deletions public/assets/scripts/choices.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! choices.js v10.2.0 | © 2022 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v10.2.0 | © 2023 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
Expand Down Expand Up @@ -390,7 +390,7 @@ var Choices = /** @class */function () {
this._store.subscribe(this._render);
this._render();
this._addEventListeners();
var shouldDisable = !this.config.addItems || this.passedElement.element.hasAttribute('disabled');
var shouldDisable = this.passedElement.element.hasAttribute('disabled');
if (shouldDisable) {
this.disable();
}
Expand Down Expand Up @@ -785,8 +785,13 @@ var Choices = /** @class */function () {
Choices.prototype._renderChoices = function () {
var _this = this;
var _a = this._store,
activeItems = _a.activeItems,
disabledChoices = _a.disabledChoices,
choices = _a.choices,
activeGroups = _a.activeGroups,
activeChoices = _a.activeChoices;
var value = this.input.value;
var canAddItem = this._canAddItem(activeItems, value);
var choiceListFragment = document.createDocumentFragment();
this.choiceList.clear();
if (this.config.resetScrollPosition) {
Expand All @@ -809,22 +814,44 @@ var Choices = /** @class */function () {
}
// If we have choices to show
if (choiceListFragment.childNodes && choiceListFragment.childNodes.length > 0) {
var activeItems = this._store.activeItems;
var canAddItem = this._canAddItem(activeItems, this.input.value);
var addNotice = false;
// ...and we can select them
if (canAddItem.response) {
// ...append them and highlight the first choice
// ...append them
this.choiceList.append(choiceListFragment);
this._highlightChoice();
// ...handle case that items can be added
if (this.config.addItems && value) {
var isInChoices = (0, utils_1.existsInArray)(choices, value);
addNotice = true;
if (this._isSelectMultipleElement && (0, utils_1.existsInArray)(disabledChoices, value)) {
// adding disabled element is disabled here, so remove message
addNotice = false;
} else if (this._isSelectOneElement && isInChoices) {
// adding existing element is disabled here, so remove message
addNotice = false;
}
// ...highlight the first choice when element exists in choices
if (isInChoices) {
this._highlightChoice();
}
} else {
// ...highlight the first choice
this._highlightChoice();
}
} else {
addNotice = true;
}
if (addNotice) {
var notice = this._getTemplate('notice', canAddItem.notice);
this.choiceList.append(notice);
}
} else {
// Otherwise show a notice
var dropdownItem = void 0;
var notice = void 0;
if (this._isSearching) {
if (this.config.addItems && canAddItem.response && value) {
dropdownItem = this._getTemplate('notice', canAddItem.notice);
} else if (this._isSearching) {
notice = typeof this.config.noResultsText === 'function' ? this.config.noResultsText() : this.config.noResultsText;
dropdownItem = this._getTemplate('notice', notice, 'no-results');
} else {
Expand Down Expand Up @@ -1166,10 +1193,10 @@ var Choices = /** @class */function () {
canAddItem = false;
notice = typeof this.config.uniqueItemText === 'function' ? this.config.uniqueItemText(value) : this.config.uniqueItemText;
}
if (this._isTextElement && this.config.addItems && canAddItem && typeof this.config.addItemFilter === 'function' && !this.config.addItemFilter(value)) {
canAddItem = false;
notice = typeof this.config.customAddItemText === 'function' ? this.config.customAddItemText(value) : this.config.customAddItemText;
}
}
if (this.config.addItems && canAddItem && typeof this.config.addItemFilter === 'function' && !this.config.addItemFilter(value)) {
canAddItem = false;
notice = typeof this.config.customAddItemText === 'function' ? this.config.customAddItemText(value) : this.config.customAddItemText;
}
return {
response: canAddItem,
Expand Down Expand Up @@ -1259,7 +1286,10 @@ var Choices = /** @class */function () {
};
Choices.prototype._onKeyDown = function (event) {
var keyCode = event.keyCode;
var activeItems = this._store.activeItems;
var _a = this._store,
activeItems = _a.activeItems,
choices = _a.choices,
disabledChoices = _a.disabledChoices;
var hasFocusedInput = this.input.isFocussed;
var hasActiveDropdown = this.dropdown.isActive;
var hasItems = this.itemList.hasChildren();
Expand Down Expand Up @@ -1290,14 +1320,22 @@ var Choices = /** @class */function () {
case A_KEY:
return this._onSelectKey(event, hasItems);
case ENTER_KEY:
return this._onEnterKey(event, activeItems, hasActiveDropdown);
// existing choices are not producable
if (this._isSelectOneElement) {
return this._onEnterKey(event, activeItems, choices, hasActiveDropdown);
}
return this._onEnterKey(event, activeItems, disabledChoices, hasActiveDropdown);
case ESC_KEY:
return this._onEscapeKey(hasActiveDropdown);
case UP_KEY:
case PAGE_UP_KEY:
case DOWN_KEY:
case PAGE_DOWN_KEY:
return this._onDirectionKey(event, hasActiveDropdown);
// don't activate deselect for existing choices
if (this._isSelectOneElement) {
return this._onDirectionKey(event, activeItems, choices, hasActiveDropdown);
}
return this._onDirectionKey(event, activeItems, disabledChoices, hasActiveDropdown);
case DELETE_KEY:
case BACK_KEY:
return this._onDeleteKey(event, activeItems, hasFocusedInput);
Expand All @@ -1312,10 +1350,10 @@ var Choices = /** @class */function () {
var canAddItem = this._canAddItem(activeItems, value);
var backKey = constants_1.KEY_CODES.BACK_KEY,
deleteKey = constants_1.KEY_CODES.DELETE_KEY;
var canShowDropdownNotice = this.config.addItems && canAddItem.notice && value;
// We are typing into a text input and have a value, we want to show a dropdown
// notice. Otherwise hide the dropdown
if (this._isTextElement) {
var canShowDropdownNotice = canAddItem.notice && value;
if (canShowDropdownNotice) {
var dropdownItem = this._getTemplate('notice', canAddItem.notice);
this.dropdown.element.innerHTML = dropdownItem.outerHTML;
Expand All @@ -1331,7 +1369,7 @@ var Choices = /** @class */function () {
if (userHasRemovedValue && canReactivateChoices) {
this._isSearching = false;
this._store.dispatch((0, choices_1.activateChoices)(true));
} else if (canSearch) {
} else if (canSearch || canShowDropdownNotice) {
this._handleSearch(this.input.rawValue);
}
}
Expand All @@ -1350,28 +1388,17 @@ var Choices = /** @class */function () {
}
}
};
Choices.prototype._onEnterKey = function (event, activeItems, hasActiveDropdown) {
Choices.prototype._onEnterKey = function (event, activeItems, nonproducibleChoices, hasActiveDropdown) {
var target = event.target;
var enterKey = constants_1.KEY_CODES.ENTER_KEY;
var targetWasButton = target && target.hasAttribute('data-button');
if (this._isTextElement && target && target.value) {
var value = this.input.value;
var canAddItem = this._canAddItem(activeItems, value);
if (canAddItem.response) {
this.hideDropdown(true);
this._addItem({
value: value
});
this._triggerChange(value);
this.clearInput();
}
}
var highlightedChoice = null;
if (targetWasButton) {
this._handleButtonAction(activeItems, target);
event.preventDefault();
}
if (hasActiveDropdown) {
var highlightedChoice = this.dropdown.getChild(".".concat(this.config.classNames.highlightedState));
highlightedChoice = this.dropdown.getChild(".".concat(this.config.classNames.highlightedState));
if (highlightedChoice) {
// add enter keyCode value
if (activeItems[0]) {
Expand All @@ -1384,6 +1411,19 @@ var Choices = /** @class */function () {
} else if (this._isSelectOneElement) {
this.showDropdown();
event.preventDefault();
return;
}
if (this.config.addItems && !highlightedChoice && target && target.value) {
var value = this.input.value;
var canAddItem = this._canAddItem(activeItems, value);
if (canAddItem.response && !(0, utils_1.existsInArray)(nonproducibleChoices, value)) {
this.hideDropdown(true);
this._setChoiceOrItem({
value: value
});
this._triggerChange(value);
this.clearInput();
}
}
};
Choices.prototype._onEscapeKey = function (hasActiveDropdown) {
Expand All @@ -1392,9 +1432,10 @@ var Choices = /** @class */function () {
this.containerOuter.focus();
}
};
Choices.prototype._onDirectionKey = function (event, hasActiveDropdown) {
Choices.prototype._onDirectionKey = function (event, activeItems, nonproducibleChoices, hasActiveDropdown) {
var keyCode = event.keyCode,
metaKey = event.metaKey;
metaKey = event.metaKey,
target = event.target;
var downKey = constants_1.KEY_CODES.DOWN_KEY,
pageUpKey = constants_1.KEY_CODES.PAGE_UP_KEY,
pageDownKey = constants_1.KEY_CODES.PAGE_DOWN_KEY;
Expand Down Expand Up @@ -1427,6 +1468,13 @@ var Choices = /** @class */function () {
this.choiceList.scrollToChildElement(nextEl, directionInt);
}
this._highlightChoice(nextEl);
} else if (this.config.addItems && target && target.value) {
// can unselect all items for creating new options
var value = this.input.value;
var canAddItem = this._canAddItem(activeItems, value);
if (canAddItem.response && !(0, utils_1.existsInArray)(nonproducibleChoices, value)) {
this.unhighlightAll();
}
}
// Prevent default to maintain cursor position whilst
// traversing dropdown options
Expand Down Expand Up @@ -3759,6 +3807,18 @@ var Store = /** @class */function () {
enumerable: false,
configurable: true
});
Object.defineProperty(Store.prototype, "disabledChoices", {
/**
* Get disabled choices from store
*/
get: function () {
return this.choices.filter(function (choice) {
return choice.disabled === true;
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(Store.prototype, "selectableChoices", {
/**
* Get selectable choices from store
Expand Down
2 changes: 1 addition & 1 deletion public/assets/scripts/choices.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/scripts/choices.min.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! choices.js v10.2.0 | © 2022 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v10.2.0 | © 2023 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
4 changes: 2 additions & 2 deletions public/types/src/scripts/choices.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ declare class Choices implements Choices {
_onKeyDown(event: KeyboardEvent): void;
_onKeyUp({ target, keyCode, }: Pick<KeyboardEvent, 'target' | 'keyCode'>): void;
_onSelectKey(event: KeyboardEvent, hasItems: boolean): void;
_onEnterKey(event: KeyboardEvent, activeItems: Item[], hasActiveDropdown: boolean): void;
_onEnterKey(event: KeyboardEvent, activeItems: Item[], nonproducibleChoices: Choice[], hasActiveDropdown: boolean): void;
_onEscapeKey(hasActiveDropdown: boolean): void;
_onDirectionKey(event: KeyboardEvent, hasActiveDropdown: boolean): void;
_onDirectionKey(event: KeyboardEvent, activeItems: Item[], nonproducibleChoices: Choice[], hasActiveDropdown: boolean): void;
_onDeleteKey(event: KeyboardEvent, activeItems: Item[], hasFocusedInput: boolean): void;
_onTouchMove(): void;
_onTouchEnd(event: TouchEvent): void;
Expand Down
Loading

0 comments on commit 774eee1

Please sign in to comment.