2022-03-13 22:22:37 +01:00
/*! choices.js v10.1.0 | © 2022 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
2016-10-18 15:15:00 +02:00
( function webpackUniversalModuleDefinition ( root , factory ) {
if ( typeof exports === 'object' && typeof module === 'object' )
module . exports = factory ( ) ;
else if ( typeof define === 'function' && define . amd )
2016-10-28 22:59:43 +02:00
define ( [ ] , factory ) ;
2016-10-18 15:15:00 +02:00
else if ( typeof exports === 'object' )
exports [ "Choices" ] = factory ( ) ;
else
root [ "Choices" ] = factory ( ) ;
2019-02-09 19:13:25 +01:00
} ) ( window , function ( ) {
2021-12-19 22:58:00 +01:00
return /******/ ( function ( ) { // webpackBootstrap
2022-01-01 00:11:45 +01:00
/******/ "use strict" ;
2021-12-19 22:58:00 +01:00
/******/ var _ _webpack _modules _ _ = ( {
/***/ 282 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
2019-12-23 19:22:54 +01:00
value : true
2021-12-19 22:58:00 +01:00
} ) ) ;
exports . clearChoices = exports . activateChoices = exports . filterChoices = exports . addChoice = void 0 ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var constants _1 = _ _webpack _require _ _ ( 883 ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var addChoice = function ( _a ) {
var value = _a . value ,
label = _a . label ,
id = _a . id ,
groupId = _a . groupId ,
disabled = _a . disabled ,
elementId = _a . elementId ,
customProperties = _a . customProperties ,
placeholder = _a . placeholder ,
keyCode = _a . keyCode ;
return {
type : constants _1 . ACTION _TYPES . ADD _CHOICE ,
value : value ,
label : label ,
id : id ,
groupId : groupId ,
disabled : disabled ,
elementId : elementId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
} ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
exports . addChoice = addChoice ;
var filterChoices = function ( results ) {
return {
type : constants _1 . ACTION _TYPES . FILTER _CHOICES ,
results : results
} ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
exports . filterChoices = filterChoices ;
var activateChoices = function ( active ) {
if ( active === void 0 ) {
active = true ;
}
return {
type : constants _1 . ACTION _TYPES . ACTIVATE _CHOICES ,
active : active
} ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
exports . activateChoices = activateChoices ;
var clearChoices = function ( ) {
return {
type : constants _1 . ACTION _TYPES . CLEAR _CHOICES
} ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
exports . clearChoices = clearChoices ;
2017-11-07 12:59:49 +01:00
2019-12-23 19:22:54 +01:00
/***/ } ) ,
2021-12-19 22:58:00 +01:00
/***/ 783 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
2019-12-23 19:22:54 +01:00
value : true
2021-12-19 22:58:00 +01:00
} ) ) ;
exports . addGroup = void 0 ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
var constants _1 = _ _webpack _require _ _ ( 883 ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var addGroup = function ( _a ) {
var value = _a . value ,
id = _a . id ,
active = _a . active ,
disabled = _a . disabled ;
return {
type : constants _1 . ACTION _TYPES . ADD _GROUP ,
value : value ,
id : id ,
active : active ,
disabled : disabled
} ;
2019-12-23 19:22:54 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
exports . addGroup = addGroup ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
/***/ 464 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
exports . highlightItem = exports . removeItem = exports . addItem = void 0 ;
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
var constants _1 = _ _webpack _require _ _ ( 883 ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var addItem = function ( _a ) {
var value = _a . value ,
label = _a . label ,
id = _a . id ,
choiceId = _a . choiceId ,
groupId = _a . groupId ,
customProperties = _a . customProperties ,
placeholder = _a . placeholder ,
keyCode = _a . keyCode ;
return {
type : constants _1 . ACTION _TYPES . ADD _ITEM ,
value : value ,
label : label ,
id : id ,
choiceId : choiceId ,
groupId : groupId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
} ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
exports . addItem = addItem ;
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
var removeItem = function ( id , choiceId ) {
return {
type : constants _1 . ACTION _TYPES . REMOVE _ITEM ,
id : id ,
choiceId : choiceId
} ;
} ;
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
exports . removeItem = removeItem ;
var highlightItem = function ( id , highlighted ) {
return {
type : constants _1 . ACTION _TYPES . HIGHLIGHT _ITEM ,
id : id ,
highlighted : highlighted
} ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
exports . highlightItem = highlightItem ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
/***/ 137 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
exports . setIsLoading = exports . resetTo = exports . clearAll = void 0 ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var constants _1 = _ _webpack _require _ _ ( 883 ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var clearAll = function ( ) {
return {
type : constants _1 . ACTION _TYPES . CLEAR _ALL
} ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
exports . clearAll = clearAll ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var resetTo = function ( state ) {
return {
type : constants _1 . ACTION _TYPES . RESET _TO ,
state : state
2019-12-23 19:22:54 +01:00
} ;
} ;
2021-12-19 22:58:00 +01:00
exports . resetTo = resetTo ;
var setIsLoading = function ( isLoading ) {
return {
type : constants _1 . ACTION _TYPES . SET _IS _LOADING ,
isLoading : isLoading
} ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
exports . setIsLoading = setIsLoading ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
/***/ 373 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2017-11-15 07:51:53 +01:00
2019-12-23 19:22:54 +01:00
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var _ _spreadArray = this && this . _ _spreadArray || function ( to , from , pack ) {
if ( pack || arguments . length === 2 ) for ( var i = 0 , l = from . length , ar ; i < l ; i ++ ) {
if ( ar || ! ( i in from ) ) {
if ( ! ar ) ar = Array . prototype . slice . call ( from , 0 , i ) ;
ar [ i ] = from [ i ] ;
}
}
return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
2019-12-23 19:22:54 +01:00
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var _ _importDefault = this && this . _ _importDefault || function ( mod ) {
return mod && mod . _ _esModule ? mod : {
"default" : mod
} ;
2019-12-23 19:22:54 +01:00
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var deepmerge _1 = _ _importDefault ( _ _webpack _require _ _ ( 996 ) ) ;
/* eslint-disable @typescript-eslint/no-explicit-any */
2019-02-09 19:13:25 +01:00
2022-01-01 00:11:45 +01:00
var fuse _js _1 = _ _importDefault ( _ _webpack _require _ _ ( 221 ) ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var choices _1 = _ _webpack _require _ _ ( 282 ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var groups _1 = _ _webpack _require _ _ ( 783 ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var items _1 = _ _webpack _require _ _ ( 464 ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var misc _1 = _ _webpack _require _ _ ( 137 ) ;
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
var components _1 = _ _webpack _require _ _ ( 520 ) ;
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
var constants _1 = _ _webpack _require _ _ ( 883 ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var defaults _1 = _ _webpack _require _ _ ( 789 ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var utils _1 = _ _webpack _require _ _ ( 799 ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var reducers _1 = _ _webpack _require _ _ ( 655 ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var store _1 = _ _importDefault ( _ _webpack _require _ _ ( 744 ) ) ;
var templates _1 = _ _importDefault ( _ _webpack _require _ _ ( 686 ) ) ;
/** @see {@link http://browserhacks.com/#hack-acea075d0ac6954f275a70023906050c} */
2017-11-15 07:51:53 +01:00
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
var IS _IE11 = '-ms-scroll-limit' in document . documentElement . style && '-ms-ime-align' in document . documentElement . style ;
var USER _DEFAULTS = { } ;
2019-10-22 23:20:40 +02:00
/ * *
2021-12-19 22:58:00 +01:00
* Choices
* @ author Josh Johnson < josh @ joshuajohnson . co . uk >
2019-10-22 23:20:40 +02:00
* /
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var Choices =
/** @class */
function ( ) {
function Choices ( element , userConfig ) {
var _this = this ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( element === void 0 ) {
element = '[data-choice]' ;
2018-10-13 12:19:24 +02:00
}
2021-12-19 22:58:00 +01:00
if ( userConfig === void 0 ) {
userConfig = { } ;
}
2017-11-07 12:59:49 +01:00
2021-12-24 18:33:32 +01:00
if ( userConfig . allowHTML === undefined ) {
2021-12-26 15:36:12 +01:00
console . warn ( 'Deprecation warning: allowHTML will default to false in a future release. To render HTML in Choices, you will need to set it to true. Setting allowHTML will suppress this message.' ) ;
2021-12-24 18:33:32 +01:00
}
2021-12-19 22:58:00 +01:00
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,
// instead of concatenating with the default array
{
arrayMerge : function ( _ , sourceArray ) {
return _ _spreadArray ( [ ] , sourceArray , true ) ;
}
} ) ;
var invalidConfigOptions = ( 0 , utils _1 . diff ) ( this . config , defaults _1 . DEFAULT _CONFIG ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( invalidConfigOptions . length ) {
console . warn ( 'Unknown config option(s) passed' , invalidConfigOptions . join ( ', ' ) ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var passedElement = typeof element === 'string' ? document . querySelector ( element ) : element ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( ! ( passedElement instanceof HTMLInputElement || passedElement instanceof HTMLSelectElement ) ) {
throw TypeError ( 'Expected one of the following types text|select-one|select-multiple' ) ;
2019-10-22 23:20:40 +02:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . _isTextElement = passedElement . type === constants _1 . TEXT _TYPE ;
this . _isSelectOneElement = passedElement . type === constants _1 . SELECT _ONE _TYPE ;
this . _isSelectMultipleElement = passedElement . type === constants _1 . SELECT _MULTIPLE _TYPE ;
this . _isSelectElement = this . _isSelectOneElement || this . _isSelectMultipleElement ;
this . config . searchEnabled = this . _isSelectMultipleElement || this . config . searchEnabled ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( ! [ 'auto' , 'always' ] . includes ( "" . concat ( this . config . renderSelectedChoices ) ) ) {
this . config . renderSelectedChoices = 'auto' ;
2017-11-15 07:51:53 +01:00
}
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
if ( userConfig . addItemFilter && typeof userConfig . addItemFilter !== 'function' ) {
var re = userConfig . addItemFilter instanceof RegExp ? userConfig . addItemFilter : new RegExp ( userConfig . addItemFilter ) ;
this . config . addItemFilter = re . test . bind ( re ) ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isTextElement ) {
this . passedElement = new components _1 . WrappedInput ( {
element : passedElement ,
classNames : this . config . classNames ,
delimiter : this . config . delimiter
} ) ;
} else {
this . passedElement = new components _1 . WrappedSelect ( {
element : passedElement ,
classNames : this . config . classNames ,
template : function ( data ) {
return _this . _templates . option ( data ) ;
}
} ) ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . initialised = false ;
this . _store = new store _1 . default ( ) ;
this . _initialState = reducers _1 . defaultState ;
this . _currentState = reducers _1 . defaultState ;
this . _prevState = reducers _1 . defaultState ;
this . _currentValue = '' ;
this . _canSearch = ! ! this . config . searchEnabled ;
this . _isScrollingOnIe = false ;
this . _highlightPosition = 0 ;
this . _wasTap = true ;
this . _placeholderValue = this . _generatePlaceholderValue ( ) ;
this . _baseId = ( 0 , utils _1 . generateId ) ( this . passedElement . element , 'choices-' ) ;
/ * *
* setting direction in cases where it ' s explicitly set on passedElement
* or when calculated direction is different from the document
* /
this . _direction = this . passedElement . dir ;
if ( ! this . _direction ) {
var elementDirection = window . getComputedStyle ( this . passedElement . element ) . direction ;
var documentDirection = window . getComputedStyle ( document . documentElement ) . direction ;
if ( elementDirection !== documentDirection ) {
this . _direction = elementDirection ;
2019-10-22 23:20:40 +02:00
}
2021-12-19 22:58:00 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _idNames = {
itemChoice : 'item-choice'
2019-10-22 23:20:40 +02:00
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectElement ) {
// Assign preset groups from passed element
this . _presetGroups = this . passedElement . optionGroups ; // Assign preset options from passed element
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
this . _presetOptions = this . passedElement . options ;
} // Assign preset choices from passed object
2019-02-09 19:13:25 +01:00
2018-10-30 23:10:21 +01:00
2021-12-19 22:58:00 +01:00
this . _presetChoices = this . config . choices ; // Assign preset items from passed object first
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . _presetItems = this . config . items ; // Add any values passed from attribute
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . passedElement . value && this . _isTextElement ) {
var splitValues = this . passedElement . value . split ( this . config . delimiter ) ;
this . _presetItems = this . _presetItems . concat ( splitValues ) ;
} // Create array of choices from option elements
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . passedElement . options ) {
this . passedElement . options . forEach ( function ( option ) {
_this . _presetChoices . push ( {
value : option . value ,
label : option . innerHTML ,
selected : ! ! option . selected ,
disabled : option . disabled || option . parentNode . disabled ,
placeholder : option . value === '' || option . hasAttribute ( 'placeholder' ) ,
2022-03-14 15:57:05 +01:00
customProperties : ( 0 , utils _1 . parseCustomProperties ) ( option . dataset . customProperties )
2021-12-19 22:58:00 +01:00
} ) ;
} ) ;
2019-10-22 23:20:40 +02:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . _render = this . _render . bind ( this ) ;
this . _onFocus = this . _onFocus . bind ( this ) ;
this . _onBlur = this . _onBlur . bind ( this ) ;
this . _onKeyUp = this . _onKeyUp . bind ( this ) ;
this . _onKeyDown = this . _onKeyDown . bind ( this ) ;
this . _onClick = this . _onClick . bind ( this ) ;
this . _onTouchMove = this . _onTouchMove . bind ( this ) ;
this . _onTouchEnd = this . _onTouchEnd . bind ( this ) ;
this . _onMouseDown = this . _onMouseDown . bind ( this ) ;
this . _onMouseOver = this . _onMouseOver . bind ( this ) ;
this . _onFormReset = this . _onFormReset . bind ( this ) ;
this . _onSelectKey = this . _onSelectKey . bind ( this ) ;
this . _onEnterKey = this . _onEnterKey . bind ( this ) ;
this . _onEscapeKey = this . _onEscapeKey . bind ( this ) ;
this . _onDirectionKey = this . _onDirectionKey . bind ( this ) ;
this . _onDeleteKey = this . _onDeleteKey . bind ( this ) ; // If element has already been initialised with Choices, fail silently
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . passedElement . isActive ) {
if ( ! this . config . silent ) {
console . warn ( 'Trying to initialise Choices on element already initialised' , {
element : element
} ) ;
}
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
this . initialised = true ;
return ;
} // Let's go
2018-10-30 23:10:21 +01:00
2021-12-19 22:58:00 +01:00
this . init ( ) ;
2019-10-22 23:20:40 +02:00
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( Choices , "defaults" , {
get : function ( ) {
return Object . preventExtensions ( {
get options ( ) {
return USER _DEFAULTS ;
} ,
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
get templates ( ) {
return templates _1 . default ;
2019-10-22 23:20:40 +02:00
}
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
} ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . init = function ( ) {
if ( this . initialised ) {
return ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _createTemplates ( ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . _createElements ( ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _createStructure ( ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _store . subscribe ( this . _render ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . _render ( ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _addEventListeners ( ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var shouldDisable = ! this . config . addItems || this . passedElement . element . hasAttribute ( 'disabled' ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( shouldDisable ) {
this . disable ( ) ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . initialised = true ;
var callbackOnInit = this . config . callbackOnInit ; // Run callback if it is a function
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( callbackOnInit && typeof callbackOnInit === 'function' ) {
callbackOnInit . call ( this ) ;
}
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . destroy = function ( ) {
if ( ! this . initialised ) {
return ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
this . _removeEventListeners ( ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . passedElement . reveal ( ) ;
this . containerOuter . unwrap ( this . passedElement . element ) ;
this . clearStore ( ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectElement ) {
this . passedElement . options = this . _presetOptions ;
2017-11-07 12:59:49 +01:00
}
2021-12-19 22:58:00 +01:00
this . _templates = templates _1 . default ;
this . initialised = false ;
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . enable = function ( ) {
if ( this . passedElement . isDisabled ) {
this . passedElement . enable ( ) ;
}
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
if ( this . containerOuter . isDisabled ) {
this . _addEventListeners ( ) ;
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
this . input . enable ( ) ;
this . containerOuter . enable ( ) ;
2017-11-15 07:51:53 +01:00
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . disable = function ( ) {
if ( ! this . passedElement . isDisabled ) {
this . passedElement . disable ( ) ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . containerOuter . isDisabled ) {
this . _removeEventListeners ( ) ;
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
this . input . disable ( ) ;
this . containerOuter . disable ( ) ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . highlightItem = function ( item , runEvent ) {
if ( runEvent === void 0 ) {
runEvent = true ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( ! item || ! item . id ) {
return this ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var id = item . id ,
_a = item . groupId ,
groupId = _a === void 0 ? - 1 : _a ,
_b = item . value ,
value = _b === void 0 ? '' : _b ,
_c = item . label ,
label = _c === void 0 ? '' : _c ;
var group = groupId >= 0 ? this . _store . getGroupById ( groupId ) : null ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _store . dispatch ( ( 0 , items _1 . highlightItem ) ( id , true ) ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( runEvent ) {
this . passedElement . triggerEvent ( constants _1 . EVENTS . highlightItem , {
id : id ,
value : value ,
label : label ,
groupValue : group && group . value ? group . value : null
} ) ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . unhighlightItem = function ( item ) {
if ( ! item || ! item . id ) {
return this ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var id = item . id ,
_a = item . groupId ,
groupId = _a === void 0 ? - 1 : _a ,
_b = item . value ,
value = _b === void 0 ? '' : _b ,
_c = item . label ,
label = _c === void 0 ? '' : _c ;
var group = groupId >= 0 ? this . _store . getGroupById ( groupId ) : null ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
this . _store . dispatch ( ( 0 , items _1 . highlightItem ) ( id , false ) ) ;
this . passedElement . triggerEvent ( constants _1 . EVENTS . highlightItem , {
id : id ,
value : value ,
label : label ,
groupValue : group && group . value ? group . value : null
} ) ;
return this ;
2019-10-22 23:20:40 +02:00
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . highlightAll = function ( ) {
var _this = this ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
this . _store . items . forEach ( function ( item ) {
return _this . highlightItem ( item ) ;
} ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . unhighlightAll = function ( ) {
var _this = this ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _store . items . forEach ( function ( item ) {
return _this . unhighlightItem ( item ) ;
} ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . removeActiveItemsByValue = function ( value ) {
var _this = this ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _store . activeItems . filter ( function ( item ) {
return item . value === value ;
} ) . forEach ( function ( item ) {
return _this . _removeItem ( item ) ;
2019-10-22 23:20:40 +02:00
} ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . removeActiveItems = function ( excludedId ) {
var _this = this ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . _store . activeItems . filter ( function ( _a ) {
var id = _a . id ;
return id !== excludedId ;
} ) . forEach ( function ( item ) {
return _this . _removeItem ( item ) ;
} ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . removeHighlightedItems = function ( runEvent ) {
var _this = this ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( runEvent === void 0 ) {
runEvent = false ;
2017-11-07 12:59:49 +01:00
}
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
this . _store . highlightedActiveItems . forEach ( function ( item ) {
_this . _removeItem ( item ) ; // If this action was performed by the user
// trigger the event
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
if ( runEvent ) {
_this . _triggerChange ( item . value ) ;
}
} ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
return this ;
2019-10-22 23:20:40 +02:00
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . showDropdown = function ( preventInputFocus ) {
var _this = this ;
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
if ( this . dropdown . isActive ) {
return this ;
}
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
requestAnimationFrame ( function ( ) {
_this . dropdown . show ( ) ;
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
_this . containerOuter . open ( _this . dropdown . distanceFromTopWindow ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( ! preventInputFocus && _this . _canSearch ) {
_this . input . focus ( ) ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
_this . passedElement . triggerEvent ( constants _1 . EVENTS . showDropdown , { } ) ;
} ) ;
return this ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
Choices . prototype . hideDropdown = function ( preventInputBlur ) {
var _this = this ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . dropdown . isActive ) {
return this ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
requestAnimationFrame ( function ( ) {
_this . dropdown . hide ( ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
_this . containerOuter . close ( ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( ! preventInputBlur && _this . _canSearch ) {
_this . input . removeActiveDescendant ( ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
_this . input . blur ( ) ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
_this . passedElement . triggerEvent ( constants _1 . EVENTS . hideDropdown , { } ) ;
} ) ;
return this ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . getValue = function ( valueOnly ) {
if ( valueOnly === void 0 ) {
valueOnly = false ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var values = this . _store . activeItems . reduce ( function ( selectedItems , item ) {
var itemValue = valueOnly ? item . value : item ;
selectedItems . push ( itemValue ) ;
return selectedItems ;
} , [ ] ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
return this . _isSelectOneElement ? values [ 0 ] : values ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . setValue = function ( items ) {
var _this = this ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . initialised ) {
return this ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
items . forEach ( function ( value ) {
return _this . _setChoiceOrItem ( value ) ;
} ) ;
return this ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . setChoiceByValue = function ( value ) {
var _this = this ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . initialised || this . _isTextElement ) {
return this ;
} // If only one value has been passed, convert to array
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var choiceValue = Array . isArray ( value ) ? value : [ value ] ; // Loop through each value and
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
choiceValue . forEach ( function ( val ) {
return _this . _findAndSelectChoiceByValue ( val ) ;
} ) ;
return this ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
/ * *
* Set choices of select input via an array of objects ( or function that returns array of object or promise of it ) ,
* a value field name and a label field name .
* This behaves the same as passing items via the choices option but can be called after initialising Choices .
* This can also be used to add groups of choices ( see example 2 ) ; Optionally pass a true ` replaceChoices ` value to remove any existing choices .
* Optionally pass a ` customProperties ` object to add additional data to your choices ( useful when searching / filtering etc ) .
*
* * * Input types affected : * * select - one , select - multiple
*
* @ example
* ` ` ` js
* const example = new Choices ( element ) ;
*
* example . setChoices ( [
* { value : 'One' , label : 'Label One' , disabled : true } ,
* { value : 'Two' , label : 'Label Two' , selected : true } ,
* { value : 'Three' , label : 'Label Three' } ,
* ] , 'value' , 'label' , false ) ;
* ` ` `
*
* @ example
* ` ` ` js
* const example = new Choices ( element ) ;
*
* example . setChoices ( async ( ) => {
* try {
* const items = await fetch ( '/items' ) ;
* return items . json ( )
* } catch ( err ) {
* console . error ( err )
* }
* } ) ;
* ` ` `
*
* @ example
* ` ` ` js
* const example = new Choices ( element ) ;
*
* example . setChoices ( [ {
* label : 'Group one' ,
* id : 1 ,
* disabled : false ,
* choices : [
* { value : 'Child One' , label : 'Child One' , selected : true } ,
* { value : 'Child Two' , label : 'Child Two' , disabled : true } ,
* { value : 'Child Three' , label : 'Child Three' } ,
* ]
* } ,
* {
* label : 'Group two' ,
* id : 2 ,
* disabled : false ,
* choices : [
* { value : 'Child Four' , label : 'Child Four' , disabled : true } ,
* { value : 'Child Five' , label : 'Child Five' } ,
* { value : 'Child Six' , label : 'Child Six' , customProperties : {
* description : 'Custom description about child six' ,
* random : 'Another random custom property'
* } } ,
* ]
* } ] , 'value' , 'label' , false ) ;
* ` ` `
* /
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . setChoices = function ( choicesArrayOrFetcher , value , label , replaceChoices ) {
var _this = this ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( choicesArrayOrFetcher === void 0 ) {
choicesArrayOrFetcher = [ ] ;
2019-12-23 19:22:54 +01:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( value === void 0 ) {
value = 'value' ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( label === void 0 ) {
label = 'label' ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( replaceChoices === void 0 ) {
replaceChoices = false ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . initialised ) {
throw new ReferenceError ( "setChoices was called on a non-initialized instance of Choices" ) ;
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( ! this . _isSelectElement ) {
throw new TypeError ( "setChoices can't be used with INPUT based Choices" ) ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( typeof value !== 'string' || ! value ) {
throw new TypeError ( "value parameter must be a name of 'value' field in passed objects" ) ;
} // Clear choices if needed
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( replaceChoices ) {
this . clearChoices ( ) ;
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( typeof choicesArrayOrFetcher === 'function' ) {
// it's a choices fetcher function
var fetcher _1 = choicesArrayOrFetcher ( this ) ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( typeof Promise === 'function' && fetcher _1 instanceof Promise ) {
// that's a promise
// eslint-disable-next-line no-promise-executor-return
return new Promise ( function ( resolve ) {
return requestAnimationFrame ( resolve ) ;
} ) . then ( function ( ) {
return _this . _handleLoadingState ( true ) ;
} ) . then ( function ( ) {
return fetcher _1 ;
} ) . then ( function ( data ) {
return _this . setChoices ( data , value , label , replaceChoices ) ;
} ) . catch ( function ( err ) {
if ( ! _this . config . silent ) {
console . error ( err ) ;
}
} ) . then ( function ( ) {
return _this . _handleLoadingState ( false ) ;
} ) . then ( function ( ) {
return _this ;
} ) ;
} // function returned something else than promise, let's check if it's an array of choices
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( ! Array . isArray ( fetcher _1 ) ) {
throw new TypeError ( ".setChoices first argument function must return either array of choices or Promise, got: " . concat ( typeof fetcher _1 ) ) ;
} // recursion with results, it's sync and choices were cleared already
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
return this . setChoices ( fetcher _1 , value , label , false ) ;
2019-12-23 19:22:54 +01:00
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( ! Array . isArray ( choicesArrayOrFetcher ) ) {
throw new TypeError ( ".setChoices must be called either with array of choices with a function resulting into Promise of array of choices" ) ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
this . containerOuter . removeLoadingState ( ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
this . _startLoading ( ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
choicesArrayOrFetcher . forEach ( function ( groupOrChoice ) {
if ( groupOrChoice . choices ) {
_this . _addGroup ( {
id : groupOrChoice . id ? parseInt ( "" . concat ( groupOrChoice . id ) , 10 ) : null ,
group : groupOrChoice ,
valueKey : value ,
labelKey : label
} ) ;
} else {
var choice = groupOrChoice ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
_this . _addChoice ( {
value : choice [ value ] ,
label : choice [ label ] ,
isSelected : ! ! choice . selected ,
isDisabled : ! ! choice . disabled ,
placeholder : ! ! choice . placeholder ,
customProperties : choice . customProperties
} ) ;
}
} ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _stopLoading ( ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . clearChoices = function ( ) {
this . _store . dispatch ( ( 0 , choices _1 . clearChoices ) ( ) ) ;
2018-06-07 17:54:11 +02:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . clearStore = function ( ) {
this . _store . dispatch ( ( 0 , misc _1 . clearAll ) ( ) ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . clearInput = function ( ) {
var shouldSetInputWidth = ! this . _isSelectOneElement ;
this . input . clear ( shouldSetInputWidth ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . _isTextElement && this . _canSearch ) {
this . _isSearching = false ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
this . _store . dispatch ( ( 0 , choices _1 . activateChoices ) ( true ) ) ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _render = function ( ) {
if ( this . _store . isLoading ( ) ) {
return ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
this . _currentState = this . _store . state ;
var stateChanged = this . _currentState . choices !== this . _prevState . choices || this . _currentState . groups !== this . _prevState . groups || this . _currentState . items !== this . _prevState . items ;
var shouldRenderChoices = this . _isSelectElement ;
var shouldRenderItems = this . _currentState . items !== this . _prevState . items ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( ! stateChanged ) {
return ;
2019-12-23 19:22:54 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( shouldRenderChoices ) {
this . _renderChoices ( ) ;
2019-12-23 19:22:54 +01:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( shouldRenderItems ) {
this . _renderItems ( ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
this . _prevState = this . _currentState ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _renderChoices = function ( ) {
var _this = this ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
var _a = this . _store ,
activeGroups = _a . activeGroups ,
activeChoices = _a . activeChoices ;
var choiceListFragment = document . createDocumentFragment ( ) ;
this . choiceList . clear ( ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . config . resetScrollPosition ) {
requestAnimationFrame ( function ( ) {
return _this . choiceList . scrollToTop ( ) ;
2019-12-23 19:22:54 +01:00
} ) ;
2021-12-19 22:58:00 +01:00
} // If we have grouped options
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( activeGroups . length >= 1 && ! this . _isSearching ) {
// If we have a placeholder choice along with groups
var activePlaceholders = activeChoices . filter ( function ( activeChoice ) {
return activeChoice . placeholder === true && activeChoice . groupId === - 1 ;
} ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( activePlaceholders . length >= 1 ) {
choiceListFragment = this . _createChoicesFragment ( activePlaceholders , choiceListFragment ) ;
2019-12-23 19:22:54 +01:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
choiceListFragment = this . _createGroupsFragment ( activeGroups , activeChoices , choiceListFragment ) ;
} else if ( activeChoices . length >= 1 ) {
choiceListFragment = this . _createChoicesFragment ( activeChoices , choiceListFragment ) ;
} // If we have choices to show
2019-11-03 18:45:16 +01:00
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( choiceListFragment . childNodes && choiceListFragment . childNodes . length > 0 ) {
var activeItems = this . _store . activeItems ;
var canAddItem = this . _canAddItem ( activeItems , this . input . value ) ; // ...and we can select them
2017-11-15 07:51:53 +01:00
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( canAddItem . response ) {
// ...append them and highlight the first choice
this . choiceList . append ( choiceListFragment ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
this . _highlightChoice ( ) ;
} else {
var notice = this . _getTemplate ( 'notice' , canAddItem . notice ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . choiceList . append ( notice ) ;
}
} else {
// Otherwise show a notice
var dropdownItem = void 0 ;
var notice = void 0 ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSearching ) {
notice = typeof this . config . noResultsText === 'function' ? this . config . noResultsText ( ) : this . config . noResultsText ;
dropdownItem = this . _getTemplate ( 'notice' , notice , 'no-results' ) ;
} else {
notice = typeof this . config . noChoicesText === 'function' ? this . config . noChoicesText ( ) : this . config . noChoicesText ;
dropdownItem = this . _getTemplate ( 'notice' , notice , 'no-choices' ) ;
}
2018-05-28 17:22:22 +02:00
2021-12-19 22:58:00 +01:00
this . choiceList . append ( dropdownItem ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _renderItems = function ( ) {
var activeItems = this . _store . activeItems || [ ] ;
this . itemList . clear ( ) ; // Create a fragment to store our list items
// (so we don't have to update the DOM for each item)
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var itemListFragment = this . _createItemsFragment ( activeItems ) ; // If we have items to add, append them
2018-05-28 17:22:22 +02:00
2021-12-19 22:58:00 +01:00
if ( itemListFragment . childNodes ) {
this . itemList . append ( itemListFragment ) ;
}
} ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _createGroupsFragment = function ( groups , choices , fragment ) {
var _this = this ;
2018-05-27 12:57:21 +02:00
2021-12-19 22:58:00 +01:00
if ( fragment === void 0 ) {
fragment = document . createDocumentFragment ( ) ;
}
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
var getGroupChoices = function ( group ) {
return choices . filter ( function ( choice ) {
if ( _this . _isSelectOneElement ) {
return choice . groupId === group . id ;
2019-12-23 19:22:54 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
return choice . groupId === group . id && ( _this . config . renderSelectedChoices === 'always' || ! choice . selected ) ;
2019-12-23 19:22:54 +01:00
} ) ;
2021-12-19 22:58:00 +01:00
} ; // If sorting is enabled, filter groups
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . config . shouldSort ) {
groups . sort ( this . config . sorter ) ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
groups . forEach ( function ( group ) {
var groupChoices = getGroupChoices ( group ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( groupChoices . length >= 1 ) {
var dropdownGroup = _this . _getTemplate ( 'choiceGroup' , group ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
fragment . appendChild ( dropdownGroup ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
_this . _createChoicesFragment ( groupChoices , fragment , true ) ;
}
} ) ;
return fragment ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _createChoicesFragment = function ( choices , fragment , withinGroup ) {
var _this = this ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( fragment === void 0 ) {
fragment = document . createDocumentFragment ( ) ;
2019-12-23 19:22:54 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( withinGroup === void 0 ) {
withinGroup = false ;
} // Create a fragment to store our list items (so we don't have to update the DOM for each item)
2018-05-27 12:57:21 +02:00
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var _a = this . config ,
renderSelectedChoices = _a . renderSelectedChoices ,
searchResultLimit = _a . searchResultLimit ,
renderChoiceLimit = _a . renderChoiceLimit ;
var filter = this . _isSearching ? utils _1 . sortByScore : this . config . sorter ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var appendChoice = function ( choice ) {
var shouldRender = renderSelectedChoices === 'auto' ? _this . _isSelectOneElement || ! choice . selected : true ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( shouldRender ) {
var dropdownItem = _this . _getTemplate ( 'choice' , choice , _this . config . itemSelectText ) ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
fragment . appendChild ( dropdownItem ) ;
}
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var rendererableChoices = choices ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( renderSelectedChoices === 'auto' && ! this . _isSelectOneElement ) {
rendererableChoices = choices . filter ( function ( choice ) {
return ! choice . selected ;
} ) ;
} // Split array into placeholders and "normal" choices
2019-12-23 19:22:54 +01:00
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var _b = rendererableChoices . reduce ( function ( acc , choice ) {
if ( choice . placeholder ) {
acc . placeholderChoices . push ( choice ) ;
} else {
acc . normalChoices . push ( choice ) ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
return acc ;
} , {
placeholderChoices : [ ] ,
normalChoices : [ ]
} ) ,
placeholderChoices = _b . placeholderChoices ,
normalChoices = _b . normalChoices ; // If sorting is enabled or the user is searching, filter choices
2019-02-09 19:13:25 +01:00
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( this . config . shouldSort || this . _isSearching ) {
normalChoices . sort ( filter ) ;
2018-05-28 17:22:22 +02:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var choiceLimit = rendererableChoices . length ; // Prepend placeholeder
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
var sortedChoices = this . _isSelectOneElement ? _ _spreadArray ( _ _spreadArray ( [ ] , placeholderChoices , true ) , normalChoices , true ) : normalChoices ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSearching ) {
choiceLimit = searchResultLimit ;
} else if ( renderChoiceLimit && renderChoiceLimit > 0 && ! withinGroup ) {
choiceLimit = renderChoiceLimit ;
} // Add each choice to dropdown within range
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
for ( var i = 0 ; i < choiceLimit ; i += 1 ) {
if ( sortedChoices [ i ] ) {
appendChoice ( sortedChoices [ i ] ) ;
}
2017-11-07 12:59:49 +01:00
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
return fragment ;
2019-12-23 19:22:54 +01:00
} ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _createItemsFragment = function ( items , fragment ) {
var _this = this ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( fragment === void 0 ) {
fragment = document . createDocumentFragment ( ) ;
} // Create fragment to add elements to
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var _a = this . config ,
shouldSortItems = _a . shouldSortItems ,
sorter = _a . sorter ,
removeItemButton = _a . removeItemButton ; // If sorting is enabled, filter items
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( shouldSortItems && ! this . _isSelectOneElement ) {
items . sort ( sorter ) ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isTextElement ) {
// Update the value of the hidden input
this . passedElement . value = items . map ( function ( _a ) {
var value = _a . value ;
return value ;
} ) . join ( this . config . delimiter ) ;
} else {
// Update the options of the hidden input
this . passedElement . options = items ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var addItemToFragment = function ( item ) {
// Create new list element
var listItem = _this . _getTemplate ( 'item' , item , removeItemButton ) ; // Append it to list
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
fragment . appendChild ( listItem ) ;
} ; // Add each list item to list
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
items . forEach ( addItemToFragment ) ;
return fragment ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
Choices . prototype . _triggerChange = function ( value ) {
if ( value === undefined || value === null ) {
return ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
this . passedElement . triggerEvent ( constants _1 . EVENTS . change , {
value : value
2019-12-23 19:22:54 +01:00
} ) ;
2017-11-15 07:51:53 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _selectPlaceholderChoice = function ( placeholderChoice ) {
this . _addItem ( {
value : placeholderChoice . value ,
label : placeholderChoice . label ,
choiceId : placeholderChoice . id ,
groupId : placeholderChoice . groupId ,
placeholder : placeholderChoice . placeholder
2019-12-23 19:22:54 +01:00
} ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _triggerChange ( placeholderChoice . value ) ;
2019-12-23 19:22:54 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _handleButtonAction = function ( activeItems , element ) {
if ( ! activeItems || ! element || ! this . config . removeItems || ! this . config . removeItemButton ) {
return ;
2019-12-23 19:22:54 +01:00
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
var itemId = element . parentNode && element . parentNode . dataset . id ;
var itemToRemove = itemId && activeItems . find ( function ( item ) {
return item . id === parseInt ( itemId , 10 ) ;
2019-12-23 19:22:54 +01:00
} ) ;
2021-12-19 22:58:00 +01:00
if ( ! itemToRemove ) {
return ;
} // Remove item associated with button
2019-10-22 23:20:40 +02:00
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
this . _removeItem ( itemToRemove ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _triggerChange ( itemToRemove . value ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectOneElement && this . _store . placeholderChoice ) {
this . _selectPlaceholderChoice ( this . _store . placeholderChoice ) ;
}
2019-11-03 18:45:16 +01:00
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _handleItemAction = function ( activeItems , element , hasShiftKey ) {
2019-12-23 19:22:54 +01:00
var _this = this ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( hasShiftKey === void 0 ) {
hasShiftKey = false ;
2019-12-23 19:22:54 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( ! activeItems || ! element || ! this . config . removeItems || this . _isSelectOneElement ) {
return ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var passedId = element . dataset . id ; // We only want to select one item with a click
// so we deselect any items that aren't the target
// unless shift is being pressed
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
activeItems . forEach ( function ( item ) {
if ( item . id === parseInt ( "" . concat ( passedId ) , 10 ) && ! item . highlighted ) {
_this . highlightItem ( item ) ;
} else if ( ! hasShiftKey && item . highlighted ) {
_this . unhighlightItem ( item ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ) ; // Focus input as without focus, a user cannot do anything with a
// highlighted item
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
this . input . focus ( ) ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
Choices . prototype . _handleChoiceAction = function ( activeItems , element ) {
if ( ! activeItems || ! element ) {
return ;
} // If we are clicking on an option
2019-02-09 19:13:25 +01:00
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
var id = element . dataset . id ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
var choice = id && this . _store . getChoiceById ( id ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( ! choice ) {
return ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
var passedKeyCode = activeItems [ 0 ] && activeItems [ 0 ] . keyCode ? activeItems [ 0 ] . keyCode : undefined ;
var hasActiveDropdown = this . dropdown . isActive ; // Update choice keyCode
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
choice . keyCode = passedKeyCode ;
this . passedElement . triggerEvent ( constants _1 . EVENTS . choice , {
choice : choice
2019-12-23 19:22:54 +01:00
} ) ;
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
if ( ! choice . selected && ! choice . disabled ) {
var canAddItem = this . _canAddItem ( activeItems , choice . value ) ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
if ( canAddItem . response ) {
this . _addItem ( {
value : choice . value ,
label : choice . label ,
choiceId : choice . id ,
groupId : choice . groupId ,
customProperties : choice . customProperties ,
placeholder : choice . placeholder ,
keyCode : choice . keyCode
} ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
this . _triggerChange ( choice . value ) ;
}
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . clearInput ( ) ; // We want to close the dropdown if we are dealing with a single select box
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( hasActiveDropdown && this . _isSelectOneElement ) {
this . hideDropdown ( true ) ;
this . containerOuter . focus ( ) ;
2019-10-22 23:20:40 +02:00
}
2021-12-19 22:58:00 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _handleBackspace = function ( activeItems ) {
if ( ! this . config . removeItems || ! activeItems ) {
return ;
2019-10-22 23:20:40 +02:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var lastItem = activeItems [ activeItems . length - 1 ] ;
var hasHighlightedItems = activeItems . some ( function ( item ) {
return item . highlighted ;
} ) ; // If editing the last item is allowed and there are not other selected items,
// we can edit the item value. Otherwise if we can remove items, remove all selected items
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( this . config . editItems && ! hasHighlightedItems && lastItem ) {
this . input . value = lastItem . value ;
this . input . setWidth ( ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . _removeItem ( lastItem ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
this . _triggerChange ( lastItem . value ) ;
} else {
if ( ! hasHighlightedItems ) {
// Highlight last item if none already highlighted
this . highlightItem ( lastItem , false ) ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
this . removeHighlightedItems ( true ) ;
2019-10-22 23:20:40 +02:00
}
2021-12-19 22:58:00 +01:00
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _startLoading = function ( ) {
this . _store . dispatch ( ( 0 , misc _1 . setIsLoading ) ( true ) ) ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _stopLoading = function ( ) {
this . _store . dispatch ( ( 0 , misc _1 . setIsLoading ) ( false ) ) ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _handleLoadingState = function ( setLoading ) {
if ( setLoading === void 0 ) {
setLoading = true ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
var placeholderItem = this . itemList . getChild ( "." . concat ( this . config . classNames . placeholder ) ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( setLoading ) {
this . disable ( ) ;
this . containerOuter . addLoadingState ( ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectOneElement ) {
if ( ! placeholderItem ) {
placeholderItem = this . _getTemplate ( 'placeholder' , this . config . loadingText ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( placeholderItem ) {
this . itemList . append ( placeholderItem ) ;
}
} else {
placeholderItem . innerHTML = this . config . loadingText ;
}
2019-12-23 19:22:54 +01:00
} else {
2021-12-19 22:58:00 +01:00
this . input . placeholder = this . config . loadingText ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} else {
this . enable ( ) ;
this . containerOuter . removeLoadingState ( ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectOneElement ) {
if ( placeholderItem ) {
placeholderItem . innerHTML = this . _placeholderValue || '' ;
}
} else {
this . input . placeholder = this . _placeholderValue || '' ;
}
}
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
Choices . prototype . _handleSearch = function ( value ) {
2022-01-03 05:38:07 +01:00
if ( ! this . input . isFocussed ) {
2021-12-19 22:58:00 +01:00
return ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var choices = this . _store . choices ;
var _a = this . config ,
searchFloor = _a . searchFloor ,
searchChoices = _a . searchChoices ;
var hasUnactiveChoices = choices . some ( function ( option ) {
return ! option . active ;
} ) ; // Check that we have a value to search and the input was an alphanumeric character
2019-12-23 19:22:54 +01:00
2022-01-03 05:38:07 +01:00
if ( value !== null && typeof value !== 'undefined' && value . length >= searchFloor ) {
2021-12-19 22:58:00 +01:00
var resultCount = searchChoices ? this . _searchChoices ( value ) : 0 ; // Trigger search event
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
this . passedElement . triggerEvent ( constants _1 . EVENTS . search , {
value : value ,
resultCount : resultCount
} ) ;
} else if ( hasUnactiveChoices ) {
// Otherwise reset choices to active
this . _isSearching = false ;
this . _store . dispatch ( ( 0 , choices _1 . activateChoices ) ( true ) ) ;
}
2019-11-03 18:45:16 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _canAddItem = function ( activeItems , value ) {
var canAddItem = true ;
var notice = typeof this . config . addItemText === 'function' ? this . config . addItemText ( value ) : this . config . addItemText ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . _isSelectOneElement ) {
var isDuplicateValue = ( 0 , utils _1 . existsInArray ) ( activeItems , value ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . config . maxItemCount > 0 && this . config . maxItemCount <= activeItems . length ) {
// If there is a max entry limit and we have reached that limit
// don't update
canAddItem = false ;
notice = typeof this . config . maxItemText === 'function' ? this . config . maxItemText ( this . config . maxItemCount ) : this . config . maxItemText ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . config . duplicateItemsAllowed && isDuplicateValue && canAddItem ) {
canAddItem = false ;
notice = typeof this . config . uniqueItemText === 'function' ? this . config . uniqueItemText ( value ) : this . config . uniqueItemText ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isTextElement && this . config . addItems && canAddItem && typeof this . config . addItemFilter === 'function' && ! this . config . addItemFilter ( value ) ) {
canAddItem = false ;
notice = typeof this . config . customAddItemText === 'function' ? this . config . customAddItemText ( value ) : this . config . customAddItemText ;
}
2019-12-23 19:22:54 +01:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
return {
response : canAddItem ,
notice : notice
} ;
2019-11-03 18:45:16 +01:00
} ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _searchChoices = function ( value ) {
var newValue = typeof value === 'string' ? value . trim ( ) : value ;
var currentValue = typeof this . _currentValue === 'string' ? this . _currentValue . trim ( ) : this . _currentValue ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( newValue . length < 1 && newValue === "" . concat ( currentValue , " " ) ) {
return 0 ;
} // If new value matches the desired length and is not the same as the current value with a space
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var haystack = this . _store . searchableChoices ;
var needle = newValue ;
var options = Object . assign ( this . config . fuseOptions , {
2022-01-01 00:11:45 +01:00
keys : _ _spreadArray ( [ ] , this . config . searchFields , true ) ,
2021-12-19 22:58:00 +01:00
includeMatches : true
} ) ;
var fuse = new fuse _js _1 . default ( haystack , options ) ;
var results = fuse . search ( needle ) ; // see https://github.com/krisk/Fuse/issues/303
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
this . _currentValue = newValue ;
this . _highlightPosition = 0 ;
this . _isSearching = true ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
this . _store . dispatch ( ( 0 , choices _1 . filterChoices ) ( results ) ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
return results . length ;
} ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _addEventListeners = function ( ) {
var documentElement = document . documentElement ; // capture events - can cancel event processing or propagation
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
documentElement . addEventListener ( 'touchend' , this . _onTouchEnd , true ) ;
this . containerOuter . element . addEventListener ( 'keydown' , this . _onKeyDown , true ) ;
this . containerOuter . element . addEventListener ( 'mousedown' , this . _onMouseDown , true ) ; // passive events - doesn't call `preventDefault` or `stopPropagation`
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
documentElement . addEventListener ( 'click' , this . _onClick , {
passive : true
} ) ;
documentElement . addEventListener ( 'touchmove' , this . _onTouchMove , {
passive : true
} ) ;
this . dropdown . element . addEventListener ( 'mouseover' , this . _onMouseOver , {
passive : true
} ) ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectOneElement ) {
this . containerOuter . element . addEventListener ( 'focus' , this . _onFocus , {
passive : true
} ) ;
this . containerOuter . element . addEventListener ( 'blur' , this . _onBlur , {
passive : true
} ) ;
}
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
this . input . element . addEventListener ( 'keyup' , this . _onKeyUp , {
passive : true
} ) ;
this . input . element . addEventListener ( 'focus' , this . _onFocus , {
passive : true
} ) ;
this . input . element . addEventListener ( 'blur' , this . _onBlur , {
passive : true
} ) ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
if ( this . input . element . form ) {
this . input . element . form . addEventListener ( 'reset' , this . _onFormReset , {
passive : true
} ) ;
2019-10-22 23:20:40 +02:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . input . addEventListeners ( ) ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _removeEventListeners = function ( ) {
var documentElement = document . documentElement ;
documentElement . removeEventListener ( 'touchend' , this . _onTouchEnd , true ) ;
this . containerOuter . element . removeEventListener ( 'keydown' , this . _onKeyDown , true ) ;
this . containerOuter . element . removeEventListener ( 'mousedown' , this . _onMouseDown , true ) ;
documentElement . removeEventListener ( 'click' , this . _onClick ) ;
documentElement . removeEventListener ( 'touchmove' , this . _onTouchMove ) ;
this . dropdown . element . removeEventListener ( 'mouseover' , this . _onMouseOver ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectOneElement ) {
this . containerOuter . element . removeEventListener ( 'focus' , this . _onFocus ) ;
this . containerOuter . element . removeEventListener ( 'blur' , this . _onBlur ) ;
2019-10-22 23:20:40 +02:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . input . element . removeEventListener ( 'keyup' , this . _onKeyUp ) ;
this . input . element . removeEventListener ( 'focus' , this . _onFocus ) ;
this . input . element . removeEventListener ( 'blur' , this . _onBlur ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( this . input . element . form ) {
this . input . element . form . removeEventListener ( 'reset' , this . _onFormReset ) ;
2019-10-22 23:20:40 +02:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . input . removeEventListeners ( ) ;
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onKeyDown = function ( event ) {
var keyCode = event . keyCode ;
var activeItems = this . _store . activeItems ;
var hasFocusedInput = this . input . isFocussed ;
var hasActiveDropdown = this . dropdown . isActive ;
var hasItems = this . itemList . hasChildren ( ) ;
var keyString = String . fromCharCode ( keyCode ) ;
var wasAlphaNumericChar = /[a-zA-Z0-9-_ ]/ . test ( keyString ) ;
var BACK _KEY = constants _1 . KEY _CODES . BACK _KEY ,
DELETE _KEY = constants _1 . KEY _CODES . DELETE _KEY ,
ENTER _KEY = constants _1 . KEY _CODES . ENTER _KEY ,
A _KEY = constants _1 . KEY _CODES . A _KEY ,
ESC _KEY = constants _1 . KEY _CODES . ESC _KEY ,
UP _KEY = constants _1 . KEY _CODES . UP _KEY ,
DOWN _KEY = constants _1 . KEY _CODES . DOWN _KEY ,
PAGE _UP _KEY = constants _1 . KEY _CODES . PAGE _UP _KEY ,
PAGE _DOWN _KEY = constants _1 . KEY _CODES . PAGE _DOWN _KEY ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( ! this . _isTextElement && ! hasActiveDropdown && wasAlphaNumericChar ) {
this . showDropdown ( ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . input . isFocussed ) {
/ *
We update the input value with the pressed key as
the input was not focussed at the time of key press
therefore does not have the value of the key .
* /
this . input . value += keyString . toLowerCase ( ) ;
}
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
switch ( keyCode ) {
case A _KEY :
return this . _onSelectKey ( event , hasItems ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
case ENTER _KEY :
return this . _onEnterKey ( event , activeItems , hasActiveDropdown ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
case ESC _KEY :
return this . _onEscapeKey ( hasActiveDropdown ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
case UP _KEY :
case PAGE _UP _KEY :
case DOWN _KEY :
case PAGE _DOWN _KEY :
return this . _onDirectionKey ( event , hasActiveDropdown ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
case DELETE _KEY :
case BACK _KEY :
return this . _onDeleteKey ( event , activeItems , hasFocusedInput ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
default :
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ;
2019-02-12 19:37:04 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onKeyUp = function ( _a ) {
var target = _a . target ,
keyCode = _a . keyCode ;
var value = this . input . value ;
var activeItems = this . _store . activeItems ;
2019-02-19 10:02:48 +01:00
2021-12-19 22:58:00 +01:00
var canAddItem = this . _canAddItem ( activeItems , value ) ;
2019-02-11 18:52:22 +01:00
2021-12-19 22:58:00 +01:00
var backKey = constants _1 . KEY _CODES . BACK _KEY ,
deleteKey = constants _1 . KEY _CODES . DELETE _KEY ; // We are typing into a text input and have a value, we want to show a dropdown
// notice. Otherwise hide the dropdown
2019-02-12 19:37:04 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isTextElement ) {
var canShowDropdownNotice = canAddItem . notice && value ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
if ( canShowDropdownNotice ) {
var dropdownItem = this . _getTemplate ( 'notice' , canAddItem . notice ) ;
2019-02-19 10:02:48 +01:00
2021-12-19 22:58:00 +01:00
this . dropdown . element . innerHTML = dropdownItem . outerHTML ;
this . showDropdown ( true ) ;
} else {
this . hideDropdown ( true ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} else {
var wasRemovalKeyCode = keyCode === backKey || keyCode === deleteKey ;
var userHasRemovedValue = wasRemovalKeyCode && target && ! target . value ;
var canReactivateChoices = ! this . _isTextElement && this . _isSearching ;
var canSearch = this . _canSearch && canAddItem . response ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
if ( userHasRemovedValue && canReactivateChoices ) {
this . _isSearching = false ;
2019-02-19 10:02:48 +01:00
2021-12-19 22:58:00 +01:00
this . _store . dispatch ( ( 0 , choices _1 . activateChoices ) ( true ) ) ;
} else if ( canSearch ) {
2022-01-01 00:11:45 +01:00
this . _handleSearch ( this . input . rawValue ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
}
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
this . _canSearch = this . config . searchEnabled ;
} ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onSelectKey = function ( event , hasItems ) {
var ctrlKey = event . ctrlKey ,
metaKey = event . metaKey ;
var hasCtrlDownKeyPressed = ctrlKey || metaKey ; // If CTRL + A or CMD + A have been pressed and there are items to select
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
if ( hasCtrlDownKeyPressed && hasItems ) {
this . _canSearch = false ;
var shouldHightlightAll = this . config . removeItems && ! this . input . value && this . input . element === document . activeElement ;
if ( shouldHightlightAll ) {
this . highlightAll ( ) ;
}
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ;
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onEnterKey = function ( event , activeItems , hasActiveDropdown ) {
var target = event . target ;
var enterKey = constants _1 . KEY _CODES . ENTER _KEY ;
var targetWasButton = target && target . hasAttribute ( 'data-button' ) ;
if ( this . _isTextElement && target && target . value ) {
var value = this . input . value ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
var canAddItem = this . _canAddItem ( activeItems , value ) ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
if ( canAddItem . response ) {
this . hideDropdown ( true ) ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
this . _addItem ( {
value : value
} ) ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
this . _triggerChange ( value ) ;
this . clearInput ( ) ;
2019-02-09 19:13:25 +01:00
}
2019-02-26 13:20:52 +01:00
}
2021-12-19 22:58:00 +01:00
if ( targetWasButton ) {
this . _handleButtonAction ( activeItems , target ) ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
event . preventDefault ( ) ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( hasActiveDropdown ) {
var highlightedChoice = this . dropdown . getChild ( "." . concat ( this . config . classNames . highlightedState ) ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( highlightedChoice ) {
// add enter keyCode value
if ( activeItems [ 0 ] ) {
activeItems [ 0 ] . keyCode = enterKey ; // eslint-disable-line no-param-reassign
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . _handleChoiceAction ( activeItems , highlightedChoice ) ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
event . preventDefault ( ) ;
} else if ( this . _isSelectOneElement ) {
this . showDropdown ( ) ;
event . preventDefault ( ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onEscapeKey = function ( hasActiveDropdown ) {
if ( hasActiveDropdown ) {
this . hideDropdown ( true ) ;
this . containerOuter . focus ( ) ;
2019-10-22 23:20:40 +02:00
}
2021-12-19 22:58:00 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onDirectionKey = function ( event , hasActiveDropdown ) {
var keyCode = event . keyCode ,
metaKey = event . metaKey ;
var downKey = constants _1 . KEY _CODES . DOWN _KEY ,
pageUpKey = constants _1 . KEY _CODES . PAGE _UP _KEY ,
pageDownKey = constants _1 . KEY _CODES . PAGE _DOWN _KEY ; // If up or down key is pressed, traverse through options
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( hasActiveDropdown || this . _isSelectOneElement ) {
this . showDropdown ( ) ;
this . _canSearch = false ;
var directionInt = keyCode === downKey || keyCode === pageDownKey ? 1 : - 1 ;
var skipKey = metaKey || keyCode === pageDownKey || keyCode === pageUpKey ;
var selectableChoiceIdentifier = '[data-choice-selectable]' ;
var nextEl = void 0 ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( skipKey ) {
if ( directionInt > 0 ) {
nextEl = this . dropdown . element . querySelector ( "" . concat ( selectableChoiceIdentifier , ":last-of-type" ) ) ;
} else {
nextEl = this . dropdown . element . querySelector ( selectableChoiceIdentifier ) ;
}
} else {
var currentEl = this . dropdown . element . querySelector ( "." . concat ( this . config . classNames . highlightedState ) ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( currentEl ) {
nextEl = ( 0 , utils _1 . getAdjacentEl ) ( currentEl , selectableChoiceIdentifier , directionInt ) ;
} else {
nextEl = this . dropdown . element . querySelector ( selectableChoiceIdentifier ) ;
}
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( nextEl ) {
// We prevent default to stop the cursor moving
// when pressing the arrow
if ( ! ( 0 , utils _1 . isScrolledIntoView ) ( nextEl , this . choiceList . element , directionInt ) ) {
this . choiceList . scrollToChildElement ( nextEl , directionInt ) ;
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
this . _highlightChoice ( nextEl ) ;
} // Prevent default to maintain cursor position whilst
// traversing dropdown options
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
event . preventDefault ( ) ;
}
2019-10-22 23:20:40 +02:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onDeleteKey = function ( event , activeItems , hasFocusedInput ) {
var target = event . target ; // If backspace or delete key is pressed and the input has no value
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . _isSelectOneElement && ! target . value && hasFocusedInput ) {
this . _handleBackspace ( activeItems ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
event . preventDefault ( ) ;
2019-10-22 23:20:40 +02:00
}
2021-12-19 22:58:00 +01:00
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onTouchMove = function ( ) {
if ( this . _wasTap ) {
this . _wasTap = false ;
}
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onTouchEnd = function ( event ) {
var target = ( event || event . touches [ 0 ] ) . target ;
var touchWasWithinContainer = this . _wasTap && this . containerOuter . element . contains ( target ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( touchWasWithinContainer ) {
var containerWasExactTarget = target === this . containerOuter . element || target === this . containerInner . element ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( containerWasExactTarget ) {
if ( this . _isTextElement ) {
this . input . focus ( ) ;
} else if ( this . _isSelectMultipleElement ) {
this . showDropdown ( ) ;
}
} // Prevents focus event firing
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
event . stopPropagation ( ) ;
2019-10-22 23:20:40 +02:00
}
2021-12-19 22:58:00 +01:00
this . _wasTap = true ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
/ * *
* Handles mousedown event in capture mode for containetOuter . element
* /
2017-11-15 07:51:53 +01:00
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onMouseDown = function ( event ) {
var target = event . target ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( ! ( target instanceof HTMLElement ) ) {
2019-12-23 19:22:54 +01:00
return ;
2021-12-19 22:58:00 +01:00
} // If we have our mouse down on the scrollbar and are on IE11...
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( IS _IE11 && this . choiceList . element . contains ( target ) ) {
// check if click was on a scrollbar area
var firstChoice = this . choiceList . element . firstElementChild ;
var isOnScrollbar = this . _direction === 'ltr' ? event . offsetX >= firstChoice . offsetWidth : event . offsetX < firstChoice . offsetLeft ;
this . _isScrollingOnIe = isOnScrollbar ;
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( target === this . input . element ) {
2019-12-23 19:22:54 +01:00
return ;
2021-12-19 22:58:00 +01:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var item = target . closest ( '[data-button],[data-item],[data-choice]' ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( item instanceof HTMLElement ) {
var hasShiftKey = event . shiftKey ;
var activeItems = this . _store . activeItems ;
var dataset = item . dataset ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( 'button' in dataset ) {
this . _handleButtonAction ( activeItems , item ) ;
} else if ( 'item' in dataset ) {
this . _handleItemAction ( activeItems , item , hasShiftKey ) ;
} else if ( 'choice' in dataset ) {
this . _handleChoiceAction ( activeItems , item ) ;
}
2019-10-22 23:20:40 +02:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
event . preventDefault ( ) ;
} ;
/ * *
* Handles mouseover event over this . dropdown
* @ param { MouseEvent } event
* /
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onMouseOver = function ( _a ) {
var target = _a . target ;
2019-02-12 19:37:04 +01:00
2021-12-19 22:58:00 +01:00
if ( target instanceof HTMLElement && 'choice' in target . dataset ) {
this . _highlightChoice ( target ) ;
}
} ;
2019-02-12 19:37:04 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onClick = function ( _a ) {
var target = _a . target ;
var clickWasWithinContainer = this . containerOuter . element . contains ( target ) ;
if ( clickWasWithinContainer ) {
if ( ! this . dropdown . isActive && ! this . containerOuter . isDisabled ) {
if ( this . _isTextElement ) {
if ( document . activeElement !== this . input . element ) {
this . input . focus ( ) ;
}
} else {
this . showDropdown ( ) ;
this . containerOuter . focus ( ) ;
}
} else if ( this . _isSelectOneElement && target !== this . input . element && ! this . dropdown . element . contains ( target ) ) {
this . hideDropdown ( ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} else {
var hasHighlightedItems = this . _store . highlightedActiveItems . length > 0 ;
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
if ( hasHighlightedItems ) {
this . unhighlightAll ( ) ;
}
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
this . containerOuter . removeFocusState ( ) ;
2019-12-23 19:22:54 +01:00
this . hideDropdown ( true ) ;
}
} ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onFocus = function ( _a ) {
var _b ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
var _this = this ;
2019-02-26 13:20:52 +01:00
2021-12-19 22:58:00 +01:00
var target = _a . target ;
var focusWasWithinContainer = target && this . containerOuter . element . contains ( target ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( ! focusWasWithinContainer ) {
return ;
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
var focusActions = ( _b = { } , _b [ constants _1 . TEXT _TYPE ] = function ( ) {
if ( target === _this . input . element ) {
_this . containerOuter . addFocusState ( ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} , _b [ constants _1 . SELECT _ONE _TYPE ] = function ( ) {
_this . containerOuter . addFocusState ( ) ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( target === _this . input . element ) {
_this . showDropdown ( true ) ;
}
} , _b [ constants _1 . SELECT _MULTIPLE _TYPE ] = function ( ) {
if ( target === _this . input . element ) {
_this . showDropdown ( true ) ; // If element is a select box, the focused element is the container and the dropdown
// isn't already open, focus and show dropdown
2019-10-22 23:20:40 +02:00
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
_this . containerOuter . addFocusState ( ) ;
}
} , _b ) ;
focusActions [ this . passedElement . element . type ] ( ) ;
2019-12-23 19:22:54 +01:00
} ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onBlur = function ( _a ) {
var _b ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var _this = this ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var target = _a . target ;
var blurWasWithinContainer = target && this . containerOuter . element . contains ( target ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( blurWasWithinContainer && ! this . _isScrollingOnIe ) {
var activeItems = this . _store . activeItems ;
var hasHighlightedItems _1 = activeItems . some ( function ( item ) {
return item . highlighted ;
} ) ;
var blurActions = ( _b = { } , _b [ constants _1 . TEXT _TYPE ] = function ( ) {
if ( target === _this . input . element ) {
_this . containerOuter . removeFocusState ( ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( hasHighlightedItems _1 ) {
_this . unhighlightAll ( ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
_this . hideDropdown ( true ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} , _b [ constants _1 . SELECT _ONE _TYPE ] = function ( ) {
_this . containerOuter . removeFocusState ( ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( target === _this . input . element || target === _this . containerOuter . element && ! _this . _canSearch ) {
_this . hideDropdown ( true ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} , _b [ constants _1 . SELECT _MULTIPLE _TYPE ] = function ( ) {
if ( target === _this . input . element ) {
_this . containerOuter . removeFocusState ( ) ;
_this . hideDropdown ( true ) ;
if ( hasHighlightedItems _1 ) {
_this . unhighlightAll ( ) ;
}
}
} , _b ) ;
blurActions [ this . passedElement . element . type ] ( ) ;
} else {
// On IE11, clicking the scollbar blurs our input and thus
// closes the dropdown. To stop this, we refocus our input
// if we know we are on IE *and* are scrolling.
this . _isScrollingOnIe = false ;
this . input . element . focus ( ) ;
2019-10-22 23:20:40 +02:00
}
2019-12-23 19:22:54 +01:00
} ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _onFormReset = function ( ) {
this . _store . dispatch ( ( 0 , misc _1 . resetTo ) ( this . _initialState ) ) ;
} ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _highlightChoice = function ( el ) {
var _this = this ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( el === void 0 ) {
el = null ;
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
var choices = Array . from ( this . dropdown . element . querySelectorAll ( '[data-choice-selectable]' ) ) ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( ! choices . length ) {
return ;
2019-12-23 19:22:54 +01:00
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
var passedEl = el ;
var highlightedChoices = Array . from ( this . dropdown . element . querySelectorAll ( "." . concat ( this . config . classNames . highlightedState ) ) ) ; // Remove any highlighted choices
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
highlightedChoices . forEach ( function ( choice ) {
choice . classList . remove ( _this . config . classNames . highlightedState ) ;
choice . setAttribute ( 'aria-selected' , 'false' ) ;
} ) ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( passedEl ) {
this . _highlightPosition = choices . indexOf ( passedEl ) ;
} else {
// Highlight choice based on last known highlight location
if ( choices . length > this . _highlightPosition ) {
// If we have an option to highlight
passedEl = choices [ this . _highlightPosition ] ;
} else {
// Otherwise highlight the option before
passedEl = choices [ choices . length - 1 ] ;
2019-12-23 19:22:54 +01:00
}
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
if ( ! passedEl ) {
passedEl = choices [ 0 ] ;
2019-12-23 19:22:54 +01:00
}
2019-10-29 22:19:56 +01:00
}
2019-02-12 19:37:04 +01:00
2021-12-19 22:58:00 +01:00
passedEl . classList . add ( this . config . classNames . highlightedState ) ;
passedEl . setAttribute ( 'aria-selected' , 'true' ) ;
this . passedElement . triggerEvent ( constants _1 . EVENTS . highlightChoice , {
el : passedEl
} ) ;
if ( this . dropdown . isActive ) {
// IE11 ignores aria-label and blocks virtual keyboard
// if aria-activedescendant is set without a dropdown
this . input . setActiveDescendant ( passedEl . id ) ;
this . containerOuter . setActiveDescendant ( passedEl . id ) ;
}
2019-12-23 19:22:54 +01:00
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _addItem = function ( _a ) {
var value = _a . value ,
_b = _a . label ,
label = _b === void 0 ? null : _b ,
_c = _a . choiceId ,
choiceId = _c === void 0 ? - 1 : _c ,
_d = _a . groupId ,
groupId = _d === void 0 ? - 1 : _d ,
_e = _a . customProperties ,
customProperties = _e === void 0 ? { } : _e ,
_f = _a . placeholder ,
placeholder = _f === void 0 ? false : _f ,
_g = _a . keyCode ,
keyCode = _g === void 0 ? - 1 : _g ;
var passedValue = typeof value === 'string' ? value . trim ( ) : value ;
var items = this . _store . items ;
var passedLabel = label || passedValue ;
var passedOptionId = choiceId || - 1 ;
var group = groupId >= 0 ? this . _store . getGroupById ( groupId ) : null ;
var id = items ? items . length + 1 : 1 ; // If a prepended value has been passed, prepend it
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( this . config . prependValue ) {
passedValue = this . config . prependValue + passedValue . toString ( ) ;
} // If an appended value has been passed, append it
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
if ( this . config . appendValue ) {
passedValue += this . config . appendValue . toString ( ) ;
}
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
this . _store . dispatch ( ( 0 , items _1 . addItem ) ( {
value : passedValue ,
label : passedLabel ,
id : id ,
choiceId : passedOptionId ,
groupId : groupId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
} ) ) ;
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectOneElement ) {
this . removeActiveItems ( id ) ;
} // Trigger change event
this . passedElement . triggerEvent ( constants _1 . EVENTS . addItem , {
id : id ,
value : passedValue ,
label : passedLabel ,
customProperties : customProperties ,
groupValue : group && group . value ? group . value : null ,
keyCode : keyCode
2019-10-28 20:53:24 +01:00
} ) ;
2021-12-19 22:58:00 +01:00
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _removeItem = function ( item ) {
var id = item . id ,
value = item . value ,
label = item . label ,
customProperties = item . customProperties ,
choiceId = item . choiceId ,
groupId = item . groupId ;
var group = groupId && groupId >= 0 ? this . _store . getGroupById ( groupId ) : null ;
if ( ! id || ! choiceId ) {
return ;
}
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
this . _store . dispatch ( ( 0 , items _1 . removeItem ) ( id , choiceId ) ) ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
this . passedElement . triggerEvent ( constants _1 . EVENTS . removeItem , {
id : id ,
value : value ,
label : label ,
customProperties : customProperties ,
groupValue : group && group . value ? group . value : null
} ) ;
2019-12-23 19:22:54 +01:00
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _addChoice = function ( _a ) {
var value = _a . value ,
_b = _a . label ,
label = _b === void 0 ? null : _b ,
_c = _a . isSelected ,
isSelected = _c === void 0 ? false : _c ,
_d = _a . isDisabled ,
isDisabled = _d === void 0 ? false : _d ,
_e = _a . groupId ,
groupId = _e === void 0 ? - 1 : _e ,
_f = _a . customProperties ,
customProperties = _f === void 0 ? { } : _f ,
_g = _a . placeholder ,
placeholder = _g === void 0 ? false : _g ,
_h = _a . keyCode ,
keyCode = _h === void 0 ? - 1 : _h ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( typeof value === 'undefined' || value === null ) {
return ;
} // Generate unique id
2019-10-29 22:19:56 +01:00
2019-10-28 20:53:24 +01:00
2021-12-19 22:58:00 +01:00
var choices = this . _store . choices ;
var choiceLabel = label || value ;
var choiceId = choices ? choices . length + 1 : 1 ;
var choiceElementId = "" . concat ( this . _baseId , "-" ) . concat ( this . _idNames . itemChoice , "-" ) . concat ( choiceId ) ;
2019-02-22 23:06:59 +01:00
2021-12-19 22:58:00 +01:00
this . _store . dispatch ( ( 0 , choices _1 . addChoice ) ( {
id : choiceId ,
groupId : groupId ,
elementId : choiceElementId ,
value : value ,
label : choiceLabel ,
disabled : isDisabled ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
} ) ) ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
if ( isSelected ) {
this . _addItem ( {
value : value ,
label : choiceLabel ,
choiceId : choiceId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
2019-12-23 19:22:54 +01:00
} ) ;
2019-10-29 22:19:56 +01:00
}
2019-12-23 19:22:54 +01:00
} ;
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _addGroup = function ( _a ) {
var _this = this ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
var group = _a . group ,
id = _a . id ,
_b = _a . valueKey ,
valueKey = _b === void 0 ? 'value' : _b ,
_c = _a . labelKey ,
labelKey = _c === void 0 ? 'label' : _c ;
var groupChoices = ( 0 , utils _1 . isType ) ( 'Object' , group ) ? group . choices : Array . from ( group . getElementsByTagName ( 'OPTION' ) ) ;
var groupId = id || Math . floor ( new Date ( ) . valueOf ( ) * Math . random ( ) ) ;
var isDisabled = group . disabled ? group . disabled : false ;
if ( groupChoices ) {
this . _store . dispatch ( ( 0 , groups _1 . addGroup ) ( {
value : group . label ,
id : groupId ,
active : true ,
disabled : isDisabled
} ) ) ;
var addGroupChoices = function ( choice ) {
var isOptDisabled = choice . disabled || choice . parentNode && choice . parentNode . disabled ;
_this . _addChoice ( {
value : choice [ valueKey ] ,
label : ( 0 , utils _1 . isType ) ( 'Object' , choice ) ? choice [ labelKey ] : choice . innerHTML ,
isSelected : choice . selected ,
isDisabled : isOptDisabled ,
groupId : groupId ,
customProperties : choice . customProperties ,
placeholder : choice . placeholder
} ) ;
} ;
groupChoices . forEach ( addGroupChoices ) ;
} else {
this . _store . dispatch ( ( 0 , groups _1 . addGroup ) ( {
value : group . label ,
id : group . id ,
active : false ,
disabled : group . disabled
} ) ) ;
2019-10-29 22:19:56 +01:00
}
2021-12-19 22:58:00 +01:00
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _getTemplate = function ( template ) {
var _a ;
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
var args = [ ] ;
for ( var _i = 1 ; _i < arguments . length ; _i ++ ) {
args [ _i - 1 ] = arguments [ _i ] ;
2019-11-13 16:40:47 +01:00
}
2021-12-24 18:33:32 +01:00
return ( _a = this . _templates [ template ] ) . call . apply ( _a , _ _spreadArray ( [ this , this . config ] , args , false ) ) ;
2019-12-23 19:22:54 +01:00
} ;
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _createTemplates = function ( ) {
var callbackOnCreateTemplates = this . config . callbackOnCreateTemplates ;
var userTemplates = { } ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( callbackOnCreateTemplates && typeof callbackOnCreateTemplates === 'function' ) {
userTemplates = callbackOnCreateTemplates . call ( this , utils _1 . strToEl ) ;
2019-10-29 22:19:56 +01:00
}
2019-10-28 20:53:24 +01:00
2021-12-19 22:58:00 +01:00
this . _templates = ( 0 , deepmerge _1 . default ) ( templates _1 . default , userTemplates ) ;
} ;
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _createElements = function ( ) {
this . containerOuter = new components _1 . Container ( {
2022-01-18 23:07:07 +01:00
element : this . _getTemplate ( 'containerOuter' , this . _direction , this . _isSelectElement , this . _isSelectOneElement , this . config . searchEnabled , this . passedElement . element . type , this . config . labelId ) ,
2021-12-19 22:58:00 +01:00
classNames : this . config . classNames ,
type : this . passedElement . element . type ,
position : this . config . position
} ) ;
this . containerInner = new components _1 . Container ( {
element : this . _getTemplate ( 'containerInner' ) ,
classNames : this . config . classNames ,
type : this . passedElement . element . type ,
position : this . config . position
} ) ;
this . input = new components _1 . Input ( {
element : this . _getTemplate ( 'input' , this . _placeholderValue ) ,
classNames : this . config . classNames ,
type : this . passedElement . element . type ,
preventPaste : ! this . config . paste
} ) ;
this . choiceList = new components _1 . List ( {
element : this . _getTemplate ( 'choiceList' , this . _isSelectOneElement )
} ) ;
this . itemList = new components _1 . List ( {
element : this . _getTemplate ( 'itemList' , this . _isSelectOneElement )
} ) ;
this . dropdown = new components _1 . Dropdown ( {
element : this . _getTemplate ( 'dropdown' ) ,
classNames : this . config . classNames ,
type : this . passedElement . element . type
} ) ;
} ;
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _createStructure = function ( ) {
// Hide original element
this . passedElement . conceal ( ) ; // Wrap input in container preserving DOM ordering
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
this . containerInner . wrap ( this . passedElement . element ) ; // Wrapper inner container with outer container
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . containerOuter . wrap ( this . containerInner . element ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectOneElement ) {
this . input . placeholder = this . config . searchPlaceholderValue || '' ;
} else if ( this . _placeholderValue ) {
this . input . placeholder = this . _placeholderValue ;
this . input . setWidth ( ) ;
2019-10-22 23:20:40 +02:00
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
this . containerOuter . element . appendChild ( this . containerInner . element ) ;
this . containerOuter . element . appendChild ( this . dropdown . element ) ;
this . containerInner . element . appendChild ( this . itemList . element ) ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . _isTextElement ) {
this . dropdown . element . appendChild ( this . choiceList . element ) ;
}
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
if ( ! this . _isSelectOneElement ) {
this . containerInner . element . appendChild ( this . input . element ) ;
} else if ( this . config . searchEnabled ) {
this . dropdown . element . insertBefore ( this . input . element , this . dropdown . element . firstChild ) ;
}
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isSelectElement ) {
this . _highlightPosition = 0 ;
this . _isSearching = false ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
this . _startLoading ( ) ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _presetGroups . length ) {
this . _addPredefinedGroups ( this . _presetGroups ) ;
2019-12-23 19:22:54 +01:00
} else {
2021-12-19 22:58:00 +01:00
this . _addPredefinedChoices ( this . _presetChoices ) ;
2019-12-23 19:22:54 +01:00
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
this . _stopLoading ( ) ;
2019-12-23 19:22:54 +01:00
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( this . _isTextElement ) {
this . _addPredefinedItems ( this . _presetItems ) ;
2019-12-23 19:22:54 +01:00
}
2019-10-22 23:20:40 +02:00
} ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _addPredefinedGroups = function ( groups ) {
var _this = this ; // If we have a placeholder option
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
var placeholderChoice = this . passedElement . placeholderOption ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( placeholderChoice && placeholderChoice . parentNode && placeholderChoice . parentNode . tagName === 'SELECT' ) {
this . _addChoice ( {
value : placeholderChoice . value ,
label : placeholderChoice . innerHTML ,
isSelected : placeholderChoice . selected ,
isDisabled : placeholderChoice . disabled ,
placeholder : true
} ) ;
}
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
groups . forEach ( function ( group ) {
return _this . _addGroup ( {
group : group ,
id : group . id || null
} ) ;
} ) ;
} ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _addPredefinedChoices = function ( choices ) {
var _this = this ; // If sorting is enabled or the user is searching, filter choices
2019-11-03 18:45:16 +01:00
2019-11-07 09:50:19 +01:00
2021-12-19 22:58:00 +01:00
if ( this . config . shouldSort ) {
choices . sort ( this . config . sorter ) ;
2019-12-23 19:22:54 +01:00
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
var hasSelectedChoice = choices . some ( function ( choice ) {
return choice . selected ;
} ) ;
var firstEnabledChoiceIndex = choices . findIndex ( function ( choice ) {
return choice . disabled === undefined || ! choice . disabled ;
} ) ;
choices . forEach ( function ( choice , index ) {
var _a = choice . value ,
value = _a === void 0 ? '' : _a ,
label = choice . label ,
customProperties = choice . customProperties ,
placeholder = choice . placeholder ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( _this . _isSelectElement ) {
// If the choice is actually a group
if ( choice . choices ) {
_this . _addGroup ( {
group : choice ,
id : choice . id || null
} ) ;
} else {
/ * *
* If there is a selected choice already or the choice is not the first in
* the array , add each choice normally .
*
* Otherwise we pre - select the first enabled choice in the array ( "select-one" only )
* /
var shouldPreselect = _this . _isSelectOneElement && ! hasSelectedChoice && index === firstEnabledChoiceIndex ;
var isSelected = shouldPreselect ? true : choice . selected ;
var isDisabled = choice . disabled ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
_this . _addChoice ( {
value : value ,
label : label ,
isSelected : ! ! isSelected ,
isDisabled : ! ! isDisabled ,
placeholder : ! ! placeholder ,
customProperties : customProperties
} ) ;
}
} else {
_this . _addChoice ( {
value : value ,
label : label ,
isSelected : ! ! choice . selected ,
isDisabled : ! ! choice . disabled ,
placeholder : ! ! choice . placeholder ,
customProperties : customProperties
} ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ) ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _addPredefinedItems = function ( items ) {
var _this = this ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
items . forEach ( function ( item ) {
if ( typeof item === 'object' && item . value ) {
_this . _addItem ( {
value : item . value ,
label : item . label ,
choiceId : item . id ,
customProperties : item . customProperties ,
placeholder : item . placeholder
} ) ;
}
if ( typeof item === 'string' ) {
_this . _addItem ( {
value : item
} ) ;
}
} ) ;
2019-10-22 23:20:40 +02:00
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _setChoiceOrItem = function ( item ) {
var _this = this ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var itemType = ( 0 , utils _1 . getType ) ( item ) . toLowerCase ( ) ;
var handleType = {
object : function ( ) {
if ( ! item . value ) {
return ;
} // If we are dealing with a select input, we need to create an option first
// that is then selected. For text inputs we can just add items normally.
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
if ( ! _this . _isTextElement ) {
_this . _addChoice ( {
value : item . value ,
label : item . label ,
isSelected : true ,
isDisabled : false ,
customProperties : item . customProperties ,
placeholder : item . placeholder
} ) ;
2019-12-23 19:22:54 +01:00
} else {
2021-12-19 22:58:00 +01:00
_this . _addItem ( {
value : item . value ,
label : item . label ,
choiceId : item . id ,
customProperties : item . customProperties ,
placeholder : item . placeholder
} ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ,
string : function ( ) {
if ( ! _this . _isTextElement ) {
_this . _addChoice ( {
value : item ,
label : item ,
isSelected : true ,
isDisabled : false
} ) ;
2019-12-23 19:22:54 +01:00
} else {
2021-12-19 22:58:00 +01:00
_this . _addItem ( {
value : item
} ) ;
2019-12-23 19:22:54 +01:00
}
}
2021-12-19 22:58:00 +01:00
} ;
handleType [ itemType ] ( ) ;
} ;
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _findAndSelectChoiceByValue = function ( value ) {
var _this = this ;
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
var choices = this . _store . choices ; // Check 'value' property exists and the choice isn't already selected
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
var foundChoice = choices . find ( function ( choice ) {
return _this . config . valueComparer ( choice . value , value ) ;
} ) ;
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
if ( foundChoice && ! foundChoice . selected ) {
this . _addItem ( {
value : foundChoice . value ,
label : foundChoice . label ,
choiceId : foundChoice . id ,
groupId : foundChoice . groupId ,
customProperties : foundChoice . customProperties ,
placeholder : foundChoice . placeholder ,
keyCode : foundChoice . keyCode
} ) ;
2019-12-23 19:22:54 +01:00
}
} ;
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
Choices . prototype . _generatePlaceholderValue = function ( ) {
if ( this . _isSelectElement && this . passedElement . placeholderOption ) {
var placeholderOption = this . passedElement . placeholderOption ;
return placeholderOption ? placeholderOption . text : null ;
}
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
var _a = this . config ,
placeholder = _a . placeholder ,
placeholderValue = _a . placeholderValue ;
var dataset = this . passedElement . element . dataset ;
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
if ( placeholder ) {
if ( placeholderValue ) {
return placeholderValue ;
}
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
if ( dataset . placeholder ) {
return dataset . placeholder ;
}
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
return null ;
2019-12-23 19:22:54 +01:00
} ;
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
return Choices ;
} ( ) ;
2018-10-13 12:19:24 +02:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = Choices ;
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2018-10-27 17:45:19 +02:00
2021-12-19 22:58:00 +01:00
/***/ 613 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2019-11-03 18:45:16 +01:00
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
var utils _1 = _ _webpack _require _ _ ( 799 ) ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
var constants _1 = _ _webpack _require _ _ ( 883 ) ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
var Container =
/** @class */
function ( ) {
function Container ( _a ) {
var element = _a . element ,
type = _a . type ,
classNames = _a . classNames ,
position = _a . position ;
this . element = element ;
this . classNames = classNames ;
this . type = type ;
this . position = position ;
this . isOpen = false ;
this . isFlipped = false ;
this . isFocussed = false ;
this . isDisabled = false ;
this . isLoading = false ;
this . _onFocus = this . _onFocus . bind ( this ) ;
this . _onBlur = this . _onBlur . bind ( this ) ;
}
2018-10-27 17:45:19 +02:00
2021-12-19 22:58:00 +01:00
Container . prototype . addEventListeners = function ( ) {
this . element . addEventListener ( 'focus' , this . _onFocus ) ;
this . element . addEventListener ( 'blur' , this . _onBlur ) ;
} ;
2018-10-27 17:45:19 +02:00
2021-12-19 22:58:00 +01:00
Container . prototype . removeEventListeners = function ( ) {
this . element . removeEventListener ( 'focus' , this . _onFocus ) ;
this . element . removeEventListener ( 'blur' , this . _onBlur ) ;
} ;
/ * *
* Determine whether container should be flipped based on passed
* dropdown position
* /
2018-10-27 17:45:19 +02:00
2019-10-15 10:49:38 +02:00
2021-12-19 22:58:00 +01:00
Container . prototype . shouldFlip = function ( dropdownPos ) {
if ( typeof dropdownPos !== 'number' ) {
return false ;
} // If flip is enabled and the dropdown bottom position is
// greater than the window height flip the dropdown.
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var shouldFlip = false ;
if ( this . position === 'auto' ) {
shouldFlip = ! window . matchMedia ( "(min-height: " . concat ( dropdownPos + 1 , "px)" ) ) . matches ;
} else if ( this . position === 'top' ) {
shouldFlip = true ;
2019-10-22 23:20:40 +02:00
}
2019-10-15 10:49:38 +02:00
2021-12-19 22:58:00 +01:00
return shouldFlip ;
} ;
Container . prototype . setActiveDescendant = function ( activeDescendantID ) {
this . element . setAttribute ( 'aria-activedescendant' , activeDescendantID ) ;
2019-12-23 19:22:54 +01:00
} ;
2019-10-15 10:49:38 +02:00
2021-12-19 22:58:00 +01:00
Container . prototype . removeActiveDescendant = function ( ) {
this . element . removeAttribute ( 'aria-activedescendant' ) ;
} ;
2019-10-15 10:49:38 +02:00
2021-12-19 22:58:00 +01:00
Container . prototype . open = function ( dropdownPos ) {
this . element . classList . add ( this . classNames . openState ) ;
this . element . setAttribute ( 'aria-expanded' , 'true' ) ;
this . isOpen = true ;
2019-11-07 09:50:19 +01:00
2021-12-19 22:58:00 +01:00
if ( this . shouldFlip ( dropdownPos ) ) {
this . element . classList . add ( this . classNames . flippedState ) ;
this . isFlipped = true ;
2019-11-07 09:50:19 +01:00
}
2019-12-23 19:22:54 +01:00
} ;
2019-11-07 09:50:19 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . close = function ( ) {
this . element . classList . remove ( this . classNames . openState ) ;
this . element . setAttribute ( 'aria-expanded' , 'false' ) ;
this . removeActiveDescendant ( ) ;
this . isOpen = false ; // A dropdown flips if it does not have space within the page
2019-10-15 10:49:38 +02:00
2021-12-19 22:58:00 +01:00
if ( this . isFlipped ) {
this . element . classList . remove ( this . classNames . flippedState ) ;
this . isFlipped = false ;
}
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . focus = function ( ) {
if ( ! this . isFocussed ) {
this . element . focus ( ) ;
2019-12-23 19:22:54 +01:00
}
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . addFocusState = function ( ) {
this . element . classList . add ( this . classNames . focusState ) ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . removeFocusState = function ( ) {
this . element . classList . remove ( this . classNames . focusState ) ;
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . enable = function ( ) {
this . element . classList . remove ( this . classNames . disabledState ) ;
this . element . removeAttribute ( 'aria-disabled' ) ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
if ( this . type === constants _1 . SELECT _ONE _TYPE ) {
this . element . setAttribute ( 'tabindex' , '0' ) ;
2019-10-29 22:19:56 +01:00
}
2021-12-19 22:58:00 +01:00
this . isDisabled = false ;
2019-12-23 19:22:54 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . disable = function ( ) {
this . element . classList . add ( this . classNames . disabledState ) ;
this . element . setAttribute ( 'aria-disabled' , 'true' ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( this . type === constants _1 . SELECT _ONE _TYPE ) {
this . element . setAttribute ( 'tabindex' , '-1' ) ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
this . isDisabled = true ;
} ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . wrap = function ( element ) {
( 0 , utils _1 . wrap ) ( element , this . element ) ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . unwrap = function ( element ) {
if ( this . element . parentNode ) {
// Move passed element outside this element
this . element . parentNode . insertBefore ( element , this . element ) ; // Remove this element
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
this . element . parentNode . removeChild ( this . element ) ;
}
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . addLoadingState = function ( ) {
this . element . classList . add ( this . classNames . loadingState ) ;
this . element . setAttribute ( 'aria-busy' , 'true' ) ;
this . isLoading = true ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . removeLoadingState = function ( ) {
this . element . classList . remove ( this . classNames . loadingState ) ;
this . element . removeAttribute ( 'aria-busy' ) ;
this . isLoading = false ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . _onFocus = function ( ) {
this . isFocussed = true ;
2019-12-23 19:22:54 +01:00
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Container . prototype . _onBlur = function ( ) {
this . isFocussed = false ;
2019-12-23 19:22:54 +01:00
} ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
return Container ;
} ( ) ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = Container ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2018-04-25 10:20:59 +02:00
2021-12-19 22:58:00 +01:00
/***/ 217 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
2019-01-26 13:36:47 +01:00
2019-02-09 19:13:25 +01:00
2018-04-25 10:20:59 +02:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var Dropdown =
/** @class */
function ( ) {
function Dropdown ( _a ) {
var element = _a . element ,
type = _a . type ,
classNames = _a . classNames ;
this . element = element ;
this . classNames = classNames ;
this . type = type ;
this . isActive = false ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( Dropdown . prototype , "distanceFromTopWindow" , {
/ * *
* Bottom position of dropdown in viewport coordinates
* /
get : function ( ) {
return this . element . getBoundingClientRect ( ) . bottom ;
} ,
enumerable : false ,
configurable : true
} ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Dropdown . prototype . getChild = function ( selector ) {
return this . element . querySelector ( selector ) ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
/ * *
* Show dropdown to user by adding active state class
* /
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
Dropdown . prototype . show = function ( ) {
this . element . classList . add ( this . classNames . activeState ) ;
this . element . setAttribute ( 'aria-expanded' , 'true' ) ;
this . isActive = true ;
return this ;
} ;
/ * *
* Hide dropdown from user
* /
2019-10-22 23:20:40 +02:00
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
Dropdown . prototype . hide = function ( ) {
this . element . classList . remove ( this . classNames . activeState ) ;
this . element . setAttribute ( 'aria-expanded' , 'false' ) ;
this . isActive = false ;
return this ;
} ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
return Dropdown ;
} ( ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = Dropdown ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
/***/ 520 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2019-12-23 19:22:54 +01:00
2016-08-23 08:24:45 +02:00
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var _ _importDefault = this && this . _ _importDefault || function ( mod ) {
return mod && mod . _ _esModule ? mod : {
"default" : mod
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
} ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
exports . WrappedSelect = exports . WrappedInput = exports . List = exports . Input = exports . Container = exports . Dropdown = void 0 ;
2016-10-26 16:43:15 +02:00
2021-12-19 22:58:00 +01:00
var dropdown _1 = _ _importDefault ( _ _webpack _require _ _ ( 217 ) ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
exports . Dropdown = dropdown _1 . default ;
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
var container _1 = _ _importDefault ( _ _webpack _require _ _ ( 613 ) ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
exports . Container = container _1 . default ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var input _1 = _ _importDefault ( _ _webpack _require _ _ ( 11 ) ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
exports . Input = input _1 . default ;
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
var list _1 = _ _importDefault ( _ _webpack _require _ _ ( 624 ) ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
exports . List = list _1 . default ;
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
var wrapped _input _1 = _ _importDefault ( _ _webpack _require _ _ ( 541 ) ) ;
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
exports . WrappedInput = wrapped _input _1 . default ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var wrapped _select _1 = _ _importDefault ( _ _webpack _require _ _ ( 982 ) ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
exports . WrappedSelect = wrapped _select _1 . default ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
/***/ 11 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var utils _1 = _ _webpack _require _ _ ( 799 ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var constants _1 = _ _webpack _require _ _ ( 883 ) ;
var Input =
/** @class */
function ( ) {
function Input ( _a ) {
var element = _a . element ,
type = _a . type ,
classNames = _a . classNames ,
preventPaste = _a . preventPaste ;
this . element = element ;
this . type = type ;
this . classNames = classNames ;
this . preventPaste = preventPaste ;
this . isFocussed = this . element . isEqualNode ( document . activeElement ) ;
this . isDisabled = element . disabled ;
this . _onPaste = this . _onPaste . bind ( this ) ;
this . _onInput = this . _onInput . bind ( this ) ;
this . _onFocus = this . _onFocus . bind ( this ) ;
this . _onBlur = this . _onBlur . bind ( this ) ;
}
Object . defineProperty ( Input . prototype , "placeholder" , {
set : function ( placeholder ) {
this . element . placeholder = placeholder ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( Input . prototype , "value" , {
get : function ( ) {
return ( 0 , utils _1 . sanitise ) ( this . element . value ) ;
} ,
set : function ( value ) {
this . element . value = value ;
} ,
enumerable : false ,
configurable : true
} ) ;
2022-01-01 00:11:45 +01:00
Object . defineProperty ( Input . prototype , "rawValue" , {
get : function ( ) {
return this . element . value ;
} ,
enumerable : false ,
configurable : true
} ) ;
2021-12-19 22:58:00 +01:00
Input . prototype . addEventListeners = function ( ) {
this . element . addEventListener ( 'paste' , this . _onPaste ) ;
this . element . addEventListener ( 'input' , this . _onInput , {
passive : true
2019-12-23 19:22:54 +01:00
} ) ;
2021-12-19 22:58:00 +01:00
this . element . addEventListener ( 'focus' , this . _onFocus , {
passive : true
2019-12-23 19:22:54 +01:00
} ) ;
2021-12-19 22:58:00 +01:00
this . element . addEventListener ( 'blur' , this . _onBlur , {
passive : true
2019-10-22 23:20:40 +02:00
} ) ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . removeEventListeners = function ( ) {
this . element . removeEventListener ( 'input' , this . _onInput ) ;
this . element . removeEventListener ( 'paste' , this . _onPaste ) ;
this . element . removeEventListener ( 'focus' , this . _onFocus ) ;
this . element . removeEventListener ( 'blur' , this . _onBlur ) ;
} ;
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . enable = function ( ) {
this . element . removeAttribute ( 'disabled' ) ;
this . isDisabled = false ;
} ;
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . disable = function ( ) {
this . element . setAttribute ( 'disabled' , '' ) ;
this . isDisabled = true ;
} ;
2018-05-28 17:22:22 +02:00
2021-12-19 22:58:00 +01:00
Input . prototype . focus = function ( ) {
if ( ! this . isFocussed ) {
this . element . focus ( ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . blur = function ( ) {
if ( this . isFocussed ) {
this . element . blur ( ) ;
}
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . clear = function ( setWidth ) {
if ( setWidth === void 0 ) {
setWidth = true ;
2019-12-23 19:22:54 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( this . element . value ) {
this . element . value = '' ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( setWidth ) {
this . setWidth ( ) ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
return this ;
} ;
/ * *
* Set the correct input width based on placeholder
* value or input value
* /
2017-11-15 07:51:53 +01:00
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . setWidth = function ( ) {
// Resize input to contents or placeholder
var _a = this . element ,
style = _a . style ,
value = _a . value ,
placeholder = _a . placeholder ;
style . minWidth = "" . concat ( placeholder . length + 1 , "ch" ) ;
style . width = "" . concat ( value . length + 1 , "ch" ) ;
2019-10-22 23:20:40 +02:00
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . setActiveDescendant = function ( activeDescendantID ) {
this . element . setAttribute ( 'aria-activedescendant' , activeDescendantID ) ;
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . removeActiveDescendant = function ( ) {
this . element . removeAttribute ( 'aria-activedescendant' ) ;
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . _onInput = function ( ) {
if ( this . type !== constants _1 . SELECT _ONE _TYPE ) {
this . setWidth ( ) ;
}
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . _onPaste = function ( event ) {
if ( this . preventPaste ) {
event . preventDefault ( ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
Input . prototype . _onFocus = function ( ) {
this . isFocussed = true ;
2019-10-22 23:20:40 +02:00
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Input . prototype . _onBlur = function ( ) {
this . isFocussed = false ;
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
return Input ;
} ( ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = Input ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
/***/ 624 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2019-02-09 19:13:25 +01:00
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var constants _1 = _ _webpack _require _ _ ( 883 ) ;
var List =
/** @class */
function ( ) {
function List ( _a ) {
var element = _a . element ;
this . element = element ;
this . scrollPos = this . element . scrollTop ;
this . height = this . element . offsetHeight ;
}
List . prototype . clear = function ( ) {
this . element . innerHTML = '' ;
2019-10-22 23:20:40 +02:00
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
List . prototype . append = function ( node ) {
this . element . appendChild ( node ) ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
List . prototype . getChild = function ( selector ) {
return this . element . querySelector ( selector ) ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
List . prototype . hasChildren = function ( ) {
return this . element . hasChildNodes ( ) ;
} ;
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
List . prototype . scrollToTop = function ( ) {
this . element . scrollTop = 0 ;
2019-10-22 23:20:40 +02:00
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
List . prototype . scrollToChildElement = function ( element , direction ) {
2019-12-23 19:22:54 +01:00
var _this = this ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( ! element ) {
return ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var listHeight = this . element . offsetHeight ; // Scroll position of dropdown
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
var listScrollPosition = this . element . scrollTop + listHeight ;
var elementHeight = element . offsetHeight ; // Distance from bottom of element to top of parent
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
var elementPos = element . offsetTop + elementHeight ; // Difference between the element and scroll position
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var destination = direction > 0 ? this . element . scrollTop + elementPos - listScrollPosition : element . offsetTop ;
requestAnimationFrame ( function ( ) {
_this . _animateScroll ( destination , direction ) ;
} ) ;
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
List . prototype . _scrollDown = function ( scrollPos , strength , destination ) {
var easing = ( destination - scrollPos ) / strength ;
var distance = easing > 1 ? easing : 1 ;
this . element . scrollTop = scrollPos + distance ;
} ;
List . prototype . _scrollUp = function ( scrollPos , strength , destination ) {
var easing = ( scrollPos - destination ) / strength ;
var distance = easing > 1 ? easing : 1 ;
this . element . scrollTop = scrollPos - distance ;
} ;
List . prototype . _animateScroll = function ( destination , direction ) {
var _this = this ;
var strength = constants _1 . SCROLLING _SPEED ;
var choiceListScrollTop = this . element . scrollTop ;
var continueAnimation = false ;
if ( direction > 0 ) {
this . _scrollDown ( choiceListScrollTop , strength , destination ) ;
if ( choiceListScrollTop < destination ) {
continueAnimation = true ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} else {
this . _scrollUp ( choiceListScrollTop , strength , destination ) ;
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
if ( choiceListScrollTop > destination ) {
continueAnimation = true ;
2019-12-23 19:22:54 +01:00
}
2019-10-29 22:19:56 +01:00
}
2021-12-19 22:58:00 +01:00
if ( continueAnimation ) {
requestAnimationFrame ( function ( ) {
_this . _animateScroll ( destination , direction ) ;
} ) ;
}
2019-12-23 19:22:54 +01:00
} ;
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
return List ;
2019-12-23 19:22:54 +01:00
} ( ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = List ;
2019-02-09 19:13:25 +01:00
2019-12-23 19:22:54 +01:00
/***/ } ) ,
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
/***/ 730 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
var utils _1 = _ _webpack _require _ _ ( 799 ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var WrappedElement =
/** @class */
function ( ) {
function WrappedElement ( _a ) {
var element = _a . element ,
classNames = _a . classNames ;
this . element = element ;
this . classNames = classNames ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( ! ( element instanceof HTMLInputElement ) && ! ( element instanceof HTMLSelectElement ) ) {
throw new TypeError ( 'Invalid element passed' ) ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
this . isDisabled = false ;
}
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( WrappedElement . prototype , "isActive" , {
get : function ( ) {
return this . element . dataset . choice === 'active' ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( WrappedElement . prototype , "dir" , {
get : function ( ) {
return this . element . dir ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( WrappedElement . prototype , "value" , {
get : function ( ) {
return this . element . value ;
} ,
set : function ( value ) {
// you must define setter here otherwise it will be readonly property
this . element . value = value ;
} ,
enumerable : false ,
configurable : true
} ) ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
WrappedElement . prototype . conceal = function ( ) {
// Hide passed input
this . element . classList . add ( this . classNames . input ) ;
this . element . hidden = true ; // Remove element from tab index
2019-10-29 22:19:56 +01:00
2021-12-19 22:58:00 +01:00
this . element . tabIndex = - 1 ; // Backup original styles if any
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
var origStyle = this . element . getAttribute ( 'style' ) ;
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
if ( origStyle ) {
this . element . setAttribute ( 'data-choice-orig-style' , origStyle ) ;
}
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
this . element . setAttribute ( 'data-choice' , 'active' ) ;
} ;
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
WrappedElement . prototype . reveal = function ( ) {
// Reinstate passed element
this . element . classList . remove ( this . classNames . input ) ;
this . element . hidden = false ;
this . element . removeAttribute ( 'tabindex' ) ; // Recover original styles if any
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
var origStyle = this . element . getAttribute ( 'data-choice-orig-style' ) ;
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
if ( origStyle ) {
this . element . removeAttribute ( 'data-choice-orig-style' ) ;
this . element . setAttribute ( 'style' , origStyle ) ;
} else {
this . element . removeAttribute ( 'style' ) ;
}
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
this . element . removeAttribute ( 'data-choice' ) ; // Re-assign values - this is weird, I know
// @todo Figure out why we need to do this
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
this . element . value = this . element . value ; // eslint-disable-line no-self-assign
} ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
WrappedElement . prototype . enable = function ( ) {
this . element . removeAttribute ( 'disabled' ) ;
this . element . disabled = false ;
this . isDisabled = false ;
} ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
WrappedElement . prototype . disable = function ( ) {
this . element . setAttribute ( 'disabled' , '' ) ;
this . element . disabled = true ;
this . isDisabled = true ;
} ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
WrappedElement . prototype . triggerEvent = function ( eventType , data ) {
( 0 , utils _1 . dispatchEvent ) ( this . element , eventType , data ) ;
} ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
return WrappedElement ;
} ( ) ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = WrappedElement ;
2017-11-07 12:59:49 +01:00
2019-12-23 19:22:54 +01:00
/***/ } ) ,
2021-12-19 22:58:00 +01:00
/***/ 541 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var _ _extends = this && this . _ _extends || function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf || {
_ _proto _ _ : [ ]
} instanceof Array && function ( d , b ) {
d . _ _proto _ _ = b ;
} || function ( d , b ) {
for ( var p in b ) if ( Object . prototype . hasOwnProperty . call ( b , p ) ) d [ p ] = b [ p ] ;
} ;
return extendStatics ( d , b ) ;
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
return function ( d , b ) {
if ( typeof b !== "function" && b !== null ) throw new TypeError ( "Class extends value " + String ( b ) + " is not a constructor or null" ) ;
extendStatics ( d , b ) ;
function _ _ ( ) {
this . constructor = d ;
2019-12-23 19:22:54 +01:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ( ) ;
2019-12-23 19:22:54 +01:00
var _ _importDefault = this && this . _ _importDefault || function ( mod ) {
return mod && mod . _ _esModule ? mod : {
"default" : mod
} ;
} ;
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
2019-12-23 19:22:54 +01:00
value : true
2021-12-19 22:58:00 +01:00
} ) ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var wrapped _element _1 = _ _importDefault ( _ _webpack _require _ _ ( 730 ) ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var WrappedInput =
2019-12-23 19:22:54 +01:00
/** @class */
2021-12-19 22:58:00 +01:00
function ( _super ) {
_ _extends ( WrappedInput , _super ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
function WrappedInput ( _a ) {
var element = _a . element ,
classNames = _a . classNames ,
delimiter = _a . delimiter ;
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
var _this = _super . call ( this , {
element : element ,
classNames : classNames
} ) || this ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
_this . delimiter = delimiter ;
return _this ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( WrappedInput . prototype , "value" , {
get : function ( ) {
return this . element . value ;
2019-12-23 19:22:54 +01:00
} ,
2021-12-19 22:58:00 +01:00
set : function ( value ) {
this . element . setAttribute ( 'value' , value ) ;
this . element . value = value ;
2019-12-23 19:22:54 +01:00
} ,
2021-12-19 22:58:00 +01:00
enumerable : false ,
2019-12-23 19:22:54 +01:00
configurable : true
} ) ;
2021-12-19 22:58:00 +01:00
return WrappedInput ;
} ( wrapped _element _1 . default ) ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = WrappedInput ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
/***/ 982 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2017-11-15 07:51:53 +01:00
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var _ _extends = this && this . _ _extends || function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf || {
_ _proto _ _ : [ ]
} instanceof Array && function ( d , b ) {
d . _ _proto _ _ = b ;
} || function ( d , b ) {
for ( var p in b ) if ( Object . prototype . hasOwnProperty . call ( b , p ) ) d [ p ] = b [ p ] ;
} ;
return extendStatics ( d , b ) ;
2019-10-22 23:20:40 +02:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
return function ( d , b ) {
if ( typeof b !== "function" && b !== null ) throw new TypeError ( "Class extends value " + String ( b ) + " is not a constructor or null" ) ;
extendStatics ( d , b ) ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
function _ _ ( ) {
this . constructor = d ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ( ) ;
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
var _ _importDefault = this && this . _ _importDefault || function ( mod ) {
return mod && mod . _ _esModule ? mod : {
"default" : mod
} ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var wrapped _element _1 = _ _importDefault ( _ _webpack _require _ _ ( 730 ) ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var WrappedSelect =
/** @class */
function ( _super ) {
_ _extends ( WrappedSelect , _super ) ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
function WrappedSelect ( _a ) {
var element = _a . element ,
classNames = _a . classNames ,
template = _a . template ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var _this = _super . call ( this , {
element : element ,
classNames : classNames
} ) || this ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
_this . template = template ;
return _this ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( WrappedSelect . prototype , "placeholderOption" , {
get : function ( ) {
return this . element . querySelector ( 'option[value=""]' ) || // Backward compatibility layer for the non-standard placeholder attribute supported in older versions.
this . element . querySelector ( 'option[placeholder]' ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( WrappedSelect . prototype , "optionGroups" , {
get : function ( ) {
return Array . from ( this . element . getElementsByTagName ( 'OPTGROUP' ) ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( WrappedSelect . prototype , "options" , {
get : function ( ) {
return Array . from ( this . element . options ) ;
} ,
set : function ( options ) {
var _this = this ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var fragment = document . createDocumentFragment ( ) ;
2019-10-28 20:53:24 +01:00
2021-12-19 22:58:00 +01:00
var addOptionToFragment = function ( data ) {
// Create a standard select option
var option = _this . template ( data ) ; // Append it to fragment
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
fragment . appendChild ( option ) ;
} ; // Add each list item to list
2017-11-07 12:59:49 +01:00
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
options . forEach ( function ( optionData ) {
return addOptionToFragment ( optionData ) ;
} ) ;
this . appendDocFragment ( fragment ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
WrappedSelect . prototype . appendDocFragment = function ( fragment ) {
this . element . innerHTML = '' ;
this . element . appendChild ( fragment ) ;
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
return WrappedSelect ;
} ( wrapped _element _1 . default ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = WrappedSelect ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
/***/ 883 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
2017-11-13 20:13:37 +01:00
2017-11-07 12:59:49 +01:00
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
exports . SCROLLING _SPEED = exports . SELECT _MULTIPLE _TYPE = exports . SELECT _ONE _TYPE = exports . TEXT _TYPE = exports . KEY _CODES = exports . ACTION _TYPES = exports . EVENTS = void 0 ;
exports . EVENTS = {
showDropdown : 'showDropdown' ,
hideDropdown : 'hideDropdown' ,
change : 'change' ,
choice : 'choice' ,
search : 'search' ,
addItem : 'addItem' ,
removeItem : 'removeItem' ,
highlightItem : 'highlightItem' ,
highlightChoice : 'highlightChoice' ,
unhighlightItem : 'unhighlightItem'
} ;
exports . ACTION _TYPES = {
ADD _CHOICE : 'ADD_CHOICE' ,
FILTER _CHOICES : 'FILTER_CHOICES' ,
ACTIVATE _CHOICES : 'ACTIVATE_CHOICES' ,
CLEAR _CHOICES : 'CLEAR_CHOICES' ,
ADD _GROUP : 'ADD_GROUP' ,
ADD _ITEM : 'ADD_ITEM' ,
REMOVE _ITEM : 'REMOVE_ITEM' ,
HIGHLIGHT _ITEM : 'HIGHLIGHT_ITEM' ,
CLEAR _ALL : 'CLEAR_ALL' ,
RESET _TO : 'RESET_TO' ,
SET _IS _LOADING : 'SET_IS_LOADING'
} ;
exports . KEY _CODES = {
BACK _KEY : 46 ,
DELETE _KEY : 8 ,
ENTER _KEY : 13 ,
A _KEY : 65 ,
ESC _KEY : 27 ,
UP _KEY : 38 ,
DOWN _KEY : 40 ,
PAGE _UP _KEY : 33 ,
PAGE _DOWN _KEY : 34
} ;
exports . TEXT _TYPE = 'text' ;
exports . SELECT _ONE _TYPE = 'select-one' ;
exports . SELECT _MULTIPLE _TYPE = 'select-multiple' ;
exports . SCROLLING _SPEED = 4 ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
/***/ 789 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
exports . DEFAULT _CONFIG = exports . DEFAULT _CLASSNAMES = void 0 ;
var utils _1 = _ _webpack _require _ _ ( 799 ) ;
exports . DEFAULT _CLASSNAMES = {
containerOuter : 'choices' ,
containerInner : 'choices__inner' ,
input : 'choices__input' ,
inputCloned : 'choices__input--cloned' ,
list : 'choices__list' ,
listItems : 'choices__list--multiple' ,
listSingle : 'choices__list--single' ,
listDropdown : 'choices__list--dropdown' ,
item : 'choices__item' ,
itemSelectable : 'choices__item--selectable' ,
itemDisabled : 'choices__item--disabled' ,
itemChoice : 'choices__item--choice' ,
placeholder : 'choices__placeholder' ,
group : 'choices__group' ,
groupHeading : 'choices__heading' ,
button : 'choices__button' ,
activeState : 'is-active' ,
focusState : 'is-focused' ,
openState : 'is-open' ,
disabledState : 'is-disabled' ,
highlightedState : 'is-highlighted' ,
selectedState : 'is-selected' ,
flippedState : 'is-flipped' ,
loadingState : 'is-loading' ,
noResults : 'has-no-results' ,
noChoices : 'has-no-choices'
} ;
exports . DEFAULT _CONFIG = {
items : [ ] ,
choices : [ ] ,
silent : false ,
renderChoiceLimit : - 1 ,
maxItemCount : - 1 ,
addItems : true ,
addItemFilter : null ,
removeItems : true ,
removeItemButton : false ,
editItems : false ,
2021-12-24 18:33:32 +01:00
allowHTML : true ,
2021-12-19 22:58:00 +01:00
duplicateItemsAllowed : true ,
delimiter : ',' ,
paste : true ,
searchEnabled : true ,
searchChoices : true ,
searchFloor : 1 ,
searchResultLimit : 4 ,
searchFields : [ 'label' , 'value' ] ,
position : 'auto' ,
resetScrollPosition : true ,
shouldSort : true ,
shouldSortItems : false ,
sorter : utils _1 . sortByAlpha ,
placeholder : true ,
placeholderValue : null ,
searchPlaceholderValue : null ,
prependValue : null ,
appendValue : null ,
renderSelectedChoices : 'auto' ,
loadingText : 'Loading...' ,
noResultsText : 'No results found' ,
noChoicesText : 'No choices to choose from' ,
itemSelectText : 'Press to select' ,
uniqueItemText : 'Only unique values can be added' ,
customAddItemText : 'Only values matching specific conditions can be added' ,
addItemText : function ( value ) {
return "Press Enter to add <b>\"" . concat ( ( 0 , utils _1 . sanitise ) ( value ) , "\"</b>" ) ;
} ,
maxItemText : function ( maxItemCount ) {
return "Only " . concat ( maxItemCount , " values can be added" ) ;
} ,
valueComparer : function ( value1 , value2 ) {
return value1 === value2 ;
} ,
fuseOptions : {
includeScore : true
} ,
2022-01-18 23:07:07 +01:00
labelId : '' ,
2021-12-19 22:58:00 +01:00
callbackOnInit : null ,
callbackOnCreateTemplates : null ,
classNames : exports . DEFAULT _CLASSNAMES
} ;
2019-10-22 23:20:40 +02:00
2019-12-23 19:22:54 +01:00
/***/ } ) ,
2019-10-22 23:20:40 +02:00
2021-12-27 15:50:45 +01:00
/***/ 18 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 978 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
/* eslint-disable @typescript-eslint/no-explicit-any */
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 948 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 359 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 285 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 533 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
/* eslint-disable @typescript-eslint/no-explicit-any */
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 187 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
var _ _createBinding = this && this . _ _createBinding || ( Object . create ? function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , {
enumerable : true ,
get : function ( ) {
return m [ k ] ;
}
} ) ;
} : function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ;
var _ _exportStar = this && this . _ _exportStar || function ( m , exports ) {
for ( var p in m ) if ( p !== "default" && ! Object . prototype . hasOwnProperty . call ( exports , p ) ) _ _createBinding ( exports , m , p ) ;
} ;
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
_ _exportStar ( _ _webpack _require _ _ ( 18 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 978 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 948 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 359 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 285 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 533 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 287 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 132 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 837 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 598 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 369 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 37 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 47 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 923 ) , exports ) ;
_ _exportStar ( _ _webpack _require _ _ ( 876 ) , exports ) ;
/***/ } ) ,
/***/ 287 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 132 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 837 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 598 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 37 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 369 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 47 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 923 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
/***/ 876 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/***/ } ) ,
2021-12-19 22:58:00 +01:00
/***/ 799 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
/* eslint-disable @typescript-eslint/no-explicit-any */
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
2022-03-14 15:57:05 +01:00
exports . parseCustomProperties = 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 ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var getRandomNumber = function ( min , max ) {
return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
2019-12-23 19:22:54 +01:00
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
exports . getRandomNumber = getRandomNumber ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var generateChars = function ( length ) {
return Array . from ( {
length : length
} , function ( ) {
return ( 0 , exports . getRandomNumber ) ( 0 , 36 ) . toString ( 36 ) ;
} ) . join ( '' ) ;
} ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
exports . generateChars = generateChars ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var generateId = function ( element , prefix ) {
var id = element . id || element . name && "" . concat ( element . name , "-" ) . concat ( ( 0 , exports . generateChars ) ( 2 ) ) || ( 0 , exports . generateChars ) ( 4 ) ;
id = id . replace ( /(:|\.|\[|\]|,)/g , '' ) ;
id = "" . concat ( prefix , "-" ) . concat ( id ) ;
return id ;
} ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
exports . generateId = generateId ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var getType = function ( obj ) {
return Object . prototype . toString . call ( obj ) . slice ( 8 , - 1 ) ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
exports . getType = getType ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var isType = function ( type , obj ) {
return obj !== undefined && obj !== null && ( 0 , exports . getType ) ( obj ) === type ;
} ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
exports . isType = isType ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
var wrap = function ( element , wrapper ) {
if ( wrapper === void 0 ) {
wrapper = document . createElement ( 'div' ) ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
if ( element . parentNode ) {
if ( element . nextSibling ) {
element . parentNode . insertBefore ( wrapper , element . nextSibling ) ;
} else {
element . parentNode . appendChild ( wrapper ) ;
2018-05-25 15:00:27 +02:00
}
2019-12-23 19:22:54 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
return wrapper . appendChild ( element ) ;
2019-12-23 19:22:54 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
exports . wrap = wrap ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var getAdjacentEl = function ( startEl , selector , direction ) {
if ( direction === void 0 ) {
direction = 1 ;
2019-12-23 19:22:54 +01:00
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
var prop = "" . concat ( direction > 0 ? 'next' : 'previous' , "ElementSibling" ) ;
var sibling = startEl [ prop ] ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
while ( sibling ) {
if ( sibling . matches ( selector ) ) {
return sibling ;
}
sibling = sibling [ prop ] ;
}
return sibling ;
} ;
exports . getAdjacentEl = getAdjacentEl ;
var isScrolledIntoView = function ( element , parent , direction ) {
if ( direction === void 0 ) {
direction = 1 ;
}
if ( ! element ) {
return false ;
}
var isVisible ;
if ( direction > 0 ) {
// In view from bottom
isVisible = parent . scrollTop + parent . offsetHeight >= element . offsetTop + element . offsetHeight ;
} else {
// In view from top
isVisible = element . offsetTop >= parent . scrollTop ;
}
return isVisible ;
} ;
exports . isScrolledIntoView = isScrolledIntoView ;
var sanitise = function ( value ) {
if ( typeof value !== 'string' ) {
return value ;
}
2021-12-24 18:33:32 +01:00
return value . replace ( /&/g , '&' ) . replace ( />/g , '>' ) . replace ( /</g , '<' ) . replace ( /"/g , '"' ) ;
2021-12-19 22:58:00 +01:00
} ;
exports . sanitise = sanitise ;
exports . strToEl = function ( ) {
var tmpEl = document . createElement ( 'div' ) ;
return function ( str ) {
var cleanedInput = str . trim ( ) ;
tmpEl . innerHTML = cleanedInput ;
var firldChild = tmpEl . children [ 0 ] ;
while ( tmpEl . firstChild ) {
tmpEl . removeChild ( tmpEl . firstChild ) ;
}
return firldChild ;
} ;
} ( ) ;
var sortByAlpha = function ( _a , _b ) {
var value = _a . value ,
_c = _a . label ,
label = _c === void 0 ? value : _c ;
var value2 = _b . value ,
_d = _b . label ,
label2 = _d === void 0 ? value2 : _d ;
return label . localeCompare ( label2 , [ ] , {
sensitivity : 'base' ,
ignorePunctuation : true ,
numeric : true
} ) ;
} ;
exports . sortByAlpha = sortByAlpha ;
var sortByScore = function ( a , b ) {
var _a = a . score ,
scoreA = _a === void 0 ? 0 : _a ;
var _b = b . score ,
scoreB = _b === void 0 ? 0 : _b ;
return scoreA - scoreB ;
} ;
exports . sortByScore = sortByScore ;
var dispatchEvent = function ( element , type , customArgs ) {
if ( customArgs === void 0 ) {
customArgs = null ;
}
var event = new CustomEvent ( type , {
detail : customArgs ,
bubbles : true ,
cancelable : true
} ) ;
return element . dispatchEvent ( event ) ;
} ;
exports . dispatchEvent = dispatchEvent ;
var existsInArray = function ( array , value , key ) {
if ( key === void 0 ) {
key = 'value' ;
}
return array . some ( function ( item ) {
if ( typeof value === 'string' ) {
return item [ key ] === value . trim ( ) ;
}
return item [ key ] === value ;
} ) ;
} ;
exports . existsInArray = existsInArray ;
var cloneObject = function ( obj ) {
return JSON . parse ( JSON . stringify ( obj ) ) ;
} ;
exports . cloneObject = cloneObject ;
/ * *
* Returns an array of keys present on the first but missing on the second object
* /
var diff = function ( a , b ) {
var aKeys = Object . keys ( a ) . sort ( ) ;
var bKeys = Object . keys ( b ) . sort ( ) ;
return aKeys . filter ( function ( i ) {
return bKeys . indexOf ( i ) < 0 ;
} ) ;
} ;
exports . diff = diff ;
2022-03-14 15:57:05 +01:00
var parseCustomProperties = function ( customProperties ) {
if ( typeof customProperties !== 'undefined' ) {
try {
return JSON . parse ( customProperties ) ;
} catch ( e ) {
return customProperties ;
}
}
return { } ;
} ;
exports . parseCustomProperties = parseCustomProperties ;
2021-12-19 22:58:00 +01:00
/***/ } ) ,
/***/ 273 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
var _ _spreadArray = this && this . _ _spreadArray || function ( to , from , pack ) {
if ( pack || arguments . length === 2 ) for ( var i = 0 , l = from . length , ar ; i < l ; i ++ ) {
if ( ar || ! ( i in from ) ) {
if ( ! ar ) ar = Array . prototype . slice . call ( from , 0 , i ) ;
ar [ i ] = from [ i ] ;
}
}
return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
} ;
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
exports . defaultState = void 0 ;
exports . defaultState = [ ] ;
function choices ( state , action ) {
if ( state === void 0 ) {
state = exports . defaultState ;
}
if ( action === void 0 ) {
action = { } ;
}
switch ( action . type ) {
case 'ADD_CHOICE' :
{
var addChoiceAction = action ;
var choice = {
id : addChoiceAction . id ,
elementId : addChoiceAction . elementId ,
groupId : addChoiceAction . groupId ,
value : addChoiceAction . value ,
label : addChoiceAction . label || addChoiceAction . value ,
disabled : addChoiceAction . disabled || false ,
selected : false ,
active : true ,
score : 9999 ,
customProperties : addChoiceAction . customProperties ,
placeholder : addChoiceAction . placeholder || false
} ;
/ *
A disabled choice appears in the choice dropdown but cannot be selected
A selected choice has been added to the passed input ' s value ( added as an item )
An active choice appears within the choice dropdown
* /
return _ _spreadArray ( _ _spreadArray ( [ ] , state , true ) , [ choice ] , false ) ;
}
case 'ADD_ITEM' :
2019-12-23 19:22:54 +01:00
{
var addItemAction _1 = action ; // When an item is added and it has an associated choice,
// we want to disable it so it can't be chosen again
2017-11-15 07:51:53 +01:00
2019-12-23 19:22:54 +01:00
if ( addItemAction _1 . choiceId > - 1 ) {
return state . map ( function ( obj ) {
var choice = obj ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( choice . id === parseInt ( "" . concat ( addItemAction _1 . choiceId ) , 10 ) ) {
2019-12-23 19:22:54 +01:00
choice . selected = true ;
}
2017-11-07 12:59:49 +01:00
2019-12-23 19:22:54 +01:00
return choice ;
} ) ;
}
return state ;
2019-10-22 23:20:40 +02:00
}
2019-02-09 19:13:25 +01:00
2019-12-23 19:22:54 +01:00
case 'REMOVE_ITEM' :
{
var removeItemAction _1 = action ; // When an item is removed and it has an associated choice,
// we want to re-enable it so it can be chosen again
2019-02-09 19:13:25 +01:00
2019-12-23 19:22:54 +01:00
if ( removeItemAction _1 . choiceId && removeItemAction _1 . choiceId > - 1 ) {
return state . map ( function ( obj ) {
var choice = obj ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
if ( choice . id === parseInt ( "" . concat ( removeItemAction _1 . choiceId ) , 10 ) ) {
2019-12-23 19:22:54 +01:00
choice . selected = false ;
}
2017-11-07 12:59:49 +01:00
2019-12-23 19:22:54 +01:00
return choice ;
} ) ;
}
2019-10-22 23:20:40 +02:00
2019-12-23 19:22:54 +01:00
return state ;
}
2019-10-22 23:20:40 +02:00
2019-12-23 19:22:54 +01:00
case 'FILTER_CHOICES' :
{
var filterChoicesAction _1 = action ;
return state . map ( function ( obj ) {
var choice = obj ; // Set active state based on whether choice is
// within filtered results
2019-10-29 22:19:56 +01:00
2019-12-23 19:22:54 +01:00
choice . active = filterChoicesAction _1 . results . some ( function ( _a ) {
var item = _a . item ,
score = _a . score ;
2019-10-22 23:20:40 +02:00
2019-12-23 19:22:54 +01:00
if ( item . id === choice . id ) {
choice . score = score ;
return true ;
}
2017-11-13 20:13:37 +01:00
2019-12-23 19:22:54 +01:00
return false ;
} ) ;
return choice ;
} ) ;
}
2018-05-28 17:22:22 +02:00
2019-12-23 19:22:54 +01:00
case 'ACTIVATE_CHOICES' :
{
var activateChoicesAction _1 = action ;
return state . map ( function ( obj ) {
var choice = obj ;
choice . active = activateChoicesAction _1 . active ;
return choice ;
2019-10-22 23:20:40 +02:00
} ) ;
2019-12-23 19:22:54 +01:00
}
2019-10-22 23:20:40 +02:00
2019-12-23 19:22:54 +01:00
case 'CLEAR_CHOICES' :
{
return exports . defaultState ;
2018-05-28 17:22:22 +02:00
}
2019-10-22 23:20:40 +02:00
2019-12-23 19:22:54 +01:00
default :
{
return state ;
}
}
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = choices ;
2019-10-22 23:20:40 +02:00
2019-12-23 19:22:54 +01:00
/***/ } ) ,
2021-12-19 22:58:00 +01:00
/***/ 871 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
2017-11-15 07:51:53 +01:00
2017-11-07 12:59:49 +01:00
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var _ _spreadArray = this && this . _ _spreadArray || function ( to , from , pack ) {
if ( pack || arguments . length === 2 ) for ( var i = 0 , l = from . length , ar ; i < l ; i ++ ) {
if ( ar || ! ( i in from ) ) {
if ( ! ar ) ar = Array . prototype . slice . call ( from , 0 , i ) ;
ar [ i ] = from [ i ] ;
}
}
return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
} ;
Object . defineProperty ( exports , "__esModule" , ( {
2019-12-23 19:22:54 +01:00
value : true
2021-12-19 22:58:00 +01:00
} ) ) ;
exports . defaultState = void 0 ;
exports . defaultState = [ ] ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
function groups ( state , action ) {
2019-12-23 19:22:54 +01:00
if ( state === void 0 ) {
state = exports . defaultState ;
}
2021-12-19 22:58:00 +01:00
if ( action === void 0 ) {
action = { } ;
}
2019-12-23 19:22:54 +01:00
switch ( action . type ) {
2021-12-19 22:58:00 +01:00
case 'ADD_GROUP' :
2019-12-23 19:22:54 +01:00
{
2021-12-19 22:58:00 +01:00
var addGroupAction = action ;
return _ _spreadArray ( _ _spreadArray ( [ ] , state , true ) , [ {
id : addGroupAction . id ,
value : addGroupAction . value ,
active : addGroupAction . active ,
disabled : addGroupAction . disabled
} ] , false ) ;
}
case 'CLEAR_CHOICES' :
{
return [ ] ;
2019-12-23 19:22:54 +01:00
}
default :
{
return state ;
}
}
2021-12-19 22:58:00 +01:00
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = groups ;
2017-11-07 12:59:49 +01:00
2019-12-23 19:22:54 +01:00
/***/ } ) ,
2021-12-19 22:58:00 +01:00
/***/ 655 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2019-11-08 10:19:18 +01:00
2019-12-23 19:22:54 +01:00
var _ _importDefault = this && this . _ _importDefault || function ( mod ) {
return mod && mod . _ _esModule ? mod : {
"default" : mod
2019-10-22 23:20:40 +02:00
} ;
2019-12-23 19:22:54 +01:00
} ;
2018-05-28 17:22:22 +02:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
2019-12-23 19:22:54 +01:00
value : true
2021-12-19 22:58:00 +01:00
} ) ) ;
exports . defaultState = void 0 ;
2018-06-07 17:54:11 +02:00
2021-12-19 22:58:00 +01:00
var redux _1 = _ _webpack _require _ _ ( 857 ) ;
2018-06-07 17:54:11 +02:00
2021-12-19 22:58:00 +01:00
var items _1 = _ _importDefault ( _ _webpack _require _ _ ( 52 ) ) ;
2018-05-28 17:22:22 +02:00
2021-12-19 22:58:00 +01:00
var groups _1 = _ _importDefault ( _ _webpack _require _ _ ( 871 ) ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var choices _1 = _ _importDefault ( _ _webpack _require _ _ ( 273 ) ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var loading _1 = _ _importDefault ( _ _webpack _require _ _ ( 502 ) ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var utils _1 = _ _webpack _require _ _ ( 799 ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
exports . defaultState = {
groups : [ ] ,
items : [ ] ,
choices : [ ] ,
loading : false
} ;
var appReducer = ( 0 , redux _1 . combineReducers ) ( {
items : items _1 . default ,
groups : groups _1 . default ,
choices : choices _1 . default ,
loading : loading _1 . default
} ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var rootReducer = function ( passedState , action ) {
var state = passedState ; // If we are clearing all items, groups and options we reassign
// state and then pass that state to our proper reducer. This isn't
// mutating our actual state
// See: http://stackoverflow.com/a/35641992
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( action . type === 'CLEAR_ALL' ) {
state = exports . defaultState ;
} else if ( action . type === 'RESET_TO' ) {
return ( 0 , utils _1 . cloneObject ) ( action . state ) ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
return appReducer ( state , action ) ;
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = rootReducer ;
2017-11-07 12:59:49 +01:00
2019-12-23 19:22:54 +01:00
/***/ } ) ,
2021-12-19 22:58:00 +01:00
/***/ 52 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var _ _spreadArray = this && this . _ _spreadArray || function ( to , from , pack ) {
if ( pack || arguments . length === 2 ) for ( var i = 0 , l = from . length , ar ; i < l ; i ++ ) {
if ( ar || ! ( i in from ) ) {
if ( ! ar ) ar = Array . prototype . slice . call ( from , 0 , i ) ;
ar [ i ] = from [ i ] ;
}
}
return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
} ;
Object . defineProperty ( exports , "__esModule" , ( {
2019-12-23 19:22:54 +01:00
value : true
2021-12-19 22:58:00 +01:00
} ) ) ;
exports . defaultState = void 0 ;
exports . defaultState = [ ] ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
function items ( state , action ) {
if ( state === void 0 ) {
state = exports . defaultState ;
2019-12-23 19:22:54 +01:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( action === void 0 ) {
action = { } ;
}
2018-05-28 16:13:55 +02:00
2021-12-19 22:58:00 +01:00
switch ( action . type ) {
case 'ADD_ITEM' :
{
var addItemAction = action ; // Add object to items array
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var newState = _ _spreadArray ( _ _spreadArray ( [ ] , state , true ) , [ {
id : addItemAction . id ,
choiceId : addItemAction . choiceId ,
groupId : addItemAction . groupId ,
value : addItemAction . value ,
label : addItemAction . label ,
active : true ,
highlighted : false ,
customProperties : addItemAction . customProperties ,
placeholder : addItemAction . placeholder || false ,
keyCode : null
} ] , false ) ;
2018-05-28 16:13:55 +02:00
2021-12-19 22:58:00 +01:00
return newState . map ( function ( obj ) {
var item = obj ;
item . highlighted = false ;
return item ;
} ) ;
}
2018-05-28 16:13:55 +02:00
2021-12-19 22:58:00 +01:00
case 'REMOVE_ITEM' :
{
// Set item to inactive
return state . map ( function ( obj ) {
var item = obj ;
2018-05-28 16:13:55 +02:00
2021-12-19 22:58:00 +01:00
if ( item . id === action . id ) {
item . active = false ;
}
2018-05-28 16:13:55 +02:00
2021-12-19 22:58:00 +01:00
return item ;
} ) ;
}
2018-05-28 16:13:55 +02:00
2021-12-19 22:58:00 +01:00
case 'HIGHLIGHT_ITEM' :
{
var highlightItemAction _1 = action ;
return state . map ( function ( obj ) {
var item = obj ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
if ( item . id === highlightItemAction _1 . id ) {
item . highlighted = highlightItemAction _1 . highlighted ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
return item ;
} ) ;
}
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
default :
{
return state ;
}
2019-11-13 16:40:47 +01:00
}
2021-12-19 22:58:00 +01:00
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = items ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2019-11-22 20:13:46 +01:00
2021-12-19 22:58:00 +01:00
/***/ 502 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
2019-12-23 19:22:54 +01:00
2019-10-22 23:20:40 +02:00
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
exports . defaultState = void 0 ;
exports . defaultState = false ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var general = function ( state , action ) {
if ( state === void 0 ) {
state = exports . defaultState ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( action === void 0 ) {
action = { } ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
switch ( action . type ) {
case 'SET_IS_LOADING' :
{
return action . isLoading ;
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
default :
{
return state ;
}
}
} ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = general ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
/***/ 744 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
var _ _spreadArray = this && this . _ _spreadArray || function ( to , from , pack ) {
if ( pack || arguments . length === 2 ) for ( var i = 0 , l = from . length , ar ; i < l ; i ++ ) {
if ( ar || ! ( i in from ) ) {
if ( ! ar ) ar = Array . prototype . slice . call ( from , 0 , i ) ;
ar [ i ] = from [ i ] ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
}
return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
} ;
2017-11-13 20:13:37 +01:00
2021-12-19 22:58:00 +01:00
var _ _importDefault = this && this . _ _importDefault || function ( mod ) {
return mod && mod . _ _esModule ? mod : {
"default" : mod
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
} ;
2017-11-07 12:59:49 +01:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
value : true
} ) ) ;
/* eslint-disable @typescript-eslint/no-explicit-any */
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var redux _1 = _ _webpack _require _ _ ( 857 ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var index _1 = _ _importDefault ( _ _webpack _require _ _ ( 655 ) ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var Store =
/** @class */
function ( ) {
function Store ( ) {
this . _store = ( 0 , redux _1 . createStore ) ( index _1 . default , window . _ _REDUX _DEVTOOLS _EXTENSION _ _ && window . _ _REDUX _DEVTOOLS _EXTENSION _ _ ( ) ) ;
}
/ * *
* Subscribe store to function call ( wrapped Redux method )
* /
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Store . prototype . subscribe = function ( onChange ) {
this . _store . subscribe ( onChange ) ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
/ * *
* Dispatch event to store ( wrapped Redux method )
* /
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Store . prototype . dispatch = function ( action ) {
this . _store . dispatch ( action ) ;
2019-12-23 19:22:54 +01:00
} ;
2018-05-25 15:00:27 +02:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( Store . prototype , "state" , {
/ * *
* Get store object ( wrapping Redux method )
* /
get : function ( ) {
return this . _store . getState ( ) ;
2019-12-23 19:22:54 +01:00
} ,
2021-12-19 22:58:00 +01:00
enumerable : false ,
2019-12-23 19:22:54 +01:00
configurable : true
} ) ;
2021-12-19 22:58:00 +01:00
Object . defineProperty ( Store . prototype , "items" , {
/ * *
* Get items from store
* /
get : function ( ) {
return this . state . items ;
2019-12-23 19:22:54 +01:00
} ,
2021-12-19 22:58:00 +01:00
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( Store . prototype , "activeItems" , {
/ * *
* Get active items from store
* /
get : function ( ) {
return this . items . filter ( function ( item ) {
return item . active === true ;
} ) ;
2019-12-23 19:22:54 +01:00
} ,
2021-12-19 22:58:00 +01:00
enumerable : false ,
2019-12-23 19:22:54 +01:00
configurable : true
} ) ;
2021-12-19 22:58:00 +01:00
Object . defineProperty ( Store . prototype , "highlightedActiveItems" , {
/ * *
* Get highlighted items from store
* /
get : function ( ) {
return this . items . filter ( function ( item ) {
return item . active && item . highlighted ;
} ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( Store . prototype , "choices" , {
/ * *
* Get choices from store
* /
get : function ( ) {
return this . state . choices ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( Store . prototype , "activeChoices" , {
/ * *
* Get active choices from store
* /
get : function ( ) {
return this . choices . filter ( function ( choice ) {
return choice . active === true ;
} ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( Store . prototype , "selectableChoices" , {
/ * *
* Get selectable choices from store
* /
get : function ( ) {
return this . choices . filter ( function ( choice ) {
return choice . disabled !== true ;
} ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( Store . prototype , "searchableChoices" , {
/ * *
* Get choices that can be searched ( excluding placeholders )
* /
get : function ( ) {
return this . selectableChoices . filter ( function ( choice ) {
return choice . placeholder !== true ;
} ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( Store . prototype , "placeholderChoice" , {
/ * *
* Get placeholder choice from store
* /
get : function ( ) {
return _ _spreadArray ( [ ] , this . choices , true ) . reverse ( ) . find ( function ( choice ) {
return choice . placeholder === true ;
} ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( Store . prototype , "groups" , {
/ * *
* Get groups from store
* /
get : function ( ) {
return this . state . groups ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( Store . prototype , "activeGroups" , {
/ * *
* Get active groups from store
* /
get : function ( ) {
var _a = this ,
groups = _a . groups ,
choices = _a . choices ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
return groups . filter ( function ( group ) {
var isActive = group . active === true && group . disabled === false ;
var hasActiveOptions = choices . some ( function ( choice ) {
return choice . active === true && choice . disabled === false ;
} ) ;
return isActive && hasActiveOptions ;
} , [ ] ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
2019-12-23 19:22:54 +01:00
/ * *
2021-12-19 22:58:00 +01:00
* Get loading state from store
2019-12-23 19:22:54 +01:00
* /
2018-02-02 12:08:03 +01:00
2021-12-19 22:58:00 +01:00
Store . prototype . isLoading = function ( ) {
return this . state . loading ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
/ * *
* Get single choice by it ' s ID
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
Store . prototype . getChoiceById = function ( id ) {
return this . activeChoices . find ( function ( choice ) {
return choice . id === parseInt ( id , 10 ) ;
} ) ;
2019-10-22 23:20:40 +02:00
} ;
2021-12-19 22:58:00 +01:00
/ * *
* Get group by group id
* /
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
Store . prototype . getGroupById = function ( id ) {
return this . groups . find ( function ( group ) {
return group . id === id ;
} ) ;
2019-12-23 19:22:54 +01:00
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
return Store ;
2019-12-23 19:22:54 +01:00
} ( ) ;
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
exports [ "default" ] = Store ;
2017-11-15 07:51:53 +01:00
2019-12-23 19:22:54 +01:00
/***/ } ) ,
2021-12-19 22:58:00 +01:00
/***/ 686 :
/***/ ( function ( _ _unused _webpack _module , exports ) {
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
/ * *
* Helpers to create HTML elements used by Choices
* Can be overridden by providing ` callbackOnCreateTemplates ` option
* /
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
Object . defineProperty ( exports , "__esModule" , ( {
2019-12-23 19:22:54 +01:00
value : true
2021-12-19 22:58:00 +01:00
} ) ) ;
var templates = {
2022-01-18 23:07:07 +01:00
containerOuter : function ( _a , dir , isSelectElement , isSelectOneElement , searchEnabled , passedElementType , labelId ) {
2021-12-24 18:33:32 +01:00
var containerOuter = _a . classNames . containerOuter ;
2021-12-19 22:58:00 +01:00
var div = Object . assign ( document . createElement ( 'div' ) , {
className : containerOuter
} ) ;
div . dataset . type = passedElementType ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( dir ) {
div . dir = dir ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( isSelectOneElement ) {
div . tabIndex = 0 ;
2019-10-22 23:20:40 +02:00
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
if ( isSelectElement ) {
div . setAttribute ( 'role' , searchEnabled ? 'combobox' : 'listbox' ) ;
2019-11-13 16:40:47 +01:00
2021-12-19 22:58:00 +01:00
if ( searchEnabled ) {
div . setAttribute ( 'aria-autocomplete' , 'list' ) ;
}
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
div . setAttribute ( 'aria-haspopup' , 'true' ) ;
div . setAttribute ( 'aria-expanded' , 'false' ) ;
2022-01-18 23:07:07 +01:00
if ( labelId ) {
div . setAttribute ( 'aria-labeledby' , labelId ) ;
}
2021-12-19 22:58:00 +01:00
return div ;
} ,
containerInner : function ( _a ) {
2021-12-24 18:33:32 +01:00
var containerInner = _a . classNames . containerInner ;
2021-12-19 22:58:00 +01:00
return Object . assign ( document . createElement ( 'div' ) , {
className : containerInner
} ) ;
} ,
itemList : function ( _a , isSelectOneElement ) {
2021-12-24 18:33:32 +01:00
var _b = _a . classNames ,
list = _b . list ,
listSingle = _b . listSingle ,
listItems = _b . listItems ;
2021-12-19 22:58:00 +01:00
return Object . assign ( document . createElement ( 'div' ) , {
className : "" . concat ( list , " " ) . concat ( isSelectOneElement ? listSingle : listItems )
} ) ;
} ,
placeholder : function ( _a , value ) {
2021-12-24 18:33:32 +01:00
var _b ;
var allowHTML = _a . allowHTML ,
placeholder = _a . classNames . placeholder ;
return Object . assign ( document . createElement ( 'div' ) , ( _b = {
className : placeholder
} , _b [ allowHTML ? 'innerHTML' : 'innerText' ] = value , _b ) ) ;
2021-12-19 22:58:00 +01:00
} ,
item : function ( _a , _b , removeItemButton ) {
2021-12-24 18:33:32 +01:00
var _c , _d ;
var allowHTML = _a . allowHTML ,
_e = _a . classNames ,
item = _e . item ,
button = _e . button ,
highlightedState = _e . highlightedState ,
itemSelectable = _e . itemSelectable ,
placeholder = _e . placeholder ;
2021-12-19 22:58:00 +01:00
var id = _b . id ,
value = _b . value ,
label = _b . label ,
customProperties = _b . customProperties ,
active = _b . active ,
disabled = _b . disabled ,
highlighted = _b . highlighted ,
isPlaceholder = _b . placeholder ;
2021-12-24 18:33:32 +01:00
var div = Object . assign ( document . createElement ( 'div' ) , ( _c = {
className : item
} , _c [ allowHTML ? 'innerHTML' : 'innerText' ] = label , _c ) ) ;
2021-12-19 22:58:00 +01:00
Object . assign ( div . dataset , {
item : '' ,
id : id ,
value : value ,
customProperties : customProperties
2019-12-23 19:22:54 +01:00
} ) ;
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
if ( active ) {
div . setAttribute ( 'aria-selected' , 'true' ) ;
}
2016-08-23 08:24:45 +02:00
2021-12-19 22:58:00 +01:00
if ( disabled ) {
div . setAttribute ( 'aria-disabled' , 'true' ) ;
}
2017-08-18 06:01:03 +02:00
2021-12-19 22:58:00 +01:00
if ( isPlaceholder ) {
div . classList . add ( placeholder ) ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
div . classList . add ( highlighted ? highlightedState : itemSelectable ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
if ( removeItemButton ) {
if ( disabled ) {
div . classList . remove ( itemSelectable ) ;
2019-10-22 23:20:40 +02:00
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
div . dataset . deletable = '' ;
/** @todo This MUST be localizable, not hardcoded! */
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
var REMOVE _ITEM _TEXT = 'Remove item' ;
2021-12-24 18:33:32 +01:00
var removeButton = Object . assign ( document . createElement ( 'button' ) , ( _d = {
2021-12-19 22:58:00 +01:00
type : 'button' ,
2021-12-24 18:33:32 +01:00
className : button
} , _d [ allowHTML ? 'innerHTML' : 'innerText' ] = REMOVE _ITEM _TEXT , _d ) ) ;
2021-12-19 22:58:00 +01:00
removeButton . setAttribute ( 'aria-label' , "" . concat ( REMOVE _ITEM _TEXT , ": '" ) . concat ( value , "'" ) ) ;
removeButton . dataset . button = '' ;
div . appendChild ( removeButton ) ;
2019-10-22 23:20:40 +02:00
}
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
return div ;
} ,
choiceList : function ( _a , isSelectOneElement ) {
2021-12-24 18:33:32 +01:00
var list = _a . classNames . list ;
2021-12-19 22:58:00 +01:00
var div = Object . assign ( document . createElement ( 'div' ) , {
className : list
} ) ;
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
if ( ! isSelectOneElement ) {
div . setAttribute ( 'aria-multiselectable' , 'true' ) ;
}
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
div . setAttribute ( 'role' , 'listbox' ) ;
return div ;
} ,
choiceGroup : function ( _a , _b ) {
2021-12-24 18:33:32 +01:00
var _c ;
var allowHTML = _a . allowHTML ,
_d = _a . classNames ,
group = _d . group ,
groupHeading = _d . groupHeading ,
itemDisabled = _d . itemDisabled ;
2021-12-19 22:58:00 +01:00
var id = _b . id ,
value = _b . value ,
disabled = _b . disabled ;
var div = Object . assign ( document . createElement ( 'div' ) , {
className : "" . concat ( group , " " ) . concat ( disabled ? itemDisabled : '' )
} ) ;
div . setAttribute ( 'role' , 'group' ) ;
Object . assign ( div . dataset , {
group : '' ,
id : id ,
value : value
} ) ;
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
if ( disabled ) {
div . setAttribute ( 'aria-disabled' , 'true' ) ;
}
2019-10-22 12:25:36 +02:00
2021-12-24 18:33:32 +01:00
div . appendChild ( Object . assign ( document . createElement ( 'div' ) , ( _c = {
className : groupHeading
} , _c [ allowHTML ? 'innerHTML' : 'innerText' ] = value , _c ) ) ) ;
2021-12-19 22:58:00 +01:00
return div ;
} ,
choice : function ( _a , _b , selectText ) {
2021-12-24 18:33:32 +01:00
var _c ;
var allowHTML = _a . allowHTML ,
_d = _a . classNames ,
item = _d . item ,
itemChoice = _d . itemChoice ,
itemSelectable = _d . itemSelectable ,
selectedState = _d . selectedState ,
itemDisabled = _d . itemDisabled ,
placeholder = _d . placeholder ;
2021-12-19 22:58:00 +01:00
var id = _b . id ,
value = _b . value ,
label = _b . label ,
groupId = _b . groupId ,
elementId = _b . elementId ,
isDisabled = _b . disabled ,
isSelected = _b . selected ,
isPlaceholder = _b . placeholder ;
2021-12-24 18:33:32 +01:00
var div = Object . assign ( document . createElement ( 'div' ) , ( _c = {
id : elementId
} , _c [ allowHTML ? 'innerHTML' : 'innerText' ] = label , _c . className = "" . concat ( item , " " ) . concat ( itemChoice ) , _c ) ) ;
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
if ( isSelected ) {
div . classList . add ( selectedState ) ;
}
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
if ( isPlaceholder ) {
div . classList . add ( placeholder ) ;
}
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
div . setAttribute ( 'role' , groupId && groupId > 0 ? 'treeitem' : 'option' ) ;
Object . assign ( div . dataset , {
choice : '' ,
id : id ,
value : value ,
selectText : selectText
} ) ;
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
if ( isDisabled ) {
div . classList . add ( itemDisabled ) ;
div . dataset . choiceDisabled = '' ;
div . setAttribute ( 'aria-disabled' , 'true' ) ;
} else {
div . classList . add ( itemSelectable ) ;
div . dataset . choiceSelectable = '' ;
2019-12-23 19:22:54 +01:00
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
return div ;
} ,
input : function ( _a , placeholderValue ) {
2021-12-24 18:33:32 +01:00
var _b = _a . classNames ,
input = _b . input ,
inputCloned = _b . inputCloned ;
2021-12-19 22:58:00 +01:00
var inp = Object . assign ( document . createElement ( 'input' ) , {
2021-12-24 18:33:32 +01:00
type : 'search' ,
name : 'search_terms' ,
2021-12-19 22:58:00 +01:00
className : "" . concat ( input , " " ) . concat ( inputCloned ) ,
autocomplete : 'off' ,
autocapitalize : 'off' ,
spellcheck : false
} ) ;
inp . setAttribute ( 'role' , 'textbox' ) ;
inp . setAttribute ( 'aria-autocomplete' , 'list' ) ;
inp . setAttribute ( 'aria-label' , placeholderValue ) ;
return inp ;
} ,
dropdown : function ( _a ) {
2021-12-24 18:33:32 +01:00
var _b = _a . classNames ,
list = _b . list ,
listDropdown = _b . listDropdown ;
2021-12-19 22:58:00 +01:00
var div = document . createElement ( 'div' ) ;
div . classList . add ( list , listDropdown ) ;
div . setAttribute ( 'aria-expanded' , 'false' ) ;
return div ;
} ,
2021-12-24 18:33:32 +01:00
notice : function ( _a , innerText , type ) {
var _b ;
var allowHTML = _a . allowHTML ,
_c = _a . classNames ,
item = _c . item ,
itemChoice = _c . itemChoice ,
noResults = _c . noResults ,
noChoices = _c . noChoices ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( type === void 0 ) {
type = '' ;
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var classes = [ item , itemChoice ] ;
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( type === 'no-choices' ) {
classes . push ( noChoices ) ;
} else if ( type === 'no-results' ) {
classes . push ( noResults ) ;
}
2019-11-03 18:45:16 +01:00
2021-12-24 18:33:32 +01:00
return Object . assign ( document . createElement ( 'div' ) , ( _b = { } , _b [ allowHTML ? 'innerHTML' : 'innerText' ] = innerText , _b . className = classes . join ( ' ' ) , _b ) ) ;
2021-12-19 22:58:00 +01:00
} ,
option : function ( _a ) {
var label = _a . label ,
value = _a . value ,
customProperties = _a . customProperties ,
active = _a . active ,
disabled = _a . disabled ;
var opt = new Option ( label , value , false , active ) ;
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
if ( customProperties ) {
opt . dataset . customProperties = "" . concat ( customProperties ) ;
}
2019-10-22 12:25:36 +02:00
2021-12-19 22:58:00 +01:00
opt . disabled = ! ! disabled ;
return opt ;
2019-12-23 19:22:54 +01:00
}
2021-12-19 22:58:00 +01:00
} ;
exports [ "default" ] = templates ;
2017-09-18 17:46:48 +02:00
2019-12-23 19:22:54 +01:00
/***/ } ) ,
2021-12-19 22:58:00 +01:00
/***/ 996 :
/***/ ( function ( module ) {
2017-09-18 17:46:48 +02:00
2021-12-19 22:58:00 +01:00
var isMergeableObject = function isMergeableObject ( value ) {
return isNonNullObject ( value )
&& ! isSpecial ( value )
} ;
2017-09-18 17:46:48 +02:00
2021-12-19 22:58:00 +01:00
function isNonNullObject ( value ) {
return ! ! value && typeof value === 'object'
}
2017-09-18 17:46:48 +02:00
2021-12-19 22:58:00 +01:00
function isSpecial ( value ) {
var stringValue = Object . prototype . toString . call ( value ) ;
2017-09-18 17:46:48 +02:00
2021-12-19 22:58:00 +01:00
return stringValue === '[object RegExp]'
|| stringValue === '[object Date]'
|| isReactElement ( value )
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25
var canUseSymbol = typeof Symbol === 'function' && Symbol . for ;
var REACT _ELEMENT _TYPE = canUseSymbol ? Symbol . for ( 'react.element' ) : 0xeac7 ;
2017-09-18 17:46:48 +02:00
2021-12-19 22:58:00 +01:00
function isReactElement ( value ) {
return value . $$typeof === REACT _ELEMENT _TYPE
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
function emptyTarget ( val ) {
return Array . isArray ( val ) ? [ ] : { }
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
function cloneUnlessOtherwiseSpecified ( value , options ) {
return ( options . clone !== false && options . isMergeableObject ( value ) )
? deepmerge ( emptyTarget ( value ) , value , options )
: value
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
function defaultArrayMerge ( target , source , options ) {
return target . concat ( source ) . map ( function ( element ) {
return cloneUnlessOtherwiseSpecified ( element , options )
} )
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
function getMergeFunction ( key , options ) {
if ( ! options . customMerge ) {
return deepmerge
}
var customMerge = options . customMerge ( key ) ;
return typeof customMerge === 'function' ? customMerge : deepmerge
}
2017-09-18 17:46:48 +02:00
2021-12-19 22:58:00 +01:00
function getEnumerableOwnPropertySymbols ( target ) {
return Object . getOwnPropertySymbols
? Object . getOwnPropertySymbols ( target ) . filter ( function ( symbol ) {
return target . propertyIsEnumerable ( symbol )
} )
: [ ]
}
2017-09-18 17:46:48 +02:00
2021-12-19 22:58:00 +01:00
function getKeys ( target ) {
return Object . keys ( target ) . concat ( getEnumerableOwnPropertySymbols ( target ) )
}
2017-09-18 17:46:48 +02:00
2021-12-19 22:58:00 +01:00
function propertyIsOnObject ( object , property ) {
try {
return property in object
} catch ( _ ) {
return false
}
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
// Protects from prototype poisoning and unexpected merging up the prototype chain.
function propertyIsUnsafe ( target , key ) {
return propertyIsOnObject ( target , key ) // Properties are safe to merge if they don't exist in the target yet,
&& ! ( Object . hasOwnProperty . call ( target , key ) // unsafe if they exist up the prototype chain,
&& Object . propertyIsEnumerable . call ( target , key ) ) // and also unsafe if they're nonenumerable.
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
function mergeObject ( target , source , options ) {
var destination = { } ;
if ( options . isMergeableObject ( target ) ) {
getKeys ( target ) . forEach ( function ( key ) {
destination [ key ] = cloneUnlessOtherwiseSpecified ( target [ key ] , options ) ;
} ) ;
}
getKeys ( source ) . forEach ( function ( key ) {
if ( propertyIsUnsafe ( target , key ) ) {
return
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( propertyIsOnObject ( target , key ) && options . isMergeableObject ( source [ key ] ) ) {
destination [ key ] = getMergeFunction ( key , options ) ( target [ key ] , source [ key ] , options ) ;
} else {
destination [ key ] = cloneUnlessOtherwiseSpecified ( source [ key ] , options ) ;
}
} ) ;
return destination
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
function deepmerge ( target , source , options ) {
options = options || { } ;
options . arrayMerge = options . arrayMerge || defaultArrayMerge ;
options . isMergeableObject = options . isMergeableObject || isMergeableObject ;
// cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()
// implementations can use it. The caller may not replace it.
options . cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
var sourceIsArray = Array . isArray ( source ) ;
var targetIsArray = Array . isArray ( target ) ;
var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( ! sourceAndTargetTypesMatch ) {
return cloneUnlessOtherwiseSpecified ( source , options )
} else if ( sourceIsArray ) {
return options . arrayMerge ( target , source , options )
} else {
return mergeObject ( target , source , options )
}
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
deepmerge . all = function deepmergeAll ( array , options ) {
if ( ! Array . isArray ( array ) ) {
throw new Error ( 'first argument should be an array' )
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
return array . reduce ( function ( prev , next ) {
return deepmerge ( prev , next , options )
} , { } )
} ;
var deepmerge _1 = deepmerge ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
module . exports = deepmerge _1 ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
2022-01-01 00:11:45 +01:00
/***/ 221 :
/***/ ( function ( _ _unused _webpack _module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
2017-11-15 07:51:53 +01:00
2022-01-01 00:11:45 +01:00
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
/* harmony export */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
/* harmony export */ "default" : function ( ) { return /* binding */ Fuse ; }
/* harmony export */ } ) ;
/ * *
* Fuse . js v6 . 5.3 - Lightweight fuzzy - search ( http : //fusejs.io)
*
* Copyright ( c ) 2021 Kiro Risk ( http : //kiro.me)
2021-12-19 22:58:00 +01:00
* All Rights Reserved . Apache Software License 2.0
2022-01-01 00:11:45 +01:00
*
2021-12-19 22:58:00 +01:00
* http : //www.apache.org/licenses/LICENSE-2.0
2019-12-23 19:22:54 +01:00
* /
2022-01-01 00:11:45 +01:00
function isArray ( value ) {
return ! Array . isArray
? getTag ( value ) === '[object Array]'
: Array . isArray ( value )
}
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js
const INFINITY = 1 / 0 ;
function baseToString ( value ) {
// Exit early for strings to avoid a performance hit in some environments.
if ( typeof value == 'string' ) {
return value
}
let result = value + '' ;
return result == '0' && 1 / value == - INFINITY ? '-0' : result
}
function toString ( value ) {
return value == null ? '' : baseToString ( value )
}
function isString ( value ) {
return typeof value === 'string'
}
function isNumber ( value ) {
return typeof value === 'number'
}
// Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js
function isBoolean ( value ) {
return (
value === true ||
value === false ||
( isObjectLike ( value ) && getTag ( value ) == '[object Boolean]' )
)
}
function isObject ( value ) {
return typeof value === 'object'
}
// Checks if `value` is object-like.
function isObjectLike ( value ) {
return isObject ( value ) && value !== null
}
function isDefined ( value ) {
return value !== undefined && value !== null
}
function isBlank ( value ) {
return ! value . trim ( ) . length
}
// Gets the `toStringTag` of `value`.
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js
function getTag ( value ) {
return value == null
? value === undefined
? '[object Undefined]'
: '[object Null]'
: Object . prototype . toString . call ( value )
}
const EXTENDED _SEARCH _UNAVAILABLE = 'Extended search is not available' ;
const INCORRECT _INDEX _TYPE = "Incorrect 'index' type" ;
const LOGICAL _SEARCH _INVALID _QUERY _FOR _KEY = ( key ) =>
` Invalid value for key ${ key } ` ;
const PATTERN _LENGTH _TOO _LARGE = ( max ) =>
` Pattern length exceeds max of ${ max } . ` ;
const MISSING _KEY _PROPERTY = ( name ) => ` Missing ${ name } property in key ` ;
const INVALID _KEY _WEIGHT _VALUE = ( key ) =>
` Property 'weight' in key ' ${ key } ' must be a positive integer ` ;
const hasOwn = Object . prototype . hasOwnProperty ;
class KeyStore {
constructor ( keys ) {
this . _keys = [ ] ;
this . _keyMap = { } ;
let totalWeight = 0 ;
keys . forEach ( ( key ) => {
let obj = createKey ( key ) ;
totalWeight += obj . weight ;
this . _keys . push ( obj ) ;
this . _keyMap [ obj . id ] = obj ;
totalWeight += obj . weight ;
} ) ;
// Normalize weights so that their sum is equal to 1
this . _keys . forEach ( ( key ) => {
key . weight /= totalWeight ;
} ) ;
}
get ( keyId ) {
return this . _keyMap [ keyId ]
}
keys ( ) {
return this . _keys
}
toJSON ( ) {
return JSON . stringify ( this . _keys )
}
}
function createKey ( key ) {
let path = null ;
let id = null ;
let src = null ;
let weight = 1 ;
if ( isString ( key ) || isArray ( key ) ) {
src = key ;
path = createKeyPath ( key ) ;
id = createKeyId ( key ) ;
} else {
if ( ! hasOwn . call ( key , 'name' ) ) {
throw new Error ( MISSING _KEY _PROPERTY ( 'name' ) )
}
const name = key . name ;
src = name ;
if ( hasOwn . call ( key , 'weight' ) ) {
weight = key . weight ;
if ( weight <= 0 ) {
throw new Error ( INVALID _KEY _WEIGHT _VALUE ( name ) )
}
}
path = createKeyPath ( name ) ;
id = createKeyId ( name ) ;
}
return { path , id , weight , src }
}
function createKeyPath ( key ) {
return isArray ( key ) ? key : key . split ( '.' )
}
function createKeyId ( key ) {
return isArray ( key ) ? key . join ( '.' ) : key
}
function get ( obj , path ) {
let list = [ ] ;
let arr = false ;
const deepGet = ( obj , path , index ) => {
if ( ! isDefined ( obj ) ) {
return
}
if ( ! path [ index ] ) {
// If there's no path left, we've arrived at the object we care about.
list . push ( obj ) ;
} else {
let key = path [ index ] ;
const value = obj [ key ] ;
if ( ! isDefined ( value ) ) {
return
}
// If we're at the last value in the path, and if it's a string/number/bool,
// add it to the list
if (
index === path . length - 1 &&
( isString ( value ) || isNumber ( value ) || isBoolean ( value ) )
) {
list . push ( toString ( value ) ) ;
} else if ( isArray ( value ) ) {
arr = true ;
// Search each item in the array.
for ( let i = 0 , len = value . length ; i < len ; i += 1 ) {
deepGet ( value [ i ] , path , index + 1 ) ;
}
} else if ( path . length ) {
// An object. Recurse further.
deepGet ( value , path , index + 1 ) ;
}
}
} ;
// Backwards compatibility (since path used to be a string)
deepGet ( obj , isString ( path ) ? path . split ( '.' ) : path , 0 ) ;
return arr ? list : list [ 0 ]
}
const MatchOptions = {
// Whether the matches should be included in the result set. When `true`, each record in the result
// set will include the indices of the matched characters.
// These can consequently be used for highlighting purposes.
includeMatches : false ,
// When `true`, the matching function will continue to the end of a search pattern even if
// a perfect match has already been located in the string.
findAllMatches : false ,
// Minimum number of characters that must be matched before a result is considered a match
minMatchCharLength : 1
} ;
const BasicOptions = {
// When `true`, the algorithm continues searching to the end of the input even if a perfect
// match is found before the end of the same input.
isCaseSensitive : false ,
// When true, the matching function will continue to the end of a search pattern even if
includeScore : false ,
// List of properties that will be searched. This also supports nested properties.
keys : [ ] ,
// Whether to sort the result list, by score
shouldSort : true ,
// Default sort function: sort by ascending score, ascending index
sortFn : ( a , b ) =>
a . score === b . score ? ( a . idx < b . idx ? - 1 : 1 ) : a . score < b . score ? - 1 : 1
} ;
const FuzzyOptions = {
// Approximately where in the text is the pattern expected to be found?
location : 0 ,
// At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
// (of both letters and location), a threshold of '1.0' would match anything.
threshold : 0.6 ,
// Determines how close the match must be to the fuzzy location (specified above).
// An exact letter match which is 'distance' characters away from the fuzzy location
// would score as a complete mismatch. A distance of '0' requires the match be at
// the exact location specified, a threshold of '1000' would require a perfect match
// to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
distance : 100
} ;
const AdvancedOptions = {
// When `true`, it enables the use of unix-like search commands
useExtendedSearch : false ,
// The get function to use when fetching an object's properties.
// The default will search nested paths *ie foo.bar.baz*
getFn : get ,
// When `true`, search will ignore `location` and `distance`, so it won't matter
// where in the string the pattern appears.
// More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
ignoreLocation : false ,
// When `true`, the calculation for the relevance score (used for sorting) will
// ignore the field-length norm.
// More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
ignoreFieldNorm : false ,
// The weight to determine how much field length norm effects scoring.
fieldNormWeight : 1
} ;
var Config = {
... BasicOptions ,
... MatchOptions ,
... FuzzyOptions ,
... AdvancedOptions
} ;
const SPACE = /[^ ]+/g ;
// Field-length norm: the shorter the field, the higher the weight.
// Set to 3 decimals to reduce index size.
function norm ( weight = 1 , mantissa = 3 ) {
const cache = new Map ( ) ;
const m = Math . pow ( 10 , mantissa ) ;
return {
get ( value ) {
const numTokens = value . match ( SPACE ) . length ;
if ( cache . has ( numTokens ) ) {
return cache . get ( numTokens )
}
// Default function is 1/sqrt(x), weight makes that variable
const norm = 1 / Math . pow ( numTokens , 0.5 * weight ) ;
// In place of `toFixed(mantissa)`, for faster computation
const n = parseFloat ( Math . round ( norm * m ) / m ) ;
cache . set ( numTokens , n ) ;
return n
} ,
clear ( ) {
cache . clear ( ) ;
}
}
}
class FuseIndex {
constructor ( {
getFn = Config . getFn ,
fieldNormWeight = Config . fieldNormWeight
} = { } ) {
this . norm = norm ( fieldNormWeight , 3 ) ;
this . getFn = getFn ;
this . isCreated = false ;
this . setIndexRecords ( ) ;
}
setSources ( docs = [ ] ) {
this . docs = docs ;
}
setIndexRecords ( records = [ ] ) {
this . records = records ;
}
setKeys ( keys = [ ] ) {
this . keys = keys ;
this . _keysMap = { } ;
keys . forEach ( ( key , idx ) => {
this . _keysMap [ key . id ] = idx ;
} ) ;
}
create ( ) {
if ( this . isCreated || ! this . docs . length ) {
return
}
this . isCreated = true ;
// List is Array<String>
if ( isString ( this . docs [ 0 ] ) ) {
this . docs . forEach ( ( doc , docIndex ) => {
this . _addString ( doc , docIndex ) ;
} ) ;
} else {
// List is Array<Object>
this . docs . forEach ( ( doc , docIndex ) => {
this . _addObject ( doc , docIndex ) ;
} ) ;
}
this . norm . clear ( ) ;
}
// Adds a doc to the end of the index
add ( doc ) {
const idx = this . size ( ) ;
if ( isString ( doc ) ) {
this . _addString ( doc , idx ) ;
} else {
this . _addObject ( doc , idx ) ;
}
}
// Removes the doc at the specified index of the index
removeAt ( idx ) {
this . records . splice ( idx , 1 ) ;
// Change ref index of every subsquent doc
for ( let i = idx , len = this . size ( ) ; i < len ; i += 1 ) {
this . records [ i ] . i -= 1 ;
}
}
getValueForItemAtKeyId ( item , keyId ) {
return item [ this . _keysMap [ keyId ] ]
}
size ( ) {
return this . records . length
}
_addString ( doc , docIndex ) {
if ( ! isDefined ( doc ) || isBlank ( doc ) ) {
return
}
let record = {
v : doc ,
i : docIndex ,
n : this . norm . get ( doc )
} ;
this . records . push ( record ) ;
}
_addObject ( doc , docIndex ) {
let record = { i : docIndex , $ : { } } ;
// Iterate over every key (i.e, path), and fetch the value at that key
this . keys . forEach ( ( key , keyIndex ) => {
// console.log(key)
let value = this . getFn ( doc , key . path ) ;
if ( ! isDefined ( value ) ) {
return
}
if ( isArray ( value ) ) {
let subRecords = [ ] ;
const stack = [ { nestedArrIndex : - 1 , value } ] ;
while ( stack . length ) {
const { nestedArrIndex , value } = stack . pop ( ) ;
if ( ! isDefined ( value ) ) {
continue
}
if ( isString ( value ) && ! isBlank ( value ) ) {
let subRecord = {
v : value ,
i : nestedArrIndex ,
n : this . norm . get ( value )
} ;
subRecords . push ( subRecord ) ;
} else if ( isArray ( value ) ) {
value . forEach ( ( item , k ) => {
stack . push ( {
nestedArrIndex : k ,
value : item
} ) ;
} ) ;
} else ;
}
record . $ [ keyIndex ] = subRecords ;
} else if ( ! isBlank ( value ) ) {
let subRecord = {
v : value ,
n : this . norm . get ( value )
} ;
record . $ [ keyIndex ] = subRecord ;
}
} ) ;
this . records . push ( record ) ;
}
toJSON ( ) {
return {
keys : this . keys ,
records : this . records
}
}
}
function createIndex (
keys ,
docs ,
{ getFn = Config . getFn , fieldNormWeight = Config . fieldNormWeight } = { }
) {
const myIndex = new FuseIndex ( { getFn , fieldNormWeight } ) ;
myIndex . setKeys ( keys . map ( createKey ) ) ;
myIndex . setSources ( docs ) ;
myIndex . create ( ) ;
return myIndex
}
function parseIndex (
data ,
{ getFn = Config . getFn , fieldNormWeight = Config . fieldNormWeight } = { }
) {
const { keys , records } = data ;
const myIndex = new FuseIndex ( { getFn , fieldNormWeight } ) ;
myIndex . setKeys ( keys ) ;
myIndex . setIndexRecords ( records ) ;
return myIndex
}
function computeScore$1 (
pattern ,
{
errors = 0 ,
currentLocation = 0 ,
expectedLocation = 0 ,
distance = Config . distance ,
ignoreLocation = Config . ignoreLocation
} = { }
) {
const accuracy = errors / pattern . length ;
if ( ignoreLocation ) {
return accuracy
}
const proximity = Math . abs ( expectedLocation - currentLocation ) ;
if ( ! distance ) {
// Dodge divide by zero error.
return proximity ? 1.0 : accuracy
}
return accuracy + proximity / distance
}
function convertMaskToIndices (
matchmask = [ ] ,
minMatchCharLength = Config . minMatchCharLength
) {
let indices = [ ] ;
let start = - 1 ;
let end = - 1 ;
let i = 0 ;
for ( let len = matchmask . length ; i < len ; i += 1 ) {
let match = matchmask [ i ] ;
if ( match && start === - 1 ) {
start = i ;
} else if ( ! match && start !== - 1 ) {
end = i - 1 ;
if ( end - start + 1 >= minMatchCharLength ) {
indices . push ( [ start , end ] ) ;
}
start = - 1 ;
}
}
// (i-1 - start) + 1 => i - start
if ( matchmask [ i - 1 ] && i - start >= minMatchCharLength ) {
indices . push ( [ start , i - 1 ] ) ;
}
return indices
}
// Machine word size
const MAX _BITS = 32 ;
function search (
text ,
pattern ,
patternAlphabet ,
{
location = Config . location ,
distance = Config . distance ,
threshold = Config . threshold ,
findAllMatches = Config . findAllMatches ,
minMatchCharLength = Config . minMatchCharLength ,
includeMatches = Config . includeMatches ,
ignoreLocation = Config . ignoreLocation
} = { }
) {
if ( pattern . length > MAX _BITS ) {
throw new Error ( PATTERN _LENGTH _TOO _LARGE ( MAX _BITS ) )
}
const patternLen = pattern . length ;
// Set starting location at beginning text and initialize the alphabet.
const textLen = text . length ;
// Handle the case when location > text.length
const expectedLocation = Math . max ( 0 , Math . min ( location , textLen ) ) ;
// Highest score beyond which we give up.
let currentThreshold = threshold ;
// Is there a nearby exact match? (speedup)
let bestLocation = expectedLocation ;
// Performance: only computer matches when the minMatchCharLength > 1
// OR if `includeMatches` is true.
const computeMatches = minMatchCharLength > 1 || includeMatches ;
// A mask of the matches, used for building the indices
const matchMask = computeMatches ? Array ( textLen ) : [ ] ;
let index ;
// Get all exact matches, here for speed up
while ( ( index = text . indexOf ( pattern , bestLocation ) ) > - 1 ) {
let score = computeScore$1 ( pattern , {
currentLocation : index ,
expectedLocation ,
distance ,
ignoreLocation
} ) ;
currentThreshold = Math . min ( score , currentThreshold ) ;
bestLocation = index + patternLen ;
if ( computeMatches ) {
let i = 0 ;
while ( i < patternLen ) {
matchMask [ index + i ] = 1 ;
i += 1 ;
}
}
}
// Reset the best location
bestLocation = - 1 ;
let lastBitArr = [ ] ;
let finalScore = 1 ;
let binMax = patternLen + textLen ;
const mask = 1 << ( patternLen - 1 ) ;
for ( let i = 0 ; i < patternLen ; i += 1 ) {
// Scan for the best match; each iteration allows for one more error.
// Run a binary search to determine how far from the match location we can stray
// at this error level.
let binMin = 0 ;
let binMid = binMax ;
while ( binMin < binMid ) {
const score = computeScore$1 ( pattern , {
errors : i ,
currentLocation : expectedLocation + binMid ,
expectedLocation ,
distance ,
ignoreLocation
} ) ;
if ( score <= currentThreshold ) {
binMin = binMid ;
} else {
binMax = binMid ;
}
binMid = Math . floor ( ( binMax - binMin ) / 2 + binMin ) ;
}
// Use the result from this iteration as the maximum for the next.
binMax = binMid ;
let start = Math . max ( 1 , expectedLocation - binMid + 1 ) ;
let finish = findAllMatches
? textLen
: Math . min ( expectedLocation + binMid , textLen ) + patternLen ;
// Initialize the bit array
let bitArr = Array ( finish + 2 ) ;
bitArr [ finish + 1 ] = ( 1 << i ) - 1 ;
for ( let j = finish ; j >= start ; j -= 1 ) {
let currentLocation = j - 1 ;
let charMatch = patternAlphabet [ text . charAt ( currentLocation ) ] ;
if ( computeMatches ) {
// Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`)
matchMask [ currentLocation ] = + ! ! charMatch ;
}
// First pass: exact match
bitArr [ j ] = ( ( bitArr [ j + 1 ] << 1 ) | 1 ) & charMatch ;
// Subsequent passes: fuzzy match
if ( i ) {
bitArr [ j ] |=
( ( lastBitArr [ j + 1 ] | lastBitArr [ j ] ) << 1 ) | 1 | lastBitArr [ j + 1 ] ;
}
if ( bitArr [ j ] & mask ) {
finalScore = computeScore$1 ( pattern , {
errors : i ,
currentLocation ,
expectedLocation ,
distance ,
ignoreLocation
} ) ;
// This match will almost certainly be better than any existing match.
// But check anyway.
if ( finalScore <= currentThreshold ) {
// Indeed it is
currentThreshold = finalScore ;
bestLocation = currentLocation ;
// Already passed `loc`, downhill from here on in.
if ( bestLocation <= expectedLocation ) {
break
}
// When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
start = Math . max ( 1 , 2 * expectedLocation - bestLocation ) ;
}
}
}
// No hope for a (better) match at greater error levels.
const score = computeScore$1 ( pattern , {
errors : i + 1 ,
currentLocation : expectedLocation ,
expectedLocation ,
distance ,
ignoreLocation
} ) ;
if ( score > currentThreshold ) {
break
}
lastBitArr = bitArr ;
}
const result = {
isMatch : bestLocation >= 0 ,
// Count exact matches (those with a score of 0) to be "almost" exact
score : Math . max ( 0.001 , finalScore )
} ;
if ( computeMatches ) {
const indices = convertMaskToIndices ( matchMask , minMatchCharLength ) ;
if ( ! indices . length ) {
result . isMatch = false ;
} else if ( includeMatches ) {
result . indices = indices ;
}
}
return result
}
function createPatternAlphabet ( pattern ) {
let mask = { } ;
for ( let i = 0 , len = pattern . length ; i < len ; i += 1 ) {
const char = pattern . charAt ( i ) ;
mask [ char ] = ( mask [ char ] || 0 ) | ( 1 << ( len - i - 1 ) ) ;
}
return mask
}
class BitapSearch {
constructor (
pattern ,
{
location = Config . location ,
threshold = Config . threshold ,
distance = Config . distance ,
includeMatches = Config . includeMatches ,
findAllMatches = Config . findAllMatches ,
minMatchCharLength = Config . minMatchCharLength ,
isCaseSensitive = Config . isCaseSensitive ,
ignoreLocation = Config . ignoreLocation
} = { }
) {
this . options = {
location ,
threshold ,
distance ,
includeMatches ,
findAllMatches ,
minMatchCharLength ,
isCaseSensitive ,
ignoreLocation
} ;
this . pattern = isCaseSensitive ? pattern : pattern . toLowerCase ( ) ;
this . chunks = [ ] ;
if ( ! this . pattern . length ) {
return
}
const addChunk = ( pattern , startIndex ) => {
this . chunks . push ( {
pattern ,
alphabet : createPatternAlphabet ( pattern ) ,
startIndex
} ) ;
} ;
const len = this . pattern . length ;
if ( len > MAX _BITS ) {
let i = 0 ;
const remainder = len % MAX _BITS ;
const end = len - remainder ;
while ( i < end ) {
addChunk ( this . pattern . substr ( i , MAX _BITS ) , i ) ;
i += MAX _BITS ;
}
if ( remainder ) {
const startIndex = len - MAX _BITS ;
addChunk ( this . pattern . substr ( startIndex ) , startIndex ) ;
}
} else {
addChunk ( this . pattern , 0 ) ;
}
}
searchIn ( text ) {
const { isCaseSensitive , includeMatches } = this . options ;
if ( ! isCaseSensitive ) {
text = text . toLowerCase ( ) ;
}
// Exact match
if ( this . pattern === text ) {
let result = {
isMatch : true ,
score : 0
} ;
if ( includeMatches ) {
result . indices = [ [ 0 , text . length - 1 ] ] ;
}
return result
}
// Otherwise, use Bitap algorithm
const {
location ,
distance ,
threshold ,
findAllMatches ,
minMatchCharLength ,
ignoreLocation
} = this . options ;
let allIndices = [ ] ;
let totalScore = 0 ;
let hasMatches = false ;
this . chunks . forEach ( ( { pattern , alphabet , startIndex } ) => {
const { isMatch , score , indices } = search ( text , pattern , alphabet , {
location : location + startIndex ,
distance ,
threshold ,
findAllMatches ,
minMatchCharLength ,
includeMatches ,
ignoreLocation
} ) ;
if ( isMatch ) {
hasMatches = true ;
}
totalScore += score ;
if ( isMatch && indices ) {
allIndices = [ ... allIndices , ... indices ] ;
}
} ) ;
let result = {
isMatch : hasMatches ,
score : hasMatches ? totalScore / this . chunks . length : 1
} ;
if ( hasMatches && includeMatches ) {
result . indices = allIndices ;
}
return result
}
}
class BaseMatch {
constructor ( pattern ) {
this . pattern = pattern ;
}
static isMultiMatch ( pattern ) {
return getMatch ( pattern , this . multiRegex )
}
static isSingleMatch ( pattern ) {
return getMatch ( pattern , this . singleRegex )
}
search ( /*text*/ ) { }
}
function getMatch ( pattern , exp ) {
const matches = pattern . match ( exp ) ;
return matches ? matches [ 1 ] : null
}
// Token: 'file
class ExactMatch extends BaseMatch {
constructor ( pattern ) {
super ( pattern ) ;
}
static get type ( ) {
return 'exact'
}
static get multiRegex ( ) {
return /^="(.*)"$/
}
static get singleRegex ( ) {
return /^=(.*)$/
}
search ( text ) {
const isMatch = text === this . pattern ;
return {
isMatch ,
score : isMatch ? 0 : 1 ,
indices : [ 0 , this . pattern . length - 1 ]
}
}
}
// Token: !fire
class InverseExactMatch extends BaseMatch {
constructor ( pattern ) {
super ( pattern ) ;
}
static get type ( ) {
return 'inverse-exact'
}
static get multiRegex ( ) {
return /^!"(.*)"$/
}
static get singleRegex ( ) {
return /^!(.*)$/
}
search ( text ) {
const index = text . indexOf ( this . pattern ) ;
const isMatch = index === - 1 ;
return {
isMatch ,
score : isMatch ? 0 : 1 ,
indices : [ 0 , text . length - 1 ]
}
}
}
// Token: ^file
class PrefixExactMatch extends BaseMatch {
constructor ( pattern ) {
super ( pattern ) ;
}
static get type ( ) {
return 'prefix-exact'
}
static get multiRegex ( ) {
return /^\^"(.*)"$/
}
static get singleRegex ( ) {
return /^\^(.*)$/
}
search ( text ) {
const isMatch = text . startsWith ( this . pattern ) ;
return {
isMatch ,
score : isMatch ? 0 : 1 ,
indices : [ 0 , this . pattern . length - 1 ]
}
}
}
// Token: !^fire
class InversePrefixExactMatch extends BaseMatch {
constructor ( pattern ) {
super ( pattern ) ;
}
static get type ( ) {
return 'inverse-prefix-exact'
}
static get multiRegex ( ) {
return /^!\^"(.*)"$/
}
static get singleRegex ( ) {
return /^!\^(.*)$/
}
search ( text ) {
const isMatch = ! text . startsWith ( this . pattern ) ;
return {
isMatch ,
score : isMatch ? 0 : 1 ,
indices : [ 0 , text . length - 1 ]
}
}
}
// Token: .file$
class SuffixExactMatch extends BaseMatch {
constructor ( pattern ) {
super ( pattern ) ;
}
static get type ( ) {
return 'suffix-exact'
}
static get multiRegex ( ) {
return /^"(.*)"\$$/
}
static get singleRegex ( ) {
return /^(.*)\$$/
}
search ( text ) {
const isMatch = text . endsWith ( this . pattern ) ;
return {
isMatch ,
score : isMatch ? 0 : 1 ,
indices : [ text . length - this . pattern . length , text . length - 1 ]
}
}
}
// Token: !.file$
class InverseSuffixExactMatch extends BaseMatch {
constructor ( pattern ) {
super ( pattern ) ;
}
static get type ( ) {
return 'inverse-suffix-exact'
}
static get multiRegex ( ) {
return /^!"(.*)"\$$/
}
static get singleRegex ( ) {
return /^!(.*)\$$/
}
search ( text ) {
const isMatch = ! text . endsWith ( this . pattern ) ;
return {
isMatch ,
score : isMatch ? 0 : 1 ,
indices : [ 0 , text . length - 1 ]
}
}
}
class FuzzyMatch extends BaseMatch {
constructor (
pattern ,
{
location = Config . location ,
threshold = Config . threshold ,
distance = Config . distance ,
includeMatches = Config . includeMatches ,
findAllMatches = Config . findAllMatches ,
minMatchCharLength = Config . minMatchCharLength ,
isCaseSensitive = Config . isCaseSensitive ,
ignoreLocation = Config . ignoreLocation
} = { }
) {
super ( pattern ) ;
this . _bitapSearch = new BitapSearch ( pattern , {
location ,
threshold ,
distance ,
includeMatches ,
findAllMatches ,
minMatchCharLength ,
isCaseSensitive ,
ignoreLocation
} ) ;
}
static get type ( ) {
return 'fuzzy'
}
static get multiRegex ( ) {
return /^"(.*)"$/
}
static get singleRegex ( ) {
return /^(.*)$/
}
search ( text ) {
return this . _bitapSearch . searchIn ( text )
}
}
// Token: 'file
class IncludeMatch extends BaseMatch {
constructor ( pattern ) {
super ( pattern ) ;
}
static get type ( ) {
return 'include'
}
static get multiRegex ( ) {
return /^'"(.*)"$/
}
static get singleRegex ( ) {
return /^'(.*)$/
}
search ( text ) {
let location = 0 ;
let index ;
const indices = [ ] ;
const patternLen = this . pattern . length ;
// Get all exact matches
while ( ( index = text . indexOf ( this . pattern , location ) ) > - 1 ) {
location = index + patternLen ;
indices . push ( [ index , location - 1 ] ) ;
}
const isMatch = ! ! indices . length ;
return {
isMatch ,
score : isMatch ? 0 : 1 ,
indices
}
}
}
// ❗Order is important. DO NOT CHANGE.
const searchers = [
ExactMatch ,
IncludeMatch ,
PrefixExactMatch ,
InversePrefixExactMatch ,
InverseSuffixExactMatch ,
SuffixExactMatch ,
InverseExactMatch ,
FuzzyMatch
] ;
const searchersLen = searchers . length ;
// Regex to split by spaces, but keep anything in quotes together
const SPACE _RE = / +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/ ;
const OR _TOKEN = '|' ;
// Return a 2D array representation of the query, for simpler parsing.
// Example:
// "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]]
function parseQuery ( pattern , options = { } ) {
return pattern . split ( OR _TOKEN ) . map ( ( item ) => {
let query = item
. trim ( )
. split ( SPACE _RE )
. filter ( ( item ) => item && ! ! item . trim ( ) ) ;
let results = [ ] ;
for ( let i = 0 , len = query . length ; i < len ; i += 1 ) {
const queryItem = query [ i ] ;
// 1. Handle multiple query match (i.e, once that are quoted, like `"hello world"`)
let found = false ;
let idx = - 1 ;
while ( ! found && ++ idx < searchersLen ) {
const searcher = searchers [ idx ] ;
let token = searcher . isMultiMatch ( queryItem ) ;
if ( token ) {
results . push ( new searcher ( token , options ) ) ;
found = true ;
}
}
if ( found ) {
continue
}
// 2. Handle single query matches (i.e, once that are *not* quoted)
idx = - 1 ;
while ( ++ idx < searchersLen ) {
const searcher = searchers [ idx ] ;
let token = searcher . isSingleMatch ( queryItem ) ;
if ( token ) {
results . push ( new searcher ( token , options ) ) ;
break
}
}
}
return results
} )
}
// These extended matchers can return an array of matches, as opposed
// to a singl match
const MultiMatchSet = new Set ( [ FuzzyMatch . type , IncludeMatch . type ] ) ;
/ * *
* Command - like searching
* === === === === === === === =
*
* Given multiple search terms delimited by spaces . e . g . ` ^jscript .python $ ruby !java ` ,
* search in a given text .
*
* Search syntax :
*
* | Token | Match type | Description |
* | -- -- -- -- -- - | -- -- -- -- -- -- -- -- -- -- -- -- -- | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
* | ` jscript ` | fuzzy - match | Items that fuzzy match ` jscript ` |
* | ` =scheme ` | exact - match | Items that are ` scheme ` |
* | ` 'python ` | include - match | Items that include ` python ` |
* | ` !ruby ` | inverse - exact - match | Items that do not include ` ruby ` |
* | ` ^java ` | prefix - exact - match | Items that start with ` java ` |
* | ` !^earlang ` | inverse - prefix - exact - match | Items that do not start with ` earlang ` |
* | ` .js $ ` | suffix - exact - match | Items that end with ` .js ` |
* | ` !.go $ ` | inverse - suffix - exact - match | Items that do not end with ` .go ` |
*
* A single pipe character acts as an OR operator . For example , the following
* query matches entries that start with ` core ` and end with either ` go ` , ` rb ` ,
* or ` py ` .
*
* ` ` `
* ^ core go$ | rb$ | py$
* ` ` `
* /
class ExtendedSearch {
constructor (
pattern ,
{
isCaseSensitive = Config . isCaseSensitive ,
includeMatches = Config . includeMatches ,
minMatchCharLength = Config . minMatchCharLength ,
ignoreLocation = Config . ignoreLocation ,
findAllMatches = Config . findAllMatches ,
location = Config . location ,
threshold = Config . threshold ,
distance = Config . distance
} = { }
) {
this . query = null ;
this . options = {
isCaseSensitive ,
includeMatches ,
minMatchCharLength ,
findAllMatches ,
ignoreLocation ,
location ,
threshold ,
distance
} ;
this . pattern = isCaseSensitive ? pattern : pattern . toLowerCase ( ) ;
this . query = parseQuery ( this . pattern , this . options ) ;
}
static condition ( _ , options ) {
return options . useExtendedSearch
}
searchIn ( text ) {
const query = this . query ;
if ( ! query ) {
return {
isMatch : false ,
score : 1
}
}
const { includeMatches , isCaseSensitive } = this . options ;
text = isCaseSensitive ? text : text . toLowerCase ( ) ;
let numMatches = 0 ;
let allIndices = [ ] ;
let totalScore = 0 ;
// ORs
for ( let i = 0 , qLen = query . length ; i < qLen ; i += 1 ) {
const searchers = query [ i ] ;
// Reset indices
allIndices . length = 0 ;
numMatches = 0 ;
// ANDs
for ( let j = 0 , pLen = searchers . length ; j < pLen ; j += 1 ) {
const searcher = searchers [ j ] ;
const { isMatch , indices , score } = searcher . search ( text ) ;
if ( isMatch ) {
numMatches += 1 ;
totalScore += score ;
if ( includeMatches ) {
const type = searcher . constructor . type ;
if ( MultiMatchSet . has ( type ) ) {
allIndices = [ ... allIndices , ... indices ] ;
} else {
allIndices . push ( indices ) ;
}
}
} else {
totalScore = 0 ;
numMatches = 0 ;
allIndices . length = 0 ;
break
}
}
// OR condition, so if TRUE, return
if ( numMatches ) {
let result = {
isMatch : true ,
score : totalScore / numMatches
} ;
if ( includeMatches ) {
result . indices = allIndices ;
}
return result
}
}
// Nothing was matched
return {
isMatch : false ,
score : 1
}
}
}
const registeredSearchers = [ ] ;
function register ( ... args ) {
registeredSearchers . push ( ... args ) ;
}
function createSearcher ( pattern , options ) {
for ( let i = 0 , len = registeredSearchers . length ; i < len ; i += 1 ) {
let searcherClass = registeredSearchers [ i ] ;
if ( searcherClass . condition ( pattern , options ) ) {
return new searcherClass ( pattern , options )
}
}
return new BitapSearch ( pattern , options )
}
const LogicalOperator = {
AND : '$and' ,
OR : '$or'
} ;
const KeyType = {
PATH : '$path' ,
PATTERN : '$val'
} ;
const isExpression = ( query ) =>
! ! ( query [ LogicalOperator . AND ] || query [ LogicalOperator . OR ] ) ;
const isPath = ( query ) => ! ! query [ KeyType . PATH ] ;
const isLeaf = ( query ) =>
! isArray ( query ) && isObject ( query ) && ! isExpression ( query ) ;
const convertToExplicit = ( query ) => ( {
[ LogicalOperator . AND ] : Object . keys ( query ) . map ( ( key ) => ( {
[ key ] : query [ key ]
} ) )
} ) ;
// When `auto` is `true`, the parse function will infer and initialize and add
// the appropriate `Searcher` instance
function parse ( query , options , { auto = true } = { } ) {
const next = ( query ) => {
let keys = Object . keys ( query ) ;
const isQueryPath = isPath ( query ) ;
if ( ! isQueryPath && keys . length > 1 && ! isExpression ( query ) ) {
return next ( convertToExplicit ( query ) )
}
if ( isLeaf ( query ) ) {
const key = isQueryPath ? query [ KeyType . PATH ] : keys [ 0 ] ;
const pattern = isQueryPath ? query [ KeyType . PATTERN ] : query [ key ] ;
if ( ! isString ( pattern ) ) {
throw new Error ( LOGICAL _SEARCH _INVALID _QUERY _FOR _KEY ( key ) )
}
const obj = {
keyId : createKeyId ( key ) ,
pattern
} ;
if ( auto ) {
obj . searcher = createSearcher ( pattern , options ) ;
}
return obj
}
let node = {
children : [ ] ,
operator : keys [ 0 ]
} ;
keys . forEach ( ( key ) => {
const value = query [ key ] ;
if ( isArray ( value ) ) {
value . forEach ( ( item ) => {
node . children . push ( next ( item ) ) ;
} ) ;
}
} ) ;
return node
} ;
if ( ! isExpression ( query ) ) {
query = convertToExplicit ( query ) ;
}
return next ( query )
}
// Practical scoring function
function computeScore (
results ,
{ ignoreFieldNorm = Config . ignoreFieldNorm }
) {
results . forEach ( ( result ) => {
let totalScore = 1 ;
result . matches . forEach ( ( { key , norm , score } ) => {
const weight = key ? key . weight : null ;
totalScore *= Math . pow (
score === 0 && weight ? Number . EPSILON : score ,
( weight || 1 ) * ( ignoreFieldNorm ? 1 : norm )
) ;
} ) ;
result . score = totalScore ;
} ) ;
}
function transformMatches ( result , data ) {
const matches = result . matches ;
data . matches = [ ] ;
if ( ! isDefined ( matches ) ) {
return
}
matches . forEach ( ( match ) => {
if ( ! isDefined ( match . indices ) || ! match . indices . length ) {
return
}
const { indices , value } = match ;
let obj = {
indices ,
value
} ;
if ( match . key ) {
obj . key = match . key . src ;
}
if ( match . idx > - 1 ) {
obj . refIndex = match . idx ;
}
data . matches . push ( obj ) ;
} ) ;
}
function transformScore ( result , data ) {
data . score = result . score ;
}
function format (
results ,
docs ,
{
includeMatches = Config . includeMatches ,
includeScore = Config . includeScore
} = { }
) {
const transformers = [ ] ;
if ( includeMatches ) transformers . push ( transformMatches ) ;
if ( includeScore ) transformers . push ( transformScore ) ;
return results . map ( ( result ) => {
const { idx } = result ;
const data = {
item : docs [ idx ] ,
refIndex : idx
} ;
if ( transformers . length ) {
transformers . forEach ( ( transformer ) => {
transformer ( result , data ) ;
} ) ;
}
return data
} )
}
class Fuse {
constructor ( docs , options = { } , index ) {
this . options = { ... Config , ... options } ;
if (
this . options . useExtendedSearch &&
! true
) { }
this . _keyStore = new KeyStore ( this . options . keys ) ;
this . setCollection ( docs , index ) ;
}
setCollection ( docs , index ) {
this . _docs = docs ;
if ( index && ! ( index instanceof FuseIndex ) ) {
throw new Error ( INCORRECT _INDEX _TYPE )
}
this . _myIndex =
index ||
createIndex ( this . options . keys , this . _docs , {
getFn : this . options . getFn ,
fieldNormWeight : this . options . fieldNormWeight
} ) ;
}
add ( doc ) {
if ( ! isDefined ( doc ) ) {
return
}
this . _docs . push ( doc ) ;
this . _myIndex . add ( doc ) ;
}
remove ( predicate = ( /* doc, idx */ ) => false ) {
const results = [ ] ;
for ( let i = 0 , len = this . _docs . length ; i < len ; i += 1 ) {
const doc = this . _docs [ i ] ;
if ( predicate ( doc , i ) ) {
this . removeAt ( i ) ;
i -= 1 ;
len -= 1 ;
results . push ( doc ) ;
}
}
return results
}
removeAt ( idx ) {
this . _docs . splice ( idx , 1 ) ;
this . _myIndex . removeAt ( idx ) ;
}
getIndex ( ) {
return this . _myIndex
}
search ( query , { limit = - 1 } = { } ) {
const {
includeMatches ,
includeScore ,
shouldSort ,
sortFn ,
ignoreFieldNorm
} = this . options ;
let results = isString ( query )
? isString ( this . _docs [ 0 ] )
? this . _searchStringList ( query )
: this . _searchObjectList ( query )
: this . _searchLogical ( query ) ;
computeScore ( results , { ignoreFieldNorm } ) ;
if ( shouldSort ) {
results . sort ( sortFn ) ;
}
if ( isNumber ( limit ) && limit > - 1 ) {
results = results . slice ( 0 , limit ) ;
}
return format ( results , this . _docs , {
includeMatches ,
includeScore
} )
}
_searchStringList ( query ) {
const searcher = createSearcher ( query , this . options ) ;
const { records } = this . _myIndex ;
const results = [ ] ;
// Iterate over every string in the index
records . forEach ( ( { v : text , i : idx , n : norm } ) => {
if ( ! isDefined ( text ) ) {
return
}
const { isMatch , score , indices } = searcher . searchIn ( text ) ;
if ( isMatch ) {
results . push ( {
item : text ,
idx ,
matches : [ { score , value : text , norm , indices } ]
} ) ;
}
} ) ;
return results
}
_searchLogical ( query ) {
const expression = parse ( query , this . options ) ;
const evaluate = ( node , item , idx ) => {
if ( ! node . children ) {
const { keyId , searcher } = node ;
const matches = this . _findMatches ( {
key : this . _keyStore . get ( keyId ) ,
value : this . _myIndex . getValueForItemAtKeyId ( item , keyId ) ,
searcher
} ) ;
if ( matches && matches . length ) {
return [
{
idx ,
item ,
matches
}
]
}
return [ ]
}
const res = [ ] ;
for ( let i = 0 , len = node . children . length ; i < len ; i += 1 ) {
const child = node . children [ i ] ;
const result = evaluate ( child , item , idx ) ;
if ( result . length ) {
res . push ( ... result ) ;
} else if ( node . operator === LogicalOperator . AND ) {
return [ ]
}
}
return res
} ;
const records = this . _myIndex . records ;
const resultMap = { } ;
const results = [ ] ;
records . forEach ( ( { $ : item , i : idx } ) => {
if ( isDefined ( item ) ) {
let expResults = evaluate ( expression , item , idx ) ;
if ( expResults . length ) {
// Dedupe when adding
if ( ! resultMap [ idx ] ) {
resultMap [ idx ] = { idx , item , matches : [ ] } ;
results . push ( resultMap [ idx ] ) ;
}
expResults . forEach ( ( { matches } ) => {
resultMap [ idx ] . matches . push ( ... matches ) ;
} ) ;
}
}
} ) ;
return results
}
_searchObjectList ( query ) {
const searcher = createSearcher ( query , this . options ) ;
const { keys , records } = this . _myIndex ;
const results = [ ] ;
// List is Array<Object>
records . forEach ( ( { $ : item , i : idx } ) => {
if ( ! isDefined ( item ) ) {
return
}
let matches = [ ] ;
// Iterate over every key (i.e, path), and fetch the value at that key
keys . forEach ( ( key , keyIndex ) => {
matches . push (
... this . _findMatches ( {
key ,
value : item [ keyIndex ] ,
searcher
} )
) ;
} ) ;
if ( matches . length ) {
results . push ( {
idx ,
item ,
matches
} ) ;
}
} ) ;
return results
}
_findMatches ( { key , value , searcher } ) {
if ( ! isDefined ( value ) ) {
return [ ]
}
let matches = [ ] ;
if ( isArray ( value ) ) {
value . forEach ( ( { v : text , i : idx , n : norm } ) => {
if ( ! isDefined ( text ) ) {
return
}
const { isMatch , score , indices } = searcher . searchIn ( text ) ;
if ( isMatch ) {
matches . push ( {
score ,
key ,
value : text ,
idx ,
norm ,
indices
} ) ;
}
} ) ;
} else {
const { v : text , n : norm } = value ;
const { isMatch , score , indices } = searcher . searchIn ( text ) ;
if ( isMatch ) {
matches . push ( { score , key , value : text , norm , indices } ) ;
}
}
return matches
}
}
Fuse . version = '6.5.3' ;
Fuse . createIndex = createIndex ;
Fuse . parseIndex = parseIndex ;
Fuse . config = Config ;
{
Fuse . parseQuery = parse ;
}
{
register ( ExtendedSearch ) ;
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
/***/ } ) ,
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
/***/ 857 :
/***/ ( function ( _ _unused _webpack _module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
// ESM COMPAT FLAG
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
// EXPORTS
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
"__DO_NOT_USE__ActionTypes" : function ( ) { return /* binding */ ActionTypes ; } ,
"applyMiddleware" : function ( ) { return /* binding */ applyMiddleware ; } ,
"bindActionCreators" : function ( ) { return /* binding */ bindActionCreators ; } ,
"combineReducers" : function ( ) { return /* binding */ combineReducers ; } ,
"compose" : function ( ) { return /* binding */ compose ; } ,
"createStore" : function ( ) { return /* binding */ createStore ; }
} ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
; // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
function _defineProperty ( obj , key , value ) {
if ( key in obj ) {
Object . defineProperty ( obj , key , {
2019-12-23 19:22:54 +01:00
value : value ,
2021-12-19 22:58:00 +01:00
enumerable : true ,
configurable : true ,
writable : true
2019-12-23 19:22:54 +01:00
} ) ;
2021-12-19 22:58:00 +01:00
} else {
obj [ key ] = value ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
return obj ;
}
; // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
function ownKeys ( object , enumerableOnly ) {
var keys = Object . keys ( object ) ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( Object . getOwnPropertySymbols ) {
var symbols = Object . getOwnPropertySymbols ( object ) ;
enumerableOnly && ( symbols = symbols . filter ( function ( sym ) {
return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ;
} ) ) , keys . push . apply ( keys , symbols ) ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
return keys ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
function _objectSpread2 ( target ) {
for ( var i = 1 ; i < arguments . length ; i ++ ) {
var source = null != arguments [ i ] ? arguments [ i ] : { } ;
i % 2 ? ownKeys ( Object ( source ) , ! 0 ) . forEach ( function ( key ) {
_defineProperty ( target , key , source [ key ] ) ;
} ) : Object . getOwnPropertyDescriptors ? Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) : ownKeys ( Object ( source ) ) . forEach ( function ( key ) {
Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ;
} ) ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
return target ;
}
; // CONCATENATED MODULE: ./node_modules/redux/es/redux.js
2017-11-15 07:51:53 +01:00
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
/ * *
* Adapted from React : https : //github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
*
* Do not require this module directly ! Use normal throw error calls . These messages will be replaced with error codes
* during build .
* @ param { number } code
* /
function formatProdErrorMessage ( code ) {
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. ' ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
// Inlined version of the `symbol-observable` polyfill
var $$observable = ( function ( ) {
return typeof Symbol === 'function' && Symbol . observable || '@@observable' ;
} ) ( ) ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
/ * *
* These are private action types reserved by Redux .
* For any unknown actions , you must return the current state .
* If the current state is undefined , you must return the initial state .
* Do not reference these action types directly in your code .
* /
var randomString = function randomString ( ) {
return Math . random ( ) . toString ( 36 ) . substring ( 7 ) . split ( '' ) . join ( '.' ) ;
} ;
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
var ActionTypes = {
INIT : "@@redux/INIT" + randomString ( ) ,
REPLACE : "@@redux/REPLACE" + randomString ( ) ,
PROBE _UNKNOWN _ACTION : function PROBE _UNKNOWN _ACTION ( ) {
return "@@redux/PROBE_UNKNOWN_ACTION" + randomString ( ) ;
}
} ;
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
/ * *
* @ param { any } obj The object to inspect .
* @ returns { boolean } True if the argument appears to be a plain object .
* /
function isPlainObject ( obj ) {
if ( typeof obj !== 'object' || obj === null ) return false ;
var proto = obj ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
while ( Object . getPrototypeOf ( proto ) !== null ) {
proto = Object . getPrototypeOf ( proto ) ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
return Object . getPrototypeOf ( obj ) === proto ;
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
// Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of
function miniKindOf ( val ) {
if ( val === void 0 ) return 'undefined' ;
if ( val === null ) return 'null' ;
var type = typeof val ;
switch ( type ) {
case 'boolean' :
case 'string' :
case 'number' :
case 'symbol' :
case 'function' :
{
return type ;
}
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( Array . isArray ( val ) ) return 'array' ;
if ( isDate ( val ) ) return 'date' ;
if ( isError ( val ) ) return 'error' ;
var constructorName = ctorName ( val ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
switch ( constructorName ) {
case 'Symbol' :
case 'Promise' :
case 'WeakMap' :
case 'WeakSet' :
case 'Map' :
case 'Set' :
return constructorName ;
} // other
2019-10-22 23:20:40 +02:00
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
return type . slice ( 8 , - 1 ) . toLowerCase ( ) . replace ( /\s/g , '' ) ;
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
function ctorName ( val ) {
return typeof val . constructor === 'function' ? val . constructor . name : null ;
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
function isError ( val ) {
return val instanceof Error || typeof val . message === 'string' && val . constructor && typeof val . constructor . stackTraceLimit === 'number' ;
}
function isDate ( val ) {
if ( val instanceof Date ) return true ;
return typeof val . toDateString === 'function' && typeof val . getDate === 'function' && typeof val . setDate === 'function' ;
}
function kindOf ( val ) {
var typeOfVal = typeof val ;
if ( false ) { }
return typeOfVal ;
}
/ * *
* Creates a Redux store that holds the state tree .
* The only way to change the data in the store is to call ` dispatch() ` on it .
*
* There should only be a single store in your app . To specify how different
* parts of the state tree respond to actions , you may combine several reducers
* into a single reducer function by using ` combineReducers ` .
*
* @ param { Function } reducer A function that returns the next state tree , given
* the current state tree and the action to handle .
*
* @ param { any } [ preloadedState ] The initial state . You may optionally specify it
* to hydrate the state from the server in universal apps , or to restore a
* previously serialized user session .
* If you use ` combineReducers ` to produce the root reducer function , this must be
* an object with the same shape as ` combineReducers ` keys .
*
* @ param { Function } [ enhancer ] The store enhancer . You may optionally specify it
* to enhance the store with third - party capabilities such as middleware ,
* time travel , persistence , etc . The only store enhancer that ships with Redux
* is ` applyMiddleware() ` .
*
* @ returns { Store } A Redux store that lets you read the state , dispatch actions
* and subscribe to changes .
* /
function createStore ( reducer , preloadedState , enhancer ) {
var _ref2 ;
if ( typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments [ 3 ] === 'function' ) {
throw new Error ( true ? formatProdErrorMessage ( 0 ) : 0 ) ;
}
if ( typeof preloadedState === 'function' && typeof enhancer === 'undefined' ) {
enhancer = preloadedState ;
preloadedState = undefined ;
}
if ( typeof enhancer !== 'undefined' ) {
if ( typeof enhancer !== 'function' ) {
throw new Error ( true ? formatProdErrorMessage ( 1 ) : 0 ) ;
2019-12-23 19:22:54 +01:00
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
return enhancer ( createStore ) ( reducer , preloadedState ) ;
2019-12-23 19:22:54 +01:00
}
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
if ( typeof reducer !== 'function' ) {
throw new Error ( true ? formatProdErrorMessage ( 2 ) : 0 ) ;
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var currentReducer = reducer ;
var currentState = preloadedState ;
var currentListeners = [ ] ;
var nextListeners = currentListeners ;
var isDispatching = false ;
/ * *
* This makes a shallow copy of currentListeners so we can use
* nextListeners as a temporary list while dispatching .
*
* This prevents any bugs around consumers calling
* subscribe / unsubscribe in the middle of a dispatch .
* /
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
function ensureCanMutateNextListeners ( ) {
if ( nextListeners === currentListeners ) {
nextListeners = currentListeners . slice ( ) ;
}
}
/ * *
* Reads the state tree managed by the store .
*
* @ returns { any } The current state tree of your application .
* /
2019-10-29 22:19:56 +01:00
2017-11-15 07:51:53 +01:00
2021-12-19 22:58:00 +01:00
function getState ( ) {
if ( isDispatching ) {
throw new Error ( true ? formatProdErrorMessage ( 3 ) : 0 ) ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
return currentState ;
}
/ * *
* Adds a change listener . It will be called any time an action is dispatched ,
* and some part of the state tree may potentially have changed . You may then
* call ` getState() ` to read the current state tree inside the callback .
*
* You may call ` dispatch() ` from a change listener , with the following
* caveats :
*
* 1. The subscriptions are snapshotted just before every ` dispatch() ` call .
* If you subscribe or unsubscribe while the listeners are being invoked , this
* will not have any effect on the ` dispatch() ` that is currently in progress .
* However , the next ` dispatch() ` call , whether nested or not , will use a more
* recent snapshot of the subscription list .
*
* 2. The listener should not expect to see all state changes , as the state
* might have been updated multiple times during a nested ` dispatch() ` before
* the listener is called . It is , however , guaranteed that all subscribers
* registered before the ` dispatch() ` started will be called with the latest
* state by the time it exits .
*
* @ param { Function } listener A callback to be invoked on every dispatch .
* @ returns { Function } A function to remove this change listener .
* /
function subscribe ( listener ) {
if ( typeof listener !== 'function' ) {
throw new Error ( true ? formatProdErrorMessage ( 4 ) : 0 ) ;
}
if ( isDispatching ) {
throw new Error ( true ? formatProdErrorMessage ( 5 ) : 0 ) ;
}
var isSubscribed = true ;
ensureCanMutateNextListeners ( ) ;
nextListeners . push ( listener ) ;
return function unsubscribe ( ) {
if ( ! isSubscribed ) {
return ;
}
if ( isDispatching ) {
throw new Error ( true ? formatProdErrorMessage ( 6 ) : 0 ) ;
}
isSubscribed = false ;
ensureCanMutateNextListeners ( ) ;
var index = nextListeners . indexOf ( listener ) ;
nextListeners . splice ( index , 1 ) ;
currentListeners = null ;
} ;
}
/ * *
* Dispatches an action . It is the only way to trigger a state change .
*
* The ` reducer ` function , used to create the store , will be called with the
* current state tree and the given ` action ` . Its return value will
* be considered the * * next * * state of the tree , and the change listeners
* will be notified .
*
* The base implementation only supports plain object actions . If you want to
* dispatch a Promise , an Observable , a thunk , or something else , you need to
* wrap your store creating function into the corresponding middleware . For
* example , see the documentation for the ` redux-thunk ` package . Even the
* middleware will eventually dispatch plain object actions using this method .
*
* @ param { Object } action A plain object representing “ what changed ” . It is
* a good idea to keep actions serializable so you can record and replay user
* sessions , or use the time travelling ` redux-devtools ` . An action must have
* a ` type ` property which may not be ` undefined ` . It is a good idea to use
* string constants for action types .
*
* @ returns { Object } For convenience , the same action object you dispatched .
*
* Note that , if you use a custom middleware , it may wrap ` dispatch() ` to
* return something else ( for example , a Promise you can await ) .
* /
function dispatch ( action ) {
if ( ! isPlainObject ( action ) ) {
throw new Error ( true ? formatProdErrorMessage ( 7 ) : 0 ) ;
}
if ( typeof action . type === 'undefined' ) {
throw new Error ( true ? formatProdErrorMessage ( 8 ) : 0 ) ;
}
if ( isDispatching ) {
throw new Error ( true ? formatProdErrorMessage ( 9 ) : 0 ) ;
}
try {
isDispatching = true ;
currentState = currentReducer ( currentState , action ) ;
} finally {
isDispatching = false ;
}
var listeners = currentListeners = nextListeners ;
for ( var i = 0 ; i < listeners . length ; i ++ ) {
var listener = listeners [ i ] ;
listener ( ) ;
}
return action ;
}
/ * *
* Replaces the reducer currently used by the store to calculate the state .
*
* You might need this if your app implements code splitting and you want to
* load some of the reducers dynamically . You might also need this if you
* implement a hot reloading mechanism for Redux .
*
* @ param { Function } nextReducer The reducer for the store to use instead .
* @ returns { void }
* /
function replaceReducer ( nextReducer ) {
if ( typeof nextReducer !== 'function' ) {
throw new Error ( true ? formatProdErrorMessage ( 10 ) : 0 ) ;
}
currentReducer = nextReducer ; // This action has a similiar effect to ActionTypes.INIT.
// Any reducers that existed in both the new and old rootReducer
// will receive the previous state. This effectively populates
// the new state tree with any relevant data from the old one.
dispatch ( {
type : ActionTypes . REPLACE
} ) ;
}
/ * *
* Interoperability point for observable / reactive libraries .
* @ returns { observable } A minimal observable of state changes .
* For more information , see the observable proposal :
* https : //github.com/tc39/proposal-observable
* /
function observable ( ) {
var _ref ;
var outerSubscribe = subscribe ;
return _ref = {
/ * *
* The minimal observable subscription method .
* @ param { Object } observer Any object that can be used as an observer .
* The observer object should have a ` next ` method .
* @ returns { subscription } An object with an ` unsubscribe ` method that can
* be used to unsubscribe the observable from the store , and prevent further
* emission of values from the observable .
* /
subscribe : function subscribe ( observer ) {
if ( typeof observer !== 'object' || observer === null ) {
throw new Error ( true ? formatProdErrorMessage ( 11 ) : 0 ) ;
}
function observeState ( ) {
if ( observer . next ) {
observer . next ( getState ( ) ) ;
}
}
observeState ( ) ;
var unsubscribe = outerSubscribe ( observeState ) ;
return {
unsubscribe : unsubscribe
} ;
}
} , _ref [ $$observable ] = function ( ) {
return this ;
} , _ref ;
} // When a store is created, an "INIT" action is dispatched so that every
// reducer returns their initial state. This effectively populates
// the initial state tree.
dispatch ( {
type : ActionTypes . INIT
} ) ;
return _ref2 = {
dispatch : dispatch ,
subscribe : subscribe ,
getState : getState ,
replaceReducer : replaceReducer
} , _ref2 [ $$observable ] = observable , _ref2 ;
}
/ * *
* Prints a warning in the console if it exists .
*
* @ param { String } message The warning message .
* @ returns { void }
* /
function warning ( message ) {
/* eslint-disable no-console */
if ( typeof console !== 'undefined' && typeof console . error === 'function' ) {
console . error ( message ) ;
}
/* eslint-enable no-console */
try {
// This error was thrown as a convenience so that if you enable
// "break on all exceptions" in your console,
// it would pause the execution at this line.
throw new Error ( message ) ;
} catch ( e ) { } // eslint-disable-line no-empty
}
function getUnexpectedStateShapeWarningMessage ( inputState , reducers , action , unexpectedKeyCache ) {
var reducerKeys = Object . keys ( reducers ) ;
var argumentName = action && action . type === ActionTypes . INIT ? 'preloadedState argument passed to createStore' : 'previous state received by the reducer' ;
if ( reducerKeys . length === 0 ) {
return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.' ;
}
if ( ! isPlainObject ( inputState ) ) {
return "The " + argumentName + " has unexpected type of \"" + kindOf ( inputState ) + "\". Expected argument to be an object with the following " + ( "keys: \"" + reducerKeys . join ( '", "' ) + "\"" ) ;
}
var unexpectedKeys = Object . keys ( inputState ) . filter ( function ( key ) {
return ! reducers . hasOwnProperty ( key ) && ! unexpectedKeyCache [ key ] ;
} ) ;
unexpectedKeys . forEach ( function ( key ) {
unexpectedKeyCache [ key ] = true ;
} ) ;
if ( action && action . type === ActionTypes . REPLACE ) return ;
if ( unexpectedKeys . length > 0 ) {
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." ) ;
}
}
function assertReducerShape ( reducers ) {
Object . keys ( reducers ) . forEach ( function ( key ) {
var reducer = reducers [ key ] ;
var initialState = reducer ( undefined , {
type : ActionTypes . INIT
} ) ;
if ( typeof initialState === 'undefined' ) {
throw new Error ( true ? formatProdErrorMessage ( 12 ) : 0 ) ;
}
if ( typeof reducer ( undefined , {
type : ActionTypes . PROBE _UNKNOWN _ACTION ( )
} ) === 'undefined' ) {
throw new Error ( true ? formatProdErrorMessage ( 13 ) : 0 ) ;
}
} ) ;
}
/ * *
* Turns an object whose values are different reducer functions , into a single
* reducer function . It will call every child reducer , and gather their results
* into a single state object , whose keys correspond to the keys of the passed
* reducer functions .
*
* @ param { Object } reducers An object whose values correspond to different
* reducer functions that need to be combined into one . One handy way to obtain
* it is to use ES6 ` import * as reducers ` syntax . The reducers may never return
* undefined for any action . Instead , they should return their initial state
* if the state passed to them was undefined , and the current state for any
* unrecognized action .
*
* @ returns { Function } A reducer function that invokes every reducer inside the
* passed object , and builds a state object with the same shape .
* /
function combineReducers ( reducers ) {
var reducerKeys = Object . keys ( reducers ) ;
var finalReducers = { } ;
for ( var i = 0 ; i < reducerKeys . length ; i ++ ) {
var key = reducerKeys [ i ] ;
if ( false ) { }
if ( typeof reducers [ key ] === 'function' ) {
finalReducers [ key ] = reducers [ key ] ;
}
}
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
var finalReducerKeys = Object . keys ( finalReducers ) ; // This is used to make sure we don't warn about the same
// keys multiple times.
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
var unexpectedKeyCache ;
if ( false ) { }
var shapeAssertionError ;
try {
assertReducerShape ( finalReducers ) ;
} catch ( e ) {
shapeAssertionError = e ;
2019-12-23 19:22:54 +01:00
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
return function combination ( state , action ) {
if ( state === void 0 ) {
state = { } ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( shapeAssertionError ) {
throw shapeAssertionError ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( false ) { var warningMessage ; }
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
var hasChanged = false ;
var nextState = { } ;
2019-02-09 19:13:25 +01:00
2021-12-19 22:58:00 +01:00
for ( var _i = 0 ; _i < finalReducerKeys . length ; _i ++ ) {
var _key = finalReducerKeys [ _i ] ;
var reducer = finalReducers [ _key ] ;
var previousStateForKey = state [ _key ] ;
var nextStateForKey = reducer ( previousStateForKey , action ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( typeof nextStateForKey === 'undefined' ) {
var actionType = action && action . type ;
throw new Error ( true ? formatProdErrorMessage ( 14 ) : 0 ) ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
nextState [ _key ] = nextStateForKey ;
hasChanged = hasChanged || nextStateForKey !== previousStateForKey ;
}
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
hasChanged = hasChanged || finalReducerKeys . length !== Object . keys ( state ) . length ;
return hasChanged ? nextState : state ;
2018-05-28 17:22:22 +02:00
} ;
2021-12-19 22:58:00 +01:00
}
2018-05-28 17:22:22 +02:00
2021-12-19 22:58:00 +01:00
function bindActionCreator ( actionCreator , dispatch ) {
return function ( ) {
return dispatch ( actionCreator . apply ( this , arguments ) ) ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
}
/ * *
* Turns an object whose values are action creators , into an object with the
* same keys , but with every function wrapped into a ` dispatch ` call so they
* may be invoked directly . This is just a convenience method , as you can call
* ` store.dispatch(MyActionCreators.doSomething()) ` yourself just fine .
*
* For convenience , you can also pass an action creator as the first argument ,
* and get a dispatch wrapped function in return .
*
* @ param { Function | Object } actionCreators An object whose values are action
* creator functions . One handy way to obtain it is to use ES6 ` import * as `
* syntax . You may also pass a single function .
*
* @ param { Function } dispatch The ` dispatch ` function available on your Redux
* store .
*
* @ returns { Function | Object } The object mimicking the original object , but with
* every action creator wrapped into the ` dispatch ` call . If you passed a
* function as ` actionCreators ` , the return value will also be a single
* function .
* /
2019-02-09 19:13:25 +01:00
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
function bindActionCreators ( actionCreators , dispatch ) {
if ( typeof actionCreators === 'function' ) {
return bindActionCreator ( actionCreators , dispatch ) ;
}
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
if ( typeof actionCreators !== 'object' || actionCreators === null ) {
throw new Error ( true ? formatProdErrorMessage ( 16 ) : 0 ) ;
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var boundActionCreators = { } ;
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
for ( var key in actionCreators ) {
var actionCreator = actionCreators [ key ] ;
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
if ( typeof actionCreator === 'function' ) {
boundActionCreators [ key ] = bindActionCreator ( actionCreator , dispatch ) ;
}
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
return boundActionCreators ;
}
2019-01-26 13:36:47 +01:00
2021-12-19 22:58:00 +01:00
/ * *
* Composes single - argument functions from right to left . The rightmost
* function can take multiple arguments as it provides the signature for
* the resulting composite function .
*
* @ param { ... Function } funcs The functions to compose .
* @ returns { Function } A function obtained by composing the argument functions
* from right to left . For example , compose ( f , g , h ) is identical to doing
* ( ... args ) => f ( g ( h ( ... args ) ) ) .
* /
function compose ( ) {
for ( var _len = arguments . length , funcs = new Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
funcs [ _key ] = arguments [ _key ] ;
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
if ( funcs . length === 0 ) {
return function ( arg ) {
return arg ;
} ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
if ( funcs . length === 1 ) {
return funcs [ 0 ] ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
return funcs . reduce ( function ( a , b ) {
return function ( ) {
return a ( b . apply ( void 0 , arguments ) ) ;
} ;
} ) ;
}
2019-11-03 18:45:16 +01:00
2021-12-19 22:58:00 +01:00
/ * *
* Creates a store enhancer that applies middleware to the dispatch method
* of the Redux store . This is handy for a variety of tasks , such as expressing
* asynchronous actions in a concise manner , or logging every action payload .
*
* See ` redux-thunk ` package as an example of the Redux middleware .
*
* Because middleware is potentially asynchronous , this should be the first
* store enhancer in the composition chain .
*
* Note that each middleware will be given the ` dispatch ` and ` getState ` functions
* as named arguments .
*
* @ param { ... Function } middlewares The middleware chain to be applied .
* @ returns { Function } A store enhancer applying the middleware .
* /
2019-12-23 19:22:54 +01:00
2021-12-19 22:58:00 +01:00
function applyMiddleware ( ) {
for ( var _len = arguments . length , middlewares = new Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
middlewares [ _key ] = arguments [ _key ] ;
}
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
return function ( createStore ) {
return function ( ) {
var store = createStore . apply ( void 0 , arguments ) ;
2019-10-22 23:20:40 +02:00
2021-12-19 22:58:00 +01:00
var _dispatch = function dispatch ( ) {
throw new Error ( true ? formatProdErrorMessage ( 15 ) : 0 ) ;
} ;
var middlewareAPI = {
getState : store . getState ,
dispatch : function dispatch ( ) {
return _dispatch . apply ( void 0 , arguments ) ;
}
} ;
var chain = middlewares . map ( function ( middleware ) {
return middleware ( middlewareAPI ) ;
} ) ;
_dispatch = compose . apply ( void 0 , chain ) ( store . dispatch ) ;
return _objectSpread2 ( _objectSpread2 ( { } , store ) , { } , {
dispatch : _dispatch
} ) ;
} ;
2019-12-23 19:22:54 +01:00
} ;
2021-12-19 22:58:00 +01:00
}
/ *
* This is a dummy function to check if the function name has been altered by minification .
* If the function has been minified and NODE _ENV !== 'production' , warn the user .
* /
function isCrushed ( ) { }
if ( false ) { }
2019-02-09 19:13:25 +01:00
2017-05-18 18:57:35 +02:00
/***/ } )
2021-12-19 22:58:00 +01:00
/******/ } ) ;
/************************************************************************/
/******/ // The module cache
/******/ var _ _webpack _module _cache _ _ = { } ;
/******/
/******/ // The require function
/******/ function _ _webpack _require _ _ ( moduleId ) {
/******/ // Check if module is in cache
/******/ var cachedModule = _ _webpack _module _cache _ _ [ moduleId ] ;
/******/ if ( cachedModule !== undefined ) {
/******/ return cachedModule . exports ;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = _ _webpack _module _cache _ _ [ moduleId ] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports : { }
/******/ } ;
/******/
/******/ // Execute the module function
/******/ _ _webpack _modules _ _ [ moduleId ] . call ( module . exports , module , module . exports , _ _webpack _require _ _ ) ;
/******/
/******/ // Return the exports of the module
/******/ return module . exports ;
/******/ }
/******/
/************************************************************************/
2021-12-26 22:38:09 +01:00
/******/ /* webpack/runtime/compat get default export */
/******/ ! function ( ) {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ _ _webpack _require _ _ . n = function ( module ) {
/******/ var getter = module && module . _ _esModule ?
/******/ function ( ) { return module [ 'default' ] ; } :
/******/ function ( ) { return module ; } ;
/******/ _ _webpack _require _ _ . d ( getter , { a : getter } ) ;
/******/ return getter ;
/******/ } ;
/******/ } ( ) ;
/******/
2021-12-19 22:58:00 +01:00
/******/ /* webpack/runtime/define property getters */
/******/ ! function ( ) {
/******/ // define getter functions for harmony exports
/******/ _ _webpack _require _ _ . d = function ( exports , definition ) {
/******/ for ( var key in definition ) {
/******/ if ( _ _webpack _require _ _ . o ( definition , key ) && ! _ _webpack _require _ _ . o ( exports , key ) ) {
/******/ Object . defineProperty ( exports , key , { enumerable : true , get : definition [ key ] } ) ;
/******/ }
/******/ }
/******/ } ;
/******/ } ( ) ;
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ ! function ( ) {
/******/ _ _webpack _require _ _ . o = function ( obj , prop ) { return Object . prototype . hasOwnProperty . call ( obj , prop ) ; }
/******/ } ( ) ;
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ ! function ( ) {
/******/ // define __esModule on exports
/******/ _ _webpack _require _ _ . r = function ( exports ) {
/******/ if ( typeof Symbol !== 'undefined' && Symbol . toStringTag ) {
/******/ Object . defineProperty ( exports , Symbol . toStringTag , { value : 'Module' } ) ;
/******/ }
/******/ Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
/******/ } ;
/******/ } ( ) ;
/******/
/************************************************************************/
2021-12-26 22:38:09 +01:00
var _ _webpack _exports _ _ = { } ;
2022-01-01 00:11:45 +01:00
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
2021-12-26 22:38:09 +01:00
! function ( ) {
/* harmony import */ var _scripts _choices _ _WEBPACK _IMPORTED _MODULE _0 _ _ = _ _webpack _require _ _ ( 373 ) ;
/* harmony import */ var _scripts _choices _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _scripts _choices _ _WEBPACK _IMPORTED _MODULE _0 _ _ ) ;
2021-12-27 15:50:45 +01:00
/* harmony import */ var _scripts _interfaces _ _WEBPACK _IMPORTED _MODULE _1 _ _ = _ _webpack _require _ _ ( 187 ) ;
/* harmony import */ var _scripts _interfaces _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _scripts _interfaces _ _WEBPACK _IMPORTED _MODULE _1 _ _ ) ;
/* harmony import */ var _scripts _constants _ _WEBPACK _IMPORTED _MODULE _2 _ _ = _ _webpack _require _ _ ( 883 ) ;
/* harmony import */ var _scripts _defaults _ _WEBPACK _IMPORTED _MODULE _3 _ _ = _ _webpack _require _ _ ( 789 ) ;
/* harmony import */ var _scripts _templates _ _WEBPACK _IMPORTED _MODULE _4 _ _ = _ _webpack _require _ _ ( 686 ) ;
2021-12-26 22:38:09 +01:00
/* harmony default export */ _ _webpack _exports _ _ [ "default" ] = ( ( _scripts _choices _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default ( ) ) ) ;
} ( ) ;
_ _webpack _exports _ _ = _ _webpack _exports _ _ [ "default" ] ;
2021-12-19 22:58:00 +01:00
/******/ return _ _webpack _exports _ _ ;
/******/ } ) ( )
;
2019-02-09 19:13:25 +01:00
} ) ;