@innovastudio/contentbuilder 1.4.125 → 1.4.126

Sign up to get free protection for your applications and to get access to all the features.
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.126",
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 {
@@ -66285,7 +66300,7 @@ class Rte {
66285
66300
  } else if (num === '+' || num === '-') {
66286
66301
  for (let i = 0; i < Object.keys(classes).length; i++) {
66287
66302
  let className = Object.values(classes)[i];
66288
- if (dom.hasClass(container, className)) {
66303
+ if (container.closest('.' + className) && !container.classList.contains('is-builder')) {
66289
66304
  if (num === '+') {
66290
66305
  if (i + 1 === Object.keys(classes).length) return;
66291
66306
  newClassName = Object.values(classes)[i + 1];
@@ -79509,6 +79524,44 @@ class ContentBuilder {
79509
79524
  var lastNode = docFrag.lastChild;
79510
79525
  range.insertNode(docFrag);
79511
79526
  */
79527
+
79528
+ /*
79529
+ When selection is made by double clicking text (to select the entire block),
79530
+ the actual selection goes to the next block as well (default behavior, tested using a simple contentEditable div).
79531
+ To fix this, re-select the contents inside.
79532
+ */
79533
+
79534
+ const blocks = this.dom.getSelectedBlocks();
79535
+ const selection = this.win.getSelection();
79536
+
79537
+ /*
79538
+ Check same selection for the block first (this is more accurate than the sameSelection checking below).
79539
+ In case of double click (to select the entire block), for example, on this element:
79540
+ <h2 class="font-light size-54"><span class="size-24">Heading</span> 2 here</h2>
79541
+ The sameSelection checking below is failed, since the container = this.getElm() will return not the entire h2, but only
79542
+ <span class="size-24">Heading</span>
79543
+ So, blocks checking below is made to fix it.
79544
+ */
79545
+ let blockSelection = false;
79546
+ if (blocks.length === 1) {
79547
+ if (blocks[0].innerText.trim() === selection.toString().trim()) {
79548
+ let range = document.createRange();
79549
+ range.selectNodeContents(blocks[0]);
79550
+ selection.removeAllRanges();
79551
+ selection.addRange(range);
79552
+ blockSelection = true;
79553
+ }
79554
+ }
79555
+ if (!blockSelection) {
79556
+ const container = this.dom.getElm();
79557
+ const sameSelection = container && container.innerText === selection.toString().trim();
79558
+ if (sameSelection || selection.toString().trim() === '') {
79559
+ let range = document.createRange();
79560
+ range.selectNodeContents(container);
79561
+ selection.removeAllRanges();
79562
+ selection.addRange(range);
79563
+ }
79564
+ }
79512
79565
  document.execCommand('insertHTML', false, sPastedText);
79513
79566
  if (this.activeCol) {
79514
79567
  /*