@sentecacommerce-theme/lib 0.12.102 → 0.13.3

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.
Files changed (51) hide show
  1. package/dist/cjs/basket/api/mutations/index.js +14 -0
  2. package/dist/cjs/basket/api/mutations/useChangeGiftVariant.js +116 -0
  3. package/dist/cjs/basket/hooks/index.js +12 -0
  4. package/dist/cjs/basket/hooks/useChangeGiftVariant.js +16 -0
  5. package/dist/cjs/hooks/useLineItem/LineItemContext.js +86 -0
  6. package/dist/cjs/hooks/useLineItem/index.js +34 -12
  7. package/dist/cjs/hooks/useProduct/index.js +17 -276
  8. package/dist/cjs/hooks/useProduct/utils/index.js +44 -18
  9. package/dist/cjs/hooks/useProductVariants/index.js +334 -0
  10. package/dist/cjs/hooks/useProductVariants/types.js +3 -0
  11. package/dist/cjs/index.js +16 -4
  12. package/dist/cjs/listing/api/queries/useListingQuery.js +1 -0
  13. package/dist/cjs/listing/hooks/useListingBreadcrumbs.js +20 -8
  14. package/dist/cjs/listing/hooks/useListingCategories.js +2 -2
  15. package/dist/cjs/listing/hooks/useListingMeta.js +12 -10
  16. package/dist/cjs/listing/utils/buildCategoryQuery.js +22 -1
  17. package/dist/cjs/seo/components/TranslationsMeta/index.js +1 -0
  18. package/dist/cjs/utils/localStorage.js +7 -2
  19. package/dist/esm/basket/api/mutations/index.js +1 -0
  20. package/dist/esm/basket/api/mutations/useChangeGiftVariant.js +106 -0
  21. package/dist/esm/basket/hooks/index.js +1 -0
  22. package/dist/esm/basket/hooks/useChangeGiftVariant.js +3 -0
  23. package/dist/esm/hooks/useLineItem/LineItemContext.js +75 -0
  24. package/dist/esm/hooks/useLineItem/index.js +16 -12
  25. package/dist/esm/hooks/useProduct/index.js +18 -277
  26. package/dist/esm/hooks/useProduct/utils/index.js +44 -18
  27. package/dist/esm/hooks/useProductVariants/index.js +293 -0
  28. package/dist/esm/hooks/useProductVariants/types.js +1 -0
  29. package/dist/esm/index.js +1 -0
  30. package/dist/esm/listing/api/queries/useListingQuery.js +1 -0
  31. package/dist/esm/listing/hooks/useListingBreadcrumbs.js +15 -3
  32. package/dist/esm/listing/hooks/useListingCategories.js +2 -2
  33. package/dist/esm/listing/hooks/useListingMeta.js +12 -12
  34. package/dist/esm/listing/utils/buildCategoryQuery.js +22 -1
  35. package/dist/esm/seo/components/TranslationsMeta/index.js +1 -0
  36. package/dist/esm/utils/localStorage.js +7 -2
  37. package/dist/types/basket/api/mutations/index.d.ts +1 -0
  38. package/dist/types/basket/api/mutations/useChangeGiftVariant.d.ts +2 -0
  39. package/dist/types/basket/hooks/index.d.ts +1 -0
  40. package/dist/types/basket/hooks/useChangeGiftVariant.d.ts +2 -0
  41. package/dist/types/hooks/basket-hooks/useBasketLineItem/index.d.ts +1 -2
  42. package/dist/types/hooks/useLineItem/LineItemContext.d.ts +22 -0
  43. package/dist/types/hooks/useLineItem/index.d.ts +2 -2
  44. package/dist/types/hooks/useProduct/index.d.ts +2 -76
  45. package/dist/types/hooks/useProduct/utils/index.d.ts +6 -4
  46. package/dist/types/hooks/useProductVariants/index.d.ts +34 -0
  47. package/dist/types/hooks/useProductVariants/types.d.ts +79 -0
  48. package/dist/types/index.d.ts +1 -0
  49. package/dist/types/listing/hooks/useListingMeta.d.ts +4 -0
  50. package/dist/types/listing/types.d.ts +1 -0
  51. package/package.json +5 -5
@@ -1,9 +1,11 @@
1
1
  Object.defineProperty(exports, "__esModule", {
2
2
  value: true
3
3
  });
4
+ var _exportNames = {};
4
5
  var _useReplaceBasketMutation = _interopRequireWildcard(require("./useReplaceBasketMutation"));
