@plasmicpkgs/commerce 0.0.6 → 0.0.9

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.
@@ -172,6 +172,44 @@ function _objectWithoutPropertiesLoose(source, excluded) {
172
172
  return target;
173
173
  }
174
174
 
175
+ function _unsupportedIterableToArray(o, minLen) {
176
+ if (!o) return;
177
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
178
+ var n = Object.prototype.toString.call(o).slice(8, -1);
179
+ if (n === "Object" && o.constructor) n = o.constructor.name;
180
+ if (n === "Map" || n === "Set") return Array.from(o);
181
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
182
+ }
183
+
184
+ function _arrayLikeToArray(arr, len) {
185
+ if (len == null || len > arr.length) len = arr.length;
186
+
187
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
188
+
189
+ return arr2;
190
+ }
191
+
192
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
193
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
194
+ if (it) return (it = it.call(o)).next.bind(it);
195
+
196
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
197
+ if (it) o = it;
198
+ var i = 0;
199
+ return function () {
200
+ if (i >= o.length) return {
201
+ done: true
202
+ };
203
+ return {
204
+ done: false,
205
+ value: o[i++]
206
+ };
207
+ };
208
+ }
209
+
210
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
211
+ }
212
+
175
213
  function createCommonjsModule(fn, module) {
176
214
  return module = { exports: {} }, fn(module, module.exports), module.exports;
177
215
  }
@@ -900,7 +938,39 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
900
938
  }
901
939
  });
902
940
 
941
+ var defaultProduct = {
942
+ id: "123456789",
943
+ name: "Product Placeholder",
944
+ description: "",
945
+ descriptionHtml: "\n <p>This is a <strong>placeholder</strong>.</p>\n <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n ",
946
+ images: [{
947
+ url: "https://static1.plasmic.app/commerce/lightweight-jacket-0.png",
948
+ alt: "Lightweight Jacket"
949
+ }, {
950
+ url: "https://static1.plasmic.app/commerce/lightweight-jacket-1.png",
951
+ alt: "Lightweight Jacket"
952
+ }, {
953
+ url: "https://static1.plasmic.app/commerce/lightweight-jacket-2.png",
954
+ alt: "Lightweight Jacket"
955
+ }],
956
+ variants: [{
957
+ id: "variiant1",
958
+ name: "Variant Placeholder",
959
+ options: []
960
+ }, {
961
+ id: "variant2",
962
+ name: "Variant Placeholder 2",
963
+ options: []
964
+ }],
965
+ price: {
966
+ value: 0,
967
+ currencyCode: "USD"
968
+ },
969
+ options: []
970
+ };
971
+
903
972
  var ProductContext = /*#__PURE__*/React__default.createContext(undefined);
973
+ var CategoryContext = /*#__PURE__*/React__default.createContext(undefined);
904
974
  function ProductProvider(_ref) {
905
975
  var product = _ref.product,
906
976
  children = _ref.children;
@@ -910,9 +980,21 @@ function ProductProvider(_ref) {
910
980
  key: product.id
911
981
  }, React__default.createElement(reactHookForm.FormProvider, Object.assign({}, methods), children));
912
982
  }
913
- function useProduct() {
914
- return React.useContext(ProductContext);
983
+ var useProduct = function useProduct() {
984
+ var product = React.useContext(ProductContext);
985
+ return product != null ? product : defaultProduct;
986
+ };
987
+ function CategoryProvider(_ref2) {
988
+ var category = _ref2.category,
989
+ children = _ref2.children;
990
+ return React__default.createElement(CategoryContext.Provider, {
991
+ value: category,
992
+ key: category.id
993
+ }, children);
915
994
  }
995
+ var useCategoryContext = function useCategoryContext() {
996
+ return React.useContext(CategoryContext);
997
+ };
916
998
 
917
999
  var _excluded = ["children"];
918
1000
  var Commerce = /*#__PURE__*/React.createContext({});
@@ -1183,10 +1265,9 @@ var addToCartButtonMeta = {
1183
1265
  }]
1184
1266
  }
1185
1267
  },
1186
- importPath: "commerce-providers/commerce",
1268
+ importPath: "@plasmicpkgs/commerce",
1187
1269
  importName: "AddToCartButton"
1188
1270
  };
