Merge pull request #18888 from storybookjs/pocka/fix/18829-outdated-snippet-copied

Fix copy button copying outdated snippet
This commit is contained in:
Norbert de Langen 2022-09-13 17:53:38 +03:00 committed by GitHub
commit ae618647c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 15 deletions

View File

@ -1,2 +1,2 @@
console.log('vue3-vite preset!')
console.log('vue3-vite preset!');
module.exports = require('./dist/preset');

View File

@ -7,10 +7,9 @@ export interface Stats {
toJson: () => any;
}
export type WithRequiredProperty<Type, Key extends keyof Type> = Type &
{
[Property in Key]-?: Type[Property];
};
export type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
[Property in Key]-?: Type[Property];
};
export type ManagerBuilder = Builder<
WithRequiredProperty<BuildOptions, 'outdir'> & { entryPoints: string[] },

View File

@ -6,7 +6,9 @@ import type { ExtendedOptions } from './types';
import { listStories } from './list-stories';
const absoluteFilesToImport = (files: string[], name: string) =>
files.map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'/@fs/${normalizePath(el)}'`).join('\n');
files
.map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'/@fs/${normalizePath(el)}'`)
.join('\n');
export async function generateVirtualStoryEntryCode(options: ExtendedOptions) {
const storyEntries = await listStories(options);

View File

@ -218,15 +218,18 @@ export const SyntaxHighlighter: FC<SyntaxHighlighterProps> = ({
const highlightableCode = formatter ? formatter(format, children) : children.trim();
const [copied, setCopied] = useState(false);
const onClick = useCallback((e: MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
copyToClipboard(highlightableCode)
.then(() => {
setCopied(true);
globalWindow.setTimeout(() => setCopied(false), 1500);
})
.catch(logger.error);
}, []);
const onClick = useCallback(
(e: MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
copyToClipboard(highlightableCode)
.then(() => {
setCopied(true);
globalWindow.setTimeout(() => setCopied(false), 1500);
})
.catch(logger.error);
},
[highlightableCode]
);
const renderer = wrapRenderer(rest.renderer, showLineNumbers);
return (