@lobehub/editor 1.0.2 → 1.0.4

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.
@@ -1,7 +1,7 @@
1
1
  import { $isCodeHighlightNode, $isCodeNode } from '@lexical/code';
2
2
  import { $isHeadingNode } from '@lexical/rich-text';
3
3
  import { mergeRegister } from '@lexical/utils';
4
- import { $createNodeSelection, $createParagraphNode, $getRoot, $getSelection, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isNodeSelection, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, $setSelection, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_NORMAL, FORMAT_TEXT_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DOWN_COMMAND, isModifierMatch } from 'lexical';
4
+ import { $createNodeSelection, $createParagraphNode, $getRoot, $getSelection, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isNodeSelection, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, $setSelection, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_NORMAL, FORMAT_TEXT_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DOWN_COMMAND, isModifierMatch } from 'lexical';
5
5
  import { CONTROL_OR_META, CONTROL_OR_META_AND_SHIFT } from "../../../common/sys";
6
6
  function resolveElement(element, isBackward, focusOffset) {
7
7
  var parent = element.getParent();
@@ -156,7 +156,7 @@ export function registerRichKeydown(editor) {
156
156
  }
157
157
  }
158
158
  return false;
159
- }, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_ARROW_DOWN_COMMAND, function (event) {
159
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_DOWN_COMMAND, function (event) {
160
160
  var selection = $getSelection();
161
161
  if ($isNodeSelection(selection)) {
162
162
  // If selection is on a node, let's try and move selection
@@ -199,7 +199,7 @@ export function registerRichKeydown(editor) {
199
199
  }
200
200
  }
201
201
  return false;
202
- }, COMMAND_PRIORITY_CRITICAL), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, function (event) {
202
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, function (event) {
203
203
  var selection = $getSelection();
204
204
  if ($isRangeSelection(selection)) {
205
205
  var _focusNode$getChildAt;
@@ -226,5 +226,5 @@ export function registerRichKeydown(editor) {
226
226
  }
227
227
  }
228
228
  return false;
229
- }, COMMAND_PRIORITY_CRITICAL));
229
+ }, COMMAND_PRIORITY_EDITOR));
230
230
  }
@@ -15,7 +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 { Children, memo, useEffect, useLayoutEffect, useRef } from 'react';
18
+ import { Children, memo, useEffect, useLayoutEffect, useRef, useState } from 'react';
19
19
  import { LexicalErrorBoundary } from "../../../editor-kernel/react/LexicalErrorBoundary";
20
20
  import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
21
21
  import { useDecorators } from "../../../editor-kernel/react/useDecorators";
@@ -58,6 +58,10 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
58
58
  }),
59
59
  cx = _useStyles.cx,
60
60
  styles = _useStyles.styles;
61
+ var _useState = useState(false),
62
+ _useState2 = _slicedToArray(_useState, 2),
63
+ isInitialized = _useState2[0],
64
+ setIsInitialized = _useState2[1];
61
65
  var _Children$only = Children.only(children),
62
66
  _Children$only$props = _Children$only.props,
63
67
  type = _Children$only$props.type,
