refactor pagebuilder asset bundling

Migrate pagebuilder and core dist assets from legacy bundled format to modern Vite/Rolldown output.

- Delete legacy pagebuilder app.css and app.js bundles in favor of per-module dist files.
- Update page-injection.js to use template literals and add source map reference.
- Refresh core dist files (PageBuilderBody, PageBuilderHead, WebsiteManager) with updated CSS/JS and remove UMD bundles.
- Replace jQuery-dependent GrapesJS scripts with vanilla JS implementations.
- Remove CKEditor hyperlinks module and replace with RTE link manager.
- Delete external library bundles (Bootstrap, Popper, Toastr, Underscore, CKEditor) from dist.
This commit is contained in:
2026-11-23 17:21:14 +01:00
parent 84545fc4a3
commit d0307d64e9
40 changed files with 1027 additions and 1989 deletions
+11
View File
@@ -43,6 +43,17 @@ function cleanObsoleteArtifacts() {
path.join(DIST_PB_DIR, 'app.css.map'),
path.join(DIST_PB_DIR, 'app.js'),
path.join(DIST_PB_DIR, 'app.js.map'),
path.join(DIST_PB_DIR, 'ckeditor-full-all-v4.14.0.min.js'),
path.join(DIST_PB_DIR, 'grapesjs-plugin-ckeditor-v0.0.10.min.js'),
path.join(DIST_PB_DIR, 'bootstrap-select-v1.13.12.min.css'),
path.join(DIST_PB_DIR, 'bootstrap-select-v1.13.12.min.js'),
path.join(DIST_PB_DIR, 'bootstrap-v4.3.1.min.css'),
path.join(DIST_PB_DIR, 'bootstrap-v4.3.1.min.js'),
path.join(DIST_PB_DIR, 'jquery-3.4.1.min.js'),
path.join(DIST_PB_DIR, 'popper-v1.12.9.min.js'),
path.join(DIST_PB_DIR, 'toastr-v2.1.3.min.css'),
path.join(DIST_PB_DIR, 'toastr-v2.1.3.min.js'),
path.join(DIST_PB_DIR, 'underscore-v1.9.1.min.js'),
];
for (const file of obsoleteFiles) {
+43 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
{"version":3,"sourceRoot":"","sources":["file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/pagebuilder.scss","file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/fields.scss","file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/style-manager.scss","file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/asset-manager.scss","file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/ckeditor.scss","file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/mobile-mode.scss"],"names":[],"mappings":"AAMA,eACE,uBACA,SACA,gBAGF,EACE,mCACA,gCACA,2BAGF,kCACE,cAGF,gBACE,eAGF,YACE,gBAGF,OACE,qBACA,YACA,WACA,gBAEA,qBACE,mBAIJ,cACE,kBACA,YACA,WACA,sBACA,cACA,sCAEA,qBACE,kBACA,UAGF,sBACE,kBACA,QACA,SACA,gCACA,YACA,aAEA,4BACE,eACA,eACA,gBACA,kBACA,cAGJ,sBACE,uBACA,wBACA,yBACA,6BACA,kBACA,oCAEF,kBACE,+BAIJ,sBACE,gBAGF,eACE,YACA,MACA,yBAEF,aACE,uBAGF,cACE,UAEA,8BACE,uBAGJ,mDAGE,aAEF,eACE,UAEF,YACE,yBACA,mBACA,cAEF,eACE,cAEF,gBACE,cAEF,wBACE,cAEF,iBACE,WACA,wBACA,qBACA,gBAEF,oBACE,UACA,WAEF,0BACE,8BAEF,0BACE,oCACA,kBAEA,gCACE,oCAMJ,cACE,SAEA,0BACE,aACA,eACA,4BACA,wBACA,qBACA,gBACA,mBACA,cACA,gCACA,eAEA,wCACE,aACA,yBACA,gCACA,iCACA,wBACA,qBACA,gBACA,WACA,gCAIN,gBACE,QAEF,sCAEE,OACA,wBACA,qBACA,gBACA,MA1Lc,MA2Ld,iBACA,gBACA,cACA,eACA,eACA,gBAEF,wBACE,iBACA,mBACA,yBACA,gBAEA,0CACE,gBAGF,4BACE,YACA,gBAGF,gCACE,mBACA,YAGJ,iCAEE,KAxNc,MA2Nd,4BACE,2BAEF,6BACE,4BAEF,8BACE,4BAOJ,cACE,yBAGA,6DAEE,WAGJ,WACE,yBACA,gBACA,YAEA,uDAGE,YAGF,0BACE,6BAOJ,gBACE,kBACA,gBACA,MAxQc,MAyQd,iBACA,gBACA,cACA,eACA,eACA,gBACA,mBACA,YACA,YAEA,mCACE,YAEA,kHAEE,8BAEF,uDACE,UAEF,oDACE,eACA,sBACA,2BACA,YACA,gBACA,wBAEF,8CACE,wBACA,wBACA,4BACA,kBACA,qBACA,mBACA,YACA,gBAIN,gBACE,kBACA,OACA,MACA,YACA,cACA,mBACA,gBACA,0BAMF,cACE,eACA,mBACA,qBACA,gBACA,YACA,iBAEA,0BACE,kBACA,SACA,SACA,eACA,cAGF,oBACE,mBACA,4BACA,gBACA,YAEA,iCACE,cAKN,WACE,YACA,gBACA,mBACA,WACA,uBAEA,cACE,YAGF,iBACE,yBAGF,wBACE,YACA,gBACA,kBACA,WAEA,4BACE,WAIN,cACE,mBACA,YAEF,sBACE,mBACA,oBAEF,iBACE,gBACA,YACA,aAEA,mBACE,iBACA,gBAGJ,oBACE,mBAEF,6BACE,8BACA,mBAEF,eACE,8BAMF,4BACE,8BAEF,yCACE,oCAEF,wCACE,wDAEF,6HAKE,8BACA,2CACA,iBACA,eACA,mBAEF,sHAGE,8BAEF,gBACE,gBACA,oBAEF,iBACE,aAEF,eACE,iBAMF,2BACE,uCAMF,eACE,cAEF,gBACE,mBAEF,oDAEE,WAEF,oBACE,uBACA,sBAEF,kBACE,mBACA,eACA,mBAEF,yDAEE,kBAEF,+BACE,WAEF,8BACE,iBACA,oBAEF,kCACE,gBAEF,iCACE,mBAEF,eACE,oBAEF,gCACE,gBACA,UAEA,0DACE,kBAEA,gFACE,kBACA,QACA,MACA,gBACA,yBACA,qBACA,cACA,gBAGF,8DACE,eACA,iBAQN,wBACE,kBACA,OACA,SACA,OAzgB8B,KA0gB9B,MA3gBc,MA4gBd,SACA,UACA,wBACA,qBACA,gBACA,mBACA,gBAEA,yDAEE,YACA,YACA,aACA,8BACA,gBACA,cACA,eACA,cAEA,qEACE,mBACA,WAEF,+EACE,iBAIJ,uCACE,mBACA,sBAEA,4CACE,aAIJ,uCACE,mBAEF,yCACE,mBCrjBJ,WACE,yBAGA,yBACE,sBACA,WAGJ,gBACE,cAEF,kBACE,cAEF,oCACE,cAEA,2CACE,yBACA,WAGJ,mBACE,6BAEF,mBACE,gCAGF,iBACE,qBAEF,sCACE,iBACA,gBACA,oBACA,WAEF,oDACE,yBCxCF,+BACE,mBACA,cAGF,cACE,WACA,cACA,iBAEA,gEAEE,aAEF,2BACE,cAEF,+BACE,yBACA,YACA,gDACA,WAEA,qCACE,yBAMJ,gEAEE,cAGF,+CACE,uCACA,uCAGF,+BACE,yBAEA,2CACE,gBACA,WACA,iBAGF,0CACE,UACA,yBAEA,iDACE,WACA,mBAKN,0CACE,WAEA,gDACE,WChEN,sBACE,aAEF,oBACE,gBACA,cAEF,eACE,aAEF,cACE,2BACA,yBACA,sBACA,qBACA,iBAGF,cACE,qBACA,gBACA,uBACA,gBACA,kBACA,sBACA,yBACA,sBACA,qBACA,iBACA,eACA,gBACA,qBACA,8HACA,WACA,yBACA,yBAIA,yBACE,WACA,WAEF,oCACE,WAKF,2BACE,uCACA,0BAEF,oCACE,cACA,iBCtDF,2CACE,UAEF,0PAKE,mBAGF,6CACE,sBCZF,kCACE,uBAGF,kCACE,aAEF,uEACE,OAGF,mCACE,kBACA,eACA,qDACA,kDACA,2CACA"}
{"version":3,"sourceRoot":"","sources":["file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/pagebuilder.scss","file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/fields.scss","file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/style-manager.scss","file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/asset-manager.scss","file:///Users/paulspenke/Repositories/Plugi/plugi/plugi-core/src/Modules/GrapesJS/resources/assets/sass/mobile-mode.scss"],"names":[],"mappings":"AAMA,eACE,uBACA,SACA,gBAGF,EACE,mCACA,gCACA,2BAGF,kCACE,cAGF,gBACE,eAGF,YACE,gBAGF,OACE,qBACA,YACA,WACA,gBAEA,qBACE,mBAIJ,cACE,kBACA,YACA,WACA,sBACA,cACA,sCAEA,qBACE,kBACA,UAGF,sBACE,kBACA,QACA,SACA,gCACA,YACA,aAEA,4BACE,eACA,eACA,gBACA,kBACA,cAGJ,sBACE,uBACA,wBACA,yBACA,6BACA,kBACA,oCAEF,kBACE,+BAIJ,sBACE,gBAGF,eACE,YACA,MACA,yBAEF,aACE,uBAGF,cACE,UAEA,8BACE,uBAGJ,mDAGE,aAEF,eACE,UAEF,YACE,yBACA,mBACA,cAEF,eACE,cAEF,gBACE,cAEF,wBACE,cAEF,iBACE,WACA,wBACA,qBACA,gBAEF,oBACE,UACA,WAEF,0BACE,8BAEF,0BACE,oCACA,kBAEA,gCACE,oCAMJ,cACE,SAEA,0BACE,aACA,eACA,4BACA,wBACA,qBACA,gBACA,mBACA,cACA,gCACA,eAEA,wCACE,aACA,yBACA,gCACA,iCACA,wBACA,qBACA,gBACA,WACA,gCAIN,gBACE,QAEF,sCAEE,OACA,wBACA,qBACA,gBACA,MA1Lc,MA2Ld,iBACA,gBACA,cACA,eACA,eACA,gBAEF,wBACE,iBACA,mBACA,yBACA,gBAEA,0CACE,gBAGF,4BACE,YACA,gBAGF,gCACE,mBACA,YAGJ,iCAEE,KAxNc,MA2Nd,4BACE,2BAEF,6BACE,4BAEF,8BACE,4BAOJ,cACE,yBAGA,6DAEE,WAGJ,WACE,yBACA,gBACA,YAEA,uDAGE,YAGF,0BACE,6BAOJ,gBACE,kBACA,gBACA,MAxQc,MAyQd,eACA,mBACA,YACA,YACA,aACA,mBAEA,mCACE,iBAEA,0CACE,mBACA,cACA,yBACA,kBACA,gBACA,eACA,aACA,eAEA,gDACE,qBAKR,gBACE,kBACA,OACA,MACA,YACA,cACA,mBACA,gBACA,YACA,eACA,YACA,WACA,aACA,mBACA,uBAMF,cACE,eACA,mBACA,qBACA,gBACA,YACA,iBAEA,0BACE,kBACA,SACA,SACA,eACA,cAGF,oBACE,mBACA,4BACA,gBACA,YAEA,iCACE,cAKN,WACE,YACA,gBACA,mBACA,WACA,uBAEA,cACE,YAGF,iBACE,yBAGF,wBACE,YACA,gBACA,kBACA,WAEA,4BACE,WAIN,cACE,mBACA,YAEF,sBACE,mBACA,oBAEF,iBACE,gBACA,YACA,aAEA,mBACE,iBACA,gBAGJ,oBACE,mBAEF,6BACE,8BACA,mBAEF,eACE,8BAMF,4BACE,8BAEF,yCACE,oCAEF,wCACE,wDAEF,6HAKE,8BACA,2CACA,iBACA,eACA,mBAEF,sHAGE,8BAEF,gBACE,gBACA,oBAEF,iBACE,aAEF,eACE,iBAMF,2BACE,uCAMF,eACE,cAEF,gBACE,mBAEF,oDAEE,WAEF,oBACE,uBACA,sBAEF,kBACE,mBACA,eACA,mBAEF,yDAEE,kBAEF,+BACE,WAEF,8BACE,iBACA,oBAEF,kCACE,gBAEF,iCACE,mBAEF,eACE,oBAEF,gCACE,gBACA,UAEA,0DACE,kBAEA,gFACE,kBACA,QACA,MACA,gBACA,yBACA,qBACA,cACA,gBAGF,8DACE,eACA,iBAQN,wBACE,kBACA,OACA,SACA,OAjgB8B,KAkgB9B,MAngBc,MAogBd,SACA,UACA,mBACA,gBACA,aAEA,yDAEE,OACA,oBACA,mBACA,uBACA,YACA,8BACA,gBACA,cACA,eACA,cACA,qBACA,YACA,8BAEA,qEACE,mBACA,WAEF,iFACE,iBAIJ,uCACE,mBACA,sBAEA,iDACE,aAIJ,uCACE,mBAEF,yCACE,mBChjBJ,WACE,yBAGA,yBACE,sBACA,WAGJ,gBACE,cAEF,kBACE,cAEF,oCACE,cAEA,2CACE,yBACA,WAGJ,mBACE,6BAEF,mBACE,gCAGF,iBACE,qBAEF,sCACE,iBACA,gBACA,oBACA,WAEF,oDACE,yBCxCF,+BACE,mBACA,cAGF,cACE,WACA,cACA,iBAEA,gEAEE,aAEF,2BACE,cAEF,+BACE,yBACA,YACA,gDACA,WAEA,qCACE,yBAMJ,gEAEE,cAGF,+CACE,uCACA,uCAGF,+BACE,yBAEA,2CACE,gBACA,WACA,iBAGF,0CACE,UACA,yBAEA,iDACE,WACA,mBAKN,0CACE,WAEA,gDACE,WChEN,sBACE,aAEF,oBACE,gBACA,cAEF,eACE,aAEF,cACE,2BACA,yBACA,sBACA,qBACA,iBAGF,cACE,qBACA,gBACA,uBACA,gBACA,kBACA,sBACA,yBACA,sBACA,qBACA,iBACA,eACA,gBACA,qBACA,8HACA,WACA,yBACA,yBAIA,yBACE,WACA,WAEF,oCACE,WAKF,2BACE,uCACA,0BAEF,oCACE,cACA,iBHigBJ,qBACE,cACA,eAEA,gCACE,yBACA,yBACA,WACA,iBACA,kBACA,aACA,eAEA,sCACE,qBAIJ,sCACE,gBACA,wRACA,4BACA,sCACA,qBACA,mBAGF,0BACE,iBACA,kBACA,eACA,eACA,YACA,6CIxlBF,kCACE,uBAGF,kCACE,aAEF,uEACE,OAGF,mCACE,kBACA,eACA,qDACA,kDACA,2CACA"}
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
@@ -1,2 +0,0 @@
/*! grapesjs-plugin-ckeditor - 0.0.10 */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("grapesjs")):"function"==typeof define&&define.amd?define(["grapesjs"],t):"object"==typeof exports?exports["grapesjs-plugin-ckeditor"]=t(require("grapesjs")):e["grapesjs-plugin-ckeditor"]=t(e.grapesjs)}("undefined"!=typeof self?self:this,function(e){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),r=function(e){return e&&e.__esModule?e:{default:e}}(o),a=function(e){return e.stopPropagation()};t.default=r.default.plugins.add("gjs-plugin-ckeditor",function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t,o={options:{},position:"left"};for(var i in o)i in n||(n[i]=o[i]);if(!CKEDITOR)throw new Error("CKEDITOR instance not found");e.setCustomRte({enable:function(t,o){if(o&&"destroyed"!=o.status)return this.focus(t,o),o;t.contentEditable=!0;var i=e.RichTextEditor.getToolbarEl();[].forEach.call(i.children,function(e){e.style.display="none"});var s=n.options;return s.extraPlugins?"string"==typeof s.extraPlugins?s.extraPlugins+=",sharedspace":s.extraPlugins.push("sharedspace"):s.extraPlugins="sharedspace",n.options.sharedSpaces||(n.options.sharedSpaces={top:i}),o=CKEDITOR.inline(t,n.options),o.getContent=o.getData,o.on("contentDom",function(){var e=o.editable();e.attachListener(e,"click",function(){t.click()})}),o.on("instanceReady",function(t){var n=i.querySelector("#cke_"+o.name);n&&(n.style.display="block"),e.trigger("canvasScroll")}),o.on("dialogShow",function(e){var t=r.default.$(".cke_dialog_background_cover, .cke_dialog");["off","on"].forEach(function(e){return t[e]("mousedown",a)})}),this.focus(t,o),o},disable:function(e,t){e.contentEditable=!1,t&&t.focusManager&&t.focusManager.blur(!0)},focus:function(e,t){t&&t.focusManager.hasFocus||(e.contentEditable=!0,t&&t.focus())}}),e.on("rteToolbarPosUpdate",function(e){switch(n.position){case"center":var t=e.elementWidth/2-e.targetWidth/2;e.left=e.elementLeft+t;break;case"right":var o=e.targetWidth;e.left=e.elementLeft+e.elementWidth-o}e.top<=e.canvasTop&&(e.top=e.elementTop+e.elementHeight),e.left<e.canvasLeft&&(e.left=e.canvasLeft)})})},function(t,n){t.exports=e}])});
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+47 -31
View File
@@ -7,7 +7,7 @@
"name": "plugi-core",
"dependencies": {
"alpinejs": "^3.12.2",
"grapesjs": "^0.21.2",
"grapesjs": "0.22.16",
"slugify": "^1.6.6"
},
"devDependencies": {
@@ -1218,9 +1218,10 @@
}
},
"node_modules/codemirror": {
"version": "5.65.13",
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.65.13.tgz",
"integrity": "sha512-SVWEzKXmbHmTQQWaz03Shrh4nybG0wXx2MEu3FO4ezbPW8IbnZEd5iGHGEffSUaitKYa3i+pHpBsSvw8sPHtzg=="
"version": "5.63.0",
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.63.0.tgz",
"integrity": "sha512-KlLWRPggDg2rBD1Mx7/EqEhaBdy+ybBCVh/efgjBDsPpMeEu6MbTAJzIT4TuCzvmbTEgvKOGzVT6wdBTNusqrg==",
"license": "MIT"
},
"node_modules/codemirror-formatting": {
"version": "1.0.0",
@@ -1322,17 +1323,19 @@
"license": "BlueOak-1.0.0"
},
"node_modules/grapesjs": {
"version": "0.21.2",
"resolved": "https://registry.npmjs.org/grapesjs/-/grapesjs-0.21.2.tgz",
"integrity": "sha512-SolzlBU8kvZEVgqLC+aoW+qQSRwP/PRnTSpzLnWzuHTf6APbnVBRYdJzExXSt8fG//Ynxp6ClUkshebqxSuTgQ==",
"version": "0.22.16",
"resolved": "https://registry.npmjs.org/grapesjs/-/grapesjs-0.22.16.tgz",
"integrity": "sha512-kCfphgpC7pqJPuMYmIhMR6ueyB3+V67isdpMZOvmuGeWDMomkgzqRWOMH3matfdqIJW7LUivHZo9GeyVQAGmLw==",
"license": "BSD-3-Clause",
"dependencies": {
"@types/backbone": "^1.4.15",
"@types/backbone": "1.4.15",
"backbone": "1.4.1",
"backbone-undo": "^0.2.5",
"codemirror": "^5.63.0",
"codemirror-formatting": "^1.0.0",
"promise-polyfill": "^8.1.3",
"underscore": "^1.13.1"
"backbone-undo": "0.2.6",
"codemirror": "5.63.0",
"codemirror-formatting": "1.0.0",
"html-entities": "~1.4.0",
"promise-polyfill": "8.3.0",
"underscore": "1.13.8"
}
},
"node_modules/has-flag": {
@@ -1344,6 +1347,12 @@
"node": ">=4"
}
},
"node_modules/html-entities": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/html-entities/-/html-entities-1.4.0.tgz",
"integrity": "sha512-8nxjcBcd8wovbeKx7h3wTji4e6+rhaVuPNpMqwWgnHh+N9ToqsCs6XztWRBPQ+UtzsoMAdKZtUENoVzU/EMtZA==",
"license": "MIT"
},
"node_modules/ignore-by-default": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
@@ -2051,9 +2060,10 @@
"dev": true
},
"node_modules/underscore": {
"version": "1.13.6",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz",
"integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A=="
"version": "1.13.8",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.8.tgz",
"integrity": "sha512-DXtD3ZtEQzc7M8m4cXotyHR+FAS18C64asBYY5vqZexfYryNNnDc02W4hKg3rdQuqOYas1jkseX0+nZXjTXnvQ==",
"license": "MIT"
},
"node_modules/util-deprecate": {
"version": "1.0.2",
@@ -2726,9 +2736,9 @@
}
},
"codemirror": {
"version": "5.65.13",
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.65.13.tgz",
"integrity": "sha512-SVWEzKXmbHmTQQWaz03Shrh4nybG0wXx2MEu3FO4ezbPW8IbnZEd5iGHGEffSUaitKYa3i+pHpBsSvw8sPHtzg=="
"version": "5.63.0",
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.63.0.tgz",
"integrity": "sha512-KlLWRPggDg2rBD1Mx7/EqEhaBdy+ybBCVh/efgjBDsPpMeEu6MbTAJzIT4TuCzvmbTEgvKOGzVT6wdBTNusqrg=="
},
"codemirror-formatting": {
"version": "1.0.0",
@@ -2804,17 +2814,18 @@
"dev": true
},
"grapesjs": {
"version": "0.21.2",
"resolved": "https://registry.npmjs.org/grapesjs/-/grapesjs-0.21.2.tgz",
"integrity": "sha512-SolzlBU8kvZEVgqLC+aoW+qQSRwP/PRnTSpzLnWzuHTf6APbnVBRYdJzExXSt8fG//Ynxp6ClUkshebqxSuTgQ==",
"version": "0.22.16",
"resolved": "https://registry.npmjs.org/grapesjs/-/grapesjs-0.22.16.tgz",
"integrity": "sha512-kCfphgpC7pqJPuMYmIhMR6ueyB3+V67isdpMZOvmuGeWDMomkgzqRWOMH3matfdqIJW7LUivHZo9GeyVQAGmLw==",
"requires": {
"@types/backbone": "^1.4.15",
"@types/backbone": "1.4.15",
"backbone": "1.4.1",
"backbone-undo": "^0.2.5",
"codemirror": "^5.63.0",
"codemirror-formatting": "^1.0.0",
"promise-polyfill": "^8.1.3",
"underscore": "^1.13.1"
"backbone-undo": "0.2.6",
"codemirror": "5.63.0",
"codemirror-formatting": "1.0.0",
"html-entities": "~1.4.0",
"promise-polyfill": "8.3.0",
"underscore": "1.13.8"
}
},
"has-flag": {
@@ -2823,6 +2834,11 @@
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true
},
"html-entities": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/html-entities/-/html-entities-1.4.0.tgz",
"integrity": "sha512-8nxjcBcd8wovbeKx7h3wTji4e6+rhaVuPNpMqwWgnHh+N9ToqsCs6XztWRBPQ+UtzsoMAdKZtUENoVzU/EMtZA=="
},
"ignore-by-default": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
@@ -3244,9 +3260,9 @@
"dev": true
},
"underscore": {
"version": "1.13.6",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz",
"integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A=="
"version": "1.13.8",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.8.tgz",
"integrity": "sha512-DXtD3ZtEQzc7M8m4cXotyHR+FAS18C64asBYY5vqZexfYryNNnDc02W4hKg3rdQuqOYas1jkseX0+nZXjTXnvQ=="
},
"util-deprecate": {
"version": "1.0.2",
+1 -1
View File
@@ -16,7 +16,7 @@
},
"dependencies": {
"alpinejs": "^3.12.2",
"grapesjs": "^0.21.2",
"grapesjs": "0.22.16",
"slugify": "^1.6.6"
}
}
@@ -1,7 +1,8 @@
import './toast';
import './pagebuilder';
import './block-search';
import './run-builder-scripts';
import './manage-editable-components';
import './save-page';
import './ckeditor-hyperlinks';
import './rte-link-manager';
import './responsive';
@@ -1,34 +1,42 @@
$(document).on("input", "#block-search input", function() {
let term = $(this).val().toLowerCase();
document.addEventListener("input", function(e) {
const input = e.target.closest("#block-search input");
if (!input) return;
$(".gjs-block-category").each(function() {
let term = input.value.toLowerCase().trim();
document.querySelectorAll(".gjs-block-category").forEach(category => {
let atLeastOneMatch = false;
$(this).find(".gjs-block").each(function() {
if (! $(this).data('original-html')) {
$(this).data('original-html', $(this).html());
category.querySelectorAll(".gjs-block").forEach(block => {
if (!block.dataset.originalHtml) {
block.dataset.originalHtml = block.innerHTML;
}
let label = $(this).text();
if (label.toLowerCase().includes(term)) {
$(this).removeClass("d-none");
let label = block.textContent || "";
if (!term || label.toLowerCase().includes(term)) {
block.classList.remove("d-none");
atLeastOneMatch = true;
let regEx = new RegExp('(' + term + ')', "gi");
let highlightedText = label.replace(regEx, '<b>$1</b>');
$(this).find(".gjs-block-label").html(
$(this).data('original-html').replace(label.trim(), highlightedText)
);
const labelEl = block.querySelector(".gjs-block-label");
if (labelEl) {
if (term) {
let regEx = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', "gi");
let highlightedText = label.replace(regEx, '<b>$1</b>');
labelEl.innerHTML = block.dataset.originalHtml.replace(label.trim(), highlightedText);
} else {
block.innerHTML = block.dataset.originalHtml;
}
}
} else {
$(this).addClass("d-none");
block.classList.add("d-none");
}
});
$(this).removeClass("d-none");
if (! atLeastOneMatch) {
$(this).addClass("d-none");
if (atLeastOneMatch) {
category.classList.remove("d-none");
} else {
category.classList.add("d-none");
}
});
});
@@ -1,127 +0,0 @@
window.CKEDITOR.on('instanceReady', function (event) {
event.editor.on('paste', function (event) {
let result = event.data.dataValue;
// remove all not allowed tags
result = result.replace(/<(?!\/?(?:a|table|tr|td|th|thead|tbody|tfoot|caption|col|colgroup|p|ul|ol|li|br|strong|em|b|i|u|strike|sub|sup|h1|h2|h3|h4|h5|h6|blockquote|pre|hr)\b)[^>]+>/gm, '');
// remove all attributes of the allowed tags except from anchor
result = result.replace(/<(a|table|tr|td|th|thead|tbody|tfoot|caption|col|colgroup|p|ul|ol|li|br|strong|em|b|i|u|strike|sub|sup|h1|h2|h3|h4|h5|h6|blockquote|pre|hr)\b[^>]*>/gm, function(match, tag) {
// for anchor tags remove all attributes except href
if (tag === 'a') {
let href = match.match(/href="([^"]*)"/);
if (! href) {
return match;
}
return '<a href="' + href[1] + '">';
}
// allow styling on some tags
if ('|table|tr|td|th|thead|tbody|tfoot|'.includes('|' + tag + '|')) {
let style = match.match(/style="([^"]*)"/);
if (! style) {
return match;
}
return '<' + tag + ' style="' + style[1] + '">';
}
return '<' + tag + '>';
});
event.data.dataValue = result;
});
});
window.CKEDITOR.on('dialogDefinition', function(event) {
let dialogName = event.data.name;
let dialogDefinition = event.data.definition;
if (dialogName === 'link') {
let infoTab = dialogDefinition.getContents('info');
dialogDefinition.onLoad = function() {
let dialog = CKEDITOR.dialog.getCurrent();
dialog.getContentElement('info', 'linkType').getElement().hide();
dialog.getContentElement('info', 'protocol').getElement().hide();
dialog.getContentElement('info', 'url').getElement().hide();
};
infoTab.add({
type: 'select',
id: 'linktype-selector',
label: 'Linktype',
'default': '',
items: [
[window.translations['page'], "page"],
["URL", "url"]
],
onChange: function(obj) {
let dialog = CKEDITOR.dialog.getCurrent();
if (obj.data.value === 'page') {
dialog.getContentElement('info', 'page-selector').getElement().show();
dialog.getContentElement('info', 'url-field').getElement().hide();
} else {
dialog.getContentElement('info', 'page-selector').getElement().hide();
dialog.getContentElement('info', 'url-field').getElement().show();
dialog.getContentElement('info', 'url-field').setValue('');
}
},
setup: function(data) {
if (data.type === undefined) {
this.setValue('page');
} else if (data.type === 'url' && data.url.url.startsWith('[page id=')) {
this.setValue('page');
} else {
this.setValue(data.type);
}
}
});
infoTab.add({
type: 'select',
id: 'page-selector',
label: window.translations['page'],
'default': '',
items: window.pages,
onChange: function() {
let dialog = CKEDITOR.dialog.getCurrent();
let page = '[page id=' + this.getValue() + ']';
dialog.setValueOf('info', 'url', page);
dialog.setValueOf('info', 'protocol', '');
},
setup: function(dialog) {
this.allowOnChange = false;
let pageId = '';
if (dialog.url) {
pageId = dialog.url.url.substr(9, dialog.url.url.length - 10);
}
this.setValue(pageId);
this.allowOnChange = true;
}
});
infoTab.add({
type: 'text',
id: 'url-field',
label: 'URL',
'default': '',
onChange: function() {
let dialog = CKEDITOR.dialog.getCurrent();
let url = this.getValue();
dialog.setValueOf('info', 'url', url);
},
setup: function(dialog) {
this.allowOnChange = false;
let url = '';
if (dialog.url) {
url = dialog.url.url;
}
this.setValue(url);
this.allowOnChange = true;
}
});
}
});
@@ -14,7 +14,7 @@
let fullScript = scriptTag.outerHTML + '<script>' + startFirstScript.toString() + startFirstScript.name + '()</script>';
window.initialComponents = window.initialComponents.replace('</body>', fullScript + '</body>');
$.each(window.languages, (languageCode, languageTranslation) => {
Object.keys(window.languages || {}).forEach(languageCode => {
if (window.pageBlocks[languageCode] === null) {
window.pageBlocks[languageCode] = {};
}
@@ -56,14 +56,15 @@
// remove whitespace from phpb-block-container elements, otherwise these components will become type=text,
// resulting in components dropped inside the container jumping to the dropped position - 1
let $blockHtml = $("<container>").append(block.content);
$blockHtml.find("[phpb-blocks-container]").each(function() {
if ($(this).html() !== '' && $(this).html().trim() === '') {
$(this).html('');
let tempDiv = document.createElement("div");
tempDiv.innerHTML = block.content;
tempDiv.querySelectorAll("[phpb-blocks-container]").forEach(cont => {
if (cont.innerHTML !== '' && cont.innerHTML.trim() === '') {
cont.innerHTML = '';
}
});
window.themeBlocks[blockSlug].content = $blockHtml.html();
block.content = $blockHtml.html();
window.themeBlocks[blockSlug].content = tempDiv.innerHTML;
block.content = tempDiv.innerHTML;
editor.BlockManager.add(blockSlug, block);
}
@@ -72,8 +73,10 @@
/**
* Switch pagebuilder to another language variant on changing the language selector.
*/
$("#language-selector select").on("change", function() {
let selectedLanguage = $(this).find("option:selected").val();
document.addEventListener("change", function(e) {
const select = e.target.closest("#language-selector select");
if (!select) return;
let selectedLanguage = select.value;
window.switchLanguage(selectedLanguage, function() {
activateLanguage(selectedLanguage);
@@ -116,7 +119,7 @@
});
};
$(window).on('pagebuilder-page-loaded', function(event) {
window.addEventListener('pagebuilder-page-loaded', function(event) {
window.editor.getWrapper().find("[phpb-content-container]").forEach(container => {
restrictEditAccess(container);
window.runScriptsOfComponentAndChildren(container);
@@ -135,19 +138,28 @@
* @param component
*/
function replacePlaceholdersForRenderedBlocks(component) {
let newComponent = component;
if (!component) return;
// if we encounter a pagebuilder block, replace it with the server-side rendered html
if (component.get('tagName') === 'phpb-block') {
let id = component.attributes.attributes.id;
if (window.pageBlocks[window.currentLanguage][id] !== undefined && window.pageBlocks[window.currentLanguage][id]['html'] !== undefined) {
newComponent = component.replaceWith(window.pageBlocks[window.currentLanguage][id]['html']);
if (component.get && component.get('tagName') === 'phpb-block') {
let id = component.attributes && component.attributes.attributes ? component.attributes.attributes.id : null;
if (id && window.pageBlocks[window.currentLanguage] && window.pageBlocks[window.currentLanguage][id] !== undefined && window.pageBlocks[window.currentLanguage][id]['html'] !== undefined) {
let replaced = component.replaceWith(window.pageBlocks[window.currentLanguage][id]['html']);
window.pageBlocks[window.currentLanguage][id]['html'] = '';
let replacedComponents = Array.isArray(replaced) ? replaced : [replaced];
replacedComponents.forEach(comp => {
if (comp && comp.get && comp.get('components')) {
comp.get('components').each(childComponent => replacePlaceholdersForRenderedBlocks(childComponent));
}
});
return;
}
}
// replace placeholders inside child components
newComponent.get('components').each(childComponent => replacePlaceholdersForRenderedBlocks(childComponent));
if (component.get && component.get('components')) {
component.get('components').each(childComponent => replacePlaceholdersForRenderedBlocks(childComponent));
}
}
/**
@@ -171,37 +183,46 @@
window.editor.on('component:selected', function(component) {
// if the component has settings, activate settings panel in pagebuilder sidebar
if (componentHasBlockSettings(component)) {
$(".gjs-pn-buttons .gjs-pn-btn:nth-of-type(2)").click();
const btn = document.querySelector(".gjs-pn-buttons .gjs-pn-btn:nth-of-type(2)");
if (btn) btn.click();
}
else if (component.get('type') === '' && componentHasBackground(component)) {
// on selecting a default component without settings, with editable background, show background styling
$(".gjs-pn-buttons .gjs-pn-btn:nth-of-type(3)").click();
if ($("#gjs-sm-position").hasClass("gjs-sm-open")) {
$("#gjs-sm-position").find(".gjs-sm-title").click();
const btn = document.querySelector(".gjs-pn-buttons .gjs-pn-btn:nth-of-type(3)");
if (btn) btn.click();
const pos = document.getElementById("gjs-sm-position");
if (pos && pos.classList.contains("gjs-sm-open")) {
const title = pos.querySelector(".gjs-sm-title");
if (title) title.click();
}
if (! $("#gjs-sm-background").hasClass("gjs-sm-open")) {
$("#gjs-sm-background").find(".gjs-sm-title").click();
const bg = document.getElementById("gjs-sm-background");
if (bg && !bg.classList.contains("gjs-sm-open")) {
const title = bg.querySelector(".gjs-sm-title");
if (title) title.click();
}
}
// if component has no settings, add no settings text to settings panel in sidebar
if (! componentHasBlockSettings(component)) {
setTimeout(function() {
$(".gjs-trt-traits").html('<p class="no-settings">' + window.translations['trait-manager']['no-settings'] + '</p>');
const traits = document.querySelector(".gjs-trt-traits");
if (traits) {
traits.innerHTML = '<p class="no-settings">' + window.translations['trait-manager']['no-settings'] + '</p>';
}
}, 0);
}
// only show the toolbar buttons that are applicable
setTimeout(function() {
if (! component.attributes.removable) {
$(".gjs-toolbar .fa-trash-o.gjs-toolbar-item").hide();
}
if (! component.attributes.copyable) {
$(".gjs-toolbar .fa-clone.gjs-toolbar-item").hide();
}
if (! component.attributes.draggable) {
$(".gjs-toolbar .fa-arrows.gjs-toolbar-item").hide();
}
const trash = document.querySelector(".gjs-toolbar .fa-trash-o.gjs-toolbar-item");
if (trash && !component.attributes.removable) trash.style.display = 'none';
const clone = document.querySelector(".gjs-toolbar .fa-clone.gjs-toolbar-item");
if (clone && !component.attributes.copyable) clone.style.display = 'none';
const arrows = document.querySelector(".gjs-toolbar .fa-arrows.gjs-toolbar-item");
if (arrows && !component.attributes.draggable) arrows.style.display = 'none';
if (! component.attributes.removable && ! component.attributes.copyable && ! component.attributes.draggable) {
window.editor.select(component.parent());
}
@@ -211,7 +232,8 @@
let labelHtml = window.themeBlocks[blockSlug]['label'];
let labelTextParts = labelHtml.split("</div>");
if (labelTextParts.length > 1) {
$(".gjs-toolbar").attr('title', "Bloknaam: " + labelTextParts[1]);
const toolbar = document.querySelector(".gjs-toolbar");
if (toolbar) toolbar.setAttribute('title', "Bloknaam: " + labelTextParts[1]);
}
}
}, 0);
@@ -322,7 +344,8 @@
// replace the <phpb-block> by the actual component
// the component is wrapped with a wrapper element to allow block styling (via a unique .style-identifier selector)
let wrapperElement = ('wrapper' in component.attributes.attributes) ? component.attributes.attributes['wrapper'] : 'div';
blockRootComponent = component.replaceWith({tagName: wrapperElement});
let rep = component.replaceWith({tagName: wrapperElement});
blockRootComponent = Array.isArray(rep) ? rep[0] : rep;
blockRootComponent.attributes['is-style-wrapper'] = true;
clone.components().each(function(componentChild) {
blockRootComponent.append(cloneComponent(componentChild));
@@ -336,9 +359,11 @@
// else, replace it by a wrapper div to allow block styling (via a unique .style-identifier selector)
if (clone.components().length === 1) {
let firstChild = cloneComponent(clone.components().models[0]);
blockRootComponent = component.replaceWith(firstChild);
let rep = component.replaceWith(firstChild);
blockRootComponent = Array.isArray(rep) ? rep[0] : rep;
} else {
blockRootComponent = component.replaceWith({tagName: 'div'});
let rep = component.replaceWith({tagName: 'div'});
blockRootComponent = Array.isArray(rep) ? rep[0] : rep;
blockRootComponent.attributes['is-style-wrapper'] = true;
clone.components().each(function(componentChild) {
blockRootComponent.append(cloneComponent(componentChild));
@@ -451,12 +476,16 @@
/**
* On updating an attribute (block setting from the settings side panel), refresh dynamic block via Ajax.
*/
window.editor.on('component:update', function(component) {
window.editor.on('component:update', async function(component) {
const frame = document.querySelector(".gjs-frame");
const frameDoc = frame && (frame.contentDocument || (frame.contentWindow && frame.contentWindow.document));
const frameEl = frameDoc ? frameDoc.getElementById(component.ccid) : null;
if (window.isLoaded !== true ||
component.attributes['block-slug'] === undefined ||
component.attributes['is-updating'] ||
component.changed['attributes'] === undefined ||
$(".gjs-frame").contents().find("#" + component.ccid).length === 0
!frameEl
) {
return;
}
@@ -487,45 +516,61 @@
}
component.attributes['is-updating'] = true;
$(".gjs-frame").contents().find("#" + component.ccid).addClass('gjs-freezed');
if (frameEl) frameEl.classList.add('gjs-freezed');
let container = window.editor.getWrapper().find("#" + component.ccid)[0].parent();
let data = window.getComponentDataInStorageFormat(component);
// refresh component contents with updated version requested via ajax call
$.ajax({
type: "POST",
url: window.renderBlockUrl,
data: {
data: JSON.stringify(data),
language: window.currentLanguage
},
success: function(blockHtml) {
let blockId = $(blockHtml).attr('block-id');
// set the block settings for the updated component to the new values
window.pageBlocks[window.currentLanguage][blockId] = (data.blocks[blockId] === undefined) ? {} : data.blocks[blockId];
// refresh component contents with updated version requested via fetch call
try {
const formData = new URLSearchParams();
formData.append('data', JSON.stringify(data));
formData.append('language', window.currentLanguage);
// replace old component for the rendered html returned by the server
component.replaceWith(blockHtml);
replacePlaceholdersForRenderedBlocks(container);
applyBlockAttributesToComponents(container);
restrictEditAccess(container, false, false);
const response = await fetch(window.renderBlockUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
},
body: formData
});
// run builder scripts of the replaced component and all its children
let replacedComponent = findChildViaBlockIdsPath(container, [blockId]);
runScriptsOfComponentAndChildren(replacedComponent);
// select the component that was selected before the ajax call
relativeIds.push(blockId);
let componentToSelect = findChildViaBlockIdsPath(container, relativeIds.reverse());
window.editor.select(componentToSelect);
},
error: function() {
$(".gjs-frame").contents().find("#" + component.ccid).removeClass('gjs-freezed');
if (!response.ok) {
if (frameEl) frameEl.classList.remove('gjs-freezed');
component.attributes['is-updating'] = false;
window.toastr.error(window.translations['toastr-component-update-failed']);
return;
}
});
const blockHtml = await response.text();
let parsedDiv = document.createElement('div');
parsedDiv.innerHTML = blockHtml;
let firstEl = parsedDiv.firstElementChild;
let blockId = firstEl ? firstEl.getAttribute('block-id') : null;
// set the block settings for the updated component to the new values
window.pageBlocks[window.currentLanguage][blockId] = (data.blocks[blockId] === undefined) ? {} : data.blocks[blockId];
// replace old component for the rendered html returned by the server
component.replaceWith(blockHtml);
replacePlaceholdersForRenderedBlocks(container);
applyBlockAttributesToComponents(container);
restrictEditAccess(container, false, false);
// run builder scripts of the replaced component and all its children
let replacedComponent = findChildViaBlockIdsPath(container, [blockId]);
runScriptsOfComponentAndChildren(replacedComponent);
// select the component that was selected before the ajax call
relativeIds.push(blockId);
let componentToSelect = findChildViaBlockIdsPath(container, relativeIds.reverse());
window.editor.select(componentToSelect);
} catch (error) {
if (frameEl) frameEl.classList.remove('gjs-freezed');
component.attributes['is-updating'] = false;
window.toastr.error(window.translations['toastr-component-update-failed']);
}
});
/**
@@ -694,13 +739,16 @@
// refresh the current component in order to switch its component type to raw-content.
// this disables GrapesJS parsing of any child elements, avoiding that any GrapesJS specific html attributes are added
let newComponent = component.replaceWith(component.toHTML());
// copy important attributes from the original component to the refreshed component
['block-id', 'block-slug', 'is-html', 'style-identifier'].forEach(attribute => {
newComponent.attributes[attribute] = component.attributes[attribute];
});
// apply block/component edit restrictions to the new raw-content type version of the component
restrictEditAccess(newComponent);
let replaced = component.replaceWith(component.toHTML());
let newComponent = Array.isArray(replaced) ? replaced[0] : replaced;
if (newComponent) {
// copy important attributes from the original component to the refreshed component
['block-id', 'block-slug', 'is-html', 'style-identifier'].forEach(attribute => {
newComponent.attributes[attribute] = component.attributes[attribute];
});
// apply block/component edit restrictions to the new raw-content type version of the component
restrictEditAccess(newComponent);
}
return;
}
}
@@ -756,7 +804,7 @@
settings.removable = true;
}
if (! $.isEmptyObject(settings)) {
if (Object.keys(settings).length > 0) {
component.set(settings);
if (settings.stylable !== undefined && settings.stylable) {
addUniqueClass(component);
@@ -1,24 +1,55 @@
$(".gjs-editor").append($("#toggle-sidebar"));
$(".gjs-pn-panels").prepend($("#sidebar-header"));
$(".gjs-pn-panels").append($("#sidebar-bottom-buttons"));
const editorEl = document.querySelector('.gjs-editor');
const toggleSidebarBtn = document.getElementById('toggle-sidebar');
const sidebarHeader = document.getElementById('sidebar-header');
const sidebarBottomButtons = document.getElementById('sidebar-bottom-buttons');
const panelsEl = document.querySelector('.gjs-pn-panels');
const gjsEl = document.getElementById('gjs');
$("#toggle-sidebar").click(function() {
$("#gjs").toggleClass('sidebar-collapsed');
if (editorEl && toggleSidebarBtn) {
editorEl.appendChild(toggleSidebarBtn);
}
if (panelsEl) {
if (sidebarHeader) panelsEl.prepend(sidebarHeader);
if (sidebarBottomButtons) panelsEl.appendChild(sidebarBottomButtons);
}
if (toggleSidebarBtn) {
toggleSidebarBtn.addEventListener('click', function() {
if (gjsEl) gjsEl.classList.toggle('sidebar-collapsed');
triggerEditorResize();
});
autoCollapseSidebar();
}
autoCollapseSidebar();
if (window.editor) {
window.editor.on('run:open-sm', function(editor) {
$(".gjs-trt-traits").parent().parent().css('display', 'none');
$(".gjs-sm-sectors").parent().parent().css('display', 'block');
const traits = document.querySelector('.gjs-trt-traits');
if (traits && traits.parentElement && traits.parentElement.parentElement) {
traits.parentElement.parentElement.style.display = 'none';
}
const sectors = document.querySelector('.gjs-sm-sectors');
if (sectors && sectors.parentElement && sectors.parentElement.parentElement) {
sectors.parentElement.parentElement.style.display = 'block';
}
// move element classes editor to advanced section
$("#gjs-sm-advanced .gjs-sm-properties").append($(".gjs-clm-tags"));
const advancedProps = document.querySelector('#gjs-sm-advanced .gjs-sm-properties');
const clmTags = document.querySelector('.gjs-clm-tags');
if (advancedProps && clmTags) {
advancedProps.appendChild(clmTags);
}
});
window.editor.on('run:open-tm', function(editor) {
$(".gjs-sm-sectors").parent().parent().css('display', 'none');
$(".gjs-trt-traits").parent().parent().css('display', 'block');
const sectors = document.querySelector('.gjs-sm-sectors');
if (sectors && sectors.parentElement && sectors.parentElement.parentElement) {
sectors.parentElement.parentElement.style.display = 'none';
}
const traits = document.querySelector('.gjs-trt-traits');
if (traits && traits.parentElement && traits.parentElement.parentElement) {
traits.parentElement.parentElement.style.display = 'block';
}
});
window.editor.on('block:drag:start', function(block) {
@@ -31,44 +62,51 @@
if (! selectedDomComponent) return;
setTimeout(function() {
let $toolbar = $(".gjs-rte-toolbar").first();
let toolbarInUpperHalf = $toolbar.offset().top < (toolbarPosition.elementTop + (0.5 * toolbarPosition.elementHeight));
let toolbar = document.querySelector('.gjs-rte-toolbar');
if (!toolbar) return;
const rect = toolbar.getBoundingClientRect();
let toolbarInUpperHalf = (rect.top + window.scrollY) < (toolbarPosition.elementTop + (0.5 * toolbarPosition.elementHeight));
if (toolbarInUpperHalf) {
let newTop = toolbarPosition.elementTop - $toolbar.height();
let newTop = toolbarPosition.elementTop - toolbar.offsetHeight;
if (newTop > 0) {
$toolbar.css('top', newTop + 'px');
} else {
//$toolbar.css('top', (toolbarPosition.elementTop + toolbarPosition.elementHeight) + 'px');
toolbar.style.top = newTop + 'px';
}
}
}, 0);
});
}
function autoCollapseSidebar() {
if ($(window).width() < 1000) {
$("#gjs").addClass('sidebar-collapsed');
triggerEditorResize();
}
function autoCollapseSidebar() {
if (window.innerWidth < 1000) {
if (gjsEl) gjsEl.classList.add('sidebar-collapsed');
triggerEditorResize();
}
}
function triggerEditorResize() {
function triggerEditorResize() {
if (window.editor && window.editor.trigger) {
window.editor.trigger('change:canvasOffset canvasScroll');
}
}
// prevent exiting page builder with backspace button
let backspaceIsPressed = false;
$(document).keydown(function(event) {
if (event.which === 8) backspaceIsPressed = true;
}).keyup(function(event) {
if (event.which === 8) backspaceIsPressed = false;
});
$(window).on('beforeunload', function(event) {
if (backspaceIsPressed) event.preventDefault();
});
// prevent exiting page builder with backspace button
let backspaceIsPressed = false;
document.addEventListener('keydown', function(event) {
if (event.key === 'Backspace' || event.which === 8) backspaceIsPressed = true;
});
document.addEventListener('keyup', function(event) {
if (event.key === 'Backspace' || event.which === 8) backspaceIsPressed = false;
});
window.addEventListener('beforeunload', function(event) {
if (backspaceIsPressed) event.preventDefault();
});
function addBlockSearch() {
$(".gjs-blocks-cs").prepend($("#block-search"));
const blocksCs = document.querySelector('.gjs-blocks-cs');
const blockSearch = document.getElementById('block-search');
if (blocksCs && blockSearch) {
blocksCs.prepend(blockSearch);
}
}
// listen to messages from iframe
@@ -77,11 +115,12 @@ window.addEventListener("message", onMessage, false);
function onMessage(event) {
// if the page is loaded, remove loading element
if (event.data === 'page-loaded') {
$("#phpb-loading").addClass('loaded');
const loadingEl = document.getElementById('phpb-loading');
if (loadingEl) loadingEl.classList.add('loaded');
addBlockSearch();
window.isLoaded = true;
$(window).trigger('pagebuilder-page-loaded');
} else if(event.data === 'touch-start') {
window.touchStart();
window.dispatchEvent(new CustomEvent('pagebuilder-page-loaded'));
} else if (event.data === 'touch-start') {
if (window.touchStart) window.touchStart();
}
}
@@ -1,6 +1,7 @@
window.touchStart = function() {
$("#gjs").addClass('sidebar-collapsed');
}
const gjsEl = document.getElementById('gjs');
if (gjsEl) gjsEl.classList.add('sidebar-collapsed');
};
@@ -0,0 +1,330 @@
export function sanitizeHtml(html) {
if (!html) return '';
// remove all not allowed tags
let result = html.replace(/<(?!\/?(?:a|table|tr|td|th|thead|tbody|tfoot|caption|col|colgroup|p|ul|ol|li|br|strong|em|b|i|u|strike|s|sub|sup|h1|h2|h3|h4|h5|h6|blockquote|pre|hr|span)\b)[^>]+>/gim, '');
// remove disallowed attributes from allowed tags, keeping href on anchor and style on table elements
result = result.replace(/<(a|table|tr|td|th|thead|tbody|tfoot|caption|col|colgroup|p|ul|ol|li|br|strong|em|b|i|u|strike|s|sub|sup|h1|h2|h3|h4|h5|h6|blockquote|pre|hr|span)\b([^>]*)>/gim, function(match, tag, attrs) {
tag = tag.toLowerCase();
if (tag === 'a') {
const hrefMatch = attrs.match(/href="([^"]*)"/i) || attrs.match(/href='([^']*)'/i);
const targetMatch = attrs.match(/target="([^"]*)"/i) || attrs.match(/target='([^']*)'/i);
const href = hrefMatch ? ` href="${hrefMatch[1]}"` : '';
const target = targetMatch && targetMatch[1] === '_blank' ? ' target="_blank"' : '';
return `<a${href}${target}>`;
}
if ('|table|tr|td|th|thead|tbody|tfoot|'.includes('|' + tag + '|')) {
const styleMatch = attrs.match(/style="([^"]*)"/i) || attrs.match(/style='([^']*)'/i);
return styleMatch ? `<${tag} style="${styleMatch[1]}">` : `<${tag}>`;
}
return `<${tag}>`;
});
return result;
}
function setupPasteSanitizer(editor) {
const handlePaste = ({ ev, rte }) => {
ev.preventDefault();
const clipboardData = ev.clipboardData || window.clipboardData;
if (!clipboardData) return;
const html = clipboardData.getData('text/html');
const text = clipboardData.getData('text/plain');
if (html) {
const cleanHtml = sanitizeHtml(html);
rte.insertHTML(cleanHtml);
} else if (text) {
const escaped = text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/(?:\r\n|\r|\n)/g, '<br/>');
rte.insertHTML(escaped);
}
};
if (editor.RichTextEditor) {
const rteConfig = editor.RichTextEditor.getConfig();
rteConfig.onPaste = handlePaste;
}
}
function registerToolbarActions(editor) {
const rte = editor.RichTextEditor;
if (!rte) return;
// Custom Link action
if (rte.get('link')) {
rte.remove('link');
}
rte.add('link', {
icon: '<i class="fa fa-link"></i>',
attributes: { title: (window.translations && window.translations['link']) || 'Link' },
result: r => openLinkModal(editor, r)
});
if (!rte.get('unorderedList')) {
rte.add('unorderedList', {
icon: '<i class="fa fa-list-ul"></i>',
attributes: { title: 'Bulleted List' },
result: r => r.exec('insertUnorderedList')
});
}
if (!rte.get('orderedList')) {
rte.add('orderedList', {
icon: '<i class="fa fa-list-ol"></i>',
attributes: { title: 'Numbered List' },
result: r => r.exec('insertOrderedList')
});
}
if (!rte.get('justifyLeft')) {
rte.add('justifyLeft', {
icon: '<i class="fa fa-align-left"></i>',
attributes: { title: 'Align Left' },
result: r => r.exec('justifyLeft')
});
}
if (!rte.get('justifyCenter')) {
rte.add('justifyCenter', {
icon: '<i class="fa fa-align-center"></i>',
attributes: { title: 'Align Center' },
result: r => r.exec('justifyCenter')
});
}
if (!rte.get('justifyRight')) {
rte.add('justifyRight', {
icon: '<i class="fa fa-align-right"></i>',
attributes: { title: 'Align Right' },
result: r => r.exec('justifyRight')
});
}
}
function openLinkModal(editor, rte) {
const sel = rte.selection();
let savedRange = null;
let currentAnchor = null;
if (sel && sel.rangeCount > 0) {
savedRange = sel.getRangeAt(0).cloneRange();
let node = sel.anchorNode;
if (node) {
if (node.nodeType === Node.TEXT_NODE) node = node.parentNode;
currentAnchor = node.closest ? node.closest('a') : null;
}
}
let initialType = 'page';
let initialPageId = '';
let initialUrl = '';
let initialTargetBlank = false;
if (currentAnchor) {
const href = currentAnchor.getAttribute('href') || '';
if (currentAnchor.getAttribute('target') === '_blank') {
initialTargetBlank = true;
}
if (href.startsWith('[page id=')) {
initialType = 'page';
initialPageId = href.substring(9, href.length - 1);
} else {
initialType = 'url';
initialUrl = href;
}
}
const pages = window.pages || [];
const translations = window.translations || {};
const container = document.createElement('div');
container.className = 'gjs-link-modal-form';
container.style.padding = '10px 0';
// Type selector: Internal Page vs External URL
const typeGroup = document.createElement('div');
typeGroup.style.marginBottom = '12px';
typeGroup.innerHTML = `
<label style="display:block; font-weight:600; margin-bottom:4px;">${translations['link-type'] || 'Link Type'}</label>
<div style="display:flex; gap:16px;">
<label style="cursor:pointer; display:flex; align-items:center; gap:6px;">
<input type="radio" name="plugi_link_type" value="page" ${initialType === 'page' ? 'checked' : ''}>
<span>${translations['page'] || 'Internal Page'}</span>
</label>
<label style="cursor:pointer; display:flex; align-items:center; gap:6px;">
<input type="radio" name="plugi_link_type" value="url" ${initialType === 'url' ? 'checked' : ''}>
<span>URL</span>
</label>
</div>
`;
container.appendChild(typeGroup);
// Page selection container
const pageGroup = document.createElement('div');
pageGroup.style.marginBottom = '12px';
pageGroup.style.display = initialType === 'page' ? 'block' : 'none';
let pageOptionsHtml = '<option value="">-- ' + (translations['select-page'] || 'Select Page') + ' --</option>';
pages.forEach(item => {
const title = Array.isArray(item) ? item[0] : (item.title || item.name);
const id = Array.isArray(item) ? item[1] : item.id;
const isSelected = String(id) === String(initialPageId) ? 'selected' : '';
pageOptionsHtml += `<option value="${id}" ${isSelected}>${title}</option>`;
});
pageGroup.innerHTML = `
<label style="display:block; font-weight:600; margin-bottom:4px;">${translations['page'] || 'Page'}</label>
<select class="form-control gjs-field" style="width:100%; padding:6px 10px; border-radius:4px;">
${pageOptionsHtml}
</select>
`;
container.appendChild(pageGroup);
// URL input container
const urlGroup = document.createElement('div');
urlGroup.style.marginBottom = '12px';
urlGroup.style.display = initialType === 'url' ? 'block' : 'none';
urlGroup.innerHTML = `
<label style="display:block; font-weight:600; margin-bottom:4px;">URL</label>
<input type="text" class="form-control gjs-field" placeholder="https://" value="${initialUrl}" style="width:100%; padding:6px 10px; border-radius:4px;">
`;
container.appendChild(urlGroup);
// Toggle between page and URL
const radios = typeGroup.querySelectorAll('input[type="radio"]');
radios.forEach(radio => {
radio.addEventListener('change', () => {
if (radio.value === 'page') {
pageGroup.style.display = 'block';
urlGroup.style.display = 'none';
} else {
pageGroup.style.display = 'none';
urlGroup.style.display = 'block';
}
});
});
// Target blank checkbox
const targetGroup = document.createElement('div');
targetGroup.style.marginBottom = '16px';
targetGroup.innerHTML = `
<label style="cursor:pointer; display:flex; align-items:center; gap:6px;">
<input type="checkbox" id="plugi_target_blank" ${initialTargetBlank ? 'checked' : ''}>
<span>${translations['target-blank'] || 'Open in new tab'}</span>
</label>
`;
container.appendChild(targetGroup);
// Buttons
const buttonsGroup = document.createElement('div');
buttonsGroup.style.display = 'flex';
buttonsGroup.style.gap = '8px';
buttonsGroup.style.justifyContent = 'flex-end';
const cancelBtn = document.createElement('button');
cancelBtn.type = 'button';
cancelBtn.className = 'btn';
cancelBtn.innerText = translations['cancel'] || 'Cancel';
cancelBtn.addEventListener('click', () => editor.Modal.close());
buttonsGroup.appendChild(cancelBtn);
if (currentAnchor) {
const unlinkBtn = document.createElement('button');
unlinkBtn.type = 'button';
unlinkBtn.className = 'btn btn-danger';
unlinkBtn.style.color = '#e53e3e';
unlinkBtn.innerText = translations['unlink'] || 'Remove Link';
unlinkBtn.addEventListener('click', () => {
const parent = currentAnchor.parentNode;
while (currentAnchor.firstChild) {
parent.insertBefore(currentAnchor.firstChild, currentAnchor);
}
parent.removeChild(currentAnchor);
editor.Modal.close();
});
buttonsGroup.appendChild(unlinkBtn);
}
const applyBtn = document.createElement('button');
applyBtn.type = 'button';
applyBtn.className = 'btn btn-primary';
applyBtn.style.backgroundColor = '#3b82f6';
applyBtn.style.color = '#fff';
applyBtn.innerText = translations['apply'] || 'Apply';
applyBtn.addEventListener('click', () => {
const selectedType = typeGroup.querySelector('input[type="radio"]:checked').value;
const pageSelect = pageGroup.querySelector('select');
const urlInput = urlGroup.querySelector('input');
const targetBlank = targetGroup.querySelector('input').checked;
let href = '';
if (selectedType === 'page') {
if (pageSelect.value) {
href = `[page id=${pageSelect.value}]`;
}
} else {
href = urlInput.value.trim();
}
if (!href) {
editor.Modal.close();
return;
}
if (savedRange && rte.doc) {
const win = rte.doc.defaultView || window;
const currentSel = win.getSelection();
if (currentSel) {
currentSel.removeAllRanges();
currentSel.addRange(savedRange);
}
}
if (currentAnchor) {
currentAnchor.setAttribute('href', href);
if (targetBlank) {
currentAnchor.setAttribute('target', '_blank');
} else {
currentAnchor.removeAttribute('target');
}
} else {
const selectedText = savedRange ? savedRange.toString() : '';
const targetAttr = targetBlank ? ' target="_blank"' : '';
const textToInsert = selectedText || href;
rte.insertHTML(`<a href="${href}"${targetAttr}>${textToInsert}</a>`);
}
editor.Modal.close();
});
buttonsGroup.appendChild(applyBtn);
container.appendChild(buttonsGroup);
editor.Modal.open({
title: translations['link'] || 'Link',
content: container
});
}
let isInitialized = false;
export function initRteLinkManager(editor) {
if (!editor || !editor.RichTextEditor || isInitialized) return;
isInitialized = true;
setupPasteSanitizer(editor);
registerToolbarActions(editor);
}
if (typeof window !== 'undefined') {
if (window.editor) {
initRteLinkManager(window.editor);
} else {
window.addEventListener('load', () => {
if (window.editor) initRteLinkManager(window.editor);
});
}
}
@@ -57,10 +57,6 @@
if (component && component.attributes && (component.attributes['block-id'] || component.attributes['id'])) {
window.runScriptsOfComponentAndChildren(component);
}
// remove all existing CKEditors after dragging a block with active editor
for (let instanceName in CKEDITOR.instances) {
CKEDITOR.instances[instanceName].destroy(true);
}
});
/**
@@ -87,20 +83,20 @@
}
if (blockId && window.customBuilderScripts[blockId] !== undefined) {
let styleIdentifier = component.attributes["style-identifier"];
let $scriptTag = $("<container>").append(window.customBuilderScripts[blockId]);
// prepend block and blockSelector variables allowing the script to refer to this exact block instance
$scriptTag.find('script').prepend('let inPageBuilder = true;');
$scriptTag.find('script').prepend('let blockSelector = ".' + styleIdentifier + '";');
$scriptTag.find('script').prepend('let block = document.getElementsByClassName("' + styleIdentifier + '")[0];');
// wrap the script contents in a self-invoking function (to add a scope avoiding variable name collisions)
$scriptTag.find('script').prepend('(function(){');
$scriptTag.find('script').append('})();');
// execute the script in the page that is being edited
let scriptTag = document.createElement("script");
scriptTag.type = "text/javascript";
scriptTag.innerHTML = $scriptTag.find('script').html();
window.editor.Canvas.getDocument().body.appendChild(scriptTag);
let tempDiv = document.createElement("div");
tempDiv.innerHTML = window.customBuilderScripts[blockId];
let parsedScript = tempDiv.querySelector('script');
if (parsedScript) {
let scriptContent = parsedScript.innerHTML;
let wrapped = `(function(){\nlet block = document.getElementsByClassName("${styleIdentifier}")[0];\nlet blockSelector = ".${styleIdentifier}";\nlet inPageBuilder = true;\n${scriptContent}\n})();`;
let scriptTag = document.createElement("script");
scriptTag.type = "text/javascript";
scriptTag.textContent = wrapped;
let canvasDoc = window.editor.Canvas.getDocument();
if (canvasDoc && canvasDoc.body) {
canvasDoc.body.appendChild(scriptTag);
}
}
}
}
@@ -14,15 +14,18 @@
/**
* Save page on clicking save button.
*/
$("#save-page").click(function() {
saveAllTranslationsToServer();
});
const savePageBtn = document.getElementById("save-page");
if (savePageBtn) {
savePageBtn.addEventListener('click', function() {
saveAllTranslationsToServer();
});
}
/**
* Save page on Ctrl + S.
*/
$(document).bind("keydown", function(e){
if(e.ctrlKey && e.which === 83) {
document.addEventListener("keydown", function(e) {
if (e.ctrlKey && (e.key === 's' || e.key === 'S' || e.which === 83)) {
// text-editor updates are not applied until focus is lost, so force GrapesJS update
window.editor.store();
@@ -42,35 +45,51 @@
window.switchLanguage = function(newLanguage, callback) {
window.setWaiting(true);
saveCurrentTranslationLocally(function() {
saveCurrentTranslationLocally(async function() {
applyChangesFromCurrentLanguageToNewLanguage(newLanguage);
let data = window.pageData;
data.blocks = {[newLanguage]: window.pageBlocks[newLanguage]};
const formData = new URLSearchParams();
formData.append('data', JSON.stringify(data));
formData.append('language', newLanguage);
// render the language variant server-side
$.ajax({
type: "POST",
url: window.renderLanguageVariantUrl,
data: {
data: JSON.stringify(data),
language: newLanguage
},
success: function(response) {
response = JSON.parse(response);
window.pageBlocks[newLanguage] = response.dynamicBlocks ? response.dynamicBlocks : {};
callback();
window.setWaiting(false);
},
error: function(error) {
callback();
console.log(error);
let errorMessage = error.statusText + ' ' + error.status;
errorMessage = error.responseJSON.message ? (errorMessage + ': "' + error.responseJSON.message + '"') : errorMessage;
try {
const response = await fetch(window.renderLanguageVariantUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
},
body: formData
});
if (!response.ok) {
let errData = {};
try { errData = await response.json(); } catch(e) {}
let errorMessage = response.statusText + ' ' + response.status;
errorMessage = errData.message ? (errorMessage + ': "' + errData.message + '"') : errorMessage;
window.toastr.error(errorMessage);
window.toastr.error(window.translations['toastr-switching-language-failed']);
callback();
window.setWaiting(false);
return;
}
});
const responseText = await response.text();
let parsed = JSON.parse(responseText);
window.pageBlocks[newLanguage] = parsed.dynamicBlocks ? parsed.dynamicBlocks : {};
callback();
window.setWaiting(false);
} catch (error) {
callback();
console.error(error);
window.toastr.error(error.message || 'Error');
window.toastr.error(window.translations['toastr-switching-language-failed']);
window.setWaiting(false);
}
});
};
@@ -98,13 +117,23 @@
// copy the content of blocks containers of the current language to the blocks containers of the new language
for (let blockId in currentLanguageBlocks) {
let $currentLanguageBlockHtmlDom = $("<container>" + currentLanguageBlocks[blockId]['html'] + "</container>");
let $newLanguageBlockHtmlDom = $("<container>" + newLanguageBlocks[blockId]['html'] + "</container>");
$currentLanguageBlockHtmlDom.find("[phpb-blocks-container]").each(function(index) {
let currentLanguageBlockContainerHtml = $(this).html();
$newLanguageBlockHtmlDom.find("[phpb-blocks-container]").eq(index).html(currentLanguageBlockContainerHtml);
let currentBlockHtml = (currentLanguageBlocks[blockId] && currentLanguageBlocks[blockId]['html']) || '';
let newBlockHtml = (newLanguageBlocks[blockId] && newLanguageBlocks[blockId]['html']) || '';
let currDiv = document.createElement("div");
currDiv.innerHTML = currentBlockHtml;
let newDiv = document.createElement("div");
newDiv.innerHTML = newBlockHtml;
let currContainers = currDiv.querySelectorAll("[phpb-blocks-container]");
let newContainers = newDiv.querySelectorAll("[phpb-blocks-container]");
currContainers.forEach((cont, index) => {
if (newContainers[index]) {
newContainers[index].innerHTML = cont.innerHTML;
}
});
newLanguageBlocks[blockId]['html'] = $newLanguageBlockHtmlDom.html();
newLanguageBlocks[blockId]['html'] = newDiv.innerHTML;
}
window.pageBlocks[newLanguage] = newLanguageBlocks;
@@ -226,10 +255,10 @@
function saveAllTranslationsToServer() {
toggleSaving();
saveCurrentTranslationLocally(function() {
saveCurrentTranslationLocally(async function() {
// update all language variants with the latest data of the current language we just saved locally
$.each(window.languages, (languageCode, languageTranslation) => {
Object.keys(window.languages || {}).forEach(languageCode => {
if (languageCode !== window.currentLanguage) {
applyChangesFromCurrentLanguageToNewLanguage(languageCode);
}
@@ -239,29 +268,45 @@
data.style = removeOldStyleSelectors(data.style);
data.blocks = window.pageBlocks;
$.ajax({
type: "POST",
url: $("#save-page").data('url'),
data: {
data: JSON.stringify(data)
},
success: function() {
toggleSaving();
window.toastr.success(window.translations['toastr-changes-saved']);
const saveBtn = document.getElementById("save-page");
const saveUrl = saveBtn ? (saveBtn.dataset.url || saveBtn.getAttribute('data-url')) : '';
setTimeout(function() {
window.changesOffset = window.editor.getModel().get('changesCount');
}, 250);
},
error: function(error) {
toggleSaving();
console.log(error);
let errorMessage = error.statusText + ' ' + error.status;
errorMessage = error.responseJSON.message ? (errorMessage + ': "' + error.responseJSON.message + '"') : errorMessage;
const formData = new URLSearchParams();
formData.append('data', JSON.stringify(data));
try {
const response = await fetch(saveUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
},
body: formData
});
toggleSaving();
if (!response.ok) {
let errData = {};
try { errData = await response.json(); } catch(e) {}
let errorMessage = response.statusText + ' ' + response.status;
errorMessage = errData.message ? (errorMessage + ': "' + errData.message + '"') : errorMessage;
window.toastr.error(errorMessage);
window.toastr.error(window.translations['toastr-saving-failed']);
return;
}
});
window.toastr.success(window.translations['toastr-changes-saved']);
setTimeout(function() {
window.changesOffset = window.editor.getModel().get('changesCount');
}, 250);
} catch(error) {
toggleSaving();
console.error(error);
window.toastr.error(error.message || 'Error');
window.toastr.error(window.translations['toastr-saving-failed']);
}
});
}
@@ -342,12 +387,15 @@
function getContainerHtml(container) {
let html = '';
container.get('components').forEach(component => html += component.toHTML());
let htmlDom = $("<container>" + html + "</container>");
let div = document.createElement("div");
div.innerHTML = html;
// replace phpb-block elements with shortcode
htmlDom.find('phpb-block').each(function() {
$(this).replaceWith('[block slug="' + $(this).attr('slug') + '" id="' + $(this).attr('id') + '"]');
div.querySelectorAll('phpb-block').forEach(el => {
let slug = el.getAttribute('slug') || '';
let id = el.getAttribute('id') || '';
el.replaceWith('[block slug="' + slug + '" id="' + id + '"]');
});
return htmlDom.html();
return div.innerHTML;
}
/**
@@ -356,12 +404,15 @@
* @param component
*/
function getComponentHtml(component) {
let htmlDom = $("<container>" + component.toHTML() + "</container>");
let div = document.createElement("div");
div.innerHTML = component.toHTML();
// replace phpb-block elements with shortcode
htmlDom.find('phpb-block').each(function() {
$(this).replaceWith('[block slug="' + $(this).attr('slug') + '" id="' + $(this).attr('id') + '"]');
div.querySelectorAll('phpb-block').forEach(el => {
let slug = el.getAttribute('slug') || '';
let id = el.getAttribute('id') || '';
el.replaceWith('[block slug="' + slug + '" id="' + id + '"]');
});
return htmlDom.html();
return div.innerHTML;
}
/**
@@ -513,17 +564,20 @@
* Toggle the save button waiting status.
*/
function toggleSaving() {
let button = $("#save-page");
let button = document.getElementById("save-page");
if (!button) return;
button.blur();
if (button.hasClass('waiting')) {
button.attr("disabled", false);
button.removeClass('waiting');
button.find('.spinner-border').addClass('d-none');
let spinner = button.querySelector('.spinner-border') || button.querySelector('.loading');
if (button.classList.contains('waiting')) {
button.removeAttribute("disabled");
button.classList.remove('waiting');
if (spinner) spinner.classList.add('d-none');
} else {
button.attr("disabled", true);
button.addClass('waiting');
button.find('.spinner-border').removeClass('d-none');
button.setAttribute("disabled", "true");
button.classList.add('waiting');
if (spinner) spinner.classList.remove('d-none');
}
}
@@ -0,0 +1,75 @@
let toastContainer = null;
function getToastContainer() {
if (!toastContainer || !document.body.contains(toastContainer)) {
toastContainer = document.createElement('div');
toastContainer.className = 'toast toast-top toast-end';
toastContainer.style.cssText = 'position:fixed; top:20px; right:20px; z-index:999999; display:flex; flex-direction:column; gap:10px; pointer-events:none;';
document.body.appendChild(toastContainer);
}
return toastContainer;
}
export function showToast(message, type = 'info', duration = 3500) {
if (!message) return;
const container = getToastContainer();
const alert = document.createElement('div');
alert.className = `alert alert-${type}`;
alert.style.cssText = `
pointer-events: auto;
min-width: 250px;
max-width: 400px;
padding: 12px 16px;
border-radius: 6px;
box-shadow: 0 4px 12px rgba(0,0,0,0.25);
color: #fff;
font-size: 14px;
font-family: inherit;
display: flex;
align-items: center;
gap: 8px;
background-color: ${type === 'success' ? '#10b981' : type === 'error' ? '#ef4444' : '#3b82f6'};
transition: opacity 0.3s ease, transform 0.3s ease;
opacity: 0;
transform: translateY(-10px);
`;
const icon = document.createElement('i');
icon.className = type === 'success' ? 'fa fa-check-circle' : type === 'error' ? 'fa fa-exclamation-circle' : 'fa fa-info-circle';
alert.appendChild(icon);
const span = document.createElement('span');
span.innerText = message;
span.style.flex = '1';
alert.appendChild(span);
container.appendChild(alert);
// animate in
requestAnimationFrame(() => {
alert.style.opacity = '1';
alert.style.transform = 'translateY(0)';
});
setTimeout(() => {
alert.style.opacity = '0';
alert.style.transform = 'translateY(-10px)';
setTimeout(() => {
if (alert.parentNode) {
alert.parentNode.removeChild(alert);
}
}, 300);
}, duration);
}
window.toastr = {
success(msg, duration = 3000) {
showToast(msg, 'success', duration);
},
error(msg, duration = 4000) {
showToast(msg, 'error', duration);
},
info(msg, duration = 3000) {
showToast(msg, 'info', duration);
}
};
@@ -1,16 +0,0 @@
.cke_dialog_body {
.cke_dialog_ui_vbox_child {
padding: 0;
}
input.cke_dialog_ui_input_text,
input.cke_dialog_ui_input_password,
input.cke_dialog_ui_input_tel,
textarea.cke_dialog_ui_input_textarea,
div.cke_dialog_ui_input_select {
margin-bottom: 10px;
}
.cke_dialog_ui_input_select {
width: 100% !important;
}
}
@@ -263,43 +263,29 @@ html, body, #gjs {
position: absolute;
box-shadow: none;
width: $sidebar-width;
padding-bottom: 0;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
padding-left: 0;
padding-right: 0;
padding: 0 10px;
background: #22272e;
height: 40px;
z-index: 100;
display: flex;
align-items: center;
#language-selector {
float: right;
margin-left: auto;
.dropdown-item.active,
.dropdown-item:active {
background: #22272e !important;
}
.dropdown-menu.show {
padding: 0;
}
.dropdown-toggle {
margin-top: 2px;
color: #fff !important;
background: none !important;
border: none;
box-shadow: none;
outline: none !important;
}
.flag-icon {
background-size: contain;
background-position: 50%;
background-repeat: no-repeat;
position: relative;
display: inline-block;
width: 1.33333333em;
height: 12px;
line-height: 1em;
select {
background: #2e323b;
color: #e3e3e3;
border: 1px solid #474c57;
border-radius: 4px;
padding: 4px 8px;
font-size: 12px;
outline: none;
cursor: pointer;
&:focus {
border-color: #3b82f6;
}
}
}
}
@@ -311,7 +297,13 @@ html, body, #gjs {
color: #c4c7ce;
background: #22272e;
border-radius: 0;
transition-duration: unset;
border: none;
cursor: pointer;
height: 40px;
width: 40px;
display: flex;
align-items: center;
justify-content: center;
}
@@ -524,28 +516,31 @@ html, body, #gjs {
width: $sidebar-width;
margin: 0;
padding: 0;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
background: #474c57;
border-top: none;
display: flex;
button,
a {
float: right;
flex: 1;
display: inline-flex;
align-items: center;
justify-content: center;
height: 100%;
width: 33.33%;
border-left: 1px solid #343944;
border-radius: 0;
color: #e3e3e3;
font-size: 15px;
padding: 8px 0;
font-size: 13px;
padding: 0 4px;
text-decoration: none;
border: none;
border-left: 1px solid #343944;
&:hover {
background: #017eb5;
color: #fff;
}
&:last-child {
&:first-child {
border-left: none;
}
}
@@ -554,7 +549,7 @@ html, body, #gjs {
background: #0091d1;
color: #fff !important;
i.fa {
i.fa-save {
display: none;
}
}
@@ -570,4 +565,40 @@ html, body, #gjs {
@import 'fields';
@import 'style-manager';
@import 'asset-manager';
@import 'ckeditor';
.gjs-link-modal-form {
color: #d1d5db;
font-size: 14px;
.gjs-field {
background-color: #2e323b;
border: 1px solid #474c57;
color: #fff;
padding: 8px 12px;
border-radius: 4px;
outline: none;
font-size: 14px;
&:focus {
border-color: #3b82f6;
}
}
select.gjs-field {
appearance: none;
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0aec0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
background-repeat: no-repeat;
background-position: right 10px center;
background-size: 16px;
padding-right: 32px;
}
.btn {
padding: 6px 14px;
border-radius: 4px;
font-size: 13px;
cursor: pointer;
border: none;
transition: background-color 0.15s ease-in-out;
}
}
@@ -2,17 +2,14 @@
window.editor.on('asset:remove', function(asset) {
let assetId = asset.attributes.public_id;
$.ajax({
type: "POST",
url: "<?= phpb_url('pagebuilder', ['action' => 'upload_delete', 'page' => $page->getId()]) ?>",
data: {
id: assetId
fetch("<?= phpb_url('pagebuilder', ['action' => 'upload_delete', 'page' => $page->getId()]) ?>", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-Requested-With": "XMLHttpRequest"
},
success: function() {
},
error: function() {
}
});
body: new URLSearchParams({ id: assetId })
}).catch(function() {});
});
</script>
@@ -1,15 +1,16 @@
<script type="text/javascript">
var editor = window.editor;
let linkType = editor.DomComponents.getType('link');
editor.DomComponents.addType('link', {
extend: 'link',
model: {
defaults: {
traits: [
{
type: 'text',
label: '<?= phpb_trans('pagebuilder.trait-manager.link.text') ?>',
name: 'content',
changeProp: 1,
type: 'text',
label: '<?= phpb_trans('pagebuilder.trait-manager.link.text') ?>',
name: 'content',
changeProp: 1,
},
{
type: 'text',
@@ -33,28 +34,34 @@ editor.DomComponents.addType('link', {
],
},
init() {
this.getTrait('content').setTargetValue(this.attributes.content.trim());
if (! this.attributes.attributes.target) {
this.getTrait('target').setTargetValue(false);
const contentTrait = this.getTrait('content');
if (contentTrait && this.attributes && this.attributes.content) {
contentTrait.setTargetValue(this.attributes.content.trim());
}
if (this.attributes && this.attributes.attributes && ! this.attributes.attributes.target) {
const targetTrait = this.getTrait('target');
if (targetTrait) {
targetTrait.setTargetValue(false);
}
}
},
}
});
const textType = editor.DomComponents.getType('text');
editor.DomComponents.addType('text', {
extend: 'text',
model: {
defaults: {
traits: [],
attributes: {},
},
},
view: textType.view.extend({
view: {
events: {
click: 'onActive',
touchend: 'onActive'
},
}),
},
});
/**
@@ -63,23 +70,20 @@ editor.DomComponents.addType('text', {
* Source: https://github.com/artf/grapesjs/issues/774#issuecomment-358963099
*/
editor.DomComponents.addType('raw-content', {
model: textType.model.extend({
},{
isComponent: function(el) {
if (el.hasAttribute && (el.hasAttribute('data-raw-content') || el.hasAttribute('phpb-editable'))) {
return {
type: 'raw-content',
content: el.innerHTML,
components: [] // avoid parsing children
};
}
}
extend: 'text',
isComponent(el) {
if (el && el.hasAttribute && (el.hasAttribute('data-raw-content') || el.hasAttribute('phpb-editable'))) {
return {
type: 'raw-content',
content: el.innerHTML,
components: [] // avoid parsing children
};
}
),
view: textType.view
},
});
editor.DomComponents.addType('row', {
extend: 'row',
model: {
defaults: {
traits: [],
@@ -89,6 +93,7 @@ editor.DomComponents.addType('row', {
});
editor.DomComponents.addType('cell', {
extend: 'cell',
model: {
defaults: {
traits: [],
@@ -98,6 +103,7 @@ editor.DomComponents.addType('cell', {
});
editor.DomComponents.addType('default', {
extend: 'default',
model: {
defaults: {
traits: [],
@@ -90,26 +90,8 @@ return [
phpb_asset('pagebuilder/page-injection.css'),
],
],
'plugins' => ['grapesjs-touch', 'grapesjs-plugin-ckeditor'],
'pluginsOpts' => [
'grapesjs-plugin-ckeditor' => [
'position' => 'center',
'options' => [
'startupFocus' => true,
'allowedContent' => true,
//'forcePasteAsPlainText' => false, // when true does not copy UL, random JS errors while pasting
'extraAllowedContent' => '*(*);*[*];ul ol li span', // allows classes, inline styles and certain elements
//'enterMode' => 'CKEDITOR.ENTER_BR', // issues on pasting in Chromes
'extraPlugins' => 'sourcedialog',
'removePlugins' => 'exportpdf',
'toolbar' => [
['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'Link', 'Unlink', '-', 'Outdent', 'Indent', '-', 'Blockquote'],
'/',
['NumberedList', 'BulletedList', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
// ['FontSize', 'TextColor'],
['Sourcedialog']
],
]
]
'plugins' => ['grapesjs-touch'],
'richTextEditor' => [
'actions' => ['bold', 'italic', 'underline', 'strikethrough']
]
];
@@ -1,5 +1,6 @@
<script type="text/javascript">
var editor = window.editor;
let styleManager = editor.StyleManager;
styleManager.addSector('advanced',{
@@ -1,5 +1,5 @@
<script type="text/javascript">
var editor = window.editor;
editor.TraitManager.addType('image', {
createInput({ trait }) {
const previewImageUrl = '<?= phpb_asset('pagebuilder/images/image-placeholder-small.jpg') ?>';
@@ -6,19 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9, user-scalable=no">
<script src="<?= phpb_asset('PageBuilderHead.js') ?>"></script>
<link rel="stylesheet" href="<?= phpb_asset('pagebuilder/bootstrap-v4.3.1.min.css') ?>">
<link rel="stylesheet" href="<?= phpb_asset('pagebuilder/bootstrap-select-v1.13.12.min.css') ?>">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="<?= phpb_asset('pagebuilder/toastr-v2.1.3.min.css') ?>">
<link rel="stylesheet" href="<?= phpb_asset('WebsiteManager.css') ?>">
<link rel="stylesheet" href="<?= phpb_asset('PageBuilderHead.css') ?>">
<?= $pageBuilder->customStyle(); ?>
<script src="<?= phpb_asset('pagebuilder/underscore-v1.9.1.min.js') ?>"></script>
<script src="<?= phpb_asset('pagebuilder/jquery-3.4.1.min.js') ?>"></script>
<script src="<?= phpb_asset('pagebuilder/popper-v1.12.9.min.js') ?>"></script>
<script src="<?= phpb_asset('pagebuilder/bootstrap-v4.3.1.min.js') ?>"></script>
<script src="<?= phpb_asset('pagebuilder/bootstrap-select-v1.13.12.min.js') ?>"></script>
<script src="<?= phpb_asset('pagebuilder/toastr-v2.1.3.min.js') ?>"></script>
<script src="<?= phpb_asset('pagebuilder/beautify-html-v1.10.2.min.js') ?>"></script>
<link href="<?= phpb_asset('icons/duotone/style.css') ?>" rel="stylesheet">
<link href="<?= phpb_asset('icons/regular/style.css') ?>" rel="stylesheet">
@@ -15,20 +15,8 @@
<div id="gjs"></div>
<script type="text/javascript" src="https://cdn.ckeditor.com/4.21.0/full-all/ckeditor.js"></script>
<script type="text/javascript" src="<?= phpb_asset('pagebuilder/grapesjs-plugin-ckeditor-v0.0.10.min.js') ?>"></script>
<script type="text/javascript" src="<?= phpb_asset('pagebuilder/grapesjs-touch-v0.1.1.min.js') ?>"></script>
<script type="text/javascript">
CKEDITOR.dtd.$editable.a = 1;
CKEDITOR.dtd.$editable.b = 1;
CKEDITOR.dtd.$editable.em = 1;
CKEDITOR.dtd.$editable.button = 1;
CKEDITOR.dtd.$editable.strong = 1;
CKEDITOR.dtd.$editable.small = 1;
CKEDITOR.dtd.$editable.span = 1;
CKEDITOR.dtd.$editable.ol = 1;
CKEDITOR.dtd.$editable.ul = 1;
CKEDITOR.dtd.$editable.table = 1;
<?php
$currentLanguage = in_array(phpb_config('general.language'), phpb_active_languages()) ?
@@ -55,7 +43,16 @@ $config = require __DIR__ . '/grapesjs/config.php';
let config = <?= json_encode($config) ?>;
config.selectorManager.escapeName = name => `${name}`.trim().replace(/([^a-z0-9\w-\:\/]+)/gi, '-')
if (window.customConfig !== undefined) {
config = $.extend(true, {}, window.customConfig, config);
function phpbDeepMerge(target, source) {
for (const key of Object.keys(source || {})) {
if (source[key] instanceof Object && !Array.isArray(source[key]) && key in target) {
Object.assign(source[key], phpbDeepMerge(target[key], source[key]));
}
}
Object.assign(target || {}, source);
return target;
}
config = phpbDeepMerge(config, window.customConfig);
}
window.initialComponents = <?= json_encode($pageRenderer->render()) ?>;
@@ -95,7 +92,7 @@ window.editor.on('load', function(editor) {
window.editor.I18n.addMessages(window.grapesJSTranslations);
// load the default or earlier saved page css components
editor.setStyle(window.initialStyle);
window.editor.setStyle(window.initialStyle);
</script>
<?php
@@ -105,22 +102,20 @@ require __DIR__ . '/grapesjs/style-manager.php';
require __DIR__ . '/grapesjs/trait-manager.php';
?>
<button id="toggle-sidebar" class="btn">
<button id="toggle-sidebar" class="btn btn-sm btn-ghost">
<i class="fa fa-bars"></i>
</button>
<div id="sidebar-header">
<div id="sidebar-header" class="flex items-center justify-between px-2">
<?php
if (sizeof(phpb_active_languages()) > 1):
?>
<div id="language-selector">
<select class="selectpicker" data-width="fit">
<div id="language-selector" class="ml-auto">
<select class="select select-bordered select-xs text-xs">
<?php
foreach (phpb_active_languages() as $languageCode => $languageTranslation):
?>
<option value="<?= phpb_e($languageCode) ?>" <?= $languageCode === $currentLanguage ? 'selected' : '' ?>
data-content='<span class="flag-icon flag-icon-<?= phpb_e($languageCode) ?>"></span><span class="language-name ml-1"><?= phpb_e($languageTranslation) ?></span>'>
>
<?= phpb_e($languageTranslation) ?>
<option value="<?= phpb_e($languageCode) ?>" <?= $languageCode === $currentLanguage ? 'selected' : '' ?>>
<?= phpb_e(strtoupper($languageCode)) ?> - <?= phpb_e($languageTranslation) ?>
</option>
<?php
endforeach;
@@ -130,38 +125,27 @@ require __DIR__ . '/grapesjs/trait-manager.php';
<?php
endif;
?>
<style>
<?php
foreach (phpb_active_languages() as $languageCode => $languageTranslation):
?>
.flag-icon-<?= $languageCode ?> {
background-image: url(<?= phpb_asset('pagebuilder/images/flags/' . $languageCode . '.svg') ?>);
}
<?php
endforeach;
?>
</style>
</div>
<div id="sidebar-bottom-buttons">
<button id="save-page" class="btn" data-url="<?= phpb_url('pagebuilder', ['action' => 'store', 'page' => $page->getId()]) ?>">
<span class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
<div id="sidebar-bottom-buttons" class="flex items-center justify-between">
<button id="save-page" class="btn btn-sm btn-success flex-1 rounded-none text-white gap-2" data-url="<?= phpb_url('pagebuilder', ['action' => 'store', 'page' => $page->getId()]) ?>">
<span class="loading loading-spinner loading-xs d-none" role="status" aria-hidden="true"></span>
<i class="fa fa-save"></i>
<?= phpb_trans('pagebuilder.save-page') ?>
<span><?= phpb_trans('pagebuilder.save-page') ?></span>
</button>
<a id="view-page" href="<?= phpb_e(phpb_full_url($page->getRoute())) ?>" target="_blank" class="btn">
<a id="view-page" href="<?= phpb_e(phpb_full_url($page->getRoute())) ?>" target="_blank" class="btn btn-sm btn-info flex-1 rounded-none text-white gap-2">
<i class="fa fa-external-link"></i>
<?= phpb_trans('pagebuilder.view-page') ?>
<span><?= phpb_trans('pagebuilder.view-page') ?></span>
</a>
<a id="go-back" href="<?= phpb_e(phpb_full_url(phpb_config('pagebuilder.actions.back'))) ?>" class="btn">
<a id="go-back" href="<?= phpb_e(phpb_full_url(phpb_config('pagebuilder.actions.back'))) ?>" class="btn btn-sm btn-neutral flex-1 rounded-none text-white gap-2">
<i class="fa fa-arrow-circle-left"></i>
<?= phpb_trans('pagebuilder.go-back') ?>
<span><?= phpb_trans('pagebuilder.go-back') ?></span>
</a>
</div>
<div id="block-search">
<i class="fa fa-search"></i>
<input type="text" class="form-control" placeholder="<?= phpb_trans('pagebuilder.filter-placeholder') ?>">
<input type="text" class="input input-sm w-full" placeholder="<?= phpb_trans('pagebuilder.filter-placeholder') ?>">
</div>
@@ -6,3 +6,4 @@
@source "../../views";
@source "../../layouts";
@source "../../../../Auth/resources/views";
@source "../../../../GrapesJS/resources/views";