@innovastudio/contentbox 1.2.0 → 1.2.3

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbox",
3
- "version": "1.2.0",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "main": "public/contentbox/contentbox.esm.js",
6
6
  "files": [
@@ -39,7 +39,7 @@
39
39
  "webpack-dev-server": "^4.0.0"
40
40
  },
41
41
  "dependencies": {
42
- "@innovastudio/contentbuilder": "^1.1.3",
42
+ "@innovastudio/contentbuilder": "^1.1.7",
43
43
  "axios": "^0.21.4",
44
44
  "cors": "^2.8.5",
45
45
  "express": "^4.17.1",
@@ -14967,6 +14967,11 @@ class Util {
14967
14967
  } // LATER: auto scroll
14968
14968
  // LATER: If image, then it needs time to load (resulting incorrect position), so hide element tool.
14969
14969
 
14970
+ }
14971
+
14972
+ if (this.builder.useCssClasses) {
14973
+ let builderActive = document.querySelector('.builder-active');
14974
+ if (builderActive) dom.contentReformat(builderActive, this.builder.cssClasses);
14970
14975
  } // Call onChange
14971
14976
 
14972
14977
 
@@ -15195,6 +15200,11 @@ class Util {
15195
15200
 
15196
15201
  columnTool = document.querySelector('.is-column-tool');
15197
15202
  columnTool.className = columnTool.className.replace('active', '');
15203
+ }
15204
+
15205
+ if (this.builder.useCssClasses) {
15206
+ let builderActive = document.querySelector('.builder-active');
15207
+ if (builderActive) dom.contentReformat(builderActive, this.builder.cssClasses);
15198
15208
  } // Call onChange
15199
15209
 
15200
15210
 
@@ -18188,39 +18198,6 @@ class Dom {
18188
18198
  if (!removeEmptyStyleChildren || removeEmptyStyleChildren.length <= 0) {
18189
18199
  return;
18190
18200
  }
18191
- }
18192
-
18193
- cleanEmptySpans(area) {
18194
- let spans = area.querySelectorAll('span');
18195
- const filter = Array.prototype.filter;
18196
- let children = filter.call(spans, element => {
18197
- return element.attributes.length === 0;
18198
- }); // Remove empty spans
18199
-
18200
- if (children && children.length > 0) {
18201
- children.forEach(element => {
18202
- element.outerHTML = element.innerHTML;
18203
- });
18204
- } // Remove spans which have empty content
18205
-
18206
-
18207
- spans = area.querySelectorAll('span');
18208
- filter.call(spans, element => {
18209
- if (element.innerHTML === '') {
18210
- element.parentNode.removeChild(element);
18211
- }
18212
- }); // Recheck
18213
-
18214
- spans = area.querySelectorAll('span');
18215
- children = filter.call(spans, element => {
18216
- return element.attributes.length === 0;
18217
- });
18218
-
18219
- if (children && children.length > 0) {
18220
- this.cleanEmptySpans(area);
18221
- } else {
18222
- return;
18223
- }
18224
18201
  } // Font Size stuff
18225
18202
 
18226
18203
 
@@ -18297,7 +18274,7 @@ class Dom {
18297
18274
  }
18298
18275
  });
18299
18276
  });
18300
- this.cleanUnusedSpan(elm); // causes lost selection
18277
+ this.cleanUnusedSpan(elm); // REVIEW (causes lost selection)
18301
18278
  }
18302
18279
 
