Skip to content

Commit 4dc0576

Browse files
authored
fix(theme): fix copy of indented code blocks, replace copy-text-to-clipboard by clipboard API (#11422)
Co-authored-by: slorber <[email protected]>
1 parent 0bc6b6e commit 4dc0576

File tree

5 files changed

+8
-24
lines changed

5 files changed

+8
-24
lines changed

packages/docusaurus-theme-classic/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@docusaurus/utils-validation": "3.8.1",
3636
"@mdx-js/react": "^3.0.0",
3737
"clsx": "^2.0.0",
38-
"copy-text-to-clipboard": "^3.2.0",
3938
"infima": "0.2.0-alpha.45",
4039
"lodash": "^4.17.21",
4140
"nprogress": "^0.2.0",

packages/docusaurus-theme-classic/src/theme/CodeBlock/Buttons/CopyButton/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import React, {
1313
type ReactNode,
1414
} from 'react';
1515
import clsx from 'clsx';
16-
import copy from 'copy-text-to-clipboard';
1716
import {translate} from '@docusaurus/Translate';
1817
import {useCodeBlockContext} from '@docusaurus/theme-common/internal';
1918
import Button from '@theme/CodeBlock/Buttons/Button';
@@ -53,11 +52,12 @@ function useCopyButton() {
5352
const copyTimeout = useRef<number | undefined>(undefined);
5453

5554
const copyCode = useCallback(() => {
56-
copy(code);
57-
setIsCopied(true);
58-
copyTimeout.current = window.setTimeout(() => {
59-
setIsCopied(false);
60-
}, 1000);
55+
navigator.clipboard.writeText(code).then(() => {
56+
setIsCopied(true);
57+
copyTimeout.current = window.setTimeout(() => {
58+
setIsCopied(false);
59+
}, 1000);
60+
});
6161
}, [code]);
6262

6363
useEffect(() => () => window.clearTimeout(copyTimeout.current), []);

packages/docusaurus/src/webpack/base.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
getCSSExtractPlugin,
1414
getMinimizers,
1515
} from '@docusaurus/bundler';
16-
1716
import {getFileLoaderUtils, md5Hash} from '@docusaurus/utils';
1817
import {loadDocusaurusAliases, loadThemeAliases} from './aliases';
1918
import {BundlerCPUProfilerPlugin} from './plugins/BundlerCPUProfilerPlugin';
@@ -28,14 +27,6 @@ const CSS_REGEX = /\.css$/i;
2827
const CSS_MODULE_REGEX = /\.module\.css$/i;
2928
export const clientDir = path.join(__dirname, '..', 'client');
3029

31-
const LibrariesToTranspile = [
32-
'copy-text-to-clipboard', // Contains optional catch binding, incompatible with recent versions of Edge
33-
];
34-
35-
const LibrariesToTranspileRegex = new RegExp(
36-
LibrariesToTranspile.map((libName) => `(node_modules/${libName})`).join('|'),
37-
);
38-
3930
function getReactAliases(siteDir: string): Record<string, string> {
4031
// Escape hatch
4132
if (process.env.DOCUSAURUS_NO_REACT_ALIASES) {
@@ -58,8 +49,7 @@ export function excludeJS(modulePath: string): boolean {
5849
// Don't transpile node_modules except any docusaurus npm package
5950
return (
6051
modulePath.includes('node_modules') &&
61-
!/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath) &&
62-
!LibrariesToTranspileRegex.test(modulePath)
52+
!/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath)
6353
);
6454
}
6555

project-words.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Blockquotes
2727
blockquotes
2828
Bokmål
2929
bunx
30+
BYOLLM
3031
caabernathy
3132
Candillon
3233
cdabcdab
@@ -367,4 +368,3 @@ Zhou
367368
zoomable
368369
zpao
369370
ödingers
370-
BYOLLM

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6813,11 +6813,6 @@ cookie@~0.4.1:
68136813
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.2.tgz#0e41f24de5ecf317947c82fc789e06a884824432"
68146814
integrity sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==
68156815

6816-
copy-text-to-clipboard@^3.2.0:
6817-
version "3.2.0"
6818-
resolved "https://registry.yarnpkg.com/copy-text-to-clipboard/-/copy-text-to-clipboard-3.2.0.tgz#0202b2d9bdae30a49a53f898626dcc3b49ad960b"
6819-
integrity sha512-RnJFp1XR/LOBDckxTib5Qjr/PMfkatD0MUCQgdpqS8MdKiNUzBjAQBEN6oUy+jW7LI93BBG3DtMB2KOOKpGs2Q==
6820-
68216816
copy-webpack-plugin@^11.0.0:
68226817
version "11.0.0"
68236818
resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-11.0.0.tgz#96d4dbdb5f73d02dd72d0528d1958721ab72e04a"

0 commit comments

Comments
 (0)