File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22defineProps <{
33 html: string
44}>()
5+
6+ const { copy } = useClipboard ()
7+
8+ // Combined click handler for:
9+ // 1. Intercepting npmjs.com links to route internally
10+ // 2. Copy button functionality for code blocks
11+ function handleClick(event : MouseEvent ) {
12+ const target = event .target as HTMLElement | undefined
13+ if (! target ) return
14+
15+ // Handle copy button clicks
16+ const copyTarget = target .closest (' [data-copy]' )
17+ if (copyTarget ) {
18+ const wrapper = copyTarget .closest (' .readme-code-block' )
19+ if (! wrapper ) return
20+
21+ const pre = wrapper .querySelector (' pre' )
22+ if (! pre ?.textContent ) return
23+
24+ copy (pre .textContent )
25+
26+ const icon = copyTarget .querySelector (' span' )
27+ if (! icon ) return
28+
29+ const originalIcon = ' i-carbon:copy'
30+ const successIcon = ' i-carbon:checkmark'
31+
32+ icon .classList .remove (originalIcon )
33+ icon .classList .add (successIcon )
34+
35+ setTimeout (() => {
36+ icon .classList .remove (successIcon )
37+ icon .classList .add (originalIcon )
38+ }, 2000 )
39+ return
40+ }
41+ }
542 </script >
643
744<template >
@@ -16,6 +53,7 @@ defineProps<{
1653 '--i18n-warning': '\'' + $t('package.readme.callout.warning') + '\'',
1754 '--i18n-caution': '\'' + $t('package.readme.callout.caution') + '\'',
1855 }"
56+ @click =" handleClick"
1957 />
2058</template >
2159
You can’t perform that action at this time.
0 commit comments