18303
18280
  cleanSelection(selection) {
@@ -18309,40 +18286,148 @@ class Dom {
18309
18286
  selection.selectAllChildren(span);
18310
18287
  this.cleanElement(span);
18311
18288
  }
18312
-
18289
+ /*
18313
18290
  cleanUnusedSpan(span) {
18314
- if (!span.hasChildNodes()) {
18315
- return;
18316
- } // Direct children with no style
18317
-
18318
-
18319
- const children = Array.from(span.children).filter(element => {
18320
- if (element.getAttribute('style') === '' || element.style === null) {
18321
- element.removeAttribute('style');
18291
+ if (!span.hasChildNodes()) {
18292
+ return;
18322
18293
  }
18294
+ // Direct children with no style
18295
+ const children = Array.from(span.children).filter((element) => {
18296
+ if (element.getAttribute('style') === '' || element.style === null) {
18297
+ element.removeAttribute('style');
18298
+ }
18299
+ let unused = ( element.attributes.length === 0 || (element.attributes.length === 1 && element.hasAttribute('data-keep')));
18300
+ return (element.nodeName.toLowerCase() === 'span' && unused);
18301
+ });
18302
+ if (children && children.length > 0) {
18303
+ children.forEach((element) => {
18304
+ const text = document.createTextNode(element.textContent);
18305
+ element.parentElement.replaceChild(text, element);
18306
+ });
18307
+ return;
18308
+ }
18309
+ // Deeper childrens
18310
+ const cleanUnusedSpanChildren = Array.from(span.children).map((element) => {
18311
+ return this.cleanUnusedSpan(element);
18312
+ });
18313
+ if (!cleanUnusedSpanChildren || cleanUnusedSpanChildren.length <= 0) {
18314
+ return;
18315
+ }
18316
+ }
18317
+ */
18323
18318
 
18324
- let unused = element.attributes.length === 0 || element.attributes.length === 1 && element.hasAttribute('data-keep');
18325
- return element.nodeName.toLowerCase() === 'span' && unused;
18326
- });
18319
+
18320
+ cleanUnusedSpan(area) {
18321
+ let spans = area.querySelectorAll('span');
18322
+ const filter = Array.prototype.filter;
18323
+ let children = filter.call(spans, element => {
18324
+ return element.attributes.length === 0;
18325
+ }); // Remove empty spans
18327
18326
 
18328
18327
  if (children && children.length > 0) {
18329
18328
  children.forEach(element => {
18330
- const text = document.createTextNode(element.textContent);
18331
- element.parentElement.replaceChild(text, element);
18329
+ element.outerHTML = element.innerHTML;
18332
18330
  });
18333
- return;
18334
- } // Deeper childrens
18331
+ } // Remove spans which have empty content
18332
+
18335
18333
 
18334
+ spans = area.querySelectorAll('span');
18335
+ filter.call(spans, element => {
18336
+ if (element.innerHTML === '') {
18337
+ element.parentNode.removeChild(element);
18338
+ }
18339
+ }); // Recheck
18336
18340
 
