Initial commit
This commit is contained in:
55
node_modules/history/DOMUtils.js
generated
vendored
Normal file
55
node_modules/history/DOMUtils.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
'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;
|
||||
};
|
||||
78
node_modules/history/LocationUtils.js
generated
vendored
Normal file
78
node_modules/history/LocationUtils.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
'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);
|
||||
};
|
||||
61
node_modules/history/PathUtils.js
generated
vendored
Normal file
61
node_modules/history/PathUtils.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
'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;
|
||||
};
|
||||
307
node_modules/history/createBrowserHistory.js
generated
vendored
Normal file
307
node_modules/history/createBrowserHistory.js
generated
vendored
Normal file
@@ -0,0 +1,307 @@
|
||||
'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;
|
||||
324
node_modules/history/createHashHistory.js
generated
vendored
Normal file
324
node_modules/history/createHashHistory.js
generated
vendored
Normal file
@@ -0,0 +1,324 @@
|
||||
'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;
|
||||
170
node_modules/history/createMemoryHistory.js
generated
vendored
Normal file
170
node_modules/history/createMemoryHistory.js
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
'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;
|
||||
85
node_modules/history/createTransitionManager.js
generated
vendored
Normal file
85
node_modules/history/createTransitionManager.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
'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;
|
||||
52
node_modules/history/es/DOMUtils.js
generated
vendored
Normal file
52
node_modules/history/es/DOMUtils.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
export var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
||||
|
||||
export var addEventListener = function addEventListener(node, event, listener) {
|
||||
return node.addEventListener ? node.addEventListener(event, listener, false) : node.attachEvent('on' + event, listener);
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
65
node_modules/history/es/LocationUtils.js
generated
vendored
Normal file
65
node_modules/history/es/LocationUtils.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
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 resolvePathname from 'resolve-pathname';
|
||||
import valueEqual from 'value-equal';
|
||||
import { parsePath } from './PathUtils';
|
||||
|
||||
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);
|
||||
};
|
||||
58
node_modules/history/es/PathUtils.js
generated
vendored
Normal file
58
node_modules/history/es/PathUtils.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
export var addLeadingSlash = function addLeadingSlash(path) {
|
||||
return path.charAt(0) === '/' ? path : '/' + path;
|
||||
};
|
||||
|
||||
export var stripLeadingSlash = function stripLeadingSlash(path) {
|
||||
return path.charAt(0) === '/' ? path.substr(1) : path;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
290
node_modules/history/es/createBrowserHistory.js
generated
vendored
Normal file
290
node_modules/history/es/createBrowserHistory.js
generated
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
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; };
|
||||
|
||||
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;
|
||||
307
node_modules/history/es/createHashHistory.js
generated
vendored
Normal file
307
node_modules/history/es/createHashHistory.js
generated
vendored
Normal file
@@ -0,0 +1,307 @@
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||
|
||||
import warning from 'warning';
|
||||
import invariant from 'invariant';
|
||||
import { 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';
|
||||
|
||||
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;
|
||||
157
node_modules/history/es/createMemoryHistory.js
generated
vendored
Normal file
157
node_modules/history/es/createMemoryHistory.js
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
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; };
|
||||
|
||||
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;
|
||||
77
node_modules/history/es/createTransitionManager.js
generated
vendored
Normal file
77
node_modules/history/es/createTransitionManager.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
import warning from 'warning';
|
||||
|
||||
var createTransitionManager = function createTransitionManager() {
|
||||
var prompt = null;
|
||||
|
||||
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;
|
||||
9
node_modules/history/es/index.js
generated
vendored
Normal file
9
node_modules/history/es/index.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import _createBrowserHistory from './createBrowserHistory';
|
||||
export { _createBrowserHistory as createBrowserHistory };
|
||||
import _createHashHistory from './createHashHistory';
|
||||
export { _createHashHistory as createHashHistory };
|
||||
import _createMemoryHistory from './createMemoryHistory';
|
||||
export { _createMemoryHistory as createMemoryHistory };
|
||||
|
||||
export { createLocation, locationsAreEqual } from './LocationUtils';
|
||||
export { parsePath, createPath } from './PathUtils';
|
||||
52
node_modules/history/index.js
generated
vendored
Normal file
52
node_modules/history/index.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
'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;
|
||||
63
node_modules/history/package.json
generated
vendored
Normal file
63
node_modules/history/package.json
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "history",
|
||||
"version": "4.7.2",
|
||||
"description": "Manage session history with JavaScript",
|
||||
"repository": "ReactTraining/history",
|
||||
"license": "MIT",
|
||||
"author": "Michael Jackson",
|
||||
"files": [
|
||||
"DOMUtils.js",
|
||||
"ExecutionEnvironment.js",
|
||||
"LocationUtils.js",
|
||||
"PathUtils.js",
|
||||
"createBrowserHistory.js",
|
||||
"createHashHistory.js",
|
||||
"createMemoryHistory.js",
|
||||
"createTransitionManager.js",
|
||||
"es",
|
||||
"index.js",
|
||||
"umd"
|
||||
],
|
||||
"main": "index.js",
|
||||
"module": "es/index.js",
|
||||
"dependencies": {
|
||||
"invariant": "^2.2.1",
|
||||
"loose-envify": "^1.2.0",
|
||||
"resolve-pathname": "^2.2.0",
|
||||
"value-equal": "^0.4.0",
|
||||
"warning": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.18.0",
|
||||
"babel-core": "^6.23.1",
|
||||
"babel-eslint": "^7.0.0",
|
||||
"babel-loader": "^6.2.10",
|
||||
"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",
|
||||
"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",
|
||||
"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"
|
||||
},
|
||||
"browserify": {
|
||||
"transform": [
|
||||
"loose-envify"
|
||||
]
|
||||
}
|
||||
}
|
||||
1478
node_modules/history/umd/history.js
generated
vendored
Normal file
1478
node_modules/history/umd/history.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/history/umd/history.min.js
generated
vendored
Normal file
1
node_modules/history/umd/history.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user