@betterstore/react 0.1.7 → 0.1.9

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