22defineProps <{
33 html: string
44}>()
5-
6- const router = useRouter ()
7- const { copy } = useClipboard ()
8-
9- // Combined click handler for:
10- // 1. Intercepting npmjs.com links to route internally
11- // 2. Copy button functionality for code blocks
12- function handleClick(event : MouseEvent ) {
13- const target = event .target as HTMLElement | undefined
14- if (! target ) return
15-
16- // Handle copy button clicks
17- const copyTarget = target .closest (' [data-copy]' )
18- if (copyTarget ) {
19- const wrapper = copyTarget .closest (' .readme-code-block' )
20- if (! wrapper ) return
21-
22- const pre = wrapper .querySelector (' pre' )
23- if (! pre ?.textContent ) return
24-
25- copy (pre .textContent )
26-
27- const icon = copyTarget .querySelector (' span' )
28- if (! icon ) return
29-
30- const originalIcon = ' i-carbon:copy'
31- const successIcon = ' i-carbon:checkmark'
32-
33- icon .classList .remove (originalIcon )
34- icon .classList .add (successIcon )
35-
36- setTimeout (() => {
37- icon .classList .remove (successIcon )
38- icon .classList .add (originalIcon )
39- }, 2000 )
40- return
41- }
42-
43- // Handle npmjs.com link clicks - route internally
44- const anchor = target .closest (' a' )
45- if (! anchor ) return
46-
47- const href = anchor .getAttribute (' href' )
48- if (! href ) return
49-
50- // Handle relative anchor links
51- if (href .startsWith (' #' )) {
52- event .preventDefault ()
53- router .push (href )
54- return
55- }
56-
57- const match = href .match (/ ^ (?:https? :\/\/ )? (?:www\. )? npmjs\. (?:com| org)(\/ . + )$ / )
58- if (! match || ! match [1 ]) return
59-
60- const route = router .resolve (match [1 ])
61- if (route ) {
62- event .preventDefault ()
63- router .push (route )
64- }
65- }
665 </script >
676
687<template >
@@ -77,7 +16,6 @@ function handleClick(event: MouseEvent) {
7716 '--i18n-warning': '\'' + $t('package.readme.callout.warning') + '\'',
7817 '--i18n-caution': '\'' + $t('package.readme.callout.caution') + '\'',
7918 }"
80- @click =" handleClick"
8119 />
8220</template >
8321
0 commit comments