1189
-
1190
1271
  function AddToCartButton(props) {
1191
1272
  var children = props.children;
1192
1273
  var product = useProduct();
@@ -1197,12 +1278,13 @@ function AddToCartButton(props) {
1197
1278
  var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1198
1279
  var _form$getValues$Produ;
1199
1280
 
1200
- var quantity, variantId;
1281
+ var quantity, _form$getValues$Produ2, variantId;
1282
+
1201
1283
  return runtime_1.wrap(function _callee$(_context) {
1202
1284
  while (1) {
1203
1285
  switch (_context.prev = _context.next) {
1204
1286
  case 0:
1205
- quantity = (_form$getValues$Produ = +form.getValues()["ProductQuantity"]) != null ? _form$getValues$Produ : 1;
1287
+ quantity = +((_form$getValues$Produ = form.getValues()["ProductQuantity"]) != null ? _form$getValues$Produ : 1);
1206
1288
 
1207
1289
  if (!(isNaN(quantity) || quantity < 1)) {
1208
1290
  _context.next = 3;
@@ -1219,7 +1301,7 @@ function AddToCartButton(props) {
1219
1301
  break;
1220
1302
  }
1221
1303
 
1222
- variantId = form.getValues()["ProductVariant"];
1304
+ variantId = (_form$getValues$Produ2 = form.getValues()["ProductVariant"]) != null ? _form$getValues$Produ2 : product.variants[0].id;
1223
1305
  _context.next = 7;
1224
1306
  return addItem({
1225
1307
  productId: product.id,
@@ -1250,7 +1332,6 @@ function AddToCartButton(props) {
1250
1332
  }
1251
1333
  }) : null;
1252
1334
  }
1253
-
1254
1335
  function registerAddToCartButton(loader, customAddToCartButtonMeta) {
1255
1336
  var doRegisterComponent = function doRegisterComponent() {
1256
1337
  return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
@@ -1264,16 +1345,148 @@ var fetcher$1 = SWRFetcher;
1264
1345
  var fn$1 = function fn(provider) {
1265
1346
  var _provider$products;
1266
1347
 
1267
- return (_provider$products = provider.products) == null ? void 0 : _provider$products.useSearch;
1348
+ return (_provider$products = provider.products) == null ? void 0 : _provider$products.useProduct;
1268
1349
  };
1269
1350
 
1270
- var useSearch = function useSearch(input) {
1351
+ var useProduct$1 = function useProduct(input) {
1271
1352
  var hook = useHook(fn$1);
1272
1353
  return useSWRHook(_extends({
1273
1354
  fetcher: fetcher$1
1274
1355
  }, hook))(input);
1275
1356
  };
1276
1357
 
1358
+ var productBoxMeta = {
1359
+ name: "plasmic-commerce-product-box",
1360
+ displayName: "Product Box",
1361
+ props: {
1362
+ children: {
1363
+ type: "slot",
1364
+ defaultValue: [{
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
+ }]
1381
+ },
1382
+ noLayout: "boolean",
1383
+ id: {
1384
+ type: "string",
1385
+ description: "Fetch a product by its slug or ID"
1386
+ }
1387
+ },
1388
+ importPath: "@plasmicpkgs/commerce",
1389
+ importName: "ProductBox"
1390
+ };
1391
+ function ProductBox(props) {
1392
+ var className = props.className,
1393
+ children = props.children,
1394
+ noLayout = props.noLayout,
1395
+ id = props.id;
1396
+
1397
+ var _useProduct = useProduct$1({
1398
+ id: id
1399
+ }),
1400
+ data = _useProduct.data,
1401
+ error = _useProduct.error,
1402
+ isLoading = _useProduct.isLoading;
1403
+
1404
+ if (!id) {
1405
+ return React__default.createElement("span", null, "You must set the id prop");
1406
+ }
1407
+
1408
+ if (error) {
1409
+ throw new CommerceError({
1410
+ message: error.message,
1411
+ code: error.code
1412
+ });
1413
+ }
1414
+
1415
+ if (isLoading) {
1416
+ return React__default.createElement("span", null, "Loading...");
1417
+ }
1418
+
1419
+ if (!data) {
1420
+ throw new Error("Product not found!");
1421
+ }
1422
+
1423
+ var renderedData = React__default.createElement(ProductProvider, {
1424
+ product: data
1425
+ }, children);
1426
+ return noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
1427
+ className: className
1428
+ }, renderedData);
1429
+ }
1430
+ function registerProductBox(loader, customProductBoxMeta) {
1431
+ var doRegisterComponent = function doRegisterComponent() {
1432
+ return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
1433
+ };
1434
+
1435
+ doRegisterComponent(ProductBox, customProductBoxMeta != null ? customProductBoxMeta : productBoxMeta);
1436
+ }
1437
+
1438
+ var fetcher$2 = SWRFetcher;
1439
+
1440
+ 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
+ var _provider$site;
1457
+
1458
+ return (_provider$site = provider.site) == null ? void 0 : _provider$site.useCategories;
1459
+ };
1460
+
1461
+ var useCategories = function useCategories(input) {
1462
+ var hook = useHook(fn$3);
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);
1478
+ return useSWRHook(_extends({
1479
+ fetcher: fetcher$4
1480
+ }, hook))(input);
1481
+ };
1482
+
1483
+ var useCommerceExtraFeatures = function useCommerceExtraFeatures() {
1484
+ var _useCommerce = useCommerce(),
1485
+ providerRef = _useCommerce.providerRef;
1486
+
1487
+ return providerRef.current.extraFeatures;
1488
+ };
1489
+
1277
1490
  var productCollectionMeta = {
1278
1491
  name: "plasmic-commerce-product-collection",
1279
1492
  displayName: "Product Collection",
@@ -1298,6 +1511,20 @@ var productCollectionMeta = {
1298
1511
  }
1299
1512
  }]
1300
1513
  },
1514
+ emptyMessage: {
1515
+ type: "slot",
1516
+ defaultValue: {
1517
+ type: "text",
1518
+ value: "No product found!"
1519
+ }
1520
+ },
1521
+ loadingMessage: {
1522
+ type: "slot",
1523
+ defaultValue: {
1524
+ type: "text",
1525
+ value: "Loading..."
1526
+ }
1527
+ },
1301
1528
  count: "number",
1302
1529
  category: {
1303
1530
  type: "choice",
@@ -1310,6 +1537,17 @@ var productCollectionMeta = {
1310
1537
  value: category.id
1311
1538
  };
1312
1539
  })) != 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);
