gatsby-core-theme 40.0.32 → 40.0.34

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/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## [40.0.34](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v40.0.33...v40.0.34) (2024-11-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * content show more fix ([c4e91fb](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/c4e91fbcb37f6c383f90dba3da2ac4d892868a7d))
7
+
8
+ ## [40.0.33](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v40.0.32...v40.0.33) (2024-11-13)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * clean up code ([020fa15](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/020fa1542f13769eb2f8e823ecef0b0916d47150))
14
+ * fix anchor for items on content module ([e9b811e](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/e9b811e19dbbf64be59fbb68e260b196daeada0b))
15
+ * fix ribbons ([95ada5b](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/95ada5b7de9625b48f9ff5c34b0934178f617898))
16
+ * fix tests ([da1e5b7](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/da1e5b7b75b67c7d9c91a883932a02f94671cc84))
17
+ * preview feature bug ([e61af0f](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/e61af0ff04f0112403b84bee8f82313bacdeafc4))
18
+ * update scroll ([30472d1](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/30472d1620cd6eba84ad28ae8d6d322c5a08192e))
19
+
20
+
21
+ * Merge branch 'tm-4954-ribbons' into 'master' ([54ad0bc](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/54ad0bc92dbed1fe3d3d862c93dbb26d16f291cc))
22
+ * Merge branch 'tm-4901-anchor' into 'master' ([dbae75c](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/dbae75c5aa5bbd582ca0de52398e1afb0a7a1c40))
23
+ * Merge branch 'master' into tm-4901-anchor ([5c21c9c](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/5c21c9c7b59b6f39d15294bbd741424006ce0e65))
24
+
1
25
  ## [40.0.32](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v40.0.31...v40.0.32) (2024-11-12)
2
26
 
3
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-core-theme",
3
- "version": "40.0.32",
3
+ "version": "40.0.34",
4
4
  "description": "Gatsby Theme NPM Package",
5
5
  "author": "",
6
6
  "license": "ISC",