18337
- const cleanUnusedSpanChildren = Array.from(span.children).map(element => {
18338
- return this.cleanUnusedSpan(element);
18341
+ spans = area.querySelectorAll('span');
18342
+ children = filter.call(spans, element => {
18343
+ return element.attributes.length === 0;
18339
18344
  });
18340
18345
 
18341
- if (!cleanUnusedSpanChildren || cleanUnusedSpanChildren.length <= 0) {
18346
+ if (children && children.length > 0) {
18347
+ this.cleanUnusedSpan(area);
18348
+ } else {
18342
18349
  return;
18343
18350
  }
18344
18351
  }
18345
18352
 
18353
+ contentReformat(area, cssClasses) {
18354
+ this.replaceTag(area, 'b', cssClasses.fontWeight.defaultBold);
18355
+ this.replaceTag(area, 'i', cssClasses.fontStyle.italic);
18356
+ this.replaceTag(area, 'u', cssClasses.textDecoration.underline);
18357
+ this.replaceTag(area, 'strike', cssClasses.textDecoration.linethrough);
18358
+ this.replaceInline(area, 'font-weight', 'normal', cssClasses.fontWeight.defaultBold);
18359
+ this.replaceInline(area, 'font-weight', 'bold', cssClasses.fontWeight.defaultBold);
18360
+ this.replaceInline(area, 'font-weight', '600', cssClasses.fontWeight.semibold);
18361
+ this.replaceInline(area, 'text-align', 'left', cssClasses.textAlign.left);
18362
+ this.replaceInline(area, 'text-align', 'right', cssClasses.textAlign.right);
18363
+ this.replaceInline(area, 'text-align', 'center', cssClasses.textAlign.center);
18364
+ this.replaceInline(area, 'text-align', 'justify', cssClasses.textAlign.justify);
18365
+ this.replaceInline(area, 'display', 'flex', cssClasses.display.flex);
18366
+ this.replaceInline(area, 'justiify-content', 'flex-start', cssClasses.justifyContent.start);
18367
+ this.replaceInline(area, 'justiify-content', 'flex-end', cssClasses.justifyContent.end);
18368
+ this.replaceInline(area, 'justiify-content', 'center', cssClasses.justifyContent.center);
18369
+ this.replaceInline(area, 'justiify-content', 'space-between', cssClasses.justifyContent.between);
18370
+ this.replaceInline(area, 'flex-direction', 'column', cssClasses.flexDirection.column);
18371
+ this.replaceInline(area, 'flex-direction', 'row', cssClasses.flexDirection.row);
18372
+ this.replaceInline(area, 'align-items', 'flex-start', cssClasses.alignItems.start);
18373
+ this.replaceInline(area, 'align-items', 'flex-end', cssClasses.alignItems.end);
18374
+ this.replaceInline(area, 'align-items', 'center', cssClasses.alignItems.center);
18375
+ this.replaceInline(area, 'text-transform', 'uppercase', cssClasses.textTransform.uppercase);
18376
+ this.replaceInline(area, 'text-transform', 'lowercase', cssClasses.textTransform.lowercase);
18377
+ this.replaceInline(area, 'text-transform', 'none', cssClasses.textTransform.normal);
18378
+ this.replaceInline(area, 'line-height', '1', cssClasses.leading.leading_10);
18379
+ this.replaceInline(area, 'line-height', '1.1', cssClasses.leading.leading_11);
18380
+ this.replaceInline(area, 'line-height', '1.2', cssClasses.leading.leading_12);
18381
+ this.replaceInline(area, 'line-height', '1.25', cssClasses.leading.leading_125);
18382
+ this.replaceInline(area, 'line-height', '1.3', cssClasses.leading.leading_13);
18383
+ this.replaceInline(area, 'line-height', '1.375', cssClasses.leading.leading_1375);
18384
+ this.replaceInline(area, 'line-height', '1.4', cssClasses.leading.leading_14);
18385
+ this.replaceInline(area, 'line-height', '1.5', cssClasses.leading.leading_15);
18386
+ this.replaceInline(area, 'line-height', '1.6', cssClasses.leading.leading_16);
18387
+ this.replaceInline(area, 'line-height', '1.625', cssClasses.leading.leading_1625);
18388
+ this.replaceInline(area, 'line-height', '1.7', cssClasses.leading.leading_17);
18389
+ this.replaceInline(area, 'line-height', '1.8', cssClasses.leading.leading_18);
18390
+ this.replaceInline(area, 'line-height', '1.9', cssClasses.leading.leading_19);
18391
+ this.replaceInline(area, 'line-height', '2', cssClasses.leading.leading_20);
18392
+ this.replaceInline(area, 'line-height', '2.1', cssClasses.leading.leading_21);
18393
+ this.replaceInline(area, 'line-height', '2.2', cssClasses.leading.leading_22);
18394
+ }
18395
+
18396
+ replaceTag(area, tag, className) {
18397
+ let elms = area.querySelectorAll(tag);
18398
+ const filter = Array.prototype.filter;
18399
+ let children = filter.call(elms, element => {
18400
+ return element.attributes.length === 0;
18401
+ });
18402
+
18403
+ if (children && children.length > 0) {
18404
+ children.forEach(element => {
18405
+ const span = document.createElement('span');
18406
+ span.setAttribute('class', className);
18407
+ span.innerHTML = element.innerHTML;
18408
+ element.outerHTML = span.outerHTML;
18409
+ });
18410
+ }
18411
+ }
18412
+
18413
+ replaceInline(builder, css, value, className) {
18414
+ let elms = builder.querySelectorAll('*');
18415
+ elms.forEach(elm => {
18416
+ if (css === 'justiify-content') {
18417
+ /*
18418
+ For some reason, cannot use elm.style[css] for 'justify-content'
18419
+ */
18420
+ if (elm.style.justifyContent === `${value}`) {
18421
+ this.addClass(elm, className);
18422
+ elm.style.justifyContent = '';
18423
+ }
18424
+ } else if (elm.style[css] === `${value}`) {
18425
+ this.addClass(elm, className);
18426
+ elm.style[css] = '';
18427
+ }
18428
+ });
18429
+ }
18430
+
18346
18431
  }
18347
18432
 
18348
18433
  var js$1 = {exports: {}};
@@ -23912,7 +23997,7 @@ class HtmlUtil {
23912
23997
  } // Clean unused spans
23913
23998
 
23914
23999
 
23915
- dom$I.cleanUnusedSpan(content);
24000
+ dom$I.cleanUnusedSpan(content); // REVIEW
23916
24001
  }
