@lobehub/editor 1.29.0 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/es/editor-kernel/kernel.js +2 -2
  2. package/es/editor-kernel/utils.d.ts +2 -1
  3. package/es/editor-kernel/utils.js +9 -2
  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/file/plugin/index.js +62 -16
  10. package/es/plugins/hr/plugin/index.js +25 -1
  11. package/es/plugins/image/node/basie-image-node.d.ts +2 -10
  12. package/es/plugins/image/node/basie-image-node.js +5 -30
  13. package/es/plugins/image/node/block-image-node.d.ts +1 -1
  14. package/es/plugins/image/node/block-image-node.js +3 -8
  15. package/es/plugins/image/node/image-node.d.ts +1 -1
  16. package/es/plugins/image/node/image-node.js +3 -8
  17. package/es/plugins/image/plugin/index.js +101 -17
  18. package/es/plugins/link/plugin/index.js +38 -4
  19. package/es/plugins/list/plugin/index.js +61 -0
  20. package/es/plugins/litexml/command/index.d.ts +16 -0
  21. package/es/plugins/litexml/command/index.js +94 -0
  22. package/es/plugins/litexml/data-source/litexml-data-source.d.ts +60 -0
  23. package/es/plugins/litexml/data-source/litexml-data-source.js +435 -0
  24. package/es/plugins/litexml/index.d.ts +7 -0
  25. package/es/plugins/litexml/index.js +5 -0
  26. package/es/plugins/litexml/plugin/index.d.ts +16 -0
  27. package/es/plugins/litexml/plugin/index.js +59 -0
  28. package/es/plugins/litexml/react/index.d.ts +3 -0
  29. package/es/plugins/litexml/react/index.js +22 -0
  30. package/es/plugins/litexml/service/litexml-service.d.ts +85 -0
  31. package/es/plugins/litexml/service/litexml-service.js +101 -0
  32. package/es/plugins/litexml/utils/index.d.ts +2 -0
  33. package/es/plugins/litexml/utils/index.js +33 -0
  34. package/es/plugins/math/plugin/index.js +40 -0
  35. package/es/plugins/mention/plugin/index.d.ts +1 -1
  36. package/es/plugins/mention/plugin/index.js +30 -4
  37. package/es/plugins/slash/react/ReactSlashPlugin.js +2 -1
  38. package/es/plugins/table/plugin/index.js +81 -0
  39. package/es/react/hooks/useEditorState/index.js +2 -1
  40. 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);
@@ -30,5 +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;
33
+ export declare function $closest(node: LexicalNode | ElementNode | null, test: (node: LexicalNode) => boolean): LexicalNode | null;
34
34
  export declare function $closestNodeType(node: LexicalNode | ElementNode | null, type: string | string[]): LexicalNode | null;
35
+ export declare function moment(): Promise<unknown>;
@@ -109,7 +109,7 @@ export function compareNodeOrder(nodeA, nodeB) {
109
109
  // This case should not happen as we checked for equality at the start
110
110
  return 0;
111
111
  }
