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