@innovastudio/contentbuilder 1.4.125 → 1.4.127

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.4.125",
4
+ "version": "1.4.127",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "files": [
@@ -1439,7 +1439,7 @@ class Util {
1439
1439
  const selection = this.builder.win.getSelection();
1440
1440
  const container = this.builder.dom.getElm();
1441
1441
  if (!container) return;
1442
- const sameSelection = container && container.innerText === selection.toString();
1442
+ const sameSelection = container && container.innerText === selection.toString().trim();
1443
1443
  if (sameSelection || selection.toString().trim() === '') {
1444
1444
  this.builder.selectionElm = container;
1445
1445
 
@@ -3395,7 +3395,7 @@ class Dom {
3395
3395
  if (callback) callback(false);
3396
3396
  return;
3397
3397
  }
3398
- const sameSelection = container && container.innerText === selection.toString();
3398
+ const sameSelection = container && container.innerText === selection.toString().trim();
3399
3399
  let newElement;
3400
3400
  if (sameSelection || selection.toString().trim() === '') {
3401
3401
  newElement = this.updateSelection(action, value, container);
@@ -3519,7 +3519,7 @@ class Dom {
3519
3519
  const selection = this.builder.win.getSelection();
3520
3520
  let container = this.getElm();
3521
3521
  if (!container) return;
3522
- const sameSelection = container && container.innerText === selection.toString();
3522
+ const sameSelection = container && container.innerText === selection.toString().trim();
3523
3523
  if (currentElement) {
3524
3524
  if (mode === 'block') if (this.getStyle(container, 'display') === 'inline') {
3525
3525
  container = this.getParentBlock(container);
@@ -3600,6 +3600,21 @@ class Dom {
3600
3600
  blocks.push(item);
3601
3601
  }
3602
3602
  });
3603
+
3604
+ /*
3605
+ If a block is double clicked to select the block, the selection goes to the next block as well.
3606
+ This seems a default behavior (tested with simple contentEditable div). So the blocks contains 2 blocks.
3607
+ To fix this, perform an extra test here:
3608
+ */
3609
+ if (blocks.length === 2) {
3610
+ // console.log(blocks[0].innerText.trim());
3611
+ // console.log(selection.toString().trim());
3612
+ if (blocks[0].innerText.trim() === selection.toString().trim()) {
3613
+ blocks.pop();
3614
+ // console.log('remove last')
3615
+ }
3616
+ }
3617
+
3603
3618
  if (multiSelectBlocks) {
3604
3619
  return blocks;
3605
3620
  } else {
@@ -3733,7 +3748,7 @@ class Dom {
3733
3748
  const selection = this.builder.win.getSelection();
3734
3749
  const container = this.getElm();
3735
3750
  if (!container) return;
3736
- const sameSelection = container && container.innerText === selection.toString();
3751
+ const sameSelection = container && container.innerText === selection.toString().trim();
3737
3752
  if (sameSelection || selection.toString().trim() === '') {
3738
3753
  this.updateSelectionToggle(action, value, config, container);
3739
3754
  } else {
@@ -4155,7 +4170,7 @@ class Dom {
4155
4170
  const anchorNode = selection.anchorNode;
4156
4171
  if (!anchorNode) return;
4157
4172
  const container = anchorNode.nodeType !== Node.TEXT_NODE && anchorNode.nodeType !== Node.COMMENT_NODE ? anchorNode : anchorNode.parentElement;
4158
- const sameSelection = container && container.innerText === selection.toString();
4173
+ const sameSelection = container && container.innerText === selection.toString().trim();
4159
4174
  if (sameSelection || selection.toString().trim() === '') {
4160
4175
  this.cleanElement(container);
4161
4176
  } else {
@@ -11311,6 +11326,7 @@ class UndoRedo {
11311
11326
  this.builder.opts.onRender();
11312
11327
  }
11313
11328
  saveForUndo(checkLater) {
11329
+ if (this.builder.onBeforeSaveForUndo) this.builder.onBeforeSaveForUndo();
11314
11330
  if (this.builder.undoRedoStyles) {
11315
11331
  if (this.undoList[120]) {
11316
11332
  let saves = this.undoList[120][0];
@@ -66285,7 +66301,7 @@ class Rte {
66285
66301
  } else if (num === '+' || num === '-') {
66286
66302
  for (let i = 0; i < Object.keys(classes).length; i++) {
66287
66303
  let className = Object.values(classes)[i];
66288
- if (dom.hasClass(container, className)) {
66304
+ if (container.closest('.' + className) && !container.classList.contains('is-builder')) {
66289
66305
  if (num === '+') {
66290
66306
  if (i + 1 === Object.keys(classes).length) return;
66291
66307
  newClassName = Object.values(classes)[i + 1];
@@ -79509,6 +79525,44 @@ class ContentBuilder {
79509
79525
  var lastNode = docFrag.lastChild;
79510
79526
  range.insertNode(docFrag);
79511
79527
  */
79528
+
79529
+ /*
79530
+ When selection is made by double clicking text (to select the entire block),
79531
+ the actual selection goes to the next block as well (default behavior, tested using a simple contentEditable div).
79532
+ To fix this, re-select the contents inside.
79533
+ */
79534
+
79535
+ const blocks = this.dom.getSelectedBlocks();
79536
+ const selection = this.win.getSelection();
79537
+
79538
+ /*
79539
+ Check same selection for the block first (this is more accurate than the sameSelection checking below).
79540
+ In case of double click (to select the entire block), for example, on this element:
79541
+ <h2 class="font-light size-54"><span class="size-24">Heading</span> 2 here</h2>
79542
+ The sameSelection checking below is failed, since the container = this.getElm() will return not the entire h2, but only
79543
+ <span class="size-24">Heading</span>
79544
+ So, blocks checking below is made to fix it.
79545
+ */
79546
+ let blockSelection = false;
79547
+ if (blocks.length === 1) {
79548
+ if (blocks[0].innerText.trim() === selection.toString().trim()) {
79549
+ let range = document.createRange();
79550
+ range.selectNodeContents(blocks[0]);
79551
+ selection.removeAllRanges();
79552
+ selection.addRange(range);
79553
+ blockSelection = true;
79554
+ }
79555
+ }
79556
+ if (!blockSelection) {
79557
+ const container = this.dom.getElm();
79558
+ const sameSelection = container && container.innerText === selection.toString().trim();
79559
+ if (sameSelection || selection.toString().trim() === '') {
79560
+ let range = document.createRange();
79561
+ range.selectNodeContents(container);
79562
+ selection.removeAllRanges();
79563
+ selection.addRange(range);
79564
+ }
79565
+ }
79512
79566
  document.execCommand('insertHTML', false, sPastedText);
79513
79567
  if (this.activeCol) {
79514
79568
  /*