@silexlabs/silex 3.0.0-alpha.128 → 3.0.0-alpha.129

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.
@@ -3864,9 +3864,13 @@ See http://bgrins.github.io/spectrum/themes/ for instructions.
3864
3864
  }
3865
3865
 
3866
3866
  .silex-hidden {
3867
+ /* do not really hide, because it breaks the code editor init in the site settings + for animation */
3867
3868
  visibility: hidden;
3868
3869
  position: absolute;
3869
3870
  opacity: 0;
3871
+ height: 10px;
3872
+ width: 10px;
3873
+ overflow: hidden;
3870
3874
  }
3871
3875
 
3872
3876
  .settings-dialog > div {
@@ -301,7 +301,7 @@ var silex;(()=>{var t={99:function(t){"undefined"!=typeof globalThis?globalThis:
301
301
  @click=${()=>this.editor.Commands.stop(Sr)}
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,Yr.STATUS_NONE)}}var Er;function kr(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"}(Er||(Er={}));const Ar="tmp-pre-publication-transformer-tohtml",Pr="tmp-pre-publication-transformer-src",jr="tmp-pre-publication-transformer-attributes-src",Mr="tmp-pre-publication-transformer-inline-css",Lr="tmp-pre-publication-transformer-href",Nr="tmp-pre-publication-transformer-tocss",Ir={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 Dr(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${$r(t,r,Ae.ASSET,Pe.CSS)})`}:e}function $r(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 Rr(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 Hr=window.location.pathname.replace(/\/$/,""),Fr=window.location.origin;function Vr(t,e,n){if(t.startsWith("/assets")){const r=new URL(t,Fr);return r.pathname=r.pathname.replace(/^\/assets/,""),r.pathname=`${Hr}${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 Ur(t){const e=`${Hr}${on}${vn}${Cn}`;if(t.startsWith(e)){const n=new URL(t,Fr);n.pathname=n.pathname.replace(new RegExp(`^${e}`),""),n.pathname=`${Hr}/assets${n.pathname}`,n.searchParams.delete("websiteId"),n.searchParams.delete("connectorId");const r="/"+n.toString().replace(new RegExp(`^${Fr}${Hr}`),"").replace(/^\//,"");return decodeURIComponent(r)}return console.warn("displayedToStored: path is not a displayed path",t),t}const Br={transformPath(t,e){if(e===Ae.ASSET)return Ur(t)},transformPermalink(t,e){if(e===Ae.ASSET)return Ur(t)}};function zr(t,e,n){const r=t.attributes?.src?{...t,attributes:{...t.attributes,src:Vr(t.attributes.src,e,n)}}:t;return r.components&&(r.components=r.components.map((t=>zr(t,e,n)))),r}function Wr(t){const e=t.attributes?.src?{...t,attributes:{...t.attributes,src:Ur(t.attributes.src)}}:t;return e.components&&(e.components=e.components.map((t=>Wr(t)))),e}const qr="publish",Gr="publish-login",Kr="publish-logout";var Yr;function Zr(t,e){t.PublicationManager=new Qr(t,e)}function Xr(t){switch(t){case Me.IN_PROGRESS:return Yr.STATUS_PENDING;case Me.ERROR:return Yr.STATUS_ERROR;case Me.SUCCESS:return Yr.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"}(Yr||(Yr={}));const Jr=window.location.origin+window.location.pathname.replace(/\/$/,"");class Qr{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Yr.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=Yr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(qr,(()=>this.startPublication())),t.Commands.add(Gr,((t,e,n)=>this.goLogin(n))),t.Commands.add(Kr,(()=>this.goLogout())),this.options.appendTo?this.dialog=new Tr(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=Yr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Yr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${Jr}${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=Yr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError(r.message,this.job,this.status)):(this.editor.trigger(Er.PUBLISH_LOGIN_END),this.settings.connector=t,this.settings.options=r.options,this.status=Yr.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=Yr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Yr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Yr.STATUS_PENDING,this.job=null,this.dialog&&this.dialog.displayPending(this.job,this.status),this.editor.trigger(Er.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=Rr(this.editor,t.src,Ae.ASSET),n=Ur(t.src).replace(/^\/assets\//,"");return{...t,path:e,src:n,type:Ae.ASSET}}))),s={...r,assets:r.assets.map((t=>({...t,src:Ur(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(Er.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=Xr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Yr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Yr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status)),this.editor.trigger(Er.PUBLISH_ERROR,{success:!1,message:t.message}),void this.editor.trigger(Er.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=wr(e.get("name")),s=`/css/${i}.css`,a=`/${i}.html`,l=$r(this.editor,s,Ae.CSS,Pe.HTML),c=Rr(this.editor,s,Ae.CSS),u=Rr(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=Xr(this.job.status)}catch(t){return this.status=Yr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status),this.editor.trigger(Er.PUBLISH_END,{success:!1,message:t.message}),void this.editor.trigger(Er.PUBLISH_ERROR,{success:!1,message:t.message})}this.job.status===Me.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(Er.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");kr(t,(n=>{if(n.get(Ar))console.warn("Publication transformer: HTML transform already altered",n);else{const r=n.toHTML.bind(n);n[Ar]=n.toHTML;const o=n.getStyle.bind(n);n[Mr]=n.getStyle;const i=n.get("attributes").href;if(i?.startsWith("./")&&(n[Lr]=i,n.set("attributes",{...n.get("attributes"),href:$r(t,i,Ae.HTML,Pe.HTML)})),n.get("attributes").src){n[Pr]=n.get("attributes").src;const e=$r(t,n.get("attributes").src,Ae.ASSET,Pe.HTML);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[jr]=n.get("src");const e=$r(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=()=>Dr(t,o())}}))}(this.editor),function(t){const e=t.getModel().get("config");t.Css.getAll().forEach((n=>{if(n[Nr])console.warn("Publication transformer: CSS transform already altered",n);else{const r=n.getStyle.bind(n);n[Nr]=n.getStyle,n.getStyle=()=>{try{const n=Dr(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){kr(t,(t=>{t[Ar]&&(t.toHTML=t[Ar],delete t[Ar]),t[Mr]&&(t.getStyle=t[Mr],delete t[Mr]),t[Pr]&&(t.set("attributes",{...t.get("attributes"),src:t[Pr]}),delete t[Pr]),t[jr]&&(t.set("src",t[jr]),delete t[jr]),t[Lr]&&(t.set("attributes",{...t.get("attributes"),href:t[Lr]}),delete t[Lr])}))}(this.editor),function(t){t.Css.getAll().forEach((t=>{t[Nr]&&(t.getStyle=t[Nr],delete t[Nr])}))}(this.editor)}}const to="fa fa-fw fa-paste silex-button",eo=" disabled",no=[{name:"./project-bar",value:or},{name:"grapesjs-style-bg",value:Wn()},{name:"./settings",value:(t,e)=>{try{pr="3.0.0-alpha.128"}catch(t){}console.info("Silex version:",pr),t.Commands.add(ur,{run:(e,n,{page:r})=>{cr=t.Modal.open({title:r?"Page settings":"Site Settings",content:"",attributes:{class:"settings-dialog"}}).onceClose((()=>{n?.set&&n.set("active",0),t.stopCommand(ur)})),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,Yr.STATUS_NONE)}}var Er;function kr(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"}(Er||(Er={}));const Ar="tmp-pre-publication-transformer-tohtml",Pr="tmp-pre-publication-transformer-src",jr="tmp-pre-publication-transformer-attributes-src",Mr="tmp-pre-publication-transformer-inline-css",Lr="tmp-pre-publication-transformer-href",Nr="tmp-pre-publication-transformer-tocss",Ir={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 Dr(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${$r(t,r,Ae.ASSET,Pe.CSS)})`}:e}function $r(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 Rr(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 Hr=window.location.pathname.replace(/\/$/,""),Fr=window.location.origin;function Vr(t,e,n){if(t.startsWith("/assets")){const r=new URL(t,Fr);return r.pathname=r.pathname.replace(/^\/assets/,""),r.pathname=`${Hr}${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 Ur(t){const e=`${Hr}${on}${vn}${Cn}`;if(t.startsWith(e)){const n=new URL(t,Fr);n.pathname=n.pathname.replace(new RegExp(`^${e}`),""),n.pathname=`${Hr}/assets${n.pathname}`,n.searchParams.delete("websiteId"),n.searchParams.delete("connectorId");const r="/"+n.toString().replace(new RegExp(`^${Fr}${Hr}`),"").replace(/^\//,"");return decodeURIComponent(r)}return console.warn("displayedToStored: path is not a displayed path",t),t}const Br={transformPath(t,e){if(e===Ae.ASSET)return Ur(t)},transformPermalink(t,e){if(e===Ae.ASSET)return Ur(t)}};function zr(t,e,n){const r=t.attributes?.src?{...t,attributes:{...t.attributes,src:Vr(t.attributes.src,e,n)}}:t;return r.components&&(r.components=r.components.map((t=>zr(t,e,n)))),r}function Wr(t){const e=t.attributes?.src?{...t,attributes:{...t.attributes,src:Ur(t.attributes.src)}}:t;return e.components&&(e.components=e.components.map((t=>Wr(t)))),e}const qr="publish",Gr="publish-login",Kr="publish-logout";var Yr;function Zr(t,e){t.PublicationManager=new Qr(t,e)}function Xr(t){switch(t){case Me.IN_PROGRESS:return Yr.STATUS_PENDING;case Me.ERROR:return Yr.STATUS_ERROR;case Me.SUCCESS:return Yr.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"}(Yr||(Yr={}));const Jr=window.location.origin+window.location.pathname.replace(/\/$/,"");class Qr{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Yr.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=Yr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(qr,(()=>this.startPublication())),t.Commands.add(Gr,((t,e,n)=>this.goLogin(n))),t.Commands.add(Kr,(()=>this.goLogout())),this.options.appendTo?this.dialog=new Tr(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=Yr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Yr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${Jr}${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=Yr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError(r.message,this.job,this.status)):(this.editor.trigger(Er.PUBLISH_LOGIN_END),this.settings.connector=t,this.settings.options=r.options,this.status=Yr.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=Yr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Yr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Yr.STATUS_PENDING,this.job=null,this.dialog&&this.dialog.displayPending(this.job,this.status),this.editor.trigger(Er.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=Rr(this.editor,t.src,Ae.ASSET),n=Ur(t.src).replace(/^\/assets\//,"");return{...t,path:e,src:n,type:Ae.ASSET}}))),s={...r,assets:r.assets.map((t=>({...t,src:Ur(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(Er.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=Xr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Yr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Yr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status)),this.editor.trigger(Er.PUBLISH_ERROR,{success:!1,message:t.message}),void this.editor.trigger(Er.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=wr(e.get("name")),s=`/css/${i}.css`,a=`/${i}.html`,l=$r(this.editor,s,Ae.CSS,Pe.HTML),c=Rr(this.editor,s,Ae.CSS),u=Rr(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=Xr(this.job.status)}catch(t){return this.status=Yr.STATUS_ERROR,this.dialog&&this.dialog.displayError(`An error occured, your site is not published. ${t.message}`,this.job,this.status),this.editor.trigger(Er.PUBLISH_END,{success:!1,message:t.message}),void this.editor.trigger(Er.PUBLISH_ERROR,{success:!1,message:t.message})}this.job.status===Me.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(Er.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");kr(t,(n=>{if(n.get(Ar))console.warn("Publication transformer: HTML transform already altered",n);else{const r=n.toHTML.bind(n);n[Ar]=n.toHTML;const o=n.getStyle.bind(n);n[Mr]=n.getStyle;const i=n.get("attributes").href;if(i?.startsWith("./")&&(n[Lr]=i,n.set("attributes",{...n.get("attributes"),href:$r(t,i,Ae.HTML,Pe.HTML)})),n.get("attributes").src){n[Pr]=n.get("attributes").src;const e=$r(t,n.get("attributes").src,Ae.ASSET,Pe.HTML);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[jr]=n.get("src");const e=$r(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=()=>Dr(t,o())}}))}(this.editor),function(t){const e=t.getModel().get("config");t.Css.getAll().forEach((n=>{if(n[Nr])console.warn("Publication transformer: CSS transform already altered",n);else{const r=n.getStyle.bind(n);n[Nr]=n.getStyle,n.getStyle=()=>{try{const n=Dr(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){kr(t,(t=>{t[Ar]&&(t.toHTML=t[Ar],delete t[Ar]),t[Mr]&&(t.getStyle=t[Mr],delete t[Mr]),t[Pr]&&(t.set("attributes",{...t.get("attributes"),src:t[Pr]}),delete t[Pr]),t[jr]&&(t.set("src",t[jr]),delete t[jr]),t[Lr]&&(t.set("attributes",{...t.get("attributes"),href:t[Lr]}),delete t[Lr])}))}(this.editor),function(t){t.Css.getAll().forEach((t=>{t[Nr]&&(t.getStyle=t[Nr],delete t[Nr])}))}(this.editor)}}const to="fa fa-fw fa-paste silex-button",eo=" disabled",no=[{name:"./project-bar",value:or},{name:"grapesjs-style-bg",value:Wn()},{name:"./settings",value:(t,e)=>{try{pr="3.0.0-alpha.129"}catch(t){}console.info("Silex version:",pr),t.Commands.add(ur,{run:(e,n,{page:r})=>{cr=t.Modal.open({title:r?"Page settings":"Site Settings",content:"",attributes:{class:"settings-dialog"}}).onceClose((()=>{n?.set&&n.set("active",0),t.stopCommand(ur)})),function(t,e,n=t.getModel()){const r=n.get("settings")||{};n.set("settings",r),Gt(At`
305
305
  <form class="silex-form">
306
306
  <div class="silex-help">
307
307
  ${fr(n)?At`
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.128",
4
+ "version": "3.0.0-alpha.129",
5
5
  "version:backwardcompat": "3.0.0",
6
6
  "author": {
7
7
  "name": "Alex Hoyau",
@@ -30,9 +30,13 @@
30
30
  }
31
31
 
32
32
  .silex-hidden {
33
+ /* do not really hide, because it breaks the code editor init in the site settings + for animation */
33
34
  visibility: hidden;
34
35
  position: absolute;
35
36
  opacity: 0;
37
+ height: 10px;
38
+ width: 10px;
39
+ overflow: hidden;
36
40
  }
37
41
 
38
42
  // full screen settings