112
- export function closest(node, test) {
112
+ export function $closest(node, test) {
113
113
  var current = node;
114
114
  while (current) {
115
115
  if (test(current)) {
@@ -120,7 +120,14 @@ export function closest(node, test) {
120
120
  return null;
121
121
  }
122
122
  export function $closestNodeType(node, type) {
123
- return closest(node, function (n) {
123
+ return $closest(node, function (n) {
124
124
  return Array.isArray(type) ? type.includes(n.getType()) : n.getType() === type;
125
125
  });
126
+ }
127
+ export function moment() {
128
+ return new Promise(function (resolve) {
129
+ queueMicrotask(function () {
130
+ return resolve(true);
131
+ });
132
+ });
126
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",
@@ -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) {
@@ -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;
@@ -16,11 +16,11 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
16
16
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
17
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
18
18
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
- import { DecoratorNode, ParagraphNode, RootNode, TextNode, createEditor } from 'lexical';
19
+ import { DecoratorNode } from 'lexical';
20
20
  export var BaseImageNode = /*#__PURE__*/function (_DecoratorNode) {
21
21
  _inherits(BaseImageNode, _DecoratorNode);
22
22
  var _super = _createSuper(BaseImageNode);
23
- function BaseImageNode(src, altText, maxWidth, width, height, showCaption, caption, captionsEnabled, key) {
23
+ function BaseImageNode(src, altText, maxWidth, width, height, key) {
24
24
  var _this;
25
25
  _classCallCheck(this, BaseImageNode);
26
26
  _this = _super.call(this, key);
@@ -29,33 +29,17 @@ export var BaseImageNode = /*#__PURE__*/function (_DecoratorNode) {
29
29
  _defineProperty(_assertThisInitialized(_this), "__width", void 0);
30
30
  _defineProperty(_assertThisInitialized(_this), "__height", void 0);
31
31
  _defineProperty(_assertThisInitialized(_this), "__maxWidth", void 0);
32
- _defineProperty(_assertThisInitialized(_this), "__showCaption", void 0);
33
- _defineProperty(_assertThisInitialized(_this), "__caption", void 0);
34
- // Captions cannot yet be used within editor cells
35
- _defineProperty(_assertThisInitialized(_this), "__captionsEnabled", void 0);
36
32
  _this.__src = src;
37
33
  _this.__altText = altText;
38
34
  _this.__maxWidth = maxWidth;
39
35
  _this.__width = width || 'inherit';
40
36
  _this.__height = height || 'inherit';
41
- _this.__showCaption = showCaption || false;
42
- _this.__caption = caption || createEditor({
43
- namespace: 'Playground/ImageNodeCaption',
44
- nodes: [RootNode, TextNode, ParagraphNode]
45
- });
46
- _this.__captionsEnabled = captionsEnabled || captionsEnabled === undefined;
47
37
  return _this;
48
38
  }
49
39
  _createClass(BaseImageNode, [{
50
40
  key: "updateFromJSON",
51
41
  value: function updateFromJSON(serializedNode) {
52
42
  var node = _get(_getPrototypeOf(BaseImageNode.prototype), "updateFromJSON", this).call(this, serializedNode);
53
- var caption = serializedNode.caption;
54
- var nestedEditor = node.__caption;
55
- var editorState = nestedEditor.parseEditorState(caption.editorState);
56
- if (!editorState.isEmpty()) {
57
- nestedEditor.setEditorState(editorState);
58
- }
59
43
  return node;
60
44
  }
61
45
  }, {
@@ -75,10 +59,8 @@ export var BaseImageNode = /*#__PURE__*/function (_DecoratorNode) {
75
59
  value: function exportJSON() {
76
60
  return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(BaseImageNode.prototype), "exportJSON", this).call(this)), {}, {
77
61
  altText: this.getAltText(),
78
- caption: this.__caption.toJSON(),
79
62
  height: this.__height === 'inherit' ? 0 : this.__height,
80
63
  maxWidth: this.__maxWidth,
81
- showCaption: this.__showCaption,
82
64
  src: this.getSrc(),
83
65
  width: this.__width === 'inherit' ? 0 : this.__width
84
66
  });
@@ -90,12 +72,6 @@ export var BaseImageNode = /*#__PURE__*/function (_DecoratorNode) {
90
72
  writable.__width = width;
91
73
  writable.__height = height;
92
74
  }
93
- }, {
94
- key: "setShowCaption",
95
- value: function setShowCaption(showCaption) {
96
- var writable = this.getWritable();
97
- writable.__showCaption = showCaption;
98
- }
99
75
  }, {
100
76
  key: "isInline",
101
77
  value: function isInline() {
@@ -132,7 +108,7 @@ export var BaseImageNode = /*#__PURE__*/function (_DecoratorNode) {
132
108
  }], [{
133
109
  key: "clone",
134
110
  value: function clone(node) {
135
- return new BaseImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__showCaption, node.__caption, node.__captionsEnabled, node.__key);
111
+ return new BaseImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__key);
136
112
  }
137
113
  }, {
138
114
  key: "importJSON",
@@ -141,10 +117,9 @@ export var BaseImageNode = /*#__PURE__*/function (_DecoratorNode) {
141
117
  height = serializedNode.height,
142
118
  width = serializedNode.width,
143
119
  maxWidth = serializedNode.maxWidth,
144
- src = serializedNode.src,
145
- showCaption = serializedNode.showCaption;
120
+ src = serializedNode.src;
146
121
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
147
- return new BaseImageNode(src, altText, maxWidth, width, height, showCaption);
122
+ return new BaseImageNode(src, altText, maxWidth, width, height);
148
123
  }
149
124
  }, {
150
125
  key: "getType",
@@ -27,5 +27,5 @@ export declare class BlockImageNode extends BaseImageNode {
27
27
  decorate(): any;
28
28
  createDOM(config: EditorConfig): HTMLElement;
29
29
  }
30
- export declare function $createBlockImageNode({ altText, height, maxWidth, captionsEnabled, src, width, showCaption, caption, key, }: ImagePayload): BlockImageNode;
30
+ export declare function $createBlockImageNode({ altText, height, maxWidth, src, width, key, }: ImagePayload): BlockImageNode;
31
31
  export declare function $isBlockImageNode(node: LexicalNode): node is BlockImageNode;