lakelib 0.1.19 → 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/dist/lake.min.js +18 -18
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.js +40 -22
- package/lib/lake.js.map +1 -1
- package/lib/types/editor.d.ts +1 -0
- package/lib/types/models/nodes.d.ts +2 -1
- package/package.json +1 -1
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.
|
|
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,7 +5506,7 @@ class History {
|
|
|
5494
5506
|
const box = getBox(nativeNode);
|
|
5495
5507
|
box.getContainer().empty();
|
|
5496
5508
|
});
|
|
5497
|
-
if (range.commonAncestor
|
|
5509
|
+
if (!this.container.contains(range.commonAncestor)) {
|
|
5498
5510
|
return newContainer;
|
|
5499
5511
|
}
|
|
5500
5512
|
if (range.isInsideBox) {
|
|
@@ -5753,27 +5765,27 @@ class Editor {
|
|
|
5753
5765
|
this.box = Editor.box;
|
|
5754
5766
|
this.copyListener = event => {
|
|
5755
5767
|
const range = this.selection.range;
|
|
5756
|
-
if (
|
|
5768
|
+
if (!this.container.contains(range.commonAncestor)) {
|
|
5757
5769
|
return;
|
|
5758
5770
|
}
|
|
5759
5771
|
this.event.emit('copy', event);
|
|
5760
5772
|
};
|
|
5761
5773
|
this.cutListener = event => {
|
|
5762
5774
|
const range = this.selection.range;
|
|
5763
|
-
if (
|
|
5775
|
+
if (!this.container.contains(range.commonAncestor)) {
|
|
5764
5776
|
return;
|
|
5765
5777
|
}
|
|
5766
5778
|
this.event.emit('cut', event);
|
|
5767
5779
|
};
|
|
5768
5780
|
this.pasteListener = event => {
|
|
5769
5781
|
const range = this.selection.range;
|
|
5770
|
-
if (
|
|
5782
|
+
if (!this.container.contains(range.commonAncestor)) {
|
|
5771
5783
|
return;
|
|
5772
5784
|
}
|
|
5773
5785
|
this.event.emit('paste', event);
|
|
5774
5786
|
};
|
|
5775
5787
|
this.selectionchangeListener = () => {
|
|
5776
|
-
this.
|
|
5788
|
+
this.updateSelectionRange();
|
|
5777
5789
|
this.updateBoxSelectionStyle();
|
|
5778
5790
|
this.emitStateChangeEvent();
|
|
5779
5791
|
};
|
|
@@ -5787,6 +5799,11 @@ class Editor {
|
|
|
5787
5799
|
this.resizeListener = () => {
|
|
5788
5800
|
this.event.emit('resize');
|
|
5789
5801
|
};
|
|
5802
|
+
this.updateSelectionRange = debounce(() => {
|
|
5803
|
+
this.selection.updateByRange();
|
|
5804
|
+
}, 1, {
|
|
5805
|
+
immediate: true,
|
|
5806
|
+
});
|
|
5790
5807
|
// Updates the classes of all boxes when the current selection of the editor is changed.
|
|
5791
5808
|
this.updateBoxSelectionStyle = debounce(() => {
|
|
5792
5809
|
// The editor has been unmounted.
|
|
@@ -5839,8 +5856,7 @@ class Editor {
|
|
|
5839
5856
|
this.emitStateChangeEvent = debounce(() => {
|
|
5840
5857
|
const commandNames = this.command.getNames();
|
|
5841
5858
|
let appliedItems = this.selection.getAppliedItems();
|
|
5842
|
-
if (appliedItems.length > 0 &&
|
|
5843
|
-
appliedItems[0].node.closestContainer().get(0) !== this.container.get(0)) {
|
|
5859
|
+
if (appliedItems.length > 0 && !this.container.contains(appliedItems[0].node)) {
|
|
5844
5860
|
appliedItems = [];
|
|
5845
5861
|
}
|
|
5846
5862
|
const disabledNameMap = new Map();
|
|
@@ -6937,6 +6953,10 @@ class Toolbar {
|
|
|
6937
6953
|
tabIndex: -1,
|
|
6938
6954
|
onClick: () => {
|
|
6939
6955
|
editor.focus();
|
|
6956
|
+
const range = editor.selection.range;
|
|
6957
|
+
if (!editor.container.contains(range.commonAncestor)) {
|
|
6958
|
+
range.shrinkAfter(editor.container);
|
|
6959
|
+
}
|
|
6940
6960
|
item.onClick(editor, item.name);
|
|
6941
6961
|
},
|
|
6942
6962
|
});
|
|
@@ -9121,11 +9141,11 @@ var formatPainter = (editor) => {
|
|
|
9121
9141
|
markList = [];
|
|
9122
9142
|
editor.history.save();
|
|
9123
9143
|
});
|
|
9124
|
-
editor.event.on('click', (
|
|
9125
|
-
if (
|
|
9144
|
+
editor.event.on('click', (targetNode) => {
|
|
9145
|
+
if (editor.container.contains(targetNode)) {
|
|
9126
9146
|
return;
|
|
9127
9147
|
}
|
|
9128
|
-
const buttonNode =
|
|
9148
|
+
const buttonNode = targetNode.closest('button[name="formatPainter"]');
|
|
9129
9149
|
if (buttonNode.length > 0) {
|
|
9130
9150
|
return;
|
|
9131
9151
|
}
|
|
@@ -9419,9 +9439,7 @@ var link = (editor) => {
|
|
|
9419
9439
|
popup.hide();
|
|
9420
9440
|
return;
|
|
9421
9441
|
}
|
|
9422
|
-
if (linkNode.
|
|
9423
|
-
linkNode.closestContainer().get(0) !== editor.container.get(0) ||
|
|
9424
|
-
linkNode.closest('lake-box').length > 0) {
|
|
9442
|
+
if (!editor.container.contains(linkNode) || linkNode.closest('lake-box').length > 0) {
|
|
9425
9443
|
popup.hide();
|
|
9426
9444
|
return;
|
|
9427
9445
|
}
|