@lobehub/editor 1.4.6 → 1.5.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 (113) hide show
  1. package/es/editor-kernel/kernel.d.ts +4 -1
  2. package/es/editor-kernel/kernel.js +56 -1
  3. package/es/index.d.ts +2 -0
  4. package/es/index.js +2 -0
  5. package/es/locale/index.d.ts +7 -0
  6. package/es/locale/index.js +7 -0
  7. package/es/plugins/code/command/index.d.ts +3 -0
  8. package/es/plugins/code/command/index.js +48 -0
  9. package/es/plugins/code/index.d.ts +3 -0
  10. package/es/plugins/code/index.js +3 -0
  11. package/es/plugins/code/node/code.d.ts +19 -0
  12. package/es/plugins/{common/node/LexicalLineBreakNode.js → code/node/code.js} +93 -95
  13. package/es/plugins/code/plugin/index.d.ts +5 -0
  14. package/es/plugins/{common/node/ParagraphNode.js → code/plugin/index.js} +40 -33
  15. package/es/plugins/code/plugin/registry.d.ts +3 -0
  16. package/es/plugins/code/plugin/registry.js +48 -0
  17. package/es/plugins/code/react/CodeReactPlugin.d.ts +4 -0
  18. package/es/plugins/code/react/CodeReactPlugin.js +31 -0
  19. package/es/plugins/code/react/index.d.ts +1 -0
  20. package/es/plugins/code/react/index.js +1 -0
  21. package/es/plugins/code/react/style.d.ts +3 -0
  22. package/es/plugins/code/react/style.js +10 -0
  23. package/es/plugins/code/react/type.d.ts +3 -0
  24. package/es/plugins/code/react/type.js +1 -0
  25. package/es/plugins/common/data-source/json-data-source.js +42 -5
  26. package/es/plugins/common/data-source/text-data-source.js +2 -2
  27. package/es/plugins/common/index.d.ts +1 -0
  28. package/es/plugins/common/index.js +1 -0
  29. package/es/plugins/common/node/ElementDOMSlot.d.ts +3 -5
  30. package/es/plugins/common/node/ElementDOMSlot.js +29 -56
  31. package/es/plugins/common/node/cursor.d.ts +12 -0
  32. package/es/plugins/common/node/cursor.js +303 -0
  33. package/es/plugins/common/plugin/index.js +5 -9
  34. package/es/plugins/common/plugin/register.d.ts +3 -1
  35. package/es/plugins/common/plugin/register.js +46 -13
  36. package/es/plugins/link/command/index.d.ts +5 -1
  37. package/es/plugins/link/command/index.js +21 -3
  38. package/es/plugins/link/react/ReactLinkPlugin.js +6 -9
  39. package/es/plugins/link/react/components/LinkEdit.d.ts +2 -1
  40. package/es/plugins/link/react/components/LinkEdit.js +195 -51
  41. package/es/plugins/link/react/components/LinkToolbar.d.ts +10 -0
  42. package/es/plugins/link/react/components/LinkToolbar.js +73 -0
  43. package/es/plugins/link/react/style.d.ts +3 -2
  44. package/es/plugins/link/react/style.js +8 -5
  45. package/es/plugins/list/command/index.d.ts +1 -0
  46. package/es/plugins/list/command/index.js +1 -0
  47. package/es/plugins/list/plugin/checkList.d.ts +3 -0
  48. package/es/plugins/list/plugin/checkList.js +167 -0
  49. package/es/plugins/list/plugin/index.js +9 -2
  50. package/es/plugins/list/react/style.js +4 -2
  51. package/es/plugins/markdown/data-source/markdown-data-source.js +5 -1
  52. package/es/plugins/markdown/service/shortcut.d.ts +3 -3
  53. package/es/plugins/math/command/index.d.ts +13 -0
  54. package/es/plugins/math/command/index.js +47 -0
  55. package/es/plugins/math/index.d.ts +3 -0
  56. package/es/plugins/math/index.js +3 -0
  57. package/es/plugins/math/node/index.d.ts +45 -0
  58. package/es/plugins/math/node/index.js +259 -0
  59. package/es/plugins/math/plugin/index.d.ts +11 -0
  60. package/es/plugins/math/plugin/index.js +103 -0
  61. package/es/plugins/math/react/component/MathEditor.d.ts +10 -0
  62. package/es/plugins/math/react/component/MathEditor.js +253 -0
  63. package/es/plugins/math/react/component/MathEditorContainer.d.ts +14 -0
  64. package/es/plugins/math/react/component/MathEditorContainer.js +60 -0
  65. package/es/plugins/math/react/component/MathEditorContent.d.ts +26 -0
  66. package/es/plugins/math/react/component/MathEditorContent.js +163 -0
  67. package/es/plugins/math/react/component/MathInline.d.ts +10 -0
  68. package/es/plugins/math/react/component/MathInline.js +105 -0
  69. package/es/plugins/math/react/component/Placeholder.d.ts +3 -0
  70. package/es/plugins/math/react/component/Placeholder.js +19 -0
  71. package/es/plugins/math/react/index.d.ts +3 -0
  72. package/es/plugins/math/react/index.js +43 -0
  73. package/es/plugins/math/react/style.d.ts +6 -0
  74. package/es/plugins/math/react/style.js +16 -0
  75. package/es/plugins/math/react/type.d.ts +13 -0
  76. package/es/plugins/math/react/type.js +1 -0
  77. package/es/plugins/slash/react/ReactSlashPlugin.js +12 -10
  78. package/es/react/ChatInputActions/ChatInputActions.js +38 -119
  79. package/es/react/ChatInputActions/components/ActionItem.d.ts +13 -0
  80. package/es/react/ChatInputActions/components/ActionItem.js +60 -0
  81. package/es/react/ChatInputActions/components/ActionRender.d.ts +9 -0
  82. package/es/react/ChatInputActions/components/ActionRender.js +64 -0
  83. package/es/react/ChatInputActions/components/CollapsedActions.d.ts +4 -0
  84. package/es/react/ChatInputActions/components/CollapsedActions.js +82 -0
  85. package/es/react/ChatInputActions/components/useContainerSize.d.ts +9 -0
  86. package/es/react/ChatInputActions/components/useContainerSize.js +43 -0
  87. package/es/react/ChatInputActions/components/useDisplayActionCount.d.ts +13 -0
  88. package/es/react/ChatInputActions/components/useDisplayActionCount.js +66 -0
  89. package/es/react/ChatInputActions/style.js +1 -1
  90. package/es/react/ChatInputActions/type.d.ts +10 -9
  91. package/es/react/FloatMenu/FloatMenu.d.ts +4 -0
  92. package/es/react/FloatMenu/FloatMenu.js +49 -0
  93. package/es/react/FloatMenu/index.d.ts +2 -0
  94. package/es/react/FloatMenu/index.js +2 -0
  95. package/es/react/FloatMenu/type.d.ts +19 -0
  96. package/es/react/FloatMenu/type.js +1 -0
  97. package/es/react/SlashMenu/SlashMenu.js +32 -48
  98. package/es/react/SlashMenu/type.d.ts +5 -13
  99. package/es/react/hooks/useEditorState/index.d.ts +4 -0
  100. package/es/react/hooks/useEditorState/index.js +40 -4
  101. package/es/react/index.d.ts +1 -0
  102. package/es/react/index.js +1 -0
  103. package/es/types/global.d.ts +4 -0
  104. package/es/types/kernel.d.ts +26 -1
  105. package/package.json +2 -1
  106. package/es/plugins/common/node/LexicalLineBreakNode.d.ts +0 -31
  107. package/es/plugins/common/node/ParagraphNode.d.ts +0 -7
  108. package/es/plugins/link/react/components/Toolbar.d.ts +0 -7
  109. package/es/plugins/link/react/components/Toolbar.js +0 -63
  110. package/es/react/ChatInputActions/components/ChatInputActionsCollapse.d.ts +0 -4
  111. package/es/react/ChatInputActions/components/ChatInputActionsCollapse.js +0 -97
  112. /package/es/react/{SlashMenu → FloatMenu}/style.d.ts +0 -0
  113. /package/es/react/{SlashMenu → FloatMenu}/style.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'eventemitter3';
