@sentecacommerce-theme/lib 0.12.91 → 0.12.92

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.
@@ -16,7 +16,7 @@ var usePixelFinishOrder = function() {
16
16
  if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
17
17
  var pixel = window.pixel;
18
18
  if (payload) {
19
- pixel.finishOrder(payload);
19
+ pixel === null || pixel === void 0 ? void 0 : pixel.finishOrder(payload);
20
20
  }
21
21
  }
22
22
  };
@@ -37,18 +37,14 @@ function _objectSpread(target) {
37
37
  }
38
38
  return target;
39
39
  }
40
- var _typeof = function(obj) {
41
- "@swc/helpers - typeof";
42
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
43
- };
44
40
  var usePixelProductClick = function() {
45
41
  var defaultMerchant = (0, _index).useConfigState().defaultMerchant;
46
42
  var sendClickEvent = function(param) {
47
43
  var product = param.product, info = param.info;
48
- if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
44
+ if ((0, _index).canUseDOM() && defaultMerchant) {
49
45
  var pixel = window.pixel;
50
- pixel.productClick(product, _objectSpread({}, info, {
51
- merchantKey: defaultMerchant || ''
46
+ pixel === null || pixel === void 0 ? void 0 : pixel.productClick(product, _objectSpread({}, info, {
47
+ merchantKey: defaultMerchant
52
48
  }));
53
49
  }
54
50
  };
@@ -6,6 +6,7 @@ var _react = _interopRequireDefault(require("react"));
6
6
  var _router = require("next/router");
7
7
  var _index = require("../../../index");
8
8
  var _releva = require("../../Releva");
9
+ var _utils = require("../../../utils");
9
10
  function _arrayLikeToArray(arr, len) {
10
11
  if (len == null || len > arr.length) len = arr.length;
11
12
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -49,10 +50,6 @@ function _nonIterableRest() {
49
50
  function _slicedToArray(arr, i) {
50
51
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
51
52
  }
52
- var _typeof = function(obj) {
53
- "@swc/helpers - typeof";
54
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
55
- };
56
53
  function _unsupportedIterableToArray(o, minLen) {
57
54
  if (!o) return;
58
55
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -63,7 +60,7 @@ function _unsupportedIterableToArray(o, minLen) {
63
60
  }
64
61
  var usePixelProductsImpression = function(param) {
65
62
  var productsData = param.productsData, isCarousel = param.isCarousel;
66
- var ref3 = _slicedToArray((0, _index).useBoolean(false), 2), sentAlready = ref3[0], setSentAlready = ref3[1];
63
+ var ref4 = _slicedToArray((0, _index).useBoolean(false), 2), sentAlready = ref4[0], setSentAlready = ref4[1];
67
64
  var defaultMerchant = (0, _index).useConfigState().defaultMerchant;
68
65
  var router = (0, _router).useRouter();
69
66
  var products = [];
@@ -71,35 +68,47 @@ var usePixelProductsImpression = function(param) {
71
68
  products = (0, _releva).createMappedProducts(productsData.products);
72
69
  }
73
70
  _react.default.useEffect(function() {
71
+ setSentAlready.off();
72
+ }, [
73
+ router.asPath,
74
+ productsData.products.length,
75
+ setSentAlready
76
+ ]);
77
+ _react.default.useEffect(function() {
78
+ var ref, ref1, ref2;
74
79
  if (sentAlready || !products.length) return;
75
- router.events.on('routeChangeComplete', function() {
76
- var ref, ref1;
77
- if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined && !((ref = productsData.products) === null || ref === void 0 ? void 0 : (ref1 = ref[0]) === null || ref1 === void 0 ? void 0 : ref1.isPlaceholder) && (productsData === null || productsData === void 0 ? void 0 : productsData.length) > 0) {
78
- var ref2;
79
- var pixel = window.pixel;
80
- var title = window === null || window === void 0 ? void 0 : (ref2 = window.document) === null || ref2 === void 0 ? void 0 : ref2.title;
81
- var sendImpressions = function() {
82
- if (!title || title === 'за') {
83
- setTimeout(function() {
84
- return sendImpressions();
85
- }, 20);
86
- return;
80
+ if ((0, _utils).canUseDOM() && !((ref = productsData.products) === null || ref === void 0 ? void 0 : (ref1 = ref[0]) === null || ref1 === void 0 ? void 0 : ref1.isPlaceholder) && (productsData === null || productsData === void 0 ? void 0 : (ref2 = productsData.products) === null || ref2 === void 0 ? void 0 : ref2.length) > 0) {
81
+ var ref3;
82
+ var pixel = window.pixel;
83
+ var title = window === null || window === void 0 ? void 0 : (ref3 = window.document) === null || ref3 === void 0 ? void 0 : ref3.title;
84
+ var sendImpressions = function() {
85
+ if (!title || title === 'за') {
86
+ setTimeout(function() {
87
+ return sendImpressions();
88
+ }, 20);
89
+ return;
90
+ }
91
+ pixel === null || pixel === void 0 ? void 0 : pixel.productsImpression(!isCarousel ? [
92
+ {
93
+ listName: title,
94
+ products: products
87
95
  }
88
- pixel === null || pixel === void 0 ? void 0 : pixel.productsImpression(!isCarousel ? [
89
- {
90
- listName: title,
91
- products: products
92
- }
93
- ] : productsData, {
94
- merchantKey: defaultMerchant || ''
95
- });
96
- };
97
- sendImpressions();
96
+ ] : productsData, {
97
+ merchantKey: defaultMerchant || ''
98
+ });
98
99
  setSentAlready.on();
99
- }
100
- });
100
+ };
101
+ sendImpressions();
102
+ }
101
103
  }, [
102
- router.route
104
+ router.route,
105
+ defaultMerchant,
106
+ sentAlready,
107
+ products,
108
+ router.events,
109
+ productsData,
110
+ setSentAlready,
111
+ isCarousel,
103
112
  ]);
104
113
  };
105
114
  exports.usePixelProductsImpression = usePixelProductsImpression;
@@ -13,7 +13,7 @@ var usePixelViewBasket = function() {
13
13
  if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
14
14
  var pixel = window.pixel;
15
15
  if (payload) {
16
- pixel.viewBasket(payload);
16
+ pixel === null || pixel === void 0 ? void 0 : pixel.viewBasket(payload);
17
17
  }
18
18
  }
19
19
  };
@@ -7,11 +7,18 @@ var _typeof = function(obj) {
7
7
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
8
8
  };
9
9
  var usePixelViewCategory = function() {
10
- var sendViewCategoryEvent = function(categoryBreadcrumb) {
10
+ var sendViewCategoryEvent = function(breadcrumbData) {
11
+ var breadcrumbString = breadcrumbData.reduce(function(res, curr, index) {
12
+ res += curr.name;
13
+ if (index !== breadcrumbData.length - 1) {
14
+ res += '/';
15
+ }
16
+ return res;
17
+ }, '');
11
18
  if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
12
19
  var pixel = window.pixel;
13
- if (categoryBreadcrumb) {
14
- pixel.viewCategory(categoryBreadcrumb);
20
+ if (breadcrumbString) {
21
+ pixel === null || pixel === void 0 ? void 0 : pixel.viewCategory(breadcrumbString);
15
22
  }
16
23
  }
17
24
  };
@@ -12,7 +12,7 @@ export var usePixelFinishOrder = function() {
12
12
  if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
13
13
  var pixel = window.pixel;
14
14
  if (payload) {
15
- pixel.finishOrder(payload);
15
+ pixel === null || pixel === void 0 ? void 0 : pixel.finishOrder(payload);
16
16
  }
17
17
  }
18
18
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { useConfigState } from '../../../index';
2
+ import { useConfigState, canUseDOM } from '../../../index';
3
3
  function _defineProperty(obj, key, value) {
4
4
  if (key in obj) {
5
5
  Object.defineProperty(obj, key, {
@@ -28,18 +28,14 @@ function _objectSpread(target) {
28
28
  }
29
29
  return target;
30
30
  }
31
- var _typeof = function(obj) {
32
- "@swc/helpers - typeof";
33
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
34
- };
35
31
  export var usePixelProductClick = function() {
36
32
  var defaultMerchant = useConfigState().defaultMerchant;
37
33
  var sendClickEvent = function(param) {
38
34
  var product = param.product, info = param.info;
39
- if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
35
+ if (canUseDOM() && defaultMerchant) {
40
36
  var pixel = window.pixel;
41
- pixel.productClick(product, _objectSpread({}, info, {
42
- merchantKey: defaultMerchant || ''
37
+ pixel === null || pixel === void 0 ? void 0 : pixel.productClick(product, _objectSpread({}, info, {
38
+ merchantKey: defaultMerchant
43
39
  }));
44
40
  }
45
41
  };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { useRouter } from 'next/router';
3
3
  import { useConfigState, useBoolean } from '../../../index';
4
4
  import { createMappedProducts } from '../../Releva';
5
+ import { canUseDOM } from '../../../utils';
5
6
  function _arrayLikeToArray(arr, len) {
6
7
  if (len == null || len > arr.length) len = arr.length;
7
8
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -40,10 +41,6 @@ function _nonIterableRest() {
40
41
  function _slicedToArray(arr, i) {
41
42
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
42
43
  }
43
- var _typeof = function(obj) {
44
- "@swc/helpers - typeof";
45
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
46
- };
47
44
  function _unsupportedIterableToArray(o, minLen) {
48
45
  if (!o) return;
49
46
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -54,7 +51,7 @@ function _unsupportedIterableToArray(o, minLen) {
54
51
  }
55
52
  export var usePixelProductsImpression = function(param) {
56
53
  var productsData = param.productsData, isCarousel = param.isCarousel;
57
- var ref3 = _slicedToArray(useBoolean(false), 2), sentAlready = ref3[0], setSentAlready = ref3[1];
54
+ var ref4 = _slicedToArray(useBoolean(false), 2), sentAlready = ref4[0], setSentAlready = ref4[1];
58
55
  var defaultMerchant = useConfigState().defaultMerchant;
59
56
  var router = useRouter();
60
57
  var products = [];
@@ -62,34 +59,46 @@ export var usePixelProductsImpression = function(param) {
62
59
  products = createMappedProducts(productsData.products);
63
60
  }
64
61
  React.useEffect(function() {
62
+ setSentAlready.off();
63
+ }, [
64
+ router.asPath,
65
+ productsData.products.length,
66
+ setSentAlready
67
+ ]);
68
+ React.useEffect(function() {
69
+ var ref, ref1, ref2;
65
70
  if (sentAlready || !products.length) return;
66
- router.events.on('routeChangeComplete', function() {
67
- var ref, ref1;
68
- if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined && !((ref = productsData.products) === null || ref === void 0 ? void 0 : (ref1 = ref[0]) === null || ref1 === void 0 ? void 0 : ref1.isPlaceholder) && (productsData === null || productsData === void 0 ? void 0 : productsData.length) > 0) {
69
- var ref2;
70
- var pixel = window.pixel;
71
- var title = window === null || window === void 0 ? void 0 : (ref2 = window.document) === null || ref2 === void 0 ? void 0 : ref2.title;
72
- var sendImpressions = function() {
73
- if (!title || title === 'за') {
74
- setTimeout(function() {
75
- return sendImpressions();
76
- }, 20);
77
- return;
71
+ if (canUseDOM() && !((ref = productsData.products) === null || ref === void 0 ? void 0 : (ref1 = ref[0]) === null || ref1 === void 0 ? void 0 : ref1.isPlaceholder) && (productsData === null || productsData === void 0 ? void 0 : (ref2 = productsData.products) === null || ref2 === void 0 ? void 0 : ref2.length) > 0) {
72
+ var ref3;
73
+ var pixel = window.pixel;
74
+ var title = window === null || window === void 0 ? void 0 : (ref3 = window.document) === null || ref3 === void 0 ? void 0 : ref3.title;
75
+ var sendImpressions = function() {
76
+ if (!title || title === 'за') {
77
+ setTimeout(function() {
78
+ return sendImpressions();
79
+ }, 20);
80
+ return;
81
+ }
82
+ pixel === null || pixel === void 0 ? void 0 : pixel.productsImpression(!isCarousel ? [
83
+ {
84
+ listName: title,
85
+ products: products
78
86
  }
79
- pixel === null || pixel === void 0 ? void 0 : pixel.productsImpression(!isCarousel ? [
80
- {
81
- listName: title,
82
- products: products
83
- }
84
- ] : productsData, {
85
- merchantKey: defaultMerchant || ''
86
- });
87
- };
88
- sendImpressions();
87
+ ] : productsData, {
88
+ merchantKey: defaultMerchant || ''
89
+ });
89
90
  setSentAlready.on();
90
- }
91
- });
91
+ };
92
+ sendImpressions();
93
+ }
92
94
  }, [
93
- router.route
95
+ router.route,
96
+ defaultMerchant,
97
+ sentAlready,
98
+ products,
99
+ router.events,
100
+ productsData,
101
+ setSentAlready,
102
+ isCarousel,
94
103
  ]);
95
104
  };
@@ -9,7 +9,7 @@ export var usePixelViewBasket = function() {
9
9
  if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
10
10
  var pixel = window.pixel;
11
11
  if (payload) {
12
- pixel.viewBasket(payload);
12
+ pixel === null || pixel === void 0 ? void 0 : pixel.viewBasket(payload);
13
13
  }
14
14
  }
15
15
  };
@@ -3,11 +3,18 @@ var _typeof = function(obj) {
3
3
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
4
4
  };
5
5
  export var usePixelViewCategory = function() {
6
- var sendViewCategoryEvent = function(categoryBreadcrumb) {
6
+ var sendViewCategoryEvent = function(breadcrumbData) {
7
+ var breadcrumbString = breadcrumbData.reduce(function(res, curr, index) {
8
+ res += curr.name;
9
+ if (index !== breadcrumbData.length - 1) {
10
+ res += '/';
11
+ }
12
+ return res;
13
+ }, '');
7
14
  if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
8
15
  var pixel = window.pixel;
9
- if (categoryBreadcrumb) {
10
- pixel.viewCategory(categoryBreadcrumb);
16
+ if (breadcrumbString) {
17
+ pixel === null || pixel === void 0 ? void 0 : pixel.viewCategory(breadcrumbString);
11
18
  }
12
19
  }
13
20
  };
@@ -1,3 +1,7 @@
1
1
  export declare const usePixelViewCategory: () => {
2
- sendViewCategoryEvent: (categoryBreadcrumb: string) => void;
2
+ sendViewCategoryEvent: (breadcrumbData: {
3
+ name: string;
4
+ id: string;
5
+ link: string;
6
+ }[]) => void;
3
7
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentecacommerce-theme/lib",
3
3
  "sideEffects": false,
4
- "version": "0.12.91",
4
+ "version": "0.12.92",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -31,13 +31,13 @@
31
31
  "watch:cjs": "swc src --out-dir dist/cjs -w",
32
32
  "watch:esm": "swc src --out-dir dist/esm --no-swcrc -w"
33
33
  },
34
- "gitHead": "bb0947520feb34f8271e3be4c9e76cfaeb3b5c5f",
34
+ "gitHead": "51758ab3d6f98e5ac31cf8b2d1b4bdefdf690fe1",
35
35
  "peerDependencies": {
36
36
  "react-query": "^2.26.2"
37
37
  },
38
38
  "dependencies": {
39
- "@sentecacommerce-theme/base": "^0.12.91",
40
- "@sentecacommerce-theme/cms": "^0.12.91",
39
+ "@sentecacommerce-theme/base": "^0.12.92",
40
+ "@sentecacommerce-theme/cms": "^0.12.92",
41
41
  "@sentecacommerce/sdk": "2.0.161",
42
42
  "body-scroll-lock": "^3.1.5",
43
43
  "copy-to-clipboard": "^3.3.1",