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