2
- import { CommandPayloadType, DecoratorNode, LexicalCommand, LexicalEditor, LexicalNodeConfig } from 'lexical';
2
+ import { CommandListener, CommandListenerPriority, CommandPayloadType, DecoratorNode, LexicalCommand, LexicalEditor, LexicalNodeConfig } from 'lexical';
3
3
  import { IEditor, IEditorKernel, IEditorPluginConstructor, IPlugin, IServiceID } from "../types/kernel";
4
4
  import { ILocaleKeys } from "../types/locale";
5
5
  import DataSource from './data-source';
@@ -75,4 +75,7 @@ export declare class Kernel extends EventEmitter implements IEditorKernel {
75
75
  get isEmpty(): boolean;
76
76
  get isSelected(): boolean;
77
77
  cleanDocument(): void;
78
+ private _commands;
79
+ private _commandsClean;
80
+ registerHighCommand<P>(command: LexicalCommand<P>, listener: CommandListener<P>, priority: CommandListenerPriority): () => void;
78
81
  }
@@ -20,7 +20,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
20
20
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
21
21
  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); }
22
22
  import EventEmitter from 'eventemitter3';
23
- import { $getSelection, $isRangeSelection, createEditor } from 'lexical';
23
+ import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_CRITICAL, createEditor } from 'lexical';
24
24
  import { get, merge, template, templateSettings } from 'lodash-es';
