@lobehub/editor 1.6.1 → 1.7.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.
@@ -33,7 +33,7 @@ import TextDataSource from "../data-source/text-data-source";
33
33
  import { patchBreakLine, registerBreakLineClick } from "../node/ElementDOMSlot";
34
34
  import { CursorNode, registerCursorNode } from "../node/cursor";
35
35
  import { createBlockNode } from "../utils";
36
- import { registerHeaderBackspace, registerRichKeydown } from "./register";
36
+ import { registerHeaderBackspace, registerLastElement, registerRichKeydown } from "./register";
37
37
  patchBreakLine();
38
38
  export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
39
39
  _inherits(CommonPlugin, _KernelPlugin);
@@ -244,7 +244,7 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
244
244
  var _this$config;
245
245
  this.registerClears(registerRichText(editor), registerDragonSupport(editor), registerHistory(editor, createEmptyHistoryState(), 300), registerHeaderBackspace(editor), registerRichKeydown(editor, this.kernel, {
246
246
  enableHotkey: (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.enableHotkey
247
- }), registerCommands(editor), registerBreakLineClick(editor), registerCursorNode(editor));
247
+ }), registerCommands(editor), registerBreakLineClick(editor), registerCursorNode(editor), registerLastElement(editor));
248
248
  }
249
249
  }, {
250
250
  key: "destroy",
@@ -7,3 +7,4 @@ export interface RichKeydownOptions {
7
7
  enableHotkey?: boolean;
8
8
  }
9
9
  export declare function registerRichKeydown(editor: LexicalEditor, kernel: IEditor, options?: RichKeydownOptions): () => void;
10
+ export declare function registerLastElement(editor: LexicalEditor): () => void;
@@ -90,7 +90,7 @@ function $isSelectionAtEndOfRoot(selection) {
90
90
  }
91
91
  export function registerHeaderBackspace(editor) {
92
92
  return editor.registerCommand(KEY_BACKSPACE_COMMAND, function (payload) {
93
- // Handle backspace key press
93
+ // Handle backspace key press for heading nodes
94
94
  var headingNode = editor.read(function () {
95
95
  var selection = $getSelection();
96
96
  // Do not handle non-collapsed selection
@@ -289,4 +289,43 @@ export function registerRichKeydown(editor, kernel, options) {
289
289
  }
290
290
  return false;
291
291
  }, COMMAND_PRIORITY_EDITOR));
292
+ }
293
+ var NEEDS_FOLLOWING_PARAGRAPH_TYPES = new Set(['code', 'table']);
294
+ export function registerLastElement(editor) {
295
+ var isProcessing = false;
296
+ return editor.registerUpdateListener(function (_ref2) {
297
+ var dirtyElements = _ref2.dirtyElements;
298
+ // Only process when root node or its direct children have changes
299
+ if (!dirtyElements.has('root') && !Array.from(dirtyElements.keys()).some(function (key) {
300
+ var _node$getParent;
301
+ var node = editor.getEditorState()._nodeMap.get(key);
302
+ return (node === null || node === void 0 || (_node$getParent = node.getParent()) === null || _node$getParent === void 0 ? void 0 : _node$getParent.getKey()) === 'root';
303
+ })) {
304
+ return;
305
+ }
306
+ if (isProcessing) return;
307
+ var needsParagraph = editor.read(function () {
308
+ var root = $getRoot();
309
+ var lastChild = root.getLastChild();
310
+
311
+ // Check if the last element needs a trailing paragraph
312
+ return NEEDS_FOLLOWING_PARAGRAPH_TYPES.has(lastChild === null || lastChild === void 0 ? void 0 : lastChild.getType());
313
+ });
314
+ if (needsParagraph) {
315
+ isProcessing = true;
316
+ queueMicrotask(function () {
317
+ editor.update(function () {
318
+ var root = $getRoot();
319
+ var currentLast = root.getLastChild();
320
+
321
+ // Double check to ensure the state still needs processing
322
+ if (NEEDS_FOLLOWING_PARAGRAPH_TYPES.has(currentLast === null || currentLast === void 0 ? void 0 : currentLast.getType())) {
323
+ var paragraph = $createParagraphNode();
324
+ root.append(paragraph);
325
+ }
326
+ isProcessing = false;
327
+ });
328
+ });
329
+ }
330
+ });
292
331
  }
@@ -43,7 +43,7 @@ var Placeholder = /*#__PURE__*/memo(function (_ref) {
43
43
  if (!canShowPlaceholder) {
44
44
  return null;
45
45
  }
46
- return /*#__PURE__*/_jsx("p", {
46
+ return /*#__PURE__*/_jsx("div", {
47
47
  className: styles.placeholder,
48
48
  style: style,
49
49
  children: children
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
5
5
  "keywords": [
6
6
  "lobehub",