File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<script setup lang="ts">
22import type { PackageFileTree } from ' #shared/types'
33import { getFileIcon } from ' ~/utils/file-icons'
4+ import { formatBytes } from ' ~/utils/formatters'
45
56const props = defineProps <{
67 tree: PackageFileTree []
@@ -35,13 +36,6 @@ const parentPath = computed(() => {
3536 if (parts .length <= 1 ) return ' '
3637 return parts .slice (0 , - 1 ).join (' /' )
3738})
38-
39- // Format file size
40- function formatBytes(bytes : number ): string {
41- if (bytes < 1024 ) return ` ${bytes } B `
42- if (bytes < 1024 * 1024 ) return ` ${(bytes / 1024 ).toFixed (1 )} kB `
43- return ` ${(bytes / (1024 * 1024 )).toFixed (1 )} MB `
44- }
4539 </script >
4640
4741<template >
Original file line number Diff line number Diff line change @@ -16,33 +16,23 @@ const menuRef = useTemplateRef('menuRef')
1616const menuId = useId ()
1717
1818// Close on click outside (check both button and menu)
19- function handleClickOutside(event : MouseEvent ) {
20- const target = event .target as Node
21- const isOutsideButton = buttonRef .value && ! buttonRef .value .contains (target )
22- const isOutsideMenu = ! menuRef .value || ! menuRef .value .contains (target )
23- if (isOutsideButton && isOutsideMenu ) {
19+ onClickOutside (
20+ menuRef ,
21+ () => {
2422 isOpen .value = false
25- }
26- }
23+ },
24+ {
25+ ignore: [buttonRef ],
26+ },
27+ )
2728
2829// Close on Escape key
29- function handleKeydown( event : KeyboardEvent ) {
30+ useEventListener ( ' keydown ' , event => {
3031 if (event .key === ' Escape' && isOpen .value ) {
3132 isOpen .value = false
3233 buttonRef .value ?.focus ()
3334 }
34- }
35-
36- onMounted (() => {
37- document .addEventListener (' click' , handleClickOutside )
38- document .addEventListener (' keydown' , handleKeydown )
3935})
40-
41- onUnmounted (() => {
42- document .removeEventListener (' click' , handleClickOutside )
43- document .removeEventListener (' keydown' , handleKeydown )
44- })
45-
4636// Columns that can be toggled (name is always visible)
4737const toggleableColumns = computed (() => props .columns .filter (col => col .id !== ' name' ))
4838
Original file line number Diff line number Diff line change @@ -23,25 +23,16 @@ const hasBothConnections = computed(() => isNpmConnected.value && !!atprotoUser.
2323/** Only show count of active (pending/approved/running) operations */
2424const operationCount = computed (() => activeOperations .value .length )
2525
26- function handleClickOutside(event : MouseEvent ) {
27- const target = event .target as HTMLElement
28- if (! target .closest (' .account-menu' )) {
29- isOpen .value = false
30- }
31- }
26+ const accountMenuRef = useTemplateRef (' accountMenuRef' )
27+
28+ onClickOutside (accountMenuRef , () => {
29+ isOpen .value = false
30+ })
3231
33- function handleKeydown( event : KeyboardEvent ) {
32+ useEventListener ( ' keydown ' , event => {
3433 if (event .key === ' Escape' && isOpen .value ) {
3534 isOpen .value = false
3635 }
37- }
38-
39- onMounted (() => {
40- document .addEventListener (' click' , handleClickOutside )
41- })
42-
43- onUnmounted (() => {
44- document .removeEventListener (' click' , handleClickOutside )
4536})
4637
4738function openConnectorModal() {
@@ -56,7 +47,7 @@ function openAuthModal() {
5647 </script >
5748
5849<template >
59- <div class = " account-menu relative " @keydown = " handleKeydown " >
50+ <div ref = " accountMenuRef " class = " relative " >
6051 <button
6152 type =" button"
6253 class =" relative flex items-center justify-end gap-2 px-2 py-1.5 min-w-24 rounded-md transition-colors duration-200 hover:bg-bg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
Original file line number Diff line number Diff line change @@ -9,9 +9,11 @@ const isActive = computed(() => !excludedRoutes.has(route.name as string))
99const isMounted = useMounted ()
1010const isVisible = shallowRef (false )
1111const scrollThreshold = 300
12- const supportsScrollStateQueries = useSupported (() => {
13- return isMounted .value && CSS .supports (' container-type' , ' scroll-state' )
14- })
12+ const { isSupported : supportsScrollStateQueries } = useCssSupports (
13+ ' container-type' ,
14+ ' scroll-state' ,
15+ { ssrValue: false },
16+ )
1517
1618function onScroll() {
1719 if (! supportsScrollStateQueries .value ) {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { assertValidPackageName } from '#shared/utils/npm'
55import { joinURL } from ' ufo'
66import { areUrlsEquivalent } from ' #shared/utils/url'
77import { isEditableElement } from ' ~/utils/input'
8+ import { formatBytes } from ' ~/utils/formatters'
89
910definePageMeta ({
1011 name: ' package' ,
@@ -243,12 +244,6 @@ function normalizeGitUrl(url: string): string {
243244 .replace (/ ^ git@github\. com:/ , ' https://github.com/' )
244245}
245246
246- function formatBytes(bytes : number ): string {
247- if (bytes < 1024 ) return ` ${bytes } B `
248- if (bytes < 1024 * 1024 ) return ` ${(bytes / 1024 ).toFixed (1 )} kB `
249- return ` ${(bytes / (1024 * 1024 )).toFixed (1 )} MB `
250- }
251-
252247function getDependencyCount(version : PackumentVersion | null ): number {
253248 if (! version ?.dependencies ) return 0
254249 return Object .keys (version .dependencies ).length
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import type {
44 PackageFileTreeResponse ,
55 PackageFileContentResponse ,
66} from ' #shared/types'
7+ import { formatBytes } from ' ~/utils/formatters'
78
89definePageMeta ({
910 name: ' code' ,
@@ -194,13 +195,6 @@ function packageRoute(ver?: string | null) {
194195 return { name: ' package' as const , params: { package: segments } }
195196}
196197
197- // Format file size
198- function formatBytes(bytes : number ): string {
199- if (bytes < 1024 ) return ` ${bytes } B `
200- if (bytes < 1024 * 1024 ) return ` ${(bytes / 1024 ).toFixed (1 )} kB `
201- return ` ${(bytes / (1024 * 1024 )).toFixed (1 )} MB `
202- }
203-
204198// Line number click handler - update URL hash without scrolling
205199function handleLineClick(lineNum : number , event : MouseEvent ) {
206200 let newHash: string
Original file line number Diff line number Diff line change @@ -46,3 +46,10 @@ export function formatCompactNumber(
4646
4747 return `${ sign } ${ Math . round ( abs ) } `
4848}
49+
50+ // Format file size
51+ export function formatBytes ( bytes : number ) : string {
52+ if ( bytes < 1024 ) return `${ bytes } B`
53+ if ( bytes < 1024 * 1024 ) return `${ ( bytes / 1024 ) . toFixed ( 1 ) } kB`
54+ return `${ ( bytes / ( 1024 * 1024 ) ) . toFixed ( 1 ) } MB`
55+ }
Original file line number Diff line number Diff line change 6565 "@vite-pwa/assets-generator" : " 1.0.2" ,
6666 "@vite-pwa/nuxt" : " 1.1.0" ,
6767 "@voidzero-dev/vite-plus-core" : " 0.0.0-833c515fa25cef20905a7f9affb156dfa6f151ab" ,
68- "@vueuse/core" : " 14.1 .0" ,
69- "@vueuse/nuxt" : " 14.1 .0" ,
70- "@vueuse/router" : " ^14.1 .0" ,
68+ "@vueuse/core" : " 14.2 .0" ,
69+ "@vueuse/nuxt" : " 14.2 .0" ,
70+ "@vueuse/router" : " ^14.2 .0" ,
7171 "marked" : " 17.0.1" ,
7272 "module-replacements" : " 2.11.0" ,
7373 "nuxt" : " 4.3.0" ,
You can’t perform that action at this time.
0 commit comments