contextmenu
Advanced tools
Comparing version 0.0.1 to 0.0.3
{ | ||
"name": "contextmenu", | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"description": "A simple context menu for JavaScript", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build-publish": "sh build/publish.sh" | ||
}, | ||
@@ -22,3 +23,9 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/inker/contextmenu#readme" | ||
} | ||
"homepage": "https://github.com/inker/contextmenu#readme", | ||
"dependencies": { | ||
"lodash": "^4.17.4" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^2.1.6" | ||
} | ||
} |
@@ -1,10 +0,10 @@ | ||
# bim | ||
# contextmenu | ||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] | ||
A bidirectional map based on the ES6 Map object containing additional methods to retrive keys by values, delete key-value pairs by values and check the existence of keys by values. The module contains two classes: `BiMap` & `WeakBiMap` based on `Map` & `WeakMap` respectively. | ||
A simple context menu for JavaScript | ||
## Installation | ||
``` | ||
npm install --save bim | ||
npm install --save contextmenu | ||
``` | ||
@@ -15,38 +15,13 @@ | ||
```javascript | ||
import { WeakBiMap } from 'bim' | ||
import ContextMenu from 'contextmenu' | ||
// create objects to use as keys | ||
const a = { | ||
i: 'foo', | ||
j: 8, | ||
} | ||
const b = { | ||
k: 'bar', | ||
p: 11, | ||
} | ||
// create the bidirectional weak map | ||
const wbm = new WeakBiMap() | ||
wbm.set(a, 5) | ||
wbm.set(b, 6) | ||
wbm.deleteValue(5) // now only has { k: 'bar', p: 11 } => 6 | ||
wbm.hasValue(5) // false | ||
const c = { | ||
h: 'quux', | ||
z: 100, | ||
} | ||
wbm.set(c, 7) | ||
wbm.hasValue(7) // true | ||
wbm.getKey(7) // { h: 'quux', z: 100 } | ||
// TODO | ||
``` | ||
[npm-url]: https://npmjs.org/package/bim | ||
[downloads-image]: http://img.shields.io/npm/dm/bim.svg | ||
[npm-image]: http://img.shields.io/npm/v/bim.svg | ||
[david-dm-url]:https://david-dm.org/inker/bim | ||
[david-dm-image]:https://david-dm.org/inker/bim.svg | ||
[david-dm-dev-url]:https://david-dm.org/inker/bim#info=devDependencies | ||
[david-dm-dev-image]:https://david-dm.org/inker/bim/dev-status.svg | ||
[npm-url]: https://npmjs.org/package/contextmenu | ||
[downloads-image]: http://img.shields.io/npm/dm/contextmenu.svg | ||
[npm-image]: http://img.shields.io/npm/v/contextmenu.svg | ||
[david-dm-url]:https://david-dm.org/inker/contextmenu | ||
[david-dm-image]:https://david-dm.org/inker/contextmenu.svg | ||
[david-dm-dev-url]:https://david-dm.org/inker/contextmenu#info=devDependencies | ||
[david-dm-dev-image]:https://david-dm.org/inker/contextmenu/dev-status.svg |
@@ -1,6 +0,3 @@ | ||
import * as L from 'leaflet' | ||
import { remove } from 'lodash' | ||
import { translate } from '../../i18n' | ||
import * as style from './style.css' | ||
@@ -21,3 +18,2 @@ | ||
export default class implements L.ILayer { | ||
private map: L.Map | ||
private readonly items: ContextMenuItem[] | ||
@@ -38,9 +34,3 @@ private readonly container: HTMLDivElement | ||
addTo(map: L.Map) { | ||
this.onAdd(map) | ||
return this | ||
} | ||
onAdd(map: L.Map) { | ||
this.map = map | ||
add() { | ||
if (map === undefined) { | ||
@@ -63,10 +53,6 @@ throw new Error('cannot add map editor to metro map: leaflet map is missing') | ||
onRemove(map: L.Map) { | ||
// TODO | ||
} | ||
private handler(event: MouseEvent) { | ||
event.preventDefault() | ||
console.log('target', event.target, event.target['parentNode']) | ||
removeAllChildren(this.container) | ||
this.container.innerHTML = '' | ||
for (const item of this.items) { | ||
@@ -83,3 +69,3 @@ if (item.trigger !== undefined && !item.trigger(event.target)) { | ||
} | ||
cell.textContent = translate(item.text) | ||
cell.textContent = item.text | ||
this.container.appendChild(cell) | ||
@@ -94,3 +80,2 @@ } | ||
this.hide() | ||
this.map.fireEvent(eventType, { clientX, clientY, relatedTarget: event.target }) | ||
} | ||
@@ -107,4 +92,4 @@ } | ||
insertItem<K extends keyof MetroMapEventMap>( | ||
event: K, | ||
insertItem( | ||
event: string, | ||
text: string, | ||
@@ -123,6 +108,3 @@ trigger?: (target: EventTarget) => boolean, | ||
removeItem<K extends keyof MetroMapEventMap>( | ||
event: K, | ||
all = false, | ||
) { | ||
removeItem(event: string, all = false) { | ||
if (all) { | ||
@@ -129,0 +111,0 @@ remove(this.items, item => item.event === event) |
18624
1
1
361
27
+ Addedlodash@^4.17.4
+ Addedlodash@4.17.21(transitive)