history
Advanced tools
Comparing version 4.7.2 to 4.8.0-beta.0
@@ -1,307 +0,3 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
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; }; | ||
var _warning = require('warning'); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var _invariant = require('invariant'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _LocationUtils = require('./LocationUtils'); | ||
var _PathUtils = require('./PathUtils'); | ||
var _createTransitionManager = require('./createTransitionManager'); | ||
var _createTransitionManager2 = _interopRequireDefault(_createTransitionManager); | ||
var _DOMUtils = require('./DOMUtils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var PopStateEvent = 'popstate'; | ||
var HashChangeEvent = 'hashchange'; | ||
var getHistoryState = function getHistoryState() { | ||
try { | ||
return window.history.state || {}; | ||
} catch (e) { | ||
// IE 11 sometimes throws when accessing window.history.state | ||
// See https://github.com/ReactTraining/history/pull/289 | ||
return {}; | ||
} | ||
}; | ||
/** | ||
* Creates a history object that uses the HTML5 history API including | ||
* pushState, replaceState, and the popstate event. | ||
*/ | ||
var createBrowserHistory = function createBrowserHistory() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
(0, _invariant2.default)(_DOMUtils.canUseDOM, 'Browser history needs a DOM'); | ||
var globalHistory = window.history; | ||
var canUseHistory = (0, _DOMUtils.supportsHistory)(); | ||
var needsHashChangeListener = !(0, _DOMUtils.supportsPopStateOnHashChange)(); | ||
var _props$forceRefresh = props.forceRefresh, | ||
forceRefresh = _props$forceRefresh === undefined ? false : _props$forceRefresh, | ||
_props$getUserConfirm = props.getUserConfirmation, | ||
getUserConfirmation = _props$getUserConfirm === undefined ? _DOMUtils.getConfirmation : _props$getUserConfirm, | ||
_props$keyLength = props.keyLength, | ||
keyLength = _props$keyLength === undefined ? 6 : _props$keyLength; | ||
var basename = props.basename ? (0, _PathUtils.stripTrailingSlash)((0, _PathUtils.addLeadingSlash)(props.basename)) : ''; | ||
var getDOMLocation = function getDOMLocation(historyState) { | ||
var _ref = historyState || {}, | ||
key = _ref.key, | ||
state = _ref.state; | ||
var _window$location = window.location, | ||
pathname = _window$location.pathname, | ||
search = _window$location.search, | ||
hash = _window$location.hash; | ||
var path = pathname + search + hash; | ||
(0, _warning2.default)(!basename || (0, _PathUtils.hasBasename)(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".'); | ||
if (basename) path = (0, _PathUtils.stripBasename)(path, basename); | ||
return (0, _LocationUtils.createLocation)(path, state, key); | ||
}; | ||
var createKey = function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength); | ||
}; | ||
var transitionManager = (0, _createTransitionManager2.default)(); | ||
var setState = function setState(nextState) { | ||
_extends(history, nextState); | ||
history.length = globalHistory.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
}; | ||
var handlePopState = function handlePopState(event) { | ||
// Ignore extraneous popstate events in WebKit. | ||
if ((0, _DOMUtils.isExtraneousPopstateEvent)(event)) return; | ||
handlePop(getDOMLocation(event.state)); | ||
}; | ||
var handleHashChange = function handleHashChange() { | ||
handlePop(getDOMLocation(getHistoryState())); | ||
}; | ||
var forceNextPop = false; | ||
var handlePop = function handlePop(location) { | ||
if (forceNextPop) { | ||
forceNextPop = false; | ||
setState(); | ||
} else { | ||
var action = 'POP'; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ action: action, location: location }); | ||
} else { | ||
revertPop(location); | ||
} | ||
}); | ||
} | ||
}; | ||
var revertPop = function revertPop(fromLocation) { | ||
var toLocation = history.location; | ||
// TODO: We could probably make this more reliable by | ||
// keeping a list of keys we've seen in sessionStorage. | ||
// Instead, we just default to 0 for keys we don't know. | ||
var toIndex = allKeys.indexOf(toLocation.key); | ||
if (toIndex === -1) toIndex = 0; | ||
var fromIndex = allKeys.indexOf(fromLocation.key); | ||
if (fromIndex === -1) fromIndex = 0; | ||
var delta = toIndex - fromIndex; | ||
if (delta) { | ||
forceNextPop = true; | ||
go(delta); | ||
} | ||
}; | ||
var initialLocation = getDOMLocation(getHistoryState()); | ||
var allKeys = [initialLocation.key]; | ||
// Public interface | ||
var createHref = function createHref(location) { | ||
return basename + (0, _PathUtils.createPath)(location); | ||
}; | ||
var push = function push(path, state) { | ||
(0, _warning2.default)(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to push when the 1st ' + 'argument is a location-like object that already has state; it is ignored'); | ||
var action = 'PUSH'; | ||
var location = (0, _LocationUtils.createLocation)(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var href = createHref(location); | ||
var key = location.key, | ||
state = location.state; | ||
if (canUseHistory) { | ||
globalHistory.pushState({ key: key, state: state }, null, href); | ||
if (forceRefresh) { | ||
window.location.href = href; | ||
} else { | ||
var prevIndex = allKeys.indexOf(history.location.key); | ||
var nextKeys = allKeys.slice(0, prevIndex === -1 ? 0 : prevIndex + 1); | ||
nextKeys.push(location.key); | ||
allKeys = nextKeys; | ||
setState({ action: action, location: location }); | ||
} | ||
} else { | ||
(0, _warning2.default)(state === undefined, 'Browser history cannot push state in browsers that do not support HTML5 history'); | ||
window.location.href = href; | ||
} | ||
}); | ||
}; | ||
var replace = function replace(path, state) { | ||
(0, _warning2.default)(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to replace when the 1st ' + 'argument is a location-like object that already has state; it is ignored'); | ||
var action = 'REPLACE'; | ||
var location = (0, _LocationUtils.createLocation)(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var href = createHref(location); | ||
var key = location.key, | ||
state = location.state; | ||
if (canUseHistory) { | ||
globalHistory.replaceState({ key: key, state: state }, null, href); | ||
if (forceRefresh) { | ||
window.location.replace(href); | ||
} else { | ||
var prevIndex = allKeys.indexOf(history.location.key); | ||
if (prevIndex !== -1) allKeys[prevIndex] = location.key; | ||
setState({ action: action, location: location }); | ||
} | ||
} else { | ||
(0, _warning2.default)(state === undefined, 'Browser history cannot replace state in browsers that do not support HTML5 history'); | ||
window.location.replace(href); | ||
} | ||
}); | ||
}; | ||
var go = function go(n) { | ||
globalHistory.go(n); | ||
}; | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
var listenerCount = 0; | ||
var checkDOMListeners = function checkDOMListeners(delta) { | ||
listenerCount += delta; | ||
if (listenerCount === 1) { | ||
(0, _DOMUtils.addEventListener)(window, PopStateEvent, handlePopState); | ||
if (needsHashChangeListener) (0, _DOMUtils.addEventListener)(window, HashChangeEvent, handleHashChange); | ||
} else if (listenerCount === 0) { | ||
(0, _DOMUtils.removeEventListener)(window, PopStateEvent, handlePopState); | ||
if (needsHashChangeListener) (0, _DOMUtils.removeEventListener)(window, HashChangeEvent, handleHashChange); | ||
} | ||
}; | ||
var isBlocked = false; | ||
var block = function block() { | ||
var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
var unblock = transitionManager.setPrompt(prompt); | ||
if (!isBlocked) { | ||
checkDOMListeners(1); | ||
isBlocked = true; | ||
} | ||
return function () { | ||
if (isBlocked) { | ||
isBlocked = false; | ||
checkDOMListeners(-1); | ||
} | ||
return unblock(); | ||
}; | ||
}; | ||
var listen = function listen(listener) { | ||
var unlisten = transitionManager.appendListener(listener); | ||
checkDOMListeners(1); | ||
return function () { | ||
checkDOMListeners(-1); | ||
unlisten(); | ||
}; | ||
}; | ||
var history = { | ||
length: globalHistory.length, | ||
action: 'POP', | ||
location: initialLocation, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
}; | ||
exports.default = createBrowserHistory; | ||
"use strict"; | ||
require("./warnAboutDeprecatedCJSRequire.js")("createBrowserHistory"); | ||
module.exports = require("./index.js").createBrowserHistory; |
@@ -1,324 +0,3 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _warning = require('warning'); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var _invariant = require('invariant'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _LocationUtils = require('./LocationUtils'); | ||
var _PathUtils = require('./PathUtils'); | ||
var _createTransitionManager = require('./createTransitionManager'); | ||
var _createTransitionManager2 = _interopRequireDefault(_createTransitionManager); | ||
var _DOMUtils = require('./DOMUtils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var HashChangeEvent = 'hashchange'; | ||
var HashPathCoders = { | ||
hashbang: { | ||
encodePath: function encodePath(path) { | ||
return path.charAt(0) === '!' ? path : '!/' + (0, _PathUtils.stripLeadingSlash)(path); | ||
}, | ||
decodePath: function decodePath(path) { | ||
return path.charAt(0) === '!' ? path.substr(1) : path; | ||
} | ||
}, | ||
noslash: { | ||
encodePath: _PathUtils.stripLeadingSlash, | ||
decodePath: _PathUtils.addLeadingSlash | ||
}, | ||
slash: { | ||
encodePath: _PathUtils.addLeadingSlash, | ||
decodePath: _PathUtils.addLeadingSlash | ||
} | ||
}; | ||
var getHashPath = function getHashPath() { | ||
// We can't use window.location.hash here because it's not | ||
// consistent across browsers - Firefox will pre-decode it! | ||
var href = window.location.href; | ||
var hashIndex = href.indexOf('#'); | ||
return hashIndex === -1 ? '' : href.substring(hashIndex + 1); | ||
}; | ||
var pushHashPath = function pushHashPath(path) { | ||
return window.location.hash = path; | ||
}; | ||
var replaceHashPath = function replaceHashPath(path) { | ||
var hashIndex = window.location.href.indexOf('#'); | ||
window.location.replace(window.location.href.slice(0, hashIndex >= 0 ? hashIndex : 0) + '#' + path); | ||
}; | ||
var createHashHistory = function createHashHistory() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
(0, _invariant2.default)(_DOMUtils.canUseDOM, 'Hash history needs a DOM'); | ||
var globalHistory = window.history; | ||
var canGoWithoutReload = (0, _DOMUtils.supportsGoWithoutReloadUsingHash)(); | ||
var _props$getUserConfirm = props.getUserConfirmation, | ||
getUserConfirmation = _props$getUserConfirm === undefined ? _DOMUtils.getConfirmation : _props$getUserConfirm, | ||
_props$hashType = props.hashType, | ||
hashType = _props$hashType === undefined ? 'slash' : _props$hashType; | ||
var basename = props.basename ? (0, _PathUtils.stripTrailingSlash)((0, _PathUtils.addLeadingSlash)(props.basename)) : ''; | ||
var _HashPathCoders$hashT = HashPathCoders[hashType], | ||
encodePath = _HashPathCoders$hashT.encodePath, | ||
decodePath = _HashPathCoders$hashT.decodePath; | ||
var getDOMLocation = function getDOMLocation() { | ||
var path = decodePath(getHashPath()); | ||
(0, _warning2.default)(!basename || (0, _PathUtils.hasBasename)(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".'); | ||
if (basename) path = (0, _PathUtils.stripBasename)(path, basename); | ||
return (0, _LocationUtils.createLocation)(path); | ||
}; | ||
var transitionManager = (0, _createTransitionManager2.default)(); | ||
var setState = function setState(nextState) { | ||
_extends(history, nextState); | ||
history.length = globalHistory.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
}; | ||
var forceNextPop = false; | ||
var ignorePath = null; | ||
var handleHashChange = function handleHashChange() { | ||
var path = getHashPath(); | ||
var encodedPath = encodePath(path); | ||
if (path !== encodedPath) { | ||
// Ensure we always have a properly-encoded hash. | ||
replaceHashPath(encodedPath); | ||
} else { | ||
var location = getDOMLocation(); | ||
var prevLocation = history.location; | ||
if (!forceNextPop && (0, _LocationUtils.locationsAreEqual)(prevLocation, location)) return; // A hashchange doesn't always == location change. | ||
if (ignorePath === (0, _PathUtils.createPath)(location)) return; // Ignore this change; we already setState in push/replace. | ||
ignorePath = null; | ||
handlePop(location); | ||
} | ||
}; | ||
var handlePop = function handlePop(location) { | ||
if (forceNextPop) { | ||
forceNextPop = false; | ||
setState(); | ||
} else { | ||
var action = 'POP'; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ action: action, location: location }); | ||
} else { | ||
revertPop(location); | ||
} | ||
}); | ||
} | ||
}; | ||
var revertPop = function revertPop(fromLocation) { | ||
var toLocation = history.location; | ||
// TODO: We could probably make this more reliable by | ||
// keeping a list of paths we've seen in sessionStorage. | ||
// Instead, we just default to 0 for paths we don't know. | ||
var toIndex = allPaths.lastIndexOf((0, _PathUtils.createPath)(toLocation)); | ||
if (toIndex === -1) toIndex = 0; | ||
var fromIndex = allPaths.lastIndexOf((0, _PathUtils.createPath)(fromLocation)); | ||
if (fromIndex === -1) fromIndex = 0; | ||
var delta = toIndex - fromIndex; | ||
if (delta) { | ||
forceNextPop = true; | ||
go(delta); | ||
} | ||
}; | ||
// Ensure the hash is encoded properly before doing anything else. | ||
var path = getHashPath(); | ||
var encodedPath = encodePath(path); | ||
if (path !== encodedPath) replaceHashPath(encodedPath); | ||
var initialLocation = getDOMLocation(); | ||
var allPaths = [(0, _PathUtils.createPath)(initialLocation)]; | ||
// Public interface | ||
var createHref = function createHref(location) { | ||
return '#' + encodePath(basename + (0, _PathUtils.createPath)(location)); | ||
}; | ||
var push = function push(path, state) { | ||
(0, _warning2.default)(state === undefined, 'Hash history cannot push state; it is ignored'); | ||
var action = 'PUSH'; | ||
var location = (0, _LocationUtils.createLocation)(path, undefined, undefined, history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var path = (0, _PathUtils.createPath)(location); | ||
var encodedPath = encodePath(basename + path); | ||
var hashChanged = getHashPath() !== encodedPath; | ||
if (hashChanged) { | ||
// We cannot tell if a hashchange was caused by a PUSH, so we'd | ||
// rather setState here and ignore the hashchange. The caveat here | ||
// is that other hash histories in the page will consider it a POP. | ||
ignorePath = path; | ||
pushHashPath(encodedPath); | ||
var prevIndex = allPaths.lastIndexOf((0, _PathUtils.createPath)(history.location)); | ||
var nextPaths = allPaths.slice(0, prevIndex === -1 ? 0 : prevIndex + 1); | ||
nextPaths.push(path); | ||
allPaths = nextPaths; | ||
setState({ action: action, location: location }); | ||
} else { | ||
(0, _warning2.default)(false, 'Hash history cannot PUSH the same path; a new entry will not be added to the history stack'); | ||
setState(); | ||
} | ||
}); | ||
}; | ||
var replace = function replace(path, state) { | ||
(0, _warning2.default)(state === undefined, 'Hash history cannot replace state; it is ignored'); | ||
var action = 'REPLACE'; | ||
var location = (0, _LocationUtils.createLocation)(path, undefined, undefined, history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var path = (0, _PathUtils.createPath)(location); | ||
var encodedPath = encodePath(basename + path); | ||
var hashChanged = getHashPath() !== encodedPath; | ||
if (hashChanged) { | ||
// We cannot tell if a hashchange was caused by a REPLACE, so we'd | ||
// rather setState here and ignore the hashchange. The caveat here | ||
// is that other hash histories in the page will consider it a POP. | ||
ignorePath = path; | ||
replaceHashPath(encodedPath); | ||
} | ||
var prevIndex = allPaths.indexOf((0, _PathUtils.createPath)(history.location)); | ||
if (prevIndex !== -1) allPaths[prevIndex] = path; | ||
setState({ action: action, location: location }); | ||
}); | ||
}; | ||
var go = function go(n) { | ||
(0, _warning2.default)(canGoWithoutReload, 'Hash history go(n) causes a full page reload in this browser'); | ||
globalHistory.go(n); | ||
}; | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
var listenerCount = 0; | ||
var checkDOMListeners = function checkDOMListeners(delta) { | ||
listenerCount += delta; | ||
if (listenerCount === 1) { | ||
(0, _DOMUtils.addEventListener)(window, HashChangeEvent, handleHashChange); | ||
} else if (listenerCount === 0) { | ||
(0, _DOMUtils.removeEventListener)(window, HashChangeEvent, handleHashChange); | ||
} | ||
}; | ||
var isBlocked = false; | ||
var block = function block() { | ||
var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
var unblock = transitionManager.setPrompt(prompt); | ||
if (!isBlocked) { | ||
checkDOMListeners(1); | ||
isBlocked = true; | ||
} | ||
return function () { | ||
if (isBlocked) { | ||
isBlocked = false; | ||
checkDOMListeners(-1); | ||
} | ||
return unblock(); | ||
}; | ||
}; | ||
var listen = function listen(listener) { | ||
var unlisten = transitionManager.appendListener(listener); | ||
checkDOMListeners(1); | ||
return function () { | ||
checkDOMListeners(-1); | ||
unlisten(); | ||
}; | ||
}; | ||
var history = { | ||
length: globalHistory.length, | ||
action: 'POP', | ||
location: initialLocation, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
}; | ||
exports.default = createHashHistory; | ||
"use strict"; | ||
require("./warnAboutDeprecatedCJSRequire.js")("createHashHistory"); | ||
module.exports = require("./index.js").createHashHistory; |
@@ -1,170 +0,3 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
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; }; | ||
var _warning = require('warning'); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var _PathUtils = require('./PathUtils'); | ||
var _LocationUtils = require('./LocationUtils'); | ||
var _createTransitionManager = require('./createTransitionManager'); | ||
var _createTransitionManager2 = _interopRequireDefault(_createTransitionManager); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var clamp = function clamp(n, lowerBound, upperBound) { | ||
return Math.min(Math.max(n, lowerBound), upperBound); | ||
}; | ||
/** | ||
* Creates a history object that stores locations in memory. | ||
*/ | ||
var createMemoryHistory = function createMemoryHistory() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var getUserConfirmation = props.getUserConfirmation, | ||
_props$initialEntries = props.initialEntries, | ||
initialEntries = _props$initialEntries === undefined ? ['/'] : _props$initialEntries, | ||
_props$initialIndex = props.initialIndex, | ||
initialIndex = _props$initialIndex === undefined ? 0 : _props$initialIndex, | ||
_props$keyLength = props.keyLength, | ||
keyLength = _props$keyLength === undefined ? 6 : _props$keyLength; | ||
var transitionManager = (0, _createTransitionManager2.default)(); | ||
var setState = function setState(nextState) { | ||
_extends(history, nextState); | ||
history.length = history.entries.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
}; | ||
var createKey = function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength); | ||
}; | ||
var index = clamp(initialIndex, 0, initialEntries.length - 1); | ||
var entries = initialEntries.map(function (entry) { | ||
return typeof entry === 'string' ? (0, _LocationUtils.createLocation)(entry, undefined, createKey()) : (0, _LocationUtils.createLocation)(entry, undefined, entry.key || createKey()); | ||
}); | ||
// Public interface | ||
var createHref = _PathUtils.createPath; | ||
var push = function push(path, state) { | ||
(0, _warning2.default)(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to push when the 1st ' + 'argument is a location-like object that already has state; it is ignored'); | ||
var action = 'PUSH'; | ||
var location = (0, _LocationUtils.createLocation)(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var prevIndex = history.index; | ||
var nextIndex = prevIndex + 1; | ||
var nextEntries = history.entries.slice(0); | ||
if (nextEntries.length > nextIndex) { | ||
nextEntries.splice(nextIndex, nextEntries.length - nextIndex, location); | ||
} else { | ||
nextEntries.push(location); | ||
} | ||
setState({ | ||
action: action, | ||
location: location, | ||
index: nextIndex, | ||
entries: nextEntries | ||
}); | ||
}); | ||
}; | ||
var replace = function replace(path, state) { | ||
(0, _warning2.default)(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to replace when the 1st ' + 'argument is a location-like object that already has state; it is ignored'); | ||
var action = 'REPLACE'; | ||
var location = (0, _LocationUtils.createLocation)(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
history.entries[history.index] = location; | ||
setState({ action: action, location: location }); | ||
}); | ||
}; | ||
var go = function go(n) { | ||
var nextIndex = clamp(history.index + n, 0, history.entries.length - 1); | ||
var action = 'POP'; | ||
var location = history.entries[nextIndex]; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ | ||
action: action, | ||
location: location, | ||
index: nextIndex | ||
}); | ||
} else { | ||
// Mimic the behavior of DOM histories by | ||
// causing a render after a cancelled POP. | ||
setState(); | ||
} | ||
}); | ||
}; | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
var canGo = function canGo(n) { | ||
var nextIndex = history.index + n; | ||
return nextIndex >= 0 && nextIndex < history.entries.length; | ||
}; | ||
var block = function block() { | ||
var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
return transitionManager.setPrompt(prompt); | ||
}; | ||
var listen = function listen(listener) { | ||
return transitionManager.appendListener(listener); | ||
}; | ||
var history = { | ||
length: entries.length, | ||
action: 'POP', | ||
location: entries[index], | ||
index: index, | ||
entries: entries, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
canGo: canGo, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
}; | ||
exports.default = createMemoryHistory; | ||
"use strict"; | ||
require("./warnAboutDeprecatedCJSRequire.js")("createMemoryHistory"); | ||
module.exports = require("./index.js").createMemoryHistory; |
@@ -1,85 +0,3 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
var _warning = require('warning'); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var createTransitionManager = function createTransitionManager() { | ||
var prompt = null; | ||
var setPrompt = function setPrompt(nextPrompt) { | ||
(0, _warning2.default)(prompt == null, 'A history supports only one prompt at a time'); | ||
prompt = nextPrompt; | ||
return function () { | ||
if (prompt === nextPrompt) prompt = null; | ||
}; | ||
}; | ||
var confirmTransitionTo = function confirmTransitionTo(location, action, getUserConfirmation, callback) { | ||
// TODO: If another transition starts while we're still confirming | ||
// the previous one, we may end up in a weird state. Figure out the | ||
// best way to handle this. | ||
if (prompt != null) { | ||
var result = typeof prompt === 'function' ? prompt(location, action) : prompt; | ||
if (typeof result === 'string') { | ||
if (typeof getUserConfirmation === 'function') { | ||
getUserConfirmation(result, callback); | ||
} else { | ||
(0, _warning2.default)(false, 'A history needs a getUserConfirmation function in order to use a prompt message'); | ||
callback(true); | ||
} | ||
} else { | ||
// Return false from a transition hook to cancel the transition. | ||
callback(result !== false); | ||
} | ||
} else { | ||
callback(true); | ||
} | ||
}; | ||
var listeners = []; | ||
var appendListener = function appendListener(fn) { | ||
var isActive = true; | ||
var listener = function listener() { | ||
if (isActive) fn.apply(undefined, arguments); | ||
}; | ||
listeners.push(listener); | ||
return function () { | ||
isActive = false; | ||
listeners = listeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
}; | ||
}; | ||
var notifyListeners = function notifyListeners() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
listeners.forEach(function (listener) { | ||
return listener.apply(undefined, args); | ||
}); | ||
}; | ||
return { | ||
setPrompt: setPrompt, | ||
confirmTransitionTo: confirmTransitionTo, | ||
appendListener: appendListener, | ||
notifyListeners: notifyListeners | ||
}; | ||
}; | ||
exports.default = createTransitionManager; | ||
"use strict"; | ||
require("./warnAboutDeprecatedCJSRequire.js")("createTransitionManager"); | ||
module.exports = require("./index.js").createTransitionManager; |
@@ -1,55 +0,3 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
var canUseDOM = exports.canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
var addEventListener = exports.addEventListener = function addEventListener(node, event, listener) { | ||
return node.addEventListener ? node.addEventListener(event, listener, false) : 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); | ||
}; | ||
var getConfirmation = exports.getConfirmation = function getConfirmation(message, callback) { | ||
return callback(window.confirm(message)); | ||
}; // eslint-disable-line no-alert | ||
/** | ||
* Returns true if the HTML5 history API is supported. Taken from Modernizr. | ||
* | ||
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE | ||
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js | ||
* changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586 | ||
*/ | ||
var supportsHistory = exports.supportsHistory = function supportsHistory() { | ||
var ua = window.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; | ||
return window.history && 'pushState' in window.history; | ||
}; | ||
/** | ||
* Returns true if browser fires popstate on hash change. | ||
* IE10 and IE11 do not. | ||
*/ | ||
var supportsPopStateOnHashChange = exports.supportsPopStateOnHashChange = function supportsPopStateOnHashChange() { | ||
return window.navigator.userAgent.indexOf('Trident') === -1; | ||
}; | ||
/** | ||
* Returns false if using go(n) with hash history causes a full page reload. | ||
*/ | ||
var supportsGoWithoutReloadUsingHash = exports.supportsGoWithoutReloadUsingHash = function supportsGoWithoutReloadUsingHash() { | ||
return window.navigator.userAgent.indexOf('Firefox') === -1; | ||
}; | ||
/** | ||
* Returns true if a given popstate event is an extraneous WebKit event. | ||
* Accounts for the fact that Chrome on iOS fires real popstate events | ||
* containing undefined state when pressing the back button. | ||
*/ | ||
var isExtraneousPopstateEvent = exports.isExtraneousPopstateEvent = function isExtraneousPopstateEvent(event) { | ||
return event.state === undefined && navigator.userAgent.indexOf('CriOS') === -1; | ||
}; | ||
"use strict"; | ||
require("./warnAboutDeprecatedCJSRequire.js")("DOMUtils"); | ||
module.exports = require("./index.js").DOMUtils; |
@@ -1,290 +0,7 @@ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
"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; }; | ||
import warnAboutDeprecatedESMImport from "./warnAboutDeprecatedESMImport.js"; | ||
warnAboutDeprecatedESMImport("createBrowserHistory"); | ||
import warning from 'warning'; | ||
import invariant from 'invariant'; | ||
import { createLocation } from './LocationUtils'; | ||
import { addLeadingSlash, stripTrailingSlash, hasBasename, stripBasename, createPath } from './PathUtils'; | ||
import createTransitionManager from './createTransitionManager'; | ||
import { canUseDOM, addEventListener, removeEventListener, getConfirmation, supportsHistory, supportsPopStateOnHashChange, isExtraneousPopstateEvent } from './DOMUtils'; | ||
var PopStateEvent = 'popstate'; | ||
var HashChangeEvent = 'hashchange'; | ||
var getHistoryState = function getHistoryState() { | ||
try { | ||
return window.history.state || {}; | ||
} catch (e) { | ||
// IE 11 sometimes throws when accessing window.history.state | ||
// See https://github.com/ReactTraining/history/pull/289 | ||
return {}; | ||
} | ||
}; | ||
/** | ||
* Creates a history object that uses the HTML5 history API including | ||
* pushState, replaceState, and the popstate event. | ||
*/ | ||
var createBrowserHistory = function createBrowserHistory() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
invariant(canUseDOM, 'Browser history needs a DOM'); | ||
var globalHistory = window.history; | ||
var canUseHistory = supportsHistory(); | ||
var needsHashChangeListener = !supportsPopStateOnHashChange(); | ||
var _props$forceRefresh = props.forceRefresh, | ||
forceRefresh = _props$forceRefresh === undefined ? false : _props$forceRefresh, | ||
_props$getUserConfirm = props.getUserConfirmation, | ||
getUserConfirmation = _props$getUserConfirm === undefined ? getConfirmation : _props$getUserConfirm, | ||
_props$keyLength = props.keyLength, | ||
keyLength = _props$keyLength === undefined ? 6 : _props$keyLength; | ||
var basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : ''; | ||
var getDOMLocation = function getDOMLocation(historyState) { | ||
var _ref = historyState || {}, | ||
key = _ref.key, | ||
state = _ref.state; | ||
var _window$location = window.location, | ||
pathname = _window$location.pathname, | ||
search = _window$location.search, | ||
hash = _window$location.hash; | ||
var path = pathname + search + hash; | ||
warning(!basename || hasBasename(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".'); | ||
if (basename) path = stripBasename(path, basename); | ||
return createLocation(path, state, key); | ||
}; | ||
var createKey = function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength); | ||
}; | ||
var transitionManager = createTransitionManager(); | ||
var setState = function setState(nextState) { | ||
_extends(history, nextState); | ||
history.length = globalHistory.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
}; | ||
var handlePopState = function handlePopState(event) { | ||
// Ignore extraneous popstate events in WebKit. | ||
if (isExtraneousPopstateEvent(event)) return; | ||
handlePop(getDOMLocation(event.state)); | ||
}; | ||
var handleHashChange = function handleHashChange() { | ||
handlePop(getDOMLocation(getHistoryState())); | ||
}; | ||
var forceNextPop = false; | ||
var handlePop = function handlePop(location) { | ||
if (forceNextPop) { | ||
forceNextPop = false; | ||
setState(); | ||
} else { | ||
var action = 'POP'; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ action: action, location: location }); | ||
} else { | ||
revertPop(location); | ||
} | ||
}); | ||
} | ||
}; | ||
var revertPop = function revertPop(fromLocation) { | ||
var toLocation = history.location; | ||
// TODO: We could probably make this more reliable by | ||
// keeping a list of keys we've seen in sessionStorage. | ||
// Instead, we just default to 0 for keys we don't know. | ||
var toIndex = allKeys.indexOf(toLocation.key); | ||
if (toIndex === -1) toIndex = 0; | ||
var fromIndex = allKeys.indexOf(fromLocation.key); | ||
if (fromIndex === -1) fromIndex = 0; | ||
var delta = toIndex - fromIndex; | ||
if (delta) { | ||
forceNextPop = true; | ||
go(delta); | ||
} | ||
}; | ||
var initialLocation = getDOMLocation(getHistoryState()); | ||
var allKeys = [initialLocation.key]; | ||
// Public interface | ||
var createHref = function createHref(location) { | ||
return basename + createPath(location); | ||
}; | ||
var push = function push(path, state) { | ||
warning(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to push when the 1st ' + 'argument is a location-like object that already has state; it is ignored'); | ||
var action = 'PUSH'; | ||
var location = createLocation(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var href = createHref(location); | ||
var key = location.key, | ||
state = location.state; | ||
if (canUseHistory) { | ||
globalHistory.pushState({ key: key, state: state }, null, href); | ||
if (forceRefresh) { | ||
window.location.href = href; | ||
} else { | ||
var prevIndex = allKeys.indexOf(history.location.key); | ||
var nextKeys = allKeys.slice(0, prevIndex === -1 ? 0 : prevIndex + 1); | ||
nextKeys.push(location.key); | ||
allKeys = nextKeys; | ||
setState({ action: action, location: location }); | ||
} | ||
} else { | ||
warning(state === undefined, 'Browser history cannot push state in browsers that do not support HTML5 history'); | ||
window.location.href = href; | ||
} | ||
}); | ||
}; | ||
var replace = function replace(path, state) { | ||
warning(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to replace when the 1st ' + 'argument is a location-like object that already has state; it is ignored'); | ||
var action = 'REPLACE'; | ||
var location = createLocation(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var href = createHref(location); | ||
var key = location.key, | ||
state = location.state; | ||
if (canUseHistory) { | ||
globalHistory.replaceState({ key: key, state: state }, null, href); | ||
if (forceRefresh) { | ||
window.location.replace(href); | ||
} else { | ||
var prevIndex = allKeys.indexOf(history.location.key); | ||
if (prevIndex !== -1) allKeys[prevIndex] = location.key; | ||
setState({ action: action, location: location }); | ||
} | ||
} else { | ||
warning(state === undefined, 'Browser history cannot replace state in browsers that do not support HTML5 history'); | ||
window.location.replace(href); | ||
} | ||
}); | ||
}; | ||
var go = function go(n) { | ||
globalHistory.go(n); | ||
}; | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
var listenerCount = 0; | ||
var checkDOMListeners = function checkDOMListeners(delta) { | ||
listenerCount += delta; | ||
if (listenerCount === 1) { | ||
addEventListener(window, PopStateEvent, handlePopState); | ||
if (needsHashChangeListener) addEventListener(window, HashChangeEvent, handleHashChange); | ||
} else if (listenerCount === 0) { | ||
removeEventListener(window, PopStateEvent, handlePopState); | ||
if (needsHashChangeListener) removeEventListener(window, HashChangeEvent, handleHashChange); | ||
} | ||
}; | ||
var isBlocked = false; | ||
var block = function block() { | ||
var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
var unblock = transitionManager.setPrompt(prompt); | ||
if (!isBlocked) { | ||
checkDOMListeners(1); | ||
isBlocked = true; | ||
} | ||
return function () { | ||
if (isBlocked) { | ||
isBlocked = false; | ||
checkDOMListeners(-1); | ||
} | ||
return unblock(); | ||
}; | ||
}; | ||
var listen = function listen(listener) { | ||
var unlisten = transitionManager.appendListener(listener); | ||
checkDOMListeners(1); | ||
return function () { | ||
checkDOMListeners(-1); | ||
unlisten(); | ||
}; | ||
}; | ||
var history = { | ||
length: globalHistory.length, | ||
action: 'POP', | ||
location: initialLocation, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
}; | ||
export default createBrowserHistory; | ||
import { createBrowserHistory } from "../esm/history.js"; | ||
export default createBrowserHistory; |
@@ -1,307 +0,7 @@ | ||
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; }; | ||
"use strict"; | ||
import warning from 'warning'; | ||
import invariant from 'invariant'; | ||
import { createLocation, locationsAreEqual } from './LocationUtils'; | ||
import { addLeadingSlash, stripLeadingSlash, stripTrailingSlash, hasBasename, stripBasename, createPath } from './PathUtils'; | ||
import createTransitionManager from './createTransitionManager'; | ||
import { canUseDOM, addEventListener, removeEventListener, getConfirmation, supportsGoWithoutReloadUsingHash } from './DOMUtils'; | ||
import warnAboutDeprecatedESMImport from "./warnAboutDeprecatedESMImport.js"; | ||
warnAboutDeprecatedESMImport("createHashHistory"); | ||
var HashChangeEvent = 'hashchange'; | ||
var HashPathCoders = { | ||
hashbang: { | ||
encodePath: function encodePath(path) { | ||
return path.charAt(0) === '!' ? path : '!/' + stripLeadingSlash(path); | ||
}, | ||
decodePath: function decodePath(path) { | ||
return path.charAt(0) === '!' ? path.substr(1) : path; | ||
} | ||
}, | ||
noslash: { | ||
encodePath: stripLeadingSlash, | ||
decodePath: addLeadingSlash | ||
}, | ||
slash: { | ||
encodePath: addLeadingSlash, | ||
decodePath: addLeadingSlash | ||
} | ||
}; | ||
var getHashPath = function getHashPath() { | ||
// We can't use window.location.hash here because it's not | ||
// consistent across browsers - Firefox will pre-decode it! | ||
var href = window.location.href; | ||
var hashIndex = href.indexOf('#'); | ||
return hashIndex === -1 ? '' : href.substring(hashIndex + 1); | ||
}; | ||
var pushHashPath = function pushHashPath(path) { | ||
return window.location.hash = path; | ||
}; | ||
var replaceHashPath = function replaceHashPath(path) { | ||
var hashIndex = window.location.href.indexOf('#'); | ||
window.location.replace(window.location.href.slice(0, hashIndex >= 0 ? hashIndex : 0) + '#' + path); | ||
}; | ||
var createHashHistory = function createHashHistory() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
invariant(canUseDOM, 'Hash history needs a DOM'); | ||
var globalHistory = window.history; | ||
var canGoWithoutReload = supportsGoWithoutReloadUsingHash(); | ||
var _props$getUserConfirm = props.getUserConfirmation, | ||
getUserConfirmation = _props$getUserConfirm === undefined ? getConfirmation : _props$getUserConfirm, | ||
_props$hashType = props.hashType, | ||
hashType = _props$hashType === undefined ? 'slash' : _props$hashType; | ||
var basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : ''; | ||
var _HashPathCoders$hashT = HashPathCoders[hashType], | ||
encodePath = _HashPathCoders$hashT.encodePath, | ||
decodePath = _HashPathCoders$hashT.decodePath; | ||
var getDOMLocation = function getDOMLocation() { | ||
var path = decodePath(getHashPath()); | ||
warning(!basename || hasBasename(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".'); | ||
if (basename) path = stripBasename(path, basename); | ||
return createLocation(path); | ||
}; | ||
var transitionManager = createTransitionManager(); | ||
var setState = function setState(nextState) { | ||
_extends(history, nextState); | ||
history.length = globalHistory.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
}; | ||
var forceNextPop = false; | ||
var ignorePath = null; | ||
var handleHashChange = function handleHashChange() { | ||
var path = getHashPath(); | ||
var encodedPath = encodePath(path); | ||
if (path !== encodedPath) { | ||
// Ensure we always have a properly-encoded hash. | ||
replaceHashPath(encodedPath); | ||
} else { | ||
var location = getDOMLocation(); | ||
var prevLocation = history.location; | ||
if (!forceNextPop && locationsAreEqual(prevLocation, location)) return; // A hashchange doesn't always == location change. | ||
if (ignorePath === createPath(location)) return; // Ignore this change; we already setState in push/replace. | ||
ignorePath = null; | ||
handlePop(location); | ||
} | ||
}; | ||
var handlePop = function handlePop(location) { | ||
if (forceNextPop) { | ||
forceNextPop = false; | ||
setState(); | ||
} else { | ||
var action = 'POP'; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ action: action, location: location }); | ||
} else { | ||
revertPop(location); | ||
} | ||
}); | ||
} | ||
}; | ||
var revertPop = function revertPop(fromLocation) { | ||
var toLocation = history.location; | ||
// TODO: We could probably make this more reliable by | ||
// keeping a list of paths we've seen in sessionStorage. | ||
// Instead, we just default to 0 for paths we don't know. | ||
var toIndex = allPaths.lastIndexOf(createPath(toLocation)); | ||
if (toIndex === -1) toIndex = 0; | ||
var fromIndex = allPaths.lastIndexOf(createPath(fromLocation)); | ||
if (fromIndex === -1) fromIndex = 0; | ||
var delta = toIndex - fromIndex; | ||
if (delta) { | ||
forceNextPop = true; | ||
go(delta); | ||
} | ||
}; | ||
// Ensure the hash is encoded properly before doing anything else. | ||
var path = getHashPath(); | ||
var encodedPath = encodePath(path); | ||
if (path !== encodedPath) replaceHashPath(encodedPath); | ||
var initialLocation = getDOMLocation(); | ||
var allPaths = [createPath(initialLocation)]; | ||
// Public interface | ||
var createHref = function createHref(location) { | ||
return '#' + encodePath(basename + createPath(location)); | ||
}; | ||
var push = function push(path, state) { | ||
warning(state === undefined, 'Hash history cannot push state; it is ignored'); | ||
var action = 'PUSH'; | ||
var location = createLocation(path, undefined, undefined, history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var path = createPath(location); | ||
var encodedPath = encodePath(basename + path); | ||
var hashChanged = getHashPath() !== encodedPath; | ||
if (hashChanged) { | ||
// We cannot tell if a hashchange was caused by a PUSH, so we'd | ||
// rather setState here and ignore the hashchange. The caveat here | ||
// is that other hash histories in the page will consider it a POP. | ||
ignorePath = path; | ||
pushHashPath(encodedPath); | ||
var prevIndex = allPaths.lastIndexOf(createPath(history.location)); | ||
var nextPaths = allPaths.slice(0, prevIndex === -1 ? 0 : prevIndex + 1); | ||
nextPaths.push(path); | ||
allPaths = nextPaths; | ||
setState({ action: action, location: location }); | ||
} else { | ||
warning(false, 'Hash history cannot PUSH the same path; a new entry will not be added to the history stack'); | ||
setState(); | ||
} | ||
}); | ||
}; | ||
var replace = function replace(path, state) { | ||
warning(state === undefined, 'Hash history cannot replace state; it is ignored'); | ||
var action = 'REPLACE'; | ||
var location = createLocation(path, undefined, undefined, history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var path = createPath(location); | ||
var encodedPath = encodePath(basename + path); | ||
var hashChanged = getHashPath() !== encodedPath; | ||
if (hashChanged) { | ||
// We cannot tell if a hashchange was caused by a REPLACE, so we'd | ||
// rather setState here and ignore the hashchange. The caveat here | ||
// is that other hash histories in the page will consider it a POP. | ||
ignorePath = path; | ||
replaceHashPath(encodedPath); | ||
} | ||
var prevIndex = allPaths.indexOf(createPath(history.location)); | ||
if (prevIndex !== -1) allPaths[prevIndex] = path; | ||
setState({ action: action, location: location }); | ||
}); | ||
}; | ||
var go = function go(n) { | ||
warning(canGoWithoutReload, 'Hash history go(n) causes a full page reload in this browser'); | ||
globalHistory.go(n); | ||
}; | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
var listenerCount = 0; | ||
var checkDOMListeners = function checkDOMListeners(delta) { | ||
listenerCount += delta; | ||
if (listenerCount === 1) { | ||
addEventListener(window, HashChangeEvent, handleHashChange); | ||
} else if (listenerCount === 0) { | ||
removeEventListener(window, HashChangeEvent, handleHashChange); | ||
} | ||
}; | ||
var isBlocked = false; | ||
var block = function block() { | ||
var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
var unblock = transitionManager.setPrompt(prompt); | ||
if (!isBlocked) { | ||
checkDOMListeners(1); | ||
isBlocked = true; | ||
} | ||
return function () { | ||
if (isBlocked) { | ||
isBlocked = false; | ||
checkDOMListeners(-1); | ||
} | ||
return unblock(); | ||
}; | ||
}; | ||
var listen = function listen(listener) { | ||
var unlisten = transitionManager.appendListener(listener); | ||
checkDOMListeners(1); | ||
return function () { | ||
checkDOMListeners(-1); | ||
unlisten(); | ||
}; | ||
}; | ||
var history = { | ||
length: globalHistory.length, | ||
action: 'POP', | ||
location: initialLocation, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
}; | ||
export default createHashHistory; | ||
import { createHashHistory } from "../esm/history.js"; | ||
export default createHashHistory; |
@@ -1,157 +0,7 @@ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
"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; }; | ||
import warnAboutDeprecatedESMImport from "./warnAboutDeprecatedESMImport.js"; | ||
warnAboutDeprecatedESMImport("createMemoryHistory"); | ||
import warning from 'warning'; | ||
import { createPath } from './PathUtils'; | ||
import { createLocation } from './LocationUtils'; | ||
import createTransitionManager from './createTransitionManager'; | ||
var clamp = function clamp(n, lowerBound, upperBound) { | ||
return Math.min(Math.max(n, lowerBound), upperBound); | ||
}; | ||
/** | ||
* Creates a history object that stores locations in memory. | ||
*/ | ||
var createMemoryHistory = function createMemoryHistory() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var getUserConfirmation = props.getUserConfirmation, | ||
_props$initialEntries = props.initialEntries, | ||
initialEntries = _props$initialEntries === undefined ? ['/'] : _props$initialEntries, | ||
_props$initialIndex = props.initialIndex, | ||
initialIndex = _props$initialIndex === undefined ? 0 : _props$initialIndex, | ||
_props$keyLength = props.keyLength, | ||
keyLength = _props$keyLength === undefined ? 6 : _props$keyLength; | ||
var transitionManager = createTransitionManager(); | ||
var setState = function setState(nextState) { | ||
_extends(history, nextState); | ||
history.length = history.entries.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
}; | ||
var createKey = function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength); | ||
}; | ||
var index = clamp(initialIndex, 0, initialEntries.length - 1); | ||
var entries = initialEntries.map(function (entry) { | ||
return typeof entry === 'string' ? createLocation(entry, undefined, createKey()) : createLocation(entry, undefined, entry.key || createKey()); | ||
}); | ||
// Public interface | ||
var createHref = createPath; | ||
var push = function push(path, state) { | ||
warning(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to push when the 1st ' + 'argument is a location-like object that already has state; it is ignored'); | ||
var action = 'PUSH'; | ||
var location = createLocation(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var prevIndex = history.index; | ||
var nextIndex = prevIndex + 1; | ||
var nextEntries = history.entries.slice(0); | ||
if (nextEntries.length > nextIndex) { | ||
nextEntries.splice(nextIndex, nextEntries.length - nextIndex, location); | ||
} else { | ||
nextEntries.push(location); | ||
} | ||
setState({ | ||
action: action, | ||
location: location, | ||
index: nextIndex, | ||
entries: nextEntries | ||
}); | ||
}); | ||
}; | ||
var replace = function replace(path, state) { | ||
warning(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to replace when the 1st ' + 'argument is a location-like object that already has state; it is ignored'); | ||
var action = 'REPLACE'; | ||
var location = createLocation(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
history.entries[history.index] = location; | ||
setState({ action: action, location: location }); | ||
}); | ||
}; | ||
var go = function go(n) { | ||
var nextIndex = clamp(history.index + n, 0, history.entries.length - 1); | ||
var action = 'POP'; | ||
var location = history.entries[nextIndex]; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ | ||
action: action, | ||
location: location, | ||
index: nextIndex | ||
}); | ||
} else { | ||
// Mimic the behavior of DOM histories by | ||
// causing a render after a cancelled POP. | ||
setState(); | ||
} | ||
}); | ||
}; | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
var canGo = function canGo(n) { | ||
var nextIndex = history.index + n; | ||
return nextIndex >= 0 && nextIndex < history.entries.length; | ||
}; | ||
var block = function block() { | ||
var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
return transitionManager.setPrompt(prompt); | ||
}; | ||
var listen = function listen(listener) { | ||
return transitionManager.appendListener(listener); | ||
}; | ||
var history = { | ||
length: entries.length, | ||
action: 'POP', | ||
location: entries[index], | ||
index: index, | ||
entries: entries, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
canGo: canGo, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
}; | ||
export default createMemoryHistory; | ||
import { createMemoryHistory } from "../esm/history.js"; | ||
export default createMemoryHistory; |
@@ -1,77 +0,7 @@ | ||
import warning from 'warning'; | ||
"use strict"; | ||
var createTransitionManager = function createTransitionManager() { | ||
var prompt = null; | ||
import warnAboutDeprecatedESMImport from "./warnAboutDeprecatedESMImport.js"; | ||
warnAboutDeprecatedESMImport("createTransitionManager"); | ||
var setPrompt = function setPrompt(nextPrompt) { | ||
warning(prompt == null, 'A history supports only one prompt at a time'); | ||
prompt = nextPrompt; | ||
return function () { | ||
if (prompt === nextPrompt) prompt = null; | ||
}; | ||
}; | ||
var confirmTransitionTo = function confirmTransitionTo(location, action, getUserConfirmation, callback) { | ||
// TODO: If another transition starts while we're still confirming | ||
// the previous one, we may end up in a weird state. Figure out the | ||
// best way to handle this. | ||
if (prompt != null) { | ||
var result = typeof prompt === 'function' ? prompt(location, action) : prompt; | ||
if (typeof result === 'string') { | ||
if (typeof getUserConfirmation === 'function') { | ||
getUserConfirmation(result, callback); | ||
} else { | ||
warning(false, 'A history needs a getUserConfirmation function in order to use a prompt message'); | ||
callback(true); | ||
} | ||
} else { | ||
// Return false from a transition hook to cancel the transition. | ||
callback(result !== false); | ||
} | ||
} else { | ||
callback(true); | ||
} | ||
}; | ||
var listeners = []; | ||
var appendListener = function appendListener(fn) { | ||
var isActive = true; | ||
var listener = function listener() { | ||
if (isActive) fn.apply(undefined, arguments); | ||
}; | ||
listeners.push(listener); | ||
return function () { | ||
isActive = false; | ||
listeners = listeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
}; | ||
}; | ||
var notifyListeners = function notifyListeners() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
listeners.forEach(function (listener) { | ||
return listener.apply(undefined, args); | ||
}); | ||
}; | ||
return { | ||
setPrompt: setPrompt, | ||
confirmTransitionTo: confirmTransitionTo, | ||
appendListener: appendListener, | ||
notifyListeners: notifyListeners | ||
}; | ||
}; | ||
export default createTransitionManager; | ||
import { createTransitionManager } from "../esm/history.js"; | ||
export default createTransitionManager; |
@@ -1,52 +0,7 @@ | ||
export var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
"use strict"; | ||
export var addEventListener = function addEventListener(node, event, listener) { | ||
return node.addEventListener ? node.addEventListener(event, listener, false) : node.attachEvent('on' + event, listener); | ||
}; | ||
import warnAboutDeprecatedESMImport from "./warnAboutDeprecatedESMImport.js"; | ||
warnAboutDeprecatedESMImport("DOMUtils"); | ||
export var removeEventListener = function removeEventListener(node, event, listener) { | ||
return node.removeEventListener ? node.removeEventListener(event, listener, false) : node.detachEvent('on' + event, listener); | ||
}; | ||
export var getConfirmation = function getConfirmation(message, callback) { | ||
return callback(window.confirm(message)); | ||
}; // eslint-disable-line no-alert | ||
/** | ||
* Returns true if the HTML5 history API is supported. Taken from Modernizr. | ||
* | ||
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE | ||
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js | ||
* changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586 | ||
*/ | ||
export var supportsHistory = function supportsHistory() { | ||
var ua = window.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; | ||
return window.history && 'pushState' in window.history; | ||
}; | ||
/** | ||
* Returns true if browser fires popstate on hash change. | ||
* IE10 and IE11 do not. | ||
*/ | ||
export var supportsPopStateOnHashChange = function supportsPopStateOnHashChange() { | ||
return window.navigator.userAgent.indexOf('Trident') === -1; | ||
}; | ||
/** | ||
* Returns false if using go(n) with hash history causes a full page reload. | ||
*/ | ||
export var supportsGoWithoutReloadUsingHash = function supportsGoWithoutReloadUsingHash() { | ||
return window.navigator.userAgent.indexOf('Firefox') === -1; | ||
}; | ||
/** | ||
* Returns true if a given popstate event is an extraneous WebKit event. | ||
* Accounts for the fact that Chrome on iOS fires real popstate events | ||
* containing undefined state when pressing the back button. | ||
*/ | ||
export var isExtraneousPopstateEvent = function isExtraneousPopstateEvent(event) { | ||
return event.state === undefined && navigator.userAgent.indexOf('CriOS') === -1; | ||
}; | ||
import { DOMUtils } from "../esm/history.js"; | ||
export default DOMUtils; |
@@ -1,65 +0,7 @@ | ||
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; }; | ||
"use strict"; | ||
import resolvePathname from 'resolve-pathname'; | ||
import valueEqual from 'value-equal'; | ||
import { parsePath } from './PathUtils'; | ||
import warnAboutDeprecatedESMImport from "./warnAboutDeprecatedESMImport.js"; | ||
warnAboutDeprecatedESMImport("LocationUtils"); | ||
export var createLocation = function createLocation(path, state, key, currentLocation) { | ||
var location = void 0; | ||
if (typeof path === 'string') { | ||
// Two-arg form: push(path, state) | ||
location = parsePath(path); | ||
location.state = state; | ||
} else { | ||
// One-arg form: push(location) | ||
location = _extends({}, path); | ||
if (location.pathname === undefined) location.pathname = ''; | ||
if (location.search) { | ||
if (location.search.charAt(0) !== '?') location.search = '?' + location.search; | ||
} else { | ||
location.search = ''; | ||
} | ||
if (location.hash) { | ||
if (location.hash.charAt(0) !== '#') location.hash = '#' + location.hash; | ||
} else { | ||
location.hash = ''; | ||
} | ||
if (state !== undefined && location.state === undefined) location.state = state; | ||
} | ||
try { | ||
location.pathname = decodeURI(location.pathname); | ||
} catch (e) { | ||
if (e instanceof URIError) { | ||
throw new URIError('Pathname "' + location.pathname + '" could not be decoded. ' + 'This is likely caused by an invalid percent-encoding.'); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
if (key) location.key = key; | ||
if (currentLocation) { | ||
// Resolve incomplete/relative pathname relative to current location. | ||
if (!location.pathname) { | ||
location.pathname = currentLocation.pathname; | ||
} else if (location.pathname.charAt(0) !== '/') { | ||
location.pathname = resolvePathname(location.pathname, currentLocation.pathname); | ||
} | ||
} else { | ||
// When there is no prior location and pathname is empty, set it to / | ||
if (!location.pathname) { | ||
location.pathname = '/'; | ||
} | ||
} | ||
return location; | ||
}; | ||
export var locationsAreEqual = function locationsAreEqual(a, b) { | ||
return a.pathname === b.pathname && a.search === b.search && a.hash === b.hash && a.key === b.key && valueEqual(a.state, b.state); | ||
}; | ||
import { LocationUtils } from "../esm/history.js"; | ||
export default LocationUtils; |
@@ -1,58 +0,7 @@ | ||
export var addLeadingSlash = function addLeadingSlash(path) { | ||
return path.charAt(0) === '/' ? path : '/' + path; | ||
}; | ||
"use strict"; | ||
export var stripLeadingSlash = function stripLeadingSlash(path) { | ||
return path.charAt(0) === '/' ? path.substr(1) : path; | ||
}; | ||
import warnAboutDeprecatedESMImport from "./warnAboutDeprecatedESMImport.js"; | ||
warnAboutDeprecatedESMImport("PathUtils"); | ||
export var hasBasename = function hasBasename(path, prefix) { | ||
return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path); | ||
}; | ||
export var stripBasename = function stripBasename(path, prefix) { | ||
return hasBasename(path, prefix) ? path.substr(prefix.length) : path; | ||
}; | ||
export var stripTrailingSlash = function stripTrailingSlash(path) { | ||
return path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path; | ||
}; | ||
export var parsePath = function parsePath(path) { | ||
var pathname = path || '/'; | ||
var search = ''; | ||
var hash = ''; | ||
var hashIndex = pathname.indexOf('#'); | ||
if (hashIndex !== -1) { | ||
hash = pathname.substr(hashIndex); | ||
pathname = pathname.substr(0, hashIndex); | ||
} | ||
var searchIndex = pathname.indexOf('?'); | ||
if (searchIndex !== -1) { | ||
search = pathname.substr(searchIndex); | ||
pathname = pathname.substr(0, searchIndex); | ||
} | ||
return { | ||
pathname: pathname, | ||
search: search === '?' ? '' : search, | ||
hash: hash === '#' ? '' : hash | ||
}; | ||
}; | ||
export var createPath = function createPath(location) { | ||
var pathname = location.pathname, | ||
search = location.search, | ||
hash = location.hash; | ||
var path = pathname || '/'; | ||
if (search && search !== '?') path += search.charAt(0) === '?' ? search : '?' + search; | ||
if (hash && hash !== '#') path += hash.charAt(0) === '#' ? hash : '#' + hash; | ||
return path; | ||
}; | ||
import { PathUtils } from "../esm/history.js"; | ||
export default PathUtils; |
57
index.js
@@ -1,52 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.createPath = exports.parsePath = exports.locationsAreEqual = exports.createLocation = exports.createMemoryHistory = exports.createHashHistory = exports.createBrowserHistory = undefined; | ||
var _LocationUtils = require('./LocationUtils'); | ||
Object.defineProperty(exports, 'createLocation', { | ||
enumerable: true, | ||
get: function get() { | ||
return _LocationUtils.createLocation; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'locationsAreEqual', { | ||
enumerable: true, | ||
get: function get() { | ||
return _LocationUtils.locationsAreEqual; | ||
} | ||
}); | ||
var _PathUtils = require('./PathUtils'); | ||
Object.defineProperty(exports, 'parsePath', { | ||
enumerable: true, | ||
get: function get() { | ||
return _PathUtils.parsePath; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'createPath', { | ||
enumerable: true, | ||
get: function get() { | ||
return _PathUtils.createPath; | ||
} | ||
}); | ||
var _createBrowserHistory2 = require('./createBrowserHistory'); | ||
var _createBrowserHistory3 = _interopRequireDefault(_createBrowserHistory2); | ||
var _createHashHistory2 = require('./createHashHistory'); | ||
var _createHashHistory3 = _interopRequireDefault(_createHashHistory2); | ||
var _createMemoryHistory2 = require('./createMemoryHistory'); | ||
var _createMemoryHistory3 = _interopRequireDefault(_createMemoryHistory2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.createBrowserHistory = _createBrowserHistory3.default; | ||
exports.createHashHistory = _createHashHistory3.default; | ||
exports.createMemoryHistory = _createMemoryHistory3.default; | ||
if (process.env.NODE_ENV === "production") { | ||
module.exports = require("./cjs/history.min.js"); | ||
} else { | ||
module.exports = require("./cjs/history.js"); | ||
} |
@@ -1,78 +0,3 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
exports.locationsAreEqual = exports.createLocation = undefined; | ||
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; }; | ||
var _resolvePathname = require('resolve-pathname'); | ||
var _resolvePathname2 = _interopRequireDefault(_resolvePathname); | ||
var _valueEqual = require('value-equal'); | ||
var _valueEqual2 = _interopRequireDefault(_valueEqual); | ||
var _PathUtils = require('./PathUtils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var createLocation = exports.createLocation = function createLocation(path, state, key, currentLocation) { | ||
var location = void 0; | ||
if (typeof path === 'string') { | ||
// Two-arg form: push(path, state) | ||
location = (0, _PathUtils.parsePath)(path); | ||
location.state = state; | ||
} else { | ||
// One-arg form: push(location) | ||
location = _extends({}, path); | ||
if (location.pathname === undefined) location.pathname = ''; | ||
if (location.search) { | ||
if (location.search.charAt(0) !== '?') location.search = '?' + location.search; | ||
} else { | ||
location.search = ''; | ||
} | ||
if (location.hash) { | ||
if (location.hash.charAt(0) !== '#') location.hash = '#' + location.hash; | ||
} else { | ||
location.hash = ''; | ||
} | ||
if (state !== undefined && location.state === undefined) location.state = state; | ||
} | ||
try { | ||
location.pathname = decodeURI(location.pathname); | ||
} catch (e) { | ||
if (e instanceof URIError) { | ||
throw new URIError('Pathname "' + location.pathname + '" could not be decoded. ' + 'This is likely caused by an invalid percent-encoding.'); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
if (key) location.key = key; | ||
if (currentLocation) { | ||
// Resolve incomplete/relative pathname relative to current location. | ||
if (!location.pathname) { | ||
location.pathname = currentLocation.pathname; | ||
} else if (location.pathname.charAt(0) !== '/') { | ||
location.pathname = (0, _resolvePathname2.default)(location.pathname, currentLocation.pathname); | ||
} | ||
} else { | ||
// When there is no prior location and pathname is empty, set it to / | ||
if (!location.pathname) { | ||
location.pathname = '/'; | ||
} | ||
} | ||
return location; | ||
}; | ||
var locationsAreEqual = exports.locationsAreEqual = function locationsAreEqual(a, b) { | ||
return a.pathname === b.pathname && a.search === b.search && a.hash === b.hash && a.key === b.key && (0, _valueEqual2.default)(a.state, b.state); | ||
}; | ||
"use strict"; | ||
require("./warnAboutDeprecatedCJSRequire.js")("LocationUtils"); | ||
module.exports = require("./index.js").LocationUtils; |
{ | ||
"name": "history", | ||
"version": "4.7.2", | ||
"version": "4.8.0-beta.0", | ||
"description": "Manage session history with JavaScript", | ||
@@ -8,2 +8,4 @@ "repository": "ReactTraining/history", | ||
"author": "Michael Jackson", | ||
"main": "index.js", | ||
"module": "esm/history.js", | ||
"files": [ | ||
@@ -14,2 +16,3 @@ "DOMUtils.js", | ||
"PathUtils.js", | ||
"cjs", | ||
"createBrowserHistory.js", | ||
@@ -20,13 +23,11 @@ "createHashHistory.js", | ||
"es", | ||
"index.js", | ||
"umd" | ||
"esm", | ||
"umd", | ||
"warnAboutDeprecatedCJSRequire.js" | ||
], | ||
"main": "index.js", | ||
"module": "es/index.js", | ||
"sideEffects": false, | ||
"scripts": { | ||
"start": "webpack-dev-server -d --content-base ./ --history-api-fallback --inline modules/index.js", | ||
"build": "node ./tools/build.js", | ||
"prepublish": "node ./tools/build.js", | ||
"build": "del cjs esm umd && rollup -c", | ||
"prepublishOnly": "del cjs esm umd && rollup -c", | ||
"clean": "git clean -fdX .", | ||
"release": "node ./tools/release.js", | ||
"lint": "eslint modules", | ||
@@ -36,35 +37,40 @@ "test": "karma start --single-run" | ||
"dependencies": { | ||
"invariant": "^2.2.1", | ||
"@babel/runtime": "^7.1.2", | ||
"loose-envify": "^1.2.0", | ||
"resolve-pathname": "^2.2.0", | ||
"value-equal": "^0.4.0", | ||
"warning": "^3.0.0" | ||
"tiny-invariant": "^1.0.2", | ||
"tiny-warning": "^1.0.0", | ||
"value-equal": "^0.4.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-core": "^6.23.1", | ||
"@babel/core": "^7.1.2", | ||
"@babel/plugin-transform-object-assign": "^7.0.0", | ||
"@babel/plugin-transform-runtime": "^7.1.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"babel-core": "^6.26.3", | ||
"babel-eslint": "^7.0.0", | ||
"babel-loader": "^6.2.10", | ||
"babel-loader": "^8.0.4", | ||
"babel-plugin-dev-expression": "^0.2.1", | ||
"babel-plugin-transform-object-assign": "^6.8.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-stage-1": "^6.5.0", | ||
"del-cli": "^1.1.0", | ||
"eslint": "^3.3.0", | ||
"eslint-plugin-import": "^2.0.0", | ||
"expect": "^1.20.1", | ||
"gzip-size": "^3.0.0", | ||
"in-publish": "^2.0.0", | ||
"karma": "^1.2.0", | ||
"karma-browserstack-launcher": "^1.0.1", | ||
"karma-chrome-launcher": "^2.0.0", | ||
"karma-firefox-launcher": "^1.0.0", | ||
"karma-mocha": "^1.0.1", | ||
"karma-mocha-reporter": "^2.0.4", | ||
"expect": "^21.0.0", | ||
"jest-mock": "^21.0.0", | ||
"karma": "^3.1.1", | ||
"karma-browserstack-launcher": "^1.3.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-firefox-launcher": "^1.1.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"karma-webpack": "^2.0.1", | ||
"mocha": "^3.0.2", | ||
"pretty-bytes": "^4.0.2", | ||
"readline-sync": "^1.4.4", | ||
"webpack": "^1.13.1", | ||
"webpack-dev-server": "^1.14.1" | ||
"karma-webpack": "^3.0.5", | ||
"mocha": "^5.2.0", | ||
"rollup": "^0.66.6", | ||
"rollup-plugin-babel": "^4.0.3", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
"rollup-plugin-replace": "^2.1.0", | ||
"rollup-plugin-size-snapshot": "^0.7.0", | ||
"rollup-plugin-uglify": "^6.0.0", | ||
"webpack": "^3.12.0" | ||
}, | ||
@@ -71,0 +77,0 @@ "browserify": { |
@@ -1,61 +0,3 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
var addLeadingSlash = exports.addLeadingSlash = function addLeadingSlash(path) { | ||
return path.charAt(0) === '/' ? path : '/' + path; | ||
}; | ||
var stripLeadingSlash = exports.stripLeadingSlash = function stripLeadingSlash(path) { | ||
return path.charAt(0) === '/' ? path.substr(1) : path; | ||
}; | ||
var hasBasename = exports.hasBasename = function hasBasename(path, prefix) { | ||
return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path); | ||
}; | ||
var stripBasename = exports.stripBasename = function stripBasename(path, prefix) { | ||
return hasBasename(path, prefix) ? path.substr(prefix.length) : path; | ||
}; | ||
var stripTrailingSlash = exports.stripTrailingSlash = function stripTrailingSlash(path) { | ||
return path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path; | ||
}; | ||
var parsePath = exports.parsePath = function parsePath(path) { | ||
var pathname = path || '/'; | ||
var search = ''; | ||
var hash = ''; | ||
var hashIndex = pathname.indexOf('#'); | ||
if (hashIndex !== -1) { | ||
hash = pathname.substr(hashIndex); | ||
pathname = pathname.substr(0, hashIndex); | ||
} | ||
var searchIndex = pathname.indexOf('?'); | ||
if (searchIndex !== -1) { | ||
search = pathname.substr(searchIndex); | ||
pathname = pathname.substr(0, searchIndex); | ||
} | ||
return { | ||
pathname: pathname, | ||
search: search === '?' ? '' : search, | ||
hash: hash === '#' ? '' : hash | ||
}; | ||
}; | ||
var createPath = exports.createPath = function createPath(location) { | ||
var pathname = location.pathname, | ||
search = location.search, | ||
hash = location.hash; | ||
var path = pathname || '/'; | ||
if (search && search !== '?') path += search.charAt(0) === '?' ? search : '?' + search; | ||
if (hash && hash !== '#') path += hash.charAt(0) === '#' ? hash : '#' + hash; | ||
return path; | ||
}; | ||
"use strict"; | ||
require("./warnAboutDeprecatedCJSRequire.js")("PathUtils"); | ||
module.exports = require("./index.js").PathUtils; |
121
README.md
@@ -5,3 +5,2 @@ # history [![Travis][build-badge]][build] [![npm package][npm-badge]][npm] | ||
[build]: https://travis-ci.org/ReactTraining/history | ||
[npm-badge]: https://img.shields.io/npm/v/history.svg?style=flat-square | ||
@@ -22,6 +21,6 @@ [npm]: https://www.npmjs.org/package/history | ||
// using ES6 modules | ||
import createHistory from 'history/createBrowserHistory' | ||
import { createBrowserHistory } from "history"; | ||
// using CommonJS modules | ||
var createHistory = require('history').createBrowserHistory | ||
var createBrowserHistory = require("history").createBrowserHistory; | ||
``` | ||
@@ -50,8 +49,8 @@ | ||
```js | ||
import createHistory from 'history/createBrowserHistory' | ||
import { createBrowserHistory } from "history"; | ||
const history = createHistory() | ||
const history = createHistory(); | ||
// Get the current location. | ||
const location = history.location | ||
const location = history.location; | ||
@@ -61,10 +60,10 @@ // Listen for changes to the current location. | ||
// location is an object like window.location | ||
console.log(action, location.pathname, location.state) | ||
}) | ||
console.log(action, location.pathname, location.state); | ||
}); | ||
// Use push, replace, and go to navigate around. | ||
history.push('/home', { some: 'state' }) | ||
history.push("/home", { some: "state" }); | ||
// To stop listening, call the function returned from listen(). | ||
unlisten() | ||
unlisten(); | ||
``` | ||
@@ -76,24 +75,24 @@ | ||
createBrowserHistory({ | ||
basename: '', // The base URL of the app (see below) | ||
forceRefresh: false, // Set true to force full page refreshes | ||
keyLength: 6, // The length of location.key | ||
basename: "", // The base URL of the app (see below) | ||
forceRefresh: false, // Set true to force full page refreshes | ||
keyLength: 6, // The length of location.key | ||
// A function to use to confirm navigation with the user (see below) | ||
getUserConfirmation: (message, callback) => callback(window.confirm(message)) | ||
}) | ||
}); | ||
createMemoryHistory({ | ||
initialEntries: [ '/' ], // The initial URLs in the history stack | ||
initialIndex: 0, // The starting index in the history stack | ||
keyLength: 6, // The length of location.key | ||
initialEntries: ["/"], // The initial URLs in the history stack | ||
initialIndex: 0, // The starting index in the history stack | ||
keyLength: 6, // The length of location.key | ||
// A function to use to confirm navigation with the user. Required | ||
// if you return string prompts from transition hooks (see below) | ||
getUserConfirmation: null | ||
}) | ||
}); | ||
createHashHistory({ | ||
basename: '', // The base URL of the app (see below) | ||
hashType: 'slash', // The hash type to use (see below) | ||
basename: "", // The base URL of the app (see below) | ||
hashType: "slash", // The hash type to use (see below) | ||
// A function to use to confirm navigation with the user (see below) | ||
getUserConfirmation: (message, callback) => callback(window.confirm(message)) | ||
}) | ||
}); | ||
``` | ||
@@ -117,5 +116,7 @@ | ||
history.listen((location, action) => { | ||
console.log(`The current URL is ${location.pathname}${location.search}${location.hash}`) | ||
console.log(`The last navigation action was ${action}`) | ||
}) | ||
console.log( | ||
`The current URL is ${location.pathname}${location.search}${location.hash}` | ||
); | ||
console.log(`The last navigation action was ${action}`); | ||
}); | ||
``` | ||
@@ -138,3 +139,3 @@ | ||
`history` objects may be used programmatically change the current location using the following methods: | ||
`history` objects may be used to programmatically change the current location using the following methods: | ||
@@ -150,3 +151,3 @@ - `history.push(path, [state])` | ||
1. A URL path *or* | ||
1. A URL path _or_ | ||
2. A location-like object with `{ pathname, search, hash, state }` | ||
@@ -156,7 +157,7 @@ | ||
// Push a new entry onto the history stack. | ||
history.push('/home') | ||
history.push("/home"); | ||
// Push a new entry onto the history stack with a query string | ||
// and some state. Location state does not appear in the URL. | ||
history.push('/home?the=query', { some: 'state' }) | ||
history.push("/home?the=query", { some: "state" }); | ||
@@ -166,11 +167,11 @@ // If you prefer, use a single location-like object to specify both | ||
history.push({ | ||
pathname: '/home', | ||
search: '?the=query', | ||
state: { some: 'state' } | ||
}) | ||
pathname: "/home", | ||
search: "?the=query", | ||
state: { some: "state" } | ||
}); | ||
// Go back to the previous history entry. The following | ||
// two lines are synonymous. | ||
history.go(-1) | ||
history.goBack() | ||
history.go(-1); | ||
history.goBack(); | ||
``` | ||
@@ -187,3 +188,3 @@ | ||
// user before they navigate away from the current page. | ||
const unblock = history.block('Are you sure you want to leave this page?') | ||
const unblock = history.block("Are you sure you want to leave this page?"); | ||
@@ -197,8 +198,7 @@ // Or use a function that returns the message when it's needed. | ||
// page if there's a form they haven't submitted yet. | ||
if (input.value !== '') | ||
return 'Are you sure you want to leave this page?' | ||
}) | ||
if (input.value !== "") return "Are you sure you want to leave this page?"; | ||
}); | ||
// To stop blocking transitions, call the function returned from block(). | ||
unblock() | ||
unblock(); | ||
``` | ||
@@ -219,3 +219,3 @@ | ||
} | ||
}) | ||
}); | ||
``` | ||
@@ -229,10 +229,10 @@ | ||
const history = createHistory({ | ||
basename: '/the/base' | ||
}) | ||
basename: "/the/base" | ||
}); | ||
history.listen(location => { | ||
console.log(location.pathname) // /home | ||
}) | ||
console.log(location.pathname); // /home | ||
}); | ||
history.push('/home') // URL is now /the/base/home | ||
history.push("/home"); // URL is now /the/base/home | ||
``` | ||
@@ -249,3 +249,3 @@ | ||
forceRefresh: true | ||
}) | ||
}); | ||
``` | ||
@@ -257,27 +257,32 @@ | ||
```js | ||
const history = createHashHistory({ | ||
hashType: 'slash' // the default | ||
}) | ||
hashType: "slash" // the default | ||
}); | ||
history.push('/home') // window.location.hash is #/home | ||
history.push("/home"); // window.location.hash is #/home | ||
const history = createHashHistory({ | ||
hashType: 'noslash' // Omit the leading slash | ||
}) | ||
hashType: "noslash" // Omit the leading slash | ||
}); | ||
history.push('/home') // window.location.hash is #home | ||
history.push("/home"); // window.location.hash is #home | ||
const history = createHashHistory({ | ||
hashType: 'hashbang' // Google's legacy AJAX URL format | ||
}) | ||
hashType: "hashbang" // Google's legacy AJAX URL format | ||
}); | ||
history.push('/home') // window.location.hash is #!/home | ||
history.push("/home"); // window.location.hash is #!/home | ||
``` | ||
## About | ||
`history` is developed and maintained by [React Training](https://reacttraining.com). If | ||
you're interested in learning more about what React can do for your company, please | ||
[get in touch](mailto:hello@reacttraining.com)! | ||
## Thanks | ||
A big thank-you to [Dan Shaw](https://www.npmjs.com/~dshaw) for letting us use the `history` npm package name! Thanks Dan! | ||
A big thank-you to [BrowserStack](https://www.browserstack.com/) for providing the infrastructure that allows us to run our build in real browsers. | ||
Also, thanks to [BrowserStack](https://www.browserstack.com/) for providing the infrastructure that allows us to run our build in real browsers. | ||
Also, thanks to [Dan Shaw](https://www.npmjs.com/~dshaw) for letting us use the `history` npm package name. Thanks Dan! |
2197
umd/history.js
@@ -1,1478 +0,1059 @@ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(); | ||
else if(typeof define === 'function' && define.amd) | ||
define([], factory); | ||
else if(typeof exports === 'object') | ||
exports["History"] = factory(); | ||
else | ||
root["History"] = factory(); | ||
})(this, function() { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.History = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) | ||
/******/ return installedModules[moduleId].exports; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ exports: {}, | ||
/******/ id: moduleId, | ||
/******/ loaded: false | ||
/******/ }; | ||
return target; | ||
}; | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
return _extends.apply(this, arguments); | ||
} | ||
/******/ // Flag the module as loaded | ||
/******/ module.loaded = true; | ||
function warning(condition, message) { | ||
{ | ||
if (condition) { | ||
return; | ||
} | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
console.warn(message); | ||
} | ||
} | ||
var prefix = 'Invariant failed'; | ||
function invariant(condition, message) { | ||
if (condition) { | ||
return; | ||
} | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
{ | ||
throw new Error(prefix + ": " + (message || '')); | ||
} | ||
} | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
function isAbsolute(pathname) { | ||
return pathname.charAt(0) === '/'; | ||
} | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
// About 1.5x faster than the two-arg version of Array#splice() | ||
function spliceOne(list, index) { | ||
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) { | ||
list[i] = list[k]; | ||
} | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(0); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([ | ||
/* 0 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
list.pop(); | ||
} | ||
'use strict'; | ||
// This implementation is based heavily on node's url.parse | ||
function resolvePathname(to) { | ||
var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
exports.__esModule = true; | ||
exports.createPath = exports.parsePath = exports.locationsAreEqual = exports.createLocation = exports.createMemoryHistory = exports.createHashHistory = exports.createBrowserHistory = undefined; | ||
var toParts = to && to.split('/') || []; | ||
var fromParts = from && from.split('/') || []; | ||
var _LocationUtils = __webpack_require__(1); | ||
var isToAbs = to && isAbsolute(to); | ||
var isFromAbs = from && isAbsolute(from); | ||
var mustEndAbs = isToAbs || isFromAbs; | ||
Object.defineProperty(exports, 'createLocation', { | ||
enumerable: true, | ||
get: function get() { | ||
return _LocationUtils.createLocation; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'locationsAreEqual', { | ||
enumerable: true, | ||
get: function get() { | ||
return _LocationUtils.locationsAreEqual; | ||
} | ||
}); | ||
if (to && isAbsolute(to)) { | ||
// to is absolute | ||
fromParts = toParts; | ||
} else if (toParts.length) { | ||
// to is relative, drop the filename | ||
fromParts.pop(); | ||
fromParts = fromParts.concat(toParts); | ||
} | ||
var _PathUtils = __webpack_require__(4); | ||
if (!fromParts.length) return '/'; | ||
Object.defineProperty(exports, 'parsePath', { | ||
enumerable: true, | ||
get: function get() { | ||
return _PathUtils.parsePath; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'createPath', { | ||
enumerable: true, | ||
get: function get() { | ||
return _PathUtils.createPath; | ||
} | ||
}); | ||
var hasTrailingSlash = void 0; | ||
if (fromParts.length) { | ||
var last = fromParts[fromParts.length - 1]; | ||
hasTrailingSlash = last === '.' || last === '..' || last === ''; | ||
} else { | ||
hasTrailingSlash = false; | ||
} | ||
var _createBrowserHistory2 = __webpack_require__(5); | ||
var up = 0; | ||
for (var i = fromParts.length; i >= 0; i--) { | ||
var part = fromParts[i]; | ||
var _createBrowserHistory3 = _interopRequireDefault(_createBrowserHistory2); | ||
if (part === '.') { | ||
spliceOne(fromParts, i); | ||
} else if (part === '..') { | ||
spliceOne(fromParts, i); | ||
up++; | ||
} else if (up) { | ||
spliceOne(fromParts, i); | ||
up--; | ||
} | ||
} | ||
var _createHashHistory2 = __webpack_require__(10); | ||
if (!mustEndAbs) for (; up--; up) { | ||
fromParts.unshift('..'); | ||
}if (mustEndAbs && fromParts[0] !== '' && (!fromParts[0] || !isAbsolute(fromParts[0]))) fromParts.unshift(''); | ||
var _createHashHistory3 = _interopRequireDefault(_createHashHistory2); | ||
var result = fromParts.join('/'); | ||
var _createMemoryHistory2 = __webpack_require__(11); | ||
if (hasTrailingSlash && result.substr(-1) !== '/') result += '/'; | ||
var _createMemoryHistory3 = _interopRequireDefault(_createMemoryHistory2); | ||
return result; | ||
} | ||
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 && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.createBrowserHistory = _createBrowserHistory3.default; | ||
exports.createHashHistory = _createHashHistory3.default; | ||
exports.createMemoryHistory = _createMemoryHistory3.default; | ||
function valueEqual(a, b) { | ||
if (a === b) return true; | ||
/***/ }, | ||
/* 1 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
if (a == null || b == null) return false; | ||
'use strict'; | ||
if (Array.isArray(a)) { | ||
return Array.isArray(b) && a.length === b.length && a.every(function (item, index) { | ||
return valueEqual(item, b[index]); | ||
}); | ||
} | ||
exports.__esModule = true; | ||
exports.locationsAreEqual = exports.createLocation = undefined; | ||
var aType = typeof a === 'undefined' ? 'undefined' : _typeof(a); | ||
var bType = typeof b === 'undefined' ? 'undefined' : _typeof(b); | ||
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; }; | ||
if (aType !== bType) return false; | ||
var _resolvePathname = __webpack_require__(2); | ||
if (aType === 'object') { | ||
var aValue = a.valueOf(); | ||
var bValue = b.valueOf(); | ||
var _resolvePathname2 = _interopRequireDefault(_resolvePathname); | ||
if (aValue !== a || bValue !== b) return valueEqual(aValue, bValue); | ||
var _valueEqual = __webpack_require__(3); | ||
var aKeys = Object.keys(a); | ||
var bKeys = Object.keys(b); | ||
var _valueEqual2 = _interopRequireDefault(_valueEqual); | ||
if (aKeys.length !== bKeys.length) return false; | ||
var _PathUtils = __webpack_require__(4); | ||
return aKeys.every(function (key) { | ||
return valueEqual(a[key], b[key]); | ||
}); | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
return false; | ||
} | ||
var createLocation = exports.createLocation = function createLocation(path, state, key, currentLocation) { | ||
var location = void 0; | ||
if (typeof path === 'string') { | ||
// Two-arg form: push(path, state) | ||
location = (0, _PathUtils.parsePath)(path); | ||
location.state = state; | ||
} else { | ||
// One-arg form: push(location) | ||
location = _extends({}, path); | ||
function addLeadingSlash(path) { | ||
return path.charAt(0) === "/" ? path : "/" + path; | ||
} | ||
function stripLeadingSlash(path) { | ||
return path.charAt(0) === "/" ? path.substr(1) : path; | ||
} | ||
function hasBasename(path, prefix) { | ||
return new RegExp("^" + prefix + "(\\/|\\?|#|$)", "i").test(path); | ||
} | ||
function stripBasename(path, prefix) { | ||
return hasBasename(path, prefix) ? path.substr(prefix.length) : path; | ||
} | ||
function stripTrailingSlash(path) { | ||
return path.charAt(path.length - 1) === "/" ? path.slice(0, -1) : path; | ||
} | ||
function parsePath(path) { | ||
var pathname = path || "/"; | ||
var search = ""; | ||
var hash = ""; | ||
var hashIndex = pathname.indexOf("#"); | ||
if (location.pathname === undefined) location.pathname = ''; | ||
if (hashIndex !== -1) { | ||
hash = pathname.substr(hashIndex); | ||
pathname = pathname.substr(0, hashIndex); | ||
} | ||
if (location.search) { | ||
if (location.search.charAt(0) !== '?') location.search = '?' + location.search; | ||
} else { | ||
location.search = ''; | ||
} | ||
var searchIndex = pathname.indexOf("?"); | ||
if (location.hash) { | ||
if (location.hash.charAt(0) !== '#') location.hash = '#' + location.hash; | ||
} else { | ||
location.hash = ''; | ||
} | ||
if (searchIndex !== -1) { | ||
search = pathname.substr(searchIndex); | ||
pathname = pathname.substr(0, searchIndex); | ||
} | ||
if (state !== undefined && location.state === undefined) location.state = state; | ||
} | ||
return { | ||
pathname: pathname, | ||
search: search === "?" ? "" : search, | ||
hash: hash === "#" ? "" : hash | ||
}; | ||
} | ||
function createPath(location) { | ||
var pathname = location.pathname, | ||
search = location.search, | ||
hash = location.hash; | ||
var path = pathname || "/"; | ||
if (search && search !== "?") path += search.charAt(0) === "?" ? search : "?" + search; | ||
if (hash && hash !== "#") path += hash.charAt(0) === "#" ? hash : "#" + hash; | ||
return path; | ||
} | ||
try { | ||
location.pathname = decodeURI(location.pathname); | ||
} catch (e) { | ||
if (e instanceof URIError) { | ||
throw new URIError('Pathname "' + location.pathname + '" could not be decoded. ' + 'This is likely caused by an invalid percent-encoding.'); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
function createLocation(path, state, key, currentLocation) { | ||
var location; | ||
if (key) location.key = key; | ||
if (typeof path === "string") { | ||
// Two-arg form: push(path, state) | ||
location = parsePath(path); | ||
location.state = state; | ||
} else { | ||
// One-arg form: push(location) | ||
location = _extends({}, path); | ||
if (location.pathname === undefined) location.pathname = ""; | ||
if (currentLocation) { | ||
// Resolve incomplete/relative pathname relative to current location. | ||
if (!location.pathname) { | ||
location.pathname = currentLocation.pathname; | ||
} else if (location.pathname.charAt(0) !== '/') { | ||
location.pathname = (0, _resolvePathname2.default)(location.pathname, currentLocation.pathname); | ||
} | ||
} else { | ||
// When there is no prior location and pathname is empty, set it to / | ||
if (!location.pathname) { | ||
location.pathname = '/'; | ||
} | ||
} | ||
if (location.search) { | ||
if (location.search.charAt(0) !== "?") location.search = "?" + location.search; | ||
} else { | ||
location.search = ""; | ||
} | ||
return location; | ||
}; | ||
if (location.hash) { | ||
if (location.hash.charAt(0) !== "#") location.hash = "#" + location.hash; | ||
} else { | ||
location.hash = ""; | ||
} | ||
var locationsAreEqual = exports.locationsAreEqual = function locationsAreEqual(a, b) { | ||
return a.pathname === b.pathname && a.search === b.search && a.hash === b.hash && a.key === b.key && (0, _valueEqual2.default)(a.state, b.state); | ||
}; | ||
if (state !== undefined && location.state === undefined) location.state = state; | ||
} | ||
/***/ }, | ||
/* 2 */ | ||
/***/ function(module, exports) { | ||
try { | ||
location.pathname = decodeURI(location.pathname); | ||
} catch (e) { | ||
if (e instanceof URIError) { | ||
throw new URIError('Pathname "' + location.pathname + '" could not be decoded. ' + "This is likely caused by an invalid percent-encoding."); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
'use strict'; | ||
if (key) location.key = key; | ||
exports.__esModule = true; | ||
function isAbsolute(pathname) { | ||
return pathname.charAt(0) === '/'; | ||
} | ||
if (currentLocation) { | ||
// Resolve incomplete/relative pathname relative to current location. | ||
if (!location.pathname) { | ||
location.pathname = currentLocation.pathname; | ||
} else if (location.pathname.charAt(0) !== "/") { | ||
location.pathname = resolvePathname(location.pathname, currentLocation.pathname); | ||
} | ||
} else { | ||
// When there is no prior location and pathname is empty, set it to / | ||
if (!location.pathname) { | ||
location.pathname = "/"; | ||
} | ||
} | ||
// About 1.5x faster than the two-arg version of Array#splice() | ||
function spliceOne(list, index) { | ||
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) { | ||
list[i] = list[k]; | ||
} | ||
return location; | ||
} | ||
function locationsAreEqual(a, b) { | ||
return a.pathname === b.pathname && a.search === b.search && a.hash === b.hash && a.key === b.key && valueEqual(a.state, b.state); | ||
} | ||
list.pop(); | ||
} | ||
function createTransitionManager() { | ||
var prompt = null; | ||
// This implementation is based heavily on node's url.parse | ||
function resolvePathname(to) { | ||
var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
function setPrompt(nextPrompt) { | ||
warning(prompt == null, "A history supports only one prompt at a time"); | ||
prompt = nextPrompt; | ||
return function () { | ||
if (prompt === nextPrompt) prompt = null; | ||
}; | ||
} | ||
var toParts = to && to.split('/') || []; | ||
var fromParts = from && from.split('/') || []; | ||
function confirmTransitionTo(location, action, getUserConfirmation, callback) { | ||
// TODO: If another transition starts while we're still confirming | ||
// the previous one, we may end up in a weird state. Figure out the | ||
// best way to handle this. | ||
if (prompt != null) { | ||
var result = typeof prompt === "function" ? prompt(location, action) : prompt; | ||
var isToAbs = to && isAbsolute(to); | ||
var isFromAbs = from && isAbsolute(from); | ||
var mustEndAbs = isToAbs || isFromAbs; | ||
if (typeof result === "string") { | ||
if (typeof getUserConfirmation === "function") { | ||
getUserConfirmation(result, callback); | ||
} else { | ||
warning(false, "A history needs a getUserConfirmation function in order to use a prompt message"); | ||
callback(true); | ||
} | ||
} else { | ||
// Return false from a transition hook to cancel the transition. | ||
callback(result !== false); | ||
} | ||
} else { | ||
callback(true); | ||
} | ||
} | ||
if (to && isAbsolute(to)) { | ||
// to is absolute | ||
fromParts = toParts; | ||
} else if (toParts.length) { | ||
// to is relative, drop the filename | ||
fromParts.pop(); | ||
fromParts = fromParts.concat(toParts); | ||
} | ||
var listeners = []; | ||
if (!fromParts.length) return '/'; | ||
function appendListener(fn) { | ||
var isActive = true; | ||
var hasTrailingSlash = void 0; | ||
if (fromParts.length) { | ||
var last = fromParts[fromParts.length - 1]; | ||
hasTrailingSlash = last === '.' || last === '..' || last === ''; | ||
} else { | ||
hasTrailingSlash = false; | ||
} | ||
function listener() { | ||
if (isActive) fn.apply(void 0, arguments); | ||
} | ||
var up = 0; | ||
for (var i = fromParts.length; i >= 0; i--) { | ||
var part = fromParts[i]; | ||
listeners.push(listener); | ||
return function () { | ||
isActive = false; | ||
listeners = listeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
}; | ||
} | ||
if (part === '.') { | ||
spliceOne(fromParts, i); | ||
} else if (part === '..') { | ||
spliceOne(fromParts, i); | ||
up++; | ||
} else if (up) { | ||
spliceOne(fromParts, i); | ||
up--; | ||
} | ||
} | ||
function notifyListeners() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
if (!mustEndAbs) for (; up--; up) { | ||
fromParts.unshift('..'); | ||
}if (mustEndAbs && fromParts[0] !== '' && (!fromParts[0] || !isAbsolute(fromParts[0]))) fromParts.unshift(''); | ||
listeners.forEach(function (listener) { | ||
return listener.apply(void 0, args); | ||
}); | ||
} | ||
var result = fromParts.join('/'); | ||
return { | ||
setPrompt: setPrompt, | ||
confirmTransitionTo: confirmTransitionTo, | ||
appendListener: appendListener, | ||
notifyListeners: notifyListeners | ||
}; | ||
} | ||
if (hasTrailingSlash && result.substr(-1) !== '/') result += '/'; | ||
var canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement); | ||
function getConfirmation(message, callback) { | ||
callback(window.confirm(message)); // eslint-disable-line no-alert | ||
} | ||
/** | ||
* Returns true if the HTML5 history API is supported. Taken from Modernizr. | ||
* | ||
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE | ||
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js | ||
* changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586 | ||
*/ | ||
return result; | ||
} | ||
function supportsHistory() { | ||
var ua = window.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; | ||
return window.history && "pushState" in window.history; | ||
} | ||
/** | ||
* Returns true if browser fires popstate on hash change. | ||
* IE10 and IE11 do not. | ||
*/ | ||
exports.default = resolvePathname; | ||
module.exports = exports['default']; | ||
function supportsPopStateOnHashChange() { | ||
return window.navigator.userAgent.indexOf("Trident") === -1; | ||
} | ||
/** | ||
* Returns false if using go(n) with hash history causes a full page reload. | ||
*/ | ||
/***/ }, | ||
/* 3 */ | ||
/***/ function(module, exports) { | ||
function supportsGoWithoutReloadUsingHash() { | ||
return window.navigator.userAgent.indexOf("Firefox") === -1; | ||
} | ||
/** | ||
* Returns true if a given popstate event is an extraneous WebKit event. | ||
* Accounts for the fact that Chrome on iOS fires real popstate events | ||
* containing undefined state when pressing the back button. | ||
*/ | ||
'use strict'; | ||
function isExtraneousPopstateEvent(event) { | ||
event.state === undefined && navigator.userAgent.indexOf("CriOS") === -1; | ||
} | ||
exports.__esModule = true; | ||
var PopStateEvent = "popstate"; | ||
var HashChangeEvent = "hashchange"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function getHistoryState() { | ||
try { | ||
return window.history.state || {}; | ||
} catch (e) { | ||
// IE 11 sometimes throws when accessing window.history.state | ||
// See https://github.com/ReactTraining/history/pull/289 | ||
return {}; | ||
} | ||
} | ||
/** | ||
* Creates a history object that uses the HTML5 history API including | ||
* pushState, replaceState, and the popstate event. | ||
*/ | ||
function valueEqual(a, b) { | ||
if (a === b) return true; | ||
if (a == null || b == null) return false; | ||
function createBrowserHistory(props) { | ||
if (props === void 0) { | ||
props = {}; | ||
} | ||
if (Array.isArray(a)) { | ||
return Array.isArray(b) && a.length === b.length && a.every(function (item, index) { | ||
return valueEqual(item, b[index]); | ||
}); | ||
} | ||
!canUseDOM ? invariant(false, "Browser history needs a DOM") : void 0; | ||
var globalHistory = window.history; | ||
var canUseHistory = supportsHistory(); | ||
var needsHashChangeListener = !supportsPopStateOnHashChange(); | ||
var _props = props, | ||
_props$forceRefresh = _props.forceRefresh, | ||
forceRefresh = _props$forceRefresh === void 0 ? false : _props$forceRefresh, | ||
_props$getUserConfirm = _props.getUserConfirmation, | ||
getUserConfirmation = _props$getUserConfirm === void 0 ? getConfirmation : _props$getUserConfirm, | ||
_props$keyLength = _props.keyLength, | ||
keyLength = _props$keyLength === void 0 ? 6 : _props$keyLength; | ||
var basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : ""; | ||
var aType = typeof a === 'undefined' ? 'undefined' : _typeof(a); | ||
var bType = typeof b === 'undefined' ? 'undefined' : _typeof(b); | ||
function getDOMLocation(historyState) { | ||
var _ref = historyState || {}, | ||
key = _ref.key, | ||
state = _ref.state; | ||
if (aType !== bType) return false; | ||
var _window$location = window.location, | ||
pathname = _window$location.pathname, | ||
search = _window$location.search, | ||
hash = _window$location.hash; | ||
var path = pathname + search + hash; | ||
warning(!basename || hasBasename(path, basename), "You are attempting to use a basename on a page whose URL path does not begin " + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".'); | ||
if (basename) path = stripBasename(path, basename); | ||
return createLocation(path, state, key); | ||
} | ||
if (aType === 'object') { | ||
var aValue = a.valueOf(); | ||
var bValue = b.valueOf(); | ||
function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength); | ||
} | ||
if (aValue !== a || bValue !== b) return valueEqual(aValue, bValue); | ||
var transitionManager = createTransitionManager(); | ||
var aKeys = Object.keys(a); | ||
var bKeys = Object.keys(b); | ||
function setState(nextState) { | ||
_extends(history, nextState); | ||
if (aKeys.length !== bKeys.length) return false; | ||
history.length = globalHistory.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
} | ||
return aKeys.every(function (key) { | ||
return valueEqual(a[key], b[key]); | ||
}); | ||
} | ||
function handlePopState(event) { | ||
// Ignore extraneous popstate events in WebKit. | ||
if (isExtraneousPopstateEvent(event)) return; | ||
handlePop(getDOMLocation(event.state)); | ||
} | ||
return false; | ||
} | ||
function handleHashChange() { | ||
handlePop(getDOMLocation(getHistoryState())); | ||
} | ||
exports.default = valueEqual; | ||
module.exports = exports['default']; | ||
var forceNextPop = false; | ||
/***/ }, | ||
/* 4 */ | ||
/***/ function(module, exports) { | ||
function handlePop(location) { | ||
if (forceNextPop) { | ||
forceNextPop = false; | ||
setState(); | ||
} else { | ||
var action = "POP"; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ | ||
action: action, | ||
location: location | ||
}); | ||
} else { | ||
revertPop(location); | ||
} | ||
}); | ||
} | ||
} | ||
'use strict'; | ||
function revertPop(fromLocation) { | ||
var toLocation = history.location; // TODO: We could probably make this more reliable by | ||
// keeping a list of keys we've seen in sessionStorage. | ||
// Instead, we just default to 0 for keys we don't know. | ||
exports.__esModule = true; | ||
var addLeadingSlash = exports.addLeadingSlash = function addLeadingSlash(path) { | ||
return path.charAt(0) === '/' ? path : '/' + path; | ||
}; | ||
var toIndex = allKeys.indexOf(toLocation.key); | ||
if (toIndex === -1) toIndex = 0; | ||
var fromIndex = allKeys.indexOf(fromLocation.key); | ||
if (fromIndex === -1) fromIndex = 0; | ||
var delta = toIndex - fromIndex; | ||
var stripLeadingSlash = exports.stripLeadingSlash = function stripLeadingSlash(path) { | ||
return path.charAt(0) === '/' ? path.substr(1) : path; | ||
}; | ||
if (delta) { | ||
forceNextPop = true; | ||
go(delta); | ||
} | ||
} | ||
var hasBasename = exports.hasBasename = function hasBasename(path, prefix) { | ||
return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path); | ||
}; | ||
var initialLocation = getDOMLocation(getHistoryState()); | ||
var allKeys = [initialLocation.key]; // Public interface | ||
var stripBasename = exports.stripBasename = function stripBasename(path, prefix) { | ||
return hasBasename(path, prefix) ? path.substr(prefix.length) : path; | ||
}; | ||
function createHref(location) { | ||
return basename + createPath(location); | ||
} | ||
var stripTrailingSlash = exports.stripTrailingSlash = function stripTrailingSlash(path) { | ||
return path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path; | ||
}; | ||
function push(path, state) { | ||
warning(!(typeof path === "object" && path.state !== undefined && state !== undefined), "You should avoid providing a 2nd state argument to push when the 1st " + "argument is a location-like object that already has state; it is ignored"); | ||
var action = "PUSH"; | ||
var location = createLocation(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var href = createHref(location); | ||
var key = location.key, | ||
state = location.state; | ||
var parsePath = exports.parsePath = function parsePath(path) { | ||
var pathname = path || '/'; | ||
var search = ''; | ||
var hash = ''; | ||
if (canUseHistory) { | ||
globalHistory.pushState({ | ||
key: key, | ||
state: state | ||
}, null, href); | ||
var hashIndex = pathname.indexOf('#'); | ||
if (hashIndex !== -1) { | ||
hash = pathname.substr(hashIndex); | ||
pathname = pathname.substr(0, hashIndex); | ||
} | ||
if (forceRefresh) { | ||
window.location.href = href; | ||
} else { | ||
var prevIndex = allKeys.indexOf(history.location.key); | ||
var nextKeys = allKeys.slice(0, prevIndex === -1 ? 0 : prevIndex + 1); | ||
nextKeys.push(location.key); | ||
allKeys = nextKeys; | ||
setState({ | ||
action: action, | ||
location: location | ||
}); | ||
} | ||
} else { | ||
warning(state === undefined, "Browser history cannot push state in browsers that do not support HTML5 history"); | ||
window.location.href = href; | ||
} | ||
}); | ||
} | ||
var searchIndex = pathname.indexOf('?'); | ||
if (searchIndex !== -1) { | ||
search = pathname.substr(searchIndex); | ||
pathname = pathname.substr(0, searchIndex); | ||
} | ||
function replace(path, state) { | ||
warning(!(typeof path === "object" && path.state !== undefined && state !== undefined), "You should avoid providing a 2nd state argument to replace when the 1st " + "argument is a location-like object that already has state; it is ignored"); | ||
var action = "REPLACE"; | ||
var location = createLocation(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var href = createHref(location); | ||
var key = location.key, | ||
state = location.state; | ||
return { | ||
pathname: pathname, | ||
search: search === '?' ? '' : search, | ||
hash: hash === '#' ? '' : hash | ||
}; | ||
}; | ||
if (canUseHistory) { | ||
globalHistory.replaceState({ | ||
key: key, | ||
state: state | ||
}, null, href); | ||
var createPath = exports.createPath = function createPath(location) { | ||
var pathname = location.pathname, | ||
search = location.search, | ||
hash = location.hash; | ||
if (forceRefresh) { | ||
window.location.replace(href); | ||
} else { | ||
var prevIndex = allKeys.indexOf(history.location.key); | ||
if (prevIndex !== -1) allKeys[prevIndex] = location.key; | ||
setState({ | ||
action: action, | ||
location: location | ||
}); | ||
} | ||
} else { | ||
warning(state === undefined, "Browser history cannot replace state in browsers that do not support HTML5 history"); | ||
window.location.replace(href); | ||
} | ||
}); | ||
} | ||
function go(n) { | ||
globalHistory.go(n); | ||
} | ||
var path = pathname || '/'; | ||
function goBack() { | ||
go(-1); | ||
} | ||
if (search && search !== '?') path += search.charAt(0) === '?' ? search : '?' + search; | ||
function goForward() { | ||
go(1); | ||
} | ||
if (hash && hash !== '#') path += hash.charAt(0) === '#' ? hash : '#' + hash; | ||
var listenerCount = 0; | ||
return path; | ||
}; | ||
function checkDOMListeners(delta) { | ||
listenerCount += delta; | ||
/***/ }, | ||
/* 5 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
if (listenerCount === 1) { | ||
window.addEventListener(PopStateEvent, handlePopState); | ||
if (needsHashChangeListener) window.addEventListener(HashChangeEvent, handleHashChange); | ||
} else if (listenerCount === 0) { | ||
window.removeEventListener(PopStateEvent, handlePopState); | ||
if (needsHashChangeListener) window.removeEventListener(HashChangeEvent, handleHashChange); | ||
} | ||
} | ||
'use strict'; | ||
var isBlocked = false; | ||
exports.__esModule = true; | ||
function block(prompt) { | ||
if (prompt === void 0) { | ||
prompt = false; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var unblock = transitionManager.setPrompt(prompt); | ||
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; }; | ||
if (!isBlocked) { | ||
checkDOMListeners(1); | ||
isBlocked = true; | ||
} | ||
var _warning = __webpack_require__(6); | ||
return function () { | ||
if (isBlocked) { | ||
isBlocked = false; | ||
checkDOMListeners(-1); | ||
} | ||
var _warning2 = _interopRequireDefault(_warning); | ||
return unblock(); | ||
}; | ||
} | ||
var _invariant = __webpack_require__(7); | ||
function listen(listener) { | ||
var unlisten = transitionManager.appendListener(listener); | ||
checkDOMListeners(1); | ||
return function () { | ||
checkDOMListeners(-1); | ||
unlisten(); | ||
}; | ||
} | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var history = { | ||
length: globalHistory.length, | ||
action: "POP", | ||
location: initialLocation, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
} | ||
var _LocationUtils = __webpack_require__(1); | ||
var HashChangeEvent$1 = "hashchange"; | ||
var HashPathCoders = { | ||
hashbang: { | ||
encodePath: function encodePath(path) { | ||
return path.charAt(0) === "!" ? path : "!/" + stripLeadingSlash(path); | ||
}, | ||
decodePath: function decodePath(path) { | ||
return path.charAt(0) === "!" ? path.substr(1) : path; | ||
} | ||
}, | ||
noslash: { | ||
encodePath: stripLeadingSlash, | ||
decodePath: addLeadingSlash | ||
}, | ||
slash: { | ||
encodePath: addLeadingSlash, | ||
decodePath: addLeadingSlash | ||
} | ||
}; | ||
var _PathUtils = __webpack_require__(4); | ||
function getHashPath() { | ||
// We can't use window.location.hash here because it's not | ||
// consistent across browsers - Firefox will pre-decode it! | ||
var href = window.location.href; | ||
var hashIndex = href.indexOf("#"); | ||
return hashIndex === -1 ? "" : href.substring(hashIndex + 1); | ||
} | ||
var _createTransitionManager = __webpack_require__(8); | ||
function pushHashPath(path) { | ||
window.location.hash = path; | ||
} | ||
var _createTransitionManager2 = _interopRequireDefault(_createTransitionManager); | ||
function replaceHashPath(path) { | ||
var hashIndex = window.location.href.indexOf("#"); | ||
window.location.replace(window.location.href.slice(0, hashIndex >= 0 ? hashIndex : 0) + "#" + path); | ||
} | ||
var _DOMUtils = __webpack_require__(9); | ||
function createHashHistory(props) { | ||
if (props === void 0) { | ||
props = {}; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
!canUseDOM ? invariant(false, "Hash history needs a DOM") : void 0; | ||
var globalHistory = window.history; | ||
var canGoWithoutReload = supportsGoWithoutReloadUsingHash(); | ||
var _props = props, | ||
_props$getUserConfirm = _props.getUserConfirmation, | ||
getUserConfirmation = _props$getUserConfirm === void 0 ? getConfirmation : _props$getUserConfirm, | ||
_props$hashType = _props.hashType, | ||
hashType = _props$hashType === void 0 ? "slash" : _props$hashType; | ||
var basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : ""; | ||
var _HashPathCoders$hashT = HashPathCoders[hashType], | ||
encodePath = _HashPathCoders$hashT.encodePath, | ||
decodePath = _HashPathCoders$hashT.decodePath; | ||
var PopStateEvent = 'popstate'; | ||
var HashChangeEvent = 'hashchange'; | ||
function getDOMLocation() { | ||
var path = decodePath(getHashPath()); | ||
warning(!basename || hasBasename(path, basename), "You are attempting to use a basename on a page whose URL path does not begin " + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".'); | ||
if (basename) path = stripBasename(path, basename); | ||
return createLocation(path); | ||
} | ||
var getHistoryState = function getHistoryState() { | ||
try { | ||
return window.history.state || {}; | ||
} catch (e) { | ||
// IE 11 sometimes throws when accessing window.history.state | ||
// See https://github.com/ReactTraining/history/pull/289 | ||
return {}; | ||
} | ||
}; | ||
var transitionManager = createTransitionManager(); | ||
/** | ||
* Creates a history object that uses the HTML5 history API including | ||
* pushState, replaceState, and the popstate event. | ||
*/ | ||
var createBrowserHistory = function createBrowserHistory() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
function setState(nextState) { | ||
_extends(history, nextState); | ||
!_DOMUtils.canUseDOM ? false ? (0, _invariant2.default)(false, 'Browser history needs a DOM') : (0, _invariant2.default)(false) : void 0; | ||
history.length = globalHistory.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
} | ||
var globalHistory = window.history; | ||
var canUseHistory = (0, _DOMUtils.supportsHistory)(); | ||
var needsHashChangeListener = !(0, _DOMUtils.supportsPopStateOnHashChange)(); | ||
var forceNextPop = false; | ||
var ignorePath = null; | ||
var _props$forceRefresh = props.forceRefresh, | ||
forceRefresh = _props$forceRefresh === undefined ? false : _props$forceRefresh, | ||
_props$getUserConfirm = props.getUserConfirmation, | ||
getUserConfirmation = _props$getUserConfirm === undefined ? _DOMUtils.getConfirmation : _props$getUserConfirm, | ||
_props$keyLength = props.keyLength, | ||
keyLength = _props$keyLength === undefined ? 6 : _props$keyLength; | ||
function handleHashChange() { | ||
var path = getHashPath(); | ||
var encodedPath = encodePath(path); | ||
var basename = props.basename ? (0, _PathUtils.stripTrailingSlash)((0, _PathUtils.addLeadingSlash)(props.basename)) : ''; | ||
if (path !== encodedPath) { | ||
// Ensure we always have a properly-encoded hash. | ||
replaceHashPath(encodedPath); | ||
} else { | ||
var location = getDOMLocation(); | ||
var prevLocation = history.location; | ||
if (!forceNextPop && locationsAreEqual(prevLocation, location)) return; // A hashchange doesn't always == location change. | ||
var getDOMLocation = function getDOMLocation(historyState) { | ||
var _ref = historyState || {}, | ||
key = _ref.key, | ||
state = _ref.state; | ||
if (ignorePath === createPath(location)) return; // Ignore this change; we already setState in push/replace. | ||
var _window$location = window.location, | ||
pathname = _window$location.pathname, | ||
search = _window$location.search, | ||
hash = _window$location.hash; | ||
ignorePath = null; | ||
handlePop(location); | ||
} | ||
} | ||
function handlePop(location) { | ||
if (forceNextPop) { | ||
forceNextPop = false; | ||
setState(); | ||
} else { | ||
var action = "POP"; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ | ||
action: action, | ||
location: location | ||
}); | ||
} else { | ||
revertPop(location); | ||
} | ||
}); | ||
} | ||
} | ||
var path = pathname + search + hash; | ||
function revertPop(fromLocation) { | ||
var toLocation = history.location; // TODO: We could probably make this more reliable by | ||
// keeping a list of paths we've seen in sessionStorage. | ||
// Instead, we just default to 0 for paths we don't know. | ||
false ? (0, _warning2.default)(!basename || (0, _PathUtils.hasBasename)(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".') : void 0; | ||
var toIndex = allPaths.lastIndexOf(createPath(toLocation)); | ||
if (toIndex === -1) toIndex = 0; | ||
var fromIndex = allPaths.lastIndexOf(createPath(fromLocation)); | ||
if (fromIndex === -1) fromIndex = 0; | ||
var delta = toIndex - fromIndex; | ||
if (basename) path = (0, _PathUtils.stripBasename)(path, basename); | ||
if (delta) { | ||
forceNextPop = true; | ||
go(delta); | ||
} | ||
} // Ensure the hash is encoded properly before doing anything else. | ||
return (0, _LocationUtils.createLocation)(path, state, key); | ||
}; | ||
var createKey = function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength); | ||
}; | ||
var path = getHashPath(); | ||
var encodedPath = encodePath(path); | ||
if (path !== encodedPath) replaceHashPath(encodedPath); | ||
var initialLocation = getDOMLocation(); | ||
var allPaths = [createPath(initialLocation)]; // Public interface | ||
var transitionManager = (0, _createTransitionManager2.default)(); | ||
function createHref(location) { | ||
return "#" + encodePath(basename + createPath(location)); | ||
} | ||
var setState = function setState(nextState) { | ||
_extends(history, nextState); | ||
function push(path, state) { | ||
warning(state === undefined, "Hash history cannot push state; it is ignored"); | ||
var action = "PUSH"; | ||
var location = createLocation(path, undefined, undefined, history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var path = createPath(location); | ||
var encodedPath = encodePath(basename + path); | ||
var hashChanged = getHashPath() !== encodedPath; | ||
history.length = globalHistory.length; | ||
if (hashChanged) { | ||
// We cannot tell if a hashchange was caused by a PUSH, so we'd | ||
// rather setState here and ignore the hashchange. The caveat here | ||
// is that other hash histories in the page will consider it a POP. | ||
ignorePath = path; | ||
pushHashPath(encodedPath); | ||
var prevIndex = allPaths.lastIndexOf(createPath(history.location)); | ||
var nextPaths = allPaths.slice(0, prevIndex === -1 ? 0 : prevIndex + 1); | ||
nextPaths.push(path); | ||
allPaths = nextPaths; | ||
setState({ | ||
action: action, | ||
location: location | ||
}); | ||
} else { | ||
warning(false, "Hash history cannot PUSH the same path; a new entry will not be added to the history stack"); | ||
setState(); | ||
} | ||
}); | ||
} | ||
transitionManager.notifyListeners(history.location, history.action); | ||
}; | ||
function replace(path, state) { | ||
warning(state === undefined, "Hash history cannot replace state; it is ignored"); | ||
var action = "REPLACE"; | ||
var location = createLocation(path, undefined, undefined, history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var path = createPath(location); | ||
var encodedPath = encodePath(basename + path); | ||
var hashChanged = getHashPath() !== encodedPath; | ||
var handlePopState = function handlePopState(event) { | ||
// Ignore extraneous popstate events in WebKit. | ||
if ((0, _DOMUtils.isExtraneousPopstateEvent)(event)) return; | ||
if (hashChanged) { | ||
// We cannot tell if a hashchange was caused by a REPLACE, so we'd | ||
// rather setState here and ignore the hashchange. The caveat here | ||
// is that other hash histories in the page will consider it a POP. | ||
ignorePath = path; | ||
replaceHashPath(encodedPath); | ||
} | ||
handlePop(getDOMLocation(event.state)); | ||
}; | ||
var prevIndex = allPaths.indexOf(createPath(history.location)); | ||
if (prevIndex !== -1) allPaths[prevIndex] = path; | ||
setState({ | ||
action: action, | ||
location: location | ||
}); | ||
}); | ||
} | ||
var handleHashChange = function handleHashChange() { | ||
handlePop(getDOMLocation(getHistoryState())); | ||
}; | ||
function go(n) { | ||
warning(canGoWithoutReload, "Hash history go(n) causes a full page reload in this browser"); | ||
globalHistory.go(n); | ||
} | ||
var forceNextPop = false; | ||
function goBack() { | ||
go(-1); | ||
} | ||
var handlePop = function handlePop(location) { | ||
if (forceNextPop) { | ||
forceNextPop = false; | ||
setState(); | ||
} else { | ||
var action = 'POP'; | ||
function goForward() { | ||
go(1); | ||
} | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ action: action, location: location }); | ||
} else { | ||
revertPop(location); | ||
} | ||
}); | ||
} | ||
}; | ||
var listenerCount = 0; | ||
var revertPop = function revertPop(fromLocation) { | ||
var toLocation = history.location; | ||
function checkDOMListeners(delta) { | ||
listenerCount += delta; | ||
// TODO: We could probably make this more reliable by | ||
// keeping a list of keys we've seen in sessionStorage. | ||
// Instead, we just default to 0 for keys we don't know. | ||
if (listenerCount === 1) { | ||
window.addEventListener(HashChangeEvent$1, handleHashChange); | ||
} else if (listenerCount === 0) { | ||
window.removeEventListener(HashChangeEvent$1, handleHashChange); | ||
} | ||
} | ||
var toIndex = allKeys.indexOf(toLocation.key); | ||
var isBlocked = false; | ||
if (toIndex === -1) toIndex = 0; | ||
function block(prompt) { | ||
if (prompt === void 0) { | ||
prompt = false; | ||
} | ||
var fromIndex = allKeys.indexOf(fromLocation.key); | ||
var unblock = transitionManager.setPrompt(prompt); | ||
if (fromIndex === -1) fromIndex = 0; | ||
if (!isBlocked) { | ||
checkDOMListeners(1); | ||
isBlocked = true; | ||
} | ||
var delta = toIndex - fromIndex; | ||
return function () { | ||
if (isBlocked) { | ||
isBlocked = false; | ||
checkDOMListeners(-1); | ||
} | ||
if (delta) { | ||
forceNextPop = true; | ||
go(delta); | ||
} | ||
}; | ||
return unblock(); | ||
}; | ||
} | ||
var initialLocation = getDOMLocation(getHistoryState()); | ||
var allKeys = [initialLocation.key]; | ||
function listen(listener) { | ||
var unlisten = transitionManager.appendListener(listener); | ||
checkDOMListeners(1); | ||
return function () { | ||
checkDOMListeners(-1); | ||
unlisten(); | ||
}; | ||
} | ||
// Public interface | ||
var history = { | ||
length: globalHistory.length, | ||
action: "POP", | ||
location: initialLocation, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
} | ||
var createHref = function createHref(location) { | ||
return basename + (0, _PathUtils.createPath)(location); | ||
}; | ||
function clamp(n, lowerBound, upperBound) { | ||
return Math.min(Math.max(n, lowerBound), upperBound); | ||
} | ||
/** | ||
* Creates a history object that stores locations in memory. | ||
*/ | ||
var push = function push(path, state) { | ||
false ? (0, _warning2.default)(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to push when the 1st ' + 'argument is a location-like object that already has state; it is ignored') : void 0; | ||
var action = 'PUSH'; | ||
var location = (0, _LocationUtils.createLocation)(path, state, createKey(), history.location); | ||
function createMemoryHistory(props) { | ||
if (props === void 0) { | ||
props = {}; | ||
} | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var _props = props, | ||
getUserConfirmation = _props.getUserConfirmation, | ||
_props$initialEntries = _props.initialEntries, | ||
initialEntries = _props$initialEntries === void 0 ? ["/"] : _props$initialEntries, | ||
_props$initialIndex = _props.initialIndex, | ||
initialIndex = _props$initialIndex === void 0 ? 0 : _props$initialIndex, | ||
_props$keyLength = _props.keyLength, | ||
keyLength = _props$keyLength === void 0 ? 6 : _props$keyLength; | ||
var transitionManager = createTransitionManager(); | ||
var href = createHref(location); | ||
var key = location.key, | ||
state = location.state; | ||
function setState(nextState) { | ||
_extends(history, nextState); | ||
history.length = history.entries.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
} | ||
if (canUseHistory) { | ||
globalHistory.pushState({ key: key, state: state }, null, href); | ||
function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength); | ||
} | ||
if (forceRefresh) { | ||
window.location.href = href; | ||
} else { | ||
var prevIndex = allKeys.indexOf(history.location.key); | ||
var nextKeys = allKeys.slice(0, prevIndex === -1 ? 0 : prevIndex + 1); | ||
var index = clamp(initialIndex, 0, initialEntries.length - 1); | ||
var entries = initialEntries.map(function (entry) { | ||
return typeof entry === "string" ? createLocation(entry, undefined, createKey()) : createLocation(entry, undefined, entry.key || createKey()); | ||
}); // Public interface | ||
nextKeys.push(location.key); | ||
allKeys = nextKeys; | ||
var createHref = createPath; | ||
setState({ action: action, location: location }); | ||
} | ||
} else { | ||
false ? (0, _warning2.default)(state === undefined, 'Browser history cannot push state in browsers that do not support HTML5 history') : void 0; | ||
function push(path, state) { | ||
warning(!(typeof path === "object" && path.state !== undefined && state !== undefined), "You should avoid providing a 2nd state argument to push when the 1st " + "argument is a location-like object that already has state; it is ignored"); | ||
var action = "PUSH"; | ||
var location = createLocation(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var prevIndex = history.index; | ||
var nextIndex = prevIndex + 1; | ||
var nextEntries = history.entries.slice(0); | ||
window.location.href = href; | ||
} | ||
}); | ||
}; | ||
if (nextEntries.length > nextIndex) { | ||
nextEntries.splice(nextIndex, nextEntries.length - nextIndex, location); | ||
} else { | ||
nextEntries.push(location); | ||
} | ||
var replace = function replace(path, state) { | ||
false ? (0, _warning2.default)(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to replace when the 1st ' + 'argument is a location-like object that already has state; it is ignored') : void 0; | ||
setState({ | ||
action: action, | ||
location: location, | ||
index: nextIndex, | ||
entries: nextEntries | ||
}); | ||
}); | ||
} | ||
var action = 'REPLACE'; | ||
var location = (0, _LocationUtils.createLocation)(path, state, createKey(), history.location); | ||
function replace(path, state) { | ||
warning(!(typeof path === "object" && path.state !== undefined && state !== undefined), "You should avoid providing a 2nd state argument to replace when the 1st " + "argument is a location-like object that already has state; it is ignored"); | ||
var action = "REPLACE"; | ||
var location = createLocation(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
history.entries[history.index] = location; | ||
setState({ | ||
action: action, | ||
location: location | ||
}); | ||
}); | ||
} | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
function go(n) { | ||
var nextIndex = clamp(history.index + n, 0, history.entries.length - 1); | ||
var action = "POP"; | ||
var location = history.entries[nextIndex]; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ | ||
action: action, | ||
location: location, | ||
index: nextIndex | ||
}); | ||
} else { | ||
// Mimic the behavior of DOM histories by | ||
// causing a render after a cancelled POP. | ||
setState(); | ||
} | ||
}); | ||
} | ||
var href = createHref(location); | ||
var key = location.key, | ||
state = location.state; | ||
function goBack() { | ||
go(-1); | ||
} | ||
function goForward() { | ||
go(1); | ||
} | ||
if (canUseHistory) { | ||
globalHistory.replaceState({ key: key, state: state }, null, href); | ||
function canGo(n) { | ||
var nextIndex = history.index + n; | ||
return nextIndex >= 0 && nextIndex < history.entries.length; | ||
} | ||
if (forceRefresh) { | ||
window.location.replace(href); | ||
} else { | ||
var prevIndex = allKeys.indexOf(history.location.key); | ||
function block(prompt) { | ||
if (prompt === void 0) { | ||
prompt = false; | ||
} | ||
if (prevIndex !== -1) allKeys[prevIndex] = location.key; | ||
return transitionManager.setPrompt(prompt); | ||
} | ||
setState({ action: action, location: location }); | ||
} | ||
} else { | ||
false ? (0, _warning2.default)(state === undefined, 'Browser history cannot replace state in browsers that do not support HTML5 history') : void 0; | ||
function listen(listener) { | ||
return transitionManager.appendListener(listener); | ||
} | ||
window.location.replace(href); | ||
} | ||
}); | ||
}; | ||
var history = { | ||
length: entries.length, | ||
action: "POP", | ||
location: entries[index], | ||
index: index, | ||
entries: entries, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
canGo: canGo, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
} | ||
var go = function go(n) { | ||
globalHistory.go(n); | ||
}; | ||
exports.createBrowserHistory = createBrowserHistory; | ||
exports.createHashHistory = createHashHistory; | ||
exports.createMemoryHistory = createMemoryHistory; | ||
exports.createLocation = createLocation; | ||
exports.locationsAreEqual = locationsAreEqual; | ||
exports.parsePath = parsePath; | ||
exports.createPath = createPath; | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
var listenerCount = 0; | ||
var checkDOMListeners = function checkDOMListeners(delta) { | ||
listenerCount += delta; | ||
if (listenerCount === 1) { | ||
(0, _DOMUtils.addEventListener)(window, PopStateEvent, handlePopState); | ||
if (needsHashChangeListener) (0, _DOMUtils.addEventListener)(window, HashChangeEvent, handleHashChange); | ||
} else if (listenerCount === 0) { | ||
(0, _DOMUtils.removeEventListener)(window, PopStateEvent, handlePopState); | ||
if (needsHashChangeListener) (0, _DOMUtils.removeEventListener)(window, HashChangeEvent, handleHashChange); | ||
} | ||
}; | ||
var isBlocked = false; | ||
var block = function block() { | ||
var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
var unblock = transitionManager.setPrompt(prompt); | ||
if (!isBlocked) { | ||
checkDOMListeners(1); | ||
isBlocked = true; | ||
} | ||
return function () { | ||
if (isBlocked) { | ||
isBlocked = false; | ||
checkDOMListeners(-1); | ||
} | ||
return unblock(); | ||
}; | ||
}; | ||
var listen = function listen(listener) { | ||
var unlisten = transitionManager.appendListener(listener); | ||
checkDOMListeners(1); | ||
return function () { | ||
checkDOMListeners(-1); | ||
unlisten(); | ||
}; | ||
}; | ||
var history = { | ||
length: globalHistory.length, | ||
action: 'POP', | ||
location: initialLocation, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
}; | ||
exports.default = createBrowserHistory; | ||
/***/ }, | ||
/* 6 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/** | ||
* Copyright 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
/** | ||
* Similar to invariant but only logs a warning if the condition is not met. | ||
* This can be used to log issues in development environments in critical | ||
* paths. Removing the logging code for production environments will keep the | ||
* same logic and follow the same code paths. | ||
*/ | ||
var warning = function() {}; | ||
if (false) { | ||
warning = function(condition, format, args) { | ||
var len = arguments.length; | ||
args = new Array(len > 2 ? len - 2 : 0); | ||
for (var key = 2; key < len; key++) { | ||
args[key - 2] = arguments[key]; | ||
} | ||
if (format === undefined) { | ||
throw new Error( | ||
'`warning(condition, format, ...args)` requires a warning ' + | ||
'message argument' | ||
); | ||
} | ||
if (format.length < 10 || (/^[s\W]*$/).test(format)) { | ||
throw new Error( | ||
'The warning format should be able to uniquely identify this ' + | ||
'warning. Please, use a more descriptive format than: ' + format | ||
); | ||
} | ||
if (!condition) { | ||
var argIndex = 0; | ||
var message = 'Warning: ' + | ||
format.replace(/%s/g, function() { | ||
return args[argIndex++]; | ||
}); | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
try { | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch(x) {} | ||
} | ||
}; | ||
} | ||
module.exports = warning; | ||
/***/ }, | ||
/* 7 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/** | ||
* Copyright 2013-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
/** | ||
* Use invariant() to assert state which your program assumes to be true. | ||
* | ||
* Provide sprintf-style format (only %s is supported) and arguments | ||
* to provide information about what broke and what you were | ||
* expecting. | ||
* | ||
* The invariant message will be stripped in production, but the invariant | ||
* will remain to ensure logic does not differ in production. | ||
*/ | ||
var invariant = function(condition, format, a, b, c, d, e, f) { | ||
if (false) { | ||
if (format === undefined) { | ||
throw new Error('invariant requires an error message argument'); | ||
} | ||
} | ||
if (!condition) { | ||
var error; | ||
if (format === undefined) { | ||
error = new Error( | ||
'Minified exception occurred; use the non-minified dev environment ' + | ||
'for the full error message and additional helpful warnings.' | ||
); | ||
} else { | ||
var args = [a, b, c, d, e, f]; | ||
var argIndex = 0; | ||
error = new Error( | ||
format.replace(/%s/g, function() { return args[argIndex++]; }) | ||
); | ||
error.name = 'Invariant Violation'; | ||
} | ||
error.framesToPop = 1; // we don't care about invariant's own frame | ||
throw error; | ||
} | ||
}; | ||
module.exports = invariant; | ||
/***/ }, | ||
/* 8 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
exports.__esModule = true; | ||
var _warning = __webpack_require__(6); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var createTransitionManager = function createTransitionManager() { | ||
var prompt = null; | ||
var setPrompt = function setPrompt(nextPrompt) { | ||
false ? (0, _warning2.default)(prompt == null, 'A history supports only one prompt at a time') : void 0; | ||
prompt = nextPrompt; | ||
return function () { | ||
if (prompt === nextPrompt) prompt = null; | ||
}; | ||
}; | ||
var confirmTransitionTo = function confirmTransitionTo(location, action, getUserConfirmation, callback) { | ||
// TODO: If another transition starts while we're still confirming | ||
// the previous one, we may end up in a weird state. Figure out the | ||
// best way to handle this. | ||
if (prompt != null) { | ||
var result = typeof prompt === 'function' ? prompt(location, action) : prompt; | ||
if (typeof result === 'string') { | ||
if (typeof getUserConfirmation === 'function') { | ||
getUserConfirmation(result, callback); | ||
} else { | ||
false ? (0, _warning2.default)(false, 'A history needs a getUserConfirmation function in order to use a prompt message') : void 0; | ||
callback(true); | ||
} | ||
} else { | ||
// Return false from a transition hook to cancel the transition. | ||
callback(result !== false); | ||
} | ||
} else { | ||
callback(true); | ||
} | ||
}; | ||
var listeners = []; | ||
var appendListener = function appendListener(fn) { | ||
var isActive = true; | ||
var listener = function listener() { | ||
if (isActive) fn.apply(undefined, arguments); | ||
}; | ||
listeners.push(listener); | ||
return function () { | ||
isActive = false; | ||
listeners = listeners.filter(function (item) { | ||
return item !== listener; | ||
}); | ||
}; | ||
}; | ||
var notifyListeners = function notifyListeners() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
listeners.forEach(function (listener) { | ||
return listener.apply(undefined, args); | ||
}); | ||
}; | ||
return { | ||
setPrompt: setPrompt, | ||
confirmTransitionTo: confirmTransitionTo, | ||
appendListener: appendListener, | ||
notifyListeners: notifyListeners | ||
}; | ||
}; | ||
exports.default = createTransitionManager; | ||
/***/ }, | ||
/* 9 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
exports.__esModule = true; | ||
var canUseDOM = exports.canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
var addEventListener = exports.addEventListener = function addEventListener(node, event, listener) { | ||
return node.addEventListener ? node.addEventListener(event, listener, false) : 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); | ||
}; | ||
var getConfirmation = exports.getConfirmation = function getConfirmation(message, callback) { | ||
return callback(window.confirm(message)); | ||
}; // eslint-disable-line no-alert | ||
/** | ||
* Returns true if the HTML5 history API is supported. Taken from Modernizr. | ||
* | ||
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE | ||
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js | ||
* changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586 | ||
*/ | ||
var supportsHistory = exports.supportsHistory = function supportsHistory() { | ||
var ua = window.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; | ||
return window.history && 'pushState' in window.history; | ||
}; | ||
/** | ||
* Returns true if browser fires popstate on hash change. | ||
* IE10 and IE11 do not. | ||
*/ | ||
var supportsPopStateOnHashChange = exports.supportsPopStateOnHashChange = function supportsPopStateOnHashChange() { | ||
return window.navigator.userAgent.indexOf('Trident') === -1; | ||
}; | ||
/** | ||
* Returns false if using go(n) with hash history causes a full page reload. | ||
*/ | ||
var supportsGoWithoutReloadUsingHash = exports.supportsGoWithoutReloadUsingHash = function supportsGoWithoutReloadUsingHash() { | ||
return window.navigator.userAgent.indexOf('Firefox') === -1; | ||
}; | ||
/** | ||
* Returns true if a given popstate event is an extraneous WebKit event. | ||
* Accounts for the fact that Chrome on iOS fires real popstate events | ||
* containing undefined state when pressing the back button. | ||
*/ | ||
var isExtraneousPopstateEvent = exports.isExtraneousPopstateEvent = function isExtraneousPopstateEvent(event) { | ||
return event.state === undefined && navigator.userAgent.indexOf('CriOS') === -1; | ||
}; | ||
/***/ }, | ||
/* 10 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
exports.__esModule = true; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _warning = __webpack_require__(6); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var _invariant = __webpack_require__(7); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _LocationUtils = __webpack_require__(1); | ||
var _PathUtils = __webpack_require__(4); | ||
var _createTransitionManager = __webpack_require__(8); | ||
var _createTransitionManager2 = _interopRequireDefault(_createTransitionManager); | ||
var _DOMUtils = __webpack_require__(9); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var HashChangeEvent = 'hashchange'; | ||
var HashPathCoders = { | ||
hashbang: { | ||
encodePath: function encodePath(path) { | ||
return path.charAt(0) === '!' ? path : '!/' + (0, _PathUtils.stripLeadingSlash)(path); | ||
}, | ||
decodePath: function decodePath(path) { | ||
return path.charAt(0) === '!' ? path.substr(1) : path; | ||
} | ||
}, | ||
noslash: { | ||
encodePath: _PathUtils.stripLeadingSlash, | ||
decodePath: _PathUtils.addLeadingSlash | ||
}, | ||
slash: { | ||
encodePath: _PathUtils.addLeadingSlash, | ||
decodePath: _PathUtils.addLeadingSlash | ||
} | ||
}; | ||
var getHashPath = function getHashPath() { | ||
// We can't use window.location.hash here because it's not | ||
// consistent across browsers - Firefox will pre-decode it! | ||
var href = window.location.href; | ||
var hashIndex = href.indexOf('#'); | ||
return hashIndex === -1 ? '' : href.substring(hashIndex + 1); | ||
}; | ||
var pushHashPath = function pushHashPath(path) { | ||
return window.location.hash = path; | ||
}; | ||
var replaceHashPath = function replaceHashPath(path) { | ||
var hashIndex = window.location.href.indexOf('#'); | ||
window.location.replace(window.location.href.slice(0, hashIndex >= 0 ? hashIndex : 0) + '#' + path); | ||
}; | ||
var createHashHistory = function createHashHistory() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
!_DOMUtils.canUseDOM ? false ? (0, _invariant2.default)(false, 'Hash history needs a DOM') : (0, _invariant2.default)(false) : void 0; | ||
var globalHistory = window.history; | ||
var canGoWithoutReload = (0, _DOMUtils.supportsGoWithoutReloadUsingHash)(); | ||
var _props$getUserConfirm = props.getUserConfirmation, | ||
getUserConfirmation = _props$getUserConfirm === undefined ? _DOMUtils.getConfirmation : _props$getUserConfirm, | ||
_props$hashType = props.hashType, | ||
hashType = _props$hashType === undefined ? 'slash' : _props$hashType; | ||
var basename = props.basename ? (0, _PathUtils.stripTrailingSlash)((0, _PathUtils.addLeadingSlash)(props.basename)) : ''; | ||
var _HashPathCoders$hashT = HashPathCoders[hashType], | ||
encodePath = _HashPathCoders$hashT.encodePath, | ||
decodePath = _HashPathCoders$hashT.decodePath; | ||
var getDOMLocation = function getDOMLocation() { | ||
var path = decodePath(getHashPath()); | ||
false ? (0, _warning2.default)(!basename || (0, _PathUtils.hasBasename)(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".') : void 0; | ||
if (basename) path = (0, _PathUtils.stripBasename)(path, basename); | ||
return (0, _LocationUtils.createLocation)(path); | ||
}; | ||
var transitionManager = (0, _createTransitionManager2.default)(); | ||
var setState = function setState(nextState) { | ||
_extends(history, nextState); | ||
history.length = globalHistory.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
}; | ||
var forceNextPop = false; | ||
var ignorePath = null; | ||
var handleHashChange = function handleHashChange() { | ||
var path = getHashPath(); | ||
var encodedPath = encodePath(path); | ||
if (path !== encodedPath) { | ||
// Ensure we always have a properly-encoded hash. | ||
replaceHashPath(encodedPath); | ||
} else { | ||
var location = getDOMLocation(); | ||
var prevLocation = history.location; | ||
if (!forceNextPop && (0, _LocationUtils.locationsAreEqual)(prevLocation, location)) return; // A hashchange doesn't always == location change. | ||
if (ignorePath === (0, _PathUtils.createPath)(location)) return; // Ignore this change; we already setState in push/replace. | ||
ignorePath = null; | ||
handlePop(location); | ||
} | ||
}; | ||
var handlePop = function handlePop(location) { | ||
if (forceNextPop) { | ||
forceNextPop = false; | ||
setState(); | ||
} else { | ||
var action = 'POP'; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ action: action, location: location }); | ||
} else { | ||
revertPop(location); | ||
} | ||
}); | ||
} | ||
}; | ||
var revertPop = function revertPop(fromLocation) { | ||
var toLocation = history.location; | ||
// TODO: We could probably make this more reliable by | ||
// keeping a list of paths we've seen in sessionStorage. | ||
// Instead, we just default to 0 for paths we don't know. | ||
var toIndex = allPaths.lastIndexOf((0, _PathUtils.createPath)(toLocation)); | ||
if (toIndex === -1) toIndex = 0; | ||
var fromIndex = allPaths.lastIndexOf((0, _PathUtils.createPath)(fromLocation)); | ||
if (fromIndex === -1) fromIndex = 0; | ||
var delta = toIndex - fromIndex; | ||
if (delta) { | ||
forceNextPop = true; | ||
go(delta); | ||
} | ||
}; | ||
// Ensure the hash is encoded properly before doing anything else. | ||
var path = getHashPath(); | ||
var encodedPath = encodePath(path); | ||
if (path !== encodedPath) replaceHashPath(encodedPath); | ||
var initialLocation = getDOMLocation(); | ||
var allPaths = [(0, _PathUtils.createPath)(initialLocation)]; | ||
// Public interface | ||
var createHref = function createHref(location) { | ||
return '#' + encodePath(basename + (0, _PathUtils.createPath)(location)); | ||
}; | ||
var push = function push(path, state) { | ||
false ? (0, _warning2.default)(state === undefined, 'Hash history cannot push state; it is ignored') : void 0; | ||
var action = 'PUSH'; | ||
var location = (0, _LocationUtils.createLocation)(path, undefined, undefined, history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var path = (0, _PathUtils.createPath)(location); | ||
var encodedPath = encodePath(basename + path); | ||
var hashChanged = getHashPath() !== encodedPath; | ||
if (hashChanged) { | ||
// We cannot tell if a hashchange was caused by a PUSH, so we'd | ||
// rather setState here and ignore the hashchange. The caveat here | ||
// is that other hash histories in the page will consider it a POP. | ||
ignorePath = path; | ||
pushHashPath(encodedPath); | ||
var prevIndex = allPaths.lastIndexOf((0, _PathUtils.createPath)(history.location)); | ||
var nextPaths = allPaths.slice(0, prevIndex === -1 ? 0 : prevIndex + 1); | ||
nextPaths.push(path); | ||
allPaths = nextPaths; | ||
setState({ action: action, location: location }); | ||
} else { | ||
false ? (0, _warning2.default)(false, 'Hash history cannot PUSH the same path; a new entry will not be added to the history stack') : void 0; | ||
setState(); | ||
} | ||
}); | ||
}; | ||
var replace = function replace(path, state) { | ||
false ? (0, _warning2.default)(state === undefined, 'Hash history cannot replace state; it is ignored') : void 0; | ||
var action = 'REPLACE'; | ||
var location = (0, _LocationUtils.createLocation)(path, undefined, undefined, history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var path = (0, _PathUtils.createPath)(location); | ||
var encodedPath = encodePath(basename + path); | ||
var hashChanged = getHashPath() !== encodedPath; | ||
if (hashChanged) { | ||
// We cannot tell if a hashchange was caused by a REPLACE, so we'd | ||
// rather setState here and ignore the hashchange. The caveat here | ||
// is that other hash histories in the page will consider it a POP. | ||
ignorePath = path; | ||
replaceHashPath(encodedPath); | ||
} | ||
var prevIndex = allPaths.indexOf((0, _PathUtils.createPath)(history.location)); | ||
if (prevIndex !== -1) allPaths[prevIndex] = path; | ||
setState({ action: action, location: location }); | ||
}); | ||
}; | ||
var go = function go(n) { | ||
false ? (0, _warning2.default)(canGoWithoutReload, 'Hash history go(n) causes a full page reload in this browser') : void 0; | ||
globalHistory.go(n); | ||
}; | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
var listenerCount = 0; | ||
var checkDOMListeners = function checkDOMListeners(delta) { | ||
listenerCount += delta; | ||
if (listenerCount === 1) { | ||
(0, _DOMUtils.addEventListener)(window, HashChangeEvent, handleHashChange); | ||
} else if (listenerCount === 0) { | ||
(0, _DOMUtils.removeEventListener)(window, HashChangeEvent, handleHashChange); | ||
} | ||
}; | ||
var isBlocked = false; | ||
var block = function block() { | ||
var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
var unblock = transitionManager.setPrompt(prompt); | ||
if (!isBlocked) { | ||
checkDOMListeners(1); | ||
isBlocked = true; | ||
} | ||
return function () { | ||
if (isBlocked) { | ||
isBlocked = false; | ||
checkDOMListeners(-1); | ||
} | ||
return unblock(); | ||
}; | ||
}; | ||
var listen = function listen(listener) { | ||
var unlisten = transitionManager.appendListener(listener); | ||
checkDOMListeners(1); | ||
return function () { | ||
checkDOMListeners(-1); | ||
unlisten(); | ||
}; | ||
}; | ||
var history = { | ||
length: globalHistory.length, | ||
action: 'POP', | ||
location: initialLocation, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
}; | ||
exports.default = createHashHistory; | ||
/***/ }, | ||
/* 11 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
exports.__esModule = true; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
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; }; | ||
var _warning = __webpack_require__(6); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var _PathUtils = __webpack_require__(4); | ||
var _LocationUtils = __webpack_require__(1); | ||
var _createTransitionManager = __webpack_require__(8); | ||
var _createTransitionManager2 = _interopRequireDefault(_createTransitionManager); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var clamp = function clamp(n, lowerBound, upperBound) { | ||
return Math.min(Math.max(n, lowerBound), upperBound); | ||
}; | ||
/** | ||
* Creates a history object that stores locations in memory. | ||
*/ | ||
var createMemoryHistory = function createMemoryHistory() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var getUserConfirmation = props.getUserConfirmation, | ||
_props$initialEntries = props.initialEntries, | ||
initialEntries = _props$initialEntries === undefined ? ['/'] : _props$initialEntries, | ||
_props$initialIndex = props.initialIndex, | ||
initialIndex = _props$initialIndex === undefined ? 0 : _props$initialIndex, | ||
_props$keyLength = props.keyLength, | ||
keyLength = _props$keyLength === undefined ? 6 : _props$keyLength; | ||
var transitionManager = (0, _createTransitionManager2.default)(); | ||
var setState = function setState(nextState) { | ||
_extends(history, nextState); | ||
history.length = history.entries.length; | ||
transitionManager.notifyListeners(history.location, history.action); | ||
}; | ||
var createKey = function createKey() { | ||
return Math.random().toString(36).substr(2, keyLength); | ||
}; | ||
var index = clamp(initialIndex, 0, initialEntries.length - 1); | ||
var entries = initialEntries.map(function (entry) { | ||
return typeof entry === 'string' ? (0, _LocationUtils.createLocation)(entry, undefined, createKey()) : (0, _LocationUtils.createLocation)(entry, undefined, entry.key || createKey()); | ||
}); | ||
// Public interface | ||
var createHref = _PathUtils.createPath; | ||
var push = function push(path, state) { | ||
false ? (0, _warning2.default)(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to push when the 1st ' + 'argument is a location-like object that already has state; it is ignored') : void 0; | ||
var action = 'PUSH'; | ||
var location = (0, _LocationUtils.createLocation)(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
var prevIndex = history.index; | ||
var nextIndex = prevIndex + 1; | ||
var nextEntries = history.entries.slice(0); | ||
if (nextEntries.length > nextIndex) { | ||
nextEntries.splice(nextIndex, nextEntries.length - nextIndex, location); | ||
} else { | ||
nextEntries.push(location); | ||
} | ||
setState({ | ||
action: action, | ||
location: location, | ||
index: nextIndex, | ||
entries: nextEntries | ||
}); | ||
}); | ||
}; | ||
var replace = function replace(path, state) { | ||
false ? (0, _warning2.default)(!((typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to replace when the 1st ' + 'argument is a location-like object that already has state; it is ignored') : void 0; | ||
var action = 'REPLACE'; | ||
var location = (0, _LocationUtils.createLocation)(path, state, createKey(), history.location); | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (!ok) return; | ||
history.entries[history.index] = location; | ||
setState({ action: action, location: location }); | ||
}); | ||
}; | ||
var go = function go(n) { | ||
var nextIndex = clamp(history.index + n, 0, history.entries.length - 1); | ||
var action = 'POP'; | ||
var location = history.entries[nextIndex]; | ||
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) { | ||
if (ok) { | ||
setState({ | ||
action: action, | ||
location: location, | ||
index: nextIndex | ||
}); | ||
} else { | ||
// Mimic the behavior of DOM histories by | ||
// causing a render after a cancelled POP. | ||
setState(); | ||
} | ||
}); | ||
}; | ||
var goBack = function goBack() { | ||
return go(-1); | ||
}; | ||
var goForward = function goForward() { | ||
return go(1); | ||
}; | ||
var canGo = function canGo(n) { | ||
var nextIndex = history.index + n; | ||
return nextIndex >= 0 && nextIndex < history.entries.length; | ||
}; | ||
var block = function block() { | ||
var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
return transitionManager.setPrompt(prompt); | ||
}; | ||
var listen = function listen(listener) { | ||
return transitionManager.appendListener(listener); | ||
}; | ||
var history = { | ||
length: entries.length, | ||
action: 'POP', | ||
location: entries[index], | ||
index: index, | ||
entries: entries, | ||
createHref: createHref, | ||
push: push, | ||
replace: replace, | ||
go: go, | ||
goBack: goBack, | ||
goForward: goForward, | ||
canGo: canGo, | ||
block: block, | ||
listen: listen | ||
}; | ||
return history; | ||
}; | ||
exports.default = createMemoryHistory; | ||
/***/ } | ||
/******/ ]) | ||
}); | ||
; | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.History=n():t.History=n()}(this,function(){return function(t){function n(o){if(e[o])return e[o].exports;var r=e[o]={exports:{},id:o,loaded:!1};return t[o].call(r.exports,r,r.exports,n),r.loaded=!0,r.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n,e){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}n.__esModule=!0,n.createPath=n.parsePath=n.locationsAreEqual=n.createLocation=n.createMemoryHistory=n.createHashHistory=n.createBrowserHistory=void 0;var r=e(2);Object.defineProperty(n,"createLocation",{enumerable:!0,get:function(){return r.createLocation}}),Object.defineProperty(n,"locationsAreEqual",{enumerable:!0,get:function(){return r.locationsAreEqual}});var i=e(1);Object.defineProperty(n,"parsePath",{enumerable:!0,get:function(){return i.parsePath}}),Object.defineProperty(n,"createPath",{enumerable:!0,get:function(){return i.createPath}});var a=e(7),c=o(a),u=e(8),s=o(u),f=e(9),l=o(f);n.createBrowserHistory=c.default,n.createHashHistory=s.default,n.createMemoryHistory=l.default},function(t,n){"use strict";n.__esModule=!0;var e=(n.addLeadingSlash=function(t){return"/"===t.charAt(0)?t:"/"+t},n.stripLeadingSlash=function(t){return"/"===t.charAt(0)?t.substr(1):t},n.hasBasename=function(t,n){return new RegExp("^"+n+"(\\/|\\?|#|$)","i").test(t)});n.stripBasename=function(t,n){return e(t,n)?t.substr(n.length):t},n.stripTrailingSlash=function(t){return"/"===t.charAt(t.length-1)?t.slice(0,-1):t},n.parsePath=function(t){var n=t||"/",e="",o="",r=n.indexOf("#");r!==-1&&(o=n.substr(r),n=n.substr(0,r));var i=n.indexOf("?");return i!==-1&&(e=n.substr(i),n=n.substr(0,i)),{pathname:n,search:"?"===e?"":e,hash:"#"===o?"":o}},n.createPath=function(t){var n=t.pathname,e=t.search,o=t.hash,r=n||"/";return e&&"?"!==e&&(r+="?"===e.charAt(0)?e:"?"+e),o&&"#"!==o&&(r+="#"===o.charAt(0)?o:"#"+o),r}},function(t,n,e){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}n.__esModule=!0,n.locationsAreEqual=n.createLocation=void 0;var r=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},i=e(10),a=o(i),c=e(11),u=o(c),s=e(1);n.createLocation=function(t,n,e,o){var i=void 0;"string"==typeof t?(i=(0,s.parsePath)(t),i.state=n):(i=r({},t),void 0===i.pathname&&(i.pathname=""),i.search?"?"!==i.search.charAt(0)&&(i.search="?"+i.search):i.search="",i.hash?"#"!==i.hash.charAt(0)&&(i.hash="#"+i.hash):i.hash="",void 0!==n&&void 0===i.state&&(i.state=n));try{i.pathname=decodeURI(i.pathname)}catch(t){throw t instanceof URIError?new URIError('Pathname "'+i.pathname+'" could not be decoded. This is likely caused by an invalid percent-encoding.'):t}return e&&(i.key=e),o?i.pathname?"/"!==i.pathname.charAt(0)&&(i.pathname=(0,a.default)(i.pathname,o.pathname)):i.pathname=o.pathname:i.pathname||(i.pathname="/"),i},n.locationsAreEqual=function(t,n){return t.pathname===n.pathname&&t.search===n.search&&t.hash===n.hash&&t.key===n.key&&(0,u.default)(t.state,n.state)}},function(t,n,e){"use strict";var o=function(){};t.exports=o},function(t,n,e){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}n.__esModule=!0;var r=e(3),i=(o(r),function(){var t=null,n=function(n){return t=n,function(){t===n&&(t=null)}},e=function(n,e,o,r){if(null!=t){var i="function"==typeof t?t(n,e):t;"string"==typeof i?"function"==typeof o?o(i,r):r(!0):r(i!==!1)}else r(!0)},o=[],r=function(t){var n=!0,e=function(){n&&t.apply(void 0,arguments)};return o.push(e),function(){n=!1,o=o.filter(function(t){return t!==e})}},i=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];o.forEach(function(t){return t.apply(void 0,n)})};return{setPrompt:n,confirmTransitionTo:e,appendListener:r,notifyListeners:i}});n.default=i},function(t,n){"use strict";n.__esModule=!0;n.canUseDOM=!("undefined"==typeof window||!window.document||!window.document.createElement),n.addEventListener=function(t,n,e){return t.addEventListener?t.addEventListener(n,e,!1):t.attachEvent("on"+n,e)},n.removeEventListener=function(t,n,e){return t.removeEventListener?t.removeEventListener(n,e,!1):t.detachEvent("on"+n,e)},n.getConfirmation=function(t,n){return n(window.confirm(t))},n.supportsHistory=function(){var t=window.navigator.userAgent;return(t.indexOf("Android 2.")===-1&&t.indexOf("Android 4.0")===-1||t.indexOf("Mobile Safari")===-1||t.indexOf("Chrome")!==-1||t.indexOf("Windows Phone")!==-1)&&(window.history&&"pushState"in window.history)},n.supportsPopStateOnHashChange=function(){return window.navigator.userAgent.indexOf("Trident")===-1},n.supportsGoWithoutReloadUsingHash=function(){return window.navigator.userAgent.indexOf("Firefox")===-1},n.isExtraneousPopstateEvent=function(t){return void 0===t.state&&navigator.userAgent.indexOf("CriOS")===-1}},function(t,n,e){"use strict";var o=function(t,n,e,o,r,i,a,c){if(!t){var u;if(void 0===n)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[e,o,r,i,a,c],f=0;u=new Error(n.replace(/%s/g,function(){return s[f++]})),u.name="Invariant Violation"}throw u.framesToPop=1,u}};t.exports=o},function(t,n,e){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}n.__esModule=!0;var r=("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t}),i=e(3),a=(o(i),e(6)),c=o(a),u=e(2),s=e(1),f=e(4),l=o(f),d=e(5),h="popstate",p="hashchange",v=function(){try{return window.history.state||{}}catch(t){return{}}},y=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};d.canUseDOM?void 0:(0,c.default)(!1);var n=window.history,e=(0,d.supportsHistory)(),o=!(0,d.supportsPopStateOnHashChange)(),i=t.forceRefresh,a=void 0!==i&&i,f=t.getUserConfirmation,y=void 0===f?d.getConfirmation:f,g=t.keyLength,m=void 0===g?6:g,w=t.basename?(0,s.stripTrailingSlash)((0,s.addLeadingSlash)(t.basename)):"",b=function(t){var n=t||{},e=n.key,o=n.state,r=window.location,i=r.pathname,a=r.search,c=r.hash,f=i+a+c;return w&&(f=(0,s.stripBasename)(f,w)),(0,u.createLocation)(f,o,e)},P=function(){return Math.random().toString(36).substr(2,m)},O=(0,l.default)(),L=function(t){r(G,t),G.length=n.length,O.notifyListeners(G.location,G.action)},x=function(t){(0,d.isExtraneousPopstateEvent)(t)||_(b(t.state))},S=function(){_(b(v()))},E=!1,_=function(t){if(E)E=!1,L();else{var n="POP";O.confirmTransitionTo(t,n,y,function(e){e?L({action:n,location:t}):A(t)})}},A=function(t){var n=G.location,e=M.indexOf(n.key);e===-1&&(e=0);var o=M.indexOf(t.key);o===-1&&(o=0);var r=e-o;r&&(E=!0,U(r))},k=b(v()),M=[k.key],T=function(t){return w+(0,s.createPath)(t)},H=function(t,o){var r="PUSH",i=(0,u.createLocation)(t,o,P(),G.location);O.confirmTransitionTo(i,r,y,function(t){if(t){var o=T(i),c=i.key,u=i.state;if(e)if(n.pushState({key:c,state:u},null,o),a)window.location.href=o;else{var s=M.indexOf(G.location.key),f=M.slice(0,s===-1?0:s+1);f.push(i.key),M=f,L({action:r,location:i})}else window.location.href=o}})},j=function(t,o){var r="REPLACE",i=(0,u.createLocation)(t,o,P(),G.location);O.confirmTransitionTo(i,r,y,function(t){if(t){var o=T(i),c=i.key,u=i.state;if(e)if(n.replaceState({key:c,state:u},null,o),a)window.location.replace(o);else{var s=M.indexOf(G.location.key);s!==-1&&(M[s]=i.key),L({action:r,location:i})}else window.location.replace(o)}})},U=function(t){n.go(t)},C=function(){return U(-1)},R=function(){return U(1)},B=0,I=function(t){B+=t,1===B?((0,d.addEventListener)(window,h,x),o&&(0,d.addEventListener)(window,p,S)):0===B&&((0,d.removeEventListener)(window,h,x),o&&(0,d.removeEventListener)(window,p,S))},q=!1,F=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=O.setPrompt(t);return q||(I(1),q=!0),function(){return q&&(q=!1,I(-1)),n()}},D=function(t){var n=O.appendListener(t);return I(1),function(){I(-1),n()}},G={length:n.length,action:"POP",location:k,createHref:T,push:H,replace:j,go:U,goBack:C,goForward:R,block:F,listen:D};return G};n.default=y},function(t,n,e){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}n.__esModule=!0;var r=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},i=e(3),a=(o(i),e(6)),c=o(a),u=e(2),s=e(1),f=e(4),l=o(f),d=e(5),h="hashchange",p={hashbang:{encodePath:function(t){return"!"===t.charAt(0)?t:"!/"+(0,s.stripLeadingSlash)(t)},decodePath:function(t){return"!"===t.charAt(0)?t.substr(1):t}},noslash:{encodePath:s.stripLeadingSlash,decodePath:s.addLeadingSlash},slash:{encodePath:s.addLeadingSlash,decodePath:s.addLeadingSlash}},v=function(){var t=window.location.href,n=t.indexOf("#");return n===-1?"":t.substring(n+1)},y=function(t){return window.location.hash=t},g=function(t){var n=window.location.href.indexOf("#");window.location.replace(window.location.href.slice(0,n>=0?n:0)+"#"+t)},m=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};d.canUseDOM?void 0:(0,c.default)(!1);var n=window.history,e=((0,d.supportsGoWithoutReloadUsingHash)(),t.getUserConfirmation),o=void 0===e?d.getConfirmation:e,i=t.hashType,a=void 0===i?"slash":i,f=t.basename?(0,s.stripTrailingSlash)((0,s.addLeadingSlash)(t.basename)):"",m=p[a],w=m.encodePath,b=m.decodePath,P=function(){var t=b(v());return f&&(t=(0,s.stripBasename)(t,f)),(0,u.createLocation)(t)},O=(0,l.default)(),L=function(t){r(V,t),V.length=n.length,O.notifyListeners(V.location,V.action)},x=!1,S=null,E=function(){var t=v(),n=w(t);if(t!==n)g(n);else{var e=P(),o=V.location;if(!x&&(0,u.locationsAreEqual)(o,e))return;if(S===(0,s.createPath)(e))return;S=null,_(e)}},_=function(t){if(x)x=!1,L();else{var n="POP";O.confirmTransitionTo(t,n,o,function(e){e?L({action:n,location:t}):A(t)})}},A=function(t){var n=V.location,e=H.lastIndexOf((0,s.createPath)(n));e===-1&&(e=0);var o=H.lastIndexOf((0,s.createPath)(t));o===-1&&(o=0);var r=e-o;r&&(x=!0,R(r))},k=v(),M=w(k);k!==M&&g(M);var T=P(),H=[(0,s.createPath)(T)],j=function(t){return"#"+w(f+(0,s.createPath)(t))},U=function(t,n){var e="PUSH",r=(0,u.createLocation)(t,void 0,void 0,V.location);O.confirmTransitionTo(r,e,o,function(t){if(t){var n=(0,s.createPath)(r),o=w(f+n),i=v()!==o;if(i){S=n,y(o);var a=H.lastIndexOf((0,s.createPath)(V.location)),c=H.slice(0,a===-1?0:a+1);c.push(n),H=c,L({action:e,location:r})}else L()}})},C=function(t,n){var e="REPLACE",r=(0,u.createLocation)(t,void 0,void 0,V.location);O.confirmTransitionTo(r,e,o,function(t){if(t){var n=(0,s.createPath)(r),o=w(f+n),i=v()!==o;i&&(S=n,g(o));var a=H.indexOf((0,s.createPath)(V.location));a!==-1&&(H[a]=n),L({action:e,location:r})}})},R=function(t){n.go(t)},B=function(){return R(-1)},I=function(){return R(1)},q=0,F=function(t){q+=t,1===q?(0,d.addEventListener)(window,h,E):0===q&&(0,d.removeEventListener)(window,h,E)},D=!1,G=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=O.setPrompt(t);return D||(F(1),D=!0),function(){return D&&(D=!1,F(-1)),n()}},W=function(t){var n=O.appendListener(t);return F(1),function(){F(-1),n()}},V={length:n.length,action:"POP",location:T,createHref:j,push:U,replace:C,go:R,goBack:B,goForward:I,block:G,listen:W};return V};n.default=m},function(t,n,e){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}n.__esModule=!0;var r=("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t}),i=e(3),a=(o(i),e(1)),c=e(2),u=e(4),s=o(u),f=function(t,n,e){return Math.min(Math.max(t,n),e)},l=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.getUserConfirmation,e=t.initialEntries,o=void 0===e?["/"]:e,i=t.initialIndex,u=void 0===i?0:i,l=t.keyLength,d=void 0===l?6:l,h=(0,s.default)(),p=function(t){r(_,t),_.length=_.entries.length,h.notifyListeners(_.location,_.action)},v=function(){return Math.random().toString(36).substr(2,d)},y=f(u,0,o.length-1),g=o.map(function(t){return"string"==typeof t?(0,c.createLocation)(t,void 0,v()):(0,c.createLocation)(t,void 0,t.key||v())}),m=a.createPath,w=function(t,e){var o="PUSH",r=(0,c.createLocation)(t,e,v(),_.location);h.confirmTransitionTo(r,o,n,function(t){if(t){var n=_.index,e=n+1,i=_.entries.slice(0);i.length>e?i.splice(e,i.length-e,r):i.push(r),p({action:o,location:r,index:e,entries:i})}})},b=function(t,e){var o="REPLACE",r=(0,c.createLocation)(t,e,v(),_.location);h.confirmTransitionTo(r,o,n,function(t){t&&(_.entries[_.index]=r,p({action:o,location:r}))})},P=function(t){var e=f(_.index+t,0,_.entries.length-1),o="POP",r=_.entries[e];h.confirmTransitionTo(r,o,n,function(t){t?p({action:o,location:r,index:e}):p()})},O=function(){return P(-1)},L=function(){return P(1)},x=function(t){var n=_.index+t;return n>=0&&n<_.entries.length},S=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return h.setPrompt(t)},E=function(t){return h.appendListener(t)},_={length:g.length,action:"POP",location:g[y],index:y,entries:g,createHref:m,push:w,replace:b,go:P,goBack:O,goForward:L,canGo:x,block:S,listen:E};return _};n.default=l},function(t,n){"use strict";function e(t){return"/"===t.charAt(0)}function o(t,n){for(var e=n,o=e+1,r=t.length;o<r;e+=1,o+=1)t[e]=t[o];t.pop()}function r(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=t&&t.split("/")||[],i=n&&n.split("/")||[],a=t&&e(t),c=n&&e(n),u=a||c;if(t&&e(t)?i=r:r.length&&(i.pop(),i=i.concat(r)),!i.length)return"/";var s=void 0;if(i.length){var f=i[i.length-1];s="."===f||".."===f||""===f}else s=!1;for(var l=0,d=i.length;d>=0;d--){var h=i[d];"."===h?o(i,d):".."===h?(o(i,d),l++):l&&(o(i,d),l--)}if(!u)for(;l--;l)i.unshift("..");!u||""===i[0]||i[0]&&e(i[0])||i.unshift("");var p=i.join("/");return s&&"/"!==p.substr(-1)&&(p+="/"),p}n.__esModule=!0,n.default=r,t.exports=n.default},function(t,n){"use strict";function e(t,n){if(t===n)return!0;if(null==t||null==n)return!1;if(Array.isArray(t))return Array.isArray(n)&&t.length===n.length&&t.every(function(t,o){return e(t,n[o])});var r="undefined"==typeof t?"undefined":o(t),i="undefined"==typeof n?"undefined":o(n);if(r!==i)return!1;if("object"===r){var a=t.valueOf(),c=n.valueOf();if(a!==t||c!==n)return e(a,c);var u=Object.keys(t),s=Object.keys(n);return u.length===s.length&&u.every(function(o){return e(t[o],n[o])})}return!1}n.__esModule=!0;var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};n.default=e,t.exports=n.default}])}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.History={})}(this,function(n){"use strict";function S(){return(S=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o])}return n}).apply(this,arguments)}var e="Invariant failed";function H(n,t){if(!n)throw new Error(e)}function d(n){return"/"===n.charAt(0)}function v(n,t){for(var e=t,o=e+1,i=n.length;o<i;e+=1,o+=1)n[e]=n[o];n.pop()}var f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function U(n){return"/"===n.charAt(0)?n:"/"+n}function t(n){return"/"===n.charAt(0)?n.substr(1):n}function j(n,t){return e=n,new RegExp("^"+t+"(\\/|\\?|#|$)","i").test(e)?n.substr(t.length):n;var e}function C(n){return"/"===n.charAt(n.length-1)?n.slice(0,-1):n}function r(n){var t=n||"/",e="",o="",i=t.indexOf("#");-1!==i&&(o=t.substr(i),t=t.substr(0,i));var r=t.indexOf("?");return-1!==r&&(e=t.substr(r),t=t.substr(0,r)),{pathname:t,search:"?"===e?"":e,hash:"#"===o?"":o}}function I(n){var t=n.pathname,e=n.search,o=n.hash,i=t||"/";return e&&"?"!==e&&(i+="?"===e.charAt(0)?e:"?"+e),o&&"#"!==o&&(i+="#"===o.charAt(0)?o:"#"+o),i}function R(n,t,e,o){var i;"string"==typeof n?(i=r(n)).state=t:(void 0===(i=S({},n)).pathname&&(i.pathname=""),i.search?"?"!==i.search.charAt(0)&&(i.search="?"+i.search):i.search="",i.hash?"#"!==i.hash.charAt(0)&&(i.hash="#"+i.hash):i.hash="",void 0!==t&&void 0===i.state&&(i.state=t));try{i.pathname=decodeURI(i.pathname)}catch(n){throw n instanceof URIError?new URIError('Pathname "'+i.pathname+'" could not be decoded. This is likely caused by an invalid percent-encoding.'):n}return e&&(i.key=e),o?i.pathname?"/"!==i.pathname.charAt(0)&&(i.pathname=function(n){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",e=n&&n.split("/")||[],o=t&&t.split("/")||[],i=n&&d(n),r=t&&d(t),a=i||r;if(n&&d(n)?o=e:e.length&&(o.pop(),o=o.concat(e)),!o.length)return"/";var c=void 0;if(o.length){var f=o[o.length-1];c="."===f||".."===f||""===f}else c=!1;for(var u=0,s=o.length;0<=s;s--){var h=o[s];"."===h?v(o,s):".."===h?(v(o,s),u++):u&&(v(o,s),u--)}if(!a)for(;u--;u)o.unshift("..");!a||""===o[0]||o[0]&&d(o[0])||o.unshift("");var l=o.join("/");return c&&"/"!==l.substr(-1)&&(l+="/"),l}(i.pathname,o.pathname)):i.pathname=o.pathname:i.pathname||(i.pathname="/"),i}function T(n,t){return n.pathname===t.pathname&&n.search===t.search&&n.hash===t.hash&&n.key===t.key&&function e(t,o){if(t===o)return!0;if(null==t||null==o)return!1;if(Array.isArray(t))return Array.isArray(o)&&t.length===o.length&&t.every(function(n,t){return e(n,o[t])});var n=void 0===t?"undefined":f(t);if(n!==(void 0===o?"undefined":f(o)))return!1;if("object"!==n)return!1;var i=t.valueOf(),r=o.valueOf();if(i!==t||r!==o)return e(i,r);var a=Object.keys(t),c=Object.keys(o);return a.length===c.length&&a.every(function(n){return e(t[n],o[n])})}(n.state,t.state)}function M(){var r=null;var o=[];return{setPrompt:function(n){return r=n,function(){r===n&&(r=null)}},confirmTransitionTo:function(n,t,e,o){if(null!=r){var i="function"==typeof r?r(n,t):r;"string"==typeof i?"function"==typeof e?e(i,o):o(!0):o(!1!==i)}else o(!0)},appendListener:function(n){var t=!0;function e(){t&&n.apply(void 0,arguments)}return o.push(e),function(){t=!1,o=o.filter(function(n){return n!==e})}},notifyListeners:function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];o.forEach(function(n){return n.apply(void 0,t)})}}}var B=!("undefined"==typeof window||!window.document||!window.document.createElement);function F(n,t){t(window.confirm(n))}var _="popstate",q="hashchange";function G(){try{return window.history.state||{}}catch(n){return{}}}var E="hashchange",L={hashbang:{encodePath:function(n){return"!"===n.charAt(0)?n:"!/"+t(n)},decodePath:function(n){return"!"===n.charAt(0)?n.substr(1):n}},noslash:{encodePath:t,decodePath:U},slash:{encodePath:U,decodePath:U}};function W(){var n=window.location.href,t=n.indexOf("#");return-1===t?"":n.substring(t+1)}function $(n){var t=window.location.href.indexOf("#");window.location.replace(window.location.href.slice(0,0<=t?t:0)+"#"+n)}function g(n,t,e){return Math.min(Math.max(n,t),e)}n.createBrowserHistory=function(n){void 0===n&&(n={}),B||H(!1);var t,c=window.history,f=(-1===(t=window.navigator.userAgent).indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&window.history&&"pushState"in window.history,e=!(-1===window.navigator.userAgent.indexOf("Trident")),o=n,i=o.forceRefresh,u=void 0!==i&&i,r=o.getUserConfirmation,s=void 0===r?F:r,a=o.keyLength,h=void 0===a?6:a,l=n.basename?C(U(n.basename)):"";function d(n){var t=n||{},e=t.key,o=t.state,i=window.location,r=i.pathname+i.search+i.hash;return l&&(r=j(r,l)),R(r,o,e)}function v(){return Math.random().toString(36).substr(2,h)}var p=M();function y(n){S(L,n),L.length=c.length,p.notifyListeners(L.location,L.action)}function g(n){void(void 0===n.state&&navigator.userAgent.indexOf("CriOS"))||P(d(n.state))}function w(){P(d(G()))}var m=!1;function P(t){m?(m=!1,y()):p.confirmTransitionTo(t,"POP",s,function(n){n?y({action:"POP",location:t}):function(n){var t=L.location,e=b.indexOf(t.key);-1===e&&(e=0);var o=b.indexOf(n.key);-1===o&&(o=0);var i=e-o;i&&(m=!0,k(i))}(t)})}var O=d(G()),b=[O.key];function x(n){return l+I(n)}function k(n){c.go(n)}var A=0;function T(n){1===(A+=n)?(window.addEventListener(_,g),e&&window.addEventListener(q,w)):0===A&&(window.removeEventListener(_,g),e&&window.removeEventListener(q,w))}var E=!1,L={length:c.length,action:"POP",location:O,createHref:x,push:function(n,t){var a=R(n,t,v(),L.location);p.confirmTransitionTo(a,"PUSH",s,function(n){if(n){var t=x(a),e=a.key,o=a.state;if(f)if(c.pushState({key:e,state:o},null,t),u)window.location.href=t;else{var i=b.indexOf(L.location.key),r=b.slice(0,-1===i?0:i+1);r.push(a.key),b=r,y({action:"PUSH",location:a})}else window.location.href=t}})},replace:function(n,t){var r="REPLACE",a=R(n,t,v(),L.location);p.confirmTransitionTo(a,r,s,function(n){if(n){var t=x(a),e=a.key,o=a.state;if(f)if(c.replaceState({key:e,state:o},null,t),u)window.location.replace(t);else{var i=b.indexOf(L.location.key);-1!==i&&(b[i]=a.key),y({action:r,location:a})}else window.location.replace(t)}})},go:k,goBack:function(){k(-1)},goForward:function(){k(1)},block:function(n){void 0===n&&(n=!1);var t=p.setPrompt(n);return E||(T(1),E=!0),function(){return E&&(E=!1,T(-1)),t()}},listen:function(n){var t=p.appendListener(n);return T(1),function(){T(-1),t()}}};return L},n.createHashHistory=function(n){void 0===n&&(n={}),B||H(!1);var t=window.history,e=(window.navigator.userAgent.indexOf("Firefox"),n),o=e.getUserConfirmation,c=void 0===o?F:o,i=e.hashType,r=void 0===i?"slash":i,f=n.basename?C(U(n.basename)):"",a=L[r],u=a.encodePath,s=a.decodePath;function h(){var n=s(W());return f&&(n=j(n,f)),R(n)}var l=M();function d(n){S(A,n),A.length=t.length,l.notifyListeners(A.location,A.action)}var v=!1,p=null;function y(){var t,n=W(),e=u(n);if(n!==e)$(e);else{var o=h(),i=A.location;if(!v&&T(i,o))return;if(p===I(o))return;p=null,t=o,v?(v=!1,d()):l.confirmTransitionTo(t,"POP",c,function(n){n?d({action:"POP",location:t}):function(n){var t=A.location,e=P.lastIndexOf(I(t));-1===e&&(e=0);var o=P.lastIndexOf(I(n));-1===o&&(o=0);var i=e-o;i&&(v=!0,O(i))}(t)})}}var g=W(),w=u(g);g!==w&&$(w);var m=h(),P=[I(m)];function O(n){t.go(n)}var b=0;function x(n){1===(b+=n)?window.addEventListener(E,y):0===b&&window.removeEventListener(E,y)}var k=!1,A={length:t.length,action:"POP",location:m,createHref:function(n){return"#"+u(f+I(n))},push:function(n,t){var a=R(n,void 0,void 0,A.location);l.confirmTransitionTo(a,"PUSH",c,function(n){if(n){var t,e=I(a),o=u(f+e);if(W()!==o){p=e,t=o,window.location.hash=t;var i=P.lastIndexOf(I(A.location)),r=P.slice(0,-1===i?0:i+1);r.push(e),P=r,d({action:"PUSH",location:a})}else d()}})},replace:function(n,t){var i="REPLACE",r=R(n,void 0,void 0,A.location);l.confirmTransitionTo(r,i,c,function(n){if(n){var t=I(r),e=u(f+t);W()!==e&&(p=t,$(e));var o=P.indexOf(I(A.location));-1!==o&&(P[o]=t),d({action:i,location:r})}})},go:O,goBack:function(){O(-1)},goForward:function(){O(1)},block:function(n){void 0===n&&(n=!1);var t=l.setPrompt(n);return k||(x(1),k=!0),function(){return k&&(k=!1,x(-1)),t()}},listen:function(n){var t=l.appendListener(n);return x(1),function(){x(-1),t()}}};return A},n.createMemoryHistory=function(n){void 0===n&&(n={});var t=n,i=t.getUserConfirmation,e=t.initialEntries,o=void 0===e?["/"]:e,r=t.initialIndex,a=void 0===r?0:r,c=t.keyLength,f=void 0===c?6:c,u=M();function s(n){S(y,n),y.length=y.entries.length,u.notifyListeners(y.location,y.action)}function h(){return Math.random().toString(36).substr(2,f)}var l=g(a,0,o.length-1),d=o.map(function(n){return R(n,void 0,"string"==typeof n?h():n.key||h())}),v=I;function p(n){var t=g(y.index+n,0,y.entries.length-1),e=y.entries[t];u.confirmTransitionTo(e,"POP",i,function(n){n?s({action:"POP",location:e,index:t}):s()})}var y={length:d.length,action:"POP",location:d[l],index:l,entries:d,createHref:v,push:function(n,t){var o=R(n,t,h(),y.location);u.confirmTransitionTo(o,"PUSH",i,function(n){if(n){var t=y.index+1,e=y.entries.slice(0);e.length>t?e.splice(t,e.length-t,o):e.push(o),s({action:"PUSH",location:o,index:t,entries:e})}})},replace:function(n,t){var e="REPLACE",o=R(n,t,h(),y.location);u.confirmTransitionTo(o,e,i,function(n){n&&(y.entries[y.index]=o,s({action:e,location:o}))})},go:p,goBack:function(){p(-1)},goForward:function(){p(1)},canGo:function(n){var t=y.index+n;return 0<=t&&t<y.entries.length},block:function(n){return void 0===n&&(n=!1),u.setPrompt(n)},listen:function(n){return u.appendListener(n)}};return y},n.createLocation=R,n.locationsAreEqual=T,n.parsePath=r,n.createPath=I,Object.defineProperty(n,"__esModule",{value:!0})}); |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
28
273
142849
6
30
2663
3
18
1
+ Added@babel/runtime@^7.1.2
+ Addedtiny-invariant@^1.0.2
+ Addedtiny-warning@^1.0.0
+ Added@babel/runtime@7.24.7(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedtiny-invariant@1.3.3(transitive)
+ Addedtiny-warning@1.0.3(transitive)
- Removedinvariant@^2.2.1
- Removedwarning@^3.0.0
- Removedinvariant@2.2.4(transitive)
- Removedwarning@3.0.0(transitive)