@@ -72,15 +76,18 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
72
76
  useEffect(function () {
73
77
  var _editor$getLexicalEdi;
74
78
  var container = editorContainerRef.current;
75
- if (container) {
79
+ if (container && !isInitialized) {
76
80
  // Initialize the editor
77
81
  editor.setRootElement(container);
82
+
83
+ // Set initial document content only once
84
+ editor.setDocument(type, content);
85
+ setIsInitialized(true);
78
86
  }
79
- editor.setDocument(type, content);
80
87
  return (_editor$getLexicalEdi = editor.getLexicalEditor()) === null || _editor$getLexicalEdi === void 0 ? void 0 : _editor$getLexicalEdi.registerUpdateListener(function () {
81
88
  onChange === null || onChange === void 0 || onChange(editor);
82
89
  });
83
- }, [editor, type, content, onChange]);
90
+ }, [editor, type, content, onChange, isInitialized]);
84
91
  return /*#__PURE__*/_jsxs("div", {
85
92
  className: cx(styles.root, styles.variant, className),
86
93
  style: style,
@@ -7,7 +7,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
7
7
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
8
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
9
  import { mergeRegister } from '@lexical/utils';
10
- import { COMMAND_PRIORITY_NORMAL, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND } from 'lexical';
10
+ import { COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_NORMAL, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND } from 'lexical';
11
11
  import { Children, useCallback, useLayoutEffect, useRef, useState } from 'react';
12
12
  import { useLexicalEditor } from "../../../editor-kernel/react";
13
13
  import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
@@ -156,7 +156,7 @@ var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
156
156
  event.stopImmediatePropagation();
157
157
  }
158
158
  return true;
159
- }, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_ARROW_UP_COMMAND, function (payload) {
159
+ }, COMMAND_PRIORITY_HIGH), editor.registerCommand(KEY_ARROW_UP_COMMAND, function (payload) {
160
160
  var event = payload;
161
161
  if (pureOptions !== null && pureOptions.length) {
162
162
  var currentIndex = activeKey ? pureOptions.findIndex(function (opt) {
@@ -168,7 +168,7 @@ var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
168
168
  event.stopImmediatePropagation();
169
169
  }
170
170
  return true;
171
- }, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_ESCAPE_COMMAND, function (payload) {
171
+ }, COMMAND_PRIORITY_HIGH), editor.registerCommand(KEY_ESCAPE_COMMAND, function (payload) {
172
172
  var event = payload;
173
173
  event.preventDefault();
174
174
  event.stopImmediatePropagation();
@@ -1,11 +1,14 @@
1
1
  'use client';
2
2
 
3
3
  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); }
4
+ var _excluded = ["maxHeight", "className", "children", "footer", "header", "style", "slashMenuRef", "classNames", "fullscreen", "styles"];
4
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
7
  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; }
7
8
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
9
  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); }
10
+ 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; }
11
+ 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; }
9
12
  import { memo } from 'react';
10
13
  import { Flexbox } from 'react-layout-kit';
11
14
  import { useStyles } from "./style";
@@ -19,23 +22,30 @@ var ChatInput = /*#__PURE__*/memo(function (_ref) {
19
22
  footer = _ref.footer,
20
23
  header = _ref.header,
21
24
  style = _ref.style,
22
- slashMenuRef = _ref.slashMenuRef;
25
+ slashMenuRef = _ref.slashMenuRef,
26
+ classNames = _ref.classNames,
27
+ fullscreen = _ref.fullscreen,
28
+ customStyles = _ref.styles,
29
+ rest = _objectWithoutProperties(_ref, _excluded);
23
30
  var _useStyles = useStyles(),
24
31
  cx = _useStyles.cx,
25
32
  styles = _useStyles.styles;
26
- return /*#__PURE__*/_jsxs(Flexbox, {
33
+ return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
27
34
  className: cx(styles.container, className),
35
+ height: fullscreen ? '100%' : undefined,
28
36
  style: _objectSpread({
29
- maxHeight: maxHeight
37
+ maxHeight: fullscreen ? undefined : maxHeight
30
38
  }, style),
31
- width: '100%',
39
+ width: '100%'
40
+ }, rest), {}, {
32
41
  children: [slashMenuRef && /*#__PURE__*/_jsx("div", {
33
42
  ref: slashMenuRef
34
43
  }), header, /*#__PURE__*/_jsx("div", {
35
- className: styles.editor,
44
+ className: cx(styles.editor, classNames === null || classNames === void 0 ? void 0 : classNames.body),
45
+ style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.body,
36
46
  children: children
37
47
  }), footer]
38
- });
48
+ }));
39
49
  });
40
50
  ChatInput.displayName = 'ChatInput';
41
51
  export default ChatInput;
@@ -1,10 +1,15 @@
1
1
  import type { CSSProperties, ReactNode, Ref } from 'react';
2
- export interface ChatInputProps {
3
- children?: ReactNode;
4
- className?: string;
2
+ import { FlexboxProps } from 'react-layout-kit';
3
+ export interface ChatInputProps extends FlexboxProps {
4
+ classNames?: {
5
+ body?: string;
6
+ };
5
7
  footer?: ReactNode;
8
+ fullscreen?: boolean;
6
9
  header?: ReactNode;
7
10
  maxHeight?: string | number;
8
11
  slashMenuRef?: Ref<HTMLDivElement>;
9
- style?: CSSProperties;
12
+ styles?: {
13
+ body?: CSSProperties;
14
+ };
10
15
  }
@@ -1,5 +1,14 @@
1
1
  'use client';
2
2
 
3
+ 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); }
4
+ var _excluded = ["className", "style", "left", "right"];
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ 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; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ 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); }
10
+ 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; }
11
+ 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; }
3
12
  import { memo } from 'react';
4
13
  import { Flexbox } from 'react-layout-kit';
