@scssyworks/context-builder
Version:
Create context menus with ease
2 lines (1 loc) • 25.4 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).contextBuilder={})}(this,(function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e,n,r,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void n(t)}c.done?e(u):Promise.resolve(u).then(r,o)}function r(t){return function(){var e=this,r=arguments;return new Promise((function(o,i){var a=t.apply(e,r);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function a(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t}function c(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,e,n){if(!e.has(t))throw new TypeError("attempted to "+n+" private field on non-instance");return e.get(t)}function l(t,e){return function(t,e){return e.get?e.get.call(t):e.value}(t,u(t,e,"get"))}function s(t,e,n){return function(t,e,n){if(e.set)e.set.call(t,n);else{if(!e.writable)throw new TypeError("attempted to set read only private field");e.value=n}}(t,u(t,e,"set"),n),n}var f={exports:{}};!function(t){var e=function(t){var e,n=Object.prototype,r=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,n){return t[e]=n}}function l(t,e,n,r){var o=e&&e.prototype instanceof m?e:m,i=Object.create(o.prototype),a=new S(r||[]);return i._invoke=function(t,e,n){var r=f;return function(o,i){if(r===p)throw new Error("Generator is already running");if(r===v){if("throw"===o)throw i;return C()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var c=L(a,n);if(c){if(c===d)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===f)throw r=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=p;var u=s(t,e,n);if("normal"===u.type){if(r=n.done?v:h,u.arg===d)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=v,n.method="throw",n.arg=u.arg)}}}(t,n,a),i}function s(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var f="suspendedStart",h="suspendedYield",p="executing",v="completed",d={};function m(){}function y(){}function g(){}var w={};u(w,i,(function(){return this}));var b=Object.getPrototypeOf,E=b&&b(b(M([])));E&&E!==n&&r.call(E,i)&&(w=E);var k=g.prototype=m.prototype=Object.create(w);function x(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function A(t,e){function n(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,r){function i(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(i,i):i()}}function L(t,n){var r=t.iterator[n.method];if(r===e){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=e,L(t,n),"throw"===n.method))return d;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var o=s(r,t.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,d;var i=o.arg;return i?i.done?(n[t.resultName]=i.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,d):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,d)}function j(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function M(t){if(t){var n=t[i];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function n(){for(;++o<t.length;)if(r.call(t,o))return n.value=t[o],n.done=!1,n;return n.value=e,n.done=!0,n};return a.next=a}}return{next:C}}function C(){return{value:e,done:!0}}return y.prototype=g,u(k,"constructor",g),u(g,"constructor",y),y.displayName=u(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,u(t,c,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},x(A.prototype),u(A.prototype,a,(function(){return this})),t.AsyncIterator=A,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var a=new A(l(e,n,r,o),i);return t.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(k),u(k,c,"Generator"),u(k,i,(function(){return this})),u(k,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=M,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(T),!t)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function o(r,o){return c.type="throw",c.arg=t,n.next=r,o&&(n.method="next",n.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),l=r.call(a,"finallyLoc");if(u&&l){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),T(n),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;T(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:M(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(f);var h=f.exports;function p(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function v(t){return function(t){if(Array.isArray(t))return p(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return p(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function m(){return"undefined"!=typeof document&&Boolean(document.body)}function y(t){return g.apply(this,arguments)}function g(){return(g=r(h.mark((function t(e){var n;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!d(e)){t.next=11;break}return t.prev=1,t.next=4,e;case 4:return n=t.sent,t.abrupt("return",n);case 8:t.prev=8,t.t0=t.catch(1),console.error(t.t0);case 11:return t.abrupt("return",e);case 12:case"end":return t.stop()}}),t,null,[[1,8]])})))).apply(this,arguments)}function w(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return b(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return b(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){throw t})),f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){c=!0,i=t})),f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function b(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function E(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}if("undefined"!=typeof document){var k=document.defaultView;if(void 0===k.CustomEvent){var x=function t(e,n){o(this,t),n=n||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,n.bubbles,n.cancelable,n.detail),r};x.prototype=k.Event.prototype,k.CustomEvent=x}}var A=new WeakMap,L=function(){function t(e){if(o(this,t),E(this,A,{writable:!0,value:void 0}),c(this,"elements",void 0),c(this,"parent",void 0),m()&&s(this,A,document.body),this.elements=[],l(this,A)&&e)if("string"==typeof e)this.elements=v(document.querySelectorAll(e));else if(e instanceof Node||e instanceof EventTarget)this.elements=[e];else if(e instanceof NodeList||e instanceof HTMLCollection)this.elements=v(e);else if(Object.prototype.hasOwnProperty.call(e,"length"))for(var n=0;n<e.length;n++)this.elements.push(e[n]);else e instanceof t&&(this.elements=v(e.elements),this.parent=e.parent);this.parent=this.getParentNode()}return a(t,[{key:"getParentNode",value:function(){var e=this.elements.map((function(t){return t.parentNode})).filter((function(t){return!!t}));return e.length?new t(e):null}},{key:"getAllParents",value:function(){var e=new t(this),n=new t;do{(e=e.getParentNode())&&n.add(e)}while(e);return n}},{key:"query",value:function(e){var n=[];return this.elements.forEach((function(t){t instanceof HTMLElement&&v(t.querySelectorAll(e)).forEach((function(t){-1===n.indexOf(t)&&n.push(t)}))})),new t(n)}},{key:"append",value:function(e){if(l(this,A)){var n;if("string"==typeof e){var r=document.createElement("div");r.innerHTML=e,n=new t(r.childNodes)}else n=new t(e);this.elements.forEach((function(t,e){if(1===n.elements.length)t.appendChild(n.elements[0]);else{var r=document.createDocumentFragment();n.elements.forEach((function(t){r.appendChild(0===e?t:t.cloneNode())})),t.appendChild(r)}}))}return this}},{key:"prepend",value:function(e){return l(this,A)&&this.elements.forEach((function(n){var r=new t(n.childNodes).detach();new t(n).append(e).append(r)})),this}},{key:"detach",value:function(){if(l(this,A)){var e=document.createDocumentFragment();return this.elements.forEach((function(t){e.appendChild(t)})),new t(e)}return this}},{key:"map",value:function(t){return l(this,A)&&"function"==typeof t?this.elements.map(t):this.elements}},{key:"filter",value:function(e){var n=[];return this.map((function(t,r){e(t,r)&&n.push(t)})),new t(n)}},{key:"add",value:function(t){var e;return(e=this.elements).push.apply(e,v(t.elements)),this}},{key:"getBodyTag",value:function(){return new t(l(this,A))}},{key:"children",value:function(){var e=[];return this.elements.forEach((function(t){v(t.childNodes).forEach((function(t){-1===e.indexOf(t)&&e.push(t)}))})),new t(e)}},{key:"on",value:function(t,e,n){return this.elements.forEach((function(r){r.addEventListener("".concat(t),e,n)})),this}},{key:"off",value:function(t,e,n){return this.elements.forEach((function(r){r.removeEventListener(t,e,n)})),this}},{key:"once",value:function(t,e,n){var r=this;return this.on(t,(function o(i){e.apply(this,[i]),r.off(t,o,n)}),n),this}},{key:"bounds",value:function(){return this.map((function(t){return t instanceof HTMLElement?t.getBoundingClientRect():null}))}},{key:"setCSSProps",value:function(t){return this.elements.forEach((function(e){e instanceof HTMLElement&&Object.keys(t).forEach((function(n){e.style[n]=t[n]}))})),this}},{key:"setAttr",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.elements.forEach((function(n){n instanceof HTMLElement&&Object.keys(t).forEach((function(r){(!e||e&&n.hasAttribute(r))&&n.setAttribute(r,"".concat(t[r]))}))})),this}},{key:"reflow",value:function(){return this.elements.forEach((function(t){t instanceof HTMLElement&&t.offsetHeight})),this}},{key:"contains",value:function(e){var n=this;return-1===new t(e).map((function(t){var e,r=w(n.elements);try{for(r.s();!(e=r.n()).done;){if(e.value.contains(t))return!0}}catch(t){r.e(t)}finally{r.f()}return!1})).indexOf(!1)}},{key:"remove",value:function(){return this.elements.forEach((function(t){var e;null===(e=t.parentNode)||void 0===e||e.removeChild(t)})),this}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];var o=new CustomEvent(t,{cancelable:!0,bubbles:!0,detail:{args:n}});return this.elements.forEach((function(t){t.dispatchEvent(o)})),this}}],[{key:"create",value:function(e){return e instanceof HTMLTemplateElement?new t(e.content).children():new t(document.createDocumentFragment()).append(e).children()}}]),t}(),j=function(){function t(e,n){o(this,t),c(this,"target",void 0),c(this,"targetPlacement",void 0),c(this,"windowProps",void 0);var r="undefined"!=typeof document&&document.defaultView||{innerWidth:0,innerHeight:0};this.target=new L(n),this.targetPlacement=this.target.bounds()[0],this.windowProps={width:r.innerWidth,height:r.innerHeight},this.target.setCSSProps({position:"fixed",top:"".concat(this.getClientY(e),"px"),left:"".concat(this.getClientX(e),"px"),maxWidth:"".concat(this.windowProps.width-10,"px"),maxHeight:"".concat(this.windowProps.height-10,"px"),overflow:"auto"})}return a(t,[{key:"getClientX",value:function(t){if(this.targetPlacement){var e=t.clientX+this.targetPlacement.width-this.windowProps.width;if(e>0)return t.clientX-e-4}return t.clientX}},{key:"getClientY",value:function(t){if(this.targetPlacement){var e=t.clientY+this.targetPlacement.height-this.windowProps.height;if(e>0)return t.clientY-e-4}return t.clientY}}]),t}();function T(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}var S=new WeakMap,M=new WeakMap,C=new WeakMap,P=new WeakMap,O=new WeakMap,W=function(){function t(e){var n=this;o(this,t),T(this,S,{writable:!0,value:void 0}),T(this,M,{writable:!0,value:void 0}),T(this,C,{writable:!0,value:"closecontextmenu"}),T(this,P,{writable:!0,value:void 0}),T(this,O,{writable:!0,value:function(t){var e=t.detail.args;"function"==typeof l(n,P)&&l(n,P).call(n,e[0]!==l(n,S))}}),s(this,S,e),m()&&s(this,M,new L(document))}return a(t,[{key:"emit",value:function(){l(this,M)&&l(this,M).emit(l(this,C),l(this,S))}},{key:"listen",value:function(t){var e;s(this,P,t),null===(e=l(this,M))||void 0===e||e.on(l(this,C),l(this,O))}},{key:"off",value:function(){var t;null===(t=l(this,M))||void 0===t||t.off(l(this,C),l(this,O)),s(this,P,void 0)}}]),t}();function N(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}var _=new WeakMap,H=new WeakMap,I=function(){function t(e){o(this,t),N(this,_,{writable:!0,value:void 0}),N(this,H,{writable:!0,value:[]}),s(this,_,e)}return a(t,[{key:"on",value:function(t,e){l(this,H).push({type:t,handler:e})}},{key:"off",value:function(t,e){"string"!=typeof t?l(this,H).length=0:s(this,H,l(this,H).filter((function(n){var r=n.type,o=n.handler;return!(r===t&&(void 0===e||o===e))})))}},{key:"emit",value:function(t){for(var e=this,n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];var i=[];return l(this,H).forEach((function(n){n.type===t&&i.push(n.handler.apply(l(e,_),r))})),i}},{key:"hasListener",value:function(t){return Boolean(l(this,H).filter((function(e){return e.type===t})).length)}}]),t}();function B(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return F(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return F(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function F(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function G(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}var z=new WeakMap,D=new WeakMap,Y=new WeakMap,X=new WeakMap,R=new WeakMap,q=new WeakMap,U=new WeakMap,$=new WeakMap,V=new WeakMap,J=new WeakMap,K=new WeakMap,Q=new WeakMap,Z=new WeakMap,tt=function(){function t(n,i){var a,u=this;o(this,t),G(this,z,{writable:!0,value:!1}),G(this,D,{writable:!0,value:!1}),G(this,Y,{writable:!0,value:void 0}),G(this,X,{writable:!0,value:void 0}),G(this,R,{writable:!0,value:void 0}),G(this,q,{writable:!0,value:void 0}),c(this,"contextTarget",void 0),c(this,"isSupported",void 0),c(this,"rootElement",void 0),c(this,"config",{}),G(this,U,{writable:!0,value:function(){var t;u.rootElement=u.rootElement.detach().children(),s(u,z,!1),s(u,D,!1),u.contextTarget.setAttr({"aria-expanded":!1},!0);for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];(t=l(u,R)).emit.apply(t,["closed"].concat(n))}}),G(this,$,{writable:!0,value:function(){l(u,D)&&("function"==typeof u.config.onDeactivate||l(u,R).hasListener("deactivate")?(s(u,z,!0),u.config.onDeactivate&&u.config.onDeactivate(u.rootElement,l(u,U)),l(u,R).emit("deactivate",u.rootElement,l(u,U))):l(u,U).call(u))}}),G(this,V,{writable:!0,value:function(t){var e=new L(t);return e.getAllParents().add(e).filter((function(t){return t instanceof HTMLElement&&t.hasAttribute("data-cm-host")}))}}),G(this,J,{writable:!0,value:function(t){t.preventDefault(),t.stopPropagation(),l(u,X).emit(),s(u,D,!0),l(u,z)||(l(u,V).call(u,t.target).setAttr({"aria-expanded":!0},!0),l(u,q).append(u.rootElement),new j(t,u.rootElement),"function"==typeof u.config.onActivate&&(u.rootElement.reflow(),u.config.onActivate.apply(u.rootElement,[u.rootElement])),"function"==typeof u.config.onContextMenu&&u.config.onContextMenu.apply(u.rootElement,[t]),l(u,R).emit("activate",u.rootElement),l(u,R).emit("contextmenu",t))}}),G(this,K,{writable:!0,value:(a=r(h.mark((function t(e){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.stopPropagation(),"function"!=typeof u.config.onClick&&!l(u,R).hasListener("click")){t.next=8;break}if(!u.config.onClick){t.next=7;break}return t.next=5,y(u.config.onClick.apply(new L(e.target),[e]));case 5:if(!t.sent){t.next=7;break}l(u,$).call(u);case 7:l(u,R).emit("click",e,new L(e.target)).forEach(function(){var t=r(h.mark((function t(e){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,y(e);case 2:if(!t.sent){t.next=4;break}l(u,$).call(u);case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}());case 8:case"end":return t.stop()}}),t)}))),function(t){return a.apply(this,arguments)})}),G(this,Q,{writable:!0,value:function(t){if("function"==typeof t){var e=t();return void 0===e||e}return!0}}),G(this,Z,{writable:!0,value:function(){var t;(u.contextTarget.off("contextmenu",l(u,J)).off("click",l(u,$)),u.rootElement.off("click",l(u,K)).remove(),m())&&(null===(t=l(u,Y))||void 0===t||t.off("click",l(u,$)));l(u,X).off(),l(u,R).emit("cleaned"),l(u,R).off(),s(u,D,!1),s(u,z,!1)}}),s(this,X,new W(this)),this.config=Object.freeze("object"===e(i)&&i||{}),s(this,q,(new L).getBodyTag()),this.contextTarget="string"==typeof n?new L(n):l(this,q),this.contextTarget.setAttr({"aria-haspopup":!0,"aria-expanded":!1},!0),this.isSupported=Boolean(this.contextTarget.elements.length),this.rootElement=L.create(this.config.rootElement?this.config.rootElement:'<ul class="context-menu-list"></ul>').setAttr({"data-cm-root":!0}).on("click",l(this,K)),this.contextTarget.setAttr({"data-cm-host":!0}).on("contextmenu",l(this,J)),m()&&(s(this,Y,new L(document)),l(this,Y).on("click",l(this,$))),l(this,X).listen((function(t){t&&l(u,$).call(u)})),s(this,R,new I(this.rootElement))}var n;return a(t,[{key:"add",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r,o=[].concat(e),i=B(o);try{for(i.s();!(r=i.n()).done;){var a=r.value;(a instanceof et||a instanceof nt)&&this.rootElement.append(a.rootElement)}}catch(t){i.e(t)}finally{i.f()}return this}},{key:"cleanup",value:(n=r(h.mark((function t(){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(l(this,R).emit("beforecleanup"),"function"!=typeof this.config.onBeforeCleanup){t.next=8;break}return t.next=4,y(l(this,Q).call(this,this.config.onBeforeCleanup));case 4:if(!t.sent){t.next=6;break}l(this,Z).call(this);case 6:t.next=9;break;case 8:l(this,Z).call(this);case 9:case"end":return t.stop()}}),t,this)}))),function(){return n.apply(this,arguments)})},{key:"on",value:function(t,e){return l(this,R).on(t,e),this}},{key:"off",value:function(t,e){return l(this,R).off(t,e),this}}]),t}(),et=function(){function t(n,r){o(this,t),c(this,"config",{}),c(this,"rootElement",void 0),c(this,"listElement",void 0),this.config=Object.freeze("object"===e(r)&&r||{}),this.listElement=L.create(this.config.listElement?this.config.listElement:'<ul class="context-submenu"></ul>').setAttr({"data-cm-submenu-root":!0}),this.rootElement=L.create(this.config.rootElement?this.config.rootElement:'<li class="menu-item"></li>').setAttr({"data-sub-elements":!0}).append(n).append(this.listElement)}return a(t,[{key:"parent",get:function(){return this.rootElement.parent}},{key:"add",value:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];var o,i=[].concat(n),a=B(i);try{for(a.s();!(o=a.n()).done;){var c=o.value;(c instanceof t||c instanceof nt)&&this.listElement.append(c.rootElement)}}catch(t){a.e(t)}finally{a.f()}return this}},{key:"remove",value:function(){this.rootElement.remove()}}]),t}(),nt=function(){function t(n,r){o(this,t),c(this,"config",{}),c(this,"rootElement",void 0),this.config=Object.freeze("object"===e(r)&&r||{}),this.rootElement=L.create(this.config.rootElement?this.config.rootElement:'<li class="menu-item"></li>').setAttr({"data-cm-leaf":!0}).append(n)}return a(t,[{key:"remove",value:function(){this.rootElement.remove()}}]),t}();t.ContextItem=nt,t.ContextList=et,t.ContextMenu=tt,Object.defineProperty(t,"__esModule",{value:!0})}));