@plasmicpkgs/commerce-swell 0.0.18 → 0.0.21
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-swell.cjs.development.js +40 -102
- package/dist/commerce-swell.cjs.development.js.map +1 -1
- package/dist/commerce-swell.cjs.production.min.js +1 -1
- package/dist/commerce-swell.cjs.production.min.js.map +1 -1
- package/dist/commerce-swell.esm.js +40 -102
- package/dist/commerce-swell.esm.js.map +1 -1
- package/dist/product/use-search.d.ts +3 -3
- package/package.json +4 -4
|
@@ -1590,7 +1590,7 @@ var walkCategoryTree = function walkCategoryTree(category, categories) {
|
|
|
1590
1590
|
queue.push.apply(queue, (_curr$children$map = (_curr$children = curr.children) == null ? void 0 : _curr$children.map(function (child) {
|
|
1591
1591
|
return ensure(categories.find(function (category) {
|
|
1592
1592
|
return category.id === child;
|
|
1593
|
-
}));
|
|
1593
|
+
}), "The child category must always exist in the categories list");
|
|
1594
1594
|
})) != null ? _curr$children$map : []);
|
|
1595
1595
|
}
|
|
1596
1596
|
|
|
@@ -1606,132 +1606,70 @@ var topologicalSortForCategoryTree = function topologicalSortForCategoryTree(cat
|
|
|
1606
1606
|
|
|
1607
1607
|
var handler$4 = {
|
|
1608
1608
|
fetchOptions: {
|
|
1609
|
-
query:
|
|
1610
|
-
method:
|
|
1609
|
+
query: "products",
|
|
1610
|
+
method: "list"
|
|
1611
1611
|
},
|
|
1612
1612
|
fetcher: function fetcher(_ref) {
|
|
1613
|
-
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1614
|
-
var input, options, fetch, sortMap, categoryId, includeSubCategories, categories, brandId, search, _input$sort, sort, count, mappedSort,
|
|
1613
|
+
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
1614
|
+
var input, options, fetch, sortMap, categoryId, includeSubCategories, categories, brandId, search, _input$sort, sort, count, mappedSort, includedCategories, _yield$fetch, products;
|
|
1615
1615
|
|
|
1616
|
-
return runtime_1.wrap(function
|
|
1616
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1617
1617
|
while (1) {
|
|
1618
|
-
switch (
|
|
1618
|
+
switch (_context.prev = _context.next) {
|
|
1619
1619
|
case 0:
|
|
1620
1620
|
input = _ref.input, options = _ref.options, fetch = _ref.fetch;
|
|
1621
|
-
sortMap = new Map([[
|
|
1622
|
-
categoryId = input.categoryId, includeSubCategories = input.includeSubCategories, categories = input.categories, brandId = input.brandId, search = input.search, _input$sort = input.sort, sort = _input$sort === void 0 ?
|
|
1621
|
+
sortMap = new Map([["latest-desc", ""], ["price-asc", "price asc"], ["price-desc", "price desc"], ["trending-desc", "popularity"]]);
|
|
1622
|
+
categoryId = input.categoryId, includeSubCategories = input.includeSubCategories, categories = input.categories, brandId = input.brandId, search = input.search, _input$sort = input.sort, sort = _input$sort === void 0 ? "latest-desc" : _input$sort, count = input.count;
|
|
1623
1623
|
mappedSort = sortMap.get(sort);
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
_fetch = /*#__PURE__*/function () {
|
|
1627
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(categoryId) {
|
|
1628
|
-
var _yield$fetch, results;
|
|
1629
|
-
|
|
1630
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1631
|
-
while (1) {
|
|
1632
|
-
switch (_context.prev = _context.next) {
|
|
1633
|
-
case 0:
|
|
1634
|
-
_context.next = 2;
|
|
1635
|
-
return fetch({
|
|
1636
|
-
query: options.query,
|
|
1637
|
-
method: options.method,
|
|
1638
|
-
variables: {
|
|
1639
|
-
category: categoryId,
|
|
1640
|
-
brand: brandId,
|
|
1641
|
-
search: search,
|
|
1642
|
-
sort: mappedSort,
|
|
1643
|
-
expand: ["variants"],
|
|
1644
|
-
limit: count
|
|
1645
|
-
}
|
|
1646
|
-
});
|
|
1647
|
-
|
|
1648
|
-
case 2:
|
|
1649
|
-
_yield$fetch = _context.sent;
|
|
1650
|
-
results = _yield$fetch.results;
|
|
1651
|
-
return _context.abrupt("return", results);
|
|
1652
|
-
|
|
1653
|
-
case 5:
|
|
1654
|
-
case "end":
|
|
1655
|
-
return _context.stop();
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
}, _callee);
|
|
1659
|
-
}));
|
|
1660
|
-
|
|
1661
|
-
return function _fetch(_x) {
|
|
1662
|
-
return _ref2.apply(this, arguments);
|
|
1663
|
-
};
|
|
1664
|
-
}();
|
|
1665
|
-
|
|
1666
|
-
if (includeSubCategories) {
|
|
1667
|
-
_context3.next = 12;
|
|
1668
|
-
break;
|
|
1669
|
-
}
|
|
1670
|
-
|
|
1671
|
-
_context3.next = 9;
|
|
1672
|
-
return _fetch(categoryId);
|
|
1673
|
-
|
|
1674
|
-
case 9:
|
|
1675
|
-
products = _context3.sent;
|
|
1676
|
-
_context3.next = 16;
|
|
1677
|
-
break;
|
|
1678
|
-
|
|
1679
|
-
case 12:
|
|
1680
|
-
includedCategories = walkCategoryTree(categories == null ? void 0 : categories.find(function (category) {
|
|
1624
|
+
includedCategories = includeSubCategories ? walkCategoryTree(categories == null ? void 0 : categories.find(function (category) {
|
|
1681
1625
|
return category.id === categoryId;
|
|
1682
|
-
}), categories);
|
|
1683
|
-
|
|
1684
|
-
return
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
return _ref3.apply(this, arguments);
|
|
1702
|
-
};
|
|
1703
|
-
}()));
|
|
1704
|
-
|
|
1705
|
-
case 15:
|
|
1706
|
-
products = _context3.sent.flatMap(function (products) {
|
|
1707
|
-
return products;
|
|
1708
|
-
}).slice(0, count);
|
|
1626
|
+
}), categories) : undefined;
|
|
1627
|
+
_context.next = 7;
|
|
1628
|
+
return fetch({
|
|
1629
|
+
query: options.query,
|
|
1630
|
+
method: options.method,
|
|
1631
|
+
variables: {
|
|
1632
|
+
category: !includeSubCategories ? categoryId : undefined,
|
|
1633
|
+
brand: brandId,
|
|
1634
|
+
search: search,
|
|
1635
|
+
sort: mappedSort,
|
|
1636
|
+
expand: ["variants"],
|
|
1637
|
+
limit: count,
|
|
1638
|
+
$filters: _extends({}, includeSubCategories ? {
|
|
1639
|
+
category: includedCategories == null ? void 0 : includedCategories.map(function (c) {
|
|
1640
|
+
return c.id;
|
|
1641
|
+
})
|
|
1642
|
+
} : {})
|
|
1643
|
+
}
|
|
1644
|
+
});
|
|
1709
1645
|
|
|
1710
|
-
case
|
|
1711
|
-
|
|
1646
|
+
case 7:
|
|
1647
|
+
_yield$fetch = _context.sent;
|
|
1648
|
+
products = _yield$fetch.results;
|
|
1649
|
+
return _context.abrupt("return", {
|
|
1712
1650
|
products: products.map(function (product) {
|
|
1713
1651
|
return normalizeProduct(product);
|
|
1714
1652
|
}),
|
|
1715
1653
|
found: products.length > 0
|
|
1716
1654
|
});
|
|
1717
1655
|
|
|
1718
|
-
case
|
|
1656
|
+
case 10:
|
|
1719
1657
|
case "end":
|
|
1720
|
-
return
|
|
1658
|
+
return _context.stop();
|
|
1721
1659
|
}
|
|
1722
1660
|
}
|
|
1723
|
-
},
|
|
1661
|
+
}, _callee);
|
|
1724
1662
|
}))();
|
|
1725
1663
|
},
|
|
1726
|
-
useHook: function useHook(
|
|
1727
|
-
var useData =
|
|
1664
|
+
useHook: function useHook(_ref2) {
|
|
1665
|
+
var useData = _ref2.useData;
|
|
1728
1666
|
return function (input) {
|
|
1729
1667
|
if (input === void 0) {
|
|
1730
1668
|
input = {};
|
|
1731
1669
|
}
|
|
1732
1670
|
|
|
1733
1671
|
return useData({
|
|
1734
|
-
input: [[
|
|
1672
|
+
input: [["search", input.search], ["categoryId", input.categoryId], ["includeSubCategories", input.includeSubCategories], ["categories", input.categories], ["brandId", input.brandId], ["sort", input.sort], ["count", input.count]],
|
|
1735
1673
|
swrOptions: _extends({
|
|
1736
1674
|
revalidateOnFocus: false
|
|
1737
1675
|
}, input.swrOptions)
|
|
@@ -1879,7 +1817,7 @@ var handler$6 = {
|
|
|
1879
1817
|
categories = _context2.sent;
|
|
1880
1818
|
|
|
1881
1819
|
case 10:
|
|
1882
|
-
normalizedCategories = topologicalSortForCategoryTree(categories.map(normalizeCategory));
|
|
1820
|
+
normalizedCategories = !categoryId ? topologicalSortForCategoryTree(categories.map(normalizeCategory)) : categories.map(normalizeCategory);
|
|
1883
1821
|
|
|
1884
1822
|
_loop = function _loop() {
|
|
1885
1823
|
var _normalizedCategories, _normalizedCategories2;
|