@lobehub/editor 3.3.2 → 3.4.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/index.d.ts +1 -0
- package/es/editor-kernel/index.js +3 -1
- package/es/editor-kernel/kernel.js +1 -0
- package/es/editor-kernel/lexical/Lexical.dev.js +3052 -0
- package/es/editor-kernel/lexical/Lexical.dev.mjs +15365 -0
- package/es/editor-kernel/lexical/Lexical.js +7634 -0
- package/es/editor-kernel/lexical/Lexical.mjs +7258 -0
- package/es/editor-kernel/lexical/LexicalCommands.d.ts +175 -0
- package/es/editor-kernel/lexical/LexicalConstants.d.ts +54 -0
- package/es/editor-kernel/lexical/LexicalEditor.d.ts +672 -0
- package/es/editor-kernel/lexical/LexicalEditorState.d.ts +39 -0
- package/es/editor-kernel/lexical/LexicalEvents.d.ts +22 -0
- package/es/editor-kernel/lexical/LexicalGC.d.ts +23 -0
- package/es/editor-kernel/lexical/LexicalMutations.d.ts +12 -0
- package/es/editor-kernel/lexical/LexicalNode.d.ts +689 -0
- package/es/editor-kernel/lexical/LexicalNodeState.d.ts +569 -0
- package/es/editor-kernel/lexical/LexicalNormalization.d.ts +11 -0
- package/es/editor-kernel/lexical/LexicalReconciler.d.ts +28 -0
- package/es/editor-kernel/lexical/LexicalSelection.d.ts +368 -0
- package/es/editor-kernel/lexical/LexicalUpdateTags.d.ts +67 -0
- package/es/editor-kernel/lexical/LexicalUpdates.d.ts +72 -0
- package/es/editor-kernel/lexical/LexicalUtils.d.ts +492 -0
- package/es/editor-kernel/lexical/caret/LexicalCaret.d.ts +635 -0
- package/es/editor-kernel/lexical/caret/LexicalCaretUtils.d.ts +224 -0
- package/es/editor-kernel/lexical/extension-core/defineExtension.d.ts +126 -0
- package/es/editor-kernel/lexical/extension-core/index.d.ts +38 -0
- package/es/editor-kernel/lexical/extension-core/internal.d.ts +32 -0
- package/es/editor-kernel/lexical/extension-core/safeCast.d.ts +15 -0
- package/es/editor-kernel/lexical/extension-core/shallowMergeConfig.d.ts +20 -0
- package/es/editor-kernel/lexical/extension-core/types.d.ts +371 -0
- package/es/editor-kernel/lexical/index.d.ts +368 -0
- package/es/editor-kernel/lexical/nodes/ArtificialNode.d.ts +16 -0
- package/es/editor-kernel/lexical/nodes/LexicalDecoratorNode.d.ts +32 -0
- package/es/editor-kernel/lexical/nodes/LexicalElementNode.d.ts +235 -0
- package/es/editor-kernel/lexical/nodes/LexicalLineBreakNode.d.ts +30 -0
- package/es/editor-kernel/lexical/nodes/LexicalParagraphNode.d.ts +39 -0
- package/es/editor-kernel/lexical/nodes/LexicalRootNode.d.ts +35 -0
- package/es/editor-kernel/lexical/nodes/LexicalTabNode.d.ts +30 -0
- package/es/editor-kernel/lexical/nodes/LexicalTextNode.d.ts +311 -0
- package/es/plugins/common/data-source/json-data-source.js +29 -3
- package/es/plugins/common/react/ReactPlainText.js +9 -0
- package/es/plugins/common/utils/index.d.ts +2 -1
- package/es/plugins/common/utils/index.js +33 -0
- package/es/plugins/litexml/command/index.js +9 -1
- package/es/plugins/litexml/data-source/litexml-data-source.js +12 -2
- package/es/plugins/litexml/plugin/index.js +41 -3
- package/es/plugins/litexml/utils/index.d.ts +2 -1
- package/es/plugins/litexml/utils/index.js +7 -1
- package/es/plugins/markdown/data-source/markdown-data-source.js +6 -25
- package/es/plugins/markdown/data-source/markdown-writer-context.d.ts +5 -1
- package/es/plugins/markdown/data-source/markdown-writer-context.js +27 -2
- package/es/plugins/markdown/service/shortcut.d.ts +7 -0
- package/es/types/kernel.d.ts +4 -0
- package/package.json +8 -2
- package/scripts/patch-lexical.js +39 -0
|
@@ -3,6 +3,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
3
3
|
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; }
|
|
4
4
|
import { $isElementNode } from 'lexical';
|
|
5
5
|
export function $parseSerializedNodeImpl(serializedNode, editor) {
|
|
6
|
+
var keepId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
7
|
+
var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
6
8
|
var type = serializedNode.type;
|
|
7
9
|
var registeredNode = editor._nodes.get(type);
|
|
8
10
|
if (registeredNode === undefined) {
|
|
@@ -13,6 +15,10 @@ export function $parseSerializedNodeImpl(serializedNode, editor) {
|
|
|
13
15
|
throw new Error("LexicalNode: Node ".concat(nodeClass.name, " does not implement .importJSON()."));
|
|
14
16
|
}
|
|
15
17
|
var node = nodeClass.importJSON(serializedNode);
|
|
18
|
+
if (keepId && serializedNode.id) {
|
|
19
|
+
node.__key = serializedNode.id;
|
|
20
|
+
state === null || state === void 0 || state._nodeMap.set(node.__key, node);
|
|
21
|
+
}
|
|
16
22
|
var children = serializedNode.children;
|
|
17
23
|
if ($isElementNode(node) && Array.isArray(children)) {
|
|
18
24
|
var _iterator = _createForOfIteratorHelper(children),
|
|
@@ -20,7 +26,7 @@ export function $parseSerializedNodeImpl(serializedNode, editor) {
|
|
|
20
26
|
try {
|
|
21
27
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
22
28
|
var serializedJSONChildNode = _step.value;
|
|
23
|
-
var childNode = $parseSerializedNodeImpl(serializedJSONChildNode, editor);
|
|
29
|
+
var childNode = $parseSerializedNodeImpl(serializedJSONChildNode, editor, keepId, state);
|
|
24
30
|
node.append(childNode);
|
|
25
31
|
}
|
|
26
32
|
} catch (err) {
|
|
@@ -60,25 +60,6 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
60
60
|
key: "write",
|
|
61
61
|
value: function write(editor, options) {
|
|
62
62
|
var _this2 = this;
|
|
63
|
-
var processChild = function processChild(parentCtx, child) {
|
|
64
|
-
var writer = _this2.markdownService.markdownWriters[child.getType()];
|
|
65
|
-
var currentCtx = parentCtx;
|
|
66
|
-
if ($isElementNode(child)) {
|
|
67
|
-
currentCtx = currentCtx.newChild();
|
|
68
|
-
}
|
|
69
|
-
var skipChildren = false;
|
|
70
|
-
if (writer) {
|
|
71
|
-
skipChildren = writer(currentCtx, child);
|
|
72
|
-
}
|
|
73
|
-
if (skipChildren) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if ($isElementNode(child)) {
|
|
77
|
-
child.getChildren().forEach(function (child) {
|
|
78
|
-
return processChild(currentCtx, child);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
63
|
if (options !== null && options !== void 0 && options.selection) {
|
|
83
64
|
return editor.getEditorState().read(function () {
|
|
84
65
|
var selection = $getSelection();
|
|
@@ -193,10 +174,10 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
193
174
|
root: _rootNode
|
|
194
175
|
});
|
|
195
176
|
var _lexicalRootNode = _editorState._nodeMap.get('root');
|
|
196
|
-
var _rootCtx = new MarkdownWriterContext();
|
|
177
|
+
var _rootCtx = new MarkdownWriterContext(_this2.markdownService);
|
|
197
178
|
return _editorState.read(function () {
|
|
198
179
|
_lexicalRootNode.getChildren().forEach(function (child) {
|
|
199
|
-
return processChild(_rootCtx, child);
|
|
180
|
+
return _rootCtx.processChild(_rootCtx, child);
|
|
200
181
|
});
|
|
201
182
|
return _rootCtx.toString();
|
|
202
183
|
});
|
|
@@ -221,10 +202,10 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
221
202
|
root: rootNode
|
|
222
203
|
});
|
|
223
204
|
var lexicalRootNode = editorState._nodeMap.get('root');
|
|
224
|
-
var rootCtx = new MarkdownWriterContext();
|
|
205
|
+
var rootCtx = new MarkdownWriterContext(_this2.markdownService);
|
|
225
206
|
return editorState.read(function () {
|
|
226
207
|
lexicalRootNode.getChildren().forEach(function (child) {
|
|
227
|
-
return processChild(rootCtx, child);
|
|
208
|
+
return rootCtx.processChild(rootCtx, child);
|
|
228
209
|
});
|
|
229
210
|
return rootCtx.toString();
|
|
230
211
|
});
|
|
@@ -232,9 +213,9 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
232
213
|
}
|
|
233
214
|
return editor.getEditorState().read(function () {
|
|
234
215
|
var rootNode = $getRoot();
|
|
235
|
-
var rootCtx = new MarkdownWriterContext();
|
|
216
|
+
var rootCtx = new MarkdownWriterContext(_this2.markdownService);
|
|
236
217
|
rootNode.getChildren().forEach(function (child) {
|
|
237
|
-
return processChild(rootCtx, child);
|
|
218
|
+
return rootCtx.processChild(rootCtx, child);
|
|
238
219
|
});
|
|
239
220
|
return rootCtx.toString();
|
|
240
221
|
});
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LexicalNode } from 'lexical';
|
|
2
|
+
import { IMarkdownWriterContext, MarkdownShortCutService } from '../service/shortcut';
|
|
2
3
|
export declare class MarkdownWriterContext implements IMarkdownWriterContext {
|
|
3
4
|
private before;
|
|
4
5
|
private after;
|
|
5
6
|
private children;
|
|
7
|
+
private markdownService;
|
|
6
8
|
private processor?;
|
|
9
|
+
constructor(markdownService?: MarkdownShortCutService);
|
|
7
10
|
appendLine(line: string): void;
|
|
8
11
|
newChild(): MarkdownWriterContext;
|
|
9
12
|
wrap(before: string, after: string): void;
|
|
10
13
|
addProcessor(processor: (before: string, content: string, after: string) => string): void;
|
|
11
14
|
toString(): string;
|
|
15
|
+
processChild(parentCtx: IMarkdownWriterContext, child: LexicalNode): void;
|
|
12
16
|
}
|
|
@@ -5,13 +5,16 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
5
5
|
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; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
7
|
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); }
|
|
8
|
+
import { $isElementNode } from 'lexical';
|
|
8
9
|
export var MarkdownWriterContext = /*#__PURE__*/function () {
|
|
9
|
-
function MarkdownWriterContext() {
|
|
10
|
+
function MarkdownWriterContext(markdownService) {
|
|
10
11
|
_classCallCheck(this, MarkdownWriterContext);
|
|
11
12
|
_defineProperty(this, "before", '');
|
|
12
13
|
_defineProperty(this, "after", '');
|
|
13
14
|
_defineProperty(this, "children", []);
|
|
15
|
+
_defineProperty(this, "markdownService", void 0);
|
|
14
16
|
_defineProperty(this, "processor", void 0);
|
|
17
|
+
this.markdownService = markdownService;
|
|
15
18
|
}
|
|
16
19
|
_createClass(MarkdownWriterContext, [{
|
|
17
20
|
key: "appendLine",
|
|
@@ -21,7 +24,7 @@ export var MarkdownWriterContext = /*#__PURE__*/function () {
|
|
|
21
24
|
}, {
|
|
22
25
|
key: "newChild",
|
|
23
26
|
value: function newChild() {
|
|
24
|
-
var child = new MarkdownWriterContext();
|
|
27
|
+
var child = new MarkdownWriterContext(this.markdownService);
|
|
25
28
|
this.children.push(child);
|
|
26
29
|
return child;
|
|
27
30
|
}
|
|
@@ -46,6 +49,28 @@ export var MarkdownWriterContext = /*#__PURE__*/function () {
|
|
|
46
49
|
return child.toString();
|
|
47
50
|
}).join(''), this.after) : content;
|
|
48
51
|
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "processChild",
|
|
54
|
+
value: function processChild(parentCtx, child) {
|
|
55
|
+
var _this = this;
|
|
56
|
+
var writer = this.markdownService.markdownWriters[child.getType()];
|
|
57
|
+
var currentCtx = parentCtx;
|
|
58
|
+
if ($isElementNode(child)) {
|
|
59
|
+
currentCtx = currentCtx.newChild();
|
|
60
|
+
}
|
|
61
|
+
var skipChildren = false;
|
|
62
|
+
if (writer) {
|
|
63
|
+
skipChildren = writer(currentCtx, child);
|
|
64
|
+
}
|
|
65
|
+
if (skipChildren) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if ($isElementNode(child)) {
|
|
69
|
+
child.getChildren().forEach(function (child) {
|
|
70
|
+
return _this.processChild(currentCtx, child);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
49
74
|
}]);
|
|
50
75
|
return MarkdownWriterContext;
|
|
51
76
|
}();
|
|
@@ -15,6 +15,13 @@ export interface IMarkdownWriterContext {
|
|
|
15
15
|
* @returns
|
|
16
16
|
*/
|
|
17
17
|
appendLine: (line: string) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Control child node to markdown
|
|
20
|
+
* @param parentCtx
|
|
21
|
+
* @param child
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
processChild: (parentCtx: IMarkdownWriterContext, child: LexicalNode) => void;
|
|
18
25
|
/**
|
|
19
26
|
* Wrap child elements
|
|
20
27
|
* @param before
|
package/es/types/kernel.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export type IServiceID<Service> = {
|
|
|
19
19
|
__serviceType?: Service;
|
|
20
20
|
};
|
|
21
21
|
export interface IKernelEventMap {
|
|
22
|
+
/**
|
|
23
|
+
* Document change event
|
|
24
|
+
*/
|
|
25
|
+
documentChange: (type: string, content: any) => void;
|
|
22
26
|
/**
|
|
23
27
|
* Editor editable state change event
|
|
24
28
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/editor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"types": "es/index.d.ts",
|
|
26
26
|
"files": [
|
|
27
27
|
"es",
|
|
28
|
+
"scripts/patch-lexical.js",
|
|
28
29
|
"react.d.ts",
|
|
29
30
|
"react.js"
|
|
30
31
|
],
|
|
@@ -70,5 +71,10 @@
|
|
|
70
71
|
"react": "^19.0.0",
|
|
71
72
|
"react-dom": "^19.0.0"
|
|
72
73
|
},
|
|
73
|
-
"packageManager": "pnpm@10.20.0"
|
|
74
|
+
"packageManager": "pnpm@10.20.0",
|
|
75
|
+
"pnpm": {
|
|
76
|
+
"overrides": {
|
|
77
|
+
"chalk": "^4.1.2"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
74
80
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* eslint-disable unicorn/no-process-exit */
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
const sourceDir = path.resolve(__dirname, '../src/editor-kernel/lexical');
|
|
6
|
+
const esSourceDir = path.resolve(__dirname, '../es/editor-kernel/lexical');
|
|
7
|
+
const targetDir = path.resolve(__dirname, '../node_modules/lexical');
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync(targetDir)) {
|
|
10
|
+
console.warn('node_modules/lexical not found, skipping patch.');
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const realSourceDir = fs.existsSync(esSourceDir) ? esSourceDir : sourceDir;
|
|
15
|
+
|
|
16
|
+
if (!fs.existsSync(realSourceDir)) {
|
|
17
|
+
console.warn('No source directory found for lexical patch.');
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function copyToLexical(dir, target) {
|
|
22
|
+
const files = fs.readdirSync(dir);
|
|
23
|
+
|
|
24
|
+
files.forEach((file) => {
|
|
25
|
+
const sourceFile = path.join(dir, file);
|
|
26
|
+
const targetFile = path.join(target, file);
|
|
27
|
+
if (fs.statSync(sourceFile).isDirectory()) {
|
|
28
|
+
copyToLexical(sourceFile, targetFile);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (fs.existsSync(sourceFile)) {
|
|
33
|
+
fs.copyFileSync(sourceFile, targetFile);
|
|
34
|
+
console.log(`Overwrote ${file} in node_modules/lexical/`);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
copyToLexical(realSourceDir, targetDir);
|