Skip to content

Commit 74cd4f5

Browse files
authored
Merge branch 'main' into fix/issue-2044
2 parents b2508a3 + c5202d0 commit 74cd4f5

33 files changed

+2099
-308
lines changed

app/components/BaseCard.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
defineProps<{
33
/** Whether this is an exact match for the query */
44
isExactMatch?: boolean
5+
selected?: boolean
56
}>()
67
</script>
78

@@ -10,6 +11,7 @@ defineProps<{
1011
class="group bg-bg-subtle border border-border rounded-lg p-4 sm:p-6 transition-[border-color,background-color] duration-200 hover:(border-border-hover bg-bg-muted) cursor-pointer relative focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-bg focus-within:ring-offset-2 focus-within:ring-fg/50 focus-within:bg-bg-muted focus-within:border-border-hover"
1112
:class="{
1213
'border-accent/30 contrast-more:border-accent/90 bg-accent/5': isExactMatch,
14+
'bg-fg-subtle/15!': selected,
1315
}"
1416
>
1517
<!-- Glow effect for exact matches -->

app/components/ColumnPicker.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const columnLabels = computed(() => ({
5454
maintenanceScore: $t('filters.columns.maintenance_score'),
5555
combinedScore: $t('filters.columns.combined_score'),
5656
security: $t('filters.columns.security'),
57+
selection: $t('filters.columns.selection'),
5758
}))
5859
5960
function getColumnLabel(id: ColumnId): string {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<script setup lang="ts">
2+
const { selectedPackages, selectedPackagesParam, clearSelectedPackages } = usePackageSelection()
3+
4+
const shortcutKey = 'b'
5+
const actionBar = useTemplateRef('actionBarRef')
6+
onKeyStroke(
7+
e => {
8+
const target = e.target as HTMLElement
9+
const isCheckbox = target.hasAttribute('data-package-card-checkbox')
10+
return isKeyWithoutModifiers(e, shortcutKey) && (!isEditableElement(target) || isCheckbox)
11+
},
12+
e => {
13+
if (selectedPackages.value.length === 0) {
14+
return
15+
}
16+
17+
e.preventDefault()
18+
actionBar.value?.focus()
19+
},
20+
)
21+
</script>
22+
23+
<template>
24+
<Transition name="action-bar-slide" appear>
25+
<section
26+
v-if="selectedPackages.length"
27+
aria-labelledby="action-bar-title"
28+
class="group fixed bottom-10 inset-is-0 w-full flex items-center justify-center z-36 pointer-events-none focus:outline-none"
29+
tabindex="-1"
30+
aria-keyshortcuts="b"
31+
ref="actionBarRef"
32+
>
33+
<h3 id="action-bar-title" class="sr-only">
34+
{{ $t('action_bar.title') }}
35+
</h3>
36+
<div
37+
class="group-focus:outline-accent group-focus:outline-2 group-focus:outline-offset-2 pointer-events-auto bg-bg shadow-2xl shadow-accent/20 border-2 border-accent/60 p-3 min-w-[300px] rounded-xl flex gap-3 items-center justify-between animate-in ring-1 ring-accent/30"
38+
>
39+
<div aria-live="polite" aria-atomic="true" class="sr-only">
40+
{{ $t('action_bar.selection', selectedPackages.length) }}.
41+
{{ $t('action_bar.shortcut', { key: shortcutKey }) }}.
42+
</div>
43+
44+
<div class="flex items-center gap-2">
45+
<span class="text-fg font-semibold text-sm flex items-center gap-1.5">
46+
{{ $t('action_bar.selection', selectedPackages.length) }}
47+
</span>
48+
<button
49+
@click="clearSelectedPackages"
50+
class="flex items-center ms-1 text-fg-muted hover:(text-fg bg-accent/10) p-1.5 rounded-lg transition-colors"
51+
:aria-label="$t('action_bar.button_close_aria_label')"
52+
>
53+
<span class="i-lucide:x text-sm" aria-hidden="true" />
54+
</button>
55+
</div>
56+
57+
<LinkBase
58+
:to="{ name: 'compare', query: { packages: selectedPackagesParam } }"
59+
variant="button-secondary"
60+
classicon="i-lucide:git-compare"
61+
>
62+
{{ $t('package.links.compare') }}
63+
</LinkBase>
64+
</div>
65+
</section>
66+
</Transition>
67+
</template>
68+
69+
<style scoped>
70+
/* Action bar slide/fade animation */
71+
.action-bar-slide-enter-active,
72+
.action-bar-slide-leave-active {
73+
transition:
74+
opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1),
75+
transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
76+
}
77+
.action-bar-slide-enter-from,
78+
.action-bar-slide-leave-to {
79+
opacity: 0;
80+
transform: translateY(40px) scale(0.98);
81+
}
82+
.action-bar-slide-enter-to,
83+
.action-bar-slide-leave-from {
84+
opacity: 1;
85+
transform: translateY(0) scale(1);
86+
}
87+
</style>

