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 28.5 kB
/*! @silexlabs/grapesjs-notifications - 0.3.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 i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},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:()=>n,NOTIFICATION_ADDED:()=>d,NOTIFICATION_CHANGED:()=>h,NOTIFICATION_CLEAR:()=>s,NOTIFICATION_CLEARED:()=>u,NOTIFICATION_LIST:()=>o,NOTIFICATION_REMOVE:()=>i,NOTIFICATION_REMOVED:()=>p,Notification:()=>l,default:()=>Ft});var n='notifications:add',i='notifications:remove',s='notifications:clear',o='notifications:list';const r={'@silexlabs/grapesjs-notifications':{Close:'✖ Dismiss',CloseAll:'✖ Dismiss all',Select:'✓ Select element',Show:'↓ Show'}};var a=void 0&&(void 0).__assign||function(){return a=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var s in e=arguments[n])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},a.apply(this,arguments)},l=function(){function t(t,e,n){var i=this;this.editor=t,this.id=null,this.componentId=null,this.group=null,this.options=this.getDefaultOptions(e),this.removeCallback=n,this.options.timeout&&(this.timeoutRef=setTimeout((function(){return i.remove()}),this.options.timeout)),this.id=e.id||null,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,i=e.page;this.editor.Pages.select(i),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 a({icons:a({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}(),c=void 0&&(void 0).__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var i,s=0,o=e.length;s<o;s++)!i&&s in e||(i||(i=Array.prototype.slice.call(e,0,s)),i[s]=e[s]);return t.concat(i||Array.prototype.slice.call(e))},h='notifications:changed',d='notifications:added',p='notifications:removed',u='notifications:cleared',f=function(){function t(t,e,n){var i=this;this.editor=e,this.options=n,this.notifications=[],this.notifications=t.map((function(t){if('object'==typeof t&&t.message){return new l(i.editor,t,(function(t){return i.remove(t)}))}return t})).filter(Boolean)}return t.prototype.getAll=function(){return c([],this.notifications,!0)},t.prototype.add=function(t){var e=this;if(t.id){var n=this.notifications.find((function(e){return e.options.id===t.id}));n&&this.remove(n)}var i=new l(this.editor,t,(function(t){return e.remove(t)}));this.notifications.push(i),this.editor.trigger(d,i),this.editor.trigger(h,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(p,n),this.editor.trigger(h,this.getAll())}},t.prototype.reset=function(){this.notifications=[],this.editor.trigger(u),this.editor.trigger(h,this.getAll())},t}();const g=globalThis,m=g.ShadowRoot&&(void 0===g.ShadyCSS||g.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,y=Symbol(),_=new WeakMap;class ${constructor(t,e,n){if(this._$cssResult$=!0,n!==y)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(m&&void 0===t){const n=void 0!==e&&1===e.length;n&&(t=_.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),n&&_.set(e,t))}return t}toString(){return this.cssText}}const v=(t,e)=>{if(m)t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const n of e){const e=document.createElement("style"),i=g.litNonce;void 0!==i&&e.setAttribute("nonce",i),e.textContent=n.cssText,t.appendChild(e)}},A=m?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return(t=>new $("string"==typeof t?t:t+"",void 0,y))(e)})(t):t,{is:b,defineProperty:w,getOwnPropertyDescriptor:E,getOwnPropertyNames:C,getOwnPropertySymbols:S,getPrototypeOf:j}=Object,x=globalThis,O=x.trustedTypes,I=O?O.emptyScript:"",T=x.reactiveElementPolyfillSupport,P=(t,e)=>t,N={toAttribute(t,e){switch(e){case Boolean:t=t?I: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}},M=(t,e)=>!b(t,e),U={attribute:!0,type:String,converter:N,reflect:!1,useDefault:!1,hasChanged:M};Symbol.metadata??=Symbol("metadata"),x.litPropertyMetadata??=new WeakMap;class R 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=U){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(),i=this.getPropertyDescriptor(t,n,e);void 0!==i&&w(this.prototype,t,i)}}static getPropertyDescriptor(t,e,n){const{get:i,set:s}=E(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:i,set(e){const o=i?.call(this);s?.call(this,e),this.requestUpdate(t,o,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??U}static _$Ei(){if(this.hasOwnProperty(P("elementProperties")))return;const t=j(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(P("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(P("properties"))){const t=this.properties,e=[...C(t),...S(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(A(t))}else void 0!==t&&e.push(A(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 v(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),i=this.constructor._$Eu(t,n);if(void 0!==i&&!0===n.reflect){const s=(void 0!==n.converter?.toAttribute?n.converter:N).toAttribute(e,n.type);this._$Em=t,null==s?this.removeAttribute(i):this.setAttribute(i,s),this._$Em=null}}_$AK(t,e){const n=this.constructor,i=n._$Eh.get(t);if(void 0!==i&&this._$Em!==i){const t=n.getPropertyOptions(i),s="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:N;this._$Em=i,this[i]=s.fromAttribute(e,t.type)??this._$Ej?.get(i)??null,this._$Em=null}}requestUpdate(t,e,n){if(void 0!==t){const i=this.constructor,s=this[t];if(n??=i.getPropertyOptions(t),!((n.hasChanged??M)(s,e)||n.useDefault&&n.reflect&&s===this._$Ej?.get(t)&&!this.hasAttribute(i._$Eu(t,n))))return;this.C(t,e,n)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:n,reflect:i,wrapped:s},o){n&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,o??e??this[t]),!0!==s||void 0!==o)||(this._$AL.has(t)||(this.hasUpdated||n||(e=void 0),this._$AL.set(t,e)),!0===i&&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,i=this[e];!0!==t||this._$AL.has(e)||void 0===i||this.C(e,void 0,n,i)}}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){}}R.elementStyles=[],R.shadowRootOptions={mode:"open"},R[P("elementProperties")]=new Map,R[P("finalized")]=new Map,T?.({ReactiveElement:R}),(x.reactiveElementVersions??=[]).push("2.1.0");const H=globalThis,k=H.trustedTypes,D=k?k.createPolicy("lit-html",{createHTML:t=>t}):void 0,z="$lit$",L=`lit$${Math.random().toFixed(9).slice(2)}$`,B="?"+L,q=`<${B}>`,F=document,K=()=>F.createComment(""),V=t=>null===t||"object"!=typeof t&&"function"!=typeof t,W=Array.isArray,J=t=>W(t)||"function"==typeof t?.[Symbol.iterator],Z="[ \t\n\f\r]",G=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Q=/-->/g,X=/>/g,Y=RegExp(`>|${Z}(?:([^\\s"'>=/]+)(${Z}*=${Z}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),tt=/'/g,et=/"/g,nt=/^(?:script|style|textarea|title)$/i,it=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),st=it(1),ot=(it(2),it(3),Symbol.for("lit-noChange")),rt=Symbol.for("lit-nothing"),at=new WeakMap,lt=F.createTreeWalker(F,129);function ct(t,e){if(!W(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==D?D.createHTML(e):e}const ht=(t,e)=>{const n=t.length-1,i=[];let s,o=2===e?"<svg>":3===e?"<math>":"",r=G;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===G?"!--"===l[1]?r=Q:void 0!==l[1]?r=X:void 0!==l[2]?(nt.test(l[2])&&(s=RegExp("</"+l[2],"g")),r=Y):void 0!==l[3]&&(r=Y):r===Y?">"===l[0]?(r=s??G,c=-1):void 0===l[1]?c=-2:(c=r.lastIndex-l[2].length,a=l[1],r=void 0===l[3]?Y:'"'===l[3]?et:tt):r===et||r===tt?r=Y:r===Q||r===X?r=G:(r=Y,s=void 0);const d=r===Y&&t[e+1].startsWith("/>")?" ":"";o+=r===G?n+q:c>=0?(i.push(a),n.slice(0,c)+z+n.slice(c)+L+d):n+L+(-2===c?e:d)}return[ct(t,o+(t[n]||"<?>")+(2===e?"</svg>":3===e?"</math>":"")),i]};class dt{constructor({strings:t,_$litType$:e},n){let i;this.parts=[];let s=0,o=0;const r=t.length-1,a=this.parts,[l,c]=ht(t,e);if(this.el=dt.createElement(l,n),lt.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(i=lt.nextNode())&&a.length<r;){if(1===i.nodeType){if(i.hasAttributes())for(const t of i.getAttributeNames())if(t.endsWith(z)){const e=c[o++],n=i.getAttribute(t).split(L),r=/([.?@])?(.*)/.exec(e);a.push({type:1,index:s,name:r[2],strings:n,ctor:"."===r[1]?mt:"?"===r[1]?yt:"@"===r[1]?_t:gt}),i.removeAttribute(t)}else t.startsWith(L)&&(a.push({type:6,index:s}),i.removeAttribute(t));if(nt.test(i.tagName)){const t=i.textContent.split(L),e=t.length-1;if(e>0){i.textContent=k?k.emptyScript:"";for(let n=0;n<e;n++)i.append(t[n],K()),lt.nextNode(),a.push({type:2,index:++s});i.append(t[e],K())}}}else if(8===i.nodeType)if(i.data===B)a.push({type:2,index:s});else{let t=-1;for(;-1!==(t=i.data.indexOf(L,t+1));)a.push({type:7,index:s}),t+=L.length-1}s++}}static createElement(t,e){const n=F.createElement("template");return n.innerHTML=t,n}}function pt(t,e,n=t,i){if(e===ot)return e;let s=void 0!==i?n._$Co?.[i]:n._$Cl;const o=V(e)?void 0:e._$litDirective$;return s?.constructor!==o&&(s?._$AO?.(!1),void 0===o?s=void 0:(s=new o(t),s._$AT(t,n,i)),void 0!==i?(n._$Co??=[])[i]=s:n._$Cl=s),void 0!==s&&(e=pt(t,s._$AS(t,e.values),s,i)),e}class ut{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,i=(t?.creationScope??F).importNode(e,!0);lt.currentNode=i;let s=lt.nextNode(),o=0,r=0,a=n[0];for(;void 0!==a;){if(o===a.index){let e;2===a.type?e=new ft(s,s.nextSibling,this,t):1===a.type?e=new a.ctor(s,a.name,a.strings,this,t):6===a.type&&(e=new $t(s,this,t)),this._$AV.push(e),a=n[++r]}o!==a?.index&&(s=lt.nextNode(),o++)}return lt.currentNode=F,i}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 ft{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,n,i){this.type=2,this._$AH=rt,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=n,this.options=i,this._$Cv=i?.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=pt(this,t,e),V(t)?t===rt||null==t||""===t?(this._$AH!==rt&&this._$AR(),this._$AH=rt):t!==this._$AH&&t!==ot&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):J(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!==rt&&V(this._$AH)?this._$AA.nextSibling.data=t:this.T(F.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:n}=t,i="number"==typeof n?this._$AC(t):(void 0===n.el&&(n.el=dt.createElement(ct(n.h,n.h[0]),this.options)),n);if(this._$AH?._$AD===i)this._$AH.p(e);else{const t=new ut(i,this),n=t.u(this.options);t.p(e),this.T(n),this._$AH=t}}_$AC(t){let e=at.get(t.strings);return void 0===e&&at.set(t.strings,e=new dt(t)),e}k(t){W(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let n,i=0;for(const s of t)i===e.length?e.push(n=new ft(this.O(K()),this.O(K()),this,this.options)):n=e[i],n._$AI(s),i++;i<e.length&&(this._$AR(n&&n._$AB.nextSibling,i),e.length=i)}_$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 gt{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,n,i,s){this.type=1,this._$AH=rt,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=s,n.length>2||""!==n[0]||""!==n[1]?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=rt}_$AI(t,e=this,n,i){const s=this.strings;let o=!1;if(void 0===s)t=pt(this,t,e,0),o=!V(t)||t!==this._$AH&&t!==ot,o&&(this._$AH=t);else{const i=t;let r,a;for(t=s[0],r=0;r<s.length-1;r++)a=pt(this,i[n+r],e,r),a===ot&&(a=this._$AH[r]),o||=!V(a)||a!==this._$AH[r],a===rt?t=rt:t!==rt&&(t+=(a??"")+s[r+1]),this._$AH[r]=a}o&&!i&&this.j(t)}j(t){t===rt?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class mt extends gt{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===rt?void 0:t}}class yt extends gt{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==rt)}}class _t extends gt{constructor(t,e,n,i,s){super(t,e,n,i,s),this.type=5}_$AI(t,e=this){if((t=pt(this,t,e,0)??rt)===ot)return;const n=this._$AH,i=t===rt&&n!==rt||t.capture!==n.capture||t.once!==n.once||t.passive!==n.passive,s=t!==rt&&(n===rt||i);i&&this.element.removeEventListener(this.name,this,n),s&&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 $t{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){pt(this,t)}}const vt=H.litHtmlPolyfillSupport;vt?.(dt,ft),(H.litHtmlVersions??=[]).push("3.3.0");const At=(t,e,n)=>{const i=n?.renderBefore??e;let s=i._$litPart$;if(void 0===s){const t=n?.renderBefore??null;i._$litPart$=s=new ft(e.insertBefore(K(),t),t,void 0,n??{})}return s._$AI(t),s},bt=globalThis;class wt extends R{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=At(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return ot}}wt._$litElement$=!0,wt["finalized"]=!0,bt.litElementHydrateSupport?.({LitElement:wt});const Et=bt.litElementPolyfillSupport;Et?.({LitElement:wt});(bt.litElementVersions??=[]).push("4.2.0");const Ct=1,St=2,jt=t=>(...e)=>({_$litDirective$:t,values:e});class xt{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 Ot=jt(class extends xt{constructor(t){if(super(t),t.type!==Ct||"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 i=!!e[t];i===this.st.has(t)||this.nt?.has(t)||(i?(n.add(t),this.st.add(t)):(n.remove(t),this.st.delete(t)))}return ot}});class It extends xt{constructor(t){if(super(t),this.it=rt,t.type!==St)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===rt||null==t)return this._t=void 0,this.it=t;if(t===ot)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:[]}}}It.directiveName="unsafeHTML",It.resultType=1;const Tt=jt(It);var Pt,Nt,Mt,Ut,Rt,Ht=void 0&&(void 0).__makeTemplateObject||function(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t},kt=void 0&&(void 0).__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var i,s=0,o=e.length;s<o;s++)!i&&s in e||(i||(i=Array.prototype.slice.call(e,0,s)),i[s]=e[s]);return t.concat(i||Array.prototype.slice.call(e))};function Dt(t,e,n,i){var s=kt([],n,!0);i.reverse&&s.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}(s).slice(0,i.maxNotifications||s.length);At(st(Pt||(Pt=Ht(["\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,i){return st(Mt||(Mt=Ht(["\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 i.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'),i.slice(0,e.maxNotifications||i.length).map((function(e){return st(Nt||(Nt=Ht(["\n ","\n "],["\n ","\n "])),zt(t,e))})))}(t,i,e,s.filter((function(t){return t.group===e}))):zt(t,e)}))),function(t){if('string'==typeof t)return document.querySelector(t);return t}(e))}function zt(t,e){return st(Rt||(Rt=Ht(["\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 "])),Ot({'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),Tt(e.message),(function(){return e.remove()}),t.I18n.t('@silexlabs/grapesjs-notifications.Close'),e.componentId?st(Ut||(Ut=Ht(["\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 Lt=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}(),Bt=void 0&&(void 0).__assign||function(){return Bt=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var s in e=arguments[n])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},Bt.apply(this,arguments)};function qt(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 Ft=function(t,e){void 0===e&&(e={});var a=Bt({i18n:{},container:qt(e.container),storeKey:void 0,maxNotifications:50,reverse:!1},e);t.I18n&&t.I18n.addMessages(Bt({en:r},a.i18n));var l=a.storeKey?new Lt(a.storeKey):null,c=new f((null==l?void 0:l.getAll())||[],t,a);return t.Commands.add(n,{run:function(t,e,n){if(!(null==n?void 0:n.type))throw new Error('Required: type (one of: info, warning, error, success)');if(!(null==n?void 0:n.message))throw new Error('Required: message (notification text)');if(!['info','warning','error','success'].includes(n.type))throw new Error("Invalid type \"".concat(n.type,"\". Must be one of: info, warning, error, success"));c.add(n)}}),t.Commands.add(i,{run:function(t,e,n){var i=(null==n?void 0:n.notification)||n;c.remove(i)}}),t.Commands.add(s,{run:function(t){c.reset()}}),t.Commands.add(o,{run:function(){return c.getAll().map((function(t){return{type:t.type,message:t.message,group:t.group}}))}}),t.on(h,(function(e){var n=e||c.getAll();null==l||l.save(n),Dt(t,a.container,n,a)})),t.on('ai-capabilities:ready',(function(t){!function(t){t({id:n,command:n,description:'Show notification to user',inputSchema:{type:'object',required:['type','message'],properties:{type:{type:'string',enum:['info','warning','error','success']},message:{type:'string'},group:{type:'string'}}},tags:['notifications']}),t({id:s,command:s,description:'Clear all notifications',destructive:!0,tags:['notifications']}),t({id:o,command:o,description:'List all notifications',readOnly:!0,tags:['notifications']})}(t)})),{getAll:function(){return c.getAll()},add:function(e){return t.runCommand(n,e)},remove:function(e){return t.runCommand(i,e)},clear:function(){return t.runCommand(s)}}};return e})())); //# sourceMappingURL=index.js.map