react-url-query
Version:
A library for managing state through query parameters in the URL in React. Works well with or without Redux and React Router.
1,611 lines (1,285 loc) • 99.8 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object')
exports["react-url-query"] = factory(require("react"));
else
root["react-url-query"] = factory(root[undefined]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_15__) {
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] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = 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;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.subqueryOmit = exports.subquery = exports.urlQueryReducer = exports.urlQueryMiddleware = exports.urlMultiPushInAction = exports.urlMultiReplaceInAction = exports.urlPushInAction = exports.urlReplaceInAction = exports.urlPushAction = exports.urlReplaceAction = exports.urlAction = exports.multiPushInUrlQueryFromAction = exports.pushUrlQueryFromAction = exports.pushInUrlQueryFromAction = exports.multiReplaceInUrlQueryFromAction = exports.replaceUrlQueryFromAction = exports.replaceInUrlQueryFromAction = exports.RouterToUrlQuery = exports.addUrlProps = exports.UrlUpdateTypes = exports.UrlQueryParamTypes = exports.urlQueryEncoder = exports.urlQueryDecoder = exports.multiPushInUrlQuery = exports.multiReplaceInUrlQuery = exports.pushUrlQuery = exports.pushInUrlQuery = exports.replaceUrlQuery = exports.replaceInUrlQuery = exports.decode = exports.encode = exports.Serialize = exports.configureUrlQuery = undefined;
var _serialize = __webpack_require__(2);
Object.defineProperty(exports, 'encode', {
enumerable: true,
get: function get() {
return _serialize.encode;
}
});
Object.defineProperty(exports, 'decode', {
enumerable: true,
get: function get() {
return _serialize.decode;
}
});
var _updateUrlQuery = __webpack_require__(4);
Object.defineProperty(exports, 'replaceInUrlQuery', {
enumerable: true,
get: function get() {
return _updateUrlQuery.replaceInUrlQuery;
}
});
Object.defineProperty(exports, 'replaceUrlQuery', {
enumerable: true,
get: function get() {
return _updateUrlQuery.replaceUrlQuery;
}
});
Object.defineProperty(exports, 'pushInUrlQuery', {
enumerable: true,
get: function get() {
return _updateUrlQuery.pushInUrlQuery;
}
});
Object.defineProperty(exports, 'pushUrlQuery', {
enumerable: true,
get: function get() {
return _updateUrlQuery.pushUrlQuery;
}
});
Object.defineProperty(exports, 'multiReplaceInUrlQuery', {
enumerable: true,
get: function get() {
return _updateUrlQuery.multiReplaceInUrlQuery;
}
});
Object.defineProperty(exports, 'multiPushInUrlQuery', {
enumerable: true,
get: function get() {
return _updateUrlQuery.multiPushInUrlQuery;
}
});
var _updateUrlQueryFromAction = __webpack_require__(6);
Object.defineProperty(exports, 'replaceInUrlQueryFromAction', {
enumerable: true,
get: function get() {
return _updateUrlQueryFromAction.replaceInUrlQueryFromAction;
}
});
Object.defineProperty(exports, 'replaceUrlQueryFromAction', {
enumerable: true,
get: function get() {
return _updateUrlQueryFromAction.replaceUrlQueryFromAction;
}
});
Object.defineProperty(exports, 'multiReplaceInUrlQueryFromAction', {
enumerable: true,
get: function get() {
return _updateUrlQueryFromAction.multiReplaceInUrlQueryFromAction;
}
});
Object.defineProperty(exports, 'pushInUrlQueryFromAction', {
enumerable: true,
get: function get() {
return _updateUrlQueryFromAction.pushInUrlQueryFromAction;
}
});
Object.defineProperty(exports, 'pushUrlQueryFromAction', {
enumerable: true,
get: function get() {
return _updateUrlQueryFromAction.pushUrlQueryFromAction;
}
});
Object.defineProperty(exports, 'multiPushInUrlQueryFromAction', {
enumerable: true,
get: function get() {
return _updateUrlQueryFromAction.multiPushInUrlQueryFromAction;
}
});
var _urlAction2 = __webpack_require__(19);
Object.defineProperty(exports, 'urlReplaceAction', {
enumerable: true,
get: function get() {
return _urlAction2.urlReplaceAction;
}
});
Object.defineProperty(exports, 'urlPushAction', {
enumerable: true,
get: function get() {
return _urlAction2.urlPushAction;
}
});
Object.defineProperty(exports, 'urlReplaceInAction', {
enumerable: true,
get: function get() {
return _urlAction2.urlReplaceInAction;
}
});
Object.defineProperty(exports, 'urlPushInAction', {
enumerable: true,
get: function get() {
return _urlAction2.urlPushInAction;
}
});
Object.defineProperty(exports, 'urlMultiReplaceInAction', {
enumerable: true,
get: function get() {
return _urlAction2.urlMultiReplaceInAction;
}
});
Object.defineProperty(exports, 'urlMultiPushInAction', {
enumerable: true,
get: function get() {
return _urlAction2.urlMultiPushInAction;
}
});
var _configureUrlQuery2 = __webpack_require__(5);
var _configureUrlQuery3 = _interopRequireDefault(_configureUrlQuery2);
var _Serialize = _interopRequireWildcard(_serialize);
var _urlQueryDecoder2 = __webpack_require__(8);
var _urlQueryDecoder3 = _interopRequireDefault(_urlQueryDecoder2);
var _urlQueryEncoder2 = __webpack_require__(21);
var _urlQueryEncoder3 = _interopRequireDefault(_urlQueryEncoder2);
var _UrlQueryParamTypes2 = __webpack_require__(16);
var _UrlQueryParamTypes3 = _interopRequireDefault(_UrlQueryParamTypes2);
var _UrlUpdateTypes2 = __webpack_require__(1);
var _UrlUpdateTypes3 = _interopRequireDefault(_UrlUpdateTypes2);
var _addUrlProps2 = __webpack_require__(18);
var _addUrlProps3 = _interopRequireDefault(_addUrlProps2);
var _RouterToUrlQuery2 = __webpack_require__(17);
var _RouterToUrlQuery3 = _interopRequireDefault(_RouterToUrlQuery2);
var _urlAction3 = _interopRequireDefault(_urlAction2);
var _urlQueryMiddleware2 = __webpack_require__(20);
var _urlQueryMiddleware3 = _interopRequireDefault(_urlQueryMiddleware2);
var _urlQueryReducer2 = __webpack_require__(7);
var _urlQueryReducer3 = _interopRequireDefault(_urlQueryReducer2);
var _subquery2 = __webpack_require__(22);
var _subquery3 = _interopRequireDefault(_subquery2);
var _subqueryOmit2 = __webpack_require__(23);
var _subqueryOmit3 = _interopRequireDefault(_subqueryOmit2);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.configureUrlQuery = _configureUrlQuery3.default;
exports.Serialize = _Serialize;
exports.urlQueryDecoder = _urlQueryDecoder3.default;
exports.urlQueryEncoder = _urlQueryEncoder3.default;
exports.UrlQueryParamTypes = _UrlQueryParamTypes3.default;
exports.UrlUpdateTypes = _UrlUpdateTypes3.default;
/** React */
exports.addUrlProps = _addUrlProps3.default;
exports.RouterToUrlQuery = _RouterToUrlQuery3.default;
/** Redux */
exports.urlAction = _urlAction3.default;
exports.urlQueryMiddleware = _urlQueryMiddleware3.default;
exports.urlQueryReducer = _urlQueryReducer3.default;
/** Utils */
exports.subquery = _subquery3.default;
exports.subqueryOmit = _subqueryOmit3.default;
/***/ },
/* 1 */
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
var UrlUpdateTypes = {
replace: 'replace',
replaceIn: 'replaceIn',
multiReplaceIn: 'multiReplaceIn',
push: 'push',
pushIn: 'pushIn',
multiPushIn: 'multiPushIn'
};
exports.default = UrlUpdateTypes;
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.Encoders = exports.Decoders = exports.encodeNumericObject = exports.encodeNumericArray = undefined;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.encodeDate = encodeDate;
exports.decodeDate = decodeDate;
exports.encodeBoolean = encodeBoolean;
exports.decodeBoolean = decodeBoolean;
exports.encodeNumber = encodeNumber;
exports.decodeNumber = decodeNumber;
exports.encodeString = encodeString;
exports.decodeString = decodeString;
exports.encodeJson = encodeJson;
exports.decodeJson = decodeJson;
exports.encodeArray = encodeArray;
exports.decodeArray = decodeArray;
exports.decodeNumericArray = decodeNumericArray;
exports.encodeObject = encodeObject;
exports.decodeObject = decodeObject;
exports.decodeNumericObject = decodeNumericObject;
exports.decode = decode;
exports.encode = encode;
var _urlQueryConfig = __webpack_require__(3);
var _urlQueryConfig2 = _interopRequireDefault(_urlQueryConfig);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); } } /**
* Functions for encoding and decoding values as strings.
*/
/**
* Encodes a date as a string in YYYY-MM-DD format.
*
* @param {Date} date
* @return {String} the encoded date
*/
function encodeDate(date) {
if (date == null) {
return date;
}
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
}
/**
* Converts a date in the format 'YYYY-mm-dd...' into a proper date, because
* new Date() does not do that correctly. The date can be as complete or incomplete
* as necessary (aka, '2015', '2015-10', '2015-10-01').
* It will not work for dates that have times included in them.
*
* @param {String} dateString String date form like '2015-10-01'
* @return {Date} parsed date
*/
function decodeDate(dateString) {
if (dateString == null || !dateString.length) {
return undefined;
}
var parts = dateString.split('-');
// may only be a year so won't even have a month
if (parts[1] != null) {
parts[1] -= 1; // Note: months are 0-based
} else {
// just a year, set the month and day to the first
parts[1] = 0;
parts[2] = 1;
}
var decoded = new (Function.prototype.bind.apply(Date, [null].concat(_toConsumableArray(parts))))();
if (isNaN(decoded.getTime())) {
return undefined;
}
return decoded;
}
/**
* Encodes a boolean as a string. true -> "1", false -> "0".
*
* @param {Boolean} bool
* @return {String} the encoded boolean
*/
function encodeBoolean(bool) {
if (bool === undefined) {
return undefined;
}
return bool ? '1' : '0';
}
/**
* Decodes a boolean from a string. "1" -> true, "0" -> false.
* Everything else maps to undefined.
*
* @param {String} boolStr the encoded boolean string
* @return {Boolean} the boolean value
*/
function decodeBoolean(boolStr) {
if (boolStr === '1') {
return true;
} else if (boolStr === '0') {
return false;
}
return undefined;
}
/**
* Encodes a number as a string.
*
* @param {Number} num
* @return {String} the encoded number
*/
function encodeNumber(num) {
if (num == null) {
return undefined;
}
return String(num);
}
/**
* Decodes a number from a string via parseFloat. If the number is invalid,
* it returns undefined.
*
* @param {String} numStr the encoded number string
* @return {Number} the number value
*/
function decodeNumber(numStr) {
if (numStr == null) {
return undefined;
}
var result = parseFloat(numStr);
if (isNaN(result)) {
return undefined;
}
return result;
}
/**
* Encodes a string while safely handling null and undefined values.
*
* @param {String} string
* @return {String} the encoded string
*/
function encodeString(str) {
if (str == null) {
return undefined;
}
return String(str);
}
/**
* Decodes a string while safely handling null and undefined values.
*
* @param {String} str the encoded string
* @return {String} the string value
*/
function decodeString(str) {
if (str == null) {
return undefined;
}
return String(str);
}
/**
* Encodes anything as a JSON string.
*
* @param {Any} any The thing to be encoded
* @return {String} The JSON string representation of any
*/
function encodeJson(any) {
if (any == null) {
return undefined;
}
return JSON.stringify(any);
}
/**
* Decodes a JSON string into javascript
*
* @param {String} jsonStr The JSON string representation
* @return {Any} The javascript representation
*/
function decodeJson(jsonStr) {
if (!jsonStr) {
return undefined;
}
var result = void 0;
try {
result = JSON.parse(jsonStr);
} catch (e) {
/* ignore errors, returning undefined */
}
return result;
}
/**
* Encodes an array as a JSON string.
*
* @param {Array} array The array to be encoded
* @return {String} The JSON string representation of array
*/
function encodeArray(array) {
var entrySeparator = arguments.length <= 1 || arguments[1] === undefined ? _urlQueryConfig2.default.entrySeparator : arguments[1];
if (!array) {
return undefined;
}
return array.join(entrySeparator);
}
/**
* Decodes a JSON string into javascript array
*
* @param {String} jsonStr The JSON string representation
* @return {Array} The javascript representation
*/
function decodeArray(arrayStr) {
var entrySeparator = arguments.length <= 1 || arguments[1] === undefined ? _urlQueryConfig2.default.entrySeparator : arguments[1];
if (!arrayStr) {
return undefined;
}
return arrayStr.split(entrySeparator).map(function (item) {
return item === '' ? undefined : item;
});
}
/**
* Encodes a numeric array as a JSON string. (alias of encodeArray)
*
* @param {Array} array The array to be encoded
* @return {String} The JSON string representation of array
*/
var encodeNumericArray = exports.encodeNumericArray = encodeArray;
/**
* Decodes a JSON string into javascript array where all entries are numbers
*
* @param {String} jsonStr The JSON string representation
* @return {Array} The javascript representation
*/
function decodeNumericArray(arrayStr) {
var entrySeparator = arguments.length <= 1 || arguments[1] === undefined ? _urlQueryConfig2.default.entrySeparator : arguments[1];
var decoded = decodeArray(arrayStr, entrySeparator);
if (!decoded) {
return undefined;
}
return decoded.map(function (d) {
return d == null ? d : +d;
});
}
/**
* Encode simple objects as readable strings. Currently works only for simple,
* flat objects where values are numbers, booleans or strings.
*
* For example { foo: bar, boo: baz } -> "foo-bar_boo-baz"
*
* @param {Object} object The object to encode
* @param {String} keyValSeparator="-" The separator between keys and values
* @param {String} entrySeparator="_" The separator between entries
* @return {String} The encoded object
*/
function encodeObject(obj) {
var keyValSeparator = arguments.length <= 1 || arguments[1] === undefined ? _urlQueryConfig2.default.keyValSeparator : arguments[1];
var entrySeparator = arguments.length <= 2 || arguments[2] === undefined ? _urlQueryConfig2.default.entrySeparator : arguments[2];
if (!obj || !Object.keys(obj).length) {
return undefined;
}
return Object.keys(obj).map(function (key) {
return '' + key + keyValSeparator + obj[key];
}).join(entrySeparator);
}
/**
* Decodes a simple object to javascript. Currently works only for simple,
* flat objects where values are numbers, booleans or strings.
*
* For example "foo-bar_boo-baz" -> { foo: bar, boo: baz }
*
* @param {String} objStr The object string to decode
* @param {String} keyValSeparator="-" The separator between keys and values
* @param {String} entrySeparator="_" The separator between entries
* @return {Object} The javascript object
*/
function decodeObject(objStr) {
var keyValSeparator = arguments.length <= 1 || arguments[1] === undefined ? _urlQueryConfig2.default.keyValSeparator : arguments[1];
var entrySeparator = arguments.length <= 2 || arguments[2] === undefined ? _urlQueryConfig2.default.entrySeparator : arguments[2];
if (!objStr || !objStr.length) {
return undefined;
}
var obj = {};
objStr.split(entrySeparator).forEach(function (entryStr) {
var _entryStr$split = entryStr.split(keyValSeparator);
var _entryStr$split2 = _slicedToArray(_entryStr$split, 2);
var key = _entryStr$split2[0];
var value = _entryStr$split2[1];
obj[key] = value;
});
return obj;
}
/**
* Encode simple objects as readable strings. Alias of encodeObject.
*
* For example { foo: 123, boo: 521 } -> "foo-123_boo-521"
*
* @param {Object} object The object to encode
* @param {String} keyValSeparator="-" The separator between keys and values
* @param {String} entrySeparator="_" The separator between entries
* @return {String} The encoded object
*/
var encodeNumericObject = exports.encodeNumericObject = encodeObject;
/**
* Decodes a simple object to javascript where all values are numbers.
* Currently works only for simple, flat objects.
*
* For example "foo-123_boo-521" -> { foo: 123, boo: 521 }
*
* @param {String} objStr The object string to decode
* @param {String} keyValSeparator="-" The separator between keys and values
* @param {String} entrySeparator="_" The separator between entries
* @return {Object} The javascript object
*/
function decodeNumericObject(objStr) {
var keyValSeparator = arguments.length <= 1 || arguments[1] === undefined ? _urlQueryConfig2.default.keyValSeparator : arguments[1];
var entrySeparator = arguments.length <= 2 || arguments[2] === undefined ? _urlQueryConfig2.default.entrySeparator : arguments[2];
var decoded = decodeObject(objStr, keyValSeparator, entrySeparator);
if (!decoded) {
return undefined;
}
// convert to numbers
Object.keys(decoded).forEach(function (key) {
decoded[key] = decoded[key] == null ? decoded[key] : +decoded[key];
});
return decoded;
}
/**
* Collection of Decoders by type
*/
var Decoders = exports.Decoders = {
number: decodeNumber,
string: decodeString,
object: decodeObject,
array: decodeArray,
json: decodeJson,
date: decodeDate,
boolean: decodeBoolean,
numericObject: decodeNumericObject,
numericArray: decodeNumericArray
};
/**
* Generic decode function that takes a type as an argument.
*
* @param {String|Function} type If a function, it is used to decode, otherwise the string is
* the key for the decoder in the Decoders collection.
* @param {String} encodedValue the value to decode
* @param {Any} defaultValue The default value to use if encodedValue is undefined.
* @return {Any} The decoded value
*/
function decode(type, encodedValue, defaultValue) {
var decodedValue = void 0;
if (typeof type === 'function') {
decodedValue = type(encodedValue, defaultValue);
} else if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) === 'object' && type.decode) {
decodedValue = type.decode(encodedValue, defaultValue);
} else if (encodedValue === undefined) {
decodedValue = defaultValue;
} else if (Decoders[type]) {
decodedValue = Decoders[type](encodedValue);
} else {
decodedValue = encodedValue;
}
return decodedValue;
}
/**
* Collection of Encoders by type
*/
var Encoders = exports.Encoders = {
number: encodeNumber,
string: encodeString,
object: encodeObject,
array: encodeArray,
json: encodeJson,
date: encodeDate,
boolean: encodeBoolean,
numericObject: encodeNumericObject,
numericArray: encodeNumericArray
};
/**
* Generic encode function that takes a type as an argument.
*
* @param {String|Function} type If a function, it is used to encode, otherwise the string is
* the key for the encoder in the Encoders collection.
* @param {String} decodedValue the value to encode
* @return {Any} The encoded value
*/
function encode(type, decodedValue) {
var encodedValue = void 0;
if (typeof type === 'function') {
encodedValue = type(decodedValue);
} else if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) === 'object' && type.encode) {
encodedValue = type.encode(decodedValue);
} else if (Encoders[type]) {
encodedValue = Encoders[type](decodedValue);
} else {
encodedValue = decodedValue;
}
return encodedValue;
}
/***/ },
/* 3 */
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
// function to create the singleton options object that can be shared
// throughout an application
function createUrlQueryConfig() {
// default options
return {
// add in generated URL change handlers based on a urlPropsQueryConfig if provided
addUrlChangeHandlers: true,
// add in `props.params` from react-router to the url object
addRouterParams: true,
// function to specify change handler name (onChange<PropName>)
changeHandlerName: function changeHandlerName(propName) {
return 'onChange' + propName[0].toUpperCase() + propName.substring(1);
},
// use this history if no history is specified
history: {
push: function push() {
// eslint-disable-next-line
console.error('No history provided to react-url-query. Please provide one via configureUrlQuery.');
},
replace: function replace() {
// eslint-disable-next-line
console.error('No history provided to react-url-query. Please provide one via configureUrlQuery.');
}
},
// reads in location from react-router-redux if available and passes it
// to the reducer in the urlQueryMiddleware
readLocationFromStore: function readLocationFromStore(state) {
if (state && state.routing) {
return state.routing.locationBeforeTransitions;
}
return undefined;
},
/**
* The separator between entries
* @default {String} "_"
*/
entrySeparator: '_',
/**
* The separator between keys and values
* @default {String} "-"
*/
keyValSeparator: '-'
};
}
exports.default = createUrlQueryConfig();
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
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; };
exports.replaceUrlQuery = replaceUrlQuery;
exports.pushUrlQuery = pushUrlQuery;
exports.replaceInUrlQuery = replaceInUrlQuery;
exports.pushInUrlQuery = pushInUrlQuery;
exports.multiReplaceInUrlQuery = multiReplaceInUrlQuery;
exports.multiPushInUrlQuery = multiPushInUrlQuery;
exports.updateUrlQuerySingle = updateUrlQuerySingle;
exports.updateUrlQueryMulti = updateUrlQueryMulti;
var _queryString = __webpack_require__(14);
var _urlQueryConfig = __webpack_require__(3);
var _urlQueryConfig2 = _interopRequireDefault(_urlQueryConfig);
var _UrlUpdateTypes = __webpack_require__(1);
var _UrlUpdateTypes2 = _interopRequireDefault(_UrlUpdateTypes);
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; }
function getLocation(location) {
if (location) {
return location;
}
// if no location provided, check history
var history = _urlQueryConfig2.default.history;
// if not in history, use window
return history.location ? history.location : window.location;
}
function mergeLocationQueryOrSearch(location, newQuery) {
// if location.query exists, update the query in location. otherwise update the search string
// replace location.query
if (location.query) {
return _extends({}, location, {
query: newQuery,
search: undefined });
}
// replace location.search
var queryStr = (0, _queryString.stringify)(newQuery);
return _extends({}, location, {
search: queryStr.length ? '?' + queryStr : undefined
});
}
function updateLocation(newQuery, location) {
location = getLocation(location);
// remove query params that are nully or an empty strings.
// note: these values are assumed to be already encoded as strings.
var filteredQuery = Object.keys(newQuery).reduce(function (queryAccumulator, queryParam) {
var encodedValue = newQuery[queryParam];
if (encodedValue != null && encodedValue !== '') {
queryAccumulator[queryParam] = encodedValue;
}
return queryAccumulator;
}, {});
var newLocation = mergeLocationQueryOrSearch(location, filteredQuery);
// remove the key from the location
delete newLocation.key;
return newLocation;
}
function updateInLocation(queryParam, encodedValue, location) {
location = getLocation(location);
// if a query is there, use it, otherwise parse the search string
var currQuery = location.query || (0, _queryString.parse)(location.search);
var newQuery = _extends({}, currQuery, _defineProperty({}, queryParam, encodedValue));
// remove if it is nully or an empty string when encoded
if (encodedValue == null || encodedValue === '') {
delete newQuery[queryParam];
}
var newLocation = mergeLocationQueryOrSearch(location, newQuery);
// remove the key from the location
delete newLocation.key;
return newLocation;
}
/**
* Update multiple parts of the location at once
*/
function multiUpdateInLocation(queryReplacements, location) {
location = getLocation(location);
// if a query is there, use it, otherwise parse the search string
var currQuery = location.query || (0, _queryString.parse)(location.search);
var newQuery = _extends({}, currQuery, queryReplacements);
// remove if it is nully or an empty string when encoded
Object.keys(queryReplacements).forEach(function (queryParam) {
var encodedValue = queryReplacements[queryParam];
if (encodedValue == null || encodedValue === '') {
delete newQuery[queryParam];
}
});
var newLocation = mergeLocationQueryOrSearch(location, newQuery);
// remove the key from the location
delete newLocation.key;
return newLocation;
}
function replaceUrlQuery(newQuery, location) {
var newLocation = updateLocation(newQuery, location);
return _urlQueryConfig2.default.history.replace(newLocation);
}
function pushUrlQuery(newQuery, location) {
var newLocation = updateLocation(newQuery, location);
return _urlQueryConfig2.default.history.push(newLocation);
}
function replaceInUrlQuery(queryParam, encodedValue, location) {
var newLocation = updateInLocation(queryParam, encodedValue, location);
return _urlQueryConfig2.default.history.replace(newLocation);
}
function pushInUrlQuery(queryParam, encodedValue, location) {
var newLocation = updateInLocation(queryParam, encodedValue, location);
return _urlQueryConfig2.default.history.push(newLocation);
}
/**
* Replace multiple query parameters in a URL at once with only one
* call to `history.replace`
*
* @param {Object} queryReplacements Object representing the params and
* their encoded values. { queryParam: encodedValue, ... }
*/
function multiReplaceInUrlQuery(queryReplacements, location) {
var newLocation = multiUpdateInLocation(queryReplacements, location);
return _urlQueryConfig2.default.history.replace(newLocation);
}
function multiPushInUrlQuery(queryReplacements, location) {
var newLocation = multiUpdateInLocation(queryReplacements, location);
return _urlQueryConfig2.default.history.push(newLocation);
}
/**
* Updates a single value in a query based on the type
*/
function updateUrlQuerySingle() {
var updateType = arguments.length <= 0 || arguments[0] === undefined ? _UrlUpdateTypes2.default.replaceIn : arguments[0];
var queryParam = arguments[1];
var encodedValue = arguments[2];
var location = arguments[3];
if (updateType === _UrlUpdateTypes2.default.replaceIn) {
return replaceInUrlQuery(queryParam, encodedValue, location);
}
if (updateType === _UrlUpdateTypes2.default.pushIn) {
return pushInUrlQuery(queryParam, encodedValue, location);
}
// for these, wrap it in a whole new query object
var newQuery = _defineProperty({}, queryParam, encodedValue);
if (updateType === _UrlUpdateTypes2.default.replace) {
return replaceUrlQuery(newQuery, location);
}
if (updateType === _UrlUpdateTypes2.default.push) {
return pushUrlQuery(newQuery, location);
}
return undefined;
}
/**
* Updates a multiple values in a query based on the type
*/
function updateUrlQueryMulti() {
var updateType = arguments.length <= 0 || arguments[0] === undefined ? _UrlUpdateTypes2.default.replaceIn : arguments[0];
var queryReplacements = arguments[1];
var location = arguments[2];
if (updateType === _UrlUpdateTypes2.default.replaceIn) {
return multiReplaceInUrlQuery(queryReplacements, location);
}
if (updateType === _UrlUpdateTypes2.default.pushIn) {
return multiPushInUrlQuery(queryReplacements, location);
}
if (updateType === _UrlUpdateTypes2.default.replace) {
return replaceUrlQuery(queryReplacements, location);
}
if (updateType === _UrlUpdateTypes2.default.push) {
return pushUrlQuery(queryReplacements, location);
}
return undefined;
}
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.default = configureUrlQuery;
var _urlQueryConfig = __webpack_require__(3);
var _urlQueryConfig2 = _interopRequireDefault(_urlQueryConfig);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function configureUrlQuery(options) {
// update the url options singleton
Object.assign(_urlQueryConfig2.default, options);
}
/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.replaceUrlQueryFromAction = replaceUrlQueryFromAction;
exports.pushUrlQueryFromAction = pushUrlQueryFromAction;
exports.replaceInUrlQueryFromAction = replaceInUrlQueryFromAction;
exports.pushInUrlQueryFromAction = pushInUrlQueryFromAction;
exports.multiReplaceInUrlQueryFromAction = multiReplaceInUrlQueryFromAction;
exports.multiPushInUrlQueryFromAction = multiPushInUrlQueryFromAction;
var _updateUrlQuery = __webpack_require__(4);
function replaceUrlQueryFromAction(action, location) {
var encodedQuery = action.payload.encodedQuery;
(0, _updateUrlQuery.replaceUrlQuery)(encodedQuery, location);
}
function pushUrlQueryFromAction(action, location) {
var encodedQuery = action.payload.encodedQuery;
(0, _updateUrlQuery.pushUrlQuery)(encodedQuery, location);
}
function replaceInUrlQueryFromAction(action, location) {
var _action$payload = action.payload;
var queryParam = _action$payload.queryParam;
var encodedValue = _action$payload.encodedValue;
(0, _updateUrlQuery.replaceInUrlQuery)(queryParam, encodedValue, location);
}
function pushInUrlQueryFromAction(action, location) {
var _action$payload2 = action.payload;
var queryParam = _action$payload2.queryParam;
var encodedValue = _action$payload2.encodedValue;
(0, _updateUrlQuery.pushInUrlQuery)(queryParam, encodedValue, location);
}
function multiReplaceInUrlQueryFromAction(action, location) {
var encodedQuery = action.payload.encodedQuery;
(0, _updateUrlQuery.multiReplaceInUrlQuery)(encodedQuery, location);
}
function multiPushInUrlQueryFromAction(action, location) {
var encodedQuery = action.payload.encodedQuery;
(0, _updateUrlQuery.multiPushInUrlQuery)(encodedQuery, location);
}
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.default = urlQueryReducer;
var _updateUrlQueryFromAction = __webpack_require__(6);
var _UrlUpdateTypes = __webpack_require__(1);
var _UrlUpdateTypes2 = _interopRequireDefault(_UrlUpdateTypes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Reducer that handles actions that modify the URL query parameters.
* In this case, the actions replace a single query parameter at a time.
*
* NOTE: This is *NOT* a Redux reducer. It does not map from (state, action) -> state.
* Instead it "reduces" actions into URL query parameter state. NOT redux state.
*/
function urlQueryReducer(action, location) {
var updateType = action && action.meta && action.meta.updateType;
switch (updateType) {
case _UrlUpdateTypes2.default.replaceIn:
return (0, _updateUrlQueryFromAction.replaceInUrlQueryFromAction)(action, location);
case _UrlUpdateTypes2.default.replace:
return (0, _updateUrlQueryFromAction.replaceUrlQueryFromAction)(action, location);
case _UrlUpdateTypes2.default.multiReplaceIn:
return (0, _updateUrlQueryFromAction.multiReplaceInUrlQueryFromAction)(action, location);
case _UrlUpdateTypes2.default.pushIn:
return (0, _updateUrlQueryFromAction.pushInUrlQueryFromAction)(action, location);
case _UrlUpdateTypes2.default.push:
return (0, _updateUrlQueryFromAction.pushUrlQueryFromAction)(action, location);
case _UrlUpdateTypes2.default.multiPushIn:
return (0, _updateUrlQueryFromAction.multiPushInUrlQueryFromAction)(action, location);
default:
break;
}
if (true) {
console.warn('urlQueryReducer encountered unhandled action.meta.updateType ' + updateType + '.', // eslint-disable-line no-console
'action =', action);
}
return undefined;
}
/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.default = urlQueryDecoder;
var _serialize = __webpack_require__(2);
/**
* Decodes a query based on the config. It compares against cached values to see
* if decoding is necessary or if it can reuse old values.
*
* @param {Object} query The query object (typically from props.location.query)
*
* @return {Object} the decoded values `{ key: decodedValue, ... }`
*/
function urlQueryDecoder(config) {
var cachedQuery = void 0;
var cachedDecodedQuery = void 0;
return function decodeQueryWithCache(query) {
// decode the query
var decodedQuery = Object.keys(config).reduce(function (decoded, key) {
var keyConfig = config[key];
// read from the URL key if provided, otherwise use the key
var _keyConfig$queryParam = keyConfig.queryParam;
var queryParam = _keyConfig$queryParam === undefined ? key : _keyConfig$queryParam;
var encodedValue = query[queryParam];
var decodedValue = void 0;
// reused cached value
if (cachedQuery && cachedQuery[queryParam] !== undefined && cachedQuery[queryParam] === encodedValue) {
decodedValue = cachedDecodedQuery[key];
// not cached, decode now
// only decode if no validate provided or validate is provided and the encoded value is valid
} else {
decodedValue = (0, _serialize.decode)(keyConfig.type, encodedValue, keyConfig.defaultValue);
}
// validate the decoded value if configured. set to undefined if not valid
if (decodedValue !== undefined && keyConfig.validate && !keyConfig.validate(decodedValue)) {
decodedValue = undefined;
}
decoded[key] = decodedValue;
return decoded;
}, {});
// update the cache
cachedQuery = query;
cachedDecodedQuery = decodedQuery;
return decodedQuery;
};
}
/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
if (true) {
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
Symbol.for &&
Symbol.for('react.element')) ||
0xeac7;
var isValidElement = function(object) {
return typeof object === 'object' &&
object !== null &&
object.$$typeof === REACT_ELEMENT_TYPE;
};
// By explicitly using `prop-types` you are opting into new development behavior.
// http://fb.me/prop-types-in-prod
var throwOnDirectAccess = true;
module.exports = __webpack_require__(26)(isValidElement, throwOnDirectAccess);
} else {
// By explicitly using `prop-types` you are opting into new production behavior.
// http://fb.me/prop-types-in-prod
module.exports = require('./factoryWithThrowingShims')();
}
/***/ },
/* 10 */
/***/ function(module, exports) {
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
/***/ },
/* 11 */
/***/ function(module, exports) {
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;
/***/ },
/* 12 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
if (true) {
validateFormat = function validateFormat(format) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
};
}
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
module.exports = invariant;
/***/ },
/* 13 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var emptyFunction = __webpack_require__(11);
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var warning = emptyFunction;
if (true) {
(function () {
var printWarning = function printWarning(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
warning = function warning(condition, format) {
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
printWarning.apply(undefined, [format].concat(args));
}
};
})();
}
module.exports = warning;
/***/ },
/* 14 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var strictUriEncode = __webpack_require__(27);
var objectAssign = __webpack_require__(24);
function encode(value, opts) {
if (opts.encode) {
return opts.strict ? strictUriEncode(value) : encodeURIComponent(value);
}
return value;
}
exports.extract = function (str) {
return str.split('?')[1] || '';
};
exports.parse = function (str) {
// Create an object with no prototype
// https://github.com/sindresorhus/query-string/issues/47
var ret = Object.create(null);
if (typeof str !== 'string') {
return ret;
}
str = str.trim().replace(/^(\?|#|&)/, '');
if (!str) {
return ret;
}
str.split('&').forEach(function (param) {
var parts = param.replace(/\+/g, ' ').split('=');
// Firefox (pre 40) decodes `%3D` to `=`
// https://github.com/sindresorhus/query-string/pull/37
var key = parts.shift();
var val = parts.length > 0 ? parts.join('=') : undefined;
key = decodeURIComponent(key);
// missing `=` should be `null`:
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
val = val === undefined ? null : decodeURIComponent(val);
if (ret[key] === undefined) {
ret[key] = val;
} else if (Array.isArray(ret[key])) {
ret[key].push(val);
} else {
ret[key] = [ret[key], val];
}
});
return ret;
};
exports.stringify = function (obj, opts) {
var defaults = {
encode: true,
strict: true
};
opts = objectAssign(defaults, opts);
return obj ? Object.keys(obj).sort().map(function (key) {
var val = obj[key];
if (val === undefined) {
return '';
}
if (val === null) {
return encode(key, opts);
}
if (Array.isArray(val)) {
var result = [];
val.slice().forEach(function (val2) {
if (val2 === undefined) {
return;
}
if (val2 === null) {
result.push(encode(key, opts));
} else {
result.push(encode(key, opts) + '=' + encode(val2, opts));
}
});
return result.join('&');
}
return encode(key, opts) + '=' + encode(val, opts);
}).filter(function (x) {
return x.length > 0;
}).join('&') : '';
};
/***/ },
/* 15 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_15__;
/***/ },
/* 16 */
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
var UrlQueryParamTypes = {
number: 'number',
string: 'string',
object: 'object',
array: 'array',
json: 'json',
date: 'date',
boolean: 'boolean',
numericObject: 'numericObject',
numericArray: 'numericArray'
};
exports.default = UrlQueryParamTypes;
/***/ },
/* 17 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = 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; }; }();
var _react = __webpack_require__(15);
var _react2 = _interopRequireDefault(_react);
var _propTypes = __webpack_require__(9);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _configureUrlQuery = __webpack_require__(5);
var _configureUrlQuery2 = _interopRequireDefault(_configureUrlQuery);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeEr