UNPKG

provide-page

Version:

Provides automatic server-side rendering and actions (regardless of whether or not client has JavaScript enabled) to React components. Use in conjunction with `provide-router`.

1,565 lines (1,214 loc) 357 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("react")); else if(typeof define === 'function' && define.amd) define(["react"], factory); else if(typeof exports === 'object') exports["providePage"] = factory(require("react")); else root["providePage"] = factory(root["React"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_2__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.NOOP = exports.DESTROY_SESSION = exports.UPDATE_SESSION = exports.PENDING_FORM = exports.PENDING_PAGE = exports.SUBMITTED_FORM = exports.SUBMIT_FORM = exports.SUBMIT_REQUEST = exports.GOT_PAGE_STATES = exports.GET_PAGE_STATES = exports.SYNC_WITH_ROUTER = exports.SET_REQUEST_ERROR = exports.SET_JS_FILES = exports.SET_CSS_FILES = exports.SET_ICON_FILE = exports.SET_META_ROBOTS = exports.SET_META_DESCRIPTION = exports.SET_DOCUMENT_TITLE = exports.SET_STATUS_CODE = exports.SET_HEADERS = exports.defaultRenderDocumentToString = exports.createMiddleware = exports.Form = exports.Link = 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 _reduxThunk = __webpack_require__(84); var _reduxThunk2 = _interopRequireDefault(_reduxThunk); var _exenv = __webpack_require__(41); var _Link2 = __webpack_require__(37); var _Link3 = _interopRequireDefault(_Link2); var _Form2 = __webpack_require__(36); var _Form3 = _interopRequireDefault(_Form2); var _createMiddleware2 = __webpack_require__(38); var _createMiddleware3 = _interopRequireDefault(_createMiddleware2); var _defaultRenderDocumentToString2 = __webpack_require__(14); var _defaultRenderDocumentToString3 = _interopRequireDefault(_defaultRenderDocumentToString2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.Link = _Link3.default; exports.Form = _Form3.default; exports.createMiddleware = _createMiddleware3.default; exports.defaultRenderDocumentToString = _defaultRenderDocumentToString3.default; var SET_HEADERS = exports.SET_HEADERS = 'SET_HEADERS'; var SET_STATUS_CODE = exports.SET_STATUS_CODE = 'SET_STATUS_CODE'; var SET_DOCUMENT_TITLE = exports.SET_DOCUMENT_TITLE = 'SET_DOCUMENT_TITLE'; var SET_META_DESCRIPTION = exports.SET_META_DESCRIPTION = 'SET_META_DESCRIPTION'; var SET_META_ROBOTS = exports.SET_META_ROBOTS = 'SET_META_ROBOTS'; var SET_ICON_FILE = exports.SET_ICON_FILE = 'SET_ICON_FILE'; var SET_CSS_FILES = exports.SET_CSS_FILES = 'SET_CSS_FILES'; var SET_JS_FILES = exports.SET_JS_FILES = 'SET_JS_FILES'; var SET_REQUEST_ERROR = exports.SET_REQUEST_ERROR = 'SET_REQUEST_ERROR'; var SYNC_WITH_ROUTER = exports.SYNC_WITH_ROUTER = 'SYNC_WITH_ROUTER'; var GET_PAGE_STATES = exports.GET_PAGE_STATES = 'GET_PAGE_STATES'; var GOT_PAGE_STATES = exports.GOT_PAGE_STATES = 'GOT_PAGE_STATES'; var SUBMIT_REQUEST = exports.SUBMIT_REQUEST = 'SUBMIT_REQUEST'; var SUBMIT_FORM = exports.SUBMIT_FORM = 'SUBMIT_FORM'; var SUBMITTED_FORM = exports.SUBMITTED_FORM = 'SUBMITTED_FORM'; var PENDING_PAGE = exports.PENDING_PAGE = 'PENDING_PAGE'; var PENDING_FORM = exports.PENDING_FORM = 'PENDING_FORM'; var UPDATE_SESSION = exports.UPDATE_SESSION = 'UPDATE_SESSION'; var DESTROY_SESSION = exports.DESTROY_SESSION = 'DESTROY_SESSION'; var NOOP = exports.NOOP = 'NOOP'; function getUrl(location) { return location ? location.pathname + location.search : null; } function clearPending(dispatch, getState) { var state = getState(); if (state.pendingForms.length) { var _state$pendingForms$s = state.pendingForms.shift(), formData = _state$pendingForms$s.formData, onSubmit = _state$pendingForms$s.onSubmit; dispatch(actions.submitForm(formData, onSubmit)); } else if (state.pendingPage) { dispatch(actions.getPageStates(typeof window === 'undefined' ? state.routerLocation : window.location)); } } var _noEffect = true; var batchAction = function batchAction(action, immediate) { if (immediate) { return action; } return function (dispatch, getState) { var type = action.type; var _getState = getState(), pageBatchedActions = _getState.pageBatchedActions; var timeout = setTimeout(function () { while (pageBatchedActions[type].count) { pageBatchedActions[type].count--; dispatch({ type: NOOP, _noEffect: _noEffect }); } delete pageBatchedActions[type]; dispatch(action); }); if (pageBatchedActions[type]) { clearTimeout(pageBatchedActions[type].timeout); pageBatchedActions[type].timeout = timeout; pageBatchedActions[type].count++; } else { pageBatchedActions[type] = { timeout: timeout, count: 0 }; } }; }; var actions = { setHeaders: function setHeaders(headers, immediate) { return batchAction({ type: SET_HEADERS, headers: headers, _noEffect: _noEffect }, immediate); }, setStatusCode: function setStatusCode(statusCode, immediate) { return batchAction({ type: SET_STATUS_CODE, statusCode: statusCode, _noEffect: _noEffect }, immediate); }, setDocumentTitle: function setDocumentTitle() { var documentTitle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var immediate = arguments[1]; return batchAction({ type: SET_DOCUMENT_TITLE, documentTitle: documentTitle, _noEffect: _noEffect }, immediate); }, setMetaDescription: function setMetaDescription() { var metaDescription = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var immediate = arguments[1]; return batchAction({ type: SET_META_DESCRIPTION, metaDescription: metaDescription, _noEffect: _noEffect }, immediate); }, setMetaRobots: function setMetaRobots() { var metaRobots = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var immediate = arguments[1]; return batchAction({ type: SET_META_ROBOTS, metaRobots: metaRobots, _noEffect: _noEffect }, immediate); }, setIconFile: function setIconFile() { var iconFile = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var immediate = arguments[1]; return batchAction({ type: SET_ICON_FILE, iconFile: iconFile, _noEffect: _noEffect }, immediate); }, setCssFiles: function setCssFiles() { var cssFiles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var immediate = arguments[1]; return batchAction({ type: SET_CSS_FILES, cssFiles: cssFiles, _noEffect: _noEffect }, immediate); }, setJsFiles: function setJsFiles() { var jsFiles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var immediate = arguments[1]; return batchAction({ type: SET_JS_FILES, jsFiles: jsFiles, _noEffect: _noEffect }, immediate); }, setRequestError: function setRequestError(requestError, immediate) { return batchAction({ type: SET_REQUEST_ERROR, requestError: requestError }, immediate); }, syncWithRouter: function syncWithRouter(routerHistory, routerLocation) { return function (dispatch, getState) { dispatch({ type: SYNC_WITH_ROUTER, routerHistory: routerHistory, routerLocation: routerLocation, _noEffect: _noEffect }); routerHistory.listen(function (nextRouterLocation) { dispatch(actions.getPageStates(nextRouterLocation)); }); }; }, getPageStates: function getPageStates(routerLocation) { return function (dispatch, getState, _ref) { var setStates = _ref.setStates; var _getState2 = getState(), ssrDisabled = _getState2.ssrDisabled, waitingForResponse = _getState2.waitingForResponse, routerHistory = _getState2.routerHistory; if (ssrDisabled === true || typeof XMLHttpRequest === 'undefined') { dispatch({ type: NOOP, _noEffect: _noEffect }); return; } if (waitingForResponse) { dispatch({ type: PENDING_PAGE, routerLocation: routerLocation, _noEffect: _noEffect }); return; } var xhr = new XMLHttpRequest(); var headers = { 'content-type': 'application/json;charset=UTF-8', 'accept': 'application/json' }; dispatch({ type: GET_PAGE_STATES, routerLocation: routerLocation, _noEffect: _noEffect }); xhr.open('GET', getUrl(routerLocation), true); for (var header in headers) { xhr.setRequestHeader(header, headers[header]); } xhr.onload = function () { var states = JSON.parse(xhr.response); setStates(states); dispatch({ type: GOT_PAGE_STATES, states: states }); clearPending(dispatch, getState); }; xhr.send(); }; }, submitRequest: function submitRequest(_ref2) { var _ref2$requestMethod = _ref2.requestMethod, requestMethod = _ref2$requestMethod === undefined ? 'POST' : _ref2$requestMethod, _ref2$requestBody = _ref2.requestBody, requestBody = _ref2$requestBody === undefined ? {} : _ref2$requestBody, _ref2$requestHeaders = _ref2.requestHeaders, requestHeaders = _ref2$requestHeaders === undefined ? {} : _ref2$requestHeaders, requestSession = _ref2.requestSession, acceptJson = _ref2.acceptJson; return { type: SUBMIT_REQUEST, requestMethod: requestMethod, requestBody: requestBody, requestHeaders: requestHeaders, requestSession: requestSession, acceptJson: acceptJson }; }, submitForm: function submitForm(formData, onSubmit) { return function (dispatch, getState, _ref3) { var setStates = _ref3.setStates; var _getState3 = getState(), ssrDisabled = _getState3.ssrDisabled, waitingForResponse = _getState3.waitingForResponse, routerLocation = _getState3.routerLocation; if (ssrDisabled === true || typeof XMLHttpRequest === 'undefined') { formData._formHandled = true; if (onSubmit) { onSubmit(null, formData); } dispatch({ type: NOOP, _noEffect: _noEffect }); return; } if (waitingForResponse) { dispatch({ type: PENDING_FORM, formData: formData, onSubmit: onSubmit, _noEffect: _noEffect }); return; } var xhr = new XMLHttpRequest(); var headers = { 'content-type': 'application/json;charset=UTF-8', 'accept': 'application/json' }; if (onSubmit) { headers['x-server-side'] = true; } dispatch({ type: SUBMIT_FORM, formData: formData, onSubmit: onSubmit }); xhr.open('POST', getUrl(routerLocation), true); for (var header in headers) { xhr.setRequestHeader(header, headers[header]); } xhr.onload = function () { var states = JSON.parse(xhr.response); formData._formHandled = true; setStates(states); if (onSubmit) { onSubmit(null, formData); } dispatch({ type: SUBMITTED_FORM, formData: formData, onSubmit: onSubmit, states: states }); clearPending(dispatch, getState); }; xhr.send(JSON.stringify(formData)); }; }, updateSession: function updateSession(updates, immediate) { return batchAction({ type: UPDATE_SESSION, updates: updates }, immediate); }, destroySession: function destroySession(immediate) { return batchAction({ type: DESTROY_SESSION }, immediate); } }; var reducers = { headers: function headers() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var action = arguments[1]; switch (action.type) { case SET_HEADERS: return action.headers; default: return state; } }, statusCode: function statusCode() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var action = arguments[1]; switch (action.type) { case SET_STATUS_CODE: return action.statusCode; default: return state; } }, documentTitle: function documentTitle() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _exenv.canUseDOM && document.title; var action = arguments[1]; switch (action.type) { case SET_DOCUMENT_TITLE: if (_exenv.canUseDOM) { document.title = action.documentTitle; } return action.documentTitle; default: return state; } }, metaDescription: function metaDescription() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Built with provide-page.'; var action = arguments[1]; switch (action.type) { case SET_META_DESCRIPTION: return action.metaDescription; default: return state; } }, metaRobots: function metaRobots() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'index,follow'; var action = arguments[1]; switch (action.type) { case SET_META_ROBOTS: return action.metaRobots; default: return state; } }, iconFile: function iconFile() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/static/favicon.ico'; var action = arguments[1]; switch (action.type) { case SET_ICON_FILE: return action.iconFile; default: return state; } }, cssFiles: function cssFiles() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var action = arguments[1]; switch (action.type) { case SET_CSS_FILES: return action.cssFiles; default: return state; } }, jsFiles: function jsFiles() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var action = arguments[1]; switch (action.type) { case SET_JS_FILES: return action.jsFiles; default: return state; } }, requestError: function requestError() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var action = arguments[1]; switch (action.type) { case SET_REQUEST_ERROR: return action.requestError; default: return state; } }, requestSession: function requestSession() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var action = arguments[1]; if (!state.__actualSession && typeof state.destroy !== 'undefined') { state = _extends({}, state, { __actualSession: state }); } switch (action.type) { case SUBMIT_REQUEST: var requestSession = action.requestSession; return requestSession ? _extends({}, requestSession, { __actualSession: requestSession }) : state; case UPDATE_SESSION: var nextState = _extends({}, state); var _action$updates = action.updates, updates = _action$updates === undefined ? {} : _action$updates; delete updates.__actualSession; // just in case if (!nextState.__actualSession) { nextState.__actualSession = {}; } for (var key in updates) { nextState[key] = updates[key]; nextState.__actualSession[key] = updates[key]; } if (nextState.__actualSession.save) { nextState.__actualSession.save(); } return nextState; case DESTROY_SESSION: if (state.__actualSession && state.__actualSession.destroy) { state.__actualSession.destroy(); return { __actualSession: state.__actualSession }; } return { __actualSession: {} }; default: return state; } }, requestMethod: function requestMethod() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var action = arguments[1]; switch (action.type) { case SUBMIT_REQUEST: return action.requestMethod; default: return state; } }, requestBody: function requestBody() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var action = arguments[1]; switch (action.type) { case SUBMIT_FORM: return action.formData; case SUBMIT_REQUEST: return action.requestBody; default: return state; } }, requestHeaders: function requestHeaders() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var action = arguments[1]; switch (action.type) { case SUBMIT_FORM: case SUBMIT_REQUEST: return action.requestHeaders || {}; default: return state; } }, acceptJson: function acceptJson() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var action = arguments[1]; switch (action.type) { case SUBMIT_REQUEST: return typeof action.acceptJson === 'undefined' ? state : action.acceptJson; default: return state; } }, routerHistory: function routerHistory() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var action = arguments[1]; switch (action.type) { case SYNC_WITH_ROUTER: return action.routerHistory; default: return state; } }, routerLocation: function routerLocation() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var action = arguments[1]; switch (action.type) { case SYNC_WITH_ROUTER: case GET_PAGE_STATES: return action.routerLocation; default: return state; } }, waitingForResponse: function waitingForResponse() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var action = arguments[1]; switch (action.type) { case GET_PAGE_STATES: case SUBMIT_FORM: return true; case GOT_PAGE_STATES: case SUBMITTED_FORM: return false; default: return state; } }, pendingPage: function pendingPage() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var action = arguments[1]; switch (action.type) { case PENDING_PAGE: return true; case GET_PAGE_STATES: case SUBMIT_FORM: return false; default: return state; } }, pendingForms: function pendingForms() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var _ref4 = arguments[1]; var type = _ref4.type, formData = _ref4.formData, onSubmit = _ref4.onSubmit; if (type === PENDING_FORM) { state.push({ formData: formData, onSubmit: onSubmit }); } return state; }, pageBatchedActions: function pageBatchedActions() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return state; }, ssrDisabled: function ssrDisabled() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; return state; } }; var merge = { formData: { keys: ['requestBody'], get: function get(_ref5, _ref6) { var requestBody = _ref5.requestBody; var formId = _ref6.formId; return requestBody && requestBody._formId === formId ? requestBody : null; } } }; var middleware = _reduxThunk2.default; var clientStateKeys = ['requestSession', 'requestError']; var subscribeTo = { router: function router(_ref7, _ref8) { var routerStore = _ref7.store; var pageStore = _ref8.store; // there's probably a better way to do this but whatever var _pageStore$getState = pageStore.getState(), routerHistory = _pageStore$getState.routerHistory; if (typeof window !== 'undefined' && !routerHistory) { var _routerStore$getState = routerStore.getState(), history = _routerStore$getState.history, routing = _routerStore$getState.routing; var location = routing && routing.locationBeforeTransitions || routing && routing.location || routerStore.getState().location || history.location; if (history && location) { pageStore.dispatch(actions.syncWithRouter(history, location)); } } } }; exports.default = { actions: actions, reducers: reducers, merge: merge, middleware: middleware, clientStateKeys: clientStateKeys, subscribeTo: subscribeTo }; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { /** * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ if (true) { var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) || 0xeac7; var isValidElement = function(object) { return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; }; // By explicitly using `prop-types` you are opting into new development behavior. // http://fb.me/prop-types-in-prod var throwOnDirectAccess = true; module.exports = __webpack_require__(57)(isValidElement, throwOnDirectAccess); } else { // By explicitly using `prop-types` you are opting into new production behavior. // http://fb.me/prop-types-in-prod module.exports = require('./factoryWithThrowingShims')(); } /***/ }), /* 2 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_2__; /***/ }), /* 3 */ /***/ (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 (true) { 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; /***/ }), /* 4 */ /***/ (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 (true) { 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; /***/ }), /* 5 */ /***/ (function(module, exports) { '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; }; /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { '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 = __webpack_require__(89); var _resolvePathname2 = _interopRequireDefault(_resolvePathname); var _valueEqual = __webpack_require__(93); var _valueEqual2 = _interopRequireDefault(_valueEqual); var _PathUtils = __webpack_require__(5); 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); }; /***/ }), /* 7 */ /***/ (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__(3); var _warning2 = _interopRequireDefault(_warning); var _PathUtils = __webpack_require__(5); var _LocationUtils = __webpack_require__(6); 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) { (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; /***/ }), /* 8 */ /***/ (function(module, exports, __webpack_require__) { 'use strict'; exports.__esModule = true; var _warning = __webpack_require__(3); 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; /***/ }), /* 9 */ /***/ (function(module, exports) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: 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; }; exports.default = shallowEqual; function shallowEqual(objA, objB) { if (objA === objB) { return true; } if (!objA || (typeof objA === 'undefined' ? 'undefined' : _typeof(objA)) !== 'object' || !objB || (typeof objB === 'undefined' ? 'undefined' : _typeof(objB)) !== 'object') { return false; } var keysA = Object.keys(objA); var keysB = Object.keys(objB); if (keysA.length !== keysB.length) { return false; } // Test for A's keys different from B. var hasOwn = Object.prototype.hasOwnProperty; for (var i = 0; i < keysA.length; i++) { if (!hasOwn.call(objB, keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) { return false; } } return true; } /***/ }), /* 10 */ /***/ (function(module, exports, __webpack_require__) { 'use strict'; exports.__esModule = true; var _Router = __webpack_require__(11); var _Router2 = _interopRequireDefault(_Router); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = _Router2.default; // Written in this round about way for babel-transform-imports /***/ }), /* 11 */ /***/ (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__(3); var _warning2 = _interopRequireDefault(_warning); var _invariant = __webpack_require__(4); var _invariant2 = _interopRequireDefault(_invariant); var _react = __webpack_require__(2); var _react2 = _interopRequireDefault(_react); var _propTypes = __webpack_require__(1); var _propTypes2 = _interopRequireDefault(_propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * The public API for putting history on context. */ var Router = function (_React$Component) { _inherits(Router, _React$Component); function Router() { var _temp, _this, _ret; _classCallCheck(this, Router); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = { match: _this.computeMatch(_this.props.history.location.pathname) }, _temp), _possibleConstructorReturn(_this, _ret); } Router.prototype.getChildContext = function getChildContext() { return { router: _extends({}, this.context.router, { history: this.props.history, route: { location: this.props.history.location, match: this.state.match } }) }; }; Router.prototype.computeMatch = function computeMatch(pathname) { return { path: '/', url: '/', params: {}, isExact: pathname === '/' }; }; Router.prototype.componentWillMount = function componentWillMount() { var _this2 = this; var _props = this.props, children = _props.children, history = _props.history; (0, _invariant2.default)(children == null || _react2.default.Children.count(children) === 1, 'A <Router> may have only one child element'); // Do this here so we can setState when a <Redirect> changes the // location in componentWillMount. This happens e.g. when doing // server rendering using a <StaticRouter>. this.unlisten = history.listen(function () { _this2.setState({ match: _this2.computeMatch(history.location.pathname) }); }); }; Router.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { (0, _warning2.default)(this.props.history === nextProps.history, 'You cannot change <Router history>'); }; Router.prototype.componentWillUnmount = function componentWillUnmount() { this.unlisten(); }; Router.prototype.render = function render() { var children = this.props.children; return children ? _react2.default.Children.only(children) : null; }; return Router; }(_react2.default.Component); Router.propTypes = { history: _propTypes2.default.object.isRequired, children: _propTypes2.default.node }; Router.contextTypes = { router: _propTypes2.default.object }; Router.childContextTypes = { router: _propTypes2.default.object.isRequired }; exports.default = Router; /***/ }), /* 12 */ /***/ (function(module, exports, __webpack_require__) { 'use strict'; exports.__esModule = true; var _pathToRegexp = __webpack_require__(54); var _pathToRegexp2 = _interopRequireDefault(_pathToRegexp); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var patternCache = {}; var cacheLimit = 10000; var cacheCount = 0; var compilePath = function compilePath(pattern, options) { var cacheKey = '' + options.end + options.strict + options.sensitive; var cache = patternCache[cacheKey] || (patternCache[cacheKey] = {}); if (cache[pattern]) return cache[pattern]; var keys = []; var re = (0, _pathToRegexp2.default)(pattern, keys, options); var compiledPattern = { re: re, keys: keys }; if (cacheCount < cacheLimit) { cache[pattern] = compiledPattern; cacheCount++; } return compiledPattern; }; /** * Public API for matching a URL pathname to a path pattern. */ var matchPath = function matchPath(pathname) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (typeof options === 'string') options = { path: options }; var _options = options, _options$path = _options.path, path = _options$path === undefined ? '/' : _options$path, _options$exact = _options.exact, exact = _options$exact === undefined ? false : _options$exact, _options$strict = _options.strict, strict = _options$strict === undefined ? false : _options$strict, _options$sensitive = _options.sensitive, sensitive = _options$sensitive === undefined ? false : _options$sensitive; var _compilePath = compilePath(path, { end: exact, strict: strict, sensitive: sensitive }), re = _compilePath.re, keys = _compilePath.keys; var match = re.exec(pathname); if (!match) return null; var url = match[0], values = match.slice(1); var isExact = pathname === url; if (exact && !isExact) return null; return { path: path, // the path pattern used to match url: path === '/' && url === '' ? '/' : url, // the matched portion of the URL isExact: isExact, // whether or not we matched exactly params: keys.reduce(function (memo, key, index) { memo[key.name] = values[index]; return memo; }, {}) }; }; exports.default = matchPath; /***/ }), /* 13 */ /***/ (function(module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var prefix = "@@redux-replicate"; var GET_INITIAL_STATE = exports.GET_INITIAL_STATE = prefix + "/GET_INITIAL_STATE"; var GOT_INITIAL_STATE = exports.GOT_INITIAL_STATE = prefix + "/GOT_INITIAL_STATE"; var INITIAL_STATE_ERROR = exports.INITIAL_STATE_ERROR = prefix + "/INITIAL_STATE_ERROR"; var REPLICATE_INITIAL_STATE = exports.REPLICATE_INITIAL_STATE = prefix + "/REPLICATE_INITIAL_STATE"; var REPLICATED_INITIAL_STATE = exports.REPLICATED_INITIAL_STATE = prefix + "/REPLICATED_INITIAL_STATE"; var REPLICATE_STATE = exports.REPLICATE_STATE = prefix + "/REPLICATE_STATE"; var REPLICATED_STATE = exports.REPLICATED_STATE = prefix + "/REPLICATED_STATE"; var STATE_CHANGE_ERROR = exports.STATE_CHANGE_ERROR = prefix + "/STATE_CHANGE_ERROR"; var SET_STATE = exports.SET_STATE = prefix + "/SET_STATE"; var FULLY_INITIALIZED = exports.FULLY_INITIALIZED = prefix + "/FULLY_INITIALIZED"; /***/ }), /* 14 */ /***/ (function(module, exports) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); function defa