@@ -9,8 +9,11 @@ import type {EditorView} from '#pm/view';
99import { i18n } from 'src/i18n/yfm-note' ;
1010import { typedMemo } from 'src/react-utils/memo' ;
1111import { Toolbar , type ToolbarData , ToolbarDataType } from 'src/toolbar' ;
12+ import { ToolbarWrapToContext } from 'src/toolbar/ToolbarRerender' ;
1213import { removeNode } from 'src/utils/remove-node' ;
1314
15+ import { NoteAttrs } from '../../const' ;
16+
1417import './YfmNoteToolbar.scss' ;
1518
1619const ToolbarMemoized = typedMemo ( Toolbar ) ;
@@ -23,7 +26,6 @@ enum YfmNoteType {
2326}
2427
2528const isEnable = ( ) => true ;
26- const isActive = ( ) => false ;
2729
2830const changeType : (
2931 type : YfmNoteType ,
@@ -38,8 +40,8 @@ const changeType: (
3840 dispatch (
3941 tr . setNodeMarkup ( pos , null , {
4042 ...node . attrs ,
41- class : `yfm-note yfm-accent-${ type } ` ,
42- 'note-type' : type ,
43+ [ NoteAttrs . Class ] : `yfm-note yfm-accent-${ type } ` ,
44+ [ NoteAttrs . Type ] : type ,
4345 } ) ,
4446 ) ;
4547 } ;
@@ -66,7 +68,7 @@ export function YfmNoteToolbar({pos, node, editorView}: YfmNoteToolbarProps) {
6668 icon : { data : CircleInfo } ,
6769 title : i18n ( type ) ,
6870 type : ToolbarDataType . SingleButton ,
69- isActive,
71+ isActive : ( ) => nodeRef . current . attrs [ NoteAttrs . Type ] === type ,
7072 isEnable,
7173 exec : ( view ) =>
7274 changeType ( type ) ( {
@@ -83,7 +85,8 @@ export function YfmNoteToolbar({pos, node, editorView}: YfmNoteToolbarProps) {
8385 icon : { data : TrashBin } ,
8486 title : i18n ( 'remove' ) ,
8587 type : ToolbarDataType . SingleButton ,
86- isActive,
88+ theme : 'danger' ,
89+ isActive : ( ) => false ,
8790 isEnable,
8891 exec : ( view ) =>
8992 removeNode ( {
@@ -98,14 +101,16 @@ export function YfmNoteToolbar({pos, node, editorView}: YfmNoteToolbarProps) {
98101 } , [ nodeRef , posRef ] ) ;
99102
100103 return (
101- < ToolbarMemoized
102- editor = { editorView }
103- focus = { onFocus }
104- // the yfm class allows to access css variables
105- // https://github.com/diplodoc-platform/transform/blob/master/src/scss/_common.scss#L17
106- className = "yfm g-md-yfm-note-toolbar"
107- qa = "g-md-toolbar-yfm-note"
108- data = { toolbarData }
109- />
104+ < ToolbarWrapToContext editor = { editorView } >
105+ < ToolbarMemoized
106+ editor = { editorView }
107+ focus = { onFocus }
108+ // the yfm class allows to access css variables
109+ // https://github.com/diplodoc-platform/transform/blob/master/src/scss/_common.scss#L17
110+ className = "yfm g-md-yfm-note-toolbar"
111+ qa = "g-md-toolbar-yfm-note"
112+ data = { toolbarData }
113+ />
114+ </ ToolbarWrapToContext >
110115 ) ;
111116}
0 commit comments