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 🙏

© 2024 – Pkg Stats / Ryan Hefner

context-menu-plus

v1.0.0

Published

A browser's context menu library.

Downloads

7

Readme

context-menu-plus

A browser's context menu library.

Install

  • Using npm
npm install context-menu-plus --save
  • Using yarn
yarn add context-menu-plus
  • Using pnpm
pnpm add context-menu-plus

Usage

Basic Usage

import { ContextMenu } from 'context-menu-plus'
const menu = new ContextMenu(document, [
  {
    id: '1', // required
    label: 'First Item'
  },
  {
    id: '2', // required
    label: 'Second Item'
  }
], (id) => {
  console.log(id)
})

Arguments

  • targetEl
    • Type: HTMLELement | HTMLDocument
    • Description: target element instance
    • Required: true
  • menuList
    • Type: MenuItem[] | MenuFun
    • Description: Can be an array or function, default is [].
    • Required: false
  • callback
    • Type: (id: string, data: any) => void
    • Description: Click the callback function of item, default is undefined.
    • Required: false
  • styles
    • Type: ContextMenuStyle
    • Description: context menu style.
    • Required: false

Methods

  • show(): Show context menu.
  • hide(): Hide context menu
  • update(): update context menu list.
  • destroy(): remove context menu eventListener and element.

Advanced Usage

Dynamically generate a menuList

import { ContextMenu } from 'context-menu-plus'
const menu = new ContextMenu(document, (ev) => {
  return [{
    id: '1', // required
    label: `x: ${ev.clientX} y: ${ev.clientY}`
  }]
}, (id) => {
  console.log(id)
})

Return extra data

import { ContextMenu } from 'context-menu-plus'
const menu = new ContextMenu(document, [
  {
    id: '1', // required
    label: 'First Item',
    data: {
      userId: 'Tom'
    }
  },
  {
    id: '2', // required
    label: 'Second Item',
    data: {
      userId: 'Lily'
    }
  }
], (id,data) => {
  console.log(id, data)
})

Used in Vue3

<script setup lang="ts">
import { ContextMenu } from 'context-menu-plus'

const menu = new ContextMenu(document, [
  {
    id: '1', // required
    label: 'First Item'
  },
  {
    id: '2', // required
    label: 'Second Item'
  }
], (id) => {
  console.log(id)
})

</script>

Used in Vue2

<script>
import { ContextMenu } from 'context-menu-plus'

export default {
  created() {
    const menu = new ContextMenu(document, [
      {
        id: '1', // required
        label: 'First Item'
      },
      {
        id: '2', // required
        label: 'Second Item'
      }
    ], (id) => {
      console.log(id)
    })
  }
}
</script>

Used in browsers

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
  <canvas width="500" height="500" id="myCanvas"></canvas>
  <script src="./fabric.min.js"></script>
  <script src="./dist/index.umd.js"></script>
  <script>
    const menu = new contextMenuPlus.ContextMenu(document, [
      {
        id: '1', // required
        label: 'First Item'
      },
      {
        id: '2', // required
        label: 'Second Item'
      }
    ], (id) => {
      console.log(id)
    })
  </script>
</body>
</html>