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

nw-menu

v0.1.1

Published

Rapidly create menus in NW.js with dot-notated indexing for every single item.

Downloads

6

Readme

nw-menu

Rapidly create menus in NW.js with dot-notated indexing for every single item.

Install

$ npm install --save nw-menu

Core dependency is NW.js.

API

Constructor

const nwMenu = require('nw-menu');
var appMenu = new nwMenu(map, option);

map is the object containing tree of menu items. Self-references are set into _meta. They must be formatted as well as nw.MenuItem. Other properties are children items and their keys can be used in dot-notation syntax to identify needed MenuItems.

Example map object:

{
	test: {
		_meta: { label: 'Your caption here...' },
	},
	copy: {
		_meta: { label: 'Copy', key: 'C', modifiers: 'ctrl' },
	},
	paste: {
		_meta: { label: 'Paste', key: 'V', modifiers: 'ctrl' },
	},
	menu: {
		_meta: { label: '1st menu' },
		menu: {
			_meta: { label: '2nd menu' },
			menu: {
				_meta: { label: '3rd menu', click: function() { alert('Clicked on 3rd item'); } }
			}
		}
	}
}

option is the object that is used in initial nw.Menu call to specify the type of menu. If you want to use menu as menubar, type this:

{ type: 'menubar' }

If you ignore option you'll get contextmenu anyway.

Usage example

Creating menubar:

const nwMenu = require('nw-menu');
var appMenu = new nwMenu({
	file: {
		_meta: { label: 'File' },
		new_: { _meta: { label: 'New', key: 'N', modifiers: 'ctrl' } },
		open: { _meta: { label: 'Open', key: 'O', modifiers: 'ctrl' } },
		save: { _meta: { label: 'Save', key: 'S', modifiers: 'ctrl' } },
		saveAs: { _meta: { label: 'Save as...', key: 'S', modifiers: 'ctrl+shift' } },
		_print: '_',
		print: { _meta: { label: 'Print', key: 'P', modifiers: 'ctrl' } },
		_quit: '_',
		quit: { _meta: { label: 'Quit', click: function() { require('process').exit(0); } } },
	},
	window: {
		_meta: { label: 'Window' },
		console: { _meta: { type: 'checkbox', label: 'Console' } },
		properties: { _meta: { type: 'checkbox', label: 'Properties' } }
	}
}, { type: 'menubar' });

Bind menubar to NW.js window:

nw.Window.get().menu = appMenu.bar();

String with underscore ('_') as value is used for separator:

	_section1: '_'
	// It's same as:
	_section1: { _meta: { type: 'separator' } }

Time for something hot. Let's disable save button:

	appMenu.getItem('file.save').enabled = false;

nwMenu.getItem returns MenuItem object associated with specified item.

Now add click callback for some of checkbox items to check switching states:

	...
	console: { _meta: { type: 'checkbox', label: 'Console', click: function() {
		if (appMenu.getItem('window.console').checked) alert('Switching console on...');
		else alert('Closing console...');
	} } },
	...

Needs testing

You can pop up any of context subMenus created by nwMenu:

appMenu.getSubMenu('window').popup(0, 0);

(However, popup method has issues on my side: I don't know why it's crashing app.)