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 🙏

© 2025 – Pkg Stats / Ryan Hefner

context-menu-plugin

v1.0.0

Published

右键菜单插件,支持Vue3和React双版本

Readme

Context Menu Plugin User Guide

A powerful context menu plugin that supports both Vue 3 and React.

Features

  • 🎯 Framework agnostic - supports both Vue 3 and React
  • 🎨 Themes support - includes light/dark themes and custom themes
  • 📱 Responsive - works on both desktop and mobile devices
  • ⌨️ Full keyboard navigation
  • 🔍 Context-aware menu items
  • 🎭 Transition animations
  • ♿ Accessibility support
  • 🛡️ TypeScript support

Installation

# NPM
npm install context-menu-plugin

# Yarn
yarn add context-menu-plugin

# PNPM
pnpm add context-menu-plugin

Framework Dependencies

For Vue 3:

npm install vue@^3.2.0

For React:

npm install react@^16.8.0 react-dom@^16.8.0

Usage

Vue 3

  1. Register the plugin in your main.js:
import { createApp } from 'vue'
import ContextMenu from 'context-menu-plugin'
import App from './App.vue'

const app = createApp(App)
app.use(ContextMenu, { framework: 'vue3' })
app.mount('#app')
  1. Use in components:
<template>
  <div v-contextmenu="menuItems">Right click here</div>
</template>

<script setup>
const menuItems = [
  { label: 'Copy', handler: () => console.log('Copy') },
  { label: 'Paste', handler: () => console.log('Paste') },
  { type: 'separator' },
  {
    label: 'More Actions',
    children: [
      { label: 'Action 1', handler: () => console.log('Action 1') },
      { label: 'Action 2', handler: () => console.log('Action 2') }
    ]
  }
]
</script>

React

  1. Import and use in your component:
import { useContextMenu, ContextMenu } from 'context-menu-plugin/react'

function App() {
  const { showContextMenu, ...menuProps } = useContextMenu()

  const menuItems = [
    { label: 'Copy', onClick: () => console.log('Copy') },
    { label: 'Paste', onClick: () => console.log('Paste') },
    { type: 'separator' },
    {
      label: 'More Actions',
      children: [
        { label: 'Action 1', onClick: () => console.log('Action 1') },
        { label: 'Action 2', onClick: () => console.log('Action 2') }
      ]
    }
  ]

  return (
    <div onContextMenu={(e) => showContextMenu(e, menuItems)}>
      Right click here
      <ContextMenu {...menuProps} />
    </div>
  )
}

Advanced Features

Context-Aware Menus

The plugin can automatically adjust menu items based on the right-clicked element.

Vue 3:

<template>
  <img v-contextmenu="{ contextAware: true }" src="image.jpg" />
  <a v-contextmenu="{ contextAware: true }" href="https://example.com">Link</a>
</template>

React:

import { createContextAwareHandler } from 'context-menu-plugin/react'

function App() {
  const { showContextMenu, ...menuProps } = useContextMenu()
  const handleContextAware = createContextAwareHandler(showContextMenu)

  return (
    <>
      <img onContextMenu={handleContextAware} src="image.jpg" />
      <a onContextMenu={handleContextAware} href="https://example.com">Link</a>
      <ContextMenu {...menuProps} />
    </>
  )
}

Themes

You can use built-in themes or create custom themes.

Vue 3:

<template>
  <div v-contextmenu="{ items: menuItems, theme: 'dark' }">
    Dark theme menu
  </div>
</template>

React:

showContextMenu(e, menuItems, { theme: 'dark' })

Position Configuration

Control menu positioning with various options:

const positionConfig = {
  boundary: true,          // Enable boundary detection
  offset: 10,             // Offset from edges
  placement: 'bottom',     // Preferred placement
  fixed: false            // Use fixed positioning
}

Vue 3:

<template>
  <div v-contextmenu="{ items: menuItems, position: positionConfig }">
    Custom position
  </div>
</template>

React:

showContextMenu(e, menuItems, positionConfig)

Menu Item Types

interface MenuItem {
  label: string | VNode          // Menu item label
  handler?: () => void          // Click handler (Vue)
  onClick?: () => void          // Click handler (React)
  disabled?: boolean            // Disable the item
  type?: 'normal' | 'separator' // Item type
  children?: MenuItem[]         // Submenu items
  icon?: string | ReactNode     // Item icon
  shortcut?: string            // Keyboard shortcut display
}

Styling

Built-in Themes

  • light (default)
  • dark
  • blue
  • green

Custom Styling

Using CSS Variables:

:root {
  --cm-bg-color: white;
  --cm-text-color: black;
  --cm-border-color: #ddd;
  --cm-hover-bg: #f5f5f5;
  --cm-disabled-opacity: 0.5;
}

CSS Classes

  • .context-menu - Main container
  • .cm-item - Menu item
  • .cm-separator - Separator line
  • .cm-disabled - Disabled item
  • .cm-submenu - Submenu container
  • .cm-theme-{name} - Theme specific class

API Reference

Vue 3 Directive

v-contextmenu="config"

interface Config {
  items?: MenuItem[]
  theme?: string
  position?: PositionConfig
  contextAware?: boolean
}

React Hook

const {
  visible: boolean,
  position: { x: number, y: number },
  items: MenuItem[],
  showContextMenu: (e: Event, items?: MenuItem[], config?: Config) => void,
  hideContextMenu: () => void,
  menuRef: React.RefObject
} = useContextMenu(options?: {
  theme?: string
})

Browser Support

  • Chrome >= 60
  • Firefox >= 55
  • Safari >= 12.1
  • Edge >= 79

Accessibility

The plugin follows WAI-ARIA guidelines:

  • Proper ARIA roles
  • Keyboard navigation
  • Focus management
  • Screen reader support

TypeScript Support

The plugin includes TypeScript definitions for all features.