2016-10-18 15:15:00 +02:00
( function webpackUniversalModuleDefinition ( root , factory ) {
2019-02-09 19:13:25 +01:00
//CommonJS2
2016-10-18 15:15:00 +02:00
if ( typeof exports === 'object' && typeof module === 'object' )
module . exports = factory ( ) ;
2019-02-09 19:13:25 +01:00
//AMD
2016-10-18 15:15:00 +02:00
else if ( typeof define === 'function' && define . amd )
2016-10-28 22:59:43 +02:00
define ( [ ] , factory ) ;
2019-02-09 19:13:25 +01:00
//CommonJS
2016-10-18 15:15:00 +02:00
else if ( typeof exports === 'object' )
exports [ "Choices" ] = factory ( ) ;
2019-02-09 19:13:25 +01:00
//Window
2016-10-18 15:15:00 +02:00
else
root [ "Choices" ] = factory ( ) ;
2019-02-09 19:13:25 +01:00
} ) ( window , function ( ) {
2016-10-18 15:15:00 +02:00
return /******/ ( function ( modules ) { // webpackBootstrap
2016-08-23 08:24:45 +02:00
/******/ // The module cache
/******/ var installedModules = { } ;
2017-11-07 12:59:49 +01:00
/******/
2016-08-23 08:24:45 +02:00
/******/ // The require function
/******/ function _ _webpack _require _ _ ( moduleId ) {
2017-11-07 12:59:49 +01:00
/******/
2016-08-23 08:24:45 +02:00
/******/ // Check if module is in cache
2017-11-07 12:59:49 +01:00
/******/ if ( installedModules [ moduleId ] ) {
2016-08-23 08:24:45 +02:00
/******/ return installedModules [ moduleId ] . exports ;
2017-11-07 12:59:49 +01:00
/******/ }
2016-08-23 08:24:45 +02:00
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules [ moduleId ] = {
2017-11-07 12:59:49 +01:00
/******/ i : moduleId ,
/******/ l : false ,
/******/ exports : { }
2016-08-23 08:24:45 +02:00
/******/ } ;
2017-11-07 12:59:49 +01:00
/******/
2016-08-23 08:24:45 +02:00
/******/ // Execute the module function
/******/ modules [ moduleId ] . call ( module . exports , module , module . exports , _ _webpack _require _ _ ) ;
2017-11-07 12:59:49 +01:00
/******/
2016-08-23 08:24:45 +02:00
/******/ // Flag the module as loaded
2017-11-07 12:59:49 +01:00
/******/ module . l = true ;
/******/
2016-08-23 08:24:45 +02:00
/******/ // Return the exports of the module
/******/ return module . exports ;
/******/ }
2017-11-07 12:59:49 +01:00
/******/
/******/
2016-08-23 08:24:45 +02:00
/******/ // expose the modules object (__webpack_modules__)
/******/ _ _webpack _require _ _ . m = modules ;
2017-11-07 12:59:49 +01:00
/******/
2016-08-23 08:24:45 +02:00
/******/ // expose the module cache
/******/ _ _webpack _require _ _ . c = installedModules ;
2017-11-07 12:59:49 +01:00
/******/
/******/ // define getter function for harmony exports
/******/ _ _webpack _require _ _ . d = function ( exports , name , getter ) {
/******/ if ( ! _ _webpack _require _ _ . o ( exports , name ) ) {
2019-02-09 19:13:25 +01:00
/******/ Object . defineProperty ( exports , name , { enumerable : true , get : getter } ) ;
2017-11-07 12:59:49 +01:00
/******/ }
/******/ } ;
/******/
2019-02-09 19:13:25 +01:00
/******/ // 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 } ) ;
/******/ } ;
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ _ _webpack _require _ _ . t = function ( value , mode ) {
/******/ if ( mode & 1 ) value = _ _webpack _require _ _ ( value ) ;
/******/ if ( mode & 8 ) return value ;
/******/ if ( ( mode & 4 ) && typeof value === 'object' && value && value . _ _esModule ) return value ;
/******/ var ns = Object . create ( null ) ;
/******/ _ _webpack _require _ _ . r ( ns ) ;
/******/ Object . defineProperty ( ns , 'default' , { enumerable : true , value : value } ) ;
/******/ if ( mode & 2 && typeof value != 'string' ) for ( var key in value ) _ _webpack _require _ _ . d ( ns , key , function ( key ) { return value [ key ] ; } . bind ( null , key ) ) ;
/******/ return ns ;
/******/ } ;
/******/
2017-11-07 12:59:49 +01:00
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ _ _webpack _require _ _ . n = function ( module ) {
/******/ var getter = module && module . _ _esModule ?
/******/ function getDefault ( ) { return module [ 'default' ] ; } :
/******/ function getModuleExports ( ) { return module ; } ;
/******/ _ _webpack _require _ _ . d ( getter , 'a' , getter ) ;
/******/ return getter ;
/******/ } ;
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ _ _webpack _require _ _ . o = function ( object , property ) { return Object . prototype . hasOwnProperty . call ( object , property ) ; } ;
/******/
2016-08-23 08:24:45 +02:00
/******/ // __webpack_public_path__
2018-05-25 15:00:27 +02:00
/******/ _ _webpack _require _ _ . p = "/public/assets/scripts/" ;
2017-11-07 12:59:49 +01:00
/******/
2019-02-09 19:13:25 +01:00
/******/
2016-08-23 08:24:45 +02:00
/******/ // Load entry module and return exports
2019-02-09 19:13:25 +01:00
/******/ return _ _webpack _require _ _ ( _ _webpack _require _ _ . s = 9 ) ;
2016-08-23 08:24:45 +02:00
/******/ } )
/************************************************************************/
/******/ ( [
/* 0 */
2017-11-13 20:13:37 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
"use strict" ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . doKeysMatch = exports . cloneObject = exports . existsInArray = exports . isIE11 = exports . fetchFromObject = exports . reduceToValues = exports . getWindowHeight = exports . regexFilter = exports . dispatchEvent = exports . sortByScore = exports . sortByAlpha = exports . calcWidthOfInput = exports . strToEl = exports . stripHTML = exports . isScrolledIntoView = exports . getAdjacentEl = exports . findAncestorByAttrName = exports . findAncestor = exports . wrap = exports . extend = exports . isElement = exports . isType = exports . getType = exports . generateId = exports . generateChars = exports . getRandomNumber = void 0 ;
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
var _this = void 0 ;
/* eslint-disable */
var getRandomNumber = function getRandomNumber ( min , max ) {
2018-05-28 17:22:22 +02:00
return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
} ;
2019-02-09 19:13:25 +01:00
exports . getRandomNumber = getRandomNumber ;
var generateChars = function generateChars ( length ) {
2017-11-15 07:51:53 +01:00
var chars = '' ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
for ( var i = 0 ; i < length ; i ++ ) {
var randomChar = getRandomNumber ( 0 , 36 ) ;
chars += randomChar . toString ( 36 ) ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
return chars ;
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . generateChars = generateChars ;
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
var generateId = function generateId ( element , prefix ) {
var id = element . id || element . name && "" . concat ( element . name , "-" ) . concat ( generateChars ( 2 ) ) || generateChars ( 4 ) ;
id = id . replace ( /(:|\.|\[|\]|,)/g , '' ) ;
id = "" . concat ( prefix , "-" ) . concat ( id ) ;
2017-11-15 07:51:53 +01:00
return id ;
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . generateId = generateId ;
var getType = function getType ( obj ) {
2017-11-15 07:51:53 +01:00
return Object . prototype . toString . call ( obj ) . slice ( 8 , - 1 ) ;
} ;
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
exports . getType = getType ;
var isType = function isType ( type , obj ) {
2017-11-15 07:51:53 +01:00
var clas = getType ( obj ) ;
return obj !== undefined && obj !== null && clas === type ;
} ;
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
exports . isType = isType ;
var isElement = function isElement ( element ) {
2018-05-29 16:08:43 +02:00
return element instanceof Element ;
2017-11-15 07:51:53 +01:00
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . isElement = isElement ;
var extend = function extend ( ) {
2017-11-15 07:51:53 +01:00
var extended = { } ;
var length = arguments . length ;
/ * *
* Merge one object into another
* @ param { Object } obj Object to merge into extended object
* /
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
var merge = function merge ( obj ) {
for ( var prop in obj ) {
if ( Object . prototype . hasOwnProperty . call ( obj , prop ) ) {
// If deep merge and property is an object, merge properties
if ( isType ( 'Object' , obj [ prop ] ) ) {
extended [ prop ] = extend ( true , extended [ prop ] , obj [ prop ] ) ;
} else {
extended [ prop ] = obj [ prop ] ;
}
}
}
2019-02-09 19:13:25 +01:00
} ; // Loop through each passed argument
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var i = 0 ; i < length ; i ++ ) {
// store argument at position i
2019-02-09 19:13:25 +01:00
var obj = arguments [ i ] ; // If we are in fact dealing with an object, merge it.
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( isType ( 'Object' , obj ) ) {
merge ( obj ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return extended ;
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . extend = extend ;
var wrap = function wrap ( element , wrapper ) {
2017-11-15 07:51:53 +01:00
wrapper = wrapper || document . createElement ( 'div' ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( element . nextSibling ) {
element . parentNode . insertBefore ( wrapper , element . nextSibling ) ;
} else {
element . parentNode . appendChild ( wrapper ) ;
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return wrapper . appendChild ( element ) ;
} ;
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
exports . wrap = wrap ;
var findAncestor = function findAncestor ( el , cls ) {
while ( ( el = el . parentElement ) && ! el . classList . contains ( cls ) ) {
;
}
2017-11-15 07:51:53 +01:00
return el ;
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . findAncestor = findAncestor ;
var findAncestorByAttrName = function findAncestorByAttrName ( el , attr ) {
2017-11-15 07:51:53 +01:00
var target = el ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
while ( target ) {
if ( target . hasAttribute ( attr ) ) {
return target ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
target = target . parentElement ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return null ;
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . findAncestorByAttrName = findAncestorByAttrName ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var getAdjacentEl = function getAdjacentEl ( startEl , className ) {
var direction = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : 1 ;
2017-11-15 07:51:53 +01:00
if ( ! startEl || ! className ) return ;
var parent = startEl . parentNode . parentNode ;
var children = Array . from ( parent . querySelectorAll ( className ) ) ;
var startPos = children . indexOf ( startEl ) ;
var operatorDirection = direction > 0 ? 1 : - 1 ;
return children [ startPos + operatorDirection ] ;
} ;
2019-02-09 19:13:25 +01:00
exports . getAdjacentEl = getAdjacentEl ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var isScrolledIntoView = function isScrolledIntoView ( el , parent ) {
var direction = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : 1 ;
2017-11-15 07:51:53 +01:00
if ( ! el ) return ;
2019-02-09 19:13:25 +01:00
var isVisible ;
2017-11-15 07:51:53 +01:00
if ( direction > 0 ) {
// In view from bottom
isVisible = parent . scrollTop + parent . offsetHeight >= el . offsetTop + el . offsetHeight ;
} else {
// In view from top
isVisible = el . offsetTop >= parent . scrollTop ;
}
return isVisible ;
} ;
2019-02-09 19:13:25 +01:00
exports . isScrolledIntoView = isScrolledIntoView ;
var stripHTML = function stripHTML ( html ) {
2018-04-25 10:20:59 +02:00
return html . replace ( /&/g , '&' ) . replace ( />/g , '&rt;' ) . replace ( /</g , '<' ) . replace ( /"/g , '"' ) ;
2017-11-15 07:51:53 +01:00
} ;
2019-02-09 19:13:25 +01:00
exports . stripHTML = stripHTML ;
var strToEl = function ( ) {
2017-11-15 07:51:53 +01:00
var tmpEl = document . createElement ( 'div' ) ;
return function ( str ) {
var cleanedInput = str . trim ( ) ;
2019-02-09 19:13:25 +01:00
var r ;
2017-11-15 07:51:53 +01:00
tmpEl . innerHTML = cleanedInput ;
r = tmpEl . children [ 0 ] ;
while ( tmpEl . firstChild ) {
tmpEl . removeChild ( tmpEl . firstChild ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return r ;
} ;
} ( ) ;
/ * *
2018-05-28 17:22:22 +02:00
* Determines the width of a passed input based on its value and passes
* it to the supplied callback function .
2017-11-15 07:51:53 +01:00
* /
2019-02-09 19:13:25 +01:00
exports . strToEl = strToEl ;
var calcWidthOfInput = function calcWidthOfInput ( input , callback ) {
2017-11-15 07:51:53 +01:00
var value = input . value || input . placeholder ;
var width = input . offsetWidth ;
if ( value ) {
2019-02-09 19:13:25 +01:00
var testEl = strToEl ( "<span>" . concat ( stripHTML ( value ) , "</span>" ) ) ;
2017-11-15 07:51:53 +01:00
testEl . style . position = 'absolute' ;
testEl . style . padding = '0' ;
testEl . style . top = '-9999px' ;
testEl . style . left = '-9999px' ;
testEl . style . width = 'auto' ;
testEl . style . whiteSpace = 'pre' ;
if ( document . body . contains ( input ) && window . getComputedStyle ) {
var inputStyle = window . getComputedStyle ( input ) ;
if ( inputStyle ) {
testEl . style . fontSize = inputStyle . fontSize ;
testEl . style . fontFamily = inputStyle . fontFamily ;
testEl . style . fontWeight = inputStyle . fontWeight ;
testEl . style . fontStyle = inputStyle . fontStyle ;
testEl . style . letterSpacing = inputStyle . letterSpacing ;
testEl . style . textTransform = inputStyle . textTransform ;
testEl . style . padding = inputStyle . padding ;
}
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
document . body . appendChild ( testEl ) ;
2018-05-28 17:22:22 +02:00
requestAnimationFrame ( function ( ) {
if ( value && testEl . offsetWidth !== input . offsetWidth ) {
width = testEl . offsetWidth + 4 ;
}
2017-11-07 12:59:49 +01:00
2018-05-28 17:22:22 +02:00
document . body . removeChild ( testEl ) ;
2019-02-09 19:13:25 +01:00
callback . call ( _this , "" . concat ( width , "px" ) ) ;
2018-05-28 17:22:22 +02:00
} ) ;
} else {
2019-02-09 19:13:25 +01:00
callback . call ( _this , "" . concat ( width , "px" ) ) ;
2018-05-28 17:22:22 +02:00
}
2017-11-15 07:51:53 +01:00
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . calcWidthOfInput = calcWidthOfInput ;
var sortByAlpha = function sortByAlpha ( a , b ) {
2017-11-15 07:51:53 +01:00
var labelA = ( a . label || a . value ) . toLowerCase ( ) ;
var labelB = ( b . label || b . value ) . toLowerCase ( ) ;
2017-11-07 12:59:49 +01:00
2018-05-29 16:08:43 +02:00
if ( labelA < labelB ) {
return - 1 ;
}
if ( labelA > labelB ) {
return 1 ;
}
2017-11-15 07:51:53 +01:00
return 0 ;
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . sortByAlpha = sortByAlpha ;
var sortByScore = function sortByScore ( a , b ) {
2017-11-15 07:51:53 +01:00
return a . score - b . score ;
} ;
2019-02-09 19:13:25 +01:00
exports . sortByScore = sortByScore ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var dispatchEvent = function dispatchEvent ( element , type ) {
var customArgs = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : null ;
2017-11-15 07:51:53 +01:00
var event = new CustomEvent ( type , {
detail : customArgs ,
bubbles : true ,
cancelable : true
} ) ;
return element . dispatchEvent ( event ) ;
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . dispatchEvent = dispatchEvent ;
var regexFilter = function regexFilter ( value , regex ) {
2017-11-15 07:51:53 +01:00
if ( ! value || ! regex ) {
return false ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var expression = new RegExp ( regex . source , 'i' ) ;
return expression . test ( value ) ;
} ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
exports . regexFilter = regexFilter ;
var getWindowHeight = function getWindowHeight ( ) {
2018-02-02 12:08:03 +01:00
var body = document . body ;
var html = document . documentElement ;
return Math . max ( body . scrollHeight , body . offsetHeight , html . clientHeight , html . scrollHeight , html . offsetHeight ) ;
} ;
2019-02-09 19:13:25 +01:00
exports . getWindowHeight = getWindowHeight ;
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
var reduceToValues = function reduceToValues ( items ) {
var key = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 'value' ;
2018-02-02 12:08:03 +01:00
var values = items . reduce ( function ( prev , current ) {
prev . push ( current [ key ] ) ;
return prev ;
} , [ ] ) ;
return values ;
} ;
2019-02-09 19:13:25 +01:00
exports . reduceToValues = reduceToValues ;
var fetchFromObject = function fetchFromObject ( object , path ) {
2018-05-29 16:08:43 +02:00
var index = path . indexOf ( '.' ) ;
2018-03-12 21:43:43 +01:00
if ( index > - 1 ) {
2018-05-29 16:08:43 +02:00
return fetchFromObject ( object [ path . substring ( 0 , index ) ] , path . substr ( index + 1 ) ) ;
2018-03-12 21:43:43 +01:00
}
2018-05-29 16:08:43 +02:00
return object [ path ] ;
2018-03-12 21:43:43 +01:00
} ;
2019-02-09 19:13:25 +01:00
exports . fetchFromObject = fetchFromObject ;
var isIE11 = function isIE11 ( ) {
2018-05-25 15:00:27 +02:00
return ! ! ( navigator . userAgent . match ( /Trident/ ) && navigator . userAgent . match ( /rv[ :]11/ ) ) ;
} ;
2019-02-09 19:13:25 +01:00
exports . isIE11 = isIE11 ;
var existsInArray = function existsInArray ( array , value ) {
2018-05-29 16:08:43 +02:00
var key = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : 'value' ;
2018-05-28 16:13:55 +02:00
return array . some ( function ( item ) {
if ( isType ( 'String' , value ) ) {
2018-05-29 16:08:43 +02:00
return item [ key ] === value . trim ( ) ;
2018-05-28 16:13:55 +02:00
}
2018-05-29 16:08:43 +02:00
return item [ key ] === value ;
2018-05-28 16:13:55 +02:00
} ) ;
} ;
2019-02-09 19:13:25 +01:00
exports . existsInArray = existsInArray ;
var cloneObject = function cloneObject ( obj ) {
2018-05-28 17:22:22 +02:00
return JSON . parse ( JSON . stringify ( obj ) ) ;
} ;
2019-02-09 19:13:25 +01:00
exports . cloneObject = cloneObject ;
var doKeysMatch = function doKeysMatch ( a , b ) {
2018-10-13 12:19:24 +02:00
var aKeys = Object . keys ( a ) . sort ( ) ;
var bKeys = Object . keys ( b ) . sort ( ) ;
return JSON . stringify ( aKeys ) === JSON . stringify ( bKeys ) ;
} ;
2019-02-09 19:13:25 +01:00
exports . doKeysMatch = doKeysMatch ;
2018-05-25 15:00:27 +02:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 1 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . SCROLLING _SPEED = exports . KEY _CODES = exports . ACTION _TYPES = exports . EVENTS = exports . DEFAULT _CONFIG = exports . DEFAULT _CLASSNAMES = void 0 ;
2018-04-25 10:20:59 +02:00
2019-02-09 19:13:25 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2018-04-25 10:20:59 +02:00
2019-02-09 19:13:25 +01:00
var DEFAULT _CLASSNAMES = {
2017-11-15 07:51:53 +01:00
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' ,
hiddenState : 'is-hidden' ,
flippedState : 'is-flipped' ,
loadingState : 'is-loading' ,
noResults : 'has-no-results' ,
noChoices : 'has-no-choices'
} ;
2019-02-09 19:13:25 +01:00
exports . DEFAULT _CLASSNAMES = DEFAULT _CLASSNAMES ;
var DEFAULT _CONFIG = {
2018-02-02 12:08:03 +01:00
items : [ ] ,
choices : [ ] ,
2017-11-15 07:51:53 +01:00
silent : false ,
renderChoiceLimit : - 1 ,
maxItemCount : - 1 ,
addItems : true ,
removeItems : true ,
removeItemButton : false ,
editItems : false ,
2018-05-29 10:30:05 +02:00
duplicateItemsAllowed : true ,
2017-11-15 07:51:53 +01:00
delimiter : ',' ,
paste : true ,
searchEnabled : true ,
searchChoices : true ,
searchFloor : 1 ,
searchResultLimit : 4 ,
searchFields : [ 'label' , 'value' ] ,
position : 'auto' ,
resetScrollPosition : true ,
regexFilter : null ,
shouldSort : true ,
shouldSortItems : false ,
2018-10-13 12:19:24 +02:00
sortFn : _utils . sortByAlpha ,
2017-11-15 07:51:53 +01:00
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' ,
2018-10-18 23:22:22 +02:00
uniqueItemText : 'Only unique values can be added' ,
2017-11-15 07:51:53 +01:00
addItemText : function addItemText ( value ) {
2019-02-09 19:13:25 +01:00
return "Press Enter to add <b>\"" . concat ( ( 0 , _utils . stripHTML ) ( value ) , "\"</b>" ) ;
2017-11-15 07:51:53 +01:00
} ,
maxItemText : function maxItemText ( maxItemCount ) {
2019-02-09 19:13:25 +01:00
return "Only " . concat ( maxItemCount , " values can be added" ) ;
2017-11-15 07:51:53 +01:00
} ,
2018-02-02 12:08:03 +01:00
itemComparer : function itemComparer ( choice , item ) {
return choice === item ;
} ,
2017-11-15 07:51:53 +01:00
fuseOptions : {
includeScore : true
} ,
callbackOnInit : null ,
2018-10-13 12:19:24 +02:00
callbackOnCreateTemplates : null ,
classNames : DEFAULT _CLASSNAMES
2017-11-15 07:51:53 +01:00
} ;
2019-02-09 19:13:25 +01:00
exports . DEFAULT _CONFIG = DEFAULT _CONFIG ;
var EVENTS = {
2017-11-15 07:51:53 +01:00
showDropdown : 'showDropdown' ,
hideDropdown : 'hideDropdown' ,
change : 'change' ,
choice : 'choice' ,
search : 'search' ,
addItem : 'addItem' ,
removeItem : 'removeItem' ,
2018-06-07 17:54:11 +02:00
highlightItem : 'highlightItem' ,
highlightChoice : 'highlightChoice'
2017-11-15 07:51:53 +01:00
} ;
2019-02-09 19:13:25 +01:00
exports . EVENTS = EVENTS ;
var ACTION _TYPES = {
2017-11-15 07:51:53 +01:00
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'
} ;
2019-02-09 19:13:25 +01:00
exports . ACTION _TYPES = ACTION _TYPES ;
var KEY _CODES = {
2017-11-15 07:51:53 +01:00
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
} ;
2019-02-09 19:13:25 +01:00
exports . KEY _CODES = KEY _CODES ;
var SCROLLING _SPEED = 4 ;
exports . SCROLLING _SPEED = SCROLLING _SPEED ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 2 */
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
"use strict" ;
/* WEBPACK VAR INJECTION */ ( function ( global , module ) { /* harmony import */ var _ponyfill _js _ _WEBPACK _IMPORTED _MODULE _0 _ _ = _ _webpack _require _ _ ( 7 ) ;
/* global window */
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var root ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
if ( typeof self !== 'undefined' ) {
root = self ;
} else if ( typeof window !== 'undefined' ) {
root = window ;
} else if ( typeof global !== 'undefined' ) {
root = global ;
} else if ( true ) {
root = module ;
} else { }
var result = Object ( _ponyfill _js _ _WEBPACK _IMPORTED _MODULE _0 _ _ [ /* default */ "a" ] ) ( root ) ;
/* harmony default export */ _ _webpack _exports _ _ [ "a" ] = ( result ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
/* WEBPACK VAR INJECTION */ } . call ( this , _ _webpack _require _ _ ( 3 ) , _ _webpack _require _ _ ( 16 ) ( module ) ) )
2017-11-07 12:59:49 +01:00
2018-05-28 16:13:55 +02:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 3 */
/***/ ( function ( module , exports ) {
2017-06-27 13:42:01 +02:00
2019-02-09 19:13:25 +01:00
var g ;
2017-06-27 13:42:01 +02:00
2019-02-09 19:13:25 +01:00
// This works in non-strict mode
g = ( function ( ) {
return this ;
} ) ( ) ;
2017-06-27 13:42:01 +02:00
2019-02-09 19:13:25 +01:00
try {
// This works if eval is allowed (see CSP)
g = g || new Function ( "return this" ) ( ) ;
} catch ( e ) {
// This works if the window reference is available
if ( typeof window === "object" ) g = window ;
}
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
// g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...}
module . exports = g ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
2018-05-25 15:00:27 +02:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 4 */
2018-10-27 17:45:19 +02:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var WrappedElement =
/*#__PURE__*/
function ( ) {
function WrappedElement ( _ref ) {
var element = _ref . element ,
classNames = _ref . classNames ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
_classCallCheck ( this , WrappedElement ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
Object . assign ( this , {
element : element ,
classNames : classNames
} ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
if ( ! ( 0 , _utils . isElement ) ( element ) ) {
throw new TypeError ( 'Invalid element passed' ) ;
}
2018-10-27 17:45:19 +02:00
2019-02-09 19:13:25 +01:00
this . isDisabled = false ;
2018-10-27 17:45:19 +02:00
}
2019-02-09 19:13:25 +01:00
_createClass ( WrappedElement , [ {
key : "conceal" ,
value : function conceal ( ) {
// Hide passed input
this . element . classList . add ( this . classNames . input ) ;
this . element . classList . add ( this . classNames . hiddenState ) ; // Remove element from tab index
2018-10-27 17:45:19 +02:00
2019-02-09 19:13:25 +01:00
this . element . tabIndex = '-1' ; // Backup original styles if any
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var origStyle = this . element . getAttribute ( 'style' ) ;
2018-10-27 17:45:19 +02:00
2019-02-09 19:13:25 +01:00
if ( origStyle ) {
this . element . setAttribute ( 'data-choice-orig-style' , origStyle ) ;
}
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
this . element . setAttribute ( 'aria-hidden' , 'true' ) ;
this . element . setAttribute ( 'data-choice' , 'active' ) ;
}
} , {
key : "reveal" ,
value : function reveal ( ) {
// Reinstate passed element
this . element . classList . remove ( this . classNames . input ) ;
this . element . classList . remove ( this . classNames . hiddenState ) ;
this . element . removeAttribute ( 'tabindex' ) ; // Recover original styles if any
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var origStyle = this . element . getAttribute ( 'data-choice-orig-style' ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
if ( origStyle ) {
this . element . removeAttribute ( 'data-choice-orig-style' ) ;
this . element . setAttribute ( 'style' , origStyle ) ;
} else {
this . element . removeAttribute ( 'style' ) ;
}
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
this . element . removeAttribute ( 'aria-hidden' ) ;
this . element . removeAttribute ( 'data-choice' ) ; // Re-assign values - this is weird, I know
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
this . element . value = this . element . value ;
}
} , {
key : "enable" ,
value : function enable ( ) {
this . element . removeAttribute ( 'disabled' ) ;
this . element . disabled = false ;
this . isDisabled = false ;
}
} , {
key : "disable" ,
value : function disable ( ) {
this . element . setAttribute ( 'disabled' , '' ) ;
this . element . disabled = true ;
this . isDisabled = true ;
}
} , {
key : "triggerEvent" ,
value : function triggerEvent ( eventType , data ) {
( 0 , _utils . dispatchEvent ) ( this . element , eventType , data ) ;
}
} , {
key : "value" ,
get : function get ( ) {
return this . element . value ;
}
} ] ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
return WrappedElement ;
} ( ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
exports . default = WrappedElement ;
2018-05-25 15:00:27 +02:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 5 */
2018-05-25 15:00:27 +02:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2019-02-09 19:13:25 +01:00
"use strict" ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = exports . TEMPLATES = void 0 ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var _classnames = _interopRequireDefault ( _ _webpack _require _ _ ( 29 ) ) ;
2018-10-27 17:45:19 +02:00
2019-02-09 19:13:25 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2018-10-27 17:45:19 +02:00
2019-02-09 19:13:25 +01:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2018-10-27 17:45:19 +02:00
2019-02-09 19:13:25 +01:00
function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
2018-10-27 17:45:19 +02:00
2019-02-09 19:13:25 +01:00
var TEMPLATES = {
containerOuter : function containerOuter ( globalClasses , direction , isSelectElement , isSelectOneElement , searchEnabled , passedElementType ) {
var tabIndex = isSelectOneElement ? 'tabindex="0"' : '' ;
var role = isSelectElement ? 'role="listbox"' : '' ;
var ariaAutoComplete = '' ;
2018-10-27 17:45:19 +02:00
2019-02-09 19:13:25 +01:00
if ( isSelectElement && searchEnabled ) {
role = 'role="combobox"' ;
ariaAutoComplete = 'aria-autocomplete="list"' ;
}
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
return ( 0 , _utils . strToEl ) ( "\n <div\n class=\"" . concat ( globalClasses . containerOuter , "\"\n data-type=\"" ) . concat ( passedElementType , "\"\n " ) . concat ( role , "\n " ) . concat ( tabIndex , "\n " ) . concat ( ariaAutoComplete , "\n aria-haspopup=\"true\"\n aria-expanded=\"false\"\n dir=\"" ) . concat ( direction , "\"\n >\n </div>\n " ) ) ;
} ,
containerInner : function containerInner ( globalClasses ) {
return ( 0 , _utils . strToEl ) ( "\n <div class=\"" . concat ( globalClasses . containerInner , "\"></div>\n " ) ) ;
} ,
itemList : function itemList ( globalClasses , isSelectOneElement ) {
var _classNames ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var localClasses = ( 0 , _classnames . default ) ( globalClasses . list , ( _classNames = { } , _defineProperty ( _classNames , globalClasses . listSingle , isSelectOneElement ) , _defineProperty ( _classNames , globalClasses . listItems , ! isSelectOneElement ) , _classNames ) ) ;
return ( 0 , _utils . strToEl ) ( "\n <div class=\"" . concat ( localClasses , "\"></div>\n " ) ) ;
} ,
placeholder : function placeholder ( globalClasses , value ) {
return ( 0 , _utils . strToEl ) ( "\n <div class=\"" . concat ( globalClasses . placeholder , "\">\n " ) . concat ( value , "\n </div>\n " ) ) ;
} ,
item : function item ( globalClasses , data , removeItemButton ) {
var _classNames2 ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var ariaSelected = data . active ? 'aria-selected="true"' : '' ;
var ariaDisabled = data . disabled ? 'aria-disabled="true"' : '' ;
var localClasses = ( 0 , _classnames . default ) ( globalClasses . item , ( _classNames2 = { } , _defineProperty ( _classNames2 , globalClasses . highlightedState , data . highlighted ) , _defineProperty ( _classNames2 , globalClasses . itemSelectable , ! data . highlighted ) , _defineProperty ( _classNames2 , globalClasses . placeholder , data . placeholder ) , _classNames2 ) ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
if ( removeItemButton ) {
var _classNames3 ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
localClasses = ( 0 , _classnames . default ) ( globalClasses . item , ( _classNames3 = { } , _defineProperty ( _classNames3 , globalClasses . highlightedState , data . highlighted ) , _defineProperty ( _classNames3 , globalClasses . itemSelectable , ! data . disabled ) , _defineProperty ( _classNames3 , globalClasses . placeholder , data . placeholder ) , _classNames3 ) ) ;
2019-02-11 18:52:22 +01:00
return ( 0 , _utils . strToEl ) ( "\n <div\n class=\"" . concat ( localClasses , "\"\n data-item\n data-id=\"" ) . concat ( data . id , "\"\n data-value=\"" ) . concat ( data . value , "\"\n data-custom-properties='" ) . concat ( data . customProperties , "'\n data-deletable\n " ) . concat ( ariaSelected , "\n " ) . concat ( ariaDisabled , "\n >\n " ) . concat ( data . label , "<!--\n --><button\n type=\"button\"\n class=\"" ) . concat ( globalClasses . button , "\"\n data-button\n aria-label=\"Remove item: '" ) . concat ( data . value , "'\"\n >\n Remove item\n </button>\n </div>\n " ) ) ;
2019-02-09 19:13:25 +01:00
}
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
return ( 0 , _utils . strToEl ) ( "\n <div\n class=\"" . concat ( localClasses , "\"\n data-item\n data-id=\"" ) . concat ( data . id , "\"\n data-value=\"" ) . concat ( data . value , "\"\n " ) . concat ( ariaSelected , "\n " ) . concat ( ariaDisabled , "\n >\n " ) . concat ( data . label , "\n </div>\n " ) ) ;
} ,
choiceList : function choiceList ( globalClasses , isSelectOneElement ) {
var ariaMultiSelectable = ! isSelectOneElement ? 'aria-multiselectable="true"' : '' ;
return ( 0 , _utils . strToEl ) ( "\n <div\n class=\"" . concat ( globalClasses . list , "\"\n dir=\"ltr\"\n role=\"listbox\"\n " ) . concat ( ariaMultiSelectable , "\n >\n </div>\n " ) ) ;
} ,
choiceGroup : function choiceGroup ( globalClasses , data ) {
var ariaDisabled = data . disabled ? 'aria-disabled="true"' : '' ;
var localClasses = ( 0 , _classnames . default ) ( globalClasses . group , _defineProperty ( { } , globalClasses . itemDisabled , data . disabled ) ) ;
return ( 0 , _utils . strToEl ) ( "\n <div\n class=\"" . concat ( localClasses , "\"\n data-group\n data-id=\"" ) . concat ( data . id , "\"\n data-value=\"" ) . concat ( data . value , "\"\n role=\"group\"\n " ) . concat ( ariaDisabled , "\n >\n <div class=\"" ) . concat ( globalClasses . groupHeading , "\">" ) . concat ( data . value , "</div>\n </div>\n " ) ) ;
} ,
choice : function choice ( globalClasses , data , itemSelectText ) {
var _classNames5 ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var role = data . groupId > 0 ? 'role="treeitem"' : 'role="option"' ;
var localClasses = ( 0 , _classnames . default ) ( globalClasses . item , globalClasses . itemChoice , ( _classNames5 = { } , _defineProperty ( _classNames5 , globalClasses . itemDisabled , data . disabled ) , _defineProperty ( _classNames5 , globalClasses . itemSelectable , ! data . disabled ) , _defineProperty ( _classNames5 , globalClasses . placeholder , data . placeholder ) , _classNames5 ) ) ;
return ( 0 , _utils . strToEl ) ( "\n <div\n class=\"" . concat ( localClasses , "\"\n data-select-text=\"" ) . concat ( itemSelectText , "\"\n data-choice\n data-id=\"" ) . concat ( data . id , "\"\n data-value=\"" ) . concat ( data . value , "\"\n " ) . concat ( data . disabled ? 'data-choice-disabled aria-disabled="true"' : 'data-choice-selectable' , "\n id=\"" ) . concat ( data . elementId , "\"\n " ) . concat ( role , "\n >\n " ) . concat ( data . label , "\n </div>\n " ) ) ;
} ,
input : function input ( globalClasses ) {
var localClasses = ( 0 , _classnames . default ) ( globalClasses . input , globalClasses . inputCloned ) ;
return ( 0 , _utils . strToEl ) ( "\n <input\n type=\"text\"\n class=\"" . concat ( localClasses , "\"\n autocomplete=\"off\"\n autocapitalize=\"off\"\n spellcheck=\"false\"\n role=\"textbox\"\n aria-autocomplete=\"list\"\n >\n " ) ) ;
} ,
dropdown : function dropdown ( globalClasses ) {
var localClasses = ( 0 , _classnames . default ) ( globalClasses . list , globalClasses . listDropdown ) ;
return ( 0 , _utils . strToEl ) ( "\n <div\n class=\"" . concat ( localClasses , "\"\n aria-expanded=\"false\"\n >\n </div>\n " ) ) ;
} ,
notice : function notice ( globalClasses , label ) {
var _classNames6 ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var type = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : '' ;
var localClasses = ( 0 , _classnames . default ) ( globalClasses . item , globalClasses . itemChoice , ( _classNames6 = { } , _defineProperty ( _classNames6 , globalClasses . noResults , type === 'no-results' ) , _defineProperty ( _classNames6 , globalClasses . noChoices , type === 'no-choices' ) , _classNames6 ) ) ;
return ( 0 , _utils . strToEl ) ( "\n <div class=\"" . concat ( localClasses , "\">\n " ) . concat ( label , "\n </div>\n " ) ) ;
} ,
option : function option ( data ) {
2019-02-11 18:52:22 +01:00
return ( 0 , _utils . strToEl ) ( "\n <option value=\"" . concat ( data . value , "\" " ) . concat ( data . active ? 'selected' : '' , " " ) . concat ( data . disabled ? 'disabled' : '' , " " ) . concat ( data . customProperties ? "data-custom-properties=" . concat ( data . customProperties ) : '' , ">" ) . concat ( data . label , "</option>\n " ) ) ;
2018-05-25 15:00:27 +02:00
}
} ;
2019-02-09 19:13:25 +01:00
exports . TEMPLATES = TEMPLATES ;
var _default = TEMPLATES ;
exports . default = _default ;
2018-05-25 15:00:27 +02:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 6 */
2018-05-25 15:00:27 +02:00
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
2019-02-09 19:13:25 +01:00
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
2018-05-25 15:00:27 +02:00
// EXTERNAL MODULE: ./node_modules/lodash-es/_freeGlobal.js
2019-02-09 19:13:25 +01:00
var _freeGlobal = _ _webpack _require _ _ ( 8 ) ;
2018-05-25 15:00:27 +02:00
// CONCATENATED MODULE: ./node_modules/lodash-es/_root.js
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self . Object === Object && self ;
/** Used as a reference to the global object. */
var root = _freeGlobal [ "a" /* default */ ] || freeSelf || Function ( 'return this' ) ( ) ;
/* harmony default export */ var _root = ( root ) ;
// CONCATENATED MODULE: ./node_modules/lodash-es/_Symbol.js
/** Built-in value references. */
var Symbol = _root . Symbol ;
/* harmony default export */ var _Symbol = ( Symbol ) ;
// CONCATENATED MODULE: ./node_modules/lodash-es/_getRawTag.js
/** Used for built-in method references. */
var objectProto = Object . prototype ;
/** Used to check objects for own properties. */
var _getRawTag _hasOwnProperty = objectProto . hasOwnProperty ;
/ * *
* Used to resolve the
* [ ` toStringTag ` ] ( http : //ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values .
* /
var nativeObjectToString = objectProto . toString ;
/** Built-in value references. */
var symToStringTag = _Symbol ? _Symbol . toStringTag : undefined ;
/ * *
* A specialized version of ` baseGetTag ` which ignores ` Symbol.toStringTag ` values .
*
* @ private
* @ param { * } value The value to query .
* @ returns { string } Returns the raw ` toStringTag ` .
* /
function getRawTag ( value ) {
var isOwn = _getRawTag _hasOwnProperty . call ( value , symToStringTag ) ,
tag = value [ symToStringTag ] ;
try {
value [ symToStringTag ] = undefined ;
var unmasked = true ;
} catch ( e ) { }
var result = nativeObjectToString . call ( value ) ;
if ( unmasked ) {
if ( isOwn ) {
value [ symToStringTag ] = tag ;
} else {
delete value [ symToStringTag ] ;
}
}
return result ;
}
/* harmony default export */ var _getRawTag = ( getRawTag ) ;
// CONCATENATED MODULE: ./node_modules/lodash-es/_objectToString.js
/** Used for built-in method references. */
var _objectToString _objectProto = Object . prototype ;
/ * *
* Used to resolve the
* [ ` toStringTag ` ] ( http : //ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values .
* /
var _objectToString _nativeObjectToString = _objectToString _objectProto . toString ;
/ * *
* Converts ` value ` to a string using ` Object.prototype.toString ` .
*
* @ private
* @ param { * } value The value to convert .
* @ returns { string } Returns the converted string .
* /
function objectToString ( value ) {
return _objectToString _nativeObjectToString . call ( value ) ;
}
/* harmony default export */ var _objectToString = ( objectToString ) ;
// CONCATENATED MODULE: ./node_modules/lodash-es/_baseGetTag.js
/** `Object#toString` result references. */
var nullTag = '[object Null]' ,
undefinedTag = '[object Undefined]' ;
/** Built-in value references. */
var _baseGetTag _symToStringTag = _Symbol ? _Symbol . toStringTag : undefined ;
/ * *
* The base implementation of ` getTag ` without fallbacks for buggy environments .
*
* @ private
2017-11-15 07:51:53 +01:00
* @ param { * } value The value to query .
* @ returns { string } Returns the ` toStringTag ` .
* /
function baseGetTag ( value ) {
if ( value == null ) {
return value === undefined ? undefinedTag : nullTag ;
}
return ( _baseGetTag _symToStringTag && _baseGetTag _symToStringTag in Object ( value ) )
? _getRawTag ( value )
: _objectToString ( value ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/* harmony default export */ var _baseGetTag = ( baseGetTag ) ;
2017-11-07 12:59:49 +01:00
2017-11-20 13:59:12 +01:00
// CONCATENATED MODULE: ./node_modules/lodash-es/_overArg.js
2017-11-15 07:51:53 +01:00
/ * *
* Creates a unary function that invokes ` func ` with its argument transformed .
*
* @ private
* @ param { Function } func The function to wrap .
* @ param { Function } transform The argument transform .
* @ returns { Function } Returns the new function .
* /
function overArg ( func , transform ) {
return function ( arg ) {
return func ( transform ( arg ) ) ;
} ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/* harmony default export */ var _overArg = ( overArg ) ;
2017-11-13 20:13:37 +01:00
2017-11-20 13:59:12 +01:00
// CONCATENATED MODULE: ./node_modules/lodash-es/_getPrototype.js
2017-11-13 20:13:37 +01:00
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/** Built-in value references. */
var getPrototype = _overArg ( Object . getPrototypeOf , Object ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/* harmony default export */ var _getPrototype = ( getPrototype ) ;
2017-11-13 20:13:37 +01:00
2017-11-20 13:59:12 +01:00
// CONCATENATED MODULE: ./node_modules/lodash-es/isObjectLike.js
2017-11-15 07:51:53 +01:00
/ * *
* Checks if ` value ` is object - like . A value is object - like if it ' s not ` null `
* and has a ` typeof ` result of "object" .
*
* @ static
* @ memberOf _
* @ since 4.0 . 0
* @ category Lang
* @ param { * } value The value to check .
* @ returns { boolean } Returns ` true ` if ` value ` is object - like , else ` false ` .
* @ example
*
* _ . isObjectLike ( { } ) ;
* // => true
*
* _ . isObjectLike ( [ 1 , 2 , 3 ] ) ;
* // => true
*
* _ . isObjectLike ( _ . noop ) ;
* // => false
*
* _ . isObjectLike ( null ) ;
* // => false
* /
function isObjectLike ( value ) {
return value != null && typeof value == 'object' ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/* harmony default export */ var lodash _es _isObjectLike = ( isObjectLike ) ;
2017-11-07 12:59:49 +01:00
2017-11-20 13:59:12 +01:00
// CONCATENATED MODULE: ./node_modules/lodash-es/isPlainObject.js
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/** `Object#toString` result references. */
var objectTag = '[object Object]' ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/** Used for built-in method references. */
var funcProto = Function . prototype ,
isPlainObject _objectProto = Object . prototype ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto . toString ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/** Used to check objects for own properties. */
var isPlainObject _hasOwnProperty = isPlainObject _objectProto . hasOwnProperty ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/** Used to infer the `Object` constructor. */
var objectCtorString = funcToString . call ( Object ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Checks if ` value ` is a plain object , that is , an object created by the
* ` Object ` constructor or one with a ` [[Prototype]] ` of ` null ` .
*
* @ static
* @ memberOf _
* @ since 0.8 . 0
* @ category Lang
* @ param { * } value The value to check .
* @ returns { boolean } Returns ` true ` if ` value ` is a plain object , else ` false ` .
* @ example
*
* function Foo ( ) {
* this . a = 1 ;
* }
*
* _ . isPlainObject ( new Foo ) ;
* // => false
*
* _ . isPlainObject ( [ 1 , 2 , 3 ] ) ;
* // => false
*
* _ . isPlainObject ( { 'x' : 0 , 'y' : 0 } ) ;
* // => true
*
* _ . isPlainObject ( Object . create ( null ) ) ;
* // => true
* /
function isPlainObject ( value ) {
if ( ! lodash _es _isObjectLike ( value ) || _baseGetTag ( value ) != objectTag ) {
return false ;
}
var proto = _getPrototype ( value ) ;
if ( proto === null ) {
return true ;
}
var Ctor = isPlainObject _hasOwnProperty . call ( proto , 'constructor' ) && proto . constructor ;
return typeof Ctor == 'function' && Ctor instanceof Ctor &&
funcToString . call ( Ctor ) == objectCtorString ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/* harmony default export */ var lodash _es _isPlainObject = ( isPlainObject ) ;
2017-11-07 12:59:49 +01:00
2018-06-07 17:54:11 +02:00
// EXTERNAL MODULE: ./node_modules/symbol-observable/es/index.js
2019-02-09 19:13:25 +01:00
var es = _ _webpack _require _ _ ( 2 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// CONCATENATED MODULE: ./node_modules/redux/es/createStore.js
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +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 ActionTypes = {
INIT : '@@redux/INIT'
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* 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 _createStore ( reducer , preloadedState , enhancer ) {
var _ref2 ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( typeof preloadedState === 'function' && typeof enhancer === 'undefined' ) {
enhancer = preloadedState ;
preloadedState = undefined ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
if ( typeof enhancer !== 'undefined' ) {
if ( typeof enhancer !== 'function' ) {
throw new Error ( 'Expected the enhancer to be a function.' ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return enhancer ( createStore _createStore ) ( reducer , preloadedState ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( typeof reducer !== 'function' ) {
throw new Error ( 'Expected the reducer to be a function.' ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
var currentReducer = reducer ;
var currentState = preloadedState ;
var currentListeners = [ ] ;
var nextListeners = currentListeners ;
var isDispatching = false ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function ensureCanMutateNextListeners ( ) {
if ( nextListeners === currentListeners ) {
nextListeners = currentListeners . slice ( ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Reads the state tree managed by the store .
*
* @ returns { any } The current state tree of your application .
* /
function getState ( ) {
return currentState ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* 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 ( 'Expected listener to be a function.' ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var isSubscribed = true ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
ensureCanMutateNextListeners ( ) ;
nextListeners . push ( listener ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return function unsubscribe ( ) {
if ( ! isSubscribed ) {
return ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
isSubscribed = false ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
ensureCanMutateNextListeners ( ) ;
var index = nextListeners . indexOf ( listener ) ;
nextListeners . splice ( index , 1 ) ;
} ;
2017-11-07 12:59:49 +01:00
}
2017-11-13 20:13:37 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* 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 ) .
2017-11-13 20:13:37 +01:00
* /
2017-11-15 07:51:53 +01:00
function dispatch ( action ) {
if ( ! lodash _es _isPlainObject ( action ) ) {
throw new Error ( 'Actions must be plain objects. ' + 'Use custom middleware for async actions.' ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( typeof action . type === 'undefined' ) {
throw new Error ( 'Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?' ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( isDispatching ) {
throw new Error ( 'Reducers may not dispatch actions.' ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
try {
isDispatching = true ;
currentState = currentReducer ( currentState , action ) ;
} finally {
isDispatching = false ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var listeners = currentListeners = nextListeners ;
for ( var i = 0 ; i < listeners . length ; i ++ ) {
var listener = listeners [ i ] ;
listener ( ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
return action ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* 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 ( 'Expected the nextReducer to be a function.' ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
currentReducer = nextReducer ;
dispatch ( { type : ActionTypes . INIT } ) ;
}
/ * *
* 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' ) {
throw new TypeError ( 'Expected the observer to be an object.' ) ;
}
function observeState ( ) {
if ( observer . next ) {
observer . next ( getState ( ) ) ;
}
}
observeState ( ) ;
var unsubscribe = outerSubscribe ( observeState ) ;
return { unsubscribe : unsubscribe } ;
}
2018-06-07 17:54:11 +02:00
} , _ref [ es [ "a" /* default */ ] ] = function ( ) {
2017-11-15 07:51:53 +01:00
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
2018-06-07 17:54:11 +02:00
} , _ref2 [ es [ "a" /* default */ ] ] = observable , _ref2 ;
2017-11-15 07:51:53 +01:00
}
// CONCATENATED MODULE: ./node_modules/redux/es/utils/warning.js
/ * *
* Prints a warning in the console if it exists .
*
* @ param { String } message The warning message .
* @ returns { void }
* /
2019-02-09 19:13:25 +01:00
function warning ( message ) {
2017-11-15 07:51:53 +01:00
/* 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 ) ;
/* eslint-disable no-empty */
} catch ( e ) { }
/* eslint-enable no-empty */
}
// CONCATENATED MODULE: ./node_modules/redux/es/combineReducers.js
2017-11-13 20:13:37 +01:00
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function getUndefinedStateErrorMessage ( key , action ) {
var actionType = action && action . type ;
var actionName = actionType && '"' + actionType . toString ( ) + '"' || 'an action' ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return 'Given action ' + actionName + ', reducer "' + key + '" returned undefined. ' + 'To ignore an action, you must explicitly return the previous state. ' + 'If you want this reducer to hold no value, you can return null instead of undefined.' ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
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' ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
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.' ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! lodash _es _isPlainObject ( inputState ) ) {
return 'The ' + argumentName + ' has unexpected type of "' + { } . toString . call ( inputState ) . match ( /\s([a-z|A-Z]+)/ ) [ 1 ] + '". Expected argument to be an object with the following ' + ( 'keys: "' + reducerKeys . join ( '", "' ) + '"' ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var unexpectedKeys = Object . keys ( inputState ) . filter ( function ( key ) {
return ! reducers . hasOwnProperty ( key ) && ! unexpectedKeyCache [ key ] ;
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
unexpectedKeys . forEach ( function ( key ) {
unexpectedKeyCache [ key ] = true ;
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
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.' ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function assertReducerShape ( reducers ) {
Object . keys ( reducers ) . forEach ( function ( key ) {
var reducer = reducers [ key ] ;
var initialState = reducer ( undefined , { type : ActionTypes . INIT } ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( typeof initialState === 'undefined' ) {
throw new Error ( 'Reducer "' + key + '" returned undefined during initialization. ' + 'If the state passed to the reducer is undefined, you must ' + 'explicitly return the initial state. The initial state may ' + 'not be undefined. If you don\'t want to set a value for this reducer, ' + 'you can use null instead of undefined.' ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) . split ( '' ) . join ( '.' ) ;
if ( typeof reducer ( undefined , { type : type } ) === 'undefined' ) {
throw new Error ( 'Reducer "' + key + '" returned undefined when probed with a random type. ' + ( 'Don\'t try to handle ' + ActionTypes . INIT + ' or other actions in "redux/*" ' ) + 'namespace. They are considered private. Instead, you must return the ' + 'current state for any unknown actions, unless it is undefined, ' + 'in which case you must return the initial state, regardless of the ' + 'action type. The initial state may not be undefined, but can be null.' ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* 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 ] ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
if ( false ) { }
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( typeof reducers [ key ] === 'function' ) {
finalReducers [ key ] = reducers [ key ] ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
}
var finalReducerKeys = Object . keys ( finalReducers ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var unexpectedKeyCache = void 0 ;
2019-02-09 19:13:25 +01:00
if ( false ) { }
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var shapeAssertionError = void 0 ;
try {
assertReducerShape ( finalReducers ) ;
} catch ( e ) {
shapeAssertionError = e ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
return function combination ( ) {
var state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
var action = arguments [ 1 ] ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
if ( shapeAssertionError ) {
throw shapeAssertionError ;
}
2016-08-23 08:24:45 +02:00
2019-02-09 19:13:25 +01:00
if ( false ) { var warningMessage ; }
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
var hasChanged = false ;
var nextState = { } ;
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 ) ;
if ( typeof nextStateForKey === 'undefined' ) {
var errorMessage = getUndefinedStateErrorMessage ( _key , action ) ;
throw new Error ( errorMessage ) ;
}
nextState [ _key ] = nextStateForKey ;
hasChanged = hasChanged || nextStateForKey !== previousStateForKey ;
}
return hasChanged ? nextState : state ;
} ;
}
// CONCATENATED MODULE: ./node_modules/redux/es/bindActionCreators.js
function bindActionCreator ( actionCreator , dispatch ) {
return function ( ) {
return dispatch ( actionCreator . apply ( undefined , arguments ) ) ;
} ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +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 a single function as the first argument ,
* and get a 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 .
* /
function bindActionCreators ( actionCreators , dispatch ) {
if ( typeof actionCreators === 'function' ) {
return bindActionCreator ( actionCreators , dispatch ) ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
if ( typeof actionCreators !== 'object' || actionCreators === null ) {
throw new Error ( 'bindActionCreators expected an object or a function, instead received ' + ( actionCreators === null ? 'null' : typeof actionCreators ) + '. ' + 'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?' ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var keys = Object . keys ( actionCreators ) ;
var boundActionCreators = { } ;
for ( var i = 0 ; i < keys . length ; i ++ ) {
var key = keys [ i ] ;
var actionCreator = actionCreators [ key ] ;
if ( typeof actionCreator === 'function' ) {
boundActionCreators [ key ] = bindActionCreator ( actionCreator , dispatch ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
}
return boundActionCreators ;
}
// CONCATENATED MODULE: ./node_modules/redux/es/compose.js
/ * *
* 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 ) ) ) .
* /
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
function compose ( ) {
for ( var _len = arguments . length , funcs = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
funcs [ _key ] = arguments [ _key ] ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( funcs . length === 0 ) {
return function ( arg ) {
return arg ;
} ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( funcs . length === 1 ) {
return funcs [ 0 ] ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return funcs . reduce ( function ( a , b ) {
return function ( ) {
return a ( b . apply ( undefined , arguments ) ) ;
} ;
} ) ;
}
// CONCATENATED MODULE: ./node_modules/redux/es/applyMiddleware.js
var _extends = Object . assign || function ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] ; for ( var key in source ) { if ( Object . prototype . hasOwnProperty . call ( source , key ) ) { target [ key ] = source [ key ] ; } } } return target ; } ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +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 .
* /
function applyMiddleware ( ) {
for ( var _len = arguments . length , middlewares = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
middlewares [ _key ] = arguments [ _key ] ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
return function ( createStore ) {
return function ( reducer , preloadedState , enhancer ) {
var store = createStore ( reducer , preloadedState , enhancer ) ;
var _dispatch = store . dispatch ;
var chain = [ ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var middlewareAPI = {
getState : store . getState ,
dispatch : function dispatch ( action ) {
return _dispatch ( action ) ;
}
} ;
chain = middlewares . map ( function ( middleware ) {
return middleware ( middlewareAPI ) ;
} ) ;
_dispatch = compose . apply ( undefined , chain ) ( store . dispatch ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
return _extends ( { } , store , {
dispatch : _dispatch
} ) ;
} ;
} ;
}
// CONCATENATED MODULE: ./node_modules/redux/es/index.js
2019-02-09 19:13:25 +01:00
/* concated harmony reexport createStore */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "createStore" , function ( ) { return createStore _createStore ; } ) ;
/* concated harmony reexport combineReducers */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "combineReducers" , function ( ) { return combineReducers ; } ) ;
/* concated harmony reexport bindActionCreators */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "bindActionCreators" , function ( ) { return bindActionCreators ; } ) ;
/* concated harmony reexport applyMiddleware */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "applyMiddleware" , function ( ) { return applyMiddleware ; } ) ;
/* concated harmony reexport compose */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "compose" , function ( ) { return compose ; } ) ;
2017-11-13 20:13:37 +01:00
2017-11-07 12:59:49 +01:00
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +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 ( ) { }
2016-08-23 08:24:45 +02:00
2019-02-09 19:13:25 +01:00
if ( false ) { }
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 7 */
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
2019-01-26 13:36:47 +01:00
2019-02-09 19:13:25 +01:00
"use strict" ;
/* harmony export (binding) */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "a" , function ( ) { return symbolObservablePonyfill ; } ) ;
function symbolObservablePonyfill ( root ) {
var result ;
var Symbol = root . Symbol ;
2019-01-26 13:36:47 +01:00
2019-02-09 19:13:25 +01:00
if ( typeof Symbol === 'function' ) {
if ( Symbol . observable ) {
result = Symbol . observable ;
} else {
result = Symbol ( 'observable' ) ;
Symbol . observable = result ;
}
} else {
result = '@@observable' ;
}
2019-01-26 13:36:47 +01:00
2019-02-09 19:13:25 +01:00
return result ;
} ;
2016-08-23 08:24:45 +02:00
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 8 */
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2019-02-09 19:13:25 +01:00
/* WEBPACK VAR INJECTION */ ( function ( global ) { /** Detect free variable `global` from Node.js. */
var freeGlobal = typeof global == 'object' && global && global . Object === Object && global ;
2017-02-17 10:26:08 +01:00
2019-02-09 19:13:25 +01:00
/* harmony default export */ _ _webpack _exports _ _ [ "a" ] = ( freeGlobal ) ;
2017-02-17 10:26:08 +01:00
2019-02-09 19:13:25 +01:00
/* WEBPACK VAR INJECTION */ } . call ( this , _ _webpack _require _ _ ( 3 ) ) )
2017-02-17 10:26:08 +01:00
2019-02-09 19:13:25 +01:00
/***/ } ) ,
/* 9 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-02-17 10:26:08 +01:00
2019-02-09 19:13:25 +01:00
module . exports = _ _webpack _require _ _ ( 10 ) ;
2017-02-17 10:26:08 +01:00
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
/***/ } ) ,
/* 10 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-02-17 10:26:08 +01:00
2019-02-09 19:13:25 +01:00
"use strict" ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var _fuse = _interopRequireDefault ( _ _webpack _require _ _ ( 11 ) ) ;
2017-02-17 10:26:08 +01:00
2019-02-09 19:13:25 +01:00
var _deepmerge = _interopRequireDefault ( _ _webpack _require _ _ ( 12 ) ) ;
2017-02-17 10:26:08 +01:00
2019-02-09 19:13:25 +01:00
_ _webpack _require _ _ ( 13 ) ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _store = _interopRequireDefault ( _ _webpack _require _ _ ( 15 ) ) ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _components = _ _webpack _require _ _ ( 22 ) ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _constants = _ _webpack _require _ _ ( 1 ) ;
2017-02-17 10:26:08 +01:00
2019-02-09 19:13:25 +01:00
var _templates = _ _webpack _require _ _ ( 5 ) ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _choices = _ _webpack _require _ _ ( 30 ) ;
2017-02-17 10:26:08 +01:00
2019-02-09 19:13:25 +01:00
var _items = _ _webpack _require _ _ ( 31 ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _groups = _ _webpack _require _ _ ( 32 ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _misc = _ _webpack _require _ _ ( 33 ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _general = _ _webpack _require _ _ ( 34 ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Choices
2018-05-27 12:57:21 +02:00
* @ author Josh Johnson < josh @ joshuajohnson . co . uk >
2017-11-13 20:13:37 +01:00
* /
2019-02-09 19:13:25 +01:00
var Choices =
/*#__PURE__*/
function ( ) {
2017-11-15 07:51:53 +01:00
function Choices ( ) {
var element = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : '[data-choice]' ;
var userConfig = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
_classCallCheck ( this , Choices ) ;
if ( ( 0 , _utils . isType ) ( 'String' , element ) ) {
2019-02-09 19:13:25 +01:00
var elements = Array . from ( document . querySelectorAll ( element ) ) ; // If there are multiple elements, create a new instance
2018-05-25 15:00:27 +02:00
// for each element besides the first one (as that already has an instance)
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( elements . length > 1 ) {
2018-05-25 15:00:27 +02:00
return this . _generateInstances ( elements , userConfig ) ;
2017-11-15 07:51:53 +01:00
}
}
2019-02-09 19:13:25 +01:00
this . config = _deepmerge . default . all ( [ _constants . DEFAULT _CONFIG , Choices . userDefaults , userConfig ] , // When merging array configs, replace with a copy of the userConfig array,
2019-01-24 20:42:26 +01:00
// instead of concatenating with the default array
2019-02-09 19:13:25 +01:00
{
arrayMerge : function arrayMerge ( destinationArray , sourceArray ) {
return [ ] . concat ( sourceArray ) ;
}
} ) ;
2018-10-13 12:19:24 +02:00
if ( ! ( 0 , _utils . doKeysMatch ) ( this . config , _constants . DEFAULT _CONFIG ) ) {
console . warn ( 'Unknown config option(s) passed' ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! [ 'auto' , 'always' ] . includes ( this . config . renderSelectedChoices ) ) {
this . config . renderSelectedChoices = 'auto' ;
2019-02-09 19:13:25 +01:00
} // Retrieve triggering element (i.e. element with 'data-choice' trigger)
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var passedElement = ( 0 , _utils . isType ) ( 'String' , element ) ? document . querySelector ( element ) : element ;
2017-11-07 12:59:49 +01:00
2018-10-13 12:19:24 +02:00
if ( ! passedElement ) {
return console . error ( 'Could not find passed element or passed element was of an invalid type' ) ;
}
2018-05-25 15:00:27 +02:00
this . _isTextElement = passedElement . type === 'text' ;
this . _isSelectOneElement = passedElement . type === 'select-one' ;
this . _isSelectMultipleElement = passedElement . type === 'select-multiple' ;
this . _isSelectElement = this . _isSelectOneElement || this . _isSelectMultipleElement ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( this . _isTextElement ) {
this . passedElement = new _components . WrappedInput ( {
element : passedElement ,
classNames : this . config . classNames ,
delimiter : this . config . delimiter
} ) ;
} else if ( this . _isSelectElement ) {
this . passedElement = new _components . WrappedSelect ( {
element : passedElement ,
classNames : this . config . classNames
} ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2019-01-24 20:42:26 +01:00
if ( ! this . passedElement ) {
2018-10-13 12:19:24 +02:00
return console . error ( 'Passed element was of an invalid type' ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( this . config . shouldSortItems === true && this . _isSelectOneElement && ! this . config . silent ) {
2018-05-28 16:13:55 +02:00
console . warn ( "shouldSortElements: Type of passed element is 'select-one', falling back to false." ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2018-05-27 12:57:21 +02:00
this . initialised = false ;
2019-02-09 19:13:25 +01:00
this . _store = new _store . default ( this . render ) ;
2018-05-28 17:22:22 +02:00
this . _initialState = { } ;
2018-05-27 12:57:21 +02:00
this . _currentState = { } ;
this . _prevState = { } ;
this . _currentValue = '' ;
2018-05-29 16:47:45 +02:00
this . _canSearch = this . config . searchEnabled ;
2018-05-27 12:57:21 +02:00
this . _isScrollingOnIe = false ;
2018-05-25 15:00:27 +02:00
this . _highlightPosition = 0 ;
2018-05-27 12:57:21 +02:00
this . _wasTap = true ;
2018-05-25 15:00:27 +02:00
this . _placeholderValue = this . _generatePlaceholderValue ( ) ;
2018-05-27 12:57:21 +02:00
this . _baseId = ( 0 , _utils . generateId ) ( this . passedElement . element , 'choices-' ) ;
2018-06-07 17:54:11 +02:00
this . _direction = this . passedElement . element . getAttribute ( 'dir' ) || 'ltr' ;
2018-05-27 12:57:21 +02:00
this . _idNames = {
itemChoice : 'item-choice'
2019-02-09 19:13:25 +01:00
} ; // Assign preset choices from passed object
this . _presetChoices = this . config . choices ; // Assign preset items from passed object first
this . _presetItems = this . config . items ; // Then add any values passed from attribute
2018-04-25 10:20:59 +02:00
if ( this . passedElement . value ) {
2018-05-25 15:00:27 +02:00
this . _presetItems = this . _presetItems . concat ( this . passedElement . value . split ( this . config . delimiter ) ) ;
2017-11-15 07:51:53 +01:00
}
2018-10-13 12:19:24 +02:00
this . _render = this . _render . bind ( this ) ;
2017-11-15 07:51:53 +01:00
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 ) ;
2018-05-28 17:22:22 +02:00
this . _onFormReset = this . _onFormReset . bind ( this ) ;
2018-10-13 12:19:24 +02:00
this . _onAKey = this . _onAKey . bind ( this ) ;
this . _onEnterKey = this . _onEnterKey . bind ( this ) ;
this . _onEscapeKey = this . _onEscapeKey . bind ( this ) ;
this . _onDirectionKey = this . _onDirectionKey . bind ( this ) ;
2019-02-09 19:13:25 +01:00
this . _onDeleteKey = this . _onDeleteKey . bind ( this ) ; // If element has already been initialised with Choices, fail silently
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( this . passedElement . element . getAttribute ( 'data-choice' ) === 'active' ) {
2018-05-29 16:47:45 +02:00
console . warn ( 'Trying to initialise Choices on element already initialised' ) ;
2019-02-09 19:13:25 +01:00
} // Let's go
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
this . init ( ) ;
2017-11-15 07:51:53 +01:00
}
/ * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= Public functions =
=== === === === === === === === === === === === === = * /
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
_createClass ( Choices , [ {
2019-02-09 19:13:25 +01:00
key : "init" ,
2017-11-15 07:51:53 +01:00
value : function init ( ) {
if ( this . initialised ) {
return ;
}
this . _createTemplates ( ) ;
2019-02-09 19:13:25 +01:00
2018-04-25 10:20:59 +02:00
this . _createElements ( ) ;
2018-10-30 23:10:21 +01:00
2019-02-09 19:13:25 +01:00
this . _createStructure ( ) ; // Set initial state (We need to clone the state because some reducers
2018-05-28 17:22:22 +02:00
// modify the inner objects properties in the state) 🤢
2019-02-09 19:13:25 +01:00
2018-05-28 17:22:22 +02:00
this . _initialState = ( 0 , _utils . cloneObject ) ( this . _store . state ) ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
this . _store . subscribe ( this . _render ) ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
this . _render ( ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . _addEventListeners ( ) ;
2018-10-13 12:19:24 +02:00
2018-10-30 23:10:21 +01:00
var shouldDisable = ! this . config . addItems || this . passedElement . element . hasAttribute ( 'disabled' ) ;
if ( shouldDisable ) {
this . disable ( ) ;
}
2018-05-29 16:47:45 +02:00
this . initialised = true ;
2019-02-09 19:13:25 +01:00
var callbackOnInit = this . config . callbackOnInit ; // Run callback if it is a function
2018-05-25 15:00:27 +02:00
if ( callbackOnInit && ( 0 , _utils . isType ) ( 'Function' , callbackOnInit ) ) {
callbackOnInit . call ( this ) ;
2017-11-15 07:51:53 +01:00
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "destroy" ,
2017-11-15 07:51:53 +01:00
value : function destroy ( ) {
if ( ! this . initialised ) {
return ;
}
this . _removeEventListeners ( ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . passedElement . reveal ( ) ;
2018-02-02 12:08:03 +01:00
this . containerOuter . unwrap ( this . passedElement . element ) ;
2018-05-25 15:00:27 +02:00
if ( this . _isSelectElement ) {
this . passedElement . options = this . _presetChoices ;
2018-02-02 12:08:03 +01:00
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
this . clearStore ( ) ;
this . config . templates = null ;
this . initialised = false ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "enable" ,
2017-11-15 07:51:53 +01:00
value : function enable ( ) {
2018-10-27 21:18:23 +02:00
if ( this . passedElement . isDisabled ) {
this . passedElement . enable ( ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . containerOuter . isDisabled ) {
this . _addEventListeners ( ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . input . enable ( ) ;
this . containerOuter . enable ( ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return this ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "disable" ,
2017-11-15 07:51:53 +01:00
value : function disable ( ) {
2018-10-27 21:18:23 +02:00
if ( ! this . passedElement . isDisabled ) {
this . passedElement . disable ( ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! this . containerOuter . isDisabled ) {
this . _removeEventListeners ( ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . input . disable ( ) ;
this . containerOuter . disable ( ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return this ;
}
2017-11-13 20:13:37 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "highlightItem" ,
2017-11-15 07:51:53 +01:00
value : function highlightItem ( item ) {
var runEvent = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : true ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! item ) {
return this ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var id = item . id ,
_item$groupId = item . groupId ,
2019-02-09 19:13:25 +01:00
groupId = _item$groupId === void 0 ? - 1 : _item$groupId ,
2017-11-15 07:51:53 +01:00
_item$value = item . value ,
2019-02-09 19:13:25 +01:00
value = _item$value === void 0 ? '' : _item$value ,
2017-11-15 07:51:53 +01:00
_item$label = item . label ,
2019-02-09 19:13:25 +01:00
label = _item$label === void 0 ? '' : _item$label ;
2018-05-25 15:00:27 +02:00
var group = groupId >= 0 ? this . _store . getGroupById ( groupId ) : null ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( ( 0 , _items . highlightItem ) ( id , true ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( runEvent ) {
this . passedElement . triggerEvent ( _constants . EVENTS . highlightItem , {
id : id ,
value : value ,
label : label ,
groupValue : group && group . value ? group . value : null
} ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return this ;
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "unhighlightItem" ,
2017-11-15 07:51:53 +01:00
value : function unhighlightItem ( item ) {
if ( ! item ) {
return this ;
}
var id = item . id ,
_item$groupId2 = item . groupId ,
2019-02-09 19:13:25 +01:00
groupId = _item$groupId2 === void 0 ? - 1 : _item$groupId2 ,
2017-11-15 07:51:53 +01:00
_item$value2 = item . value ,
2019-02-09 19:13:25 +01:00
value = _item$value2 === void 0 ? '' : _item$value2 ,
2017-11-15 07:51:53 +01:00
_item$label2 = item . label ,
2019-02-09 19:13:25 +01:00
label = _item$label2 === void 0 ? '' : _item$label2 ;
2018-05-25 15:00:27 +02:00
var group = groupId >= 0 ? this . _store . getGroupById ( groupId ) : null ;
2017-11-15 07:51:53 +01:00
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( ( 0 , _items . highlightItem ) ( id , false ) ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . passedElement . triggerEvent ( _constants . EVENTS . highlightItem , {
id : id ,
value : value ,
label : label ,
groupValue : group && group . value ? group . value : null
} ) ;
return this ;
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "highlightAll" ,
2017-11-15 07:51:53 +01:00
value : function highlightAll ( ) {
2018-05-25 15:00:27 +02:00
var _this = this ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
this . _store . items . forEach ( function ( item ) {
return _this . highlightItem ( item ) ;
2017-11-15 07:51:53 +01:00
} ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return this ;
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "unhighlightAll" ,
2017-11-15 07:51:53 +01:00
value : function unhighlightAll ( ) {
2018-05-25 15:00:27 +02:00
var _this2 = this ;
2017-11-15 07:51:53 +01:00
2018-05-25 15:00:27 +02:00
this . _store . items . forEach ( function ( item ) {
return _this2 . unhighlightItem ( item ) ;
2017-11-15 07:51:53 +01:00
} ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return this ;
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "removeActiveItemsByValue" ,
2017-11-21 15:10:29 +01:00
value : function removeActiveItemsByValue ( value ) {
2018-05-25 15:00:27 +02:00
var _this3 = this ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
this . _store . activeItems . filter ( function ( item ) {
return item . value === value ;
} ) . forEach ( function ( item ) {
return _this3 . _removeItem ( item ) ;
2017-11-15 07:51:53 +01:00
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return this ;
}
2017-11-13 20:13:37 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "removeActiveItems" ,
2017-11-15 07:51:53 +01:00
value : function removeActiveItems ( excludedId ) {
2018-05-25 15:00:27 +02:00
var _this4 = this ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
this . _store . activeItems . filter ( function ( _ref ) {
var id = _ref . id ;
return id !== excludedId ;
} ) . forEach ( function ( item ) {
return _this4 . _removeItem ( item ) ;
2017-11-15 07:51:53 +01:00
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return this ;
2017-11-13 20:13:37 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "removeHighlightedItems" ,
2017-11-15 07:51:53 +01:00
value : function removeHighlightedItems ( ) {
2018-05-25 15:00:27 +02:00
var _this5 = this ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var runEvent = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : false ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
this . _store . highlightedActiveItems . forEach ( function ( item ) {
2019-02-09 19:13:25 +01:00
_this5 . _removeItem ( item ) ; // If this action was performed by the user
2018-02-02 12:08:03 +01:00
// trigger the event
2019-02-09 19:13:25 +01:00
2018-02-02 12:08:03 +01:00
if ( runEvent ) {
2018-05-25 15:00:27 +02:00
_this5 . _triggerChange ( item . value ) ;
2017-11-15 07:51:53 +01:00
}
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return this ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "showDropdown" ,
2018-05-29 16:08:43 +02:00
value : function showDropdown ( preventInputFocus ) {
2018-05-25 15:00:27 +02:00
var _this6 = this ;
2017-11-15 07:51:53 +01:00
if ( this . dropdown . isActive ) {
return this ;
}
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
requestAnimationFrame ( function ( ) {
_this6 . dropdown . show ( ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
_this6 . containerOuter . open ( _this6 . dropdown . distanceFromTopWindow ( ) ) ;
2018-02-02 12:08:03 +01:00
2018-05-29 16:47:45 +02:00
if ( ! preventInputFocus && _this6 . _canSearch ) {
2018-05-25 15:00:27 +02:00
_this6 . input . focus ( ) ;
}
2018-02-02 12:08:03 +01:00
2018-05-25 15:00:27 +02:00
_this6 . passedElement . triggerEvent ( _constants . EVENTS . showDropdown , { } ) ;
} ) ;
2017-11-15 07:51:53 +01:00
return this ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "hideDropdown" ,
2018-05-29 16:08:43 +02:00
value : function hideDropdown ( preventInputBlur ) {
2018-05-25 15:00:27 +02:00
var _this7 = this ;
2017-11-15 07:51:53 +01:00
if ( ! this . dropdown . isActive ) {
return this ;
}
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
requestAnimationFrame ( function ( ) {
_this7 . dropdown . hide ( ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
_this7 . containerOuter . close ( ) ;
2018-02-02 12:08:03 +01:00
2018-05-29 16:47:45 +02:00
if ( ! preventInputBlur && _this7 . _canSearch ) {
2018-05-25 15:00:27 +02:00
_this7 . input . removeActiveDescendant ( ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
_this7 . input . blur ( ) ;
}
2018-02-02 12:08:03 +01:00
2018-05-25 15:00:27 +02:00
_this7 . passedElement . triggerEvent ( _constants . EVENTS . hideDropdown , { } ) ;
} ) ;
2017-11-15 07:51:53 +01:00
return this ;
}
2017-11-13 20:13:37 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "toggleDropdown" ,
2017-11-15 07:51:53 +01:00
value : function toggleDropdown ( ) {
2018-05-29 16:47:45 +02:00
this . dropdown . isActive ? this . hideDropdown ( ) : this . showDropdown ( ) ;
2017-11-15 07:51:53 +01:00
return this ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "getValue" ,
2017-11-15 07:51:53 +01:00
value : function getValue ( ) {
var valueOnly = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : false ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
var values = this . _store . activeItems . reduce ( function ( selectedItems , item ) {
2017-11-15 07:51:53 +01:00
var itemValue = valueOnly ? item . value : item ;
selectedItems . push ( itemValue ) ;
return selectedItems ;
} , [ ] ) ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
return this . _isSelectOneElement ? values [ 0 ] : values ;
2017-11-15 07:51:53 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "setValue" ,
2017-11-15 07:51:53 +01:00
value : function setValue ( args ) {
2018-05-25 15:00:27 +02:00
var _this8 = this ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! this . initialised ) {
return this ;
}
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
[ ] . concat ( args ) . forEach ( function ( value ) {
2018-05-25 15:00:27 +02:00
return _this8 . _setChoiceOrItem ( value ) ;
2017-11-15 07:51:53 +01:00
} ) ;
return this ;
}
2017-11-13 20:13:37 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "setChoiceByValue" ,
2017-11-15 07:51:53 +01:00
value : function setChoiceByValue ( value ) {
2018-05-25 15:00:27 +02:00
var _this9 = this ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( ! this . initialised || this . _isTextElement ) {
2017-11-15 07:51:53 +01:00
return this ;
2019-02-09 19:13:25 +01:00
} // If only one value has been passed, convert to array
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var choiceValue = ( 0 , _utils . isType ) ( 'Array' , value ) ? value : [ value ] ; // Loop through each value and
2017-11-15 07:51:53 +01:00
choiceValue . forEach ( function ( val ) {
2018-05-25 15:00:27 +02:00
return _this9 . _findAndSelectChoiceByValue ( val ) ;
2017-11-15 07:51:53 +01:00
} ) ;
return this ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "setChoices" ,
2017-11-15 07:51:53 +01:00
value : function setChoices ( ) {
2018-05-25 15:00:27 +02:00
var _this10 = this ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var choices = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ;
var value = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : '' ;
2017-11-15 07:51:53 +01:00
var label = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : '' ;
var replaceChoices = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : false ;
2018-05-25 15:00:27 +02:00
if ( ! this . _isSelectElement || ! choices . length || ! value ) {
2017-11-15 07:51:53 +01:00
return this ;
2019-02-09 19:13:25 +01:00
} // Clear choices if needed
2017-11-15 07:51:53 +01:00
if ( replaceChoices ) {
this . _clearChoices ( ) ;
}
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
this . containerOuter . removeLoadingState ( ) ;
2019-02-09 19:13:25 +01:00
2018-02-02 12:08:03 +01:00
var addGroupsAndChoices = function addGroupsAndChoices ( groupOrChoice ) {
if ( groupOrChoice . choices ) {
2018-06-07 17:54:11 +02:00
_this10 . _addGroup ( {
group : groupOrChoice ,
id : groupOrChoice . id || null ,
valueKey : value ,
labelKey : label
} ) ;
2018-02-02 12:08:03 +01:00
} else {
2018-06-07 17:54:11 +02:00
_this10 . _addChoice ( {
value : groupOrChoice [ value ] ,
label : groupOrChoice [ label ] ,
isSelected : groupOrChoice . selected ,
isDisabled : groupOrChoice . disabled ,
customProperties : groupOrChoice . customProperties ,
placeholder : groupOrChoice . placeholder
} ) ;
2018-02-02 12:08:03 +01:00
}
} ;
2017-11-07 12:59:49 +01:00
2019-01-26 13:36:47 +01:00
this . _setLoading ( true ) ;
2019-02-09 19:13:25 +01:00
2018-02-02 12:08:03 +01:00
choices . forEach ( addGroupsAndChoices ) ;
2019-02-09 19:13:25 +01:00
2019-01-26 13:36:47 +01:00
this . _setLoading ( false ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return this ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "clearStore" ,
2017-11-15 07:51:53 +01:00
value : function clearStore ( ) {
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( ( 0 , _misc . clearAll ) ( ) ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return this ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "clearInput" ,
2017-11-15 07:51:53 +01:00
value : function clearInput ( ) {
2018-05-25 15:00:27 +02:00
var shouldSetInputWidth = ! this . _isSelectOneElement ;
2017-11-15 07:51:53 +01:00
this . input . clear ( shouldSetInputWidth ) ;
2017-11-07 12:59:49 +01:00
2018-05-29 16:47:45 +02:00
if ( ! this . _isTextElement && this . _canSearch ) {
2018-05-25 15:00:27 +02:00
this . _isSearching = false ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( ( 0 , _choices . activateChoices ) ( true ) ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return this ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "ajax" ,
2017-11-15 07:51:53 +01:00
value : function ajax ( fn ) {
2018-05-25 15:00:27 +02:00
var _this11 = this ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( ! this . initialised || ! this . _isSelectElement || ! fn ) {
2017-11-15 07:51:53 +01:00
return this ;
}
requestAnimationFrame ( function ( ) {
2018-05-25 15:00:27 +02:00
return _this11 . _handleLoadingState ( true ) ;
2017-11-15 07:51:53 +01:00
} ) ;
fn ( this . _ajaxCallback ( ) ) ;
return this ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
/* ===== End of Public functions ====== */
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= Private functions =
=== === === === === === === === === === === === === === === * /
2017-11-07 12:59:49 +01:00
2018-10-13 12:19:24 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "_render" ,
2018-10-13 12:19:24 +02:00
value : function _render ( ) {
2019-01-26 13:36:47 +01:00
if ( this . _store . isLoading ( ) ) {
return ;
}
2018-10-13 12:19:24 +02: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 ;
if ( ! stateChanged ) {
return ;
}
if ( shouldRenderChoices ) {
this . _renderChoices ( ) ;
}
if ( shouldRenderItems ) {
this . _renderItems ( ) ;
}
this . _prevState = this . _currentState ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_renderChoices" ,
2018-10-13 12:19:24 +02:00
value : function _renderChoices ( ) {
var _this12 = this ;
2019-02-09 19:13:25 +01:00
var _this$ _store = this . _store ,
activeGroups = _this$ _store . activeGroups ,
activeChoices = _this$ _store . activeChoices ;
2018-10-13 12:19:24 +02:00
var choiceListFragment = document . createDocumentFragment ( ) ;
this . choiceList . clear ( ) ;
if ( this . config . resetScrollPosition ) {
requestAnimationFrame ( function ( ) {
return _this12 . choiceList . scrollToTop ( ) ;
} ) ;
2019-02-09 19:13:25 +01:00
} // If we have grouped options
2018-10-13 12:19:24 +02: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-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
if ( activePlaceholders . length >= 1 ) {
choiceListFragment = this . _createChoicesFragment ( activePlaceholders , choiceListFragment ) ;
}
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
choiceListFragment = this . _createGroupsFragment ( activeGroups , activeChoices , choiceListFragment ) ;
} else if ( activeChoices . length >= 1 ) {
choiceListFragment = this . _createChoicesFragment ( activeChoices , choiceListFragment ) ;
2019-02-09 19:13:25 +01:00
} // If we have choices to show
2018-10-13 12:19:24 +02:00
if ( choiceListFragment . childNodes && choiceListFragment . childNodes . length > 0 ) {
var activeItems = this . _store . activeItems ;
2019-02-09 19:13:25 +01:00
var canAddItem = this . _canAddItem ( activeItems , this . input . value ) ; // ...and we can select them
2018-10-13 12:19:24 +02:00
if ( canAddItem . response ) {
// ...append them and highlight the first choice
this . choiceList . append ( choiceListFragment ) ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
this . _highlightChoice ( ) ;
} else {
// ...otherwise show a notice
this . choiceList . append ( this . _getTemplate ( 'notice' , canAddItem . notice ) ) ;
}
} else {
// Otherwise show a notice
2019-02-09 19:13:25 +01:00
var dropdownItem ;
var notice ;
2018-10-13 12:19:24 +02:00
if ( this . _isSearching ) {
notice = ( 0 , _utils . isType ) ( 'Function' , this . config . noResultsText ) ? this . config . noResultsText ( ) : this . config . noResultsText ;
dropdownItem = this . _getTemplate ( 'notice' , notice , 'no-results' ) ;
} else {
notice = ( 0 , _utils . isType ) ( 'Function' , this . config . noChoicesText ) ? this . config . noChoicesText ( ) : this . config . noChoicesText ;
dropdownItem = this . _getTemplate ( 'notice' , notice , 'no-choices' ) ;
}
this . choiceList . append ( dropdownItem ) ;
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_renderItems" ,
2018-10-13 12:19:24 +02:00
value : function _renderItems ( ) {
var activeItems = this . _store . activeItems || [ ] ;
2019-02-09 19:13:25 +01:00
this . itemList . clear ( ) ; // Create a fragment to store our list items
2018-10-18 23:22:22 +02:00
// (so we don't have to update the DOM for each item)
2018-10-13 12:19:24 +02:00
2019-02-09 19:13:25 +01:00
var itemListFragment = this . _createItemsFragment ( activeItems ) ; // If we have items to add, append them
2018-10-18 23:22:22 +02:00
if ( itemListFragment . childNodes ) {
this . itemList . append ( itemListFragment ) ;
2018-10-13 12:19:24 +02:00
}
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_createGroupsFragment" ,
2018-05-25 15:00:27 +02:00
value : function _createGroupsFragment ( groups , choices , fragment ) {
2018-10-13 12:19:24 +02:00
var _this13 = this ;
2018-05-25 15:00:27 +02:00
var groupFragment = fragment || document . createDocumentFragment ( ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
var getGroupChoices = function getGroupChoices ( group ) {
return choices . filter ( function ( choice ) {
2018-10-13 12:19:24 +02:00
if ( _this13 . _isSelectOneElement ) {
2018-05-25 15:00:27 +02:00
return choice . groupId === group . id ;
}
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
return choice . groupId === group . id && ( _this13 . config . renderSelectedChoices === 'always' || ! choice . selected ) ;
2018-05-25 15:00:27 +02:00
} ) ;
2019-02-09 19:13:25 +01:00
} ; // If sorting is enabled, filter groups
2018-05-25 15:00:27 +02:00
if ( this . config . shouldSort ) {
groups . sort ( this . config . sortFn ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
groups . forEach ( function ( group ) {
var groupChoices = getGroupChoices ( group ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
if ( groupChoices . length >= 1 ) {
2018-10-13 12:19:24 +02:00
var dropdownGroup = _this13 . _getTemplate ( 'choiceGroup' , group ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
groupFragment . appendChild ( dropdownGroup ) ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
_this13 . _createChoicesFragment ( groupChoices , groupFragment , true ) ;
2018-05-25 15:00:27 +02:00
}
2017-11-15 07:51:53 +01:00
} ) ;
2018-05-25 15:00:27 +02:00
return groupFragment ;
2017-11-15 07:51:53 +01:00
}
2018-05-25 15:00:27 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "_createChoicesFragment" ,
2018-05-25 15:00:27 +02:00
value : function _createChoicesFragment ( choices , fragment ) {
2018-10-13 12:19:24 +02:00
var _this14 = this ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
var withinGroup = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : false ;
// Create a fragment to store our list items (so we don't have to update the DOM for each item)
var choicesFragment = fragment || document . createDocumentFragment ( ) ;
2019-02-09 19:13:25 +01:00
var _this$config = this . config ,
renderSelectedChoices = _this$config . renderSelectedChoices ,
searchResultLimit = _this$config . searchResultLimit ,
renderChoiceLimit = _this$config . renderChoiceLimit ;
2018-05-25 15:00:27 +02:00
var filter = this . _isSearching ? _utils . sortByScore : this . config . sortFn ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
var appendChoice = function appendChoice ( choice ) {
2018-10-13 12:19:24 +02:00
var shouldRender = renderSelectedChoices === 'auto' ? _this14 . _isSelectOneElement || ! choice . selected : true ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
if ( shouldRender ) {
2018-10-13 12:19:24 +02:00
var dropdownItem = _this14 . _getTemplate ( 'choice' , choice , _this14 . config . itemSelectText ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
choicesFragment . appendChild ( dropdownItem ) ;
}
} ;
2017-11-15 07:51:53 +01:00
2018-05-25 15:00:27 +02:00
var rendererableChoices = choices ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( renderSelectedChoices === 'auto' && ! this . _isSelectOneElement ) {
rendererableChoices = choices . filter ( function ( choice ) {
return ! choice . selected ;
} ) ;
2019-02-09 19:13:25 +01:00
} // Split array into placeholders and "normal" choices
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
var _rendererableChoices$ = rendererableChoices . reduce ( function ( acc , choice ) {
if ( choice . placeholder ) {
acc . placeholderChoices . push ( choice ) ;
} else {
acc . normalChoices . push ( choice ) ;
}
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
return acc ;
2019-02-09 19:13:25 +01:00
} , {
placeholderChoices : [ ] ,
normalChoices : [ ]
} ) ,
2018-05-25 15:00:27 +02:00
placeholderChoices = _rendererableChoices$ . placeholderChoices ,
2019-02-09 19:13:25 +01:00
normalChoices = _rendererableChoices$ . normalChoices ; // If sorting is enabled or the user is searching, filter choices
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
2018-05-25 15:00:27 +02:00
if ( this . config . shouldSort || this . _isSearching ) {
normalChoices . sort ( filter ) ;
}
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var choiceLimit = rendererableChoices . length ; // Prepend placeholeder
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var sortedChoices = [ ] . concat ( placeholderChoices , normalChoices ) ;
2017-11-15 07:51:53 +01:00
2018-05-25 15:00:27 +02:00
if ( this . _isSearching ) {
choiceLimit = searchResultLimit ;
} else if ( renderChoiceLimit > 0 && ! withinGroup ) {
choiceLimit = renderChoiceLimit ;
2019-02-09 19:13:25 +01:00
} // Add each choice to dropdown within range
2017-11-15 07:51:53 +01:00
2018-05-25 15:00:27 +02:00
for ( var i = 0 ; i < choiceLimit ; i += 1 ) {
if ( sortedChoices [ i ] ) {
appendChoice ( sortedChoices [ i ] ) ;
2017-11-15 07:51:53 +01:00
}
2018-05-25 15:00:27 +02:00
}
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
return choicesFragment ;
2017-11-15 07:51:53 +01:00
}
2018-05-25 15:00:27 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "_createItemsFragment" ,
2018-05-25 15:00:27 +02:00
value : function _createItemsFragment ( items ) {
2018-10-13 12:19:24 +02:00
var _this15 = this ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
var fragment = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : null ;
// Create fragment to add elements to
2019-02-09 19:13:25 +01:00
var _this$config2 = this . config ,
shouldSortItems = _this$config2 . shouldSortItems ,
sortFn = _this$config2 . sortFn ,
removeItemButton = _this$config2 . removeItemButton ;
var itemListFragment = fragment || document . createDocumentFragment ( ) ; // If sorting is enabled, filter items
2018-05-25 15:00:27 +02:00
if ( shouldSortItems && ! this . _isSelectOneElement ) {
items . sort ( sortFn ) ;
}
if ( this . _isTextElement ) {
// Update the value of the hidden input
this . passedElement . value = items ;
} else {
// Update the options of the hidden input
this . passedElement . options = items ;
}
var addItemToFragment = function addItemToFragment ( item ) {
// Create new list element
2019-02-09 19:13:25 +01:00
var listItem = _this15 . _getTemplate ( 'item' , item , removeItemButton ) ; // Append it to list
2018-05-25 15:00:27 +02:00
itemListFragment . appendChild ( listItem ) ;
2019-02-09 19:13:25 +01:00
} ; // Add each list item to list
2018-05-25 15:00:27 +02:00
items . forEach ( function ( item ) {
return addItemToFragment ( item ) ;
} ) ;
return itemListFragment ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_triggerChange" ,
2018-05-25 15:00:27 +02:00
value : function _triggerChange ( value ) {
if ( value === undefined || value === null ) {
return ;
}
this . passedElement . triggerEvent ( _constants . EVENTS . change , {
value : value
} ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_selectPlaceholderChoice" ,
2018-05-25 15:00:27 +02:00
value : function _selectPlaceholderChoice ( ) {
var placeholderChoice = this . _store . placeholderChoice ;
if ( placeholderChoice ) {
2018-06-07 17:54:11 +02:00
this . _addItem ( {
value : placeholderChoice . value ,
label : placeholderChoice . label ,
choiceId : placeholderChoice . id ,
groupId : placeholderChoice . groupId ,
placeholder : placeholderChoice . placeholder
} ) ;
2018-05-25 15:00:27 +02:00
this . _triggerChange ( placeholderChoice . value ) ;
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_handleButtonAction" ,
2018-05-25 15:00:27 +02:00
value : function _handleButtonAction ( activeItems , element ) {
if ( ! activeItems || ! element || ! this . config . removeItems || ! this . config . removeItemButton ) {
return ;
}
var itemId = element . parentNode . getAttribute ( 'data-id' ) ;
var itemToRemove = activeItems . find ( function ( item ) {
return item . id === parseInt ( itemId , 10 ) ;
2019-02-09 19:13:25 +01:00
} ) ; // Remove item associated with button
2018-05-25 15:00:27 +02:00
this . _removeItem ( itemToRemove ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
this . _triggerChange ( itemToRemove . value ) ;
if ( this . _isSelectOneElement ) {
this . _selectPlaceholderChoice ( ) ;
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_handleItemAction" ,
2018-05-25 15:00:27 +02:00
value : function _handleItemAction ( activeItems , element ) {
2018-10-13 12:19:24 +02:00
var _this16 = this ;
2018-05-25 15:00:27 +02:00
var hasShiftKey = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : false ;
if ( ! activeItems || ! element || ! this . config . removeItems || this . _isSelectOneElement ) {
return ;
}
2019-02-09 19:13:25 +01:00
var passedId = element . getAttribute ( 'data-id' ) ; // We only want to select one item with a click
2018-05-25 15:00:27 +02:00
// so we deselect any items that aren't the target
// unless shift is being pressed
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
activeItems . forEach ( function ( item ) {
if ( item . id === parseInt ( passedId , 10 ) && ! item . highlighted ) {
2018-10-13 12:19:24 +02:00
_this16 . highlightItem ( item ) ;
2018-05-25 15:00:27 +02:00
} else if ( ! hasShiftKey && item . highlighted ) {
2018-10-13 12:19:24 +02:00
_this16 . unhighlightItem ( item ) ;
2018-05-25 15:00:27 +02:00
}
2019-02-09 19:13:25 +01:00
} ) ; // Focus input as without focus, a user cannot do anything with a
2018-05-25 15:00:27 +02:00
// highlighted item
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
this . input . focus ( ) ;
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_handleChoiceAction" ,
2017-11-15 07:51:53 +01:00
value : function _handleChoiceAction ( activeItems , element ) {
if ( ! activeItems || ! element ) {
return ;
2019-02-09 19:13:25 +01:00
} // If we are clicking on an option
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var id = element . getAttribute ( 'data-id' ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
var choice = this . _store . getChoiceById ( id ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
var passedKeyCode = activeItems [ 0 ] && activeItems [ 0 ] . keyCode ? activeItems [ 0 ] . keyCode : null ;
2019-02-09 19:13:25 +01:00
var hasActiveDropdown = this . dropdown . isActive ; // Update choice keyCode
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
choice . keyCode = passedKeyCode ;
this . passedElement . triggerEvent ( _constants . EVENTS . choice , {
choice : choice
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( choice && ! choice . selected && ! choice . disabled ) {
var canAddItem = this . _canAddItem ( activeItems , choice . value ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( canAddItem . response ) {
2018-06-07 17:54:11 +02:00
this . _addItem ( {
value : choice . value ,
label : choice . label ,
choiceId : choice . id ,
groupId : choice . groupId ,
customProperties : choice . customProperties ,
placeholder : choice . placeholder ,
keyCode : choice . keyCode
} ) ;
2017-11-15 07:51:53 +01:00
this . _triggerChange ( choice . value ) ;
}
}
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
this . clearInput ( ) ; // We wont to close the dropdown if we are dealing with a single select box
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( hasActiveDropdown && this . _isSelectOneElement ) {
2018-05-29 16:08:43 +02:00
this . hideDropdown ( true ) ;
2017-11-15 07:51:53 +01:00
this . containerOuter . focus ( ) ;
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_handleBackspace" ,
2017-11-15 07:51:53 +01:00
value : function _handleBackspace ( activeItems ) {
if ( ! this . config . removeItems || ! activeItems ) {
return ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var lastItem = activeItems [ activeItems . length - 1 ] ;
var hasHighlightedItems = activeItems . some ( function ( item ) {
return item . highlighted ;
2019-02-09 19:13:25 +01:00
} ) ; // If editing the last item is allowed and there are not other selected items,
2017-11-15 07:51:53 +01:00
// we can edit the item value. Otherwise if we can remove items, remove all selected items
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( this . config . editItems && ! hasHighlightedItems && lastItem ) {
2018-04-25 10:20:59 +02:00
this . input . value = lastItem . value ;
2017-11-15 07:51:53 +01:00
this . input . setWidth ( ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . _removeItem ( lastItem ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . _triggerChange ( lastItem . value ) ;
} else {
if ( ! hasHighlightedItems ) {
// Highlight last item if none already highlighted
this . highlightItem ( lastItem , false ) ;
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . removeHighlightedItems ( true ) ;
}
}
2019-01-26 13:36:47 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_setLoading" ,
2019-01-26 13:36:47 +01:00
value : function _setLoading ( isLoading ) {
this . _store . dispatch ( ( 0 , _general . setIsLoading ) ( isLoading ) ) ;
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_handleLoadingState" ,
2017-11-15 07:51:53 +01:00
value : function _handleLoadingState ( ) {
2019-01-26 13:36:47 +01:00
var setLoading = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : true ;
2019-02-09 19:13:25 +01:00
var placeholderItem = this . itemList . getChild ( "." . concat ( this . config . classNames . placeholder ) ) ;
2018-11-03 14:25:58 +01:00
2019-01-26 13:36:47 +01:00
if ( setLoading ) {
2018-11-03 14:25:58 +01:00
this . disable ( ) ;
2017-11-15 07:51:53 +01:00
this . containerOuter . addLoadingState ( ) ;
2018-11-03 14:25:58 +01:00
2018-05-25 15:00:27 +02:00
if ( this . _isSelectOneElement ) {
2017-11-15 07:51:53 +01:00
if ( ! placeholderItem ) {
placeholderItem = this . _getTemplate ( 'placeholder' , this . config . loadingText ) ;
this . itemList . append ( placeholderItem ) ;
} else {
placeholderItem . innerHTML = this . config . loadingText ;
}
} else {
2018-04-25 10:20:59 +02:00
this . input . placeholder = this . config . loadingText ;
2017-11-15 07:51:53 +01:00
}
} else {
2018-11-03 14:25:58 +01:00
this . enable ( ) ;
2017-11-15 07:51:53 +01:00
this . containerOuter . removeLoadingState ( ) ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( this . _isSelectOneElement ) {
placeholderItem . innerHTML = this . _placeholderValue || '' ;
2017-11-15 07:51:53 +01:00
} else {
2018-05-25 15:00:27 +02:00
this . input . placeholder = this . _placeholderValue || '' ;
2017-11-15 07:51:53 +01:00
}
}
}
2018-10-13 12:19:24 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "_handleSearch" ,
2018-10-13 12:19:24 +02:00
value : function _handleSearch ( value ) {
if ( ! value || ! this . input . isFocussed ) {
return ;
}
var choices = this . _store . choices ;
2019-02-09 19:13:25 +01:00
var _this$config3 = this . config ,
searchFloor = _this$config3 . searchFloor ,
searchChoices = _this$config3 . searchChoices ;
2018-10-13 12:19:24 +02:00
var hasUnactiveChoices = choices . some ( function ( option ) {
return ! option . active ;
2019-02-09 19:13:25 +01:00
} ) ; // Check that we have a value to search and the input was an alphanumeric character
2018-10-13 12:19:24 +02:00
if ( value && value . length >= searchFloor ) {
2019-02-09 19:13:25 +01:00
var resultCount = searchChoices ? this . _searchChoices ( value ) : 0 ; // Trigger search event
2018-10-13 12:19:24 +02:00
this . passedElement . triggerEvent ( _constants . EVENTS . search , {
value : value ,
resultCount : resultCount
} ) ;
} else if ( hasUnactiveChoices ) {
// Otherwise reset choices to active
this . _isSearching = false ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
this . _store . dispatch ( ( 0 , _choices . activateChoices ) ( true ) ) ;
}
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_canAddItem" ,
2017-11-15 07:51:53 +01:00
value : function _canAddItem ( activeItems , value ) {
var canAddItem = true ;
var notice = ( 0 , _utils . isType ) ( 'Function' , this . config . addItemText ) ? this . config . addItemText ( value ) : this . config . addItemText ;
2017-11-07 12:59:49 +01:00
2018-05-28 16:13:55 +02:00
if ( ! this . _isSelectOneElement ) {
2018-05-29 16:08:43 +02:00
var isDuplicateValue = ( 0 , _utils . existsInArray ) ( activeItems , value ) ;
2018-05-28 16:13:55 +02:00
2017-11-15 07:51:53 +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 = ( 0 , _utils . isType ) ( 'Function' , this . config . maxItemText ) ? this . config . maxItemText ( this . config . maxItemCount ) : this . config . maxItemText ;
}
2017-11-07 12:59:49 +01:00
2018-05-28 16:13:55 +02:00
if ( this . config . regexFilter && this . _isTextElement && this . config . addItems && canAddItem ) {
// If a user has supplied a regular expression filter
// determine whether we can update based on whether
// our regular expression passes
canAddItem = ( 0 , _utils . regexFilter ) ( value , this . config . regexFilter ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2018-05-29 16:08:43 +02:00
if ( ! this . config . duplicateItemsAllowed && isDuplicateValue && canAddItem ) {
2018-05-28 16:13:55 +02:00
canAddItem = false ;
notice = ( 0 , _utils . isType ) ( 'Function' , this . config . uniqueItemText ) ? this . config . uniqueItemText ( value ) : this . config . uniqueItemText ;
}
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return {
response : canAddItem ,
notice : notice
} ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_ajaxCallback" ,
2017-11-15 07:51:53 +01:00
value : function _ajaxCallback ( ) {
2018-10-13 12:19:24 +02:00
var _this17 = this ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return function ( results , value , label ) {
if ( ! results || ! value ) {
return ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var parsedResults = ( 0 , _utils . isType ) ( 'Object' , results ) ? [ results ] : results ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( parsedResults && ( 0 , _utils . isType ) ( 'Array' , parsedResults ) && parsedResults . length ) {
// Remove loading states/text
2018-10-13 12:19:24 +02:00
_this17 . _handleLoadingState ( false ) ;
2019-02-09 19:13:25 +01:00
_this17 . _setLoading ( true ) ; // Add each result as a choice
2017-11-15 07:51:53 +01:00
parsedResults . forEach ( function ( result ) {
if ( result . choices ) {
2018-10-13 12:19:24 +02:00
_this17 . _addGroup ( {
2018-06-07 17:54:11 +02:00
group : result ,
id : result . id || null ,
valueKey : value ,
labelKey : label
} ) ;
2017-11-15 07:51:53 +01:00
} else {
2018-10-13 12:19:24 +02:00
_this17 . _addChoice ( {
2018-06-07 17:54:11 +02:00
value : ( 0 , _utils . fetchFromObject ) ( result , value ) ,
label : ( 0 , _utils . fetchFromObject ) ( result , label ) ,
isSelected : result . selected ,
isDisabled : result . disabled ,
customProperties : result . customProperties ,
placeholder : result . placeholder
} ) ;
2017-11-15 07:51:53 +01:00
}
} ) ;
2017-11-07 12:59:49 +01:00
2019-01-26 13:36:47 +01:00
_this17 . _setLoading ( false ) ;
2018-10-13 12:19:24 +02:00
if ( _this17 . _isSelectOneElement ) {
_this17 . _selectPlaceholderChoice ( ) ;
2017-11-15 07:51:53 +01:00
}
} else {
// No results, remove loading state
2018-10-13 12:19:24 +02:00
_this17 . _handleLoadingState ( false ) ;
2017-11-15 07:51:53 +01:00
}
} ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_searchChoices" ,
2017-11-15 07:51:53 +01:00
value : function _searchChoices ( value ) {
var newValue = ( 0 , _utils . isType ) ( 'String' , value ) ? value . trim ( ) : value ;
2018-05-25 15:00:27 +02:00
var currentValue = ( 0 , _utils . isType ) ( 'String' , this . _currentValue ) ? this . _currentValue . trim ( ) : this . _currentValue ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
if ( newValue . length < 1 && newValue === "" . concat ( currentValue , " " ) ) {
2017-11-15 07:51:53 +01:00
return 0 ;
2019-02-09 19:13:25 +01:00
} // If new value matches the desired length and is not the same as the current value with a space
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
var haystack = this . _store . searchableChoices ;
2017-11-15 07:51:53 +01:00
var needle = newValue ;
2019-02-09 19:13:25 +01:00
var keys = [ ] . concat ( this . config . searchFields ) ;
var options = Object . assign ( this . config . fuseOptions , {
keys : keys
} ) ;
var fuse = new _fuse . default ( haystack , options ) ;
2017-11-15 07:51:53 +01:00
var results = fuse . search ( needle ) ;
2018-05-25 15:00:27 +02:00
this . _currentValue = newValue ;
this . _highlightPosition = 0 ;
this . _isSearching = true ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( ( 0 , _choices . filterChoices ) ( results ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return results . length ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_addEventListeners" ,
2017-11-15 07:51:53 +01:00
value : function _addEventListeners ( ) {
document . addEventListener ( 'keyup' , this . _onKeyUp ) ;
document . addEventListener ( 'keydown' , this . _onKeyDown ) ;
document . addEventListener ( 'click' , this . _onClick ) ;
document . addEventListener ( 'touchmove' , this . _onTouchMove ) ;
document . addEventListener ( 'touchend' , this . _onTouchEnd ) ;
document . addEventListener ( 'mousedown' , this . _onMouseDown ) ;
document . addEventListener ( 'mouseover' , this . _onMouseOver ) ;
2018-05-25 15:00:27 +02:00
if ( this . _isSelectOneElement ) {
2017-11-15 07:51:53 +01:00
this . containerOuter . element . addEventListener ( 'focus' , this . _onFocus ) ;
this . containerOuter . element . addEventListener ( 'blur' , this . _onBlur ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
this . input . element . addEventListener ( 'focus' , this . _onFocus ) ;
this . input . element . addEventListener ( 'blur' , this . _onBlur ) ;
2017-11-07 12:59:49 +01:00
2018-05-28 17:22:22 +02:00
if ( this . input . element . form ) {
this . input . element . form . addEventListener ( 'reset' , this . _onFormReset ) ;
}
2017-11-15 07:51:53 +01:00
this . input . addEventListeners ( ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_removeEventListeners" ,
2017-11-15 07:51:53 +01:00
value : function _removeEventListeners ( ) {
document . removeEventListener ( 'keyup' , this . _onKeyUp ) ;
document . removeEventListener ( 'keydown' , this . _onKeyDown ) ;
document . removeEventListener ( 'click' , this . _onClick ) ;
document . removeEventListener ( 'touchmove' , this . _onTouchMove ) ;
document . removeEventListener ( 'touchend' , this . _onTouchEnd ) ;
document . removeEventListener ( 'mousedown' , this . _onMouseDown ) ;
document . removeEventListener ( 'mouseover' , this . _onMouseOver ) ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( this . _isSelectOneElement ) {
2017-11-15 07:51:53 +01:00
this . containerOuter . element . removeEventListener ( 'focus' , this . _onFocus ) ;
this . containerOuter . element . removeEventListener ( 'blur' , this . _onBlur ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . input . element . removeEventListener ( 'focus' , this . _onFocus ) ;
this . input . element . removeEventListener ( 'blur' , this . _onBlur ) ;
2018-05-28 17:22:22 +02:00
if ( this . input . element . form ) {
this . input . element . form . removeEventListener ( 'reset' , this . _onFormReset ) ;
}
2017-11-15 07:51:53 +01:00
this . input . removeEventListeners ( ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onKeyDown" ,
2018-05-27 12:57:21 +02:00
value : function _onKeyDown ( event ) {
2018-10-13 12:19:24 +02:00
var _keyDownActions ;
2017-11-13 20:13:37 +01:00
2018-05-27 12:57:21 +02:00
var target = event . target ,
keyCode = event . keyCode ,
ctrlKey = event . ctrlKey ,
metaKey = event . metaKey ;
if ( target !== this . input . element && ! this . containerOuter . element . contains ( target ) ) {
2017-11-15 07:51:53 +01:00
return ;
}
2017-11-13 20:13:37 +01:00
2018-05-25 15:00:27 +02:00
var activeItems = this . _store . activeItems ;
2017-11-15 07:51:53 +01:00
var hasFocusedInput = this . input . isFocussed ;
var hasActiveDropdown = this . dropdown . isActive ;
var hasItems = this . itemList . hasChildren ;
2018-05-27 12:57:21 +02:00
var keyString = String . fromCharCode ( keyCode ) ;
2018-10-13 12:19:24 +02:00
var BACK _KEY = _constants . KEY _CODES . BACK _KEY ,
DELETE _KEY = _constants . KEY _CODES . DELETE _KEY ,
ENTER _KEY = _constants . KEY _CODES . ENTER _KEY ,
A _KEY = _constants . KEY _CODES . A _KEY ,
ESC _KEY = _constants . KEY _CODES . ESC _KEY ,
UP _KEY = _constants . KEY _CODES . UP _KEY ,
DOWN _KEY = _constants . KEY _CODES . DOWN _KEY ,
PAGE _UP _KEY = _constants . KEY _CODES . PAGE _UP _KEY ,
PAGE _DOWN _KEY = _constants . KEY _CODES . PAGE _DOWN _KEY ;
2019-02-09 19:13:25 +01:00
var hasCtrlDownKeyPressed = ctrlKey || metaKey ; // If a user is typing and the dropdown is not active
2018-10-13 12:19:24 +02:00
2018-05-25 15:00:27 +02:00
if ( ! this . _isTextElement && /[a-zA-Z0-9-_ ]/ . test ( keyString ) ) {
2018-05-29 16:08:43 +02:00
this . showDropdown ( ) ;
2019-02-09 19:13:25 +01:00
} // Map keys to key actions
2017-11-13 20:13:37 +01:00
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var keyDownActions = ( _keyDownActions = { } , _defineProperty ( _keyDownActions , A _KEY , this . _onAKey ) , _defineProperty ( _keyDownActions , ENTER _KEY , this . _onEnterKey ) , _defineProperty ( _keyDownActions , ESC _KEY , this . _onEscapeKey ) , _defineProperty ( _keyDownActions , UP _KEY , this . _onDirectionKey ) , _defineProperty ( _keyDownActions , PAGE _UP _KEY , this . _onDirectionKey ) , _defineProperty ( _keyDownActions , DOWN _KEY , this . _onDirectionKey ) , _defineProperty ( _keyDownActions , PAGE _DOWN _KEY , this . _onDirectionKey ) , _defineProperty ( _keyDownActions , DELETE _KEY , this . _onDeleteKey ) , _defineProperty ( _keyDownActions , BACK _KEY , this . _onDeleteKey ) , _keyDownActions ) ; // If keycode has a function, run it
2018-10-13 12:19:24 +02:00
if ( keyDownActions [ keyCode ] ) {
keyDownActions [ keyCode ] ( {
2018-11-24 18:49:14 +01:00
event : event ,
2018-10-13 12:19:24 +02:00
target : target ,
keyCode : keyCode ,
metaKey : metaKey ,
activeItems : activeItems ,
hasFocusedInput : hasFocusedInput ,
hasActiveDropdown : hasActiveDropdown ,
hasItems : hasItems ,
hasCtrlDownKeyPressed : hasCtrlDownKeyPressed
} ) ;
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onKeyUp" ,
2018-10-13 12:19:24 +02:00
value : function _onKeyUp ( _ref2 ) {
var target = _ref2 . target ,
keyCode = _ref2 . keyCode ;
2017-11-07 12:59:49 +01:00
2018-10-13 12:19:24 +02:00
if ( target !== this . input . element ) {
return ;
}
2017-11-13 20:13:37 +01:00
2018-10-13 12:19:24 +02:00
var value = this . input . value ;
var activeItems = this . _store . activeItems ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var canAddItem = this . _canAddItem ( activeItems , value ) ; // We are typing into a text input and have a value, we want to show a dropdown
2018-10-13 12:19:24 +02:00
// notice. Otherwise hide the dropdown
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
if ( this . _isTextElement ) {
if ( value ) {
if ( canAddItem . notice ) {
var dropdownItem = this . _getTemplate ( 'notice' , canAddItem . notice ) ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
this . dropdown . element . innerHTML = dropdownItem . outerHTML ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2018-10-13 12:19:24 +02:00
if ( canAddItem . response === true ) {
this . showDropdown ( true ) ;
} else if ( ! canAddItem . notice ) {
this . hideDropdown ( true ) ;
}
} else {
this . hideDropdown ( true ) ;
2017-11-15 07:51:53 +01:00
}
2018-10-13 12:19:24 +02:00
} else {
var backKey = _constants . KEY _CODES . BACK _KEY ;
2019-02-09 19:13:25 +01:00
var deleteKey = _constants . KEY _CODES . DELETE _KEY ; // If user has removed value...
2017-11-07 12:59:49 +01:00
2018-10-13 12:19:24 +02:00
if ( ( keyCode === backKey || keyCode === deleteKey ) && ! target . value ) {
if ( ! this . _isTextElement && this . _isSearching ) {
this . _isSearching = false ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
this . _store . dispatch ( ( 0 , _choices . activateChoices ) ( true ) ) ;
2017-11-15 07:51:53 +01:00
}
2018-10-13 12:19:24 +02:00
} else if ( this . _canSearch && canAddItem . response ) {
this . _handleSearch ( this . input . value ) ;
}
}
2017-11-07 12:59:49 +01:00
2018-10-13 12:19:24 +02:00
this . _canSearch = this . config . searchEnabled ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onAKey" ,
2018-10-13 12:19:24 +02:00
value : function _onAKey ( _ref3 ) {
var hasItems = _ref3 . hasItems ,
hasCtrlDownKeyPressed = _ref3 . hasCtrlDownKeyPressed ;
2017-11-07 12:59:49 +01:00
2018-10-13 12:19:24 +02:00
// If CTRL + A or CMD + A have been pressed and there are items to select
if ( hasCtrlDownKeyPressed && hasItems ) {
this . _canSearch = false ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
if ( this . config . removeItems && ! this . input . value && this . input . element === document . activeElement ) {
// Highlight items
this . highlightAll ( ) ;
2017-11-15 07:51:53 +01:00
}
2018-10-13 12:19:24 +02:00
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onEnterKey" ,
2018-10-13 12:19:24 +02:00
value : function _onEnterKey ( _ref4 ) {
2018-11-24 18:49:14 +01:00
var event = _ref4 . event ,
target = _ref4 . target ,
2018-10-13 12:19:24 +02:00
activeItems = _ref4 . activeItems ,
hasActiveDropdown = _ref4 . hasActiveDropdown ;
2019-02-09 19:13:25 +01:00
var enterKey = _constants . KEY _CODES . ENTER _KEY ; // If enter key is pressed and the input has a value
2018-10-13 12:19:24 +02:00
if ( this . _isTextElement && target . value ) {
var value = this . input . value ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var canAddItem = this . _canAddItem ( activeItems , value ) ; // All is good, add
2018-10-13 12:19:24 +02:00
if ( canAddItem . response ) {
this . hideDropdown ( true ) ;
2019-02-09 19:13:25 +01:00
this . _addItem ( {
value : value
} ) ;
2018-10-13 12:19:24 +02:00
this . _triggerChange ( value ) ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
this . clearInput ( ) ;
2017-11-15 07:51:53 +01:00
}
2018-10-13 12:19:24 +02:00
}
2017-11-13 20:13:37 +01:00
2018-10-13 12:19:24 +02:00
if ( target . hasAttribute ( 'data-button' ) ) {
this . _handleButtonAction ( activeItems , target ) ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
event . preventDefault ( ) ;
}
2017-11-13 20:13:37 +01:00
2018-10-13 12:19:24 +02:00
if ( hasActiveDropdown ) {
2019-02-09 19:13:25 +01:00
var highlighted = this . dropdown . getChild ( "." . concat ( this . config . classNames . highlightedState ) ) ; // If we have a highlighted choice
2018-10-13 12:19:24 +02:00
if ( highlighted ) {
// 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
2018-10-13 12:19:24 +02:00
this . _handleChoiceAction ( activeItems , highlighted ) ;
}
2018-10-30 20:21:07 +01:00
event . preventDefault ( ) ;
2018-10-13 12:19:24 +02:00
} else if ( this . _isSelectOneElement ) {
// Open single select dropdown if it's not active
this . showDropdown ( ) ;
event . preventDefault ( ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onEscapeKey" ,
2018-10-13 12:19:24 +02:00
value : function _onEscapeKey ( _ref5 ) {
var hasActiveDropdown = _ref5 . hasActiveDropdown ;
2018-05-27 12:57:21 +02:00
2018-10-13 12:19:24 +02:00
if ( hasActiveDropdown ) {
this . hideDropdown ( true ) ;
this . containerOuter . focus ( ) ;
2017-11-13 20:13:37 +01:00
}
2018-10-13 12:19:24 +02:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onDirectionKey" ,
2018-10-13 12:19:24 +02:00
value : function _onDirectionKey ( _ref6 ) {
2018-11-24 18:49:14 +01:00
var event = _ref6 . event ,
hasActiveDropdown = _ref6 . hasActiveDropdown ,
2018-10-13 12:19:24 +02:00
keyCode = _ref6 . keyCode ,
metaKey = _ref6 . metaKey ;
var downKey = _constants . KEY _CODES . DOWN _KEY ,
pageUpKey = _constants . KEY _CODES . PAGE _UP _KEY ,
2019-02-09 19:13:25 +01:00
pageDownKey = _constants . KEY _CODES . PAGE _DOWN _KEY ; // If up or down key is pressed, traverse through options
2017-11-07 12:59:49 +01:00
2018-10-13 12:19:24 +02: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]' ;
2019-02-09 19:13:25 +01:00
var nextEl ;
2017-11-13 20:13:37 +01:00
2018-10-13 12:19:24 +02:00
if ( skipKey ) {
if ( directionInt > 0 ) {
nextEl = Array . from ( this . dropdown . element . querySelectorAll ( selectableChoiceIdentifier ) ) . pop ( ) ;
} else {
nextEl = this . dropdown . element . querySelector ( selectableChoiceIdentifier ) ;
2017-11-15 07:51:53 +01:00
}
} else {
2019-02-09 19:13:25 +01:00
var currentEl = this . dropdown . element . querySelector ( "." . concat ( this . config . classNames . highlightedState ) ) ;
2018-10-13 12:19:24 +02:00
if ( currentEl ) {
nextEl = ( 0 , _utils . getAdjacentEl ) ( currentEl , selectableChoiceIdentifier , directionInt ) ;
} else {
nextEl = this . dropdown . element . querySelector ( selectableChoiceIdentifier ) ;
}
2017-11-15 07:51:53 +01:00
}
2018-10-13 12:19:24 +02:00
if ( nextEl ) {
// We prevent default to stop the cursor moving
// when pressing the arrow
if ( ! ( 0 , _utils . isScrolledIntoView ) ( nextEl , this . choiceList . element , directionInt ) ) {
this . choiceList . scrollToChoice ( nextEl , directionInt ) ;
2017-11-15 07:51:53 +01:00
}
2018-10-13 12:19:24 +02:00
2019-02-09 19:13:25 +01:00
this . _highlightChoice ( nextEl ) ;
} // Prevent default to maintain cursor position whilst
2018-10-13 12:19:24 +02:00
// traversing dropdown options
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
event . preventDefault ( ) ;
2017-11-15 07:51:53 +01:00
}
2018-10-13 12:19:24 +02:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onDeleteKey" ,
2018-10-13 12:19:24 +02:00
value : function _onDeleteKey ( _ref7 ) {
2018-11-24 18:49:14 +01:00
var event = _ref7 . event ,
target = _ref7 . target ,
2018-10-13 12:19:24 +02:00
hasFocusedInput = _ref7 . hasFocusedInput ,
activeItems = _ref7 . activeItems ;
2018-05-29 16:47:45 +02:00
2018-10-13 12:19:24 +02:00
// If backspace or delete key is pressed and the input has no value
if ( hasFocusedInput && ! target . value && ! this . _isSelectOneElement ) {
this . _handleBackspace ( activeItems ) ;
2019-02-09 19:13:25 +01:00
2018-10-13 12:19:24 +02:00
event . preventDefault ( ) ;
}
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onTouchMove" ,
2017-11-15 07:51:53 +01:00
value : function _onTouchMove ( ) {
2018-05-25 15:00:27 +02:00
if ( this . _wasTap === true ) {
this . _wasTap = false ;
2017-11-07 12:59:49 +01:00
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onTouchEnd" ,
2018-05-27 12:57:21 +02:00
value : function _onTouchEnd ( event ) {
2019-02-09 19:13:25 +01:00
var target = event . target || event . touches [ 0 ] . target ; // If a user tapped within our container...
2017-11-13 20:13:37 +01:00
2018-05-25 15:00:27 +02:00
if ( this . _wasTap === true && this . containerOuter . element . contains ( target ) ) {
2017-11-15 07:51:53 +01:00
// ...and we aren't dealing with a single select box, show dropdown/focus input
2018-05-28 17:22:22 +02:00
var containerWasTarget = target === this . containerOuter . element || target === this . containerInner . element ;
if ( containerWasTarget && ! this . _isSelectOneElement ) {
2018-05-25 15:00:27 +02:00
if ( this . _isTextElement ) {
2017-11-15 07:51:53 +01:00
// If text element, we only want to focus the input
this . input . focus ( ) ;
} else {
// If a select box, we want to show the dropdown
2018-05-29 16:08:43 +02:00
this . showDropdown ( ) ;
2017-11-15 07:51:53 +01:00
}
2019-02-09 19:13:25 +01:00
} // Prevents focus event firing
2018-05-27 12:57:21 +02:00
event . stopPropagation ( ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-13 20:13:37 +01:00
2018-05-25 15:00:27 +02:00
this . _wasTap = true ;
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onMouseDown" ,
2018-05-27 12:57:21 +02:00
value : function _onMouseDown ( event ) {
var target = event . target ,
2019-02-09 19:13:25 +01:00
shiftKey = event . shiftKey ; // If we have our mouse down on the scrollbar and are on IE11...
2018-05-27 12:57:21 +02:00
2018-05-25 15:00:27 +02:00
if ( target === this . choiceList && ( 0 , _utils . isIE11 ) ( ) ) {
this . _isScrollingOnIe = true ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2018-05-29 16:47:45 +02:00
if ( ! this . containerOuter . element . contains ( target ) || target === this . input . element ) {
return ;
}
var activeItems = this . _store . activeItems ;
var hasShiftKey = shiftKey ;
var buttonTarget = ( 0 , _utils . findAncestorByAttrName ) ( target , 'data-button' ) ;
var itemTarget = ( 0 , _utils . findAncestorByAttrName ) ( target , 'data-item' ) ;
var choiceTarget = ( 0 , _utils . findAncestorByAttrName ) ( target , 'data-choice' ) ;
if ( buttonTarget ) {
this . _handleButtonAction ( activeItems , buttonTarget ) ;
} else if ( itemTarget ) {
this . _handleItemAction ( activeItems , itemTarget , hasShiftKey ) ;
} else if ( choiceTarget ) {
this . _handleChoiceAction ( activeItems , choiceTarget ) ;
2017-11-13 20:13:37 +01:00
}
2018-05-29 16:47:45 +02:00
event . preventDefault ( ) ;
2017-11-15 07:51:53 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onMouseOver" ,
2018-10-13 12:19:24 +02:00
value : function _onMouseOver ( _ref8 ) {
var target = _ref8 . target ;
2018-05-27 12:57:21 +02:00
var targetWithinDropdown = target === this . dropdown || this . dropdown . element . contains ( target ) ;
var shouldHighlightChoice = targetWithinDropdown && target . hasAttribute ( 'data-choice' ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( shouldHighlightChoice ) {
2018-05-27 12:57:21 +02:00
this . _highlightChoice ( target ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onClick" ,
2018-10-13 12:19:24 +02:00
value : function _onClick ( _ref9 ) {
var target = _ref9 . target ;
2018-05-27 12:57:21 +02:00
2017-11-15 07:51:53 +01:00
if ( this . containerOuter . element . contains ( target ) ) {
2018-10-30 21:29:22 +01:00
if ( ! this . dropdown . isActive && ! this . containerOuter . isDisabled ) {
2018-05-25 15:00:27 +02:00
if ( this . _isTextElement ) {
2017-11-15 07:51:53 +01:00
if ( document . activeElement !== this . input . element ) {
this . input . focus ( ) ;
}
} else {
this . showDropdown ( ) ;
2018-05-29 16:08:43 +02:00
this . containerOuter . focus ( ) ;
2017-11-15 07:51:53 +01:00
}
2018-05-25 15:00:27 +02:00
} else if ( this . _isSelectOneElement && target !== this . input . element && ! this . dropdown . element . contains ( target ) ) {
2018-05-29 16:08:43 +02:00
this . hideDropdown ( ) ;
2017-11-15 07:51:53 +01:00
}
} else {
2018-05-29 16:08:43 +02:00
var hasHighlightedItems = this . _store . highlightedActiveItems ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( hasHighlightedItems ) {
this . unhighlightAll ( ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . containerOuter . removeFocusState ( ) ;
2018-05-29 16:08:43 +02:00
this . hideDropdown ( true ) ;
2017-11-15 07:51:53 +01:00
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onFocus" ,
2018-10-13 12:19:24 +02:00
value : function _onFocus ( _ref10 ) {
2018-05-25 15:00:27 +02:00
var _this18 = this ;
2018-10-13 12:19:24 +02:00
var target = _ref10 . target ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( ! this . containerOuter . element . contains ( target ) ) {
return ;
}
var focusActions = {
text : function text ( ) {
2018-05-25 15:00:27 +02:00
if ( target === _this18 . input . element ) {
_this18 . containerOuter . addFocusState ( ) ;
2017-11-15 07:51:53 +01:00
}
} ,
'select-one' : function selectOne ( ) {
2018-05-25 15:00:27 +02:00
_this18 . containerOuter . addFocusState ( ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
if ( target === _this18 . input . element ) {
2018-05-29 16:08:43 +02:00
_this18 . showDropdown ( true ) ;
2017-11-15 07:51:53 +01:00
}
} ,
'select-multiple' : function selectMultiple ( ) {
2018-05-25 15:00:27 +02:00
if ( target === _this18 . input . element ) {
2019-02-09 19:13:25 +01:00
_this18 . showDropdown ( true ) ; // If element is a select box, the focused element is the container and the dropdown
2017-11-15 07:51:53 +01:00
// isn't already open, focus and show dropdown
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
_this18 . containerOuter . addFocusState ( ) ;
2017-11-07 12:59:49 +01:00
}
}
2017-11-15 07:51:53 +01:00
} ;
focusActions [ this . passedElement . element . type ] ( ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onBlur" ,
2018-10-13 12:19:24 +02:00
value : function _onBlur ( _ref11 ) {
2018-05-25 15:00:27 +02:00
var _this19 = this ;
2018-10-13 12:19:24 +02:00
var target = _ref11 . target ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// If target is something that concerns us
2018-05-25 15:00:27 +02:00
if ( this . containerOuter . element . contains ( target ) && ! this . _isScrollingOnIe ) {
var activeItems = this . _store . activeItems ;
2017-11-15 07:51:53 +01:00
var hasHighlightedItems = activeItems . some ( function ( item ) {
return item . highlighted ;
} ) ;
var blurActions = {
text : function text ( ) {
2018-05-25 15:00:27 +02:00
if ( target === _this19 . input . element ) {
_this19 . containerOuter . removeFocusState ( ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( hasHighlightedItems ) {
2018-05-25 15:00:27 +02:00
_this19 . unhighlightAll ( ) ;
2017-11-15 07:51:53 +01:00
}
2019-02-09 19:13:25 +01:00
2018-05-29 16:08:43 +02:00
_this19 . hideDropdown ( true ) ;
2017-11-15 07:51:53 +01:00
}
} ,
'select-one' : function selectOne ( ) {
2018-05-25 15:00:27 +02:00
_this19 . containerOuter . removeFocusState ( ) ;
2019-02-09 19:13:25 +01:00
2018-05-29 16:47:45 +02:00
if ( target === _this19 . input . element || target === _this19 . containerOuter . element && ! _this19 . _canSearch ) {
2018-05-29 16:08:43 +02:00
_this19 . hideDropdown ( true ) ;
2017-11-15 07:51:53 +01:00
}
} ,
'select-multiple' : function selectMultiple ( ) {
2018-05-25 15:00:27 +02:00
if ( target === _this19 . input . element ) {
_this19 . containerOuter . removeFocusState ( ) ;
2019-02-09 19:13:25 +01:00
2018-05-29 16:08:43 +02:00
_this19 . hideDropdown ( true ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( hasHighlightedItems ) {
2018-05-25 15:00:27 +02:00
_this19 . unhighlightAll ( ) ;
2017-11-15 07:51:53 +01:00
}
}
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} ;
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.
2018-05-25 15:00:27 +02:00
this . _isScrollingOnIe = false ;
2017-11-15 07:51:53 +01:00
this . input . element . focus ( ) ;
2017-11-13 20:13:37 +01:00
}
}
2018-05-28 17:22:22 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "_onFormReset" ,
2018-05-28 17:22:22 +02:00
value : function _onFormReset ( ) {
this . _store . dispatch ( ( 0 , _misc . resetTo ) ( this . _initialState ) ) ;
}
2018-05-25 15:00:27 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "_highlightChoice" ,
2018-05-25 15:00:27 +02:00
value : function _highlightChoice ( ) {
2018-05-28 16:13:55 +02:00
var _this20 = this ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
var el = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : null ;
var choices = Array . from ( this . dropdown . element . querySelectorAll ( '[data-choice-selectable]' ) ) ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( ! choices . length ) {
2017-11-15 07:51:53 +01:00
return ;
2017-11-07 12:59:49 +01:00
}
2018-05-25 15:00:27 +02:00
var passedEl = el ;
2019-02-09 19:13:25 +01:00
var highlightedChoices = Array . from ( this . dropdown . element . querySelectorAll ( "." . concat ( this . config . classNames . highlightedState ) ) ) ; // Remove any highlighted choices
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
highlightedChoices . forEach ( function ( choice ) {
2018-05-28 16:13:55 +02:00
choice . classList . remove ( _this20 . config . classNames . highlightedState ) ;
2018-05-25 15:00:27 +02:00
choice . setAttribute ( 'aria-selected' , 'false' ) ;
} ) ;
2018-02-02 12:08:03 +01:00
if ( passedEl ) {
2018-05-25 15:00:27 +02:00
this . _highlightPosition = choices . indexOf ( passedEl ) ;
2018-02-02 12:08:03 +01:00
} else {
// Highlight choice based on last known highlight location
2018-05-25 15:00:27 +02:00
if ( choices . length > this . _highlightPosition ) {
2018-02-02 12:08:03 +01:00
// If we have an option to highlight
2018-05-25 15:00:27 +02:00
passedEl = choices [ this . _highlightPosition ] ;
2017-11-15 07:51:53 +01:00
} else {
2018-02-02 12:08:03 +01:00
// Otherwise highlight the option before
passedEl = choices [ choices . length - 1 ] ;
}
2017-11-13 20:13:37 +01:00
2018-02-02 12:08:03 +01:00
if ( ! passedEl ) {
passedEl = choices [ 0 ] ;
2017-11-15 07:51:53 +01:00
}
2018-02-02 12:08:03 +01:00
}
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
passedEl . classList . add ( this . config . classNames . highlightedState ) ;
passedEl . setAttribute ( 'aria-selected' , 'true' ) ;
2019-02-09 19:13:25 +01:00
this . passedElement . triggerEvent ( _constants . EVENTS . highlightChoice , {
el : passedEl
} ) ;
2017-11-15 07:51:53 +01:00
2018-05-29 16:47:45 +02:00
if ( this . dropdown . isActive ) {
2018-02-02 12:08:03 +01:00
// 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 ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_addItem" ,
2018-10-13 12:19:24 +02:00
value : function _addItem ( _ref12 ) {
var value = _ref12 . value ,
_ref12$label = _ref12 . label ,
2019-02-09 19:13:25 +01:00
label = _ref12$label === void 0 ? null : _ref12$label ,
2018-10-13 12:19:24 +02:00
_ref12$choiceId = _ref12 . choiceId ,
2019-02-09 19:13:25 +01:00
choiceId = _ref12$choiceId === void 0 ? - 1 : _ref12$choiceId ,
2018-10-13 12:19:24 +02:00
_ref12$groupId = _ref12 . groupId ,
2019-02-09 19:13:25 +01:00
groupId = _ref12$groupId === void 0 ? - 1 : _ref12$groupId ,
2018-10-13 12:19:24 +02:00
_ref12$customProperti = _ref12 . customProperties ,
2019-02-09 19:13:25 +01:00
customProperties = _ref12$customProperti === void 0 ? null : _ref12$customProperti ,
2018-10-13 12:19:24 +02:00
_ref12$placeholder = _ref12 . placeholder ,
2019-02-09 19:13:25 +01:00
placeholder = _ref12$placeholder === void 0 ? false : _ref12$placeholder ,
2018-10-13 12:19:24 +02:00
_ref12$keyCode = _ref12 . keyCode ,
2019-02-09 19:13:25 +01:00
keyCode = _ref12$keyCode === void 0 ? null : _ref12$keyCode ;
2017-11-15 07:51:53 +01:00
var passedValue = ( 0 , _utils . isType ) ( 'String' , value ) ? value . trim ( ) : value ;
var passedKeyCode = keyCode ;
2018-02-02 12:08:03 +01:00
var passedCustomProperties = customProperties ;
2018-05-25 15:00:27 +02:00
var items = this . _store . items ;
2017-11-15 07:51:53 +01:00
var passedLabel = label || passedValue ;
var passedOptionId = parseInt ( choiceId , 10 ) || - 1 ;
2018-05-25 15:00:27 +02:00
var group = groupId >= 0 ? this . _store . getGroupById ( groupId ) : null ;
2019-02-09 19:13:25 +01:00
var id = items ? items . length + 1 : 1 ; // If a prepended value has been passed, prepend it
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . config . prependValue ) {
passedValue = this . config . prependValue + passedValue . toString ( ) ;
2019-02-09 19:13:25 +01:00
} // If an appended value has been passed, append it
2017-11-15 07:51:53 +01:00
if ( this . config . appendValue ) {
passedValue += this . config . appendValue . toString ( ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-13 20:13:37 +01:00
2018-06-07 17:54:11 +02:00
this . _store . dispatch ( ( 0 , _items . addItem ) ( {
value : passedValue ,
label : passedLabel ,
id : id ,
choiceId : passedOptionId ,
groupId : groupId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : passedKeyCode
} ) ) ;
2017-11-13 20:13:37 +01:00
2018-05-25 15:00:27 +02:00
if ( this . _isSelectOneElement ) {
2017-11-15 07:51:53 +01:00
this . removeActiveItems ( id ) ;
2019-02-09 19:13:25 +01:00
} // Trigger change event
2017-11-15 07:51:53 +01:00
2018-11-25 13:48:49 +01:00
this . passedElement . triggerEvent ( _constants . EVENTS . addItem , {
id : id ,
value : passedValue ,
label : passedLabel ,
customProperties : passedCustomProperties ,
groupValue : group && group . value ? group . value : undefined ,
keyCode : passedKeyCode
} ) ;
2017-11-13 20:13:37 +01:00
return this ;
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_removeItem" ,
2017-11-15 07:51:53 +01:00
value : function _removeItem ( item ) {
if ( ! item || ! ( 0 , _utils . isType ) ( 'Object' , item ) ) {
return this ;
}
2017-11-13 20:13:37 +01:00
2018-02-02 12:08:03 +01:00
var id = item . id ,
value = item . value ,
label = item . label ,
choiceId = item . choiceId ,
groupId = item . groupId ;
2018-05-25 15:00:27 +02:00
var group = groupId >= 0 ? this . _store . getGroupById ( groupId ) : null ;
2017-11-13 20:13:37 +01:00
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( ( 0 , _items . removeItem ) ( id , choiceId ) ) ;
2017-11-15 07:51:53 +01:00
if ( group && group . value ) {
this . passedElement . triggerEvent ( _constants . EVENTS . removeItem , {
id : id ,
value : value ,
label : label ,
groupValue : group . value
} ) ;
} else {
this . passedElement . triggerEvent ( _constants . EVENTS . removeItem , {
id : id ,
value : value ,
label : label
} ) ;
}
2017-11-13 20:13:37 +01:00
return this ;
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_addChoice" ,
2018-10-13 12:19:24 +02:00
value : function _addChoice ( _ref13 ) {
var value = _ref13 . value ,
_ref13$label = _ref13 . label ,
2019-02-09 19:13:25 +01:00
label = _ref13$label === void 0 ? null : _ref13$label ,
2018-10-13 12:19:24 +02:00
_ref13$isSelected = _ref13 . isSelected ,
2019-02-09 19:13:25 +01:00
isSelected = _ref13$isSelected === void 0 ? false : _ref13$isSelected ,
2018-10-13 12:19:24 +02:00
_ref13$isDisabled = _ref13 . isDisabled ,
2019-02-09 19:13:25 +01:00
isDisabled = _ref13$isDisabled === void 0 ? false : _ref13$isDisabled ,
2018-10-13 12:19:24 +02:00
_ref13$groupId = _ref13 . groupId ,
2019-02-09 19:13:25 +01:00
groupId = _ref13$groupId === void 0 ? - 1 : _ref13$groupId ,
2018-10-13 12:19:24 +02:00
_ref13$customProperti = _ref13 . customProperties ,
2019-02-09 19:13:25 +01:00
customProperties = _ref13$customProperti === void 0 ? null : _ref13$customProperti ,
2018-10-13 12:19:24 +02:00
_ref13$placeholder = _ref13 . placeholder ,
2019-02-09 19:13:25 +01:00
placeholder = _ref13$placeholder === void 0 ? false : _ref13$placeholder ,
2018-10-13 12:19:24 +02:00
_ref13$keyCode = _ref13 . keyCode ,
2019-02-09 19:13:25 +01:00
keyCode = _ref13$keyCode === void 0 ? null : _ref13$keyCode ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( typeof value === 'undefined' || value === null ) {
return ;
2019-02-09 19:13:25 +01:00
} // Generate unique id
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
var choices = this . _store . choices ;
2017-11-15 07:51:53 +01:00
var choiceLabel = label || value ;
var choiceId = choices ? choices . length + 1 : 1 ;
2019-02-09 19:13:25 +01:00
var choiceElementId = "" . concat ( this . _baseId , "-" ) . concat ( this . _idNames . itemChoice , "-" ) . concat ( choiceId ) ;
2017-11-07 12:59:49 +01:00
2018-06-07 17:54:11 +02:00
this . _store . dispatch ( ( 0 , _choices . addChoice ) ( {
value : value ,
label : choiceLabel ,
id : choiceId ,
groupId : groupId ,
disabled : isDisabled ,
elementId : choiceElementId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
} ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( isSelected ) {
2018-06-07 17:54:11 +02:00
this . _addItem ( {
value : value ,
label : choiceLabel ,
choiceId : choiceId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
} ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_clearChoices" ,
2017-11-15 07:51:53 +01:00
value : function _clearChoices ( ) {
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( ( 0 , _choices . clearChoices ) ( ) ) ;
2017-11-13 20:13:37 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_addGroup" ,
2018-10-13 12:19:24 +02:00
value : function _addGroup ( _ref14 ) {
2018-05-28 16:13:55 +02:00
var _this21 = this ;
2017-11-13 20:13:37 +01:00
2018-10-13 12:19:24 +02:00
var group = _ref14 . group ,
id = _ref14 . id ,
_ref14$valueKey = _ref14 . valueKey ,
2019-02-09 19:13:25 +01:00
valueKey = _ref14$valueKey === void 0 ? 'value' : _ref14$valueKey ,
2018-10-13 12:19:24 +02:00
_ref14$labelKey = _ref14 . labelKey ,
2019-02-09 19:13:25 +01:00
labelKey = _ref14$labelKey === void 0 ? 'label' : _ref14$labelKey ;
2017-11-15 07:51:53 +01:00
var groupChoices = ( 0 , _utils . 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 ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( groupChoices ) {
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( ( 0 , _groups . addGroup ) ( group . label , groupId , true , isDisabled ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var addGroupChoices = function addGroupChoices ( choice ) {
var isOptDisabled = choice . disabled || choice . parentNode && choice . parentNode . disabled ;
2018-06-07 17:54:11 +02:00
_this21 . _addChoice ( {
value : choice [ valueKey ] ,
label : ( 0 , _utils . isType ) ( 'Object' , choice ) ? choice [ labelKey ] : choice . innerHTML ,
isSelected : choice . selected ,
isDisabled : isOptDisabled ,
groupId : groupId ,
customProperties : choice . customProperties ,
placeholder : choice . placeholder
} ) ;
2017-11-15 07:51:53 +01:00
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
groupChoices . forEach ( addGroupChoices ) ;
2017-11-13 20:13:37 +01:00
} else {
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( ( 0 , _groups . addGroup ) ( group . label , group . id , false , group . disabled ) ) ;
2017-11-07 12:59:49 +01:00
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_getTemplate" ,
2017-11-15 07:51:53 +01:00
value : function _getTemplate ( template ) {
var _templates$template ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! template ) {
return null ;
}
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var _this$config4 = this . config ,
templates = _this$config4 . templates ,
classNames = _this$config4 . classNames ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
for ( var _len = arguments . length , args = new Array ( _len > 1 ? _len - 1 : 0 ) , _key = 1 ; _key < _len ; _key ++ ) {
2017-11-15 07:51:53 +01:00
args [ _key - 1 ] = arguments [ _key ] ;
}
2017-11-07 12:59:49 +01:00
2018-05-28 16:13:55 +02:00
return ( _templates$template = templates [ template ] ) . call . apply ( _templates$template , [ this , classNames ] . concat ( args ) ) ;
2017-11-13 20:13:37 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "_createTemplates" ,
2017-11-15 07:51:53 +01:00
value : function _createTemplates ( ) {
2018-05-25 15:00:27 +02:00
var callbackOnCreateTemplates = this . config . callbackOnCreateTemplates ;
2017-11-15 07:51:53 +01:00
var userTemplates = { } ;
2018-05-25 15:00:27 +02:00
if ( callbackOnCreateTemplates && ( 0 , _utils . isType ) ( 'Function' , callbackOnCreateTemplates ) ) {
userTemplates = callbackOnCreateTemplates . call ( this , _utils . strToEl ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
this . config . templates = ( 0 , _utils . extend ) ( _templates . TEMPLATES , userTemplates ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_createElements" ,
2018-04-25 10:20:59 +02:00
value : function _createElements ( ) {
2018-05-25 15:00:27 +02:00
this . containerOuter = new _components . Container ( {
2018-06-07 17:54:11 +02:00
element : this . _getTemplate ( 'containerOuter' , this . _direction , this . _isSelectElement , this . _isSelectOneElement , this . config . searchEnabled , this . passedElement . element . type ) ,
2018-05-25 15:00:27 +02:00
classNames : this . config . classNames ,
type : this . passedElement . element . type ,
position : this . config . position
} ) ;
this . containerInner = new _components . Container ( {
2018-06-07 17:54:11 +02:00
element : this . _getTemplate ( 'containerInner' ) ,
2018-05-25 15:00:27 +02:00
classNames : this . config . classNames ,
type : this . passedElement . element . type ,
position : this . config . position
} ) ;
this . input = new _components . Input ( {
2018-06-07 17:54:11 +02:00
element : this . _getTemplate ( 'input' ) ,
2018-05-25 15:00:27 +02:00
classNames : this . config . classNames ,
type : this . passedElement . element . type
} ) ;
this . choiceList = new _components . List ( {
2018-06-07 17:54:11 +02:00
element : this . _getTemplate ( 'choiceList' , this . _isSelectOneElement )
2018-05-25 15:00:27 +02:00
} ) ;
this . itemList = new _components . List ( {
2018-06-07 17:54:11 +02:00
element : this . _getTemplate ( 'itemList' , this . _isSelectOneElement )
2018-05-25 15:00:27 +02:00
} ) ;
this . dropdown = new _components . Dropdown ( {
2018-06-07 17:54:11 +02:00
element : this . _getTemplate ( 'dropdown' ) ,
2018-05-25 15:00:27 +02:00
classNames : this . config . classNames ,
type : this . passedElement . element . type
} ) ;
}
2018-04-25 10:20:59 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "_createStructure" ,
2018-04-25 10:20:59 +02:00
value : function _createStructure ( ) {
// Hide original element
2019-02-09 19:13:25 +01:00
this . passedElement . conceal ( ) ; // Wrap input in container preserving DOM ordering
this . containerInner . wrap ( this . passedElement . element ) ; // Wrapper inner container with outer container
2018-02-02 12:08:03 +01:00
this . containerOuter . wrap ( this . containerInner . element ) ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( this . _isSelectOneElement ) {
2018-04-25 10:20:59 +02:00
this . input . placeholder = this . config . searchPlaceholderValue || '' ;
2018-05-25 15:00:27 +02:00
} else if ( this . _placeholderValue ) {
this . input . placeholder = this . _placeholderValue ;
2017-11-15 07:51:53 +01:00
this . input . setWidth ( true ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . containerOuter . element . appendChild ( this . containerInner . element ) ;
this . containerOuter . element . appendChild ( this . dropdown . element ) ;
2018-04-25 10:20:59 +02:00
this . containerInner . element . appendChild ( this . itemList . element ) ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( ! this . _isTextElement ) {
2018-04-25 10:20:59 +02:00
this . dropdown . element . appendChild ( this . choiceList . element ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( ! this . _isSelectOneElement ) {
2017-11-15 07:51:53 +01:00
this . containerInner . element . appendChild ( this . input . element ) ;
2018-05-25 15:00:27 +02:00
} else if ( this . config . searchEnabled ) {
2018-04-25 10:20:59 +02:00
this . dropdown . element . insertBefore ( this . input . element , this . dropdown . element . firstChild ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
if ( this . _isSelectElement ) {
2017-11-15 07:51:53 +01:00
this . _addPredefinedChoices ( ) ;
2018-05-25 15:00:27 +02:00
} else if ( this . _isTextElement ) {
2017-11-15 07:51:53 +01:00
this . _addPredefinedItems ( ) ;
}
}
2017-11-13 20:13:37 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_addPredefinedChoices" ,
2017-11-15 07:51:53 +01:00
value : function _addPredefinedChoices ( ) {
2018-05-28 16:13:55 +02:00
var _this22 = this ;
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
var passedGroups = this . passedElement . optionGroups ;
2018-05-25 15:00:27 +02:00
this . _highlightPosition = 0 ;
this . _isSearching = false ;
2019-02-09 19:13:25 +01:00
2019-01-26 13:36:47 +01:00
this . _setLoading ( true ) ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
if ( passedGroups && passedGroups . length ) {
// If we have a placeholder option
2018-04-25 10:20:59 +02:00
var placeholderChoice = this . passedElement . placeholderOption ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( placeholderChoice && placeholderChoice . parentNode . tagName === 'SELECT' ) {
2018-06-07 17:54:11 +02:00
this . _addChoice ( {
value : placeholderChoice . value ,
label : placeholderChoice . innerHTML ,
isSelected : placeholderChoice . selected ,
isDisabled : placeholderChoice . disabled ,
placeholder : true
} ) ;
2017-11-15 07:51:53 +01:00
}
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
passedGroups . forEach ( function ( group ) {
2018-06-07 17:54:11 +02:00
return _this22 . _addGroup ( {
group : group ,
id : group . id || null
} ) ;
2017-11-15 07:51:53 +01:00
} ) ;
} else {
2018-04-25 10:20:59 +02:00
var passedOptions = this . passedElement . options ;
2018-02-02 12:08:03 +01:00
var filter = this . config . sortFn ;
2019-02-09 19:13:25 +01:00
var allChoices = this . _presetChoices ; // Create array of options from option elements
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
passedOptions . forEach ( function ( o ) {
allChoices . push ( {
value : o . value ,
label : o . innerHTML ,
selected : o . selected ,
disabled : o . disabled || o . parentNode . disabled ,
2019-02-11 18:52:22 +01:00
placeholder : o . hasAttribute ( 'placeholder' ) ,
customProperties : o . getAttribute ( 'data-custom-properties' )
2017-11-15 07:51:53 +01:00
} ) ;
2019-02-09 19:13:25 +01:00
} ) ; // If sorting is enabled or the user is searching, filter choices
2017-11-15 07:51:53 +01:00
2019-02-11 18:52:22 +01:00
if ( this . config . shouldSort ) allChoices . sort ( filter ) ; // Determine whether there is a selected choice
2017-11-15 07:51:53 +01:00
var hasSelectedChoice = allChoices . some ( function ( choice ) {
return choice . selected ;
} ) ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
var handleChoice = function handleChoice ( choice , index ) {
2018-06-07 17:54:11 +02:00
var value = choice . value ,
label = choice . label ,
customProperties = choice . customProperties ,
placeholder = choice . placeholder ;
2018-05-28 16:13:55 +02:00
if ( _this22 . _isSelectElement ) {
2017-11-15 07:51:53 +01:00
// If the choice is actually a group
if ( choice . choices ) {
2018-06-07 17:54:11 +02:00
_this22 . _addGroup ( {
group : choice ,
id : choice . id || null
} ) ;
2017-11-15 07:51:53 +01:00
} else {
// If there is a selected choice already or the choice is not
// the first in the array, add each choice normally
// Otherwise pre-select the first choice in the array if it's a single select
2018-05-28 16:13:55 +02:00
var shouldPreselect = _this22 . _isSelectOneElement && ! hasSelectedChoice && index === 0 ;
2017-11-15 07:51:53 +01:00
var isSelected = shouldPreselect ? true : choice . selected ;
var isDisabled = shouldPreselect ? false : choice . disabled ;
2018-06-07 17:54:11 +02:00
_this22 . _addChoice ( {
value : value ,
label : label ,
isSelected : isSelected ,
isDisabled : isDisabled ,
customProperties : customProperties ,
placeholder : placeholder
} ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-13 20:13:37 +01:00
} else {
2018-06-07 17:54:11 +02:00
_this22 . _addChoice ( {
value : value ,
label : label ,
isSelected : choice . selected ,
isDisabled : choice . disabled ,
customProperties : customProperties ,
placeholder : placeholder
} ) ;
2017-11-13 20:13:37 +01:00
}
2019-02-09 19:13:25 +01:00
} ; // Add each choice
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
allChoices . forEach ( function ( choice , index ) {
return handleChoice ( choice , index ) ;
} ) ;
2017-11-13 20:13:37 +01:00
}
2019-01-26 13:36:47 +01:00
this . _setLoading ( false ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_addPredefinedItems" ,
2017-11-15 07:51:53 +01:00
value : function _addPredefinedItems ( ) {
2018-05-28 16:13:55 +02:00
var _this23 = this ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
var handlePresetItem = function handlePresetItem ( item ) {
var itemType = ( 0 , _utils . getType ) ( item ) ;
2019-02-09 19:13:25 +01:00
2018-06-07 17:54:11 +02:00
if ( itemType === 'Object' && item . value ) {
_this23 . _addItem ( {
value : item . value ,
label : item . label ,
choiceId : item . id ,
customProperties : item . customProperties ,
placeholder : item . placeholder
} ) ;
2017-11-15 07:51:53 +01:00
} else if ( itemType === 'String' ) {
2018-06-07 17:54:11 +02:00
_this23 . _addItem ( {
value : item
} ) ;
2017-11-15 07:51:53 +01:00
}
} ;
2017-02-17 10:26:08 +01:00
2018-05-25 15:00:27 +02:00
this . _presetItems . forEach ( function ( item ) {
2017-11-15 07:51:53 +01:00
return handlePresetItem ( item ) ;
} ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_setChoiceOrItem" ,
2017-11-15 07:51:53 +01:00
value : function _setChoiceOrItem ( item ) {
2018-05-28 16:13:55 +02:00
var _this24 = this ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var itemType = ( 0 , _utils . getType ) ( item ) . toLowerCase ( ) ;
var handleType = {
object : function object ( ) {
if ( ! item . value ) {
return ;
2019-02-09 19:13:25 +01:00
} // If we are dealing with a select input, we need to create an option first
2017-11-15 07:51:53 +01:00
// that is then selected. For text inputs we can just add items normally.
2019-02-09 19:13:25 +01:00
2018-05-28 16:13:55 +02:00
if ( ! _this24 . _isTextElement ) {
2018-06-07 17:54:11 +02:00
_this24 . _addChoice ( {
value : item . value ,
label : item . label ,
isSelected : true ,
isDisabled : false ,
customProperties : item . customProperties ,
placeholder : item . placeholder
} ) ;
2017-11-15 07:51:53 +01:00
} else {
2018-06-07 17:54:11 +02:00
_this24 . _addItem ( {
value : item . value ,
label : item . label ,
choiceId : item . id ,
customProperties : item . customProperties ,
placeholder : item . placeholder
} ) ;
2017-11-15 07:51:53 +01:00
}
} ,
string : function string ( ) {
2018-05-28 16:13:55 +02:00
if ( ! _this24 . _isTextElement ) {
2018-06-07 17:54:11 +02:00
_this24 . _addChoice ( {
value : item ,
label : item ,
isSelected : true ,
isDisabled : false
} ) ;
2017-11-15 07:51:53 +01:00
} else {
2018-06-07 17:54:11 +02:00
_this24 . _addItem ( {
value : item
} ) ;
2017-11-15 07:51:53 +01:00
}
}
} ;
handleType [ itemType ] ( ) ;
}
2017-11-13 20:13:37 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "_findAndSelectChoiceByValue" ,
2017-11-15 07:51:53 +01:00
value : function _findAndSelectChoiceByValue ( val ) {
2018-05-28 16:13:55 +02:00
var _this25 = this ;
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
var choices = this . _store . choices ; // Check 'value' property exists and the choice isn't already selected
2017-11-15 07:51:53 +01:00
var foundChoice = choices . find ( function ( choice ) {
2018-05-28 16:13:55 +02:00
return _this25 . config . itemComparer ( choice . value , val ) ;
2017-11-15 07:51:53 +01:00
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( foundChoice && ! foundChoice . selected ) {
2018-06-07 17:54:11 +02:00
this . _addItem ( {
value : foundChoice . value ,
label : foundChoice . label ,
2018-11-25 13:48:49 +01:00
choiceId : foundChoice . id ,
2018-06-07 17:54:11 +02:00
groupId : foundChoice . groupId ,
customProperties : foundChoice . customProperties ,
placeholder : foundChoice . placeholder ,
keyCode : foundChoice . keyCode
} ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
}
2018-05-25 15:00:27 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "_generateInstances" ,
2018-05-25 15:00:27 +02:00
value : function _generateInstances ( elements , config ) {
return elements . reduce ( function ( instances , element ) {
instances . push ( new Choices ( element , config ) ) ;
return instances ;
} , [ this ] ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_generatePlaceholderValue" ,
2018-05-25 15:00:27 +02:00
value : function _generatePlaceholderValue ( ) {
2018-05-27 12:57:21 +02:00
if ( this . _isSelectOneElement ) {
return false ;
2018-05-25 15:00:27 +02:00
}
2018-05-27 12:57:21 +02:00
return this . config . placeholder ? this . config . placeholderValue || this . passedElement . element . getAttribute ( 'placeholder' ) : false ;
2018-05-25 15:00:27 +02:00
}
2017-11-15 07:51:53 +01:00
/* ===== End of Private functions ====== */
} ] ) ;
return Choices ;
} ( ) ;
2019-02-09 19:13:25 +01:00
Choices . userDefaults = { } ; // We cannot export default here due to Webpack: https://github.com/webpack/webpack/issues/3929
2017-11-15 07:51:53 +01:00
module . exports = Choices ;
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 11 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
/ * !
2019-02-11 18:52:22 +01:00
* Fuse . js v3 . 4.2 - Lightweight fuzzy - search ( http : //fusejs.io)
2019-02-09 19:13:25 +01:00
*
2017-11-15 07:51:53 +01:00
* Copyright ( c ) 2012 - 2017 Kirollos Risk ( http : //kiro.me)
* All Rights Reserved . Apache Software License 2.0
2019-02-09 19:13:25 +01:00
*
2017-11-15 07:51:53 +01:00
* http : //www.apache.org/licenses/LICENSE-2.0
* /
( function webpackUniversalModuleDefinition ( root , factory ) {
if ( true )
module . exports = factory ( ) ;
2019-02-09 19:13:25 +01:00
else { }
2017-11-15 07:51:53 +01:00
} ) ( this , function ( ) {
return /******/ ( function ( modules ) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = { } ;
/******/
/******/ // The require function
/******/ function _ _webpack _require _ _ ( moduleId ) {
/******/
/******/ // Check if module is in cache
/******/ if ( installedModules [ moduleId ] ) {
/******/ return installedModules [ moduleId ] . exports ;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules [ moduleId ] = {
/******/ i : moduleId ,
/******/ l : false ,
/******/ exports : { }
/******/ } ;
/******/
/******/ // Execute the module function
/******/ modules [ moduleId ] . call ( module . exports , module , module . exports , _ _webpack _require _ _ ) ;
/******/
/******/ // Flag the module as loaded
/******/ module . l = true ;
/******/
/******/ // Return the exports of the module
/******/ return module . exports ;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ _ _webpack _require _ _ . m = modules ;
/******/
/******/ // expose the module cache
/******/ _ _webpack _require _ _ . c = installedModules ;
/******/
/******/ // define getter function for harmony exports
/******/ _ _webpack _require _ _ . d = function ( exports , name , getter ) {
/******/ if ( ! _ _webpack _require _ _ . o ( exports , name ) ) {
2019-02-09 19:13:25 +01:00
/******/ Object . defineProperty ( exports , name , { enumerable : true , get : getter } ) ;
/******/ }
/******/ } ;
/******/
/******/ // define __esModule on exports
/******/ _ _webpack _require _ _ . r = function ( exports ) {
/******/ if ( typeof Symbol !== 'undefined' && Symbol . toStringTag ) {
/******/ Object . defineProperty ( exports , Symbol . toStringTag , { value : 'Module' } ) ;
2017-11-15 07:51:53 +01:00
/******/ }
2019-02-09 19:13:25 +01:00
/******/ Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
/******/ } ;
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ _ _webpack _require _ _ . t = function ( value , mode ) {
/******/ if ( mode & 1 ) value = _ _webpack _require _ _ ( value ) ;
/******/ if ( mode & 8 ) return value ;
/******/ if ( ( mode & 4 ) && typeof value === 'object' && value && value . _ _esModule ) return value ;
/******/ var ns = Object . create ( null ) ;
/******/ _ _webpack _require _ _ . r ( ns ) ;
/******/ Object . defineProperty ( ns , 'default' , { enumerable : true , value : value } ) ;
/******/ if ( mode & 2 && typeof value != 'string' ) for ( var key in value ) _ _webpack _require _ _ . d ( ns , key , function ( key ) { return value [ key ] ; } . bind ( null , key ) ) ;
/******/ return ns ;
2017-11-15 07:51:53 +01:00
/******/ } ;
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ _ _webpack _require _ _ . n = function ( module ) {
/******/ var getter = module && module . _ _esModule ?
/******/ function getDefault ( ) { return module [ 'default' ] ; } :
/******/ function getModuleExports ( ) { return module ; } ;
/******/ _ _webpack _require _ _ . d ( getter , 'a' , getter ) ;
/******/ return getter ;
/******/ } ;
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ _ _webpack _require _ _ . o = function ( object , property ) { return Object . prototype . hasOwnProperty . call ( object , property ) ; } ;
/******/
/******/ // __webpack_public_path__
/******/ _ _webpack _require _ _ . p = "" ;
/******/
2019-02-09 19:13:25 +01:00
/******/
2017-11-15 07:51:53 +01:00
/******/ // Load entry module and return exports
2019-02-09 19:13:25 +01:00
/******/ return _ _webpack _require _ _ ( _ _webpack _require _ _ . s = "./src/index.js" ) ;
2017-11-15 07:51:53 +01:00
/******/ } )
/************************************************************************/
2019-02-09 19:13:25 +01:00
/******/ ( {
2016-08-23 08:24:45 +02:00
2019-02-09 19:13:25 +01:00
/***/ "./src/bitap/bitap_matched_indices.js" :
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * \
! * * * . / src / bitap / bitap _matched _indices . js * * * !
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/*! no static exports found */
/***/ ( function ( module , exports ) {
2016-08-23 08:24:45 +02:00
2019-02-11 18:52:22 +01:00
module . exports = function ( ) {
var matchmask = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ;
var minMatchCharLength = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 1 ;
var matchedIndices = [ ] ;
var start = - 1 ;
var end = - 1 ;
var i = 0 ;
2016-08-23 08:24:45 +02:00
2019-02-11 18:52:22 +01:00
for ( var len = matchmask . length ; i < len ; i += 1 ) {
var match = matchmask [ i ] ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
if ( match && start === - 1 ) {
start = i ;
} else if ( ! match && start !== - 1 ) {
end = i - 1 ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( end - start + 1 >= minMatchCharLength ) {
matchedIndices . push ( [ start , end ] ) ;
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
start = - 1 ;
2017-11-13 20:13:37 +01:00
}
2019-02-09 19:13:25 +01:00
} // (i-1 - start) + 1 => i - start
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
if ( matchmask [ i - 1 ] && i - start >= minMatchCharLength ) {
matchedIndices . push ( [ start , i - 1 ] ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return matchedIndices ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
/***/ "./src/bitap/bitap_pattern_alphabet.js" :
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * \
! * * * . / src / bitap / bitap _pattern _alphabet . js * * * !
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/*! no static exports found */
/***/ ( function ( module , exports ) {
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
module . exports = function ( pattern ) {
var mask = { } ;
var len = pattern . length ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
for ( var i = 0 ; i < len ; i += 1 ) {
2017-11-15 07:51:53 +01:00
mask [ pattern . charAt ( i ) ] = 0 ;
}
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
for ( var _i = 0 ; _i < len ; _i += 1 ) {
mask [ pattern . charAt ( _i ) ] |= 1 << len - _i - 1 ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return mask ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
/***/ "./src/bitap/bitap_regex_search.js" :
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * \
! * * * . / src / bitap / bitap _regex _search . js * * * !
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/*! no static exports found */
/***/ ( function ( module , exports ) {
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
var SPECIAL _CHARS _REGEX = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
module . exports = function ( text , pattern ) {
var tokenSeparator = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : / +/g ;
var regex = new RegExp ( pattern . replace ( SPECIAL _CHARS _REGEX , '\\$&' ) . replace ( tokenSeparator , '|' ) ) ;
var matches = text . match ( regex ) ;
var isMatch = ! ! matches ;
var matchedIndices = [ ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( isMatch ) {
2019-02-11 18:52:22 +01:00
for ( var i = 0 , matchesLen = matches . length ; i < matchesLen ; i += 1 ) {
var match = matches [ i ] ;
2017-11-15 07:51:53 +01:00
matchedIndices . push ( [ text . indexOf ( match ) , match . length - 1 ] ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return {
// TODO: revisit this score
score : isMatch ? 0.5 : 1 ,
2019-02-11 18:52:22 +01:00
isMatch : isMatch ,
matchedIndices : matchedIndices
2017-11-15 07:51:53 +01:00
} ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
/***/ "./src/bitap/bitap_score.js" :
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * \
! * * * . / src / bitap / bitap _score . js * * * !
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/*! no static exports found */
/***/ ( function ( module , exports ) {
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
module . exports = function ( pattern , _ref ) {
var _ref$errors = _ref . errors ,
errors = _ref$errors === void 0 ? 0 : _ref$errors ,
_ref$currentLocation = _ref . currentLocation ,
currentLocation = _ref$currentLocation === void 0 ? 0 : _ref$currentLocation ,
_ref$expectedLocation = _ref . expectedLocation ,
expectedLocation = _ref$expectedLocation === void 0 ? 0 : _ref$expectedLocation ,
_ref$distance = _ref . distance ,
distance = _ref$distance === void 0 ? 100 : _ref$distance ;
var accuracy = errors / pattern . length ;
var proximity = Math . abs ( expectedLocation - currentLocation ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! distance ) {
// Dodge divide by zero error.
return proximity ? 1.0 : accuracy ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return accuracy + proximity / distance ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/***/ "./src/bitap/bitap_search.js" :
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * \
! * * * . / src / bitap / bitap _search . js * * * !
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/*! no static exports found */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
var bitapScore = _ _webpack _require _ _ ( /*! ./bitap_score */ "./src/bitap/bitap_score.js" ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var matchedIndices = _ _webpack _require _ _ ( /*! ./bitap_matched_indices */ "./src/bitap/bitap_matched_indices.js" ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
module . exports = function ( text , pattern , patternAlphabet , _ref ) {
var _ref$location = _ref . location ,
location = _ref$location === void 0 ? 0 : _ref$location ,
_ref$distance = _ref . distance ,
distance = _ref$distance === void 0 ? 100 : _ref$distance ,
_ref$threshold = _ref . threshold ,
threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold ,
_ref$findAllMatches = _ref . findAllMatches ,
findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches ,
_ref$minMatchCharLeng = _ref . minMatchCharLength ,
minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng ;
var expectedLocation = location ; // Set starting location at beginning text and initialize the alphabet.
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var textLen = text . length ; // Highest score beyond which we give up.
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
var currentThreshold = threshold ; // Is there a nearby exact match? (speedup)
2017-11-13 20:13:37 +01:00
2019-02-11 18:52:22 +01:00
var bestLocation = text . indexOf ( pattern , expectedLocation ) ;
var patternLen = pattern . length ; // a mask of the matches
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var matchMask = [ ] ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
for ( var i = 0 ; i < textLen ; i += 1 ) {
2017-11-15 07:51:53 +01:00
matchMask [ i ] = 0 ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
if ( bestLocation !== - 1 ) {
2019-02-11 18:52:22 +01:00
var score = bitapScore ( pattern , {
2017-11-15 07:51:53 +01:00
errors : 0 ,
currentLocation : bestLocation ,
2019-02-11 18:52:22 +01:00
expectedLocation : expectedLocation ,
distance : distance
2017-11-15 07:51:53 +01:00
} ) ;
2019-02-09 19:13:25 +01:00
currentThreshold = Math . min ( score , currentThreshold ) ; // What about in the other direction? (speed up)
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
bestLocation = text . lastIndexOf ( pattern , expectedLocation + patternLen ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( bestLocation !== - 1 ) {
2019-02-11 18:52:22 +01:00
var _score = bitapScore ( pattern , {
2017-11-15 07:51:53 +01:00
errors : 0 ,
currentLocation : bestLocation ,
2019-02-11 18:52:22 +01:00
expectedLocation : expectedLocation ,
distance : distance
2017-11-15 07:51:53 +01:00
} ) ;
2019-02-11 18:52:22 +01:00
currentThreshold = Math . min ( _score , currentThreshold ) ;
2017-11-15 07:51:53 +01:00
}
2019-02-09 19:13:25 +01:00
} // Reset the best location
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
bestLocation = - 1 ;
2019-02-11 18:52:22 +01:00
var lastBitArr = [ ] ;
var finalScore = 1 ;
var binMax = patternLen + textLen ;
var mask = 1 << patternLen - 1 ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
for ( var _i = 0 ; _i < patternLen ; _i += 1 ) {
2017-11-15 07:51:53 +01:00
// 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.
2019-02-11 18:52:22 +01:00
var binMin = 0 ;
var binMid = binMax ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
while ( binMin < binMid ) {
2019-02-11 18:52:22 +01:00
var _score3 = bitapScore ( pattern , {
errors : _i ,
2017-11-15 07:51:53 +01:00
currentLocation : expectedLocation + binMid ,
2019-02-11 18:52:22 +01:00
expectedLocation : expectedLocation ,
distance : distance
2017-11-15 07:51:53 +01:00
} ) ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
if ( _score3 <= currentThreshold ) {
2017-11-15 07:51:53 +01:00
binMin = binMid ;
} else {
binMax = binMid ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
binMid = Math . floor ( ( binMax - binMin ) / 2 + binMin ) ;
2019-02-09 19:13:25 +01:00
} // Use the result from this iteration as the maximum for the next.
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
binMax = binMid ;
2019-02-11 18:52:22 +01:00
var start = Math . max ( 1 , expectedLocation - binMid + 1 ) ;
var finish = findAllMatches ? textLen : Math . min ( expectedLocation + binMid , textLen ) + patternLen ; // Initialize the bit array
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
var bitArr = Array ( finish + 2 ) ;
bitArr [ finish + 1 ] = ( 1 << _i ) - 1 ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
for ( var j = finish ; j >= start ; j -= 1 ) {
var currentLocation = j - 1 ;
var charMatch = patternAlphabet [ text . charAt ( currentLocation ) ] ;
2017-11-15 07:51:53 +01:00
if ( charMatch ) {
matchMask [ currentLocation ] = 1 ;
2019-02-09 19:13:25 +01:00
} // First pass: exact match
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
bitArr [ j ] = ( bitArr [ j + 1 ] << 1 | 1 ) & charMatch ; // Subsequent passes: fuzzy match
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
if ( _i !== 0 ) {
2017-11-15 07:51:53 +01:00
bitArr [ j ] |= ( lastBitArr [ j + 1 ] | lastBitArr [ j ] ) << 1 | 1 | lastBitArr [ j + 1 ] ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
if ( bitArr [ j ] & mask ) {
finalScore = bitapScore ( pattern , {
2019-02-11 18:52:22 +01:00
errors : _i ,
currentLocation : currentLocation ,
expectedLocation : expectedLocation ,
distance : distance
2019-02-09 19:13:25 +01:00
} ) ; // This match will almost certainly be better than any existing match.
2017-11-15 07:51:53 +01:00
// But check anyway.
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( finalScore <= currentThreshold ) {
// Indeed it is
currentThreshold = finalScore ;
2019-02-09 19:13:25 +01:00
bestLocation = currentLocation ; // Already passed `loc`, downhill from here on in.
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( bestLocation <= expectedLocation ) {
break ;
2019-02-09 19:13:25 +01:00
} // When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
start = Math . max ( 1 , 2 * expectedLocation - bestLocation ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-13 20:13:37 +01:00
}
2019-02-09 19:13:25 +01:00
} // No hope for a (better) match at greater error levels.
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var _score2 = bitapScore ( pattern , {
errors : _i + 1 ,
2017-11-15 07:51:53 +01:00
currentLocation : expectedLocation ,
2019-02-11 18:52:22 +01:00
expectedLocation : expectedLocation ,
distance : distance
2019-02-09 19:13:25 +01:00
} ) ; // console.log('score', score, finalScore)
2017-11-13 20:13:37 +01:00
2019-02-11 18:52:22 +01:00
if ( _score2 > currentThreshold ) {
2017-11-15 07:51:53 +01:00
break ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
lastBitArr = bitArr ;
2019-02-09 19:13:25 +01:00
} // console.log('FINAL SCORE', finalScore)
2017-11-15 07:51:53 +01:00
// Count exact matches (those with a score of 0) to be "almost" exact
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return {
isMatch : bestLocation >= 0 ,
score : finalScore === 0 ? 0.001 : finalScore ,
matchedIndices : matchedIndices ( matchMask , minMatchCharLength )
} ;
} ;
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/***/ "./src/bitap/index.js" :
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * \
! * * * . / src / bitap / index . js * * * !
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/*! no static exports found */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-15 07:51:53 +01:00
2019-02-11 18:52:22 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
var bitapRegexSearch = _ _webpack _require _ _ ( /*! ./bitap_regex_search */ "./src/bitap/bitap_regex_search.js" ) ;
var bitapSearch = _ _webpack _require _ _ ( /*! ./bitap_search */ "./src/bitap/bitap_search.js" ) ;
var patternAlphabet = _ _webpack _require _ _ ( /*! ./bitap_pattern_alphabet */ "./src/bitap/bitap_pattern_alphabet.js" ) ;
var Bitap =
/*#__PURE__*/
function ( ) {
function Bitap ( pattern , _ref ) {
var _ref$location = _ref . location ,
location = _ref$location === void 0 ? 0 : _ref$location ,
_ref$distance = _ref . distance ,
distance = _ref$distance === void 0 ? 100 : _ref$distance ,
_ref$threshold = _ref . threshold ,
threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold ,
_ref$maxPatternLength = _ref . maxPatternLength ,
maxPatternLength = _ref$maxPatternLength === void 0 ? 32 : _ref$maxPatternLength ,
_ref$isCaseSensitive = _ref . isCaseSensitive ,
isCaseSensitive = _ref$isCaseSensitive === void 0 ? false : _ref$isCaseSensitive ,
_ref$tokenSeparator = _ref . tokenSeparator ,
tokenSeparator = _ref$tokenSeparator === void 0 ? / +/g : _ref$tokenSeparator ,
_ref$findAllMatches = _ref . findAllMatches ,
findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches ,
_ref$minMatchCharLeng = _ref . minMatchCharLength ,
minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng ;
_classCallCheck ( this , Bitap ) ;
2017-11-15 07:51:53 +01:00
this . options = {
2019-02-11 18:52:22 +01:00
location : location ,
distance : distance ,
threshold : threshold ,
maxPatternLength : maxPatternLength ,
isCaseSensitive : isCaseSensitive ,
tokenSeparator : tokenSeparator ,
findAllMatches : findAllMatches ,
minMatchCharLength : minMatchCharLength
2017-11-15 07:51:53 +01:00
} ;
2019-02-09 19:13:25 +01:00
this . pattern = this . options . isCaseSensitive ? pattern : pattern . toLowerCase ( ) ;
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
if ( this . pattern . length <= maxPatternLength ) {
this . patternAlphabet = patternAlphabet ( this . pattern ) ;
}
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
_createClass ( Bitap , [ {
key : "search" ,
value : function search ( text ) {
if ( ! this . options . isCaseSensitive ) {
text = text . toLowerCase ( ) ;
} // Exact match
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
if ( this . pattern === text ) {
return {
isMatch : true ,
score : 0 ,
matchedIndices : [ [ 0 , text . length - 1 ] ]
} ;
} // When pattern length is greater than the machine word length, just do a a regex comparison
var _this$options = this . options ,
maxPatternLength = _this$options . maxPatternLength ,
tokenSeparator = _this$options . tokenSeparator ;
if ( this . pattern . length > maxPatternLength ) {
return bitapRegexSearch ( text , this . pattern , tokenSeparator ) ;
} // Otherwise, use Bitap algorithm
var _this$options2 = this . options ,
location = _this$options2 . location ,
distance = _this$options2 . distance ,
threshold = _this$options2 . threshold ,
findAllMatches = _this$options2 . findAllMatches ,
minMatchCharLength = _this$options2 . minMatchCharLength ;
return bitapSearch ( text , this . pattern , this . patternAlphabet , {
location : location ,
distance : distance ,
threshold : threshold ,
findAllMatches : findAllMatches ,
minMatchCharLength : minMatchCharLength
} ) ;
}
} ] ) ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
return Bitap ;
} ( ) ; // let x = new Bitap("od mn war", {})
2019-02-09 19:13:25 +01:00
// let result = x.search("Old Man's War")
// console.log(result)
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
module . exports = Bitap ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
/***/ } ) ,
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
/***/ "./src/helpers/deep_value.js" :
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * \
! * * * . / src / helpers / deep _value . js * * * !
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/*! no static exports found */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
var isArray = _ _webpack _require _ _ ( /*! ./is_array */ "./src/helpers/is_array.js" ) ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
var deepValue = function deepValue ( obj , path , list ) {
2019-02-09 19:13:25 +01:00
if ( ! path ) {
// If there's no path left, we've gotten to the object we care about.
list . push ( obj ) ;
} else {
2019-02-11 18:52:22 +01:00
var dotIndex = path . indexOf ( '.' ) ;
var firstSegment = path ;
var remaining = null ;
2019-02-09 19:13:25 +01:00
if ( dotIndex !== - 1 ) {
firstSegment = path . slice ( 0 , dotIndex ) ;
remaining = path . slice ( dotIndex + 1 ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
var value = obj [ firstSegment ] ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
if ( value !== null && value !== undefined ) {
if ( ! remaining && ( typeof value === 'string' || typeof value === 'number' ) ) {
list . push ( value . toString ( ) ) ;
} else if ( isArray ( value ) ) {
// Search each item in the array.
2019-02-11 18:52:22 +01:00
for ( var i = 0 , len = value . length ; i < len ; i += 1 ) {
2019-02-09 19:13:25 +01:00
deepValue ( value [ i ] , remaining , list ) ;
2017-11-13 20:13:37 +01:00
}
2019-02-09 19:13:25 +01:00
} else if ( remaining ) {
// An object. Recurse further.
deepValue ( value , remaining , list ) ;
}
}
}
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
return list ;
} ;
2019-02-11 18:52:22 +01:00
module . exports = function ( obj , path ) {
2019-02-09 19:13:25 +01:00
return deepValue ( obj , path , [ ] ) ;
} ;
/***/ } ) ,
/***/ "./src/helpers/is_array.js" :
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * \
! * * * . / src / helpers / is _array . js * * * !
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/*! no static exports found */
/***/ ( function ( module , exports ) {
2019-02-11 18:52:22 +01:00
module . exports = function ( obj ) {
return ! Array . isArray ? Object . prototype . toString . call ( obj ) === '[object Array]' : Array . isArray ( obj ) ;
} ;
2019-02-09 19:13:25 +01:00
/***/ } ) ,
/***/ "./src/index.js" :
/ * ! * * * * * * * * * * * * * * * * * * * * * * ! * \
! * * * . / src / index . js * * * !
\ * * * * * * * * * * * * * * * * * * * * * * /
/*! no static exports found */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2019-02-11 18:52:22 +01:00
function _typeof ( obj ) { if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var Bitap = _ _webpack _require _ _ ( /*! ./bitap */ "./src/bitap/index.js" ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var deepValue = _ _webpack _require _ _ ( /*! ./helpers/deep_value */ "./src/helpers/deep_value.js" ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var isArray = _ _webpack _require _ _ ( /*! ./helpers/is_array */ "./src/helpers/is_array.js" ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var Fuse =
/*#__PURE__*/
function ( ) {
function Fuse ( list , _ref ) {
var _ref$location = _ref . location ,
location = _ref$location === void 0 ? 0 : _ref$location ,
_ref$distance = _ref . distance ,
distance = _ref$distance === void 0 ? 100 : _ref$distance ,
_ref$threshold = _ref . threshold ,
threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold ,
_ref$maxPatternLength = _ref . maxPatternLength ,
maxPatternLength = _ref$maxPatternLength === void 0 ? 32 : _ref$maxPatternLength ,
_ref$caseSensitive = _ref . caseSensitive ,
caseSensitive = _ref$caseSensitive === void 0 ? false : _ref$caseSensitive ,
_ref$tokenSeparator = _ref . tokenSeparator ,
tokenSeparator = _ref$tokenSeparator === void 0 ? / +/g : _ref$tokenSeparator ,
_ref$findAllMatches = _ref . findAllMatches ,
findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches ,
_ref$minMatchCharLeng = _ref . minMatchCharLength ,
minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng ,
_ref$id = _ref . id ,
id = _ref$id === void 0 ? null : _ref$id ,
_ref$keys = _ref . keys ,
keys = _ref$keys === void 0 ? [ ] : _ref$keys ,
_ref$shouldSort = _ref . shouldSort ,
shouldSort = _ref$shouldSort === void 0 ? true : _ref$shouldSort ,
_ref$getFn = _ref . getFn ,
getFn = _ref$getFn === void 0 ? deepValue : _ref$getFn ,
_ref$sortFn = _ref . sortFn ,
sortFn = _ref$sortFn === void 0 ? function ( a , b ) {
return a . score - b . score ;
} : _ref$sortFn ,
_ref$tokenize = _ref . tokenize ,
tokenize = _ref$tokenize === void 0 ? false : _ref$tokenize ,
_ref$matchAllTokens = _ref . matchAllTokens ,
matchAllTokens = _ref$matchAllTokens === void 0 ? false : _ref$matchAllTokens ,
_ref$includeMatches = _ref . includeMatches ,
includeMatches = _ref$includeMatches === void 0 ? false : _ref$includeMatches ,
_ref$includeScore = _ref . includeScore ,
includeScore = _ref$includeScore === void 0 ? false : _ref$includeScore ,
_ref$verbose = _ref . verbose ,
verbose = _ref$verbose === void 0 ? false : _ref$verbose ;
_classCallCheck ( this , Fuse ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
this . options = {
location : location ,
distance : distance ,
threshold : threshold ,
maxPatternLength : maxPatternLength ,
isCaseSensitive : caseSensitive ,
tokenSeparator : tokenSeparator ,
findAllMatches : findAllMatches ,
minMatchCharLength : minMatchCharLength ,
id : id ,
keys : keys ,
includeMatches : includeMatches ,
includeScore : includeScore ,
shouldSort : shouldSort ,
getFn : getFn ,
sortFn : sortFn ,
verbose : verbose ,
tokenize : tokenize ,
matchAllTokens : matchAllTokens
} ;
this . setCollection ( list ) ;
2019-02-09 19:13:25 +01:00
}
2019-02-11 18:52:22 +01:00
_createClass ( Fuse , [ {
key : "setCollection" ,
value : function setCollection ( list ) {
this . list = list ;
return list ;
}
} , {
key : "search" ,
value : function search ( pattern ) {
var opts = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : {
limit : false
} ;
this . _log ( "---------\nSearch pattern: \"" . concat ( pattern , "\"" ) ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var _this$ _prepareSearche = this . _prepareSearchers ( pattern ) ,
tokenSearchers = _this$ _prepareSearche . tokenSearchers ,
fullSearcher = _this$ _prepareSearche . fullSearcher ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var _this$ _search = this . _search ( tokenSearchers , fullSearcher ) ,
weights = _this$ _search . weights ,
results = _this$ _search . results ;
this . _computeScore ( weights , results ) ;
if ( this . options . shouldSort ) {
this . _sort ( results ) ;
2019-02-09 19:13:25 +01:00
}
2019-02-11 18:52:22 +01:00
if ( opts . limit && typeof opts . limit === 'number' ) {
results = results . slice ( 0 , opts . limit ) ;
}
return this . _format ( results ) ;
2019-02-09 19:13:25 +01:00
}
2019-02-11 18:52:22 +01:00
} , {
key : "_prepareSearchers" ,
value : function _prepareSearchers ( ) {
var pattern = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : '' ;
var tokenSearchers = [ ] ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
if ( this . options . tokenize ) {
// Tokenize on the separator
var tokens = pattern . split ( this . options . tokenSeparator ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
for ( var i = 0 , len = tokens . length ; i < len ; i += 1 ) {
tokenSearchers . push ( new Bitap ( tokens [ i ] , this . options ) ) ;
}
2019-02-09 19:13:25 +01:00
}
2019-02-11 18:52:22 +01:00
var fullSearcher = new Bitap ( pattern , this . options ) ;
2019-02-09 19:13:25 +01:00
return {
2019-02-11 18:52:22 +01:00
tokenSearchers : tokenSearchers ,
fullSearcher : fullSearcher
2019-02-09 19:13:25 +01:00
} ;
2019-02-11 18:52:22 +01:00
}
} , {
key : "_search" ,
value : function _search ( ) {
var tokenSearchers = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ;
var fullSearcher = arguments . length > 1 ? arguments [ 1 ] : undefined ;
var list = this . list ;
var resultMap = { } ;
var results = [ ] ; // Check the first item in the list, if it's a string, then we assume
// that every item in the list is also a string, and thus it's a flattened array.
if ( typeof list [ 0 ] === 'string' ) {
// Iterate over every item
for ( var i = 0 , len = list . length ; i < len ; i += 1 ) {
this . _analyze ( {
key : '' ,
value : list [ i ] ,
record : i ,
index : i
} , {
resultMap : resultMap ,
results : results ,
tokenSearchers : tokenSearchers ,
fullSearcher : fullSearcher
} ) ;
}
return {
weights : null ,
results : results
} ;
} // Otherwise, the first item is an Object (hopefully), and thus the searching
// is done on the values of the keys of each item.
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var weights = { } ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
for ( var _i = 0 , _len = list . length ; _i < _len ; _i += 1 ) {
var item = list [ _i ] ; // Iterate over every key
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
for ( var j = 0 , keysLen = this . options . keys . length ; j < keysLen ; j += 1 ) {
var key = this . options . keys [ j ] ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
if ( typeof key !== 'string' ) {
weights [ key . name ] = {
weight : 1 - key . weight || 1
} ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
if ( key . weight <= 0 || key . weight > 1 ) {
throw new Error ( 'Key weight has to be > 0 and <= 1' ) ;
}
key = key . name ;
} else {
weights [ key ] = {
weight : 1
} ;
2017-11-07 12:59:49 +01:00
}
2019-02-11 18:52:22 +01:00
this . _analyze ( {
key : key ,
value : this . options . getFn ( item , key ) ,
record : item ,
index : _i
} , {
resultMap : resultMap ,
results : results ,
tokenSearchers : tokenSearchers ,
fullSearcher : fullSearcher
} ) ;
2017-11-15 07:51:53 +01:00
}
2019-02-09 19:13:25 +01:00
}
2019-02-11 18:52:22 +01:00
return {
weights : weights ,
results : results
} ;
2019-02-09 19:13:25 +01:00
}
2019-02-11 18:52:22 +01:00
} , {
key : "_analyze" ,
value : function _analyze ( _ref2 , _ref3 ) {
var key = _ref2 . key ,
_ref2$arrayIndex = _ref2 . arrayIndex ,
arrayIndex = _ref2$arrayIndex === void 0 ? - 1 : _ref2$arrayIndex ,
value = _ref2 . value ,
record = _ref2 . record ,
index = _ref2 . index ;
var _ref3$tokenSearchers = _ref3 . tokenSearchers ,
tokenSearchers = _ref3$tokenSearchers === void 0 ? [ ] : _ref3$tokenSearchers ,
_ref3$fullSearcher = _ref3 . fullSearcher ,
fullSearcher = _ref3$fullSearcher === void 0 ? [ ] : _ref3$fullSearcher ,
_ref3$resultMap = _ref3 . resultMap ,
resultMap = _ref3$resultMap === void 0 ? { } : _ref3$resultMap ,
_ref3$results = _ref3 . results ,
results = _ref3$results === void 0 ? [ ] : _ref3$results ;
// Check if the texvaluet can be searched
if ( value === undefined || value === null ) {
return ;
}
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
var exists = false ;
var averageScore = - 1 ;
var numTextMatches = 0 ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
if ( typeof value === 'string' ) {
this . _log ( "\nKey: " . concat ( key === '' ? '-' : key ) ) ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
var mainSearchResult = fullSearcher . search ( value ) ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
this . _log ( "Full text: \"" . concat ( value , "\", score: " ) . concat ( mainSearchResult . score ) ) ;
2017-11-07 12:59:49 +01:00
2019-02-11 18:52:22 +01:00
if ( this . options . tokenize ) {
var words = value . split ( this . options . tokenSeparator ) ;
var scores = [ ] ;
2017-11-15 07:51:53 +01:00
2019-02-11 18:52:22 +01:00
for ( var i = 0 ; i < tokenSearchers . length ; i += 1 ) {
var tokenSearcher = tokenSearchers [ i ] ;
2017-11-15 07:51:53 +01:00
2019-02-11 18:52:22 +01:00
this . _log ( "\nPattern: \"" . concat ( tokenSearcher . pattern , "\"" ) ) ; // let tokenScores = []
2017-11-15 07:51:53 +01:00
2019-02-11 18:52:22 +01:00
var hasMatchInText = false ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
for ( var j = 0 ; j < words . length ; j += 1 ) {
var word = words [ j ] ;
var tokenSearchResult = tokenSearcher . search ( word ) ;
var obj = { } ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
if ( tokenSearchResult . isMatch ) {
obj [ word ] = tokenSearchResult . score ;
exists = true ;
hasMatchInText = true ;
scores . push ( tokenSearchResult . score ) ;
} else {
obj [ word ] = 1 ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
if ( ! this . options . matchAllTokens ) {
scores . push ( 1 ) ;
}
2017-11-15 07:51:53 +01:00
}
2019-02-11 18:52:22 +01:00
this . _log ( "Token: \"" . concat ( word , "\", score: " ) . concat ( obj [ word ] ) ) ; // tokenScores.push(obj)
2016-08-23 08:24:45 +02:00
2019-02-11 18:52:22 +01:00
}
2017-11-15 07:51:53 +01:00
2019-02-11 18:52:22 +01:00
if ( hasMatchInText ) {
numTextMatches += 1 ;
}
2019-02-09 19:13:25 +01:00
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
averageScore = scores [ 0 ] ;
var scoresLen = scores . length ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
for ( var _i2 = 1 ; _i2 < scoresLen ; _i2 += 1 ) {
averageScore += scores [ _i2 ] ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
averageScore = averageScore / scoresLen ;
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
this . _log ( 'Token score average:' , averageScore ) ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
var finalScore = mainSearchResult . score ;
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
if ( averageScore > - 1 ) {
finalScore = ( finalScore + averageScore ) / 2 ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
this . _log ( 'Score average:' , finalScore ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var checkTextMatches = this . options . tokenize && this . options . matchAllTokens ? numTextMatches >= tokenSearchers . length : true ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
this . _log ( "\nCheck Matches: " . concat ( checkTextMatches ) ) ; // If a match is found, add the item to <rawResults>, including its score
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
if ( ( exists || mainSearchResult . isMatch ) && checkTextMatches ) {
// Check if the item already exists in our results
var existingResult = resultMap [ index ] ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
if ( existingResult ) {
// Use the lowest score
// existingResult.score, bitapResult.score
existingResult . output . push ( {
key : key ,
arrayIndex : arrayIndex ,
value : value ,
2019-02-09 19:13:25 +01:00
score : finalScore ,
matchedIndices : mainSearchResult . matchedIndices
2019-02-11 18:52:22 +01:00
} ) ;
} else {
// Add it to the raw result list
resultMap [ index ] = {
item : record ,
output : [ {
key : key ,
arrayIndex : arrayIndex ,
value : value ,
score : finalScore ,
matchedIndices : mainSearchResult . matchedIndices
} ]
} ;
results . push ( resultMap [ index ] ) ;
}
}
} else if ( isArray ( value ) ) {
for ( var _i3 = 0 , len = value . length ; _i3 < len ; _i3 += 1 ) {
this . _analyze ( {
key : key ,
arrayIndex : _i3 ,
value : value [ _i3 ] ,
record : record ,
index : index
} , {
resultMap : resultMap ,
results : results ,
tokenSearchers : tokenSearchers ,
fullSearcher : fullSearcher
} ) ;
2018-05-25 15:00:27 +02:00
}
2019-02-09 19:13:25 +01:00
}
2018-05-25 15:00:27 +02:00
}
2019-02-11 18:52:22 +01:00
} , {
key : "_computeScore" ,
value : function _computeScore ( weights , results ) {
this . _log ( '\n\nComputing score:\n' ) ;
for ( var i = 0 , len = results . length ; i < len ; i += 1 ) {
var output = results [ i ] . output ;
var scoreLen = output . length ;
var currScore = 1 ;
var bestScore = 1 ;
for ( var j = 0 ; j < scoreLen ; j += 1 ) {
var weight = weights ? weights [ output [ j ] . key ] . weight : 1 ;
var score = weight === 1 ? output [ j ] . score : output [ j ] . score || 0.001 ;
var nScore = score * weight ;
if ( weight !== 1 ) {
bestScore = Math . min ( bestScore , nScore ) ;
} else {
output [ j ] . nScore = nScore ;
currScore *= nScore ;
}
2018-05-25 15:00:27 +02:00
}
2019-02-11 18:52:22 +01:00
results [ i ] . score = bestScore === 1 ? currScore : bestScore ;
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
this . _log ( results [ i ] ) ;
}
2018-05-25 15:00:27 +02:00
}
2019-02-11 18:52:22 +01:00
} , {
key : "_sort" ,
value : function _sort ( results ) {
this . _log ( '\n\nSorting....' ) ;
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
results . sort ( this . options . sortFn ) ;
}
} , {
key : "_format" ,
value : function _format ( results ) {
var finalOutput = [ ] ;
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
if ( this . options . verbose ) {
var cache = [ ] ;
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
this . _log ( '\n\nOutput:\n\n' , JSON . stringify ( results , function ( key , value ) {
if ( _typeof ( value ) === 'object' && value !== null ) {
if ( cache . indexOf ( value ) !== - 1 ) {
// Circular reference found, discard key
return ;
} // Store value in our collection
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
cache . push ( value ) ;
}
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
return value ;
} ) ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
cache = null ;
}
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var transformers = [ ] ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
if ( this . options . includeMatches ) {
transformers . push ( function ( result , data ) {
var output = result . output ;
data . matches = [ ] ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
for ( var i = 0 , len = output . length ; i < len ; i += 1 ) {
var item = output [ i ] ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
if ( item . matchedIndices . length === 0 ) {
continue ;
}
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
var obj = {
indices : item . matchedIndices ,
value : item . value
} ;
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
if ( item . key ) {
obj . key = item . key ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
if ( item . hasOwnProperty ( 'arrayIndex' ) && item . arrayIndex > - 1 ) {
obj . arrayIndex = item . arrayIndex ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
data . matches . push ( obj ) ;
2019-02-09 19:13:25 +01:00
}
2019-02-11 18:52:22 +01:00
} ) ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
if ( this . options . includeScore ) {
transformers . push ( function ( result , data ) {
data . score = result . score ;
} ) ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
for ( var i = 0 , len = results . length ; i < len ; i += 1 ) {
var result = results [ i ] ;
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
if ( this . options . id ) {
result . item = this . options . getFn ( result . item , this . options . id ) [ 0 ] ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
if ( ! transformers . length ) {
finalOutput . push ( result . item ) ;
continue ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
var data = {
item : result . item
} ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
for ( var j = 0 , _len2 = transformers . length ; j < _len2 ; j += 1 ) {
transformers [ j ] ( result , data ) ;
}
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
finalOutput . push ( data ) ;
2018-05-25 15:00:27 +02:00
}
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
return finalOutput ;
2018-05-25 15:00:27 +02:00
}
2019-02-11 18:52:22 +01:00
} , {
key : "_log" ,
value : function _log ( ) {
if ( this . options . verbose ) {
var _console ;
2018-05-25 15:00:27 +02:00
2019-02-11 18:52:22 +01:00
( _console = console ) . log . apply ( _console , arguments ) ;
}
2019-02-09 19:13:25 +01:00
}
2019-02-11 18:52:22 +01:00
} ] ) ;
2019-02-09 19:13:25 +01:00
2019-02-11 18:52:22 +01:00
return Fuse ;
} ( ) ;
2018-05-25 15:00:27 +02:00
module . exports = Fuse ;
/***/ } )
2019-02-09 19:13:25 +01:00
/******/ } ) ;
2018-05-25 15:00:27 +02:00
} ) ;
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 12 */
2018-10-13 12:19:24 +02:00
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
2018-05-25 15:00:27 +02:00
"use strict" ;
2019-02-09 19:13:25 +01:00
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
2018-10-13 12:19:24 +02:00
var isMergeableObject = function isMergeableObject ( value ) {
return isNonNullObject ( value )
&& ! isSpecial ( value )
} ;
2018-05-25 15:00:27 +02:00
2018-10-13 12:19:24 +02:00
function isNonNullObject ( value ) {
return ! ! value && typeof value === 'object'
}
2018-05-25 15:00:27 +02:00
2018-10-13 12:19:24 +02:00
function isSpecial ( value ) {
var stringValue = Object . prototype . toString . call ( value ) ;
return stringValue === '[object RegExp]'
|| stringValue === '[object Date]'
|| isReactElement ( value )
}
// 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 ;
function isReactElement ( value ) {
return value . $$typeof === REACT _ELEMENT _TYPE
}
function emptyTarget ( val ) {
return Array . isArray ( val ) ? [ ] : { }
}
function cloneUnlessOtherwiseSpecified ( value , options ) {
return ( options . clone !== false && options . isMergeableObject ( value ) )
? deepmerge ( emptyTarget ( value ) , value , options )
: value
}
function defaultArrayMerge ( target , source , options ) {
return target . concat ( source ) . map ( function ( element ) {
return cloneUnlessOtherwiseSpecified ( element , options )
} )
}
function mergeObject ( target , source , options ) {
var destination = { } ;
if ( options . isMergeableObject ( target ) ) {
Object . keys ( target ) . forEach ( function ( key ) {
destination [ key ] = cloneUnlessOtherwiseSpecified ( target [ key ] , options ) ;
} ) ;
}
Object . keys ( source ) . forEach ( function ( key ) {
if ( ! options . isMergeableObject ( source [ key ] ) || ! target [ key ] ) {
destination [ key ] = cloneUnlessOtherwiseSpecified ( source [ key ] , options ) ;
} else {
destination [ key ] = deepmerge ( target [ key ] , source [ key ] , options ) ;
}
} ) ;
return destination
}
function deepmerge ( target , source , options ) {
options = options || { } ;
options . arrayMerge = options . arrayMerge || defaultArrayMerge ;
options . isMergeableObject = options . isMergeableObject || isMergeableObject ;
var sourceIsArray = Array . isArray ( source ) ;
var targetIsArray = Array . isArray ( target ) ;
var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray ;
if ( ! sourceAndTargetTypesMatch ) {
return cloneUnlessOtherwiseSpecified ( source , options )
} else if ( sourceIsArray ) {
return options . arrayMerge ( target , source , options )
} else {
return mergeObject ( target , source , options )
}
}
deepmerge . all = function deepmergeAll ( array , options ) {
if ( ! Array . isArray ( array ) ) {
throw new Error ( 'first argument should be an array' )
}
return array . reduce ( function ( prev , next ) {
return deepmerge ( prev , next , options )
} , { } )
} ;
2019-02-09 19:13:25 +01:00
var deepmerge _1 = deepmerge ;
/* harmony default export */ _ _webpack _exports _ _ [ "default" ] = ( deepmerge _1 ) ;
2018-10-27 17:45:19 +02:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 13 */
2018-10-27 17:45:19 +02:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
2019-02-09 19:13:25 +01:00
_ _webpack _require _ _ ( 14 ) ;
2018-10-27 17:45:19 +02:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 14 */
2018-05-25 15:00:27 +02:00
/***/ ( function ( module , exports ) {
// Polyfill for creating CustomEvents on IE9/10/11
// code pulled from:
// https://github.com/d4tocchini/customevent-polyfill
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Polyfill
try {
var ce = new window . CustomEvent ( 'test' ) ;
ce . preventDefault ( ) ;
if ( ce . defaultPrevented !== true ) {
// IE has problems with .preventDefault() on custom events
// http://stackoverflow.com/questions/23349191
throw new Error ( 'Could not prevent default' ) ;
2017-11-15 07:51:53 +01:00
}
2018-05-25 15:00:27 +02:00
} catch ( e ) {
var CustomEvent = function ( event , params ) {
var evt , origPrevent ;
params = params || {
bubbles : false ,
cancelable : false ,
detail : undefined
} ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
evt = document . createEvent ( "CustomEvent" ) ;
evt . initCustomEvent ( event , params . bubbles , params . cancelable , params . detail ) ;
origPrevent = evt . preventDefault ;
evt . preventDefault = function ( ) {
origPrevent . call ( this ) ;
try {
Object . defineProperty ( this , 'defaultPrevented' , {
get : function ( ) {
return true ;
}
} ) ;
} catch ( e ) {
this . defaultPrevented = true ;
}
} ;
return evt ;
} ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
CustomEvent . prototype = window . Event . prototype ;
window . CustomEvent = CustomEvent ; // expose definition to window
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 15 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . default = void 0 ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _redux = _ _webpack _require _ _ ( 6 ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _index = _interopRequireDefault ( _ _webpack _require _ _ ( 17 ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
var Store =
/*#__PURE__*/
function ( ) {
2017-11-15 07:51:53 +01:00
function Store ( ) {
_classCallCheck ( this , Store ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
this . _store = ( 0 , _redux . createStore ) ( _index . default , window . _ _REDUX _DEVTOOLS _EXTENSION _ _ && window . _ _REDUX _DEVTOOLS _EXTENSION _ _ ( ) ) ;
2017-11-15 07:51:53 +01:00
}
/ * *
* Subscribe store to function call ( wrapped Redux method )
* @ param { Function } onChange Function to trigger when state changes
* @ return
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
_createClass ( Store , [ {
2019-02-09 19:13:25 +01:00
key : "subscribe" ,
2017-11-15 07:51:53 +01:00
value : function subscribe ( onChange ) {
2018-05-25 15:00:27 +02:00
this . _store . subscribe ( onChange ) ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Dispatch event to store ( wrapped Redux method )
* @ param { Function } action Action function to trigger
* @ return
2017-11-07 12:59:49 +01:00
* /
} , {
2019-02-09 19:13:25 +01:00
key : "dispatch" ,
2017-11-15 07:51:53 +01:00
value : function dispatch ( action ) {
2018-05-25 15:00:27 +02:00
this . _store . dispatch ( action ) ;
2017-11-15 07:51:53 +01:00
}
/ * *
* Get store object ( wrapping Redux method )
* @ return { Object } State
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "isLoading" ,
2018-04-25 10:20:59 +02:00
2019-01-26 13:36:47 +01:00
/ * *
* Get loading state from store
* @ return { Boolean } Loading State
* /
value : function isLoading ( ) {
return this . state . general . loading ;
}
2018-04-25 10:20:59 +02:00
/ * *
* Get single choice by it ' s ID
* @ return { Object } Found choice
* /
2019-01-26 13:36:47 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "getChoiceById" ,
2018-04-25 10:20:59 +02:00
value : function getChoiceById ( id ) {
if ( id ) {
var choices = this . activeChoices ;
var foundChoice = choices . find ( function ( choice ) {
return choice . id === parseInt ( id , 10 ) ;
} ) ;
return foundChoice ;
}
2019-02-09 19:13:25 +01:00
2018-04-25 10:20:59 +02:00
return false ;
}
/ * *
* Get group by group id
* @ param { Number } id Group ID
* @ return { Object } Group data
* /
} , {
2019-02-09 19:13:25 +01:00
key : "getGroupById" ,
2018-04-25 10:20:59 +02:00
value : function getGroupById ( id ) {
return this . groups . find ( function ( group ) {
return group . id === parseInt ( id , 10 ) ;
} ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "state" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
2018-05-25 15:00:27 +02:00
return this . _store . getState ( ) ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Get items from store
* @ return { Array } Item objects
2017-11-07 12:59:49 +01:00
* /
} , {
2019-02-09 19:13:25 +01:00
key : "items" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
return this . state . items ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Get active items from store
* @ return { Array } Item objects
2017-11-07 12:59:49 +01:00
* /
} , {
2019-02-09 19:13:25 +01:00
key : "activeItems" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
return this . items . filter ( function ( item ) {
2017-11-15 07:51:53 +01:00
return item . active === true ;
2018-02-02 12:08:03 +01:00
} ) ;
2017-11-15 07:51:53 +01:00
}
/ * *
2018-05-28 16:13:55 +02:00
* Get highlighted items from store
* @ return { Array } Item objects
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "highlightedActiveItems" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
return this . items . filter ( function ( item ) {
2018-02-02 12:08:03 +01:00
return item . active && item . highlighted ;
} ) ;
2017-11-15 07:51:53 +01:00
}
/ * *
* Get choices from store
* @ return { Array } Option objects
* /
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "choices" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
return this . state . choices ;
2017-11-15 07:51:53 +01:00
}
/ * *
* Get active choices from store
* @ return { Array } Option objects
* /
2016-08-23 08:24:45 +02:00
2017-11-13 20:13:37 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "activeChoices" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
var choices = this . choices ;
2017-11-15 07:51:53 +01:00
var values = choices . filter ( function ( choice ) {
return choice . active === true ;
} ) ;
return values ;
}
/ * *
* Get selectable choices from store
* @ return { Array } Option objects
* /
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "selectableChoices" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
return this . choices . filter ( function ( choice ) {
2017-11-15 07:51:53 +01:00
return choice . disabled !== true ;
} ) ;
}
/ * *
* Get choices that can be searched ( excluding placeholders )
* @ return { Array } Option objects
* /
2016-10-26 16:43:15 +02:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "searchableChoices" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
return this . selectableChoices . filter ( function ( choice ) {
2017-11-15 07:51:53 +01:00
return choice . placeholder !== true ;
} ) ;
}
/ * *
* Get placeholder choice from store
* @ return { Object } Found placeholder
* /
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "placeholderChoice" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
2019-02-09 19:13:25 +01:00
return [ ] . concat ( this . choices ) . reverse ( ) . find ( function ( choice ) {
2017-11-15 07:51:53 +01:00
return choice . placeholder === true ;
2017-11-13 20:13:37 +01:00
} ) ;
}
2017-11-15 07:51:53 +01:00
/ * *
* Get groups from store
* @ return { Array } Group objects
* /
2017-11-13 20:13:37 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "groups" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
return this . state . groups ;
2017-11-15 07:51:53 +01:00
}
/ * *
* Get active groups from store
* @ return { Array } Group objects
* /
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "activeGroups" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
var groups = this . groups ;
var choices = this . choices ;
return groups . filter ( function ( group ) {
2017-11-15 07:51:53 +01:00
var isActive = group . active === true && group . disabled === false ;
var hasActiveOptions = choices . some ( function ( choice ) {
return choice . active === true && choice . disabled === false ;
} ) ;
return isActive && hasActiveOptions ;
} , [ ] ) ;
2017-11-13 20:13:37 +01:00
}
} ] ) ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
return Store ;
2017-11-13 20:13:37 +01:00
} ( ) ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
exports . default = Store ;
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 16 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports ) {
2019-01-26 13:36:47 +01:00
module . exports = function ( originalModule ) {
2019-02-09 19:13:25 +01:00
if ( ! originalModule . webpackPolyfill ) {
2019-01-26 13:36:47 +01:00
var module = Object . create ( originalModule ) ;
// module.parent = undefined by default
2019-02-09 19:13:25 +01:00
if ( ! module . children ) module . children = [ ] ;
2019-01-26 13:36:47 +01:00
Object . defineProperty ( module , "loaded" , {
enumerable : true ,
get : function ( ) {
return module . l ;
}
} ) ;
Object . defineProperty ( module , "id" , {
enumerable : true ,
get : function ( ) {
return module . i ;
}
} ) ;
Object . defineProperty ( module , "exports" , {
2019-02-09 19:13:25 +01:00
enumerable : true
2019-01-26 13:36:47 +01:00
} ) ;
module . webpackPolyfill = 1 ;
}
return module ;
} ;
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 17 */
2017-11-13 20:13:37 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
"use strict" ;
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . default = void 0 ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _redux = _ _webpack _require _ _ ( 6 ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _items = _interopRequireDefault ( _ _webpack _require _ _ ( 18 ) ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _groups = _interopRequireDefault ( _ _webpack _require _ _ ( 19 ) ) ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _choices = _interopRequireDefault ( _ _webpack _require _ _ ( 20 ) ) ;
2019-01-26 13:36:47 +01:00
2019-02-09 19:13:25 +01:00
var _general = _interopRequireDefault ( _ _webpack _require _ _ ( 21 ) ) ;
2019-01-26 13:36:47 +01:00
2019-02-09 19:13:25 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2018-05-28 17:22:22 +02:00
2017-11-15 07:51:53 +01:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
var appReducer = ( 0 , _redux . combineReducers ) ( {
2019-02-09 19:13:25 +01:00
items : _items . default ,
groups : _groups . default ,
choices : _choices . default ,
general : _general . default
2017-11-15 07:51:53 +01:00
} ) ;
var rootReducer = function rootReducer ( passedState , action ) {
2019-02-09 19:13:25 +01:00
var state = passedState ; // If we are clearing all items, groups and options we reassign
2017-11-15 07:51:53 +01:00
// state and then pass that state to our proper reducer. This isn't
// mutating our actual state
// See: http://stackoverflow.com/a/35641992
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( action . type === 'CLEAR_ALL' ) {
state = undefined ;
2018-05-28 17:22:22 +02:00
} else if ( action . type === 'RESET_TO' ) {
return ( 0 , _utils . cloneObject ) ( action . state ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
return appReducer ( state , action ) ;
} ;
2019-02-09 19:13:25 +01:00
var _default = rootReducer ;
exports . default = _default ;
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 18 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = items ;
2019-02-09 19:13:25 +01:00
exports . defaultState = void 0 ;
var defaultState = [ ] ;
exports . defaultState = defaultState ;
2017-11-15 07:51:53 +01:00
function items ( ) {
var state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : defaultState ;
2019-02-09 19:13:25 +01:00
var action = arguments . length > 1 ? arguments [ 1 ] : undefined ;
2017-11-15 07:51:53 +01:00
switch ( action . type ) {
case 'ADD_ITEM' :
{
// Add object to items array
2019-02-09 19:13:25 +01:00
var newState = [ ] . concat ( state , [ {
2017-11-15 07:51:53 +01:00
id : action . id ,
choiceId : action . choiceId ,
groupId : action . groupId ,
value : action . value ,
label : action . label ,
active : true ,
highlighted : false ,
customProperties : action . customProperties ,
placeholder : action . placeholder || false ,
keyCode : null
} ] ) ;
return newState . map ( function ( obj ) {
var item = obj ;
2018-02-02 12:08:03 +01:00
item . highlighted = false ;
2017-11-15 07:51:53 +01:00
return item ;
} ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
case 'REMOVE_ITEM' :
{
// Set item to inactive
return state . map ( function ( obj ) {
var item = obj ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( item . id === action . id ) {
item . active = false ;
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return item ;
} ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
case 'HIGHLIGHT_ITEM' :
{
return state . map ( function ( obj ) {
var item = obj ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( item . id === action . id ) {
item . highlighted = action . highlighted ;
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return item ;
} ) ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
default :
{
return state ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 19 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = groups ;
2019-02-09 19:13:25 +01:00
exports . defaultState = void 0 ;
var defaultState = [ ] ;
exports . defaultState = defaultState ;
2017-11-15 07:51:53 +01:00
function groups ( ) {
var state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : defaultState ;
2019-02-09 19:13:25 +01:00
var action = arguments . length > 1 ? arguments [ 1 ] : undefined ;
2017-11-15 07:51:53 +01:00
switch ( action . type ) {
case 'ADD_GROUP' :
{
2019-02-09 19:13:25 +01:00
return [ ] . concat ( state , [ {
2017-11-15 07:51:53 +01:00
id : action . id ,
value : action . value ,
active : action . active ,
disabled : action . disabled
} ] ) ;
}
case 'CLEAR_CHOICES' :
{
return [ ] ;
}
default :
{
return state ;
}
}
}
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 20 */
2017-11-13 20:13:37 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = choices ;
2019-02-09 19:13:25 +01:00
exports . defaultState = void 0 ;
var defaultState = [ ] ;
exports . defaultState = defaultState ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
function choices ( ) {
var state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : defaultState ;
2019-02-09 19:13:25 +01:00
var action = arguments . length > 1 ? arguments [ 1 ] : undefined ;
2017-11-15 07:51:53 +01:00
switch ( action . type ) {
case 'ADD_CHOICE' :
{
/ *
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
* /
2019-02-09 19:13:25 +01:00
return [ ] . concat ( state , [ {
2017-11-15 07:51:53 +01:00
id : action . id ,
elementId : action . elementId ,
groupId : action . groupId ,
value : action . value ,
label : action . label || action . value ,
disabled : action . disabled || false ,
selected : false ,
active : true ,
score : 9999 ,
customProperties : action . customProperties ,
placeholder : action . placeholder || false ,
keyCode : null
} ] ) ;
}
case 'ADD_ITEM' :
{
// If all choices need to be activated
if ( action . activateOptions ) {
return state . map ( function ( obj ) {
var choice = obj ;
choice . active = action . active ;
return choice ;
} ) ;
2019-02-09 19:13:25 +01:00
} // When an item is added and it has an associated choice,
2017-11-15 07:51:53 +01:00
// we want to disable it so it can't be chosen again
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( action . choiceId > - 1 ) {
return state . map ( function ( obj ) {
var choice = obj ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( choice . id === parseInt ( action . choiceId , 10 ) ) {
choice . selected = true ;
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return choice ;
} ) ;
2017-11-13 20:13:37 +01:00
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
return state ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
case 'REMOVE_ITEM' :
{
// When an item is removed and it has an associated choice,
// we want to re-enable it so it can be chosen again
if ( action . choiceId > - 1 ) {
return state . map ( function ( obj ) {
var choice = obj ;
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
if ( choice . id === parseInt ( action . choiceId , 10 ) ) {
choice . selected = false ;
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return choice ;
} ) ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
return state ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
case 'FILTER_CHOICES' :
{
return state . map ( function ( obj ) {
2019-02-09 19:13:25 +01:00
var choice = obj ; // Set active state based on whether choice is
2017-11-15 07:51:53 +01:00
// within filtered results
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
choice . active = action . results . some ( function ( _ref ) {
var item = _ref . item ,
score = _ref . score ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( item . id === choice . id ) {
choice . score = score ;
return true ;
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
return false ;
} ) ;
return choice ;
} ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
case 'ACTIVATE_CHOICES' :
{
return state . map ( function ( obj ) {
var choice = obj ;
choice . active = action . active ;
return choice ;
} ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
case 'CLEAR_CHOICES' :
{
return defaultState ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
default :
{
return state ;
}
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 21 */
2018-05-25 15:00:27 +02:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
2019-01-26 13:36:47 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . default = exports . defaultState = void 0 ;
var defaultState = {
2019-01-26 13:36:47 +01:00
loading : false
} ;
2019-02-09 19:13:25 +01:00
exports . defaultState = defaultState ;
2019-01-26 13:36:47 +01:00
var general = function general ( ) {
var state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : defaultState ;
2019-02-09 19:13:25 +01:00
var action = arguments . length > 1 ? arguments [ 1 ] : undefined ;
2019-01-26 13:36:47 +01:00
switch ( action . type ) {
2019-02-09 19:13:25 +01:00
case 'SET_IS_LOADING' :
2019-01-26 13:36:47 +01:00
{
return {
loading : action . isLoading
} ;
}
default :
{
return state ;
}
}
} ;
2019-02-09 19:13:25 +01:00
var _default = general ;
exports . default = _default ;
2019-01-26 13:36:47 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 22 */
2019-01-26 13:36:47 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
2018-05-25 15:00:27 +02:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
Object . defineProperty ( exports , "Dropdown" , {
enumerable : true ,
get : function get ( ) {
return _dropdown . default ;
}
} ) ;
Object . defineProperty ( exports , "Container" , {
enumerable : true ,
get : function get ( ) {
return _container . default ;
}
} ) ;
Object . defineProperty ( exports , "Input" , {
enumerable : true ,
get : function get ( ) {
return _input . default ;
}
} ) ;
Object . defineProperty ( exports , "List" , {
enumerable : true ,
get : function get ( ) {
return _list . default ;
}
} ) ;
Object . defineProperty ( exports , "WrappedInput" , {
enumerable : true ,
get : function get ( ) {
return _wrappedInput . default ;
}
} ) ;
Object . defineProperty ( exports , "WrappedSelect" , {
enumerable : true ,
get : function get ( ) {
return _wrappedSelect . default ;
}
} ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var _dropdown = _interopRequireDefault ( _ _webpack _require _ _ ( 23 ) ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var _container = _interopRequireDefault ( _ _webpack _require _ _ ( 24 ) ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var _input = _interopRequireDefault ( _ _webpack _require _ _ ( 25 ) ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var _list = _interopRequireDefault ( _ _webpack _require _ _ ( 26 ) ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var _wrappedInput = _interopRequireDefault ( _ _webpack _require _ _ ( 27 ) ) ;
2018-05-25 15:00:27 +02:00
2019-02-09 19:13:25 +01:00
var _wrappedSelect = _interopRequireDefault ( _ _webpack _require _ _ ( 28 ) ) ;
2018-05-25 15:00:27 +02:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 23 */
2017-11-13 20:13:37 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . default = void 0 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2019-02-09 19:13:25 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
var Dropdown =
/*#__PURE__*/
function ( ) {
2018-05-25 15:00:27 +02:00
function Dropdown ( _ref ) {
var element = _ref . element ,
type = _ref . type ,
classNames = _ref . classNames ;
2017-11-15 07:51:53 +01:00
_classCallCheck ( this , Dropdown ) ;
2019-02-09 19:13:25 +01:00
Object . assign ( this , {
element : element ,
type : type ,
classNames : classNames
} ) ;
2017-11-15 07:51:53 +01:00
this . isActive = false ;
2017-11-13 20:13:37 +01:00
}
2018-04-25 10:20:59 +02:00
/ * *
* Determine how far the top of our element is from
* the top of the window
* @ return { Number } Vertical position
* /
2016-08-23 08:24:45 +02:00
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
_createClass ( Dropdown , [ {
2019-02-09 19:13:25 +01:00
key : "distanceFromTopWindow" ,
2018-04-25 10:20:59 +02:00
value : function distanceFromTopWindow ( ) {
2017-11-15 07:51:53 +01:00
this . dimensions = this . element . getBoundingClientRect ( ) ;
this . position = Math . ceil ( this . dimensions . top + window . pageYOffset + this . element . offsetHeight ) ;
return this . position ;
}
/ * *
* Find element that matches passed selector
* @ return { HTMLElement }
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "getChild" ,
2017-11-15 07:51:53 +01:00
value : function getChild ( selector ) {
return this . element . querySelector ( selector ) ;
}
/ * *
* Show dropdown to user by adding active state class
* @ return { Object } Class instance
* @ public
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "show" ,
2017-11-15 07:51:53 +01:00
value : function show ( ) {
this . element . classList . add ( this . classNames . activeState ) ;
this . element . setAttribute ( 'aria-expanded' , 'true' ) ;
this . isActive = true ;
2018-05-25 15:00:27 +02:00
return this ;
2017-11-15 07:51:53 +01:00
}
/ * *
* Hide dropdown from user
* @ return { Object } Class instance
* @ public
* /
} , {
2019-02-09 19:13:25 +01:00
key : "hide" ,
2017-11-15 07:51:53 +01:00
value : function hide ( ) {
this . element . classList . remove ( this . classNames . activeState ) ;
this . element . setAttribute ( 'aria-expanded' , 'false' ) ;
this . isActive = false ;
2018-05-25 15:00:27 +02:00
return this ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} ] ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return Dropdown ;
} ( ) ;
exports . default = Dropdown ;
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 24 */
2017-11-13 20:13:37 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . default = void 0 ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2018-02-02 12:08:03 +01:00
2017-11-15 07:51:53 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
var Container =
/*#__PURE__*/
function ( ) {
2018-05-25 15:00:27 +02:00
function Container ( _ref ) {
var element = _ref . element ,
type = _ref . type ,
classNames = _ref . classNames ,
position = _ref . position ;
2017-11-15 07:51:53 +01:00
_classCallCheck ( this , Container ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
Object . assign ( this , {
element : element ,
classNames : classNames ,
type : type ,
position : position
} ) ;
2017-11-15 07:51:53 +01:00
this . isOpen = false ;
this . isFlipped = false ;
this . isFocussed = false ;
this . isDisabled = false ;
this . isLoading = false ;
2018-05-25 15:00:27 +02:00
this . _onFocus = this . _onFocus . bind ( this ) ;
this . _onBlur = this . _onBlur . bind ( this ) ;
2017-11-15 07:51:53 +01:00
}
2018-04-25 10:20:59 +02:00
/ * *
* Add event listeners
2018-05-28 16:13:55 +02:00
* /
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
_createClass ( Container , [ {
2019-02-09 19:13:25 +01:00
key : "addEventListeners" ,
2017-11-15 07:51:53 +01:00
value : function addEventListeners ( ) {
2018-05-25 15:00:27 +02:00
this . element . addEventListener ( 'focus' , this . _onFocus ) ;
this . element . addEventListener ( 'blur' , this . _onBlur ) ;
2017-11-15 07:51:53 +01:00
}
/ * *
* Remove event listeners
2018-05-28 16:13:55 +02:00
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/** */
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "removeEventListeners" ,
2017-11-15 07:51:53 +01:00
value : function removeEventListeners ( ) {
2018-05-25 15:00:27 +02:00
this . element . removeEventListener ( 'focus' , this . _onFocus ) ;
this . element . removeEventListener ( 'blur' , this . _onBlur ) ;
2017-11-15 07:51:53 +01:00
}
/ * *
* Determine whether container should be flipped
* based on passed dropdown position
* @ param { Number } dropdownPos
* @ returns
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "shouldFlip" ,
2017-11-15 07:51:53 +01:00
value : function shouldFlip ( dropdownPos ) {
2018-02-02 12:08:03 +01:00
var windowHeight = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : ( 0 , _utils . getWindowHeight ) ( ) ;
2017-11-15 07:51:53 +01:00
if ( dropdownPos === undefined ) {
return false ;
2019-02-09 19:13:25 +01:00
} // If flip is enabled and the dropdown bottom position is
2017-11-15 07:51:53 +01:00
// greater than the window height flip the dropdown.
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
var shouldFlip = false ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
if ( this . position === 'auto' ) {
2018-02-02 12:08:03 +01:00
shouldFlip = dropdownPos >= windowHeight ;
2018-05-25 15:00:27 +02:00
} else if ( this . position === 'top' ) {
2017-11-15 07:51:53 +01:00
shouldFlip = true ;
2017-11-07 12:59:49 +01:00
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
return shouldFlip ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
/ * *
* Set active descendant attribute
* @ param { Number } activeDescendant ID of active descendant
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "setActiveDescendant" ,
2017-11-15 07:51:53 +01:00
value : function setActiveDescendant ( activeDescendantID ) {
this . element . setAttribute ( 'aria-activedescendant' , activeDescendantID ) ;
}
/ * *
* Remove active descendant attribute
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "removeActiveDescendant" ,
2017-11-15 07:51:53 +01:00
value : function removeActiveDescendant ( ) {
this . element . removeAttribute ( 'aria-activedescendant' ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "open" ,
2017-11-15 07:51:53 +01:00
value : function open ( dropdownPos ) {
this . element . classList . add ( this . classNames . openState ) ;
this . element . setAttribute ( 'aria-expanded' , 'true' ) ;
this . isOpen = true ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . shouldFlip ( dropdownPos ) ) {
this . element . classList . add ( this . classNames . flippedState ) ;
this . isFlipped = true ;
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "close" ,
2017-11-15 07:51:53 +01:00
value : function close ( ) {
this . element . classList . remove ( this . classNames . openState ) ;
this . element . setAttribute ( 'aria-expanded' , 'false' ) ;
this . removeActiveDescendant ( ) ;
2019-02-09 19:13:25 +01:00
this . isOpen = false ; // A dropdown flips if it does not have space within the page
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . isFlipped ) {
this . element . classList . remove ( this . classNames . flippedState ) ;
this . isFlipped = false ;
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "focus" ,
2017-11-15 07:51:53 +01:00
value : function focus ( ) {
if ( ! this . isFocussed ) {
this . element . focus ( ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "addFocusState" ,
2017-11-15 07:51:53 +01:00
value : function addFocusState ( ) {
this . element . classList . add ( this . classNames . focusState ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "removeFocusState" ,
2017-11-15 07:51:53 +01:00
value : function removeFocusState ( ) {
this . element . classList . remove ( this . classNames . focusState ) ;
}
/ * *
* Remove disabled state
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "enable" ,
2017-11-15 07:51:53 +01:00
value : function enable ( ) {
2018-02-02 12:08:03 +01:00
this . element . classList . remove ( this . classNames . disabledState ) ;
2017-11-15 07:51:53 +01:00
this . element . removeAttribute ( 'aria-disabled' ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
if ( this . type === 'select-one' ) {
2017-11-15 07:51:53 +01:00
this . element . setAttribute ( 'tabindex' , '0' ) ;
2017-11-13 20:13:37 +01:00
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . isDisabled = false ;
}
/ * *
* Set disabled state
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "disable" ,
2017-11-15 07:51:53 +01:00
value : function disable ( ) {
2018-02-02 12:08:03 +01:00
this . element . classList . add ( this . classNames . disabledState ) ;
2017-11-15 07:51:53 +01:00
this . element . setAttribute ( 'aria-disabled' , 'true' ) ;
2019-02-09 19:13:25 +01:00
2018-05-25 15:00:27 +02:00
if ( this . type === 'select-one' ) {
2017-11-15 07:51:53 +01:00
this . element . setAttribute ( 'tabindex' , '-1' ) ;
}
2019-02-09 19:13:25 +01:00
2017-11-15 07:51:53 +01:00
this . isDisabled = true ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "wrap" ,
2018-02-02 12:08:03 +01:00
value : function wrap ( element ) {
( 0 , _utils . wrap ) ( element , this . element ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "unwrap" ,
2018-02-02 12:08:03 +01:00
value : function unwrap ( element ) {
// Move passed element outside this element
2019-02-09 19:13:25 +01:00
this . element . parentNode . insertBefore ( element , this . element ) ; // Remove this element
2017-11-15 07:51:53 +01:00
this . element . parentNode . removeChild ( this . element ) ;
}
/ * *
* Add loading state to element
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "addLoadingState" ,
2017-11-15 07:51:53 +01:00
value : function addLoadingState ( ) {
this . element . classList . add ( this . classNames . loadingState ) ;
this . element . setAttribute ( 'aria-busy' , 'true' ) ;
this . isLoading = true ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
/ * *
* Remove loading state from element
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "removeLoadingState" ,
2017-11-15 07:51:53 +01:00
value : function removeLoadingState ( ) {
this . element . classList . remove ( this . classNames . loadingState ) ;
this . element . removeAttribute ( 'aria-busy' ) ;
this . isLoading = false ;
2017-11-13 20:13:37 +01:00
}
2018-05-25 15:00:27 +02:00
/ * *
* Set focussed state
* /
} , {
2019-02-09 19:13:25 +01:00
key : "_onFocus" ,
2018-05-25 15:00:27 +02:00
value : function _onFocus ( ) {
this . isFocussed = true ;
}
/ * *
* Remove blurred state
* /
} , {
2019-02-09 19:13:25 +01:00
key : "_onBlur" ,
2018-05-25 15:00:27 +02:00
value : function _onBlur ( ) {
this . isFocussed = false ;
}
2017-11-15 07:51:53 +01:00
} ] ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return Container ;
} ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
exports . default = Container ;
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 25 */
2017-11-13 20:13:37 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . default = void 0 ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2017-11-15 07:51:53 +01:00
2017-11-13 20:13:37 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
var Input =
/*#__PURE__*/
function ( ) {
2018-05-25 15:00:27 +02:00
function Input ( _ref ) {
var element = _ref . element ,
type = _ref . type ,
classNames = _ref . classNames ,
placeholderValue = _ref . placeholderValue ;
2017-11-15 07:51:53 +01:00
_classCallCheck ( this , Input ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
Object . assign ( this , {
element : element ,
type : type ,
classNames : classNames ,
placeholderValue : placeholderValue
} ) ;
2017-11-15 07:51:53 +01:00
this . element = element ;
this . classNames = classNames ;
this . isFocussed = this . element === document . activeElement ;
2019-02-09 19:13:25 +01:00
this . isDisabled = false ; // Bind event listeners
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
this . _onPaste = this . _onPaste . bind ( this ) ;
this . _onInput = this . _onInput . bind ( this ) ;
this . _onFocus = this . _onFocus . bind ( this ) ;
this . _onBlur = this . _onBlur . bind ( this ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
_createClass ( Input , [ {
2019-02-09 19:13:25 +01:00
key : "addEventListeners" ,
2017-11-15 07:51:53 +01:00
value : function addEventListeners ( ) {
2018-05-25 15:00:27 +02:00
this . element . addEventListener ( 'input' , this . _onInput ) ;
this . element . addEventListener ( 'paste' , this . _onPaste ) ;
this . element . addEventListener ( 'focus' , this . _onFocus ) ;
this . element . addEventListener ( 'blur' , this . _onBlur ) ;
2018-05-28 17:22:22 +02:00
if ( this . element . form ) {
this . element . form . addEventListener ( 'reset' , this . _onFormReset ) ;
}
2017-11-15 07:51:53 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "removeEventListeners" ,
2017-11-15 07:51:53 +01:00
value : function removeEventListeners ( ) {
2018-05-25 15:00:27 +02:00
this . element . removeEventListener ( 'input' , this . _onInput ) ;
this . element . removeEventListener ( 'paste' , this . _onPaste ) ;
this . element . removeEventListener ( 'focus' , this . _onFocus ) ;
this . element . removeEventListener ( 'blur' , this . _onBlur ) ;
2018-05-28 17:22:22 +02:00
if ( this . element . form ) {
this . element . form . removeEventListener ( 'reset' , this . _onFormReset ) ;
}
2017-11-15 07:51:53 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "enable" ,
2017-11-15 07:51:53 +01:00
value : function enable ( ) {
this . element . removeAttribute ( 'disabled' ) ;
this . isDisabled = false ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "disable" ,
2017-11-15 07:51:53 +01:00
value : function disable ( ) {
this . element . setAttribute ( 'disabled' , '' ) ;
this . isDisabled = true ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "focus" ,
2017-11-15 07:51:53 +01:00
value : function focus ( ) {
if ( ! this . isFocussed ) {
this . element . focus ( ) ;
}
}
2018-02-02 12:08:03 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "blur" ,
2018-02-02 12:08:03 +01:00
value : function blur ( ) {
if ( this . isFocussed ) {
this . element . blur ( ) ;
}
}
2017-11-15 07:51:53 +01:00
/ * *
* Set value of input to blank
* @ return { Object } Class instance
* @ public
* /
} , {
2019-02-09 19:13:25 +01:00
key : "clear" ,
2017-11-15 07:51:53 +01:00
value : function clear ( ) {
var setWidth = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : true ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . element . value ) {
this . element . value = '' ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( setWidth ) {
this . setWidth ( ) ;
2017-11-07 12:59:49 +01:00
}
2018-05-25 15:00:27 +02:00
return this ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
/ * *
* Set the correct input width based on placeholder
* value or input value
* @ return
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "setWidth" ,
2017-11-15 07:51:53 +01:00
value : function setWidth ( enforceWidth ) {
2018-05-28 17:22:22 +02:00
var _this = this ;
2018-06-07 17:54:11 +02:00
var callback = function callback ( width ) {
_this . element . style . width = width ;
} ;
2018-05-25 15:00:27 +02:00
if ( this . _placeholderValue ) {
2017-11-15 07:51:53 +01:00
// If there is a placeholder, we only want to set the width of the input when it is a greater
// length than 75% of the placeholder. This stops the input jumping around.
2018-06-07 17:54:11 +02:00
var valueHasDesiredLength = this . element . value . length >= this . _placeholderValue . length / 1.25 ;
if ( this . element . value && valueHasDesiredLength || enforceWidth ) {
this . calcWidth ( callback ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
} else {
// If there is no placeholder, resize input to contents
2018-06-07 17:54:11 +02:00
this . calcWidth ( callback ) ;
2017-11-07 12:59:49 +01:00
}
}
2017-11-13 20:13:37 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "calcWidth" ,
2018-05-28 17:22:22 +02:00
value : function calcWidth ( callback ) {
return ( 0 , _utils . calcWidthOfInput ) ( this . element , callback ) ;
2017-11-15 07:51:53 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "setActiveDescendant" ,
2017-11-15 07:51:53 +01:00
value : function setActiveDescendant ( activeDescendantID ) {
this . element . setAttribute ( 'aria-activedescendant' , activeDescendantID ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "removeActiveDescendant" ,
2017-11-15 07:51:53 +01:00
value : function removeActiveDescendant ( ) {
this . element . removeAttribute ( 'aria-activedescendant' ) ;
}
2018-05-25 15:00:27 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "_onInput" ,
2018-05-25 15:00:27 +02:00
value : function _onInput ( ) {
if ( this . type !== 'select-one' ) {
this . setWidth ( ) ;
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onPaste" ,
2018-05-28 17:22:22 +02:00
value : function _onPaste ( event ) {
2019-02-09 19:13:25 +01:00
var target = event . target ; // Disable pasting into the input if option has been set
2018-05-28 17:22:22 +02:00
if ( target === this . element && this . preventPaste ) {
event . preventDefault ( ) ;
2018-05-25 15:00:27 +02:00
}
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onFocus" ,
2018-05-25 15:00:27 +02:00
value : function _onFocus ( ) {
this . isFocussed = true ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_onBlur" ,
2018-05-25 15:00:27 +02:00
value : function _onBlur ( ) {
this . isFocussed = false ;
}
2018-04-25 10:20:59 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "placeholder" ,
2018-04-25 10:20:59 +02:00
set : function set ( placeholder ) {
this . element . placeholder = placeholder ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "value" ,
2018-04-25 10:20:59 +02:00
set : function set ( value ) {
2019-02-09 19:13:25 +01:00
this . element . value = "" . concat ( value ) ;
2018-04-25 10:20:59 +02:00
} ,
get : function get ( ) {
2018-05-28 17:22:22 +02:00
return ( 0 , _utils . stripHTML ) ( this . element . value ) ;
2018-04-25 10:20:59 +02:00
}
2017-11-15 07:51:53 +01:00
} ] ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return Input ;
} ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
exports . default = Input ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 26 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . default = void 0 ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _constants = _ _webpack _require _ _ ( 1 ) ;
2018-05-28 16:13:55 +02:00
2017-11-15 07:51:53 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2019-02-09 19:13:25 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
var List =
/*#__PURE__*/
function ( ) {
2018-05-25 15:00:27 +02:00
function List ( _ref ) {
var element = _ref . element ;
2017-11-15 07:51:53 +01:00
_classCallCheck ( this , List ) ;
2019-02-09 19:13:25 +01:00
Object . assign ( this , {
element : element
} ) ;
2017-11-15 07:51:53 +01:00
this . scrollPos = this . element . scrollTop ;
this . height = this . element . offsetHeight ;
this . hasChildren = ! ! this . element . children ;
}
2018-04-25 10:20:59 +02:00
_createClass ( List , [ {
2019-02-09 19:13:25 +01:00
key : "clear" ,
2017-11-15 07:51:53 +01:00
value : function clear ( ) {
this . element . innerHTML = '' ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "append" ,
2017-11-15 07:51:53 +01:00
value : function append ( node ) {
this . element . appendChild ( node ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "getChild" ,
2017-11-15 07:51:53 +01:00
value : function getChild ( selector ) {
return this . element . querySelector ( selector ) ;
}
2018-05-28 16:13:55 +02:00
} , {
2019-02-09 19:13:25 +01:00
key : "scrollToTop" ,
2018-05-28 16:13:55 +02:00
value : function scrollToTop ( ) {
this . element . scrollTop = 0 ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "scrollToChoice" ,
2018-05-28 16:13:55 +02:00
value : function scrollToChoice ( choice , direction ) {
var _this = this ;
if ( ! choice ) {
return ;
}
var dropdownHeight = this . element . offsetHeight ;
2019-02-09 19:13:25 +01:00
var choiceHeight = choice . offsetHeight ; // Distance from bottom of element to top of parent
var choicePos = choice . offsetTop + choiceHeight ; // Scroll position of dropdown
var containerScrollPos = this . element . scrollTop + dropdownHeight ; // Difference between the choice and scroll position
2018-05-28 16:13:55 +02:00
2019-02-09 19:13:25 +01:00
var endpoint = direction > 0 ? this . element . scrollTop + choicePos - containerScrollPos : choice . offsetTop ;
2018-05-28 16:13:55 +02:00
requestAnimationFrame ( function ( time ) {
_this . _animateScroll ( time , endpoint , direction ) ;
} ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_scrollDown" ,
2018-05-28 16:13:55 +02:00
value : function _scrollDown ( scrollPos , strength , endpoint ) {
var easing = ( endpoint - scrollPos ) / strength ;
var distance = easing > 1 ? easing : 1 ;
this . element . scrollTop = scrollPos + distance ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_scrollUp" ,
2018-05-28 16:13:55 +02:00
value : function _scrollUp ( scrollPos , strength , endpoint ) {
var easing = ( scrollPos - endpoint ) / strength ;
var distance = easing > 1 ? easing : 1 ;
this . element . scrollTop = scrollPos - distance ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "_animateScroll" ,
2018-05-28 16:13:55 +02:00
value : function _animateScroll ( time , endpoint , direction ) {
var _this2 = this ;
var strength = _constants . SCROLLING _SPEED ;
var choiceListScrollTop = this . element . scrollTop ;
var continueAnimation = false ;
if ( direction > 0 ) {
this . _scrollDown ( choiceListScrollTop , strength , endpoint ) ;
if ( choiceListScrollTop < endpoint ) {
continueAnimation = true ;
}
} else {
this . _scrollUp ( choiceListScrollTop , strength , endpoint ) ;
if ( choiceListScrollTop > endpoint ) {
continueAnimation = true ;
}
}
if ( continueAnimation ) {
2018-05-28 17:22:22 +02:00
requestAnimationFrame ( function ( ) {
2018-05-28 16:13:55 +02:00
_this2 . _animateScroll ( time , endpoint , direction ) ;
} ) ;
}
}
2017-11-15 07:51:53 +01:00
} ] ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return List ;
} ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
exports . default = List ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 27 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . default = void 0 ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _wrappedElement = _interopRequireDefault ( _ _webpack _require _ _ ( 4 ) ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _typeof ( obj ) { if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _possibleConstructorReturn ( self , call ) { if ( call && ( _typeof ( call ) === "object" || typeof call === "function" ) ) { return call ; } return _assertThisInitialized ( self ) ; }
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _assertThisInitialized ( self ) { if ( self === void 0 ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return self ; }
2016-08-23 08:24:45 +02:00
2019-02-09 19:13:25 +01:00
function _get ( target , property , receiver ) { if ( typeof Reflect !== "undefined" && Reflect . get ) { _get = Reflect . get ; } else { _get = function _get ( target , property , receiver ) { var base = _superPropBase ( target , property ) ; if ( ! base ) return ; var desc = Object . getOwnPropertyDescriptor ( base , property ) ; if ( desc . get ) { return desc . get . call ( receiver ) ; } return desc . value ; } ; } return _get ( target , property , receiver || target ) ; }
function _superPropBase ( object , property ) { while ( ! Object . prototype . hasOwnProperty . call ( object , property ) ) { object = _getPrototypeOf ( object ) ; if ( object === null ) break ; } return object ; }
function _getPrototypeOf ( o ) { _getPrototypeOf = Object . setPrototypeOf ? Object . getPrototypeOf : function _getPrototypeOf ( o ) { return o . _ _proto _ _ || Object . getPrototypeOf ( o ) ; } ; return _getPrototypeOf ( o ) ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function" ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , writable : true , configurable : true } } ) ; if ( superClass ) _setPrototypeOf ( subClass , superClass ) ; }
function _setPrototypeOf ( o , p ) { _setPrototypeOf = Object . setPrototypeOf || function _setPrototypeOf ( o , p ) { o . _ _proto _ _ = p ; return o ; } ; return _setPrototypeOf ( o , p ) ; }
var WrappedInput =
/*#__PURE__*/
function ( _WrappedElement ) {
2017-11-15 07:51:53 +01:00
_inherits ( WrappedInput , _WrappedElement ) ;
2017-11-07 12:59:49 +01:00
2018-05-25 15:00:27 +02:00
function WrappedInput ( _ref ) {
2019-02-09 19:13:25 +01:00
var _this ;
2018-05-25 15:00:27 +02:00
var element = _ref . element ,
classNames = _ref . classNames ,
delimiter = _ref . delimiter ;
2017-11-15 07:51:53 +01:00
_classCallCheck ( this , WrappedInput ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
_this = _possibleConstructorReturn ( this , _getPrototypeOf ( WrappedInput ) . call ( this , {
element : element ,
classNames : classNames
} ) ) ;
2018-05-25 15:00:27 +02:00
_this . delimiter = delimiter ;
2017-11-15 07:51:53 +01:00
return _this ;
}
_createClass ( WrappedInput , [ {
2019-02-09 19:13:25 +01:00
key : "value" ,
2018-04-25 10:20:59 +02:00
set : function set ( items ) {
2018-02-02 12:08:03 +01:00
var itemsFiltered = ( 0 , _utils . reduceToValues ) ( items ) ;
2018-05-25 15:00:27 +02:00
var itemsFilteredString = itemsFiltered . join ( this . delimiter ) ;
2018-02-02 12:08:03 +01:00
this . element . setAttribute ( 'value' , itemsFilteredString ) ;
this . element . value = itemsFilteredString ;
2019-02-09 19:13:25 +01:00
} // @todo figure out why we need this? Perhaps a babel issue
2018-04-25 10:20:59 +02:00
,
get : function get ( ) {
2019-02-09 19:13:25 +01:00
return _get ( _getPrototypeOf ( WrappedInput . prototype ) , "value" , this ) ;
2018-04-25 10:20:59 +02:00
}
2017-11-15 07:51:53 +01:00
} ] ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return WrappedInput ;
2019-02-09 19:13:25 +01:00
} ( _wrappedElement . default ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
exports . default = WrappedInput ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 28 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . default = void 0 ;
var _wrappedElement = _interopRequireDefault ( _ _webpack _require _ _ ( 4 ) ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
var _templates = _interopRequireDefault ( _ _webpack _require _ _ ( 5 ) ) ;
2017-11-07 12:59:49 +01:00
2019-02-09 19:13:25 +01:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
function _typeof ( obj ) { if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
2018-02-02 12:08:03 +01:00
2019-02-09 19:13:25 +01:00
function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
function _possibleConstructorReturn ( self , call ) { if ( call && ( _typeof ( call ) === "object" || typeof call === "function" ) ) { return call ; } return _assertThisInitialized ( self ) ; }
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
function _assertThisInitialized ( self ) { if ( self === void 0 ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return self ; }
2017-11-13 20:13:37 +01:00
2019-02-09 19:13:25 +01:00
function _getPrototypeOf ( o ) { _getPrototypeOf = Object . setPrototypeOf ? Object . getPrototypeOf : function _getPrototypeOf ( o ) { return o . _ _proto _ _ || Object . getPrototypeOf ( o ) ; } ; return _getPrototypeOf ( o ) ; }
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function" ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , writable : true , configurable : true } } ) ; if ( superClass ) _setPrototypeOf ( subClass , superClass ) ; }
function _setPrototypeOf ( o , p ) { _setPrototypeOf = Object . setPrototypeOf || function _setPrototypeOf ( o , p ) { o . _ _proto _ _ = p ; return o ; } ; return _setPrototypeOf ( o , p ) ; }
var WrappedSelect =
/*#__PURE__*/
function ( _WrappedElement ) {
2017-11-15 07:51:53 +01:00
_inherits ( WrappedSelect , _WrappedElement ) ;
2018-05-25 15:00:27 +02:00
function WrappedSelect ( _ref ) {
var element = _ref . element ,
classNames = _ref . classNames ;
2017-11-15 07:51:53 +01:00
2018-05-25 15:00:27 +02:00
_classCallCheck ( this , WrappedSelect ) ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
return _possibleConstructorReturn ( this , _getPrototypeOf ( WrappedSelect ) . call ( this , {
element : element ,
classNames : classNames
} ) ) ;
2017-11-15 07:51:53 +01:00
}
_createClass ( WrappedSelect , [ {
2019-02-09 19:13:25 +01:00
key : "appendDocFragment" ,
2018-04-25 10:20:59 +02:00
value : function appendDocFragment ( fragment ) {
this . element . innerHTML = '' ;
this . element . appendChild ( fragment ) ;
2017-11-15 07:51:53 +01:00
}
} , {
2019-02-09 19:13:25 +01:00
key : "placeholderOption" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
2017-11-15 07:51:53 +01:00
return this . element . querySelector ( 'option[placeholder]' ) ;
}
} , {
2019-02-09 19:13:25 +01:00
key : "optionGroups" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
2017-11-15 07:51:53 +01:00
return Array . from ( this . element . getElementsByTagName ( 'OPTGROUP' ) ) ;
}
2018-02-02 12:08:03 +01:00
} , {
2019-02-09 19:13:25 +01:00
key : "options" ,
2018-04-25 10:20:59 +02:00
get : function get ( ) {
return Array . from ( this . element . options ) ;
} ,
set : function set ( options ) {
2018-02-02 12:08:03 +01:00
var fragment = document . createDocumentFragment ( ) ;
2019-02-09 19:13:25 +01:00
2018-02-02 12:08:03 +01:00
var addOptionToFragment = function addOptionToFragment ( data ) {
// Create a standard select option
2019-02-09 19:13:25 +01:00
var template = _templates . default . option ( data ) ; // Append it to fragment
2018-02-02 12:08:03 +01:00
fragment . appendChild ( template ) ;
2019-02-09 19:13:25 +01:00
} ; // Add each list item to list
2016-08-23 08:24:45 +02:00
2018-02-02 12:08:03 +01:00
options . forEach ( function ( optionData ) {
return addOptionToFragment ( optionData ) ;
} ) ;
this . appendDocFragment ( fragment ) ;
2017-11-15 07:51:53 +01:00
}
2018-02-02 12:08:03 +01:00
} ] ) ;
2016-08-23 08:24:45 +02:00
2018-02-02 12:08:03 +01:00
return WrappedSelect ;
2019-02-09 19:13:25 +01:00
} ( _wrappedElement . default ) ;
2017-08-18 06:01:03 +02:00
2018-02-02 12:08:03 +01:00
exports . default = WrappedSelect ;
2017-11-15 07:51:53 +01:00
2017-05-18 18:57:35 +02:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 29 */
2017-11-07 12:59:49 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
var _ _WEBPACK _AMD _DEFINE _ARRAY _ _ , _ _WEBPACK _AMD _DEFINE _RESULT _ _ ; / * !
2019-02-09 19:13:25 +01:00
Copyright ( c ) 2017 Jed Watson .
2017-11-07 12:59:49 +01:00
Licensed under the MIT License ( MIT ) , see
http : //jedwatson.github.io/classnames
* /
/* global define */
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
( function ( ) {
'use strict' ;
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
var hasOwn = { } . hasOwnProperty ;
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
function classNames ( ) {
var classes = [ ] ;
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
for ( var i = 0 ; i < arguments . length ; i ++ ) {
var arg = arguments [ i ] ;
if ( ! arg ) continue ;
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
var argType = typeof arg ;
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
if ( argType === 'string' || argType === 'number' ) {
classes . push ( arg ) ;
2019-02-09 19:13:25 +01:00
} else if ( Array . isArray ( arg ) && arg . length ) {
var inner = classNames . apply ( null , arg ) ;
if ( inner ) {
classes . push ( inner ) ;
}
2017-11-07 12:59:49 +01:00
} else if ( argType === 'object' ) {
for ( var key in arg ) {
if ( hasOwn . call ( arg , key ) && arg [ key ] ) {
classes . push ( key ) ;
}
}
}
}
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
return classes . join ( ' ' ) ;
}
2017-09-18 17:46:48 +02:00
2019-02-09 19:13:25 +01:00
if ( true && module . exports ) {
classNames . default = classNames ;
2017-11-07 12:59:49 +01:00
module . exports = classNames ;
} else if ( true ) {
// register as 'classnames', consistent with npm package name
2018-02-02 12:08:03 +01:00
! ( _ _WEBPACK _AMD _DEFINE _ARRAY _ _ = [ ] , _ _WEBPACK _AMD _DEFINE _RESULT _ _ = ( function ( ) {
2017-11-07 12:59:49 +01:00
return classNames ;
2018-02-02 12:08:03 +01:00
} ) . apply ( exports , _ _WEBPACK _AMD _DEFINE _ARRAY _ _ ) ,
2017-11-07 12:59:49 +01:00
_ _WEBPACK _AMD _DEFINE _RESULT _ _ !== undefined && ( module . exports = _ _WEBPACK _AMD _DEFINE _RESULT _ _ ) ) ;
2019-02-09 19:13:25 +01:00
} else { }
2017-11-07 12:59:49 +01:00
} ( ) ) ;
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 30 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . clearChoices = exports . activateChoices = exports . filterChoices = exports . addChoice = void 0 ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _constants = _ _webpack _require _ _ ( 1 ) ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var addChoice = function addChoice ( _ref ) {
2018-06-07 17:54:11 +02:00
var value = _ref . value ,
label = _ref . label ,
id = _ref . id ,
groupId = _ref . groupId ,
disabled = _ref . disabled ,
elementId = _ref . elementId ,
customProperties = _ref . customProperties ,
placeholder = _ref . placeholder ,
keyCode = _ref . keyCode ;
2017-11-15 07:51:53 +01:00
return {
type : _constants . ACTION _TYPES . ADD _CHOICE ,
value : value ,
label : label ,
id : id ,
groupId : groupId ,
disabled : disabled ,
elementId : elementId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . addChoice = addChoice ;
var filterChoices = function filterChoices ( results ) {
2017-11-15 07:51:53 +01:00
return {
type : _constants . ACTION _TYPES . FILTER _CHOICES ,
results : results
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . filterChoices = filterChoices ;
var activateChoices = function activateChoices ( ) {
2017-11-15 07:51:53 +01:00
var active = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : true ;
return {
type : _constants . ACTION _TYPES . ACTIVATE _CHOICES ,
active : active
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . activateChoices = activateChoices ;
var clearChoices = function clearChoices ( ) {
2017-11-15 07:51:53 +01:00
return {
type : _constants . ACTION _TYPES . CLEAR _CHOICES
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . clearChoices = clearChoices ;
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 31 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . highlightItem = exports . removeItem = exports . addItem = void 0 ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _constants = _ _webpack _require _ _ ( 1 ) ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var addItem = function addItem ( _ref ) {
2018-06-07 17:54:11 +02:00
var value = _ref . value ,
label = _ref . label ,
id = _ref . id ,
choiceId = _ref . choiceId ,
groupId = _ref . groupId ,
customProperties = _ref . customProperties ,
placeholder = _ref . placeholder ,
keyCode = _ref . keyCode ;
2017-11-15 07:51:53 +01:00
return {
type : _constants . ACTION _TYPES . ADD _ITEM ,
value : value ,
label : label ,
id : id ,
choiceId : choiceId ,
groupId : groupId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . addItem = addItem ;
var removeItem = function removeItem ( id , choiceId ) {
2017-11-15 07:51:53 +01:00
return {
type : _constants . ACTION _TYPES . REMOVE _ITEM ,
id : id ,
choiceId : choiceId
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . removeItem = removeItem ;
var highlightItem = function highlightItem ( id , highlighted ) {
2017-11-15 07:51:53 +01:00
return {
type : _constants . ACTION _TYPES . HIGHLIGHT _ITEM ,
id : id ,
highlighted : highlighted
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . highlightItem = highlightItem ;
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 32 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . addGroup = void 0 ;
2017-11-15 07:51:53 +01:00
2019-02-09 19:13:25 +01:00
var _constants = _ _webpack _require _ _ ( 1 ) ;
2017-11-15 07:51:53 +01:00
/* eslint-disable import/prefer-default-export */
2019-02-09 19:13:25 +01:00
var addGroup = function addGroup ( value , id , active , disabled ) {
2017-11-15 07:51:53 +01:00
return {
type : _constants . ACTION _TYPES . ADD _GROUP ,
value : value ,
id : id ,
active : active ,
disabled : disabled
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . addGroup = addGroup ;
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 33 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . resetTo = exports . clearAll = void 0 ;
var clearAll = function clearAll ( ) {
2017-11-15 07:51:53 +01:00
return {
type : 'CLEAR_ALL'
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . clearAll = clearAll ;
var resetTo = function resetTo ( state ) {
2018-05-28 17:22:22 +02:00
return {
type : 'RESET_TO' ,
state : state
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . resetTo = resetTo ;
2019-01-26 13:36:47 +01:00
/***/ } ) ,
2019-02-09 19:13:25 +01:00
/* 34 */
2019-01-26 13:36:47 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2019-02-09 19:13:25 +01:00
exports . setIsLoading = void 0 ;
2019-01-26 13:36:47 +01:00
2019-02-09 19:13:25 +01:00
/* eslint-disable import/prefer-default-export */
var setIsLoading = function setIsLoading ( isLoading ) {
2019-01-26 13:36:47 +01:00
return {
2019-02-09 19:13:25 +01:00
type : 'SET_IS_LOADING' ,
2019-01-26 13:36:47 +01:00
isLoading : isLoading
} ;
} ;
2019-02-09 19:13:25 +01:00
exports . setIsLoading = setIsLoading ;
2017-05-18 18:57:35 +02:00
/***/ } )
2017-11-07 12:59:49 +01:00
/******/ ] ) ;
2019-02-09 19:13:25 +01:00
} ) ;