opnform-host-nginx/public/vendor/mailcoach-editor/assets/editor.e48a8a0e.js

11 lines
13 KiB
JavaScript

import{E as e,H as t,L as a,I as n,Q as o,D as i,R as s,T as d,a as r}from"./vendor.871f4f88.js";function l(e,t=document){return t.querySelector(e)}function c(e,t=document){return Array.from(t.querySelectorAll(e))}!function(e=".",t="__import__"){try{self[t]=new Function("u","return import(u)")}catch(a){const n=new URL(e,location),o=e=>{URL.revokeObjectURL(e.src),e.remove()};self[t]=e=>new Promise(((a,i)=>{const s=new URL(e,n);if(self[t].moduleMap[s])return a(self[t].moduleMap[s]);const d=new Blob([`import * as m from '${s}';`,`${t}.moduleMap['${s}']=m;`],{type:"text/javascript"}),r=Object.assign(document.createElement("script"),{type:"module",src:URL.createObjectURL(d),onerror(){i(new Error(`Failed to import: ${e}`)),o(r)},onload(){a(self[t].moduleMap[s]),o(r)}});document.head.appendChild(r)})),self[t].moduleMap={}}}("/build/assets/");const u=['a[href]:not([disabled]):not([tabindex="-1"])','button:not([disabled]):not([tabindex="-1"])','textarea:not([disabled]):not([tabindex="-1"])','input:not([type="hidden"]):not([disabled]):not([tabindex="-1"])','select:not([disabled]):not([tabindex="-1"])'];function m(e,t,a){document.addEventListener(e,(e=>{const n=e.target.closest(t);n&&a({event:e,target:n})}))}function h(){}async function g(e,t){e.classList.add(`${t}-leave`),e.classList.add(`${t}-leave-start`),await v(),e.classList.remove(`${t}-leave-start`),e.classList.add(`${t}-leave-end`),await p(e),e.classList.remove(`${t}-leave-end`),e.classList.remove(`${t}-leave`),e.classList.add("hidden"),await v()}function p(e){return new Promise((t=>{const a=1e3*Number(getComputedStyle(e).transitionDuration.replace("s",""));setTimeout((()=>{t()}),a)}))}function v(){return new Promise((e=>{requestAnimationFrame((()=>{requestAnimationFrame(e)}))}))}async function f(e,t){return(await fetch(e,{method:"POST",body:t,credentials:"same-origin",headers:{"X-CSRF-Token":l('[name="_token"]').value}})).json()}async function w(e,t){const a=await fetch(e,{method:"POST",body:JSON.stringify({data:t}),credentials:"same-origin",headers:{"Content-Type":"application/json","X-CSRF-Token":l('[name="_token"]').value}});return(await a.json()).html}function b(e,{onConfirm:t=h,onDismiss:a=h}={}){const n=l(`[data-modal="${e}"]`);!async function(e,t){e.classList.remove("hidden"),e.classList.add(`${t}-enter`),e.classList.add(`${t}-enter-start`),await v(),e.classList.remove(`${t}-enter-start`),e.classList.add(`${t}-enter-end`),await p(e),e.classList.remove(`${t}-enter-end`),e.classList.remove(`${t}-enter`),await v()}(n,"fade");E(n,{onConfirm:t,onDismiss:a,onClose:function(e){const t=c(u.join(", "),e),a=t[0],n=t[t.length-1];function o(e){"Tab"===e.key&&(e.shiftKey?document.activeElement===a&&(e.preventDefault(),n.focus()):document.activeElement===n&&(e.preventDefault(),a.focus()))}return a&&a.focus(),window.addEventListener("keydown",o),()=>{window.removeEventListener("keydown",o)}}(n)}),y(!0)}function y(e){window.history.replaceState({},"",window.location.pathname+window.location.search+(e?"#modal":""))}function E(e,{onConfirm:t,onDismiss:a,onClose:n}){function o(t){"Escape"===t.key&&e.dispatchEvent(new Event("dismiss"))}function i(){t(),d(),g(e,"fade")}function s(){a(),d(),g(e,"fade")}function d(){n(),window.removeEventListener("keydown",o),e.removeEventListener("confirm",i),e.removeEventListener("dismiss",s),y(!1)}window.addEventListener("keydown",o),e.addEventListener("confirm",i),e.addEventListener("dismiss",s)}if(m("click","[data-modal-trigger]",(({target:e})=>{b(e.dataset.modalTrigger)})),m("click","[data-modal-confirm]",(({target:e})=>{e.closest("[data-modal]").dispatchEvent(new Event("confirm"))})),m("click","[data-modal-dismiss]",(({target:e})=>{e.closest("[data-modal]").dispatchEvent(new Event("dismiss"))})),m("click","[data-modal-backdrop]",(({event:e,target:t})=>{if(e.target===t){t.closest("[data-modal]").dispatchEvent(new Event("dismiss"))}})),document.addEventListener("turbolinks:load",(()=>{c("[data-modal]").filter((e=>!e.classList.contains("hidden"))).forEach((e=>{E(e,{onConfirm:h,onDismiss:h,onClose:h})}))})),window.location.hash.includes("#modal")){const e=document.querySelector("[data-modal]");if(e){b(e.getAttribute("data-modal"))}}
/**
* CodeTool for Editor.js
*
* @author CodeX (team@ifmo.su)
* @copyright CodeX 2018
* @license MIT
* @version 2.0.0
*/
class L{static get isReadOnlySupported(){return!0}static get enableLineBreaks(){return!0}constructor({data:e,config:t,api:a,readOnly:n}){this.api=a,this.readOnly=n,this.placeholder=this.api.i18n.t(t.placeholder||L.DEFAULT_PLACEHOLDER),this.CSS={baseClass:this.api.styles.block,input:this.api.styles.input,wrapper:"ce-code",textarea:"ce-code__textarea"},this.nodes={holder:null,textarea:null,language:null,theme:null},this.data={code:e.code||"",language:e.language||"",theme:e.theme||"default"},this.nodes.holder=this.drawView()}drawView(){const e=document.createElement("div"),t=document.createElement("textarea"),a=document.createElement("input"),n=document.createElement("select");e.classList.add(this.CSS.baseClass,this.CSS.wrapper),t.classList.add(this.CSS.textarea,this.CSS.input),t.placeholder=this.placeholder,t.textContent=this.data.code,a.classList.add(this.CSS.input),a.value=this.data.language,a.placeholder="Language",n.classList.add(this.CSS.input,"theme-selector"),this.readOnly&&(t.disabled=!0,a.disabled=!0);const o=document.createElement("div");o.appendChild(a),o.appendChild(n),o.classList.add("grid","grid-cols-2","gap-4","mt-4"),e.appendChild(o),e.appendChild(t),t.addEventListener("keydown",(e=>{switch(e.code){case"Tab":this.tabHandler(e)}}));const i=document.createElement("option");i.setAttribute("disabled",!0),i.setAttribute("selected",!0),i.textContent="Select a theme",n.appendChild(i);const s=["a11y-dark","a11y-light","agate","an-old-hope","androidstudio","arduino-light","arta","ascetic","atelier-cave-dark","atelier-cave-light","atelier-dune-dark","atelier-dune-light","atelier-estuary-dark","atelier-estuary-light","atelier-forest-dark","atelier-forest-light","atelier-heath-dark","atelier-heath-light","atelier-lakeside-dark","atelier-lakeside-light","atelier-plateau-dark","atelier-plateau-light","atelier-savanna-dark","atelier-savanna-light","atelier-seaside-dark","atelier-seaside-light","atelier-sulphurpool-dark","atelier-sulphurpool-light","atom-one-dark","atom-one-dark-reasonable","atom-one-light","brown-paper","codepen-embed","color-brewer","darcula","dark","darkula","default","docco","dracula","far","foundation","github","github-gist","gml","googlecode","gradient-dark","grayscale","gruvbox-dark","gruvbox-light","hopscotch","hybrid","idea","ir-black","isbl-editor-dark","isbl-editor-light","kimbie.dark","kimbie.light","lightfair","magula","mono-blue","monokai","monokai-sublime","night-owl","nord","obsidian","ocean","paraiso-dark","paraiso-light","pojoaque","pojoaque.jpg","purebasic","qtcreator_dark","qtcreator_light","railscasts","rainbow","routeros","school-book","shades-of-purple","solarized-dark","solarized-light","sunburst","tomorrow","tomorrow-night","tomorrow-night-blue","tomorrow-night-bright","tomorrow-night-eighties","vs","vs2015","xcode","xt256","zenburn"];for(let d=0;d<s.length;d++){const e=document.createElement("option"),t=s[d];"string"==typeof t?(e.setAttribute("value",t),e.textContent=t):(e.setAttribute("value",t.value),e.textContent=t.label),n.appendChild(e)}return""!==this.data.theme&&(n.value=this.data.theme),n.addEventListener("change",(e=>{document.querySelectorAll(".theme-selector").forEach((t=>{t.value=e.target.value}))})),this.nodes.textarea=t,this.nodes.language=a,this.nodes.theme=n,e}render(){return this.nodes.holder}save(e){return{code:e.querySelector("textarea").value,language:e.querySelector("input").value,theme:document.querySelector(".theme-selector").value}}onPaste(e){const t=e.detail.data;this.data={code:t.textContent}}get data(){return this._data}set data(e){this._data=e,this.nodes.textarea&&(this.nodes.textarea.textContent=e.code),this.nodes.language&&(this.nodes.language.value=e.language),this.nodes.theme&&(this.nodes.theme.value=e.theme)}static get toolbox(){return{icon:'<svg width="14" height="14" viewBox="0 -1 14 14" xmlns="http://www.w3.org/2000/svg" > <path d="M3.177 6.852c.205.253.347.572.427.954.078.372.117.844.117 1.417 0 .418.01.725.03.92.02.18.057.314.107.396.046.075.093.117.14.134.075.027.218.056.42.083a.855.855 0 0 1 .56.297c.145.167.215.38.215.636 0 .612-.432.934-1.216.934-.457 0-.87-.087-1.233-.262a1.995 1.995 0 0 1-.853-.751 2.09 2.09 0 0 1-.305-1.097c-.014-.648-.029-1.168-.043-1.56-.013-.383-.034-.631-.06-.733-.064-.263-.158-.455-.276-.578a2.163 2.163 0 0 0-.505-.376c-.238-.134-.41-.256-.519-.371C.058 6.76 0 6.567 0 6.315c0-.37.166-.657.493-.846.329-.186.56-.342.693-.466a.942.942 0 0 0 .26-.447c.056-.2.088-.42.097-.658.01-.25.024-.85.043-1.802.015-.629.239-1.14.672-1.522C2.691.19 3.268 0 3.977 0c.783 0 1.216.317 1.216.921 0 .264-.069.48-.211.643a.858.858 0 0 1-.563.29c-.249.03-.417.076-.498.126-.062.04-.112.134-.139.291-.031.187-.052.562-.061 1.119a8.828 8.828 0 0 1-.112 1.378 2.24 2.24 0 0 1-.404.963c-.159.212-.373.406-.64.583.25.163.454.342.612.538zm7.34 0c.157-.196.362-.375.612-.538a2.544 2.544 0 0 1-.641-.583 2.24 2.24 0 0 1-.404-.963 8.828 8.828 0 0 1-.112-1.378c-.009-.557-.03-.932-.061-1.119-.027-.157-.077-.251-.14-.29-.08-.051-.248-.096-.496-.127a.858.858 0 0 1-.564-.29C8.57 1.401 8.5 1.185 8.5.921 8.5.317 8.933 0 9.716 0c.71 0 1.286.19 1.72.574.432.382.656.893.671 1.522.02.952.033 1.553.043 1.802.009.238.041.458.097.658a.942.942 0 0 0 .26.447c.133.124.364.28.693.466a.926.926 0 0 1 .493.846c0 .252-.058.446-.183.58-.109.115-.281.237-.52.371-.21.118-.377.244-.504.376-.118.123-.212.315-.277.578-.025.102-.045.35-.06.733-.013.392-.027.912-.042 1.56a2.09 2.09 0 0 1-.305 1.097c-.2.323-.486.574-.853.75a2.811 2.811 0 0 1-1.233.263c-.784 0-1.216-.322-1.216-.934 0-.256.07-.47.214-.636a.855.855 0 0 1 .562-.297c.201-.027.344-.056.418-.083.048-.017.096-.06.14-.134a.996.996 0 0 0 .107-.396c.02-.195.031-.502.031-.92 0-.573.039-1.045.117-1.417.08-.382.222-.701.427-.954z" /> </svg>',title:"Code"}}static get DEFAULT_PLACEHOLDER(){return"Enter code"}static get pasteConfig(){return{tags:["pre"]}}static get sanitize(){return{code:!0}}tabHandler(e){e.stopPropagation(),e.preventDefault();const t=e.target,a=e.shiftKey,n=t.selectionStart,o=t.value,i=" ";let s;if(a){const e=function(e,t){let a="";for(;"\n"!==a&&t>0;)t-=1,a=e.substr(t,1);return"\n"===a&&(t+=1),t}(o,n);if(o.substr(e,i.length)!==i)return;t.value=o.substring(0,e)+o.substring(e+i.length),s=n-i.length}else s=n+i.length,t.value=o.substring(0,n)+i+o.substring(n);t.setSelectionRange(s,s)}}function k(e){document.getElementById("html")&&("dirty"!==document.getElementById("html").dataset.dirty||confirm("Are you sure you want to leave this page? Any unsaved changes will be lost.")?(document.removeEventListener("turbolinks:before-visit",k),window.removeEventListener("beforeunload",k),window.editor.destroy(),window.editor=void 0):e.preventDefault())}function C(){document.addEventListener("turbolinks:before-visit",k),document.addEventListener("turbolinks:load",C),window.addEventListener("beforeunload",k);const c=l("#editor-js");if(!c||void 0!==window.editor)return;let u=c.dataset.structuredHtml?JSON.parse(c.dataset.structuredHtml):void 0;window.editor=new e({holder:c,autofocus:!0,data:u,tools:{header:t,list:{class:a,inlineToolbar:!0},image:{class:n,config:{uploader:{uploadByFile(e){const t=new FormData;return t.append("file",e),f(c.dataset.upload,t)},uploadByUrl(e){const t=new FormData;return t.append("url",e),f(c.dataset.upload,t)}}}},quote:o,delimiter:i,raw:s,table:{class:d},code:L,inlineCode:{class:r,shortcut:"CMD+SHIFT+M"}},onChange:()=>{document.getElementById("html").dataset.dirty="dirty"}}),l("#save").addEventListener("click",(e=>{e.preventDefault(),window.editor.save().then((e=>{w(c.dataset.route,{body:e,template:l("#template").value}).then((t=>{document.getElementById("html").value=t,document.getElementById("body").value=JSON.stringify(e),document.getElementById("html").dataset.dirty="",document.querySelector("main form").submit()})).catch((e=>{console.log("Saving failed: ",e)}))})).catch((e=>{console.log("Saving failed: ",e)}))})),l("#preview").addEventListener("click",(e=>{e.preventDefault(),window.editor.save().then((e=>{w(c.dataset.route,{body:e,template:l("#template").value}).then((e=>{l("#html").value=e;const t=document.createEvent("Event");t.initEvent("input",!0,!0),document.getElementById("html").dispatchEvent(t),b("preview")}))}))})),l('[data-modal-trigger="edit-template"]').addEventListener("click",(()=>{document.getElementById("structured_html[template]").value=l("#template").value})),l('[data-modal-confirm="edit-template"]').addEventListener("click",(()=>{l("#template").value=document.getElementById("structured_html[template]").value}))}document.addEventListener("turbolinks:load",C),document.addEventListener("load",C),document.addEventListener("before-visit",k),window.addEventListener("beforeunload",k),C();