npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@oixg/context-menu

v1.0.10

Published

Context menu composable for Vue 3

Readme

@oixg/context-menu

右键菜单 composable,UI 完全由你控制。零外部依赖,仅约 1KB。

安装

npm install @oixg/context-menu

用法

<script setup lang="ts">
import { useContextMenu } from '@oixg/context-menu'

const { open, triggerEvents, style, close, menuRef } = useContextMenu()
</script>

<template>
  <div v-on="triggerEvents">右键点击</div>
  <div v-if="open" :style="style" :ref="menuRef" class="menu">
    <div @click="close">选项一</div>
    <div @click="close">选项二</div>
  </div>
</template>

行为

  • 右键点击触发元素时,菜单出现在鼠标位置
  • 自动边界修正:菜单不超出视口范围(右下角右键时自动左移/上移)
  • 点击菜单外部任意位置(左键),菜单自动关闭

API

useContextMenu(id?: string)

参数

| 参数 | 类型 | 说明 | |------|------|------| | id | string (可选) | 实例标识。不传每次调用创建独立实例;传相同 id 返回同一个实例(完全共享) |

返回值

| 返回值 | 类型 | 说明 | |--------|------|------| | open | Ref<boolean> | 菜单开关状态 | | triggerEvents | { contextmenu: (event) => void } | 绑定到触发元素的事件 | | style | { position: 'fixed'; left: string; top: string } | 绑定到菜单容器的样式,控制菜单位置 | | close | () => void | 手动关闭菜单 | | menuRef | (el: any) => void | callback ref,绑定到菜单容器用于边界位置修正 |

triggerEvents 使用 v-on 绑定:<div v-on="triggerEvents">

style 使用 :style 绑定:<div :style="style">(推荐解构使用,不解构需在模板中加 .value

menuRef 使用 :ref 绑定:<div :ref="menuRef">

作用域说明

| 用法 | 行为 | |------|------| | useContextMenu() | 每次调用返回完全独立的实例 | | useContextMenu('foo') + useContextMenu('foo') | 相同 id 返回同一个实例,所有属性完全共享。适合跨组件通信 |

示例:触发组件和菜单组件跨组件共享同一个实例。

<!-- TriggerComponent.vue -->
<script setup lang="ts">
const { triggerEvents } = useContextMenu('category-menu')
</script>
<template>
  <div v-on="triggerEvents">右键打开菜单</div>
</template>
<!-- MenuComponent.vue -->
<script setup lang="ts">
const { open, style, menuRef, close } = useContextMenu('category-menu')
</script>
<template>
  <div v-if="open.value" :style="style" :ref="menuRef" class="menu">
    <div @click="close">选项</div>
  </div>
</template>

边界修正

menuRef 绑定到菜单容器后,composable 会自动读取菜单尺寸并在超出视口时修正位置。建议始终绑定。