@docusaurus/theme-classic 0.0.0-4784 → 0.0.0-4788
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.
|
@@ -4,110 +4,14 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React
|
|
7
|
+
import React from 'react';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
import {translate} from '@docusaurus/Translate';
|
|
10
|
+
import {ThemeClassNames, useBackToTopButton} from '@docusaurus/theme-common';
|
|
10
11
|
import styles from './styles.module.css';
|
|
11
|
-
import {
|
|
12
|
-
ThemeClassNames,
|
|
13
|
-
useScrollPosition,
|
|
14
|
-
useLocationChange,
|
|
15
|
-
} from '@docusaurus/theme-common';
|
|
16
|
-
const threshold = 300; // Not all have support for smooth scrolling (particularly Safari mobile iOS)
|
|
17
|
-
// TODO proper detection is currently unreliable!
|
|
18
|
-
// see https://github.com/wessberg/scroll-behavior-polyfill/issues/16
|
|
19
|
-
|
|
20
|
-
const SupportsNativeSmoothScrolling = false; // const SupportsNativeSmoothScrolling =
|
|
21
|
-
// ExecutionEnvironment.canUseDOM &&
|
|
22
|
-
// 'scrollBehavior' in document.documentElement.style;
|
|
23
|
-
|
|
24
|
-
function smoothScrollTopNative() {
|
|
25
|
-
window.scrollTo({
|
|
26
|
-
top: 0,
|
|
27
|
-
behavior: 'smooth',
|
|
28
|
-
});
|
|
29
|
-
return () => {
|
|
30
|
-
// Nothing to cancel, it's natively cancelled if user tries to scroll down
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function smoothScrollTopPolyfill() {
|
|
35
|
-
let raf = null;
|
|
36
|
-
|
|
37
|
-
function rafRecursion() {
|
|
38
|
-
const currentScroll = document.documentElement.scrollTop;
|
|
39
|
-
|
|
40
|
-
if (currentScroll > 0) {
|
|
41
|
-
raf = requestAnimationFrame(rafRecursion);
|
|
42
|
-
window.scrollTo(0, Math.floor(currentScroll * 0.85));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
rafRecursion(); // Break the recursion. Prevents the user from "fighting" against that
|
|
47
|
-
// recursion producing a weird UX
|
|
48
|
-
|
|
49
|
-
return () => raf && cancelAnimationFrame(raf);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function useSmoothScrollToTop() {
|
|
53
|
-
const lastCancelRef = useRef(null);
|
|
54
|
-
|
|
55
|
-
function smoothScrollTop() {
|
|
56
|
-
lastCancelRef.current = SupportsNativeSmoothScrolling
|
|
57
|
-
? smoothScrollTopNative()
|
|
58
|
-
: smoothScrollTopPolyfill();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
smoothScrollTop,
|
|
63
|
-
cancelScrollToTop: () => lastCancelRef.current?.(),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
12
|
export default function BackToTopButton() {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
const {smoothScrollTop, cancelScrollToTop} = useSmoothScrollToTop();
|
|
71
|
-
useScrollPosition(({scrollY: scrollTop}, lastPosition) => {
|
|
72
|
-
const lastScrollTop = lastPosition?.scrollY; // No lastScrollTop means component is just being mounted.
|
|
73
|
-
// Not really a scroll event from the user, so we ignore it
|
|
74
|
-
|
|
75
|
-
if (!lastScrollTop) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (isFocusedAnchor.current) {
|
|
80
|
-
isFocusedAnchor.current = false;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const isScrollingUp = scrollTop < lastScrollTop;
|
|
85
|
-
|
|
86
|
-
if (!isScrollingUp) {
|
|
87
|
-
cancelScrollToTop();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (scrollTop < threshold) {
|
|
91
|
-
setShow(false);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (isScrollingUp) {
|
|
96
|
-
const documentHeight = document.documentElement.scrollHeight;
|
|
97
|
-
const windowHeight = window.innerHeight;
|
|
98
|
-
|
|
99
|
-
if (scrollTop + windowHeight < documentHeight) {
|
|
100
|
-
setShow(true);
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
setShow(false);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
useLocationChange((locationChangeEvent) => {
|
|
107
|
-
if (locationChangeEvent.location.hash) {
|
|
108
|
-
isFocusedAnchor.current = true;
|
|
109
|
-
setShow(false);
|
|
110
|
-
}
|
|
13
|
+
const {shown, scrollToTop} = useBackToTopButton({
|
|
14
|
+
threshold: 300,
|
|
111
15
|
});
|
|
112
16
|
return (
|
|
113
17
|
<button
|
|
@@ -120,10 +24,10 @@ export default function BackToTopButton() {
|
|
|
120
24
|
'clean-btn',
|
|
121
25
|
ThemeClassNames.common.backToTopButton,
|
|
122
26
|
styles.backToTopButton,
|
|
123
|
-
|
|
27
|
+
shown && styles.backToTopButtonShow,
|
|
124
28
|
)}
|
|
125
29
|
type="button"
|
|
126
|
-
onClick={
|
|
30
|
+
onClick={scrollToTop}
|
|
127
31
|
/>
|
|
128
32
|
);
|
|
129
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4788",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@docusaurus/core": "0.0.0-
|
|
25
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
26
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
28
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
29
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
30
|
-
"@docusaurus/utils": "0.0.0-
|
|
31
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
32
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
24
|
+
"@docusaurus/core": "0.0.0-4788",
|
|
25
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4788",
|
|
26
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4788",
|
|
27
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4788",
|
|
28
|
+
"@docusaurus/theme-common": "0.0.0-4788",
|
|
29
|
+
"@docusaurus/theme-translations": "0.0.0-4788",
|
|
30
|
+
"@docusaurus/utils": "0.0.0-4788",
|
|
31
|
+
"@docusaurus/utils-common": "0.0.0-4788",
|
|
32
|
+
"@docusaurus/utils-validation": "0.0.0-4788",
|
|
33
33
|
"@mdx-js/react": "^1.6.22",
|
|
34
34
|
"clsx": "^1.1.1",
|
|
35
35
|
"copy-text-to-clipboard": "^3.0.1",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"rtlcss": "^3.5.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
46
|
-
"@docusaurus/types": "0.0.0-
|
|
45
|
+
"@docusaurus/module-type-aliases": "0.0.0-4788",
|
|
46
|
+
"@docusaurus/types": "0.0.0-4788",
|
|
47
47
|
"@types/mdx-js__react": "^1.5.5",
|
|
48
48
|
"@types/prismjs": "^1.26.0",
|
|
49
49
|
"@types/rtlcss": "^3.1.2",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=14"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "880b995e4b33e050d1e6cb2bcbe5058ee6fd8cbd"
|
|
63
63
|
}
|
|
@@ -5,122 +5,15 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React
|
|
8
|
+
import React from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
10
|
import {translate} from '@docusaurus/Translate';
|
|
11
|
+
import {ThemeClassNames, useBackToTopButton} from '@docusaurus/theme-common';
|
|
11
12
|
|
|
12
13
|
import styles from './styles.module.css';
|
|
13
|
-
import {
|
|
14
|
-
ThemeClassNames,
|
|
15
|
-
useScrollPosition,
|
|
16
|
-
useLocationChange,
|
|
17
|
-
} from '@docusaurus/theme-common';
|
|
18
|
-
|
|
19
|
-
const threshold = 300;
|
|
20
|
-
|
|
21
|
-
// Not all have support for smooth scrolling (particularly Safari mobile iOS)
|
|
22
|
-
// TODO proper detection is currently unreliable!
|
|
23
|
-
// see https://github.com/wessberg/scroll-behavior-polyfill/issues/16
|
|
24
|
-
const SupportsNativeSmoothScrolling = false;
|
|
25
|
-
// const SupportsNativeSmoothScrolling =
|
|
26
|
-
// ExecutionEnvironment.canUseDOM &&
|
|
27
|
-
// 'scrollBehavior' in document.documentElement.style;
|
|
28
|
-
|
|
29
|
-
type CancelScrollTop = () => void;
|
|
30
|
-
|
|
31
|
-
function smoothScrollTopNative(): CancelScrollTop {
|
|
32
|
-
window.scrollTo({top: 0, behavior: 'smooth'});
|
|
33
|
-
return () => {
|
|
34
|
-
// Nothing to cancel, it's natively cancelled if user tries to scroll down
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function smoothScrollTopPolyfill(): CancelScrollTop {
|
|
39
|
-
let raf: number | null = null;
|
|
40
|
-
function rafRecursion() {
|
|
41
|
-
const currentScroll = document.documentElement.scrollTop;
|
|
42
|
-
if (currentScroll > 0) {
|
|
43
|
-
raf = requestAnimationFrame(rafRecursion);
|
|
44
|
-
window.scrollTo(0, Math.floor(currentScroll * 0.85));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
rafRecursion();
|
|
48
|
-
|
|
49
|
-
// Break the recursion. Prevents the user from "fighting" against that
|
|
50
|
-
// recursion producing a weird UX
|
|
51
|
-
return () => raf && cancelAnimationFrame(raf);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
type UseSmoothScrollTopReturn = {
|
|
55
|
-
// We use a cancel function because the non-native smooth scroll-top
|
|
56
|
-
// implementation must be interrupted if user scroll down
|
|
57
|
-
smoothScrollTop: () => void;
|
|
58
|
-
cancelScrollToTop: CancelScrollTop;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
function useSmoothScrollToTop(): UseSmoothScrollTopReturn {
|
|
62
|
-
const lastCancelRef = useRef<CancelScrollTop | null>(null);
|
|
63
|
-
|
|
64
|
-
function smoothScrollTop(): void {
|
|
65
|
-
lastCancelRef.current = SupportsNativeSmoothScrolling
|
|
66
|
-
? smoothScrollTopNative()
|
|
67
|
-
: smoothScrollTopPolyfill();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
smoothScrollTop,
|
|
72
|
-
cancelScrollToTop: () => lastCancelRef.current?.(),
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
14
|
|
|
76
15
|
export default function BackToTopButton(): JSX.Element {
|
|
77
|
-
const
|
|
78
|
-
const isFocusedAnchor = useRef(false);
|
|
79
|
-
const {smoothScrollTop, cancelScrollToTop} = useSmoothScrollToTop();
|
|
80
|
-
|
|
81
|
-
useScrollPosition(({scrollY: scrollTop}, lastPosition) => {
|
|
82
|
-
const lastScrollTop = lastPosition?.scrollY;
|
|
83
|
-
|
|
84
|
-
// No lastScrollTop means component is just being mounted.
|
|
85
|
-
// Not really a scroll event from the user, so we ignore it
|
|
86
|
-
if (!lastScrollTop) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (isFocusedAnchor.current) {
|
|
91
|
-
isFocusedAnchor.current = false;
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const isScrollingUp = scrollTop < lastScrollTop;
|
|
96
|
-
|
|
97
|
-
if (!isScrollingUp) {
|
|
98
|
-
cancelScrollToTop();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (scrollTop < threshold) {
|
|
102
|
-
setShow(false);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (isScrollingUp) {
|
|
107
|
-
const documentHeight = document.documentElement.scrollHeight;
|
|
108
|
-
const windowHeight = window.innerHeight;
|
|
109
|
-
if (scrollTop + windowHeight < documentHeight) {
|
|
110
|
-
setShow(true);
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
setShow(false);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
useLocationChange((locationChangeEvent) => {
|
|
118
|
-
if (locationChangeEvent.location.hash) {
|
|
119
|
-
isFocusedAnchor.current = true;
|
|
120
|
-
setShow(false);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
16
|
+
const {shown, scrollToTop} = useBackToTopButton({threshold: 300});
|
|
124
17
|
return (
|
|
125
18
|
<button
|
|
126
19
|
aria-label={translate({
|
|
@@ -132,10 +25,10 @@ export default function BackToTopButton(): JSX.Element {
|
|
|
132
25
|
'clean-btn',
|
|
133
26
|
ThemeClassNames.common.backToTopButton,
|
|
134
27
|
styles.backToTopButton,
|
|
135
|
-
|
|
28
|
+
shown && styles.backToTopButtonShow,
|
|
136
29
|
)}
|
|
137
30
|
type="button"
|
|
138
|
-
onClick={
|
|
31
|
+
onClick={scrollToTop}
|
|
139
32
|
/>
|
|
140
33
|
);
|
|
141
34
|
}
|