@apify/docs-theme 1.0.140 → 1.0.142

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/docs-theme",
3
- "version": "1.0.140",
3
+ "version": "1.0.142",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -32,3 +32,50 @@
32
32
  // load();
33
33
  // }
34
34
  // }, 500);
35
+
36
+ let lastKnownScrollHash = '';
37
+
38
+ // handles automatic scrolling of the API reference sidebar (redoc)
39
+ function scrollSidebarItemIntoView() {
40
+ const hash = window.location.hash.substring(1);
41
+
42
+ if (hash !== lastKnownScrollHash) {
43
+ const $li = document.querySelector(`li[data-item-id="${hash}"]`);
44
+
45
+ if (!$li) {
46
+ return;
47
+ }
48
+
49
+ // not visible, click on the parent <li> first
50
+ if (!$li.offsetParent) {
51
+ $li.parentElement?.parentElement?.click();
52
+ }
53
+
54
+ $li.scrollIntoView({
55
+ // smooth would be nice, but it's not working in some case
56
+ // behavior: 'smooth',
57
+ block: 'nearest',
58
+ inline: 'center',
59
+ });
60
+ lastKnownScrollHash = hash;
61
+ }
62
+ }
63
+
64
+ let ticking = false;
65
+
66
+ document.addEventListener('scroll', () => {
67
+ if (!ticking) {
68
+ // throttling based on current frame rate
69
+ window.requestAnimationFrame(() => {
70
+ scrollSidebarItemIntoView();
71
+ ticking = false;
72
+ });
73
+
74
+ ticking = true;
75
+ }
76
+ });
77
+
78
+ document.addEventListener('DOMContentLoaded', () => {
79
+ // we need to wait a bit more, since the event fires too soon, and a lot of hydration is done after it
80
+ setTimeout(() => scrollSidebarItemIntoView(), 3000);
81
+ });