@scssyworks/context-builder
Version:
Create context menus with ease
2 lines (1 loc) • 25.1 kB
JavaScript
function t(e){return t="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},t(e)}function e(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 n(t){return function(){var n=this,r=arguments;return new Promise((function(o,i){var a=t.apply(n,r);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(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 i(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function c(t,e,n){if(!e.has(t))throw new TypeError("attempted to "+n+" private field on non-instance");return e.get(t)}function u(t,e){return function(t,e){return e.get?e.get.call(t):e.value}(t,c(t,e,"get"))}function l(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,c(t,e,"set"),n),n}var s={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 d?e:d,i=Object.create(o.prototype),a=new T(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===m)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===m)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",m={};function d(){}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=d.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 m;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var o=s(r,t.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,m;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,m):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,m)}function S(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 j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,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,T.prototype={constructor:T,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(j),!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,m):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),m},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),j(n),m}},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;j(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),m}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(s);var f=s.exports;function h(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 p(t){return function(t){if(Array.isArray(t))return h(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 h(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)?h(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 v(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function m(){return"undefined"!=typeof document&&Boolean(document.body)}function d(t){return y.apply(this,arguments)}function y(){return(y=n(f.mark((function t(e){var n;return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!v(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 g(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 w(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 w(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 w(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 b(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 E=document.defaultView;if(void 0===E.CustomEvent){var k=function t(e,n){r(this,t),n=n||{bubbles:!1,cancelable:!1,detail:void 0};var o=document.createEvent("CustomEvent");return o.initCustomEvent(e,n.bubbles,n.cancelable,n.detail),o};k.prototype=E.Event.prototype,E.CustomEvent=k}}var x=new WeakMap,A=function(){function t(e){if(r(this,t),b(this,x,{writable:!0,value:void 0}),a(this,"elements",void 0),a(this,"parent",void 0),m()&&l(this,x,document.body),this.elements=[],u(this,x)&&e)if("string"==typeof e)this.elements=p(document.querySelectorAll(e));else if(e instanceof Node||e instanceof EventTarget)this.elements=[e];else if(e instanceof NodeList||e instanceof HTMLCollection)this.elements=p(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=p(e.elements),this.parent=e.parent);this.parent=this.getParentNode()}return i(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&&p(t.querySelectorAll(e)).forEach((function(t){-1===n.indexOf(t)&&n.push(t)}))})),new t(n)}},{key:"append",value:function(e){if(u(this,x)){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 u(this,x)&&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(u(this,x)){var e=document.createDocumentFragment();return this.elements.forEach((function(t){e.appendChild(t)})),new t(e)}return this}},{key:"map",value:function(t){return u(this,x)&&"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,p(t.elements)),this}},{key:"getBodyTag",value:function(){return new t(u(this,x))}},{key:"children",value:function(){var e=[];return this.elements.forEach((function(t){p(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=g(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}(),L=function(){function t(e,n){r(this,t),a(this,"target",void 0),a(this,"targetPlacement",void 0),a(this,"windowProps",void 0);var o="undefined"!=typeof document&&document.defaultView||{innerWidth:0,innerHeight:0};this.target=new A(n),this.targetPlacement=this.target.bounds()[0],this.windowProps={width:o.innerWidth,height:o.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 i(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 S(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 j=new WeakMap,T=new WeakMap,M=new WeakMap,C=new WeakMap,P=new WeakMap,O=function(){function t(e){var n=this;r(this,t),S(this,j,{writable:!0,value:void 0}),S(this,T,{writable:!0,value:void 0}),S(this,M,{writable:!0,value:"closecontextmenu"}),S(this,C,{writable:!0,value:void 0}),S(this,P,{writable:!0,value:function(t){var e=t.detail.args;"function"==typeof u(n,C)&&u(n,C).call(n,e[0]!==u(n,j))}}),l(this,j,e),m()&&l(this,T,new A(document))}return i(t,[{key:"emit",value:function(){u(this,T)&&u(this,T).emit(u(this,M),u(this,j))}},{key:"listen",value:function(t){var e;l(this,C,t),null===(e=u(this,T))||void 0===e||e.on(u(this,M),u(this,P))}},{key:"off",value:function(){var t;null===(t=u(this,T))||void 0===t||t.off(u(this,M),u(this,P)),l(this,C,void 0)}}]),t}();function W(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 N=new WeakMap,_=new WeakMap,H=function(){function t(e){r(this,t),W(this,N,{writable:!0,value:void 0}),W(this,_,{writable:!0,value:[]}),l(this,N,e)}return i(t,[{key:"on",value:function(t,e){u(this,_).push({type:t,handler:e})}},{key:"off",value:function(t,e){"string"!=typeof t?u(this,_).length=0:l(this,_,u(this,_).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 u(this,_).forEach((function(n){n.type===t&&i.push(n.handler.apply(u(e,N),r))})),i}},{key:"hasListener",value:function(t){return Boolean(u(this,_).filter((function(e){return e.type===t})).length)}}]),t}();function I(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 B(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 G=new WeakMap,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=function(){function e(o,i){var c,s=this;r(this,e),B(this,G,{writable:!0,value:!1}),B(this,z,{writable:!0,value:!1}),B(this,D,{writable:!0,value:void 0}),B(this,Y,{writable:!0,value:void 0}),B(this,X,{writable:!0,value:void 0}),B(this,R,{writable:!0,value:void 0}),a(this,"contextTarget",void 0),a(this,"isSupported",void 0),a(this,"rootElement",void 0),a(this,"config",{}),B(this,q,{writable:!0,value:function(){var t;s.rootElement=s.rootElement.detach().children(),l(s,G,!1),l(s,z,!1),s.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=u(s,X)).emit.apply(t,["closed"].concat(n))}}),B(this,U,{writable:!0,value:function(){u(s,z)&&("function"==typeof s.config.onDeactivate||u(s,X).hasListener("deactivate")?(l(s,G,!0),s.config.onDeactivate&&s.config.onDeactivate(s.rootElement,u(s,q)),u(s,X).emit("deactivate",s.rootElement,u(s,q))):u(s,q).call(s))}}),B(this,$,{writable:!0,value:function(t){var e=new A(t);return e.getAllParents().add(e).filter((function(t){return t instanceof HTMLElement&&t.hasAttribute("data-cm-host")}))}}),B(this,V,{writable:!0,value:function(t){t.preventDefault(),t.stopPropagation(),u(s,Y).emit(),l(s,z,!0),u(s,G)||(u(s,$).call(s,t.target).setAttr({"aria-expanded":!0},!0),u(s,R).append(s.rootElement),new L(t,s.rootElement),"function"==typeof s.config.onActivate&&(s.rootElement.reflow(),s.config.onActivate.apply(s.rootElement,[s.rootElement])),"function"==typeof s.config.onContextMenu&&s.config.onContextMenu.apply(s.rootElement,[t]),u(s,X).emit("activate",s.rootElement),u(s,X).emit("contextmenu",t))}}),B(this,J,{writable:!0,value:(c=n(f.mark((function t(e){return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.stopPropagation(),"function"!=typeof s.config.onClick&&!u(s,X).hasListener("click")){t.next=8;break}if(!s.config.onClick){t.next=7;break}return t.next=5,d(s.config.onClick.apply(new A(e.target),[e]));case 5:if(!t.sent){t.next=7;break}u(s,U).call(s);case 7:u(s,X).emit("click",e,new A(e.target)).forEach(function(){var t=n(f.mark((function t(e){return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,d(e);case 2:if(!t.sent){t.next=4;break}u(s,U).call(s);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 c.apply(this,arguments)})}),B(this,K,{writable:!0,value:function(t){if("function"==typeof t){var e=t();return void 0===e||e}return!0}}),B(this,Q,{writable:!0,value:function(){var t;(s.contextTarget.off("contextmenu",u(s,V)).off("click",u(s,U)),s.rootElement.off("click",u(s,J)).remove(),m())&&(null===(t=u(s,D))||void 0===t||t.off("click",u(s,U)));u(s,Y).off(),u(s,X).emit("cleaned"),u(s,X).off(),l(s,z,!1),l(s,G,!1)}}),l(this,Y,new O(this)),this.config=Object.freeze("object"===t(i)&&i||{}),l(this,R,(new A).getBodyTag()),this.contextTarget="string"==typeof o?new A(o):u(this,R),this.contextTarget.setAttr({"aria-haspopup":!0,"aria-expanded":!1},!0),this.isSupported=Boolean(this.contextTarget.elements.length),this.rootElement=A.create(this.config.rootElement?this.config.rootElement:'<ul class="context-menu-list"></ul>').setAttr({"data-cm-root":!0}).on("click",u(this,J)),this.contextTarget.setAttr({"data-cm-host":!0}).on("contextmenu",u(this,V)),m()&&(l(this,D,new A(document)),u(this,D).on("click",u(this,U))),u(this,Y).listen((function(t){t&&u(s,U).call(s)})),l(this,X,new H(this.rootElement))}var o;return i(e,[{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=I(o);try{for(i.s();!(r=i.n()).done;){var a=r.value;(a instanceof tt||a instanceof et)&&this.rootElement.append(a.rootElement)}}catch(t){i.e(t)}finally{i.f()}return this}},{key:"cleanup",value:(o=n(f.mark((function t(){return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(u(this,X).emit("beforecleanup"),"function"!=typeof this.config.onBeforeCleanup){t.next=8;break}return t.next=4,d(u(this,K).call(this,this.config.onBeforeCleanup));case 4:if(!t.sent){t.next=6;break}u(this,Q).call(this);case 6:t.next=9;break;case 8:u(this,Q).call(this);case 9:case"end":return t.stop()}}),t,this)}))),function(){return o.apply(this,arguments)})},{key:"on",value:function(t,e){return u(this,X).on(t,e),this}},{key:"off",value:function(t,e){return u(this,X).off(t,e),this}}]),e}(),tt=function(){function e(n,o){r(this,e),a(this,"config",{}),a(this,"rootElement",void 0),a(this,"listElement",void 0),this.config=Object.freeze("object"===t(o)&&o||{}),this.listElement=A.create(this.config.listElement?this.config.listElement:'<ul class="context-submenu"></ul>').setAttr({"data-cm-submenu-root":!0}),this.rootElement=A.create(this.config.rootElement?this.config.rootElement:'<li class="menu-item"></li>').setAttr({"data-sub-elements":!0}).append(n).append(this.listElement)}return i(e,[{key:"parent",get:function(){return this.rootElement.parent}},{key:"add",value:function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var o,i=[].concat(n),a=I(i);try{for(a.s();!(o=a.n()).done;){var c=o.value;(c instanceof e||c instanceof et)&&this.listElement.append(c.rootElement)}}catch(t){a.e(t)}finally{a.f()}return this}},{key:"remove",value:function(){this.rootElement.remove()}}]),e}(),et=function(){function e(n,o){r(this,e),a(this,"config",{}),a(this,"rootElement",void 0),this.config=Object.freeze("object"===t(o)&&o||{}),this.rootElement=A.create(this.config.rootElement?this.config.rootElement:'<li class="menu-item"></li>').setAttr({"data-cm-leaf":!0}).append(n)}return i(e,[{key:"remove",value:function(){this.rootElement.remove()}}]),e}();export{et as ContextItem,tt as ContextList,Z as ContextMenu};