UNPKG

@creaditor/newsletter-starterkit

Version:

Creaditor Newsletter Editor - Starterkit for creating beautiful email newsletters

171 lines 15.6 kB
/*! For license information please see 2605.creaditor.bundle.js.LICENSE.txt */ "use strict";(("undefined"!=typeof self?self:this).webpackChunkCreaditor=("undefined"!=typeof self?self:this).webpackChunkCreaditor||[]).push([[2605],{2605:(t,e,s)=>{s.r(e),s.d(e,{SendTestEmailsPlugin:()=>V});var i=s(21293);const r=globalThis,o=r.ShadowRoot&&(void 0===r.ShadyCSS||r.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,a=Symbol(),n=new WeakMap;const l=t=>new class{constructor(t,e,s){if(this._$cssResult$=!0,s!==a)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(o&&void 0===t){const s=void 0!==e&&1===e.length;s&&(t=n.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&n.set(e,t))}return t}toString(){return this.cssText}}("string"==typeof t?t:t+"",void 0,a),h=(t,e)=>{if(o)t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const s of e){const e=document.createElement("style"),i=r.litNonce;void 0!==i&&e.setAttribute("nonce",i),e.textContent=s.cssText,t.appendChild(e)}},p=o?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return l(e)})(t):t,{is:d,defineProperty:c,getOwnPropertyDescriptor:u,getOwnPropertyNames:m,getOwnPropertySymbols:f,getPrototypeOf:g}=Object,y=globalThis,v=y.trustedTypes,E=v?v.emptyScript:"",b=y.reactiveElementPolyfillSupport,$=(t,e)=>t,S={toAttribute(t,e){switch(e){case Boolean:t=t?E:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let s=t;switch(e){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t)}catch(t){s=null}}return s}},w=(t,e)=>!d(t,e),x={attribute:!0,type:String,converter:S,reflect:!1,useDefault:!1,hasChanged:w};Symbol.metadata??=Symbol("metadata"),y.litPropertyMetadata??=new WeakMap;class _ 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=x){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 s=Symbol(),i=this.getPropertyDescriptor(t,s,e);void 0!==i&&c(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){const{get:i,set:r}=u(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:i,set(e){const o=i?.call(this);r?.call(this,e),this.requestUpdate(t,o,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??x}static _$Ei(){if(this.hasOwnProperty($("elementProperties")))return;const t=g(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty($("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty($("properties"))){const t=this.properties,e=[...m(t),...f(t)];for(const s of e)this.createProperty(s,t[s])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,s]of e)this.elementProperties.set(t,s)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const s=this._$Eu(t,e);void 0!==s&&this._$Eh.set(s,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const t of s)e.unshift(p(t))}else void 0!==t&&e.push(p(t));return e}static _$Eu(t,e){const s=e.attribute;return!1===s?void 0:"string"==typeof s?s:"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 s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return h(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,s){this._$AK(t,s)}_$ET(t,e){const s=this.constructor.elementProperties.get(t),i=this.constructor._$Eu(t,s);if(void 0!==i&&!0===s.reflect){const r=(void 0!==s.converter?.toAttribute?s.converter:S).toAttribute(e,s.type);this._$Em=t,null==r?this.removeAttribute(i):this.setAttribute(i,r),this._$Em=null}}_$AK(t,e){const s=this.constructor,i=s._$Eh.get(t);if(void 0!==i&&this._$Em!==i){const t=s.getPropertyOptions(i),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:S;this._$Em=i;const o=r.fromAttribute(e,t.type);this[i]=o??this._$Ej?.get(i)??o,this._$Em=null}}requestUpdate(t,e,s){if(void 0!==t){const i=this.constructor,r=this[t];if(s??=i.getPropertyOptions(t),!((s.hasChanged??w)(r,e)||s.useDefault&&s.reflect&&r===this._$Ej?.get(t)&&!this.hasAttribute(i._$Eu(t,s))))return;this.C(t,e,s)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:s,reflect:i,wrapped:r},o){s&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,o??e??this[t]),!0!==r||void 0!==o)||(this._$AL.has(t)||(this.hasUpdated||s||(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,s]of t){const{wrapped:t}=s,i=this[e];!0!==t||this._$AL.has(e)||void 0===i||this.C(e,void 0,s,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){}}_.elementStyles=[],_.shadowRootOptions={mode:"open"},_[$("elementProperties")]=new Map,_[$("finalized")]=new Map,b?.({ReactiveElement:_}),(y.reactiveElementVersions??=[]).push("2.1.1");const C={attribute:!0,type:String,converter:S,reflect:!1,hasChanged:w},P=(t=C,e,s)=>{const{kind:i,metadata:r}=s;let o=globalThis.litPropertyMetadata.get(r);if(void 0===o&&globalThis.litPropertyMetadata.set(r,o=new Map),"setter"===i&&((t=Object.create(t)).wrapped=!0),o.set(s.name,t),"accessor"===i){const{name:i}=s;return{set(s){const r=e.get.call(this);e.set.call(this,s),this.requestUpdate(i,r,t)},init(e){return void 0!==e&&this.C(i,void 0,t,e),e}}}if("setter"===i){const{name:i}=s;return function(s){const r=this[i];e.call(this,s),this.requestUpdate(i,r,t)}}throw Error("Unsupported decorator location: "+i)};function O(t){return(e,s)=>"object"==typeof s?P(t,e,s):((t,e,s)=>{const i=e.hasOwnProperty(s);return e.constructor.createProperty(s,t),i?Object.getOwnPropertyDescriptor(e,s):void 0})(t,e,s)}function T(t){return O({...t,state:!0,attribute:!1})}var U=Object.defineProperty,A=Object.getOwnPropertyDescriptor,M=(t,e,s,i)=>{for(var r,o=i>1?void 0:i?A(e,s):e,a=t.length-1;a>=0;a--)(r=t[a])&&(o=(i?r(e,s,o):r(o))||o);return i&&o&&U(e,s,o),o};const k="cdtr-test-emails";let V=class extends i.oi{constructor(){super(...arguments),this.emails=[],this.inputValue="",this.error="",this.isLoading=!1,this.customColor="#000",this.customTextColor="#ffffff",this.buttonText="#ffffff",this.triggerText="Send Test Emails",this.headerText="Send Test Emails",this.inputPlaceholder="Enter email addresses (comma or enter to add)",this.sendButtonText="Send",this.loadingText="Sending...",this.invalidEmailError="Please enter a valid email address",this.noEmailsError="Please add at least one email address"}connectedCallback(){super.connectedCallback();const t=localStorage.getItem(k);t&&(this.emails=JSON.parse(t))}validateEmail(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}handleInput(t){const e=t.target;this.inputValue=e.value,this.error=""}handleKeyDown(t){"Enter"!==t.key&&","!==t.key||(t.preventDefault(),this.addEmail())}addEmail(){const t=this.inputValue.trim();t&&(this.validateEmail(t)?(this.emails.includes(t)||(this.emails=[...this.emails,t],localStorage.setItem(k,JSON.stringify(this.emails)),this.dispatchEvent(new CustomEvent("email-added",{detail:{email:t},bubbles:!0,composed:!0}))),this.inputValue=""):this.error=this.invalidEmailError)}removeEmail(t){this.emails=this.emails.filter((e=>e!==t)),localStorage.setItem(k,JSON.stringify(this.emails)),this.dispatchEvent(new CustomEvent("email-removed",{detail:{email:t},bubbles:!0,composed:!0}))}sendEmails(){this.inputValue.trim()&&this.validateEmail(this.inputValue.trim())&&this.addEmail(),0!==this.emails.length?(this.isLoading=!0,this.dispatchEvent(new CustomEvent("sendEmails",{detail:{emails:this.emails},bubbles:!0,composed:!0})),setTimeout((()=>{this.isLoading=!1;const t=this.shadowRoot?.querySelector("cdtr-popover");t&&t.close&&t.close()}),1e3)):this.error=this.noEmailsError}render(){return i.dy` <cdtr-popover> <paper-button color="primary" slot="trigger" style="color: ${this.customTextColor};" > <svg width="20" height="20" xmlns="http://www.w3. org/2000/svg" viewBox="0 0 24 24" fill="currentColor" > <path d="M21 3C21.5523 3 22 3.44772 22 4V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V19H20V7.3L12 14.5L2 5.5V4C2 3.44772 2.44772 3 3 3H21ZM8 15V17H0V15H8ZM5 10V12H0V10H5ZM19.5659 5H4.43414L12 11.8093L19.5659 5Z" ></path> </svg> <span dir="auto">${this.triggerText}</span> </paper-button> <div slot="content" class="popover-content" dir="auto"> <div class="popover-header"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" > <path d="M21 3C21.5523 3 22 3.44772 22 4V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V19H20V7.3L12 14.5L2 5.5V4C2 3.44772 2.44772 3 3 3H21ZM8 15V17H0V15H8ZM5 10V12H0V10H5ZM19.5659 5H4.43414L12 11.8093L19.5659 5Z" ></path> </svg> <h3>${this.headerText}</h3> </div> <input name="emails" class="email-input" type="text" .value=${this.inputValue} @input=${this.handleInput} @keydown=${this.handleKeyDown} placeholder=${this.inputPlaceholder} dir="auto" /> ${this.error?i.dy`<div class="error" dir="auto">${this.error}</div>`:""} <div class="email-tags"> ${this.emails.map((t=>i.dy` <div class="email-tag" dir="auto"> ${t} <span class="remove-tag" @click=${()=>this.removeEmail(t)} >×</span > </div> `))} </div> <paper-button size="sm" fullwidth @click=${this.sendEmails} ?disabled=${this.isLoading} class="send-button" style="background: ${this.customColor}; color: ${this.customTextColor};width:100%;" > ${this.isLoading?i.dy` <span class="loading-spinner"></span> <span dir="auto">${this.loadingText}</span> `:i.dy`<span dir="auto">${this.sendButtonText}</span>`} </paper-button> </div> </cdtr-popover> `}};V.styles=i.iv` :host { display: block; } * { font-family: Arial, Helvetica, sans-serif; box-sizing: border-box; } paper-button { text-transform: none; min-width: 10px; } .popover-content { padding: 16px; min-width: 300px; } .popover-header { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid #e0e0e0; } .popover-header h3 { margin: 0; font-size: 16px; font-weight: 600; color: #333; } .popover-header svg { width: 20px; height: 20px; color: #666; } .email-input { padding: 8px 12px; border: 1px solid #ccc; border-radius: 4px; width: 100%; margin-bottom: 8px; font-size: 14px; transition: border-color 0.2s; } .email-input:focus { outline: none; border-color: #666; } .email-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; max-width: 200px; } .email-tag { background: #f0f0f0; padding: 4px 8px; border-radius: 4px; display: flex; align-items: center; gap: 4px; font-size: 13px; } .remove-tag { cursor: pointer; color: #666; font-size: 16px; line-height: 1; padding: 0 2px; } .remove-tag:hover { color: #ff0000; } .error { color: #ff0000; font-size: 12px; margin-bottom: 8px; } .loading-spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid #ffffff; border-radius: 50%; border-top-color: transparent; animation: spin 1s ease-in-out infinite; margin-right: 8px; } @keyframes spin { to { transform: rotate(360deg); } } .send-button:disabled { opacity: 0.6; cursor: not-allowed; } `,M([T()],V.prototype,"emails",2),M([T()],V.prototype,"inputValue",2),M([T()],V.prototype,"error",2),M([T()],V.prototype,"isLoading",2),M([O({type:String})],V.prototype,"customColor",2),M([O({type:String})],V.prototype,"customTextColor",2),M([O({type:String})],V.prototype,"buttonText",2),M([O({type:String})],V.prototype,"triggerText",2),M([O({type:String})],V.prototype,"headerText",2),M([O({type:String})],V.prototype,"inputPlaceholder",2),M([O({type:String})],V.prototype,"sendButtonText",2),M([O({type:String})],V.prototype,"loadingText",2),M([O({type:String})],V.prototype,"invalidEmailError",2),M([O({type:String})],V.prototype,"noEmailsError",2),V=M([(t=>(e,s)=>{void 0!==s?s.addInitializer((()=>{customElements.define(t,e)})):customElements.define(t,e)})("cdtr-send-test-emails-plugin")],V)}}]);