@constructor-io/constructorio-ui-plp 1.6.5 → 1.6.6
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/constructorio-ui-plp-bundled.js +12 -12
- package/lib/cjs/hooks/useProduct.js +13 -9
- package/lib/cjs/utils/itemFieldGetters.js +5 -1
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/hooks/useProduct.js +7 -2
- package/lib/mjs/utils/itemFieldGetters.js +3 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/types.d.ts +1 -0
- package/lib/types/utils/itemFieldGetters.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ const useCioPlpContext_1 = require("./useCioPlpContext");
|
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
const itemFieldGetters_1 = require("../utils/itemFieldGetters");
|
|
8
8
|
const useProductInfo = ({ item }) => {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
10
10
|
const state = (0, useCioPlpContext_1.useCioPlpContext)();
|
|
11
11
|
const productSwatch = (0, useProductSwatch_1.default)({ item });
|
|
12
12
|
if (!item.data || !item.itemId || !item.itemName) {
|
|
@@ -15,18 +15,22 @@ const useProductInfo = ({ item }) => {
|
|
|
15
15
|
const getPrice = (0, utils_1.tryCatchify)(((_a = state === null || state === void 0 ? void 0 : state.itemFieldGetters) === null || _a === void 0 ? void 0 : _a.getPrice) || itemFieldGetters_1.getPrice);
|
|
16
16
|
const getSalePrice = (0, utils_1.tryCatchify)(((_b = state === null || state === void 0 ? void 0 : state.itemFieldGetters) === null || _b === void 0 ? void 0 : _b.getSalePrice) || itemFieldGetters_1.getSalePrice);
|
|
17
17
|
const getRolloverImage = (0, utils_1.tryCatchify)(((_c = state === null || state === void 0 ? void 0 : state.itemFieldGetters) === null || _c === void 0 ? void 0 : _c.getRolloverImage) || itemFieldGetters_1.getRolloverImage);
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const getItemUrl = (0, utils_1.tryCatchify)(((_d = state === null || state === void 0 ? void 0 : state.itemFieldGetters) === null || _d === void 0 ? void 0 : _d.getItemUrl) || itemFieldGetters_1.getItemUrl);
|
|
19
|
+
const itemName = ((_e = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _e === void 0 ? void 0 : _e.itemName) || item.itemName;
|
|
20
|
+
const itemPrice = ((_f = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _f === void 0 ? void 0 : _f.price) || getPrice(item);
|
|
21
|
+
const itemImageUrl = ((_g = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _g === void 0 ? void 0 : _g.imageUrl) || item.imageUrl;
|
|
22
|
+
// Get href - merge variation URL into item if variation is selected
|
|
23
|
+
const itemWithVariationUrl = (productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation)
|
|
24
|
+
? Object.assign(Object.assign({}, item), { url: productSwatch.selectedVariation.url }) : item;
|
|
25
|
+
const itemUrl = getItemUrl(itemWithVariationUrl) || ((_h = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _h === void 0 ? void 0 : _h.url);
|
|
26
|
+
const variationId = (_j = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _j === void 0 ? void 0 : _j.variationId;
|
|
27
|
+
let rolloverImage = (_k = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _k === void 0 ? void 0 : _k.rolloverImage;
|
|
24
28
|
// Fallback to item's rollover image if all variations don't have a rollover image
|
|
25
|
-
if (!rolloverImage && ((
|
|
29
|
+
if (!rolloverImage && ((_l = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.swatchList) === null || _l === void 0 ? void 0 : _l.every((swatch) => !swatch.rolloverImage))) {
|
|
26
30
|
rolloverImage = getRolloverImage(item);
|
|
27
31
|
}
|
|
28
32
|
const { itemId } = item;
|
|
29
|
-
let salePrice = ((
|
|
33
|
+
let salePrice = ((_m = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _m === void 0 ? void 0 : _m.salePrice) || getSalePrice(item);
|
|
30
34
|
let hasSalePrice = true;
|
|
31
35
|
if (!(0, utils_1.isValidSalePrice)(salePrice, itemPrice)) {
|
|
32
36
|
salePrice = undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIsHiddenGroupField = exports.getSwatchPreview = exports.getSwatches = exports.getRolloverImage = exports.getSalePrice = exports.getPrice = void 0;
|
|
3
|
+
exports.getItemUrl = exports.getIsHiddenGroupField = exports.getSwatchPreview = exports.getSwatches = exports.getRolloverImage = exports.getSalePrice = exports.getPrice = void 0;
|
|
4
4
|
// eslint-disable-next-line import/prefer-default-export
|
|
5
5
|
function getPrice(item) {
|
|
6
6
|
return item.data.price;
|
|
@@ -45,3 +45,7 @@ function getIsHiddenGroupField(group) {
|
|
|
45
45
|
return (_a = group === null || group === void 0 ? void 0 : group.data) === null || _a === void 0 ? void 0 : _a.cio_plp_hidden;
|
|
46
46
|
}
|
|
47
47
|
exports.getIsHiddenGroupField = getIsHiddenGroupField;
|
|
48
|
+
function getItemUrl(item) {
|
|
49
|
+
return item === null || item === void 0 ? void 0 : item.url;
|
|
50
|
+
}
|
|
51
|
+
exports.getItemUrl = getItemUrl;
|
package/lib/cjs/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import useProductSwatch from './useProductSwatch';
|
|
2
2
|
import { useCioPlpContext } from './useCioPlpContext';
|
|
3
3
|
import { tryCatchify, isValidSalePrice } from '../utils';
|
|
4
|
-
import { getPrice as defaultGetPrice, getSalePrice as defaultGetSalePrice, getRolloverImage as defaultGetRolloverImage, } from '../utils/itemFieldGetters';
|
|
4
|
+
import { getPrice as defaultGetPrice, getSalePrice as defaultGetSalePrice, getRolloverImage as defaultGetRolloverImage, getItemUrl as defaultGetItemUrl, } from '../utils/itemFieldGetters';
|
|
5
5
|
const useProductInfo = ({ item }) => {
|
|
6
6
|
const state = useCioPlpContext();
|
|
7
7
|
const productSwatch = useProductSwatch({ item });
|
|
@@ -11,10 +11,15 @@ const useProductInfo = ({ item }) => {
|
|
|
11
11
|
const getPrice = tryCatchify(state?.itemFieldGetters?.getPrice || defaultGetPrice);
|
|
12
12
|
const getSalePrice = tryCatchify(state?.itemFieldGetters?.getSalePrice || defaultGetSalePrice);
|
|
13
13
|
const getRolloverImage = tryCatchify(state?.itemFieldGetters?.getRolloverImage || defaultGetRolloverImage);
|
|
14
|
+
const getItemUrl = tryCatchify(state?.itemFieldGetters?.getItemUrl || defaultGetItemUrl);
|
|
14
15
|
const itemName = productSwatch?.selectedVariation?.itemName || item.itemName;
|
|
15
16
|
const itemPrice = productSwatch?.selectedVariation?.price || getPrice(item);
|
|
16
17
|
const itemImageUrl = productSwatch?.selectedVariation?.imageUrl || item.imageUrl;
|
|
17
|
-
|
|
18
|
+
// Get href - merge variation URL into item if variation is selected
|
|
19
|
+
const itemWithVariationUrl = productSwatch?.selectedVariation
|
|
20
|
+
? { ...item, url: productSwatch.selectedVariation.url }
|
|
21
|
+
: item;
|
|
22
|
+
const itemUrl = getItemUrl(itemWithVariationUrl) || productSwatch?.selectedVariation?.url;
|
|
18
23
|
const variationId = productSwatch?.selectedVariation?.variationId;
|
|
19
24
|
let rolloverImage = productSwatch?.selectedVariation?.rolloverImage;
|
|
20
25
|
// Fallback to item's rollover image if all variations don't have a rollover image
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.6.
|
|
1
|
+
export default '1.6.6';
|
package/lib/types/types.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface ItemFieldGetters {
|
|
|
17
17
|
getSwatchPreview: (variation: Variation) => string;
|
|
18
18
|
getSwatches: (item: Item, retrievePrice: ItemFieldGetters['getPrice'], retrieveSwatchPreview: ItemFieldGetters['getSwatchPreview'], retrieveSalePrice: ItemFieldGetters['getSalePrice'], retrieveRolloverImage: ItemFieldGetters['getRolloverImage']) => SwatchItem[] | undefined;
|
|
19
19
|
getIsHiddenGroupField: (group: PlpItemGroup) => boolean | undefined;
|
|
20
|
+
getItemUrl: (item: Item) => string | undefined;
|
|
20
21
|
}
|
|
21
22
|
export interface Formatters {
|
|
22
23
|
formatPrice: (price?: number) => string;
|
|
@@ -5,3 +5,4 @@ export declare function getRolloverImage(item: Item | Variation): string | undef
|
|
|
5
5
|
export declare function getSwatches(item: Item, retrievePrice: ItemFieldGetters['getPrice'], retrieveSwatchPreview: ItemFieldGetters['getSwatchPreview'], retrieveSalePrice: ItemFieldGetters['getSalePrice'], retrieveRolloverImage: ItemFieldGetters['getRolloverImage']): SwatchItem[] | undefined;
|
|
6
6
|
export declare function getSwatchPreview(variation: Variation): string;
|
|
7
7
|
export declare function getIsHiddenGroupField(group: PlpItemGroup): any;
|
|
8
|
+
export declare function getItemUrl(item: Item): string | undefined;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.6.
|
|
1
|
+
declare const _default: "1.6.6";
|
|
2
2
|
export default _default;
|