From 4d1c3cd2aea5a8882fcadd21780d2233f7b9c54c Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Fri, 22 Feb 2019 22:06:59 +0000 Subject: [PATCH] Version 6.0.2 --- public/assets/scripts/choices.js | 1330 ++++++++++++-------------- public/assets/scripts/choices.min.js | 28 +- public/index.html | 6 +- 3 files changed, 635 insertions(+), 729 deletions(-) diff --git a/public/assets/scripts/choices.js b/public/assets/scripts/choices.js index 030737d..4f641c3 100644 --- a/public/assets/scripts/choices.js +++ b/public/assets/scripts/choices.js @@ -108,11 +108,10 @@ return /******/ (function(modules) { // webpackBootstrap Object.defineProperty(exports, "__esModule", { value: true }); -exports.diff = exports.cloneObject = exports.existsInArray = exports.isIE11 = exports.fetchFromObject = exports.reduceToValues = exports.getWindowHeight = exports.dispatchEvent = exports.sortByScore = exports.sortByAlpha = exports.calcWidthOfInput = exports.strToEl = exports.stripHTML = exports.isScrolledIntoView = exports.getAdjacentEl = exports.findAncestorByAttrName = exports.findAncestor = exports.wrap = exports.extend = exports.isElement = exports.isType = exports.getType = exports.generateId = exports.generateChars = exports.getRandomNumber = void 0; +exports.diff = exports.cloneObject = exports.existsInArray = exports.isIE11 = exports.fetchFromObject = exports.getWindowHeight = exports.dispatchEvent = exports.sortByScore = exports.sortByAlpha = exports.calcWidthOfInput = exports.strToEl = exports.sanitise = exports.isScrolledIntoView = exports.getAdjacentEl = exports.findAncestorByAttrName = exports.wrap = exports.isElement = exports.isType = exports.getType = exports.generateId = exports.generateChars = exports.getRandomNumber = void 0; var _this = void 0; -/* eslint-disable */ var getRandomNumber = function getRandomNumber(min, max) { return Math.floor(Math.random() * (max - min) + min); }; @@ -148,8 +147,7 @@ var getType = function getType(obj) { exports.getType = getType; var isType = function isType(type, obj) { - var clas = getType(obj); - return obj !== undefined && obj !== null && clas === type; + return obj !== undefined && obj !== null && getType(obj) === type; }; exports.isType = isType; @@ -160,44 +158,8 @@ var isElement = function isElement(element) { exports.isElement = isElement; -var extend = function extend() { - var extended = {}; - var length = arguments.length; - /** - * 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]; - } - } - } - }; // Loop through each passed argument - - - for (var i = 0; i < length; i++) { - // store argument at position i - var obj = arguments[i]; // If we are in fact dealing with an object, merge it. - - if (isType('Object', obj)) { - merge(obj); - } - } - - return extended; -}; - -exports.extend = extend; - -var wrap = function wrap(element, wrapper) { - wrapper = wrapper || document.createElement('div'); +var wrap = function wrap(element) { + var wrapper = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.createElement('div'); if (element.nextSibling) { element.parentNode.insertBefore(wrapper, element.nextSibling); @@ -210,16 +172,6 @@ var wrap = function wrap(element, wrapper) { exports.wrap = wrap; -var findAncestor = function findAncestor(el, cls) { - while ((el = el.parentElement) && !el.classList.contains(cls)) { - ; - } - - return el; -}; - -exports.findAncestor = findAncestor; - var findAncestorByAttrName = function findAncestorByAttrName(el, attr) { var target = el; @@ -238,7 +190,11 @@ exports.findAncestorByAttrName = findAncestorByAttrName; var getAdjacentEl = function getAdjacentEl(startEl, className) { var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; - if (!startEl || !className) return; + + if (!startEl || !className) { + return; + } + var parent = startEl.parentNode.parentNode; var children = Array.from(parent.querySelectorAll(className)); var startPos = children.indexOf(startEl); @@ -250,7 +206,11 @@ exports.getAdjacentEl = getAdjacentEl; var isScrolledIntoView = function isScrolledIntoView(el, parent) { var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; - if (!el) return; + + if (!el) { + return; + } + var isVisible; if (direction > 0) { @@ -266,25 +226,28 @@ var isScrolledIntoView = function isScrolledIntoView(el, parent) { exports.isScrolledIntoView = isScrolledIntoView; -var stripHTML = function stripHTML(html) { - return html.replace(/&/g, '&').replace(/>/g, '&rt;').replace(//g, '&rt;').replace(/".concat(stripHTML(value), "")); + var testEl = strToEl("".concat(sanitise(value), "")); testEl.style.position = 'absolute'; testEl.style.padding = '0'; testEl.style.top = '-9999px'; @@ -339,8 +302,8 @@ var calcWidthOfInput = function calcWidthOfInput(input, callback) { exports.calcWidthOfInput = calcWidthOfInput; var sortByAlpha = function sortByAlpha(a, b) { - var labelA = (a.label || a.value).toLowerCase(); - var labelB = (b.label || b.value).toLowerCase(); + var labelA = "".concat(a.label || a.value).toLowerCase(); + var labelB = "".concat(b.label || b.value).toLowerCase(); if (labelA < labelB) { return -1; @@ -381,17 +344,6 @@ var getWindowHeight = function getWindowHeight() { exports.getWindowHeight = getWindowHeight; -var 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; -}; - -exports.reduceToValues = reduceToValues; - var fetchFromObject = function fetchFromObject(object, path) { var index = path.indexOf('.'); @@ -519,7 +471,7 @@ var DEFAULT_CONFIG = { uniqueItemText: 'Only unique values can be added', customAddItemText: 'Only values matching specific conditions can be added', addItemText: function addItemText(value) { - return "Press Enter to add \"".concat((0, _utils.stripHTML)(value), "\""); + return "Press Enter to add \"".concat((0, _utils.sanitise)(value), "\""); }, maxItemText: function maxItemText(maxItemCount) { return "Only ".concat(maxItemCount, " values can be added"); @@ -3570,7 +3522,7 @@ function () { userTemplates = callbackOnCreateTemplates.call(this, _utils.strToEl); } - this.config.templates = (0, _utils.extend)(_templates.TEMPLATES, userTemplates); + this.config.templates = (0, _deepmerge.default)(_templates.TEMPLATES, userTemplates); } }, { key: "_createElements", @@ -3877,7 +3829,7 @@ module.exports = Choices; /***/ (function(module, exports, __webpack_require__) { /*! - * Fuse.js v3.4.2 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v3.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2012-2017 Kirollos Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -3984,16 +3936,14 @@ return /******/ (function(modules) { // webpackBootstrap /*! no static exports found */ /***/ (function(module, exports) { -module.exports = function () { - var matchmask = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - var minMatchCharLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; - var matchedIndices = []; - var start = -1; - var end = -1; - var i = 0; +module.exports = (matchmask = [], minMatchCharLength = 1) => { + let matchedIndices = []; + let start = -1; + let end = -1; + let i = 0; - for (var len = matchmask.length; i < len; i += 1) { - var match = matchmask[i]; + for (let len = matchmask.length; i < len; i += 1) { + let match = matchmask[i]; if (match && start === -1) { start = i; @@ -4025,16 +3975,16 @@ module.exports = function () { /*! no static exports found */ /***/ (function(module, exports) { -module.exports = function (pattern) { - var mask = {}; - var len = pattern.length; +module.exports = pattern => { + let mask = {}; + let len = pattern.length; - for (var i = 0; i < len; i += 1) { + for (let i = 0; i < len; i += 1) { mask[pattern.charAt(i)] = 0; } - for (var _i = 0; _i < len; _i += 1) { - mask[pattern.charAt(_i)] |= 1 << len - _i - 1; + for (let i = 0; i < len; i += 1) { + mask[pattern.charAt(i)] |= 1 << len - i - 1; } return mask; @@ -4049,18 +3999,17 @@ module.exports = function (pattern) { /*! no static exports found */ /***/ (function(module, exports) { -var SPECIAL_CHARS_REGEX = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g; +const SPECIAL_CHARS_REGEX = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g; -module.exports = function (text, pattern) { - var tokenSeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : / +/g; - var regex = new RegExp(pattern.replace(SPECIAL_CHARS_REGEX, '\\$&').replace(tokenSeparator, '|')); - var matches = text.match(regex); - var isMatch = !!matches; - var matchedIndices = []; +module.exports = (text, pattern, tokenSeparator = / +/g) => { + let regex = new RegExp(pattern.replace(SPECIAL_CHARS_REGEX, '\\$&').replace(tokenSeparator, '|')); + let matches = text.match(regex); + let isMatch = !!matches; + let matchedIndices = []; if (isMatch) { - for (var i = 0, matchesLen = matches.length; i < matchesLen; i += 1) { - var match = matches[i]; + for (let i = 0, matchesLen = matches.length; i < matchesLen; i += 1) { + let match = matches[i]; matchedIndices.push([text.indexOf(match), match.length - 1]); } } @@ -4068,8 +4017,8 @@ module.exports = function (text, pattern) { return { // TODO: revisit this score score: isMatch ? 0.5 : 1, - isMatch: isMatch, - matchedIndices: matchedIndices + isMatch, + matchedIndices }; }; @@ -4082,17 +4031,14 @@ module.exports = function (text, pattern) { /*! no static exports found */ /***/ (function(module, exports) { -module.exports = function (pattern, _ref) { - var _ref$errors = _ref.errors, - errors = _ref$errors === void 0 ? 0 : _ref$errors, - _ref$currentLocation = _ref.currentLocation, - currentLocation = _ref$currentLocation === void 0 ? 0 : _ref$currentLocation, - _ref$expectedLocation = _ref.expectedLocation, - expectedLocation = _ref$expectedLocation === void 0 ? 0 : _ref$expectedLocation, - _ref$distance = _ref.distance, - distance = _ref$distance === void 0 ? 100 : _ref$distance; - var accuracy = errors / pattern.length; - var proximity = Math.abs(expectedLocation - currentLocation); +module.exports = (pattern, { + errors = 0, + currentLocation = 0, + expectedLocation = 0, + distance = 100 +}) => { + const accuracy = errors / pattern.length; + const proximity = Math.abs(expectedLocation - currentLocation); if (!distance) { // Dodge divide by zero error. @@ -4111,82 +4057,77 @@ module.exports = function (pattern, _ref) { /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -var bitapScore = __webpack_require__(/*! ./bitap_score */ "./src/bitap/bitap_score.js"); +const bitapScore = __webpack_require__(/*! ./bitap_score */ "./src/bitap/bitap_score.js"); -var matchedIndices = __webpack_require__(/*! ./bitap_matched_indices */ "./src/bitap/bitap_matched_indices.js"); +const matchedIndices = __webpack_require__(/*! ./bitap_matched_indices */ "./src/bitap/bitap_matched_indices.js"); -module.exports = function (text, pattern, patternAlphabet, _ref) { - var _ref$location = _ref.location, - location = _ref$location === void 0 ? 0 : _ref$location, - _ref$distance = _ref.distance, - distance = _ref$distance === void 0 ? 100 : _ref$distance, - _ref$threshold = _ref.threshold, - threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold, - _ref$findAllMatches = _ref.findAllMatches, - findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches, - _ref$minMatchCharLeng = _ref.minMatchCharLength, - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng; - var expectedLocation = location; // Set starting location at beginning text and initialize the alphabet. +module.exports = (text, pattern, patternAlphabet, { + location = 0, + distance = 100, + threshold = 0.6, + findAllMatches = false, + minMatchCharLength = 1 +}) => { + const expectedLocation = location; // Set starting location at beginning text and initialize the alphabet. - var textLen = text.length; // Highest score beyond which we give up. + const textLen = text.length; // Highest score beyond which we give up. - var currentThreshold = threshold; // Is there a nearby exact match? (speedup) + let currentThreshold = threshold; // Is there a nearby exact match? (speedup) - var bestLocation = text.indexOf(pattern, expectedLocation); - var patternLen = pattern.length; // a mask of the matches + let bestLocation = text.indexOf(pattern, expectedLocation); + const patternLen = pattern.length; // a mask of the matches - var matchMask = []; + const matchMask = []; - for (var i = 0; i < textLen; i += 1) { + for (let i = 0; i < textLen; i += 1) { matchMask[i] = 0; } if (bestLocation !== -1) { - var score = bitapScore(pattern, { + let score = bitapScore(pattern, { errors: 0, currentLocation: bestLocation, - expectedLocation: expectedLocation, - distance: distance + expectedLocation, + distance }); currentThreshold = Math.min(score, currentThreshold); // What about in the other direction? (speed up) bestLocation = text.lastIndexOf(pattern, expectedLocation + patternLen); if (bestLocation !== -1) { - var _score = bitapScore(pattern, { + let score = bitapScore(pattern, { errors: 0, currentLocation: bestLocation, - expectedLocation: expectedLocation, - distance: distance + expectedLocation, + distance }); - - currentThreshold = Math.min(_score, currentThreshold); + currentThreshold = Math.min(score, currentThreshold); } } // Reset the best location bestLocation = -1; - var lastBitArr = []; - var finalScore = 1; - var binMax = patternLen + textLen; - var mask = 1 << patternLen - 1; + let lastBitArr = []; + let finalScore = 1; + let binMax = patternLen + textLen; + const mask = 1 << patternLen - 1; - for (var _i = 0; _i < patternLen; _i += 1) { + for (let i = 0; i < patternLen; i += 1) { // Scan for the best match; each iteration allows for one more error. // Run a binary search to determine how far from the match location we can stray // at this error level. - var binMin = 0; - var binMid = binMax; + let binMin = 0; + let binMid = binMax; while (binMin < binMid) { - var _score3 = bitapScore(pattern, { - errors: _i, + const score = bitapScore(pattern, { + errors: i, currentLocation: expectedLocation + binMid, - expectedLocation: expectedLocation, - distance: distance + expectedLocation, + distance }); - if (_score3 <= currentThreshold) { + if (score <= currentThreshold) { binMin = binMid; } else { binMax = binMid; @@ -4197,15 +4138,15 @@ module.exports = function (text, pattern, patternAlphabet, _ref) { binMax = binMid; - var start = Math.max(1, expectedLocation - binMid + 1); - var finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen; // Initialize the bit array + let start = Math.max(1, expectedLocation - binMid + 1); + let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen; // Initialize the bit array - var bitArr = Array(finish + 2); - bitArr[finish + 1] = (1 << _i) - 1; + let bitArr = Array(finish + 2); + bitArr[finish + 1] = (1 << i) - 1; - for (var j = finish; j >= start; j -= 1) { - var currentLocation = j - 1; - var charMatch = patternAlphabet[text.charAt(currentLocation)]; + for (let j = finish; j >= start; j -= 1) { + let currentLocation = j - 1; + let charMatch = patternAlphabet[text.charAt(currentLocation)]; if (charMatch) { matchMask[currentLocation] = 1; @@ -4214,16 +4155,16 @@ module.exports = function (text, pattern, patternAlphabet, _ref) { bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch; // Subsequent passes: fuzzy match - if (_i !== 0) { + if (i !== 0) { bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1]; } if (bitArr[j] & mask) { finalScore = bitapScore(pattern, { - errors: _i, - currentLocation: currentLocation, - expectedLocation: expectedLocation, - distance: distance + errors: i, + currentLocation, + expectedLocation, + distance }); // This match will almost certainly be better than any existing match. // But check anyway. @@ -4243,15 +4184,14 @@ module.exports = function (text, pattern, patternAlphabet, _ref) { } // No hope for a (better) match at greater error levels. - var _score2 = bitapScore(pattern, { - errors: _i + 1, + const score = bitapScore(pattern, { + errors: i + 1, currentLocation: expectedLocation, - expectedLocation: expectedLocation, - distance: distance + expectedLocation, + distance }); // console.log('score', score, finalScore) - - if (_score2 > currentThreshold) { + if (score > currentThreshold) { break; } @@ -4276,50 +4216,46 @@ module.exports = function (text, pattern, patternAlphabet, _ref) { /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +const bitapRegexSearch = __webpack_require__(/*! ./bitap_regex_search */ "./src/bitap/bitap_regex_search.js"); -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); } } +const bitapSearch = __webpack_require__(/*! ./bitap_search */ "./src/bitap/bitap_search.js"); -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var bitapRegexSearch = __webpack_require__(/*! ./bitap_regex_search */ "./src/bitap/bitap_regex_search.js"); - -var bitapSearch = __webpack_require__(/*! ./bitap_search */ "./src/bitap/bitap_search.js"); - -var patternAlphabet = __webpack_require__(/*! ./bitap_pattern_alphabet */ "./src/bitap/bitap_pattern_alphabet.js"); - -var Bitap = -/*#__PURE__*/ -function () { - function Bitap(pattern, _ref) { - var _ref$location = _ref.location, - location = _ref$location === void 0 ? 0 : _ref$location, - _ref$distance = _ref.distance, - distance = _ref$distance === void 0 ? 100 : _ref$distance, - _ref$threshold = _ref.threshold, - threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold, - _ref$maxPatternLength = _ref.maxPatternLength, - maxPatternLength = _ref$maxPatternLength === void 0 ? 32 : _ref$maxPatternLength, - _ref$isCaseSensitive = _ref.isCaseSensitive, - isCaseSensitive = _ref$isCaseSensitive === void 0 ? false : _ref$isCaseSensitive, - _ref$tokenSeparator = _ref.tokenSeparator, - tokenSeparator = _ref$tokenSeparator === void 0 ? / +/g : _ref$tokenSeparator, - _ref$findAllMatches = _ref.findAllMatches, - findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches, - _ref$minMatchCharLeng = _ref.minMatchCharLength, - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng; - - _classCallCheck(this, Bitap); +const patternAlphabet = __webpack_require__(/*! ./bitap_pattern_alphabet */ "./src/bitap/bitap_pattern_alphabet.js"); +class Bitap { + constructor(pattern, { + // Approximately where in the text is the pattern expected to be found? + location = 0, + // Determines how close the match must be to the fuzzy location (specified above). + // An exact letter match which is 'distance' characters away from the fuzzy location + // would score as a complete mismatch. A distance of '0' requires the match be at + // the exact location specified, a threshold of '1000' would require a perfect match + // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold. + distance = 100, + // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match + // (of both letters and location), a threshold of '1.0' would match anything. + threshold = 0.6, + // Machine word size + maxPatternLength = 32, + // Indicates whether comparisons should be case sensitive. + isCaseSensitive = false, + // Regex used to separate words when searching. Only applicable when `tokenize` is `true`. + tokenSeparator = / +/g, + // When true, the algorithm continues searching to the end of the input even if a perfect + // match is found before the end of the same input. + findAllMatches = false, + // Minimum number of characters that must be matched before a result is considered a match + minMatchCharLength = 1 + }) { this.options = { - location: location, - distance: distance, - threshold: threshold, - maxPatternLength: maxPatternLength, - isCaseSensitive: isCaseSensitive, - tokenSeparator: tokenSeparator, - findAllMatches: findAllMatches, - minMatchCharLength: minMatchCharLength + location, + distance, + threshold, + maxPatternLength, + isCaseSensitive, + tokenSeparator, + findAllMatches, + minMatchCharLength }; this.pattern = this.options.isCaseSensitive ? pattern : pattern.toLowerCase(); @@ -4328,50 +4264,48 @@ function () { } } - _createClass(Bitap, [{ - key: "search", - value: function search(text) { - if (!this.options.isCaseSensitive) { - text = text.toLowerCase(); - } // Exact match + search(text) { + if (!this.options.isCaseSensitive) { + text = text.toLowerCase(); + } // Exact match - if (this.pattern === text) { - return { - isMatch: true, - score: 0, - matchedIndices: [[0, text.length - 1]] - }; - } // When pattern length is greater than the machine word length, just do a a regex comparison + if (this.pattern === text) { + return { + isMatch: true, + score: 0, + matchedIndices: [[0, text.length - 1]] + }; + } // When pattern length is greater than the machine word length, just do a a regex comparison - var _this$options = this.options, - maxPatternLength = _this$options.maxPatternLength, - tokenSeparator = _this$options.tokenSeparator; + const { + maxPatternLength, + tokenSeparator + } = this.options; - if (this.pattern.length > maxPatternLength) { - return bitapRegexSearch(text, this.pattern, tokenSeparator); - } // Otherwise, use Bitap algorithm + if (this.pattern.length > maxPatternLength) { + return bitapRegexSearch(text, this.pattern, tokenSeparator); + } // Otherwise, use Bitap algorithm - var _this$options2 = this.options, - location = _this$options2.location, - distance = _this$options2.distance, - threshold = _this$options2.threshold, - findAllMatches = _this$options2.findAllMatches, - minMatchCharLength = _this$options2.minMatchCharLength; - return bitapSearch(text, this.pattern, this.patternAlphabet, { - location: location, - distance: distance, - threshold: threshold, - findAllMatches: findAllMatches, - minMatchCharLength: minMatchCharLength - }); - } - }]); + const { + location, + distance, + threshold, + findAllMatches, + minMatchCharLength + } = this.options; + return bitapSearch(text, this.pattern, this.patternAlphabet, { + location, + distance, + threshold, + findAllMatches, + minMatchCharLength + }); + } - return Bitap; -}(); // let x = new Bitap("od mn war", {}) +} // let x = new Bitap("od mn war", {}) // let result = x.search("Old Man's War") // console.log(result) @@ -4387,30 +4321,30 @@ module.exports = Bitap; /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -var isArray = __webpack_require__(/*! ./is_array */ "./src/helpers/is_array.js"); +const isArray = __webpack_require__(/*! ./is_array */ "./src/helpers/is_array.js"); -var deepValue = function deepValue(obj, path, list) { +const 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; + const dotIndex = path.indexOf('.'); + let firstSegment = path; + let remaining = null; if (dotIndex !== -1) { firstSegment = path.slice(0, dotIndex); remaining = path.slice(dotIndex + 1); } - var value = obj[firstSegment]; + const value = obj[firstSegment]; 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) { + for (let i = 0, len = value.length; i < len; i += 1) { deepValue(value[i], remaining, list); } } else if (remaining) { @@ -4423,7 +4357,7 @@ var deepValue = function deepValue(obj, path, list) { return list; }; -module.exports = function (obj, path) { +module.exports = (obj, path) => { return deepValue(obj, path, []); }; @@ -4436,9 +4370,7 @@ module.exports = function (obj, path) { /*! no static exports found */ /***/ (function(module, exports) { -module.exports = function (obj) { - return !Array.isArray ? Object.prototype.toString.call(obj) === '[object Array]' : Array.isArray(obj); -}; +module.exports = obj => !Array.isArray ? Object.prototype.toString.call(obj) === '[object Array]' : Array.isArray(obj); /***/ }), @@ -4449,502 +4381,476 @@ module.exports = function (obj) { /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } +const Bitap = __webpack_require__(/*! ./bitap */ "./src/bitap/index.js"); -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +const deepValue = __webpack_require__(/*! ./helpers/deep_value */ "./src/helpers/deep_value.js"); -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Bitap = __webpack_require__(/*! ./bitap */ "./src/bitap/index.js"); - -var deepValue = __webpack_require__(/*! ./helpers/deep_value */ "./src/helpers/deep_value.js"); - -var isArray = __webpack_require__(/*! ./helpers/is_array */ "./src/helpers/is_array.js"); - -var Fuse = -/*#__PURE__*/ -function () { - function Fuse(list, _ref) { - var _ref$location = _ref.location, - location = _ref$location === void 0 ? 0 : _ref$location, - _ref$distance = _ref.distance, - distance = _ref$distance === void 0 ? 100 : _ref$distance, - _ref$threshold = _ref.threshold, - threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold, - _ref$maxPatternLength = _ref.maxPatternLength, - maxPatternLength = _ref$maxPatternLength === void 0 ? 32 : _ref$maxPatternLength, - _ref$caseSensitive = _ref.caseSensitive, - caseSensitive = _ref$caseSensitive === void 0 ? false : _ref$caseSensitive, - _ref$tokenSeparator = _ref.tokenSeparator, - tokenSeparator = _ref$tokenSeparator === void 0 ? / +/g : _ref$tokenSeparator, - _ref$findAllMatches = _ref.findAllMatches, - findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches, - _ref$minMatchCharLeng = _ref.minMatchCharLength, - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng, - _ref$id = _ref.id, - id = _ref$id === void 0 ? null : _ref$id, - _ref$keys = _ref.keys, - keys = _ref$keys === void 0 ? [] : _ref$keys, - _ref$shouldSort = _ref.shouldSort, - shouldSort = _ref$shouldSort === void 0 ? true : _ref$shouldSort, - _ref$getFn = _ref.getFn, - getFn = _ref$getFn === void 0 ? deepValue : _ref$getFn, - _ref$sortFn = _ref.sortFn, - sortFn = _ref$sortFn === void 0 ? function (a, b) { - return a.score - b.score; - } : _ref$sortFn, - _ref$tokenize = _ref.tokenize, - tokenize = _ref$tokenize === void 0 ? false : _ref$tokenize, - _ref$matchAllTokens = _ref.matchAllTokens, - matchAllTokens = _ref$matchAllTokens === void 0 ? false : _ref$matchAllTokens, - _ref$includeMatches = _ref.includeMatches, - includeMatches = _ref$includeMatches === void 0 ? false : _ref$includeMatches, - _ref$includeScore = _ref.includeScore, - includeScore = _ref$includeScore === void 0 ? false : _ref$includeScore, - _ref$verbose = _ref.verbose, - verbose = _ref$verbose === void 0 ? false : _ref$verbose; - - _classCallCheck(this, Fuse); +const isArray = __webpack_require__(/*! ./helpers/is_array */ "./src/helpers/is_array.js"); +class Fuse { + constructor(list, { + // Approximately where in the text is the pattern expected to be found? + location = 0, + // Determines how close the match must be to the fuzzy location (specified above). + // An exact letter match which is 'distance' characters away from the fuzzy location + // would score as a complete mismatch. A distance of '0' requires the match be at + // the exact location specified, a threshold of '1000' would require a perfect match + // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold. + distance = 100, + // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match + // (of both letters and location), a threshold of '1.0' would match anything. + threshold = 0.6, + // Machine word size + maxPatternLength = 32, + // Indicates whether comparisons should be case sensitive. + caseSensitive = false, + // Regex used to separate words when searching. Only applicable when `tokenize` is `true`. + tokenSeparator = / +/g, + // When true, the algorithm continues searching to the end of the input even if a perfect + // match is found before the end of the same input. + findAllMatches = false, + // Minimum number of characters that must be matched before a result is considered a match + minMatchCharLength = 1, + // The name of the identifier property. If specified, the returned result will be a list + // of the items' dentifiers, otherwise it will be a list of the items. + id = null, + // List of properties that will be searched. This also supports nested properties. + keys = [], + // Whether to sort the result list, by score + shouldSort = true, + // The get function to use when fetching an object's properties. + // The default will search nested paths *ie foo.bar.baz* + getFn = deepValue, + // Default sort function + sortFn = (a, b) => a.score - b.score, + // When true, the search algorithm will search individual words **and** the full string, + // computing the final score as a function of both. Note that when `tokenize` is `true`, + // the `threshold`, `distance`, and `location` are inconsequential for individual tokens. + tokenize = false, + // When true, the result set will only include records that match all tokens. Will only work + // if `tokenize` is also true. + matchAllTokens = false, + includeMatches = false, + includeScore = false, + // Will print to the console. Useful for debugging. + verbose = false + }) { this.options = { - location: location, - distance: distance, - threshold: threshold, - maxPatternLength: maxPatternLength, + location, + distance, + threshold, + 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 + tokenSeparator, + findAllMatches, + minMatchCharLength, + id, + keys, + includeMatches, + includeScore, + shouldSort, + getFn, + sortFn, + verbose, + tokenize, + matchAllTokens }; this.setCollection(list); } - _createClass(Fuse, [{ - key: "setCollection", - value: function setCollection(list) { - this.list = list; - return list; + setCollection(list) { + this.list = list; + return list; + } + + search(pattern, opts = { + limit: false + }) { + this._log(`---------\nSearch pattern: "${pattern}"`); + + const { + tokenSearchers, + fullSearcher + } = this._prepareSearchers(pattern); + + let { + weights, + results + } = this._search(tokenSearchers, fullSearcher); + + this._computeScore(weights, results); + + if (this.options.shouldSort) { + this._sort(results); } - }, { - key: "search", - value: function search(pattern) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - limit: false + + if (opts.limit && typeof opts.limit === 'number') { + results = results.slice(0, opts.limit); + } + + return this._format(results); + } + + _prepareSearchers(pattern = '') { + const tokenSearchers = []; + + if (this.options.tokenize) { + // Tokenize on the separator + const tokens = pattern.split(this.options.tokenSeparator); + + for (let i = 0, len = tokens.length; i < len; i += 1) { + tokenSearchers.push(new Bitap(tokens[i], this.options)); + } + } + + let fullSearcher = new Bitap(pattern, this.options); + return { + tokenSearchers, + fullSearcher + }; + } + + _search(tokenSearchers = [], fullSearcher) { + const list = this.list; + const resultMap = {}; + const results = []; // Check the first item in the list, if it's a string, then we assume + // that every item in the list is also a string, and thus it's a flattened array. + + if (typeof list[0] === 'string') { + // Iterate over every item + for (let i = 0, len = list.length; i < len; i += 1) { + this._analyze({ + key: '', + value: list[i], + record: i, + index: i + }, { + resultMap, + results, + tokenSearchers, + fullSearcher + }); + } + + return { + weights: null, + results }; + } // Otherwise, the first item is an Object (hopefully), and thus the searching + // is done on the values of the keys of each item. - this._log("---------\nSearch pattern: \"".concat(pattern, "\"")); - var _this$_prepareSearche = this._prepareSearchers(pattern), - tokenSearchers = _this$_prepareSearche.tokenSearchers, - fullSearcher = _this$_prepareSearche.fullSearcher; + const weights = {}; - var _this$_search = this._search(tokenSearchers, fullSearcher), - weights = _this$_search.weights, - results = _this$_search.results; + for (let i = 0, len = list.length; i < len; i += 1) { + let item = list[i]; // Iterate over every key - this._computeScore(weights, results); + for (let j = 0, keysLen = this.options.keys.length; j < keysLen; j += 1) { + let key = this.options.keys[j]; - if (this.options.shouldSort) { - this._sort(results); + 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'); + } + + key = key.name; + } else { + weights[key] = { + weight: 1 + }; + } + + this._analyze({ + key, + value: this.options.getFn(item, key), + record: item, + index: i + }, { + resultMap, + results, + tokenSearchers, + fullSearcher + }); } - - if (opts.limit && typeof opts.limit === 'number') { - results = results.slice(0, opts.limit); - } - - return this._format(results); } + + return { + weights, + results + }; + } + + _analyze({ + key, + arrayIndex = -1, + value, + record, + index }, { - key: "_prepareSearchers", - value: function _prepareSearchers() { - var pattern = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - var tokenSearchers = []; + tokenSearchers = [], + fullSearcher = [], + resultMap = {}, + results = [] + }) { + // Check if the texvaluet can be searched + if (value === undefined || value === null) { + return; + } + + let exists = false; + let averageScore = -1; + let numTextMatches = 0; + + if (typeof value === 'string') { + this._log(`\nKey: ${key === '' ? '-' : key}`); + + let mainSearchResult = fullSearcher.search(value); + + this._log(`Full text: "${value}", score: ${mainSearchResult.score}`); if (this.options.tokenize) { - // Tokenize on the separator - var tokens = pattern.split(this.options.tokenSeparator); + let words = value.split(this.options.tokenSeparator); + let scores = []; - for (var i = 0, len = tokens.length; i < len; i += 1) { - tokenSearchers.push(new Bitap(tokens[i], this.options)); - } - } + for (let i = 0; i < tokenSearchers.length; i += 1) { + let tokenSearcher = tokenSearchers[i]; - var fullSearcher = new Bitap(pattern, this.options); - return { - tokenSearchers: tokenSearchers, - fullSearcher: fullSearcher - }; - } - }, { - key: "_search", - value: function _search() { - var tokenSearchers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - var fullSearcher = arguments.length > 1 ? arguments[1] : undefined; - var list = this.list; - var resultMap = {}; - var results = []; // Check the first item in the list, if it's a string, then we assume - // that every item in the list is also a string, and thus it's a flattened array. - - if (typeof list[0] === 'string') { - // Iterate over every item - for (var i = 0, len = list.length; i < len; i += 1) { - this._analyze({ - key: '', - value: list[i], - record: i, - index: i - }, { - resultMap: resultMap, - results: results, - tokenSearchers: tokenSearchers, - fullSearcher: fullSearcher - }); - } - - return { - weights: null, - results: results - }; - } // Otherwise, the first item is an Object (hopefully), and thus the searching - // is done on the values of the keys of each item. + this._log(`\nPattern: "${tokenSearcher.pattern}"`); // let tokenScores = [] - var weights = {}; + let hasMatchInText = false; - for (var _i = 0, _len = list.length; _i < _len; _i += 1) { - var item = list[_i]; // Iterate over every key + for (let j = 0; j < words.length; j += 1) { + let word = words[j]; + let tokenSearchResult = tokenSearcher.search(word); + let obj = {}; - for (var j = 0, keysLen = this.options.keys.length; j < keysLen; j += 1) { - var key = this.options.keys[j]; + if (tokenSearchResult.isMatch) { + obj[word] = tokenSearchResult.score; + exists = true; + hasMatchInText = true; + scores.push(tokenSearchResult.score); + } else { + obj[word] = 1; - 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'); - } - - key = key.name; - } else { - weights[key] = { - weight: 1 - }; - } - - this._analyze({ - key: key, - value: this.options.getFn(item, key), - record: item, - index: _i - }, { - resultMap: resultMap, - results: results, - tokenSearchers: tokenSearchers, - fullSearcher: fullSearcher - }); - } - } - - return { - weights: weights, - results: results - }; - } - }, { - key: "_analyze", - value: function _analyze(_ref2, _ref3) { - var key = _ref2.key, - _ref2$arrayIndex = _ref2.arrayIndex, - arrayIndex = _ref2$arrayIndex === void 0 ? -1 : _ref2$arrayIndex, - value = _ref2.value, - record = _ref2.record, - index = _ref2.index; - var _ref3$tokenSearchers = _ref3.tokenSearchers, - tokenSearchers = _ref3$tokenSearchers === void 0 ? [] : _ref3$tokenSearchers, - _ref3$fullSearcher = _ref3.fullSearcher, - fullSearcher = _ref3$fullSearcher === void 0 ? [] : _ref3$fullSearcher, - _ref3$resultMap = _ref3.resultMap, - resultMap = _ref3$resultMap === void 0 ? {} : _ref3$resultMap, - _ref3$results = _ref3.results, - results = _ref3$results === void 0 ? [] : _ref3$results; - - // Check if the texvaluet can be searched - if (value === undefined || value === null) { - return; - } - - var exists = false; - var averageScore = -1; - var numTextMatches = 0; - - if (typeof value === 'string') { - this._log("\nKey: ".concat(key === '' ? '-' : key)); - - var mainSearchResult = fullSearcher.search(value); - - this._log("Full text: \"".concat(value, "\", score: ").concat(mainSearchResult.score)); - - 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: \"".concat(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); - } + if (!this.options.matchAllTokens) { + scores.push(1); } - - this._log("Token: \"".concat(word, "\", score: ").concat(obj[word])); // tokenScores.push(obj) - } - if (hasMatchInText) { - numTextMatches += 1; - } + this._log(`Token: "${word}", score: ${obj[word]}`); // tokenScores.push(obj) + } - averageScore = scores[0]; - var scoresLen = scores.length; - - for (var _i2 = 1; _i2 < scoresLen; _i2 += 1) { - averageScore += scores[_i2]; + if (hasMatchInText) { + numTextMatches += 1; } - - averageScore = averageScore / scoresLen; - - this._log('Token score average:', averageScore); } - var finalScore = mainSearchResult.score; + averageScore = scores[0]; + let scoresLen = scores.length; - if (averageScore > -1) { - finalScore = (finalScore + averageScore) / 2; + for (let i = 1; i < scoresLen; i += 1) { + averageScore += scores[i]; } - this._log('Score average:', finalScore); + averageScore = averageScore / scoresLen; - var checkTextMatches = this.options.tokenize && this.options.matchAllTokens ? numTextMatches >= tokenSearchers.length : true; + this._log('Token score average:', averageScore); + } - this._log("\nCheck Matches: ".concat(checkTextMatches)); // If a match is found, add the item to , including its score + let finalScore = mainSearchResult.score; + + if (averageScore > -1) { + finalScore = (finalScore + averageScore) / 2; + } + + this._log('Score average:', finalScore); + + let checkTextMatches = this.options.tokenize && this.options.matchAllTokens ? numTextMatches >= tokenSearchers.length : true; + + this._log(`\nCheck Matches: ${checkTextMatches}`); // If a match is found, add the item to , including its score - if ((exists || mainSearchResult.isMatch) && checkTextMatches) { - // Check if the item already exists in our results - var existingResult = resultMap[index]; + if ((exists || mainSearchResult.isMatch) && checkTextMatches) { + // Check if the item already exists in our results + let existingResult = resultMap[index]; - if (existingResult) { - // Use the lowest score - // existingResult.score, bitapResult.score - existingResult.output.push({ - key: key, - arrayIndex: arrayIndex, - value: value, + if (existingResult) { + // Use the lowest score + // existingResult.score, bitapResult.score + existingResult.output.push({ + key, + arrayIndex, + value, + score: finalScore, + matchedIndices: mainSearchResult.matchedIndices + }); + } else { + // Add it to the raw result list + resultMap[index] = { + item: record, + output: [{ + key, + arrayIndex, + 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 - }] - }; - 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 - }); + }] + }; + results.push(resultMap[index]); } } - } - }, { - key: "_computeScore", - value: function _computeScore(weights, results) { - this._log('\n\nComputing score:\n'); - - for (var i = 0, len = results.length; i < len; i += 1) { - var output = results[i].output; - var scoreLen = output.length; - var currScore = 1; - var bestScore = 1; - - for (var j = 0; j < scoreLen; j += 1) { - var weight = weights ? weights[output[j].key].weight : 1; - var score = weight === 1 ? output[j].score : output[j].score || 0.001; - var nScore = score * weight; - - if (weight !== 1) { - bestScore = Math.min(bestScore, nScore); - } else { - output[j].nScore = nScore; - currScore *= nScore; - } - } - - results[i].score = bestScore === 1 ? currScore : bestScore; - - this._log(results[i]); - } - } - }, { - key: "_sort", - value: function _sort(results) { - this._log('\n\nSorting....'); - - results.sort(this.options.sortFn); - } - }, { - key: "_format", - value: function _format(results) { - var finalOutput = []; - - if (this.options.verbose) { - var cache = []; - - this._log('\n\nOutput:\n\n', JSON.stringify(results, function (key, value) { - if (_typeof(value) === 'object' && value !== null) { - if (cache.indexOf(value) !== -1) { - // Circular reference found, discard key - return; - } // Store value in our collection - - - cache.push(value); - } - - return value; - })); - - cache = null; - } - - var transformers = []; - - if (this.options.includeMatches) { - transformers.push(function (result, data) { - var output = result.output; - data.matches = []; - - for (var i = 0, len = output.length; i < len; i += 1) { - var item = output[i]; - - if (item.matchedIndices.length === 0) { - continue; - } - - 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); - } + } else if (isArray(value)) { + for (let i = 0, len = value.length; i < len; i += 1) { + this._analyze({ + key, + arrayIndex: i, + value: value[i], + record, + index + }, { + resultMap, + results, + tokenSearchers, + fullSearcher }); } - - if (this.options.includeScore) { - transformers.push(function (result, data) { - data.score = result.score; - }); - } - - for (var i = 0, len = results.length; i < len; i += 1) { - var result = results[i]; - - if (this.options.id) { - result.item = this.options.getFn(result.item, this.options.id)[0]; - } - - if (!transformers.length) { - finalOutput.push(result.item); - continue; - } - - var data = { - item: result.item - }; - - for (var j = 0, _len2 = transformers.length; j < _len2; j += 1) { - transformers[j](result, data); - } - - finalOutput.push(data); - } - - return finalOutput; } - }, { - key: "_log", - value: function _log() { - if (this.options.verbose) { - var _console; + } - (_console = console).log.apply(_console, arguments); + _computeScore(weights, results) { + this._log('\n\nComputing score:\n'); + + for (let i = 0, len = results.length; i < len; i += 1) { + const output = results[i].output; + const scoreLen = output.length; + let currScore = 1; + let bestScore = 1; + + for (let j = 0; j < scoreLen; j += 1) { + let weight = weights ? weights[output[j].key].weight : 1; + let score = weight === 1 ? output[j].score : output[j].score || 0.001; + let nScore = score * weight; + + if (weight !== 1) { + bestScore = Math.min(bestScore, nScore); + } else { + output[j].nScore = nScore; + currScore *= nScore; + } } - } - }]); - return Fuse; -}(); + results[i].score = bestScore === 1 ? currScore : bestScore; + + this._log(results[i]); + } + } + + _sort(results) { + this._log('\n\nSorting....'); + + results.sort(this.options.sortFn); + } + + _format(results) { + const finalOutput = []; + + if (this.options.verbose) { + let cache = []; + + this._log('\n\nOutput:\n\n', JSON.stringify(results, function (key, value) { + if (typeof value === 'object' && value !== null) { + if (cache.indexOf(value) !== -1) { + // Circular reference found, discard key + return; + } // Store value in our collection + + + cache.push(value); + } + + return value; + })); + + cache = null; + } + + let transformers = []; + + if (this.options.includeMatches) { + transformers.push((result, data) => { + const output = result.output; + data.matches = []; + + for (let i = 0, len = output.length; i < len; i += 1) { + let item = output[i]; + + if (item.matchedIndices.length === 0) { + continue; + } + + let 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); + } + }); + } + + if (this.options.includeScore) { + transformers.push((result, data) => { + data.score = result.score; + }); + } + + for (let i = 0, len = results.length; i < len; i += 1) { + const result = results[i]; + + if (this.options.id) { + result.item = this.options.getFn(result.item, this.options.id)[0]; + } + + if (!transformers.length) { + finalOutput.push(result.item); + continue; + } + + const data = { + item: result.item + }; + + for (let j = 0, len = transformers.length; j < len; j += 1) { + transformers[j](result, data); + } + + finalOutput.push(data); + } + + return finalOutput; + } + + _log() { + if (this.options.verbose) { + console.log(...arguments); + } + } + +} module.exports = Fuse; @@ -6157,8 +6063,7 @@ function () { this.element = element; this.classNames = classNames; this.isFocussed = this.element === document.activeElement; - this.isDisabled = false; // Bind event listeners - + this.isDisabled = false; this._onPaste = this._onPaste.bind(this); this._onInput = this._onInput.bind(this); this._onFocus = this._onFocus.bind(this); @@ -6289,7 +6194,7 @@ function () { }, { key: "_onPaste", value: function _onPaste(event) { - var target = event.target; // Disable pasting into the input if option has been set + var target = event.target; if (target === this.element && this.preventPaste) { event.preventDefault(); @@ -6313,10 +6218,10 @@ function () { }, { key: "value", set: function set(value) { - this.element.value = "".concat(value); + this.element.value = value; }, get: function get() { - return (0, _utils.stripHTML)(this.element.value); + return (0, _utils.sanitise)(this.element.value); } }]); @@ -6466,8 +6371,6 @@ exports.default = void 0; var _wrappedElement = _interopRequireDefault(__webpack_require__(4)); -var _utils = __webpack_require__(0); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -6517,10 +6420,13 @@ function (_WrappedElement) { _createClass(WrappedInput, [{ key: "value", set: function set(items) { - var itemsFiltered = (0, _utils.reduceToValues)(items); - var itemsFilteredString = itemsFiltered.join(this.delimiter); - this.element.setAttribute('value', itemsFilteredString); - this.element.value = itemsFilteredString; + var itemValues = items.map(function (_ref2) { + var value = _ref2.value; + return value; + }); + var joinedValues = itemValues.join(this.delimiter); + this.element.setAttribute('value', joinedValues); + this.element.value = joinedValues; } // @todo figure out why we need this? Perhaps a babel issue , get: function get() { diff --git a/public/assets/scripts/choices.min.js b/public/assets/scripts/choices.min.js index 30fa2a6..a9488c0 100644 --- a/public/assets/scripts/choices.min.js +++ b/public/assets/scripts/choices.min.js @@ -1,50 +1,50 @@ -/*! choices.js v6.0.1 | (c) 2019 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Choices=t():e.Choices=t()}(window,function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/public/assets/scripts/",n(n.s=9)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.diff=t.cloneObject=t.existsInArray=t.isIE11=t.fetchFromObject=t.reduceToValues=t.getWindowHeight=t.dispatchEvent=t.sortByScore=t.sortByAlpha=t.calcWidthOfInput=t.strToEl=t.stripHTML=t.isScrolledIntoView=t.getAdjacentEl=t.findAncestorByAttrName=t.findAncestor=t.wrap=t.extend=t.isElement=t.isType=t.getType=t.generateId=t.generateChars=t.getRandomNumber=void 0;var i=function(e,t){return Math.floor(Math.random()*(t-e)+e)};t.getRandomNumber=i;var r=function(e){for(var t="",n=0;n2&&void 0!==arguments[2]?arguments[2]:1;if(e&&t){var i=e.parentNode.parentNode,r=Array.from(i.querySelectorAll(t)),o=r.indexOf(e);return r[o+(n>0?1:-1)]}};t.isScrolledIntoView=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;if(e)return n>0?t.scrollTop+t.offsetHeight>=e.offsetTop+e.offsetHeight:e.offsetTop>=t.scrollTop};var a=function(e){return e.replace(/&/g,"&").replace(/>/g,"&rt;").replace(/".concat(a(n),""));if(r.style.position="absolute",r.style.padding="0",r.style.top="-9999px",r.style.left="-9999px",r.style.width="auto",r.style.whiteSpace="pre",document.body.contains(e)&&window.getComputedStyle){var o=window.getComputedStyle(e);o&&(r.style.fontSize=o.fontSize,r.style.fontFamily=o.fontFamily,r.style.fontWeight=o.fontWeight,r.style.fontStyle=o.fontStyle,r.style.letterSpacing=o.letterSpacing,r.style.textTransform=o.textTransform,r.style.padding=o.padding)}document.body.appendChild(r),requestAnimationFrame(function(){n&&r.offsetWidth!==e.offsetWidth&&(i=r.offsetWidth+4),document.body.removeChild(r),t.call(void 0,"".concat(i,"px"))})}else t.call(void 0,"".concat(i,"px"))};t.sortByAlpha=function(e,t){var n=(e.label||e.value).toLowerCase(),i=(t.label||t.value).toLowerCase();return ni?1:0};t.sortByScore=function(e,t){return e.score-t.score};t.dispatchEvent=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=new CustomEvent(t,{detail:n,bubbles:!0,cancelable:!0});return e.dispatchEvent(i)};t.getWindowHeight=function(){var e=document.body,t=document.documentElement;return Math.max(e.scrollHeight,e.offsetHeight,t.clientHeight,t.scrollHeight,t.offsetHeight)};t.reduceToValues=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"value";return e.reduce(function(e,n){return e.push(n[t]),e},[])};t.fetchFromObject=function e(t,n){var i=n.indexOf(".");return i>-1?e(t[n.substring(0,i)],n.substr(i+1)):t[n]};t.isIE11=function(){return!(!navigator.userAgent.match(/Trident/)||!navigator.userAgent.match(/rv[ :]11/))};t.existsInArray=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"value";return e.some(function(e){return s("String",t)?e[n]===t.trim():e[n]===t})};t.cloneObject=function(e){return JSON.parse(JSON.stringify(e))};t.diff=function(e,t){var n=Object.keys(e).sort(),i=Object.keys(t).sort();return n.filter(function(e){return i.indexOf(e)<0})}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SCROLLING_SPEED=t.KEY_CODES=t.ACTION_TYPES=t.EVENTS=t.DEFAULT_CONFIG=t.DEFAULT_CLASSNAMES=void 0;var i=n(0),r={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"};t.DEFAULT_CLASSNAMES=r;var o={items:[],choices:[],silent:!1,renderChoiceLimit:-1,maxItemCount:-1,addItems:!0,addItemFilterFn:null,removeItems:!0,removeItemButton:!1,editItems:!1,duplicateItemsAllowed:!0,delimiter:",",paste:!0,searchEnabled:!0,searchChoices:!0,searchFloor:1,searchResultLimit:4,searchFields:["label","value"],position:"auto",resetScrollPosition:!0,shouldSort:!0,shouldSortItems:!1,sortFn:i.sortByAlpha,placeholder:!0,placeholderValue:null,searchPlaceholderValue:null,prependValue:null,appendValue:null,renderSelectedChoices:"auto",loadingText:"Loading...",noResultsText:"No results found",noChoicesText:"No choices to choose from",itemSelectText:"Press to select",uniqueItemText:"Only unique values can be added",customAddItemText:"Only values matching specific conditions can be added",addItemText:function(e){return'Press Enter to add "'.concat((0,i.stripHTML)(e),'"')},maxItemText:function(e){return"Only ".concat(e," values can be added")},itemComparer:function(e,t){return e===t},fuseOptions:{includeScore:!0},callbackOnInit:null,callbackOnCreateTemplates:null,classNames:r};t.DEFAULT_CONFIG=o;t.EVENTS={showDropdown:"showDropdown",hideDropdown:"hideDropdown",change:"change",choice:"choice",search:"search",addItem:"addItem",removeItem:"removeItem",highlightItem:"highlightItem",highlightChoice:"highlightChoice"};t.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"};t.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};t.SCROLLING_SPEED=4},function(e,t,n){"use strict";(function(e,i){var r,o=n(7);r="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==e?e:i;var s=Object(o.a)(r);t.a=s}).call(this,n(3),n(16)(e))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=n(0);function r(e,t){for(var n=0;n