-
-
Notifications
You must be signed in to change notification settings - Fork 438
feat: added feature to copy version number by hovering on the version #2660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8ed5b85
deb30ac
6b32d0f
698c6d9
57d5fd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,21 @@ const packageHeaderHeight = usePackageHeaderHeight() | |
| const header = useTemplateRef('header') | ||
| const isHeaderPinned = shallowRef(false) | ||
| const { height: headerHeight } = useElementBounding(header) | ||
| const versionSelectorRef = useTemplateRef('versionSelectorRef') | ||
| const versionSelectorOpen = computed(() => versionSelectorRef.value?.isOpen ?? false) | ||
| const shouldHideCopyText = ref(false) | ||
| let hideTextTimeout: ReturnType<typeof setTimeout> | null = null | ||
|
|
||
| watch(versionSelectorOpen, isOpen => { | ||
| if (isOpen) { | ||
| shouldHideCopyText.value = true | ||
| if (hideTextTimeout) clearTimeout(hideTextTimeout) | ||
| } else { | ||
| hideTextTimeout = setTimeout(() => { | ||
| shouldHideCopyText.value = false | ||
| }, 300) | ||
| } | ||
| }) | ||
|
Comment on lines
+27
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does the timeout do here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we close the version selector, there's a short delay before the copy text comes back, to prevent UI flickering if someone opens and closes the selector quickly (like an accidental click). 300ms keeps it feeling smooth. The 300ms was added to keep it smooth.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels a little bit weird/unnatural with the delay, as if it's broken I'm thinking, Either the delay could be decreased Or, hide the |
||
|
|
||
| function isStickyPinned(el: HTMLElement | null): boolean { | ||
| if (!el) return false | ||
|
|
@@ -61,6 +76,7 @@ const { y: scrollY } = useScroll(window) | |
| const showScrollToTop = computed(() => scrollY.value > SCROLL_TO_TOP_THRESHOLD) | ||
|
|
||
| const packageName = computed(() => props.pkg?.name ?? '') | ||
| const resolvedVersionDisplay = computed(() => props.resolvedVersion ?? '') | ||
| const fundingUrl = computed(() => { | ||
| let funding = props.displayVersion?.funding | ||
| if (Array.isArray(funding)) funding = funding[0] | ||
|
|
@@ -75,6 +91,11 @@ const { copied: copiedPkgName, copy: copyPkgName } = useClipboard({ | |
| copiedDuring: 2000, | ||
| }) | ||
|
|
||
| const { copied: copiedPkgVersion, copy: copyPkgVersion } = useClipboard({ | ||
| source: resolvedVersionDisplay, | ||
| copiedDuring: 2000, | ||
| }) | ||
|
|
||
| function hasProvenance(version: PackumentVersion | null): boolean { | ||
| if (!version?.dist) return false | ||
| return !!(version.dist as { attestations?: unknown }).attestations | ||
|
|
@@ -86,8 +107,10 @@ useCommandPaletteContextCommands( | |
| computed((): CommandPaletteContextCommandInput[] => { | ||
| if (!packageName.value) return [] | ||
|
|
||
| const commands: CommandPaletteContextCommandInput[] = [ | ||
| { | ||
| const commands: CommandPaletteContextCommandInput[] = [] | ||
|
|
||
| if (packageName.value) { | ||
| commands.push({ | ||
| id: 'package-copy-name', | ||
| group: 'package', | ||
| label: $t('package.copy_name'), | ||
|
|
@@ -97,8 +120,22 @@ useCommandPaletteContextCommands( | |
| copyPkgName() | ||
| announce($t('command_palette.announcements.copied_to_clipboard')) | ||
| }, | ||
| }, | ||
| ] | ||
| }) | ||
| } | ||
|
Comment on lines
110
to
+124
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can do it like this const commands: CommandPaletteContextCommandInput[] = [
{
id: 'package-copy-name',
group: 'package',
label: $t('package.copy_name'),
keywords: [packageName.value],
iconClass: 'i-lucide:copy',
action: () => {
copyPkgName()
announce($t('command_palette.announcements.copied_to_clipboard'))
},
}
] |
||
|
|
||
| if (props.resolvedVersion) { | ||
| commands.push({ | ||
| id: 'package-copy-version', | ||
| group: 'package', | ||
| label: $t('package.versions.copy_version'), | ||
| keywords: [props.resolvedVersion ?? ''], | ||
| iconClass: 'i-lucide:copy', | ||
| action: () => { | ||
| copyPkgVersion() | ||
| announce($t('command_palette.announcements.copied_to_clipboard')) | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| if (fundingUrl.value) { | ||
| commands.push({ | ||
|
|
@@ -287,16 +324,25 @@ useShortcuts({ | |
| <span class="i-lucide:cable rtl-flip min-w-3 w-3 h-3 mx-1" aria-hidden="true" /> | ||
| </TooltipApp> | ||
| </template> | ||
| <!-- Version selector --> | ||
| <VersionSelector | ||
| <CopyToClipboardButton | ||
| :copied="copiedPkgVersion" | ||
| v-if="resolvedVersion && pkg?.versions && pkg?.['dist-tags']" | ||
| :package-name="packageName" | ||
| :current-version="resolvedVersion" | ||
| :versions="pkg.versions" | ||
| :dist-tags="pkg['dist-tags']" | ||
| :url-pattern="versionUrlPattern" | ||
| position-class="max-md:inset-is-0 md:inset-ie-0" | ||
| /> | ||
| :copy-text="$t('package.versions.copy_version')" | ||
| :hide-copy-text="shouldHideCopyText" | ||
| class="inline-flex items-center min-w-0" | ||
| @click="copyPkgVersion()" | ||
| > | ||
| <!-- Version selector --> | ||
| <VersionSelector | ||
| ref="versionSelectorRef" | ||
| :package-name="packageName" | ||
| :current-version="resolvedVersion" | ||
| :versions="pkg.versions" | ||
| :dist-tags="pkg['dist-tags']" | ||
| :url-pattern="versionUrlPattern" | ||
| position-class="max-md:inset-is-0 md:inset-ie-0" | ||
| /> | ||
| </CopyToClipboardButton> | ||
| </div> | ||
| </div> | ||
| <!-- Docs + Code — inline on desktop, floating bottom bar on mobile --> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall, the previous layout of package pages had the version number next to the package name which was a better candidate for a convenience like this. Now, with the version being a part of the version selector — a component that has significant issues on its own — this seems like a bit too much is going on. If we want this functionality, I think a dedicated button next to the version number would be better, as it avoids two popover interactions for the same element and the button on hover could be inferred as a tooltip for what the version selector does. That or we should find somewhere else to do this.