ol-contextmenu 5.3.0 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/helpers/dom.d.ts +1 -1
- package/dist/main.d.ts +10 -10
- package/dist/ol-contextmenu.css +3 -3
- package/dist/ol-contextmenu.iife.js +3 -3
- package/dist/ol-contextmenu.js +5 -7
- package/dist/ol-contextmenu.umd.cjs +3 -3
- package/dist/types.d.ts +3 -3
- package/package.json +21 -20
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
</a>
|
|
16
16
|
</p>
|
|
17
17
|
|
|
18
|
-
A `contextmenu` extension for [OpenLayers](http://openlayers.org/). **Requires** OpenLayers **
|
|
18
|
+
A `contextmenu` extension for [OpenLayers](http://openlayers.org/). **Requires** OpenLayers **v7.0.0** or higher.
|
|
19
19
|
|
|
20
20
|

|
|
21
21
|
|
package/dist/constants.d.ts
CHANGED
package/dist/helpers/dom.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TinyEmitter } from 'tiny-emitter';
|
|
2
|
-
import {
|
|
2
|
+
import { Item } from '../types';
|
|
3
3
|
export declare function createFragment(html: string): DocumentFragment;
|
|
4
4
|
export declare function getLineHeight(container: HTMLDivElement): number;
|
|
5
5
|
export declare function addMenuEntry({ parentNode, item, isSubmenu, isInsideSubmenu, emitter, }: {
|
package/dist/main.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import Control from 'ol/control/Control';
|
|
1
|
+
import { default as OlMap } from 'ol/Map';
|
|
2
|
+
import { Pixel } from 'ol/pixel';
|
|
3
|
+
import { EventsKey } from 'ol/events';
|
|
4
|
+
import { default as BaseEvent } from 'ol/events/Event';
|
|
5
|
+
import { ObjectEvent } from 'ol/Object';
|
|
6
|
+
import { Coordinate } from 'ol/coordinate';
|
|
7
|
+
import { Types as ObjectEventTypes } from 'ol/ObjectEventType';
|
|
8
|
+
import { CombinedOnSignature, EventTypes as OlEventTypes, OnSignature } from 'ol/Observable';
|
|
9
|
+
import { default as Control } from 'ol/control/Control';
|
|
10
10
|
import { TinyEmitter } from 'tiny-emitter';
|
|
11
11
|
import { Item, Options, MenuEntry, ContextMenuEvent, CustomEventTypes } from './types';
|
|
12
12
|
export default class ContextMenu extends Control {
|
|
@@ -31,7 +31,7 @@ export default class ContextMenu extends Control {
|
|
|
31
31
|
clear(): void;
|
|
32
32
|
enable(): void;
|
|
33
33
|
disable(): void;
|
|
34
|
-
getDefaultItems(): import(
|
|
34
|
+
getDefaultItems(): import('./types').SingleItem[];
|
|
35
35
|
countItems(): number;
|
|
36
36
|
extend(items: Item[]): void;
|
|
37
37
|
closeMenu(): void;
|
package/dist/ol-contextmenu.css
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.
|
|
3
|
+
* ol-contextmenu - v5.5.0
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built:
|
|
5
|
+
* Built: Wed Aug 07 2024 12:29:18 GMT+0000 (Coordinated Universal Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
.ol-ctx-menu-container{position:absolute;padding:8px;background:#fff;color:#222;font-size:13px;border-radius:5px;box-shadow:#0003 3px 3px 5px;box-sizing:border-box}.ol-ctx-menu-container div,.ol-ctx-menu-container span,.ol-ctx-menu-container a,.ol-ctx-menu-container img,.ol-ctx-menu-container ul,.ol-ctx-menu-container li{margin:0;padding:0;border:0;font:inherit;font-size:100%;vertical-align:baseline}.ol-ctx-menu-container a img{border:none}.ol-ctx-menu-container *,.ol-ctx-menu-container *:before,.ol-ctx-menu-container *:after{box-sizing:inherit}.ol-ctx-menu-container.ol-ctx-menu-hidden{opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container ul{list-style:none}.ol-ctx-menu-container li{position:relative;line-height:20px;padding:2px 5px;white-space:nowrap}.ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover{cursor:pointer;background-color:#333;color:#eee}.ol-ctx-menu-container li.ol-ctx-menu-submenu .ol-ctx-menu-container{border:1px solid #eee;padding:8px;top:0;opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container li.ol-ctx-menu-submenu:after{position:absolute;top:7px;right:10px;content:"";display:inline-block;width:.6em;height:.6em;border-right:.3em solid #222;border-top:.3em solid #222;transform:rotate(45deg)}.ol-ctx-menu-container li.ol-ctx-menu-submenu:hover:after{border-color:#eee}.ol-ctx-menu-container:not(.ol-ctx-menu-hidden) li.ol-ctx-menu-submenu:hover>.ol-ctx-menu-container{opacity:1;visibility:visible;transition-delay:0s}.ol-ctx-menu-container li.ol-ctx-menu-separator{padding:0}.ol-ctx-menu-container li.ol-ctx-menu-separator hr{border:0;height:1px;background-image:linear-gradient(to left
|
|
8
|
+
.ol-ctx-menu-container{position:absolute;padding:8px;background:#fff;color:#222;font-size:13px;border-radius:5px;box-shadow:#0003 3px 3px 5px;box-sizing:border-box}.ol-ctx-menu-container div,.ol-ctx-menu-container span,.ol-ctx-menu-container a,.ol-ctx-menu-container img,.ol-ctx-menu-container ul,.ol-ctx-menu-container li{margin:0;padding:0;border:0;font:inherit;font-size:100%;vertical-align:baseline}.ol-ctx-menu-container a img{border:none}.ol-ctx-menu-container *,.ol-ctx-menu-container *:before,.ol-ctx-menu-container *:after{box-sizing:inherit}.ol-ctx-menu-container.ol-ctx-menu-hidden{opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container ul{list-style:none}.ol-ctx-menu-container li{position:relative;line-height:20px;padding:2px 5px;white-space:nowrap}.ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover{cursor:pointer;background-color:#333;color:#eee}.ol-ctx-menu-container li.ol-ctx-menu-submenu .ol-ctx-menu-container{border:1px solid #eee;padding:8px;top:0;opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container li.ol-ctx-menu-submenu:after{position:absolute;top:7px;right:10px;content:"";display:inline-block;width:.6em;height:.6em;border-right:.3em solid #222;border-top:.3em solid #222;transform:rotate(45deg)}.ol-ctx-menu-container li.ol-ctx-menu-submenu:hover:after{border-color:#eee}.ol-ctx-menu-container:not(.ol-ctx-menu-hidden) li.ol-ctx-menu-submenu:hover>.ol-ctx-menu-container{opacity:1;visibility:visible;transition-delay:0s}.ol-ctx-menu-container li.ol-ctx-menu-separator{padding:0}.ol-ctx-menu-container li.ol-ctx-menu-separator hr{border:0;height:1px;background-image:linear-gradient(to left,#0000,#000000bf,#0000)}.ol-ctx-menu-icon{text-indent:20px;background-size:20px auto;background-repeat:no-repeat;background-position:left center}.ol-ctx-menu-zoom-in{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABaUlEQVQ4T72U7VHCQBCGn90GtAMuNGCswFiBWIFQgWMFxg6wArECsQKhArEBiB1Qwa1zgQn5IAYcxv13k71n3919L8KJQ07M47+BzgG9TRfZ/JBuWhS6BJFHRJICYrZGZIz3z5Ct2+B7gG6I6kt+wewdkQVwjtkAkR5mC8yu26A1oItR/cTsOweQBdgutD8G7jGm2PJ2n8oqUKIpIjd4HxTM8gvaT/F+AlmWnyWaIXKF95eNguFzTYFhNsdWu9kFgFlaFMANUH3D8wDLoLgSTSD2il8NCe2ZXQBxWDGwxmyUzzOMBZ7wy7Qb2K0wQfXjMOBuhlFpZtNty5sFaTQBuTusZdymeqs1SpYKcO9HkE3KbTd9WFijMHJQ5hBNEAYNq5Qd0dhyke0GiE4QzjqfW23mHT8Hl4DG4Lce3FPE7AtbBSdsbNqpoJLgYkRnNeUV+xwJDHTnUEkxHGbhBXUs5TjJjew/KPy94g+NRaIVRYmMXwAAAABJRU5ErkJggg==)}.ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-in{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABc0lEQVQ4T71U21ECQRDsJgGdvQDECMQIxAjECMQILCPwzAAjECIQI0AiEDPQAPaWCBhrcKHuCUcV5f7dY3v6tUscefHIePhfwBBCF8CZqRCReRs1tQxDCH1VfQLQz4EsSY4AvIjIsgm8AhhCGKrqa9zwrqoLAKckB5HtguR1E2gBMITQU9VPAD8GICIGtl3e+xHJBwBT59xtHcsCYJZlUwA3kcGHbfDep51OZywi3/acZZm9vyJ5WR5o38uACmDunNt6ZwAkUxFZDwghDFT1jeSjiJinhVUBVNVJkiTDKO8CQA+AsbNQ7s1Ps0VVn5MkSfcCtmBoDZi1Bdx4eJ7zbBolrwPy3o9J3rWSHPs3A1BbjVKlYBaIyDgvu9LDXDU2RTZmXVW1oKyLxRD+OrkOrJLy5mVM0iaftDhuhVbsvBzMglzKUNW6IV/OOWtCM8MmVvEkmbwt83LaB19fdgOtVquUZJeknaDdobTwbOcvBzPcN/AXH1DFFWP7u9oAAAAASUVORK5CYII=)}.ol-ctx-menu-zoom-out{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABU0lEQVQ4T72U7VECMRRFz3sNaAdkacC1AtcKxApcKnCsQOwAK3CtQKxAqEBsANYOqCDPyTIC+8WCw5jfybn33dxEOPGSE/P4b6BzQG89RT47ZJoWhy5B5BGRZAMxWyEyxvtnyFdt8AagS1F9KQ6YvSMyB84xGyDSw2yO2XUbtAJ0MaqfmH0XAPIA2y7tj4F7jAm2uG1yWQZKNEHkBu+Dg2njWBJNEbnC+8uaIFRuWfuG2QxbbrOrUd0A1Tc8D7AIjkur7DAAsVf8MiWMZ3ZR2m02LPIMscATfjHqBnY7TFD9OAy4zTCCPG/MUKMM5O6wkXFr9dZq7FQqqHk/hDzbFa73cFONTZFDdRyiCcKg5rrSiLaXkiI6RjjrfG6VzDs+B5eAxuDXeYpmNRGzL2wZ/wof+du4GNFpBVqqz5HA4MM5VEYYDrOs+1I6Q9u/4Q8O9wN/AGgWjBVqQjjgAAAAAElFTkSuQmCC)}.ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-out{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABYklEQVQ4T72U4VHCQBCF36tA91KAWIFYgViBWIFYgWMFYgdYgVCBWAFSgdiBFpAsFWSdxcDkQoBkhnF/ZjbfvX377ogjF4/Mw/8CVbUD4MynEJF5k2lqFapqz8yeAPRKkCXJEYAXEVnugm8BVXVgZq/FD+9mtgBwSrJfqF2QvN4FjYCq2jWzTwA/DhARh20qTdMRyQcA0xDCbZ3KCJhl2RTATaHgo+6HLMv8+xXJy+qB3l8FGoB5CKHsXcRV1b6ZvZF8FBH3NKotoJlNkiQZFONdlLtJ3rufbouZPSdJMjwIbKDQEzBrClx7eC4i33Uepmk6JnnXaOQifzMAtdGoRApugYiMI1uqKkrRWAfZo9MxM1+UZzFewl8mN4nYdVM83L7BkwbXLUrF3sfBLQDQBbDy08x8vOohXyEE71lVq9emuEk+3gZa3XYroCvwFyjP8yHJDsnxwaU08GxvS2uFhw78BbzWrxXgMbsHAAAAAElFTkSuQmCC)}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.
|
|
3
|
+
* ol-contextmenu - v5.5.0
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built:
|
|
5
|
+
* Built: Wed Aug 07 2024 12:29:18 GMT+0000 (Coordinated Universal Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
var ContextMenu=function(
|
|
8
|
+
var ContextMenu=function(f,h){"use strict";var P=Object.defineProperty;var H=(f,h,E)=>h in f?P(f,h,{enumerable:!0,configurable:!0,writable:!0,value:E}):f[h]=E;var a=(f,h,E)=>H(f,typeof h!="symbol"?h+"":h,E);var E={exports:{}};function x(){}x.prototype={on:function(s,t,e){var n=this.e||(this.e={});return(n[s]||(n[s]=[])).push({fn:t,ctx:e}),this},once:function(s,t,e){var n=this;function o(){n.off(s,o),t.apply(e,arguments)}return o._=t,this.on(s,o,e)},emit:function(s){var t=[].slice.call(arguments,1),e=((this.e||(this.e={}))[s]||[]).slice(),n=0,o=e.length;for(n;n<o;n++)e[n].fn.apply(e[n].ctx,t);return this},off:function(s,t){var e=this.e||(this.e={}),n=e[s],o=[];if(n&&t)for(var i=0,l=n.length;i<l;i++)n[i].fn!==t&&n[i].fn._!==t&&o.push(n[i]);return o.length?e[s]=o:delete e[s],this}},E.exports=x;var T=E.exports.TinyEmitter=x,L=(s=>(s.CONTEXTMENU="contextmenu",s.CLICK="click",s.DBLCLICK="dblclick",s))(L||{}),d=(s=>(s.BEFOREOPEN="beforeopen",s.OPEN="open",s.CLOSE="close",s.ADD_MENU_ENTRY="add-menu-entry",s))(d||{});class S extends h{constructor(t){super(t.type,t.map,t.originalEvent)}}const k={width:150,scrollAt:4,eventType:L.CONTEXTMENU,defaultItems:!0,items:[]},p="ol-ctx-menu",r={namespace:p,container:`${p}-container`,separator:`${p}-separator`,submenu:`${p}-submenu`,hidden:`${p}-hidden`,icon:`${p}-icon`,zoomIn:`${p}-zoom-in`,zoomOut:`${p}-zoom-out`,unselectable:"ol-unselectable"},A=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(s,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:s.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(s,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:s.coordinate})}}];function b(s){const t=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=s;e.firstChild;)t.append(e.firstChild);return t}function I(s){const t=document.importNode(s),e=s.offsetWidth;t.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const n=b("<span>Foo</span>"),o=b("<span>Foo</span>"),i=document.createElement("li"),l=document.createElement("li");i.append(n),l.append(o),t.append(i),t.append(l),s.parentNode?.append(t);const c=t.offsetHeight/2;return s.parentNode?.removeChild(t),c}function $({parentNode:s,item:t,isSubmenu:e=!1,isInsideSubmenu:n=!1,emitter:o}){const i=`_${Math.random().toString(36).slice(2,11)}`;if(typeof t!="string"&&"text"in t){const v=`<span>${t.text}</span>`,g=b(v),m=document.createElement("li");t.classname=t.classname||"",t.icon&&(t.classname===""?t.classname=r.icon:t.classname.includes(r.icon)===!1&&(t.classname+=` ${r.icon}`),m.setAttribute("style",`background-image:url(${t.icon})`)),m.id=i,m.className=t.classname,m.append(g),s.append(m);const N={id:i,isSubmenu:e,isInsideSubmenu:n,isSeparator:!1,callback:"callback"in t?t.callback:null,data:"data"in t?t.data:null};return o.emit(d.ADD_MENU_ENTRY,N,m),m}const l=`<li id="${i}" class="${r.separator}"><hr></li>`,c=b(l);s.append(c);const y=s.lastChild,M={id:i,isSubmenu:!1,isInsideSubmenu:!1,isSeparator:!0,callback:null,data:null};return o.emit(d.ADD_MENU_ENTRY,M,y),y}function w({container:s,items:t,menuWidth:e,isInsideSubmenu:n,emitter:o}){t.forEach(i=>{if(typeof i!="string"&&"items"in i&&Array.isArray(i.items)){const l=$({parentNode:s,item:i,isSubmenu:!0,emitter:o});l.classList.add(r.submenu);const c=document.createElement("ul");c.classList.add(r.container),c.style.width=`${e}px`,l.append(c),w({emitter:o,menuWidth:e,container:c,items:i.items,isInsideSubmenu:!0})}else $({parentNode:s,item:i,isSubmenu:!1,isInsideSubmenu:n,emitter:o})})}function C(s,t){if(!s)throw new Error(t)}class O extends f{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const n=document.createElement("div");super({element:n});a(this,"map");a(this,"emitter",new T);a(this,"container");a(this,"coordinate",[]);a(this,"pixel",[]);a(this,"contextMenuEventListener");a(this,"entryCallbackEventListener");a(this,"mapMoveListener");a(this,"lineHeight",0);a(this,"disabled");a(this,"opened");a(this,"items",[]);a(this,"menuEntries",new Map);a(this,"options");this.options={...k,...e};const o=document.createElement("ul");n.append(o),n.style.width=`${this.options.width}px`,n.classList.add(r.container,r.unselectable,r.hidden),this.container=n,this.contextMenuEventListener=i=>{this.handleContextMenu(i)},this.entryCallbackEventListener=i=>{this.handleEntryCallback(i)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener("beforeunload",()=>{this.removeListeners()},{once:!0})}clear(){for(const e of this.menuEntries.keys())this.removeMenuEntry(e);this.container.replaceChildren(),this.container.append(document.createElement("ul"))}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return A}countItems(){return this.menuEntries.size}extend(e){C(Array.isArray(e),"@param `items` should be an Array."),w({items:e,emitter:this.emitter,menuWidth:this.options.width,container:this.container.firstElementChild})}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(d.CLOSE)}isOpen(){return this.opened}updatePosition(e){C(Array.isArray(e),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=e,this.positionContainer())}pop(){const e=Array.from(this.menuEntries.keys()).pop();e&&this.removeMenuEntry(e)}shift(){const e=Array.from(this.menuEntries.keys()).shift();e&&this.removeMenuEntry(e)}push(e){e&&this.extend([e])}setMap(e){if(super.setMap(e),e){this.map=e,e.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),e.on("movestart",()=>{this.handleMapMove()}),this.emitter.on(d.ADD_MENU_ENTRY,(o,i)=>{this.handleAddMenuEntry(o,i)},this),this.items=this.options.defaultItems?this.options.items.concat(A):this.options.items,w({items:this.items,emitter:this.emitter,menuWidth:this.options.width,container:this.container.firstElementChild});const n=this.getMenuEntriesLength();this.lineHeight=n>0?this.container.offsetHeight/n:I(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.emitter.off(d.ADD_MENU_ENTRY)}removeMenuEntry(e){let n=document.getElementById(e);n?.remove(),n=null,this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent(new S({map:this.map,originalEvent:e,type:d.BEFOREOPEN})),!this.disabled&&(this.options.eventType===L.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)}),e.target?.addEventListener("pointerdown",n=>{this.opened&&(n.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new S({map:this.map,originalEvent:e,type:d.OPEN}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1&&e.isSubmenu===!1&&e.isInsideSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],n={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},o=this.getMenuEntriesLength(),i={w:this.container.offsetWidth,h:Math.round(this.lineHeight*o)},l=n.w>=i.w?this.pixel[0]+5:this.pixel[0]-i.w;this.container.style.left=`${l}px`,this.container.style.top=n.h>=i.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-i.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",n.w-=i.w;const c=v=>Array.from(v.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let y=0;const M=(v,g)=>{y+=1,c(v).forEach(N=>{const D=g>=i.w?i.w-8:(i.w+8)*-1,u=N.querySelector(`ul.${r.container}`),_=Math.round(this.lineHeight*Array.from(u.children).filter(z=>z.tagName==="LI").length);u.style.left=`${D}px`,u.style.right="auto",u.style.top=n.h>=_+i.h?"0":`-${u.offsetHeight-25}px`,u.style.bottom="auto",u.style.zIndex=String(y),c(u).length>0&&M(u,g-i.w)})};M(this.container.firstElementChild,n.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const n=e.currentTarget,o=this.menuEntries.get(n.id);if(!o)return;const i={data:o.data,coordinate:this.coordinate};this.closeMenu(),o.callback?.(i,this.map)}handleAddMenuEntry(e,n){this.menuEntries.set(e.id,e),this.positionContainer(),"callback"in e&&typeof e.callback=="function"&&n.addEventListener("click",this.entryCallbackEventListener,!1)}}return O}(ol.control.Control,ol.MapBrowserEvent);
|
package/dist/ol-contextmenu.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.
|
|
3
|
+
* ol-contextmenu - v5.5.0
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built:
|
|
5
|
+
* Built: Wed Aug 07 2024 12:29:18 GMT+0000 (Coordinated Universal Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
var k = Object.defineProperty;
|
|
9
9
|
var I = (n, t, e) => t in n ? k(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
10
|
-
var a = (n, t, e) =>
|
|
10
|
+
var a = (n, t, e) => I(n, typeof t != "symbol" ? t + "" : t, e);
|
|
11
11
|
import O from "ol/control/Control";
|
|
12
12
|
import D from "ol/MapBrowserEvent";
|
|
13
13
|
var S = { exports: {} };
|
|
@@ -168,8 +168,7 @@ function M({
|
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
function b(n, t) {
|
|
171
|
-
if (!n)
|
|
172
|
-
throw new Error(t);
|
|
171
|
+
if (!n) throw new Error(t);
|
|
173
172
|
}
|
|
174
173
|
class R extends O {
|
|
175
174
|
constructor(e = {}) {
|
|
@@ -351,8 +350,7 @@ class R extends O {
|
|
|
351
350
|
handleEntryCallback(e) {
|
|
352
351
|
e.preventDefault(), e.stopPropagation();
|
|
353
352
|
const s = e.currentTarget, o = this.menuEntries.get(s.id);
|
|
354
|
-
if (!o)
|
|
355
|
-
return;
|
|
353
|
+
if (!o) return;
|
|
356
354
|
const i = {
|
|
357
355
|
data: o.data,
|
|
358
356
|
coordinate: this.coordinate
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.
|
|
3
|
+
* ol-contextmenu - v5.5.0
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built:
|
|
5
|
+
* Built: Wed Aug 07 2024 12:29:18 GMT+0000 (Coordinated Universal Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
(function(l,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("ol/control/Control"),require("ol/MapBrowserEvent")):typeof define=="function"&&define.amd?define(["ol/control/Control","ol/MapBrowserEvent"],c):(l=typeof globalThis<"u"?globalThis:l||self,l.ContextMenu=c(l.ol.control.Control,l.ol.MapBrowserEvent))})(this,function(l,c){"use strict";var P=Object.defineProperty;var H=(l,c,
|
|
8
|
+
(function(l,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("ol/control/Control"),require("ol/MapBrowserEvent")):typeof define=="function"&&define.amd?define(["ol/control/Control","ol/MapBrowserEvent"],c):(l=typeof globalThis<"u"?globalThis:l||self,l.ContextMenu=c(l.ol.control.Control,l.ol.MapBrowserEvent))})(this,function(l,c){"use strict";var P=Object.defineProperty;var H=(l,c,E)=>c in l?P(l,c,{enumerable:!0,configurable:!0,writable:!0,value:E}):l[c]=E;var a=(l,c,E)=>H(l,typeof c!="symbol"?c+"":c,E);var E={exports:{}};function x(){}x.prototype={on:function(s,t,e){var n=this.e||(this.e={});return(n[s]||(n[s]=[])).push({fn:t,ctx:e}),this},once:function(s,t,e){var n=this;function o(){n.off(s,o),t.apply(e,arguments)}return o._=t,this.on(s,o,e)},emit:function(s){var t=[].slice.call(arguments,1),e=((this.e||(this.e={}))[s]||[]).slice(),n=0,o=e.length;for(n;n<o;n++)e[n].fn.apply(e[n].ctx,t);return this},off:function(s,t){var e=this.e||(this.e={}),n=e[s],o=[];if(n&&t)for(var i=0,h=n.length;i<h;i++)n[i].fn!==t&&n[i].fn._!==t&&o.push(n[i]);return o.length?e[s]=o:delete e[s],this}},E.exports=x;var T=E.exports.TinyEmitter=x,L=(s=>(s.CONTEXTMENU="contextmenu",s.CLICK="click",s.DBLCLICK="dblclick",s))(L||{}),p=(s=>(s.BEFOREOPEN="beforeopen",s.OPEN="open",s.CLOSE="close",s.ADD_MENU_ENTRY="add-menu-entry",s))(p||{});class S extends c{constructor(t){super(t.type,t.map,t.originalEvent)}}const k={width:150,scrollAt:4,eventType:L.CONTEXTMENU,defaultItems:!0,items:[]},m="ol-ctx-menu",r={namespace:m,container:`${m}-container`,separator:`${m}-separator`,submenu:`${m}-submenu`,hidden:`${m}-hidden`,icon:`${m}-icon`,zoomIn:`${m}-zoom-in`,zoomOut:`${m}-zoom-out`,unselectable:"ol-unselectable"},A=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(s,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:s.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(s,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:s.coordinate})}}];function M(s){const t=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=s;e.firstChild;)t.append(e.firstChild);return t}function I(s){const t=document.importNode(s),e=s.offsetWidth;t.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const n=M("<span>Foo</span>"),o=M("<span>Foo</span>"),i=document.createElement("li"),h=document.createElement("li");i.append(n),h.append(o),t.append(i),t.append(h),s.parentNode?.append(t);const u=t.offsetHeight/2;return s.parentNode?.removeChild(t),u}function $({parentNode:s,item:t,isSubmenu:e=!1,isInsideSubmenu:n=!1,emitter:o}){const i=`_${Math.random().toString(36).slice(2,11)}`;if(typeof t!="string"&&"text"in t){const v=`<span>${t.text}</span>`,g=M(v),f=document.createElement("li");t.classname=t.classname||"",t.icon&&(t.classname===""?t.classname=r.icon:t.classname.includes(r.icon)===!1&&(t.classname+=` ${r.icon}`),f.setAttribute("style",`background-image:url(${t.icon})`)),f.id=i,f.className=t.classname,f.append(g),s.append(f);const N={id:i,isSubmenu:e,isInsideSubmenu:n,isSeparator:!1,callback:"callback"in t?t.callback:null,data:"data"in t?t.data:null};return o.emit(p.ADD_MENU_ENTRY,N,f),f}const h=`<li id="${i}" class="${r.separator}"><hr></li>`,u=M(h);s.append(u);const y=s.lastChild,b={id:i,isSubmenu:!1,isInsideSubmenu:!1,isSeparator:!0,callback:null,data:null};return o.emit(p.ADD_MENU_ENTRY,b,y),y}function w({container:s,items:t,menuWidth:e,isInsideSubmenu:n,emitter:o}){t.forEach(i=>{if(typeof i!="string"&&"items"in i&&Array.isArray(i.items)){const h=$({parentNode:s,item:i,isSubmenu:!0,emitter:o});h.classList.add(r.submenu);const u=document.createElement("ul");u.classList.add(r.container),u.style.width=`${e}px`,h.append(u),w({emitter:o,menuWidth:e,container:u,items:i.items,isInsideSubmenu:!0})}else $({parentNode:s,item:i,isSubmenu:!1,isInsideSubmenu:n,emitter:o})})}function C(s,t){if(!s)throw new Error(t)}class O extends l{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const n=document.createElement("div");super({element:n});a(this,"map");a(this,"emitter",new T);a(this,"container");a(this,"coordinate",[]);a(this,"pixel",[]);a(this,"contextMenuEventListener");a(this,"entryCallbackEventListener");a(this,"mapMoveListener");a(this,"lineHeight",0);a(this,"disabled");a(this,"opened");a(this,"items",[]);a(this,"menuEntries",new Map);a(this,"options");this.options={...k,...e};const o=document.createElement("ul");n.append(o),n.style.width=`${this.options.width}px`,n.classList.add(r.container,r.unselectable,r.hidden),this.container=n,this.contextMenuEventListener=i=>{this.handleContextMenu(i)},this.entryCallbackEventListener=i=>{this.handleEntryCallback(i)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener("beforeunload",()=>{this.removeListeners()},{once:!0})}clear(){for(const e of this.menuEntries.keys())this.removeMenuEntry(e);this.container.replaceChildren(),this.container.append(document.createElement("ul"))}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return A}countItems(){return this.menuEntries.size}extend(e){C(Array.isArray(e),"@param `items` should be an Array."),w({items:e,emitter:this.emitter,menuWidth:this.options.width,container:this.container.firstElementChild})}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(p.CLOSE)}isOpen(){return this.opened}updatePosition(e){C(Array.isArray(e),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=e,this.positionContainer())}pop(){const e=Array.from(this.menuEntries.keys()).pop();e&&this.removeMenuEntry(e)}shift(){const e=Array.from(this.menuEntries.keys()).shift();e&&this.removeMenuEntry(e)}push(e){e&&this.extend([e])}setMap(e){if(super.setMap(e),e){this.map=e,e.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),e.on("movestart",()=>{this.handleMapMove()}),this.emitter.on(p.ADD_MENU_ENTRY,(o,i)=>{this.handleAddMenuEntry(o,i)},this),this.items=this.options.defaultItems?this.options.items.concat(A):this.options.items,w({items:this.items,emitter:this.emitter,menuWidth:this.options.width,container:this.container.firstElementChild});const n=this.getMenuEntriesLength();this.lineHeight=n>0?this.container.offsetHeight/n:I(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.emitter.off(p.ADD_MENU_ENTRY)}removeMenuEntry(e){let n=document.getElementById(e);n?.remove(),n=null,this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent(new S({map:this.map,originalEvent:e,type:p.BEFOREOPEN})),!this.disabled&&(this.options.eventType===L.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)}),e.target?.addEventListener("pointerdown",n=>{this.opened&&(n.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new S({map:this.map,originalEvent:e,type:p.OPEN}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1&&e.isSubmenu===!1&&e.isInsideSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],n={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},o=this.getMenuEntriesLength(),i={w:this.container.offsetWidth,h:Math.round(this.lineHeight*o)},h=n.w>=i.w?this.pixel[0]+5:this.pixel[0]-i.w;this.container.style.left=`${h}px`,this.container.style.top=n.h>=i.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-i.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",n.w-=i.w;const u=v=>Array.from(v.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let y=0;const b=(v,g)=>{y+=1,u(v).forEach(N=>{const D=g>=i.w?i.w-8:(i.w+8)*-1,d=N.querySelector(`ul.${r.container}`),_=Math.round(this.lineHeight*Array.from(d.children).filter(z=>z.tagName==="LI").length);d.style.left=`${D}px`,d.style.right="auto",d.style.top=n.h>=_+i.h?"0":`-${d.offsetHeight-25}px`,d.style.bottom="auto",d.style.zIndex=String(y),u(d).length>0&&b(d,g-i.w)})};b(this.container.firstElementChild,n.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const n=e.currentTarget,o=this.menuEntries.get(n.id);if(!o)return;const i={data:o.data,coordinate:this.coordinate};this.closeMenu(),o.callback?.(i,this.map)}handleAddMenuEntry(e,n){this.menuEntries.set(e.id,e),this.positionContainer(),"callback"in e&&typeof e.callback=="function"&&n.addEventListener("click",this.entryCallbackEventListener,!1)}}return O});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import MapBrowserEvent from 'ol/MapBrowserEvent';
|
|
1
|
+
import { default as OlMap } from 'ol/Map';
|
|
2
|
+
import { Coordinate } from 'ol/coordinate';
|
|
3
|
+
import { default as MapBrowserEvent } from 'ol/MapBrowserEvent';
|
|
4
4
|
export declare enum EventTypes {
|
|
5
5
|
CONTEXTMENU = "contextmenu",
|
|
6
6
|
CLICK = "click",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ol-contextmenu",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "Custom Context Menu for Openlayers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/ol-contextmenu.umd.cjs",
|
|
@@ -45,33 +45,34 @@
|
|
|
45
45
|
"lint": "eslint .",
|
|
46
46
|
"lint:fix": "npm run lint -- --fix",
|
|
47
47
|
"test": "jest",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
48
|
+
"prepare": "husky",
|
|
49
|
+
"release": "release-it --no-npm.publish"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@swc/core": "^1.
|
|
53
|
-
"@swc/jest": "^0.2.
|
|
54
|
-
"@types/jest": "^29.5.
|
|
55
|
-
"eslint": "^8.
|
|
56
|
-
"eslint-config-jwalker": "^8.
|
|
57
|
-
"eslint-config-prettier": "^9.
|
|
58
|
-
"eslint-plugin-jest": "^27.
|
|
59
|
-
"eslint-plugin-prettier": "^5.
|
|
60
|
-
"husky": "^
|
|
52
|
+
"@swc/core": "^1.7.6",
|
|
53
|
+
"@swc/jest": "^0.2.36",
|
|
54
|
+
"@types/jest": "^29.5.12",
|
|
55
|
+
"eslint": "^8.57.0",
|
|
56
|
+
"eslint-config-jwalker": "^8.8.0",
|
|
57
|
+
"eslint-config-prettier": "^9.1.0",
|
|
58
|
+
"eslint-plugin-jest": "^27.9.0",
|
|
59
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
60
|
+
"husky": "^9.1.4",
|
|
61
61
|
"identity-obj-proxy": "^3.0.0",
|
|
62
62
|
"jest": "^29.7.0",
|
|
63
63
|
"jest-environment-jsdom": "^29.7.0",
|
|
64
|
-
"ol": "^
|
|
65
|
-
"prettier": "^3.
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
64
|
+
"ol": "^10.0.0",
|
|
65
|
+
"prettier": "^3.3.3",
|
|
66
|
+
"release-it": "^17.6.0",
|
|
67
|
+
"rimraf": "^6.0.1",
|
|
68
|
+
"sass": "^1.77.8",
|
|
69
|
+
"typescript": "^5.5.4",
|
|
70
|
+
"vite": "^5.3.5",
|
|
70
71
|
"vite-plugin-banner": "^0.7.1",
|
|
71
|
-
"vite-plugin-dts": "^
|
|
72
|
+
"vite-plugin-dts": "^4.0.1"
|
|
72
73
|
},
|
|
73
74
|
"peerDependencies": {
|
|
74
|
-
"ol": "> 7.x <=
|
|
75
|
+
"ol": "> 7.x <= 10.x"
|
|
75
76
|
},
|
|
76
77
|
"dependencies": {
|
|
77
78
|
"tiny-emitter": "^2.1.0"
|