1313
1551
  }
1314
1552
  },
1315
1553
  brand: {
@@ -1335,36 +1573,51 @@ var productCollectionMeta = {
1335
1573
  padding: "8px",
1336
1574
  maxWidth: "100%"
1337
1575
  },
1338
- importPath: "commerce-providers/commerce",
1576
+ importPath: "@plasmicpkgs/commerce",
1339
1577
  importName: "ProductCollection"
1340
1578
  };
1341
-
1342
1579
  function ProductCollection(props) {
1580
+ var _categoryCtx$id;
1581
+
1343
1582
  var className = props.className,
1344
1583
  children = props.children,
1345
1584
  count = props.count,
1346
1585
  category = props.category,
1586
+ includeSubCategories = props.includeSubCategories,
1347
1587
  brand = props.brand,
1348
1588
  noLayout = props.noLayout,
1349
- setControlContextData = props.setControlContextData;
1589
+ setControlContextData = props.setControlContextData,
1590
+ emptyMessage = props.emptyMessage,
1591
+ loadingMessage = props.loadingMessage;
1592
+
1593
+ var _useCategories = useCategories(),
1594
+ categories = _useCategories.data,
1595
+ isCategoriesLoading = _useCategories.isLoading;
1596
+
1597
+ var _useBrands = useBrands(),
1598
+ brands = _useBrands.data,
1599
+ isBrandsLoading = _useBrands.isLoading;
1600
+
1601
+ var categoryCtx = useCategoryContext();
1350
1602
 
1351
1603
  var _useSearch = useSearch({
1352
- categoryId: category,
1604
+ categoryId: (_categoryCtx$id = categoryCtx == null ? void 0 : categoryCtx.id) != null ? _categoryCtx$id : category,
1353
1605
  brandId: brand,
1354
- count: count
1606
+ count: count,
1607
+ categories: categories != null ? categories : [],
1608
+ includeSubCategories: includeSubCategories
1355
1609
  }),
1356
- data = _useSearch.data;
1357
-
1358
- var _useCategories = useCategories({}),
1359
- categories = _useCategories.data;
1610
+ data = _useSearch.data,
1611
+ isSearchLoading = _useSearch.isLoading;
1360
1612
 
1361
- var _useBrands = useBrands({}),
1362
- brands = _useBrands.data;
1613
+ var features = useCommerceExtraFeatures();
1363
1614
 
1364
1615
  if (categories && brands) {
1365
1616
  setControlContextData == null ? void 0 : setControlContextData({
1366
1617
  categories: categories,
1367
- brands: brands
1618
+ brands: brands,
1619
+ features: features,
1620
+ hasCategoryCtx: !!categoryCtx
1368
1621
  });
1369
1622
  }
1370
1623
 
@@ -1374,11 +1627,19 @@ function ProductCollection(props) {
1374
1627
  key: product.id
1375
1628
  }, host.repeatedElement(i === 0, children));
1376
1629
  });
1630
+
1631
+ if ([isSearchLoading, isBrandsLoading, isCategoriesLoading].includes(true)) {
1632
+ return React__default.isValidElement(loadingMessage) ? loadingMessage : null;
1633
+ }
1634
+
1635
+ if (!data || data.products.length === 0) {
1636
+ return React__default.isValidElement(emptyMessage) ? emptyMessage : null;
1637
+ }
1638
+
1377
1639
  return noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