23917
24002
 
23918
24003
  const util = this.builder.util;
@@ -26096,18 +26181,31 @@ const renderQuickAdd = builder => {
26096
26181
  elm = quickadd.querySelector('.add-button');
26097
26182
  if (elm) dom$F.addEventListener(elm, 'click', () => {
26098
26183
  const mode = quickadd.getAttribute('data-mode');
26099
- const html = `<div>
26184
+ let html = `<div>
26100
26185
  <a href="#" class="transition-all inline-block cursor-pointer no-underline border-2 border-solid border-transparent ml-1 mr-1 hover:border-transparent rounded bg-gray-200 hover:bg-gray-300 tracking-75 uppercase py-2 size-14 px-8 font-semibold text-gray-600">Read More</a>
26101
26186
  </div>`;
26187
+
26188
+ if (builder.opts.emailMode) {
26189
+ html = '<div><a href="#" style="margin-top: ;margin-right: ;margin-bottom: ;margin-left: ;display: inline-block; text-decoration: none; transition: all 0.16s ease 0s; border-style: solid; cursor: pointer; background-color: rgb(220, 220, 220); color: rgb(0, 0, 0); border-color: rgb(220, 220, 220); border-width: 2px; border-radius: 0px; padding: 13px 28px; line-height: 21px; text-transform: uppercase; font-weight: 400; font-size: 14px; letter-spacing: 3px;">Read More</a></div>';
26190
+ }
26191
+
26102
26192
  util.addContent(html, mode);
26103
26193
  });
26104
26194
  elm = quickadd.querySelector('.add-twobutton');
26105
26195
  if (elm) dom$F.addEventListener(elm, 'click', () => {
26106
26196
  const mode = quickadd.getAttribute('data-mode');
26107
- const html = `<div>
26197
+ let html = `<div>
26108
26198
  <a href="#" class="transition-all inline-block cursor-pointer no-underline border-2 border-solid border-transparent ml-1 mr-1 hover:border-transparent rounded bg-gray-200 hover:bg-gray-300 tracking-75 uppercase py-2 size-14 px-8 font-semibold text-gray-600">Read More</a>
26109
26199
  <a href="#" class="transition-all inline-block cursor-pointer no-underline border-2 border-solid ml-1 mr-1 rounded tracking-75 uppercase py-2 size-14 px-8 border-current hover:border-transparent hover:text-white font-semibold text-indigo-500 hover:bg-indigo-500">Get Started</a>
26110
26200
  </div>`;
26201
+
26202
+ if (builder.opts.emailMode) {
26203
+ html = `<div>
26204
+ <a href="#" style="margin-top: ;margin-right: ;margin-bottom: ;margin-left: ;display: inline-block; text-decoration: none; transition: all 0.16s ease 0s; border-style: solid; cursor: pointer; background-color: rgb(220, 220, 220); color: rgb(0, 0, 0); border-color: rgb(220, 220, 220); border-width: 2px; border-radius: 0px; padding: 13px 28px; line-height: 21px; text-transform: uppercase; font-weight: 400; font-size: 14px; letter-spacing: 3px;">Read More</a> &nbsp;
26205
+ <a href="#" style="display: inline-block; text-decoration: none; transition: all 0.16s ease 0s; border-style: solid; cursor: pointer; background-color: rgba(0, 0, 0, 0); border-color: rgb(53, 53, 53); border-width: 2px; border-radius: 0px; padding: 13px 28px; line-height: 21px; text-transform: uppercase; font-weight: 600; font-size: 14px; letter-spacing: 3px; color: rgb(53, 53, 53);">Get Started</a>
26206
+ </div>`;
26207
+ }
26208
+
26111
26209
  util.addContent(html, mode);
26112
26210
  });
26113
26211
  elm = quickadd.querySelector('.add-spacer');
@@ -76554,12 +76652,6 @@ class ContentBuilder {
76554
76652
  defaultBold: 'font-semibold',
76555
76653
  defaultNormal: 'font-light'
76556
76654
  },
76557
- textAlign: {
76558
- left: 'text-left',
76559
- center: 'text-center',
76560
- right: 'text-right',
76561
- justify: 'text-justify'
76562
- },
76563
76655
  fontStyle: {
76564
76656
  italic: 'italic',
76565
76657
  normal: 'not-italic'
@@ -76765,6 +76857,12 @@ class ContentBuilder {
76765
76857
  superscript: 'sup',
76766
76858
  subscript: 'sub'
76767
76859
  },
76860
+ textAlign: {
76861
+ left: 'text-left',
76862
+ center: 'text-center',
76863
+ right: 'text-right',
76864
+ justify: 'text-justify'
76865
+ },
76768
76866
  display: {
76769
76867
  flex: 'flex',
76770
76868
  block: 'block',
@@ -76798,7 +76896,8 @@ class ContentBuilder {
76798
76896
  stretch: 'items-stretch'
76799
76897
  }
76800
76898
  },
76801
- useCssClasses: false
76899
+ useCssClasses: true,
76900
+ useButtonPlugin: false
76802
76901
  }; // obj.preserveSelection = true; (can be set programmatically) to prevent click that clears selection on external custom modal.
76803
76902
 
76804
76903
  this.opts = Object.assign(this, defaults, opts);
@@ -76861,16 +76960,19 @@ class ContentBuilder {
76861
76960
  this.opts.onMediaUpload = this.opts.onLargerImageUpload;
76862
76961
  } else if (this.opts.onMediaUpload) {
76863
76962
  this.opts.onLargerImageUpload = this.opts.onMediaUpload;
76864
- } // Check if button editor plugin is used
76963
+ } // useButtonPlugin
76865
76964
 
