sanity-plugin-mux-input 2.12.0 → 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/src/util/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type {ObjectInputProps, PreviewLayoutKey, PreviewProps, SchemaType} from 'sanity'
2
2
  import type {PartialDeep} from 'type-fest'
3
+ import type MuxPlayerElement from '@mux/mux-player'
3
4
 
4
5
  /**
5
6
  * Standard static rendition options available for plugin configuration defaults
@@ -122,6 +123,50 @@ export interface MuxInputConfig {
122
123
  * @defaultValue false
123
124
  */
124
125
  disableTextTrackConfig?: boolean
126
+
127
+ /**
128
+ * The mime types that are accepted by the input.
129
+ *
130
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/accept}
131
+ * @defaultValue ['video/*','audio/*']
132
+
133
+ */
134
+ acceptedMimeTypes?: ('audio/*' | 'video/*')[]
135
+
136
+ /**
137
+ * Maximum file size allowed for video uploads in bytes.
138
+ * If not specified, no file size validation will be performed.
139
+ *
140
+ * @example 1024 * 1024 * 1024 // 1 GB
141
+ * @defaultValue undefined
142
+ */
143
+ maxAssetFileSize?: number
144
+
145
+ /**
146
+ * Maximum video duration allowed in seconds.
147
+ * If not specified, no duration validation will be performed.
148
+ *
149
+ * @example 2 * 60 * 60 // 2 hours
150
+ * @defaultValue undefined
151
+ */
152
+ maxAssetDuration?: number
153
+
154
+ /**
155
+ * HLS.js configuration options to be passed to the Mux Player.
156
+ * These options allow you to customize the underlying HLS.js playback engine behavior.
157
+ *
158
+ * @see {@link https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning}
159
+ * @defaultValue undefined
160
+ * @example
161
+ * ```ts
162
+ * {
163
+ * maxBufferLength: 30,
164
+ * lowLatencyMode: true,
165
+ * capLevelToPlayerSize: true
166
+ * }
167
+ * ```
168
+ */
169
+ hlsConfig?: MuxPlayerElement['_hlsConfig']
125
170
  }
126
171
 
127
172
  export interface PluginConfig extends MuxInputConfig {
@@ -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
- }