5
6
  Object.keys(_useReplaceBasketMutation).forEach(function(key) {
6
7
  if (key === "default" || key === "__esModule") return;
8
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
7
9
  if (key in exports && exports[key] === _useReplaceBasketMutation[key]) return;
8
10
  Object.defineProperty(exports, key, {
9
11
  enumerable: true,
@@ -12,6 +14,18 @@ Object.keys(_useReplaceBasketMutation).forEach(function(key) {
12
14
  }
13
15
  });
14
16
  });
17
+ var _useChangeGiftVariant = _interopRequireWildcard(require("./useChangeGiftVariant"));
18
+ Object.keys(_useChangeGiftVariant).forEach(function(key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
21
+ if (key in exports && exports[key] === _useChangeGiftVariant[key]) return;
22
+ Object.defineProperty(exports, key, {
23
+ enumerable: true,
24
+ get: function() {
25
+ return _useChangeGiftVariant[key];
26
+ }
27
+ });
28
+ });
15
29
  function _interopRequireWildcard(obj) {
16
30
  if (obj && obj.__esModule) {
17
31
  return obj;
@@ -0,0 +1,116 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.useChangeGiftVariantMutation = void 0;
5
+ var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime"));
6
+ var _react = _interopRequireDefault(require("react"));
7
+ var _reactQuery = require("react-query");
8
+ var _sdk = require("@sentecacommerce/sdk");
9
+ var _index = require("../../index");
10
+ function _arrayLikeToArray(arr, len) {
11
+ if (len == null || len > arr.length) len = arr.length;
12
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
13
+ return arr2;
14
+ }
15
+ function _arrayWithHoles(arr) {
16
+ if (Array.isArray(arr)) return arr;
17
+ }
18
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
19
+ try {
20
+ var info = gen[key](arg);
21
+ var value = info.value;
22
+ } catch (error) {
23
+ reject(error);
24
+ return;
25
+ }
26
+ if (info.done) {
27
+ resolve(value);
28
+ } else {
29
+ Promise.resolve(value).then(_next, _throw);
30
+ }
31
+ }
32
+ function _asyncToGenerator(fn) {
33
+ return function() {
34
+ var self = this, args = arguments;
35
+ return new Promise(function(resolve, reject) {
36
+ var gen = fn.apply(self, args);
37
+ function _next(value) {
38
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
39
+ }
40
+ function _throw(err) {
41
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
42
+ }
43
+ _next(undefined);
44
+ });
45
+ };
46
+ }
47
+ function _interopRequireDefault(obj) {
48
+ return obj && obj.__esModule ? obj : {
49
+ default: obj
50
+ };
51
+ }
52
+ function _iterableToArrayLimit(arr, i) {
53
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
54
+ if (_i == null) return;
55
+ var _arr = [];
56
+ var _n = true;
57
+ var _d = false;
58
+ var _s, _e;
59
+ try {
60
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
61
+ _arr.push(_s.value);
62
+ if (i && _arr.length === i) break;
63
+ }
64
+ } catch (err) {
65
+ _d = true;
66
+ _e = err;
67
+ } finally{
68
+ try {
69
+ if (!_n && _i["return"] != null) _i["return"]();
70
+ } finally{
71
+ if (_d) throw _e;
72
+ }
73
+ }
74
+ return _arr;
75
+ }
76
+ function _nonIterableRest() {
77
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
78
+ }
79
+ function _slicedToArray(arr, i) {
80
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
81
+ }
82
+ function _unsupportedIterableToArray(o, minLen) {
83
+ if (!o) return;
84
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
85
+ var n = Object.prototype.toString.call(o).slice(8, -1);
86
+ if (n === "Object" && o.constructor) n = o.constructor.name;
87
+ if (n === "Map" || n === "Set") return Array.from(n);
88
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
89
+ }
90
+ var useChangeGiftVariantMutation = function() {
91
+ var ref = _slicedToArray((0, _index).useReplaceBasket(), 1), replaceBasket = ref[0];
92
+ return (0, _reactQuery).useMutation(function() {
93
+ var _ref = _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee(props) {
94
+ return _regeneratorRuntime.default.wrap(function _callee$(_ctx) {
95
+ while(1)switch(_ctx.prev = _ctx.next){
96
+ case 0:
97
+ _ctx.next = 2;
98
+ return (0, _sdk).MyCartChangeSelectableGiftLineItemVariant(props);
99
+ case 2:
100
+ return _ctx.abrupt("return", _ctx.sent);
101
+ case 3:
102
+ case "end":
103
+ return _ctx.stop();
104
+ }
105
+ }, _callee);
106
+ }));
107
+ return function(props) {
108
+ return _ref.apply(this, arguments);
109
+ };
110
+ }(), {
111
+ onSuccess: function(data) {
112
+ return replaceBasket(data);
113
+ }
114
+ });
115
+ };
116
+ exports.useChangeGiftVariantMutation = useChangeGiftVariantMutation;
@@ -26,6 +26,18 @@ Object.keys(_useBasketCrossSaleItems).forEach(function(key) {
26
26
  }
27
27
  });
