@lobehub/editor 1.34.1 → 1.34.3

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.
@@ -0,0 +1,8 @@
1
+ import { LexicalCommand, LexicalEditor } from 'lexical';
2
+ export declare const HIDE_TOOLBAR_COMMAND: LexicalCommand<void>;
3
+ export declare const SHOW_TOOLBAR_COMMAND: LexicalCommand<void>;
4
+ export interface ToolbarCommandOptions {
5
+ onHide?: () => void;
6
+ onShow?: () => void;
7
+ }
8
+ export declare function registerToolbarCommand(editor: LexicalEditor, options?: ToolbarCommandOptions): () => void;
@@ -0,0 +1,16 @@
1
+ import { mergeRegister } from '@lexical/utils';
2
+ import { COMMAND_PRIORITY_LOW, createCommand } from 'lexical';
3
+ export var HIDE_TOOLBAR_COMMAND = createCommand();
4
+ export var SHOW_TOOLBAR_COMMAND = createCommand();
5
+ export function registerToolbarCommand(editor, options) {
6
+ var _ref = options || {},
7
+ onHide = _ref.onHide,
8
+ onShow = _ref.onShow;
9
+ return mergeRegister(editor.registerCommand(HIDE_TOOLBAR_COMMAND, function () {
10
+ onHide === null || onHide === void 0 || onHide();
11
+ return true;
12
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(SHOW_TOOLBAR_COMMAND, function () {
13
+ onShow === null || onShow === void 0 || onShow();
14
+ return true;
15
+ }, COMMAND_PRIORITY_LOW));
16
+ }
@@ -1 +1,2 @@
1
+ export * from './command';
1
2
  export * from './react';
@@ -1 +1,2 @@
1
+ export * from "./command";
1
2
  export * from "./react";
@@ -10,6 +10,7 @@ import { $getSelection, COMMAND_PRIORITY_LOW, SELECTION_CHANGE_COMMAND, getDOMSe
10
10
  import { useCallback, useRef } from 'react';
11
11
  import { useLexicalComposerContext, useLexicalEditor } from "../../../editor-kernel/react";
12
12
  import { ILinkService } from "../../link";
13
+ import { HIDE_TOOLBAR_COMMAND, registerToolbarCommand } from "../command";
13
14
  import { getDOMRangeRect } from "../utils/getDOMRangeRect";
14
15
  import { setFloatingElemPosition } from "../utils/setFloatingElemPosition";
15
16
  import { useStyles } from "./style";
@@ -87,7 +88,7 @@ export var ReactToolbarPlugin = function ReactToolbarPlugin(_ref) {
87
88
  }, []);
88
89
  useLexicalEditor(function (editor) {
89
90
  var handleMouseDown = handleMouseDownFactory(function () {
90
- $hideFloatingToolbar();
91
+ editor.dispatchCommand(HIDE_TOOLBAR_COMMAND, undefined);
91
92
  });
92
93
  var handleMouseUp = handleMouseUpFactory(function () {
93
94
  editor.update(function () {
@@ -99,7 +100,9 @@ export var ReactToolbarPlugin = function ReactToolbarPlugin(_ref) {
99
100
  rootElement.addEventListener('mousedown', handleMouseDown);
100
101
  rootElement.addEventListener('mouseup', handleMouseUp);
101
102
  }
102
- return mergeRegister(editor.registerUpdateListener(function (_ref2) {
103
+ return mergeRegister(registerToolbarCommand(editor, {
104
+ onHide: $hideFloatingToolbar
105
+ }), editor.registerUpdateListener(function (_ref2) {
103
106
  var editorState = _ref2.editorState;
104
107
  // Only update when mouse is not pressed
105
108
  if (!isMouseDownRef.current) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.34.1",
3
+ "version": "1.34.3",
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",