Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function createCopyToClipboardFunction() {
if (globalWindow.navigator?.clipboard) {

Check failure on line 2 in code/core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx > Show Line Numbers

ReferenceError: Click to debug the error directly in Storybook: http://localhost:6006/?path=/story/components-syntaxhighlighter--show-line-numbers&addonPanel=storybook/interactions/panel globalWindow is not defined ❯ createCopyToClipboardFunction core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx:2:2 ❯ core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx:60:57

Check failure on line 2 in code/core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx > Padded

ReferenceError: Click to debug the error directly in Storybook: http://localhost:6006/?path=/story/components-syntaxhighlighter--padded&addonPanel=storybook/interactions/panel globalWindow is not defined ❯ createCopyToClipboardFunction core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx:2:2 ❯ core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx:60:57

Check failure on line 2 in code/core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx > Bordered Copyable

ReferenceError: Click to debug the error directly in Storybook: http://localhost:6006/?path=/story/components-syntaxhighlighter--bordered-copyable&addonPanel=storybook/interactions/panel globalWindow is not defined ❯ createCopyToClipboardFunction core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx:2:2 ❯ core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx:60:57

Check failure on line 2 in code/core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx > Story

ReferenceError: Click to debug the error directly in Storybook: http://localhost:6006/?path=/story/components-syntaxhighlighter--story&addonPanel=storybook/interactions/panel globalWindow is not defined ❯ createCopyToClipboardFunction core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx:2:2 ❯ core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx:60:57

Check failure on line 2 in code/core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx > Unsupported Dark

ReferenceError: Click to debug the error directly in Storybook: http://localhost:6006/?path=/story/components-syntaxhighlighter--unsupported-dark&addonPanel=storybook/interactions/panel globalWindow is not defined ❯ createCopyToClipboardFunction core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx:2:2 ❯ core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx:60:57

Check failure on line 2 in code/core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx > Unsupported

ReferenceError: Click to debug the error directly in Storybook: http://localhost:6006/?path=/story/components-syntaxhighlighter--unsupported&addonPanel=storybook/interactions/panel globalWindow is not defined ❯ createCopyToClipboardFunction core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx:2:2 ❯ core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx:60:57

Check failure on line 2 in code/core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx > Custom Syntax

ReferenceError: Click to debug the error directly in Storybook: http://localhost:6006/?path=/story/components-syntaxhighlighter--custom-syntax&addonPanel=storybook/interactions/panel globalWindow is not defined ❯ createCopyToClipboardFunction core/src/components/components/syntaxhighlighter/createCopyToClipboardFunction.tsx:2:2 ❯ core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx:60:57
return async (text: string) => {
try {
await globalWindow.top?.navigator.clipboard.writeText(text);
} catch {
await globalWindow.navigator.clipboard.writeText(text);
}
};
}
return async (text: string) => {
const tmp = document.createElement('TEXTAREA') as HTMLTextAreaElement;
const focus = document.activeElement as HTMLTextAreaElement;

tmp.value = text;

document.body.appendChild(tmp);
tmp.select();
document.execCommand('copy');
document.body.removeChild(tmp);
focus.focus();
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MouseEvent } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';

import { logger } from 'storybook/internal/client-logger';

Expand All @@ -26,13 +26,14 @@ import { styled } from 'storybook/theming';
import { ActionBar } from '../ActionBar/ActionBar';
import type { ScrollAreaProps } from '../ScrollArea/ScrollArea';
import { ScrollArea } from '../ScrollArea/ScrollArea';
import { createCopyToClipboardFunction } from './createCopyToClipboardFunction';
import type {
SyntaxHighlighterProps,
SyntaxHighlighterRenderer,
SyntaxHighlighterRendererProps,
} from './syntaxhighlighter-types';

const { document, window: globalWindow } = global;
const { window: globalWindow } = global;

export const supportedLanguages = {
jsextra: jsExtras,
Expand All @@ -58,30 +59,6 @@ const themedSyntax = memoize(2)((theme) =>

const copyToClipboard: (text: string) => Promise<void> = createCopyToClipboardFunction();

export function createCopyToClipboardFunction() {
if (globalWindow.navigator?.clipboard) {
return async (text: string) => {
try {
await globalWindow.top?.navigator.clipboard.writeText(text);
} catch {
await globalWindow.navigator.clipboard.writeText(text);
}
};
}
return async (text: string) => {
const tmp = document.createElement('TEXTAREA') as HTMLTextAreaElement;
const focus = document.activeElement as HTMLTextAreaElement;

tmp.value = text;

document.body.appendChild(tmp);
tmp.select();
document.execCommand('copy');
document.body.removeChild(tmp);
focus.focus();
};
}

export interface WrapperProps {
bordered?: boolean;
padded?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { Children } from 'react';

import { styled } from 'storybook/theming';

import { SyntaxHighlighter } from '../../syntaxhighlighter/syntaxhighlighter';
import { SyntaxHighlighter } from '../../syntaxhighlighter/lazy-syntaxhighlighter';
import type { SupportedLanguage } from '../../syntaxhighlighter/syntaxhighlighter-types';
import { codeCommon } from '../lib/common';
import { isReactChildString } from '../lib/isReactChildString';
Expand Down
2 changes: 1 addition & 1 deletion code/core/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type {
SupportedLanguage,
} from './components/syntaxhighlighter/syntaxhighlighter-types';
export { SyntaxHighlighter } from './components/syntaxhighlighter/lazy-syntaxhighlighter';
export { createCopyToClipboardFunction } from './components/syntaxhighlighter/syntaxhighlighter';
export { createCopyToClipboardFunction } from './components/syntaxhighlighter/createCopyToClipboardFunction';

// UI
export { ActionBar } from './components/ActionBar/ActionBar';
Expand Down
Loading