@docusaurus/theme-classic 3.9.2-canary-6526 → 3.9.2-canary-6541
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.
|
@@ -32,6 +32,18 @@ function ariaLabel(isCopied) {
|
|
|
32
32
|
description: 'The ARIA label for copy code blocks button',
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
+
async function copyToClipboard(text) {
|
|
36
|
+
// The clipboard API is only defined in secure contexts (HTTPS / localhost).
|
|
37
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
|
|
38
|
+
if (navigator.clipboard) {
|
|
39
|
+
return navigator.clipboard.writeText(text);
|
|
40
|
+
}
|
|
41
|
+
// Fall back to copy-text-to-clipboard for non-secure contexts (e.g. HTTP
|
|
42
|
+
// on a local network). The fallback is lazily loaded to avoid bundle
|
|
43
|
+
// overhead for the common HTTPS case.
|
|
44
|
+
const {default: copy} = await import('copy-text-to-clipboard');
|
|
45
|
+
return copy(text);
|
|
46
|
+
}
|
|
35
47
|
function useCopyButton() {
|
|
36
48
|
const {
|
|
37
49
|
metadata: {code},
|
|
@@ -39,12 +51,14 @@ function useCopyButton() {
|
|
|
39
51
|
const [isCopied, setIsCopied] = useState(false);
|
|
40
52
|
const copyTimeout = useRef(undefined);
|
|
41
53
|
const copyCode = useCallback(() => {
|
|
42
|
-
|
|
54
|
+
copyToClipboard(code).then(() => {
|
|
43
55
|
setIsCopied(true);
|
|
44
56
|
copyTimeout.current = window.setTimeout(() => {
|
|
45
57
|
setIsCopied(false);
|
|
46
58
|
}, 1000);
|
|
47
59
|
});
|
|
60
|
+
// Errors are intentionally not caught so they remain unhandled and can
|
|
61
|
+
// be captured by observability tools (e.g. Sentry, PostHog).
|
|
48
62
|
}, [code]);
|
|
49
63
|
useEffect(() => () => window.clearTimeout(copyTimeout.current), []);
|
|
50
64
|
return {copyCode, isCopied};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "3.9.2-canary-
|
|
3
|
+
"version": "3.9.2-canary-6541",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -20,21 +20,22 @@
|
|
|
20
20
|
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@docusaurus/core": "3.9.2-canary-
|
|
24
|
-
"@docusaurus/logger": "3.9.2-canary-
|
|
25
|
-
"@docusaurus/mdx-loader": "3.9.2-canary-
|
|
26
|
-
"@docusaurus/module-type-aliases": "3.9.2-canary-
|
|
27
|
-
"@docusaurus/plugin-content-blog": "3.9.2-canary-
|
|
28
|
-
"@docusaurus/plugin-content-docs": "3.9.2-canary-
|
|
29
|
-
"@docusaurus/plugin-content-pages": "3.9.2-canary-
|
|
30
|
-
"@docusaurus/theme-common": "3.9.2-canary-
|
|
31
|
-
"@docusaurus/theme-translations": "3.9.2-canary-
|
|
32
|
-
"@docusaurus/types": "3.9.2-canary-
|
|
33
|
-
"@docusaurus/utils": "3.9.2-canary-
|
|
34
|
-
"@docusaurus/utils-common": "3.9.2-canary-
|
|
35
|
-
"@docusaurus/utils-validation": "3.9.2-canary-
|
|
23
|
+
"@docusaurus/core": "3.9.2-canary-6541",
|
|
24
|
+
"@docusaurus/logger": "3.9.2-canary-6541",
|
|
25
|
+
"@docusaurus/mdx-loader": "3.9.2-canary-6541",
|
|
26
|
+
"@docusaurus/module-type-aliases": "3.9.2-canary-6541",
|
|
27
|
+
"@docusaurus/plugin-content-blog": "3.9.2-canary-6541",
|
|
28
|
+
"@docusaurus/plugin-content-docs": "3.9.2-canary-6541",
|
|
29
|
+
"@docusaurus/plugin-content-pages": "3.9.2-canary-6541",
|
|
30
|
+
"@docusaurus/theme-common": "3.9.2-canary-6541",
|
|
31
|
+
"@docusaurus/theme-translations": "3.9.2-canary-6541",
|
|
32
|
+
"@docusaurus/types": "3.9.2-canary-6541",
|
|
33
|
+
"@docusaurus/utils": "3.9.2-canary-6541",
|
|
34
|
+
"@docusaurus/utils-common": "3.9.2-canary-6541",
|
|
35
|
+
"@docusaurus/utils-validation": "3.9.2-canary-6541",
|
|
36
36
|
"@mdx-js/react": "^3.0.0",
|
|
37
37
|
"clsx": "^2.0.0",
|
|
38
|
+
"copy-text-to-clipboard": "^3.2.0",
|
|
38
39
|
"infima": "0.2.0-alpha.45",
|
|
39
40
|
"lodash": "^4.17.21",
|
|
40
41
|
"nprogress": "^0.2.0",
|
|
@@ -60,5 +61,5 @@
|
|
|
60
61
|
"engines": {
|
|
61
62
|
"node": ">=20.0"
|
|
62
63
|
},
|
|
63
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "60ac4995b8bfb7a1b649eb7c7ae6e812222438c5"
|
|
64
65
|
}
|
|
@@ -44,6 +44,19 @@ function ariaLabel(isCopied: boolean) {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
async function copyToClipboard(text: string) {
|
|
48
|
+
// The clipboard API is only defined in secure contexts (HTTPS / localhost).
|
|
49
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
|
|
50
|
+
if (navigator.clipboard) {
|
|
51
|
+
return navigator.clipboard.writeText(text);
|
|
52
|
+
}
|
|
53
|
+
// Fall back to copy-text-to-clipboard for non-secure contexts (e.g. HTTP
|
|
54
|
+
// on a local network). The fallback is lazily loaded to avoid bundle
|
|
55
|
+
// overhead for the common HTTPS case.
|
|
56
|
+
const {default: copy} = await import('copy-text-to-clipboard');
|
|
57
|
+
return copy(text);
|
|
58
|
+
}
|
|
59
|
+
|
|
47
60
|
function useCopyButton() {
|
|
48
61
|
const {
|
|
49
62
|
metadata: {code},
|
|
@@ -52,12 +65,14 @@ function useCopyButton() {
|
|
|
52
65
|
const copyTimeout = useRef<number | undefined>(undefined);
|
|
53
66
|
|
|
54
67
|
const copyCode = useCallback(() => {
|
|
55
|
-
|
|
68
|
+
copyToClipboard(code).then(() => {
|
|
56
69
|
setIsCopied(true);
|
|
57
70
|
copyTimeout.current = window.setTimeout(() => {
|
|
58
71
|
setIsCopied(false);
|
|
59
72
|
}, 1000);
|
|
60
73
|
});
|
|
74
|
+
// Errors are intentionally not caught so they remain unhandled and can
|
|
75
|
+
// be captured by observability tools (e.g. Sentry, PostHog).
|
|
61
76
|
}, [code]);
|
|
62
77
|
|
|
63
78
|
useEffect(() => () => window.clearTimeout(copyTimeout.current), []);
|