5
14
  import { useStyles } from "./style";
@@ -8,20 +17,22 @@ var ChatInputActionBar = /*#__PURE__*/memo(function (_ref) {
8
17
  var className = _ref.className,
9
18
  style = _ref.style,
10
19
  left = _ref.left,
11
- right = _ref.right;
20
+ right = _ref.right,
21
+ rest = _objectWithoutProperties(_ref, _excluded);
12
22
  var _useStyles = useStyles(),
13
23
  cx = _useStyles.cx,
14
24
  styles = _useStyles.styles;
15
- return /*#__PURE__*/_jsxs(Flexbox, {
25
+ return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
16
26
  align: 'center',
17
27
  className: cx(styles.container, className),
18
28
  gap: 4,
19
29
  horizontal: true,
20
30
  justify: 'space-between',
21
31
  padding: 4,
22
- style: style,
32
+ style: style
33
+ }, rest), {}, {
23
34
  children: [left, right]
24
- });
35
+ }));
25
36
  });
26
37
  ChatInputActionBar.displayName = 'ChatInputActionBar';
27
38
  export default ChatInputActionBar;
@@ -1,7 +1,6 @@
1
- import type { CSSProperties, ReactNode } from 'react';
2
- export interface ChatInputActionBarProps {
3
- className?: string;
1
+ import type { ReactNode } from 'react';
2
+ import { FlexboxProps } from 'react-layout-kit';
3
+ export interface ChatInputActionBarProps extends Omit<FlexboxProps, 'children'> {
4
4
  left?: ReactNode;
5
5
  right?: ReactNode;
6
- style?: CSSProperties;
7
6
  }
@@ -9,7 +9,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
9
9
  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); }
10
10
  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; }
11
11
  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; }
12
- import { createElement, memo } from 'react';
12
+ import { createElement, memo, useMemo } from 'react';
13
13
  import { ReactEditor } from "../../editor-kernel/react/react-editor";
14
14
  import { ReactEditorContent, ReactPlainText } from "../../plugins/common";
15
15
  import { ReactMentionPlugin } from "../../plugins/mention";
@@ -32,28 +32,17 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
32
32
  mentionOption = _ref$mentionOption === void 0 ? {} : _ref$mentionOption,
33
33
  variant = _ref.variant,
34
34
  theme = _ref.theme,
35
- children = _ref.children;
35
+ children = _ref.children,
36
+ _ref$type = _ref.type,
37
+ type = _ref$type === void 0 ? 'json' : _ref$type;
36
38
  var _useEditorContent = useEditorContent(),
37
39
  config = _useEditorContent.config;
38
40
  var enableSlash = Boolean((slashOption === null || slashOption === void 0 ? void 0 : slashOption.items) && slashOption.items.length > 0);
39
41
  var enableMention = Boolean((mentionOption === null || mentionOption === void 0 ? void 0 : mentionOption.items) && mentionOption.items.length > 0);
40
42
  var markdownWriter = mentionOption.markdownWriter,
41
43
  restMentionOption = _objectWithoutProperties(mentionOption, _excluded);
