@innovastudio/contentbuilder 1.1.4 → 1.1.7

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/contentbuilder",
3
- "version": "1.1.4",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "public/contentbuilder/contentbuilder.esm.js",
6
6
  "files": [
@@ -2093,11 +2093,11 @@ button:focus {
2093
2093
  position: fixed;
2094
2094
  overflow: hidden;
2095
2095
  width: 520px;
2096
- height: 720px;
2096
+ height: 686px;
2097
2097
  top: 50%;
2098
2098
  left: auto;
2099
2099
  right: 30%;
2100
- margin-top: -205px;
2100
+ margin-top: -383px;
2101
2101
  box-sizing: content-box;
2102
2102
  flex-direction: row;
2103
2103
  align-items: flex-start;
@@ -4513,6 +4513,11 @@ class Util {
4513
4513
  } // LATER: auto scroll
4514
4514
  // LATER: If image, then it needs time to load (resulting incorrect position), so hide element tool.
4515
4515
 
4516
+ }
4517
+
4518
+ if (this.builder.useCssClasses) {
4519
+ let builderActive = document.querySelector('.builder-active');
4520
+ if (builderActive) dom.contentReformat(builderActive, this.builder.cssClasses);
4516
4521
  } // Call onChange
4517
4522
 
4518
4523
 
@@ -4741,6 +4746,11 @@ class Util {
4741
4746
 
4742
4747
  columnTool = document.querySelector('.is-column-tool');
4743
4748
  columnTool.className = columnTool.className.replace('active', '');
4749
+ }
4750
+
4751
+ if (this.builder.useCssClasses) {
4752
+ let builderActive = document.querySelector('.builder-active');
4753
+ if (builderActive) dom.contentReformat(builderActive, this.builder.cssClasses);
4744
4754
  } // Call onChange
4745
4755
 
4746
4756
 
@@ -7734,39 +7744,6 @@ class Dom {
7734
7744
  if (!removeEmptyStyleChildren || removeEmptyStyleChildren.length <= 0) {
7735
7745
  return;
7736
7746
  }
7737
- }
7738
-
7739
- cleanEmptySpans(area) {
7740
- let spans = area.querySelectorAll('span');
7741
- const filter = Array.prototype.filter;
7742
- let children = filter.call(spans, element => {
7743
- return element.attributes.length === 0;
7744
- }); // Remove empty spans
7745
-
7746
- if (children && children.length > 0) {
7747
- children.forEach(element => {
7748
- element.outerHTML = element.innerHTML;
7749
- });
7750
- } // Remove spans which have empty content
7751
-
7752
-
7753
- spans = area.querySelectorAll('span');
7754
- filter.call(spans, element => {
7755
- if (element.innerHTML === '') {
7756
- element.parentNode.removeChild(element);
7757
- }
7758
- }); // Recheck
7759
-
7760
- spans = area.querySelectorAll('span');
7761
- children = filter.call(spans, element => {
7762
- return element.attributes.length === 0;
7763
- });
7764
-
7765
- if (children && children.length > 0) {
7766
- this.cleanEmptySpans(area);
7767
- } else {
7768
- return;
7769
- }
7770
7747
  } // Font Size stuff
7771
7748
 
7772
7749
 
@@ -7843,7 +7820,7 @@ class Dom {
7843
7820
  }
7844
7821
  });
7845
7822
  });
7846
- this.cleanUnusedSpan(elm); // causes lost selection
7823
+ this.cleanUnusedSpan(elm); // REVIEW (causes lost selection)
7847
7824
  }
7848
7825
 
