@plasmicpkgs/commerce 0.0.11 → 0.0.14
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/commerce.cjs.development.js +828 -598
- package/dist/commerce.cjs.development.js.map +1 -1
- package/dist/commerce.cjs.production.min.js +1 -1
- package/dist/commerce.cjs.production.min.js.map +1 -1
- package/dist/commerce.esm.js +824 -598
- package/dist/commerce.esm.js.map +1 -1
- package/dist/contexts.d.ts +10 -3
- package/dist/index.d.ts +25 -23
- package/dist/registerCategoryLink.d.ts +12 -0
- package/dist/registerCategoryMedia.d.ts +10 -0
- package/dist/registerProductCollection.d.ts +3 -1
- package/dist/registerProductLink.d.ts +1 -1
- package/dist/registerProductSlider.d.ts +14 -0
- package/dist/types/site.d.ts +11 -6
- package/package.json +2 -2
|
@@ -9,8 +9,8 @@ var React = require('react');
|
|
|
9
9
|
var React__default = _interopDefault(React);
|
|
10
10
|
var reactHookForm = require('react-hook-form');
|
|
11
11
|
var useSWR = _interopDefault(require('swr'));
|
|
12
|
-
var host = require('@plasmicapp/host');
|
|
13
12
|
var Cookies = _interopDefault(require('js-cookie'));
|
|
13
|
+
var host = require('@plasmicapp/host');
|
|
14
14
|
|
|
15
15
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
16
16
|
try {
|
|
@@ -971,6 +971,7 @@ var defaultProduct = {
|
|
|
971
971
|
|
|
972
972
|
var ProductContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
973
973
|
var CategoryContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
974
|
+
var SliderContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
974
975
|
function ProductProvider(_ref) {
|
|
975
976
|
var product = _ref.product,
|
|
976
977
|
children = _ref.children;
|
|
@@ -995,6 +996,20 @@ function CategoryProvider(_ref2) {
|
|
|
995
996
|
var useCategoryContext = function useCategoryContext() {
|
|
996
997
|
return React.useContext(CategoryContext);
|
|
997
998
|
};
|
|
999
|
+
function ProductSliderProvider(_ref3) {
|
|
1000
|
+
var mediaIndex = _ref3.mediaIndex,
|
|
1001
|
+
onClick = _ref3.onClick,
|
|
1002
|
+
children = _ref3.children;
|
|
1003
|
+
return React__default.createElement(SliderContext.Provider, {
|
|
1004
|
+
value: mediaIndex,
|
|
1005
|
+
key: mediaIndex
|
|
1006
|
+
}, React__default.cloneElement(React__default.isValidElement(children) ? children : React__default.createElement(React__default.Fragment, null), {
|
|
1007
|
+
onClick: onClick
|
|
1008
|
+
}));
|
|
1009
|
+
}
|
|
1010
|
+
var useProductSliderContext = function useProductSliderContext() {
|
|
1011
|
+
return React.useContext(SliderContext);
|
|
1012
|
+
};
|
|
998
1013
|
|
|
999
1014
|
var _excluded = ["children"];
|
|
1000
1015
|
var Commerce = /*#__PURE__*/React.createContext({});
|
|
@@ -1340,143 +1355,209 @@ function registerAddToCartButton(loader, customAddToCartButtonMeta) {
|
|
|
1340
1355
|
doRegisterComponent(AddToCartButton, customAddToCartButtonMeta != null ? customAddToCartButtonMeta : addToCartButtonMeta);
|
|
1341
1356
|
}
|
|
1342
1357
|
|
|
1343
|
-
var fetcher$1 =
|
|
1358
|
+
var fetcher$1 = /*#__PURE__*/function () {
|
|
1359
|
+
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
|
|
1360
|
+
var options, cartId, fetch;
|
|
1361
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1362
|
+
while (1) {
|
|
1363
|
+
switch (_context.prev = _context.next) {
|
|
1364
|
+
case 0:
|
|
1365
|
+
options = _ref.options, cartId = _ref.input.cartId, fetch = _ref.fetch;
|
|
1366
|
+
|
|
1367
|
+
if (!cartId) {
|
|
1368
|
+
_context.next = 7;
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
_context.next = 4;
|
|
1373
|
+
return fetch(options);
|
|
1374
|
+
|
|
1375
|
+
case 4:
|
|
1376
|
+
_context.t0 = _context.sent;
|
|
1377
|
+
_context.next = 8;
|
|
1378
|
+
break;
|
|
1379
|
+
|
|
1380
|
+
case 7:
|
|
1381
|
+
_context.t0 = null;
|
|
1382
|
+
|
|
1383
|
+
case 8:
|
|
1384
|
+
return _context.abrupt("return", _context.t0);
|
|
1385
|
+
|
|
1386
|
+
case 9:
|
|
1387
|
+
case "end":
|
|
1388
|
+
return _context.stop();
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}, _callee);
|
|
1392
|
+
}));
|
|
1393
|
+
|
|
1394
|
+
return function fetcher(_x) {
|
|
1395
|
+
return _ref2.apply(this, arguments);
|
|
1396
|
+
};
|
|
1397
|
+
}();
|
|
1344
1398
|
|
|
1345
1399
|
var fn$1 = function fn(provider) {
|
|
1346
|
-
var _provider$
|
|
1400
|
+
var _provider$cart;
|
|
1347
1401
|
|
|
1348
|
-
return (_provider$
|
|
1402
|
+
return (_provider$cart = provider.cart) == null ? void 0 : _provider$cart.useCart;
|
|
1349
1403
|
};
|
|
1350
1404
|
|
|
1351
|
-
var
|
|
1405
|
+
var useCart = function useCart(input) {
|
|
1406
|
+
var _hook$fetcher;
|
|
1407
|
+
|
|
1352
1408
|
var hook = useHook(fn$1);
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1409
|
+
|
|
1410
|
+
var _useCommerce = useCommerce(),
|
|
1411
|
+
cartCookie = _useCommerce.cartCookie;
|
|
1412
|
+
|
|
1413
|
+
var fetcherFn = (_hook$fetcher = hook.fetcher) != null ? _hook$fetcher : fetcher$1;
|
|
1414
|
+
|
|
1415
|
+
var wrapper = function wrapper(context) {
|
|
1416
|
+
context.input.cartId = Cookies.get(cartCookie);
|
|
1417
|
+
return fetcherFn(context);
|
|
1418
|
+
};
|
|
1419
|
+
|
|
1420
|
+
return useSWRHook(_extends({}, hook, {
|
|
1421
|
+
fetcher: wrapper
|
|
1422
|
+
}))(input);
|
|
1356
1423
|
};
|
|
1357
1424
|
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1425
|
+
/*
|
|
1426
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/commerce/src
|
|
1427
|
+
Changes: None
|
|
1428
|
+
*/
|
|
1429
|
+
function formatPrice(_ref) {
|
|
1430
|
+
var amount = _ref.amount,
|
|
1431
|
+
currencyCode = _ref.currencyCode,
|
|
1432
|
+
locale = _ref.locale;
|
|
1433
|
+
var formatCurrency = new Intl.NumberFormat(locale, {
|
|
1434
|
+
style: 'currency',
|
|
1435
|
+
currency: currencyCode
|
|
1436
|
+
});
|
|
1437
|
+
return formatCurrency.format(amount);
|
|
1438
|
+
}
|
|
1439
|
+
function formatVariantPrice(_ref2) {
|
|
1440
|
+
var amount = _ref2.amount,
|
|
1441
|
+
baseAmount = _ref2.baseAmount,
|
|
1442
|
+
currencyCode = _ref2.currencyCode,
|
|
1443
|
+
locale = _ref2.locale;
|
|
1444
|
+
var hasDiscount = baseAmount > amount;
|
|
1445
|
+
var formatDiscount = new Intl.NumberFormat(locale, {
|
|
1446
|
+
style: 'percent'
|
|
1447
|
+
});
|
|
1448
|
+
var discount = hasDiscount ? formatDiscount.format((baseAmount - amount) / baseAmount) : null;
|
|
1449
|
+
var price = formatPrice({
|
|
1450
|
+
amount: amount,
|
|
1451
|
+
currencyCode: currencyCode,
|
|
1452
|
+
locale: locale
|
|
1453
|
+
});
|
|
1454
|
+
var basePrice = hasDiscount ? formatPrice({
|
|
1455
|
+
amount: baseAmount,
|
|
1456
|
+
currencyCode: currencyCode,
|
|
1457
|
+
locale: locale
|
|
1458
|
+
}) : null;
|
|
1459
|
+
return {
|
|
1460
|
+
price: price,
|
|
1461
|
+
basePrice: basePrice,
|
|
1462
|
+
discount: discount
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
function usePrice(data) {
|
|
1466
|
+
var _ref3 = data != null ? data : {},
|
|
1467
|
+
amount = _ref3.amount,
|
|
1468
|
+
baseAmount = _ref3.baseAmount,
|
|
1469
|
+
currencyCode = _ref3.currencyCode;
|
|
1470
|
+
|
|
1471
|
+
var _useCommerce = useCommerce(),
|
|
1472
|
+
locale = _useCommerce.locale;
|
|
1473
|
+
|
|
1474
|
+
var value = React.useMemo(function () {
|
|
1475
|
+
if (typeof amount !== 'number' || !currencyCode) return '';
|
|
1476
|
+
return baseAmount ? formatVariantPrice({
|
|
1477
|
+
amount: amount,
|
|
1478
|
+
baseAmount: baseAmount,
|
|
1479
|
+
currencyCode: currencyCode,
|
|
1480
|
+
locale: locale
|
|
1481
|
+
}) : formatPrice({
|
|
1482
|
+
amount: amount,
|
|
1483
|
+
currencyCode: currencyCode,
|
|
1484
|
+
locale: locale
|
|
1485
|
+
});
|
|
1486
|
+
}, [amount, baseAmount, currencyCode]);
|
|
1487
|
+
return typeof value === 'string' ? {
|
|
1488
|
+
price: value
|
|
1489
|
+
} : value;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
var cartMeta = {
|
|
1493
|
+
name: "plasmic-commerce-cart",
|
|
1494
|
+
displayName: "Cart",
|
|
1361
1495
|
props: {
|
|
1362
|
-
|
|
1363
|
-
type: "
|
|
1364
|
-
|
|
1365
|
-
type: "vbox",
|
|
1366
|
-
children: [{
|
|
1367
|
-
type: "component",
|
|
1368
|
-
name: "plasmic-commerce-product-text-field",
|
|
1369
|
-
props: {
|
|
1370
|
-
field: "name"
|
|
1371
|
-
}
|
|
1372
|
-
}, {
|
|
1373
|
-
type: "component",
|
|
1374
|
-
name: "plasmic-commerce-product-media"
|
|
1375
|
-
}],
|
|
1376
|
-
styles: {
|
|
1377
|
-
width: "100%",
|
|
1378
|
-
minWidth: 0
|
|
1379
|
-
}
|
|
1380
|
-
}]
|
|
1496
|
+
field: {
|
|
1497
|
+
type: "choice",
|
|
1498
|
+
options: ["Size", "Total Price"]
|
|
1381
1499
|
},
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
type: "string",
|
|
1385
|
-
description: "Fetch a product by its slug or ID"
|
|
1500
|
+
hideIfIsEmpty: {
|
|
1501
|
+
type: "boolean"
|
|
1386
1502
|
}
|
|
1387
1503
|
},
|
|
1388
1504
|
importPath: "@plasmicpkgs/commerce",
|
|
1389
|
-
importName: "
|
|
1505
|
+
importName: "CartComponent"
|
|
1390
1506
|
};
|
|
1391
|
-
function
|
|
1507
|
+
function CartComponent(props) {
|
|
1508
|
+
var _data$totalPrice, _data$currency$code;
|
|
1509
|
+
|
|
1392
1510
|
var className = props.className,
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
id = props.id;
|
|
1511
|
+
field = props.field,
|
|
1512
|
+
hideIfIsEmpty = props.hideIfIsEmpty;
|
|
1396
1513
|
|
|
1397
|
-
var
|
|
1398
|
-
|
|
1514
|
+
var _useCart = useCart(),
|
|
1515
|
+
data = _useCart.data;
|
|
1516
|
+
|
|
1517
|
+
var _usePrice = usePrice({
|
|
1518
|
+
amount: (_data$totalPrice = data == null ? void 0 : data.totalPrice) != null ? _data$totalPrice : 0,
|
|
1519
|
+
currencyCode: (_data$currency$code = data == null ? void 0 : data.currency.code) != null ? _data$currency$code : "USD"
|
|
1399
1520
|
}),
|
|
1400
|
-
|
|
1401
|
-
error = _useProduct.error,
|
|
1402
|
-
isLoading = _useProduct.isLoading;
|
|
1521
|
+
price = _usePrice.price;
|
|
1403
1522
|
|
|
1404
|
-
if (!
|
|
1405
|
-
return React__default.createElement("
|
|
1523
|
+
if (!field) {
|
|
1524
|
+
return React__default.createElement("p", null, "You must set the field prop");
|
|
1406
1525
|
}
|
|
1407
1526
|
|
|
1408
|
-
|
|
1409
|
-
throw new CommerceError({
|
|
1410
|
-
message: error.message,
|
|
1411
|
-
code: error.code
|
|
1412
|
-
});
|
|
1413
|
-
}
|
|
1527
|
+
var value;
|
|
1414
1528
|
|
|
1415
|
-
if (
|
|
1416
|
-
|
|
1417
|
-
}
|
|
1529
|
+
if (field === "Size") {
|
|
1530
|
+
var _data$lineItems$lengt;
|
|
1418
1531
|
|
|
1419
|
-
|
|
1420
|
-
|
|
1532
|
+
value = (_data$lineItems$lengt = data == null ? void 0 : data.lineItems.length) != null ? _data$lineItems$lengt : 0;
|
|
1533
|
+
} else if (field === "Total Price") {
|
|
1534
|
+
value = price != null ? price : 0;
|
|
1421
1535
|
}
|
|
1422
1536
|
|
|
1423
|
-
|
|
1424
|
-
product: data
|
|
1425
|
-
}, children);
|
|
1426
|
-
return noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
|
|
1537
|
+
return hideIfIsEmpty && value === 0 ? null : React__default.createElement("span", {
|
|
1427
1538
|
className: className
|
|
1428
|
-
},
|
|
1539
|
+
}, value);
|
|
1429
1540
|
}
|
|
1430
|
-
function
|
|
1541
|
+
function registerCart(loader, customCartMeta) {
|
|
1431
1542
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1432
1543
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1433
1544
|
};
|
|
1434
1545
|
|
|
1435
|
-
doRegisterComponent(
|
|
1546
|
+
doRegisterComponent(CartComponent, customCartMeta != null ? customCartMeta : cartMeta);
|
|
1436
1547
|
}
|
|
1437
1548
|
|
|
1438
1549
|
var fetcher$2 = SWRFetcher;
|
|
1439
1550
|
|
|
1440
1551
|
var fn$2 = function fn(provider) {
|
|
1441
|
-
var _provider$products;
|
|
1442
|
-
|
|
1443
|
-
return (_provider$products = provider.products) == null ? void 0 : _provider$products.useSearch;
|
|
1444
|
-
};
|
|
1445
|
-
|
|
1446
|
-
var useSearch = function useSearch(input) {
|
|
1447
|
-
var hook = useHook(fn$2);
|
|
1448
|
-
return useSWRHook(_extends({
|
|
1449
|
-
fetcher: fetcher$2
|
|
1450
|
-
}, hook))(input);
|
|
1451
|
-
};
|
|
1452
|
-
|
|
1453
|
-
var fetcher$3 = SWRFetcher;
|
|
1454
|
-
|
|
1455
|
-
var fn$3 = function fn(provider) {
|
|
1456
1552
|
var _provider$site;
|
|
1457
1553
|
|
|
1458
1554
|
return (_provider$site = provider.site) == null ? void 0 : _provider$site.useCategories;
|
|
1459
1555
|
};
|
|
1460
1556
|
|
|
1461
1557
|
var useCategories = function useCategories(input) {
|
|
1462
|
-
var hook = useHook(fn$
|
|
1463
|
-
return useSWRHook(_extends({
|
|
1464
|
-
fetcher: fetcher$3
|
|
1465
|
-
}, hook))(input);
|
|
1466
|
-
};
|
|
1467
|
-
|
|
1468
|
-
var fetcher$4 = SWRFetcher;
|
|
1469
|
-
|
|
1470
|
-
var fn$4 = function fn(provider) {
|
|
1471
|
-
var _provider$site;
|
|
1472
|
-
|
|
1473
|
-
return (_provider$site = provider.site) == null ? void 0 : _provider$site.useBrands;
|
|
1474
|
-
};
|
|
1475
|
-
|
|
1476
|
-
var useBrands = function useBrands(input) {
|
|
1477
|
-
var hook = useHook(fn$4);
|
|
1558
|
+
var hook = useHook(fn$2);
|
|
1478
1559
|
return useSWRHook(_extends({
|
|
1479
|
-
fetcher: fetcher$
|
|
1560
|
+
fetcher: fetcher$2
|
|
1480
1561
|
}, hook))(input);
|
|
1481
1562
|
};
|
|
1482
1563
|
|
|
@@ -1487,9 +1568,9 @@ var useCommerceExtraFeatures = function useCommerceExtraFeatures() {
|
|
|
1487
1568
|
return providerRef.current.extraFeatures;
|
|
1488
1569
|
};
|
|
1489
1570
|
|
|
1490
|
-
var
|
|
1491
|
-
name: "plasmic-commerce-
|
|
1492
|
-
displayName: "
|
|
1571
|
+
var categoryCollectionMeta = {
|
|
1572
|
+
name: "plasmic-commerce-category-collection",
|
|
1573
|
+
displayName: "Category Collection",
|
|
1493
1574
|
props: {
|
|
1494
1575
|
children: {
|
|
1495
1576
|
type: "slot",
|
|
@@ -1497,13 +1578,13 @@ var productCollectionMeta = {
|
|
|
1497
1578
|
type: "vbox",
|
|
1498
1579
|
children: [{
|
|
1499
1580
|
type: "component",
|
|
1500
|
-
name: "plasmic-commerce-
|
|
1581
|
+
name: "plasmic-commerce-category-field",
|
|
1501
1582
|
props: {
|
|
1502
1583
|
field: "name"
|
|
1503
1584
|
}
|
|
1504
1585
|
}, {
|
|
1505
1586
|
type: "component",
|
|
1506
|
-
name: "plasmic-commerce-product-
|
|
1587
|
+
name: "plasmic-commerce-product-collection"
|
|
1507
1588
|
}],
|
|
1508
1589
|
styles: {
|
|
1509
1590
|
width: "100%",
|
|
@@ -1511,11 +1592,14 @@ var productCollectionMeta = {
|
|
|
1511
1592
|
}
|
|
1512
1593
|
}]
|
|
1513
1594
|
},
|
|
1595
|
+
noLayout: {
|
|
1596
|
+
type: "boolean"
|
|
1597
|
+
},
|
|
1514
1598
|
emptyMessage: {
|
|
1515
1599
|
type: "slot",
|
|
1516
1600
|
defaultValue: {
|
|
1517
1601
|
type: "text",
|
|
1518
|
-
value: "No
|
|
1602
|
+
value: "No collection found!"
|
|
1519
1603
|
}
|
|
1520
1604
|
},
|
|
1521
1605
|
loadingMessage: {
|
|
@@ -1525,7 +1609,6 @@ var productCollectionMeta = {
|
|
|
1525
1609
|
value: "Loading..."
|
|
1526
1610
|
}
|
|
1527
1611
|
},
|
|
1528
|
-
count: "number",
|
|
1529
1612
|
category: {
|
|
1530
1613
|
type: "choice",
|
|
1531
1614
|
options: function options(props, ctx) {
|
|
@@ -1537,102 +1620,63 @@ var productCollectionMeta = {
|
|
|
1537
1620
|
value: category.id
|
|
1538
1621
|
};
|
|
1539
1622
|
})) != null ? _ctx$categories$map : [];
|
|
1540
|
-
},
|
|
1541
|
-
hidden: function hidden(props, ctx) {
|
|
1542
|
-
return !!(ctx != null && ctx.hasCategoryCtx);
|
|
1543
|
-
}
|
|
1544
|
-
},
|
|
1545
|
-
includeSubCategories: {
|
|
1546
|
-
type: "boolean",
|
|
1547
|
-
hidden: function hidden(props, ctx) {
|
|
1548
|
-
var _ctx$features;
|
|
1549
|
-
|
|
1550
|
-
return !(ctx != null && (_ctx$features = ctx.features) != null && _ctx$features.includeSubCategories);
|
|
1551
|
-
}
|
|
1552
|
-
},
|
|
1553
|
-
brand: {
|
|
1554
|
-
type: "choice",
|
|
1555
|
-
options: function options(props, ctx) {
|
|
1556
|
-
var _ctx$brands$map;
|
|
1557
|
-
|
|
1558
|
-
return (_ctx$brands$map = ctx == null ? void 0 : ctx.brands.map(function (brand) {
|
|
1559
|
-
return {
|
|
1560
|
-
label: brand.name,
|
|
1561
|
-
value: brand.entityId
|
|
1562
|
-
};
|
|
1563
|
-
})) != null ? _ctx$brands$map : [];
|
|
1564
1623
|
}
|
|
1565
|
-
}
|
|
1566
|
-
noLayout: "boolean"
|
|
1624
|
+
}
|
|
1567
1625
|
},
|
|
1568
1626
|
defaultStyles: {
|
|
1569
1627
|
display: "grid",
|
|
1570
|
-
gridTemplateColumns: "1fr
|
|
1628
|
+
gridTemplateColumns: "1fr",
|
|
1571
1629
|
gridRowGap: "8px",
|
|
1572
|
-
gridColumnGap: "8px",
|
|
1573
1630
|
padding: "8px",
|
|
1574
1631
|
maxWidth: "100%"
|
|
1575
1632
|
},
|
|
1576
1633
|
importPath: "@plasmicpkgs/commerce",
|
|
1577
|
-
importName: "
|
|
1634
|
+
importName: "CategoryCollection"
|
|
1578
1635
|
};
|
|
1579
|
-
function
|
|
1580
|
-
var
|
|
1581
|
-
|
|
1582
|
-
var className = props.className,
|
|
1583
|
-
children = props.children,
|
|
1584
|
-
count = props.count,
|
|
1585
|
-
category = props.category,
|
|
1586
|
-
includeSubCategories = props.includeSubCategories,
|
|
1587
|
-
brand = props.brand,
|
|
1636
|
+
function CategoryCollection(props) {
|
|
1637
|
+
var children = props.children,
|
|
1588
1638
|
noLayout = props.noLayout,
|
|
1589
|
-
|
|
1639
|
+
className = props.className,
|
|
1640
|
+
loadingMessage = props.loadingMessage,
|
|
1590
1641
|
emptyMessage = props.emptyMessage,
|
|
1591
|
-
|
|
1642
|
+
selectedCategory = props.category,
|
|
1643
|
+
setControlContextData = props.setControlContextData;
|
|
1644
|
+
var features = useCommerceExtraFeatures();
|
|
1645
|
+
var inEditor = React__default.useContext(host.PlasmicCanvasContext);
|
|
1592
1646
|
|
|
1593
1647
|
var _useCategories = useCategories(),
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
var _useBrands = useBrands(),
|
|
1598
|
-
brands = _useBrands.data,
|
|
1599
|
-
isBrandsLoading = _useBrands.isLoading;
|
|
1600
|
-
|
|
1601
|
-
var categoryCtx = useCategoryContext();
|
|
1648
|
+
allCategories = _useCategories.data,
|
|
1649
|
+
isAllCategoriesLoading = _useCategories.isLoading;
|
|
1602
1650
|
|
|
1603
|
-
var
|
|
1604
|
-
categoryId:
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
categories: categories != null ? categories : [],
|
|
1608
|
-
includeSubCategories: includeSubCategories
|
|
1651
|
+
var _useCategories2 = useCategories({
|
|
1652
|
+
categoryId: selectedCategory,
|
|
1653
|
+
topologicalSort: !selectedCategory && (features == null ? void 0 : features.includeSubCategories),
|
|
1654
|
+
addIsEmptyField: !!inEditor
|
|
1609
1655
|
}),
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
var features = useCommerceExtraFeatures();
|
|
1656
|
+
categories = _useCategories2.data,
|
|
1657
|
+
isLoading = _useCategories2.isLoading;
|
|
1614
1658
|
|
|
1615
|
-
if (
|
|
1659
|
+
if (allCategories) {
|
|
1616
1660
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
1617
|
-
categories:
|
|
1618
|
-
brands: brands,
|
|
1619
|
-
features: features,
|
|
1620
|
-
hasCategoryCtx: !!categoryCtx
|
|
1661
|
+
categories: allCategories
|
|
1621
1662
|
});
|
|
1622
1663
|
}
|
|
1623
1664
|
|
|
1624
|
-
var
|
|
1625
|
-
return
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1665
|
+
var firstCategoryNotEmpty = categories == null ? void 0 : categories.find(function (category) {
|
|
1666
|
+
return !category.isEmpty;
|
|
1667
|
+
});
|
|
1668
|
+
var renderedData = categories == null ? void 0 : categories.map(function (category, i) {
|
|
1669
|
+
return React__default.createElement(CategoryProvider, {
|
|
1670
|
+
category: category,
|
|
1671
|
+
key: category.id
|
|
1672
|
+
}, host.repeatedElement(firstCategoryNotEmpty ? category === firstCategoryNotEmpty : i === 0, children));
|
|
1629
1673
|
});
|
|
1630
1674
|
|
|
1631
|
-
if ([
|
|
1675
|
+
if ([isAllCategoriesLoading, isLoading].includes(true)) {
|
|
1632
1676
|
return React__default.isValidElement(loadingMessage) ? loadingMessage : null;
|
|
1633
1677
|
}
|
|
1634
1678
|
|
|
1635
|
-
if (!
|
|
1679
|
+
if (!categories || categories.length === 0) {
|
|
1636
1680
|
return React__default.isValidElement(emptyMessage) ? emptyMessage : null;
|
|
1637
1681
|
}
|
|
1638
1682
|
|
|
@@ -1640,38 +1684,72 @@ function ProductCollection(props) {
|
|
|
1640
1684
|
className: className
|
|
1641
1685
|
}, renderedData);
|
|
1642
1686
|
}
|
|
1643
|
-
function
|
|
1687
|
+
function registerCategoryCollection(loader, customCategoryCollectionMeta) {
|
|
1644
1688
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1645
1689
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1646
1690
|
};
|
|
1647
1691
|
|
|
1648
|
-
doRegisterComponent(
|
|
1692
|
+
doRegisterComponent(CategoryCollection, customCategoryCollectionMeta != null ? customCategoryCollectionMeta : categoryCollectionMeta);
|
|
1649
1693
|
}
|
|
1650
1694
|
|
|
1651
|
-
var
|
|
1652
|
-
name: "plasmic-commerce-
|
|
1653
|
-
displayName: "
|
|
1695
|
+
var categoryFieldMeta = {
|
|
1696
|
+
name: "plasmic-commerce-category-field",
|
|
1697
|
+
displayName: "Category Field",
|
|
1698
|
+
props: {
|
|
1699
|
+
field: {
|
|
1700
|
+
type: "choice",
|
|
1701
|
+
options: ["id", "name", "slug", "path"]
|
|
1702
|
+
}
|
|
1703
|
+
},
|
|
1704
|
+
importPath: "@plasmicpkgs/commerce",
|
|
1705
|
+
importName: "CategoryField"
|
|
1706
|
+
};
|
|
1707
|
+
function CategoryField(props) {
|
|
1708
|
+
var className = props.className,
|
|
1709
|
+
field = props.field;
|
|
1710
|
+
var category = useCategoryContext();
|
|
1711
|
+
|
|
1712
|
+
if (!field) {
|
|
1713
|
+
return React__default.createElement("span", null, "You must set the field prop");
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
var data = category ? category[field] : "Category field placeholder";
|
|
1717
|
+
return React__default.createElement("span", {
|
|
1718
|
+
className: className
|
|
1719
|
+
}, data);
|
|
1720
|
+
}
|
|
1721
|
+
function registerCategoryField(loader, customCategoryFieldMeta) {
|
|
1722
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
1723
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1724
|
+
};
|
|
1725
|
+
|
|
1726
|
+
doRegisterComponent(CategoryField, customCategoryFieldMeta != null ? customCategoryFieldMeta : categoryFieldMeta);
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
var categoryLinkMeta = {
|
|
1730
|
+
name: "plasmic-commerce-category-link",
|
|
1731
|
+
displayName: "Category Link",
|
|
1654
1732
|
props: {
|
|
1655
1733
|
children: "slot",
|
|
1656
1734
|
linkDest: {
|
|
1657
1735
|
type: "string",
|
|
1658
|
-
defaultValueHint: "
|
|
1659
|
-
description: "Set the link destination. You can use {slug} to replace by the
|
|
1736
|
+
defaultValueHint: "category/{slug}",
|
|
1737
|
+
description: "Set the link destination. You can use {slug} to replace by the category slug"
|
|
1660
1738
|
}
|
|
1661
1739
|
},
|
|
1662
1740
|
importPath: "@plasmicpkgs/commerce",
|
|
1663
|
-
importName: "
|
|
1741
|
+
importName: "CategoryLink"
|
|
1664
1742
|
};
|
|
1665
|
-
function
|
|
1743
|
+
function CategoryLink(props) {
|
|
1666
1744
|
var className = props.className,
|
|
1667
1745
|
children = props.children,
|
|
1668
1746
|
linkDest = props.linkDest;
|
|
1669
|
-
var
|
|
1747
|
+
var category = useCategoryContext();
|
|
1670
1748
|
|
|
1671
1749
|
var resolveLink = function resolveLink(linkDest) {
|
|
1672
1750
|
var _linkDest$match;
|
|
1673
1751
|
|
|
1674
|
-
if (!
|
|
1752
|
+
if (!linkDest) {
|
|
1675
1753
|
return undefined;
|
|
1676
1754
|
}
|
|
1677
1755
|
|
|
@@ -1684,11 +1762,11 @@ function ProductLink(props) {
|
|
|
1684
1762
|
var match = _step.value;
|
|
1685
1763
|
var field = match.slice(1, -1);
|
|
1686
1764
|
|
|
1687
|
-
if (!(field in
|
|
1765
|
+
if (!category || !(field in category)) {
|
|
1688
1766
|
return undefined;
|
|
1689
1767
|
}
|
|
1690
1768
|
|
|
1691
|
-
resolvedLink = resolvedLink.replace(regex,
|
|
1769
|
+
resolvedLink = resolvedLink.replace(regex, category[field]);
|
|
1692
1770
|
}
|
|
1693
1771
|
|
|
1694
1772
|
return resolvedLink;
|
|
@@ -1703,580 +1781,716 @@ function ProductLink(props) {
|
|
|
1703
1781
|
}
|
|
1704
1782
|
}, children);
|
|
1705
1783
|
}
|
|
1706
|
-
function
|
|
1784
|
+
function registerCategoryLink(loader, customCategoryLinkMeta) {
|
|
1707
1785
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1708
1786
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1709
1787
|
};
|
|
1710
1788
|
|
|
1711
|
-
doRegisterComponent(
|
|
1789
|
+
doRegisterComponent(CategoryLink, customCategoryLinkMeta != null ? customCategoryLinkMeta : categoryLinkMeta);
|
|
1712
1790
|
}
|
|
1713
1791
|
|
|
1714
|
-
var
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
displayName: "Product Media",
|
|
1792
|
+
var categoryMediaMeta = {
|
|
1793
|
+
name: "plasmic-commerce-category-media",
|
|
1794
|
+
displayName: "Category Media",
|
|
1718
1795
|
props: {
|
|
1719
1796
|
mediaIndex: "number"
|
|
1720
1797
|
},
|
|
1721
1798
|
importPath: "@plasmicpkgs/commerce",
|
|
1722
|
-
importName: "
|
|
1799
|
+
importName: "CategoryMedia"
|
|
1723
1800
|
};
|
|
1724
|
-
function
|
|
1801
|
+
function CategoryMedia(props) {
|
|
1725
1802
|
var _image$url;
|
|
1726
1803
|
|
|
1727
1804
|
var className = props.className,
|
|
1728
1805
|
_props$mediaIndex = props.mediaIndex,
|
|
1729
1806
|
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex;
|
|
1730
|
-
var
|
|
1731
|
-
var image =
|
|
1807
|
+
var category = useCategoryContext();
|
|
1808
|
+
var image = category != null && category.images ? category.images[mediaIndex] : undefined;
|
|
1732
1809
|
return React__default.createElement("img", {
|
|
1733
|
-
alt: (
|
|
1734
|
-
src:
|
|
1735
|
-
loading:
|
|
1810
|
+
alt: (category == null ? void 0 : category.name) || "Category Image",
|
|
1811
|
+
src: (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "",
|
|
1812
|
+
loading: "lazy",
|
|
1736
1813
|
className: className
|
|
1737
1814
|
});
|
|
1738
1815
|
}
|
|
1739
|
-
function
|
|
1816
|
+
function registerCategoryMedia(loader, customCategoryMediaMeta) {
|
|
1740
1817
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1741
1818
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1742
1819
|
};
|
|
1743
1820
|
|
|
1744
|
-
doRegisterComponent(
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
/*
|
|
1748
|
-
Forked from https://github.com/vercel/commerce/tree/main/packages/commerce/src
|
|
1749
|
-
Changes: None
|
|
1750
|
-
*/
|
|
1751
|
-
function formatPrice(_ref) {
|
|
1752
|
-
var amount = _ref.amount,
|
|
1753
|
-
currencyCode = _ref.currencyCode,
|
|
1754
|
-
locale = _ref.locale;
|
|
1755
|
-
var formatCurrency = new Intl.NumberFormat(locale, {
|
|
1756
|
-
style: 'currency',
|
|
1757
|
-
currency: currencyCode
|
|
1758
|
-
});
|
|
1759
|
-
return formatCurrency.format(amount);
|
|
1760
|
-
}
|
|
1761
|
-
function formatVariantPrice(_ref2) {
|
|
1762
|
-
var amount = _ref2.amount,
|
|
1763
|
-
baseAmount = _ref2.baseAmount,
|
|
1764
|
-
currencyCode = _ref2.currencyCode,
|
|
1765
|
-
locale = _ref2.locale;
|
|
1766
|
-
var hasDiscount = baseAmount > amount;
|
|
1767
|
-
var formatDiscount = new Intl.NumberFormat(locale, {
|
|
1768
|
-
style: 'percent'
|
|
1769
|
-
});
|
|
1770
|
-
var discount = hasDiscount ? formatDiscount.format((baseAmount - amount) / baseAmount) : null;
|
|
1771
|
-
var price = formatPrice({
|
|
1772
|
-
amount: amount,
|
|
1773
|
-
currencyCode: currencyCode,
|
|
1774
|
-
locale: locale
|
|
1775
|
-
});
|
|
1776
|
-
var basePrice = hasDiscount ? formatPrice({
|
|
1777
|
-
amount: baseAmount,
|
|
1778
|
-
currencyCode: currencyCode,
|
|
1779
|
-
locale: locale
|
|
1780
|
-
}) : null;
|
|
1781
|
-
return {
|
|
1782
|
-
price: price,
|
|
1783
|
-
basePrice: basePrice,
|
|
1784
|
-
discount: discount
|
|
1785
|
-
};
|
|
1821
|
+
doRegisterComponent(CategoryMedia, customCategoryMediaMeta != null ? customCategoryMediaMeta : categoryMediaMeta);
|
|
1786
1822
|
}
|
|
1787
|
-
function usePrice(data) {
|
|
1788
|
-
var _ref3 = data != null ? data : {},
|
|
1789
|
-
amount = _ref3.amount,
|
|
1790
|
-
baseAmount = _ref3.baseAmount,
|
|
1791
|
-
currencyCode = _ref3.currencyCode;
|
|
1792
1823
|
|
|
1793
|
-
|
|
1794
|
-
locale = _useCommerce.locale;
|
|
1824
|
+
var fetcher$3 = SWRFetcher;
|
|
1795
1825
|
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
return baseAmount ? formatVariantPrice({
|
|
1799
|
-
amount: amount,
|
|
1800
|
-
baseAmount: baseAmount,
|
|
1801
|
-
currencyCode: currencyCode,
|
|
1802
|
-
locale: locale
|
|
1803
|
-
}) : formatPrice({
|
|
1804
|
-
amount: amount,
|
|
1805
|
-
currencyCode: currencyCode,
|
|
1806
|
-
locale: locale
|
|
1807
|
-
});
|
|
1808
|
-
}, [amount, baseAmount, currencyCode]);
|
|
1809
|
-
return typeof value === 'string' ? {
|
|
1810
|
-
price: value
|
|
1811
|
-
} : value;
|
|
1812
|
-
}
|
|
1826
|
+
var fn$3 = function fn(provider) {
|
|
1827
|
+
var _provider$products;
|
|
1813
1828
|
|
|
1814
|
-
|
|
1815
|
-
|
|
1829
|
+
return (_provider$products = provider.products) == null ? void 0 : _provider$products.useProduct;
|
|
1830
|
+
};
|
|
1816
1831
|
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1832
|
+
var useProduct$1 = function useProduct(input) {
|
|
1833
|
+
var hook = useHook(fn$3);
|
|
1834
|
+
return useSWRHook(_extends({
|
|
1835
|
+
fetcher: fetcher$3
|
|
1836
|
+
}, hook))(input);
|
|
1820
1837
|
};
|
|
1821
1838
|
|
|
1822
|
-
var
|
|
1823
|
-
name: "plasmic-commerce-product-
|
|
1824
|
-
displayName: "Product
|
|
1825
|
-
props: {
|
|
1839
|
+
var productBoxMeta = {
|
|
1840
|
+
name: "plasmic-commerce-product-box",
|
|
1841
|
+
displayName: "Product Box",
|
|
1842
|
+
props: {
|
|
1843
|
+
children: {
|
|
1844
|
+
type: "slot",
|
|
1845
|
+
defaultValue: [{
|
|
1846
|
+
type: "vbox",
|
|
1847
|
+
children: [{
|
|
1848
|
+
type: "component",
|
|
1849
|
+
name: "plasmic-commerce-product-text-field",
|
|
1850
|
+
props: {
|
|
1851
|
+
field: "name"
|
|
1852
|
+
}
|
|
1853
|
+
}, {
|
|
1854
|
+
type: "component",
|
|
1855
|
+
name: "plasmic-commerce-product-media"
|
|
1856
|
+
}],
|
|
1857
|
+
styles: {
|
|
1858
|
+
width: "100%",
|
|
1859
|
+
minWidth: 0
|
|
1860
|
+
}
|
|
1861
|
+
}]
|
|
1862
|
+
},
|
|
1863
|
+
noLayout: "boolean",
|
|
1864
|
+
id: {
|
|
1865
|
+
type: "string",
|
|
1866
|
+
description: "Fetch a product by its slug or ID"
|
|
1867
|
+
}
|
|
1868
|
+
},
|
|
1826
1869
|
importPath: "@plasmicpkgs/commerce",
|
|
1827
|
-
importName: "
|
|
1870
|
+
importName: "ProductBox"
|
|
1828
1871
|
};
|
|
1829
|
-
function
|
|
1830
|
-
var
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
var form = reactHookForm.useFormContext();
|
|
1835
|
-
var watchProductVariant = form == null ? void 0 : form.watch("ProductVariant", (_product$variants$0$i = product.variants[0].id) != null ? _product$variants$0$i : "");
|
|
1872
|
+
function ProductBox(props) {
|
|
1873
|
+
var className = props.className,
|
|
1874
|
+
children = props.children,
|
|
1875
|
+
noLayout = props.noLayout,
|
|
1876
|
+
id = props.id;
|
|
1836
1877
|
|
|
1837
|
-
var
|
|
1838
|
-
|
|
1839
|
-
currencyCode: product ? product.price.currencyCode : 'USD'
|
|
1878
|
+
var _useProduct = useProduct$1({
|
|
1879
|
+
id: id
|
|
1840
1880
|
}),
|
|
1841
|
-
|
|
1881
|
+
data = _useProduct.data,
|
|
1882
|
+
error = _useProduct.error,
|
|
1883
|
+
isLoading = _useProduct.isLoading;
|
|
1842
1884
|
|
|
1843
|
-
|
|
1885
|
+
if (!id) {
|
|
1886
|
+
return React__default.createElement("span", null, "You must set the id prop");
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
if (error) {
|
|
1890
|
+
throw new CommerceError({
|
|
1891
|
+
message: error.message,
|
|
1892
|
+
code: error.code
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
if (isLoading) {
|
|
1897
|
+
return React__default.createElement("span", null, "Loading...");
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
if (!data) {
|
|
1901
|
+
throw new Error("Product not found!");
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
var renderedData = React__default.createElement(ProductProvider, {
|
|
1905
|
+
product: data
|
|
1906
|
+
}, children);
|
|
1907
|
+
return noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
|
|
1844
1908
|
className: className
|
|
1845
|
-
},
|
|
1909
|
+
}, renderedData);
|
|
1846
1910
|
}
|
|
1847
|
-
function
|
|
1911
|
+
function registerProductBox(loader, customProductBoxMeta) {
|
|
1848
1912
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1849
1913
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1850
1914
|
};
|
|
1851
1915
|
|
|
1852
|
-
doRegisterComponent(
|
|
1916
|
+
doRegisterComponent(ProductBox, customProductBoxMeta != null ? customProductBoxMeta : productBoxMeta);
|
|
1853
1917
|
}
|
|
1854
1918
|
|
|
1855
|
-
var
|
|
1856
|
-
|
|
1857
|
-
|
|
1919
|
+
var fetcher$4 = SWRFetcher;
|
|
1920
|
+
|
|
1921
|
+
var fn$4 = function fn(provider) {
|
|
1922
|
+
var _provider$products;
|
|
1923
|
+
|
|
1924
|
+
return (_provider$products = provider.products) == null ? void 0 : _provider$products.useSearch;
|
|
1925
|
+
};
|
|
1926
|
+
|
|
1927
|
+
var useSearch = function useSearch(input) {
|
|
1928
|
+
var hook = useHook(fn$4);
|
|
1929
|
+
return useSWRHook(_extends({
|
|
1930
|
+
fetcher: fetcher$4
|
|
1931
|
+
}, hook))(input);
|
|
1932
|
+
};
|
|
1933
|
+
|
|
1934
|
+
var fetcher$5 = SWRFetcher;
|
|
1935
|
+
|
|
1936
|
+
var fn$5 = function fn(provider) {
|
|
1937
|
+
var _provider$site;
|
|
1938
|
+
|
|
1939
|
+
return (_provider$site = provider.site) == null ? void 0 : _provider$site.useBrands;
|
|
1940
|
+
};
|
|
1941
|
+
|
|
1942
|
+
var useBrands = function useBrands(input) {
|
|
1943
|
+
var hook = useHook(fn$5);
|
|
1944
|
+
return useSWRHook(_extends({
|
|
1945
|
+
fetcher: fetcher$5
|
|
1946
|
+
}, hook))(input);
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
var productCollectionMeta = {
|
|
1950
|
+
name: "plasmic-commerce-product-collection",
|
|
1951
|
+
displayName: "Product Collection",
|
|
1858
1952
|
props: {
|
|
1859
1953
|
children: {
|
|
1860
1954
|
type: "slot",
|
|
1861
1955
|
defaultValue: [{
|
|
1862
|
-
type: "
|
|
1863
|
-
|
|
1864
|
-
|
|
1956
|
+
type: "vbox",
|
|
1957
|
+
children: [{
|
|
1958
|
+
type: "component",
|
|
1959
|
+
name: "plasmic-commerce-product-text-field",
|
|
1960
|
+
props: {
|
|
1961
|
+
field: "name"
|
|
1962
|
+
}
|
|
1963
|
+
}, {
|
|
1964
|
+
type: "component",
|
|
1965
|
+
name: "plasmic-commerce-product-media"
|
|
1966
|
+
}],
|
|
1967
|
+
styles: {
|
|
1968
|
+
width: "100%",
|
|
1969
|
+
minWidth: 0
|
|
1865
1970
|
}
|
|
1866
1971
|
}]
|
|
1867
|
-
}
|
|
1972
|
+
},
|
|
1973
|
+
emptyMessage: {
|
|
1974
|
+
type: "slot",
|
|
1975
|
+
defaultValue: {
|
|
1976
|
+
type: "text",
|
|
1977
|
+
value: "No product found!"
|
|
1978
|
+
}
|
|
1979
|
+
},
|
|
1980
|
+
loadingMessage: {
|
|
1981
|
+
type: "slot",
|
|
1982
|
+
defaultValue: {
|
|
1983
|
+
type: "text",
|
|
1984
|
+
value: "Loading..."
|
|
1985
|
+
}
|
|
1986
|
+
},
|
|
1987
|
+
count: "number",
|
|
1988
|
+
category: {
|
|
1989
|
+
type: "choice",
|
|
1990
|
+
options: function options(props, ctx) {
|
|
1991
|
+
var _ctx$categories$map;
|
|
1992
|
+
|
|
1993
|
+
return (_ctx$categories$map = ctx == null ? void 0 : ctx.categories.map(function (category) {
|
|
1994
|
+
return {
|
|
1995
|
+
label: category.name,
|
|
1996
|
+
value: category.id
|
|
1997
|
+
};
|
|
1998
|
+
})) != null ? _ctx$categories$map : [];
|
|
1999
|
+
},
|
|
2000
|
+
hidden: function hidden(props, ctx) {
|
|
2001
|
+
return !!(ctx != null && ctx.hasCategoryCtx);
|
|
2002
|
+
}
|
|
2003
|
+
},
|
|
2004
|
+
includeSubCategories: {
|
|
2005
|
+
type: "boolean",
|
|
2006
|
+
hidden: function hidden(props, ctx) {
|
|
2007
|
+
var _ctx$features;
|
|
2008
|
+
|
|
2009
|
+
return !(ctx != null && (_ctx$features = ctx.features) != null && _ctx$features.includeSubCategories);
|
|
2010
|
+
}
|
|
2011
|
+
},
|
|
2012
|
+
brand: {
|
|
2013
|
+
type: "choice",
|
|
2014
|
+
options: function options(props, ctx) {
|
|
2015
|
+
var _ctx$brands$map;
|
|
2016
|
+
|
|
2017
|
+
return (_ctx$brands$map = ctx == null ? void 0 : ctx.brands.map(function (brand) {
|
|
2018
|
+
return {
|
|
2019
|
+
label: brand.name,
|
|
2020
|
+
value: brand.entityId
|
|
2021
|
+
};
|
|
2022
|
+
})) != null ? _ctx$brands$map : [];
|
|
2023
|
+
}
|
|
2024
|
+
},
|
|
2025
|
+
search: {
|
|
2026
|
+
type: "string"
|
|
2027
|
+
},
|
|
2028
|
+
sort: {
|
|
2029
|
+
type: "choice",
|
|
2030
|
+
options: [{
|
|
2031
|
+
label: "Trending",
|
|
2032
|
+
value: "trending-desc"
|
|
2033
|
+
}, {
|
|
2034
|
+
label: "New Arrivals",
|
|
2035
|
+
value: "latest-desc"
|
|
2036
|
+
}, {
|
|
2037
|
+
label: "Price: Low to High",
|
|
2038
|
+
value: "price-asc"
|
|
2039
|
+
}, {
|
|
2040
|
+
label: "Price: High to Low",
|
|
2041
|
+
value: "price-desc"
|
|
2042
|
+
}]
|
|
2043
|
+
},
|
|
2044
|
+
noLayout: "boolean"
|
|
2045
|
+
},
|
|
2046
|
+
defaultStyles: {
|
|
2047
|
+
display: "grid",
|
|
2048
|
+
gridTemplateColumns: "1fr 1fr 1fr 1fr",
|
|
2049
|
+
gridRowGap: "8px",
|
|
2050
|
+
gridColumnGap: "8px",
|
|
2051
|
+
padding: "8px",
|
|
2052
|
+
maxWidth: "100%"
|
|
1868
2053
|
},
|
|
1869
2054
|
importPath: "@plasmicpkgs/commerce",
|
|
1870
|
-
importName: "
|
|
2055
|
+
importName: "ProductCollection"
|
|
1871
2056
|
};
|
|
1872
|
-
function
|
|
2057
|
+
function ProductCollection(props) {
|
|
2058
|
+
var _categoryCtx$id;
|
|
2059
|
+
|
|
1873
2060
|
var className = props.className,
|
|
1874
|
-
children = props.children
|
|
1875
|
-
|
|
1876
|
-
|
|
2061
|
+
children = props.children,
|
|
2062
|
+
count = props.count,
|
|
2063
|
+
category = props.category,
|
|
2064
|
+
includeSubCategories = props.includeSubCategories,
|
|
2065
|
+
brand = props.brand,
|
|
2066
|
+
noLayout = props.noLayout,
|
|
2067
|
+
setControlContextData = props.setControlContextData,
|
|
2068
|
+
emptyMessage = props.emptyMessage,
|
|
2069
|
+
loadingMessage = props.loadingMessage,
|
|
2070
|
+
search = props.search,
|
|
2071
|
+
sort = props.sort;
|
|
2072
|
+
|
|
2073
|
+
var _useCategories = useCategories(),
|
|
2074
|
+
categories = _useCategories.data,
|
|
2075
|
+
isCategoriesLoading = _useCategories.isLoading;
|
|
2076
|
+
|
|
2077
|
+
var _useBrands = useBrands(),
|
|
2078
|
+
brands = _useBrands.data,
|
|
2079
|
+
isBrandsLoading = _useBrands.isLoading;
|
|
2080
|
+
|
|
2081
|
+
var categoryCtx = useCategoryContext();
|
|
2082
|
+
|
|
2083
|
+
var _useSearch = useSearch({
|
|
2084
|
+
categoryId: (_categoryCtx$id = categoryCtx == null ? void 0 : categoryCtx.id) != null ? _categoryCtx$id : category,
|
|
2085
|
+
brandId: brand,
|
|
2086
|
+
count: count,
|
|
2087
|
+
categories: categories != null ? categories : [],
|
|
2088
|
+
includeSubCategories: includeSubCategories,
|
|
2089
|
+
search: search,
|
|
2090
|
+
sort: sort
|
|
2091
|
+
}),
|
|
2092
|
+
data = _useSearch.data,
|
|
2093
|
+
isSearchLoading = _useSearch.isLoading;
|
|
2094
|
+
|
|
2095
|
+
var features = useCommerceExtraFeatures();
|
|
2096
|
+
|
|
2097
|
+
if (categories && brands) {
|
|
2098
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
2099
|
+
categories: categories,
|
|
2100
|
+
brands: brands,
|
|
2101
|
+
features: features,
|
|
2102
|
+
hasCategoryCtx: !!categoryCtx
|
|
2103
|
+
});
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
var renderedData = data == null ? void 0 : data.products.map(function (product, i) {
|
|
2107
|
+
return React__default.createElement(ProductProvider, {
|
|
2108
|
+
product: product,
|
|
2109
|
+
key: product.id
|
|
2110
|
+
}, host.repeatedElement(i === 0, children));
|
|
2111
|
+
});
|
|
2112
|
+
|
|
2113
|
+
if ([isSearchLoading, isBrandsLoading, isCategoriesLoading].includes(true)) {
|
|
2114
|
+
return React__default.isValidElement(loadingMessage) ? loadingMessage : null;
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
if (!data || data.products.length === 0) {
|
|
2118
|
+
return React__default.isValidElement(emptyMessage) ? emptyMessage : null;
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
return noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
|
|
1877
2122
|
className: className
|
|
1878
|
-
},
|
|
1879
|
-
name: "ProductQuantity",
|
|
1880
|
-
defaultValue: 1,
|
|
1881
|
-
control: form == null ? void 0 : form.control,
|
|
1882
|
-
render: function render(_ref) {
|
|
1883
|
-
var field = _ref.field;
|
|
1884
|
-
return React__default.isValidElement(children) ? React__default.cloneElement(children, _extends({}, children.props, field, {
|
|
1885
|
-
name: "ProductQuantity"
|
|
1886
|
-
})) : React__default.createElement(React__default.Fragment, null);
|
|
1887
|
-
}
|
|
1888
|
-
}));
|
|
2123
|
+
}, renderedData);
|
|
1889
2124
|
}
|
|
1890
|
-
function
|
|
2125
|
+
function registerProductCollection(loader, customProductCollectionMeta) {
|
|
1891
2126
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1892
2127
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1893
2128
|
};
|
|
1894
2129
|
|
|
1895
|
-
doRegisterComponent(
|
|
2130
|
+
doRegisterComponent(ProductCollection, customProductCollectionMeta != null ? customProductCollectionMeta : productCollectionMeta);
|
|
1896
2131
|
}
|
|
1897
2132
|
|
|
1898
|
-
var
|
|
1899
|
-
name: "plasmic-commerce-product-
|
|
1900
|
-
displayName: "Product
|
|
2133
|
+
var productLinkMeta = {
|
|
2134
|
+
name: "plasmic-commerce-product-link",
|
|
2135
|
+
displayName: "Product Link",
|
|
1901
2136
|
props: {
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
2137
|
+
children: "slot",
|
|
2138
|
+
linkDest: {
|
|
2139
|
+
type: "string",
|
|
2140
|
+
defaultValueHint: "products/{slug}",
|
|
2141
|
+
description: "Set the link destination. You can use {slug} to replace by the product slug"
|
|
1905
2142
|
}
|
|
1906
2143
|
},
|
|
1907
2144
|
importPath: "@plasmicpkgs/commerce",
|
|
1908
|
-
importName: "
|
|
2145
|
+
importName: "ProductLink"
|
|
1909
2146
|
};
|
|
1910
|
-
function
|
|
2147
|
+
function ProductLink(props) {
|
|
1911
2148
|
var className = props.className,
|
|
1912
|
-
|
|
2149
|
+
children = props.children,
|
|
2150
|
+
linkDest = props.linkDest;
|
|
1913
2151
|
var product = useProduct();
|
|
1914
2152
|
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
className: className
|
|
1918
|
-
}, "Fake Product Field");
|
|
1919
|
-
}
|
|
2153
|
+
var resolveLink = function resolveLink(linkDest) {
|
|
2154
|
+
var _linkDest$match;
|
|
1920
2155
|
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
}, "Unknown Product Field");
|
|
1925
|
-
}
|
|
2156
|
+
if (!linkDest) {
|
|
2157
|
+
return undefined;
|
|
2158
|
+
}
|
|
1926
2159
|
|
|
1927
|
-
|
|
2160
|
+
var regex = /{[^}]*}/;
|
|
2161
|
+
var regexAll = new RegExp(regex, "g");
|
|
2162
|
+
var matches = (_linkDest$match = linkDest.match(regexAll)) != null ? _linkDest$match : [];
|
|
2163
|
+
var resolvedLink = linkDest;
|
|
1928
2164
|
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
2165
|
+
for (var _iterator = _createForOfIteratorHelperLoose(matches), _step; !(_step = _iterator()).done;) {
|
|
2166
|
+
var match = _step.value;
|
|
2167
|
+
var field = match.slice(1, -1);
|
|
2168
|
+
|
|
2169
|
+
if (!product || !(field in product)) {
|
|
2170
|
+
return undefined;
|
|
1934
2171
|
}
|
|
1935
|
-
}) : React__default.createElement("div", {
|
|
1936
|
-
className: className
|
|
1937
|
-
}, product.description);
|
|
1938
|
-
} else {
|
|
1939
|
-
value = product[field];
|
|
1940
|
-
}
|
|
1941
2172
|
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
2173
|
+
resolvedLink = resolvedLink.replace(regex, product[field]);
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
return resolvedLink;
|
|
2177
|
+
};
|
|
2178
|
+
|
|
2179
|
+
return React__default.createElement("a", {
|
|
2180
|
+
className: className,
|
|
2181
|
+
href: resolveLink(linkDest),
|
|
2182
|
+
style: {
|
|
2183
|
+
color: "inherit",
|
|
2184
|
+
textDecoration: "inherit"
|
|
2185
|
+
}
|
|
2186
|
+
}, children);
|
|
1945
2187
|
}
|
|
1946
|
-
function
|
|
2188
|
+
function registerProductLink(loader, customProductLinkMeta) {
|
|
1947
2189
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1948
2190
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1949
2191
|
};
|
|
1950
2192
|
|
|
1951
|
-
doRegisterComponent(
|
|
2193
|
+
doRegisterComponent(ProductLink, customProductLinkMeta != null ? customProductLinkMeta : productLinkMeta);
|
|
1952
2194
|
}
|
|
1953
2195
|
|
|
1954
|
-
var
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
2196
|
+
var placeholderImage = "https://static1.plasmic.app/commerce/lightweight-jacket-0.png";
|
|
2197
|
+
var productMediaMeta = {
|
|
2198
|
+
name: "plasmic-commerce-product-media",
|
|
2199
|
+
displayName: "Product Media",
|
|
2200
|
+
props: {
|
|
2201
|
+
mediaIndex: "number"
|
|
2202
|
+
},
|
|
1958
2203
|
importPath: "@plasmicpkgs/commerce",
|
|
1959
|
-
importName: "
|
|
2204
|
+
importName: "ProductMedia"
|
|
1960
2205
|
};
|
|
1961
|
-
function
|
|
1962
|
-
var
|
|
2206
|
+
function ProductMedia(props) {
|
|
2207
|
+
var _image$url;
|
|
1963
2208
|
|
|
1964
|
-
var className = props.className
|
|
2209
|
+
var className = props.className,
|
|
2210
|
+
_props$mediaIndex = props.mediaIndex,
|
|
2211
|
+
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex;
|
|
1965
2212
|
var product = useProduct();
|
|
1966
|
-
var
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
var field = _ref.field;
|
|
1975
|
-
return React__default.createElement("select", Object.assign({
|
|
1976
|
-
className: className
|
|
1977
|
-
}, field), (_product$variants$map = product == null ? void 0 : product.variants.map(function (variant) {
|
|
1978
|
-
return React__default.createElement("option", {
|
|
1979
|
-
value: variant.id
|
|
1980
|
-
}, variant.name);
|
|
1981
|
-
})) != null ? _product$variants$map : React__default.createElement("option", null, "Product Variant Placeholder"));
|
|
1982
|
-
}
|
|
2213
|
+
var sliderContext = useProductSliderContext();
|
|
2214
|
+
var image = product == null ? void 0 : product.images[sliderContext != null ? sliderContext : mediaIndex];
|
|
2215
|
+
return React__default.createElement("img", {
|
|
2216
|
+
alt: (product == null ? void 0 : product.name) || "Product Image",
|
|
2217
|
+
src: product ? (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "" : placeholderImage,
|
|
2218
|
+
loading: "lazy",
|
|
2219
|
+
className: className
|
|
1983
2220
|
});
|
|
1984
2221
|
}
|
|
1985
|
-
function
|
|
2222
|
+
function registerProductMedia(loader, customProductMediaMeta) {
|
|
1986
2223
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1987
2224
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1988
2225
|
};
|
|
1989
2226
|
|
|
1990
|
-
doRegisterComponent(
|
|
2227
|
+
doRegisterComponent(ProductMedia, customProductMediaMeta != null ? customProductMediaMeta : productMediaMeta);
|
|
1991
2228
|
}
|
|
1992
2229
|
|
|
1993
|
-
var
|
|
1994
|
-
var
|
|
1995
|
-
var options, cartId, fetch;
|
|
1996
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1997
|
-
while (1) {
|
|
1998
|
-
switch (_context.prev = _context.next) {
|
|
1999
|
-
case 0:
|
|
2000
|
-
options = _ref.options, cartId = _ref.input.cartId, fetch = _ref.fetch;
|
|
2001
|
-
|
|
2002
|
-
if (!cartId) {
|
|
2003
|
-
_context.next = 7;
|
|
2004
|
-
break;
|
|
2005
|
-
}
|
|
2006
|
-
|
|
2007
|
-
_context.next = 4;
|
|
2008
|
-
return fetch(options);
|
|
2009
|
-
|
|
2010
|
-
case 4:
|
|
2011
|
-
_context.t0 = _context.sent;
|
|
2012
|
-
_context.next = 8;
|
|
2013
|
-
break;
|
|
2014
|
-
|
|
2015
|
-
case 7:
|
|
2016
|
-
_context.t0 = null;
|
|
2017
|
-
|
|
2018
|
-
case 8:
|
|
2019
|
-
return _context.abrupt("return", _context.t0);
|
|
2020
|
-
|
|
2021
|
-
case 9:
|
|
2022
|
-
case "end":
|
|
2023
|
-
return _context.stop();
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
}, _callee);
|
|
2027
|
-
}));
|
|
2028
|
-
|
|
2029
|
-
return function fetcher(_x) {
|
|
2030
|
-
return _ref2.apply(this, arguments);
|
|
2031
|
-
};
|
|
2032
|
-
}();
|
|
2033
|
-
|
|
2034
|
-
var fn$5 = function fn(provider) {
|
|
2035
|
-
var _provider$cart;
|
|
2036
|
-
|
|
2037
|
-
return (_provider$cart = provider.cart) == null ? void 0 : _provider$cart.useCart;
|
|
2038
|
-
};
|
|
2039
|
-
|
|
2040
|
-
var useCart = function useCart(input) {
|
|
2041
|
-
var _hook$fetcher;
|
|
2042
|
-
|
|
2043
|
-
var hook = useHook(fn$5);
|
|
2044
|
-
|
|
2045
|
-
var _useCommerce = useCommerce(),
|
|
2046
|
-
cartCookie = _useCommerce.cartCookie;
|
|
2047
|
-
|
|
2048
|
-
var fetcherFn = (_hook$fetcher = hook.fetcher) != null ? _hook$fetcher : fetcher$5;
|
|
2049
|
-
|
|
2050
|
-
var wrapper = function wrapper(context) {
|
|
2051
|
-
context.input.cartId = Cookies.get(cartCookie);
|
|
2052
|
-
return fetcherFn(context);
|
|
2053
|
-
};
|
|
2230
|
+
var getProductPrice = function getProductPrice(product, variantId) {
|
|
2231
|
+
var _product$variants$fin, _product$variants$fin2;
|
|
2054
2232
|
|
|
2055
|
-
return
|
|
2056
|
-
|
|
2057
|
-
}))
|
|
2233
|
+
return (_product$variants$fin = (_product$variants$fin2 = product.variants.find(function (variant) {
|
|
2234
|
+
return variant.id === variantId;
|
|
2235
|
+
})) == null ? void 0 : _product$variants$fin2.price) != null ? _product$variants$fin : product.price.value;
|
|
2058
2236
|
};
|
|
2059
2237
|
|
|
2060
|
-
var
|
|
2061
|
-
name: "plasmic-commerce-
|
|
2062
|
-
displayName: "
|
|
2063
|
-
props: {
|
|
2064
|
-
field: {
|
|
2065
|
-
type: "choice",
|
|
2066
|
-
options: ["Size", "Total Price"]
|
|
2067
|
-
},
|
|
2068
|
-
hideIfIsEmpty: {
|
|
2069
|
-
type: "boolean"
|
|
2070
|
-
}
|
|
2071
|
-
},
|
|
2238
|
+
var productPriceMeta = {
|
|
2239
|
+
name: "plasmic-commerce-product-price",
|
|
2240
|
+
displayName: "Product Price",
|
|
2241
|
+
props: {},
|
|
2072
2242
|
importPath: "@plasmicpkgs/commerce",
|
|
2073
|
-
importName: "
|
|
2243
|
+
importName: "ProductPriceComponent"
|
|
2074
2244
|
};
|
|
2075
|
-
function
|
|
2076
|
-
var
|
|
2077
|
-
|
|
2078
|
-
var className = props.className,
|
|
2079
|
-
field = props.field,
|
|
2080
|
-
hideIfIsEmpty = props.hideIfIsEmpty;
|
|
2081
|
-
|
|
2082
|
-
var _useCart = useCart(),
|
|
2083
|
-
data = _useCart.data;
|
|
2084
|
-
|
|
2085
|
-
var _usePrice = usePrice({
|
|
2086
|
-
amount: (_data$totalPrice = data == null ? void 0 : data.totalPrice) != null ? _data$totalPrice : 0,
|
|
2087
|
-
currencyCode: (_data$currency$code = data == null ? void 0 : data.currency.code) != null ? _data$currency$code : "USD"
|
|
2088
|
-
}),
|
|
2089
|
-
price = _usePrice.price;
|
|
2090
|
-
|
|
2091
|
-
if (!field) {
|
|
2092
|
-
return React__default.createElement("p", null, "You must set the field prop");
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
|
-
var value;
|
|
2245
|
+
function ProductPriceComponent(props) {
|
|
2246
|
+
var _product$price;
|
|
2096
2247
|
|
|
2097
|
-
|
|
2098
|
-
|
|
2248
|
+
var className = props.className;
|
|
2249
|
+
var product = useProduct();
|
|
2250
|
+
var form = reactHookForm.useFormContext();
|
|
2251
|
+
var watchProductVariant = form == null ? void 0 : form.watch("ProductVariant", (_product$price = product.price) != null ? _product$price : "");
|
|
2099
2252
|
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
}
|
|
2253
|
+
var _usePrice = usePrice({
|
|
2254
|
+
amount: product ? getProductPrice(product, watchProductVariant) : 0,
|
|
2255
|
+
currencyCode: product ? product.price.currencyCode : "USD"
|
|
2256
|
+
}),
|
|
2257
|
+
price = _usePrice.price;
|
|
2104
2258
|
|
|
2105
|
-
return
|
|
2259
|
+
return React__default.createElement("span", {
|
|
2106
2260
|
className: className
|
|
2107
|
-
},
|
|
2261
|
+
}, price);
|
|
2108
2262
|
}
|
|
2109
|
-
function
|
|
2263
|
+
function registerProductPrice(loader, customProductPriceMeta) {
|
|
2110
2264
|
var doRegisterComponent = function doRegisterComponent() {
|
|
2111
2265
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2112
2266
|
};
|
|
2113
2267
|
|
|
2114
|
-
doRegisterComponent(
|
|
2268
|
+
doRegisterComponent(ProductPriceComponent, customProductPriceMeta != null ? customProductPriceMeta : productPriceMeta);
|
|
2115
2269
|
}
|
|
2116
2270
|
|
|
2117
|
-
var
|
|
2118
|
-
name: "plasmic-commerce-
|
|
2119
|
-
displayName: "
|
|
2271
|
+
var productQuantityMeta = {
|
|
2272
|
+
name: "plasmic-commerce-product-quantity",
|
|
2273
|
+
displayName: "Product Quantity",
|
|
2120
2274
|
props: {
|
|
2121
2275
|
children: {
|
|
2122
2276
|
type: "slot",
|
|
2123
2277
|
defaultValue: [{
|
|
2124
|
-
type: "
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
name: "plasmic-commerce-category-field",
|
|
2128
|
-
props: {
|
|
2129
|
-
field: "name"
|
|
2130
|
-
}
|
|
2131
|
-
}, {
|
|
2132
|
-
type: "component",
|
|
2133
|
-
name: "plasmic-commerce-product-collection"
|
|
2134
|
-
}],
|
|
2135
|
-
styles: {
|
|
2136
|
-
width: "100%",
|
|
2137
|
-
minWidth: 0
|
|
2278
|
+
type: "input",
|
|
2279
|
+
attrs: {
|
|
2280
|
+
value: "1"
|
|
2138
2281
|
}
|
|
2139
2282
|
}]
|
|
2283
|
+
}
|
|
2284
|
+
},
|
|
2285
|
+
importPath: "@plasmicpkgs/commerce",
|
|
2286
|
+
importName: "ProductQuantity"
|
|
2287
|
+
};
|
|
2288
|
+
function ProductQuantity(props) {
|
|
2289
|
+
var className = props.className,
|
|
2290
|
+
children = props.children;
|
|
2291
|
+
var form = reactHookForm.useFormContext();
|
|
2292
|
+
return React__default.createElement("div", {
|
|
2293
|
+
className: className
|
|
2294
|
+
}, React__default.createElement(reactHookForm.Controller, {
|
|
2295
|
+
name: "ProductQuantity",
|
|
2296
|
+
defaultValue: 1,
|
|
2297
|
+
control: form == null ? void 0 : form.control,
|
|
2298
|
+
render: function render(_ref) {
|
|
2299
|
+
var field = _ref.field;
|
|
2300
|
+
return React__default.isValidElement(children) ? React__default.cloneElement(children, _extends({}, children.props, field, {
|
|
2301
|
+
name: "ProductQuantity"
|
|
2302
|
+
})) : React__default.createElement(React__default.Fragment, null);
|
|
2303
|
+
}
|
|
2304
|
+
}));
|
|
2305
|
+
}
|
|
2306
|
+
function registerProductQuantity(loader, customProductQuantityMeta) {
|
|
2307
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
2308
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2309
|
+
};
|
|
2310
|
+
|
|
2311
|
+
doRegisterComponent(ProductQuantity, customProductQuantityMeta != null ? customProductQuantityMeta : productQuantityMeta);
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
var productSliderMeta = {
|
|
2315
|
+
name: "plasmic-commerce-product-slider",
|
|
2316
|
+
displayName: "Product Slider",
|
|
2317
|
+
props: {
|
|
2318
|
+
thumbsVisible: {
|
|
2319
|
+
type: "number",
|
|
2320
|
+
description: "Number of thumbs visible",
|
|
2321
|
+
defaultValue: 4,
|
|
2322
|
+
defaultValueHint: 4
|
|
2140
2323
|
},
|
|
2141
|
-
|
|
2142
|
-
type: "boolean"
|
|
2143
|
-
},
|
|
2144
|
-
emptyMessage: {
|
|
2324
|
+
slideContainer: {
|
|
2145
2325
|
type: "slot",
|
|
2146
2326
|
defaultValue: {
|
|
2147
|
-
type: "
|
|
2148
|
-
|
|
2327
|
+
type: "vbox",
|
|
2328
|
+
children: [{
|
|
2329
|
+
type: "component",
|
|
2330
|
+
name: "plasmic-commerce-product-media"
|
|
2331
|
+
}]
|
|
2149
2332
|
}
|
|
2150
2333
|
},
|
|
2151
|
-
|
|
2334
|
+
thumbsContainer: {
|
|
2152
2335
|
type: "slot",
|
|
2153
2336
|
defaultValue: {
|
|
2154
|
-
type: "
|
|
2155
|
-
|
|
2337
|
+
type: "hbox",
|
|
2338
|
+
children: [{
|
|
2339
|
+
type: "component",
|
|
2340
|
+
name: "plasmic-commerce-product-media"
|
|
2341
|
+
}]
|
|
2156
2342
|
}
|
|
2157
2343
|
},
|
|
2158
|
-
|
|
2159
|
-
type: "
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
return (_ctx$categories$map = ctx == null ? void 0 : ctx.categories.map(function (category) {
|
|
2164
|
-
return {
|
|
2165
|
-
label: category.name,
|
|
2166
|
-
value: category.id
|
|
2167
|
-
};
|
|
2168
|
-
})) != null ? _ctx$categories$map : [];
|
|
2169
|
-
}
|
|
2344
|
+
slideSelected: {
|
|
2345
|
+
type: "number",
|
|
2346
|
+
defaultValue: 0,
|
|
2347
|
+
defaultValueHint: 0,
|
|
2348
|
+
description: "Current slide selected"
|
|
2170
2349
|
}
|
|
2171
2350
|
},
|
|
2172
|
-
defaultStyles: {
|
|
2173
|
-
display: "grid",
|
|
2174
|
-
gridTemplateColumns: "1fr",
|
|
2175
|
-
gridRowGap: "8px",
|
|
2176
|
-
padding: "8px",
|
|
2177
|
-
maxWidth: "100%"
|
|
2178
|
-
},
|
|
2179
2351
|
importPath: "@plasmicpkgs/commerce",
|
|
2180
|
-
importName: "
|
|
2352
|
+
importName: "ProductSlider"
|
|
2181
2353
|
};
|
|
2182
|
-
function
|
|
2183
|
-
var
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
var
|
|
2191
|
-
var inEditor = host.usePlasmicCanvasContext();
|
|
2192
|
-
|
|
2193
|
-
var _useCategories = useCategories(),
|
|
2194
|
-
allCategories = _useCategories.data,
|
|
2195
|
-
isAllCategoriesLoading = _useCategories.isLoading;
|
|
2196
|
-
|
|
2197
|
-
var _useCategories2 = useCategories({
|
|
2198
|
-
categoryId: selectedCategory,
|
|
2199
|
-
topologicalSort: !selectedCategory && (features == null ? void 0 : features.includeSubCategories),
|
|
2200
|
-
addIsEmptyField: !!inEditor
|
|
2201
|
-
}),
|
|
2202
|
-
categories = _useCategories2.data,
|
|
2203
|
-
isLoading = _useCategories2.isLoading;
|
|
2204
|
-
|
|
2205
|
-
if (allCategories) {
|
|
2206
|
-
setControlContextData == null ? void 0 : setControlContextData({
|
|
2207
|
-
categories: allCategories
|
|
2208
|
-
});
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
var firstCategoryNotEmpty = categories == null ? void 0 : categories.find(function (category) {
|
|
2212
|
-
return !category.isEmpty;
|
|
2213
|
-
});
|
|
2214
|
-
var renderedData = categories == null ? void 0 : categories.map(function (category, i) {
|
|
2215
|
-
return React__default.createElement(CategoryProvider, {
|
|
2216
|
-
category: category,
|
|
2217
|
-
key: category.id
|
|
2218
|
-
}, host.repeatedElement(firstCategoryNotEmpty ? category === firstCategoryNotEmpty : i === 0, children));
|
|
2219
|
-
});
|
|
2220
|
-
|
|
2221
|
-
if ([isAllCategoriesLoading, isLoading].includes(true)) {
|
|
2222
|
-
return React__default.isValidElement(loadingMessage) ? loadingMessage : null;
|
|
2223
|
-
}
|
|
2354
|
+
function ProductSlider(props) {
|
|
2355
|
+
var className = props.className,
|
|
2356
|
+
slideContainer = props.slideContainer,
|
|
2357
|
+
thumbsContainer = props.thumbsContainer,
|
|
2358
|
+
_props$thumbsVisible = props.thumbsVisible,
|
|
2359
|
+
thumbsVisible = _props$thumbsVisible === void 0 ? 4 : _props$thumbsVisible,
|
|
2360
|
+
_props$slideSelected = props.slideSelected,
|
|
2361
|
+
slideSelected = _props$slideSelected === void 0 ? 0 : _props$slideSelected;
|
|
2362
|
+
var product = useProduct();
|
|
2224
2363
|
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2364
|
+
var _React$useState = React__default.useState(slideSelected),
|
|
2365
|
+
selected = _React$useState[0],
|
|
2366
|
+
setSelected = _React$useState[1];
|
|
2228
2367
|
|
|
2229
|
-
|
|
2368
|
+
var maximumRight = product.images.length - thumbsVisible;
|
|
2369
|
+
var leftIndex = Math.min(maximumRight, Math.max(0, selected - 1));
|
|
2370
|
+
return React__default.createElement("div", {
|
|
2230
2371
|
className: className
|
|
2231
|
-
},
|
|
2372
|
+
}, React__default.createElement(ProductSliderProvider, {
|
|
2373
|
+
mediaIndex: selected,
|
|
2374
|
+
children: slideContainer
|
|
2375
|
+
}), React__default.createElement("div", {
|
|
2376
|
+
style: {
|
|
2377
|
+
display: "grid",
|
|
2378
|
+
gridTemplateColumns: "repeat(" + thumbsVisible + ", 1fr)"
|
|
2379
|
+
}
|
|
2380
|
+
}, product.images.slice(leftIndex, leftIndex + thumbsVisible).map(function (image, i) {
|
|
2381
|
+
return host.repeatedElement(i === 0, React__default.createElement(ProductSliderProvider, {
|
|
2382
|
+
mediaIndex: leftIndex + i,
|
|
2383
|
+
children: thumbsContainer,
|
|
2384
|
+
onClick: function onClick() {
|
|
2385
|
+
return setSelected(leftIndex + i);
|
|
2386
|
+
}
|
|
2387
|
+
}));
|
|
2388
|
+
})));
|
|
2232
2389
|
}
|
|
2233
|
-
function
|
|
2390
|
+
function registerProductSlider(loader, customProductSliderMeta) {
|
|
2234
2391
|
var doRegisterComponent = function doRegisterComponent() {
|
|
2235
2392
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2236
2393
|
};
|
|
2237
2394
|
|
|
2238
|
-
doRegisterComponent(
|
|
2395
|
+
doRegisterComponent(ProductSlider, customProductSliderMeta != null ? customProductSliderMeta : productSliderMeta);
|
|
2239
2396
|
}
|
|
2240
2397
|
|
|
2241
|
-
var
|
|
2242
|
-
name: "plasmic-commerce-
|
|
2243
|
-
displayName: "
|
|
2398
|
+
var productTextFieldMeta = {
|
|
2399
|
+
name: "plasmic-commerce-product-text-field",
|
|
2400
|
+
displayName: "Product Text Field",
|
|
2244
2401
|
props: {
|
|
2245
2402
|
field: {
|
|
2246
2403
|
type: "choice",
|
|
2247
|
-
options: ["id", "name", "slug", "path"]
|
|
2404
|
+
options: ["id", "name", "description", "sku", "slug", "path"]
|
|
2248
2405
|
}
|
|
2249
2406
|
},
|
|
2250
2407
|
importPath: "@plasmicpkgs/commerce",
|
|
2251
|
-
importName: "
|
|
2408
|
+
importName: "ProductTextField"
|
|
2252
2409
|
};
|
|
2253
|
-
function
|
|
2410
|
+
function ProductTextField(props) {
|
|
2254
2411
|
var className = props.className,
|
|
2255
2412
|
field = props.field;
|
|
2256
|
-
var
|
|
2413
|
+
var product = useProduct();
|
|
2414
|
+
|
|
2415
|
+
if (!product) {
|
|
2416
|
+
return React__default.createElement("span", {
|
|
2417
|
+
className: className
|
|
2418
|
+
}, "Fake Product Field");
|
|
2419
|
+
}
|
|
2257
2420
|
|
|
2258
2421
|
if (!field) {
|
|
2259
|
-
return React__default.createElement("span",
|
|
2422
|
+
return React__default.createElement("span", {
|
|
2423
|
+
className: className
|
|
2424
|
+
}, "Unknown Product Field");
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
var value;
|
|
2428
|
+
|
|
2429
|
+
if (field === "description") {
|
|
2430
|
+
var _product$descriptionH;
|
|
2431
|
+
|
|
2432
|
+
return React__default.createElement("div", {
|
|
2433
|
+
className: className,
|
|
2434
|
+
dangerouslySetInnerHTML: {
|
|
2435
|
+
__html: (_product$descriptionH = product.descriptionHtml) != null ? _product$descriptionH : product.description
|
|
2436
|
+
}
|
|
2437
|
+
});
|
|
2438
|
+
} else {
|
|
2439
|
+
value = product[field];
|
|
2260
2440
|
}
|
|
2261
2441
|
|
|
2262
|
-
var data = category ? category[field] : "Category field placeholder";
|
|
2263
2442
|
return React__default.createElement("span", {
|
|
2264
2443
|
className: className
|
|
2265
|
-
},
|
|
2444
|
+
}, value);
|
|
2266
2445
|
}
|
|
2267
|
-
function
|
|
2446
|
+
function registerTextField(loader, customProductTextFieldMeta) {
|
|
2268
2447
|
var doRegisterComponent = function doRegisterComponent() {
|
|
2269
2448
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2270
2449
|
};
|
|
2271
2450
|
|
|
2272
|
-
doRegisterComponent(
|
|
2451
|
+
doRegisterComponent(ProductTextField, customProductTextFieldMeta != null ? customProductTextFieldMeta : productTextFieldMeta);
|
|
2273
2452
|
}
|
|
2274
2453
|
|
|
2454
|
+
var productVariantPickerMeta = {
|
|
2455
|
+
name: "plasmic-commerce-product-variant-picker",
|
|
2456
|
+
displayName: "Product Variant Picker",
|
|
2457
|
+
props: {},
|
|
2458
|
+
importPath: "@plasmicpkgs/commerce",
|
|
2459
|
+
importName: "ProductVariantPicker"
|
|
2460
|
+
};
|
|
2461
|
+
function ProductVariantPicker(props) {
|
|
2462
|
+
var _useFormContext, _product$variants$fin;
|
|
2463
|
+
|
|
2464
|
+
var className = props.className;
|
|
2465
|
+
var product = useProduct();
|
|
2466
|
+
var form = (_useFormContext = reactHookForm.useFormContext()) != null ? _useFormContext : reactHookForm.useForm();
|
|
2467
|
+
return React__default.createElement(reactHookForm.Controller, {
|
|
2468
|
+
name: "ProductVariant",
|
|
2469
|
+
control: form == null ? void 0 : form.control,
|
|
2470
|
+
defaultValue: product == null ? void 0 : (_product$variants$fin = product.variants.find(function (v) {
|
|
2471
|
+
return v.price === product.price.value;
|
|
2472
|
+
})) == null ? void 0 : _product$variants$fin.id,
|
|
2473
|
+
render: function render(_ref) {
|
|
2474
|
+
var _product$variants$map;
|
|
2275
2475
|
|
|
2476
|
+
var field = _ref.field;
|
|
2477
|
+
return React__default.createElement("select", Object.assign({
|
|
2478
|
+
className: className
|
|
2479
|
+
}, field), (_product$variants$map = product == null ? void 0 : product.variants.map(function (variant) {
|
|
2480
|
+
return React__default.createElement("option", {
|
|
2481
|
+
value: variant.id
|
|
2482
|
+
}, variant.name);
|
|
2483
|
+
})) != null ? _product$variants$map : React__default.createElement("option", null, "Product Variant Placeholder"));
|
|
2484
|
+
}
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
function registerProductVariantPicker(loader, customProductVariantPickerMeta) {
|
|
2488
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
2489
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2490
|
+
};
|
|
2276
2491
|
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
};
|
|
2492
|
+
doRegisterComponent(ProductVariantPicker, customProductVariantPickerMeta != null ? customProductVariantPickerMeta : productVariantPickerMeta);
|
|
2493
|
+
}
|
|
2280
2494
|
|
|
2281
2495
|
var fetcher$6 = mutationFetcher;
|
|
2282
2496
|
|
|
@@ -2316,6 +2530,15 @@ var cart = {
|
|
|
2316
2530
|
|
|
2317
2531
|
|
|
2318
2532
|
|
|
2533
|
+
var product = {
|
|
2534
|
+
__proto__: null
|
|
2535
|
+
};
|
|
2536
|
+
|
|
2537
|
+
/*
|
|
2538
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/commerce/src
|
|
2539
|
+
Changes: Added CategoryImage
|
|
2540
|
+
*/
|
|
2541
|
+
|
|
2319
2542
|
var site = {
|
|
2320
2543
|
__proto__: null
|
|
2321
2544
|
};
|
|
@@ -2330,9 +2553,12 @@ function registerAll(loader) {
|
|
|
2330
2553
|
registerProductQuantity(loader);
|
|
2331
2554
|
registerProductVariantPicker(loader);
|
|
2332
2555
|
registerProductBox(loader);
|
|
2556
|
+
registerProductSlider(loader);
|
|
2333
2557
|
registerProductLink(loader);
|
|
2334
2558
|
registerCategoryCollection(loader);
|
|
2335
2559
|
registerCategoryField(loader);
|
|
2560
|
+
registerCategoryLink(loader);
|
|
2561
|
+
registerCategoryMedia(loader);
|
|
2336
2562
|
}
|
|
2337
2563
|
|
|
2338
2564
|
exports.AddToCartButton = AddToCartButton;
|
|
@@ -2340,6 +2566,7 @@ exports.CartComponent = CartComponent;
|
|
|
2340
2566
|
exports.CartType = cart;
|
|
2341
2567
|
exports.CategoryCollection = CategoryCollection;
|
|
2342
2568
|
exports.CategoryField = CategoryField;
|
|
2569
|
+
exports.CategoryLink = CategoryLink;
|
|
2343
2570
|
exports.CommerceError = CommerceError;
|
|
2344
2571
|
exports.CoreCommerceProvider = CoreCommerceProvider;
|
|
2345
2572
|
exports.FetcherError = FetcherError;
|
|
@@ -2347,6 +2574,7 @@ exports.ProductBox = ProductBox;
|
|
|
2347
2574
|
exports.ProductCollection = ProductCollection;
|
|
2348
2575
|
exports.ProductLink = ProductLink;
|
|
2349
2576
|
exports.ProductMedia = ProductMedia;
|
|
2577
|
+
exports.ProductPlaceholder = defaultProduct;
|
|
2350
2578
|
exports.ProductPriceComponent = ProductPriceComponent;
|
|
2351
2579
|
exports.ProductQuantity = ProductQuantity;
|
|
2352
2580
|
exports.ProductTextField = ProductTextField;
|
|
@@ -2358,7 +2586,8 @@ exports.addToCartButtonMeta = addToCartButtonMeta;
|
|
|
2358
2586
|
exports.cartMeta = cartMeta;
|
|
2359
2587
|
exports.categoryCollectionMeta = categoryCollectionMeta;
|
|
2360
2588
|
exports.categoryFieldMeta = categoryFieldMeta;
|
|
2361
|
-
exports.
|
|
2589
|
+
exports.categoryLinkMeta = categoryLinkMeta;
|
|
2590
|
+
exports.fetcher = fetcher$4;
|
|
2362
2591
|
exports.getCommerceProvider = getCommerceProvider;
|
|
2363
2592
|
exports.productBoxMeta = productBoxMeta;
|
|
2364
2593
|
exports.productCollectionMeta = productCollectionMeta;
|
|
@@ -2373,6 +2602,7 @@ exports.registerAll = registerAll;
|
|
|
2373
2602
|
exports.registerCart = registerCart;
|
|
2374
2603
|
exports.registerCategoryCollection = registerCategoryCollection;
|
|
2375
2604
|
exports.registerCategoryField = registerCategoryField;
|
|
2605
|
+
exports.registerCategoryLink = registerCategoryLink;
|
|
2376
2606
|
exports.registerProductBox = registerProductBox;
|
|
2377
2607
|
exports.registerProductCollection = registerProductCollection;
|
|
2378
2608
|
exports.registerProductLink = registerProductLink;
|