sanity-plugin-mux-input 2.12.1 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +133 -0
- package/dist/index.d.mts +41 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +188 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +188 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/_exports/index.ts +1 -0
- package/src/components/FileInputButton.tsx +2 -2
- package/src/components/Player.tsx +4 -3
- package/src/components/PlayerActionsMenu.tsx +4 -3
- package/src/components/UploadConfiguration.tsx +181 -4
- package/src/components/UploadPlaceholder.tsx +14 -6
- package/src/components/Uploader.tsx +54 -6
- package/src/components/VideoInBrowser.tsx +2 -7
- package/src/components/VideoPlayer.tsx +33 -6
- package/src/components/icons/Audio.tsx +13 -0
- package/src/util/types.ts +45 -0
- package/src/components/FileInputArea.tsx +0 -93
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {UploadIcon} from '@sanity/icons'
|
|
2
|
-
import {Card, CardTone, Flex, Inline} from '@sanity/ui'
|
|
3
|
-
import {PropsWithChildren, useRef, useState} from 'react'
|
|
4
|
-
|
|
5
|
-
import {extractDroppedFiles} from '../util/extractFiles'
|
|
6
|
-
import {FileInputButton} from './FileInputButton'
|
|
7
|
-
|
|
8
|
-
interface FileInputAreaProps extends PropsWithChildren {
|
|
9
|
-
accept?: string
|
|
10
|
-
acceptMIMETypes?: string[]
|
|
11
|
-
label: React.ReactNode
|
|
12
|
-
onSelect: (files: FileList | File[]) => void
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default function FileInputArea({
|
|
16
|
-
label,
|
|
17
|
-
accept,
|
|
18
|
-
acceptMIMETypes,
|
|
19
|
-
onSelect,
|
|
20
|
-
}: FileInputAreaProps) {
|
|
21
|
-
const dragEnteredEls = useRef<EventTarget[]>([])
|
|
22
|
-
const [dragState, setDragState] = useState<'valid' | 'invalid' | null>(null)
|
|
23
|
-
|
|
24
|
-
// Stages and validates an upload from dragging+dropping files or folders
|
|
25
|
-
const handleDrop: React.DragEventHandler<HTMLDivElement> = (event) => {
|
|
26
|
-
setDragState(null)
|
|
27
|
-
event.preventDefault()
|
|
28
|
-
event.stopPropagation()
|
|
29
|
-
extractDroppedFiles(event.nativeEvent.dataTransfer!).then(onSelect)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/* ------------------------------- Drag State ------------------------------- */
|
|
33
|
-
|
|
34
|
-
const handleDragOver: React.DragEventHandler<HTMLDivElement> = (event) => {
|
|
35
|
-
event.preventDefault()
|
|
36
|
-
event.stopPropagation()
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const handleDragEnter: React.DragEventHandler<HTMLDivElement> = (event) => {
|
|
40
|
-
event.stopPropagation()
|
|
41
|
-
dragEnteredEls.current.push(event.target)
|
|
42
|
-
const type = event.dataTransfer.items?.[0]?.type
|
|
43
|
-
setDragState(
|
|
44
|
-
!acceptMIMETypes || acceptMIMETypes.some((mimeType) => type?.match(mimeType))
|
|
45
|
-
? 'valid'
|
|
46
|
-
: 'invalid'
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const handleDragLeave: React.DragEventHandler<HTMLDivElement> = (event) => {
|
|
51
|
-
event.stopPropagation()
|
|
52
|
-
const idx = dragEnteredEls.current.indexOf(event.target)
|
|
53
|
-
if (idx > -1) {
|
|
54
|
-
dragEnteredEls.current.splice(idx, 1)
|
|
55
|
-
}
|
|
56
|
-
if (dragEnteredEls.current.length === 0) {
|
|
57
|
-
setDragState(null)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let tone: CardTone = 'inherit'
|
|
62
|
-
if (dragState) tone = dragState === 'valid' ? 'positive' : 'critical'
|
|
63
|
-
return (
|
|
64
|
-
<Card border sizing="border" tone={tone} style={{borderStyle: 'dashed'}} padding={3}>
|
|
65
|
-
<Flex
|
|
66
|
-
align="center"
|
|
67
|
-
justify="space-between"
|
|
68
|
-
gap={4}
|
|
69
|
-
direction={['column', 'column', 'row']}
|
|
70
|
-
paddingY={[2, 2, 0]}
|
|
71
|
-
sizing="border"
|
|
72
|
-
onDrop={handleDrop}
|
|
73
|
-
onDragOver={handleDragOver}
|
|
74
|
-
onDragLeave={handleDragLeave}
|
|
75
|
-
onDragEnter={handleDragEnter}
|
|
76
|
-
>
|
|
77
|
-
<Flex align="center" justify="center" gap={2} flex={1}>
|
|
78
|
-
{label}
|
|
79
|
-
</Flex>
|
|
80
|
-
<Inline space={2}>
|
|
81
|
-
<FileInputButton
|
|
82
|
-
mode="ghost"
|
|
83
|
-
tone="default"
|
|
84
|
-
icon={UploadIcon}
|
|
85
|
-
text="Upload"
|
|
86
|
-
onSelect={onSelect}
|
|
87
|
-
accept={accept}
|
|
88
|
-
/>
|
|
89
|
-
</Inline>
|
|
90
|
-
</Flex>
|
|
91
|
-
</Card>
|
|
92
|
-
)
|
|
93
|
-
}
|