@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.
- package/dist/cjs/basket/api/mutations/index.js +14 -0
- package/dist/cjs/basket/api/mutations/useChangeGiftVariant.js +116 -0
- package/dist/cjs/basket/hooks/index.js +12 -0
- package/dist/cjs/basket/hooks/useChangeGiftVariant.js +16 -0
- package/dist/cjs/hooks/useLineItem/LineItemContext.js +86 -0
- package/dist/cjs/hooks/useLineItem/index.js +34 -12
- package/dist/cjs/hooks/useProduct/index.js +17 -276
- package/dist/cjs/hooks/useProduct/utils/index.js +44 -18
- package/dist/cjs/hooks/useProductVariants/index.js +334 -0
- package/dist/cjs/hooks/useProductVariants/types.js +3 -0
- package/dist/cjs/index.js +16 -4
- package/dist/cjs/listing/api/queries/useListingQuery.js +1 -0
- package/dist/cjs/listing/hooks/useListingBreadcrumbs.js +20 -8
- package/dist/cjs/listing/hooks/useListingCategories.js +2 -2
- package/dist/cjs/listing/hooks/useListingMeta.js +12 -10
- package/dist/cjs/listing/utils/buildCategoryQuery.js +22 -1
- package/dist/cjs/seo/components/TranslationsMeta/index.js +1 -0
- package/dist/cjs/utils/localStorage.js +7 -2
- package/dist/esm/basket/api/mutations/index.js +1 -0
- package/dist/esm/basket/api/mutations/useChangeGiftVariant.js +106 -0
- package/dist/esm/basket/hooks/index.js +1 -0
- package/dist/esm/basket/hooks/useChangeGiftVariant.js +3 -0
- package/dist/esm/hooks/useLineItem/LineItemContext.js +75 -0
- package/dist/esm/hooks/useLineItem/index.js +16 -12
- package/dist/esm/hooks/useProduct/index.js +18 -277
- package/dist/esm/hooks/useProduct/utils/index.js +44 -18
- package/dist/esm/hooks/useProductVariants/index.js +293 -0
- package/dist/esm/hooks/useProductVariants/types.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/listing/api/queries/useListingQuery.js +1 -0
- package/dist/esm/listing/hooks/useListingBreadcrumbs.js +15 -3
- package/dist/esm/listing/hooks/useListingCategories.js +2 -2
- package/dist/esm/listing/hooks/useListingMeta.js +12 -12
- package/dist/esm/listing/utils/buildCategoryQuery.js +22 -1
- package/dist/esm/seo/components/TranslationsMeta/index.js +1 -0
- package/dist/esm/utils/localStorage.js +7 -2
- package/dist/types/basket/api/mutations/index.d.ts +1 -0
- package/dist/types/basket/api/mutations/useChangeGiftVariant.d.ts +2 -0
- package/dist/types/basket/hooks/index.d.ts +1 -0
- package/dist/types/basket/hooks/useChangeGiftVariant.d.ts +2 -0
- package/dist/types/hooks/basket-hooks/useBasketLineItem/index.d.ts +1 -2
- package/dist/types/hooks/useLineItem/LineItemContext.d.ts +22 -0
- package/dist/types/hooks/useLineItem/index.d.ts +2 -2
- package/dist/types/hooks/useProduct/index.d.ts +2 -76
- package/dist/types/hooks/useProduct/utils/index.d.ts +6 -4
- package/dist/types/hooks/useProductVariants/index.d.ts +34 -0
- package/dist/types/hooks/useProductVariants/types.d.ts +79 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/listing/hooks/useListingMeta.d.ts +4 -0
- package/dist/types/listing/types.d.ts +1 -0
- package/package.json +5 -5
@@ -0,0 +1,106 @@
|
|
1
|
+
import regeneratorRuntime from "regenerator-runtime";
|
2
|
+
import React from 'react';
|
3
|
+
import { useMutation } from 'react-query';
|
4
|
+
import { MyCartChangeSelectableGiftLineItemVariant } from '@sentecacommerce/sdk';
|
5
|
+
import { useReplaceBasket } from '../../index';
|
6
|
+
function _arrayLikeToArray(arr, len) {
|
7
|
+
if (len == null || len > arr.length) len = arr.length;
|
8
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
9
|
+
return arr2;
|
10
|
+
}
|
11
|
+
function _arrayWithHoles(arr) {
|
12
|
+
if (Array.isArray(arr)) return arr;
|
13
|
+
}
|
14
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
15
|
+
try {
|
16
|
+
var info = gen[key](arg);
|
17
|
+
var value = info.value;
|
18
|
+
} catch (error) {
|
19
|
+
reject(error);
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
if (info.done) {
|
23
|
+
resolve(value);
|
24
|
+
} else {
|
25
|
+
Promise.resolve(value).then(_next, _throw);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
function _asyncToGenerator(fn) {
|
29
|
+
return function() {
|
30
|
+
var self = this, args = arguments;
|
31
|
+
return new Promise(function(resolve, reject) {
|
32
|
+
var gen = fn.apply(self, args);
|
33
|
+
function _next(value) {
|
34
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
35
|
+
}
|
36
|
+
function _throw(err) {
|
37
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
38
|
+
}
|
39
|
+
_next(undefined);
|
40
|
+
});
|
41
|
+
};
|
42
|
+
}
|
43
|
+
function _iterableToArrayLimit(arr, i) {
|
44
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
45
|
+
if (_i == null) return;
|
46
|
+
var _arr = [];
|
47
|
+
var _n = true;
|
48
|
+
var _d = false;
|
49
|
+
var _s, _e;
|
50
|
+
try {
|
51
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
52
|
+
_arr.push(_s.value);
|
53
|
+
if (i && _arr.length === i) break;
|
54
|
+
}
|
55
|
+
} catch (err) {
|
56
|
+
_d = true;
|
57
|
+
_e = err;
|
58
|
+
} finally{
|
59
|
+
try {
|
60
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
61
|
+
} finally{
|
62
|
+
if (_d) throw _e;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return _arr;
|
66
|
+
}
|
67
|
+
function _nonIterableRest() {
|
68
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
69
|
+
}
|
70
|
+
function _slicedToArray(arr, i) {
|
71
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
72
|
+
}
|
73
|
+
function _unsupportedIterableToArray(o, minLen) {
|
74
|
+
if (!o) return;
|
75
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
76
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
77
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
78
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
79
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
80
|
+
}
|
81
|
+
export var useChangeGiftVariantMutation = function() {
|
82
|
+
var ref = _slicedToArray(useReplaceBasket(), 1), replaceBasket = ref[0];
|
83
|
+
return useMutation(function() {
|
84
|
+
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(props) {
|
85
|
+
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
86
|
+
while(1)switch(_ctx.prev = _ctx.next){
|
87
|
+
case 0:
|
88
|
+
_ctx.next = 2;
|
89
|
+
return MyCartChangeSelectableGiftLineItemVariant(props);
|
90
|
+
case 2:
|
91
|
+
return _ctx.abrupt("return", _ctx.sent);
|
92
|
+
case 3:
|
93
|
+
case "end":
|
94
|
+
return _ctx.stop();
|
95
|
+
}
|
96
|
+
}, _callee);
|
97
|
+
}));
|
98
|
+
return function(props) {
|
99
|
+
return _ref.apply(this, arguments);
|
100
|
+
};
|
101
|
+
}(), {
|
102
|
+
onSuccess: function(data) {
|
103
|
+
return replaceBasket(data);
|
104
|
+
}
|
105
|
+
});
|
106
|
+
};
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { useProductVariants } from '../useProductVariants';
|
3
|
+
import { getTranslatableField } from '../..';
|
4
|
+
function _defineProperty(obj, key, value) {
|
5
|
+
if (key in obj) {
|
6
|
+
Object.defineProperty(obj, key, {
|
7
|
+
value: value,
|
8
|
+
enumerable: true,
|
9
|
+
configurable: true,
|
10
|
+
writable: true
|
11
|
+
});
|
12
|
+
} else {
|
13
|
+
obj[key] = value;
|
14
|
+
}
|
15
|
+
return obj;
|
16
|
+
}
|
17
|
+
function _objectSpread(target) {
|
18
|
+
for(var i = 1; i < arguments.length; i++){
|
19
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
20
|
+
var ownKeys = Object.keys(source);
|
21
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
22
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
23
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
24
|
+
}));
|
25
|
+
}
|
26
|
+
ownKeys.forEach(function(key) {
|
27
|
+
_defineProperty(target, key, source[key]);
|
28
|
+
});
|
29
|
+
}
|
30
|
+
return target;
|
31
|
+
}
|
32
|
+
var LineItemStateContext = /*#__PURE__*/ React.createContext(undefined);
|
33
|
+
var CountDispatchContext = /*#__PURE__*/ React.createContext(undefined);
|
34
|
+
export function LineItemStateProvider(param) {
|
35
|
+
var product = param.product, children = param.children;
|
36
|
+
var ref = useProductVariants({
|
37
|
+
product: product,
|
38
|
+
defaultVariantId: product.variantId,
|
39
|
+
isLineItem: true
|
40
|
+
}), variants = ref.variants, selectedVariant = ref.selectedVariant, getVariantById = ref.getVariantById, getVariantByAttribute = ref.getVariantByAttribute, getVariantByCombination = ref.getVariantByCombination, selectVariantById = ref.selectVariantById, selectVariantByAttribute = ref.selectVariantByAttribute, selectVariantByCombination = ref.selectVariantByCombination;
|
41
|
+
var state = {
|
42
|
+
variants: variants,
|
43
|
+
selectedVariant: _objectSpread({}, selectedVariant, {
|
44
|
+
name: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name),
|
45
|
+
slug: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.slug)
|
46
|
+
})
|
47
|
+
};
|
48
|
+
var functions = {
|
49
|
+
getVariantById: getVariantById,
|
50
|
+
getVariantByAttribute: getVariantByAttribute,
|
51
|
+
getVariantByCombination: getVariantByCombination,
|
52
|
+
selectVariantById: selectVariantById,
|
53
|
+
selectVariantByAttribute: selectVariantByAttribute,
|
54
|
+
selectVariantByCombination: selectVariantByCombination
|
55
|
+
};
|
56
|
+
return(/*#__PURE__*/ React.createElement(LineItemStateContext.Provider, {
|
57
|
+
value: state
|
58
|
+
}, /*#__PURE__*/ React.createElement(CountDispatchContext.Provider, {
|
59
|
+
value: functions
|
60
|
+
}, children)));
|
61
|
+
}
|
62
|
+
export function useLineItemState() {
|
63
|
+
var context = React.useContext(LineItemStateContext);
|
64
|
+
if (context === undefined) {
|
65
|
+
throw new Error('useLineItemState must be used within a LineItemStateProvider');
|
66
|
+
}
|
67
|
+
return context;
|
68
|
+
}
|
69
|
+
export function useLineItemFunctions() {
|
70
|
+
var context = React.useContext(CountDispatchContext);
|
71
|
+
if (context === undefined) {
|
72
|
+
throw new Error('useLineItemFunctions must be used within a LineItemStateProvider');
|
73
|
+
}
|
74
|
+
return context;
|
75
|
+
}
|
@@ -29,11 +29,12 @@ function _objectSpread(target) {
|
|
29
29
|
}
|
30
30
|
return target;
|
31
31
|
}
|
32
|
+
export { useLineItemFunctions, useLineItemState, LineItemStateProvider } from './LineItemContext';
|
32
33
|
export var useLineItem = function(props) {
|
33
|
-
var
|
34
|
+
var ref17 = usePrefetchProduct(getTranslatableField(props === null || props === void 0 ? void 0 : props.slug)), onMouseEnter = ref17.onMouseEnter, onMouseLeave = ref17.onMouseLeave, onMouseDown = ref17.onMouseDown;
|
34
35
|
var data = React.useMemo(function() {
|
35
|
-
var
|
36
|
-
var mappedAttributes = (
|
36
|
+
var ref18, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13;
|
37
|
+
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) {
|
37
38
|
var current = props === null || props === void 0 ? void 0 : props.attributes[key];
|
38
39
|
var ref;
|
39
40
|
map[key] = {
|
@@ -54,7 +55,7 @@ export var useLineItem = function(props) {
|
|
54
55
|
}
|
55
56
|
return map;
|
56
57
|
}, {});
|
57
|
-
var
|
58
|
+
var ref14, ref15, ref16;
|
58
59
|
return {
|
59
60
|
_id: props === null || props === void 0 ? void 0 : props._id,
|
60
61
|
name: getTranslatableField(props === null || props === void 0 ? void 0 : props.name),
|
@@ -62,18 +63,21 @@ export var useLineItem = function(props) {
|
|
62
63
|
name: 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),
|
63
64
|
slug: 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)
|
64
65
|
},
|
66
|
+
attributes: props === null || props === void 0 ? void 0 : props.attributes,
|
67
|
+
variantAttributes: (ref6 = props) === null || ref6 === void 0 ? void 0 : ref6.variantAttributes,
|
68
|
+
variants: props === null || props === void 0 ? void 0 : props.variants,
|
65
69
|
slug: getTranslatableField(props === null || props === void 0 ? void 0 : props.slug),
|
66
70
|
collapseKey: props === null || props === void 0 ? void 0 : props.collapseKey,
|
67
71
|
variantId: props === null || props === void 0 ? void 0 : props.variantId,
|
68
|
-
offerId: props === null || props === void 0 ? void 0 : (
|
72
|
+
offerId: props === null || props === void 0 ? void 0 : (ref7 = props.offer) === null || ref7 === void 0 ? void 0 : ref7._id,
|
69
73
|
offer: props === null || props === void 0 ? void 0 : props.offer,
|
70
74
|
sku: props === null || props === void 0 ? void 0 : props.sku,
|
71
75
|
images: (props === null || props === void 0 ? void 0 : props.images) || {},
|
72
76
|
ratings: props === null || props === void 0 ? void 0 : props.reviewRatingStatistics,
|
73
|
-
price: props === null || props === void 0 ? void 0 : (
|
74
|
-
discountedPrice: props === null || props === void 0 ? void 0 : (
|
75
|
-
variantOptions: (
|
76
|
-
variantsCount: (
|
77
|
+
price: props === null || props === void 0 ? void 0 : (ref8 = props.offer) === null || ref8 === void 0 ? void 0 : ref8.originalPrice,
|
78
|
+
discountedPrice: props === null || props === void 0 ? void 0 : (ref9 = props.offer) === null || ref9 === void 0 ? void 0 : ref9.discountedPrice,
|
79
|
+
variantOptions: (ref14 = props === null || props === void 0 ? void 0 : props.variantOptions) !== null && ref14 !== void 0 ? ref14 : 0,
|
80
|
+
variantsCount: (ref15 = props === null || props === void 0 ? void 0 : props.variantsCount) !== null && ref15 !== void 0 ? ref15 : 0,
|
77
81
|
categories: props === null || props === void 0 ? void 0 : props.categories.map(function(category) {
|
78
82
|
return {
|
79
83
|
name: getTranslatableField(category.name),
|
@@ -81,9 +85,9 @@ export var useLineItem = function(props) {
|
|
81
85
|
};
|
82
86
|
}),
|
83
87
|
inventory: {
|
84
|
-
hasAvailableQuantity: (props === null || props === void 0 ? void 0 : (
|
85
|
-
availableQuantity: (props === null || props === void 0 ? void 0 : (
|
86
|
-
maxQuantity: props === null || props === void 0 ? void 0 : (
|
88
|
+
hasAvailableQuantity: (props === null || props === void 0 ? void 0 : (ref10 = props.inventorySnapshot) === null || ref10 === void 0 ? void 0 : ref10.canOrder) ? true : false,
|
89
|
+
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,
|
90
|
+
maxQuantity: props === null || props === void 0 ? void 0 : (ref13 = props.offer) === null || ref13 === void 0 ? void 0 : ref13.maxQuantity
|
87
91
|
},
|
88
92
|
labels: mapLabelData(props === null || props === void 0 ? void 0 : props.labels),
|
89
93
|
getCustomFieldByKey: function(key) {
|
@@ -1,281 +1,46 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { getTranslatableField } from '../../';
|
3
|
-
import {
|
3
|
+
import { createProductContent, getProductVideos, formatCategories, createCollapseKeyImagesMap } from './utils';
|
4
4
|
import { productsApi } from '../../api/productsApi';
|
5
5
|
import { assetsFieldsToMap } from '../../utils/assetsToMap';
|
6
|
-
|
7
|
-
if (len == null || len > arr.length) len = arr.length;
|
8
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
9
|
-
return arr2;
|
10
|
-
}
|
11
|
-
function _arrayWithHoles(arr) {
|
12
|
-
if (Array.isArray(arr)) return arr;
|
13
|
-
}
|
14
|
-
function _arrayWithoutHoles(arr) {
|
15
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
16
|
-
}
|
17
|
-
function _defineProperty(obj, key, value) {
|
18
|
-
if (key in obj) {
|
19
|
-
Object.defineProperty(obj, key, {
|
20
|
-
value: value,
|
21
|
-
enumerable: true,
|
22
|
-
configurable: true,
|
23
|
-
writable: true
|
24
|
-
});
|
25
|
-
} else {
|
26
|
-
obj[key] = value;
|
27
|
-
}
|
28
|
-
return obj;
|
29
|
-
}
|
30
|
-
function _iterableToArray(iter) {
|
31
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
32
|
-
}
|
33
|
-
function _iterableToArrayLimit(arr, i) {
|
34
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
35
|
-
if (_i == null) return;
|
36
|
-
var _arr = [];
|
37
|
-
var _n = true;
|
38
|
-
var _d = false;
|
39
|
-
var _s, _e;
|
40
|
-
try {
|
41
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
42
|
-
_arr.push(_s.value);
|
43
|
-
if (i && _arr.length === i) break;
|
44
|
-
}
|
45
|
-
} catch (err) {
|
46
|
-
_d = true;
|
47
|
-
_e = err;
|
48
|
-
} finally{
|
49
|
-
try {
|
50
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
51
|
-
} finally{
|
52
|
-
if (_d) throw _e;
|
53
|
-
}
|
54
|
-
}
|
55
|
-
return _arr;
|
56
|
-
}
|
57
|
-
function _nonIterableRest() {
|
58
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
59
|
-
}
|
60
|
-
function _nonIterableSpread() {
|
61
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
62
|
-
}
|
63
|
-
function _objectSpread(target) {
|
64
|
-
for(var i = 1; i < arguments.length; i++){
|
65
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
66
|
-
var ownKeys = Object.keys(source);
|
67
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
68
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
69
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
70
|
-
}));
|
71
|
-
}
|
72
|
-
ownKeys.forEach(function(key) {
|
73
|
-
_defineProperty(target, key, source[key]);
|
74
|
-
});
|
75
|
-
}
|
76
|
-
return target;
|
77
|
-
}
|
78
|
-
function _slicedToArray(arr, i) {
|
79
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
80
|
-
}
|
81
|
-
function _toConsumableArray(arr) {
|
82
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
83
|
-
}
|
84
|
-
function _unsupportedIterableToArray(o, minLen) {
|
85
|
-
if (!o) return;
|
86
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
87
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
88
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
89
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
90
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
91
|
-
}
|
6
|
+
import { useProductVariants } from '../useProductVariants';
|
92
7
|
var ProductStateContext = /*#__PURE__*/ React.createContext(undefined);
|
93
8
|
var CountDispatchContext = /*#__PURE__*/ React.createContext(undefined);
|
94
9
|
export function ProductProvider(param) {
|
95
10
|
var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName;
|
96
|
-
var
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
var currentVariant = arr[index];
|
101
|
-
var mappedAttributes = createMappedAttributes(currentVariant);
|
102
|
-
var mappedOptions = createMappedOptions(currentVariant === null || currentVariant === void 0 ? void 0 : currentVariant.availableOptions) || [];
|
103
|
-
var isAvailable = currentVariant === null || currentVariant === void 0 ? void 0 : (ref10 = currentVariant.inventorySnapshot) === null || ref10 === void 0 ? void 0 : ref10.canOrder;
|
104
|
-
var updatedVariant = _objectSpread({}, currentVariant, {
|
105
|
-
inventory: {
|
106
|
-
hasAvailableQuantity: (ref6 = currentVariant.inventorySnapshot) === null || ref6 === void 0 ? void 0 : ref6.canOrder,
|
107
|
-
availableQuantity: (ref7 = currentVariant.inventorySnapshot) === null || ref7 === void 0 ? void 0 : ref7.availableQuantity
|
108
|
-
},
|
109
|
-
isAvailable: isAvailable ? true : false,
|
110
|
-
quantity: isAvailable ? currentVariant === null || currentVariant === void 0 ? void 0 : (ref8 = currentVariant.inventorySnapshot) === null || ref8 === void 0 ? void 0 : ref8.availableQuantity : 0,
|
111
|
-
attributes: mappedAttributes,
|
112
|
-
options: mappedOptions,
|
113
|
-
selectedOptions: [],
|
114
|
-
labels: createLabelsMap(currentVariant.labels),
|
115
|
-
getAttribute: function(rule) {
|
116
|
-
return getSelectedAttribute(rule, mappedAttributes);
|
117
|
-
},
|
118
|
-
getAttributeByKey: function(key) {
|
119
|
-
var ref;
|
120
|
-
return (ref = mappedAttributes.find(function(a) {
|
121
|
-
return a.name === key;
|
122
|
-
})) === null || ref === void 0 ? void 0 : ref.value;
|
123
|
-
},
|
124
|
-
getAvailabilityByStore: function() {
|
125
|
-
var ref;
|
126
|
-
return processAvailabilityPerStore(currentVariant === null || currentVariant === void 0 ? void 0 : (ref = currentVariant.inventorySnapshot) === null || ref === void 0 ? void 0 : ref.availabilities);
|
127
|
-
}
|
128
|
-
});
|
129
|
-
map[currentVariant._id] = updatedVariant;
|
130
|
-
return map;
|
131
|
-
}, {});
|
132
|
-
return variantsWithInventory || {};
|
133
|
-
};
|
134
|
-
var getCombinationsAndAttributeRules = function getCombinationsAndAttributeRules() {
|
135
|
-
var mappedAttributeRules = createAttributeRulesMap(product);
|
136
|
-
var attributesWithId = Object.keys(variants || {}).map(function(key) {
|
137
|
-
return {
|
138
|
-
variantId: variants === null || variants === void 0 ? void 0 : variants[key]._id,
|
139
|
-
attributes: variants === null || variants === void 0 ? void 0 : variants[key].attributes
|
140
|
-
};
|
141
|
-
});
|
142
|
-
var combinationsMap = createCombinationsMap(Object.keys(mappedAttributeRules), attributesWithId);
|
143
|
-
assignCombinationsToAttributeRules(mappedAttributeRules, combinationsMap);
|
144
|
-
return {
|
145
|
-
combinations: combinationsMap,
|
146
|
-
attributeRules: mappedAttributeRules
|
147
|
-
};
|
148
|
-
};
|
149
|
-
var getDefaultVariant = function getDefaultVariant() {
|
150
|
-
if (!defaultVariantId) return null;
|
151
|
-
return variants[defaultVariantId];
|
152
|
-
};
|
153
|
-
var selectVariantById = function selectVariantById(id) {
|
154
|
-
setSelectedVariant(variants[id]);
|
155
|
-
};
|
156
|
-
var selectVariantByAttribute = function selectVariantByAttribute(key) {
|
157
|
-
var ref;
|
158
|
-
// Get by collapseKey for SD
|
159
|
-
var split = key.split(':');
|
160
|
-
if (split[0] === 'collapseKey') {
|
161
|
-
var id = Object.keys(variants).find(function(el) {
|
162
|
-
return variants[el].collapseKey === split[1];
|
163
|
-
});
|
164
|
-
return setSelectedVariant(variants[id]);
|
165
|
-
}
|
166
|
-
var id1 = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
|
167
|
-
setSelectedVariant(variants[id1]);
|
168
|
-
};
|
169
|
-
var selectVariantByCombination = function selectVariantByCombination(key, value) {
|
170
|
-
// Take collapseKey for SD
|
171
|
-
var split = value.split(':');
|
172
|
-
if (split[0] === 'collapseKey') {
|
173
|
-
var id = Object.keys(variants).find(function(el) {
|
174
|
-
var ref;
|
175
|
-
return variants[el].collapseKey === split[1] && ((ref = variants[el].attributes.find(function(attr) {
|
176
|
-
return attr.name === 'size';
|
177
|
-
})) === null || ref === void 0 ? void 0 : ref.value) === key;
|
178
|
-
});
|
179
|
-
return setSelectedVariant(variants[id]);
|
180
|
-
}
|
181
|
-
var id2 = combinations[key].params[value];
|
182
|
-
setSelectedVariant(variants[id2]);
|
183
|
-
};
|
184
|
-
var selectVariantOptions = function selectVariantOptions(definitionKey, optionKey) {
|
185
|
-
if (selectedVariant) {
|
186
|
-
var newSelectedVariant = _objectSpread({}, selectedVariant);
|
187
|
-
newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(function(opt) {
|
188
|
-
return opt.definitionKey !== definitionKey;
|
189
|
-
});
|
190
|
-
newSelectedVariant.selectedOptions = _toConsumableArray(newSelectedVariant.selectedOptions).concat([
|
191
|
-
{
|
192
|
-
definitionKey: definitionKey,
|
193
|
-
optionKey: optionKey
|
194
|
-
},
|
195
|
-
]);
|
196
|
-
newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(function(option) {
|
197
|
-
return createSelectedOption2(newSelectedVariant.options, option);
|
198
|
-
});
|
199
|
-
setSelectedVariant(newSelectedVariant);
|
200
|
-
}
|
201
|
-
};
|
202
|
-
var getSelectedAttribute = function getSelectedAttribute(rule, attributes) {
|
203
|
-
var ref;
|
204
|
-
var attributeRule = (ref = attributeRules[rule]) === null || ref === void 0 ? void 0 : ref.values;
|
205
|
-
var result;
|
206
|
-
attributes.forEach(function(currentKey) {
|
207
|
-
var found = attributeRule === null || attributeRule === void 0 ? void 0 : attributeRule[currentKey.value];
|
208
|
-
if (found) result = _objectSpread({
|
209
|
-
id: currentKey.value,
|
210
|
-
name: rule
|
211
|
-
}, found);
|
212
|
-
});
|
213
|
-
return result;
|
214
|
-
};
|
215
|
-
var getVariantById = function getVariantById(id) {
|
216
|
-
return variants === null || variants === void 0 ? void 0 : variants[id];
|
217
|
-
};
|
218
|
-
var getVariantByAttribute = function getVariantByAttribute(key) {
|
219
|
-
var ref;
|
220
|
-
var id = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
|
221
|
-
return variants === null || variants === void 0 ? void 0 : variants[id];
|
222
|
-
};
|
223
|
-
var getVariantByCombination = function getVariantByCombination(key, value) {
|
224
|
-
var ref11;
|
225
|
-
var split = value === null || value === void 0 ? void 0 : value.split(':');
|
226
|
-
if ((split === null || split === void 0 ? void 0 : split[0]) === 'collapseKey') {
|
227
|
-
var id = Object.keys(variants).find(function(el) {
|
228
|
-
var ref;
|
229
|
-
return variants[el].collapseKey === (split === null || split === void 0 ? void 0 : split[1]) && ((ref = variants[el].attributes.find(function(attr) {
|
230
|
-
return attr.name === 'size';
|
231
|
-
})) === null || ref === void 0 ? void 0 : ref.value) === key;
|
232
|
-
});
|
233
|
-
return variants[id];
|
234
|
-
}
|
235
|
-
var id3 = (ref11 = combinations[key]) === null || ref11 === void 0 ? void 0 : ref11.params[value];
|
236
|
-
return variants === null || variants === void 0 ? void 0 : variants[id3];
|
237
|
-
};
|
238
|
-
var getCustomFieldValue = function getCustomFieldValue(field) {
|
239
|
-
return customFields === null || customFields === void 0 ? void 0 : customFields[field];
|
240
|
-
};
|
241
|
-
var getCombinationsForAttributeRule = function getCombinationsForAttributeRule(key, id) {
|
242
|
-
var ref, ref12;
|
243
|
-
var result = attributeRules === null || attributeRules === void 0 ? void 0 : (ref = attributeRules[key]) === null || ref === void 0 ? void 0 : (ref12 = ref.values) === null || ref12 === void 0 ? void 0 : ref12[id];
|
244
|
-
return result;
|
245
|
-
};
|
246
|
-
var ref5 = _slicedToArray(React.useState(false), 2), mounted = ref5[0], setMounted = ref5[1];
|
247
|
-
var ref1 = _slicedToArray(React.useState(getCombinationsAndAttributeRules), 2), ref2 = ref1[0], combinations = ref2.combinations, attributeRules = ref2.attributeRules, setCombinationsAndAttributeRules = ref1[1];
|
248
|
-
var ref3 = _slicedToArray(React.useState(getVariantsWithInventory), 2), variants = ref3[0], setVariants = ref3[1];
|
249
|
-
var ref4 = _slicedToArray(React.useState(getDefaultVariant), 2), selectedVariant = ref4[0], setSelectedVariant = ref4[1];
|
11
|
+
var ref38 = useProductVariants({
|
12
|
+
product: product,
|
13
|
+
defaultVariantId: defaultVariantId
|
14
|
+
}), selectedVariant = ref38.selectedVariant, attributeRules = ref38.attributeRules, variants = ref38.variants, getVariantById = ref38.getVariantById, getVariantByAttribute = ref38.getVariantByAttribute, getVariantByCombination = ref38.getVariantByCombination, getCustomFieldValue = ref38.getCustomFieldValue, getCombinationsForAttributeRule = ref38.getCombinationsForAttributeRule, selectVariantById = ref38.selectVariantById, selectVariantByAttribute = ref38.selectVariantByAttribute, selectVariantByCombination = ref38.selectVariantByCombination, selectVariantOptions = ref38.selectVariantOptions;
|
250
15
|
var metaData = React.useMemo(function() {
|
251
|
-
var ref, ref13, ref14, ref15, ref16, ref17, ref18, ref19, ref20, ref21, ref22, ref23, ref24, ref25, ref26, ref27, ref28, ref29, ref30, ref31, ref32, ref33, ref34, ref35, ref36, ref37
|
16
|
+
var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13, ref14, ref15, ref16, ref17, ref18, ref19, ref20, ref21, ref22, ref23, ref24, ref25, ref26, ref27, ref28, ref29, ref30, ref31, ref32, ref33, ref34, ref35, ref36, ref37;
|
252
17
|
var rootCategory = product === null || product === void 0 ? void 0 : (ref = product.categories) === null || ref === void 0 ? void 0 : ref[0];
|
253
18
|
var rootCategoryId = rootCategory === null || rootCategory === void 0 ? void 0 : rootCategory.resourceId;
|
254
19
|
var metaObj = {
|
255
20
|
_id: product === null || product === void 0 ? void 0 : product._id,
|
256
|
-
name: includeBrandInName && (product === null || product === void 0 ? void 0 : (
|
21
|
+
name: includeBrandInName && (product === null || product === void 0 ? void 0 : (ref1 = product.brands) === null || ref1 === void 0 ? void 0 : (ref2 = ref1[0]) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.resource) === null || ref3 === void 0 ? void 0 : ref3.name) ? "".concat(getTranslatableField(product === null || product === void 0 ? void 0 : (ref4 = product.brands) === null || ref4 === void 0 ? void 0 : (ref5 = ref4[0]) === null || ref5 === void 0 ? void 0 : (ref6 = ref5.resource) === null || ref6 === void 0 ? void 0 : ref6.name), " ").concat(getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name)) : getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
|
257
22
|
slug: getTranslatableField(product === null || product === void 0 ? void 0 : product.slug),
|
258
23
|
description: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.description) || getTranslatableField(product === null || product === void 0 ? void 0 : product.description),
|
259
24
|
shortDescription: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.metaDescription) || getTranslatableField(product === null || product === void 0 ? void 0 : product.metaDescription),
|
260
25
|
brand: {
|
261
|
-
_id: product === null || product === void 0 ? void 0 : (
|
262
|
-
name: getTranslatableField(product === null || product === void 0 ? void 0 : (
|
263
|
-
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (
|
264
|
-
logo: product === null || product === void 0 ? void 0 : (
|
26
|
+
_id: product === null || product === void 0 ? void 0 : (ref7 = product.brands) === null || ref7 === void 0 ? void 0 : (ref8 = ref7[0]) === null || ref8 === void 0 ? void 0 : ref8.resourceId,
|
27
|
+
name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref9 = product.brands) === null || ref9 === void 0 ? void 0 : (ref10 = ref9[0]) === null || ref10 === void 0 ? void 0 : (ref11 = ref10.resource) === null || ref11 === void 0 ? void 0 : ref11.name),
|
28
|
+
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref12 = product.brands) === null || ref12 === void 0 ? void 0 : (ref13 = ref12[0]) === null || ref13 === void 0 ? void 0 : (ref14 = ref13.resource) === null || ref14 === void 0 ? void 0 : ref14.slug),
|
29
|
+
logo: product === null || product === void 0 ? void 0 : (ref15 = product.brands) === null || ref15 === void 0 ? void 0 : (ref16 = ref15[0]) === null || ref16 === void 0 ? void 0 : (ref17 = ref16.resource) === null || ref17 === void 0 ? void 0 : (ref18 = ref17.assets) === null || ref18 === void 0 ? void 0 : (ref19 = ref18[0]) === null || ref19 === void 0 ? void 0 : (ref20 = ref19.sources) === null || ref20 === void 0 ? void 0 : (ref21 = ref20[0]) === null || ref21 === void 0 ? void 0 : ref21.url
|
265
30
|
},
|
266
31
|
category: {
|
267
|
-
_id: product === null || product === void 0 ? void 0 : (
|
268
|
-
name: getTranslatableField(product === null || product === void 0 ? void 0 : (
|
269
|
-
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (
|
32
|
+
_id: product === null || product === void 0 ? void 0 : (ref23 = product.categories) === null || ref23 === void 0 ? void 0 : (ref24 = ref23[(product === null || product === void 0 ? void 0 : (ref22 = product.categories) === null || ref22 === void 0 ? void 0 : ref22.length) - 1]) === null || ref24 === void 0 ? void 0 : ref24.resourceId,
|
33
|
+
name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref26 = product.categories) === null || ref26 === void 0 ? void 0 : (ref27 = ref26[(product === null || product === void 0 ? void 0 : (ref25 = product.categories) === null || ref25 === void 0 ? void 0 : ref25.length) - 1]) === null || ref27 === void 0 ? void 0 : (ref28 = ref27.resource) === null || ref28 === void 0 ? void 0 : ref28.name),
|
34
|
+
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref30 = product.categories) === null || ref30 === void 0 ? void 0 : (ref31 = ref30[(product === null || product === void 0 ? void 0 : (ref29 = product.categories) === null || ref29 === void 0 ? void 0 : ref29.length) - 1]) === null || ref31 === void 0 ? void 0 : (ref32 = ref31.resource) === null || ref32 === void 0 ? void 0 : ref32.slug)
|
270
35
|
},
|
271
36
|
rootCategory: {
|
272
37
|
_id: rootCategoryId,
|
273
|
-
name: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (
|
274
|
-
slug: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (
|
38
|
+
name: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref33 = rootCategory.resource) === null || ref33 === void 0 ? void 0 : ref33.name),
|
39
|
+
slug: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref34 = rootCategory.resource) === null || ref34 === void 0 ? void 0 : ref34.slug)
|
275
40
|
},
|
276
41
|
categories: formatCategories(product === null || product === void 0 ? void 0 : product.categories, rootCategoryId),
|
277
42
|
reviewRatingStatistics: product === null || product === void 0 ? void 0 : product.reviewRatingStatistics,
|
278
|
-
content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (
|
43
|
+
content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref35 = selectedVariant.content) === null || ref35 === void 0 ? void 0 : ref35.map(createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref36 = selectedVariant.content) === null || ref36 === void 0 ? void 0 : ref36.map(createProductContent) : product === null || product === void 0 ? void 0 : (ref37 = product.content) === null || ref37 === void 0 ? void 0 : ref37.map(createProductContent),
|
279
44
|
assets: assetsFieldsToMap(product === null || product === void 0 ? void 0 : product.assets)
|
280
45
|
};
|
281
46
|
return metaObj;
|
@@ -303,30 +68,6 @@ export function ProductProvider(param) {
|
|
303
68
|
product === null || product === void 0 ? void 0 : product.metaTitle,
|
304
69
|
selectedVariant,
|
305
70
|
]);
|
306
|
-
var customFields = React.useMemo(function() {
|
307
|
-
var mappedFields = createCustomFieldsMap(product === null || product === void 0 ? void 0 : product.custom);
|
308
|
-
return mappedFields;
|
309
|
-
}, [
|
310
|
-
product === null || product === void 0 ? void 0 : product.custom
|
311
|
-
]);
|
312
|
-
React.useEffect(function() {
|
313
|
-
// prevent unnecessary calculations
|
314
|
-
if (mounted) {
|
315
|
-
setVariants(getVariantsWithInventory());
|
316
|
-
}
|
317
|
-
}, [
|
318
|
-
product
|
319
|
-
]);
|
320
|
-
React.useMemo(function() {
|
321
|
-
// prevent unnecessary calculations
|
322
|
-
if (!mounted) {
|
323
|
-
return setMounted(true);
|
324
|
-
}
|
325
|
-
var data = getCombinationsAndAttributeRules();
|
326
|
-
setCombinationsAndAttributeRules(data);
|
327
|
-
}, [
|
328
|
-
variants
|
329
|
-
]);
|
330
71
|
var collapsedImages = createCollapseKeyImagesMap(product);
|
331
72
|
var state = {
|
332
73
|
metaData: metaData,
|