28
28
  });
29
+ var _useChangeGiftVariant = _interopRequireWildcard(require("./useChangeGiftVariant"));
30
+ Object.keys(_useChangeGiftVariant).forEach(function(key) {
31
+ if (key === "default" || key === "__esModule") return;
32
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
33
+ if (key in exports && exports[key] === _useChangeGiftVariant[key]) return;
34
+ Object.defineProperty(exports, key, {
35
+ enumerable: true,
36
+ get: function() {
37
+ return _useChangeGiftVariant[key];
38
+ }
39
+ });
40
+ });
29
41
  function _interopRequireWildcard(obj) {
30
42
  if (obj && obj.__esModule) {
31
43
  return obj;
@@ -0,0 +1,16 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ Object.defineProperty(exports, "useChangeGiftVariant", {
5
+ enumerable: true,
6
+ get: function() {
7
+ return _mutations.useChangeGiftVariantMutation;
8
+ }
9
+ });
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _mutations = require("../api/mutations");
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
@@ -0,0 +1,86 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.LineItemStateProvider = LineItemStateProvider;
5
+ exports.useLineItemState = useLineItemState;
6
+ exports.useLineItemFunctions = useLineItemFunctions;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _useProductVariants = require("../useProductVariants");
9
+ var _ = require("../..");
10
+ function _defineProperty(obj, key, value) {
11
+ if (key in obj) {
12
+ Object.defineProperty(obj, key, {
13
+ value: value,
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true
17
+ });
18
+ } else {
19
+ obj[key] = value;
20
+ }
21
+ return obj;
22
+ }
23
+ function _interopRequireDefault(obj) {
24
+ return obj && obj.__esModule ? obj : {
25
+ default: obj
26
+ };
27
+ }
28
+ function _objectSpread(target) {
29
+ for(var i = 1; i < arguments.length; i++){
30
+ var source = arguments[i] != null ? arguments[i] : {};
31
+ var ownKeys = Object.keys(source);
32
+ if (typeof Object.getOwnPropertySymbols === "function") {
33
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
34
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
35
+ }));
36
+ }
37
+ ownKeys.forEach(function(key) {
38
+ _defineProperty(target, key, source[key]);
39
+ });
40
+ }
41
+ return target;
42
+ }
43
+ var LineItemStateContext = /*#__PURE__*/ _react.default.createContext(undefined);
44
+ var CountDispatchContext = /*#__PURE__*/ _react.default.createContext(undefined);
45
+ function LineItemStateProvider(param) {
46
+ var product = param.product, children = param.children;
47
+ var ref = (0, _useProductVariants).useProductVariants({
48
+ product: product,
49
+ defaultVariantId: product.variantId,
50
+ isLineItem: true
51
+ }), variants = ref.variants, selectedVariant = ref.selectedVariant, getVariantById = ref.getVariantById, getVariantByAttribute = ref.getVariantByAttribute, getVariantByCombination = ref.getVariantByCombination, selectVariantById = ref.selectVariantById, selectVariantByAttribute = ref.selectVariantByAttribute, selectVariantByCombination = ref.selectVariantByCombination;
52
+ var state = {
53
+ variants: variants,
54
+ selectedVariant: _objectSpread({}, selectedVariant, {
55
+ name: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name),
56
+ slug: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.slug)
57
+ })
58
+ };
59
+ var functions = {
60
+ getVariantById: getVariantById,
61
+ getVariantByAttribute: getVariantByAttribute,
62
+ getVariantByCombination: getVariantByCombination,
63
+ selectVariantById: selectVariantById,
64
+ selectVariantByAttribute: selectVariantByAttribute,
65
+ selectVariantByCombination: selectVariantByCombination
66
+ };
67
+ return(/*#__PURE__*/ _react.default.createElement(LineItemStateContext.Provider, {
68
+ value: state
69
+ }, /*#__PURE__*/ _react.default.createElement(CountDispatchContext.Provider, {
70
+ value: functions
71
+ }, children)));
72
+ }
73
+ function useLineItemState() {
74
+ var context = _react.default.useContext(LineItemStateContext);
75
+ if (context === undefined) {
76
+ throw new Error('useLineItemState must be used within a LineItemStateProvider');
77
+ }
78
+ return context;
79
+ }
80
+ function useLineItemFunctions() {
81
+ var context = _react.default.useContext(CountDispatchContext);
82
+ if (context === undefined) {
83
+ throw new Error('useLineItemFunctions must be used within a LineItemStateProvider');
84
+ }
85
+ return context;
86
+ }
@@ -1,10 +1,29 @@
1
1
  Object.defineProperty(exports, "__esModule", {
2
2
  value: true
3
3
  });