@@ -142,6 +142,7 @@ const Modules = ({ module, page, pageContext, modulePosition }) => {
142
142
  return (
143
143
  ModuleComponent && (
144
144
  <div
145
+ data-track={!!module.anchor_label}
145
146
  id={
146
147
  module.name === 'archive' && module.module_title ? null : anchorLabel
147
148
  }
@@ -1,28 +1,26 @@
1
+ /* eslint-disable react-hooks/rules-of-hooks */
1
2
  /* eslint-disable no-nested-ternary */
2
3
  /* eslint-disable import/no-extraneous-dependencies */
3
4
  /* eslint-disable no-unused-expressions */
4
5
  /* eslint-disable prefer-destructuring */
5
6
  /* eslint-disable react-hooks/exhaustive-deps */
6
7
  import React, { useRef, useState } from "react";
7
- import PropTypes from 'prop-types';
8
- import { IoIosArrowBack } from '@react-icons/all-files/io/IoIosArrowBack';
9
- import { IoIosArrowForward } from '@react-icons/all-files/io/IoIosArrowForward';
10
- import isSticky from '~hooks/stickyOnScroll';
11
- import keygen from '~helpers/keygen';
12
- import { anchorLink, removeSymbols } from '~helpers/strings';
8
+ import PropTypes from "prop-types";
9
+ import { IoIosArrowBack } from "@react-icons/all-files/io/IoIosArrowBack";
10
+ import { IoIosArrowForward } from "@react-icons/all-files/io/IoIosArrowForward";
11
+ import isSticky from "~hooks/stickyOnScroll";
12
+ import keygen from "~helpers/keygen";
13
+ import { anchorLink, removeSymbols } from "~helpers/strings";
13
14
 
14
- import useTranslate from '~hooks/useTranslate/useTranslate';
15
- import styles from './anchor.module.scss';
15
+ import useTranslate from "~hooks/useTranslate/useTranslate";
16
+ import styles from "./anchor.module.scss";
16
17
 
17
18
  function Anchor({
18
19
  module: { items },
19
- headerOffset = 80,
20
20
  isFixed = true,
21
21
  stickyOffset = 0,
22
22
  icon = null,
23
23
  showTitle = true,
24
- heightOfAnchor = 60,
25
- offset = 10,
26
24
  exclOperator = false,
27
25
  minCharactersForButtons = 86,
28
26
  setShowButtons = false,
@@ -42,97 +40,92 @@ function Anchor({
42
40
  const anchorList = items.map((anchor) => {
43
41
  numberOfCharacters += anchor?.label?.length;
44
42
  return {
45
- id: `${anchor.label && removeSymbols(anchorLink(anchor?.label?.toLowerCase()))}`,
43
+ id: `${
44
+ anchor.label &&
45
+ removeSymbols(anchorLink(anchor?.label?.toLowerCase().trim()))
46
+ }`,
46
47
  label: anchor.label,
47
- slug: `${anchor.label && anchorLink(anchor?.label?.toLowerCase().trim())}`,
48
+ slug: `${
49
+ anchor.label && anchorLink(anchor?.label?.toLowerCase().trim())
50
+ }`,
48
51
  };
49
52
  });
50
- const showButtons = numberOfCharacters > minCharactersForButtons && setShowButtons;
53
+ const showButtons =
54
+ numberOfCharacters > minCharactersForButtons && setShowButtons;
51
55
 
52
56
  const updateButtons = (shift) => {
53
57
  setScrollEnd(
54
- Math.floor(anchorListRef.current.scrollWidth - (anchorListRef.current.scrollLeft + shift)) <=
55
- anchorListRef.current.offsetWidth
58
+ Math.floor(
59
+ anchorListRef.current.scrollWidth -
60
+ (anchorListRef.current.scrollLeft + shift)
61
+ ) <= anchorListRef.current.offsetWidth
56
62
  );
57
63
  };
58
64
 
59
65
  const scroll = (shift) => {
60
66
  anchorListRef.current.scrollTo({
61
67
  left: anchorListRef.current.scrollLeft + shift,
62
- behavior: 'smooth',
68
+ behavior: "smooth",
63
69
  });
64
70
  updateButtons(shift);
65
71
  setScrollX(scrollX + shift);
66
72
  };
67
73
 
68
- function compact(array) {
69
- return array?.filter(Boolean);
70
- }
71
-
72
74
  const setActiveAnchor = () => {
75
+ const elements = document.querySelectorAll("[data-track='true']");
73
76
  const { innerHeight, scrollY } = window;
77
+ const scrollHeight = document.body.scrollHeight;
74
78
 
75
- // Progress scroll bar
76
- const scrollHeight = document.querySelector('body').scrollHeight;
79
+ // Update progress bar
77
80
  const calcPercent = (scrollY * 100) / (scrollHeight - innerHeight);
78
- progressBar.current ? (progressBar.current.style.width = `${calcPercent}%`) : null;
79
-
80
- // Get element in viewport
81
- const currentAnchor = anchorList?.map((el) => {
82
- const element = document.getElementById(el.id);
83
- if (element?.offsetTop - headerOffset - heightOfAnchor - offset <= scrollY) {
84
- return element;
85
- }
86
- return null;
87
- });
81
+ if (progressBar.current) {
82
+ progressBar.current.style.width = `${calcPercent}%`;
83
+ }
88
84
 
89
- // Filter out undefined value
90
- const currentAnchorValues = compact(currentAnchor);
91
- const currentAnchorValuesLength = currentAnchorValues.length - 1;
85
+ // Get visible elements
86
+ const visibleElements = Array.from(elements)
87
+ .filter((el) => el.getBoundingClientRect().top >= 0)
88
+ .map((el) => el.id);
92
89
 
93
- const activeElement = itemsRef.current.find(
94
- (element) =>
95
- element &&
96
- element.getAttribute('href') ===
97
- `#${currentAnchorValues[currentAnchorValuesLength]?.getAttribute('id')}`
90
+ // Reset active classes
91
+ itemsRef.current.forEach((li) =>
92
+ li?.parentNode.classList.remove(styles.active)
98
93
  );
99
94
 
100
- // Remove all active classes
101
- itemsRef.current.forEach((li) => {
102
- li && li.parentNode.classList.remove(styles.active);
103
- });
95
+ if (visibleElements.length > 0) {
96
+ const activeElement = itemsRef.current.find(
97
+ (el) => el?.getAttribute("href") === `#${visibleElements[0]}`
98
+ );
104
99
 
105
- if (activeElement && anchorListRef.current) {
106
- activeElement.parentNode.classList.add(styles.active);
100
+ if (activeElement) {
101
+ activeElement.parentNode.classList.add(styles.active);
107
102
 
108
- const elementOffsetWidth = activeElement.offsetWidth;
109
- const elementOffsetLeft = activeElement.offsetLeft;
103
+ const { offsetWidth: elementWidth, offsetLeft: elementLeft } =
104
+ activeElement;
105
+ const containerWidth = anchorContainerRef.current.offsetWidth;
110
106
 
111
- if (elementOffsetLeft > anchorContainerRef.current.offsetWidth - elementOffsetWidth) {
112
107
  anchorListRef.current.scrollLeft =
113
- elementOffsetWidth + elementOffsetLeft + 5 - anchorContainerRef.current.offsetWidth;
114
- } else {
115
- anchorListRef.current.scrollLeft = 0;
108
+ elementLeft > containerWidth - elementWidth
109
+ ? elementLeft + elementWidth + 5 - containerWidth
110
+ : 0;
116
111
  }
117
- } else if (anchorListRef.current) {
118
- // anchorListRef.current.scrollLeft = 0;
119
112
  }
120
113
  };
121
114
 
122
- const sticky = isFixed && isSticky(stickyOffset, setActiveAnchor, anchorContainerRef);
115
+ const sticky =
116
+ isFixed && isSticky(stickyOffset, setActiveAnchor, anchorContainerRef);
123
117
 
124
118
  const anchorItems = anchorList?.map((item, index) => (
125
119
  // eslint-disable-next-line react/no-array-index-key
126
- <li key={index} className={styles.anchorItem || ''}>
120
+ <li key={index} className={styles.anchorItem || ""}>
127
121
  <a
128
- className={`${styles.link || ''} anchor-carousel-gtm anchor-menu-gtm`}
122
+ className={`${styles.link || ""} anchor-carousel-gtm anchor-menu-gtm`}
129
123
  key={keygen()}
130
124
  draggable="false"
131
125
  // eslint-disable-next-line no-return-assign
132
126
  ref={(el) => (itemsRef.current[index] = el)}
133
127
  href={`#${item?.id && item.id}`}
134
128
  >
135
- {/* eslint-disable-next-line react-hooks/rules-of-hooks */}
136
129
  {useTranslate(item.slug, item.label)}
137
130
  {icon}
138
131
  </a>
@@ -140,21 +133,24 @@ function Anchor({
140
133
  ));
141
134
 
142
135
  return (
143
- <div className={styles.containerAnchor || ''} ref={anchorContainerRef}>
136
+ <div className={styles.containerAnchor || ""} ref={anchorContainerRef}>
144
137
  {showTitle && (
145
- <div className={`${styles.anchorTitle || ''}`}>
146
- {/* eslint-disable-next-line react-hooks/rules-of-hooks */}
147
- <span>{useTranslate('anchor_title', 'Table of Contents')}</span>
138
+ <div className={`${styles.anchorTitle || ""}`}>
139
+ <span>{useTranslate("anchor_title", "Table of Contents")}</span>
148
140
  </div>
149
141
  )}
150
142
 
151
143
  <div
152
- className={`${sticky ? styles.stickyContainer || '' : styles.defaultConatiner || ''}
153
- ${exclOperator ? styles.usingExclOperator || '' : ''}`}
144
+ className={`${
145
+ sticky ? styles.stickyContainer || "" : styles.defaultConatiner || ""
146
+ }
147
+ ${exclOperator ? styles.usingExclOperator || "" : ""}`}
154
148
  >
155
149
  {showButtons && (
156
150
  <button
157
- className={`${styles.buttLeft} ${scrollX <= 0 ? styles.disabled : ''}`}
151
+ className={`${styles.buttLeft} ${
152
+ scrollX <= 0 ? styles.disabled : ""
153
+ }`}
158
154
  onClick={() => scroll(-buttonScroll)}
159
155
  type="button"
160
156
  title="anchorButtonLeft"
@@ -162,12 +158,14 @@ function Anchor({
162
158
  {leftButtonIcon}
163
159
  </button>
164
160
  )}
165
- <ul ref={anchorListRef} className={`${styles.anchor || ''}`}>
161
+ <ul ref={anchorListRef} className={`${styles.anchor || ""}`}>
166
162
  {anchorItems}
167
163
  </ul>
168
164
  {showButtons && (
169
165
  <button
170
- className={`${styles.buttRight} ${!scrollEnd ? '' : styles.disabled}`}
166
+ className={`${styles.buttRight} ${
167
+ !scrollEnd ? "" : styles.disabled
168
+ }`}
171
169
  onClick={() => scroll(buttonScroll)}
172
170
  type="button"
173
171
  title="anchorButtonRight"
@@ -175,7 +173,9 @@ function Anchor({
175
173
  {rightButtonIcon}
176
174
  </button>
177
175
  )}
178
- {sticky && <div ref={progressBar} className={styles.progressBar || ''} />}
176
+ {sticky && (
177
+ <div ref={progressBar} className={styles.progressBar || ""} />
178
+ )}
179
179
  </div>
180
180
  </div>
181
181
  );
@@ -190,13 +190,10 @@ Anchor.propTypes = {
190
190
  })
191
191
  ),
192
192
  }).isRequired,
193
- headerOffset: PropTypes.number,
194
193
  styles: PropTypes.shape({}),
195
194
  isFixed: PropTypes.bool,
196
195
  icon: PropTypes.element,
197
196
  showTitle: PropTypes.string,
198
- heightOfAnchor: PropTypes.number,
199
- offset: PropTypes.number,
200
197
  stickyOffset: PropTypes.number,
201
198
  buttonScroll: PropTypes.number,
202
199
  leftButtonIcon: PropTypes.shape({}),
@@ -338,11 +338,6 @@ export function processTopListModule(
338
338
 
339
339
  listItem.items = listItem.items
340
340
  ? listItem.items.map((item) => {
341
- // Remove the ribbons if are empty, will be add ribbons from operator
342
- if (item.ribbons && item.ribbons.length === 0) delete item.ribbons;
343
- if (item.ribbon_ids && item.ribbon_ids.length === 0)
344
- delete item.ribbon_ids;
345
-
346
341
  const operatorRelation = Object.values(relations.operator).find(
347
342
  (operator) =>
348
343
  operator.operator_id === item.operator_id &&
@@ -350,7 +345,7 @@ export function processTopListModule(
350
345
  type === operator.type
351
346
  );
352
347
 
353
- if (operatorRelation) {
348
+ if (operatorRelation) {
354
349
  operatorRelation.ribbons =
355
350
  item.ribbon_ids && item.ribbon_ids.length === 0
356
351
  ? operatorRelation.ribbons
@@ -405,6 +400,7 @@ export function processContentModule(
405
400
  relationData
406
401
  );
407
402
  if (module.show_more_enabled === "1" && module.show_more_content) {
403
+ module.show_more_content = (content && content[module.show_more_content]) || module.show_more_content;
408
404
  module.show_more_content = generatePlaceholderString(
409
405
  module.show_more_content,
410
406
  translations,
@@ -11,6 +11,10 @@ export default (node, moduleWidth = 960, moduleName, pageTemplate, modulePositio
11
11
  node.attribs.class = styles && styles[node?.attribs?.class];
12
12
  }
13
13
 
14
+ if(node && node.attribs && node.attribs['data-anchor-label']) {
15
+ node.attribs['data-track'] = true;
16
+ }
17
+
14
18
  if(node.name ==='div' && (node.attribs['data-type'] === 'columnBlock' || node.attribs['data-type'] === 'threeColumnBlock')) {
15
19
  node.attribs.class = `${styles.column} ${node.attribs?.class === 'two-column-block' ? styles.twoColumnBlock : styles.threeColumnBlock}`;
16
20
  }
@@ -30,12 +30,10 @@ export async function getAPIData(page, url, headers, preview) {
30
30
  ribbons: ribbonsData
31
31
  },{}, null, null, true);
32
32
 
33
- const { path } = processed.pages[pagePreview.market].preview[0];
34
-
35
33
  const pagePreviewProcessed = processed.pages[pagePreview.market][
36
34
  pagePreview.relation_type
37
35
  // eslint-disable-next-line no-shadow
38
- ].find((page) => page.path === path);
36
+ ].find((page) => page.path === params?.path);
39
37
 
40
38
  return {
41
39
  props: {