7849
7826
  cleanSelection(selection) {
@@ -7855,40 +7832,148 @@ class Dom {
7855
7832
  selection.selectAllChildren(span);
7856
7833
  this.cleanElement(span);
7857
7834
  }
7858
-
7835
+ /*
7859
7836
  cleanUnusedSpan(span) {
7860
- if (!span.hasChildNodes()) {
7861
- return;
7862
- } // Direct children with no style
7863
-
7864
-
7865
- const children = Array.from(span.children).filter(element => {
7866
- if (element.getAttribute('style') === '' || element.style === null) {
7867
- element.removeAttribute('style');
7837
+ if (!span.hasChildNodes()) {
7838
+ return;
7839
+ }
7840
+ // Direct children with no style
7841
+ const children = Array.from(span.children).filter((element) => {
7842
+ if (element.getAttribute('style') === '' || element.style === null) {
7843
+ element.removeAttribute('style');
7844
+ }
7845
+ let unused = ( element.attributes.length === 0 || (element.attributes.length === 1 && element.hasAttribute('data-keep')));
7846
+ return (element.nodeName.toLowerCase() === 'span' && unused);
7847
+ });
7848
+ if (children && children.length > 0) {
7849
+ children.forEach((element) => {
7850
+ const text = document.createTextNode(element.textContent);
7851
+ element.parentElement.replaceChild(text, element);
7852
+ });
7853
+ return;
7854
+ }
7855
+ // Deeper childrens
7856
+ const cleanUnusedSpanChildren = Array.from(span.children).map((element) => {
7857
+ return this.cleanUnusedSpan(element);
7858
+ });
7859
+ if (!cleanUnusedSpanChildren || cleanUnusedSpanChildren.length <= 0) {
7860
+ return;
7868
7861
  }
7862
+ }
7863
+ */
7869
7864
 
7870
- let unused = element.attributes.length === 0 || element.attributes.length === 1 && element.hasAttribute('data-keep');
7871
- return element.nodeName.toLowerCase() === 'span' && unused;
7872
- });
7865
+
7866
+ cleanUnusedSpan(area) {
7867
+ let spans = area.querySelectorAll('span');
7868
+ const filter = Array.prototype.filter;
7869
+ let children = filter.call(spans, element => {
7870
+ return element.attributes.length === 0;
7871
+ }); // Remove empty spans
7873
7872
 
7874
7873
  if (children && children.length > 0) {
7875
7874
  children.forEach(element => {
7876
- const text = document.createTextNode(element.textContent);
7877
- element.parentElement.replaceChild(text, element);
7875
+ element.outerHTML = element.innerHTML;
7878
7876
  });
7879
- return;
7880
- } // Deeper childrens
7877
+ } // Remove spans which have empty content
7881
7878
 
7882
7879
 
