history
Advanced tools
Comparing version 2.0.1 to 3.0.0-0
110
CHANGES.md
@@ -0,1 +1,21 @@ | ||
## [HEAD] | ||
- **Feature:** Added `history.getCurrentLocation()` method | ||
- **Breakage:** `history.listen` no longer calls the callback synchronously once. | ||
Use `history.getCurrentLocation` instead | ||
- **Breakage:** `location.key` on the initial POP is `null`. Users who relied on | ||
this key may immediately use `replace` to get it back | ||
- **Breakage:** `location.state` is `undefined` (instead of `null`) if the location | ||
has no state. This helps us know when we need to access session storage and when | ||
we can safely ignore it | ||
- **Bugfix:** Hash history now uses a custom query string key/value pair only if | ||
the location has state. This obsoletes using `{ queryKey: false }` to prevent | ||
the query string from being used ([#163]) | ||
- **Bugfix:** Do not access `window.sessionStorage` unless the location has state. | ||
This should minimize the # of times we access session storage and allow users to | ||
opt-out of using it entirely by not using location state | ||
[HEAD]: https://github.com/mjackson/history/compare/latest...HEAD | ||
[#163]: https://github.com/mjackson/history/issues/163 | ||
## [v2.0.0] | ||
@@ -7,5 +27,5 @@ > Feb 4, 2016 | ||
[v2.0.0]: https://github.com/reactjs/history/compare/v2.0.0-rc3...v2.0.0 | ||
[#221]: https://github.com/reactjs/history/issues/221 | ||
[#223]: https://github.com/reactjs/history/pull/223 | ||
[v2.0.0]: https://github.com/mjackson/history/compare/v2.0.0-rc3...v2.0.0 | ||
[#221]: https://github.com/mjackson/history/issues/221 | ||
[#223]: https://github.com/mjackson/history/pull/223 | ||
@@ -19,6 +39,6 @@ ## [v2.0.0-rc3] | ||
[v2.0.0-rc3]: https://github.com/reactjs/history/compare/v2.0.0-rc2...v2.0.0-rc3 | ||
[#179]: https://github.com/reactjs/history/pull/179 | ||
[#208]: https://github.com/reactjs/history/pull/208 | ||
[#200]: https://github.com/reactjs/history/pull/200 | ||
[v2.0.0-rc3]: https://github.com/mjackson/history/compare/v2.0.0-rc2...v2.0.0-rc3 | ||
[#179]: https://github.com/mjackson/history/pull/179 | ||
[#208]: https://github.com/mjackson/history/pull/208 | ||
[#200]: https://github.com/mjackson/history/pull/200 | ||
@@ -30,3 +50,3 @@ ## [v2.0.0-rc2] | ||
[v2.0.0-rc2]: https://github.com/reactjs/history/compare/v2.0.0-rc1...v2.0.0-rc2 | ||
[v2.0.0-rc2]: https://github.com/mjackson/history/compare/v2.0.0-rc1...v2.0.0-rc2 | ||
@@ -38,4 +58,4 @@ ## [v2.0.0-rc1] | ||
[v2.0.0-rc1]: https://github.com/reactjs/history/compare/v1.17.0...v2.0.0-rc1 | ||
[#177]: https://github.com/reactjs/history/pull/177 | ||
[v2.0.0-rc1]: https://github.com/mjackson/history/compare/v1.17.0...v2.0.0-rc1 | ||
[#177]: https://github.com/mjackson/history/pull/177 | ||
@@ -48,5 +68,5 @@ ## [v1.17.0] | ||
[v1.17.0]: https://github.com/reactjs/history/compare/v1.16.0...v1.17.0 | ||
[#170]: https://github.com/reactjs/history/pull/170 | ||
[#189]: https://github.com/reactjs/history/pull/189 | ||
[v1.17.0]: https://github.com/mjackson/history/compare/v1.16.0...v1.17.0 | ||
[#170]: https://github.com/mjackson/history/pull/170 | ||
[#189]: https://github.com/mjackson/history/pull/189 | ||
@@ -60,3 +80,3 @@ ## [v1.16.0] | ||
[v1.16.0]: https://github.com/reactjs/history/compare/v1.15.0...v1.16.0 | ||
[v1.16.0]: https://github.com/mjackson/history/compare/v1.15.0...v1.16.0 | ||
[reactjs/react-router#2682]: https://github.com/reactjs/react-router/issues/2682 | ||
@@ -70,4 +90,4 @@ | ||
[v1.15.0]: https://github.com/reactjs/history/compare/v1.14.0...v1.15.0 | ||
[#173]: https://github.com/reactjs/history/pull/173 | ||
[v1.15.0]: https://github.com/mjackson/history/compare/v1.14.0...v1.15.0 | ||
[#173]: https://github.com/mjackson/history/pull/173 | ||
@@ -84,9 +104,9 @@ ## [v1.14.0] | ||
[v1.14.0]: https://github.com/reactjs/history/compare/v1.13.1...v1.14.0 | ||
[#121]: https://github.com/reactjs/history/issues/121 | ||
[#141]: https://github.com/reactjs/history/pull/141 | ||
[#146]: https://github.com/reactjs/history/pull/146 | ||
[#152]: https://github.com/reactjs/history/pull/152 | ||
[#167]: https://github.com/reactjs/history/pull/167 | ||
[#168]: https://github.com/reactjs/history/pull/168 | ||
[v1.14.0]: https://github.com/mjackson/history/compare/v1.13.1...v1.14.0 | ||
[#121]: https://github.com/mjackson/history/issues/121 | ||
[#141]: https://github.com/mjackson/history/pull/141 | ||
[#146]: https://github.com/mjackson/history/pull/146 | ||
[#152]: https://github.com/mjackson/history/pull/152 | ||
[#167]: https://github.com/mjackson/history/pull/167 | ||
[#168]: https://github.com/mjackson/history/pull/168 | ||
@@ -100,5 +120,5 @@ ## [v1.13.1] | ||
[v1.13.1]: https://github.com/reactjs/history/compare/v1.13.0...v1.13.1 | ||
[#43]: https://github.com/reactjs/history/pull/43 | ||
[#139]: https://github.com/reactjs/history/pull/139 | ||
[v1.13.1]: https://github.com/mjackson/history/compare/v1.13.0...v1.13.1 | ||
[#43]: https://github.com/mjackson/history/pull/43 | ||
[#139]: https://github.com/mjackson/history/pull/139 | ||
@@ -112,5 +132,5 @@ ## [v1.13.0] | ||
[v1.13.0]: https://github.com/reactjs/history/compare/v1.12.6...v1.13.0 | ||
[#108]: https://github.com/reactjs/history/pull/108 | ||
[#94]: https://github.com/reactjs/history/issues/94 | ||
[v1.13.0]: https://github.com/mjackson/history/compare/v1.12.6...v1.13.0 | ||
[#108]: https://github.com/mjackson/history/pull/108 | ||
[#94]: https://github.com/mjackson/history/issues/94 | ||
@@ -123,4 +143,4 @@ ## [v1.12.6] | ||
[v1.12.6]: https://github.com/reactjs/history/compare/v1.12.5...v1.12.6 | ||
[#95]: https://github.com/reactjs/history/issues/95 | ||
[v1.12.6]: https://github.com/mjackson/history/compare/v1.12.5...v1.12.6 | ||
[#95]: https://github.com/mjackson/history/issues/95 | ||
@@ -135,4 +155,4 @@ ## [v1.12.5] | ||
[v1.12.5]: https://github.com/reactjs/history/compare/v1.12.4...v1.12.5 | ||
[#93]: https://github.com/reactjs/history/issues/93 | ||
[v1.12.5]: https://github.com/mjackson/history/compare/v1.12.4...v1.12.5 | ||
[#93]: https://github.com/mjackson/history/issues/93 | ||
@@ -144,4 +164,4 @@ ## [v1.12.4] | ||
[v1.12.4]: https://github.com/reactjs/history/compare/v1.12.3...v1.12.4 | ||
[#62]: https://github.com/reactjs/history/issues/62 | ||
[v1.12.4]: https://github.com/mjackson/history/compare/v1.12.3...v1.12.4 | ||
[#62]: https://github.com/mjackson/history/issues/62 | ||
@@ -154,5 +174,5 @@ ## [v1.12.3] | ||
[v1.12.3]: https://github.com/reactjs/history/compare/v1.12.2...v1.12.3 | ||
[#71]: https://github.com/reactjs/history/issues/71 | ||
[#42]: https://github.com/reactjs/history/issues/42 | ||
[v1.12.3]: https://github.com/mjackson/history/compare/v1.12.2...v1.12.3 | ||
[#71]: https://github.com/mjackson/history/issues/71 | ||
[#42]: https://github.com/mjackson/history/issues/42 | ||
@@ -164,4 +184,4 @@ ## [v1.12.2] | ||
[v1.12.2]: https://github.com/reactjs/history/compare/v1.12.1...v1.12.2 | ||
[#51-comments]: https://github.com/reactjs/history/pull/51#issuecomment-143189672 | ||
[v1.12.2]: https://github.com/mjackson/history/compare/v1.12.1...v1.12.2 | ||
[#51-comments]: https://github.com/mjackson/history/pull/51#issuecomment-143189672 | ||
@@ -174,3 +194,3 @@ ## [v1.12.1] | ||
[v1.12.1]: https://github.com/reactjs/history/compare/v1.12.0...v1.12.1 | ||
[v1.12.1]: https://github.com/mjackson/history/compare/v1.12.0...v1.12.1 | ||
@@ -183,3 +203,3 @@ ## [v1.12.0] | ||
[v1.12.0]: https://github.com/reactjs/history/compare/v1.11.1...v1.12.0 | ||
[v1.12.0]: https://github.com/mjackson/history/compare/v1.11.1...v1.12.0 | ||
@@ -192,4 +212,4 @@ ## [v1.11.1] | ||
[v1.11.1]: https://github.com/reactjs/history/compare/v1.11.0...v1.11.1 | ||
[#68]: https://github.com/reactjs/history/issues/68 | ||
[v1.11.1]: https://github.com/mjackson/history/compare/v1.11.0...v1.11.1 | ||
[#68]: https://github.com/mjackson/history/issues/68 | ||
@@ -206,2 +226,2 @@ ## [v1.11.0] | ||
[v1.11.0]: https://github.com/reactjs/history/compare/v1.10.2...v1.11.0 | ||
[v1.11.0]: https://github.com/mjackson/history/compare/v1.10.2...v1.11.0 |
@@ -0,15 +1,16 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
/** | ||
* Indicates that navigation was caused by a call to history.push. | ||
*/ | ||
'use strict'; | ||
var PUSH = exports.PUSH = 'PUSH'; | ||
var PUSH = 'PUSH'; | ||
export { PUSH }; | ||
/** | ||
* Indicates that navigation was caused by a call to history.replace. | ||
*/ | ||
var REPLACE = 'REPLACE'; | ||
var REPLACE = exports.REPLACE = 'REPLACE'; | ||
export { REPLACE }; | ||
/** | ||
@@ -23,9 +24,2 @@ * Indicates that navigation was caused by some other action such | ||
*/ | ||
var POP = 'POP'; | ||
export { POP }; | ||
export default { | ||
PUSH: PUSH, | ||
REPLACE: REPLACE, | ||
POP: POP | ||
}; | ||
var POP = exports.POP = 'POP'; |
"use strict"; | ||
var _slice = Array.prototype.slice; | ||
export { loopAsync }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function loopAsync(turns, work, callback) { | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var loopAsync = exports.loopAsync = function loopAsync(turns, work, callback) { | ||
var currentTurn = 0, | ||
isDone = false; | ||
var sync = false, | ||
var isSync = false, | ||
hasNext = false, | ||
doneArgs = undefined; | ||
doneArgs = void 0; | ||
function done() { | ||
var done = function done() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
isDone = true; | ||
if (sync) { | ||
if (isSync) { | ||
// Iterate instead of recursing if possible. | ||
doneArgs = [].concat(_slice.call(arguments)); | ||
doneArgs = args; | ||
return; | ||
} | ||
callback.apply(this, arguments); | ||
} | ||
callback.apply(undefined, args); | ||
}; | ||
function next() { | ||
if (isDone) { | ||
return; | ||
} | ||
var next = function next() { | ||
if (isDone) return; | ||
hasNext = true; | ||
if (sync) { | ||
// Iterate instead of recursing if possible. | ||
return; | ||
} | ||
sync = true; | ||
if (isSync) return; // Iterate instead of recursing if possible. | ||
isSync = true; | ||
while (!isDone && currentTurn < turns && hasNext) { | ||
hasNext = false; | ||
work.call(this, currentTurn++, next, done); | ||
work.call(undefined, currentTurn++, next, done); | ||
} | ||
sync = false; | ||
isSync = false; | ||
if (isDone) { | ||
// This means the loop finished synchronously. | ||
callback.apply(this, doneArgs); | ||
callback.apply(undefined, _toConsumableArray(doneArgs)); | ||
return; | ||
@@ -54,5 +58,5 @@ } | ||
} | ||
} | ||
}; | ||
next(); | ||
} | ||
}; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
import invariant from 'invariant'; | ||
import { PUSH, POP } from './Actions'; | ||
import { parsePath } from './PathUtils'; | ||
import { canUseDOM } from './ExecutionEnvironment'; | ||
import { addEventListener, removeEventListener, getWindowPath, supportsHistory } from './DOMUtils'; | ||
import { saveState, readState } from './DOMStateStorage'; | ||
import createDOMHistory from './createDOMHistory'; | ||
var _invariant = require('invariant'); | ||
/** | ||
* Creates and returns a history object that uses HTML5's history API | ||
* (pushState, replaceState, and the popstate event) to manage history. | ||
* This is the recommended method of managing history in browsers because | ||
* it provides the cleanest URLs. | ||
* | ||
* Note: In browsers that do not support the HTML5 history API full | ||
* page reloads will be used to preserve URLs. | ||
*/ | ||
function createBrowserHistory() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
!canUseDOM ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Browser history needs a DOM') : invariant(false) : undefined; | ||
var _ExecutionEnvironment = require('./ExecutionEnvironment'); | ||
var forceRefresh = options.forceRefresh; | ||
var _BrowserProtocol = require('./BrowserProtocol'); | ||
var isSupported = supportsHistory(); | ||
var useRefresh = !isSupported || forceRefresh; | ||
var BrowserProtocol = _interopRequireWildcard(_BrowserProtocol); | ||
function getCurrentLocation(historyState) { | ||
historyState = historyState || window.history.state || {}; | ||
var _RefreshProtocol = require('./RefreshProtocol'); | ||
var path = getWindowPath(); | ||
var _historyState = historyState; | ||
var key = _historyState.key; | ||
var RefreshProtocol = _interopRequireWildcard(_RefreshProtocol); | ||
var state = undefined; | ||
if (key) { | ||
state = readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
var _DOMUtils = require('./DOMUtils'); | ||
if (isSupported) window.history.replaceState(_extends({}, historyState, { key: key }), null, path); | ||
} | ||
var _createHistory = require('./createHistory'); | ||
var location = parsePath(path); | ||
var _createHistory2 = _interopRequireDefault(_createHistory); | ||
return history.createLocation(_extends({}, location, { state: state }), undefined, key); | ||
} | ||
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 startPopStateListener(_ref) { | ||
var transitionTo = _ref.transitionTo; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function popStateListener(event) { | ||
if (event.state === undefined) return; // Ignore extraneous popstate events in WebKit. | ||
/** | ||
* Creates and returns a history object that uses HTML5's history API | ||
* (pushState, replaceState, and the popstate event) to manage history. | ||
* This is the recommended method of managing history in browsers because | ||
* it provides the cleanest URLs. | ||
* | ||
* Note: In browsers that do not support the HTML5 history API full | ||
* page reloads will be used to preserve clean URLs. You can force this | ||
* behavior using { forceRefresh: true } in options. | ||
*/ | ||
var createBrowserHistory = function createBrowserHistory() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
transitionTo(getCurrentLocation(event.state)); | ||
} | ||
!_ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'Browser history needs a DOM') : (0, _invariant2.default)(false) : void 0; | ||
addEventListener(window, 'popstate', popStateListener); | ||
var useRefresh = options.forceRefresh || !(0, _DOMUtils.supportsHistory)(); | ||
var Protocol = useRefresh ? RefreshProtocol : BrowserProtocol; | ||
return function () { | ||
removeEventListener(window, 'popstate', popStateListener); | ||
}; | ||
} | ||
var getUserConfirmation = Protocol.getUserConfirmation; | ||
var getCurrentLocation = Protocol.getCurrentLocation; | ||
var pushLocation = Protocol.pushLocation; | ||
var replaceLocation = Protocol.replaceLocation; | ||
var go = Protocol.go; | ||
function finishTransition(location) { | ||
var basename = location.basename; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var hash = location.hash; | ||
var state = location.state; | ||
var action = location.action; | ||
var key = location.key; | ||
if (action === POP) return; // Nothing to do. | ||
saveState(key, state); | ||
var path = (basename || '') + pathname + search + hash; | ||
var historyState = { | ||
key: key | ||
}; | ||
if (action === PUSH) { | ||
if (useRefresh) { | ||
window.location.href = path; | ||
return false; // Prevent location update. | ||
} else { | ||
window.history.pushState(historyState, null, path); | ||
} | ||
} else { | ||
// REPLACE | ||
if (useRefresh) { | ||
window.location.replace(path); | ||
return false; // Prevent location update. | ||
} else { | ||
window.history.replaceState(historyState, null, path); | ||
} | ||
} | ||
} | ||
var history = createDOMHistory(_extends({}, options, { | ||
var history = (0, _createHistory2.default)(_extends({ | ||
getUserConfirmation: getUserConfirmation }, options, { | ||
getCurrentLocation: getCurrentLocation, | ||
finishTransition: finishTransition, | ||
saveState: saveState | ||
pushLocation: pushLocation, | ||
replaceLocation: replaceLocation, | ||
go: go | ||
})); | ||
/* eslint-ignore prefer-const */ | ||
var listenerCount = 0, | ||
stopPopStateListener = undefined; | ||
stopListener = void 0; | ||
function listenBefore(listener) { | ||
if (++listenerCount === 1) stopPopStateListener = startPopStateListener(history); | ||
var startListener = function startListener(listener, before) { | ||
if (++listenerCount === 1) stopListener = BrowserProtocol.startListener(history.transitionTo); | ||
var unlisten = history.listenBefore(listener); | ||
var unlisten = before ? history.listenBefore(listener) : history.listen(listener); | ||
@@ -123,40 +78,20 @@ return function () { | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
if (--listenerCount === 0) stopListener(); | ||
}; | ||
} | ||
}; | ||
function listen(listener) { | ||
if (++listenerCount === 1) stopPopStateListener = startPopStateListener(history); | ||
var listenBefore = function listenBefore(listener) { | ||
return startListener(listener, true); | ||
}; | ||
var unlisten = history.listen(listener); | ||
var listen = function listen(listener) { | ||
return startListener(listener, false); | ||
}; | ||
return function () { | ||
unlisten(); | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
}; | ||
} | ||
// deprecated | ||
function registerTransitionHook(hook) { | ||
if (++listenerCount === 1) stopPopStateListener = startPopStateListener(history); | ||
history.registerTransitionHook(hook); | ||
} | ||
// deprecated | ||
function unregisterTransitionHook(hook) { | ||
history.unregisterTransitionHook(hook); | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
} | ||
return _extends({}, history, { | ||
listenBefore: listenBefore, | ||
listen: listen, | ||
registerTransitionHook: registerTransitionHook, | ||
unregisterTransitionHook: unregisterTransitionHook | ||
listen: listen | ||
}); | ||
} | ||
}; | ||
export default createBrowserHistory; | ||
exports.default = createBrowserHistory; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
import warning from 'warning'; | ||
import invariant from 'invariant'; | ||
import { PUSH, POP } from './Actions'; | ||
import { parsePath } from './PathUtils'; | ||
import { canUseDOM } from './ExecutionEnvironment'; | ||
import { addEventListener, removeEventListener, getHashPath, replaceHashPath, supportsGoWithoutReloadUsingHash } from './DOMUtils'; | ||
import { saveState, readState } from './DOMStateStorage'; | ||
import createDOMHistory from './createDOMHistory'; | ||
var _warning = require('warning'); | ||
function isAbsolutePath(path) { | ||
return typeof path === 'string' && path.charAt(0) === '/'; | ||
} | ||
var _warning2 = _interopRequireDefault(_warning); | ||
function ensureSlash() { | ||
var path = getHashPath(); | ||
var _invariant = require('invariant'); | ||
if (isAbsolutePath(path)) return true; | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
replaceHashPath('/' + path); | ||
var _ExecutionEnvironment = require('./ExecutionEnvironment'); | ||
return false; | ||
} | ||
var _DOMUtils = require('./DOMUtils'); | ||
function addQueryStringValueToPath(path, key, value) { | ||
return path + (path.indexOf('?') === -1 ? '?' : '&') + (key + '=' + value); | ||
} | ||
var _HashProtocol = require('./HashProtocol'); | ||
function stripQueryStringValueFromPath(path, key) { | ||
return path.replace(new RegExp('[?&]?' + key + '=[a-zA-Z0-9]+'), ''); | ||
} | ||
var HashProtocol = _interopRequireWildcard(_HashProtocol); | ||
function getQueryStringValueFromPath(path, key) { | ||
var match = path.match(new RegExp('\\?.*?\\b' + key + '=(.+?)\\b')); | ||
return match && match[1]; | ||
} | ||
var _createHistory = require('./createHistory'); | ||
var _createHistory2 = _interopRequireDefault(_createHistory); | ||
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 }; } | ||
var DefaultQueryKey = '_k'; | ||
function createHashHistory() { | ||
var createHashHistory = function createHashHistory() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
!canUseDOM ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Hash history needs a DOM') : invariant(false) : undefined; | ||
!_ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'Hash history needs a DOM') : (0, _invariant2.default)(false) : void 0; | ||
var queryKey = options.queryKey; | ||
if (queryKey === undefined || !!queryKey) queryKey = typeof queryKey === 'string' ? queryKey : DefaultQueryKey; | ||
function getCurrentLocation() { | ||
var path = getHashPath(); | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(queryKey !== false, 'Using { queryKey: false } no longer works. Instead, just don\'t ' + 'use location state if you don\'t want a key in your URL query string') : void 0; | ||
var key = undefined, | ||
state = undefined; | ||
if (queryKey) { | ||
key = getQueryStringValueFromPath(path, queryKey); | ||
path = stripQueryStringValueFromPath(path, queryKey); | ||
if (typeof queryKey !== 'string') queryKey = DefaultQueryKey; | ||
if (key) { | ||
state = readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
replaceHashPath(addQueryStringValueToPath(path, queryKey, key)); | ||
} | ||
} else { | ||
key = state = null; | ||
} | ||
var getUserConfirmation = HashProtocol.getUserConfirmation; | ||
var location = parsePath(path); | ||
return history.createLocation(_extends({}, location, { state: state }), undefined, key); | ||
} | ||
var getCurrentLocation = function getCurrentLocation() { | ||
return HashProtocol.getCurrentLocation(queryKey); | ||
}; | ||
function startHashChangeListener(_ref) { | ||
var transitionTo = _ref.transitionTo; | ||
var pushLocation = function pushLocation(location) { | ||
return HashProtocol.pushLocation(location, queryKey); | ||
}; | ||
function hashChangeListener() { | ||
if (!ensureSlash()) return; // Always make sure hashes are preceeded with a /. | ||
var replaceLocation = function replaceLocation(location) { | ||
return HashProtocol.replaceLocation(location, queryKey); | ||
}; | ||
transitionTo(getCurrentLocation()); | ||
} | ||
ensureSlash(); | ||
addEventListener(window, 'hashchange', hashChangeListener); | ||
return function () { | ||
removeEventListener(window, 'hashchange', hashChangeListener); | ||
}; | ||
} | ||
function finishTransition(location) { | ||
var basename = location.basename; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var state = location.state; | ||
var action = location.action; | ||
var key = location.key; | ||
if (action === POP) return; // Nothing to do. | ||
var path = (basename || '') + pathname + search; | ||
if (queryKey) { | ||
path = addQueryStringValueToPath(path, queryKey, key); | ||
saveState(key, state); | ||
} else { | ||
// Drop key and state. | ||
location.key = location.state = null; | ||
} | ||
var currentHash = getHashPath(); | ||
if (action === PUSH) { | ||
if (currentHash !== path) { | ||
window.location.hash = path; | ||
} else { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'You cannot PUSH the same path using hash history') : undefined; | ||
} | ||
} else if (currentHash !== path) { | ||
// REPLACE | ||
replaceHashPath(path); | ||
} | ||
} | ||
var history = createDOMHistory(_extends({}, options, { | ||
var history = (0, _createHistory2.default)(_extends({ | ||
getUserConfirmation: getUserConfirmation }, options, { | ||
getCurrentLocation: getCurrentLocation, | ||
finishTransition: finishTransition, | ||
saveState: saveState | ||
pushLocation: pushLocation, | ||
replaceLocation: replaceLocation, | ||
go: HashProtocol.go | ||
})); | ||
var listenerCount = 0, | ||
stopHashChangeListener = undefined; | ||
stopListener = void 0; | ||
function listenBefore(listener) { | ||
if (++listenerCount === 1) stopHashChangeListener = startHashChangeListener(history); | ||
var startListener = function startListener(listener, before) { | ||
if (++listenerCount === 1) stopListener = HashProtocol.startListener(history.transitionTo, queryKey); | ||
var unlisten = history.listenBefore(listener); | ||
var unlisten = before ? history.listenBefore(listener) : history.listen(listener); | ||
@@ -145,85 +81,34 @@ return function () { | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
if (--listenerCount === 0) stopListener(); | ||
}; | ||
} | ||
}; | ||
function listen(listener) { | ||
if (++listenerCount === 1) stopHashChangeListener = startHashChangeListener(history); | ||
var listenBefore = function listenBefore(listener) { | ||
return startListener(listener, true); | ||
}; | ||
var unlisten = history.listen(listener); | ||
var listen = function listen(listener) { | ||
return startListener(listener, false); | ||
}; | ||
return function () { | ||
unlisten(); | ||
var goIsSupportedWithoutReload = (0, _DOMUtils.supportsGoWithoutReloadUsingHash)(); | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
}; | ||
} | ||
var go = function go(n) { | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(goIsSupportedWithoutReload, 'Hash history go(n) causes a full page reload in this browser') : void 0; | ||
function push(location) { | ||
process.env.NODE_ENV !== 'production' ? warning(queryKey || location.state == null, 'You cannot use state without a queryKey it will be dropped') : undefined; | ||
history.push(location); | ||
} | ||
function replace(location) { | ||
process.env.NODE_ENV !== 'production' ? warning(queryKey || location.state == null, 'You cannot use state without a queryKey it will be dropped') : undefined; | ||
history.replace(location); | ||
} | ||
var goIsSupportedWithoutReload = supportsGoWithoutReloadUsingHash(); | ||
function go(n) { | ||
process.env.NODE_ENV !== 'production' ? warning(goIsSupportedWithoutReload, 'Hash history go(n) causes a full page reload in this browser') : undefined; | ||
history.go(n); | ||
} | ||
}; | ||
function createHref(path) { | ||
var createHref = function createHref(path) { | ||
return '#' + history.createHref(path); | ||
} | ||
}; | ||
// deprecated | ||
function registerTransitionHook(hook) { | ||
if (++listenerCount === 1) stopHashChangeListener = startHashChangeListener(history); | ||
history.registerTransitionHook(hook); | ||
} | ||
// deprecated | ||
function unregisterTransitionHook(hook) { | ||
history.unregisterTransitionHook(hook); | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
} | ||
// deprecated | ||
function pushState(state, path) { | ||
process.env.NODE_ENV !== 'production' ? warning(queryKey || state == null, 'You cannot use state without a queryKey it will be dropped') : undefined; | ||
history.pushState(state, path); | ||
} | ||
// deprecated | ||
function replaceState(state, path) { | ||
process.env.NODE_ENV !== 'production' ? warning(queryKey || state == null, 'You cannot use state without a queryKey it will be dropped') : undefined; | ||
history.replaceState(state, path); | ||
} | ||
return _extends({}, history, { | ||
listenBefore: listenBefore, | ||
listen: listen, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
createHref: createHref, | ||
registerTransitionHook: registerTransitionHook, // deprecated - warning is in createHistory | ||
unregisterTransitionHook: unregisterTransitionHook, // deprecated - warning is in createHistory | ||
pushState: pushState, // deprecated - warning is in createHistory | ||
replaceState: replaceState // deprecated - warning is in createHistory | ||
createHref: createHref | ||
}); | ||
} | ||
}; | ||
export default createHashHistory; | ||
exports.default = createHashHistory; |
'use strict'; | ||
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; }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
import warning from 'warning'; | ||
import deepEqual from 'deep-equal'; | ||
import { parsePath } from './PathUtils'; | ||
import { loopAsync } from './AsyncUtils'; | ||
import { PUSH, REPLACE, POP } from './Actions'; | ||
import _createLocation from './createLocation'; | ||
import runTransitionHook from './runTransitionHook'; | ||
import deprecate from './deprecate'; | ||
var _deepEqual = require('deep-equal'); | ||
function createRandomKey(length) { | ||
return Math.random().toString(36).substr(2, length); | ||
} | ||
var _deepEqual2 = _interopRequireDefault(_deepEqual); | ||
function locationsAreEqual(a, b) { | ||
return a.pathname === b.pathname && a.search === b.search && | ||
//a.action === b.action && // Different action !== location change. | ||
a.key === b.key && deepEqual(a.state, b.state); | ||
} | ||
var _AsyncUtils = require('./AsyncUtils'); | ||
var DefaultKeyLength = 6; | ||
var _PathUtils = require('./PathUtils'); | ||
function createHistory() { | ||
var _runTransitionHook = require('./runTransitionHook'); | ||
var _runTransitionHook2 = _interopRequireDefault(_runTransitionHook); | ||
var _Actions = require('./Actions'); | ||
var _LocationUtils = require('./LocationUtils'); | ||
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); } } | ||
var createHistory = function createHistory() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var getCurrentLocation = options.getCurrentLocation; | ||
var finishTransition = options.finishTransition; | ||
var saveState = options.saveState; | ||
var getUserConfirmation = options.getUserConfirmation; | ||
var pushLocation = options.pushLocation; | ||
var replaceLocation = options.replaceLocation; | ||
var go = options.go; | ||
var getUserConfirmation = options.getUserConfirmation; | ||
var keyLength = options.keyLength; | ||
if (typeof keyLength !== 'number') keyLength = DefaultKeyLength; | ||
var transitionHooks = []; | ||
var currentLocation = void 0; | ||
var pendingLocation = void 0; | ||
var beforeListeners = []; | ||
var listeners = []; | ||
var allKeys = []; | ||
function listenBefore(hook) { | ||
transitionHooks.push(hook); | ||
var getCurrentIndex = function getCurrentIndex() { | ||
if (pendingLocation && pendingLocation.action === _Actions.POP) return allKeys.indexOf(pendingLocation.key); | ||
return function () { | ||
transitionHooks = transitionHooks.filter(function (item) { | ||
return item !== hook; | ||
}); | ||
}; | ||
} | ||
if (currentLocation) return allKeys.indexOf(currentLocation.key); | ||
var allKeys = []; | ||
var changeListeners = []; | ||
var location = undefined; | ||
return -1; | ||
}; | ||
function getCurrent() { | ||
if (pendingLocation && pendingLocation.action === POP) { | ||
return allKeys.indexOf(pendingLocation.key); | ||
} else if (location) { | ||
return allKeys.indexOf(location.key); | ||
} else { | ||
return -1; | ||
} | ||
} | ||
var updateLocation = function updateLocation(nextLocation) { | ||
currentLocation = nextLocation; | ||
function updateLocation(newLocation) { | ||
var current = getCurrent(); | ||
var currentIndex = getCurrentIndex(); | ||
location = newLocation; | ||
if (location.action === PUSH) { | ||
allKeys = [].concat(allKeys.slice(0, current + 1), [location.key]); | ||
} else if (location.action === REPLACE) { | ||
allKeys[current] = location.key; | ||
if (currentLocation.action === _Actions.PUSH) { | ||
allKeys = [].concat(_toConsumableArray(allKeys.slice(0, currentIndex + 1)), [currentLocation.key]); | ||
} else if (currentLocation.action === _Actions.REPLACE) { | ||
allKeys[currentIndex] = currentLocation.key; | ||
} | ||
changeListeners.forEach(function (listener) { | ||
listener(location); | ||
listeners.forEach(function (listener) { | ||
return listener(currentLocation); | ||
}); | ||
} | ||
}; | ||
function listen(listener) { | ||
changeListeners.push(listener); | ||
var listenBefore = function listenBefore(listener) { | ||
beforeListeners.push(listener); | ||
if (location) { | ||
listener(location); | ||
} else { | ||
var _location = getCurrentLocation(); | ||
allKeys = [_location.key]; | ||
updateLocation(_location); | ||
} | ||
return function () { | ||
return beforeListeners = beforeListeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
}; | ||
}; | ||
var listen = function listen(listener) { | ||
listeners.push(listener); | ||
return function () { | ||
changeListeners = changeListeners.filter(function (item) { | ||
return listeners = listeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
}; | ||
} | ||
}; | ||
function confirmTransitionTo(location, callback) { | ||
loopAsync(transitionHooks.length, function (index, next, done) { | ||
runTransitionHook(transitionHooks[index], location, function (result) { | ||
if (result != null) { | ||
done(result); | ||
} else { | ||
next(); | ||
} | ||
var confirmTransitionTo = function confirmTransitionTo(location, callback) { | ||
(0, _AsyncUtils.loopAsync)(beforeListeners.length, function (index, next, done) { | ||
(0, _runTransitionHook2.default)(beforeListeners[index], location, function (result) { | ||
return result != null ? done(result) : next(); | ||
}); | ||
@@ -109,3 +95,3 @@ }, function (message) { | ||
getUserConfirmation(message, function (ok) { | ||
callback(ok !== false); | ||
return callback(ok !== false); | ||
}); | ||
@@ -116,132 +102,70 @@ } else { | ||
}); | ||
} | ||
}; | ||
var pendingLocation = undefined; | ||
var transitionTo = function transitionTo(nextLocation) { | ||
if (currentLocation && (0, _LocationUtils.locationsAreEqual)(currentLocation, nextLocation) || pendingLocation && (0, _LocationUtils.locationsAreEqual)(pendingLocation, nextLocation)) return; // Nothing to do | ||
function transitionTo(nextLocation) { | ||
if (location && locationsAreEqual(location, nextLocation)) return; // Nothing to do. | ||
pendingLocation = nextLocation; | ||
confirmTransitionTo(nextLocation, function (ok) { | ||
if (pendingLocation !== nextLocation) return; // Transition was interrupted. | ||
if (pendingLocation !== nextLocation) return; // Transition was interrupted during confirmation | ||
pendingLocation = null; | ||
if (ok) { | ||
// treat PUSH to current path like REPLACE to be consistent with browsers | ||
if (nextLocation.action === PUSH) { | ||
var prevPath = createPath(location); | ||
var nextPath = createPath(nextLocation); | ||
// Treat PUSH to same path like REPLACE to be consistent with browsers | ||
if (nextLocation.action === _Actions.PUSH) { | ||
var prevPath = (0, _PathUtils.createPath)(currentLocation); | ||
var nextPath = (0, _PathUtils.createPath)(nextLocation); | ||
if (nextPath === prevPath && deepEqual(location.state, nextLocation.state)) nextLocation.action = REPLACE; | ||
if (nextPath === prevPath && (0, _deepEqual2.default)(currentLocation.state, nextLocation.state)) nextLocation.action = _Actions.REPLACE; | ||
} | ||
if (finishTransition(nextLocation) !== false) updateLocation(nextLocation); | ||
} else if (location && nextLocation.action === POP) { | ||
var prevIndex = allKeys.indexOf(location.key); | ||
if (nextLocation.action === _Actions.POP) { | ||
updateLocation(nextLocation); | ||
} else if (nextLocation.action === _Actions.PUSH) { | ||
if (pushLocation(nextLocation) !== false) updateLocation(nextLocation); | ||
} else if (nextLocation.action === _Actions.REPLACE) { | ||
if (replaceLocation(nextLocation) !== false) updateLocation(nextLocation); | ||
} | ||
} else if (currentLocation && nextLocation.action === _Actions.POP) { | ||
var prevIndex = allKeys.indexOf(currentLocation.key); | ||
var nextIndex = allKeys.indexOf(nextLocation.key); | ||
if (prevIndex !== -1 && nextIndex !== -1) go(prevIndex - nextIndex); // Restore the URL. | ||
if (prevIndex !== -1 && nextIndex !== -1) go(prevIndex - nextIndex); // Restore the URL | ||
} | ||
}); | ||
} | ||
}; | ||
function push(location) { | ||
transitionTo(createLocation(location, PUSH, createKey())); | ||
} | ||
var push = function push(input) { | ||
return transitionTo(createLocation(input, _Actions.PUSH)); | ||
}; | ||
function replace(location) { | ||
transitionTo(createLocation(location, REPLACE, createKey())); | ||
} | ||
var replace = function replace(input) { | ||
return transitionTo(createLocation(input, _Actions.REPLACE)); | ||
}; | ||
function goBack() { | ||
go(-1); | ||
} | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
function goForward() { | ||
go(1); | ||
} | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
function createKey() { | ||
return createRandomKey(keyLength); | ||
} | ||
var createKey = function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength || 6); | ||
}; | ||
function createPath(location) { | ||
if (location == null || typeof location === 'string') return location; | ||
var createHref = function createHref(location) { | ||
return (0, _PathUtils.createPath)(location); | ||
}; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var hash = location.hash; | ||
var result = pathname; | ||
if (search) result += search; | ||
if (hash) result += hash; | ||
return result; | ||
} | ||
function createHref(location) { | ||
return createPath(location); | ||
} | ||
function createLocation(location, action) { | ||
var createLocation = function createLocation(location, action) { | ||
var key = arguments.length <= 2 || arguments[2] === undefined ? createKey() : arguments[2]; | ||
return (0, _LocationUtils.createLocation)(location, action, key); | ||
}; | ||
if (typeof action === 'object') { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'The state (2nd) argument to history.createLocation is deprecated; use a ' + 'location descriptor instead') : undefined; | ||
if (typeof location === 'string') location = parsePath(location); | ||
location = _extends({}, location, { state: action }); | ||
action = key; | ||
key = arguments[3] || createKey(); | ||
} | ||
return _createLocation(location, action, key); | ||
} | ||
// deprecated | ||
function setState(state) { | ||
if (location) { | ||
updateLocationState(location, state); | ||
updateLocation(location); | ||
} else { | ||
updateLocationState(getCurrentLocation(), state); | ||
} | ||
} | ||
function updateLocationState(location, state) { | ||
location.state = _extends({}, location.state, state); | ||
saveState(location.key, location.state); | ||
} | ||
// deprecated | ||
function registerTransitionHook(hook) { | ||
if (transitionHooks.indexOf(hook) === -1) transitionHooks.push(hook); | ||
} | ||
// deprecated | ||
function unregisterTransitionHook(hook) { | ||
transitionHooks = transitionHooks.filter(function (item) { | ||
return item !== hook; | ||
}); | ||
} | ||
// deprecated | ||
function pushState(state, path) { | ||
if (typeof path === 'string') path = parsePath(path); | ||
push(_extends({ state: state }, path)); | ||
} | ||
// deprecated | ||
function replaceState(state, path) { | ||
if (typeof path === 'string') path = parsePath(path); | ||
replace(_extends({ state: state }, path)); | ||
} | ||
return { | ||
getCurrentLocation: getCurrentLocation, | ||
listenBefore: listenBefore, | ||
@@ -256,14 +180,8 @@ listen: listen, | ||
createKey: createKey, | ||
createPath: createPath, | ||
createPath: _PathUtils.createPath, | ||
createHref: createHref, | ||
createLocation: createLocation, | ||
setState: deprecate(setState, 'setState is deprecated; use location.key to save state instead'), | ||
registerTransitionHook: deprecate(registerTransitionHook, 'registerTransitionHook is deprecated; use listenBefore instead'), | ||
unregisterTransitionHook: deprecate(unregisterTransitionHook, 'unregisterTransitionHook is deprecated; use the callback returned from listenBefore instead'), | ||
pushState: deprecate(pushState, 'pushState is deprecated; use push instead'), | ||
replaceState: deprecate(replaceState, 'replaceState is deprecated; use replace instead') | ||
createLocation: createLocation | ||
}; | ||
} | ||
}; | ||
export default createHistory; | ||
exports.default = createHistory; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
import warning from 'warning'; | ||
import invariant from 'invariant'; | ||
import { parsePath } from './PathUtils'; | ||
import { PUSH, REPLACE, POP } from './Actions'; | ||
import createHistory from './createHistory'; | ||
var _warning = require('warning'); | ||
function createStateStorage(entries) { | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var _invariant = require('invariant'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _LocationUtils = require('./LocationUtils'); | ||
var _PathUtils = require('./PathUtils'); | ||
var _createHistory = require('./createHistory'); | ||
var _createHistory2 = _interopRequireDefault(_createHistory); | ||
var _Actions = require('./Actions'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var createStateStorage = function createStateStorage(entries) { | ||
return entries.filter(function (entry) { | ||
@@ -18,5 +36,5 @@ return entry.state; | ||
}, {}); | ||
} | ||
}; | ||
function createMemoryHistory() { | ||
var createMemoryHistory = function createMemoryHistory() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -30,112 +48,94 @@ | ||
var history = createHistory(_extends({}, options, { | ||
getCurrentLocation: getCurrentLocation, | ||
finishTransition: finishTransition, | ||
saveState: saveState, | ||
go: go | ||
})); | ||
var getCurrentLocation = function getCurrentLocation() { | ||
var entry = entries[current]; | ||
var path = (0, _PathUtils.createPath)(entry); | ||
var _options = options; | ||
var entries = _options.entries; | ||
var current = _options.current; | ||
var key = void 0, | ||
state = void 0; | ||
if (entry.key) { | ||
key = entry.key; | ||
state = readState(key); | ||
} | ||
if (typeof entries === 'string') { | ||
entries = [entries]; | ||
} else if (!Array.isArray(entries)) { | ||
entries = ['/']; | ||
} | ||
var init = (0, _PathUtils.parsePath)(path); | ||
entries = entries.map(function (entry) { | ||
var key = history.createKey(); | ||
return (0, _LocationUtils.createLocation)(_extends({}, init, { state: state }), undefined, key); | ||
}; | ||
if (typeof entry === 'string') return { pathname: entry, key: key }; | ||
var canGo = function canGo(n) { | ||
var index = current + n; | ||
return index >= 0 && index < entries.length; | ||
}; | ||
if (typeof entry === 'object' && entry) return _extends({}, entry, { key: key }); | ||
var go = function go(n) { | ||
if (!n) return; | ||
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Unable to create history entry from %s', entry) : invariant(false) : undefined; | ||
}); | ||
if (!canGo(n)) { | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(false, 'Cannot go(%s) there is not enough history', n) : void 0; | ||
if (current == null) { | ||
current = entries.length - 1; | ||
} else { | ||
!(current >= 0 && current < entries.length) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Current index must be >= 0 and < %s, was %s', entries.length, current) : invariant(false) : undefined; | ||
} | ||
return; | ||
} | ||
var storage = createStateStorage(entries); | ||
current += n; | ||
var currentLocation = getCurrentLocation(); | ||
function saveState(key, state) { | ||
storage[key] = state; | ||
} | ||
// Change action to POP | ||
history.transitionTo(_extends({}, currentLocation, { action: _Actions.POP })); | ||
}; | ||
function readState(key) { | ||
return storage[key]; | ||
} | ||
var pushLocation = function pushLocation(location) { | ||
current += 1; | ||
function getCurrentLocation() { | ||
var entry = entries[current]; | ||
var basename = entry.basename; | ||
var pathname = entry.pathname; | ||
var search = entry.search; | ||
if (current < entries.length) entries.splice(current); | ||
var path = (basename || '') + pathname + (search || ''); | ||
entries.push(location); | ||
var key = undefined, | ||
state = undefined; | ||
if (entry.key) { | ||
key = entry.key; | ||
state = readState(key); | ||
} else { | ||
key = history.createKey(); | ||
state = null; | ||
entry.key = key; | ||
} | ||
saveState(location.key, location.state); | ||
}; | ||
var location = parsePath(path); | ||
var replaceLocation = function replaceLocation(location) { | ||
entries[current] = location; | ||
saveState(location.key, location.state); | ||
}; | ||
return history.createLocation(_extends({}, location, { state: state }), undefined, key); | ||
} | ||
var history = (0, _createHistory2.default)(_extends({}, options, { | ||
getCurrentLocation: getCurrentLocation, | ||
pushLocation: pushLocation, | ||
replaceLocation: replaceLocation, | ||
go: go | ||
})); | ||
function canGo(n) { | ||
var index = current + n; | ||
return index >= 0 && index < entries.length; | ||
} | ||
var entries = options.entries; | ||
var current = options.current; | ||
function go(n) { | ||
if (n) { | ||
if (!canGo(n)) { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'Cannot go(%s) there is not enough history', n) : undefined; | ||
return; | ||
} | ||
current += n; | ||
if (typeof entries === 'string') { | ||
entries = [entries]; | ||
} else if (!Array.isArray(entries)) { | ||
entries = ['/']; | ||
} | ||
var currentLocation = getCurrentLocation(); | ||
entries = entries.map(function (entry) { | ||
return (0, _LocationUtils.createLocation)(entry); | ||
}); | ||
// change action to POP | ||
history.transitionTo(_extends({}, currentLocation, { action: POP })); | ||
} | ||
if (current == null) { | ||
current = entries.length - 1; | ||
} else { | ||
!(current >= 0 && current < entries.length) ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'Current index must be >= 0 and < %s, was %s', entries.length, current) : (0, _invariant2.default)(false) : void 0; | ||
} | ||
function finishTransition(location) { | ||
switch (location.action) { | ||
case PUSH: | ||
current += 1; | ||
var storage = createStateStorage(entries); | ||
// if we are not on the top of stack | ||
// remove rest and push new | ||
if (current < entries.length) entries.splice(current); | ||
var saveState = function saveState(key, state) { | ||
return storage[key] = state; | ||
}; | ||
entries.push(location); | ||
saveState(location.key, location.state); | ||
break; | ||
case REPLACE: | ||
entries[current] = location; | ||
saveState(location.key, location.state); | ||
break; | ||
} | ||
} | ||
var readState = function readState(key) { | ||
return storage[key]; | ||
}; | ||
return history; | ||
} | ||
}; | ||
export default createMemoryHistory; | ||
exports.default = createMemoryHistory; |
@@ -1,18 +0,25 @@ | ||
/*eslint-disable no-empty */ | ||
'use strict'; | ||
export { saveState }; | ||
export { readState }; | ||
import warning from 'warning'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.readState = exports.saveState = undefined; | ||
var KeyPrefix = '@@History/'; | ||
var QuotaExceededErrors = ['QuotaExceededError', 'QUOTA_EXCEEDED_ERR']; | ||
var _warning = require('warning'); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var QuotaExceededErrors = ['QuotaExceededError', 'QUOTA_EXCEEDED_ERR']; /* eslint-disable no-empty */ | ||
var SecurityError = 'SecurityError'; | ||
var KeyPrefix = '@@History/'; | ||
function createKey(key) { | ||
var createKey = function createKey(key) { | ||
return KeyPrefix + key; | ||
} | ||
}; | ||
function saveState(key, state) { | ||
var saveState = exports.saveState = function saveState(key, state) { | ||
try { | ||
@@ -28,3 +35,3 @@ if (state == null) { | ||
// attempt to access window.sessionStorage. | ||
process.env.NODE_ENV !== 'production' ? warning(false, '[history] Unable to save state; sessionStorage is not available due to security settings') : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(false, '[history] Unable to save state; sessionStorage is not available due to security settings') : void 0; | ||
@@ -36,3 +43,3 @@ return; | ||
// Safari "private mode" throws QuotaExceededError. | ||
process.env.NODE_ENV !== 'production' ? warning(false, '[history] Unable to save state; sessionStorage is not available in Safari private mode') : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(false, '[history] Unable to save state; sessionStorage is not available in Safari private mode') : void 0; | ||
@@ -44,6 +51,6 @@ return; | ||
} | ||
} | ||
}; | ||
function readState(key) { | ||
var json = undefined; | ||
var readState = exports.readState = function readState(key) { | ||
var json = void 0; | ||
try { | ||
@@ -55,5 +62,5 @@ json = window.sessionStorage.getItem(createKey(key)); | ||
// attempt to access window.sessionStorage. | ||
process.env.NODE_ENV !== 'production' ? warning(false, '[history] Unable to read state; sessionStorage is not available due to security settings') : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(false, '[history] Unable to read state; sessionStorage is not available due to security settings') : void 0; | ||
return null; | ||
return undefined; | ||
} | ||
@@ -70,3 +77,3 @@ } | ||
return null; | ||
} | ||
return undefined; | ||
}; |
'use strict'; | ||
export { addEventListener }; | ||
export { removeEventListener }; | ||
export { getHashPath }; | ||
export { replaceHashPath }; | ||
export { getWindowPath }; | ||
export { go }; | ||
export { getUserConfirmation }; | ||
export { supportsHistory }; | ||
export { supportsGoWithoutReloadUsingHash }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var addEventListener = exports.addEventListener = function addEventListener(node, event, listener) { | ||
return node.addEventListener ? node.addEventListener(event, listener, false) : node.attachEvent('on' + event, listener); | ||
}; | ||
function addEventListener(node, event, listener) { | ||
if (node.addEventListener) { | ||
node.addEventListener(event, listener, false); | ||
} else { | ||
node.attachEvent('on' + event, listener); | ||
} | ||
} | ||
var removeEventListener = exports.removeEventListener = function removeEventListener(node, event, listener) { | ||
return node.removeEventListener ? node.removeEventListener(event, listener, false) : node.detachEvent('on' + event, listener); | ||
}; | ||
function removeEventListener(node, event, listener) { | ||
if (node.removeEventListener) { | ||
node.removeEventListener(event, listener, false); | ||
} else { | ||
node.detachEvent('on' + event, listener); | ||
} | ||
} | ||
function getHashPath() { | ||
// We can't use window.location.hash here because it's not | ||
// consistent across browsers - Firefox will pre-decode it! | ||
return window.location.href.split('#')[1] || ''; | ||
} | ||
function replaceHashPath(path) { | ||
window.location.replace(window.location.pathname + window.location.search + '#' + path); | ||
} | ||
function getWindowPath() { | ||
return window.location.pathname + window.location.search + window.location.hash; | ||
} | ||
function go(n) { | ||
if (n) window.history.go(n); | ||
} | ||
function getUserConfirmation(message, callback) { | ||
callback(window.confirm(message)); | ||
} | ||
/** | ||
@@ -56,12 +19,11 @@ * Returns true if the HTML5 history API is supported. Taken from Modernizr. | ||
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js | ||
* changed to avoid false negatives for Windows Phones: https://github.com/rackt/react-router/issues/586 | ||
* changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586 | ||
*/ | ||
var supportsHistory = exports.supportsHistory = function supportsHistory() { | ||
var ua = navigator.userAgent; | ||
function supportsHistory() { | ||
var ua = navigator.userAgent; | ||
if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1) { | ||
return false; | ||
} | ||
if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1) return false; | ||
return window.history && 'pushState' in window.history; | ||
} | ||
}; | ||
@@ -71,6 +33,4 @@ /** | ||
*/ | ||
function supportsGoWithoutReloadUsingHash() { | ||
var ua = navigator.userAgent; | ||
return ua.indexOf('Firefox') === -1; | ||
} | ||
var supportsGoWithoutReloadUsingHash = exports.supportsGoWithoutReloadUsingHash = function supportsGoWithoutReloadUsingHash() { | ||
return navigator.userAgent.indexOf('Firefox') === -1; | ||
}; |
'use strict'; | ||
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
export { canUseDOM }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var canUseDOM = exports.canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); |
'use strict'; | ||
import deprecate from './deprecate'; | ||
import _createLocation from './createLocation'; | ||
import _createHistory from './createBrowserHistory'; | ||
export { _createHistory as createHistory }; | ||
import _createHashHistory from './createHashHistory'; | ||
export { _createHashHistory as createHashHistory }; | ||
import _createMemoryHistory from './createMemoryHistory'; | ||
export { _createMemoryHistory as createMemoryHistory }; | ||
import _useBasename from './useBasename'; | ||
export { _useBasename as useBasename }; | ||
import _useBeforeUnload from './useBeforeUnload'; | ||
export { _useBeforeUnload as useBeforeUnload }; | ||
import _useQueries from './useQueries'; | ||
export { _useQueries as useQueries }; | ||
import _Actions from './Actions'; | ||
export { _Actions as Actions }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Actions = exports.useQueries = exports.useBeforeUnload = exports.useBasename = exports.createMemoryHistory = exports.createHashHistory = exports.createHistory = undefined; | ||
// deprecated | ||
import _enableBeforeUnload from './enableBeforeUnload'; | ||
export { _enableBeforeUnload as enableBeforeUnload }; | ||
import _enableQueries from './enableQueries'; | ||
export { _enableQueries as enableQueries }; | ||
var createLocation = deprecate(_createLocation, 'Using createLocation without a history instance is deprecated; please use history.createLocation instead'); | ||
export { createLocation }; | ||
var _createBrowserHistory = require('./createBrowserHistory'); | ||
var _createBrowserHistory2 = _interopRequireDefault(_createBrowserHistory); | ||
var _createHashHistory2 = require('./createHashHistory'); | ||
var _createHashHistory3 = _interopRequireDefault(_createHashHistory2); | ||
var _createMemoryHistory2 = require('./createMemoryHistory'); | ||
var _createMemoryHistory3 = _interopRequireDefault(_createMemoryHistory2); | ||
var _useBasename2 = require('./useBasename'); | ||
var _useBasename3 = _interopRequireDefault(_useBasename2); | ||
var _useBeforeUnload2 = require('./useBeforeUnload'); | ||
var _useBeforeUnload3 = _interopRequireDefault(_useBeforeUnload2); | ||
var _useQueries2 = require('./useQueries'); | ||
var _useQueries3 = _interopRequireDefault(_useQueries2); | ||
var _Actions2 = require('./Actions'); | ||
var _Actions3 = _interopRequireDefault(_Actions2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.createHistory = _createBrowserHistory2.default; | ||
exports.createHashHistory = _createHashHistory3.default; | ||
exports.createMemoryHistory = _createMemoryHistory3.default; | ||
exports.useBasename = _useBasename3.default; | ||
exports.useBeforeUnload = _useBeforeUnload3.default; | ||
exports.useQueries = _useQueries3.default; | ||
exports.Actions = _Actions3.default; |
'use strict'; | ||
export { extractPath }; | ||
export { parsePath }; | ||
import warning from 'warning'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.createPath = exports.parsePath = exports.getQueryStringValueFromPath = exports.stripQueryStringValueFromPath = exports.addQueryStringValueToPath = exports.isAbsolutePath = undefined; | ||
function extractPath(string) { | ||
var match = string.match(/^https?:\/\/[^\/]*/); | ||
var _warning = require('warning'); | ||
if (match == null) return string; | ||
var _warning2 = _interopRequireDefault(_warning); | ||
return string.substring(match[0].length); | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function parsePath(path) { | ||
var isAbsolutePath = exports.isAbsolutePath = function isAbsolutePath(path) { | ||
return typeof path === 'string' && path.charAt(0) === '/'; | ||
}; | ||
var addQueryStringValueToPath = exports.addQueryStringValueToPath = function addQueryStringValueToPath(path, key, value) { | ||
var _parsePath = parsePath(path); | ||
var pathname = _parsePath.pathname; | ||
var search = _parsePath.search; | ||
var hash = _parsePath.hash; | ||
return createPath({ | ||
pathname: pathname, | ||
search: search + (search.indexOf('?') === -1 ? '?' : '&') + key + '=' + value, | ||
hash: hash | ||
}); | ||
}; | ||
var stripQueryStringValueFromPath = exports.stripQueryStringValueFromPath = function stripQueryStringValueFromPath(path, key) { | ||
var _parsePath2 = parsePath(path); | ||
var pathname = _parsePath2.pathname; | ||
var search = _parsePath2.search; | ||
var hash = _parsePath2.hash; | ||
return createPath({ | ||
pathname: pathname, | ||
search: search.replace(new RegExp('([?&])' + key + '=[a-zA-Z0-9]+(&?)'), function (match, prefix, suffix) { | ||
return prefix === '?' ? prefix : suffix; | ||
}), | ||
hash: hash | ||
}); | ||
}; | ||
var getQueryStringValueFromPath = exports.getQueryStringValueFromPath = function getQueryStringValueFromPath(path, key) { | ||
var _parsePath3 = parsePath(path); | ||
var search = _parsePath3.search; | ||
var match = search.match(new RegExp('[?&]' + key + '=([a-zA-Z0-9]+)')); | ||
return match && match[1]; | ||
}; | ||
var extractPath = function extractPath(string) { | ||
var match = string.match(/^https?:\/\/[^\/]*/); | ||
return match == null ? string : string.substring(match[0].length); | ||
}; | ||
var parsePath = exports.parsePath = function parsePath(path) { | ||
var pathname = extractPath(path); | ||
@@ -20,3 +69,3 @@ var search = ''; | ||
process.env.NODE_ENV !== 'production' ? warning(path === pathname, 'A path must be pathname + search + hash only, not a fully qualified URL like "%s"', path) : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(path === pathname, 'A path must be pathname + search + hash only, not a fully qualified URL like "%s"', path) : void 0; | ||
@@ -42,2 +91,19 @@ var hashIndex = pathname.indexOf('#'); | ||
}; | ||
} | ||
}; | ||
var createPath = exports.createPath = function createPath(location) { | ||
if (location == null || typeof location === 'string') return location; | ||
var basename = location.basename; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var hash = location.hash; | ||
var path = (basename || '') + pathname; | ||
if (search && search !== '?') path += search; | ||
if (hash) path += hash; | ||
return path; | ||
}; |
'use strict'; | ||
import warning from 'warning'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function runTransitionHook(hook, location, callback) { | ||
var _warning = require('warning'); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var runTransitionHook = function runTransitionHook(hook, location, callback) { | ||
var result = hook(location, callback); | ||
@@ -13,6 +21,6 @@ | ||
} else { | ||
process.env.NODE_ENV !== 'production' ? warning(result === undefined, 'You should not "return" in a transition hook with a callback argument; call the callback instead') : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(result === undefined, 'You should not "return" in a transition hook with a callback argument; ' + 'call the callback instead') : void 0; | ||
} | ||
} | ||
}; | ||
export default runTransitionHook; | ||
exports.default = runTransitionHook; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
import { canUseDOM } from './ExecutionEnvironment'; | ||
import { extractPath, parsePath } from './PathUtils'; | ||
import runTransitionHook from './runTransitionHook'; | ||
import deprecate from './deprecate'; | ||
var _ExecutionEnvironment = require('./ExecutionEnvironment'); | ||
function useBasename(createHistory) { | ||
var _runTransitionHook = require('./runTransitionHook'); | ||
var _runTransitionHook2 = _interopRequireDefault(_runTransitionHook); | ||
var _PathUtils = require('./PathUtils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var useBasename = function useBasename(createHistory) { | ||
return function () { | ||
@@ -15,3 +24,2 @@ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var history = createHistory(options); | ||
var basename = options.basename; | ||
@@ -21,9 +29,12 @@ | ||
// documents as basename if it's not explicitly given. | ||
if (basename == null && canUseDOM) { | ||
if (basename == null && _ExecutionEnvironment.canUseDOM) { | ||
var base = document.getElementsByTagName('base')[0]; | ||
if (base) basename = extractPath(base.href); | ||
if (base) basename = base.getAttribute('href'); | ||
} | ||
function addBasename(location) { | ||
var addBasename = function addBasename(location) { | ||
if (!location) return location; | ||
if (basename && location.basename == null) { | ||
@@ -41,10 +52,9 @@ if (location.pathname.indexOf(basename) === 0) { | ||
return location; | ||
} | ||
}; | ||
function prependBasename(location) { | ||
var prependBasename = function prependBasename(location) { | ||
if (!basename) return location; | ||
if (typeof location === 'string') location = parsePath(location); | ||
var pname = location.pathname; | ||
var object = typeof location === 'string' ? (0, _PathUtils.parsePath)(location) : location; | ||
var pname = object.pathname; | ||
var normalizedBasename = basename.slice(-1) === '/' ? basename : basename + '/'; | ||
@@ -57,35 +67,39 @@ var normalizedPathname = pname.charAt(0) === '/' ? pname.slice(1) : pname; | ||
}); | ||
} | ||
}; | ||
// Override all read methods with basename-aware versions. | ||
function listenBefore(hook) { | ||
var getCurrentLocation = function getCurrentLocation() { | ||
return addBasename(history.getCurrentLocation()); | ||
}; | ||
var listenBefore = function listenBefore(hook) { | ||
return history.listenBefore(function (location, callback) { | ||
runTransitionHook(hook, addBasename(location), callback); | ||
return (0, _runTransitionHook2.default)(hook, addBasename(location), callback); | ||
}); | ||
} | ||
}; | ||
function listen(listener) { | ||
var listen = function listen(listener) { | ||
return history.listen(function (location) { | ||
listener(addBasename(location)); | ||
return listener(addBasename(location)); | ||
}); | ||
} | ||
}; | ||
// Override all write methods with basename-aware versions. | ||
function push(location) { | ||
history.push(prependBasename(location)); | ||
} | ||
var push = function push(location) { | ||
return history.push(prependBasename(location)); | ||
}; | ||
function replace(location) { | ||
history.replace(prependBasename(location)); | ||
} | ||
var replace = function replace(location) { | ||
return history.replace(prependBasename(location)); | ||
}; | ||
function createPath(location) { | ||
var createPath = function createPath(location) { | ||
return history.createPath(prependBasename(location)); | ||
} | ||
}; | ||
function createHref(location) { | ||
var createHref = function createHref(location) { | ||
return history.createHref(prependBasename(location)); | ||
} | ||
}; | ||
function createLocation(location) { | ||
var createLocation = function createLocation(location) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -96,19 +110,6 @@ args[_key - 1] = arguments[_key]; | ||
return addBasename(history.createLocation.apply(history, [prependBasename(location)].concat(args))); | ||
} | ||
}; | ||
// deprecated | ||
function pushState(state, path) { | ||
if (typeof path === 'string') path = parsePath(path); | ||
push(_extends({ state: state }, path)); | ||
} | ||
// deprecated | ||
function replaceState(state, path) { | ||
if (typeof path === 'string') path = parsePath(path); | ||
replace(_extends({ state: state }, path)); | ||
} | ||
return _extends({}, history, { | ||
getCurrentLocation: getCurrentLocation, | ||
listenBefore: listenBefore, | ||
@@ -120,10 +121,7 @@ listen: listen, | ||
createHref: createHref, | ||
createLocation: createLocation, | ||
pushState: deprecate(pushState, 'pushState is deprecated; use push instead'), | ||
replaceState: deprecate(replaceState, 'replaceState is deprecated; use replace instead') | ||
createLocation: createLocation | ||
}); | ||
}; | ||
} | ||
}; | ||
export default useBasename; | ||
exports.default = useBasename; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
import warning from 'warning'; | ||
import { canUseDOM } from './ExecutionEnvironment'; | ||
import { addEventListener, removeEventListener } from './DOMUtils'; | ||
import deprecate from './deprecate'; | ||
var _invariant = require('invariant'); | ||
function startBeforeUnloadListener(getBeforeUnloadPromptMessage) { | ||
function listener(event) { | ||
var message = getBeforeUnloadPromptMessage(); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _DOMUtils = require('./DOMUtils'); | ||
var _ExecutionEnvironment = require('./ExecutionEnvironment'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var startListener = function startListener(getPromptMessage) { | ||
var handleBeforeUnload = function handleBeforeUnload(event) { | ||
var message = getPromptMessage(); | ||
if (typeof message === 'string') { | ||
@@ -18,10 +27,12 @@ (event || window.event).returnValue = message; | ||
} | ||
} | ||
addEventListener(window, 'beforeunload', listener); | ||
return undefined; | ||
}; | ||
(0, _DOMUtils.addEventListener)(window, 'beforeunload', handleBeforeUnload); | ||
return function () { | ||
removeEventListener(window, 'beforeunload', listener); | ||
return (0, _DOMUtils.removeEventListener)(window, 'beforeunload', handleBeforeUnload); | ||
}; | ||
} | ||
}; | ||
@@ -33,69 +44,39 @@ /** | ||
*/ | ||
function useBeforeUnload(createHistory) { | ||
var useBeforeUnload = function useBeforeUnload(createHistory) { | ||
!_ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'useBeforeUnload only works in DOM environments') : (0, _invariant2.default)(false) : void 0; | ||
return function (options) { | ||
var history = createHistory(options); | ||
var stopBeforeUnloadListener = undefined; | ||
var beforeUnloadHooks = []; | ||
var listeners = []; | ||
var stopListener = void 0; | ||
function getBeforeUnloadPromptMessage() { | ||
var message = undefined; | ||
for (var i = 0, len = beforeUnloadHooks.length; message == null && i < len; ++i) { | ||
message = beforeUnloadHooks[i].call(); | ||
var getPromptMessage = function getPromptMessage() { | ||
var message = void 0; | ||
for (var i = 0, len = listeners.length; message == null && i < len; ++i) { | ||
message = listeners[i].call(); | ||
}return message; | ||
} | ||
}; | ||
function listenBeforeUnload(hook) { | ||
beforeUnloadHooks.push(hook); | ||
var listenBeforeUnload = function listenBeforeUnload(listener) { | ||
if (listeners.push(listener) === 1) stopListener = startListener(getPromptMessage); | ||
if (beforeUnloadHooks.length === 1) { | ||
if (canUseDOM) { | ||
stopBeforeUnloadListener = startBeforeUnloadListener(getBeforeUnloadPromptMessage); | ||
} else { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'listenBeforeUnload only works in DOM environments') : undefined; | ||
} | ||
} | ||
return function () { | ||
beforeUnloadHooks = beforeUnloadHooks.filter(function (item) { | ||
return item !== hook; | ||
listeners = listeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
if (beforeUnloadHooks.length === 0 && stopBeforeUnloadListener) { | ||
stopBeforeUnloadListener(); | ||
stopBeforeUnloadListener = null; | ||
if (listeners.length === 0 && stopListener) { | ||
stopListener(); | ||
stopListener = null; | ||
} | ||
}; | ||
} | ||
}; | ||
// deprecated | ||
function registerBeforeUnloadHook(hook) { | ||
if (canUseDOM && beforeUnloadHooks.indexOf(hook) === -1) { | ||
beforeUnloadHooks.push(hook); | ||
if (beforeUnloadHooks.length === 1) stopBeforeUnloadListener = startBeforeUnloadListener(getBeforeUnloadPromptMessage); | ||
} | ||
} | ||
// deprecated | ||
function unregisterBeforeUnloadHook(hook) { | ||
if (beforeUnloadHooks.length > 0) { | ||
beforeUnloadHooks = beforeUnloadHooks.filter(function (item) { | ||
return item !== hook; | ||
}); | ||
if (beforeUnloadHooks.length === 0) stopBeforeUnloadListener(); | ||
} | ||
} | ||
return _extends({}, history, { | ||
listenBeforeUnload: listenBeforeUnload, | ||
registerBeforeUnloadHook: deprecate(registerBeforeUnloadHook, 'registerBeforeUnloadHook is deprecated; use listenBeforeUnload instead'), | ||
unregisterBeforeUnloadHook: deprecate(unregisterBeforeUnloadHook, 'unregisterBeforeUnloadHook is deprecated; use the callback returned from listenBeforeUnload instead') | ||
listenBeforeUnload: listenBeforeUnload | ||
}); | ||
}; | ||
} | ||
}; | ||
export default useBeforeUnload; | ||
exports.default = useBeforeUnload; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
import warning from 'warning'; | ||
import { parse, stringify } from 'query-string'; | ||
import runTransitionHook from './runTransitionHook'; | ||
import { parsePath } from './PathUtils'; | ||
import deprecate from './deprecate'; | ||
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 SEARCH_BASE_KEY = '$searchBase'; | ||
var _warning = require('warning'); | ||
function defaultStringifyQuery(query) { | ||
return stringify(query).replace(/%20/g, '+'); | ||
} | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var defaultParseQueryString = parse; | ||
var _queryString = require('query-string'); | ||
function isNestedObject(object) { | ||
var _runTransitionHook = require('./runTransitionHook'); | ||
var _runTransitionHook2 = _interopRequireDefault(_runTransitionHook); | ||
var _PathUtils = require('./PathUtils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var defaultStringifyQuery = function defaultStringifyQuery(query) { | ||
return (0, _queryString.stringify)(query).replace(/%20/g, '+'); | ||
}; | ||
var defaultParseQueryString = _queryString.parse; | ||
var isNestedObject = function isNestedObject(object) { | ||
for (var p in object) { | ||
if (object.hasOwnProperty(p) && typeof object[p] === 'object' && !Array.isArray(object[p]) && object[p] !== null) return true; | ||
}return false; | ||
} | ||
if (object.hasOwnProperty(p) && _typeof(object[p]) === 'object' && !Array.isArray(object[p]) && object[p] !== null) return true; | ||
} | ||
return false; | ||
}; | ||
/** | ||
@@ -29,3 +43,3 @@ * Returns a new createHistory function that may be used to create | ||
*/ | ||
function useQueries(createHistory) { | ||
var useQueries = function useQueries(createHistory) { | ||
return function () { | ||
@@ -35,6 +49,6 @@ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var history = createHistory(options); | ||
var stringifyQuery = options.stringifyQuery; | ||
var parseQueryString = options.parseQueryString; | ||
if (typeof stringifyQuery !== 'function') stringifyQuery = defaultStringifyQuery; | ||
@@ -44,81 +58,59 @@ | ||
function addQuery(location) { | ||
if (location.query == null) { | ||
var search = location.search; | ||
var decodeQuery = function decodeQuery(location) { | ||
if (!location) return location; | ||
location.query = parseQueryString(search.substring(1)); | ||
location[SEARCH_BASE_KEY] = { search: search, searchBase: '' }; | ||
} | ||
if (location.query == null) location.query = parseQueryString(location.search.substring(1)); | ||
// TODO: Instead of all the book-keeping here, this should just strip the | ||
// stringified query from the search. | ||
return location; | ||
} | ||
}; | ||
function appendQuery(location, query) { | ||
var _extends2; | ||
var encodeQuery = function encodeQuery(location, query) { | ||
if (query == null) return location; | ||
var searchBaseSpec = location[SEARCH_BASE_KEY]; | ||
var queryString = query ? stringifyQuery(query) : ''; | ||
if (!searchBaseSpec && !queryString) { | ||
return location; | ||
} | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(stringifyQuery !== defaultStringifyQuery || !isNestedObject(query), 'useQueries does not stringify nested query objects by default; ' + 'use a custom stringifyQuery function') : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(stringifyQuery !== defaultStringifyQuery || !isNestedObject(query), 'useQueries does not stringify nested query objects by default; ' + 'use a custom stringifyQuery function') : undefined; | ||
var object = typeof location === 'string' ? (0, _PathUtils.parsePath)(location) : location; | ||
var queryString = stringifyQuery(query); | ||
var search = queryString ? '?' + queryString : ''; | ||
if (typeof location === 'string') location = parsePath(location); | ||
var searchBase = undefined; | ||
if (searchBaseSpec && location.search === searchBaseSpec.search) { | ||
searchBase = searchBaseSpec.searchBase; | ||
} else { | ||
searchBase = location.search || ''; | ||
} | ||
var search = searchBase; | ||
if (queryString) { | ||
search += (search ? '&' : '?') + queryString; | ||
} | ||
return _extends({}, location, (_extends2 = { | ||
return _extends({}, object, { | ||
search: search | ||
}, _extends2[SEARCH_BASE_KEY] = { search: search, searchBase: searchBase }, _extends2)); | ||
} | ||
}); | ||
}; | ||
// Override all read methods with query-aware versions. | ||
function listenBefore(hook) { | ||
var getCurrentLocation = function getCurrentLocation() { | ||
return decodeQuery(history.getCurrentLocation()); | ||
}; | ||
var listenBefore = function listenBefore(hook) { | ||
return history.listenBefore(function (location, callback) { | ||
runTransitionHook(hook, addQuery(location), callback); | ||
return (0, _runTransitionHook2.default)(hook, decodeQuery(location), callback); | ||
}); | ||
} | ||
}; | ||
function listen(listener) { | ||
var listen = function listen(listener) { | ||
return history.listen(function (location) { | ||
listener(addQuery(location)); | ||
return listener(decodeQuery(location)); | ||
}); | ||
} | ||
}; | ||
// Override all write methods with query-aware versions. | ||
function push(location) { | ||
history.push(appendQuery(location, location.query)); | ||
} | ||
var push = function push(location) { | ||
return history.push(encodeQuery(location, location.query)); | ||
}; | ||
function replace(location) { | ||
history.replace(appendQuery(location, location.query)); | ||
} | ||
var replace = function replace(location) { | ||
return history.replace(encodeQuery(location, location.query)); | ||
}; | ||
function createPath(location, query) { | ||
process.env.NODE_ENV !== 'production' ? warning(!query, 'the query argument to createPath is deprecated; use a location descriptor instead') : undefined; | ||
var createPath = function createPath(location) { | ||
return history.createPath(encodeQuery(location, location.query)); | ||
}; | ||
return history.createPath(appendQuery(location, query || location.query)); | ||
} | ||
var createHref = function createHref(location) { | ||
return history.createHref(encodeQuery(location, location.query)); | ||
}; | ||
function createHref(location, query) { | ||
process.env.NODE_ENV !== 'production' ? warning(!query, 'the query argument to createHref is deprecated; use a location descriptor instead') : undefined; | ||
return history.createHref(appendQuery(location, query || location.query)); | ||
} | ||
function createLocation(location) { | ||
var createLocation = function createLocation(location) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -128,24 +120,11 @@ args[_key - 1] = arguments[_key]; | ||
var fullLocation = history.createLocation.apply(history, [appendQuery(location, location.query)].concat(args)); | ||
if (location.query) { | ||
fullLocation.query = location.query; | ||
} | ||
return addQuery(fullLocation); | ||
} | ||
var newLocation = history.createLocation.apply(history, [encodeQuery(location, location.query)].concat(args)); | ||
// deprecated | ||
function pushState(state, path, query) { | ||
if (typeof path === 'string') path = parsePath(path); | ||
if (location.query) newLocation.query = location.query; | ||
push(_extends({ state: state }, path, { query: query })); | ||
} | ||
return decodeQuery(newLocation); | ||
}; | ||
// deprecated | ||
function replaceState(state, path, query) { | ||
if (typeof path === 'string') path = parsePath(path); | ||
replace(_extends({ state: state }, path, { query: query })); | ||
} | ||
return _extends({}, history, { | ||
getCurrentLocation: getCurrentLocation, | ||
listenBefore: listenBefore, | ||
@@ -157,10 +136,7 @@ listen: listen, | ||
createHref: createHref, | ||
createLocation: createLocation, | ||
pushState: deprecate(pushState, 'pushState is deprecated; use push instead'), | ||
replaceState: deprecate(replaceState, 'replaceState is deprecated; use replace instead') | ||
createLocation: createLocation | ||
}); | ||
}; | ||
} | ||
}; | ||
export default useQueries; | ||
exports.default = useQueries; |
@@ -0,16 +1,16 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
/** | ||
* Indicates that navigation was caused by a call to history.push. | ||
*/ | ||
'use strict'; | ||
var PUSH = exports.PUSH = 'PUSH'; | ||
exports.__esModule = true; | ||
var PUSH = 'PUSH'; | ||
exports.PUSH = PUSH; | ||
/** | ||
* Indicates that navigation was caused by a call to history.replace. | ||
*/ | ||
var REPLACE = 'REPLACE'; | ||
var REPLACE = exports.REPLACE = 'REPLACE'; | ||
exports.REPLACE = REPLACE; | ||
/** | ||
@@ -24,9 +24,2 @@ * Indicates that navigation was caused by some other action such | ||
*/ | ||
var POP = 'POP'; | ||
exports.POP = POP; | ||
exports['default'] = { | ||
PUSH: PUSH, | ||
REPLACE: REPLACE, | ||
POP: POP | ||
}; | ||
var POP = exports.POP = 'POP'; |
"use strict"; | ||
exports.__esModule = true; | ||
var _slice = Array.prototype.slice; | ||
exports.loopAsync = loopAsync; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function loopAsync(turns, work, callback) { | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var loopAsync = exports.loopAsync = function loopAsync(turns, work, callback) { | ||
var currentTurn = 0, | ||
isDone = false; | ||
var sync = false, | ||
var isSync = false, | ||
hasNext = false, | ||
doneArgs = undefined; | ||
doneArgs = void 0; | ||
function done() { | ||
var done = function done() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
isDone = true; | ||
if (sync) { | ||
if (isSync) { | ||
// Iterate instead of recursing if possible. | ||
doneArgs = [].concat(_slice.call(arguments)); | ||
doneArgs = args; | ||
return; | ||
} | ||
callback.apply(this, arguments); | ||
} | ||
callback.apply(undefined, args); | ||
}; | ||
function next() { | ||
if (isDone) { | ||
return; | ||
} | ||
var next = function next() { | ||
if (isDone) return; | ||
hasNext = true; | ||
if (sync) { | ||
// Iterate instead of recursing if possible. | ||
return; | ||
} | ||
sync = true; | ||
if (isSync) return; // Iterate instead of recursing if possible. | ||
isSync = true; | ||
while (!isDone && currentTurn < turns && hasNext) { | ||
hasNext = false; | ||
work.call(this, currentTurn++, next, done); | ||
work.call(undefined, currentTurn++, next, done); | ||
} | ||
sync = false; | ||
isSync = false; | ||
if (isDone) { | ||
// This means the loop finished synchronously. | ||
callback.apply(this, doneArgs); | ||
callback.apply(undefined, _toConsumableArray(doneArgs)); | ||
return; | ||
@@ -55,5 +58,5 @@ } | ||
} | ||
} | ||
}; | ||
next(); | ||
} | ||
}; |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _invariant = require('invariant'); | ||
@@ -13,16 +13,22 @@ | ||
var _Actions = require('./Actions'); | ||
var _ExecutionEnvironment = require('./ExecutionEnvironment'); | ||
var _PathUtils = require('./PathUtils'); | ||
var _BrowserProtocol = require('./BrowserProtocol'); | ||
var _ExecutionEnvironment = require('./ExecutionEnvironment'); | ||
var BrowserProtocol = _interopRequireWildcard(_BrowserProtocol); | ||
var _RefreshProtocol = require('./RefreshProtocol'); | ||
var RefreshProtocol = _interopRequireWildcard(_RefreshProtocol); | ||
var _DOMUtils = require('./DOMUtils'); | ||
var _DOMStateStorage = require('./DOMStateStorage'); | ||
var _createHistory = require('./createHistory'); | ||
var _createDOMHistory = require('./createDOMHistory'); | ||
var _createHistory2 = _interopRequireDefault(_createHistory); | ||
var _createDOMHistory2 = _interopRequireDefault(_createDOMHistory); | ||
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 }; } | ||
/** | ||
@@ -35,101 +41,36 @@ * Creates and returns a history object that uses HTML5's history API | ||
* Note: In browsers that do not support the HTML5 history API full | ||
* page reloads will be used to preserve URLs. | ||
* page reloads will be used to preserve clean URLs. You can force this | ||
* behavior using { forceRefresh: true } in options. | ||
*/ | ||
function createBrowserHistory() { | ||
var createBrowserHistory = function createBrowserHistory() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
!_ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? _invariant2['default'](false, 'Browser history needs a DOM') : _invariant2['default'](false) : undefined; | ||
!_ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'Browser history needs a DOM') : (0, _invariant2.default)(false) : void 0; | ||
var forceRefresh = options.forceRefresh; | ||
var useRefresh = options.forceRefresh || !(0, _DOMUtils.supportsHistory)(); | ||
var Protocol = useRefresh ? RefreshProtocol : BrowserProtocol; | ||
var isSupported = _DOMUtils.supportsHistory(); | ||
var useRefresh = !isSupported || forceRefresh; | ||
var getUserConfirmation = Protocol.getUserConfirmation; | ||
var getCurrentLocation = Protocol.getCurrentLocation; | ||
var pushLocation = Protocol.pushLocation; | ||
var replaceLocation = Protocol.replaceLocation; | ||
var go = Protocol.go; | ||
function getCurrentLocation(historyState) { | ||
historyState = historyState || window.history.state || {}; | ||
var path = _DOMUtils.getWindowPath(); | ||
var _historyState = historyState; | ||
var key = _historyState.key; | ||
var state = undefined; | ||
if (key) { | ||
state = _DOMStateStorage.readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
if (isSupported) window.history.replaceState(_extends({}, historyState, { key: key }), null, path); | ||
} | ||
var location = _PathUtils.parsePath(path); | ||
return history.createLocation(_extends({}, location, { state: state }), undefined, key); | ||
} | ||
function startPopStateListener(_ref) { | ||
var transitionTo = _ref.transitionTo; | ||
function popStateListener(event) { | ||
if (event.state === undefined) return; // Ignore extraneous popstate events in WebKit. | ||
transitionTo(getCurrentLocation(event.state)); | ||
} | ||
_DOMUtils.addEventListener(window, 'popstate', popStateListener); | ||
return function () { | ||
_DOMUtils.removeEventListener(window, 'popstate', popStateListener); | ||
}; | ||
} | ||
function finishTransition(location) { | ||
var basename = location.basename; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var hash = location.hash; | ||
var state = location.state; | ||
var action = location.action; | ||
var key = location.key; | ||
if (action === _Actions.POP) return; // Nothing to do. | ||
_DOMStateStorage.saveState(key, state); | ||
var path = (basename || '') + pathname + search + hash; | ||
var historyState = { | ||
key: key | ||
}; | ||
if (action === _Actions.PUSH) { | ||
if (useRefresh) { | ||
window.location.href = path; | ||
return false; // Prevent location update. | ||
} else { | ||
window.history.pushState(historyState, null, path); | ||
} | ||
} else { | ||
// REPLACE | ||
if (useRefresh) { | ||
window.location.replace(path); | ||
return false; // Prevent location update. | ||
} else { | ||
window.history.replaceState(historyState, null, path); | ||
} | ||
} | ||
} | ||
var history = _createDOMHistory2['default'](_extends({}, options, { | ||
var history = (0, _createHistory2.default)(_extends({ | ||
getUserConfirmation: getUserConfirmation }, options, { | ||
getCurrentLocation: getCurrentLocation, | ||
finishTransition: finishTransition, | ||
saveState: _DOMStateStorage.saveState | ||
pushLocation: pushLocation, | ||
replaceLocation: replaceLocation, | ||
go: go | ||
})); | ||
/* eslint-ignore prefer-const */ | ||
var listenerCount = 0, | ||
stopPopStateListener = undefined; | ||
stopListener = void 0; | ||
function listenBefore(listener) { | ||
if (++listenerCount === 1) stopPopStateListener = startPopStateListener(history); | ||
var startListener = function startListener(listener, before) { | ||
if (++listenerCount === 1) stopListener = BrowserProtocol.startListener(history.transitionTo); | ||
var unlisten = history.listenBefore(listener); | ||
var unlisten = before ? history.listenBefore(listener) : history.listen(listener); | ||
@@ -139,41 +80,20 @@ return function () { | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
if (--listenerCount === 0) stopListener(); | ||
}; | ||
} | ||
}; | ||
function listen(listener) { | ||
if (++listenerCount === 1) stopPopStateListener = startPopStateListener(history); | ||
var listenBefore = function listenBefore(listener) { | ||
return startListener(listener, true); | ||
}; | ||
var unlisten = history.listen(listener); | ||
var listen = function listen(listener) { | ||
return startListener(listener, false); | ||
}; | ||
return function () { | ||
unlisten(); | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
}; | ||
} | ||
// deprecated | ||
function registerTransitionHook(hook) { | ||
if (++listenerCount === 1) stopPopStateListener = startPopStateListener(history); | ||
history.registerTransitionHook(hook); | ||
} | ||
// deprecated | ||
function unregisterTransitionHook(hook) { | ||
history.unregisterTransitionHook(hook); | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
} | ||
return _extends({}, history, { | ||
listenBefore: listenBefore, | ||
listen: listen, | ||
registerTransitionHook: registerTransitionHook, | ||
unregisterTransitionHook: unregisterTransitionHook | ||
listen: listen | ||
}); | ||
} | ||
}; | ||
exports['default'] = createBrowserHistory; | ||
module.exports = exports['default']; | ||
exports.default = createBrowserHistory; |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _warning = require('warning'); | ||
@@ -17,6 +17,2 @@ | ||
var _Actions = require('./Actions'); | ||
var _PathUtils = require('./PathUtils'); | ||
var _ExecutionEnvironment = require('./ExecutionEnvironment'); | ||
@@ -26,135 +22,58 @@ | ||
var _DOMStateStorage = require('./DOMStateStorage'); | ||
var _HashProtocol = require('./HashProtocol'); | ||
var _createDOMHistory = require('./createDOMHistory'); | ||
var HashProtocol = _interopRequireWildcard(_HashProtocol); | ||
var _createDOMHistory2 = _interopRequireDefault(_createDOMHistory); | ||
var _createHistory = require('./createHistory'); | ||
function isAbsolutePath(path) { | ||
return typeof path === 'string' && path.charAt(0) === '/'; | ||
} | ||
var _createHistory2 = _interopRequireDefault(_createHistory); | ||
function ensureSlash() { | ||
var path = _DOMUtils.getHashPath(); | ||
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; } } | ||
if (isAbsolutePath(path)) return true; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
_DOMUtils.replaceHashPath('/' + path); | ||
return false; | ||
} | ||
function addQueryStringValueToPath(path, key, value) { | ||
return path + (path.indexOf('?') === -1 ? '?' : '&') + (key + '=' + value); | ||
} | ||
function stripQueryStringValueFromPath(path, key) { | ||
return path.replace(new RegExp('[?&]?' + key + '=[a-zA-Z0-9]+'), ''); | ||
} | ||
function getQueryStringValueFromPath(path, key) { | ||
var match = path.match(new RegExp('\\?.*?\\b' + key + '=(.+?)\\b')); | ||
return match && match[1]; | ||
} | ||
var DefaultQueryKey = '_k'; | ||
function createHashHistory() { | ||
var createHashHistory = function createHashHistory() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
!_ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? _invariant2['default'](false, 'Hash history needs a DOM') : _invariant2['default'](false) : undefined; | ||
!_ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'Hash history needs a DOM') : (0, _invariant2.default)(false) : void 0; | ||
var queryKey = options.queryKey; | ||
if (queryKey === undefined || !!queryKey) queryKey = typeof queryKey === 'string' ? queryKey : DefaultQueryKey; | ||
function getCurrentLocation() { | ||
var path = _DOMUtils.getHashPath(); | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(queryKey !== false, 'Using { queryKey: false } no longer works. Instead, just don\'t ' + 'use location state if you don\'t want a key in your URL query string') : void 0; | ||
var key = undefined, | ||
state = undefined; | ||
if (queryKey) { | ||
key = getQueryStringValueFromPath(path, queryKey); | ||
path = stripQueryStringValueFromPath(path, queryKey); | ||
if (typeof queryKey !== 'string') queryKey = DefaultQueryKey; | ||
if (key) { | ||
state = _DOMStateStorage.readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
_DOMUtils.replaceHashPath(addQueryStringValueToPath(path, queryKey, key)); | ||
} | ||
} else { | ||
key = state = null; | ||
} | ||
var getUserConfirmation = HashProtocol.getUserConfirmation; | ||
var location = _PathUtils.parsePath(path); | ||
return history.createLocation(_extends({}, location, { state: state }), undefined, key); | ||
} | ||
var getCurrentLocation = function getCurrentLocation() { | ||
return HashProtocol.getCurrentLocation(queryKey); | ||
}; | ||
function startHashChangeListener(_ref) { | ||
var transitionTo = _ref.transitionTo; | ||
var pushLocation = function pushLocation(location) { | ||
return HashProtocol.pushLocation(location, queryKey); | ||
}; | ||
function hashChangeListener() { | ||
if (!ensureSlash()) return; // Always make sure hashes are preceeded with a /. | ||
var replaceLocation = function replaceLocation(location) { | ||
return HashProtocol.replaceLocation(location, queryKey); | ||
}; | ||
transitionTo(getCurrentLocation()); | ||
} | ||
ensureSlash(); | ||
_DOMUtils.addEventListener(window, 'hashchange', hashChangeListener); | ||
return function () { | ||
_DOMUtils.removeEventListener(window, 'hashchange', hashChangeListener); | ||
}; | ||
} | ||
function finishTransition(location) { | ||
var basename = location.basename; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var state = location.state; | ||
var action = location.action; | ||
var key = location.key; | ||
if (action === _Actions.POP) return; // Nothing to do. | ||
var path = (basename || '') + pathname + search; | ||
if (queryKey) { | ||
path = addQueryStringValueToPath(path, queryKey, key); | ||
_DOMStateStorage.saveState(key, state); | ||
} else { | ||
// Drop key and state. | ||
location.key = location.state = null; | ||
} | ||
var currentHash = _DOMUtils.getHashPath(); | ||
if (action === _Actions.PUSH) { | ||
if (currentHash !== path) { | ||
window.location.hash = path; | ||
} else { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](false, 'You cannot PUSH the same path using hash history') : undefined; | ||
} | ||
} else if (currentHash !== path) { | ||
// REPLACE | ||
_DOMUtils.replaceHashPath(path); | ||
} | ||
} | ||
var history = _createDOMHistory2['default'](_extends({}, options, { | ||
var history = (0, _createHistory2.default)(_extends({ | ||
getUserConfirmation: getUserConfirmation }, options, { | ||
getCurrentLocation: getCurrentLocation, | ||
finishTransition: finishTransition, | ||
saveState: _DOMStateStorage.saveState | ||
pushLocation: pushLocation, | ||
replaceLocation: replaceLocation, | ||
go: HashProtocol.go | ||
})); | ||
var listenerCount = 0, | ||
stopHashChangeListener = undefined; | ||
stopListener = void 0; | ||
function listenBefore(listener) { | ||
if (++listenerCount === 1) stopHashChangeListener = startHashChangeListener(history); | ||
var startListener = function startListener(listener, before) { | ||
if (++listenerCount === 1) stopListener = HashProtocol.startListener(history.transitionTo, queryKey); | ||
var unlisten = history.listenBefore(listener); | ||
var unlisten = before ? history.listenBefore(listener) : history.listen(listener); | ||
@@ -164,86 +83,34 @@ return function () { | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
if (--listenerCount === 0) stopListener(); | ||
}; | ||
} | ||
}; | ||
function listen(listener) { | ||
if (++listenerCount === 1) stopHashChangeListener = startHashChangeListener(history); | ||
var listenBefore = function listenBefore(listener) { | ||
return startListener(listener, true); | ||
}; | ||
var unlisten = history.listen(listener); | ||
var listen = function listen(listener) { | ||
return startListener(listener, false); | ||
}; | ||
return function () { | ||
unlisten(); | ||
var goIsSupportedWithoutReload = (0, _DOMUtils.supportsGoWithoutReloadUsingHash)(); | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
}; | ||
} | ||
var go = function go(n) { | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(goIsSupportedWithoutReload, 'Hash history go(n) causes a full page reload in this browser') : void 0; | ||
function push(location) { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](queryKey || location.state == null, 'You cannot use state without a queryKey it will be dropped') : undefined; | ||
history.push(location); | ||
} | ||
function replace(location) { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](queryKey || location.state == null, 'You cannot use state without a queryKey it will be dropped') : undefined; | ||
history.replace(location); | ||
} | ||
var goIsSupportedWithoutReload = _DOMUtils.supportsGoWithoutReloadUsingHash(); | ||
function go(n) { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](goIsSupportedWithoutReload, 'Hash history go(n) causes a full page reload in this browser') : undefined; | ||
history.go(n); | ||
} | ||
}; | ||
function createHref(path) { | ||
var createHref = function createHref(path) { | ||
return '#' + history.createHref(path); | ||
} | ||
}; | ||
// deprecated | ||
function registerTransitionHook(hook) { | ||
if (++listenerCount === 1) stopHashChangeListener = startHashChangeListener(history); | ||
history.registerTransitionHook(hook); | ||
} | ||
// deprecated | ||
function unregisterTransitionHook(hook) { | ||
history.unregisterTransitionHook(hook); | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
} | ||
// deprecated | ||
function pushState(state, path) { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](queryKey || state == null, 'You cannot use state without a queryKey it will be dropped') : undefined; | ||
history.pushState(state, path); | ||
} | ||
// deprecated | ||
function replaceState(state, path) { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](queryKey || state == null, 'You cannot use state without a queryKey it will be dropped') : undefined; | ||
history.replaceState(state, path); | ||
} | ||
return _extends({}, history, { | ||
listenBefore: listenBefore, | ||
listen: listen, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
createHref: createHref, | ||
registerTransitionHook: registerTransitionHook, // deprecated - warning is in createHistory | ||
unregisterTransitionHook: unregisterTransitionHook, // deprecated - warning is in createHistory | ||
pushState: pushState, // deprecated - warning is in createHistory | ||
replaceState: replaceState // deprecated - warning is in createHistory | ||
createHref: createHref | ||
}); | ||
} | ||
}; | ||
exports['default'] = createHashHistory; | ||
module.exports = exports['default']; | ||
exports.default = createHashHistory; |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _warning = require('warning'); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var _deepEqual = require('deep-equal'); | ||
@@ -17,12 +11,6 @@ | ||
var _PathUtils = require('./PathUtils'); | ||
var _AsyncUtils = require('./AsyncUtils'); | ||
var _Actions = require('./Actions'); | ||
var _PathUtils = require('./PathUtils'); | ||
var _createLocation2 = require('./createLocation'); | ||
var _createLocation3 = _interopRequireDefault(_createLocation2); | ||
var _runTransitionHook = require('./runTransitionHook'); | ||
@@ -32,97 +20,74 @@ | ||
var _deprecate = require('./deprecate'); | ||
var _Actions = require('./Actions'); | ||
var _deprecate2 = _interopRequireDefault(_deprecate); | ||
var _LocationUtils = require('./LocationUtils'); | ||
function createRandomKey(length) { | ||
return Math.random().toString(36).substr(2, length); | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function locationsAreEqual(a, b) { | ||
return a.pathname === b.pathname && a.search === b.search && | ||
//a.action === b.action && // Different action !== location change. | ||
a.key === b.key && _deepEqual2['default'](a.state, b.state); | ||
} | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var DefaultKeyLength = 6; | ||
function createHistory() { | ||
var createHistory = function createHistory() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var getCurrentLocation = options.getCurrentLocation; | ||
var finishTransition = options.finishTransition; | ||
var saveState = options.saveState; | ||
var getUserConfirmation = options.getUserConfirmation; | ||
var pushLocation = options.pushLocation; | ||
var replaceLocation = options.replaceLocation; | ||
var go = options.go; | ||
var getUserConfirmation = options.getUserConfirmation; | ||
var keyLength = options.keyLength; | ||
if (typeof keyLength !== 'number') keyLength = DefaultKeyLength; | ||
var transitionHooks = []; | ||
var currentLocation = void 0; | ||
var pendingLocation = void 0; | ||
var beforeListeners = []; | ||
var listeners = []; | ||
var allKeys = []; | ||
function listenBefore(hook) { | ||
transitionHooks.push(hook); | ||
var getCurrentIndex = function getCurrentIndex() { | ||
if (pendingLocation && pendingLocation.action === _Actions.POP) return allKeys.indexOf(pendingLocation.key); | ||
return function () { | ||
transitionHooks = transitionHooks.filter(function (item) { | ||
return item !== hook; | ||
}); | ||
}; | ||
} | ||
if (currentLocation) return allKeys.indexOf(currentLocation.key); | ||
var allKeys = []; | ||
var changeListeners = []; | ||
var location = undefined; | ||
return -1; | ||
}; | ||
function getCurrent() { | ||
if (pendingLocation && pendingLocation.action === _Actions.POP) { | ||
return allKeys.indexOf(pendingLocation.key); | ||
} else if (location) { | ||
return allKeys.indexOf(location.key); | ||
} else { | ||
return -1; | ||
} | ||
} | ||
var updateLocation = function updateLocation(nextLocation) { | ||
currentLocation = nextLocation; | ||
function updateLocation(newLocation) { | ||
var current = getCurrent(); | ||
var currentIndex = getCurrentIndex(); | ||
location = newLocation; | ||
if (location.action === _Actions.PUSH) { | ||
allKeys = [].concat(allKeys.slice(0, current + 1), [location.key]); | ||
} else if (location.action === _Actions.REPLACE) { | ||
allKeys[current] = location.key; | ||
if (currentLocation.action === _Actions.PUSH) { | ||
allKeys = [].concat(_toConsumableArray(allKeys.slice(0, currentIndex + 1)), [currentLocation.key]); | ||
} else if (currentLocation.action === _Actions.REPLACE) { | ||
allKeys[currentIndex] = currentLocation.key; | ||
} | ||
changeListeners.forEach(function (listener) { | ||
listener(location); | ||
listeners.forEach(function (listener) { | ||
return listener(currentLocation); | ||
}); | ||
} | ||
}; | ||
function listen(listener) { | ||
changeListeners.push(listener); | ||
var listenBefore = function listenBefore(listener) { | ||
beforeListeners.push(listener); | ||
if (location) { | ||
listener(location); | ||
} else { | ||
var _location = getCurrentLocation(); | ||
allKeys = [_location.key]; | ||
updateLocation(_location); | ||
} | ||
return function () { | ||
return beforeListeners = beforeListeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
}; | ||
}; | ||
var listen = function listen(listener) { | ||
listeners.push(listener); | ||
return function () { | ||
changeListeners = changeListeners.filter(function (item) { | ||
return listeners = listeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
}; | ||
} | ||
}; | ||
function confirmTransitionTo(location, callback) { | ||
_AsyncUtils.loopAsync(transitionHooks.length, function (index, next, done) { | ||
_runTransitionHook2['default'](transitionHooks[index], location, function (result) { | ||
if (result != null) { | ||
done(result); | ||
} else { | ||
next(); | ||
} | ||
var confirmTransitionTo = function confirmTransitionTo(location, callback) { | ||
(0, _AsyncUtils.loopAsync)(beforeListeners.length, function (index, next, done) { | ||
(0, _runTransitionHook2.default)(beforeListeners[index], location, function (result) { | ||
return result != null ? done(result) : next(); | ||
}); | ||
@@ -132,3 +97,3 @@ }, function (message) { | ||
getUserConfirmation(message, function (ok) { | ||
callback(ok !== false); | ||
return callback(ok !== false); | ||
}); | ||
@@ -139,132 +104,70 @@ } else { | ||
}); | ||
} | ||
}; | ||
var pendingLocation = undefined; | ||
var transitionTo = function transitionTo(nextLocation) { | ||
if (currentLocation && (0, _LocationUtils.locationsAreEqual)(currentLocation, nextLocation) || pendingLocation && (0, _LocationUtils.locationsAreEqual)(pendingLocation, nextLocation)) return; // Nothing to do | ||
function transitionTo(nextLocation) { | ||
if (location && locationsAreEqual(location, nextLocation)) return; // Nothing to do. | ||
pendingLocation = nextLocation; | ||
confirmTransitionTo(nextLocation, function (ok) { | ||
if (pendingLocation !== nextLocation) return; // Transition was interrupted. | ||
if (pendingLocation !== nextLocation) return; // Transition was interrupted during confirmation | ||
pendingLocation = null; | ||
if (ok) { | ||
// treat PUSH to current path like REPLACE to be consistent with browsers | ||
// Treat PUSH to same path like REPLACE to be consistent with browsers | ||
if (nextLocation.action === _Actions.PUSH) { | ||
var prevPath = createPath(location); | ||
var nextPath = createPath(nextLocation); | ||
var prevPath = (0, _PathUtils.createPath)(currentLocation); | ||
var nextPath = (0, _PathUtils.createPath)(nextLocation); | ||
if (nextPath === prevPath && _deepEqual2['default'](location.state, nextLocation.state)) nextLocation.action = _Actions.REPLACE; | ||
if (nextPath === prevPath && (0, _deepEqual2.default)(currentLocation.state, nextLocation.state)) nextLocation.action = _Actions.REPLACE; | ||
} | ||
if (finishTransition(nextLocation) !== false) updateLocation(nextLocation); | ||
} else if (location && nextLocation.action === _Actions.POP) { | ||
var prevIndex = allKeys.indexOf(location.key); | ||
if (nextLocation.action === _Actions.POP) { | ||
updateLocation(nextLocation); | ||
} else if (nextLocation.action === _Actions.PUSH) { | ||
if (pushLocation(nextLocation) !== false) updateLocation(nextLocation); | ||
} else if (nextLocation.action === _Actions.REPLACE) { | ||
if (replaceLocation(nextLocation) !== false) updateLocation(nextLocation); | ||
} | ||
} else if (currentLocation && nextLocation.action === _Actions.POP) { | ||
var prevIndex = allKeys.indexOf(currentLocation.key); | ||
var nextIndex = allKeys.indexOf(nextLocation.key); | ||
if (prevIndex !== -1 && nextIndex !== -1) go(prevIndex - nextIndex); // Restore the URL. | ||
if (prevIndex !== -1 && nextIndex !== -1) go(prevIndex - nextIndex); // Restore the URL | ||
} | ||
}); | ||
} | ||
}; | ||
function push(location) { | ||
transitionTo(createLocation(location, _Actions.PUSH, createKey())); | ||
} | ||
var push = function push(input) { | ||
return transitionTo(createLocation(input, _Actions.PUSH)); | ||
}; | ||
function replace(location) { | ||
transitionTo(createLocation(location, _Actions.REPLACE, createKey())); | ||
} | ||
var replace = function replace(input) { | ||
return transitionTo(createLocation(input, _Actions.REPLACE)); | ||
}; | ||
function goBack() { | ||
go(-1); | ||
} | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
function goForward() { | ||
go(1); | ||
} | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
function createKey() { | ||
return createRandomKey(keyLength); | ||
} | ||
var createKey = function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength || 6); | ||
}; | ||
function createPath(location) { | ||
if (location == null || typeof location === 'string') return location; | ||
var createHref = function createHref(location) { | ||
return (0, _PathUtils.createPath)(location); | ||
}; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var hash = location.hash; | ||
var result = pathname; | ||
if (search) result += search; | ||
if (hash) result += hash; | ||
return result; | ||
} | ||
function createHref(location) { | ||
return createPath(location); | ||
} | ||
function createLocation(location, action) { | ||
var createLocation = function createLocation(location, action) { | ||
var key = arguments.length <= 2 || arguments[2] === undefined ? createKey() : arguments[2]; | ||
return (0, _LocationUtils.createLocation)(location, action, key); | ||
}; | ||
if (typeof action === 'object') { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](false, 'The state (2nd) argument to history.createLocation is deprecated; use a ' + 'location descriptor instead') : undefined; | ||
if (typeof location === 'string') location = _PathUtils.parsePath(location); | ||
location = _extends({}, location, { state: action }); | ||
action = key; | ||
key = arguments[3] || createKey(); | ||
} | ||
return _createLocation3['default'](location, action, key); | ||
} | ||
// deprecated | ||
function setState(state) { | ||
if (location) { | ||
updateLocationState(location, state); | ||
updateLocation(location); | ||
} else { | ||
updateLocationState(getCurrentLocation(), state); | ||
} | ||
} | ||
function updateLocationState(location, state) { | ||
location.state = _extends({}, location.state, state); | ||
saveState(location.key, location.state); | ||
} | ||
// deprecated | ||
function registerTransitionHook(hook) { | ||
if (transitionHooks.indexOf(hook) === -1) transitionHooks.push(hook); | ||
} | ||
// deprecated | ||
function unregisterTransitionHook(hook) { | ||
transitionHooks = transitionHooks.filter(function (item) { | ||
return item !== hook; | ||
}); | ||
} | ||
// deprecated | ||
function pushState(state, path) { | ||
if (typeof path === 'string') path = _PathUtils.parsePath(path); | ||
push(_extends({ state: state }, path)); | ||
} | ||
// deprecated | ||
function replaceState(state, path) { | ||
if (typeof path === 'string') path = _PathUtils.parsePath(path); | ||
replace(_extends({ state: state }, path)); | ||
} | ||
return { | ||
getCurrentLocation: getCurrentLocation, | ||
listenBefore: listenBefore, | ||
@@ -279,15 +182,8 @@ listen: listen, | ||
createKey: createKey, | ||
createPath: createPath, | ||
createPath: _PathUtils.createPath, | ||
createHref: createHref, | ||
createLocation: createLocation, | ||
setState: _deprecate2['default'](setState, 'setState is deprecated; use location.key to save state instead'), | ||
registerTransitionHook: _deprecate2['default'](registerTransitionHook, 'registerTransitionHook is deprecated; use listenBefore instead'), | ||
unregisterTransitionHook: _deprecate2['default'](unregisterTransitionHook, 'unregisterTransitionHook is deprecated; use the callback returned from listenBefore instead'), | ||
pushState: _deprecate2['default'](pushState, 'pushState is deprecated; use push instead'), | ||
replaceState: _deprecate2['default'](replaceState, 'replaceState is deprecated; use replace instead') | ||
createLocation: createLocation | ||
}; | ||
} | ||
}; | ||
exports['default'] = createHistory; | ||
module.exports = exports['default']; | ||
exports.default = createHistory; |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _warning = require('warning'); | ||
@@ -17,6 +17,6 @@ | ||
var _LocationUtils = require('./LocationUtils'); | ||
var _PathUtils = require('./PathUtils'); | ||
var _Actions = require('./Actions'); | ||
var _createHistory = require('./createHistory'); | ||
@@ -26,3 +26,7 @@ | ||
function createStateStorage(entries) { | ||
var _Actions = require('./Actions'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var createStateStorage = function createStateStorage(entries) { | ||
return entries.filter(function (entry) { | ||
@@ -34,5 +38,5 @@ return entry.state; | ||
}, {}); | ||
} | ||
}; | ||
function createMemoryHistory() { | ||
var createMemoryHistory = function createMemoryHistory() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -46,113 +50,94 @@ | ||
var history = _createHistory2['default'](_extends({}, options, { | ||
getCurrentLocation: getCurrentLocation, | ||
finishTransition: finishTransition, | ||
saveState: saveState, | ||
go: go | ||
})); | ||
var getCurrentLocation = function getCurrentLocation() { | ||
var entry = entries[current]; | ||
var path = (0, _PathUtils.createPath)(entry); | ||
var _options = options; | ||
var entries = _options.entries; | ||
var current = _options.current; | ||
var key = void 0, | ||
state = void 0; | ||
if (entry.key) { | ||
key = entry.key; | ||
state = readState(key); | ||
} | ||
if (typeof entries === 'string') { | ||
entries = [entries]; | ||
} else if (!Array.isArray(entries)) { | ||
entries = ['/']; | ||
} | ||
var init = (0, _PathUtils.parsePath)(path); | ||
entries = entries.map(function (entry) { | ||
var key = history.createKey(); | ||
return (0, _LocationUtils.createLocation)(_extends({}, init, { state: state }), undefined, key); | ||
}; | ||
if (typeof entry === 'string') return { pathname: entry, key: key }; | ||
var canGo = function canGo(n) { | ||
var index = current + n; | ||
return index >= 0 && index < entries.length; | ||
}; | ||
if (typeof entry === 'object' && entry) return _extends({}, entry, { key: key }); | ||
var go = function go(n) { | ||
if (!n) return; | ||
!false ? process.env.NODE_ENV !== 'production' ? _invariant2['default'](false, 'Unable to create history entry from %s', entry) : _invariant2['default'](false) : undefined; | ||
}); | ||
if (!canGo(n)) { | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(false, 'Cannot go(%s) there is not enough history', n) : void 0; | ||
if (current == null) { | ||
current = entries.length - 1; | ||
} else { | ||
!(current >= 0 && current < entries.length) ? process.env.NODE_ENV !== 'production' ? _invariant2['default'](false, 'Current index must be >= 0 and < %s, was %s', entries.length, current) : _invariant2['default'](false) : undefined; | ||
} | ||
return; | ||
} | ||
var storage = createStateStorage(entries); | ||
current += n; | ||
var currentLocation = getCurrentLocation(); | ||
function saveState(key, state) { | ||
storage[key] = state; | ||
} | ||
// Change action to POP | ||
history.transitionTo(_extends({}, currentLocation, { action: _Actions.POP })); | ||
}; | ||
function readState(key) { | ||
return storage[key]; | ||
} | ||
var pushLocation = function pushLocation(location) { | ||
current += 1; | ||
function getCurrentLocation() { | ||
var entry = entries[current]; | ||
var basename = entry.basename; | ||
var pathname = entry.pathname; | ||
var search = entry.search; | ||
if (current < entries.length) entries.splice(current); | ||
var path = (basename || '') + pathname + (search || ''); | ||
entries.push(location); | ||
var key = undefined, | ||
state = undefined; | ||
if (entry.key) { | ||
key = entry.key; | ||
state = readState(key); | ||
} else { | ||
key = history.createKey(); | ||
state = null; | ||
entry.key = key; | ||
} | ||
saveState(location.key, location.state); | ||
}; | ||
var location = _PathUtils.parsePath(path); | ||
var replaceLocation = function replaceLocation(location) { | ||
entries[current] = location; | ||
saveState(location.key, location.state); | ||
}; | ||
return history.createLocation(_extends({}, location, { state: state }), undefined, key); | ||
} | ||
var history = (0, _createHistory2.default)(_extends({}, options, { | ||
getCurrentLocation: getCurrentLocation, | ||
pushLocation: pushLocation, | ||
replaceLocation: replaceLocation, | ||
go: go | ||
})); | ||
function canGo(n) { | ||
var index = current + n; | ||
return index >= 0 && index < entries.length; | ||
} | ||
var entries = options.entries; | ||
var current = options.current; | ||
function go(n) { | ||
if (n) { | ||
if (!canGo(n)) { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](false, 'Cannot go(%s) there is not enough history', n) : undefined; | ||
return; | ||
} | ||
current += n; | ||
if (typeof entries === 'string') { | ||
entries = [entries]; | ||
} else if (!Array.isArray(entries)) { | ||
entries = ['/']; | ||
} | ||
var currentLocation = getCurrentLocation(); | ||
entries = entries.map(function (entry) { | ||
return (0, _LocationUtils.createLocation)(entry); | ||
}); | ||
// change action to POP | ||
history.transitionTo(_extends({}, currentLocation, { action: _Actions.POP })); | ||
} | ||
if (current == null) { | ||
current = entries.length - 1; | ||
} else { | ||
!(current >= 0 && current < entries.length) ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'Current index must be >= 0 and < %s, was %s', entries.length, current) : (0, _invariant2.default)(false) : void 0; | ||
} | ||
function finishTransition(location) { | ||
switch (location.action) { | ||
case _Actions.PUSH: | ||
current += 1; | ||
var storage = createStateStorage(entries); | ||
// if we are not on the top of stack | ||
// remove rest and push new | ||
if (current < entries.length) entries.splice(current); | ||
var saveState = function saveState(key, state) { | ||
return storage[key] = state; | ||
}; | ||
entries.push(location); | ||
saveState(location.key, location.state); | ||
break; | ||
case _Actions.REPLACE: | ||
entries[current] = location; | ||
saveState(location.key, location.state); | ||
break; | ||
} | ||
} | ||
var readState = function readState(key) { | ||
return storage[key]; | ||
}; | ||
return history; | ||
} | ||
}; | ||
exports['default'] = createMemoryHistory; | ||
module.exports = exports['default']; | ||
exports.default = createMemoryHistory; |
@@ -1,10 +0,8 @@ | ||
/*eslint-disable no-empty */ | ||
'use strict'; | ||
exports.__esModule = true; | ||
exports.saveState = saveState; | ||
exports.readState = readState; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.readState = exports.saveState = undefined; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _warning = require('warning'); | ||
@@ -14,12 +12,15 @@ | ||
var KeyPrefix = '@@History/'; | ||
var QuotaExceededErrors = ['QuotaExceededError', 'QUOTA_EXCEEDED_ERR']; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var QuotaExceededErrors = ['QuotaExceededError', 'QUOTA_EXCEEDED_ERR']; /* eslint-disable no-empty */ | ||
var SecurityError = 'SecurityError'; | ||
var KeyPrefix = '@@History/'; | ||
function createKey(key) { | ||
var createKey = function createKey(key) { | ||
return KeyPrefix + key; | ||
} | ||
}; | ||
function saveState(key, state) { | ||
var saveState = exports.saveState = function saveState(key, state) { | ||
try { | ||
@@ -35,3 +36,3 @@ if (state == null) { | ||
// attempt to access window.sessionStorage. | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](false, '[history] Unable to save state; sessionStorage is not available due to security settings') : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(false, '[history] Unable to save state; sessionStorage is not available due to security settings') : void 0; | ||
@@ -43,3 +44,3 @@ return; | ||
// Safari "private mode" throws QuotaExceededError. | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](false, '[history] Unable to save state; sessionStorage is not available in Safari private mode') : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(false, '[history] Unable to save state; sessionStorage is not available in Safari private mode') : void 0; | ||
@@ -51,6 +52,6 @@ return; | ||
} | ||
} | ||
}; | ||
function readState(key) { | ||
var json = undefined; | ||
var readState = exports.readState = function readState(key) { | ||
var json = void 0; | ||
try { | ||
@@ -62,5 +63,5 @@ json = window.sessionStorage.getItem(createKey(key)); | ||
// attempt to access window.sessionStorage. | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](false, '[history] Unable to read state; sessionStorage is not available due to security settings') : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(false, '[history] Unable to read state; sessionStorage is not available due to security settings') : void 0; | ||
return null; | ||
return undefined; | ||
} | ||
@@ -77,3 +78,3 @@ } | ||
return null; | ||
} | ||
return undefined; | ||
}; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.addEventListener = addEventListener; | ||
exports.removeEventListener = removeEventListener; | ||
exports.getHashPath = getHashPath; | ||
exports.replaceHashPath = replaceHashPath; | ||
exports.getWindowPath = getWindowPath; | ||
exports.go = go; | ||
exports.getUserConfirmation = getUserConfirmation; | ||
exports.supportsHistory = supportsHistory; | ||
exports.supportsGoWithoutReloadUsingHash = supportsGoWithoutReloadUsingHash; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var addEventListener = exports.addEventListener = function addEventListener(node, event, listener) { | ||
return node.addEventListener ? node.addEventListener(event, listener, false) : node.attachEvent('on' + event, listener); | ||
}; | ||
function addEventListener(node, event, listener) { | ||
if (node.addEventListener) { | ||
node.addEventListener(event, listener, false); | ||
} else { | ||
node.attachEvent('on' + event, listener); | ||
} | ||
} | ||
var removeEventListener = exports.removeEventListener = function removeEventListener(node, event, listener) { | ||
return node.removeEventListener ? node.removeEventListener(event, listener, false) : node.detachEvent('on' + event, listener); | ||
}; | ||
function removeEventListener(node, event, listener) { | ||
if (node.removeEventListener) { | ||
node.removeEventListener(event, listener, false); | ||
} else { | ||
node.detachEvent('on' + event, listener); | ||
} | ||
} | ||
function getHashPath() { | ||
// We can't use window.location.hash here because it's not | ||
// consistent across browsers - Firefox will pre-decode it! | ||
return window.location.href.split('#')[1] || ''; | ||
} | ||
function replaceHashPath(path) { | ||
window.location.replace(window.location.pathname + window.location.search + '#' + path); | ||
} | ||
function getWindowPath() { | ||
return window.location.pathname + window.location.search + window.location.hash; | ||
} | ||
function go(n) { | ||
if (n) window.history.go(n); | ||
} | ||
function getUserConfirmation(message, callback) { | ||
callback(window.confirm(message)); | ||
} | ||
/** | ||
@@ -57,12 +19,11 @@ * Returns true if the HTML5 history API is supported. Taken from Modernizr. | ||
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js | ||
* changed to avoid false negatives for Windows Phones: https://github.com/rackt/react-router/issues/586 | ||
* changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586 | ||
*/ | ||
var supportsHistory = exports.supportsHistory = function supportsHistory() { | ||
var ua = navigator.userAgent; | ||
function supportsHistory() { | ||
var ua = navigator.userAgent; | ||
if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1) { | ||
return false; | ||
} | ||
if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1) return false; | ||
return window.history && 'pushState' in window.history; | ||
} | ||
}; | ||
@@ -72,6 +33,4 @@ /** | ||
*/ | ||
function supportsGoWithoutReloadUsingHash() { | ||
var ua = navigator.userAgent; | ||
return ua.indexOf('Firefox') === -1; | ||
} | ||
var supportsGoWithoutReloadUsingHash = exports.supportsGoWithoutReloadUsingHash = function supportsGoWithoutReloadUsingHash() { | ||
return navigator.userAgent.indexOf('Firefox') === -1; | ||
}; |
'use strict'; | ||
exports.__esModule = true; | ||
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
exports.canUseDOM = canUseDOM; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var canUseDOM = exports.canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Actions = exports.useQueries = exports.useBeforeUnload = exports.useBasename = exports.createMemoryHistory = exports.createHashHistory = exports.createHistory = undefined; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _deprecate = require('./deprecate'); | ||
var _deprecate2 = _interopRequireDefault(_deprecate); | ||
var _createLocation2 = require('./createLocation'); | ||
var _createLocation3 = _interopRequireDefault(_createLocation2); | ||
var _createBrowserHistory = require('./createBrowserHistory'); | ||
@@ -19,4 +12,2 @@ | ||
exports.createHistory = _createBrowserHistory2['default']; | ||
var _createHashHistory2 = require('./createHashHistory'); | ||
@@ -26,4 +17,2 @@ | ||
exports.createHashHistory = _createHashHistory3['default']; | ||
var _createMemoryHistory2 = require('./createMemoryHistory'); | ||
@@ -33,4 +22,2 @@ | ||
exports.createMemoryHistory = _createMemoryHistory3['default']; | ||
var _useBasename2 = require('./useBasename'); | ||
@@ -40,4 +27,2 @@ | ||
exports.useBasename = _useBasename3['default']; | ||
var _useBeforeUnload2 = require('./useBeforeUnload'); | ||
@@ -47,4 +32,2 @@ | ||
exports.useBeforeUnload = _useBeforeUnload3['default']; | ||
var _useQueries2 = require('./useQueries'); | ||
@@ -54,4 +37,2 @@ | ||
exports.useQueries = _useQueries3['default']; | ||
var _Actions2 = require('./Actions'); | ||
@@ -61,18 +42,10 @@ | ||
exports.Actions = _Actions3['default']; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// deprecated | ||
var _enableBeforeUnload2 = require('./enableBeforeUnload'); | ||
var _enableBeforeUnload3 = _interopRequireDefault(_enableBeforeUnload2); | ||
exports.enableBeforeUnload = _enableBeforeUnload3['default']; | ||
var _enableQueries2 = require('./enableQueries'); | ||
var _enableQueries3 = _interopRequireDefault(_enableQueries2); | ||
exports.enableQueries = _enableQueries3['default']; | ||
var createLocation = _deprecate2['default'](_createLocation3['default'], 'Using createLocation without a history instance is deprecated; please use history.createLocation instead'); | ||
exports.createLocation = createLocation; | ||
exports.createHistory = _createBrowserHistory2.default; | ||
exports.createHashHistory = _createHashHistory3.default; | ||
exports.createMemoryHistory = _createMemoryHistory3.default; | ||
exports.useBasename = _useBasename3.default; | ||
exports.useBeforeUnload = _useBeforeUnload3.default; | ||
exports.useQueries = _useQueries3.default; | ||
exports.Actions = _Actions3.default; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.extractPath = extractPath; | ||
exports.parsePath = parsePath; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.createPath = exports.parsePath = exports.getQueryStringValueFromPath = exports.stripQueryStringValueFromPath = exports.addQueryStringValueToPath = exports.isAbsolutePath = undefined; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _warning = require('warning'); | ||
@@ -13,11 +12,55 @@ | ||
function extractPath(string) { | ||
var match = string.match(/^https?:\/\/[^\/]*/); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
if (match == null) return string; | ||
var isAbsolutePath = exports.isAbsolutePath = function isAbsolutePath(path) { | ||
return typeof path === 'string' && path.charAt(0) === '/'; | ||
}; | ||
return string.substring(match[0].length); | ||
} | ||
var addQueryStringValueToPath = exports.addQueryStringValueToPath = function addQueryStringValueToPath(path, key, value) { | ||
var _parsePath = parsePath(path); | ||
function parsePath(path) { | ||
var pathname = _parsePath.pathname; | ||
var search = _parsePath.search; | ||
var hash = _parsePath.hash; | ||
return createPath({ | ||
pathname: pathname, | ||
search: search + (search.indexOf('?') === -1 ? '?' : '&') + key + '=' + value, | ||
hash: hash | ||
}); | ||
}; | ||
var stripQueryStringValueFromPath = exports.stripQueryStringValueFromPath = function stripQueryStringValueFromPath(path, key) { | ||
var _parsePath2 = parsePath(path); | ||
var pathname = _parsePath2.pathname; | ||
var search = _parsePath2.search; | ||
var hash = _parsePath2.hash; | ||
return createPath({ | ||
pathname: pathname, | ||
search: search.replace(new RegExp('([?&])' + key + '=[a-zA-Z0-9]+(&?)'), function (match, prefix, suffix) { | ||
return prefix === '?' ? prefix : suffix; | ||
}), | ||
hash: hash | ||
}); | ||
}; | ||
var getQueryStringValueFromPath = exports.getQueryStringValueFromPath = function getQueryStringValueFromPath(path, key) { | ||
var _parsePath3 = parsePath(path); | ||
var search = _parsePath3.search; | ||
var match = search.match(new RegExp('[?&]' + key + '=([a-zA-Z0-9]+)')); | ||
return match && match[1]; | ||
}; | ||
var extractPath = function extractPath(string) { | ||
var match = string.match(/^https?:\/\/[^\/]*/); | ||
return match == null ? string : string.substring(match[0].length); | ||
}; | ||
var parsePath = exports.parsePath = function parsePath(path) { | ||
var pathname = extractPath(path); | ||
@@ -27,3 +70,3 @@ var search = ''; | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](path === pathname, 'A path must be pathname + search + hash only, not a fully qualified URL like "%s"', path) : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(path === pathname, 'A path must be pathname + search + hash only, not a fully qualified URL like "%s"', path) : void 0; | ||
@@ -49,2 +92,19 @@ var hashIndex = pathname.indexOf('#'); | ||
}; | ||
} | ||
}; | ||
var createPath = exports.createPath = function createPath(location) { | ||
if (location == null || typeof location === 'string') return location; | ||
var basename = location.basename; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var hash = location.hash; | ||
var path = (basename || '') + pathname; | ||
if (search && search !== '?') path += search; | ||
if (hash) path += hash; | ||
return path; | ||
}; |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _warning = require('warning'); | ||
@@ -11,3 +11,5 @@ | ||
function runTransitionHook(hook, location, callback) { | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var runTransitionHook = function runTransitionHook(hook, location, callback) { | ||
var result = hook(location, callback); | ||
@@ -20,7 +22,6 @@ | ||
} else { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](result === undefined, 'You should not "return" in a transition hook with a callback argument; call the callback instead') : undefined; | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(result === undefined, 'You should not "return" in a transition hook with a callback argument; ' + 'call the callback instead') : void 0; | ||
} | ||
} | ||
}; | ||
exports['default'] = runTransitionHook; | ||
module.exports = exports['default']; | ||
exports.default = runTransitionHook; |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _ExecutionEnvironment = require('./ExecutionEnvironment'); | ||
var _PathUtils = require('./PathUtils'); | ||
var _runTransitionHook = require('./runTransitionHook'); | ||
@@ -17,7 +15,7 @@ | ||
var _deprecate = require('./deprecate'); | ||
var _PathUtils = require('./PathUtils'); | ||
var _deprecate2 = _interopRequireDefault(_deprecate); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function useBasename(createHistory) { | ||
var useBasename = function useBasename(createHistory) { | ||
return function () { | ||
@@ -27,3 +25,2 @@ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var history = createHistory(options); | ||
var basename = options.basename; | ||
@@ -33,9 +30,12 @@ | ||
// documents as basename if it's not explicitly given. | ||
if (basename == null && _ExecutionEnvironment.canUseDOM) { | ||
var base = document.getElementsByTagName('base')[0]; | ||
if (base) basename = _PathUtils.extractPath(base.href); | ||
if (base) basename = base.getAttribute('href'); | ||
} | ||
function addBasename(location) { | ||
var addBasename = function addBasename(location) { | ||
if (!location) return location; | ||
if (basename && location.basename == null) { | ||
@@ -53,10 +53,9 @@ if (location.pathname.indexOf(basename) === 0) { | ||
return location; | ||
} | ||
}; | ||
function prependBasename(location) { | ||
var prependBasename = function prependBasename(location) { | ||
if (!basename) return location; | ||
if (typeof location === 'string') location = _PathUtils.parsePath(location); | ||
var pname = location.pathname; | ||
var object = typeof location === 'string' ? (0, _PathUtils.parsePath)(location) : location; | ||
var pname = object.pathname; | ||
var normalizedBasename = basename.slice(-1) === '/' ? basename : basename + '/'; | ||
@@ -69,35 +68,39 @@ var normalizedPathname = pname.charAt(0) === '/' ? pname.slice(1) : pname; | ||
}); | ||
} | ||
}; | ||
// Override all read methods with basename-aware versions. | ||
function listenBefore(hook) { | ||
var getCurrentLocation = function getCurrentLocation() { | ||
return addBasename(history.getCurrentLocation()); | ||
}; | ||
var listenBefore = function listenBefore(hook) { | ||
return history.listenBefore(function (location, callback) { | ||
_runTransitionHook2['default'](hook, addBasename(location), callback); | ||
return (0, _runTransitionHook2.default)(hook, addBasename(location), callback); | ||
}); | ||
} | ||
}; | ||
function listen(listener) { | ||
var listen = function listen(listener) { | ||
return history.listen(function (location) { | ||
listener(addBasename(location)); | ||
return listener(addBasename(location)); | ||
}); | ||
} | ||
}; | ||
// Override all write methods with basename-aware versions. | ||
function push(location) { | ||
history.push(prependBasename(location)); | ||
} | ||
var push = function push(location) { | ||
return history.push(prependBasename(location)); | ||
}; | ||
function replace(location) { | ||
history.replace(prependBasename(location)); | ||
} | ||
var replace = function replace(location) { | ||
return history.replace(prependBasename(location)); | ||
}; | ||
function createPath(location) { | ||
var createPath = function createPath(location) { | ||
return history.createPath(prependBasename(location)); | ||
} | ||
}; | ||
function createHref(location) { | ||
var createHref = function createHref(location) { | ||
return history.createHref(prependBasename(location)); | ||
} | ||
}; | ||
function createLocation(location) { | ||
var createLocation = function createLocation(location) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -108,19 +111,6 @@ args[_key - 1] = arguments[_key]; | ||
return addBasename(history.createLocation.apply(history, [prependBasename(location)].concat(args))); | ||
} | ||
}; | ||
// deprecated | ||
function pushState(state, path) { | ||
if (typeof path === 'string') path = _PathUtils.parsePath(path); | ||
push(_extends({ state: state }, path)); | ||
} | ||
// deprecated | ||
function replaceState(state, path) { | ||
if (typeof path === 'string') path = _PathUtils.parsePath(path); | ||
replace(_extends({ state: state }, path)); | ||
} | ||
return _extends({}, history, { | ||
getCurrentLocation: getCurrentLocation, | ||
listenBefore: listenBefore, | ||
@@ -132,11 +122,7 @@ listen: listen, | ||
createHref: createHref, | ||
createLocation: createLocation, | ||
pushState: _deprecate2['default'](pushState, 'pushState is deprecated; use push instead'), | ||
replaceState: _deprecate2['default'](replaceState, 'replaceState is deprecated; use replace instead') | ||
createLocation: createLocation | ||
}); | ||
}; | ||
} | ||
}; | ||
exports['default'] = useBasename; | ||
module.exports = exports['default']; | ||
exports.default = useBasename; |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _invariant = require('invariant'); | ||
var _warning = require('warning'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var _DOMUtils = require('./DOMUtils'); | ||
var _ExecutionEnvironment = require('./ExecutionEnvironment'); | ||
var _DOMUtils = require('./DOMUtils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _deprecate = require('./deprecate'); | ||
var startListener = function startListener(getPromptMessage) { | ||
var handleBeforeUnload = function handleBeforeUnload(event) { | ||
var message = getPromptMessage(); | ||
var _deprecate2 = _interopRequireDefault(_deprecate); | ||
function startBeforeUnloadListener(getBeforeUnloadPromptMessage) { | ||
function listener(event) { | ||
var message = getBeforeUnloadPromptMessage(); | ||
if (typeof message === 'string') { | ||
@@ -29,10 +27,12 @@ (event || window.event).returnValue = message; | ||
} | ||
} | ||
_DOMUtils.addEventListener(window, 'beforeunload', listener); | ||
return undefined; | ||
}; | ||
(0, _DOMUtils.addEventListener)(window, 'beforeunload', handleBeforeUnload); | ||
return function () { | ||
_DOMUtils.removeEventListener(window, 'beforeunload', listener); | ||
return (0, _DOMUtils.removeEventListener)(window, 'beforeunload', handleBeforeUnload); | ||
}; | ||
} | ||
}; | ||
@@ -44,70 +44,39 @@ /** | ||
*/ | ||
function useBeforeUnload(createHistory) { | ||
var useBeforeUnload = function useBeforeUnload(createHistory) { | ||
!_ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'useBeforeUnload only works in DOM environments') : (0, _invariant2.default)(false) : void 0; | ||
return function (options) { | ||
var history = createHistory(options); | ||
var stopBeforeUnloadListener = undefined; | ||
var beforeUnloadHooks = []; | ||
var listeners = []; | ||
var stopListener = void 0; | ||
function getBeforeUnloadPromptMessage() { | ||
var message = undefined; | ||
for (var i = 0, len = beforeUnloadHooks.length; message == null && i < len; ++i) { | ||
message = beforeUnloadHooks[i].call(); | ||
var getPromptMessage = function getPromptMessage() { | ||
var message = void 0; | ||
for (var i = 0, len = listeners.length; message == null && i < len; ++i) { | ||
message = listeners[i].call(); | ||
}return message; | ||
} | ||
}; | ||
function listenBeforeUnload(hook) { | ||
beforeUnloadHooks.push(hook); | ||
var listenBeforeUnload = function listenBeforeUnload(listener) { | ||
if (listeners.push(listener) === 1) stopListener = startListener(getPromptMessage); | ||
if (beforeUnloadHooks.length === 1) { | ||
if (_ExecutionEnvironment.canUseDOM) { | ||
stopBeforeUnloadListener = startBeforeUnloadListener(getBeforeUnloadPromptMessage); | ||
} else { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](false, 'listenBeforeUnload only works in DOM environments') : undefined; | ||
} | ||
} | ||
return function () { | ||
beforeUnloadHooks = beforeUnloadHooks.filter(function (item) { | ||
return item !== hook; | ||
listeners = listeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
if (beforeUnloadHooks.length === 0 && stopBeforeUnloadListener) { | ||
stopBeforeUnloadListener(); | ||
stopBeforeUnloadListener = null; | ||
if (listeners.length === 0 && stopListener) { | ||
stopListener(); | ||
stopListener = null; | ||
} | ||
}; | ||
} | ||
}; | ||
// deprecated | ||
function registerBeforeUnloadHook(hook) { | ||
if (_ExecutionEnvironment.canUseDOM && beforeUnloadHooks.indexOf(hook) === -1) { | ||
beforeUnloadHooks.push(hook); | ||
if (beforeUnloadHooks.length === 1) stopBeforeUnloadListener = startBeforeUnloadListener(getBeforeUnloadPromptMessage); | ||
} | ||
} | ||
// deprecated | ||
function unregisterBeforeUnloadHook(hook) { | ||
if (beforeUnloadHooks.length > 0) { | ||
beforeUnloadHooks = beforeUnloadHooks.filter(function (item) { | ||
return item !== hook; | ||
}); | ||
if (beforeUnloadHooks.length === 0) stopBeforeUnloadListener(); | ||
} | ||
} | ||
return _extends({}, history, { | ||
listenBeforeUnload: listenBeforeUnload, | ||
registerBeforeUnloadHook: _deprecate2['default'](registerBeforeUnloadHook, 'registerBeforeUnloadHook is deprecated; use listenBeforeUnload instead'), | ||
unregisterBeforeUnloadHook: _deprecate2['default'](unregisterBeforeUnloadHook, 'unregisterBeforeUnloadHook is deprecated; use the callback returned from listenBeforeUnload instead') | ||
listenBeforeUnload: listenBeforeUnload | ||
}); | ||
}; | ||
} | ||
}; | ||
exports['default'] = useBeforeUnload; | ||
module.exports = exports['default']; | ||
exports.default = useBeforeUnload; |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
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; }; | ||
@@ -21,20 +23,18 @@ var _warning = require('warning'); | ||
var _deprecate = require('./deprecate'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _deprecate2 = _interopRequireDefault(_deprecate); | ||
var defaultStringifyQuery = function defaultStringifyQuery(query) { | ||
return (0, _queryString.stringify)(query).replace(/%20/g, '+'); | ||
}; | ||
var SEARCH_BASE_KEY = '$searchBase'; | ||
function defaultStringifyQuery(query) { | ||
return _queryString.stringify(query).replace(/%20/g, '+'); | ||
} | ||
var defaultParseQueryString = _queryString.parse; | ||
function isNestedObject(object) { | ||
var isNestedObject = function isNestedObject(object) { | ||
for (var p in object) { | ||
if (object.hasOwnProperty(p) && typeof object[p] === 'object' && !Array.isArray(object[p]) && object[p] !== null) return true; | ||
}return false; | ||
} | ||
if (object.hasOwnProperty(p) && _typeof(object[p]) === 'object' && !Array.isArray(object[p]) && object[p] !== null) return true; | ||
} | ||
return false; | ||
}; | ||
/** | ||
@@ -44,3 +44,3 @@ * Returns a new createHistory function that may be used to create | ||
*/ | ||
function useQueries(createHistory) { | ||
var useQueries = function useQueries(createHistory) { | ||
return function () { | ||
@@ -50,6 +50,6 @@ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var history = createHistory(options); | ||
var stringifyQuery = options.stringifyQuery; | ||
var parseQueryString = options.parseQueryString; | ||
if (typeof stringifyQuery !== 'function') stringifyQuery = defaultStringifyQuery; | ||
@@ -59,81 +59,59 @@ | ||
function addQuery(location) { | ||
if (location.query == null) { | ||
var search = location.search; | ||
var decodeQuery = function decodeQuery(location) { | ||
if (!location) return location; | ||
location.query = parseQueryString(search.substring(1)); | ||
location[SEARCH_BASE_KEY] = { search: search, searchBase: '' }; | ||
} | ||
if (location.query == null) location.query = parseQueryString(location.search.substring(1)); | ||
// TODO: Instead of all the book-keeping here, this should just strip the | ||
// stringified query from the search. | ||
return location; | ||
} | ||
}; | ||
function appendQuery(location, query) { | ||
var _extends2; | ||
var encodeQuery = function encodeQuery(location, query) { | ||
if (query == null) return location; | ||
var searchBaseSpec = location[SEARCH_BASE_KEY]; | ||
var queryString = query ? stringifyQuery(query) : ''; | ||
if (!searchBaseSpec && !queryString) { | ||
return location; | ||
} | ||
process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(stringifyQuery !== defaultStringifyQuery || !isNestedObject(query), 'useQueries does not stringify nested query objects by default; ' + 'use a custom stringifyQuery function') : void 0; | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](stringifyQuery !== defaultStringifyQuery || !isNestedObject(query), 'useQueries does not stringify nested query objects by default; ' + 'use a custom stringifyQuery function') : undefined; | ||
var object = typeof location === 'string' ? (0, _PathUtils.parsePath)(location) : location; | ||
var queryString = stringifyQuery(query); | ||
var search = queryString ? '?' + queryString : ''; | ||
if (typeof location === 'string') location = _PathUtils.parsePath(location); | ||
var searchBase = undefined; | ||
if (searchBaseSpec && location.search === searchBaseSpec.search) { | ||
searchBase = searchBaseSpec.searchBase; | ||
} else { | ||
searchBase = location.search || ''; | ||
} | ||
var search = searchBase; | ||
if (queryString) { | ||
search += (search ? '&' : '?') + queryString; | ||
} | ||
return _extends({}, location, (_extends2 = { | ||
return _extends({}, object, { | ||
search: search | ||
}, _extends2[SEARCH_BASE_KEY] = { search: search, searchBase: searchBase }, _extends2)); | ||
} | ||
}); | ||
}; | ||
// Override all read methods with query-aware versions. | ||
function listenBefore(hook) { | ||
var getCurrentLocation = function getCurrentLocation() { | ||
return decodeQuery(history.getCurrentLocation()); | ||
}; | ||
var listenBefore = function listenBefore(hook) { | ||
return history.listenBefore(function (location, callback) { | ||
_runTransitionHook2['default'](hook, addQuery(location), callback); | ||
return (0, _runTransitionHook2.default)(hook, decodeQuery(location), callback); | ||
}); | ||
} | ||
}; | ||
function listen(listener) { | ||
var listen = function listen(listener) { | ||
return history.listen(function (location) { | ||
listener(addQuery(location)); | ||
return listener(decodeQuery(location)); | ||
}); | ||
} | ||
}; | ||
// Override all write methods with query-aware versions. | ||
function push(location) { | ||
history.push(appendQuery(location, location.query)); | ||
} | ||
var push = function push(location) { | ||
return history.push(encodeQuery(location, location.query)); | ||
}; | ||
function replace(location) { | ||
history.replace(appendQuery(location, location.query)); | ||
} | ||
var replace = function replace(location) { | ||
return history.replace(encodeQuery(location, location.query)); | ||
}; | ||
function createPath(location, query) { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](!query, 'the query argument to createPath is deprecated; use a location descriptor instead') : undefined; | ||
var createPath = function createPath(location) { | ||
return history.createPath(encodeQuery(location, location.query)); | ||
}; | ||
return history.createPath(appendQuery(location, query || location.query)); | ||
} | ||
var createHref = function createHref(location) { | ||
return history.createHref(encodeQuery(location, location.query)); | ||
}; | ||
function createHref(location, query) { | ||
process.env.NODE_ENV !== 'production' ? _warning2['default'](!query, 'the query argument to createHref is deprecated; use a location descriptor instead') : undefined; | ||
return history.createHref(appendQuery(location, query || location.query)); | ||
} | ||
function createLocation(location) { | ||
var createLocation = function createLocation(location) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -143,24 +121,11 @@ args[_key - 1] = arguments[_key]; | ||
var fullLocation = history.createLocation.apply(history, [appendQuery(location, location.query)].concat(args)); | ||
if (location.query) { | ||
fullLocation.query = location.query; | ||
} | ||
return addQuery(fullLocation); | ||
} | ||
var newLocation = history.createLocation.apply(history, [encodeQuery(location, location.query)].concat(args)); | ||
// deprecated | ||
function pushState(state, path, query) { | ||
if (typeof path === 'string') path = _PathUtils.parsePath(path); | ||
if (location.query) newLocation.query = location.query; | ||
push(_extends({ state: state }, path, { query: query })); | ||
} | ||
return decodeQuery(newLocation); | ||
}; | ||
// deprecated | ||
function replaceState(state, path, query) { | ||
if (typeof path === 'string') path = _PathUtils.parsePath(path); | ||
replace(_extends({ state: state }, path, { query: query })); | ||
} | ||
return _extends({}, history, { | ||
getCurrentLocation: getCurrentLocation, | ||
listenBefore: listenBefore, | ||
@@ -172,11 +137,7 @@ listen: listen, | ||
createHref: createHref, | ||
createLocation: createLocation, | ||
pushState: _deprecate2['default'](pushState, 'pushState is deprecated; use push instead'), | ||
replaceState: _deprecate2['default'](replaceState, 'replaceState is deprecated; use replace instead') | ||
createLocation: createLocation | ||
}); | ||
}; | ||
} | ||
}; | ||
exports['default'] = useQueries; | ||
module.exports = exports['default']; | ||
exports.default = useQueries; |
{ | ||
"name": "history", | ||
"version": "2.0.1", | ||
"version": "3.0.0-0", | ||
"description": "Manage browser history with JavaScript", | ||
"files": [ | ||
"es6", | ||
"lib", | ||
"modules/*.js", | ||
"umd" | ||
], | ||
"main": "lib/index", | ||
"author": "Michael Jackson", | ||
"license": "MIT", | ||
"webpack": "lib", | ||
"browser": "umd/history.min.js", | ||
"main": "lib", | ||
"jsnext:main": "es6/index", | ||
@@ -17,18 +15,19 @@ "repository": { | ||
}, | ||
"files": [ | ||
"lib", | ||
"umd", | ||
"es6" | ||
], | ||
"scripts": { | ||
"lint": "eslint modules", | ||
"start": "webpack-dev-server -d --content-base ./ --history-api-fallback --inline modules/index.js", | ||
"build-cjs": "rimraf lib && babel ./modules --stage 0 --loose all --plugins dev-expression -d lib --ignore '__tests__'", | ||
"build-es6": "rimraf es6 && babel ./modules --stage 0 --loose all --plugins dev-expression -d es6 --blacklist=es6.modules --ignore '__tests__'", | ||
"build-umd": "NODE_ENV=production webpack modules/index.js umd/History.js", | ||
"build-min": "NODE_ENV=production webpack -p modules/index.js umd/History.min.js", | ||
"build-cjs": "rimraf lib && babel ./modules -d lib --ignore '__tests__'", | ||
"build-es6": "rimraf es6 && babel ./modules -d es6 --blacklist=es6.modules --ignore '__tests__'", | ||
"build-umd": "NODE_ENV=production webpack modules/index.js umd/history.js", | ||
"build-min": "NODE_ENV=production webpack -p modules/index.js umd/history.min.js", | ||
"build": "node ./scripts/build.js", | ||
"release": "node ./scripts/release.js", | ||
"prepublish": "npm run build", | ||
"test": "npm run lint && karma start" | ||
"test": "npm run lint && karma start", | ||
"lint": "eslint modules" | ||
}, | ||
"authors": [ | ||
"Michael Jackson" | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
@@ -41,11 +40,12 @@ "deep-equal": "^1.0.0", | ||
"devDependencies": { | ||
"assert": "1.3.0", | ||
"babel": "^5.8.35", | ||
"babel-core": "^5.8.35", | ||
"babel-eslint": "^4.1.8", | ||
"babel-loader": "^5.4.0", | ||
"babel-plugin-dev-expression": "^0.1.0", | ||
"eslint": "^1.10.3", | ||
"eslint-config-rackt": "^1.1.1", | ||
"eslint-plugin-react": "^3.16.1", | ||
"babel-cli": "^6.6.5", | ||
"babel-eslint": "^5.0.0", | ||
"babel-loader": "^6.2.4", | ||
"babel-plugin-dev-expression": "^0.2.1", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-stage-1": "^6.5.0", | ||
"eslint": "^2.2.0", | ||
"eslint-config-airbnb": "^6.0.2", | ||
"eslint-plugin-react": "^4.1.0", | ||
"estraverse-fb": "^1.3.1", | ||
"expect": "^1.12.0", | ||
@@ -52,0 +52,0 @@ "gzip-size": "^3.0.0", |
@@ -9,3 +9,3 @@ # history [![Travis][build-badge]][build] [![npm package][npm-badge]][npm] | ||
[`history`](https://www.npmjs.com/package/history) is a JavaScript library that lets you easily manage session history in browsers, testing environments, and (soon, via [React Native](https://facebook.github.io/react-native/)) native devices. `history` abstracts away the differences in these different platforms and provides a minimal API that lets you manage the history stack, navigate, confirm navigation, and persist state between sessions. `history` is library-agnostic and may easily be included in any JavaScript project. | ||
[`history`](https://www.npmjs.com/package/history) is a JavaScript library that lets you easily manage session history anywhere JavaScript runs. `history` abstracts away the differences in various environments and provides a minimal API that lets you manage the history stack, navigate, confirm navigation, and persist state between sessions. | ||
@@ -16,6 +16,3 @@ ## Docs & Help | ||
- [Changelog](/CHANGES.md) | ||
- [Stack Overflow](http://stackoverflow.com/questions/tagged/react-router) | ||
For questions and support, please visit [our channel on Reactiflux](https://discord.gg/0ZcbPKXt5bYaNQ46) or [Stack Overflow](http://stackoverflow.com/questions/tagged/react-router). The issue tracker is *exclusively* for bug reports and feature requests. | ||
## Installation | ||
@@ -40,3 +37,3 @@ | ||
```html | ||
<script src="https://npmcdn.com/history/umd/History.min.js"></script> | ||
<script src="https://npmcdn.com/history/umd/history.min.js"></script> | ||
``` | ||
@@ -55,4 +52,6 @@ | ||
// Listen for changes to the current location. The | ||
// listener is called once immediately. | ||
// Get the current location | ||
const location = history.getCurrentLocation() | ||
// Listen for changes to the current location | ||
const unlisten = history.listen(location => { | ||
@@ -62,9 +61,13 @@ console.log(location.pathname) | ||
// Push a new entry onto the history stack | ||
history.push({ | ||
pathname: '/the/path', | ||
search: '?a=query', | ||
// Extra location-specific state may be kept in session | ||
// storage instead of in the URL query string! | ||
state: { the: 'state' } | ||
}) | ||
// When you're finished, stop the listener. | ||
// When you're finished, stop the listener | ||
unlisten() | ||
@@ -71,0 +74,0 @@ ``` |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.History=t():e.History=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var a=n[r]={exports:{},id:r,loaded:!1};return e[r].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var a=n(3),o=r(a),u=n(12),i=r(u),s=n(16),c=r(s);t.createHistory=c["default"];var f=n(17),l=r(f);t.createHashHistory=l["default"];var d=n(18),p=r(d);t.createMemoryHistory=p["default"];var h=n(21),g=r(h);t.useBasename=g["default"];var v=n(13),y=r(v);t.useBeforeUnload=y["default"];var m=n(14),w=r(m);t.useQueries=w["default"];var P=n(4),_=r(P);t.Actions=_["default"];var O=n(19),b=r(O);t.enableBeforeUnload=b["default"];var S=n(20),x=r(S);t.enableQueries=x["default"];var k=o["default"](i["default"],"Using createLocation without a history instance is deprecated; please use history.createLocation instead");t.createLocation=k},function(e,t,n){"use strict";var r=function(){};e.exports=r},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e){var t=e.match(/^https?:\/\/[^\/]*/);return null==t?e:e.substring(t[0].length)}function o(e){var t=a(e),n="",r="",o=t.indexOf("#");-1!==o&&(r=t.substring(o),t=t.substring(0,o));var u=t.indexOf("?");return-1!==u&&(n=t.substring(u),t=t.substring(0,u)),""===t&&(t="/"),{pathname:t,search:n,hash:r}}t.__esModule=!0,t.extractPath=a,t.parsePath=o;var u=n(1);r(u)},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e,t){return function(){return e.apply(this,arguments)}}t.__esModule=!0;var o=n(1);r(o);t["default"]=a,e.exports=t["default"]},function(e,t){"use strict";t.__esModule=!0;var n="PUSH";t.PUSH=n;var r="REPLACE";t.REPLACE=r;var a="POP";t.POP=a,t["default"]={PUSH:n,REPLACE:r,POP:a}},function(e,t){"use strict";t.__esModule=!0;var n=!("undefined"==typeof window||!window.document||!window.document.createElement);t.canUseDOM=n},function(e,t){"use strict";function n(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)}function r(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent("on"+t,n)}function a(){return window.location.href.split("#")[1]||""}function o(e){window.location.replace(window.location.pathname+window.location.search+"#"+e)}function u(){return window.location.pathname+window.location.search+window.location.hash}function i(e){e&&window.history.go(e)}function s(e,t){t(window.confirm(e))}function c(){var e=navigator.userAgent;return-1===e.indexOf("Android 2.")&&-1===e.indexOf("Android 4.0")||-1===e.indexOf("Mobile Safari")||-1!==e.indexOf("Chrome")||-1!==e.indexOf("Windows Phone")?window.history&&"pushState"in window.history:!1}function f(){var e=navigator.userAgent;return-1===e.indexOf("Firefox")}t.__esModule=!0,t.addEventListener=n,t.removeEventListener=r,t.getHashPath=a,t.replaceHashPath=o,t.getWindowPath=u,t.go=i,t.getUserConfirmation=s,t.supportsHistory=c,t.supportsGoWithoutReloadUsingHash=f},function(e,t,n){"use strict";var r=function(e,t,n,r,a,o,u,i){if(!e){var s;if(void 0===t)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,a,o,u,i],f=0;s=new Error(t.replace(/%s/g,function(){return c[f++]})),s.name="Invariant Violation"}throw s.framesToPop=1,s}};e.exports=r},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e,t,n){var r=e(t,n);e.length<2&&n(r)}t.__esModule=!0;var o=n(1);r(o);t["default"]=a,e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e){return s+e}function o(e,t){try{null==t?window.sessionStorage.removeItem(a(e)):window.sessionStorage.setItem(a(e),JSON.stringify(t))}catch(n){if(n.name===f)return;if(c.indexOf(n.name)>=0&&0===window.sessionStorage.length)return;throw n}}function u(e){var t=void 0;try{t=window.sessionStorage.getItem(a(e))}catch(n){if(n.name===f)return null}if(t)try{return JSON.parse(t)}catch(n){}return null}t.__esModule=!0,t.saveState=o,t.readState=u;var i=n(1),s=(r(i),"@@History/"),c=["QuotaExceededError","QUOTA_EXCEEDED_ERR"],f="SecurityError"},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e){function t(e){return s.canUseDOM?void 0:i["default"](!1),n.listen(e)}var n=l["default"](o({getUserConfirmation:c.getUserConfirmation},e,{go:c.go}));return o({},n,{listen:t})}t.__esModule=!0;var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=n(7),i=r(u),s=n(5),c=n(6),f=n(11),l=r(f);t["default"]=a,e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e){return Math.random().toString(36).substr(2,e)}function o(e,t){return e.pathname===t.pathname&&e.search===t.search&&e.key===t.key&&f["default"](e.state,t.state)}function u(){function e(e){return q.push(e),function(){q=q.filter(function(t){return t!==e})}}function t(){return K&&K.action===p.POP?D.indexOf(K.key):Q?D.indexOf(Q.key):-1}function n(e){var n=t();Q=e,Q.action===p.PUSH?D=[].concat(D.slice(0,n+1),[Q.key]):Q.action===p.REPLACE&&(D[n]=Q.key),I.forEach(function(e){e(Q)})}function r(e){if(I.push(e),Q)e(Q);else{var t=L();D=[t.key],n(t)}return function(){I=I.filter(function(t){return t!==e})}}function u(e,t){d.loopAsync(q.length,function(t,n,r){y["default"](q[t],e,function(e){null!=e?r(e):n()})},function(e){C&&"string"==typeof e?C(e,function(e){t(e!==!1)}):t(e!==!1)})}function s(e){Q&&o(Q,e)||(K=e,u(e,function(t){if(K===e)if(t){if(e.action===p.PUSH){var r=O(Q),a=O(e);a===r&&f["default"](Q.state,e.state)&&(e.action=p.REPLACE)}A(e)!==!1&&n(e)}else if(Q&&e.action===p.POP){var o=D.indexOf(Q.key),u=D.indexOf(e.key);-1!==o&&-1!==u&&T(o-u)}}))}function c(e){s(S(e,p.PUSH,_()))}function h(e){s(S(e,p.REPLACE,_()))}function v(){T(-1)}function m(){T(1)}function _(){return a(R)}function O(e){if(null==e||"string"==typeof e)return e;var t=e.pathname,n=e.search,r=e.hash,a=t;return n&&(a+=n),r&&(a+=r),a}function b(e){return O(e)}function S(e,t){var n=arguments.length<=2||void 0===arguments[2]?_():arguments[2];return"object"==typeof t&&("string"==typeof e&&(e=l.parsePath(e)),e=i({},e,{state:t}),t=n,n=arguments[3]||_()),g["default"](e,t,n)}function x(e){Q?(k(Q,e),n(Q)):k(L(),e)}function k(e,t){e.state=i({},e.state,t),B(e.key,e.state)}function H(e){-1===q.indexOf(e)&&q.push(e)}function M(e){q=q.filter(function(t){return t!==e})}function E(e,t){"string"==typeof t&&(t=l.parsePath(t)),c(i({state:e},t))}function j(e,t){"string"==typeof t&&(t=l.parsePath(t)),h(i({state:e},t))}var U=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],L=U.getCurrentLocation,A=U.finishTransition,B=U.saveState,T=U.go,C=U.getUserConfirmation,R=U.keyLength;"number"!=typeof R&&(R=P);var q=[],D=[],I=[],Q=void 0,K=void 0;return{listenBefore:e,listen:r,transitionTo:s,push:c,replace:h,go:T,goBack:v,goForward:m,createKey:_,createPath:O,createHref:b,createLocation:S,setState:w["default"](x,"setState is deprecated; use location.key to save state instead"),registerTransitionHook:w["default"](H,"registerTransitionHook is deprecated; use listenBefore instead"),unregisterTransitionHook:w["default"](M,"unregisterTransitionHook is deprecated; use the callback returned from listenBefore instead"),pushState:w["default"](E,"pushState is deprecated; use push instead"),replaceState:w["default"](j,"replaceState is deprecated; use replace instead")}}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s=n(1),c=(r(s),n(22)),f=r(c),l=n(2),d=n(15),p=n(4),h=n(12),g=r(h),v=n(8),y=r(v),m=n(3),w=r(m),P=6;t["default"]=u,e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(){var e=arguments.length<=0||void 0===arguments[0]?"/":arguments[0],t=arguments.length<=1||void 0===arguments[1]?i.POP:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2],r=arguments.length<=3||void 0===arguments[3]?null:arguments[3];"string"==typeof e&&(e=s.parsePath(e)),"object"==typeof t&&(e=o({},e,{state:t}),t=n||i.POP,n=r);var a=e.pathname||"/",u=e.search||"",c=e.hash||"",f=e.state||null;return{pathname:a,search:u,hash:c,state:f,action:t,key:n}}t.__esModule=!0;var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=n(1),i=(r(u),n(4)),s=n(2);t["default"]=a,e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e){function t(t){var n=e();return"string"==typeof n?((t||window.event).returnValue=n,n):void 0}return c.addEventListener(window,"beforeunload",t),function(){c.removeEventListener(window,"beforeunload",t)}}function o(e){return function(t){function n(){for(var e=void 0,t=0,n=d.length;null==e&&n>t;++t)e=d[t].call();return e}function r(e){return d.push(e),1===d.length&&s.canUseDOM&&(f=a(n)),function(){d=d.filter(function(t){return t!==e}),0===d.length&&f&&(f(),f=null)}}function o(e){s.canUseDOM&&-1===d.indexOf(e)&&(d.push(e),1===d.length&&(f=a(n)))}function i(e){d.length>0&&(d=d.filter(function(t){return t!==e}),0===d.length&&f())}var c=e(t),f=void 0,d=[];return u({},c,{listenBeforeUnload:r,registerBeforeUnloadHook:l["default"](o,"registerBeforeUnloadHook is deprecated; use listenBeforeUnload instead"),unregisterBeforeUnloadHook:l["default"](i,"unregisterBeforeUnloadHook is deprecated; use the callback returned from listenBeforeUnload instead")})}}t.__esModule=!0;var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(1),s=(r(i),n(5)),c=n(6),f=n(3),l=r(f);t["default"]=o,e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e){return s.stringify(e).replace(/%20/g,"+")}function o(e){return function(){function t(e){if(null==e.query){var t=e.search;e.query=O(t.substring(1)),e[h]={search:t,searchBase:""}}return e}function n(e,t){var n,r=e[h],a=t?_(t):"";if(!r&&!a)return e;"string"==typeof e&&(e=l.parsePath(e));var o=void 0;o=r&&e.search===r.search?r.searchBase:e.search||"";var i=o;return a&&(i+=(i?"&":"?")+a),u({},e,(n={search:i},n[h]={search:i,searchBase:o},n))}function r(e){return P.listenBefore(function(n,r){f["default"](e,t(n),r)})}function o(e){return P.listen(function(n){e(t(n))})}function i(e){P.push(n(e,e.query))}function s(e){P.replace(n(e,e.query))}function c(e,t){return P.createPath(n(e,t||e.query))}function d(e,t){return P.createHref(n(e,t||e.query))}function v(e){for(var r=arguments.length,a=Array(r>1?r-1:0),o=1;r>o;o++)a[o-1]=arguments[o];var u=P.createLocation.apply(P,[n(e,e.query)].concat(a));return e.query&&(u.query=e.query),t(u)}function y(e,t,n){"string"==typeof t&&(t=l.parsePath(t)),i(u({state:e},t,{query:n}))}function m(e,t,n){"string"==typeof t&&(t=l.parsePath(t)),s(u({state:e},t,{query:n}))}var w=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],P=e(w),_=w.stringifyQuery,O=w.parseQueryString;return"function"!=typeof _&&(_=a),"function"!=typeof O&&(O=g),u({},P,{listenBefore:r,listen:o,push:i,replace:s,createPath:c,createHref:d,createLocation:v,pushState:p["default"](y,"pushState is deprecated; use push instead"),replaceState:p["default"](m,"replaceState is deprecated; use replace instead")})}}t.__esModule=!0;var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(1),s=(r(i),n(25)),c=n(8),f=r(c),l=n(2),d=n(3),p=r(d),h="$searchBase",g=s.parse;t["default"]=o,e.exports=t["default"]},function(e,t){"use strict";function n(e,t,n){function a(){return i=!0,s?void(f=[].concat(r.call(arguments))):void n.apply(this,arguments)}function o(){if(!i&&(c=!0,!s)){for(s=!0;!i&&e>u&&c;)c=!1,t.call(this,u++,o,a);return s=!1,i?void n.apply(this,f):void(u>=e&&c&&(i=!0,n()))}}var u=0,i=!1,s=!1,c=!1,f=void 0;o()}t.__esModule=!0;var r=Array.prototype.slice;t.loopAsync=n},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(){function e(e){e=e||window.history.state||{};var t=l.getWindowPath(),n=e,r=n.key,a=void 0;r?a=d.readState(r):(a=null,r=w.createKey(),y&&window.history.replaceState(o({},e,{key:r}),null,t));var u=c.parsePath(t);return w.createLocation(o({},u,{state:a}),void 0,r)}function t(t){function n(t){void 0!==t.state&&r(e(t.state))}var r=t.transitionTo;return l.addEventListener(window,"popstate",n),function(){l.removeEventListener(window,"popstate",n)}}function n(e){var t=e.basename,n=e.pathname,r=e.search,a=e.hash,o=e.state,u=e.action,i=e.key;if(u!==s.POP){d.saveState(i,o);var c=(t||"")+n+r+a,f={key:i};if(u===s.PUSH){if(m)return window.location.href=c,!1;window.history.pushState(f,null,c)}else{if(m)return window.location.replace(c),!1;window.history.replaceState(f,null,c)}}}function r(e){1===++P&&(_=t(w));var n=w.listenBefore(e);return function(){n(),0===--P&&_()}}function a(e){1===++P&&(_=t(w));var n=w.listen(e);return function(){n(),0===--P&&_()}}function u(e){1===++P&&(_=t(w)),w.registerTransitionHook(e)}function p(e){w.unregisterTransitionHook(e),0===--P&&_()}var g=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];f.canUseDOM?void 0:i["default"](!1);var v=g.forceRefresh,y=l.supportsHistory(),m=!y||v,w=h["default"](o({},g,{getCurrentLocation:e,finishTransition:n,saveState:d.saveState})),P=0,_=void 0;return o({},w,{listenBefore:r,listen:a,registerTransitionHook:u,unregisterTransitionHook:p})}t.__esModule=!0;var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=n(7),i=r(u),s=n(4),c=n(2),f=n(5),l=n(6),d=n(9),p=n(10),h=r(p);t["default"]=a,e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e){return"string"==typeof e&&"/"===e.charAt(0)}function o(){var e=y.getHashPath();return a(e)?!0:(y.replaceHashPath("/"+e),!1)}function u(e,t,n){return e+(-1===e.indexOf("?")?"?":"&")+(t+"="+n)}function i(e,t){return e.replace(new RegExp("[?&]?"+t+"=[a-zA-Z0-9]+"),"")}function s(e,t){var n=e.match(new RegExp("\\?.*?\\b"+t+"=(.+?)\\b"));return n&&n[1]}function c(){function e(){var e=y.getHashPath(),t=void 0,n=void 0;H?(t=s(e,H),e=i(e,H),t?n=m.readState(t):(n=null,t=M.createKey(),y.replaceHashPath(u(e,H,t)))):t=n=null;var r=g.parsePath(e);return M.createLocation(f({},r,{state:n}),void 0,t)}function t(t){function n(){o()&&r(e())}var r=t.transitionTo;return o(),y.addEventListener(window,"hashchange",n),function(){y.removeEventListener(window,"hashchange",n)}}function n(e){var t=e.basename,n=e.pathname,r=e.search,a=e.state,o=e.action,i=e.key;if(o!==h.POP){var s=(t||"")+n+r;H?(s=u(s,H,i),m.saveState(i,a)):e.key=e.state=null;var c=y.getHashPath();o===h.PUSH?c!==s&&(window.location.hash=s):c!==s&&y.replaceHashPath(s)}}function r(e){1===++E&&(j=t(M));var n=M.listenBefore(e);return function(){n(),0===--E&&j()}}function a(e){1===++E&&(j=t(M));var n=M.listen(e);return function(){n(),0===--E&&j()}}function c(e){M.push(e)}function l(e){M.replace(e)}function d(e){M.go(e)}function w(e){return"#"+M.createHref(e)}function O(e){1===++E&&(j=t(M)),M.registerTransitionHook(e)}function b(e){M.unregisterTransitionHook(e),0===--E&&j()}function S(e,t){M.pushState(e,t)}function x(e,t){M.replaceState(e,t)}var k=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];v.canUseDOM?void 0:p["default"](!1);var H=k.queryKey;(void 0===H||H)&&(H="string"==typeof H?H:_);var M=P["default"](f({},k,{getCurrentLocation:e,finishTransition:n,saveState:m.saveState})),E=0,j=void 0;y.supportsGoWithoutReloadUsingHash();return f({},M,{listenBefore:r,listen:a,push:c,replace:l,go:d,createHref:w,registerTransitionHook:O,unregisterTransitionHook:b,pushState:S,replaceState:x})}t.__esModule=!0;var f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l=n(1),d=(r(l),n(7)),p=r(d),h=n(4),g=n(2),v=n(5),y=n(6),m=n(9),w=n(10),P=r(w),_="_k";t["default"]=c,e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e){return e.filter(function(e){return e.state}).reduce(function(e,t){return e[t.key]=t.state,e},{})}function o(){function e(e,t){y[e]=t}function t(e){return y[e]}function n(){var e=g[v],n=e.basename,r=e.pathname,a=e.search,o=(n||"")+r+(a||""),i=void 0,s=void 0;e.key?(i=e.key,s=t(i)):(i=d.createKey(),s=null,e.key=i);var c=f.parsePath(o);return d.createLocation(u({},c,{state:s}),void 0,i)}function r(e){var t=v+e;return t>=0&&t<g.length}function o(e){if(e){if(!r(e))return;v+=e;var t=n();d.transitionTo(u({},t,{action:l.POP}))}}function i(t){switch(t.action){case l.PUSH:v+=1,v<g.length&&g.splice(v),g.push(t),e(t.key,t.state);break;case l.REPLACE:g[v]=t,e(t.key,t.state)}}var s=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];Array.isArray(s)?s={entries:s}:"string"==typeof s&&(s={entries:[s]});var d=p["default"](u({},s,{getCurrentLocation:n,finishTransition:i,saveState:e,go:o})),h=s,g=h.entries,v=h.current;"string"==typeof g?g=[g]:Array.isArray(g)||(g=["/"]),g=g.map(function(e){var t=d.createKey();return"string"==typeof e?{pathname:e,key:t}:"object"==typeof e&&e?u({},e,{key:t}):void c["default"](!1)}),null==v?v=g.length-1:v>=0&&v<g.length?void 0:c["default"](!1);var y=a(g);return d}t.__esModule=!0;var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(1),s=(r(i),n(7)),c=r(s),f=n(2),l=n(4),d=n(11),p=r(d);t["default"]=o,e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var a=n(3),o=r(a),u=n(13),i=r(u);t["default"]=o["default"](i["default"],"enableBeforeUnload is deprecated, use useBeforeUnload instead"),e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var a=n(3),o=r(a),u=n(14),i=r(u);t["default"]=o["default"](i["default"],"enableQueries is deprecated, use useQueries instead"),e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function a(e){return function(){function t(e){return w&&null==e.basename&&(0===e.pathname.indexOf(w)?(e.pathname=e.pathname.substring(w.length),e.basename=w,""===e.pathname&&(e.pathname="/")):e.basename=""),e}function n(e){if(!w)return e;"string"==typeof e&&(e=i.parsePath(e));var t=e.pathname,n="/"===w.slice(-1)?w:w+"/",r="/"===t.charAt(0)?t.slice(1):t,a=n+r;return o({},e,{pathname:a})}function r(e){return m.listenBefore(function(n,r){c["default"](e,t(n),r)})}function a(e){return m.listen(function(n){e(t(n))})}function s(e){m.push(n(e))}function f(e){m.replace(n(e))}function d(e){return m.createPath(n(e))}function p(e){return m.createHref(n(e))}function h(e){for(var r=arguments.length,a=Array(r>1?r-1:0),o=1;r>o;o++)a[o-1]=arguments[o];return t(m.createLocation.apply(m,[n(e)].concat(a)))}function g(e,t){"string"==typeof t&&(t=i.parsePath(t)),s(o({state:e},t))}function v(e,t){"string"==typeof t&&(t=i.parsePath(t)),f(o({state:e},t))}var y=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],m=e(y),w=y.basename;if(null==w&&u.canUseDOM){var P=document.getElementsByTagName("base")[0];P&&(w=i.extractPath(P.href))}return o({},m,{listenBefore:r,listen:a,push:s,replace:f,createPath:d,createHref:p,createLocation:h,pushState:l["default"](g,"pushState is deprecated; use push instead"),replaceState:l["default"](v,"replaceState is deprecated; use replace instead")})}}t.__esModule=!0;var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=n(5),i=n(2),s=n(8),c=r(s),f=n(3),l=r(f);t["default"]=a,e.exports=t["default"]},function(e,t,n){function r(e){return null===e||void 0===e}function a(e){return e&&"object"==typeof e&&"number"==typeof e.length?"function"!=typeof e.copy||"function"!=typeof e.slice?!1:e.length>0&&"number"!=typeof e[0]?!1:!0:!1}function o(e,t,n){var o,f;if(r(e)||r(t))return!1;if(e.prototype!==t.prototype)return!1;if(s(e))return s(t)?(e=u.call(e),t=u.call(t),c(e,t,n)):!1;if(a(e)){if(!a(t))return!1;if(e.length!==t.length)return!1;for(o=0;o<e.length;o++)if(e[o]!==t[o])return!1;return!0}try{var l=i(e),d=i(t)}catch(p){return!1}if(l.length!=d.length)return!1;for(l.sort(),d.sort(),o=l.length-1;o>=0;o--)if(l[o]!=d[o])return!1;for(o=l.length-1;o>=0;o--)if(f=l[o],!c(e[f],t[f],n))return!1;return typeof e==typeof t}var u=Array.prototype.slice,i=n(24),s=n(23),c=e.exports=function(e,t,n){return n||(n={}),e===t?!0:e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():!e||!t||"object"!=typeof e&&"object"!=typeof t?n.strict?e===t:e==t:o(e,t,n)}},function(e,t){function n(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function r(e){return e&&"object"==typeof e&&"number"==typeof e.length&&Object.prototype.hasOwnProperty.call(e,"callee")&&!Object.prototype.propertyIsEnumerable.call(e,"callee")||!1}var a="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();t=e.exports=a?n:r,t.supported=n,t.unsupported=r},function(e,t){function n(e){var t=[];for(var n in e)t.push(n);return t}t=e.exports="function"==typeof Object.keys?Object.keys:n,t.shim=n},function(e,t,n){"use strict";var r=n(26);t.extract=function(e){return e.split("?")[1]||""},t.parse=function(e){return"string"!=typeof e?{}:(e=e.trim().replace(/^(\?|#|&)/,""),e?e.split("&").reduce(function(e,t){var n=t.replace(/\+/g," ").split("="),r=n.shift(),a=n.length>0?n.join("="):void 0;return r=decodeURIComponent(r),a=void 0===a?null:decodeURIComponent(a),e.hasOwnProperty(r)?Array.isArray(e[r])?e[r].push(a):e[r]=[e[r],a]:e[r]=a,e},{}):{})},t.stringify=function(e){return e?Object.keys(e).sort().map(function(t){var n=e[t];return void 0===n?"":null===n?t:Array.isArray(n)?n.sort().map(function(e){return r(t)+"="+r(e)}).join("&"):r(t)+"="+r(n)}).filter(function(e){return e.length>0}).join("&"):""}},function(e,t){"use strict";e.exports=function(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.History=t():e.History=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Actions=t.useQueries=t.useBeforeUnload=t.useBasename=t.createMemoryHistory=t.createHashHistory=t.createHistory=void 0;var o=n(16),i=r(o),u=n(17),a=r(u),c=n(18),f=r(c),s=n(19),l=r(s),d=n(20),p=r(d),h=n(21),v=r(h),y=n(5),g=r(y);t.createHistory=i["default"],t.createHashHistory=a["default"],t.createMemoryHistory=f["default"],t.useBasename=l["default"],t.useBeforeUnload=p["default"],t.useQueries=v["default"],t.Actions=g["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.createPath=t.parsePath=t.getQueryStringValueFromPath=t.stripQueryStringValueFromPath=t.addQueryStringValueToPath=t.isAbsolutePath=void 0;var o=n(2),i=(r(o),t.isAbsolutePath=function(e){return"string"==typeof e&&"/"===e.charAt(0)},t.addQueryStringValueToPath=function(e,t,n){var r=u(e),o=r.pathname,i=r.search,c=r.hash;return a({pathname:o,search:i+(-1===i.indexOf("?")?"?":"&")+t+"="+n,hash:c})},t.stripQueryStringValueFromPath=function(e,t){var n=u(e),r=n.pathname,o=n.search,i=n.hash;return a({pathname:r,search:o.replace(new RegExp("([?&])"+t+"=[a-zA-Z0-9]+(&?)"),function(e,t,n){return"?"===t?t:n}),hash:i})},t.getQueryStringValueFromPath=function(e,t){var n=u(e),r=n.search,o=r.match(new RegExp("[?&]"+t+"=([a-zA-Z0-9]+)"));return o&&o[1]},function(e){var t=e.match(/^https?:\/\/[^\/]*/);return null==t?e:e.substring(t[0].length)}),u=t.parsePath=function(e){var t=i(e),n="",r="",o=t.indexOf("#");-1!==o&&(r=t.substring(o),t=t.substring(0,o));var u=t.indexOf("?");return-1!==u&&(n=t.substring(u),t=t.substring(0,u)),""===t&&(t="/"),{pathname:t,search:n,hash:r}},a=t.createPath=function(e){if(null==e||"string"==typeof e)return e;var t=e.basename,n=e.pathname,r=e.search,o=e.hash,i=(t||"")+n;return r&&"?"!==r&&(i+=r),o&&(i+=o),i}},function(e,t,n){"use strict";var r=function(){};e.exports=r},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.addEventListener=function(e,t,n){return e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)},t.removeEventListener=function(e,t,n){return e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent("on"+t,n)},t.supportsHistory=function(){var e=navigator.userAgent;return-1===e.indexOf("Android 2.")&&-1===e.indexOf("Android 4.0")||-1===e.indexOf("Mobile Safari")||-1!==e.indexOf("Chrome")||-1!==e.indexOf("Windows Phone")?window.history&&"pushState"in window.history:!1},t.supportsGoWithoutReloadUsingHash=function(){return-1===navigator.userAgent.indexOf("Firefox")}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.createLocation=t.locationsAreEqual=void 0;var o=n(12),i=r(o),u=n(1),a=n(5);t.locationsAreEqual=function(e,t){return e.pathname===t.pathname&&e.search===t.search&&e.hash===t.hash&&e.key===t.key&&(0,i["default"])(e.state,t.state)},t.createLocation=function(){var e=arguments.length<=0||void 0===arguments[0]?"/":arguments[0],t=arguments.length<=1||void 0===arguments[1]?a.POP:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2],r="string"==typeof e?(0,u.parsePath)(e):e,o=r.pathname||"/",i=r.search||"",c=r.hash||"",f=r.state;return{pathname:o,search:i,hash:c,state:f,action:t,key:n}}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.PUSH="PUSH",t.REPLACE="REPLACE",t.POP="POP"},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.canUseDOM=!("undefined"==typeof window||!window.document||!window.document.createElement)},function(e,t,n){"use strict";var r=function(e,t,n,r,o,i,u,a){if(!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var f=[n,r,o,i,u,a],s=0;c=new Error(t.replace(/%s/g,function(){return f[s++]})),c.name="Invariant Violation"}throw c.framesToPop=1,c}};e.exports=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.go=t.replaceLocation=t.pushLocation=t.startListener=t.getUserConfirmation=t.getCurrentLocation=void 0;var r=n(4),o=n(3),i=n(11),u=n(1),a=function(e){var t=e&&e.key;return(0,r.createLocation)({pathname:window.location.pathname,search:window.location.search,hash:window.location.hash,state:t?(0,i.readState)(t):void 0},void 0,t)},c=(t.getCurrentLocation=function(){return a(window.history.state)},t.getUserConfirmation=function(e,t){return t(window.confirm(e))},"popstate"),f=(t.startListener=function(e){var t=function(t){void 0!==t.state&&e(a(t.state))};return(0,o.addEventListener)(window,c,t),function(){return(0,o.removeEventListener)(window,c,t)}},function(e,t){var n=e.state,r=e.key;void 0!==n&&(0,i.saveState)(r,n),t({key:r},(0,u.createPath)(e))});t.pushLocation=function(e){return f(e,function(e,t){return window.history.pushState(e,null,t)})},t.replaceLocation=function(e){return f(e,function(e,t){return window.history.replaceState(e,null,t)})},t.go=function(e){e&&window.history.go(e)}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}Object.defineProperty(t,"__esModule",{value:!0});var i=n(12),u=r(i),a=n(13),c=n(1),f=n(10),s=r(f),l=n(5),d=n(4),p=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=e.getCurrentLocation,n=e.getUserConfirmation,r=e.pushLocation,i=e.replaceLocation,f=e.go,p=e.keyLength,h=void 0,v=void 0,y=[],g=[],m=[],P=function(){return v&&v.action===l.POP?m.indexOf(v.key):h?m.indexOf(h.key):-1},b=function(e){h=e;var t=P();h.action===l.PUSH?m=[].concat(o(m.slice(0,t+1)),[h.key]):h.action===l.REPLACE&&(m[t]=h.key),g.forEach(function(e){return e(h)})},O=function(e){return y.push(e),function(){return y=y.filter(function(t){return t!==e})}},w=function(e){return g.push(e),function(){return g=g.filter(function(t){return t!==e})}},L=function(e,t){(0,a.loopAsync)(y.length,function(t,n,r){(0,s["default"])(y[t],e,function(e){return null!=e?r(e):n()})},function(e){n&&"string"==typeof e?n(e,function(e){return t(e!==!1)}):t(e!==!1)})},_=function(e){h&&(0,d.locationsAreEqual)(h,e)||v&&(0,d.locationsAreEqual)(v,e)||(v=e,L(e,function(t){if(v===e)if(v=null,t){if(e.action===l.PUSH){var n=(0,c.createPath)(h),o=(0,c.createPath)(e);o===n&&(0,u["default"])(h.state,e.state)&&(e.action=l.REPLACE)}e.action===l.POP?b(e):e.action===l.PUSH?r(e)!==!1&&b(e):e.action===l.REPLACE&&i(e)!==!1&&b(e)}else if(h&&e.action===l.POP){var a=m.indexOf(h.key),s=m.indexOf(e.key);-1!==a&&-1!==s&&f(a-s)}}))},j=function(e){return _(x(e,l.PUSH))},A=function(e){return _(x(e,l.REPLACE))},E=function(){return f(-1)},M=function(){return f(1)},C=function(){return Math.random().toString(36).substr(2,p||6)},S=function(e){return(0,c.createPath)(e)},x=function(e,t){var n=arguments.length<=2||void 0===arguments[2]?C():arguments[2];return(0,d.createLocation)(e,t,n)};return{getCurrentLocation:t,listenBefore:O,listen:w,transitionTo:_,push:j,replace:A,go:f,goBack:E,goForward:M,createKey:C,createPath:c.createPath,createHref:S,createLocation:x}};t["default"]=p},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(2),i=(r(o),function(e,t,n){var r=e(t,n);e.length<2&&n(r)});t["default"]=i},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.readState=t.saveState=void 0;var o=n(2),i=(r(o),["QuotaExceededError","QUOTA_EXCEEDED_ERR"]),u="SecurityError",a="@@History/",c=function(e){return a+e};t.saveState=function(e,t){try{null==t?window.sessionStorage.removeItem(c(e)):window.sessionStorage.setItem(c(e),JSON.stringify(t))}catch(n){if(n.name===u)return;if(i.indexOf(n.name)>=0&&0===window.sessionStorage.length)return;throw n}},t.readState=function(e){var t=void 0;try{t=window.sessionStorage.getItem(c(e))}catch(n){if(n.name===u)return}if(t)try{return JSON.parse(t)}catch(n){}}},function(e,t,n){function r(e){return null===e||void 0===e}function o(e){return e&&"object"==typeof e&&"number"==typeof e.length?"function"!=typeof e.copy||"function"!=typeof e.slice?!1:!(e.length>0&&"number"!=typeof e[0]):!1}function i(e,t,n){var i,s;if(r(e)||r(t))return!1;if(e.prototype!==t.prototype)return!1;if(c(e))return c(t)?(e=u.call(e),t=u.call(t),f(e,t,n)):!1;if(o(e)){if(!o(t))return!1;if(e.length!==t.length)return!1;for(i=0;i<e.length;i++)if(e[i]!==t[i])return!1;return!0}try{var l=a(e),d=a(t)}catch(p){return!1}if(l.length!=d.length)return!1;for(l.sort(),d.sort(),i=l.length-1;i>=0;i--)if(l[i]!=d[i])return!1;for(i=l.length-1;i>=0;i--)if(s=l[i],!f(e[s],t[s],n))return!1;return typeof e==typeof t}var u=Array.prototype.slice,a=n(23),c=n(22),f=e.exports=function(e,t,n){return n||(n={}),e===t?!0:e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():!e||!t||"object"!=typeof e&&"object"!=typeof t?n.strict?e===t:e==t:i(e,t,n)}},function(e,t){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}Object.defineProperty(t,"__esModule",{value:!0});t.loopAsync=function(e,t,r){var o=0,i=!1,u=!1,a=!1,c=void 0,f=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];return i=!0,u?void(c=t):void r.apply(void 0,t)},s=function l(){if(!i&&(a=!0,!u)){for(u=!0;!i&&e>o&&a;)a=!1,t.call(void 0,o++,l,f);return u=!1,i?void r.apply(void 0,n(c)):void(o>=e&&a&&(i=!0,r()))}};s()}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.replaceLocation=t.pushLocation=t.startListener=t.getCurrentLocation=t.go=t.getUserConfirmation=void 0;var o=n(8);Object.defineProperty(t,"getUserConfirmation",{enumerable:!0,get:function(){return o.getUserConfirmation}}),Object.defineProperty(t,"go",{enumerable:!0,get:function(){return o.go}});var i=n(2),u=(r(i),n(4)),a=n(3),c=n(11),f=n(1),s=function(){var e=window.location.href,t=e.indexOf("#");return-1===t?"":e.substring(t+1)},l=function(e){return window.location.hash=e},d=function(e){return window.location.replace(window.location.pathname+window.location.search+"#"+e)},p=function(){var e=s();return(0,f.isAbsolutePath)(e)?!0:(d("/"+e),!1)},h=t.getCurrentLocation=function(e){var t=s(),n=(0,f.getQueryStringValueFromPath)(t,e),r=void 0;n&&(t=(0,f.stripQueryStringValueFromPath)(t,e),r=(0,c.readState)(n));var o=(0,f.parsePath)(t);return o.state=r,(0,u.createLocation)(o,void 0,n)},v="hashchange",y=void 0,g=(t.startListener=function(e,t){var n=function(){if(p()){var n=h(t);y&&n.key&&y.key===n.key||(y=n,e(n))}};return p(),(0,a.addEventListener)(window,v,n),function(){return(0,a.removeEventListener)(window,v,n)}},function(e,t,n){var r=e.state,o=e.key,i=(0,f.createPath)(e);void 0!==r&&(i=(0,f.addQueryStringValueToPath)(i,t,o),(0,c.saveState)(o,r)),y=e,n(i)});t.pushLocation=function(e,t){return g(e,t,function(e){s()!==e&&l(e)})},t.replaceLocation=function(e,t){return g(e,t,function(e){s()!==e&&d(e)})}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.replaceLocation=t.pushLocation=t.getCurrentLocation=t.go=t.getUserConfirmation=void 0;var r=n(8);Object.defineProperty(t,"getUserConfirmation",{enumerable:!0,get:function(){return r.getUserConfirmation}}),Object.defineProperty(t,"go",{enumerable:!0,get:function(){return r.go}});var o=n(4),i=n(1);t.getCurrentLocation=function(){return(0,o.createLocation)(window.location)},t.pushLocation=function(e){return window.location.href=(0,i.createPath)(e),!1},t.replaceLocation=function(e){return window.location.replace((0,i.createPath)(e)),!1}},function(e,t,n){"use strict";function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t["default"]=e,t}function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=n(7),a=o(u),c=n(6),f=n(8),s=r(f),l=n(15),d=r(l),p=n(3),h=n(9),v=o(h),y=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];c.canUseDOM?void 0:(0,a["default"])(!1);var t=e.forceRefresh||!(0,p.supportsHistory)(),n=t?d:s,r=n.getUserConfirmation,o=n.getCurrentLocation,u=n.pushLocation,f=n.replaceLocation,l=n.go,h=(0,v["default"])(i({getUserConfirmation:r},e,{getCurrentLocation:o,pushLocation:u,replaceLocation:f,go:l})),y=0,g=void 0,m=function(e,t){1===++y&&(g=s.startListener(h.transitionTo));var n=t?h.listenBefore(e):h.listen(e);return function(){n(),0===--y&&g()}},P=function(e){return m(e,!0)},b=function(e){return m(e,!1)};return i({},h,{listenBefore:P,listen:b})};t["default"]=y},function(e,t,n){"use strict";function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t["default"]=e,t}function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=n(2),a=(o(u),n(7)),c=o(a),f=n(6),s=n(3),l=n(14),d=r(l),p=n(9),h=o(p),v="_k",y=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];f.canUseDOM?void 0:(0,c["default"])(!1);var t=e.queryKey;"string"!=typeof t&&(t=v);var n=d.getUserConfirmation,r=function(){return d.getCurrentLocation(t)},o=function(e){return d.pushLocation(e,t)},u=function(e){return d.replaceLocation(e,t)},a=(0,h["default"])(i({getUserConfirmation:n},e,{getCurrentLocation:r,pushLocation:o,replaceLocation:u,go:d.go})),l=0,p=void 0,y=function(e,n){1===++l&&(p=d.startListener(a.transitionTo,t));var r=n?a.listenBefore(e):a.listen(e);return function(){r(),0===--l&&p()}},g=function(e){return y(e,!0)},m=function(e){return y(e,!1)},P=((0,s.supportsGoWithoutReloadUsingHash)(),function(e){a.go(e)}),b=function(e){return"#"+a.createHref(e)};return i({},a,{listenBefore:g,listen:m,go:P,createHref:b})};t["default"]=y},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(2),u=(r(i),n(7)),a=r(u),c=n(4),f=n(1),s=n(9),l=r(s),d=n(5),p=function(e){return e.filter(function(e){return e.state}).reduce(function(e,t){return e[t.key]=t.state,e},{})},h=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];Array.isArray(e)?e={entries:e}:"string"==typeof e&&(e={entries:[e]});var t=function(){var e=h[v],t=(0,f.createPath)(e),n=void 0,r=void 0;e.key&&(n=e.key,r=m(n));var i=(0,f.parsePath)(t);return(0,c.createLocation)(o({},i,{state:r}),void 0,n)},n=function(e){var t=v+e;return t>=0&&t<h.length},r=function(e){if(e&&n(e)){v+=e;var r=t();s.transitionTo(o({},r,{action:d.POP}))}},i=function(e){v+=1,v<h.length&&h.splice(v),h.push(e),g(e.key,e.state)},u=function(e){h[v]=e,g(e.key,e.state)},s=(0,l["default"])(o({},e,{getCurrentLocation:t,pushLocation:i,replaceLocation:u,go:r})),h=e.entries,v=e.current;"string"==typeof h?h=[h]:Array.isArray(h)||(h=["/"]),h=h.map(function(e){return(0,c.createLocation)(e)}),null==v?v=h.length-1:v>=0&&v<h.length?void 0:(0,a["default"])(!1);var y=p(h),g=function(e,t){return y[e]=t},m=function(e){return y[e]};return s};t["default"]=h},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(6),u=n(10),a=r(u),c=n(1),f=function(e){return function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e(t),r=t.basename;if(null==r&&i.canUseDOM){var u=document.getElementsByTagName("base")[0];u&&(r=u.getAttribute("href"))}var f=function(e){return e?(r&&null==e.basename&&(0===e.pathname.indexOf(r)?(e.pathname=e.pathname.substring(r.length),e.basename=r,""===e.pathname&&(e.pathname="/")):e.basename=""),e):e},s=function(e){if(!r)return e;var t="string"==typeof e?(0,c.parsePath)(e):e,n=t.pathname,i="/"===r.slice(-1)?r:r+"/",u="/"===n.charAt(0)?n.slice(1):n,a=i+u;return o({},e,{pathname:a})},l=function(){return f(n.getCurrentLocation())},d=function(e){return n.listenBefore(function(t,n){return(0,a["default"])(e,f(t),n)})},p=function(e){return n.listen(function(t){return e(f(t))})},h=function(e){return n.push(s(e))},v=function(e){return n.replace(s(e))},y=function(e){return n.createPath(s(e))},g=function(e){return n.createHref(s(e))},m=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),o=1;t>o;o++)r[o-1]=arguments[o];return f(n.createLocation.apply(n,[s(e)].concat(r)))};return o({},n,{getCurrentLocation:l,listenBefore:d,listen:p,push:h,replace:v,createPath:y,createHref:g,createLocation:m})}};t["default"]=f},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(7),u=r(i),a=n(3),c=n(6),f=function(e){var t=function(t){var n=e();return"string"==typeof n?((t||window.event).returnValue=n,n):void 0};return(0,a.addEventListener)(window,"beforeunload",t),function(){return(0,a.removeEventListener)(window,"beforeunload",t)}},s=function(e){return c.canUseDOM?void 0:(0,u["default"])(!1),function(t){var n=e(t),r=[],i=void 0,u=function(){for(var e=void 0,t=0,n=r.length;null==e&&n>t;++t)e=r[t].call();return e},a=function(e){return 1===r.push(e)&&(i=f(u)),function(){r=r.filter(function(t){return t!==e}),0===r.length&&i&&(i(),i=null)}};return o({},n,{listenBeforeUnload:a})}};t["default"]=s},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},n(2)),u=(r(i),n(24)),a=n(10),c=r(a),f=n(1),s=function(e){return(0,u.stringify)(e).replace(/%20/g,"+")},l=u.parse,d=function(e){return function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e(t),r=t.stringifyQuery,i=t.parseQueryString;"function"!=typeof r&&(r=s),"function"!=typeof i&&(i=l);var u=function(e){return e?(null==e.query&&(e.query=i(e.search.substring(1))),e):e},a=function(e,t){if(null==t)return e;var n="string"==typeof e?(0,f.parsePath)(e):e,i=r(t),u=i?"?"+i:"";return o({},n,{search:u})},d=function(){return u(n.getCurrentLocation())},p=function(e){return n.listenBefore(function(t,n){return(0,c["default"])(e,u(t),n)})},h=function(e){return n.listen(function(t){return e(u(t))})},v=function(e){return n.push(a(e,e.query))},y=function(e){return n.replace(a(e,e.query))},g=function(e){return n.createPath(a(e,e.query))},m=function(e){return n.createHref(a(e,e.query))},P=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),o=1;t>o;o++)r[o-1]=arguments[o];var i=n.createLocation.apply(n,[a(e,e.query)].concat(r));return e.query&&(i.query=e.query),u(i)};return o({},n,{getCurrentLocation:d,listenBefore:p,listen:h,push:v,replace:y,createPath:g,createHref:m,createLocation:P})}};t["default"]=d},function(e,t){function n(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function r(e){return e&&"object"==typeof e&&"number"==typeof e.length&&Object.prototype.hasOwnProperty.call(e,"callee")&&!Object.prototype.propertyIsEnumerable.call(e,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();t=e.exports=o?n:r,t.supported=n,t.unsupported=r},function(e,t){function n(e){var t=[];for(var n in e)t.push(n);return t}t=e.exports="function"==typeof Object.keys?Object.keys:n,t.shim=n},function(e,t,n){"use strict";var r=n(25);t.extract=function(e){return e.split("?")[1]||""},t.parse=function(e){return"string"!=typeof e?{}:(e=e.trim().replace(/^(\?|#|&)/,""),e?e.split("&").reduce(function(e,t){var n=t.replace(/\+/g," ").split("="),r=n.shift(),o=n.length>0?n.join("="):void 0;return r=decodeURIComponent(r),o=void 0===o?null:decodeURIComponent(o),e.hasOwnProperty(r)?Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]:e[r]=o,e},{}):{})},t.stringify=function(e){return e?Object.keys(e).sort().map(function(t){var n=e[t];return void 0===n?"":null===n?t:Array.isArray(n)?n.slice().sort().map(function(e){return r(t)+"="+r(e)}).join("&"):r(t)+"="+r(n)}).filter(function(e){return e.length>0}).join("&"):""}},function(e,t){"use strict";e.exports=function(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}}])}); |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
0
78
28
195271
25
44
3718
1
1