@lobehub/editor 1.29.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.
- package/es/editor-kernel/kernel.js +2 -2
- package/es/editor-kernel/utils.d.ts +2 -1
- package/es/editor-kernel/utils.js +9 -2
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/plugins/code/plugin/index.js +24 -1
- package/es/plugins/codeblock/plugin/index.js +47 -3
- package/es/plugins/common/plugin/index.js +108 -3
- package/es/plugins/file/plugin/index.js +62 -16
- package/es/plugins/hr/plugin/index.js +25 -1
- package/es/plugins/image/node/basie-image-node.d.ts +2 -10
- package/es/plugins/image/node/basie-image-node.js +5 -30
- package/es/plugins/image/node/block-image-node.d.ts +1 -1
- package/es/plugins/image/node/block-image-node.js +3 -8
- package/es/plugins/image/node/image-node.d.ts +1 -1
- package/es/plugins/image/node/image-node.js +3 -8
- package/es/plugins/image/plugin/index.js +101 -17
- package/es/plugins/link/plugin/index.js +38 -4
- package/es/plugins/list/plugin/index.js +61 -0
- package/es/plugins/litexml/command/index.d.ts +16 -0
- package/es/plugins/litexml/command/index.js +94 -0
- package/es/plugins/litexml/data-source/litexml-data-source.d.ts +60 -0
- package/es/plugins/litexml/data-source/litexml-data-source.js +435 -0
- package/es/plugins/litexml/index.d.ts +7 -0
- package/es/plugins/litexml/index.js +5 -0
- package/es/plugins/litexml/plugin/index.d.ts +16 -0
- package/es/plugins/litexml/plugin/index.js +59 -0
- package/es/plugins/litexml/react/index.d.ts +3 -0
- package/es/plugins/litexml/react/index.js +22 -0
- package/es/plugins/litexml/service/litexml-service.d.ts +85 -0
- package/es/plugins/litexml/service/litexml-service.js +101 -0
- package/es/plugins/litexml/utils/index.d.ts +2 -0
- package/es/plugins/litexml/utils/index.js +33 -0
- package/es/plugins/math/plugin/index.js +40 -0
- package/es/plugins/mention/plugin/index.d.ts +1 -1
- package/es/plugins/mention/plugin/index.js +30 -4
- package/es/plugins/slash/react/ReactSlashPlugin.js +2 -1
- package/es/plugins/table/plugin/index.js +81 -0
- package/es/react/hooks/useEditorState/index.js +2 -1
- package/package.json +7 -6
|
@@ -132,7 +132,7 @@ export var BlockImageNode = /*#__PURE__*/function (_BaseImageNode) {
|
|
|
132
132
|
}, {
|
|
133
133
|
key: "clone",
|
|
134
134
|
value: function clone(node) {
|
|
135
|
-
return new BlockImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.
|
|
135
|
+
return new BlockImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__key);
|
|
136
136
|
}
|
|
137
137
|
}, {
|
|
138
138
|
key: "importJSON",
|
|
@@ -141,14 +141,12 @@ export var BlockImageNode = /*#__PURE__*/function (_BaseImageNode) {
|
|
|
141
141
|
height = serializedNode.height,
|
|
142
142
|
width = serializedNode.width,
|
|
143
143
|
maxWidth = serializedNode.maxWidth,
|
|
144
|
-
src = serializedNode.src
|
|
145
|
-
showCaption = serializedNode.showCaption;
|
|
144
|
+
src = serializedNode.src;
|
|
146
145
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
147
146
|
return $createBlockImageNode({
|
|
148
147
|
altText: altText,
|
|
149
148
|
height: height,
|
|
150
149
|
maxWidth: maxWidth,
|
|
151
|
-
showCaption: showCaption,
|
|
152
150
|
src: src,
|
|
153
151
|
width: width
|
|
154
152
|
}).updateFromJSON(serializedNode);
|
|
@@ -177,13 +175,10 @@ export function $createBlockImageNode(_ref) {
|
|
|
177
175
|
height = _ref.height,
|
|
178
176
|
_ref$maxWidth = _ref.maxWidth,
|
|
179
177
|
maxWidth = _ref$maxWidth === void 0 ? 500 : _ref$maxWidth,
|
|
180
|
-
captionsEnabled = _ref.captionsEnabled,
|
|
181
178
|
src = _ref.src,
|
|
182
179
|
width = _ref.width,
|
|
183
|
-
showCaption = _ref.showCaption,
|
|
184
|
-
caption = _ref.caption,
|
|
185
180
|
key = _ref.key;
|
|
186
|
-
return $applyNodeReplacement(new BlockImageNode(src, altText, maxWidth, width, height,
|
|
181
|
+
return $applyNodeReplacement(new BlockImageNode(src, altText, maxWidth, width, height, key));
|
|
187
182
|
}
|
|
188
183
|
function $convertImageElement(domNode) {
|
|
189
184
|
var img = domNode;
|
|
@@ -25,5 +25,5 @@ export declare class ImageNode extends BaseImageNode {
|
|
|
25
25
|
static importDOM(): DOMConversionMap | null;
|
|
26
26
|
decorate(): any;
|
|
27
27
|
}
|
|
28
|
-
export declare function $createImageNode({ altText, height, maxWidth,
|
|
28
|
+
export declare function $createImageNode({ altText, height, maxWidth, src, width, key, }: ImagePayload): ImageNode;
|
|
29
29
|
export declare function $isImageNode(node: LexicalNode): node is ImageNode;
|
|
@@ -116,7 +116,7 @@ export var ImageNode = /*#__PURE__*/function (_BaseImageNode) {
|
|
|
116
116
|
}, {
|
|
117
117
|
key: "clone",
|
|
118
118
|
value: function clone(node) {
|
|
119
|
-
return new ImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.
|
|
119
|
+
return new ImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__key);
|
|
120
120
|
}
|
|
121
121
|
}, {
|
|
122
122
|
key: "importJSON",
|
|
@@ -125,14 +125,12 @@ export var ImageNode = /*#__PURE__*/function (_BaseImageNode) {
|
|
|
125
125
|
height = serializedNode.height,
|
|
126
126
|
width = serializedNode.width,
|
|
127
127
|
maxWidth = serializedNode.maxWidth,
|
|
128
|
-
src = serializedNode.src
|
|
129
|
-
showCaption = serializedNode.showCaption;
|
|
128
|
+
src = serializedNode.src;
|
|
130
129
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
131
130
|
return $createImageNode({
|
|
132
131
|
altText: altText,
|
|
133
132
|
height: height,
|
|
134
133
|
maxWidth: maxWidth,
|
|
135
|
-
showCaption: showCaption,
|
|
136
134
|
src: src,
|
|
137
135
|
width: width
|
|
138
136
|
}).updateFromJSON(serializedNode);
|
|
@@ -161,13 +159,10 @@ export function $createImageNode(_ref) {
|
|
|
161
159
|
height = _ref.height,
|
|
162
160
|
_ref$maxWidth = _ref.maxWidth,
|
|
163
161
|
maxWidth = _ref$maxWidth === void 0 ? 500 : _ref$maxWidth,
|
|
164
|
-
captionsEnabled = _ref.captionsEnabled,
|
|
165
162
|
src = _ref.src,
|
|
166
163
|
width = _ref.width,
|
|
167
|
-
showCaption = _ref.showCaption,
|
|
168
|
-
caption = _ref.caption,
|
|
169
164
|
key = _ref.key;
|
|
170
|
-
return $applyNodeReplacement(new ImageNode(src, altText, maxWidth, width, height,
|
|
165
|
+
return $applyNodeReplacement(new ImageNode(src, altText, maxWidth, width, height, key));
|
|
171
166
|
}
|
|
172
167
|
function $convertImageElement(domNode) {
|
|
173
168
|
var img = domNode;
|
|
@@ -16,7 +16,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
16
16
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
17
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
18
18
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
+
import { INodeHelper } from "../../../editor-kernel/inode/helper";
|
|
19
20
|
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
21
|
+
import { ILitexmlService } from "../../litexml";
|
|
20
22
|
import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
|
|
21
23
|
import { IUploadService, UPLOAD_PRIORITY_HIGH } from "../../upload";
|
|
22
24
|
import { INSERT_IMAGE_COMMAND, registerImageCommand } from "../command";
|
|
@@ -42,22 +44,21 @@ export var ImagePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
42
44
|
_createClass(ImagePlugin, [{
|
|
43
45
|
key: "onInit",
|
|
44
46
|
value: function onInit(editor) {
|
|
45
|
-
var _this$
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
(_this$kernel$requireS3 = this.kernel.requireService(IUploadService)) === null || _this$kernel$requireS3 === void 0 || _this$kernel$requireS3.registerUpload( /*#__PURE__*/function () {
|
|
47
|
+
var _this$config;
|
|
48
|
+
this.register(registerImageCommand(editor, this.config.handleUpload, (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.defaultBlockImage));
|
|
49
|
+
this.registerMarkdown();
|
|
50
|
+
this.registerLiteXml();
|
|
51
|
+
this.registerUpload(editor);
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
key: "registerUpload",
|
|
55
|
+
value: function registerUpload(editor) {
|
|
56
|
+
var _this2 = this;
|
|
57
|
+
var uploadService = this.kernel.requireService(IUploadService);
|
|
58
|
+
if (!uploadService) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
uploadService.registerUpload( /*#__PURE__*/function () {
|
|
61
62
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file, from, range) {
|
|
62
63
|
var _this2$config;
|
|
63
64
|
var imageWidth;
|
|
@@ -84,7 +85,90 @@ export var ImagePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
84
85
|
return _ref.apply(this, arguments);
|
|
85
86
|
};
|
|
86
87
|
}(), UPLOAD_PRIORITY_HIGH);
|
|
87
|
-
|
|
88
|
+
}
|
|
89
|
+
}, {
|
|
90
|
+
key: "registerLiteXml",
|
|
91
|
+
value: function registerLiteXml() {
|
|
92
|
+
var litexmlService = this.kernel.requireService(ILitexmlService);
|
|
93
|
+
if (!litexmlService) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
litexmlService.registerXMLWriter(ImageNode.getType(), function (node, ctx) {
|
|
97
|
+
if ($isImageNode(node)) {
|
|
98
|
+
var attributes = {
|
|
99
|
+
src: node.src
|
|
100
|
+
};
|
|
101
|
+
if (node.altText) {
|
|
102
|
+
attributes.alt = node.altText;
|
|
103
|
+
}
|
|
104
|
+
return ctx.createXmlNode('img', attributes);
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
});
|
|
108
|
+
litexmlService.registerXMLWriter(BlockImageNode.getType(), function (node, ctx) {
|
|
109
|
+
if ($isBlockImageNode(node)) {
|
|
110
|
+
var attributes = {
|
|
111
|
+
block: 'true',
|
|
112
|
+
src: node.src
|
|
113
|
+
};
|
|
114
|
+
if (node.altText) {
|
|
115
|
+
attributes.alt = node.altText;
|
|
116
|
+
}
|
|
117
|
+
if (node.width) {
|
|
118
|
+
attributes.width = String(node.width);
|
|
119
|
+
}
|
|
120
|
+
if (node.maxWidth) {
|
|
121
|
+
attributes['max-width'] = String(node.maxWidth);
|
|
122
|
+
}
|
|
123
|
+
return ctx.createXmlNode('img', attributes);
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
});
|
|
127
|
+
litexmlService.registerXMLReader('img', function (xmlNode) {
|
|
128
|
+
if (xmlNode.getAttribute('block') === 'true') {
|
|
129
|
+
return INodeHelper.createElementNode(BlockImageNode.getType(), {
|
|
130
|
+
altText: xmlNode.getAttribute('alt') || '',
|
|
131
|
+
maxWidth: xmlNode.getAttribute('max-width') ? parseInt(xmlNode.getAttribute('max-width'), 10) : undefined,
|
|
132
|
+
src: xmlNode.getAttribute('src') || '',
|
|
133
|
+
width: xmlNode.getAttribute('width') ? parseInt(xmlNode.getAttribute('width'), 10) : undefined
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
return INodeHelper.createElementNode(ImageNode.getType(), {
|
|
137
|
+
altText: xmlNode.getAttribute('alt') || '',
|
|
138
|
+
maxWidth: xmlNode.getAttribute('max-width') ? parseInt(xmlNode.getAttribute('max-width'), 10) : undefined,
|
|
139
|
+
src: xmlNode.getAttribute('src') || '',
|
|
140
|
+
width: xmlNode.getAttribute('width') ? parseInt(xmlNode.getAttribute('width'), 10) : undefined
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}, {
|
|
146
|
+
key: "registerMarkdown",
|
|
147
|
+
value: function registerMarkdown() {
|
|
148
|
+
var markdownService = this.kernel.requireService(IMarkdownShortCutService);
|
|
149
|
+
if (!markdownService) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
markdownService.registerMarkdownWriter(ImageNode.getType(), function (ctx, node) {
|
|
153
|
+
if ($isImageNode(node)) {
|
|
154
|
+
ctx.appendLine(".concat(node.src, ")"));
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
markdownService.registerMarkdownWriter(BlockImageNode.getType(), function (ctx, node) {
|
|
158
|
+
if ($isBlockImageNode(node)) {
|
|
159
|
+
ctx.appendLine(".concat(node.src, ")\n\n"));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
markdownService.registerMarkdownReader('image', function (node) {
|
|
163
|
+
var altText = node.alt;
|
|
164
|
+
var src = node.url;
|
|
165
|
+
return INodeHelper.createTypeNode(ImageNode.getType(), {
|
|
166
|
+
altText: altText,
|
|
167
|
+
showCaption: false,
|
|
168
|
+
src: src,
|
|
169
|
+
version: 1
|
|
170
|
+
});
|
|
171
|
+
});
|
|
88
172
|
}
|
|
89
173
|
}, {
|
|
90
174
|
key: "getImageWidth",
|
|
@@ -22,6 +22,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
22
22
|
import { $createTextNode, COMMAND_PRIORITY_NORMAL, PASTE_COMMAND } from 'lexical';
|
|
23
23
|
import { INodeHelper } from "../../../editor-kernel/inode/helper";
|
|
24
24
|
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
25
|
+
import { ILitexmlService } from "../../litexml";
|
|
25
26
|
import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
|
|
26
27
|
import { INSERT_LINK_COMMAND, registerLinkCommand } from "../command";
|
|
27
28
|
import { $createLinkNode, $isLinkNode, AutoLinkNode, LinkNode } from "../node/LinkNode";
|
|
@@ -55,10 +56,7 @@ export var LinkPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
55
56
|
var _this$config,
|
|
56
57
|
_this$config2,
|
|
57
58
|
_this$config3,
|
|
58
|
-
_this2 = this
|
|
59
|
-
_this$kernel$requireS,
|
|
60
|
-
_this$kernel$requireS2,
|
|
61
|
-
_this$kernel$requireS3;
|
|
59
|
+
_this2 = this;
|
|
62
60
|
this.register(registerLinkCommand(editor));
|
|
63
61
|
this.register(registerLinkCommands(editor, this.kernel, {
|
|
64
62
|
attributes: (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.attributes,
|
|
@@ -80,6 +78,42 @@ export var LinkPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
80
78
|
}
|
|
81
79
|
return false;
|
|
82
80
|
}, COMMAND_PRIORITY_NORMAL));
|
|
81
|
+
this.registerMarkdown();
|
|
82
|
+
this.registerLiteXml();
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "registerLiteXml",
|
|
86
|
+
value: function registerLiteXml() {
|
|
87
|
+
var litexmlService = this.kernel.requireService(ILitexmlService);
|
|
88
|
+
if (!litexmlService) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
litexmlService.registerXMLWriter(LinkNode.getType(), function (node, ctx) {
|
|
92
|
+
if ($isLinkNode(node)) {
|
|
93
|
+
var attributes = {
|
|
94
|
+
href: node.getURL()
|
|
95
|
+
};
|
|
96
|
+
return ctx.createXmlNode('a', attributes);
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
});
|
|
100
|
+
litexmlService.registerXMLReader('a', function (xmlNode, children) {
|
|
101
|
+
var linkNode = INodeHelper.createElementNode('link', {
|
|
102
|
+
children: children,
|
|
103
|
+
direction: 'ltr',
|
|
104
|
+
format: '',
|
|
105
|
+
indent: 0,
|
|
106
|
+
type: 'link',
|
|
107
|
+
url: xmlNode.getAttribute('href') || '',
|
|
108
|
+
version: 1
|
|
109
|
+
});
|
|
110
|
+
return [linkNode];
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "registerMarkdown",
|
|
115
|
+
value: function registerMarkdown() {
|
|
116
|
+
var _this$kernel$requireS, _this$kernel$requireS2, _this$kernel$requireS3;
|
|
83
117
|
(_this$kernel$requireS = this.kernel.requireService(IMarkdownShortCutService)) === null || _this$kernel$requireS === void 0 || _this$kernel$requireS.registerMarkdownShortCut({
|
|
84
118
|
regExp: /\[([^[]+)]\(([^\s()]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?\)\s?$/,
|
|
85
119
|
replace: function replace(textNode, match) {
|
|
@@ -19,6 +19,7 @@ import { cx } from 'antd-style';
|
|
|
19
19
|
import { $isRootNode } from 'lexical';
|
|
20
20
|
import { INodeHelper } from "../../../editor-kernel/inode/helper";
|
|
21
21
|
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
22
|
+
import { ILitexmlService } from "../../litexml";
|
|
22
23
|
import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
|
|
23
24
|
import { listReplace } from "../utils";
|
|
24
25
|
import { registerCheckList } from "./checkList";
|
|
@@ -66,6 +67,66 @@ export var ListPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
66
67
|
enableHotkey: (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.enableHotkey
|
|
67
68
|
}));
|
|
68
69
|
this.registerMarkdown();
|
|
70
|
+
this.registerLiteXml();
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "registerLiteXml",
|
|
74
|
+
value: function registerLiteXml() {
|
|
75
|
+
var litexmlService = this.kernel.requireService(ILitexmlService);
|
|
76
|
+
if (!litexmlService) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
litexmlService.registerXMLWriter(ListNode.getType(), function (node, ctx) {
|
|
80
|
+
if ($isListNode(node)) {
|
|
81
|
+
var tagName = node.getListType() === 'number' ? 'ol' : 'ul';
|
|
82
|
+
var attributes = {};
|
|
83
|
+
if (node.getListType() === 'number' && node.getStart() !== 1) {
|
|
84
|
+
attributes.start = node.getStart().toString();
|
|
85
|
+
}
|
|
86
|
+
return ctx.createXmlNode(tagName, attributes);
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
});
|
|
90
|
+
litexmlService.registerXMLWriter(ListItemNode.getType(), function (node, ctx) {
|
|
91
|
+
if ($isListItemNode(node)) {
|
|
92
|
+
return ctx.createXmlNode('li');
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
});
|
|
96
|
+
litexmlService.registerXMLReader('ol', function (xmlNode, children) {
|
|
97
|
+
return INodeHelper.createElementNode('list', {
|
|
98
|
+
children: children,
|
|
99
|
+
direction: 'ltr',
|
|
100
|
+
format: '',
|
|
101
|
+
indent: 0,
|
|
102
|
+
listType: 'number',
|
|
103
|
+
start: xmlNode.getAttribute('start') ? parseInt(xmlNode.getAttribute('start'), 10) : 1,
|
|
104
|
+
tag: 'ol',
|
|
105
|
+
version: 1
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
litexmlService.registerXMLReader('ul', function (xmlNode, children) {
|
|
109
|
+
return INodeHelper.createElementNode('list', {
|
|
110
|
+
children: children,
|
|
111
|
+
direction: 'ltr',
|
|
112
|
+
format: '',
|
|
113
|
+
indent: 0,
|
|
114
|
+
listType: 'bullet',
|
|
115
|
+
start: 1,
|
|
116
|
+
tag: 'ul',
|
|
117
|
+
version: 1
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
litexmlService.registerXMLReader('li', function (xmlNode, children) {
|
|
121
|
+
return INodeHelper.createElementNode('listitem', {
|
|
122
|
+
children: children,
|
|
123
|
+
direction: 'ltr',
|
|
124
|
+
format: '',
|
|
125
|
+
indent: 0,
|
|
126
|
+
type: 'listitem',
|
|
127
|
+
version: 1
|
|
128
|
+
});
|
|
129
|
+
});
|
|
69
130
|
}
|
|
70
131
|
}, {
|
|
71
132
|
key: "registerMarkdown",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LexicalEditor } from 'lexical';
|
|
2
|
+
import type LitexmlDataSource from '../data-source/litexml-data-source';
|
|
3
|
+
export declare const LITEXML_APPLY_COMMAND: import("lexical").LexicalCommand<{
|
|
4
|
+
litexml: string | string[];
|
|
5
|
+
}>;
|
|
6
|
+
export declare const LITEXML_REMOVE_COMMAND: import("lexical").LexicalCommand<{
|
|
7
|
+
id: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const LITEXML_INSERT_COMMAND: import("lexical").LexicalCommand<{
|
|
10
|
+
beforeId: string;
|
|
11
|
+
litexml: string;
|
|
12
|
+
} | {
|
|
13
|
+
afterId: string;
|
|
14
|
+
litexml: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function registerLiteXMLCommand(editor: LexicalEditor, dataSource: LitexmlDataSource): () => void;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { mergeRegister } from '@lexical/utils';
|
|
2
|
+
import { $getNodeByKey, $insertNodes, $isElementNode, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
3
|
+
import { $closest } from "../../../editor-kernel";
|
|
4
|
+
import { $parseSerializedNodeImpl } from "../utils";
|
|
5
|
+
export var LITEXML_APPLY_COMMAND = createCommand('LITEXML_APPLY_COMMAND');
|
|
6
|
+
export var LITEXML_REMOVE_COMMAND = createCommand('LITEXML_REMOVE_COMMAND');
|
|
7
|
+
export var LITEXML_INSERT_COMMAND = createCommand('LITEXML_INSERT_COMMAND');
|
|
8
|
+
export function registerLiteXMLCommand(editor, dataSource) {
|
|
9
|
+
return mergeRegister(editor.registerCommand(LITEXML_APPLY_COMMAND, function (payload) {
|
|
10
|
+
var litexml = payload.litexml;
|
|
11
|
+
var arrayXml = Array.isArray(litexml) ? litexml : [litexml];
|
|
12
|
+
editor.update(function () {
|
|
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
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
prevNode = prevNode.insertAfter(newNode);
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
$insertNodes([newNode]);
|
|
39
|
+
prevNode = newNode;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Error replacing node:', error);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return false;
|
|
49
|
+
}, COMMAND_PRIORITY_EDITOR // Priority
|
|
50
|
+
), editor.registerCommand(LITEXML_REMOVE_COMMAND, function (payload) {
|
|
51
|
+
var id = payload.id;
|
|
52
|
+
editor.update(function () {
|
|
53
|
+
var node = $getNodeByKey(id);
|
|
54
|
+
if (node) {
|
|
55
|
+
node.remove();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return false;
|
|
59
|
+
}, COMMAND_PRIORITY_EDITOR // Priority
|
|
60
|
+
), editor.registerCommand(LITEXML_INSERT_COMMAND, function (payload) {
|
|
61
|
+
var litexml = payload.litexml;
|
|
62
|
+
var isBefore = ('beforeId' in payload);
|
|
63
|
+
var inode = dataSource.readLiteXMLToInode(litexml);
|
|
64
|
+
editor.update(function () {
|
|
65
|
+
try {
|
|
66
|
+
var referenceNode = null;
|
|
67
|
+
if (isBefore) {
|
|
68
|
+
referenceNode = $getNodeByKey(payload.beforeId);
|
|
69
|
+
} else {
|
|
70
|
+
referenceNode = $getNodeByKey(payload.afterId);
|
|
71
|
+
}
|
|
72
|
+
if (!referenceNode) {
|
|
73
|
+
throw new Error('Reference node not found for insertion.');
|
|
74
|
+
}
|
|
75
|
+
var newNodes = inode.root.children.map(function (child) {
|
|
76
|
+
return $parseSerializedNodeImpl(child, editor);
|
|
77
|
+
});
|
|
78
|
+
if (isBefore) {
|
|
79
|
+
referenceNode = referenceNode.insertBefore(newNodes);
|
|
80
|
+
} else {
|
|
81
|
+
newNodes.forEach(function (node) {
|
|
82
|
+
if (referenceNode) {
|
|
83
|
+
referenceNode = referenceNode.insertAfter(node);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Error inserting node:', error);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return false;
|
|
92
|
+
}, COMMAND_PRIORITY_EDITOR // Priority
|
|
93
|
+
));
|
|
94
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { LexicalEditor } from 'lexical';
|
|
2
|
+
import { DataSource } from "../../../editor-kernel";
|
|
3
|
+
import type { IWriteOptions } from "../../../editor-kernel/data-source";
|
|
4
|
+
import type { ILitexmlService } from '../service/litexml-service';
|
|
5
|
+
/**
|
|
6
|
+
* LitexmlDataSource - Handles conversion between Lexical editor state and XML format
|
|
7
|
+
* Provides read (parse XML to Lexical) and write (export Lexical to XML) capabilities
|
|
8
|
+
*/
|
|
9
|
+
export default class LitexmlDataSource extends DataSource {
|
|
10
|
+
protected dataType: string;
|
|
11
|
+
private litexmlService;
|
|
12
|
+
private ctx;
|
|
13
|
+
constructor(dataType?: string, service?: ILitexmlService);
|
|
14
|
+
readLiteXMLToInode(litexml: string): any;
|
|
15
|
+
/**
|
|
16
|
+
* Parse XML string and set it to the editor
|
|
17
|
+
* @param editor - The Lexical editor instance
|
|
18
|
+
* @param data - XML string to parse
|
|
19
|
+
*/
|
|
20
|
+
read(editor: LexicalEditor, data: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Export editor content to XML format
|
|
23
|
+
* @param editor - The Lexical editor instance
|
|
24
|
+
* @param options - Write options (e.g., selection flag)
|
|
25
|
+
* @returns XML string representation of the editor content
|
|
26
|
+
*/
|
|
27
|
+
write(editor: LexicalEditor, options?: IWriteOptions): any;
|
|
28
|
+
/**
|
|
29
|
+
* Parse XML string using browser's built-in parser
|
|
30
|
+
*/
|
|
31
|
+
private parseXMLString;
|
|
32
|
+
/**
|
|
33
|
+
* Convert XML document to Lexical node structure
|
|
34
|
+
*/
|
|
35
|
+
private xmlToLexical;
|
|
36
|
+
/**
|
|
37
|
+
* Recursively process XML elements and convert to Lexical nodes
|
|
38
|
+
*/
|
|
39
|
+
private processXMLElement;
|
|
40
|
+
/**
|
|
41
|
+
* Process XML element's children
|
|
42
|
+
*/
|
|
43
|
+
private processXMLChildren;
|
|
44
|
+
/**
|
|
45
|
+
* Convert Lexical node structure to XML string
|
|
46
|
+
*/
|
|
47
|
+
private lexicalToXML;
|
|
48
|
+
/**
|
|
49
|
+
* Recursively convert Lexical nodes to XML elements
|
|
50
|
+
*/
|
|
51
|
+
private nodesToXML;
|
|
52
|
+
/**
|
|
53
|
+
* Build XML attribute string from attributes object
|
|
54
|
+
*/
|
|
55
|
+
private buildXMLAttributes;
|
|
56
|
+
/**
|
|
57
|
+
* Escape XML special characters
|
|
58
|
+
*/
|
|
59
|
+
private escapeXML;
|
|
60
|
+
}
|