UNPKG

@silexlabs/grapesjs-notifications

Version:

This GrapesJs plugin is designed to enhance the user experience within the editor by providing a robust notification system. This plugin captures and displays various types of notifications including errors, warnings, and activities, thereby facilitating

3 lines 27.3 kB
/*! @silexlabs/grapesjs-notifications - 0.2.0 */ !function(t,e){'object'==typeof exports&&'object'==typeof module?module.exports=e():'function'==typeof define&&define.amd?define([],e):'object'==typeof exports?exports["@silexlabs/grapesjs-notifications"]=e():t["@silexlabs/grapesjs-notifications"]=e()}('undefined'!=typeof globalThis?globalThis:'undefined'!=typeof window?window:this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var s in n)t.o(n,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:n[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{'undefined'!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(t,'__esModule',{value:!0})}},e={};t.r(e),t.d(e,{NOTIFICATION_ADD:()=>Dt,NOTIFICATION_ADDED:()=>a,NOTIFICATION_CHANGED:()=>r,NOTIFICATION_CLEAR:()=>Lt,NOTIFICATION_CLEARED:()=>c,NOTIFICATION_REMOVE:()=>zt,NOTIFICATION_REMOVED:()=>l,Notification:()=>i,default:()=>Kt});const n={'@silexlabs/grapesjs-notifications':{Close:'✖ Dismiss',CloseAll:'✖ Dismiss all',Select:'✓ Select component',Show:'↓ Show'}};var s=void 0&&(void 0).__assign||function(){return s=Object.assign||function(t){for(var e,n=1,s=arguments.length;n<s;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},s.apply(this,arguments)},i=function(){function t(t,e,n){var s=this;this.editor=t,this.componentId=null,this.group=null,this.options=this.getDefaultOptions(e),this.removeCallback=n,this.options.timeout&&(this.timeoutRef=setTimeout((function(){return s.remove()}),this.options.timeout)),this.message=this.options.message,this.type=this.options.type,this.componentId=e.componentId||null,this.group=e.group||null,this.model={attributes:e}}return t.prototype.select=function(){var t=this;if(this.options.componentId){var e=this.getAllComponents(this.editor).find((function(e){var n=e.component;e.page;return n.getId()===t.options.componentId}))||null;if(e){var n=e.component,s=e.page;this.editor.Pages.select(s),this.editor.select(n),this.editor.Canvas.scrollTo(n)}else console.error("Component with ID ".concat(this.options.componentId," not found")),this.editor.runCommand('notifications:add',{message:"Component with ID ".concat(this.options.componentId," not found"),type:'error'})}},t.prototype.remove=function(){this.removeCallback?this.removeCallback(this):this.editor.runCommand('notifications:remove',{notification:this}),this.timeoutRef&&clearTimeout(this.timeoutRef)},t.prototype.getSvgIcon=function(t){var e;return null===(e=this.options.icons)||void 0===e?void 0:e[t]},t.prototype.getDefaultOptions=function(t){return s({icons:s({info:"🚧",warning:"⚠",error:"🚫",success:"✅",group:"📌"},t.icons)},t)},t.prototype.getAllComponents=function(t){var e=this;return t.Pages.getAll().map((function(t){return e.getAllComponentInPage(t)})).flat()},t.prototype.getAllComponentInPage=function(t){var e=t.getMainComponent();return[{component:e,page:t}].concat(this.getAllChildrenComponent(e).map((function(e){return{component:e,page:t}})))},t.prototype.getAllChildrenComponent=function(t){var e=this,n=Array.from(t.components().models);return n.concat(n.map((function(t){return e.getAllChildrenComponent(t)})).flat())},t}(),o=void 0&&(void 0).__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var s,i=0,o=e.length;i<o;i++)!s&&i in e||(s||(s=Array.prototype.slice.call(e,0,i)),s[i]=e[i]);return t.concat(s||Array.prototype.slice.call(e))},r='notifications:changed',a='notifications:added',l='notifications:removed',c='notifications:cleared',h=function(){function t(t,e,n){var s=this;this.editor=e,this.options=n,this.notifications=[],this.notifications=t.map((function(t){if('object'==typeof t&&t.message){return new i(s.editor,t,(function(t){return s.remove(t)}))}return t})).filter(Boolean)}return t.prototype.getAll=function(){return o([],this.notifications,!0)},t.prototype.add=function(t){var e=this,n=new i(this.editor,t,(function(t){return e.remove(t)}));this.notifications.push(n),this.editor.trigger(a,n),this.editor.trigger(r,this.getAll())},t.prototype.remove=function(t){var e=this.notifications.findIndex((function(e){return e===t||e.model===t}));if(e>-1){var n=this.notifications.splice(e,1)[0];this.editor.trigger(l,n),this.editor.trigger(r,this.getAll())}},t.prototype.reset=function(){this.notifications=[],this.editor.trigger(c),this.editor.trigger(r,this.getAll())},t}();const p=globalThis,d=p.ShadowRoot&&(void 0===p.ShadyCSS||p.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,u=Symbol(),f=new WeakMap;class g{constructor(t,e,n){if(this._$cssResult$=!0,n!==u)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(d&&void 0===t){const n=void 0!==e&&1===e.length;n&&(t=f.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),n&&f.set(e,t))}return t}toString(){return this.cssText}}const m=(t,e)=>{if(d)t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const n of e){const e=document.createElement("style"),s=p.litNonce;void 0!==s&&e.setAttribute("nonce",s),e.textContent=n.cssText,t.appendChild(e)}},_=d?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return(t=>new g("string"==typeof t?t:t+"",void 0,u))(e)})(t):t,{is:y,defineProperty:$,getOwnPropertyDescriptor:v,getOwnPropertyNames:A,getOwnPropertySymbols:b,getPrototypeOf:E}=Object,C=globalThis,S=C.trustedTypes,j=S?S.emptyScript:"",w=C.reactiveElementPolyfillSupport,x=(t,e)=>t,O={toAttribute(t,e){switch(e){case Boolean:t=t?j:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=null!==t;break;case Number:n=null===t?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch(t){n=null}}return n}},P=(t,e)=>!y(t,e),I={attribute:!0,type:String,converter:O,reflect:!1,useDefault:!1,hasChanged:P};Symbol.metadata??=Symbol("metadata"),C.litPropertyMetadata??=new WeakMap;class T extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=I){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const n=Symbol(),s=this.getPropertyDescriptor(t,n,e);void 0!==s&&$(this.prototype,t,s)}}static getPropertyDescriptor(t,e,n){const{get:s,set:i}=v(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:s,set(e){const o=s?.call(this);i?.call(this,e),this.requestUpdate(t,o,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??I}static _$Ei(){if(this.hasOwnProperty(x("elementProperties")))return;const t=E(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(x("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(x("properties"))){const t=this.properties,e=[...A(t),...b(t)];for(const n of e)this.createProperty(n,t[n])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,n]of e)this.elementProperties.set(t,n)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const n=this._$Eu(t,e);void 0!==n&&this._$Eh.set(n,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const n=new Set(t.flat(1/0).reverse());for(const t of n)e.unshift(_(t))}else void 0!==t&&e.push(_(t));return e}static _$Eu(t,e){const n=e.attribute;return!1===n?void 0:"string"==typeof n?n:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)))}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const n of e.keys())this.hasOwnProperty(n)&&(t.set(n,this[n]),delete this[n]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return m(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach((t=>t.hostConnected?.()))}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()))}attributeChangedCallback(t,e,n){this._$AK(t,n)}_$ET(t,e){const n=this.constructor.elementProperties.get(t),s=this.constructor._$Eu(t,n);if(void 0!==s&&!0===n.reflect){const i=(void 0!==n.converter?.toAttribute?n.converter:O).toAttribute(e,n.type);this._$Em=t,null==i?this.removeAttribute(s):this.setAttribute(s,i),this._$Em=null}}_$AK(t,e){const n=this.constructor,s=n._$Eh.get(t);if(void 0!==s&&this._$Em!==s){const t=n.getPropertyOptions(s),i="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:O;this._$Em=s,this[s]=i.fromAttribute(e,t.type)??this._$Ej?.get(s)??null,this._$Em=null}}requestUpdate(t,e,n){if(void 0!==t){const s=this.constructor,i=this[t];if(n??=s.getPropertyOptions(t),!((n.hasChanged??P)(i,e)||n.useDefault&&n.reflect&&i===this._$Ej?.get(t)&&!this.hasAttribute(s._$Eu(t,n))))return;this.C(t,e,n)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:n,reflect:s,wrapped:i},o){n&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,o??e??this[t]),!0!==i||void 0!==o)||(this._$AL.has(t)||(this.hasUpdated||n||(e=void 0),this._$AL.set(t,e)),!0===s&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,e]of this._$Ep)this[t]=e;this._$Ep=void 0}const t=this.constructor.elementProperties;if(t.size>0)for(const[e,n]of t){const{wrapped:t}=n,s=this[e];!0!==t||this._$AL.has(e)||void 0===s||this.C(e,void 0,n,s)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(e)):this._$EM()}catch(e){throw t=!1,this._$EM(),e}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach((t=>this._$ET(t,this[t]))),this._$EM()}updated(t){}firstUpdated(t){}}T.elementStyles=[],T.shadowRootOptions={mode:"open"},T[x("elementProperties")]=new Map,T[x("finalized")]=new Map,w?.({ReactiveElement:T}),(C.reactiveElementVersions??=[]).push("2.1.0");const N=globalThis,M=N.trustedTypes,U=M?M.createPolicy("lit-html",{createHTML:t=>t}):void 0,H="$lit$",R=`lit$${Math.random().toFixed(9).slice(2)}$`,k="?"+R,D=`<${k}>`,z=document,L=()=>z.createComment(""),B=t=>null===t||"object"!=typeof t&&"function"!=typeof t,K=Array.isArray,F=t=>K(t)||"function"==typeof t?.[Symbol.iterator],V="[ \t\n\f\r]",W=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,q=/-->/g,J=/>/g,Z=RegExp(`>|${V}(?:([^\\s"'>=/]+)(${V}*=${V}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),G=/'/g,Q=/"/g,X=/^(?:script|style|textarea|title)$/i,Y=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),tt=Y(1),et=(Y(2),Y(3),Symbol.for("lit-noChange")),nt=Symbol.for("lit-nothing"),st=new WeakMap,it=z.createTreeWalker(z,129);function ot(t,e){if(!K(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==U?U.createHTML(e):e}const rt=(t,e)=>{const n=t.length-1,s=[];let i,o=2===e?"<svg>":3===e?"<math>":"",r=W;for(let e=0;e<n;e++){const n=t[e];let a,l,c=-1,h=0;for(;h<n.length&&(r.lastIndex=h,l=r.exec(n),null!==l);)h=r.lastIndex,r===W?"!--"===l[1]?r=q:void 0!==l[1]?r=J:void 0!==l[2]?(X.test(l[2])&&(i=RegExp("</"+l[2],"g")),r=Z):void 0!==l[3]&&(r=Z):r===Z?">"===l[0]?(r=i??W,c=-1):void 0===l[1]?c=-2:(c=r.lastIndex-l[2].length,a=l[1],r=void 0===l[3]?Z:'"'===l[3]?Q:G):r===Q||r===G?r=Z:r===q||r===J?r=W:(r=Z,i=void 0);const p=r===Z&&t[e+1].startsWith("/>")?" ":"";o+=r===W?n+D:c>=0?(s.push(a),n.slice(0,c)+H+n.slice(c)+R+p):n+R+(-2===c?e:p)}return[ot(t,o+(t[n]||"<?>")+(2===e?"</svg>":3===e?"</math>":"")),s]};class at{constructor({strings:t,_$litType$:e},n){let s;this.parts=[];let i=0,o=0;const r=t.length-1,a=this.parts,[l,c]=rt(t,e);if(this.el=at.createElement(l,n),it.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(s=it.nextNode())&&a.length<r;){if(1===s.nodeType){if(s.hasAttributes())for(const t of s.getAttributeNames())if(t.endsWith(H)){const e=c[o++],n=s.getAttribute(t).split(R),r=/([.?@])?(.*)/.exec(e);a.push({type:1,index:i,name:r[2],strings:n,ctor:"."===r[1]?dt:"?"===r[1]?ut:"@"===r[1]?ft:pt}),s.removeAttribute(t)}else t.startsWith(R)&&(a.push({type:6,index:i}),s.removeAttribute(t));if(X.test(s.tagName)){const t=s.textContent.split(R),e=t.length-1;if(e>0){s.textContent=M?M.emptyScript:"";for(let n=0;n<e;n++)s.append(t[n],L()),it.nextNode(),a.push({type:2,index:++i});s.append(t[e],L())}}}else if(8===s.nodeType)if(s.data===k)a.push({type:2,index:i});else{let t=-1;for(;-1!==(t=s.data.indexOf(R,t+1));)a.push({type:7,index:i}),t+=R.length-1}i++}}static createElement(t,e){const n=z.createElement("template");return n.innerHTML=t,n}}function lt(t,e,n=t,s){if(e===et)return e;let i=void 0!==s?n._$Co?.[s]:n._$Cl;const o=B(e)?void 0:e._$litDirective$;return i?.constructor!==o&&(i?._$AO?.(!1),void 0===o?i=void 0:(i=new o(t),i._$AT(t,n,s)),void 0!==s?(n._$Co??=[])[s]=i:n._$Cl=i),void 0!==i&&(e=lt(t,i._$AS(t,e.values),i,s)),e}class ct{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:n}=this._$AD,s=(t?.creationScope??z).importNode(e,!0);it.currentNode=s;let i=it.nextNode(),o=0,r=0,a=n[0];for(;void 0!==a;){if(o===a.index){let e;2===a.type?e=new ht(i,i.nextSibling,this,t):1===a.type?e=new a.ctor(i,a.name,a.strings,this,t):6===a.type&&(e=new gt(i,this,t)),this._$AV.push(e),a=n[++r]}o!==a?.index&&(i=it.nextNode(),o++)}return it.currentNode=z,s}p(t){let e=0;for(const n of this._$AV)void 0!==n&&(void 0!==n.strings?(n._$AI(t,n,e),e+=n.strings.length-2):n._$AI(t[e])),e++}}class ht{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,n,s){this.type=2,this._$AH=nt,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=n,this.options=s,this._$Cv=s?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t?.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=lt(this,t,e),B(t)?t===nt||null==t||""===t?(this._$AH!==nt&&this._$AR(),this._$AH=nt):t!==this._$AH&&t!==et&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):F(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==nt&&B(this._$AH)?this._$AA.nextSibling.data=t:this.T(z.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:n}=t,s="number"==typeof n?this._$AC(t):(void 0===n.el&&(n.el=at.createElement(ot(n.h,n.h[0]),this.options)),n);if(this._$AH?._$AD===s)this._$AH.p(e);else{const t=new ct(s,this),n=t.u(this.options);t.p(e),this.T(n),this._$AH=t}}_$AC(t){let e=st.get(t.strings);return void 0===e&&st.set(t.strings,e=new at(t)),e}k(t){K(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let n,s=0;for(const i of t)s===e.length?e.push(n=new ht(this.O(L()),this.O(L()),this,this.options)):n=e[s],n._$AI(i),s++;s<e.length&&(this._$AR(n&&n._$AB.nextSibling,s),e.length=s)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t))}}class pt{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,n,s,i){this.type=1,this._$AH=nt,this._$AN=void 0,this.element=t,this.name=e,this._$AM=s,this.options=i,n.length>2||""!==n[0]||""!==n[1]?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=nt}_$AI(t,e=this,n,s){const i=this.strings;let o=!1;if(void 0===i)t=lt(this,t,e,0),o=!B(t)||t!==this._$AH&&t!==et,o&&(this._$AH=t);else{const s=t;let r,a;for(t=i[0],r=0;r<i.length-1;r++)a=lt(this,s[n+r],e,r),a===et&&(a=this._$AH[r]),o||=!B(a)||a!==this._$AH[r],a===nt?t=nt:t!==nt&&(t+=(a??"")+i[r+1]),this._$AH[r]=a}o&&!s&&this.j(t)}j(t){t===nt?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class dt extends pt{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===nt?void 0:t}}class ut extends pt{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==nt)}}class ft extends pt{constructor(t,e,n,s,i){super(t,e,n,s,i),this.type=5}_$AI(t,e=this){if((t=lt(this,t,e,0)??nt)===et)return;const n=this._$AH,s=t===nt&&n!==nt||t.capture!==n.capture||t.once!==n.once||t.passive!==n.passive,i=t!==nt&&(n===nt||s);s&&this.element.removeEventListener(this.name,this,n),i&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}}class gt{constructor(t,e,n){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=n}get _$AU(){return this._$AM._$AU}_$AI(t){lt(this,t)}}const mt=N.litHtmlPolyfillSupport;mt?.(at,ht),(N.litHtmlVersions??=[]).push("3.3.0");const _t=(t,e,n)=>{const s=n?.renderBefore??e;let i=s._$litPart$;if(void 0===i){const t=n?.renderBefore??null;s._$litPart$=i=new ht(e.insertBefore(L(),t),t,void 0,n??{})}return i._$AI(t),i},yt=globalThis;class $t extends T{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=_t(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return et}}$t._$litElement$=!0,$t["finalized"]=!0,yt.litElementHydrateSupport?.({LitElement:$t});const vt=yt.litElementPolyfillSupport;vt?.({LitElement:$t});(yt.litElementVersions??=[]).push("4.2.0");const At=1,bt=2,Et=t=>(...e)=>({_$litDirective$:t,values:e});class Ct{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,n){this._$Ct=t,this._$AM=e,this._$Ci=n}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}const St=Et(class extends Ct{constructor(t){if(super(t),t.type!==At||"class"!==t.name||t.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return" "+Object.keys(t).filter((e=>t[e])).join(" ")+" "}update(t,[e]){if(void 0===this.st){this.st=new Set,void 0!==t.strings&&(this.nt=new Set(t.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in e)e[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(e)}const n=t.element.classList;for(const t of this.st)t in e||(n.remove(t),this.st.delete(t));for(const t in e){const s=!!e[t];s===this.st.has(t)||this.nt?.has(t)||(s?(n.add(t),this.st.add(t)):(n.remove(t),this.st.delete(t)))}return et}});class jt extends Ct{constructor(t){if(super(t),this.it=nt,t.type!==bt)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===nt||null==t)return this._t=void 0,this.it=t;if(t===et)return t;if("string"!=typeof t)throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.it)return this._t;this.it=t;const e=[t];return e.raw=e,this._t={_$litType$:this.constructor.resultType,strings:e,values:[]}}}jt.directiveName="unsafeHTML",jt.resultType=1;const wt=Et(jt);var xt,Ot,Pt,It,Tt,Nt=void 0&&(void 0).__makeTemplateObject||function(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t},Mt=void 0&&(void 0).__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var s,i=0,o=e.length;i<o;i++)!s&&i in e||(s||(s=Array.prototype.slice.call(e,0,i)),s[i]=e[i]);return t.concat(s||Array.prototype.slice.call(e))};function Ut(t,e,n,s){var i=Mt([],n,!0);s.reverse&&i.reverse();var o=function(t){var e={},n=[];return t.forEach((function(t){t.group&&!e[t.group]?(e[t.group]=!0,n.push(t.group)):t.group||n.push(t)})),n}(i).slice(0,s.maxNotifications||i.length);_t(tt(xt||(xt=Nt(["\n <style>\n .gjs-notification {\n top: 10px;\n right: 10px;\n max-width: 300px;\n z-index: 9999;\n list-style: none;\n padding: 10px;\n margin: 10px;\n font-family: var(--gjs-main-font);\n font-size: var(--gjs-font-size);\n max-height: 80vh;\n overflow-y: auto;\n }\n .gjs-notification details summary {\n list-style: none;\n }\n .gjs-notification li {\n border-radius: 5px;\n margin: 10px 0;\n padding: 10px;\n list-style: none;\n }\n .gjs-notification ul {\n padding: 0;\n }\n </style>\n <ul class=\"gjs-notification\">\n ","\n </ul>\n "],["\n <style>\n .gjs-notification {\n top: 10px;\n right: 10px;\n max-width: 300px;\n z-index: 9999;\n list-style: none;\n padding: 10px;\n margin: 10px;\n font-family: var(--gjs-main-font);\n font-size: var(--gjs-font-size);\n max-height: 80vh;\n overflow-y: auto;\n }\n .gjs-notification details summary {\n list-style: none;\n }\n .gjs-notification li {\n border-radius: 5px;\n margin: 10px 0;\n padding: 10px;\n list-style: none;\n }\n .gjs-notification ul {\n padding: 0;\n }\n </style>\n <ul class=\"gjs-notification\">\n ","\n </ul>\n "])),o.map((function(e){return'string'==typeof e?function(t,e,n,s){return tt(Pt||(Pt=Nt(["\n <li class=\"gjs-sm gjs-one-bg gjs-two-color gjs-notification__group\">\n <details class=\"gjs-sm gjs-one-bg gjs-two-color\">\n <summary class=\"gjs-sm-header gjs-label\">\n <div>📌 ","</div>\n <button @click="," class=\"gjs-btn-prim\">","</button>\n <button\n @click=","\n class=\"gjs-btn-prim\"\n >","</button>\n </summary>\n <ul>\n ","\n </ul>\n </details>\n </li>\n "],["\n <li class=\"gjs-sm gjs-one-bg gjs-two-color gjs-notification__group\">\n <details class=\"gjs-sm gjs-one-bg gjs-two-color\">\n <summary class=\"gjs-sm-header gjs-label\">\n <div>\\u{1F4CC} ","</div>\n <button @click="," class=\"gjs-btn-prim\">","</button>\n <button\n @click=","\n class=\"gjs-btn-prim\"\n >","</button>\n </summary>\n <ul>\n ","\n </ul>\n </details>\n </li>\n "])),n,(function(){return s.forEach((function(t){return t.remove()}))}),t.I18n.t('@silexlabs/grapesjs-notifications.CloseAll'),(function(t){return t.currentTarget.closest('details').toggleAttribute('open')}),t.I18n.t('@silexlabs/grapesjs-notifications.Show'),s.slice(0,e.maxNotifications||s.length).map((function(e){return tt(Ot||(Ot=Nt(["\n ","\n "],["\n ","\n "])),Ht(t,e))})))}(t,s,e,i.filter((function(t){return t.group===e}))):Ht(t,e)}))),function(t){if('string'==typeof t)return document.querySelector(t);return t}(e))}function Ht(t,e){return tt(Tt||(Tt=Nt(["\n <li class=",">\n <header class=\"gjs-sm-header gjs-label\">\n <span>","</span>\n <span class=\"gjs-sm-header\">","</span>\n </header>\n <footer class=\"gjs-sm-footer\">\n <button @click="," class=\"gjs-btn-prim\">","</button>\n ","\n </footer>\n </li>\n "],["\n <li class=",">\n <header class=\"gjs-sm-header gjs-label\">\n <span>","</span>\n <span class=\"gjs-sm-header\">","</span>\n </header>\n <footer class=\"gjs-sm-footer\">\n <button @click="," class=\"gjs-btn-prim\">","</button>\n ","\n </footer>\n </li>\n "])),St({'gjs-sm':!0,'gjs-one-bg':!0,'gjs-two-color':!0,'gjs-notification__item':!0,'gjs-notification__info':'info'===e.type,'gjs-notification__warning':'warning'===e.type,'gjs-notification__error':'error'===e.type,'gjs-notification__success':'success'===e.type}),e.getSvgIcon(e.type),wt(e.message),(function(){return e.remove()}),t.I18n.t('@silexlabs/grapesjs-notifications.Close'),e.componentId?tt(It||(It=Nt(["\n <button @click="," class=\"gjs-btn-prim\">","</button>\n "],["\n <button @click="," class=\"gjs-btn-prim\">","</button>\n "])),(function(){return e.select()}),t.I18n.t('@silexlabs/grapesjs-notifications.Select')):'')}var Rt=function(){function t(t){this.storeKey=t}return t.prototype.getAll=function(){return this.storeKey?JSON.parse(localStorage.getItem(this.storeKey)||'[]'):[]},t.prototype.save=function(t){this.storeKey&&localStorage.setItem(this.storeKey,JSON.stringify(t.map((function(t){var e;return{message:t.message,type:t.type,componentId:t.componentId,group:t.group,timeout:null===(e=t.options)||void 0===e?void 0:e.timeout}}))))},t}(),kt=void 0&&(void 0).__assign||function(){return kt=Object.assign||function(t){for(var e,n=1,s=arguments.length;n<s;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},kt.apply(this,arguments)},Dt='notifications:add',zt='notifications:remove',Lt='notifications:clear';function Bt(t){if(t)return t;var e=document.createElement('ul');return e.style.position='fixed',e.style.bottom='10px',e.style.zIndex='9999',document.body.appendChild(e),e}const Kt=function(t,e){void 0===e&&(e={});var s=kt({i18n:{},container:Bt(e.container),storeKey:void 0,maxNotifications:50,reverse:!1},e);t.I18n&&t.I18n.addMessages(kt({en:n},s.i18n));var i=s.storeKey?new Rt(s.storeKey):null,o=new h((null==i?void 0:i.getAll())||[],t,s);return t.Commands.add(Dt,{run:function(t,e,n){o.add(n)}}),t.Commands.add(zt,{run:function(t,e,n){var s=(null==n?void 0:n.notification)||n;o.remove(s)}}),t.Commands.add(Lt,{run:function(t){o.reset()}}),t.on(r,(function(e){var n=e||o.getAll();null==i||i.save(n),Ut(t,s.container,n,s)})),{getAll:function(){return o.getAll()},add:function(e){return t.runCommand(Dt,e)},remove:function(e){return t.runCommand(zt,e)},clear:function(){return t.runCommand(Lt)}}};return e})())); //# sourceMappingURL=index.js.map