@lobehub/editor 1.4.7 → 1.5.1

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 (98) 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 +11 -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/FloatMenu/FloatMenu.d.ts +4 -0
  79. package/es/react/FloatMenu/FloatMenu.js +49 -0
  80. package/es/react/FloatMenu/index.d.ts +2 -0
  81. package/es/react/FloatMenu/index.js +2 -0
  82. package/es/react/FloatMenu/type.d.ts +19 -0
  83. package/es/react/FloatMenu/type.js +1 -0
  84. package/es/react/SlashMenu/SlashMenu.js +32 -48
  85. package/es/react/SlashMenu/type.d.ts +5 -13
  86. package/es/react/hooks/useEditorState/index.d.ts +4 -0
  87. package/es/react/hooks/useEditorState/index.js +40 -4
  88. package/es/react/index.d.ts +1 -0
  89. package/es/react/index.js +1 -0
  90. package/es/types/global.d.ts +4 -0
  91. package/es/types/kernel.d.ts +26 -1
  92. package/package.json +2 -1
  93. package/es/plugins/common/node/LexicalLineBreakNode.d.ts +0 -31
  94. package/es/plugins/common/node/ParagraphNode.d.ts +0 -7
  95. package/es/plugins/link/react/components/Toolbar.d.ts +0 -7
  96. package/es/plugins/link/react/components/Toolbar.js +0 -63
  97. /package/es/react/{SlashMenu → FloatMenu}/style.d.ts +0 -0
  98. /package/es/react/{SlashMenu → FloatMenu}/style.js +0 -0
@@ -0,0 +1,43 @@
1
+ 'use client';
2
+
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ 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); }
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
+ 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
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ import { useLayoutEffect } from 'react';
10
+ import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
11
+ import { MarkdownPlugin } from "../../markdown";
12
+ import { MathPlugin } from "../plugin";
13
+ import MathEdit from "./component/MathEditor";
14
+ import MathInline from "./component/MathInline";
15
+ import { useStyles } from "./style";
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ export var ReactMathPlugin = function ReactMathPlugin(_ref) {
18
+ var className = _ref.className,
19
+ renderComp = _ref.renderComp,
20
+ theme = _ref.theme;
21
+ var _useLexicalComposerCo = useLexicalComposerContext(),
22
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
23
+ editor = _useLexicalComposerCo2[0];
24
+ var _useStyles = useStyles(),
25
+ styles = _useStyles.styles;
26
+ useLayoutEffect(function () {
27
+ editor.registerPlugin(MarkdownPlugin);
28
+ editor.registerPlugin(MathPlugin, {
29
+ decorator: function decorator(node, editor) {
30
+ return /*#__PURE__*/_jsx(MathInline, {
31
+ className: className,
32
+ editor: editor,
33
+ node: node
34
+ });
35
+ },
36
+ theme: theme || styles
37
+ });
38
+ }, [editor]);
39
+ return /*#__PURE__*/_jsx(MathEdit, {
40
+ renderComp: renderComp
41
+ });
42
+ };
43
+ ReactMathPlugin.displayName = 'ReactMathPlugin';
@@ -0,0 +1,6 @@
1
+ export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
2
+ mathInline: string;
3
+ mathBlock: string;
4
+ mathEditor: import("antd-style").SerializedStyles;
5
+ mathEditorFooter: import("antd-style").SerializedStyles;
6
+ }>;
@@ -0,0 +1,16 @@
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
2
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
+ /* eslint-disable sort-keys-fix/sort-keys-fix */
4
+ import { createStyles } from 'antd-style';
5
+ export var useStyles = createStyles(function (_ref) {
6
+ var cx = _ref.cx,
7
+ css = _ref.css,
8
+ token = _ref.token;
9
+ var latex = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n user-select: none;\n font-size: 1em;\n\n .katex-error {\n color: ", " !important;\n }\n\n .katex-html {\n overflow: auto hidden;\n padding: 3px;\n\n .base {\n margin-block: 0;\n margin-inline: auto;\n }\n\n .tag {\n position: relative !important;\n display: inline-block;\n padding-inline-start: 0.5rem;\n }\n }\n\n &.selected {\n color: #000;\n background: ", ";\n }\n\n &:hover {\n background: ", ";\n }\n\n &.editing {\n background: ", ";\n }\n\n &:has(.katex-error) {\n background: ", ";\n }\n "])), token.colorError, token.yellow, token.colorFillTertiary, token.colorFillTertiary, token.colorErrorBg);
10
+ return {
11
+ mathInline: cx(latex, css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: inline-block;\n "])))),
12
+ mathBlock: cx(latex, css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n overflow: auto hidden;\n display: block;\n white-space: nowrap;\n "])))),
13
+ mathEditor: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 999;\n inset-block-start: -9999px;\n inset-inline-start: -9999px;\n\n width: 320px;\n\n background: ", ";\n\n textarea {\n width: 100%;\n\n font-family: ", ";\n font-size: 13px;\n\n background: transparent !important;\n\n transition: none !important;\n }\n "])), token.colorBgElevated, token.fontFamilyCode),
14
+ mathEditorFooter: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n border-block-start: 1px solid ", ";\n background: ", ";\n "])), token.colorBorderSecondary, token.colorFillQuaternary)
15
+ };
16
+ });
@@ -0,0 +1,13 @@
1
+ import type { FC, ReactNode } from 'react';
2
+ export interface ReactMathPluginProps {
3
+ className?: string;
4
+ /** 自定义渲染组件,接收 MathEditorContent 作为子节点 */
5
+ renderComp?: FC<{
6
+ children: ReactNode;
7
+ open?: boolean;
8
+ }>;
9
+ theme?: {
10
+ mathBlock?: string;
11
+ mathInline?: string;
12
+ };
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -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_HIGH, 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_CRITICAL, 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";
@@ -140,11 +140,11 @@ var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
140
140
  }
141
141
  close();
142
142
  }, [editor, resolution, close]);
143
- useLexicalEditor(function (editor) {
143
+ useLexicalEditor(function () {
144
144
  var pureOptions = options.filter(function (item) {
145
145
  return !('type' in item && item.type === 'divider') && 'key' in item && Boolean(item.key);
146
146
  });
147
- return mergeRegister(editor.registerCommand(KEY_ARROW_DOWN_COMMAND, function (payload) {
147
+ return mergeRegister(editor.registerHighCommand(KEY_ARROW_DOWN_COMMAND, function (payload) {
148
148
  var event = payload;
149
149
  if (pureOptions !== null && pureOptions.length) {
150
150
  var currentIndex = activeKey ? pureOptions.findIndex(function (opt) {
@@ -154,9 +154,10 @@ var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
154
154
  setActiveKey(String(pureOptions[newIndex].key));
155
155
  event.preventDefault();
156
156
  event.stopImmediatePropagation();
157
+ return true;
157
158
  }
158
- return true;
159
- }, COMMAND_PRIORITY_HIGH), editor.registerCommand(KEY_ARROW_UP_COMMAND, function (payload) {
159
+ return false;
160
+ }, COMMAND_PRIORITY_CRITICAL), editor.registerHighCommand(KEY_ARROW_UP_COMMAND, function (payload) {
160
161
  var event = payload;
161
162
  if (pureOptions !== null && pureOptions.length) {
162
163
  var currentIndex = activeKey ? pureOptions.findIndex(function (opt) {
@@ -166,15 +167,16 @@ var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
166
167
  setActiveKey(String(pureOptions[newIndex].key));
167
168
  event.preventDefault();
168
169
  event.stopImmediatePropagation();
170
+ return true;
169
171
  }
170
- return true;
171
- }, COMMAND_PRIORITY_HIGH), editor.registerCommand(KEY_ESCAPE_COMMAND, function (payload) {
172
+ return false;
173
+ }, COMMAND_PRIORITY_CRITICAL), editor.registerHighCommand(KEY_ESCAPE_COMMAND, function (payload) {
172
174
  var event = payload;
173
175
  event.preventDefault();
174
176
  event.stopImmediatePropagation();
175
177
  close();
176
178
  return true;
177
- }, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_TAB_COMMAND, function (payload) {
179
+ }, COMMAND_PRIORITY_CRITICAL), editor.registerHighCommand(KEY_TAB_COMMAND, function (payload) {
178
180
  var event = payload;
179
181
  if (options === null || activeKey === null) {
180
182
  return false;
@@ -189,7 +191,7 @@ var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
189
191
  event.stopImmediatePropagation();
190
192
  handleMenuSelect(selectedOption);
191
193
  return true;
192
- }, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_ENTER_COMMAND, function (event) {
194
+ }, COMMAND_PRIORITY_CRITICAL), editor.registerHighCommand(KEY_ENTER_COMMAND, function (event) {
193
195
  if (options === null || activeKey === null) {
194
196
  return false;
195
197
  }
@@ -205,7 +207,7 @@ var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
205
207
  }
206
208
  handleMenuSelect(selectedOption);
207
209
  return true;
208
- }, COMMAND_PRIORITY_NORMAL));
210
+ }, COMMAND_PRIORITY_CRITICAL));
209
211
  }, [options, activeKey, handleActiveKeyChange, handleMenuSelect]);
210
212
 
211
213
  // Get custom render component if available
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { FloatMenuProps } from './type';
3
+ declare const FloatMenu: import("react").NamedExoticComponent<FloatMenuProps>;
4
+ export default FloatMenu;
@@ -0,0 +1,49 @@
1
+ 'use client';
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
+ 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
+ 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
+ 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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ 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); }
9
+ import { Block } from '@lobehub/ui';
10
+ import { memo } from 'react';
11
+ import { createPortal } from 'react-dom';
12
+ import { Flexbox } from 'react-layout-kit';
13
+ import { useStyles } from "./style";
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ var FloatMenu = /*#__PURE__*/memo(function (_ref) {
16
+ var className = _ref.className,
17
+ style = _ref.style,
18
+ getPopupContainer = _ref.getPopupContainer,
19
+ children = _ref.children,
20
+ _ref$maxHeight = _ref.maxHeight,
21
+ maxHeight = _ref$maxHeight === void 0 ? 'min(50vh, 640px)' : _ref$maxHeight,
22
+ open = _ref.open,
23
+ customStyles = _ref.styles,
24
+ classNames = _ref.classNames;
25
+ var _useStyles = useStyles(),
26
+ cx = _useStyles.cx,
27
+ styles = _useStyles.styles;
28
+ var parent = getPopupContainer();
29
+ if (!parent) return;
30
+ if (!open) return;
31
+ var node = /*#__PURE__*/_jsx(Flexbox, {
32
+ className: cx(styles.root, classNames === null || classNames === void 0 ? void 0 : classNames.root),
33
+ paddingInline: 8,
34
+ style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.root,
35
+ width: '100%',
36
+ children: /*#__PURE__*/_jsx(Block, {
37
+ className: cx(styles.container, className, classNames === null || classNames === void 0 ? void 0 : classNames.container),
38
+ shadow: true,
39
+ style: _objectSpread(_objectSpread({
40
+ maxHeight: maxHeight
41
+ }, style), customStyles === null || customStyles === void 0 ? void 0 : customStyles.container),
42
+ variant: 'outlined',
43
+ children: children
44
+ })
45
+ });
46
+ return /*#__PURE__*/createPortal(node, parent);
47
+ });
48
+ FloatMenu.displayName = 'FloatMenu';
49
+ export default FloatMenu;
@@ -0,0 +1,2 @@
1
+ export { default } from './FloatMenu';
2
+ export * from './type';
@@ -0,0 +1,2 @@
1
+ export { default } from "./FloatMenu";
2
+ export * from "./type";
@@ -0,0 +1,19 @@
1
+ import type { BlockProps } from '@lobehub/ui';
2
+ import type { CSSProperties, ReactNode } from 'react';
3
+ export interface FloatMenuProps {
4
+ children?: ReactNode;
5
+ className?: string;
6
+ classNames?: {
7
+ container?: string;
8
+ root?: string;
9
+ };
10
+ containerProps?: Omit<BlockProps, 'children'>;
11
+ getPopupContainer: () => HTMLDivElement | null;
12
+ maxHeight?: string | number;
13
+ open?: boolean;
14
+ style?: CSSProperties;
15
+ styles?: {
16
+ container?: CSSProperties;
17
+ root?: CSSProperties;
18
+ };
19
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,35 +1,27 @@
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 = ["options", "activeKey", "loading", "onSelect", "classNames", "styles", "menuProps"];
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); }
9
- import { Block, Menu } from '@lobehub/ui';
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; }
12
+ import { Menu } from '@lobehub/ui';
10
13
  import { memo, useCallback } from 'react';
11
- import { createPortal } from 'react-dom';
12
- import { Flexbox } from 'react-layout-kit';
13
- import { useStyles } from "./style";
14
+ import FloatMenu from "../FloatMenu";
14
15
  import { jsx as _jsx } from "react/jsx-runtime";
15
16
  var SlashMenu = /*#__PURE__*/memo(function (_ref) {
16
- var className = _ref.className,
17
- style = _ref.style,
18
- getPopupContainer = _ref.getPopupContainer,
19
- open = _ref.open,
20
- options = _ref.options,
17
+ var options = _ref.options,
21
18
  activeKey = _ref.activeKey,
22
19
  loading = _ref.loading,
23
- _ref$maxHeight = _ref.maxHeight,
24
- maxHeight = _ref$maxHeight === void 0 ? 'min(50vh, 640px)' : _ref$maxHeight,
25
20
  onSelect = _ref.onSelect,
26
- customStyles = _ref.styles,
27
21
  classNames = _ref.classNames,
28
- menuProps = _ref.menuProps;
29
- var _useStyles = useStyles(),
30
- cx = _useStyles.cx,
31
- styles = _useStyles.styles;
32
- var parent = getPopupContainer();
22
+ customStyles = _ref.styles,
23
+ menuProps = _ref.menuProps,
24
+ floatMenuProps = _objectWithoutProperties(_ref, _excluded);
33
25
  var handleMenuClick = useCallback(function (_ref2) {
34
26
  var key = _ref2.key;
35
27
  if (!onSelect) return;
@@ -38,37 +30,29 @@ var SlashMenu = /*#__PURE__*/memo(function (_ref) {
38
30
  });
39
31
  if (option) onSelect === null || onSelect === void 0 || onSelect(option);
40
32
  }, [options, onSelect]);
41
- if (!parent) return;
42
- if (!open) return;
43
- var node = /*#__PURE__*/_jsx(Flexbox, {
44
- className: cx(styles.root, classNames === null || classNames === void 0 ? void 0 : classNames.root),
45
- paddingInline: 8,
46
- style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.root,
47
- width: '100%',
48
- children: /*#__PURE__*/_jsx(Block, {
49
- className: cx(styles.container, className, classNames === null || classNames === void 0 ? void 0 : classNames.container),
50
- gap: 4,
51
- horizontal: true,
52
- shadow: true,
53
- style: _objectSpread(_objectSpread({
54
- maxHeight: maxHeight
55
- }, style), customStyles === null || customStyles === void 0 ? void 0 : customStyles.container),
56
- variant: 'outlined',
57
- children: /*#__PURE__*/_jsx(Menu, _objectSpread({
58
- className: classNames === null || classNames === void 0 ? void 0 : classNames.menu,
59
- items: loading ? [{
60
- disabled: true,
61
- key: 'loading',
62
- label: 'Loading...'
63
- }] : options,
64
- mode: 'inline',
65
- onClick: handleMenuClick,
66
- selectedKeys: activeKey ? [activeKey] : undefined,
67
- style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.menu
68
- }, menuProps))
69
- })
70
- });
71
- return /*#__PURE__*/createPortal(node, parent);
33
+ return /*#__PURE__*/_jsx(FloatMenu, _objectSpread(_objectSpread({
34
+ classNames: {
35
+ container: classNames === null || classNames === void 0 ? void 0 : classNames.container,
36
+ root: classNames === null || classNames === void 0 ? void 0 : classNames.root
37
+ },
38
+ styles: {
39
+ container: customStyles === null || customStyles === void 0 ? void 0 : customStyles.container,
40
+ root: customStyles === null || customStyles === void 0 ? void 0 : customStyles.root
41
+ }
42
+ }, floatMenuProps), {}, {
43
+ children: /*#__PURE__*/_jsx(Menu, _objectSpread({
44
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.menu,
45
+ items: loading ? [{
46
+ disabled: true,
47
+ key: 'loading',
48
+ label: 'Loading...'
49
+ }] : options,
50
+ mode: 'inline',
51
+ onClick: handleMenuClick,
52
+ selectedKeys: activeKey ? [activeKey] : undefined,
53
+ style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.menu
54
+ }, menuProps))
55
+ }));
72
56
  });
73
57
  SlashMenu.displayName = 'SlashMenu';
74
58
  export default SlashMenu;
@@ -1,21 +1,13 @@
1
- import type { BlockProps, MenuProps } from '@lobehub/ui';
1
+ import type { MenuProps } from '@lobehub/ui';
2
2
  import type { CSSProperties } from 'react';
3
3
  import type { MenuRenderProps } from "../../plugins/slash";
4
- export interface SlashMenuProps extends MenuRenderProps {
5
- className?: string;
6
- classNames?: {
7
- container?: string;
4
+ import type { FloatMenuProps } from "../FloatMenu";
5
+ export interface SlashMenuProps extends MenuRenderProps, Omit<FloatMenuProps, 'children'> {
6
+ classNames?: FloatMenuProps['classNames'] & {
8
7
  menu?: string;
9
- root?: string;
10
8
  };
11
- containerProps?: Omit<BlockProps, 'children'>;
12
- getPopupContainer: () => HTMLDivElement | null;
13
- maxHeight?: string | number;
14
9
  menuProps?: MenuProps;
15
- style?: CSSProperties;
16
- styles?: {
17
- container?: CSSProperties;
10
+ styles?: FloatMenuProps['styles'] & {
18
11
  menu?: CSSProperties;
19
- root?: CSSProperties;
20
12
  };
21
13
  }
@@ -15,6 +15,8 @@ export interface EditorState {
15
15
  canRedo: boolean;
16
16
  /** Whether undo operation is available */
17
17
  canUndo: boolean;
18
+ /** Toggle check list */
19
+ checkList: () => void;
18
20
  /** Toggle code formatting */
19
21
  code: () => void;
20
22
  /** Format selection as code block */
@@ -23,6 +25,8 @@ export interface EditorState {
23
25
  codeblockLang: string | null | undefined;
24
26
  /** Insert or toggle link */
25
27
  insertLink: () => void;
28
+ /** Insert math (inline or block based on context) */
29
+ insertMath: () => void;
26
30
  /** Whether cursor is inside a blockquote */
27
31
  isBlockquote: boolean;
28
32
  /** Whether selection has bold formatting */
@@ -9,12 +9,16 @@ import { $isListNode, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND
9
9
  import { $createQuoteNode, $isHeadingNode, $isQuoteNode } from '@lexical/rich-text';
10
10
  import { $setBlocksType } from '@lexical/selection';
11
11
  import { $getNearestNodeOfType, mergeRegister } from '@lexical/utils';
12
- import { $getSelection, $isRangeSelection, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, REDO_COMMAND, SELECTION_CHANGE_COMMAND, UNDO_COMMAND } from 'lexical';
12
+ import { $createNodeSelection, $getSelection, $isParagraphNode, $isRangeSelection, $setSelection, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, REDO_COMMAND, SELECTION_CHANGE_COMMAND, UNDO_COMMAND } from 'lexical';
13
13
  import { useCallback, useEffect, useMemo, useState } from 'react';
14
+ import { INSERT_CODEINLINE_COMMAND } from "../../../plugins/code";
15
+ import { $isSelectionInCodeInline } from "../../../plugins/code/node/code";
14
16
  import { UPDATE_CODEBLOCK_LANG } from "../../../plugins/codeblock";
15
17
  import { $isRootTextContentEmpty } from "../../../plugins/common/utils";
16
18
  import { $isLinkNode, TOGGLE_LINK_COMMAND } from "../../../plugins/link/node/LinkNode";
17
19
  import { sanitizeUrl } from "../../../plugins/link/utils";
20
+ import { INSERT_CHECK_LIST_COMMAND } from "../../../plugins/list";
21
+ import { $createMathBlockNode, $createMathInlineNode } from "../../../plugins/math/node";
18
22
  import { $findTopLevelElement, formatParagraph, getSelectedNode } from "./utils";
19
23
 
20
24
  /**
@@ -101,7 +105,7 @@ export function useEditorState(editor) {
101
105
  setIsItalic(selection.hasFormat('italic'));
102
106
  setIsUnderline(selection.hasFormat('underline'));
103
107
  setIsStrikethrough(selection.hasFormat('strikethrough'));
104
- setIsCode(selection.hasFormat('code'));
108
+ setIsCode($isSelectionInCodeInline(lexicalEditor));
105
109
  var anchorNode = selection.anchor.getNode();
106
110
  var focusNode = selection.focus.getNode();
107
111
  var element = $findTopLevelElement(anchorNode);
@@ -161,7 +165,7 @@ export function useEditorState(editor) {
161
165
  formatText('italic');
162
166
  }, [formatText]);
163
167
  var code = useCallback(function () {
164
- formatText('code');
168
+ editor === null || editor === void 0 || editor.dispatchCommand(INSERT_CODEINLINE_COMMAND, undefined);
165
169
  }, [formatText]);
166
170
  var bulletList = useCallback(function () {
167
171
  if (blockType !== 'bullet') {
@@ -177,6 +181,13 @@ export function useEditorState(editor) {
177
181
  formatParagraph(editor === null || editor === void 0 ? void 0 : editor.getLexicalEditor());
178
182
  }
179
183
  }, [blockType, editor]);
184
+ var checkList = useCallback(function () {
185
+ if (blockType !== 'check') {
186
+ editor === null || editor === void 0 || editor.dispatchCommand(INSERT_CHECK_LIST_COMMAND, undefined);
187
+ } else {
188
+ formatParagraph(editor === null || editor === void 0 ? void 0 : editor.getLexicalEditor());
189
+ }
190
+ }, [blockType, editor]);
180
191
  var codeblock = useCallback(function () {
181
192
  if (blockType !== 'code') {
182
193
  var _editor$getLexicalEdi2;
@@ -237,6 +248,29 @@ export function useEditorState(editor) {
237
248
  editor === null || editor === void 0 || (_editor$getLexicalEdi5 = editor.getLexicalEditor()) === null || _editor$getLexicalEdi5 === void 0 || _editor$getLexicalEdi5.dispatchCommand(TOGGLE_LINK_COMMAND, null);
238
249
  }
239
250
  }, [editor, isLink]);
251
+ var insertMath = useCallback(function () {
252
+ var _editor$getLexicalEdi6;
253
+ editor === null || editor === void 0 || (_editor$getLexicalEdi6 = editor.getLexicalEditor()) === null || _editor$getLexicalEdi6 === void 0 || _editor$getLexicalEdi6.update(function () {
254
+ var selection = $getSelection();
255
+ if ($isRangeSelection(selection)) {
256
+ // 检查当前上下文来决定插入行内还是块级数学公式
257
+ var anchorNode = selection.anchor.getNode();
258
+ var element = $findTopLevelElement(anchorNode);
259
+
260
+ // 判断是否应该插入块级数学公式的条件(默认插入 inline):
261
+ // 1. 在空段落开头(没有任何内容的段落)
262
+ // 2. 选择了整行内容
263
+ var shouldInsertBlock = $isParagraphNode(element) && selection.isCollapsed() && selection.anchor.offset === 0 && element.getTextContentSize() === 0 || !selection.isCollapsed() && selection.anchor.offset === 0 && selection.focus.offset === element.getTextContentSize();
264
+ var mathNode = shouldInsertBlock ? $createMathBlockNode('') : $createMathInlineNode('');
265
+ selection.insertNodes([mathNode]);
266
+
267
+ // 选择新创建的数学节点
268
+ var nodeSelection = $createNodeSelection();
269
+ nodeSelection.add(mathNode.getKey());
270
+ $setSelection(nodeSelection);
271
+ }
272
+ });
273
+ }, [editor]);
240
274
  useEffect(function () {
241
275
  if (!editor) return;
242
276
  var lexicalEditor = editor.getLexicalEditor();
@@ -276,10 +310,12 @@ export function useEditorState(editor) {
276
310
  bulletList: bulletList,
277
311
  canRedo: canRedo,
278
312
  canUndo: canUndo,
313
+ checkList: checkList,
279
314
  code: code,
280
315
  codeblock: codeblock,
281
316
  codeblockLang: codeblockLang,
282
317
  insertLink: insertLink,
318
+ insertMath: insertMath,
283
319
  isBlockquote: isBlockquote,
284
320
  isBold: isBold,
285
321
  isCode: isCode,
@@ -297,5 +333,5 @@ export function useEditorState(editor) {
297
333
  undo: undo,
298
334
  updateCodeblockLang: updateCodeblockLang
299
335
  };
300
- }, [blockType, bold, bulletList, canRedo, canUndo, code, codeblockLang, blockquote, codeblock, insertLink, isBold, isCode, isEmpty, isBlockquote, isCodeblock, isItalic, isSelected, isStrikethrough, isUnderline, italic, numberList, redo, strikethrough, underline, undo, updateCodeblockLang]);
336
+ }, [blockType, canRedo, canUndo, codeblockLang, isBold, isCode, isEmpty, isBlockquote, isCodeblock, isItalic, isSelected, isStrikethrough, isUnderline, italic]);
301
337
  }
@@ -4,6 +4,7 @@ export { type ChatInputActionEvent, default as ChatInputActions, type ChatInputA
4
4
  export { default as CodeLanguageSelect, type CodeLanguageSelectProps } from './CodeLanguageSelect';
5
5
  export { default as Editor, type EditorProps, withProps } from './Editor';
6
6
  export { EditorProvider, type EditorProviderConfig, type EditorProviderProps, useEditorContent, } from './EditorProvider';
7
+ export { default as FloatMenu, type FloatMenuProps } from './FloatMenu';
7
8
  export { useEditor } from './hooks/useEditor';
8
9
  export { type EditorState, useEditorState } from './hooks/useEditorState';
9
10
  export { default as SendButton, type SendButtonProps } from './SendButton';
package/es/react/index.js CHANGED
@@ -4,6 +4,7 @@ export { default as ChatInputActions } from "./ChatInputActions";
4
4
  export { default as CodeLanguageSelect } from "./CodeLanguageSelect";
5
5
  export { default as Editor, withProps } from "./Editor";
6
6
  export { EditorProvider, useEditorContent } from "./EditorProvider";
7
+ export { default as FloatMenu } from "./FloatMenu";
7
8
  export { useEditor } from "./hooks/useEditor";
8
9
  export { useEditorState } from "./hooks/useEditorState";
9
10
  export { default as SendButton } from "./SendButton";
@@ -18,3 +18,7 @@ declare module '*.svg' {
18
18
  const content: any;
19
19
  export default content;
20
20
  }
21
+
22
+ declare namespace globalThis {
23
+ let __DEV__: boolean | undefined;
24
+ }
@@ -1,6 +1,8 @@
1
- import type { CommandPayloadType, DecoratorNode, LexicalCommand, LexicalEditor, LexicalNodeConfig } from 'lexical';
1
+ import type { CommandListener, CommandListenerPriority, CommandPayloadType, DecoratorNode, LexicalCommand, LexicalEditor, LexicalNodeConfig } from 'lexical';
2
2
  import type DataSource from "../editor-kernel/data-source";
3
3
  import { ILocaleKeys } from './locale';
4
+ export type Commands = Map<LexicalCommand<unknown>, Array<Set<CommandListener<unknown>>>>;
5
+ export type CommandsClean = Map<LexicalCommand<unknown>, () => void>;
4
6
  /**
5
7
  * Service ID type
6
8
  */
@@ -95,6 +97,29 @@ export interface IEditor {
95
97
  * @param listener
96
98
  */
97
99
  once<T extends keyof IKernelEventMap>(event: T, listener: IKernelEventMap[T]): this;
100
+ /**
101
+ * Extends the priority level of Lexical commands.
102
+ * Registers a listener that triggers when the provided command is dispatched
103
+ * via {@link LexicalEditor.dispatch}. The listener is triggered based on its priority.
104
+ * Listeners with higher priority can "intercept" commands and prevent them
105
+ * from propagating to other handlers by returning true.
106
+ *
107
+ * Listeners are always invoked within {@link LexicalEditor.update} and can call dollar functions.
108
+ *
109
+ * Listeners registered at the same priority level will deterministically run
110
+ * in the order of registration.
111
+ *
112
+ * @param command - The command that triggers the callback.
113
+ * @param listener - The function executed when the command is dispatched.
114
+ * @param priority - The relative priority of the listener. 0 | 1 | 2 | 3 | 4
115
+ * (or {@link COMMAND_PRIORITY_EDITOR} |
116
+ * {@link COMMAND_PRIORITY_LOW} |
117
+ * {@link COMMAND_PRIORITY_NORMAL} |
118
+ * {@link COMMAND_PRIORITY_HIGH} |
119
+ * {@link COMMAND_PRIORITY_CRITICAL})
120
+ * @returns A teardown function to clean up the listener.
121
+ */
122
+ registerHighCommand<P>(command: LexicalCommand<P>, listener: CommandListener<P>, priority: CommandListenerPriority): () => void;
98
123
  /**
99
124
  * Register internationalization text
100
125
  * @param locale Internationalization text object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.4.7",
3
+ "version": "1.5.1",
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",
@@ -46,6 +46,7 @@
46
46
  "eventemitter3": "^5.0.1",
47
47
  "framer-motion": "^12.23.12",
48
48
  "fuse.js": "^7.1.0",
49
+ "katex": "^0.16.22",
49
50
  "lexical": "^0.34.0",
50
51
  "lodash-es": "^4.17.21",
51
52
  "lucide-react": "^0.536.0",
@@ -1,31 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import { DOMConversionMap, DecoratorNode, LexicalNode, SerializedLexicalNode } from 'lexical';
9
- export type SerializedLineBreakNode = SerializedLexicalNode;
10
- declare const LexicalNodeImpl: import("lexical").KlassConstructor<{
11
- new (key?: string | undefined): DecoratorNode<any>;
12
- getType(): string;
13
- clone(_data: unknown): LexicalNode;
14
- importDOM?: (() => DOMConversionMap<any> | null) | undefined;
15
- importJSON(_serializedNode: SerializedLexicalNode): LexicalNode;
16
- transform(): ((node: LexicalNode) => void) | null;
17
- }>;
18
- /** @noInheritDoc */
19
- export declare class LineBreakNode extends LexicalNodeImpl {
20
- static getType(): string;
21
- static clone(node: LineBreakNode): LineBreakNode;
22
- getTextContent(): '\n';
23
- createDOM(): HTMLElement;
24
- updateDOM(): false;
25
- isInline(): true;
26
- static importDOM(): DOMConversionMap | null;
27
- static importJSON(serializedLineBreakNode: SerializedLineBreakNode): LineBreakNode;
28
- }
29
- export declare function $createLineBreakNode(): LineBreakNode;
30
- export declare function $isLineBreakNode(node: LexicalNode | null | undefined): node is LineBreakNode;
31
- export {};
@@ -1,7 +0,0 @@
1
- import { EditorConfig, ElementDOMSlot, ParagraphNode } from 'lexical';
2
- export declare class MParagraphNode extends ParagraphNode {
3
- static getType(): string;
4
- static clone(node: ParagraphNode): ParagraphNode;
5
- createDOM(config: EditorConfig): HTMLElement;
6
- getDOMSlot(element: HTMLElement): ElementDOMSlot<HTMLElement>;
7
- }