1+ import React from 'react' ;
2+
13import { i18n } from '../../i18n/menubar' ;
24import {
35 isBoldActive ,
@@ -10,6 +12,7 @@ import {
1012 isItalicActive ,
1113} from '../../markup/active' ;
1214import {
15+ insertLink ,
1316 insertTable ,
1417 liftListItem ,
1518 sinkListItem ,
@@ -45,19 +48,21 @@ import {ToolbarData} from '../../toolbar/Toolbar';
4548import { ToolbarGroupData } from '../../toolbar/ToolbarGroup' ;
4649import { ToolbarListButtonData } from '../../toolbar/ToolbarListButton' ;
4750import {
51+ ToolbarButtonPopupData ,
4852 ToolbarDataType ,
4953 ToolbarListItemData ,
5054 ToolbarReactComponentData ,
5155 ToolbarSingleItemData ,
5256} from '../../toolbar/types' ;
57+ import { ToolbarLinkPopup } from '../toolbar/custom/ToolbarLinkPopup' ;
5358import { MToolbarColors } from '../toolbar/markup/MToolbarColors' ;
54- import { MToolbarFile } from '../toolbar/markup/MToolbarFile' ;
55- import { MToolbarImage } from '../toolbar/markup/MToolbarImage' ;
56- import { MToolbarLink } from '../toolbar/markup/MToolbarLink' ;
59+ import { MToolbarFilePopup } from '../toolbar/markup/MToolbarFilePopup' ;
60+ import { MToolbarImagePopup } from '../toolbar/markup/MToolbarImagePopup' ;
5761
5862import { ActionName } from './action-names' ;
5963import { icons } from './icons' ;
6064
65+ const noop = ( ) => { } ;
6166const isActiveFn = ( ) => false ;
6267const isEnableFn = ( ) => true ;
6368
@@ -278,11 +283,29 @@ export const mListMoveListConfig: MToolbarListButtonData = {
278283 ] ,
279284} ;
280285
281- export const mLinkButton : MToolbarReactComponentData = {
286+ export const mLinkButton : ToolbarButtonPopupData < CodeEditor > = {
282287 id : ActionName . link ,
283- type : ToolbarDataType . ReactComponent ,
284- component : MToolbarLink ,
285- width : 28 ,
288+ type : ToolbarDataType . ButtonPopup ,
289+ icon : icons . link ,
290+ title : i18n ( 'link' ) ,
291+ exec : noop ,
292+ isActive : isActiveFn ,
293+ isEnable : isEnableFn ,
294+ renderPopup : ( props ) => {
295+ const { editor} = props ;
296+ const selection = editor . cm . getSelection ( ) ;
297+
298+ return (
299+ < ToolbarLinkPopup
300+ { ...props }
301+ formInitialText = { selection }
302+ formReadOnlyText = { Boolean ( selection ) }
303+ onSubmit = { ( url , text ) => {
304+ insertLink ( { url, text} ) ( editor . cm ) ;
305+ } }
306+ />
307+ ) ;
308+ } ,
286309} ;
287310
288311export const mNoteButton : MToolbarSingleItemData = {
@@ -427,15 +450,23 @@ export const mToolbarConfig: MToolbarData = [
427450 [
428451 {
429452 id : 'image' ,
430- type : ToolbarDataType . ReactComponent ,
431- component : MToolbarImage ,
432- width : 28 ,
453+ type : ToolbarDataType . ButtonPopup ,
454+ icon : icons . image ,
455+ title : i18n ( 'image' ) ,
456+ exec : noop ,
457+ isActive : isActiveFn ,
458+ isEnable : isEnableFn ,
459+ renderPopup : ( props ) => < MToolbarImagePopup { ...props } /> ,
433460 } ,
434461 {
435462 id : 'file' ,
436- type : ToolbarDataType . ReactComponent ,
437- component : MToolbarFile ,
438- width : 28 ,
463+ type : ToolbarDataType . ButtonPopup ,
464+ icon : icons . file ,
465+ title : i18n ( 'file' ) ,
466+ exec : noop ,
467+ isActive : isActiveFn ,
468+ isEnable : isEnableFn ,
469+ renderPopup : ( props ) => < MToolbarFilePopup { ...props } /> ,
439470 } ,
440471 mTableButton ,
441472 mCheckboxButton ,
0 commit comments