@docusaurus/theme-classic 0.0.0-4785 → 0.0.0-4789

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, {useRef, useState} from '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 [show, setShow] = useState(false);
69
- const isFocusedAnchor = useRef(false);
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
- show && styles.backToTopButtonShow,
27
+ shown && styles.backToTopButtonShow,
124
28
  )}
125
29
  type="button"
126
- onClick={() => smoothScrollTop()}
30
+ onClick={scrollToTop}
127
31
  />
128
32
  );
129
33
  }
@@ -8,13 +8,14 @@
8
8
  .codeBlockContainer {
9
9
  margin-bottom: var(--ifm-leading);
10
10
  box-shadow: var(--ifm-global-shadow-lw);
11
+ border-radius: var(--ifm-code-border-radius);
11
12
  }
12
13
 
13
14
  .codeBlockContent {
14
15
  position: relative;
15
16
  /* rtl:ignore */
16
17
  direction: ltr;
17
- border-radius: var(--ifm-global-radius);
18
+ border-radius: inherit;
18
19
  }
19
20
 
20
21
  .codeBlockTitle {
@@ -22,8 +23,8 @@
22
23
  font-size: var(--ifm-code-font-size);
23
24
  font-weight: 500;
24
25
  padding: 0.75rem var(--ifm-pre-padding);
25
- border-top-left-radius: var(--ifm-global-radius);
26
- border-top-right-radius: var(--ifm-global-radius);
26
+ border-top-left-radius: inherit;
27
+ border-top-right-radius: inherit;
27
28
  }
28
29
 
29
30
  .codeBlock {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-4785",
3
+ "version": "0.0.0-4789",
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-4785",
25
- "@docusaurus/plugin-content-blog": "0.0.0-4785",
26
- "@docusaurus/plugin-content-docs": "0.0.0-4785",
27
- "@docusaurus/plugin-content-pages": "0.0.0-4785",
28
- "@docusaurus/theme-common": "0.0.0-4785",
29
- "@docusaurus/theme-translations": "0.0.0-4785",
30
- "@docusaurus/utils": "0.0.0-4785",
31
- "@docusaurus/utils-common": "0.0.0-4785",
32
- "@docusaurus/utils-validation": "0.0.0-4785",
24
+ "@docusaurus/core": "0.0.0-4789",
25
+ "@docusaurus/plugin-content-blog": "0.0.0-4789",
26
+ "@docusaurus/plugin-content-docs": "0.0.0-4789",
27
+ "@docusaurus/plugin-content-pages": "0.0.0-4789",
28
+ "@docusaurus/theme-common": "0.0.0-4789",
29
+ "@docusaurus/theme-translations": "0.0.0-4789",
30
+ "@docusaurus/utils": "0.0.0-4789",
31
+ "@docusaurus/utils-common": "0.0.0-4789",
32
+ "@docusaurus/utils-validation": "0.0.0-4789",
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-4785",
46
- "@docusaurus/types": "0.0.0-4785",
45
+ "@docusaurus/module-type-aliases": "0.0.0-4789",
46
+ "@docusaurus/types": "0.0.0-4789",
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": "aff38fd1f2ff6a3b6338590f11af84aadd28cd1b"
62
+ "gitHead": "86d45a1daff5a4e5c79c3354ed7b389ed4cde659"
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, {useRef, useState} from '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 [show, setShow] = useState(false);
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
- show && styles.backToTopButtonShow,
28
+ shown && styles.backToTopButtonShow,
136
29
  )}
137
30
  type="button"
138
- onClick={() => smoothScrollTop()}
31
+ onClick={scrollToTop}
139
32
  />
140
33
  );
141
34
  }
@@ -8,13 +8,14 @@
8
8
  .codeBlockContainer {
9
9
  margin-bottom: var(--ifm-leading);
10
10
  box-shadow: var(--ifm-global-shadow-lw);
11
+ border-radius: var(--ifm-code-border-radius);
11
12
  }
12
13
 
13
14
  .codeBlockContent {
14
15
  position: relative;
15
16
  /* rtl:ignore */
16
17
  direction: ltr;
17
- border-radius: var(--ifm-global-radius);
18
+ border-radius: inherit;
18
19
  }
19
20
 
20
21
  .codeBlockTitle {
@@ -22,8 +23,8 @@
22
23
  font-size: var(--ifm-code-font-size);
23
24
  font-weight: 500;
24
25
  padding: 0.75rem var(--ifm-pre-padding);
25
- border-top-left-radius: var(--ifm-global-radius);
26
- border-top-right-radius: var(--ifm-global-radius);
26
+ border-top-left-radius: inherit;
27
+ border-top-right-radius: inherit;
27
28
  }
28
29
 
29
30
  .codeBlock {