@lobehub/editor 1.28.1 → 1.30.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.
Files changed (43) hide show
  1. package/es/editor-kernel/kernel.js +2 -2
  2. package/es/editor-kernel/utils.d.ts +4 -1
  3. package/es/editor-kernel/utils.js +22 -0
  4. package/es/index.d.ts +1 -0
  5. package/es/index.js +1 -0
  6. package/es/plugins/code/plugin/index.js +24 -1
  7. package/es/plugins/codeblock/plugin/index.js +47 -3
  8. package/es/plugins/common/plugin/index.js +108 -3
  9. package/es/plugins/common/react/Placeholder/index.js +3 -1
  10. package/es/plugins/file/plugin/index.js +62 -16
  11. package/es/plugins/hr/plugin/index.js +25 -1
  12. package/es/plugins/image/command/index.d.ts +1 -1
  13. package/es/plugins/image/command/index.js +4 -2
  14. package/es/plugins/image/node/basie-image-node.d.ts +2 -10
  15. package/es/plugins/image/node/basie-image-node.js +5 -30
  16. package/es/plugins/image/node/block-image-node.d.ts +1 -1
  17. package/es/plugins/image/node/block-image-node.js +3 -8
  18. package/es/plugins/image/node/image-node.d.ts +1 -1
  19. package/es/plugins/image/node/image-node.js +3 -8
  20. package/es/plugins/image/plugin/index.js +101 -16
  21. package/es/plugins/link/plugin/index.js +38 -4
  22. package/es/plugins/list/plugin/index.js +61 -0
  23. package/es/plugins/litexml/command/index.d.ts +16 -0
  24. package/es/plugins/litexml/command/index.js +91 -0
  25. package/es/plugins/litexml/data-source/litexml-data-source.d.ts +60 -0
  26. package/es/plugins/litexml/data-source/litexml-data-source.js +435 -0
  27. package/es/plugins/litexml/index.d.ts +7 -0
  28. package/es/plugins/litexml/index.js +5 -0
  29. package/es/plugins/litexml/plugin/index.d.ts +16 -0
  30. package/es/plugins/litexml/plugin/index.js +59 -0
  31. package/es/plugins/litexml/react/index.d.ts +3 -0
  32. package/es/plugins/litexml/react/index.js +22 -0
  33. package/es/plugins/litexml/service/litexml-service.d.ts +85 -0
  34. package/es/plugins/litexml/service/litexml-service.js +101 -0
  35. package/es/plugins/litexml/utils/index.d.ts +2 -0
  36. package/es/plugins/litexml/utils/index.js +33 -0
  37. package/es/plugins/math/plugin/index.js +40 -0
  38. package/es/plugins/mention/plugin/index.d.ts +1 -1
  39. package/es/plugins/mention/plugin/index.js +30 -4
  40. package/es/plugins/slash/react/ReactSlashPlugin.js +2 -1
  41. package/es/plugins/table/plugin/index.js +81 -0
  42. package/es/react/hooks/useEditorState/index.js +2 -1
  43. package/package.json +7 -6
@@ -29,7 +29,7 @@ import { createDebugLogger } from "../utils/debug";
29
29
  import { getHotkeyById, registerHotkey as _registerHotkey } from "../utils/hotkey/registerHotkey";
30
30
  import { registerEvent } from "./event";
31
31
  import { KernelPlugin } from "./plugin";
32
- import { createEmptyEditorState } from "./utils";
32
+ import { createEmptyEditorState, noop } from "./utils";
33
33
  templateSettings.interpolate = /{{([\S\s]+?)}}/g;
34
34
  export var Kernel = /*#__PURE__*/function (_EventEmitter) {
35
35
  _inherits(Kernel, _EventEmitter);
@@ -687,7 +687,7 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
687
687
  }
688
688
  var listenersInPriorityOrder = commandsMap.get(command);
689
689
  if (listenersInPriorityOrder === undefined) {
690
- return function () {};
690
+ return noop;
691
691
  }
692
692
  var listeners = listenersInPriorityOrder[priority];
693
693
  listeners.add(listener);
@@ -1,4 +1,4 @@
1
- import { LexicalEditor, LexicalNode, NodeKey } from 'lexical';
1
+ import { ElementNode, LexicalEditor, LexicalNode, NodeKey } from 'lexical';
2
2
  import type { IEditorKernel, IServiceID } from "../types";
3
3
  export declare const DOM_ELEMENT_TYPE = 1;
4
4
  export declare const DOM_TEXT_TYPE = 3;
@@ -30,3 +30,6 @@ export declare function getKernelFromEditor(editor: LexicalEditor): IEditorKerne
30
30
  * @returns
31
31
  */
32
32
  export declare function compareNodeOrder(nodeA: LexicalNode, nodeB: LexicalNode): number;
33
+ export declare function $closest(node: LexicalNode | ElementNode | null, test: (node: LexicalNode) => boolean): LexicalNode | null;
34
+ export declare function $closestNodeType(node: LexicalNode | ElementNode | null, type: string | string[]): LexicalNode | null;
35
+ export declare function moment(): Promise<unknown>;
@@ -108,4 +108,26 @@ export function compareNodeOrder(nodeA, nodeB) {
108
108
 
109
109
  // This case should not happen as we checked for equality at the start
110
110
  return 0;
111
+ }
112
+ export function $closest(node, test) {
113
+ var current = node;
114
+ while (current) {
115
+ if (test(current)) {
116
+ return current;
117
+ }
118
+ current = current.getParent();
119
+ }
120
+ return null;
121
+ }
122
+ export function $closestNodeType(node, type) {
123
+ return $closest(node, function (n) {
124
+ return Array.isArray(type) ? type.includes(n.getType()) : n.getType() === type;
125
+ });
126
+ }
127
+ export function moment() {
128
+ return new Promise(function (resolve) {
129
+ queueMicrotask(function () {
130
+ return resolve(true);
131
+ });
132
+ });
111
133
  }
package/es/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from './plugins/image';
10
10
  export * from './plugins/link';
11
11
  export * from './plugins/link-highlight';
12
12
  export * from './plugins/list';
13
+ export * from './plugins/litexml';
13
14
  export * from './plugins/markdown';
14
15
  export * from './plugins/math';
15
16
  export * from './plugins/mention';
package/es/index.js CHANGED
@@ -10,6 +10,7 @@ export * from "./plugins/image";
10
10
  export * from "./plugins/link";
11
11
  export * from "./plugins/link-highlight";
12
12
  export * from "./plugins/list";
13
+ export * from "./plugins/litexml";
13
14
  export * from "./plugins/markdown";
14
15
  export * from "./plugins/math";
15
16
  export * from "./plugins/mention";
@@ -17,6 +17,7 @@ import { $setSelection, TextNode } from 'lexical';
17
17
  import { INodeHelper } from "../../../editor-kernel/inode/helper";
18
18
  import { KernelPlugin } from "../../../editor-kernel/plugin";
19
19
  import { $createCursorNode, cursorNodeSerialized } from "../../common";
20
+ import { ILitexmlService } from "../../litexml";
20
21
  import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
21
22
  import { registerCodeInlineCommand } from "../command";
22
23
  import { $createCodeNode, CodeNode } from "../node/code";
@@ -49,12 +50,34 @@ export var CodePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
49
50
  node.replace($createCodeNode(node.getTextContent())).insertAfter($createCursorNode());
50
51
  }
51
52
  }));
53
+ this.registerMarkdown();
54
+ this.registerLiteXml();
55
+ }
56
+ }, {
57
+ key: "registerLiteXml",
58
+ value: function registerLiteXml() {
59
+ var litexmlService = this.kernel.requireService(ILitexmlService);
60
+ if (!litexmlService) {
61
+ return;
62
+ }
63
+ litexmlService.registerXMLWriter(CodeNode.getType(), function (node, ctx) {
64
+ return ctx.createXmlNode('codeInline', {});
65
+ });
66
+ litexmlService.registerXMLReader('codeInline', function (xmlElement, children) {
67
+ return INodeHelper.createElementNode(CodeNode.getType(), {
68
+ children: children
69
+ });
70
+ });
71
+ }
72
+ }, {
73
+ key: "registerMarkdown",
74
+ value: function registerMarkdown() {
52
75
  var markdownService = this.kernel.requireService(IMarkdownShortCutService);
53
76
  if (!markdownService) {
54
77
  return;
55
78
  }
56
79
  markdownService.registerMarkdownWriter(CodeNode.getType(), function (ctx, node) {
57
- ctx.appendLine("`".concat(node.getTextContent(), "`"));
80
+ ctx.appendLine("`".concat(node.getTextContent().replaceAll("\uFEFF", ''), "`"));
58
81
  return true;
59
82
  });
60
83
  markdownService.registerMarkdownShortCuts([{
@@ -17,6 +17,7 @@ import { $createCodeNode, $isCodeHighlightNode, $isCodeNode, CodeHighlightNode,
17
17
  import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, PASTE_COMMAND, TabNode } from 'lexical';
18
18
  import { INodeHelper } from "../../../editor-kernel/inode/helper";
19
19
  import { KernelPlugin } from "../../../editor-kernel/plugin";
20
+ import { ILitexmlService } from "../../litexml";
20
21
  import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
21
22
  import { CustomShikiTokenizer, registerCodeCommand } from "../command";
22
23
  import { getCodeLanguageByInput } from "../utils/language";
@@ -121,11 +122,54 @@ export var CodeblockPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
121
122
  return false;
122
123
  }, COMMAND_PRIORITY_EDITOR));
123
124
  this.registerMarkdown();
125
+ this.registerLiteXml();
126
+ }
127
+ }, {
128
+ key: "registerLiteXml",
129
+ value: function registerLiteXml() {
130
+ var _this2 = this;
131
+ var litexmlService = this.kernel.requireService(ILitexmlService);
132
+ if (!litexmlService) {
133
+ return;
134
+ }
135
+ litexmlService.registerXMLWriter(CodeNode.getType(), function (node, ctx) {
136
+ var codeNode = node;
137
+ var xmlNode = ctx.createXmlNode('code', {
138
+ lang: codeNode.getLanguage() || 'plaintext'
139
+ }, codeNode.getTextContent());
140
+ return xmlNode;
141
+ });
142
+ litexmlService.registerXMLReader('code', function (xmlElment, children) {
143
+ var _this2$config;
144
+ var text = children.map(function (v) {
145
+ return v.text || '';
146
+ }).join('');
147
+ return INodeHelper.createElementNode(CodeNode.getType(), {
148
+ children: text.split('\n').flatMap(function (text, index, arr) {
149
+ var textNode = INodeHelper.createTextNode(text);
150
+ textNode.type = 'code-highlight';
151
+ if (index === arr.length - 1) {
152
+ return textNode;
153
+ }
154
+ return [textNode, {
155
+ type: 'linebreak',
156
+ version: 1
157
+ }];
158
+ }).flat(),
159
+ direction: 'ltr',
160
+ format: '',
161
+ indent: 0,
162
+ language: xmlElment.getAttribute('lang'),
163
+ textStyle: '--shiki-dark:var(--color-info);--shiki-light:var(--color-info)',
164
+ theme: "".concat(toMarkdownTheme((_this2$config = _this2.config) === null || _this2$config === void 0 ? void 0 : _this2$config.shikiTheme), " needUpdate"),
165
+ version: 1
166
+ });
167
+ });
124
168
  }
125
169
  }, {
126
170
  key: "registerMarkdown",
127
171
  value: function registerMarkdown() {
128
- var _this2 = this;
172
+ var _this3 = this;
129
173
  var kernel = this.kernel;
130
174
  var markdownService = kernel.requireService(IMarkdownShortCutService);
131
175
  if (!markdownService) {
@@ -160,7 +204,7 @@ export var CodeblockPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
160
204
  }
161
205
  });
162
206
  markdownService.registerMarkdownReader('code', function (node) {
163
- var _this2$config;
207
+ var _this3$config;
164
208
  var language = node.lang ? getCodeLanguageByInput(node.lang) : 'plaintext';
165
209
  return INodeHelper.createElementNode('code', {
166
210
  children: node.value.split('\n').flatMap(function (text, index, arr) {
@@ -179,7 +223,7 @@ export var CodeblockPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
179
223
  indent: 0,
180
224
  language: language,
181
225
  textStyle: '--shiki-dark:var(--color-info);--shiki-light:var(--color-info)',
182
- theme: "".concat(toMarkdownTheme((_this2$config = _this2.config) === null || _this2$config === void 0 ? void 0 : _this2$config.shikiTheme), " needUpdate"),
226
+ theme: "".concat(toMarkdownTheme((_this3$config = _this3.config) === null || _this3$config === void 0 ? void 0 : _this3$config.shikiTheme), " needUpdate"),
183
227
  version: 1
184
228
  });
185
229
  });
@@ -25,8 +25,11 @@ import { registerDragonSupport } from '@lexical/dragon';
25
25
  import { registerHistory } from '@lexical/history';
26
26
  import { $createHeadingNode, $createQuoteNode, $isHeadingNode, $isQuoteNode, HeadingNode, QuoteNode, registerRichText } from '@lexical/rich-text';
27
27
  import { CAN_USE_DOM } from '@lexical/utils';
28
- import { $createLineBreakNode, $createParagraphNode, $getSelection, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_HIGH, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND } from 'lexical';
28
+ import { $createLineBreakNode, $createParagraphNode, $getSelection, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_HIGH, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, ParagraphNode, TEXT_TYPE_TO_FORMAT, TextNode } from 'lexical';
29
+ import { noop } from "../../../editor-kernel";
30
+ import { INodeHelper } from "../../../editor-kernel/inode/helper";
29
31
  import { KernelPlugin } from "../../../editor-kernel/plugin";
32
+ import { ILitexmlService } from "../../litexml";
30
33
  import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
31
34
  import { isPunctuationChar } from "../../markdown/utils";
32
35
  import { registerCommands } from "../command";
@@ -199,7 +202,7 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
199
202
  markdownService.registerMarkdownShortCuts(textFormatShortcuts);
200
203
  }
201
204
  markdownService.registerMarkdownWriter('paragraph', function (ctx) {
202
- ctx.wrap('', '\n');
205
+ ctx.wrap('', '\n\n');
203
206
  });
204
207
  markdownService.registerMarkdownWriter('quote', function (ctx, node) {
205
208
  if ($isQuoteNode(node)) {
@@ -323,7 +326,7 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
323
326
  key: "onInit",
324
327
  value: function onInit(editor) {
325
328
  var _this$config2;
326
- this.registerClears(registerRichText(editor), CAN_USE_DOM ? registerDragonSupport(editor) : function () {}, registerHistory(editor, this.kernel.getHistoryState(), 300), registerHeaderBackspace(editor), registerRichKeydown(editor, this.kernel, {
329
+ this.registerClears(registerRichText(editor), CAN_USE_DOM ? registerDragonSupport(editor) : noop, registerHistory(editor, this.kernel.getHistoryState(), 300), registerHeaderBackspace(editor), registerRichKeydown(editor, this.kernel, {
327
330
  enableHotkey: (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.enableHotkey
328
331
  }), registerCommands(editor), registerBreakLineClick(editor), registerCursorNode(editor), registerLastElement(editor),
329
332
  // Convert soft line breaks (Shift+Enter) to hard line breaks (paragraph breaks)
@@ -363,6 +366,108 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
363
366
  return true; // Prevent default line break behavior
364
367
  }, COMMAND_PRIORITY_HIGH));
365
368
  this.registerMarkdown(this.kernel);
369
+ this.registerLiteXml();
370
+ }
371
+ }, {
372
+ key: "registerLiteXml",
373
+ value: function registerLiteXml() {
374
+ var litexmlService = this.kernel.requireService(ILitexmlService);
375
+ if (!litexmlService) {
376
+ return;
377
+ }
378
+ litexmlService.registerXMLWriter(TextNode.getType(), function (node, ctx) {
379
+ var attr = {};
380
+ if ($isTextNode(node)) {
381
+ if (node.hasFormat('bold')) {
382
+ attr['bold'] = 'true';
383
+ }
384
+ if (node.hasFormat('italic')) {
385
+ attr['italic'] = 'true';
386
+ }
387
+ if (node.hasFormat('underline')) {
388
+ attr['underline'] = 'true';
389
+ }
390
+ if (node.hasFormat('strikethrough')) {
391
+ attr['strikethrough'] = 'true';
392
+ }
393
+ if (node.hasFormat('subscript')) {
394
+ attr['subscript'] = 'true';
395
+ }
396
+ if (node.hasFormat('superscript')) {
397
+ attr['superscript'] = 'true';
398
+ }
399
+ return ctx.createXmlNode('span', attr, node.getTextContent());
400
+ }
401
+ return false;
402
+ });
403
+ litexmlService.registerXMLReader('span', function (xmlElement) {
404
+ var textContent = xmlElement.textContent || '';
405
+ var bold = xmlElement.getAttribute('bold');
406
+ var italic = xmlElement.getAttribute('italic');
407
+ var underline = xmlElement.getAttribute('underline');
408
+ var strikethrough = xmlElement.getAttribute('strikethrough');
409
+ var subscript = xmlElement.getAttribute('subscript');
410
+ var superscript = xmlElement.getAttribute('superscript');
411
+ var format = 0;
412
+ if (bold === 'true') {
413
+ format |= TEXT_TYPE_TO_FORMAT['bold'];
414
+ }
415
+ if (italic === 'true') {
416
+ format |= TEXT_TYPE_TO_FORMAT['italic'];
417
+ }
418
+ if (underline === 'true') {
419
+ format |= TEXT_TYPE_TO_FORMAT['underline'];
420
+ }
421
+ if (strikethrough === 'true') {
422
+ format |= TEXT_TYPE_TO_FORMAT['strikethrough'];
423
+ }
424
+ if (subscript === 'true') {
425
+ format |= TEXT_TYPE_TO_FORMAT['subscript'];
426
+ }
427
+ if (superscript === 'true') {
428
+ format |= TEXT_TYPE_TO_FORMAT['superscript'];
429
+ }
430
+ return INodeHelper.createTextNode(textContent, {
431
+ detail: 0,
432
+ format: format,
433
+ mode: 'normal',
434
+ style: ''
435
+ });
436
+ });
437
+ litexmlService.registerXMLWriter('quote', function (node, ctx) {
438
+ if ($isQuoteNode(node)) {
439
+ return ctx.createXmlNode('quote', {});
440
+ }
441
+ return false;
442
+ });
443
+ litexmlService.registerXMLWriter('heading', function (node, ctx) {
444
+ if ($isHeadingNode(node)) {
445
+ return ctx.createXmlNode(node.getTag(), {});
446
+ }
447
+ return false;
448
+ });
449
+ litexmlService.registerXMLWriter(ParagraphNode.getType(), function (node, ctx) {
450
+ return ctx.createXmlNode('p', {});
451
+ });
452
+ litexmlService.registerXMLReader('quote', function (xmlElement, children) {
453
+ return INodeHelper.createElementNode(QuoteNode.getType(), {
454
+ children: children
455
+ });
456
+ });
457
+ litexmlService.registerXMLReader('p', function (xmlElement, children) {
458
+ return INodeHelper.createElementNode(ParagraphNode.getType(), {
459
+ children: children
460
+ });
461
+ });
462
+ var headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
463
+ headingTags.forEach(function (tag) {
464
+ litexmlService.registerXMLReader(tag, function (xmlElement, children) {
465
+ return INodeHelper.createElementNode(HeadingNode.getType(), {
466
+ children: children,
467
+ tag: tag
468
+ });
469
+ });
470
+ });
366
471
  }
367
472
  }, {
368
473
  key: "destroy",
@@ -7,6 +7,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { mergeRegister } from '@lexical/utils';
8
8
  import { $getNodeByKey, $getSelection, $isBlockElementNode, $isRangeSelection } from 'lexical';
9
9
  import { memo, useRef, useState } from 'react';
10
+ import { $closestNodeType } from "../../../../editor-kernel";
10
11
  import { useLexicalEditor } from "../../../../editor-kernel/react";
11
12
  import { $canShowPlaceholderCurry } from "../../utils";
12
13
  import { useStyles } from "./style";
@@ -55,7 +56,8 @@ var Placeholder = /*#__PURE__*/memo(function (_ref) {
55
56
  while (node && !$isBlockElementNode(node)) {
56
57
  node = node.getParent();
57
58
  }
58
- if (node) {
59
+ var tableNode = $closestNodeType(node, ['tablecell', 'heading']);
60
+ if (node && !tableNode) {
59
61
  var dom = editor.getElementByKey(node.getKey());
60
62
  if (dom && hasOnlyBrChild(dom)) {
61
63
  if (currentPlaceHolderRef.current && currentPlaceHolderRef.current !== dom) {
@@ -18,7 +18,9 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
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
19
  import { $wrapNodeInElement } from '@lexical/utils';
20
20
  import { $createParagraphNode, $createRangeSelection, $insertNodes, $isRootOrShadowRoot, $setSelection } from 'lexical';
21
+ import { INodeHelper } from "../../../editor-kernel/inode/helper";
21
22
  import { KernelPlugin } from "../../../editor-kernel/plugin";
23
+ import { ILitexmlService } from "../../litexml";
22
24
  import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
23
25
  import { IUploadService } from "../../upload";
24
26
  import { createDebugLogger } from "../../../utils/debug";
@@ -32,7 +34,6 @@ export var FilePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
32
34
  _inherits(FilePlugin, _KernelPlugin);
33
35
  var _super = _createSuper(FilePlugin);
34
36
  function FilePlugin(kernel, config) {
35
- var _kernel$requireServic;
36
37
  var _this;
37
38
  _classCallCheck(this, FilePlugin);
38
39
  _this = _super.call(this);
@@ -47,21 +48,6 @@ export var FilePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
47
48
  _this.registerDecorator(kernel, FileNode.getType(), function (node, editor) {
48
49
  return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
49
50
  });
50
- (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownWriter(FileNode.getType(), function (ctx, node) {
51
- if ($isFileNode(node)) {
52
- if (config !== null && config !== void 0 && config.markdownWriter) {
53
- ctx.appendLine(config.markdownWriter(node));
54
- return;
55
- }
56
- if (node.status === 'pending') {
57
- ctx.appendLine("Uploading ".concat(node.name, "..."));
58
- } else if (node.status === 'error') {
59
- ctx.appendLine("Failed to upload ".concat(node.name, ": ").concat(node.message));
60
- } else {
61
- ctx.appendLine("[".concat(node.name, "](").concat(node.fileUrl, ")"));
62
- }
63
- }
64
- });
65
51
  return _this;
66
52
  }
67
53
  _createClass(FilePlugin, [{
@@ -112,6 +98,66 @@ export var FilePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
112
98
  }());
113
99
  this.register(registerFileCommand(editor, this.config.handleUpload));
114
100
  this.register(registerFileNodeSelectionObserver(editor));
101
+ this.registerLiteXml();
102
+ this.registerMarkdownWriter();
103
+ }
104
+ }, {
105
+ key: "registerLiteXml",
106
+ value: function registerLiteXml() {
107
+ var litexmlService = this.kernel.requireService(ILitexmlService);
108
+ if (!litexmlService) {
109
+ return;
110
+ }
111
+ litexmlService.registerXMLWriter(FileNode.getType(), function (node, ctx) {
112
+ if ($isFileNode(node)) {
113
+ var _node$size;
114
+ return ctx.createXmlNode('file', {
115
+ fileUrl: node.fileUrl || '',
116
+ message: node.message || '',
117
+ name: node.name,
118
+ size: ((_node$size = node.size) === null || _node$size === void 0 ? void 0 : _node$size.toString()) || '0',
119
+ status: node.status
120
+ });
121
+ }
122
+ return false;
123
+ });
124
+ litexmlService.registerXMLReader('file', function (xmlElement) {
125
+ var name = xmlElement.getAttribute('name') || 'unknown';
126
+ var fileUrl = xmlElement.getAttribute('fileUrl') || '';
127
+ var status = xmlElement.getAttribute('status');
128
+ return INodeHelper.createTypeNode(FileNode.getType(), {
129
+ fileUrl: fileUrl,
130
+ message: xmlElement.getAttribute('message') || '',
131
+ name: name,
132
+ size: parseInt(xmlElement.getAttribute('size') || '0', 10),
133
+ status: status
134
+ });
135
+ });
136
+ }
137
+ }, {
138
+ key: "registerMarkdownWriter",
139
+ value: function registerMarkdownWriter() {
140
+ var _this3 = this;
141
+ var markdownService = this.kernel.requireService(IMarkdownShortCutService);
142
+ if (!markdownService) {
143
+ return;
144
+ }
145
+ markdownService.registerMarkdownWriter(FileNode.getType(), function (ctx, node) {
146
+ if ($isFileNode(node)) {
147
+ var _this3$config;
148
+ if ((_this3$config = _this3.config) !== null && _this3$config !== void 0 && _this3$config.markdownWriter) {
149
+ ctx.appendLine(_this3.config.markdownWriter(node));
150
+ return;
151
+ }
152
+ if (node.status === 'pending') {
153
+ ctx.appendLine("Uploading ".concat(node.name, "..."));
154
+ } else if (node.status === 'error') {
155
+ ctx.appendLine("Failed to upload ".concat(node.name, ": ").concat(node.message));
156
+ } else {
157
+ ctx.appendLine("[".concat(node.name, "](").concat(node.fileUrl, ")"));
158
+ }
159
+ }
160
+ });
115
161
  }
116
162
  }]);
117
163
  return FilePlugin;
@@ -15,6 +15,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
15
15
  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); }
16
16
  import { INodeHelper } from "../../../editor-kernel/inode/helper";
17
17
  import { KernelPlugin } from "../../../editor-kernel/plugin";
18
+ import { ILitexmlService } from "../../litexml";
18
19
  import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
19
20
  import { registerHorizontalRuleCommand } from "../command";
20
21
  import { $createHorizontalRuleNode, $isHorizontalRuleNode, HorizontalRuleNode } from "../node/HorizontalRuleNode";
@@ -42,8 +43,31 @@ export var HRPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
42
43
  _createClass(HRPlugin, [{
43
44
  key: "onInit",
44
45
  value: function onInit(editor) {
45
- var _this$kernel$requireS, _this$kernel$requireS2, _this$kernel$requireS3;
46
46
  this.register(registerHorizontalRuleCommand(editor));
47
+ this.registerMarkdown();
48
+ this.registerLiteXml();
49
+ }
50
+ }, {
51
+ key: "registerLiteXml",
52
+ value: function registerLiteXml() {
53
+ var litexmlService = this.kernel.requireService(ILitexmlService);
54
+ if (!litexmlService) {
55
+ return;
56
+ }
57
+ litexmlService.registerXMLWriter(HorizontalRuleNode.getType(), function (node, ctx) {
58
+ if ($isHorizontalRuleNode(node)) {
59
+ return ctx.createXmlNode('hr', {});
60
+ }
61
+ return false;
62
+ });
63
+ litexmlService.registerXMLReader('hr', function () {
64
+ return INodeHelper.createElementNode(HorizontalRuleNode.getType(), {});
65
+ });
66
+ }
67
+ }, {
68
+ key: "registerMarkdown",
69
+ value: function registerMarkdown() {
70
+ var _this$kernel$requireS, _this$kernel$requireS2, _this$kernel$requireS3;
47
71
  (_this$kernel$requireS = this.kernel.requireService(IMarkdownShortCutService)) === null || _this$kernel$requireS === void 0 || _this$kernel$requireS.registerMarkdownShortCut({
48
72
  regExp: /^(---|\*\*\*|___)$/,
49
73
  replace: function replace(parentNode, _1, _2, isImport) {
@@ -7,4 +7,4 @@ export declare const INSERT_IMAGE_COMMAND: import("lexical").LexicalCommand<{
7
7
  }>;
8
8
  export declare function registerImageCommand(editor: LexicalEditor, handleUpload: (file: File) => Promise<{
9
9
  url: string;
10
- }>): () => void;
10
+ }>, defaultBlockImage?: boolean): () => void;
@@ -9,11 +9,13 @@ function isImageFile(file) {
9
9
  return file.type.startsWith('image/');
10
10
  }
11
11
  export function registerImageCommand(editor, handleUpload) {
12
+ var defaultBlockImage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
12
13
  return editor.registerCommand(INSERT_IMAGE_COMMAND, function (payload) {
13
14
  var file = payload.file,
14
15
  range = payload.range,
15
16
  block = payload.block,
16
17
  maxWidth = payload.maxWidth;
18
+ var isBlock = block !== null && block !== void 0 ? block : defaultBlockImage;
17
19
  if (!isImageFile(file)) {
18
20
  return false; // Not an image file
19
21
  }
@@ -26,7 +28,7 @@ export function registerImageCommand(editor, handleUpload) {
26
28
  }
27
29
  $setSelection(rangeSelection);
28
30
  }
29
- var imageNode = block ? $createBlockImageNode({
31
+ var imageNode = isBlock ? $createBlockImageNode({
30
32
  altText: file.name,
31
33
  maxWidth: maxWidth || 800,
32
34
  src: placeholderURL
@@ -36,7 +38,7 @@ export function registerImageCommand(editor, handleUpload) {
36
38
  src: placeholderURL
37
39
  });
38
40
  $insertNodes([imageNode]); // Insert a zero-width space to ensure the image is not the last child
39
- if (!block && $isRootOrShadowRoot(imageNode.getParentOrThrow())) {
41
+ if (!isBlock && $isRootOrShadowRoot(imageNode.getParentOrThrow())) {
40
42
  $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
41
43
  }
42
44
  handleUpload(file).then(function (res) {
@@ -1,21 +1,17 @@
1
- import { DOMExportOutput, DecoratorNode, EditorConfig, LexicalEditor, LexicalUpdateJSON, NodeKey, SerializedEditor, SerializedLexicalNode, Spread } from 'lexical';
1
+ import { DOMExportOutput, DecoratorNode, EditorConfig, LexicalEditor, LexicalUpdateJSON, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
2
2
  export interface ImagePayload {
3
3
  altText: string;
4
4
  caption?: LexicalEditor;
5
- captionsEnabled?: boolean;
6
5
  height?: number;
7
6
  key?: NodeKey;
8
7
  maxWidth?: number;
9
- showCaption?: boolean;
10
8
  src: string;
11
9
  width?: number;
12
10
  }
13
11
  export type SerializedImageNode = Spread<{
14
12
  altText: string;
15
- caption: SerializedEditor;
16
13
  height?: number;
17
14
  maxWidth: number;
18
- showCaption: boolean;
19
15
  src: string;
20
16
  width?: number;
21
17
  }, SerializedLexicalNode>;
@@ -25,18 +21,14 @@ export declare class BaseImageNode extends DecoratorNode<any> {
25
21
  __width: 'inherit' | number;
26
22
  __height: 'inherit' | number;
27
23
  __maxWidth: number;
28
- __showCaption: boolean;
29
- __caption: LexicalEditor;
30
- __captionsEnabled: boolean;
31
24
  static clone(node: BaseImageNode): BaseImageNode;
32
25
  static importJSON(serializedNode: SerializedImageNode): BaseImageNode;
33
26
  static getType(): string;
34
27
  updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedImageNode>): this;
35
28
  exportDOM(): DOMExportOutput;
36
- constructor(src: string, altText: string, maxWidth: number, width?: 'inherit' | number, height?: 'inherit' | number, showCaption?: boolean, caption?: LexicalEditor, captionsEnabled?: boolean, key?: NodeKey);
29
+ constructor(src: string, altText: string, maxWidth: number, width?: 'inherit' | number, height?: 'inherit' | number, key?: NodeKey);
37
30
  exportJSON(): SerializedImageNode;
38
31
  setWidthAndHeight(width: 'inherit' | number, height: 'inherit' | number): void;
39
- setShowCaption(showCaption: boolean): void;
40
32
  isInline(): boolean;
41
33
  createDOM(config: EditorConfig): HTMLElement;
42
34
  updateDOM(): false;