lakelib 0.1.20 → 0.1.21

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/lib/lake.js CHANGED
@@ -676,14 +676,6 @@ class Nodes {
676
676
  }
677
677
  return true;
678
678
  }
679
- // Returns a boolean value indicating whether the node and the target node are siblings.
680
- isSibling(target) {
681
- if (this.length === 0) {
682
- return false;
683
- }
684
- const parent = this.get(0).parentNode;
685
- return parent && parent === target.parent().get(0);
686
- }
687
679
  // Gets a native node at the specified index.
688
680
  get(index) {
689
681
  return this.nodeList[index];
@@ -732,6 +724,23 @@ class Nodes {
732
724
  const element = this.get(0);
733
725
  return element.matches(selector);
734
726
  }
727
+ // Returns a boolean value indicating whether a node is a descendant of a given node, that is the node itself,
728
+ // one of its direct children (childNodes), one of the children's direct children, and so on.
729
+ contains(otherNode) {
730
+ if (otherNode instanceof Nodes) {
731
+ otherNode = otherNode.get(0);
732
+ }
733
+ const element = this.get(0);
734
+ return element.contains(otherNode);
735
+ }
736
+ // Returns a boolean value indicating whether the node and the target node are siblings.
737
+ isSibling(target) {
738
+ if (this.length === 0) {
739
+ return false;
740
+ }
741
+ const parent = this.get(0).parentNode;
742
+ return parent && parent === target.parent().get(0);
743
+ }
735
744
  // Returns the descendants of the first element which are selected by the specified CSS selector.
736
745
  find(selector) {
737
746
  if (typeof selector === 'string') {
@@ -5164,7 +5173,7 @@ function removeBox(range) {
5164
5173
  return box;
5165
5174
  }
5166
5175
 
5167
- var version = "0.1.20";
5176
+ var version = "0.1.21";
5168
5177
 
5169
5178
  // Returns the attributes of the element as an key-value object.
5170
5179
  function getAttributes(node) {
@@ -5256,6 +5265,9 @@ class Selection {
5256
5265
  // Updates the saved range with the range of the native selection.
5257
5266
  updateByRange() {
5258
5267
  const newRange = this.getRangeFromNativeSelection();
5268
+ if (!this.container.contains(newRange.commonAncestor)) {
5269
+ return;
5270
+ }
5259
5271
  if (this.range.startNode.get(0) === newRange.startNode.get(0) &&
5260
5272
  this.range.startOffset === newRange.startOffset &&
5261
5273
  this.range.endNode.get(0) === newRange.endNode.get(0) &&
@@ -5494,8 +5506,7 @@ class History {
5494
5506
  const box = getBox(nativeNode);
5495
5507
  box.getContainer().empty();
5496
5508
  });
5497
- if (range.commonAncestor.isOutside ||
5498
- range.commonAncestor.closestContainer().get(0) !== this.container.get(0)) {
5509
+ if (!this.container.contains(range.commonAncestor)) {
5499
5510
  return newContainer;
5500
5511
  }
5501
5512
  if (range.isInsideBox) {
@@ -5754,27 +5765,27 @@ class Editor {
5754
5765
  this.box = Editor.box;
5755
5766
  this.copyListener = event => {
5756
5767
  const range = this.selection.range;
5757
- if (range.commonAncestor.closestContainer().get(0) !== this.container.get(0)) {
5768
+ if (!this.container.contains(range.commonAncestor)) {
5758
5769
  return;
5759
5770
  }
5760
5771
  this.event.emit('copy', event);
5761
5772
  };
5762
5773
  this.cutListener = event => {
5763
5774
  const range = this.selection.range;
5764
- if (range.commonAncestor.closestContainer().get(0) !== this.container.get(0)) {
5775
+ if (!this.container.contains(range.commonAncestor)) {
5765
5776
  return;
5766
5777
  }
5767
5778
  this.event.emit('cut', event);
5768
5779
  };
5769
5780
  this.pasteListener = event => {
5770
5781
  const range = this.selection.range;
5771
- if (range.commonAncestor.closestContainer().get(0) !== this.container.get(0)) {
5782
+ if (!this.container.contains(range.commonAncestor)) {
5772
5783
  return;
5773
5784
  }
5774
5785
  this.event.emit('paste', event);
5775
5786
  };
5776
5787
  this.selectionchangeListener = () => {
5777
- this.selection.updateByRange();
5788
+ this.updateSelectionRange();
5778
5789
  this.updateBoxSelectionStyle();
5779
5790
  this.emitStateChangeEvent();
5780
5791
  };
@@ -5788,6 +5799,11 @@ class Editor {
5788
5799
  this.resizeListener = () => {
5789
5800
  this.event.emit('resize');
5790
5801
  };
5802
+ this.updateSelectionRange = debounce(() => {
5803
+ this.selection.updateByRange();
5804
+ }, 1, {
5805
+ immediate: true,
5806
+ });
5791
5807
  // Updates the classes of all boxes when the current selection of the editor is changed.
5792
5808
  this.updateBoxSelectionStyle = debounce(() => {
5793
5809
  // The editor has been unmounted.
@@ -5840,8 +5856,7 @@ class Editor {
5840
5856
  this.emitStateChangeEvent = debounce(() => {
5841
5857
  const commandNames = this.command.getNames();
5842
5858
  let appliedItems = this.selection.getAppliedItems();
5843
- if (appliedItems.length > 0 &&
5844
- appliedItems[0].node.closestContainer().get(0) !== this.container.get(0)) {
5859
+ if (appliedItems.length > 0 && !this.container.contains(appliedItems[0].node)) {
5845
5860
  appliedItems = [];
5846
5861
  }
5847
5862
  const disabledNameMap = new Map();
@@ -6938,6 +6953,10 @@ class Toolbar {
6938
6953
  tabIndex: -1,
6939
6954
  onClick: () => {
6940
6955
  editor.focus();
6956
+ const range = editor.selection.range;
6957
+ if (!editor.container.contains(range.commonAncestor)) {
6958
+ range.shrinkAfter(editor.container);
6959
+ }
6941
6960
  item.onClick(editor, item.name);
6942
6961
  },
6943
6962
  });
@@ -9122,11 +9141,11 @@ var formatPainter = (editor) => {
9122
9141
  markList = [];
9123
9142
  editor.history.save();
9124
9143
  });
9125
- editor.event.on('click', (tagetNode) => {
9126
- if (tagetNode.isInside && tagetNode.closestContainer().get(0) === editor.container.get(0)) {
9144
+ editor.event.on('click', (targetNode) => {
9145
+ if (editor.container.contains(targetNode)) {
9127
9146
  return;
9128
9147
  }
9129
- const buttonNode = tagetNode.closest('button[name="formatPainter"]');
9148
+ const buttonNode = targetNode.closest('button[name="formatPainter"]');
9130
9149
  if (buttonNode.length > 0) {
9131
9150
  return;
9132
9151
  }
@@ -9420,9 +9439,7 @@ var link = (editor) => {
9420
9439
  popup.hide();
9421
9440
  return;
9422
9441
  }
9423
- if (linkNode.isOutside ||
9424
- linkNode.closestContainer().get(0) !== editor.container.get(0) ||
9425
- linkNode.closest('lake-box').length > 0) {
9442
+ if (!editor.container.contains(linkNode) || linkNode.closest('lake-box').length > 0) {
9426
9443
  popup.hide();
9427
9444
  return;
9428
9445
  }