@lobehub/editor 1.5.7 → 1.5.8

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.
@@ -15,6 +15,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
15
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
16
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
17
17
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
18
+ import { COMMAND_PRIORITY_EDITOR, KEY_DOWN_COMMAND } from 'lexical';
18
19
  import { Children, memo, useEffect, useLayoutEffect, useRef, useState } from 'react';
19
20
  import { LexicalErrorBoundary } from "../../../editor-kernel/react/LexicalErrorBoundary";
20
21
  import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
@@ -96,6 +97,29 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
96
97
  onChange === null || onChange === void 0 || onChange(editor);
97
98
  });
98
99
  }, [editor, type, content, onChange, isInitialized]);
100
+ useEffect(function () {
101
+ if (editor && onPressEnter) {
102
+ return editor.registerHighCommand(KEY_DOWN_COMMAND, function (event) {
103
+ if (event.key === 'Enter' && !event.isComposing && onPressEnter({
104
+ editor: editor,
105
+ event: event
106
+ })) {
107
+ event.preventDefault();
108
+ return true; // Indicate that the event has been handled
109
+ }
110
+
111
+ //
112
+ if (onKeyDown !== null && onKeyDown !== void 0 && onKeyDown({
113
+ editor: editor,
114
+ event: event
115
+ })) {
116
+ event.preventDefault();
117
+ return true; // Indicate that the event has been handled
118
+ }
119
+ return false; // Allow other handlers to process the event
120
+ }, COMMAND_PRIORITY_EDITOR);
121
+ }
122
+ }, [editor, onPressEnter, onKeyDown]);
99
123
  useEffect(function () {
100
124
  if (autoFocus && editorContainerRef.current) {
101
125
  editorContainerRef.current.focus();
@@ -131,22 +155,6 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
131
155
  event: event
132
156
  });
133
157
  };
134
- var handleKeyDown = function handleKeyDown(event) {
135
- var isComposing = event.nativeEvent.isComposing;
136
- if (event.key === 'Enter' && !isComposing &&
137
- // Regular Enter key handling
138
- onPressEnter) {
139
- onPressEnter({
140
- editor: editor,
141
- event: event
142
- });
143
- }
144
- // Call the optional onKeyDown handler
145
- onKeyDown === null || onKeyDown === void 0 || onKeyDown({
146
- editor: editor,
147
- event: event
148
- });
149
- };
150
158
  return /*#__PURE__*/_jsxs("div", {
151
159
  className: cx(styles.root, styles.variant, className),
152
160
  style: style,
@@ -157,7 +165,6 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
157
165
  onCompositionStart: handleCompositionStart,
158
166
  onContextMenu: handleContextMenu,
159
167
  onFocus: handleFocus,
160
- onKeyDown: handleKeyDown,
161
168
  ref: editorContainerRef,
162
169
  style: {
163
170
  outline: 'none'
@@ -1,4 +1,4 @@
1
- import type { CSSProperties, CompositionEvent, FocusEvent, KeyboardEvent, MouseEvent, ReactElement, ReactNode } from 'react';
1
+ import type { CSSProperties, CompositionEvent, FocusEvent, MouseEvent, ReactElement, ReactNode } from 'react';
2
2
  import type { CommonPluginOptions } from "..";
3
3
  import type { IEditor } from "../../../types";
4
4
  export interface ReactEditorContentProps {
@@ -33,12 +33,12 @@ export interface ReactPlainTextProps {
33
33
  }) => void;
34
34
  onKeyDown?: (props: {
35
35
  editor: IEditor;
36
- event: KeyboardEvent<HTMLDivElement>;
37
- }) => void;
36
+ event: KeyboardEvent;
37
+ }) => boolean | void;
38
38
  onPressEnter?: (props: {
39
39
  editor: IEditor;
40
- event: KeyboardEvent<HTMLDivElement>;
41
- }) => void;
40
+ event: KeyboardEvent;
41
+ }) => boolean | void;
42
42
  style?: CSSProperties;
43
43
  theme?: CommonPluginOptions['theme'] & {
44
44
  fontSize?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.5.7",
3
+ "version": "1.5.8",
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",