@plasmicpkgs/commerce 0.0.12 → 0.0.15
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 +882 -600
- 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 +873 -601
- package/dist/commerce.esm.js.map +1 -1
- package/dist/contexts.d.ts +10 -3
- package/dist/index.d.ts +27 -23
- package/dist/registerCategoryLink.d.ts +12 -0
- package/dist/registerCategoryMedia.d.ts +11 -0
- package/dist/registerProductCollection.d.ts +3 -1
- package/dist/registerProductLink.d.ts +1 -1
- package/dist/registerProductMedia.d.ts +1 -0
- 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,762 @@ 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
|
-
mediaIndex: "number"
|
|
1796
|
+
mediaIndex: "number",
|
|
1797
|
+
mediaSize: {
|
|
1798
|
+
type: "choice",
|
|
1799
|
+
options: [{
|
|
1800
|
+
label: "Fill",
|
|
1801
|
+
value: "fill"
|
|
1802
|
+
}, {
|
|
1803
|
+
label: "Container",
|
|
1804
|
+
value: "contain"
|
|
1805
|
+
}, {
|
|
1806
|
+
label: "Cover",
|
|
1807
|
+
value: "cover"
|
|
1808
|
+
}, {
|
|
1809
|
+
label: "None",
|
|
1810
|
+
value: "none"
|
|
1811
|
+
}, {
|
|
1812
|
+
label: "Scale down",
|
|
1813
|
+
value: "scale-down"
|
|
1814
|
+
}]
|
|
1815
|
+
}
|
|
1720
1816
|
},
|
|
1721
1817
|
importPath: "@plasmicpkgs/commerce",
|
|
1722
|
-
importName: "
|
|
1818
|
+
importName: "CategoryMedia"
|
|
1723
1819
|
};
|
|
1724
|
-
function
|
|
1820
|
+
function CategoryMedia(props) {
|
|
1725
1821
|
var _image$url;
|
|
1726
1822
|
|
|
1727
1823
|
var className = props.className,
|
|
1728
1824
|
_props$mediaIndex = props.mediaIndex,
|
|
1729
|
-
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex
|
|
1730
|
-
|
|
1731
|
-
var
|
|
1825
|
+
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex,
|
|
1826
|
+
mediaSize = props.mediaSize;
|
|
1827
|
+
var category = useCategoryContext();
|
|
1828
|
+
var image = category != null && category.images ? category.images[mediaIndex] : undefined;
|
|
1732
1829
|
return React__default.createElement("img", {
|
|
1733
|
-
alt: (
|
|
1734
|
-
src:
|
|
1735
|
-
loading:
|
|
1736
|
-
className: className
|
|
1830
|
+
alt: (category == null ? void 0 : category.name) || "Category Image",
|
|
1831
|
+
src: (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "",
|
|
1832
|
+
loading: "lazy",
|
|
1833
|
+
className: className,
|
|
1834
|
+
style: {
|
|
1835
|
+
objectFit: mediaSize
|
|
1836
|
+
}
|
|
1737
1837
|
});
|
|
1738
1838
|
}
|
|
1739
|
-
function
|
|
1839
|
+
function registerCategoryMedia(loader, customCategoryMediaMeta) {
|
|
1740
1840
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1741
1841
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1742
1842
|
};
|
|
1743
1843
|
|
|
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
|
-
};
|
|
1844
|
+
doRegisterComponent(CategoryMedia, customCategoryMediaMeta != null ? customCategoryMediaMeta : categoryMediaMeta);
|
|
1786
1845
|
}
|
|
1787
|
-
function usePrice(data) {
|
|
1788
|
-
var _ref3 = data != null ? data : {},
|
|
1789
|
-
amount = _ref3.amount,
|
|
1790
|
-
baseAmount = _ref3.baseAmount,
|
|
1791
|
-
currencyCode = _ref3.currencyCode;
|
|
1792
1846
|
|
|
1793
|
-
|
|
1794
|
-
locale = _useCommerce.locale;
|
|
1847
|
+
var fetcher$3 = SWRFetcher;
|
|
1795
1848
|
|
|
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
|
-
}
|
|
1849
|
+
var fn$3 = function fn(provider) {
|
|
1850
|
+
var _provider$products;
|
|
1813
1851
|
|
|
1814
|
-
|
|
1815
|
-
|
|
1852
|
+
return (_provider$products = provider.products) == null ? void 0 : _provider$products.useProduct;
|
|
1853
|
+
};
|
|
1816
1854
|
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1855
|
+
var useProduct$1 = function useProduct(input) {
|
|
1856
|
+
var hook = useHook(fn$3);
|
|
1857
|
+
return useSWRHook(_extends({
|
|
1858
|
+
fetcher: fetcher$3
|
|
1859
|
+
}, hook))(input);
|
|
1820
1860
|
};
|
|
1821
1861
|
|
|
1822
|
-
var
|
|
1823
|
-
name: "plasmic-commerce-product-
|
|
1824
|
-
displayName: "Product
|
|
1825
|
-
props: {
|
|
1862
|
+
var productBoxMeta = {
|
|
1863
|
+
name: "plasmic-commerce-product-box",
|
|
1864
|
+
displayName: "Product Box",
|
|
1865
|
+
props: {
|
|
1866
|
+
children: {
|
|
1867
|
+
type: "slot",
|
|
1868
|
+
defaultValue: [{
|
|
1869
|
+
type: "vbox",
|
|
1870
|
+
children: [{
|
|
1871
|
+
type: "component",
|
|
1872
|
+
name: "plasmic-commerce-product-text-field",
|
|
1873
|
+
props: {
|
|
1874
|
+
field: "name"
|
|
1875
|
+
}
|
|
1876
|
+
}, {
|
|
1877
|
+
type: "component",
|
|
1878
|
+
name: "plasmic-commerce-product-media"
|
|
1879
|
+
}],
|
|
1880
|
+
styles: {
|
|
1881
|
+
width: "100%",
|
|
1882
|
+
minWidth: 0
|
|
1883
|
+
}
|
|
1884
|
+
}]
|
|
1885
|
+
},
|
|
1886
|
+
noLayout: "boolean",
|
|
1887
|
+
id: {
|
|
1888
|
+
type: "string",
|
|
1889
|
+
description: "Fetch a product by its slug or ID"
|
|
1890
|
+
}
|
|
1891
|
+
},
|
|
1826
1892
|
importPath: "@plasmicpkgs/commerce",
|
|
1827
|
-
importName: "
|
|
1893
|
+
importName: "ProductBox"
|
|
1828
1894
|
};
|
|
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 : "");
|
|
1895
|
+
function ProductBox(props) {
|
|
1896
|
+
var className = props.className,
|
|
1897
|
+
children = props.children,
|
|
1898
|
+
noLayout = props.noLayout,
|
|
1899
|
+
id = props.id;
|
|
1836
1900
|
|
|
1837
|
-
var
|
|
1838
|
-
|
|
1839
|
-
currencyCode: product ? product.price.currencyCode : 'USD'
|
|
1901
|
+
var _useProduct = useProduct$1({
|
|
1902
|
+
id: id
|
|
1840
1903
|
}),
|
|
1841
|
-
|
|
1904
|
+
data = _useProduct.data,
|
|
1905
|
+
error = _useProduct.error,
|
|
1906
|
+
isLoading = _useProduct.isLoading;
|
|
1842
1907
|
|
|
1843
|
-
|
|
1908
|
+
if (!id) {
|
|
1909
|
+
return React__default.createElement("span", null, "You must set the id prop");
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
if (error) {
|
|
1913
|
+
throw new CommerceError({
|
|
1914
|
+
message: error.message,
|
|
1915
|
+
code: error.code
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
if (isLoading) {
|
|
1920
|
+
return React__default.createElement("span", null, "Loading...");
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
if (!data) {
|
|
1924
|
+
throw new Error("Product not found!");
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
var renderedData = React__default.createElement(ProductProvider, {
|
|
1928
|
+
product: data
|
|
1929
|
+
}, children);
|
|
1930
|
+
return noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
|
|
1844
1931
|
className: className
|
|
1845
|
-
},
|
|
1932
|
+
}, renderedData);
|
|
1846
1933
|
}
|
|
1847
|
-
function
|
|
1934
|
+
function registerProductBox(loader, customProductBoxMeta) {
|
|
1848
1935
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1849
1936
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1850
1937
|
};
|
|
1851
1938
|
|
|
1852
|
-
doRegisterComponent(
|
|
1939
|
+
doRegisterComponent(ProductBox, customProductBoxMeta != null ? customProductBoxMeta : productBoxMeta);
|
|
1853
1940
|
}
|
|
1854
1941
|
|
|
1855
|
-
var
|
|
1856
|
-
|
|
1857
|
-
|
|
1942
|
+
var fetcher$4 = SWRFetcher;
|
|
1943
|
+
|
|
1944
|
+
var fn$4 = function fn(provider) {
|
|
1945
|
+
var _provider$products;
|
|
1946
|
+
|
|
1947
|
+
return (_provider$products = provider.products) == null ? void 0 : _provider$products.useSearch;
|
|
1948
|
+
};
|
|
1949
|
+
|
|
1950
|
+
var useSearch = function useSearch(input) {
|
|
1951
|
+
var hook = useHook(fn$4);
|
|
1952
|
+
return useSWRHook(_extends({
|
|
1953
|
+
fetcher: fetcher$4
|
|
1954
|
+
}, hook))(input);
|
|
1955
|
+
};
|
|
1956
|
+
|
|
1957
|
+
var fetcher$5 = SWRFetcher;
|
|
1958
|
+
|
|
1959
|
+
var fn$5 = function fn(provider) {
|
|
1960
|
+
var _provider$site;
|
|
1961
|
+
|
|
1962
|
+
return (_provider$site = provider.site) == null ? void 0 : _provider$site.useBrands;
|
|
1963
|
+
};
|
|
1964
|
+
|
|
1965
|
+
var useBrands = function useBrands(input) {
|
|
1966
|
+
var hook = useHook(fn$5);
|
|
1967
|
+
return useSWRHook(_extends({
|
|
1968
|
+
fetcher: fetcher$5
|
|
1969
|
+
}, hook))(input);
|
|
1970
|
+
};
|
|
1971
|
+
|
|
1972
|
+
var productCollectionMeta = {
|
|
1973
|
+
name: "plasmic-commerce-product-collection",
|
|
1974
|
+
displayName: "Product Collection",
|
|
1858
1975
|
props: {
|
|
1859
1976
|
children: {
|
|
1860
1977
|
type: "slot",
|
|
1861
1978
|
defaultValue: [{
|
|
1862
|
-
type: "
|
|
1863
|
-
|
|
1864
|
-
|
|
1979
|
+
type: "vbox",
|
|
1980
|
+
children: [{
|
|
1981
|
+
type: "component",
|
|
1982
|
+
name: "plasmic-commerce-product-text-field",
|
|
1983
|
+
props: {
|
|
1984
|
+
field: "name"
|
|
1985
|
+
}
|
|
1986
|
+
}, {
|
|
1987
|
+
type: "component",
|
|
1988
|
+
name: "plasmic-commerce-product-media"
|
|
1989
|
+
}],
|
|
1990
|
+
styles: {
|
|
1991
|
+
width: "100%",
|
|
1992
|
+
minWidth: 0
|
|
1865
1993
|
}
|
|
1866
1994
|
}]
|
|
1867
|
-
}
|
|
1995
|
+
},
|
|
1996
|
+
emptyMessage: {
|
|
1997
|
+
type: "slot",
|
|
1998
|
+
defaultValue: {
|
|
1999
|
+
type: "text",
|
|
2000
|
+
value: "No product found!"
|
|
2001
|
+
}
|
|
2002
|
+
},
|
|
2003
|
+
loadingMessage: {
|
|
2004
|
+
type: "slot",
|
|
2005
|
+
defaultValue: {
|
|
2006
|
+
type: "text",
|
|
2007
|
+
value: "Loading..."
|
|
2008
|
+
}
|
|
2009
|
+
},
|
|
2010
|
+
count: "number",
|
|
2011
|
+
category: {
|
|
2012
|
+
type: "choice",
|
|
2013
|
+
options: function options(props, ctx) {
|
|
2014
|
+
var _ctx$categories$map;
|
|
2015
|
+
|
|
2016
|
+
return (_ctx$categories$map = ctx == null ? void 0 : ctx.categories.map(function (category) {
|
|
2017
|
+
return {
|
|
2018
|
+
label: category.name,
|
|
2019
|
+
value: category.id
|
|
2020
|
+
};
|
|
2021
|
+
})) != null ? _ctx$categories$map : [];
|
|
2022
|
+
},
|
|
2023
|
+
hidden: function hidden(props, ctx) {
|
|
2024
|
+
return !!(ctx != null && ctx.hasCategoryCtx);
|
|
2025
|
+
}
|
|
2026
|
+
},
|
|
2027
|
+
includeSubCategories: {
|
|
2028
|
+
type: "boolean",
|
|
2029
|
+
hidden: function hidden(props, ctx) {
|
|
2030
|
+
var _ctx$features;
|
|
2031
|
+
|
|
2032
|
+
return !(ctx != null && (_ctx$features = ctx.features) != null && _ctx$features.includeSubCategories);
|
|
2033
|
+
}
|
|
2034
|
+
},
|
|
2035
|
+
brand: {
|
|
2036
|
+
type: "choice",
|
|
2037
|
+
options: function options(props, ctx) {
|
|
2038
|
+
var _ctx$brands$map;
|
|
2039
|
+
|
|
2040
|
+
return (_ctx$brands$map = ctx == null ? void 0 : ctx.brands.map(function (brand) {
|
|
2041
|
+
return {
|
|
2042
|
+
label: brand.name,
|
|
2043
|
+
value: brand.entityId
|
|
2044
|
+
};
|
|
2045
|
+
})) != null ? _ctx$brands$map : [];
|
|
2046
|
+
}
|
|
2047
|
+
},
|
|
2048
|
+
search: {
|
|
2049
|
+
type: "string"
|
|
2050
|
+
},
|
|
2051
|
+
sort: {
|
|
2052
|
+
type: "choice",
|
|
2053
|
+
options: [{
|
|
2054
|
+
label: "Trending",
|
|
2055
|
+
value: "trending-desc"
|
|
2056
|
+
}, {
|
|
2057
|
+
label: "New Arrivals",
|
|
2058
|
+
value: "latest-desc"
|
|
2059
|
+
}, {
|
|
2060
|
+
label: "Price: Low to High",
|
|
2061
|
+
value: "price-asc"
|
|
2062
|
+
}, {
|
|
2063
|
+
label: "Price: High to Low",
|
|
2064
|
+
value: "price-desc"
|
|
2065
|
+
}]
|
|
2066
|
+
},
|
|
2067
|
+
noLayout: "boolean"
|
|
2068
|
+
},
|
|
2069
|
+
defaultStyles: {
|
|
2070
|
+
display: "grid",
|
|
2071
|
+
gridTemplateColumns: "1fr 1fr 1fr 1fr",
|
|
2072
|
+
gridRowGap: "8px",
|
|
2073
|
+
gridColumnGap: "8px",
|
|
2074
|
+
padding: "8px",
|
|
2075
|
+
maxWidth: "100%"
|
|
1868
2076
|
},
|
|
1869
2077
|
importPath: "@plasmicpkgs/commerce",
|
|
1870
|
-
importName: "
|
|
2078
|
+
importName: "ProductCollection"
|
|
1871
2079
|
};
|
|
1872
|
-
function
|
|
2080
|
+
function ProductCollection(props) {
|
|
2081
|
+
var _categoryCtx$id;
|
|
2082
|
+
|
|
1873
2083
|
var className = props.className,
|
|
1874
|
-
children = props.children
|
|
1875
|
-
|
|
1876
|
-
|
|
2084
|
+
children = props.children,
|
|
2085
|
+
count = props.count,
|
|
2086
|
+
category = props.category,
|
|
2087
|
+
includeSubCategories = props.includeSubCategories,
|
|
2088
|
+
brand = props.brand,
|
|
2089
|
+
noLayout = props.noLayout,
|
|
2090
|
+
setControlContextData = props.setControlContextData,
|
|
2091
|
+
emptyMessage = props.emptyMessage,
|
|
2092
|
+
loadingMessage = props.loadingMessage,
|
|
2093
|
+
search = props.search,
|
|
2094
|
+
sort = props.sort;
|
|
2095
|
+
|
|
2096
|
+
var _useCategories = useCategories(),
|
|
2097
|
+
categories = _useCategories.data,
|
|
2098
|
+
isCategoriesLoading = _useCategories.isLoading;
|
|
2099
|
+
|
|
2100
|
+
var _useBrands = useBrands(),
|
|
2101
|
+
brands = _useBrands.data,
|
|
2102
|
+
isBrandsLoading = _useBrands.isLoading;
|
|
2103
|
+
|
|
2104
|
+
var categoryCtx = useCategoryContext();
|
|
2105
|
+
|
|
2106
|
+
var _useSearch = useSearch({
|
|
2107
|
+
categoryId: (_categoryCtx$id = categoryCtx == null ? void 0 : categoryCtx.id) != null ? _categoryCtx$id : category,
|
|
2108
|
+
brandId: brand,
|
|
2109
|
+
count: count,
|
|
2110
|
+
categories: categories != null ? categories : [],
|
|
2111
|
+
includeSubCategories: includeSubCategories,
|
|
2112
|
+
search: search,
|
|
2113
|
+
sort: sort
|
|
2114
|
+
}),
|
|
2115
|
+
data = _useSearch.data,
|
|
2116
|
+
isSearchLoading = _useSearch.isLoading;
|
|
2117
|
+
|
|
2118
|
+
var features = useCommerceExtraFeatures();
|
|
2119
|
+
|
|
2120
|
+
if (categories && brands) {
|
|
2121
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
2122
|
+
categories: categories,
|
|
2123
|
+
brands: brands,
|
|
2124
|
+
features: features,
|
|
2125
|
+
hasCategoryCtx: !!categoryCtx
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
var renderedData = data == null ? void 0 : data.products.map(function (product, i) {
|
|
2130
|
+
return React__default.createElement(ProductProvider, {
|
|
2131
|
+
product: product,
|
|
2132
|
+
key: product.id
|
|
2133
|
+
}, host.repeatedElement(i === 0, children));
|
|
2134
|
+
});
|
|
2135
|
+
|
|
2136
|
+
if ([isSearchLoading, isBrandsLoading, isCategoriesLoading].includes(true)) {
|
|
2137
|
+
return React__default.isValidElement(loadingMessage) ? loadingMessage : null;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
if (!data || data.products.length === 0) {
|
|
2141
|
+
return React__default.isValidElement(emptyMessage) ? emptyMessage : null;
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
return noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
|
|
1877
2145
|
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
|
-
}));
|
|
2146
|
+
}, renderedData);
|
|
1889
2147
|
}
|
|
1890
|
-
function
|
|
2148
|
+
function registerProductCollection(loader, customProductCollectionMeta) {
|
|
1891
2149
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1892
2150
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1893
2151
|
};
|
|
1894
2152
|
|
|
1895
|
-
doRegisterComponent(
|
|
2153
|
+
doRegisterComponent(ProductCollection, customProductCollectionMeta != null ? customProductCollectionMeta : productCollectionMeta);
|
|
1896
2154
|
}
|
|
1897
2155
|
|
|
1898
|
-
var
|
|
1899
|
-
name: "plasmic-commerce-product-
|
|
1900
|
-
displayName: "Product
|
|
2156
|
+
var productLinkMeta = {
|
|
2157
|
+
name: "plasmic-commerce-product-link",
|
|
2158
|
+
displayName: "Product Link",
|
|
1901
2159
|
props: {
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
2160
|
+
children: "slot",
|
|
2161
|
+
linkDest: {
|
|
2162
|
+
type: "string",
|
|
2163
|
+
defaultValueHint: "products/{slug}",
|
|
2164
|
+
description: "Set the link destination. You can use {slug} to replace by the product slug"
|
|
1905
2165
|
}
|
|
1906
2166
|
},
|
|
1907
2167
|
importPath: "@plasmicpkgs/commerce",
|
|
1908
|
-
importName: "
|
|
2168
|
+
importName: "ProductLink"
|
|
1909
2169
|
};
|
|
1910
|
-
function
|
|
2170
|
+
function ProductLink(props) {
|
|
1911
2171
|
var className = props.className,
|
|
1912
|
-
|
|
2172
|
+
children = props.children,
|
|
2173
|
+
linkDest = props.linkDest;
|
|
1913
2174
|
var product = useProduct();
|
|
1914
2175
|
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
className: className
|
|
1918
|
-
}, "Fake Product Field");
|
|
1919
|
-
}
|
|
2176
|
+
var resolveLink = function resolveLink(linkDest) {
|
|
2177
|
+
var _linkDest$match;
|
|
1920
2178
|
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
}, "Unknown Product Field");
|
|
1925
|
-
}
|
|
2179
|
+
if (!linkDest) {
|
|
2180
|
+
return undefined;
|
|
2181
|
+
}
|
|
1926
2182
|
|
|
1927
|
-
|
|
2183
|
+
var regex = /{[^}]*}/;
|
|
2184
|
+
var regexAll = new RegExp(regex, "g");
|
|
2185
|
+
var matches = (_linkDest$match = linkDest.match(regexAll)) != null ? _linkDest$match : [];
|
|
2186
|
+
var resolvedLink = linkDest;
|
|
1928
2187
|
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
2188
|
+
for (var _iterator = _createForOfIteratorHelperLoose(matches), _step; !(_step = _iterator()).done;) {
|
|
2189
|
+
var match = _step.value;
|
|
2190
|
+
var field = match.slice(1, -1);
|
|
2191
|
+
|
|
2192
|
+
if (!product || !(field in product)) {
|
|
2193
|
+
return undefined;
|
|
1934
2194
|
}
|
|
1935
|
-
}) : React__default.createElement("div", {
|
|
1936
|
-
className: className
|
|
1937
|
-
}, product.description);
|
|
1938
|
-
} else {
|
|
1939
|
-
value = product[field];
|
|
1940
|
-
}
|
|
1941
2195
|
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
2196
|
+
resolvedLink = resolvedLink.replace(regex, product[field]);
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
return resolvedLink;
|
|
2200
|
+
};
|
|
2201
|
+
|
|
2202
|
+
return React__default.createElement("a", {
|
|
2203
|
+
className: className,
|
|
2204
|
+
href: resolveLink(linkDest),
|
|
2205
|
+
style: {
|
|
2206
|
+
color: "inherit",
|
|
2207
|
+
textDecoration: "inherit"
|
|
2208
|
+
}
|
|
2209
|
+
}, children);
|
|
1945
2210
|
}
|
|
1946
|
-
function
|
|
2211
|
+
function registerProductLink(loader, customProductLinkMeta) {
|
|
1947
2212
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1948
2213
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1949
2214
|
};
|
|
1950
2215
|
|
|
1951
|
-
doRegisterComponent(
|
|
2216
|
+
doRegisterComponent(ProductLink, customProductLinkMeta != null ? customProductLinkMeta : productLinkMeta);
|
|
1952
2217
|
}
|
|
1953
2218
|
|
|
1954
|
-
var
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
2219
|
+
var placeholderImage = "https://static1.plasmic.app/commerce/lightweight-jacket-0.png";
|
|
2220
|
+
var productMediaMeta = {
|
|
2221
|
+
name: "plasmic-commerce-product-media",
|
|
2222
|
+
displayName: "Product Media",
|
|
2223
|
+
props: {
|
|
2224
|
+
mediaIndex: "number",
|
|
2225
|
+
mediaSize: {
|
|
2226
|
+
type: "choice",
|
|
2227
|
+
options: [{
|
|
2228
|
+
label: "Fill",
|
|
2229
|
+
value: "fill"
|
|
2230
|
+
}, {
|
|
2231
|
+
label: "Container",
|
|
2232
|
+
value: "contain"
|
|
2233
|
+
}, {
|
|
2234
|
+
label: "Cover",
|
|
2235
|
+
value: "cover"
|
|
2236
|
+
}, {
|
|
2237
|
+
label: "None",
|
|
2238
|
+
value: "none"
|
|
2239
|
+
}, {
|
|
2240
|
+
label: "Scale down",
|
|
2241
|
+
value: "scale-down"
|
|
2242
|
+
}]
|
|
2243
|
+
}
|
|
2244
|
+
},
|
|
1958
2245
|
importPath: "@plasmicpkgs/commerce",
|
|
1959
|
-
importName: "
|
|
2246
|
+
importName: "ProductMedia"
|
|
1960
2247
|
};
|
|
1961
|
-
function
|
|
1962
|
-
var
|
|
2248
|
+
function ProductMedia(props) {
|
|
2249
|
+
var _image$url;
|
|
1963
2250
|
|
|
1964
|
-
var className = props.className
|
|
2251
|
+
var className = props.className,
|
|
2252
|
+
_props$mediaIndex = props.mediaIndex,
|
|
2253
|
+
mediaIndex = _props$mediaIndex === void 0 ? 0 : _props$mediaIndex,
|
|
2254
|
+
mediaSize = props.mediaSize;
|
|
1965
2255
|
var product = useProduct();
|
|
1966
|
-
var
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
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"));
|
|
2256
|
+
var sliderContext = useProductSliderContext();
|
|
2257
|
+
var image = product == null ? void 0 : product.images[sliderContext != null ? sliderContext : mediaIndex];
|
|
2258
|
+
return React__default.createElement("img", {
|
|
2259
|
+
alt: (product == null ? void 0 : product.name) || "Product Image",
|
|
2260
|
+
src: product ? (_image$url = image == null ? void 0 : image.url) != null ? _image$url : "" : placeholderImage,
|
|
2261
|
+
loading: "lazy",
|
|
2262
|
+
className: className,
|
|
2263
|
+
style: {
|
|
2264
|
+
objectFit: mediaSize
|
|
1982
2265
|
}
|
|
1983
2266
|
});
|
|
1984
2267
|
}
|
|
1985
|
-
function
|
|
2268
|
+
function registerProductMedia(loader, customProductMediaMeta) {
|
|
1986
2269
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1987
2270
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
1988
2271
|
};
|
|
1989
2272
|
|
|
1990
|
-
doRegisterComponent(
|
|
2273
|
+
doRegisterComponent(ProductMedia, customProductMediaMeta != null ? customProductMediaMeta : productMediaMeta);
|
|
1991
2274
|
}
|
|
1992
2275
|
|
|
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
|
-
};
|
|
2276
|
+
var getProductPrice = function getProductPrice(product, variantId) {
|
|
2277
|
+
var _product$variants$fin, _product$variants$fin2;
|
|
2054
2278
|
|
|
2055
|
-
return
|
|
2056
|
-
|
|
2057
|
-
}))
|
|
2279
|
+
return (_product$variants$fin = (_product$variants$fin2 = product.variants.find(function (variant) {
|
|
2280
|
+
return variant.id === variantId;
|
|
2281
|
+
})) == null ? void 0 : _product$variants$fin2.price) != null ? _product$variants$fin : product.price.value;
|
|
2058
2282
|
};
|
|
2059
2283
|
|
|
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
|
-
},
|
|
2284
|
+
var productPriceMeta = {
|
|
2285
|
+
name: "plasmic-commerce-product-price",
|
|
2286
|
+
displayName: "Product Price",
|
|
2287
|
+
props: {},
|
|
2072
2288
|
importPath: "@plasmicpkgs/commerce",
|
|
2073
|
-
importName: "
|
|
2289
|
+
importName: "ProductPriceComponent"
|
|
2074
2290
|
};
|
|
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;
|
|
2291
|
+
function ProductPriceComponent(props) {
|
|
2292
|
+
var _product$price;
|
|
2096
2293
|
|
|
2097
|
-
|
|
2098
|
-
|
|
2294
|
+
var className = props.className;
|
|
2295
|
+
var product = useProduct();
|
|
2296
|
+
var form = reactHookForm.useFormContext();
|
|
2297
|
+
var watchProductVariant = form == null ? void 0 : form.watch("ProductVariant", (_product$price = product.price) != null ? _product$price : "");
|
|
2099
2298
|
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
}
|
|
2299
|
+
var _usePrice = usePrice({
|
|
2300
|
+
amount: product ? getProductPrice(product, watchProductVariant) : 0,
|
|
2301
|
+
currencyCode: product ? product.price.currencyCode : "USD"
|
|
2302
|
+
}),
|
|
2303
|
+
price = _usePrice.price;
|
|
2104
2304
|
|
|
2105
|
-
return
|
|
2305
|
+
return React__default.createElement("span", {
|
|
2106
2306
|
className: className
|
|
2107
|
-
},
|
|
2307
|
+
}, price);
|
|
2108
2308
|
}
|
|
2109
|
-
function
|
|
2309
|
+
function registerProductPrice(loader, customProductPriceMeta) {
|
|
2110
2310
|
var doRegisterComponent = function doRegisterComponent() {
|
|
2111
2311
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2112
2312
|
};
|
|
2113
2313
|
|
|
2114
|
-
doRegisterComponent(
|
|
2314
|
+
doRegisterComponent(ProductPriceComponent, customProductPriceMeta != null ? customProductPriceMeta : productPriceMeta);
|
|
2115
2315
|
}
|
|
2116
2316
|
|
|
2117
|
-
var
|
|
2118
|
-
name: "plasmic-commerce-
|
|
2119
|
-
displayName: "
|
|
2317
|
+
var productQuantityMeta = {
|
|
2318
|
+
name: "plasmic-commerce-product-quantity",
|
|
2319
|
+
displayName: "Product Quantity",
|
|
2120
2320
|
props: {
|
|
2121
2321
|
children: {
|
|
2122
2322
|
type: "slot",
|
|
2123
2323
|
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
|
|
2324
|
+
type: "input",
|
|
2325
|
+
attrs: {
|
|
2326
|
+
value: "1"
|
|
2138
2327
|
}
|
|
2139
2328
|
}]
|
|
2329
|
+
}
|
|
2330
|
+
},
|
|
2331
|
+
importPath: "@plasmicpkgs/commerce",
|
|
2332
|
+
importName: "ProductQuantity"
|
|
2333
|
+
};
|
|
2334
|
+
function ProductQuantity(props) {
|
|
2335
|
+
var className = props.className,
|
|
2336
|
+
children = props.children;
|
|
2337
|
+
var form = reactHookForm.useFormContext();
|
|
2338
|
+
return React__default.createElement("div", {
|
|
2339
|
+
className: className
|
|
2340
|
+
}, React__default.createElement(reactHookForm.Controller, {
|
|
2341
|
+
name: "ProductQuantity",
|
|
2342
|
+
defaultValue: 1,
|
|
2343
|
+
control: form == null ? void 0 : form.control,
|
|
2344
|
+
render: function render(_ref) {
|
|
2345
|
+
var field = _ref.field;
|
|
2346
|
+
return React__default.isValidElement(children) ? React__default.cloneElement(children, _extends({}, children.props, field, {
|
|
2347
|
+
name: "ProductQuantity"
|
|
2348
|
+
})) : React__default.createElement(React__default.Fragment, null);
|
|
2349
|
+
}
|
|
2350
|
+
}));
|
|
2351
|
+
}
|
|
2352
|
+
function registerProductQuantity(loader, customProductQuantityMeta) {
|
|
2353
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
2354
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2355
|
+
};
|
|
2356
|
+
|
|
2357
|
+
doRegisterComponent(ProductQuantity, customProductQuantityMeta != null ? customProductQuantityMeta : productQuantityMeta);
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
var productSliderMeta = {
|
|
2361
|
+
name: "plasmic-commerce-product-slider",
|
|
2362
|
+
displayName: "Product Slider",
|
|
2363
|
+
props: {
|
|
2364
|
+
thumbsVisible: {
|
|
2365
|
+
type: "number",
|
|
2366
|
+
description: "Number of thumbs visible",
|
|
2367
|
+
defaultValue: 4,
|
|
2368
|
+
defaultValueHint: 4
|
|
2140
2369
|
},
|
|
2141
|
-
|
|
2142
|
-
type: "boolean"
|
|
2143
|
-
},
|
|
2144
|
-
emptyMessage: {
|
|
2370
|
+
slideContainer: {
|
|
2145
2371
|
type: "slot",
|
|
2146
2372
|
defaultValue: {
|
|
2147
|
-
type: "
|
|
2148
|
-
|
|
2373
|
+
type: "vbox",
|
|
2374
|
+
children: [{
|
|
2375
|
+
type: "component",
|
|
2376
|
+
name: "plasmic-commerce-product-media"
|
|
2377
|
+
}]
|
|
2149
2378
|
}
|
|
2150
2379
|
},
|
|
2151
|
-
|
|
2380
|
+
thumbsContainer: {
|
|
2152
2381
|
type: "slot",
|
|
2153
2382
|
defaultValue: {
|
|
2154
|
-
type: "
|
|
2155
|
-
|
|
2383
|
+
type: "hbox",
|
|
2384
|
+
children: [{
|
|
2385
|
+
type: "component",
|
|
2386
|
+
name: "plasmic-commerce-product-media"
|
|
2387
|
+
}]
|
|
2156
2388
|
}
|
|
2157
2389
|
},
|
|
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
|
-
}
|
|
2390
|
+
slideSelected: {
|
|
2391
|
+
type: "number",
|
|
2392
|
+
defaultValue: 0,
|
|
2393
|
+
defaultValueHint: 0,
|
|
2394
|
+
description: "Current slide selected"
|
|
2170
2395
|
}
|
|
2171
2396
|
},
|
|
2172
|
-
defaultStyles: {
|
|
2173
|
-
display: "grid",
|
|
2174
|
-
gridTemplateColumns: "1fr",
|
|
2175
|
-
gridRowGap: "8px",
|
|
2176
|
-
padding: "8px",
|
|
2177
|
-
maxWidth: "100%"
|
|
2178
|
-
},
|
|
2179
2397
|
importPath: "@plasmicpkgs/commerce",
|
|
2180
|
-
importName: "
|
|
2398
|
+
importName: "ProductSlider"
|
|
2181
2399
|
};
|
|
2182
|
-
function
|
|
2183
|
-
var
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
var
|
|
2191
|
-
var inEditor = React__default.useContext(host.PlasmicCanvasContext);
|
|
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
|
-
}
|
|
2400
|
+
function ProductSlider(props) {
|
|
2401
|
+
var className = props.className,
|
|
2402
|
+
slideContainer = props.slideContainer,
|
|
2403
|
+
thumbsContainer = props.thumbsContainer,
|
|
2404
|
+
_props$thumbsVisible = props.thumbsVisible,
|
|
2405
|
+
thumbsVisible = _props$thumbsVisible === void 0 ? 4 : _props$thumbsVisible,
|
|
2406
|
+
_props$slideSelected = props.slideSelected,
|
|
2407
|
+
slideSelected = _props$slideSelected === void 0 ? 0 : _props$slideSelected;
|
|
2408
|
+
var product = useProduct();
|
|
2224
2409
|
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2410
|
+
var _React$useState = React__default.useState(slideSelected),
|
|
2411
|
+
selected = _React$useState[0],
|
|
2412
|
+
setSelected = _React$useState[1];
|
|
2228
2413
|
|
|
2229
|
-
|
|
2414
|
+
var maximumRight = product.images.length - thumbsVisible;
|
|
2415
|
+
var leftIndex = Math.min(maximumRight, Math.max(0, selected - 1));
|
|
2416
|
+
return React__default.createElement("div", {
|
|
2230
2417
|
className: className
|
|
2231
|
-
},
|
|
2418
|
+
}, React__default.createElement(ProductSliderProvider, {
|
|
2419
|
+
mediaIndex: selected,
|
|
2420
|
+
children: slideContainer
|
|
2421
|
+
}), React__default.createElement("div", {
|
|
2422
|
+
style: {
|
|
2423
|
+
display: "grid",
|
|
2424
|
+
gridTemplateColumns: "repeat(" + thumbsVisible + ", 1fr)"
|
|
2425
|
+
}
|
|
2426
|
+
}, product.images.slice(leftIndex, leftIndex + thumbsVisible).map(function (image, i) {
|
|
2427
|
+
return host.repeatedElement(i === 0, React__default.createElement(ProductSliderProvider, {
|
|
2428
|
+
mediaIndex: leftIndex + i,
|
|
2429
|
+
children: thumbsContainer,
|
|
2430
|
+
onClick: function onClick() {
|
|
2431
|
+
return setSelected(leftIndex + i);
|
|
2432
|
+
}
|
|
2433
|
+
}));
|
|
2434
|
+
})));
|
|
2232
2435
|
}
|
|
2233
|
-
function
|
|
2436
|
+
function registerProductSlider(loader, customProductSliderMeta) {
|
|
2234
2437
|
var doRegisterComponent = function doRegisterComponent() {
|
|
2235
2438
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2236
2439
|
};
|
|
2237
2440
|
|
|
2238
|
-
doRegisterComponent(
|
|
2441
|
+
doRegisterComponent(ProductSlider, customProductSliderMeta != null ? customProductSliderMeta : productSliderMeta);
|
|
2239
2442
|
}
|
|
2240
2443
|
|
|
2241
|
-
var
|
|
2242
|
-
name: "plasmic-commerce-
|
|
2243
|
-
displayName: "
|
|
2444
|
+
var productTextFieldMeta = {
|
|
2445
|
+
name: "plasmic-commerce-product-text-field",
|
|
2446
|
+
displayName: "Product Text Field",
|
|
2244
2447
|
props: {
|
|
2245
2448
|
field: {
|
|
2246
2449
|
type: "choice",
|
|
2247
|
-
options: ["id", "name", "slug", "path"]
|
|
2450
|
+
options: ["id", "name", "description", "sku", "slug", "path"]
|
|
2248
2451
|
}
|
|
2249
2452
|
},
|
|
2250
2453
|
importPath: "@plasmicpkgs/commerce",
|
|
2251
|
-
importName: "
|
|
2454
|
+
importName: "ProductTextField"
|
|
2252
2455
|
};
|
|
2253
|
-
function
|
|
2456
|
+
function ProductTextField(props) {
|
|
2254
2457
|
var className = props.className,
|
|
2255
2458
|
field = props.field;
|
|
2256
|
-
var
|
|
2459
|
+
var product = useProduct();
|
|
2460
|
+
|
|
2461
|
+
if (!product) {
|
|
2462
|
+
return React__default.createElement("span", {
|
|
2463
|
+
className: className
|
|
2464
|
+
}, "Fake Product Field");
|
|
2465
|
+
}
|
|
2257
2466
|
|
|
2258
2467
|
if (!field) {
|
|
2259
|
-
return React__default.createElement("span",
|
|
2468
|
+
return React__default.createElement("span", {
|
|
2469
|
+
className: className
|
|
2470
|
+
}, "Unknown Product Field");
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
var value;
|
|
2474
|
+
|
|
2475
|
+
if (field === "description") {
|
|
2476
|
+
var _product$descriptionH;
|
|
2477
|
+
|
|
2478
|
+
return React__default.createElement("div", {
|
|
2479
|
+
className: className,
|
|
2480
|
+
dangerouslySetInnerHTML: {
|
|
2481
|
+
__html: (_product$descriptionH = product.descriptionHtml) != null ? _product$descriptionH : product.description
|
|
2482
|
+
}
|
|
2483
|
+
});
|
|
2484
|
+
} else {
|
|
2485
|
+
value = product[field];
|
|
2260
2486
|
}
|
|
2261
2487
|
|
|
2262
|
-
var data = category ? category[field] : "Category field placeholder";
|
|
2263
2488
|
return React__default.createElement("span", {
|
|
2264
2489
|
className: className
|
|
2265
|
-
},
|
|
2490
|
+
}, value);
|
|
2266
2491
|
}
|
|
2267
|
-
function
|
|
2492
|
+
function registerTextField(loader, customProductTextFieldMeta) {
|
|
2268
2493
|
var doRegisterComponent = function doRegisterComponent() {
|
|
2269
2494
|
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2270
2495
|
};
|
|
2271
2496
|
|
|
2272
|
-
doRegisterComponent(
|
|
2497
|
+
doRegisterComponent(ProductTextField, customProductTextFieldMeta != null ? customProductTextFieldMeta : productTextFieldMeta);
|
|
2273
2498
|
}
|
|
2274
2499
|
|
|
2500
|
+
var productVariantPickerMeta = {
|
|
2501
|
+
name: "plasmic-commerce-product-variant-picker",
|
|
2502
|
+
displayName: "Product Variant Picker",
|
|
2503
|
+
props: {},
|
|
2504
|
+
importPath: "@plasmicpkgs/commerce",
|
|
2505
|
+
importName: "ProductVariantPicker"
|
|
2506
|
+
};
|
|
2507
|
+
function ProductVariantPicker(props) {
|
|
2508
|
+
var _useFormContext, _product$variants$fin;
|
|
2509
|
+
|
|
2510
|
+
var className = props.className;
|
|
2511
|
+
var product = useProduct();
|
|
2512
|
+
var form = (_useFormContext = reactHookForm.useFormContext()) != null ? _useFormContext : reactHookForm.useForm();
|
|
2513
|
+
return React__default.createElement(reactHookForm.Controller, {
|
|
2514
|
+
name: "ProductVariant",
|
|
2515
|
+
control: form == null ? void 0 : form.control,
|
|
2516
|
+
defaultValue: product == null ? void 0 : (_product$variants$fin = product.variants.find(function (v) {
|
|
2517
|
+
return v.price === product.price.value;
|
|
2518
|
+
})) == null ? void 0 : _product$variants$fin.id,
|
|
2519
|
+
render: function render(_ref) {
|
|
2520
|
+
var _product$variants$map;
|
|
2275
2521
|
|
|
2522
|
+
var field = _ref.field;
|
|
2523
|
+
return React__default.createElement("select", Object.assign({
|
|
2524
|
+
className: className
|
|
2525
|
+
}, field), (_product$variants$map = product == null ? void 0 : product.variants.map(function (variant) {
|
|
2526
|
+
return React__default.createElement("option", {
|
|
2527
|
+
value: variant.id
|
|
2528
|
+
}, variant.name);
|
|
2529
|
+
})) != null ? _product$variants$map : React__default.createElement("option", null, "Product Variant Placeholder"));
|
|
2530
|
+
}
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
function registerProductVariantPicker(loader, customProductVariantPickerMeta) {
|
|
2534
|
+
var doRegisterComponent = function doRegisterComponent() {
|
|
2535
|
+
return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
|
|
2536
|
+
};
|
|
2276
2537
|
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
};
|
|
2538
|
+
doRegisterComponent(ProductVariantPicker, customProductVariantPickerMeta != null ? customProductVariantPickerMeta : productVariantPickerMeta);
|
|
2539
|
+
}
|
|
2280
2540
|
|
|
2281
2541
|
var fetcher$6 = mutationFetcher;
|
|
2282
2542
|
|
|
@@ -2316,6 +2576,15 @@ var cart = {
|
|
|
2316
2576
|
|
|
2317
2577
|
|
|
2318
2578
|
|
|
2579
|
+
var product = {
|
|
2580
|
+
__proto__: null
|
|
2581
|
+
};
|
|
2582
|
+
|
|
2583
|
+
/*
|
|
2584
|
+
Forked from https://github.com/vercel/commerce/tree/main/packages/commerce/src
|
|
2585
|
+
Changes: Added CategoryImage
|
|
2586
|
+
*/
|
|
2587
|
+
|
|
2319
2588
|
var site = {
|
|
2320
2589
|
__proto__: null
|
|
2321
2590
|
};
|
|
@@ -2330,9 +2599,12 @@ function registerAll(loader) {
|
|
|
2330
2599
|
registerProductQuantity(loader);
|
|
2331
2600
|
registerProductVariantPicker(loader);
|
|
2332
2601
|
registerProductBox(loader);
|
|
2602
|
+
registerProductSlider(loader);
|
|
2333
2603
|
registerProductLink(loader);
|
|
2334
2604
|
registerCategoryCollection(loader);
|
|
2335
2605
|
registerCategoryField(loader);
|
|
2606
|
+
registerCategoryLink(loader);
|
|
2607
|
+
registerCategoryMedia(loader);
|
|
2336
2608
|
}
|
|
2337
2609
|
|
|
2338
2610
|
exports.AddToCartButton = AddToCartButton;
|
|
@@ -2340,6 +2612,8 @@ exports.CartComponent = CartComponent;
|
|
|
2340
2612
|
exports.CartType = cart;
|
|
2341
2613
|
exports.CategoryCollection = CategoryCollection;
|
|
2342
2614
|
exports.CategoryField = CategoryField;
|
|
2615
|
+
exports.CategoryLink = CategoryLink;
|
|
2616
|
+
exports.CategoryMedia = CategoryMedia;
|
|
2343
2617
|
exports.CommerceError = CommerceError;
|
|
2344
2618
|
exports.CoreCommerceProvider = CoreCommerceProvider;
|
|
2345
2619
|
exports.FetcherError = FetcherError;
|
|
@@ -2347,8 +2621,10 @@ exports.ProductBox = ProductBox;
|
|
|
2347
2621
|
exports.ProductCollection = ProductCollection;
|
|
2348
2622
|
exports.ProductLink = ProductLink;
|
|
2349
2623
|
exports.ProductMedia = ProductMedia;
|
|
2624
|
+
exports.ProductPlaceholder = defaultProduct;
|
|
2350
2625
|
exports.ProductPriceComponent = ProductPriceComponent;
|
|
2351
2626
|
exports.ProductQuantity = ProductQuantity;
|
|
2627
|
+
exports.ProductSlider = ProductSlider;
|
|
2352
2628
|
exports.ProductTextField = ProductTextField;
|
|
2353
2629
|
exports.ProductTypes = product;
|
|
2354
2630
|
exports.ProductVariantPicker = ProductVariantPicker;
|
|
@@ -2358,7 +2634,9 @@ exports.addToCartButtonMeta = addToCartButtonMeta;
|
|
|
2358
2634
|
exports.cartMeta = cartMeta;
|
|
2359
2635
|
exports.categoryCollectionMeta = categoryCollectionMeta;
|
|
2360
2636
|
exports.categoryFieldMeta = categoryFieldMeta;
|
|
2361
|
-
exports.
|
|
2637
|
+
exports.categoryLinkMeta = categoryLinkMeta;
|
|
2638
|
+
exports.categoryMediaMeta = categoryMediaMeta;
|
|
2639
|
+
exports.fetcher = fetcher$4;
|
|
2362
2640
|
exports.getCommerceProvider = getCommerceProvider;
|
|
2363
2641
|
exports.productBoxMeta = productBoxMeta;
|
|
2364
2642
|
exports.productCollectionMeta = productCollectionMeta;
|
|
@@ -2366,6 +2644,7 @@ exports.productLinkMeta = productLinkMeta;
|
|
|
2366
2644
|
exports.productMediaMeta = productMediaMeta;
|
|
2367
2645
|
exports.productPriceMeta = productPriceMeta;
|
|
2368
2646
|
exports.productQuantityMeta = productQuantityMeta;
|
|
2647
|
+
exports.productSliderMeta = productSliderMeta;
|
|
2369
2648
|
exports.productTextFieldMeta = productTextFieldMeta;
|
|
2370
2649
|
exports.productVariantPickerMeta = productVariantPickerMeta;
|
|
2371
2650
|
exports.registerAddToCartButton = registerAddToCartButton;
|
|
@@ -2373,12 +2652,15 @@ exports.registerAll = registerAll;
|
|
|
2373
2652
|
exports.registerCart = registerCart;
|
|
2374
2653
|
exports.registerCategoryCollection = registerCategoryCollection;
|
|
2375
2654
|
exports.registerCategoryField = registerCategoryField;
|
|
2655
|
+
exports.registerCategoryLink = registerCategoryLink;
|
|
2656
|
+
exports.registerCategoryMedia = registerCategoryMedia;
|
|
2376
2657
|
exports.registerProductBox = registerProductBox;
|
|
2377
2658
|
exports.registerProductCollection = registerProductCollection;
|
|
2378
2659
|
exports.registerProductLink = registerProductLink;
|
|
2379
2660
|
exports.registerProductMedia = registerProductMedia;
|
|
2380
2661
|
exports.registerProductPrice = registerProductPrice;
|
|
2381
2662
|
exports.registerProductQuantity = registerProductQuantity;
|
|
2663
|
+
exports.registerProductSlider = registerProductSlider;
|
|
2382
2664
|
exports.registerProductVariantPicker = registerProductVariantPicker;
|
|
2383
2665
|
exports.registerTextField = registerTextField;
|
|
2384
2666
|
exports.useAddItem = useAddItem;
|