[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 /*! choices.js v9.1.0 | © 2021 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ 2 (function webpackUniversalModuleDefinition(root, factory) { 3 if(typeof exports === 'object' && typeof module === 'object') 4 module.exports = factory(); 5 else if(typeof define === 'function' && define.amd) 6 define([], factory); 7 else if(typeof exports === 'object') 8 exports["Choices"] = factory(); 9 else 10 root["Choices"] = factory(); 11 })(window, function() { 12 return /******/ (function() { // webpackBootstrap 13 /******/ var __webpack_modules__ = ({ 14 15 /***/ 282: 16 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 17 18 "use strict"; 19 20 21 Object.defineProperty(exports, "__esModule", ({ 22 value: true 23 })); 24 exports.clearChoices = exports.activateChoices = exports.filterChoices = exports.addChoice = void 0; 25 26 var constants_1 = __webpack_require__(883); 27 28 var addChoice = function (_a) { 29 var value = _a.value, 30 label = _a.label, 31 id = _a.id, 32 groupId = _a.groupId, 33 disabled = _a.disabled, 34 elementId = _a.elementId, 35 customProperties = _a.customProperties, 36 placeholder = _a.placeholder, 37 keyCode = _a.keyCode; 38 return { 39 type: constants_1.ACTION_TYPES.ADD_CHOICE, 40 value: value, 41 label: label, 42 id: id, 43 groupId: groupId, 44 disabled: disabled, 45 elementId: elementId, 46 customProperties: customProperties, 47 placeholder: placeholder, 48 keyCode: keyCode 49 }; 50 }; 51 52 exports.addChoice = addChoice; 53 54 var filterChoices = function (results) { 55 return { 56 type: constants_1.ACTION_TYPES.FILTER_CHOICES, 57 results: results 58 }; 59 }; 60 61 exports.filterChoices = filterChoices; 62 63 var activateChoices = function (active) { 64 if (active === void 0) { 65 active = true; 66 } 67 68 return { 69 type: constants_1.ACTION_TYPES.ACTIVATE_CHOICES, 70 active: active 71 }; 72 }; 73 74 exports.activateChoices = activateChoices; 75 76 var clearChoices = function () { 77 return { 78 type: constants_1.ACTION_TYPES.CLEAR_CHOICES 79 }; 80 }; 81 82 exports.clearChoices = clearChoices; 83 84 /***/ }), 85 86 /***/ 783: 87 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 88 89 "use strict"; 90 91 92 Object.defineProperty(exports, "__esModule", ({ 93 value: true 94 })); 95 exports.addGroup = void 0; 96 97 var constants_1 = __webpack_require__(883); 98 99 var addGroup = function (_a) { 100 var value = _a.value, 101 id = _a.id, 102 active = _a.active, 103 disabled = _a.disabled; 104 return { 105 type: constants_1.ACTION_TYPES.ADD_GROUP, 106 value: value, 107 id: id, 108 active: active, 109 disabled: disabled 110 }; 111 }; 112 113 exports.addGroup = addGroup; 114 115 /***/ }), 116 117 /***/ 464: 118 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 119 120 "use strict"; 121 122 123 Object.defineProperty(exports, "__esModule", ({ 124 value: true 125 })); 126 exports.highlightItem = exports.removeItem = exports.addItem = void 0; 127 128 var constants_1 = __webpack_require__(883); 129 130 var addItem = function (_a) { 131 var value = _a.value, 132 label = _a.label, 133 id = _a.id, 134 choiceId = _a.choiceId, 135 groupId = _a.groupId, 136 customProperties = _a.customProperties, 137 placeholder = _a.placeholder, 138 keyCode = _a.keyCode; 139 return { 140 type: constants_1.ACTION_TYPES.ADD_ITEM, 141 value: value, 142 label: label, 143 id: id, 144 choiceId: choiceId, 145 groupId: groupId, 146 customProperties: customProperties, 147 placeholder: placeholder, 148 keyCode: keyCode 149 }; 150 }; 151 152 exports.addItem = addItem; 153 154 var removeItem = function (id, choiceId) { 155 return { 156 type: constants_1.ACTION_TYPES.REMOVE_ITEM, 157 id: id, 158 choiceId: choiceId 159 }; 160 }; 161 162 exports.removeItem = removeItem; 163 164 var highlightItem = function (id, highlighted) { 165 return { 166 type: constants_1.ACTION_TYPES.HIGHLIGHT_ITEM, 167 id: id, 168 highlighted: highlighted 169 }; 170 }; 171 172 exports.highlightItem = highlightItem; 173 174 /***/ }), 175 176 /***/ 137: 177 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 178 179 "use strict"; 180 181 182 Object.defineProperty(exports, "__esModule", ({ 183 value: true 184 })); 185 exports.setIsLoading = exports.resetTo = exports.clearAll = void 0; 186 187 var constants_1 = __webpack_require__(883); 188 189 var clearAll = function () { 190 return { 191 type: constants_1.ACTION_TYPES.CLEAR_ALL 192 }; 193 }; 194 195 exports.clearAll = clearAll; 196 197 var resetTo = function (state) { 198 return { 199 type: constants_1.ACTION_TYPES.RESET_TO, 200 state: state 201 }; 202 }; 203 204 exports.resetTo = resetTo; 205 206 var setIsLoading = function (isLoading) { 207 return { 208 type: constants_1.ACTION_TYPES.SET_IS_LOADING, 209 isLoading: isLoading 210 }; 211 }; 212 213 exports.setIsLoading = setIsLoading; 214 215 /***/ }), 216 217 /***/ 373: 218 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 219 220 "use strict"; 221 222 223 var __spreadArray = this && this.__spreadArray || function (to, from, pack) { 224 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { 225 if (ar || !(i in from)) { 226 if (!ar) ar = Array.prototype.slice.call(from, 0, i); 227 ar[i] = from[i]; 228 } 229 } 230 return to.concat(ar || Array.prototype.slice.call(from)); 231 }; 232 233 var __importDefault = this && this.__importDefault || function (mod) { 234 return mod && mod.__esModule ? mod : { 235 "default": mod 236 }; 237 }; 238 239 Object.defineProperty(exports, "__esModule", ({ 240 value: true 241 })); 242 243 var deepmerge_1 = __importDefault(__webpack_require__(996)); 244 /* eslint-disable @typescript-eslint/no-explicit-any */ 245 246 247 var fuse_js_1 = __importDefault(__webpack_require__(70)); 248 249 var choices_1 = __webpack_require__(282); 250 251 var groups_1 = __webpack_require__(783); 252 253 var items_1 = __webpack_require__(464); 254 255 var misc_1 = __webpack_require__(137); 256 257 var components_1 = __webpack_require__(520); 258 259 var constants_1 = __webpack_require__(883); 260 261 var defaults_1 = __webpack_require__(789); 262 263 var utils_1 = __webpack_require__(799); 264 265 var reducers_1 = __webpack_require__(655); 266 267 var store_1 = __importDefault(__webpack_require__(744)); 268 269 var templates_1 = __importDefault(__webpack_require__(686)); 270 /** @see {@link http://browserhacks.com/#hack-acea075d0ac6954f275a70023906050c} */ 271 272 273 var IS_IE11 = '-ms-scroll-limit' in document.documentElement.style && '-ms-ime-align' in document.documentElement.style; 274 var USER_DEFAULTS = {}; 275 /** 276 * Choices 277 * @author Josh Johnson<[email protected]> 278 */ 279 280 var Choices = 281 /** @class */ 282 function () { 283 function Choices(element, userConfig) { 284 var _this = this; 285 286 if (element === void 0) { 287 element = '[data-choice]'; 288 } 289 290 if (userConfig === void 0) { 291 userConfig = {}; 292 } 293 294 this.config = deepmerge_1.default.all([defaults_1.DEFAULT_CONFIG, Choices.defaults.options, userConfig], // When merging array configs, replace with a copy of the userConfig array, 295 // instead of concatenating with the default array 296 { 297 arrayMerge: function (_, sourceArray) { 298 return __spreadArray([], sourceArray, true); 299 } 300 }); 301 var invalidConfigOptions = (0, utils_1.diff)(this.config, defaults_1.DEFAULT_CONFIG); 302 303 if (invalidConfigOptions.length) { 304 console.warn('Unknown config option(s) passed', invalidConfigOptions.join(', ')); 305 } 306 307 var passedElement = typeof element === 'string' ? document.querySelector(element) : element; 308 309 if (!(passedElement instanceof HTMLInputElement || passedElement instanceof HTMLSelectElement)) { 310 throw TypeError('Expected one of the following types text|select-one|select-multiple'); 311 } 312 313 this._isTextElement = passedElement.type === constants_1.TEXT_TYPE; 314 this._isSelectOneElement = passedElement.type === constants_1.SELECT_ONE_TYPE; 315 this._isSelectMultipleElement = passedElement.type === constants_1.SELECT_MULTIPLE_TYPE; 316 this._isSelectElement = this._isSelectOneElement || this._isSelectMultipleElement; 317 this.config.searchEnabled = this._isSelectMultipleElement || this.config.searchEnabled; 318 319 if (!['auto', 'always'].includes("".concat(this.config.renderSelectedChoices))) { 320 this.config.renderSelectedChoices = 'auto'; 321 } 322 323 if (userConfig.addItemFilter && typeof userConfig.addItemFilter !== 'function') { 324 var re = userConfig.addItemFilter instanceof RegExp ? userConfig.addItemFilter : new RegExp(userConfig.addItemFilter); 325 this.config.addItemFilter = re.test.bind(re); 326 } 327 328 if (this._isTextElement) { 329 this.passedElement = new components_1.WrappedInput({ 330 element: passedElement, 331 classNames: this.config.classNames, 332 delimiter: this.config.delimiter 333 }); 334 } else { 335 this.passedElement = new components_1.WrappedSelect({ 336 element: passedElement, 337 classNames: this.config.classNames, 338 template: function (data) { 339 return _this._templates.option(data); 340 } 341 }); 342 } 343 344 this.initialised = false; 345 this._store = new store_1.default(); 346 this._initialState = reducers_1.defaultState; 347 this._currentState = reducers_1.defaultState; 348 this._prevState = reducers_1.defaultState; 349 this._currentValue = ''; 350 this._canSearch = !!this.config.searchEnabled; 351 this._isScrollingOnIe = false; 352 this._highlightPosition = 0; 353 this._wasTap = true; 354 this._placeholderValue = this._generatePlaceholderValue(); 355 this._baseId = (0, utils_1.generateId)(this.passedElement.element, 'choices-'); 356 /** 357 * setting direction in cases where it's explicitly set on passedElement 358 * or when calculated direction is different from the document 359 */ 360 361 this._direction = this.passedElement.dir; 362 363 if (!this._direction) { 364 var elementDirection = window.getComputedStyle(this.passedElement.element).direction; 365 var documentDirection = window.getComputedStyle(document.documentElement).direction; 366 367 if (elementDirection !== documentDirection) { 368 this._direction = elementDirection; 369 } 370 } 371 372 this._idNames = { 373 itemChoice: 'item-choice' 374 }; 375 376 if (this._isSelectElement) { 377 // Assign preset groups from passed element 378 this._presetGroups = this.passedElement.optionGroups; // Assign preset options from passed element 379 380 this._presetOptions = this.passedElement.options; 381 } // Assign preset choices from passed object 382 383 384 this._presetChoices = this.config.choices; // Assign preset items from passed object first 385 386 this._presetItems = this.config.items; // Add any values passed from attribute 387 388 if (this.passedElement.value && this._isTextElement) { 389 var splitValues = this.passedElement.value.split(this.config.delimiter); 390 this._presetItems = this._presetItems.concat(splitValues); 391 } // Create array of choices from option elements 392 393 394 if (this.passedElement.options) { 395 this.passedElement.options.forEach(function (option) { 396 _this._presetChoices.push({ 397 value: option.value, 398 label: option.innerHTML, 399 selected: !!option.selected, 400 disabled: option.disabled || option.parentNode.disabled, 401 placeholder: option.value === '' || option.hasAttribute('placeholder'), 402 customProperties: option.dataset['custom-properties'] 403 }); 404 }); 405 } 406 407 this._render = this._render.bind(this); 408 this._onFocus = this._onFocus.bind(this); 409 this._onBlur = this._onBlur.bind(this); 410 this._onKeyUp = this._onKeyUp.bind(this); 411 this._onKeyDown = this._onKeyDown.bind(this); 412 this._onClick = this._onClick.bind(this); 413 this._onTouchMove = this._onTouchMove.bind(this); 414 this._onTouchEnd = this._onTouchEnd.bind(this); 415 this._onMouseDown = this._onMouseDown.bind(this); 416 this._onMouseOver = this._onMouseOver.bind(this); 417 this._onFormReset = this._onFormReset.bind(this); 418 this._onSelectKey = this._onSelectKey.bind(this); 419 this._onEnterKey = this._onEnterKey.bind(this); 420 this._onEscapeKey = this._onEscapeKey.bind(this); 421 this._onDirectionKey = this._onDirectionKey.bind(this); 422 this._onDeleteKey = this._onDeleteKey.bind(this); // If element has already been initialised with Choices, fail silently 423 424 if (this.passedElement.isActive) { 425 if (!this.config.silent) { 426 console.warn('Trying to initialise Choices on element already initialised', { 427 element: element 428 }); 429 } 430 431 this.initialised = true; 432 return; 433 } // Let's go 434 435 436 this.init(); 437 } 438 439 Object.defineProperty(Choices, "defaults", { 440 get: function () { 441 return Object.preventExtensions({ 442 get options() { 443 return USER_DEFAULTS; 444 }, 445 446 get templates() { 447 return templates_1.default; 448 } 449 450 }); 451 }, 452 enumerable: false, 453 configurable: true 454 }); 455 456 Choices.prototype.init = function () { 457 if (this.initialised) { 458 return; 459 } 460 461 this._createTemplates(); 462 463 this._createElements(); 464 465 this._createStructure(); 466 467 this._store.subscribe(this._render); 468 469 this._render(); 470 471 this._addEventListeners(); 472 473 var shouldDisable = !this.config.addItems || this.passedElement.element.hasAttribute('disabled'); 474 475 if (shouldDisable) { 476 this.disable(); 477 } 478 479 this.initialised = true; 480 var callbackOnInit = this.config.callbackOnInit; // Run callback if it is a function 481 482 if (callbackOnInit && typeof callbackOnInit === 'function') { 483 callbackOnInit.call(this); 484 } 485 }; 486 487 Choices.prototype.destroy = function () { 488 if (!this.initialised) { 489 return; 490 } 491 492 this._removeEventListeners(); 493 494 this.passedElement.reveal(); 495 this.containerOuter.unwrap(this.passedElement.element); 496 this.clearStore(); 497 498 if (this._isSelectElement) { 499 this.passedElement.options = this._presetOptions; 500 } 501 502 this._templates = templates_1.default; 503 this.initialised = false; 504 }; 505 506 Choices.prototype.enable = function () { 507 if (this.passedElement.isDisabled) { 508 this.passedElement.enable(); 509 } 510 511 if (this.containerOuter.isDisabled) { 512 this._addEventListeners(); 513 514 this.input.enable(); 515 this.containerOuter.enable(); 516 } 517 518 return this; 519 }; 520 521 Choices.prototype.disable = function () { 522 if (!this.passedElement.isDisabled) { 523 this.passedElement.disable(); 524 } 525 526 if (!this.containerOuter.isDisabled) { 527 this._removeEventListeners(); 528 529 this.input.disable(); 530 this.containerOuter.disable(); 531 } 532 533 return this; 534 }; 535 536 Choices.prototype.highlightItem = function (item, runEvent) { 537 if (runEvent === void 0) { 538 runEvent = true; 539 } 540 541 if (!item || !item.id) { 542 return this; 543 } 544 545 var id = item.id, 546 _a = item.groupId, 547 groupId = _a === void 0 ? -1 : _a, 548 _b = item.value, 549 value = _b === void 0 ? '' : _b, 550 _c = item.label, 551 label = _c === void 0 ? '' : _c; 552 var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; 553 554 this._store.dispatch((0, items_1.highlightItem)(id, true)); 555 556 if (runEvent) { 557 this.passedElement.triggerEvent(constants_1.EVENTS.highlightItem, { 558 id: id, 559 value: value, 560 label: label, 561 groupValue: group && group.value ? group.value : null 562 }); 563 } 564 565 return this; 566 }; 567 568 Choices.prototype.unhighlightItem = function (item) { 569 if (!item || !item.id) { 570 return this; 571 } 572 573 var id = item.id, 574 _a = item.groupId, 575 groupId = _a === void 0 ? -1 : _a, 576 _b = item.value, 577 value = _b === void 0 ? '' : _b, 578 _c = item.label, 579 label = _c === void 0 ? '' : _c; 580 var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; 581 582 this._store.dispatch((0, items_1.highlightItem)(id, false)); 583 584 this.passedElement.triggerEvent(constants_1.EVENTS.highlightItem, { 585 id: id, 586 value: value, 587 label: label, 588 groupValue: group && group.value ? group.value : null 589 }); 590 return this; 591 }; 592 593 Choices.prototype.highlightAll = function () { 594 var _this = this; 595 596 this._store.items.forEach(function (item) { 597 return _this.highlightItem(item); 598 }); 599 600 return this; 601 }; 602 603 Choices.prototype.unhighlightAll = function () { 604 var _this = this; 605 606 this._store.items.forEach(function (item) { 607 return _this.unhighlightItem(item); 608 }); 609 610 return this; 611 }; 612 613 Choices.prototype.removeActiveItemsByValue = function (value) { 614 var _this = this; 615 616 this._store.activeItems.filter(function (item) { 617 return item.value === value; 618 }).forEach(function (item) { 619 return _this._removeItem(item); 620 }); 621 622 return this; 623 }; 624 625 Choices.prototype.removeActiveItems = function (excludedId) { 626 var _this = this; 627 628 this._store.activeItems.filter(function (_a) { 629 var id = _a.id; 630 return id !== excludedId; 631 }).forEach(function (item) { 632 return _this._removeItem(item); 633 }); 634 635 return this; 636 }; 637 638 Choices.prototype.removeHighlightedItems = function (runEvent) { 639 var _this = this; 640 641 if (runEvent === void 0) { 642 runEvent = false; 643 } 644 645 this._store.highlightedActiveItems.forEach(function (item) { 646 _this._removeItem(item); // If this action was performed by the user 647 // trigger the event 648 649 650 if (runEvent) { 651 _this._triggerChange(item.value); 652 } 653 }); 654 655 return this; 656 }; 657 658 Choices.prototype.showDropdown = function (preventInputFocus) { 659 var _this = this; 660 661 if (this.dropdown.isActive) { 662 return this; 663 } 664 665 requestAnimationFrame(function () { 666 _this.dropdown.show(); 667 668 _this.containerOuter.open(_this.dropdown.distanceFromTopWindow); 669 670 if (!preventInputFocus && _this._canSearch) { 671 _this.input.focus(); 672 } 673 674 _this.passedElement.triggerEvent(constants_1.EVENTS.showDropdown, {}); 675 }); 676 return this; 677 }; 678 679 Choices.prototype.hideDropdown = function (preventInputBlur) { 680 var _this = this; 681 682 if (!this.dropdown.isActive) { 683 return this; 684 } 685 686 requestAnimationFrame(function () { 687 _this.dropdown.hide(); 688 689 _this.containerOuter.close(); 690 691 if (!preventInputBlur && _this._canSearch) { 692 _this.input.removeActiveDescendant(); 693 694 _this.input.blur(); 695 } 696 697 _this.passedElement.triggerEvent(constants_1.EVENTS.hideDropdown, {}); 698 }); 699 return this; 700 }; 701 702 Choices.prototype.getValue = function (valueOnly) { 703 if (valueOnly === void 0) { 704 valueOnly = false; 705 } 706 707 var values = this._store.activeItems.reduce(function (selectedItems, item) { 708 var itemValue = valueOnly ? item.value : item; 709 selectedItems.push(itemValue); 710 return selectedItems; 711 }, []); 712 713 return this._isSelectOneElement ? values[0] : values; 714 }; 715 716 Choices.prototype.setValue = function (items) { 717 var _this = this; 718 719 if (!this.initialised) { 720 return this; 721 } 722 723 items.forEach(function (value) { 724 return _this._setChoiceOrItem(value); 725 }); 726 return this; 727 }; 728 729 Choices.prototype.setChoiceByValue = function (value) { 730 var _this = this; 731 732 if (!this.initialised || this._isTextElement) { 733 return this; 734 } // If only one value has been passed, convert to array 735 736 737 var choiceValue = Array.isArray(value) ? value : [value]; // Loop through each value and 738 739 choiceValue.forEach(function (val) { 740 return _this._findAndSelectChoiceByValue(val); 741 }); 742 return this; 743 }; 744 /** 745 * Set choices of select input via an array of objects (or function that returns array of object or promise of it), 746 * a value field name and a label field name. 747 * This behaves the same as passing items via the choices option but can be called after initialising Choices. 748 * This can also be used to add groups of choices (see example 2); Optionally pass a true `replaceChoices` value to remove any existing choices. 749 * Optionally pass a `customProperties` object to add additional data to your choices (useful when searching/filtering etc). 750 * 751 * **Input types affected:** select-one, select-multiple 752 * 753 * @example 754 * ```js 755 * const example = new Choices(element); 756 * 757 * example.setChoices([ 758 * {value: 'One', label: 'Label One', disabled: true}, 759 * {value: 'Two', label: 'Label Two', selected: true}, 760 * {value: 'Three', label: 'Label Three'}, 761 * ], 'value', 'label', false); 762 * ``` 763 * 764 * @example 765 * ```js 766 * const example = new Choices(element); 767 * 768 * example.setChoices(async () => { 769 * try { 770 * const items = await fetch('/items'); 771 * return items.json() 772 * } catch(err) { 773 * console.error(err) 774 * } 775 * }); 776 * ``` 777 * 778 * @example 779 * ```js 780 * const example = new Choices(element); 781 * 782 * example.setChoices([{ 783 * label: 'Group one', 784 * id: 1, 785 * disabled: false, 786 * choices: [ 787 * {value: 'Child One', label: 'Child One', selected: true}, 788 * {value: 'Child Two', label: 'Child Two', disabled: true}, 789 * {value: 'Child Three', label: 'Child Three'}, 790 * ] 791 * }, 792 * { 793 * label: 'Group two', 794 * id: 2, 795 * disabled: false, 796 * choices: [ 797 * {value: 'Child Four', label: 'Child Four', disabled: true}, 798 * {value: 'Child Five', label: 'Child Five'}, 799 * {value: 'Child Six', label: 'Child Six', customProperties: { 800 * description: 'Custom description about child six', 801 * random: 'Another random custom property' 802 * }}, 803 * ] 804 * }], 'value', 'label', false); 805 * ``` 806 */ 807 808 809 Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices) { 810 var _this = this; 811 812 if (choicesArrayOrFetcher === void 0) { 813 choicesArrayOrFetcher = []; 814 } 815 816 if (value === void 0) { 817 value = 'value'; 818 } 819 820 if (label === void 0) { 821 label = 'label'; 822 } 823 824 if (replaceChoices === void 0) { 825 replaceChoices = false; 826 } 827 828 if (!this.initialised) { 829 throw new ReferenceError("setChoices was called on a non-initialized instance of Choices"); 830 } 831 832 if (!this._isSelectElement) { 833 throw new TypeError("setChoices can't be used with INPUT based Choices"); 834 } 835 836 if (typeof value !== 'string' || !value) { 837 throw new TypeError("value parameter must be a name of 'value' field in passed objects"); 838 } // Clear choices if needed 839 840 841 if (replaceChoices) { 842 this.clearChoices(); 843 } 844 845 if (typeof choicesArrayOrFetcher === 'function') { 846 // it's a choices fetcher function 847 var fetcher_1 = choicesArrayOrFetcher(this); 848 849 if (typeof Promise === 'function' && fetcher_1 instanceof Promise) { 850 // that's a promise 851 // eslint-disable-next-line no-promise-executor-return 852 return new Promise(function (resolve) { 853 return requestAnimationFrame(resolve); 854 }).then(function () { 855 return _this._handleLoadingState(true); 856 }).then(function () { 857 return fetcher_1; 858 }).then(function (data) { 859 return _this.setChoices(data, value, label, replaceChoices); 860 }).catch(function (err) { 861 if (!_this.config.silent) { 862 console.error(err); 863 } 864 }).then(function () { 865 return _this._handleLoadingState(false); 866 }).then(function () { 867 return _this; 868 }); 869 } // function returned something else than promise, let's check if it's an array of choices 870 871 872 if (!Array.isArray(fetcher_1)) { 873 throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof fetcher_1)); 874 } // recursion with results, it's sync and choices were cleared already 875 876 877 return this.setChoices(fetcher_1, value, label, false); 878 } 879 880 if (!Array.isArray(choicesArrayOrFetcher)) { 881 throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices"); 882 } 883 884 this.containerOuter.removeLoadingState(); 885 886 this._startLoading(); 887 888 choicesArrayOrFetcher.forEach(function (groupOrChoice) { 889 if (groupOrChoice.choices) { 890 _this._addGroup({ 891 id: groupOrChoice.id ? parseInt("".concat(groupOrChoice.id), 10) : null, 892 group: groupOrChoice, 893 valueKey: value, 894 labelKey: label 895 }); 896 } else { 897 var choice = groupOrChoice; 898 899 _this._addChoice({ 900 value: choice[value], 901 label: choice[label], 902 isSelected: !!choice.selected, 903 isDisabled: !!choice.disabled, 904 placeholder: !!choice.placeholder, 905 customProperties: choice.customProperties 906 }); 907 } 908 }); 909 910 this._stopLoading(); 911 912 return this; 913 }; 914 915 Choices.prototype.clearChoices = function () { 916 this._store.dispatch((0, choices_1.clearChoices)()); 917 918 return this; 919 }; 920 921 Choices.prototype.clearStore = function () { 922 this._store.dispatch((0, misc_1.clearAll)()); 923 924 return this; 925 }; 926 927 Choices.prototype.clearInput = function () { 928 var shouldSetInputWidth = !this._isSelectOneElement; 929 this.input.clear(shouldSetInputWidth); 930 931 if (!this._isTextElement && this._canSearch) { 932 this._isSearching = false; 933 934 this._store.dispatch((0, choices_1.activateChoices)(true)); 935 } 936 937 return this; 938 }; 939 940 Choices.prototype._render = function () { 941 if (this._store.isLoading()) { 942 return; 943 } 944 945 this._currentState = this._store.state; 946 var stateChanged = this._currentState.choices !== this._prevState.choices || this._currentState.groups !== this._prevState.groups || this._currentState.items !== this._prevState.items; 947 var shouldRenderChoices = this._isSelectElement; 948 var shouldRenderItems = this._currentState.items !== this._prevState.items; 949 950 if (!stateChanged) { 951 return; 952 } 953 954 if (shouldRenderChoices) { 955 this._renderChoices(); 956 } 957 958 if (shouldRenderItems) { 959 this._renderItems(); 960 } 961 962 this._prevState = this._currentState; 963 }; 964 965 Choices.prototype._renderChoices = function () { 966 var _this = this; 967 968 var _a = this._store, 969 activeGroups = _a.activeGroups, 970 activeChoices = _a.activeChoices; 971 var choiceListFragment = document.createDocumentFragment(); 972 this.choiceList.clear(); 973 974 if (this.config.resetScrollPosition) { 975 requestAnimationFrame(function () { 976 return _this.choiceList.scrollToTop(); 977 }); 978 } // If we have grouped options 979 980 981 if (activeGroups.length >= 1 && !this._isSearching) { 982 // If we have a placeholder choice along with groups 983 var activePlaceholders = activeChoices.filter(function (activeChoice) { 984 return activeChoice.placeholder === true && activeChoice.groupId === -1; 985 }); 986 987 if (activePlaceholders.length >= 1) { 988 choiceListFragment = this._createChoicesFragment(activePlaceholders, choiceListFragment); 989 } 990 991 choiceListFragment = this._createGroupsFragment(activeGroups, activeChoices, choiceListFragment); 992 } else if (activeChoices.length >= 1) { 993 choiceListFragment = this._createChoicesFragment(activeChoices, choiceListFragment); 994 } // If we have choices to show 995 996 997 if (choiceListFragment.childNodes && choiceListFragment.childNodes.length > 0) { 998 var activeItems = this._store.activeItems; 999 1000 var canAddItem = this._canAddItem(activeItems, this.input.value); // ...and we can select them 1001 1002 1003 if (canAddItem.response) { 1004 // ...append them and highlight the first choice 1005 this.choiceList.append(choiceListFragment); 1006 1007 this._highlightChoice(); 1008 } else { 1009 var notice = this._getTemplate('notice', canAddItem.notice); 1010 1011 this.choiceList.append(notice); 1012 } 1013 } else { 1014 // Otherwise show a notice 1015 var dropdownItem = void 0; 1016 var notice = void 0; 1017 1018 if (this._isSearching) { 1019 notice = typeof this.config.noResultsText === 'function' ? this.config.noResultsText() : this.config.noResultsText; 1020 dropdownItem = this._getTemplate('notice', notice, 'no-results'); 1021 } else { 1022 notice = typeof this.config.noChoicesText === 'function' ? this.config.noChoicesText() : this.config.noChoicesText; 1023 dropdownItem = this._getTemplate('notice', notice, 'no-choices'); 1024 } 1025 1026 this.choiceList.append(dropdownItem); 1027 } 1028 }; 1029 1030 Choices.prototype._renderItems = function () { 1031 var activeItems = this._store.activeItems || []; 1032 this.itemList.clear(); // Create a fragment to store our list items 1033 // (so we don't have to update the DOM for each item) 1034 1035 var itemListFragment = this._createItemsFragment(activeItems); // If we have items to add, append them 1036 1037 1038 if (itemListFragment.childNodes) { 1039 this.itemList.append(itemListFragment); 1040 } 1041 }; 1042 1043 Choices.prototype._createGroupsFragment = function (groups, choices, fragment) { 1044 var _this = this; 1045 1046 if (fragment === void 0) { 1047 fragment = document.createDocumentFragment(); 1048 } 1049 1050 var getGroupChoices = function (group) { 1051 return choices.filter(function (choice) { 1052 if (_this._isSelectOneElement) { 1053 return choice.groupId === group.id; 1054 } 1055 1056 return choice.groupId === group.id && (_this.config.renderSelectedChoices === 'always' || !choice.selected); 1057 }); 1058 }; // If sorting is enabled, filter groups 1059 1060 1061 if (this.config.shouldSort) { 1062 groups.sort(this.config.sorter); 1063 } 1064 1065 groups.forEach(function (group) { 1066 var groupChoices = getGroupChoices(group); 1067 1068 if (groupChoices.length >= 1) { 1069 var dropdownGroup = _this._getTemplate('choiceGroup', group); 1070 1071 fragment.appendChild(dropdownGroup); 1072 1073 _this._createChoicesFragment(groupChoices, fragment, true); 1074 } 1075 }); 1076 return fragment; 1077 }; 1078 1079 Choices.prototype._createChoicesFragment = function (choices, fragment, withinGroup) { 1080 var _this = this; 1081 1082 if (fragment === void 0) { 1083 fragment = document.createDocumentFragment(); 1084 } 1085 1086 if (withinGroup === void 0) { 1087 withinGroup = false; 1088 } // Create a fragment to store our list items (so we don't have to update the DOM for each item) 1089 1090 1091 var _a = this.config, 1092 renderSelectedChoices = _a.renderSelectedChoices, 1093 searchResultLimit = _a.searchResultLimit, 1094 renderChoiceLimit = _a.renderChoiceLimit; 1095 var filter = this._isSearching ? utils_1.sortByScore : this.config.sorter; 1096 1097 var appendChoice = function (choice) { 1098 var shouldRender = renderSelectedChoices === 'auto' ? _this._isSelectOneElement || !choice.selected : true; 1099 1100 if (shouldRender) { 1101 var dropdownItem = _this._getTemplate('choice', choice, _this.config.itemSelectText); 1102 1103 fragment.appendChild(dropdownItem); 1104 } 1105 }; 1106 1107 var rendererableChoices = choices; 1108 1109 if (renderSelectedChoices === 'auto' && !this._isSelectOneElement) { 1110 rendererableChoices = choices.filter(function (choice) { 1111 return !choice.selected; 1112 }); 1113 } // Split array into placeholders and "normal" choices 1114 1115 1116 var _b = rendererableChoices.reduce(function (acc, choice) { 1117 if (choice.placeholder) { 1118 acc.placeholderChoices.push(choice); 1119 } else { 1120 acc.normalChoices.push(choice); 1121 } 1122 1123 return acc; 1124 }, { 1125 placeholderChoices: [], 1126 normalChoices: [] 1127 }), 1128 placeholderChoices = _b.placeholderChoices, 1129 normalChoices = _b.normalChoices; // If sorting is enabled or the user is searching, filter choices 1130 1131 1132 if (this.config.shouldSort || this._isSearching) { 1133 normalChoices.sort(filter); 1134 } 1135 1136 var choiceLimit = rendererableChoices.length; // Prepend placeholeder 1137 1138 var sortedChoices = this._isSelectOneElement ? __spreadArray(__spreadArray([], placeholderChoices, true), normalChoices, true) : normalChoices; 1139 1140 if (this._isSearching) { 1141 choiceLimit = searchResultLimit; 1142 } else if (renderChoiceLimit && renderChoiceLimit > 0 && !withinGroup) { 1143 choiceLimit = renderChoiceLimit; 1144 } // Add each choice to dropdown within range 1145 1146 1147 for (var i = 0; i < choiceLimit; i += 1) { 1148 if (sortedChoices[i]) { 1149 appendChoice(sortedChoices[i]); 1150 } 1151 } 1152 1153 return fragment; 1154 }; 1155 1156 Choices.prototype._createItemsFragment = function (items, fragment) { 1157 var _this = this; 1158 1159 if (fragment === void 0) { 1160 fragment = document.createDocumentFragment(); 1161 } // Create fragment to add elements to 1162 1163 1164 var _a = this.config, 1165 shouldSortItems = _a.shouldSortItems, 1166 sorter = _a.sorter, 1167 removeItemButton = _a.removeItemButton; // If sorting is enabled, filter items 1168 1169 if (shouldSortItems && !this._isSelectOneElement) { 1170 items.sort(sorter); 1171 } 1172 1173 if (this._isTextElement) { 1174 // Update the value of the hidden input 1175 this.passedElement.value = items.map(function (_a) { 1176 var value = _a.value; 1177 return value; 1178 }).join(this.config.delimiter); 1179 } else { 1180 // Update the options of the hidden input 1181 this.passedElement.options = items; 1182 } 1183 1184 var addItemToFragment = function (item) { 1185 // Create new list element 1186 var listItem = _this._getTemplate('item', item, removeItemButton); // Append it to list 1187 1188 1189 fragment.appendChild(listItem); 1190 }; // Add each list item to list 1191 1192 1193 items.forEach(addItemToFragment); 1194 return fragment; 1195 }; 1196 1197 Choices.prototype._triggerChange = function (value) { 1198 if (value === undefined || value === null) { 1199 return; 1200 } 1201 1202 this.passedElement.triggerEvent(constants_1.EVENTS.change, { 1203 value: value 1204 }); 1205 }; 1206 1207 Choices.prototype._selectPlaceholderChoice = function (placeholderChoice) { 1208 this._addItem({ 1209 value: placeholderChoice.value, 1210 label: placeholderChoice.label, 1211 choiceId: placeholderChoice.id, 1212 groupId: placeholderChoice.groupId, 1213 placeholder: placeholderChoice.placeholder 1214 }); 1215 1216 this._triggerChange(placeholderChoice.value); 1217 }; 1218 1219 Choices.prototype._handleButtonAction = function (activeItems, element) { 1220 if (!activeItems || !element || !this.config.removeItems || !this.config.removeItemButton) { 1221 return; 1222 } 1223 1224 var itemId = element.parentNode && element.parentNode.dataset.id; 1225 var itemToRemove = itemId && activeItems.find(function (item) { 1226 return item.id === parseInt(itemId, 10); 1227 }); 1228 1229 if (!itemToRemove) { 1230 return; 1231 } // Remove item associated with button 1232 1233 1234 this._removeItem(itemToRemove); 1235 1236 this._triggerChange(itemToRemove.value); 1237 1238 if (this._isSelectOneElement && this._store.placeholderChoice) { 1239 this._selectPlaceholderChoice(this._store.placeholderChoice); 1240 } 1241 }; 1242 1243 Choices.prototype._handleItemAction = function (activeItems, element, hasShiftKey) { 1244 var _this = this; 1245 1246 if (hasShiftKey === void 0) { 1247 hasShiftKey = false; 1248 } 1249 1250 if (!activeItems || !element || !this.config.removeItems || this._isSelectOneElement) { 1251 return; 1252 } 1253 1254 var passedId = element.dataset.id; // We only want to select one item with a click 1255 // so we deselect any items that aren't the target 1256 // unless shift is being pressed 1257 1258 activeItems.forEach(function (item) { 1259 if (item.id === parseInt("".concat(passedId), 10) && !item.highlighted) { 1260 _this.highlightItem(item); 1261 } else if (!hasShiftKey && item.highlighted) { 1262 _this.unhighlightItem(item); 1263 } 1264 }); // Focus input as without focus, a user cannot do anything with a 1265 // highlighted item 1266 1267 this.input.focus(); 1268 }; 1269 1270 Choices.prototype._handleChoiceAction = function (activeItems, element) { 1271 if (!activeItems || !element) { 1272 return; 1273 } // If we are clicking on an option 1274 1275 1276 var id = element.dataset.id; 1277 1278 var choice = id && this._store.getChoiceById(id); 1279 1280 if (!choice) { 1281 return; 1282 } 1283 1284 var passedKeyCode = activeItems[0] && activeItems[0].keyCode ? activeItems[0].keyCode : undefined; 1285 var hasActiveDropdown = this.dropdown.isActive; // Update choice keyCode 1286 1287 choice.keyCode = passedKeyCode; 1288 this.passedElement.triggerEvent(constants_1.EVENTS.choice, { 1289 choice: choice 1290 }); 1291 1292 if (!choice.selected && !choice.disabled) { 1293 var canAddItem = this._canAddItem(activeItems, choice.value); 1294 1295 if (canAddItem.response) { 1296 this._addItem({ 1297 value: choice.value, 1298 label: choice.label, 1299 choiceId: choice.id, 1300 groupId: choice.groupId, 1301 customProperties: choice.customProperties, 1302 placeholder: choice.placeholder, 1303 keyCode: choice.keyCode 1304 }); 1305 1306 this._triggerChange(choice.value); 1307 } 1308 } 1309 1310 this.clearInput(); // We want to close the dropdown if we are dealing with a single select box 1311 1312 if (hasActiveDropdown && this._isSelectOneElement) { 1313 this.hideDropdown(true); 1314 this.containerOuter.focus(); 1315 } 1316 }; 1317 1318 Choices.prototype._handleBackspace = function (activeItems) { 1319 if (!this.config.removeItems || !activeItems) { 1320 return; 1321 } 1322 1323 var lastItem = activeItems[activeItems.length - 1]; 1324 var hasHighlightedItems = activeItems.some(function (item) { 1325 return item.highlighted; 1326 }); // If editing the last item is allowed and there are not other selected items, 1327 // we can edit the item value. Otherwise if we can remove items, remove all selected items 1328 1329 if (this.config.editItems && !hasHighlightedItems && lastItem) { 1330 this.input.value = lastItem.value; 1331 this.input.setWidth(); 1332 1333 this._removeItem(lastItem); 1334 1335 this._triggerChange(lastItem.value); 1336 } else { 1337 if (!hasHighlightedItems) { 1338 // Highlight last item if none already highlighted 1339 this.highlightItem(lastItem, false); 1340 } 1341 1342 this.removeHighlightedItems(true); 1343 } 1344 }; 1345 1346 Choices.prototype._startLoading = function () { 1347 this._store.dispatch((0, misc_1.setIsLoading)(true)); 1348 }; 1349 1350 Choices.prototype._stopLoading = function () { 1351 this._store.dispatch((0, misc_1.setIsLoading)(false)); 1352 }; 1353 1354 Choices.prototype._handleLoadingState = function (setLoading) { 1355 if (setLoading === void 0) { 1356 setLoading = true; 1357 } 1358 1359 var placeholderItem = this.itemList.getChild(".".concat(this.config.classNames.placeholder)); 1360 1361 if (setLoading) { 1362 this.disable(); 1363 this.containerOuter.addLoadingState(); 1364 1365 if (this._isSelectOneElement) { 1366 if (!placeholderItem) { 1367 placeholderItem = this._getTemplate('placeholder', this.config.loadingText); 1368 1369 if (placeholderItem) { 1370 this.itemList.append(placeholderItem); 1371 } 1372 } else { 1373 placeholderItem.innerHTML = this.config.loadingText; 1374 } 1375 } else { 1376 this.input.placeholder = this.config.loadingText; 1377 } 1378 } else { 1379 this.enable(); 1380 this.containerOuter.removeLoadingState(); 1381 1382 if (this._isSelectOneElement) { 1383 if (placeholderItem) { 1384 placeholderItem.innerHTML = this._placeholderValue || ''; 1385 } 1386 } else { 1387 this.input.placeholder = this._placeholderValue || ''; 1388 } 1389 } 1390 }; 1391 1392 Choices.prototype._handleSearch = function (value) { 1393 if (!value || !this.input.isFocussed) { 1394 return; 1395 } 1396 1397 var choices = this._store.choices; 1398 var _a = this.config, 1399 searchFloor = _a.searchFloor, 1400 searchChoices = _a.searchChoices; 1401 var hasUnactiveChoices = choices.some(function (option) { 1402 return !option.active; 1403 }); // Check that we have a value to search and the input was an alphanumeric character 1404 1405 if (value && value.length >= searchFloor) { 1406 var resultCount = searchChoices ? this._searchChoices(value) : 0; // Trigger search event 1407 1408 this.passedElement.triggerEvent(constants_1.EVENTS.search, { 1409 value: value, 1410 resultCount: resultCount 1411 }); 1412 } else if (hasUnactiveChoices) { 1413 // Otherwise reset choices to active 1414 this._isSearching = false; 1415 1416 this._store.dispatch((0, choices_1.activateChoices)(true)); 1417 } 1418 }; 1419 1420 Choices.prototype._canAddItem = function (activeItems, value) { 1421 var canAddItem = true; 1422 var notice = typeof this.config.addItemText === 'function' ? this.config.addItemText(value) : this.config.addItemText; 1423 1424 if (!this._isSelectOneElement) { 1425 var isDuplicateValue = (0, utils_1.existsInArray)(activeItems, value); 1426 1427 if (this.config.maxItemCount > 0 && this.config.maxItemCount <= activeItems.length) { 1428 // If there is a max entry limit and we have reached that limit 1429 // don't update 1430 canAddItem = false; 1431 notice = typeof this.config.maxItemText === 'function' ? this.config.maxItemText(this.config.maxItemCount) : this.config.maxItemText; 1432 } 1433 1434 if (!this.config.duplicateItemsAllowed && isDuplicateValue && canAddItem) { 1435 canAddItem = false; 1436 notice = typeof this.config.uniqueItemText === 'function' ? this.config.uniqueItemText(value) : this.config.uniqueItemText; 1437 } 1438 1439 if (this._isTextElement && this.config.addItems && canAddItem && typeof this.config.addItemFilter === 'function' && !this.config.addItemFilter(value)) { 1440 canAddItem = false; 1441 notice = typeof this.config.customAddItemText === 'function' ? this.config.customAddItemText(value) : this.config.customAddItemText; 1442 } 1443 } 1444 1445 return { 1446 response: canAddItem, 1447 notice: notice 1448 }; 1449 }; 1450 1451 Choices.prototype._searchChoices = function (value) { 1452 var newValue = typeof value === 'string' ? value.trim() : value; 1453 var currentValue = typeof this._currentValue === 'string' ? this._currentValue.trim() : this._currentValue; 1454 1455 if (newValue.length < 1 && newValue === "".concat(currentValue, " ")) { 1456 return 0; 1457 } // If new value matches the desired length and is not the same as the current value with a space 1458 1459 1460 var haystack = this._store.searchableChoices; 1461 var needle = newValue; 1462 1463 var keys = __spreadArray([], this.config.searchFields, true); 1464 1465 var options = Object.assign(this.config.fuseOptions, { 1466 keys: keys, 1467 includeMatches: true 1468 }); 1469 var fuse = new fuse_js_1.default(haystack, options); 1470 var results = fuse.search(needle); // see https://github.com/krisk/Fuse/issues/303 1471 1472 this._currentValue = newValue; 1473 this._highlightPosition = 0; 1474 this._isSearching = true; 1475 1476 this._store.dispatch((0, choices_1.filterChoices)(results)); 1477 1478 return results.length; 1479 }; 1480 1481 Choices.prototype._addEventListeners = function () { 1482 var documentElement = document.documentElement; // capture events - can cancel event processing or propagation 1483 1484 documentElement.addEventListener('touchend', this._onTouchEnd, true); 1485 this.containerOuter.element.addEventListener('keydown', this._onKeyDown, true); 1486 this.containerOuter.element.addEventListener('mousedown', this._onMouseDown, true); // passive events - doesn't call `preventDefault` or `stopPropagation` 1487 1488 documentElement.addEventListener('click', this._onClick, { 1489 passive: true 1490 }); 1491 documentElement.addEventListener('touchmove', this._onTouchMove, { 1492 passive: true 1493 }); 1494 this.dropdown.element.addEventListener('mouseover', this._onMouseOver, { 1495 passive: true 1496 }); 1497 1498 if (this._isSelectOneElement) { 1499 this.containerOuter.element.addEventListener('focus', this._onFocus, { 1500 passive: true 1501 }); 1502 this.containerOuter.element.addEventListener('blur', this._onBlur, { 1503 passive: true 1504 }); 1505 } 1506 1507 this.input.element.addEventListener('keyup', this._onKeyUp, { 1508 passive: true 1509 }); 1510 this.input.element.addEventListener('focus', this._onFocus, { 1511 passive: true 1512 }); 1513 this.input.element.addEventListener('blur', this._onBlur, { 1514 passive: true 1515 }); 1516 1517 if (this.input.element.form) { 1518 this.input.element.form.addEventListener('reset', this._onFormReset, { 1519 passive: true 1520 }); 1521 } 1522 1523 this.input.addEventListeners(); 1524 }; 1525 1526 Choices.prototype._removeEventListeners = function () { 1527 var documentElement = document.documentElement; 1528 documentElement.removeEventListener('touchend', this._onTouchEnd, true); 1529 this.containerOuter.element.removeEventListener('keydown', this._onKeyDown, true); 1530 this.containerOuter.element.removeEventListener('mousedown', this._onMouseDown, true); 1531 documentElement.removeEventListener('click', this._onClick); 1532 documentElement.removeEventListener('touchmove', this._onTouchMove); 1533 this.dropdown.element.removeEventListener('mouseover', this._onMouseOver); 1534 1535 if (this._isSelectOneElement) { 1536 this.containerOuter.element.removeEventListener('focus', this._onFocus); 1537 this.containerOuter.element.removeEventListener('blur', this._onBlur); 1538 } 1539 1540 this.input.element.removeEventListener('keyup', this._onKeyUp); 1541 this.input.element.removeEventListener('focus', this._onFocus); 1542 this.input.element.removeEventListener('blur', this._onBlur); 1543 1544 if (this.input.element.form) { 1545 this.input.element.form.removeEventListener('reset', this._onFormReset); 1546 } 1547 1548 this.input.removeEventListeners(); 1549 }; 1550 1551 Choices.prototype._onKeyDown = function (event) { 1552 var keyCode = event.keyCode; 1553 var activeItems = this._store.activeItems; 1554 var hasFocusedInput = this.input.isFocussed; 1555 var hasActiveDropdown = this.dropdown.isActive; 1556 var hasItems = this.itemList.hasChildren(); 1557 var keyString = String.fromCharCode(keyCode); 1558 var wasAlphaNumericChar = /[a-zA-Z0-9-_ ]/.test(keyString); 1559 var BACK_KEY = constants_1.KEY_CODES.BACK_KEY, 1560 DELETE_KEY = constants_1.KEY_CODES.DELETE_KEY, 1561 ENTER_KEY = constants_1.KEY_CODES.ENTER_KEY, 1562 A_KEY = constants_1.KEY_CODES.A_KEY, 1563 ESC_KEY = constants_1.KEY_CODES.ESC_KEY, 1564 UP_KEY = constants_1.KEY_CODES.UP_KEY, 1565 DOWN_KEY = constants_1.KEY_CODES.DOWN_KEY, 1566 PAGE_UP_KEY = constants_1.KEY_CODES.PAGE_UP_KEY, 1567 PAGE_DOWN_KEY = constants_1.KEY_CODES.PAGE_DOWN_KEY; 1568 1569 if (!this._isTextElement && !hasActiveDropdown && wasAlphaNumericChar) { 1570 this.showDropdown(); 1571 1572 if (!this.input.isFocussed) { 1573 /* 1574 We update the input value with the pressed key as 1575 the input was not focussed at the time of key press 1576 therefore does not have the value of the key. 1577 */ 1578 this.input.value += keyString.toLowerCase(); 1579 } 1580 } 1581 1582 switch (keyCode) { 1583 case A_KEY: 1584 return this._onSelectKey(event, hasItems); 1585 1586 case ENTER_KEY: 1587 return this._onEnterKey(event, activeItems, hasActiveDropdown); 1588 1589 case ESC_KEY: 1590 return this._onEscapeKey(hasActiveDropdown); 1591 1592 case UP_KEY: 1593 case PAGE_UP_KEY: 1594 case DOWN_KEY: 1595 case PAGE_DOWN_KEY: 1596 return this._onDirectionKey(event, hasActiveDropdown); 1597 1598 case DELETE_KEY: 1599 case BACK_KEY: 1600 return this._onDeleteKey(event, activeItems, hasFocusedInput); 1601 1602 default: 1603 } 1604 }; 1605 1606 Choices.prototype._onKeyUp = function (_a) { 1607 var target = _a.target, 1608 keyCode = _a.keyCode; 1609 var value = this.input.value; 1610 var activeItems = this._store.activeItems; 1611 1612 var canAddItem = this._canAddItem(activeItems, value); 1613 1614 var backKey = constants_1.KEY_CODES.BACK_KEY, 1615 deleteKey = constants_1.KEY_CODES.DELETE_KEY; // We are typing into a text input and have a value, we want to show a dropdown 1616 // notice. Otherwise hide the dropdown 1617 1618 if (this._isTextElement) { 1619 var canShowDropdownNotice = canAddItem.notice && value; 1620 1621 if (canShowDropdownNotice) { 1622 var dropdownItem = this._getTemplate('notice', canAddItem.notice); 1623 1624 this.dropdown.element.innerHTML = dropdownItem.outerHTML; 1625 this.showDropdown(true); 1626 } else { 1627 this.hideDropdown(true); 1628 } 1629 } else { 1630 var wasRemovalKeyCode = keyCode === backKey || keyCode === deleteKey; 1631 var userHasRemovedValue = wasRemovalKeyCode && target && !target.value; 1632 var canReactivateChoices = !this._isTextElement && this._isSearching; 1633 var canSearch = this._canSearch && canAddItem.response; 1634 1635 if (userHasRemovedValue && canReactivateChoices) { 1636 this._isSearching = false; 1637 1638 this._store.dispatch((0, choices_1.activateChoices)(true)); 1639 } else if (canSearch) { 1640 this._handleSearch(this.input.value); 1641 } 1642 } 1643 1644 this._canSearch = this.config.searchEnabled; 1645 }; 1646 1647 Choices.prototype._onSelectKey = function (event, hasItems) { 1648 var ctrlKey = event.ctrlKey, 1649 metaKey = event.metaKey; 1650 var hasCtrlDownKeyPressed = ctrlKey || metaKey; // If CTRL + A or CMD + A have been pressed and there are items to select 1651 1652 if (hasCtrlDownKeyPressed && hasItems) { 1653 this._canSearch = false; 1654 var shouldHightlightAll = this.config.removeItems && !this.input.value && this.input.element === document.activeElement; 1655 1656 if (shouldHightlightAll) { 1657 this.highlightAll(); 1658 } 1659 } 1660 }; 1661 1662 Choices.prototype._onEnterKey = function (event, activeItems, hasActiveDropdown) { 1663 var target = event.target; 1664 var enterKey = constants_1.KEY_CODES.ENTER_KEY; 1665 var targetWasButton = target && target.hasAttribute('data-button'); 1666 1667 if (this._isTextElement && target && target.value) { 1668 var value = this.input.value; 1669 1670 var canAddItem = this._canAddItem(activeItems, value); 1671 1672 if (canAddItem.response) { 1673 this.hideDropdown(true); 1674 1675 this._addItem({ 1676 value: value 1677 }); 1678 1679 this._triggerChange(value); 1680 1681 this.clearInput(); 1682 } 1683 } 1684 1685 if (targetWasButton) { 1686 this._handleButtonAction(activeItems, target); 1687 1688 event.preventDefault(); 1689 } 1690 1691 if (hasActiveDropdown) { 1692 var highlightedChoice = this.dropdown.getChild(".".concat(this.config.classNames.highlightedState)); 1693 1694 if (highlightedChoice) { 1695 // add enter keyCode value 1696 if (activeItems[0]) { 1697 activeItems[0].keyCode = enterKey; // eslint-disable-line no-param-reassign 1698 } 1699 1700 this._handleChoiceAction(activeItems, highlightedChoice); 1701 } 1702 1703 event.preventDefault(); 1704 } else if (this._isSelectOneElement) { 1705 this.showDropdown(); 1706 event.preventDefault(); 1707 } 1708 }; 1709 1710 Choices.prototype._onEscapeKey = function (hasActiveDropdown) { 1711 if (hasActiveDropdown) { 1712 this.hideDropdown(true); 1713 this.containerOuter.focus(); 1714 } 1715 }; 1716 1717 Choices.prototype._onDirectionKey = function (event, hasActiveDropdown) { 1718 var keyCode = event.keyCode, 1719 metaKey = event.metaKey; 1720 var downKey = constants_1.KEY_CODES.DOWN_KEY, 1721 pageUpKey = constants_1.KEY_CODES.PAGE_UP_KEY, 1722 pageDownKey = constants_1.KEY_CODES.PAGE_DOWN_KEY; // If up or down key is pressed, traverse through options 1723 1724 if (hasActiveDropdown || this._isSelectOneElement) { 1725 this.showDropdown(); 1726 this._canSearch = false; 1727 var directionInt = keyCode === downKey || keyCode === pageDownKey ? 1 : -1; 1728 var skipKey = metaKey || keyCode === pageDownKey || keyCode === pageUpKey; 1729 var selectableChoiceIdentifier = '[data-choice-selectable]'; 1730 var nextEl = void 0; 1731 1732 if (skipKey) { 1733 if (directionInt > 0) { 1734 nextEl = this.dropdown.element.querySelector("".concat(selectableChoiceIdentifier, ":last-of-type")); 1735 } else { 1736 nextEl = this.dropdown.element.querySelector(selectableChoiceIdentifier); 1737 } 1738 } else { 1739 var currentEl = this.dropdown.element.querySelector(".".concat(this.config.classNames.highlightedState)); 1740 1741 if (currentEl) { 1742 nextEl = (0, utils_1.getAdjacentEl)(currentEl, selectableChoiceIdentifier, directionInt); 1743 } else { 1744 nextEl = this.dropdown.element.querySelector(selectableChoiceIdentifier); 1745 } 1746 } 1747 1748 if (nextEl) { 1749 // We prevent default to stop the cursor moving 1750 // when pressing the arrow 1751 if (!(0, utils_1.isScrolledIntoView)(nextEl, this.choiceList.element, directionInt)) { 1752 this.choiceList.scrollToChildElement(nextEl, directionInt); 1753 } 1754 1755 this._highlightChoice(nextEl); 1756 } // Prevent default to maintain cursor position whilst 1757 // traversing dropdown options 1758 1759 1760 event.preventDefault(); 1761 } 1762 }; 1763 1764 Choices.prototype._onDeleteKey = function (event, activeItems, hasFocusedInput) { 1765 var target = event.target; // If backspace or delete key is pressed and the input has no value 1766 1767 if (!this._isSelectOneElement && !target.value && hasFocusedInput) { 1768 this._handleBackspace(activeItems); 1769 1770 event.preventDefault(); 1771 } 1772 }; 1773 1774 Choices.prototype._onTouchMove = function () { 1775 if (this._wasTap) { 1776 this._wasTap = false; 1777 } 1778 }; 1779 1780 Choices.prototype._onTouchEnd = function (event) { 1781 var target = (event || event.touches[0]).target; 1782 var touchWasWithinContainer = this._wasTap && this.containerOuter.element.contains(target); 1783 1784 if (touchWasWithinContainer) { 1785 var containerWasExactTarget = target === this.containerOuter.element || target === this.containerInner.element; 1786 1787 if (containerWasExactTarget) { 1788 if (this._isTextElement) { 1789 this.input.focus(); 1790 } else if (this._isSelectMultipleElement) { 1791 this.showDropdown(); 1792 } 1793 } // Prevents focus event firing 1794 1795 1796 event.stopPropagation(); 1797 } 1798 1799 this._wasTap = true; 1800 }; 1801 /** 1802 * Handles mousedown event in capture mode for containetOuter.element 1803 */ 1804 1805 1806 Choices.prototype._onMouseDown = function (event) { 1807 var target = event.target; 1808 1809 if (!(target instanceof HTMLElement)) { 1810 return; 1811 } // If we have our mouse down on the scrollbar and are on IE11... 1812 1813 1814 if (IS_IE11 && this.choiceList.element.contains(target)) { 1815 // check if click was on a scrollbar area 1816 var firstChoice = this.choiceList.element.firstElementChild; 1817 var isOnScrollbar = this._direction === 'ltr' ? event.offsetX >= firstChoice.offsetWidth : event.offsetX < firstChoice.offsetLeft; 1818 this._isScrollingOnIe = isOnScrollbar; 1819 } 1820 1821 if (target === this.input.element) { 1822 return; 1823 } 1824 1825 var item = target.closest('[data-button],[data-item],[data-choice]'); 1826 1827 if (item instanceof HTMLElement) { 1828 var hasShiftKey = event.shiftKey; 1829 var activeItems = this._store.activeItems; 1830 var dataset = item.dataset; 1831 1832 if ('button' in dataset) { 1833 this._handleButtonAction(activeItems, item); 1834 } else if ('item' in dataset) { 1835 this._handleItemAction(activeItems, item, hasShiftKey); 1836 } else if ('choice' in dataset) { 1837 this._handleChoiceAction(activeItems, item); 1838 } 1839 } 1840 1841 event.preventDefault(); 1842 }; 1843 /** 1844 * Handles mouseover event over this.dropdown 1845 * @param {MouseEvent} event 1846 */ 1847 1848 1849 Choices.prototype._onMouseOver = function (_a) { 1850 var target = _a.target; 1851 1852 if (target instanceof HTMLElement && 'choice' in target.dataset) { 1853 this._highlightChoice(target); 1854 } 1855 }; 1856 1857 Choices.prototype._onClick = function (_a) { 1858 var target = _a.target; 1859 var clickWasWithinContainer = this.containerOuter.element.contains(target); 1860 1861 if (clickWasWithinContainer) { 1862 if (!this.dropdown.isActive && !this.containerOuter.isDisabled) { 1863 if (this._isTextElement) { 1864 if (document.activeElement !== this.input.element) { 1865 this.input.focus(); 1866 } 1867 } else { 1868 this.showDropdown(); 1869 this.containerOuter.focus(); 1870 } 1871 } else if (this._isSelectOneElement && target !== this.input.element && !this.dropdown.element.contains(target)) { 1872 this.hideDropdown(); 1873 } 1874 } else { 1875 var hasHighlightedItems = this._store.highlightedActiveItems.length > 0; 1876 1877 if (hasHighlightedItems) { 1878 this.unhighlightAll(); 1879 } 1880 1881 this.containerOuter.removeFocusState(); 1882 this.hideDropdown(true); 1883 } 1884 }; 1885 1886 Choices.prototype._onFocus = function (_a) { 1887 var _b; 1888 1889 var _this = this; 1890 1891 var target = _a.target; 1892 var focusWasWithinContainer = target && this.containerOuter.element.contains(target); 1893 1894 if (!focusWasWithinContainer) { 1895 return; 1896 } 1897 1898 var focusActions = (_b = {}, _b[constants_1.TEXT_TYPE] = function () { 1899 if (target === _this.input.element) { 1900 _this.containerOuter.addFocusState(); 1901 } 1902 }, _b[constants_1.SELECT_ONE_TYPE] = function () { 1903 _this.containerOuter.addFocusState(); 1904 1905 if (target === _this.input.element) { 1906 _this.showDropdown(true); 1907 } 1908 }, _b[constants_1.SELECT_MULTIPLE_TYPE] = function () { 1909 if (target === _this.input.element) { 1910 _this.showDropdown(true); // If element is a select box, the focused element is the container and the dropdown 1911 // isn't already open, focus and show dropdown 1912 1913 1914 _this.containerOuter.addFocusState(); 1915 } 1916 }, _b); 1917 focusActions[this.passedElement.element.type](); 1918 }; 1919 1920 Choices.prototype._onBlur = function (_a) { 1921 var _b; 1922 1923 var _this = this; 1924 1925 var target = _a.target; 1926 var blurWasWithinContainer = target && this.containerOuter.element.contains(target); 1927 1928 if (blurWasWithinContainer && !this._isScrollingOnIe) { 1929 var activeItems = this._store.activeItems; 1930 var hasHighlightedItems_1 = activeItems.some(function (item) { 1931 return item.highlighted; 1932 }); 1933 var blurActions = (_b = {}, _b[constants_1.TEXT_TYPE] = function () { 1934 if (target === _this.input.element) { 1935 _this.containerOuter.removeFocusState(); 1936 1937 if (hasHighlightedItems_1) { 1938 _this.unhighlightAll(); 1939 } 1940 1941 _this.hideDropdown(true); 1942 } 1943 }, _b[constants_1.SELECT_ONE_TYPE] = function () { 1944 _this.containerOuter.removeFocusState(); 1945 1946 if (target === _this.input.element || target === _this.containerOuter.element && !_this._canSearch) { 1947 _this.hideDropdown(true); 1948 } 1949 }, _b[constants_1.SELECT_MULTIPLE_TYPE] = function () { 1950 if (target === _this.input.element) { 1951 _this.containerOuter.removeFocusState(); 1952 1953 _this.hideDropdown(true); 1954 1955 if (hasHighlightedItems_1) { 1956 _this.unhighlightAll(); 1957 } 1958 } 1959 }, _b); 1960 blurActions[this.passedElement.element.type](); 1961 } else { 1962 // On IE11, clicking the scollbar blurs our input and thus 1963 // closes the dropdown. To stop this, we refocus our input 1964 // if we know we are on IE *and* are scrolling. 1965 this._isScrollingOnIe = false; 1966 this.input.element.focus(); 1967 } 1968 }; 1969 1970 Choices.prototype._onFormReset = function () { 1971 this._store.dispatch((0, misc_1.resetTo)(this._initialState)); 1972 }; 1973 1974 Choices.prototype._highlightChoice = function (el) { 1975 var _this = this; 1976 1977 if (el === void 0) { 1978 el = null; 1979 } 1980 1981 var choices = Array.from(this.dropdown.element.querySelectorAll('[data-choice-selectable]')); 1982 1983 if (!choices.length) { 1984 return; 1985 } 1986 1987 var passedEl = el; 1988 var highlightedChoices = Array.from(this.dropdown.element.querySelectorAll(".".concat(this.config.classNames.highlightedState))); // Remove any highlighted choices 1989 1990 highlightedChoices.forEach(function (choice) { 1991 choice.classList.remove(_this.config.classNames.highlightedState); 1992 choice.setAttribute('aria-selected', 'false'); 1993 }); 1994 1995 if (passedEl) { 1996 this._highlightPosition = choices.indexOf(passedEl); 1997 } else { 1998 // Highlight choice based on last known highlight location 1999 if (choices.length > this._highlightPosition) { 2000 // If we have an option to highlight 2001 passedEl = choices[this._highlightPosition]; 2002 } else { 2003 // Otherwise highlight the option before 2004 passedEl = choices[choices.length - 1]; 2005 } 2006 2007 if (!passedEl) { 2008 passedEl = choices[0]; 2009 } 2010 } 2011 2012 passedEl.classList.add(this.config.classNames.highlightedState); 2013 passedEl.setAttribute('aria-selected', 'true'); 2014 this.passedElement.triggerEvent(constants_1.EVENTS.highlightChoice, { 2015 el: passedEl 2016 }); 2017 2018 if (this.dropdown.isActive) { 2019 // IE11 ignores aria-label and blocks virtual keyboard 2020 // if aria-activedescendant is set without a dropdown 2021 this.input.setActiveDescendant(passedEl.id); 2022 this.containerOuter.setActiveDescendant(passedEl.id); 2023 } 2024 }; 2025 2026 Choices.prototype._addItem = function (_a) { 2027 var value = _a.value, 2028 _b = _a.label, 2029 label = _b === void 0 ? null : _b, 2030 _c = _a.choiceId, 2031 choiceId = _c === void 0 ? -1 : _c, 2032 _d = _a.groupId, 2033 groupId = _d === void 0 ? -1 : _d, 2034 _e = _a.customProperties, 2035 customProperties = _e === void 0 ? {} : _e, 2036 _f = _a.placeholder, 2037 placeholder = _f === void 0 ? false : _f, 2038 _g = _a.keyCode, 2039 keyCode = _g === void 0 ? -1 : _g; 2040 var passedValue = typeof value === 'string' ? value.trim() : value; 2041 var items = this._store.items; 2042 var passedLabel = label || passedValue; 2043 var passedOptionId = choiceId || -1; 2044 var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; 2045 var id = items ? items.length + 1 : 1; // If a prepended value has been passed, prepend it 2046 2047 if (this.config.prependValue) { 2048 passedValue = this.config.prependValue + passedValue.toString(); 2049 } // If an appended value has been passed, append it 2050 2051 2052 if (this.config.appendValue) { 2053 passedValue += this.config.appendValue.toString(); 2054 } 2055 2056 this._store.dispatch((0, items_1.addItem)({ 2057 value: passedValue, 2058 label: passedLabel, 2059 id: id, 2060 choiceId: passedOptionId, 2061 groupId: groupId, 2062 customProperties: customProperties, 2063 placeholder: placeholder, 2064 keyCode: keyCode 2065 })); 2066 2067 if (this._isSelectOneElement) { 2068 this.removeActiveItems(id); 2069 } // Trigger change event 2070 2071 2072 this.passedElement.triggerEvent(constants_1.EVENTS.addItem, { 2073 id: id, 2074 value: passedValue, 2075 label: passedLabel, 2076 customProperties: customProperties, 2077 groupValue: group && group.value ? group.value : null, 2078 keyCode: keyCode 2079 }); 2080 }; 2081 2082 Choices.prototype._removeItem = function (item) { 2083 var id = item.id, 2084 value = item.value, 2085 label = item.label, 2086 customProperties = item.customProperties, 2087 choiceId = item.choiceId, 2088 groupId = item.groupId; 2089 var group = groupId && groupId >= 0 ? this._store.getGroupById(groupId) : null; 2090 2091 if (!id || !choiceId) { 2092 return; 2093 } 2094 2095 this._store.dispatch((0, items_1.removeItem)(id, choiceId)); 2096 2097 this.passedElement.triggerEvent(constants_1.EVENTS.removeItem, { 2098 id: id, 2099 value: value, 2100 label: label, 2101 customProperties: customProperties, 2102 groupValue: group && group.value ? group.value : null 2103 }); 2104 }; 2105 2106 Choices.prototype._addChoice = function (_a) { 2107 var value = _a.value, 2108 _b = _a.label, 2109 label = _b === void 0 ? null : _b, 2110 _c = _a.isSelected, 2111 isSelected = _c === void 0 ? false : _c, 2112 _d = _a.isDisabled, 2113 isDisabled = _d === void 0 ? false : _d, 2114 _e = _a.groupId, 2115 groupId = _e === void 0 ? -1 : _e, 2116 _f = _a.customProperties, 2117 customProperties = _f === void 0 ? {} : _f, 2118 _g = _a.placeholder, 2119 placeholder = _g === void 0 ? false : _g, 2120 _h = _a.keyCode, 2121 keyCode = _h === void 0 ? -1 : _h; 2122 2123 if (typeof value === 'undefined' || value === null) { 2124 return; 2125 } // Generate unique id 2126 2127 2128 var choices = this._store.choices; 2129 var choiceLabel = label || value; 2130 var choiceId = choices ? choices.length + 1 : 1; 2131 var choiceElementId = "".concat(this._baseId, "-").concat(this._idNames.itemChoice, "-").concat(choiceId); 2132 2133 this._store.dispatch((0, choices_1.addChoice)({ 2134 id: choiceId, 2135 groupId: groupId, 2136 elementId: choiceElementId, 2137 value: value, 2138 label: choiceLabel, 2139 disabled: isDisabled, 2140 customProperties: customProperties, 2141 placeholder: placeholder, 2142 keyCode: keyCode 2143 })); 2144 2145 if (isSelected) { 2146 this._addItem({ 2147 value: value, 2148 label: choiceLabel, 2149 choiceId: choiceId, 2150 customProperties: customProperties, 2151 placeholder: placeholder, 2152 keyCode: keyCode 2153 }); 2154 } 2155 }; 2156 2157 Choices.prototype._addGroup = function (_a) { 2158 var _this = this; 2159 2160 var group = _a.group, 2161 id = _a.id, 2162 _b = _a.valueKey, 2163 valueKey = _b === void 0 ? 'value' : _b, 2164 _c = _a.labelKey, 2165 labelKey = _c === void 0 ? 'label' : _c; 2166 var groupChoices = (0, utils_1.isType)('Object', group) ? group.choices : Array.from(group.getElementsByTagName('OPTION')); 2167 var groupId = id || Math.floor(new Date().valueOf() * Math.random()); 2168 var isDisabled = group.disabled ? group.disabled : false; 2169 2170 if (groupChoices) { 2171 this._store.dispatch((0, groups_1.addGroup)({ 2172 value: group.label, 2173 id: groupId, 2174 active: true, 2175 disabled: isDisabled 2176 })); 2177 2178 var addGroupChoices = function (choice) { 2179 var isOptDisabled = choice.disabled || choice.parentNode && choice.parentNode.disabled; 2180 2181 _this._addChoice({ 2182 value: choice[valueKey], 2183 label: (0, utils_1.isType)('Object', choice) ? choice[labelKey] : choice.innerHTML, 2184 isSelected: choice.selected, 2185 isDisabled: isOptDisabled, 2186 groupId: groupId, 2187 customProperties: choice.customProperties, 2188 placeholder: choice.placeholder 2189 }); 2190 }; 2191 2192 groupChoices.forEach(addGroupChoices); 2193 } else { 2194 this._store.dispatch((0, groups_1.addGroup)({ 2195 value: group.label, 2196 id: group.id, 2197 active: false, 2198 disabled: group.disabled 2199 })); 2200 } 2201 }; 2202 2203 Choices.prototype._getTemplate = function (template) { 2204 var _a; 2205 2206 var args = []; 2207 2208 for (var _i = 1; _i < arguments.length; _i++) { 2209 args[_i - 1] = arguments[_i]; 2210 } 2211 2212 var classNames = this.config.classNames; 2213 return (_a = this._templates[template]).call.apply(_a, __spreadArray([this, classNames], args, false)); 2214 }; 2215 2216 Choices.prototype._createTemplates = function () { 2217 var callbackOnCreateTemplates = this.config.callbackOnCreateTemplates; 2218 var userTemplates = {}; 2219 2220 if (callbackOnCreateTemplates && typeof callbackOnCreateTemplates === 'function') { 2221 userTemplates = callbackOnCreateTemplates.call(this, utils_1.strToEl); 2222 } 2223 2224 this._templates = (0, deepmerge_1.default)(templates_1.default, userTemplates); 2225 }; 2226 2227 Choices.prototype._createElements = function () { 2228 this.containerOuter = new components_1.Container({ 2229 element: this._getTemplate('containerOuter', this._direction, this._isSelectElement, this._isSelectOneElement, this.config.searchEnabled, this.passedElement.element.type), 2230 classNames: this.config.classNames, 2231 type: this.passedElement.element.type, 2232 position: this.config.position 2233 }); 2234 this.containerInner = new components_1.Container({ 2235 element: this._getTemplate('containerInner'), 2236 classNames: this.config.classNames, 2237 type: this.passedElement.element.type, 2238 position: this.config.position 2239 }); 2240 this.input = new components_1.Input({ 2241 element: this._getTemplate('input', this._placeholderValue), 2242 classNames: this.config.classNames, 2243 type: this.passedElement.element.type, 2244 preventPaste: !this.config.paste 2245 }); 2246 this.choiceList = new components_1.List({ 2247 element: this._getTemplate('choiceList', this._isSelectOneElement) 2248 }); 2249 this.itemList = new components_1.List({ 2250 element: this._getTemplate('itemList', this._isSelectOneElement) 2251 }); 2252 this.dropdown = new components_1.Dropdown({ 2253 element: this._getTemplate('dropdown'), 2254 classNames: this.config.classNames, 2255 type: this.passedElement.element.type 2256 }); 2257 }; 2258 2259 Choices.prototype._createStructure = function () { 2260 // Hide original element 2261 this.passedElement.conceal(); // Wrap input in container preserving DOM ordering 2262 2263 this.containerInner.wrap(this.passedElement.element); // Wrapper inner container with outer container 2264 2265 this.containerOuter.wrap(this.containerInner.element); 2266 2267 if (this._isSelectOneElement) { 2268 this.input.placeholder = this.config.searchPlaceholderValue || ''; 2269 } else if (this._placeholderValue) { 2270 this.input.placeholder = this._placeholderValue; 2271 this.input.setWidth(); 2272 } 2273 2274 this.containerOuter.element.appendChild(this.containerInner.element); 2275 this.containerOuter.element.appendChild(this.dropdown.element); 2276 this.containerInner.element.appendChild(this.itemList.element); 2277 2278 if (!this._isTextElement) { 2279 this.dropdown.element.appendChild(this.choiceList.element); 2280 } 2281 2282 if (!this._isSelectOneElement) { 2283 this.containerInner.element.appendChild(this.input.element); 2284 } else if (this.config.searchEnabled) { 2285 this.dropdown.element.insertBefore(this.input.element, this.dropdown.element.firstChild); 2286 } 2287 2288 if (this._isSelectElement) { 2289 this._highlightPosition = 0; 2290 this._isSearching = false; 2291 2292 this._startLoading(); 2293 2294 if (this._presetGroups.length) { 2295 this._addPredefinedGroups(this._presetGroups); 2296 } else { 2297 this._addPredefinedChoices(this._presetChoices); 2298 } 2299 2300 this._stopLoading(); 2301 } 2302 2303 if (this._isTextElement) { 2304 this._addPredefinedItems(this._presetItems); 2305 } 2306 }; 2307 2308 Choices.prototype._addPredefinedGroups = function (groups) { 2309 var _this = this; // If we have a placeholder option 2310 2311 2312 var placeholderChoice = this.passedElement.placeholderOption; 2313 2314 if (placeholderChoice && placeholderChoice.parentNode && placeholderChoice.parentNode.tagName === 'SELECT') { 2315 this._addChoice({ 2316 value: placeholderChoice.value, 2317 label: placeholderChoice.innerHTML, 2318 isSelected: placeholderChoice.selected, 2319 isDisabled: placeholderChoice.disabled, 2320 placeholder: true 2321 }); 2322 } 2323 2324 groups.forEach(function (group) { 2325 return _this._addGroup({ 2326 group: group, 2327 id: group.id || null 2328 }); 2329 }); 2330 }; 2331 2332 Choices.prototype._addPredefinedChoices = function (choices) { 2333 var _this = this; // If sorting is enabled or the user is searching, filter choices 2334 2335 2336 if (this.config.shouldSort) { 2337 choices.sort(this.config.sorter); 2338 } 2339 2340 var hasSelectedChoice = choices.some(function (choice) { 2341 return choice.selected; 2342 }); 2343 var firstEnabledChoiceIndex = choices.findIndex(function (choice) { 2344 return choice.disabled === undefined || !choice.disabled; 2345 }); 2346 choices.forEach(function (choice, index) { 2347 var _a = choice.value, 2348 value = _a === void 0 ? '' : _a, 2349 label = choice.label, 2350 customProperties = choice.customProperties, 2351 placeholder = choice.placeholder; 2352 2353 if (_this._isSelectElement) { 2354 // If the choice is actually a group 2355 if (choice.choices) { 2356 _this._addGroup({ 2357 group: choice, 2358 id: choice.id || null 2359 }); 2360 } else { 2361 /** 2362 * If there is a selected choice already or the choice is not the first in 2363 * the array, add each choice normally. 2364 * 2365 * Otherwise we pre-select the first enabled choice in the array ("select-one" only) 2366 */ 2367 var shouldPreselect = _this._isSelectOneElement && !hasSelectedChoice && index === firstEnabledChoiceIndex; 2368 var isSelected = shouldPreselect ? true : choice.selected; 2369 var isDisabled = choice.disabled; 2370 2371 _this._addChoice({ 2372 value: value, 2373 label: label, 2374 isSelected: !!isSelected, 2375 isDisabled: !!isDisabled, 2376 placeholder: !!placeholder, 2377 customProperties: customProperties 2378 }); 2379 } 2380 } else { 2381 _this._addChoice({ 2382 value: value, 2383 label: label, 2384 isSelected: !!choice.selected, 2385 isDisabled: !!choice.disabled, 2386 placeholder: !!choice.placeholder, 2387 customProperties: customProperties 2388 }); 2389 } 2390 }); 2391 }; 2392 2393 Choices.prototype._addPredefinedItems = function (items) { 2394 var _this = this; 2395 2396 items.forEach(function (item) { 2397 if (typeof item === 'object' && item.value) { 2398 _this._addItem({ 2399 value: item.value, 2400 label: item.label, 2401 choiceId: item.id, 2402 customProperties: item.customProperties, 2403 placeholder: item.placeholder 2404 }); 2405 } 2406 2407 if (typeof item === 'string') { 2408 _this._addItem({ 2409 value: item 2410 }); 2411 } 2412 }); 2413 }; 2414 2415 Choices.prototype._setChoiceOrItem = function (item) { 2416 var _this = this; 2417 2418 var itemType = (0, utils_1.getType)(item).toLowerCase(); 2419 var handleType = { 2420 object: function () { 2421 if (!item.value) { 2422 return; 2423 } // If we are dealing with a select input, we need to create an option first 2424 // that is then selected. For text inputs we can just add items normally. 2425 2426 2427 if (!_this._isTextElement) { 2428 _this._addChoice({ 2429 value: item.value, 2430 label: item.label, 2431 isSelected: true, 2432 isDisabled: false, 2433 customProperties: item.customProperties, 2434 placeholder: item.placeholder 2435 }); 2436 } else { 2437 _this._addItem({ 2438 value: item.value, 2439 label: item.label, 2440 choiceId: item.id, 2441 customProperties: item.customProperties, 2442 placeholder: item.placeholder 2443 }); 2444 } 2445 }, 2446 string: function () { 2447 if (!_this._isTextElement) { 2448 _this._addChoice({ 2449 value: item, 2450 label: item, 2451 isSelected: true, 2452 isDisabled: false 2453 }); 2454 } else { 2455 _this._addItem({ 2456 value: item 2457 }); 2458 } 2459 } 2460 }; 2461 handleType[itemType](); 2462 }; 2463 2464 Choices.prototype._findAndSelectChoiceByValue = function (value) { 2465 var _this = this; 2466 2467 var choices = this._store.choices; // Check 'value' property exists and the choice isn't already selected 2468 2469 var foundChoice = choices.find(function (choice) { 2470 return _this.config.valueComparer(choice.value, value); 2471 }); 2472 2473 if (foundChoice && !foundChoice.selected) { 2474 this._addItem({ 2475 value: foundChoice.value, 2476 label: foundChoice.label, 2477 choiceId: foundChoice.id, 2478 groupId: foundChoice.groupId, 2479 customProperties: foundChoice.customProperties, 2480 placeholder: foundChoice.placeholder, 2481 keyCode: foundChoice.keyCode 2482 }); 2483 } 2484 }; 2485 2486 Choices.prototype._generatePlaceholderValue = function () { 2487 if (this._isSelectElement && this.passedElement.placeholderOption) { 2488 var placeholderOption = this.passedElement.placeholderOption; 2489 return placeholderOption ? placeholderOption.text : null; 2490 } 2491 2492 var _a = this.config, 2493 placeholder = _a.placeholder, 2494 placeholderValue = _a.placeholderValue; 2495 var dataset = this.passedElement.element.dataset; 2496 2497 if (placeholder) { 2498 if (placeholderValue) { 2499 return placeholderValue; 2500 } 2501 2502 if (dataset.placeholder) { 2503 return dataset.placeholder; 2504 } 2505 } 2506 2507 return null; 2508 }; 2509 2510 return Choices; 2511 }(); 2512 2513 exports["default"] = Choices; 2514 2515 /***/ }), 2516 2517 /***/ 613: 2518 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 2519 2520 "use strict"; 2521 2522 2523 Object.defineProperty(exports, "__esModule", ({ 2524 value: true 2525 })); 2526 2527 var utils_1 = __webpack_require__(799); 2528 2529 var constants_1 = __webpack_require__(883); 2530 2531 var Container = 2532 /** @class */ 2533 function () { 2534 function Container(_a) { 2535 var element = _a.element, 2536 type = _a.type, 2537 classNames = _a.classNames, 2538 position = _a.position; 2539 this.element = element; 2540 this.classNames = classNames; 2541 this.type = type; 2542 this.position = position; 2543 this.isOpen = false; 2544 this.isFlipped = false; 2545 this.isFocussed = false; 2546 this.isDisabled = false; 2547 this.isLoading = false; 2548 this._onFocus = this._onFocus.bind(this); 2549 this._onBlur = this._onBlur.bind(this); 2550 } 2551 2552 Container.prototype.addEventListeners = function () { 2553 this.element.addEventListener('focus', this._onFocus); 2554 this.element.addEventListener('blur', this._onBlur); 2555 }; 2556 2557 Container.prototype.removeEventListeners = function () { 2558 this.element.removeEventListener('focus', this._onFocus); 2559 this.element.removeEventListener('blur', this._onBlur); 2560 }; 2561 /** 2562 * Determine whether container should be flipped based on passed 2563 * dropdown position 2564 */ 2565 2566 2567 Container.prototype.shouldFlip = function (dropdownPos) { 2568 if (typeof dropdownPos !== 'number') { 2569 return false; 2570 } // If flip is enabled and the dropdown bottom position is 2571 // greater than the window height flip the dropdown. 2572 2573 2574 var shouldFlip = false; 2575 2576 if (this.position === 'auto') { 2577 shouldFlip = !window.matchMedia("(min-height: ".concat(dropdownPos + 1, "px)")).matches; 2578 } else if (this.position === 'top') { 2579 shouldFlip = true; 2580 } 2581 2582 return shouldFlip; 2583 }; 2584 2585 Container.prototype.setActiveDescendant = function (activeDescendantID) { 2586 this.element.setAttribute('aria-activedescendant', activeDescendantID); 2587 }; 2588 2589 Container.prototype.removeActiveDescendant = function () { 2590 this.element.removeAttribute('aria-activedescendant'); 2591 }; 2592 2593 Container.prototype.open = function (dropdownPos) { 2594 this.element.classList.add(this.classNames.openState); 2595 this.element.setAttribute('aria-expanded', 'true'); 2596 this.isOpen = true; 2597 2598 if (this.shouldFlip(dropdownPos)) { 2599 this.element.classList.add(this.classNames.flippedState); 2600 this.isFlipped = true; 2601 } 2602 }; 2603 2604 Container.prototype.close = function () { 2605 this.element.classList.remove(this.classNames.openState); 2606 this.element.setAttribute('aria-expanded', 'false'); 2607 this.removeActiveDescendant(); 2608 this.isOpen = false; // A dropdown flips if it does not have space within the page 2609 2610 if (this.isFlipped) { 2611 this.element.classList.remove(this.classNames.flippedState); 2612 this.isFlipped = false; 2613 } 2614 }; 2615 2616 Container.prototype.focus = function () { 2617 if (!this.isFocussed) { 2618 this.element.focus(); 2619 } 2620 }; 2621 2622 Container.prototype.addFocusState = function () { 2623 this.element.classList.add(this.classNames.focusState); 2624 }; 2625 2626 Container.prototype.removeFocusState = function () { 2627 this.element.classList.remove(this.classNames.focusState); 2628 }; 2629 2630 Container.prototype.enable = function () { 2631 this.element.classList.remove(this.classNames.disabledState); 2632 this.element.removeAttribute('aria-disabled'); 2633 2634 if (this.type === constants_1.SELECT_ONE_TYPE) { 2635 this.element.setAttribute('tabindex', '0'); 2636 } 2637 2638 this.isDisabled = false; 2639 }; 2640 2641 Container.prototype.disable = function () { 2642 this.element.classList.add(this.classNames.disabledState); 2643 this.element.setAttribute('aria-disabled', 'true'); 2644 2645 if (this.type === constants_1.SELECT_ONE_TYPE) { 2646 this.element.setAttribute('tabindex', '-1'); 2647 } 2648 2649 this.isDisabled = true; 2650 }; 2651 2652 Container.prototype.wrap = function (element) { 2653 (0, utils_1.wrap)(element, this.element); 2654 }; 2655 2656 Container.prototype.unwrap = function (element) { 2657 if (this.element.parentNode) { 2658 // Move passed element outside this element 2659 this.element.parentNode.insertBefore(element, this.element); // Remove this element 2660 2661 this.element.parentNode.removeChild(this.element); 2662 } 2663 }; 2664 2665 Container.prototype.addLoadingState = function () { 2666 this.element.classList.add(this.classNames.loadingState); 2667 this.element.setAttribute('aria-busy', 'true'); 2668 this.isLoading = true; 2669 }; 2670 2671 Container.prototype.removeLoadingState = function () { 2672 this.element.classList.remove(this.classNames.loadingState); 2673 this.element.removeAttribute('aria-busy'); 2674 this.isLoading = false; 2675 }; 2676 2677 Container.prototype._onFocus = function () { 2678 this.isFocussed = true; 2679 }; 2680 2681 Container.prototype._onBlur = function () { 2682 this.isFocussed = false; 2683 }; 2684 2685 return Container; 2686 }(); 2687 2688 exports["default"] = Container; 2689 2690 /***/ }), 2691 2692 /***/ 217: 2693 /***/ (function(__unused_webpack_module, exports) { 2694 2695 "use strict"; 2696 2697 2698 Object.defineProperty(exports, "__esModule", ({ 2699 value: true 2700 })); 2701 2702 var Dropdown = 2703 /** @class */ 2704 function () { 2705 function Dropdown(_a) { 2706 var element = _a.element, 2707 type = _a.type, 2708 classNames = _a.classNames; 2709 this.element = element; 2710 this.classNames = classNames; 2711 this.type = type; 2712 this.isActive = false; 2713 } 2714 2715 Object.defineProperty(Dropdown.prototype, "distanceFromTopWindow", { 2716 /** 2717 * Bottom position of dropdown in viewport coordinates 2718 */ 2719 get: function () { 2720 return this.element.getBoundingClientRect().bottom; 2721 }, 2722 enumerable: false, 2723 configurable: true 2724 }); 2725 2726 Dropdown.prototype.getChild = function (selector) { 2727 return this.element.querySelector(selector); 2728 }; 2729 /** 2730 * Show dropdown to user by adding active state class 2731 */ 2732 2733 2734 Dropdown.prototype.show = function () { 2735 this.element.classList.add(this.classNames.activeState); 2736 this.element.setAttribute('aria-expanded', 'true'); 2737 this.isActive = true; 2738 return this; 2739 }; 2740 /** 2741 * Hide dropdown from user 2742 */ 2743 2744 2745 Dropdown.prototype.hide = function () { 2746 this.element.classList.remove(this.classNames.activeState); 2747 this.element.setAttribute('aria-expanded', 'false'); 2748 this.isActive = false; 2749 return this; 2750 }; 2751 2752 return Dropdown; 2753 }(); 2754 2755 exports["default"] = Dropdown; 2756 2757 /***/ }), 2758 2759 /***/ 520: 2760 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 2761 2762 "use strict"; 2763 2764 2765 var __importDefault = this && this.__importDefault || function (mod) { 2766 return mod && mod.__esModule ? mod : { 2767 "default": mod 2768 }; 2769 }; 2770 2771 Object.defineProperty(exports, "__esModule", ({ 2772 value: true 2773 })); 2774 exports.WrappedSelect = exports.WrappedInput = exports.List = exports.Input = exports.Container = exports.Dropdown = void 0; 2775 2776 var dropdown_1 = __importDefault(__webpack_require__(217)); 2777 2778 exports.Dropdown = dropdown_1.default; 2779 2780 var container_1 = __importDefault(__webpack_require__(613)); 2781 2782 exports.Container = container_1.default; 2783 2784 var input_1 = __importDefault(__webpack_require__(11)); 2785 2786 exports.Input = input_1.default; 2787 2788 var list_1 = __importDefault(__webpack_require__(624)); 2789 2790 exports.List = list_1.default; 2791 2792 var wrapped_input_1 = __importDefault(__webpack_require__(541)); 2793 2794 exports.WrappedInput = wrapped_input_1.default; 2795 2796 var wrapped_select_1 = __importDefault(__webpack_require__(982)); 2797 2798 exports.WrappedSelect = wrapped_select_1.default; 2799 2800 /***/ }), 2801 2802 /***/ 11: 2803 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 2804 2805 "use strict"; 2806 2807 2808 Object.defineProperty(exports, "__esModule", ({ 2809 value: true 2810 })); 2811 2812 var utils_1 = __webpack_require__(799); 2813 2814 var constants_1 = __webpack_require__(883); 2815 2816 var Input = 2817 /** @class */ 2818 function () { 2819 function Input(_a) { 2820 var element = _a.element, 2821 type = _a.type, 2822 classNames = _a.classNames, 2823 preventPaste = _a.preventPaste; 2824 this.element = element; 2825 this.type = type; 2826 this.classNames = classNames; 2827 this.preventPaste = preventPaste; 2828 this.isFocussed = this.element.isEqualNode(document.activeElement); 2829 this.isDisabled = element.disabled; 2830 this._onPaste = this._onPaste.bind(this); 2831 this._onInput = this._onInput.bind(this); 2832 this._onFocus = this._onFocus.bind(this); 2833 this._onBlur = this._onBlur.bind(this); 2834 } 2835 2836 Object.defineProperty(Input.prototype, "placeholder", { 2837 set: function (placeholder) { 2838 this.element.placeholder = placeholder; 2839 }, 2840 enumerable: false, 2841 configurable: true 2842 }); 2843 Object.defineProperty(Input.prototype, "value", { 2844 get: function () { 2845 return (0, utils_1.sanitise)(this.element.value); 2846 }, 2847 set: function (value) { 2848 this.element.value = value; 2849 }, 2850 enumerable: false, 2851 configurable: true 2852 }); 2853 2854 Input.prototype.addEventListeners = function () { 2855 this.element.addEventListener('paste', this._onPaste); 2856 this.element.addEventListener('input', this._onInput, { 2857 passive: true 2858 }); 2859 this.element.addEventListener('focus', this._onFocus, { 2860 passive: true 2861 }); 2862 this.element.addEventListener('blur', this._onBlur, { 2863 passive: true 2864 }); 2865 }; 2866 2867 Input.prototype.removeEventListeners = function () { 2868 this.element.removeEventListener('input', this._onInput); 2869 this.element.removeEventListener('paste', this._onPaste); 2870 this.element.removeEventListener('focus', this._onFocus); 2871 this.element.removeEventListener('blur', this._onBlur); 2872 }; 2873 2874 Input.prototype.enable = function () { 2875 this.element.removeAttribute('disabled'); 2876 this.isDisabled = false; 2877 }; 2878 2879 Input.prototype.disable = function () { 2880 this.element.setAttribute('disabled', ''); 2881 this.isDisabled = true; 2882 }; 2883 2884 Input.prototype.focus = function () { 2885 if (!this.isFocussed) { 2886 this.element.focus(); 2887 } 2888 }; 2889 2890 Input.prototype.blur = function () { 2891 if (this.isFocussed) { 2892 this.element.blur(); 2893 } 2894 }; 2895 2896 Input.prototype.clear = function (setWidth) { 2897 if (setWidth === void 0) { 2898 setWidth = true; 2899 } 2900 2901 if (this.element.value) { 2902 this.element.value = ''; 2903 } 2904 2905 if (setWidth) { 2906 this.setWidth(); 2907 } 2908 2909 return this; 2910 }; 2911 /** 2912 * Set the correct input width based on placeholder 2913 * value or input value 2914 */ 2915 2916 2917 Input.prototype.setWidth = function () { 2918 // Resize input to contents or placeholder 2919 var _a = this.element, 2920 style = _a.style, 2921 value = _a.value, 2922 placeholder = _a.placeholder; 2923 style.minWidth = "".concat(placeholder.length + 1, "ch"); 2924 style.width = "".concat(value.length + 1, "ch"); 2925 }; 2926 2927 Input.prototype.setActiveDescendant = function (activeDescendantID) { 2928 this.element.setAttribute('aria-activedescendant', activeDescendantID); 2929 }; 2930 2931 Input.prototype.removeActiveDescendant = function () { 2932 this.element.removeAttribute('aria-activedescendant'); 2933 }; 2934 2935 Input.prototype._onInput = function () { 2936 if (this.type !== constants_1.SELECT_ONE_TYPE) { 2937 this.setWidth(); 2938 } 2939 }; 2940 2941 Input.prototype._onPaste = function (event) { 2942 if (this.preventPaste) { 2943 event.preventDefault(); 2944 } 2945 }; 2946 2947 Input.prototype._onFocus = function () { 2948 this.isFocussed = true; 2949 }; 2950 2951 Input.prototype._onBlur = function () { 2952 this.isFocussed = false; 2953 }; 2954 2955 return Input; 2956 }(); 2957 2958 exports["default"] = Input; 2959 2960 /***/ }), 2961 2962 /***/ 624: 2963 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 2964 2965 "use strict"; 2966 2967 2968 Object.defineProperty(exports, "__esModule", ({ 2969 value: true 2970 })); 2971 2972 var constants_1 = __webpack_require__(883); 2973 2974 var List = 2975 /** @class */ 2976 function () { 2977 function List(_a) { 2978 var element = _a.element; 2979 this.element = element; 2980 this.scrollPos = this.element.scrollTop; 2981 this.height = this.element.offsetHeight; 2982 } 2983 2984 List.prototype.clear = function () { 2985 this.element.innerHTML = ''; 2986 }; 2987 2988 List.prototype.append = function (node) { 2989 this.element.appendChild(node); 2990 }; 2991 2992 List.prototype.getChild = function (selector) { 2993 return this.element.querySelector(selector); 2994 }; 2995 2996 List.prototype.hasChildren = function () { 2997 return this.element.hasChildNodes(); 2998 }; 2999 3000 List.prototype.scrollToTop = function () { 3001 this.element.scrollTop = 0; 3002 }; 3003 3004 List.prototype.scrollToChildElement = function (element, direction) { 3005 var _this = this; 3006 3007 if (!element) { 3008 return; 3009 } 3010 3011 var listHeight = this.element.offsetHeight; // Scroll position of dropdown 3012 3013 var listScrollPosition = this.element.scrollTop + listHeight; 3014 var elementHeight = element.offsetHeight; // Distance from bottom of element to top of parent 3015 3016 var elementPos = element.offsetTop + elementHeight; // Difference between the element and scroll position 3017 3018 var destination = direction > 0 ? this.element.scrollTop + elementPos - listScrollPosition : element.offsetTop; 3019 requestAnimationFrame(function () { 3020 _this._animateScroll(destination, direction); 3021 }); 3022 }; 3023 3024 List.prototype._scrollDown = function (scrollPos, strength, destination) { 3025 var easing = (destination - scrollPos) / strength; 3026 var distance = easing > 1 ? easing : 1; 3027 this.element.scrollTop = scrollPos + distance; 3028 }; 3029 3030 List.prototype._scrollUp = function (scrollPos, strength, destination) { 3031 var easing = (scrollPos - destination) / strength; 3032 var distance = easing > 1 ? easing : 1; 3033 this.element.scrollTop = scrollPos - distance; 3034 }; 3035 3036 List.prototype._animateScroll = function (destination, direction) { 3037 var _this = this; 3038 3039 var strength = constants_1.SCROLLING_SPEED; 3040 var choiceListScrollTop = this.element.scrollTop; 3041 var continueAnimation = false; 3042 3043 if (direction > 0) { 3044 this._scrollDown(choiceListScrollTop, strength, destination); 3045 3046 if (choiceListScrollTop < destination) { 3047 continueAnimation = true; 3048 } 3049 } else { 3050 this._scrollUp(choiceListScrollTop, strength, destination); 3051 3052 if (choiceListScrollTop > destination) { 3053 continueAnimation = true; 3054 } 3055 } 3056 3057 if (continueAnimation) { 3058 requestAnimationFrame(function () { 3059 _this._animateScroll(destination, direction); 3060 }); 3061 } 3062 }; 3063 3064 return List; 3065 }(); 3066 3067 exports["default"] = List; 3068 3069 /***/ }), 3070 3071 /***/ 730: 3072 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 3073 3074 "use strict"; 3075 3076 3077 Object.defineProperty(exports, "__esModule", ({ 3078 value: true 3079 })); 3080 3081 var utils_1 = __webpack_require__(799); 3082 3083 var WrappedElement = 3084 /** @class */ 3085 function () { 3086 function WrappedElement(_a) { 3087 var element = _a.element, 3088 classNames = _a.classNames; 3089 this.element = element; 3090 this.classNames = classNames; 3091 3092 if (!(element instanceof HTMLInputElement) && !(element instanceof HTMLSelectElement)) { 3093 throw new TypeError('Invalid element passed'); 3094 } 3095 3096 this.isDisabled = false; 3097 } 3098 3099 Object.defineProperty(WrappedElement.prototype, "isActive", { 3100 get: function () { 3101 return this.element.dataset.choice === 'active'; 3102 }, 3103 enumerable: false, 3104 configurable: true 3105 }); 3106 Object.defineProperty(WrappedElement.prototype, "dir", { 3107 get: function () { 3108 return this.element.dir; 3109 }, 3110 enumerable: false, 3111 configurable: true 3112 }); 3113 Object.defineProperty(WrappedElement.prototype, "value", { 3114 get: function () { 3115 return this.element.value; 3116 }, 3117 set: function (value) { 3118 // you must define setter here otherwise it will be readonly property 3119 this.element.value = value; 3120 }, 3121 enumerable: false, 3122 configurable: true 3123 }); 3124 3125 WrappedElement.prototype.conceal = function () { 3126 // Hide passed input 3127 this.element.classList.add(this.classNames.input); 3128 this.element.hidden = true; // Remove element from tab index 3129 3130 this.element.tabIndex = -1; // Backup original styles if any 3131 3132 var origStyle = this.element.getAttribute('style'); 3133 3134 if (origStyle) { 3135 this.element.setAttribute('data-choice-orig-style', origStyle); 3136 } 3137 3138 this.element.setAttribute('data-choice', 'active'); 3139 }; 3140 3141 WrappedElement.prototype.reveal = function () { 3142 // Reinstate passed element 3143 this.element.classList.remove(this.classNames.input); 3144 this.element.hidden = false; 3145 this.element.removeAttribute('tabindex'); // Recover original styles if any 3146 3147 var origStyle = this.element.getAttribute('data-choice-orig-style'); 3148 3149 if (origStyle) { 3150 this.element.removeAttribute('data-choice-orig-style'); 3151 this.element.setAttribute('style', origStyle); 3152 } else { 3153 this.element.removeAttribute('style'); 3154 } 3155 3156 this.element.removeAttribute('data-choice'); // Re-assign values - this is weird, I know 3157 // @todo Figure out why we need to do this 3158 3159 this.element.value = this.element.value; // eslint-disable-line no-self-assign 3160 }; 3161 3162 WrappedElement.prototype.enable = function () { 3163 this.element.removeAttribute('disabled'); 3164 this.element.disabled = false; 3165 this.isDisabled = false; 3166 }; 3167 3168 WrappedElement.prototype.disable = function () { 3169 this.element.setAttribute('disabled', ''); 3170 this.element.disabled = true; 3171 this.isDisabled = true; 3172 }; 3173 3174 WrappedElement.prototype.triggerEvent = function (eventType, data) { 3175 (0, utils_1.dispatchEvent)(this.element, eventType, data); 3176 }; 3177 3178 return WrappedElement; 3179 }(); 3180 3181 exports["default"] = WrappedElement; 3182 3183 /***/ }), 3184 3185 /***/ 541: 3186 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 3187 3188 "use strict"; 3189 3190 3191 var __extends = this && this.__extends || function () { 3192 var extendStatics = function (d, b) { 3193 extendStatics = Object.setPrototypeOf || { 3194 __proto__: [] 3195 } instanceof Array && function (d, b) { 3196 d.__proto__ = b; 3197 } || function (d, b) { 3198 for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; 3199 }; 3200 3201 return extendStatics(d, b); 3202 }; 3203 3204 return function (d, b) { 3205 if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 3206 extendStatics(d, b); 3207 3208 function __() { 3209 this.constructor = d; 3210 } 3211 3212 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 3213 }; 3214 }(); 3215 3216 var __importDefault = this && this.__importDefault || function (mod) { 3217 return mod && mod.__esModule ? mod : { 3218 "default": mod 3219 }; 3220 }; 3221 3222 Object.defineProperty(exports, "__esModule", ({ 3223 value: true 3224 })); 3225 3226 var wrapped_element_1 = __importDefault(__webpack_require__(730)); 3227 3228 var WrappedInput = 3229 /** @class */ 3230 function (_super) { 3231 __extends(WrappedInput, _super); 3232 3233 function WrappedInput(_a) { 3234 var element = _a.element, 3235 classNames = _a.classNames, 3236 delimiter = _a.delimiter; 3237 3238 var _this = _super.call(this, { 3239 element: element, 3240 classNames: classNames 3241 }) || this; 3242 3243 _this.delimiter = delimiter; 3244 return _this; 3245 } 3246 3247 Object.defineProperty(WrappedInput.prototype, "value", { 3248 get: function () { 3249 return this.element.value; 3250 }, 3251 set: function (value) { 3252 this.element.setAttribute('value', value); 3253 this.element.value = value; 3254 }, 3255 enumerable: false, 3256 configurable: true 3257 }); 3258 return WrappedInput; 3259 }(wrapped_element_1.default); 3260 3261 exports["default"] = WrappedInput; 3262 3263 /***/ }), 3264 3265 /***/ 982: 3266 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 3267 3268 "use strict"; 3269 3270 3271 var __extends = this && this.__extends || function () { 3272 var extendStatics = function (d, b) { 3273 extendStatics = Object.setPrototypeOf || { 3274 __proto__: [] 3275 } instanceof Array && function (d, b) { 3276 d.__proto__ = b; 3277 } || function (d, b) { 3278 for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; 3279 }; 3280 3281 return extendStatics(d, b); 3282 }; 3283 3284 return function (d, b) { 3285 if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 3286 extendStatics(d, b); 3287 3288 function __() { 3289 this.constructor = d; 3290 } 3291 3292 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 3293 }; 3294 }(); 3295 3296 var __importDefault = this && this.__importDefault || function (mod) { 3297 return mod && mod.__esModule ? mod : { 3298 "default": mod 3299 }; 3300 }; 3301 3302 Object.defineProperty(exports, "__esModule", ({ 3303 value: true 3304 })); 3305 3306 var wrapped_element_1 = __importDefault(__webpack_require__(730)); 3307 3308 var WrappedSelect = 3309 /** @class */ 3310 function (_super) { 3311 __extends(WrappedSelect, _super); 3312 3313 function WrappedSelect(_a) { 3314 var element = _a.element, 3315 classNames = _a.classNames, 3316 template = _a.template; 3317 3318 var _this = _super.call(this, { 3319 element: element, 3320 classNames: classNames 3321 }) || this; 3322 3323 _this.template = template; 3324 return _this; 3325 } 3326 3327 Object.defineProperty(WrappedSelect.prototype, "placeholderOption", { 3328 get: function () { 3329 return this.element.querySelector('option[value=""]') || // Backward compatibility layer for the non-standard placeholder attribute supported in older versions. 3330 this.element.querySelector('option[placeholder]'); 3331 }, 3332 enumerable: false, 3333 configurable: true 3334 }); 3335 Object.defineProperty(WrappedSelect.prototype, "optionGroups", { 3336 get: function () { 3337 return Array.from(this.element.getElementsByTagName('OPTGROUP')); 3338 }, 3339 enumerable: false, 3340 configurable: true 3341 }); 3342 Object.defineProperty(WrappedSelect.prototype, "options", { 3343 get: function () { 3344 return Array.from(this.element.options); 3345 }, 3346 set: function (options) { 3347 var _this = this; 3348 3349 var fragment = document.createDocumentFragment(); 3350 3351 var addOptionToFragment = function (data) { 3352 // Create a standard select option 3353 var option = _this.template(data); // Append it to fragment 3354 3355 3356 fragment.appendChild(option); 3357 }; // Add each list item to list 3358 3359 3360 options.forEach(function (optionData) { 3361 return addOptionToFragment(optionData); 3362 }); 3363 this.appendDocFragment(fragment); 3364 }, 3365 enumerable: false, 3366 configurable: true 3367 }); 3368 3369 WrappedSelect.prototype.appendDocFragment = function (fragment) { 3370 this.element.innerHTML = ''; 3371 this.element.appendChild(fragment); 3372 }; 3373 3374 return WrappedSelect; 3375 }(wrapped_element_1.default); 3376 3377 exports["default"] = WrappedSelect; 3378 3379 /***/ }), 3380 3381 /***/ 883: 3382 /***/ (function(__unused_webpack_module, exports) { 3383 3384 "use strict"; 3385 3386 3387 Object.defineProperty(exports, "__esModule", ({ 3388 value: true 3389 })); 3390 exports.SCROLLING_SPEED = exports.SELECT_MULTIPLE_TYPE = exports.SELECT_ONE_TYPE = exports.TEXT_TYPE = exports.KEY_CODES = exports.ACTION_TYPES = exports.EVENTS = void 0; 3391 exports.EVENTS = { 3392 showDropdown: 'showDropdown', 3393 hideDropdown: 'hideDropdown', 3394 change: 'change', 3395 choice: 'choice', 3396 search: 'search', 3397 addItem: 'addItem', 3398 removeItem: 'removeItem', 3399 highlightItem: 'highlightItem', 3400 highlightChoice: 'highlightChoice', 3401 unhighlightItem: 'unhighlightItem' 3402 }; 3403 exports.ACTION_TYPES = { 3404 ADD_CHOICE: 'ADD_CHOICE', 3405 FILTER_CHOICES: 'FILTER_CHOICES', 3406 ACTIVATE_CHOICES: 'ACTIVATE_CHOICES', 3407 CLEAR_CHOICES: 'CLEAR_CHOICES', 3408 ADD_GROUP: 'ADD_GROUP', 3409 ADD_ITEM: 'ADD_ITEM', 3410 REMOVE_ITEM: 'REMOVE_ITEM', 3411 HIGHLIGHT_ITEM: 'HIGHLIGHT_ITEM', 3412 CLEAR_ALL: 'CLEAR_ALL', 3413 RESET_TO: 'RESET_TO', 3414 SET_IS_LOADING: 'SET_IS_LOADING' 3415 }; 3416 exports.KEY_CODES = { 3417 BACK_KEY: 46, 3418 DELETE_KEY: 8, 3419 ENTER_KEY: 13, 3420 A_KEY: 65, 3421 ESC_KEY: 27, 3422 UP_KEY: 38, 3423 DOWN_KEY: 40, 3424 PAGE_UP_KEY: 33, 3425 PAGE_DOWN_KEY: 34 3426 }; 3427 exports.TEXT_TYPE = 'text'; 3428 exports.SELECT_ONE_TYPE = 'select-one'; 3429 exports.SELECT_MULTIPLE_TYPE = 'select-multiple'; 3430 exports.SCROLLING_SPEED = 4; 3431 3432 /***/ }), 3433 3434 /***/ 789: 3435 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 3436 3437 "use strict"; 3438 3439 3440 Object.defineProperty(exports, "__esModule", ({ 3441 value: true 3442 })); 3443 exports.DEFAULT_CONFIG = exports.DEFAULT_CLASSNAMES = void 0; 3444 3445 var utils_1 = __webpack_require__(799); 3446 3447 exports.DEFAULT_CLASSNAMES = { 3448 containerOuter: 'choices', 3449 containerInner: 'choices__inner', 3450 input: 'choices__input', 3451 inputCloned: 'choices__input--cloned', 3452 list: 'choices__list', 3453 listItems: 'choices__list--multiple', 3454 listSingle: 'choices__list--single', 3455 listDropdown: 'choices__list--dropdown', 3456 item: 'choices__item', 3457 itemSelectable: 'choices__item--selectable', 3458 itemDisabled: 'choices__item--disabled', 3459 itemChoice: 'choices__item--choice', 3460 placeholder: 'choices__placeholder', 3461 group: 'choices__group', 3462 groupHeading: 'choices__heading', 3463 button: 'choices__button', 3464 activeState: 'is-active', 3465 focusState: 'is-focused', 3466 openState: 'is-open', 3467 disabledState: 'is-disabled', 3468 highlightedState: 'is-highlighted', 3469 selectedState: 'is-selected', 3470 flippedState: 'is-flipped', 3471 loadingState: 'is-loading', 3472 noResults: 'has-no-results', 3473 noChoices: 'has-no-choices' 3474 }; 3475 exports.DEFAULT_CONFIG = { 3476 items: [], 3477 choices: [], 3478 silent: false, 3479 renderChoiceLimit: -1, 3480 maxItemCount: -1, 3481 addItems: true, 3482 addItemFilter: null, 3483 removeItems: true, 3484 removeItemButton: false, 3485 editItems: false, 3486 duplicateItemsAllowed: true, 3487 delimiter: ',', 3488 paste: true, 3489 searchEnabled: true, 3490 searchChoices: true, 3491 searchFloor: 1, 3492 searchResultLimit: 4, 3493 searchFields: ['label', 'value'], 3494 position: 'auto', 3495 resetScrollPosition: true, 3496 shouldSort: true, 3497 shouldSortItems: false, 3498 sorter: utils_1.sortByAlpha, 3499 placeholder: true, 3500 placeholderValue: null, 3501 searchPlaceholderValue: null, 3502 prependValue: null, 3503 appendValue: null, 3504 renderSelectedChoices: 'auto', 3505 loadingText: 'Loading...', 3506 noResultsText: 'No results found', 3507 noChoicesText: 'No choices to choose from', 3508 itemSelectText: 'Press to select', 3509 uniqueItemText: 'Only unique values can be added', 3510 customAddItemText: 'Only values matching specific conditions can be added', 3511 addItemText: function (value) { 3512 return "Press Enter to add <b>\"".concat((0, utils_1.sanitise)(value), "\"</b>"); 3513 }, 3514 maxItemText: function (maxItemCount) { 3515 return "Only ".concat(maxItemCount, " values can be added"); 3516 }, 3517 valueComparer: function (value1, value2) { 3518 return value1 === value2; 3519 }, 3520 fuseOptions: { 3521 includeScore: true 3522 }, 3523 callbackOnInit: null, 3524 callbackOnCreateTemplates: null, 3525 classNames: exports.DEFAULT_CLASSNAMES 3526 }; 3527 3528 /***/ }), 3529 3530 /***/ 799: 3531 /***/ (function(__unused_webpack_module, exports) { 3532 3533 "use strict"; 3534 3535 /* eslint-disable @typescript-eslint/no-explicit-any */ 3536 3537 Object.defineProperty(exports, "__esModule", ({ 3538 value: true 3539 })); 3540 exports.diff = exports.cloneObject = exports.existsInArray = exports.dispatchEvent = exports.sortByScore = exports.sortByAlpha = exports.strToEl = exports.sanitise = exports.isScrolledIntoView = exports.getAdjacentEl = exports.wrap = exports.isType = exports.getType = exports.generateId = exports.generateChars = exports.getRandomNumber = void 0; 3541 3542 var getRandomNumber = function (min, max) { 3543 return Math.floor(Math.random() * (max - min) + min); 3544 }; 3545 3546 exports.getRandomNumber = getRandomNumber; 3547 3548 var generateChars = function (length) { 3549 return Array.from({ 3550 length: length 3551 }, function () { 3552 return (0, exports.getRandomNumber)(0, 36).toString(36); 3553 }).join(''); 3554 }; 3555 3556 exports.generateChars = generateChars; 3557 3558 var generateId = function (element, prefix) { 3559 var id = element.id || element.name && "".concat(element.name, "-").concat((0, exports.generateChars)(2)) || (0, exports.generateChars)(4); 3560 id = id.replace(/(:|\.|\[|\]|,)/g, ''); 3561 id = "".concat(prefix, "-").concat(id); 3562 return id; 3563 }; 3564 3565 exports.generateId = generateId; 3566 3567 var getType = function (obj) { 3568 return Object.prototype.toString.call(obj).slice(8, -1); 3569 }; 3570 3571 exports.getType = getType; 3572 3573 var isType = function (type, obj) { 3574 return obj !== undefined && obj !== null && (0, exports.getType)(obj) === type; 3575 }; 3576 3577 exports.isType = isType; 3578 3579 var wrap = function (element, wrapper) { 3580 if (wrapper === void 0) { 3581 wrapper = document.createElement('div'); 3582 } 3583 3584 if (element.parentNode) { 3585 if (element.nextSibling) { 3586 element.parentNode.insertBefore(wrapper, element.nextSibling); 3587 } else { 3588 element.parentNode.appendChild(wrapper); 3589 } 3590 } 3591 3592 return wrapper.appendChild(element); 3593 }; 3594 3595 exports.wrap = wrap; 3596 3597 var getAdjacentEl = function (startEl, selector, direction) { 3598 if (direction === void 0) { 3599 direction = 1; 3600 } 3601 3602 var prop = "".concat(direction > 0 ? 'next' : 'previous', "ElementSibling"); 3603 var sibling = startEl[prop]; 3604 3605 while (sibling) { 3606 if (sibling.matches(selector)) { 3607 return sibling; 3608 } 3609 3610 sibling = sibling[prop]; 3611 } 3612 3613 return sibling; 3614 }; 3615 3616 exports.getAdjacentEl = getAdjacentEl; 3617 3618 var isScrolledIntoView = function (element, parent, direction) { 3619 if (direction === void 0) { 3620 direction = 1; 3621 } 3622 3623 if (!element) { 3624 return false; 3625 } 3626 3627 var isVisible; 3628 3629 if (direction > 0) { 3630 // In view from bottom 3631 isVisible = parent.scrollTop + parent.offsetHeight >= element.offsetTop + element.offsetHeight; 3632 } else { 3633 // In view from top 3634 isVisible = element.offsetTop >= parent.scrollTop; 3635 } 3636 3637 return isVisible; 3638 }; 3639 3640 exports.isScrolledIntoView = isScrolledIntoView; 3641 3642 var sanitise = function (value) { 3643 if (typeof value !== 'string') { 3644 return value; 3645 } 3646 3647 return value.replace(/&/g, '&').replace(/>/g, '&rt;').replace(/</g, '<').replace(/"/g, '"'); 3648 }; 3649 3650 exports.sanitise = sanitise; 3651 3652 exports.strToEl = function () { 3653 var tmpEl = document.createElement('div'); 3654 return function (str) { 3655 var cleanedInput = str.trim(); 3656 tmpEl.innerHTML = cleanedInput; 3657 var firldChild = tmpEl.children[0]; 3658 3659 while (tmpEl.firstChild) { 3660 tmpEl.removeChild(tmpEl.firstChild); 3661 } 3662 3663 return firldChild; 3664 }; 3665 }(); 3666 3667 var sortByAlpha = function (_a, _b) { 3668 var value = _a.value, 3669 _c = _a.label, 3670 label = _c === void 0 ? value : _c; 3671 var value2 = _b.value, 3672 _d = _b.label, 3673 label2 = _d === void 0 ? value2 : _d; 3674 return label.localeCompare(label2, [], { 3675 sensitivity: 'base', 3676 ignorePunctuation: true, 3677 numeric: true 3678 }); 3679 }; 3680 3681 exports.sortByAlpha = sortByAlpha; 3682 3683 var sortByScore = function (a, b) { 3684 var _a = a.score, 3685 scoreA = _a === void 0 ? 0 : _a; 3686 var _b = b.score, 3687 scoreB = _b === void 0 ? 0 : _b; 3688 return scoreA - scoreB; 3689 }; 3690 3691 exports.sortByScore = sortByScore; 3692 3693 var dispatchEvent = function (element, type, customArgs) { 3694 if (customArgs === void 0) { 3695 customArgs = null; 3696 } 3697 3698 var event = new CustomEvent(type, { 3699 detail: customArgs, 3700 bubbles: true, 3701 cancelable: true 3702 }); 3703 return element.dispatchEvent(event); 3704 }; 3705 3706 exports.dispatchEvent = dispatchEvent; 3707 3708 var existsInArray = function (array, value, key) { 3709 if (key === void 0) { 3710 key = 'value'; 3711 } 3712 3713 return array.some(function (item) { 3714 if (typeof value === 'string') { 3715 return item[key] === value.trim(); 3716 } 3717 3718 return item[key] === value; 3719 }); 3720 }; 3721 3722 exports.existsInArray = existsInArray; 3723 3724 var cloneObject = function (obj) { 3725 return JSON.parse(JSON.stringify(obj)); 3726 }; 3727 3728 exports.cloneObject = cloneObject; 3729 /** 3730 * Returns an array of keys present on the first but missing on the second object 3731 */ 3732 3733 var diff = function (a, b) { 3734 var aKeys = Object.keys(a).sort(); 3735 var bKeys = Object.keys(b).sort(); 3736 return aKeys.filter(function (i) { 3737 return bKeys.indexOf(i) < 0; 3738 }); 3739 }; 3740 3741 exports.diff = diff; 3742 3743 /***/ }), 3744 3745 /***/ 273: 3746 /***/ (function(__unused_webpack_module, exports) { 3747 3748 "use strict"; 3749 3750 3751 var __spreadArray = this && this.__spreadArray || function (to, from, pack) { 3752 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { 3753 if (ar || !(i in from)) { 3754 if (!ar) ar = Array.prototype.slice.call(from, 0, i); 3755 ar[i] = from[i]; 3756 } 3757 } 3758 return to.concat(ar || Array.prototype.slice.call(from)); 3759 }; 3760 3761 Object.defineProperty(exports, "__esModule", ({ 3762 value: true 3763 })); 3764 exports.defaultState = void 0; 3765 exports.defaultState = []; 3766 3767 function choices(state, action) { 3768 if (state === void 0) { 3769 state = exports.defaultState; 3770 } 3771 3772 if (action === void 0) { 3773 action = {}; 3774 } 3775 3776 switch (action.type) { 3777 case 'ADD_CHOICE': 3778 { 3779 var addChoiceAction = action; 3780 var choice = { 3781 id: addChoiceAction.id, 3782 elementId: addChoiceAction.elementId, 3783 groupId: addChoiceAction.groupId, 3784 value: addChoiceAction.value, 3785 label: addChoiceAction.label || addChoiceAction.value, 3786 disabled: addChoiceAction.disabled || false, 3787 selected: false, 3788 active: true, 3789 score: 9999, 3790 customProperties: addChoiceAction.customProperties, 3791 placeholder: addChoiceAction.placeholder || false 3792 }; 3793 /* 3794 A disabled choice appears in the choice dropdown but cannot be selected 3795 A selected choice has been added to the passed input's value (added as an item) 3796 An active choice appears within the choice dropdown 3797 */ 3798 3799 return __spreadArray(__spreadArray([], state, true), [choice], false); 3800 } 3801 3802 case 'ADD_ITEM': 3803 { 3804 var addItemAction_1 = action; // When an item is added and it has an associated choice, 3805 // we want to disable it so it can't be chosen again 3806 3807 if (addItemAction_1.choiceId > -1) { 3808 return state.map(function (obj) { 3809 var choice = obj; 3810 3811 if (choice.id === parseInt("".concat(addItemAction_1.choiceId), 10)) { 3812 choice.selected = true; 3813 } 3814 3815 return choice; 3816 }); 3817 } 3818 3819 return state; 3820 } 3821 3822 case 'REMOVE_ITEM': 3823 { 3824 var removeItemAction_1 = action; // When an item is removed and it has an associated choice, 3825 // we want to re-enable it so it can be chosen again 3826 3827 if (removeItemAction_1.choiceId && removeItemAction_1.choiceId > -1) { 3828 return state.map(function (obj) { 3829 var choice = obj; 3830 3831 if (choice.id === parseInt("".concat(removeItemAction_1.choiceId), 10)) { 3832 choice.selected = false; 3833 } 3834 3835 return choice; 3836 }); 3837 } 3838 3839 return state; 3840 } 3841 3842 case 'FILTER_CHOICES': 3843 { 3844 var filterChoicesAction_1 = action; 3845 return state.map(function (obj) { 3846 var choice = obj; // Set active state based on whether choice is 3847 // within filtered results 3848 3849 choice.active = filterChoicesAction_1.results.some(function (_a) { 3850 var item = _a.item, 3851 score = _a.score; 3852 3853 if (item.id === choice.id) { 3854 choice.score = score; 3855 return true; 3856 } 3857 3858 return false; 3859 }); 3860 return choice; 3861 }); 3862 } 3863 3864 case 'ACTIVATE_CHOICES': 3865 { 3866 var activateChoicesAction_1 = action; 3867 return state.map(function (obj) { 3868 var choice = obj; 3869 choice.active = activateChoicesAction_1.active; 3870 return choice; 3871 }); 3872 } 3873 3874 case 'CLEAR_CHOICES': 3875 { 3876 return exports.defaultState; 3877 } 3878 3879 default: 3880 { 3881 return state; 3882 } 3883 } 3884 } 3885 3886 exports["default"] = choices; 3887 3888 /***/ }), 3889 3890 /***/ 871: 3891 /***/ (function(__unused_webpack_module, exports) { 3892 3893 "use strict"; 3894 3895 3896 var __spreadArray = this && this.__spreadArray || function (to, from, pack) { 3897 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { 3898 if (ar || !(i in from)) { 3899 if (!ar) ar = Array.prototype.slice.call(from, 0, i); 3900 ar[i] = from[i]; 3901 } 3902 } 3903 return to.concat(ar || Array.prototype.slice.call(from)); 3904 }; 3905 3906 Object.defineProperty(exports, "__esModule", ({ 3907 value: true 3908 })); 3909 exports.defaultState = void 0; 3910 exports.defaultState = []; 3911 3912 function groups(state, action) { 3913 if (state === void 0) { 3914 state = exports.defaultState; 3915 } 3916 3917 if (action === void 0) { 3918 action = {}; 3919 } 3920 3921 switch (action.type) { 3922 case 'ADD_GROUP': 3923 { 3924 var addGroupAction = action; 3925 return __spreadArray(__spreadArray([], state, true), [{ 3926 id: addGroupAction.id, 3927 value: addGroupAction.value, 3928 active: addGroupAction.active, 3929 disabled: addGroupAction.disabled 3930 }], false); 3931 } 3932 3933 case 'CLEAR_CHOICES': 3934 { 3935 return []; 3936 } 3937 3938 default: 3939 { 3940 return state; 3941 } 3942 } 3943 } 3944 3945 exports["default"] = groups; 3946 3947 /***/ }), 3948 3949 /***/ 655: 3950 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 3951 3952 "use strict"; 3953 3954 3955 var __importDefault = this && this.__importDefault || function (mod) { 3956 return mod && mod.__esModule ? mod : { 3957 "default": mod 3958 }; 3959 }; 3960 3961 Object.defineProperty(exports, "__esModule", ({ 3962 value: true 3963 })); 3964 exports.defaultState = void 0; 3965 3966 var redux_1 = __webpack_require__(857); 3967 3968 var items_1 = __importDefault(__webpack_require__(52)); 3969 3970 var groups_1 = __importDefault(__webpack_require__(871)); 3971 3972 var choices_1 = __importDefault(__webpack_require__(273)); 3973 3974 var loading_1 = __importDefault(__webpack_require__(502)); 3975 3976 var utils_1 = __webpack_require__(799); 3977 3978 exports.defaultState = { 3979 groups: [], 3980 items: [], 3981 choices: [], 3982 loading: false 3983 }; 3984 var appReducer = (0, redux_1.combineReducers)({ 3985 items: items_1.default, 3986 groups: groups_1.default, 3987 choices: choices_1.default, 3988 loading: loading_1.default 3989 }); 3990 3991 var rootReducer = function (passedState, action) { 3992 var state = passedState; // If we are clearing all items, groups and options we reassign 3993 // state and then pass that state to our proper reducer. This isn't 3994 // mutating our actual state 3995 // See: http://stackoverflow.com/a/35641992 3996 3997 if (action.type === 'CLEAR_ALL') { 3998 state = exports.defaultState; 3999 } else if (action.type === 'RESET_TO') { 4000 return (0, utils_1.cloneObject)(action.state); 4001 } 4002 4003 return appReducer(state, action); 4004 }; 4005 4006 exports["default"] = rootReducer; 4007 4008 /***/ }), 4009 4010 /***/ 52: 4011 /***/ (function(__unused_webpack_module, exports) { 4012 4013 "use strict"; 4014 4015 4016 var __spreadArray = this && this.__spreadArray || function (to, from, pack) { 4017 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { 4018 if (ar || !(i in from)) { 4019 if (!ar) ar = Array.prototype.slice.call(from, 0, i); 4020 ar[i] = from[i]; 4021 } 4022 } 4023 return to.concat(ar || Array.prototype.slice.call(from)); 4024 }; 4025 4026 Object.defineProperty(exports, "__esModule", ({ 4027 value: true 4028 })); 4029 exports.defaultState = void 0; 4030 exports.defaultState = []; 4031 4032 function items(state, action) { 4033 if (state === void 0) { 4034 state = exports.defaultState; 4035 } 4036 4037 if (action === void 0) { 4038 action = {}; 4039 } 4040 4041 switch (action.type) { 4042 case 'ADD_ITEM': 4043 { 4044 var addItemAction = action; // Add object to items array 4045 4046 var newState = __spreadArray(__spreadArray([], state, true), [{ 4047 id: addItemAction.id, 4048 choiceId: addItemAction.choiceId, 4049 groupId: addItemAction.groupId, 4050 value: addItemAction.value, 4051 label: addItemAction.label, 4052 active: true, 4053 highlighted: false, 4054 customProperties: addItemAction.customProperties, 4055 placeholder: addItemAction.placeholder || false, 4056 keyCode: null 4057 }], false); 4058 4059 return newState.map(function (obj) { 4060 var item = obj; 4061 item.highlighted = false; 4062 return item; 4063 }); 4064 } 4065 4066 case 'REMOVE_ITEM': 4067 { 4068 // Set item to inactive 4069 return state.map(function (obj) { 4070 var item = obj; 4071 4072 if (item.id === action.id) { 4073 item.active = false; 4074 } 4075 4076 return item; 4077 }); 4078 } 4079 4080 case 'HIGHLIGHT_ITEM': 4081 { 4082 var highlightItemAction_1 = action; 4083 return state.map(function (obj) { 4084 var item = obj; 4085 4086 if (item.id === highlightItemAction_1.id) { 4087 item.highlighted = highlightItemAction_1.highlighted; 4088 } 4089 4090 return item; 4091 }); 4092 } 4093 4094 default: 4095 { 4096 return state; 4097 } 4098 } 4099 } 4100 4101 exports["default"] = items; 4102 4103 /***/ }), 4104 4105 /***/ 502: 4106 /***/ (function(__unused_webpack_module, exports) { 4107 4108 "use strict"; 4109 4110 4111 Object.defineProperty(exports, "__esModule", ({ 4112 value: true 4113 })); 4114 exports.defaultState = void 0; 4115 exports.defaultState = false; 4116 4117 var general = function (state, action) { 4118 if (state === void 0) { 4119 state = exports.defaultState; 4120 } 4121 4122 if (action === void 0) { 4123 action = {}; 4124 } 4125 4126 switch (action.type) { 4127 case 'SET_IS_LOADING': 4128 { 4129 return action.isLoading; 4130 } 4131 4132 default: 4133 { 4134 return state; 4135 } 4136 } 4137 }; 4138 4139 exports["default"] = general; 4140 4141 /***/ }), 4142 4143 /***/ 744: 4144 /***/ (function(__unused_webpack_module, exports, __webpack_require__) { 4145 4146 "use strict"; 4147 4148 4149 var __spreadArray = this && this.__spreadArray || function (to, from, pack) { 4150 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { 4151 if (ar || !(i in from)) { 4152 if (!ar) ar = Array.prototype.slice.call(from, 0, i); 4153 ar[i] = from[i]; 4154 } 4155 } 4156 return to.concat(ar || Array.prototype.slice.call(from)); 4157 }; 4158 4159 var __importDefault = this && this.__importDefault || function (mod) { 4160 return mod && mod.__esModule ? mod : { 4161 "default": mod 4162 }; 4163 }; 4164 4165 Object.defineProperty(exports, "__esModule", ({ 4166 value: true 4167 })); 4168 /* eslint-disable @typescript-eslint/no-explicit-any */ 4169 4170 var redux_1 = __webpack_require__(857); 4171 4172 var index_1 = __importDefault(__webpack_require__(655)); 4173 4174 var Store = 4175 /** @class */ 4176 function () { 4177 function Store() { 4178 this._store = (0, redux_1.createStore)(index_1.default, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()); 4179 } 4180 /** 4181 * Subscribe store to function call (wrapped Redux method) 4182 */ 4183 4184 4185 Store.prototype.subscribe = function (onChange) { 4186 this._store.subscribe(onChange); 4187 }; 4188 /** 4189 * Dispatch event to store (wrapped Redux method) 4190 */ 4191 4192 4193 Store.prototype.dispatch = function (action) { 4194 this._store.dispatch(action); 4195 }; 4196 4197 Object.defineProperty(Store.prototype, "state", { 4198 /** 4199 * Get store object (wrapping Redux method) 4200 */ 4201 get: function () { 4202 return this._store.getState(); 4203 }, 4204 enumerable: false, 4205 configurable: true 4206 }); 4207 Object.defineProperty(Store.prototype, "items", { 4208 /** 4209 * Get items from store 4210 */ 4211 get: function () { 4212 return this.state.items; 4213 }, 4214 enumerable: false, 4215 configurable: true 4216 }); 4217 Object.defineProperty(Store.prototype, "activeItems", { 4218 /** 4219 * Get active items from store 4220 */ 4221 get: function () { 4222 return this.items.filter(function (item) { 4223 return item.active === true; 4224 }); 4225 }, 4226 enumerable: false, 4227 configurable: true 4228 }); 4229 Object.defineProperty(Store.prototype, "highlightedActiveItems", { 4230 /** 4231 * Get highlighted items from store 4232 */ 4233 get: function () { 4234 return this.items.filter(function (item) { 4235 return item.active && item.highlighted; 4236 }); 4237 }, 4238 enumerable: false, 4239 configurable: true 4240 }); 4241 Object.defineProperty(Store.prototype, "choices", { 4242 /** 4243 * Get choices from store 4244 */ 4245 get: function () { 4246 return this.state.choices; 4247 }, 4248 enumerable: false, 4249 configurable: true 4250 }); 4251 Object.defineProperty(Store.prototype, "activeChoices", { 4252 /** 4253 * Get active choices from store 4254 */ 4255 get: function () { 4256 return this.choices.filter(function (choice) { 4257 return choice.active === true; 4258 }); 4259 }, 4260 enumerable: false, 4261 configurable: true 4262 }); 4263 Object.defineProperty(Store.prototype, "selectableChoices", { 4264 /** 4265 * Get selectable choices from store 4266 */ 4267 get: function () { 4268 return this.choices.filter(function (choice) { 4269 return choice.disabled !== true; 4270 }); 4271 }, 4272 enumerable: false, 4273 configurable: true 4274 }); 4275 Object.defineProperty(Store.prototype, "searchableChoices", { 4276 /** 4277 * Get choices that can be searched (excluding placeholders) 4278 */ 4279 get: function () { 4280 return this.selectableChoices.filter(function (choice) { 4281 return choice.placeholder !== true; 4282 }); 4283 }, 4284 enumerable: false, 4285 configurable: true 4286 }); 4287 Object.defineProperty(Store.prototype, "placeholderChoice", { 4288 /** 4289 * Get placeholder choice from store 4290 */ 4291 get: function () { 4292 return __spreadArray([], this.choices, true).reverse().find(function (choice) { 4293 return choice.placeholder === true; 4294 }); 4295 }, 4296 enumerable: false, 4297 configurable: true 4298 }); 4299 Object.defineProperty(Store.prototype, "groups", { 4300 /** 4301 * Get groups from store 4302 */ 4303 get: function () { 4304 return this.state.groups; 4305 }, 4306 enumerable: false, 4307 configurable: true 4308 }); 4309 Object.defineProperty(Store.prototype, "activeGroups", { 4310 /** 4311 * Get active groups from store 4312 */ 4313 get: function () { 4314 var _a = this, 4315 groups = _a.groups, 4316 choices = _a.choices; 4317 4318 return groups.filter(function (group) { 4319 var isActive = group.active === true && group.disabled === false; 4320 var hasActiveOptions = choices.some(function (choice) { 4321 return choice.active === true && choice.disabled === false; 4322 }); 4323 return isActive && hasActiveOptions; 4324 }, []); 4325 }, 4326 enumerable: false, 4327 configurable: true 4328 }); 4329 /** 4330 * Get loading state from store 4331 */ 4332 4333 Store.prototype.isLoading = function () { 4334 return this.state.loading; 4335 }; 4336 /** 4337 * Get single choice by it's ID 4338 */ 4339 4340 4341 Store.prototype.getChoiceById = function (id) { 4342 return this.activeChoices.find(function (choice) { 4343 return choice.id === parseInt(id, 10); 4344 }); 4345 }; 4346 /** 4347 * Get group by group id 4348 */ 4349 4350 4351 Store.prototype.getGroupById = function (id) { 4352 return this.groups.find(function (group) { 4353 return group.id === id; 4354 }); 4355 }; 4356 4357 return Store; 4358 }(); 4359 4360 exports["default"] = Store; 4361 4362 /***/ }), 4363 4364 /***/ 686: 4365 /***/ (function(__unused_webpack_module, exports) { 4366 4367 "use strict"; 4368 4369 /** 4370 * Helpers to create HTML elements used by Choices 4371 * Can be overridden by providing `callbackOnCreateTemplates` option 4372 */ 4373 4374 Object.defineProperty(exports, "__esModule", ({ 4375 value: true 4376 })); 4377 var templates = { 4378 containerOuter: function (_a, dir, isSelectElement, isSelectOneElement, searchEnabled, passedElementType) { 4379 var containerOuter = _a.containerOuter; 4380 var div = Object.assign(document.createElement('div'), { 4381 className: containerOuter 4382 }); 4383 div.dataset.type = passedElementType; 4384 4385 if (dir) { 4386 div.dir = dir; 4387 } 4388 4389 if (isSelectOneElement) { 4390 div.tabIndex = 0; 4391 } 4392 4393 if (isSelectElement) { 4394 div.setAttribute('role', searchEnabled ? 'combobox' : 'listbox'); 4395 4396 if (searchEnabled) { 4397 div.setAttribute('aria-autocomplete', 'list'); 4398 } 4399 } 4400 4401 div.setAttribute('aria-haspopup', 'true'); 4402 div.setAttribute('aria-expanded', 'false'); 4403 return div; 4404 }, 4405 containerInner: function (_a) { 4406 var containerInner = _a.containerInner; 4407 return Object.assign(document.createElement('div'), { 4408 className: containerInner 4409 }); 4410 }, 4411 itemList: function (_a, isSelectOneElement) { 4412 var list = _a.list, 4413 listSingle = _a.listSingle, 4414 listItems = _a.listItems; 4415 return Object.assign(document.createElement('div'), { 4416 className: "".concat(list, " ").concat(isSelectOneElement ? listSingle : listItems) 4417 }); 4418 }, 4419 placeholder: function (_a, value) { 4420 var placeholder = _a.placeholder; 4421 return Object.assign(document.createElement('div'), { 4422 className: placeholder, 4423 innerHTML: value 4424 }); 4425 }, 4426 item: function (_a, _b, removeItemButton) { 4427 var item = _a.item, 4428 button = _a.button, 4429 highlightedState = _a.highlightedState, 4430 itemSelectable = _a.itemSelectable, 4431 placeholder = _a.placeholder; 4432 var id = _b.id, 4433 value = _b.value, 4434 label = _b.label, 4435 customProperties = _b.customProperties, 4436 active = _b.active, 4437 disabled = _b.disabled, 4438 highlighted = _b.highlighted, 4439 isPlaceholder = _b.placeholder; 4440 var div = Object.assign(document.createElement('div'), { 4441 className: item, 4442 innerHTML: label 4443 }); 4444 Object.assign(div.dataset, { 4445 item: '', 4446 id: id, 4447 value: value, 4448 customProperties: customProperties 4449 }); 4450 4451 if (active) { 4452 div.setAttribute('aria-selected', 'true'); 4453 } 4454 4455 if (disabled) { 4456 div.setAttribute('aria-disabled', 'true'); 4457 } 4458 4459 if (isPlaceholder) { 4460 div.classList.add(placeholder); 4461 } 4462 4463 div.classList.add(highlighted ? highlightedState : itemSelectable); 4464 4465 if (removeItemButton) { 4466 if (disabled) { 4467 div.classList.remove(itemSelectable); 4468 } 4469 4470 div.dataset.deletable = ''; 4471 /** @todo This MUST be localizable, not hardcoded! */ 4472 4473 var REMOVE_ITEM_TEXT = 'Remove item'; 4474 var removeButton = Object.assign(document.createElement('button'), { 4475 type: 'button', 4476 className: button, 4477 innerHTML: REMOVE_ITEM_TEXT 4478 }); 4479 removeButton.setAttribute('aria-label', "".concat(REMOVE_ITEM_TEXT, ": '").concat(value, "'")); 4480 removeButton.dataset.button = ''; 4481 div.appendChild(removeButton); 4482 } 4483 4484 return div; 4485 }, 4486 choiceList: function (_a, isSelectOneElement) { 4487 var list = _a.list; 4488 var div = Object.assign(document.createElement('div'), { 4489 className: list 4490 }); 4491 4492 if (!isSelectOneElement) { 4493 div.setAttribute('aria-multiselectable', 'true'); 4494 } 4495 4496 div.setAttribute('role', 'listbox'); 4497 return div; 4498 }, 4499 choiceGroup: function (_a, _b) { 4500 var group = _a.group, 4501 groupHeading = _a.groupHeading, 4502 itemDisabled = _a.itemDisabled; 4503 var id = _b.id, 4504 value = _b.value, 4505 disabled = _b.disabled; 4506 var div = Object.assign(document.createElement('div'), { 4507 className: "".concat(group, " ").concat(disabled ? itemDisabled : '') 4508 }); 4509 div.setAttribute('role', 'group'); 4510 Object.assign(div.dataset, { 4511 group: '', 4512 id: id, 4513 value: value 4514 }); 4515 4516 if (disabled) { 4517 div.setAttribute('aria-disabled', 'true'); 4518 } 4519 4520 div.appendChild(Object.assign(document.createElement('div'), { 4521 className: groupHeading, 4522 innerHTML: value 4523 })); 4524 return div; 4525 }, 4526 choice: function (_a, _b, selectText) { 4527 var item = _a.item, 4528 itemChoice = _a.itemChoice, 4529 itemSelectable = _a.itemSelectable, 4530 selectedState = _a.selectedState, 4531 itemDisabled = _a.itemDisabled, 4532 placeholder = _a.placeholder; 4533 var id = _b.id, 4534 value = _b.value, 4535 label = _b.label, 4536 groupId = _b.groupId, 4537 elementId = _b.elementId, 4538 isDisabled = _b.disabled, 4539 isSelected = _b.selected, 4540 isPlaceholder = _b.placeholder; 4541 var div = Object.assign(document.createElement('div'), { 4542 id: elementId, 4543 innerHTML: label, 4544 className: "".concat(item, " ").concat(itemChoice) 4545 }); 4546 4547 if (isSelected) { 4548 div.classList.add(selectedState); 4549 } 4550 4551 if (isPlaceholder) { 4552 div.classList.add(placeholder); 4553 } 4554 4555 div.setAttribute('role', groupId && groupId > 0 ? 'treeitem' : 'option'); 4556 Object.assign(div.dataset, { 4557 choice: '', 4558 id: id, 4559 value: value, 4560 selectText: selectText 4561 }); 4562 4563 if (isDisabled) { 4564 div.classList.add(itemDisabled); 4565 div.dataset.choiceDisabled = ''; 4566 div.setAttribute('aria-disabled', 'true'); 4567 } else { 4568 div.classList.add(itemSelectable); 4569 div.dataset.choiceSelectable = ''; 4570 } 4571 4572 return div; 4573 }, 4574 input: function (_a, placeholderValue) { 4575 var input = _a.input, 4576 inputCloned = _a.inputCloned; 4577 var inp = Object.assign(document.createElement('input'), { 4578 type: 'text', 4579 className: "".concat(input, " ").concat(inputCloned), 4580 autocomplete: 'off', 4581 autocapitalize: 'off', 4582 spellcheck: false 4583 }); 4584 inp.setAttribute('role', 'textbox'); 4585 inp.setAttribute('aria-autocomplete', 'list'); 4586 inp.setAttribute('aria-label', placeholderValue); 4587 return inp; 4588 }, 4589 dropdown: function (_a) { 4590 var list = _a.list, 4591 listDropdown = _a.listDropdown; 4592 var div = document.createElement('div'); 4593 div.classList.add(list, listDropdown); 4594 div.setAttribute('aria-expanded', 'false'); 4595 return div; 4596 }, 4597 notice: function (_a, innerHTML, type) { 4598 var item = _a.item, 4599 itemChoice = _a.itemChoice, 4600 noResults = _a.noResults, 4601 noChoices = _a.noChoices; 4602 4603 if (type === void 0) { 4604 type = ''; 4605 } 4606 4607 var classes = [item, itemChoice]; 4608 4609 if (type === 'no-choices') { 4610 classes.push(noChoices); 4611 } else if (type === 'no-results') { 4612 classes.push(noResults); 4613 } 4614 4615 return Object.assign(document.createElement('div'), { 4616 innerHTML: innerHTML, 4617 className: classes.join(' ') 4618 }); 4619 }, 4620 option: function (_a) { 4621 var label = _a.label, 4622 value = _a.value, 4623 customProperties = _a.customProperties, 4624 active = _a.active, 4625 disabled = _a.disabled; 4626 var opt = new Option(label, value, false, active); 4627 4628 if (customProperties) { 4629 opt.dataset.customProperties = "".concat(customProperties); 4630 } 4631 4632 opt.disabled = !!disabled; 4633 return opt; 4634 } 4635 }; 4636 exports["default"] = templates; 4637 4638 /***/ }), 4639 4640 /***/ 996: 4641 /***/ (function(module) { 4642 4643 "use strict"; 4644 4645 4646 var isMergeableObject = function isMergeableObject(value) { 4647 return isNonNullObject(value) 4648 && !isSpecial(value) 4649 }; 4650 4651 function isNonNullObject(value) { 4652 return !!value && typeof value === 'object' 4653 } 4654 4655 function isSpecial(value) { 4656 var stringValue = Object.prototype.toString.call(value); 4657 4658 return stringValue === '[object RegExp]' 4659 || stringValue === '[object Date]' 4660 || isReactElement(value) 4661 } 4662 4663 // see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25 4664 var canUseSymbol = typeof Symbol === 'function' && Symbol.for; 4665 var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7; 4666 4667 function isReactElement(value) { 4668 return value.$$typeof === REACT_ELEMENT_TYPE 4669 } 4670 4671 function emptyTarget(val) { 4672 return Array.isArray(val) ? [] : {} 4673 } 4674 4675 function cloneUnlessOtherwiseSpecified(value, options) { 4676 return (options.clone !== false && options.isMergeableObject(value)) 4677 ? deepmerge(emptyTarget(value), value, options) 4678 : value 4679 } 4680 4681 function defaultArrayMerge(target, source, options) { 4682 return target.concat(source).map(function(element) { 4683 return cloneUnlessOtherwiseSpecified(element, options) 4684 }) 4685 } 4686 4687 function getMergeFunction(key, options) { 4688 if (!options.customMerge) { 4689 return deepmerge 4690 } 4691 var customMerge = options.customMerge(key); 4692 return typeof customMerge === 'function' ? customMerge : deepmerge 4693 } 4694 4695 function getEnumerableOwnPropertySymbols(target) { 4696 return Object.getOwnPropertySymbols 4697 ? Object.getOwnPropertySymbols(target).filter(function(symbol) { 4698 return target.propertyIsEnumerable(symbol) 4699 }) 4700 : [] 4701 } 4702 4703 function getKeys(target) { 4704 return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) 4705 } 4706 4707 function propertyIsOnObject(object, property) { 4708 try { 4709 return property in object 4710 } catch(_) { 4711 return false 4712 } 4713 } 4714 4715 // Protects from prototype poisoning and unexpected merging up the prototype chain. 4716 function propertyIsUnsafe(target, key) { 4717 return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, 4718 && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, 4719 && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. 4720 } 4721 4722 function mergeObject(target, source, options) { 4723 var destination = {}; 4724 if (options.isMergeableObject(target)) { 4725 getKeys(target).forEach(function(key) { 4726 destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); 4727 }); 4728 } 4729 getKeys(source).forEach(function(key) { 4730 if (propertyIsUnsafe(target, key)) { 4731 return 4732 } 4733 4734 if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) { 4735 destination[key] = getMergeFunction(key, options)(target[key], source[key], options); 4736 } else { 4737 destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); 4738 } 4739 }); 4740 return destination 4741 } 4742 4743 function deepmerge(target, source, options) { 4744 options = options || {}; 4745 options.arrayMerge = options.arrayMerge || defaultArrayMerge; 4746 options.isMergeableObject = options.isMergeableObject || isMergeableObject; 4747 // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge() 4748 // implementations can use it. The caller may not replace it. 4749 options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified; 4750 4751 var sourceIsArray = Array.isArray(source); 4752 var targetIsArray = Array.isArray(target); 4753 var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; 4754 4755 if (!sourceAndTargetTypesMatch) { 4756 return cloneUnlessOtherwiseSpecified(source, options) 4757 } else if (sourceIsArray) { 4758 return options.arrayMerge(target, source, options) 4759 } else { 4760 return mergeObject(target, source, options) 4761 } 4762 } 4763 4764 deepmerge.all = function deepmergeAll(array, options) { 4765 if (!Array.isArray(array)) { 4766 throw new Error('first argument should be an array') 4767 } 4768 4769 return array.reduce(function(prev, next) { 4770 return deepmerge(prev, next, options) 4771 }, {}) 4772 }; 4773 4774 var deepmerge_1 = deepmerge; 4775 4776 module.exports = deepmerge_1; 4777 4778 4779 /***/ }), 4780 4781 /***/ 70: 4782 /***/ (function(module) { 4783 4784 /*! 4785 * Fuse.js v3.4.6 - Lightweight fuzzy-search (http://fusejs.io) 4786 * 4787 * Copyright (c) 2012-2017 Kirollos Risk (http://kiro.me) 4788 * All Rights Reserved. Apache Software License 2.0 4789 * 4790 * http://www.apache.org/licenses/LICENSE-2.0 4791 */ 4792 !function(e,t){ true?module.exports=t():0}(this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){e.exports=function(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,n){function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var i=n(2),a=n(8),s=n(0),c=function(){function e(t,n){var r=n.location,o=void 0===r?0:r,i=n.distance,s=void 0===i?100:i,c=n.threshold,h=void 0===c?.6:c,l=n.maxPatternLength,u=void 0===l?32:l,f=n.caseSensitive,d=void 0!==f&&f,v=n.tokenSeparator,p=void 0===v?/ +/g:v,g=n.findAllMatches,y=void 0!==g&&g,m=n.minMatchCharLength,k=void 0===m?1:m,S=n.id,x=void 0===S?null:S,b=n.keys,M=void 0===b?[]:b,_=n.shouldSort,L=void 0===_||_,w=n.getFn,A=void 0===w?a:w,C=n.sortFn,I=void 0===C?function(e,t){return e.score-t.score}:C,O=n.tokenize,j=void 0!==O&&O,P=n.matchAllTokens,F=void 0!==P&&P,T=n.includeMatches,z=void 0!==T&&T,E=n.includeScore,K=void 0!==E&&E,$=n.verbose,J=void 0!==$&&$;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options={location:o,distance:s,threshold:h,maxPatternLength:u,isCaseSensitive:d,tokenSeparator:p,findAllMatches:y,minMatchCharLength:k,id:x,keys:M,includeMatches:z,includeScore:K,shouldSort:L,getFn:A,sortFn:I,verbose:J,tokenize:j,matchAllTokens:F},this.setCollection(t)}var t,n,c;return t=e,(n=[{key:"setCollection",value:function(e){return this.list=e,e}},{key:"search",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:!1};this._log('---------\nSearch pattern: "'.concat(e,'"'));var n=this._prepareSearchers(e),r=n.tokenSearchers,o=n.fullSearcher,i=this._search(r,o),a=i.weights,s=i.results;return this._computeScore(a,s),this.options.shouldSort&&this._sort(s),t.limit&&"number"==typeof t.limit&&(s=s.slice(0,t.limit)),this._format(s)}},{key:"_prepareSearchers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=[];if(this.options.tokenize)for(var n=e.split(this.options.tokenSeparator),r=0,o=n.length;r<o;r+=1)t.push(new i(n[r],this.options));return{tokenSearchers:t,fullSearcher:new i(e,this.options)}}},{key:"_search",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1?arguments[1]:void 0,n=this.list,r={},o=[];if("string"==typeof n[0]){for(var i=0,a=n.length;i<a;i+=1)this._analyze({key:"",value:n[i],record:i,index:i},{resultMap:r,results:o,tokenSearchers:e,fullSearcher:t});return{weights:null,results:o}}for(var s={},c=0,h=n.length;c<h;c+=1)for(var l=n[c],u=0,f=this.options.keys.length;u<f;u+=1){var d=this.options.keys[u];if("string"!=typeof d){if(s[d.name]={weight:1-d.weight||1},d.weight<=0||d.weight>1)throw new Error("Key weight has to be > 0 and <= 1");d=d.name}else s[d]={weight:1};this._analyze({key:d,value:this.options.getFn(l,d),record:l,index:c},{resultMap:r,results:o,tokenSearchers:e,fullSearcher:t})}return{weights:s,results:o}}},{key:"_analyze",value:function(e,t){var n=e.key,r=e.arrayIndex,o=void 0===r?-1:r,i=e.value,a=e.record,c=e.index,h=t.tokenSearchers,l=void 0===h?[]:h,u=t.fullSearcher,f=void 0===u?[]:u,d=t.resultMap,v=void 0===d?{}:d,p=t.results,g=void 0===p?[]:p;if(null!=i){var y=!1,m=-1,k=0;if("string"==typeof i){this._log("\nKey: ".concat(""===n?"-":n));var S=f.search(i);if(this._log('Full text: "'.concat(i,'", score: ').concat(S.score)),this.options.tokenize){for(var x=i.split(this.options.tokenSeparator),b=[],M=0;M<l.length;M+=1){var _=l[M];this._log('\nPattern: "'.concat(_.pattern,'"'));for(var L=!1,w=0;w<x.length;w+=1){var A=x[w],C=_.search(A),I={};C.isMatch?(I[A]=C.score,y=!0,L=!0,b.push(C.score)):(I[A]=1,this.options.matchAllTokens||b.push(1)),this._log('Token: "'.concat(A,'", score: ').concat(I[A]))}L&&(k+=1)}m=b[0];for(var O=b.length,j=1;j<O;j+=1)m+=b[j];m/=O,this._log("Token score average:",m)}var P=S.score;m>-1&&(P=(P+m)/2),this._log("Score average:",P);var F=!this.options.tokenize||!this.options.matchAllTokens||k>=l.length;if(this._log("\nCheck Matches: ".concat(F)),(y||S.isMatch)&&F){var T=v[c];T?T.output.push({key:n,arrayIndex:o,value:i,score:P,matchedIndices:S.matchedIndices}):(v[c]={item:a,output:[{key:n,arrayIndex:o,value:i,score:P,matchedIndices:S.matchedIndices}]},g.push(v[c]))}}else if(s(i))for(var z=0,E=i.length;z<E;z+=1)this._analyze({key:n,arrayIndex:z,value:i[z],record:a,index:c},{resultMap:v,results:g,tokenSearchers:l,fullSearcher:f})}}},{key:"_computeScore",value:function(e,t){this._log("\n\nComputing score:\n");for(var n=0,r=t.length;n<r;n+=1){for(var o=t[n].output,i=o.length,a=1,s=1,c=0;c<i;c+=1){var h=e?e[o[c].key].weight:1,l=(1===h?o[c].score:o[c].score||.001)*h;1!==h?s=Math.min(s,l):(o[c].nScore=l,a*=l)}t[n].score=1===s?a:s,this._log(t[n])}}},{key:"_sort",value:function(e){this._log("\n\nSorting...."),e.sort(this.options.sortFn)}},{key:"_format",value:function(e){var t=[];if(this.options.verbose){var n=[];this._log("\n\nOutput:\n\n",JSON.stringify(e,function(e,t){if("object"===r(t)&&null!==t){if(-1!==n.indexOf(t))return;n.push(t)}return t})),n=null}var o=[];this.options.includeMatches&&o.push(function(e,t){var n=e.output;t.matches=[];for(var r=0,o=n.length;r<o;r+=1){var i=n[r];if(0!==i.matchedIndices.length){var a={indices:i.matchedIndices,value:i.value};i.key&&(a.key=i.key),i.hasOwnProperty("arrayIndex")&&i.arrayIndex>-1&&(a.arrayIndex=i.arrayIndex),t.matches.push(a)}}}),this.options.includeScore&&o.push(function(e,t){t.score=e.score});for(var i=0,a=e.length;i<a;i+=1){var s=e[i];if(this.options.id&&(s.item=this.options.getFn(s.item,this.options.id)[0]),o.length){for(var c={item:s.item},h=0,l=o.length;h<l;h+=1)o[h](s,c);t.push(c)}else t.push(s.item)}return t}},{key:"_log",value:function(){var e;this.options.verbose&&(e=console).log.apply(e,arguments)}}])&&o(t.prototype,n),c&&o(t,c),e}();e.exports=c},function(e,t,n){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var o=n(3),i=n(4),a=n(7),s=function(){function e(t,n){var r=n.location,o=void 0===r?0:r,i=n.distance,s=void 0===i?100:i,c=n.threshold,h=void 0===c?.6:c,l=n.maxPatternLength,u=void 0===l?32:l,f=n.isCaseSensitive,d=void 0!==f&&f,v=n.tokenSeparator,p=void 0===v?/ +/g:v,g=n.findAllMatches,y=void 0!==g&&g,m=n.minMatchCharLength,k=void 0===m?1:m;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options={location:o,distance:s,threshold:h,maxPatternLength:u,isCaseSensitive:d,tokenSeparator:p,findAllMatches:y,minMatchCharLength:k},this.pattern=this.options.isCaseSensitive?t:t.toLowerCase(),this.pattern.length<=u&&(this.patternAlphabet=a(this.pattern))}var t,n,s;return t=e,(n=[{key:"search",value:function(e){if(this.options.isCaseSensitive||(e=e.toLowerCase()),this.pattern===e)return{isMatch:!0,score:0,matchedIndices:[[0,e.length-1]]};var t=this.options,n=t.maxPatternLength,r=t.tokenSeparator;if(this.pattern.length>n)return o(e,this.pattern,r);var a=this.options,s=a.location,c=a.distance,h=a.threshold,l=a.findAllMatches,u=a.minMatchCharLength;return i(e,this.pattern,this.patternAlphabet,{location:s,distance:c,threshold:h,findAllMatches:l,minMatchCharLength:u})}}])&&r(t.prototype,n),s&&r(t,s),e}();e.exports=s},function(e,t){var n=/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;e.exports=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:/ +/g,o=new RegExp(t.replace(n,"\\$&").replace(r,"|")),i=e.match(o),a=!!i,s=[];if(a)for(var c=0,h=i.length;c<h;c+=1){var l=i[c];s.push([e.indexOf(l),l.length-1])}return{score:a?.5:1,isMatch:a,matchedIndices:s}}},function(e,t,n){var r=n(5),o=n(6);e.exports=function(e,t,n,i){for(var a=i.location,s=void 0===a?0:a,c=i.distance,h=void 0===c?100:c,l=i.threshold,u=void 0===l?.6:l,f=i.findAllMatches,d=void 0!==f&&f,v=i.minMatchCharLength,p=void 0===v?1:v,g=s,y=e.length,m=u,k=e.indexOf(t,g),S=t.length,x=[],b=0;b<y;b+=1)x[b]=0;if(-1!==k){var M=r(t,{errors:0,currentLocation:k,expectedLocation:g,distance:h});if(m=Math.min(M,m),-1!==(k=e.lastIndexOf(t,g+S))){var _=r(t,{errors:0,currentLocation:k,expectedLocation:g,distance:h});m=Math.min(_,m)}}k=-1;for(var L=[],w=1,A=S+y,C=1<<(S<=31?S-1:30),I=0;I<S;I+=1){for(var O=0,j=A;O<j;){r(t,{errors:I,currentLocation:g+j,expectedLocation:g,distance:h})<=m?O=j:A=j,j=Math.floor((A-O)/2+O)}A=j;var P=Math.max(1,g-j+1),F=d?y:Math.min(g+j,y)+S,T=Array(F+2);T[F+1]=(1<<I)-1;for(var z=F;z>=P;z-=1){var E=z-1,K=n[e.charAt(E)];if(K&&(x[E]=1),T[z]=(T[z+1]<<1|1)&K,0!==I&&(T[z]|=(L[z+1]|L[z])<<1|1|L[z+1]),T[z]&C&&(w=r(t,{errors:I,currentLocation:E,expectedLocation:g,distance:h}))<=m){if(m=w,(k=E)<=g)break;P=Math.max(1,2*g-k)}}if(r(t,{errors:I+1,currentLocation:g,expectedLocation:g,distance:h})>m)break;L=T}return{isMatch:k>=0,score:0===w?.001:w,matchedIndices:o(x,p)}}},function(e,t){e.exports=function(e,t){var n=t.errors,r=void 0===n?0:n,o=t.currentLocation,i=void 0===o?0:o,a=t.expectedLocation,s=void 0===a?0:a,c=t.distance,h=void 0===c?100:c,l=r/e.length,u=Math.abs(s-i);return h?l+u/h:u?1:l}},function(e,t){e.exports=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=[],r=-1,o=-1,i=0,a=e.length;i<a;i+=1){var s=e[i];s&&-1===r?r=i:s||-1===r||((o=i-1)-r+1>=t&&n.push([r,o]),r=-1)}return e[i-1]&&i-r>=t&&n.push([r,i-1]),n}},function(e,t){e.exports=function(e){for(var t={},n=e.length,r=0;r<n;r+=1)t[e.charAt(r)]=0;for(var o=0;o<n;o+=1)t[e.charAt(o)]|=1<<n-o-1;return t}},function(e,t,n){var r=n(0);e.exports=function(e,t){return function e(t,n,o){if(n){var i=n.indexOf("."),a=n,s=null;-1!==i&&(a=n.slice(0,i),s=n.slice(i+1));var c=t[a];if(null!=c)if(s||"string"!=typeof c&&"number"!=typeof c)if(r(c))for(var h=0,l=c.length;h<l;h+=1)e(c[h],s,o);else s&&e(c,s,o);else o.push(c.toString())}else o.push(t);return o}(e,t,[])}}])}); 4793 4794 /***/ }), 4795 4796 /***/ 857: 4797 /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { 4798 4799 "use strict"; 4800 // ESM COMPAT FLAG 4801 __webpack_require__.r(__webpack_exports__); 4802 4803 // EXPORTS 4804 __webpack_require__.d(__webpack_exports__, { 4805 "__DO_NOT_USE__ActionTypes": function() { return /* binding */ ActionTypes; }, 4806 "applyMiddleware": function() { return /* binding */ applyMiddleware; }, 4807 "bindActionCreators": function() { return /* binding */ bindActionCreators; }, 4808 "combineReducers": function() { return /* binding */ combineReducers; }, 4809 "compose": function() { return /* binding */ compose; }, 4810 "createStore": function() { return /* binding */ createStore; } 4811 }); 4812 4813 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js 4814 function _defineProperty(obj, key, value) { 4815 if (key in obj) { 4816 Object.defineProperty(obj, key, { 4817 value: value, 4818 enumerable: true, 4819 configurable: true, 4820 writable: true 4821 }); 4822 } else { 4823 obj[key] = value; 4824 } 4825 4826 return obj; 4827 } 4828 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js 4829 4830 4831 function ownKeys(object, enumerableOnly) { 4832 var keys = Object.keys(object); 4833 4834 if (Object.getOwnPropertySymbols) { 4835 var symbols = Object.getOwnPropertySymbols(object); 4836 enumerableOnly && (symbols = symbols.filter(function (sym) { 4837 return Object.getOwnPropertyDescriptor(object, sym).enumerable; 4838 })), keys.push.apply(keys, symbols); 4839 } 4840 4841 return keys; 4842 } 4843 4844 function _objectSpread2(target) { 4845 for (var i = 1; i < arguments.length; i++) { 4846 var source = null != arguments[i] ? arguments[i] : {}; 4847 i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { 4848 _defineProperty(target, key, source[key]); 4849 }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { 4850 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); 4851 }); 4852 } 4853 4854 return target; 4855 } 4856 ;// CONCATENATED MODULE: ./node_modules/redux/es/redux.js 4857 4858 4859 /** 4860 * Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js 4861 * 4862 * Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes 4863 * during build. 4864 * @param {number} code 4865 */ 4866 function formatProdErrorMessage(code) { 4867 return "Minified Redux error #" + code + "; visit https://redux.js.org/Errors?code=" + code + " for the full message or " + 'use the non-minified dev environment for full errors. '; 4868 } 4869 4870 // Inlined version of the `symbol-observable` polyfill 4871 var $$observable = (function () { 4872 return typeof Symbol === 'function' && Symbol.observable || '@@observable'; 4873 })(); 4874 4875 /** 4876 * These are private action types reserved by Redux. 4877 * For any unknown actions, you must return the current state. 4878 * If the current state is undefined, you must return the initial state. 4879 * Do not reference these action types directly in your code. 4880 */ 4881 var randomString = function randomString() { 4882 return Math.random().toString(36).substring(7).split('').join('.'); 4883 }; 4884 4885 var ActionTypes = { 4886 INIT: "@@redux/INIT" + randomString(), 4887 REPLACE: "@@redux/REPLACE" + randomString(), 4888 PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() { 4889 return "@@redux/PROBE_UNKNOWN_ACTION" + randomString(); 4890 } 4891 }; 4892 4893 /** 4894 * @param {any} obj The object to inspect. 4895 * @returns {boolean} True if the argument appears to be a plain object. 4896 */ 4897 function isPlainObject(obj) { 4898 if (typeof obj !== 'object' || obj === null) return false; 4899 var proto = obj; 4900 4901 while (Object.getPrototypeOf(proto) !== null) { 4902 proto = Object.getPrototypeOf(proto); 4903 } 4904 4905 return Object.getPrototypeOf(obj) === proto; 4906 } 4907 4908 // Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of 4909 function miniKindOf(val) { 4910 if (val === void 0) return 'undefined'; 4911 if (val === null) return 'null'; 4912 var type = typeof val; 4913 4914 switch (type) { 4915 case 'boolean': 4916 case 'string': 4917 case 'number': 4918 case 'symbol': 4919 case 'function': 4920 { 4921 return type; 4922 } 4923 } 4924 4925 if (Array.isArray(val)) return 'array'; 4926 if (isDate(val)) return 'date'; 4927 if (isError(val)) return 'error'; 4928 var constructorName = ctorName(val); 4929 4930 switch (constructorName) { 4931 case 'Symbol': 4932 case 'Promise': 4933 case 'WeakMap': 4934 case 'WeakSet': 4935 case 'Map': 4936 case 'Set': 4937 return constructorName; 4938 } // other 4939 4940 4941 return type.slice(8, -1).toLowerCase().replace(/\s/g, ''); 4942 } 4943 4944 function ctorName(val) { 4945 return typeof val.constructor === 'function' ? val.constructor.name : null; 4946 } 4947 4948 function isError(val) { 4949 return val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number'; 4950 } 4951 4952 function isDate(val) { 4953 if (val instanceof Date) return true; 4954 return typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function'; 4955 } 4956 4957 function kindOf(val) { 4958 var typeOfVal = typeof val; 4959 4960 if (false) {} 4961 4962 return typeOfVal; 4963 } 4964 4965 /** 4966 * Creates a Redux store that holds the state tree. 4967 * The only way to change the data in the store is to call `dispatch()` on it. 4968 * 4969 * There should only be a single store in your app. To specify how different 4970 * parts of the state tree respond to actions, you may combine several reducers 4971 * into a single reducer function by using `combineReducers`. 4972 * 4973 * @param {Function} reducer A function that returns the next state tree, given 4974 * the current state tree and the action to handle. 4975 * 4976 * @param {any} [preloadedState] The initial state. You may optionally specify it 4977 * to hydrate the state from the server in universal apps, or to restore a 4978 * previously serialized user session. 4979 * If you use `combineReducers` to produce the root reducer function, this must be 4980 * an object with the same shape as `combineReducers` keys. 4981 * 4982 * @param {Function} [enhancer] The store enhancer. You may optionally specify it 4983 * to enhance the store with third-party capabilities such as middleware, 4984 * time travel, persistence, etc. The only store enhancer that ships with Redux 4985 * is `applyMiddleware()`. 4986 * 4987 * @returns {Store} A Redux store that lets you read the state, dispatch actions 4988 * and subscribe to changes. 4989 */ 4990 4991 function createStore(reducer, preloadedState, enhancer) { 4992 var _ref2; 4993 4994 if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') { 4995 throw new Error( true ? formatProdErrorMessage(0) : 0); 4996 } 4997 4998 if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') { 4999 enhancer = preloadedState; 5000 preloadedState = undefined; 5001 } 5002 5003 if (typeof enhancer !== 'undefined') { 5004 if (typeof enhancer !== 'function') { 5005 throw new Error( true ? formatProdErrorMessage(1) : 0); 5006 } 5007 5008 return enhancer(createStore)(reducer, preloadedState); 5009 } 5010 5011 if (typeof reducer !== 'function') { 5012 throw new Error( true ? formatProdErrorMessage(2) : 0); 5013 } 5014 5015 var currentReducer = reducer; 5016 var currentState = preloadedState; 5017 var currentListeners = []; 5018 var nextListeners = currentListeners; 5019 var isDispatching = false; 5020 /** 5021 * This makes a shallow copy of currentListeners so we can use 5022 * nextListeners as a temporary list while dispatching. 5023 * 5024 * This prevents any bugs around consumers calling 5025 * subscribe/unsubscribe in the middle of a dispatch. 5026 */ 5027 5028 function ensureCanMutateNextListeners() { 5029 if (nextListeners === currentListeners) { 5030 nextListeners = currentListeners.slice(); 5031 } 5032 } 5033 /** 5034 * Reads the state tree managed by the store. 5035 * 5036 * @returns {any} The current state tree of your application. 5037 */ 5038 5039 5040 function getState() { 5041 if (isDispatching) { 5042 throw new Error( true ? formatProdErrorMessage(3) : 0); 5043 } 5044 5045 return currentState; 5046 } 5047 /** 5048 * Adds a change listener. It will be called any time an action is dispatched, 5049 * and some part of the state tree may potentially have changed. You may then 5050 * call `getState()` to read the current state tree inside the callback. 5051 * 5052 * You may call `dispatch()` from a change listener, with the following 5053 * caveats: 5054 * 5055 * 1. The subscriptions are snapshotted just before every `dispatch()` call. 5056 * If you subscribe or unsubscribe while the listeners are being invoked, this 5057 * will not have any effect on the `dispatch()` that is currently in progress. 5058 * However, the next `dispatch()` call, whether nested or not, will use a more 5059 * recent snapshot of the subscription list. 5060 * 5061 * 2. The listener should not expect to see all state changes, as the state 5062 * might have been updated multiple times during a nested `dispatch()` before 5063 * the listener is called. It is, however, guaranteed that all subscribers 5064 * registered before the `dispatch()` started will be called with the latest 5065 * state by the time it exits. 5066 * 5067 * @param {Function} listener A callback to be invoked on every dispatch. 5068 * @returns {Function} A function to remove this change listener. 5069 */ 5070 5071 5072 function subscribe(listener) { 5073 if (typeof listener !== 'function') { 5074 throw new Error( true ? formatProdErrorMessage(4) : 0); 5075 } 5076 5077 if (isDispatching) { 5078 throw new Error( true ? formatProdErrorMessage(5) : 0); 5079 } 5080 5081 var isSubscribed = true; 5082 ensureCanMutateNextListeners(); 5083 nextListeners.push(listener); 5084 return function unsubscribe() { 5085 if (!isSubscribed) { 5086 return; 5087 } 5088 5089 if (isDispatching) { 5090 throw new Error( true ? formatProdErrorMessage(6) : 0); 5091 } 5092 5093 isSubscribed = false; 5094 ensureCanMutateNextListeners(); 5095 var index = nextListeners.indexOf(listener); 5096 nextListeners.splice(index, 1); 5097 currentListeners = null; 5098 }; 5099 } 5100 /** 5101 * Dispatches an action. It is the only way to trigger a state change. 5102 * 5103 * The `reducer` function, used to create the store, will be called with the 5104 * current state tree and the given `action`. Its return value will 5105 * be considered the **next** state of the tree, and the change listeners 5106 * will be notified. 5107 * 5108 * The base implementation only supports plain object actions. If you want to 5109 * dispatch a Promise, an Observable, a thunk, or something else, you need to 5110 * wrap your store creating function into the corresponding middleware. For 5111 * example, see the documentation for the `redux-thunk` package. Even the 5112 * middleware will eventually dispatch plain object actions using this method. 5113 * 5114 * @param {Object} action A plain object representing “what changed”. It is 5115 * a good idea to keep actions serializable so you can record and replay user 5116 * sessions, or use the time travelling `redux-devtools`. An action must have 5117 * a `type` property which may not be `undefined`. It is a good idea to use 5118 * string constants for action types. 5119 * 5120 * @returns {Object} For convenience, the same action object you dispatched. 5121 * 5122 * Note that, if you use a custom middleware, it may wrap `dispatch()` to 5123 * return something else (for example, a Promise you can await). 5124 */ 5125 5126 5127 function dispatch(action) { 5128 if (!isPlainObject(action)) { 5129 throw new Error( true ? formatProdErrorMessage(7) : 0); 5130 } 5131 5132 if (typeof action.type === 'undefined') { 5133 throw new Error( true ? formatProdErrorMessage(8) : 0); 5134 } 5135 5136 if (isDispatching) { 5137 throw new Error( true ? formatProdErrorMessage(9) : 0); 5138 } 5139 5140 try { 5141 isDispatching = true; 5142 currentState = currentReducer(currentState, action); 5143 } finally { 5144 isDispatching = false; 5145 } 5146 5147 var listeners = currentListeners = nextListeners; 5148 5149 for (var i = 0; i < listeners.length; i++) { 5150 var listener = listeners[i]; 5151 listener(); 5152 } 5153 5154 return action; 5155 } 5156 /** 5157 * Replaces the reducer currently used by the store to calculate the state. 5158 * 5159 * You might need this if your app implements code splitting and you want to 5160 * load some of the reducers dynamically. You might also need this if you 5161 * implement a hot reloading mechanism for Redux. 5162 * 5163 * @param {Function} nextReducer The reducer for the store to use instead. 5164 * @returns {void} 5165 */ 5166 5167 5168 function replaceReducer(nextReducer) { 5169 if (typeof nextReducer !== 'function') { 5170 throw new Error( true ? formatProdErrorMessage(10) : 0); 5171 } 5172 5173 currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT. 5174 // Any reducers that existed in both the new and old rootReducer 5175 // will receive the previous state. This effectively populates 5176 // the new state tree with any relevant data from the old one. 5177 5178 dispatch({ 5179 type: ActionTypes.REPLACE 5180 }); 5181 } 5182 /** 5183 * Interoperability point for observable/reactive libraries. 5184 * @returns {observable} A minimal observable of state changes. 5185 * For more information, see the observable proposal: 5186 * https://github.com/tc39/proposal-observable 5187 */ 5188 5189 5190 function observable() { 5191 var _ref; 5192 5193 var outerSubscribe = subscribe; 5194 return _ref = { 5195 /** 5196 * The minimal observable subscription method. 5197 * @param {Object} observer Any object that can be used as an observer. 5198 * The observer object should have a `next` method. 5199 * @returns {subscription} An object with an `unsubscribe` method that can 5200 * be used to unsubscribe the observable from the store, and prevent further 5201 * emission of values from the observable. 5202 */ 5203 subscribe: function subscribe(observer) { 5204 if (typeof observer !== 'object' || observer === null) { 5205 throw new Error( true ? formatProdErrorMessage(11) : 0); 5206 } 5207 5208 function observeState() { 5209 if (observer.next) { 5210 observer.next(getState()); 5211 } 5212 } 5213 5214 observeState(); 5215 var unsubscribe = outerSubscribe(observeState); 5216 return { 5217 unsubscribe: unsubscribe 5218 }; 5219 } 5220 }, _ref[$$observable] = function () { 5221 return this; 5222 }, _ref; 5223 } // When a store is created, an "INIT" action is dispatched so that every 5224 // reducer returns their initial state. This effectively populates 5225 // the initial state tree. 5226 5227 5228 dispatch({ 5229 type: ActionTypes.INIT 5230 }); 5231 return _ref2 = { 5232 dispatch: dispatch, 5233 subscribe: subscribe, 5234 getState: getState, 5235 replaceReducer: replaceReducer 5236 }, _ref2[$$observable] = observable, _ref2; 5237 } 5238 5239 /** 5240 * Prints a warning in the console if it exists. 5241 * 5242 * @param {String} message The warning message. 5243 * @returns {void} 5244 */ 5245 function warning(message) { 5246 /* eslint-disable no-console */ 5247 if (typeof console !== 'undefined' && typeof console.error === 'function') { 5248 console.error(message); 5249 } 5250 /* eslint-enable no-console */ 5251 5252 5253 try { 5254 // This error was thrown as a convenience so that if you enable 5255 // "break on all exceptions" in your console, 5256 // it would pause the execution at this line. 5257 throw new Error(message); 5258 } catch (e) {} // eslint-disable-line no-empty 5259 5260 } 5261 5262 function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) { 5263 var reducerKeys = Object.keys(reducers); 5264 var argumentName = action && action.type === ActionTypes.INIT ? 'preloadedState argument passed to createStore' : 'previous state received by the reducer'; 5265 5266 if (reducerKeys.length === 0) { 5267 return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.'; 5268 } 5269 5270 if (!isPlainObject(inputState)) { 5271 return "The " + argumentName + " has unexpected type of \"" + kindOf(inputState) + "\". Expected argument to be an object with the following " + ("keys: \"" + reducerKeys.join('", "') + "\""); 5272 } 5273 5274 var unexpectedKeys = Object.keys(inputState).filter(function (key) { 5275 return !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]; 5276 }); 5277 unexpectedKeys.forEach(function (key) { 5278 unexpectedKeyCache[key] = true; 5279 }); 5280 if (action && action.type === ActionTypes.REPLACE) return; 5281 5282 if (unexpectedKeys.length > 0) { 5283 return "Unexpected " + (unexpectedKeys.length > 1 ? 'keys' : 'key') + " " + ("\"" + unexpectedKeys.join('", "') + "\" found in " + argumentName + ". ") + "Expected to find one of the known reducer keys instead: " + ("\"" + reducerKeys.join('", "') + "\". Unexpected keys will be ignored."); 5284 } 5285 } 5286 5287 function assertReducerShape(reducers) { 5288 Object.keys(reducers).forEach(function (key) { 5289 var reducer = reducers[key]; 5290 var initialState = reducer(undefined, { 5291 type: ActionTypes.INIT 5292 }); 5293 5294 if (typeof initialState === 'undefined') { 5295 throw new Error( true ? formatProdErrorMessage(12) : 0); 5296 } 5297 5298 if (typeof reducer(undefined, { 5299 type: ActionTypes.PROBE_UNKNOWN_ACTION() 5300 }) === 'undefined') { 5301 throw new Error( true ? formatProdErrorMessage(13) : 0); 5302 } 5303 }); 5304 } 5305 /** 5306 * Turns an object whose values are different reducer functions, into a single 5307 * reducer function. It will call every child reducer, and gather their results 5308 * into a single state object, whose keys correspond to the keys of the passed 5309 * reducer functions. 5310 * 5311 * @param {Object} reducers An object whose values correspond to different 5312 * reducer functions that need to be combined into one. One handy way to obtain 5313 * it is to use ES6 `import * as reducers` syntax. The reducers may never return 5314 * undefined for any action. Instead, they should return their initial state 5315 * if the state passed to them was undefined, and the current state for any 5316 * unrecognized action. 5317 * 5318 * @returns {Function} A reducer function that invokes every reducer inside the 5319 * passed object, and builds a state object with the same shape. 5320 */ 5321 5322 5323 function combineReducers(reducers) { 5324 var reducerKeys = Object.keys(reducers); 5325 var finalReducers = {}; 5326 5327 for (var i = 0; i < reducerKeys.length; i++) { 5328 var key = reducerKeys[i]; 5329 5330 if (false) {} 5331 5332 if (typeof reducers[key] === 'function') { 5333 finalReducers[key] = reducers[key]; 5334 } 5335 } 5336 5337 var finalReducerKeys = Object.keys(finalReducers); // This is used to make sure we don't warn about the same 5338 // keys multiple times. 5339 5340 var unexpectedKeyCache; 5341 5342 if (false) {} 5343 5344 var shapeAssertionError; 5345 5346 try { 5347 assertReducerShape(finalReducers); 5348 } catch (e) { 5349 shapeAssertionError = e; 5350 } 5351 5352 return function combination(state, action) { 5353 if (state === void 0) { 5354 state = {}; 5355 } 5356 5357 if (shapeAssertionError) { 5358 throw shapeAssertionError; 5359 } 5360 5361 if (false) { var warningMessage; } 5362 5363 var hasChanged = false; 5364 var nextState = {}; 5365 5366 for (var _i = 0; _i < finalReducerKeys.length; _i++) { 5367 var _key = finalReducerKeys[_i]; 5368 var reducer = finalReducers[_key]; 5369 var previousStateForKey = state[_key]; 5370 var nextStateForKey = reducer(previousStateForKey, action); 5371 5372 if (typeof nextStateForKey === 'undefined') { 5373 var actionType = action && action.type; 5374 throw new Error( true ? formatProdErrorMessage(14) : 0); 5375 } 5376 5377 nextState[_key] = nextStateForKey; 5378 hasChanged = hasChanged || nextStateForKey !== previousStateForKey; 5379 } 5380 5381 hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length; 5382 return hasChanged ? nextState : state; 5383 }; 5384 } 5385 5386 function bindActionCreator(actionCreator, dispatch) { 5387 return function () { 5388 return dispatch(actionCreator.apply(this, arguments)); 5389 }; 5390 } 5391 /** 5392 * Turns an object whose values are action creators, into an object with the 5393 * same keys, but with every function wrapped into a `dispatch` call so they 5394 * may be invoked directly. This is just a convenience method, as you can call 5395 * `store.dispatch(MyActionCreators.doSomething())` yourself just fine. 5396 * 5397 * For convenience, you can also pass an action creator as the first argument, 5398 * and get a dispatch wrapped function in return. 5399 * 5400 * @param {Function|Object} actionCreators An object whose values are action 5401 * creator functions. One handy way to obtain it is to use ES6 `import * as` 5402 * syntax. You may also pass a single function. 5403 * 5404 * @param {Function} dispatch The `dispatch` function available on your Redux 5405 * store. 5406 * 5407 * @returns {Function|Object} The object mimicking the original object, but with 5408 * every action creator wrapped into the `dispatch` call. If you passed a 5409 * function as `actionCreators`, the return value will also be a single 5410 * function. 5411 */ 5412 5413 5414 function bindActionCreators(actionCreators, dispatch) { 5415 if (typeof actionCreators === 'function') { 5416 return bindActionCreator(actionCreators, dispatch); 5417 } 5418 5419 if (typeof actionCreators !== 'object' || actionCreators === null) { 5420 throw new Error( true ? formatProdErrorMessage(16) : 0); 5421 } 5422 5423 var boundActionCreators = {}; 5424 5425 for (var key in actionCreators) { 5426 var actionCreator = actionCreators[key]; 5427 5428 if (typeof actionCreator === 'function') { 5429 boundActionCreators[key] = bindActionCreator(actionCreator, dispatch); 5430 } 5431 } 5432 5433 return boundActionCreators; 5434 } 5435 5436 /** 5437 * Composes single-argument functions from right to left. The rightmost 5438 * function can take multiple arguments as it provides the signature for 5439 * the resulting composite function. 5440 * 5441 * @param {...Function} funcs The functions to compose. 5442 * @returns {Function} A function obtained by composing the argument functions 5443 * from right to left. For example, compose(f, g, h) is identical to doing 5444 * (...args) => f(g(h(...args))). 5445 */ 5446 function compose() { 5447 for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) { 5448 funcs[_key] = arguments[_key]; 5449 } 5450 5451 if (funcs.length === 0) { 5452 return function (arg) { 5453 return arg; 5454 }; 5455 } 5456 5457 if (funcs.length === 1) { 5458 return funcs[0]; 5459 } 5460 5461 return funcs.reduce(function (a, b) { 5462 return function () { 5463 return a(b.apply(void 0, arguments)); 5464 }; 5465 }); 5466 } 5467 5468 /** 5469 * Creates a store enhancer that applies middleware to the dispatch method 5470 * of the Redux store. This is handy for a variety of tasks, such as expressing 5471 * asynchronous actions in a concise manner, or logging every action payload. 5472 * 5473 * See `redux-thunk` package as an example of the Redux middleware. 5474 * 5475 * Because middleware is potentially asynchronous, this should be the first 5476 * store enhancer in the composition chain. 5477 * 5478 * Note that each middleware will be given the `dispatch` and `getState` functions 5479 * as named arguments. 5480 * 5481 * @param {...Function} middlewares The middleware chain to be applied. 5482 * @returns {Function} A store enhancer applying the middleware. 5483 */ 5484 5485 function applyMiddleware() { 5486 for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) { 5487 middlewares[_key] = arguments[_key]; 5488 } 5489 5490 return function (createStore) { 5491 return function () { 5492 var store = createStore.apply(void 0, arguments); 5493 5494 var _dispatch = function dispatch() { 5495 throw new Error( true ? formatProdErrorMessage(15) : 0); 5496 }; 5497 5498 var middlewareAPI = { 5499 getState: store.getState, 5500 dispatch: function dispatch() { 5501 return _dispatch.apply(void 0, arguments); 5502 } 5503 }; 5504 var chain = middlewares.map(function (middleware) { 5505 return middleware(middlewareAPI); 5506 }); 5507 _dispatch = compose.apply(void 0, chain)(store.dispatch); 5508 return _objectSpread2(_objectSpread2({}, store), {}, { 5509 dispatch: _dispatch 5510 }); 5511 }; 5512 }; 5513 } 5514 5515 /* 5516 * This is a dummy function to check if the function name has been altered by minification. 5517 * If the function has been minified and NODE_ENV !== 'production', warn the user. 5518 */ 5519 5520 function isCrushed() {} 5521 5522 if (false) {} 5523 5524 5525 5526 5527 /***/ }) 5528 5529 /******/ }); 5530 /************************************************************************/ 5531 /******/ // The module cache 5532 /******/ var __webpack_module_cache__ = {}; 5533 /******/ 5534 /******/ // The require function 5535 /******/ function __webpack_require__(moduleId) { 5536 /******/ // Check if module is in cache 5537 /******/ var cachedModule = __webpack_module_cache__[moduleId]; 5538 /******/ if (cachedModule !== undefined) { 5539 /******/ return cachedModule.exports; 5540 /******/ } 5541 /******/ // Create a new module (and put it into the cache) 5542 /******/ var module = __webpack_module_cache__[moduleId] = { 5543 /******/ // no module.id needed 5544 /******/ // no module.loaded needed 5545 /******/ exports: {} 5546 /******/ }; 5547 /******/ 5548 /******/ // Execute the module function 5549 /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); 5550 /******/ 5551 /******/ // Return the exports of the module 5552 /******/ return module.exports; 5553 /******/ } 5554 /******/ 5555 /************************************************************************/ 5556 /******/ /* webpack/runtime/define property getters */ 5557 /******/ !function() { 5558 /******/ // define getter functions for harmony exports 5559 /******/ __webpack_require__.d = function(exports, definition) { 5560 /******/ for(var key in definition) { 5561 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 5562 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 5563 /******/ } 5564 /******/ } 5565 /******/ }; 5566 /******/ }(); 5567 /******/ 5568 /******/ /* webpack/runtime/hasOwnProperty shorthand */ 5569 /******/ !function() { 5570 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } 5571 /******/ }(); 5572 /******/ 5573 /******/ /* webpack/runtime/make namespace object */ 5574 /******/ !function() { 5575 /******/ // define __esModule on exports 5576 /******/ __webpack_require__.r = function(exports) { 5577 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 5578 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 5579 /******/ } 5580 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 5581 /******/ }; 5582 /******/ }(); 5583 /******/ 5584 /************************************************************************/ 5585 /******/ 5586 /******/ // startup 5587 /******/ // Load entry module and return exports 5588 /******/ // This entry module is referenced by other modules so it can't be inlined 5589 /******/ var __webpack_exports__ = __webpack_require__(373); 5590 /******/ __webpack_exports__ = __webpack_exports__["default"]; 5591 /******/ 5592 /******/ return __webpack_exports__; 5593 /******/ })() 5594 ; 5595 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |