@lobehub/editor 3.4.2 → 3.6.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/lexical/Lexical.dev.js +1 -1
- package/es/editor-kernel/lexical/Lexical.dev.mjs +7 -3
- package/es/editor-kernel/lexical/Lexical.js +2 -2
- package/es/editor-kernel/lexical/Lexical.mjs +2 -2
- package/es/editor-kernel/lexical/LexicalEditor.d.ts +1 -1
- package/es/editor-kernel/lexical/LexicalUpdates.d.ts +1 -1
- package/es/editor-kernel/lexical/LexicalUtils.d.ts +2 -2
- package/es/editor-kernel/lexical/nodes/LexicalTextNode.d.ts +1 -1
- package/es/plugins/codemirror-block/react/components/MoreOptions.js +2 -2
- package/es/plugins/common/plugin/index.js +154 -116
- package/es/plugins/common/react/ReactPlainText.js +2 -2
- package/es/plugins/common/react/style.d.ts +0 -2
- package/es/plugins/common/react/style.js +3 -5
- package/es/plugins/litexml/command/diffCommand.js +23 -0
- package/es/plugins/litexml/command/index.js +25 -6
- package/es/plugins/litexml/node/DiffNode.d.ts +1 -1
- package/es/plugins/litexml/react/style.js +1 -1
- package/es/plugins/litexml/utils/index.js +3 -4
- package/es/plugins/markdown/data-source/markdown-data-source.d.ts +1 -0
- package/es/plugins/markdown/data-source/markdown-data-source.js +24 -2
- package/es/plugins/mention/react/components/Mention.js +2 -1
- package/es/plugins/mention/react/style.js +1 -1
- package/es/plugins/table/react/index.js +1 -1
- package/es/react/ChatInputActions/components/CollapsedActions.js +1 -2
- package/es/react/Editor/Editor.js +13 -2
- package/es/react/Editor/type.d.ts +5 -0
- package/es/react/FloatActions/components/CollapsedActions.js +1 -2
- package/package.json +3 -3
|
@@ -2296,7 +2296,7 @@ if(this._pendingEditorState===null){rootElement.removeAttribute('autocapitalize'
|
|
|
2296
2296
|
* See {@link LexicalNode.exportJSON}
|
|
2297
2297
|
*
|
|
2298
2298
|
* @returns A JSON-serializable javascript object
|
|
2299
|
-
*/},{key:"toJSON",value:function toJSON(){return{editorState:this._editorState.toJSON()};}}]);return LexicalEditor;}();/** @internal */ /** The version with build identifiers for this editor (since 0.17.1) */_defineProperty(LexicalEditor,"version",void 0);LexicalEditor.version='0.39.0+dev.cjs';var pendingNodeToClone=null;function setPendingNodeToClone(pendingNode){pendingNodeToClone=pendingNode;}function getPendingNodeToClone(){var node=pendingNodeToClone;pendingNodeToClone=null;return node;}var keyCounter=1;function resetRandomKey(){keyCounter=1;}function generateRandomKey(){return''+keyCounter++;}/**
|
|
2299
|
+
*/},{key:"toJSON",value:function toJSON(){return{editorState:this._editorState.toJSON()};}}]);return LexicalEditor;}();/** @internal */ /** The version with build identifiers for this editor (since 0.17.1) */_defineProperty(LexicalEditor,"version",void 0);LexicalEditor.version='0.39.0+dev.cjs';var pendingNodeToClone=null;function setPendingNodeToClone(pendingNode){pendingNodeToClone=pendingNode;}function getPendingNodeToClone(){var node=pendingNodeToClone;pendingNodeToClone=null;return node;}var keyCounter=1;function resetRandomKey(targetId){if(targetId!==undefined){keyCounter=targetId;}else{keyCounter=1;}}function generateRandomKey(targetId){return''+keyCounter++;}/**
|
|
2300
2300
|
* @internal
|
|
2301
2301
|
*/function getRegisteredNodeOrThrow(editor,nodeType){var registeredNode=getRegisteredNode(editor,nodeType);if(registeredNode===undefined){{formatDevErrorMessage("registeredNode: Type ".concat(nodeType," not found"));}}return registeredNode;}/**
|
|
2302
2302
|
* @internal
|
|
@@ -11814,10 +11814,14 @@ function getPendingNodeToClone() {
|
|
|
11814
11814
|
return node;
|
|
11815
11815
|
}
|
|
11816
11816
|
let keyCounter = 1;
|
|
11817
|
-
function resetRandomKey() {
|
|
11818
|
-
|
|
11817
|
+
function resetRandomKey(targetId) {
|
|
11818
|
+
if (targetId !== undefined) {
|
|
11819
|
+
keyCounter = targetId;
|
|
11820
|
+
} else {
|
|
11821
|
+
keyCounter = 1;
|
|
11822
|
+
}
|
|
11819
11823
|
}
|
|
11820
|
-
function generateRandomKey() {
|
|
11824
|
+
function generateRandomKey(targetId) {
|
|
11821
11825
|
return '' + keyCounter++;
|
|
11822
11826
|
}
|
|
11823
11827
|
|
|
@@ -7621,8 +7621,8 @@ exports.$addUpdateTag = wi, exports.$applyNodeReplacement = Bi, exports.$caretFr
|
|
|
7621
7621
|
return M.test(t) ? 'rtl' : A.test(t) ? 'ltr' : null;
|
|
7622
7622
|
}, exports.getTransformSetFromKlass = Eo, exports.isBlockDomNode = qi, exports.isCurrentlyReadOnlyMode = $r, exports.isDOMDocumentNode = Uo, exports.isDOMNode = Hi, exports.isDOMTextNode = $o, exports.isDOMUnmanaged = os, exports.isDocumentFragment = Vi, exports.isExactShortcutMatch = pi, exports.isHTMLAnchorElement = function (t) {
|
|
7623
7623
|
return ji(t) && 'A' === t.tagName;
|
|
7624
|
-
}, exports.isHTMLElement = ji, exports.isInlineDomNode = Gi, exports.isLexicalEditor = Ro, exports.isModifierMatch = _i, exports.isSelectionCapturedInDecoratorInput = Lo, exports.isSelectionWithinEditor = Fo, exports.makeStepwiseIterator = Is, exports.removeFromParent = Ho, exports.resetRandomKey = function () {
|
|
7625
|
-
Ao = 1;
|
|
7624
|
+
}, exports.isHTMLElement = ji, exports.isInlineDomNode = Gi, exports.isLexicalEditor = Ro, exports.isModifierMatch = _i, exports.isSelectionCapturedInDecoratorInput = Lo, exports.isSelectionWithinEditor = Fo, exports.makeStepwiseIterator = Is, exports.removeFromParent = Ho, exports.resetRandomKey = function (t) {
|
|
7625
|
+
Ao = void 0 !== t ? t : 1;
|
|
7626
7626
|
}, exports.safeCast = function (t) {
|
|
7627
7627
|
return t;
|
|
7628
7628
|
}, exports.setDOMUnmanaged = function (t) {
|
|
@@ -615,7 +615,7 @@ export declare class LexicalEditor {
|
|
|
615
615
|
*/
|
|
616
616
|
parseEditorState(
|
|
617
617
|
maybeStringifiedEditorState: string | SerializedEditorState,
|
|
618
|
-
updateFn?: (
|
|
618
|
+
updateFn?: (state: EditorState) => void,
|
|
619
619
|
): EditorState;
|
|
620
620
|
/**
|
|
621
621
|
* Executes a read of the editor's state, with the
|
|
@@ -33,7 +33,7 @@ export declare function $parseSerializedNode(serializedNode: SerializedLexicalNo
|
|
|
33
33
|
export declare function parseEditorState(
|
|
34
34
|
serializedEditorState: SerializedEditorState,
|
|
35
35
|
editor: LexicalEditor,
|
|
36
|
-
updateFn: void | ((
|
|
36
|
+
updateFn: void | ((state: EditorState) => void),
|
|
37
37
|
): EditorState;
|
|
38
38
|
export declare function readEditorState<V>(
|
|
39
39
|
editor: LexicalEditor | null,
|
|
@@ -28,8 +28,8 @@ import { type TextFormatType, TextNode } from './nodes/LexicalTextNode';
|
|
|
28
28
|
export declare const emptyFunction: () => void;
|
|
29
29
|
export declare function setPendingNodeToClone(pendingNode: null | LexicalNode): void;
|
|
30
30
|
export declare function getPendingNodeToClone(): null | LexicalNode;
|
|
31
|
-
export declare function resetRandomKey(): void;
|
|
32
|
-
export declare function generateRandomKey(): string;
|
|
31
|
+
export declare function resetRandomKey(targetId?: number): void;
|
|
32
|
+
export declare function generateRandomKey(targetId?: number): string;
|
|
33
33
|
/**
|
|
34
34
|
* @internal
|
|
35
35
|
*/
|
|
@@ -306,6 +306,6 @@ export declare class TextNode extends LexicalNode {
|
|
|
306
306
|
*/
|
|
307
307
|
isTextEntity(): boolean;
|
|
308
308
|
}
|
|
309
|
-
export declare function findParentPreDOMNode(node: Node):
|
|
309
|
+
export declare function findParentPreDOMNode(node: Node): any;
|
|
310
310
|
export declare function $createTextNode(text?: string): TextNode;
|
|
311
311
|
export declare function $isTextNode(node: LexicalNode | null | undefined): node is TextNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { ActionIcon, Flexbox, InputNumber, Text } from '@lobehub/ui';
|
|
4
|
-
import {
|
|
3
|
+
import { ActionIcon, Flexbox, InputNumber, Popover, Text } from '@lobehub/ui';
|
|
4
|
+
import { Switch } from 'antd';
|
|
5
5
|
import { MoreHorizontalIcon } from 'lucide-react';
|
|
6
6
|
import { useCallback } from 'react';
|
|
7
7
|
import { useTranslation } from "../../../../editor-kernel/react/useTranslation";
|
|
@@ -45,13 +45,46 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
45
45
|
_inherits(CommonPlugin, _KernelPlugin);
|
|
46
46
|
var _super = _createSuper(CommonPlugin);
|
|
47
47
|
function CommonPlugin(kernel) {
|
|
48
|
+
var _config$markdownOptio;
|
|
48
49
|
var _this;
|
|
49
50
|
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
50
51
|
_classCallCheck(this, CommonPlugin);
|
|
51
52
|
_this = _super.call(this);
|
|
52
|
-
|
|
53
|
+
|
|
54
|
+
// Parse markdown options and update formats
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "formats", {
|
|
56
|
+
bold: true,
|
|
57
|
+
header: true,
|
|
58
|
+
italic: true,
|
|
59
|
+
quote: true,
|
|
60
|
+
strikethrough: true,
|
|
61
|
+
subscript: false,
|
|
62
|
+
superscript: false
|
|
63
|
+
});
|
|
53
64
|
_this.kernel = kernel;
|
|
54
65
|
_this.config = config;
|
|
66
|
+
var markdownOption = (_config$markdownOptio = config.markdownOption) !== null && _config$markdownOptio !== void 0 ? _config$markdownOptio : true;
|
|
67
|
+
if (_typeof(markdownOption) === 'object') {
|
|
68
|
+
var _markdownOption$bold, _markdownOption$heade, _markdownOption$itali, _markdownOption$quote, _markdownOption$strik, _markdownOption$subsc, _markdownOption$super;
|
|
69
|
+
_this.formats.bold = (_markdownOption$bold = markdownOption.bold) !== null && _markdownOption$bold !== void 0 ? _markdownOption$bold : true;
|
|
70
|
+
_this.formats.header = (_markdownOption$heade = markdownOption.header) !== null && _markdownOption$heade !== void 0 ? _markdownOption$heade : true;
|
|
71
|
+
_this.formats.italic = (_markdownOption$itali = markdownOption.italic) !== null && _markdownOption$itali !== void 0 ? _markdownOption$itali : true;
|
|
72
|
+
_this.formats.quote = (_markdownOption$quote = markdownOption.quote) !== null && _markdownOption$quote !== void 0 ? _markdownOption$quote : true;
|
|
73
|
+
_this.formats.strikethrough = (_markdownOption$strik = markdownOption.strikethrough) !== null && _markdownOption$strik !== void 0 ? _markdownOption$strik : true;
|
|
74
|
+
_this.formats.subscript = (_markdownOption$subsc = markdownOption.subscript) !== null && _markdownOption$subsc !== void 0 ? _markdownOption$subsc : false;
|
|
75
|
+
_this.formats.superscript = (_markdownOption$super = markdownOption.superscript) !== null && _markdownOption$super !== void 0 ? _markdownOption$super : false;
|
|
76
|
+
} else if (markdownOption === false) {
|
|
77
|
+
// Disable all formats if markdown is disabled
|
|
78
|
+
_this.formats.bold = false;
|
|
79
|
+
_this.formats.header = false;
|
|
80
|
+
_this.formats.italic = false;
|
|
81
|
+
_this.formats.quote = false;
|
|
82
|
+
_this.formats.strikethrough = false;
|
|
83
|
+
_this.formats.subscript = false;
|
|
84
|
+
_this.formats.superscript = false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Register the JSON data source
|
|
55
88
|
kernel.registerDataSource(new JSONDataSource('json'));
|
|
56
89
|
// Register the text data source
|
|
57
90
|
kernel.registerDataSource(new TextDataSource('text'));
|
|
@@ -88,29 +121,7 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
88
121
|
var markdownOption = (_this$config$markdown = (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.markdownOption) !== null && _this$config$markdown !== void 0 ? _this$config$markdown : true;
|
|
89
122
|
var isMarkdownEnabled = markdownOption !== false;
|
|
90
123
|
var breakMark = isMarkdownEnabled ? '\n\n' : '\n';
|
|
91
|
-
|
|
92
|
-
// Determine which formats are enabled
|
|
93
|
-
var formats = {
|
|
94
|
-
bold: true,
|
|
95
|
-
header: true,
|
|
96
|
-
italic: true,
|
|
97
|
-
quote: true,
|
|
98
|
-
strikethrough: true,
|
|
99
|
-
subscript: false,
|
|
100
|
-
// Disabled by default
|
|
101
|
-
superscript: false // Disabled by default
|
|
102
|
-
// Note: code, underline, underlineStrikethrough are handled by other plugins/writers
|
|
103
|
-
};
|
|
104
|
-
if (_typeof(markdownOption) === 'object') {
|
|
105
|
-
var _markdownOption$bold, _markdownOption$heade, _markdownOption$itali, _markdownOption$quote, _markdownOption$strik, _markdownOption$subsc, _markdownOption$super;
|
|
106
|
-
formats.bold = (_markdownOption$bold = markdownOption.bold) !== null && _markdownOption$bold !== void 0 ? _markdownOption$bold : true;
|
|
107
|
-
formats.header = (_markdownOption$heade = markdownOption.header) !== null && _markdownOption$heade !== void 0 ? _markdownOption$heade : true;
|
|
108
|
-
formats.italic = (_markdownOption$itali = markdownOption.italic) !== null && _markdownOption$itali !== void 0 ? _markdownOption$itali : true;
|
|
109
|
-
formats.quote = (_markdownOption$quote = markdownOption.quote) !== null && _markdownOption$quote !== void 0 ? _markdownOption$quote : true;
|
|
110
|
-
formats.strikethrough = (_markdownOption$strik = markdownOption.strikethrough) !== null && _markdownOption$strik !== void 0 ? _markdownOption$strik : true;
|
|
111
|
-
formats.subscript = (_markdownOption$subsc = markdownOption.subscript) !== null && _markdownOption$subsc !== void 0 ? _markdownOption$subsc : false;
|
|
112
|
-
formats.superscript = (_markdownOption$super = markdownOption.superscript) !== null && _markdownOption$super !== void 0 ? _markdownOption$super : false;
|
|
113
|
-
}
|
|
124
|
+
var formats = this.formats;
|
|
114
125
|
|
|
115
126
|
// Register quote shortcut if enabled
|
|
116
127
|
if (formats.quote) {
|
|
@@ -202,64 +213,74 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
202
213
|
markdownService.registerMarkdownShortCuts(textFormatShortcuts);
|
|
203
214
|
}
|
|
204
215
|
markdownService.registerMarkdownWriter('paragraph', function (ctx) {
|
|
205
|
-
ctx.wrap('',
|
|
206
|
-
});
|
|
207
|
-
markdownService.registerMarkdownWriter('quote', function (ctx, node) {
|
|
208
|
-
if ($isQuoteNode(node)) {
|
|
209
|
-
ctx.wrap('> ', breakMark);
|
|
210
|
-
}
|
|
216
|
+
ctx.wrap('', breakMark);
|
|
211
217
|
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
case 'h2':
|
|
221
|
-
{
|
|
222
|
-
ctx.wrap('## ', breakMark);
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
case 'h3':
|
|
226
|
-
{
|
|
227
|
-
ctx.wrap('### ', breakMark);
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
case 'h4':
|
|
231
|
-
{
|
|
232
|
-
ctx.wrap('#### ', breakMark);
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
case 'h5':
|
|
236
|
-
{
|
|
237
|
-
ctx.wrap('##### ', breakMark);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case 'h6':
|
|
241
|
-
{
|
|
242
|
-
ctx.wrap('###### ', breakMark);
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
default:
|
|
246
|
-
{
|
|
247
|
-
ctx.wrap('', '\n');
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
218
|
+
|
|
219
|
+
// Register quote writer only if quote format is enabled
|
|
220
|
+
if (formats.quote) {
|
|
221
|
+
markdownService.registerMarkdownWriter('quote', function (ctx, node) {
|
|
222
|
+
if ($isQuoteNode(node)) {
|
|
223
|
+
ctx.wrap('> ', breakMark);
|
|
250
224
|
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Register heading writer only if header format is enabled
|
|
229
|
+
if (formats.header) {
|
|
230
|
+
markdownService.registerMarkdownWriter('heading', function (ctx, node) {
|
|
231
|
+
if ($isHeadingNode(node)) {
|
|
232
|
+
switch (node.getTag()) {
|
|
233
|
+
case 'h1':
|
|
234
|
+
{
|
|
235
|
+
ctx.wrap('# ', '\n\n');
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
case 'h2':
|
|
239
|
+
{
|
|
240
|
+
ctx.wrap('## ', '\n\n');
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case 'h3':
|
|
244
|
+
{
|
|
245
|
+
ctx.wrap('### ', '\n\n');
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
case 'h4':
|
|
249
|
+
{
|
|
250
|
+
ctx.wrap('#### ', '\n\n');
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
case 'h5':
|
|
254
|
+
{
|
|
255
|
+
ctx.wrap('##### ', '\n\n');
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case 'h6':
|
|
259
|
+
{
|
|
260
|
+
ctx.wrap('###### ', '\n\n');
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
default:
|
|
264
|
+
{
|
|
265
|
+
ctx.wrap('', '\n\n');
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Register text writer with conditional format handling
|
|
253
274
|
markdownService.registerMarkdownWriter('text', function (ctx, node) {
|
|
254
275
|
if (!$isTextNode(node)) {
|
|
255
276
|
return;
|
|
256
277
|
}
|
|
257
|
-
var isBold = node.hasFormat('bold');
|
|
258
|
-
var isItalic = node.hasFormat('italic');
|
|
278
|
+
var isBold = formats.bold && node.hasFormat('bold');
|
|
279
|
+
var isItalic = formats.italic && node.hasFormat('italic');
|
|
259
280
|
var isUnderline = node.hasFormat('underline');
|
|
260
|
-
var isStrikethrough = node.hasFormat('strikethrough');
|
|
261
|
-
var isSuperscript = node.hasFormat('superscript');
|
|
262
|
-
var isSubscript = node.hasFormat('subscript');
|
|
281
|
+
var isStrikethrough = formats.strikethrough && node.hasFormat('strikethrough');
|
|
282
|
+
var isSuperscript = formats.superscript && node.hasFormat('superscript');
|
|
283
|
+
var isSubscript = formats.subscript && node.hasFormat('subscript');
|
|
263
284
|
if (isBold) {
|
|
264
285
|
ctx.appendLine('**');
|
|
265
286
|
}
|
|
@@ -315,7 +336,7 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
315
336
|
// Register markdown writer for linebreak nodes (soft line breaks)
|
|
316
337
|
markdownService.registerMarkdownWriter('linebreak', function (ctx) {
|
|
317
338
|
// In markdown, soft line breaks are represented as two spaces followed by a newline
|
|
318
|
-
ctx.appendLine('
|
|
339
|
+
ctx.appendLine('\n');
|
|
319
340
|
});
|
|
320
341
|
|
|
321
342
|
// 注册 markdown reader
|
|
@@ -383,35 +404,44 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
383
404
|
if (!litexmlService) {
|
|
384
405
|
return;
|
|
385
406
|
}
|
|
407
|
+
var formats = this.formats;
|
|
386
408
|
litexmlService.registerXMLWriter(TextNode.getType(), function (node, ctx) {
|
|
387
409
|
var attr = {};
|
|
388
410
|
if ($isTextNode(node)) {
|
|
389
|
-
if (node.hasFormat('bold')) {
|
|
411
|
+
if (formats.bold && node.hasFormat('bold')) {
|
|
390
412
|
attr['bold'] = 'true';
|
|
391
413
|
}
|
|
392
|
-
if (node.hasFormat('italic')) {
|
|
414
|
+
if (formats.italic && node.hasFormat('italic')) {
|
|
393
415
|
attr['italic'] = 'true';
|
|
394
416
|
}
|
|
395
417
|
if (node.hasFormat('underline')) {
|
|
396
418
|
attr['underline'] = 'true';
|
|
397
419
|
}
|
|
398
|
-
if (node.hasFormat('strikethrough')) {
|
|
420
|
+
if (formats.strikethrough && node.hasFormat('strikethrough')) {
|
|
399
421
|
attr['strikethrough'] = 'true';
|
|
400
422
|
}
|
|
401
|
-
if (node.hasFormat('subscript')) {
|
|
423
|
+
if (formats.subscript && node.hasFormat('subscript')) {
|
|
402
424
|
attr['subscript'] = 'true';
|
|
403
425
|
}
|
|
404
|
-
if (node.hasFormat('superscript')) {
|
|
426
|
+
if (formats.superscript && node.hasFormat('superscript')) {
|
|
405
427
|
attr['superscript'] = 'true';
|
|
406
428
|
}
|
|
407
429
|
return ctx.createXmlNode('span', attr, node.getTextContent());
|
|
408
430
|
}
|
|
409
431
|
return false;
|
|
410
432
|
});
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
433
|
+
|
|
434
|
+
// Register bold readers only if bold format is enabled
|
|
435
|
+
if (formats.bold) {
|
|
436
|
+
litexmlService.registerXMLReader('b', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['bold']));
|
|
437
|
+
litexmlService.registerXMLReader('strong', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['bold']));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Register italic readers only if italic format is enabled
|
|
441
|
+
if (formats.italic) {
|
|
442
|
+
litexmlService.registerXMLReader('i', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['italic']));
|
|
443
|
+
litexmlService.registerXMLReader('emphasis', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['italic']));
|
|
444
|
+
}
|
|
415
445
|
litexmlService.registerXMLReader('u', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['underline']));
|
|
416
446
|
litexmlService.registerXMLReader('ins', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['underline']));
|
|
417
447
|
litexmlService.registerXMLReader('span', function (xmlElement, children) {
|
|
@@ -422,22 +452,22 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
422
452
|
var subscript = xmlElement.getAttribute('subscript');
|
|
423
453
|
var superscript = xmlElement.getAttribute('superscript');
|
|
424
454
|
var format = 0;
|
|
425
|
-
if (bold === 'true') {
|
|
455
|
+
if (formats.bold && bold === 'true') {
|
|
426
456
|
format |= TEXT_TYPE_TO_FORMAT['bold'];
|
|
427
457
|
}
|
|
428
|
-
if (italic === 'true') {
|
|
458
|
+
if (formats.italic && italic === 'true') {
|
|
429
459
|
format |= TEXT_TYPE_TO_FORMAT['italic'];
|
|
430
460
|
}
|
|
431
461
|
if (underline === 'true') {
|
|
432
462
|
format |= TEXT_TYPE_TO_FORMAT['underline'];
|
|
433
463
|
}
|
|
434
|
-
if (strikethrough === 'true') {
|
|
464
|
+
if (formats.strikethrough && strikethrough === 'true') {
|
|
435
465
|
format |= TEXT_TYPE_TO_FORMAT['strikethrough'];
|
|
436
466
|
}
|
|
437
|
-
if (subscript === 'true') {
|
|
467
|
+
if (formats.subscript && subscript === 'true') {
|
|
438
468
|
format |= TEXT_TYPE_TO_FORMAT['subscript'];
|
|
439
469
|
}
|
|
440
|
-
if (superscript === 'true') {
|
|
470
|
+
if (formats.superscript && superscript === 'true') {
|
|
441
471
|
format |= TEXT_TYPE_TO_FORMAT['superscript'];
|
|
442
472
|
}
|
|
443
473
|
children.forEach(function (child) {
|
|
@@ -447,40 +477,48 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
447
477
|
});
|
|
448
478
|
return children;
|
|
449
479
|
});
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
480
|
+
|
|
481
|
+
// Register quote writer/reader only if quote format is enabled
|
|
482
|
+
if (formats.quote) {
|
|
483
|
+
litexmlService.registerXMLWriter('quote', function (node, ctx) {
|
|
484
|
+
if ($isQuoteNode(node)) {
|
|
485
|
+
return ctx.createXmlNode('quote', {});
|
|
486
|
+
}
|
|
487
|
+
return false;
|
|
488
|
+
});
|
|
489
|
+
litexmlService.registerXMLReader('quote', function (xmlElement, children) {
|
|
490
|
+
return INodeHelper.createElementNode(QuoteNode.getType(), {
|
|
491
|
+
children: children
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Register heading writer/reader only if header format is enabled
|
|
497
|
+
if (formats.header) {
|
|
498
|
+
litexmlService.registerXMLWriter('heading', function (node, ctx) {
|
|
499
|
+
if ($isHeadingNode(node)) {
|
|
500
|
+
return ctx.createXmlNode(node.getTag(), {});
|
|
501
|
+
}
|
|
502
|
+
return false;
|
|
503
|
+
});
|
|
504
|
+
var headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
|
|
505
|
+
headingTags.forEach(function (tag) {
|
|
506
|
+
litexmlService.registerXMLReader(tag, function (xmlElement, children) {
|
|
507
|
+
return INodeHelper.createElementNode(HeadingNode.getType(), {
|
|
508
|
+
children: children,
|
|
509
|
+
tag: tag
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
});
|
|
513
|
+
}
|
|
462
514
|
litexmlService.registerXMLWriter(ParagraphNode.getType(), function (node, ctx) {
|
|
463
515
|
return ctx.createXmlNode('p', {});
|
|
464
516
|
});
|
|
465
|
-
litexmlService.registerXMLReader('quote', function (xmlElement, children) {
|
|
466
|
-
return INodeHelper.createElementNode(QuoteNode.getType(), {
|
|
467
|
-
children: children
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
517
|
litexmlService.registerXMLReader('p', function (xmlElement, children) {
|
|
471
518
|
return INodeHelper.createElementNode(ParagraphNode.getType(), {
|
|
472
519
|
children: children
|
|
473
520
|
});
|
|
474
521
|
});
|
|
475
|
-
var headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
|
|
476
|
-
headingTags.forEach(function (tag) {
|
|
477
|
-
litexmlService.registerXMLReader(tag, function (xmlElement, children) {
|
|
478
|
-
return INodeHelper.createElementNode(HeadingNode.getType(), {
|
|
479
|
-
children: children,
|
|
480
|
-
tag: tag
|
|
481
|
-
});
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
522
|
}
|
|
485
523
|
}, {
|
|
486
524
|
key: "destroy",
|
|
@@ -59,7 +59,7 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
59
59
|
_theme$headerMultiple = theme.headerMultiple,
|
|
60
60
|
headerMultiple = _theme$headerMultiple === void 0 ? isChat ? 0.25 : 0.6 : _theme$headerMultiple,
|
|
61
61
|
_theme$lineHeight = theme.lineHeight,
|
|
62
|
-
lineHeight = _theme$lineHeight === void 0 ? isChat ? 1.
|
|
62
|
+
lineHeight = _theme$lineHeight === void 0 ? isChat ? 1.4 : 1.6 : _theme$lineHeight,
|
|
63
63
|
_theme$marginMultiple = theme.marginMultiple,
|
|
64
64
|
marginMultiple = _theme$marginMultiple === void 0 ? isChat ? 1 : 2 : _theme$marginMultiple,
|
|
65
65
|
restTheme = _objectWithoutProperties(theme, _excluded);
|
|
@@ -220,7 +220,7 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
220
220
|
});
|
|
221
221
|
};
|
|
222
222
|
return /*#__PURE__*/_jsxs("div", {
|
|
223
|
-
className: cx(styles.root,
|
|
223
|
+
className: cx(styles.root, styles.variant, className),
|
|
224
224
|
style: _objectSpread(_objectSpread({}, cssVariables), style),
|
|
225
225
|
children: [/*#__PURE__*/_jsx("div", {
|
|
226
226
|
className: styles.editorContent,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17
|
|
1
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
|
|
2
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
-
import { createStaticStyles,
|
|
3
|
+
import { createStaticStyles, cx, keyframes } from 'antd-style';
|
|
4
4
|
var cursorBlink = keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n to {\n visibility: hidden;\n }\n"])));
|
|
5
5
|
export var themeStyles = createStaticStyles(function (_ref) {
|
|
6
6
|
var css = _ref.css,
|
|
@@ -23,7 +23,7 @@ export var themeStyles = createStaticStyles(function (_ref) {
|
|
|
23
23
|
export var styles = createStaticStyles(function (_ref2) {
|
|
24
24
|
var css = _ref2.css,
|
|
25
25
|
cssVar = _ref2.cssVar;
|
|
26
|
-
var __root = css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: var(--common-font-size, 16px);\n --lobe-markdown-header-multiple: var(--common-header-multiple, 1);\n --lobe-markdown-margin-multiple: var(--common-margin-multiple, 2);\n --lobe-markdown-line-height: var(--common-line-height, 1.
|
|
26
|
+
var __root = css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: var(--common-font-size, 16px);\n --lobe-markdown-header-multiple: var(--common-header-multiple, 1);\n --lobe-markdown-margin-multiple: var(--common-margin-multiple, 2);\n --lobe-markdown-line-height: var(--common-line-height, 1.6);\n --lobe-markdown-border-radius: ", ";\n --lobe-markdown-border-color: ", ";\n\n position: relative;\n\n display: flex;\n flex-direction: column;\n\n width: 100%;\n max-width: 100%;\n height: 100%;\n\n font-size: var(--lobe-markdown-font-size);\n line-height: var(--lobe-markdown-line-height);\n word-break: break-word;\n\n [data-placeholder] {\n position: relative;\n }\n\n [data-placeholder]::after {\n pointer-events: none;\n content: attr(data-placeholder);\n user-select: none;\n\n position: absolute;\n inset-block-start: 50%;\n transform: translateY(-50%);\n\n padding-inline-start: 2px;\n\n color: ", ";\n white-space: nowrap;\n }\n\n [data-lexical-cursor='true'] {\n pointer-events: none;\n position: absolute;\n display: block;\n\n &::after {\n content: '';\n\n position: absolute;\n inset-block-start: -2px;\n\n display: block;\n\n width: 20px;\n border-block-start: 1px solid ", ";\n\n animation: ", " 1.1s steps(2, start) infinite;\n }\n }\n "])), cssVar.borderRadiusLG, cssVar.colorFillQuaternary, cssVar.colorTextDescription, cssVar.colorText, cursorBlink);
|
|
27
27
|
var header = css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n margin-block: max(\n calc(var(--lobe-markdown-header-multiple) * var(--lobe-markdown-margin-multiple) * 0.4em),\n var(--lobe-markdown-font-size)\n );\n font-weight: bold;\n line-height: 1.25;\n }\n\n h1 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 1.5 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h2 {\n font-size: calc(var(--lobe-markdown-font-size) * (1 + var(--lobe-markdown-header-multiple)));\n }\n\n h3 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 0.5 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h4 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 0.25 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h5,\n h6 {\n font-size: calc(var(--lobe-markdown-font-size) * 1);\n }\n "])));
|
|
28
28
|
var p = css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n p {\n margin-block: 4px;\n line-height: var(--lobe-markdown-line-height);\n letter-spacing: 0.02em;\n\n &:not(:first-child) {\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n\n &:not(:last-child) {\n margin-block-end: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n }\n "])));
|
|
29
29
|
var blockquote = css(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n .editor_quote {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n margin-inline: 0;\n padding-block: 0;\n padding-inline: 1em;\n border-inline-start: solid 4px ", ";\n\n color: ", ";\n }\n "])), cssVar.colorBorder, cssVar.colorTextSecondary);
|
|
@@ -34,8 +34,6 @@ export var styles = createStaticStyles(function (_ref2) {
|
|
|
34
34
|
code: code,
|
|
35
35
|
editorContent: editorContent,
|
|
36
36
|
header: header,
|
|
37
|
-
noHeader: css(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n margin-block: 0;\n font-size: var(--lobe-markdown-font-size);\n font-weight: normal;\n line-height: var(--lobe-markdown-line-height);\n }\n "]))),
|
|
38
|
-
noStyle: css(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["\n --lobe-markdown-header-multiple: 0;\n --lobe-markdown-margin-multiple: 0;\n --lobe-markdown-line-height: 1.5;\n\n p {\n margin-block: 4px;\n }\n "]))),
|
|
39
37
|
p: p,
|
|
40
38
|
root: __root,
|
|
41
39
|
variant: cx(header, p, blockquote, code)
|
|
@@ -61,6 +61,29 @@ function doAction(node, action) {
|
|
|
61
61
|
_parent.selectEnd();
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
if (node.diffType === 'listItemRemove') {
|
|
65
|
+
if (action === DiffAction.Accept) {
|
|
66
|
+
node.getParentOrThrow().remove();
|
|
67
|
+
} else if (action === DiffAction.Reject) {
|
|
68
|
+
node.getChildren().forEach(function (child) {
|
|
69
|
+
node.getParentOrThrow().append(child);
|
|
70
|
+
});
|
|
71
|
+
node.getParentOrThrow().selectEnd();
|
|
72
|
+
node.remove();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (node.diffType === 'listItemAdd') {
|
|
76
|
+
if (action === DiffAction.Accept) {
|
|
77
|
+
var _children4 = node.getChildren();
|
|
78
|
+
_children4.forEach(function (child) {
|
|
79
|
+
node.getParentOrThrow().append(child);
|
|
80
|
+
});
|
|
81
|
+
node.getParentOrThrow().selectEnd();
|
|
82
|
+
node.remove();
|
|
83
|
+
} else if (action === DiffAction.Reject) {
|
|
84
|
+
node.remove();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
64
87
|
}
|
|
65
88
|
export function registerLiteXMLDiffCommand(editor) {
|
|
66
89
|
return mergeRegister(editor.registerCommand(LITEXML_DIFFNODE_COMMAND, function (payload) {
|
|
@@ -14,6 +14,7 @@ import { $closest } from "../../../editor-kernel";
|
|
|
14
14
|
import { createDebugLogger } from "../../../utils/debug";
|
|
15
15
|
import { $createDiffNode, DiffNode } from "../node/DiffNode";
|
|
16
16
|
import { $cloneNode, $parseSerializedNodeImpl, charToId } from "../utils";
|
|
17
|
+
import { $isListItemNode } from '@lexical/list';
|
|
17
18
|
var logger = createDebugLogger('plugin', 'litexml');
|
|
18
19
|
|
|
19
20
|
// Helpers to reduce duplication and improve readability
|
|
@@ -302,9 +303,18 @@ function handleRemove(editor, key, delay) {
|
|
|
302
303
|
}
|
|
303
304
|
return;
|
|
304
305
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
if ($isListItemNode(node)) {
|
|
307
|
+
var diffNode = $createDiffNode('listItemRemove');
|
|
308
|
+
node.getChildren().forEach(function (child) {
|
|
309
|
+
diffNode.append($cloneNode(child, editor));
|
|
310
|
+
});
|
|
311
|
+
node.clear();
|
|
312
|
+
node.append(diffNode);
|
|
313
|
+
} else {
|
|
314
|
+
var _diffNode2 = $createDiffNode('remove');
|
|
315
|
+
_diffNode2.append($cloneNode(node, editor));
|
|
316
|
+
node.replace(_diffNode2, false);
|
|
317
|
+
}
|
|
308
318
|
} else {
|
|
309
319
|
var oldBlock = $closest(node, function (node) {
|
|
310
320
|
return node.isInline() === false;
|
|
@@ -414,9 +424,18 @@ function handleInsert(editor, payload, dataSource) {
|
|
|
414
424
|
}
|
|
415
425
|
newNodes.forEach(function (node) {
|
|
416
426
|
if (referenceNode) {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
427
|
+
if ($isListItemNode(node)) {
|
|
428
|
+
var diffNode = $createDiffNode('listItemAdd');
|
|
429
|
+
node.getChildren().forEach(function (child) {
|
|
430
|
+
diffNode.append(child);
|
|
431
|
+
});
|
|
432
|
+
node.append(diffNode);
|
|
433
|
+
referenceNode = referenceNode.insertAfter(node);
|
|
434
|
+
} else {
|
|
435
|
+
var _diffNode3 = $createDiffNode('add');
|
|
436
|
+
_diffNode3.append(node);
|
|
437
|
+
referenceNode = referenceNode.insertAfter(_diffNode3);
|
|
438
|
+
}
|
|
420
439
|
}
|
|
421
440
|
});
|
|
422
441
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
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
|
+
export type DiffType = 'add' | 'remove' | 'modify' | 'unchanged' | 'listItemModify' | 'listItemRemove' | 'listItemAdd';
|
|
4
4
|
export type SerializedDiffNode = Spread<{
|
|
5
5
|
diffType: DiffType;
|
|
6
6
|
}, SerializedElementNode>;
|
|
@@ -4,5 +4,5 @@ import { createStaticStyles } from 'antd-style';
|
|
|
4
4
|
export var styles = createStaticStyles(function (_ref) {
|
|
5
5
|
var css = _ref.css,
|
|
6
6
|
cssVar = _ref.cssVar;
|
|
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 "])), cssVar.colorSuccess, cssVar.colorError, cssVar.colorTextQuaternary, cssVar.colorWarning, cssVar.colorTextQuaternary, cssVar.colorWarning, cssVar.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\n &[data-diff-type='listItemRemove'] {\n display: inline-block;\n }\n\n &[data-diff-type='listItemRemove'] .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='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 "])), cssVar.colorSuccess, cssVar.colorError, cssVar.colorTextQuaternary, cssVar.colorError, cssVar.colorTextQuaternary, cssVar.colorWarning, cssVar.colorTextQuaternary, cssVar.colorWarning, cssVar.colorTextQuaternary);
|
|
8
8
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
2
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
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
|
-
import { $isElementNode } from 'lexical';
|
|
4
|
+
import { $isElementNode, resetRandomKey } from 'lexical';
|
|
5
5
|
export function $parseSerializedNodeImpl(serializedNode, editor) {
|
|
6
6
|
var keepId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
7
7
|
var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
@@ -14,11 +14,10 @@ export function $parseSerializedNodeImpl(serializedNode, editor) {
|
|
|
14
14
|
if (serializedNode.type !== nodeClass.getType()) {
|
|
15
15
|
throw new Error("LexicalNode: Node ".concat(nodeClass.name, " does not implement .importJSON()."));
|
|
16
16
|
}
|
|
17
|
-
var node = nodeClass.importJSON(serializedNode);
|
|
18
17
|
if (keepId && serializedNode.id) {
|
|
19
|
-
|
|
20
|
-
state === null || state === void 0 || state._nodeMap.set(node.__key, node);
|
|
18
|
+
resetRandomKey(Number(serializedNode.id));
|
|
21
19
|
}
|
|
20
|
+
var node = nodeClass.importJSON(serializedNode);
|
|
22
21
|
var children = serializedNode.children;
|
|
23
22
|
if ($isElementNode(node) && Array.isArray(children)) {
|
|
24
23
|
var childNodes = [];
|
|
@@ -7,6 +7,7 @@ export default class MarkdownDataSource extends DataSource {
|
|
|
7
7
|
protected dataType: string;
|
|
8
8
|
protected markdownService: MarkdownShortCutService;
|
|
9
9
|
protected getService?: (<T>(serviceId: IServiceID<T>) => T | null) | undefined;
|
|
10
|
+
private formatMarkdown;
|
|
10
11
|
constructor(dataType: string, markdownService: MarkdownShortCutService, getService?: (<T>(serviceId: IServiceID<T>) => T | null) | undefined);
|
|
11
12
|
read(editor: LexicalEditor, data: string): void;
|
|
12
13
|
write(editor: LexicalEditor, options?: IWriteOptions): any;
|
|
@@ -27,6 +27,8 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
27
27
|
/* eslint-disable unicorn/no-for-loop */
|
|
28
28
|
import { $isTableSelection } from '@lexical/table';
|
|
29
29
|
import { $getCharacterOffsets, $getNodeByKey, $getRoot, $getSelection, $isElementNode, $isRangeSelection, $isTextNode } from 'lexical';
|
|
30
|
+
import { remark } from 'remark';
|
|
31
|
+
import remarkGfm from 'remark-gfm';
|
|
30
32
|
import { DataSource } from "../../../editor-kernel";
|
|
31
33
|
import { INodeHelper } from "../../../editor-kernel/inode/helper";
|
|
32
34
|
import { INodeService } from "../../inode";
|
|
@@ -46,6 +48,26 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
46
48
|
return _this;
|
|
47
49
|
}
|
|
48
50
|
_createClass(MarkdownDataSource, [{
|
|
51
|
+
key: "formatMarkdown",
|
|
52
|
+
value: function formatMarkdown(markdown) {
|
|
53
|
+
try {
|
|
54
|
+
var result = remark().use([[remarkGfm, {
|
|
55
|
+
singleTilde: false
|
|
56
|
+
}]]).data('settings', {
|
|
57
|
+
bullet: '-',
|
|
58
|
+
emphasis: '*',
|
|
59
|
+
fences: true,
|
|
60
|
+
rule: '-',
|
|
61
|
+
strong: '*',
|
|
62
|
+
tightDefinitions: true
|
|
63
|
+
}).processSync(markdown);
|
|
64
|
+
return String(result);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
logger.error('Failed to format markdown:', error);
|
|
67
|
+
return markdown;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
49
71
|
key: "read",
|
|
50
72
|
value: function read(editor, data) {
|
|
51
73
|
var _this$getService;
|
|
@@ -179,7 +201,7 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
179
201
|
_lexicalRootNode.getChildren().forEach(function (child) {
|
|
180
202
|
return _rootCtx.processChild(_rootCtx, child);
|
|
181
203
|
});
|
|
182
|
-
return _rootCtx.toString();
|
|
204
|
+
return _this2.formatMarkdown(_rootCtx.toString());
|
|
183
205
|
});
|
|
184
206
|
} else if ($isTableSelection(selection)) {
|
|
185
207
|
// todo
|
|
@@ -217,7 +239,7 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
217
239
|
rootNode.getChildren().forEach(function (child) {
|
|
218
240
|
return rootCtx.processChild(rootCtx, child);
|
|
219
241
|
});
|
|
220
|
-
return rootCtx.toString();
|
|
242
|
+
return _this2.formatMarkdown(rootCtx.toString());
|
|
221
243
|
});
|
|
222
244
|
}
|
|
223
245
|
}]);
|
|
@@ -4,6 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
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; }
|
|
5
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { cx } from 'antd-style';
|
|
7
8
|
import { CLICK_COMMAND, COMMAND_PRIORITY_LOW } from 'lexical';
|
|
8
9
|
import { useCallback, useEffect, useRef } from 'react';
|
|
9
10
|
import { useLexicalNodeSelection } from "../../../../editor-kernel/react/useLexicalNodeSelection";
|
|
@@ -30,7 +31,7 @@ var Mention = function Mention(_ref) {
|
|
|
30
31
|
return editor.registerCommand(CLICK_COMMAND, onClick, COMMAND_PRIORITY_LOW);
|
|
31
32
|
}, [editor, node, onClick]);
|
|
32
33
|
return /*#__PURE__*/_jsxs("span", {
|
|
33
|
-
className: className,
|
|
34
|
+
className: cx('editor_mention', className),
|
|
34
35
|
ref: spanRef,
|
|
35
36
|
children: ["@", node.label]
|
|
36
37
|
});
|
|
@@ -6,6 +6,6 @@ export var styles = createStaticStyles(function (_ref) {
|
|
|
6
6
|
var css = _ref.css,
|
|
7
7
|
cssVar = _ref.cssVar;
|
|
8
8
|
return {
|
|
9
|
-
mention: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n user-select: none;\n\n position: relative;\n\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid ", ";\n border-radius: 0.25em;\n\n font-size: 0.875em;\n line-height: 1;\n color: ", ";\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n\n &.selected {\n color: #000;\n background: ", ";\n }\n "])), cssVar.
|
|
9
|
+
mention: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n user-select: none;\n\n position: relative;\n\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid ", ";\n border-radius: 0.25em;\n\n font-size: 0.875em;\n line-height: 1;\n color: ", ";\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n\n .editor_mention {\n padding: 0;\n }\n\n &.selected {\n color: #000;\n background: ", ";\n }\n "])), cssVar.colorInfoBgHover, cssVar.colorInfo, cssVar.colorInfoBg, cssVar.yellow)
|
|
10
10
|
};
|
|
11
11
|
});
|
|
@@ -47,7 +47,7 @@ export var ReactTablePlugin = function ReactTablePlugin(_ref) {
|
|
|
47
47
|
useLexicalEditor(function (editor) {
|
|
48
48
|
setLexicalEditor(editor);
|
|
49
49
|
editor.registerUpdateListener(function () {
|
|
50
|
-
editor.
|
|
50
|
+
editor.read(function () {
|
|
51
51
|
var selection = $getSelection();
|
|
52
52
|
if (!$isTableSelection(selection) && !$isRangeSelection(selection)) {
|
|
53
53
|
return null;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { ActionIcon, Flexbox } from '@lobehub/ui';
|
|
4
|
-
import { Popover } from 'antd';
|
|
3
|
+
import { ActionIcon, Flexbox, Popover } from '@lobehub/ui';
|
|
5
4
|
import { CircleChevronLeftIcon, CircleChevronRightIcon, CircleChevronUpIcon } from 'lucide-react';
|
|
6
5
|
import { motion } from 'motion/react';
|
|
7
6
|
import { styles } from "../style";
|
|
@@ -15,6 +15,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
15
15
|
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; }
|
|
16
16
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
17
17
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
18
|
+
import { debounce } from 'es-toolkit';
|
|
18
19
|
import { createElement, memo, useMemo } from 'react';
|
|
19
20
|
import { ReactEditor } from "../../editor-kernel/react/react-editor";
|
|
20
21
|
import { ReactEditorContent, ReactPlainText } from "../../plugins/common";
|
|
@@ -29,6 +30,8 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
29
30
|
var content = _ref.content,
|
|
30
31
|
style = _ref.style,
|
|
31
32
|
className = _ref.className,
|
|
33
|
+
_ref$debounceWait = _ref.debounceWait,
|
|
34
|
+
debounceWait = _ref$debounceWait === void 0 ? 100 : _ref$debounceWait,
|
|
32
35
|
editable = _ref.editable,
|
|
33
36
|
editor = _ref.editor,
|
|
34
37
|
onInit = _ref.onInit,
|
|
@@ -64,6 +67,14 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
64
67
|
var enableMention = Boolean((mentionOption === null || mentionOption === void 0 ? void 0 : mentionOption.items) && mentionOption.items.length > 0);
|
|
65
68
|
var markdownWriter = mentionOption.markdownWriter,
|
|
66
69
|
restMentionOption = _objectWithoutProperties(mentionOption, _excluded);
|
|
70
|
+
|
|
71
|
+
// Create debounced versions of onChange and onTextChange
|
|
72
|
+
var debouncedOnChange = useMemo(function () {
|
|
73
|
+
return onChange ? debounce(onChange, debounceWait) : undefined;
|
|
74
|
+
}, [onChange, debounceWait]);
|
|
75
|
+
var debouncedOnTextChange = useMemo(function () {
|
|
76
|
+
return onTextChange ? debounce(onTextChange, debounceWait) : undefined;
|
|
77
|
+
}, [onTextChange, debounceWait]);
|
|
67
78
|
var memoPlugins = useMemo(function () {
|
|
68
79
|
return [enablePasteMarkdown && ReactMarkdownPlugin].concat(_toConsumableArray(plugins)).filter(Boolean).map(function (plugin, index) {
|
|
69
80
|
var withNoProps = typeof plugin === 'function';
|
|
@@ -105,14 +116,14 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
105
116
|
enablePasteMarkdown: enablePasteMarkdown,
|
|
106
117
|
markdownOption: markdownOption,
|
|
107
118
|
onBlur: onBlur,
|
|
108
|
-
onChange:
|
|
119
|
+
onChange: debouncedOnChange,
|
|
109
120
|
onCompositionEnd: onCompositionEnd,
|
|
110
121
|
onCompositionStart: onCompositionStart,
|
|
111
122
|
onContextMenu: onContextMenu,
|
|
112
123
|
onFocus: onFocus,
|
|
113
124
|
onKeyDown: onKeyDown,
|
|
114
125
|
onPressEnter: onPressEnter,
|
|
115
|
-
onTextChange:
|
|
126
|
+
onTextChange: debouncedOnTextChange,
|
|
116
127
|
style: style,
|
|
117
128
|
variant: variant,
|
|
118
129
|
children: /*#__PURE__*/_jsx(ReactEditorContent, {
|
|
@@ -11,6 +11,11 @@ export interface EditorProps extends Partial<ReactEditorContentProps>, Omit<Reac
|
|
|
11
11
|
autoFocus?: boolean;
|
|
12
12
|
children?: ReactNode;
|
|
13
13
|
className?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Debounce wait time in milliseconds for onChange and onTextChange callbacks
|
|
16
|
+
* @default 100
|
|
17
|
+
*/
|
|
18
|
+
debounceWait?: number;
|
|
14
19
|
editable?: boolean;
|
|
15
20
|
editor?: IEditor;
|
|
16
21
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { ActionIcon, Flexbox } from '@lobehub/ui';
|
|
4
|
-
import { Popover } from 'antd';
|
|
3
|
+
import { ActionIcon, Flexbox, Popover } from '@lobehub/ui';
|
|
5
4
|
import { CircleChevronLeftIcon, CircleChevronRightIcon, CircleChevronUpIcon } from 'lucide-react';
|
|
6
5
|
import { motion } from 'motion/react';
|
|
7
6
|
import { styles } from "../style";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/editor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.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",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"lucide-react": "^0.562.0",
|
|
57
57
|
"polished": "^4.3.1",
|
|
58
58
|
"re-resizable": "^6.11.2",
|
|
59
|
-
"react-error-boundary": "^6.0.
|
|
59
|
+
"react-error-boundary": "^6.0.2",
|
|
60
60
|
"react-merge-refs": "^3.0.2",
|
|
61
61
|
"remark-cjk-friendly": "^1.2.3",
|
|
62
62
|
"remark-supersub": "^1.0.0",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"use-merge-value": "^1.2.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@lobehub/ui": "^4.
|
|
68
|
+
"@lobehub/ui": "^4.11.5",
|
|
69
69
|
"antd": "^6.1.1",
|
|
70
70
|
"motion": "^12.0.0",
|
|
71
71
|
"react": "^19.0.0",
|