@kaitify/core 0.0.3-beta.1 → 0.0.3-beta.2
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/extensions/Extension.d.ts +4 -4
- package/lib/extensions/code-block/index.d.ts +1 -1
- package/lib/extensions/link/index.d.ts +1 -1
- package/lib/kaitify-core.es.js +45 -46
- package/lib/kaitify-core.umd.js +1 -1
- package/lib/model/Editor.d.ts +5 -6
- package/lib/model/KNode.d.ts +2 -2
- package/package.json +1 -1
|
@@ -60,7 +60,7 @@ export type ExtensionCreateOptionType = {
|
|
|
60
60
|
*/
|
|
61
61
|
onPasteKeepStyles?: (this: Editor, node: KNode) => KNodeStylesType;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* 视图更新前回调
|
|
64
64
|
*/
|
|
65
65
|
onBeforeUpdateView?: (this: Editor) => void;
|
|
66
66
|
/**
|
|
@@ -68,7 +68,7 @@ export type ExtensionCreateOptionType = {
|
|
|
68
68
|
*/
|
|
69
69
|
onAfterUpdateView?: (this: Editor) => void;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* 在删除和换行操作中块节点从其父节点中抽离出去成为与父节点同级的节点后触发,如果返回true则表示继续使用默认逻辑,会将该节点转为段落,返回false则不走默认逻辑,需要自定义处理
|
|
72
72
|
*/
|
|
73
73
|
onDetachMentBlockFromParent?: (this: Editor, node: KNode) => boolean;
|
|
74
74
|
/**
|
|
@@ -149,7 +149,7 @@ export declare class Extension {
|
|
|
149
149
|
*/
|
|
150
150
|
onPasteKeepStyles?: (this: Editor, node: KNode) => KNodeStylesType;
|
|
151
151
|
/**
|
|
152
|
-
*
|
|
152
|
+
* 视图更新前回调
|
|
153
153
|
*/
|
|
154
154
|
onBeforeUpdateView?: (this: Editor) => void;
|
|
155
155
|
/**
|
|
@@ -157,7 +157,7 @@ export declare class Extension {
|
|
|
157
157
|
*/
|
|
158
158
|
onAfterUpdateView?: (this: Editor) => void;
|
|
159
159
|
/**
|
|
160
|
-
*
|
|
160
|
+
* 在删除和换行操作中块节点从其父节点中抽离出去成为与父节点同级的节点后触发,如果返回true则表示继续使用默认逻辑,会将该节点转为段落,返回false则不走默认逻辑,需要自定义处理
|
|
161
161
|
*/
|
|
162
162
|
onDetachMentBlockFromParent?: (this: Editor, node: KNode) => boolean;
|
|
163
163
|
/**
|
|
@@ -26,7 +26,7 @@ declare module '../../model' {
|
|
|
26
26
|
/**
|
|
27
27
|
* 更新光标所在代码块的语言类型
|
|
28
28
|
*/
|
|
29
|
-
updateCodeBlockLanguage?: (language
|
|
29
|
+
updateCodeBlockLanguage?: (language?: HljsLanguageType) => Promise<void>;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
export type CodeBlockExtensionPropsType = {
|
package/lib/kaitify-core.es.js
CHANGED
|
@@ -1399,7 +1399,7 @@ const kebabToCamel = (val) => {
|
|
|
1399
1399
|
const getDomAttributes = (dom) => {
|
|
1400
1400
|
const attributes = Array.from(dom.attributes);
|
|
1401
1401
|
const length = attributes.length;
|
|
1402
|
-
const regExp = new RegExp(`(^on)|(^style$)|(^${NODE_MARK}$)
|
|
1402
|
+
const regExp = new RegExp(`(^on)|(^style$)|(^${NODE_MARK}$)`);
|
|
1403
1403
|
const result = {};
|
|
1404
1404
|
for (let i = 0; i < length; i++) {
|
|
1405
1405
|
const { nodeName, nodeValue } = attributes[i];
|
|
@@ -1564,22 +1564,6 @@ class KNode {
|
|
|
1564
1564
|
}
|
|
1565
1565
|
return newNode2;
|
|
1566
1566
|
});
|
|
1567
|
-
/**
|
|
1568
|
-
* 【API】如果当前节点是文本节点或者闭合节点,则判断是不是指定节点后代中所有文本节点和闭合节点中的第一个
|
|
1569
|
-
*/
|
|
1570
|
-
__publicField(this, "firstInTargetNode", (node) => {
|
|
1571
|
-
if (!this.isText() && !this.isClosed()) {
|
|
1572
|
-
return false;
|
|
1573
|
-
}
|
|
1574
|
-
if (this.isEqual(node)) {
|
|
1575
|
-
return true;
|
|
1576
|
-
}
|
|
1577
|
-
if (node.isContains(this) && node.hasChildren()) {
|
|
1578
|
-
const firstChild = node.children[0];
|
|
1579
|
-
return this.firstInTargetNode(firstChild);
|
|
1580
|
-
}
|
|
1581
|
-
return false;
|
|
1582
|
-
});
|
|
1583
1567
|
/**
|
|
1584
1568
|
* 【API】获取当前节点下的所有可聚焦的节点,如果自身符合也会包括在内
|
|
1585
1569
|
* 1. type 是 all 获取闭合节点和文本节点;
|
|
@@ -1835,6 +1819,22 @@ class KNode {
|
|
|
1835
1819
|
}
|
|
1836
1820
|
return newNode2;
|
|
1837
1821
|
}
|
|
1822
|
+
/**
|
|
1823
|
+
* 【API】如果当前节点是文本节点或者闭合节点,则判断是不是指定节点后代中所有文本节点和闭合节点中的第一个
|
|
1824
|
+
*/
|
|
1825
|
+
firstInTargetNode(node) {
|
|
1826
|
+
if (!this.isText() && !this.isClosed()) {
|
|
1827
|
+
return false;
|
|
1828
|
+
}
|
|
1829
|
+
if (this.isEqual(node)) {
|
|
1830
|
+
return true;
|
|
1831
|
+
}
|
|
1832
|
+
if (node.isContains(this) && node.hasChildren()) {
|
|
1833
|
+
const firstChild = node.children[0];
|
|
1834
|
+
return this.firstInTargetNode(firstChild);
|
|
1835
|
+
}
|
|
1836
|
+
return false;
|
|
1837
|
+
}
|
|
1838
1838
|
/**
|
|
1839
1839
|
* 【API】如果当前节点是文本节点或者闭合节点,则判断是不是指定节点后代中所有文本节点和闭合节点中的最后一个
|
|
1840
1840
|
*/
|
|
@@ -2950,12 +2950,12 @@ const formatLineBreakSpaceText = ({ editor, node }) => {
|
|
|
2950
2950
|
endPrevNumber = (preText.match(regExp) || []).length;
|
|
2951
2951
|
}
|
|
2952
2952
|
}
|
|
2953
|
-
node.textContent = node.textContent.replace(/\n/g, (
|
|
2954
|
-
const
|
|
2955
|
-
if (!
|
|
2956
|
-
|
|
2953
|
+
node.textContent = node.textContent.replace(/\n/g, (char, index) => {
|
|
2954
|
+
const nextChar = node.textContent[index + 1];
|
|
2955
|
+
if (!nextChar || !isZeroWidthText(nextChar)) {
|
|
2956
|
+
char = char + getZeroWidthText();
|
|
2957
2957
|
}
|
|
2958
|
-
return
|
|
2958
|
+
return char;
|
|
2959
2959
|
});
|
|
2960
2960
|
if (startPrevNumber > 0) {
|
|
2961
2961
|
editor.selection.start.offset += startPrevNumber;
|
|
@@ -2970,8 +2970,8 @@ const formatZeroWidthTextMerge = ({ editor, node }) => {
|
|
|
2970
2970
|
let val = node.textContent;
|
|
2971
2971
|
let i = 0;
|
|
2972
2972
|
while (i < val.length) {
|
|
2973
|
-
const
|
|
2974
|
-
if (i > 0 && isZeroWidthText(
|
|
2973
|
+
const char = val.charAt(i);
|
|
2974
|
+
if (i > 0 && isZeroWidthText(char) && isZeroWidthText(val.charAt(i - 1))) {
|
|
2975
2975
|
if (editor.isSelectionInTargetNode(node, "start") && editor.selection.start.offset >= i + 1) {
|
|
2976
2976
|
editor.selection.start.offset -= 1;
|
|
2977
2977
|
}
|
|
@@ -3020,7 +3020,7 @@ const patchNodes$1 = (newNodes, oldNodes) => {
|
|
|
3020
3020
|
return [];
|
|
3021
3021
|
}
|
|
3022
3022
|
if (newNodes.length === 0) {
|
|
3023
|
-
return oldNodes.filter((node) =>
|
|
3023
|
+
return oldNodes.filter((node) => !!node).map((oldNode) => ({
|
|
3024
3024
|
oldNode,
|
|
3025
3025
|
newNode: null
|
|
3026
3026
|
}));
|
|
@@ -3361,7 +3361,7 @@ class Extension {
|
|
|
3361
3361
|
*/
|
|
3362
3362
|
__publicField(this, "onPasteKeepStyles");
|
|
3363
3363
|
/**
|
|
3364
|
-
*
|
|
3364
|
+
* 视图更新前回调
|
|
3365
3365
|
*/
|
|
3366
3366
|
__publicField(this, "onBeforeUpdateView");
|
|
3367
3367
|
/**
|
|
@@ -3369,7 +3369,7 @@ class Extension {
|
|
|
3369
3369
|
*/
|
|
3370
3370
|
__publicField(this, "onAfterUpdateView");
|
|
3371
3371
|
/**
|
|
3372
|
-
*
|
|
3372
|
+
* 在删除和换行操作中块节点从其父节点中抽离出去成为与父节点同级的节点后触发,如果返回true则表示继续使用默认逻辑,会将该节点转为段落,返回false则不走默认逻辑,需要自定义处理
|
|
3373
3373
|
*/
|
|
3374
3374
|
__publicField(this, "onDetachMentBlockFromParent");
|
|
3375
3375
|
/**
|
|
@@ -7010,10 +7010,10 @@ const CodeExtension = () => Extension.create({
|
|
|
7010
7010
|
const length = focusNodes.length;
|
|
7011
7011
|
for (let i = 0; i < length; i++) {
|
|
7012
7012
|
const node = focusNodes[i];
|
|
7013
|
-
const
|
|
7013
|
+
const isExistInCode = !!node.getMatchNode({
|
|
7014
7014
|
tag: "code"
|
|
7015
7015
|
});
|
|
7016
|
-
if (
|
|
7016
|
+
if (isExistInCode) {
|
|
7017
7017
|
continue;
|
|
7018
7018
|
}
|
|
7019
7019
|
const newNode2 = node.clone(true);
|
|
@@ -36049,7 +36049,7 @@ const AttachmentExtension = (props) => Extension.create({
|
|
|
36049
36049
|
if (node.isMatch({ tag: "span", marks: { [ATTACHMENT_NODE_TAG]: true } })) {
|
|
36050
36050
|
const url = node.marks[ATTACHMENT_NODE_TAG];
|
|
36051
36051
|
const text2 = KNode.flat(node.children ?? []).filter((n) => n.isText()).map((n) => n.textContent).join("");
|
|
36052
|
-
const icon = (_c = (_b = (_a = node.styles) == null ? void 0 : _a.backgroundImage) == null ? void 0 : _b.match(/url\(["']?(.*?)["']?\)/)) == null ? void 0 : _c[1];
|
|
36052
|
+
const icon = ((_c = (_b = (_a = node.styles) == null ? void 0 : _a.backgroundImage) == null ? void 0 : _b.match(/url\(["']?(.*?)["']?\)/)) == null ? void 0 : _c[1]) ?? "";
|
|
36053
36053
|
node.type = "closed";
|
|
36054
36054
|
node.tag = ATTACHMENT_NODE_TAG;
|
|
36055
36055
|
node.children = void 0;
|
|
@@ -36649,16 +36649,16 @@ const TableExtension = () => Extension.create({
|
|
|
36649
36649
|
//td内无段落则加入段落
|
|
36650
36650
|
({ node, editor }) => {
|
|
36651
36651
|
if (node.isMatch({ tag: "td" }) && !node.children.some((item) => item.isBlock())) {
|
|
36652
|
-
const
|
|
36652
|
+
const paragraph = KNode.create({
|
|
36653
36653
|
type: "block",
|
|
36654
36654
|
tag: editor.blockRenderTag
|
|
36655
36655
|
});
|
|
36656
|
-
|
|
36657
|
-
item.parent =
|
|
36656
|
+
paragraph.children = node.children.map((item) => {
|
|
36657
|
+
item.parent = paragraph;
|
|
36658
36658
|
return item;
|
|
36659
36659
|
});
|
|
36660
|
-
node.children = [
|
|
36661
|
-
|
|
36660
|
+
node.children = [paragraph];
|
|
36661
|
+
paragraph.parent = node;
|
|
36662
36662
|
}
|
|
36663
36663
|
},
|
|
36664
36664
|
//针对跨行跨列的单元格,增加隐藏单元格
|
|
@@ -36685,7 +36685,7 @@ const TableExtension = () => Extension.create({
|
|
|
36685
36685
|
if (this.isParagraph(blockNode) && blockNode.allIsPlaceholder() && pBlock && this.isParagraph(pBlock) && pBlock.allIsPlaceholder() && ppBlock) {
|
|
36686
36686
|
blockNode.toEmpty();
|
|
36687
36687
|
pBlock.toEmpty();
|
|
36688
|
-
const
|
|
36688
|
+
const paragraph = KNode.create({
|
|
36689
36689
|
type: "block",
|
|
36690
36690
|
tag: this.blockRenderTag,
|
|
36691
36691
|
children: [
|
|
@@ -36695,8 +36695,8 @@ const TableExtension = () => Extension.create({
|
|
|
36695
36695
|
}
|
|
36696
36696
|
]
|
|
36697
36697
|
});
|
|
36698
|
-
this.addNodeAfter(
|
|
36699
|
-
this.setSelectionBefore(
|
|
36698
|
+
this.addNodeAfter(paragraph, tableNode);
|
|
36699
|
+
this.setSelectionBefore(paragraph);
|
|
36700
36700
|
}
|
|
36701
36701
|
}
|
|
36702
36702
|
},
|
|
@@ -37146,7 +37146,7 @@ const patchNodes = (newNodes, oldNodes) => {
|
|
|
37146
37146
|
return [];
|
|
37147
37147
|
}
|
|
37148
37148
|
if (newNodes.length === 0) {
|
|
37149
|
-
return oldNodes.filter((node) =>
|
|
37149
|
+
return oldNodes.filter((node) => !!node).map((oldNode) => ({
|
|
37150
37150
|
type: "remove",
|
|
37151
37151
|
oldNode,
|
|
37152
37152
|
newNode: null
|
|
@@ -37344,9 +37344,9 @@ const insertDom = (editor, newNode2) => {
|
|
|
37344
37344
|
const previousDom = previousNode ? findDom(editor, previousNode) : null;
|
|
37345
37345
|
const nextNode = newNode2.getNext(parentNode ? parentNode.children : editor.stackNodes);
|
|
37346
37346
|
const nextDom = nextNode ? findDom(editor, nextNode) : null;
|
|
37347
|
-
if (previousDom &&
|
|
37347
|
+
if (previousDom && isContains(parentDom, previousDom)) {
|
|
37348
37348
|
previousDom.nextElementSibling ? parentDom.insertBefore(newDom, previousDom.nextElementSibling) : parentDom.appendChild(newDom);
|
|
37349
|
-
} else if (nextDom &&
|
|
37349
|
+
} else if (nextDom && isContains(parentDom, nextDom)) {
|
|
37350
37350
|
parentDom.insertBefore(newDom, nextDom);
|
|
37351
37351
|
} else {
|
|
37352
37352
|
const idx = (parentNode ? parentNode.children : editor.stackNodes).findIndex((item) => item.isEqual(newNode2));
|
|
@@ -37462,7 +37462,7 @@ class Editor {
|
|
|
37462
37462
|
*/
|
|
37463
37463
|
__publicField(this, "textRenderTag", "span");
|
|
37464
37464
|
/**
|
|
37465
|
-
*
|
|
37465
|
+
* 编辑器内渲染默认块级节点的真实标签,即段落标签【初始化后不建议修改】【open】
|
|
37466
37466
|
*/
|
|
37467
37467
|
__publicField(this, "blockRenderTag", "p");
|
|
37468
37468
|
/**
|
|
@@ -37558,7 +37558,7 @@ class Editor {
|
|
|
37558
37558
|
*/
|
|
37559
37559
|
__publicField(this, "onAfterUpdateView");
|
|
37560
37560
|
/**
|
|
37561
|
-
*
|
|
37561
|
+
* 在删除和换行操作中块节点从其父节点中抽离出去成为与父节点同级的节点后触发,如果返回true则表示继续使用默认逻辑,会将该节点转为段落,返回false则不走默认逻辑,需要自定义处理【初始化后不可修改】
|
|
37562
37562
|
*/
|
|
37563
37563
|
__publicField(this, "onDetachMentBlockFromParent");
|
|
37564
37564
|
/**
|
|
@@ -37603,7 +37603,7 @@ class Editor {
|
|
|
37603
37603
|
newHtml: void 0
|
|
37604
37604
|
});
|
|
37605
37605
|
/**
|
|
37606
|
-
* 是否编辑器内部渲染真实光标引起
|
|
37606
|
+
* 是否编辑器内部渲染真实光标引起selectionChange事件【不可修改】
|
|
37607
37607
|
*/
|
|
37608
37608
|
__publicField(this, "internalCauseSelectionChange", false);
|
|
37609
37609
|
/**
|
|
@@ -38429,8 +38429,7 @@ class Editor {
|
|
|
38429
38429
|
}
|
|
38430
38430
|
/**
|
|
38431
38431
|
* 向选区进行换行
|
|
38432
|
-
* 1.
|
|
38433
|
-
* 2. 非代码块样式内换行是插入换行符\n
|
|
38432
|
+
* 1. 在代码块样式内换行是插入换行符\n
|
|
38434
38433
|
* 2. 光标所在块节点是固定块节点,则无法换行
|
|
38435
38434
|
* 3. 光标所在块节点只有占位符,并且其存在父节点,且父节点不是固定块节点,会从父节点抽离到与父节点同级
|
|
38436
38435
|
* 4. 光标所在块节点只有占位符,并且不存在父节点,且不是段落,则会转为段落
|