7883
- const cleanUnusedSpanChildren = Array.from(span.children).map(element => {
7884
- return this.cleanUnusedSpan(element);
7880
+ spans = area.querySelectorAll('span');
7881
+ filter.call(spans, element => {
7882
+ if (element.innerHTML === '') {
7883
+ element.parentNode.removeChild(element);
7884
+ }
7885
+ }); // Recheck
7886
+
7887
+ spans = area.querySelectorAll('span');
7888
+ children = filter.call(spans, element => {
7889
+ return element.attributes.length === 0;
7885
7890
  });
7886
7891
 
7887
- if (!cleanUnusedSpanChildren || cleanUnusedSpanChildren.length <= 0) {
7892
+ if (children && children.length > 0) {
7893
+ this.cleanUnusedSpan(area);
7894
+ } else {
7888
7895
  return;
7889
7896
  }
7890
7897
  }
7891
7898
 
7899
+ contentReformat(area, cssClasses) {
7900
+ this.replaceTag(area, 'b', cssClasses.fontWeight.defaultBold);
7901
+ this.replaceTag(area, 'i', cssClasses.fontStyle.italic);
7902
+ this.replaceTag(area, 'u', cssClasses.textDecoration.underline);
7903
+ this.replaceTag(area, 'strike', cssClasses.textDecoration.linethrough);
7904
+ this.replaceInline(area, 'font-weight', 'normal', cssClasses.fontWeight.defaultBold);
7905
+ this.replaceInline(area, 'font-weight', 'bold', cssClasses.fontWeight.defaultBold);
7906
+ this.replaceInline(area, 'font-weight', '600', cssClasses.fontWeight.semibold);
7907
+ this.replaceInline(area, 'text-align', 'left', cssClasses.textAlign.left);
7908
+ this.replaceInline(area, 'text-align', 'right', cssClasses.textAlign.right);
7909
+ this.replaceInline(area, 'text-align', 'center', cssClasses.textAlign.center);
7910
+ this.replaceInline(area, 'text-align', 'justify', cssClasses.textAlign.justify);
7911
+ this.replaceInline(area, 'display', 'flex', cssClasses.display.flex);
7912
+ this.replaceInline(area, 'justiify-content', 'flex-start', cssClasses.justifyContent.start);
7913
+ this.replaceInline(area, 'justiify-content', 'flex-end', cssClasses.justifyContent.end);
7914
+ this.replaceInline(area, 'justiify-content', 'center', cssClasses.justifyContent.center);
7915
+ this.replaceInline(area, 'justiify-content', 'space-between', cssClasses.justifyContent.between);
7916
+ this.replaceInline(area, 'flex-direction', 'column', cssClasses.flexDirection.column);
7917
+ this.replaceInline(area, 'flex-direction', 'row', cssClasses.flexDirection.row);
7918
+ this.replaceInline(area, 'align-items', 'flex-start', cssClasses.alignItems.start);
7919
+ this.replaceInline(area, 'align-items', 'flex-end', cssClasses.alignItems.end);
7920
+ this.replaceInline(area, 'align-items', 'center', cssClasses.alignItems.center);
7921
+ this.replaceInline(area, 'text-transform', 'uppercase', cssClasses.textTransform.uppercase);
7922
+ this.replaceInline(area, 'text-transform', 'lowercase', cssClasses.textTransform.lowercase);
7923
+ this.replaceInline(area, 'text-transform', 'none', cssClasses.textTransform.normal);
7924
+ this.replaceInline(area, 'line-height', '1', cssClasses.leading.leading_10);
7925
+ this.replaceInline(area, 'line-height', '1.1', cssClasses.leading.leading_11);
7926
+ this.replaceInline(area, 'line-height', '1.2', cssClasses.leading.leading_12);
7927
+ this.replaceInline(area, 'line-height', '1.25', cssClasses.leading.leading_125);
7928
+ this.replaceInline(area, 'line-height', '1.3', cssClasses.leading.leading_13);
7929
+ this.replaceInline(area, 'line-height', '1.375', cssClasses.leading.leading_1375);
7930
+ this.replaceInline(area, 'line-height', '1.4', cssClasses.leading.leading_14);
7931
+ this.replaceInline(area, 'line-height', '1.5', cssClasses.leading.leading_15);
7932
+ this.replaceInline(area, 'line-height', '1.6', cssClasses.leading.leading_16);
7933
+ this.replaceInline(area, 'line-height', '1.625', cssClasses.leading.leading_1625);
7934
+ this.replaceInline(area, 'line-height', '1.7', cssClasses.leading.leading_17);
7935
+ this.replaceInline(area, 'line-height', '1.8', cssClasses.leading.leading_18);
7936
+ this.replaceInline(area, 'line-height', '1.9', cssClasses.leading.leading_19);
7937
+ this.replaceInline(area, 'line-height', '2', cssClasses.leading.leading_20);
7938
+ this.replaceInline(area, 'line-height', '2.1', cssClasses.leading.leading_21);
7939
+ this.replaceInline(area, 'line-height', '2.2', cssClasses.leading.leading_22);
7940
+ }
7941
+
7942
+ replaceTag(area, tag, className) {
7943
+ let elms = area.querySelectorAll(tag);
7944
+ const filter = Array.prototype.filter;
7945
+ let children = filter.call(elms, element => {
7946
+ return element.attributes.length === 0;
7947
+ });
7948
+
7949
+ if (children && children.length > 0) {
7950
+ children.forEach(element => {
7951
+ const span = document.createElement('span');
7952
+ span.setAttribute('class', className);
7953
+ span.innerHTML = element.innerHTML;
7954
+ element.outerHTML = span.outerHTML;
7955
+ });
7956
+ }
7957
+ }
7958
+
7959
+ replaceInline(builder, css, value, className) {
7960
+ let elms = builder.querySelectorAll('*');
7961
+ elms.forEach(elm => {
7962
+ if (css === 'justiify-content') {
7963
+ /*
7964
+ For some reason, cannot use elm.style[css] for 'justify-content'
7965
+ */
7966
+ if (elm.style.justifyContent === `${value}`) {
7967
+ this.addClass(elm, className);
7968
+ elm.style.justifyContent = '';
7969
+ }
7970
+ } else if (elm.style[css] === `${value}`) {
7971
+ this.addClass(elm, className);
7972
+ elm.style[css] = '';
7973
+ }
7974
+ });
7975
+ }
7976
+
7892
7977
  }
7893
7978
 
7894
7979
  var js$1 = {exports: {}};
@@ -13458,7 +13543,7 @@ class HtmlUtil {
13458
13543
  } // Clean unused spans
13459
13544
 
13460
13545
 
13461
- dom$I.cleanUnusedSpan(content);
13546
+ dom$I.cleanUnusedSpan(content); // REVIEW
13462
13547
  }