42
- return /*#__PURE__*/_jsxs(ReactEditor, {
43
- config: config,
44
- editorRef: editorRef,
45
- children: [/*#__PURE__*/_jsx(ReactPlainText, {
46
- className: className,
47
- onChange: onChange,
48
- style: style,
49
- theme: theme,
50
- variant: variant,
51
- children: /*#__PURE__*/_jsx(ReactEditorContent, {
52
- content: content,
53
- placeholder: placeholder,
54
- type: "json"
55
- })
56
- }), plugins.map(function (plugin, index) {
44
+ var memoPlugins = useMemo(function () {
45
+ return plugins.map(function (plugin, index) {
57
46
  var withNoProps = typeof plugin === 'function';
58
47
  if (withNoProps) return /*#__PURE__*/createElement(plugin, {
59
48
  key: index
@@ -61,9 +50,17 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
61
50
  return /*#__PURE__*/createElement(plugin[0], _objectSpread({
62
51
  key: index
63
52
  }, plugin[1]));
64
- }), enableMention && /*#__PURE__*/_jsx(ReactMentionPlugin, {
53
+ });
54
+ }, [plugins]);
55
+ var memoMention = useMemo(function () {
56
+ if (!enableMention) return;
57
+ return /*#__PURE__*/_jsx(ReactMentionPlugin, {
65
58
  markdownWriter: markdownWriter
66
- }), (enableSlash || enableMention) && /*#__PURE__*/_jsxs(ReactSlashPlugin, {
59
+ });
60
+ }, [enableMention, markdownWriter]);
61
+ var memoSlash = useMemo(function () {
62
+ if (!enableSlash && !enableMention) return null;
63
+ return /*#__PURE__*/_jsxs(ReactSlashPlugin, {
67
64
  children: [enableSlash ? /*#__PURE__*/_jsx(ReactSlashOption, _objectSpread({
68
65
  maxLength: 1,
69
66
  trigger: "/"
@@ -71,6 +68,22 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
71
68
  maxLength: 6,
72
69
  trigger: "@"
73
70
  }, restMentionOption)) : undefined]
71
+ });
72
+ }, [enableSlash, enableMention, slashOption, restMentionOption]);
73
+ return /*#__PURE__*/_jsxs(ReactEditor, {
74
+ config: config,
75
+ editorRef: editorRef,
76
+ children: [memoPlugins, memoSlash, memoMention, /*#__PURE__*/_jsx(ReactPlainText, {
77
+ className: className,
78
+ onChange: onChange,
79
+ style: style,
80
+ theme: theme,
81
+ variant: variant,
82
+ children: /*#__PURE__*/_jsx(ReactEditorContent, {
83
+ content: content,
84
+ placeholder: placeholder,
85
+ type: type
86
+ })
74
87
  }), children]
75
88
  });
76
89
  });
@@ -7,14 +7,12 @@ export type EditorPlugin = FC<any> | [FC<any>, Record<string, any>];
7
7
  interface MentionOption extends Partial<ReactSlashOptionProps> {
8
8
  markdownWriter?: ReactMentionPluginProps['markdownWriter'];
9
9
  }
10
- export interface EditorProps {
10
+ export interface EditorProps extends Partial<ReactEditorContentProps> {
11
11
  children?: ReactNode;
12
12
  className?: string;
13
- content?: ReactEditorContentProps['content'];
14
13
  editorRef?: Ref<IEditor>;
15
14
  mentionOption?: MentionOption;
16
15
  onChange?: (editor: IEditor) => void;
17
- placeholder?: ReactNode;
18
16
  plugins?: EditorPlugin[];
19
17
  slashOption?: Partial<ReactSlashOptionProps>;
20
18
  style?: CSSProperties;
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  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); }
4
- var _excluded = ["type", "menu", "className", "style", "loading", "generating", "size", "shape"];
4
+ var _excluded = ["type", "menu", "className", "style", "loading", "generating", "size", "shape", "onSend", "onStop", "onClick"];
5
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  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; }
@@ -28,12 +28,21 @@ var SendButton = /*#__PURE__*/memo(function (_ref) {
28
28
  _ref$size = _ref.size,
29
29
  size = _ref$size === void 0 ? 32 : _ref$size,
30
30
  shape = _ref.shape,
31
+ onSend = _ref.onSend,
32
+ onStop = _ref.onStop,
33
+ _onClick = _ref.onClick,
31
34
  rest = _objectWithoutProperties(_ref, _excluded);
32
35
  var _useStyles = useStyles(size),
33
36
  cx = _useStyles.cx,
34
37
  styles = _useStyles.styles;
35
38
  if (generating) return /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
36
39
  className: cx(styles.loadingButton, className),
40
+ onClick: function onClick(e) {
41
+ e.stopPropagation();
42
+ e.preventDefault();
43
+ if (onStop) onStop(e);
44
+ if (_onClick) _onClick(e);
45
+ },
37
46
  shape: shape,
38
47
  style: _objectSpread(_objectSpread({}, style), {}, {
39
48
  width: menu ? size * 2 : size
@@ -56,6 +65,12 @@ var SendButton = /*#__PURE__*/memo(function (_ref) {
56
65
  if (!menu) return /*#__PURE__*/_jsx(Button, _objectSpread({
57
66
  className: cx(styles.button, className),
58
67
  icon: /*#__PURE__*/_jsx(SendIcon, {}),
68
+ onClick: function onClick(e) {
69
+ e.stopPropagation();
70
+ e.preventDefault();
71
+ if (onSend) onSend(e);
72
+ if (_onClick) _onClick(e);
73
+ },
59
74
  shape: shape,
60
75
  style: style,
61
76
  type: type
@@ -66,6 +81,12 @@ var SendButton = /*#__PURE__*/memo(function (_ref) {
66
81
  icon: ChevronDownIcon
67
82
  }),
68
83
  menu: menu,
84
+ onClick: function onClick(e) {
85
+ e.stopPropagation();
86
+ e.preventDefault();
87
+ if (onSend) onSend(e);
88
+ if (_onClick) _onClick(e);
89
+ },
69
90
  placement: 'topRight',
70
91
  style: style,
71
92
  type: type
@@ -1,6 +1,8 @@
1
1
  import type { DropdownButtonProps } from 'antd/lib/dropdown';
2
2
  export interface SendButtonProps extends Omit<DropdownButtonProps, 'children' | 'icon' | 'size'> {
3
3
  generating?: boolean;
4
+ onSend?: DropdownButtonProps['onClick'];
5
+ onStop?: DropdownButtonProps['onClick'];
4
6
  shape?: 'default' | 'round';
5
7
  size?: number;
6
8
  }
@@ -22,7 +22,10 @@ var SlashMenu = /*#__PURE__*/memo(function (_ref) {
22
22
  loading = _ref.loading,
23
23
  _ref$maxHeight = _ref.maxHeight,
24
24
  maxHeight = _ref$maxHeight === void 0 ? 'min(50vh, 640px)' : _ref$maxHeight,
25
- onSelect = _ref.onSelect;
25
+ onSelect = _ref.onSelect,
26
+ customStyles = _ref.styles,
27
+ classNames = _ref.classNames,
28
+ menuProps = _ref.menuProps;
26
29
  var _useStyles = useStyles(),
27
30
  cx = _useStyles.cx,
28
31
  styles = _useStyles.styles;
@@ -38,19 +41,21 @@ var SlashMenu = /*#__PURE__*/memo(function (_ref) {
38
41
  if (!parent) return;
39
42
  if (!open) return;
40
43
  var node = /*#__PURE__*/_jsx(Flexbox, {
41
- className: styles.root,
44
+ className: cx(styles.root, classNames === null || classNames === void 0 ? void 0 : classNames.root),
42
45
  paddingInline: 8,
46
+ style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.root,
43
47
  width: '100%',
44
48
  children: /*#__PURE__*/_jsx(Block, {
45
- className: cx(styles.container, className),
49
+ className: cx(styles.container, className, classNames === null || classNames === void 0 ? void 0 : classNames.container),
46
50
  gap: 4,
47
51
  horizontal: true,
48
52
  shadow: true,
49
- style: _objectSpread({
53
+ style: _objectSpread(_objectSpread({
50
54
  maxHeight: maxHeight
51
- }, style),
55
+ }, style), customStyles === null || customStyles === void 0 ? void 0 : customStyles.container),
52
56
  variant: 'outlined',
53
- children: /*#__PURE__*/_jsx(Menu, {
57
+ children: /*#__PURE__*/_jsx(Menu, _objectSpread({
58
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.menu,
54
59
  items: loading ? [{
55
60
  disabled: true,
56
61
  key: 'loading',
@@ -58,8 +63,9 @@ var SlashMenu = /*#__PURE__*/memo(function (_ref) {
58
63
  }] : options,
59
64
  mode: 'inline',
60
65
  onClick: handleMenuClick,
61
- selectedKeys: activeKey ? [activeKey] : undefined
62
- })
66
+ selectedKeys: activeKey ? [activeKey] : undefined,
67
+ style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.menu
68
+ }, menuProps))
63
69
  })
64
70
  });
65
71
  return /*#__PURE__*/createPortal(node, parent);
@@ -1,8 +1,21 @@
1
+ import type { BlockProps, MenuProps } from '@lobehub/ui';
1
2
  import type { CSSProperties } from 'react';
2
- import { MenuRenderProps } from "../../plugins/slash";
3
+ import type { MenuRenderProps } from "../../plugins/slash";
3
4
  export interface SlashMenuProps extends MenuRenderProps {
4
5
  className?: string;
6
+ classNames?: {
7
+ container?: string;
8
+ menu?: string;
9
+ root?: string;
10
+ };
11
+ containerProps?: Omit<BlockProps, 'children'>;
5
12
  getPopupContainer: () => HTMLDivElement | null;
6
13
  maxHeight?: string | number;
14
+ menuProps?: MenuProps;
7
15
  style?: CSSProperties;
16
+ styles?: {
17
+ container?: CSSProperties;
18
+ menu?: CSSProperties;
19
+ root?: CSSProperties;
20
+ };
8
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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",