@silexlabs/silex 3.0.0-alpha.112 → 3.0.0-alpha.113

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.
@@ -228,7 +228,7 @@ var silex;(()=>{var t={99:function(t){"undefined"!=typeof globalThis?globalThis:
228
228
  @click=${()=>this.editor.Commands.stop(xr)}
229
229
  >Close</button>
230
230
  </footer>
231
- `}}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,Hr.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";function Lr(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${Nr(t,r,$.ASSET)})`}:e}function Nr(t,e,n){return t.getModel().get("config").publicationTransformers.reduce(((t,e)=>{try{return e.transformPermalink?e.transformPermalink(t,n)??t:t}catch(e){return console.error("Publication transformer: error transforming path",t,e),t}}),e)}function Ir(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 Dr="publish",$r="publish-login",Rr="publish-logout";var Hr;function Fr(t,e){t.PublicationManager=new Br(t,e)}function Vr(t){switch(t){case H.IN_PROGRESS:return Hr.STATUS_PENDING;case H.ERROR:return Hr.STATUS_ERROR;case H.SUCCESS:return Hr.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"}(Hr||(Hr={}));const Ur=window.location.origin+window.location.pathname.replace(/\/$/,"");class Br{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Hr.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??{},gn({type:R.HOSTING,connectorId:this.settings.connector?.connectorId}).then((t=>{})).catch((t=>{this.status=Hr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(Dr,(()=>this.startPublication())),t.Commands.add($r,((t,e,n)=>this.goLogin(n))),t.Commands.add(Rr,(()=>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=Hr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Hr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${Ur}${f}${h}${y}?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=Hr.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=Hr.STATUS_NONE,this.editor.store(null),this.dialog&&this.dialog.displayPending(this.job,this.status)))};window.addEventListener("message",n,!1)}))}async goLogout(){try{await vn({type:R.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=Hr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Hr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Hr.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:$.HTML},{path:t.cssPath,content:t.css,type:$.CSS}])).concat(r.assets.map((t=>{const e=Ir(this.editor,t.src,$.ASSET),n=Nr(this.editor,t.src,$.ASSET);return{...t,path:e,src:n,type:$.ASSET}}))),a={...r,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 mn({websiteId:e,hostingId:this.settings.connector.connectorId,storageId:n,data:a,options:this.settings.options});this.job=r,this.status=Vr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Hr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Hr.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=Nr(this.editor,a,$.CSS),c=Ir(this.editor,a,$.CSS),u=Ir(this.editor,s,$.HTML),p=this.editor.getHtml({component:o});return{html:`<!DOCTYPE html>\n<html lang="${r("lang")}">\n<head>\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 yn({jobId:this.job.jobId}),this.status=Vr(this.job.status)}catch(t){return this.status=Hr.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===H.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(Or.PUBLISH_END,{success:this.job.status===H.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:Nr(t,i,$.HTML)})),n.get("attributes").src){n[kr]=n.get("attributes").src;const e=Nr(t,n.get("attributes").src,$.ASSET);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[Ar]=n.get("src");const e=Nr(t,n.get("src"),$.ASSET);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=()=>Lr(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=e.publicationTransformers.reduce(((t,e)=>({...e.renderCssRule?e.renderCssRule(t,r)??t:t})),Lr(t,r()));return n}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 zr=[{name:"./project-bar",value:ar},{name:"grapesjs-style-bg",value:Kn()},{name:"./settings",value:(t,e)=>{try{pr="3.0.0-alpha.112"}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),je(de`
231
+ `}}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,Hr.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";function Lr(t,e){const n=e["background-image"],r=n?.match(/url\(["']?(.*?)["']?\)/)?.pop();return r?{...e,"background-image":`url(${Nr(t,r,$.ASSET)})`}:e}function Nr(t,e,n){return t.getModel().get("config").publicationTransformers.reduce(((t,e)=>{try{return e.transformPermalink?e.transformPermalink(t,n)??t:t}catch(e){return console.error("Publication transformer: error transforming path",t,e),t}}),e)}function Ir(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 Dr="publish",$r="publish-login",Rr="publish-logout";var Hr;function Fr(t,e){t.PublicationManager=new Br(t,e)}function Vr(t){switch(t){case H.IN_PROGRESS:return Hr.STATUS_PENDING;case H.ERROR:return Hr.STATUS_ERROR;case H.SUCCESS:return Hr.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"}(Hr||(Hr={}));const Ur=window.location.origin+window.location.pathname.replace(/\/$/,"");class Br{editor;dialog;_settings;get settings(){return this._settings}set settings(t){this._settings=t,this.dialog&&(this.dialog.settings=t)}options;job=null;status=Hr.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??{},gn({type:R.HOSTING,connectorId:this.settings.connector?.connectorId}).then((t=>{})).catch((t=>{this.status=Hr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login",this.job,this.status)}))})),t.Commands.add(Dr,(()=>this.startPublication())),t.Commands.add($r,((t,e,n)=>this.goLogin(n))),t.Commands.add(Rr,(()=>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=Hr.STATUS_NONE,this.editor.store(null),void(this.dialog&&this.dialog.displayPending(this.job,this.status));this.settings={},this.status=Hr.STATUS_LOGGED_OUT,this.dialog&&this.dialog.displayPending(this.job,this.status);const e=t.connectorId,n=t.type;return window.open(t.oauthUrl||`${Ur}${f}${h}${y}?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=Hr.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=Hr.STATUS_NONE,this.editor.store(null),this.dialog&&this.dialog.displayPending(this.job,this.status)))};window.addEventListener("message",n,!1)}))}async goLogout(){try{await vn({type:R.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=Hr.STATUS_ERROR,this.dialog&&this.dialog.displayError(t.message,this.job,this.status)}}async startPublication(){if(this.status===Hr.STATUS_PENDING)throw new Error("Publication is already in progress");this.status=Hr.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:$.HTML},{path:t.cssPath,content:t.css,type:$.CSS}])).concat(r.assets.map((t=>{const e=Ir(this.editor,t.src,$.ASSET),n=Nr(this.editor,t.src,$.ASSET);return{...t,path:e,src:n,type:$.ASSET}}))),a={...r,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 mn({websiteId:e,hostingId:this.settings.connector.connectorId,storageId:n,data:a,options:this.settings.options});this.job=r,this.status=Vr(this.job.status),this.trackProgress()}catch(t){return console.error("publish error",t),401===t.code||401===t.httpStatusCode?(this.status=Hr.STATUS_LOGGED_OUT,this.settings={},this.dialog&&this.dialog.displayError("Please login.",this.job,this.status)):(this.status=Hr.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=Nr(this.editor,a,$.CSS),c=Ir(this.editor,a,$.CSS),u=Ir(this.editor,s,$.HTML),p=this.editor.getHtml({component:o});return{html:`<!DOCTYPE html>\n<html lang="${r("lang")}">\n<head>\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 yn({jobId:this.job.jobId}),this.status=Vr(this.job.status)}catch(t){return this.status=Hr.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===H.IN_PROGRESS?setTimeout((()=>this.trackProgress()),2e3):this.editor.trigger(Or.PUBLISH_END,{success:this.job.status===H.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:Nr(t,i,$.HTML)})),n.get("attributes").src){n[kr]=n.get("attributes").src;const e=Nr(t,n.get("attributes").src,$.ASSET);n.set("attributes",{...n.get("attributes"),src:e})}if(n.get("src")){n[Ar]=n.get("src");const e=Nr(t,n.get("src"),$.ASSET);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=()=>Lr(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=e.publicationTransformers.reduce(((t,e)=>({...e.renderCssRule?e.renderCssRule(t,r)??t:t})),Lr(t,r()));return n}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 zr=[{name:"./project-bar",value:ar},{name:"grapesjs-style-bg",value:Kn()},{name:"./settings",value:(t,e)=>{try{pr="3.0.0-alpha.113"}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),je(de`
232
232
  <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>
233
233
  <form class="silex-form">
234
234
  <h2>General settings</h2>
@@ -232,8 +232,7 @@ function default_1(config, opts = {}) {
232
232
  config.emit(events_1.ServerEvent.WEBSITE_ASSET_STORE_START, { files, websiteId, connectorId });
233
233
  const result = await writeAssets(req['session'], websiteId, files, connectorId);
234
234
  const baseUrl = new URL(config.url).pathname.replace(/\/$/, '');
235
- const data = result.map(path => '/assets/'
236
- + path.replace(/^\//, '')
235
+ const data = result.map(path => (0, path_1.join)(baseUrl, constants_1.API_PATH, constants_1.API_WEBSITE_PATH, constants_1.API_WEBSITE_ASSET_READ, path)
237
236
  + `?websiteId=${websiteId}&connectorId=${connectorId ? connectorId : ''}`);
238
237
  res.json({
239
238
  data,
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.112",
4
+ "version": "3.0.0-alpha.113",
5
5
  "version:backwardcompat": "3.0.0",
6
6
  "author": {
7
7
  "name": "Alex Hoyau",
@@ -24,7 +24,7 @@ import { ApiError, ApiWebsiteAssetsReadParams, ApiWebsiteAssetsReadQuery, ApiWeb
24
24
  import { ConnectorFile, ConnectorFileContent, ConnectorSession, StorageConnector, getConnector } from '../connectors/connectors'
25
25
  import { Readable } from 'stream'
26
26
  import { requiredParam } from '../utils/validation'
27
- import { basename } from 'path'
27
+ import { basename, join } from 'path'
28
28
  import { ServerConfig } from '../config'
29
29
  import { ServerEvent, WebsiteStoreEndEventType, WebsiteStoreStartEventType, WebsiteAssetStoreStartEventType, WebsiteAssetStoreEndEventType } from '../events'
30
30
 
@@ -301,8 +301,12 @@ export default function (config: ServerConfig, opts = {}): Router {
301
301
  // Return the file URLs to insert in the website
302
302
  // As expected by grapesjs (https://grapesjs.com/docs/modules/Assets.html#uploading-assets)
303
303
  const data = result.map(path =>
304
- '/assets/'
305
- + path.replace(/^\//, '') // Remove the leading slash
304
+ join(
305
+ // We should return path without this line, as it is saved, not as it is displayed
306
+ // But this url is sent straight to grapesjs, so we need to return the url as it is displayed
307
+ baseUrl, API_PATH, API_WEBSITE_PATH, API_WEBSITE_ASSET_READ,
308
+ path,
309
+ )
306
310
  + `?websiteId=${websiteId}&connectorId=${connectorId ? connectorId : ''}` // As expected by wesite API (readAsset)
307
311
  )
308
312