13463
13548
 
13464
13549
  const util = this.builder.util;
@@ -66113,12 +66198,6 @@ class ContentBuilder {
66113
66198
  defaultBold: 'font-semibold',
66114
66199
  defaultNormal: 'font-light'
66115
66200
  },
66116
- textAlign: {
66117
- left: 'text-left',
66118
- center: 'text-center',
66119
- right: 'text-right',
66120
- justify: 'text-justify'
66121
- },
66122
66201
  fontStyle: {
66123
66202
  italic: 'italic',
66124
66203
  normal: 'not-italic'
@@ -66324,6 +66403,12 @@ class ContentBuilder {
66324
66403
  superscript: 'sup',
66325
66404
  subscript: 'sub'
66326
66405
  },
66406
+ textAlign: {
66407
+ left: 'text-left',
66408
+ center: 'text-center',
66409
+ right: 'text-right',
66410
+ justify: 'text-justify'
66411
+ },
66327
66412
  display: {
66328
66413
  flex: 'flex',
66329
66414
  block: 'block',
@@ -66357,7 +66442,8 @@ class ContentBuilder {
66357
66442
  stretch: 'items-stretch'
66358
66443
  }
66359
66444
  },
66360
- useCssClasses: false
66445
+ useCssClasses: true,
66446
+ useButtonPlugin: false
66361
66447
  }; // obj.preserveSelection = true; (can be set programmatically) to prevent click that clears selection on external custom modal.
66362
66448
 
66363
66449
  this.opts = Object.assign(this, defaults, opts);
@@ -66420,16 +66506,19 @@ class ContentBuilder {
66420
66506
  this.opts.onMediaUpload = this.opts.onLargerImageUpload;
66421
66507
  } else if (this.opts.onMediaUpload) {
66422
66508
  this.opts.onLargerImageUpload = this.opts.onMediaUpload;
66423
- } // Check if button editor plugin is used
66509
+ } // useButtonPlugin
66510
+
66424
66511
 
66512
+ if (this.opts.emailMode) {
66513
+ this.useButtonPlugin = true;
66514
+ }
66425
66515
 
66426
- const plugins = this.plugins;
66427
- this.useButtonPlugin = false;
66516
+ if (!this.useButtonPlugin) {
66517
+ let _arr = this.plugins.filter(item => {
66518
+ return item.name !== 'buttoneditor';
66519
+ });
66428
66520
 
66429
- for (let i = 0; i < plugins.length; i++) {
66430
- if (plugins[i].name === 'buttoneditor') {
66431
- this.useButtonPlugin = true;
66432
- }
66521
+ this.plugins = [..._arr];
66433
66522
  } // Alternative settions to define css grid frameworks
66434
66523
 
66435
66524
 
@@ -66851,6 +66940,8 @@ class ContentBuilder {
66851
66940
  const builders = document.querySelectorAll(this.opts.container);
66852
66941
  Array.prototype.forEach.call(builders, builder => {
66853
66942
  this.applyBehaviorOn(builder); // includes setZoomOnControl
66943
+
66944
+ this.contentReformatOn(builder);
66854
66945
  }); // Call onRender to indicate content is ready for editing (applyBehavior has been applied)
66855
66946
 
66856
66947
  this.opts.onRender();
@@ -66858,6 +66949,10 @@ class ContentBuilder {
66858
66949
  } // applyBehavior
66859
66950
 
66860
66951
 
66952
+ contentReformatOn(builder) {
66953
+ if (this.opts.useCssClasses) dom.contentReformat(builder, this.opts.cssClasses);
66954
+ }
66955
+
66861
66956
  applyBehaviorOn(builder) {
66862
66957
  const util = this.util; //Make absolute
66863
66958