File tree 2 files changed +23
-1
lines changed
form/inputs/common/fileTarget
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,25 @@ export type FileInfo = {
20
20
type : DataTransferItem [ 'type' ] // mime type of file or string
21
21
}
22
22
23
+ type CamelToKebab < S extends string > = S extends `${infer P1 } ${infer P2 } `
24
+ ? P2 extends Uncapitalize < P2 >
25
+ ? `${Lowercase < P1 > } ${CamelToKebab < P2 > } `
26
+ : `${Lowercase < P1 > } -${CamelToKebab < Uncapitalize < P2 > > } `
27
+ : S
28
+
29
+ type DataAttribute < S extends string > = `data-${CamelToKebab < S > } `
30
+
31
+ const fileTargetAttributeName = 'isFileTarget'
32
+ const fileTargetDataAttribute : Record < DataAttribute < typeof fileTargetAttributeName > , 'true' > = {
33
+ 'data-is-file-target' : 'true' ,
34
+ }
35
+
36
+ /**
37
+ * @internal
38
+ */
39
+ export const isFileTargetElement = ( el : HTMLElement ) : boolean =>
40
+ el ?. dataset ?. [ fileTargetAttributeName ] === 'true'
41
+
23
42
type Props = {
24
43
// Triggered when the target component receives one or more files, either originating from a drop event or a paste event
25
44
onFiles ?: ( files : File [ ] ) => void
@@ -189,6 +208,7 @@ export function fileTarget<ComponentProps>(Component: ComponentType<ComponentPro
189
208
onDragLeave = { disabled ? undefined : handleDragLeave }
190
209
onDrop = { disabled ? undefined : handleDrop }
191
210
data-test-id = "file-target"
211
+ { ...fileTargetDataAttribute }
192
212
/>
193
213
{ ! disabled && showPasteInput && (
194
214
< div contentEditable onPaste = { handlePaste } ref = { pasteInput } style = { PASTE_INPUT_STYLE } />
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import {isHotkey} from 'is-hotkey-esm'
3
3
import { useCallback , useEffect , useRef } from 'react'
4
4
import { type FormDocumentValue } from 'sanity'
5
5
6
+ import { isFileTargetElement } from '../form/inputs/common/fileTarget/fileTarget'
6
7
import { useCopyPaste } from '../studio/copyPaste'
7
8
import { hasSelection , isEmptyFocusPath , isNativeEditableElement } from '../studio/copyPaste/utils'
8
9
@@ -56,7 +57,8 @@ export function useGlobalCopyPasteElementHandler({
56
57
if ( isPasteHotKey ( event ) ) {
57
58
if (
58
59
isNativeEditableElement ( targetElement as HTMLElement ) ||
59
- isEmptyFocusPath ( focusPathRef . current )
60
+ isEmptyFocusPath ( focusPathRef . current ) ||
61
+ isFileTargetElement ( targetElement as HTMLElement )
60
62
) {
61
63
return
62
64
}
You can’t perform that action at this time.
0 commit comments