4
+ Object.defineProperty(exports, "useLineItemFunctions", {
5
+ enumerable: true,
6
+ get: function() {
7
+ return _lineItemContext.useLineItemFunctions;
8
+ }
9
+ });
10
+ Object.defineProperty(exports, "useLineItemState", {
11
+ enumerable: true,
12
+ get: function() {
13
+ return _lineItemContext.useLineItemState;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "LineItemStateProvider", {
17
+ enumerable: true,
18
+ get: function() {
19
+ return _lineItemContext.LineItemStateProvider;
20
+ }
21
+ });
4
22
  exports.useLineItem = void 0;
5
23
  var _react = _interopRequireDefault(require("react"));
6
24
  var _utils = require("../../utils");
7
25
  var _usePrefetchProduct = require("../usePrefetchProduct");
26
+ var _lineItemContext = require("./LineItemContext");
8
27
  function _defineProperty(obj, key, value) {
9
28
  if (key in obj) {
10
29
  Object.defineProperty(obj, key, {
@@ -39,10 +58,10 @@ function _objectSpread(target) {
39
58
  return target;
40
59
  }
41
60
  var useLineItem = function(props) {
42
- var ref16 = (0, _usePrefetchProduct).usePrefetchProduct((0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : props.slug)), onMouseEnter = ref16.onMouseEnter, onMouseLeave = ref16.onMouseLeave, onMouseDown = ref16.onMouseDown;
61
+ var ref17 = (0, _usePrefetchProduct).usePrefetchProduct((0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : props.slug)), onMouseEnter = ref17.onMouseEnter, onMouseLeave = ref17.onMouseLeave, onMouseDown = ref17.onMouseDown;
43
62
  var data = _react.default.useMemo(function() {
44
- var ref17, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12;
45
- var mappedAttributes = (ref17 = Object.keys(props === null || props === void 0 ? void 0 : props.attributes)) === null || ref17 === void 0 ? void 0 : ref17.reduce(function(map, key) {
63
+ var ref18, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13;
64
+ var mappedAttributes = (ref18 = Object.keys(props === null || props === void 0 ? void 0 : props.attributes)) === null || ref18 === void 0 ? void 0 : ref18.reduce(function(map, key) {
46
65
  var current = props === null || props === void 0 ? void 0 : props.attributes[key];
47
66
  var ref;
48
67
  map[key] = {
@@ -63,7 +82,7 @@ var useLineItem = function(props) {
63
82
  }
64
83
  return map;
65
84
  }, {});
66
- var ref13, ref14, ref15;
85
+ var ref14, ref15, ref16;
67
86
  return {
68
87
  _id: props === null || props === void 0 ? void 0 : props._id,
69
88
  name: (0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : props.name),
@@ -71,18 +90,21 @@ var useLineItem = function(props) {
71
90
  name: (0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : (ref2 = props.brands) === null || ref2 === void 0 ? void 0 : (ref3 = ref2[0]) === null || ref3 === void 0 ? void 0 : ref3.name),
72
91
  slug: (0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : (ref4 = props.brands) === null || ref4 === void 0 ? void 0 : (ref5 = ref4[0]) === null || ref5 === void 0 ? void 0 : ref5.slug)
73
92
  },
93
+ attributes: props === null || props === void 0 ? void 0 : props.attributes,
94
+ variantAttributes: (ref6 = props) === null || ref6 === void 0 ? void 0 : ref6.variantAttributes,
95
+ variants: props === null || props === void 0 ? void 0 : props.variants,
74
96
  slug: (0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : props.slug),
75
97
  collapseKey: props === null || props === void 0 ? void 0 : props.collapseKey,
76
98
  variantId: props === null || props === void 0 ? void 0 : props.variantId,
77
- offerId: props === null || props === void 0 ? void 0 : (ref6 = props.offer) === null || ref6 === void 0 ? void 0 : ref6._id,
99
+ offerId: props === null || props === void 0 ? void 0 : (ref7 = props.offer) === null || ref7 === void 0 ? void 0 : ref7._id,
78
100
  offer: props === null || props === void 0 ? void 0 : props.offer,
79
101
  sku: props === null || props === void 0 ? void 0 : props.sku,
80
102
  images: (props === null || props === void 0 ? void 0 : props.images) || {},
81
103
  ratings: props === null || props === void 0 ? void 0 : props.reviewRatingStatistics,
82
- price: props === null || props === void 0 ? void 0 : (ref7 = props.offer) === null || ref7 === void 0 ? void 0 : ref7.originalPrice,
83
- discountedPrice: props === null || props === void 0 ? void 0 : (ref8 = props.offer) === null || ref8 === void 0 ? void 0 : ref8.discountedPrice,
84
- variantOptions: (ref13 = props === null || props === void 0 ? void 0 : props.variantOptions) !== null && ref13 !== void 0 ? ref13 : 0,
85
- variantsCount: (ref14 = props === null || props === void 0 ? void 0 : props.variantsCount) !== null && ref14 !== void 0 ? ref14 : 0,
104
+ price: props === null || props === void 0 ? void 0 : (ref8 = props.offer) === null || ref8 === void 0 ? void 0 : ref8.originalPrice,
105
+ discountedPrice: props === null || props === void 0 ? void 0 : (ref9 = props.offer) === null || ref9 === void 0 ? void 0 : ref9.discountedPrice,
106
+ variantOptions: (ref14 = props === null || props === void 0 ? void 0 : props.variantOptions) !== null && ref14 !== void 0 ? ref14 : 0,
107
+ variantsCount: (ref15 = props === null || props === void 0 ? void 0 : props.variantsCount) !== null && ref15 !== void 0 ? ref15 : 0,
86
108
  categories: props === null || props === void 0 ? void 0 : props.categories.map(function(category) {
87
109
  return {
88
110
  name: (0, _utils).getTranslatableField(category.name),
@@ -90,9 +112,9 @@ var useLineItem = function(props) {
90
112
  };
91
113
  }),
92
114
  inventory: {
93
- hasAvailableQuantity: (props === null || props === void 0 ? void 0 : (ref9 = props.inventorySnapshot) === null || ref9 === void 0 ? void 0 : ref9.canOrder) ? true : false,
94
- availableQuantity: (props === null || props === void 0 ? void 0 : (ref10 = props.inventorySnapshot) === null || ref10 === void 0 ? void 0 : ref10.canOrder) ? (ref15 = props === null || props === void 0 ? void 0 : (ref11 = props.inventorySnapshot) === null || ref11 === void 0 ? void 0 : ref11.availableQuantity) !== null && ref15 !== void 0 ? ref15 : 0 : 0,
95
- maxQuantity: props === null || props === void 0 ? void 0 : (ref12 = props.offer) === null || ref12 === void 0 ? void 0 : ref12.maxQuantity
115
+ hasAvailableQuantity: (props === null || props === void 0 ? void 0 : (ref10 = props.inventorySnapshot) === null || ref10 === void 0 ? void 0 : ref10.canOrder) ? true : false,
116
+ availableQuantity: (props === null || props === void 0 ? void 0 : (ref11 = props.inventorySnapshot) === null || ref11 === void 0 ? void 0 : ref11.canOrder) ? (ref16 = props === null || props === void 0 ? void 0 : (ref12 = props.inventorySnapshot) === null || ref12 === void 0 ? void 0 : ref12.availableQuantity) !== null && ref16 !== void 0 ? ref16 : 0 : 0,
117
+ maxQuantity: props === null || props === void 0 ? void 0 : (ref13 = props.offer) === null || ref13 === void 0 ? void 0 : ref13.maxQuantity
96
118
  },
97
119
  labels: mapLabelData(props === null || props === void 0 ? void 0 : props.labels),
98
120
  getCustomFieldByKey: function(key) {