11import "./styles/index.scss" ;
22
33import { Menu } from "@arco-design/web-react" ;
4- import { useMemoizedFn } from "ahooks" ;
54import type { EditorKit } from "doc-editor-core" ;
65import type { TextElement } from "doc-editor-delta" ;
76import { Editor } from "doc-editor-delta" ;
87import { ReactEditor } from "doc-editor-delta" ;
98import { EVENT_ENUM } from "doc-editor-utils" ;
10- import { omit } from "doc-editor-utils" ;
9+ import { Collection } from "doc-editor-utils" ;
1110import type { FC } from "react" ;
1211import React , { useEffect , useMemo , useRef , useState } from "react" ;
1312
1413import { FONT_BASE_KEY } from "../font-base/types" ;
1514import { HYPER_LINK_KEY } from "../hyper-link/types" ;
1615import { LINE_HEIGHT_KEY } from "../line-height/types" ;
16+ import { useMemoFn } from "../shared/hooks/preset" ;
1717import { MenuItems } from "./components/menu" ;
1818import { execSelectMarks , getSelectionRect , maskMenuToolBar , Portal } from "./utils/selection" ;
1919
@@ -32,11 +32,13 @@ export const MenuToolBar: FC<{
3232 const toolbarRef = useRef < HTMLDivElement > ( null ) ;
3333 const [ selectedMarks , setSelectedMarks ] = useState < string [ ] > ( [ ] ) ;
3434
35- const wakeUpToolbar = useMemoizedFn ( ( wakeUp : boolean ) => {
35+ const wakeUpToolbar = useMemoFn ( ( wakeUp : boolean ) => {
3636 const toolbar = toolbarRef . current ;
3737 if ( ! toolbar ) return void 0 ;
3838 if ( ReactEditor . isFocused ( editor . raw ) && wakeUp ) {
39- setSelectedMarks ( omit ( Object . keys ( Editor . marks ( editor . raw ) || [ ] ) , NOT_INIT_SELECT ) ) ;
39+ setSelectedMarks (
40+ Collection . omit ( Object . keys ( Editor . marks ( editor . raw ) || [ ] ) , NOT_INIT_SELECT )
41+ ) ;
4042 const rect = getSelectionRect ( ) ;
4143 if ( rect ) {
4244 toolbar . style . top = `${ rect . top + window . pageYOffset - TOOLBAR_OFFSET_HEIGHT - 10 } px` ;
@@ -74,29 +76,27 @@ export const MenuToolBar: FC<{
7476 } ;
7577 } , [ editor , wakeUpToolbar , props . readonly ] ) ;
7678
77- const exec = useMemoizedFn (
78- ( param : string , event : React . MouseEvent < HTMLDivElement , MouseEvent > ) => {
79- const [ key , extraKey ] = param . split ( "." ) ;
80- const marks = Editor . marks ( editor . raw ) ;
81- const position = { left : 0 , top : 0 } ;
82- const toolbar = toolbarRef . current ;
83- setSelectedMarks ( execSelectMarks ( key , selectedMarks , MUTEX_SELECT ) ) ;
84- if ( toolbar ) {
85- position . top = toolbar . offsetTop + toolbar . offsetHeight / 2 ;
86- position . left = toolbar . offsetLeft + toolbar . offsetWidth / 2 ;
87- }
88- const result = props . editor . command . exec ( key , {
89- extraKey,
90- event,
91- position,
92- marks : marks as TextElement ,
93- } ) ;
94- if ( result ) {
95- keepStatus . current = true ;
96- result . then ( ( ) => ( keepStatus . current = false ) ) ;
97- }
79+ const exec = useMemoFn ( ( param : string , event : React . MouseEvent < HTMLDivElement , MouseEvent > ) => {
80+ const [ key , extraKey ] = param . split ( "." ) ;
81+ const marks = Editor . marks ( editor . raw ) ;
82+ const position = { left : 0 , top : 0 } ;
83+ const toolbar = toolbarRef . current ;
84+ setSelectedMarks ( execSelectMarks ( key , selectedMarks , MUTEX_SELECT ) ) ;
85+ if ( toolbar ) {
86+ position . top = toolbar . offsetTop + toolbar . offsetHeight / 2 ;
87+ position . left = toolbar . offsetLeft + toolbar . offsetWidth / 2 ;
9888 }
99- ) ;
89+ const result = props . editor . command . exec ( key , {
90+ extraKey,
91+ event,
92+ position,
93+ marks : marks as TextElement ,
94+ } ) ;
95+ if ( result ) {
96+ keepStatus . current = true ;
97+ result . then ( ( ) => ( keepStatus . current = false ) ) ;
98+ }
99+ } ) ;
100100
101101 const HoverMenu = useMemo (
102102 ( ) => (
0 commit comments