@stripe/react-stripe-js
Advanced tools
Comparing version 1.0.0-beta.3 to 1.0.0-beta.4
@@ -6,2 +6,35 @@ # Changelog | ||
## v1.0.0-beta.3 2020-01-24 | ||
More examples and miscellaneous documentation updates. | ||
### Fixes | ||
- Removes a warning about `useLayoutEffect` when using React Stripe.js with | ||
server side rendering. | ||
## v1.0.0-beta.2 2020-01-21 | ||
Reversion to v1. | ||
### New Features | ||
- Add support for passing `Promise<StripeObject | null>` to the stripe prop of | ||
`Elements`. This removes the need for users to create and manage their own | ||
state when asynchronously loading Stripe.js and can be used with the | ||
`loadStripe` function from the | ||
[Stripe.js module](https://github.com/stripe/stripe-js). | ||
```jsx | ||
import {loadStripe} from '@stripe/stripe-js'; | ||
const stripePromise = loadStripe('pk_test_6pRNASCoBOKtIshFeQd4XMUh'); | ||
const App = () => <Elements stripe={stripePromise}>{/* ... */}</Elements>; | ||
``` | ||
## v1.0.0-beta.1 2019-12-20 | ||
Rename from @stripe/react-stripe to @stripe/react-stripe-js | ||
## v7.0.0-beta.0 2019-12-18 | ||
@@ -8,0 +41,0 @@ |
import React, { useRef, useEffect, useMemo, useState, useContext, useLayoutEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
var PLAIN_OBJECT_STR = '[object Object]'; | ||
var isEqual = function isEqual(left, right) { | ||
if (_typeof(left) !== 'object' || _typeof(right) !== 'object') { | ||
return left === right; | ||
} | ||
if (left === null || right === null) return left === right; | ||
var leftArray = Array.isArray(left); | ||
var rightArray = Array.isArray(right); | ||
if (leftArray !== rightArray) return false; | ||
var leftPlainObject = Object.prototype.toString.call(left) === PLAIN_OBJECT_STR; | ||
var rightPlainObject = Object.prototype.toString.call(right) === PLAIN_OBJECT_STR; | ||
if (leftPlainObject !== rightPlainObject) return false; | ||
if (!leftPlainObject && !leftArray) return false; | ||
var leftKeys = Object.keys(left); | ||
var rightKeys = Object.keys(right); | ||
if (leftKeys.length !== rightKeys.length) return false; | ||
var keySet = {}; | ||
for (var i = 0; i < leftKeys.length; i += 1) { | ||
keySet[leftKeys[i]] = true; | ||
} | ||
for (var _i = 0; _i < rightKeys.length; _i += 1) { | ||
keySet[rightKeys[_i]] = true; | ||
} | ||
var allKeys = Object.keys(keySet); | ||
if (allKeys.length !== leftKeys.length) { | ||
return false; | ||
} | ||
var l = left; | ||
var r = right; | ||
var pred = function pred(key) { | ||
return isEqual(l[key], r[key]); | ||
}; | ||
return allKeys.every(pred); | ||
const isUnknownObject = (raw) => { | ||
return raw !== null && typeof raw === 'object'; | ||
}; | ||
var usePrevious = function usePrevious(value) { | ||
var ref = useRef(value); | ||
useEffect(function () { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
const isPromise = (raw) => { | ||
return isUnknownObject(raw) && typeof raw.then === 'function'; | ||
}; | ||
// We are using types to enforce the `stripe` prop in this lib, | ||
// but in a real integration `stripe` could be anything, so we need | ||
// but in an untyped integration `stripe` could be anything, so we need | ||
// to do some sanity validation to prevent type errors. | ||
var validateStripe = function validateStripe(maybeStripe) { | ||
if (maybeStripe === null) { | ||
return maybeStripe; | ||
} | ||
if (_typeof(maybeStripe) === 'object' && typeof maybeStripe.elements === 'function' && typeof maybeStripe.createSource === 'function' && typeof maybeStripe.createToken === 'function' && typeof maybeStripe.createPaymentMethod === 'function') { | ||
// If the object appears to be roughly Stripe shaped, | ||
// force cast it to the expected type. | ||
return maybeStripe; | ||
} | ||
throw new Error('Invalid prop `stripe` supplied to `Elements`. Please pass a valid Stripe object or null. ' + 'You can obtain a Stripe object by calling `window.Stripe(...)` with your publishable key.'); | ||
const isStripe = (raw) => { | ||
return (isUnknownObject(raw) && | ||
typeof raw.elements === 'function' && | ||
typeof raw.createToken === 'function' && | ||
typeof raw.createPaymentMethod === 'function' && | ||
typeof raw.confirmCardPayment === 'function'); | ||
}; | ||
var parseStripeProp = function parseStripeProp(raw) { | ||
if (raw !== null && _typeof(raw) === 'object' && raw.then && typeof raw.then === 'function') { | ||
return { | ||
tag: 'async', | ||
stripePromise: Promise.resolve(raw).then(validateStripe) | ||
const PLAIN_OBJECT_STR = '[object Object]'; | ||
const isEqual = (left, right) => { | ||
if (!isUnknownObject(left) || !isUnknownObject(right)) { | ||
return left === right; | ||
} | ||
const leftArray = Array.isArray(left); | ||
const rightArray = Array.isArray(right); | ||
if (leftArray !== rightArray) | ||
return false; | ||
const leftPlainObject = Object.prototype.toString.call(left) === PLAIN_OBJECT_STR; | ||
const rightPlainObject = Object.prototype.toString.call(right) === PLAIN_OBJECT_STR; | ||
if (leftPlainObject !== rightPlainObject) | ||
return false; | ||
if (!leftPlainObject && !leftArray) | ||
return false; | ||
const leftKeys = Object.keys(left); | ||
const rightKeys = Object.keys(right); | ||
if (leftKeys.length !== rightKeys.length) | ||
return false; | ||
const keySet = {}; | ||
for (let i = 0; i < leftKeys.length; i += 1) { | ||
keySet[leftKeys[i]] = true; | ||
} | ||
for (let i = 0; i < rightKeys.length; i += 1) { | ||
keySet[rightKeys[i]] = true; | ||
} | ||
const allKeys = Object.keys(keySet); | ||
if (allKeys.length !== leftKeys.length) { | ||
return false; | ||
} | ||
const l = left; | ||
const r = right; | ||
const pred = (key) => { | ||
return isEqual(l[key], r[key]); | ||
}; | ||
} | ||
var stripe = validateStripe(raw); | ||
if (stripe === null) { | ||
return { | ||
tag: 'empty' | ||
}; | ||
} | ||
return { | ||
tag: 'sync', | ||
stripe: stripe | ||
}; | ||
return allKeys.every(pred); | ||
}; | ||
var ElementsContext = React.createContext(); | ||
var parseElementsContext = function parseElementsContext(ctx, useCase) { | ||
if (!ctx) { | ||
throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(useCase, " in an <Elements> provider.")); | ||
} | ||
return ctx; | ||
const usePrevious = (value) => { | ||
const ref = useRef(value); | ||
useEffect(() => { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
}; | ||
var Elements = function Elements(_ref) { | ||
var rawStripeProp = _ref.stripe, | ||
options = _ref.options, | ||
children = _ref.children; | ||
var _final = useRef(false); | ||
var isMounted = useRef(true); | ||
var parsed = useMemo(function () { | ||
return parseStripeProp(rawStripeProp); | ||
}, [rawStripeProp]); | ||
var _useState = useState(function () { | ||
return { | ||
stripe: null, | ||
elements: null | ||
}; | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
ctx = _useState2[0], | ||
setContext = _useState2[1]; | ||
var prevStripe = usePrevious(rawStripeProp); | ||
var prevOptions = usePrevious(options); | ||
if (prevStripe !== null) { | ||
if (prevStripe !== rawStripeProp) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.'); | ||
const INVALID_STRIPE_ERROR = 'Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.'; | ||
// We are using types to enforce the `stripe` prop in this lib, but in a real | ||
// integration `stripe` could be anything, so we need to do some sanity | ||
// validation to prevent type errors. | ||
const validateStripe = (maybeStripe) => { | ||
if (maybeStripe === null || isStripe(maybeStripe)) { | ||
return maybeStripe; | ||
} | ||
if (!isEqual(options, prevOptions)) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `options` prop after setting the `stripe` prop.'); | ||
throw new Error(INVALID_STRIPE_ERROR); | ||
}; | ||
const parseStripeProp = (raw) => { | ||
if (isPromise(raw)) { | ||
return { | ||
tag: 'async', | ||
stripePromise: Promise.resolve(raw).then(validateStripe), | ||
}; | ||
} | ||
} | ||
if (!_final.current) { | ||
if (parsed.tag === 'sync') { | ||
_final.current = true; | ||
setContext({ | ||
stripe: parsed.stripe, | ||
elements: parsed.stripe.elements(options) | ||
}); | ||
const stripe = validateStripe(raw); | ||
if (stripe === null) { | ||
return { tag: 'empty' }; | ||
} | ||
if (parsed.tag === 'async') { | ||
_final.current = true; | ||
parsed.stripePromise.then(function (stripe) { | ||
if (stripe && isMounted.current) { | ||
// Only update Elements context if the component is still mounted | ||
// and stripe is not null. We allow stripe to be null to make | ||
// handling SSR easier. | ||
setContext({ | ||
stripe: stripe, | ||
elements: stripe.elements(options) | ||
}); | ||
return { tag: 'sync', stripe }; | ||
}; | ||
const ElementsContext = React.createContext(null); | ||
ElementsContext.displayName = 'ElementsContext'; | ||
const parseElementsContext = (ctx, useCase) => { | ||
if (!ctx) { | ||
throw new Error(`Could not find Elements context; You need to wrap the part of your app that ${useCase} in an <Elements> provider.`); | ||
} | ||
return ctx; | ||
}; | ||
/** | ||
* The `Elements` provider allows you to use [Element components](https://stripe.com/docs/stripe-js/react#element-components) and access the [Stripe object](https://stripe.com/docs/js/initializing) in any nested component. | ||
* Render an `Elements` provider at the root of your React app so that it is available everywhere you need it. | ||
* | ||
* To use the `Elements` provider, call `loadStripe` from `@stripe/stripe-js` with your publishable key. | ||
* The `loadStripe` function will asynchronously load the Stripe.js script and initialize a `Stripe` object. | ||
* Pass the returned `Promise` to `Elements`. | ||
* | ||
* @docs https://stripe.com/docs/stripe-js/react#elements-provider | ||
*/ | ||
const Elements = ({ stripe: rawStripeProp, options, children, }) => { | ||
const final = useRef(false); | ||
const isMounted = useRef(true); | ||
const parsed = useMemo(() => parseStripeProp(rawStripeProp), [rawStripeProp]); | ||
const [ctx, setContext] = useState(() => ({ | ||
stripe: null, | ||
elements: null, | ||
})); | ||
const prevStripe = usePrevious(rawStripeProp); | ||
const prevOptions = usePrevious(options); | ||
if (prevStripe !== null) { | ||
if (prevStripe !== rawStripeProp) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.'); | ||
} | ||
}); | ||
if (!isEqual(options, prevOptions)) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `options` prop after setting the `stripe` prop.'); | ||
} | ||
} | ||
} | ||
useEffect(function () { | ||
return function () { | ||
isMounted.current = false; | ||
}; | ||
}, []); | ||
return React.createElement(ElementsContext.Provider, { | ||
value: ctx | ||
}, children); | ||
if (!final.current) { | ||
if (parsed.tag === 'sync') { | ||
final.current = true; | ||
setContext({ | ||
stripe: parsed.stripe, | ||
elements: parsed.stripe.elements(options), | ||
}); | ||
} | ||
if (parsed.tag === 'async') { | ||
final.current = true; | ||
parsed.stripePromise.then((stripe) => { | ||
if (stripe && isMounted.current) { | ||
// Only update Elements context if the component is still mounted | ||
// and stripe is not null. We allow stripe to be null to make | ||
// handling SSR easier. | ||
setContext({ | ||
stripe, | ||
elements: stripe.elements(options), | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
useEffect(() => { | ||
return () => { | ||
isMounted.current = false; | ||
}; | ||
}, []); | ||
return (React.createElement(ElementsContext.Provider, { value: ctx }, children)); | ||
}; | ||
Elements.propTypes = { | ||
stripe: PropTypes.any, | ||
children: PropTypes.node, | ||
options: PropTypes.object | ||
stripe: PropTypes.any, | ||
options: PropTypes.object, | ||
}; | ||
var useElementsContextWithUseCase = function useElementsContextWithUseCase(useCaseMessage) { | ||
var ctx = useContext(ElementsContext); | ||
return parseElementsContext(ctx, useCaseMessage); | ||
const useElementsContextWithUseCase = (useCaseMessage) => { | ||
const ctx = useContext(ElementsContext); | ||
return parseElementsContext(ctx, useCaseMessage); | ||
}; | ||
var useElements = function useElements() { | ||
var _useElementsContextWi = useElementsContextWithUseCase('calls useElements()'), | ||
elements = _useElementsContextWi.elements; | ||
return elements; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#useelements-hook | ||
*/ | ||
const useElements = () => { | ||
const { elements } = useElementsContextWithUseCase('calls useElements()'); | ||
return elements; | ||
}; | ||
var useStripe = function useStripe() { | ||
var _useElementsContextWi2 = useElementsContextWithUseCase('calls useStripe()'), | ||
stripe = _useElementsContextWi2.stripe; | ||
return stripe; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#usestripe-hook | ||
*/ | ||
const useStripe = () => { | ||
const { stripe } = useElementsContextWithUseCase('calls useStripe()'); | ||
return stripe; | ||
}; | ||
var ElementsConsumer = function ElementsConsumer(_ref2) { | ||
var children = _ref2.children; | ||
var ctx = useElementsContextWithUseCase('mounts <ElementsConsumer>'); | ||
return children(ctx); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#elements-consumer | ||
*/ | ||
const ElementsConsumer = ({ children, }) => { | ||
const ctx = useElementsContextWithUseCase('mounts <ElementsConsumer>'); | ||
// Assert to satsify the busted React.FC return type (it should be ReactNode) | ||
return children(ctx); | ||
}; | ||
ElementsConsumer.propTypes = { | ||
children: PropTypes.func.isRequired | ||
children: PropTypes.func.isRequired, | ||
}; | ||
var extractUpdateableOptions = function extractUpdateableOptions(options) { | ||
if (!options) { | ||
return {}; | ||
} | ||
var paymentRequest = options.paymentRequest, | ||
rest = _objectWithoutProperties(options, ["paymentRequest"]); | ||
return rest; | ||
const useCallbackReference = (cb) => { | ||
const ref = useRef(cb); | ||
useEffect(() => { | ||
ref.current = cb; | ||
}, [cb]); | ||
return (...args) => { | ||
if (ref.current) { | ||
ref.current(...args); | ||
} | ||
}; | ||
}; | ||
var noop = function noop() {}; | ||
var capitalized = function capitalized(str) { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
}; | ||
var useCallbackReference = function useCallbackReference(cb) { | ||
var cbStore = useRef(cb); | ||
useEffect(function () { | ||
cbStore.current = cb; | ||
}, [cb]); | ||
return function () { | ||
if (cbStore.current) { | ||
cbStore.current.apply(cbStore, arguments); | ||
const extractUpdateableOptions = (options) => { | ||
if (!isUnknownObject(options)) { | ||
return {}; | ||
} | ||
}; | ||
const { paymentRequest: _, ...rest } = options; | ||
return rest; | ||
}; | ||
var createElementComponent = function createElementComponent(type, isServer) { | ||
var displayName = "".concat(capitalized(type), "Element"); | ||
var ClientElement = function ClientElement(props) { | ||
var id = props.id, | ||
className = props.className, | ||
options = props.options, | ||
onBlur = props.onBlur, | ||
onFocus = props.onFocus, | ||
onReady = props.onReady, | ||
onChange = props.onChange, | ||
onClick = props.onClick; | ||
var _useElementsContextWi = useElementsContextWithUseCase("mounts <".concat(displayName, ">")), | ||
elements = _useElementsContextWi.elements; | ||
var elementRef = useRef(); | ||
var domNode = useRef(); | ||
var callOnReady = useCallbackReference(onReady); | ||
var callOnBlur = useCallbackReference(onBlur); | ||
var callOnFocus = useCallbackReference(onFocus); | ||
var callOnClick = useCallbackReference(onClick); | ||
var callOnChange = useCallbackReference(onChange); | ||
useLayoutEffect(function () { | ||
if (elementRef.current == null && elements && domNode.current != null) { | ||
var element = elements.create(type, options); | ||
elementRef.current = element; | ||
element.mount(domNode.current); | ||
element.on('ready', function () { | ||
return callOnReady(element); | ||
const noop = () => { }; | ||
const capitalized = (str) => str.charAt(0).toUpperCase() + str.slice(1); | ||
const createElementComponent = (type, isServer) => { | ||
const displayName = `${capitalized(type)}Element`; | ||
const ClientElement = ({ id, className, options = {}, onBlur = noop, onFocus = noop, onReady = noop, onChange = noop, onClick = noop, }) => { | ||
const { elements } = useElementsContextWithUseCase(`mounts <${displayName}>`); | ||
const elementRef = useRef(null); | ||
const domNode = useRef(null); | ||
const callOnReady = useCallbackReference(onReady); | ||
const callOnBlur = useCallbackReference(onBlur); | ||
const callOnFocus = useCallbackReference(onFocus); | ||
const callOnClick = useCallbackReference(onClick); | ||
const callOnChange = useCallbackReference(onChange); | ||
useLayoutEffect(() => { | ||
if (elementRef.current == null && elements && domNode.current != null) { | ||
const element = elements.create(type, options); | ||
elementRef.current = element; | ||
element.mount(domNode.current); | ||
element.on('ready', () => callOnReady(element)); | ||
element.on('change', callOnChange); | ||
element.on('blur', callOnBlur); | ||
element.on('focus', callOnFocus); | ||
// Users can pass an an onClick prop on any Element component | ||
// just as they could listen for the `click` event on any Element, | ||
// but only the PaymentRequestButton will actually trigger the event. | ||
element.on('click', callOnClick); | ||
} | ||
}); | ||
element.on('change', callOnChange); | ||
element.on('blur', callOnBlur); | ||
element.on('focus', callOnFocus); // Users can pass an an onClick prop on any Element component | ||
// just as they could listen for the `click` event on any Element, | ||
// but only the PaymentRequestButton will actually trigger the event. | ||
element.on('click', callOnClick); | ||
} | ||
}); | ||
var prevOptions = useRef(options); | ||
useEffect(function () { | ||
if (prevOptions.current && prevOptions.current.paymentRequest !== options.paymentRequest) { | ||
console.warn('Unsupported prop change: options.paymentRequest is not a customizable property.'); | ||
} | ||
var updateableOptions = extractUpdateableOptions(options); | ||
if (Object.keys(updateableOptions).length !== 0 && !isEqual(updateableOptions, extractUpdateableOptions(prevOptions.current))) { | ||
if (elementRef.current) { | ||
elementRef.current.update(updateableOptions); | ||
prevOptions.current = options; | ||
} | ||
} | ||
}, [options]); | ||
useEffect(function () { | ||
return function () { | ||
if (elementRef.current) { | ||
elementRef.current.destroy(); | ||
} | ||
}; | ||
}, []); | ||
return React.createElement("div", { | ||
id: id, | ||
className: className, | ||
ref: domNode | ||
}); | ||
}; // Only render the Element wrapper in a server environment. | ||
var ServerElement = function ServerElement(props) { | ||
// Validate that we are in the right context by calling useElementsContextWithUseCase. | ||
useElementsContextWithUseCase("mounts <".concat(displayName, ">")); | ||
var id = props.id, | ||
className = props.className; | ||
return React.createElement("div", { | ||
id: id, | ||
className: className | ||
}); | ||
}; | ||
var Element = isServer ? ServerElement : ClientElement; | ||
Element.propTypes = { | ||
id: PropTypes.string, | ||
className: PropTypes.string, | ||
onChange: PropTypes.func, | ||
onBlur: PropTypes.func, | ||
onFocus: PropTypes.func, | ||
onReady: PropTypes.func, | ||
onClick: PropTypes.func, | ||
options: PropTypes.object | ||
}; | ||
Element.defaultProps = { | ||
onChange: noop, | ||
onBlur: noop, | ||
onFocus: noop, | ||
onReady: noop, | ||
onClick: noop, | ||
options: {} | ||
}; | ||
Element.displayName = displayName; | ||
Element.__elementType = type; // eslint-disable-line no-underscore-dangle | ||
return Element; | ||
const prevOptions = useRef(options); | ||
useEffect(() => { | ||
if (prevOptions.current && | ||
prevOptions.current.paymentRequest !== options.paymentRequest) { | ||
console.warn('Unsupported prop change: options.paymentRequest is not a customizable property.'); | ||
} | ||
const updateableOptions = extractUpdateableOptions(options); | ||
if (Object.keys(updateableOptions).length !== 0 && | ||
!isEqual(updateableOptions, extractUpdateableOptions(prevOptions.current))) { | ||
if (elementRef.current) { | ||
elementRef.current.update(updateableOptions); | ||
prevOptions.current = options; | ||
} | ||
} | ||
}, [options]); | ||
useEffect(() => () => { | ||
if (elementRef.current) { | ||
elementRef.current.destroy(); | ||
} | ||
}, []); | ||
return React.createElement("div", { id: id, className: className, ref: domNode }); | ||
}; | ||
// Only render the Element wrapper in a server environment. | ||
const ServerElement = (props) => { | ||
// Validate that we are in the right context by calling useElementsContextWithUseCase. | ||
useElementsContextWithUseCase(`mounts <${displayName}>`); | ||
const { id, className } = props; | ||
return React.createElement("div", { id: id, className: className }); | ||
}; | ||
const Element = isServer ? ServerElement : ClientElement; | ||
Element.propTypes = { | ||
id: PropTypes.string, | ||
className: PropTypes.string, | ||
onChange: PropTypes.func, | ||
onBlur: PropTypes.func, | ||
onFocus: PropTypes.func, | ||
onReady: PropTypes.func, | ||
onClick: PropTypes.func, | ||
options: PropTypes.object, | ||
}; | ||
Element.displayName = displayName; | ||
Element.__elementType = type; | ||
return Element; | ||
}; | ||
var isServer = typeof window === 'undefined'; | ||
var CardElement = createElementComponent('card', isServer); | ||
var CardNumberElement = createElementComponent('cardNumber', isServer); | ||
var CardExpiryElement = createElementComponent('cardExpiry', isServer); | ||
var CardCvcElement = createElementComponent('cardCvc', isServer); | ||
var IbanElement = createElementComponent('iban', isServer); | ||
var IdealBankElement = createElementComponent('idealBank', isServer); | ||
var PaymentRequestButtonElement = createElementComponent('paymentRequestButton', isServer); | ||
const isServer = typeof window === 'undefined'; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardElement = createElementComponent('card', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardNumberElement = createElementComponent('cardNumber', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardExpiryElement = createElementComponent('cardExpiry', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardCvcElement = createElementComponent('cardCvc', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const IbanElement = createElementComponent('iban', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const IdealBankElement = createElementComponent('idealBank', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const PaymentRequestButtonElement = createElementComponent('paymentRequestButton', isServer); | ||
export { CardCvcElement, CardElement, CardExpiryElement, CardNumberElement, Elements, ElementsConsumer, IbanElement, IdealBankElement, PaymentRequestButtonElement, useElements, useStripe }; |
@@ -11,435 +11,309 @@ 'use strict'; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
var PLAIN_OBJECT_STR = '[object Object]'; | ||
var isEqual = function isEqual(left, right) { | ||
if (_typeof(left) !== 'object' || _typeof(right) !== 'object') { | ||
return left === right; | ||
} | ||
if (left === null || right === null) return left === right; | ||
var leftArray = Array.isArray(left); | ||
var rightArray = Array.isArray(right); | ||
if (leftArray !== rightArray) return false; | ||
var leftPlainObject = Object.prototype.toString.call(left) === PLAIN_OBJECT_STR; | ||
var rightPlainObject = Object.prototype.toString.call(right) === PLAIN_OBJECT_STR; | ||
if (leftPlainObject !== rightPlainObject) return false; | ||
if (!leftPlainObject && !leftArray) return false; | ||
var leftKeys = Object.keys(left); | ||
var rightKeys = Object.keys(right); | ||
if (leftKeys.length !== rightKeys.length) return false; | ||
var keySet = {}; | ||
for (var i = 0; i < leftKeys.length; i += 1) { | ||
keySet[leftKeys[i]] = true; | ||
} | ||
for (var _i = 0; _i < rightKeys.length; _i += 1) { | ||
keySet[rightKeys[_i]] = true; | ||
} | ||
var allKeys = Object.keys(keySet); | ||
if (allKeys.length !== leftKeys.length) { | ||
return false; | ||
} | ||
var l = left; | ||
var r = right; | ||
var pred = function pred(key) { | ||
return isEqual(l[key], r[key]); | ||
}; | ||
return allKeys.every(pred); | ||
const isUnknownObject = (raw) => { | ||
return raw !== null && typeof raw === 'object'; | ||
}; | ||
var usePrevious = function usePrevious(value) { | ||
var ref = React.useRef(value); | ||
React.useEffect(function () { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
const isPromise = (raw) => { | ||
return isUnknownObject(raw) && typeof raw.then === 'function'; | ||
}; | ||
// We are using types to enforce the `stripe` prop in this lib, | ||
// but in a real integration `stripe` could be anything, so we need | ||
// but in an untyped integration `stripe` could be anything, so we need | ||
// to do some sanity validation to prevent type errors. | ||
var validateStripe = function validateStripe(maybeStripe) { | ||
if (maybeStripe === null) { | ||
return maybeStripe; | ||
} | ||
if (_typeof(maybeStripe) === 'object' && typeof maybeStripe.elements === 'function' && typeof maybeStripe.createSource === 'function' && typeof maybeStripe.createToken === 'function' && typeof maybeStripe.createPaymentMethod === 'function') { | ||
// If the object appears to be roughly Stripe shaped, | ||
// force cast it to the expected type. | ||
return maybeStripe; | ||
} | ||
throw new Error('Invalid prop `stripe` supplied to `Elements`. Please pass a valid Stripe object or null. ' + 'You can obtain a Stripe object by calling `window.Stripe(...)` with your publishable key.'); | ||
const isStripe = (raw) => { | ||
return (isUnknownObject(raw) && | ||
typeof raw.elements === 'function' && | ||
typeof raw.createToken === 'function' && | ||
typeof raw.createPaymentMethod === 'function' && | ||
typeof raw.confirmCardPayment === 'function'); | ||
}; | ||
var parseStripeProp = function parseStripeProp(raw) { | ||
if (raw !== null && _typeof(raw) === 'object' && raw.then && typeof raw.then === 'function') { | ||
return { | ||
tag: 'async', | ||
stripePromise: Promise.resolve(raw).then(validateStripe) | ||
const PLAIN_OBJECT_STR = '[object Object]'; | ||
const isEqual = (left, right) => { | ||
if (!isUnknownObject(left) || !isUnknownObject(right)) { | ||
return left === right; | ||
} | ||
const leftArray = Array.isArray(left); | ||
const rightArray = Array.isArray(right); | ||
if (leftArray !== rightArray) | ||
return false; | ||
const leftPlainObject = Object.prototype.toString.call(left) === PLAIN_OBJECT_STR; | ||
const rightPlainObject = Object.prototype.toString.call(right) === PLAIN_OBJECT_STR; | ||
if (leftPlainObject !== rightPlainObject) | ||
return false; | ||
if (!leftPlainObject && !leftArray) | ||
return false; | ||
const leftKeys = Object.keys(left); | ||
const rightKeys = Object.keys(right); | ||
if (leftKeys.length !== rightKeys.length) | ||
return false; | ||
const keySet = {}; | ||
for (let i = 0; i < leftKeys.length; i += 1) { | ||
keySet[leftKeys[i]] = true; | ||
} | ||
for (let i = 0; i < rightKeys.length; i += 1) { | ||
keySet[rightKeys[i]] = true; | ||
} | ||
const allKeys = Object.keys(keySet); | ||
if (allKeys.length !== leftKeys.length) { | ||
return false; | ||
} | ||
const l = left; | ||
const r = right; | ||
const pred = (key) => { | ||
return isEqual(l[key], r[key]); | ||
}; | ||
} | ||
var stripe = validateStripe(raw); | ||
if (stripe === null) { | ||
return { | ||
tag: 'empty' | ||
}; | ||
} | ||
return { | ||
tag: 'sync', | ||
stripe: stripe | ||
}; | ||
return allKeys.every(pred); | ||
}; | ||
var ElementsContext = React__default.createContext(); | ||
var parseElementsContext = function parseElementsContext(ctx, useCase) { | ||
if (!ctx) { | ||
throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(useCase, " in an <Elements> provider.")); | ||
} | ||
return ctx; | ||
const usePrevious = (value) => { | ||
const ref = React.useRef(value); | ||
React.useEffect(() => { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
}; | ||
var Elements = function Elements(_ref) { | ||
var rawStripeProp = _ref.stripe, | ||
options = _ref.options, | ||
children = _ref.children; | ||
var _final = React.useRef(false); | ||
var isMounted = React.useRef(true); | ||
var parsed = React.useMemo(function () { | ||
return parseStripeProp(rawStripeProp); | ||
}, [rawStripeProp]); | ||
var _useState = React.useState(function () { | ||
return { | ||
stripe: null, | ||
elements: null | ||
}; | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
ctx = _useState2[0], | ||
setContext = _useState2[1]; | ||
var prevStripe = usePrevious(rawStripeProp); | ||
var prevOptions = usePrevious(options); | ||
if (prevStripe !== null) { | ||
if (prevStripe !== rawStripeProp) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.'); | ||
const INVALID_STRIPE_ERROR = 'Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.'; | ||
// We are using types to enforce the `stripe` prop in this lib, but in a real | ||
// integration `stripe` could be anything, so we need to do some sanity | ||
// validation to prevent type errors. | ||
const validateStripe = (maybeStripe) => { | ||
if (maybeStripe === null || isStripe(maybeStripe)) { | ||
return maybeStripe; | ||
} | ||
if (!isEqual(options, prevOptions)) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `options` prop after setting the `stripe` prop.'); | ||
throw new Error(INVALID_STRIPE_ERROR); | ||
}; | ||
const parseStripeProp = (raw) => { | ||
if (isPromise(raw)) { | ||
return { | ||
tag: 'async', | ||
stripePromise: Promise.resolve(raw).then(validateStripe), | ||
}; | ||
} | ||
} | ||
if (!_final.current) { | ||
if (parsed.tag === 'sync') { | ||
_final.current = true; | ||
setContext({ | ||
stripe: parsed.stripe, | ||
elements: parsed.stripe.elements(options) | ||
}); | ||
const stripe = validateStripe(raw); | ||
if (stripe === null) { | ||
return { tag: 'empty' }; | ||
} | ||
if (parsed.tag === 'async') { | ||
_final.current = true; | ||
parsed.stripePromise.then(function (stripe) { | ||
if (stripe && isMounted.current) { | ||
// Only update Elements context if the component is still mounted | ||
// and stripe is not null. We allow stripe to be null to make | ||
// handling SSR easier. | ||
setContext({ | ||
stripe: stripe, | ||
elements: stripe.elements(options) | ||
}); | ||
return { tag: 'sync', stripe }; | ||
}; | ||
const ElementsContext = React__default.createContext(null); | ||
ElementsContext.displayName = 'ElementsContext'; | ||
const parseElementsContext = (ctx, useCase) => { | ||
if (!ctx) { | ||
throw new Error(`Could not find Elements context; You need to wrap the part of your app that ${useCase} in an <Elements> provider.`); | ||
} | ||
return ctx; | ||
}; | ||
/** | ||
* The `Elements` provider allows you to use [Element components](https://stripe.com/docs/stripe-js/react#element-components) and access the [Stripe object](https://stripe.com/docs/js/initializing) in any nested component. | ||
* Render an `Elements` provider at the root of your React app so that it is available everywhere you need it. | ||
* | ||
* To use the `Elements` provider, call `loadStripe` from `@stripe/stripe-js` with your publishable key. | ||
* The `loadStripe` function will asynchronously load the Stripe.js script and initialize a `Stripe` object. | ||
* Pass the returned `Promise` to `Elements`. | ||
* | ||
* @docs https://stripe.com/docs/stripe-js/react#elements-provider | ||
*/ | ||
const Elements = ({ stripe: rawStripeProp, options, children, }) => { | ||
const final = React.useRef(false); | ||
const isMounted = React.useRef(true); | ||
const parsed = React.useMemo(() => parseStripeProp(rawStripeProp), [rawStripeProp]); | ||
const [ctx, setContext] = React.useState(() => ({ | ||
stripe: null, | ||
elements: null, | ||
})); | ||
const prevStripe = usePrevious(rawStripeProp); | ||
const prevOptions = usePrevious(options); | ||
if (prevStripe !== null) { | ||
if (prevStripe !== rawStripeProp) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.'); | ||
} | ||
}); | ||
if (!isEqual(options, prevOptions)) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `options` prop after setting the `stripe` prop.'); | ||
} | ||
} | ||
} | ||
React.useEffect(function () { | ||
return function () { | ||
isMounted.current = false; | ||
}; | ||
}, []); | ||
return React__default.createElement(ElementsContext.Provider, { | ||
value: ctx | ||
}, children); | ||
if (!final.current) { | ||
if (parsed.tag === 'sync') { | ||
final.current = true; | ||
setContext({ | ||
stripe: parsed.stripe, | ||
elements: parsed.stripe.elements(options), | ||
}); | ||
} | ||
if (parsed.tag === 'async') { | ||
final.current = true; | ||
parsed.stripePromise.then((stripe) => { | ||
if (stripe && isMounted.current) { | ||
// Only update Elements context if the component is still mounted | ||
// and stripe is not null. We allow stripe to be null to make | ||
// handling SSR easier. | ||
setContext({ | ||
stripe, | ||
elements: stripe.elements(options), | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
React.useEffect(() => { | ||
return () => { | ||
isMounted.current = false; | ||
}; | ||
}, []); | ||
return (React__default.createElement(ElementsContext.Provider, { value: ctx }, children)); | ||
}; | ||
Elements.propTypes = { | ||
stripe: PropTypes.any, | ||
children: PropTypes.node, | ||
options: PropTypes.object | ||
stripe: PropTypes.any, | ||
options: PropTypes.object, | ||
}; | ||
var useElementsContextWithUseCase = function useElementsContextWithUseCase(useCaseMessage) { | ||
var ctx = React.useContext(ElementsContext); | ||
return parseElementsContext(ctx, useCaseMessage); | ||
const useElementsContextWithUseCase = (useCaseMessage) => { | ||
const ctx = React.useContext(ElementsContext); | ||
return parseElementsContext(ctx, useCaseMessage); | ||
}; | ||
var useElements = function useElements() { | ||
var _useElementsContextWi = useElementsContextWithUseCase('calls useElements()'), | ||
elements = _useElementsContextWi.elements; | ||
return elements; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#useelements-hook | ||
*/ | ||
const useElements = () => { | ||
const { elements } = useElementsContextWithUseCase('calls useElements()'); | ||
return elements; | ||
}; | ||
var useStripe = function useStripe() { | ||
var _useElementsContextWi2 = useElementsContextWithUseCase('calls useStripe()'), | ||
stripe = _useElementsContextWi2.stripe; | ||
return stripe; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#usestripe-hook | ||
*/ | ||
const useStripe = () => { | ||
const { stripe } = useElementsContextWithUseCase('calls useStripe()'); | ||
return stripe; | ||
}; | ||
var ElementsConsumer = function ElementsConsumer(_ref2) { | ||
var children = _ref2.children; | ||
var ctx = useElementsContextWithUseCase('mounts <ElementsConsumer>'); | ||
return children(ctx); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#elements-consumer | ||
*/ | ||
const ElementsConsumer = ({ children, }) => { | ||
const ctx = useElementsContextWithUseCase('mounts <ElementsConsumer>'); | ||
// Assert to satsify the busted React.FC return type (it should be ReactNode) | ||
return children(ctx); | ||
}; | ||
ElementsConsumer.propTypes = { | ||
children: PropTypes.func.isRequired | ||
children: PropTypes.func.isRequired, | ||
}; | ||
var extractUpdateableOptions = function extractUpdateableOptions(options) { | ||
if (!options) { | ||
return {}; | ||
} | ||
var paymentRequest = options.paymentRequest, | ||
rest = _objectWithoutProperties(options, ["paymentRequest"]); | ||
return rest; | ||
const useCallbackReference = (cb) => { | ||
const ref = React.useRef(cb); | ||
React.useEffect(() => { | ||
ref.current = cb; | ||
}, [cb]); | ||
return (...args) => { | ||
if (ref.current) { | ||
ref.current(...args); | ||
} | ||
}; | ||
}; | ||
var noop = function noop() {}; | ||
var capitalized = function capitalized(str) { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
}; | ||
var useCallbackReference = function useCallbackReference(cb) { | ||
var cbStore = React.useRef(cb); | ||
React.useEffect(function () { | ||
cbStore.current = cb; | ||
}, [cb]); | ||
return function () { | ||
if (cbStore.current) { | ||
cbStore.current.apply(cbStore, arguments); | ||
const extractUpdateableOptions = (options) => { | ||
if (!isUnknownObject(options)) { | ||
return {}; | ||
} | ||
}; | ||
const { paymentRequest: _, ...rest } = options; | ||
return rest; | ||
}; | ||
var createElementComponent = function createElementComponent(type, isServer) { | ||
var displayName = "".concat(capitalized(type), "Element"); | ||
var ClientElement = function ClientElement(props) { | ||
var id = props.id, | ||
className = props.className, | ||
options = props.options, | ||
onBlur = props.onBlur, | ||
onFocus = props.onFocus, | ||
onReady = props.onReady, | ||
onChange = props.onChange, | ||
onClick = props.onClick; | ||
var _useElementsContextWi = useElementsContextWithUseCase("mounts <".concat(displayName, ">")), | ||
elements = _useElementsContextWi.elements; | ||
var elementRef = React.useRef(); | ||
var domNode = React.useRef(); | ||
var callOnReady = useCallbackReference(onReady); | ||
var callOnBlur = useCallbackReference(onBlur); | ||
var callOnFocus = useCallbackReference(onFocus); | ||
var callOnClick = useCallbackReference(onClick); | ||
var callOnChange = useCallbackReference(onChange); | ||
React.useLayoutEffect(function () { | ||
if (elementRef.current == null && elements && domNode.current != null) { | ||
var element = elements.create(type, options); | ||
elementRef.current = element; | ||
element.mount(domNode.current); | ||
element.on('ready', function () { | ||
return callOnReady(element); | ||
const noop = () => { }; | ||
const capitalized = (str) => str.charAt(0).toUpperCase() + str.slice(1); | ||
const createElementComponent = (type, isServer) => { | ||
const displayName = `${capitalized(type)}Element`; | ||
const ClientElement = ({ id, className, options = {}, onBlur = noop, onFocus = noop, onReady = noop, onChange = noop, onClick = noop, }) => { | ||
const { elements } = useElementsContextWithUseCase(`mounts <${displayName}>`); | ||
const elementRef = React.useRef(null); | ||
const domNode = React.useRef(null); | ||
const callOnReady = useCallbackReference(onReady); | ||
const callOnBlur = useCallbackReference(onBlur); | ||
const callOnFocus = useCallbackReference(onFocus); | ||
const callOnClick = useCallbackReference(onClick); | ||
const callOnChange = useCallbackReference(onChange); | ||
React.useLayoutEffect(() => { | ||
if (elementRef.current == null && elements && domNode.current != null) { | ||
const element = elements.create(type, options); | ||
elementRef.current = element; | ||
element.mount(domNode.current); | ||
element.on('ready', () => callOnReady(element)); | ||
element.on('change', callOnChange); | ||
element.on('blur', callOnBlur); | ||
element.on('focus', callOnFocus); | ||
// Users can pass an an onClick prop on any Element component | ||
// just as they could listen for the `click` event on any Element, | ||
// but only the PaymentRequestButton will actually trigger the event. | ||
element.on('click', callOnClick); | ||
} | ||
}); | ||
element.on('change', callOnChange); | ||
element.on('blur', callOnBlur); | ||
element.on('focus', callOnFocus); // Users can pass an an onClick prop on any Element component | ||
// just as they could listen for the `click` event on any Element, | ||
// but only the PaymentRequestButton will actually trigger the event. | ||
element.on('click', callOnClick); | ||
} | ||
}); | ||
var prevOptions = React.useRef(options); | ||
React.useEffect(function () { | ||
if (prevOptions.current && prevOptions.current.paymentRequest !== options.paymentRequest) { | ||
console.warn('Unsupported prop change: options.paymentRequest is not a customizable property.'); | ||
} | ||
var updateableOptions = extractUpdateableOptions(options); | ||
if (Object.keys(updateableOptions).length !== 0 && !isEqual(updateableOptions, extractUpdateableOptions(prevOptions.current))) { | ||
if (elementRef.current) { | ||
elementRef.current.update(updateableOptions); | ||
prevOptions.current = options; | ||
} | ||
} | ||
}, [options]); | ||
React.useEffect(function () { | ||
return function () { | ||
if (elementRef.current) { | ||
elementRef.current.destroy(); | ||
} | ||
}; | ||
}, []); | ||
return React__default.createElement("div", { | ||
id: id, | ||
className: className, | ||
ref: domNode | ||
}); | ||
}; // Only render the Element wrapper in a server environment. | ||
var ServerElement = function ServerElement(props) { | ||
// Validate that we are in the right context by calling useElementsContextWithUseCase. | ||
useElementsContextWithUseCase("mounts <".concat(displayName, ">")); | ||
var id = props.id, | ||
className = props.className; | ||
return React__default.createElement("div", { | ||
id: id, | ||
className: className | ||
}); | ||
}; | ||
var Element = isServer ? ServerElement : ClientElement; | ||
Element.propTypes = { | ||
id: PropTypes.string, | ||
className: PropTypes.string, | ||
onChange: PropTypes.func, | ||
onBlur: PropTypes.func, | ||
onFocus: PropTypes.func, | ||
onReady: PropTypes.func, | ||
onClick: PropTypes.func, | ||
options: PropTypes.object | ||
}; | ||
Element.defaultProps = { | ||
onChange: noop, | ||
onBlur: noop, | ||
onFocus: noop, | ||
onReady: noop, | ||
onClick: noop, | ||
options: {} | ||
}; | ||
Element.displayName = displayName; | ||
Element.__elementType = type; // eslint-disable-line no-underscore-dangle | ||
return Element; | ||
const prevOptions = React.useRef(options); | ||
React.useEffect(() => { | ||
if (prevOptions.current && | ||
prevOptions.current.paymentRequest !== options.paymentRequest) { | ||
console.warn('Unsupported prop change: options.paymentRequest is not a customizable property.'); | ||
} | ||
const updateableOptions = extractUpdateableOptions(options); | ||
if (Object.keys(updateableOptions).length !== 0 && | ||
!isEqual(updateableOptions, extractUpdateableOptions(prevOptions.current))) { | ||
if (elementRef.current) { | ||
elementRef.current.update(updateableOptions); | ||
prevOptions.current = options; | ||
} | ||
} | ||
}, [options]); | ||
React.useEffect(() => () => { | ||
if (elementRef.current) { | ||
elementRef.current.destroy(); | ||
} | ||
}, []); | ||
return React__default.createElement("div", { id: id, className: className, ref: domNode }); | ||
}; | ||
// Only render the Element wrapper in a server environment. | ||
const ServerElement = (props) => { | ||
// Validate that we are in the right context by calling useElementsContextWithUseCase. | ||
useElementsContextWithUseCase(`mounts <${displayName}>`); | ||
const { id, className } = props; | ||
return React__default.createElement("div", { id: id, className: className }); | ||
}; | ||
const Element = isServer ? ServerElement : ClientElement; | ||
Element.propTypes = { | ||
id: PropTypes.string, | ||
className: PropTypes.string, | ||
onChange: PropTypes.func, | ||
onBlur: PropTypes.func, | ||
onFocus: PropTypes.func, | ||
onReady: PropTypes.func, | ||
onClick: PropTypes.func, | ||
options: PropTypes.object, | ||
}; | ||
Element.displayName = displayName; | ||
Element.__elementType = type; | ||
return Element; | ||
}; | ||
var isServer = typeof window === 'undefined'; | ||
var CardElement = createElementComponent('card', isServer); | ||
var CardNumberElement = createElementComponent('cardNumber', isServer); | ||
var CardExpiryElement = createElementComponent('cardExpiry', isServer); | ||
var CardCvcElement = createElementComponent('cardCvc', isServer); | ||
var IbanElement = createElementComponent('iban', isServer); | ||
var IdealBankElement = createElementComponent('idealBank', isServer); | ||
var PaymentRequestButtonElement = createElementComponent('paymentRequestButton', isServer); | ||
const isServer = typeof window === 'undefined'; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardElement = createElementComponent('card', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardNumberElement = createElementComponent('cardNumber', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardExpiryElement = createElementComponent('cardExpiry', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardCvcElement = createElementComponent('cardCvc', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const IbanElement = createElementComponent('iban', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const IdealBankElement = createElementComponent('idealBank', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const PaymentRequestButtonElement = createElementComponent('paymentRequestButton', isServer); | ||
@@ -446,0 +320,0 @@ exports.CardCvcElement = CardCvcElement; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : | ||
(global = global || self, factory(global.ReactStripe = {}, global.React)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : | ||
(global = global || self, factory(global.ReactStripe = {}, global.React)); | ||
}(this, (function (exports, React) { 'use strict'; | ||
var React__default = 'default' in React ? React['default'] : React; | ||
var React__default = 'default' in React ? React['default'] : React; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
function unwrapExports (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
return _typeof(obj); | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
var reactIs_production_min = createCommonjsModule(function (module, exports) { | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var b = "function" === typeof Symbol && Symbol.for, | ||
c = b ? Symbol.for("react.element") : 60103, | ||
d = b ? Symbol.for("react.portal") : 60106, | ||
e = b ? Symbol.for("react.fragment") : 60107, | ||
f = b ? Symbol.for("react.strict_mode") : 60108, | ||
g = b ? Symbol.for("react.profiler") : 60114, | ||
h = b ? Symbol.for("react.provider") : 60109, | ||
k = b ? Symbol.for("react.context") : 60110, | ||
l = b ? Symbol.for("react.async_mode") : 60111, | ||
m = b ? Symbol.for("react.concurrent_mode") : 60111, | ||
n = b ? Symbol.for("react.forward_ref") : 60112, | ||
p = b ? Symbol.for("react.suspense") : 60113, | ||
q = b ? Symbol.for("react.suspense_list") : 60120, | ||
r = b ? Symbol.for("react.memo") : 60115, | ||
t = b ? Symbol.for("react.lazy") : 60116, | ||
v = b ? Symbol.for("react.fundamental") : 60117, | ||
w = b ? Symbol.for("react.responder") : 60118, | ||
x = b ? Symbol.for("react.scope") : 60119; | ||
return target; | ||
} | ||
function y(a) { | ||
if ("object" === typeof a && null !== a) { | ||
var u = a.$$typeof; | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
switch (u) { | ||
case c: | ||
switch (a = a.type, a) { | ||
case l: | ||
case m: | ||
case e: | ||
case g: | ||
case f: | ||
case p: | ||
return a; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
default: | ||
switch (a = a && a.$$typeof, a) { | ||
case k: | ||
case n: | ||
case t: | ||
case r: | ||
case h: | ||
return a; | ||
var key, i; | ||
default: | ||
return u; | ||
} | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
} | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
case d: | ||
return u; | ||
} | ||
} | ||
} | ||
return target; | ||
} | ||
function z(a) { | ||
return y(a) === m; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
} | ||
exports.typeOf = y; | ||
exports.AsyncMode = l; | ||
exports.ConcurrentMode = m; | ||
exports.ContextConsumer = k; | ||
exports.ContextProvider = h; | ||
exports.Element = c; | ||
exports.ForwardRef = n; | ||
exports.Fragment = e; | ||
exports.Lazy = t; | ||
exports.Memo = r; | ||
exports.Portal = d; | ||
exports.Profiler = g; | ||
exports.StrictMode = f; | ||
exports.Suspense = p; | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
exports.isValidElementType = function (a) { | ||
return "string" === typeof a || "function" === typeof a || a === e || a === m || a === g || a === f || a === p || a === q || "object" === typeof a && null !== a && (a.$$typeof === t || a.$$typeof === r || a.$$typeof === h || a.$$typeof === k || a.$$typeof === n || a.$$typeof === v || a.$$typeof === w || a.$$typeof === x); | ||
}; | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
exports.isAsyncMode = function (a) { | ||
return z(a) || y(a) === l; | ||
}; | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
exports.isConcurrentMode = z; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
exports.isContextConsumer = function (a) { | ||
return y(a) === k; | ||
}; | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
exports.isContextProvider = function (a) { | ||
return y(a) === h; | ||
}; | ||
return _arr; | ||
} | ||
exports.isElement = function (a) { | ||
return "object" === typeof a && null !== a && a.$$typeof === c; | ||
}; | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
exports.isForwardRef = function (a) { | ||
return y(a) === n; | ||
}; | ||
function unwrapExports (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
exports.isFragment = function (a) { | ||
return y(a) === e; | ||
}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
exports.isLazy = function (a) { | ||
return y(a) === t; | ||
}; | ||
var reactIs_production_min = createCommonjsModule(function (module, exports) { | ||
Object.defineProperty(exports,"__esModule",{value:!0}); | ||
var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?Symbol.for("react.suspense_list"): | ||
60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.fundamental"):60117,w=b?Symbol.for("react.responder"):60118,x=b?Symbol.for("react.scope"):60119;function y(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case h:return a;default:return u}}case t:case r:case d:return u}}}function z(a){return y(a)===m} | ||
exports.typeOf=y;exports.AsyncMode=l;exports.ConcurrentMode=m;exports.ContextConsumer=k;exports.ContextProvider=h;exports.Element=c;exports.ForwardRef=n;exports.Fragment=e;exports.Lazy=t;exports.Memo=r;exports.Portal=d;exports.Profiler=g;exports.StrictMode=f;exports.Suspense=p; | ||
exports.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n||a.$$typeof===v||a.$$typeof===w||a.$$typeof===x)};exports.isAsyncMode=function(a){return z(a)||y(a)===l};exports.isConcurrentMode=z;exports.isContextConsumer=function(a){return y(a)===k};exports.isContextProvider=function(a){return y(a)===h}; | ||
exports.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};exports.isForwardRef=function(a){return y(a)===n};exports.isFragment=function(a){return y(a)===e};exports.isLazy=function(a){return y(a)===t};exports.isMemo=function(a){return y(a)===r};exports.isPortal=function(a){return y(a)===d};exports.isProfiler=function(a){return y(a)===g};exports.isStrictMode=function(a){return y(a)===f};exports.isSuspense=function(a){return y(a)===p}; | ||
}); | ||
exports.isMemo = function (a) { | ||
return y(a) === r; | ||
}; | ||
unwrapExports(reactIs_production_min); | ||
var reactIs_production_min_1 = reactIs_production_min.typeOf; | ||
var reactIs_production_min_2 = reactIs_production_min.AsyncMode; | ||
var reactIs_production_min_3 = reactIs_production_min.ConcurrentMode; | ||
var reactIs_production_min_4 = reactIs_production_min.ContextConsumer; | ||
var reactIs_production_min_5 = reactIs_production_min.ContextProvider; | ||
var reactIs_production_min_6 = reactIs_production_min.Element; | ||
var reactIs_production_min_7 = reactIs_production_min.ForwardRef; | ||
var reactIs_production_min_8 = reactIs_production_min.Fragment; | ||
var reactIs_production_min_9 = reactIs_production_min.Lazy; | ||
var reactIs_production_min_10 = reactIs_production_min.Memo; | ||
var reactIs_production_min_11 = reactIs_production_min.Portal; | ||
var reactIs_production_min_12 = reactIs_production_min.Profiler; | ||
var reactIs_production_min_13 = reactIs_production_min.StrictMode; | ||
var reactIs_production_min_14 = reactIs_production_min.Suspense; | ||
var reactIs_production_min_15 = reactIs_production_min.isValidElementType; | ||
var reactIs_production_min_16 = reactIs_production_min.isAsyncMode; | ||
var reactIs_production_min_17 = reactIs_production_min.isConcurrentMode; | ||
var reactIs_production_min_18 = reactIs_production_min.isContextConsumer; | ||
var reactIs_production_min_19 = reactIs_production_min.isContextProvider; | ||
var reactIs_production_min_20 = reactIs_production_min.isElement; | ||
var reactIs_production_min_21 = reactIs_production_min.isForwardRef; | ||
var reactIs_production_min_22 = reactIs_production_min.isFragment; | ||
var reactIs_production_min_23 = reactIs_production_min.isLazy; | ||
var reactIs_production_min_24 = reactIs_production_min.isMemo; | ||
var reactIs_production_min_25 = reactIs_production_min.isPortal; | ||
var reactIs_production_min_26 = reactIs_production_min.isProfiler; | ||
var reactIs_production_min_27 = reactIs_production_min.isStrictMode; | ||
var reactIs_production_min_28 = reactIs_production_min.isSuspense; | ||
exports.isPortal = function (a) { | ||
return y(a) === d; | ||
}; | ||
var reactIs_development = createCommonjsModule(function (module, exports) { | ||
exports.isProfiler = function (a) { | ||
return y(a) === g; | ||
}; | ||
exports.isStrictMode = function (a) { | ||
return y(a) === f; | ||
}; | ||
exports.isSuspense = function (a) { | ||
return y(a) === p; | ||
}; | ||
}); | ||
if (process.env.NODE_ENV !== "production") { | ||
(function() { | ||
unwrapExports(reactIs_production_min); | ||
var reactIs_production_min_1 = reactIs_production_min.typeOf; | ||
var reactIs_production_min_2 = reactIs_production_min.AsyncMode; | ||
var reactIs_production_min_3 = reactIs_production_min.ConcurrentMode; | ||
var reactIs_production_min_4 = reactIs_production_min.ContextConsumer; | ||
var reactIs_production_min_5 = reactIs_production_min.ContextProvider; | ||
var reactIs_production_min_6 = reactIs_production_min.Element; | ||
var reactIs_production_min_7 = reactIs_production_min.ForwardRef; | ||
var reactIs_production_min_8 = reactIs_production_min.Fragment; | ||
var reactIs_production_min_9 = reactIs_production_min.Lazy; | ||
var reactIs_production_min_10 = reactIs_production_min.Memo; | ||
var reactIs_production_min_11 = reactIs_production_min.Portal; | ||
var reactIs_production_min_12 = reactIs_production_min.Profiler; | ||
var reactIs_production_min_13 = reactIs_production_min.StrictMode; | ||
var reactIs_production_min_14 = reactIs_production_min.Suspense; | ||
var reactIs_production_min_15 = reactIs_production_min.isValidElementType; | ||
var reactIs_production_min_16 = reactIs_production_min.isAsyncMode; | ||
var reactIs_production_min_17 = reactIs_production_min.isConcurrentMode; | ||
var reactIs_production_min_18 = reactIs_production_min.isContextConsumer; | ||
var reactIs_production_min_19 = reactIs_production_min.isContextProvider; | ||
var reactIs_production_min_20 = reactIs_production_min.isElement; | ||
var reactIs_production_min_21 = reactIs_production_min.isForwardRef; | ||
var reactIs_production_min_22 = reactIs_production_min.isFragment; | ||
var reactIs_production_min_23 = reactIs_production_min.isLazy; | ||
var reactIs_production_min_24 = reactIs_production_min.isMemo; | ||
var reactIs_production_min_25 = reactIs_production_min.isPortal; | ||
var reactIs_production_min_26 = reactIs_production_min.isProfiler; | ||
var reactIs_production_min_27 = reactIs_production_min.isStrictMode; | ||
var reactIs_production_min_28 = reactIs_production_min.isSuspense; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var reactIs_development = createCommonjsModule(function (module, exports) { | ||
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol | ||
// nor polyfill, then a plain number is used for performance. | ||
var hasSymbol = typeof Symbol === 'function' && Symbol.for; | ||
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7; | ||
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca; | ||
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb; | ||
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc; | ||
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2; | ||
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd; | ||
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary | ||
// (unstable) APIs that have been removed. Can we remove the symbols? | ||
if (process.env.NODE_ENV !== "production") { | ||
(function () { | ||
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf; | ||
var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf; | ||
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; | ||
var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1; | ||
var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8; | ||
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; | ||
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4; | ||
var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5; | ||
var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6; | ||
var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); // The Symbol used to tag the ReactElement-like types. If there is no native Symbol | ||
// nor polyfill, then a plain number is used for performance. | ||
function isValidElementType(type) { | ||
return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill. | ||
type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE); | ||
} | ||
var hasSymbol = typeof Symbol === 'function' && Symbol.for; | ||
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7; | ||
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca; | ||
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb; | ||
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc; | ||
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2; | ||
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd; | ||
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary | ||
// (unstable) APIs that have been removed. Can we remove the symbols? | ||
/** | ||
* Forked from fbjs/warning: | ||
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js | ||
* | ||
* Only change is we use console.warn instead of console.error, | ||
* and do nothing when 'console' is not supported. | ||
* This really simplifies the code. | ||
* --- | ||
* Similar to invariant but only logs a warning if the condition is not met. | ||
* This can be used to log issues in development environments in critical | ||
* paths. Removing the logging code for production environments will keep the | ||
* same logic and follow the same code paths. | ||
*/ | ||
var lowPriorityWarningWithoutStack = function () {}; | ||
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf; | ||
var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf; | ||
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; | ||
var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1; | ||
var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8; | ||
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; | ||
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4; | ||
var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5; | ||
var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6; | ||
var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7; | ||
{ | ||
var printWarning = function (format) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
function isValidElementType(type) { | ||
return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill. | ||
type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE); | ||
} | ||
/** | ||
* Forked from fbjs/warning: | ||
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js | ||
* | ||
* Only change is we use console.warn instead of console.error, | ||
* and do nothing when 'console' is not supported. | ||
* This really simplifies the code. | ||
* --- | ||
* Similar to invariant but only logs a warning if the condition is not met. | ||
* This can be used to log issues in development environments in critical | ||
* paths. Removing the logging code for production environments will keep the | ||
* same logic and follow the same code paths. | ||
*/ | ||
var argIndex = 0; | ||
var message = 'Warning: ' + format.replace(/%s/g, function () { | ||
return args[argIndex++]; | ||
}); | ||
if (typeof console !== 'undefined') { | ||
console.warn(message); | ||
} | ||
var lowPriorityWarningWithoutStack = function () {}; | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
{ | ||
var printWarning = function (format) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
lowPriorityWarningWithoutStack = function (condition, format) { | ||
if (format === undefined) { | ||
throw new Error('`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument'); | ||
} | ||
var argIndex = 0; | ||
var message = 'Warning: ' + format.replace(/%s/g, function () { | ||
return args[argIndex++]; | ||
}); | ||
if (!condition) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
args[_key2 - 2] = arguments[_key2]; | ||
} | ||
if (typeof console !== 'undefined') { | ||
console.warn(message); | ||
} | ||
printWarning.apply(void 0, [format].concat(args)); | ||
} | ||
}; | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
var lowPriorityWarningWithoutStack$1 = lowPriorityWarningWithoutStack; | ||
lowPriorityWarningWithoutStack = function (condition, format) { | ||
if (format === undefined) { | ||
throw new Error('`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument'); | ||
} | ||
function typeOf(object) { | ||
if (typeof object === 'object' && object !== null) { | ||
var $$typeof = object.$$typeof; | ||
if (!condition) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
args[_key2 - 2] = arguments[_key2]; | ||
} | ||
switch ($$typeof) { | ||
case REACT_ELEMENT_TYPE: | ||
var type = object.type; | ||
printWarning.apply(void 0, [format].concat(args)); | ||
} | ||
}; | ||
} | ||
var lowPriorityWarningWithoutStack$1 = lowPriorityWarningWithoutStack; | ||
switch (type) { | ||
case REACT_ASYNC_MODE_TYPE: | ||
case REACT_CONCURRENT_MODE_TYPE: | ||
case REACT_FRAGMENT_TYPE: | ||
case REACT_PROFILER_TYPE: | ||
case REACT_STRICT_MODE_TYPE: | ||
case REACT_SUSPENSE_TYPE: | ||
return type; | ||
function typeOf(object) { | ||
if (typeof object === 'object' && object !== null) { | ||
var $$typeof = object.$$typeof; | ||
default: | ||
var $$typeofType = type && type.$$typeof; | ||
switch ($$typeof) { | ||
case REACT_ELEMENT_TYPE: | ||
var type = object.type; | ||
switch ($$typeofType) { | ||
case REACT_CONTEXT_TYPE: | ||
case REACT_FORWARD_REF_TYPE: | ||
case REACT_PROVIDER_TYPE: | ||
return $$typeofType; | ||
switch (type) { | ||
case REACT_ASYNC_MODE_TYPE: | ||
case REACT_CONCURRENT_MODE_TYPE: | ||
case REACT_FRAGMENT_TYPE: | ||
case REACT_PROFILER_TYPE: | ||
case REACT_STRICT_MODE_TYPE: | ||
case REACT_SUSPENSE_TYPE: | ||
return type; | ||
default: | ||
return $$typeof; | ||
} | ||
default: | ||
var $$typeofType = type && type.$$typeof; | ||
} | ||
switch ($$typeofType) { | ||
case REACT_CONTEXT_TYPE: | ||
case REACT_FORWARD_REF_TYPE: | ||
case REACT_LAZY_TYPE: | ||
case REACT_MEMO_TYPE: | ||
case REACT_PROVIDER_TYPE: | ||
return $$typeofType; | ||
case REACT_LAZY_TYPE: | ||
case REACT_MEMO_TYPE: | ||
case REACT_PORTAL_TYPE: | ||
return $$typeof; | ||
} | ||
} | ||
default: | ||
return $$typeof; | ||
} | ||
return undefined; | ||
} // AsyncMode is deprecated along with isAsyncMode | ||
} | ||
var AsyncMode = REACT_ASYNC_MODE_TYPE; | ||
var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE; | ||
var ContextConsumer = REACT_CONTEXT_TYPE; | ||
var ContextProvider = REACT_PROVIDER_TYPE; | ||
var Element = REACT_ELEMENT_TYPE; | ||
var ForwardRef = REACT_FORWARD_REF_TYPE; | ||
var Fragment = REACT_FRAGMENT_TYPE; | ||
var Lazy = REACT_LAZY_TYPE; | ||
var Memo = REACT_MEMO_TYPE; | ||
var Portal = REACT_PORTAL_TYPE; | ||
var Profiler = REACT_PROFILER_TYPE; | ||
var StrictMode = REACT_STRICT_MODE_TYPE; | ||
var Suspense = REACT_SUSPENSE_TYPE; | ||
var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated | ||
case REACT_PORTAL_TYPE: | ||
return $$typeof; | ||
} | ||
} | ||
function isAsyncMode(object) { | ||
{ | ||
if (!hasWarnedAboutDeprecatedIsAsyncMode) { | ||
hasWarnedAboutDeprecatedIsAsyncMode = true; | ||
lowPriorityWarningWithoutStack$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.'); | ||
} | ||
} | ||
return undefined; | ||
} // AsyncMode is deprecated along with isAsyncMode | ||
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE; | ||
} | ||
function isConcurrentMode(object) { | ||
return typeOf(object) === REACT_CONCURRENT_MODE_TYPE; | ||
} | ||
function isContextConsumer(object) { | ||
return typeOf(object) === REACT_CONTEXT_TYPE; | ||
} | ||
function isContextProvider(object) { | ||
return typeOf(object) === REACT_PROVIDER_TYPE; | ||
} | ||
function isElement(object) { | ||
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; | ||
} | ||
function isForwardRef(object) { | ||
return typeOf(object) === REACT_FORWARD_REF_TYPE; | ||
} | ||
function isFragment(object) { | ||
return typeOf(object) === REACT_FRAGMENT_TYPE; | ||
} | ||
function isLazy(object) { | ||
return typeOf(object) === REACT_LAZY_TYPE; | ||
} | ||
function isMemo(object) { | ||
return typeOf(object) === REACT_MEMO_TYPE; | ||
} | ||
function isPortal(object) { | ||
return typeOf(object) === REACT_PORTAL_TYPE; | ||
} | ||
function isProfiler(object) { | ||
return typeOf(object) === REACT_PROFILER_TYPE; | ||
} | ||
function isStrictMode(object) { | ||
return typeOf(object) === REACT_STRICT_MODE_TYPE; | ||
} | ||
function isSuspense(object) { | ||
return typeOf(object) === REACT_SUSPENSE_TYPE; | ||
} | ||
exports.typeOf = typeOf; | ||
exports.AsyncMode = AsyncMode; | ||
exports.ConcurrentMode = ConcurrentMode; | ||
exports.ContextConsumer = ContextConsumer; | ||
exports.ContextProvider = ContextProvider; | ||
exports.Element = Element; | ||
exports.ForwardRef = ForwardRef; | ||
exports.Fragment = Fragment; | ||
exports.Lazy = Lazy; | ||
exports.Memo = Memo; | ||
exports.Portal = Portal; | ||
exports.Profiler = Profiler; | ||
exports.StrictMode = StrictMode; | ||
exports.Suspense = Suspense; | ||
exports.isValidElementType = isValidElementType; | ||
exports.isAsyncMode = isAsyncMode; | ||
exports.isConcurrentMode = isConcurrentMode; | ||
exports.isContextConsumer = isContextConsumer; | ||
exports.isContextProvider = isContextProvider; | ||
exports.isElement = isElement; | ||
exports.isForwardRef = isForwardRef; | ||
exports.isFragment = isFragment; | ||
exports.isLazy = isLazy; | ||
exports.isMemo = isMemo; | ||
exports.isPortal = isPortal; | ||
exports.isProfiler = isProfiler; | ||
exports.isStrictMode = isStrictMode; | ||
exports.isSuspense = isSuspense; | ||
})(); | ||
} | ||
}); | ||
var AsyncMode = REACT_ASYNC_MODE_TYPE; | ||
var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE; | ||
var ContextConsumer = REACT_CONTEXT_TYPE; | ||
var ContextProvider = REACT_PROVIDER_TYPE; | ||
var Element = REACT_ELEMENT_TYPE; | ||
var ForwardRef = REACT_FORWARD_REF_TYPE; | ||
var Fragment = REACT_FRAGMENT_TYPE; | ||
var Lazy = REACT_LAZY_TYPE; | ||
var Memo = REACT_MEMO_TYPE; | ||
var Portal = REACT_PORTAL_TYPE; | ||
var Profiler = REACT_PROFILER_TYPE; | ||
var StrictMode = REACT_STRICT_MODE_TYPE; | ||
var Suspense = REACT_SUSPENSE_TYPE; | ||
var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated | ||
unwrapExports(reactIs_development); | ||
var reactIs_development_1 = reactIs_development.typeOf; | ||
var reactIs_development_2 = reactIs_development.AsyncMode; | ||
var reactIs_development_3 = reactIs_development.ConcurrentMode; | ||
var reactIs_development_4 = reactIs_development.ContextConsumer; | ||
var reactIs_development_5 = reactIs_development.ContextProvider; | ||
var reactIs_development_6 = reactIs_development.Element; | ||
var reactIs_development_7 = reactIs_development.ForwardRef; | ||
var reactIs_development_8 = reactIs_development.Fragment; | ||
var reactIs_development_9 = reactIs_development.Lazy; | ||
var reactIs_development_10 = reactIs_development.Memo; | ||
var reactIs_development_11 = reactIs_development.Portal; | ||
var reactIs_development_12 = reactIs_development.Profiler; | ||
var reactIs_development_13 = reactIs_development.StrictMode; | ||
var reactIs_development_14 = reactIs_development.Suspense; | ||
var reactIs_development_15 = reactIs_development.isValidElementType; | ||
var reactIs_development_16 = reactIs_development.isAsyncMode; | ||
var reactIs_development_17 = reactIs_development.isConcurrentMode; | ||
var reactIs_development_18 = reactIs_development.isContextConsumer; | ||
var reactIs_development_19 = reactIs_development.isContextProvider; | ||
var reactIs_development_20 = reactIs_development.isElement; | ||
var reactIs_development_21 = reactIs_development.isForwardRef; | ||
var reactIs_development_22 = reactIs_development.isFragment; | ||
var reactIs_development_23 = reactIs_development.isLazy; | ||
var reactIs_development_24 = reactIs_development.isMemo; | ||
var reactIs_development_25 = reactIs_development.isPortal; | ||
var reactIs_development_26 = reactIs_development.isProfiler; | ||
var reactIs_development_27 = reactIs_development.isStrictMode; | ||
var reactIs_development_28 = reactIs_development.isSuspense; | ||
function isAsyncMode(object) { | ||
{ | ||
if (!hasWarnedAboutDeprecatedIsAsyncMode) { | ||
hasWarnedAboutDeprecatedIsAsyncMode = true; | ||
lowPriorityWarningWithoutStack$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.'); | ||
} | ||
} | ||
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE; | ||
} | ||
var reactIs = createCommonjsModule(function (module) { | ||
function isConcurrentMode(object) { | ||
return typeOf(object) === REACT_CONCURRENT_MODE_TYPE; | ||
} | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = reactIs_production_min; | ||
} else { | ||
module.exports = reactIs_development; | ||
} | ||
}); | ||
function isContextConsumer(object) { | ||
return typeOf(object) === REACT_CONTEXT_TYPE; | ||
} | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
var getOwnPropertySymbols = Object.getOwnPropertySymbols; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var propIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
function isContextProvider(object) { | ||
return typeOf(object) === REACT_PROVIDER_TYPE; | ||
} | ||
function toObject(val) { | ||
if (val === null || val === undefined) { | ||
throw new TypeError('Object.assign cannot be called with null or undefined'); | ||
} | ||
function isElement(object) { | ||
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; | ||
} | ||
return Object(val); | ||
} | ||
function isForwardRef(object) { | ||
return typeOf(object) === REACT_FORWARD_REF_TYPE; | ||
} | ||
function shouldUseNative() { | ||
try { | ||
if (!Object.assign) { | ||
return false; | ||
} | ||
function isFragment(object) { | ||
return typeOf(object) === REACT_FRAGMENT_TYPE; | ||
} | ||
// Detect buggy property enumeration order in older V8 versions. | ||
function isLazy(object) { | ||
return typeOf(object) === REACT_LAZY_TYPE; | ||
} | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=4118 | ||
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers | ||
test1[5] = 'de'; | ||
if (Object.getOwnPropertyNames(test1)[0] === '5') { | ||
return false; | ||
} | ||
function isMemo(object) { | ||
return typeOf(object) === REACT_MEMO_TYPE; | ||
} | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test2 = {}; | ||
for (var i = 0; i < 10; i++) { | ||
test2['_' + String.fromCharCode(i)] = i; | ||
} | ||
var order2 = Object.getOwnPropertyNames(test2).map(function (n) { | ||
return test2[n]; | ||
}); | ||
if (order2.join('') !== '0123456789') { | ||
return false; | ||
} | ||
function isPortal(object) { | ||
return typeOf(object) === REACT_PORTAL_TYPE; | ||
} | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test3 = {}; | ||
'abcdefghijklmnopqrst'.split('').forEach(function (letter) { | ||
test3[letter] = letter; | ||
}); | ||
if (Object.keys(Object.assign({}, test3)).join('') !== | ||
'abcdefghijklmnopqrst') { | ||
return false; | ||
} | ||
function isProfiler(object) { | ||
return typeOf(object) === REACT_PROFILER_TYPE; | ||
} | ||
return true; | ||
} catch (err) { | ||
// We don't expect any of the above to throw, but better to be safe. | ||
return false; | ||
} | ||
} | ||
function isStrictMode(object) { | ||
return typeOf(object) === REACT_STRICT_MODE_TYPE; | ||
} | ||
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { | ||
var from; | ||
var to = toObject(target); | ||
var symbols; | ||
function isSuspense(object) { | ||
return typeOf(object) === REACT_SUSPENSE_TYPE; | ||
} | ||
for (var s = 1; s < arguments.length; s++) { | ||
from = Object(arguments[s]); | ||
exports.typeOf = typeOf; | ||
exports.AsyncMode = AsyncMode; | ||
exports.ConcurrentMode = ConcurrentMode; | ||
exports.ContextConsumer = ContextConsumer; | ||
exports.ContextProvider = ContextProvider; | ||
exports.Element = Element; | ||
exports.ForwardRef = ForwardRef; | ||
exports.Fragment = Fragment; | ||
exports.Lazy = Lazy; | ||
exports.Memo = Memo; | ||
exports.Portal = Portal; | ||
exports.Profiler = Profiler; | ||
exports.StrictMode = StrictMode; | ||
exports.Suspense = Suspense; | ||
exports.isValidElementType = isValidElementType; | ||
exports.isAsyncMode = isAsyncMode; | ||
exports.isConcurrentMode = isConcurrentMode; | ||
exports.isContextConsumer = isContextConsumer; | ||
exports.isContextProvider = isContextProvider; | ||
exports.isElement = isElement; | ||
exports.isForwardRef = isForwardRef; | ||
exports.isFragment = isFragment; | ||
exports.isLazy = isLazy; | ||
exports.isMemo = isMemo; | ||
exports.isPortal = isPortal; | ||
exports.isProfiler = isProfiler; | ||
exports.isStrictMode = isStrictMode; | ||
exports.isSuspense = isSuspense; | ||
})(); | ||
} | ||
}); | ||
for (var key in from) { | ||
if (hasOwnProperty.call(from, key)) { | ||
to[key] = from[key]; | ||
} | ||
} | ||
unwrapExports(reactIs_development); | ||
var reactIs_development_1 = reactIs_development.typeOf; | ||
var reactIs_development_2 = reactIs_development.AsyncMode; | ||
var reactIs_development_3 = reactIs_development.ConcurrentMode; | ||
var reactIs_development_4 = reactIs_development.ContextConsumer; | ||
var reactIs_development_5 = reactIs_development.ContextProvider; | ||
var reactIs_development_6 = reactIs_development.Element; | ||
var reactIs_development_7 = reactIs_development.ForwardRef; | ||
var reactIs_development_8 = reactIs_development.Fragment; | ||
var reactIs_development_9 = reactIs_development.Lazy; | ||
var reactIs_development_10 = reactIs_development.Memo; | ||
var reactIs_development_11 = reactIs_development.Portal; | ||
var reactIs_development_12 = reactIs_development.Profiler; | ||
var reactIs_development_13 = reactIs_development.StrictMode; | ||
var reactIs_development_14 = reactIs_development.Suspense; | ||
var reactIs_development_15 = reactIs_development.isValidElementType; | ||
var reactIs_development_16 = reactIs_development.isAsyncMode; | ||
var reactIs_development_17 = reactIs_development.isConcurrentMode; | ||
var reactIs_development_18 = reactIs_development.isContextConsumer; | ||
var reactIs_development_19 = reactIs_development.isContextProvider; | ||
var reactIs_development_20 = reactIs_development.isElement; | ||
var reactIs_development_21 = reactIs_development.isForwardRef; | ||
var reactIs_development_22 = reactIs_development.isFragment; | ||
var reactIs_development_23 = reactIs_development.isLazy; | ||
var reactIs_development_24 = reactIs_development.isMemo; | ||
var reactIs_development_25 = reactIs_development.isPortal; | ||
var reactIs_development_26 = reactIs_development.isProfiler; | ||
var reactIs_development_27 = reactIs_development.isStrictMode; | ||
var reactIs_development_28 = reactIs_development.isSuspense; | ||
if (getOwnPropertySymbols) { | ||
symbols = getOwnPropertySymbols(from); | ||
for (var i = 0; i < symbols.length; i++) { | ||
if (propIsEnumerable.call(from, symbols[i])) { | ||
to[symbols[i]] = from[symbols[i]]; | ||
} | ||
} | ||
} | ||
} | ||
var reactIs = createCommonjsModule(function (module) { | ||
return to; | ||
}; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = reactIs_production_min; | ||
} else { | ||
module.exports = reactIs_development; | ||
} | ||
}); | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; | ||
var getOwnPropertySymbols = Object.getOwnPropertySymbols; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var propIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
var ReactPropTypesSecret_1 = ReactPropTypesSecret; | ||
function toObject(val) { | ||
if (val === null || val === undefined) { | ||
throw new TypeError('Object.assign cannot be called with null or undefined'); | ||
} | ||
var printWarning = function() {}; | ||
return Object(val); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1; | ||
var loggedTypeFailures = {}; | ||
var has = Function.call.bind(Object.prototype.hasOwnProperty); | ||
function shouldUseNative() { | ||
try { | ||
if (!Object.assign) { | ||
return false; | ||
} // Detect buggy property enumeration order in older V8 versions. | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=4118 | ||
printWarning = function(text) { | ||
var message = 'Warning: ' + text; | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
} | ||
/** | ||
* Assert that the values match with the type specs. | ||
* Error messages are memorized and will only be shown once. | ||
* | ||
* @param {object} typeSpecs Map of name to a ReactPropType | ||
* @param {object} values Runtime values that need to be type-checked | ||
* @param {string} location e.g. "prop", "context", "child context" | ||
* @param {string} componentName Name of the component for error messages. | ||
* @param {?Function} getStack Returns the component stack. | ||
* @private | ||
*/ | ||
function checkPropTypes(typeSpecs, values, location, componentName, getStack) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
for (var typeSpecName in typeSpecs) { | ||
if (has(typeSpecs, typeSpecName)) { | ||
var error; | ||
// Prop type validation may throw. In case they do, we don't want to | ||
// fail the render phase where it didn't fail before. So we log it. | ||
// After these have been cleaned up, we'll let them throw. | ||
try { | ||
// This is intentionally an invariant that gets caught. It's the same | ||
// behavior as without this statement except with a better message. | ||
if (typeof typeSpecs[typeSpecName] !== 'function') { | ||
var err = Error( | ||
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + | ||
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' | ||
); | ||
err.name = 'Invariant Violation'; | ||
throw err; | ||
} | ||
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
if (error && !(error instanceof Error)) { | ||
printWarning( | ||
(componentName || 'React class') + ': type specification of ' + | ||
location + ' `' + typeSpecName + '` is invalid; the type checker ' + | ||
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' + | ||
'You may have forgotten to pass an argument to the type checker ' + | ||
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + | ||
'shape all require an argument).' | ||
); | ||
} | ||
if (error instanceof Error && !(error.message in loggedTypeFailures)) { | ||
// Only monitor this failure once because there tends to be a lot of the | ||
// same error. | ||
loggedTypeFailures[error.message] = true; | ||
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers | ||
var stack = getStack ? getStack() : ''; | ||
test1[5] = 'de'; | ||
printWarning( | ||
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '') | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (Object.getOwnPropertyNames(test1)[0] === '5') { | ||
return false; | ||
} // https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
/** | ||
* Resets warning cache when testing. | ||
* | ||
* @private | ||
*/ | ||
checkPropTypes.resetWarningCache = function() { | ||
if (process.env.NODE_ENV !== 'production') { | ||
loggedTypeFailures = {}; | ||
} | ||
}; | ||
var checkPropTypes_1 = checkPropTypes; | ||
var test2 = {}; | ||
var has$1 = Function.call.bind(Object.prototype.hasOwnProperty); | ||
var printWarning$1 = function() {}; | ||
for (var i = 0; i < 10; i++) { | ||
test2['_' + String.fromCharCode(i)] = i; | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
printWarning$1 = function(text) { | ||
var message = 'Warning: ' + text; | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
} | ||
var order2 = Object.getOwnPropertyNames(test2).map(function (n) { | ||
return test2[n]; | ||
}); | ||
function emptyFunctionThatReturnsNull() { | ||
return null; | ||
} | ||
if (order2.join('') !== '0123456789') { | ||
return false; | ||
} // https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) { | ||
/* global Symbol */ | ||
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; | ||
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. | ||
/** | ||
* Returns the iterator method function contained on the iterable object. | ||
* | ||
* Be sure to invoke the function with the iterable as context: | ||
* | ||
* var iteratorFn = getIteratorFn(myIterable); | ||
* if (iteratorFn) { | ||
* var iterator = iteratorFn.call(myIterable); | ||
* ... | ||
* } | ||
* | ||
* @param {?object} maybeIterable | ||
* @return {?function} | ||
*/ | ||
function getIteratorFn(maybeIterable) { | ||
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); | ||
if (typeof iteratorFn === 'function') { | ||
return iteratorFn; | ||
} | ||
} | ||
var test3 = {}; | ||
'abcdefghijklmnopqrst'.split('').forEach(function (letter) { | ||
test3[letter] = letter; | ||
}); | ||
/** | ||
* Collection of methods that allow declaration and validation of props that are | ||
* supplied to React components. Example usage: | ||
* | ||
* var Props = require('ReactPropTypes'); | ||
* var MyArticle = React.createClass({ | ||
* propTypes: { | ||
* // An optional string prop named "description". | ||
* description: Props.string, | ||
* | ||
* // A required enum prop named "category". | ||
* category: Props.oneOf(['News','Photos']).isRequired, | ||
* | ||
* // A prop named "dialog" that requires an instance of Dialog. | ||
* dialog: Props.instanceOf(Dialog).isRequired | ||
* }, | ||
* render: function() { ... } | ||
* }); | ||
* | ||
* A more formal specification of how these methods are used: | ||
* | ||
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) | ||
* decl := ReactPropTypes.{type}(.isRequired)? | ||
* | ||
* Each and every declaration produces a function with the same signature. This | ||
* allows the creation of custom validation functions. For example: | ||
* | ||
* var MyLink = React.createClass({ | ||
* propTypes: { | ||
* // An optional string or URI prop named "href". | ||
* href: function(props, propName, componentName) { | ||
* var propValue = props[propName]; | ||
* if (propValue != null && typeof propValue !== 'string' && | ||
* !(propValue instanceof URI)) { | ||
* return new Error( | ||
* 'Expected a string or an URI for ' + propName + ' in ' + | ||
* componentName | ||
* ); | ||
* } | ||
* } | ||
* }, | ||
* render: function() {...} | ||
* }); | ||
* | ||
* @internal | ||
*/ | ||
if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') { | ||
return false; | ||
} | ||
var ANONYMOUS = '<<anonymous>>'; | ||
return true; | ||
} catch (err) { | ||
// We don't expect any of the above to throw, but better to be safe. | ||
return false; | ||
} | ||
} | ||
// Important! | ||
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`. | ||
var ReactPropTypes = { | ||
array: createPrimitiveTypeChecker('array'), | ||
bool: createPrimitiveTypeChecker('boolean'), | ||
func: createPrimitiveTypeChecker('function'), | ||
number: createPrimitiveTypeChecker('number'), | ||
object: createPrimitiveTypeChecker('object'), | ||
string: createPrimitiveTypeChecker('string'), | ||
symbol: createPrimitiveTypeChecker('symbol'), | ||
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { | ||
var from; | ||
var to = toObject(target); | ||
var symbols; | ||
any: createAnyTypeChecker(), | ||
arrayOf: createArrayOfTypeChecker, | ||
element: createElementTypeChecker(), | ||
elementType: createElementTypeTypeChecker(), | ||
instanceOf: createInstanceTypeChecker, | ||
node: createNodeChecker(), | ||
objectOf: createObjectOfTypeChecker, | ||
oneOf: createEnumTypeChecker, | ||
oneOfType: createUnionTypeChecker, | ||
shape: createShapeTypeChecker, | ||
exact: createStrictShapeTypeChecker, | ||
}; | ||
for (var s = 1; s < arguments.length; s++) { | ||
from = Object(arguments[s]); | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
/*eslint-disable no-self-compare*/ | ||
function is(x, y) { | ||
// SameValue algorithm | ||
if (x === y) { | ||
// Steps 1-5, 7-10 | ||
// Steps 6.b-6.e: +0 != -0 | ||
return x !== 0 || 1 / x === 1 / y; | ||
} else { | ||
// Step 6.a: NaN == NaN | ||
return x !== x && y !== y; | ||
} | ||
} | ||
/*eslint-enable no-self-compare*/ | ||
for (var key in from) { | ||
if (hasOwnProperty.call(from, key)) { | ||
to[key] = from[key]; | ||
} | ||
} | ||
/** | ||
* We use an Error-like object for backward compatibility as people may call | ||
* PropTypes directly and inspect their output. However, we don't use real | ||
* Errors anymore. We don't inspect their stack anyway, and creating them | ||
* is prohibitively expensive if they are created too often, such as what | ||
* happens in oneOfType() for any type before the one that matched. | ||
*/ | ||
function PropTypeError(message) { | ||
this.message = message; | ||
this.stack = ''; | ||
} | ||
// Make `instanceof Error` still work for returned errors. | ||
PropTypeError.prototype = Error.prototype; | ||
if (getOwnPropertySymbols) { | ||
symbols = getOwnPropertySymbols(from); | ||
function createChainableTypeChecker(validate) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
var manualPropTypeCallCache = {}; | ||
var manualPropTypeWarningCount = 0; | ||
} | ||
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { | ||
componentName = componentName || ANONYMOUS; | ||
propFullName = propFullName || propName; | ||
for (var i = 0; i < symbols.length; i++) { | ||
if (propIsEnumerable.call(from, symbols[i])) { | ||
to[symbols[i]] = from[symbols[i]]; | ||
} | ||
} | ||
} | ||
} | ||
if (secret !== ReactPropTypesSecret_1) { | ||
if (throwOnDirectAccess) { | ||
// New behavior only for users of `prop-types` package | ||
var err = new Error( | ||
'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' | ||
); | ||
err.name = 'Invariant Violation'; | ||
throw err; | ||
} else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') { | ||
// Old behavior for people using React.PropTypes | ||
var cacheKey = componentName + ':' + propName; | ||
if ( | ||
!manualPropTypeCallCache[cacheKey] && | ||
// Avoid spamming the console because they are often not actionable except for lib authors | ||
manualPropTypeWarningCount < 3 | ||
) { | ||
printWarning$1( | ||
'You are manually calling a React.PropTypes validation ' + | ||
'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' + | ||
'and will throw in the standalone `prop-types` package. ' + | ||
'You may be seeing this warning due to a third-party PropTypes ' + | ||
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.' | ||
); | ||
manualPropTypeCallCache[cacheKey] = true; | ||
manualPropTypeWarningCount++; | ||
} | ||
} | ||
} | ||
if (props[propName] == null) { | ||
if (isRequired) { | ||
if (props[propName] === null) { | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); | ||
} | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); | ||
} | ||
return null; | ||
} else { | ||
return validate(props, propName, componentName, location, propFullName); | ||
} | ||
} | ||
return to; | ||
}; | ||
var chainedCheckType = checkType.bind(null, false); | ||
chainedCheckType.isRequired = checkType.bind(null, true); | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
return chainedCheckType; | ||
} | ||
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; | ||
var ReactPropTypesSecret_1 = ReactPropTypesSecret; | ||
function createPrimitiveTypeChecker(expectedType) { | ||
function validate(props, propName, componentName, location, propFullName, secret) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== expectedType) { | ||
// `propValue` being instance of, say, date/regexp, pass the 'object' | ||
// check, but we can offer a more precise error message here rather than | ||
// 'of type `object`'. | ||
var preciseType = getPreciseType(propValue); | ||
var printWarning = function () {}; | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1; | ||
function createAnyTypeChecker() { | ||
return createChainableTypeChecker(emptyFunctionThatReturnsNull); | ||
} | ||
var loggedTypeFailures = {}; | ||
var has = Function.call.bind(Object.prototype.hasOwnProperty); | ||
function createArrayOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); | ||
} | ||
var propValue = props[propName]; | ||
if (!Array.isArray(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); | ||
} | ||
for (var i = 0; i < propValue.length; i++) { | ||
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
printWarning = function (text) { | ||
var message = 'Warning: ' + text; | ||
function createElementTypeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
if (!isValidElement(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
function createElementTypeTypeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
if (!reactIs.isValidElementType(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
} | ||
/** | ||
* Assert that the values match with the type specs. | ||
* Error messages are memorized and will only be shown once. | ||
* | ||
* @param {object} typeSpecs Map of name to a ReactPropType | ||
* @param {object} values Runtime values that need to be type-checked | ||
* @param {string} location e.g. "prop", "context", "child context" | ||
* @param {string} componentName Name of the component for error messages. | ||
* @param {?Function} getStack Returns the component stack. | ||
* @private | ||
*/ | ||
function createInstanceTypeChecker(expectedClass) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!(props[propName] instanceof expectedClass)) { | ||
var expectedClassName = expectedClass.name || ANONYMOUS; | ||
var actualClassName = getClassName(props[propName]); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createEnumTypeChecker(expectedValues) { | ||
if (!Array.isArray(expectedValues)) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (arguments.length > 1) { | ||
printWarning$1( | ||
'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' + | ||
'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).' | ||
); | ||
} else { | ||
printWarning$1('Invalid argument supplied to oneOf, expected an array.'); | ||
} | ||
} | ||
return emptyFunctionThatReturnsNull; | ||
} | ||
function checkPropTypes(typeSpecs, values, location, componentName, getStack) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
for (var typeSpecName in typeSpecs) { | ||
if (has(typeSpecs, typeSpecName)) { | ||
var error; // Prop type validation may throw. In case they do, we don't want to | ||
// fail the render phase where it didn't fail before. So we log it. | ||
// After these have been cleaned up, we'll let them throw. | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
for (var i = 0; i < expectedValues.length; i++) { | ||
if (is(propValue, expectedValues[i])) { | ||
return null; | ||
} | ||
} | ||
try { | ||
// This is intentionally an invariant that gets caught. It's the same | ||
// behavior as without this statement except with a better message. | ||
if (typeof typeSpecs[typeSpecName] !== 'function') { | ||
var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'); | ||
err.name = 'Invariant Violation'; | ||
throw err; | ||
} | ||
var valuesString = JSON.stringify(expectedValues, function replacer(key, value) { | ||
var type = getPreciseType(value); | ||
if (type === 'symbol') { | ||
return String(value); | ||
} | ||
return value; | ||
}); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
function createObjectOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); | ||
} | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); | ||
} | ||
for (var key in propValue) { | ||
if (has$1(propValue, key)) { | ||
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
if (error && !(error instanceof Error)) { | ||
printWarning((componentName || 'React class') + ': type specification of ' + location + ' `' + typeSpecName + '` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).'); | ||
} | ||
function createUnionTypeChecker(arrayOfTypeCheckers) { | ||
if (!Array.isArray(arrayOfTypeCheckers)) { | ||
process.env.NODE_ENV !== 'production' ? printWarning$1('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; | ||
return emptyFunctionThatReturnsNull; | ||
} | ||
if (error instanceof Error && !(error.message in loggedTypeFailures)) { | ||
// Only monitor this failure once because there tends to be a lot of the | ||
// same error. | ||
loggedTypeFailures[error.message] = true; | ||
var stack = getStack ? getStack() : ''; | ||
printWarning('Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Resets warning cache when testing. | ||
* | ||
* @private | ||
*/ | ||
for (var i = 0; i < arrayOfTypeCheckers.length; i++) { | ||
var checker = arrayOfTypeCheckers[i]; | ||
if (typeof checker !== 'function') { | ||
printWarning$1( | ||
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + | ||
'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.' | ||
); | ||
return emptyFunctionThatReturnsNull; | ||
} | ||
} | ||
function validate(props, propName, componentName, location, propFullName) { | ||
for (var i = 0; i < arrayOfTypeCheckers.length; i++) { | ||
var checker = arrayOfTypeCheckers[i]; | ||
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) { | ||
return null; | ||
} | ||
} | ||
checkPropTypes.resetWarningCache = function () { | ||
if (process.env.NODE_ENV !== 'production') { | ||
loggedTypeFailures = {}; | ||
} | ||
}; | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
var checkPropTypes_1 = checkPropTypes; | ||
function createNodeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!isNode(props[propName])) { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
var has$1 = Function.call.bind(Object.prototype.hasOwnProperty); | ||
function createShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
for (var key in shapeTypes) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
continue; | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
var printWarning$1 = function () {}; | ||
function createStrictShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
// We need to check all keys in case some are required but missing from | ||
// props. | ||
var allKeys = objectAssign({}, props[propName], shapeTypes); | ||
for (var key in allKeys) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
return new PropTypeError( | ||
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + | ||
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') + | ||
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') | ||
); | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
printWarning$1 = function (text) { | ||
var message = 'Warning: ' + text; | ||
return createChainableTypeChecker(validate); | ||
} | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
function isNode(propValue) { | ||
switch (typeof propValue) { | ||
case 'number': | ||
case 'string': | ||
case 'undefined': | ||
return true; | ||
case 'boolean': | ||
return !propValue; | ||
case 'object': | ||
if (Array.isArray(propValue)) { | ||
return propValue.every(isNode); | ||
} | ||
if (propValue === null || isValidElement(propValue)) { | ||
return true; | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
} | ||
var iteratorFn = getIteratorFn(propValue); | ||
if (iteratorFn) { | ||
var iterator = iteratorFn.call(propValue); | ||
var step; | ||
if (iteratorFn !== propValue.entries) { | ||
while (!(step = iterator.next()).done) { | ||
if (!isNode(step.value)) { | ||
return false; | ||
} | ||
} | ||
} else { | ||
// Iterator will provide entry [k,v] tuples rather than values. | ||
while (!(step = iterator.next()).done) { | ||
var entry = step.value; | ||
if (entry) { | ||
if (!isNode(entry[1])) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
function emptyFunctionThatReturnsNull() { | ||
return null; | ||
} | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
var factoryWithTypeCheckers = function (isValidElement, throwOnDirectAccess) { | ||
/* global Symbol */ | ||
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; | ||
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. | ||
function isSymbol(propType, propValue) { | ||
// Native Symbol. | ||
if (propType === 'symbol') { | ||
return true; | ||
} | ||
/** | ||
* Returns the iterator method function contained on the iterable object. | ||
* | ||
* Be sure to invoke the function with the iterable as context: | ||
* | ||
* var iteratorFn = getIteratorFn(myIterable); | ||
* if (iteratorFn) { | ||
* var iterator = iteratorFn.call(myIterable); | ||
* ... | ||
* } | ||
* | ||
* @param {?object} maybeIterable | ||
* @return {?function} | ||
*/ | ||
// falsy value can't be a Symbol | ||
if (!propValue) { | ||
return false; | ||
} | ||
function getIteratorFn(maybeIterable) { | ||
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); | ||
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' | ||
if (propValue['@@toStringTag'] === 'Symbol') { | ||
return true; | ||
} | ||
if (typeof iteratorFn === 'function') { | ||
return iteratorFn; | ||
} | ||
} | ||
/** | ||
* Collection of methods that allow declaration and validation of props that are | ||
* supplied to React components. Example usage: | ||
* | ||
* var Props = require('ReactPropTypes'); | ||
* var MyArticle = React.createClass({ | ||
* propTypes: { | ||
* // An optional string prop named "description". | ||
* description: Props.string, | ||
* | ||
* // A required enum prop named "category". | ||
* category: Props.oneOf(['News','Photos']).isRequired, | ||
* | ||
* // A prop named "dialog" that requires an instance of Dialog. | ||
* dialog: Props.instanceOf(Dialog).isRequired | ||
* }, | ||
* render: function() { ... } | ||
* }); | ||
* | ||
* A more formal specification of how these methods are used: | ||
* | ||
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) | ||
* decl := ReactPropTypes.{type}(.isRequired)? | ||
* | ||
* Each and every declaration produces a function with the same signature. This | ||
* allows the creation of custom validation functions. For example: | ||
* | ||
* var MyLink = React.createClass({ | ||
* propTypes: { | ||
* // An optional string or URI prop named "href". | ||
* href: function(props, propName, componentName) { | ||
* var propValue = props[propName]; | ||
* if (propValue != null && typeof propValue !== 'string' && | ||
* !(propValue instanceof URI)) { | ||
* return new Error( | ||
* 'Expected a string or an URI for ' + propName + ' in ' + | ||
* componentName | ||
* ); | ||
* } | ||
* } | ||
* }, | ||
* render: function() {...} | ||
* }); | ||
* | ||
* @internal | ||
*/ | ||
// Fallback for non-spec compliant Symbols which are polyfilled. | ||
if (typeof Symbol === 'function' && propValue instanceof Symbol) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
var ANONYMOUS = '<<anonymous>>'; // Important! | ||
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`. | ||
// Equivalent of `typeof` but with special handling for array and regexp. | ||
function getPropType(propValue) { | ||
var propType = typeof propValue; | ||
if (Array.isArray(propValue)) { | ||
return 'array'; | ||
} | ||
if (propValue instanceof RegExp) { | ||
// Old webkits (at least until Android 4.0) return 'function' rather than | ||
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/ | ||
// passes PropTypes.object. | ||
return 'object'; | ||
} | ||
if (isSymbol(propType, propValue)) { | ||
return 'symbol'; | ||
} | ||
return propType; | ||
} | ||
var ReactPropTypes = { | ||
array: createPrimitiveTypeChecker('array'), | ||
bool: createPrimitiveTypeChecker('boolean'), | ||
func: createPrimitiveTypeChecker('function'), | ||
number: createPrimitiveTypeChecker('number'), | ||
object: createPrimitiveTypeChecker('object'), | ||
string: createPrimitiveTypeChecker('string'), | ||
symbol: createPrimitiveTypeChecker('symbol'), | ||
any: createAnyTypeChecker(), | ||
arrayOf: createArrayOfTypeChecker, | ||
element: createElementTypeChecker(), | ||
elementType: createElementTypeTypeChecker(), | ||
instanceOf: createInstanceTypeChecker, | ||
node: createNodeChecker(), | ||
objectOf: createObjectOfTypeChecker, | ||
oneOf: createEnumTypeChecker, | ||
oneOfType: createUnionTypeChecker, | ||
shape: createShapeTypeChecker, | ||
exact: createStrictShapeTypeChecker | ||
}; | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
// This handles more types than `getPropType`. Only used for error messages. | ||
// See `createPrimitiveTypeChecker`. | ||
function getPreciseType(propValue) { | ||
if (typeof propValue === 'undefined' || propValue === null) { | ||
return '' + propValue; | ||
} | ||
var propType = getPropType(propValue); | ||
if (propType === 'object') { | ||
if (propValue instanceof Date) { | ||
return 'date'; | ||
} else if (propValue instanceof RegExp) { | ||
return 'regexp'; | ||
} | ||
} | ||
return propType; | ||
} | ||
/*eslint-disable no-self-compare*/ | ||
// Returns a string that is postfixed to a warning about an invalid type. | ||
// For example, "undefined" or "of type array" | ||
function getPostfixForTypeWarning(value) { | ||
var type = getPreciseType(value); | ||
switch (type) { | ||
case 'array': | ||
case 'object': | ||
return 'an ' + type; | ||
case 'boolean': | ||
case 'date': | ||
case 'regexp': | ||
return 'a ' + type; | ||
default: | ||
return type; | ||
} | ||
} | ||
function is(x, y) { | ||
// SameValue algorithm | ||
if (x === y) { | ||
// Steps 1-5, 7-10 | ||
// Steps 6.b-6.e: +0 != -0 | ||
return x !== 0 || 1 / x === 1 / y; | ||
} else { | ||
// Step 6.a: NaN == NaN | ||
return x !== x && y !== y; | ||
} | ||
} | ||
/*eslint-enable no-self-compare*/ | ||
// Returns class name of the object, if any. | ||
function getClassName(propValue) { | ||
if (!propValue.constructor || !propValue.constructor.name) { | ||
return ANONYMOUS; | ||
} | ||
return propValue.constructor.name; | ||
} | ||
/** | ||
* We use an Error-like object for backward compatibility as people may call | ||
* PropTypes directly and inspect their output. However, we don't use real | ||
* Errors anymore. We don't inspect their stack anyway, and creating them | ||
* is prohibitively expensive if they are created too often, such as what | ||
* happens in oneOfType() for any type before the one that matched. | ||
*/ | ||
ReactPropTypes.checkPropTypes = checkPropTypes_1; | ||
ReactPropTypes.resetWarningCache = checkPropTypes_1.resetWarningCache; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
return ReactPropTypes; | ||
}; | ||
function PropTypeError(message) { | ||
this.message = message; | ||
this.stack = ''; | ||
} // Make `instanceof Error` still work for returned errors. | ||
function emptyFunction() {} | ||
function emptyFunctionWithReset() {} | ||
emptyFunctionWithReset.resetWarningCache = emptyFunction; | ||
var factoryWithThrowingShims = function() { | ||
function shim(props, propName, componentName, location, propFullName, secret) { | ||
if (secret === ReactPropTypesSecret_1) { | ||
// It is still safe when called from React. | ||
return; | ||
} | ||
var err = new Error( | ||
'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' | ||
); | ||
err.name = 'Invariant Violation'; | ||
throw err; | ||
} shim.isRequired = shim; | ||
function getShim() { | ||
return shim; | ||
} // Important! | ||
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`. | ||
var ReactPropTypes = { | ||
array: shim, | ||
bool: shim, | ||
func: shim, | ||
number: shim, | ||
object: shim, | ||
string: shim, | ||
symbol: shim, | ||
PropTypeError.prototype = Error.prototype; | ||
any: shim, | ||
arrayOf: getShim, | ||
element: shim, | ||
elementType: shim, | ||
instanceOf: getShim, | ||
node: shim, | ||
objectOf: getShim, | ||
oneOf: getShim, | ||
oneOfType: getShim, | ||
shape: getShim, | ||
exact: getShim, | ||
function createChainableTypeChecker(validate) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
var manualPropTypeCallCache = {}; | ||
var manualPropTypeWarningCount = 0; | ||
} | ||
checkPropTypes: emptyFunctionWithReset, | ||
resetWarningCache: emptyFunction | ||
}; | ||
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { | ||
componentName = componentName || ANONYMOUS; | ||
propFullName = propFullName || propName; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
if (secret !== ReactPropTypesSecret_1) { | ||
if (throwOnDirectAccess) { | ||
// New behavior only for users of `prop-types` package | ||
var err = new Error('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'); | ||
err.name = 'Invariant Violation'; | ||
throw err; | ||
} else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') { | ||
// Old behavior for people using React.PropTypes | ||
var cacheKey = componentName + ':' + propName; | ||
return ReactPropTypes; | ||
}; | ||
if (!manualPropTypeCallCache[cacheKey] && // Avoid spamming the console because they are often not actionable except for lib authors | ||
manualPropTypeWarningCount < 3) { | ||
printWarning$1('You are manually calling a React.PropTypes validation ' + 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' + 'and will throw in the standalone `prop-types` package. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'); | ||
manualPropTypeCallCache[cacheKey] = true; | ||
manualPropTypeWarningCount++; | ||
} | ||
} | ||
} | ||
var propTypes = createCommonjsModule(function (module) { | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
if (props[propName] == null) { | ||
if (isRequired) { | ||
if (props[propName] === null) { | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
var ReactIs = reactIs; | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); | ||
} | ||
// By explicitly using `prop-types` you are opting into new development behavior. | ||
// http://fb.me/prop-types-in-prod | ||
var throwOnDirectAccess = true; | ||
module.exports = factoryWithTypeCheckers(ReactIs.isElement, throwOnDirectAccess); | ||
} else { | ||
// By explicitly using `prop-types` you are opting into new production behavior. | ||
// http://fb.me/prop-types-in-prod | ||
module.exports = factoryWithThrowingShims(); | ||
} | ||
}); | ||
return null; | ||
} else { | ||
return validate(props, propName, componentName, location, propFullName); | ||
} | ||
} | ||
var PLAIN_OBJECT_STR = '[object Object]'; | ||
var chainedCheckType = checkType.bind(null, false); | ||
chainedCheckType.isRequired = checkType.bind(null, true); | ||
return chainedCheckType; | ||
} | ||
var isEqual = function isEqual(left, right) { | ||
if (_typeof(left) !== 'object' || _typeof(right) !== 'object') { | ||
return left === right; | ||
} | ||
function createPrimitiveTypeChecker(expectedType) { | ||
function validate(props, propName, componentName, location, propFullName, secret) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (left === null || right === null) return left === right; | ||
var leftArray = Array.isArray(left); | ||
var rightArray = Array.isArray(right); | ||
if (leftArray !== rightArray) return false; | ||
var leftPlainObject = Object.prototype.toString.call(left) === PLAIN_OBJECT_STR; | ||
var rightPlainObject = Object.prototype.toString.call(right) === PLAIN_OBJECT_STR; | ||
if (leftPlainObject !== rightPlainObject) return false; | ||
if (!leftPlainObject && !leftArray) return false; | ||
var leftKeys = Object.keys(left); | ||
var rightKeys = Object.keys(right); | ||
if (leftKeys.length !== rightKeys.length) return false; | ||
var keySet = {}; | ||
if (propType !== expectedType) { | ||
// `propValue` being instance of, say, date/regexp, pass the 'object' | ||
// check, but we can offer a more precise error message here rather than | ||
// 'of type `object`'. | ||
var preciseType = getPreciseType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); | ||
} | ||
for (var i = 0; i < leftKeys.length; i += 1) { | ||
keySet[leftKeys[i]] = true; | ||
} | ||
return null; | ||
} | ||
for (var _i = 0; _i < rightKeys.length; _i += 1) { | ||
keySet[rightKeys[_i]] = true; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
var allKeys = Object.keys(keySet); | ||
function createAnyTypeChecker() { | ||
return createChainableTypeChecker(emptyFunctionThatReturnsNull); | ||
} | ||
if (allKeys.length !== leftKeys.length) { | ||
return false; | ||
} | ||
function createArrayOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); | ||
} | ||
var l = left; | ||
var r = right; | ||
var propValue = props[propName]; | ||
var pred = function pred(key) { | ||
return isEqual(l[key], r[key]); | ||
}; | ||
if (!Array.isArray(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); | ||
} | ||
return allKeys.every(pred); | ||
}; | ||
for (var i = 0; i < propValue.length; i++) { | ||
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1); | ||
var usePrevious = function usePrevious(value) { | ||
var ref = React.useRef(value); | ||
React.useEffect(function () { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
}; | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
// We are using types to enforce the `stripe` prop in this lib, | ||
// but in a real integration `stripe` could be anything, so we need | ||
// to do some sanity validation to prevent type errors. | ||
var validateStripe = function validateStripe(maybeStripe) { | ||
if (maybeStripe === null) { | ||
return maybeStripe; | ||
} | ||
return null; | ||
} | ||
if (_typeof(maybeStripe) === 'object' && typeof maybeStripe.elements === 'function' && typeof maybeStripe.createSource === 'function' && typeof maybeStripe.createToken === 'function' && typeof maybeStripe.createPaymentMethod === 'function') { | ||
// If the object appears to be roughly Stripe shaped, | ||
// force cast it to the expected type. | ||
return maybeStripe; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
throw new Error('Invalid prop `stripe` supplied to `Elements`. Please pass a valid Stripe object or null. ' + 'You can obtain a Stripe object by calling `window.Stripe(...)` with your publishable key.'); | ||
}; | ||
function createElementTypeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var parseStripeProp = function parseStripeProp(raw) { | ||
if (raw !== null && _typeof(raw) === 'object' && raw.then && typeof raw.then === 'function') { | ||
return { | ||
tag: 'async', | ||
stripePromise: Promise.resolve(raw).then(validateStripe) | ||
}; | ||
} | ||
if (!isValidElement(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); | ||
} | ||
var stripe = validateStripe(raw); | ||
return null; | ||
} | ||
if (stripe === null) { | ||
return { | ||
tag: 'empty' | ||
}; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
return { | ||
tag: 'sync', | ||
stripe: stripe | ||
}; | ||
}; | ||
function createElementTypeTypeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var ElementsContext = React__default.createContext(); | ||
var parseElementsContext = function parseElementsContext(ctx, useCase) { | ||
if (!ctx) { | ||
throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(useCase, " in an <Elements> provider.")); | ||
} | ||
if (!reactIs.isValidElementType(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.')); | ||
} | ||
return ctx; | ||
}; | ||
var Elements = function Elements(_ref) { | ||
var rawStripeProp = _ref.stripe, | ||
options = _ref.options, | ||
children = _ref.children; | ||
return null; | ||
} | ||
var _final = React.useRef(false); | ||
return createChainableTypeChecker(validate); | ||
} | ||
var isMounted = React.useRef(true); | ||
var parsed = React.useMemo(function () { | ||
return parseStripeProp(rawStripeProp); | ||
}, [rawStripeProp]); | ||
function createInstanceTypeChecker(expectedClass) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!(props[propName] instanceof expectedClass)) { | ||
var expectedClassName = expectedClass.name || ANONYMOUS; | ||
var actualClassName = getClassName(props[propName]); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); | ||
} | ||
var _useState = React.useState(function () { | ||
return { | ||
stripe: null, | ||
elements: null | ||
}; | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
ctx = _useState2[0], | ||
setContext = _useState2[1]; | ||
return null; | ||
} | ||
var prevStripe = usePrevious(rawStripeProp); | ||
var prevOptions = usePrevious(options); | ||
return createChainableTypeChecker(validate); | ||
} | ||
if (prevStripe !== null) { | ||
if (prevStripe !== rawStripeProp) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.'); | ||
} | ||
function createEnumTypeChecker(expectedValues) { | ||
if (!Array.isArray(expectedValues)) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (arguments.length > 1) { | ||
printWarning$1('Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' + 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'); | ||
} else { | ||
printWarning$1('Invalid argument supplied to oneOf, expected an array.'); | ||
} | ||
} | ||
if (!isEqual(options, prevOptions)) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `options` prop after setting the `stripe` prop.'); | ||
} | ||
} | ||
return emptyFunctionThatReturnsNull; | ||
} | ||
if (!_final.current) { | ||
if (parsed.tag === 'sync') { | ||
_final.current = true; | ||
setContext({ | ||
stripe: parsed.stripe, | ||
elements: parsed.stripe.elements(options) | ||
}); | ||
} | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
if (parsed.tag === 'async') { | ||
_final.current = true; | ||
parsed.stripePromise.then(function (stripe) { | ||
if (stripe && isMounted.current) { | ||
// Only update Elements context if the component is still mounted | ||
// and stripe is not null. We allow stripe to be null to make | ||
// handling SSR easier. | ||
setContext({ | ||
stripe: stripe, | ||
elements: stripe.elements(options) | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
for (var i = 0; i < expectedValues.length; i++) { | ||
if (is(propValue, expectedValues[i])) { | ||
return null; | ||
} | ||
} | ||
React.useEffect(function () { | ||
return function () { | ||
isMounted.current = false; | ||
}; | ||
}, []); | ||
return React__default.createElement(ElementsContext.Provider, { | ||
value: ctx | ||
}, children); | ||
}; | ||
Elements.propTypes = { | ||
stripe: propTypes.any, | ||
children: propTypes.node, | ||
options: propTypes.object | ||
}; | ||
var useElementsContextWithUseCase = function useElementsContextWithUseCase(useCaseMessage) { | ||
var ctx = React.useContext(ElementsContext); | ||
return parseElementsContext(ctx, useCaseMessage); | ||
}; | ||
var useElements = function useElements() { | ||
var _useElementsContextWi = useElementsContextWithUseCase('calls useElements()'), | ||
elements = _useElementsContextWi.elements; | ||
var valuesString = JSON.stringify(expectedValues, function replacer(key, value) { | ||
var type = getPreciseType(value); | ||
return elements; | ||
}; | ||
var useStripe = function useStripe() { | ||
var _useElementsContextWi2 = useElementsContextWithUseCase('calls useStripe()'), | ||
stripe = _useElementsContextWi2.stripe; | ||
if (type === 'symbol') { | ||
return String(value); | ||
} | ||
return stripe; | ||
}; | ||
var ElementsConsumer = function ElementsConsumer(_ref2) { | ||
var children = _ref2.children; | ||
var ctx = useElementsContextWithUseCase('mounts <ElementsConsumer>'); | ||
return children(ctx); | ||
}; | ||
ElementsConsumer.propTypes = { | ||
children: propTypes.func.isRequired | ||
}; | ||
return value; | ||
}); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); | ||
} | ||
var extractUpdateableOptions = function extractUpdateableOptions(options) { | ||
if (!options) { | ||
return {}; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
var paymentRequest = options.paymentRequest, | ||
rest = _objectWithoutProperties(options, ["paymentRequest"]); | ||
function createObjectOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); | ||
} | ||
return rest; | ||
}; | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
var noop = function noop() {}; | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); | ||
} | ||
var capitalized = function capitalized(str) { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
}; | ||
for (var key in propValue) { | ||
if (has$1(propValue, key)) { | ||
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
var useCallbackReference = function useCallbackReference(cb) { | ||
var cbStore = React.useRef(cb); | ||
React.useEffect(function () { | ||
cbStore.current = cb; | ||
}, [cb]); | ||
return function () { | ||
if (cbStore.current) { | ||
cbStore.current.apply(cbStore, arguments); | ||
} | ||
}; | ||
}; | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
} | ||
var createElementComponent = function createElementComponent(type, isServer) { | ||
var displayName = "".concat(capitalized(type), "Element"); | ||
return null; | ||
} | ||
var ClientElement = function ClientElement(props) { | ||
var id = props.id, | ||
className = props.className, | ||
options = props.options, | ||
onBlur = props.onBlur, | ||
onFocus = props.onFocus, | ||
onReady = props.onReady, | ||
onChange = props.onChange, | ||
onClick = props.onClick; | ||
return createChainableTypeChecker(validate); | ||
} | ||
var _useElementsContextWi = useElementsContextWithUseCase("mounts <".concat(displayName, ">")), | ||
elements = _useElementsContextWi.elements; | ||
function createUnionTypeChecker(arrayOfTypeCheckers) { | ||
if (!Array.isArray(arrayOfTypeCheckers)) { | ||
process.env.NODE_ENV !== 'production' ? printWarning$1('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; | ||
return emptyFunctionThatReturnsNull; | ||
} | ||
var elementRef = React.useRef(); | ||
var domNode = React.useRef(); | ||
var callOnReady = useCallbackReference(onReady); | ||
var callOnBlur = useCallbackReference(onBlur); | ||
var callOnFocus = useCallbackReference(onFocus); | ||
var callOnClick = useCallbackReference(onClick); | ||
var callOnChange = useCallbackReference(onChange); | ||
React.useLayoutEffect(function () { | ||
if (elementRef.current == null && elements && domNode.current != null) { | ||
var element = elements.create(type, options); | ||
elementRef.current = element; | ||
element.mount(domNode.current); | ||
element.on('ready', function () { | ||
return callOnReady(element); | ||
}); | ||
element.on('change', callOnChange); | ||
element.on('blur', callOnBlur); | ||
element.on('focus', callOnFocus); // Users can pass an an onClick prop on any Element component | ||
// just as they could listen for the `click` event on any Element, | ||
// but only the PaymentRequestButton will actually trigger the event. | ||
for (var i = 0; i < arrayOfTypeCheckers.length; i++) { | ||
var checker = arrayOfTypeCheckers[i]; | ||
element.on('click', callOnClick); | ||
} | ||
}); | ||
var prevOptions = React.useRef(options); | ||
React.useEffect(function () { | ||
if (prevOptions.current && prevOptions.current.paymentRequest !== options.paymentRequest) { | ||
console.warn('Unsupported prop change: options.paymentRequest is not a customizable property.'); | ||
} | ||
if (typeof checker !== 'function') { | ||
printWarning$1('Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'); | ||
return emptyFunctionThatReturnsNull; | ||
} | ||
} | ||
var updateableOptions = extractUpdateableOptions(options); | ||
function validate(props, propName, componentName, location, propFullName) { | ||
for (var i = 0; i < arrayOfTypeCheckers.length; i++) { | ||
var checker = arrayOfTypeCheckers[i]; | ||
if (Object.keys(updateableOptions).length !== 0 && !isEqual(updateableOptions, extractUpdateableOptions(prevOptions.current))) { | ||
if (elementRef.current) { | ||
elementRef.current.update(updateableOptions); | ||
prevOptions.current = options; | ||
} | ||
} | ||
}, [options]); | ||
React.useEffect(function () { | ||
return function () { | ||
if (elementRef.current) { | ||
elementRef.current.destroy(); | ||
} | ||
}; | ||
}, []); | ||
return React__default.createElement("div", { | ||
id: id, | ||
className: className, | ||
ref: domNode | ||
}); | ||
}; // Only render the Element wrapper in a server environment. | ||
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) { | ||
return null; | ||
} | ||
} | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); | ||
} | ||
var ServerElement = function ServerElement(props) { | ||
// Validate that we are in the right context by calling useElementsContextWithUseCase. | ||
useElementsContextWithUseCase("mounts <".concat(displayName, ">")); | ||
var id = props.id, | ||
className = props.className; | ||
return React__default.createElement("div", { | ||
id: id, | ||
className: className | ||
}); | ||
}; | ||
return createChainableTypeChecker(validate); | ||
} | ||
var Element = isServer ? ServerElement : ClientElement; | ||
Element.propTypes = { | ||
id: propTypes.string, | ||
className: propTypes.string, | ||
onChange: propTypes.func, | ||
onBlur: propTypes.func, | ||
onFocus: propTypes.func, | ||
onReady: propTypes.func, | ||
onClick: propTypes.func, | ||
options: propTypes.object | ||
}; | ||
Element.defaultProps = { | ||
onChange: noop, | ||
onBlur: noop, | ||
onFocus: noop, | ||
onReady: noop, | ||
onClick: noop, | ||
options: {} | ||
}; | ||
Element.displayName = displayName; | ||
Element.__elementType = type; // eslint-disable-line no-underscore-dangle | ||
function createNodeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!isNode(props[propName])) { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); | ||
} | ||
return Element; | ||
}; | ||
return null; | ||
} | ||
var isServer = typeof window === 'undefined'; | ||
var CardElement = createElementComponent('card', isServer); | ||
var CardNumberElement = createElementComponent('cardNumber', isServer); | ||
var CardExpiryElement = createElementComponent('cardExpiry', isServer); | ||
var CardCvcElement = createElementComponent('cardCvc', isServer); | ||
var IbanElement = createElementComponent('iban', isServer); | ||
var IdealBankElement = createElementComponent('idealBank', isServer); | ||
var PaymentRequestButtonElement = createElementComponent('paymentRequestButton', isServer); | ||
return createChainableTypeChecker(validate); | ||
} | ||
exports.CardCvcElement = CardCvcElement; | ||
exports.CardElement = CardElement; | ||
exports.CardExpiryElement = CardExpiryElement; | ||
exports.CardNumberElement = CardNumberElement; | ||
exports.Elements = Elements; | ||
exports.ElementsConsumer = ElementsConsumer; | ||
exports.IbanElement = IbanElement; | ||
exports.IdealBankElement = IdealBankElement; | ||
exports.PaymentRequestButtonElement = PaymentRequestButtonElement; | ||
exports.useElements = useElements; | ||
exports.useStripe = useStripe; | ||
function createShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
for (var key in shapeTypes) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
continue; | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createStrictShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} // We need to check all keys in case some are required but missing from | ||
// props. | ||
var allKeys = objectAssign({}, props[propName], shapeTypes); | ||
for (var key in allKeys) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')); | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function isNode(propValue) { | ||
switch (typeof propValue) { | ||
case 'number': | ||
case 'string': | ||
case 'undefined': | ||
return true; | ||
case 'boolean': | ||
return !propValue; | ||
case 'object': | ||
if (Array.isArray(propValue)) { | ||
return propValue.every(isNode); | ||
} | ||
if (propValue === null || isValidElement(propValue)) { | ||
return true; | ||
} | ||
var iteratorFn = getIteratorFn(propValue); | ||
if (iteratorFn) { | ||
var iterator = iteratorFn.call(propValue); | ||
var step; | ||
if (iteratorFn !== propValue.entries) { | ||
while (!(step = iterator.next()).done) { | ||
if (!isNode(step.value)) { | ||
return false; | ||
} | ||
} | ||
} else { | ||
// Iterator will provide entry [k,v] tuples rather than values. | ||
while (!(step = iterator.next()).done) { | ||
var entry = step.value; | ||
if (entry) { | ||
if (!isNode(entry[1])) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
function isSymbol(propType, propValue) { | ||
// Native Symbol. | ||
if (propType === 'symbol') { | ||
return true; | ||
} // falsy value can't be a Symbol | ||
if (!propValue) { | ||
return false; | ||
} // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' | ||
if (propValue['@@toStringTag'] === 'Symbol') { | ||
return true; | ||
} // Fallback for non-spec compliant Symbols which are polyfilled. | ||
if (typeof Symbol === 'function' && propValue instanceof Symbol) { | ||
return true; | ||
} | ||
return false; | ||
} // Equivalent of `typeof` but with special handling for array and regexp. | ||
function getPropType(propValue) { | ||
var propType = typeof propValue; | ||
if (Array.isArray(propValue)) { | ||
return 'array'; | ||
} | ||
if (propValue instanceof RegExp) { | ||
// Old webkits (at least until Android 4.0) return 'function' rather than | ||
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/ | ||
// passes PropTypes.object. | ||
return 'object'; | ||
} | ||
if (isSymbol(propType, propValue)) { | ||
return 'symbol'; | ||
} | ||
return propType; | ||
} // This handles more types than `getPropType`. Only used for error messages. | ||
// See `createPrimitiveTypeChecker`. | ||
function getPreciseType(propValue) { | ||
if (typeof propValue === 'undefined' || propValue === null) { | ||
return '' + propValue; | ||
} | ||
var propType = getPropType(propValue); | ||
if (propType === 'object') { | ||
if (propValue instanceof Date) { | ||
return 'date'; | ||
} else if (propValue instanceof RegExp) { | ||
return 'regexp'; | ||
} | ||
} | ||
return propType; | ||
} // Returns a string that is postfixed to a warning about an invalid type. | ||
// For example, "undefined" or "of type array" | ||
function getPostfixForTypeWarning(value) { | ||
var type = getPreciseType(value); | ||
switch (type) { | ||
case 'array': | ||
case 'object': | ||
return 'an ' + type; | ||
case 'boolean': | ||
case 'date': | ||
case 'regexp': | ||
return 'a ' + type; | ||
default: | ||
return type; | ||
} | ||
} // Returns class name of the object, if any. | ||
function getClassName(propValue) { | ||
if (!propValue.constructor || !propValue.constructor.name) { | ||
return ANONYMOUS; | ||
} | ||
return propValue.constructor.name; | ||
} | ||
ReactPropTypes.checkPropTypes = checkPropTypes_1; | ||
ReactPropTypes.resetWarningCache = checkPropTypes_1.resetWarningCache; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
return ReactPropTypes; | ||
}; | ||
function emptyFunction() {} | ||
function emptyFunctionWithReset() {} | ||
emptyFunctionWithReset.resetWarningCache = emptyFunction; | ||
var factoryWithThrowingShims = function () { | ||
function shim(props, propName, componentName, location, propFullName, secret) { | ||
if (secret === ReactPropTypesSecret_1) { | ||
// It is still safe when called from React. | ||
return; | ||
} | ||
var err = new Error('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'); | ||
err.name = 'Invariant Violation'; | ||
throw err; | ||
} | ||
shim.isRequired = shim; | ||
function getShim() { | ||
return shim; | ||
} | ||
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`. | ||
var ReactPropTypes = { | ||
array: shim, | ||
bool: shim, | ||
func: shim, | ||
number: shim, | ||
object: shim, | ||
string: shim, | ||
symbol: shim, | ||
any: shim, | ||
arrayOf: getShim, | ||
element: shim, | ||
elementType: shim, | ||
instanceOf: getShim, | ||
node: shim, | ||
objectOf: getShim, | ||
oneOf: getShim, | ||
oneOfType: getShim, | ||
shape: getShim, | ||
exact: getShim, | ||
checkPropTypes: emptyFunctionWithReset, | ||
resetWarningCache: emptyFunction | ||
}; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
return ReactPropTypes; | ||
}; | ||
var propTypes = createCommonjsModule(function (module) { | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
if (process.env.NODE_ENV !== 'production') { | ||
var ReactIs = reactIs; // By explicitly using `prop-types` you are opting into new development behavior. | ||
// http://fb.me/prop-types-in-prod | ||
var throwOnDirectAccess = true; | ||
module.exports = factoryWithTypeCheckers(ReactIs.isElement, throwOnDirectAccess); | ||
} else { | ||
// By explicitly using `prop-types` you are opting into new production behavior. | ||
// http://fb.me/prop-types-in-prod | ||
module.exports = factoryWithThrowingShims(); | ||
} | ||
}); | ||
const isUnknownObject = (raw) => { | ||
return raw !== null && typeof raw === 'object'; | ||
}; | ||
const isPromise = (raw) => { | ||
return isUnknownObject(raw) && typeof raw.then === 'function'; | ||
}; | ||
// We are using types to enforce the `stripe` prop in this lib, | ||
// but in an untyped integration `stripe` could be anything, so we need | ||
// to do some sanity validation to prevent type errors. | ||
const isStripe = (raw) => { | ||
return (isUnknownObject(raw) && | ||
typeof raw.elements === 'function' && | ||
typeof raw.createToken === 'function' && | ||
typeof raw.createPaymentMethod === 'function' && | ||
typeof raw.confirmCardPayment === 'function'); | ||
}; | ||
const PLAIN_OBJECT_STR = '[object Object]'; | ||
const isEqual = (left, right) => { | ||
if (!isUnknownObject(left) || !isUnknownObject(right)) { | ||
return left === right; | ||
} | ||
const leftArray = Array.isArray(left); | ||
const rightArray = Array.isArray(right); | ||
if (leftArray !== rightArray) | ||
return false; | ||
const leftPlainObject = Object.prototype.toString.call(left) === PLAIN_OBJECT_STR; | ||
const rightPlainObject = Object.prototype.toString.call(right) === PLAIN_OBJECT_STR; | ||
if (leftPlainObject !== rightPlainObject) | ||
return false; | ||
if (!leftPlainObject && !leftArray) | ||
return false; | ||
const leftKeys = Object.keys(left); | ||
const rightKeys = Object.keys(right); | ||
if (leftKeys.length !== rightKeys.length) | ||
return false; | ||
const keySet = {}; | ||
for (let i = 0; i < leftKeys.length; i += 1) { | ||
keySet[leftKeys[i]] = true; | ||
} | ||
for (let i = 0; i < rightKeys.length; i += 1) { | ||
keySet[rightKeys[i]] = true; | ||
} | ||
const allKeys = Object.keys(keySet); | ||
if (allKeys.length !== leftKeys.length) { | ||
return false; | ||
} | ||
const l = left; | ||
const r = right; | ||
const pred = (key) => { | ||
return isEqual(l[key], r[key]); | ||
}; | ||
return allKeys.every(pred); | ||
}; | ||
const usePrevious = (value) => { | ||
const ref = React.useRef(value); | ||
React.useEffect(() => { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
}; | ||
const INVALID_STRIPE_ERROR = 'Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.'; | ||
// We are using types to enforce the `stripe` prop in this lib, but in a real | ||
// integration `stripe` could be anything, so we need to do some sanity | ||
// validation to prevent type errors. | ||
const validateStripe = (maybeStripe) => { | ||
if (maybeStripe === null || isStripe(maybeStripe)) { | ||
return maybeStripe; | ||
} | ||
throw new Error(INVALID_STRIPE_ERROR); | ||
}; | ||
const parseStripeProp = (raw) => { | ||
if (isPromise(raw)) { | ||
return { | ||
tag: 'async', | ||
stripePromise: Promise.resolve(raw).then(validateStripe), | ||
}; | ||
} | ||
const stripe = validateStripe(raw); | ||
if (stripe === null) { | ||
return { tag: 'empty' }; | ||
} | ||
return { tag: 'sync', stripe }; | ||
}; | ||
const ElementsContext = React__default.createContext(null); | ||
ElementsContext.displayName = 'ElementsContext'; | ||
const parseElementsContext = (ctx, useCase) => { | ||
if (!ctx) { | ||
throw new Error(`Could not find Elements context; You need to wrap the part of your app that ${useCase} in an <Elements> provider.`); | ||
} | ||
return ctx; | ||
}; | ||
/** | ||
* The `Elements` provider allows you to use [Element components](https://stripe.com/docs/stripe-js/react#element-components) and access the [Stripe object](https://stripe.com/docs/js/initializing) in any nested component. | ||
* Render an `Elements` provider at the root of your React app so that it is available everywhere you need it. | ||
* | ||
* To use the `Elements` provider, call `loadStripe` from `@stripe/stripe-js` with your publishable key. | ||
* The `loadStripe` function will asynchronously load the Stripe.js script and initialize a `Stripe` object. | ||
* Pass the returned `Promise` to `Elements`. | ||
* | ||
* @docs https://stripe.com/docs/stripe-js/react#elements-provider | ||
*/ | ||
const Elements = ({ stripe: rawStripeProp, options, children, }) => { | ||
const final = React.useRef(false); | ||
const isMounted = React.useRef(true); | ||
const parsed = React.useMemo(() => parseStripeProp(rawStripeProp), [rawStripeProp]); | ||
const [ctx, setContext] = React.useState(() => ({ | ||
stripe: null, | ||
elements: null, | ||
})); | ||
const prevStripe = usePrevious(rawStripeProp); | ||
const prevOptions = usePrevious(options); | ||
if (prevStripe !== null) { | ||
if (prevStripe !== rawStripeProp) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.'); | ||
} | ||
if (!isEqual(options, prevOptions)) { | ||
console.warn('Unsupported prop change on Elements: You cannot change the `options` prop after setting the `stripe` prop.'); | ||
} | ||
} | ||
if (!final.current) { | ||
if (parsed.tag === 'sync') { | ||
final.current = true; | ||
setContext({ | ||
stripe: parsed.stripe, | ||
elements: parsed.stripe.elements(options), | ||
}); | ||
} | ||
if (parsed.tag === 'async') { | ||
final.current = true; | ||
parsed.stripePromise.then((stripe) => { | ||
if (stripe && isMounted.current) { | ||
// Only update Elements context if the component is still mounted | ||
// and stripe is not null. We allow stripe to be null to make | ||
// handling SSR easier. | ||
setContext({ | ||
stripe, | ||
elements: stripe.elements(options), | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
React.useEffect(() => { | ||
return () => { | ||
isMounted.current = false; | ||
}; | ||
}, []); | ||
return (React__default.createElement(ElementsContext.Provider, { value: ctx }, children)); | ||
}; | ||
Elements.propTypes = { | ||
stripe: propTypes.any, | ||
options: propTypes.object, | ||
}; | ||
const useElementsContextWithUseCase = (useCaseMessage) => { | ||
const ctx = React.useContext(ElementsContext); | ||
return parseElementsContext(ctx, useCaseMessage); | ||
}; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#useelements-hook | ||
*/ | ||
const useElements = () => { | ||
const { elements } = useElementsContextWithUseCase('calls useElements()'); | ||
return elements; | ||
}; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#usestripe-hook | ||
*/ | ||
const useStripe = () => { | ||
const { stripe } = useElementsContextWithUseCase('calls useStripe()'); | ||
return stripe; | ||
}; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#elements-consumer | ||
*/ | ||
const ElementsConsumer = ({ children, }) => { | ||
const ctx = useElementsContextWithUseCase('mounts <ElementsConsumer>'); | ||
// Assert to satsify the busted React.FC return type (it should be ReactNode) | ||
return children(ctx); | ||
}; | ||
ElementsConsumer.propTypes = { | ||
children: propTypes.func.isRequired, | ||
}; | ||
const useCallbackReference = (cb) => { | ||
const ref = React.useRef(cb); | ||
React.useEffect(() => { | ||
ref.current = cb; | ||
}, [cb]); | ||
return (...args) => { | ||
if (ref.current) { | ||
ref.current(...args); | ||
} | ||
}; | ||
}; | ||
const extractUpdateableOptions = (options) => { | ||
if (!isUnknownObject(options)) { | ||
return {}; | ||
} | ||
const { paymentRequest: _, ...rest } = options; | ||
return rest; | ||
}; | ||
const noop = () => { }; | ||
const capitalized = (str) => str.charAt(0).toUpperCase() + str.slice(1); | ||
const createElementComponent = (type, isServer) => { | ||
const displayName = `${capitalized(type)}Element`; | ||
const ClientElement = ({ id, className, options = {}, onBlur = noop, onFocus = noop, onReady = noop, onChange = noop, onClick = noop, }) => { | ||
const { elements } = useElementsContextWithUseCase(`mounts <${displayName}>`); | ||
const elementRef = React.useRef(null); | ||
const domNode = React.useRef(null); | ||
const callOnReady = useCallbackReference(onReady); | ||
const callOnBlur = useCallbackReference(onBlur); | ||
const callOnFocus = useCallbackReference(onFocus); | ||
const callOnClick = useCallbackReference(onClick); | ||
const callOnChange = useCallbackReference(onChange); | ||
React.useLayoutEffect(() => { | ||
if (elementRef.current == null && elements && domNode.current != null) { | ||
const element = elements.create(type, options); | ||
elementRef.current = element; | ||
element.mount(domNode.current); | ||
element.on('ready', () => callOnReady(element)); | ||
element.on('change', callOnChange); | ||
element.on('blur', callOnBlur); | ||
element.on('focus', callOnFocus); | ||
// Users can pass an an onClick prop on any Element component | ||
// just as they could listen for the `click` event on any Element, | ||
// but only the PaymentRequestButton will actually trigger the event. | ||
element.on('click', callOnClick); | ||
} | ||
}); | ||
const prevOptions = React.useRef(options); | ||
React.useEffect(() => { | ||
if (prevOptions.current && | ||
prevOptions.current.paymentRequest !== options.paymentRequest) { | ||
console.warn('Unsupported prop change: options.paymentRequest is not a customizable property.'); | ||
} | ||
const updateableOptions = extractUpdateableOptions(options); | ||
if (Object.keys(updateableOptions).length !== 0 && | ||
!isEqual(updateableOptions, extractUpdateableOptions(prevOptions.current))) { | ||
if (elementRef.current) { | ||
elementRef.current.update(updateableOptions); | ||
prevOptions.current = options; | ||
} | ||
} | ||
}, [options]); | ||
React.useEffect(() => () => { | ||
if (elementRef.current) { | ||
elementRef.current.destroy(); | ||
} | ||
}, []); | ||
return React__default.createElement("div", { id: id, className: className, ref: domNode }); | ||
}; | ||
// Only render the Element wrapper in a server environment. | ||
const ServerElement = (props) => { | ||
// Validate that we are in the right context by calling useElementsContextWithUseCase. | ||
useElementsContextWithUseCase(`mounts <${displayName}>`); | ||
const { id, className } = props; | ||
return React__default.createElement("div", { id: id, className: className }); | ||
}; | ||
const Element = isServer ? ServerElement : ClientElement; | ||
Element.propTypes = { | ||
id: propTypes.string, | ||
className: propTypes.string, | ||
onChange: propTypes.func, | ||
onBlur: propTypes.func, | ||
onFocus: propTypes.func, | ||
onReady: propTypes.func, | ||
onClick: propTypes.func, | ||
options: propTypes.object, | ||
}; | ||
Element.displayName = displayName; | ||
Element.__elementType = type; | ||
return Element; | ||
}; | ||
const isServer = typeof window === 'undefined'; | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardElement = createElementComponent('card', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardNumberElement = createElementComponent('cardNumber', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardExpiryElement = createElementComponent('cardExpiry', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const CardCvcElement = createElementComponent('cardCvc', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const IbanElement = createElementComponent('iban', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const IdealBankElement = createElementComponent('idealBank', isServer); | ||
/** | ||
* @docs https://stripe.com/docs/stripe-js/react#element-components | ||
*/ | ||
const PaymentRequestButtonElement = createElementComponent('paymentRequestButton', isServer); | ||
exports.CardCvcElement = CardCvcElement; | ||
exports.CardElement = CardElement; | ||
exports.CardExpiryElement = CardExpiryElement; | ||
exports.CardNumberElement = CardNumberElement; | ||
exports.Elements = Elements; | ||
exports.ElementsConsumer = ElementsConsumer; | ||
exports.IbanElement = IbanElement; | ||
exports.IdealBankElement = IdealBankElement; | ||
exports.PaymentRequestButtonElement = PaymentRequestButtonElement; | ||
exports.useElements = useElements; | ||
exports.useStripe = useStripe; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,1 +0,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=e||self).ReactStripe={},e.React)}(this,(function(e,t){"use strict";var n="default"in t?t.default:t;function r(e){return(r="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})(e)}function o(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},u=Object.keys(e);for(r=0;r<u.length;r++)n=u[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(r=0;r<u.length;r++)n=u[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],r=!0,o=!1,u=void 0;try{for(var c,i=e[Symbol.iterator]();!(r=(c=i.next()).done)&&(n.push(c.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{r||null==i.return||i.return()}finally{if(o)throw u}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var c="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";function i(){}function a(){}a.resetWarningCache=i;var s=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e){e.exports=function(){function e(e,t,n,r,o,u){if(u!==c){var i=new Error("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");throw i.name="Invariant Violation",i}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:a,resetWarningCache:i};return n.PropTypes=n,n}()})),l=function e(t,n){if("object"!==r(t)||"object"!==r(n))return t===n;if(null===t||null===n)return t===n;var o=Array.isArray(t);if(o!==Array.isArray(n))return!1;var u="[object Object]"===Object.prototype.toString.call(t);if(u!==("[object Object]"===Object.prototype.toString.call(n)))return!1;if(!u&&!o)return!1;var c=Object.keys(t),i=Object.keys(n);if(c.length!==i.length)return!1;for(var a={},s=0;s<c.length;s+=1)a[c[s]]=!0;for(var l=0;l<i.length;l+=1)a[i[l]]=!0;var f=Object.keys(a);if(f.length!==c.length)return!1;var p=t,y=n;return f.every((function(t){return e(p[t],y[t])}))},f=function(e){var n=t.useRef(e);return t.useEffect((function(){n.current=e}),[e]),n.current},p=function(e){if(null===e)return e;if("object"===r(e)&&"function"==typeof e.elements&&"function"==typeof e.createSource&&"function"==typeof e.createToken&&"function"==typeof e.createPaymentMethod)return e;throw new Error("Invalid prop `stripe` supplied to `Elements`. Please pass a valid Stripe object or null. You can obtain a Stripe object by calling `window.Stripe(...)` with your publishable key.")},y=n.createContext(),m=function(e){var o=e.stripe,c=e.options,i=e.children,a=t.useRef(!1),s=t.useRef(!0),m=t.useMemo((function(){return function(e){if(null!==e&&"object"===r(e)&&e.then&&"function"==typeof e.then)return{tag:"async",stripePromise:Promise.resolve(e).then(p)};var t=p(e);return null===t?{tag:"empty"}:{tag:"sync",stripe:t}}(o)}),[o]),d=u(t.useState((function(){return{stripe:null,elements:null}})),2),b=d[0],h=d[1],v=f(o),g=f(c);return null!==v&&(v!==o&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it."),l(c,g)||console.warn("Unsupported prop change on Elements: You cannot change the `options` prop after setting the `stripe` prop.")),a.current||("sync"===m.tag&&(a.current=!0,h({stripe:m.stripe,elements:m.stripe.elements(c)})),"async"===m.tag&&(a.current=!0,m.stripePromise.then((function(e){e&&s.current&&h({stripe:e,elements:e.elements(c)})})))),t.useEffect((function(){return function(){s.current=!1}}),[]),n.createElement(y.Provider,{value:b},i)};m.propTypes={stripe:s.any,children:s.node,options:s.object};var d=function(e){return function(e,t){if(!e)throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(t," in an <Elements> provider."));return e}(t.useContext(y),e)},b=function(e){return(0,e.children)(d("mounts <ElementsConsumer>"))};b.propTypes={children:s.func.isRequired};var h=function(e){if(!e)return{};e.paymentRequest;return o(e,["paymentRequest"])},v=function(){},g=function(e){var n=t.useRef(e);return t.useEffect((function(){n.current=e}),[e]),function(){n.current&&n.current.apply(n,arguments)}},E=function(e,r){var o,u="".concat((o=e).charAt(0).toUpperCase()+o.slice(1),"Element"),c=r?function(e){d("mounts <".concat(u,">"));var t=e.id,r=e.className;return n.createElement("div",{id:t,className:r})}:function(r){var o=r.id,c=r.className,i=r.options,a=r.onBlur,s=r.onFocus,f=r.onReady,p=r.onChange,y=r.onClick,m=d("mounts <".concat(u,">")).elements,b=t.useRef(),v=t.useRef(),E=g(f),j=g(a),O=g(s),R=g(y),S=g(p);t.useLayoutEffect((function(){if(null==b.current&&m&&null!=v.current){var t=m.create(e,i);b.current=t,t.mount(v.current),t.on("ready",(function(){return E(t)})),t.on("change",S),t.on("blur",j),t.on("focus",O),t.on("click",R)}}));var C=t.useRef(i);return t.useEffect((function(){C.current&&C.current.paymentRequest!==i.paymentRequest&&console.warn("Unsupported prop change: options.paymentRequest is not a customizable property.");var e=h(i);0===Object.keys(e).length||l(e,h(C.current))||b.current&&(b.current.update(e),C.current=i)}),[i]),t.useEffect((function(){return function(){b.current&&b.current.destroy()}}),[]),n.createElement("div",{id:o,className:c,ref:v})};return c.propTypes={id:s.string,className:s.string,onChange:s.func,onBlur:s.func,onFocus:s.func,onReady:s.func,onClick:s.func,options:s.object},c.defaultProps={onChange:v,onBlur:v,onFocus:v,onReady:v,onClick:v,options:{}},c.displayName=u,c.__elementType=e,c},j="undefined"==typeof window,O=E("card",j),R=E("cardNumber",j),S=E("cardExpiry",j),C=E("cardCvc",j),w=E("iban",j),k=E("idealBank",j),P=E("paymentRequestButton",j);e.CardCvcElement=C,e.CardElement=O,e.CardExpiryElement=S,e.CardNumberElement=R,e.Elements=m,e.ElementsConsumer=b,e.IbanElement=w,e.IdealBankElement=k,e.PaymentRequestButtonElement=P,e.useElements=function(){return d("calls useElements()").elements},e.useStripe=function(){return d("calls useStripe()").stripe},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).ReactStripe={},e.React)}(this,(function(e,t){"use strict";var n="default"in t?t.default:t;function r(){}function o(){}o.resetWarningCache=r;var s=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e){e.exports=function(){function e(e,t,n,r,o,s){if("SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==s){var c=new Error("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");throw c.name="Invariant Violation",c}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:o,resetWarningCache:r};return n.PropTypes=n,n}()}));const c=e=>null!==e&&"object"==typeof e,u=(e,t)=>{if(!c(e)||!c(t))return e===t;const n=Array.isArray(e);if(n!==Array.isArray(t))return!1;const r="[object Object]"===Object.prototype.toString.call(e);if(r!==("[object Object]"===Object.prototype.toString.call(t)))return!1;if(!r&&!n)return!1;const o=Object.keys(e),s=Object.keys(t);if(o.length!==s.length)return!1;const a={};for(let e=0;e<o.length;e+=1)a[o[e]]=!0;for(let e=0;e<s.length;e+=1)a[s[e]]=!0;const p=Object.keys(a);if(p.length!==o.length)return!1;const i=e,l=t;return p.every(e=>u(i[e],l[e]))},a=e=>{const n=t.useRef(e);return t.useEffect(()=>{n.current=e},[e]),n.current},p=e=>{if(null===e||c(t=e)&&"function"==typeof t.elements&&"function"==typeof t.createToken&&"function"==typeof t.createPaymentMethod&&"function"==typeof t.confirmCardPayment)return e;var t;throw new Error("Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.")},i=e=>{if((e=>c(e)&&"function"==typeof e.then)(e))return{tag:"async",stripePromise:Promise.resolve(e).then(p)};const t=p(e);return null===t?{tag:"empty"}:{tag:"sync",stripe:t}},l=n.createContext(null);l.displayName="ElementsContext";const f=({stripe:e,options:r,children:o})=>{const s=t.useRef(!1),c=t.useRef(!0),p=t.useMemo(()=>i(e),[e]),[f,m]=t.useState(()=>({stripe:null,elements:null})),y=a(e),d=a(r);return null!==y&&(y!==e&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it."),u(r,d)||console.warn("Unsupported prop change on Elements: You cannot change the `options` prop after setting the `stripe` prop.")),s.current||("sync"===p.tag&&(s.current=!0,m({stripe:p.stripe,elements:p.stripe.elements(r)})),"async"===p.tag&&(s.current=!0,p.stripePromise.then(e=>{e&&c.current&&m({stripe:e,elements:e.elements(r)})}))),t.useEffect(()=>()=>{c.current=!1},[]),n.createElement(l.Provider,{value:f},o)};f.propTypes={stripe:s.any,options:s.object};const m=e=>((e,t)=>{if(!e)throw new Error(`Could not find Elements context; You need to wrap the part of your app that ${t} in an <Elements> provider.`);return e})(t.useContext(l),e),y=({children:e})=>e(m("mounts <ElementsConsumer>"));y.propTypes={children:s.func.isRequired};const d=e=>{const n=t.useRef(e);return t.useEffect(()=>{n.current=e},[e]),(...e)=>{n.current&&n.current(...e)}},h=e=>{if(!c(e))return{};const{paymentRequest:t,...n}=e;return n},E=()=>{},g=(e,r)=>{const o=`${c=e,c.charAt(0).toUpperCase()+c.slice(1)}Element`;var c;const a=r?e=>{m(`mounts <${o}>`);const{id:t,className:r}=e;return n.createElement("div",{id:t,className:r})}:({id:r,className:s,options:c={},onBlur:a=E,onFocus:p=E,onReady:i=E,onChange:l=E,onClick:f=E})=>{const{elements:y}=m(`mounts <${o}>`),g=t.useRef(null),b=t.useRef(null),R=d(i),C=d(a),j=d(p),v=d(f),O=d(l);t.useLayoutEffect(()=>{if(null==g.current&&y&&null!=b.current){const t=y.create(e,c);g.current=t,t.mount(b.current),t.on("ready",()=>R(t)),t.on("change",O),t.on("blur",C),t.on("focus",j),t.on("click",v)}});const T=t.useRef(c);return t.useEffect(()=>{T.current&&T.current.paymentRequest!==c.paymentRequest&&console.warn("Unsupported prop change: options.paymentRequest is not a customizable property.");const e=h(c);0===Object.keys(e).length||u(e,h(T.current))||g.current&&(g.current.update(e),T.current=c)},[c]),t.useEffect(()=>()=>{g.current&&g.current.destroy()},[]),n.createElement("div",{id:r,className:s,ref:b})};return a.propTypes={id:s.string,className:s.string,onChange:s.func,onBlur:s.func,onFocus:s.func,onReady:s.func,onClick:s.func,options:s.object},a.displayName=o,a.__elementType=e,a},b="undefined"==typeof window,R=g("card",b),C=g("cardNumber",b),j=g("cardExpiry",b),v=g("cardCvc",b),O=g("iban",b),T=g("idealBank",b),k=g("paymentRequestButton",b);e.CardCvcElement=v,e.CardElement=R,e.CardExpiryElement=j,e.CardNumberElement=C,e.Elements=f,e.ElementsConsumer=y,e.IbanElement=O,e.IdealBankElement=T,e.PaymentRequestButtonElement=k,e.useElements=()=>{const{elements:e}=m("calls useElements()");return e},e.useStripe=()=>{const{stripe:e}=m("calls useStripe()");return e},Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@stripe/react-stripe-js", | ||
"version": "1.0.0-beta.3", | ||
"version": "1.0.0-beta.4", | ||
"description": "React components for Stripe.js and Stripe Elements", | ||
@@ -10,13 +10,13 @@ "main": "dist/react-stripe.js", | ||
"browser": "dist/react-stripe.umd.js", | ||
"types": "dist/react-stripe.d.ts", | ||
"scripts": { | ||
"test": "jest", | ||
"rollup": "rollup -c", | ||
"lint": "eslint src examples", | ||
"flow": "flow", | ||
"build": "yarn run lint && yarn run flow && yarn run rollup", | ||
"lint": "eslint '{src,examples}/**/*.{ts,tsx,js}'", | ||
"lint:prettier": "prettier './**/*.js' './**/*.css' './**/*.md' --list-different", | ||
"typecheck": "tsc", | ||
"build": "yarn run clean && yarn run rollup -c", | ||
"clean": "rimraf dist", | ||
"prettier": "prettier './**/*.js' './**/*.css' './**/*.md' --write", | ||
"prettier-list-different": "prettier './**/*.js' './**/*.css' './**/*.md' --list-different", | ||
"prepublish": "yarn run clean && yarn run build", | ||
"publish": "npm publish --access public", | ||
"prettier:fix": "prettier './**/*.js' './**/*.css' './**/*.md' --write", | ||
"ci": "yarn run lint && yarn run lint:prettier && yarn run test && yarn run typecheck && yarn run build", | ||
"prepublish": "yarn run ci", | ||
"doctoc": "doctoc README.md", | ||
@@ -32,5 +32,2 @@ "storybook": "start-storybook -p 6006 " | ||
"license": "MIT", | ||
"dependencies": { | ||
"prop-types": "^15.7.2" | ||
}, | ||
"repository": { | ||
@@ -45,2 +42,3 @@ "type": "git", | ||
"jest": { | ||
"preset": "ts-jest/presets/js-with-ts", | ||
"setupFilesAfterEnv": [ | ||
@@ -50,2 +48,5 @@ "<rootDir>/test/setupJest.js" | ||
}, | ||
"dependencies": { | ||
"prop-types": "^15.7.2" | ||
}, | ||
"devDependencies": { | ||
@@ -55,3 +56,2 @@ "@babel/cli": "^7.7.0", | ||
"@babel/preset-env": "^7.7.1", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/preset-react": "^7.7.0", | ||
@@ -61,4 +61,12 @@ "@storybook/addon-actions": "^5.2.6", | ||
"@storybook/addons": "^5.2.6", | ||
"@storybook/preset-typescript": "^1.2.0", | ||
"@storybook/react": "^5.2.6", | ||
"@stripe/stripe-js": "^1.0.0-beta.3", | ||
"@stripe/stripe-js": "1.0.0-beta.5", | ||
"@types/enzyme": "^3.10.4", | ||
"@types/jest": "^25.1.1", | ||
"@types/react": "^16.9.19", | ||
"@types/react-dom": "^16.9.5", | ||
"@typescript-eslint/eslint-plugin": "^2.18.0", | ||
"@typescript-eslint/parser": "^2.18.0", | ||
"@wessberg/rollup-plugin-ts": "^1.2.15", | ||
"babel-eslint": "^10.0.3", | ||
@@ -71,14 +79,14 @@ "babel-jest": "^24.9.0", | ||
"eslint-config-airbnb": "18.0.1", | ||
"eslint-config-prettier": "^6.5.0", | ||
"eslint-plugin-flowtype": "^4.3.0", | ||
"eslint-config-prettier": "^6.10.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jest": "^22.6.3", | ||
"eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"eslint-plugin-react": "^7.14.3", | ||
"eslint-plugin-react-hooks": "^1.7.0", | ||
"flow-bin": "^0.111.3", | ||
"jest": "^24.9.0", | ||
"fork-ts-checker-webpack-plugin": "^4.0.3", | ||
"jest": "^25.1.0", | ||
"prettier": "^1.19.1", | ||
"react": "~16.9.0", | ||
"react-docgen-typescript-loader": "^3.6.0", | ||
"react-dom": "~16.9.0", | ||
@@ -91,5 +99,9 @@ "rimraf": "^2.6.2", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^5.1.2" | ||
"rollup-plugin-terser": "^5.1.2", | ||
"ts-jest": "^25.1.0", | ||
"ts-loader": "^6.2.1", | ||
"typescript": "^3.7.5" | ||
}, | ||
"peerDependencies": { | ||
"@stripe/stripe-js": "1.0.0-beta.5", | ||
"react": "^16.8.0", | ||
@@ -96,0 +108,0 @@ "react-dom": "^16.8.0" |
@@ -9,2 +9,8 @@ # React Stripe.js | ||
### We’re currently beta-testing this library. | ||
Please contact us at | ||
[stripejs-feedback@stripe.com](mailto:stripejs-feedback@stripe.com) and provide | ||
your Stripe account ID for access to new documentation! | ||
## Getting Started | ||
@@ -33,3 +39,3 @@ | ||
import ReactDOM from 'react-dom'; | ||
import {loadStripe} from '@stripe/react-stripe-js'; | ||
import {loadStripe} from '@stripe/stripe-js'; | ||
import { | ||
@@ -80,3 +86,3 @@ CardElement, | ||
import ReactDOM from 'react-dom'; | ||
import {loadStripe} from '@stripe/react-stripe-js'; | ||
import {loadStripe} from '@stripe/stripe-js'; | ||
import {CardElement, Elements, ElementsConsumer} from '@stripe/react-stripe-js'; | ||
@@ -133,2 +139,12 @@ | ||
### TypeScript support | ||
React Stripe.js is packaged with TypeScript declarations. Some types are pulled | ||
from [`@stripe/stripe-js`](https://github.com/stripe/stripe-js)—be sure to add | ||
`@stripe/stripe-js` as a dependency to your project for full TypeScript support. | ||
Typings in React Stripe.js follow the same | ||
[versioning policy](https://github.com/stripe/stripe-js#typescript-support) as | ||
`@stripe/stripe-js`. | ||
### Contributing | ||
@@ -135,0 +151,0 @@ |
@@ -1,2 +0,1 @@ | ||
// @noflow | ||
import React, {useLayoutEffect} from 'react'; | ||
@@ -3,0 +2,0 @@ import {mount} from 'enzyme'; |
@@ -1,2 +0,1 @@ | ||
// @noflow | ||
import React from 'react'; | ||
@@ -3,0 +2,0 @@ import {act} from 'react-dom/test-utils'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
208267
24
4421
150
4
47
2