livecode-static/docs/assets/js/ec7fa08a.d33ce892.js
2025-06-11 22:23:49 +08:00

45 lines
16 KiB
JavaScript

"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["6176"],{2108:function(e,t,s){s.r(t),s.d(t,{default:()=>u,frontMatter:()=>l,metadata:()=>n,assets:()=>c,params:()=>d,toc:()=>m,contentTitle:()=>a});var n=JSON.parse('{"id":"languages/mjml","title":"MJML","description":"MJML is a markup language designed to reduce the pain of coding a responsive email.","source":"@site/docs/languages/mjml.mdx","sourceDirName":"languages","slug":"/languages/mjml","permalink":"/docs/languages/mjml","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/languages/mjml.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"MDX","permalink":"/docs/languages/mdx"},"next":{"title":"Mustache","permalink":"/docs/languages/mustache"}}'),o=s("5893"),i=s("65"),r=s("3365");let l={},a="MJML",c={},d={mjml:"<mjml>\n <mj-body>\n <mj-section>\n <mj-column>\n <mj-text>\n Hello World!\n </mj-text>\n </mj-column>\n </mj-section>\n </mj-body>\n</mjml>\n"},m=[{value:"Language Info",id:"language-info",level:2},{value:"Name",id:"name",level:3},{value:"Extension",id:"extension",level:3},{value:"Editor",id:"editor",level:3},{value:"Compiler",id:"compiler",level:2},{value:"Version",id:"version",level:3},{value:"Custom Settings",id:"custom-settings",level:2},{value:"Example Usage",id:"example-usage",level:2},{value:"Links",id:"links",level:2}];function h(e){let t={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.header,{children:(0,o.jsx)(t.h1,{id:"mjml",children:"MJML"})}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.a,{href:"https://mjml.io/",children:"MJML"})," is a markup language designed to reduce the pain of coding a responsive email."]}),"\n",(0,o.jsx)(t.h2,{id:"language-info",children:"Language Info"}),"\n",(0,o.jsx)(t.h3,{id:"name",children:"Name"}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.code,{children:"mjml"})}),"\n",(0,o.jsx)(t.h3,{id:"extension",children:"Extension"}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.code,{children:".mjml"})}),"\n",(0,o.jsx)(t.h3,{id:"editor",children:"Editor"}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.code,{children:"markup"})}),"\n",(0,o.jsx)(t.h2,{id:"compiler",children:"Compiler"}),"\n",(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/package/mjml-browser",children:"browser build"})," of the official ",(0,o.jsx)(t.a,{href:"https://github.com/mjmlio/mjml",children:"MJML compiler"}),"."]}),"\n",(0,o.jsx)(t.h3,{id:"version",children:"Version"}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"mjml-browser"}),": v4.15.3"]}),"\n",(0,o.jsx)(t.h2,{id:"custom-settings",children:"Custom Settings"}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.a,{href:"/docs/advanced/custom-settings",children:"Custom settings"})," added to the property ",(0,o.jsx)(t.code,{children:"mjml"})," are passed as a JSON object to the mjml compiler. Please check the ",(0,o.jsx)(t.a,{href:"https://documentation.mjml.io/#inside-node-js",children:"documentation"})," for full reference."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Example:"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'{\n "mjml": {\n "keepComments": false,\n "minify": true\n }\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"example-usage",children:"Example Usage"}),"\n","\n","\n",(0,o.jsx)(r.Z,{params:d}),"\n",(0,o.jsxs)(t.p,{children:["This playground loads a template from the official MJML ",(0,o.jsx)(t.a,{href:"https://github.com/mjmlio/email-templates",children:"email templates"}),":"]}),"\n",(0,o.jsx)(r.Z,{import:"https://github.com/mjmlio/email-templates/blob/master/templates/onepage.mjml",height:"400"}),"\n",(0,o.jsx)(t.h2,{id:"links",children:"Links"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsxs)(t.li,{children:["\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.a,{href:"https://mjml.io/",children:"MJML official website"})}),"\n"]}),"\n",(0,o.jsxs)(t.li,{children:["\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.a,{href:"https://documentation.mjml.io/",children:"MJML documentation"})}),"\n"]}),"\n",(0,o.jsxs)(t.li,{children:["\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.a,{href:"https://github.com/mjmlio/mjml",children:"MJML GitHub repo"})}),"\n"]}),"\n",(0,o.jsxs)(t.li,{children:["\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.a,{href:"https://mjml.io/templates",children:"Official email templates"})}),"\n"]}),"\n"]})]})}function u(e={}){let{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(h,{...e})}):h(e)}},3365:function(e,t,s){s.d(t,{Z:()=>f});var n=s("5893"),o=s("4200"),i=s("7294"),r=s("8294");function l(e){let t=(0,i.useRef)(null),[s,o]=(0,i.useState)(e.className||""),[l,a]=(0,i.useState)(e.style||{}),[c,d]=(0,i.useState)(e.height),[m,h]=(0,i.useState)(),[u,p]=(0,i.useState)(JSON.stringify(e.config||"")),[g,f]=(0,i.useState)("");return(0,i.useEffect)(()=>{if(!t.current)return;let{className:s,style:n,height:i,sdkReady:l,config:c,...j}=e;if(o(s||""),a(n||{}),d(i),m&&g===JSON.stringify(j)){if(u===JSON.stringify(c))return;p(JSON.stringify(c)),"string"==typeof c?fetch(c).then(e=>e.json()).then(e=>{m?.setConfig(e)}):c&&m.setConfig(c)}else f(JSON.stringify(j)),m?.destroy(),(0,r.T)(t.current,{config:c,...j}).then(e=>{h(e),"function"==typeof l&&l(e)})},[e]),(0,i.useEffect)(()=>()=>{m?.destroy()},[]),(0,n.jsx)("div",{ref:t,className:s,style:l,"data-height":c})}var a=s("1858"),c=s("3262"),d=s("1705"),m=s("7645"),h=s("8168"),u=s("8228"),p=s("5050");function g(e){let[t,s]=(0,i.useState)(e.js),[o,r]=(0,i.useState)(e.ts),[l,a]=(0,i.useState)(e.react),[g,f]=(0,i.useState)(e.vue),[j,v]=(0,i.useState)(e.svelte),y="3.7rem",[x,b]=(0,i.useState)(!0),[w,S]=(0,i.useState)(y),C=(0,i.useRef)(null),E=()=>{setTimeout(()=>{S(`calc(${C.current.offsetHeight}px + ${y})`)},5),setTimeout(()=>{S(`calc(${C.current.offsetHeight}px + ${y})`)},255)};return(0,i.useEffect)(()=>{if(c.Z.canUseDOM){let e=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"js";try{return window.prettier?.format(e,{parser:"html"===t?"html":"babel",plugins:window.prettierPlugins})}catch{return e}};s(e(t,"js")),r(e(o,"ts")),a(e(l,"jsx")),f(e(g,"html")),v(e(j,"html"))}},[]),(0,n.jsxs)("details",{className:`alert alert--info ${p.Z.details} ${u.Z.details}`,"data-collapsed":x,style:{height:x?y:w,overflow:"hidden",willChange:"height",transition:`height ${x?"250ms":"265ms"} ease-in-out 0s`,margin:"1em 0"},children:[(0,n.jsx)("summary",{onClick:()=>{b(!x),E()},children:"show code"}),(0,n.jsx)("div",{ref:C,style:{display:"block",overflow:"hidden"},children:(0,n.jsx)("div",{className:p.Z.collapsibleContent,children:(0,n.jsxs)(h.Z,{groupId:"sdk-code",children:[(0,n.jsx)(m.Z,{value:"js",label:"JS",attributes:{onMouseDown:E},children:(0,n.jsx)(d.Z,{language:"js",children:t})}),(0,n.jsx)(m.Z,{value:"ts",label:"TS",attributes:{onMouseDown:E},children:(0,n.jsx)(d.Z,{language:"ts",children:o})}),(0,n.jsx)(m.Z,{value:"react",label:"React",attributes:{onMouseDown:E},children:(0,n.jsx)(d.Z,{language:"jsx",children:l})}),(0,n.jsx)(m.Z,{value:"vue",label:"Vue",attributes:{onMouseDown:E},children:(0,n.jsx)(d.Z,{language:"html",children:g})}),(0,n.jsx)(m.Z,{value:"svelte",label:"Svelte",attributes:{onMouseDown:E},children:(0,n.jsx)(d.Z,{language:"html",children:j})})]})})})]})}function f(e){let{className:t,style:s,showCode:i,height:r,...c}=e,{colorMode:d}=(0,o.I)(),m=e=>JSON.stringify(e,null,2),h=`
import { createPlayground } from 'livecodes';
const options = ${m(c)};
createPlayground('#container', options);
`.trimStart(),u=`
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = ${m(c)};
createPlayground('#container', options);
`.trimStart(),p=`
import LiveCodes from 'livecodes/react';
export default function App() {
const options = ${m(c)};
return (<LiveCodes {...options}></LiveCodes>);
}
`.trimStart(),f=`
<script setup>
import LiveCodes from "livecodes/vue";
const options = ${m(c)};
</script>
<template>
<LiveCodes v-bind="options" />
</template>
`,j=`
<script>
import { onMount } from 'svelte';
import { createPlayground } from 'livecodes';
let options = $state(${m(c)});
let container = $state(null);
onMount(() => {
createPlayground(container, options);
});
</script>
<div bind:this="{container}"></div>
`.trimStart();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l,{className:`container_Egsj ${e.className}`,style:{height:r||"50vh",...e.style},appUrl:a.G,...e,config:{theme:d,themeColor:"hsl(215, 8%, 60%)",..."object"==typeof e.config?e.config:{}}}),!1!==e.showCode&&(0,n.jsx)(g,{js:h,ts:u,react:p,vue:f,svelte:j})]})}},8294:function(e,t,s){s.d(t,{T:function(){return o},r:function(){return i}});var n=s(7728);async function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"object"!=typeof e||e instanceof HTMLElement||!e.headless&&"headless"!==e.view||(t=e,e=null);let{config:s={},headless:n,loading:o="lazy",view:r}=t,l=n||"headless"===r,a=null,c=null;if("string"==typeof e)a=document.querySelector(e);else if(e instanceof HTMLElement)a=e;else if(!(l&&"object"==typeof e))throw Error("A valid container element is required.");if(!a){if(l)E(a=document.createElement("div")),document.body.appendChild(a);else throw Error(`Cannot find element: "${e}"`)}let d=new URL(i(t)),m=d.origin;d.searchParams.set("embed","true"),d.searchParams.set("loading",l?"eager":o);let h=globalThis.process;d.searchParams.set("sdkVersion",h?.env?.SDK_VERSION||"latest"),"object"==typeof s&&Object.keys(s).length>0&&d.searchParams.set("config","sdk");let u=t.params;"object"==typeof u&&Object.keys(u).length>0&&JSON.stringify(u).length<1800&&Object.keys(u).forEach(e=>{d.searchParams.set(e,encodeURIComponent(String(u[e])))});let p=!1,g="Cannot call API methods after calling `destroy()`.",f=await new Promise(e=>{if(!a)return;let t=a.dataset.height||a.style.height;if(t&&!l){let e=isNaN(Number(t))?t:t+"px";a.style.height=e}"false"===a.dataset.defaultStyles||l||(a.style.backgroundColor||="#fff",a.style.border||="1px solid black",a.style.borderRadius||="8px",a.style.boxSizing||="border-box",a.style.padding||="0",a.style.width||="100%",a.style.height||=a.style.height||"300px",a.style.minHeight="200px",a.style.flexGrow="1",a.style.overflow||="hidden",a.style.resize||="vertical");let n="livecodes",i=a.querySelector(`iframe.${n}`),r=i||document.createElement("iframe");r.classList.add(n),r.setAttribute("allow","accelerometer; camera; encrypted-media; display-capture; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write; web-share"),r.setAttribute("allowtransparency","true"),r.setAttribute("allowpaymentrequest","true"),r.setAttribute("allowfullscreen","true"),r.setAttribute("sandbox","allow-same-origin allow-downloads allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-presentation allow-scripts"),r.setAttribute("loading","eager"===o?"eager":"lazy"),l?E(r):(r.style.height="100%",r.style.minHeight="200px",r.style.width="100%",r.style.margin="0",r.style.border="0",r.style.borderRadius=a.style.borderRadius),addEventListener("message",function e(t){t.source===r.contentWindow&&t.origin===m&&t.data?.type==="livecodes-init"&&(removeEventListener("message",e),c=Number(t.data.payload.appVersion.replace(/^v/,"")))}),(!c||c<46)&&addEventListener("message",function e(t){t.source===r.contentWindow&&t.origin===m&&t.data?.type==="livecodes-get-config"&&(removeEventListener("message",e),r.contentWindow?.postMessage({type:"livecodes-config",payload:s},m))}),r.onload=()=>{e(r)},r.src=d.href,i||a.appendChild(r)}),j=new Promise(e=>{addEventListener("message",function t(s){s.source===f.contentWindow&&s.origin===m&&s.data?.type==="livecodes-ready"&&(removeEventListener("message",t),e(),j.settled=!0)})}),v=()=>p?Promise.reject(g):new Promise(async e=>{j.settled&&e(),f.contentWindow?.postMessage({type:"livecodes-load"},m),await j,e()}),y=(e,t)=>new Promise(async(s,n)=>{if(p)return n(g);await v();let o=M();addEventListener("message",function t(i){if(i.source===f.contentWindow&&i.origin===m&&i.data?.type==="livecodes-api-response"&&i.data?.id===o&&i.data.method===e){removeEventListener("message",t);let e=i.data.payload;e?.error?n(e.error):s(e)}}),f.contentWindow?.postMessage({method:e,id:o,args:t},m)}),x={},b=["load","ready","code","console","tests","destroy"],w=(e,t)=>{if(p)throw Error(g);return b.includes(e)?(y("watch",[e]),x[e]||(x[e]=[]),x[e]?.push(t),{remove:()=>{x[e]=x[e]?.filter(e=>e!==t),x[e]?.length===0&&y("watch",[e,"unsubscribe"])}}):{remove:()=>void 0}},S=e=>({"livecodes-app-loaded":"load","livecodes-ready":"ready","livecodes-change":"code","livecodes-console":"console","livecodes-test-results":"tests","livecodes-destroy":"destroy"})[e];addEventListener("message",async e=>{let t=S(e.data?.type??"");if(e.source!==f.contentWindow||e.origin!==m||!t||!x[t])return;let s=e.data?.payload;x[t]?.forEach(e=>{e(s)})});let C=()=>{Object.values(x).forEach(e=>{e.length=0}),f?.remove?.(),p=!0};function E(e){e.style.position="absolute",e.style.top="0",e.style.visibility="hidden",e.style.opacity="0"}"lazy"===o&&"IntersectionObserver"in window&&new IntersectionObserver((e,t)=>{e.forEach(async e=>{e.isIntersecting&&(await v(),t.unobserve(a))})},{rootMargin:"150px"}).observe(a);let M=()=>(String(Math.random())+Date.now().toFixed()).replace("0.","");return{load:()=>v(),run:()=>y("run"),format:e=>y("format",[e]),getShareUrl:e=>y("getShareUrl",[e]),getConfig:e=>y("getConfig",[e]),setConfig:e=>y("setConfig",[e]),getCode:()=>y("getCode"),show:(e,t)=>y("show",[e,t]),runTests:()=>y("runTests"),onChange:e=>w("code",e),watch:w,exec:function(e){for(var t=arguments.length,s=Array(t>1?t-1:0),n=1;n<t;n++)s[n-1]=arguments[n];return y("exec",[e,...s])},destroy:()=>j.settled?y("destroy").then(C):p?Promise.reject(g):(C(),Promise.resolve())}}function i(){let e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{appUrl:s="https://livecodes.io",params:o={},config:i={},headless:r,import:l,lite:a,view:c,...d}=t;try{e=new URL(s)}catch{throw Error(`${s} is not a valid URL.`)}let m=new URLSearchParams;Object.entries(d).forEach(t=>{let[s,n]=t;void 0!==n&&e.searchParams.set(s,String(n))});let h="headless"===t.view||r;if(a&&(console.warn('Deprecation notice: "lite" option is deprecated. Use "config: { mode: \'lite\' }" instead.'),"object"==typeof i&&null==i.mode?i.mode="lite":e.searchParams.set("lite","true")),c&&(console.warn('Deprecation notice: The "view" option has been moved to "config.view". For headless mode use "headless: true".'),"object"==typeof i&&null==i.view&&"headless"!==c?i.view=c:e.searchParams.set("view",c)),"string"==typeof i)try{new URL(i),e.searchParams.set("config",encodeURIComponent(i))}catch{throw Error('"config" is not a valid URL or configuration object.')}else i&&"object"==typeof i&&Object.keys(i).length>0&&(i.title&&"Untitled Project"!==i.title&&e.searchParams.set("title",i.title),i.description&&i.description.length>0&&e.searchParams.set("description",i.description),m.set("config","code/"+(0,n.compressToEncodedURIComponent)(JSON.stringify(i))));if(o&&"object"==typeof o&&Object.keys(o).length>0)try{m.set("params",(0,n.compressToEncodedURIComponent)(JSON.stringify(o)))}catch{Object.keys(o).forEach(t=>{e.searchParams.set(t,encodeURIComponent(String(o[t])))})}return l&&e.searchParams.set("x",encodeURIComponent(l)),h&&e.searchParams.set("headless","true"),e.hash=m.toString(),e.href}},65:function(e,t,s){s.d(t,{Z:function(){return l},a:function(){return r}});var n=s(7294);let o={},i=n.createContext(o);function r(e){let t=n.useContext(i);return n.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]);