@lobehub/editor 1.18.2 → 1.19.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.
@@ -24,7 +24,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
24
24
  import { registerDragonSupport } from '@lexical/dragon';
25
25
  import { createEmptyHistoryState, registerHistory } from '@lexical/history';
26
26
  import { $createHeadingNode, $createQuoteNode, $isHeadingNode, $isQuoteNode, HeadingNode, QuoteNode, registerRichText } from '@lexical/rich-text';
27
- import { $createLineBreakNode, $createParagraphNode, $isTextNode, COMMAND_PRIORITY_HIGH, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND } from 'lexical';
27
+ import { $createLineBreakNode, $createParagraphNode, $getSelection, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_HIGH, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND } from 'lexical';
28
28
  import { KernelPlugin } from "../../../editor-kernel/plugin";
29
29
  import { IMarkdownShortCutService, isPunctuationChar } from "../../markdown";
30
30
  import { registerCommands } from "../command";
@@ -32,7 +32,7 @@ import JSONDataSource from "../data-source/json-data-source";
32
32
  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
- import { createBlockNode } from "../utils";
35
+ import { $isCursorInQuote, $isCursorInTable, createBlockNode } from "../utils";
36
36
  import { registerMDReader } from "./mdReader";
37
37
  import { registerHeaderBackspace, registerLastElement, registerRichKeydown } from "./register";
38
38
  patchBreakLine();
@@ -319,8 +319,38 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
319
319
  // Convert soft line breaks (Shift+Enter) to hard line breaks (paragraph breaks)
320
320
  // This allows breaking out of code blocks with Shift+Enter
321
321
  editor.registerCommand(INSERT_LINE_BREAK_COMMAND, function () {
322
- // Dispatch paragraph command instead of line break
323
- editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);
322
+ // editor.read(() => {
323
+ var selection = $getSelection();
324
+ if (!$isRangeSelection(selection)) {
325
+ console.info('---------?');
326
+ return false;
327
+ }
328
+
329
+ // Check if cursor is in a table
330
+ var _$isCursorInTable = $isCursorInTable(selection),
331
+ inCell = _$isCursorInTable.inCell,
332
+ inTable = _$isCursorInTable.inTable;
333
+ if (inCell) {
334
+ // We're in a table cell, allow normal line break behavior
335
+ return false;
336
+ }
337
+ if (inTable) {
338
+ // We're in a table but not in a cell, prevent line break
339
+ return false;
340
+ }
341
+
342
+ // Check if cursor is in a quote
343
+ var inQuote = $isCursorInQuote(selection);
344
+ if (inQuote) {
345
+ // We're in a quote block, allow normal line break behavior
346
+ // This preserves line breaks within quotes while maintaining quote formatting
347
+ return false;
348
+ }
349
+
350
+ // Not in a table or quote, convert to paragraph break
351
+ editor.update(function () {
352
+ editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);
353
+ });
324
354
  return true; // Prevent default line break behavior
325
355
  }, COMMAND_PRIORITY_HIGH));
326
356
  this.registerMarkdown(this.kernel);
@@ -26,3 +26,8 @@ export declare function $canShowPlaceholder(isComposing: boolean): boolean;
26
26
  * @returns A function that executes $canShowPlaceholder with arguments.
27
27
  */
28
28
  export declare function $canShowPlaceholderCurry(isEditorComposing: boolean): () => boolean;
29
+ export declare function $isCursorInTable(selection: any): {
30
+ inCell: boolean;
31
+ inTable: boolean;
32
+ };
33
+ export declare function $isCursorInQuote(selection: any): boolean;
@@ -4,7 +4,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
5
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
6
  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; }
7
- import { $getRoot, $isDecoratorNode, $isElementNode, $isParagraphNode, $isTextNode } from 'lexical';
7
+ import { $isQuoteNode } from '@lexical/rich-text';
8
+ import { $isTableCellNode, $isTableNode } from '@lexical/table';
9
+ import { $getRoot, $isDecoratorNode, $isElementNode, $isParagraphNode, $isRangeSelection, $isTextNode } from 'lexical';
8
10
  export var createBlockNode = function createBlockNode(createNode) {
9
11
  return function (parentNode, children, match, isImport) {
10
12
  var node = createNode(match, parentNode);
@@ -93,4 +95,62 @@ export function $canShowPlaceholderCurry(isEditorComposing) {
93
95
  return function () {
94
96
  return $canShowPlaceholder(isEditorComposing);
95
97
  };
98
+ }
99
+
100
+ // Utility function to check if cursor is in a table
101
+ export function $isCursorInTable(selection) {
102
+ if (!$isRangeSelection(selection)) {
103
+ return {
104
+ inCell: false,
105
+ inTable: false
106
+ };
107
+ }
108
+ var focusNode = selection.focus.getNode();
109
+ var currentNode = focusNode;
110
+ var inTable = false;
111
+ var inCell = false;
112
+
113
+ // Traverse up the parent chain to find table context
114
+ while (currentNode) {
115
+ if ($isTableCellNode(currentNode)) {
116
+ inCell = true;
117
+ inTable = true;
118
+ break;
119
+ }
120
+ if ($isTableNode(currentNode)) {
121
+ inTable = true;
122
+ break;
123
+ }
124
+ var parent = currentNode.getParent();
125
+ if (!parent) {
126
+ break;
127
+ }
128
+ currentNode = parent;
129
+ }
130
+ return {
131
+ inCell: inCell,
132
+ inTable: inTable
133
+ };
134
+ }
135
+
136
+ // Utility function to check if cursor is in a quote
137
+ export function $isCursorInQuote(selection) {
138
+ if (!$isRangeSelection(selection)) {
139
+ return false;
140
+ }
141
+ var focusNode = selection.focus.getNode();
142
+ var currentNode = focusNode;
143
+
144
+ // Traverse up the parent chain to find quote context
145
+ while (currentNode) {
146
+ if ($isQuoteNode(currentNode)) {
147
+ return true;
148
+ }
149
+ var parent = currentNode.getParent();
150
+ if (!parent) {
151
+ break;
152
+ }
153
+ currentNode = parent;
154
+ }
155
+ return false;
96
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.18.2",
3
+ "version": "1.19.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",