1378
1640
  className: className
1379
1641
  }, renderedData);
1380
1642
  }
1381
-
1382
1643
  function registerProductCollection(loader, customProductCollectionMeta) {
1383
1644
  var doRegisterComponent = function doRegisterComponent() {
1384
1645
  return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
@@ -1387,6 +1648,69 @@ function registerProductCollection(loader, customProductCollectionMeta) {
1387
1648
  doRegisterComponent(ProductCollection, customProductCollectionMeta != null ? customProductCollectionMeta : productCollectionMeta);
1388
1649
  }
1389
1650
 
1651
+ var productLinkMeta = {
1652
+ name: "plasmic-commerce-product-link",
1653
+ displayName: "Product Link",
1654
+ props: {
1655
+ children: "slot",
1656
+ linkDest: {
1657
+ type: "string",
1658
+ defaultValueHint: "products/{slug}",
1659
+ description: "Set the link destination. You can use {slug} to replace by the product slug"
1660
+ }
1661
+ },
1662
+ importPath: "@plasmicpkgs/commerce",
1663
+ importName: "ProductLink"
1664
+ };
1665
+ function ProductLink(props) {
1666
+ var className = props.className,
1667
+ children = props.children,
1668
+ linkDest = props.linkDest;
1669
+ var product = useProduct();
1670
+
1671
+ var resolveLink = function resolveLink(linkDest) {
1672
+ var _linkDest$match;
1673
+
1674
+ if (!product || !linkDest) {
1675
+ return undefined;
1676
+ }
1677
+
1678
+ var regex = /{[^}]*}/;
1679
+ var regexAll = new RegExp(regex, "g");
1680
+ var matches = (_linkDest$match = linkDest.match(regexAll)) != null ? _linkDest$match : [];
1681
+ var resolvedLink = linkDest;
1682
+
1683
+ for (var _iterator = _createForOfIteratorHelperLoose(matches), _step; !(_step = _iterator()).done;) {
1684
+ var match = _step.value;
1685
+ var field = match.slice(1, -1);
1686
+
1687
+ if (!(field in product)) {
1688
+ return undefined;
1689
+ }
1690
+
1691
+ resolvedLink = resolvedLink.replace(regex, product[field]);
1692
+ }
1693
+
1694
+ return resolvedLink;
1695
+ };
1696
+
1697
+ return React__default.createElement("a", {
1698
+ className: className,
1699
+ href: resolveLink(linkDest),
1700
+ style: {
1701
+ color: "inherit",
1702
+ textDecoration: "inherit"
1703
+ }
1704
+ }, children);
1705
+ }
1706
+ function registerProductLink(loader, customProductLinkMeta) {
1707
+ var doRegisterComponent = function doRegisterComponent() {
1708
+ return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
1709
+ };
1710
+
1711
+ doRegisterComponent(ProductLink, customProductLinkMeta != null ? customProductLinkMeta : productLinkMeta);
1712
+ }
1713
+
1390
1714
  var placeholderImage = "https://static1.plasmic.app/commerce/lightweight-jacket-0.png";
1391
1715
  var productMediaMeta = {
1392
1716
  name: "plasmic-commerce-product-media",
@@ -1394,7 +1718,7 @@ var productMediaMeta = {
1394
1718
  props: {
1395
1719
  mediaIndex: "number"
1396
1720
  },
1397
- importPath: "commerce-providers/commerce",
1721
+ importPath: "@plasmicpkgs/commerce",
1398
1722
  importName: "ProductMedia"
1399
1723
  };
1400
1724
  function ProductMedia(props) {
@@ -1499,19 +1823,16 @@ var productPriceMeta = {
1499
1823
  name: "plasmic-commerce-product-price",
1500
1824
  displayName: "Product Price",
1501
1825
  props: {},
1502
- importPath: "commerce-providers/commerce",
1826
+ importPath: "@plasmicpkgs/commerce",
1503
1827
  importName: "ProductPrice"
1504
1828
  };
1505
- function ProductPrice(props) {
1829
+ function ProductPriceComponent(props) {
1830
+ var _product$variants$0$i;
1831
+
1506
1832
  var className = props.className;
1507
1833
  var product = useProduct();
1508
1834
  var form = reactHookForm.useFormContext();
1509
-
1510
- if (!product) {
1511
- throw new Error("This component must be within a product context.");
1512
- }
1513
-
1514
- var watchProductVariant = form.watch("ProductVariant", product == null ? void 0 : product.variants[0].id);
1835
+ var watchProductVariant = form == null ? void 0 : form.watch("ProductVariant", (_product$variants$0$i = product.variants[0].id) != null ? _product$variants$0$i : "");
1515
1836
 
1516
1837
  var _usePrice = usePrice({
1517
1838
  amount: product ? getProductPrice(product, watchProductVariant) : 0,
@@ -1528,7 +1849,7 @@ function registerProductPrice(loader, customProductPriceMeta) {
1528
1849
  return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
1529
1850
  };
1530
1851
 
1531
- doRegisterComponent(ProductPrice, customProductPriceMeta != null ? customProductPriceMeta : productPriceMeta);
1852
+ doRegisterComponent(ProductPriceComponent, customProductPriceMeta != null ? customProductPriceMeta : productPriceMeta);
1532
1853
  }
1533
1854
 
1534
1855
  var productQuantityMeta = {
@@ -1545,7 +1866,7 @@ var productQuantityMeta = {
1545
1866
  }]
1546
1867
  }
1547
1868
  },
1548
- importPath: "commerce-providers/commerce",
1869
+ importPath: "@plasmicpkgs/commerce",
1549
1870
  importName: "ProductQuantity"
1550
1871
  };
1551
1872
  function ProductQuantity(props) {
@@ -1583,7 +1904,7 @@ var productTextFieldMeta = {
1583
1904
  options: ["id", "name", "description", "sku", "slug", "path"]
1584
1905
  }
1585
1906
  },
1586
- importPath: "commerce-providers/commerce",
1907
+ importPath: "@plasmicpkgs/commerce",
1587
1908
  importName: "ProductTextField"
1588
1909
  };
1589
1910
  function ProductTextField(props) {
@@ -1634,13 +1955,15 @@ var productVariantPickerMeta = {
1634
1955
  name: "plasmic-commerce-product-variant-picker",
1635
1956
  displayName: "Product Variant Picker",
1636
1957
  props: {},
1637
- importPath: "commerce-providers/commerce",
1958
+ importPath: "@plasmicpkgs/commerce",
1638
1959
  importName: "ProductVariantPicker"
1639
1960
  };
1640
1961
  function ProductVariantPicker(props) {
1962
+ var _useFormContext;
1963
+
1641
1964
  var className = props.className;
1642
1965
  var product = useProduct();
1643
- var form = reactHookForm.useFormContext();
1966
+ var form = (_useFormContext = reactHookForm.useFormContext()) != null ? _useFormContext : reactHookForm.useForm();
1644
1967
  return React__default.createElement(reactHookForm.Controller, {
1645
1968
  name: "ProductVariant",
1646
1969
  control: form == null ? void 0 : form.control,
@@ -1655,7 +1978,7 @@ function ProductVariantPicker(props) {
1655
1978
  return React__default.createElement("option", {
1656
1979
  value: variant.id
1657
1980
  }, variant.name);
1658
- })) != null ? _product$variants$map : React__default.createElement("option", null, "Fake Product Variant"));
1981
+ })) != null ? _product$variants$map : React__default.createElement("option", null, "Product Variant Placeholder"));
1659
1982
  }
