@silexlabs/silex 3.0.0-alpha.134 → 3.0.0-alpha.135
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client/js/main.js
CHANGED
|
@@ -379,7 +379,7 @@ var silex;(()=>{var t={99:function(t){"undefined"!=typeof globalThis?globalThis:
|
|
|
379
379
|
@click=${()=>this.editor.Commands.stop(Tr)}
|
|
380
380
|
>Close</button>
|
|
381
381
|
</footer>
|
|
382
|
-
`}}displayPending(t,e){this.errorMessage=null,this.renderDialog(t,e)}displayError(t,e,n){console.info(t),this.errorMessage=t,this.renderDialog(e,n)}async closeDialog(){this.isOpen=!1,this.renderDialog(null,null),this.sender&&this.sender.set("active",0),this.sender=null}async toggleDialog(){this.isOpen?this.closeDialog():this.openDialog()}async openDialog(){this.isOpen=!0;const t=this.editor.Panels.getPanel("options")?.view.el.querySelector(".publish-button");if(t){const e=t.getBoundingClientRect(),n=450,r=20,o=50;this.move({left:e.right-n-r,top:e.bottom+10,width:n,minHeight:o})}else console.error("Unable to find publish button");this.renderDialog(null,Zr.STATUS_NONE)}}function Ar(t,e){t.Pages.getAll().forEach((t=>{t.getMainComponent().onAll((t=>e(t)))}))}const Pr="tmp-pre-publication-transformer-tohtml",jr="tmp-pre-publication-transformer-src",Mr="tmp-pre-publication-transformer-attributes-src",Lr="tmp-pre-publication-transformer-inline-css",Nr="tmp-pre-publication-transformer-href",Ir="tmp-pre-publication-transformer-tocss",Dr={renderComponent:(t,e)=>e(),renderCssRule:(t,e)=>e(),transformPath:(t,e)=>t,transformPermalink(t,e,n){switch(n){case Pe.HTML:return t;case Pe.CSS:return`../${t.replace(/^\//,"")}`;default:throw new Error(`Unknown initiator ${n}`)}},transformFile:t=>t};function $r(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${Rr(t,r,Ae.ASSET,Pe.CSS)})`}:e}function Rr(t,e,n,r){return t.getModel().get("config").publicationTransformers.reduce(((t,e)=>{try{return e.transformPermalink?e.transformPermalink(t,n,r)??t:t}catch(e){return console.error("Publication transformer: error transforming path",t,e),t}}),e)}function Hr(t,e,n){return t.getModel().get("config").publicationTransformers.reduce(((t,e)=>{try{return e.transformPath?e.transformPath(t,n)??t:t}catch(e){return console.error("Publication transformer: error transforming path",t,e),t}}),e)}const Fr=window.location.pathname.replace(/\/$/,""),Vr=window.location.origin;function Ur(t,e,n){if(t.startsWith("/assets")){const r=new URL(t,Vr);return r.pathname=r.pathname.replace(/^\/assets/,""),r.pathname=`${Fr}${on}${vn}${Cn}${r.pathname}`,r.searchParams.set("websiteId",e),r.searchParams.set("connectorId",n),`${decodeURIComponent(r.pathname)}${r.search}`}return console.warn("storedToDisplayed: path is not a stored path",t),t}function Br(t){const e=`${Fr}${on}${vn}${Cn}`;if(t.startsWith(e)){const n=new URL(t,Vr);n.pathname=n.pathname.replace(new RegExp(`^${e}`),""),n.pathname=`${Fr}/assets${n.pathname}`,n.searchParams.delete("websiteId"),n.searchParams.delete("connectorId");const r="/"+n.toString().replace(new RegExp(`^${Vr}${Fr}`),"").replace(/^\//,"");return decodeURIComponent(r)}return console.warn("displayedToStored: path is not a displayed path",t),t}const zr={transformPath(t,e){if(e===Ae.ASSET)return Br(t)},transformPermalink(t,e){if(e===Ae.ASSET)return Br(t)}};function Wr(t,e,n){const r=t.attributes?.src?{...t,attributes:{...t.attributes,src:Ur(t.attributes.src,e,n)}}:t;return r.components&&(r.components=r.components.map((t=>Wr(t,e,n)))),r}function qr(t){const e=t.attributes?.src?{...t,attributes:{...t.attributes,src:Br(t.attributes.src)}}:t;return e.components&&(e.components=e.components.map((t=>qr(t)))),e}const Gr="publish",Kr="publish-login",Yr="publish-logout";var Zr;function Xr(t,e){t.PublicationManager=new to(t,e)}function Jr(t){switch(t){case Me.IN_PROGRESS:return Zr.STATUS_PENDING;case Me.ERROR:return Zr.STATUS_ERROR;case Me.SUCCESS:return Zr.STATUS_SUCCESS}throw new Error(`Unknown job status ${t}`)}!function(t){t.STATUS_NONE="STATUS_NONE",t.STATUS_PENDING="STATUS_PENDING",t.STATUS_ERROR="STATUS_ERROR",t.STATUS_SUCCESS="STATUS_SUCCESS",t.STATUS_LOGGED_OUT="STATUS_AUTH_ERROR"}(Zr||(Zr={}));const Qr=window.location.origin+window.location.pathname.replace(/\/$/,"");class to{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Zr.STATUS_NONE;constructor(t,e){this.editor=t,this.options={appendTo:"options",...e},t.on("storage:start:store",(t=>{t.publication=this.settings})),t.on("storage:end:load",(t=>{this.settings=t.publication??{},$e({type:je.HOSTING,connectorId:this.settings.connector?.connectorId}).then((t=>{})).catch((t=>{this.status=Zr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(Gr,(()=>this.startPublication())),t.Commands.add(Kr,((t,e,n)=>this.goLogin(n))),t.Commands.add(Yr,(()=>this.goLogout())),this.options.appendTo?this.dialog=new kr(t,{appendTo:this.options.appendTo}):console.info("PublicationUi is disabled because no appendTo option is set")}async goLogin(t){if(t.isLoggedIn)return this.settings={...this.settings,connector:t},this.status=Zr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Zr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${Qr}${on}${sn}${un}?connectorId=${e}&type=${n}`,"_blank"),new Promise((e=>{const n=async e=>{const r=e.data;"login"===r?.type&&(window.removeEventListener("message",n),r.error?(this.status=Zr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError(r.message,this.job,this.status)):(this.editor.trigger(lr.PUBLISH_LOGIN_END),this.settings.connector=t,this.settings.options=r.options,this.status=Zr.STATUS_NONE,this.editor.store(null),this.dialog&&this.dialog.displayPending(this.job,this.status)))};window.addEventListener("message",n,!1)}))}async goLogout(){try{await Re({type:je.HOSTING,connectorId:this.settings.connector.connectorId}),this.settings={},this.dialog&&this.dialog.displayPending(this.job,this.status)}catch(t){console.error("logout error",t),this.status=Zr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Zr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Zr.STATUS_PENDING,this.job=null,this.dialog&&this.dialog.displayPending(this.job,this.status),this.editor.trigger(lr.PUBLISH_START);const t=this.editor.getModel().get("user");if(!t)throw new Error("User not logged in to a storage connector");if(!this.settings.connector?.connectorId)throw new Error("User not logged in to a hosting connector");const e=this.options.websiteId,n=t.storage.connectorId;this.setPublicationTransformers();const r=this.editor.getProjectData(),o=this.editor.getModel().get("settings"),i=(await this.getHtmlFiles(o)).flatMap((t=>[{path:t.htmlPath,content:t.html,type:Ae.HTML},{path:t.cssPath,content:t.css,type:Ae.CSS}])).concat(r.assets.map((t=>{const e=Hr(this.editor,t.src,Ae.ASSET),n=Br(t.src).replace(/^\/assets\//,"");return{...t,path:e,src:n,type:Ae.ASSET}}))),s={...r,assets:r.assets.map((t=>({...t,src:Br(t.src)}))),settings:o,publication:this.settings,files:i};this.resetPublicationTransformers(),function(t,e){const n=t.getModel().get("config");e.files=n.publicationTransformers.reduce(((t,n)=>t.map(((t,r)=>{try{return e.pages[r],n.transformFile?n.transformFile(t)??t:t}catch(e){return console.error("Publication transformer: error transforming file",t,e),t}}))),e.files)}(this.editor,s),this.editor.trigger(lr.PUBLISH_DATA,s);try{const[t,r]=await He({websiteId:e,hostingId:this.settings.connector.connectorId,storageId:n,data:s,options:this.settings.options});this.job=r,this.status=Jr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Zr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Zr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status)),this.editor.trigger(lr.PUBLISH_ERROR,{success:!1,message:t.message}),void this.editor.trigger(lr.PUBLISH_END,{success:!1,message:t.message})}}async getHtmlFiles(t){return this.editor.Pages.getAll().map((e=>{const n=e.get("settings");function r(e){return(n||{})[e]||(t||[])[e]||""}const o=e.getMainComponent(),i=xr(e.get("name")),s=`/css/${i}.css`,a=`/${i}.html`,l=Rr(this.editor,s,Ae.CSS,Pe.HTML),c=Hr(this.editor,s,Ae.CSS),u=Hr(this.editor,a,Ae.HTML),p=this.editor.getHtml({component:o});return{html:`<!DOCTYPE html>\n<html lang="${r("lang")}">\n<head>\n<meta charset="UTF-8">\n<link rel="stylesheet" href="${l}" />\n${t?.head||""}\n${n?.head||""}\n<title>${r("title")}</title>\n<link rel="icon" href="${r("favicon")}" />\n${["description","og:title","og:description","og:image"].map((t=>`<meta name="${t}" property="${t}" content="${r(t)}"/>`)).join("\n")}\n</head>\n${p}\n</html>`,css:this.editor.getCss({component:o}),cssPath:c,htmlPath:u}}))}async trackProgress(){try{this.job=await Fe({jobId:this.job.jobId}),this.status=Jr(this.job.status)}catch(t){return this.status=Zr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status),this.editor.trigger(lr.PUBLISH_END,{success:!1,message:t.message}),void this.editor.trigger(lr.PUBLISH_ERROR,{success:!1,message:t.message})}this.job.status===Me.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(lr.PUBLISH_END,{success:this.job.status===Me.SUCCESS,message:this.job.message}),this.dialog&&this.dialog.displayPending(this.job,this.status)}setPublicationTransformers(){!function(t){const e=t.getModel().get("config");Ar(t,(n=>{if(n.get(Pr))console.warn("Publication transformer: HTML transform already altered",n);else{const r=n.toHTML.bind(n);n[Pr]=n.toHTML;const o=n.getStyle.bind(n);n[Lr]=n.getStyle;const i=n.get("attributes").href;if(i?.startsWith("./")&&(n[Nr]=i,n.set("attributes",{...n.get("attributes"),href:Rr(t,i,Ae.HTML,Pe.HTML)})),n.get("attributes").src){n[jr]=n.get("attributes").src;const e=Rr(t,n.get("attributes").src,Ae.ASSET,Pe.HTML);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[Mr]=n.get("src");const e=Rr(t,n.get("src"),Ae.ASSET,Pe.HTML);n.set("src",e)}n.toHTML=()=>e.publicationTransformers.reduce(((t,e)=>{try{return e.renderComponent?e.renderComponent(n,(()=>t))??t:t}catch(e){return console.error("Publication transformer: error rendering component",n,e),t}}),r()),n.getStyle=()=>$r(t,o())}}))}(this.editor),function(t){const e=t.getModel().get("config");t.Css.getAll().forEach((n=>{if(n[Ir])console.warn("Publication transformer: CSS transform already altered",n);else{const r=n.getStyle.bind(n);n[Ir]=n.getStyle,n.getStyle=()=>{try{const n=$r(t,r()),o=e.publicationTransformers.reduce(((t,e)=>({...e.renderCssRule?e.renderCssRule(t,(()=>n))??t:t})),n);return o}catch(t){return console.error("Publication transformer: error rendering style",n,t),r()}}}}))}(this.editor)}resetPublicationTransformers(){!function(t){Ar(t,(t=>{t[Pr]&&(t.toHTML=t[Pr],delete t[Pr]),t[Lr]&&(t.getStyle=t[Lr],delete t[Lr]),t[jr]&&(t.set("attributes",{...t.get("attributes"),src:t[jr]}),delete t[jr]),t[Mr]&&(t.set("src",t[Mr]),delete t[Mr]),t[Nr]&&(t.set("attributes",{...t.get("attributes"),href:t[Nr]}),delete t[Nr])}))}(this.editor),function(t){t.Css.getAll().forEach((t=>{t[Ir]&&(t.getStyle=t[Ir],delete t[Ir])}))}(this.editor)}}const eo="fa fa-fw fa-paste silex-button",no=" disabled",ro=[{name:"./project-bar",value:or},{name:"grapesjs-style-bg",value:Wn()},{name:"./settings",value:(t,e)=>{try{hr="3.0.0-alpha.134"}catch(t){}console.info("Silex version:",hr),t.Commands.add(fr,{run:(e,n,{page:r})=>{dr=t.Modal.open({title:r?"Page settings":"Site Settings",content:"",attributes:{class:"settings-dialog"}}).onceClose((()=>{n?.set&&n.set("active",0),t.stopCommand(fr)})),function(t,e,n=t.getModel()){const r=n.get("settings")||{};n.set("settings",r);const o=sr(n)?cr:ur;let i=o[0];Gt(At`
|
|
382
|
+
`}}displayPending(t,e){this.errorMessage=null,this.renderDialog(t,e)}displayError(t,e,n){console.info(t),this.errorMessage=t,this.renderDialog(e,n)}async closeDialog(){this.isOpen=!1,this.renderDialog(null,null),this.sender&&this.sender.set("active",0),this.sender=null}async toggleDialog(){this.isOpen?this.closeDialog():this.openDialog()}async openDialog(){this.isOpen=!0;const t=this.editor.Panels.getPanel("options")?.view.el.querySelector(".publish-button");if(t){const e=t.getBoundingClientRect(),n=450,r=20,o=50;this.move({left:e.right-n-r,top:e.bottom+10,width:n,minHeight:o})}else console.error("Unable to find publish button");this.renderDialog(null,Zr.STATUS_NONE)}}function Ar(t,e){t.Pages.getAll().forEach((t=>{t.getMainComponent().onAll((t=>e(t)))}))}const Pr="tmp-pre-publication-transformer-tohtml",jr="tmp-pre-publication-transformer-src",Mr="tmp-pre-publication-transformer-attributes-src",Lr="tmp-pre-publication-transformer-inline-css",Nr="tmp-pre-publication-transformer-href",Ir="tmp-pre-publication-transformer-tocss",Dr={renderComponent:(t,e)=>e(),renderCssRule:(t,e)=>e(),transformPath:(t,e)=>t,transformPermalink(t,e,n){switch(n){case Pe.HTML:return t;case Pe.CSS:return`../${t.replace(/^\//,"")}`;default:throw new Error(`Unknown initiator ${n}`)}},transformFile:t=>t};function $r(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${Rr(t,r,Ae.ASSET,Pe.CSS)})`}:e}function Rr(t,e,n,r){return t.getModel().get("config").publicationTransformers.reduce(((t,e)=>{try{return e.transformPermalink?e.transformPermalink(t,n,r)??t:t}catch(e){return console.error("Publication transformer: error transforming path",t,e),t}}),e)}function Hr(t,e,n){return t.getModel().get("config").publicationTransformers.reduce(((t,e)=>{try{return e.transformPath?e.transformPath(t,n)??t:t}catch(e){return console.error("Publication transformer: error transforming path",t,e),t}}),e)}const Fr=window.location.pathname.replace(/\/$/,""),Vr=window.location.origin;function Ur(t,e,n){if(t.startsWith("/assets")){const r=new URL(t,Vr);return r.pathname=r.pathname.replace(/^\/assets/,""),r.pathname=`${Fr}${on}${vn}${Cn}${r.pathname}`,r.searchParams.set("websiteId",e),r.searchParams.set("connectorId",n),`${decodeURIComponent(r.pathname)}${r.search}`}return console.warn("storedToDisplayed: path is not a stored path",t),t}function Br(t){const e=`${Fr}${on}${vn}${Cn}`;if(t.startsWith(e)){const n=new URL(t,Vr);n.pathname=n.pathname.replace(new RegExp(`^${e}`),""),n.pathname=`${Fr}/assets${n.pathname}`,n.searchParams.delete("websiteId"),n.searchParams.delete("connectorId");const r="/"+n.toString().replace(new RegExp(`^${Vr}${Fr}`),"").replace(/^\//,"");return decodeURIComponent(r)}return console.warn("displayedToStored: path is not a displayed path",t),t}const zr={transformPath(t,e){if(e===Ae.ASSET)return Br(t)},transformPermalink(t,e){if(e===Ae.ASSET)return Br(t)}};function Wr(t,e,n){const r=t.attributes?.src?{...t,attributes:{...t.attributes,src:Ur(t.attributes.src,e,n)}}:t;return r.components&&(r.components=r.components.map((t=>Wr(t,e,n)))),r}function qr(t){const e=t.attributes?.src?{...t,attributes:{...t.attributes,src:Br(t.attributes.src)}}:t;return e.components&&(e.components=e.components.map((t=>qr(t)))),e}const Gr="publish",Kr="publish-login",Yr="publish-logout";var Zr;function Xr(t,e){t.PublicationManager=new to(t,e)}function Jr(t){switch(t){case Me.IN_PROGRESS:return Zr.STATUS_PENDING;case Me.ERROR:return Zr.STATUS_ERROR;case Me.SUCCESS:return Zr.STATUS_SUCCESS}throw new Error(`Unknown job status ${t}`)}!function(t){t.STATUS_NONE="STATUS_NONE",t.STATUS_PENDING="STATUS_PENDING",t.STATUS_ERROR="STATUS_ERROR",t.STATUS_SUCCESS="STATUS_SUCCESS",t.STATUS_LOGGED_OUT="STATUS_AUTH_ERROR"}(Zr||(Zr={}));const Qr=window.location.origin+window.location.pathname.replace(/\/$/,"");class to{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Zr.STATUS_NONE;constructor(t,e){this.editor=t,this.options={appendTo:"options",...e},t.on("storage:start:store",(t=>{t.publication=this.settings})),t.on("storage:end:load",(t=>{this.settings=t.publication??{},$e({type:je.HOSTING,connectorId:this.settings.connector?.connectorId}).then((t=>{})).catch((t=>{this.status=Zr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(Gr,(()=>this.startPublication())),t.Commands.add(Kr,((t,e,n)=>this.goLogin(n))),t.Commands.add(Yr,(()=>this.goLogout())),this.options.appendTo?this.dialog=new kr(t,{appendTo:this.options.appendTo}):console.info("PublicationUi is disabled because no appendTo option is set")}async goLogin(t){if(t.isLoggedIn)return this.settings={...this.settings,connector:t},this.status=Zr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Zr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${Qr}${on}${sn}${un}?connectorId=${e}&type=${n}`,"_blank"),new Promise((e=>{const n=async e=>{const r=e.data;"login"===r?.type&&(window.removeEventListener("message",n),r.error?(this.status=Zr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError(r.message,this.job,this.status)):(this.editor.trigger(lr.PUBLISH_LOGIN_END),this.settings.connector=t,this.settings.options=r.options,this.status=Zr.STATUS_NONE,this.editor.store(null),this.dialog&&this.dialog.displayPending(this.job,this.status)))};window.addEventListener("message",n,!1)}))}async goLogout(){try{await Re({type:je.HOSTING,connectorId:this.settings.connector.connectorId}),this.settings={},this.dialog&&this.dialog.displayPending(this.job,this.status)}catch(t){console.error("logout error",t),this.status=Zr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Zr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Zr.STATUS_PENDING,this.job=null,this.dialog&&this.dialog.displayPending(this.job,this.status),this.editor.trigger(lr.PUBLISH_START);const t=this.editor.getModel().get("user");if(!t)throw new Error("User not logged in to a storage connector");if(!this.settings.connector?.connectorId)throw new Error("User not logged in to a hosting connector");const e=this.options.websiteId,n=t.storage.connectorId;this.setPublicationTransformers();const r=this.editor.getProjectData(),o=this.editor.getModel().get("settings"),i=(await this.getHtmlFiles(o)).flatMap((t=>[{path:t.htmlPath,content:t.html,type:Ae.HTML},{path:t.cssPath,content:t.css,type:Ae.CSS}])).concat(r.assets.map((t=>{const e=Hr(this.editor,t.src,Ae.ASSET),n=Br(t.src).replace(/^\/assets\//,"");return{...t,path:e,src:n,type:Ae.ASSET}}))),s={...r,assets:r.assets.map((t=>({...t,src:Br(t.src)}))),settings:o,publication:this.settings,files:i};this.resetPublicationTransformers(),function(t,e){const n=t.getModel().get("config");e.files=n.publicationTransformers.reduce(((t,n)=>t.map(((t,r)=>{try{return e.pages[r],n.transformFile?n.transformFile(t)??t:t}catch(e){return console.error("Publication transformer: error transforming file",t,e),t}}))),e.files)}(this.editor,s),this.editor.trigger(lr.PUBLISH_DATA,s);try{const[t,r]=await He({websiteId:e,hostingId:this.settings.connector.connectorId,storageId:n,data:s,options:this.settings.options});this.job=r,this.status=Jr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Zr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Zr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status)),this.editor.trigger(lr.PUBLISH_ERROR,{success:!1,message:t.message}),void this.editor.trigger(lr.PUBLISH_END,{success:!1,message:t.message})}}async getHtmlFiles(t){return this.editor.Pages.getAll().map((e=>{const n=e.get("settings");function r(e){return(n||{})[e]||(t||[])[e]||""}const o=e.getMainComponent(),i=xr(e.get("name")),s=`/css/${i}.css`,a=`/${i}.html`,l=Rr(this.editor,s,Ae.CSS,Pe.HTML),c=Hr(this.editor,s,Ae.CSS),u=Hr(this.editor,a,Ae.HTML),p=this.editor.getHtml({component:o});return{html:`<!DOCTYPE html>\n<html lang="${r("lang")}">\n<head>\n<meta charset="UTF-8">\n<link rel="stylesheet" href="${l}" />\n${t?.head||""}\n${n?.head||""}\n<title>${r("title")}</title>\n<link rel="icon" href="${r("favicon")}" />\n${["description","og:title","og:description","og:image"].map((t=>`<meta name="${t}" property="${t}" content="${r(t)}"/>`)).join("\n")}\n</head>\n${p}\n</html>`,css:this.editor.getCss({component:o}),cssPath:c,htmlPath:u}}))}async trackProgress(){try{this.job=await Fe({jobId:this.job.jobId}),this.status=Jr(this.job.status)}catch(t){return this.status=Zr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status),this.editor.trigger(lr.PUBLISH_END,{success:!1,message:t.message}),void this.editor.trigger(lr.PUBLISH_ERROR,{success:!1,message:t.message})}this.job.status===Me.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(lr.PUBLISH_END,{success:this.job.status===Me.SUCCESS,message:this.job.message}),this.dialog&&this.dialog.displayPending(this.job,this.status)}setPublicationTransformers(){!function(t){const e=t.getModel().get("config");Ar(t,(n=>{if(n.get(Pr))console.warn("Publication transformer: HTML transform already altered",n);else{const r=n.toHTML.bind(n);n[Pr]=n.toHTML;const o=n.getStyle.bind(n);n[Lr]=n.getStyle;const i=n.get("attributes").href;if(i?.startsWith("./")&&(n[Nr]=i,n.set("attributes",{...n.get("attributes"),href:Rr(t,i,Ae.HTML,Pe.HTML)})),n.get("attributes").src){n[jr]=n.get("attributes").src;const e=Rr(t,n.get("attributes").src,Ae.ASSET,Pe.HTML);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[Mr]=n.get("src");const e=Rr(t,n.get("src"),Ae.ASSET,Pe.HTML);n.set("src",e)}n.toHTML=()=>e.publicationTransformers.reduce(((t,e)=>{try{return e.renderComponent?e.renderComponent(n,(()=>t))??t:t}catch(e){return console.error("Publication transformer: error rendering component",n,e),t}}),r()),n.getStyle=()=>$r(t,o())}}))}(this.editor),function(t){const e=t.getModel().get("config");t.Css.getAll().forEach((n=>{if(n[Ir])console.warn("Publication transformer: CSS transform already altered",n);else{const r=n.getStyle.bind(n);n[Ir]=n.getStyle,n.getStyle=()=>{try{const n=$r(t,r()),o=e.publicationTransformers.reduce(((t,e)=>({...e.renderCssRule?e.renderCssRule(t,(()=>n))??t:t})),n);return o}catch(t){return console.error("Publication transformer: error rendering style",n,t),r()}}}}))}(this.editor)}resetPublicationTransformers(){!function(t){Ar(t,(t=>{t[Pr]&&(t.toHTML=t[Pr],delete t[Pr]),t[Lr]&&(t.getStyle=t[Lr],delete t[Lr]),t[jr]&&(t.set("attributes",{...t.get("attributes"),src:t[jr]}),delete t[jr]),t[Mr]&&(t.set("src",t[Mr]),delete t[Mr]),t[Nr]&&(t.set("attributes",{...t.get("attributes"),href:t[Nr]}),delete t[Nr])}))}(this.editor),function(t){t.Css.getAll().forEach((t=>{t[Ir]&&(t.getStyle=t[Ir],delete t[Ir])}))}(this.editor)}}const eo="fa fa-fw fa-paste silex-button",no=" disabled",ro=[{name:"./project-bar",value:or},{name:"grapesjs-style-bg",value:Wn()},{name:"./settings",value:(t,e)=>{try{hr="3.0.0-alpha.135"}catch(t){}console.info("Silex version:",hr),t.Commands.add(fr,{run:(e,n,{page:r})=>{dr=t.Modal.open({title:r?"Page settings":"Site Settings",content:"",attributes:{class:"settings-dialog"}}).onceClose((()=>{n?.set&&n.set("active",0),t.stopCommand(fr)})),function(t,e,n=t.getModel()){const r=n.get("settings")||{};n.set("settings",r);const o=sr(n)?cr:ur;let i=o[0];Gt(At`
|
|
383
383
|
<form class="silex-form">
|
|
384
384
|
<div class="silex-help">
|
|
385
385
|
${sr(n)?At`
|
package/package.json
CHANGED
package/src/css/_variables.scss
CHANGED