Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@docusaurus/utils-validation": "3.9.2",
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"copy-text-to-clipboard": "^3.2.0",
"infima": "0.2.0-alpha.45",
"lodash": "^4.17.21",
"nprogress": "^0.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ function ariaLabel(isCopied: boolean) {
});
}

async function copyToClipboard(text: string) {
// The clipboard API is only defined in secure contexts (HTTPS / localhost).
// See https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
if (navigator.clipboard) {
return navigator.clipboard.writeText(text);
}
// Fall back to copy-text-to-clipboard for non-secure contexts (e.g. HTTP
// on a local network). The fallback is lazily loaded to avoid bundle
// overhead for the common HTTPS case.
const {default: copy} = await import('copy-text-to-clipboard');
return copy(text);
}

function useCopyButton() {
const {
metadata: {code},
Expand All @@ -52,12 +65,14 @@ function useCopyButton() {
const copyTimeout = useRef<number | undefined>(undefined);

const copyCode = useCallback(() => {
navigator.clipboard.writeText(code).then(() => {
copyToClipboard(code).then(() => {
setIsCopied(true);
copyTimeout.current = window.setTimeout(() => {
setIsCopied(false);
}, 1000);
});
// Errors are intentionally not caught so they remain unhandled and can
// be captured by observability tools (e.g. Sentry, PostHog).
}, [code]);

useEffect(() => () => window.clearTimeout(copyTimeout.current), []);
Expand Down
9 changes: 7 additions & 2 deletions packages/docusaurus-types/src/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type FasterConfig = {
export type FutureV4Config = {
removeLegacyPostBuildHeadAttribute: boolean;
useCssCascadeLayers: boolean;
siteStorageNamespacing: boolean;
};

// VCS (Version Control System) info about a given change, e.g., a git commit.
Expand Down Expand Up @@ -96,8 +97,6 @@ export type FutureConfig = {

experimental_faster: FasterConfig;

experimental_storage: StorageConfig;

experimental_vcs: VcsConfig;

/**
Expand Down Expand Up @@ -175,6 +174,12 @@ export type DocusaurusConfig = {
* @see https://docusaurus.io/docs/api/docusaurus-config#i18n
*/
i18n: I18nConfig;
/**
* Site-wide browser storage options.
*
* @see https://docusaurus.io/docs/api/docusaurus-config#storage
*/
storage: StorageConfig;
/**
* Docusaurus future flags and experimental features.
* Similar to Remix future flags, see https://remix.run/blog/future-flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ exports[`loadSiteConfig website with .cjs siteConfig 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -73,6 +70,10 @@ exports[`loadSiteConfig website with .cjs siteConfig 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "",
"themeConfig": {},
Expand Down Expand Up @@ -105,17 +106,14 @@ exports[`loadSiteConfig website with ts + js config 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -158,6 +156,10 @@ exports[`loadSiteConfig website with ts + js config 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "",
"themeConfig": {},
Expand Down Expand Up @@ -190,17 +192,14 @@ exports[`loadSiteConfig website with valid JS CJS config 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -243,6 +242,10 @@ exports[`loadSiteConfig website with valid JS CJS config 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "",
"themeConfig": {},
Expand Down Expand Up @@ -275,17 +278,14 @@ exports[`loadSiteConfig website with valid JS ESM config 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -328,6 +328,10 @@ exports[`loadSiteConfig website with valid JS ESM config 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "",
"themeConfig": {},
Expand Down Expand Up @@ -360,17 +364,14 @@ exports[`loadSiteConfig website with valid TypeScript CJS config 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -413,6 +414,10 @@ exports[`loadSiteConfig website with valid TypeScript CJS config 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "",
"themeConfig": {},
Expand Down Expand Up @@ -445,17 +450,14 @@ exports[`loadSiteConfig website with valid TypeScript ESM config 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -498,6 +500,10 @@ exports[`loadSiteConfig website with valid TypeScript ESM config 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "",
"themeConfig": {},
Expand Down Expand Up @@ -530,17 +536,14 @@ exports[`loadSiteConfig website with valid async config 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -585,6 +588,10 @@ exports[`loadSiteConfig website with valid async config 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "Hello World",
"themeConfig": {},
Expand Down Expand Up @@ -617,17 +624,14 @@ exports[`loadSiteConfig website with valid async config creator function 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -672,6 +676,10 @@ exports[`loadSiteConfig website with valid async config creator function 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "Hello World",
"themeConfig": {},
Expand Down Expand Up @@ -704,17 +712,14 @@ exports[`loadSiteConfig website with valid config creator function 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -759,6 +764,10 @@ exports[`loadSiteConfig website with valid config creator function 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "Hello World",
"themeConfig": {},
Expand Down Expand Up @@ -794,17 +803,14 @@ exports[`loadSiteConfig website with valid siteConfig 1`] = `
"swcJsMinimizer": false,
},
"experimental_router": "browser",
"experimental_storage": {
"namespace": false,
"type": "localStorage",
},
"experimental_vcs": {
"getFileCreationInfo": [Function],
"getFileLastUpdateInfo": [Function],
"initialize": [Function],
},
"v4": {
"removeLegacyPostBuildHeadAttribute": false,
"siteStorageNamespacing": false,
"useCssCascadeLayers": false,
},
},
Expand Down Expand Up @@ -857,6 +863,10 @@ exports[`loadSiteConfig website with valid siteConfig 1`] = `
"staticDirectories": [
"static",
],
"storage": {
"namespace": false,
"type": "localStorage",
},
"stylesheets": [],
"tagline": "Hello World",
"themeConfig": {},
Expand Down
Loading
Loading