app/components/Package/Card.vue

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const props = defineProps<{
1616
searchQuery?: string
1717
}>()
1818
19+
const { isPackageSelected, togglePackageSelection, canSelectMore } = usePackageSelection()
20+
const isSelected = computed<boolean>(() => {
21+
return isPackageSelected(props.result.package.name)
22+
})
23+
1924
const emit = defineEmits<{
2025
clickKeyword: [keyword: string]
2126
}>()
@@ -39,16 +44,16 @@ const numberFormatter = useNumberFormatter()
3944
</script>
4045

4146
<template>
42-
<BaseCard :isExactMatch="isExactMatch">
43-
<div class="mb-2 flex items-baseline justify-start gap-2">
47+
<BaseCard :selected="isSelected" :isExactMatch="isExactMatch">
48+
<header class="mb-4 flex items-baseline justify-between gap-2">
4449
<component
4550
:is="headingLevel ?? 'h3'"
4651
class="font-mono text-sm sm:text-base font-medium text-fg group-hover:text-fg transition-colors duration-200 min-w-0 break-all"
4752
>
4853
<NuxtLink
4954
:to="packageRoute(result.package.name)"
5055
:prefetch-on="prefetch ? 'visibility' : 'interaction'"
51-
class="decoration-none scroll-mt-48 scroll-mb-6 after:content-[''] after:absolute after:inset-0"
56+
class="decoration-none after:content-[''] after:absolute after:inset-0"
5257
:data-result-index="index"
5358
dir="ltr"
5459
>{{ result.package.name }}</NuxtLink
@@ -59,28 +64,17 @@ const numberFormatter = useNumberFormatter()
5964
>{{ $t('search.exact_match') }}</span
6065
>
6166
</component>
62-
<span aria-hidden="true" class="flex-shrink-1 flex-grow-1" />
63-
<!-- Mobile: version next to package name -->
64-
<div class="sm:hidden text-fg-subtle flex items-center gap-1.5 shrink-0">
65-
<span
66-
v-if="result.package.version"
67-
class="font-mono text-xs truncate max-w-20"
68-
:title="result.package.version"
69-
>
70-
v{{ result.package.version }}
71-
</span>
72-
<ProvenanceBadge
73-
v-if="result.package.publisher?.trustedPublisher"
74-
:provider="result.package.publisher.trustedPublisher.id"
75-
:package-name="result.package.name"
76-
:version="result.package.version"
77-
:linked="false"
78-
compact
79-
/>
80-
</div>
81-
</div>
82-
<div class="flex justify-start items-start gap-4 sm:gap-8">
83-
<div class="min-w-0">
67+
68+
<PackageSelectionCheckbox
69+
:package-name="result.package.name"
70+
:disabled="!canSelectMore && !isSelected"
71+
:checked="isSelected"
72+
@change="togglePackageSelection"
73+
/>
74+
</header>
75+
76+
<div class="flex flex-col sm:flex-row sm:justify-start sm:items-start gap-6 sm:gap-8">
77+
<div class="min-w-0 w-full">
8478
<p v-if="pkgDescription" class="text-fg-muted text-xs sm:text-sm line-clamp-2 mb-2 sm:mb-3">
8579
<span v-html="pkgDescription" />
8680
</p>
@@ -124,10 +118,9 @@ const numberFormatter = useNumberFormatter()
124118
</div>
125119
</dl>
126120
</div>
127-
<span aria-hidden="true" class="flex-shrink-1 flex-grow-1" />
128-
<!-- Desktop: version and downloads on right side -->
129-
<div class="hidden sm:flex flex-col gap-2 shrink-0">
130-
<div class="text-fg-subtle flex items-start gap-2 justify-end">
121+
122+
<div class="flex flex-col gap-2 shrink-0">
123+
<div class="text-fg-subtle flex items-start gap-2 sm:justify-end">
131124
<span
132125
v-if="result.package.version"
133126
class="font-mono text-xs truncate max-w-32"
@@ -150,7 +143,7 @@ const numberFormatter = useNumberFormatter()
150143
</div>
151144
<div
152145
v-if="result.downloads?.weekly"
153-
class="text-fg-subtle gap-2 flex items-center justify-end"
146+
class="text-fg-subtle gap-2 flex items-center sm:justify-end"
154147
>
155148
<span class="i-lucide:chart-line w-3.5 h-3.5" aria-hidden="true" />
156149
<span class="font-mono text-xs">

