@plasmicpkgs/commerce-swell 0.0.1 → 0.0.5
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 +192 -27
- 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 +192 -27
- package/dist/commerce-swell.esm.js.map +1 -1
- package/dist/provider.d.ts +10 -0
- package/dist/registerCommerceProvider.d.ts +5 -5
- package/dist/registerable.d.ts +2 -0
- package/dist/site/use-brands.d.ts +12 -0
- package/dist/site/use-categories.d.ts +12 -0
- package/package.json +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import registerComponent from '@plasmicapp/host/registerComponent';
|
|
2
1
|
import React, { useMemo, useCallback } from 'react';
|
|
3
2
|
import { CommerceError, useCart, ValidationError, getCommerceProvider as getCommerceProvider$1, useCommerce as useCommerce$1 } from '@plasmicpkgs/commerce';
|
|
4
3
|
import swell from 'swell-js';
|
|
5
4
|
import Cookies from 'js-cookie';
|
|
6
5
|
import debounce from 'lodash.debounce';
|
|
6
|
+
import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
Forked from https://github.com/vercel/commerce/tree/main/packages/swell/src
|
|
@@ -174,9 +174,9 @@ var runtime = (function (exports) {
|
|
|
174
174
|
// This is a polyfill for %IteratorPrototype% for environments that
|
|
175
175
|
// don't natively support it.
|
|
176
176
|
var IteratorPrototype = {};
|
|
177
|
-
IteratorPrototype
|
|
177
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
178
178
|
return this;
|
|
179
|
-
};
|
|
179
|
+
});
|
|
180
180
|
|
|
181
181
|
var getProto = Object.getPrototypeOf;
|
|
182
182
|
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
@@ -190,8 +190,9 @@ var runtime = (function (exports) {
|
|
|
190
190
|
|
|
191
191
|
var Gp = GeneratorFunctionPrototype.prototype =
|
|
192
192
|
Generator.prototype = Object.create(IteratorPrototype);
|
|
193
|
-
GeneratorFunction.prototype =
|
|
194
|
-
|
|
193
|
+
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
194
|
+
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
195
|
+
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
195
196
|
GeneratorFunction.displayName = define(
|
|
196
197
|
GeneratorFunctionPrototype,
|
|
197
198
|
toStringTagSymbol,
|
|
@@ -305,9 +306,9 @@ var runtime = (function (exports) {
|
|
|
305
306
|
}
|
|
306
307
|
|
|
307
308
|
defineIteratorMethods(AsyncIterator.prototype);
|
|
308
|
-
AsyncIterator.prototype
|
|
309
|
+
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
309
310
|
return this;
|
|
310
|
-
};
|
|
311
|
+
});
|
|
311
312
|
exports.AsyncIterator = AsyncIterator;
|
|
312
313
|
|
|
313
314
|
// Note that simple async functions are implemented on top of
|
|
@@ -500,13 +501,13 @@ var runtime = (function (exports) {
|
|
|
500
501
|
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
501
502
|
// object to not be returned from this call. This ensures that doesn't happen.
|
|
502
503
|
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
503
|
-
Gp
|
|
504
|
+
define(Gp, iteratorSymbol, function() {
|
|
504
505
|
return this;
|
|
505
|
-
};
|
|
506
|
+
});
|
|
506
507
|
|
|
507
|
-
Gp
|
|
508
|
+
define(Gp, "toString", function() {
|
|
508
509
|
return "[object Generator]";
|
|
509
|
-
};
|
|
510
|
+
});
|
|
510
511
|
|
|
511
512
|
function pushTryEntry(locs) {
|
|
512
513
|
var entry = { tryLoc: locs[0] };
|
|
@@ -825,17 +826,24 @@ try {
|
|
|
825
826
|
} catch (accidentalStrictMode) {
|
|
826
827
|
// This module should not be running in strict mode, so the above
|
|
827
828
|
// assignment should always work unless something is misconfigured. Just
|
|
828
|
-
// in case runtime.js accidentally runs in strict mode,
|
|
829
|
+
// in case runtime.js accidentally runs in strict mode, in modern engines
|
|
830
|
+
// we can explicitly access globalThis. In older engines we can escape
|
|
829
831
|
// strict mode using a global Function call. This could conceivably fail
|
|
830
832
|
// if a Content Security Policy forbids using Function, but in that case
|
|
831
833
|
// the proper solution is to fix the accidental strict mode problem. If
|
|
832
834
|
// you've misconfigured your bundler to force strict mode and applied a
|
|
833
835
|
// CSP to forbid Function, and you're not willing to fix either of those
|
|
834
836
|
// problems, please detail your unique predicament in a GitHub issue.
|
|
835
|
-
|
|
837
|
+
if (typeof globalThis === "object") {
|
|
838
|
+
globalThis.regeneratorRuntime = runtime;
|
|
839
|
+
} else {
|
|
840
|
+
Function("r", "regeneratorRuntime = r")(runtime);
|
|
841
|
+
}
|
|
836
842
|
}
|
|
837
843
|
});
|
|
838
844
|
|
|
845
|
+
var _excluded = ["file"];
|
|
846
|
+
|
|
839
847
|
var normalizeProductOption = function normalizeProductOption(_ref2) {
|
|
840
848
|
var id = _ref2.id,
|
|
841
849
|
_ref2$name = _ref2.name,
|
|
@@ -872,7 +880,7 @@ var normalizeProductImages = function normalizeProductImages(images) {
|
|
|
872
880
|
|
|
873
881
|
return images == null ? void 0 : images.map(function (_ref3) {
|
|
874
882
|
var file = _ref3.file,
|
|
875
|
-
rest = _objectWithoutPropertiesLoose(_ref3,
|
|
883
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
876
884
|
|
|
877
885
|
return _extends({
|
|
878
886
|
url: (file == null ? void 0 : file.url) + '',
|
|
@@ -1523,7 +1531,7 @@ var handler$4 = {
|
|
|
1523
1531
|
},
|
|
1524
1532
|
fetcher: function fetcher(_ref) {
|
|
1525
1533
|
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
1526
|
-
var input, fetch, sortMap, categoryId, search, _input$sort, sort, count, mappedSort, _yield$fetch, results, found, products;
|
|
1534
|
+
var input, fetch, sortMap, categoryId, brandId, search, _input$sort, sort, count, mappedSort, _yield$fetch, results, found, products;
|
|
1527
1535
|
|
|
1528
1536
|
return runtime_1.wrap(function _callee$(_context) {
|
|
1529
1537
|
while (1) {
|
|
@@ -1531,7 +1539,7 @@ var handler$4 = {
|
|
|
1531
1539
|
case 0:
|
|
1532
1540
|
input = _ref.input, fetch = _ref.fetch;
|
|
1533
1541
|
sortMap = new Map([['latest-desc', ''], ['price-asc', 'price_asc'], ['price-desc', 'price_desc'], ['trending-desc', 'popularity']]);
|
|
1534
|
-
categoryId = input.categoryId, search = input.search, _input$sort = input.sort, sort = _input$sort === void 0 ? 'latest-desc' : _input$sort, count = input.count;
|
|
1542
|
+
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;
|
|
1535
1543
|
mappedSort = sortMap.get(sort);
|
|
1536
1544
|
_context.next = 6;
|
|
1537
1545
|
return fetch({
|
|
@@ -1539,6 +1547,7 @@ var handler$4 = {
|
|
|
1539
1547
|
method: 'list',
|
|
1540
1548
|
variables: {
|
|
1541
1549
|
category: categoryId,
|
|
1550
|
+
brand: brandId,
|
|
1542
1551
|
search: search,
|
|
1543
1552
|
sort: mappedSort,
|
|
1544
1553
|
expand: ["variants"],
|
|
@@ -1583,6 +1592,168 @@ var handler$4 = {
|
|
|
1583
1592
|
}
|
|
1584
1593
|
};
|
|
1585
1594
|
|
|
1595
|
+
var handler$5 = {
|
|
1596
|
+
fetchOptions: {
|
|
1597
|
+
query: 'categories',
|
|
1598
|
+
method: 'get'
|
|
1599
|
+
},
|
|
1600
|
+
fetcher: function fetcher(_ref) {
|
|
1601
|
+
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
1602
|
+
var _data$results$map;
|
|
1603
|
+
|
|
1604
|
+
var fetch, data;
|
|
1605
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1606
|
+
while (1) {
|
|
1607
|
+
switch (_context.prev = _context.next) {
|
|
1608
|
+
case 0:
|
|
1609
|
+
fetch = _ref.fetch;
|
|
1610
|
+
_context.next = 3;
|
|
1611
|
+
return fetch({
|
|
1612
|
+
query: 'categories',
|
|
1613
|
+
method: 'get'
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
case 3:
|
|
1617
|
+
data = _context.sent;
|
|
1618
|
+
return _context.abrupt("return", (_data$results$map = data.results.map(function (_ref2) {
|
|
1619
|
+
var id = _ref2.id,
|
|
1620
|
+
name = _ref2.name,
|
|
1621
|
+
slug = _ref2.slug;
|
|
1622
|
+
return {
|
|
1623
|
+
id: id,
|
|
1624
|
+
name: name,
|
|
1625
|
+
slug: slug,
|
|
1626
|
+
path: "/" + slug
|
|
1627
|
+
};
|
|
1628
|
+
})) != null ? _data$results$map : []);
|
|
1629
|
+
|
|
1630
|
+
case 5:
|
|
1631
|
+
case "end":
|
|
1632
|
+
return _context.stop();
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
}, _callee);
|
|
1636
|
+
}))();
|
|
1637
|
+
},
|
|
1638
|
+
useHook: function useHook(_ref3) {
|
|
1639
|
+
var useData = _ref3.useData;
|
|
1640
|
+
return function (input) {
|
|
1641
|
+
var response = useData({
|
|
1642
|
+
swrOptions: _extends({
|
|
1643
|
+
revalidateOnFocus: false
|
|
1644
|
+
}, input == null ? void 0 : input.swrOptions)
|
|
1645
|
+
});
|
|
1646
|
+
return useMemo(function () {
|
|
1647
|
+
return Object.create(response, {
|
|
1648
|
+
isEmpty: {
|
|
1649
|
+
get: function get() {
|
|
1650
|
+
var _response$data$length, _response$data;
|
|
1651
|
+
|
|
1652
|
+
return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
|
|
1653
|
+
},
|
|
1654
|
+
enumerable: true
|
|
1655
|
+
}
|
|
1656
|
+
});
|
|
1657
|
+
}, [response]);
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
|
|
1662
|
+
var handler$6 = {
|
|
1663
|
+
fetchOptions: {
|
|
1664
|
+
query: 'attributes',
|
|
1665
|
+
method: 'get'
|
|
1666
|
+
},
|
|
1667
|
+
fetcher: function fetcher(_ref) {
|
|
1668
|
+
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
1669
|
+
var _yield$fetch$values, _yield$fetch;
|
|
1670
|
+
|
|
1671
|
+
var fetch, vendors;
|
|
1672
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1673
|
+
while (1) {
|
|
1674
|
+
switch (_context.prev = _context.next) {
|
|
1675
|
+
case 0:
|
|
1676
|
+
fetch = _ref.fetch;
|
|
1677
|
+
_context.next = 3;
|
|
1678
|
+
return fetch({
|
|
1679
|
+
query: 'attributes',
|
|
1680
|
+
method: 'get',
|
|
1681
|
+
variables: 'brand'
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
case 3:
|
|
1685
|
+
_context.t0 = _yield$fetch = _context.sent;
|
|
1686
|
+
|
|
1687
|
+
if (!(_context.t0 == null)) {
|
|
1688
|
+
_context.next = 8;
|
|
1689
|
+
break;
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
_context.t1 = void 0;
|
|
1693
|
+
_context.next = 9;
|
|
1694
|
+
break;
|
|
1695
|
+
|
|
1696
|
+
case 8:
|
|
1697
|
+
_context.t1 = _yield$fetch.values;
|
|
1698
|
+
|
|
1699
|
+
case 9:
|
|
1700
|
+
_context.t2 = _yield$fetch$values = _context.t1;
|
|
1701
|
+
|
|
1702
|
+
if (!(_context.t2 != null)) {
|
|
1703
|
+
_context.next = 14;
|
|
1704
|
+
break;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
_context.t3 = _yield$fetch$values;
|
|
1708
|
+
_context.next = 15;
|
|
1709
|
+
break;
|
|
1710
|
+
|
|
1711
|
+
case 14:
|
|
1712
|
+
_context.t3 = [];
|
|
1713
|
+
|
|
1714
|
+
case 15:
|
|
1715
|
+
vendors = _context.t3;
|
|
1716
|
+
console.log("dale", "useBrands", vendors);
|
|
1717
|
+
return _context.abrupt("return", Array.from(new Set(vendors).values()).map(function (v) {
|
|
1718
|
+
return {
|
|
1719
|
+
entityId: v,
|
|
1720
|
+
name: v,
|
|
1721
|
+
path: "brands/" + v
|
|
1722
|
+
};
|
|
1723
|
+
}));
|
|
1724
|
+
|
|
1725
|
+
case 18:
|
|
1726
|
+
case "end":
|
|
1727
|
+
return _context.stop();
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
}, _callee);
|
|
1731
|
+
}))();
|
|
1732
|
+
},
|
|
1733
|
+
useHook: function useHook(_ref2) {
|
|
1734
|
+
var useData = _ref2.useData;
|
|
1735
|
+
return function (input) {
|
|
1736
|
+
var response = useData({
|
|
1737
|
+
swrOptions: _extends({
|
|
1738
|
+
revalidateOnFocus: false
|
|
1739
|
+
}, input == null ? void 0 : input.swrOptions)
|
|
1740
|
+
});
|
|
1741
|
+
return useMemo(function () {
|
|
1742
|
+
return Object.create(response, {
|
|
1743
|
+
isEmpty: {
|
|
1744
|
+
get: function get() {
|
|
1745
|
+
var _response$data$length, _response$data;
|
|
1746
|
+
|
|
1747
|
+
return ((_response$data$length = (_response$data = response.data) == null ? void 0 : _response$data.length) != null ? _response$data$length : 0) <= 0;
|
|
1748
|
+
},
|
|
1749
|
+
enumerable: true
|
|
1750
|
+
}
|
|
1751
|
+
});
|
|
1752
|
+
}, [response]);
|
|
1753
|
+
};
|
|
1754
|
+
}
|
|
1755
|
+
};
|
|
1756
|
+
|
|
1586
1757
|
var fetcher = /*#__PURE__*/function () {
|
|
1587
1758
|
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref) {
|
|
1588
1759
|
var _ref$method, method, variables, query, callSwell, _callSwell;
|
|
@@ -1685,6 +1856,10 @@ var getSwellProvider = function getSwellProvider(storeId, publicKey) {
|
|
|
1685
1856
|
},
|
|
1686
1857
|
products: {
|
|
1687
1858
|
useSearch: handler$4
|
|
1859
|
+
},
|
|
1860
|
+
site: {
|
|
1861
|
+
useCategories: handler$5,
|
|
1862
|
+
useBrands: handler$6
|
|
1688
1863
|
}
|
|
1689
1864
|
};
|
|
1690
1865
|
};
|
|
@@ -1704,9 +1879,6 @@ var commerceProviderMeta = {
|
|
|
1704
1879
|
name: "plasmic-commerce-swell-provider",
|
|
1705
1880
|
displayName: "Swell Provider",
|
|
1706
1881
|
props: {
|
|
1707
|
-
children: {
|
|
1708
|
-
type: "slot"
|
|
1709
|
-
},
|
|
1710
1882
|
storeId: "string",
|
|
1711
1883
|
publicKey: "string"
|
|
1712
1884
|
},
|
|
@@ -1718,20 +1890,13 @@ function CommerceProviderComponent(props) {
|
|
|
1718
1890
|
var storeId = props.storeId,
|
|
1719
1891
|
publicKey = props.publicKey,
|
|
1720
1892
|
children = props.children;
|
|
1721
|
-
|
|
1722
|
-
if (!storeId) {
|
|
1723
|
-
return React.createElement("p", null, " You must set the store id ");
|
|
1724
|
-
} else if (!publicKey) {
|
|
1725
|
-
return React.createElement("p", null, " You must set the public key ");
|
|
1726
|
-
}
|
|
1727
|
-
|
|
1728
1893
|
var CommerceProvider = getCommerceProvider(storeId, publicKey);
|
|
1729
1894
|
return React.createElement(CommerceProvider, null, children);
|
|
1730
1895
|
}
|
|
1731
1896
|
|
|
1732
1897
|
function registerCommerceProvider(loader, customCommerceProviderMeta) {
|
|
1733
1898
|
var doRegisterComponent = function doRegisterComponent() {
|
|
1734
|
-
return loader ? loader.
|
|
1899
|
+
return loader ? loader.registerGlobalContext.apply(loader, arguments) : registerGlobalContext.apply(void 0, arguments);
|
|
1735
1900
|
};
|
|
1736
1901
|
|
|
1737
1902
|
doRegisterComponent(CommerceProviderComponent, customCommerceProviderMeta != null ? customCommerceProviderMeta : commerceProviderMeta);
|