@lobehub/editor 1.34.2 → 1.34.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.
@@ -4,5 +4,5 @@ import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref) {
5
5
  var css = _ref.css,
6
6
  token = _ref.token;
7
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n .toolbar {\n position: absolute;\n z-index: 10;\n inset-block-start: -4px;\n inset-inline-end: 0;\n transform: translateY(-100%);\n\n opacity: 0;\n }\n\n &:hover {\n .toolbar {\n opacity: 1;\n }\n }\n\n &[data-diff-type='add'] .content {\n position: relative;\n padding-inline-start: 8px;\n border-inline-start: 3px solid ", ";\n background-color: ", ";\n }\n\n &[data-diff-type='remove'] .content {\n position: relative;\n padding-inline-start: 8px;\n border-inline-start: 3px solid ", ";\n background-color: ", ";\n }\n\n &[data-diff-type='modify'] .content {\n position: relative;\n\n /* first child: original (deleted) */\n > *:first-child {\n opacity: 0.6;\n }\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n "])), token.colorSuccess, token.colorSuccessBg, token.colorError, token.colorErrorBg, token.colorTextQuaternary);
7
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n .toolbar {\n position: absolute;\n z-index: 10;\n inset-block-end: -4px;\n inset-inline-end: 0;\n transform: translateY(100%);\n\n opacity: 0;\n }\n\n &:hover {\n .toolbar {\n opacity: 1;\n }\n }\n\n &[data-diff-type='add'] .content {\n position: relative;\n margin-block: 4px;\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n }\n\n &[data-diff-type='remove'] .content {\n position: relative;\n margin-block: 4px;\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n }\n\n &[data-diff-type='modify'] .content {\n position: relative;\n margin-block: 4px;\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n "])), token.colorSuccess, token.colorError, token.colorTextQuaternary, token.colorWarning, token.colorTextQuaternary);
8
8
  });
@@ -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";
@@ -6,10 +6,11 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { mergeRegister } from '@lexical/utils';
8
8
  import { Block } from '@lobehub/ui';
9
- import { $getSelection, BLUR_COMMAND, COMMAND_PRIORITY_LOW, SELECTION_CHANGE_COMMAND, getDOMSelection } from 'lexical';
9
+ import { $getSelection, COMMAND_PRIORITY_LOW, SELECTION_CHANGE_COMMAND, getDOMSelection } from 'lexical';
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) {
@@ -113,9 +116,6 @@ export var ReactToolbarPlugin = function ReactToolbarPlugin(_ref) {
113
116
  $updateTextFormatFloatingToolbar(editor);
114
117
  }
115
118
  return false;
116
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(BLUR_COMMAND, function () {
117
- $hideFloatingToolbar();
118
- return false;
119
119
  }, COMMAND_PRIORITY_LOW), function () {
120
120
  if (rootElement) {
121
121
  rootElement.removeEventListener('mousedown', handleMouseDown);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.34.2",
3
+ "version": "1.34.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",