├── .babelrc ├── .gitignore ├── .travis.yml ├── LICENSE.md ├── README.md ├── dist ├── index.es.js ├── index.js ├── index.umd.js └── index.umd.min.js ├── example ├── gatsby-config.js ├── package.json ├── src │ ├── ApiForm.js │ ├── App.js │ ├── Blob.js │ ├── DynamicSpreadsheet.js │ ├── Field.js │ ├── Octokitty │ │ ├── index.js │ │ └── style.css │ ├── Select.js │ ├── Table.js │ └── pages │ │ ├── index.js │ │ └── style.css └── yarn.lock ├── modules ├── GoogleSheet.js ├── GoogleSheetsApi.js ├── __tests__ │ ├── GoogleSheet.test.js │ ├── GoogleSheetsApi.test.js │ └── __snapshots__ │ │ ├── GoogleSheet.test.js.snap │ │ └── GoogleSheetsApi.test.js.snap └── index.js ├── package.json ├── rollup.config.js ├── scripts ├── build.js ├── release.js └── testSetup.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "react", 4 | ["env", { "targets": {"node": "current"}, "loose": true }], 5 | "stage-2" 6 | ] 7 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | public 4 | .cache 5 | cjs 6 | esm 7 | umd -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 'node' -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2018 Louis R. DeScioli 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @lourd/react-google-sheet [![npm package badge][npm-badge]][npm] [![Build status][travis badge]][travis] 2 | 3 | [npm-badge]: https://img.shields.io/npm/v/@lourd/react-google-sheet.svg?style=flat-square 4 | [npm]: https://www.npmjs.com/package/@lourd/react-google-sheet 5 | [travis badge]: https://travis-ci.org/lourd/react-google-sheet.svg 6 | [travis]: https://travis-ci.org/lourd/react-google-sheet 7 | [site]: https://lourd.github.io/react-google-sheet 8 | [api component]: https://github.com/lourd/react-google-api 9 | 10 | Easily use data from Google Sheets in your React application with the [`GoogleSheet`](#googlesheet) component. 11 | 12 | ## Background 13 | 14 | The motivation for making this module was researching ways to easily use data from Google Sheets. This module is a client-centric approach, using React to make a declarative component API for the [Google Sheets browser API](https://developers.google.com/sheets/api/quickstart/js). 15 | 16 | Under the hood this is using the generic [`@lourd/react-google-api`][api component] module for handling loading and initializing the Google API JavaScript client library. 17 | 18 | ## Example 19 | 20 | There are just a couple steps to using the [example app][site]. The source is in the [`example` directory](./example). 21 | 22 | 1. Click the `Authorize` button and allow the site to have access to your Google Sheets data 23 | 2. Get the ID of a spreadsheet that you have permission to view. In the URL of a sheet it's in between `/d/` and `/edit`, i.e. for `/spreadsheets/d/foofoo/edit` it's **foofoo**. 24 | 3. Choose a range of the spreadsheet, e.g. `Tab 1!2:12` 25 | 26 | You can also use your own API key and application ID that you made on the [Google APIs console](https://console.developers.google.com/apis/credentials). 27 | 28 | ## Installation 29 | 30 | ```sh 31 | yarn add @lourd/react-google-sheet 32 | # or 33 | npm install --save @lourd/react-google-sheet 34 | ``` 35 | 36 | ### Browser 37 | 38 | Available as a simple ` 44 | 45 | ``` 46 | 47 | #### Production 48 | 49 | ```html 50 | 51 | 52 | ``` 53 | 54 | ## Reference 55 | 56 | ```js 57 | import { GoogleSheet, GoogleSheetsApi } from '@lourd/react-google-sheet' 58 | ``` 59 | 60 | ### [``](./modules/GoogleSheetsApi.js) 61 | 62 | This component handles downloading and instantiating the Google sheets browser API, and passing it into context for other components to use. See an example of this component used in [App.js](./example/src/App.js#L9-L32) 63 | 64 | | Property | Type | Required | Default | Description | 65 | | :------- | :--------- | :------- | :---------------------------------------------------------- | :----------------------------------------------------------- | 66 | | scopes | `[string]` | no | `['https://www.googleapis.com/auth/spreadsheets.readonly']` | The authorization scopes being requested for the API client. | 67 | 68 | ### [``](./modules/GoogleSheet.js/) 69 | 70 | | Property | Type | Required | Description | 71 | | :------- | :------- | :------- | :------------------------------------ | 72 | | id | `string` | yes | The id of the spreadsheet | 73 | | range | `string` | yes | The range of cells in the spreadsheet | 74 | 75 | Ths component handles getting the Google client from context and using it to request the data from the Sheets API. See an example of this component used in [DynamicSpreadsheet.js](./example/src/DynamicSpreadsheet.js#L21-L33) 76 | -------------------------------------------------------------------------------- /dist/index.es.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import equalByKeys from '@lourd/equal-by-keys'; 4 | import { GoogleApiConsumer, GoogleApi } from '@lourd/react-google-api'; 5 | 6 | var asyncToGenerator = function (fn) { 7 | return function () { 8 | var gen = fn.apply(this, arguments); 9 | return new Promise(function (resolve, reject) { 10 | function step(key, arg) { 11 | try { 12 | var info = gen[key](arg); 13 | var value = info.value; 14 | } catch (error) { 15 | reject(error); 16 | return; 17 | } 18 | 19 | if (info.done) { 20 | resolve(value); 21 | } else { 22 | return Promise.resolve(value).then(function (value) { 23 | step("next", value); 24 | }, function (err) { 25 | step("throw", err); 26 | }); 27 | } 28 | } 29 | 30 | return step("next"); 31 | }); 32 | }; 33 | }; 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | var _extends = Object.assign || function (target) { 46 | for (var i = 1; i < arguments.length; i++) { 47 | var source = arguments[i]; 48 | 49 | for (var key in source) { 50 | if (Object.prototype.hasOwnProperty.call(source, key)) { 51 | target[key] = source[key]; 52 | } 53 | } 54 | } 55 | 56 | return target; 57 | }; 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | var objectWithoutProperties = function (obj, keys) { 72 | var target = {}; 73 | 74 | for (var i in obj) { 75 | if (keys.indexOf(i) >= 0) continue; 76 | if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; 77 | target[i] = obj[i]; 78 | } 79 | 80 | return target; 81 | }; 82 | 83 | class GSheetData extends React.Component { 84 | 85 | constructor(props) { 86 | super(props); 87 | this.state = { 88 | error: null, 89 | data: null, 90 | loading: false 91 | }; 92 | this.fetch = this.fetch.bind(this); 93 | } 94 | 95 | componentDidMount() { 96 | this.fetch(); 97 | } 98 | 99 | componentDidUpdate(prevProps) { 100 | if (!equalByKeys(this.props, prevProps, 'id', 'range')) { 101 | this.fetch(); 102 | } 103 | } 104 | 105 | fetch() { 106 | var _this = this; 107 | 108 | return asyncToGenerator(function* () { 109 | _this.setState({ loading: true }); 110 | try { 111 | const params = { 112 | spreadsheetId: _this.props.id, 113 | range: _this.props.range 114 | }; 115 | const response = yield _this.props.api.client.sheets.spreadsheets.values.get(params); 116 | // Unable to cancel requests, so we wait until it's done and check it's still the desired one 117 | if (_this.props.id === params.spreadsheetId && _this.props.range === params.range) { 118 | _this.setState({ 119 | loading: false, 120 | error: null, 121 | data: response.result.values 122 | }); 123 | } 124 | } catch (response) { 125 | // If the api is still null, this will be a TypeError, not a response object 126 | const error = response.result ? response.result.error : response; 127 | _this.setState({ loading: false, error }); 128 | } 129 | })(); 130 | } 131 | 132 | render() { 133 | return this.props.children({ 134 | error: this.state.error, 135 | data: this.state.data, 136 | loading: this.state.loading, 137 | refetch: this.fetch 138 | }); 139 | } 140 | } 141 | 142 | GSheetData.propTypes = { 143 | id: PropTypes.string.isRequired, 144 | range: PropTypes.string.isRequired, 145 | api: PropTypes.object.isRequired 146 | }; 147 | const GoogleSheet = props => React.createElement( 148 | GoogleApiConsumer, 149 | null, 150 | api => React.createElement(GSheetData, _extends({ api: api }, props)) 151 | ); 152 | 153 | const GoogleSheetsApi = (_ref) => { 154 | var _ref$scopes = _ref.scopes; 155 | let scopes = _ref$scopes === undefined ? ['https://www.googleapis.com/auth/spreadsheets.readonly'] : _ref$scopes, 156 | props = objectWithoutProperties(_ref, ['scopes']); 157 | return React.createElement(GoogleApi, _extends({ 158 | scopes: scopes, 159 | discoveryDocs: ['https://sheets.googleapis.com/$discovery/rest?version=v4'] 160 | }, props)); 161 | }; 162 | 163 | export { GoogleSheet, GoogleSheetsApi }; 164 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var React = _interopDefault(require('react')); 8 | var PropTypes = _interopDefault(require('prop-types')); 9 | var equalByKeys = _interopDefault(require('@lourd/equal-by-keys')); 10 | var reactGoogleApi = require('@lourd/react-google-api'); 11 | 12 | var asyncToGenerator = function (fn) { 13 | return function () { 14 | var gen = fn.apply(this, arguments); 15 | return new Promise(function (resolve, reject) { 16 | function step(key, arg) { 17 | try { 18 | var info = gen[key](arg); 19 | var value = info.value; 20 | } catch (error) { 21 | reject(error); 22 | return; 23 | } 24 | 25 | if (info.done) { 26 | resolve(value); 27 | } else { 28 | return Promise.resolve(value).then(function (value) { 29 | step("next", value); 30 | }, function (err) { 31 | step("throw", err); 32 | }); 33 | } 34 | } 35 | 36 | return step("next"); 37 | }); 38 | }; 39 | }; 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | var _extends = Object.assign || function (target) { 52 | for (var i = 1; i < arguments.length; i++) { 53 | var source = arguments[i]; 54 | 55 | for (var key in source) { 56 | if (Object.prototype.hasOwnProperty.call(source, key)) { 57 | target[key] = source[key]; 58 | } 59 | } 60 | } 61 | 62 | return target; 63 | }; 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | var objectWithoutProperties = function (obj, keys) { 78 | var target = {}; 79 | 80 | for (var i in obj) { 81 | if (keys.indexOf(i) >= 0) continue; 82 | if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; 83 | target[i] = obj[i]; 84 | } 85 | 86 | return target; 87 | }; 88 | 89 | class GSheetData extends React.Component { 90 | 91 | constructor(props) { 92 | super(props); 93 | this.state = { 94 | error: null, 95 | data: null, 96 | loading: false 97 | }; 98 | this.fetch = this.fetch.bind(this); 99 | } 100 | 101 | componentDidMount() { 102 | this.fetch(); 103 | } 104 | 105 | componentDidUpdate(prevProps) { 106 | if (!equalByKeys(this.props, prevProps, 'id', 'range')) { 107 | this.fetch(); 108 | } 109 | } 110 | 111 | fetch() { 112 | var _this = this; 113 | 114 | return asyncToGenerator(function* () { 115 | _this.setState({ loading: true }); 116 | try { 117 | const params = { 118 | spreadsheetId: _this.props.id, 119 | range: _this.props.range 120 | }; 121 | const response = yield _this.props.api.client.sheets.spreadsheets.values.get(params); 122 | // Unable to cancel requests, so we wait until it's done and check it's still the desired one 123 | if (_this.props.id === params.spreadsheetId && _this.props.range === params.range) { 124 | _this.setState({ 125 | loading: false, 126 | error: null, 127 | data: response.result.values 128 | }); 129 | } 130 | } catch (response) { 131 | // If the api is still null, this will be a TypeError, not a response object 132 | const error = response.result ? response.result.error : response; 133 | _this.setState({ loading: false, error }); 134 | } 135 | })(); 136 | } 137 | 138 | render() { 139 | return this.props.children({ 140 | error: this.state.error, 141 | data: this.state.data, 142 | loading: this.state.loading, 143 | refetch: this.fetch 144 | }); 145 | } 146 | } 147 | 148 | GSheetData.propTypes = { 149 | id: PropTypes.string.isRequired, 150 | range: PropTypes.string.isRequired, 151 | api: PropTypes.object.isRequired 152 | }; 153 | const GoogleSheet = props => React.createElement( 154 | reactGoogleApi.GoogleApiConsumer, 155 | null, 156 | api => React.createElement(GSheetData, _extends({ api: api }, props)) 157 | ); 158 | 159 | const GoogleSheetsApi = (_ref) => { 160 | var _ref$scopes = _ref.scopes; 161 | let scopes = _ref$scopes === undefined ? ['https://www.googleapis.com/auth/spreadsheets.readonly'] : _ref$scopes, 162 | props = objectWithoutProperties(_ref, ['scopes']); 163 | return React.createElement(reactGoogleApi.GoogleApi, _extends({ 164 | scopes: scopes, 165 | discoveryDocs: ['https://sheets.googleapis.com/$discovery/rest?version=v4'] 166 | }, props)); 167 | }; 168 | 169 | exports.GoogleSheet = GoogleSheet; 170 | exports.GoogleSheetsApi = GoogleSheetsApi; 171 | -------------------------------------------------------------------------------- /dist/index.umd.js: -------------------------------------------------------------------------------- 1 | (function (global, factory) { 2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : 3 | typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : 4 | (factory((global.ReactGoogleSheet = {}),global.React)); 5 | }(this, (function (exports,React) { 'use strict'; 6 | 7 | React = React && React.hasOwnProperty('default') ? React['default'] : React; 8 | 9 | function createCommonjsModule(fn, module) { 10 | return module = { exports: {} }, fn(module, module.exports), module.exports; 11 | } 12 | 13 | /** 14 | * Copyright (c) 2013-present, Facebook, Inc. 15 | * 16 | * This source code is licensed under the MIT license found in the 17 | * LICENSE file in the root directory of this source tree. 18 | * 19 | * 20 | */ 21 | 22 | function makeEmptyFunction(arg) { 23 | return function () { 24 | return arg; 25 | }; 26 | } 27 | 28 | /** 29 | * This function accepts and discards inputs; it has no side effects. This is 30 | * primarily useful idiomatically for overridable function endpoints which 31 | * always need to be callable, since JS lacks a null-call idiom ala Cocoa. 32 | */ 33 | var emptyFunction = function emptyFunction() {}; 34 | 35 | emptyFunction.thatReturns = makeEmptyFunction; 36 | emptyFunction.thatReturnsFalse = makeEmptyFunction(false); 37 | emptyFunction.thatReturnsTrue = makeEmptyFunction(true); 38 | emptyFunction.thatReturnsNull = makeEmptyFunction(null); 39 | emptyFunction.thatReturnsThis = function () { 40 | return this; 41 | }; 42 | emptyFunction.thatReturnsArgument = function (arg) { 43 | return arg; 44 | }; 45 | 46 | var emptyFunction_1 = emptyFunction; 47 | 48 | /** 49 | * Copyright (c) 2013-present, Facebook, Inc. 50 | * 51 | * This source code is licensed under the MIT license found in the 52 | * LICENSE file in the root directory of this source tree. 53 | * 54 | */ 55 | 56 | /** 57 | * Use invariant() to assert state which your program assumes to be true. 58 | * 59 | * Provide sprintf-style format (only %s is supported) and arguments 60 | * to provide information about what broke and what you were 61 | * expecting. 62 | * 63 | * The invariant message will be stripped in production, but the invariant 64 | * will remain to ensure logic does not differ in production. 65 | */ 66 | 67 | var validateFormat = function validateFormat(format) {}; 68 | 69 | if (undefined !== 'production') { 70 | validateFormat = function validateFormat(format) { 71 | if (format === undefined) { 72 | throw new Error('invariant requires an error message argument'); 73 | } 74 | }; 75 | } 76 | 77 | function invariant(condition, format, a, b, c, d, e, f) { 78 | validateFormat(format); 79 | 80 | if (!condition) { 81 | var error; 82 | if (format === undefined) { 83 | error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); 84 | } else { 85 | var args = [a, b, c, d, e, f]; 86 | var argIndex = 0; 87 | error = new Error(format.replace(/%s/g, function () { 88 | return args[argIndex++]; 89 | })); 90 | error.name = 'Invariant Violation'; 91 | } 92 | 93 | error.framesToPop = 1; // we don't care about invariant's own frame 94 | throw error; 95 | } 96 | } 97 | 98 | var invariant_1 = invariant; 99 | 100 | /** 101 | * Similar to invariant but only logs a warning if the condition is not met. 102 | * This can be used to log issues in development environments in critical 103 | * paths. Removing the logging code for production environments will keep the 104 | * same logic and follow the same code paths. 105 | */ 106 | 107 | var warning = emptyFunction_1; 108 | 109 | if (undefined !== 'production') { 110 | var printWarning = function printWarning(format) { 111 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 112 | args[_key - 1] = arguments[_key]; 113 | } 114 | 115 | var argIndex = 0; 116 | var message = 'Warning: ' + format.replace(/%s/g, function () { 117 | return args[argIndex++]; 118 | }); 119 | if (typeof console !== 'undefined') { 120 | console.error(message); 121 | } 122 | try { 123 | // --- Welcome to debugging React --- 124 | // This error was thrown as a convenience so that you can use this stack 125 | // to find the callsite that caused this warning to fire. 126 | throw new Error(message); 127 | } catch (x) {} 128 | }; 129 | 130 | warning = function warning(condition, format) { 131 | if (format === undefined) { 132 | throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); 133 | } 134 | 135 | if (format.indexOf('Failed Composite propType: ') === 0) { 136 | return; // Ignore CompositeComponent proptype check. 137 | } 138 | 139 | if (!condition) { 140 | for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { 141 | args[_key2 - 2] = arguments[_key2]; 142 | } 143 | 144 | printWarning.apply(undefined, [format].concat(args)); 145 | } 146 | }; 147 | } 148 | 149 | var warning_1 = warning; 150 | 151 | /* 152 | object-assign 153 | (c) Sindre Sorhus 154 | @license MIT 155 | */ 156 | 157 | /* eslint-disable no-unused-vars */ 158 | var getOwnPropertySymbols = Object.getOwnPropertySymbols; 159 | var hasOwnProperty = Object.prototype.hasOwnProperty; 160 | var propIsEnumerable = Object.prototype.propertyIsEnumerable; 161 | 162 | function toObject(val) { 163 | if (val === null || val === undefined) { 164 | throw new TypeError('Object.assign cannot be called with null or undefined'); 165 | } 166 | 167 | return Object(val); 168 | } 169 | 170 | function shouldUseNative() { 171 | try { 172 | if (!Object.assign) { 173 | return false; 174 | } 175 | 176 | // Detect buggy property enumeration order in older V8 versions. 177 | 178 | // https://bugs.chromium.org/p/v8/issues/detail?id=4118 179 | var test1 = new String('abc'); // eslint-disable-line no-new-wrappers 180 | test1[5] = 'de'; 181 | if (Object.getOwnPropertyNames(test1)[0] === '5') { 182 | return false; 183 | } 184 | 185 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056 186 | var test2 = {}; 187 | for (var i = 0; i < 10; i++) { 188 | test2['_' + String.fromCharCode(i)] = i; 189 | } 190 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) { 191 | return test2[n]; 192 | }); 193 | if (order2.join('') !== '0123456789') { 194 | return false; 195 | } 196 | 197 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056 198 | var test3 = {}; 199 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { 200 | test3[letter] = letter; 201 | }); 202 | if (Object.keys(Object.assign({}, test3)).join('') !== 203 | 'abcdefghijklmnopqrst') { 204 | return false; 205 | } 206 | 207 | return true; 208 | } catch (err) { 209 | // We don't expect any of the above to throw, but better to be safe. 210 | return false; 211 | } 212 | } 213 | 214 | var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { 215 | var from; 216 | var to = toObject(target); 217 | var symbols; 218 | 219 | for (var s = 1; s < arguments.length; s++) { 220 | from = Object(arguments[s]); 221 | 222 | for (var key in from) { 223 | if (hasOwnProperty.call(from, key)) { 224 | to[key] = from[key]; 225 | } 226 | } 227 | 228 | if (getOwnPropertySymbols) { 229 | symbols = getOwnPropertySymbols(from); 230 | for (var i = 0; i < symbols.length; i++) { 231 | if (propIsEnumerable.call(from, symbols[i])) { 232 | to[symbols[i]] = from[symbols[i]]; 233 | } 234 | } 235 | } 236 | } 237 | 238 | return to; 239 | }; 240 | 241 | /** 242 | * Copyright (c) 2013-present, Facebook, Inc. 243 | * 244 | * This source code is licensed under the MIT license found in the 245 | * LICENSE file in the root directory of this source tree. 246 | */ 247 | 248 | var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; 249 | 250 | var ReactPropTypesSecret_1 = ReactPropTypesSecret; 251 | 252 | if (undefined !== 'production') { 253 | var invariant$2 = invariant_1; 254 | var warning$1 = warning_1; 255 | var ReactPropTypesSecret$2 = ReactPropTypesSecret_1; 256 | var loggedTypeFailures = {}; 257 | } 258 | 259 | /** 260 | * Assert that the values match with the type specs. 261 | * Error messages are memorized and will only be shown once. 262 | * 263 | * @param {object} typeSpecs Map of name to a ReactPropType 264 | * @param {object} values Runtime values that need to be type-checked 265 | * @param {string} location e.g. "prop", "context", "child context" 266 | * @param {string} componentName Name of the component for error messages. 267 | * @param {?Function} getStack Returns the component stack. 268 | * @private 269 | */ 270 | function checkPropTypes(typeSpecs, values, location, componentName, getStack) { 271 | if (undefined !== 'production') { 272 | for (var typeSpecName in typeSpecs) { 273 | if (typeSpecs.hasOwnProperty(typeSpecName)) { 274 | var error; 275 | // Prop type validation may throw. In case they do, we don't want to 276 | // fail the render phase where it didn't fail before. So we log it. 277 | // After these have been cleaned up, we'll let them throw. 278 | try { 279 | // This is intentionally an invariant that gets caught. It's the same 280 | // behavior as without this statement except with a better message. 281 | invariant$2(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]); 282 | error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$2); 283 | } catch (ex) { 284 | error = ex; 285 | } 286 | warning$1(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); 287 | if (error instanceof Error && !(error.message in loggedTypeFailures)) { 288 | // Only monitor this failure once because there tends to be a lot of the 289 | // same error. 290 | loggedTypeFailures[error.message] = true; 291 | 292 | var stack = getStack ? getStack() : ''; 293 | 294 | warning$1(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); 295 | } 296 | } 297 | } 298 | } 299 | } 300 | 301 | var checkPropTypes_1 = checkPropTypes; 302 | 303 | var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) { 304 | /* global Symbol */ 305 | var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; 306 | var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. 307 | 308 | /** 309 | * Returns the iterator method function contained on the iterable object. 310 | * 311 | * Be sure to invoke the function with the iterable as context: 312 | * 313 | * var iteratorFn = getIteratorFn(myIterable); 314 | * if (iteratorFn) { 315 | * var iterator = iteratorFn.call(myIterable); 316 | * ... 317 | * } 318 | * 319 | * @param {?object} maybeIterable 320 | * @return {?function} 321 | */ 322 | function getIteratorFn(maybeIterable) { 323 | var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); 324 | if (typeof iteratorFn === 'function') { 325 | return iteratorFn; 326 | } 327 | } 328 | 329 | /** 330 | * Collection of methods that allow declaration and validation of props that are 331 | * supplied to React components. Example usage: 332 | * 333 | * var Props = require('ReactPropTypes'); 334 | * var MyArticle = React.createClass({ 335 | * propTypes: { 336 | * // An optional string prop named "description". 337 | * description: Props.string, 338 | * 339 | * // A required enum prop named "category". 340 | * category: Props.oneOf(['News','Photos']).isRequired, 341 | * 342 | * // A prop named "dialog" that requires an instance of Dialog. 343 | * dialog: Props.instanceOf(Dialog).isRequired 344 | * }, 345 | * render: function() { ... } 346 | * }); 347 | * 348 | * A more formal specification of how these methods are used: 349 | * 350 | * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) 351 | * decl := ReactPropTypes.{type}(.isRequired)? 352 | * 353 | * Each and every declaration produces a function with the same signature. This 354 | * allows the creation of custom validation functions. For example: 355 | * 356 | * var MyLink = React.createClass({ 357 | * propTypes: { 358 | * // An optional string or URI prop named "href". 359 | * href: function(props, propName, componentName) { 360 | * var propValue = props[propName]; 361 | * if (propValue != null && typeof propValue !== 'string' && 362 | * !(propValue instanceof URI)) { 363 | * return new Error( 364 | * 'Expected a string or an URI for ' + propName + ' in ' + 365 | * componentName 366 | * ); 367 | * } 368 | * } 369 | * }, 370 | * render: function() {...} 371 | * }); 372 | * 373 | * @internal 374 | */ 375 | 376 | var ANONYMOUS = '<>'; 377 | 378 | // Important! 379 | // Keep this list in sync with production version in `./factoryWithThrowingShims.js`. 380 | var ReactPropTypes = { 381 | array: createPrimitiveTypeChecker('array'), 382 | bool: createPrimitiveTypeChecker('boolean'), 383 | func: createPrimitiveTypeChecker('function'), 384 | number: createPrimitiveTypeChecker('number'), 385 | object: createPrimitiveTypeChecker('object'), 386 | string: createPrimitiveTypeChecker('string'), 387 | symbol: createPrimitiveTypeChecker('symbol'), 388 | 389 | any: createAnyTypeChecker(), 390 | arrayOf: createArrayOfTypeChecker, 391 | element: createElementTypeChecker(), 392 | instanceOf: createInstanceTypeChecker, 393 | node: createNodeChecker(), 394 | objectOf: createObjectOfTypeChecker, 395 | oneOf: createEnumTypeChecker, 396 | oneOfType: createUnionTypeChecker, 397 | shape: createShapeTypeChecker, 398 | exact: createStrictShapeTypeChecker, 399 | }; 400 | 401 | /** 402 | * inlined Object.is polyfill to avoid requiring consumers ship their own 403 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is 404 | */ 405 | /*eslint-disable no-self-compare*/ 406 | function is(x, y) { 407 | // SameValue algorithm 408 | if (x === y) { 409 | // Steps 1-5, 7-10 410 | // Steps 6.b-6.e: +0 != -0 411 | return x !== 0 || 1 / x === 1 / y; 412 | } else { 413 | // Step 6.a: NaN == NaN 414 | return x !== x && y !== y; 415 | } 416 | } 417 | /*eslint-enable no-self-compare*/ 418 | 419 | /** 420 | * We use an Error-like object for backward compatibility as people may call 421 | * PropTypes directly and inspect their output. However, we don't use real 422 | * Errors anymore. We don't inspect their stack anyway, and creating them 423 | * is prohibitively expensive if they are created too often, such as what 424 | * happens in oneOfType() for any type before the one that matched. 425 | */ 426 | function PropTypeError(message) { 427 | this.message = message; 428 | this.stack = ''; 429 | } 430 | // Make `instanceof Error` still work for returned errors. 431 | PropTypeError.prototype = Error.prototype; 432 | 433 | function createChainableTypeChecker(validate) { 434 | if (undefined !== 'production') { 435 | var manualPropTypeCallCache = {}; 436 | var manualPropTypeWarningCount = 0; 437 | } 438 | function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { 439 | componentName = componentName || ANONYMOUS; 440 | propFullName = propFullName || propName; 441 | 442 | if (secret !== ReactPropTypesSecret_1) { 443 | if (throwOnDirectAccess) { 444 | // New behavior only for users of `prop-types` package 445 | invariant_1( 446 | false, 447 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 448 | 'Use `PropTypes.checkPropTypes()` to call them. ' + 449 | 'Read more at http://fb.me/use-check-prop-types' 450 | ); 451 | } else if (undefined !== 'production' && typeof console !== 'undefined') { 452 | // Old behavior for people using React.PropTypes 453 | var cacheKey = componentName + ':' + propName; 454 | if ( 455 | !manualPropTypeCallCache[cacheKey] && 456 | // Avoid spamming the console because they are often not actionable except for lib authors 457 | manualPropTypeWarningCount < 3 458 | ) { 459 | warning_1( 460 | false, 461 | 'You are manually calling a React.PropTypes validation ' + 462 | 'function for the `%s` prop on `%s`. This is deprecated ' + 463 | 'and will throw in the standalone `prop-types` package. ' + 464 | 'You may be seeing this warning due to a third-party PropTypes ' + 465 | 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', 466 | propFullName, 467 | componentName 468 | ); 469 | manualPropTypeCallCache[cacheKey] = true; 470 | manualPropTypeWarningCount++; 471 | } 472 | } 473 | } 474 | if (props[propName] == null) { 475 | if (isRequired) { 476 | if (props[propName] === null) { 477 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); 478 | } 479 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); 480 | } 481 | return null; 482 | } else { 483 | return validate(props, propName, componentName, location, propFullName); 484 | } 485 | } 486 | 487 | var chainedCheckType = checkType.bind(null, false); 488 | chainedCheckType.isRequired = checkType.bind(null, true); 489 | 490 | return chainedCheckType; 491 | } 492 | 493 | function createPrimitiveTypeChecker(expectedType) { 494 | function validate(props, propName, componentName, location, propFullName, secret) { 495 | var propValue = props[propName]; 496 | var propType = getPropType(propValue); 497 | if (propType !== expectedType) { 498 | // `propValue` being instance of, say, date/regexp, pass the 'object' 499 | // check, but we can offer a more precise error message here rather than 500 | // 'of type `object`'. 501 | var preciseType = getPreciseType(propValue); 502 | 503 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); 504 | } 505 | return null; 506 | } 507 | return createChainableTypeChecker(validate); 508 | } 509 | 510 | function createAnyTypeChecker() { 511 | return createChainableTypeChecker(emptyFunction_1.thatReturnsNull); 512 | } 513 | 514 | function createArrayOfTypeChecker(typeChecker) { 515 | function validate(props, propName, componentName, location, propFullName) { 516 | if (typeof typeChecker !== 'function') { 517 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); 518 | } 519 | var propValue = props[propName]; 520 | if (!Array.isArray(propValue)) { 521 | var propType = getPropType(propValue); 522 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); 523 | } 524 | for (var i = 0; i < propValue.length; i++) { 525 | var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1); 526 | if (error instanceof Error) { 527 | return error; 528 | } 529 | } 530 | return null; 531 | } 532 | return createChainableTypeChecker(validate); 533 | } 534 | 535 | function createElementTypeChecker() { 536 | function validate(props, propName, componentName, location, propFullName) { 537 | var propValue = props[propName]; 538 | if (!isValidElement(propValue)) { 539 | var propType = getPropType(propValue); 540 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); 541 | } 542 | return null; 543 | } 544 | return createChainableTypeChecker(validate); 545 | } 546 | 547 | function createInstanceTypeChecker(expectedClass) { 548 | function validate(props, propName, componentName, location, propFullName) { 549 | if (!(props[propName] instanceof expectedClass)) { 550 | var expectedClassName = expectedClass.name || ANONYMOUS; 551 | var actualClassName = getClassName(props[propName]); 552 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); 553 | } 554 | return null; 555 | } 556 | return createChainableTypeChecker(validate); 557 | } 558 | 559 | function createEnumTypeChecker(expectedValues) { 560 | if (!Array.isArray(expectedValues)) { 561 | undefined !== 'production' ? warning_1(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0; 562 | return emptyFunction_1.thatReturnsNull; 563 | } 564 | 565 | function validate(props, propName, componentName, location, propFullName) { 566 | var propValue = props[propName]; 567 | for (var i = 0; i < expectedValues.length; i++) { 568 | if (is(propValue, expectedValues[i])) { 569 | return null; 570 | } 571 | } 572 | 573 | var valuesString = JSON.stringify(expectedValues); 574 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); 575 | } 576 | return createChainableTypeChecker(validate); 577 | } 578 | 579 | function createObjectOfTypeChecker(typeChecker) { 580 | function validate(props, propName, componentName, location, propFullName) { 581 | if (typeof typeChecker !== 'function') { 582 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); 583 | } 584 | var propValue = props[propName]; 585 | var propType = getPropType(propValue); 586 | if (propType !== 'object') { 587 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); 588 | } 589 | for (var key in propValue) { 590 | if (propValue.hasOwnProperty(key)) { 591 | var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); 592 | if (error instanceof Error) { 593 | return error; 594 | } 595 | } 596 | } 597 | return null; 598 | } 599 | return createChainableTypeChecker(validate); 600 | } 601 | 602 | function createUnionTypeChecker(arrayOfTypeCheckers) { 603 | if (!Array.isArray(arrayOfTypeCheckers)) { 604 | undefined !== 'production' ? warning_1(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; 605 | return emptyFunction_1.thatReturnsNull; 606 | } 607 | 608 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) { 609 | var checker = arrayOfTypeCheckers[i]; 610 | if (typeof checker !== 'function') { 611 | warning_1( 612 | false, 613 | 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + 614 | 'received %s at index %s.', 615 | getPostfixForTypeWarning(checker), 616 | i 617 | ); 618 | return emptyFunction_1.thatReturnsNull; 619 | } 620 | } 621 | 622 | function validate(props, propName, componentName, location, propFullName) { 623 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) { 624 | var checker = arrayOfTypeCheckers[i]; 625 | if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) { 626 | return null; 627 | } 628 | } 629 | 630 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); 631 | } 632 | return createChainableTypeChecker(validate); 633 | } 634 | 635 | function createNodeChecker() { 636 | function validate(props, propName, componentName, location, propFullName) { 637 | if (!isNode(props[propName])) { 638 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); 639 | } 640 | return null; 641 | } 642 | return createChainableTypeChecker(validate); 643 | } 644 | 645 | function createShapeTypeChecker(shapeTypes) { 646 | function validate(props, propName, componentName, location, propFullName) { 647 | var propValue = props[propName]; 648 | var propType = getPropType(propValue); 649 | if (propType !== 'object') { 650 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); 651 | } 652 | for (var key in shapeTypes) { 653 | var checker = shapeTypes[key]; 654 | if (!checker) { 655 | continue; 656 | } 657 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); 658 | if (error) { 659 | return error; 660 | } 661 | } 662 | return null; 663 | } 664 | return createChainableTypeChecker(validate); 665 | } 666 | 667 | function createStrictShapeTypeChecker(shapeTypes) { 668 | function validate(props, propName, componentName, location, propFullName) { 669 | var propValue = props[propName]; 670 | var propType = getPropType(propValue); 671 | if (propType !== 'object') { 672 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); 673 | } 674 | // We need to check all keys in case some are required but missing from 675 | // props. 676 | var allKeys = objectAssign({}, props[propName], shapeTypes); 677 | for (var key in allKeys) { 678 | var checker = shapeTypes[key]; 679 | if (!checker) { 680 | return new PropTypeError( 681 | 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + 682 | '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + 683 | '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') 684 | ); 685 | } 686 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); 687 | if (error) { 688 | return error; 689 | } 690 | } 691 | return null; 692 | } 693 | 694 | return createChainableTypeChecker(validate); 695 | } 696 | 697 | function isNode(propValue) { 698 | switch (typeof propValue) { 699 | case 'number': 700 | case 'string': 701 | case 'undefined': 702 | return true; 703 | case 'boolean': 704 | return !propValue; 705 | case 'object': 706 | if (Array.isArray(propValue)) { 707 | return propValue.every(isNode); 708 | } 709 | if (propValue === null || isValidElement(propValue)) { 710 | return true; 711 | } 712 | 713 | var iteratorFn = getIteratorFn(propValue); 714 | if (iteratorFn) { 715 | var iterator = iteratorFn.call(propValue); 716 | var step; 717 | if (iteratorFn !== propValue.entries) { 718 | while (!(step = iterator.next()).done) { 719 | if (!isNode(step.value)) { 720 | return false; 721 | } 722 | } 723 | } else { 724 | // Iterator will provide entry [k,v] tuples rather than values. 725 | while (!(step = iterator.next()).done) { 726 | var entry = step.value; 727 | if (entry) { 728 | if (!isNode(entry[1])) { 729 | return false; 730 | } 731 | } 732 | } 733 | } 734 | } else { 735 | return false; 736 | } 737 | 738 | return true; 739 | default: 740 | return false; 741 | } 742 | } 743 | 744 | function isSymbol(propType, propValue) { 745 | // Native Symbol. 746 | if (propType === 'symbol') { 747 | return true; 748 | } 749 | 750 | // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' 751 | if (propValue['@@toStringTag'] === 'Symbol') { 752 | return true; 753 | } 754 | 755 | // Fallback for non-spec compliant Symbols which are polyfilled. 756 | if (typeof Symbol === 'function' && propValue instanceof Symbol) { 757 | return true; 758 | } 759 | 760 | return false; 761 | } 762 | 763 | // Equivalent of `typeof` but with special handling for array and regexp. 764 | function getPropType(propValue) { 765 | var propType = typeof propValue; 766 | if (Array.isArray(propValue)) { 767 | return 'array'; 768 | } 769 | if (propValue instanceof RegExp) { 770 | // Old webkits (at least until Android 4.0) return 'function' rather than 771 | // 'object' for typeof a RegExp. We'll normalize this here so that /bla/ 772 | // passes PropTypes.object. 773 | return 'object'; 774 | } 775 | if (isSymbol(propType, propValue)) { 776 | return 'symbol'; 777 | } 778 | return propType; 779 | } 780 | 781 | // This handles more types than `getPropType`. Only used for error messages. 782 | // See `createPrimitiveTypeChecker`. 783 | function getPreciseType(propValue) { 784 | if (typeof propValue === 'undefined' || propValue === null) { 785 | return '' + propValue; 786 | } 787 | var propType = getPropType(propValue); 788 | if (propType === 'object') { 789 | if (propValue instanceof Date) { 790 | return 'date'; 791 | } else if (propValue instanceof RegExp) { 792 | return 'regexp'; 793 | } 794 | } 795 | return propType; 796 | } 797 | 798 | // Returns a string that is postfixed to a warning about an invalid type. 799 | // For example, "undefined" or "of type array" 800 | function getPostfixForTypeWarning(value) { 801 | var type = getPreciseType(value); 802 | switch (type) { 803 | case 'array': 804 | case 'object': 805 | return 'an ' + type; 806 | case 'boolean': 807 | case 'date': 808 | case 'regexp': 809 | return 'a ' + type; 810 | default: 811 | return type; 812 | } 813 | } 814 | 815 | // Returns class name of the object, if any. 816 | function getClassName(propValue) { 817 | if (!propValue.constructor || !propValue.constructor.name) { 818 | return ANONYMOUS; 819 | } 820 | return propValue.constructor.name; 821 | } 822 | 823 | ReactPropTypes.checkPropTypes = checkPropTypes_1; 824 | ReactPropTypes.PropTypes = ReactPropTypes; 825 | 826 | return ReactPropTypes; 827 | }; 828 | 829 | var factoryWithThrowingShims = function() { 830 | function shim(props, propName, componentName, location, propFullName, secret) { 831 | if (secret === ReactPropTypesSecret_1) { 832 | // It is still safe when called from React. 833 | return; 834 | } 835 | invariant_1( 836 | false, 837 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 838 | 'Use PropTypes.checkPropTypes() to call them. ' + 839 | 'Read more at http://fb.me/use-check-prop-types' 840 | ); 841 | } 842 | shim.isRequired = shim; 843 | function getShim() { 844 | return shim; 845 | } 846 | // Important! 847 | // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`. 848 | var ReactPropTypes = { 849 | array: shim, 850 | bool: shim, 851 | func: shim, 852 | number: shim, 853 | object: shim, 854 | string: shim, 855 | symbol: shim, 856 | 857 | any: shim, 858 | arrayOf: getShim, 859 | element: shim, 860 | instanceOf: getShim, 861 | node: shim, 862 | objectOf: getShim, 863 | oneOf: getShim, 864 | oneOfType: getShim, 865 | shape: getShim, 866 | exact: getShim 867 | }; 868 | 869 | ReactPropTypes.checkPropTypes = emptyFunction_1; 870 | ReactPropTypes.PropTypes = ReactPropTypes; 871 | 872 | return ReactPropTypes; 873 | }; 874 | 875 | var propTypes = createCommonjsModule(function (module) { 876 | /** 877 | * Copyright (c) 2013-present, Facebook, Inc. 878 | * 879 | * This source code is licensed under the MIT license found in the 880 | * LICENSE file in the root directory of this source tree. 881 | */ 882 | 883 | if (undefined !== 'production') { 884 | var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && 885 | Symbol.for && 886 | Symbol.for('react.element')) || 887 | 0xeac7; 888 | 889 | var isValidElement = function(object) { 890 | return typeof object === 'object' && 891 | object !== null && 892 | object.$$typeof === REACT_ELEMENT_TYPE; 893 | }; 894 | 895 | // By explicitly using `prop-types` you are opting into new development behavior. 896 | // http://fb.me/prop-types-in-prod 897 | var throwOnDirectAccess = true; 898 | module.exports = factoryWithTypeCheckers(isValidElement, throwOnDirectAccess); 899 | } else { 900 | // By explicitly using `prop-types` you are opting into new production behavior. 901 | // http://fb.me/prop-types-in-prod 902 | module.exports = factoryWithThrowingShims(); 903 | } 904 | }); 905 | 906 | function equalByKeys(objA, objB, ...keys) { 907 | return !keys.some(key => objA[key] !== objB[key]) 908 | } 909 | 910 | function createCommonjsModule$1(fn, module) { 911 | return module = { exports: {} }, fn(module, module.exports), module.exports; 912 | } 913 | 914 | /** 915 | * Copyright (c) 2013-present, Facebook, Inc. 916 | * 917 | * This source code is licensed under the MIT license found in the 918 | * LICENSE file in the root directory of this source tree. 919 | * 920 | * 921 | */ 922 | 923 | function makeEmptyFunction$1(arg) { 924 | return function () { 925 | return arg; 926 | }; 927 | } 928 | 929 | /** 930 | * This function accepts and discards inputs; it has no side effects. This is 931 | * primarily useful idiomatically for overridable function endpoints which 932 | * always need to be callable, since JS lacks a null-call idiom ala Cocoa. 933 | */ 934 | var emptyFunction$2 = function emptyFunction() {}; 935 | 936 | emptyFunction$2.thatReturns = makeEmptyFunction$1; 937 | emptyFunction$2.thatReturnsFalse = makeEmptyFunction$1(false); 938 | emptyFunction$2.thatReturnsTrue = makeEmptyFunction$1(true); 939 | emptyFunction$2.thatReturnsNull = makeEmptyFunction$1(null); 940 | emptyFunction$2.thatReturnsThis = function () { 941 | return this; 942 | }; 943 | emptyFunction$2.thatReturnsArgument = function (arg) { 944 | return arg; 945 | }; 946 | 947 | var emptyFunction_1$2 = emptyFunction$2; 948 | 949 | /** 950 | * Copyright (c) 2013-present, Facebook, Inc. 951 | * 952 | * This source code is licensed under the MIT license found in the 953 | * LICENSE file in the root directory of this source tree. 954 | * 955 | */ 956 | 957 | /** 958 | * Use invariant() to assert state which your program assumes to be true. 959 | * 960 | * Provide sprintf-style format (only %s is supported) and arguments 961 | * to provide information about what broke and what you were 962 | * expecting. 963 | * 964 | * The invariant message will be stripped in production, but the invariant 965 | * will remain to ensure logic does not differ in production. 966 | */ 967 | 968 | var validateFormat$1 = function validateFormat(format) {}; 969 | 970 | if (undefined !== 'production') { 971 | validateFormat$1 = function validateFormat(format) { 972 | if (format === undefined) { 973 | throw new Error('invariant requires an error message argument'); 974 | } 975 | }; 976 | } 977 | 978 | function invariant$3(condition, format, a, b, c, d, e, f) { 979 | validateFormat$1(format); 980 | 981 | if (!condition) { 982 | var error; 983 | if (format === undefined) { 984 | error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); 985 | } else { 986 | var args = [a, b, c, d, e, f]; 987 | var argIndex = 0; 988 | error = new Error(format.replace(/%s/g, function () { 989 | return args[argIndex++]; 990 | })); 991 | error.name = 'Invariant Violation'; 992 | } 993 | 994 | error.framesToPop = 1; // we don't care about invariant's own frame 995 | throw error; 996 | } 997 | } 998 | 999 | var invariant_1$2 = invariant$3; 1000 | 1001 | /** 1002 | * Similar to invariant but only logs a warning if the condition is not met. 1003 | * This can be used to log issues in development environments in critical 1004 | * paths. Removing the logging code for production environments will keep the 1005 | * same logic and follow the same code paths. 1006 | */ 1007 | 1008 | var warning$2 = emptyFunction_1$2; 1009 | 1010 | if (undefined !== 'production') { 1011 | var printWarning$1 = function printWarning(format) { 1012 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 1013 | args[_key - 1] = arguments[_key]; 1014 | } 1015 | 1016 | var argIndex = 0; 1017 | var message = 'Warning: ' + format.replace(/%s/g, function () { 1018 | return args[argIndex++]; 1019 | }); 1020 | if (typeof console !== 'undefined') { 1021 | console.error(message); 1022 | } 1023 | try { 1024 | // --- Welcome to debugging React --- 1025 | // This error was thrown as a convenience so that you can use this stack 1026 | // to find the callsite that caused this warning to fire. 1027 | throw new Error(message); 1028 | } catch (x) {} 1029 | }; 1030 | 1031 | warning$2 = function warning(condition, format) { 1032 | if (format === undefined) { 1033 | throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); 1034 | } 1035 | 1036 | if (format.indexOf('Failed Composite propType: ') === 0) { 1037 | return; // Ignore CompositeComponent proptype check. 1038 | } 1039 | 1040 | if (!condition) { 1041 | for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { 1042 | args[_key2 - 2] = arguments[_key2]; 1043 | } 1044 | 1045 | printWarning$1.apply(undefined, [format].concat(args)); 1046 | } 1047 | }; 1048 | } 1049 | 1050 | var warning_1$2 = warning$2; 1051 | 1052 | /* 1053 | object-assign 1054 | (c) Sindre Sorhus 1055 | @license MIT 1056 | */ 1057 | 1058 | /* eslint-disable no-unused-vars */ 1059 | var getOwnPropertySymbols$1 = Object.getOwnPropertySymbols; 1060 | var hasOwnProperty$1 = Object.prototype.hasOwnProperty; 1061 | var propIsEnumerable$1 = Object.prototype.propertyIsEnumerable; 1062 | 1063 | function toObject$1(val) { 1064 | if (val === null || val === undefined) { 1065 | throw new TypeError('Object.assign cannot be called with null or undefined'); 1066 | } 1067 | 1068 | return Object(val); 1069 | } 1070 | 1071 | function shouldUseNative$1() { 1072 | try { 1073 | if (!Object.assign) { 1074 | return false; 1075 | } 1076 | 1077 | // Detect buggy property enumeration order in older V8 versions. 1078 | 1079 | // https://bugs.chromium.org/p/v8/issues/detail?id=4118 1080 | var test1 = new String('abc'); // eslint-disable-line no-new-wrappers 1081 | test1[5] = 'de'; 1082 | if (Object.getOwnPropertyNames(test1)[0] === '5') { 1083 | return false; 1084 | } 1085 | 1086 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056 1087 | var test2 = {}; 1088 | for (var i = 0; i < 10; i++) { 1089 | test2['_' + String.fromCharCode(i)] = i; 1090 | } 1091 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) { 1092 | return test2[n]; 1093 | }); 1094 | if (order2.join('') !== '0123456789') { 1095 | return false; 1096 | } 1097 | 1098 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056 1099 | var test3 = {}; 1100 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { 1101 | test3[letter] = letter; 1102 | }); 1103 | if (Object.keys(Object.assign({}, test3)).join('') !== 1104 | 'abcdefghijklmnopqrst') { 1105 | return false; 1106 | } 1107 | 1108 | return true; 1109 | } catch (err) { 1110 | // We don't expect any of the above to throw, but better to be safe. 1111 | return false; 1112 | } 1113 | } 1114 | 1115 | var objectAssign$2 = shouldUseNative$1() ? Object.assign : function (target, source) { 1116 | var from; 1117 | var to = toObject$1(target); 1118 | var symbols; 1119 | 1120 | for (var s = 1; s < arguments.length; s++) { 1121 | from = Object(arguments[s]); 1122 | 1123 | for (var key in from) { 1124 | if (hasOwnProperty$1.call(from, key)) { 1125 | to[key] = from[key]; 1126 | } 1127 | } 1128 | 1129 | if (getOwnPropertySymbols$1) { 1130 | symbols = getOwnPropertySymbols$1(from); 1131 | for (var i = 0; i < symbols.length; i++) { 1132 | if (propIsEnumerable$1.call(from, symbols[i])) { 1133 | to[symbols[i]] = from[symbols[i]]; 1134 | } 1135 | } 1136 | } 1137 | } 1138 | 1139 | return to; 1140 | }; 1141 | 1142 | /** 1143 | * Copyright (c) 2013-present, Facebook, Inc. 1144 | * 1145 | * This source code is licensed under the MIT license found in the 1146 | * LICENSE file in the root directory of this source tree. 1147 | */ 1148 | 1149 | var ReactPropTypesSecret$3 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; 1150 | 1151 | var ReactPropTypesSecret_1$2 = ReactPropTypesSecret$3; 1152 | 1153 | if (undefined !== 'production') { 1154 | var invariant$2$1 = invariant_1$2; 1155 | var warning$1$1 = warning_1$2; 1156 | var ReactPropTypesSecret$2$1 = ReactPropTypesSecret_1$2; 1157 | var loggedTypeFailures$1 = {}; 1158 | } 1159 | 1160 | /** 1161 | * Assert that the values match with the type specs. 1162 | * Error messages are memorized and will only be shown once. 1163 | * 1164 | * @param {object} typeSpecs Map of name to a ReactPropType 1165 | * @param {object} values Runtime values that need to be type-checked 1166 | * @param {string} location e.g. "prop", "context", "child context" 1167 | * @param {string} componentName Name of the component for error messages. 1168 | * @param {?Function} getStack Returns the component stack. 1169 | * @private 1170 | */ 1171 | function checkPropTypes$2(typeSpecs, values, location, componentName, getStack) { 1172 | if (undefined !== 'production') { 1173 | for (var typeSpecName in typeSpecs) { 1174 | if (typeSpecs.hasOwnProperty(typeSpecName)) { 1175 | var error; 1176 | // Prop type validation may throw. In case they do, we don't want to 1177 | // fail the render phase where it didn't fail before. So we log it. 1178 | // After these have been cleaned up, we'll let them throw. 1179 | try { 1180 | // This is intentionally an invariant that gets caught. It's the same 1181 | // behavior as without this statement except with a better message. 1182 | invariant$2$1(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]); 1183 | error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$2$1); 1184 | } catch (ex) { 1185 | error = ex; 1186 | } 1187 | warning$1$1(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); 1188 | if (error instanceof Error && !(error.message in loggedTypeFailures$1)) { 1189 | // Only monitor this failure once because there tends to be a lot of the 1190 | // same error. 1191 | loggedTypeFailures$1[error.message] = true; 1192 | 1193 | var stack = getStack ? getStack() : ''; 1194 | 1195 | warning$1$1(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); 1196 | } 1197 | } 1198 | } 1199 | } 1200 | } 1201 | 1202 | var checkPropTypes_1$2 = checkPropTypes$2; 1203 | 1204 | var factoryWithTypeCheckers$2 = function(isValidElement, throwOnDirectAccess) { 1205 | /* global Symbol */ 1206 | var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; 1207 | var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. 1208 | 1209 | /** 1210 | * Returns the iterator method function contained on the iterable object. 1211 | * 1212 | * Be sure to invoke the function with the iterable as context: 1213 | * 1214 | * var iteratorFn = getIteratorFn(myIterable); 1215 | * if (iteratorFn) { 1216 | * var iterator = iteratorFn.call(myIterable); 1217 | * ... 1218 | * } 1219 | * 1220 | * @param {?object} maybeIterable 1221 | * @return {?function} 1222 | */ 1223 | function getIteratorFn(maybeIterable) { 1224 | var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); 1225 | if (typeof iteratorFn === 'function') { 1226 | return iteratorFn; 1227 | } 1228 | } 1229 | 1230 | /** 1231 | * Collection of methods that allow declaration and validation of props that are 1232 | * supplied to React components. Example usage: 1233 | * 1234 | * var Props = require('ReactPropTypes'); 1235 | * var MyArticle = React.createClass({ 1236 | * propTypes: { 1237 | * // An optional string prop named "description". 1238 | * description: Props.string, 1239 | * 1240 | * // A required enum prop named "category". 1241 | * category: Props.oneOf(['News','Photos']).isRequired, 1242 | * 1243 | * // A prop named "dialog" that requires an instance of Dialog. 1244 | * dialog: Props.instanceOf(Dialog).isRequired 1245 | * }, 1246 | * render: function() { ... } 1247 | * }); 1248 | * 1249 | * A more formal specification of how these methods are used: 1250 | * 1251 | * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) 1252 | * decl := ReactPropTypes.{type}(.isRequired)? 1253 | * 1254 | * Each and every declaration produces a function with the same signature. This 1255 | * allows the creation of custom validation functions. For example: 1256 | * 1257 | * var MyLink = React.createClass({ 1258 | * propTypes: { 1259 | * // An optional string or URI prop named "href". 1260 | * href: function(props, propName, componentName) { 1261 | * var propValue = props[propName]; 1262 | * if (propValue != null && typeof propValue !== 'string' && 1263 | * !(propValue instanceof URI)) { 1264 | * return new Error( 1265 | * 'Expected a string or an URI for ' + propName + ' in ' + 1266 | * componentName 1267 | * ); 1268 | * } 1269 | * } 1270 | * }, 1271 | * render: function() {...} 1272 | * }); 1273 | * 1274 | * @internal 1275 | */ 1276 | 1277 | var ANONYMOUS = '<>'; 1278 | 1279 | // Important! 1280 | // Keep this list in sync with production version in `./factoryWithThrowingShims.js`. 1281 | var ReactPropTypes = { 1282 | array: createPrimitiveTypeChecker('array'), 1283 | bool: createPrimitiveTypeChecker('boolean'), 1284 | func: createPrimitiveTypeChecker('function'), 1285 | number: createPrimitiveTypeChecker('number'), 1286 | object: createPrimitiveTypeChecker('object'), 1287 | string: createPrimitiveTypeChecker('string'), 1288 | symbol: createPrimitiveTypeChecker('symbol'), 1289 | 1290 | any: createAnyTypeChecker(), 1291 | arrayOf: createArrayOfTypeChecker, 1292 | element: createElementTypeChecker(), 1293 | instanceOf: createInstanceTypeChecker, 1294 | node: createNodeChecker(), 1295 | objectOf: createObjectOfTypeChecker, 1296 | oneOf: createEnumTypeChecker, 1297 | oneOfType: createUnionTypeChecker, 1298 | shape: createShapeTypeChecker, 1299 | exact: createStrictShapeTypeChecker, 1300 | }; 1301 | 1302 | /** 1303 | * inlined Object.is polyfill to avoid requiring consumers ship their own 1304 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is 1305 | */ 1306 | /*eslint-disable no-self-compare*/ 1307 | function is(x, y) { 1308 | // SameValue algorithm 1309 | if (x === y) { 1310 | // Steps 1-5, 7-10 1311 | // Steps 6.b-6.e: +0 != -0 1312 | return x !== 0 || 1 / x === 1 / y; 1313 | } else { 1314 | // Step 6.a: NaN == NaN 1315 | return x !== x && y !== y; 1316 | } 1317 | } 1318 | /*eslint-enable no-self-compare*/ 1319 | 1320 | /** 1321 | * We use an Error-like object for backward compatibility as people may call 1322 | * PropTypes directly and inspect their output. However, we don't use real 1323 | * Errors anymore. We don't inspect their stack anyway, and creating them 1324 | * is prohibitively expensive if they are created too often, such as what 1325 | * happens in oneOfType() for any type before the one that matched. 1326 | */ 1327 | function PropTypeError(message) { 1328 | this.message = message; 1329 | this.stack = ''; 1330 | } 1331 | // Make `instanceof Error` still work for returned errors. 1332 | PropTypeError.prototype = Error.prototype; 1333 | 1334 | function createChainableTypeChecker(validate) { 1335 | if (undefined !== 'production') { 1336 | var manualPropTypeCallCache = {}; 1337 | var manualPropTypeWarningCount = 0; 1338 | } 1339 | function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { 1340 | componentName = componentName || ANONYMOUS; 1341 | propFullName = propFullName || propName; 1342 | 1343 | if (secret !== ReactPropTypesSecret_1$2) { 1344 | if (throwOnDirectAccess) { 1345 | // New behavior only for users of `prop-types` package 1346 | invariant_1$2( 1347 | false, 1348 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 1349 | 'Use `PropTypes.checkPropTypes()` to call them. ' + 1350 | 'Read more at http://fb.me/use-check-prop-types' 1351 | ); 1352 | } else if (undefined !== 'production' && typeof console !== 'undefined') { 1353 | // Old behavior for people using React.PropTypes 1354 | var cacheKey = componentName + ':' + propName; 1355 | if ( 1356 | !manualPropTypeCallCache[cacheKey] && 1357 | // Avoid spamming the console because they are often not actionable except for lib authors 1358 | manualPropTypeWarningCount < 3 1359 | ) { 1360 | warning_1$2( 1361 | false, 1362 | 'You are manually calling a React.PropTypes validation ' + 1363 | 'function for the `%s` prop on `%s`. This is deprecated ' + 1364 | 'and will throw in the standalone `prop-types` package. ' + 1365 | 'You may be seeing this warning due to a third-party PropTypes ' + 1366 | 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', 1367 | propFullName, 1368 | componentName 1369 | ); 1370 | manualPropTypeCallCache[cacheKey] = true; 1371 | manualPropTypeWarningCount++; 1372 | } 1373 | } 1374 | } 1375 | if (props[propName] == null) { 1376 | if (isRequired) { 1377 | if (props[propName] === null) { 1378 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); 1379 | } 1380 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); 1381 | } 1382 | return null; 1383 | } else { 1384 | return validate(props, propName, componentName, location, propFullName); 1385 | } 1386 | } 1387 | 1388 | var chainedCheckType = checkType.bind(null, false); 1389 | chainedCheckType.isRequired = checkType.bind(null, true); 1390 | 1391 | return chainedCheckType; 1392 | } 1393 | 1394 | function createPrimitiveTypeChecker(expectedType) { 1395 | function validate(props, propName, componentName, location, propFullName, secret) { 1396 | var propValue = props[propName]; 1397 | var propType = getPropType(propValue); 1398 | if (propType !== expectedType) { 1399 | // `propValue` being instance of, say, date/regexp, pass the 'object' 1400 | // check, but we can offer a more precise error message here rather than 1401 | // 'of type `object`'. 1402 | var preciseType = getPreciseType(propValue); 1403 | 1404 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); 1405 | } 1406 | return null; 1407 | } 1408 | return createChainableTypeChecker(validate); 1409 | } 1410 | 1411 | function createAnyTypeChecker() { 1412 | return createChainableTypeChecker(emptyFunction_1$2.thatReturnsNull); 1413 | } 1414 | 1415 | function createArrayOfTypeChecker(typeChecker) { 1416 | function validate(props, propName, componentName, location, propFullName) { 1417 | if (typeof typeChecker !== 'function') { 1418 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); 1419 | } 1420 | var propValue = props[propName]; 1421 | if (!Array.isArray(propValue)) { 1422 | var propType = getPropType(propValue); 1423 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); 1424 | } 1425 | for (var i = 0; i < propValue.length; i++) { 1426 | var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1$2); 1427 | if (error instanceof Error) { 1428 | return error; 1429 | } 1430 | } 1431 | return null; 1432 | } 1433 | return createChainableTypeChecker(validate); 1434 | } 1435 | 1436 | function createElementTypeChecker() { 1437 | function validate(props, propName, componentName, location, propFullName) { 1438 | var propValue = props[propName]; 1439 | if (!isValidElement(propValue)) { 1440 | var propType = getPropType(propValue); 1441 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); 1442 | } 1443 | return null; 1444 | } 1445 | return createChainableTypeChecker(validate); 1446 | } 1447 | 1448 | function createInstanceTypeChecker(expectedClass) { 1449 | function validate(props, propName, componentName, location, propFullName) { 1450 | if (!(props[propName] instanceof expectedClass)) { 1451 | var expectedClassName = expectedClass.name || ANONYMOUS; 1452 | var actualClassName = getClassName(props[propName]); 1453 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); 1454 | } 1455 | return null; 1456 | } 1457 | return createChainableTypeChecker(validate); 1458 | } 1459 | 1460 | function createEnumTypeChecker(expectedValues) { 1461 | if (!Array.isArray(expectedValues)) { 1462 | undefined !== 'production' ? warning_1$2(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0; 1463 | return emptyFunction_1$2.thatReturnsNull; 1464 | } 1465 | 1466 | function validate(props, propName, componentName, location, propFullName) { 1467 | var propValue = props[propName]; 1468 | for (var i = 0; i < expectedValues.length; i++) { 1469 | if (is(propValue, expectedValues[i])) { 1470 | return null; 1471 | } 1472 | } 1473 | 1474 | var valuesString = JSON.stringify(expectedValues); 1475 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); 1476 | } 1477 | return createChainableTypeChecker(validate); 1478 | } 1479 | 1480 | function createObjectOfTypeChecker(typeChecker) { 1481 | function validate(props, propName, componentName, location, propFullName) { 1482 | if (typeof typeChecker !== 'function') { 1483 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); 1484 | } 1485 | var propValue = props[propName]; 1486 | var propType = getPropType(propValue); 1487 | if (propType !== 'object') { 1488 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); 1489 | } 1490 | for (var key in propValue) { 1491 | if (propValue.hasOwnProperty(key)) { 1492 | var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1$2); 1493 | if (error instanceof Error) { 1494 | return error; 1495 | } 1496 | } 1497 | } 1498 | return null; 1499 | } 1500 | return createChainableTypeChecker(validate); 1501 | } 1502 | 1503 | function createUnionTypeChecker(arrayOfTypeCheckers) { 1504 | if (!Array.isArray(arrayOfTypeCheckers)) { 1505 | undefined !== 'production' ? warning_1$2(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; 1506 | return emptyFunction_1$2.thatReturnsNull; 1507 | } 1508 | 1509 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) { 1510 | var checker = arrayOfTypeCheckers[i]; 1511 | if (typeof checker !== 'function') { 1512 | warning_1$2( 1513 | false, 1514 | 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + 1515 | 'received %s at index %s.', 1516 | getPostfixForTypeWarning(checker), 1517 | i 1518 | ); 1519 | return emptyFunction_1$2.thatReturnsNull; 1520 | } 1521 | } 1522 | 1523 | function validate(props, propName, componentName, location, propFullName) { 1524 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) { 1525 | var checker = arrayOfTypeCheckers[i]; 1526 | if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1$2) == null) { 1527 | return null; 1528 | } 1529 | } 1530 | 1531 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); 1532 | } 1533 | return createChainableTypeChecker(validate); 1534 | } 1535 | 1536 | function createNodeChecker() { 1537 | function validate(props, propName, componentName, location, propFullName) { 1538 | if (!isNode(props[propName])) { 1539 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); 1540 | } 1541 | return null; 1542 | } 1543 | return createChainableTypeChecker(validate); 1544 | } 1545 | 1546 | function createShapeTypeChecker(shapeTypes) { 1547 | function validate(props, propName, componentName, location, propFullName) { 1548 | var propValue = props[propName]; 1549 | var propType = getPropType(propValue); 1550 | if (propType !== 'object') { 1551 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); 1552 | } 1553 | for (var key in shapeTypes) { 1554 | var checker = shapeTypes[key]; 1555 | if (!checker) { 1556 | continue; 1557 | } 1558 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1$2); 1559 | if (error) { 1560 | return error; 1561 | } 1562 | } 1563 | return null; 1564 | } 1565 | return createChainableTypeChecker(validate); 1566 | } 1567 | 1568 | function createStrictShapeTypeChecker(shapeTypes) { 1569 | function validate(props, propName, componentName, location, propFullName) { 1570 | var propValue = props[propName]; 1571 | var propType = getPropType(propValue); 1572 | if (propType !== 'object') { 1573 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); 1574 | } 1575 | // We need to check all keys in case some are required but missing from 1576 | // props. 1577 | var allKeys = objectAssign$2({}, props[propName], shapeTypes); 1578 | for (var key in allKeys) { 1579 | var checker = shapeTypes[key]; 1580 | if (!checker) { 1581 | return new PropTypeError( 1582 | 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + 1583 | '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + 1584 | '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') 1585 | ); 1586 | } 1587 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1$2); 1588 | if (error) { 1589 | return error; 1590 | } 1591 | } 1592 | return null; 1593 | } 1594 | 1595 | return createChainableTypeChecker(validate); 1596 | } 1597 | 1598 | function isNode(propValue) { 1599 | switch (typeof propValue) { 1600 | case 'number': 1601 | case 'string': 1602 | case 'undefined': 1603 | return true; 1604 | case 'boolean': 1605 | return !propValue; 1606 | case 'object': 1607 | if (Array.isArray(propValue)) { 1608 | return propValue.every(isNode); 1609 | } 1610 | if (propValue === null || isValidElement(propValue)) { 1611 | return true; 1612 | } 1613 | 1614 | var iteratorFn = getIteratorFn(propValue); 1615 | if (iteratorFn) { 1616 | var iterator = iteratorFn.call(propValue); 1617 | var step; 1618 | if (iteratorFn !== propValue.entries) { 1619 | while (!(step = iterator.next()).done) { 1620 | if (!isNode(step.value)) { 1621 | return false; 1622 | } 1623 | } 1624 | } else { 1625 | // Iterator will provide entry [k,v] tuples rather than values. 1626 | while (!(step = iterator.next()).done) { 1627 | var entry = step.value; 1628 | if (entry) { 1629 | if (!isNode(entry[1])) { 1630 | return false; 1631 | } 1632 | } 1633 | } 1634 | } 1635 | } else { 1636 | return false; 1637 | } 1638 | 1639 | return true; 1640 | default: 1641 | return false; 1642 | } 1643 | } 1644 | 1645 | function isSymbol(propType, propValue) { 1646 | // Native Symbol. 1647 | if (propType === 'symbol') { 1648 | return true; 1649 | } 1650 | 1651 | // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' 1652 | if (propValue['@@toStringTag'] === 'Symbol') { 1653 | return true; 1654 | } 1655 | 1656 | // Fallback for non-spec compliant Symbols which are polyfilled. 1657 | if (typeof Symbol === 'function' && propValue instanceof Symbol) { 1658 | return true; 1659 | } 1660 | 1661 | return false; 1662 | } 1663 | 1664 | // Equivalent of `typeof` but with special handling for array and regexp. 1665 | function getPropType(propValue) { 1666 | var propType = typeof propValue; 1667 | if (Array.isArray(propValue)) { 1668 | return 'array'; 1669 | } 1670 | if (propValue instanceof RegExp) { 1671 | // Old webkits (at least until Android 4.0) return 'function' rather than 1672 | // 'object' for typeof a RegExp. We'll normalize this here so that /bla/ 1673 | // passes PropTypes.object. 1674 | return 'object'; 1675 | } 1676 | if (isSymbol(propType, propValue)) { 1677 | return 'symbol'; 1678 | } 1679 | return propType; 1680 | } 1681 | 1682 | // This handles more types than `getPropType`. Only used for error messages. 1683 | // See `createPrimitiveTypeChecker`. 1684 | function getPreciseType(propValue) { 1685 | if (typeof propValue === 'undefined' || propValue === null) { 1686 | return '' + propValue; 1687 | } 1688 | var propType = getPropType(propValue); 1689 | if (propType === 'object') { 1690 | if (propValue instanceof Date) { 1691 | return 'date'; 1692 | } else if (propValue instanceof RegExp) { 1693 | return 'regexp'; 1694 | } 1695 | } 1696 | return propType; 1697 | } 1698 | 1699 | // Returns a string that is postfixed to a warning about an invalid type. 1700 | // For example, "undefined" or "of type array" 1701 | function getPostfixForTypeWarning(value) { 1702 | var type = getPreciseType(value); 1703 | switch (type) { 1704 | case 'array': 1705 | case 'object': 1706 | return 'an ' + type; 1707 | case 'boolean': 1708 | case 'date': 1709 | case 'regexp': 1710 | return 'a ' + type; 1711 | default: 1712 | return type; 1713 | } 1714 | } 1715 | 1716 | // Returns class name of the object, if any. 1717 | function getClassName(propValue) { 1718 | if (!propValue.constructor || !propValue.constructor.name) { 1719 | return ANONYMOUS; 1720 | } 1721 | return propValue.constructor.name; 1722 | } 1723 | 1724 | ReactPropTypes.checkPropTypes = checkPropTypes_1$2; 1725 | ReactPropTypes.PropTypes = ReactPropTypes; 1726 | 1727 | return ReactPropTypes; 1728 | }; 1729 | 1730 | var factoryWithThrowingShims$2 = function() { 1731 | function shim(props, propName, componentName, location, propFullName, secret) { 1732 | if (secret === ReactPropTypesSecret_1$2) { 1733 | // It is still safe when called from React. 1734 | return; 1735 | } 1736 | invariant_1$2( 1737 | false, 1738 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 1739 | 'Use PropTypes.checkPropTypes() to call them. ' + 1740 | 'Read more at http://fb.me/use-check-prop-types' 1741 | ); 1742 | } 1743 | shim.isRequired = shim; 1744 | function getShim() { 1745 | return shim; 1746 | } 1747 | // Important! 1748 | // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`. 1749 | var ReactPropTypes = { 1750 | array: shim, 1751 | bool: shim, 1752 | func: shim, 1753 | number: shim, 1754 | object: shim, 1755 | string: shim, 1756 | symbol: shim, 1757 | 1758 | any: shim, 1759 | arrayOf: getShim, 1760 | element: shim, 1761 | instanceOf: getShim, 1762 | node: shim, 1763 | objectOf: getShim, 1764 | oneOf: getShim, 1765 | oneOfType: getShim, 1766 | shape: getShim, 1767 | exact: getShim 1768 | }; 1769 | 1770 | ReactPropTypes.checkPropTypes = emptyFunction_1$2; 1771 | ReactPropTypes.PropTypes = ReactPropTypes; 1772 | 1773 | return ReactPropTypes; 1774 | }; 1775 | 1776 | var propTypes$1 = createCommonjsModule$1(function (module) { 1777 | /** 1778 | * Copyright (c) 2013-present, Facebook, Inc. 1779 | * 1780 | * This source code is licensed under the MIT license found in the 1781 | * LICENSE file in the root directory of this source tree. 1782 | */ 1783 | 1784 | if (undefined !== 'production') { 1785 | var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && 1786 | Symbol.for && 1787 | Symbol.for('react.element')) || 1788 | 0xeac7; 1789 | 1790 | var isValidElement = function(object) { 1791 | return typeof object === 'object' && 1792 | object !== null && 1793 | object.$$typeof === REACT_ELEMENT_TYPE; 1794 | }; 1795 | 1796 | // By explicitly using `prop-types` you are opting into new development behavior. 1797 | // http://fb.me/prop-types-in-prod 1798 | var throwOnDirectAccess = true; 1799 | module.exports = factoryWithTypeCheckers$2(isValidElement, throwOnDirectAccess); 1800 | } else { 1801 | // By explicitly using `prop-types` you are opting into new production behavior. 1802 | // http://fb.me/prop-types-in-prod 1803 | module.exports = factoryWithThrowingShims$2(); 1804 | } 1805 | }); 1806 | 1807 | function createCommonjsModule$1$1(fn, module) { 1808 | return module = { exports: {} }, fn(module, module.exports), module.exports; 1809 | } 1810 | 1811 | /** 1812 | * Copyright (c) 2013-present, Facebook, Inc. 1813 | * 1814 | * This source code is licensed under the MIT license found in the 1815 | * LICENSE file in the root directory of this source tree. 1816 | * 1817 | * 1818 | */ 1819 | 1820 | function makeEmptyFunction$1$1(arg) { 1821 | return function () { 1822 | return arg; 1823 | }; 1824 | } 1825 | 1826 | /** 1827 | * This function accepts and discards inputs; it has no side effects. This is 1828 | * primarily useful idiomatically for overridable function endpoints which 1829 | * always need to be callable, since JS lacks a null-call idiom ala Cocoa. 1830 | */ 1831 | var emptyFunction$2$1 = function emptyFunction() {}; 1832 | 1833 | emptyFunction$2$1.thatReturns = makeEmptyFunction$1$1; 1834 | emptyFunction$2$1.thatReturnsFalse = makeEmptyFunction$1$1(false); 1835 | emptyFunction$2$1.thatReturnsTrue = makeEmptyFunction$1$1(true); 1836 | emptyFunction$2$1.thatReturnsNull = makeEmptyFunction$1$1(null); 1837 | emptyFunction$2$1.thatReturnsThis = function () { 1838 | return this; 1839 | }; 1840 | emptyFunction$2$1.thatReturnsArgument = function (arg) { 1841 | return arg; 1842 | }; 1843 | 1844 | var emptyFunction_1$2$1 = emptyFunction$2$1; 1845 | 1846 | /** 1847 | * Copyright (c) 2013-present, Facebook, Inc. 1848 | * 1849 | * This source code is licensed under the MIT license found in the 1850 | * LICENSE file in the root directory of this source tree. 1851 | * 1852 | */ 1853 | 1854 | /** 1855 | * Use invariant() to assert state which your program assumes to be true. 1856 | * 1857 | * Provide sprintf-style format (only %s is supported) and arguments 1858 | * to provide information about what broke and what you were 1859 | * expecting. 1860 | * 1861 | * The invariant message will be stripped in production, but the invariant 1862 | * will remain to ensure logic does not differ in production. 1863 | */ 1864 | 1865 | var validateFormat$1$1 = function validateFormat(format) {}; 1866 | 1867 | if (undefined !== 'production') { 1868 | validateFormat$1$1 = function validateFormat(format) { 1869 | if (format === undefined) { 1870 | throw new Error('invariant requires an error message argument'); 1871 | } 1872 | }; 1873 | } 1874 | 1875 | function invariant$3$1(condition, format, a, b, c, d, e, f) { 1876 | validateFormat$1$1(format); 1877 | 1878 | if (!condition) { 1879 | var error; 1880 | if (format === undefined) { 1881 | error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); 1882 | } else { 1883 | var args = [a, b, c, d, e, f]; 1884 | var argIndex = 0; 1885 | error = new Error(format.replace(/%s/g, function () { 1886 | return args[argIndex++]; 1887 | })); 1888 | error.name = 'Invariant Violation'; 1889 | } 1890 | 1891 | error.framesToPop = 1; // we don't care about invariant's own frame 1892 | throw error; 1893 | } 1894 | } 1895 | 1896 | var invariant_1$2$1 = invariant$3$1; 1897 | 1898 | /** 1899 | * Similar to invariant but only logs a warning if the condition is not met. 1900 | * This can be used to log issues in development environments in critical 1901 | * paths. Removing the logging code for production environments will keep the 1902 | * same logic and follow the same code paths. 1903 | */ 1904 | 1905 | var warning$2$1 = emptyFunction_1$2$1; 1906 | 1907 | if (undefined !== 'production') { 1908 | var printWarning$1$1 = function printWarning(format) { 1909 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 1910 | args[_key - 1] = arguments[_key]; 1911 | } 1912 | 1913 | var argIndex = 0; 1914 | var message = 'Warning: ' + format.replace(/%s/g, function () { 1915 | return args[argIndex++]; 1916 | }); 1917 | if (typeof console !== 'undefined') { 1918 | console.error(message); 1919 | } 1920 | try { 1921 | // --- Welcome to debugging React --- 1922 | // This error was thrown as a convenience so that you can use this stack 1923 | // to find the callsite that caused this warning to fire. 1924 | throw new Error(message); 1925 | } catch (x) {} 1926 | }; 1927 | 1928 | warning$2$1 = function warning(condition, format) { 1929 | if (format === undefined) { 1930 | throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); 1931 | } 1932 | 1933 | if (format.indexOf('Failed Composite propType: ') === 0) { 1934 | return; // Ignore CompositeComponent proptype check. 1935 | } 1936 | 1937 | if (!condition) { 1938 | for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { 1939 | args[_key2 - 2] = arguments[_key2]; 1940 | } 1941 | 1942 | printWarning$1$1.apply(undefined, [format].concat(args)); 1943 | } 1944 | }; 1945 | } 1946 | 1947 | var warning_1$2$1 = warning$2$1; 1948 | 1949 | /* 1950 | object-assign 1951 | (c) Sindre Sorhus 1952 | @license MIT 1953 | */ 1954 | 1955 | /* eslint-disable no-unused-vars */ 1956 | var getOwnPropertySymbols$1$1 = Object.getOwnPropertySymbols; 1957 | var hasOwnProperty$1$1 = Object.prototype.hasOwnProperty; 1958 | var propIsEnumerable$1$1 = Object.prototype.propertyIsEnumerable; 1959 | 1960 | function toObject$1$1(val) { 1961 | if (val === null || val === undefined) { 1962 | throw new TypeError('Object.assign cannot be called with null or undefined'); 1963 | } 1964 | 1965 | return Object(val); 1966 | } 1967 | 1968 | function shouldUseNative$1$1() { 1969 | try { 1970 | if (!Object.assign) { 1971 | return false; 1972 | } 1973 | 1974 | // Detect buggy property enumeration order in older V8 versions. 1975 | 1976 | // https://bugs.chromium.org/p/v8/issues/detail?id=4118 1977 | var test1 = new String('abc'); // eslint-disable-line no-new-wrappers 1978 | test1[5] = 'de'; 1979 | if (Object.getOwnPropertyNames(test1)[0] === '5') { 1980 | return false; 1981 | } 1982 | 1983 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056 1984 | var test2 = {}; 1985 | for (var i = 0; i < 10; i++) { 1986 | test2['_' + String.fromCharCode(i)] = i; 1987 | } 1988 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) { 1989 | return test2[n]; 1990 | }); 1991 | if (order2.join('') !== '0123456789') { 1992 | return false; 1993 | } 1994 | 1995 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056 1996 | var test3 = {}; 1997 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { 1998 | test3[letter] = letter; 1999 | }); 2000 | if (Object.keys(Object.assign({}, test3)).join('') !== 2001 | 'abcdefghijklmnopqrst') { 2002 | return false; 2003 | } 2004 | 2005 | return true; 2006 | } catch (err) { 2007 | // We don't expect any of the above to throw, but better to be safe. 2008 | return false; 2009 | } 2010 | } 2011 | 2012 | var objectAssign$2$1 = shouldUseNative$1$1() ? Object.assign : function (target, source) { 2013 | var from; 2014 | var to = toObject$1$1(target); 2015 | var symbols; 2016 | 2017 | for (var s = 1; s < arguments.length; s++) { 2018 | from = Object(arguments[s]); 2019 | 2020 | for (var key in from) { 2021 | if (hasOwnProperty$1$1.call(from, key)) { 2022 | to[key] = from[key]; 2023 | } 2024 | } 2025 | 2026 | if (getOwnPropertySymbols$1$1) { 2027 | symbols = getOwnPropertySymbols$1$1(from); 2028 | for (var i = 0; i < symbols.length; i++) { 2029 | if (propIsEnumerable$1$1.call(from, symbols[i])) { 2030 | to[symbols[i]] = from[symbols[i]]; 2031 | } 2032 | } 2033 | } 2034 | } 2035 | 2036 | return to; 2037 | }; 2038 | 2039 | /** 2040 | * Copyright (c) 2013-present, Facebook, Inc. 2041 | * 2042 | * This source code is licensed under the MIT license found in the 2043 | * LICENSE file in the root directory of this source tree. 2044 | */ 2045 | 2046 | var ReactPropTypesSecret$3$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; 2047 | 2048 | var ReactPropTypesSecret_1$2$1 = ReactPropTypesSecret$3$1; 2049 | 2050 | if (undefined !== 'production') { 2051 | var invariant$1$1 = invariant_1$2$1; 2052 | var warning$1$1$1 = warning_1$2$1; 2053 | var ReactPropTypesSecret$1$1 = ReactPropTypesSecret_1$2$1; 2054 | var loggedTypeFailures$1$1 = {}; 2055 | } 2056 | 2057 | /** 2058 | * Assert that the values match with the type specs. 2059 | * Error messages are memorized and will only be shown once. 2060 | * 2061 | * @param {object} typeSpecs Map of name to a ReactPropType 2062 | * @param {object} values Runtime values that need to be type-checked 2063 | * @param {string} location e.g. "prop", "context", "child context" 2064 | * @param {string} componentName Name of the component for error messages. 2065 | * @param {?Function} getStack Returns the component stack. 2066 | * @private 2067 | */ 2068 | function checkPropTypes$2$1(typeSpecs, values, location, componentName, getStack) { 2069 | if (undefined !== 'production') { 2070 | for (var typeSpecName in typeSpecs) { 2071 | if (typeSpecs.hasOwnProperty(typeSpecName)) { 2072 | var error; 2073 | // Prop type validation may throw. In case they do, we don't want to 2074 | // fail the render phase where it didn't fail before. So we log it. 2075 | // After these have been cleaned up, we'll let them throw. 2076 | try { 2077 | // This is intentionally an invariant that gets caught. It's the same 2078 | // behavior as without this statement except with a better message. 2079 | invariant$1$1(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]); 2080 | error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1$1); 2081 | } catch (ex) { 2082 | error = ex; 2083 | } 2084 | warning$1$1$1(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); 2085 | if (error instanceof Error && !(error.message in loggedTypeFailures$1$1)) { 2086 | // Only monitor this failure once because there tends to be a lot of the 2087 | // same error. 2088 | loggedTypeFailures$1$1[error.message] = true; 2089 | 2090 | var stack = getStack ? getStack() : ''; 2091 | 2092 | warning$1$1$1(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); 2093 | } 2094 | } 2095 | } 2096 | } 2097 | } 2098 | 2099 | var checkPropTypes_1$2$1 = checkPropTypes$2$1; 2100 | 2101 | var factoryWithTypeCheckers$2$1 = function(isValidElement, throwOnDirectAccess) { 2102 | /* global Symbol */ 2103 | var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; 2104 | var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. 2105 | 2106 | /** 2107 | * Returns the iterator method function contained on the iterable object. 2108 | * 2109 | * Be sure to invoke the function with the iterable as context: 2110 | * 2111 | * var iteratorFn = getIteratorFn(myIterable); 2112 | * if (iteratorFn) { 2113 | * var iterator = iteratorFn.call(myIterable); 2114 | * ... 2115 | * } 2116 | * 2117 | * @param {?object} maybeIterable 2118 | * @return {?function} 2119 | */ 2120 | function getIteratorFn(maybeIterable) { 2121 | var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); 2122 | if (typeof iteratorFn === 'function') { 2123 | return iteratorFn; 2124 | } 2125 | } 2126 | 2127 | /** 2128 | * Collection of methods that allow declaration and validation of props that are 2129 | * supplied to React components. Example usage: 2130 | * 2131 | * var Props = require('ReactPropTypes'); 2132 | * var MyArticle = React.createClass({ 2133 | * propTypes: { 2134 | * // An optional string prop named "description". 2135 | * description: Props.string, 2136 | * 2137 | * // A required enum prop named "category". 2138 | * category: Props.oneOf(['News','Photos']).isRequired, 2139 | * 2140 | * // A prop named "dialog" that requires an instance of Dialog. 2141 | * dialog: Props.instanceOf(Dialog).isRequired 2142 | * }, 2143 | * render: function() { ... } 2144 | * }); 2145 | * 2146 | * A more formal specification of how these methods are used: 2147 | * 2148 | * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) 2149 | * decl := ReactPropTypes.{type}(.isRequired)? 2150 | * 2151 | * Each and every declaration produces a function with the same signature. This 2152 | * allows the creation of custom validation functions. For example: 2153 | * 2154 | * var MyLink = React.createClass({ 2155 | * propTypes: { 2156 | * // An optional string or URI prop named "href". 2157 | * href: function(props, propName, componentName) { 2158 | * var propValue = props[propName]; 2159 | * if (propValue != null && typeof propValue !== 'string' && 2160 | * !(propValue instanceof URI)) { 2161 | * return new Error( 2162 | * 'Expected a string or an URI for ' + propName + ' in ' + 2163 | * componentName 2164 | * ); 2165 | * } 2166 | * } 2167 | * }, 2168 | * render: function() {...} 2169 | * }); 2170 | * 2171 | * @internal 2172 | */ 2173 | 2174 | var ANONYMOUS = '<>'; 2175 | 2176 | // Important! 2177 | // Keep this list in sync with production version in `./factoryWithThrowingShims.js`. 2178 | var ReactPropTypes = { 2179 | array: createPrimitiveTypeChecker('array'), 2180 | bool: createPrimitiveTypeChecker('boolean'), 2181 | func: createPrimitiveTypeChecker('function'), 2182 | number: createPrimitiveTypeChecker('number'), 2183 | object: createPrimitiveTypeChecker('object'), 2184 | string: createPrimitiveTypeChecker('string'), 2185 | symbol: createPrimitiveTypeChecker('symbol'), 2186 | 2187 | any: createAnyTypeChecker(), 2188 | arrayOf: createArrayOfTypeChecker, 2189 | element: createElementTypeChecker(), 2190 | instanceOf: createInstanceTypeChecker, 2191 | node: createNodeChecker(), 2192 | objectOf: createObjectOfTypeChecker, 2193 | oneOf: createEnumTypeChecker, 2194 | oneOfType: createUnionTypeChecker, 2195 | shape: createShapeTypeChecker, 2196 | exact: createStrictShapeTypeChecker, 2197 | }; 2198 | 2199 | /** 2200 | * inlined Object.is polyfill to avoid requiring consumers ship their own 2201 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is 2202 | */ 2203 | /*eslint-disable no-self-compare*/ 2204 | function is(x, y) { 2205 | // SameValue algorithm 2206 | if (x === y) { 2207 | // Steps 1-5, 7-10 2208 | // Steps 6.b-6.e: +0 != -0 2209 | return x !== 0 || 1 / x === 1 / y; 2210 | } else { 2211 | // Step 6.a: NaN == NaN 2212 | return x !== x && y !== y; 2213 | } 2214 | } 2215 | /*eslint-enable no-self-compare*/ 2216 | 2217 | /** 2218 | * We use an Error-like object for backward compatibility as people may call 2219 | * PropTypes directly and inspect their output. However, we don't use real 2220 | * Errors anymore. We don't inspect their stack anyway, and creating them 2221 | * is prohibitively expensive if they are created too often, such as what 2222 | * happens in oneOfType() for any type before the one that matched. 2223 | */ 2224 | function PropTypeError(message) { 2225 | this.message = message; 2226 | this.stack = ''; 2227 | } 2228 | // Make `instanceof Error` still work for returned errors. 2229 | PropTypeError.prototype = Error.prototype; 2230 | 2231 | function createChainableTypeChecker(validate) { 2232 | if (undefined !== 'production') { 2233 | var manualPropTypeCallCache = {}; 2234 | var manualPropTypeWarningCount = 0; 2235 | } 2236 | function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { 2237 | componentName = componentName || ANONYMOUS; 2238 | propFullName = propFullName || propName; 2239 | 2240 | if (secret !== ReactPropTypesSecret_1$2$1) { 2241 | if (throwOnDirectAccess) { 2242 | // New behavior only for users of `prop-types` package 2243 | invariant_1$2$1( 2244 | false, 2245 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 2246 | 'Use `PropTypes.checkPropTypes()` to call them. ' + 2247 | 'Read more at http://fb.me/use-check-prop-types' 2248 | ); 2249 | } else if (undefined !== 'production' && typeof console !== 'undefined') { 2250 | // Old behavior for people using React.PropTypes 2251 | var cacheKey = componentName + ':' + propName; 2252 | if ( 2253 | !manualPropTypeCallCache[cacheKey] && 2254 | // Avoid spamming the console because they are often not actionable except for lib authors 2255 | manualPropTypeWarningCount < 3 2256 | ) { 2257 | warning_1$2$1( 2258 | false, 2259 | 'You are manually calling a React.PropTypes validation ' + 2260 | 'function for the `%s` prop on `%s`. This is deprecated ' + 2261 | 'and will throw in the standalone `prop-types` package. ' + 2262 | 'You may be seeing this warning due to a third-party PropTypes ' + 2263 | 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', 2264 | propFullName, 2265 | componentName 2266 | ); 2267 | manualPropTypeCallCache[cacheKey] = true; 2268 | manualPropTypeWarningCount++; 2269 | } 2270 | } 2271 | } 2272 | if (props[propName] == null) { 2273 | if (isRequired) { 2274 | if (props[propName] === null) { 2275 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); 2276 | } 2277 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); 2278 | } 2279 | return null; 2280 | } else { 2281 | return validate(props, propName, componentName, location, propFullName); 2282 | } 2283 | } 2284 | 2285 | var chainedCheckType = checkType.bind(null, false); 2286 | chainedCheckType.isRequired = checkType.bind(null, true); 2287 | 2288 | return chainedCheckType; 2289 | } 2290 | 2291 | function createPrimitiveTypeChecker(expectedType) { 2292 | function validate(props, propName, componentName, location, propFullName, secret) { 2293 | var propValue = props[propName]; 2294 | var propType = getPropType(propValue); 2295 | if (propType !== expectedType) { 2296 | // `propValue` being instance of, say, date/regexp, pass the 'object' 2297 | // check, but we can offer a more precise error message here rather than 2298 | // 'of type `object`'. 2299 | var preciseType = getPreciseType(propValue); 2300 | 2301 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); 2302 | } 2303 | return null; 2304 | } 2305 | return createChainableTypeChecker(validate); 2306 | } 2307 | 2308 | function createAnyTypeChecker() { 2309 | return createChainableTypeChecker(emptyFunction_1$2$1.thatReturnsNull); 2310 | } 2311 | 2312 | function createArrayOfTypeChecker(typeChecker) { 2313 | function validate(props, propName, componentName, location, propFullName) { 2314 | if (typeof typeChecker !== 'function') { 2315 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); 2316 | } 2317 | var propValue = props[propName]; 2318 | if (!Array.isArray(propValue)) { 2319 | var propType = getPropType(propValue); 2320 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); 2321 | } 2322 | for (var i = 0; i < propValue.length; i++) { 2323 | var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1$2$1); 2324 | if (error instanceof Error) { 2325 | return error; 2326 | } 2327 | } 2328 | return null; 2329 | } 2330 | return createChainableTypeChecker(validate); 2331 | } 2332 | 2333 | function createElementTypeChecker() { 2334 | function validate(props, propName, componentName, location, propFullName) { 2335 | var propValue = props[propName]; 2336 | if (!isValidElement(propValue)) { 2337 | var propType = getPropType(propValue); 2338 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); 2339 | } 2340 | return null; 2341 | } 2342 | return createChainableTypeChecker(validate); 2343 | } 2344 | 2345 | function createInstanceTypeChecker(expectedClass) { 2346 | function validate(props, propName, componentName, location, propFullName) { 2347 | if (!(props[propName] instanceof expectedClass)) { 2348 | var expectedClassName = expectedClass.name || ANONYMOUS; 2349 | var actualClassName = getClassName(props[propName]); 2350 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); 2351 | } 2352 | return null; 2353 | } 2354 | return createChainableTypeChecker(validate); 2355 | } 2356 | 2357 | function createEnumTypeChecker(expectedValues) { 2358 | if (!Array.isArray(expectedValues)) { 2359 | undefined !== 'production' ? warning_1$2$1(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0; 2360 | return emptyFunction_1$2$1.thatReturnsNull; 2361 | } 2362 | 2363 | function validate(props, propName, componentName, location, propFullName) { 2364 | var propValue = props[propName]; 2365 | for (var i = 0; i < expectedValues.length; i++) { 2366 | if (is(propValue, expectedValues[i])) { 2367 | return null; 2368 | } 2369 | } 2370 | 2371 | var valuesString = JSON.stringify(expectedValues); 2372 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); 2373 | } 2374 | return createChainableTypeChecker(validate); 2375 | } 2376 | 2377 | function createObjectOfTypeChecker(typeChecker) { 2378 | function validate(props, propName, componentName, location, propFullName) { 2379 | if (typeof typeChecker !== 'function') { 2380 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); 2381 | } 2382 | var propValue = props[propName]; 2383 | var propType = getPropType(propValue); 2384 | if (propType !== 'object') { 2385 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); 2386 | } 2387 | for (var key in propValue) { 2388 | if (propValue.hasOwnProperty(key)) { 2389 | var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1$2$1); 2390 | if (error instanceof Error) { 2391 | return error; 2392 | } 2393 | } 2394 | } 2395 | return null; 2396 | } 2397 | return createChainableTypeChecker(validate); 2398 | } 2399 | 2400 | function createUnionTypeChecker(arrayOfTypeCheckers) { 2401 | if (!Array.isArray(arrayOfTypeCheckers)) { 2402 | undefined !== 'production' ? warning_1$2$1(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; 2403 | return emptyFunction_1$2$1.thatReturnsNull; 2404 | } 2405 | 2406 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) { 2407 | var checker = arrayOfTypeCheckers[i]; 2408 | if (typeof checker !== 'function') { 2409 | warning_1$2$1( 2410 | false, 2411 | 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + 2412 | 'received %s at index %s.', 2413 | getPostfixForTypeWarning(checker), 2414 | i 2415 | ); 2416 | return emptyFunction_1$2$1.thatReturnsNull; 2417 | } 2418 | } 2419 | 2420 | function validate(props, propName, componentName, location, propFullName) { 2421 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) { 2422 | var checker = arrayOfTypeCheckers[i]; 2423 | if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1$2$1) == null) { 2424 | return null; 2425 | } 2426 | } 2427 | 2428 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); 2429 | } 2430 | return createChainableTypeChecker(validate); 2431 | } 2432 | 2433 | function createNodeChecker() { 2434 | function validate(props, propName, componentName, location, propFullName) { 2435 | if (!isNode(props[propName])) { 2436 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); 2437 | } 2438 | return null; 2439 | } 2440 | return createChainableTypeChecker(validate); 2441 | } 2442 | 2443 | function createShapeTypeChecker(shapeTypes) { 2444 | function validate(props, propName, componentName, location, propFullName) { 2445 | var propValue = props[propName]; 2446 | var propType = getPropType(propValue); 2447 | if (propType !== 'object') { 2448 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); 2449 | } 2450 | for (var key in shapeTypes) { 2451 | var checker = shapeTypes[key]; 2452 | if (!checker) { 2453 | continue; 2454 | } 2455 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1$2$1); 2456 | if (error) { 2457 | return error; 2458 | } 2459 | } 2460 | return null; 2461 | } 2462 | return createChainableTypeChecker(validate); 2463 | } 2464 | 2465 | function createStrictShapeTypeChecker(shapeTypes) { 2466 | function validate(props, propName, componentName, location, propFullName) { 2467 | var propValue = props[propName]; 2468 | var propType = getPropType(propValue); 2469 | if (propType !== 'object') { 2470 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); 2471 | } 2472 | // We need to check all keys in case some are required but missing from 2473 | // props. 2474 | var allKeys = objectAssign$2$1({}, props[propName], shapeTypes); 2475 | for (var key in allKeys) { 2476 | var checker = shapeTypes[key]; 2477 | if (!checker) { 2478 | return new PropTypeError( 2479 | 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + 2480 | '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + 2481 | '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') 2482 | ); 2483 | } 2484 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1$2$1); 2485 | if (error) { 2486 | return error; 2487 | } 2488 | } 2489 | return null; 2490 | } 2491 | 2492 | return createChainableTypeChecker(validate); 2493 | } 2494 | 2495 | function isNode(propValue) { 2496 | switch (typeof propValue) { 2497 | case 'number': 2498 | case 'string': 2499 | case 'undefined': 2500 | return true; 2501 | case 'boolean': 2502 | return !propValue; 2503 | case 'object': 2504 | if (Array.isArray(propValue)) { 2505 | return propValue.every(isNode); 2506 | } 2507 | if (propValue === null || isValidElement(propValue)) { 2508 | return true; 2509 | } 2510 | 2511 | var iteratorFn = getIteratorFn(propValue); 2512 | if (iteratorFn) { 2513 | var iterator = iteratorFn.call(propValue); 2514 | var step; 2515 | if (iteratorFn !== propValue.entries) { 2516 | while (!(step = iterator.next()).done) { 2517 | if (!isNode(step.value)) { 2518 | return false; 2519 | } 2520 | } 2521 | } else { 2522 | // Iterator will provide entry [k,v] tuples rather than values. 2523 | while (!(step = iterator.next()).done) { 2524 | var entry = step.value; 2525 | if (entry) { 2526 | if (!isNode(entry[1])) { 2527 | return false; 2528 | } 2529 | } 2530 | } 2531 | } 2532 | } else { 2533 | return false; 2534 | } 2535 | 2536 | return true; 2537 | default: 2538 | return false; 2539 | } 2540 | } 2541 | 2542 | function isSymbol(propType, propValue) { 2543 | // Native Symbol. 2544 | if (propType === 'symbol') { 2545 | return true; 2546 | } 2547 | 2548 | // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' 2549 | if (propValue['@@toStringTag'] === 'Symbol') { 2550 | return true; 2551 | } 2552 | 2553 | // Fallback for non-spec compliant Symbols which are polyfilled. 2554 | if (typeof Symbol === 'function' && propValue instanceof Symbol) { 2555 | return true; 2556 | } 2557 | 2558 | return false; 2559 | } 2560 | 2561 | // Equivalent of `typeof` but with special handling for array and regexp. 2562 | function getPropType(propValue) { 2563 | var propType = typeof propValue; 2564 | if (Array.isArray(propValue)) { 2565 | return 'array'; 2566 | } 2567 | if (propValue instanceof RegExp) { 2568 | // Old webkits (at least until Android 4.0) return 'function' rather than 2569 | // 'object' for typeof a RegExp. We'll normalize this here so that /bla/ 2570 | // passes PropTypes.object. 2571 | return 'object'; 2572 | } 2573 | if (isSymbol(propType, propValue)) { 2574 | return 'symbol'; 2575 | } 2576 | return propType; 2577 | } 2578 | 2579 | // This handles more types than `getPropType`. Only used for error messages. 2580 | // See `createPrimitiveTypeChecker`. 2581 | function getPreciseType(propValue) { 2582 | if (typeof propValue === 'undefined' || propValue === null) { 2583 | return '' + propValue; 2584 | } 2585 | var propType = getPropType(propValue); 2586 | if (propType === 'object') { 2587 | if (propValue instanceof Date) { 2588 | return 'date'; 2589 | } else if (propValue instanceof RegExp) { 2590 | return 'regexp'; 2591 | } 2592 | } 2593 | return propType; 2594 | } 2595 | 2596 | // Returns a string that is postfixed to a warning about an invalid type. 2597 | // For example, "undefined" or "of type array" 2598 | function getPostfixForTypeWarning(value) { 2599 | var type = getPreciseType(value); 2600 | switch (type) { 2601 | case 'array': 2602 | case 'object': 2603 | return 'an ' + type; 2604 | case 'boolean': 2605 | case 'date': 2606 | case 'regexp': 2607 | return 'a ' + type; 2608 | default: 2609 | return type; 2610 | } 2611 | } 2612 | 2613 | // Returns class name of the object, if any. 2614 | function getClassName(propValue) { 2615 | if (!propValue.constructor || !propValue.constructor.name) { 2616 | return ANONYMOUS; 2617 | } 2618 | return propValue.constructor.name; 2619 | } 2620 | 2621 | ReactPropTypes.checkPropTypes = checkPropTypes_1$2$1; 2622 | ReactPropTypes.PropTypes = ReactPropTypes; 2623 | 2624 | return ReactPropTypes; 2625 | }; 2626 | 2627 | var factoryWithThrowingShims$2$1 = function() { 2628 | function shim(props, propName, componentName, location, propFullName, secret) { 2629 | if (secret === ReactPropTypesSecret_1$2$1) { 2630 | // It is still safe when called from React. 2631 | return; 2632 | } 2633 | invariant_1$2$1( 2634 | false, 2635 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 2636 | 'Use PropTypes.checkPropTypes() to call them. ' + 2637 | 'Read more at http://fb.me/use-check-prop-types' 2638 | ); 2639 | } 2640 | shim.isRequired = shim; 2641 | function getShim() { 2642 | return shim; 2643 | } 2644 | // Important! 2645 | // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`. 2646 | var ReactPropTypes = { 2647 | array: shim, 2648 | bool: shim, 2649 | func: shim, 2650 | number: shim, 2651 | object: shim, 2652 | string: shim, 2653 | symbol: shim, 2654 | 2655 | any: shim, 2656 | arrayOf: getShim, 2657 | element: shim, 2658 | instanceOf: getShim, 2659 | node: shim, 2660 | objectOf: getShim, 2661 | oneOf: getShim, 2662 | oneOfType: getShim, 2663 | shape: getShim, 2664 | exact: getShim 2665 | }; 2666 | 2667 | ReactPropTypes.checkPropTypes = emptyFunction_1$2$1; 2668 | ReactPropTypes.PropTypes = ReactPropTypes; 2669 | 2670 | return ReactPropTypes; 2671 | }; 2672 | 2673 | var propTypes$1$1 = createCommonjsModule$1$1(function (module) { 2674 | /** 2675 | * Copyright (c) 2013-present, Facebook, Inc. 2676 | * 2677 | * This source code is licensed under the MIT license found in the 2678 | * LICENSE file in the root directory of this source tree. 2679 | */ 2680 | 2681 | if (undefined !== 'production') { 2682 | var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && 2683 | Symbol.for && 2684 | Symbol.for('react.element')) || 2685 | 0xeac7; 2686 | 2687 | var isValidElement = function(object) { 2688 | return typeof object === 'object' && 2689 | object !== null && 2690 | object.$$typeof === REACT_ELEMENT_TYPE; 2691 | }; 2692 | 2693 | // By explicitly using `prop-types` you are opting into new development behavior. 2694 | // http://fb.me/prop-types-in-prod 2695 | var throwOnDirectAccess = true; 2696 | module.exports = factoryWithTypeCheckers$2$1(isValidElement, throwOnDirectAccess); 2697 | } else { 2698 | // By explicitly using `prop-types` you are opting into new production behavior. 2699 | // http://fb.me/prop-types-in-prod 2700 | module.exports = factoryWithThrowingShims$2$1(); 2701 | } 2702 | }); 2703 | 2704 | /** 2705 | * Copyright 2013-2015, Facebook, Inc. 2706 | * All rights reserved. 2707 | * 2708 | * This source code is licensed under the BSD-style license found in the 2709 | * LICENSE file in the root directory of this source tree. An additional grant 2710 | * of patent rights can be found in the PATENTS file in the same directory. 2711 | */ 2712 | 2713 | /** 2714 | * Use invariant() to assert state which your program assumes to be true. 2715 | * 2716 | * Provide sprintf-style format (only %s is supported) and arguments 2717 | * to provide information about what broke and what you were 2718 | * expecting. 2719 | * 2720 | * The invariant message will be stripped in production, but the invariant 2721 | * will remain to ensure logic does not differ in production. 2722 | */ 2723 | 2724 | var NODE_ENV = undefined; 2725 | 2726 | var invariant$3$1$1 = function(condition, format, a, b, c, d, e, f) { 2727 | if (NODE_ENV !== 'production') { 2728 | if (format === undefined) { 2729 | throw new Error('invariant requires an error message argument'); 2730 | } 2731 | } 2732 | 2733 | if (!condition) { 2734 | var error; 2735 | if (format === undefined) { 2736 | error = new Error( 2737 | 'Minified exception occurred; use the non-minified dev environment ' + 2738 | 'for the full error message and additional helpful warnings.' 2739 | ); 2740 | } else { 2741 | var args = [a, b, c, d, e, f]; 2742 | var argIndex = 0; 2743 | error = new Error( 2744 | format.replace(/%s/g, function() { return args[argIndex++]; }) 2745 | ); 2746 | error.name = 'Invariant Violation'; 2747 | } 2748 | 2749 | error.framesToPop = 1; // we don't care about invariant's own frame 2750 | throw error; 2751 | } 2752 | }; 2753 | 2754 | var invariant_1$2$1$1 = invariant$3$1$1; 2755 | 2756 | /** 2757 | * Copyright 2014-2015, Facebook, Inc. 2758 | * All rights reserved. 2759 | * 2760 | * This source code is licensed under the BSD-style license found in the 2761 | * LICENSE file in the root directory of this source tree. An additional grant 2762 | * of patent rights can be found in the PATENTS file in the same directory. 2763 | */ 2764 | 2765 | /** 2766 | * Similar to invariant but only logs a warning if the condition is not met. 2767 | * This can be used to log issues in development environments in critical 2768 | * paths. Removing the logging code for production environments will keep the 2769 | * same logic and follow the same code paths. 2770 | */ 2771 | 2772 | var __DEV__ = undefined !== 'production'; 2773 | 2774 | var warning$2$1$1 = function() {}; 2775 | 2776 | if (__DEV__) { 2777 | warning$2$1$1 = function(condition, format, args) { 2778 | var len = arguments.length; 2779 | args = new Array(len > 2 ? len - 2 : 0); 2780 | for (var key = 2; key < len; key++) { 2781 | args[key - 2] = arguments[key]; 2782 | } 2783 | if (format === undefined) { 2784 | throw new Error( 2785 | '`warning(condition, format, ...args)` requires a warning ' + 2786 | 'message argument' 2787 | ); 2788 | } 2789 | 2790 | if (format.length < 10 || (/^[s\W]*$/).test(format)) { 2791 | throw new Error( 2792 | 'The warning format should be able to uniquely identify this ' + 2793 | 'warning. Please, use a more descriptive format than: ' + format 2794 | ); 2795 | } 2796 | 2797 | if (!condition) { 2798 | var argIndex = 0; 2799 | var message = 'Warning: ' + 2800 | format.replace(/%s/g, function() { 2801 | return args[argIndex++]; 2802 | }); 2803 | if (typeof console !== 'undefined') { 2804 | console.error(message); 2805 | } 2806 | try { 2807 | // This error was thrown as a convenience so that you can use this stack 2808 | // to find the callsite that caused this warning to fire. 2809 | throw new Error(message); 2810 | } catch(x) {} 2811 | } 2812 | }; 2813 | } 2814 | 2815 | var warning_1$2$1$1 = warning$2$1$1; 2816 | 2817 | function createDeprecationWarning() { 2818 | var alreadyWarned = false; 2819 | return function (message) { 2820 | warning_1$2$1$1(alreadyWarned, message); 2821 | alreadyWarned = true; 2822 | }; 2823 | } 2824 | 2825 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { 2826 | return typeof obj; 2827 | } : function (obj) { 2828 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; 2829 | }; 2830 | 2831 | 2832 | 2833 | 2834 | 2835 | 2836 | 2837 | 2838 | 2839 | 2840 | 2841 | var classCallCheck = function (instance, Constructor) { 2842 | if (!(instance instanceof Constructor)) { 2843 | throw new TypeError("Cannot call a class as a function"); 2844 | } 2845 | }; 2846 | 2847 | 2848 | 2849 | 2850 | 2851 | 2852 | 2853 | 2854 | 2855 | var _extends = Object.assign || function (target) { 2856 | for (var i = 1; i < arguments.length; i++) { 2857 | var source = arguments[i]; 2858 | 2859 | for (var key in source) { 2860 | if (Object.prototype.hasOwnProperty.call(source, key)) { 2861 | target[key] = source[key]; 2862 | } 2863 | } 2864 | } 2865 | 2866 | return target; 2867 | }; 2868 | 2869 | 2870 | 2871 | var inherits = function (subClass, superClass) { 2872 | if (typeof superClass !== "function" && superClass !== null) { 2873 | throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); 2874 | } 2875 | 2876 | subClass.prototype = Object.create(superClass && superClass.prototype, { 2877 | constructor: { 2878 | value: subClass, 2879 | enumerable: false, 2880 | writable: true, 2881 | configurable: true 2882 | } 2883 | }); 2884 | if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; 2885 | }; 2886 | 2887 | 2888 | 2889 | 2890 | 2891 | 2892 | 2893 | 2894 | 2895 | 2896 | 2897 | var possibleConstructorReturn = function (self, call) { 2898 | if (!self) { 2899 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 2900 | } 2901 | 2902 | return call && (typeof call === "object" || typeof call === "function") ? call : self; 2903 | }; 2904 | 2905 | var deprecationWarning = createDeprecationWarning(); 2906 | 2907 | function createBroadcast(initialValue) { 2908 | var currentValue = initialValue; 2909 | var subscribers = []; 2910 | 2911 | var getValue = function getValue() { 2912 | return currentValue; 2913 | }; 2914 | 2915 | var publish = function publish(state) { 2916 | currentValue = state; 2917 | subscribers.forEach(function (s) { 2918 | return s(currentValue); 2919 | }); 2920 | }; 2921 | 2922 | var subscribe = function subscribe(subscriber) { 2923 | subscribers.push(subscriber); 2924 | 2925 | return function () { 2926 | subscribers = subscribers.filter(function (s) { 2927 | return s !== subscriber; 2928 | }); 2929 | }; 2930 | }; 2931 | 2932 | return { 2933 | getValue: getValue, 2934 | publish: publish, 2935 | subscribe: subscribe 2936 | }; 2937 | } 2938 | 2939 | /** 2940 | * A provides a generic way for descendants to "subscribe" 2941 | * to some value that changes over time, bypassing any intermediate 2942 | * shouldComponentUpdate's in the hierarchy. It puts all subscription 2943 | * functions on context.broadcasts, keyed by "channel". 2944 | * 2945 | * To use it, a subscriber must opt-in to context.broadcasts. See the 2946 | * component for a reference implementation. 2947 | */ 2948 | 2949 | var Broadcast = function (_React$Component) { 2950 | inherits(Broadcast, _React$Component); 2951 | 2952 | function Broadcast() { 2953 | var _temp, _this, _ret; 2954 | 2955 | classCallCheck(this, Broadcast); 2956 | 2957 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 2958 | args[_key] = arguments[_key]; 2959 | } 2960 | 2961 | return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.broadcast = createBroadcast(_this.props.value), _temp), possibleConstructorReturn(_this, _ret); 2962 | } 2963 | 2964 | Broadcast.prototype.getChildContext = function getChildContext() { 2965 | var _babelHelpers$extends; 2966 | 2967 | return { 2968 | broadcasts: _extends({}, this.context.broadcasts, (_babelHelpers$extends = {}, _babelHelpers$extends[this.props.channel] = this.broadcast, _babelHelpers$extends)) 2969 | }; 2970 | }; 2971 | 2972 | Broadcast.prototype.componentWillMount = function componentWillMount() { 2973 | deprecationWarning(" is deprecated and will be removed in the next major release. " + "Please use createContext instead. See https://goo.gl/QAF37J for more info."); 2974 | }; 2975 | 2976 | Broadcast.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { 2977 | invariant_1$2$1$1(this.props.channel === nextProps.channel, "You cannot change "); 2978 | 2979 | if (!this.props.compareValues(this.props.value, nextProps.value)) { 2980 | this.broadcast.publish(nextProps.value); 2981 | } 2982 | }; 2983 | 2984 | Broadcast.prototype.render = function render() { 2985 | return React.Children.only(this.props.children); 2986 | }; 2987 | 2988 | return Broadcast; 2989 | }(React.Component); 2990 | 2991 | Broadcast.propTypes = { 2992 | channel: propTypes$1$1.string.isRequired, 2993 | children: propTypes$1$1.node.isRequired, 2994 | compareValues: propTypes$1$1.func, 2995 | value: propTypes$1$1.any 2996 | }; 2997 | Broadcast.defaultProps = { 2998 | compareValues: function compareValues(prevValue, nextValue) { 2999 | return prevValue === nextValue; 3000 | } 3001 | }; 3002 | Broadcast.contextTypes = { 3003 | broadcasts: propTypes$1$1.object 3004 | }; 3005 | Broadcast.childContextTypes = { 3006 | broadcasts: propTypes$1$1.object.isRequired 3007 | }; 3008 | 3009 | var deprecationWarning$1 = createDeprecationWarning(); 3010 | 3011 | /** 3012 | * A pulls the value for a channel off of context.broadcasts 3013 | * and passes it to its children function. 3014 | */ 3015 | 3016 | var Subscriber = function (_React$Component) { 3017 | inherits(Subscriber, _React$Component); 3018 | 3019 | function Subscriber() { 3020 | var _temp, _this, _ret; 3021 | 3022 | classCallCheck(this, Subscriber); 3023 | 3024 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 3025 | args[_key] = arguments[_key]; 3026 | } 3027 | 3028 | return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = { 3029 | value: undefined 3030 | }, _temp), possibleConstructorReturn(_this, _ret); 3031 | } 3032 | 3033 | Subscriber.prototype.getBroadcast = function getBroadcast() { 3034 | var broadcasts = this.context.broadcasts || {}; 3035 | var broadcast = broadcasts[this.props.channel]; 3036 | 3037 | invariant_1$2$1$1(this.props.quiet || broadcast, ' must be rendered in the context of a ', this.props.channel, this.props.channel); 3038 | 3039 | return broadcast; 3040 | }; 3041 | 3042 | Subscriber.prototype.componentWillMount = function componentWillMount() { 3043 | deprecationWarning$1(" is deprecated and will be removed in the next major release. " + "Please use createContext instead. See https://goo.gl/QAF37J for more info."); 3044 | 3045 | var broadcast = this.getBroadcast(); 3046 | 3047 | if (broadcast) { 3048 | this.setState({ 3049 | value: broadcast.getValue() 3050 | }); 3051 | } 3052 | }; 3053 | 3054 | Subscriber.prototype.componentDidMount = function componentDidMount() { 3055 | var _this2 = this; 3056 | 3057 | var broadcast = this.getBroadcast(); 3058 | 3059 | if (broadcast) { 3060 | this.unsubscribe = broadcast.subscribe(function (value) { 3061 | _this2.setState({ value: value }); 3062 | }); 3063 | } 3064 | }; 3065 | 3066 | Subscriber.prototype.componentWillUnmount = function componentWillUnmount() { 3067 | if (this.unsubscribe) this.unsubscribe(); 3068 | }; 3069 | 3070 | Subscriber.prototype.render = function render() { 3071 | var children = this.props.children; 3072 | 3073 | return children ? children(this.state.value) : null; 3074 | }; 3075 | 3076 | return Subscriber; 3077 | }(React.Component); 3078 | 3079 | Subscriber.propTypes = { 3080 | channel: propTypes$1$1.string.isRequired, 3081 | children: propTypes$1$1.func, 3082 | quiet: propTypes$1$1.bool 3083 | }; 3084 | Subscriber.defaultProps = { 3085 | quiet: false 3086 | }; 3087 | Subscriber.contextTypes = { 3088 | broadcasts: propTypes$1$1.object 3089 | }; 3090 | 3091 | var valueTypes = { 3092 | string: propTypes$1$1.string, 3093 | number: propTypes$1$1.number, 3094 | function: propTypes$1$1.func, 3095 | boolean: propTypes$1$1.bool 3096 | }; 3097 | 3098 | // TODO: This could probably be improved. 3099 | function getPropType(value) { 3100 | var type = typeof value === "undefined" ? "undefined" : _typeof(value); 3101 | 3102 | if (type === "object") { 3103 | return Array.isArray(value) ? propTypes$1$1.array : propTypes$1$1.object; 3104 | } 3105 | 3106 | return valueTypes[type] || propTypes$1$1.any; 3107 | } 3108 | 3109 | function createContext(defaultValue) { 3110 | var valueType = getPropType(defaultValue); 3111 | var channel = Symbol(); 3112 | 3113 | /** 3114 | * A is a container for a "value" that its 3115 | * may subscribe to. 3116 | */ 3117 | 3118 | var Provider = function (_React$Component) { 3119 | inherits(Provider, _React$Component); 3120 | 3121 | function Provider() { 3122 | var _temp, _this, _ret; 3123 | 3124 | classCallCheck(this, Provider); 3125 | 3126 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 3127 | args[_key] = arguments[_key]; 3128 | } 3129 | 3130 | return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.subscribers = [], _this.publish = function (value) { 3131 | _this.subscribers.forEach(function (s) { 3132 | return s(value); 3133 | }); 3134 | }, _this.subscribe = function (subscriber) { 3135 | _this.subscribers.push(subscriber); 3136 | 3137 | return function () { 3138 | _this.subscribers = _this.subscribers.filter(function (s) { 3139 | return s !== subscriber; 3140 | }); 3141 | }; 3142 | }, _temp), possibleConstructorReturn(_this, _ret); 3143 | } 3144 | /** 3145 | * For convenience when setting up a component that tracks this 3146 | * 's value in state. 3147 | * 3148 | * const { 3149 | * Provider, 3150 | * Consumer 3151 | * } = createContext("default value") 3152 | * 3153 | * class MyComponent { 3154 | * state = { 3155 | * broadcastValue: Provider.defaultValue 3156 | * } 3157 | * 3158 | * // ... 3159 | * 3160 | * render() { 3161 | * return 3162 | * } 3163 | * } 3164 | */ 3165 | 3166 | 3167 | Provider.prototype.getChildContext = function getChildContext() { 3168 | var _babelHelpers$extends; 3169 | 3170 | return { 3171 | broadcasts: _extends({}, this.context.broadcasts, (_babelHelpers$extends = {}, _babelHelpers$extends[channel] = { 3172 | initialValue: this.props.value, 3173 | subscribe: this.subscribe 3174 | }, _babelHelpers$extends)) 3175 | }; 3176 | }; 3177 | 3178 | Provider.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { 3179 | if (this.props.value !== nextProps.value) { 3180 | this.publish(nextProps.value); 3181 | } 3182 | }; 3183 | 3184 | Provider.prototype.render = function render() { 3185 | return this.props.children; 3186 | }; 3187 | 3188 | return Provider; 3189 | }(React.Component); 3190 | 3191 | /** 3192 | * A sets state whenever its changes 3193 | * and calls its render prop with the result. 3194 | */ 3195 | 3196 | 3197 | Provider.defaultValue = defaultValue; 3198 | Provider.propTypes = { 3199 | children: propTypes$1$1.node, 3200 | value: valueType 3201 | }; 3202 | Provider.defaultProps = { 3203 | value: defaultValue 3204 | }; 3205 | Provider.contextTypes = { 3206 | broadcasts: propTypes$1$1.object 3207 | }; 3208 | Provider.childContextTypes = { 3209 | broadcasts: propTypes$1$1.object.isRequired 3210 | }; 3211 | 3212 | var Consumer = function (_React$Component2) { 3213 | inherits(Consumer, _React$Component2); 3214 | 3215 | function Consumer() { 3216 | var _temp2, _this2, _ret2; 3217 | 3218 | classCallCheck(this, Consumer); 3219 | 3220 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 3221 | args[_key2] = arguments[_key2]; 3222 | } 3223 | 3224 | return _ret2 = (_temp2 = (_this2 = possibleConstructorReturn(this, _React$Component2.call.apply(_React$Component2, [this].concat(args))), _this2), _this2.broadcast = _this2.context.broadcasts && _this2.context.broadcasts[channel], _this2.state = { 3225 | value: _this2.broadcast ? _this2.broadcast.initialValue : defaultValue 3226 | }, _temp2), possibleConstructorReturn(_this2, _ret2); 3227 | } 3228 | 3229 | Consumer.prototype.componentDidMount = function componentDidMount() { 3230 | var _this3 = this; 3231 | 3232 | if (this.broadcast) { 3233 | this.unsubscribe = this.broadcast.subscribe(function (value) { 3234 | _this3.setState({ value: value }); 3235 | }); 3236 | } else { 3237 | warning_1$2$1$1(this.props.quiet, " was rendered outside the context of its "); 3238 | } 3239 | }; 3240 | 3241 | Consumer.prototype.componentWillUnmount = function componentWillUnmount() { 3242 | if (this.unsubscribe) this.unsubscribe(); 3243 | }; 3244 | 3245 | Consumer.prototype.render = function render() { 3246 | var children = this.props.children; 3247 | 3248 | return children ? children(this.state.value) : null; 3249 | }; 3250 | 3251 | return Consumer; 3252 | }(React.Component); 3253 | 3254 | Consumer.contextTypes = { 3255 | broadcasts: propTypes$1$1.object 3256 | }; 3257 | Consumer.propTypes = { 3258 | children: propTypes$1$1.func, 3259 | quiet: propTypes$1$1.bool 3260 | }; 3261 | Consumer.defaultProps = { 3262 | quiet: false 3263 | }; 3264 | 3265 | 3266 | return { 3267 | Provider: Provider, 3268 | Consumer: Consumer 3269 | }; 3270 | } 3271 | 3272 | function loadScript(url) { 3273 | return new Promise((resolve, reject) => { 3274 | const script = document.createElement('script'); 3275 | script.onload = resolve; 3276 | script.onerror = reject; 3277 | script.src = url; 3278 | script.async = true; 3279 | script.type = 'text/javascript'; 3280 | document.head.appendChild(script); 3281 | }) 3282 | } 3283 | 3284 | var asyncToGenerator = function (fn) { 3285 | return function () { 3286 | var gen = fn.apply(this, arguments); 3287 | return new Promise(function (resolve, reject) { 3288 | function step(key, arg) { 3289 | try { 3290 | var info = gen[key](arg); 3291 | var value = info.value; 3292 | } catch (error) { 3293 | reject(error); 3294 | return; 3295 | } 3296 | 3297 | if (info.done) { 3298 | resolve(value); 3299 | } else { 3300 | return Promise.resolve(value).then(function (value) { 3301 | step("next", value); 3302 | }, function (err) { 3303 | step("throw", err); 3304 | }); 3305 | } 3306 | } 3307 | 3308 | return step("next"); 3309 | }); 3310 | }; 3311 | }; 3312 | 3313 | var _createContext = createContext(null); 3314 | 3315 | const GoogleApiProvider = _createContext.Provider; 3316 | const GoogleApiConsumer = _createContext.Consumer; 3317 | 3318 | GoogleApiProvider.displayName = 'GoogleApiProvider'; 3319 | GoogleApiConsumer.displayName = 'GoogleApiConsumer'; 3320 | 3321 | class GoogleApi extends React.Component { 3322 | constructor(...args) { 3323 | var _temp; 3324 | 3325 | return _temp = super(...args), this.authorize = () => { 3326 | if (this.auth) { 3327 | this.auth.signIn(); 3328 | } 3329 | }, this.signout = () => { 3330 | if (this.auth) { 3331 | this.auth.signOut(); 3332 | } 3333 | }, this.state = { 3334 | signedIn: false, 3335 | client: null, 3336 | loading: true, 3337 | error: null, 3338 | authorize: this.authorize, 3339 | signout: this.signout 3340 | }, _temp; 3341 | } 3342 | 3343 | componentDidMount() { 3344 | this.setupApi(); 3345 | } 3346 | 3347 | setupApi() { 3348 | var _this = this; 3349 | 3350 | return asyncToGenerator(function* () { 3351 | try { 3352 | if (typeof window.gapi === 'undefined') { 3353 | yield loadScript('https://apis.google.com/js/api.js'); 3354 | } 3355 | if (!gapi.client) { 3356 | yield new Promise(function (resolve, reject) { 3357 | return gapi.load('client:auth2', { 3358 | callback: resolve, 3359 | onerror: reject 3360 | }); 3361 | }); 3362 | } 3363 | yield gapi.client.init({ 3364 | apiKey: _this.props.apiKey, 3365 | clientId: _this.props.clientId, 3366 | discoveryDocs: _this.props.discoveryDocs, 3367 | scope: _this.props.scopes.join(',') 3368 | }); 3369 | } catch (error) { 3370 | _this.setState({ 3371 | loading: false, 3372 | error 3373 | }); 3374 | return; 3375 | } 3376 | _this.auth = gapi.auth2.getAuthInstance(); 3377 | _this.setState({ 3378 | client: gapi.client, 3379 | loading: false, 3380 | signedIn: _this.auth.isSignedIn.get() 3381 | }); 3382 | _this.auth.isSignedIn.listen(function (signedIn) { 3383 | return _this.setState({ signedIn }); 3384 | }); 3385 | })(); 3386 | } 3387 | 3388 | render() { 3389 | return React.createElement( 3390 | GoogleApiProvider, 3391 | { value: this.state }, 3392 | typeof this.props.children === 'function' ? this.props.children(this.state) : this.props.children 3393 | ); 3394 | } 3395 | } 3396 | 3397 | GoogleApi.propTypes = { 3398 | clientId: propTypes$1.string.isRequired, 3399 | apiKey: propTypes$1.string.isRequired, 3400 | discoveryDocs: propTypes$1.arrayOf(propTypes$1.string).isRequired, 3401 | scopes: propTypes$1.arrayOf(propTypes$1.string).isRequired, 3402 | children: propTypes$1.oneOfType([propTypes$1.func, propTypes$1.node]) 3403 | }; 3404 | 3405 | var asyncToGenerator$1 = function (fn) { 3406 | return function () { 3407 | var gen = fn.apply(this, arguments); 3408 | return new Promise(function (resolve, reject) { 3409 | function step(key, arg) { 3410 | try { 3411 | var info = gen[key](arg); 3412 | var value = info.value; 3413 | } catch (error) { 3414 | reject(error); 3415 | return; 3416 | } 3417 | 3418 | if (info.done) { 3419 | resolve(value); 3420 | } else { 3421 | return Promise.resolve(value).then(function (value) { 3422 | step("next", value); 3423 | }, function (err) { 3424 | step("throw", err); 3425 | }); 3426 | } 3427 | } 3428 | 3429 | return step("next"); 3430 | }); 3431 | }; 3432 | }; 3433 | 3434 | 3435 | 3436 | 3437 | 3438 | 3439 | 3440 | 3441 | 3442 | 3443 | 3444 | var _extends$1 = Object.assign || function (target) { 3445 | for (var i = 1; i < arguments.length; i++) { 3446 | var source = arguments[i]; 3447 | 3448 | for (var key in source) { 3449 | if (Object.prototype.hasOwnProperty.call(source, key)) { 3450 | target[key] = source[key]; 3451 | } 3452 | } 3453 | } 3454 | 3455 | return target; 3456 | }; 3457 | 3458 | 3459 | 3460 | 3461 | 3462 | 3463 | 3464 | 3465 | 3466 | 3467 | 3468 | 3469 | 3470 | var objectWithoutProperties = function (obj, keys) { 3471 | var target = {}; 3472 | 3473 | for (var i in obj) { 3474 | if (keys.indexOf(i) >= 0) continue; 3475 | if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; 3476 | target[i] = obj[i]; 3477 | } 3478 | 3479 | return target; 3480 | }; 3481 | 3482 | class GSheetData extends React.Component { 3483 | 3484 | constructor(props) { 3485 | super(props); 3486 | this.state = { 3487 | error: null, 3488 | data: null, 3489 | loading: false 3490 | }; 3491 | this.fetch = this.fetch.bind(this); 3492 | } 3493 | 3494 | componentDidMount() { 3495 | this.fetch(); 3496 | } 3497 | 3498 | componentDidUpdate(prevProps) { 3499 | if (!equalByKeys(this.props, prevProps, 'id', 'range')) { 3500 | this.fetch(); 3501 | } 3502 | } 3503 | 3504 | fetch() { 3505 | var _this = this; 3506 | 3507 | return asyncToGenerator$1(function* () { 3508 | _this.setState({ loading: true }); 3509 | try { 3510 | const params = { 3511 | spreadsheetId: _this.props.id, 3512 | range: _this.props.range 3513 | }; 3514 | const response = yield _this.props.api.client.sheets.spreadsheets.values.get(params); 3515 | // Unable to cancel requests, so we wait until it's done and check it's still the desired one 3516 | if (_this.props.id === params.spreadsheetId && _this.props.range === params.range) { 3517 | _this.setState({ 3518 | loading: false, 3519 | error: null, 3520 | data: response.result.values 3521 | }); 3522 | } 3523 | } catch (response) { 3524 | // If the api is still null, this will be a TypeError, not a response object 3525 | const error = response.result ? response.result.error : response; 3526 | _this.setState({ loading: false, error }); 3527 | } 3528 | })(); 3529 | } 3530 | 3531 | render() { 3532 | return this.props.children({ 3533 | error: this.state.error, 3534 | data: this.state.data, 3535 | loading: this.state.loading, 3536 | refetch: this.fetch 3537 | }); 3538 | } 3539 | } 3540 | 3541 | GSheetData.propTypes = { 3542 | id: propTypes.string.isRequired, 3543 | range: propTypes.string.isRequired, 3544 | api: propTypes.object.isRequired 3545 | }; 3546 | const GoogleSheet = props => React.createElement( 3547 | GoogleApiConsumer, 3548 | null, 3549 | api => React.createElement(GSheetData, _extends$1({ api: api }, props)) 3550 | ); 3551 | 3552 | const GoogleSheetsApi = (_ref) => { 3553 | var _ref$scopes = _ref.scopes; 3554 | let scopes = _ref$scopes === undefined ? ['https://www.googleapis.com/auth/spreadsheets.readonly'] : _ref$scopes, 3555 | props = objectWithoutProperties(_ref, ['scopes']); 3556 | return React.createElement(GoogleApi, _extends$1({ 3557 | scopes: scopes, 3558 | discoveryDocs: ['https://sheets.googleapis.com/$discovery/rest?version=v4'] 3559 | }, props)); 3560 | }; 3561 | 3562 | exports.GoogleSheet = GoogleSheet; 3563 | exports.GoogleSheetsApi = GoogleSheetsApi; 3564 | 3565 | Object.defineProperty(exports, '__esModule', { value: true }); 3566 | 3567 | }))); 3568 | -------------------------------------------------------------------------------- /dist/index.umd.min.js: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t(e.ReactGoogleSheet={},e.React)}(this,function(e,t){"use strict";function r(e){return function(){return e}}t=t&&t.hasOwnProperty("default")?t.default:t;var n=function(){};n.thatReturns=r,n.thatReturnsFalse=r(!1),n.thatReturnsTrue=r(!0),n.thatReturnsNull=r(null),n.thatReturnsThis=function(){return this},n.thatReturnsArgument=function(e){return e};var o=n;var i=function(e,t,r,n,o,i,s,a){if(!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[r,n,o,i,s,a],p=0;(c=new Error(t.replace(/%s/g,function(){return u[p++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}},s=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable;(function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}})()&&Object.assign;var u,p="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",l=(function(e){e.exports=function(){function e(e,t,r,n,o,s){s!==p&&i(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=o,r.PropTypes=r,r}()}(u={exports:{}},u.exports),u.exports);function h(e){return function(){return e}}var f=function(){};f.thatReturns=h,f.thatReturnsFalse=h(!1),f.thatReturnsTrue=h(!0),f.thatReturnsNull=h(null),f.thatReturnsThis=function(){return this},f.thatReturnsArgument=function(e){return e};var d=f;var y=function(e,t,r,n,o,i,s,a){if(!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[r,n,o,i,s,a],p=0;(c=new Error(t.replace(/%s/g,function(){return u[p++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}},b=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;(function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}})()&&Object.assign;var g="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",O=function(e,t){return e(t={exports:{}},t.exports),t.exports}(function(e){e.exports=function(){function e(e,t,r,n,o,i){i!==g&&y(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=d,r.PropTypes=r,r}()}),j=function(e,t,r,n,o,i,s,a){if(!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[r,n,o,i,s,a],p=0;(c=new Error(t.replace(/%s/g,function(){return u[p++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}},P=function(){};var w=P;function x(){var e=!1;return function(t){w(e,t),e=!0}}var S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},R=Object.assign||function(e){for(var t=1;t is deprecated and will be removed in the next major release. Please use createContext instead. See https://goo.gl/QAF37J for more info.")},r.prototype.componentWillReceiveProps=function(e){j(this.props.channel===e.channel,"You cannot change "),this.props.compareValues(this.props.value,e.value)||this.broadcast.publish(e.value)},r.prototype.render=function(){return t.Children.only(this.props.children)},r}(t.Component);I.propTypes={channel:O.string.isRequired,children:O.node.isRequired,compareValues:O.func,value:O.any},I.defaultProps={compareValues:function(e,t){return e===t}},I.contextTypes={broadcasts:O.object},I.childContextTypes={broadcasts:O.object.isRequired};var q=x(),A=function(e){function t(){var r,n;T(this,t);for(var o=arguments.length,i=Array(o),s=0;s must be rendered in the context of a ',this.props.channel,this.props.channel),e},t.prototype.componentWillMount=function(){q(" is deprecated and will be removed in the next major release. Please use createContext instead. See https://goo.gl/QAF37J for more info.");var e=this.getBroadcast();e&&this.setState({value:e.getValue()})},t.prototype.componentDidMount=function(){var e=this,t=this.getBroadcast();t&&(this.unsubscribe=t.subscribe(function(t){e.setState({value:t})}))},t.prototype.componentWillUnmount=function(){this.unsubscribe&&this.unsubscribe()},t.prototype.render=function(){var e=this.props.children;return e?e(this.state.value):null},t}(t.Component);A.propTypes={channel:O.string.isRequired,children:O.func,quiet:O.bool},A.defaultProps={quiet:!1},A.contextTypes={broadcasts:O.object};var k={string:O.string,number:O.number,function:O.func,boolean:O.bool};var D=function(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,r){return function n(o,i){try{var s=t[o](i),a=s.value}catch(e){return void r(e)}if(!s.done)return Promise.resolve(a).then(function(e){n("next",e)},function(e){n("throw",e)});e(a)}("next")})}},V=function(e){var r,n,o="object"===(n=void 0===(r=e)?"undefined":S(r))?Array.isArray(r)?O.array:O.object:k[n]||O.any,i=Symbol(),s=function(e){function t(){var r,n;T(this,t);for(var o=arguments.length,i=Array(o),s=0;s was rendered outside the context of its ")},r.prototype.componentWillUnmount=function(){this.unsubscribe&&this.unsubscribe()},r.prototype.render=function(){var e=this.props.children;return e?e(this.state.value):null},r}(t.Component);return a.contextTypes={broadcasts:O.object},a.propTypes={children:O.func,quiet:O.bool},a.defaultProps={quiet:!1},{Provider:s,Consumer:a}}(null);const M=V.Provider,N=V.Consumer;M.displayName="GoogleApiProvider",N.displayName="GoogleApiConsumer";class B extends t.Component{constructor(...e){var t;return t=super(...e),this.authorize=(()=>{this.auth&&this.auth.signIn()}),this.signout=(()=>{this.auth&&this.auth.signOut()}),this.state={signedIn:!1,client:null,loading:!0,error:null,authorize:this.authorize,signout:this.signout},t}componentDidMount(){this.setupApi()}setupApi(){var e=this;return D(function*(){try{void 0===window.gapi&&(yield(t="https://apis.google.com/js/api.js",new Promise((e,r)=>{const n=document.createElement("script");n.onload=e,n.onerror=r,n.src=t,n.async=!0,n.type="text/javascript",document.head.appendChild(n)}))),gapi.client||(yield new Promise(function(e,t){return gapi.load("client:auth2",{callback:e,onerror:t})})),yield gapi.client.init({apiKey:e.props.apiKey,clientId:e.props.clientId,discoveryDocs:e.props.discoveryDocs,scope:e.props.scopes.join(",")})}catch(t){return void e.setState({loading:!1,error:t})}var t;e.auth=gapi.auth2.getAuthInstance(),e.setState({client:gapi.client,loading:!1,signedIn:e.auth.isSignedIn.get()}),e.auth.isSignedIn.listen(function(t){return e.setState({signedIn:t})})})()}render(){return t.createElement(M,{value:this.state},"function"==typeof this.props.children?this.props.children(this.state):this.props.children)}}B.propTypes={clientId:l.string.isRequired,apiKey:l.string.isRequired,discoveryDocs:l.arrayOf(l.string).isRequired,scopes:l.arrayOf(l.string).isRequired,children:l.oneOfType([l.func,l.node])};var W=function(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,r){return function n(o,i){try{var s=t[o](i),a=s.value}catch(e){return void r(e)}if(!s.done)return Promise.resolve(a).then(function(e){n("next",e)},function(e){n("throw",e)});e(a)}("next")})}},U=Object.assign||function(e){for(var t=1;te[r]!==t[r])})(this.props,e,"id","range")||this.fetch()}fetch(){var e=this;return W(function*(){e.setState({loading:!0});try{const t={spreadsheetId:e.props.id,range:e.props.range},r=yield e.props.api.client.sheets.spreadsheets.values.get(t);e.props.id===t.spreadsheetId&&e.props.range===t.range&&e.setState({loading:!1,error:null,data:r.result.values})}catch(t){const r=t.result?t.result.error:t;e.setState({loading:!1,error:r})}})()}render(){return this.props.children({error:this.state.error,data:this.state.data,loading:this.state.loading,refetch:this.fetch})}}e.GoogleSheet=(e=>t.createElement(N,null,r=>t.createElement(F,U({api:r},e)))),e.GoogleSheetsApi=(e=>{var r=e.scopes;let n=void 0===r?["https://www.googleapis.com/auth/spreadsheets.readonly"]:r,o=function(e,t){var r={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}(e,["scopes"]);return t.createElement(B,U({scopes:n,discoveryDocs:["https://sheets.googleapis.com/$discovery/rest?version=v4"]},o))}),Object.defineProperty(e,"__esModule",{value:!0})}); 2 | -------------------------------------------------------------------------------- /example/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | pathPrefix: 'react-google-sheet', 3 | } 4 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-google-sheet-example", 3 | "version": "0.0.3", 4 | "private": true, 5 | "author": "Louis DeScioli", 6 | "homepage": "https://lourd.github.io/react-google-sheet", 7 | "scripts": { 8 | "build": "gatsby build", 9 | "build:gh": "gatsby build --prefix-paths", 10 | "start": "gatsby develop", 11 | "deploy": "rm -rf public && yarn run build:gh && gh-pages -d public" 12 | }, 13 | "dependencies": { 14 | "gatsby": "^1.9.166", 15 | "gh-pages": "^1.1.0", 16 | "prop-types": "^15.6.0", 17 | "react": "^16.2.0", 18 | "react-dom": "^16.2.0", 19 | "react-helmet": "^5.2.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/src/ApiForm.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types' 3 | import Field from './Field' 4 | 5 | class ApiForm extends React.Component { 6 | static propTypes = { 7 | onSubmit: PropTypes.func.isRequired, 8 | } 9 | 10 | state = { 11 | apiKey: this.props.init.apiKey, 12 | clientId: this.props.init.clientId, 13 | } 14 | 15 | handleSubmit = event => { 16 | event.preventDefault() 17 | this.props.onSubmit(this.state) 18 | } 19 | 20 | handleChange = (key, value) => this.setState({ [key]: value }) 21 | 22 | render() { 23 | return ( 24 |
25 | 31 | 37 | 38 | 39 | ) 40 | } 41 | } 42 | 43 | export default ApiForm 44 | -------------------------------------------------------------------------------- /example/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types' 3 | import Head from 'react-helmet' 4 | import { GoogleSheetsApi } from '../../' 5 | import DynamicSpreadsheet from './DynamicSpreadsheet' 6 | import ApiForm from './ApiForm' 7 | import Blob from './Blob' 8 | 9 | const SheetsDemo = props => ( 10 | 11 | {({ authorize, loading: apiLoading, signout, signedIn, error }) => ( 12 |
13 | {apiLoading ? ( 14 |
Loading...
15 | ) : error ? ( 16 | 17 | ) : signedIn ? ( 18 | 19 | ) : ( 20 | 21 | )} 22 | {signedIn && } 23 |
24 | )} 25 |
26 | ) 27 | 28 | SheetsDemo.propTypes = { 29 | clientId: PropTypes.string.isRequired, 30 | apiKey: PropTypes.string.isRequired, 31 | reset: PropTypes.func.isRequired, 32 | } 33 | 34 | class App extends React.Component { 35 | state = { 36 | apiKey: 'AIzaSyDS0rsId2YdsGWAgU4xiLm8zS8gf4k9d2Y', 37 | clientId: 38 | '377437361891-v0ib2hve7mupdcpsibtuqr35o2h61op9.apps.googleusercontent.com', 39 | } 40 | 41 | handleSubmit = state => this.setState(state) 42 | 43 | reset = () => this.setState({ apiKey: '', clientId: '' }) 44 | 45 | render() { 46 | return ( 47 |
48 | 49 | Google Sheets React Component Demo 50 | 51 |

Google Sheets API React Component

52 | {this.state.apiKey && ( 53 | 54 | )} 55 | {this.state.apiKey ? ( 56 | 61 | ) : ( 62 | 63 | )} 64 |
65 | ) 66 | } 67 | } 68 | 69 | export default App 70 | -------------------------------------------------------------------------------- /example/src/Blob.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Blob = ({ data }) =>
{JSON.stringify(data, null, 2)}
; 4 | 5 | export default Blob; 6 | -------------------------------------------------------------------------------- /example/src/DynamicSpreadsheet.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | import Blob from './Blob' 4 | import Field from './Field' 5 | import { GoogleSheet } from '../../' 6 | import Select from './Select' 7 | import Table from './Table' 8 | 9 | const RenderChoices = { 10 | table: Table, 11 | blob: Blob, 12 | } 13 | 14 | const MyData = ({ data, render }) => { 15 | const Comp = RenderChoices[render] 16 | return 17 | } 18 | 19 | // Wraps the GoogleSheet component to provide some basic components 20 | // for display loading & error states 21 | const SimpleGSheet = props => ( 22 | 23 | {({ error, data, loading }) => 24 | loading ? ( 25 | 'Getting data...' 26 | ) : error ? ( 27 | JSON.stringify(error, null, 2) 28 | ) : data ? ( 29 | 30 | ) : null 31 | } 32 | 33 | ) 34 | 35 | class DynamicSpreadsheet extends React.Component { 36 | state = { 37 | id: '', 38 | range: '', 39 | render: 'table', 40 | submitted: null, 41 | } 42 | 43 | handleSubmit = event => { 44 | event.preventDefault() 45 | this.setState({ 46 | submitted: { 47 | id: this.state.id, 48 | range: this.state.range, 49 | }, 50 | }) 51 | } 52 | 53 | handleChange = (key, value) => this.setState({ [key]: value }) 54 | 55 | render() { 56 | return ( 57 |
58 |
59 | 65 | 71 | 79 | 80 | {this.state.submitted && ( 81 | 86 | )} 87 |
88 | ) 89 | } 90 | } 91 | 92 | export default DynamicSpreadsheet 93 | -------------------------------------------------------------------------------- /example/src/Field.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | class Field extends React.Component { 5 | static propTypes = { 6 | name: PropTypes.string.isRequired, 7 | onChange: PropTypes.func.isRequired, 8 | value: PropTypes.any, 9 | label: PropTypes.string 10 | }; 11 | 12 | handleChange = event => { 13 | this.props.onChange(this.props.name, event.target.value); 14 | }; 15 | 16 | render() { 17 | const label = this.props.label || this.props.name; 18 | return ( 19 |
20 | 21 |
22 | 27 |
28 |
29 | ); 30 | } 31 | } 32 | 33 | export default Field; 34 | -------------------------------------------------------------------------------- /example/src/Octokitty/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './style.css'; 3 | 4 | // Forked from https://github.com/tholman/github-corners 5 | 6 | const Octokitty = props => ( 7 | 12 | 25 | 26 | ); 27 | 28 | export default Octokitty; 29 | -------------------------------------------------------------------------------- /example/src/Octokitty/style.css: -------------------------------------------------------------------------------- 1 | .github-corner:hover .octo-arm { 2 | animation: octocat-wave 560ms ease-in-out; 3 | } 4 | @keyframes octocat-wave { 5 | 0%, 6 | 100% { 7 | transform: rotate(0); 8 | } 9 | 20%, 10 | 60% { 11 | transform: rotate(-25deg); 12 | } 13 | 40%, 14 | 80% { 15 | transform: rotate(10deg); 16 | } 17 | } 18 | @media (max-width: 500px) { 19 | .github-corner:hover .octo-arm { 20 | animation: none; 21 | } 22 | .github-corner .octo-arm { 23 | animation: octocat-wave 560ms ease-in-out; 24 | } 25 | } 26 | .octo-arm { 27 | transform-origin: 130px 106px; 28 | } 29 | 30 | .github-corner svg { 31 | fill: #222; 32 | color: #fff; 33 | position: absolute; 34 | top: 0; 35 | border: 0; 36 | right: 0; 37 | } 38 | -------------------------------------------------------------------------------- /example/src/Select.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | class Select extends React.Component { 5 | static propTypes = { 6 | name: PropTypes.string.isRequired, 7 | onChange: PropTypes.func.isRequired, 8 | value: PropTypes.any, 9 | label: PropTypes.string 10 | }; 11 | 12 | handleChange = event => { 13 | this.props.onChange(this.props.name, event.target.value); 14 | }; 15 | 16 | render() { 17 | const label = this.props.label || this.props.name; 18 | return ( 19 |
20 | 21 |
22 | 33 |
34 |
35 | ); 36 | } 37 | } 38 | 39 | export default Select; 40 | -------------------------------------------------------------------------------- /example/src/Table.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Table = ({ data }) => ( 4 | 5 | 6 | {data[0].map((label, i) => )} 7 | 8 | 9 | {data 10 | .slice(1) 11 | .map((row, i) => ( 12 | {row.map((cell, j) => )} 13 | ))} 14 | 15 |
{label}
{cell}
16 | ); 17 | 18 | export default Table; 19 | -------------------------------------------------------------------------------- /example/src/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import Head from 'react-helmet'; 4 | import Octokitty from '../Octokitty'; 5 | import App from '../App'; 6 | 7 | import './style.css'; 8 | 9 | export default () => ( 10 |
11 | 12 | 13 |
14 | ); 15 | -------------------------------------------------------------------------------- /example/src/pages/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, 3 | Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; 4 | } 5 | 6 | label { 7 | display: inline-block; 8 | margin-bottom: 2px; 9 | font-size: 0.8em; 10 | } 11 | 12 | input, 13 | button { 14 | margin-bottom: 5px; 15 | } 16 | -------------------------------------------------------------------------------- /modules/GoogleSheet.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types' 3 | import equalByKeys from '@lourd/equal-by-keys' 4 | import { GoogleApiConsumer } from '@lourd/react-google-api' 5 | 6 | class GSheetData extends React.Component { 7 | static propTypes = { 8 | id: PropTypes.string.isRequired, 9 | range: PropTypes.string.isRequired, 10 | api: PropTypes.object.isRequired, 11 | } 12 | 13 | state = { 14 | error: null, 15 | data: null, 16 | loading: false, 17 | } 18 | 19 | constructor(props) { 20 | super(props) 21 | this.fetch = this.fetch.bind(this) 22 | } 23 | 24 | componentDidMount() { 25 | this.fetch() 26 | } 27 | 28 | componentDidUpdate(prevProps) { 29 | if (!equalByKeys(this.props, prevProps, 'id', 'range')) { 30 | this.fetch() 31 | } 32 | } 33 | 34 | async fetch() { 35 | this.setState({ loading: true }) 36 | try { 37 | const params = { 38 | spreadsheetId: this.props.id, 39 | range: this.props.range, 40 | } 41 | const response = await this.props.api.client.sheets.spreadsheets.values.get( 42 | params, 43 | ) 44 | // Unable to cancel requests, so we wait until it's done and check it's still the desired one 45 | if ( 46 | this.props.id === params.spreadsheetId && 47 | this.props.range === params.range 48 | ) { 49 | this.setState({ 50 | loading: false, 51 | error: null, 52 | data: response.result.values, 53 | }) 54 | } 55 | } catch (response) { 56 | // If the api is still null, this will be a TypeError, not a response object 57 | const error = response.result ? response.result.error : response 58 | this.setState({ loading: false, error }) 59 | } 60 | } 61 | 62 | render() { 63 | return this.props.children({ 64 | error: this.state.error, 65 | data: this.state.data, 66 | loading: this.state.loading, 67 | refetch: this.fetch, 68 | }) 69 | } 70 | } 71 | 72 | const GoogleSheet = props => ( 73 | 74 | {api => } 75 | 76 | ) 77 | 78 | export default GoogleSheet 79 | export { GSheetData } 80 | -------------------------------------------------------------------------------- /modules/GoogleSheetsApi.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { GoogleApi } from '@lourd/react-google-api' 3 | 4 | const GoogleSheetsApi = ({ 5 | scopes = ['https://www.googleapis.com/auth/spreadsheets.readonly'], 6 | ...props 7 | }) => ( 8 | 13 | ) 14 | 15 | export default GoogleSheetsApi 16 | -------------------------------------------------------------------------------- /modules/__tests__/GoogleSheet.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { mount } from 'enzyme' 3 | 4 | import Deferred from '@lourd/deferred' 5 | import { GoogleSheetApi, GoogleSheet } from '../' 6 | import { GSheetData } from '../GoogleSheet' 7 | 8 | it("renders the underlying GSheetData component with the api from context and passes through props, freaking out if there isn't an api provided in context", () => { 9 | jest.spyOn(console, 'error').mockImplementation(() => {}) 10 | const fn = jest.fn(() => null) 11 | const props = { 12 | id: 'foo', 13 | range: 'things', 14 | foo: 'bar', 15 | } 16 | const result = mount({fn}) 17 | expect(result).toMatchSnapshot('mounted component') 18 | expect(fn).toMatchSnapshot('child function calls') 19 | expect(console.error).toMatchSnapshot('logged errors') 20 | console.error.mockRestore() 21 | }) 22 | 23 | describe('GSheetData component', () => { 24 | it('calls the api methods to load the data and renders the children function with the data loading state and a refetch function', async () => { 25 | const api = { 26 | client: { 27 | sheets: { 28 | spreadsheets: { 29 | values: { 30 | get: jest.fn(), 31 | }, 32 | }, 33 | }, 34 | }, 35 | } 36 | const deferred = new Deferred() 37 | api.client.sheets.spreadsheets.values.get.mockReturnValueOnce( 38 | deferred.promise, 39 | ) 40 | const props = { 41 | id: 'foo', 42 | range: 'bar', 43 | api, 44 | } 45 | const children = jest.fn(() => null) 46 | const wrapper = mount({children}) 47 | expect(wrapper.state()).toMatchSnapshot('loading state') 48 | expect(api.client.sheets.spreadsheets.values.get).toMatchSnapshot( 49 | 'spreadsheet data loading method call', 50 | ) 51 | const response = { 52 | result: { 53 | values: ['🤖', '👽', '💩'], 54 | }, 55 | } 56 | deferred.resolve(response) 57 | // wait here for component updates to occur 58 | await deferred.promise 59 | expect(wrapper.state()).toMatchSnapshot('resolved state') 60 | expect(children).toMatchSnapshot('children function calls') 61 | }) 62 | 63 | it('refetches if the id or range props changes', () => { 64 | const response = { result: { values: ['🤖', '👽', '💩'] } } 65 | const api = { 66 | client: { 67 | sheets: { 68 | spreadsheets: { 69 | values: { get: jest.fn(() => Promise.resolve(response)) }, 70 | }, 71 | }, 72 | }, 73 | } 74 | const props = { id: 'foo', range: 'bar', api } 75 | const wrapper = mount({() => null}) 76 | wrapper.setProps({ id: 'different' }) 77 | wrapper.setProps({ range: 'also different ' }) 78 | expect(api.client.sheets.spreadsheets.values.get).toMatchSnapshot( 79 | 'multiple data loading calls', 80 | ) 81 | }) 82 | 83 | it("doesn't update state if the id or range changed while the data was being fetched", async () => { 84 | const api = { 85 | client: { 86 | sheets: { 87 | spreadsheets: { values: { get: jest.fn() } }, 88 | }, 89 | }, 90 | } 91 | const request1 = new Deferred() 92 | const request2 = new Deferred() 93 | api.client.sheets.spreadsheets.values.get 94 | .mockReturnValueOnce(request1.promise) 95 | .mockReturnValueOnce(request2.promise) 96 | const children = jest.fn(() => null) 97 | const response1 = { result: { values: ['🤖', '👽', '💩'] } } 98 | const response2 = { result: { values: ['💂', '👩‍🎤', '👢'] } } 99 | const props = { id: 'foo', range: 'bar', api } 100 | const wrapper = mount({children}) 101 | wrapper.setProps({ id: 'different' }) 102 | request1.resolve(response1) 103 | await request1.promise 104 | expect(wrapper.state()).toMatchSnapshot('final state') 105 | }) 106 | 107 | it('sets the error in state if the data request has an error', async () => { 108 | const deferred = new Deferred() 109 | const api = { 110 | client: { 111 | sheets: { 112 | spreadsheets: { values: { get: jest.fn(() => deferred.promise) } }, 113 | }, 114 | }, 115 | } 116 | const props = { id: 'foo', range: 'bar', api } 117 | const children = jest.fn(() => null) 118 | const wrapper = mount({children}) 119 | const error = new Error('👻👹') 120 | const response = { result: { error } } 121 | deferred.reject(response) 122 | // have to wait on the promise here so rejecting it propagates through the react component update 123 | await expect(deferred.promise).rejects 124 | expect(wrapper.state()).toMatchSnapshot('resolved error state') 125 | expect(children).toMatchSnapshot('children function calls with error state') 126 | }) 127 | }) 128 | -------------------------------------------------------------------------------- /modules/__tests__/GoogleSheetsApi.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { mount } from 'enzyme' 3 | 4 | import GoogleSheetsApi from '../GoogleSheetsApi' 5 | 6 | it('renders the GoogleApi with the sheets discovery doc provided and a default scope and passes all props through', () => { 7 | const result = mount( 8 | 9 | {null} 10 | , 11 | ) 12 | expect(result).toMatchSnapshot('default case') 13 | }) 14 | 15 | it('accepts an array of scopes', () => { 16 | const result = mount( 17 | 18 | {null} 19 | , 20 | ) 21 | expect(result).toMatchSnapshot('custom scopes') 22 | }) 23 | -------------------------------------------------------------------------------- /modules/__tests__/__snapshots__/GoogleSheet.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`GSheetData component calls the api methods to load the data and renders the children function with the data loading state and a refetch function: children function calls 1`] = ` 4 | [MockFunction] { 5 | "calls": Array [ 6 | Array [ 7 | Object { 8 | "data": null, 9 | "error": null, 10 | "loading": false, 11 | "refetch": [Function], 12 | }, 13 | ], 14 | Array [ 15 | Object { 16 | "data": null, 17 | "error": null, 18 | "loading": true, 19 | "refetch": [Function], 20 | }, 21 | ], 22 | Array [ 23 | Object { 24 | "data": Array [ 25 | "🤖", 26 | "👽", 27 | "💩", 28 | ], 29 | "error": null, 30 | "loading": false, 31 | "refetch": [Function], 32 | }, 33 | ], 34 | ], 35 | } 36 | `; 37 | 38 | exports[`GSheetData component calls the api methods to load the data and renders the children function with the data loading state and a refetch function: loading state 1`] = ` 39 | Object { 40 | "data": null, 41 | "error": null, 42 | "loading": true, 43 | } 44 | `; 45 | 46 | exports[`GSheetData component calls the api methods to load the data and renders the children function with the data loading state and a refetch function: resolved state 1`] = ` 47 | Object { 48 | "data": Array [ 49 | "🤖", 50 | "👽", 51 | "💩", 52 | ], 53 | "error": null, 54 | "loading": false, 55 | } 56 | `; 57 | 58 | exports[`GSheetData component calls the api methods to load the data and renders the children function with the data loading state and a refetch function: spreadsheet data loading method call 1`] = ` 59 | [MockFunction] { 60 | "calls": Array [ 61 | Array [ 62 | Object { 63 | "range": "bar", 64 | "spreadsheetId": "foo", 65 | }, 66 | ], 67 | ], 68 | } 69 | `; 70 | 71 | exports[`GSheetData component doesn't update state if the id or range changed while the data was being fetched: final state 1`] = ` 72 | Object { 73 | "data": null, 74 | "error": null, 75 | "loading": true, 76 | } 77 | `; 78 | 79 | exports[`GSheetData component refetches if the id or range props changes: multiple data loading calls 1`] = ` 80 | [MockFunction] { 81 | "calls": Array [ 82 | Array [ 83 | Object { 84 | "range": "bar", 85 | "spreadsheetId": "foo", 86 | }, 87 | ], 88 | Array [ 89 | Object { 90 | "range": "bar", 91 | "spreadsheetId": "different", 92 | }, 93 | ], 94 | Array [ 95 | Object { 96 | "range": "also different ", 97 | "spreadsheetId": "different", 98 | }, 99 | ], 100 | ], 101 | } 102 | `; 103 | 104 | exports[`GSheetData component sets the error in state if the data request has an error: children function calls with error state 1`] = ` 105 | [MockFunction] { 106 | "calls": Array [ 107 | Array [ 108 | Object { 109 | "data": null, 110 | "error": null, 111 | "loading": false, 112 | "refetch": [Function], 113 | }, 114 | ], 115 | Array [ 116 | Object { 117 | "data": null, 118 | "error": null, 119 | "loading": true, 120 | "refetch": [Function], 121 | }, 122 | ], 123 | Array [ 124 | Object { 125 | "data": null, 126 | "error": [Error: 👻👹], 127 | "loading": false, 128 | "refetch": [Function], 129 | }, 130 | ], 131 | ], 132 | } 133 | `; 134 | 135 | exports[`GSheetData component sets the error in state if the data request has an error: resolved error state 1`] = ` 136 | Object { 137 | "data": null, 138 | "error": [Error: 👻👹], 139 | "loading": false, 140 | } 141 | `; 142 | 143 | exports[`renders the underlying GSheetData component with the api from context and passes through props, freaking out if there isn't an api provided in context: child function calls 1`] = ` 144 | [MockFunction] { 145 | "calls": Array [ 146 | Array [ 147 | Object { 148 | "data": null, 149 | "error": null, 150 | "loading": false, 151 | "refetch": [Function], 152 | }, 153 | ], 154 | Array [ 155 | Object { 156 | "data": null, 157 | "error": [TypeError: Cannot read property 'client' of null], 158 | "loading": false, 159 | "refetch": [Function], 160 | }, 161 | ], 162 | ], 163 | } 164 | `; 165 | 166 | exports[`renders the underlying GSheetData component with the api from context and passes through props, freaking out if there isn't an api provided in context: logged errors 1`] = ` 167 | [MockFunction] { 168 | "calls": Array [ 169 | Array [ 170 | "Warning: Failed prop type: The prop \`api\` is marked as required in \`GSheetData\`, but its value is \`null\`. 171 | in GSheetData (created by GoogleApiConsumer) 172 | in GoogleApiConsumer (created by GoogleSheet) 173 | in GoogleSheet (created by WrapperComponent) 174 | in WrapperComponent", 175 | ], 176 | Array [ 177 | "Warning: was rendered outside the context of its ", 178 | ], 179 | ], 180 | } 181 | `; 182 | 183 | exports[`renders the underlying GSheetData component with the api from context and passes through props, freaking out if there isn't an api provided in context: mounted component 1`] = ` 184 | 189 | 192 | 198 | 199 | 200 | `; 201 | -------------------------------------------------------------------------------- /modules/__tests__/__snapshots__/GoogleSheetsApi.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`accepts an array of scopes: custom scopes 1`] = ` 4 | 14 | 29 | 41 | 42 | 43 | `; 44 | 45 | exports[`renders the GoogleApi with the sheets discovery doc provided and a default scope and passes all props through: default case 1`] = ` 46 | 51 | 66 | 78 | 79 | 80 | `; 81 | -------------------------------------------------------------------------------- /modules/index.js: -------------------------------------------------------------------------------- 1 | export { default as GoogleSheet } from './GoogleSheet' 2 | export { default as GoogleSheetsApi } from './GoogleSheetsApi' 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@lourd/react-google-sheet", 3 | "version": "0.4.0", 4 | "description": "Google sheets data through React components", 5 | "repository": "lourd/react-google-sheet", 6 | "homepage": "https://github.com/lourd/react-google-sheet", 7 | "author": "Louis DeScioli (descioli.design)", 8 | "license": "MIT", 9 | "main": "dist/index.js", 10 | "module": "dist/index.es.js", 11 | "files": [ 12 | "dist" 13 | ], 14 | "scripts": { 15 | "build": "node ./scripts/build.js", 16 | "release": "npm run build && node ./scripts/release.js", 17 | "test": "jest modules" 18 | }, 19 | "peerDependencies": { 20 | "react": ">=15 || ^16" 21 | }, 22 | "dependencies": { 23 | "@lourd/equal-by-keys": "^0.1.2", 24 | "@lourd/react-google-api": "^0.1.0", 25 | "prop-types": "^15.6.0" 26 | }, 27 | "devDependencies": { 28 | "@lourd/deferred": "^0.1.0", 29 | "babel-core": "^6.17.0", 30 | "babel-eslint": "^7.0.0", 31 | "babel-plugin-external-helpers": "^6.22.0", 32 | "babel-plugin-transform-react-remove-prop-types": "^0.4.12", 33 | "babel-preset-env": "^1.6.1", 34 | "babel-preset-react": "^6.5.0", 35 | "babel-preset-stage-2": "^6.24.1", 36 | "enzyme": "^3.3.0", 37 | "enzyme-adapter-react-16": "^1.1.1", 38 | "enzyme-to-json": "^3.3.1", 39 | "gzip-size": "^3.0.0", 40 | "jest": "^22.0.0", 41 | "pretty-bytes": "^4.0.0", 42 | "raf": "^3.4.0", 43 | "react": "^16.2.0", 44 | "react-dom": "^16.2.0", 45 | "readline-sync": "^1.4.7", 46 | "rollup": "^0.55.0", 47 | "rollup-plugin-babel": "^3.0.3", 48 | "rollup-plugin-commonjs": "^8.2.6", 49 | "rollup-plugin-node-resolve": "^3.0.2", 50 | "rollup-plugin-replace": "^2.0.0", 51 | "rollup-plugin-uglify": "^3.0.0" 52 | }, 53 | "keywords": [], 54 | "jest": { 55 | "setupFiles": [ 56 | "./scripts/testSetup.js" 57 | ], 58 | "snapshotSerializers": [ 59 | "enzyme-to-json/serializer" 60 | ] 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import babel from 'rollup-plugin-babel' 2 | import commonjs from 'rollup-plugin-commonjs' 3 | import replace from 'rollup-plugin-replace' 4 | import resolve from 'rollup-plugin-node-resolve' 5 | import uglify from 'rollup-plugin-uglify' 6 | 7 | const { BUILD_ENV, BUILD_FORMAT } = process.env 8 | 9 | const babelPlugins = [ 10 | 'external-helpers' 11 | ] 12 | 13 | if (BUILD_ENV === 'production') { 14 | babelPlugins.push([ 15 | 'transform-react-remove-prop-types', 16 | { removeImport: true }, 17 | ]) 18 | } 19 | 20 | const config = { 21 | input: 'modules/index.js', 22 | output: { 23 | name: 'ReactGoogleSheet', 24 | globals: { 25 | react: 'React', 26 | }, 27 | }, 28 | // by listing no external, everything is external, we just get a warning 29 | // external: [], 30 | plugins: [ 31 | babel({ 32 | babelrc: false, 33 | presets: [ 34 | 'react', 35 | [ 36 | 'env', 37 | { 38 | loose: true, 39 | modules: false, 40 | targets: { 41 | chrome: '60', 42 | edge: '15', 43 | firefox: '57', 44 | ios: '10.3', 45 | }, 46 | }, 47 | ], 48 | 'stage-2' 49 | ], 50 | plugins: babelPlugins, 51 | exclude: 'node_modules/**', 52 | }), 53 | ], 54 | } 55 | 56 | if (BUILD_FORMAT === 'umd') { 57 | // In the browser build, include our smaller dependencies 58 | // so users only need to include React 59 | config.external = ['react'] 60 | config.plugins.push( 61 | ...[ 62 | resolve(), 63 | commonjs({ 64 | include: /node_modules/, 65 | }), 66 | replace({ 67 | 'process.env.NODE_ENV': JSON.stringify(BUILD_ENV), 68 | }), 69 | ], 70 | ) 71 | if (BUILD_ENV === 'production') { 72 | config.plugins.push(uglify()) 73 | } 74 | } 75 | 76 | export default config -------------------------------------------------------------------------------- /scripts/build.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const path = require('path') 3 | const { execSync } = require('child_process') 4 | const pkg = require('../package.json') 5 | const prettyBytes = require('pretty-bytes') 6 | const gzipSize = require('gzip-size') 7 | 8 | const { name, dir } = path.parse(pkg.main) 9 | 10 | const filebase = `${dir}/${name}` 11 | 12 | process.chdir(path.resolve(__dirname, '..')) 13 | 14 | const exec = (command, extraEnv) => 15 | execSync(command, { 16 | stdio: 'inherit', 17 | env: Object.assign({}, process.env, extraEnv), 18 | }) 19 | 20 | const formats = [ 21 | { format: 'cjs', file: `${filebase}.js`, description: 'CJS module' }, 22 | { format: 'es', file: `${filebase}.es.js`, description: 'ES module' }, 23 | { 24 | format: 'umd', 25 | file: `${filebase}.umd.js`, 26 | description: 'UMD module', 27 | env: { 28 | BUILD_FORMAT: 'umd', 29 | }, 30 | }, 31 | { 32 | format: 'umd', 33 | file: `${filebase}.umd.min.js`, 34 | description: 'minified UMD module', 35 | env: { 36 | BUILD_ENV: 'production', 37 | BUILD_FORMAT: 'umd', 38 | }, 39 | }, 40 | ] 41 | 42 | for (const { format, file, description, env } of formats) { 43 | console.log(`Building ${description}...`) 44 | exec(`rollup -c -f ${format} -o ${file}`, env) 45 | } 46 | 47 | for (const { file, description } of formats) { 48 | const minifiedFile = fs.readFileSync(file) 49 | const minifiedSize = prettyBytes(minifiedFile.byteLength) 50 | const gzippedSize = prettyBytes(gzipSize.sync(minifiedFile)) 51 | console.log(`The ${description} is ${minifiedSize}, (${gzippedSize} gzipped)`) 52 | } -------------------------------------------------------------------------------- /scripts/release.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const path = require('path') 3 | const execSync = require('child_process').execSync 4 | const prompt = require('readline-sync').question 5 | 6 | process.chdir(path.resolve(__dirname, '..')) 7 | 8 | const exec = command => execSync(command, { stdio: 'inherit' }) 9 | 10 | const getPackageVersion = () => 11 | JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json'))) 12 | .version 13 | 14 | // Get the next version, which may be specified as a semver 15 | // version number or anything `npm version` recognizes. This 16 | // is a "pre-release" if nextVersion is premajor, preminor, 17 | // prepatch, or prerelease 18 | const nextVersion = prompt( 19 | `Next version (current version is ${getPackageVersion()})? `, 20 | ) 21 | const isPrerelease = 22 | nextVersion.substr(0, 3) === 'pre' || nextVersion.indexOf('-') !== -1 23 | 24 | // 1) Increment the package version in package.json 25 | // 2) Create a new commit 26 | // 3) Create a v* tag that points to that commit 27 | exec(`npm version ${nextVersion} -m "Version %s"`) 28 | 29 | // 4) Publish to npm. Use the "next" tag for pre-releases, 30 | // "latest" for all others 31 | exec(`npm publish --tag ${isPrerelease ? 'next' : 'latest'}`) 32 | 33 | // 5) Push the v* tag to GitHub 34 | exec(`git push origin v${getPackageVersion()}`) 35 | -------------------------------------------------------------------------------- /scripts/testSetup.js: -------------------------------------------------------------------------------- 1 | import 'raf/polyfill' 2 | import { configure } from 'enzyme' 3 | import Adapter from 'enzyme-adapter-react-16' 4 | 5 | configure({ adapter: new Adapter() }) 6 | --------------------------------------------------------------------------------