@innovastudio/contentbuilder 1.3.81 → 1.3.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbuilder",
3
3
  "type": "module",
4
- "version": "1.3.81",
4
+ "version": "1.3.82",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "files": [
@@ -15048,6 +15048,79 @@ class HtmlUtil {
15048
15048
  block.getAttribute('data-settings', uniqueID);
15049
15049
  }
15050
15050
  });
15051
+ } //Make absolute (for Export/Download)
15052
+
15053
+
15054
+ if (this.builder.makeAbsolute) {
15055
+ const convertMediaUrl = imgUrl => {
15056
+ // make absolute
15057
+ let img = document.createElement('img');
15058
+ img.src = imgUrl;
15059
+ img.setAttribute('data-absoluteurl', img.src);
15060
+ imgUrl = img.getAttribute('data-absoluteurl');
15061
+ return imgUrl;
15062
+ };
15063
+
15064
+ const convertBgUrl = imgUrl => {
15065
+ // make absolute
15066
+ let img = document.createElement('img');
15067
+ img.src = imgUrl;
15068
+ img.setAttribute('data-absoluteurl', img.src);
15069
+ imgUrl = img.getAttribute('data-absoluteurl'); // Do not use imgUrl directly, change base to [%PATH%] instead
15070
+ // (to prevent auto converting back to relative path)
15071
+
15072
+ let urlBase = location.href.substring(0, location.href.lastIndexOf('/'));
15073
+ return imgUrl.replace(urlBase, '[%PATH%]'); // Example:
15074
+ // url = http://localhost:8080/uploads/image.jpg
15075
+ // urlBase = http://localhost:8080
15076
+ // become: [%PATH%]/uploads/image.jpg
15077
+ };
15078
+
15079
+ const convertMedia = (elm, attrName) => {
15080
+ if (elm.hasAttribute(attrName)) {
15081
+ if (!(elm.parentNode.tagName.toLowerCase() === 'video' || elm.parentNode.tagName.toLowerCase() === 'audio')) return;
15082
+ let imgUrl = elm.getAttribute(attrName);
15083
+ imgUrl = convertMediaUrl(imgUrl);
15084
+ elm.setAttribute(attrName, `${imgUrl}`);
15085
+ }
15086
+ };
15087
+
15088
+ let imgs = tmp.querySelectorAll('img');
15089
+ Array.prototype.forEach.call(imgs, img => {
15090
+ let src = img.src;
15091
+ img.setAttribute('src', src);
15092
+ });
15093
+ let elms = tmp.querySelectorAll('*');
15094
+ elms.forEach(elm => {
15095
+ if (elm.style.backgroundImage) {
15096
+ let s = elm.style.backgroundImage;
15097
+
15098
+ if (s.indexOf('url(') !== -1) {
15099
+ let imgUrl = s.slice(4, -1).replace(/["']/g, '');
15100
+ imgUrl = convertBgUrl(imgUrl);
15101
+ elm.style.backgroundImage = `url(${imgUrl})`;
15102
+ }
15103
+ }
15104
+
15105
+ convertMedia(elm, 'src');
15106
+ convertMedia(elm, 'data-default');
15107
+ convertMedia(elm, 'data-240');
15108
+ convertMedia(elm, 'data-360');
15109
+ convertMedia(elm, 'data-480');
15110
+ convertMedia(elm, 'data-540');
15111
+ convertMedia(elm, 'data-720');
15112
+ convertMedia(elm, 'data-1080');
15113
+ convertMedia(elm, 'data-1440');
15114
+ convertMedia(elm, 'data-2160');
15115
+
15116
+ if (elm.hasAttribute('href')) {
15117
+ if (elm.tagName.toLowerCase() === 'link') {
15118
+ let imgUrl = elm.getAttribute('href');
15119
+ imgUrl = convertMediaUrl(imgUrl);
15120
+ elm.setAttribute('href', `${imgUrl}`);
15121
+ }
15122
+ }
15123
+ });
15051
15124
  } //Cleaning
15052
15125
 
15053
15126
 
@@ -15316,6 +15389,13 @@ class HtmlUtil {
15316
15389
  return html;
15317
15390
  }
15318
15391
 
15392
+ beautify(html) {
15393
+ let beautify = JsBeautify.html;
15394
+ html = beautify(html);
15395
+ html = html.replace(/(\r\n|\r|\n){3,}/g, '$1\n');
15396
+ return html;
15397
+ }
15398
+
15319
15399
  }
15320
15400
 
15321
15401
  class UndoRedo {
@@ -15866,6 +15946,14 @@ const prepareSvgIcons = builder => {
15866
15946
  <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
15867
15947
  <path d="M9.88 9.878a3 3 0 1 0 4.243 4.242m.581 -3.42a3.012 3.012 0 0 0 -1.45 -1.426m-3.877 -3.913a9.469 9.469 0 0 1 2.623 -.361c4 0 7.333 2.333 10 7c-.778 1.362 -1.613 2.524 -2.504 3.489m-2.138 1.859c-1.629 1.101 -3.415 1.652 -5.358 1.652c-4 0 -7.333 -2.333 -10 -7c1.374 -2.404 2.924 -4.189 4.652 -5.354m-3.652 -3.646l18 18"></path>
15868
15948
  </symbol>
15949
+
15950
+ <symbol id="icon-download" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
15951
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
15952
+ <path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"></path>
15953
+ <path d="M7 11l5 5l5 -5"></path>
15954
+ <path d="M12 4l0 12"></path>
15955
+ </symbol>
15956
+
15869
15957
  </defs>
15870
15958
  </svg>`;
15871
15959
  builder.dom.appendHtml(builder.builderStuff, html);
@@ -22903,7 +22991,7 @@ function getOffset(element) {
22903
22991
  top: box.top + (window.pageYOffset - document.documentElement.clientTop)
22904
22992
  };
22905
22993
  }
22906
- var location = WINDOW.location;
22994
+ var location$1 = WINDOW.location;
22907
22995
  var REGEXP_ORIGINS = /^(\w+:)\/\/([^:/?#]*):?(\d*)/i;
22908
22996
  /**
22909
22997
  * Check if the given URL is a cross origin URL.
@@ -22913,7 +23001,7 @@ var REGEXP_ORIGINS = /^(\w+:)\/\/([^:/?#]*):?(\d*)/i;
22913
23001
 
22914
23002
  function isCrossOriginURL(url) {
22915
23003
  var parts = url.match(REGEXP_ORIGINS);
22916
- return parts !== null && (parts[1] !== location.protocol || parts[2] !== location.hostname || parts[3] !== location.port);
23004
+ return parts !== null && (parts[1] !== location$1.protocol || parts[2] !== location$1.hostname || parts[3] !== location$1.port);
22917
23005
  }
22918
23006
  /**
22919
23007
  * Add timestamp to the given URL.
@@ -53654,10 +53742,12 @@ class Code {
53654
53742
  viewhtml = this.builderStuff.querySelector('.viewhtml');
53655
53743
  }
53656
53744
 
53657
- let textarea = viewhtml.querySelector('textarea'); // Commented, to prevent {id} get formatted.
53658
- // let beautify = JsBeautify.html;
53659
- // html = beautify(html);
53745
+ let textarea = viewhtml.querySelector('textarea'); // Prevent {id} get formatted.
53660
53746
 
53747
+ html = html.replaceAll('{id}', '__id__');
53748
+ let beautify = JsBeautify.html;
53749
+ html = beautify(html);
53750
+ html = html.replaceAll('__id__', '{id}');
53661
53751
  textarea.value = html;
53662
53752
  this.htmlUtil.view('code');
53663
53753
  });
@@ -75241,6 +75331,39 @@ class ContentBuilder {
75241
75331
  </div>
75242
75332
  </div>
75243
75333
  `,
75334
+ pageTemplate: `<!DOCTYPE html>
75335
+ <html lang="en">
75336
+ <head>
75337
+ <meta charset="utf-8">
75338
+ <title>Page</title>
75339
+ <meta name="viewport" content="width=device-width, initial-scale=1">
75340
+ <meta name="description" content="">
75341
+ <link rel="shortcut icon" href="#" />
75342
+
75343
+ <link href="[%PATH%]/assets/minimalist-blocks/content.css" rel="stylesheet" type="text/css" />
75344
+
75345
+ <link href="[%PATH%]/assets/scripts/glide/css/glide.core.css" rel="stylesheet" type="text/css" />
75346
+ <link href="[%PATH%]/assets/scripts/glide/css/glide.theme.css" rel="stylesheet" type="text/css" />
75347
+ <script src="[%PATH%]/assets/scripts/glide/glide.js" type="text/javascript"></script>
75348
+
75349
+ <style>
75350
+ .container {
75351
+ margin: 150px auto 0;
75352
+ max-width: 800px;
75353
+ width: 100%;
75354
+ padding: 0 20px;
75355
+ box-sizing: border-box;
75356
+ }
75357
+ </style>
75358
+ </head>
75359
+ <body>
75360
+
75361
+ <div class="container">
75362
+ [%CONTENT%]
75363
+ </div>
75364
+
75365
+ </body>
75366
+ </html>`,
75244
75367
 
75245
75368
  /*
75246
75369
  onZoomStart: () => {
@@ -76752,7 +76875,11 @@ class ContentBuilder {
76752
76875
 
76753
76876
  const builders = this.doc.querySelectorAll(this.opts.container);
76754
76877
  Array.prototype.forEach.call(builders, builder => {
76755
- builder.innerHTML = htmlutil.readHtml(builder, true);
76878
+ // builder.innerHTML = htmlutil.readHtml(builder, true);
76879
+ let html = htmlutil.readHtml(builder, false);
76880
+ let range = this.doc.createRange();
76881
+ builder.innerHTML = '';
76882
+ builder.appendChild(range.createContextualFragment(html)); // Use createContextualFragment so that embedded javascript code (code block) will be executed
76756
76883
  });
76757
76884
  Array.prototype.forEach.call(builders, builder => {
76758
76885
  builder.removeAttribute('data-sort');
@@ -77079,6 +77206,46 @@ class ContentBuilder {
77079
77206
 
77080
77207
  saveForUndo(checkLater) {
77081
77208
  this.uo.saveForUndo(checkLater);
77209
+ }
77210
+
77211
+ download(options = {}) {
77212
+ let pageTemplate = this.pageTemplate;
77213
+ let output = ''; // [%CONTENT%]
77214
+
77215
+ this.makeAbsolute = true; //To make absolute (for Export/Download)
77216
+
77217
+ let html = this.html();
77218
+ this.makeAbsolute = false;
77219
+ output = pageTemplate.replace('[%CONTENT%]', html); // Custom
77220
+
77221
+ if (options.replace) {
77222
+ options.replace.forEach(rule => {
77223
+ output = output.replaceAll(`${rule[0]}`, rule[1]);
77224
+ });
77225
+ } // [%PATH%]
77226
+
77227
+
77228
+ if (options.path) {
77229
+ output = output.replaceAll('[%PATH%]', options.path);
77230
+ } else {
77231
+ let urlBase;
77232
+ urlBase = location.href.substring(0, location.href.lastIndexOf('/'));
77233
+ output = output.replaceAll('[%PATH%]', urlBase);
77234
+ } // Beautify
77235
+
77236
+
77237
+ output = this.beautify(output);
77238
+ const a = document.createElement('a');
77239
+ a.href = window.URL.createObjectURL(new Blob([output], {
77240
+ type: 'text/plain'
77241
+ }));
77242
+ a.download = 'page.html';
77243
+ a.click();
77244
+ }
77245
+
77246
+ beautify(html) {
77247
+ const htmlutil = new HtmlUtil(this);
77248
+ return htmlutil.beautify(html);
77082
77249
  } // Module related
77083
77250
 
77084
77251