lakelib 0.1.12 → 0.1.13
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.css +5 -0
- package/dist/lake.min.js +9 -9
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.css +5 -0
- package/lib/lake.js +129 -135
- package/lib/lake.js.map +1 -1
- package/lib/types/editor.d.ts +4 -2
- package/lib/types/managers/box-manager.d.ts +0 -3
- package/lib/types/models/range.d.ts +4 -4
- package/package.json +1 -1
package/lib/lake.css
CHANGED
|
@@ -762,6 +762,7 @@ lake-box .lake-box-strip ::selection {
|
|
|
762
762
|
}
|
|
763
763
|
lake-box .lake-box-container {
|
|
764
764
|
display: block;
|
|
765
|
+
align-self: center;
|
|
765
766
|
}
|
|
766
767
|
lake-box .lake-box-hovered .lake-button-group,
|
|
767
768
|
lake-box .lake-box-focused .lake-button-group,
|
|
@@ -833,6 +834,8 @@ lake-box[name="hr"] .lake-box-focused .lake-hr {
|
|
|
833
834
|
|
|
834
835
|
.lake-video {
|
|
835
836
|
position: relative;
|
|
837
|
+
font-size: 14px;
|
|
838
|
+
font-weight: normal;
|
|
836
839
|
line-height: 0;
|
|
837
840
|
box-sizing: content-box;
|
|
838
841
|
border: 1px solid transparent;
|
|
@@ -1052,6 +1055,8 @@ lake-box[name="image"] .lake-box-selected .lake-image-error {
|
|
|
1052
1055
|
|
|
1053
1056
|
.lake-file {
|
|
1054
1057
|
position: relative;
|
|
1058
|
+
font-size: 16px;
|
|
1059
|
+
font-weight: normal;
|
|
1055
1060
|
line-height: 0;
|
|
1056
1061
|
box-sizing: content-box;
|
|
1057
1062
|
border: 1px solid transparent;
|
package/lib/lake.js
CHANGED
|
@@ -319,7 +319,7 @@ function parseStyle(styleValue) {
|
|
|
319
319
|
// Converts the special tags to ordinary HTML tags that can be parsed by browser.
|
|
320
320
|
function normalizeValue(value) {
|
|
321
321
|
return value.
|
|
322
|
-
replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box
|
|
322
|
+
replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>|$)/ig, '$1</lake-box>').
|
|
323
323
|
replace(/<anchor\s*\/>/ig, '<lake-bookmark type="anchor"></lake-bookmark>').
|
|
324
324
|
replace(/<focus\s*\/>/ig, '<lake-bookmark type="focus"></lake-bookmark>');
|
|
325
325
|
}
|
|
@@ -1566,7 +1566,7 @@ class Range {
|
|
|
1566
1566
|
}
|
|
1567
1567
|
}
|
|
1568
1568
|
// Relocates the start and end points of the range for the box.
|
|
1569
|
-
|
|
1569
|
+
adjustBox() {
|
|
1570
1570
|
const startBoxNode = this.startNode.closest('lake-box');
|
|
1571
1571
|
if (startBoxNode.length > 0) {
|
|
1572
1572
|
const startRange = this.clone();
|
|
@@ -1591,7 +1591,7 @@ class Range {
|
|
|
1591
1591
|
}
|
|
1592
1592
|
}
|
|
1593
1593
|
// Relocates the beginning or end position of the range for table.
|
|
1594
|
-
|
|
1594
|
+
adjustTable() {
|
|
1595
1595
|
const startTable = this.startNode.closest('table');
|
|
1596
1596
|
const endTable = this.endNode.closest('table');
|
|
1597
1597
|
if (startTable.length === 0 && endTable.length > 0 && endTable.isInside) {
|
|
@@ -1617,7 +1617,7 @@ class Range {
|
|
|
1617
1617
|
// [<p>foo</p><p>]bar</p>
|
|
1618
1618
|
// to
|
|
1619
1619
|
// <p>[foo]</p><p>bar</p>
|
|
1620
|
-
|
|
1620
|
+
adjustBlock() {
|
|
1621
1621
|
if (!this.isCollapsed) {
|
|
1622
1622
|
// [<p>foo</p><p>]bar</p> to [<p>foo</p>]<p>bar</p>
|
|
1623
1623
|
if (this.endNode.isElement && this.endOffset === 0) {
|
|
@@ -1639,10 +1639,10 @@ class Range {
|
|
|
1639
1639
|
}
|
|
1640
1640
|
}
|
|
1641
1641
|
// Relocates the start and end points of the range.
|
|
1642
|
-
|
|
1643
|
-
this.
|
|
1644
|
-
this.
|
|
1645
|
-
this.
|
|
1642
|
+
adjust() {
|
|
1643
|
+
this.adjustBox();
|
|
1644
|
+
this.adjustTable();
|
|
1645
|
+
this.adjustBlock();
|
|
1646
1646
|
}
|
|
1647
1647
|
// Returns the previous node of the beginning point of the range.
|
|
1648
1648
|
getPrevNode() {
|
|
@@ -1684,7 +1684,7 @@ class Range {
|
|
|
1684
1684
|
}
|
|
1685
1685
|
const nodeList = [];
|
|
1686
1686
|
const clonedRange = this.clone();
|
|
1687
|
-
clonedRange.
|
|
1687
|
+
clonedRange.adjustBox();
|
|
1688
1688
|
for (const child of clonedRange.commonAncestor.getWalker()) {
|
|
1689
1689
|
if (child.isBox && clonedRange.intersectsNode(child)) {
|
|
1690
1690
|
nodeList.push(child);
|
|
@@ -2717,21 +2717,18 @@ function nodeAndView(node) {
|
|
|
2717
2717
|
let bottom = rect.bottom;
|
|
2718
2718
|
let viewportWidth = window.innerWidth;
|
|
2719
2719
|
let viewportHeight = window.innerHeight;
|
|
2720
|
-
const
|
|
2721
|
-
if (
|
|
2722
|
-
const
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
viewportWidth = viewportRect.width;
|
|
2733
|
-
viewportHeight = viewportRect.height;
|
|
2734
|
-
}
|
|
2720
|
+
const viewport = node.closestScroller();
|
|
2721
|
+
if (viewport.length > 0) {
|
|
2722
|
+
const nativeViewport = viewport.get(0);
|
|
2723
|
+
const viewportRect = nativeViewport.getBoundingClientRect();
|
|
2724
|
+
const offsetLeft = viewportRect.x;
|
|
2725
|
+
const offsetTop = viewportRect.y;
|
|
2726
|
+
left -= offsetLeft;
|
|
2727
|
+
right -= offsetLeft;
|
|
2728
|
+
top -= offsetTop;
|
|
2729
|
+
bottom -= offsetTop;
|
|
2730
|
+
viewportWidth = viewportRect.width;
|
|
2731
|
+
viewportHeight = viewportRect.height;
|
|
2735
2732
|
}
|
|
2736
2733
|
const position = {
|
|
2737
2734
|
left,
|
|
@@ -3670,7 +3667,7 @@ class Box {
|
|
|
3670
3667
|
newContainer.append(content);
|
|
3671
3668
|
morph(container, newContainer);
|
|
3672
3669
|
}
|
|
3673
|
-
debug(`Box '${this.name}' (id
|
|
3670
|
+
debug(`Box '${this.name}' (id: ${this.node.id}) rendered`);
|
|
3674
3671
|
}
|
|
3675
3672
|
// Destroys a rendered box.
|
|
3676
3673
|
unmount() {
|
|
@@ -3679,7 +3676,7 @@ class Box {
|
|
|
3679
3676
|
boxData[this.node.id] = {};
|
|
3680
3677
|
this.event.removeAllListeners();
|
|
3681
3678
|
this.node.empty();
|
|
3682
|
-
debug(`Box '${this.name}' (id
|
|
3679
|
+
debug(`Box '${this.name}' (id: ${this.node.id}) unmounted`);
|
|
3683
3680
|
}
|
|
3684
3681
|
// Returns a HTML string of the box.
|
|
3685
3682
|
getHTML() {
|
|
@@ -4375,8 +4372,8 @@ function deleteContents(range) {
|
|
|
4375
4372
|
if (range.isCollapsed) {
|
|
4376
4373
|
return;
|
|
4377
4374
|
}
|
|
4378
|
-
range.
|
|
4379
|
-
range.
|
|
4375
|
+
range.adjustBox();
|
|
4376
|
+
range.adjustTable();
|
|
4380
4377
|
if (range.isInoperative) {
|
|
4381
4378
|
return;
|
|
4382
4379
|
}
|
|
@@ -4385,7 +4382,7 @@ function deleteContents(range) {
|
|
|
4385
4382
|
const noMerge = startBlock.get(0) === endBlock.get(0);
|
|
4386
4383
|
const nativeRange = range.get();
|
|
4387
4384
|
nativeRange.deleteContents();
|
|
4388
|
-
range.
|
|
4385
|
+
range.adjustBlock();
|
|
4389
4386
|
if (noMerge) {
|
|
4390
4387
|
const block = range.getBlocks()[0];
|
|
4391
4388
|
if (block && block.isEmpty) {
|
|
@@ -4414,7 +4411,7 @@ function insertFragment(range, fragment) {
|
|
|
4414
4411
|
return;
|
|
4415
4412
|
}
|
|
4416
4413
|
if (range.isCollapsed) {
|
|
4417
|
-
range.
|
|
4414
|
+
range.adjustBox();
|
|
4418
4415
|
}
|
|
4419
4416
|
else {
|
|
4420
4417
|
deleteContents(range);
|
|
@@ -4424,7 +4421,7 @@ function insertFragment(range, fragment) {
|
|
|
4424
4421
|
const bookmark = insertBookmark(range);
|
|
4425
4422
|
bookmark.focus.before(fragment);
|
|
4426
4423
|
toBookmark(range, bookmark);
|
|
4427
|
-
range.
|
|
4424
|
+
range.adjustBlock();
|
|
4428
4425
|
}
|
|
4429
4426
|
|
|
4430
4427
|
// Inserts a HTML string into the specified range.
|
|
@@ -4543,7 +4540,7 @@ function splitBlock$1(range) {
|
|
|
4543
4540
|
};
|
|
4544
4541
|
}
|
|
4545
4542
|
if (range.isCollapsed) {
|
|
4546
|
-
range.
|
|
4543
|
+
range.adjustBox();
|
|
4547
4544
|
}
|
|
4548
4545
|
else {
|
|
4549
4546
|
deleteContents(range);
|
|
@@ -4649,7 +4646,7 @@ function splitMarks(range, removeEmptyMark = true) {
|
|
|
4649
4646
|
end: null,
|
|
4650
4647
|
};
|
|
4651
4648
|
}
|
|
4652
|
-
range.
|
|
4649
|
+
range.adjustBox();
|
|
4653
4650
|
if (range.isCollapsed) {
|
|
4654
4651
|
const parts = splitMarksAtPoint(range.startNode, range.startOffset, removeEmptyMark);
|
|
4655
4652
|
if (parts.start) {
|
|
@@ -4754,7 +4751,7 @@ function addMark(range, value) {
|
|
|
4754
4751
|
range.shrinkAfter(newBlock);
|
|
4755
4752
|
}
|
|
4756
4753
|
else {
|
|
4757
|
-
range.
|
|
4754
|
+
range.adjustBox();
|
|
4758
4755
|
}
|
|
4759
4756
|
}
|
|
4760
4757
|
const block = range.startNode.closestBlock();
|
|
@@ -4950,7 +4947,7 @@ function insertLink(range, value) {
|
|
|
4950
4947
|
return linkNode;
|
|
4951
4948
|
}
|
|
4952
4949
|
|
|
4953
|
-
var version = "0.1.
|
|
4950
|
+
var version = "0.1.13";
|
|
4954
4951
|
|
|
4955
4952
|
// Inserts a box into the specified range.
|
|
4956
4953
|
function insertBox(range, boxName, boxValue) {
|
|
@@ -5239,7 +5236,7 @@ class Command {
|
|
|
5239
5236
|
getItem(name) {
|
|
5240
5237
|
const commandItem = this.commandMap.get(name);
|
|
5241
5238
|
if (commandItem === undefined) {
|
|
5242
|
-
throw new Error(`Command '${name}' does not exist
|
|
5239
|
+
throw new Error(`Command '${name}' does not exist`);
|
|
5243
5240
|
}
|
|
5244
5241
|
return commandItem;
|
|
5245
5242
|
}
|
|
@@ -5389,19 +5386,19 @@ class History {
|
|
|
5389
5386
|
if (!prevItem) {
|
|
5390
5387
|
break;
|
|
5391
5388
|
}
|
|
5389
|
+
this.index--;
|
|
5392
5390
|
const prevValue = this.getValue(prevItem);
|
|
5393
5391
|
if (this.removeBookmark(prevValue) !== this.removeBookmark(value)) {
|
|
5394
5392
|
this.morphContainer(prevItem);
|
|
5395
5393
|
this.event.emit('undo', prevValue);
|
|
5396
5394
|
break;
|
|
5397
5395
|
}
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
this.index--;
|
|
5396
|
+
}
|
|
5397
|
+
if (this.index < 1) {
|
|
5398
|
+
this.index = 1;
|
|
5402
5399
|
}
|
|
5403
5400
|
this.selection.updateByBookmark();
|
|
5404
|
-
debug(`History undone
|
|
5401
|
+
debug(`History undone (index: ${this.index})`);
|
|
5405
5402
|
}
|
|
5406
5403
|
redo() {
|
|
5407
5404
|
if (!this.list[this.index]) {
|
|
@@ -5423,7 +5420,7 @@ class History {
|
|
|
5423
5420
|
}
|
|
5424
5421
|
}
|
|
5425
5422
|
this.selection.updateByBookmark();
|
|
5426
|
-
debug(`History redone
|
|
5423
|
+
debug(`History redone (index: ${this.index})`);
|
|
5427
5424
|
}
|
|
5428
5425
|
continue() {
|
|
5429
5426
|
this.canSave = true;
|
|
@@ -5450,7 +5447,7 @@ class History {
|
|
|
5450
5447
|
if (emitSaveEvent) {
|
|
5451
5448
|
this.event.emit('save', denormalizeValue(value));
|
|
5452
5449
|
}
|
|
5453
|
-
debug(`History saved
|
|
5450
|
+
debug(`History saved (index: ${this.index})`);
|
|
5454
5451
|
}
|
|
5455
5452
|
}
|
|
5456
5453
|
|
|
@@ -5529,27 +5526,6 @@ class BoxManager {
|
|
|
5529
5526
|
getNames() {
|
|
5530
5527
|
return Array.from(boxes.keys());
|
|
5531
5528
|
}
|
|
5532
|
-
rectifyInstances(container) {
|
|
5533
|
-
const instanceMap = getInstanceMap(container.id);
|
|
5534
|
-
for (const box of instanceMap.values()) {
|
|
5535
|
-
if (!box.node.get(0).isConnected) {
|
|
5536
|
-
box.unmount();
|
|
5537
|
-
instanceMap.delete(box.node.id);
|
|
5538
|
-
}
|
|
5539
|
-
}
|
|
5540
|
-
}
|
|
5541
|
-
renderAll(container) {
|
|
5542
|
-
this.rectifyInstances(container);
|
|
5543
|
-
const instanceMap = getInstanceMap(container.id);
|
|
5544
|
-
container.find('lake-box').each(boxNativeNode => {
|
|
5545
|
-
const boxNode = query(boxNativeNode);
|
|
5546
|
-
if (instanceMap.get(boxNode.id)) {
|
|
5547
|
-
return;
|
|
5548
|
-
}
|
|
5549
|
-
const box = getBox(boxNode);
|
|
5550
|
-
box.render();
|
|
5551
|
-
});
|
|
5552
|
-
}
|
|
5553
5529
|
}
|
|
5554
5530
|
|
|
5555
5531
|
class Plugin {
|
|
@@ -5650,7 +5626,7 @@ class Editor {
|
|
|
5650
5626
|
}
|
|
5651
5627
|
const range = this.selection.range;
|
|
5652
5628
|
const clonedRange = range.clone();
|
|
5653
|
-
clonedRange.
|
|
5629
|
+
clonedRange.adjustBox();
|
|
5654
5630
|
this.container.find('lake-box').each(boxNativeNode => {
|
|
5655
5631
|
const box = getBox(boxNativeNode);
|
|
5656
5632
|
const boxContainer = box.getContainer();
|
|
@@ -5740,7 +5716,7 @@ class Editor {
|
|
|
5740
5716
|
maxWait: 100,
|
|
5741
5717
|
});
|
|
5742
5718
|
this.emitChangeEvent = (value) => {
|
|
5743
|
-
this.
|
|
5719
|
+
this.fixContent();
|
|
5744
5720
|
this.emitStateChangeEvent();
|
|
5745
5721
|
this.togglePlaceholderClass(value);
|
|
5746
5722
|
this.scrollToCaret();
|
|
@@ -5872,15 +5848,15 @@ class Editor {
|
|
|
5872
5848
|
}
|
|
5873
5849
|
bindHistoryEvents() {
|
|
5874
5850
|
this.history.event.on('undo', value => {
|
|
5875
|
-
this.
|
|
5851
|
+
this.renderBoxes();
|
|
5876
5852
|
this.emitChangeEvent(value);
|
|
5877
5853
|
});
|
|
5878
5854
|
this.history.event.on('redo', value => {
|
|
5879
|
-
this.
|
|
5855
|
+
this.renderBoxes();
|
|
5880
5856
|
this.emitChangeEvent(value);
|
|
5881
5857
|
});
|
|
5882
5858
|
this.history.event.on('save', value => {
|
|
5883
|
-
this.
|
|
5859
|
+
this.removeBoxGarbage();
|
|
5884
5860
|
this.emitChangeEvent(value);
|
|
5885
5861
|
});
|
|
5886
5862
|
}
|
|
@@ -5897,19 +5873,19 @@ class Editor {
|
|
|
5897
5873
|
return i18nObject(this.config.lang);
|
|
5898
5874
|
}
|
|
5899
5875
|
// Fixes wrong content, especially empty tag.
|
|
5900
|
-
|
|
5876
|
+
fixContent() {
|
|
5901
5877
|
let children = this.container.children();
|
|
5902
5878
|
for (const child of children) {
|
|
5903
5879
|
if ((child.isBlock || child.isMark) && child.html() === '') {
|
|
5904
5880
|
child.remove();
|
|
5905
|
-
debug('
|
|
5881
|
+
debug('fixContent(): empty tag was removed');
|
|
5906
5882
|
}
|
|
5907
5883
|
}
|
|
5908
5884
|
children = this.container.children();
|
|
5909
5885
|
if (children.length === 0) {
|
|
5910
5886
|
this.container.html('<p><br /></p>');
|
|
5911
5887
|
this.selection.range.shrinkAfter(this.container);
|
|
5912
|
-
debug('
|
|
5888
|
+
debug('fixContent(): default paragraph was added');
|
|
5913
5889
|
return;
|
|
5914
5890
|
}
|
|
5915
5891
|
if (children.length === 1) {
|
|
@@ -5919,7 +5895,7 @@ class Editor {
|
|
|
5919
5895
|
child.before(paragraph);
|
|
5920
5896
|
paragraph.append(child);
|
|
5921
5897
|
this.selection.range.shrinkAfter(paragraph);
|
|
5922
|
-
debug('
|
|
5898
|
+
debug('fixContent(): void element was wrapped in paragraph');
|
|
5923
5899
|
}
|
|
5924
5900
|
}
|
|
5925
5901
|
}
|
|
@@ -5941,16 +5917,40 @@ class Editor {
|
|
|
5941
5917
|
this.history.save();
|
|
5942
5918
|
}
|
|
5943
5919
|
// Sets default config for a plugin.
|
|
5944
|
-
setPluginConfig(
|
|
5945
|
-
if (!this.config[
|
|
5946
|
-
this.config[
|
|
5920
|
+
setPluginConfig(name, config) {
|
|
5921
|
+
if (!this.config[name]) {
|
|
5922
|
+
this.config[name] = {};
|
|
5947
5923
|
}
|
|
5948
|
-
for (const key of Object.keys(
|
|
5949
|
-
if (this.config[
|
|
5950
|
-
this.config[
|
|
5924
|
+
for (const key of Object.keys(config)) {
|
|
5925
|
+
if (this.config[name][key] === undefined) {
|
|
5926
|
+
this.config[name][key] = config[key];
|
|
5951
5927
|
}
|
|
5952
5928
|
}
|
|
5953
5929
|
}
|
|
5930
|
+
// Removes all unused box instances.
|
|
5931
|
+
removeBoxGarbage() {
|
|
5932
|
+
const instanceMap = getInstanceMap(this.container.id);
|
|
5933
|
+
for (const box of instanceMap.values()) {
|
|
5934
|
+
if (!box.node.get(0).isConnected) {
|
|
5935
|
+
box.unmount();
|
|
5936
|
+
instanceMap.delete(box.node.id);
|
|
5937
|
+
}
|
|
5938
|
+
}
|
|
5939
|
+
}
|
|
5940
|
+
// Renders all boxes that haven't been rendered yet.
|
|
5941
|
+
renderBoxes() {
|
|
5942
|
+
this.removeBoxGarbage();
|
|
5943
|
+
const container = this.container;
|
|
5944
|
+
const instanceMap = getInstanceMap(container.id);
|
|
5945
|
+
container.find('lake-box').each(boxNativeNode => {
|
|
5946
|
+
const boxNode = query(boxNativeNode);
|
|
5947
|
+
if (instanceMap.get(boxNode.id)) {
|
|
5948
|
+
return;
|
|
5949
|
+
}
|
|
5950
|
+
const box = getBox(boxNode);
|
|
5951
|
+
box.render();
|
|
5952
|
+
});
|
|
5953
|
+
}
|
|
5954
5954
|
// Sets focus on the editor area.
|
|
5955
5955
|
focus() {
|
|
5956
5956
|
this.container.focus();
|
|
@@ -5978,44 +5978,16 @@ class Editor {
|
|
|
5978
5978
|
});
|
|
5979
5979
|
this.overlayContainer.find('.lake-artificial-caret').remove();
|
|
5980
5980
|
this.overlayContainer.append(artificialCaret);
|
|
5981
|
+
const position = nodeAndView(artificialCaret);
|
|
5981
5982
|
// Scrolls the artificial caret element into the visible area of the browser window
|
|
5982
5983
|
// if it's not already within the visible area of the browser window.
|
|
5983
|
-
// If the element is already within the
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
const nativeViewport = viewport.get(0);
|
|
5991
|
-
const viewportRect = nativeViewport.getBoundingClientRect();
|
|
5992
|
-
scrollX = nativeViewport.scrollLeft;
|
|
5993
|
-
scrollY = nativeViewport.scrollTop;
|
|
5994
|
-
viewportWidth = viewportRect.width;
|
|
5995
|
-
viewportHeight = viewportRect.height;
|
|
5996
|
-
}
|
|
5997
|
-
else {
|
|
5998
|
-
const nativeContainerWrapper = this.containerWrapper.get(0);
|
|
5999
|
-
scrollX = window.scrollX;
|
|
6000
|
-
scrollY = window.scrollY;
|
|
6001
|
-
viewportWidth = window.innerWidth - nativeContainerWrapper.offsetLeft;
|
|
6002
|
-
viewportHeight = window.innerHeight - nativeContainerWrapper.offsetTop;
|
|
6003
|
-
}
|
|
6004
|
-
let needScroll = false;
|
|
6005
|
-
let alignToTop = true;
|
|
6006
|
-
if (left < scrollX || left > scrollX + viewportWidth) {
|
|
6007
|
-
needScroll = true;
|
|
6008
|
-
}
|
|
6009
|
-
if (top < scrollY) {
|
|
6010
|
-
needScroll = true;
|
|
6011
|
-
alignToTop = true;
|
|
6012
|
-
}
|
|
6013
|
-
else if (top > scrollY + viewportHeight) {
|
|
6014
|
-
needScroll = true;
|
|
6015
|
-
alignToTop = false;
|
|
6016
|
-
}
|
|
6017
|
-
if (needScroll) {
|
|
6018
|
-
artificialCaret.get(0).scrollIntoView(alignToTop);
|
|
5984
|
+
// If the element is already within the visibposition.rightle area of the browser window, then no scrolling takes place.
|
|
5985
|
+
if (position.left < 0 || position.right < 0 || position.top < 0 || position.bottom < 0) {
|
|
5986
|
+
artificialCaret.get(0).scrollIntoView({
|
|
5987
|
+
behavior: 'instant',
|
|
5988
|
+
block: 'center',
|
|
5989
|
+
inline: 'nearest',
|
|
5990
|
+
});
|
|
6019
5991
|
}
|
|
6020
5992
|
artificialCaret.remove();
|
|
6021
5993
|
}
|
|
@@ -6027,7 +5999,7 @@ class Editor {
|
|
|
6027
5999
|
this.container.empty();
|
|
6028
6000
|
this.togglePlaceholderClass(htmlParser.getHTML());
|
|
6029
6001
|
this.container.append(fragment);
|
|
6030
|
-
|
|
6002
|
+
this.renderBoxes();
|
|
6031
6003
|
this.selection.updateByBookmark();
|
|
6032
6004
|
}
|
|
6033
6005
|
// Returns the contents from the editor.
|
|
@@ -6055,7 +6027,7 @@ class Editor {
|
|
|
6055
6027
|
this.selection.updateByBookmark();
|
|
6056
6028
|
this.history.save();
|
|
6057
6029
|
}
|
|
6058
|
-
|
|
6030
|
+
this.renderBoxes();
|
|
6059
6031
|
if (this.toolbar) {
|
|
6060
6032
|
this.toolbar.render(this);
|
|
6061
6033
|
}
|
|
@@ -7970,7 +7942,11 @@ var copy = (editor) => {
|
|
|
7970
7942
|
if (range.isInsideBox) {
|
|
7971
7943
|
return;
|
|
7972
7944
|
}
|
|
7973
|
-
|
|
7945
|
+
if (!range.isCollapsed) {
|
|
7946
|
+
range.adjust();
|
|
7947
|
+
return;
|
|
7948
|
+
}
|
|
7949
|
+
const boxNode = range.commonAncestor.closest('lake-box');
|
|
7974
7950
|
if (boxNode.length === 0) {
|
|
7975
7951
|
return;
|
|
7976
7952
|
}
|
|
@@ -7992,12 +7968,26 @@ var cut = (editor) => {
|
|
|
7992
7968
|
if (editor.readonly) {
|
|
7993
7969
|
return;
|
|
7994
7970
|
}
|
|
7995
|
-
editor.event.on('cut', event => {
|
|
7971
|
+
editor.event.on('cut', (event) => {
|
|
7972
|
+
const dataTransfer = event.clipboardData;
|
|
7973
|
+
if (!dataTransfer) {
|
|
7974
|
+
return;
|
|
7975
|
+
}
|
|
7996
7976
|
const range = editor.selection.range;
|
|
7997
7977
|
if (range.isInsideBox) {
|
|
7998
7978
|
return;
|
|
7999
7979
|
}
|
|
8000
|
-
|
|
7980
|
+
if (!range.isCollapsed) {
|
|
7981
|
+
event.preventDefault();
|
|
7982
|
+
const fragment = editor.selection.range.cloneContents();
|
|
7983
|
+
const tempContainer = query('<div />');
|
|
7984
|
+
tempContainer.append(fragment);
|
|
7985
|
+
dataTransfer.setData('text/html', tempContainer.html());
|
|
7986
|
+
editor.selection.deleteContents();
|
|
7987
|
+
editor.history.save();
|
|
7988
|
+
return;
|
|
7989
|
+
}
|
|
7990
|
+
const boxNode = range.commonAncestor.closest('lake-box');
|
|
8001
7991
|
if (boxNode.length === 0) {
|
|
8002
7992
|
return;
|
|
8003
7993
|
}
|
|
@@ -8005,10 +7995,6 @@ var cut = (editor) => {
|
|
|
8005
7995
|
return;
|
|
8006
7996
|
}
|
|
8007
7997
|
event.preventDefault();
|
|
8008
|
-
const dataTransfer = event.clipboardData;
|
|
8009
|
-
if (!dataTransfer) {
|
|
8010
|
-
return;
|
|
8011
|
-
}
|
|
8012
7998
|
const box = getBox(boxNode);
|
|
8013
7999
|
const content = box.getHTML();
|
|
8014
8000
|
dataTransfer.setData('text/html', content);
|
|
@@ -8130,6 +8116,14 @@ function insertFirstNode(editor, otherNode) {
|
|
|
8130
8116
|
}
|
|
8131
8117
|
const nextSibling = child.next();
|
|
8132
8118
|
editor.selection.insertNode(child);
|
|
8119
|
+
if (child.isBox) {
|
|
8120
|
+
getBox(child).render();
|
|
8121
|
+
}
|
|
8122
|
+
else if (child.isElement) {
|
|
8123
|
+
child.find('lake-box').each(node => {
|
|
8124
|
+
getBox(node).render();
|
|
8125
|
+
});
|
|
8126
|
+
}
|
|
8133
8127
|
child = nextSibling;
|
|
8134
8128
|
}
|
|
8135
8129
|
otherNode.remove();
|
|
@@ -8167,6 +8161,7 @@ function pasteFragment(editor, fragment) {
|
|
|
8167
8161
|
parts.end.remove();
|
|
8168
8162
|
}
|
|
8169
8163
|
selection.insertFragment(fragment);
|
|
8164
|
+
editor.renderBoxes();
|
|
8170
8165
|
range.shrinkAfter(lastNode);
|
|
8171
8166
|
}
|
|
8172
8167
|
fixNumberedList(editor.container.children().filter(node => node.isBlock));
|
|
@@ -8219,7 +8214,6 @@ var paste = (editor) => {
|
|
|
8219
8214
|
editor.event.emit('beforepaste', fragment);
|
|
8220
8215
|
fixClipboardData(fragment);
|
|
8221
8216
|
pasteFragment(editor, fragment);
|
|
8222
|
-
editor.box.renderAll(editor.container);
|
|
8223
8217
|
});
|
|
8224
8218
|
};
|
|
8225
8219
|
|
|
@@ -9748,13 +9742,13 @@ var enterKey = (editor) => {
|
|
|
9748
9742
|
return;
|
|
9749
9743
|
}
|
|
9750
9744
|
event.preventDefault();
|
|
9751
|
-
editor.
|
|
9745
|
+
editor.fixContent();
|
|
9752
9746
|
if (range.isBox) {
|
|
9753
9747
|
addBlockOrSplitBlockForBox(editor);
|
|
9754
9748
|
editor.history.save();
|
|
9755
9749
|
return;
|
|
9756
9750
|
}
|
|
9757
|
-
range.
|
|
9751
|
+
range.adjust();
|
|
9758
9752
|
if (range.isInoperative) {
|
|
9759
9753
|
return;
|
|
9760
9754
|
}
|
|
@@ -9833,14 +9827,14 @@ var shiftEnterKey = (editor) => {
|
|
|
9833
9827
|
if (range.isInsideBox) {
|
|
9834
9828
|
return;
|
|
9835
9829
|
}
|
|
9836
|
-
editor.
|
|
9830
|
+
editor.fixContent();
|
|
9837
9831
|
event.preventDefault();
|
|
9838
9832
|
if (range.isBox) {
|
|
9839
9833
|
addBlockOrLineBreakForBox(editor);
|
|
9840
9834
|
editor.history.save();
|
|
9841
9835
|
return;
|
|
9842
9836
|
}
|
|
9843
|
-
range.
|
|
9837
|
+
range.adjust();
|
|
9844
9838
|
if (range.isInoperative) {
|
|
9845
9839
|
return;
|
|
9846
9840
|
}
|
|
@@ -9898,7 +9892,7 @@ var backspaceKey = (editor) => {
|
|
|
9898
9892
|
if (range.isInsideBox) {
|
|
9899
9893
|
return;
|
|
9900
9894
|
}
|
|
9901
|
-
editor.
|
|
9895
|
+
editor.fixContent();
|
|
9902
9896
|
if (range.isBoxStart) {
|
|
9903
9897
|
const boxNode = range.startNode.closest('lake-box');
|
|
9904
9898
|
const prevNode = boxNode.prev();
|
|
@@ -9929,7 +9923,7 @@ var backspaceKey = (editor) => {
|
|
|
9929
9923
|
editor.history.save();
|
|
9930
9924
|
return;
|
|
9931
9925
|
}
|
|
9932
|
-
range.
|
|
9926
|
+
range.adjustBox();
|
|
9933
9927
|
}
|
|
9934
9928
|
if (range.isBox) {
|
|
9935
9929
|
event.preventDefault();
|
|
@@ -9946,7 +9940,7 @@ var backspaceKey = (editor) => {
|
|
|
9946
9940
|
editor.history.save();
|
|
9947
9941
|
return;
|
|
9948
9942
|
}
|
|
9949
|
-
range.
|
|
9943
|
+
range.adjust();
|
|
9950
9944
|
const prevNode = range.getPrevNode();
|
|
9951
9945
|
if (prevNode.isBox) {
|
|
9952
9946
|
event.preventDefault();
|
|
@@ -10036,7 +10030,7 @@ var deleteKey = (editor) => {
|
|
|
10036
10030
|
if (range.isInsideBox) {
|
|
10037
10031
|
return;
|
|
10038
10032
|
}
|
|
10039
|
-
editor.
|
|
10033
|
+
editor.fixContent();
|
|
10040
10034
|
if (range.isBoxEnd) {
|
|
10041
10035
|
const boxNode = range.startNode.closest('lake-box');
|
|
10042
10036
|
const nextNode = boxNode.next();
|
|
@@ -10061,7 +10055,7 @@ var deleteKey = (editor) => {
|
|
|
10061
10055
|
range.shrinkBefore(nextNode);
|
|
10062
10056
|
return;
|
|
10063
10057
|
}
|
|
10064
|
-
range.
|
|
10058
|
+
range.adjustBox();
|
|
10065
10059
|
}
|
|
10066
10060
|
if (range.isBox) {
|
|
10067
10061
|
event.preventDefault();
|
|
@@ -10078,7 +10072,7 @@ var deleteKey = (editor) => {
|
|
|
10078
10072
|
editor.history.save();
|
|
10079
10073
|
return;
|
|
10080
10074
|
}
|
|
10081
|
-
range.
|
|
10075
|
+
range.adjust();
|
|
10082
10076
|
const nextNode = range.getNextNode();
|
|
10083
10077
|
if (nextNode.isBox) {
|
|
10084
10078
|
event.preventDefault();
|