@@ -25,8 +25,8 @@ import { insertParsedHtmlNodes } from './plugins/insertParsedHtmlNodes';
25
25
import { parseMarkdownToNodesAndInsert } from './plugins/parseMarkdownToNodesAndInsert' ;
26
26
27
27
import { useDebounceFn } from '@ant-design/pro-components' ;
28
+ import { useRefFunction } from '../../hooks/useRefFunction' ;
28
29
import { PluginContext } from '../plugin' ;
29
- import { TagPopupProps } from './elements/code/TagPopup' ;
30
30
import { useHighlight } from './plugins/useHighlight' ;
31
31
import { useKeyboard } from './plugins/useKeyboard' ;
32
32
import { useOnchange } from './plugins/useOnchange' ;
@@ -58,7 +58,6 @@ export type MEditorProps = {
58
58
comment ?: MarkdownEditorProps [ 'comment' ] ;
59
59
prefixCls ?: string ;
60
60
reportMode ?: MarkdownEditorProps [ 'reportMode' ] ;
61
- tag ?: TagPopupProps ;
62
61
placeholder ?: string ;
63
62
} & MarkdownEditorProps ;
64
63
@@ -79,19 +78,13 @@ const genTableMinSize = (
79
78
} ;
80
79
81
80
export const MEditor = observer (
82
- ( {
83
- eleItemRender,
84
- reportMode,
85
- tag,
86
- instance,
87
- ...editorProps
88
- } : MEditorProps ) => {
81
+ ( { eleItemRender, reportMode, instance, ...editorProps } : MEditorProps ) => {
89
82
const { store, markdownEditorRef, markdownContainerRef, readonly } =
90
83
useEditorStore ( ) ;
91
84
const changedMark = useRef ( false ) ;
92
85
const value = useRef < any [ ] > ( [ EditorUtils . p ] ) ;
93
86
const nodeRef = useRef < MarkdownEditorInstance > ( ) ;
94
- const { prefixCls = '$' } = tag || { } ;
87
+ const { prefixCls = '$' } = editorProps . tagInputProps || { } ;
95
88
96
89
const onKeyDown = useKeyboard (
97
90
store ,
@@ -106,19 +99,23 @@ export const MEditor = observer(
106
99
const high = useHighlight ( store ) ;
107
100
const first = useRef ( true ) ;
108
101
109
- const handleKeyDown = ( event : React . KeyboardEvent < HTMLDivElement > ) => {
110
- if ( tag && event ?. key === prefixCls ) {
111
- Transforms . insertNodes ( markdownEditorRef . current , {
112
- type : 'code' ,
113
- code : true ,
114
- tag : {
115
- ...tag ,
116
- } ,
117
- text : '' ,
118
- } ) ;
119
- }
120
- onKeyDown ( event ) ;
121
- } ;
102
+ const handleKeyDown = useRefFunction (
103
+ ( event : React . KeyboardEvent < HTMLDivElement > ) => {
104
+ if ( editorProps . tagInputProps ?. enable && event ?. key === prefixCls ) {
105
+ event . preventDefault ( ) ;
106
+ event . stopPropagation ( ) ;
107
+ Transforms . insertNodes ( markdownEditorRef . current , [
108
+ {
109
+ code : true ,
110
+ tag : true ,
111
+ text : '$' ,
112
+ } ,
113
+ ] ) ;
114
+ return ;
115
+ }
116
+ onKeyDown ( event ) ;
117
+ } ,
118
+ ) ;
122
119
123
120
/**
124
121
* 初始化编辑器
@@ -587,6 +584,7 @@ export const MEditor = observer(
587
584
comment = { editorProps ?. comment }
588
585
children = { props . children }
589
586
hashId = { hashId }
587
+ tagInputProps = { editorProps . tagInputProps }
590
588
/>
591
589
) ;
592
590
} ;
0 commit comments