ol-contextmenu 5.0.1-alpha → 5.0.3-alpha
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/dist/constants.d.ts +14 -0
- package/dist/emitter.d.ts +3 -0
- package/dist/helpers/dom.d.ts +5 -0
- package/dist/main.d.ts +43 -0
- package/dist/ol-contextmenu.d.ts +3 -0
- package/dist/ol-contextmenu.js +1 -1
- package/dist/ol-contextmenu.umd.cjs +1 -1
- package/dist/types.d.ts +49 -0
- package/dist/vite-env.d.ts +1 -0
- package/package.json +7 -6
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SingleItem, Options } from './types';
|
|
2
|
+
export declare const DEFAULT_OPTIONS: Options;
|
|
3
|
+
export declare const CSS_CLASSES: {
|
|
4
|
+
namespace: string;
|
|
5
|
+
container: string;
|
|
6
|
+
separator: string;
|
|
7
|
+
submenu: string;
|
|
8
|
+
hidden: string;
|
|
9
|
+
icon: string;
|
|
10
|
+
zoomIn: string;
|
|
11
|
+
zoomOut: string;
|
|
12
|
+
unselectable: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const DEFAULT_ITEMS: SingleItem[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Item } from '../types';
|
|
2
|
+
export declare function createFragment(html: string): DocumentFragment;
|
|
3
|
+
export declare function getLineHeight(container: HTMLDivElement): number;
|
|
4
|
+
export declare function addMenuEntry(parentNode: HTMLUListElement, item: Item, isSubmenu?: boolean): HTMLLIElement;
|
|
5
|
+
export declare function addMenuEntries(container: HTMLUListElement, items: Item[], menuWidth: number): void;
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Pixel } from 'ol/pixel';
|
|
2
|
+
import type { Coordinate } from 'ol/coordinate';
|
|
3
|
+
import Control from 'ol/control/Control';
|
|
4
|
+
import OlMap from 'ol/Map';
|
|
5
|
+
import { Item, MenuEntry, Options } from './types';
|
|
6
|
+
export default class ContextMenu extends Control {
|
|
7
|
+
protected map: OlMap;
|
|
8
|
+
protected container: HTMLDivElement;
|
|
9
|
+
protected coordinate: Coordinate;
|
|
10
|
+
protected pixel: Pixel;
|
|
11
|
+
protected contextMenuEventListener: (evt: MouseEvent) => void;
|
|
12
|
+
protected entryCallbackEventListener: (evt: MouseEvent) => void;
|
|
13
|
+
protected mapMoveListener: () => void;
|
|
14
|
+
protected lineHeight: number;
|
|
15
|
+
protected disabled: boolean;
|
|
16
|
+
protected opened: boolean;
|
|
17
|
+
protected items: Item[];
|
|
18
|
+
protected menuEntries: Map<string, MenuEntry>;
|
|
19
|
+
options: Options;
|
|
20
|
+
constructor(opts?: Partial<Options>);
|
|
21
|
+
clear(): void;
|
|
22
|
+
enable(): void;
|
|
23
|
+
disable(): void;
|
|
24
|
+
getDefaultItems(): import("./types").SingleItem[];
|
|
25
|
+
countItems(): number;
|
|
26
|
+
extend(items: Item[]): void;
|
|
27
|
+
closeMenu(): void;
|
|
28
|
+
isOpen(): boolean;
|
|
29
|
+
updatePosition(pixel: Pixel): void;
|
|
30
|
+
pop(): void;
|
|
31
|
+
shift(): void;
|
|
32
|
+
push(item: Item): void;
|
|
33
|
+
setMap(map: OlMap): void;
|
|
34
|
+
protected removeListeners(): void;
|
|
35
|
+
protected removeMenuEntry(id: string): void;
|
|
36
|
+
protected handleContextMenu(evt: MouseEvent): void;
|
|
37
|
+
protected openMenu(): void;
|
|
38
|
+
protected getMenuEntriesLength(): number;
|
|
39
|
+
protected positionContainer(): void;
|
|
40
|
+
protected handleMapMove(): void;
|
|
41
|
+
protected handleEntryCallback(evt: MouseEvent): void;
|
|
42
|
+
protected handleAddMenuEntry(item: MenuEntry, element: HTMLLIElement): void;
|
|
43
|
+
}
|
package/dist/ol-contextmenu.js
CHANGED
|
@@ -181,7 +181,7 @@ class z extends T {
|
|
|
181
181
|
clear() {
|
|
182
182
|
for (const e of this.menuEntries.keys())
|
|
183
183
|
this.removeMenuEntry(e);
|
|
184
|
-
this.container.replaceChildren();
|
|
184
|
+
this.container.replaceChildren(), this.container.append(document.createElement("ul"));
|
|
185
185
|
}
|
|
186
186
|
enable() {
|
|
187
187
|
this.disabled = !1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("ol/control/Control")):typeof define=="function"&&define.amd?define(["ol/control/Control"],c):(l=typeof globalThis<"u"?globalThis:l||self,l.ContextMenu=c(l.ol.control.Control))})(this,function(l){"use strict";var z=Object.defineProperty;var H=(l,c,f)=>c in l?z(l,c,{enumerable:!0,configurable:!0,writable:!0,value:f}):l[c]=f;var a=(l,c,f)=>(H(l,typeof c!="symbol"?c+"":c,f),f);const f=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(l);var M=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(M||{}),m=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(m||{});const S={width:150,scrollAt:4,eventType:M.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"},C=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(n,i)=>{const e=i.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(n,i)=>{const e=i.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var A={exports:{}};function x(){}x.prototype={on:function(n,i,e){var t=this.e||(this.e={});return(t[n]||(t[n]=[])).push({fn:i,ctx:e}),this},once:function(n,i,e){var t=this;function s(){t.off(n,s),i.apply(e,arguments)}return s._=i,this.on(n,s,e)},emit:function(n){var i=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),t=0,s=e.length;for(t;t<s;t++)e[t].fn.apply(e[t].ctx,i);return this},off:function(n,i){var e=this.e||(this.e={}),t=e[n],s=[];if(t&&i)for(var o=0,h=t.length;o<h;o++)t[o].fn!==i&&t[o].fn._!==i&&s.push(t[o]);return s.length?e[n]=s:delete e[n],this}},A.exports=x;var k=A.exports.TinyEmitter=x;const b=new k;function y(n){const i=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)i.append(e.firstChild);return i}function T(n){const i=document.importNode(n),e=n.offsetWidth;i.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const t=y("<span>Foo</span>"),s=y("<span>Foo</span>"),o=document.createElement("li"),h=document.createElement("li");o.append(t),h.append(s),i.append(o),i.append(h),n.parentNode?.append(i);const E=i.offsetHeight/2;return n.parentNode?.removeChild(i),E}function $(n,i,e=!1){const t=`_${Math.random().toString(36).slice(2,11)}`;if(typeof i!="string"&&"text"in i){const E=`<span>${i.text}</span>`,v=y(E),u=document.createElement("li");return i.classname=i.classname||"",i.icon&&(i.classname===""?i.classname=r.icon:i.classname.includes(r.icon)===!1&&(i.classname+=` ${r.icon}`),u.setAttribute("style",`background-image:url(${i.icon})`)),u.id=t,u.className=i.classname,u.append(v),n.append(u),b.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!1,callback:"callback"in i?i.callback:null,data:"data"in i?i.data:null},u),u}const s=`<li id="${t}" class="${r.separator}"><hr></li>`,o=y(s);n.append(o);const h=n.lastChild;return b.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!0,callback:null,data:null},h),h}function L(n,i,e){i.forEach(t=>{if(typeof t!="string"&&"items"in t&&Array.isArray(t.items)){const s=$(n,t,!0);s.classList.add(r.submenu);const o=document.createElement("ul");o.classList.add(r.container),o.style.width=`${e}px`,s.append(o),L(o,t.items,e)}else $(n,t)})}const P="";function w(n,i){if(!n)throw new Error(i)}class N extends f.default{constructor(e={}){w(typeof e=="object","@param `opts` should be object type!");const t=document.createElement("div");super({element:t});a(this,"map");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={...S,...e};const s=document.createElement("ul");t.append(s),t.style.width=`${this.options.width}px`,t.classList.add(r.container,r.unselectable,r.hidden),this.container=t,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,b.on(m.ADD_MENU_ENTRY,(o,h)=>{this.handleAddMenuEntry(o,h)},this)}clear(){for(const e of this.menuEntries.keys())this.removeMenuEntry(e);this.container.replaceChildren()}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return C}countItems(){return this.menuEntries.size}extend(e){w(Array.isArray(e),"@param `items` should be an Array."),L(this.container.firstElementChild,e,this.options.width)}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(m.CLOSE)}isOpen(){return this.opened}updatePosition(e){w(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,this.map.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.map.on("movestart",()=>{this.handleMapMove()}),this.items=this.options.defaultItems?this.options.items.concat(C):this.options.items,L(this.container.firstElementChild,this.items,this.options.width);const t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:T(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1)}removeMenuEntry(e){const t=document.getElementById(e);t?.remove(),t?.removeEventListener("click",this.entryCallbackEventListener),this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent({type:m.BEFOREOPEN,pixel:this.pixel,coordinate:this.coordinate}),!this.disabled&&(this.options.eventType===M.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),this.openMenu(),e.target?.addEventListener("pointerdown",t=>{this.opened&&(t.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(){this.menuEntries.size!==0&&(this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1||e.isSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],t={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},s={w:this.container.offsetWidth,h:Math.round(this.lineHeight*this.getMenuEntriesLength())},o=t.w>=s.w?this.pixel[0]+5:this.pixel[0]-s.w;this.container.style.left=`${o}px`,this.container.style.top=t.h>=s.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-s.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",t.w-=s.w;const h=u=>Array.from(u.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let E=0;const v=(u,g)=>{E+=1,h(u).forEach(_=>{const D=g>=s.w?s.w-8:(s.w+8)*-1,d=_.querySelector(`ul.${r.container}`),O=Math.round(this.lineHeight*Array.from(d.children).filter(I=>I.tagName==="LI").length);d.style.left=`${D}px`,d.style.right="auto",d.style.top=t.h>=O+s.h?"0":`-${d.offsetHeight-25}px`,d.style.bottom="auto",d.style.zIndex=String(E),h(d).length>0&&v(d,g-s.w)})};v(this.container.firstElementChild,t.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,s=this.menuEntries.get(t.id);if(!s)return;const o={coordinate:this.coordinate,data:s.data};this.closeMenu(),s.callback?.(o,this.map)}handleAddMenuEntry(e,t){this.menuEntries.set(e.id,e),"callback"in e&&typeof e.callback=="function"&&t.addEventListener("click",this.entryCallbackEventListener,!1)}}return window.ol?.control&&(window.ol.control.ContextMenu=N),N});
|
|
1
|
+
(function(l,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("ol/control/Control")):typeof define=="function"&&define.amd?define(["ol/control/Control"],c):(l=typeof globalThis<"u"?globalThis:l||self,l.ContextMenu=c(l.ol.control.Control))})(this,function(l){"use strict";var z=Object.defineProperty;var H=(l,c,f)=>c in l?z(l,c,{enumerable:!0,configurable:!0,writable:!0,value:f}):l[c]=f;var a=(l,c,f)=>(H(l,typeof c!="symbol"?c+"":c,f),f);const f=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(l);var M=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(M||{}),m=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(m||{});const S={width:150,scrollAt:4,eventType:M.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"},C=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(n,i)=>{const e=i.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(n,i)=>{const e=i.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var A={exports:{}};function x(){}x.prototype={on:function(n,i,e){var t=this.e||(this.e={});return(t[n]||(t[n]=[])).push({fn:i,ctx:e}),this},once:function(n,i,e){var t=this;function s(){t.off(n,s),i.apply(e,arguments)}return s._=i,this.on(n,s,e)},emit:function(n){var i=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),t=0,s=e.length;for(t;t<s;t++)e[t].fn.apply(e[t].ctx,i);return this},off:function(n,i){var e=this.e||(this.e={}),t=e[n],s=[];if(t&&i)for(var o=0,h=t.length;o<h;o++)t[o].fn!==i&&t[o].fn._!==i&&s.push(t[o]);return s.length?e[n]=s:delete e[n],this}},A.exports=x;var k=A.exports.TinyEmitter=x;const b=new k;function y(n){const i=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)i.append(e.firstChild);return i}function T(n){const i=document.importNode(n),e=n.offsetWidth;i.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const t=y("<span>Foo</span>"),s=y("<span>Foo</span>"),o=document.createElement("li"),h=document.createElement("li");o.append(t),h.append(s),i.append(o),i.append(h),n.parentNode?.append(i);const E=i.offsetHeight/2;return n.parentNode?.removeChild(i),E}function $(n,i,e=!1){const t=`_${Math.random().toString(36).slice(2,11)}`;if(typeof i!="string"&&"text"in i){const E=`<span>${i.text}</span>`,v=y(E),u=document.createElement("li");return i.classname=i.classname||"",i.icon&&(i.classname===""?i.classname=r.icon:i.classname.includes(r.icon)===!1&&(i.classname+=` ${r.icon}`),u.setAttribute("style",`background-image:url(${i.icon})`)),u.id=t,u.className=i.classname,u.append(v),n.append(u),b.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!1,callback:"callback"in i?i.callback:null,data:"data"in i?i.data:null},u),u}const s=`<li id="${t}" class="${r.separator}"><hr></li>`,o=y(s);n.append(o);const h=n.lastChild;return b.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!0,callback:null,data:null},h),h}function L(n,i,e){i.forEach(t=>{if(typeof t!="string"&&"items"in t&&Array.isArray(t.items)){const s=$(n,t,!0);s.classList.add(r.submenu);const o=document.createElement("ul");o.classList.add(r.container),o.style.width=`${e}px`,s.append(o),L(o,t.items,e)}else $(n,t)})}const P="";function w(n,i){if(!n)throw new Error(i)}class N extends f.default{constructor(e={}){w(typeof e=="object","@param `opts` should be object type!");const t=document.createElement("div");super({element:t});a(this,"map");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={...S,...e};const s=document.createElement("ul");t.append(s),t.style.width=`${this.options.width}px`,t.classList.add(r.container,r.unselectable,r.hidden),this.container=t,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,b.on(m.ADD_MENU_ENTRY,(o,h)=>{this.handleAddMenuEntry(o,h)},this)}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 C}countItems(){return this.menuEntries.size}extend(e){w(Array.isArray(e),"@param `items` should be an Array."),L(this.container.firstElementChild,e,this.options.width)}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(m.CLOSE)}isOpen(){return this.opened}updatePosition(e){w(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,this.map.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.map.on("movestart",()=>{this.handleMapMove()}),this.items=this.options.defaultItems?this.options.items.concat(C):this.options.items,L(this.container.firstElementChild,this.items,this.options.width);const t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:T(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1)}removeMenuEntry(e){const t=document.getElementById(e);t?.remove(),t?.removeEventListener("click",this.entryCallbackEventListener),this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent({type:m.BEFOREOPEN,pixel:this.pixel,coordinate:this.coordinate}),!this.disabled&&(this.options.eventType===M.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),this.openMenu(),e.target?.addEventListener("pointerdown",t=>{this.opened&&(t.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(){this.menuEntries.size!==0&&(this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1||e.isSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],t={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},s={w:this.container.offsetWidth,h:Math.round(this.lineHeight*this.getMenuEntriesLength())},o=t.w>=s.w?this.pixel[0]+5:this.pixel[0]-s.w;this.container.style.left=`${o}px`,this.container.style.top=t.h>=s.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-s.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",t.w-=s.w;const h=u=>Array.from(u.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let E=0;const v=(u,g)=>{E+=1,h(u).forEach(_=>{const D=g>=s.w?s.w-8:(s.w+8)*-1,d=_.querySelector(`ul.${r.container}`),O=Math.round(this.lineHeight*Array.from(d.children).filter(I=>I.tagName==="LI").length);d.style.left=`${D}px`,d.style.right="auto",d.style.top=t.h>=O+s.h?"0":`-${d.offsetHeight-25}px`,d.style.bottom="auto",d.style.zIndex=String(E),h(d).length>0&&v(d,g-s.w)})};v(this.container.firstElementChild,t.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,s=this.menuEntries.get(t.id);if(!s)return;const o={coordinate:this.coordinate,data:s.data};this.closeMenu(),s.callback?.(o,this.map)}handleAddMenuEntry(e,t){this.menuEntries.set(e.id,e),"callback"in e&&typeof e.callback=="function"&&t.addEventListener("click",this.entryCallbackEventListener,!1)}}return window.ol?.control&&(window.ol.control.ContextMenu=N),N});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Map as OlMap } from 'ol';
|
|
2
|
+
import { Coordinate } from 'ol/coordinate';
|
|
3
|
+
import BaseEvent from 'ol/events/Event';
|
|
4
|
+
import { Pixel } from 'ol/pixel';
|
|
5
|
+
export declare enum EventTypes {
|
|
6
|
+
CONTEXTMENU = "contextmenu",
|
|
7
|
+
CLICK = "click",
|
|
8
|
+
DBLCLICK = "dblclick"
|
|
9
|
+
}
|
|
10
|
+
export declare enum CustomEventTypes {
|
|
11
|
+
BEFOREOPEN = "beforeopen",
|
|
12
|
+
OPEN = "open",
|
|
13
|
+
CLOSE = "close",
|
|
14
|
+
ADD_MENU_ENTRY = "add-menu-entry"
|
|
15
|
+
}
|
|
16
|
+
export interface ContextMenuEvent extends BaseEvent {
|
|
17
|
+
coordinate: Coordinate;
|
|
18
|
+
pixel: Pixel;
|
|
19
|
+
}
|
|
20
|
+
export declare type CallbackObject = {
|
|
21
|
+
coordinate: Coordinate;
|
|
22
|
+
data: unknown;
|
|
23
|
+
};
|
|
24
|
+
export declare type ItemSeparator = '-';
|
|
25
|
+
export declare type SingleItem = {
|
|
26
|
+
text: string;
|
|
27
|
+
classname?: string;
|
|
28
|
+
icon?: string;
|
|
29
|
+
callback: (object: CallbackObject, map: OlMap) => void;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
};
|
|
32
|
+
export declare type MenuEntry = {
|
|
33
|
+
id: string;
|
|
34
|
+
isSubmenu: boolean;
|
|
35
|
+
isSeparator: boolean;
|
|
36
|
+
callback: SingleItem['callback'] | null;
|
|
37
|
+
data: unknown;
|
|
38
|
+
};
|
|
39
|
+
export declare type ItemWithNested = Pick<SingleItem, 'text' | 'classname' | 'icon'> & {
|
|
40
|
+
items: SingleItem[] | ItemWithNested[];
|
|
41
|
+
};
|
|
42
|
+
export declare type Item = SingleItem | ItemSeparator | ItemWithNested;
|
|
43
|
+
export declare type Options = {
|
|
44
|
+
width: number;
|
|
45
|
+
scrollAt: number;
|
|
46
|
+
eventType: `${EventTypes}`;
|
|
47
|
+
defaultItems: boolean;
|
|
48
|
+
items: Item[];
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ol-contextmenu",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3-alpha",
|
|
4
4
|
"description": "Custom Context Menu for Openlayers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/ol-contextmenu.umd.cjs",
|
|
@@ -31,18 +31,17 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"dev": "vite",
|
|
34
|
-
"build": "
|
|
34
|
+
"build": "rimraf ./dist && vite build",
|
|
35
35
|
"preview": "vite preview",
|
|
36
36
|
"lint": "eslint --cache --ext .js .",
|
|
37
37
|
"lint:fix": "npm run lint -- --fix",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
38
|
+
"test": "jest",
|
|
39
|
+
"prepublishOnly": "npm run lint && npm test && npm run build"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@swc/core": "^1.3.0",
|
|
43
43
|
"@swc/jest": "^0.2.22",
|
|
44
44
|
"@types/jest": "^29.0.2",
|
|
45
|
-
"@vitejs/plugin-legacy": "^2.1.0",
|
|
46
45
|
"canvas": "^2.10.1",
|
|
47
46
|
"eslint": "^8.23.1",
|
|
48
47
|
"eslint-config-jwalker": "^7.9.2",
|
|
@@ -54,8 +53,10 @@
|
|
|
54
53
|
"jest-environment-jsdom": "^29.0.3",
|
|
55
54
|
"ol": "^7.1.0",
|
|
56
55
|
"prettier": "^2.7.1",
|
|
56
|
+
"rimraf": "^3.0.2",
|
|
57
57
|
"typescript": "^4.8.3",
|
|
58
|
-
"vite": "^3.1.0"
|
|
58
|
+
"vite": "^3.1.0",
|
|
59
|
+
"vite-plugin-dts": "^1.5.0"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
61
62
|
"ol": "^7.1.0"
|