@silexlabs/silex 3.0.0-alpha.124 → 3.0.0-alpha.125

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.
@@ -301,7 +301,7 @@ var silex;(()=>{var t={99:function(t){"undefined"!=typeof globalThis?globalThis:
301
301
  @click=${()=>this.editor.Commands.stop(xr)}
302
302
  >Close</button>
303
303
  </footer>
304
- `}}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,Gr.STATUS_NONE)}}var Or;function Tr(t,e){t.Pages.getAll().forEach((t=>{t.getMainComponent().onAll((t=>e(t)))}))}!function(t){t.STARTUP_START="silex:startup:start",t.STARTUP_END="silex:startup:end",t.GRAPESJS_START="silex:grapesjs:start",t.GRAPESJS_END="silex:grapesjs:end",t.PUBLISH_START="silex:publish:start",t.PUBLISH_DATA="silex:publish:data",t.PUBLISH_END="silex:publish:end",t.PUBLISH_ERROR="silex:publish:error",t.PUBLISH_LOGIN_START="silex:publish:login:start",t.PUBLISH_LOGIN_END="silex:publish:login:end",t.ASSET_WRITE_END="silex:asset:write:end",t.WRITE_END="silex:write:end"}(Or||(Or={}));const Er="tmp-pre-publication-transformer-tohtml",kr="tmp-pre-publication-transformer-src",Ar="tmp-pre-publication-transformer-attributes-src",Pr="tmp-pre-publication-transformer-inline-css",jr="tmp-pre-publication-transformer-href",Mr="tmp-pre-publication-transformer-tocss",Lr={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 Nr(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${Ir(t,r,Ae.ASSET,Pe.CSS)})`}:e}function Ir(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 Dr(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 $r=window.location.pathname.replace(/\/$/,""),Rr=window.location.origin;function Hr(t,e,n){if(t.startsWith("/assets")){const r=new URL(t,Rr);return r.pathname=r.pathname.replace(/^\/assets/,""),r.pathname=`${$r}${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 Fr(t){const e=`${$r}${on}${vn}${Cn}`;if(t.startsWith(e)){const n=new URL(t,Rr);n.pathname=n.pathname.replace(new RegExp(`^${e}`),""),n.pathname=`${$r}/assets${n.pathname}`,n.searchParams.delete("websiteId"),n.searchParams.delete("connectorId");const r="/"+n.toString().replace(new RegExp(`^${Rr}${$r}`),"").replace(/^\//,"");return decodeURIComponent(r)}return console.warn("displayedToStored: path is not a displayed path",t),t}const Vr={transformPath(t,e){if(e===Ae.ASSET)return Fr(t)},transformPermalink(t,e){if(e===Ae.ASSET)return Fr(t)}};function Ur(t,e,n){const r=t.attributes?.src?{...t,attributes:{...t.attributes,src:Hr(t.attributes.src,e,n)}}:t;return r.components&&(r.components=r.components.map((t=>Ur(t,e,n)))),r}function Br(t){const e=t.attributes?.src?{...t,attributes:{...t.attributes,src:Fr(t.attributes.src)}}:t;return e.components&&(e.components=e.components.map((t=>Br(t)))),e}const zr="publish",Wr="publish-login",qr="publish-logout";var Gr;function Kr(t,e){t.PublicationManager=new Xr(t,e)}function Yr(t){switch(t){case Me.IN_PROGRESS:return Gr.STATUS_PENDING;case Me.ERROR:return Gr.STATUS_ERROR;case Me.SUCCESS:return Gr.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"}(Gr||(Gr={}));const Zr=window.location.origin+window.location.pathname.replace(/\/$/,"");class Xr{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Gr.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=Gr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(zr,(()=>this.startPublication())),t.Commands.add(Wr,((t,e,n)=>this.goLogin(n))),t.Commands.add(qr,(()=>this.goLogout())),this.options.appendTo?this.dialog=new Sr(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=Gr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Gr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${Zr}${on}${an}${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=Gr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError(r.message,this.job,this.status)):(this.editor.trigger(Or.PUBLISH_LOGIN_END),this.settings.connector=t,this.settings.options=r.options,this.status=Gr.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=Gr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Gr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Gr.STATUS_PENDING,this.job=null,this.dialog&&this.dialog.displayPending(this.job,this.status),this.editor.trigger(Or.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=Dr(this.editor,t.src,Ae.ASSET),n=Fr(t.src).replace(/^\/assets\//,"");return{...t,path:e,src:n,type:Ae.ASSET}}))),a={...r,assets:r.assets.map((t=>({...t,src:Fr(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,a),this.editor.trigger(Or.PUBLISH_DATA,a);try{const[t,r]=await He({websiteId:e,hostingId:this.settings.connector.connectorId,storageId:n,data:a,options:this.settings.options});this.job=r,this.status=Yr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Gr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Gr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status)),this.editor.trigger(Or.PUBLISH_ERROR,{success:!1,message:t.message}),void this.editor.trigger(Or.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=yr(e.get("name")),a=`/css/${i}.css`,s=`/${i}.html`,l=Ir(this.editor,a,Ae.CSS,Pe.HTML),c=Dr(this.editor,a,Ae.CSS),u=Dr(this.editor,s,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=Yr(this.job.status)}catch(t){return this.status=Gr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status),this.editor.trigger(Or.PUBLISH_END,{success:!1,message:t.message}),void this.editor.trigger(Or.PUBLISH_ERROR,{success:!1,message:t.message})}this.job.status===Me.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(Or.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");Tr(t,(n=>{if(n.get(Er))console.warn("Publication transformer: HTML transform already altered",n);else{const r=n.toHTML.bind(n);n[Er]=n.toHTML;const o=n.getStyle.bind(n);n[Pr]=n.getStyle;const i=n.get("attributes").href;if(i?.startsWith("./")&&(n[jr]=i,n.set("attributes",{...n.get("attributes"),href:Ir(t,i,Ae.HTML,Pe.HTML)})),n.get("attributes").src){n[kr]=n.get("attributes").src;const e=Ir(t,n.get("attributes").src,Ae.ASSET,Pe.HTML);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[Ar]=n.get("src");const e=Ir(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=()=>Nr(t,o())}}))}(this.editor),function(t){const e=t.getModel().get("config");t.Css.getAll().forEach((n=>{if(n[Mr])console.warn("Publication transformer: CSS transform already altered",n);else{const r=n.getStyle.bind(n);n[Mr]=n.getStyle,n.getStyle=()=>{try{const n=Nr(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){Tr(t,(t=>{t[Er]&&(t.toHTML=t[Er],delete t[Er]),t[Pr]&&(t.getStyle=t[Pr],delete t[Pr]),t[kr]&&(t.set("attributes",{...t.get("attributes"),src:t[kr]}),delete t[kr]),t[Ar]&&(t.set("src",t[Ar]),delete t[Ar]),t[jr]&&(t.set("attributes",{...t.get("attributes"),href:t[jr]}),delete t[jr])}))}(this.editor),function(t){t.Css.getAll().forEach((t=>{t[Mr]&&(t.getStyle=t[Mr],delete t[Mr])}))}(this.editor)}}const Jr=[{name:"./project-bar",value:or},{name:"grapesjs-style-bg",value:Wn()},{name:"./settings",value:(t,e)=>{try{cr="3.0.0-alpha.124"}catch(t){}console.info("Silex version:",cr),t.Commands.add(lr,{run:(e,n,{page:r})=>{sr=t.Modal.open({title:r?"Page settings":"Site Settings",content:"",attributes:{class:"settings-dialog"}}).onceClose((()=>{n?.set&&n.set("active",0),t.stopCommand(lr)})),function(t,e,n=t.getModel()){const r=n.get("settings")||{};n.set("settings",r),Gt(At`
304
+ `}}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,Gr.STATUS_NONE)}}var Or;function Tr(t,e){t.Pages.getAll().forEach((t=>{t.getMainComponent().onAll((t=>e(t)))}))}!function(t){t.STARTUP_START="silex:startup:start",t.STARTUP_END="silex:startup:end",t.GRAPESJS_START="silex:grapesjs:start",t.GRAPESJS_END="silex:grapesjs:end",t.PUBLISH_START="silex:publish:start",t.PUBLISH_DATA="silex:publish:data",t.PUBLISH_END="silex:publish:end",t.PUBLISH_ERROR="silex:publish:error",t.PUBLISH_LOGIN_START="silex:publish:login:start",t.PUBLISH_LOGIN_END="silex:publish:login:end",t.ASSET_WRITE_END="silex:asset:write:end",t.WRITE_END="silex:write:end"}(Or||(Or={}));const Er="tmp-pre-publication-transformer-tohtml",kr="tmp-pre-publication-transformer-src",Ar="tmp-pre-publication-transformer-attributes-src",Pr="tmp-pre-publication-transformer-inline-css",jr="tmp-pre-publication-transformer-href",Mr="tmp-pre-publication-transformer-tocss",Lr={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 Nr(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${Ir(t,r,Ae.ASSET,Pe.CSS)})`}:e}function Ir(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 Dr(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 $r=window.location.pathname.replace(/\/$/,""),Rr=window.location.origin;function Hr(t,e,n){if(t.startsWith("/assets")){const r=new URL(t,Rr);return r.pathname=r.pathname.replace(/^\/assets/,""),r.pathname=`${$r}${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 Fr(t){const e=`${$r}${on}${vn}${Cn}`;if(t.startsWith(e)){const n=new URL(t,Rr);n.pathname=n.pathname.replace(new RegExp(`^${e}`),""),n.pathname=`${$r}/assets${n.pathname}`,n.searchParams.delete("websiteId"),n.searchParams.delete("connectorId");const r="/"+n.toString().replace(new RegExp(`^${Rr}${$r}`),"").replace(/^\//,"");return decodeURIComponent(r)}return console.warn("displayedToStored: path is not a displayed path",t),t}const Vr={transformPath(t,e){if(e===Ae.ASSET)return Fr(t)},transformPermalink(t,e){if(e===Ae.ASSET)return Fr(t)}};function Ur(t,e,n){const r=t.attributes?.src?{...t,attributes:{...t.attributes,src:Hr(t.attributes.src,e,n)}}:t;return r.components&&(r.components=r.components.map((t=>Ur(t,e,n)))),r}function Br(t){const e=t.attributes?.src?{...t,attributes:{...t.attributes,src:Fr(t.attributes.src)}}:t;return e.components&&(e.components=e.components.map((t=>Br(t)))),e}const zr="publish",Wr="publish-login",qr="publish-logout";var Gr;function Kr(t,e){t.PublicationManager=new Xr(t,e)}function Yr(t){switch(t){case Me.IN_PROGRESS:return Gr.STATUS_PENDING;case Me.ERROR:return Gr.STATUS_ERROR;case Me.SUCCESS:return Gr.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"}(Gr||(Gr={}));const Zr=window.location.origin+window.location.pathname.replace(/\/$/,"");class Xr{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Gr.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=Gr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(zr,(()=>this.startPublication())),t.Commands.add(Wr,((t,e,n)=>this.goLogin(n))),t.Commands.add(qr,(()=>this.goLogout())),this.options.appendTo?this.dialog=new Sr(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=Gr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Gr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${Zr}${on}${an}${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=Gr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError(r.message,this.job,this.status)):(this.editor.trigger(Or.PUBLISH_LOGIN_END),this.settings.connector=t,this.settings.options=r.options,this.status=Gr.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=Gr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Gr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Gr.STATUS_PENDING,this.job=null,this.dialog&&this.dialog.displayPending(this.job,this.status),this.editor.trigger(Or.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=Dr(this.editor,t.src,Ae.ASSET),n=Fr(t.src).replace(/^\/assets\//,"");return{...t,path:e,src:n,type:Ae.ASSET}}))),a={...r,assets:r.assets.map((t=>({...t,src:Fr(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,a),this.editor.trigger(Or.PUBLISH_DATA,a);try{const[t,r]=await He({websiteId:e,hostingId:this.settings.connector.connectorId,storageId:n,data:a,options:this.settings.options});this.job=r,this.status=Yr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Gr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Gr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status)),this.editor.trigger(Or.PUBLISH_ERROR,{success:!1,message:t.message}),void this.editor.trigger(Or.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=yr(e.get("name")),a=`/css/${i}.css`,s=`/${i}.html`,l=Ir(this.editor,a,Ae.CSS,Pe.HTML),c=Dr(this.editor,a,Ae.CSS),u=Dr(this.editor,s,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=Yr(this.job.status)}catch(t){return this.status=Gr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status),this.editor.trigger(Or.PUBLISH_END,{success:!1,message:t.message}),void this.editor.trigger(Or.PUBLISH_ERROR,{success:!1,message:t.message})}this.job.status===Me.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(Or.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");Tr(t,(n=>{if(n.get(Er))console.warn("Publication transformer: HTML transform already altered",n);else{const r=n.toHTML.bind(n);n[Er]=n.toHTML;const o=n.getStyle.bind(n);n[Pr]=n.getStyle;const i=n.get("attributes").href;if(i?.startsWith("./")&&(n[jr]=i,n.set("attributes",{...n.get("attributes"),href:Ir(t,i,Ae.HTML,Pe.HTML)})),n.get("attributes").src){n[kr]=n.get("attributes").src;const e=Ir(t,n.get("attributes").src,Ae.ASSET,Pe.HTML);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[Ar]=n.get("src");const e=Ir(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=()=>Nr(t,o())}}))}(this.editor),function(t){const e=t.getModel().get("config");t.Css.getAll().forEach((n=>{if(n[Mr])console.warn("Publication transformer: CSS transform already altered",n);else{const r=n.getStyle.bind(n);n[Mr]=n.getStyle,n.getStyle=()=>{try{const n=Nr(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){Tr(t,(t=>{t[Er]&&(t.toHTML=t[Er],delete t[Er]),t[Pr]&&(t.getStyle=t[Pr],delete t[Pr]),t[kr]&&(t.set("attributes",{...t.get("attributes"),src:t[kr]}),delete t[kr]),t[Ar]&&(t.set("src",t[Ar]),delete t[Ar]),t[jr]&&(t.set("attributes",{...t.get("attributes"),href:t[jr]}),delete t[jr])}))}(this.editor),function(t){t.Css.getAll().forEach((t=>{t[Mr]&&(t.getStyle=t[Mr],delete t[Mr])}))}(this.editor)}}const Jr=[{name:"./project-bar",value:or},{name:"grapesjs-style-bg",value:Wn()},{name:"./settings",value:(t,e)=>{try{cr="3.0.0-alpha.125"}catch(t){}console.info("Silex version:",cr),t.Commands.add(lr,{run:(e,n,{page:r})=>{sr=t.Modal.open({title:r?"Page settings":"Site Settings",content:"",attributes:{class:"settings-dialog"}}).onceClose((()=>{n?.set&&n.set("active",0),t.stopCommand(lr)})),function(t,e,n=t.getModel()){const r=n.get("settings")||{};n.set("settings",r),Gt(At`
305
305
  <p>The page settings will override site settings, <a href="https://github.com/silexlabs/Silex/wiki/Settings" target="_blank">more info about settings here</a>.</p>
306
306
  <form class="silex-form">
307
307
  <h2>General settings</h2>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silexlabs/silex",
3
3
  "description": "Free and easy website builder for everyone.",
4
- "version": "3.0.0-alpha.124",
4
+ "version": "3.0.0-alpha.125",
5
5
  "version:backwardcompat": "3.0.0",
6
6
  "author": {
7
7
  "name": "Alex Hoyau",