@kaitify/core 0.0.1-beta.18 → 0.0.1-beta.19
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/kaitify-core.es.js
CHANGED
|
@@ -1393,16 +1393,17 @@ const kebabToCamel = (val) => {
|
|
|
1393
1393
|
return val.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
1394
1394
|
};
|
|
1395
1395
|
const getDomAttributes = (dom) => {
|
|
1396
|
-
|
|
1397
|
-
const length =
|
|
1396
|
+
const attributes = Array.from(dom.attributes);
|
|
1397
|
+
const length = attributes.length;
|
|
1398
|
+
const regExp = new RegExp(`(^on)|(^style$)|(^${NODE_MARK}$)`, "g");
|
|
1399
|
+
const result = {};
|
|
1398
1400
|
for (let i = 0; i < length; i++) {
|
|
1399
|
-
const
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
o[attribute.nodeName] = attribute.nodeValue || "";
|
|
1401
|
+
const { nodeName, nodeValue } = attributes[i];
|
|
1402
|
+
if (!regExp.test(nodeName)) {
|
|
1403
|
+
result[nodeName] = nodeValue ?? "";
|
|
1403
1404
|
}
|
|
1404
1405
|
}
|
|
1405
|
-
return
|
|
1406
|
+
return result;
|
|
1406
1407
|
};
|
|
1407
1408
|
const getDomStyles = (dom) => {
|
|
1408
1409
|
let o = {};
|
|
@@ -1540,14 +1541,10 @@ class KNode {
|
|
|
1540
1541
|
void: this.void
|
|
1541
1542
|
});
|
|
1542
1543
|
if (deep && this.hasChildren()) {
|
|
1543
|
-
this.children.
|
|
1544
|
+
newNode2.children = this.children.map((child) => {
|
|
1544
1545
|
const newChild = child.clone(deep);
|
|
1545
|
-
if (newNode2.hasChildren()) {
|
|
1546
|
-
newNode2.children.push(newChild);
|
|
1547
|
-
} else {
|
|
1548
|
-
newNode2.children = [newChild];
|
|
1549
|
-
}
|
|
1550
1546
|
newChild.parent = newNode2;
|
|
1547
|
+
return newChild;
|
|
1551
1548
|
});
|
|
1552
1549
|
}
|
|
1553
1550
|
return newNode2;
|
|
@@ -1555,7 +1552,7 @@ class KNode {
|
|
|
1555
1552
|
/**
|
|
1556
1553
|
* 【API】如果当前节点是文本节点或者闭合节点,则判断是不是指定节点后代中所有文本节点和闭合节点中的第一个
|
|
1557
1554
|
*/
|
|
1558
|
-
__publicField(this, "
|
|
1555
|
+
__publicField(this, "firstInTargetNode", (node) => {
|
|
1559
1556
|
if (!this.isText() && !this.isClosed()) {
|
|
1560
1557
|
return false;
|
|
1561
1558
|
}
|
|
@@ -1564,27 +1561,27 @@ class KNode {
|
|
|
1564
1561
|
}
|
|
1565
1562
|
if (node.isContains(this) && node.hasChildren()) {
|
|
1566
1563
|
const firstChild = node.children[0];
|
|
1567
|
-
return this.
|
|
1564
|
+
return this.firstInTargetNode(firstChild);
|
|
1568
1565
|
}
|
|
1569
1566
|
return false;
|
|
1570
1567
|
});
|
|
1571
1568
|
/**
|
|
1572
|
-
* 【API
|
|
1569
|
+
* 【API】获取当前节点下的所有可聚焦的节点,如果自身符合也会包括在内
|
|
1570
|
+
* 1. type 是 all 获取闭合节点和文本节点;
|
|
1571
|
+
* 2. type 是 closed 获取闭合节点;
|
|
1572
|
+
* 3. type 是 text 获取文本节点
|
|
1573
1573
|
*/
|
|
1574
1574
|
__publicField(this, "getFocusNodes", (type = "all") => {
|
|
1575
|
-
const nodes = [];
|
|
1576
1575
|
if (this.isClosed() && (type == "all" || type == "closed")) {
|
|
1577
|
-
|
|
1576
|
+
return [this];
|
|
1578
1577
|
}
|
|
1579
1578
|
if (this.isText() && (type == "all" || type == "text")) {
|
|
1580
|
-
|
|
1579
|
+
return [this];
|
|
1581
1580
|
}
|
|
1582
1581
|
if (this.hasChildren()) {
|
|
1583
|
-
this.children.
|
|
1584
|
-
nodes.push(...item.getFocusNodes(type));
|
|
1585
|
-
});
|
|
1582
|
+
return this.children.flatMap((item) => item.getFocusNodes(type));
|
|
1586
1583
|
}
|
|
1587
|
-
return
|
|
1584
|
+
return [];
|
|
1588
1585
|
});
|
|
1589
1586
|
}
|
|
1590
1587
|
/**
|
|
@@ -1658,7 +1655,10 @@ class KNode {
|
|
|
1658
1655
|
return !this.textContent;
|
|
1659
1656
|
}
|
|
1660
1657
|
if (this.isInline() || this.isBlock()) {
|
|
1661
|
-
|
|
1658
|
+
if (!this.hasChildren()) {
|
|
1659
|
+
return true;
|
|
1660
|
+
}
|
|
1661
|
+
return this.children.every((item) => {
|
|
1662
1662
|
return item.isEmpty();
|
|
1663
1663
|
});
|
|
1664
1664
|
}
|
|
@@ -1769,7 +1769,7 @@ class KNode {
|
|
|
1769
1769
|
return false;
|
|
1770
1770
|
}
|
|
1771
1771
|
/**
|
|
1772
|
-
* 【API
|
|
1772
|
+
* 【API】判断当前节点是否在拥有代码块样式的块级节点内(包括自身),是的话返回该块级节点,否则返回null
|
|
1773
1773
|
*/
|
|
1774
1774
|
isInCodeBlockStyle() {
|
|
1775
1775
|
const block = this.getBlock();
|
|
@@ -1824,14 +1824,10 @@ class KNode {
|
|
|
1824
1824
|
});
|
|
1825
1825
|
newNode2.key = this.key;
|
|
1826
1826
|
if (this.hasChildren()) {
|
|
1827
|
-
this.children.
|
|
1827
|
+
newNode2.children = this.children.map((child) => {
|
|
1828
1828
|
const newChild = child.fullClone();
|
|
1829
|
-
if (newNode2.hasChildren()) {
|
|
1830
|
-
newNode2.children.push(newChild);
|
|
1831
|
-
} else {
|
|
1832
|
-
newNode2.children = [newChild];
|
|
1833
|
-
}
|
|
1834
1829
|
newChild.parent = newNode2;
|
|
1830
|
+
return newChild;
|
|
1835
1831
|
});
|
|
1836
1832
|
}
|
|
1837
1833
|
return newNode2;
|
|
@@ -1839,7 +1835,7 @@ class KNode {
|
|
|
1839
1835
|
/**
|
|
1840
1836
|
* 【API】如果当前节点是文本节点或者闭合节点,则判断是不是指定节点后代中所有文本节点和闭合节点中的最后一个
|
|
1841
1837
|
*/
|
|
1842
|
-
|
|
1838
|
+
lastInTargetNode(node) {
|
|
1843
1839
|
if (!this.isText() && !this.isClosed()) {
|
|
1844
1840
|
return false;
|
|
1845
1841
|
}
|
|
@@ -1848,7 +1844,7 @@ class KNode {
|
|
|
1848
1844
|
}
|
|
1849
1845
|
if (node.isContains(this) && node.hasChildren()) {
|
|
1850
1846
|
const lastChild = node.children[node.children.length - 1];
|
|
1851
|
-
return this.
|
|
1847
|
+
return this.lastInTargetNode(lastChild);
|
|
1852
1848
|
}
|
|
1853
1849
|
return false;
|
|
1854
1850
|
}
|
|
@@ -1862,7 +1858,7 @@ class KNode {
|
|
|
1862
1858
|
}
|
|
1863
1859
|
const previousNode = nodes[index - 1];
|
|
1864
1860
|
if (previousNode.isEmpty()) {
|
|
1865
|
-
return
|
|
1861
|
+
return previousNode.getPrevious(nodes);
|
|
1866
1862
|
}
|
|
1867
1863
|
return previousNode;
|
|
1868
1864
|
}
|
|
@@ -1876,7 +1872,7 @@ class KNode {
|
|
|
1876
1872
|
}
|
|
1877
1873
|
const nextNode = nodes[index + 1];
|
|
1878
1874
|
if (nextNode.isEmpty()) {
|
|
1879
|
-
return
|
|
1875
|
+
return nextNode.getNext(nodes);
|
|
1880
1876
|
}
|
|
1881
1877
|
return nextNode;
|
|
1882
1878
|
}
|
|
@@ -1938,13 +1934,13 @@ class KNode {
|
|
|
1938
1934
|
knode.type = options.type;
|
|
1939
1935
|
knode.tag = options.tag;
|
|
1940
1936
|
knode.textContent = options.textContent;
|
|
1941
|
-
knode.fixed = options.fixed
|
|
1942
|
-
knode.locked = options.locked
|
|
1943
|
-
knode.nested = options.nested
|
|
1944
|
-
knode.void = options.void
|
|
1937
|
+
knode.fixed = options.fixed ?? false;
|
|
1938
|
+
knode.locked = options.locked ?? false;
|
|
1939
|
+
knode.nested = options.nested ?? false;
|
|
1940
|
+
knode.void = options.void ?? false;
|
|
1945
1941
|
knode.marks = common.clone(options.marks);
|
|
1946
1942
|
knode.styles = common.clone(options.styles);
|
|
1947
|
-
knode.namespace = options.namespace;
|
|
1943
|
+
knode.namespace = options.namespace ?? "";
|
|
1948
1944
|
knode.children = (_a = options.children) == null ? void 0 : _a.map((item) => {
|
|
1949
1945
|
const childNode = KNode.create(item);
|
|
1950
1946
|
childNode.parent = knode;
|
|
@@ -1984,38 +1980,33 @@ class KNode {
|
|
|
1984
1980
|
* 【API】将某个节点数组扁平化处理后返回
|
|
1985
1981
|
*/
|
|
1986
1982
|
static flat(nodes) {
|
|
1987
|
-
const
|
|
1988
|
-
const
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1983
|
+
const result = [];
|
|
1984
|
+
const stack = nodes.slice().reverse();
|
|
1985
|
+
while (stack.length > 0) {
|
|
1986
|
+
const node = stack.pop();
|
|
1987
|
+
result.push(node);
|
|
1988
|
+
if (node.hasChildren()) {
|
|
1989
|
+
stack.push(...node.children.slice().reverse());
|
|
1994
1990
|
}
|
|
1995
1991
|
}
|
|
1996
|
-
return
|
|
1992
|
+
return result;
|
|
1997
1993
|
}
|
|
1998
1994
|
/**
|
|
1999
1995
|
* 【API】在指定的节点数组中根据key查找节点
|
|
2000
1996
|
*/
|
|
2001
1997
|
static searchByKey(key, nodes) {
|
|
2002
|
-
|
|
2003
|
-
const
|
|
2004
|
-
|
|
2005
|
-
const
|
|
2006
|
-
if (
|
|
2007
|
-
node
|
|
2008
|
-
break;
|
|
1998
|
+
const stack = nodes.slice().reverse();
|
|
1999
|
+
const targetKey = Number(key);
|
|
2000
|
+
while (stack.length > 0) {
|
|
2001
|
+
const node = stack.pop();
|
|
2002
|
+
if (node.key === targetKey) {
|
|
2003
|
+
return node;
|
|
2009
2004
|
}
|
|
2010
|
-
if (
|
|
2011
|
-
|
|
2012
|
-
if (n) {
|
|
2013
|
-
node = n;
|
|
2014
|
-
break;
|
|
2015
|
-
}
|
|
2005
|
+
if (node.hasChildren()) {
|
|
2006
|
+
stack.push(...node.children.slice().reverse());
|
|
2016
2007
|
}
|
|
2017
2008
|
}
|
|
2018
|
-
return
|
|
2009
|
+
return null;
|
|
2019
2010
|
}
|
|
2020
2011
|
}
|
|
2021
2012
|
class Selection {
|
|
@@ -2156,21 +2147,24 @@ const splitNodeToNodes = function(node) {
|
|
|
2156
2147
|
}
|
|
2157
2148
|
};
|
|
2158
2149
|
const emptyFixedBlock = function(node) {
|
|
2150
|
+
var _a;
|
|
2159
2151
|
if (!node.isBlock()) {
|
|
2160
2152
|
return;
|
|
2161
2153
|
}
|
|
2162
2154
|
if (node.hasChildren()) {
|
|
2163
|
-
node.children.
|
|
2155
|
+
node.children = (_a = node.children) == null ? void 0 : _a.filter((item) => {
|
|
2164
2156
|
if (item.isBlock() && item.fixed) {
|
|
2165
2157
|
emptyFixedBlock.apply(this, [item]);
|
|
2158
|
+
return true;
|
|
2166
2159
|
} else {
|
|
2167
2160
|
item.toEmpty();
|
|
2168
|
-
|
|
2169
|
-
const placeholderNode = KNode.createPlaceholder();
|
|
2170
|
-
this.addNode(placeholderNode, item.parent);
|
|
2171
|
-
}
|
|
2161
|
+
return false;
|
|
2172
2162
|
}
|
|
2173
2163
|
});
|
|
2164
|
+
if (node.isEmpty()) {
|
|
2165
|
+
const placeholderNode = KNode.createPlaceholder();
|
|
2166
|
+
this.addNode(placeholderNode, node);
|
|
2167
|
+
}
|
|
2174
2168
|
}
|
|
2175
2169
|
};
|
|
2176
2170
|
const mergeBlock = function(node, target) {
|
|
@@ -2264,10 +2258,10 @@ const applyMergeNode = function(node, type) {
|
|
|
2264
2258
|
}
|
|
2265
2259
|
if (type == "prevSibling") {
|
|
2266
2260
|
if (node.isText()) {
|
|
2267
|
-
if (this.
|
|
2261
|
+
if (this.isSelectionInTargetNode(targetNode, "start")) {
|
|
2268
2262
|
this.selection.start.node = node;
|
|
2269
2263
|
}
|
|
2270
|
-
if (this.
|
|
2264
|
+
if (this.isSelectionInTargetNode(targetNode, "end")) {
|
|
2271
2265
|
this.selection.end.node = node;
|
|
2272
2266
|
}
|
|
2273
2267
|
node.textContent = targetNode.textContent + node.textContent;
|
|
@@ -2302,11 +2296,11 @@ const applyMergeNode = function(node, type) {
|
|
|
2302
2296
|
}
|
|
2303
2297
|
if (type == "nextSibling") {
|
|
2304
2298
|
if (node.isText()) {
|
|
2305
|
-
if (this.
|
|
2299
|
+
if (this.isSelectionInTargetNode(targetNode, "start")) {
|
|
2306
2300
|
this.selection.start.node = node;
|
|
2307
2301
|
this.selection.start.offset = node.textContent.length + this.selection.start.offset;
|
|
2308
2302
|
}
|
|
2309
|
-
if (this.
|
|
2303
|
+
if (this.isSelectionInTargetNode(targetNode, "end")) {
|
|
2310
2304
|
this.selection.end.node = node;
|
|
2311
2305
|
this.selection.end.offset = node.textContent.length + this.selection.end.offset;
|
|
2312
2306
|
}
|
|
@@ -2360,10 +2354,10 @@ const applyMergeNode = function(node, type) {
|
|
|
2360
2354
|
}
|
|
2361
2355
|
targetNode.textContent = node.textContent;
|
|
2362
2356
|
targetNode.children = void 0;
|
|
2363
|
-
if (this.
|
|
2357
|
+
if (this.isSelectionInTargetNode(node, "start")) {
|
|
2364
2358
|
this.selection.start.node = targetNode;
|
|
2365
2359
|
}
|
|
2366
|
-
if (this.
|
|
2360
|
+
if (this.isSelectionInTargetNode(node, "end")) {
|
|
2367
2361
|
this.selection.end.node = targetNode;
|
|
2368
2362
|
}
|
|
2369
2363
|
} else {
|
|
@@ -2404,32 +2398,31 @@ const convertToBlock = function(node) {
|
|
|
2404
2398
|
if (node.isBlock()) {
|
|
2405
2399
|
return;
|
|
2406
2400
|
}
|
|
2407
|
-
const newNode2 = node.clone(true);
|
|
2408
2401
|
if (node.isText() || node.isClosed()) {
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2402
|
+
const index = node.parent ? node.parent.children.findIndex((item) => item.isEqual(node)) : this.stackNodes.findIndex((item) => item.isEqual(node));
|
|
2403
|
+
const paragraph = KNode.create({
|
|
2404
|
+
type: "block",
|
|
2405
|
+
tag: this.blockRenderTag
|
|
2406
|
+
});
|
|
2407
|
+
if (node.parent) {
|
|
2408
|
+
paragraph.parent = node.parent;
|
|
2414
2409
|
}
|
|
2410
|
+
node.parent ? node.parent.children.splice(index, 1, paragraph) : this.stackNodes.splice(index, 1, paragraph);
|
|
2411
|
+
paragraph.children = [node];
|
|
2412
|
+
node.parent = paragraph;
|
|
2413
|
+
} else if (node.isInline()) {
|
|
2414
|
+
node.type = "block";
|
|
2415
2415
|
}
|
|
2416
|
-
node.type = "block";
|
|
2417
|
-
node.tag = this.blockRenderTag;
|
|
2418
|
-
node.marks = void 0;
|
|
2419
|
-
node.styles = void 0;
|
|
2420
|
-
node.textContent = void 0;
|
|
2421
|
-
node.children = [newNode2];
|
|
2422
|
-
newNode2.parent = node;
|
|
2423
2416
|
};
|
|
2424
2417
|
const formatNodes = function(rule, nodes, sourceNodes) {
|
|
2425
2418
|
let i = 0;
|
|
2426
2419
|
while (i < nodes.length) {
|
|
2427
2420
|
const node = nodes[i];
|
|
2428
2421
|
if (node.isEmpty()) {
|
|
2429
|
-
if (this.
|
|
2422
|
+
if (this.isSelectionInTargetNode(node, "start")) {
|
|
2430
2423
|
this.updateSelectionRecently("start");
|
|
2431
2424
|
}
|
|
2432
|
-
if (this.
|
|
2425
|
+
if (this.isSelectionInTargetNode(node, "end")) {
|
|
2433
2426
|
this.updateSelectionRecently("end");
|
|
2434
2427
|
}
|
|
2435
2428
|
const index = sourceNodes.findIndex((item) => item.isEqual(node));
|
|
@@ -2437,10 +2430,10 @@ const formatNodes = function(rule, nodes, sourceNodes) {
|
|
|
2437
2430
|
} else {
|
|
2438
2431
|
rule({ editor: this, node });
|
|
2439
2432
|
if (node.isEmpty()) {
|
|
2440
|
-
if (this.
|
|
2433
|
+
if (this.isSelectionInTargetNode(node, "start")) {
|
|
2441
2434
|
this.updateSelectionRecently("start");
|
|
2442
2435
|
}
|
|
2443
|
-
if (this.
|
|
2436
|
+
if (this.isSelectionInTargetNode(node, "end")) {
|
|
2444
2437
|
this.updateSelectionRecently("end");
|
|
2445
2438
|
}
|
|
2446
2439
|
const index = sourceNodes.findIndex((item) => item.isEqual(node));
|
|
@@ -2453,10 +2446,10 @@ const formatNodes = function(rule, nodes, sourceNodes) {
|
|
|
2453
2446
|
formatNodes.apply(this, [rule, node.children, node.children]);
|
|
2454
2447
|
}
|
|
2455
2448
|
if (node.isEmpty()) {
|
|
2456
|
-
if (this.
|
|
2449
|
+
if (this.isSelectionInTargetNode(node, "start")) {
|
|
2457
2450
|
this.updateSelectionRecently("start");
|
|
2458
2451
|
}
|
|
2459
|
-
if (this.
|
|
2452
|
+
if (this.isSelectionInTargetNode(node, "end")) {
|
|
2460
2453
|
this.updateSelectionRecently("end");
|
|
2461
2454
|
}
|
|
2462
2455
|
const index = sourceNodes.findIndex((item) => item.isEqual(node));
|
|
@@ -2692,7 +2685,9 @@ const checkNodes = function() {
|
|
|
2692
2685
|
}
|
|
2693
2686
|
};
|
|
2694
2687
|
const handlerForPasteKeepMarksAndStyles = function(nodes) {
|
|
2695
|
-
nodes.
|
|
2688
|
+
const length = nodes.length;
|
|
2689
|
+
for (let i = 0; i < length; i++) {
|
|
2690
|
+
const node = nodes[i];
|
|
2696
2691
|
const marks = {};
|
|
2697
2692
|
const styles2 = {};
|
|
2698
2693
|
if (node.hasMarks()) {
|
|
@@ -2719,55 +2714,56 @@ const handlerForPasteKeepMarksAndStyles = function(nodes) {
|
|
|
2719
2714
|
if (node.hasChildren()) {
|
|
2720
2715
|
handlerForPasteKeepMarksAndStyles.apply(this, [node.children]);
|
|
2721
2716
|
}
|
|
2722
|
-
}
|
|
2717
|
+
}
|
|
2723
2718
|
};
|
|
2724
2719
|
const handlerForPasteFiles = async function(files) {
|
|
2725
2720
|
const length = files.length;
|
|
2726
2721
|
for (let i = 0; i < length; i++) {
|
|
2727
|
-
|
|
2728
|
-
|
|
2722
|
+
const file$1 = files[i];
|
|
2723
|
+
if (file$1.type.startsWith("image/")) {
|
|
2724
|
+
const useDefault = typeof this.onPasteImage == "function" ? await this.onPasteImage.apply(this, [file$1]) : true;
|
|
2729
2725
|
if (useDefault) {
|
|
2730
|
-
const url = await file.dataFileToBase64(
|
|
2726
|
+
const url = await file.dataFileToBase64(file$1);
|
|
2731
2727
|
const image = KNode.create({
|
|
2732
2728
|
type: "closed",
|
|
2733
2729
|
tag: "img",
|
|
2734
2730
|
marks: {
|
|
2735
2731
|
src: url,
|
|
2736
|
-
alt:
|
|
2732
|
+
alt: file$1.name || ""
|
|
2737
2733
|
}
|
|
2738
2734
|
});
|
|
2739
2735
|
this.insertNode(image);
|
|
2740
2736
|
}
|
|
2741
|
-
} else if (
|
|
2742
|
-
const useDefault = typeof this.onPasteVideo == "function" ? await this.onPasteVideo.apply(this, [
|
|
2737
|
+
} else if (file$1.type.startsWith("video/")) {
|
|
2738
|
+
const useDefault = typeof this.onPasteVideo == "function" ? await this.onPasteVideo.apply(this, [file$1]) : true;
|
|
2743
2739
|
if (useDefault) {
|
|
2744
|
-
const url = await file.dataFileToBase64(
|
|
2740
|
+
const url = await file.dataFileToBase64(file$1);
|
|
2745
2741
|
const video = KNode.create({
|
|
2746
2742
|
type: "closed",
|
|
2747
2743
|
tag: "video",
|
|
2748
2744
|
marks: {
|
|
2749
2745
|
src: url,
|
|
2750
|
-
alt:
|
|
2746
|
+
alt: file$1.name || ""
|
|
2751
2747
|
}
|
|
2752
2748
|
});
|
|
2753
2749
|
this.insertNode(video);
|
|
2754
2750
|
}
|
|
2755
2751
|
} else if (typeof this.onPasteFile == "function") {
|
|
2756
|
-
this.onPasteFile.apply(this, [
|
|
2752
|
+
this.onPasteFile.apply(this, [file$1]);
|
|
2757
2753
|
}
|
|
2758
2754
|
}
|
|
2759
2755
|
};
|
|
2760
2756
|
const fillPlaceholderToEmptyBlock = function(nodes) {
|
|
2761
|
-
const
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2757
|
+
const stack = nodes.slice().reverse();
|
|
2758
|
+
while (stack.length > 0) {
|
|
2759
|
+
const node = stack.pop();
|
|
2760
|
+
if (!node.isBlock()) continue;
|
|
2761
|
+
if (node.isEmpty()) {
|
|
2762
|
+
const placeholderNode = KNode.createPlaceholder();
|
|
2763
|
+
node.children = [placeholderNode];
|
|
2764
|
+
placeholderNode.parent = node;
|
|
2765
|
+
} else if (node.hasChildren()) {
|
|
2766
|
+
stack.push(...node.children.slice().reverse());
|
|
2771
2767
|
}
|
|
2772
2768
|
}
|
|
2773
2769
|
};
|
|
@@ -2825,8 +2821,8 @@ const handlerForNormalInsertParagraph = function() {
|
|
|
2825
2821
|
const node = this.selection.start.node;
|
|
2826
2822
|
const offset = this.selection.start.offset;
|
|
2827
2823
|
const blockNode = node.getBlock();
|
|
2828
|
-
const firstSelectionNode = this.
|
|
2829
|
-
const lastSelectionNode = this.
|
|
2824
|
+
const firstSelectionNode = this.getFirstSelectionNode(blockNode);
|
|
2825
|
+
const lastSelectionNode = this.getLastSelectionNode(blockNode);
|
|
2830
2826
|
if (firstSelectionNode.isEqual(node) && offset == 0) {
|
|
2831
2827
|
const newBlockNode = blockNode.clone(false);
|
|
2832
2828
|
const placeholderNode = KNode.createPlaceholder();
|
|
@@ -2886,8 +2882,8 @@ const fomratBlockTagParse = ({ editor, node }) => {
|
|
|
2886
2882
|
};
|
|
2887
2883
|
const formatBlockInChildren = ({ editor, node }) => {
|
|
2888
2884
|
if (node.hasChildren() && !node.isEmpty()) {
|
|
2889
|
-
const
|
|
2890
|
-
if (
|
|
2885
|
+
const hasNonEmptyBlock = node.children.some((item) => item.isBlock() && !item.isEmpty());
|
|
2886
|
+
if (hasNonEmptyBlock) {
|
|
2891
2887
|
node.children.forEach((item) => {
|
|
2892
2888
|
if (!item.isEmpty() && !item.isBlock()) {
|
|
2893
2889
|
convertToBlock.apply(editor, [item]);
|
|
@@ -2913,11 +2909,11 @@ const formatUneditableNoodes = ({ editor, node }) => {
|
|
|
2913
2909
|
editor.addNodeAfter(zeroWidthText, uneditableNode);
|
|
2914
2910
|
}
|
|
2915
2911
|
if (editor.isUserDelection) {
|
|
2916
|
-
if (editor.
|
|
2912
|
+
if (editor.isSelectionInTargetNode(uneditableNode, "all")) {
|
|
2917
2913
|
const previousSelectionNode = editor.getPreviousSelectionNode(uneditableNode);
|
|
2918
2914
|
const nexteSelectionNode = editor.getNextSelectionNode(uneditableNode);
|
|
2919
2915
|
if (editor.selection.collapsed()) {
|
|
2920
|
-
const firstNode = editor.
|
|
2916
|
+
const firstNode = editor.getFirstSelectionNode(uneditableNode);
|
|
2921
2917
|
if (firstNode.isEqual(editor.selection.start.node) && editor.selection.start.offset == 0) {
|
|
2922
2918
|
editor.setSelectionAfter(previousSelectionNode, "all");
|
|
2923
2919
|
} else {
|
|
@@ -2927,10 +2923,10 @@ const formatUneditableNoodes = ({ editor, node }) => {
|
|
|
2927
2923
|
editor.setSelectionAfter(previousSelectionNode, "start");
|
|
2928
2924
|
editor.setSelectionBefore(nexteSelectionNode, "end");
|
|
2929
2925
|
}
|
|
2930
|
-
} else if (editor.
|
|
2926
|
+
} else if (editor.isSelectionInTargetNode(uneditableNode, "start")) {
|
|
2931
2927
|
const nexteSelectionNode = editor.getNextSelectionNode(uneditableNode);
|
|
2932
2928
|
editor.setSelectionBefore(nexteSelectionNode, "start");
|
|
2933
|
-
} else if (editor.
|
|
2929
|
+
} else if (editor.isSelectionInTargetNode(uneditableNode, "end")) {
|
|
2934
2930
|
const previousSelectionNode = editor.getPreviousSelectionNode(uneditableNode);
|
|
2935
2931
|
editor.setSelectionAfter(previousSelectionNode, "end");
|
|
2936
2932
|
}
|
|
@@ -2973,10 +2969,10 @@ const formatZeroWidthTextMerge = ({ editor, node }) => {
|
|
|
2973
2969
|
while (i < val.length) {
|
|
2974
2970
|
const chart = val.charAt(i);
|
|
2975
2971
|
if (i > 0 && isZeroWidthText(chart) && isZeroWidthText(val.charAt(i - 1))) {
|
|
2976
|
-
if (editor.
|
|
2972
|
+
if (editor.isSelectionInTargetNode(node, "start") && editor.selection.start.offset >= i + 1) {
|
|
2977
2973
|
editor.selection.start.offset -= 1;
|
|
2978
2974
|
}
|
|
2979
|
-
if (editor.
|
|
2975
|
+
if (editor.isSelectionInTargetNode(node, "end") && editor.selection.end.offset >= i + 1) {
|
|
2980
2976
|
editor.selection.end.offset -= 1;
|
|
2981
2977
|
}
|
|
2982
2978
|
val = string.delete(val, i, 1);
|
|
@@ -2987,6 +2983,11 @@ const formatZeroWidthTextMerge = ({ editor, node }) => {
|
|
|
2987
2983
|
node.textContent = val;
|
|
2988
2984
|
}
|
|
2989
2985
|
};
|
|
2986
|
+
const formatLineBreakText = ({ node }) => {
|
|
2987
|
+
if (node.isText() && !node.isEmpty()) {
|
|
2988
|
+
node.textContent = node.textContent.replace(/\r\n/g, "\n");
|
|
2989
|
+
}
|
|
2990
|
+
};
|
|
2990
2991
|
const formatSiblingNodesMerge = ({ editor, node }) => {
|
|
2991
2992
|
if ((node.isBlock() || node.isInline()) && node.hasChildren() && node.children.length > 1) {
|
|
2992
2993
|
let index = 0;
|
|
@@ -3238,7 +3239,7 @@ const onComposition = async function(e) {
|
|
|
3238
3239
|
if (parentNode.isText() && parentNode.textContent != element2.textContent) {
|
|
3239
3240
|
const textContent = parentNode.textContent || "";
|
|
3240
3241
|
parentNode.textContent = element2.textContent || "";
|
|
3241
|
-
if (this.
|
|
3242
|
+
if (this.isSelectionInTargetNode(parentNode)) {
|
|
3242
3243
|
updateSelection$1.apply(this);
|
|
3243
3244
|
}
|
|
3244
3245
|
element2.textContent = textContent;
|
|
@@ -3356,7 +3357,7 @@ const setDomObserve = (editor) => {
|
|
|
3356
3357
|
if (parentNode.isText() && parentNode.textContent != mutationRecord.target.textContent) {
|
|
3357
3358
|
const textContent = parentNode.textContent || "";
|
|
3358
3359
|
parentNode.textContent = mutationRecord.target.textContent || "";
|
|
3359
|
-
if (editor.
|
|
3360
|
+
if (editor.isSelectionInTargetNode(parentNode)) {
|
|
3360
3361
|
updateSelection$1.apply(editor);
|
|
3361
3362
|
}
|
|
3362
3363
|
removeDomObserve(editor);
|
|
@@ -6913,10 +6914,10 @@ const CodeExtension = () => Extension.create({
|
|
|
6913
6914
|
node.textContent = void 0;
|
|
6914
6915
|
node.children = [newNode2];
|
|
6915
6916
|
newNode2.parent = node;
|
|
6916
|
-
if (this.
|
|
6917
|
+
if (this.isSelectionInTargetNode(node, "start")) {
|
|
6917
6918
|
this.selection.start.node = newNode2;
|
|
6918
6919
|
}
|
|
6919
|
-
if (this.
|
|
6920
|
+
if (this.isSelectionInTargetNode(node, "end")) {
|
|
6920
6921
|
this.selection.end.node = newNode2;
|
|
6921
6922
|
}
|
|
6922
6923
|
}
|
|
@@ -6933,8 +6934,8 @@ const CodeExtension = () => Extension.create({
|
|
|
6933
6934
|
const codeNode = node.getMatchNode({
|
|
6934
6935
|
tag: "code"
|
|
6935
6936
|
});
|
|
6936
|
-
const firstSelectionNode = this.
|
|
6937
|
-
const lastSelectionNode = this.
|
|
6937
|
+
const firstSelectionNode = this.getFirstSelectionNode(codeNode);
|
|
6938
|
+
const lastSelectionNode = this.getLastSelectionNode(codeNode);
|
|
6938
6939
|
if (firstSelectionNode.isEqual(node) && offset == 0) {
|
|
6939
6940
|
const zeroWidthText = KNode.createZeroWidthText();
|
|
6940
6941
|
this.addNodeBefore(zeroWidthText, codeNode);
|
|
@@ -7004,7 +7005,7 @@ const CodeExtension = () => Extension.create({
|
|
|
7004
7005
|
}
|
|
7005
7006
|
} else {
|
|
7006
7007
|
const startOffset = this.selection.start.offset;
|
|
7007
|
-
const firstStartSelectionNode = this.
|
|
7008
|
+
const firstStartSelectionNode = this.getFirstSelectionNode(startCodeNode);
|
|
7008
7009
|
const focusNodes = this.getFocusSplitNodesBySelection("all");
|
|
7009
7010
|
const length = focusNodes.length;
|
|
7010
7011
|
const map = {};
|
|
@@ -7026,7 +7027,7 @@ const CodeExtension = () => Extension.create({
|
|
|
7026
7027
|
}
|
|
7027
7028
|
}
|
|
7028
7029
|
Object.values(map).forEach((item) => {
|
|
7029
|
-
item.nodes.reverse().forEach((node) => {
|
|
7030
|
+
item.nodes.slice().reverse().forEach((node) => {
|
|
7030
7031
|
this.addNodeAfter(node, item.code);
|
|
7031
7032
|
});
|
|
7032
7033
|
});
|
|
@@ -22869,11 +22870,11 @@ const MathExtension = () => Extension.create({
|
|
|
22869
22870
|
const zeroWidthText = KNode.createZeroWidthText();
|
|
22870
22871
|
editor.addNodeAfter(zeroWidthText, node);
|
|
22871
22872
|
}
|
|
22872
|
-
if (editor.
|
|
22873
|
+
if (editor.isSelectionInTargetNode(node, "start")) {
|
|
22873
22874
|
const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
|
|
22874
22875
|
if (newTextNode) editor.setSelectionBefore(newTextNode, "start");
|
|
22875
22876
|
}
|
|
22876
|
-
if (editor.
|
|
22877
|
+
if (editor.isSelectionInTargetNode(node, "end")) {
|
|
22877
22878
|
const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
|
|
22878
22879
|
if (newTextNode) editor.setSelectionBefore(newTextNode, "end");
|
|
22879
22880
|
}
|
|
@@ -35134,7 +35135,7 @@ const updateSelection = (editor, node, textNodes, newNodes) => {
|
|
|
35134
35135
|
if (!editor.selection.focused()) {
|
|
35135
35136
|
return;
|
|
35136
35137
|
}
|
|
35137
|
-
if (editor.
|
|
35138
|
+
if (editor.isSelectionInTargetNode(node, "start")) {
|
|
35138
35139
|
const startIndex = textNodes.findIndex((n) => editor.selection.start.node.isEqual(n));
|
|
35139
35140
|
const offset = textNodes.filter((_n, i2) => i2 < startIndex).reduce((total, item) => total + item.textContent.length, 0) + editor.selection.start.offset;
|
|
35140
35141
|
const newTextNodes = KNode.flat(newNodes).filter((n) => n.isText() && !n.isEmpty());
|
|
@@ -35151,7 +35152,7 @@ const updateSelection = (editor, node, textNodes, newNodes) => {
|
|
|
35151
35152
|
index = newIndex;
|
|
35152
35153
|
}
|
|
35153
35154
|
}
|
|
35154
|
-
if (editor.
|
|
35155
|
+
if (editor.isSelectionInTargetNode(node, "end")) {
|
|
35155
35156
|
const endIndex = textNodes.findIndex((n) => editor.selection.end.node.isEqual(n));
|
|
35156
35157
|
const offset = textNodes.filter((_n, i2) => i2 < endIndex).reduce((total, item) => total + item.textContent.length, 0) + editor.selection.end.offset;
|
|
35157
35158
|
const newTextNodes = KNode.flat(newNodes).filter((n) => n.isText() && !n.isEmpty());
|
|
@@ -35239,8 +35240,8 @@ const CodeBlockExtension = () => Extension.create({
|
|
|
35239
35240
|
});
|
|
35240
35241
|
updateSelection(editor, node, textNodes, nodes);
|
|
35241
35242
|
} else {
|
|
35242
|
-
const selectionStartInNode = editor.
|
|
35243
|
-
const selectionEndInNode = editor.
|
|
35243
|
+
const selectionStartInNode = editor.isSelectionInTargetNode(node, "start");
|
|
35244
|
+
const selectionEndInNode = editor.isSelectionInTargetNode(node, "end");
|
|
35244
35245
|
const placeholderNode = KNode.createPlaceholder();
|
|
35245
35246
|
node.children = [placeholderNode];
|
|
35246
35247
|
placeholderNode.parent = node;
|
|
@@ -35444,11 +35445,11 @@ const AttachmentExtension = (props) => Extension.create({
|
|
|
35444
35445
|
const zeroWidthText = KNode.createZeroWidthText();
|
|
35445
35446
|
editor.addNodeAfter(zeroWidthText, node);
|
|
35446
35447
|
}
|
|
35447
|
-
if (editor.
|
|
35448
|
+
if (editor.isSelectionInTargetNode(node, "start")) {
|
|
35448
35449
|
const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
|
|
35449
35450
|
if (newTextNode) editor.setSelectionBefore(newTextNode, "start");
|
|
35450
35451
|
}
|
|
35451
|
-
if (editor.
|
|
35452
|
+
if (editor.isSelectionInTargetNode(node, "end")) {
|
|
35452
35453
|
const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
|
|
35453
35454
|
if (newTextNode) editor.setSelectionBefore(newTextNode, "end");
|
|
35454
35455
|
}
|
|
@@ -36809,7 +36810,7 @@ class Editor {
|
|
|
36809
36810
|
/**
|
|
36810
36811
|
* 编辑器的节点数组格式化规则【初始化后不可修改】【open】
|
|
36811
36812
|
*/
|
|
36812
|
-
__publicField(this, "formatRules", [fomratBlockTagParse, formatBlockInChildren, formatUneditableNoodes, formatPlaceholderMerge, formatZeroWidthTextMerge, formatSiblingNodesMerge, formatParentNodeMerge]);
|
|
36813
|
+
__publicField(this, "formatRules", [fomratBlockTagParse, formatBlockInChildren, formatUneditableNoodes, formatPlaceholderMerge, formatZeroWidthTextMerge, formatLineBreakText, formatSiblingNodesMerge, formatParentNodeMerge]);
|
|
36813
36814
|
/**
|
|
36814
36815
|
* 自定义dom转为非文本节点的后续处理【初始化后不可修改】
|
|
36815
36816
|
*/
|
|
@@ -37093,7 +37094,7 @@ class Editor {
|
|
|
37093
37094
|
if (dom.nodeType == 3) {
|
|
37094
37095
|
return KNode.create({
|
|
37095
37096
|
type: "text",
|
|
37096
|
-
textContent: dom.textContent
|
|
37097
|
+
textContent: dom.textContent ?? ""
|
|
37097
37098
|
});
|
|
37098
37099
|
}
|
|
37099
37100
|
const marks = getDomAttributes(dom);
|
|
@@ -37118,7 +37119,7 @@ class Editor {
|
|
|
37118
37119
|
tag,
|
|
37119
37120
|
marks,
|
|
37120
37121
|
styles: styles2,
|
|
37121
|
-
namespace: namespace
|
|
37122
|
+
namespace: namespace ?? ""
|
|
37122
37123
|
};
|
|
37123
37124
|
if (["p", "div", "address", "article", "aside", "nav", "section"].includes(tag)) {
|
|
37124
37125
|
config.type = "block";
|
|
@@ -37162,8 +37163,7 @@ class Editor {
|
|
|
37162
37163
|
const nodes = [];
|
|
37163
37164
|
template.content.childNodes.forEach((item) => {
|
|
37164
37165
|
if (item.nodeType == 1 || item.nodeType == 3) {
|
|
37165
|
-
|
|
37166
|
-
nodes.push(node);
|
|
37166
|
+
nodes.push(this.domParseNode(item));
|
|
37167
37167
|
}
|
|
37168
37168
|
});
|
|
37169
37169
|
return nodes;
|
|
@@ -37217,14 +37217,10 @@ class Editor {
|
|
|
37217
37217
|
*/
|
|
37218
37218
|
addNodeBefore(node, target) {
|
|
37219
37219
|
if (target.parent) {
|
|
37220
|
-
const index = target.parent.children.findIndex((item) =>
|
|
37221
|
-
return target.isEqual(item);
|
|
37222
|
-
});
|
|
37220
|
+
const index = target.parent.children.findIndex((item) => target.isEqual(item));
|
|
37223
37221
|
this.addNode(node, target.parent, index);
|
|
37224
37222
|
} else {
|
|
37225
|
-
const index = this.stackNodes.findIndex((item) =>
|
|
37226
|
-
return target.isEqual(item);
|
|
37227
|
-
});
|
|
37223
|
+
const index = this.stackNodes.findIndex((item) => target.isEqual(item));
|
|
37228
37224
|
this.stackNodes.splice(index, 0, node);
|
|
37229
37225
|
node.parent = void 0;
|
|
37230
37226
|
}
|
|
@@ -37234,14 +37230,10 @@ class Editor {
|
|
|
37234
37230
|
*/
|
|
37235
37231
|
addNodeAfter(node, target) {
|
|
37236
37232
|
if (target.parent) {
|
|
37237
|
-
const index = target.parent.children.findIndex((item) =>
|
|
37238
|
-
return target.isEqual(item);
|
|
37239
|
-
});
|
|
37233
|
+
const index = target.parent.children.findIndex((item) => target.isEqual(item));
|
|
37240
37234
|
this.addNode(node, target.parent, index + 1);
|
|
37241
37235
|
} else {
|
|
37242
|
-
const index = this.stackNodes.findIndex((item) =>
|
|
37243
|
-
return target.isEqual(item);
|
|
37244
|
-
});
|
|
37236
|
+
const index = this.stackNodes.findIndex((item) => target.isEqual(item));
|
|
37245
37237
|
this.stackNodes.splice(index + 1, 0, node);
|
|
37246
37238
|
node.parent = void 0;
|
|
37247
37239
|
}
|
|
@@ -37249,97 +37241,93 @@ class Editor {
|
|
|
37249
37241
|
/**
|
|
37250
37242
|
* 获取某个节点内的最后一个可以设置光标点的节点,包括自身
|
|
37251
37243
|
*/
|
|
37252
|
-
|
|
37253
|
-
|
|
37254
|
-
|
|
37255
|
-
|
|
37256
|
-
|
|
37257
|
-
|
|
37258
|
-
|
|
37259
|
-
|
|
37260
|
-
|
|
37261
|
-
|
|
37262
|
-
|
|
37263
|
-
|
|
37264
|
-
for (let i = length - 1; i >= 0; i--) {
|
|
37265
|
-
const child = node.children[i];
|
|
37266
|
-
selectionNode = this.getLastSelectionNodeInChildren(child);
|
|
37267
|
-
if (selectionNode) {
|
|
37268
|
-
break;
|
|
37244
|
+
getLastSelectionNode(node) {
|
|
37245
|
+
const stack = [node];
|
|
37246
|
+
while (stack.length > 0) {
|
|
37247
|
+
const currentNode = stack.pop();
|
|
37248
|
+
if (currentNode.isEmpty() || currentNode.void) {
|
|
37249
|
+
continue;
|
|
37250
|
+
}
|
|
37251
|
+
if (currentNode.isText() || currentNode.isClosed()) {
|
|
37252
|
+
return currentNode;
|
|
37253
|
+
}
|
|
37254
|
+
if (currentNode.hasChildren()) {
|
|
37255
|
+
stack.push(...currentNode.children);
|
|
37269
37256
|
}
|
|
37270
37257
|
}
|
|
37271
|
-
return
|
|
37258
|
+
return null;
|
|
37272
37259
|
}
|
|
37273
37260
|
/**
|
|
37274
37261
|
* 获取某个节点内的第一个可以设置光标点的节点,包括自身
|
|
37275
37262
|
*/
|
|
37276
|
-
|
|
37277
|
-
|
|
37278
|
-
|
|
37279
|
-
|
|
37280
|
-
|
|
37281
|
-
|
|
37282
|
-
|
|
37283
|
-
|
|
37284
|
-
|
|
37285
|
-
|
|
37286
|
-
|
|
37287
|
-
|
|
37288
|
-
for (let i = 0; i < length; i++) {
|
|
37289
|
-
const child = node.children[i];
|
|
37290
|
-
selectionNode = this.getFirstSelectionNodeInChildren(child);
|
|
37291
|
-
if (selectionNode) {
|
|
37292
|
-
break;
|
|
37263
|
+
getFirstSelectionNode(node) {
|
|
37264
|
+
const stack = [node];
|
|
37265
|
+
while (stack.length > 0) {
|
|
37266
|
+
const currentNode = stack.pop();
|
|
37267
|
+
if (currentNode.isEmpty() || currentNode.void) {
|
|
37268
|
+
continue;
|
|
37269
|
+
}
|
|
37270
|
+
if (currentNode.isText() || currentNode.isClosed()) {
|
|
37271
|
+
return currentNode;
|
|
37272
|
+
}
|
|
37273
|
+
if (currentNode.hasChildren()) {
|
|
37274
|
+
stack.push(...currentNode.children.slice().reverse());
|
|
37293
37275
|
}
|
|
37294
37276
|
}
|
|
37295
|
-
return
|
|
37277
|
+
return null;
|
|
37296
37278
|
}
|
|
37297
37279
|
/**
|
|
37298
37280
|
* 查找指定节点之前可以设置为光标点的非空节点,不包括自身
|
|
37299
37281
|
*/
|
|
37300
37282
|
getPreviousSelectionNode(node) {
|
|
37301
|
-
|
|
37302
|
-
|
|
37303
|
-
|
|
37304
|
-
|
|
37305
|
-
|
|
37283
|
+
let currentNode = node;
|
|
37284
|
+
while (currentNode) {
|
|
37285
|
+
const nodes = currentNode.parent ? currentNode.parent.children : this.stackNodes;
|
|
37286
|
+
const previousNode = currentNode.getPrevious(nodes);
|
|
37287
|
+
if (!previousNode) {
|
|
37288
|
+
currentNode = currentNode.parent;
|
|
37289
|
+
continue;
|
|
37306
37290
|
}
|
|
37307
|
-
if (previousNode.void) {
|
|
37308
|
-
|
|
37291
|
+
if (previousNode.isEmpty() || previousNode.void) {
|
|
37292
|
+
currentNode = previousNode;
|
|
37293
|
+
continue;
|
|
37309
37294
|
}
|
|
37310
37295
|
if (previousNode.isText() || previousNode.isClosed()) {
|
|
37311
37296
|
return previousNode;
|
|
37312
37297
|
}
|
|
37313
|
-
return this.
|
|
37298
|
+
return this.getLastSelectionNode(previousNode);
|
|
37314
37299
|
}
|
|
37315
|
-
return
|
|
37300
|
+
return null;
|
|
37316
37301
|
}
|
|
37317
37302
|
/**
|
|
37318
37303
|
* 查找指定节点之后可以设置为光标点的非空节点,不包括自身
|
|
37319
37304
|
*/
|
|
37320
37305
|
getNextSelectionNode(node) {
|
|
37321
|
-
|
|
37322
|
-
|
|
37323
|
-
|
|
37324
|
-
|
|
37325
|
-
|
|
37306
|
+
let currentNode = node;
|
|
37307
|
+
while (currentNode) {
|
|
37308
|
+
const nodes = currentNode.parent ? currentNode.parent.children : this.stackNodes;
|
|
37309
|
+
const nextNode = currentNode.getNext(nodes);
|
|
37310
|
+
if (!nextNode) {
|
|
37311
|
+
currentNode = currentNode.parent;
|
|
37312
|
+
continue;
|
|
37326
37313
|
}
|
|
37327
|
-
if (nextNode.void) {
|
|
37328
|
-
|
|
37314
|
+
if (nextNode.isEmpty() || nextNode.void) {
|
|
37315
|
+
currentNode = nextNode;
|
|
37316
|
+
continue;
|
|
37329
37317
|
}
|
|
37330
37318
|
if (nextNode.isText() || nextNode.isClosed()) {
|
|
37331
37319
|
return nextNode;
|
|
37332
37320
|
}
|
|
37333
|
-
return this.
|
|
37321
|
+
return this.getFirstSelectionNode(nextNode);
|
|
37334
37322
|
}
|
|
37335
|
-
return
|
|
37323
|
+
return null;
|
|
37336
37324
|
}
|
|
37337
37325
|
/**
|
|
37338
37326
|
* 设置光标到指定节点内部的起始处,如果没有指定节点则设置光标到编辑器起始处,start表示只设置起点,end表示只设置终点,all表示起点和终点都设置
|
|
37339
37327
|
*/
|
|
37340
37328
|
setSelectionBefore(node, type = "all") {
|
|
37341
37329
|
if (node) {
|
|
37342
|
-
const selectionNode = this.
|
|
37330
|
+
const selectionNode = this.getFirstSelectionNode(node);
|
|
37343
37331
|
if (selectionNode) {
|
|
37344
37332
|
if (type == "start" || type == "all") {
|
|
37345
37333
|
this.selection.start = {
|
|
@@ -37356,7 +37344,7 @@ class Editor {
|
|
|
37356
37344
|
}
|
|
37357
37345
|
} else {
|
|
37358
37346
|
const firstNode = this.stackNodes[0];
|
|
37359
|
-
let selectionNode = this.
|
|
37347
|
+
let selectionNode = this.getFirstSelectionNode(firstNode);
|
|
37360
37348
|
if (!selectionNode) selectionNode = this.getNextSelectionNode(firstNode);
|
|
37361
37349
|
if (selectionNode) {
|
|
37362
37350
|
if (type == "start" || type == "all") {
|
|
@@ -37379,7 +37367,7 @@ class Editor {
|
|
|
37379
37367
|
*/
|
|
37380
37368
|
setSelectionAfter(node, type = "all") {
|
|
37381
37369
|
if (node) {
|
|
37382
|
-
const selectionNode = this.
|
|
37370
|
+
const selectionNode = this.getLastSelectionNode(node);
|
|
37383
37371
|
if (selectionNode) {
|
|
37384
37372
|
if (type == "start" || type == "all") {
|
|
37385
37373
|
this.selection.start = {
|
|
@@ -37396,7 +37384,7 @@ class Editor {
|
|
|
37396
37384
|
}
|
|
37397
37385
|
} else {
|
|
37398
37386
|
const lastNode = this.stackNodes[this.stackNodes.length - 1];
|
|
37399
|
-
let selectionNode = this.
|
|
37387
|
+
let selectionNode = this.getLastSelectionNode(lastNode);
|
|
37400
37388
|
if (!selectionNode) selectionNode = this.getPreviousSelectionNode(lastNode);
|
|
37401
37389
|
if (selectionNode) {
|
|
37402
37390
|
if (type == "start" || type == "all") {
|
|
@@ -37461,7 +37449,7 @@ class Editor {
|
|
|
37461
37449
|
/**
|
|
37462
37450
|
* 判断光标是否在某个节点内,start表示只判断起点,end表示只判断终点,all表示起点和终点都判断
|
|
37463
37451
|
*/
|
|
37464
|
-
|
|
37452
|
+
isSelectionInTargetNode(node, type = "all") {
|
|
37465
37453
|
if (!this.selection.focused()) {
|
|
37466
37454
|
return false;
|
|
37467
37455
|
}
|
|
@@ -37533,7 +37521,7 @@ class Editor {
|
|
|
37533
37521
|
break;
|
|
37534
37522
|
} else {
|
|
37535
37523
|
if (node.isContains(endNode)) {
|
|
37536
|
-
const lastSelectionNode = this.
|
|
37524
|
+
const lastSelectionNode = this.getLastSelectionNode(node);
|
|
37537
37525
|
if (endNode.isEqual(lastSelectionNode) && endOffset == (endNode.isText() ? endNode.textContent.length : 1)) {
|
|
37538
37526
|
result.push({
|
|
37539
37527
|
node,
|
|
@@ -37625,11 +37613,7 @@ class Editor {
|
|
|
37625
37613
|
if (!this.selection.focused() || this.selection.collapsed()) {
|
|
37626
37614
|
return [];
|
|
37627
37615
|
}
|
|
37628
|
-
|
|
37629
|
-
this.getSelectedNodes().forEach((item) => {
|
|
37630
|
-
nodes.push(...item.node.getFocusNodes(type));
|
|
37631
|
-
});
|
|
37632
|
-
return nodes;
|
|
37616
|
+
return this.getSelectedNodes().flatMap((item) => item.node.getFocusNodes(type));
|
|
37633
37617
|
}
|
|
37634
37618
|
/**
|
|
37635
37619
|
* 获取所有在光标范围内的可聚焦节点,该方法可能会切割部分文本节点,摒弃其不在光标范围内的部分,所以也可能会更新光标的位置
|
|
@@ -37665,10 +37649,10 @@ class Editor {
|
|
|
37665
37649
|
newAfterTextNode.textContent = textContent.substring(item.offset[1]);
|
|
37666
37650
|
nodes.push(item.node);
|
|
37667
37651
|
}
|
|
37668
|
-
if (this.
|
|
37652
|
+
if (this.isSelectionInTargetNode(item.node, "start")) {
|
|
37669
37653
|
this.setSelectionBefore(item.node, "start");
|
|
37670
37654
|
}
|
|
37671
|
-
if (this.
|
|
37655
|
+
if (this.isSelectionInTargetNode(item.node, "end")) {
|
|
37672
37656
|
this.setSelectionAfter(item.node, "end");
|
|
37673
37657
|
}
|
|
37674
37658
|
} else {
|
|
@@ -37692,7 +37676,6 @@ class Editor {
|
|
|
37692
37676
|
if (!this.selection.focused()) {
|
|
37693
37677
|
return;
|
|
37694
37678
|
}
|
|
37695
|
-
text2 = text2.replace(/\r\n/g, "\n");
|
|
37696
37679
|
if (this.selection.collapsed()) {
|
|
37697
37680
|
const node = this.selection.start.node;
|
|
37698
37681
|
const offset = this.selection.start.offset;
|
|
@@ -37720,7 +37703,12 @@ class Editor {
|
|
|
37720
37703
|
}
|
|
37721
37704
|
}
|
|
37722
37705
|
/**
|
|
37723
|
-
*
|
|
37706
|
+
* 向选区进行换行
|
|
37707
|
+
* 1. 所在块节点只有占位符并且块节点不是段落则会转为段落
|
|
37708
|
+
* 2. 非代码块样式内换行是插入换行符\n
|
|
37709
|
+
* 2. 光标所在块节点是固定块节点,则无法换行
|
|
37710
|
+
* 3. 光标所在块节点只有占位符,并且其存在父节点,且父节点不是固定块节点,会从父节点抽离到与父节点同级
|
|
37711
|
+
* 4. 光标所在块节点只有占位符,并且不存在父节点,且不是段落,则会转为段落
|
|
37724
37712
|
*/
|
|
37725
37713
|
insertParagraph() {
|
|
37726
37714
|
if (!this.selection.focused()) {
|
|
@@ -37775,8 +37763,8 @@ class Editor {
|
|
|
37775
37763
|
const selectionNode = this.selection.start.node;
|
|
37776
37764
|
const offset = this.selection.start.offset;
|
|
37777
37765
|
const blockNode = selectionNode.getBlock();
|
|
37778
|
-
const firstSelectionNode = this.
|
|
37779
|
-
const lastSelectionNode = this.
|
|
37766
|
+
const firstSelectionNode = this.getFirstSelectionNode(blockNode);
|
|
37767
|
+
const lastSelectionNode = this.getLastSelectionNode(blockNode);
|
|
37780
37768
|
if (!blockNode.fixed && node.isBlock() && !node.fixed) {
|
|
37781
37769
|
if (!!selectionNode.isInCodeBlockStyle()) {
|
|
37782
37770
|
node.type = "inline";
|