app/components/Package/Header.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ const likeAction = async () => {
247247

248248
<template>
249249
<!-- Package header -->
250-
<header class="bg-bg pt-5 w-full container">
250+
<header class="bg-bg pt-5 pb-1 w-full container">
251251
<!-- Package name and version -->
252252
<div class="flex items-baseline justify-between gap-x-2 gap-y-1 flex-wrap min-w-0">
253253
<CopyToClipboardButton
@@ -319,7 +319,7 @@ const likeAction = async () => {
319319
</header>
320320
<div
321321
ref="header"
322-
class="w-full bg-bg sticky top-14 z-50 border-b border-border pt-2"
322+
class="w-full bg-bg sticky top-14 z-10 border-b border-border pt-2"
323323
:class="[$style.packageHeader]"
324324
data-testid="package-subheader"
325325
>
@@ -395,7 +395,7 @@ const likeAction = async () => {
395395
v-if="mainLink"
396396
:to="mainLink"
397397
aria-keyshortcuts="m"
398-
class="decoration-none border-b-2 p-1 hover:border-accent/50 lowercase"
398+
class="decoration-none border-b-2 p-1 hover:border-accent/50 lowercase focus-visible:[outline-offset:-2px]!"
399399
:class="page === 'main' ? 'border-accent text-accent!' : 'border-transparent'"
400400
>
401401
{{ $t('package.links.main') }}
@@ -404,7 +404,7 @@ const likeAction = async () => {
404404
v-if="docsLink"
405405
:to="docsLink"
406406
aria-keyshortcuts="d"
407-
class="decoration-none border-b-2 p-1 hover:border-accent/50"
407+
class="decoration-none border-b-2 p-1 hover:border-accent/50 focus-visible:[outline-offset:-2px]!"
408408
:class="page === 'docs' ? 'border-accent text-accent!' : 'border-transparent'"
409409
>
410410
{{ $t('package.links.docs') }}
@@ -413,7 +413,7 @@ const likeAction = async () => {
413413
v-if="codeLink"
414414
:to="codeLink"
415415
aria-keyshortcuts="."
416-
class="decoration-none border-b-2 p-1 hover:border-accent/50"
416+
class="decoration-none border-b-2 p-1 hover:border-accent/50 focus-visible:[outline-offset:-2px]!"
417417
:class="page === 'code' ? 'border-accent text-accent!' : 'border-transparent'"
418418
>
419419
{{ $t('package.links.code') }}
@@ -423,7 +423,7 @@ const likeAction = async () => {
423423
:to="diffLink"
424424
:title="$t('compare.compare_versions_title')"
425425
aria-keyshortcuts="f"
426-
class="decoration-none border-b-2 p-1 hover:border-accent/50"
426+
class="decoration-none border-b-2 p-1 hover:border-accent/50 focus-visible:[outline-offset:-2px]!"
427427
:class="page === 'diff' ? 'border-accent text-accent!' : 'border-transparent'"
428428
>
429429
{{ $t('compare.compare_versions') }}

app/components/Package/List.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ defineExpose({
166166
<template #default="{ item, index }">
167167
<div class="pb-4">
168168
<PackageCard
169-
:result="item as NpmSearchResult"
169+
:key="item.package.name"
170+
:result="item"
170171
:heading-level="headingLevel"
171172
:show-publisher="showPublisher"
172173
:index="index"

app/components/Package/ListToolbar.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const pageSize = defineModel<PageSize>('pageSize', { required: true })
4343
4444
const emit = defineEmits<{
4545
'toggleColumn': [columnId: ColumnId]
46+
'toggleSelection': []
4647
'resetColumns': []
4748
'clearFilter': [chip: FilterChip]
4849
'clearAllFilters': []
@@ -110,6 +111,8 @@ const sortKeyLabelKeys = computed<Record<SortKey, string>>(() => ({
110111
function getSortKeyLabelKey(key: SortKey): string {
111112
return sortKeyLabelKeys.value[key]
112113
}
114+
115+
const { selectedPackages, clearSelectedPackages } = usePackageSelection()
113116
</script>
114117

115118
<template>
@@ -211,6 +214,26 @@ function getSortKeyLabelKey(key: SortKey): string {
211214

212215
<ViewModeToggle v-model="viewMode" />
213216
</div>
217+
218+
<div
219+
class="flex items-center order-3 sm:border-is sm:border-fg-subtle/20 sm:ps-3"
220+
v-if="selectedPackages.length"
221+
>
222+
<ButtonBase
223+
variant="secondary"
224+
@click="emit('toggleSelection')"
225+
classicon="i-lucide:package-check"
226+
>
227+
{{ t('filters.view_selected') }} ({{ selectedPackages.length }})
228+
</ButtonBase>
229+
<button
230+
@click="clearSelectedPackages"
231+
aria-label="Close action bar"
232+
class="flex items-center ms-2"
233+
>
234+
<span class="i-lucide:x text-sm" />
235+
</button>
236+
</div>
214237
</div>
215238
</div>
216239

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
packageName: string
4+
checked: boolean
5+
disabled?: boolean
6+
}>()
7+
8+
const emit = defineEmits<{
9+
(e: 'change', packageName: string): void
10+
}>()
11+
12+
const { t } = useI18n()
13+
const disabledText = t('package.card.select_maximum', MAX_PACKAGE_SELECTION)
14+
</script>
15+
16+
<template>
17+
<div class="relative z-1">
18+
<label>
19+
<span class="sr-only" v-if="disabled">{{ disabledText }}</span>
20+
<span class="sr-only" v-else> {{ $t('package.card.select') }}: {{ packageName }} </span>
21+
22+
<TooltipApp v-if="disabled" :text="disabledText" position="top">
23+
<input
24+
class="opacity-0 group-hover:opacity-100 size-4 accent-accent border border-fg-muted/30 hover:cursor-not-allowed"
25+
:class="{ 'opacity-100! disabled:opacity-30!': isTouchDevice() }"
26+
type="checkbox"
27+
:disabled
28+
/>
29+
</TooltipApp>
30+
31+
<input
32+
v-else
33+
data-package-card-checkbox
34+
class="opacity-0 group-focus-within:opacity-100 checked:opacity-100 group-hover:opacity-100 size-4 cursor-pointer accent-accent border border-fg-muted/30 hover:border-accent transition-colors disabled:group-hover:opacity-30 disabled:hover:cursor-not-allowed"
35+
:class="{ 'opacity-100! disabled:opacity-30!': isTouchDevice() }"
36+
type="checkbox"
37+
:checked
38+
:disabled
39+
@change="emit('change', packageName)"
40+
/>
41+
</label>
42+
</div>
43+
</template>

0 commit comments

Comments
 (0)