@plasmicpkgs/commerce-swell 0.0.8 → 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.
- package/dist/commerce-swell.cjs.development.js +150 -38
- 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 +150 -38
- package/dist/commerce-swell.esm.js.map +1 -1
- package/dist/product/use-search.d.ts +3 -0
- package/dist/provider.d.ts +5 -0
- package/dist/types/site.d.ts +3 -0
- package/dist/utils/category-tree.d.ts +2 -0
- package/dist/utils/common.d.ts +1 -0
- package/package.json +4 -4
|
@@ -1531,66 +1531,170 @@ var handler$3 = {
|
|
|
1531
1531
|
}
|
|
1532
1532
|
};
|
|
1533
1533
|
|
|
1534
|
+
function ensure(x, msg) {
|
|
1535
|
+
if (msg === void 0) {
|
|
1536
|
+
msg = "";
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
if (x === null || x === undefined) {
|
|
1540
|
+
debugger;
|
|
1541
|
+
throw new Error("Value must not be undefined or null" + (msg ? "- " + msg : ""));
|
|
1542
|
+
} else {
|
|
1543
|
+
return x;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
var walkCategoryTree = function walkCategoryTree(category, categories) {
|
|
1548
|
+
if (!category || !categories) {
|
|
1549
|
+
return [];
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
var queue = [category];
|
|
1553
|
+
var result = [];
|
|
1554
|
+
|
|
1555
|
+
while (queue.length > 0) {
|
|
1556
|
+
var _curr$children$map, _curr$children;
|
|
1557
|
+
|
|
1558
|
+
var curr = ensure(queue.shift());
|
|
1559
|
+
result.push(curr);
|
|
1560
|
+
queue.push.apply(queue, (_curr$children$map = (_curr$children = curr.children) == null ? void 0 : _curr$children.map(function (child) {
|
|
1561
|
+
return ensure(categories.find(function (category) {
|
|
1562
|
+
return category.id === child.id;
|
|
1563
|
+
}));
|
|
1564
|
+
})) != null ? _curr$children$map : []);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
return result;
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1534
1570
|
var handler$4 = {
|
|
1535
1571
|
fetchOptions: {
|
|
1536
1572
|
query: 'products',
|
|
1537
1573
|
method: 'list'
|
|
1538
1574
|
},
|
|
1539
1575
|
fetcher: function fetcher(_ref) {
|
|
1540
|
-
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1541
|
-
var input, fetch, sortMap, categoryId, brandId, search, _input$sort, sort, count, mappedSort,
|
|
1576
|
+
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
1577
|
+
var input, options, fetch, sortMap, categoryId, includeSubCategories, categories, brandId, search, _input$sort, sort, count, mappedSort, products, _fetch, includedCategories;
|
|
1542
1578
|
|
|
1543
|
-
return runtime_1.wrap(function
|
|
1579
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1544
1580
|
while (1) {
|
|
1545
|
-
switch (
|
|
1581
|
+
switch (_context3.prev = _context3.next) {
|
|
1546
1582
|
case 0:
|
|
1547
|
-
input = _ref.input, fetch = _ref.fetch;
|
|
1583
|
+
input = _ref.input, options = _ref.options, fetch = _ref.fetch;
|
|
1548
1584
|
sortMap = new Map([['latest-desc', ''], ['price-asc', 'price_asc'], ['price-desc', 'price_desc'], ['trending-desc', 'popularity']]);
|
|
1549
|
-
categoryId = input.categoryId, brandId = input.brandId, search = input.search, _input$sort = input.sort, sort = _input$sort === void 0 ? 'latest-desc' : _input$sort, count = input.count;
|
|
1585
|
+
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;
|
|
1550
1586
|
mappedSort = sortMap.get(sort);
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1587
|
+
products = [];
|
|
1588
|
+
|
|
1589
|
+
_fetch = /*#__PURE__*/function () {
|
|
1590
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(categoryId) {
|
|
1591
|
+
var _yield$fetch, results;
|
|
1592
|
+
|
|
1593
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1594
|
+
while (1) {
|
|
1595
|
+
switch (_context.prev = _context.next) {
|
|
1596
|
+
case 0:
|
|
1597
|
+
_context.next = 2;
|
|
1598
|
+
return fetch({
|
|
1599
|
+
query: options.query,
|
|
1600
|
+
method: options.method,
|
|
1601
|
+
variables: {
|
|
1602
|
+
category: categoryId,
|
|
1603
|
+
brand: brandId,
|
|
1604
|
+
search: search,
|
|
1605
|
+
sort: mappedSort,
|
|
1606
|
+
expand: ["variants"],
|
|
1607
|
+
limit: count
|
|
1608
|
+
}
|
|
1609
|
+
});
|
|
1610
|
+
|
|
1611
|
+
case 2:
|
|
1612
|
+
_yield$fetch = _context.sent;
|
|
1613
|
+
results = _yield$fetch.results;
|
|
1614
|
+
return _context.abrupt("return", results);
|
|
1615
|
+
|
|
1616
|
+
case 5:
|
|
1617
|
+
case "end":
|
|
1618
|
+
return _context.stop();
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
}, _callee);
|
|
1622
|
+
}));
|
|
1564
1623
|
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1624
|
+
return function _fetch(_x) {
|
|
1625
|
+
return _ref2.apply(this, arguments);
|
|
1626
|
+
};
|
|
1627
|
+
}();
|
|
1628
|
+
|
|
1629
|
+
if (includeSubCategories) {
|
|
1630
|
+
_context3.next = 12;
|
|
1631
|
+
break;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
_context3.next = 9;
|
|
1635
|
+
return _fetch(categoryId);
|
|
1636
|
+
|
|
1637
|
+
case 9:
|
|
1638
|
+
products = _context3.sent;
|
|
1639
|
+
_context3.next = 16;
|
|
1640
|
+
break;
|
|
1641
|
+
|
|
1642
|
+
case 12:
|
|
1643
|
+
includedCategories = walkCategoryTree(categories == null ? void 0 : categories.find(function (category) {
|
|
1644
|
+
return category.id === categoryId;
|
|
1645
|
+
}), categories);
|
|
1646
|
+
_context3.next = 15;
|
|
1647
|
+
return Promise.all(includedCategories.flatMap( /*#__PURE__*/function () {
|
|
1648
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(category) {
|
|
1649
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1650
|
+
while (1) {
|
|
1651
|
+
switch (_context2.prev = _context2.next) {
|
|
1652
|
+
case 0:
|
|
1653
|
+
return _context2.abrupt("return", _fetch(category.id));
|
|
1654
|
+
|
|
1655
|
+
case 1:
|
|
1656
|
+
case "end":
|
|
1657
|
+
return _context2.stop();
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
}, _callee2);
|
|
1661
|
+
}));
|
|
1662
|
+
|
|
1663
|
+
return function (_x2) {
|
|
1664
|
+
return _ref3.apply(this, arguments);
|
|
1665
|
+
};
|
|
1666
|
+
}()));
|
|
1667
|
+
|
|
1668
|
+
case 15:
|
|
1669
|
+
products = _context3.sent.flatMap(function (products) {
|
|
1670
|
+
return products;
|
|
1671
|
+
}).slice(0, count);
|
|
1672
|
+
|
|
1673
|
+
case 16:
|
|
1674
|
+
return _context3.abrupt("return", {
|
|
1675
|
+
products: products.map(function (product) {
|
|
1676
|
+
return normalizeProduct(product);
|
|
1677
|
+
}),
|
|
1678
|
+
found: products.length > 0
|
|
1575
1679
|
});
|
|
1576
1680
|
|
|
1577
|
-
case
|
|
1681
|
+
case 17:
|
|
1578
1682
|
case "end":
|
|
1579
|
-
return
|
|
1683
|
+
return _context3.stop();
|
|
1580
1684
|
}
|
|
1581
1685
|
}
|
|
1582
|
-
},
|
|
1686
|
+
}, _callee3);
|
|
1583
1687
|
}))();
|
|
1584
1688
|
},
|
|
1585
|
-
useHook: function useHook(
|
|
1586
|
-
var useData =
|
|
1689
|
+
useHook: function useHook(_ref4) {
|
|
1690
|
+
var useData = _ref4.useData;
|
|
1587
1691
|
return function (input) {
|
|
1588
1692
|
if (input === void 0) {
|
|
1589
1693
|
input = {};
|
|
1590
1694
|
}
|
|
1591
1695
|
|
|
1592
1696
|
return useData({
|
|
1593
|
-
input: [['search', input.search], ['categoryId', input.categoryId], ['brandId', input.brandId], ['sort', input.sort], ['count', input.count]],
|
|
1697
|
+
input: [['search', input.search], ['categoryId', input.categoryId], ['includeSubCategories', input.includeSubCategories], ['categories', input.categories], ['brandId', input.brandId], ['sort', input.sort], ['count', input.count]],
|
|
1594
1698
|
swrOptions: _extends({
|
|
1595
1699
|
revalidateOnFocus: false
|
|
1596
1700
|
}, input.swrOptions)
|
|
@@ -1676,7 +1780,10 @@ var handler$6 = {
|
|
|
1676
1780
|
_context.next = 3;
|
|
1677
1781
|
return fetch({
|
|
1678
1782
|
query: 'categories',
|
|
1679
|
-
method: 'get'
|
|
1783
|
+
method: 'get',
|
|
1784
|
+
variables: {
|
|
1785
|
+
expand: ["children"]
|
|
1786
|
+
}
|
|
1680
1787
|
});
|
|
1681
1788
|
|
|
1682
1789
|
case 3:
|
|
@@ -1684,12 +1791,14 @@ var handler$6 = {
|
|
|
1684
1791
|
return _context.abrupt("return", (_data$results$map = data.results.map(function (_ref2) {
|
|
1685
1792
|
var id = _ref2.id,
|
|
1686
1793
|
name = _ref2.name,
|
|
1687
|
-
slug = _ref2.slug
|
|
1794
|
+
slug = _ref2.slug,
|
|
1795
|
+
children = _ref2.children;
|
|
1688
1796
|
return {
|
|
1689
1797
|
id: id,
|
|
1690
1798
|
name: name,
|
|
1691
1799
|
slug: slug,
|
|
1692
|
-
path: "/" + slug
|
|
1800
|
+
path: "/" + slug,
|
|
1801
|
+
children: children.results
|
|
1693
1802
|
};
|
|
1694
1803
|
})) != null ? _data$results$map : []);
|
|
1695
1804
|
|
|
@@ -1927,6 +2036,9 @@ var getSwellProvider = function getSwellProvider(storeId, publicKey) {
|
|
|
1927
2036
|
site: {
|
|
1928
2037
|
useCategories: handler$6,
|
|
1929
2038
|
useBrands: handler$7
|
|
2039
|
+
},
|
|
2040
|
+
extraFeatures: {
|
|
2041
|
+
includeSubCategories: true
|
|
1930
2042
|
}
|
|
1931
2043
|
};
|
|
1932
2044
|
};
|