2018-02-02 12:08:03 +01:00
/*! choices.js v3.0.2 | (c) 2018 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
2016-10-18 15:15:00 +02:00
( function webpackUniversalModuleDefinition ( root , factory ) {
2017-11-15 07:51:53 +01:00
//CommonJS2
2016-10-18 15:15:00 +02:00
if ( typeof exports === 'object' && typeof module === 'object' )
module . exports = factory ( ) ;
2017-11-15 07:51:53 +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 ) ;
2017-11-15 07:51:53 +01:00
//CommonJS
2016-10-18 15:15:00 +02:00
else if ( typeof exports === 'object' )
exports [ "Choices" ] = factory ( ) ;
2017-11-15 07:51:53 +01:00
//Window
2016-10-18 15:15:00 +02:00
else
root [ "Choices" ] = factory ( ) ;
2018-02-02 12:08:03 +01:00
} ) ( typeof self !== 'undefined' ? self : this , 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 ) ) {
/******/ Object . defineProperty ( exports , name , {
/******/ configurable : false ,
/******/ enumerable : true ,
/******/ get : getter
/******/ } ) ;
/******/ }
/******/ } ;
/******/
/******/ // 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__
2017-09-18 17:46:48 +02:00
/******/ _ _webpack _require _ _ . p = "/src/scripts/dist/" ;
2017-11-07 12:59:49 +01:00
/******/
2016-08-23 08:24:45 +02:00
/******/ // Load entry module and return exports
2018-02-02 12:08:03 +01:00
/******/ return _ _webpack _require _ _ ( _ _webpack _require _ _ . s = 6 ) ;
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
} ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/* eslint-disable */
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Capitalises the first letter of each word in a string
* @ param { String } str String to capitalise
* @ return { String } Capitalised string
* /
var capitalise = exports . capitalise = function capitalise ( str ) {
return str . replace ( /\w\S*/g , function ( txt ) {
return txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( ) ;
} ) ;
} ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Generates a string of random chars
* @ param { Number } length Length of the string to generate
* @ return { String } String of random chars
* /
var generateChars = exports . generateChars = function generateChars ( length ) {
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
/ * *
2017-11-15 07:51:53 +01:00
* Generates a unique id based on an element
* @ param { HTMLElement } element Element to generate the id from
* @ param { String } Prefix for the Id
* @ return { String } Unique Id
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
var generateId = exports . generateId = function generateId ( element , prefix ) {
var id = element . id || element . name && element . name + '-' + generateChars ( 2 ) || generateChars ( 4 ) ;
id = id . replace ( /(:|\.|\[|\]|,)/g , '' ) ;
id = prefix + id ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
return id ;
} ;
2017-11-07 12:59:49 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Tests the type of an object
* @ param { String } type Type to test object against
* @ param { Object } obj Object to be tested
* @ return { Boolean }
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
var getType = exports . getType = function getType ( obj ) {
return Object . prototype . toString . call ( obj ) . slice ( 8 , - 1 ) ;
} ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Tests the type of an object
* @ param { String } type Type to test object against
* @ param { Object } obj Object to be tested
* @ return { Boolean }
* /
var isType = exports . isType = function isType ( type , obj ) {
var clas = getType ( obj ) ;
return obj !== undefined && obj !== null && clas === type ;
} ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Tests to see if a passed object is a node
* @ param { Object } obj Object to be tested
* @ return { Boolean }
* /
var isNode = exports . isNode = function isNode ( o ) {
return ( typeof Node === 'undefined' ? 'undefined' : _typeof ( Node ) ) === 'object' ? o instanceof Node : o && ( typeof o === 'undefined' ? 'undefined' : _typeof ( o ) ) === 'object' && typeof o . nodeType === 'number' && typeof o . nodeName === 'string' ;
} ;
2017-11-07 12:59:49 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Tests to see if a passed object is an element
* @ param { Object } obj Object to be tested
* @ return { Boolean }
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
var isElement = exports . isElement = function isElement ( o ) {
return ( typeof HTMLElement === 'undefined' ? 'undefined' : _typeof ( HTMLElement ) ) === 'object' ? o instanceof HTMLElement : // DOM2
o && ( typeof o === 'undefined' ? 'undefined' : _typeof ( o ) ) === 'object' && o !== null && o . nodeType === 1 && typeof o . nodeName === 'string' ;
} ;
2017-11-07 12:59:49 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Merges unspecified amount of objects into new object
2017-11-07 12:59:49 +01:00
* @ private
2017-11-15 07:51:53 +01:00
* @ return { Object } Merged object of arguments
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
var extend = exports . extend = function extend ( ) {
var extended = { } ;
var length = arguments . length ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Merge one object into another
* @ param { Object } obj Object to merge into extended object
* /
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 ] ;
}
}
}
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Loop through each passed argument
for ( var i = 0 ; i < length ; i ++ ) {
// store argument at position i
var obj = arguments [ i ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If we are in fact dealing with an object, merge it.
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
/ * *
2017-11-15 07:51:53 +01:00
* CSS transition end event listener
* @ return
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
var whichTransitionEvent = exports . whichTransitionEvent = function whichTransitionEvent ( ) {
var t = void 0 ,
el = document . createElement ( 'fakeelement' ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var transitions = {
transition : 'transitionend' ,
OTransition : 'oTransitionEnd' ,
MozTransition : 'transitionend' ,
WebkitTransition : 'webkitTransitionEnd'
} ;
for ( t in transitions ) {
if ( el . style [ t ] !== undefined ) {
return transitions [ t ] ;
}
}
} ;
2017-11-07 12:59:49 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* CSS animation end event listener
* @ return
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
var whichAnimationEvent = exports . whichAnimationEvent = function whichAnimationEvent ( ) {
var t = void 0 ,
el = document . createElement ( 'fakeelement' ) ;
var animations = {
animation : 'animationend' ,
OAnimation : 'oAnimationEnd' ,
MozAnimation : 'animationend' ,
WebkitAnimation : 'webkitAnimationEnd'
2017-11-13 20:13:37 +01:00
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( t in animations ) {
if ( el . style [ t ] !== undefined ) {
return animations [ t ] ;
}
}
} ;
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Get the ancestors of each element in the current set of matched elements ,
* up to but not including the element matched by the selector
* @ param { NodeElement } elem Element to begin search from
* @ param { NodeElement } parent Parent to find
* @ param { String } selector Class to find
* @ return { Array } Array of parent elements
2017-11-13 20:13:37 +01:00
* /
2017-11-15 07:51:53 +01:00
var getParentsUntil = exports . getParentsUntil = function getParentsUntil ( elem , parent , selector ) {
var parents = [ ] ;
// Get matches
for ( ; elem && elem !== document ; elem = elem . parentNode ) {
// Check if parent has been reached
if ( parent ) {
var parentType = parent . charAt ( 0 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If parent is a class
if ( parentType === '.' ) {
if ( elem . classList . contains ( parent . substr ( 1 ) ) ) {
break ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If parent is an ID
if ( parentType === '#' ) {
if ( elem . id === parent . substr ( 1 ) ) {
break ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If parent is a data attribute
if ( parentType === '[' ) {
if ( elem . hasAttribute ( parent . substr ( 1 , parent . length - 1 ) ) ) {
break ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If parent is a tag
if ( elem . tagName . toLowerCase ( ) === parent ) {
break ;
}
}
if ( selector ) {
var selectorType = selector . charAt ( 0 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If selector is a class
if ( selectorType === '.' ) {
if ( elem . classList . contains ( selector . substr ( 1 ) ) ) {
parents . push ( elem ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If selector is an ID
if ( selectorType === '#' ) {
if ( elem . id === selector . substr ( 1 ) ) {
parents . push ( elem ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If selector is a data attribute
if ( selectorType === '[' ) {
if ( elem . hasAttribute ( selector . substr ( 1 , selector . length - 1 ) ) ) {
parents . push ( elem ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If selector is a tag
if ( elem . tagName . toLowerCase ( ) === selector ) {
parents . push ( elem ) ;
}
} else {
parents . push ( elem ) ;
}
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
// Return parents if any exist
if ( parents . length === 0 ) {
return null ;
}
return parents ;
} ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var wrap = exports . wrap = function wrap ( element , wrapper ) {
wrapper = wrapper || document . createElement ( 'div' ) ;
if ( element . nextSibling ) {
element . parentNode . insertBefore ( wrapper , element . nextSibling ) ;
} else {
element . parentNode . appendChild ( wrapper ) ;
}
return wrapper . appendChild ( element ) ;
} ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var getSiblings = exports . getSiblings = function getSiblings ( elem ) {
var siblings = [ ] ;
var sibling = elem . parentNode . firstChild ;
for ( ; sibling ; sibling = sibling . nextSibling ) {
if ( sibling . nodeType === 1 && sibling !== elem ) {
siblings . push ( sibling ) ;
}
}
return siblings ;
} ;
2017-11-07 12:59:49 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Find ancestor in DOM tree
* @ param { NodeElement } el Element to start search from
* @ param { [ type ] } cls Class of parent
* @ return { NodeElement } Found parent element
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
var findAncestor = exports . findAncestor = function findAncestor ( el , cls ) {
while ( ( el = el . parentElement ) && ! el . classList . contains ( cls ) ) { }
return el ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Find ancestor in DOM tree by attribute name
* @ param { NodeElement } el Element to start search from
* @ param { string } attr Attribute name of parent
* @ return { ? NodeElement } Found parent element or null
* /
var findAncestorByAttrName = exports . findAncestorByAttrName = function findAncestorByAttrName ( el , attr ) {
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
2017-11-15 07:51:53 +01:00
/ * *
* Debounce an event handler .
* @ param { Function } func Function to run after wait
* @ param { Number } wait The delay before the function is executed
* @ param { Boolean } immediate If passed , trigger the function on the leading edge , instead of the trailing .
* @ return { Function } A function will be called after it stops being called for a given delay
* /
var debounce = exports . debounce = function debounce ( func , wait , immediate ) {
var timeout = void 0 ;
return function ( ) {
var context = this ,
args = arguments ;
var later = function later ( ) {
timeout = null ;
if ( ! immediate ) func . apply ( context , args ) ;
} ;
var callNow = immediate && ! timeout ;
clearTimeout ( timeout ) ;
timeout = setTimeout ( later , wait ) ;
if ( callNow ) func . apply ( context , args ) ;
} ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Get an element ' s distance from the top of the page
* @ private
* @ param { NodeElement } el Element to test for
* @ return { Number } Elements Distance from top of page
* /
var getElemDistance = exports . getElemDistance = function getElemDistance ( el ) {
var location = 0 ;
if ( el . offsetParent ) {
do {
location += el . offsetTop ;
el = el . offsetParent ;
} while ( el ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
return location >= 0 ? location : 0 ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Determine element height multiplied by any offsets
* @ private
* @ param { HTMLElement } el Element to test for
* @ return { Number } Height of element
* /
var getElementOffset = exports . getElementOffset = function getElementOffset ( el , offset ) {
var elOffset = offset ;
if ( elOffset > 1 ) elOffset = 1 ;
if ( elOffset > 0 ) elOffset = 0 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return Math . max ( el . offsetHeight * elOffset ) ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Get the next or previous element from a given start point
* @ param { HTMLElement } startEl Element to start position from
* @ param { String } className The class we will look through
* @ param { Number } direction Positive next element , negative previous element
* @ return { [ HTMLElement } Found element
* /
var getAdjacentEl = exports . getAdjacentEl = function getAdjacentEl ( startEl , className ) {
var direction = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : 1 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! startEl || ! className ) return ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var parent = startEl . parentNode . parentNode ;
var children = Array . from ( parent . querySelectorAll ( className ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var startPos = children . indexOf ( startEl ) ;
var operatorDirection = direction > 0 ? 1 : - 1 ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
return children [ startPos + operatorDirection ] ;
} ;
/ * *
* Get scroll position based on top / bottom position
* @ private
* @ return { String } Position of scroll
* /
var getScrollPosition = exports . getScrollPosition = function getScrollPosition ( position ) {
if ( position === 'bottom' ) {
// Scroll position from the bottom of the viewport
return Math . max ( ( window . scrollY || window . pageYOffset ) + ( window . innerHeight || document . documentElement . clientHeight ) ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
// Scroll position from the top of the viewport
return window . scrollY || window . pageYOffset ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Determine whether an element is within the viewport
* @ param { HTMLElement } el Element to test
* @ return { String } Position of scroll
* @ return { Boolean }
* /
var isInView = exports . isInView = function isInView ( el , position , offset ) {
// If the user has scrolled further than the distance from the element to the top of its parent
return this . getScrollPosition ( position ) > this . getElemDistance ( el ) + this . getElementOffset ( el , offset ) ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Determine whether an element is within
* @ param { HTMLElement } el Element to test
* @ param { HTMLElement } parent Scrolling parent
* @ param { Number } direction Whether element is visible from above or below
* @ return { Boolean }
* /
var isScrolledIntoView = exports . isScrolledIntoView = function isScrolledIntoView ( el , parent ) {
var direction = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : 1 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! el ) return ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var isVisible = void 0 ;
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 ;
} ;
/ * *
2018-04-25 10:20:59 +02:00
* Escape html in the string
* @ param { String } html Initial string / html
2017-11-15 07:51:53 +01:00
* @ return { String } Sanitised string
* /
var stripHTML = exports . 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
} ;
/ * *
* Adds animation to an element and removes it upon animation completion
* @ param { Element } el Element to add animation to
* @ param { String } animation Animation class to add to element
* @ return
* /
var addAnimation = exports . addAnimation = function addAnimation ( el , animation ) {
var animationEvent = whichAnimationEvent ( ) ;
var removeAnimation = function removeAnimation ( ) {
el . classList . remove ( animation ) ;
el . removeEventListener ( animationEvent , removeAnimation , false ) ;
} ;
el . classList . add ( animation ) ;
el . addEventListener ( animationEvent , removeAnimation , false ) ;
} ;
/ * *
* Get a random number between a range
* @ param { Number } min Minimum range
* @ param { Number } max Maximum range
* @ return { Number } Random number
* /
var getRandomNumber = exports . getRandomNumber = function getRandomNumber ( min , max ) {
return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
} ;
/ * *
* Turn a string into a node
* @ param { String } String to convert
* @ return { HTMLElement } Converted node element
* /
var strToEl = exports . strToEl = function ( ) {
var tmpEl = document . createElement ( 'div' ) ;
return function ( str ) {
var cleanedInput = str . trim ( ) ;
var r = void 0 ;
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 ;
} ;
} ( ) ;
/ * *
* Sets the width of a passed input based on its value
* @ return { Number } Width of input
* /
2018-04-25 10:20:59 +02:00
var calcWidthOfInput = exports . calcWidthOfInput = function calcWidthOfInput ( input ) {
2017-11-15 07:51:53 +01:00
var value = input . value || input . placeholder ;
var width = input . offsetWidth ;
if ( value ) {
2018-04-25 10:20:59 +02:00
var testEl = strToEl ( '<span>' + 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 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( value && testEl . offsetWidth !== input . offsetWidth ) {
width = testEl . offsetWidth + 4 ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
document . body . removeChild ( testEl ) ;
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 width + 'px' ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Sorting function for current and previous string
* @ param { String } a Current value
* @ param { String } b Next value
* @ return { Number } - 1 for after previous ,
* 1 for before ,
* 0 for same location
* /
var sortByAlpha = exports . sortByAlpha = function sortByAlpha ( a , b ) {
var labelA = ( a . label || a . value ) . toLowerCase ( ) ;
var labelB = ( b . label || b . value ) . toLowerCase ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( labelA < labelB ) return - 1 ;
if ( labelA > labelB ) return 1 ;
return 0 ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Sort by numeric score
* @ param { Object } a Current value
* @ param { Object } b Next value
* @ return { Number } - 1 for after previous ,
* 1 for before ,
* 0 for same location
* /
var sortByScore = exports . sortByScore = function sortByScore ( a , b ) {
return a . score - b . score ;
} ;
/ * *
* Dispatch native event
* @ param { NodeElement } element Element to trigger event on
* @ param { String } type Type of event to trigger
* @ param { Object } customArgs Data to pass with event
* @ return { Object } Triggered event
* /
var dispatchEvent = exports . dispatchEvent = function dispatchEvent ( element , type ) {
var customArgs = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : null ;
2017-11-07 12:59:49 +01:00
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
/ * *
2017-11-15 07:51:53 +01:00
* Tests value against a regular expression
* @ param { string } value Value to test
* @ return { Boolean } Whether test passed / failed
* @ private
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
var regexFilter = exports . regexFilter = function regexFilter ( value , regex ) {
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
2018-02-02 12:08:03 +01:00
var getWindowHeight = exports . getWindowHeight = function getWindowHeight ( ) {
var body = document . body ;
var html = document . documentElement ;
return Math . max ( body . scrollHeight , body . offsetHeight , html . clientHeight , html . scrollHeight , html . offsetHeight ) ;
} ;
var reduceToValues = exports . reduceToValues = function reduceToValues ( items ) {
var key = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 'value' ;
var values = items . reduce ( function ( prev , current ) {
prev . push ( current [ key ] ) ;
return prev ;
} , [ ] ) ;
return values ;
} ;
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 1 */
/***/ ( 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
} ) ;
2018-04-25 10:20:59 +02:00
exports . SCROLLING _SPEED = exports . KEY _CODES = exports . ACTION _TYPES = exports . EVENTS = exports . DEFAULT _CONFIG = exports . DEFAULT _CLASSNAMES = undefined ;
var _utils = _ _webpack _require _ _ ( 0 ) ;
2017-11-15 07:51:53 +01:00
var DEFAULT _CLASSNAMES = exports . DEFAULT _CLASSNAMES = {
containerOuter : 'choices' ,
containerInner : 'choices__inner' ,
input : 'choices__input' ,
inputCloned : 'choices__input--cloned' ,
list : 'choices__list' ,
listItems : 'choices__list--multiple' ,
listSingle : 'choices__list--single' ,
listDropdown : 'choices__list--dropdown' ,
item : 'choices__item' ,
itemSelectable : 'choices__item--selectable' ,
itemDisabled : 'choices__item--disabled' ,
itemChoice : 'choices__item--choice' ,
placeholder : 'choices__placeholder' ,
group : 'choices__group' ,
groupHeading : 'choices__heading' ,
button : 'choices__button' ,
activeState : 'is-active' ,
focusState : 'is-focused' ,
openState : 'is-open' ,
disabledState : 'is-disabled' ,
highlightedState : 'is-highlighted' ,
hiddenState : 'is-hidden' ,
flippedState : 'is-flipped' ,
loadingState : 'is-loading' ,
noResults : 'has-no-results' ,
noChoices : 'has-no-choices'
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var DEFAULT _CONFIG = exports . 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 ,
duplicateItems : true ,
delimiter : ',' ,
paste : true ,
searchEnabled : true ,
searchChoices : true ,
searchFloor : 1 ,
searchResultLimit : 4 ,
searchFields : [ 'label' , 'value' ] ,
position : 'auto' ,
resetScrollPosition : true ,
regexFilter : null ,
shouldSort : true ,
shouldSortItems : false ,
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-02-02 12:08:03 +01:00
uniqueItemText : 'Only unique values can be added.' ,
2017-11-15 07:51:53 +01:00
addItemText : function addItemText ( value ) {
2018-04-25 10:20:59 +02:00
return 'Press Enter to add <b>"' + ( 0 , _utils . stripHTML ) ( value ) + '"</b>' ;
2017-11-15 07:51:53 +01:00
} ,
maxItemText : function maxItemText ( maxItemCount ) {
return 'Only ' + maxItemCount + ' values can be added.' ;
} ,
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 ,
callbackOnCreateTemplates : null
} ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var EVENTS = exports . EVENTS = {
showDropdown : 'showDropdown' ,
hideDropdown : 'hideDropdown' ,
change : 'change' ,
choice : 'choice' ,
search : 'search' ,
addItem : 'addItem' ,
removeItem : 'removeItem' ,
highlightItem : 'highlightItem'
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var ACTION _TYPES = exports . ACTION _TYPES = {
ADD _CHOICE : 'ADD_CHOICE' ,
FILTER _CHOICES : 'FILTER_CHOICES' ,
ACTIVATE _CHOICES : 'ACTIVATE_CHOICES' ,
CLEAR _CHOICES : 'CLEAR_CHOICES' ,
ADD _GROUP : 'ADD_GROUP' ,
ADD _ITEM : 'ADD_ITEM' ,
REMOVE _ITEM : 'REMOVE_ITEM' ,
HIGHLIGHT _ITEM : 'HIGHLIGHT_ITEM' ,
CLEAR _ALL : 'CLEAR_ALL'
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var KEY _CODES = exports . KEY _CODES = {
BACK _KEY : 46 ,
DELETE _KEY : 8 ,
ENTER _KEY : 13 ,
A _KEY : 65 ,
ESC _KEY : 27 ,
UP _KEY : 38 ,
DOWN _KEY : 40 ,
PAGE _UP _KEY : 33 ,
PAGE _DOWN _KEY : 34
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var SCROLLING _SPEED = exports . SCROLLING _SPEED = 4 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 2 */
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
Object . defineProperty ( _ _webpack _exports _ _ , "__esModule" , { value : true } ) ;
2017-11-07 12:59:49 +01:00
2017-11-20 13:59:12 +01:00
// EXTERNAL MODULE: ./node_modules/lodash-es/_freeGlobal.js
2018-02-02 12:08:03 +01:00
var _freeGlobal = _ _webpack _require _ _ ( 10 ) ;
2017-11-07 12:59:49 +01:00
2017-11-20 13:59:12 +01:00
// CONCATENATED MODULE: ./node_modules/lodash-es/_root.js
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self . Object === Object && self ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/** Used as a reference to the global object. */
var root = _freeGlobal [ "a" /* default */ ] || freeSelf || Function ( 'return this' ) ( ) ;
2017-06-27 13:42:01 +02:00
2017-11-15 07:51:53 +01:00
/* harmony default export */ var _root = ( root ) ;
2017-06-27 13:42:01 +02:00
2017-11-20 13:59:12 +01:00
// CONCATENATED MODULE: ./node_modules/lodash-es/_Symbol.js
2017-06-27 13:42:01 +02:00
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
/** Built-in value references. */
var Symbol = _root . Symbol ;
/* harmony default export */ var _Symbol = ( Symbol ) ;
2017-11-20 13:59:12 +01:00
// CONCATENATED MODULE: ./node_modules/lodash-es/_getRawTag.js
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/** Used for built-in method references. */
var objectProto = Object . prototype ;
/** Used to check objects for own properties. */
var _getRawTag _hasOwnProperty = objectProto . hasOwnProperty ;
2017-11-07 12:59:49 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Used to resolve the
* [ ` toStringTag ` ] ( http : //ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values .
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
var nativeObjectToString = objectProto . toString ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/** Built-in value references. */
var symToStringTag = _Symbol ? _Symbol . toStringTag : undefined ;
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* A specialized version of ` baseGetTag ` which ignores ` Symbol.toStringTag ` values .
2017-11-13 20:13:37 +01:00
*
2017-11-15 07:51:53 +01:00
* @ private
* @ param { * } value The value to query .
* @ returns { string } Returns the raw ` toStringTag ` .
2017-11-13 20:13:37 +01:00
* /
2017-11-15 07:51:53 +01:00
function getRawTag ( value ) {
var isOwn = _getRawTag _hasOwnProperty . call ( value , symToStringTag ) ,
tag = value [ symToStringTag ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
try {
value [ symToStringTag ] = undefined ;
var unmasked = true ;
} catch ( e ) { }
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var result = nativeObjectToString . call ( value ) ;
if ( unmasked ) {
if ( isOwn ) {
value [ symToStringTag ] = tag ;
} else {
delete value [ symToStringTag ] ;
}
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
return result ;
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 _getRawTag = ( getRawTag ) ;
2017-11-20 13:59:12 +01:00
// CONCATENATED MODULE: ./node_modules/lodash-es/_objectToString.js
2017-11-15 07:51:53 +01:00
/** Used for built-in method references. */
var _objectToString _objectProto = Object . prototype ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* 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 ;
2017-11-07 12:59:49 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Converts ` value ` to a string using ` Object.prototype.toString ` .
2017-11-07 12:59:49 +01:00
*
2017-11-15 07:51:53 +01:00
* @ private
* @ param { * } value The value to convert .
* @ returns { string } Returns the converted string .
2017-11-07 12:59:49 +01:00
* /
2017-11-15 07:51:53 +01:00
function objectToString ( value ) {
return _objectToString _nativeObjectToString . call ( 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 _objectToString = ( objectToString ) ;
2017-11-07 12:59:49 +01:00
2017-11-20 13:59:12 +01:00
// CONCATENATED MODULE: ./node_modules/lodash-es/_baseGetTag.js
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/** `Object#toString` result references. */
var nullTag = '[object Null]' ,
undefinedTag = '[object Undefined]' ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/** Built-in value references. */
var _baseGetTag _symToStringTag = _Symbol ? _Symbol . toStringTag : undefined ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* The base implementation of ` getTag ` without fallbacks for buggy environments .
*
* @ private
* @ 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
2017-11-20 13:59:12 +01:00
// EXTERNAL MODULE: ./node_modules/symbol-observable/index.js
2018-02-02 12:08:03 +01:00
var symbol _observable = _ _webpack _require _ _ ( 11 ) ;
2017-11-15 07:51:53 +01:00
var symbol _observable _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( symbol _observable ) ;
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 } ;
}
} , _ref [ symbol _observable _default . a ] = function ( ) {
return this ;
} , _ref ;
}
// When a store is created, an "INIT" action is dispatched so that every
// reducer returns their initial state. This effectively populates
// the initial state tree.
dispatch ( { type : ActionTypes . INIT } ) ;
return _ref2 = {
dispatch : dispatch ,
subscribe : subscribe ,
getState : getState ,
replaceReducer : replaceReducer
} , _ref2 [ symbol _observable _default . a ] = observable , _ref2 ;
}
// 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 }
* /
function warning _warning ( message ) {
/* eslint-disable no-console */
if ( typeof console !== 'undefined' && typeof console . error === 'function' ) {
console . error ( message ) ;
}
/* eslint-enable no-console */
try {
// This error was thrown as a convenience so that if you enable
// "break on all exceptions" in your console,
// it would pause the execution at this line.
throw new Error ( message ) ;
/* 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
2017-11-15 07:51:53 +01:00
if ( false ) {
if ( typeof reducers [ key ] === 'undefined' ) {
warning ( 'No reducer provided for key "' + key + '"' ) ;
}
2017-11-13 20:13:37 +01:00
}
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 ;
if ( false ) {
unexpectedKeyCache = { } ;
}
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
2017-11-15 07:51:53 +01:00
if ( false ) {
var warningMessage = getUnexpectedStateShapeWarningMessage ( state , finalReducers , action , unexpectedKeyCache ) ;
if ( warningMessage ) {
warning ( warningMessage ) ;
}
2017-11-13 20:13:37 +01:00
}
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
/* concated harmony reexport */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "createStore" , function ( ) { return createStore _createStore ; } ) ;
/* concated harmony reexport */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "combineReducers" , function ( ) { return combineReducers ; } ) ;
/* concated harmony reexport */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "bindActionCreators" , function ( ) { return bindActionCreators ; } ) ;
/* concated harmony reexport */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "applyMiddleware" , function ( ) { return applyMiddleware ; } ) ;
/* concated harmony reexport */ _ _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
2017-11-15 07:51:53 +01:00
if ( false ) {
warning ( 'You are currently using minified code outside of NODE_ENV === \'production\'. ' + 'This means that you are running a slower development build of Redux. ' + 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + 'or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' + 'to ensure you have the correct code for your production build.' ) ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 3 */
/***/ ( function ( module , exports ) {
2016-08-23 08:24:45 +02:00
2018-02-02 12:08:03 +01:00
var g ;
// This works in non-strict mode
g = ( function ( ) {
return this ;
} ) ( ) ;
try {
// This works if eval is allowed (see CSP)
g = g || Function ( "return this" ) ( ) || ( 1 , eval ) ( "this" ) ;
} catch ( e ) {
// This works if the window reference is available
if ( typeof window === "object" )
g = window ;
}
// 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 ;
2016-08-23 08:24:45 +02:00
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 4 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
var _createClass = 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 ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2017-02-17 10:26:08 +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-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
var WrappedElement = function ( ) {
function WrappedElement ( instance , element , classNames ) {
_classCallCheck ( this , WrappedElement ) ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
this . parentInstance = instance ;
this . element = element ;
this . classNames = classNames ;
this . isDisabled = false ;
}
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
_createClass ( WrappedElement , [ {
key : 'conceal' ,
value : function conceal ( ) {
// Hide passed input
this . element . classList . add ( this . classNames . input , this . classNames . hiddenState ) ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
// Remove element from tab index
this . element . tabIndex = '-1' ;
// Backup original styles if any
var origStyle = this . element . getAttribute ( 'style' ) ;
if ( origStyle ) {
this . element . setAttribute ( 'data-choice-orig-style' , origStyle ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
this . element . setAttribute ( 'aria-hidden' , 'true' ) ;
this . element . setAttribute ( 'data-choice' , 'active' ) ;
2017-11-13 20:13:37 +01:00
}
} , {
2017-11-15 07:51:53 +01:00
key : 'reveal' ,
value : function reveal ( ) {
// Reinstate passed element
this . element . classList . remove ( this . classNames . input , this . classNames . hiddenState ) ;
this . element . removeAttribute ( 'tabindex' ) ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
// Recover original styles if any
var origStyle = this . element . getAttribute ( 'data-choice-orig-style' ) ;
if ( origStyle ) {
this . element . removeAttribute ( 'data-choice-orig-style' ) ;
this . element . setAttribute ( 'style' , origStyle ) ;
} else {
this . element . removeAttribute ( 'style' ) ;
}
this . element . removeAttribute ( 'aria-hidden' ) ;
this . element . removeAttribute ( 'data-choice' ) ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
// Re-assign values - this is weird, I know
this . element . value = this . element . value ;
}
2017-11-13 20:13:37 +01:00
} , {
key : 'enable' ,
value : function enable ( ) {
2017-11-15 07:51:53 +01:00
this . element . removeAttribute ( 'disabled' ) ;
this . element . disabled = false ;
2017-11-13 20:13:37 +01:00
this . isDisabled = false ;
2017-11-07 12:59:49 +01:00
}
2017-11-13 20:13:37 +01:00
} , {
key : 'disable' ,
value : function disable ( ) {
2017-11-15 07:51:53 +01:00
this . element . setAttribute ( 'disabled' , '' ) ;
this . element . disabled = true ;
2017-11-13 20:13:37 +01:00
this . isDisabled = true ;
}
} , {
2017-11-15 07:51:53 +01:00
key : 'triggerEvent' ,
value : function triggerEvent ( eventType , data ) {
( 0 , _utils . dispatchEvent ) ( this . element , eventType , data ) ;
2017-11-13 20:13:37 +01:00
}
2018-04-25 10:20:59 +02:00
} , {
key : 'value' ,
get : function get ( ) {
return this . element . 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
return WrappedElement ;
2017-11-13 20:13:37 +01:00
} ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
exports . default = WrappedElement ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 5 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . TEMPLATES = undefined ;
var _classnames = _ _webpack _require _ _ ( 25 ) ;
var _classnames2 = _interopRequireDefault ( _classnames ) ;
var _utils = _ _webpack _require _ _ ( 0 ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
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 ; }
var TEMPLATES = exports . TEMPLATES = {
containerOuter : function containerOuter ( globalClasses , direction , isSelectElement , isSelectOneElement , searchEnabled , passedElementType ) {
var tabIndex = isSelectOneElement ? 'tabindex="0"' : '' ;
var role = isSelectElement ? 'role="listbox"' : '' ;
var ariaAutoComplete = '' ;
if ( isSelectElement && searchEnabled ) {
role = 'role="combobox"' ;
ariaAutoComplete = 'aria-autocomplete="list"' ;
}
return ( 0 , _utils . strToEl ) ( '\n <div\n class="' + globalClasses . containerOuter + '"\n data-type="' + passedElementType + '"\n ' + role + '\n ' + tabIndex + '\n ' + ariaAutoComplete + '\n aria-haspopup="true"\n aria-expanded="false"\n dir="' + direction + '"\n >\n </div>\n ' ) ;
} ,
containerInner : function containerInner ( globalClasses ) {
return ( 0 , _utils . strToEl ) ( '\n <div class="' + globalClasses . containerInner + '"></div>\n ' ) ;
} ,
itemList : function itemList ( globalClasses , isSelectOneElement ) {
var _classNames ;
var localClasses = ( 0 , _classnames2 . default ) ( globalClasses . list , ( _classNames = { } , _defineProperty ( _classNames , globalClasses . listSingle , isSelectOneElement ) , _defineProperty ( _classNames , globalClasses . listItems , ! isSelectOneElement ) , _classNames ) ) ;
return ( 0 , _utils . strToEl ) ( '\n <div class="' + localClasses + '"></div>\n ' ) ;
} ,
placeholder : function placeholder ( globalClasses , value ) {
return ( 0 , _utils . strToEl ) ( '\n <div class="' + globalClasses . placeholder + '">\n ' + value + '\n </div>\n ' ) ;
} ,
item : function item ( globalClasses , data , removeItemButton ) {
var _classNames2 ;
var ariaSelected = data . active ? 'aria-selected="true"' : '' ;
var ariaDisabled = data . disabled ? 'aria-disabled="true"' : '' ;
var localClasses = ( 0 , _classnames2 . default ) ( globalClasses . item , ( _classNames2 = { } , _defineProperty ( _classNames2 , globalClasses . highlightedState , data . highlighted ) , _defineProperty ( _classNames2 , globalClasses . itemSelectable , ! data . highlighted ) , _defineProperty ( _classNames2 , globalClasses . placeholder , data . placeholder ) , _classNames2 ) ) ;
if ( removeItemButton ) {
var _classNames3 ;
localClasses = ( 0 , _classnames2 . default ) ( globalClasses . item , ( _classNames3 = { } , _defineProperty ( _classNames3 , globalClasses . highlightedState , data . highlighted ) , _defineProperty ( _classNames3 , globalClasses . itemSelectable , ! data . disabled ) , _defineProperty ( _classNames3 , globalClasses . placeholder , data . placeholder ) , _classNames3 ) ) ;
return ( 0 , _utils . strToEl ) ( '\n <div\n class="' + localClasses + '"\n data-item\n data-id="' + data . id + '"\n data-value="' + data . value + '"\n data-deletable\n ' + ariaSelected + '\n ' + ariaDisabled + '\n >\n ' + data . label + '<!--\n --><button\n type="button"\n class="' + globalClasses . button + '"\n data-button\n aria-label="Remove item: \'' + data . value + '\'"\n >\n Remove item\n </button>\n </div>\n ' ) ;
}
return ( 0 , _utils . strToEl ) ( '\n <div\n class="' + localClasses + '"\n data-item\n data-id="' + data . id + '"\n data-value="' + data . value + '"\n ' + ariaSelected + '\n ' + ariaDisabled + '\n >\n ' + data . label + '\n </div>\n ' ) ;
} ,
choiceList : function choiceList ( globalClasses , isSelectOneElement ) {
var ariaMultiSelectable = ! isSelectOneElement ? 'aria-multiselectable="true"' : '' ;
return ( 0 , _utils . strToEl ) ( '\n <div\n class="' + globalClasses . list + '"\n dir="ltr"\n role="listbox"\n ' + ariaMultiSelectable + '\n >\n </div>\n ' ) ;
} ,
choiceGroup : function choiceGroup ( globalClasses , data ) {
var ariaDisabled = data . disabled ? 'aria-disabled="true"' : '' ;
var localClasses = ( 0 , _classnames2 . default ) ( globalClasses . group , _defineProperty ( { } , globalClasses . itemDisabled , data . disabled ) ) ;
return ( 0 , _utils . strToEl ) ( '\n <div\n class="' + localClasses + '"\n data-group\n data-id="' + data . id + '"\n data-value="' + data . value + '"\n role="group"\n ' + ariaDisabled + '\n >\n <div class="' + globalClasses . groupHeading + '">' + data . value + '</div>\n </div>\n ' ) ;
} ,
choice : function choice ( globalClasses , data , itemSelectText ) {
var _classNames5 ;
var role = data . groupId > 0 ? 'role="treeitem"' : 'role="option"' ;
var localClasses = ( 0 , _classnames2 . 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="' + localClasses + '"\n data-select-text="' + itemSelectText + '"\n data-choice\n data-id="' + data . id + '"\n data-value="' + data . value + '"\n ' + ( data . disabled ? 'data-choice-disabled aria-disabled="true"' : 'data-choice-selectable' ) + '\n id="' + data . elementId + '"\n ' + role + '\n >\n ' + data . label + '\n </div>\n ' ) ;
} ,
input : function input ( globalClasses ) {
var localClasses = ( 0 , _classnames2 . default ) ( globalClasses . input , globalClasses . inputCloned ) ;
return ( 0 , _utils . strToEl ) ( '\n <input\n type="text"\n class="' + 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 , _classnames2 . default ) ( globalClasses . list , globalClasses . listDropdown ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
return ( 0 , _utils . strToEl ) ( '\n <div\n class="' + localClasses + '"\n aria-expanded="false"\n >\n </div>\n ' ) ;
} ,
notice : function notice ( globalClasses , label ) {
var _classNames6 ;
var type = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : '' ;
var localClasses = ( 0 , _classnames2 . 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="' + localClasses + '">\n ' + label + '\n </div>\n ' ) ;
} ,
option : function option ( data ) {
return ( 0 , _utils . strToEl ) ( '\n <option value="' + data . value + '" ' + ( data . selected ? 'selected' : '' ) + ' ' + ( data . disabled ? 'disabled' : '' ) + '>' + data . label + '</option>\n ' ) ;
}
} ;
exports . default = TEMPLATES ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 6 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
module . exports = _ _webpack _require _ _ ( 7 ) ;
/***/ } ) ,
/* 7 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
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
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
var _createClass = 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 ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
2017-11-13 20:13:37 +01:00
2018-02-02 12:08:03 +01:00
var _fuse = _ _webpack _require _ _ ( 8 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _fuse2 = _interopRequireDefault ( _fuse ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _store = _ _webpack _require _ _ ( 9 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _store2 = _interopRequireDefault ( _store ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _dropdown = _ _webpack _require _ _ ( 19 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _dropdown2 = _interopRequireDefault ( _dropdown ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _container = _ _webpack _require _ _ ( 20 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _container2 = _interopRequireDefault ( _container ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _input = _ _webpack _require _ _ ( 21 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _input2 = _interopRequireDefault ( _input ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _list = _ _webpack _require _ _ ( 22 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _list2 = _interopRequireDefault ( _list ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _wrappedInput = _ _webpack _require _ _ ( 23 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _wrappedInput2 = _interopRequireDefault ( _wrappedInput ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _wrappedSelect = _ _webpack _require _ _ ( 24 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _wrappedSelect2 = _interopRequireDefault ( _wrappedSelect ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _constants = _ _webpack _require _ _ ( 1 ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _templates = _ _webpack _require _ _ ( 5 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _choices = _ _webpack _require _ _ ( 26 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _items = _ _webpack _require _ _ ( 27 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _groups = _ _webpack _require _ _ ( 28 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _misc = _ _webpack _require _ _ ( 29 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
_ _webpack _require _ _ ( 30 ) ;
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 _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 ; }
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
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
2017-11-13 20:13:37 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Choices
2017-11-13 20:13:37 +01:00
* /
2017-11-15 07:51:53 +01:00
var Choices = function ( ) {
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 there are multiple elements, create a new instance
// for each element besides the first one (as that already has an instance)
if ( ( 0 , _utils . isType ) ( 'String' , element ) ) {
var elements = document . querySelectorAll ( element ) ;
if ( elements . length > 1 ) {
for ( var i = 1 ; i < elements . length ; i += 1 ) {
var el = elements [ i ] ;
/* eslint-disable no-new */
new Choices ( el , userConfig ) ;
}
}
}
var defaultConfig = _extends ( { } , _constants . DEFAULT _CONFIG , {
items : [ ] ,
choices : [ ] ,
classNames : _constants . DEFAULT _CLASSNAMES ,
2018-02-02 12:08:03 +01:00
sortFn : _utils . sortByAlpha
2017-11-15 07:51:53 +01:00
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Merge options with user options
this . config = ( 0 , _utils . extend ) ( defaultConfig , Choices . userDefaults , userConfig ) ;
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' ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Create data store
this . store = new _store2 . default ( this . render ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// State tracking
this . initialised = false ;
this . currentState = { } ;
this . prevState = { } ;
this . currentValue = '' ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Retrieve triggering element (i.e. element with 'data-choice' trigger)
var passedElement = ( 0 , _utils . isType ) ( 'String' , element ) ? document . querySelector ( element ) : element ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . isTextElement = passedElement . type === 'text' ;
this . isSelectOneElement = passedElement . type === 'select-one' ;
this . isSelectMultipleElement = passedElement . type === 'select-multiple' ;
this . isSelectElement = this . isSelectOneElement || this . isSelectMultipleElement ;
this . isValidElementType = this . isTextElement || this . isSelectElement ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . isTextElement ) {
this . passedElement = new _wrappedInput2 . default ( this , passedElement , this . config . classNames ) ;
} else if ( this . isSelectElement ) {
this . passedElement = new _wrappedSelect2 . default ( this , passedElement , this . config . classNames ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! this . passedElement ) {
if ( ! this . config . silent ) {
console . error ( 'Passed element not found' ) ;
}
return false ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . isIe11 = ! ! ( navigator . userAgent . match ( /Trident/ ) && navigator . userAgent . match ( /rv[ :]11/ ) ) ;
this . isScrollingOnIe = false ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . config . shouldSortItems === true && this . isSelectOneElement ) {
if ( ! this . config . silent ) {
console . warn ( 'shouldSortElements: Type of passed element is \'select-one\', falling back to false.' ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . highlightPosition = 0 ;
this . canSearch = this . config . searchEnabled ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . placeholder = false ;
if ( ! this . isSelectOneElement ) {
this . placeholder = this . config . placeholder ? this . config . placeholderValue || this . passedElement . element . getAttribute ( 'placeholder' ) : false ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +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 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Then add any values passed from attribute
2018-04-25 10:20:59 +02:00
if ( this . passedElement . value ) {
this . presetItems = this . presetItems . concat ( this . passedElement . value . split ( this . config . delimiter ) ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Set unique base Id
this . baseId = ( 0 , _utils . generateId ) ( this . passedElement . element , 'choices-' ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . idNames = {
itemChoice : 'item-choice'
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Bind methods
this . render = this . render . bind ( this ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Bind event handlers
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 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Monitor touch taps/scrolls
this . wasTap = true ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Cutting the mustard
var cuttingTheMustard = 'classList' in document . documentElement ;
if ( ! cuttingTheMustard && ! this . config . silent ) {
console . error ( 'Choices: Your browser doesn\'t support Choices' ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var canInit = ( 0 , _utils . isElement ) ( this . passedElement . element ) && this . isValidElementType ;
if ( canInit ) {
// If element has already been initialised with Choices
if ( this . passedElement . element . getAttribute ( 'data-choice' ) === 'active' ) {
return false ;
}
// Let's go
this . init ( ) ;
} else if ( ! this . config . silent ) {
console . error ( 'Incompatible input passed' ) ;
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
/ * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= Public functions =
=== === === === === === === === === === === === === = * /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Initialise Choices
* @ return
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
_createClass ( Choices , [ {
key : 'init' ,
value : function init ( ) {
if ( this . initialised ) {
return ;
}
// Set initialise flag
this . initialised = true ;
2018-04-25 10:20:59 +02:00
// Create required templates
2017-11-15 07:51:53 +01:00
this . _createTemplates ( ) ;
2018-04-25 10:20:59 +02:00
// Create required elements
this . _createElements ( ) ;
2017-11-15 07:51:53 +01:00
// Generate input markup
this . _createStructure ( ) ;
// Subscribe store to render method
this . store . subscribe ( this . render ) ;
// Render any items
this . render ( ) ;
// Trigger event listeners
this . _addEventListeners ( ) ;
var callback = this . config . callbackOnInit ;
// Run callback if it is a function
if ( callback && ( 0 , _utils . isType ) ( 'Function' , callback ) ) {
callback . call ( this ) ;
}
}
/ * *
* Destroy Choices and nullify values
* @ return
* @ public
* /
} , {
key : 'destroy' ,
value : function destroy ( ) {
if ( ! this . initialised ) {
return ;
}
// Remove all event listeners
this . _removeEventListeners ( ) ;
this . passedElement . reveal ( ) ;
2018-02-02 12:08:03 +01:00
this . containerOuter . unwrap ( this . passedElement . element ) ;
if ( this . isSelectElement ) {
2018-04-25 10:20:59 +02:00
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
// Clear data store
this . clearStore ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Nullify instance-specific data
this . config . templates = null ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Uninitialise
this . initialised = 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
/ * *
* Enable interaction with Choices
* @ return { Object } Class instance
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'enable' ,
value : function enable ( ) {
if ( ! this . initialised ) {
return this ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . passedElement . enable ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . containerOuter . isDisabled ) {
this . _addEventListeners ( ) ;
this . input . enable ( ) ;
this . containerOuter . enable ( ) ;
}
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
2017-11-15 07:51:53 +01:00
/ * *
* Disable interaction with Choices
* @ return { Object } Class instance
* @ public
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'disable' ,
value : function disable ( ) {
if ( ! this . initialised ) {
return this ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . passedElement . disable ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! this . containerOuter . isDisabled ) {
this . _removeEventListeners ( ) ;
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-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Render group choices into a DOM fragment and append to choice list
* @ param { Array } groups Groups to add to list
* @ param { Array } choices Choices to add to groups
* @ param { DocumentFragment } fragment Fragment to add groups and options to ( optional )
* @ return { DocumentFragment } Populated options fragment
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2017-12-20 16:10:01 +01:00
key : 'createGroupsFragment' ,
value : function createGroupsFragment ( groups , choices , fragment ) {
2017-11-15 07:51:53 +01:00
var _this = this ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var groupFragment = fragment || document . createDocumentFragment ( ) ;
var getGroupChoices = function getGroupChoices ( group ) {
return choices . filter ( function ( choice ) {
if ( _this . isSelectOneElement ) {
return choice . groupId === group . id ;
}
return choice . groupId === group . id && ( _this . config . renderSelectedChoices === 'always' || ! choice . selected ) ;
} ) ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If sorting is enabled, filter groups
if ( this . config . shouldSort ) {
2018-02-02 12:08:03 +01:00
groups . sort ( this . config . sortFn ) ;
2017-11-15 07:51:53 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
groups . forEach ( function ( group ) {
var groupChoices = getGroupChoices ( group ) ;
if ( groupChoices . length >= 1 ) {
var dropdownGroup = _this . _getTemplate ( 'choiceGroup' , group ) ;
groupFragment . appendChild ( dropdownGroup ) ;
2017-12-20 16:10:01 +01:00
_this . createChoicesFragment ( groupChoices , groupFragment , true ) ;
2017-11-15 07:51:53 +01:00
}
} ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
return groupFragment ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Render choices into a DOM fragment and append to choice list
* @ param { Array } choices Choices to add to list
* @ param { DocumentFragment } fragment Fragment to add choices to ( optional )
* @ return { DocumentFragment } Populated choices fragment
2017-11-13 20:13:37 +01:00
* @ private
2017-11-07 12:59:49 +01:00
* /
} , {
2017-12-20 16:10:01 +01:00
key : 'createChoicesFragment' ,
value : function createChoicesFragment ( choices , fragment ) {
2017-11-15 07:51:53 +01:00
var _this2 = this ;
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 ( ) ;
var _config = this . config ,
renderSelectedChoices = _config . renderSelectedChoices ,
searchResultLimit = _config . searchResultLimit ,
renderChoiceLimit = _config . renderChoiceLimit ;
2018-02-02 12:08:03 +01:00
var filter = this . isSearching ? _utils . sortByScore : this . config . sortFn ;
2017-11-15 07:51:53 +01:00
var appendChoice = function appendChoice ( choice ) {
var shouldRender = renderSelectedChoices === 'auto' ? _this2 . isSelectOneElement || ! choice . selected : true ;
if ( shouldRender ) {
var dropdownItem = _this2 . _getTemplate ( 'choice' , choice , _this2 . config . itemSelectText ) ;
choicesFragment . appendChild ( dropdownItem ) ;
}
} ;
var rendererableChoices = choices ;
if ( renderSelectedChoices === 'auto' && ! this . isSelectOneElement ) {
rendererableChoices = choices . filter ( function ( choice ) {
return ! choice . selected ;
} ) ;
}
// Split array into placeholders and "normal" choices
var _rendererableChoices$ = rendererableChoices . reduce ( function ( acc , choice ) {
if ( choice . placeholder ) {
acc . placeholderChoices . push ( choice ) ;
} else {
acc . normalChoices . push ( choice ) ;
}
return acc ;
} , { placeholderChoices : [ ] , normalChoices : [ ] } ) ,
placeholderChoices = _rendererableChoices$ . placeholderChoices ,
normalChoices = _rendererableChoices$ . normalChoices ;
// If sorting is enabled or the user is searching, filter choices
if ( this . config . shouldSort || this . isSearching ) {
normalChoices . sort ( filter ) ;
}
var choiceLimit = rendererableChoices . length ;
// Prepend placeholeder
var sortedChoices = [ ] . concat ( _toConsumableArray ( placeholderChoices ) , _toConsumableArray ( normalChoices ) ) ;
if ( this . isSearching ) {
choiceLimit = searchResultLimit ;
} else if ( renderChoiceLimit > 0 && ! withinGroup ) {
choiceLimit = renderChoiceLimit ;
}
// Add each choice to dropdown within range
for ( var i = 0 ; i < choiceLimit ; i += 1 ) {
if ( sortedChoices [ i ] ) {
appendChoice ( sortedChoices [ i ] ) ;
}
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
return choicesFragment ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Render items into a DOM fragment and append to items list
* @ param { Array } items Items to add to list
* @ param { DocumentFragment } [ fragment ] Fragment to add items to ( optional )
2017-11-13 20:13:37 +01:00
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
} , {
2017-12-20 16:10:01 +01:00
key : 'createItemsFragment' ,
value : function createItemsFragment ( items ) {
2017-11-15 07:51:53 +01:00
var _this3 = this ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var fragment = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : null ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Create fragment to add elements to
var itemListFragment = fragment || document . createDocumentFragment ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If sorting is enabled, filter items
if ( this . config . shouldSortItems && ! this . isSelectOneElement ) {
2018-02-02 12:08:03 +01:00
items . sort ( this . config . sortFn ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
if ( this . isTextElement ) {
// Update the value of the hidden input
2018-04-25 10:20:59 +02:00
this . passedElement . value = items ;
2017-11-15 07:51:53 +01:00
} else {
// Update the options of the hidden input
2018-04-25 10:20:59 +02:00
this . passedElement . options = items ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
var addItemToFragment = function addItemToFragment ( item ) {
// Create new list element
var listItem = _this3 . _getTemplate ( 'item' , item , _this3 . config . removeItemButton ) ;
// Append it to list
itemListFragment . appendChild ( listItem ) ;
} ;
// Add each list item to list
items . forEach ( function ( item ) {
return addItemToFragment ( item ) ;
} ) ;
return itemListFragment ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Render DOM with values
* @ return
* @ private
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : 'render' ,
value : function render ( ) {
2018-04-25 10:20:59 +02:00
this . currentState = this . store . state ;
2017-11-15 07:51:53 +01:00
var stateChanged = this . currentState . choices !== this . prevState . choices || this . currentState . groups !== this . prevState . groups || this . currentState . items !== this . prevState . items ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! stateChanged ) {
return ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
/* Choices */
if ( this . isSelectElement ) {
// Get active groups/choices
2018-04-25 10:20:59 +02:00
var activeGroups = this . store . activeGroups ;
var activeChoices = this . store . activeChoices ;
2017-11-15 07:51:53 +01:00
var choiceListFragment = document . createDocumentFragment ( ) ;
// Clear choices
this . choiceList . clear ( ) ;
// Scroll back to top of choices list
if ( this . config . resetScrollPosition ) {
this . choiceList . scrollTo ( 0 ) ;
}
// If we have grouped options
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 ;
} ) ;
if ( activePlaceholders . length >= 1 ) {
2017-12-20 16:10:01 +01:00
choiceListFragment = this . createChoicesFragment ( activePlaceholders , choiceListFragment ) ;
2017-11-15 07:51:53 +01:00
}
2017-12-20 16:10:01 +01:00
choiceListFragment = this . createGroupsFragment ( activeGroups , activeChoices , choiceListFragment ) ;
2017-11-15 07:51:53 +01:00
} else if ( activeChoices . length >= 1 ) {
2017-12-20 16:10:01 +01:00
choiceListFragment = this . createChoicesFragment ( activeChoices , choiceListFragment ) ;
2017-11-15 07:51:53 +01:00
}
// If we have choices to show
if ( choiceListFragment . childNodes && choiceListFragment . childNodes . length > 0 ) {
2018-04-25 10:20:59 +02:00
var activeItems = this . store . activeItems ;
var canAddItem = this . _canAddItem ( activeItems , this . input . value ) ;
2018-02-02 12:08:03 +01:00
2017-11-15 07:51:53 +01:00
// ...and we can select them
if ( canAddItem . response ) {
// ...append them and highlight the first choice
this . choiceList . append ( choiceListFragment ) ;
this . _highlightChoice ( ) ;
} else {
// ...otherwise show a notice
this . choiceList . append ( this . _getTemplate ( 'notice' , canAddItem . notice ) ) ;
}
} else {
// Otherwise show a notice
var dropdownItem = void 0 ;
var notice = void 0 ;
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 ) ;
}
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
/* Items */
2018-02-02 12:08:03 +01:00
if ( this . currentState . items !== this . prevState . items ) {
// Get active items (items that can be selected)
2018-04-25 10:20:59 +02:00
var _activeItems = this . store . activeItems || [ ] ;
2018-02-02 12:08:03 +01:00
// Clear list
this . itemList . clear ( ) ;
if ( _activeItems . length ) {
// Create a fragment to store our list items
// (so we don't have to update the DOM for each item)
var itemListFragment = this . createItemsFragment ( _activeItems ) ;
// If we have items to add, append them
if ( itemListFragment . childNodes ) {
this . itemList . append ( itemListFragment ) ;
}
2017-11-13 20:13:37 +01:00
}
}
2017-11-15 07:51:53 +01:00
this . prevState = this . currentState ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
/ * *
* Select item ( a selected item can be deleted )
* @ param { Element } item Element to select
* @ param { Boolean } [ runEvent = true ] Whether to trigger 'highlightItem' event
* @ return { Object } Class instance
* @ public
* /
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : 'highlightItem' ,
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 ,
groupId = _item$groupId === undefined ? - 1 : _item$groupId ,
_item$value = item . value ,
value = _item$value === undefined ? '' : _item$value ,
_item$label = item . label ,
label = _item$label === undefined ? '' : _item$label ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var group = groupId >= 0 ? this . store . getGroupById ( groupId ) : null ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01: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
}
/ * *
2017-11-15 07:51:53 +01:00
* Deselect item
* @ param { Element } item Element to de - select
* @ return { Object } Class instance
* @ public
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : 'unhighlightItem' ,
value : function unhighlightItem ( item ) {
if ( ! item ) {
return this ;
}
var id = item . id ,
_item$groupId2 = item . groupId ,
groupId = _item$groupId2 === undefined ? - 1 : _item$groupId2 ,
_item$value2 = item . value ,
value = _item$value2 === undefined ? '' : _item$value2 ,
_item$label2 = item . label ,
label = _item$label2 === undefined ? '' : _item$label2 ;
var group = groupId >= 0 ? this . store . getGroupById ( groupId ) : null ;
this . store . dispatch ( ( 0 , _items . highlightItem ) ( id , false ) ) ;
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
}
/ * *
2017-11-15 07:51:53 +01:00
* Highlight items within store
* @ return { Object } Class instance
* @ public
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : 'highlightAll' ,
value : function highlightAll ( ) {
var _this4 = this ;
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
var items = this . store . items ;
2017-11-15 07:51:53 +01:00
items . forEach ( function ( item ) {
return _this4 . highlightItem ( item ) ;
} ) ;
return this ;
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
* Deselect items within store
* @ return { Object } Class instance
* @ public
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : 'unhighlightAll' ,
value : function unhighlightAll ( ) {
var _this5 = this ;
2018-04-25 10:20:59 +02:00
var items = this . store . items ;
2017-11-15 07:51:53 +01:00
items . forEach ( function ( item ) {
return _this5 . unhighlightItem ( item ) ;
} ) ;
return this ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Remove an item from the store by its value
* @ param { String } value Value to search for
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
} , {
2017-11-21 15:10:29 +01:00
key : 'removeActiveItemsByValue' ,
value : function removeActiveItemsByValue ( value ) {
2017-11-15 07:51:53 +01:00
var _this6 = this ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
if ( ! value ) {
2017-11-15 07:51:53 +01:00
return this ;
}
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
var items = this . store . activeItems ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
items . forEach ( function ( item ) {
if ( item . value === value ) {
_this6 . _removeItem ( item ) ;
}
} ) ;
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
2017-11-15 07:51:53 +01:00
/ * *
* Remove all items from store array
* @ note Removed items are soft deleted
* @ param { Number } excludedId Optionally exclude item by ID
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : 'removeActiveItems' ,
value : function removeActiveItems ( excludedId ) {
var _this7 = this ;
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
var items = this . store . activeItems ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
items . forEach ( function ( item ) {
2018-02-02 12:08:03 +01:00
if ( excludedId !== item . id ) {
2017-11-15 07:51:53 +01:00
_this7 . _removeItem ( item ) ;
}
} ) ;
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
}
2017-11-15 07:51:53 +01:00
/ * *
* Remove all selected items from store
* @ note Removed items are soft deleted
* @ return { Object } Class instance
* @ public
* /
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : 'removeHighlightedItems' ,
value : function removeHighlightedItems ( ) {
var _this8 = 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-04-25 10:20:59 +02:00
var items = this . store . highlightedActiveItems ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
items . forEach ( function ( item ) {
2018-02-02 12:08:03 +01:00
_this8 . _removeItem ( item ) ;
// If this action was performed by the user
// trigger the event
if ( runEvent ) {
_this8 . _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 ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Show dropdown to user by adding active state class
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'showDropdown' ,
2018-02-02 12:08:03 +01:00
value : function showDropdown ( focusInput ) {
2017-11-15 07:51:53 +01:00
if ( this . dropdown . isActive ) {
return this ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . dropdown . show ( ) ;
2018-04-25 10:20:59 +02:00
this . containerOuter . open ( this . dropdown . distanceFromTopWindow ( ) ) ;
2018-02-02 12:08:03 +01:00
if ( focusInput && this . canSearch ) {
this . input . focus ( ) ;
}
2017-11-15 07:51:53 +01:00
this . passedElement . triggerEvent ( _constants . EVENTS . showDropdown , { } ) ;
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
2017-11-15 07:51:53 +01:00
/ * *
* Hide dropdown from user
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'hideDropdown' ,
2018-02-02 12:08:03 +01:00
value : function hideDropdown ( blurInput ) {
2017-11-15 07:51:53 +01:00
if ( ! this . dropdown . isActive ) {
return this ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . dropdown . hide ( ) ;
2018-02-02 12:08:03 +01:00
this . containerOuter . close ( ) ;
if ( blurInput && this . canSearch ) {
this . input . removeActiveDescendant ( ) ;
this . input . blur ( ) ;
}
2017-11-15 07:51:53 +01:00
this . passedElement . triggerEvent ( _constants . EVENTS . hideDropdown , { } ) ;
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
2017-11-15 07:51:53 +01:00
/ * *
* Determine whether to hide or show dropdown based on its current state
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : 'toggleDropdown' ,
value : function toggleDropdown ( ) {
if ( this . dropdown . isActive ) {
this . hideDropdown ( ) ;
} else {
this . showDropdown ( true ) ;
}
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
2017-11-15 07:51:53 +01:00
/ * *
* Get value ( s ) of input ( i . e . inputted items ( text ) or selected choices ( select ) )
* @ param { Boolean } valueOnly Get only values of selected items , otherwise return selected items
* @ return { Array / String } selected value ( select - one ) or
* array of selected items ( inputs & select - multiple )
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'getValue' ,
value : function getValue ( ) {
var valueOnly = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : false ;
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
var items = this . store . activeItems ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var values = items . reduce ( function ( selectedItems , item ) {
var itemValue = valueOnly ? item . value : item ;
selectedItems . push ( itemValue ) ;
return selectedItems ;
} , [ ] ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return this . isSelectOneElement ? values [ 0 ] : values ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Set value of input . If the input is a select box , a choice will
* be created and selected otherwise an item will created directly .
* @ param { Array } args Array of value objects or value strings
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'setValue' ,
value : function setValue ( args ) {
var _this9 = 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
2017-11-15 07:51:53 +01:00
// Convert args to an iterable array
var values = [ ] . concat ( _toConsumableArray ( args ) ) ;
values . forEach ( function ( value ) {
return _this9 . _setChoiceOrItem ( value ) ;
} ) ;
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
2017-11-15 07:51:53 +01:00
/ * *
* Select value of select box via the value of an existing choice
* @ param { Array / String } value An array of strings of a single string
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : 'setChoiceByValue' ,
value : function setChoiceByValue ( value ) {
var _this10 = this ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
if ( ! this . initialised || this . isTextElement ) {
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
// If only one value has been passed, convert to array
var choiceValue = ( 0 , _utils . isType ) ( 'Array' , value ) ? value : [ value ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Loop through each value and
choiceValue . forEach ( function ( val ) {
return _this10 . _findAndSelectChoiceByValue ( val ) ;
} ) ;
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
2017-11-15 07:51:53 +01:00
/ * *
* Direct populate choices
* @ param { Array } choices - Choices to insert
* @ param { String } value - Name of 'value' property
* @ param { String } label - Name of 'label' property
* @ param { Boolean } replaceChoices Whether existing choices should be removed
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'setChoices' ,
value : function setChoices ( ) {
var choices = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ;
var value = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : '' ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _this11 = this ;
2017-11-07 12:59:49 +01:00
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-02-02 12:08:03 +01:00
if ( ! this . isSelectElement || ! choices . length || ! value ) {
2017-11-15 07:51:53 +01:00
return this ;
}
// Clear choices if needed
if ( replaceChoices ) {
this . _clearChoices ( ) ;
}
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
this . containerOuter . removeLoadingState ( ) ;
var addGroupsAndChoices = function addGroupsAndChoices ( groupOrChoice ) {
if ( groupOrChoice . choices ) {
_this11 . _addGroup ( groupOrChoice , groupOrChoice . id || null , value , label ) ;
} else {
_this11 . _addChoice ( groupOrChoice [ value ] , groupOrChoice [ label ] , groupOrChoice . selected , groupOrChoice . disabled , undefined , groupOrChoice . customProperties , groupOrChoice . placeholder ) ;
}
} ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
choices . forEach ( addGroupsAndChoices ) ;
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
2017-11-15 07:51:53 +01:00
/ * *
* Clear items , choices and groups
* @ note Hard delete
* @ return { Object } Class instance
* @ public
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'clearStore' ,
value : function clearStore ( ) {
this . store . dispatch ( ( 0 , _misc . clearAll ) ( ) ) ;
return this ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
/ * *
* Set value of input to blank
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'clearInput' ,
value : function clearInput ( ) {
var shouldSetInputWidth = ! this . isSelectOneElement ;
this . input . clear ( shouldSetInputWidth ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! this . isTextElement && this . config . searchEnabled ) {
this . isSearching = false ;
this . store . dispatch ( ( 0 , _choices . activateChoices ) ( true ) ) ;
}
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
2017-11-15 07:51:53 +01:00
/ * *
* Populate options via ajax callback
* @ param { Function } fn Function that actually makes an AJAX request
* @ return { Object } Class instance
* @ public
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'ajax' ,
value : function ajax ( fn ) {
var _this12 = this ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! this . initialised || ! this . isSelectElement || ! fn ) {
return this ;
}
requestAnimationFrame ( function ( ) {
return _this12 . _handleLoadingState ( true ) ;
} ) ;
fn ( this . _ajaxCallback ( ) ) ;
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
}
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
2017-11-15 07:51:53 +01:00
/ * *
* Call change callback
* @ param { String } value - last added / deleted / selected value
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_triggerChange' ,
value : function _triggerChange ( value ) {
2018-04-25 10:20:59 +02:00
if ( value === undefined || value === null ) {
2017-11-15 07:51:53 +01:00
return ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . passedElement . triggerEvent ( _constants . EVENTS . change , {
value : value
} ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Select placeholder choice
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_selectPlaceholderChoice' ,
value : function _selectPlaceholderChoice ( ) {
2018-04-25 10:20:59 +02:00
var placeholderChoice = this . store . placeholderChoice ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( placeholderChoice ) {
this . _addItem ( placeholderChoice . value , placeholderChoice . label , placeholderChoice . id , placeholderChoice . groupId , null , placeholderChoice . placeholder ) ;
this . _triggerChange ( placeholderChoice . value ) ;
}
}
/ * *
* Process enter / click of an item button
* @ param { Array } activeItems The currently active items
* @ param { Element } element Button being interacted with
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_handleButtonAction' ,
value : function _handleButtonAction ( activeItems , element ) {
if ( ! activeItems || ! element || ! this . config . removeItems || ! this . config . removeItemButton ) {
return ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var itemId = element . parentNode . getAttribute ( 'data-id' ) ;
var itemToRemove = activeItems . find ( function ( item ) {
return item . id === parseInt ( itemId , 10 ) ;
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Remove item associated with button
this . _removeItem ( itemToRemove ) ;
this . _triggerChange ( itemToRemove . value ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . isSelectOneElement ) {
this . _selectPlaceholderChoice ( ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Process click of an item
* @ param { Array } activeItems The currently active items
* @ param { Element } element Item being interacted with
* @ param { Boolean } hasShiftKey Whether the user has the shift key active
* @ return
* @ private
* /
} , {
key : '_handleItemAction' ,
value : function _handleItemAction ( activeItems , element ) {
var _this13 = this ;
var hasShiftKey = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : false ;
if ( ! activeItems || ! element || ! this . config . removeItems || this . isSelectOneElement ) {
return ;
}
var passedId = element . getAttribute ( 'data-id' ) ;
// We only want to select one item with a click
// so we deselect any items that aren't the target
// unless shift is being pressed
activeItems . forEach ( function ( item ) {
if ( item . id === parseInt ( passedId , 10 ) && ! item . highlighted ) {
_this13 . highlightItem ( item ) ;
} else if ( ! hasShiftKey && item . highlighted ) {
_this13 . unhighlightItem ( item ) ;
}
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Focus input as without focus, a user cannot do anything with a
// highlighted item
this . input . focus ( ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Process click of a choice
* @ param { Array } activeItems The currently active items
* @ param { Element } element Choice being interacted with
* @ return
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_handleChoiceAction' ,
value : function _handleChoiceAction ( activeItems , element ) {
if ( ! activeItems || ! element ) {
return ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If we are clicking on an option
var id = element . getAttribute ( 'data-id' ) ;
var choice = this . store . getChoiceById ( id ) ;
var passedKeyCode = activeItems [ 0 ] && activeItems [ 0 ] . keyCode ? activeItems [ 0 ] . keyCode : null ;
var hasActiveDropdown = this . dropdown . isActive ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Update choice keyCode
choice . keyCode = passedKeyCode ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
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 ) {
this . _addItem ( choice . value , choice . label , choice . id , choice . groupId , choice . customProperties , choice . placeholder , choice . keyCode ) ;
this . _triggerChange ( choice . value ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . clearInput ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// We wont to close the dropdown if we are dealing with a single select box
if ( hasActiveDropdown && this . isSelectOneElement ) {
this . hideDropdown ( ) ;
this . containerOuter . focus ( ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Process back space event
* @ param { Array } activeItems items
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_handleBackspace' ,
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 ;
} ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// If editing the last item is allowed and there are not other selected items,
// we can edit the item value. Otherwise if we can remove items, remove all selected items
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 ( ) ;
this . _removeItem ( lastItem ) ;
this . _triggerChange ( lastItem . value ) ;
} else {
if ( ! hasHighlightedItems ) {
// Highlight last item if none already highlighted
this . highlightItem ( lastItem , false ) ;
}
this . removeHighlightedItems ( true ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Apply or remove a loading state to the component .
* @ param { Boolean } isLoading default value set to 'true' .
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_handleLoadingState' ,
value : function _handleLoadingState ( ) {
var isLoading = 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
var placeholderItem = this . itemList . getChild ( '.' + this . config . classNames . placeholder ) ;
if ( isLoading ) {
this . containerOuter . addLoadingState ( ) ;
if ( this . isSelectOneElement ) {
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 {
this . containerOuter . removeLoadingState ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . isSelectOneElement ) {
placeholderItem . innerHTML = this . placeholder || '' ;
} else {
2018-04-25 10:20:59 +02:00
this . input . placeholder = this . 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
/ * *
* Validates whether an item can be added by a user
* @ param { Array } activeItems The currently active items
* @ param { String } value Value of item to add
* @ return { Object } Response : Whether user can add item
* Notice : Notice show in dropdown
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_canAddItem' ,
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
2017-11-15 07:51:53 +01:00
if ( this . isSelectMultipleElement || this . isTextElement ) {
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-02-02 12:08:03 +01:00
if ( this . config . regexFilter && this . isTextElement && this . config . addItems && canAddItem ) {
2017-11-15 07:51:53 +01:00
// 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-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If no duplicates are allowed, and the value already exists
// in the array
var isUnique = ! activeItems . some ( function ( item ) {
if ( ( 0 , _utils . isType ) ( 'String' , value ) ) {
return item . value === value . trim ( ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return item . value === value ;
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! isUnique && ! this . config . duplicateItems && ! this . isSelectOneElement && canAddItem ) {
canAddItem = false ;
notice = ( 0 , _utils . isType ) ( 'Function' , this . config . uniqueItemText ) ? this . config . uniqueItemText ( value ) : this . config . uniqueItemText ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return {
response : canAddItem ,
notice : notice
} ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Retrieve the callback used to populate component ' s choices in an async way .
* @ returns { Function } The callback as a function .
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_ajaxCallback' ,
value : function _ajaxCallback ( ) {
var _this14 = 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
_this14 . _handleLoadingState ( false ) ;
// Add each result as a choice
parsedResults . forEach ( function ( result ) {
if ( result . choices ) {
var groupId = result . id || null ;
_this14 . _addGroup ( result , groupId , value , label ) ;
} else {
_this14 . _addChoice ( result [ value ] , result [ label ] , result . selected , result . disabled , undefined , result . customProperties , result . placeholder ) ;
}
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( _this14 . isSelectOneElement ) {
_this14 . _selectPlaceholderChoice ( ) ;
}
} else {
// No results, remove loading state
_this14 . _handleLoadingState ( false ) ;
}
} ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Filter choices based on search value
* @ param { String } value Value to filter by
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_searchChoices' ,
value : function _searchChoices ( value ) {
var newValue = ( 0 , _utils . isType ) ( 'String' , value ) ? value . trim ( ) : value ;
var currentValue = ( 0 , _utils . isType ) ( 'String' , this . currentValue ) ? this . currentValue . trim ( ) : this . currentValue ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( newValue . length < 1 && newValue === currentValue + ' ' ) {
return 0 ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If new value matches the desired length and is not the same as the current value with a space
2018-04-25 10:20:59 +02:00
var haystack = this . store . searchableChoices ;
2017-11-15 07:51:53 +01:00
var needle = newValue ;
var keys = ( 0 , _utils . isType ) ( 'Array' , this . config . searchFields ) ? this . config . searchFields : [ this . config . searchFields ] ;
var options = Object . assign ( this . config . fuseOptions , { keys : keys } ) ;
var fuse = new _fuse2 . default ( haystack , options ) ;
var results = fuse . search ( needle ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . currentValue = newValue ;
this . highlightPosition = 0 ;
this . isSearching = true ;
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-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Determine the action when a user is searching
* @ param { String } value Value entered by user
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_handleSearch' ,
value : function _handleSearch ( value ) {
if ( ! value || ! this . input . isFocussed ) {
return ;
}
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
var choices = this . store . choices ;
2017-11-15 07:51:53 +01:00
var hasUnactiveChoices = choices . some ( function ( option ) {
return ! option . active ;
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Check that we have a value to search and the input was an alphanumeric character
if ( value && value . length >= this . config . searchFloor ) {
var resultCount = this . config . searchChoices ? this . _searchChoices ( value ) : 0 ;
// Trigger search event
this . passedElement . triggerEvent ( _constants . EVENTS . search , {
value : value ,
resultCount : resultCount
} ) ;
} else if ( hasUnactiveChoices ) {
// Otherwise reset choices to active
this . isSearching = false ;
this . store . dispatch ( ( 0 , _choices . activateChoices ) ( true ) ) ;
2017-11-07 12:59:49 +01:00
}
}
2017-11-15 07:51:53 +01:00
/ * *
* Trigger event listeners
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_addEventListeners' ,
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 ) ;
if ( this . isSelectOneElement ) {
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
2017-11-15 07:51:53 +01:00
this . input . addEventListeners ( ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Remove event listeners
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_removeEventListeners' ,
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
2017-11-15 07:51:53 +01:00
if ( this . isSelectOneElement ) {
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 ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
this . input . removeEventListeners ( ) ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Key down event
* @ param { Object } e Event
* @ return
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_onKeyDown' ,
value : function _onKeyDown ( e ) {
var _this15 = this ,
_keyDownActions ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( e . target !== this . input . element && ! this . containerOuter . element . contains ( e . target ) ) {
return ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var target = e . target ;
2018-04-25 10:20:59 +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 ;
var keyString = String . fromCharCode ( e . keyCode ) ;
var backKey = _constants . KEY _CODES . BACK _KEY ;
var deleteKey = _constants . KEY _CODES . DELETE _KEY ;
var enterKey = _constants . KEY _CODES . ENTER _KEY ;
var aKey = _constants . KEY _CODES . A _KEY ;
var escapeKey = _constants . KEY _CODES . ESC _KEY ;
var upKey = _constants . KEY _CODES . UP _KEY ;
var downKey = _constants . KEY _CODES . DOWN _KEY ;
var pageUpKey = _constants . KEY _CODES . PAGE _UP _KEY ;
var pageDownKey = _constants . KEY _CODES . PAGE _DOWN _KEY ;
var ctrlDownKey = e . ctrlKey || e . metaKey ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// If a user is typing and the dropdown is not active
if ( ! this . isTextElement && /[a-zA-Z0-9-_ ]/ . test ( keyString ) ) {
this . showDropdown ( 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
this . canSearch = this . config . searchEnabled ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var onAKey = function onAKey ( ) {
// If CTRL + A or CMD + A have been pressed and there are items to select
if ( ctrlDownKey && hasItems ) {
_this15 . canSearch = false ;
2018-04-25 10:20:59 +02:00
if ( _this15 . config . removeItems && ! _this15 . input . value && _this15 . input . element === document . activeElement ) {
2017-11-15 07:51:53 +01:00
// Highlight items
_this15 . highlightAll ( ) ;
}
}
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var onEnterKey = function onEnterKey ( ) {
// If enter key is pressed and the input has a value
if ( _this15 . isTextElement && target . value ) {
2018-04-25 10:20:59 +02:00
var value = _this15 . input . value ;
2017-11-15 07:51:53 +01:00
var canAddItem = _this15 . _canAddItem ( activeItems , value ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// All is good, add
if ( canAddItem . response ) {
_this15 . hideDropdown ( ) ;
_this15 . _addItem ( value ) ;
_this15 . _triggerChange ( value ) ;
_this15 . clearInput ( ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( target . hasAttribute ( 'data-button' ) ) {
_this15 . _handleButtonAction ( activeItems , target ) ;
e . preventDefault ( ) ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( hasActiveDropdown ) {
e . preventDefault ( ) ;
var highlighted = _this15 . dropdown . getChild ( '.' + _this15 . config . classNames . highlightedState ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If we have a highlighted choice
if ( highlighted ) {
// add enter keyCode value
if ( activeItems [ 0 ] ) {
activeItems [ 0 ] . keyCode = enterKey ;
}
_this15 . _handleChoiceAction ( activeItems , highlighted ) ;
}
} else if ( _this15 . isSelectOneElement ) {
// Open single select dropdown if it's not active
_this15 . showDropdown ( true ) ;
e . preventDefault ( ) ;
}
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var onEscapeKey = function onEscapeKey ( ) {
if ( hasActiveDropdown ) {
_this15 . hideDropdown ( ) ;
_this15 . containerOuter . focus ( ) ;
}
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var onDirectionKey = function onDirectionKey ( ) {
// If up or down key is pressed, traverse through options
if ( hasActiveDropdown || _this15 . isSelectOneElement ) {
// Show dropdown if focus
_this15 . showDropdown ( true ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
_this15 . canSearch = false ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var directionInt = e . keyCode === downKey || e . keyCode === pageDownKey ? 1 : - 1 ;
var skipKey = e . metaKey || e . keyCode === pageDownKey || e . keyCode === pageUpKey ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var nextEl = void 0 ;
if ( skipKey ) {
if ( directionInt > 0 ) {
nextEl = Array . from ( _this15 . dropdown . element . querySelectorAll ( '[data-choice-selectable]' ) ) . pop ( ) ;
} else {
nextEl = _this15 . dropdown . element . querySelector ( '[data-choice-selectable]' ) ;
}
} else {
var currentEl = _this15 . dropdown . element . querySelector ( '.' + _this15 . config . classNames . highlightedState ) ;
if ( currentEl ) {
nextEl = ( 0 , _utils . getAdjacentEl ) ( currentEl , '[data-choice-selectable]' , directionInt ) ;
} else {
nextEl = _this15 . dropdown . element . querySelector ( '[data-choice-selectable]' ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( nextEl ) {
// We prevent default to stop the cursor moving
// when pressing the arrow
2018-02-02 12:08:03 +01:00
if ( ! ( 0 , _utils . isScrolledIntoView ) ( nextEl , _this15 . choiceList . element , directionInt ) ) {
2017-11-15 07:51:53 +01:00
_this15 . _scrollToChoice ( nextEl , directionInt ) ;
}
_this15 . _highlightChoice ( nextEl ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Prevent default to maintain cursor position whilst
// traversing dropdown options
e . preventDefault ( ) ;
}
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var onDeleteKey = function onDeleteKey ( ) {
// If backspace or delete key is pressed and the input has no value
if ( hasFocusedInput && ! e . target . value && ! _this15 . isSelectOneElement ) {
_this15 . _handleBackspace ( activeItems ) ;
e . preventDefault ( ) ;
}
} ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// Map keys to key actions
var keyDownActions = ( _keyDownActions = { } , _defineProperty ( _keyDownActions , aKey , onAKey ) , _defineProperty ( _keyDownActions , enterKey , onEnterKey ) , _defineProperty ( _keyDownActions , escapeKey , onEscapeKey ) , _defineProperty ( _keyDownActions , upKey , onDirectionKey ) , _defineProperty ( _keyDownActions , pageUpKey , onDirectionKey ) , _defineProperty ( _keyDownActions , downKey , onDirectionKey ) , _defineProperty ( _keyDownActions , pageDownKey , onDirectionKey ) , _defineProperty ( _keyDownActions , deleteKey , onDeleteKey ) , _defineProperty ( _keyDownActions , backKey , onDeleteKey ) , _keyDownActions ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// If keycode has a function, run it
if ( keyDownActions [ e . keyCode ] ) {
keyDownActions [ e . keyCode ] ( ) ;
}
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Key up event
* @ param { Object } e Event
* @ return
* @ private
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_onKeyUp' ,
value : function _onKeyUp ( e ) {
if ( e . target !== this . input . element ) {
return ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
var value = this . input . value ;
var activeItems = this . store . activeItems ;
2017-11-15 07:51:53 +01:00
var canAddItem = this . _canAddItem ( activeItems , value ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// We are typing into a text input and have a value, we want to show a dropdown
// notice. Otherwise hide the dropdown
if ( this . isTextElement ) {
if ( value ) {
if ( canAddItem . notice ) {
var dropdownItem = this . _getTemplate ( 'notice' , canAddItem . notice ) ;
this . dropdown . element . innerHTML = dropdownItem . outerHTML ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( canAddItem . response === true ) {
this . showDropdown ( ) ;
} else if ( ! canAddItem . notice ) {
this . hideDropdown ( ) ;
}
} else {
this . hideDropdown ( ) ;
}
} else {
var backKey = _constants . KEY _CODES . BACK _KEY ;
var deleteKey = _constants . KEY _CODES . DELETE _KEY ;
// If user has removed value...
if ( ( e . keyCode === backKey || e . keyCode === deleteKey ) && ! e . target . value ) {
// ...and it is a multiple select input, activate choices (if searching)
if ( ! this . isTextElement && this . isSearching ) {
this . isSearching = false ;
this . store . dispatch ( ( 0 , _choices . activateChoices ) ( true ) ) ;
}
} else if ( this . canSearch && canAddItem . response ) {
2018-04-25 10:20:59 +02:00
this . _handleSearch ( this . input . value ) ;
2017-11-15 07:51:53 +01:00
}
}
// Re-establish canSearch value from changes in _onKeyDown
this . canSearch = this . config . searchEnabled ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Touch move event
* @ return
2017-11-07 12:59:49 +01:00
* @ private
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_onTouchMove' ,
value : function _onTouchMove ( ) {
if ( this . wasTap === true ) {
this . wasTap = false ;
2017-11-07 12:59:49 +01:00
}
}
/ * *
2017-11-15 07:51:53 +01:00
* Touch end event
* @ param { Object } e Event
* @ return
2017-11-07 12:59:49 +01:00
* @ private
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_onTouchEnd' ,
value : function _onTouchEnd ( e ) {
var target = e . target || e . touches [ 0 ] . target ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// If a user tapped within our container...
if ( this . wasTap === true && this . containerOuter . element . contains ( target ) ) {
// ...and we aren't dealing with a single select box, show dropdown/focus input
if ( ( target === this . containerOuter . element || target === this . containerInner . element ) && ! this . isSelectOneElement ) {
if ( this . isTextElement ) {
// If text element, we only want to focus the input
this . input . focus ( ) ;
} else {
// If a select box, we want to show the dropdown
this . showDropdown ( true ) ;
}
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
// Prevents focus event firing
e . stopPropagation ( ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
this . wasTap = true ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Mouse down event
* @ param { Object } e Event
2017-11-07 12:59:49 +01:00
* @ return
* @ private
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_onMouseDown' ,
value : function _onMouseDown ( e ) {
var target = e . target ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If we have our mouse down on the scrollbar and are on IE11...
if ( target === this . choiceList && this . isIe11 ) {
this . isScrollingOnIe = 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
if ( this . containerOuter . element . contains ( target ) && target !== this . input . element ) {
2018-04-25 10:20:59 +02:00
var activeItems = this . store . activeItems ;
2017-11-15 07:51:53 +01:00
var hasShiftKey = e . shiftKey ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var buttonTarget = ( 0 , _utils . findAncestorByAttrName ) ( target , 'data-button' ) ;
var itemTarget = ( 0 , _utils . findAncestorByAttrName ) ( target , 'data-item' ) ;
var choiceTarget = ( 0 , _utils . findAncestorByAttrName ) ( target , 'data-choice' ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( buttonTarget ) {
this . _handleButtonAction ( activeItems , buttonTarget ) ;
} else if ( itemTarget ) {
this . _handleItemAction ( activeItems , itemTarget , hasShiftKey ) ;
} else if ( choiceTarget ) {
this . _handleChoiceAction ( activeItems , choiceTarget ) ;
}
e . preventDefault ( ) ;
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
/ * *
* Mouse over ( hover ) event
* @ param { Object } e Event
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_onMouseOver' ,
value : function _onMouseOver ( e ) {
// If the dropdown is either the target or one of its children is the target
var targetWithinDropdown = e . target === this . dropdown || this . dropdown . element . contains ( e . target ) ;
var shouldHighlightChoice = targetWithinDropdown && e . target . hasAttribute ( 'data-choice' ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( shouldHighlightChoice ) {
this . _highlightChoice ( e . target ) ;
}
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Click event
* @ param { Object } e Event
2017-11-07 12:59:49 +01:00
* @ return
* @ private
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_onClick' ,
value : function _onClick ( e ) {
var target = e . target ;
var hasActiveDropdown = this . dropdown . isActive ;
2018-04-25 10:20:59 +02:00
var activeItems = this . store . activeItems ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If target is something that concerns us
if ( this . containerOuter . element . contains ( target ) ) {
if ( ! hasActiveDropdown ) {
if ( this . isTextElement ) {
if ( document . activeElement !== this . input . element ) {
this . input . focus ( ) ;
}
} else if ( this . canSearch ) {
this . showDropdown ( true ) ;
} else {
this . showDropdown ( ) ;
// code smell
this . containerOuter . focus ( ) ;
}
} else if ( this . isSelectOneElement && target !== this . input . element && ! this . dropdown . element . contains ( target ) ) {
this . hideDropdown ( true ) ;
}
} else {
var hasHighlightedItems = activeItems . some ( function ( item ) {
return item . highlighted ;
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// De-select any highlighted items
if ( hasHighlightedItems ) {
this . unhighlightAll ( ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Remove focus state
this . containerOuter . removeFocusState ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Close all other dropdowns
this . hideDropdown ( ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Focus event
* @ param { Object } e Event
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_onFocus' ,
value : function _onFocus ( e ) {
var _this16 = this ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var target = e . target ;
if ( ! this . containerOuter . element . contains ( target ) ) {
return ;
}
var focusActions = {
text : function text ( ) {
if ( target === _this16 . input . element ) {
_this16 . containerOuter . addFocusState ( ) ;
}
} ,
'select-one' : function selectOne ( ) {
_this16 . containerOuter . addFocusState ( ) ;
if ( target === _this16 . input . element ) {
// Show dropdown if it isn't already showing
_this16 . showDropdown ( ) ;
}
} ,
'select-multiple' : function selectMultiple ( ) {
if ( target === _this16 . input . element ) {
// If element is a select box, the focused element is the container and the dropdown
// isn't already open, focus and show dropdown
_this16 . containerOuter . addFocusState ( ) ;
_this16 . showDropdown ( true ) ;
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
focusActions [ this . passedElement . element . type ] ( ) ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Blur event
* @ param { Object } e Event
* @ return
* @ private
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : '_onBlur' ,
value : function _onBlur ( e ) {
var _this17 = this ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var target = e . target ;
// If target is something that concerns us
if ( this . containerOuter . element . contains ( target ) && ! this . isScrollingOnIe ) {
2018-04-25 10:20:59 +02:00
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 ( ) {
if ( target === _this17 . input . element ) {
// Remove the focus state
_this17 . containerOuter . removeFocusState ( ) ;
// De-select any highlighted items
if ( hasHighlightedItems ) {
_this17 . unhighlightAll ( ) ;
}
_this17 . hideDropdown ( ) ;
}
} ,
'select-one' : function selectOne ( ) {
_this17 . containerOuter . removeFocusState ( ) ;
2018-02-02 12:08:03 +01:00
if ( target === _this17 . input . element || target === _this17 . containerOuter . element && ! _this17 . canSearch ) {
2017-11-15 07:51:53 +01:00
_this17 . hideDropdown ( ) ;
}
} ,
'select-multiple' : function selectMultiple ( ) {
if ( target === _this17 . input . element ) {
// Remove the focus state
_this17 . containerOuter . removeFocusState ( ) ;
_this17 . hideDropdown ( ) ;
// De-select any highlighted items
if ( hasHighlightedItems ) {
_this17 . unhighlightAll ( ) ;
}
}
2017-11-13 20:13:37 +01:00
}
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.
this . isScrollingOnIe = false ;
this . input . element . focus ( ) ;
2017-11-13 20:13:37 +01:00
}
}
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Scroll to an option element
* @ param { HTMLElement } choice Option to scroll to
* @ param { Number } direction Whether option is above or below
* @ return
* @ private
2017-11-13 20:13:37 +01:00
* /
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : '_scrollToChoice' ,
value : function _scrollToChoice ( choice , direction ) {
var _this18 = this ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( ! choice ) {
return ;
2017-11-07 12:59:49 +01:00
}
2018-02-02 12:08:03 +01:00
var dropdownHeight = this . choiceList . element . offsetHeight ;
2017-11-15 07:51:53 +01:00
var choiceHeight = choice . offsetHeight ;
// Distance from bottom of element to top of parent
var choicePos = choice . offsetTop + choiceHeight ;
// Scroll position of dropdown
2018-02-02 12:08:03 +01:00
var containerScrollPos = this . choiceList . element . scrollTop + dropdownHeight ;
2017-11-15 07:51:53 +01:00
// Difference between the choice and scroll position
2018-02-02 12:08:03 +01:00
var endPoint = direction > 0 ? this . choiceList . element . scrollTop + choicePos - containerScrollPos : choice . offsetTop ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var animateScroll = function animateScroll ( ) {
var strength = _constants . SCROLLING _SPEED ;
2018-02-02 12:08:03 +01:00
var choiceListScrollTop = _this18 . choiceList . element . scrollTop ;
2017-11-15 07:51:53 +01:00
var continueAnimation = false ;
var easing = void 0 ;
var distance = void 0 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( direction > 0 ) {
easing = ( endPoint - choiceListScrollTop ) / strength ;
distance = easing > 1 ? easing : 1 ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
_this18 . choiceList . scrollTo ( choiceListScrollTop + distance ) ;
if ( choiceListScrollTop < endPoint ) {
continueAnimation = true ;
}
} else {
easing = ( choiceListScrollTop - endPoint ) / strength ;
distance = easing > 1 ? easing : 1 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
_this18 . choiceList . scrollTo ( choiceListScrollTop - distance ) ;
if ( choiceListScrollTop > endPoint ) {
continueAnimation = true ;
}
}
if ( continueAnimation ) {
requestAnimationFrame ( function ( time ) {
animateScroll ( time , endPoint , direction ) ;
} ) ;
}
} ;
requestAnimationFrame ( function ( time ) {
animateScroll ( time , endPoint , direction ) ;
} ) ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Highlight choice
* @ param { HTMLElement } [ el ] Element to highlight
* @ return
* @ private
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_highlightChoice' ,
value : function _highlightChoice ( ) {
var _this19 = this ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var el = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : null ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// Highlight first element in dropdown
var choices = Array . from ( this . dropdown . element . querySelectorAll ( '[data-choice-selectable]' ) ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
if ( ! choices . length ) {
return ;
}
2017-11-13 20:13:37 +01:00
2018-02-02 12:08:03 +01:00
var passedEl = el ;
var highlightedChoices = Array . from ( this . dropdown . element . querySelectorAll ( '.' + this . config . classNames . highlightedState ) ) ;
var hasActiveDropdown = this . dropdown . isActive ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
// Remove any highlighted choices
highlightedChoices . forEach ( function ( choice ) {
choice . classList . remove ( _this19 . config . classNames . highlightedState ) ;
choice . setAttribute ( 'aria-selected' , 'false' ) ;
} ) ;
if ( passedEl ) {
this . highlightPosition = choices . indexOf ( passedEl ) ;
} else {
// Highlight choice based on last known highlight location
if ( choices . length > this . highlightPosition ) {
// If we have an option to highlight
passedEl = choices [ this . highlightPosition ] ;
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
// Highlight given option, and set accessiblity attributes
passedEl . classList . add ( this . config . classNames . highlightedState ) ;
passedEl . setAttribute ( 'aria-selected' , 'true' ) ;
2017-11-15 07:51:53 +01:00
2018-02-02 12:08:03 +01:00
if ( hasActiveDropdown ) {
// 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
}
/ * *
2017-11-15 07:51:53 +01:00
* Add item to store with correct value
* @ param { String } value Value to add to store
* @ param { String } [ label ] Label to add to store
* @ param { Number } [ choiceId = - 1 ] ID of the associated choice that was selected
* @ param { Number } [ groupId = - 1 ] ID of group choice is within . Negative number indicates no group
* @ param { Object } [ customProperties ] Object containing user defined properties
2017-11-13 20:13:37 +01:00
* @ return { Object } Class instance
* @ public
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_addItem' ,
value : function _addItem ( value ) {
var label = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : null ;
var choiceId = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : - 1 ;
var groupId = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : - 1 ;
var customProperties = arguments . length > 4 && arguments [ 4 ] !== undefined ? arguments [ 4 ] : null ;
var placeholder = arguments . length > 5 && arguments [ 5 ] !== undefined ? arguments [ 5 ] : false ;
var keyCode = arguments . length > 6 && arguments [ 6 ] !== undefined ? arguments [ 6 ] : null ;
2017-11-07 12:59:49 +01:00
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-04-25 10:20:59 +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 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Get group if group ID passed
var group = groupId >= 0 ? this . store . getGroupById ( groupId ) : null ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Generate unique id
var id = items ? items . length + 1 : 1 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If a prepended value has been passed, prepend it
if ( this . config . prependValue ) {
passedValue = this . config . prependValue + passedValue . toString ( ) ;
}
// If an appended value has been passed, append it
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
2017-11-15 07:51:53 +01:00
this . store . dispatch ( ( 0 , _items . addItem ) ( passedValue , passedLabel , id , passedOptionId , groupId , customProperties , placeholder , passedKeyCode ) ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( this . isSelectOneElement ) {
this . removeActiveItems ( id ) ;
}
// Trigger change event
if ( group && group . value ) {
this . passedElement . triggerEvent ( _constants . EVENTS . addItem , {
id : id ,
value : passedValue ,
label : passedLabel ,
2018-02-02 12:08:03 +01:00
customProperties : passedCustomProperties ,
2017-11-15 07:51:53 +01:00
groupValue : group . value ,
keyCode : passedKeyCode
} ) ;
} else {
this . passedElement . triggerEvent ( _constants . EVENTS . addItem , {
id : id ,
value : passedValue ,
label : passedLabel ,
2018-02-02 12:08:03 +01:00
customProperties : passedCustomProperties ,
2017-11-15 07:51:53 +01:00
keyCode : passedKeyCode
} ) ;
}
2017-11-13 20:13:37 +01:00
return this ;
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Remove item from store
* @ param { Object } item Item to remove
2017-11-13 20:13:37 +01:00
* @ return { Object } Class instance
* @ public
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_removeItem' ,
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 ;
2017-11-15 07:51:53 +01:00
var group = groupId >= 0 ? this . store . getGroupById ( groupId ) : null ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
this . store . dispatch ( ( 0 , _items . removeItem ) ( id , choiceId ) ) ;
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
}
/ * *
2017-11-15 07:51:53 +01:00
* Add choice to dropdown
* @ param { String } value Value of choice
* @ param { String } [ label ] Label of choice
* @ param { Boolean } [ isSelected = false ] Whether choice is selected
* @ param { Boolean } [ isDisabled = false ] Whether choice is disabled
* @ param { Number } [ groupId = - 1 ] ID of group choice is within . Negative number indicates no group
* @ param { Object } [ customProperties ] Object containing user defined properties
* @ return
* @ private
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_addChoice' ,
value : function _addChoice ( value ) {
var label = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : null ;
var isSelected = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : false ;
var isDisabled = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : false ;
var groupId = arguments . length > 4 && arguments [ 4 ] !== undefined ? arguments [ 4 ] : - 1 ;
var customProperties = arguments . length > 5 && arguments [ 5 ] !== undefined ? arguments [ 5 ] : null ;
var placeholder = arguments . length > 6 && arguments [ 6 ] !== undefined ? arguments [ 6 ] : false ;
var keyCode = arguments . length > 7 && arguments [ 7 ] !== undefined ? arguments [ 7 ] : null ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( typeof value === 'undefined' || value === null ) {
return ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Generate unique id
2018-04-25 10:20:59 +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 ;
var choiceElementId = this . baseId + '-' + this . idNames . itemChoice + '-' + choiceId ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . store . dispatch ( ( 0 , _choices . addChoice ) ( value , choiceLabel , choiceId , groupId , isDisabled , choiceElementId , customProperties , placeholder , keyCode ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( isSelected ) {
this . _addItem ( value , choiceLabel , choiceId , undefined , customProperties , placeholder , keyCode ) ;
}
2017-11-07 12:59:49 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Clear all choices added to the store .
* @ return
* @ private
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_clearChoices' ,
value : function _clearChoices ( ) {
this . store . dispatch ( ( 0 , _choices . clearChoices ) ( ) ) ;
2017-11-13 20:13:37 +01:00
}
/ * *
2017-11-15 07:51:53 +01:00
* Add group to dropdown
* @ param { Object } group Group to add
* @ param { Number } id Group ID
* @ param { String } [ valueKey ] name of the value property on the object
* @ param { String } [ labelKey ] name of the label property on the object
* @ return
* @ private
2017-11-13 20:13:37 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_addGroup' ,
value : function _addGroup ( group , id ) {
var _this20 = this ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var valueKey = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : 'value' ;
var labelKey = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : 'label' ;
2017-11-07 12:59:49 +01:00
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 ) {
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 ;
_this20 . _addChoice ( choice [ valueKey ] , ( 0 , _utils . isType ) ( 'Object' , choice ) ? choice [ labelKey ] : choice . innerHTML , choice . selected , isOptDisabled , groupId , choice . customProperties , choice . placeholder ) ;
} ;
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 {
2017-11-15 07:51:53 +01:00
this . store . dispatch ( ( 0 , _groups . addGroup ) ( group . label , group . id , false , group . disabled ) ) ;
2017-11-07 12:59:49 +01:00
}
}
/ * *
2017-11-15 07:51:53 +01:00
* Get template from name
* @ param { String } template Name of template to get
* @ param { ... } args Data to pass to template
* @ return { HTMLElement } Template
* @ private
2017-11-07 12:59:49 +01:00
* /
} , {
2017-11-15 07:51:53 +01:00
key : '_getTemplate' ,
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 ;
}
var templates = this . config . templates ;
var globalClasses = this . config . classNames ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var _len = arguments . length , args = Array ( _len > 1 ? _len - 1 : 0 ) , _key = 1 ; _key < _len ; _key ++ ) {
args [ _key - 1 ] = arguments [ _key ] ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return ( _templates$template = templates [ template ] ) . call . apply ( _templates$template , [ this , globalClasses ] . concat ( args ) ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/ * *
2017-11-15 07:51:53 +01:00
* Create HTML element based on type and arguments
* @ return
* @ private
2017-11-13 20:13:37 +01:00
* /
2017-11-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : '_createTemplates' ,
value : function _createTemplates ( ) {
// User's custom templates
var callbackTemplate = this . config . callbackOnCreateTemplates ;
var userTemplates = { } ;
if ( callbackTemplate && ( 0 , _utils . isType ) ( 'Function' , callbackTemplate ) ) {
userTemplates = callbackTemplate . 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-07 12:59:49 +01:00
2017-11-13 20:13:37 +01:00
/ * *
2018-04-25 10:20:59 +02:00
* Create DOM elements using templates
2017-11-13 20:13:37 +01:00
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
2018-04-25 10:20:59 +02:00
key : '_createElements' ,
value : function _createElements ( ) {
2017-11-15 07:51:53 +01:00
var direction = this . passedElement . element . getAttribute ( 'dir' ) || 'ltr' ;
var containerOuter = this . _getTemplate ( 'containerOuter' , direction , this . isSelectElement , this . isSelectOneElement , this . config . searchEnabled , this . passedElement . element . type ) ;
var containerInner = this . _getTemplate ( 'containerInner' ) ;
var itemList = this . _getTemplate ( 'itemList' , this . isSelectOneElement ) ;
var choiceList = this . _getTemplate ( 'choiceList' , this . isSelectOneElement ) ;
var input = this . _getTemplate ( 'input' ) ;
var dropdown = this . _getTemplate ( 'dropdown' ) ;
this . containerOuter = new _container2 . default ( this , containerOuter , this . config . classNames ) ;
this . containerInner = new _container2 . default ( this , containerInner , this . config . classNames ) ;
this . input = new _input2 . default ( this , input , this . config . classNames ) ;
this . choiceList = new _list2 . default ( this , choiceList , this . config . classNames ) ;
this . itemList = new _list2 . default ( this , itemList , this . config . classNames ) ;
this . dropdown = new _dropdown2 . default ( this , dropdown , this . config . classNames ) ;
2018-04-25 10:20:59 +02:00
}
2017-11-15 07:51:53 +01:00
2018-04-25 10:20:59 +02:00
/ * *
* Create DOM structure around passed select element
* @ return
* @ private
* /
2017-11-15 07:51:53 +01:00
2018-04-25 10:20:59 +02:00
} , {
key : '_createStructure' ,
value : function _createStructure ( ) {
// Hide original element
this . passedElement . conceal ( ) ;
2017-11-15 07:51:53 +01:00
// Wrap input in container preserving DOM ordering
2018-02-02 12:08:03 +01:00
this . containerInner . wrap ( this . passedElement . element ) ;
2017-11-15 07:51:53 +01:00
// 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
2017-11-15 07:51:53 +01:00
if ( this . isSelectOneElement ) {
2018-04-25 10:20:59 +02:00
this . input . placeholder = this . config . searchPlaceholderValue || '' ;
2017-11-15 07:51:53 +01:00
} else if ( this . placeholder ) {
2018-04-25 10:20:59 +02:00
this . input . placeholder = this . placeholder ;
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
if ( ! this . config . addItems ) {
this . disable ( ) ;
}
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
2017-11-15 07:51:53 +01: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
2017-11-15 07:51:53 +01:00
if ( ! this . isSelectOneElement ) {
this . containerInner . element . appendChild ( this . input . element ) ;
} else if ( this . canSearch ) {
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
2017-11-15 07:51:53 +01:00
if ( this . isSelectElement ) {
this . _addPredefinedChoices ( ) ;
} else if ( this . isTextElement ) {
this . _addPredefinedItems ( ) ;
}
}
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : '_addPredefinedChoices' ,
value : function _addPredefinedChoices ( ) {
var _this21 = this ;
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
var passedGroups = this . passedElement . optionGroups ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . highlightPosition = 0 ;
this . isSearching = false ;
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 ;
2017-11-15 07:51:53 +01:00
if ( placeholderChoice && placeholderChoice . parentNode . tagName === 'SELECT' ) {
this . _addChoice ( placeholderChoice . value , placeholderChoice . innerHTML , placeholderChoice . selected , placeholderChoice . disabled , undefined , undefined ,
/* placeholder */ true ) ;
}
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
passedGroups . forEach ( function ( group ) {
_this21 . _addGroup ( group , group . id || null ) ;
} ) ;
} 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 ;
2017-11-15 07:51:53 +01:00
var allChoices = this . presetChoices ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Create array of options from option elements
passedOptions . forEach ( function ( o ) {
allChoices . push ( {
value : o . value ,
label : o . innerHTML ,
selected : o . selected ,
disabled : o . disabled || o . parentNode . disabled ,
placeholder : o . hasAttribute ( 'placeholder' )
} ) ;
} ) ;
// If sorting is enabled or the user is searching, filter choices
if ( this . config . shouldSort ) {
allChoices . sort ( filter ) ;
}
// Determine whether there is a selected choice
var hasSelectedChoice = allChoices . some ( function ( choice ) {
return choice . selected ;
} ) ;
var handleChoice = function handleChoice ( choice , index ) {
if ( _this21 . isSelectElement ) {
// If the choice is actually a group
if ( choice . choices ) {
_this21 . _addGroup ( choice , choice . id || null ) ;
} else {
// If there is a selected choice already or the choice is not
// the first in the array, add each choice normally
// Otherwise pre-select the first choice in the array if it's a single select
var shouldPreselect = _this21 . isSelectOneElement && ! hasSelectedChoice && index === 0 ;
var isSelected = shouldPreselect ? true : choice . selected ;
var isDisabled = shouldPreselect ? false : choice . disabled ;
_this21 . _addChoice ( choice . value , choice . label , isSelected , isDisabled , undefined , choice . customProperties , choice . placeholder ) ;
}
2017-11-13 20:13:37 +01:00
} else {
2017-11-15 07:51:53 +01:00
_this21 . _addChoice ( choice . value , choice . label , choice . selected , choice . disabled , undefined , choice . customProperties , choice . placeholder ) ;
2017-11-13 20:13:37 +01:00
}
} ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
// Add each choice
allChoices . forEach ( function ( choice , index ) {
return handleChoice ( choice , index ) ;
} ) ;
2017-11-13 20:13:37 +01:00
}
}
2017-11-15 07:51:53 +01:00
} , {
key : '_addPredefinedItems' ,
value : function _addPredefinedItems ( ) {
var _this22 = 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 ) ;
if ( itemType === 'Object' ) {
if ( ! item . value ) {
return ;
}
_this22 . _addItem ( item . value , item . label , item . id , undefined , item . customProperties , item . placeholder ) ;
} else if ( itemType === 'String' ) {
_this22 . _addItem ( item ) ;
}
} ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
this . presetItems . forEach ( function ( item ) {
return handlePresetItem ( item ) ;
} ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} , {
key : '_setChoiceOrItem' ,
value : function _setChoiceOrItem ( item ) {
var _this23 = 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 ;
}
// If we are dealing with a select input, we need to create an option first
// that is then selected. For text inputs we can just add items normally.
if ( ! _this23 . isTextElement ) {
_this23 . _addChoice ( item . value , item . label , true , false , - 1 , item . customProperties , item . placeholder ) ;
} else {
_this23 . _addItem ( item . value , item . label , item . id , undefined , item . customProperties , item . placeholder ) ;
}
} ,
string : function string ( ) {
if ( ! _this23 . isTextElement ) {
_this23 . _addChoice ( item , item , true , false , - 1 , null ) ;
} else {
_this23 . _addItem ( item ) ;
}
}
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
handleType [ itemType ] ( ) ;
}
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : '_findAndSelectChoiceByValue' ,
value : function _findAndSelectChoiceByValue ( val ) {
2018-02-02 12:08:03 +01:00
var _this24 = this ;
2018-04-25 10:20:59 +02:00
var choices = this . store . choices ;
2017-11-15 07:51:53 +01:00
// Check 'value' property exists and the choice isn't already selected
var foundChoice = choices . find ( function ( choice ) {
2018-02-02 12:08:03 +01:00
return _this24 . 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 ) {
this . _addItem ( foundChoice . value , foundChoice . label , foundChoice . id , foundChoice . groupId , foundChoice . customProperties , foundChoice . placeholder , foundChoice . keyCode ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
}
/* ===== End of Private functions ====== */
} ] ) ;
return Choices ;
} ( ) ;
Choices . userDefaults = { } ;
2017-11-20 13:59:12 +01:00
// 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 ;
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 8 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
/ * !
2018-02-02 12:08:03 +01:00
* Fuse . js v3 . 2.0 - Lightweight fuzzy - search ( http : //fusejs.io)
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
*
* http : //www.apache.org/licenses/LICENSE-2.0
* /
( function webpackUniversalModuleDefinition ( root , factory ) {
if ( true )
module . exports = factory ( ) ;
else if ( typeof define === 'function' && define . amd )
define ( "Fuse" , [ ] , factory ) ;
else if ( typeof exports === 'object' )
exports [ "Fuse" ] = factory ( ) ;
else
root [ "Fuse" ] = factory ( ) ;
} ) ( 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 ;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ _ _webpack _require _ _ . i = function ( value ) { return value ; } ;
/******/
/******/ // define getter function for harmony exports
/******/ _ _webpack _require _ _ . d = function ( exports , name , getter ) {
/******/ if ( ! _ _webpack _require _ _ . o ( exports , name ) ) {
/******/ Object . defineProperty ( exports , name , {
/******/ configurable : false ,
/******/ enumerable : true ,
/******/ get : getter
/******/ } ) ;
/******/ }
/******/ } ;
/******/
/******/ // 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 = "" ;
/******/
/******/ // Load entry module and return exports
/******/ return _ _webpack _require _ _ ( _ _webpack _require _ _ . s = 8 ) ;
/******/ } )
/************************************************************************/
/******/ ( [
/* 0 */
/***/ ( 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
module . exports = function ( obj ) {
return Object . prototype . toString . call ( obj ) === '[object Array]' ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 1 */
/***/ ( 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
var _createClass = 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 ) ; } } return function ( 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-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
2017-11-15 07:51:53 +01:00
var bitapRegexSearch = _ _webpack _require _ _ ( 5 ) ;
var bitapSearch = _ _webpack _require _ _ ( 7 ) ;
var patternAlphabet = _ _webpack _require _ _ ( 4 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var Bitap = function ( ) {
function Bitap ( pattern , _ref ) {
var _ref$location = _ref . location ,
location = _ref$location === undefined ? 0 : _ref$location ,
_ref$distance = _ref . distance ,
distance = _ref$distance === undefined ? 100 : _ref$distance ,
_ref$threshold = _ref . threshold ,
threshold = _ref$threshold === undefined ? 0.6 : _ref$threshold ,
_ref$maxPatternLength = _ref . maxPatternLength ,
maxPatternLength = _ref$maxPatternLength === undefined ? 32 : _ref$maxPatternLength ,
_ref$isCaseSensitive = _ref . isCaseSensitive ,
isCaseSensitive = _ref$isCaseSensitive === undefined ? false : _ref$isCaseSensitive ,
_ref$tokenSeparator = _ref . tokenSeparator ,
tokenSeparator = _ref$tokenSeparator === undefined ? / +/g : _ref$tokenSeparator ,
_ref$findAllMatches = _ref . findAllMatches ,
findAllMatches = _ref$findAllMatches === undefined ? false : _ref$findAllMatches ,
_ref$minMatchCharLeng = _ref . minMatchCharLength ,
minMatchCharLength = _ref$minMatchCharLeng === undefined ? 1 : _ref$minMatchCharLeng ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
_classCallCheck ( this , Bitap ) ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
this . options = {
location : location ,
distance : distance ,
threshold : threshold ,
maxPatternLength : maxPatternLength ,
isCaseSensitive : isCaseSensitive ,
tokenSeparator : tokenSeparator ,
findAllMatches : findAllMatches ,
minMatchCharLength : minMatchCharLength
} ;
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
this . pattern = this . options . isCaseSensitive ? pattern : pattern . toLowerCase ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . pattern . length <= maxPatternLength ) {
this . patternAlphabet = patternAlphabet ( this . pattern ) ;
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
_createClass ( Bitap , [ {
key : 'search' ,
value : function search ( text ) {
if ( ! this . options . isCaseSensitive ) {
text = text . toLowerCase ( ) ;
2017-11-07 12:59:49 +01:00
}
2017-02-17 10:26:08 +01:00
2017-11-15 07:51:53 +01:00
// Exact match
if ( this . pattern === text ) {
return {
isMatch : true ,
score : 0 ,
matchedIndices : [ [ 0 , text . length - 1 ] ]
} ;
2017-11-13 20:13:37 +01:00
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
// When pattern length is greater than the machine word length, just do a a regex comparison
var _options = this . options ,
maxPatternLength = _options . maxPatternLength ,
tokenSeparator = _options . tokenSeparator ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
if ( this . pattern . length > maxPatternLength ) {
return bitapRegexSearch ( text , this . pattern , tokenSeparator ) ;
2017-11-13 20:13:37 +01:00
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
// Otherwise, use Bitap algorithm
var _options2 = this . options ,
location = _options2 . location ,
distance = _options2 . distance ,
threshold = _options2 . threshold ,
findAllMatches = _options2 . findAllMatches ,
minMatchCharLength = _options2 . minMatchCharLength ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
return bitapSearch ( text , this . pattern , this . patternAlphabet , {
location : location ,
distance : distance ,
threshold : threshold ,
findAllMatches : findAllMatches ,
minMatchCharLength : minMatchCharLength
2017-11-13 20:13:37 +01:00
} ) ;
2017-11-15 07:51:53 +01:00
}
} ] ) ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
return Bitap ;
} ( ) ;
2016-10-26 16:43:15 +02:00
2017-11-15 07:51:53 +01:00
// let x = new Bitap("od mn war", {})
// let result = x.search("Old Man's War")
// console.log(result)
2016-10-26 16:43:15 +02:00
2017-11-15 07:51:53 +01:00
module . exports = Bitap ;
2016-10-26 16:43:15 +02:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 2 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2016-10-26 16:43:15 +02:00
2017-11-15 07:51:53 +01:00
var isArray = _ _webpack _require _ _ ( 0 ) ;
2016-10-26 16:43:15 +02:00
2017-11-15 07:51:53 +01:00
var deepValue = function deepValue ( obj , path , list ) {
if ( ! path ) {
// If there's no path left, we've gotten to the object we care about.
list . push ( obj ) ;
} else {
var dotIndex = path . indexOf ( '.' ) ;
var firstSegment = path ;
var remaining = null ;
2016-10-26 16:43:15 +02:00
2017-11-15 07:51:53 +01:00
if ( dotIndex !== - 1 ) {
firstSegment = path . slice ( 0 , dotIndex ) ;
remaining = path . slice ( dotIndex + 1 ) ;
}
2016-10-26 16:43:15 +02:00
2017-11-15 07:51:53 +01:00
var value = obj [ firstSegment ] ;
2016-09-26 11:36:04 +02:00
2017-11-15 07:51:53 +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.
for ( var i = 0 , len = value . length ; i < len ; i += 1 ) {
deepValue ( value [ i ] , remaining , list ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
} else if ( remaining ) {
// An object. Recurse further.
deepValue ( value , remaining , list ) ;
2017-11-13 20:13:37 +01:00
}
}
2017-11-15 07:51:53 +01:00
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
return list ;
} ;
2016-11-07 15:05:31 +01:00
2017-11-15 07:51:53 +01:00
module . exports = function ( obj , path ) {
return deepValue ( obj , path , [ ] ) ;
} ;
2016-11-07 15:05:31 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 3 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2016-11-07 15:05:31 +01:00
2017-11-15 07:51:53 +01:00
"use strict" ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +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 ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
var matchedIndices = [ ] ;
var start = - 1 ;
var end = - 1 ;
var i = 0 ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
for ( var len = matchmask . length ; i < len ; i += 1 ) {
var match = matchmask [ i ] ;
if ( match && start === - 1 ) {
start = i ;
} else if ( ! match && start !== - 1 ) {
end = i - 1 ;
if ( end - start + 1 >= minMatchCharLength ) {
matchedIndices . push ( [ start , end ] ) ;
}
start = - 1 ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
// (i-1 - start) + 1 => i - start
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
/***/ } ) ,
/* 4 */
/***/ ( 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
module . exports = function ( pattern ) {
var mask = { } ;
var len = pattern . length ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var i = 0 ; i < len ; i += 1 ) {
mask [ pattern . charAt ( i ) ] = 0 ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var _i = 0 ; _i < len ; _i += 1 ) {
mask [ pattern . charAt ( _i ) ] |= 1 << len - _i - 1 ;
}
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
/***/ } ) ,
/* 5 */
/***/ ( 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
var SPECIAL _CHARS _REGEX = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
module . exports = function ( text , pattern ) {
var tokenSeparator = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : / +/g ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
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 ) {
for ( var i = 0 , matchesLen = matches . length ; i < matchesLen ; i += 1 ) {
var match = matches [ i ] ;
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 ,
isMatch : isMatch ,
matchedIndices : matchedIndices
} ;
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
/* 6 */
/***/ ( 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
module . exports = function ( pattern , _ref ) {
var _ref$errors = _ref . errors ,
errors = _ref$errors === undefined ? 0 : _ref$errors ,
_ref$currentLocation = _ref . currentLocation ,
currentLocation = _ref$currentLocation === undefined ? 0 : _ref$currentLocation ,
_ref$expectedLocation = _ref . expectedLocation ,
expectedLocation = _ref$expectedLocation === undefined ? 0 : _ref$expectedLocation ,
_ref$distance = _ref . distance ,
distance = _ref$distance === undefined ? 100 : _ref$distance ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
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
/***/ } ) ,
/* 7 */
/***/ ( 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-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var bitapScore = _ _webpack _require _ _ ( 6 ) ;
var matchedIndices = _ _webpack _require _ _ ( 3 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
module . exports = function ( text , pattern , patternAlphabet , _ref ) {
var _ref$location = _ref . location ,
location = _ref$location === undefined ? 0 : _ref$location ,
_ref$distance = _ref . distance ,
distance = _ref$distance === undefined ? 100 : _ref$distance ,
_ref$threshold = _ref . threshold ,
threshold = _ref$threshold === undefined ? 0.6 : _ref$threshold ,
_ref$findAllMatches = _ref . findAllMatches ,
findAllMatches = _ref$findAllMatches === undefined ? false : _ref$findAllMatches ,
_ref$minMatchCharLeng = _ref . minMatchCharLength ,
minMatchCharLength = _ref$minMatchCharLeng === undefined ? 1 : _ref$minMatchCharLeng ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var expectedLocation = location ;
// Set starting location at beginning text and initialize the alphabet.
var textLen = text . length ;
// Highest score beyond which we give up.
var currentThreshold = threshold ;
// Is there a nearby exact match? (speedup)
var bestLocation = text . indexOf ( pattern , expectedLocation ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var patternLen = pattern . length ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// a mask of the matches
var matchMask = [ ] ;
for ( var i = 0 ; i < textLen ; i += 1 ) {
matchMask [ i ] = 0 ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
if ( bestLocation !== - 1 ) {
var score = bitapScore ( pattern , {
errors : 0 ,
currentLocation : bestLocation ,
expectedLocation : expectedLocation ,
distance : distance
} ) ;
currentThreshold = Math . min ( score , currentThreshold ) ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
// What about in the other direction? (speed up)
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 ) {
var _score = bitapScore ( pattern , {
errors : 0 ,
currentLocation : bestLocation ,
expectedLocation : expectedLocation ,
distance : distance
} ) ;
currentThreshold = Math . min ( _score , currentThreshold ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Reset the best location
bestLocation = - 1 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var lastBitArr = [ ] ;
var finalScore = 1 ;
var binMax = patternLen + textLen ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var mask = 1 << patternLen - 1 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var _i = 0 ; _i < patternLen ; _i += 1 ) {
// Scan for the best match; each iteration allows for one more error.
// Run a binary search to determine how far from the match location we can stray
// at this error level.
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 ) {
var _score3 = bitapScore ( pattern , {
errors : _i ,
currentLocation : expectedLocation + binMid ,
expectedLocation : expectedLocation ,
distance : distance
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( _score3 <= currentThreshold ) {
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 ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Use the result from this iteration as the maximum for the next.
binMax = binMid ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var start = Math . max ( 1 , expectedLocation - binMid + 1 ) ;
var finish = findAllMatches ? textLen : Math . min ( expectedLocation + binMid , textLen ) + patternLen ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Initialize the bit array
var bitArr = Array ( finish + 2 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
bitArr [ finish + 1 ] = ( 1 << _i ) - 1 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var j = finish ; j >= start ; j -= 1 ) {
var currentLocation = j - 1 ;
var charMatch = patternAlphabet [ text . charAt ( currentLocation ) ] ;
if ( charMatch ) {
matchMask [ currentLocation ] = 1 ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
// First pass: exact match
bitArr [ j ] = ( bitArr [ j + 1 ] << 1 | 1 ) & charMatch ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Subsequent passes: fuzzy match
if ( _i !== 0 ) {
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 , {
errors : _i ,
currentLocation : currentLocation ,
expectedLocation : expectedLocation ,
distance : distance
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// This match will almost certainly be better than any existing match.
// But check anyway.
if ( finalScore <= currentThreshold ) {
// Indeed it is
currentThreshold = finalScore ;
bestLocation = currentLocation ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Already passed `loc`, downhill from here on in.
if ( bestLocation <= expectedLocation ) {
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
// When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
start = Math . max ( 1 , 2 * expectedLocation - bestLocation ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-13 20:13:37 +01:00
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// No hope for a (better) match at greater error levels.
var _score2 = bitapScore ( pattern , {
errors : _i + 1 ,
currentLocation : expectedLocation ,
expectedLocation : expectedLocation ,
distance : distance
} ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( _score2 > currentThreshold ) {
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 ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// Count exact matches (those with a score of 0) to be "almost" exact
return {
isMatch : bestLocation >= 0 ,
score : finalScore === 0 ? 0.001 : finalScore ,
matchedIndices : matchedIndices ( matchMask , minMatchCharLength )
} ;
} ;
/***/ } ) ,
/* 8 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
var _createClass = 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 ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
var Bitap = _ _webpack _require _ _ ( 1 ) ;
var deepValue = _ _webpack _require _ _ ( 2 ) ;
var isArray = _ _webpack _require _ _ ( 0 ) ;
var Fuse = function ( ) {
function Fuse ( list , _ref ) {
var _ref$location = _ref . location ,
location = _ref$location === undefined ? 0 : _ref$location ,
_ref$distance = _ref . distance ,
distance = _ref$distance === undefined ? 100 : _ref$distance ,
_ref$threshold = _ref . threshold ,
threshold = _ref$threshold === undefined ? 0.6 : _ref$threshold ,
_ref$maxPatternLength = _ref . maxPatternLength ,
maxPatternLength = _ref$maxPatternLength === undefined ? 32 : _ref$maxPatternLength ,
_ref$caseSensitive = _ref . caseSensitive ,
caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive ,
_ref$tokenSeparator = _ref . tokenSeparator ,
tokenSeparator = _ref$tokenSeparator === undefined ? / +/g : _ref$tokenSeparator ,
_ref$findAllMatches = _ref . findAllMatches ,
findAllMatches = _ref$findAllMatches === undefined ? false : _ref$findAllMatches ,
_ref$minMatchCharLeng = _ref . minMatchCharLength ,
minMatchCharLength = _ref$minMatchCharLeng === undefined ? 1 : _ref$minMatchCharLeng ,
_ref$id = _ref . id ,
id = _ref$id === undefined ? null : _ref$id ,
_ref$keys = _ref . keys ,
keys = _ref$keys === undefined ? [ ] : _ref$keys ,
_ref$shouldSort = _ref . shouldSort ,
shouldSort = _ref$shouldSort === undefined ? true : _ref$shouldSort ,
_ref$getFn = _ref . getFn ,
getFn = _ref$getFn === undefined ? deepValue : _ref$getFn ,
_ref$sortFn = _ref . sortFn ,
sortFn = _ref$sortFn === undefined ? function ( a , b ) {
return a . score - b . score ;
} : _ref$sortFn ,
_ref$tokenize = _ref . tokenize ,
tokenize = _ref$tokenize === undefined ? false : _ref$tokenize ,
_ref$matchAllTokens = _ref . matchAllTokens ,
matchAllTokens = _ref$matchAllTokens === undefined ? false : _ref$matchAllTokens ,
_ref$includeMatches = _ref . includeMatches ,
includeMatches = _ref$includeMatches === undefined ? false : _ref$includeMatches ,
_ref$includeScore = _ref . includeScore ,
includeScore = _ref$includeScore === undefined ? false : _ref$includeScore ,
_ref$verbose = _ref . verbose ,
verbose = _ref$verbose === undefined ? false : _ref$verbose ;
_classCallCheck ( this , Fuse ) ;
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
} ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
this . setCollection ( list ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
_createClass ( Fuse , [ {
key : 'setCollection' ,
value : function setCollection ( list ) {
this . list = list ;
return list ;
2017-11-07 12:59:49 +01:00
}
} , {
2017-11-15 07:51:53 +01:00
key : 'search' ,
value : function search ( pattern ) {
this . _log ( '---------\nSearch pattern: "' + pattern + '"' ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _prepareSearchers2 = this . _prepareSearchers ( pattern ) ,
tokenSearchers = _prepareSearchers2 . tokenSearchers ,
fullSearcher = _prepareSearchers2 . fullSearcher ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _search2 = this . _search ( tokenSearchers , fullSearcher ) ,
weights = _search2 . weights ,
results = _search2 . results ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . _computeScore ( weights , results ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . options . shouldSort ) {
this . _sort ( results ) ;
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 this . _format ( results ) ;
2017-11-13 20:13:37 +01:00
}
} , {
2017-11-15 07:51:53 +01:00
key : '_prepareSearchers' ,
value : function _prepareSearchers ( ) {
var pattern = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : '' ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var tokenSearchers = [ ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . options . tokenize ) {
// Tokenize on the separator
var tokens = pattern . split ( this . options . tokenSeparator ) ;
for ( var i = 0 , len = tokens . length ; i < len ; i += 1 ) {
tokenSearchers . push ( new Bitap ( tokens [ i ] , this . options ) ) ;
2017-11-07 12:59:49 +01:00
}
}
2017-11-15 07:51:53 +01:00
var fullSearcher = new Bitap ( pattern , this . options ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return { tokenSearchers : tokenSearchers , fullSearcher : fullSearcher } ;
}
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : '_search' ,
value : function _search ( ) {
var tokenSearchers = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ;
var fullSearcher = arguments [ 1 ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var list = this . list ;
var resultMap = { } ;
var results = [ ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// 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
} ) ;
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 { weights : null , results : results } ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Otherwise, the first item is an Object (hopefully), and thus the searching
// is done on the values of the keys of each item.
var weights = { } ;
for ( var _i = 0 , _len = list . length ; _i < _len ; _i += 1 ) {
var item = list [ _i ] ;
// Iterate over every key
for ( var j = 0 , keysLen = this . options . keys . length ; j < keysLen ; j += 1 ) {
var key = this . options . keys [ j ] ;
if ( typeof key !== 'string' ) {
weights [ key . name ] = {
weight : 1 - key . weight || 1
} ;
if ( key . weight <= 0 || key . weight > 1 ) {
throw new Error ( 'Key weight has to be > 0 and <= 1' ) ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
key = key . name ;
} else {
weights [ key ] = {
weight : 1
} ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +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-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
return { weights : weights , results : results } ;
}
2017-11-13 20:13:37 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : '_analyze' ,
value : function _analyze ( _ref2 , _ref3 ) {
var key = _ref2 . key ,
_ref2$arrayIndex = _ref2 . arrayIndex ,
arrayIndex = _ref2$arrayIndex === undefined ? - 1 : _ref2$arrayIndex ,
value = _ref2 . value ,
record = _ref2 . record ,
index = _ref2 . index ;
var _ref3$tokenSearchers = _ref3 . tokenSearchers ,
tokenSearchers = _ref3$tokenSearchers === undefined ? [ ] : _ref3$tokenSearchers ,
_ref3$fullSearcher = _ref3 . fullSearcher ,
fullSearcher = _ref3$fullSearcher === undefined ? [ ] : _ref3$fullSearcher ,
_ref3$resultMap = _ref3 . resultMap ,
resultMap = _ref3$resultMap === undefined ? { } : _ref3$resultMap ,
_ref3$results = _ref3 . results ,
results = _ref3$results === undefined ? [ ] : _ref3$results ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Check if the texvaluet can be searched
if ( value === undefined || value === null ) {
2017-11-13 20:13:37 +01:00
return ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
var exists = false ;
var averageScore = - 1 ;
var numTextMatches = 0 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( typeof value === 'string' ) {
this . _log ( '\nKey: ' + ( key === '' ? '-' : key ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var mainSearchResult = fullSearcher . search ( value ) ;
this . _log ( 'Full text: "' + value + '", score: ' + mainSearchResult . score ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . options . tokenize ) {
var words = value . split ( this . options . tokenSeparator ) ;
var scores = [ ] ;
for ( var i = 0 ; i < tokenSearchers . length ; i += 1 ) {
var tokenSearcher = tokenSearchers [ i ] ;
this . _log ( '\nPattern: "' + tokenSearcher . pattern + '"' ) ;
// let tokenScores = []
var hasMatchInText = false ;
for ( var j = 0 ; j < words . length ; j += 1 ) {
var word = words [ j ] ;
var tokenSearchResult = tokenSearcher . search ( word ) ;
var obj = { } ;
if ( tokenSearchResult . isMatch ) {
obj [ word ] = tokenSearchResult . score ;
exists = true ;
hasMatchInText = true ;
scores . push ( tokenSearchResult . score ) ;
} else {
obj [ word ] = 1 ;
if ( ! this . options . matchAllTokens ) {
scores . push ( 1 ) ;
}
}
this . _log ( 'Token: "' + word + '", score: ' + obj [ word ] ) ;
// tokenScores.push(obj)
}
if ( hasMatchInText ) {
numTextMatches += 1 ;
}
2017-11-13 20:13:37 +01:00
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
averageScore = scores [ 0 ] ;
var scoresLen = scores . length ;
for ( var _i2 = 1 ; _i2 < scoresLen ; _i2 += 1 ) {
averageScore += scores [ _i2 ] ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
averageScore = averageScore / scoresLen ;
this . _log ( 'Token score average:' , averageScore ) ;
2017-11-13 20:13:37 +01:00
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
var finalScore = mainSearchResult . score ;
if ( averageScore > - 1 ) {
finalScore = ( finalScore + averageScore ) / 2 ;
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 . _log ( 'Score average:' , finalScore ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var checkTextMatches = this . options . tokenize && this . options . matchAllTokens ? numTextMatches >= tokenSearchers . length : true ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . _log ( '\nCheck Matches: ' + checkTextMatches ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// If a match is found, add the item to <rawResults>, including its score
if ( ( exists || mainSearchResult . isMatch ) && checkTextMatches ) {
// Check if the item already exists in our results
var existingResult = resultMap [ index ] ;
if ( existingResult ) {
// Use the lowest score
// existingResult.score, bitapResult.score
existingResult . output . push ( {
key : key ,
arrayIndex : arrayIndex ,
value : value ,
score : finalScore ,
matchedIndices : mainSearchResult . matchedIndices
} ) ;
} else {
// Add it to the raw result list
resultMap [ index ] = {
item : record ,
output : [ {
key : key ,
arrayIndex : arrayIndex ,
value : value ,
score : finalScore ,
matchedIndices : mainSearchResult . matchedIndices
} ]
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
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
} ) ;
}
}
}
} , {
key : '_computeScore' ,
value : function _computeScore ( weights , results ) {
this . _log ( '\n\nComputing score:\n' ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var i = 0 , len = results . length ; i < len ; i += 1 ) {
var output = results [ i ] . output ;
var scoreLen = output . length ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var totalScore = 0 ;
var bestScore = 1 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var j = 0 ; j < scoreLen ; j += 1 ) {
var weight = weights ? weights [ output [ j ] . key ] . weight : 1 ;
2018-02-02 12:08:03 +01:00
var score = weight === 1 ? output [ j ] . score : output [ j ] . score || 0.001 ;
2017-11-15 07:51:53 +01:00
var nScore = score * weight ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( weight !== 1 ) {
bestScore = Math . min ( bestScore , nScore ) ;
} else {
output [ j ] . nScore = nScore ;
totalScore += nScore ;
2017-11-13 20:13:37 +01:00
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
results [ i ] . score = bestScore === 1 ? totalScore / scoreLen : bestScore ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . _log ( results [ i ] ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
} , {
key : '_sort' ,
value : function _sort ( results ) {
this . _log ( '\n\nSorting....' ) ;
results . sort ( this . options . sortFn ) ;
}
} , {
key : '_format' ,
value : function _format ( results ) {
var finalOutput = [ ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . _log ( '\n\nOutput:\n\n' , JSON . stringify ( results ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var transformers = [ ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . options . includeMatches ) {
transformers . push ( function ( result , data ) {
var output = result . output ;
data . matches = [ ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var i = 0 , len = output . length ; i < len ; i += 1 ) {
var item = output [ i ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( item . matchedIndices . length === 0 ) {
continue ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var obj = {
indices : item . matchedIndices ,
value : item . value
} ;
if ( item . key ) {
obj . key = item . key ;
}
if ( item . hasOwnProperty ( 'arrayIndex' ) && item . arrayIndex > - 1 ) {
obj . arrayIndex = item . arrayIndex ;
}
data . matches . push ( obj ) ;
}
} ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . options . includeScore ) {
transformers . push ( function ( result , data ) {
data . score = result . score ;
} ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var i = 0 , len = results . length ; i < len ; i += 1 ) {
var result = results [ i ] ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
if ( this . options . id ) {
result . item = this . options . getFn ( result . item , this . options . id ) [ 0 ] ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
if ( ! transformers . length ) {
finalOutput . push ( result . item ) ;
continue ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var data = {
item : result . item
} ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
for ( var j = 0 , _len2 = transformers . length ; j < _len2 ; j += 1 ) {
transformers [ j ] ( result , data ) ;
}
finalOutput . push ( data ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
return finalOutput ;
}
2017-11-07 12:59:49 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : '_log' ,
value : function _log ( ) {
if ( this . options . verbose ) {
var _console ;
( _console = console ) . log . apply ( _console , arguments ) ;
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 Fuse ;
} ( ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
module . exports = Fuse ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } )
/******/ ] ) ;
} ) ;
//# sourceMappingURL=fuse.js.map
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 9 */
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
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _createClass = 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 ) ; } } return function ( 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-15 07:51:53 +01:00
var _redux = _ _webpack _require _ _ ( 2 ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _index = _ _webpack _require _ _ ( 15 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _index2 = _interopRequireDefault ( _index ) ;
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 _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
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
2017-11-15 07:51:53 +01:00
var Store = function ( ) {
function Store ( ) {
_classCallCheck ( this , Store ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . store = ( 0 , _redux . createStore ) ( _index2 . default , window . devToolsExtension ? window . devToolsExtension ( ) : undefined ) ;
}
2017-11-07 12:59:49 +01:00
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 , [ {
key : 'subscribe' ,
value : function subscribe ( onChange ) {
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
* /
} , {
2017-11-15 07:51:53 +01:00
key : 'dispatch' ,
value : function dispatch ( action ) {
this . store . dispatch ( action ) ;
}
2017-11-13 20:13:37 +01:00
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
} , {
2018-04-25 10:20:59 +02:00
key : 'getChoiceById' ,
/ * *
* Get single choice by it ' s ID
* @ return { Object } Found choice
* /
value : function getChoiceById ( id ) {
if ( id ) {
var choices = this . activeChoices ;
var foundChoice = choices . find ( function ( choice ) {
return choice . id === parseInt ( id , 10 ) ;
} ) ;
return foundChoice ;
}
return false ;
}
/ * *
* Get group by group id
* @ param { Number } id Group ID
* @ return { Object } Group data
* /
} , {
key : 'getGroupById' ,
value : function getGroupById ( id ) {
return this . groups . find ( function ( group ) {
return group . id === parseInt ( id , 10 ) ;
} ) ;
}
} , {
key : 'state' ,
get : function get ( ) {
2017-11-15 07:51:53 +01: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
* /
} , {
2018-04-25 10:20:59 +02:00
key : 'items' ,
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
* /
} , {
2018-04-25 10:20:59 +02:00
key : 'activeItems' ,
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
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
2018-02-02 12:08:03 +01: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
} , {
2018-04-25 10:20:59 +02:00
key : 'highlightedActiveItems' ,
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
}
2016-08-23 08:24:45 +02:00
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
} , {
2018-04-25 10:20:59 +02:00
key : 'choices' ,
get : function get ( ) {
return this . state . choices ;
2017-11-15 07:51:53 +01:00
}
2016-08-23 08:24:45 +02:00
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
} , {
2018-04-25 10:20:59 +02:00
key : 'activeChoices' ,
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 ;
} ) ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
return values ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* 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
} , {
2018-04-25 10:20:59 +02:00
key : 'selectableChoices' ,
get : function get ( ) {
return this . choices . filter ( function ( choice ) {
2017-11-15 07:51:53 +01:00
return choice . disabled !== true ;
} ) ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
/ * *
* 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
} , {
2018-04-25 10:20:59 +02:00
key : 'searchableChoices' ,
get : function get ( ) {
return this . selectableChoices . filter ( 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 placeholder choice from store
* @ return { Object } Found placeholder
* /
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
} , {
2018-04-25 10:20:59 +02:00
key : 'placeholderChoice' ,
get : function get ( ) {
return [ ] . concat ( _toConsumableArray ( 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
} , {
2018-04-25 10:20:59 +02:00
key : 'groups' ,
get : function get ( ) {
return this . state . groups ;
2017-11-15 07:51:53 +01:00
}
2016-08-23 08:24:45 +02:00
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
} , {
2018-04-25 10:20:59 +02:00
key : 'activeGroups' ,
get : function get ( ) {
var groups = this . groups ;
var choices = this . choices ;
2016-08-23 08:24:45 +02:00
2018-04-25 10:20:59 +02:00
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 ;
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 10 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
/* WEBPACK VAR INJECTION */ ( function ( global ) { /** Detect free variable `global` from Node.js. */
var freeGlobal = typeof global == 'object' && global && global . Object === Object && global ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/* harmony default export */ _ _webpack _exports _ _ [ "a" ] = ( freeGlobal ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/* WEBPACK VAR INJECTION */ } . call ( _ _webpack _exports _ _ , _ _webpack _require _ _ ( 3 ) ) )
2016-08-23 08:24:45 +02:00
2017-05-18 18:57:35 +02:00
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 11 */
2017-11-13 20:13:37 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2018-02-02 12:08:03 +01:00
module . exports = _ _webpack _require _ _ ( 12 ) ;
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 12 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
/* WEBPACK VAR INJECTION */ ( function ( global , module ) {
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2018-02-02 12:08:03 +01:00
var _ponyfill = _ _webpack _require _ _ ( 14 ) ;
2017-11-15 07:51:53 +01:00
var _ponyfill2 = _interopRequireDefault ( _ponyfill ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { 'default' : obj } ; }
var root ; /* global window */
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 {
root = Function ( 'return this' ) ( ) ;
}
var result = ( 0 , _ponyfill2 [ 'default' ] ) ( root ) ;
exports [ 'default' ] = result ;
2018-02-02 12:08:03 +01:00
/* WEBPACK VAR INJECTION */ } . call ( exports , _ _webpack _require _ _ ( 3 ) , _ _webpack _require _ _ ( 13 ) ( module ) ) )
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 13 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports ) {
2018-02-02 12:08:03 +01:00
module . exports = function ( module ) {
if ( ! module . webpackPolyfill ) {
module . deprecate = function ( ) { } ;
module . paths = [ ] ;
// module.parent = undefined by default
if ( ! module . children ) module . children = [ ] ;
Object . defineProperty ( module , "loaded" , {
enumerable : true ,
get : function ( ) {
return module . l ;
}
} ) ;
Object . defineProperty ( module , "id" , {
enumerable : true ,
get : function ( ) {
return module . i ;
}
} ) ;
module . webpackPolyfill = 1 ;
}
return module ;
} ;
2017-11-15 07:51:53 +01:00
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 14 */
2017-05-18 18:57:35 +02:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2016-08-23 08:24:45 +02:00
2017-11-07 12:59:49 +01:00
"use strict" ;
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports [ 'default' ] = symbolObservablePonyfill ;
function symbolObservablePonyfill ( root ) {
var result ;
var _Symbol = root . Symbol ;
if ( typeof _Symbol === 'function' ) {
if ( _Symbol . observable ) {
result = _Symbol . observable ;
} else {
result = _Symbol ( 'observable' ) ;
_Symbol . observable = result ;
}
} else {
result = '@@observable' ;
}
return result ;
2017-11-07 12:59:49 +01:00
} ;
2017-05-18 18:57:35 +02:00
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 15 */
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
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _redux = _ _webpack _require _ _ ( 2 ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _items = _ _webpack _require _ _ ( 16 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _items2 = _interopRequireDefault ( _items ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _groups = _ _webpack _require _ _ ( 17 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _groups2 = _interopRequireDefault ( _groups ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _choices = _ _webpack _require _ _ ( 18 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _choices2 = _interopRequireDefault ( _choices ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
var appReducer = ( 0 , _redux . combineReducers ) ( {
items : _items2 . default ,
groups : _groups2 . default ,
choices : _choices2 . default
} ) ;
var rootReducer = function rootReducer ( passedState , action ) {
var state = passedState ;
// If we are clearing all items, groups and options we reassign
// state and then pass that state to our proper reducer. This isn't
// mutating our actual state
// See: http://stackoverflow.com/a/35641992
if ( action . type === 'CLEAR_ALL' ) {
state = undefined ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
return appReducer ( state , action ) ;
} ;
exports . default = rootReducer ;
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 16 */
2017-11-15 07:51:53 +01:00
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = items ;
function _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
var defaultState = exports . defaultState = [ ] ;
function items ( ) {
var state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : defaultState ;
var action = arguments [ 1 ] ;
switch ( action . type ) {
case 'ADD_ITEM' :
{
// Add object to items array
var newState = [ ] . concat ( _toConsumableArray ( state ) , [ {
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 ;
if ( item . id === action . id ) {
item . active = false ;
}
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 ;
if ( item . id === action . id ) {
item . highlighted = action . highlighted ;
}
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
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 17 */
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 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
var defaultState = exports . defaultState = [ ] ;
function groups ( ) {
var state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : defaultState ;
var action = arguments [ 1 ] ;
switch ( action . type ) {
case 'ADD_GROUP' :
{
return [ ] . concat ( _toConsumableArray ( state ) , [ {
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
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 18 */
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 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var defaultState = exports . 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 ;
var action = arguments [ 1 ] ;
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
* /
return [ ] . concat ( _toConsumableArray ( state ) , [ {
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 ;
} ) ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
// When an item is added and it has an associated choice,
// we want to disable it so it can't be chosen again
if ( action . choiceId > - 1 ) {
return state . map ( function ( obj ) {
var choice = obj ;
if ( choice . id === parseInt ( action . choiceId , 10 ) ) {
choice . selected = true ;
}
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 ;
if ( choice . id === parseInt ( action . choiceId , 10 ) ) {
choice . selected = false ;
}
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 ) {
var choice = obj ;
// Set active state based on whether choice is
// within filtered results
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 ;
}
return false ;
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
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
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 19 */
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
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _createClass = 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 ) ; } } return function ( 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-15 07:51:53 +01:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
var Dropdown = function ( ) {
function Dropdown ( instance , element , classNames ) {
_classCallCheck ( this , Dropdown ) ;
this . parentInstance = instance ;
this . element = element ;
this . classNames = classNames ;
this . dimensions = null ;
this . position = null ;
this . isActive = false ;
2017-11-13 20:13:37 +01:00
}
2017-11-07 12:59:49 +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 , [ {
key : 'distanceFromTopWindow' ,
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 ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Find element that matches passed selector
* @ return { HTMLElement }
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'getChild' ,
value : function getChild ( selector ) {
return this . element . querySelector ( selector ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* 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
} , {
key : 'show' ,
value : function show ( ) {
this . element . classList . add ( this . classNames . activeState ) ;
this . element . setAttribute ( 'aria-expanded' , 'true' ) ;
this . isActive = true ;
return this . parentInstance ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Hide dropdown from user
* @ return { Object } Class instance
* @ public
* /
} , {
key : 'hide' ,
value : function hide ( ) {
this . element . classList . remove ( this . classNames . activeState ) ;
this . element . setAttribute ( 'aria-expanded' , 'false' ) ;
this . isActive = false ;
return this . parentInstance ;
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
/***/ } ) ,
2018-02-02 12:08:03 +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
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _createClass = 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 ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
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
2017-11-15 07:51:53 +01:00
var Container = function ( ) {
function Container ( instance , element , classNames ) {
_classCallCheck ( this , Container ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . parentInstance = instance ;
this . element = element ;
this . classNames = classNames ;
this . config = instance . config ;
this . isOpen = false ;
this . isFlipped = false ;
this . isFocussed = false ;
this . isDisabled = false ;
this . isLoading = false ;
this . onFocus = this . onFocus . bind ( this ) ;
this . onBlur = this . onBlur . bind ( this ) ;
}
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
/ * *
* Add event listeners
* /
2017-11-07 12:59:49 +01:00
2018-04-25 10:20:59 +02:00
_createClass ( Container , [ {
2017-11-15 07:51:53 +01:00
key : 'addEventListeners' ,
value : function addEventListeners ( ) {
this . element . addEventListener ( 'focus' , this . onFocus ) ;
this . element . addEventListener ( 'blur' , this . onBlur ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Remove event listeners
* /
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
} , {
key : 'removeEventListeners' ,
value : function removeEventListeners ( ) {
this . element . removeEventListener ( 'focus' , this . onFocus ) ;
this . element . removeEventListener ( 'blur' , this . onBlur ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Set focussed state
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'onFocus' ,
value : function onFocus ( ) {
this . isFocussed = true ;
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
/ * *
* Remove blurred state
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'onBlur' ,
value : function onBlur ( ) {
this . isFocussed = false ;
}
2017-11-07 12:59:49 +01:00
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
} , {
key : 'shouldFlip' ,
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 ;
}
// If flip is enabled and the dropdown bottom position is
// greater than the window height flip the dropdown.
var shouldFlip = false ;
if ( this . config . position === 'auto' ) {
2018-02-02 12:08:03 +01:00
shouldFlip = dropdownPos >= windowHeight ;
2017-11-15 07:51:53 +01:00
} else if ( this . config . position === 'top' ) {
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
} , {
key : 'setActiveDescendant' ,
value : function setActiveDescendant ( activeDescendantID ) {
this . element . setAttribute ( 'aria-activedescendant' , activeDescendantID ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Remove active descendant attribute
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'removeActiveDescendant' ,
value : function removeActiveDescendant ( ) {
this . element . removeAttribute ( 'aria-activedescendant' ) ;
}
} , {
key : 'open' ,
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 ;
}
}
} , {
key : 'close' ,
value : function close ( ) {
this . element . classList . remove ( this . classNames . openState ) ;
this . element . setAttribute ( 'aria-expanded' , 'false' ) ;
this . removeActiveDescendant ( ) ;
this . isOpen = false ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// A dropdown flips if it does not have space within the page
if ( this . isFlipped ) {
this . element . classList . remove ( this . classNames . flippedState ) ;
this . isFlipped = false ;
}
}
} , {
key : 'focus' ,
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
}
} , {
key : 'addFocusState' ,
value : function addFocusState ( ) {
this . element . classList . add ( this . classNames . focusState ) ;
}
} , {
key : 'removeFocusState' ,
value : function removeFocusState ( ) {
this . element . classList . remove ( this . classNames . focusState ) ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
/ * *
* Remove disabled state
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'enable' ,
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' ) ;
if ( this . parentInstance . isSelectOneElement ) {
this . element . setAttribute ( 'tabindex' , '0' ) ;
2017-11-13 20:13:37 +01:00
}
2017-11-15 07:51:53 +01:00
this . isDisabled = false ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Set disabled state
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'disable' ,
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' ) ;
if ( this . parentInstance . isSelectOneElement ) {
this . element . setAttribute ( 'tabindex' , '-1' ) ;
}
this . isDisabled = true ;
}
} , {
2018-02-02 12:08:03 +01:00
key : 'wrap' ,
value : function wrap ( element ) {
( 0 , _utils . wrap ) ( element , this . element ) ;
}
} , {
key : 'unwrap' ,
value : function unwrap ( element ) {
// Move passed element outside this element
this . element . parentNode . insertBefore ( element , this . element ) ;
// Remove this element
2017-11-15 07:51:53 +01:00
this . element . parentNode . removeChild ( this . element ) ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Add loading state to element
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'addLoadingState' ,
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-07 12:59:49 +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
} , {
key : 'removeLoadingState' ,
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
}
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
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 21 */
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
} ) ;
2017-11-13 20:13:37 +01:00
var _createClass = 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 ) ; } } return function ( 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-15 07:51:53 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
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
2017-11-15 07:51:53 +01:00
var Input = function ( ) {
function Input ( instance , element , classNames ) {
_classCallCheck ( this , Input ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . parentInstance = instance ;
this . element = element ;
this . classNames = classNames ;
this . isFocussed = this . element === document . activeElement ;
this . isDisabled = false ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
// Bind event listeners
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-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
_createClass ( Input , [ {
key : 'addEventListeners' ,
value : function addEventListeners ( ) {
this . element . addEventListener ( 'input' , this . onInput ) ;
this . element . addEventListener ( 'paste' , this . onPaste ) ;
this . element . addEventListener ( 'focus' , this . onFocus ) ;
this . element . addEventListener ( 'blur' , this . onBlur ) ;
}
} , {
key : 'removeEventListeners' ,
value : function removeEventListeners ( ) {
this . element . removeEventListener ( 'input' , this . onInput ) ;
this . element . removeEventListener ( 'paste' , this . onPaste ) ;
this . element . removeEventListener ( 'focus' , this . onFocus ) ;
this . element . removeEventListener ( 'blur' , this . onBlur ) ;
}
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Input event
* @ return
* @ private
* /
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'onInput' ,
value : function onInput ( ) {
if ( ! this . parentInstance . isSelectOneElement ) {
this . setWidth ( ) ;
}
2017-11-07 12:59:49 +01:00
}
2017-11-15 07:51:53 +01:00
/ * *
* Paste event
* @ param { Object } e Event
* @ return
* @ private
* /
2017-11-07 12:59:49 +01:00
} , {
2017-11-15 07:51:53 +01:00
key : 'onPaste' ,
value : function onPaste ( e ) {
// Disable pasting into the input if option has been set
if ( e . target === this . element && ! this . parentInstance . config . paste ) {
e . preventDefault ( ) ;
}
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Set focussed state
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'onFocus' ,
value : function onFocus ( ) {
this . isFocussed = true ;
}
/ * *
* Remove focussed state
* /
} , {
key : 'onBlur' ,
value : function onBlur ( ) {
this . isFocussed = false ;
}
} , {
key : 'enable' ,
value : function enable ( ) {
this . element . removeAttribute ( 'disabled' ) ;
this . isDisabled = false ;
}
} , {
key : 'disable' ,
value : function disable ( ) {
this . element . setAttribute ( 'disabled' , '' ) ;
this . isDisabled = true ;
}
} , {
key : 'focus' ,
value : function focus ( ) {
if ( ! this . isFocussed ) {
this . element . focus ( ) ;
}
}
2018-02-02 12:08:03 +01:00
} , {
key : 'blur' ,
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
* /
} , {
key : 'clear' ,
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
}
2017-11-15 07:51:53 +01:00
return this . parentInstance ;
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
} , {
key : 'setWidth' ,
value : function setWidth ( enforceWidth ) {
if ( this . parentInstance . placeholder ) {
// 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.
if ( this . element . value && this . element . value . length >= this . parentInstance . placeholder . length / 1.25 || enforceWidth ) {
2018-04-25 10:20:59 +02:00
this . element . style . width = this . calcWidth ( ) ;
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-04-25 10:20:59 +02:00
this . element . style . width = this . calcWidth ( ) ;
2017-11-07 12:59:49 +01:00
}
}
2017-11-13 20:13:37 +01:00
} , {
2018-04-25 10:20:59 +02:00
key : 'calcWidth' ,
value : function calcWidth ( ) {
return ( 0 , _utils . calcWidthOfInput ) ( this . element ) ;
2017-11-15 07:51:53 +01:00
}
} , {
key : 'setActiveDescendant' ,
value : function setActiveDescendant ( activeDescendantID ) {
this . element . setAttribute ( 'aria-activedescendant' , activeDescendantID ) ;
}
} , {
key : 'removeActiveDescendant' ,
value : function removeActiveDescendant ( ) {
this . element . removeAttribute ( 'aria-activedescendant' ) ;
}
2018-04-25 10:20:59 +02:00
} , {
key : 'placeholder' ,
set : function set ( placeholder ) {
this . element . placeholder = placeholder ;
}
} , {
key : 'value' ,
set : function set ( value ) {
this . element . value = value ;
} ,
get : function get ( ) {
return this . element . 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 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
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 22 */
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
} ) ;
var _createClass = 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 ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
var List = function ( ) {
function List ( instance , element , classNames ) {
_classCallCheck ( this , List ) ;
this . parentInstance = instance ;
this . element = element ;
this . classNames = classNames ;
this . scrollPos = this . element . scrollTop ;
this . height = this . element . offsetHeight ;
this . hasChildren = ! ! this . element . children ;
}
2018-04-25 10:20:59 +02:00
/ * *
* Clear List contents
* /
2017-11-15 07:51:53 +01:00
2018-04-25 10:20:59 +02:00
_createClass ( List , [ {
2017-11-15 07:51:53 +01:00
key : 'clear' ,
value : function clear ( ) {
this . element . innerHTML = '' ;
}
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
/ * *
* Scroll to passed position on Y axis
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'scrollTo' ,
value : function scrollTo ( ) {
var scrollPos = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : 0 ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
this . element . scrollTop = scrollPos ;
}
/ * *
* Append node to element
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'append' ,
value : function append ( node ) {
this . element . appendChild ( node ) ;
}
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
/ * *
* Find element that matches passed selector
* @ return { HTMLElement }
* /
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
} , {
key : 'getChild' ,
value : function getChild ( selector ) {
return this . element . querySelector ( selector ) ;
}
} ] ) ;
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
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 23 */
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
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _createClass = 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 ) ; } } return function ( 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-15 07:51:53 +01:00
var _get = function get ( object , property , receiver ) { if ( object === null ) object = Function . prototype ; var desc = Object . getOwnPropertyDescriptor ( object , property ) ; if ( desc === undefined ) { var parent = Object . getPrototypeOf ( object ) ; if ( parent === null ) { return undefined ; } else { return get ( parent , property , receiver ) ; } } else if ( "value" in desc ) { return desc . value ; } else { var getter = desc . get ; if ( getter === undefined ) { return undefined ; } return getter . call ( receiver ) ; } } ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _wrappedElement = _ _webpack _require _ _ ( 4 ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _wrappedElement2 = _interopRequireDefault ( _wrappedElement ) ;
2017-11-07 12:59:49 +01:00
2018-02-02 12:08:03 +01:00
var _utils = _ _webpack _require _ _ ( 0 ) ;
2017-11-15 07:51:53 +01:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2017-11-13 20:13:37 +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
2017-11-15 07:51:53 +01:00
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; }
2016-08-23 08:24:45 +02:00
2017-11-15 07:51:53 +01:00
var WrappedInput = function ( _WrappedElement ) {
_inherits ( WrappedInput , _WrappedElement ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
function WrappedInput ( instance , element , classNames ) {
_classCallCheck ( this , WrappedInput ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _this = _possibleConstructorReturn ( this , ( WrappedInput . _ _proto _ _ || Object . getPrototypeOf ( WrappedInput ) ) . call ( this , instance , element , classNames ) ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
_this . parentInstance = instance ;
_this . element = element ;
_this . classNames = classNames ;
return _this ;
}
_createClass ( WrappedInput , [ {
2018-04-25 10:20:59 +02:00
key : 'value' ,
set : function set ( items ) {
2018-02-02 12:08:03 +01:00
var itemsFiltered = ( 0 , _utils . reduceToValues ) ( items ) ;
var itemsFilteredString = itemsFiltered . join ( this . parentInstance . config . delimiter ) ;
this . element . setAttribute ( 'value' , itemsFilteredString ) ;
this . element . value = itemsFilteredString ;
2017-11-15 07:51:53 +01:00
}
2018-04-25 10:20:59 +02:00
// @todo figure out why we need this? Perhaps a babel issue
,
get : function get ( ) {
return _get ( WrappedInput . prototype . _ _proto _ _ || Object . getPrototypeOf ( WrappedInput . prototype ) , 'value' , this ) ;
}
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 ;
} ( _wrappedElement2 . 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
/***/ } ) ,
2018-02-02 12:08:03 +01:00
/* 24 */
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
} ) ;
2017-11-07 12:59:49 +01:00
2017-11-15 07:51:53 +01:00
var _createClass = 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 ) ; } } return function ( 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-15 07:51:53 +01:00
var _wrappedElement = _ _webpack _require _ _ ( 4 ) ;
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
var _wrappedElement2 = _interopRequireDefault ( _wrappedElement ) ;
2017-11-13 20:13:37 +01:00
2018-02-02 12:08:03 +01:00
var _templates = _ _webpack _require _ _ ( 5 ) ;
var _templates2 = _interopRequireDefault ( _templates ) ;
2017-11-15 07:51:53 +01:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2017-11-13 20:13:37 +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-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
2017-11-13 20:13:37 +01:00
2017-11-15 07:51:53 +01:00
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; }
var WrappedSelect = function ( _WrappedElement ) {
_inherits ( WrappedSelect , _WrappedElement ) ;
function WrappedSelect ( instance , element , classNames ) {
_classCallCheck ( this , WrappedSelect ) ;
var _this = _possibleConstructorReturn ( this , ( WrappedSelect . _ _proto _ _ || Object . getPrototypeOf ( WrappedSelect ) ) . call ( this , instance , element , classNames ) ) ;
_this . parentInstance = instance ;
_this . element = element ;
_this . classNames = classNames ;
return _this ;
}
_createClass ( WrappedSelect , [ {
2018-04-25 10:20:59 +02:00
key : 'appendDocFragment' ,
value : function appendDocFragment ( fragment ) {
this . element . innerHTML = '' ;
this . element . appendChild ( fragment ) ;
2017-11-15 07:51:53 +01:00
}
} , {
2018-04-25 10:20:59 +02:00
key : 'placeholderOption' ,
get : function get ( ) {
2017-11-15 07:51:53 +01:00
return this . element . querySelector ( 'option[placeholder]' ) ;
}
} , {
2018-04-25 10:20:59 +02:00
key : 'optionGroups' ,
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
} , {
2018-04-25 10:20:59 +02:00
key : 'options' ,
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 ( ) ;
var addOptionToFragment = function addOptionToFragment ( data ) {
// Create a standard select option
var template = _templates2 . default . option ( data ) ;
// Append it to fragment
fragment . appendChild ( template ) ;
} ;
2016-08-23 08:24:45 +02:00
2018-02-02 12:08:03 +01:00
// Add each list item to list
options . forEach ( function ( optionData ) {
return addOptionToFragment ( optionData ) ;
} ) ;
2016-08-23 08:24:45 +02:00
2018-02-02 12:08:03 +01:00
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 ;
} ( _wrappedElement2 . 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
/***/ } ) ,
2017-11-15 07:51:53 +01:00
/* 25 */
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 _ _ ; / * !
Copyright ( c ) 2016 Jed Watson .
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 ) ;
} else if ( Array . isArray ( arg ) ) {
classes . push ( classNames . apply ( null , arg ) ) ;
} 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
2017-11-07 12:59:49 +01:00
if ( typeof module !== 'undefined' && module . exports ) {
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 _ _ ) ) ;
} else {
window . classNames = classNames ;
}
} ( ) ) ;
2017-09-18 17:46:48 +02:00
2017-11-07 12:59:49 +01:00
/***/ } ) ,
2017-11-15 07:51:53 +01:00
/* 26 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . clearChoices = exports . activateChoices = exports . filterChoices = exports . addChoice = undefined ;
var _constants = _ _webpack _require _ _ ( 1 ) ;
var addChoice = exports . addChoice = function addChoice ( value , label , id , groupId , disabled , elementId , customProperties , placeholder , keyCode ) {
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
} ;
} ;
var filterChoices = exports . filterChoices = function filterChoices ( results ) {
return {
type : _constants . ACTION _TYPES . FILTER _CHOICES ,
results : results
} ;
} ;
var activateChoices = exports . activateChoices = function activateChoices ( ) {
var active = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : true ;
return {
type : _constants . ACTION _TYPES . ACTIVATE _CHOICES ,
active : active
} ;
} ;
var clearChoices = exports . clearChoices = function clearChoices ( ) {
return {
type : _constants . ACTION _TYPES . CLEAR _CHOICES
} ;
} ;
/***/ } ) ,
/* 27 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . highlightItem = exports . removeItem = exports . addItem = undefined ;
var _constants = _ _webpack _require _ _ ( 1 ) ;
var addItem = exports . addItem = function addItem ( value , label , id , choiceId , groupId , customProperties , placeholder , keyCode ) {
return {
type : _constants . ACTION _TYPES . ADD _ITEM ,
value : value ,
label : label ,
id : id ,
choiceId : choiceId ,
groupId : groupId ,
customProperties : customProperties ,
placeholder : placeholder ,
keyCode : keyCode
} ;
} ;
var removeItem = exports . removeItem = function removeItem ( id , choiceId ) {
return {
type : _constants . ACTION _TYPES . REMOVE _ITEM ,
id : id ,
choiceId : choiceId
} ;
} ;
var highlightItem = exports . highlightItem = function highlightItem ( id , highlighted ) {
return {
type : _constants . ACTION _TYPES . HIGHLIGHT _ITEM ,
id : id ,
highlighted : highlighted
} ;
} ;
/***/ } ) ,
/* 28 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . addGroup = undefined ;
var _constants = _ _webpack _require _ _ ( 1 ) ;
/* eslint-disable import/prefer-default-export */
var addGroup = exports . addGroup = function addGroup ( value , id , active , disabled ) {
return {
type : _constants . ACTION _TYPES . ADD _GROUP ,
value : value ,
id : id ,
active : active ,
disabled : disabled
} ;
} ;
/***/ } ) ,
/* 29 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
/* eslint-disable import/prefer-default-export */
var clearAll = exports . clearAll = function clearAll ( ) {
return {
type : 'CLEAR_ALL'
} ;
} ;
/***/ } ) ,
/* 30 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
2016-08-23 08:24:45 +02:00
2017-11-07 12:59:49 +01:00
/* eslint-disable */
( function ( ) {
// Production steps of ECMA-262, Edition 6, 22.1.2.1
// Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from
if ( ! Array . from ) {
Array . from = function ( ) {
var toStr = Object . prototype . toString ;
var isCallable = function isCallable ( fn ) {
return typeof fn === 'function' || toStr . call ( fn ) === '[object Function]' ;
} ;
var toInteger = function toInteger ( value ) {
var number = Number ( value ) ;
if ( isNaN ( number ) ) {
return 0 ;
}
if ( number === 0 || ! isFinite ( number ) ) {
return number ;
}
return ( number > 0 ? 1 : - 1 ) * Math . floor ( Math . abs ( number ) ) ;
} ;
var maxSafeInteger = Math . pow ( 2 , 53 ) - 1 ;
var toLength = function toLength ( value ) {
var len = toInteger ( value ) ;
return Math . min ( Math . max ( len , 0 ) , maxSafeInteger ) ;
} ;
// The length property of the from method is 1.
return function from ( arrayLike /* , mapFn, thisArg */ ) {
// 1. Let C be the this value.
var C = this ;
// 2. Let items be ToObject(arrayLike).
var items = Object ( arrayLike ) ;
// 3. ReturnIfAbrupt(items).
if ( arrayLike == null ) {
throw new TypeError ( 'Array.from requires an array-like object - not null or undefined' ) ;
}
// 4. If mapfn is undefined, then let mapping be false.
var mapFn = arguments . length > 1 ? arguments [ 1 ] : void undefined ;
var T = void 0 ;
if ( typeof mapFn !== 'undefined' ) {
// 5. else
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
if ( ! isCallable ( mapFn ) ) {
throw new TypeError ( 'Array.from: when provided, the second argument must be a function' ) ;
}
// 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
if ( arguments . length > 2 ) {
T = arguments [ 2 ] ;
}
}
// 10. Let lenValue be Get(items, "length").
// 11. Let len be ToLength(lenValue).
var len = toLength ( items . length ) ;
// 13. If IsConstructor(C) is true, then
// 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
// 14. a. Else, Let A be ArrayCreate(len).
var A = isCallable ( C ) ? Object ( new C ( len ) ) : new Array ( len ) ;
// 16. Let k be 0.
var k = 0 ;
// 17. Repeat, while k < len… (also steps a - h)
var kValue = void 0 ;
while ( k < len ) {
kValue = items [ k ] ;
if ( mapFn ) {
A [ k ] = typeof T === 'undefined' ? mapFn ( kValue , k ) : mapFn . call ( T , kValue , k ) ;
} else {
A [ k ] = kValue ;
}
k += 1 ;
}
// 18. Let putStatus be Put(A, "length", len, true).
A . length = len ;
// 20. Return A.
return A ;
} ;
} ( ) ;
}
// Reference: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find
if ( ! Array . prototype . find ) {
Array . prototype . find = function ( predicate ) {
'use strict' ;
if ( this == null ) {
throw new TypeError ( 'Array.prototype.find called on null or undefined' ) ;
}
if ( typeof predicate !== 'function' ) {
throw new TypeError ( 'predicate must be a function' ) ;
}
var list = Object ( this ) ;
var length = list . length >>> 0 ;
var thisArg = arguments [ 1 ] ;
var value = void 0 ;
for ( var i = 0 ; i < length ; i ++ ) {
value = list [ i ] ;
if ( predicate . call ( thisArg , value , i , list ) ) {
return value ;
}
}
return undefined ;
} ;
}
function CustomEvent ( event , params ) {
params = params || {
bubbles : false ,
cancelable : false ,
detail : undefined
} ;
var evt = document . createEvent ( 'CustomEvent' ) ;
evt . initCustomEvent ( event , params . bubbles , params . cancelable , params . detail ) ;
return evt ;
}
CustomEvent . prototype = window . Event . prototype ;
window . CustomEvent = CustomEvent ;
} ) ( ) ;
2016-08-23 08:24:45 +02:00
2017-05-18 18:57:35 +02:00
/***/ } )
2017-11-07 12:59:49 +01:00
/******/ ] ) ;
2016-10-18 15:15:00 +02:00
} ) ;
2017-07-31 17:18:36 +02:00
//# sourceMappingURL=choices.js.map