@plasmicpkgs/commerce 0.0.1 → 0.0.5
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/README.md +1 -0
- package/dist/api/endpoints/cart.d.ts +4 -0
- package/dist/api/endpoints/catalog/products.d.ts +4 -0
- package/dist/api/index.d.ts +75 -0
- package/dist/api/operations.d.ts +130 -0
- package/dist/api/utils/errors.d.ts +10 -0
- package/dist/api/utils/is-allowed-method.d.ts +3 -0
- package/dist/api/utils/is-allowed-operation.d.ts +6 -0
- package/dist/api/utils/types.d.ts +34 -0
- package/dist/cart/use-add-item.d.ts +5 -6
- package/dist/cart/use-cart.d.ts +5 -6
- package/dist/cart/use-remove-item.d.ts +5 -6
- package/dist/cart/use-update-item.d.ts +5 -6
- package/dist/commerce.cjs.development.js +1933 -0
- package/dist/commerce.cjs.development.js.map +1 -0
- package/dist/commerce.cjs.production.min.js +2 -0
- package/dist/commerce.cjs.production.min.js.map +1 -0
- package/dist/commerce.d.ts +41 -0
- package/dist/commerce.esm.js +1908 -0
- package/dist/commerce.esm.js.map +1 -0
- package/dist/contexts.d.ts +10 -7
- package/dist/index.d.ts +25 -71
- package/dist/index.js +7 -28
- package/dist/product/use-price.d.ts +26 -26
- package/dist/product/use-search.d.ts +6 -6
- package/dist/registerAddToCartButton.d.ts +9 -0
- package/dist/registerProductCollection.d.ts +18 -11
- package/dist/registerProductMedia.d.ts +10 -0
- package/dist/registerProductPrice.d.ts +9 -0
- package/dist/registerProductQuantity.d.ts +11 -0
- package/dist/registerProductTextField.d.ts +10 -0
- package/dist/registerProductVariantPicker.d.ts +9 -0
- package/dist/registerUseCart.d.ts +9 -0
- package/dist/registerable.d.ts +4 -4
- package/dist/site/use-brands.d.ts +5 -0
- package/dist/site/use-categories.d.ts +5 -0
- package/dist/types/cart.d.ts +157 -157
- package/dist/types/checkout.d.ts +57 -57
- package/dist/types/common.d.ts +13 -13
- package/dist/types/customer/address.d.ts +110 -110
- package/dist/types/customer/card.d.ts +113 -113
- package/dist/types/customer/index.d.ts +24 -24
- package/dist/types/index.d.ts +12 -12
- package/dist/types/login.d.ts +27 -27
- package/dist/types/logout.d.ts +17 -17
- package/dist/types/page.d.ts +24 -24
- package/dist/types/product.d.ts +102 -99
- package/dist/types/signup.d.ts +23 -23
- package/dist/types/site.d.ts +41 -17
- package/dist/types/wishlist.d.ts +83 -83
- package/dist/utils/default-fetcher.d.ts +4 -4
- package/dist/utils/define-property.d.ts +21 -21
- package/dist/utils/errors.d.ts +27 -27
- package/dist/utils/get-product-price.d.ts +2 -0
- package/dist/utils/types.d.ts +95 -94
- package/dist/utils/use-data.d.ts +12 -12
- package/dist/utils/use-hook.d.ts +6 -6
- package/package.json +13 -13
- package/dist/auth/use-login.d.ts +0 -6
- package/dist/auth/use-login.js +0 -9
- package/dist/auth/use-logout.d.ts +0 -6
- package/dist/auth/use-logout.js +0 -9
- package/dist/auth/use-signup.d.ts +0 -6
- package/dist/auth/use-signup.js +0 -9
- package/dist/cart/use-add-item.js +0 -9
- package/dist/cart/use-cart.js +0 -18
- package/dist/cart/use-remove-item.js +0 -9
- package/dist/cart/use-update-item.js +0 -9
- package/dist/checkout/use-checkout.d.ts +0 -6
- package/dist/checkout/use-checkout.js +0 -18
- package/dist/checkout/use-submit-checkout.d.ts +0 -6
- package/dist/checkout/use-submit-checkout.js +0 -9
- package/dist/contexts.js +0 -46
- package/dist/customer/address/use-add-item.d.ts +0 -6
- package/dist/customer/address/use-add-item.js +0 -9
- package/dist/customer/address/use-addresses.d.ts +0 -6
- package/dist/customer/address/use-addresses.js +0 -18
- package/dist/customer/address/use-remove-item.d.ts +0 -6
- package/dist/customer/address/use-remove-item.js +0 -9
- package/dist/customer/address/use-update-item.d.ts +0 -6
- package/dist/customer/address/use-update-item.js +0 -9
- package/dist/customer/card/use-add-item.d.ts +0 -6
- package/dist/customer/card/use-add-item.js +0 -9
- package/dist/customer/card/use-cards.d.ts +0 -6
- package/dist/customer/card/use-cards.js +0 -18
- package/dist/customer/card/use-remove-item.d.ts +0 -6
- package/dist/customer/card/use-remove-item.js +0 -9
- package/dist/customer/card/use-update-item.d.ts +0 -6
- package/dist/customer/card/use-update-item.js +0 -9
- package/dist/customer/use-customer.d.ts +0 -6
- package/dist/customer/use-customer.js +0 -9
- package/dist/product/use-price.js +0 -33
- package/dist/product/use-search.js +0 -9
- package/dist/registerProductCollection.js +0 -42
- package/dist/registerProductImage.d.ts +0 -13
- package/dist/registerProductImage.js +0 -37
- package/dist/registerable.js +0 -0
- package/dist/tsconfig.tsbuildinfo +0 -2970
- package/dist/types/cart.js +0 -0
- package/dist/types/checkout.js +0 -0
- package/dist/types/common.js +0 -0
- package/dist/types/customer/address.js +0 -0
- package/dist/types/customer/card.js +0 -0
- package/dist/types/customer/index.js +0 -2
- package/dist/types/index.js +0 -11
- package/dist/types/login.js +0 -0
- package/dist/types/logout.js +0 -0
- package/dist/types/page.js +0 -0
- package/dist/types/product.js +0 -0
- package/dist/types/signup.js +0 -0
- package/dist/types/site.js +0 -0
- package/dist/types/wishlist.js +0 -0
- package/dist/utils/default-fetcher.js +0 -3
- package/dist/utils/define-property.js +0 -4
- package/dist/utils/errors.js +0 -24
- package/dist/utils/types.js +0 -0
- package/dist/utils/use-data.js +0 -43
- package/dist/utils/use-hook.js +0 -37
|
@@ -0,0 +1,1908 @@
|
|
|
1
|
+
import registerComponent from '@plasmicapp/host/registerComponent';
|
|
2
|
+
import React, { useContext, useRef, useMemo, createContext, useCallback } from 'react';
|
|
3
|
+
import { useForm, FormProvider, useFormContext, Controller } from 'react-hook-form';
|
|
4
|
+
import useSWR from 'swr';
|
|
5
|
+
import { repeatedElement } from '@plasmicapp/host';
|
|
6
|
+
import Cookies from 'js-cookie';
|
|
7
|
+
|
|
8
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
9
|
+
try {
|
|
10
|
+
var info = gen[key](arg);
|
|
11
|
+
var value = info.value;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
reject(error);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _asyncToGenerator(fn) {
|
|
25
|
+
return function () {
|
|
26
|
+
var self = this,
|
|
27
|
+
args = arguments;
|
|
28
|
+
return new Promise(function (resolve, reject) {
|
|
29
|
+
var gen = fn.apply(self, args);
|
|
30
|
+
|
|
31
|
+
function _next(value) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function _throw(err) {
|
|
36
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_next(undefined);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _extends() {
|
|
45
|
+
_extends = Object.assign || function (target) {
|
|
46
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
47
|
+
var source = arguments[i];
|
|
48
|
+
|
|
49
|
+
for (var key in source) {
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
51
|
+
target[key] = source[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return target;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return _extends.apply(this, arguments);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _inheritsLoose(subClass, superClass) {
|
|
63
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
64
|
+
subClass.prototype.constructor = subClass;
|
|
65
|
+
|
|
66
|
+
_setPrototypeOf(subClass, superClass);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function _getPrototypeOf(o) {
|
|
70
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
71
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
72
|
+
};
|
|
73
|
+
return _getPrototypeOf(o);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function _setPrototypeOf(o, p) {
|
|
77
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
78
|
+
o.__proto__ = p;
|
|
79
|
+
return o;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return _setPrototypeOf(o, p);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function _isNativeReflectConstruct() {
|
|
86
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
87
|
+
if (Reflect.construct.sham) return false;
|
|
88
|
+
if (typeof Proxy === "function") return true;
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
92
|
+
return true;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function _construct(Parent, args, Class) {
|
|
99
|
+
if (_isNativeReflectConstruct()) {
|
|
100
|
+
_construct = Reflect.construct;
|
|
101
|
+
} else {
|
|
102
|
+
_construct = function _construct(Parent, args, Class) {
|
|
103
|
+
var a = [null];
|
|
104
|
+
a.push.apply(a, args);
|
|
105
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
106
|
+
var instance = new Constructor();
|
|
107
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
108
|
+
return instance;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return _construct.apply(null, arguments);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function _isNativeFunction(fn) {
|
|
116
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function _wrapNativeSuper(Class) {
|
|
120
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
121
|
+
|
|
122
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
123
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
124
|
+
|
|
125
|
+
if (typeof Class !== "function") {
|
|
126
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (typeof _cache !== "undefined") {
|
|
130
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
131
|
+
|
|
132
|
+
_cache.set(Class, Wrapper);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function Wrapper() {
|
|
136
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
140
|
+
constructor: {
|
|
141
|
+
value: Wrapper,
|
|
142
|
+
enumerable: false,
|
|
143
|
+
writable: true,
|
|
144
|
+
configurable: true
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return _wrapNativeSuper(Class);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
154
|
+
if (source == null) return {};
|
|
155
|
+
var target = {};
|
|
156
|
+
var sourceKeys = Object.keys(source);
|
|
157
|
+
var key, i;
|
|
158
|
+
|
|
159
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
160
|
+
key = sourceKeys[i];
|
|
161
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
162
|
+
target[key] = source[key];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return target;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function createCommonjsModule(fn, module) {
|
|
169
|
+
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var runtime_1 = createCommonjsModule(function (module) {
|
|
173
|
+
/**
|
|
174
|
+
* Copyright (c) 2014-present, Facebook, Inc.
|
|
175
|
+
*
|
|
176
|
+
* This source code is licensed under the MIT license found in the
|
|
177
|
+
* LICENSE file in the root directory of this source tree.
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
var runtime = (function (exports) {
|
|
181
|
+
|
|
182
|
+
var Op = Object.prototype;
|
|
183
|
+
var hasOwn = Op.hasOwnProperty;
|
|
184
|
+
var undefined$1; // More compressible than void 0.
|
|
185
|
+
var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
|
186
|
+
var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
|
187
|
+
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
188
|
+
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
189
|
+
|
|
190
|
+
function define(obj, key, value) {
|
|
191
|
+
Object.defineProperty(obj, key, {
|
|
192
|
+
value: value,
|
|
193
|
+
enumerable: true,
|
|
194
|
+
configurable: true,
|
|
195
|
+
writable: true
|
|
196
|
+
});
|
|
197
|
+
return obj[key];
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
|
|
201
|
+
define({}, "");
|
|
202
|
+
} catch (err) {
|
|
203
|
+
define = function(obj, key, value) {
|
|
204
|
+
return obj[key] = value;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
209
|
+
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
|
|
210
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
|
211
|
+
var generator = Object.create(protoGenerator.prototype);
|
|
212
|
+
var context = new Context(tryLocsList || []);
|
|
213
|
+
|
|
214
|
+
// The ._invoke method unifies the implementations of the .next,
|
|
215
|
+
// .throw, and .return methods.
|
|
216
|
+
generator._invoke = makeInvokeMethod(innerFn, self, context);
|
|
217
|
+
|
|
218
|
+
return generator;
|
|
219
|
+
}
|
|
220
|
+
exports.wrap = wrap;
|
|
221
|
+
|
|
222
|
+
// Try/catch helper to minimize deoptimizations. Returns a completion
|
|
223
|
+
// record like context.tryEntries[i].completion. This interface could
|
|
224
|
+
// have been (and was previously) designed to take a closure to be
|
|
225
|
+
// invoked without arguments, but in all the cases we care about we
|
|
226
|
+
// already have an existing method we want to call, so there's no need
|
|
227
|
+
// to create a new function object. We can even get away with assuming
|
|
228
|
+
// the method takes exactly one argument, since that happens to be true
|
|
229
|
+
// in every case, so we don't have to touch the arguments object. The
|
|
230
|
+
// only additional allocation required is the completion record, which
|
|
231
|
+
// has a stable shape and so hopefully should be cheap to allocate.
|
|
232
|
+
function tryCatch(fn, obj, arg) {
|
|
233
|
+
try {
|
|
234
|
+
return { type: "normal", arg: fn.call(obj, arg) };
|
|
235
|
+
} catch (err) {
|
|
236
|
+
return { type: "throw", arg: err };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var GenStateSuspendedStart = "suspendedStart";
|
|
241
|
+
var GenStateSuspendedYield = "suspendedYield";
|
|
242
|
+
var GenStateExecuting = "executing";
|
|
243
|
+
var GenStateCompleted = "completed";
|
|
244
|
+
|
|
245
|
+
// Returning this object from the innerFn has the same effect as
|
|
246
|
+
// breaking out of the dispatch switch statement.
|
|
247
|
+
var ContinueSentinel = {};
|
|
248
|
+
|
|
249
|
+
// Dummy constructor functions that we use as the .constructor and
|
|
250
|
+
// .constructor.prototype properties for functions that return Generator
|
|
251
|
+
// objects. For full spec compliance, you may wish to configure your
|
|
252
|
+
// minifier not to mangle the names of these two functions.
|
|
253
|
+
function Generator() {}
|
|
254
|
+
function GeneratorFunction() {}
|
|
255
|
+
function GeneratorFunctionPrototype() {}
|
|
256
|
+
|
|
257
|
+
// This is a polyfill for %IteratorPrototype% for environments that
|
|
258
|
+
// don't natively support it.
|
|
259
|
+
var IteratorPrototype = {};
|
|
260
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
261
|
+
return this;
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
var getProto = Object.getPrototypeOf;
|
|
265
|
+
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
266
|
+
if (NativeIteratorPrototype &&
|
|
267
|
+
NativeIteratorPrototype !== Op &&
|
|
268
|
+
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
269
|
+
// This environment has a native %IteratorPrototype%; use it instead
|
|
270
|
+
// of the polyfill.
|
|
271
|
+
IteratorPrototype = NativeIteratorPrototype;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
var Gp = GeneratorFunctionPrototype.prototype =
|
|
275
|
+
Generator.prototype = Object.create(IteratorPrototype);
|
|
276
|
+
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
277
|
+
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
278
|
+
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
279
|
+
GeneratorFunction.displayName = define(
|
|
280
|
+
GeneratorFunctionPrototype,
|
|
281
|
+
toStringTagSymbol,
|
|
282
|
+
"GeneratorFunction"
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Helper for defining the .next, .throw, and .return methods of the
|
|
286
|
+
// Iterator interface in terms of a single ._invoke method.
|
|
287
|
+
function defineIteratorMethods(prototype) {
|
|
288
|
+
["next", "throw", "return"].forEach(function(method) {
|
|
289
|
+
define(prototype, method, function(arg) {
|
|
290
|
+
return this._invoke(method, arg);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
exports.isGeneratorFunction = function(genFun) {
|
|
296
|
+
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
297
|
+
return ctor
|
|
298
|
+
? ctor === GeneratorFunction ||
|
|
299
|
+
// For the native GeneratorFunction constructor, the best we can
|
|
300
|
+
// do is to check its .name property.
|
|
301
|
+
(ctor.displayName || ctor.name) === "GeneratorFunction"
|
|
302
|
+
: false;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
exports.mark = function(genFun) {
|
|
306
|
+
if (Object.setPrototypeOf) {
|
|
307
|
+
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
308
|
+
} else {
|
|
309
|
+
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
310
|
+
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
311
|
+
}
|
|
312
|
+
genFun.prototype = Object.create(Gp);
|
|
313
|
+
return genFun;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// Within the body of any async function, `await x` is transformed to
|
|
317
|
+
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
|
|
318
|
+
// `hasOwn.call(value, "__await")` to determine if the yielded value is
|
|
319
|
+
// meant to be awaited.
|
|
320
|
+
exports.awrap = function(arg) {
|
|
321
|
+
return { __await: arg };
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
function AsyncIterator(generator, PromiseImpl) {
|
|
325
|
+
function invoke(method, arg, resolve, reject) {
|
|
326
|
+
var record = tryCatch(generator[method], generator, arg);
|
|
327
|
+
if (record.type === "throw") {
|
|
328
|
+
reject(record.arg);
|
|
329
|
+
} else {
|
|
330
|
+
var result = record.arg;
|
|
331
|
+
var value = result.value;
|
|
332
|
+
if (value &&
|
|
333
|
+
typeof value === "object" &&
|
|
334
|
+
hasOwn.call(value, "__await")) {
|
|
335
|
+
return PromiseImpl.resolve(value.__await).then(function(value) {
|
|
336
|
+
invoke("next", value, resolve, reject);
|
|
337
|
+
}, function(err) {
|
|
338
|
+
invoke("throw", err, resolve, reject);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return PromiseImpl.resolve(value).then(function(unwrapped) {
|
|
343
|
+
// When a yielded Promise is resolved, its final value becomes
|
|
344
|
+
// the .value of the Promise<{value,done}> result for the
|
|
345
|
+
// current iteration.
|
|
346
|
+
result.value = unwrapped;
|
|
347
|
+
resolve(result);
|
|
348
|
+
}, function(error) {
|
|
349
|
+
// If a rejected Promise was yielded, throw the rejection back
|
|
350
|
+
// into the async generator function so it can be handled there.
|
|
351
|
+
return invoke("throw", error, resolve, reject);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
var previousPromise;
|
|
357
|
+
|
|
358
|
+
function enqueue(method, arg) {
|
|
359
|
+
function callInvokeWithMethodAndArg() {
|
|
360
|
+
return new PromiseImpl(function(resolve, reject) {
|
|
361
|
+
invoke(method, arg, resolve, reject);
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return previousPromise =
|
|
366
|
+
// If enqueue has been called before, then we want to wait until
|
|
367
|
+
// all previous Promises have been resolved before calling invoke,
|
|
368
|
+
// so that results are always delivered in the correct order. If
|
|
369
|
+
// enqueue has not been called before, then it is important to
|
|
370
|
+
// call invoke immediately, without waiting on a callback to fire,
|
|
371
|
+
// so that the async generator function has the opportunity to do
|
|
372
|
+
// any necessary setup in a predictable way. This predictability
|
|
373
|
+
// is why the Promise constructor synchronously invokes its
|
|
374
|
+
// executor callback, and why async functions synchronously
|
|
375
|
+
// execute code before the first await. Since we implement simple
|
|
376
|
+
// async functions in terms of async generators, it is especially
|
|
377
|
+
// important to get this right, even though it requires care.
|
|
378
|
+
previousPromise ? previousPromise.then(
|
|
379
|
+
callInvokeWithMethodAndArg,
|
|
380
|
+
// Avoid propagating failures to Promises returned by later
|
|
381
|
+
// invocations of the iterator.
|
|
382
|
+
callInvokeWithMethodAndArg
|
|
383
|
+
) : callInvokeWithMethodAndArg();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Define the unified helper method that is used to implement .next,
|
|
387
|
+
// .throw, and .return (see defineIteratorMethods).
|
|
388
|
+
this._invoke = enqueue;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
defineIteratorMethods(AsyncIterator.prototype);
|
|
392
|
+
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
393
|
+
return this;
|
|
394
|
+
});
|
|
395
|
+
exports.AsyncIterator = AsyncIterator;
|
|
396
|
+
|
|
397
|
+
// Note that simple async functions are implemented on top of
|
|
398
|
+
// AsyncIterator objects; they just return a Promise for the value of
|
|
399
|
+
// the final result produced by the iterator.
|
|
400
|
+
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
401
|
+
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
402
|
+
|
|
403
|
+
var iter = new AsyncIterator(
|
|
404
|
+
wrap(innerFn, outerFn, self, tryLocsList),
|
|
405
|
+
PromiseImpl
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
return exports.isGeneratorFunction(outerFn)
|
|
409
|
+
? iter // If outerFn is a generator, return the full iterator.
|
|
410
|
+
: iter.next().then(function(result) {
|
|
411
|
+
return result.done ? result.value : iter.next();
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
function makeInvokeMethod(innerFn, self, context) {
|
|
416
|
+
var state = GenStateSuspendedStart;
|
|
417
|
+
|
|
418
|
+
return function invoke(method, arg) {
|
|
419
|
+
if (state === GenStateExecuting) {
|
|
420
|
+
throw new Error("Generator is already running");
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (state === GenStateCompleted) {
|
|
424
|
+
if (method === "throw") {
|
|
425
|
+
throw arg;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Be forgiving, per 25.3.3.3.3 of the spec:
|
|
429
|
+
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
|
|
430
|
+
return doneResult();
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
context.method = method;
|
|
434
|
+
context.arg = arg;
|
|
435
|
+
|
|
436
|
+
while (true) {
|
|
437
|
+
var delegate = context.delegate;
|
|
438
|
+
if (delegate) {
|
|
439
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
440
|
+
if (delegateResult) {
|
|
441
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
442
|
+
return delegateResult;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (context.method === "next") {
|
|
447
|
+
// Setting context._sent for legacy support of Babel's
|
|
448
|
+
// function.sent implementation.
|
|
449
|
+
context.sent = context._sent = context.arg;
|
|
450
|
+
|
|
451
|
+
} else if (context.method === "throw") {
|
|
452
|
+
if (state === GenStateSuspendedStart) {
|
|
453
|
+
state = GenStateCompleted;
|
|
454
|
+
throw context.arg;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
context.dispatchException(context.arg);
|
|
458
|
+
|
|
459
|
+
} else if (context.method === "return") {
|
|
460
|
+
context.abrupt("return", context.arg);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
state = GenStateExecuting;
|
|
464
|
+
|
|
465
|
+
var record = tryCatch(innerFn, self, context);
|
|
466
|
+
if (record.type === "normal") {
|
|
467
|
+
// If an exception is thrown from innerFn, we leave state ===
|
|
468
|
+
// GenStateExecuting and loop back for another invocation.
|
|
469
|
+
state = context.done
|
|
470
|
+
? GenStateCompleted
|
|
471
|
+
: GenStateSuspendedYield;
|
|
472
|
+
|
|
473
|
+
if (record.arg === ContinueSentinel) {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
value: record.arg,
|
|
479
|
+
done: context.done
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
} else if (record.type === "throw") {
|
|
483
|
+
state = GenStateCompleted;
|
|
484
|
+
// Dispatch the exception by looping back around to the
|
|
485
|
+
// context.dispatchException(context.arg) call above.
|
|
486
|
+
context.method = "throw";
|
|
487
|
+
context.arg = record.arg;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Call delegate.iterator[context.method](context.arg) and handle the
|
|
494
|
+
// result, either by returning a { value, done } result from the
|
|
495
|
+
// delegate iterator, or by modifying context.method and context.arg,
|
|
496
|
+
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
497
|
+
function maybeInvokeDelegate(delegate, context) {
|
|
498
|
+
var method = delegate.iterator[context.method];
|
|
499
|
+
if (method === undefined$1) {
|
|
500
|
+
// A .throw or .return when the delegate iterator has no .throw
|
|
501
|
+
// method always terminates the yield* loop.
|
|
502
|
+
context.delegate = null;
|
|
503
|
+
|
|
504
|
+
if (context.method === "throw") {
|
|
505
|
+
// Note: ["return"] must be used for ES3 parsing compatibility.
|
|
506
|
+
if (delegate.iterator["return"]) {
|
|
507
|
+
// If the delegate iterator has a return method, give it a
|
|
508
|
+
// chance to clean up.
|
|
509
|
+
context.method = "return";
|
|
510
|
+
context.arg = undefined$1;
|
|
511
|
+
maybeInvokeDelegate(delegate, context);
|
|
512
|
+
|
|
513
|
+
if (context.method === "throw") {
|
|
514
|
+
// If maybeInvokeDelegate(context) changed context.method from
|
|
515
|
+
// "return" to "throw", let that override the TypeError below.
|
|
516
|
+
return ContinueSentinel;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
context.method = "throw";
|
|
521
|
+
context.arg = new TypeError(
|
|
522
|
+
"The iterator does not provide a 'throw' method");
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return ContinueSentinel;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
529
|
+
|
|
530
|
+
if (record.type === "throw") {
|
|
531
|
+
context.method = "throw";
|
|
532
|
+
context.arg = record.arg;
|
|
533
|
+
context.delegate = null;
|
|
534
|
+
return ContinueSentinel;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
var info = record.arg;
|
|
538
|
+
|
|
539
|
+
if (! info) {
|
|
540
|
+
context.method = "throw";
|
|
541
|
+
context.arg = new TypeError("iterator result is not an object");
|
|
542
|
+
context.delegate = null;
|
|
543
|
+
return ContinueSentinel;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (info.done) {
|
|
547
|
+
// Assign the result of the finished delegate to the temporary
|
|
548
|
+
// variable specified by delegate.resultName (see delegateYield).
|
|
549
|
+
context[delegate.resultName] = info.value;
|
|
550
|
+
|
|
551
|
+
// Resume execution at the desired location (see delegateYield).
|
|
552
|
+
context.next = delegate.nextLoc;
|
|
553
|
+
|
|
554
|
+
// If context.method was "throw" but the delegate handled the
|
|
555
|
+
// exception, let the outer generator proceed normally. If
|
|
556
|
+
// context.method was "next", forget context.arg since it has been
|
|
557
|
+
// "consumed" by the delegate iterator. If context.method was
|
|
558
|
+
// "return", allow the original .return call to continue in the
|
|
559
|
+
// outer generator.
|
|
560
|
+
if (context.method !== "return") {
|
|
561
|
+
context.method = "next";
|
|
562
|
+
context.arg = undefined$1;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
} else {
|
|
566
|
+
// Re-yield the result returned by the delegate method.
|
|
567
|
+
return info;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// The delegate iterator is finished, so forget it and continue with
|
|
571
|
+
// the outer generator.
|
|
572
|
+
context.delegate = null;
|
|
573
|
+
return ContinueSentinel;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// Define Generator.prototype.{next,throw,return} in terms of the
|
|
577
|
+
// unified ._invoke helper method.
|
|
578
|
+
defineIteratorMethods(Gp);
|
|
579
|
+
|
|
580
|
+
define(Gp, toStringTagSymbol, "Generator");
|
|
581
|
+
|
|
582
|
+
// A Generator should always return itself as the iterator object when the
|
|
583
|
+
// @@iterator function is called on it. Some browsers' implementations of the
|
|
584
|
+
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
585
|
+
// object to not be returned from this call. This ensures that doesn't happen.
|
|
586
|
+
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
587
|
+
define(Gp, iteratorSymbol, function() {
|
|
588
|
+
return this;
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
define(Gp, "toString", function() {
|
|
592
|
+
return "[object Generator]";
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
function pushTryEntry(locs) {
|
|
596
|
+
var entry = { tryLoc: locs[0] };
|
|
597
|
+
|
|
598
|
+
if (1 in locs) {
|
|
599
|
+
entry.catchLoc = locs[1];
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (2 in locs) {
|
|
603
|
+
entry.finallyLoc = locs[2];
|
|
604
|
+
entry.afterLoc = locs[3];
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
this.tryEntries.push(entry);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function resetTryEntry(entry) {
|
|
611
|
+
var record = entry.completion || {};
|
|
612
|
+
record.type = "normal";
|
|
613
|
+
delete record.arg;
|
|
614
|
+
entry.completion = record;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function Context(tryLocsList) {
|
|
618
|
+
// The root entry object (effectively a try statement without a catch
|
|
619
|
+
// or a finally block) gives us a place to store values thrown from
|
|
620
|
+
// locations where there is no enclosing try statement.
|
|
621
|
+
this.tryEntries = [{ tryLoc: "root" }];
|
|
622
|
+
tryLocsList.forEach(pushTryEntry, this);
|
|
623
|
+
this.reset(true);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
exports.keys = function(object) {
|
|
627
|
+
var keys = [];
|
|
628
|
+
for (var key in object) {
|
|
629
|
+
keys.push(key);
|
|
630
|
+
}
|
|
631
|
+
keys.reverse();
|
|
632
|
+
|
|
633
|
+
// Rather than returning an object with a next method, we keep
|
|
634
|
+
// things simple and return the next function itself.
|
|
635
|
+
return function next() {
|
|
636
|
+
while (keys.length) {
|
|
637
|
+
var key = keys.pop();
|
|
638
|
+
if (key in object) {
|
|
639
|
+
next.value = key;
|
|
640
|
+
next.done = false;
|
|
641
|
+
return next;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// To avoid creating an additional object, we just hang the .value
|
|
646
|
+
// and .done properties off the next function object itself. This
|
|
647
|
+
// also ensures that the minifier will not anonymize the function.
|
|
648
|
+
next.done = true;
|
|
649
|
+
return next;
|
|
650
|
+
};
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
function values(iterable) {
|
|
654
|
+
if (iterable) {
|
|
655
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
|
656
|
+
if (iteratorMethod) {
|
|
657
|
+
return iteratorMethod.call(iterable);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (typeof iterable.next === "function") {
|
|
661
|
+
return iterable;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
if (!isNaN(iterable.length)) {
|
|
665
|
+
var i = -1, next = function next() {
|
|
666
|
+
while (++i < iterable.length) {
|
|
667
|
+
if (hasOwn.call(iterable, i)) {
|
|
668
|
+
next.value = iterable[i];
|
|
669
|
+
next.done = false;
|
|
670
|
+
return next;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
next.value = undefined$1;
|
|
675
|
+
next.done = true;
|
|
676
|
+
|
|
677
|
+
return next;
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
return next.next = next;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// Return an iterator with no values.
|
|
685
|
+
return { next: doneResult };
|
|
686
|
+
}
|
|
687
|
+
exports.values = values;
|
|
688
|
+
|
|
689
|
+
function doneResult() {
|
|
690
|
+
return { value: undefined$1, done: true };
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
Context.prototype = {
|
|
694
|
+
constructor: Context,
|
|
695
|
+
|
|
696
|
+
reset: function(skipTempReset) {
|
|
697
|
+
this.prev = 0;
|
|
698
|
+
this.next = 0;
|
|
699
|
+
// Resetting context._sent for legacy support of Babel's
|
|
700
|
+
// function.sent implementation.
|
|
701
|
+
this.sent = this._sent = undefined$1;
|
|
702
|
+
this.done = false;
|
|
703
|
+
this.delegate = null;
|
|
704
|
+
|
|
705
|
+
this.method = "next";
|
|
706
|
+
this.arg = undefined$1;
|
|
707
|
+
|
|
708
|
+
this.tryEntries.forEach(resetTryEntry);
|
|
709
|
+
|
|
710
|
+
if (!skipTempReset) {
|
|
711
|
+
for (var name in this) {
|
|
712
|
+
// Not sure about the optimal order of these conditions:
|
|
713
|
+
if (name.charAt(0) === "t" &&
|
|
714
|
+
hasOwn.call(this, name) &&
|
|
715
|
+
!isNaN(+name.slice(1))) {
|
|
716
|
+
this[name] = undefined$1;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
|
|
722
|
+
stop: function() {
|
|
723
|
+
this.done = true;
|
|
724
|
+
|
|
725
|
+
var rootEntry = this.tryEntries[0];
|
|
726
|
+
var rootRecord = rootEntry.completion;
|
|
727
|
+
if (rootRecord.type === "throw") {
|
|
728
|
+
throw rootRecord.arg;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
return this.rval;
|
|
732
|
+
},
|
|
733
|
+
|
|
734
|
+
dispatchException: function(exception) {
|
|
735
|
+
if (this.done) {
|
|
736
|
+
throw exception;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
var context = this;
|
|
740
|
+
function handle(loc, caught) {
|
|
741
|
+
record.type = "throw";
|
|
742
|
+
record.arg = exception;
|
|
743
|
+
context.next = loc;
|
|
744
|
+
|
|
745
|
+
if (caught) {
|
|
746
|
+
// If the dispatched exception was caught by a catch block,
|
|
747
|
+
// then let that catch block handle the exception normally.
|
|
748
|
+
context.method = "next";
|
|
749
|
+
context.arg = undefined$1;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
return !! caught;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
756
|
+
var entry = this.tryEntries[i];
|
|
757
|
+
var record = entry.completion;
|
|
758
|
+
|
|
759
|
+
if (entry.tryLoc === "root") {
|
|
760
|
+
// Exception thrown outside of any try block that could handle
|
|
761
|
+
// it, so set the completion value of the entire function to
|
|
762
|
+
// throw the exception.
|
|
763
|
+
return handle("end");
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (entry.tryLoc <= this.prev) {
|
|
767
|
+
var hasCatch = hasOwn.call(entry, "catchLoc");
|
|
768
|
+
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
769
|
+
|
|
770
|
+
if (hasCatch && hasFinally) {
|
|
771
|
+
if (this.prev < entry.catchLoc) {
|
|
772
|
+
return handle(entry.catchLoc, true);
|
|
773
|
+
} else if (this.prev < entry.finallyLoc) {
|
|
774
|
+
return handle(entry.finallyLoc);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
} else if (hasCatch) {
|
|
778
|
+
if (this.prev < entry.catchLoc) {
|
|
779
|
+
return handle(entry.catchLoc, true);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
} else if (hasFinally) {
|
|
783
|
+
if (this.prev < entry.finallyLoc) {
|
|
784
|
+
return handle(entry.finallyLoc);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
} else {
|
|
788
|
+
throw new Error("try statement without catch or finally");
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
|
|
794
|
+
abrupt: function(type, arg) {
|
|
795
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
796
|
+
var entry = this.tryEntries[i];
|
|
797
|
+
if (entry.tryLoc <= this.prev &&
|
|
798
|
+
hasOwn.call(entry, "finallyLoc") &&
|
|
799
|
+
this.prev < entry.finallyLoc) {
|
|
800
|
+
var finallyEntry = entry;
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (finallyEntry &&
|
|
806
|
+
(type === "break" ||
|
|
807
|
+
type === "continue") &&
|
|
808
|
+
finallyEntry.tryLoc <= arg &&
|
|
809
|
+
arg <= finallyEntry.finallyLoc) {
|
|
810
|
+
// Ignore the finally entry if control is not jumping to a
|
|
811
|
+
// location outside the try/catch block.
|
|
812
|
+
finallyEntry = null;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
|
816
|
+
record.type = type;
|
|
817
|
+
record.arg = arg;
|
|
818
|
+
|
|
819
|
+
if (finallyEntry) {
|
|
820
|
+
this.method = "next";
|
|
821
|
+
this.next = finallyEntry.finallyLoc;
|
|
822
|
+
return ContinueSentinel;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return this.complete(record);
|
|
826
|
+
},
|
|
827
|
+
|
|
828
|
+
complete: function(record, afterLoc) {
|
|
829
|
+
if (record.type === "throw") {
|
|
830
|
+
throw record.arg;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
if (record.type === "break" ||
|
|
834
|
+
record.type === "continue") {
|
|
835
|
+
this.next = record.arg;
|
|
836
|
+
} else if (record.type === "return") {
|
|
837
|
+
this.rval = this.arg = record.arg;
|
|
838
|
+
this.method = "return";
|
|
839
|
+
this.next = "end";
|
|
840
|
+
} else if (record.type === "normal" && afterLoc) {
|
|
841
|
+
this.next = afterLoc;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
return ContinueSentinel;
|
|
845
|
+
},
|
|
846
|
+
|
|
847
|
+
finish: function(finallyLoc) {
|
|
848
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
849
|
+
var entry = this.tryEntries[i];
|
|
850
|
+
if (entry.finallyLoc === finallyLoc) {
|
|
851
|
+
this.complete(entry.completion, entry.afterLoc);
|
|
852
|
+
resetTryEntry(entry);
|
|
853
|
+
return ContinueSentinel;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
},
|
|
857
|
+
|
|
858
|
+
"catch": function(tryLoc) {
|
|
859
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
860
|
+
var entry = this.tryEntries[i];
|
|
861
|
+
if (entry.tryLoc === tryLoc) {
|
|
862
|
+
var record = entry.completion;
|
|
863
|
+
if (record.type === "throw") {
|
|
864
|
+
var thrown = record.arg;
|
|
865
|
+
resetTryEntry(entry);
|
|
866
|
+
}
|
|
867
|
+
return thrown;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// The context.catch method must only be called with a location
|
|
872
|
+
// argument that corresponds to a known catch block.
|
|
873
|
+
throw new Error("illegal catch attempt");
|
|
874
|
+
},
|
|
875
|
+
|
|
876
|
+
delegateYield: function(iterable, resultName, nextLoc) {
|
|
877
|
+
this.delegate = {
|
|
878
|
+
iterator: values(iterable),
|
|
879
|
+
resultName: resultName,
|
|
880
|
+
nextLoc: nextLoc
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
if (this.method === "next") {
|
|
884
|
+
// Deliberately forget the last sent value so that we don't
|
|
885
|
+
// accidentally pass it on to the delegate.
|
|
886
|
+
this.arg = undefined$1;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
return ContinueSentinel;
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
// Regardless of whether this script is executing as a CommonJS module
|
|
894
|
+
// or not, return the runtime object so that we can declare the variable
|
|
895
|
+
// regeneratorRuntime in the outer scope, which allows this module to be
|
|
896
|
+
// injected easily by `bin/regenerator --include-runtime script.js`.
|
|
897
|
+
return exports;
|
|
898
|
+
|
|
899
|
+
}(
|
|
900
|
+
// If this script is executing as a CommonJS module, use module.exports
|
|
901
|
+
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
902
|
+
// object. Either way, the resulting object will be used to initialize
|
|
903
|
+
// the regeneratorRuntime variable at the top of this file.
|
|
904
|
+
module.exports
|
|
905
|
+
));
|
|
906
|
+
|
|
907
|
+
try {
|
|
908
|
+
regeneratorRuntime = runtime;
|
|
909
|
+
} catch (accidentalStrictMode) {
|
|
910
|
+
// This module should not be running in strict mode, so the above
|
|
911
|
+
// assignment should always work unless something is misconfigured. Just
|
|
912
|
+
// in case runtime.js accidentally runs in strict mode, in modern engines
|
|
913
|
+
// we can explicitly access globalThis. In older engines we can escape
|
|
914
|
+
// strict mode using a global Function call. This could conceivably fail
|
|
915
|
+
// if a Content Security Policy forbids using Function, but in that case
|
|
916
|
+
// the proper solution is to fix the accidental strict mode problem. If
|
|
917
|
+
// you've misconfigured your bundler to force strict mode and applied a
|
|
918
|
+
// CSP to forbid Function, and you're not willing to fix either of those
|
|
919
|
+
// problems, please detail your unique predicament in a GitHub issue.
|
|
920
|
+
if (typeof globalThis === "object") {
|
|
921
|
+
globalThis.regeneratorRuntime = runtime;
|
|
922
|
+
} else {
|
|
923
|
+
Function("r", "regeneratorRuntime = r")(runtime);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
var ProductContext = /*#__PURE__*/React.createContext(undefined);
|
|
929
|
+
function ProductProvider(_ref) {
|
|
930
|
+
var product = _ref.product,
|
|
931
|
+
children = _ref.children;
|
|
932
|
+
var methods = useForm();
|
|
933
|
+
return React.createElement(ProductContext.Provider, {
|
|
934
|
+
value: product,
|
|
935
|
+
key: product.id
|
|
936
|
+
}, React.createElement(FormProvider, Object.assign({}, methods), children));
|
|
937
|
+
}
|
|
938
|
+
function useProduct() {
|
|
939
|
+
return useContext(ProductContext);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
var _excluded = ["children"];
|
|
943
|
+
var Commerce = /*#__PURE__*/createContext({});
|
|
944
|
+
function CoreCommerceProvider(_ref) {
|
|
945
|
+
var provider = _ref.provider,
|
|
946
|
+
children = _ref.children;
|
|
947
|
+
var providerRef = useRef(provider); // TODO: Remove the fetcherRef
|
|
948
|
+
|
|
949
|
+
var fetcherRef = useRef(provider.fetcher); // If the parent re-renders this provider will re-render every
|
|
950
|
+
// consumer unless we memoize the config
|
|
951
|
+
|
|
952
|
+
var _providerRef$current = providerRef.current,
|
|
953
|
+
locale = _providerRef$current.locale,
|
|
954
|
+
cartCookie = _providerRef$current.cartCookie;
|
|
955
|
+
var cfg = useMemo(function () {
|
|
956
|
+
return {
|
|
957
|
+
providerRef: providerRef,
|
|
958
|
+
fetcherRef: fetcherRef,
|
|
959
|
+
locale: locale,
|
|
960
|
+
cartCookie: cartCookie
|
|
961
|
+
};
|
|
962
|
+
}, [locale, cartCookie]);
|
|
963
|
+
return React.createElement(Commerce.Provider, {
|
|
964
|
+
value: cfg
|
|
965
|
+
}, children);
|
|
966
|
+
}
|
|
967
|
+
function getCommerceProvider(provider) {
|
|
968
|
+
return function CommerceProvider(_ref2) {
|
|
969
|
+
var children = _ref2.children,
|
|
970
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
971
|
+
|
|
972
|
+
return React.createElement(CoreCommerceProvider, {
|
|
973
|
+
provider: _extends({}, provider, props)
|
|
974
|
+
}, children);
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
function useCommerce() {
|
|
978
|
+
return useContext(Commerce);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/*
|
|
982
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/commerce/src
|
|
983
|
+
Changes: None
|
|
984
|
+
*/
|
|
985
|
+
// Taken from https://fettblog.eu/typescript-assertion-signatures/
|
|
986
|
+
function defineProperty(obj, prop, val) {
|
|
987
|
+
Object.defineProperty(obj, prop, val);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
var CommerceError = /*#__PURE__*/function (_Error) {
|
|
991
|
+
_inheritsLoose(CommerceError, _Error);
|
|
992
|
+
|
|
993
|
+
function CommerceError(_ref) {
|
|
994
|
+
var _this;
|
|
995
|
+
|
|
996
|
+
var message = _ref.message,
|
|
997
|
+
code = _ref.code,
|
|
998
|
+
errors = _ref.errors;
|
|
999
|
+
var error = message ? _extends({
|
|
1000
|
+
message: message
|
|
1001
|
+
}, code ? {
|
|
1002
|
+
code: code
|
|
1003
|
+
} : {}) : errors[0];
|
|
1004
|
+
_this = _Error.call(this, error.message) || this;
|
|
1005
|
+
_this.errors = message ? [error] : errors;
|
|
1006
|
+
if (error.code) _this.code = error.code;
|
|
1007
|
+
return _this;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
return CommerceError;
|
|
1011
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error)); // Used for errors that come from a bad implementation of the hooks
|
|
1012
|
+
|
|
1013
|
+
var ValidationError = /*#__PURE__*/function (_CommerceError) {
|
|
1014
|
+
_inheritsLoose(ValidationError, _CommerceError);
|
|
1015
|
+
|
|
1016
|
+
function ValidationError(options) {
|
|
1017
|
+
var _this2;
|
|
1018
|
+
|
|
1019
|
+
_this2 = _CommerceError.call(this, options) || this;
|
|
1020
|
+
_this2.code = 'validation_error';
|
|
1021
|
+
return _this2;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
return ValidationError;
|
|
1025
|
+
}(CommerceError);
|
|
1026
|
+
var FetcherError = /*#__PURE__*/function (_CommerceError2) {
|
|
1027
|
+
_inheritsLoose(FetcherError, _CommerceError2);
|
|
1028
|
+
|
|
1029
|
+
function FetcherError(options) {
|
|
1030
|
+
var _this3;
|
|
1031
|
+
|
|
1032
|
+
_this3 = _CommerceError2.call(this, options) || this;
|
|
1033
|
+
_this3.status = options.status;
|
|
1034
|
+
return _this3;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
return FetcherError;
|
|
1038
|
+
}(CommerceError);
|
|
1039
|
+
|
|
1040
|
+
var useData = function useData(options, input, fetcherFn, swrOptions) {
|
|
1041
|
+
var hookInput = Array.isArray(input) ? input : Object.entries(input);
|
|
1042
|
+
|
|
1043
|
+
var fetcher = /*#__PURE__*/function () {
|
|
1044
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(url, query, method) {
|
|
1045
|
+
var _len,
|
|
1046
|
+
args,
|
|
1047
|
+
_key,
|
|
1048
|
+
_args = arguments;
|
|
1049
|
+
|
|
1050
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1051
|
+
while (1) {
|
|
1052
|
+
switch (_context.prev = _context.next) {
|
|
1053
|
+
case 0:
|
|
1054
|
+
_context.prev = 0;
|
|
1055
|
+
|
|
1056
|
+
for (_len = _args.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
1057
|
+
args[_key - 3] = _args[_key];
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
_context.next = 4;
|
|
1061
|
+
return options.fetcher({
|
|
1062
|
+
options: {
|
|
1063
|
+
url: url,
|
|
1064
|
+
query: query,
|
|
1065
|
+
method: method
|
|
1066
|
+
},
|
|
1067
|
+
// Transform the input array into an object
|
|
1068
|
+
input: args.reduce(function (obj, val, i) {
|
|
1069
|
+
obj[hookInput[i][0]] = val;
|
|
1070
|
+
return obj;
|
|
1071
|
+
}, {}),
|
|
1072
|
+
fetch: fetcherFn
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
case 4:
|
|
1076
|
+
return _context.abrupt("return", _context.sent);
|
|
1077
|
+
|
|
1078
|
+
case 7:
|
|
1079
|
+
_context.prev = 7;
|
|
1080
|
+
_context.t0 = _context["catch"](0);
|
|
1081
|
+
|
|
1082
|
+
// SWR will not log errors, but any error that's not an instance
|
|
1083
|
+
// of CommerceError is not welcomed by this hook
|
|
1084
|
+
if (!(_context.t0 instanceof CommerceError)) {
|
|
1085
|
+
console.error(_context.t0);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
throw _context.t0;
|
|
1089
|
+
|
|
1090
|
+
case 11:
|
|
1091
|
+
case "end":
|
|
1092
|
+
return _context.stop();
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}, _callee, null, [[0, 7]]);
|
|
1096
|
+
}));
|
|
1097
|
+
|
|
1098
|
+
return function fetcher(_x, _x2, _x3) {
|
|
1099
|
+
return _ref.apply(this, arguments);
|
|
1100
|
+
};
|
|
1101
|
+
}();
|
|
1102
|
+
|
|
1103
|
+
var response = useSWR(function () {
|
|
1104
|
+
var opts = options.fetchOptions;
|
|
1105
|
+
return opts ? [opts.url, opts.query, opts.method].concat(hookInput.map(function (e) {
|
|
1106
|
+
return e[1];
|
|
1107
|
+
})) : null;
|
|
1108
|
+
}, fetcher, swrOptions);
|
|
1109
|
+
|
|
1110
|
+
if (!('isLoading' in response)) {
|
|
1111
|
+
defineProperty(response, 'isLoading', {
|
|
1112
|
+
get: function get() {
|
|
1113
|
+
return response.data === undefined;
|
|
1114
|
+
},
|
|
1115
|
+
enumerable: true
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
return response;
|
|
1120
|
+
};
|
|
1121
|
+
|
|
1122
|
+
/*
|
|
1123
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/commerce/src
|
|
1124
|
+
Changes: None
|
|
1125
|
+
*/
|
|
1126
|
+
function useFetcher() {
|
|
1127
|
+
var _providerRef$current$;
|
|
1128
|
+
|
|
1129
|
+
var _useCommerce = useCommerce(),
|
|
1130
|
+
providerRef = _useCommerce.providerRef,
|
|
1131
|
+
fetcherRef = _useCommerce.fetcherRef;
|
|
1132
|
+
|
|
1133
|
+
return (_providerRef$current$ = providerRef.current.fetcher) != null ? _providerRef$current$ : fetcherRef.current;
|
|
1134
|
+
}
|
|
1135
|
+
function useHook(fn) {
|
|
1136
|
+
var _useCommerce2 = useCommerce(),
|
|
1137
|
+
providerRef = _useCommerce2.providerRef;
|
|
1138
|
+
|
|
1139
|
+
var provider = providerRef.current;
|
|
1140
|
+
return fn(provider);
|
|
1141
|
+
}
|
|
1142
|
+
function useSWRHook(hook) {
|
|
1143
|
+
var fetcher = useFetcher();
|
|
1144
|
+
return hook.useHook({
|
|
1145
|
+
useData: function useData$1(ctx) {
|
|
1146
|
+
var _ctx$input;
|
|
1147
|
+
|
|
1148
|
+
var response = useData(hook, (_ctx$input = ctx == null ? void 0 : ctx.input) != null ? _ctx$input : [], fetcher, ctx == null ? void 0 : ctx.swrOptions);
|
|
1149
|
+
|
|
1150
|
+
return response;
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
function useMutationHook(hook) {
|
|
1155
|
+
var fetcher = useFetcher();
|
|
1156
|
+
return hook.useHook({
|
|
1157
|
+
fetch: useCallback(function (_temp) {
|
|
1158
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
1159
|
+
input = _ref.input;
|
|
1160
|
+
|
|
1161
|
+
return hook.fetcher({
|
|
1162
|
+
input: input,
|
|
1163
|
+
options: hook.fetchOptions,
|
|
1164
|
+
fetch: fetcher
|
|
1165
|
+
});
|
|
1166
|
+
}, [fetcher, hook.fetchOptions])
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
var SWRFetcher = function SWRFetcher(_ref) {
|
|
1171
|
+
var options = _ref.options,
|
|
1172
|
+
fetch = _ref.fetch;
|
|
1173
|
+
return fetch(options);
|
|
1174
|
+
};
|
|
1175
|
+
var mutationFetcher = function mutationFetcher(_ref2) {
|
|
1176
|
+
var input = _ref2.input,
|
|
1177
|
+
options = _ref2.options,
|
|
1178
|
+
fetch = _ref2.fetch;
|
|
1179
|
+
return fetch(_extends({}, options, {
|
|
1180
|
+
body: input
|
|
1181
|
+
}));
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
var fetcher = mutationFetcher;
|
|
1185
|
+
|
|
1186
|
+
var fn = function fn(provider) {
|
|
1187
|
+
var _provider$cart;
|
|
1188
|
+
|
|
1189
|
+
return (_provider$cart = provider.cart) == null ? void 0 : _provider$cart.useAddItem;
|
|
1190
|
+
};
|
|
1191
|
+
|
|
1192
|
+
var useAddItem = function useAddItem() {
|
|
1193
|
+
var hook = useHook(fn);
|
|
1194
|
+
return useMutationHook(_extends({
|
|
1195
|
+
fetcher: fetcher
|
|
1196
|
+
}, hook)).apply(void 0, arguments);
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
var addToCartButtonMeta = {
|
|
1200
|
+
name: "plasmic-commerce-add-to-cart-button",
|
|
1201
|
+
displayName: "Add To Cart Button",
|
|
1202
|
+
props: {
|
|
1203
|
+
children: {
|
|
1204
|
+
type: "slot",
|
|
1205
|
+
defaultValue: [{
|
|
1206
|
+
type: "button",
|
|
1207
|
+
value: "Add To Cart"
|
|
1208
|
+
}]
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1211
|
+
importPath: "commerce-providers/commerce",
|
|
1212
|
+
importName: "AddToCartButton"
|
|
1213
|
+
};
|
|
1214
|
+
|
|
1215
|
+
function AddToCartButton(props) {
|
|
1216
|
+
var children = props.children;
|
|
1217
|
+
var product = useProduct();
|
|
1218
|
+
var form = useFormContext();
|
|
1219
|
+
var addItem = useAddItem();
|
|
1220
|
+
|
|
1221
|
+
var addToCart = /*#__PURE__*/function () {
|
|
1222
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
1223
|
+
var _form$getValues$Produ;
|
|
1224
|
+
|
|
1225
|
+
var quantity, variantId;
|
|
1226
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1227
|
+
while (1) {
|
|
1228
|
+
switch (_context.prev = _context.next) {
|
|
1229
|
+
case 0:
|
|
1230
|
+
quantity = (_form$getValues$Produ = +form.getValues()["ProductQuantity"]) != null ? _form$getValues$Produ : 1;
|
|
1231
|
+
|
|
1232
|
+
if (!(isNaN(quantity) || quantity < 1)) {
|
|
1233
|
+
_context.next = 3;
|
|
1234
|
+
break;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
throw new CommerceError({
|
|
1238
|
+
message: 'The item quantity has to be a valid integer greater than 0'
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
case 3:
|
|
1242
|
+
if (!product) {
|
|
1243
|
+
_context.next = 7;
|
|
1244
|
+
break;
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
variantId = form.getValues()["ProductVariant"];
|
|
1248
|
+
_context.next = 7;
|
|
1249
|
+
return addItem({
|
|
1250
|
+
productId: product.id,
|
|
1251
|
+
variantId: variantId,
|
|
1252
|
+
quantity: quantity
|
|
1253
|
+
});
|
|
1254
|
+
|
|
1255
|
+
case 7:
|
|
1256
|
+
case "end":
|
|
1257
|
+
return _context.stop();
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}, _callee);
|
|
1261
|
+
}));
|
|
1262
|
+
|
|
1263
|
+
return function addToCart() {
|
|
1264
|
+
return _ref.apply(this, arguments);
|
|
1265
|
+
};
|
|
1266
|
+
}();
|
|
1267
|
+
|
|
1268
|
+
return React.isValidElement(children) ? React.cloneElement(children, {
|
|
1269
|
+
onClick: function onClick(e) {
|
|
1270
|
+
if (children.props.onClick && typeof children.props.onClick === "function") {
|
|
1271
|
+
children.props.onClick(e);
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
addToCart();
|
|
1275
|
+
}
|
|
1276
|
+
}) : null;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
function registerAddToCartButton(loader, customAddToCartButtonMeta) {
|
|
1280
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1281
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1282
|
+
};
|
|
1283
|
+
|
|
1284
|
+
doRegisterComponent(AddToCartButton, customAddToCartButtonMeta != null ? customAddToCartButtonMeta : addToCartButtonMeta);
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
var fetcher$1 = SWRFetcher;
|
|
1288
|
+
|
|
1289
|
+
var fn$1 = function fn(provider) {
|
|
1290
|
+
var _provider$products;
|
|
1291
|
+
|
|
1292
|
+
return (_provider$products = provider.products) == null ? void 0 : _provider$products.useSearch;
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
var useSearch = function useSearch(input) {
|
|
1296
|
+
var hook = useHook(fn$1);
|
|
1297
|
+
return useSWRHook(_extends({
|
|
1298
|
+
fetcher: fetcher$1
|
|
1299
|
+
}, hook))(input);
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
var productCollectionMeta = {
|
|
1303
|
+
name: "plasmic-commerce-product-collection",
|
|
1304
|
+
displayName: "Product Collection",
|
|
1305
|
+
props: {
|
|
1306
|
+
children: {
|
|
1307
|
+
type: "slot",
|
|
1308
|
+
defaultValue: [{
|
|
1309
|
+
type: "vbox",
|
|
1310
|
+
children: [{
|
|
1311
|
+
type: "component",
|
|
1312
|
+
name: "plasmic-commerce-product-text-field",
|
|
1313
|
+
props: {
|
|
1314
|
+
field: "name"
|
|
1315
|
+
}
|
|
1316
|
+
}, {
|
|
1317
|
+
type: "component",
|
|
1318
|
+
name: "plasmic-commerce-product-media"
|
|
1319
|
+
}],
|
|
1320
|
+
styles: {
|
|
1321
|
+
width: "100%",
|
|
1322
|
+
minWidth: 0
|
|
1323
|
+
}
|
|
1324
|
+
}]
|
|
1325
|
+
},
|
|
1326
|
+
count: "number",
|
|
1327
|
+
category: {
|
|
1328
|
+
type: "choice",
|
|
1329
|
+
options: function options(props, ctx) {
|
|
1330
|
+
var _ctx$categories$map;
|
|
1331
|
+
|
|
1332
|
+
return (_ctx$categories$map = ctx == null ? void 0 : ctx.categories.map(function (category) {
|
|
1333
|
+
return {
|
|
1334
|
+
label: category.name,
|
|
1335
|
+
value: category.id
|
|
1336
|
+
};
|
|
1337
|
+
})) != null ? _ctx$categories$map : [];
|
|
1338
|
+
}
|
|
1339
|
+
},
|
|
1340
|
+
brand: {
|
|
1341
|
+
type: "choice",
|
|
1342
|
+
options: function options(props, ctx) {
|
|
1343
|
+
var _ctx$brands$map;
|
|
1344
|
+
|
|
1345
|
+
return (_ctx$brands$map = ctx == null ? void 0 : ctx.brands.map(function (brand) {
|
|
1346
|
+
return {
|
|
1347
|
+
label: brand.name,
|
|
1348
|
+
value: brand.entityId
|
|
1349
|
+
};
|
|
1350
|
+
})) != null ? _ctx$brands$map : [];
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
},
|
|
1354
|
+
defaultStyles: {
|
|
1355
|
+
display: "grid",
|
|
1356
|
+
gridTemplateColumns: "1fr 1fr 1fr 1fr",
|
|
1357
|
+
gridRowGap: "8px",
|
|
1358
|
+
gridColumnGap: "8px",
|
|
1359
|
+
padding: "8px",
|
|
1360
|
+
maxWidth: "100%"
|
|
1361
|
+
},
|
|
1362
|
+
importPath: "commerce-providers/commerce",
|
|
1363
|
+
importName: "ProductCollection"
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
function ProductCollection(props) {
|
|
1367
|
+
var className = props.className,
|
|
1368
|
+
children = props.children,
|
|
1369
|
+
count = props.count,
|
|
1370
|
+
category = props.category,
|
|
1371
|
+
brand = props.brand,
|
|
1372
|
+
setControlContextData = props.setControlContextData;
|
|
1373
|
+
|
|
1374
|
+
var _useSearch = useSearch({
|
|
1375
|
+
categoryId: category,
|
|
1376
|
+
brandId: brand,
|
|
1377
|
+
count: count
|
|
1378
|
+
}),
|
|
1379
|
+
data = _useSearch.data;
|
|
1380
|
+
|
|
1381
|
+
var _useCategories = useCategories({}),
|
|
1382
|
+
categories = _useCategories.data;
|
|
1383
|
+
|
|
1384
|
+
var _useBrands = useBrands({}),
|
|
1385
|
+
brands = _useBrands.data;
|
|
1386
|
+
|
|
1387
|
+
if (categories && brands) {
|
|
1388
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
1389
|
+
categories: categories,
|
|
1390
|
+
brands: brands
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
return React.createElement("div", {
|
|
1395
|
+
className: className
|
|
1396
|
+
}, data == null ? void 0 : data.products.map(function (product, i) {
|
|
1397
|
+
return React.createElement(ProductProvider, {
|
|
1398
|
+
product: product,
|
|
1399
|
+
key: product.id
|
|
1400
|
+
}, repeatedElement(i === 0, children));
|
|
1401
|
+
}));
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
function registerProductCollection(loader, customProductCollectionMeta) {
|
|
1405
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1406
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1407
|
+
};
|
|
1408
|
+
|
|
1409
|
+
doRegisterComponent(ProductCollection, customProductCollectionMeta != null ? customProductCollectionMeta : productCollectionMeta);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
var placeholderImage = "https://static1.plasmic.app/commerce/lightweight-jacket-0.png";
|
|
1413
|
+
var productMediaMeta = {
|
|
1414
|
+
name: "plasmic-commerce-product-media",
|
|
1415
|
+
displayName: "Product Media",
|
|
1416
|
+
props: {
|
|
1417
|
+
mediaIndex: "number"
|
|
1418
|
+
},
|
|
1419
|
+
importPath: "commerce-providers/commerce",
|
|
1420
|
+
importName: "ProductMedia"
|
|
1421
|
+
};
|
|
1422
|
+
function ProductMedia(props) {
|
|
1423
|
+
var _image$url;
|
|
1424
|
+
|
|
1425
|
+
var className = props.className,
|
|
1426
|
+
_props$mediaIndex = props.mediaIndex,
|
|
1427
|
+
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex;
|
|
1428
|
+
var product = useProduct();
|
|
1429
|
+
var image = product == null ? void 0 : product.images[mediaIndex];
|
|
1430
|
+
return React.createElement("img", {
|
|
1431
|
+
alt: (product == null ? void 0 : product.name) || 'Product Image',
|
|
1432
|
+
src: product ? (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "" : placeholderImage,
|
|
1433
|
+
loading: 'lazy',
|
|
1434
|
+
className: className
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
function registerProductMedia(loader, customProductMediaMeta) {
|
|
1438
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1439
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
doRegisterComponent(ProductMedia, customProductMediaMeta != null ? customProductMediaMeta : productMediaMeta);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
/*
|
|
1446
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/commerce/src
|
|
1447
|
+
Changes: None
|
|
1448
|
+
*/
|
|
1449
|
+
function formatPrice(_ref) {
|
|
1450
|
+
var amount = _ref.amount,
|
|
1451
|
+
currencyCode = _ref.currencyCode,
|
|
1452
|
+
locale = _ref.locale;
|
|
1453
|
+
var formatCurrency = new Intl.NumberFormat(locale, {
|
|
1454
|
+
style: 'currency',
|
|
1455
|
+
currency: currencyCode
|
|
1456
|
+
});
|
|
1457
|
+
return formatCurrency.format(amount);
|
|
1458
|
+
}
|
|
1459
|
+
function formatVariantPrice(_ref2) {
|
|
1460
|
+
var amount = _ref2.amount,
|
|
1461
|
+
baseAmount = _ref2.baseAmount,
|
|
1462
|
+
currencyCode = _ref2.currencyCode,
|
|
1463
|
+
locale = _ref2.locale;
|
|
1464
|
+
var hasDiscount = baseAmount > amount;
|
|
1465
|
+
var formatDiscount = new Intl.NumberFormat(locale, {
|
|
1466
|
+
style: 'percent'
|
|
1467
|
+
});
|
|
1468
|
+
var discount = hasDiscount ? formatDiscount.format((baseAmount - amount) / baseAmount) : null;
|
|
1469
|
+
var price = formatPrice({
|
|
1470
|
+
amount: amount,
|
|
1471
|
+
currencyCode: currencyCode,
|
|
1472
|
+
locale: locale
|
|
1473
|
+
});
|
|
1474
|
+
var basePrice = hasDiscount ? formatPrice({
|
|
1475
|
+
amount: baseAmount,
|
|
1476
|
+
currencyCode: currencyCode,
|
|
1477
|
+
locale: locale
|
|
1478
|
+
}) : null;
|
|
1479
|
+
return {
|
|
1480
|
+
price: price,
|
|
1481
|
+
basePrice: basePrice,
|
|
1482
|
+
discount: discount
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
function usePrice(data) {
|
|
1486
|
+
var _ref3 = data != null ? data : {},
|
|
1487
|
+
amount = _ref3.amount,
|
|
1488
|
+
baseAmount = _ref3.baseAmount,
|
|
1489
|
+
currencyCode = _ref3.currencyCode;
|
|
1490
|
+
|
|
1491
|
+
var _useCommerce = useCommerce(),
|
|
1492
|
+
locale = _useCommerce.locale;
|
|
1493
|
+
|
|
1494
|
+
var value = useMemo(function () {
|
|
1495
|
+
if (typeof amount !== 'number' || !currencyCode) return '';
|
|
1496
|
+
return baseAmount ? formatVariantPrice({
|
|
1497
|
+
amount: amount,
|
|
1498
|
+
baseAmount: baseAmount,
|
|
1499
|
+
currencyCode: currencyCode,
|
|
1500
|
+
locale: locale
|
|
1501
|
+
}) : formatPrice({
|
|
1502
|
+
amount: amount,
|
|
1503
|
+
currencyCode: currencyCode,
|
|
1504
|
+
locale: locale
|
|
1505
|
+
});
|
|
1506
|
+
}, [amount, baseAmount, currencyCode]);
|
|
1507
|
+
return typeof value === 'string' ? {
|
|
1508
|
+
price: value
|
|
1509
|
+
} : value;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
var getProductPrice = function getProductPrice(product, variantId) {
|
|
1513
|
+
var _product$variants$fin, _product$variants$fin2;
|
|
1514
|
+
|
|
1515
|
+
return (_product$variants$fin = (_product$variants$fin2 = product.variants.find(function (variant) {
|
|
1516
|
+
return variant.id === variantId;
|
|
1517
|
+
})) == null ? void 0 : _product$variants$fin2.price) != null ? _product$variants$fin : product.price.value;
|
|
1518
|
+
};
|
|
1519
|
+
|
|
1520
|
+
var productPriceMeta = {
|
|
1521
|
+
name: "plasmic-commerce-product-price",
|
|
1522
|
+
displayName: "Product Price",
|
|
1523
|
+
props: {},
|
|
1524
|
+
importPath: "commerce-providers/commerce",
|
|
1525
|
+
importName: "ProductPrice"
|
|
1526
|
+
};
|
|
1527
|
+
function ProductPrice(props) {
|
|
1528
|
+
var className = props.className;
|
|
1529
|
+
var product = useProduct();
|
|
1530
|
+
var form = useFormContext();
|
|
1531
|
+
|
|
1532
|
+
if (!product) {
|
|
1533
|
+
throw new Error("This component must be within a product context.");
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
var watchProductVariant = form.watch("ProductVariant", product == null ? void 0 : product.variants[0].id);
|
|
1537
|
+
|
|
1538
|
+
var _usePrice = usePrice({
|
|
1539
|
+
amount: product ? getProductPrice(product, watchProductVariant) : 0,
|
|
1540
|
+
currencyCode: product ? product.price.currencyCode : 'USD'
|
|
1541
|
+
}),
|
|
1542
|
+
price = _usePrice.price;
|
|
1543
|
+
|
|
1544
|
+
return React.createElement("span", {
|
|
1545
|
+
className: className
|
|
1546
|
+
}, price);
|
|
1547
|
+
}
|
|
1548
|
+
function registerProductPrice(loader, customProductPriceMeta) {
|
|
1549
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1550
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1551
|
+
};
|
|
1552
|
+
|
|
1553
|
+
doRegisterComponent(ProductPrice, customProductPriceMeta != null ? customProductPriceMeta : productPriceMeta);
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
var productQuantityMeta = {
|
|
1557
|
+
name: "plasmic-commerce-product-quantity",
|
|
1558
|
+
displayName: "Product Quantity",
|
|
1559
|
+
props: {
|
|
1560
|
+
children: {
|
|
1561
|
+
type: "slot",
|
|
1562
|
+
defaultValue: [{
|
|
1563
|
+
type: "input",
|
|
1564
|
+
attrs: {
|
|
1565
|
+
value: "1"
|
|
1566
|
+
}
|
|
1567
|
+
}]
|
|
1568
|
+
}
|
|
1569
|
+
},
|
|
1570
|
+
importPath: "commerce-providers/commerce",
|
|
1571
|
+
importName: "ProductQuantity"
|
|
1572
|
+
};
|
|
1573
|
+
function ProductQuantity(props) {
|
|
1574
|
+
var className = props.className,
|
|
1575
|
+
children = props.children;
|
|
1576
|
+
var form = useFormContext();
|
|
1577
|
+
return React.createElement("div", {
|
|
1578
|
+
className: className
|
|
1579
|
+
}, React.createElement(Controller, {
|
|
1580
|
+
name: "ProductQuantity",
|
|
1581
|
+
defaultValue: 1,
|
|
1582
|
+
control: form == null ? void 0 : form.control,
|
|
1583
|
+
render: function render(_ref) {
|
|
1584
|
+
var field = _ref.field;
|
|
1585
|
+
return React.isValidElement(children) ? React.cloneElement(children, _extends({}, children.props, field, {
|
|
1586
|
+
name: "ProductQuantity"
|
|
1587
|
+
})) : React.createElement(React.Fragment, null);
|
|
1588
|
+
}
|
|
1589
|
+
}));
|
|
1590
|
+
}
|
|
1591
|
+
function registerProductQuantity(loader, customProductQuantityMeta) {
|
|
1592
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1593
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1594
|
+
};
|
|
1595
|
+
|
|
1596
|
+
doRegisterComponent(ProductQuantity, customProductQuantityMeta != null ? customProductQuantityMeta : productQuantityMeta);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
var productTextFieldMeta = {
|
|
1600
|
+
name: "plasmic-commerce-product-text-field",
|
|
1601
|
+
displayName: "Product Text Field",
|
|
1602
|
+
props: {
|
|
1603
|
+
field: {
|
|
1604
|
+
type: "choice",
|
|
1605
|
+
options: ["id", "name", "description", "sku", "slug", "path"]
|
|
1606
|
+
}
|
|
1607
|
+
},
|
|
1608
|
+
importPath: "commerce-providers/commerce",
|
|
1609
|
+
importName: "ProductTextField"
|
|
1610
|
+
};
|
|
1611
|
+
function ProductTextField(props) {
|
|
1612
|
+
var className = props.className,
|
|
1613
|
+
field = props.field;
|
|
1614
|
+
var product = useProduct();
|
|
1615
|
+
|
|
1616
|
+
if (!product) {
|
|
1617
|
+
return React.createElement("span", {
|
|
1618
|
+
className: className
|
|
1619
|
+
}, "Fake Product Field");
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
if (!field) {
|
|
1623
|
+
return React.createElement("span", {
|
|
1624
|
+
className: className
|
|
1625
|
+
}, "Unknown Product Field");
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
var value;
|
|
1629
|
+
|
|
1630
|
+
if (field === "description") {
|
|
1631
|
+
return product.descriptionHtml ? React.createElement("div", {
|
|
1632
|
+
className: className,
|
|
1633
|
+
dangerouslySetInnerHTML: {
|
|
1634
|
+
__html: product.descriptionHtml
|
|
1635
|
+
}
|
|
1636
|
+
}) : React.createElement("div", {
|
|
1637
|
+
className: className
|
|
1638
|
+
}, product.description);
|
|
1639
|
+
} else {
|
|
1640
|
+
value = product[field];
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
return React.createElement("span", {
|
|
1644
|
+
className: className
|
|
1645
|
+
}, value);
|
|
1646
|
+
}
|
|
1647
|
+
function registerTextField(loader, customProductTextFieldMeta) {
|
|
1648
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1649
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
doRegisterComponent(ProductTextField, customProductTextFieldMeta != null ? customProductTextFieldMeta : productTextFieldMeta);
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
var productVariantPickerMeta = {
|
|
1656
|
+
name: "plasmic-commerce-product-variant-picker",
|
|
1657
|
+
displayName: "Product Variant Picker",
|
|
1658
|
+
props: {},
|
|
1659
|
+
importPath: "commerce-providers/commerce",
|
|
1660
|
+
importName: "ProductVariantPicker"
|
|
1661
|
+
};
|
|
1662
|
+
function ProductVariantPicker(props) {
|
|
1663
|
+
var className = props.className;
|
|
1664
|
+
var product = useProduct();
|
|
1665
|
+
var form = useFormContext();
|
|
1666
|
+
return React.createElement(Controller, {
|
|
1667
|
+
name: "ProductVariant",
|
|
1668
|
+
control: form == null ? void 0 : form.control,
|
|
1669
|
+
defaultValue: product == null ? void 0 : product.variants[0].id,
|
|
1670
|
+
render: function render(_ref) {
|
|
1671
|
+
var _product$variants$map;
|
|
1672
|
+
|
|
1673
|
+
var field = _ref.field;
|
|
1674
|
+
return React.createElement("select", Object.assign({
|
|
1675
|
+
className: className
|
|
1676
|
+
}, field), (_product$variants$map = product == null ? void 0 : product.variants.map(function (variant) {
|
|
1677
|
+
return React.createElement("option", {
|
|
1678
|
+
value: variant.id
|
|
1679
|
+
}, variant.name);
|
|
1680
|
+
})) != null ? _product$variants$map : React.createElement("option", null, "Fake Product Variant"));
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
function registerProductVariantPicker(loader, customProductVariantPickerMeta) {
|
|
1685
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1686
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1687
|
+
};
|
|
1688
|
+
|
|
1689
|
+
doRegisterComponent(ProductVariantPicker, customProductVariantPickerMeta != null ? customProductVariantPickerMeta : productVariantPickerMeta);
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
var fetcher$2 = /*#__PURE__*/function () {
|
|
1693
|
+
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
|
|
1694
|
+
var options, cartId, fetch;
|
|
1695
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1696
|
+
while (1) {
|
|
1697
|
+
switch (_context.prev = _context.next) {
|
|
1698
|
+
case 0:
|
|
1699
|
+
options = _ref.options, cartId = _ref.input.cartId, fetch = _ref.fetch;
|
|
1700
|
+
|
|
1701
|
+
if (!cartId) {
|
|
1702
|
+
_context.next = 7;
|
|
1703
|
+
break;
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
_context.next = 4;
|
|
1707
|
+
return fetch(options);
|
|
1708
|
+
|
|
1709
|
+
case 4:
|
|
1710
|
+
_context.t0 = _context.sent;
|
|
1711
|
+
_context.next = 8;
|
|
1712
|
+
break;
|
|
1713
|
+
|
|
1714
|
+
case 7:
|
|
1715
|
+
_context.t0 = null;
|
|
1716
|
+
|
|
1717
|
+
case 8:
|
|
1718
|
+
return _context.abrupt("return", _context.t0);
|
|
1719
|
+
|
|
1720
|
+
case 9:
|
|
1721
|
+
case "end":
|
|
1722
|
+
return _context.stop();
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
}, _callee);
|
|
1726
|
+
}));
|
|
1727
|
+
|
|
1728
|
+
return function fetcher(_x) {
|
|
1729
|
+
return _ref2.apply(this, arguments);
|
|
1730
|
+
};
|
|
1731
|
+
}();
|
|
1732
|
+
|
|
1733
|
+
var fn$2 = function fn(provider) {
|
|
1734
|
+
var _provider$cart;
|
|
1735
|
+
|
|
1736
|
+
return (_provider$cart = provider.cart) == null ? void 0 : _provider$cart.useCart;
|
|
1737
|
+
};
|
|
1738
|
+
|
|
1739
|
+
var useCart = function useCart(input) {
|
|
1740
|
+
var _hook$fetcher;
|
|
1741
|
+
|
|
1742
|
+
var hook = useHook(fn$2);
|
|
1743
|
+
|
|
1744
|
+
var _useCommerce = useCommerce(),
|
|
1745
|
+
cartCookie = _useCommerce.cartCookie;
|
|
1746
|
+
|
|
1747
|
+
var fetcherFn = (_hook$fetcher = hook.fetcher) != null ? _hook$fetcher : fetcher$2;
|
|
1748
|
+
|
|
1749
|
+
var wrapper = function wrapper(context) {
|
|
1750
|
+
context.input.cartId = Cookies.get(cartCookie);
|
|
1751
|
+
return fetcherFn(context);
|
|
1752
|
+
};
|
|
1753
|
+
|
|
1754
|
+
return useSWRHook(_extends({}, hook, {
|
|
1755
|
+
fetcher: wrapper
|
|
1756
|
+
}))(input);
|
|
1757
|
+
};
|
|
1758
|
+
|
|
1759
|
+
var useCartMeta = {
|
|
1760
|
+
name: "plasmic-commerce-use-cart",
|
|
1761
|
+
displayName: "Use Cart",
|
|
1762
|
+
props: {
|
|
1763
|
+
field: {
|
|
1764
|
+
type: "choice",
|
|
1765
|
+
options: ["Size", "Total Price"]
|
|
1766
|
+
}
|
|
1767
|
+
},
|
|
1768
|
+
importPath: "commerce-providers/commerce",
|
|
1769
|
+
importName: "UseCart"
|
|
1770
|
+
};
|
|
1771
|
+
|
|
1772
|
+
function UseCartComponent(props) {
|
|
1773
|
+
var _data$totalPrice, _data$currency$code;
|
|
1774
|
+
|
|
1775
|
+
var className = props.className,
|
|
1776
|
+
field = props.field;
|
|
1777
|
+
|
|
1778
|
+
var _useCart = useCart(),
|
|
1779
|
+
data = _useCart.data;
|
|
1780
|
+
|
|
1781
|
+
var _usePrice = usePrice({
|
|
1782
|
+
amount: (_data$totalPrice = data == null ? void 0 : data.totalPrice) != null ? _data$totalPrice : 0,
|
|
1783
|
+
currencyCode: (_data$currency$code = data == null ? void 0 : data.currency.code) != null ? _data$currency$code : "USD"
|
|
1784
|
+
}),
|
|
1785
|
+
price = _usePrice.price;
|
|
1786
|
+
|
|
1787
|
+
if (!field) {
|
|
1788
|
+
return React.createElement("p", null, "You must set the field prop");
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
var value;
|
|
1792
|
+
|
|
1793
|
+
if (field === "Size") {
|
|
1794
|
+
var _data$lineItems$lengt;
|
|
1795
|
+
|
|
1796
|
+
value = "" + ((_data$lineItems$lengt = data == null ? void 0 : data.lineItems.length) != null ? _data$lineItems$lengt : 0);
|
|
1797
|
+
} else if (field === "Total Price") {
|
|
1798
|
+
value = "" + price;
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
return React.createElement("span", {
|
|
1802
|
+
className: className
|
|
1803
|
+
}, value);
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
function registerUseCart(loader, customUseCartMeta) {
|
|
1807
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1808
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1809
|
+
};
|
|
1810
|
+
|
|
1811
|
+
doRegisterComponent(UseCartComponent, customUseCartMeta != null ? customUseCartMeta : useCartMeta);
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
var x = function x() {
|
|
1815
|
+
return 2;
|
|
1816
|
+
};
|
|
1817
|
+
|
|
1818
|
+
|
|
1819
|
+
|
|
1820
|
+
var product = {
|
|
1821
|
+
__proto__: null
|
|
1822
|
+
};
|
|
1823
|
+
|
|
1824
|
+
var fetcher$3 = SWRFetcher;
|
|
1825
|
+
|
|
1826
|
+
var fn$3 = function fn(provider) {
|
|
1827
|
+
var _provider$site;
|
|
1828
|
+
|
|
1829
|
+
return (_provider$site = provider.site) == null ? void 0 : _provider$site.useCategories;
|
|
1830
|
+
};
|
|
1831
|
+
|
|
1832
|
+
var useCategories = function useCategories(input) {
|
|
1833
|
+
var hook = useHook(fn$3);
|
|
1834
|
+
return useSWRHook(_extends({
|
|
1835
|
+
fetcher: fetcher$3
|
|
1836
|
+
}, hook))(input);
|
|
1837
|
+
};
|
|
1838
|
+
|
|
1839
|
+
var fetcher$4 = SWRFetcher;
|
|
1840
|
+
|
|
1841
|
+
var fn$4 = function fn(provider) {
|
|
1842
|
+
var _provider$site;
|
|
1843
|
+
|
|
1844
|
+
return (_provider$site = provider.site) == null ? void 0 : _provider$site.useBrands;
|
|
1845
|
+
};
|
|
1846
|
+
|
|
1847
|
+
var useBrands = function useBrands(input) {
|
|
1848
|
+
var hook = useHook(fn$4);
|
|
1849
|
+
return useSWRHook(_extends({
|
|
1850
|
+
fetcher: fetcher$4
|
|
1851
|
+
}, hook))(input);
|
|
1852
|
+
};
|
|
1853
|
+
|
|
1854
|
+
var fetcher$5 = mutationFetcher;
|
|
1855
|
+
|
|
1856
|
+
var fn$5 = function fn(provider) {
|
|
1857
|
+
var _provider$cart;
|
|
1858
|
+
|
|
1859
|
+
return (_provider$cart = provider.cart) == null ? void 0 : _provider$cart.useRemoveItem;
|
|
1860
|
+
};
|
|
1861
|
+
|
|
1862
|
+
var useRemoveItem = function useRemoveItem(input) {
|
|
1863
|
+
var hook = useHook(fn$5);
|
|
1864
|
+
return useMutationHook(_extends({
|
|
1865
|
+
fetcher: fetcher$5
|
|
1866
|
+
}, hook))(input);
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1869
|
+
var fetcher$6 = mutationFetcher;
|
|
1870
|
+
|
|
1871
|
+
var fn$6 = function fn(provider) {
|
|
1872
|
+
var _provider$cart;
|
|
1873
|
+
|
|
1874
|
+
return (_provider$cart = provider.cart) == null ? void 0 : _provider$cart.useUpdateItem;
|
|
1875
|
+
};
|
|
1876
|
+
|
|
1877
|
+
var useUpdateItem = function useUpdateItem(input) {
|
|
1878
|
+
var hook = useHook(fn$6);
|
|
1879
|
+
return useMutationHook(_extends({
|
|
1880
|
+
fetcher: fetcher$6
|
|
1881
|
+
}, hook))(input);
|
|
1882
|
+
};
|
|
1883
|
+
|
|
1884
|
+
|
|
1885
|
+
|
|
1886
|
+
var cart = {
|
|
1887
|
+
__proto__: null
|
|
1888
|
+
};
|
|
1889
|
+
|
|
1890
|
+
|
|
1891
|
+
|
|
1892
|
+
var site = {
|
|
1893
|
+
__proto__: null
|
|
1894
|
+
};
|
|
1895
|
+
|
|
1896
|
+
function registerAll(loader) {
|
|
1897
|
+
registerProductCollection(loader);
|
|
1898
|
+
registerTextField(loader);
|
|
1899
|
+
registerProductPrice(loader);
|
|
1900
|
+
registerProductMedia(loader);
|
|
1901
|
+
registerUseCart(loader);
|
|
1902
|
+
registerAddToCartButton(loader);
|
|
1903
|
+
registerProductQuantity(loader);
|
|
1904
|
+
registerProductVariantPicker(loader);
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
export { cart as CartType, CommerceError, CoreCommerceProvider, FetcherError, product as ProductTypes, site as SiteTypes, ValidationError, fetcher$1 as fetcher, getCommerceProvider, registerAll, useAddItem, useBrands, useCart, useCategories, useCommerce, useRemoveItem, useSearch, useUpdateItem, x };
|
|
1908
|
+
//# sourceMappingURL=commerce.esm.js.map
|