25
25
  import defaultLocale from "../locale";
26
26
  import { $isRootTextContentEmpty } from "../plugins/common/utils";
@@ -45,6 +45,8 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
45
45
  _defineProperty(_assertThisInitialized(_this), "localeMap", defaultLocale);
46
46
  _defineProperty(_assertThisInitialized(_this), "hotReloadMode", false);
47
47
  _defineProperty(_assertThisInitialized(_this), "editor", void 0);
48
+ _defineProperty(_assertThisInitialized(_this), "_commands", new Map());
49
+ _defineProperty(_assertThisInitialized(_this), "_commandsClean", new Map());
48
50
  _this.dataTypeMap = new Map();
49
51
  // Enable hot reload mode in development
50
52
  _this.hotReloadMode = _this.detectDevelopmentMode();
@@ -153,6 +155,7 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
153
155
  var editor = this.editor = createEditor({
154
156
  // @ts-expect-error Inject into lexical editor instance
155
157
  __kernel: this,
158
+ namespace: 'lobehub',
156
159
  nodes: this.nodes,
157
160
  onError: function onError(error) {
158
161
  _this2.emit('error', error);
@@ -452,6 +455,58 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
452
455
  value: function cleanDocument() {
453
456
  this.setDocument('text', '');
454
457
  }
458
+ }, {
459
+ key: "registerHighCommand",
460
+ value: function registerHighCommand(command, listener, priority) {
461
+ var _this4 = this;
462
+ var lexicalEditor = this.editor;
463
+ if (!lexicalEditor) {
464
+ throw new Error('Editor is not initialized.');
465
+ }
466
+ var commandsMap = this._commands;
467
+ if (!commandsMap.has(command)) {
468
+ commandsMap.set(command, [new Set(), new Set(), new Set(), new Set(), new Set()]);
469
+ this._commandsClean.set(command, lexicalEditor.registerCommand(command, function (payload) {
470
+ for (var i = 4; i >= 0; i--) {
471
+ var listenerInPriorityOrder = _this4._commands.get(command);
472
+ if (listenerInPriorityOrder !== undefined) {
473
+ var listenersSet = listenerInPriorityOrder[i];
474
+ var _iterator3 = _createForOfIteratorHelper(listenersSet),
475
+ _step3;
476
+ try {
477
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
478
+ var _listener = _step3.value;
479
+ if (_listener(payload, lexicalEditor)) {
480
+ return true;
481
+ }
482
+ }
483
+ } catch (err) {
484
+ _iterator3.e(err);
485
+ } finally {
486
+ _iterator3.f();
487
+ }
488
+ }
489
+ }
490
+ return false;
491
+ }, COMMAND_PRIORITY_CRITICAL));
492
+ }
493
+ var listenersInPriorityOrder = commandsMap.get(command);
494
+ if (listenersInPriorityOrder === undefined) {
495
+ return function () {};
496
+ }
497
+ var listeners = listenersInPriorityOrder[priority];
498
+ listeners.add(listener);
499
+ return function () {
500
+ listeners.delete(listener);
501
+ if (listenersInPriorityOrder.every(function (listenersSet) {
502
+ return listenersSet.size === 0;
503
+ })) {
504
+ var _this4$_commandsClean;
505
+ commandsMap.delete(command);
506
+ (_this4$_commandsClean = _this4._commandsClean.get(command)) === null || _this4$_commandsClean === void 0 || _this4$_commandsClean();
507
+ }
508
+ };
509
+ }
455
510
  }], [{
456
511
  key: "setGlobalHotReloadMode",
457
512
  value: function setGlobalHotReloadMode(enabled) {
package/es/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './editor-kernel';
2
2
  export * from './editor-kernel/react';
3
+ export * from './plugins/code';
3
4
  export * from './plugins/codeblock';
4
5
  export * from './plugins/common';
5
6
  export * from './plugins/file';
@@ -7,6 +8,7 @@ export * from './plugins/hr';
7
8
  export * from './plugins/image';
8
9
  export * from './plugins/link';
9
10
  export * from './plugins/list';
11
+ export * from './plugins/math';
10
12
  export * from './plugins/mention';
11
13
  export * from './plugins/slash';
12
14
  export * from './plugins/table';
package/es/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./editor-kernel";
2
2
  export * from "./editor-kernel/react";
3
+ export * from "./plugins/code";
3
4
  export * from "./plugins/codeblock";
4
5
  export * from "./plugins/common";
5
6
  export * from "./plugins/file";
@@ -7,6 +8,7 @@ export * from "./plugins/hr";
7
8
  export * from "./plugins/image";
8
9
  export * from "./plugins/link";
9
10
  export * from "./plugins/list";
11
+ export * from "./plugins/math";
10
12
  export * from "./plugins/mention";
11
13
  export * from "./plugins/slash";
12
14
  export * from "./plugins/table";
@@ -1,4 +1,6 @@
1
1
  declare const _default: {
2
+ cancel: string;
3
+ confirm: string;
2
4
  file: {
3
5
  error: string;
4
6
  uploading: string;
@@ -8,10 +10,15 @@ declare const _default: {
8
10
  };
9
11
  link: {
10
12
  edit: string;
13
+ editLinkTitle: string;
14
+ editTextTitle: string;
11
15
  open: string;
12
16
  placeholder: string;
13
17
  unlink: string;
14
18
  };
19
+ math: {
20
+ placeholder: string;
21
+ };
15
22
  table: {
16
23
  delete: string;
17
24
  deleteColumn: string;
@@ -1,4 +1,6 @@
1
1
  export default {
2
+ cancel: 'Cancel',
3
+ confirm: 'Confirm',
2
4
  file: {
3
5
  error: 'Error: {{message}}',
4
6
  uploading: 'Uploading file...'
@@ -8,10 +10,15 @@ export default {
8
10
  },
9
11
  link: {
10
12
  edit: 'Edit Link',
13
+ editLinkTitle: 'Link',
14
+ editTextTitle: 'Text',
11
15
  open: 'Open Link',
12
16
  placeholder: 'Enter link URL',
13
17
  unlink: 'Unlink Link'
14
18
  },
19
+ math: {
20
+ placeholder: 'Enter TeX formula'
21
+ },
15
22
  table: {
16
23
  delete: 'Delete table',
17
24
  deleteColumn: 'Delete column',
@@ -0,0 +1,3 @@
1
+ import { LexicalEditor } from 'lexical';
2
+ export declare const INSERT_CODEINLINE_COMMAND: import("lexical").LexicalCommand<undefined>;
3
+ export declare function registerCodeInlineCommand(editor: LexicalEditor): () => void;
@@ -0,0 +1,48 @@
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
+ 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
+ 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 { $isCodeHighlightNode } from '@lexical/code';
5
+ import { $getSelection, $insertNodes, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
6
+ import { $createCursorNode } from "../../common";
7
+ import { $createCodeNode, $isCodeInlineNode } from "../node/code";
8
+ export var INSERT_CODEINLINE_COMMAND = createCommand('INSERT_CODEINLINE_COMMAND');
9
+ export function registerCodeInlineCommand(editor) {
10
+ return editor.registerCommand(INSERT_CODEINLINE_COMMAND, function () {
11
+ editor.update(function () {
12
+ var selection = $getSelection();
13
+ if (!selection || !$isRangeSelection(selection)) {
14
+ return false;
15
+ }
16
+ var focusNode = selection.focus.getNode();
17
+ var anchorNode = selection.anchor.getNode();
18
+ if ($isCodeHighlightNode(focusNode) || $isCodeHighlightNode(anchorNode)) {
19
+ return false;
20
+ }
21
+ if (focusNode.getParent() !== anchorNode.getParent()) {
22
+ return false;
23
+ }
24
+ var parentNode = focusNode.getParent();
25
+ if ($isCodeInlineNode(parentNode)) {
26
+ var _iterator = _createForOfIteratorHelper(parentNode.getChildren().slice(0)),
27
+ _step;
28
+ try {
29
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
30
+ var node = _step.value;
31
+ parentNode.insertBefore(node);
32
+ }
33
+ } catch (err) {
34
+ _iterator.e(err);
35
+ } finally {
36
+ _iterator.f();
37
+ }
38
+ parentNode.remove();
39
+ return true;
40
+ }
41
+ var codeNode = $createCodeNode(selection.getTextContent());
42
+ $insertNodes([codeNode, $createCursorNode()]);
43
+ codeNode.select();
44
+ });
45
+ return true;
46
+ }, COMMAND_PRIORITY_EDITOR // Priority
47
+ );
48
+ }
@@ -0,0 +1,3 @@
1
+ export { INSERT_CODEINLINE_COMMAND } from './command';
2
+ export { CodePlugin } from './plugin';
3
+ export { ReactCodePlugin } from './react';
@@ -0,0 +1,3 @@
1
+ export { INSERT_CODEINLINE_COMMAND } from "./command";
2
+ export { CodePlugin } from "./plugin";
3
+ export { ReactCodePlugin } from "./react";
@@ -0,0 +1,19 @@
1
+ import { EditorConfig, LexicalEditor, SerializedElementNode } from 'lexical';
2
+ import { CardLikeElementNode } from "../../common";
3
+ export type SerializedCodeNode = SerializedElementNode;
4
+ export declare class CodeNode extends CardLikeElementNode {
5
+ static getType(): string;
6
+ static clone(node: CodeNode): CodeNode;
7
+ static importJSON(serializedNode: SerializedCodeNode): CodeNode;
8
+ createDOM(config: EditorConfig): HTMLElement;
9
+ getDOMSlot(element: HTMLElement): import("lexical").ElementDOMSlot<HTMLElement>;
10
+ canBeEmpty(): boolean;
11
+ isCardLike(): boolean;
12
+ isInline(): boolean;
13
+ canIndent(): boolean;
14
+ canInsertTextBefore(): boolean;
15
+ canInsertTextAfter(): boolean;
16
+ }
17
+ export declare function $createCodeNode(textContent?: string): CodeNode;
18
+ export declare function $isCodeInlineNode(node: unknown): node is CodeNode;
19
+ export declare function $isSelectionInCodeInline(editor: LexicalEditor): boolean;
@@ -4,6 +4,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
4
4
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  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); }
7
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
8
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
7
9
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
8
10
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9
11
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -11,130 +13,126 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
11
13
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
14
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
15
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
14
- /**
15
- * Copyright (c) Meta Platforms, Inc. and affiliates.
16
- *
17
- * This source code is licensed under the MIT license found in the
18
- * LICENSE file in the root directory of this source tree.
19
- *
20
- */
21
- import { $applyNodeReplacement, DecoratorNode, isBlockDomNode, isDOMTextNode } from 'lexical';
22
- var LexicalNodeImpl = DecoratorNode.prototype.constructor;
23
-
24
- /** @noInheritDoc */
25
- export var LineBreakNode = /*#__PURE__*/function (_LexicalNodeImpl) {
26
- _inherits(LineBreakNode, _LexicalNodeImpl);
27
- var _super = _createSuper(LineBreakNode);
28
- function LineBreakNode() {
29
- _classCallCheck(this, LineBreakNode);
16
+ /* eslint-disable @typescript-eslint/no-use-before-define */
17
+ import { addClassNamesToElement } from '@lexical/utils';
18
+ import { $applyNodeReplacement, $createTextNode, $getSelection, $isNodeSelection, $isRangeSelection } from 'lexical';
19
+ import { $createCursorNode, CardLikeElementNode } from "../../common";
20
+ export var CodeNode = /*#__PURE__*/function (_CardLikeElementNode) {
21
+ _inherits(CodeNode, _CardLikeElementNode);
22
+ var _super = _createSuper(CodeNode);
23
+ function CodeNode() {
24
+ _classCallCheck(this, CodeNode);
30
25
  return _super.apply(this, arguments);
31
26
  }
32
- _createClass(LineBreakNode, [{
33
- key: "getTextContent",
34
- value: function getTextContent() {
35
- return '\n';
27
+ _createClass(CodeNode, [{
28
+ key: "createDOM",
29
+ value: function createDOM(config) {
30
+ var element = document.createElement('span');
31
+ // eslint-disable-next-line unicorn/prefer-dom-node-dataset
32
+ element.setAttribute('data-lexical-key', this.getKey());
33
+ // const filler = document.createElement('t-filler');
34
+ // filler.contentEditable = 'false';
35
+ // filler.innerHTML = '\uFEFF';
36
+ // eslint-disable-next-line unicorn/prefer-dom-node-dataset
37
+ // filler.setAttribute('data-lexical-cursor', 'true');
38
+ // element.append(filler);
39
+ var childContainer = document.createElement('ne-content');
40
+ element.append(childContainer);
41
+ addClassNamesToElement(element, config.theme.codeInline);
42
+ return element;
36
43
  }
37
44
  }, {
38
- key: "createDOM",
39
- value: function createDOM() {
40
- return document.createElement('br');
45
+ key: "getDOMSlot",
46
+ value: function getDOMSlot(element) {
47
+ var neContent = element.querySelector('ne-content');
48
+ if (!neContent) {
49
+ throw new Error('CodeNode: ne-content not found');
50
+ }
51
+ return _get(_getPrototypeOf(CodeNode.prototype), "getDOMSlot", this).call(this, element).withElement(neContent);
41
52
  }
42
53
  }, {
43
- key: "updateDOM",
44
- value: function updateDOM() {
54
+ key: "canBeEmpty",
55
+ value: function canBeEmpty() {
45
56
  return false;
46
57
  }
58
+ }, {
59
+ key: "isCardLike",
60
+ value: function isCardLike() {
61
+ return true;
62
+ }
47
63
  }, {
48
64
  key: "isInline",
49
65
  value: function isInline() {
50
66
  return true;
51
67
  }
68
+ }, {
69
+ key: "canIndent",
70
+ value: function canIndent() {
71
+ return false;
72
+ }
73
+ }, {
74
+ key: "canInsertTextBefore",
75
+ value: function canInsertTextBefore() {
76
+ return true;
77
+ }
78
+ }, {
79
+ key: "canInsertTextAfter",
80
+ value: function canInsertTextAfter() {
81
+ return true;
82
+ }
52
83
  }], [{
53
84
  key: "getType",
54
85
  value: function getType() {
55
- return 'linebreak';
86
+ return 'codeInline';
56
87
  }
57
88
  }, {
58
89
  key: "clone",
59
90
  value: function clone(node) {
60
- return new LineBreakNode(node.__key);
61
- }
62
- }, {
63
- key: "importDOM",
64
- value: function importDOM() {
65
- return {
66
- br: function br(node) {
67
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
68
- if (isOnlyChildInBlockNode(node) || isLastChildInBlockNode(node)) {
69
- return null;
70
- }
71
- return {
72
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
73
- conversion: $convertLineBreakElement,
74
- priority: 0
75
- };
76
- }
77
- };
91
+ return new CodeNode(node.__key);
78
92
  }
79
93
  }, {
80
94
  key: "importJSON",
81
- value: function importJSON(serializedLineBreakNode) {
82
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
83
- return $createLineBreakNode().updateFromJSON(serializedLineBreakNode);
95
+ value: function importJSON(serializedNode) {
96
+ return $createCodeNode().updateFromJSON(serializedNode);
84
97
  }
85
98
  }]);
86
- return LineBreakNode;
87
- }(LexicalNodeImpl);
88
- function $convertLineBreakElement() {
89
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
90
- return {
91
- node: $createLineBreakNode()
92
- };
93
- }
94
- export function $createLineBreakNode() {
95
- return $applyNodeReplacement(new LineBreakNode());
99
+ return CodeNode;
100
+ }(CardLikeElementNode);
101
+ export function $createCodeNode(textContent) {
102
+ var codeNode = $applyNodeReplacement(new CodeNode());
103
+ var cursorNode = $createCursorNode();
104
+ codeNode.append(cursorNode);
105
+ if (textContent) {
106
+ codeNode.append($createTextNode(textContent));
107
+ }
108
+ return codeNode;
96
109
  }
97
- export function $isLineBreakNode(node) {
98
- return node instanceof LineBreakNode;
110
+ export function $isCodeInlineNode(node) {
111
+ return node instanceof CodeNode;
99
112
  }
100
- function isOnlyChildInBlockNode(node) {
101
- var parentElement = node.parentElement;
102
- if (parentElement !== null && isBlockDomNode(parentElement)) {
103
- var firstChild = parentElement.firstChild;
104
- if (firstChild === node ||
105
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
106
- firstChild.nextSibling === node && isWhitespaceDomTextNode(firstChild)) {
107
- var lastChild = parentElement.lastChild;
108
- if (lastChild === node || lastChild.previousSibling === node &&
109
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
110
- isWhitespaceDomTextNode(lastChild)) {
113
+ export function $isSelectionInCodeInline(editor) {
114
+ return editor.read(function () {
115
+ var selection = $getSelection();
116
+ if (!selection) {
117
+ return false;
118
+ }
119
+ if ($isRangeSelection(selection)) {
120
+ var focusNode = selection.focus.getNode();
121
+ var anchorNode = selection.anchor.getNode();
122
+ if (focusNode.getParent() !== anchorNode.getParent()) {
123
+ return false;
124
+ }
125
+ var parentNode = focusNode.getParent();
126
+ if ($isCodeInlineNode(parentNode)) {
111
127
  return true;
112
128
  }
113
- }
114
- }
115
- return false;
116
- }
117
- function isLastChildInBlockNode(node) {
118
- var parentElement = node.parentElement;
119
- if (parentElement !== null && isBlockDomNode(parentElement)) {
120
- // check if node is first child, because only child dont count
121
- var firstChild = parentElement.firstChild;
122
- if (firstChild === node ||
123
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
124
- firstChild.nextSibling === node && isWhitespaceDomTextNode(firstChild)) {
125
129
  return false;
130
+ } else if ($isNodeSelection(selection)) {
131
+ var nodes = selection.getNodes();
132
+ if (nodes.length === 1 && $isCodeInlineNode(nodes[0])) {
133
+ return true;
134
+ }
126
135
  }
127
-
128
- // check if its last child
129
- var lastChild = parentElement.lastChild;
130
- if (lastChild === node ||
131
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
132
- lastChild.previousSibling === node && isWhitespaceDomTextNode(lastChild)) {
133
- return true;
134
- }
135
- }
136
- return false;
137
- }
138
- function isWhitespaceDomTextNode(node) {
139
- return isDOMTextNode(node) && /^( |\t|\r?\n)+$/.test(node.textContent || '');
136
+ return false;
137
+ });
140
138
  }
@@ -0,0 +1,5 @@
1
+ import { IEditorPluginConstructor } from "../../../types";
2
+ export interface CodePluginOptions {
3
+ theme?: string;
4
+ }
5
+ export declare const CodePlugin: IEditorPluginConstructor<CodePluginOptions>;
@@ -1,11 +1,8 @@
1
+ var _class;
1
2
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
3
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
4
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
5
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
- 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); }
7
- function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
8
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
9
6
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
7
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
8
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -13,35 +10,45 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
13
10
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
11
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
12
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
- import { ParagraphNode } from 'lexical';
17
- import { MElementDOMSlot } from "./ElementDOMSlot";
18
- export var MParagraphNode = /*#__PURE__*/function (_ParagraphNode) {
19
- _inherits(MParagraphNode, _ParagraphNode);
20
- var _super = _createSuper(MParagraphNode);
21
- function MParagraphNode() {
22
- _classCallCheck(this, MParagraphNode);
23
- return _super.apply(this, arguments);
13
+ 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; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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
+ import { KernelPlugin } from "../../../editor-kernel/plugin";
17
+ import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
18
+ import { registerCodeInlineCommand } from "../command";
19
+ import { CodeNode } from "../node/code";
20
+ import { registerCodeInline } from "./registry";
21
+
22
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
23
+
24
+ export var CodePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
25
+ _inherits(CodePlugin, _KernelPlugin);
26
+ var _super = _createSuper(CodePlugin);
27
+ function CodePlugin(kernel, options) {
28
+ var _this;
29
+ _classCallCheck(this, CodePlugin);
30
+ _this = _super.call(this);
31
+ _this.kernel = kernel;
32
+ kernel.registerNodes([CodeNode]);
33
+ kernel.registerThemes({
34
+ codeInline: (options === null || options === void 0 ? void 0 : options.theme) || 'editor-code'
35
+ });
36
+ return _this;
24
37
  }
25
- _createClass(MParagraphNode, [{
26
- key: "createDOM",
27
- value: function createDOM(config) {
28
- return _get(_getPrototypeOf(MParagraphNode.prototype), "createDOM", this).call(this, config);
29
- }
30
- }, {
31
- key: "getDOMSlot",
32
- value: function getDOMSlot(element) {
33
- return new MElementDOMSlot(element);
34
- }
35
- }], [{
36
- key: "getType",
37
- value: function getType() {
38
- return 'paragraph';
39
- }
40
- }, {
41
- key: "clone",
42
- value: function clone(node) {
43
- return new MParagraphNode(node.__key);
38
+ _createClass(CodePlugin, [{
39
+ key: "onInit",
40
+ value: function onInit(editor) {
41
+ this.register(registerCodeInlineCommand(editor));
42
+ this.register(registerCodeInline(editor, this.kernel));
43
+ var markdownService = this.kernel.requireService(IMarkdownShortCutService);
44
+ if (!markdownService) {
45
+ return;
46
+ }
47
+ markdownService.registerMarkdownWriter(CodeNode.getType(), function (ctx, node) {
48
+ ctx.appendLine("`".concat(node.getTextContent(), "`"));
49
+ return true;
50
+ });
44
51
  }
45
52
  }]);
46
- return MParagraphNode;
47
- }(ParagraphNode);
53
+ return CodePlugin;
54
+ }(KernelPlugin), _defineProperty(_class, "pluginName", 'CodePlugin'), _class);
@@ -0,0 +1,3 @@
1
+ import { LexicalEditor } from 'lexical';
2
+ import { IEditorKernel } from "../../../types";
3
+ export declare function registerCodeInline(editor: LexicalEditor, kernel: IEditorKernel): () => void;