@griddo/ax 11.12.1-rc.7 → 11.12.1-rc.9
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "11.12.1-rc.
|
|
4
|
+
"version": "11.12.1-rc.9",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
@@ -217,5 +217,5 @@
|
|
|
217
217
|
"publishConfig": {
|
|
218
218
|
"access": "public"
|
|
219
219
|
},
|
|
220
|
-
"gitHead": "
|
|
220
|
+
"gitHead": "e32cbe0e89e5a45fe9ca85413bcf382975d53d05"
|
|
221
221
|
}
|
|
@@ -23,6 +23,29 @@ const isEffectivelyVisible = (el: HTMLElement): boolean => {
|
|
|
23
23
|
return true;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
const getScrollOffset = (el: HTMLElement): { scrollX: number; scrollY: number } => {
|
|
27
|
+
let scrollX = window.scrollX;
|
|
28
|
+
let scrollY = window.scrollY;
|
|
29
|
+
|
|
30
|
+
let parent: HTMLElement | null = el.parentElement;
|
|
31
|
+
while (parent && parent !== document.body) {
|
|
32
|
+
const style = window.getComputedStyle(parent);
|
|
33
|
+
const overflowY = style.overflowY;
|
|
34
|
+
const overflowX = style.overflowX;
|
|
35
|
+
|
|
36
|
+
if (overflowY === "auto" || overflowY === "scroll") {
|
|
37
|
+
scrollY = parent.scrollTop;
|
|
38
|
+
}
|
|
39
|
+
if (overflowX === "auto" || overflowX === "scroll") {
|
|
40
|
+
scrollX = parent.scrollLeft;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
parent = parent.parentElement;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { scrollX, scrollY };
|
|
47
|
+
};
|
|
48
|
+
|
|
26
49
|
const HeadingsOverlay = ({ headingFilter }: IHeadingsOverlayProps) => {
|
|
27
50
|
const [boxes, setBoxes] = useState<HeadingBox[]>([]);
|
|
28
51
|
const rafRef = useRef<number>(0);
|
|
@@ -33,14 +56,13 @@ const HeadingsOverlay = ({ headingFilter }: IHeadingsOverlayProps) => {
|
|
|
33
56
|
rafRef.current = requestAnimationFrame(() => {
|
|
34
57
|
const selector = headingFilter || "h1, h2, h3, h4, h5, h6";
|
|
35
58
|
const headings = Array.from(document.querySelectorAll<HTMLElement>(selector));
|
|
36
|
-
const scrollX = window.scrollX;
|
|
37
|
-
const scrollY = window.scrollY;
|
|
38
59
|
const boxes: HeadingBox[] = [];
|
|
39
60
|
for (let i = 0; i < headings.length; i++) {
|
|
40
61
|
const el = headings[i];
|
|
41
62
|
const rect = el.getBoundingClientRect();
|
|
42
63
|
if (rect.width === 0 && rect.height === 0) continue;
|
|
43
64
|
if (!isEffectivelyVisible(el)) continue;
|
|
65
|
+
const { scrollX, scrollY } = getScrollOffset(el);
|
|
44
66
|
boxes.push({
|
|
45
67
|
id: el.dataset.griddoid || `heading-${i}`,
|
|
46
68
|
tag: el.tagName.toLowerCase(),
|
|
@@ -55,20 +77,57 @@ const HeadingsOverlay = ({ headingFilter }: IHeadingsOverlayProps) => {
|
|
|
55
77
|
|
|
56
78
|
update();
|
|
57
79
|
|
|
80
|
+
document.fonts.ready.then(update);
|
|
81
|
+
|
|
58
82
|
window.addEventListener("resize", update);
|
|
59
|
-
window.addEventListener("scroll", update, true);
|
|
60
83
|
document.addEventListener("animationend", update, true);
|
|
61
84
|
document.addEventListener("transitionend", update, true);
|
|
62
85
|
|
|
63
|
-
|
|
64
|
-
|
|
86
|
+
// Detectar contenedores scrollables y escuchar su scroll
|
|
87
|
+
const scrollContainers = new Set<Element>();
|
|
88
|
+
const detectScrollContainers = () => {
|
|
89
|
+
scrollContainers.clear();
|
|
90
|
+
const headings = Array.from(document.querySelectorAll<HTMLElement>(headingFilter || "h1, h2, h3, h4, h5, h6"));
|
|
91
|
+
headings.forEach((el) => {
|
|
92
|
+
let parent: HTMLElement | null = el.parentElement;
|
|
93
|
+
while (parent && parent !== document.body) {
|
|
94
|
+
const style = window.getComputedStyle(parent);
|
|
95
|
+
if (
|
|
96
|
+
style.overflowY === "auto" ||
|
|
97
|
+
style.overflowY === "scroll" ||
|
|
98
|
+
style.overflowX === "auto" ||
|
|
99
|
+
style.overflowX === "scroll"
|
|
100
|
+
) {
|
|
101
|
+
scrollContainers.add(parent);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
parent = parent.parentElement;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
detectScrollContainers();
|
|
110
|
+
scrollContainers.forEach((container) => {
|
|
111
|
+
container.addEventListener("scroll", update, { passive: true });
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const observer = new MutationObserver(() => {
|
|
115
|
+
detectScrollContainers();
|
|
116
|
+
scrollContainers.forEach((container) => {
|
|
117
|
+
container.addEventListener("scroll", update, { passive: true });
|
|
118
|
+
});
|
|
119
|
+
update();
|
|
120
|
+
});
|
|
121
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
65
122
|
|
|
66
123
|
return () => {
|
|
67
124
|
cancelAnimationFrame(rafRef.current);
|
|
68
125
|
window.removeEventListener("resize", update);
|
|
69
|
-
window.removeEventListener("scroll", update, true);
|
|
70
126
|
document.removeEventListener("animationend", update, true);
|
|
71
127
|
document.removeEventListener("transitionend", update, true);
|
|
128
|
+
scrollContainers.forEach((container) => {
|
|
129
|
+
container.removeEventListener("scroll", update);
|
|
130
|
+
});
|
|
72
131
|
observer.disconnect();
|
|
73
132
|
};
|
|
74
133
|
}, [headingFilter]);
|
|
@@ -6,7 +6,10 @@ const addIdsToHeadings = (container: HTMLElement, headingFilter: string | null):
|
|
|
6
6
|
const text = heading.textContent?.trim();
|
|
7
7
|
if (!text) return;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const id = `heading-${index + 1}`;
|
|
10
|
+
if (heading.dataset.griddoid !== id) {
|
|
11
|
+
heading.dataset.griddoid = id;
|
|
12
|
+
}
|
|
10
13
|
});
|
|
11
14
|
};
|
|
12
15
|
|