lakelib 0.0.4 → 0.0.5
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 +3 -4
- package/dist/lake.min.js +10 -10
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.css +3 -4
- package/lib/lake.js +356 -271
- package/lib/lake.js.map +1 -1
- package/lib/types/editor.d.ts +3 -0
- package/lib/types/managers/command.d.ts +3 -1
- package/lib/types/models/range.d.ts +6 -6
- package/lib/types/plugins/escape-key.d.ts +3 -0
- package/lib/types/types/object.d.ts +2 -2
- package/lib/types/ui/toolbar.d.ts +12 -3
- package/lib/types/utils/split-nodes.d.ts +2 -2
- package/package.json +1 -1
package/lib/lake.js
CHANGED
|
@@ -1229,11 +1229,11 @@ class Range {
|
|
|
1229
1229
|
const boxNode = this.commonAncestor.closest('lake-box');
|
|
1230
1230
|
return boxNode.length > 0;
|
|
1231
1231
|
}
|
|
1232
|
-
// Returns a boolean value indicating whether the range's common ancestor node is in the
|
|
1232
|
+
// Returns a boolean value indicating whether the range's common ancestor node is in the start strip of the box.
|
|
1233
1233
|
// case 1: <lake-box><span class="lake-box-strip">|</span><div class="lake-box-container"></div> ...
|
|
1234
1234
|
// case 2: <lake-box><span class="lake-box-strip"></span>|<div class="lake-box-container"></div> ...
|
|
1235
1235
|
// case 3: <lake-box>|<span class="lake-box-strip"></span><div class="lake-box-container"></div> ...
|
|
1236
|
-
get
|
|
1236
|
+
get isBoxStart() {
|
|
1237
1237
|
const boxNode = this.commonAncestor.closest('lake-box');
|
|
1238
1238
|
if (boxNode.length === 0) {
|
|
1239
1239
|
return false;
|
|
@@ -1254,11 +1254,11 @@ class Range {
|
|
|
1254
1254
|
// case: ... <div class="lake-box-container">|<div></div></div> ...
|
|
1255
1255
|
return this.isCollapsed && this.startNode.get(0) === boxContainer.get(0) && this.startOffset === 0;
|
|
1256
1256
|
}
|
|
1257
|
-
// Returns a boolean value indicating whether the range's common ancestor node is in the
|
|
1257
|
+
// Returns a boolean value indicating whether the range's common ancestor node is in the end strip of the box.
|
|
1258
1258
|
// case 1: ... <div class="lake-box-container"></div><span class="lake-box-strip">|</span></lake-box>
|
|
1259
1259
|
// case 2: ... <div class="lake-box-container"></div>|<span class="lake-box-strip"></span></lake-box>
|
|
1260
1260
|
// case 3: ... <div class="lake-box-container"></div><span class="lake-box-strip"></span>|</lake-box>
|
|
1261
|
-
get
|
|
1261
|
+
get isBoxEnd() {
|
|
1262
1262
|
const boxNode = this.commonAncestor.closest('lake-box');
|
|
1263
1263
|
if (boxNode.length === 0) {
|
|
1264
1264
|
return false;
|
|
@@ -1385,8 +1385,8 @@ class Range {
|
|
|
1385
1385
|
this.setStart(boxContainer, 0);
|
|
1386
1386
|
this.collapseToStart();
|
|
1387
1387
|
}
|
|
1388
|
-
// Sets the range to the
|
|
1389
|
-
|
|
1388
|
+
// Sets the range to the start position of the box.
|
|
1389
|
+
selectBoxStart(boxNode) {
|
|
1390
1390
|
const boxStrip = boxNode.find('.lake-box-strip');
|
|
1391
1391
|
if (boxStrip.length === 0) {
|
|
1392
1392
|
throw new Error(`The box cannot be selected because the box '${boxNode.attr('name')}' (id=${boxNode.id}) has not been rendered yet.`);
|
|
@@ -1394,8 +1394,8 @@ class Range {
|
|
|
1394
1394
|
this.selectNodeContents(boxStrip.eq(0));
|
|
1395
1395
|
this.collapseToEnd();
|
|
1396
1396
|
}
|
|
1397
|
-
// Sets the range to the
|
|
1398
|
-
|
|
1397
|
+
// Sets the range to the start position of the box.
|
|
1398
|
+
selectBoxEnd(boxNode) {
|
|
1399
1399
|
const boxStrip = boxNode.find('.lake-box-strip');
|
|
1400
1400
|
if (boxStrip.length === 0) {
|
|
1401
1401
|
throw new Error(`The box cannot be selected because the box '${boxNode.attr('name')}' (id=${boxNode.id}) has not been rendered yet.`);
|
|
@@ -1406,7 +1406,7 @@ class Range {
|
|
|
1406
1406
|
// Collapses the range and sets the range to the beginning of the contents of the specified node.
|
|
1407
1407
|
shrinkBefore(node) {
|
|
1408
1408
|
if (node.isBox) {
|
|
1409
|
-
this.
|
|
1409
|
+
this.selectBoxStart(node);
|
|
1410
1410
|
return;
|
|
1411
1411
|
}
|
|
1412
1412
|
if (node.isText) {
|
|
@@ -1420,7 +1420,7 @@ class Range {
|
|
|
1420
1420
|
(child = this.startNode.children()[0]) &&
|
|
1421
1421
|
child.isElement && !child.isVoid) {
|
|
1422
1422
|
if (child.isBox) {
|
|
1423
|
-
this.
|
|
1423
|
+
this.selectBoxStart(child);
|
|
1424
1424
|
return;
|
|
1425
1425
|
}
|
|
1426
1426
|
this.setStart(child, 0);
|
|
@@ -1430,7 +1430,7 @@ class Range {
|
|
|
1430
1430
|
// Collapses the range and sets the range to the end of the contents of the specified node.
|
|
1431
1431
|
shrinkAfter(node) {
|
|
1432
1432
|
if (node.isBox) {
|
|
1433
|
-
this.
|
|
1433
|
+
this.selectBoxEnd(node);
|
|
1434
1434
|
return;
|
|
1435
1435
|
}
|
|
1436
1436
|
if (node.isText) {
|
|
@@ -1445,7 +1445,7 @@ class Range {
|
|
|
1445
1445
|
(child = this.endNode.children()[this.endOffset - 1]) &&
|
|
1446
1446
|
child.isElement && !child.isVoid) {
|
|
1447
1447
|
if (child.isBox) {
|
|
1448
|
-
this.
|
|
1448
|
+
this.selectBoxEnd(child);
|
|
1449
1449
|
return;
|
|
1450
1450
|
}
|
|
1451
1451
|
this.setEnd(child, child.children().length);
|
|
@@ -1481,7 +1481,7 @@ class Range {
|
|
|
1481
1481
|
if (startBoxNode.length > 0) {
|
|
1482
1482
|
const startRange = this.clone();
|
|
1483
1483
|
startRange.collapseToStart();
|
|
1484
|
-
if (startRange.
|
|
1484
|
+
if (startRange.isBoxEnd) {
|
|
1485
1485
|
this.setStartAfter(startBoxNode);
|
|
1486
1486
|
}
|
|
1487
1487
|
else {
|
|
@@ -1492,7 +1492,7 @@ class Range {
|
|
|
1492
1492
|
if (endBoxNode.length > 0) {
|
|
1493
1493
|
const endRange = this.clone();
|
|
1494
1494
|
endRange.collapseToEnd();
|
|
1495
|
-
if (endRange.
|
|
1495
|
+
if (endRange.isBoxStart) {
|
|
1496
1496
|
this.setEndBefore(endBoxNode);
|
|
1497
1497
|
}
|
|
1498
1498
|
else {
|
|
@@ -1673,9 +1673,9 @@ class Range {
|
|
|
1673
1673
|
}
|
|
1674
1674
|
return marks;
|
|
1675
1675
|
}
|
|
1676
|
-
// Returns the text of the
|
|
1676
|
+
// Returns the text of the start part of the closest block divided into two parts by the start point of the range.
|
|
1677
1677
|
// "<p>one<anchor />two<focus />three</p>" returns "three".
|
|
1678
|
-
|
|
1678
|
+
getStartText() {
|
|
1679
1679
|
const node = this.startNode;
|
|
1680
1680
|
const offset = this.startOffset;
|
|
1681
1681
|
let block = node.closestBlock();
|
|
@@ -1685,20 +1685,20 @@ class Range {
|
|
|
1685
1685
|
if (block.length === 0) {
|
|
1686
1686
|
return '';
|
|
1687
1687
|
}
|
|
1688
|
-
const
|
|
1689
|
-
|
|
1690
|
-
|
|
1688
|
+
const startRange = new Range();
|
|
1689
|
+
startRange.setStartBefore(block);
|
|
1690
|
+
startRange.setEnd(node, offset);
|
|
1691
1691
|
const container = query('<div />');
|
|
1692
|
-
container.append(
|
|
1692
|
+
container.append(startRange.cloneContents());
|
|
1693
1693
|
const text = container.text();
|
|
1694
1694
|
if (text === '' && container.find('lake-box').length > 0) {
|
|
1695
1695
|
return '\u200B';
|
|
1696
1696
|
}
|
|
1697
1697
|
return text;
|
|
1698
1698
|
}
|
|
1699
|
-
// Returns the text of the
|
|
1699
|
+
// Returns the text of the end part of the closest block divided into two parts by the end point of the range.
|
|
1700
1700
|
// "<p>one<anchor />two<focus />three</p>" returns "three".
|
|
1701
|
-
|
|
1701
|
+
getEndText() {
|
|
1702
1702
|
const node = this.endNode;
|
|
1703
1703
|
const offset = this.endOffset;
|
|
1704
1704
|
let block = node.closestBlock();
|
|
@@ -1708,11 +1708,11 @@ class Range {
|
|
|
1708
1708
|
if (block.length === 0) {
|
|
1709
1709
|
return '';
|
|
1710
1710
|
}
|
|
1711
|
-
const
|
|
1712
|
-
|
|
1713
|
-
|
|
1711
|
+
const endRange = new Range();
|
|
1712
|
+
endRange.setStart(node, offset);
|
|
1713
|
+
endRange.setEndAfter(block);
|
|
1714
1714
|
const container = query('<div />');
|
|
1715
|
-
container.append(
|
|
1715
|
+
container.append(endRange.cloneContents());
|
|
1716
1716
|
const text = container.text();
|
|
1717
1717
|
if (text === '' && container.find('lake-box').length > 0) {
|
|
1718
1718
|
return '\u200B';
|
|
@@ -1770,23 +1770,23 @@ function splitNodes(node, offset, limitNode) {
|
|
|
1770
1770
|
return null;
|
|
1771
1771
|
}
|
|
1772
1772
|
range.collapseToStart();
|
|
1773
|
-
const
|
|
1773
|
+
const startPart = parent.clone();
|
|
1774
1774
|
let child = parent.first();
|
|
1775
1775
|
while (child.length > 0) {
|
|
1776
1776
|
if (range.compareBeforeNode(child) >= 0) {
|
|
1777
1777
|
break;
|
|
1778
1778
|
}
|
|
1779
1779
|
const nextNode = child.next();
|
|
1780
|
-
|
|
1780
|
+
startPart.append(child);
|
|
1781
1781
|
child = nextNode;
|
|
1782
1782
|
}
|
|
1783
|
-
parent.before(
|
|
1783
|
+
parent.before(startPart);
|
|
1784
1784
|
if (parent.parent().length > 0 && parent.parent().get(0) !== limitNode.get(0)) {
|
|
1785
1785
|
return splitNodes(parent.parent(), parent.index(), limitNode);
|
|
1786
1786
|
}
|
|
1787
1787
|
return {
|
|
1788
|
-
|
|
1789
|
-
|
|
1788
|
+
start: startPart,
|
|
1789
|
+
end: parent,
|
|
1790
1790
|
};
|
|
1791
1791
|
}
|
|
1792
1792
|
|
|
@@ -2857,6 +2857,9 @@ class Box {
|
|
|
2857
2857
|
container.off('mouseleave');
|
|
2858
2858
|
container.off('click');
|
|
2859
2859
|
}
|
|
2860
|
+
container.on('mousedown', event => {
|
|
2861
|
+
event.preventDefault();
|
|
2862
|
+
});
|
|
2860
2863
|
container.on('mouseenter', () => {
|
|
2861
2864
|
if (container.hasClass('lake-box-selected') ||
|
|
2862
2865
|
container.hasClass('lake-box-focused') ||
|
|
@@ -3032,7 +3035,7 @@ function getElementRules() {
|
|
|
3032
3035
|
type: ['inline', 'block'],
|
|
3033
3036
|
name: /^[\w-]+$/,
|
|
3034
3037
|
value: /^[^"]+$/,
|
|
3035
|
-
focus: ['
|
|
3038
|
+
focus: ['start', 'center', 'end'],
|
|
3036
3039
|
},
|
|
3037
3040
|
br: {},
|
|
3038
3041
|
hr: {},
|
|
@@ -3291,8 +3294,8 @@ function insertNode(range, node) {
|
|
|
3291
3294
|
// or the method inserts a pair of bookmarks into the beginning and the end of the range.
|
|
3292
3295
|
// case 1: foo<lake-bookmark type="focus" />bar
|
|
3293
3296
|
// case 2: <lake-bookmark type="anchor" />foo<lake-bookmark type="focus" />
|
|
3294
|
-
// case 3: foo<lake-box type="inline" name="image" focus="
|
|
3295
|
-
// case 4: foo<lake-box type="inline" name="image" focus="
|
|
3297
|
+
// case 3: foo<lake-box type="inline" name="image" focus="start"></lake-box>bar
|
|
3298
|
+
// case 4: foo<lake-box type="inline" name="image" focus="end"></lake-box>bar
|
|
3296
3299
|
// case 5: <lake-bookmark type="anchor" /><lake-box type="inline" name="image"></lake-box>foo<lake-bookmark type="focus" />
|
|
3297
3300
|
function insertBookmark(range) {
|
|
3298
3301
|
if (range.commonAncestor.isOutside) {
|
|
@@ -3304,11 +3307,11 @@ function insertBookmark(range) {
|
|
|
3304
3307
|
// box
|
|
3305
3308
|
const boxNode = range.startNode.closest('lake-box');
|
|
3306
3309
|
if (boxNode.length > 0) {
|
|
3307
|
-
if (range.
|
|
3308
|
-
boxNode.attr('focus', '
|
|
3310
|
+
if (range.isBoxStart) {
|
|
3311
|
+
boxNode.attr('focus', 'start');
|
|
3309
3312
|
}
|
|
3310
|
-
else if (range.
|
|
3311
|
-
boxNode.attr('focus', '
|
|
3313
|
+
else if (range.isBoxEnd) {
|
|
3314
|
+
boxNode.attr('focus', 'end');
|
|
3312
3315
|
}
|
|
3313
3316
|
else {
|
|
3314
3317
|
boxNode.attr('focus', 'center');
|
|
@@ -3382,14 +3385,14 @@ function toBookmark(range, bookmark) {
|
|
|
3382
3385
|
box.render();
|
|
3383
3386
|
}
|
|
3384
3387
|
const focusValue = focus.attr('focus');
|
|
3385
|
-
if (focusValue === '
|
|
3386
|
-
range.
|
|
3388
|
+
if (focusValue === 'start') {
|
|
3389
|
+
range.selectBoxStart(focus);
|
|
3387
3390
|
}
|
|
3388
3391
|
else if (focusValue === 'center') {
|
|
3389
3392
|
range.selectBox(focus);
|
|
3390
3393
|
}
|
|
3391
3394
|
else {
|
|
3392
|
-
range.
|
|
3395
|
+
range.selectBoxEnd(focus);
|
|
3393
3396
|
}
|
|
3394
3397
|
focus.removeAttr('focus');
|
|
3395
3398
|
return;
|
|
@@ -3593,8 +3596,8 @@ function setBlocks(range, value) {
|
|
|
3593
3596
|
function splitBlock$1(range) {
|
|
3594
3597
|
if (range.commonAncestor.isOutside) {
|
|
3595
3598
|
return {
|
|
3596
|
-
|
|
3597
|
-
|
|
3599
|
+
start: null,
|
|
3600
|
+
end: null,
|
|
3598
3601
|
};
|
|
3599
3602
|
}
|
|
3600
3603
|
if (range.isCollapsed) {
|
|
@@ -3607,8 +3610,8 @@ function splitBlock$1(range) {
|
|
|
3607
3610
|
const closestBlock = node.closestOperableBlock();
|
|
3608
3611
|
if (closestBlock.length === 0) {
|
|
3609
3612
|
return {
|
|
3610
|
-
|
|
3611
|
-
|
|
3613
|
+
start: null,
|
|
3614
|
+
end: null,
|
|
3612
3615
|
};
|
|
3613
3616
|
}
|
|
3614
3617
|
let limitBlock = closestBlock.parent();
|
|
@@ -3616,37 +3619,37 @@ function splitBlock$1(range) {
|
|
|
3616
3619
|
limitBlock = node.closestContainer();
|
|
3617
3620
|
}
|
|
3618
3621
|
const parts = splitNodes(node, range.startOffset, limitBlock);
|
|
3619
|
-
let
|
|
3620
|
-
let
|
|
3622
|
+
let start = null;
|
|
3623
|
+
let end = null;
|
|
3621
3624
|
if (parts) {
|
|
3622
|
-
|
|
3623
|
-
|
|
3625
|
+
start = parts.start;
|
|
3626
|
+
end = parts.end;
|
|
3624
3627
|
}
|
|
3625
3628
|
if (!parts && node.isBlock) {
|
|
3626
3629
|
if (range.startOffset > 0) {
|
|
3627
|
-
|
|
3630
|
+
start = node.children()[range.startOffset - 1];
|
|
3628
3631
|
}
|
|
3629
|
-
|
|
3630
|
-
if (
|
|
3631
|
-
|
|
3632
|
+
end = node.children()[range.startOffset];
|
|
3633
|
+
if (end && !end.isBlock) {
|
|
3634
|
+
end = null;
|
|
3632
3635
|
}
|
|
3633
3636
|
}
|
|
3634
|
-
if (
|
|
3635
|
-
appendDeepest(
|
|
3637
|
+
if (start && start.isEmpty) {
|
|
3638
|
+
appendDeepest(start, query('<br />'));
|
|
3636
3639
|
}
|
|
3637
|
-
if (
|
|
3638
|
-
if (
|
|
3639
|
-
appendDeepest(
|
|
3640
|
-
range.shrinkAfter(
|
|
3640
|
+
if (end) {
|
|
3641
|
+
if (end.isEmpty) {
|
|
3642
|
+
appendDeepest(end, query('<br />'));
|
|
3643
|
+
range.shrinkAfter(end);
|
|
3641
3644
|
}
|
|
3642
3645
|
else {
|
|
3643
|
-
range.shrinkBefore(
|
|
3646
|
+
range.shrinkBefore(end);
|
|
3644
3647
|
}
|
|
3645
3648
|
}
|
|
3646
3649
|
fixList(range);
|
|
3647
3650
|
return {
|
|
3648
|
-
|
|
3649
|
-
|
|
3651
|
+
start,
|
|
3652
|
+
end,
|
|
3650
3653
|
};
|
|
3651
3654
|
}
|
|
3652
3655
|
|
|
@@ -3664,8 +3667,8 @@ function removeEmptyMarks$1(node) {
|
|
|
3664
3667
|
}
|
|
3665
3668
|
// Splits text nodes or mark nodes at a specified position.
|
|
3666
3669
|
function splitMarksAtPoint(node, offset, removeEmptyMark) {
|
|
3667
|
-
let
|
|
3668
|
-
let
|
|
3670
|
+
let start = null;
|
|
3671
|
+
let end = null;
|
|
3669
3672
|
let limitBlock = node.closestBlock();
|
|
3670
3673
|
if (limitBlock.length === 0) {
|
|
3671
3674
|
limitBlock = node.closestContainer();
|
|
@@ -3673,23 +3676,23 @@ function splitMarksAtPoint(node, offset, removeEmptyMark) {
|
|
|
3673
3676
|
const parts = splitNodes(node, offset, limitBlock);
|
|
3674
3677
|
if (parts) {
|
|
3675
3678
|
if (removeEmptyMark) {
|
|
3676
|
-
removeEmptyMarks$1(parts.
|
|
3677
|
-
removeEmptyMarks$1(parts.
|
|
3678
|
-
if (!parts.
|
|
3679
|
-
|
|
3679
|
+
removeEmptyMarks$1(parts.start);
|
|
3680
|
+
removeEmptyMarks$1(parts.end);
|
|
3681
|
+
if (!parts.start.isEmpty) {
|
|
3682
|
+
start = parts.start;
|
|
3680
3683
|
}
|
|
3681
|
-
if (!parts.
|
|
3682
|
-
|
|
3684
|
+
if (!parts.end.isEmpty) {
|
|
3685
|
+
end = parts.end;
|
|
3683
3686
|
}
|
|
3684
3687
|
}
|
|
3685
3688
|
else {
|
|
3686
|
-
|
|
3687
|
-
|
|
3689
|
+
start = parts.start;
|
|
3690
|
+
end = parts.end;
|
|
3688
3691
|
}
|
|
3689
3692
|
}
|
|
3690
3693
|
return {
|
|
3691
|
-
|
|
3692
|
-
|
|
3694
|
+
start,
|
|
3695
|
+
end,
|
|
3693
3696
|
};
|
|
3694
3697
|
}
|
|
3695
3698
|
// Splits text nodes or mark nodes.
|
|
@@ -3699,46 +3702,46 @@ function splitMarksAtPoint(node, offset, removeEmptyMark) {
|
|
|
3699
3702
|
function splitMarks(range, removeEmptyMark = true) {
|
|
3700
3703
|
if (range.commonAncestor.isOutside) {
|
|
3701
3704
|
return {
|
|
3702
|
-
|
|
3705
|
+
start: null,
|
|
3703
3706
|
center: null,
|
|
3704
|
-
|
|
3707
|
+
end: null,
|
|
3705
3708
|
};
|
|
3706
3709
|
}
|
|
3707
3710
|
range.adaptBox();
|
|
3708
3711
|
if (range.isCollapsed) {
|
|
3709
3712
|
const parts = splitMarksAtPoint(range.startNode, range.startOffset, removeEmptyMark);
|
|
3710
|
-
if (parts.
|
|
3711
|
-
range.setStartAfter(parts.
|
|
3713
|
+
if (parts.start) {
|
|
3714
|
+
range.setStartAfter(parts.start);
|
|
3712
3715
|
range.collapseToStart();
|
|
3713
3716
|
}
|
|
3714
|
-
else if (parts.
|
|
3715
|
-
range.setStartBefore(parts.
|
|
3717
|
+
else if (parts.end) {
|
|
3718
|
+
range.setStartBefore(parts.end);
|
|
3716
3719
|
range.collapseToStart();
|
|
3717
3720
|
}
|
|
3718
3721
|
return {
|
|
3719
|
-
|
|
3722
|
+
start: parts.start,
|
|
3720
3723
|
center: null,
|
|
3721
|
-
|
|
3724
|
+
end: parts.end,
|
|
3722
3725
|
};
|
|
3723
3726
|
}
|
|
3724
3727
|
const startParts = splitMarksAtPoint(range.startNode, range.startOffset, removeEmptyMark);
|
|
3725
|
-
if (startParts.
|
|
3726
|
-
range.setStartAfter(startParts.
|
|
3728
|
+
if (startParts.start) {
|
|
3729
|
+
range.setStartAfter(startParts.start);
|
|
3727
3730
|
}
|
|
3728
|
-
else if (startParts.
|
|
3729
|
-
range.setStartBefore(startParts.
|
|
3731
|
+
else if (startParts.end) {
|
|
3732
|
+
range.setStartBefore(startParts.end);
|
|
3730
3733
|
}
|
|
3731
3734
|
const endParts = splitMarksAtPoint(range.endNode, range.endOffset, removeEmptyMark);
|
|
3732
|
-
if (endParts.
|
|
3733
|
-
range.setEndAfter(endParts.
|
|
3735
|
+
if (endParts.start) {
|
|
3736
|
+
range.setEndAfter(endParts.start);
|
|
3734
3737
|
}
|
|
3735
|
-
else if (endParts.
|
|
3736
|
-
range.setEndBefore(endParts.
|
|
3738
|
+
else if (endParts.end) {
|
|
3739
|
+
range.setEndBefore(endParts.end);
|
|
3737
3740
|
}
|
|
3738
3741
|
return {
|
|
3739
|
-
|
|
3740
|
-
center: endParts.
|
|
3741
|
-
|
|
3742
|
+
start: startParts.start,
|
|
3743
|
+
center: endParts.start,
|
|
3744
|
+
end: endParts.end,
|
|
3742
3745
|
};
|
|
3743
3746
|
}
|
|
3744
3747
|
|
|
@@ -3800,7 +3803,7 @@ function addMark(range, value) {
|
|
|
3800
3803
|
const box = new Box(boxNode);
|
|
3801
3804
|
if (box.type === 'block') {
|
|
3802
3805
|
const newBlock = query('<p><br /></p>');
|
|
3803
|
-
if (range.
|
|
3806
|
+
if (range.isBoxStart) {
|
|
3804
3807
|
boxNode.before(newBlock);
|
|
3805
3808
|
}
|
|
3806
3809
|
else {
|
|
@@ -3817,8 +3820,8 @@ function addMark(range, value) {
|
|
|
3817
3820
|
// https://en.wikipedia.org/wiki/Zero-width_space
|
|
3818
3821
|
const zeroWidthSpace = new Nodes(document.createTextNode('\u200B'));
|
|
3819
3822
|
const parts = splitMarks(range);
|
|
3820
|
-
if (parts.
|
|
3821
|
-
const newMark = copyNestedMarks$1(parts.
|
|
3823
|
+
if (parts.start) {
|
|
3824
|
+
const newMark = copyNestedMarks$1(parts.start);
|
|
3822
3825
|
if (newMark) {
|
|
3823
3826
|
if (newMark.name === tagName) {
|
|
3824
3827
|
newMark.css(cssProperties);
|
|
@@ -3914,17 +3917,17 @@ function removeMark(range, value) {
|
|
|
3914
3917
|
return;
|
|
3915
3918
|
}
|
|
3916
3919
|
const parts = splitMarks(range, false);
|
|
3917
|
-
if (!parts.
|
|
3920
|
+
if (!parts.start) {
|
|
3918
3921
|
return;
|
|
3919
3922
|
}
|
|
3920
|
-
if (parts.
|
|
3921
|
-
removeEmptyMarks(parts.
|
|
3923
|
+
if (parts.end) {
|
|
3924
|
+
removeEmptyMarks(parts.end);
|
|
3922
3925
|
}
|
|
3923
3926
|
const zeroWidthSpace = new Nodes(document.createTextNode('\u200B'));
|
|
3924
|
-
const newMark = copyNestedMarks(parts.
|
|
3927
|
+
const newMark = copyNestedMarks(parts.start, tagName);
|
|
3925
3928
|
if (!newMark) {
|
|
3926
|
-
parts.
|
|
3927
|
-
removeEmptyMarks(parts.
|
|
3929
|
+
parts.start.after(zeroWidthSpace);
|
|
3930
|
+
removeEmptyMarks(parts.start);
|
|
3928
3931
|
if (zeroWidthSpace.prev().isText) {
|
|
3929
3932
|
range.setStartAfter(zeroWidthSpace.prev());
|
|
3930
3933
|
range.collapseToStart();
|
|
@@ -3936,8 +3939,8 @@ function removeMark(range, value) {
|
|
|
3936
3939
|
return;
|
|
3937
3940
|
}
|
|
3938
3941
|
appendDeepest(newMark, zeroWidthSpace);
|
|
3939
|
-
parts.
|
|
3940
|
-
removeEmptyMarks(parts.
|
|
3942
|
+
parts.start.after(newMark);
|
|
3943
|
+
removeEmptyMarks(parts.start);
|
|
3941
3944
|
range.shrinkAfter(newMark);
|
|
3942
3945
|
return;
|
|
3943
3946
|
}
|
|
@@ -4291,7 +4294,7 @@ class Dropdown {
|
|
|
4291
4294
|
}
|
|
4292
4295
|
}
|
|
4293
4296
|
|
|
4294
|
-
var version = "0.0.
|
|
4297
|
+
var version = "0.0.4";
|
|
4295
4298
|
|
|
4296
4299
|
// Inserts a box into the specified range.
|
|
4297
4300
|
function insertBox(range, boxName, boxValue) {
|
|
@@ -4308,23 +4311,23 @@ function insertBox(range, boxName, boxValue) {
|
|
|
4308
4311
|
if (box.type === 'inline') {
|
|
4309
4312
|
insertFragment(range, fragment);
|
|
4310
4313
|
box.render();
|
|
4311
|
-
range.
|
|
4314
|
+
range.selectBoxEnd(box.node);
|
|
4312
4315
|
return box;
|
|
4313
4316
|
}
|
|
4314
4317
|
// block box
|
|
4315
4318
|
const parts = splitBlock$1(range);
|
|
4316
|
-
if (parts.
|
|
4317
|
-
range.setEndAfter(parts.
|
|
4319
|
+
if (parts.start) {
|
|
4320
|
+
range.setEndAfter(parts.start);
|
|
4318
4321
|
range.collapseToEnd();
|
|
4319
4322
|
}
|
|
4320
|
-
if (parts.
|
|
4321
|
-
parts.
|
|
4323
|
+
if (parts.end && parts.end.isEmpty) {
|
|
4324
|
+
parts.end.remove();
|
|
4322
4325
|
}
|
|
4323
4326
|
insertFragment(range, fragment);
|
|
4324
4327
|
box.render();
|
|
4325
|
-
range.
|
|
4326
|
-
if (parts.
|
|
4327
|
-
parts.
|
|
4328
|
+
range.selectBoxEnd(box.node);
|
|
4329
|
+
if (parts.start && parts.start.isEmpty) {
|
|
4330
|
+
parts.start.remove();
|
|
4328
4331
|
}
|
|
4329
4332
|
return box;
|
|
4330
4333
|
}
|
|
@@ -4527,12 +4530,18 @@ class Command {
|
|
|
4527
4530
|
this.event = new EventEmitter();
|
|
4528
4531
|
this.selection = selection;
|
|
4529
4532
|
}
|
|
4530
|
-
add(name,
|
|
4531
|
-
this.commandMap.set(name,
|
|
4533
|
+
add(name, commandItem) {
|
|
4534
|
+
this.commandMap.set(name, commandItem);
|
|
4535
|
+
}
|
|
4536
|
+
delete(name) {
|
|
4537
|
+
this.commandMap.delete(name);
|
|
4532
4538
|
}
|
|
4533
4539
|
getNames() {
|
|
4534
4540
|
return Array.from(this.commandMap.keys());
|
|
4535
4541
|
}
|
|
4542
|
+
has(name) {
|
|
4543
|
+
return this.commandMap.get(name) !== undefined;
|
|
4544
|
+
}
|
|
4536
4545
|
getItem(name) {
|
|
4537
4546
|
const commandItem = this.commandMap.get(name);
|
|
4538
4547
|
if (commandItem === undefined) {
|
|
@@ -4930,6 +4939,7 @@ class Editor {
|
|
|
4930
4939
|
}
|
|
4931
4940
|
if (range.compareBeforeNode(boxContainer) < 0 && range.compareAfterNode(boxContainer) > 0) {
|
|
4932
4941
|
if (!(range.isCollapsed && range.startNode.get(0) === boxContainer.get(0) && range.startOffset === 0)) {
|
|
4942
|
+
boxContainer.removeClass('lake-box-hovered');
|
|
4933
4943
|
boxContainer.removeClass('lake-box-selected');
|
|
4934
4944
|
boxContainer.removeClass('lake-box-focused');
|
|
4935
4945
|
boxContainer.addClass('lake-box-activated');
|
|
@@ -4939,6 +4949,7 @@ class Editor {
|
|
|
4939
4949
|
if (clonedRange.intersectsNode(box.node)) {
|
|
4940
4950
|
boxContainer.removeClass('lake-box-activated');
|
|
4941
4951
|
if (range.isCollapsed) {
|
|
4952
|
+
boxContainer.removeClass('lake-box-hovered');
|
|
4942
4953
|
boxContainer.removeClass('lake-box-selected');
|
|
4943
4954
|
boxContainer.addClass('lake-box-focused');
|
|
4944
4955
|
}
|
|
@@ -4985,12 +4996,16 @@ class Editor {
|
|
|
4985
4996
|
}
|
|
4986
4997
|
}
|
|
4987
4998
|
}
|
|
4988
|
-
|
|
4999
|
+
const stateData = {
|
|
4989
5000
|
appliedItems,
|
|
4990
5001
|
disabledNameMap,
|
|
4991
5002
|
selectedNameMap,
|
|
4992
5003
|
selectedValuesMap,
|
|
4993
|
-
}
|
|
5004
|
+
};
|
|
5005
|
+
if (this.toolbar) {
|
|
5006
|
+
this.toolbar.updateState(stateData);
|
|
5007
|
+
}
|
|
5008
|
+
this.event.emit('statechange', stateData);
|
|
4994
5009
|
}, 100, {
|
|
4995
5010
|
leading: false,
|
|
4996
5011
|
trailing: true,
|
|
@@ -5005,6 +5020,7 @@ class Editor {
|
|
|
5005
5020
|
throw new Error('The root of the config must be specified.');
|
|
5006
5021
|
}
|
|
5007
5022
|
this.root = query(config.root);
|
|
5023
|
+
this.toolbar = config.toolbar;
|
|
5008
5024
|
this.config = Object.assign(Object.assign({}, defaultConfig), config);
|
|
5009
5025
|
this.containerWrapper = query('<div class="lake-container-wrapper" />');
|
|
5010
5026
|
this.container = query('<div class="lake-container" />');
|
|
@@ -5030,7 +5046,7 @@ class Editor {
|
|
|
5030
5046
|
const boxNode = stripNode.closest('lake-box');
|
|
5031
5047
|
const box = new Box(boxNode);
|
|
5032
5048
|
if (box.type === 'inline') {
|
|
5033
|
-
if (range.
|
|
5049
|
+
if (range.isBoxStart) {
|
|
5034
5050
|
range.setStartBefore(boxNode);
|
|
5035
5051
|
range.collapseToStart();
|
|
5036
5052
|
}
|
|
@@ -5041,7 +5057,7 @@ class Editor {
|
|
|
5041
5057
|
}
|
|
5042
5058
|
else {
|
|
5043
5059
|
const paragraph = query('<p />');
|
|
5044
|
-
if (range.
|
|
5060
|
+
if (range.isBoxStart) {
|
|
5045
5061
|
boxNode.before(paragraph);
|
|
5046
5062
|
}
|
|
5047
5063
|
else {
|
|
@@ -5062,7 +5078,7 @@ class Editor {
|
|
|
5062
5078
|
});
|
|
5063
5079
|
this.container.on('beforeinput', () => {
|
|
5064
5080
|
const range = this.selection.range;
|
|
5065
|
-
if (range.
|
|
5081
|
+
if (range.isBoxStart || range.isBoxEnd) {
|
|
5066
5082
|
this.commitUnsavedInputData();
|
|
5067
5083
|
}
|
|
5068
5084
|
});
|
|
@@ -5082,7 +5098,7 @@ class Editor {
|
|
|
5082
5098
|
}
|
|
5083
5099
|
if (inputEvent.inputType === 'insertText' ||
|
|
5084
5100
|
inputEvent.inputType === 'insertCompositionText') {
|
|
5085
|
-
if (range.
|
|
5101
|
+
if (range.isBoxStart || range.isBoxEnd) {
|
|
5086
5102
|
this.inputInBoxStrip();
|
|
5087
5103
|
}
|
|
5088
5104
|
else {
|
|
@@ -5230,6 +5246,9 @@ class Editor {
|
|
|
5230
5246
|
Editor.plugin.loadAll(this);
|
|
5231
5247
|
}
|
|
5232
5248
|
Editor.box.renderAll(this);
|
|
5249
|
+
if (this.toolbar) {
|
|
5250
|
+
this.toolbar.render(this);
|
|
5251
|
+
}
|
|
5233
5252
|
if (!this.readonly) {
|
|
5234
5253
|
window.addEventListener('beforeunload', this.beforeunloadListener);
|
|
5235
5254
|
document.addEventListener('selectionchange', this.selectionchangeListener);
|
|
@@ -6270,8 +6289,10 @@ toolbarItems.forEach(item => {
|
|
|
6270
6289
|
});
|
|
6271
6290
|
class Toolbar {
|
|
6272
6291
|
constructor(config) {
|
|
6292
|
+
this.allMenuMap = new Map();
|
|
6293
|
+
this.buttonItemList = [];
|
|
6294
|
+
this.dropdownItemList = [];
|
|
6273
6295
|
this.items = config.items || defaultItems;
|
|
6274
|
-
this.editor = config.editor;
|
|
6275
6296
|
this.root = query(config.root);
|
|
6276
6297
|
this.container = query('<div class="lake-toolbar" />');
|
|
6277
6298
|
this.root.addClass('lake-custom-properties');
|
|
@@ -6279,8 +6300,7 @@ class Toolbar {
|
|
|
6279
6300
|
appendDivider() {
|
|
6280
6301
|
this.container.append('<div class="lake-toolbar-divider" />');
|
|
6281
6302
|
}
|
|
6282
|
-
appendButton(item) {
|
|
6283
|
-
const editor = this.editor;
|
|
6303
|
+
appendButton(editor, item) {
|
|
6284
6304
|
const button = new Button({
|
|
6285
6305
|
root: this.container,
|
|
6286
6306
|
name: item.name,
|
|
@@ -6294,8 +6314,7 @@ class Toolbar {
|
|
|
6294
6314
|
});
|
|
6295
6315
|
button.render();
|
|
6296
6316
|
}
|
|
6297
|
-
appendDropdown(item) {
|
|
6298
|
-
const editor = this.editor;
|
|
6317
|
+
appendDropdown(editor, item) {
|
|
6299
6318
|
const dropdown = new Dropdown({
|
|
6300
6319
|
root: this.container,
|
|
6301
6320
|
name: item.name,
|
|
@@ -6315,8 +6334,7 @@ class Toolbar {
|
|
|
6315
6334
|
});
|
|
6316
6335
|
dropdown.render();
|
|
6317
6336
|
}
|
|
6318
|
-
appendUpload(item) {
|
|
6319
|
-
const editor = this.editor;
|
|
6337
|
+
appendUpload(editor, item) {
|
|
6320
6338
|
const uploadNode = query(safeTemplate `
|
|
6321
6339
|
<div class="lake-upload" name="${item.name}">
|
|
6322
6340
|
<input type="file" />
|
|
@@ -6355,14 +6373,69 @@ class Toolbar {
|
|
|
6355
6373
|
}
|
|
6356
6374
|
});
|
|
6357
6375
|
}
|
|
6376
|
+
// Updates state of each item such as disabled, selected.
|
|
6377
|
+
updateState(data) {
|
|
6378
|
+
var _a;
|
|
6379
|
+
const { appliedItems, disabledNameMap, selectedNameMap, selectedValuesMap } = data;
|
|
6380
|
+
for (const item of this.buttonItemList) {
|
|
6381
|
+
const selectedClass = 'lake-button-selected';
|
|
6382
|
+
const buttonNode = this.container.find(`button[name="${item.name}"]`);
|
|
6383
|
+
let isDisabled = disabledNameMap.get(item.name);
|
|
6384
|
+
if (isDisabled === undefined) {
|
|
6385
|
+
isDisabled = item.isDisabled && appliedItems.length > 0 ? item.isDisabled(appliedItems) : false;
|
|
6386
|
+
}
|
|
6387
|
+
if (isDisabled) {
|
|
6388
|
+
buttonNode.attr('disabled', 'true');
|
|
6389
|
+
buttonNode.removeClass(selectedClass);
|
|
6390
|
+
}
|
|
6391
|
+
else {
|
|
6392
|
+
buttonNode.removeAttr('disabled');
|
|
6393
|
+
}
|
|
6394
|
+
if (!isDisabled) {
|
|
6395
|
+
let isSelected = selectedNameMap.get(item.name);
|
|
6396
|
+
if (isSelected === undefined) {
|
|
6397
|
+
isSelected = item.isSelected && appliedItems.length > 0 ? item.isSelected(appliedItems) : false;
|
|
6398
|
+
}
|
|
6399
|
+
if (isSelected) {
|
|
6400
|
+
buttonNode.addClass(selectedClass);
|
|
6401
|
+
}
|
|
6402
|
+
else {
|
|
6403
|
+
buttonNode.removeClass(selectedClass);
|
|
6404
|
+
}
|
|
6405
|
+
}
|
|
6406
|
+
}
|
|
6407
|
+
for (const item of this.dropdownItemList) {
|
|
6408
|
+
let selectedValues = selectedValuesMap.get(item.name);
|
|
6409
|
+
if (selectedValues === undefined) {
|
|
6410
|
+
selectedValues = item.selectedValues && appliedItems.length > 0 ? item.selectedValues(appliedItems) : [];
|
|
6411
|
+
}
|
|
6412
|
+
const dropdownNode = this.container.find(`div.lake-dropdown[name="${item.name}"]`);
|
|
6413
|
+
let isDisabled = disabledNameMap.get(item.name);
|
|
6414
|
+
if (isDisabled === undefined) {
|
|
6415
|
+
isDisabled = item.isDisabled && appliedItems.length > 0 ? item.isDisabled(appliedItems) : false;
|
|
6416
|
+
}
|
|
6417
|
+
if (isDisabled) {
|
|
6418
|
+
dropdownNode.attr('disabled', 'true');
|
|
6419
|
+
}
|
|
6420
|
+
else {
|
|
6421
|
+
dropdownNode.removeAttr('disabled');
|
|
6422
|
+
}
|
|
6423
|
+
if (!isDisabled) {
|
|
6424
|
+
Dropdown.setValue(dropdownNode, selectedValues);
|
|
6425
|
+
const textNode = dropdownNode.find('.lake-dropdown-text');
|
|
6426
|
+
if (textNode.length > 0) {
|
|
6427
|
+
const key = selectedValues[0] || item.defaultValue;
|
|
6428
|
+
const menuMap = this.allMenuMap.get(item.name);
|
|
6429
|
+
const text = (_a = (menuMap && menuMap.get(key))) !== null && _a !== void 0 ? _a : key;
|
|
6430
|
+
textNode.text(text);
|
|
6431
|
+
}
|
|
6432
|
+
}
|
|
6433
|
+
}
|
|
6434
|
+
}
|
|
6358
6435
|
// Renders a toolbar for the specified editor.
|
|
6359
|
-
render() {
|
|
6360
|
-
const editor = this.editor;
|
|
6436
|
+
render(editor) {
|
|
6361
6437
|
this.root.empty();
|
|
6362
6438
|
this.root.append(this.container);
|
|
6363
|
-
const allMenuMap = new Map();
|
|
6364
|
-
const buttonItemList = [];
|
|
6365
|
-
const dropdownItemList = [];
|
|
6366
6439
|
this.items.forEach(name => {
|
|
6367
6440
|
if (name === '|') {
|
|
6368
6441
|
this.appendDivider();
|
|
@@ -6379,76 +6452,18 @@ class Toolbar {
|
|
|
6379
6452
|
item = name;
|
|
6380
6453
|
}
|
|
6381
6454
|
if (item.type === 'button') {
|
|
6382
|
-
buttonItemList.push(item);
|
|
6383
|
-
this.appendButton(item);
|
|
6455
|
+
this.buttonItemList.push(item);
|
|
6456
|
+
this.appendButton(editor, item);
|
|
6384
6457
|
return;
|
|
6385
6458
|
}
|
|
6386
6459
|
if (item.type === 'dropdown') {
|
|
6387
|
-
allMenuMap.set(item.name, Dropdown.getMenuMap(item.menuItems));
|
|
6388
|
-
dropdownItemList.push(item);
|
|
6389
|
-
this.appendDropdown(item);
|
|
6460
|
+
this.allMenuMap.set(item.name, Dropdown.getMenuMap(item.menuItems));
|
|
6461
|
+
this.dropdownItemList.push(item);
|
|
6462
|
+
this.appendDropdown(editor, item);
|
|
6390
6463
|
return;
|
|
6391
6464
|
}
|
|
6392
6465
|
if (item.type === 'upload') {
|
|
6393
|
-
this.appendUpload(item);
|
|
6394
|
-
}
|
|
6395
|
-
});
|
|
6396
|
-
editor.event.on('statechange', data => {
|
|
6397
|
-
var _a;
|
|
6398
|
-
const { appliedItems, disabledNameMap, selectedNameMap, selectedValuesMap } = data;
|
|
6399
|
-
for (const item of buttonItemList) {
|
|
6400
|
-
const selectedClass = 'lake-button-selected';
|
|
6401
|
-
const buttonNode = this.container.find(`button[name="${item.name}"]`);
|
|
6402
|
-
let isDisabled = disabledNameMap.get(item.name);
|
|
6403
|
-
if (isDisabled === undefined) {
|
|
6404
|
-
isDisabled = item.isDisabled && appliedItems.length > 0 ? item.isDisabled(appliedItems) : false;
|
|
6405
|
-
}
|
|
6406
|
-
if (isDisabled) {
|
|
6407
|
-
buttonNode.attr('disabled', 'true');
|
|
6408
|
-
buttonNode.removeClass(selectedClass);
|
|
6409
|
-
}
|
|
6410
|
-
else {
|
|
6411
|
-
buttonNode.removeAttr('disabled');
|
|
6412
|
-
}
|
|
6413
|
-
if (!isDisabled) {
|
|
6414
|
-
let isSelected = selectedNameMap.get(item.name);
|
|
6415
|
-
if (isSelected === undefined) {
|
|
6416
|
-
isSelected = item.isSelected && appliedItems.length > 0 ? item.isSelected(appliedItems) : false;
|
|
6417
|
-
}
|
|
6418
|
-
if (isSelected) {
|
|
6419
|
-
buttonNode.addClass(selectedClass);
|
|
6420
|
-
}
|
|
6421
|
-
else {
|
|
6422
|
-
buttonNode.removeClass(selectedClass);
|
|
6423
|
-
}
|
|
6424
|
-
}
|
|
6425
|
-
}
|
|
6426
|
-
for (const item of dropdownItemList) {
|
|
6427
|
-
let selectedValues = selectedValuesMap.get(item.name);
|
|
6428
|
-
if (selectedValues === undefined) {
|
|
6429
|
-
selectedValues = item.selectedValues && appliedItems.length > 0 ? item.selectedValues(appliedItems) : [];
|
|
6430
|
-
}
|
|
6431
|
-
const dropdownNode = this.container.find(`div.lake-dropdown[name="${item.name}"]`);
|
|
6432
|
-
let isDisabled = disabledNameMap.get(item.name);
|
|
6433
|
-
if (isDisabled === undefined) {
|
|
6434
|
-
isDisabled = item.isDisabled && appliedItems.length > 0 ? item.isDisabled(appliedItems) : false;
|
|
6435
|
-
}
|
|
6436
|
-
if (isDisabled) {
|
|
6437
|
-
dropdownNode.attr('disabled', 'true');
|
|
6438
|
-
}
|
|
6439
|
-
else {
|
|
6440
|
-
dropdownNode.removeAttr('disabled');
|
|
6441
|
-
}
|
|
6442
|
-
if (!isDisabled) {
|
|
6443
|
-
Dropdown.setValue(dropdownNode, selectedValues);
|
|
6444
|
-
const textNode = dropdownNode.find('.lake-dropdown-text');
|
|
6445
|
-
if (textNode.length > 0) {
|
|
6446
|
-
const key = selectedValues[0] || item.defaultValue;
|
|
6447
|
-
const menuMap = allMenuMap.get(item.name);
|
|
6448
|
-
const text = (_a = (menuMap && menuMap.get(key))) !== null && _a !== void 0 ? _a : key;
|
|
6449
|
-
textNode.text(text);
|
|
6450
|
-
}
|
|
6451
|
-
}
|
|
6466
|
+
this.appendUpload(editor, item);
|
|
6452
6467
|
}
|
|
6453
6468
|
});
|
|
6454
6469
|
}
|
|
@@ -6932,47 +6947,80 @@ const imageBox = {
|
|
|
6932
6947
|
|
|
6933
6948
|
const config = {
|
|
6934
6949
|
defaultLang: 'text',
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6950
|
+
comment: '#57606a',
|
|
6951
|
+
name: '#444d56',
|
|
6952
|
+
variableName: '#953800',
|
|
6953
|
+
typeName: '#0550ae',
|
|
6954
|
+
propertyName: '#444d56',
|
|
6955
|
+
className: '#24292e',
|
|
6956
|
+
labelName: '#005cc5',
|
|
6957
|
+
namespace: '#0550ae',
|
|
6958
|
+
macroName: '#444d56',
|
|
6959
|
+
literal: '#444d56',
|
|
6943
6960
|
string: '#0a3069',
|
|
6944
|
-
constant: '#0550ae',
|
|
6945
|
-
type: '#24292f',
|
|
6946
|
-
class: '#24292e',
|
|
6947
6961
|
number: '#0550ae',
|
|
6948
|
-
|
|
6962
|
+
bool: '#0550ae',
|
|
6963
|
+
regexp: '#116329',
|
|
6964
|
+
color: '#0550ae',
|
|
6965
|
+
keyword: '#cf222e',
|
|
6966
|
+
modifier: '#24292f',
|
|
6967
|
+
operator: '#cf222e',
|
|
6968
|
+
bracket: '#57606a',
|
|
6969
|
+
content: '#57606a',
|
|
6970
|
+
meta: '#8250df',
|
|
6949
6971
|
heading: '#0550ae',
|
|
6950
6972
|
invalid: '#f6f8fa',
|
|
6951
|
-
|
|
6973
|
+
definition: '#cf222e',
|
|
6974
|
+
constant: '#0550ae',
|
|
6975
|
+
function: '#005cc5',
|
|
6976
|
+
standard: '#444d56',
|
|
6977
|
+
special: '#444d56',
|
|
6952
6978
|
};
|
|
6979
|
+
// https://lezer.codemirror.net/docs/ref/#highlight.tags
|
|
6953
6980
|
function getHighlightStyle(CodeMirror) {
|
|
6954
6981
|
const { HighlightStyle, tags } = CodeMirror;
|
|
6955
6982
|
return HighlightStyle.define([
|
|
6956
|
-
{ tag: tags.
|
|
6957
|
-
{ tag: [tags.name
|
|
6958
|
-
{ tag: [tags.
|
|
6959
|
-
{ tag: [tags.
|
|
6960
|
-
{ tag: [tags.
|
|
6961
|
-
{ tag: [tags.
|
|
6962
|
-
{ tag: [tags.
|
|
6963
|
-
{ tag: [tags.
|
|
6964
|
-
{ tag: [tags.
|
|
6965
|
-
{ tag: [tags.
|
|
6966
|
-
{ tag: [tags.
|
|
6967
|
-
{ tag: [tags.
|
|
6968
|
-
{ tag: [tags.
|
|
6983
|
+
{ tag: [tags.comment, tags.lineComment, tags.blockComment, tags.docComment], color: config.comment },
|
|
6984
|
+
{ tag: [tags.name], color: config.name },
|
|
6985
|
+
{ tag: [tags.variableName, tags.self], color: config.variableName },
|
|
6986
|
+
{ tag: [tags.typeName, tags.tagName], color: config.typeName },
|
|
6987
|
+
{ tag: [tags.propertyName, tags.attributeName], color: config.propertyName },
|
|
6988
|
+
{ tag: [tags.className], color: config.className },
|
|
6989
|
+
{ tag: [tags.labelName], color: config.labelName },
|
|
6990
|
+
{ tag: [tags.namespace], color: config.namespace },
|
|
6991
|
+
{ tag: [tags.macroName], color: config.macroName },
|
|
6992
|
+
{ tag: [tags.literal], color: config.literal },
|
|
6993
|
+
{ tag: [tags.string, tags.docString, tags.character, tags.attributeValue, tags.unit], color: config.string },
|
|
6994
|
+
{ tag: [tags.number, tags.integer, tags.float], color: config.number },
|
|
6995
|
+
{ tag: [tags.bool, tags.null, tags.atom], color: config.bool },
|
|
6996
|
+
{ tag: [tags.regexp, tags.escape, tags.url], color: config.regexp },
|
|
6997
|
+
{ tag: [tags.color], color: config.color },
|
|
6998
|
+
{ tag: [
|
|
6999
|
+
tags.keyword, tags.operatorKeyword, tags.controlKeyword,
|
|
7000
|
+
tags.definitionKeyword, tags.moduleKeyword,
|
|
7001
|
+
], color: config.keyword },
|
|
7002
|
+
{ tag: [tags.modifier], color: config.modifier },
|
|
7003
|
+
{ tag: [
|
|
7004
|
+
tags.operator, tags.derefOperator, tags.arithmeticOperator, tags.logicOperator, tags.bitwiseOperator,
|
|
7005
|
+
tags.compareOperator, tags.updateOperator, tags.definitionOperator, tags.typeOperator, tags.controlOperator,
|
|
7006
|
+
], color: config.operator },
|
|
7007
|
+
{ tag: [
|
|
7008
|
+
tags.punctuation, tags.separator, tags.bracket, tags.angleBracket, tags.squareBracket,
|
|
7009
|
+
tags.paren, tags.brace, tags.contentSeparator,
|
|
7010
|
+
], color: config.bracket },
|
|
7011
|
+
{ tag: [tags.content], color: config.content },
|
|
7012
|
+
{ tag: [tags.meta, tags.documentMeta, tags.annotation, tags.processingInstruction], color: config.meta },
|
|
7013
|
+
{ tag: tags.heading, fontWeight: 'bold', color: config.heading },
|
|
6969
7014
|
{ tag: tags.strong, fontWeight: 'bold' },
|
|
6970
7015
|
{ tag: tags.emphasis, fontStyle: 'italic' },
|
|
6971
7016
|
{ tag: tags.link, textDecoration: 'underline' },
|
|
6972
|
-
{ tag: tags.heading, fontWeight: 'bold', color: config.heading },
|
|
6973
|
-
{ tag: [tags.atom, tags.bool, tags.special(tags.variableName)], color: config.variable },
|
|
6974
|
-
{ tag: tags.invalid, color: config.invalid },
|
|
6975
7017
|
{ tag: tags.strikethrough, textDecoration: 'line-through' },
|
|
7018
|
+
{ tag: [tags.invalid, tags.inserted, tags.deleted, tags.changed], color: config.invalid },
|
|
7019
|
+
{ tag: [tags.definition(tags.name)], color: config.definition },
|
|
7020
|
+
{ tag: [tags.constant(tags.name)], color: config.constant },
|
|
7021
|
+
{ tag: [tags.function(tags.variableName)], color: config.function },
|
|
7022
|
+
{ tag: [tags.standard(tags.name)], color: config.standard },
|
|
7023
|
+
{ tag: [tags.special(tags.variableName)], color: config.special },
|
|
6976
7024
|
]);
|
|
6977
7025
|
}
|
|
6978
7026
|
const codeBlockBox = {
|
|
@@ -6996,7 +7044,10 @@ const codeBlockBox = {
|
|
|
6996
7044
|
const CodeMirror = window.CodeMirror;
|
|
6997
7045
|
if (!CodeMirror) {
|
|
6998
7046
|
codeBlockNode.addClass('lake-code-block-error');
|
|
6999
|
-
codeBlockNode.text(
|
|
7047
|
+
codeBlockNode.text(`
|
|
7048
|
+
The code cannot be displayed because window.CodeMirror is not found.
|
|
7049
|
+
Please check if the CodeMirror file is added to this page.
|
|
7050
|
+
`.trim());
|
|
7000
7051
|
codeBlockNode.on('click', () => {
|
|
7001
7052
|
editor.selection.range.selectBox(box.node);
|
|
7002
7053
|
});
|
|
@@ -7086,7 +7137,7 @@ var copy = (editor) => {
|
|
|
7086
7137
|
if (boxNode.length === 0) {
|
|
7087
7138
|
return;
|
|
7088
7139
|
}
|
|
7089
|
-
if (range.
|
|
7140
|
+
if (range.isBoxStart || range.isBoxEnd) {
|
|
7090
7141
|
return;
|
|
7091
7142
|
}
|
|
7092
7143
|
event.preventDefault();
|
|
@@ -7110,7 +7161,7 @@ var cut = (editor) => {
|
|
|
7110
7161
|
if (boxNode.length === 0) {
|
|
7111
7162
|
return;
|
|
7112
7163
|
}
|
|
7113
|
-
if (range.
|
|
7164
|
+
if (range.isBoxStart || range.isBoxEnd) {
|
|
7114
7165
|
return;
|
|
7115
7166
|
}
|
|
7116
7167
|
event.preventDefault();
|
|
@@ -7185,11 +7236,11 @@ function insertFirstNode(editor, otherNode) {
|
|
|
7185
7236
|
if (boxNode.length > 0) {
|
|
7186
7237
|
const box = new Box(boxNode);
|
|
7187
7238
|
if (box.type === 'inline') {
|
|
7188
|
-
if (range.
|
|
7239
|
+
if (range.isBoxStart) {
|
|
7189
7240
|
range.setStartBefore(boxNode);
|
|
7190
7241
|
range.collapseToStart();
|
|
7191
7242
|
}
|
|
7192
|
-
else if (range.
|
|
7243
|
+
else if (range.isBoxEnd) {
|
|
7193
7244
|
range.setStartAfter(boxNode);
|
|
7194
7245
|
range.collapseToStart();
|
|
7195
7246
|
}
|
|
@@ -7199,11 +7250,11 @@ function insertFirstNode(editor, otherNode) {
|
|
|
7199
7250
|
}
|
|
7200
7251
|
else {
|
|
7201
7252
|
const paragraph = query('<p />');
|
|
7202
|
-
if (range.
|
|
7253
|
+
if (range.isBoxStart) {
|
|
7203
7254
|
boxNode.before(paragraph);
|
|
7204
7255
|
range.shrinkAfter(paragraph);
|
|
7205
7256
|
}
|
|
7206
|
-
else if (range.
|
|
7257
|
+
else if (range.isBoxEnd) {
|
|
7207
7258
|
boxNode.after(paragraph);
|
|
7208
7259
|
range.shrinkAfter(paragraph);
|
|
7209
7260
|
}
|
|
@@ -7267,12 +7318,12 @@ function pasteFragment(editor, fragment) {
|
|
|
7267
7318
|
// insert fragment
|
|
7268
7319
|
if (fragment.childNodes.length > 0) {
|
|
7269
7320
|
const parts = selection.splitBlock();
|
|
7270
|
-
if (parts.
|
|
7271
|
-
range.setEndAfter(parts.
|
|
7321
|
+
if (parts.start) {
|
|
7322
|
+
range.setEndAfter(parts.start);
|
|
7272
7323
|
range.collapseToEnd();
|
|
7273
7324
|
}
|
|
7274
|
-
if (parts.
|
|
7275
|
-
parts.
|
|
7325
|
+
if (parts.end && parts.end.isEmpty) {
|
|
7326
|
+
parts.end.remove();
|
|
7276
7327
|
}
|
|
7277
7328
|
selection.insertFragment(fragment);
|
|
7278
7329
|
range.shrinkAfter(lastNode);
|
|
@@ -8101,6 +8152,9 @@ var image = (editor) => {
|
|
|
8101
8152
|
};
|
|
8102
8153
|
|
|
8103
8154
|
var codeBlock = (editor) => {
|
|
8155
|
+
if (!window.CodeMirror) {
|
|
8156
|
+
return;
|
|
8157
|
+
}
|
|
8104
8158
|
editor.command.add('codeBlock', {
|
|
8105
8159
|
execute: (value) => {
|
|
8106
8160
|
const box = editor.insertBox('codeBlock', value);
|
|
@@ -8278,6 +8332,11 @@ function executeMarkCommand(editor, point) {
|
|
|
8278
8332
|
for (const item of markItemList) {
|
|
8279
8333
|
const results = item.re.exec(text);
|
|
8280
8334
|
if (results !== null) {
|
|
8335
|
+
const parameters = item.getParameters();
|
|
8336
|
+
const commandName = parameters.shift();
|
|
8337
|
+
if (!editor.command.has(commandName)) {
|
|
8338
|
+
return false;
|
|
8339
|
+
}
|
|
8281
8340
|
// <p>foo**bold**<focus /></p>, offset = 11
|
|
8282
8341
|
// to
|
|
8283
8342
|
// <p>foobold\u200B<focus /></p>,
|
|
@@ -8291,8 +8350,7 @@ function executeMarkCommand(editor, point) {
|
|
|
8291
8350
|
node.get(0).nodeValue = newValue;
|
|
8292
8351
|
range.setStart(node, offset - results[0].length);
|
|
8293
8352
|
range.setEnd(node, offset - (oldValue.length - newValue.length) - 1);
|
|
8294
|
-
|
|
8295
|
-
editor.command.execute(parameters.shift(), ...parameters);
|
|
8353
|
+
editor.command.execute(commandName, ...parameters);
|
|
8296
8354
|
selection.toBookmark(bookmark);
|
|
8297
8355
|
editor.commitOperation();
|
|
8298
8356
|
return true;
|
|
@@ -8308,6 +8366,11 @@ function spaceKeyExecutesBlockCommand(editor, point) {
|
|
|
8308
8366
|
for (const item of blockItemListForSpaceKey) {
|
|
8309
8367
|
const results = item.re.exec(text);
|
|
8310
8368
|
if (results !== null) {
|
|
8369
|
+
const parameters = item.getParameters(results);
|
|
8370
|
+
const commandName = parameters.shift();
|
|
8371
|
+
if (!editor.command.has(commandName)) {
|
|
8372
|
+
return false;
|
|
8373
|
+
}
|
|
8311
8374
|
// <p>#<focus />foo</p>
|
|
8312
8375
|
// to
|
|
8313
8376
|
// <h1><focus />foo</h1>
|
|
@@ -8318,8 +8381,7 @@ function spaceKeyExecutesBlockCommand(editor, point) {
|
|
|
8318
8381
|
const block = bookmark.focus.closestBlock();
|
|
8319
8382
|
fixEmptyBlock(block);
|
|
8320
8383
|
selection.range.shrinkAfter(block);
|
|
8321
|
-
|
|
8322
|
-
editor.command.execute(parameters.shift(), ...parameters);
|
|
8384
|
+
editor.command.execute(commandName, ...parameters);
|
|
8323
8385
|
selection.toBookmark(bookmark);
|
|
8324
8386
|
editor.commitOperation();
|
|
8325
8387
|
return true;
|
|
@@ -8334,15 +8396,19 @@ function enterKeyExecutesBlockCommand(editor, block) {
|
|
|
8334
8396
|
for (const item of blockItemListForEnterKey) {
|
|
8335
8397
|
const results = item.re.exec(text);
|
|
8336
8398
|
if (results !== null) {
|
|
8399
|
+
const parameters = item.getParameters(results);
|
|
8400
|
+
const commandName = parameters.shift();
|
|
8401
|
+
if (!editor.command.has(commandName)) {
|
|
8402
|
+
return false;
|
|
8403
|
+
}
|
|
8337
8404
|
// <p>---<focus /></p>
|
|
8338
8405
|
// to
|
|
8339
|
-
// <lake-box type="block" name="hr" focus="
|
|
8406
|
+
// <lake-box type="block" name="hr" focus="end"></lake-box>
|
|
8340
8407
|
editor.prepareOperation();
|
|
8341
8408
|
block.empty();
|
|
8342
8409
|
fixEmptyBlock(block);
|
|
8343
8410
|
selection.range.shrinkAfter(block);
|
|
8344
|
-
|
|
8345
|
-
editor.command.execute(parameters.shift(), ...parameters);
|
|
8411
|
+
editor.command.execute(commandName, ...parameters);
|
|
8346
8412
|
editor.commitOperation();
|
|
8347
8413
|
return true;
|
|
8348
8414
|
}
|
|
@@ -8391,7 +8457,7 @@ var markdown = (editor) => {
|
|
|
8391
8457
|
if (block.find('lake-box').length > 0) {
|
|
8392
8458
|
return;
|
|
8393
8459
|
}
|
|
8394
|
-
if (range.
|
|
8460
|
+
if (range.getEndText() !== '') {
|
|
8395
8461
|
return;
|
|
8396
8462
|
}
|
|
8397
8463
|
if (enterKeyExecutesBlockCommand(editor, block)) {
|
|
@@ -8405,14 +8471,14 @@ var markdown = (editor) => {
|
|
|
8405
8471
|
|
|
8406
8472
|
function splitBlock(editor, block) {
|
|
8407
8473
|
const range = editor.selection.range;
|
|
8408
|
-
const
|
|
8474
|
+
const endText = range.getEndText();
|
|
8409
8475
|
editor.selection.splitBlock();
|
|
8410
8476
|
block = range.getBlocks()[0];
|
|
8411
8477
|
if (!block) {
|
|
8412
8478
|
editor.history.save();
|
|
8413
8479
|
return;
|
|
8414
8480
|
}
|
|
8415
|
-
if (
|
|
8481
|
+
if (endText === '' && (block.isHeading || block.name === 'blockquote')) {
|
|
8416
8482
|
editor.selection.setBlocks('<p />');
|
|
8417
8483
|
editor.history.save();
|
|
8418
8484
|
return;
|
|
@@ -8426,12 +8492,12 @@ function addBlockOrSplitBlockForBox(editor) {
|
|
|
8426
8492
|
const boxNode = range.startNode.closest('lake-box');
|
|
8427
8493
|
const block = boxNode.closestBlock();
|
|
8428
8494
|
if (block.length > 0 && !block.isContainer) {
|
|
8429
|
-
if (range.
|
|
8495
|
+
if (range.isBoxStart) {
|
|
8430
8496
|
range.setStartBefore(boxNode);
|
|
8431
8497
|
range.collapseToStart();
|
|
8432
8498
|
splitBlock(editor, block);
|
|
8433
8499
|
}
|
|
8434
|
-
else if (range.
|
|
8500
|
+
else if (range.isBoxEnd) {
|
|
8435
8501
|
range.setStartAfter(boxNode);
|
|
8436
8502
|
range.collapseToStart();
|
|
8437
8503
|
splitBlock(editor, block);
|
|
@@ -8442,10 +8508,10 @@ function addBlockOrSplitBlockForBox(editor) {
|
|
|
8442
8508
|
return;
|
|
8443
8509
|
}
|
|
8444
8510
|
const newBlock = query('<p><br /></p>');
|
|
8445
|
-
if (range.
|
|
8511
|
+
if (range.isBoxStart) {
|
|
8446
8512
|
boxNode.before(newBlock);
|
|
8447
8513
|
}
|
|
8448
|
-
else if (range.
|
|
8514
|
+
else if (range.isBoxEnd) {
|
|
8449
8515
|
boxNode.after(newBlock);
|
|
8450
8516
|
range.shrinkAfter(newBlock);
|
|
8451
8517
|
}
|
|
@@ -8495,8 +8561,8 @@ function addLineBreak(editor) {
|
|
|
8495
8561
|
const block = range.startNode.closestBlock();
|
|
8496
8562
|
if (block.length > 0 && !block.isContainer) {
|
|
8497
8563
|
const prevNode = range.getPrevNode();
|
|
8498
|
-
const
|
|
8499
|
-
if (prevNode.name !== 'br' &&
|
|
8564
|
+
const endText = range.getEndText();
|
|
8565
|
+
if (prevNode.name !== 'br' && endText === '') {
|
|
8500
8566
|
editor.selection.insertContents('<br /><br />');
|
|
8501
8567
|
editor.history.save();
|
|
8502
8568
|
return;
|
|
@@ -8509,12 +8575,12 @@ function addBlockOrLineBreakForBox(editor) {
|
|
|
8509
8575
|
const boxNode = range.startNode.closest('lake-box');
|
|
8510
8576
|
const block = boxNode.closestBlock();
|
|
8511
8577
|
if (block.length > 0 && !block.isContainer) {
|
|
8512
|
-
if (range.
|
|
8578
|
+
if (range.isBoxStart) {
|
|
8513
8579
|
range.setStartBefore(boxNode);
|
|
8514
8580
|
range.collapseToStart();
|
|
8515
8581
|
addLineBreak(editor);
|
|
8516
8582
|
}
|
|
8517
|
-
else if (range.
|
|
8583
|
+
else if (range.isBoxEnd) {
|
|
8518
8584
|
range.setStartAfter(boxNode);
|
|
8519
8585
|
range.collapseToStart();
|
|
8520
8586
|
addLineBreak(editor);
|
|
@@ -8525,10 +8591,10 @@ function addBlockOrLineBreakForBox(editor) {
|
|
|
8525
8591
|
return;
|
|
8526
8592
|
}
|
|
8527
8593
|
const newBlock = query('<p><br /></p>');
|
|
8528
|
-
if (range.
|
|
8594
|
+
if (range.isBoxStart) {
|
|
8529
8595
|
boxNode.before(newBlock);
|
|
8530
8596
|
}
|
|
8531
|
-
else if (range.
|
|
8597
|
+
else if (range.isBoxEnd) {
|
|
8532
8598
|
boxNode.after(newBlock);
|
|
8533
8599
|
range.shrinkAfter(newBlock);
|
|
8534
8600
|
}
|
|
@@ -8576,7 +8642,7 @@ function mergeWithPreviousBlock(editor, block) {
|
|
|
8576
8642
|
if (block.isEmpty) {
|
|
8577
8643
|
block.remove();
|
|
8578
8644
|
}
|
|
8579
|
-
range.
|
|
8645
|
+
range.selectBoxEnd(prevBlock);
|
|
8580
8646
|
return;
|
|
8581
8647
|
}
|
|
8582
8648
|
if (prevBlock.name === 'br') {
|
|
@@ -8605,7 +8671,7 @@ var backspaceKey = (editor) => {
|
|
|
8605
8671
|
return;
|
|
8606
8672
|
}
|
|
8607
8673
|
editor.rectifyContent();
|
|
8608
|
-
if (range.
|
|
8674
|
+
if (range.isBoxStart) {
|
|
8609
8675
|
const boxNode = range.startNode.closest('lake-box');
|
|
8610
8676
|
const prevNode = boxNode.prev();
|
|
8611
8677
|
if (prevNode.length === 0) {
|
|
@@ -8663,8 +8729,8 @@ var backspaceKey = (editor) => {
|
|
|
8663
8729
|
editor.history.save();
|
|
8664
8730
|
return;
|
|
8665
8731
|
}
|
|
8666
|
-
const
|
|
8667
|
-
if (
|
|
8732
|
+
const startText = range.getStartText();
|
|
8733
|
+
if (startText === '') {
|
|
8668
8734
|
event.preventDefault();
|
|
8669
8735
|
let block = range.getBlocks()[0];
|
|
8670
8736
|
if (!block) {
|
|
@@ -8700,7 +8766,7 @@ function mergeWithNextBlock(editor, block) {
|
|
|
8700
8766
|
if (block.isEmpty) {
|
|
8701
8767
|
block.remove();
|
|
8702
8768
|
}
|
|
8703
|
-
range.
|
|
8769
|
+
range.selectBoxStart(nextBlock);
|
|
8704
8770
|
editor.history.save();
|
|
8705
8771
|
return;
|
|
8706
8772
|
}
|
|
@@ -8722,7 +8788,7 @@ var deleteKey = (editor) => {
|
|
|
8722
8788
|
return;
|
|
8723
8789
|
}
|
|
8724
8790
|
editor.rectifyContent();
|
|
8725
|
-
if (range.
|
|
8791
|
+
if (range.isBoxEnd) {
|
|
8726
8792
|
const boxNode = range.startNode.closest('lake-box');
|
|
8727
8793
|
const nextNode = boxNode.next();
|
|
8728
8794
|
if (nextNode.length === 0) {
|
|
@@ -8779,8 +8845,8 @@ var deleteKey = (editor) => {
|
|
|
8779
8845
|
nextNode.remove();
|
|
8780
8846
|
editor.history.save();
|
|
8781
8847
|
}
|
|
8782
|
-
const
|
|
8783
|
-
if (
|
|
8848
|
+
const endText = range.getEndText();
|
|
8849
|
+
if (endText === '') {
|
|
8784
8850
|
event.preventDefault();
|
|
8785
8851
|
let block = range.getBlocks()[0];
|
|
8786
8852
|
if (!block) {
|
|
@@ -8819,7 +8885,7 @@ var arrowKeys = (editor) => {
|
|
|
8819
8885
|
}
|
|
8820
8886
|
const boxNode = range.commonAncestor.closest('lake-box');
|
|
8821
8887
|
if (boxNode.length > 0) {
|
|
8822
|
-
if (range.
|
|
8888
|
+
if (range.isBoxStart) {
|
|
8823
8889
|
const prevNode = boxNode.prev();
|
|
8824
8890
|
if (prevNode.isBlock || prevNode.isBox) {
|
|
8825
8891
|
event.preventDefault();
|
|
@@ -8834,13 +8900,13 @@ var arrowKeys = (editor) => {
|
|
|
8834
8900
|
range.collapseToStart();
|
|
8835
8901
|
return;
|
|
8836
8902
|
}
|
|
8837
|
-
if (range.
|
|
8903
|
+
if (range.isBoxEnd) {
|
|
8838
8904
|
event.preventDefault();
|
|
8839
8905
|
range.selectBox(boxNode);
|
|
8840
8906
|
return;
|
|
8841
8907
|
}
|
|
8842
8908
|
event.preventDefault();
|
|
8843
|
-
range.
|
|
8909
|
+
range.selectBoxStart(boxNode);
|
|
8844
8910
|
return;
|
|
8845
8911
|
}
|
|
8846
8912
|
if (!range.isCollapsed) {
|
|
@@ -8859,12 +8925,12 @@ var arrowKeys = (editor) => {
|
|
|
8859
8925
|
}
|
|
8860
8926
|
const boxNode = range.commonAncestor.closest('lake-box');
|
|
8861
8927
|
if (boxNode.length > 0) {
|
|
8862
|
-
if (range.
|
|
8928
|
+
if (range.isBoxStart) {
|
|
8863
8929
|
event.preventDefault();
|
|
8864
8930
|
range.selectBox(boxNode);
|
|
8865
8931
|
return;
|
|
8866
8932
|
}
|
|
8867
|
-
if (range.
|
|
8933
|
+
if (range.isBoxEnd) {
|
|
8868
8934
|
const nextNode = boxNode.next();
|
|
8869
8935
|
if (nextNode.isBlock || nextNode.isBox) {
|
|
8870
8936
|
event.preventDefault();
|
|
@@ -8880,7 +8946,7 @@ var arrowKeys = (editor) => {
|
|
|
8880
8946
|
return;
|
|
8881
8947
|
}
|
|
8882
8948
|
event.preventDefault();
|
|
8883
|
-
range.
|
|
8949
|
+
range.selectBoxEnd(boxNode);
|
|
8884
8950
|
return;
|
|
8885
8951
|
}
|
|
8886
8952
|
if (!range.isCollapsed) {
|
|
@@ -8932,6 +8998,24 @@ var arrowKeys = (editor) => {
|
|
|
8932
8998
|
});
|
|
8933
8999
|
};
|
|
8934
9000
|
|
|
9001
|
+
var escapeKey = (editor) => {
|
|
9002
|
+
editor.keystroke.setKeydown('escape', event => {
|
|
9003
|
+
const selection = editor.selection;
|
|
9004
|
+
const range = selection.range;
|
|
9005
|
+
if (range.isBoxCenter || range.isInsideBox) {
|
|
9006
|
+
event.preventDefault();
|
|
9007
|
+
const boxNode = range.commonAncestor.closest('lake-box');
|
|
9008
|
+
range.selectBoxEnd(boxNode);
|
|
9009
|
+
selection.addRangeToNativeSelection();
|
|
9010
|
+
return;
|
|
9011
|
+
}
|
|
9012
|
+
if (editor.root.hasClass('lake-root-focused')) {
|
|
9013
|
+
event.preventDefault();
|
|
9014
|
+
editor.blur();
|
|
9015
|
+
}
|
|
9016
|
+
});
|
|
9017
|
+
};
|
|
9018
|
+
|
|
8935
9019
|
Editor.box.add(hrBox);
|
|
8936
9020
|
Editor.box.add(imageBox);
|
|
8937
9021
|
Editor.box.add(codeBlockBox);
|
|
@@ -8970,6 +9054,7 @@ Editor.plugin.add(backspaceKey);
|
|
|
8970
9054
|
Editor.plugin.add(deleteKey);
|
|
8971
9055
|
Editor.plugin.add(tabKey);
|
|
8972
9056
|
Editor.plugin.add(arrowKeys);
|
|
9057
|
+
Editor.plugin.add(escapeKey);
|
|
8973
9058
|
|
|
8974
9059
|
export { Box, Button, Dropdown, Editor, Fragment, HTMLParser, Nodes, Range, TextParser, Toolbar, index as Utils, addMark, deleteContents, fixList, icons, insertBookmark, insertContents, insertFragment, insertLink, insertNode, removeMark, setBlocks, splitBlock$1 as splitBlock, splitMarks, toBookmark };
|
|
8975
9060
|
//# sourceMappingURL=lake.js.map
|