@betterstore/react 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.cjs.js +17 -2156
- package/dist/index.mjs +399 -0
- package/package.json +1 -1
- package/rollup.config.mjs +10 -3
- package/dist/index.esm.js +0 -2538
package/dist/index.cjs.js
CHANGED
|
@@ -1,47 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var zustand = require('zustand');
|
|
3
4
|
var React = require('react');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let state;
|
|
7
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
8
|
-
const setState = (partial, replace) => {
|
|
9
|
-
const nextState = typeof partial === "function" ? partial(state) : partial;
|
|
10
|
-
if (!Object.is(nextState, state)) {
|
|
11
|
-
const previousState = state;
|
|
12
|
-
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
|
13
|
-
listeners.forEach((listener) => listener(state, previousState));
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const getState = () => state;
|
|
17
|
-
const getInitialState = () => initialState;
|
|
18
|
-
const subscribe = (listener) => {
|
|
19
|
-
listeners.add(listener);
|
|
20
|
-
return () => listeners.delete(listener);
|
|
21
|
-
};
|
|
22
|
-
const api = { setState, getState, getInitialState, subscribe };
|
|
23
|
-
const initialState = state = createState(setState, getState, api);
|
|
24
|
-
return api;
|
|
25
|
-
};
|
|
26
|
-
const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
|
|
27
|
-
|
|
28
|
-
const identity = (arg) => arg;
|
|
29
|
-
function useStore(api, selector = identity) {
|
|
30
|
-
const slice = React.useSyncExternalStore(
|
|
31
|
-
api.subscribe,
|
|
32
|
-
() => selector(api.getState()),
|
|
33
|
-
() => selector(api.getInitialState())
|
|
34
|
-
);
|
|
35
|
-
React.useDebugValue(slice);
|
|
36
|
-
return slice;
|
|
37
|
-
}
|
|
38
|
-
const createImpl = (createState) => {
|
|
39
|
-
const api = createStore(createState);
|
|
40
|
-
const useBoundStore = (selector) => useStore(api, selector);
|
|
41
|
-
Object.assign(useBoundStore, api);
|
|
42
|
-
return useBoundStore;
|
|
43
|
-
};
|
|
44
|
-
const create = (createState) => createState ? createImpl(createState) : createImpl;
|
|
5
|
+
var reactStripeJs = require('@stripe/react-stripe-js');
|
|
6
|
+
var stripeJs = require('@stripe/stripe-js');
|
|
45
7
|
|
|
46
8
|
function createJSONStorage(getStorage, options) {
|
|
47
9
|
let storage;
|
|
@@ -240,12 +202,18 @@ const generateLineItemId = (item) => {
|
|
|
240
202
|
metadata: item.metadata,
|
|
241
203
|
}));
|
|
242
204
|
};
|
|
243
|
-
const useCart = create()(persist((set, get) => ({
|
|
205
|
+
const useCart = zustand.create()(persist((set, get) => ({
|
|
244
206
|
lineItems: [],
|
|
245
207
|
addItem: (product, additionalParams) => set((state) => {
|
|
246
208
|
var _a, _b;
|
|
247
209
|
const productId = typeof product === "string" ? product : product === null || product === void 0 ? void 0 : product.id;
|
|
248
|
-
const formattedNewItem =
|
|
210
|
+
const formattedNewItem = {
|
|
211
|
+
productId: productId,
|
|
212
|
+
product: typeof product !== "string" ? product : undefined,
|
|
213
|
+
quantity: (_a = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.quantity) !== null && _a !== void 0 ? _a : 1,
|
|
214
|
+
variantOptions: (_b = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) !== null && _b !== void 0 ? _b : [],
|
|
215
|
+
metadata: additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.metadata,
|
|
216
|
+
};
|
|
249
217
|
const id = generateLineItemId(formattedNewItem);
|
|
250
218
|
const existingItemIndex = state.lineItems.findIndex((item) => item.id === id);
|
|
251
219
|
if (existingItemIndex !== -1) {
|
|
@@ -380,2121 +348,14 @@ function CheckoutEmbed({ betterStore, checkoutId, }) {
|
|
|
380
348
|
}
|
|
381
349
|
var index$1 = React.memo(CheckoutEmbed);
|
|
382
350
|
|
|
383
|
-
|
|
384
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
var propTypes = {exports: {}};
|
|
388
|
-
|
|
389
|
-
var reactIs = {exports: {}};
|
|
390
|
-
|
|
391
|
-
var reactIs_production_min = {};
|
|
392
|
-
|
|
393
|
-
/** @license React v16.13.1
|
|
394
|
-
* react-is.production.min.js
|
|
395
|
-
*
|
|
396
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
397
|
-
*
|
|
398
|
-
* This source code is licensed under the MIT license found in the
|
|
399
|
-
* LICENSE file in the root directory of this source tree.
|
|
400
|
-
*/
|
|
401
|
-
|
|
402
|
-
var hasRequiredReactIs_production_min;
|
|
403
|
-
|
|
404
|
-
function requireReactIs_production_min () {
|
|
405
|
-
if (hasRequiredReactIs_production_min) return reactIs_production_min;
|
|
406
|
-
hasRequiredReactIs_production_min = 1;
|
|
407
|
-
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?
|
|
408
|
-
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.block"):60121,w=b?Symbol.for("react.fundamental"):60117,x=b?Symbol.for("react.responder"):60118,y=b?Symbol.for("react.scope"):60119;
|
|
409
|
-
function z(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 t:case r:case h:return a;default:return u}}case d:return u}}}function A(a){return z(a)===m}reactIs_production_min.AsyncMode=l;reactIs_production_min.ConcurrentMode=m;reactIs_production_min.ContextConsumer=k;reactIs_production_min.ContextProvider=h;reactIs_production_min.Element=c;reactIs_production_min.ForwardRef=n;reactIs_production_min.Fragment=e;reactIs_production_min.Lazy=t;reactIs_production_min.Memo=r;reactIs_production_min.Portal=d;
|
|
410
|
-
reactIs_production_min.Profiler=g;reactIs_production_min.StrictMode=f;reactIs_production_min.Suspense=p;reactIs_production_min.isAsyncMode=function(a){return A(a)||z(a)===l};reactIs_production_min.isConcurrentMode=A;reactIs_production_min.isContextConsumer=function(a){return z(a)===k};reactIs_production_min.isContextProvider=function(a){return z(a)===h};reactIs_production_min.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};reactIs_production_min.isForwardRef=function(a){return z(a)===n};reactIs_production_min.isFragment=function(a){return z(a)===e};reactIs_production_min.isLazy=function(a){return z(a)===t};
|
|
411
|
-
reactIs_production_min.isMemo=function(a){return z(a)===r};reactIs_production_min.isPortal=function(a){return z(a)===d};reactIs_production_min.isProfiler=function(a){return z(a)===g};reactIs_production_min.isStrictMode=function(a){return z(a)===f};reactIs_production_min.isSuspense=function(a){return z(a)===p};
|
|
412
|
-
reactIs_production_min.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===w||a.$$typeof===x||a.$$typeof===y||a.$$typeof===v)};reactIs_production_min.typeOf=z;
|
|
413
|
-
return reactIs_production_min;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
var reactIs_development = {};
|
|
417
|
-
|
|
418
|
-
/** @license React v16.13.1
|
|
419
|
-
* react-is.development.js
|
|
420
|
-
*
|
|
421
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
422
|
-
*
|
|
423
|
-
* This source code is licensed under the MIT license found in the
|
|
424
|
-
* LICENSE file in the root directory of this source tree.
|
|
425
|
-
*/
|
|
426
|
-
|
|
427
|
-
var hasRequiredReactIs_development;
|
|
428
|
-
|
|
429
|
-
function requireReactIs_development () {
|
|
430
|
-
if (hasRequiredReactIs_development) return reactIs_development;
|
|
431
|
-
hasRequiredReactIs_development = 1;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if (process.env.NODE_ENV !== "production") {
|
|
436
|
-
(function() {
|
|
437
|
-
|
|
438
|
-
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
439
|
-
// nor polyfill, then a plain number is used for performance.
|
|
440
|
-
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
441
|
-
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
|
442
|
-
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
|
443
|
-
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
|
444
|
-
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
|
445
|
-
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
|
446
|
-
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
|
447
|
-
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
|
|
448
|
-
// (unstable) APIs that have been removed. Can we remove the symbols?
|
|
449
|
-
|
|
450
|
-
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
|
451
|
-
var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
|
|
452
|
-
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
|
453
|
-
var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
|
|
454
|
-
var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
|
|
455
|
-
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
|
456
|
-
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
|
457
|
-
var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
|
|
458
|
-
var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
|
|
459
|
-
var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
|
|
460
|
-
var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
|
|
461
|
-
|
|
462
|
-
function isValidElementType(type) {
|
|
463
|
-
return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
|
|
464
|
-
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 || type.$$typeof === REACT_BLOCK_TYPE);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function typeOf(object) {
|
|
468
|
-
if (typeof object === 'object' && object !== null) {
|
|
469
|
-
var $$typeof = object.$$typeof;
|
|
470
|
-
|
|
471
|
-
switch ($$typeof) {
|
|
472
|
-
case REACT_ELEMENT_TYPE:
|
|
473
|
-
var type = object.type;
|
|
474
|
-
|
|
475
|
-
switch (type) {
|
|
476
|
-
case REACT_ASYNC_MODE_TYPE:
|
|
477
|
-
case REACT_CONCURRENT_MODE_TYPE:
|
|
478
|
-
case REACT_FRAGMENT_TYPE:
|
|
479
|
-
case REACT_PROFILER_TYPE:
|
|
480
|
-
case REACT_STRICT_MODE_TYPE:
|
|
481
|
-
case REACT_SUSPENSE_TYPE:
|
|
482
|
-
return type;
|
|
483
|
-
|
|
484
|
-
default:
|
|
485
|
-
var $$typeofType = type && type.$$typeof;
|
|
486
|
-
|
|
487
|
-
switch ($$typeofType) {
|
|
488
|
-
case REACT_CONTEXT_TYPE:
|
|
489
|
-
case REACT_FORWARD_REF_TYPE:
|
|
490
|
-
case REACT_LAZY_TYPE:
|
|
491
|
-
case REACT_MEMO_TYPE:
|
|
492
|
-
case REACT_PROVIDER_TYPE:
|
|
493
|
-
return $$typeofType;
|
|
494
|
-
|
|
495
|
-
default:
|
|
496
|
-
return $$typeof;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
case REACT_PORTAL_TYPE:
|
|
502
|
-
return $$typeof;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
return undefined;
|
|
507
|
-
} // AsyncMode is deprecated along with isAsyncMode
|
|
508
|
-
|
|
509
|
-
var AsyncMode = REACT_ASYNC_MODE_TYPE;
|
|
510
|
-
var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
|
|
511
|
-
var ContextConsumer = REACT_CONTEXT_TYPE;
|
|
512
|
-
var ContextProvider = REACT_PROVIDER_TYPE;
|
|
513
|
-
var Element = REACT_ELEMENT_TYPE;
|
|
514
|
-
var ForwardRef = REACT_FORWARD_REF_TYPE;
|
|
515
|
-
var Fragment = REACT_FRAGMENT_TYPE;
|
|
516
|
-
var Lazy = REACT_LAZY_TYPE;
|
|
517
|
-
var Memo = REACT_MEMO_TYPE;
|
|
518
|
-
var Portal = REACT_PORTAL_TYPE;
|
|
519
|
-
var Profiler = REACT_PROFILER_TYPE;
|
|
520
|
-
var StrictMode = REACT_STRICT_MODE_TYPE;
|
|
521
|
-
var Suspense = REACT_SUSPENSE_TYPE;
|
|
522
|
-
var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
|
|
523
|
-
|
|
524
|
-
function isAsyncMode(object) {
|
|
525
|
-
{
|
|
526
|
-
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
|
|
527
|
-
hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
|
|
528
|
-
|
|
529
|
-
console['warn']('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.');
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
|
|
534
|
-
}
|
|
535
|
-
function isConcurrentMode(object) {
|
|
536
|
-
return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
|
|
537
|
-
}
|
|
538
|
-
function isContextConsumer(object) {
|
|
539
|
-
return typeOf(object) === REACT_CONTEXT_TYPE;
|
|
540
|
-
}
|
|
541
|
-
function isContextProvider(object) {
|
|
542
|
-
return typeOf(object) === REACT_PROVIDER_TYPE;
|
|
543
|
-
}
|
|
544
|
-
function isElement(object) {
|
|
545
|
-
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
546
|
-
}
|
|
547
|
-
function isForwardRef(object) {
|
|
548
|
-
return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
|
549
|
-
}
|
|
550
|
-
function isFragment(object) {
|
|
551
|
-
return typeOf(object) === REACT_FRAGMENT_TYPE;
|
|
552
|
-
}
|
|
553
|
-
function isLazy(object) {
|
|
554
|
-
return typeOf(object) === REACT_LAZY_TYPE;
|
|
555
|
-
}
|
|
556
|
-
function isMemo(object) {
|
|
557
|
-
return typeOf(object) === REACT_MEMO_TYPE;
|
|
558
|
-
}
|
|
559
|
-
function isPortal(object) {
|
|
560
|
-
return typeOf(object) === REACT_PORTAL_TYPE;
|
|
561
|
-
}
|
|
562
|
-
function isProfiler(object) {
|
|
563
|
-
return typeOf(object) === REACT_PROFILER_TYPE;
|
|
564
|
-
}
|
|
565
|
-
function isStrictMode(object) {
|
|
566
|
-
return typeOf(object) === REACT_STRICT_MODE_TYPE;
|
|
567
|
-
}
|
|
568
|
-
function isSuspense(object) {
|
|
569
|
-
return typeOf(object) === REACT_SUSPENSE_TYPE;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
reactIs_development.AsyncMode = AsyncMode;
|
|
573
|
-
reactIs_development.ConcurrentMode = ConcurrentMode;
|
|
574
|
-
reactIs_development.ContextConsumer = ContextConsumer;
|
|
575
|
-
reactIs_development.ContextProvider = ContextProvider;
|
|
576
|
-
reactIs_development.Element = Element;
|
|
577
|
-
reactIs_development.ForwardRef = ForwardRef;
|
|
578
|
-
reactIs_development.Fragment = Fragment;
|
|
579
|
-
reactIs_development.Lazy = Lazy;
|
|
580
|
-
reactIs_development.Memo = Memo;
|
|
581
|
-
reactIs_development.Portal = Portal;
|
|
582
|
-
reactIs_development.Profiler = Profiler;
|
|
583
|
-
reactIs_development.StrictMode = StrictMode;
|
|
584
|
-
reactIs_development.Suspense = Suspense;
|
|
585
|
-
reactIs_development.isAsyncMode = isAsyncMode;
|
|
586
|
-
reactIs_development.isConcurrentMode = isConcurrentMode;
|
|
587
|
-
reactIs_development.isContextConsumer = isContextConsumer;
|
|
588
|
-
reactIs_development.isContextProvider = isContextProvider;
|
|
589
|
-
reactIs_development.isElement = isElement;
|
|
590
|
-
reactIs_development.isForwardRef = isForwardRef;
|
|
591
|
-
reactIs_development.isFragment = isFragment;
|
|
592
|
-
reactIs_development.isLazy = isLazy;
|
|
593
|
-
reactIs_development.isMemo = isMemo;
|
|
594
|
-
reactIs_development.isPortal = isPortal;
|
|
595
|
-
reactIs_development.isProfiler = isProfiler;
|
|
596
|
-
reactIs_development.isStrictMode = isStrictMode;
|
|
597
|
-
reactIs_development.isSuspense = isSuspense;
|
|
598
|
-
reactIs_development.isValidElementType = isValidElementType;
|
|
599
|
-
reactIs_development.typeOf = typeOf;
|
|
600
|
-
})();
|
|
601
|
-
}
|
|
602
|
-
return reactIs_development;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
var hasRequiredReactIs;
|
|
606
|
-
|
|
607
|
-
function requireReactIs () {
|
|
608
|
-
if (hasRequiredReactIs) return reactIs.exports;
|
|
609
|
-
hasRequiredReactIs = 1;
|
|
610
|
-
|
|
611
|
-
if (process.env.NODE_ENV === 'production') {
|
|
612
|
-
reactIs.exports = requireReactIs_production_min();
|
|
613
|
-
} else {
|
|
614
|
-
reactIs.exports = requireReactIs_development();
|
|
615
|
-
}
|
|
616
|
-
return reactIs.exports;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
/*
|
|
620
|
-
object-assign
|
|
621
|
-
(c) Sindre Sorhus
|
|
622
|
-
@license MIT
|
|
623
|
-
*/
|
|
624
|
-
|
|
625
|
-
var objectAssign;
|
|
626
|
-
var hasRequiredObjectAssign;
|
|
627
|
-
|
|
628
|
-
function requireObjectAssign () {
|
|
629
|
-
if (hasRequiredObjectAssign) return objectAssign;
|
|
630
|
-
hasRequiredObjectAssign = 1;
|
|
631
|
-
/* eslint-disable no-unused-vars */
|
|
632
|
-
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
633
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
634
|
-
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
635
|
-
|
|
636
|
-
function toObject(val) {
|
|
637
|
-
if (val === null || val === undefined) {
|
|
638
|
-
throw new TypeError('Object.assign cannot be called with null or undefined');
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
return Object(val);
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
function shouldUseNative() {
|
|
645
|
-
try {
|
|
646
|
-
if (!Object.assign) {
|
|
647
|
-
return false;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
// Detect buggy property enumeration order in older V8 versions.
|
|
651
|
-
|
|
652
|
-
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
|
|
653
|
-
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
|
|
654
|
-
test1[5] = 'de';
|
|
655
|
-
if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
|
656
|
-
return false;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
|
660
|
-
var test2 = {};
|
|
661
|
-
for (var i = 0; i < 10; i++) {
|
|
662
|
-
test2['_' + String.fromCharCode(i)] = i;
|
|
663
|
-
}
|
|
664
|
-
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
|
665
|
-
return test2[n];
|
|
666
|
-
});
|
|
667
|
-
if (order2.join('') !== '0123456789') {
|
|
668
|
-
return false;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
|
672
|
-
var test3 = {};
|
|
673
|
-
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
|
674
|
-
test3[letter] = letter;
|
|
675
|
-
});
|
|
676
|
-
if (Object.keys(Object.assign({}, test3)).join('') !==
|
|
677
|
-
'abcdefghijklmnopqrst') {
|
|
678
|
-
return false;
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
return true;
|
|
682
|
-
} catch (err) {
|
|
683
|
-
// We don't expect any of the above to throw, but better to be safe.
|
|
684
|
-
return false;
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
|
|
689
|
-
var from;
|
|
690
|
-
var to = toObject(target);
|
|
691
|
-
var symbols;
|
|
692
|
-
|
|
693
|
-
for (var s = 1; s < arguments.length; s++) {
|
|
694
|
-
from = Object(arguments[s]);
|
|
695
|
-
|
|
696
|
-
for (var key in from) {
|
|
697
|
-
if (hasOwnProperty.call(from, key)) {
|
|
698
|
-
to[key] = from[key];
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
if (getOwnPropertySymbols) {
|
|
703
|
-
symbols = getOwnPropertySymbols(from);
|
|
704
|
-
for (var i = 0; i < symbols.length; i++) {
|
|
705
|
-
if (propIsEnumerable.call(from, symbols[i])) {
|
|
706
|
-
to[symbols[i]] = from[symbols[i]];
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
return to;
|
|
713
|
-
};
|
|
714
|
-
return objectAssign;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
/**
|
|
718
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
719
|
-
*
|
|
720
|
-
* This source code is licensed under the MIT license found in the
|
|
721
|
-
* LICENSE file in the root directory of this source tree.
|
|
722
|
-
*/
|
|
723
|
-
|
|
724
|
-
var ReactPropTypesSecret_1;
|
|
725
|
-
var hasRequiredReactPropTypesSecret;
|
|
726
|
-
|
|
727
|
-
function requireReactPropTypesSecret () {
|
|
728
|
-
if (hasRequiredReactPropTypesSecret) return ReactPropTypesSecret_1;
|
|
729
|
-
hasRequiredReactPropTypesSecret = 1;
|
|
730
|
-
|
|
731
|
-
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
|
732
|
-
|
|
733
|
-
ReactPropTypesSecret_1 = ReactPropTypesSecret;
|
|
734
|
-
return ReactPropTypesSecret_1;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
var has;
|
|
738
|
-
var hasRequiredHas;
|
|
739
|
-
|
|
740
|
-
function requireHas () {
|
|
741
|
-
if (hasRequiredHas) return has;
|
|
742
|
-
hasRequiredHas = 1;
|
|
743
|
-
has = Function.call.bind(Object.prototype.hasOwnProperty);
|
|
744
|
-
return has;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
/**
|
|
748
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
749
|
-
*
|
|
750
|
-
* This source code is licensed under the MIT license found in the
|
|
751
|
-
* LICENSE file in the root directory of this source tree.
|
|
752
|
-
*/
|
|
753
|
-
|
|
754
|
-
var checkPropTypes_1;
|
|
755
|
-
var hasRequiredCheckPropTypes;
|
|
756
|
-
|
|
757
|
-
function requireCheckPropTypes () {
|
|
758
|
-
if (hasRequiredCheckPropTypes) return checkPropTypes_1;
|
|
759
|
-
hasRequiredCheckPropTypes = 1;
|
|
760
|
-
|
|
761
|
-
var printWarning = function() {};
|
|
762
|
-
|
|
763
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
764
|
-
var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
|
|
765
|
-
var loggedTypeFailures = {};
|
|
766
|
-
var has = /*@__PURE__*/ requireHas();
|
|
767
|
-
|
|
768
|
-
printWarning = function(text) {
|
|
769
|
-
var message = 'Warning: ' + text;
|
|
770
|
-
if (typeof console !== 'undefined') {
|
|
771
|
-
console.error(message);
|
|
772
|
-
}
|
|
773
|
-
try {
|
|
774
|
-
// --- Welcome to debugging React ---
|
|
775
|
-
// This error was thrown as a convenience so that you can use this stack
|
|
776
|
-
// to find the callsite that caused this warning to fire.
|
|
777
|
-
throw new Error(message);
|
|
778
|
-
} catch (x) { /**/ }
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
/**
|
|
783
|
-
* Assert that the values match with the type specs.
|
|
784
|
-
* Error messages are memorized and will only be shown once.
|
|
785
|
-
*
|
|
786
|
-
* @param {object} typeSpecs Map of name to a ReactPropType
|
|
787
|
-
* @param {object} values Runtime values that need to be type-checked
|
|
788
|
-
* @param {string} location e.g. "prop", "context", "child context"
|
|
789
|
-
* @param {string} componentName Name of the component for error messages.
|
|
790
|
-
* @param {?Function} getStack Returns the component stack.
|
|
791
|
-
* @private
|
|
792
|
-
*/
|
|
793
|
-
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
|
794
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
795
|
-
for (var typeSpecName in typeSpecs) {
|
|
796
|
-
if (has(typeSpecs, typeSpecName)) {
|
|
797
|
-
var error;
|
|
798
|
-
// Prop type validation may throw. In case they do, we don't want to
|
|
799
|
-
// fail the render phase where it didn't fail before. So we log it.
|
|
800
|
-
// After these have been cleaned up, we'll let them throw.
|
|
801
|
-
try {
|
|
802
|
-
// This is intentionally an invariant that gets caught. It's the same
|
|
803
|
-
// behavior as without this statement except with a better message.
|
|
804
|
-
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
|
805
|
-
var err = Error(
|
|
806
|
-
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
|
807
|
-
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' +
|
|
808
|
-
'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'
|
|
809
|
-
);
|
|
810
|
-
err.name = 'Invariant Violation';
|
|
811
|
-
throw err;
|
|
812
|
-
}
|
|
813
|
-
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
|
814
|
-
} catch (ex) {
|
|
815
|
-
error = ex;
|
|
816
|
-
}
|
|
817
|
-
if (error && !(error instanceof Error)) {
|
|
818
|
-
printWarning(
|
|
819
|
-
(componentName || 'React class') + ': type specification of ' +
|
|
820
|
-
location + ' `' + typeSpecName + '` is invalid; the type checker ' +
|
|
821
|
-
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
|
|
822
|
-
'You may have forgotten to pass an argument to the type checker ' +
|
|
823
|
-
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
|
|
824
|
-
'shape all require an argument).'
|
|
825
|
-
);
|
|
826
|
-
}
|
|
827
|
-
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
828
|
-
// Only monitor this failure once because there tends to be a lot of the
|
|
829
|
-
// same error.
|
|
830
|
-
loggedTypeFailures[error.message] = true;
|
|
831
|
-
|
|
832
|
-
var stack = getStack ? getStack() : '';
|
|
833
|
-
|
|
834
|
-
printWarning(
|
|
835
|
-
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
/**
|
|
844
|
-
* Resets warning cache when testing.
|
|
845
|
-
*
|
|
846
|
-
* @private
|
|
847
|
-
*/
|
|
848
|
-
checkPropTypes.resetWarningCache = function() {
|
|
849
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
850
|
-
loggedTypeFailures = {};
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
|
|
854
|
-
checkPropTypes_1 = checkPropTypes;
|
|
855
|
-
return checkPropTypes_1;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
/**
|
|
859
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
860
|
-
*
|
|
861
|
-
* This source code is licensed under the MIT license found in the
|
|
862
|
-
* LICENSE file in the root directory of this source tree.
|
|
863
|
-
*/
|
|
864
|
-
|
|
865
|
-
var factoryWithTypeCheckers;
|
|
866
|
-
var hasRequiredFactoryWithTypeCheckers;
|
|
867
|
-
|
|
868
|
-
function requireFactoryWithTypeCheckers () {
|
|
869
|
-
if (hasRequiredFactoryWithTypeCheckers) return factoryWithTypeCheckers;
|
|
870
|
-
hasRequiredFactoryWithTypeCheckers = 1;
|
|
871
|
-
|
|
872
|
-
var ReactIs = requireReactIs();
|
|
873
|
-
var assign = requireObjectAssign();
|
|
874
|
-
|
|
875
|
-
var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
|
|
876
|
-
var has = /*@__PURE__*/ requireHas();
|
|
877
|
-
var checkPropTypes = /*@__PURE__*/ requireCheckPropTypes();
|
|
878
|
-
|
|
879
|
-
var printWarning = function() {};
|
|
880
|
-
|
|
881
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
882
|
-
printWarning = function(text) {
|
|
883
|
-
var message = 'Warning: ' + text;
|
|
884
|
-
if (typeof console !== 'undefined') {
|
|
885
|
-
console.error(message);
|
|
886
|
-
}
|
|
887
|
-
try {
|
|
888
|
-
// --- Welcome to debugging React ---
|
|
889
|
-
// This error was thrown as a convenience so that you can use this stack
|
|
890
|
-
// to find the callsite that caused this warning to fire.
|
|
891
|
-
throw new Error(message);
|
|
892
|
-
} catch (x) {}
|
|
893
|
-
};
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
function emptyFunctionThatReturnsNull() {
|
|
897
|
-
return null;
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
|
|
901
|
-
/* global Symbol */
|
|
902
|
-
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
|
903
|
-
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Returns the iterator method function contained on the iterable object.
|
|
907
|
-
*
|
|
908
|
-
* Be sure to invoke the function with the iterable as context:
|
|
909
|
-
*
|
|
910
|
-
* var iteratorFn = getIteratorFn(myIterable);
|
|
911
|
-
* if (iteratorFn) {
|
|
912
|
-
* var iterator = iteratorFn.call(myIterable);
|
|
913
|
-
* ...
|
|
914
|
-
* }
|
|
915
|
-
*
|
|
916
|
-
* @param {?object} maybeIterable
|
|
917
|
-
* @return {?function}
|
|
918
|
-
*/
|
|
919
|
-
function getIteratorFn(maybeIterable) {
|
|
920
|
-
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
|
921
|
-
if (typeof iteratorFn === 'function') {
|
|
922
|
-
return iteratorFn;
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
/**
|
|
927
|
-
* Collection of methods that allow declaration and validation of props that are
|
|
928
|
-
* supplied to React components. Example usage:
|
|
929
|
-
*
|
|
930
|
-
* var Props = require('ReactPropTypes');
|
|
931
|
-
* var MyArticle = React.createClass({
|
|
932
|
-
* propTypes: {
|
|
933
|
-
* // An optional string prop named "description".
|
|
934
|
-
* description: Props.string,
|
|
935
|
-
*
|
|
936
|
-
* // A required enum prop named "category".
|
|
937
|
-
* category: Props.oneOf(['News','Photos']).isRequired,
|
|
938
|
-
*
|
|
939
|
-
* // A prop named "dialog" that requires an instance of Dialog.
|
|
940
|
-
* dialog: Props.instanceOf(Dialog).isRequired
|
|
941
|
-
* },
|
|
942
|
-
* render: function() { ... }
|
|
943
|
-
* });
|
|
944
|
-
*
|
|
945
|
-
* A more formal specification of how these methods are used:
|
|
946
|
-
*
|
|
947
|
-
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
|
948
|
-
* decl := ReactPropTypes.{type}(.isRequired)?
|
|
949
|
-
*
|
|
950
|
-
* Each and every declaration produces a function with the same signature. This
|
|
951
|
-
* allows the creation of custom validation functions. For example:
|
|
952
|
-
*
|
|
953
|
-
* var MyLink = React.createClass({
|
|
954
|
-
* propTypes: {
|
|
955
|
-
* // An optional string or URI prop named "href".
|
|
956
|
-
* href: function(props, propName, componentName) {
|
|
957
|
-
* var propValue = props[propName];
|
|
958
|
-
* if (propValue != null && typeof propValue !== 'string' &&
|
|
959
|
-
* !(propValue instanceof URI)) {
|
|
960
|
-
* return new Error(
|
|
961
|
-
* 'Expected a string or an URI for ' + propName + ' in ' +
|
|
962
|
-
* componentName
|
|
963
|
-
* );
|
|
964
|
-
* }
|
|
965
|
-
* }
|
|
966
|
-
* },
|
|
967
|
-
* render: function() {...}
|
|
968
|
-
* });
|
|
969
|
-
*
|
|
970
|
-
* @internal
|
|
971
|
-
*/
|
|
972
|
-
|
|
973
|
-
var ANONYMOUS = '<<anonymous>>';
|
|
974
|
-
|
|
975
|
-
// Important!
|
|
976
|
-
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
|
|
977
|
-
var ReactPropTypes = {
|
|
978
|
-
array: createPrimitiveTypeChecker('array'),
|
|
979
|
-
bigint: createPrimitiveTypeChecker('bigint'),
|
|
980
|
-
bool: createPrimitiveTypeChecker('boolean'),
|
|
981
|
-
func: createPrimitiveTypeChecker('function'),
|
|
982
|
-
number: createPrimitiveTypeChecker('number'),
|
|
983
|
-
object: createPrimitiveTypeChecker('object'),
|
|
984
|
-
string: createPrimitiveTypeChecker('string'),
|
|
985
|
-
symbol: createPrimitiveTypeChecker('symbol'),
|
|
986
|
-
|
|
987
|
-
any: createAnyTypeChecker(),
|
|
988
|
-
arrayOf: createArrayOfTypeChecker,
|
|
989
|
-
element: createElementTypeChecker(),
|
|
990
|
-
elementType: createElementTypeTypeChecker(),
|
|
991
|
-
instanceOf: createInstanceTypeChecker,
|
|
992
|
-
node: createNodeChecker(),
|
|
993
|
-
objectOf: createObjectOfTypeChecker,
|
|
994
|
-
oneOf: createEnumTypeChecker,
|
|
995
|
-
oneOfType: createUnionTypeChecker,
|
|
996
|
-
shape: createShapeTypeChecker,
|
|
997
|
-
exact: createStrictShapeTypeChecker,
|
|
998
|
-
};
|
|
999
|
-
|
|
1000
|
-
/**
|
|
1001
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
1002
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
1003
|
-
*/
|
|
1004
|
-
/*eslint-disable no-self-compare*/
|
|
1005
|
-
function is(x, y) {
|
|
1006
|
-
// SameValue algorithm
|
|
1007
|
-
if (x === y) {
|
|
1008
|
-
// Steps 1-5, 7-10
|
|
1009
|
-
// Steps 6.b-6.e: +0 != -0
|
|
1010
|
-
return x !== 0 || 1 / x === 1 / y;
|
|
1011
|
-
} else {
|
|
1012
|
-
// Step 6.a: NaN == NaN
|
|
1013
|
-
return x !== x && y !== y;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
/*eslint-enable no-self-compare*/
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* We use an Error-like object for backward compatibility as people may call
|
|
1020
|
-
* PropTypes directly and inspect their output. However, we don't use real
|
|
1021
|
-
* Errors anymore. We don't inspect their stack anyway, and creating them
|
|
1022
|
-
* is prohibitively expensive if they are created too often, such as what
|
|
1023
|
-
* happens in oneOfType() for any type before the one that matched.
|
|
1024
|
-
*/
|
|
1025
|
-
function PropTypeError(message, data) {
|
|
1026
|
-
this.message = message;
|
|
1027
|
-
this.data = data && typeof data === 'object' ? data: {};
|
|
1028
|
-
this.stack = '';
|
|
1029
|
-
}
|
|
1030
|
-
// Make `instanceof Error` still work for returned errors.
|
|
1031
|
-
PropTypeError.prototype = Error.prototype;
|
|
1032
|
-
|
|
1033
|
-
function createChainableTypeChecker(validate) {
|
|
1034
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1035
|
-
var manualPropTypeCallCache = {};
|
|
1036
|
-
var manualPropTypeWarningCount = 0;
|
|
1037
|
-
}
|
|
1038
|
-
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
|
1039
|
-
componentName = componentName || ANONYMOUS;
|
|
1040
|
-
propFullName = propFullName || propName;
|
|
1041
|
-
|
|
1042
|
-
if (secret !== ReactPropTypesSecret) {
|
|
1043
|
-
if (throwOnDirectAccess) {
|
|
1044
|
-
// New behavior only for users of `prop-types` package
|
|
1045
|
-
var err = new Error(
|
|
1046
|
-
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
|
1047
|
-
'Use `PropTypes.checkPropTypes()` to call them. ' +
|
|
1048
|
-
'Read more at http://fb.me/use-check-prop-types'
|
|
1049
|
-
);
|
|
1050
|
-
err.name = 'Invariant Violation';
|
|
1051
|
-
throw err;
|
|
1052
|
-
} else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
|
|
1053
|
-
// Old behavior for people using React.PropTypes
|
|
1054
|
-
var cacheKey = componentName + ':' + propName;
|
|
1055
|
-
if (
|
|
1056
|
-
!manualPropTypeCallCache[cacheKey] &&
|
|
1057
|
-
// Avoid spamming the console because they are often not actionable except for lib authors
|
|
1058
|
-
manualPropTypeWarningCount < 3
|
|
1059
|
-
) {
|
|
1060
|
-
printWarning(
|
|
1061
|
-
'You are manually calling a React.PropTypes validation ' +
|
|
1062
|
-
'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
|
|
1063
|
-
'and will throw in the standalone `prop-types` package. ' +
|
|
1064
|
-
'You may be seeing this warning due to a third-party PropTypes ' +
|
|
1065
|
-
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
|
|
1066
|
-
);
|
|
1067
|
-
manualPropTypeCallCache[cacheKey] = true;
|
|
1068
|
-
manualPropTypeWarningCount++;
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
if (props[propName] == null) {
|
|
1073
|
-
if (isRequired) {
|
|
1074
|
-
if (props[propName] === null) {
|
|
1075
|
-
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
|
1076
|
-
}
|
|
1077
|
-
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
|
1078
|
-
}
|
|
1079
|
-
return null;
|
|
1080
|
-
} else {
|
|
1081
|
-
return validate(props, propName, componentName, location, propFullName);
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
var chainedCheckType = checkType.bind(null, false);
|
|
1086
|
-
chainedCheckType.isRequired = checkType.bind(null, true);
|
|
1087
|
-
|
|
1088
|
-
return chainedCheckType;
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
function createPrimitiveTypeChecker(expectedType) {
|
|
1092
|
-
function validate(props, propName, componentName, location, propFullName, secret) {
|
|
1093
|
-
var propValue = props[propName];
|
|
1094
|
-
var propType = getPropType(propValue);
|
|
1095
|
-
if (propType !== expectedType) {
|
|
1096
|
-
// `propValue` being instance of, say, date/regexp, pass the 'object'
|
|
1097
|
-
// check, but we can offer a more precise error message here rather than
|
|
1098
|
-
// 'of type `object`'.
|
|
1099
|
-
var preciseType = getPreciseType(propValue);
|
|
1100
|
-
|
|
1101
|
-
return new PropTypeError(
|
|
1102
|
-
'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'),
|
|
1103
|
-
{expectedType: expectedType}
|
|
1104
|
-
);
|
|
1105
|
-
}
|
|
1106
|
-
return null;
|
|
1107
|
-
}
|
|
1108
|
-
return createChainableTypeChecker(validate);
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
function createAnyTypeChecker() {
|
|
1112
|
-
return createChainableTypeChecker(emptyFunctionThatReturnsNull);
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
function createArrayOfTypeChecker(typeChecker) {
|
|
1116
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1117
|
-
if (typeof typeChecker !== 'function') {
|
|
1118
|
-
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
|
1119
|
-
}
|
|
1120
|
-
var propValue = props[propName];
|
|
1121
|
-
if (!Array.isArray(propValue)) {
|
|
1122
|
-
var propType = getPropType(propValue);
|
|
1123
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
1124
|
-
}
|
|
1125
|
-
for (var i = 0; i < propValue.length; i++) {
|
|
1126
|
-
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
|
|
1127
|
-
if (error instanceof Error) {
|
|
1128
|
-
return error;
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
return null;
|
|
1132
|
-
}
|
|
1133
|
-
return createChainableTypeChecker(validate);
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
function createElementTypeChecker() {
|
|
1137
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1138
|
-
var propValue = props[propName];
|
|
1139
|
-
if (!isValidElement(propValue)) {
|
|
1140
|
-
var propType = getPropType(propValue);
|
|
1141
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
|
1142
|
-
}
|
|
1143
|
-
return null;
|
|
1144
|
-
}
|
|
1145
|
-
return createChainableTypeChecker(validate);
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
function createElementTypeTypeChecker() {
|
|
1149
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1150
|
-
var propValue = props[propName];
|
|
1151
|
-
if (!ReactIs.isValidElementType(propValue)) {
|
|
1152
|
-
var propType = getPropType(propValue);
|
|
1153
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
|
|
1154
|
-
}
|
|
1155
|
-
return null;
|
|
1156
|
-
}
|
|
1157
|
-
return createChainableTypeChecker(validate);
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
function createInstanceTypeChecker(expectedClass) {
|
|
1161
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1162
|
-
if (!(props[propName] instanceof expectedClass)) {
|
|
1163
|
-
var expectedClassName = expectedClass.name || ANONYMOUS;
|
|
1164
|
-
var actualClassName = getClassName(props[propName]);
|
|
1165
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
|
1166
|
-
}
|
|
1167
|
-
return null;
|
|
1168
|
-
}
|
|
1169
|
-
return createChainableTypeChecker(validate);
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
function createEnumTypeChecker(expectedValues) {
|
|
1173
|
-
if (!Array.isArray(expectedValues)) {
|
|
1174
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1175
|
-
if (arguments.length > 1) {
|
|
1176
|
-
printWarning(
|
|
1177
|
-
'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
|
|
1178
|
-
'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
|
|
1179
|
-
);
|
|
1180
|
-
} else {
|
|
1181
|
-
printWarning('Invalid argument supplied to oneOf, expected an array.');
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
return emptyFunctionThatReturnsNull;
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1188
|
-
var propValue = props[propName];
|
|
1189
|
-
for (var i = 0; i < expectedValues.length; i++) {
|
|
1190
|
-
if (is(propValue, expectedValues[i])) {
|
|
1191
|
-
return null;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
|
|
1196
|
-
var type = getPreciseType(value);
|
|
1197
|
-
if (type === 'symbol') {
|
|
1198
|
-
return String(value);
|
|
1199
|
-
}
|
|
1200
|
-
return value;
|
|
1201
|
-
});
|
|
1202
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
|
1203
|
-
}
|
|
1204
|
-
return createChainableTypeChecker(validate);
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
function createObjectOfTypeChecker(typeChecker) {
|
|
1208
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1209
|
-
if (typeof typeChecker !== 'function') {
|
|
1210
|
-
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
|
1211
|
-
}
|
|
1212
|
-
var propValue = props[propName];
|
|
1213
|
-
var propType = getPropType(propValue);
|
|
1214
|
-
if (propType !== 'object') {
|
|
1215
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
1216
|
-
}
|
|
1217
|
-
for (var key in propValue) {
|
|
1218
|
-
if (has(propValue, key)) {
|
|
1219
|
-
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
|
1220
|
-
if (error instanceof Error) {
|
|
1221
|
-
return error;
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
return null;
|
|
1226
|
-
}
|
|
1227
|
-
return createChainableTypeChecker(validate);
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
1231
|
-
if (!Array.isArray(arrayOfTypeCheckers)) {
|
|
1232
|
-
process.env.NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
|
|
1233
|
-
return emptyFunctionThatReturnsNull;
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
1237
|
-
var checker = arrayOfTypeCheckers[i];
|
|
1238
|
-
if (typeof checker !== 'function') {
|
|
1239
|
-
printWarning(
|
|
1240
|
-
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
|
|
1241
|
-
'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
|
|
1242
|
-
);
|
|
1243
|
-
return emptyFunctionThatReturnsNull;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1248
|
-
var expectedTypes = [];
|
|
1249
|
-
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
1250
|
-
var checker = arrayOfTypeCheckers[i];
|
|
1251
|
-
var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret);
|
|
1252
|
-
if (checkerResult == null) {
|
|
1253
|
-
return null;
|
|
1254
|
-
}
|
|
1255
|
-
if (checkerResult.data && has(checkerResult.data, 'expectedType')) {
|
|
1256
|
-
expectedTypes.push(checkerResult.data.expectedType);
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': '';
|
|
1260
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.'));
|
|
1261
|
-
}
|
|
1262
|
-
return createChainableTypeChecker(validate);
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
function createNodeChecker() {
|
|
1266
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1267
|
-
if (!isNode(props[propName])) {
|
|
1268
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
1269
|
-
}
|
|
1270
|
-
return null;
|
|
1271
|
-
}
|
|
1272
|
-
return createChainableTypeChecker(validate);
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
function invalidValidatorError(componentName, location, propFullName, key, type) {
|
|
1276
|
-
return new PropTypeError(
|
|
1277
|
-
(componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' +
|
|
1278
|
-
'it must be a function, usually from the `prop-types` package, but received `' + type + '`.'
|
|
1279
|
-
);
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
function createShapeTypeChecker(shapeTypes) {
|
|
1283
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1284
|
-
var propValue = props[propName];
|
|
1285
|
-
var propType = getPropType(propValue);
|
|
1286
|
-
if (propType !== 'object') {
|
|
1287
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
1288
|
-
}
|
|
1289
|
-
for (var key in shapeTypes) {
|
|
1290
|
-
var checker = shapeTypes[key];
|
|
1291
|
-
if (typeof checker !== 'function') {
|
|
1292
|
-
return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
|
|
1293
|
-
}
|
|
1294
|
-
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
|
1295
|
-
if (error) {
|
|
1296
|
-
return error;
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
return createChainableTypeChecker(validate);
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
function createStrictShapeTypeChecker(shapeTypes) {
|
|
1305
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
1306
|
-
var propValue = props[propName];
|
|
1307
|
-
var propType = getPropType(propValue);
|
|
1308
|
-
if (propType !== 'object') {
|
|
1309
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
1310
|
-
}
|
|
1311
|
-
// We need to check all keys in case some are required but missing from props.
|
|
1312
|
-
var allKeys = assign({}, props[propName], shapeTypes);
|
|
1313
|
-
for (var key in allKeys) {
|
|
1314
|
-
var checker = shapeTypes[key];
|
|
1315
|
-
if (has(shapeTypes, key) && typeof checker !== 'function') {
|
|
1316
|
-
return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
|
|
1317
|
-
}
|
|
1318
|
-
if (!checker) {
|
|
1319
|
-
return new PropTypeError(
|
|
1320
|
-
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
|
|
1321
|
-
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
|
|
1322
|
-
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
|
|
1323
|
-
);
|
|
1324
|
-
}
|
|
1325
|
-
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
|
1326
|
-
if (error) {
|
|
1327
|
-
return error;
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
return null;
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
return createChainableTypeChecker(validate);
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
function isNode(propValue) {
|
|
1337
|
-
switch (typeof propValue) {
|
|
1338
|
-
case 'number':
|
|
1339
|
-
case 'string':
|
|
1340
|
-
case 'undefined':
|
|
1341
|
-
return true;
|
|
1342
|
-
case 'boolean':
|
|
1343
|
-
return !propValue;
|
|
1344
|
-
case 'object':
|
|
1345
|
-
if (Array.isArray(propValue)) {
|
|
1346
|
-
return propValue.every(isNode);
|
|
1347
|
-
}
|
|
1348
|
-
if (propValue === null || isValidElement(propValue)) {
|
|
1349
|
-
return true;
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
var iteratorFn = getIteratorFn(propValue);
|
|
1353
|
-
if (iteratorFn) {
|
|
1354
|
-
var iterator = iteratorFn.call(propValue);
|
|
1355
|
-
var step;
|
|
1356
|
-
if (iteratorFn !== propValue.entries) {
|
|
1357
|
-
while (!(step = iterator.next()).done) {
|
|
1358
|
-
if (!isNode(step.value)) {
|
|
1359
|
-
return false;
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
} else {
|
|
1363
|
-
// Iterator will provide entry [k,v] tuples rather than values.
|
|
1364
|
-
while (!(step = iterator.next()).done) {
|
|
1365
|
-
var entry = step.value;
|
|
1366
|
-
if (entry) {
|
|
1367
|
-
if (!isNode(entry[1])) {
|
|
1368
|
-
return false;
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
} else {
|
|
1374
|
-
return false;
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
return true;
|
|
1378
|
-
default:
|
|
1379
|
-
return false;
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
function isSymbol(propType, propValue) {
|
|
1384
|
-
// Native Symbol.
|
|
1385
|
-
if (propType === 'symbol') {
|
|
1386
|
-
return true;
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
// falsy value can't be a Symbol
|
|
1390
|
-
if (!propValue) {
|
|
1391
|
-
return false;
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
|
1395
|
-
if (propValue['@@toStringTag'] === 'Symbol') {
|
|
1396
|
-
return true;
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
// Fallback for non-spec compliant Symbols which are polyfilled.
|
|
1400
|
-
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
|
1401
|
-
return true;
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
return false;
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
// Equivalent of `typeof` but with special handling for array and regexp.
|
|
1408
|
-
function getPropType(propValue) {
|
|
1409
|
-
var propType = typeof propValue;
|
|
1410
|
-
if (Array.isArray(propValue)) {
|
|
1411
|
-
return 'array';
|
|
1412
|
-
}
|
|
1413
|
-
if (propValue instanceof RegExp) {
|
|
1414
|
-
// Old webkits (at least until Android 4.0) return 'function' rather than
|
|
1415
|
-
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
|
1416
|
-
// passes PropTypes.object.
|
|
1417
|
-
return 'object';
|
|
1418
|
-
}
|
|
1419
|
-
if (isSymbol(propType, propValue)) {
|
|
1420
|
-
return 'symbol';
|
|
1421
|
-
}
|
|
1422
|
-
return propType;
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
// This handles more types than `getPropType`. Only used for error messages.
|
|
1426
|
-
// See `createPrimitiveTypeChecker`.
|
|
1427
|
-
function getPreciseType(propValue) {
|
|
1428
|
-
if (typeof propValue === 'undefined' || propValue === null) {
|
|
1429
|
-
return '' + propValue;
|
|
1430
|
-
}
|
|
1431
|
-
var propType = getPropType(propValue);
|
|
1432
|
-
if (propType === 'object') {
|
|
1433
|
-
if (propValue instanceof Date) {
|
|
1434
|
-
return 'date';
|
|
1435
|
-
} else if (propValue instanceof RegExp) {
|
|
1436
|
-
return 'regexp';
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
return propType;
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
// Returns a string that is postfixed to a warning about an invalid type.
|
|
1443
|
-
// For example, "undefined" or "of type array"
|
|
1444
|
-
function getPostfixForTypeWarning(value) {
|
|
1445
|
-
var type = getPreciseType(value);
|
|
1446
|
-
switch (type) {
|
|
1447
|
-
case 'array':
|
|
1448
|
-
case 'object':
|
|
1449
|
-
return 'an ' + type;
|
|
1450
|
-
case 'boolean':
|
|
1451
|
-
case 'date':
|
|
1452
|
-
case 'regexp':
|
|
1453
|
-
return 'a ' + type;
|
|
1454
|
-
default:
|
|
1455
|
-
return type;
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
// Returns class name of the object, if any.
|
|
1460
|
-
function getClassName(propValue) {
|
|
1461
|
-
if (!propValue.constructor || !propValue.constructor.name) {
|
|
1462
|
-
return ANONYMOUS;
|
|
1463
|
-
}
|
|
1464
|
-
return propValue.constructor.name;
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
ReactPropTypes.checkPropTypes = checkPropTypes;
|
|
1468
|
-
ReactPropTypes.resetWarningCache = checkPropTypes.resetWarningCache;
|
|
1469
|
-
ReactPropTypes.PropTypes = ReactPropTypes;
|
|
1470
|
-
|
|
1471
|
-
return ReactPropTypes;
|
|
1472
|
-
};
|
|
1473
|
-
return factoryWithTypeCheckers;
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
/**
|
|
1477
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
1478
|
-
*
|
|
1479
|
-
* This source code is licensed under the MIT license found in the
|
|
1480
|
-
* LICENSE file in the root directory of this source tree.
|
|
1481
|
-
*/
|
|
1482
|
-
|
|
1483
|
-
var factoryWithThrowingShims;
|
|
1484
|
-
var hasRequiredFactoryWithThrowingShims;
|
|
1485
|
-
|
|
1486
|
-
function requireFactoryWithThrowingShims () {
|
|
1487
|
-
if (hasRequiredFactoryWithThrowingShims) return factoryWithThrowingShims;
|
|
1488
|
-
hasRequiredFactoryWithThrowingShims = 1;
|
|
1489
|
-
|
|
1490
|
-
var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
|
|
1491
|
-
|
|
1492
|
-
function emptyFunction() {}
|
|
1493
|
-
function emptyFunctionWithReset() {}
|
|
1494
|
-
emptyFunctionWithReset.resetWarningCache = emptyFunction;
|
|
1495
|
-
|
|
1496
|
-
factoryWithThrowingShims = function() {
|
|
1497
|
-
function shim(props, propName, componentName, location, propFullName, secret) {
|
|
1498
|
-
if (secret === ReactPropTypesSecret) {
|
|
1499
|
-
// It is still safe when called from React.
|
|
1500
|
-
return;
|
|
1501
|
-
}
|
|
1502
|
-
var err = new Error(
|
|
1503
|
-
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
|
1504
|
-
'Use PropTypes.checkPropTypes() to call them. ' +
|
|
1505
|
-
'Read more at http://fb.me/use-check-prop-types'
|
|
1506
|
-
);
|
|
1507
|
-
err.name = 'Invariant Violation';
|
|
1508
|
-
throw err;
|
|
1509
|
-
} shim.isRequired = shim;
|
|
1510
|
-
function getShim() {
|
|
1511
|
-
return shim;
|
|
1512
|
-
} // Important!
|
|
1513
|
-
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
|
|
1514
|
-
var ReactPropTypes = {
|
|
1515
|
-
array: shim,
|
|
1516
|
-
bigint: shim,
|
|
1517
|
-
bool: shim,
|
|
1518
|
-
func: shim,
|
|
1519
|
-
number: shim,
|
|
1520
|
-
object: shim,
|
|
1521
|
-
string: shim,
|
|
1522
|
-
symbol: shim,
|
|
1523
|
-
|
|
1524
|
-
any: shim,
|
|
1525
|
-
arrayOf: getShim,
|
|
1526
|
-
element: shim,
|
|
1527
|
-
elementType: shim,
|
|
1528
|
-
instanceOf: getShim,
|
|
1529
|
-
node: shim,
|
|
1530
|
-
objectOf: getShim,
|
|
1531
|
-
oneOf: getShim,
|
|
1532
|
-
oneOfType: getShim,
|
|
1533
|
-
shape: getShim,
|
|
1534
|
-
exact: getShim,
|
|
1535
|
-
|
|
1536
|
-
checkPropTypes: emptyFunctionWithReset,
|
|
1537
|
-
resetWarningCache: emptyFunction
|
|
1538
|
-
};
|
|
1539
|
-
|
|
1540
|
-
ReactPropTypes.PropTypes = ReactPropTypes;
|
|
1541
|
-
|
|
1542
|
-
return ReactPropTypes;
|
|
1543
|
-
};
|
|
1544
|
-
return factoryWithThrowingShims;
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
/**
|
|
1548
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
1549
|
-
*
|
|
1550
|
-
* This source code is licensed under the MIT license found in the
|
|
1551
|
-
* LICENSE file in the root directory of this source tree.
|
|
1552
|
-
*/
|
|
1553
|
-
|
|
1554
|
-
var hasRequiredPropTypes;
|
|
1555
|
-
|
|
1556
|
-
function requirePropTypes () {
|
|
1557
|
-
if (hasRequiredPropTypes) return propTypes.exports;
|
|
1558
|
-
hasRequiredPropTypes = 1;
|
|
1559
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1560
|
-
var ReactIs = requireReactIs();
|
|
1561
|
-
|
|
1562
|
-
// By explicitly using `prop-types` you are opting into new development behavior.
|
|
1563
|
-
// http://fb.me/prop-types-in-prod
|
|
1564
|
-
var throwOnDirectAccess = true;
|
|
1565
|
-
propTypes.exports = /*@__PURE__*/ requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
|
|
1566
|
-
} else {
|
|
1567
|
-
// By explicitly using `prop-types` you are opting into new production behavior.
|
|
1568
|
-
// http://fb.me/prop-types-in-prod
|
|
1569
|
-
propTypes.exports = /*@__PURE__*/ requireFactoryWithThrowingShims()();
|
|
1570
|
-
}
|
|
1571
|
-
return propTypes.exports;
|
|
1572
|
-
}
|
|
1573
|
-
|
|
1574
|
-
var propTypesExports = /*@__PURE__*/ requirePropTypes();
|
|
1575
|
-
var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
|
|
1576
|
-
|
|
1577
|
-
function ownKeys(object, enumerableOnly) {
|
|
1578
|
-
var keys = Object.keys(object);
|
|
1579
|
-
|
|
1580
|
-
if (Object.getOwnPropertySymbols) {
|
|
1581
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
1582
|
-
|
|
1583
|
-
if (enumerableOnly) {
|
|
1584
|
-
symbols = symbols.filter(function (sym) {
|
|
1585
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
1586
|
-
});
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
keys.push.apply(keys, symbols);
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
return keys;
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
function _objectSpread2(target) {
|
|
1596
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
1597
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
1598
|
-
|
|
1599
|
-
if (i % 2) {
|
|
1600
|
-
ownKeys(Object(source), true).forEach(function (key) {
|
|
1601
|
-
_defineProperty(target, key, source[key]);
|
|
1602
|
-
});
|
|
1603
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
1604
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
1605
|
-
} else {
|
|
1606
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
1607
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1608
|
-
});
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
return target;
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
function _typeof(obj) {
|
|
1616
|
-
"@babel/helpers - typeof";
|
|
1617
|
-
|
|
1618
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
1619
|
-
_typeof = function (obj) {
|
|
1620
|
-
return typeof obj;
|
|
1621
|
-
};
|
|
1622
|
-
} else {
|
|
1623
|
-
_typeof = function (obj) {
|
|
1624
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
1625
|
-
};
|
|
1626
|
-
}
|
|
1627
|
-
|
|
1628
|
-
return _typeof(obj);
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
function _defineProperty(obj, key, value) {
|
|
1632
|
-
if (key in obj) {
|
|
1633
|
-
Object.defineProperty(obj, key, {
|
|
1634
|
-
value: value,
|
|
1635
|
-
enumerable: true,
|
|
1636
|
-
configurable: true,
|
|
1637
|
-
writable: true
|
|
1638
|
-
});
|
|
1639
|
-
} else {
|
|
1640
|
-
obj[key] = value;
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
return obj;
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
function _slicedToArray(arr, i) {
|
|
1647
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
function _arrayWithHoles(arr) {
|
|
1651
|
-
if (Array.isArray(arr)) return arr;
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
function _iterableToArrayLimit(arr, i) {
|
|
1655
|
-
var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);
|
|
1656
|
-
|
|
1657
|
-
if (_i == null) return;
|
|
1658
|
-
var _arr = [];
|
|
1659
|
-
var _n = true;
|
|
1660
|
-
var _d = false;
|
|
1661
|
-
|
|
1662
|
-
var _s, _e;
|
|
1663
|
-
|
|
1664
|
-
try {
|
|
1665
|
-
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
1666
|
-
_arr.push(_s.value);
|
|
1667
|
-
|
|
1668
|
-
if (i && _arr.length === i) break;
|
|
1669
|
-
}
|
|
1670
|
-
} catch (err) {
|
|
1671
|
-
_d = true;
|
|
1672
|
-
_e = err;
|
|
1673
|
-
} finally {
|
|
1674
|
-
try {
|
|
1675
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
1676
|
-
} finally {
|
|
1677
|
-
if (_d) throw _e;
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
return _arr;
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
1685
|
-
if (!o) return;
|
|
1686
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
1687
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1688
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1689
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
1690
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
function _arrayLikeToArray(arr, len) {
|
|
1694
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
1695
|
-
|
|
1696
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
1697
|
-
|
|
1698
|
-
return arr2;
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
function _nonIterableRest() {
|
|
1702
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
var useAttachEvent = function useAttachEvent(element, event, cb) {
|
|
1706
|
-
var cbDefined = !!cb;
|
|
1707
|
-
var cbRef = React.useRef(cb); // In many integrations the callback prop changes on each render.
|
|
1708
|
-
// Using a ref saves us from calling element.on/.off every render.
|
|
1709
|
-
|
|
1710
|
-
React.useEffect(function () {
|
|
1711
|
-
cbRef.current = cb;
|
|
1712
|
-
}, [cb]);
|
|
1713
|
-
React.useEffect(function () {
|
|
1714
|
-
if (!cbDefined || !element) {
|
|
1715
|
-
return function () {};
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
var decoratedCb = function decoratedCb() {
|
|
1719
|
-
if (cbRef.current) {
|
|
1720
|
-
cbRef.current.apply(cbRef, arguments);
|
|
1721
|
-
}
|
|
1722
|
-
};
|
|
1723
|
-
|
|
1724
|
-
element.on(event, decoratedCb);
|
|
1725
|
-
return function () {
|
|
1726
|
-
element.off(event, decoratedCb);
|
|
1727
|
-
};
|
|
1728
|
-
}, [cbDefined, event, element, cbRef]);
|
|
1729
|
-
};
|
|
1730
|
-
|
|
1731
|
-
var usePrevious = function usePrevious(value) {
|
|
1732
|
-
var ref = React.useRef(value);
|
|
1733
|
-
React.useEffect(function () {
|
|
1734
|
-
ref.current = value;
|
|
1735
|
-
}, [value]);
|
|
1736
|
-
return ref.current;
|
|
1737
|
-
};
|
|
1738
|
-
|
|
1739
|
-
var isUnknownObject = function isUnknownObject(raw) {
|
|
1740
|
-
return raw !== null && _typeof(raw) === 'object';
|
|
1741
|
-
};
|
|
1742
|
-
var isPromise = function isPromise(raw) {
|
|
1743
|
-
return isUnknownObject(raw) && typeof raw.then === 'function';
|
|
1744
|
-
}; // We are using types to enforce the `stripe` prop in this lib,
|
|
1745
|
-
// but in an untyped integration `stripe` could be anything, so we need
|
|
1746
|
-
// to do some sanity validation to prevent type errors.
|
|
1747
|
-
|
|
1748
|
-
var isStripe = function isStripe(raw) {
|
|
1749
|
-
return isUnknownObject(raw) && typeof raw.elements === 'function' && typeof raw.createToken === 'function' && typeof raw.createPaymentMethod === 'function' && typeof raw.confirmCardPayment === 'function';
|
|
1750
|
-
};
|
|
1751
|
-
|
|
1752
|
-
var PLAIN_OBJECT_STR = '[object Object]';
|
|
1753
|
-
var isEqual = function isEqual(left, right) {
|
|
1754
|
-
if (!isUnknownObject(left) || !isUnknownObject(right)) {
|
|
1755
|
-
return left === right;
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
var leftArray = Array.isArray(left);
|
|
1759
|
-
var rightArray = Array.isArray(right);
|
|
1760
|
-
if (leftArray !== rightArray) return false;
|
|
1761
|
-
var leftPlainObject = Object.prototype.toString.call(left) === PLAIN_OBJECT_STR;
|
|
1762
|
-
var rightPlainObject = Object.prototype.toString.call(right) === PLAIN_OBJECT_STR;
|
|
1763
|
-
if (leftPlainObject !== rightPlainObject) return false; // not sure what sort of special object this is (regexp is one option), so
|
|
1764
|
-
// fallback to reference check.
|
|
1765
|
-
|
|
1766
|
-
if (!leftPlainObject && !leftArray) return left === right;
|
|
1767
|
-
var leftKeys = Object.keys(left);
|
|
1768
|
-
var rightKeys = Object.keys(right);
|
|
1769
|
-
if (leftKeys.length !== rightKeys.length) return false;
|
|
1770
|
-
var keySet = {};
|
|
1771
|
-
|
|
1772
|
-
for (var i = 0; i < leftKeys.length; i += 1) {
|
|
1773
|
-
keySet[leftKeys[i]] = true;
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
for (var _i = 0; _i < rightKeys.length; _i += 1) {
|
|
1777
|
-
keySet[rightKeys[_i]] = true;
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
var allKeys = Object.keys(keySet);
|
|
1781
|
-
|
|
1782
|
-
if (allKeys.length !== leftKeys.length) {
|
|
1783
|
-
return false;
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
var l = left;
|
|
1787
|
-
var r = right;
|
|
1788
|
-
|
|
1789
|
-
var pred = function pred(key) {
|
|
1790
|
-
return isEqual(l[key], r[key]);
|
|
1791
|
-
};
|
|
1792
|
-
|
|
1793
|
-
return allKeys.every(pred);
|
|
1794
|
-
};
|
|
1795
|
-
|
|
1796
|
-
var extractAllowedOptionsUpdates = function extractAllowedOptionsUpdates(options, prevOptions, immutableKeys) {
|
|
1797
|
-
if (!isUnknownObject(options)) {
|
|
1798
|
-
return null;
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
return Object.keys(options).reduce(function (newOptions, key) {
|
|
1802
|
-
var isUpdated = !isUnknownObject(prevOptions) || !isEqual(options[key], prevOptions[key]);
|
|
1803
|
-
|
|
1804
|
-
if (immutableKeys.includes(key)) {
|
|
1805
|
-
if (isUpdated) {
|
|
1806
|
-
console.warn("Unsupported prop change: options.".concat(key, " is not a mutable property."));
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
return newOptions;
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
if (!isUpdated) {
|
|
1813
|
-
return newOptions;
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1816
|
-
return _objectSpread2(_objectSpread2({}, newOptions || {}), {}, _defineProperty({}, key, options[key]));
|
|
1817
|
-
}, null);
|
|
1818
|
-
};
|
|
1819
|
-
|
|
1820
|
-
var INVALID_STRIPE_ERROR$2 = '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
|
|
1821
|
-
// integration `stripe` could be anything, so we need to do some sanity
|
|
1822
|
-
// validation to prevent type errors.
|
|
1823
|
-
|
|
1824
|
-
var validateStripe = function validateStripe(maybeStripe) {
|
|
1825
|
-
var errorMsg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INVALID_STRIPE_ERROR$2;
|
|
1826
|
-
|
|
1827
|
-
if (maybeStripe === null || isStripe(maybeStripe)) {
|
|
1828
|
-
return maybeStripe;
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
throw new Error(errorMsg);
|
|
1832
|
-
};
|
|
1833
|
-
|
|
1834
|
-
var parseStripeProp = function parseStripeProp(raw) {
|
|
1835
|
-
var errorMsg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INVALID_STRIPE_ERROR$2;
|
|
1836
|
-
|
|
1837
|
-
if (isPromise(raw)) {
|
|
1838
|
-
return {
|
|
1839
|
-
tag: 'async',
|
|
1840
|
-
stripePromise: Promise.resolve(raw).then(function (result) {
|
|
1841
|
-
return validateStripe(result, errorMsg);
|
|
1842
|
-
})
|
|
1843
|
-
};
|
|
1844
|
-
}
|
|
1845
|
-
|
|
1846
|
-
var stripe = validateStripe(raw, errorMsg);
|
|
1847
|
-
|
|
1848
|
-
if (stripe === null) {
|
|
1849
|
-
return {
|
|
1850
|
-
tag: 'empty'
|
|
1851
|
-
};
|
|
1852
|
-
}
|
|
1853
|
-
|
|
1854
|
-
return {
|
|
1855
|
-
tag: 'sync',
|
|
1856
|
-
stripe: stripe
|
|
1857
|
-
};
|
|
1858
|
-
};
|
|
1859
|
-
|
|
1860
|
-
var registerWithStripeJs = function registerWithStripeJs(stripe) {
|
|
1861
|
-
if (!stripe || !stripe._registerWrapper || !stripe.registerAppInfo) {
|
|
1862
|
-
return;
|
|
1863
|
-
}
|
|
1864
|
-
|
|
1865
|
-
stripe._registerWrapper({
|
|
1866
|
-
name: 'react-stripe-js',
|
|
1867
|
-
version: "3.3.0"
|
|
1868
|
-
});
|
|
1869
|
-
|
|
1870
|
-
stripe.registerAppInfo({
|
|
1871
|
-
name: 'react-stripe-js',
|
|
1872
|
-
version: "3.3.0",
|
|
1873
|
-
url: 'https://stripe.com/docs/stripe-js/react'
|
|
1874
|
-
});
|
|
1875
|
-
};
|
|
1876
|
-
|
|
1877
|
-
var ElementsContext = /*#__PURE__*/React.createContext(null);
|
|
1878
|
-
ElementsContext.displayName = 'ElementsContext';
|
|
1879
|
-
var parseElementsContext = function parseElementsContext(ctx, useCase) {
|
|
1880
|
-
if (!ctx) {
|
|
1881
|
-
throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(useCase, " in an <Elements> provider."));
|
|
1882
|
-
}
|
|
1883
|
-
|
|
1884
|
-
return ctx;
|
|
1885
|
-
};
|
|
1886
|
-
/**
|
|
1887
|
-
* 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.
|
|
1888
|
-
* Render an `Elements` provider at the root of your React app so that it is available everywhere you need it.
|
|
1889
|
-
*
|
|
1890
|
-
* To use the `Elements` provider, call `loadStripe` from `@stripe/stripe-js` with your publishable key.
|
|
1891
|
-
* The `loadStripe` function will asynchronously load the Stripe.js script and initialize a `Stripe` object.
|
|
1892
|
-
* Pass the returned `Promise` to `Elements`.
|
|
1893
|
-
*
|
|
1894
|
-
* @docs https://stripe.com/docs/stripe-js/react#elements-provider
|
|
1895
|
-
*/
|
|
1896
|
-
|
|
1897
|
-
var Elements = function Elements(_ref) {
|
|
1898
|
-
var rawStripeProp = _ref.stripe,
|
|
1899
|
-
options = _ref.options,
|
|
1900
|
-
children = _ref.children;
|
|
1901
|
-
var parsed = React.useMemo(function () {
|
|
1902
|
-
return parseStripeProp(rawStripeProp);
|
|
1903
|
-
}, [rawStripeProp]); // For a sync stripe instance, initialize into context
|
|
1904
|
-
|
|
1905
|
-
var _React$useState = React.useState(function () {
|
|
1906
|
-
return {
|
|
1907
|
-
stripe: parsed.tag === 'sync' ? parsed.stripe : null,
|
|
1908
|
-
elements: parsed.tag === 'sync' ? parsed.stripe.elements(options) : null
|
|
1909
|
-
};
|
|
1910
|
-
}),
|
|
1911
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
1912
|
-
ctx = _React$useState2[0],
|
|
1913
|
-
setContext = _React$useState2[1];
|
|
1914
|
-
|
|
1915
|
-
React.useEffect(function () {
|
|
1916
|
-
var isMounted = true;
|
|
1917
|
-
|
|
1918
|
-
var safeSetContext = function safeSetContext(stripe) {
|
|
1919
|
-
setContext(function (ctx) {
|
|
1920
|
-
// no-op if we already have a stripe instance (https://github.com/stripe/react-stripe-js/issues/296)
|
|
1921
|
-
if (ctx.stripe) return ctx;
|
|
1922
|
-
return {
|
|
1923
|
-
stripe: stripe,
|
|
1924
|
-
elements: stripe.elements(options)
|
|
1925
|
-
};
|
|
1926
|
-
});
|
|
1927
|
-
}; // For an async stripePromise, store it in context once resolved
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
if (parsed.tag === 'async' && !ctx.stripe) {
|
|
1931
|
-
parsed.stripePromise.then(function (stripe) {
|
|
1932
|
-
if (stripe && isMounted) {
|
|
1933
|
-
// Only update Elements context if the component is still mounted
|
|
1934
|
-
// and stripe is not null. We allow stripe to be null to make
|
|
1935
|
-
// handling SSR easier.
|
|
1936
|
-
safeSetContext(stripe);
|
|
1937
|
-
}
|
|
1938
|
-
});
|
|
1939
|
-
} else if (parsed.tag === 'sync' && !ctx.stripe) {
|
|
1940
|
-
// Or, handle a sync stripe instance going from null -> populated
|
|
1941
|
-
safeSetContext(parsed.stripe);
|
|
1942
|
-
}
|
|
1943
|
-
|
|
1944
|
-
return function () {
|
|
1945
|
-
isMounted = false;
|
|
1946
|
-
};
|
|
1947
|
-
}, [parsed, ctx, options]); // Warn on changes to stripe prop
|
|
1948
|
-
|
|
1949
|
-
var prevStripe = usePrevious(rawStripeProp);
|
|
1950
|
-
React.useEffect(function () {
|
|
1951
|
-
if (prevStripe !== null && prevStripe !== rawStripeProp) {
|
|
1952
|
-
console.warn('Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.');
|
|
1953
|
-
}
|
|
1954
|
-
}, [prevStripe, rawStripeProp]); // Apply updates to elements when options prop has relevant changes
|
|
1955
|
-
|
|
1956
|
-
var prevOptions = usePrevious(options);
|
|
1957
|
-
React.useEffect(function () {
|
|
1958
|
-
if (!ctx.elements) {
|
|
1959
|
-
return;
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
var updates = extractAllowedOptionsUpdates(options, prevOptions, ['clientSecret', 'fonts']);
|
|
1963
|
-
|
|
1964
|
-
if (updates) {
|
|
1965
|
-
ctx.elements.update(updates);
|
|
1966
|
-
}
|
|
1967
|
-
}, [options, prevOptions, ctx.elements]); // Attach react-stripe-js version to stripe.js instance
|
|
1968
|
-
|
|
1969
|
-
React.useEffect(function () {
|
|
1970
|
-
registerWithStripeJs(ctx.stripe);
|
|
1971
|
-
}, [ctx.stripe]);
|
|
1972
|
-
return /*#__PURE__*/React.createElement(ElementsContext.Provider, {
|
|
1973
|
-
value: ctx
|
|
1974
|
-
}, children);
|
|
1975
|
-
};
|
|
1976
|
-
Elements.propTypes = {
|
|
1977
|
-
stripe: PropTypes.any,
|
|
1978
|
-
options: PropTypes.object
|
|
1979
|
-
};
|
|
1980
|
-
var useElementsContextWithUseCase = function useElementsContextWithUseCase(useCaseMessage) {
|
|
1981
|
-
var ctx = React.useContext(ElementsContext);
|
|
1982
|
-
return parseElementsContext(ctx, useCaseMessage);
|
|
1983
|
-
};
|
|
1984
|
-
/**
|
|
1985
|
-
* @docs https://stripe.com/docs/stripe-js/react#useelements-hook
|
|
1986
|
-
*/
|
|
1987
|
-
|
|
1988
|
-
var useElements = function useElements() {
|
|
1989
|
-
var _useElementsContextWi = useElementsContextWithUseCase('calls useElements()'),
|
|
1990
|
-
elements = _useElementsContextWi.elements;
|
|
1991
|
-
|
|
1992
|
-
return elements;
|
|
1993
|
-
};
|
|
1994
|
-
({
|
|
1995
|
-
children: PropTypes.func.isRequired
|
|
1996
|
-
});
|
|
1997
|
-
var CheckoutSdkContext = /*#__PURE__*/React.createContext(null);
|
|
1998
|
-
CheckoutSdkContext.displayName = 'CheckoutSdkContext';
|
|
1999
|
-
var parseCheckoutSdkContext = function parseCheckoutSdkContext(ctx, useCase) {
|
|
2000
|
-
if (!ctx) {
|
|
2001
|
-
throw new Error("Could not find CheckoutProvider context; You need to wrap the part of your app that ".concat(useCase, " in an <CheckoutProvider> provider."));
|
|
2002
|
-
}
|
|
2003
|
-
|
|
2004
|
-
return ctx;
|
|
2005
|
-
};
|
|
2006
|
-
var CheckoutContext = /*#__PURE__*/React.createContext(null);
|
|
2007
|
-
CheckoutContext.displayName = 'CheckoutContext';
|
|
2008
|
-
({
|
|
2009
|
-
stripe: PropTypes.any,
|
|
2010
|
-
options: PropTypes.shape({
|
|
2011
|
-
clientSecret: PropTypes.string.isRequired,
|
|
2012
|
-
elementsOptions: PropTypes.object
|
|
2013
|
-
}).isRequired
|
|
2014
|
-
});
|
|
2015
|
-
var useElementsOrCheckoutSdkContextWithUseCase = function useElementsOrCheckoutSdkContextWithUseCase(useCaseString) {
|
|
2016
|
-
var checkoutSdkContext = React.useContext(CheckoutSdkContext);
|
|
2017
|
-
var elementsContext = React.useContext(ElementsContext);
|
|
2018
|
-
|
|
2019
|
-
if (checkoutSdkContext && elementsContext) {
|
|
2020
|
-
throw new Error("You cannot wrap the part of your app that ".concat(useCaseString, " in both <CheckoutProvider> and <Elements> providers."));
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
if (checkoutSdkContext) {
|
|
2024
|
-
return parseCheckoutSdkContext(checkoutSdkContext, useCaseString);
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
return parseElementsContext(elementsContext, useCaseString);
|
|
2028
|
-
};
|
|
2029
|
-
|
|
2030
|
-
var capitalized = function capitalized(str) {
|
|
2031
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
2032
|
-
};
|
|
2033
|
-
|
|
2034
|
-
var createElementComponent = function createElementComponent(type, isServer) {
|
|
2035
|
-
var displayName = "".concat(capitalized(type), "Element");
|
|
2036
|
-
|
|
2037
|
-
var ClientElement = function ClientElement(_ref) {
|
|
2038
|
-
var id = _ref.id,
|
|
2039
|
-
className = _ref.className,
|
|
2040
|
-
_ref$options = _ref.options,
|
|
2041
|
-
options = _ref$options === void 0 ? {} : _ref$options,
|
|
2042
|
-
onBlur = _ref.onBlur,
|
|
2043
|
-
onFocus = _ref.onFocus,
|
|
2044
|
-
onReady = _ref.onReady,
|
|
2045
|
-
onChange = _ref.onChange,
|
|
2046
|
-
onEscape = _ref.onEscape,
|
|
2047
|
-
onClick = _ref.onClick,
|
|
2048
|
-
onLoadError = _ref.onLoadError,
|
|
2049
|
-
onLoaderStart = _ref.onLoaderStart,
|
|
2050
|
-
onNetworksChange = _ref.onNetworksChange,
|
|
2051
|
-
onConfirm = _ref.onConfirm,
|
|
2052
|
-
onCancel = _ref.onCancel,
|
|
2053
|
-
onShippingAddressChange = _ref.onShippingAddressChange,
|
|
2054
|
-
onShippingRateChange = _ref.onShippingRateChange;
|
|
2055
|
-
var ctx = useElementsOrCheckoutSdkContextWithUseCase("mounts <".concat(displayName, ">"));
|
|
2056
|
-
var elements = 'elements' in ctx ? ctx.elements : null;
|
|
2057
|
-
var checkoutSdk = 'checkoutSdk' in ctx ? ctx.checkoutSdk : null;
|
|
2058
|
-
|
|
2059
|
-
var _React$useState = React.useState(null),
|
|
2060
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
2061
|
-
element = _React$useState2[0],
|
|
2062
|
-
setElement = _React$useState2[1];
|
|
2063
|
-
|
|
2064
|
-
var elementRef = React.useRef(null);
|
|
2065
|
-
var domNode = React.useRef(null); // For every event where the merchant provides a callback, call element.on
|
|
2066
|
-
// with that callback. If the merchant ever changes the callback, removes
|
|
2067
|
-
// the old callback with element.off and then call element.on with the new one.
|
|
2068
|
-
|
|
2069
|
-
useAttachEvent(element, 'blur', onBlur);
|
|
2070
|
-
useAttachEvent(element, 'focus', onFocus);
|
|
2071
|
-
useAttachEvent(element, 'escape', onEscape);
|
|
2072
|
-
useAttachEvent(element, 'click', onClick);
|
|
2073
|
-
useAttachEvent(element, 'loaderror', onLoadError);
|
|
2074
|
-
useAttachEvent(element, 'loaderstart', onLoaderStart);
|
|
2075
|
-
useAttachEvent(element, 'networkschange', onNetworksChange);
|
|
2076
|
-
useAttachEvent(element, 'confirm', onConfirm);
|
|
2077
|
-
useAttachEvent(element, 'cancel', onCancel);
|
|
2078
|
-
useAttachEvent(element, 'shippingaddresschange', onShippingAddressChange);
|
|
2079
|
-
useAttachEvent(element, 'shippingratechange', onShippingRateChange);
|
|
2080
|
-
useAttachEvent(element, 'change', onChange);
|
|
2081
|
-
var readyCallback;
|
|
2082
|
-
|
|
2083
|
-
if (onReady) {
|
|
2084
|
-
if (type === 'expressCheckout') {
|
|
2085
|
-
// Passes through the event, which includes visible PM types
|
|
2086
|
-
readyCallback = onReady;
|
|
2087
|
-
} else {
|
|
2088
|
-
// For other Elements, pass through the Element itself.
|
|
2089
|
-
readyCallback = function readyCallback() {
|
|
2090
|
-
onReady(element);
|
|
2091
|
-
};
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
|
-
useAttachEvent(element, 'ready', readyCallback);
|
|
2096
|
-
React.useLayoutEffect(function () {
|
|
2097
|
-
if (elementRef.current === null && domNode.current !== null && (elements || checkoutSdk)) {
|
|
2098
|
-
var newElement = null;
|
|
2099
|
-
|
|
2100
|
-
if (checkoutSdk) {
|
|
2101
|
-
newElement = checkoutSdk.createElement(type, options);
|
|
2102
|
-
} else if (elements) {
|
|
2103
|
-
newElement = elements.create(type, options);
|
|
2104
|
-
} // Store element in a ref to ensure it's _immediately_ available in cleanup hooks in StrictMode
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
elementRef.current = newElement; // Store element in state to facilitate event listener attachment
|
|
2108
|
-
|
|
2109
|
-
setElement(newElement);
|
|
2110
|
-
|
|
2111
|
-
if (newElement) {
|
|
2112
|
-
newElement.mount(domNode.current);
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
}, [elements, checkoutSdk, options]);
|
|
2116
|
-
var prevOptions = usePrevious(options);
|
|
2117
|
-
React.useEffect(function () {
|
|
2118
|
-
if (!elementRef.current) {
|
|
2119
|
-
return;
|
|
2120
|
-
}
|
|
2121
|
-
|
|
2122
|
-
var updates = extractAllowedOptionsUpdates(options, prevOptions, ['paymentRequest']);
|
|
2123
|
-
|
|
2124
|
-
if (updates && 'update' in elementRef.current) {
|
|
2125
|
-
elementRef.current.update(updates);
|
|
2126
|
-
}
|
|
2127
|
-
}, [options, prevOptions]);
|
|
2128
|
-
React.useLayoutEffect(function () {
|
|
2129
|
-
return function () {
|
|
2130
|
-
if (elementRef.current && typeof elementRef.current.destroy === 'function') {
|
|
2131
|
-
try {
|
|
2132
|
-
elementRef.current.destroy();
|
|
2133
|
-
elementRef.current = null;
|
|
2134
|
-
} catch (error) {// Do nothing
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
};
|
|
2138
|
-
}, []);
|
|
2139
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
2140
|
-
id: id,
|
|
2141
|
-
className: className,
|
|
2142
|
-
ref: domNode
|
|
2143
|
-
});
|
|
2144
|
-
}; // Only render the Element wrapper in a server environment.
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
var ServerElement = function ServerElement(props) {
|
|
2148
|
-
useElementsOrCheckoutSdkContextWithUseCase("mounts <".concat(displayName, ">"));
|
|
2149
|
-
var id = props.id,
|
|
2150
|
-
className = props.className;
|
|
2151
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
2152
|
-
id: id,
|
|
2153
|
-
className: className
|
|
2154
|
-
});
|
|
2155
|
-
};
|
|
2156
|
-
|
|
2157
|
-
var Element = isServer ? ServerElement : ClientElement;
|
|
2158
|
-
Element.propTypes = {
|
|
2159
|
-
id: PropTypes.string,
|
|
2160
|
-
className: PropTypes.string,
|
|
2161
|
-
onChange: PropTypes.func,
|
|
2162
|
-
onBlur: PropTypes.func,
|
|
2163
|
-
onFocus: PropTypes.func,
|
|
2164
|
-
onReady: PropTypes.func,
|
|
2165
|
-
onEscape: PropTypes.func,
|
|
2166
|
-
onClick: PropTypes.func,
|
|
2167
|
-
onLoadError: PropTypes.func,
|
|
2168
|
-
onLoaderStart: PropTypes.func,
|
|
2169
|
-
onNetworksChange: PropTypes.func,
|
|
2170
|
-
onConfirm: PropTypes.func,
|
|
2171
|
-
onCancel: PropTypes.func,
|
|
2172
|
-
onShippingAddressChange: PropTypes.func,
|
|
2173
|
-
onShippingRateChange: PropTypes.func,
|
|
2174
|
-
options: PropTypes.object
|
|
2175
|
-
};
|
|
2176
|
-
Element.displayName = displayName;
|
|
2177
|
-
Element.__elementType = type;
|
|
2178
|
-
return Element;
|
|
2179
|
-
};
|
|
2180
|
-
|
|
2181
|
-
var isServer = typeof window === 'undefined';
|
|
2182
|
-
|
|
2183
|
-
var EmbeddedCheckoutContext = /*#__PURE__*/React.createContext(null);
|
|
2184
|
-
EmbeddedCheckoutContext.displayName = 'EmbeddedCheckoutProviderContext';
|
|
2185
|
-
|
|
2186
|
-
/**
|
|
2187
|
-
* @docs https://stripe.com/docs/stripe-js/react#usestripe-hook
|
|
2188
|
-
*/
|
|
2189
|
-
|
|
2190
|
-
var useStripe = function useStripe() {
|
|
2191
|
-
var _useElementsOrCheckou = useElementsOrCheckoutSdkContextWithUseCase('calls useStripe()'),
|
|
2192
|
-
stripe = _useElementsOrCheckou.stripe;
|
|
2193
|
-
|
|
2194
|
-
return stripe;
|
|
2195
|
-
};
|
|
2196
|
-
|
|
2197
|
-
/**
|
|
2198
|
-
* Requires beta access:
|
|
2199
|
-
* Contact [Stripe support](https://support.stripe.com/) for more information.
|
|
2200
|
-
*
|
|
2201
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2202
|
-
*/
|
|
2203
|
-
|
|
2204
|
-
createElementComponent('auBankAccount', isServer);
|
|
2205
|
-
/**
|
|
2206
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2207
|
-
*/
|
|
2208
|
-
|
|
2209
|
-
createElementComponent('card', isServer);
|
|
2210
|
-
/**
|
|
2211
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2212
|
-
*/
|
|
2213
|
-
|
|
2214
|
-
createElementComponent('cardNumber', isServer);
|
|
2215
|
-
/**
|
|
2216
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2217
|
-
*/
|
|
2218
|
-
|
|
2219
|
-
createElementComponent('cardExpiry', isServer);
|
|
2220
|
-
/**
|
|
2221
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2222
|
-
*/
|
|
2223
|
-
|
|
2224
|
-
createElementComponent('cardCvc', isServer);
|
|
2225
|
-
/**
|
|
2226
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2227
|
-
*/
|
|
2228
|
-
|
|
2229
|
-
createElementComponent('fpxBank', isServer);
|
|
2230
|
-
/**
|
|
2231
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2232
|
-
*/
|
|
2233
|
-
|
|
2234
|
-
createElementComponent('iban', isServer);
|
|
2235
|
-
/**
|
|
2236
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2237
|
-
*/
|
|
2238
|
-
|
|
2239
|
-
createElementComponent('idealBank', isServer);
|
|
2240
|
-
/**
|
|
2241
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2242
|
-
*/
|
|
2243
|
-
|
|
2244
|
-
createElementComponent('p24Bank', isServer);
|
|
2245
|
-
/**
|
|
2246
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2247
|
-
*/
|
|
2248
|
-
|
|
2249
|
-
createElementComponent('epsBank', isServer);
|
|
2250
|
-
var PaymentElement$1 = createElementComponent('payment', isServer);
|
|
2251
|
-
/**
|
|
2252
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2253
|
-
*/
|
|
2254
|
-
|
|
2255
|
-
createElementComponent('expressCheckout', isServer);
|
|
2256
|
-
/**
|
|
2257
|
-
* Requires beta access:
|
|
2258
|
-
* Contact [Stripe support](https://support.stripe.com/) for more information.
|
|
2259
|
-
*/
|
|
2260
|
-
|
|
2261
|
-
createElementComponent('currencySelector', isServer);
|
|
2262
|
-
/**
|
|
2263
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2264
|
-
*/
|
|
2265
|
-
|
|
2266
|
-
createElementComponent('paymentRequestButton', isServer);
|
|
2267
|
-
/**
|
|
2268
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2269
|
-
*/
|
|
2270
|
-
|
|
2271
|
-
createElementComponent('linkAuthentication', isServer);
|
|
2272
|
-
/**
|
|
2273
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2274
|
-
*/
|
|
2275
|
-
|
|
2276
|
-
createElementComponent('address', isServer);
|
|
2277
|
-
/**
|
|
2278
|
-
* @deprecated
|
|
2279
|
-
* Use `AddressElement` instead.
|
|
2280
|
-
*
|
|
2281
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2282
|
-
*/
|
|
2283
|
-
|
|
2284
|
-
createElementComponent('shippingAddress', isServer);
|
|
2285
|
-
/**
|
|
2286
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2287
|
-
*/
|
|
2288
|
-
|
|
2289
|
-
createElementComponent('paymentMethodMessaging', isServer);
|
|
2290
|
-
/**
|
|
2291
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2292
|
-
*/
|
|
2293
|
-
|
|
2294
|
-
createElementComponent('affirmMessage', isServer);
|
|
2295
|
-
/**
|
|
2296
|
-
* @docs https://stripe.com/docs/stripe-js/react#element-components
|
|
2297
|
-
*/
|
|
2298
|
-
|
|
2299
|
-
createElementComponent('afterpayClearpayMessage', isServer);
|
|
2300
|
-
|
|
2301
|
-
var RELEASE_TRAIN = 'v3';
|
|
2302
|
-
|
|
2303
|
-
var runtimeVersionToUrlVersion = function runtimeVersionToUrlVersion(version) {
|
|
2304
|
-
return version === 3 ? 'v3' : version;
|
|
2305
|
-
};
|
|
2306
|
-
|
|
2307
|
-
var ORIGIN = 'https://js.stripe.com';
|
|
2308
|
-
var STRIPE_JS_URL = "".concat(ORIGIN, "/v3") ;
|
|
2309
|
-
var V3_URL_REGEX = /^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;
|
|
2310
|
-
var STRIPE_JS_URL_REGEX = /^https:\/\/js\.stripe\.com\/(v3|[a-z]+)\/stripe\.js(\?.*)?$/;
|
|
2311
|
-
var EXISTING_SCRIPT_MESSAGE = 'loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used';
|
|
2312
|
-
|
|
2313
|
-
var isStripeJSURL = function isStripeJSURL(url) {
|
|
2314
|
-
return V3_URL_REGEX.test(url) || STRIPE_JS_URL_REGEX.test(url);
|
|
2315
|
-
};
|
|
2316
|
-
|
|
2317
|
-
var findScript = function findScript() {
|
|
2318
|
-
var scripts = document.querySelectorAll("script[src^=\"".concat(ORIGIN, "\"]"));
|
|
2319
|
-
|
|
2320
|
-
for (var i = 0; i < scripts.length; i++) {
|
|
2321
|
-
var script = scripts[i];
|
|
2322
|
-
|
|
2323
|
-
if (!isStripeJSURL(script.src)) {
|
|
2324
|
-
continue;
|
|
2325
|
-
}
|
|
2326
|
-
|
|
2327
|
-
return script;
|
|
2328
|
-
}
|
|
2329
|
-
|
|
2330
|
-
return null;
|
|
2331
|
-
};
|
|
2332
|
-
|
|
2333
|
-
var injectScript = function injectScript(params) {
|
|
2334
|
-
var queryString = '';
|
|
2335
|
-
var script = document.createElement('script');
|
|
2336
|
-
script.src = "".concat(STRIPE_JS_URL).concat(queryString);
|
|
2337
|
-
var headOrBody = document.head || document.body;
|
|
2338
|
-
|
|
2339
|
-
if (!headOrBody) {
|
|
2340
|
-
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.');
|
|
2341
|
-
}
|
|
2342
|
-
|
|
2343
|
-
headOrBody.appendChild(script);
|
|
2344
|
-
return script;
|
|
2345
|
-
};
|
|
2346
|
-
|
|
2347
|
-
var registerWrapper = function registerWrapper(stripe, startTime) {
|
|
2348
|
-
if (!stripe || !stripe._registerWrapper) {
|
|
2349
|
-
return;
|
|
2350
|
-
}
|
|
2351
|
-
|
|
2352
|
-
stripe._registerWrapper({
|
|
2353
|
-
name: 'stripe-js',
|
|
2354
|
-
version: "5.10.0",
|
|
2355
|
-
startTime: startTime
|
|
2356
|
-
});
|
|
2357
|
-
};
|
|
2358
|
-
|
|
2359
|
-
var stripePromise$1 = null;
|
|
2360
|
-
var onErrorListener = null;
|
|
2361
|
-
var onLoadListener = null;
|
|
2362
|
-
|
|
2363
|
-
var onError = function onError(reject) {
|
|
2364
|
-
return function (cause) {
|
|
2365
|
-
reject(new Error('Failed to load Stripe.js', {
|
|
2366
|
-
cause: cause
|
|
2367
|
-
}));
|
|
2368
|
-
};
|
|
2369
|
-
};
|
|
2370
|
-
|
|
2371
|
-
var onLoad = function onLoad(resolve, reject) {
|
|
2372
|
-
return function () {
|
|
2373
|
-
if (window.Stripe) {
|
|
2374
|
-
resolve(window.Stripe);
|
|
2375
|
-
} else {
|
|
2376
|
-
reject(new Error('Stripe.js not available'));
|
|
2377
|
-
}
|
|
2378
|
-
};
|
|
2379
|
-
};
|
|
2380
|
-
|
|
2381
|
-
var loadScript = function loadScript(params) {
|
|
2382
|
-
// Ensure that we only attempt to load Stripe.js at most once
|
|
2383
|
-
if (stripePromise$1 !== null) {
|
|
2384
|
-
return stripePromise$1;
|
|
2385
|
-
}
|
|
2386
|
-
|
|
2387
|
-
stripePromise$1 = new Promise(function (resolve, reject) {
|
|
2388
|
-
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
2389
|
-
// Resolve to null when imported server side. This makes the module
|
|
2390
|
-
// safe to import in an isomorphic code base.
|
|
2391
|
-
resolve(null);
|
|
2392
|
-
return;
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
|
-
if (window.Stripe) {
|
|
2396
|
-
resolve(window.Stripe);
|
|
2397
|
-
return;
|
|
2398
|
-
}
|
|
2399
|
-
|
|
2400
|
-
try {
|
|
2401
|
-
var script = findScript();
|
|
2402
|
-
|
|
2403
|
-
if (script && params) ; else if (!script) {
|
|
2404
|
-
script = injectScript(params);
|
|
2405
|
-
} else if (script && onLoadListener !== null && onErrorListener !== null) {
|
|
2406
|
-
var _script$parentNode;
|
|
2407
|
-
|
|
2408
|
-
// remove event listeners
|
|
2409
|
-
script.removeEventListener('load', onLoadListener);
|
|
2410
|
-
script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
|
|
2411
|
-
// reload script to trigger 'load' event
|
|
2412
|
-
|
|
2413
|
-
(_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
|
|
2414
|
-
script = injectScript(params);
|
|
2415
|
-
}
|
|
2416
|
-
|
|
2417
|
-
onLoadListener = onLoad(resolve, reject);
|
|
2418
|
-
onErrorListener = onError(reject);
|
|
2419
|
-
script.addEventListener('load', onLoadListener);
|
|
2420
|
-
script.addEventListener('error', onErrorListener);
|
|
2421
|
-
} catch (error) {
|
|
2422
|
-
reject(error);
|
|
2423
|
-
return;
|
|
2424
|
-
}
|
|
2425
|
-
}); // Resets stripePromise on error
|
|
2426
|
-
|
|
2427
|
-
return stripePromise$1["catch"](function (error) {
|
|
2428
|
-
stripePromise$1 = null;
|
|
2429
|
-
return Promise.reject(error);
|
|
2430
|
-
});
|
|
2431
|
-
};
|
|
2432
|
-
var initStripe = function initStripe(maybeStripe, args, startTime) {
|
|
2433
|
-
if (maybeStripe === null) {
|
|
2434
|
-
return null;
|
|
2435
|
-
}
|
|
2436
|
-
|
|
2437
|
-
var pk = args[0];
|
|
2438
|
-
var isTestKey = pk.match(/^pk_test/); // @ts-expect-error this is not publicly typed
|
|
2439
|
-
|
|
2440
|
-
var version = runtimeVersionToUrlVersion(maybeStripe.version);
|
|
2441
|
-
var expectedVersion = RELEASE_TRAIN;
|
|
2442
|
-
|
|
2443
|
-
if (isTestKey && version !== expectedVersion) {
|
|
2444
|
-
console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("5.10.0", " expected Stripe.js@").concat(expectedVersion, ". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));
|
|
2445
|
-
}
|
|
2446
|
-
|
|
2447
|
-
var stripe = maybeStripe.apply(undefined, args);
|
|
2448
|
-
registerWrapper(stripe, startTime);
|
|
2449
|
-
return stripe;
|
|
2450
|
-
}; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
2451
|
-
|
|
2452
|
-
var stripePromise$2;
|
|
2453
|
-
var loadCalled = false;
|
|
2454
|
-
|
|
2455
|
-
var getStripePromise = function getStripePromise() {
|
|
2456
|
-
if (stripePromise$2) {
|
|
2457
|
-
return stripePromise$2;
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
stripePromise$2 = loadScript(null)["catch"](function (error) {
|
|
2461
|
-
// clear cache on error
|
|
2462
|
-
stripePromise$2 = null;
|
|
2463
|
-
return Promise.reject(error);
|
|
2464
|
-
});
|
|
2465
|
-
return stripePromise$2;
|
|
2466
|
-
}; // Execute our own script injection after a tick to give users time to do their
|
|
2467
|
-
// own script injection.
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
Promise.resolve().then(function () {
|
|
2471
|
-
return getStripePromise();
|
|
2472
|
-
})["catch"](function (error) {
|
|
2473
|
-
if (!loadCalled) {
|
|
2474
|
-
console.warn(error);
|
|
2475
|
-
}
|
|
2476
|
-
});
|
|
2477
|
-
var loadStripe = function loadStripe() {
|
|
2478
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2479
|
-
args[_key] = arguments[_key];
|
|
2480
|
-
}
|
|
2481
|
-
|
|
2482
|
-
loadCalled = true;
|
|
2483
|
-
var startTime = Date.now(); // if previous attempts are unsuccessful, will re-load script
|
|
2484
|
-
|
|
2485
|
-
return getStripePromise().then(function (maybeStripe) {
|
|
2486
|
-
return initStripe(maybeStripe, args, startTime);
|
|
2487
|
-
});
|
|
2488
|
-
};
|
|
2489
|
-
|
|
2490
|
-
const useCheckout = create((set) => ({
|
|
351
|
+
const useCheckout = zustand.create((set) => ({
|
|
2491
352
|
isSubmitting: false,
|
|
2492
353
|
setIsSubmitting: (isSubmitting) => set({ isSubmitting }),
|
|
2493
354
|
}));
|
|
2494
355
|
|
|
2495
356
|
const CheckoutForm = ({ onSuccess, onError, children, }) => {
|
|
2496
|
-
const stripe = useStripe();
|
|
2497
|
-
const elements = useElements();
|
|
357
|
+
const stripe = reactStripeJs.useStripe();
|
|
358
|
+
const elements = reactStripeJs.useElements();
|
|
2498
359
|
const { setIsSubmitting } = useCheckout();
|
|
2499
360
|
const [errorMessage, setErrorMessage] = React.useState(undefined);
|
|
2500
361
|
const handleSubmit = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -2522,17 +383,17 @@ const CheckoutForm = ({ onSuccess, onError, children, }) => {
|
|
|
2522
383
|
});
|
|
2523
384
|
return (React.createElement("form", { onSubmit: handleSubmit },
|
|
2524
385
|
React.createElement("div", null,
|
|
2525
|
-
React.createElement(PaymentElement
|
|
386
|
+
React.createElement(reactStripeJs.PaymentElement, null),
|
|
2526
387
|
React.createElement("p", { className: "text-red-500" }, errorMessage)),
|
|
2527
388
|
children));
|
|
2528
389
|
};
|
|
2529
390
|
var CheckoutForm$1 = React.memo(CheckoutForm);
|
|
2530
391
|
|
|
2531
392
|
const publicStripeKey = "pk_test_51OjSZ2JoDmiuDQz4Vub296KIgTCy4y8NJos59h93bq3sLe3veuXnV9XVmvvWDFlt3aEWHY4pOuIXyahEjjKZwezn00qo4U5fQS";
|
|
2532
|
-
const stripePromise = loadStripe(publicStripeKey);
|
|
393
|
+
const stripePromise = stripeJs.loadStripe(publicStripeKey);
|
|
2533
394
|
function PaymentElement({ paymentSecret, checkoutAppearance, onSuccess, onError, children, }) {
|
|
2534
395
|
const options = Object.assign(Object.assign({ locale: "en" }, (checkoutAppearance ? checkoutAppearance : {})), { clientSecret: paymentSecret });
|
|
2535
|
-
return (React.createElement(Elements, { stripe: stripePromise, options: options },
|
|
396
|
+
return (React.createElement(reactStripeJs.Elements, { stripe: stripePromise, options: options },
|
|
2536
397
|
React.createElement(CheckoutForm$1, { onSuccess: onSuccess, onError: onError, children: children })));
|
|
2537
398
|
}
|
|
2538
399
|
var index = React.memo(PaymentElement);
|