76866
76965
 
76867
- const plugins = this.plugins;
76868
- this.useButtonPlugin = false;
76966
+ if (this.opts.emailMode) {
76967
+ this.useButtonPlugin = true;
76968
+ }
76869
76969
 
76870
- for (let i = 0; i < plugins.length; i++) {
76871
- if (plugins[i].name === 'buttoneditor') {
76872
- this.useButtonPlugin = true;
76873
- }
76970
+ if (!this.useButtonPlugin) {
76971
+ let _arr = this.plugins.filter(item => {
76972
+ return item.name !== 'buttoneditor';
76973
+ });
76974
+
76975
+ this.plugins = [..._arr];
76874
76976
  } // Alternative settions to define css grid frameworks
76875
76977
 
76876
76978
 
@@ -77292,6 +77394,8 @@ class ContentBuilder {
77292
77394
  const builders = document.querySelectorAll(this.opts.container);
77293
77395
  Array.prototype.forEach.call(builders, builder => {
77294
77396
  this.applyBehaviorOn(builder); // includes setZoomOnControl
77397
+
77398
+ this.contentReformatOn(builder);
77295
77399
  }); // Call onRender to indicate content is ready for editing (applyBehavior has been applied)
77296
77400
 
77297
77401
  this.opts.onRender();
@@ -77299,6 +77403,10 @@ class ContentBuilder {
77299
77403
  } // applyBehavior
77300
77404
 
77301
77405
 
77406
+ contentReformatOn(builder) {
77407
+ if (this.opts.useCssClasses) dom$J.contentReformat(builder, this.opts.cssClasses);
77408
+ }
77409
+
77302
77410
  applyBehaviorOn(builder) {
77303
77411
  const util = this.util; //Make absolute
77304
77412
 
@@ -80756,10 +80864,6 @@ class ContentBox {
80756
80864
  name: 'symbols',
80757
80865
  showInMainToolbar: true,
80758
80866
  showInElementToolbar: false
80759
- }, {
80760
- name: 'buttoneditor',
80761
- showInMainToolbar: false,
80762
- showInElementToolbar: false
80763
80867
  }],
80764
80868
  disableConfig: false,
80765
80869
  useLightbox: true,
@@ -80848,7 +80952,6 @@ class ContentBox {
80848
80952
  undoContainerOnly: false,
80849
80953
  absolutePath: false,
80850
80954
  maxEmbedImageWidth: 1600,
80851
- useCssClasses: false,
80852
80955
  zoom: 0.6,
80853
80956
  contentStyleWithSample: false,
80854
80957
  contentSizes: [300, 320, 340, 360, 380, 400, 420, 440, 460, 480, 500, 520, 540, 560, 580, 600, 620, 640, 660, 680, 700, 720, 740, 760, 780, 800, 820, 840, 860, 880, 900, 920, 940, 960, 970, 980, 1000, 1020, 1040, 1050, 1060, 1080, 1100, 1120, 1140, 1160, 1180, 1200, 1220, 1240, 1260, 1280, 1300, 1320, 1340, 1360, 1380, 1400, 1420, 1440, 1460, 1480, 1500, 1520, 1540, 1560, 1580, 1600, 1620, 1640, 1660, 1680, 1700, 1720, 1740, 1760, 1780, 1800, 1820, 1840, 1860, 1880, 1900, 1920, 1940, 1960, 1980, 2000, 2020, 2040, 2060, 2080, 2100, 2120, 2140, 2160, 2180, 2200, 2220, 2240, 2260, 2280, 2300, 2320, 2340, 2360, 2380, 2400, 2420, 2440, 2460, 2480, 2500, 2520, 2540, 2560, 2580, 2600, 2620, 2640, 2660, 2680, 2700],
@@ -82799,6 +82902,8 @@ class ContentBox {
82799
82902
  }
82800
82903
  },
82801
82904
  cssInBody: false,
82905
+ useCssClasses: true,
82906
+ useButtonPlugin: false,
82802
82907
 
82803
82908
  /* Old Version (backward compatible) */
82804
82909
  onAddSectionOpen: function () {},
@@ -83024,6 +83129,7 @@ class ContentBox {
83024
83129
  undoContainerOnly: this.settings.undoContainerOnly,
83025
83130
  absolutePath: this.settings.absolutePath,
83026
83131
  useCssClasses: this.settings.useCssClasses,
83132
+ useButtonPlugin: this.settings.useButtonPlugin,
83027
83133
  zoom: this.settings.zoom,
83028
83134
  onZoomStart: () => {
83029
83135
  // const wrapper = this.wrapperEl;