@innovastudio/contentbox 1.1.2 → 1.1.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.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "main": "public/contentbox/contentbox.esm.js",
6
6
  "files": [
@@ -38,7 +38,7 @@
38
38
  "webpack-dev-server": "^4.0.0"
39
39
  },
40
40
  "dependencies": {
41
- "@innovastudio/contentbuilder": "^1.0.82",
41
+ "@innovastudio/contentbuilder": "^1.0.83",
42
42
  "axios": "^0.21.4",
43
43
  "cors": "^2.8.5",
44
44
  "express": "^4.17.1",
@@ -50298,7 +50298,7 @@ class Image {
50298
50298
  // if(initialWidth <200 && initialHeight<200) {
50299
50299
 
50300
50300
 
50301
- if (initialWidth <= 1600 && initialHeight <= 1600) {
50301
+ if (initialWidth <= 1600 && initialHeight <= 1600 && this.builder.opts.maxEmbedImageWidth >= 1600) {
50302
50302
  let reader = new FileReader();
50303
50303
  reader.addEventListener('load', e => {
50304
50304
  if (!document.getElementById('__preview')) {
@@ -70669,12 +70669,6 @@ class ContentBuilder {
70669
70669
  for (let n = 0; n < elm.attributes.length; n++) {
70670
70670
  if (elm.attributes[n].name !== 'style') elm.removeAttribute(elm.attributes[n].name);
70671
70671
  }
70672
- }); // Extra:
70673
- // Remove li with white-space: pre;
70674
-
70675
- elms = contentword.querySelectorAll('li');
70676
- Array.prototype.forEach.call(elms, elm => {
70677
- elm.style.whiteSpace = '';
70678
70672
  });
70679
70673
  } else {
70680
70674
  //html-without-styles (default)
@@ -70688,14 +70682,26 @@ class ContentBuilder {
70688
70682
  Array.prototype.forEach.call(elms, elm => {
70689
70683
  removeAttributes(elm);
70690
70684
  });
70691
- } // NOTE: paste <h1><p> jadi nempel
70692
- // NOTE ($editor => contentword)
70693
- // if($editor.children('p,h1,h2,h3,h4,h5,h6,ul,li').length>1){
70694
- // //Fix text that doesn't have paragraph
70695
- // $editor.contents().filter(function() {
70696
- // return (this.nodeType === 3 && jQuery.trim(this.nodeValue)!=='');
70697
- // }).wrap( "<p></p>" ).end().filter("br").remove();
70698
- // }
70685
+ }
70686
+ /*
70687
+ Additional Cleanup:
70688
+ - Remove p inside li
70689
+ - Remove li with white-space: pre
70690
+ */
70691
+
70692
+
70693
+ let elms = contentword.querySelectorAll('li');
70694
+ Array.prototype.forEach.call(elms, elm => {
70695
+ elm.style.whiteSpace = '';
70696
+ const childNodes = elm.childNodes;
70697
+ let i = childNodes.length;
70698
+
70699
+ while (i--) {
70700
+ if (childNodes[i].tagName === 'P') {
70701
+ childNodes[i].outerHTML = childNodes[i].innerHTML;
70702
+ }
70703
+ }
70704
+ }); // NOTE: paste <h1><p> jadi nempel
70699
70705
  // // Source: https://gist.github.com/sbrin/6801034
70700
70706
  // jQuery('p', $editor).each(function(){
70701
70707
  // var str = jQuery(this).attr('style');
@@ -70748,16 +70754,12 @@ class ContentBuilder {
70748
70754
  // //jQuery("[class^='Mso']", $editor).removeAttr('class'); //done (see cleanHTML)
70749
70755
  // jQuery('p:empty', $editor).remove();
70750
70756
 
70751
-
70752
70757
  sPastedText = contentword.innerHTML;
70753
70758
  }
70754
70759
  }
70755
70760
 
70756
70761
  contentword = document.querySelector('#idContentWord');
70757
- if (contentword) contentword.parentNode.removeChild(contentword); // LATER
70758
- // jQuery('.cell-active').find('.elm-active').removeClass('elm-active');
70759
- // jQuery("#divElementTool").css("display", "none"); //force hide ellement tool
70760
-
70762
+ if (contentword) contentword.parentNode.removeChild(contentword);
70761
70763
  util.restoreSelection();
70762
70764
  var oSel = window.getSelection();
70763
70765
  var range = oSel.getRangeAt(0);
@@ -70765,16 +70767,80 @@ class ContentBuilder {
70765
70767
  range.collapse(true);
70766
70768
  var docFrag = range.createContextualFragment(sPastedText);
70767
70769
  var lastNode = docFrag.lastChild;
70768
- range.insertNode(docFrag); // // Fix HTML structure (Sometimes h1 can be pasted inside p)
70769
- // let elms = col.querySelectorAll('p,h1,h2,h3,h4,h5,h6');
70770
- // Array.prototype.forEach.call(elms, (elm) => {
70771
- // let elmswithin = elm.querySelectorAll('p,h1,h2,h3,h4,h5,h6');
70772
- // Array.prototype.forEach.call(elmswithin, (elmwithin) => {
70773
- // elmwithin.outerHTML = elmwithin.innerHTML;
70774
- // });
70775
- // });
70776
- // LATER
70777
- // $block.find('h1:empty,h2:empty,h3:empty,h4:empty,h5:empty,h6:empty,p:empty').remove();
70770
+ range.insertNode(docFrag);
70771
+
70772
+ if (this.activeCol) {
70773
+ /*
70774
+ Additional Cleanup:
70775
+ - Remove empty elements (empty p, etc)
70776
+ */
70777
+ // $block.find('h1:empty,h2:empty,h3:empty,h4:empty,h5:empty,h6:empty,p:empty').remove();
70778
+ this.activeCol.querySelectorAll('*:empty').forEach(x => {
70779
+ x.remove();
70780
+ });
70781
+ /*
70782
+ Additional Cleanup:
70783
+ Fix HTML structure. The problem:
70784
+ <p class="elm-active">
70785
+ ...Sometimes h1, h2, p can be pasted here..
70786
+ </p>
70787
+ */
70788
+
70789
+ let elmActive = this.activeCol.querySelector('p.elm-active,h1.elm-active,h2.elm-active,h3.elm-active,h4.elm-active,h5.elm-active,h6.elm-active');
70790
+
70791
+ if (elmActive) {
70792
+ let elms = elmActive.querySelectorAll('p,h1,h2,h3,h4,h5,h6');
70793
+
70794
+ if (elms.length > 0) {
70795
+ let elmClosestElement = elmActive.nextElementSibling; //Fix text that doesn't have paragraph
70796
+
70797
+ let textNodes = Array.from(elmActive.childNodes).filter(node => node.nodeType === 3 && node.textContent.trim().length > 1);
70798
+ textNodes.forEach(node => {
70799
+ const span = document.createElement('p');
70800
+ node.after(span);
70801
+ span.appendChild(node);
70802
+ });
70803
+
70804
+ if (elmActive.firstElementChild && elmActive.childNodes.length === 1) {
70805
+ if (elmActive.firstElementChild.tagName === 'SPAN') {
70806
+ // Paste HTML with styles
70807
+ elmActive.outerHTML = elmActive.firstElementChild.innerHTML; //fix
70808
+ // Re-clean empty elements
70809
+
70810
+ this.activeCol.querySelectorAll('*:empty').forEach(x => {
70811
+ x.remove();
70812
+ }); //place cursor
70813
+
70814
+ if (elmClosestElement) dom$F.moveCursorToElement(elmClosestElement.previousElementSibling);else dom$F.moveCursorToElement(this.activeCol);
70815
+ let builderActive = document.querySelector('.builder-active');
70816
+ if (builderActive) this.applyBehaviorOn(builderActive); //Trigger Change event
70817
+
70818
+ this.opts.onChange(); //Trigger Render event
70819
+
70820
+ this.opts.onRender();
70821
+ return;
70822
+ }
70823
+ } // Paste HTML without styles
70824
+
70825
+
70826
+ elmActive.outerHTML = elmActive.innerHTML; //fix
70827
+ // Re-clean empty elements
70828
+
70829
+ this.activeCol.querySelectorAll('*:empty').forEach(x => {
70830
+ x.remove();
70831
+ }); //place cursor
70832
+
70833
+ if (elmClosestElement) dom$F.moveCursorToElement(elmClosestElement.previousElementSibling);else dom$F.moveCursorToElement(this.activeCol);
70834
+ let builderActive = document.querySelector('.builder-active');
70835
+ if (builderActive) this.applyBehaviorOn(builderActive); //Trigger Change event
70836
+
70837
+ this.opts.onChange(); //Trigger Render event
70838
+
70839
+ this.opts.onRender();
70840
+ return;
70841
+ }
70842
+ }
70843
+ }
70778
70844
 
70779
70845
  range.setStartAfter(lastNode);
70780
70846
  range.setEndAfter(lastNode);