@silexlabs/silex 3.0.0-alpha.137 → 3.0.0-alpha.138
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
|
@@ -159,7 +159,7 @@ var silex;(()=>{var t={99:function(t){"undefined"!=typeof globalThis?globalThis:
|
|
|
159
159
|
><span>${e.text}</span></div>
|
|
160
160
|
`))}
|
|
161
161
|
</header>
|
|
162
|
-
`,r),document.body.appendChild(r),t.on("load",(()=>{n.view.el.appendChild(r)}))),"string"==typeof e.command&&t.Commands.add(e.command,{run(){e.attributes.containerClassName&&(n.set("visible",!0),r.classList.remove("gjs-hidden"),document.body.classList.add("silex-squeeze-left"),t.refresh())},stop(){e.attributes.containerClassName&&(n.set("visible",!1),r.classList.add("gjs-hidden"),document.body.classList.remove("silex-squeeze-left"),t.refresh())}})}(t,e))),t.on("stop:preview",(()=>{n.set("visible",!1),ir(t)})),t.on("load device:select page",(()=>{ir(t)}))};function ir(t){
|
|
162
|
+
`,r),document.body.appendChild(r),t.on("load",(()=>{n.view.el.appendChild(r)}))),"string"==typeof e.command&&t.Commands.add(e.command,{run(){e.attributes.containerClassName&&(n.set("visible",!0),r.classList.remove("gjs-hidden"),document.body.classList.add("silex-squeeze-left"),t.refresh())},stop(){e.attributes.containerClassName&&(n.set("visible",!1),r.classList.add("gjs-hidden"),document.body.classList.remove("silex-squeeze-left"),t.refresh())}})}(t,e))),t.on("stop:preview",(()=>{n.set("visible",!1),ir(t)})),t.on("load device:select page",(()=>{ir(t)}))};function ir(t){t.Panels.getPanel(rr).get("visible")?document.body.classList.add("silex-squeeze-left"):document.body.classList.remove("silex-squeeze-left"),t.refresh()}const sr="settings-head-wrapper";function ar(t){return!!t.getHtml}const lr=[{id:"general",label:"General",render:(t,e)=>At`
|
|
163
163
|
<div id="settings-general" class="silex-hideable">
|
|
164
164
|
<div class="gjs-sm-sector-title">General</div>
|
|
165
165
|
<div class="silex-form__group col2">
|
|
@@ -379,7 +379,7 @@ var silex;(()=>{var t={99:function(t){"undefined"!=typeof globalThis?globalThis:
|
|
|
379
379
|
@click=${()=>this.editor.Commands.stop(Er)}
|
|
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,Xr.STATUS_NONE)}}function Pr(t,e){t.Pages.getAll().forEach((t=>{t.getMainComponent().onAll((t=>e(t)))}))}const jr="tmp-pre-publication-transformer-tohtml",Mr="tmp-pre-publication-transformer-src",Lr="tmp-pre-publication-transformer-attributes-src",Nr="tmp-pre-publication-transformer-inline-css",Ir="tmp-pre-publication-transformer-href",Dr="tmp-pre-publication-transformer-tocss",$r={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 Rr(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${Hr(t,r,Ae.ASSET,Pe.CSS)})`}:e}function Hr(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 Fr(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 Vr=window.location.pathname.replace(/\/$/,""),Ur=window.location.origin;function Br(t,e,n){if(t.startsWith("/assets")){const r=new URL(t,Ur);return r.pathname=r.pathname.replace(/^\/assets/,""),r.pathname=`${Vr}${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 zr(t){const e=`${Vr}${on}${vn}${Cn}`;if(t.startsWith(e)){const n=new URL(t,Ur);n.pathname=n.pathname.replace(new RegExp(`^${e}`),""),n.pathname=`${Vr}/assets${n.pathname}`,n.searchParams.delete("websiteId"),n.searchParams.delete("connectorId");const r="/"+n.toString().replace(new RegExp(`^${Ur}${Vr}`),"").replace(/^\//,"");return decodeURIComponent(r)}return console.warn("displayedToStored: path is not a displayed path",t),t}const Wr={transformPath(t,e){if(e===Ae.ASSET)return zr(t)},transformPermalink(t,e){if(e===Ae.ASSET)return zr(t)}};function qr(t,e,n){const r=t.attributes?.src?{...t,attributes:{...t.attributes,src:Br(t.attributes.src,e,n)}}:t;return r.components&&(r.components=r.components.map((t=>qr(t,e,n)))),r}function Gr(t){const e=t.attributes?.src?{...t,attributes:{...t.attributes,src:zr(t.attributes.src)}}:t;return e.components&&(e.components=e.components.map((t=>Gr(t)))),e}const Kr="publish",Yr="publish-login",Zr="publish-logout";var Xr;function Jr(t,e){t.PublicationManager=new eo(t,e)}function Qr(t){switch(t){case Me.IN_PROGRESS:return Xr.STATUS_PENDING;case Me.ERROR:return Xr.STATUS_ERROR;case Me.SUCCESS:return Xr.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"}(Xr||(Xr={}));const to=window.location.origin+window.location.pathname.replace(/\/$/,"");class eo{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Xr.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=Xr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(Kr,(()=>this.startPublication())),t.Commands.add(Yr,((t,e,n)=>this.goLogin(n))),t.Commands.add(Zr,(()=>this.goLogout())),this.options.appendTo?this.dialog=new Ar(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=Xr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Xr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${to}${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=Xr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError(r.message,this.job,this.status)):(this.editor.trigger(cr.PUBLISH_LOGIN_END),this.settings.connector=t,this.settings.options=r.options,this.status=Xr.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=Xr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Xr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Xr.STATUS_PENDING,this.job=null,this.dialog&&this.dialog.displayPending(this.job,this.status),this.editor.trigger(cr.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=Fr(this.editor,t.src,Ae.ASSET),n=zr(t.src).replace(/^\/assets\//,"");return{...t,path:e,src:n,type:Ae.ASSET}}))),s={...r,assets:r.assets.map((t=>({...t,src:zr(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(cr.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=Qr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Xr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Xr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status)),this.editor.trigger(cr.PUBLISH_ERROR,{success:!1,message:t.message}),void this.editor.trigger(cr.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=Cr(e.get("name")),s=`/css/${i}.css`,a=`/${i}.html`,l=Hr(this.editor,s,Ae.CSS,Pe.HTML),c=Fr(this.editor,s,Ae.CSS),u=Fr(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=Qr(this.job.status)}catch(t){return this.status=Xr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status),this.editor.trigger(cr.PUBLISH_END,{success:!1,message:t.message}),void this.editor.trigger(cr.PUBLISH_ERROR,{success:!1,message:t.message})}this.job.status===Me.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(cr.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");Pr(t,(n=>{if(n.get(jr))console.warn("Publication transformer: HTML transform already altered",n);else{const r=n.toHTML.bind(n);n[jr]=n.toHTML;const o=n.getStyle.bind(n);n[Nr]=n.getStyle;const i=n.get("attributes").href;if(i?.startsWith("./")&&(n[Ir]=i,n.set("attributes",{...n.get("attributes"),href:Hr(t,i,Ae.HTML,Pe.HTML)})),n.get("attributes").src){n[Mr]=n.get("attributes").src;const e=Hr(t,n.get("attributes").src,Ae.ASSET,Pe.HTML);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[Lr]=n.get("src");const e=Hr(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=()=>Rr(t,o())}}))}(this.editor),function(t){const e=t.getModel().get("config");t.Css.getAll().forEach((n=>{if(n[Dr])console.warn("Publication transformer: CSS transform already altered",n);else{const r=n.getStyle.bind(n);n[Dr]=n.getStyle,n.getStyle=()=>{try{const n=Rr(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){Pr(t,(t=>{t[jr]&&(t.toHTML=t[jr],delete t[jr]),t[Nr]&&(t.getStyle=t[Nr],delete t[Nr]),t[Mr]&&(t.set("attributes",{...t.get("attributes"),src:t[Mr]}),delete t[Mr]),t[Lr]&&(t.set("src",t[Lr]),delete t[Lr]),t[Ir]&&(t.set("attributes",{...t.get("attributes"),href:t[Ir]}),delete t[Ir])}))}(this.editor),function(t){t.Css.getAll().forEach((t=>{t[Dr]&&(t.getStyle=t[Dr],delete t[Dr])}))}(this.editor)}}const no="fa fa-fw fa-paste silex-button",ro=" disabled",oo=[{name:"./project-bar",value:or},{name:"grapesjs-style-bg",value:Wn()},{name:"./settings",value:(t,e)=>{try{gr="3.0.0-alpha.137"}catch(t){}console.info("Silex version:",gr),t.Commands.add(hr,{run:(e,n,{page:r})=>{fr=t.Modal.open({title:r?"Page settings":"Site Settings",content:"",attributes:{class:"settings-dialog"}}).onceClose((()=>{n?.set&&n.set("active",0),t.stopCommand(hr)})),function(t,e,n=t.getModel()){const r=n.get("settings")||{};n.set("settings",r);const o=ar(n)?ur:pr;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,Xr.STATUS_NONE)}}function Pr(t,e){t.Pages.getAll().forEach((t=>{t.getMainComponent().onAll((t=>e(t)))}))}const jr="tmp-pre-publication-transformer-tohtml",Mr="tmp-pre-publication-transformer-src",Lr="tmp-pre-publication-transformer-attributes-src",Nr="tmp-pre-publication-transformer-inline-css",Ir="tmp-pre-publication-transformer-href",Dr="tmp-pre-publication-transformer-tocss",$r={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 Rr(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${Hr(t,r,Ae.ASSET,Pe.CSS)})`}:e}function Hr(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 Fr(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 Vr=window.location.pathname.replace(/\/$/,""),Ur=window.location.origin;function Br(t,e,n){if(t.startsWith("/assets")){const r=new URL(t,Ur);return r.pathname=r.pathname.replace(/^\/assets/,""),r.pathname=`${Vr}${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 zr(t){const e=`${Vr}${on}${vn}${Cn}`;if(t.startsWith(e)){const n=new URL(t,Ur);n.pathname=n.pathname.replace(new RegExp(`^${e}`),""),n.pathname=`${Vr}/assets${n.pathname}`,n.searchParams.delete("websiteId"),n.searchParams.delete("connectorId");const r="/"+n.toString().replace(new RegExp(`^${Ur}${Vr}`),"").replace(/^\//,"");return decodeURIComponent(r)}return console.warn("displayedToStored: path is not a displayed path",t),t}const Wr={transformPath(t,e){if(e===Ae.ASSET)return zr(t)},transformPermalink(t,e){if(e===Ae.ASSET)return zr(t)}};function qr(t,e,n){const r=t.attributes?.src?{...t,attributes:{...t.attributes,src:Br(t.attributes.src,e,n)}}:t;return r.components&&(r.components=r.components.map((t=>qr(t,e,n)))),r}function Gr(t){const e=t.attributes?.src?{...t,attributes:{...t.attributes,src:zr(t.attributes.src)}}:t;return e.components&&(e.components=e.components.map((t=>Gr(t)))),e}const Kr="publish",Yr="publish-login",Zr="publish-logout";var Xr;function Jr(t,e){t.PublicationManager=new eo(t,e)}function Qr(t){switch(t){case Me.IN_PROGRESS:return Xr.STATUS_PENDING;case Me.ERROR:return Xr.STATUS_ERROR;case Me.SUCCESS:return Xr.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"}(Xr||(Xr={}));const to=window.location.origin+window.location.pathname.replace(/\/$/,"");class eo{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Xr.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=Xr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(Kr,(()=>this.startPublication())),t.Commands.add(Yr,((t,e,n)=>this.goLogin(n))),t.Commands.add(Zr,(()=>this.goLogout())),this.options.appendTo?this.dialog=new Ar(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=Xr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Xr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${to}${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=Xr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError(r.message,this.job,this.status)):(this.editor.trigger(cr.PUBLISH_LOGIN_END),this.settings.connector=t,this.settings.options=r.options,this.status=Xr.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=Xr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Xr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Xr.STATUS_PENDING,this.job=null,this.dialog&&this.dialog.displayPending(this.job,this.status),this.editor.trigger(cr.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=Fr(this.editor,t.src,Ae.ASSET),n=zr(t.src).replace(/^\/assets\//,"");return{...t,path:e,src:n,type:Ae.ASSET}}))),s={...r,assets:r.assets.map((t=>({...t,src:zr(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(cr.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=Qr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Xr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Xr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status)),this.editor.trigger(cr.PUBLISH_ERROR,{success:!1,message:t.message}),void this.editor.trigger(cr.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=Cr(e.get("name")),s=`/css/${i}.css`,a=`/${i}.html`,l=Hr(this.editor,s,Ae.CSS,Pe.HTML),c=Fr(this.editor,s,Ae.CSS),u=Fr(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=Qr(this.job.status)}catch(t){return this.status=Xr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status),this.editor.trigger(cr.PUBLISH_END,{success:!1,message:t.message}),void this.editor.trigger(cr.PUBLISH_ERROR,{success:!1,message:t.message})}this.job.status===Me.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(cr.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");Pr(t,(n=>{if(n.get(jr))console.warn("Publication transformer: HTML transform already altered",n);else{const r=n.toHTML.bind(n);n[jr]=n.toHTML;const o=n.getStyle.bind(n);n[Nr]=n.getStyle;const i=n.get("attributes").href;if(i?.startsWith("./")&&(n[Ir]=i,n.set("attributes",{...n.get("attributes"),href:Hr(t,i,Ae.HTML,Pe.HTML)})),n.get("attributes").src){n[Mr]=n.get("attributes").src;const e=Hr(t,n.get("attributes").src,Ae.ASSET,Pe.HTML);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[Lr]=n.get("src");const e=Hr(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=()=>Rr(t,o())}}))}(this.editor),function(t){const e=t.getModel().get("config");t.Css.getAll().forEach((n=>{if(n[Dr])console.warn("Publication transformer: CSS transform already altered",n);else{const r=n.getStyle.bind(n);n[Dr]=n.getStyle,n.getStyle=()=>{try{const n=Rr(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){Pr(t,(t=>{t[jr]&&(t.toHTML=t[jr],delete t[jr]),t[Nr]&&(t.getStyle=t[Nr],delete t[Nr]),t[Mr]&&(t.set("attributes",{...t.get("attributes"),src:t[Mr]}),delete t[Mr]),t[Lr]&&(t.set("src",t[Lr]),delete t[Lr]),t[Ir]&&(t.set("attributes",{...t.get("attributes"),href:t[Ir]}),delete t[Ir])}))}(this.editor),function(t){t.Css.getAll().forEach((t=>{t[Dr]&&(t.getStyle=t[Dr],delete t[Dr])}))}(this.editor)}}const no="fa fa-fw fa-paste silex-button",ro=" disabled",oo=[{name:"./project-bar",value:or},{name:"grapesjs-style-bg",value:Wn()},{name:"./settings",value:(t,e)=>{try{gr="3.0.0-alpha.138"}catch(t){}console.info("Silex version:",gr),t.Commands.add(hr,{run:(e,n,{page:r})=>{fr=t.Modal.open({title:r?"Page settings":"Site Settings",content:"",attributes:{class:"settings-dialog"}}).onceClose((()=>{n?.set&&n.set("active",0),t.stopCommand(hr)})),function(t,e,n=t.getModel()){const r=n.get("settings")||{};n.set("settings",r);const o=ar(n)?ur:pr;let i=o[0];Gt(At`
|
|
383
383
|
<form class="silex-form">
|
|
384
384
|
<div class="silex-help">
|
|
385
385
|
${ar(n)?At`
|
|
@@ -43,7 +43,6 @@ export const projectBarPlugin = (editor, opts) => {
|
|
|
43
43
|
};
|
|
44
44
|
function updateSqueez(editor) {
|
|
45
45
|
const containerPanel = editor.Panels.getPanel(containerPanelId);
|
|
46
|
-
console.log('zzz', containerPanel, containerPanel.get('visible'));
|
|
47
46
|
// make sure the squeez corresponds to the state (reset when change page)
|
|
48
47
|
if (containerPanel.get('visible'))
|
|
49
48
|
document.body.classList.add('silex-squeeze-left');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-bar.js","sourceRoot":"","sources":["../../../../../src/ts/client/grapesjs/project-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,MAAM,UAAU,CAAA;AAErC,MAAM,OAAO,GAAG,mBAAmB,CAAA;AACnC,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAiBhD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;IAC/C,yDAAyD;IACzD,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC5C,EAAE,EAAE,gBAAgB;QACpB,OAAO,EAAI,KAAK;KACjB,CAAC,CAAA;IACF,2CAA2C;IAC3C,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACrB,EAAE,EAAE,OAAO;QACX,OAAO,EAAE,IAAI,CAAC,MAAM;QACpB,OAAO,EAAI,IAAI;KAChB,CAAC,CAAA;IACF,kCAAkC;IAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;IAElD,8CAA8C;IAC9C,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;QAC7B,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QACpC,YAAY,CAAC,MAAM,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,+CAA+C;IAC/C,MAAM,CAAC,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;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editor: Editor) {
|
|
67
67
|
const containerPanel = editor.Panels.getPanel(containerPanelId)
|
|
68
|
-
console.log('zzz', containerPanel, containerPanel.get('visible'))
|
|
69
68
|
// make sure the squeez corresponds to the state (reset when change page)
|
|
70
69
|
if(containerPanel.get('visible')) document.body.classList.add('silex-squeeze-left')
|
|
71
70
|
else document.body.classList.remove('silex-squeeze-left')
|