@lobehub/editor 1.34.5 → 1.36.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.
- package/es/plugins/image/plugin/index.js +10 -0
- package/es/plugins/litexml/command/diffCommand.d.ts +3 -0
- package/es/plugins/litexml/command/diffCommand.js +74 -25
- package/es/plugins/litexml/command/index.js +106 -9
- package/es/plugins/litexml/data-source/litexml-data-source.js +7 -4
- package/es/plugins/litexml/index.d.ts +1 -0
- package/es/plugins/litexml/index.js +1 -0
- package/es/plugins/litexml/node/DiffNode.d.ts +6 -5
- package/es/plugins/litexml/plugin/index.js +41 -0
- package/es/plugins/litexml/react/style.js +1 -1
- package/es/plugins/litexml/service/litexml-service.d.ts +4 -1
- package/package.json +1 -1
|
@@ -125,6 +125,7 @@ export var ImagePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
125
125
|
}, {
|
|
126
126
|
key: "registerLiteXml",
|
|
127
127
|
value: function registerLiteXml() {
|
|
128
|
+
var _this3 = this;
|
|
128
129
|
var litexmlService = this.kernel.requireService(ILitexmlService);
|
|
129
130
|
if (!litexmlService) {
|
|
130
131
|
return;
|
|
@@ -161,6 +162,15 @@ export var ImagePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
161
162
|
return false;
|
|
162
163
|
});
|
|
163
164
|
litexmlService.registerXMLReader('img', function (xmlNode) {
|
|
165
|
+
var _this3$config;
|
|
166
|
+
if (((_this3$config = _this3.config) === null || _this3$config === void 0 ? void 0 : _this3$config.defaultBlockImage) !== false) {
|
|
167
|
+
return INodeHelper.createElementNode(BlockImageNode.getType(), {
|
|
168
|
+
altText: xmlNode.getAttribute('alt') || '',
|
|
169
|
+
maxWidth: xmlNode.getAttribute('max-width') ? parseInt(xmlNode.getAttribute('max-width'), 10) : undefined,
|
|
170
|
+
src: xmlNode.getAttribute('src') || '',
|
|
171
|
+
width: xmlNode.getAttribute('width') ? parseInt(xmlNode.getAttribute('width'), 10) : undefined
|
|
172
|
+
});
|
|
173
|
+
}
|
|
164
174
|
if (xmlNode.getAttribute('block') === 'true') {
|
|
165
175
|
return INodeHelper.createElementNode(BlockImageNode.getType(), {
|
|
166
176
|
altText: xmlNode.getAttribute('alt') || '',
|
|
@@ -7,4 +7,7 @@ export declare const LITEXML_DIFFNODE_COMMAND: import("lexical").LexicalCommand<
|
|
|
7
7
|
action: DiffAction;
|
|
8
8
|
nodeKey: string;
|
|
9
9
|
}>;
|
|
10
|
+
export declare const LITEXML_DIFFNODE_ALL_COMMAND: import("lexical").LexicalCommand<{
|
|
11
|
+
action: DiffAction;
|
|
12
|
+
}>;
|
|
10
13
|
export declare function registerLiteXMLDiffCommand(editor: LexicalEditor): () => void;
|
|
@@ -1,11 +1,67 @@
|
|
|
1
1
|
import { mergeRegister } from '@lexical/utils';
|
|
2
|
-
import { $getNodeByKey, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
2
|
+
import { $getNodeByKey, $isElementNode, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
3
|
+
import { DiffNode } from "../node/DiffNode";
|
|
3
4
|
export var DiffAction = /*#__PURE__*/function (DiffAction) {
|
|
4
5
|
DiffAction[DiffAction["Reject"] = 0] = "Reject";
|
|
5
6
|
DiffAction[DiffAction["Accept"] = 1] = "Accept";
|
|
6
7
|
return DiffAction;
|
|
7
8
|
}({});
|
|
8
9
|
export var LITEXML_DIFFNODE_COMMAND = createCommand('LITEXML_DIFFNODE_COMMAND');
|
|
10
|
+
export var LITEXML_DIFFNODE_ALL_COMMAND = createCommand('LITEXML_DIFFNODE_ALL_COMMAND');
|
|
11
|
+
function doAction(node, action) {
|
|
12
|
+
if (node.diffType === 'modify') {
|
|
13
|
+
var children = node.getChildren();
|
|
14
|
+
if (action === DiffAction.Accept) {
|
|
15
|
+
node.replace(children[1], false).selectEnd();
|
|
16
|
+
} else if (action === DiffAction.Reject) {
|
|
17
|
+
node.replace(children[0], false).selectEnd();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (node.diffType === 'remove') {
|
|
21
|
+
if (action === DiffAction.Accept) {
|
|
22
|
+
node.remove();
|
|
23
|
+
} else if (action === DiffAction.Reject) {
|
|
24
|
+
var _children = node.getChildren();
|
|
25
|
+
node.replace(_children[0], false).selectEnd();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (node.diffType === 'add') {
|
|
29
|
+
if (action === DiffAction.Accept) {
|
|
30
|
+
var _children2 = node.getChildren();
|
|
31
|
+
node.replace(_children2[0], false).selectEnd();
|
|
32
|
+
} else if (action === DiffAction.Reject) {
|
|
33
|
+
node.remove();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (node.diffType === 'listItemModify') {
|
|
37
|
+
var _children3 = node.getChildren();
|
|
38
|
+
if (action === DiffAction.Accept) {
|
|
39
|
+
var lastChild = _children3[1];
|
|
40
|
+
if (!$isElementNode(lastChild)) {
|
|
41
|
+
throw new Error('Expected element node as child of DiffNode');
|
|
42
|
+
}
|
|
43
|
+
var nodeChildrens = lastChild.getChildren();
|
|
44
|
+
for (var i = nodeChildrens.length - 1; i >= 0; i--) {
|
|
45
|
+
node.insertAfter(nodeChildrens[i]);
|
|
46
|
+
}
|
|
47
|
+
var parent = node.getParentOrThrow();
|
|
48
|
+
node.remove();
|
|
49
|
+
parent.selectEnd();
|
|
50
|
+
} else if (action === DiffAction.Reject) {
|
|
51
|
+
var firstChild = _children3[0];
|
|
52
|
+
if (!$isElementNode(firstChild)) {
|
|
53
|
+
throw new Error('Expected element node as child of DiffNode');
|
|
54
|
+
}
|
|
55
|
+
var _nodeChildrens = firstChild.getChildren();
|
|
56
|
+
for (var _i = _nodeChildrens.length - 1; _i >= 0; _i--) {
|
|
57
|
+
node.insertAfter(_nodeChildrens[_i]);
|
|
58
|
+
}
|
|
59
|
+
var _parent = node.getParentOrThrow();
|
|
60
|
+
node.remove();
|
|
61
|
+
_parent.selectEnd();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
9
65
|
export function registerLiteXMLDiffCommand(editor) {
|
|
10
66
|
return mergeRegister(editor.registerCommand(LITEXML_DIFFNODE_COMMAND, function (payload) {
|
|
11
67
|
var action = payload.action,
|
|
@@ -17,30 +73,23 @@ export function registerLiteXMLDiffCommand(editor) {
|
|
|
17
73
|
return false;
|
|
18
74
|
}
|
|
19
75
|
editor.update(function () {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (action === DiffAction.Accept) {
|
|
38
|
-
var _children2 = node.getChildren();
|
|
39
|
-
node.replace(_children2[0], false).selectEnd();
|
|
40
|
-
} else if (action === DiffAction.Reject) {
|
|
41
|
-
node.remove();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
76
|
+
doAction(node, action);
|
|
77
|
+
});
|
|
78
|
+
return false;
|
|
79
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(LITEXML_DIFFNODE_ALL_COMMAND, function (payload) {
|
|
80
|
+
var action = payload.action;
|
|
81
|
+
var nodes = editor.read(function () {
|
|
82
|
+
return Array.from(editor._editorState._nodeMap.values()).filter(function (n) {
|
|
83
|
+
return n instanceof DiffNode && !!n.getParent();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
if (!nodes.length) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
editor.update(function () {
|
|
90
|
+
nodes.forEach(function (node) {
|
|
91
|
+
doAction(node, action);
|
|
92
|
+
});
|
|
44
93
|
});
|
|
45
94
|
return false;
|
|
46
95
|
}, COMMAND_PRIORITY_EDITOR));
|
|
@@ -9,9 +9,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
9
9
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
10
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
11
11
|
import { mergeRegister } from '@lexical/utils';
|
|
12
|
-
import { $getNodeByKey, $insertNodes, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
12
|
+
import { $createParagraphNode, $getNodeByKey, $insertNodes, $isElementNode, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
13
13
|
import { $closest } from "../../../editor-kernel";
|
|
14
|
-
import { $createDiffNode } from "../node/DiffNode";
|
|
14
|
+
import { $createDiffNode, DiffNode } from "../node/DiffNode";
|
|
15
15
|
import { $cloneNode, $parseSerializedNodeImpl, charToId } from "../utils";
|
|
16
16
|
|
|
17
17
|
// Helpers to reduce duplication and improve readability
|
|
@@ -41,6 +41,13 @@ function handleReplaceForApplyDelay(oldNode, newNode, modifyBlockNodes, diffNode
|
|
|
41
41
|
if (!oldBlock) {
|
|
42
42
|
throw new Error('Old block node not found for diffing.');
|
|
43
43
|
}
|
|
44
|
+
var originDiffNode = $closest(oldNode, function (node) {
|
|
45
|
+
return node.getType() === DiffNode.getType();
|
|
46
|
+
});
|
|
47
|
+
if (originDiffNode) {
|
|
48
|
+
oldNode.replace(newNode, false);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
44
51
|
if (oldNode === oldBlock) {
|
|
45
52
|
var diffNode = $createDiffNode('modify');
|
|
46
53
|
diffNode.append($cloneNode(oldBlock, editor), newNode);
|
|
@@ -59,14 +66,35 @@ function finalizeModifyBlocks(modifyBlockNodes, diffNodeMap, editor) {
|
|
|
59
66
|
var _iterator = _createForOfIteratorHelper(modifyBlockNodes),
|
|
60
67
|
_step;
|
|
61
68
|
try {
|
|
62
|
-
|
|
69
|
+
var _loop = function _loop() {
|
|
63
70
|
var blockNodeKey = _step.value;
|
|
64
71
|
var blockNode = $getNodeByKey(blockNodeKey);
|
|
65
72
|
var diffNode = diffNodeMap.get(blockNodeKey);
|
|
66
73
|
if (diffNode && blockNode) {
|
|
67
|
-
|
|
68
|
-
blockNode.
|
|
74
|
+
// 如果是列表项,可能需要特殊处理
|
|
75
|
+
if (blockNode.getType() === 'listitem' && $isElementNode(blockNode)) {
|
|
76
|
+
var newDiffNode = $createDiffNode('listItemModify');
|
|
77
|
+
var firstChild = diffNode.getFirstChild();
|
|
78
|
+
if (firstChild && $isElementNode(firstChild)) {
|
|
79
|
+
newDiffNode.append(firstChild);
|
|
80
|
+
}
|
|
81
|
+
var children = blockNode.getChildren();
|
|
82
|
+
var p = $createParagraphNode();
|
|
83
|
+
children.forEach(function (child) {
|
|
84
|
+
child.remove();
|
|
85
|
+
p.append(child);
|
|
86
|
+
});
|
|
87
|
+
newDiffNode.append(p);
|
|
88
|
+
blockNode.append(newDiffNode);
|
|
89
|
+
return 1; // continue
|
|
90
|
+
} else {
|
|
91
|
+
diffNode.append($cloneNode(blockNode, editor));
|
|
92
|
+
blockNode.replace(diffNode, false);
|
|
93
|
+
}
|
|
69
94
|
}
|
|
95
|
+
};
|
|
96
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
97
|
+
if (_loop()) continue;
|
|
70
98
|
}
|
|
71
99
|
} catch (err) {
|
|
72
100
|
_iterator.e(err);
|
|
@@ -226,6 +254,32 @@ function handleRemove(editor, key, delay) {
|
|
|
226
254
|
|
|
227
255
|
// delay removal: show a diff
|
|
228
256
|
if (node.isInline() === false) {
|
|
257
|
+
var originDiffNode = $closest(node, function (node) {
|
|
258
|
+
return node.getType() === DiffNode.getType();
|
|
259
|
+
});
|
|
260
|
+
if (originDiffNode) {
|
|
261
|
+
switch (originDiffNode.diffType) {
|
|
262
|
+
case 'add':
|
|
263
|
+
{
|
|
264
|
+
originDiffNode.remove();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
case 'listItemModify':
|
|
268
|
+
case 'modify':
|
|
269
|
+
{
|
|
270
|
+
var children = originDiffNode.getChildren();
|
|
271
|
+
originDiffNode.replace(children[0], false).selectEnd();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
case 'remove':
|
|
275
|
+
case 'unchanged':
|
|
276
|
+
{
|
|
277
|
+
// do nothing special
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
229
283
|
var diffNode = $createDiffNode('remove');
|
|
230
284
|
diffNode.append($cloneNode(node, editor));
|
|
231
285
|
node.replace(diffNode, false);
|
|
@@ -236,6 +290,13 @@ function handleRemove(editor, key, delay) {
|
|
|
236
290
|
if (!oldBlock) {
|
|
237
291
|
throw new Error('Old block node not found for removal.');
|
|
238
292
|
}
|
|
293
|
+
var _originDiffNode = $closest(node, function (node) {
|
|
294
|
+
return node.getType() === DiffNode.getType();
|
|
295
|
+
});
|
|
296
|
+
if (_originDiffNode) {
|
|
297
|
+
node.remove();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
239
300
|
// wrap changes inside a modify diff
|
|
240
301
|
wrapBlockModify(oldBlock, editor, function () {
|
|
241
302
|
node.remove();
|
|
@@ -278,6 +339,12 @@ function handleInsert(editor, payload, dataSource) {
|
|
|
278
339
|
// delay insertion: show diffs or wrap block modifications
|
|
279
340
|
if (isBefore) {
|
|
280
341
|
if (referenceNode.isInline() === false) {
|
|
342
|
+
var originDiffNode = $closest(referenceNode, function (node) {
|
|
343
|
+
return node.getType() === DiffNode.getType();
|
|
344
|
+
});
|
|
345
|
+
if (originDiffNode) {
|
|
346
|
+
referenceNode = originDiffNode;
|
|
347
|
+
}
|
|
281
348
|
var diffNodes = newNodes.map(function (node) {
|
|
282
349
|
var diffNode = $createDiffNode('add');
|
|
283
350
|
diffNode.append(node);
|
|
@@ -295,16 +362,34 @@ function handleInsert(editor, payload, dataSource) {
|
|
|
295
362
|
if (!refBlock) {
|
|
296
363
|
throw new Error('Reference block node not found for insertion.');
|
|
297
364
|
}
|
|
298
|
-
|
|
365
|
+
var _originDiffNode2 = $closest(referenceNode, function (node) {
|
|
366
|
+
return node.getType() === DiffNode.getType();
|
|
367
|
+
});
|
|
368
|
+
if (_originDiffNode2) {
|
|
369
|
+
// 可能是 modify / add,那么直接修改就好了
|
|
299
370
|
newNodes.forEach(function (node) {
|
|
300
371
|
if (referenceNode) {
|
|
301
372
|
referenceNode = referenceNode.insertBefore(node);
|
|
302
373
|
}
|
|
303
374
|
});
|
|
304
|
-
}
|
|
375
|
+
} else {
|
|
376
|
+
wrapBlockModify(refBlock, editor, function () {
|
|
377
|
+
newNodes.forEach(function (node) {
|
|
378
|
+
if (referenceNode) {
|
|
379
|
+
referenceNode = referenceNode.insertBefore(node);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
}
|
|
305
384
|
}
|
|
306
385
|
} else {
|
|
307
386
|
if (referenceNode.isInline() === false) {
|
|
387
|
+
var _originDiffNode3 = $closest(referenceNode, function (node) {
|
|
388
|
+
return node.getType() === DiffNode.getType();
|
|
389
|
+
});
|
|
390
|
+
if (_originDiffNode3) {
|
|
391
|
+
referenceNode = _originDiffNode3;
|
|
392
|
+
}
|
|
308
393
|
newNodes.forEach(function (node) {
|
|
309
394
|
if (referenceNode) {
|
|
310
395
|
var diffNode = $createDiffNode('add');
|
|
@@ -319,13 +404,25 @@ function handleInsert(editor, payload, dataSource) {
|
|
|
319
404
|
if (!_refBlock) {
|
|
320
405
|
throw new Error('Reference block node not found for insertion.');
|
|
321
406
|
}
|
|
322
|
-
|
|
407
|
+
var _originDiffNode4 = $closest(referenceNode, function (node) {
|
|
408
|
+
return node.getType() === DiffNode.getType();
|
|
409
|
+
});
|
|
410
|
+
if (_originDiffNode4) {
|
|
411
|
+
// 可能是 modify / add,那么直接修改就好了
|
|
323
412
|
newNodes.forEach(function (node) {
|
|
324
413
|
if (referenceNode) {
|
|
325
414
|
referenceNode = referenceNode.insertAfter(node);
|
|
326
415
|
}
|
|
327
416
|
});
|
|
328
|
-
}
|
|
417
|
+
} else {
|
|
418
|
+
wrapBlockModify(_refBlock, editor, function () {
|
|
419
|
+
newNodes.forEach(function (node) {
|
|
420
|
+
if (referenceNode) {
|
|
421
|
+
referenceNode = referenceNode.insertAfter(node);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
}
|
|
329
426
|
}
|
|
330
427
|
}
|
|
331
428
|
} catch (error) {
|
|
@@ -368,16 +368,19 @@ var LitexmlDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
368
368
|
try {
|
|
369
369
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
370
370
|
var writer = _step2.value;
|
|
371
|
-
var handled = writer(node, this.ctx, indent);
|
|
371
|
+
var handled = writer(node, this.ctx, indent, this.nodesToXML.bind(this));
|
|
372
372
|
if (handled) {
|
|
373
|
+
if ('lines' in handled) {
|
|
374
|
+
lines.push.apply(lines, _toConsumableArray(handled.lines));
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
373
377
|
var attrs = this.buildXMLAttributes(_objectSpread({
|
|
374
378
|
id: idToChar(node.getKey())
|
|
375
379
|
}, handled.attributes));
|
|
376
380
|
var openTag = "".concat(indentStr, "<").concat(handled.tagName).concat(attrs, ">");
|
|
377
381
|
var closeTag = "</".concat(handled.tagName, ">");
|
|
378
382
|
if (handled.textContent) {
|
|
379
|
-
|
|
380
|
-
lines.push("".concat(openTag).concat(childLines.join('')).concat(closeTag));
|
|
383
|
+
lines.push("".concat(openTag).concat(handled.textContent).concat(closeTag));
|
|
381
384
|
} else if ($isElementNode(node)) {
|
|
382
385
|
var children = node.getChildren();
|
|
383
386
|
children.forEach(function (child) {
|
|
@@ -399,7 +402,7 @@ var LitexmlDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
399
402
|
if ($isElementNode(node)) {
|
|
400
403
|
var _children = node.getChildren();
|
|
401
404
|
_children.forEach(function (child) {
|
|
402
|
-
_this6.nodesToXML(child, childLines, indent
|
|
405
|
+
_this6.nodesToXML(child, childLines, indent);
|
|
403
406
|
});
|
|
404
407
|
}
|
|
405
408
|
lines.push.apply(lines, childLines);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { LITEXML_APPLY_COMMAND, LITEXML_INSERT_COMMAND, LITEXML_MODIFY_COMMAND, LITEXML_REMOVE_COMMAND, } from './command';
|
|
2
|
+
export { DiffAction, LITEXML_DIFFNODE_ALL_COMMAND, LITEXML_DIFFNODE_COMMAND, } from './command/diffCommand';
|
|
2
3
|
export { default as LitexmlDataSource } from './data-source/litexml-data-source';
|
|
3
4
|
export type { LitexmlPluginOptions } from './plugin';
|
|
4
5
|
export { LitexmlPlugin } from './plugin';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { LITEXML_APPLY_COMMAND, LITEXML_INSERT_COMMAND, LITEXML_MODIFY_COMMAND, LITEXML_REMOVE_COMMAND } from "./command";
|
|
2
|
+
export { DiffAction, LITEXML_DIFFNODE_ALL_COMMAND, LITEXML_DIFFNODE_COMMAND } from "./command/diffCommand";
|
|
2
3
|
export { default as LitexmlDataSource } from "./data-source/litexml-data-source";
|
|
3
4
|
export { LitexmlPlugin } from "./plugin";
|
|
4
5
|
export { ReactLiteXmlPlugin } from "./react";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DOMExportOutput, EditorConfig, ElementDOMSlot, LexicalEditor, LexicalUpdateJSON, SerializedElementNode, Spread } from 'lexical';
|
|
2
2
|
import { CardLikeElementNode } from "../../common/node/cursor";
|
|
3
|
+
export type DiffType = 'add' | 'remove' | 'modify' | 'unchanged' | 'listItemModify';
|
|
3
4
|
export type SerializedDiffNode = Spread<{
|
|
4
|
-
diffType:
|
|
5
|
+
diffType: DiffType;
|
|
5
6
|
}, SerializedElementNode>;
|
|
6
7
|
/** DiffNode - contains two block children: original and modified */
|
|
7
8
|
export declare class DiffNode extends CardLikeElementNode {
|
|
@@ -10,9 +11,9 @@ export declare class DiffNode extends CardLikeElementNode {
|
|
|
10
11
|
static importJSON(serializedNode: SerializedDiffNode): DiffNode;
|
|
11
12
|
static importDOM(): null;
|
|
12
13
|
private __diffType;
|
|
13
|
-
constructor(type:
|
|
14
|
-
get diffType():
|
|
15
|
-
setDiffType(type:
|
|
14
|
+
constructor(type: DiffType, key?: string);
|
|
15
|
+
get diffType(): DiffType;
|
|
16
|
+
setDiffType(type: DiffType): this;
|
|
16
17
|
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedDiffNode>): this;
|
|
17
18
|
exportJSON(): SerializedDiffNode;
|
|
18
19
|
exportDOM(editor: LexicalEditor): DOMExportOutput;
|
|
@@ -22,5 +23,5 @@ export declare class DiffNode extends CardLikeElementNode {
|
|
|
22
23
|
isInline(): boolean;
|
|
23
24
|
isCardLike(): boolean;
|
|
24
25
|
}
|
|
25
|
-
export declare function $createDiffNode(diffType?:
|
|
26
|
+
export declare function $createDiffNode(diffType?: DiffType): DiffNode;
|
|
26
27
|
export declare function $isDiffNode(node: unknown): node is DiffNode;
|
|
@@ -36,6 +36,7 @@ export var LitexmlPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
36
36
|
_classCallCheck(this, LitexmlPlugin);
|
|
37
37
|
_this = _super.call(this);
|
|
38
38
|
_defineProperty(_assertThisInitialized(_this), "datasource", void 0);
|
|
39
|
+
_defineProperty(_assertThisInitialized(_this), "service", void 0);
|
|
39
40
|
_this.kernel = kernel;
|
|
40
41
|
_this.config = config;
|
|
41
42
|
kernel.registerThemes({
|
|
@@ -44,6 +45,7 @@ export var LitexmlPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
44
45
|
|
|
45
46
|
// Create and register the Litexml service
|
|
46
47
|
var litexmlService = new LitexmlService();
|
|
48
|
+
_this.service = litexmlService;
|
|
47
49
|
kernel.registerService(ILitexmlService, litexmlService);
|
|
48
50
|
_this.datasource = new LitexmlDataSource('litexml', function (serviceId) {
|
|
49
51
|
return kernel.requireService(serviceId);
|
|
@@ -72,6 +74,45 @@ export var LitexmlPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
72
74
|
// Plugin initialization logic can be added here if needed
|
|
73
75
|
this.register(registerLiteXMLCommand(editor, this.datasource));
|
|
74
76
|
this.register(registerLiteXMLDiffCommand(editor));
|
|
77
|
+
this.regiserLiteXml();
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "regiserLiteXml",
|
|
81
|
+
value: function regiserLiteXml() {
|
|
82
|
+
this.service.registerXMLWriter(DiffNode.getType(), function (node, ctx, indent, nodeToXML) {
|
|
83
|
+
var diffNode = node;
|
|
84
|
+
var lines = [];
|
|
85
|
+
switch (diffNode.diffType) {
|
|
86
|
+
case 'modify':
|
|
87
|
+
{
|
|
88
|
+
nodeToXML(diffNode.getChildAtIndex(1), lines, indent);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'add':
|
|
92
|
+
{
|
|
93
|
+
nodeToXML(diffNode.getChildAtIndex(0), lines, indent);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'remove':
|
|
97
|
+
{
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case 'listItemModify':
|
|
101
|
+
{
|
|
102
|
+
diffNode.getChildAtIndex(1).getChildren().forEach(function (child) {
|
|
103
|
+
nodeToXML(child, lines, indent);
|
|
104
|
+
});
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
{
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
lines: lines
|
|
114
|
+
};
|
|
115
|
+
});
|
|
75
116
|
}
|
|
76
117
|
}]);
|
|
77
118
|
return LitexmlPlugin;
|
|
@@ -4,5 +4,5 @@ import { createStyles } from 'antd-style';
|
|
|
4
4
|
export var useStyles = createStyles(function (_ref) {
|
|
5
5
|
var css = _ref.css,
|
|
6
6
|
token = _ref.token;
|
|
7
|
-
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n .toolbar {\n position: absolute;\n z-index: 10;\n inset-block-end: 0;\n inset-inline-end: 8px;\n\n opacity: 0;\n }\n\n &:hover {\n .toolbar {\n opacity: 1;\n }\n }\n\n &[data-diff-type='add'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n }\n\n &[data-diff-type='remove'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n }\n\n &[data-diff-type='modify'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n "])), token.colorSuccess, token.colorError, token.colorTextQuaternary, token.colorWarning, token.colorTextQuaternary);
|
|
7
|
+
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n .toolbar {\n position: absolute;\n z-index: 10;\n inset-block-end: 0;\n inset-inline-end: 8px;\n\n opacity: 0;\n }\n\n &:hover {\n .toolbar {\n opacity: 1;\n }\n }\n\n &[data-diff-type='add'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n }\n\n &[data-diff-type='remove'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n }\n\n &[data-diff-type='listItemModify'] {\n display: inline-block;\n\n p {\n display: block !important;\n }\n }\n\n &[data-diff-type='listItemModify'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n\n &[data-diff-type='modify'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n "])), token.colorSuccess, token.colorError, token.colorTextQuaternary, token.colorWarning, token.colorTextQuaternary, token.colorWarning, token.colorTextQuaternary);
|
|
8
8
|
});
|
|
@@ -6,7 +6,7 @@ export type XMLReaderFunc = (xmlElement: Element, children: any[]) => any | any[
|
|
|
6
6
|
/**
|
|
7
7
|
* XML Writer function type - converts Lexical node to XML string
|
|
8
8
|
*/
|
|
9
|
-
export type XMLWriterFunc = (node: LexicalNode, ctx: IWriterContext, indent: number) => IXmlNode | false;
|
|
9
|
+
export type XMLWriterFunc = (node: LexicalNode, ctx: IWriterContext, indent: number, nodeToXML: (node: any, lines: string[], indent?: number) => void) => IXmlNode | HandleChildrenResult | false;
|
|
10
10
|
/**
|
|
11
11
|
* Record of XML readers indexed by tag name
|
|
12
12
|
*/
|
|
@@ -27,6 +27,9 @@ export interface IXmlNode {
|
|
|
27
27
|
tagName: string;
|
|
28
28
|
textContent?: string;
|
|
29
29
|
}
|
|
30
|
+
export interface HandleChildrenResult {
|
|
31
|
+
lines: string[];
|
|
32
|
+
}
|
|
30
33
|
export interface IWriterContext {
|
|
31
34
|
createXmlNode(tagName: string, attributes?: {
|
|
32
35
|
[key: string]: string;
|
package/package.json
CHANGED