@lobehub/editor 1.30.0 → 1.31.0
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LexicalEditor } from 'lexical';
|
|
2
2
|
import type LitexmlDataSource from '../data-source/litexml-data-source';
|
|
3
3
|
export declare const LITEXML_APPLY_COMMAND: import("lexical").LexicalCommand<{
|
|
4
|
-
litexml: string;
|
|
4
|
+
litexml: string | string[];
|
|
5
5
|
}>;
|
|
6
6
|
export declare const LITEXML_REMOVE_COMMAND: import("lexical").LexicalCommand<{
|
|
7
7
|
id: string;
|
|
@@ -8,38 +8,41 @@ export var LITEXML_INSERT_COMMAND = createCommand('LITEXML_INSERT_COMMAND');
|
|
|
8
8
|
export function registerLiteXMLCommand(editor, dataSource) {
|
|
9
9
|
return mergeRegister(editor.registerCommand(LITEXML_APPLY_COMMAND, function (payload) {
|
|
10
10
|
var litexml = payload.litexml;
|
|
11
|
-
var
|
|
11
|
+
var arrayXml = Array.isArray(litexml) ? litexml : [litexml];
|
|
12
12
|
editor.update(function () {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
arrayXml.forEach(function (xml) {
|
|
14
|
+
var inode = dataSource.readLiteXMLToInode(xml);
|
|
15
|
+
var prevNode = null;
|
|
16
|
+
inode.root.children.forEach(function (child) {
|
|
17
|
+
try {
|
|
18
|
+
var oldNode = $getNodeByKey(child.id);
|
|
19
|
+
var newNode = $parseSerializedNodeImpl(child, editor);
|
|
20
|
+
if (oldNode) {
|
|
21
|
+
prevNode = oldNode.replace(newNode, $isElementNode(newNode));
|
|
22
|
+
} else {
|
|
23
|
+
if (prevNode) {
|
|
24
|
+
if (!newNode.isInline()) {
|
|
25
|
+
var prevBlock = $closest(prevNode, function (node) {
|
|
26
|
+
return node.isInline() === false;
|
|
27
|
+
});
|
|
28
|
+
if (prevBlock) {
|
|
29
|
+
prevNode = prevBlock.insertAfter(newNode);
|
|
30
|
+
} else {
|
|
31
|
+
$insertNodes([newNode]);
|
|
32
|
+
prevNode = newNode;
|
|
33
|
+
}
|
|
28
34
|
} else {
|
|
29
|
-
|
|
30
|
-
prevNode = newNode;
|
|
35
|
+
prevNode = prevNode.insertAfter(newNode);
|
|
31
36
|
}
|
|
32
37
|
} else {
|
|
33
|
-
|
|
38
|
+
$insertNodes([newNode]);
|
|
39
|
+
prevNode = newNode;
|
|
34
40
|
}
|
|
35
|
-
} else {
|
|
36
|
-
$insertNodes([newNode]);
|
|
37
|
-
prevNode = newNode;
|
|
38
41
|
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Error replacing node:', error);
|
|
39
44
|
}
|
|
40
|
-
}
|
|
41
|
-
console.error('Error replacing node:', error);
|
|
42
|
-
}
|
|
45
|
+
});
|
|
43
46
|
});
|
|
44
47
|
});
|
|
45
48
|
return false;
|
package/package.json
CHANGED