4
4
*/
5
5
6
6
import { IDomEditor } from '../../editor/interface'
7
- import { DomEditor } from '../../editor/dom-editor'
8
- import TextArea from '../TextArea'
9
- import { hasEditableTarget } from '../helpers'
10
7
import { isPlainTextOnlyPaste } from '../../utils/dom'
11
- import { HAS_BEFORE_INPUT_SUPPORT } from '../../utils/ua'
8
+ import { HAS_BEFORE_INPUT_SUPPORT , IS_SAFARI } from '../../utils/ua'
12
9
import { EDITOR_TO_CAN_PASTE } from '../../utils/weak-maps'
10
+ import { hasEditableTarget } from '../helpers'
11
+ import TextArea from '../TextArea'
13
12
14
13
function handleOnPaste ( e : Event , textarea : TextArea , editor : IDomEditor ) {
15
14
EDITOR_TO_CAN_PASTE . set ( editor , true ) // 标记为:可执行默认粘贴
16
15
17
16
const event = e as ClipboardEvent
18
17
const { readOnly } = editor . getConfig ( )
19
18
20
- if ( readOnly ) return
21
- if ( ! hasEditableTarget ( editor , event . target ) ) return
19
+ if ( readOnly ) { return }
20
+ if ( ! hasEditableTarget ( editor , event . target ) ) { return }
22
21
23
22
const { customPaste } = editor . getConfig ( )
23
+
24
24
if ( customPaste ) {
25
25
const res = customPaste ( editor , event )
26
+
26
27
if ( res === false ) {
27
28
// 自行实现粘贴,不执行默认粘贴
28
29
EDITOR_TO_CAN_PASTE . set ( editor , false ) // 标记为:不可执行默认粘贴
@@ -32,12 +33,13 @@ function handleOnPaste(e: Event, textarea: TextArea, editor: IDomEditor) {
32
33
33
34
// 如果支持 beforeInput 且不是纯粘贴文本(如 html、图片文件),则使用 beforeInput 来实现
34
35
// 这里只处理:不支持 beforeInput 或者 粘贴纯文本
35
- if ( HAS_BEFORE_INPUT_SUPPORT && ! isPlainTextOnlyPaste ( event ) ) return
36
+ if ( ! IS_SAFARI && HAS_BEFORE_INPUT_SUPPORT && ! isPlainTextOnlyPaste ( event ) ) { return }
36
37
37
38
event . preventDefault ( )
38
39
39
40
const data = event . clipboardData
40
- if ( data == null ) return
41
+
42
+ if ( data == null ) { return }
41
43
editor . insertData ( data )
42
44
}
43
45
0 commit comments