UNPKG

@creaditor/newsletter-starterkit

Version:

Creaditor Newsletter Editor - Starterkit for creating beautiful email newsletters

1 lines 8.13 kB
"use strict";(("undefined"!=typeof self?self:this).webpackChunkCreaditor=("undefined"!=typeof self?self:this).webpackChunkCreaditor||[]).push([[7946],{7946:(e,t,n)=>{n.r(t),n.d(t,{default:()=>x});n(30814),n(70235);let a=!0;const o=e=>{{const{component:t,commands:n,helpers:o}=e,r=t.parent("col");return{select:e=>{let{changeTab:t,tab:n}=e;n.text||t("image")},tabs:e=>{const t=[{text:"image",selected:!0},{text:"design"},{text:"link"},{text:"ai"},{text:"settings"}];return e?(t.forEach((t=>t.selected=t.selected=t.text===e)),t):t},layout:e=>{const{tab:o,changeTab:s,tabs:i}=e;return[{type:"info",text:"image_micro_copy",active:()=>"image"===o.text},{type:"imagePrompt",active:()=>"ai"===o.text,onChange:e=>{e.target.value}},{type:"gallery",active:()=>"image"===o.text,src:t.props.src,hasPreview:!0,text:"openGalleryImage",justify:"flex-start",onChange:e=>{let t=e.detail;Array.isArray(t)&&(t=t[0]),n.execCommand("src",t.src)}},{type:"input",title:"add_urlAddress_from_media_site",active:()=>"image"===o.text,value:t.props.src||"",onChange:e=>{const t=e.target.value;n.execCommand("src",t)}},{type:"input",title:"altText",active:()=>"image"===o.text,value:t.props.alt||"",onChange:e=>{const t=e.target.value;n.execCommand("alt",t)}},{type:"checkbox",title:"fullWidthOnMobile",checked:!!t.props.isFullWidthOnMobile,active:()=>"image"===o.text,onChange:e=>{const t=e.target.checked;n.execCommand("isFullWidthOnMobile",t)}},{type:"divider",active:()=>"design"===o.text},{type:"checkbox",title:"keep_ratio",checked:!!a,active:()=>"design"===o.text,onChange:e=>{a=!a,s("design")}},{type:"slider",min:10,title:"size",active:()=>"design"===o.text&&a,max:a?1e3:r?.element?.offsetWidth,value:parseInt(t.props.style.width),onInput:e=>{const t=e.target.value;n.execCommand("style",{width:t+"px",height:"auto"})}},{type:"slider",min:10,title:"width",active:()=>"design"===o.text&&!a,max:a?1e3:r?.element?.offsetWidth,value:parseInt(t.props.style.width),onInput:e=>{const a=e.target.value,o=t.atomElement.getBoundingClientRect().height;n.execCommand("style",{width:a+"px",height:o+"px"})}},{type:"slider",min:10,title:"height",active:()=>"design"===o.text&&!a,max:2*r?.element?.offsetWidth,value:parseInt(t.props.style.height),onInput:e=>{const a=e.target.value,o=t.atomElement.getBoundingClientRect().width;n.execCommand("style",{height:a+"px",width:o+"px"})}},{type:"divider",active:()=>"design"===o.text},{type:"linkpicker",href:t.props.onClick?.link,protocol:t.props.onClick?.link?.protocol,target:t.props.onClick?.link?.target,autofocus:!0,active:()=>"link"===o.text,onChange:e=>{const t={link:e.target.value};n.execCommand("onClick",t)}}]}}}};var r=n(46245);const s=()=>({set:(e,t,n)=>{switch(t){case"src":case"isFullWidthOnMobile":case"isOpenWithModal":case"isCircle":case"alt":case"onClick":return e[t]=n,!0;case"style":if("object"==typeof n)return e[t]=(0,r.Z)(e[t],n),!0}}});var i=n(46062),c=n.n(i),l=n(32877),d=n.n(l),p=n(96793),m=n.n(p),u=n(17892),g=n.n(u),y=n(11173),h=n.n(y),f=n(76555),v={};v.setAttributes=g(),v.insert=m().bind(null,"head"),v.domAPI=d(),v.insertStyleElement=h();c()(f.Z,v);const w=f.Z&&f.Z.locals?f.Z.locals:void 0,x=()=>{const e="image";return{name:e,create:t=>{const{createElement:n,compose:a,helpers:r}=t,{arrayToString:i,mergeDiff:c}=r,l=document.createElement("img"),d=document.createElement("div");a.props.style&&!parseInt(a.props.style.height)&&(a.props.style.height="auto"),l.addEventListener("drop",(e=>{e.preventDefault();var t=e.dataTransfer.getData("text/html");const n=document.createElement("div");n.innerHTML=t;const o=n.querySelector("img");o&&o.src&&a.editor.store().updateComponent(a,"src",o.src)})),l.draggable=!0,l.src=a.props.src;const p=i(a.classList);function m(e){"Delete"!==e.key&&"Backspace"!==e.key||u.commands.remove()}l.className=i(p,"editor-image",w.image),d.append(l),l.addEventListener("dblclick",(()=>{const e=document.createElement("cdtr-gallery");e.opened=!0,e.multi=!0,document.body.append(e),e.addEventListener("file",(t=>{let n=t.detail;Array.isArray(n)&&(n=n[0]),a.editor.store().execCommands([{key:"src",value:n.src},{key:"style",value:{height:"auto"}}]),e.opened=!1,setTimeout((()=>{e.remove()}),1500)})),e.addEventListener("close",(()=>{e.remove()}))}));const u=n({name:e,id:a.id,template:d,defaultProps:{style:{height:"auto",width:"200px"}},draggable:{group:"element"},droppable:{group:"element"},render:()=>{c(l,{style:a.props.style}),l.width=a.props.width||a.props.style.width,l.height=a.props.height||a.props.style.height,c(l,{src:a.props.src}),c(l,{alt:a.props.alt})},resizeable:()=>d,handleBar:!0,validator:s({template:d,image:l,helpers:r}),schema:a.schema,onSelect:e=>{l.classList.add(e),document.addEventListener("keyup",m)},onDeselect:e=>{l.classList.remove(e),document.removeEventListener("keyup",m)},elementProps:a,remove:()=>{d.remove()},createEditor:o});let g=0,y=0,h=!1,f=!1,v=!1,x=!1;return l.addEventListener("dragover",(e=>{e.preventDefault()})),l.addEventListener("dragstart",(e=>{g=e.clientX,y=e.clientY,h=!0,f=!1,v=!1,x=!1})),l.addEventListener("drag",(e=>{if(!h)return;const t=l.closest(".block-component")||l.closest("[data-block]")||l.parentElement;if(!t)return;const n=t.getBoundingClientRect(),a=n.width,o=n.left,r=e.clientX-o,s=.3*a,i=.7*a;if(r<s&&!f){f=!0,x=!1,v=!1;const e=u.parent("col");e&&e.commands.execCommand("justify","start")}else if(r>i&&!v){v=!0,x=!1,f=!1;const e=u.parent("col");e&&e.commands.execCommand("justify","end")}else if(r>=s&&r<=i&&!x){x=!0,f=!1,v=!1;const e=u.closest("col");e&&e.commands.execCommand("justify","center")}})),l.addEventListener("dragend",(e=>{h=!1,f=!1,v=!1,x=!1})),u}}}},76555:(e,t,n)=>{n.d(t,{Z:()=>i});var a=n(40272),o=n.n(a),r=n(82609),s=n.n(r)()(o());s.push([e.id,".DYtLgzP53oukeRBVqQDc{\n display: block;\n max-width: 100%;\n}","",{version:3,sources:["webpack://./../image-editor-component/lib/style.module.css"],names:[],mappings:"AAAA;IACI,cAAc;IACd,eAAe;AACnB",sourcesContent:[".image{\n display: block;\n max-width: 100%;\n}"],sourceRoot:""}]),s.locals={image:"DYtLgzP53oukeRBVqQDc"};const i=s},30814:(e,t,n)=>{n.d(t,{td:()=>d});const a=window.cdtrSignalKey||`___${Math.random().toString(36).substr(2,9)}`;window.cdtrSignalKey=a,window[a]||(window[a]={});const o=window[a],r=window.__cdtrEvents||{};function s(e){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e)).then((e=>Array.from(new Uint8Array(e)).map((e=>e.toString(16).padStart(2,"0"))).join("")))}function i(e){if(e.length%2!=0)throw new Error("Invalid hex string");const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.substr(n,2),16);return t}async function c(e){const t=await s(e),n=o[t];if(n){const e=await crypto.subtle.importKey("raw",i(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),a=await async function(e,t,n){const a=await crypto.subtle.decrypt({name:"AES-GCM",iv:t},e,n);return(new TextDecoder).decode(a)}(e,n.iv,n.encrypted);return JSON.parse(a)}return null}function l(e,t){if(r[e])for(const n in r[e])Object.prototype.hasOwnProperty.call(r[e],n)&&r[e][n].forEach((e=>e(t)));Array.isArray(r["*"])&&r["*"].forEach((e=>e(t)))}window.__cdtrEvents=r;const d={set:async function(e,t){const n=JSON.parse(JSON.stringify(t)),a=await s(e),c=await crypto.subtle.importKey("raw",i(a),{name:"AES-GCM"},!1,["encrypt","decrypt"]),d=await async function(e,t){const n=crypto.getRandomValues(new Uint8Array(12)),a=(new TextEncoder).encode(t),o=await crypto.subtle.encrypt({name:"AES-GCM",iv:n},e,a);return{iv:n,encrypted:new Uint8Array(o)}}(c,JSON.stringify(n));o[a]=d,r.set&&r.set[a]&&r.set[a].forEach((e=>e(n))),Array.isArray(r["*"])&&r["*"].forEach((e=>e(n))),l(e,n)},get:c,remove:async function(e){const t=await s(e);delete o[t]},on:async function(e,t,n){r[e]||(r[e]={});const a=await s(t);r[e][a]||(r[e][a]=[]),r[e][a].push((e=>{!function(){const e=(new Error).stack;if(e&&e.indexOf(" at <anonymous>:1")>-1)throw console.warn("Function call blocked: Detected console execution."),new Error("Function call blocked: Detected console execution.")}(),n(e)}));const o=await c(t);return o&&n(o),a},off:function(e,t){r[e]&&r[e][t]&&delete r[e][t]},dispatch:l,OPTIONS:{SET:"set"}}}}]);