1660
1983
  });
1661
1984
  }
@@ -1667,7 +1990,7 @@ function registerProductVariantPicker(loader, customProductVariantPickerMeta) {
1667
1990
  doRegisterComponent(ProductVariantPicker, customProductVariantPickerMeta != null ? customProductVariantPickerMeta : productVariantPickerMeta);
1668
1991
  }
1669
1992
 
1670
- var fetcher$2 = /*#__PURE__*/function () {
1993
+ var fetcher$5 = /*#__PURE__*/function () {
1671
1994
  var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
1672
1995
  var options, cartId, fetch;
1673
1996
  return runtime_1.wrap(function _callee$(_context) {
@@ -1708,7 +2031,7 @@ var fetcher$2 = /*#__PURE__*/function () {
1708
2031
  };
1709
2032
  }();
1710
2033
 
1711
- var fn$2 = function fn(provider) {
2034
+ var fn$5 = function fn(provider) {
1712
2035
  var _provider$cart;
1713
2036
 
1714
2037
  return (_provider$cart = provider.cart) == null ? void 0 : _provider$cart.useCart;
@@ -1717,12 +2040,12 @@ var fn$2 = function fn(provider) {
1717
2040
  var useCart = function useCart(input) {
1718
2041
  var _hook$fetcher;
1719
2042
 
1720
- var hook = useHook(fn$2);
2043
+ var hook = useHook(fn$5);
1721
2044
 
1722
2045
  var _useCommerce = useCommerce(),
1723
2046
  cartCookie = _useCommerce.cartCookie;
1724
2047
 
1725
- var fetcherFn = (_hook$fetcher = hook.fetcher) != null ? _hook$fetcher : fetcher$2;
2048
+ var fetcherFn = (_hook$fetcher = hook.fetcher) != null ? _hook$fetcher : fetcher$5;
1726
2049
 
1727
2050
  var wrapper = function wrapper(context) {
1728
2051
  context.input.cartId = Cookies.get(cartCookie);
@@ -1734,24 +2057,27 @@ var useCart = function useCart(input) {
1734
2057
  }))(input);
1735
2058
  };
1736
2059
 
1737
- var useCartMeta = {
1738
- name: "plasmic-commerce-use-cart",
1739
- displayName: "Use Cart",
2060
+ var cartMeta = {
2061
+ name: "plasmic-commerce-cart",
2062
+ displayName: "Cart",
1740
2063
  props: {
1741
2064
  field: {
1742
2065
  type: "choice",
1743
2066
  options: ["Size", "Total Price"]
2067
+ },
2068
+ hideIfIsEmpty: {
2069
+ type: "boolean"
1744
2070
  }
1745
2071
  },
1746
- importPath: "commerce-providers/commerce",
1747
- importName: "UseCart"
2072
+ importPath: "@plasmicpkgs/commerce",
2073
+ importName: "Cart"
1748
2074
  };
1749
-
1750
- function UseCartComponent(props) {
2075
+ function CartComponent(props) {
1751
2076
  var _data$totalPrice, _data$currency$code;
1752
2077
 
1753
2078
  var className = props.className,
1754
- field = props.field;
2079
+ field = props.field,
2080
+ hideIfIsEmpty = props.hideIfIsEmpty;
1755
2081
 
1756
2082
  var _useCart = useCart(),
1757
2083
  data = _useCart.data;
@@ -1771,91 +2097,214 @@ function UseCartComponent(props) {
1771
2097
  if (field === "Size") {
1772
2098
  var _data$lineItems$lengt;
1773
2099
 
1774
- value = "" + ((_data$lineItems$lengt = data == null ? void 0 : data.lineItems.length) != null ? _data$lineItems$lengt : 0);
2100
+ value = (_data$lineItems$lengt = data == null ? void 0 : data.lineItems.length) != null ? _data$lineItems$lengt : 0;
1775
2101
  } else if (field === "Total Price") {
1776
- value = "" + price;
2102
+ value = price != null ? price : 0;
1777
2103
  }
1778
2104
 
1779
- return React__default.createElement("span", {
2105
+ return hideIfIsEmpty && value === 0 ? null : React__default.createElement("span", {
1780
2106
  className: className
1781
2107
  }, value);
1782
2108
  }
1783
-
1784
- function registerUseCart(loader, customUseCartMeta) {
2109
+ function registerCart(loader, customCartMeta) {
1785
2110
  var doRegisterComponent = function doRegisterComponent() {
1786
2111
  return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
1787
2112
  };
1788
2113
 
1789
- doRegisterComponent(UseCartComponent, customUseCartMeta != null ? customUseCartMeta : useCartMeta);
2114
+ doRegisterComponent(CartComponent, customCartMeta != null ? customCartMeta : cartMeta);
1790
2115
  }
1791
2116
 
1792
- var x = function x() {
1793
- return 2;
2117
+ var categoryCollectionMeta = {
2118
+ name: "plasmic-commerce-category-collection",
2119
+ displayName: "Category Collection",
2120
+ props: {
2121
+ children: {
2122
+ type: "slot",
2123
+ defaultValue: [{
2124
+ type: "vbox",
2125
+ children: [{
2126
+ type: "component",
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
2138
+ }
2139
+ }]
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
+ }
2171
+ },
2172
+ defaultStyles: {
2173
+ display: "grid",
2174
+ gridTemplateColumns: "1fr",
2175
+ gridRowGap: "8px",
2176
+ padding: "8px",
2177
+ maxWidth: "100%"
2178
+ },
2179
+ importPath: "@plasmicpkgs/commerce",
2180
+ importName: "CategoryCollection"
1794
2181
  };
2182
+ function CategoryCollection(props) {
2183
+ var children = props.children,
2184
+ noLayout = props.noLayout,
2185
+ className = props.className,
2186
+ loadingMessage = props.loadingMessage,
2187
+ emptyMessage = props.emptyMessage,
2188
+ selectedCategory = props.category,
2189
+ setControlContextData = props.setControlContextData;
2190
+ var features = useCommerceExtraFeatures();
2191
+ var inEditor = host.usePlasmicCanvasContext();
1795
2192
 
2193
+ var _useCategories = useCategories(),
2194
+ allCategories = _useCategories.data,
2195
+ isAllCategoriesLoading = _useCategories.isLoading;
1796
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;
1797
2204
 
1798
- var product = {
1799
- __proto__: null
1800
- };
2205
+ if (allCategories) {
2206
+ setControlContextData == null ? void 0 : setControlContextData({
2207
+ categories: allCategories
2208
+ });
2209
+ }
1801
2210
 
1802
- var fetcher$3 = SWRFetcher;
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
+ });
1803
2220
 
1804
- var fn$3 = function fn(provider) {
1805
- var _provider$site;
2221
+ if ([isAllCategoriesLoading, isLoading].includes(true)) {
2222
+ return React__default.isValidElement(loadingMessage) ? loadingMessage : null;
2223
+ }
1806
2224
 
1807
- return (_provider$site = provider.site) == null ? void 0 : _provider$site.useCategories;
1808
- };
2225
+ if (!categories || categories.length === 0) {
2226
+ return React__default.isValidElement(emptyMessage) ? emptyMessage : null;
2227
+ }
1809
2228
 
1810
- var useCategories = function useCategories(input) {
1811
- var hook = useHook(fn$3);
1812
- return useSWRHook(_extends({
1813
- fetcher: fetcher$3
1814
- }, hook))(input);
2229
+ return noLayout ? React__default.createElement(React__default.Fragment, null, renderedData) : React__default.createElement("div", {
2230
+ className: className
2231
+ }, renderedData);
2232
+ }
2233
+ function registerCategoryCollection(loader, customCategoryCollectionMeta) {
2234
+ var doRegisterComponent = function doRegisterComponent() {
2235
+ return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
2236
+ };
2237
+
2238
+ doRegisterComponent(CategoryCollection, customCategoryCollectionMeta != null ? customCategoryCollectionMeta : categoryCollectionMeta);
2239
+ }
2240
+
2241
+ var categoryFieldMeta = {
2242
+ name: "plasmic-commerce-category-field",
2243
+ displayName: "Category Field",
2244
+ props: {
2245
+ field: {
2246
+ type: "choice",
2247
+ options: ["id", "name", "slug", "path"]
2248
+ }
2249
+ },
2250
+ importPath: "@plasmicpkgs/commerce",
2251
+ importName: "CategoryField"
1815
2252
  };
2253
+ function CategoryField(props) {
2254
+ var className = props.className,
2255
+ field = props.field;
2256
+ var category = useCategoryContext();
1816
2257
 
1817
- var fetcher$4 = SWRFetcher;
2258
+ if (!field) {
2259
+ return React__default.createElement("span", null, "You must set the field prop");
2260
+ }
1818
2261
 
1819
- var fn$4 = function fn(provider) {
1820
- var _provider$site;
2262
+ var data = category ? category[field] : "Category field placeholder";
2263
+ return React__default.createElement("span", {
2264
+ className: className
2265
+ }, data);
2266
+ }
2267
+ function registerCategoryField(loader, customCategoryFieldMeta) {
2268
+ var doRegisterComponent = function doRegisterComponent() {
2269
+ return loader ? loader.registerComponent.apply(loader, arguments) : registerComponent.apply(void 0, arguments);
2270
+ };
1821
2271
 
1822
- return (_provider$site = provider.site) == null ? void 0 : _provider$site.useBrands;
1823
- };
2272
+ doRegisterComponent(CategoryField, customCategoryFieldMeta != null ? customCategoryFieldMeta : categoryFieldMeta);
2273
+ }
1824
2274
 
1825
- var useBrands = function useBrands(input) {
1826
- var hook = useHook(fn$4);
1827
- return useSWRHook(_extends({
1828
- fetcher: fetcher$4
1829
- }, hook))(input);
2275
+
2276
+
2277
+ var product = {
2278
+ __proto__: null
1830
2279
  };
1831
2280
 
1832
- var fetcher$5 = mutationFetcher;
2281
+ var fetcher$6 = mutationFetcher;
1833
2282
 
1834
- var fn$5 = function fn(provider) {
2283
+ var fn$6 = function fn(provider) {
1835
2284
  var _provider$cart;
1836
2285
 
1837
2286
  return (_provider$cart = provider.cart) == null ? void 0 : _provider$cart.useRemoveItem;
1838
2287
  };
1839
2288
 
1840
2289
  var useRemoveItem = function useRemoveItem(input) {
1841
- var hook = useHook(fn$5);
2290
+ var hook = useHook(fn$6);
1842
2291
  return useMutationHook(_extends({
1843
- fetcher: fetcher$5
2292
+ fetcher: fetcher$6
1844
2293
  }, hook))(input);
1845
2294
  };
1846
2295
 
1847
- var fetcher$6 = mutationFetcher;
2296
+ var fetcher$7 = mutationFetcher;
1848
2297
 
1849
- var fn$6 = function fn(provider) {
2298
+ var fn$7 = function fn(provider) {
1850
2299
  var _provider$cart;
1851
2300
 
1852
2301
  return (_provider$cart = provider.cart) == null ? void 0 : _provider$cart.useUpdateItem;
1853
2302
  };
1854
2303
 
1855
2304
  var useUpdateItem = function useUpdateItem(input) {
1856
- var hook = useHook(fn$6);
2305
+ var hook = useHook(fn$7);
1857
2306
  return useMutationHook(_extends({
1858
- fetcher: fetcher$6
2307
+ fetcher: fetcher$7
1859
2308
  }, hook))(input);
1860
2309
  };
1861
2310
 
@@ -1876,29 +2325,69 @@ function registerAll(loader) {
1876
2325
  registerTextField(loader);
1877
2326
  registerProductPrice(loader);
1878
2327
  registerProductMedia(loader);
1879
- registerUseCart(loader);
2328
+ registerCart(loader);
1880
2329
  registerAddToCartButton(loader);
1881
2330
  registerProductQuantity(loader);
1882
2331
  registerProductVariantPicker(loader);
2332
+ registerProductBox(loader);
2333
+ registerProductLink(loader);
2334
+ registerCategoryCollection(loader);
2335
+ registerCategoryField(loader);
1883
2336
  }
1884
2337
 
2338
+ exports.AddToCartButton = AddToCartButton;
2339
+ exports.CartComponent = CartComponent;
1885
2340
  exports.CartType = cart;
2341
+ exports.CategoryCollection = CategoryCollection;
2342
+ exports.CategoryField = CategoryField;
1886
2343
  exports.CommerceError = CommerceError;
1887
2344
  exports.CoreCommerceProvider = CoreCommerceProvider;
1888
2345
  exports.FetcherError = FetcherError;
2346
+ exports.ProductBox = ProductBox;
2347
+ exports.ProductCollection = ProductCollection;
2348
+ exports.ProductLink = ProductLink;
2349
+ exports.ProductMedia = ProductMedia;
2350
+ exports.ProductPriceComponent = ProductPriceComponent;
2351
+ exports.ProductQuantity = ProductQuantity;
2352
+ exports.ProductTextField = ProductTextField;
1889
2353
  exports.ProductTypes = product;
2354
+ exports.ProductVariantPicker = ProductVariantPicker;
1890
2355
  exports.SiteTypes = site;
1891
2356
  exports.ValidationError = ValidationError;
1892
- exports.fetcher = fetcher$1;
2357
+ exports.addToCartButtonMeta = addToCartButtonMeta;
2358
+ exports.cartMeta = cartMeta;
2359
+ exports.categoryCollectionMeta = categoryCollectionMeta;
2360
+ exports.categoryFieldMeta = categoryFieldMeta;
2361
+ exports.fetcher = fetcher$2;
1893
2362
  exports.getCommerceProvider = getCommerceProvider;
2363
+ exports.productBoxMeta = productBoxMeta;
2364
+ exports.productCollectionMeta = productCollectionMeta;
2365
+ exports.productLinkMeta = productLinkMeta;
2366
+ exports.productMediaMeta = productMediaMeta;
2367
+ exports.productPriceMeta = productPriceMeta;
2368
+ exports.productQuantityMeta = productQuantityMeta;
2369
+ exports.productTextFieldMeta = productTextFieldMeta;
2370
+ exports.productVariantPickerMeta = productVariantPickerMeta;
2371
+ exports.registerAddToCartButton = registerAddToCartButton;
1894
2372
  exports.registerAll = registerAll;
2373
+ exports.registerCart = registerCart;
2374
+ exports.registerCategoryCollection = registerCategoryCollection;
2375
+ exports.registerCategoryField = registerCategoryField;
2376
+ exports.registerProductBox = registerProductBox;
2377
+ exports.registerProductCollection = registerProductCollection;
2378
+ exports.registerProductLink = registerProductLink;
2379
+ exports.registerProductMedia = registerProductMedia;
2380
+ exports.registerProductPrice = registerProductPrice;
2381
+ exports.registerProductQuantity = registerProductQuantity;
2382
+ exports.registerProductVariantPicker = registerProductVariantPicker;
2383
+ exports.registerTextField = registerTextField;
1895
2384
  exports.useAddItem = useAddItem;
1896
2385
  exports.useBrands = useBrands;
1897
2386
  exports.useCart = useCart;
1898
2387
  exports.useCategories = useCategories;
1899
2388
  exports.useCommerce = useCommerce;
2389
+ exports.useProduct = useProduct$1;
1900
2390
  exports.useRemoveItem = useRemoveItem;
1901
2391
  exports.useSearch = useSearch;
1902
2392
  exports.useUpdateItem = useUpdateItem;
1903
- exports.x = x;
1904
2393
  //# sourceMappingURL=commerce.cjs.development.js.map