sanity-plugin-mux-input 2.2.0 → 2.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-mux-input",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "An input component that integrates Sanity Studio with Mux video encoding/hosting service.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -74,7 +74,7 @@
74
74
  "scroll-into-view-if-needed": "^3",
75
75
  "suspend-react": "^0.1.0",
76
76
  "swr": "^2.1.0",
77
- "type-fest": "^3.6.1",
77
+ "type-fest": "^4.0.0",
78
78
  "use-error-boundary": "^2.0.6"
79
79
  },
80
80
  "devDependencies": {
@@ -94,16 +94,16 @@
94
94
  "eslint-config-react-app": "^7.0.1",
95
95
  "eslint-config-sanity": "^6.0.0",
96
96
  "eslint-plugin-import": "^2.28.0",
97
- "eslint-plugin-prettier": "^4.2.1",
97
+ "eslint-plugin-prettier": "^5.0.0",
98
98
  "eslint-plugin-react": "^7.33.1",
99
99
  "eslint-plugin-react-hooks": "^4.6.0",
100
100
  "eslint-plugin-simple-import-sort": "^10.0.0",
101
101
  "husky": "^8.0.3",
102
102
  "lint-staged": "^13.2.3",
103
103
  "next": "^13.4.12",
104
- "next-sanity": "^4.3.3",
104
+ "next-sanity": "^5.1.6",
105
105
  "npm-run-all": "^4.1.5",
106
- "prettier": "^2.8.8",
106
+ "prettier": "^3.0.1",
107
107
  "prettier-plugin-packagejson": "^2.4.5",
108
108
  "react": "^18.2.0",
109
109
  "react-dom": "^18.2.0",
@@ -123,7 +123,8 @@
123
123
  "node": ">=14"
124
124
  },
125
125
  "publishConfig": {
126
- "access": "public"
126
+ "access": "public",
127
+ "provenance": true
127
128
  },
128
129
  "sanityExchangeUrl": "https://www.sanity.io/plugins/sanity-plugin-mux-input"
129
130
  }
@@ -1,18 +1,35 @@
1
1
  import {Dialog} from '@sanity/ui'
2
2
  import React, {useCallback, useId} from 'react'
3
+ import styled from 'styled-components'
3
4
 
4
5
  import type {SetDialogState} from '../hooks/useDialogState'
5
6
  import SelectAsset, {type Props as SelectAssetProps} from './SelectAsset'
6
7
 
7
- interface Props extends Pick<SelectAssetProps, 'onChange' | 'asset'> {
8
+ /** To prevent Content Layout Shift (CLS), ensure that the dialog always occupies the entire available height. */
9
+ const StyledDialog = styled(Dialog)`
10
+ > div[data-ui='DialogCard'] > div[data-ui='Card'] {
11
+ height: 100%;
12
+ }
13
+ `
14
+
15
+ export default function InputBrowser({
16
+ setDialogState,
17
+ asset,
18
+ onChange,
19
+ }: Pick<SelectAssetProps, 'onChange' | 'asset'> & {
8
20
  setDialogState: SetDialogState
9
- }
10
- export default function InputBrowser({setDialogState, asset, onChange}: Props) {
21
+ }) {
11
22
  const id = `InputBrowser${useId()}`
12
23
  const handleClose = useCallback(() => setDialogState(false), [setDialogState])
13
24
  return (
14
- <Dialog __unstable_autoFocus header="Select video" id={id} onClose={handleClose} width={2}>
25
+ <StyledDialog
26
+ __unstable_autoFocus
27
+ header="Select video"
28
+ id={id}
29
+ onClose={handleClose}
30
+ width={2}
31
+ >
15
32
  <SelectAsset asset={asset} onChange={onChange} setDialogState={setDialogState} />
16
- </Dialog>
33
+ </StyledDialog>
17
34
  )
18
35
  }
@@ -75,7 +75,7 @@ const Player = ({asset, buttons, readOnly, onChange}: Props) => {
75
75
  <UploadProgress
76
76
  progress={100}
77
77
  filename={asset?.filename}
78
- text={(isLoading !== true && isLoading) || 'Waiting for Mux to complete the file'}
78
+ text={(isLoading !== true && isLoading) || 'Waiting for Mux to complete the upload'}
79
79
  onCancel={readOnly ? undefined : () => handleCancelUpload()}
80
80
  />
81
81
  )
@@ -8,7 +8,7 @@ import {useClient} from '../../hooks/useClient'
8
8
  import {DIALOGS_Z_INDEX} from '../../util/constants'
9
9
  import {PluginPlacement, VideoAssetDocument} from '../../util/types'
10
10
  import SpinnerBox from '../SpinnerBox'
11
- import FileReferences from './VideoReferences'
11
+ import VideoReferences from './VideoReferences'
12
12
 
13
13
  export default function DeleteDialog({
14
14
  asset,
@@ -62,9 +62,9 @@ export default function DeleteDialog({
62
62
 
63
63
  return (
64
64
  <Dialog
65
- header={'Delete file'}
65
+ header={'Delete video'}
66
66
  zOffset={DIALOGS_Z_INDEX}
67
- id="deleting-file-details-dialog"
67
+ id="deleting-video-details-dialog"
68
68
  onClose={cancelDelete}
69
69
  onClickOutside={cancelDelete}
70
70
  width={1}
@@ -76,7 +76,7 @@ export default function DeleteDialog({
76
76
  icon={TrashIcon}
77
77
  fontSize={2}
78
78
  padding={3}
79
- text="Delete file"
79
+ text="Delete video"
80
80
  tone="critical"
81
81
  onClick={confirmDelete}
82
82
  disabled={['processing_deletion', 'checkingReferences', 'cantDelete'].some(
@@ -99,7 +99,7 @@ export default function DeleteDialog({
99
99
  <Stack space={3}>
100
100
  {state === 'checkingReferences' && (
101
101
  <>
102
- <Heading size={2}>Checking if file can be deleted</Heading>
102
+ <Heading size={2}>Checking if video can be deleted</Heading>
103
103
  <SpinnerBox />
104
104
  </>
105
105
  )}
@@ -108,10 +108,10 @@ export default function DeleteDialog({
108
108
  <Heading size={2}>Video can't be deleted</Heading>
109
109
  <Text size={2} style={{marginBottom: '2rem'}}>
110
110
  There are {references?.length} document{references && references.length > 0 && 's'}{' '}
111
- pointing to this file. Remove their references to this file or delete them before
111
+ pointing to this video. Remove their references to this file or delete them before
112
112
  proceeding.
113
113
  </Text>
114
- <FileReferences
114
+ <VideoReferences
115
115
  references={references}
116
116
  isLoaded={!referencesLoading}
117
117
  placement={placement}
@@ -120,7 +120,7 @@ export default function DeleteDialog({
120
120
  )}
121
121
  {state === 'confirm' && (
122
122
  <>
123
- <Heading size={2}>Are you sure you want to delete this file?</Heading>
123
+ <Heading size={2}>Are you sure you want to delete this video?</Heading>
124
124
  <Text size={2}>This action is irreversible</Text>
125
125
  <Stack space={4} marginTop={4}>
126
126
  <Flex align="center" as="label">
@@ -139,14 +139,14 @@ export default function DeleteDialog({
139
139
  )}
140
140
  {state === 'processing_deletion' && (
141
141
  <>
142
- <Heading size={2}>Deleting file...</Heading>
142
+ <Heading size={2}>Deleting video...</Heading>
143
143
  <SpinnerBox />
144
144
  </>
145
145
  )}
146
146
  {state === 'error_deleting' && (
147
147
  <>
148
148
  <Heading size={2}>Something went wrong!</Heading>
149
- <Text size={2}>Try deleting the file again by clicking the button below</Text>
149
+ <Text size={2}>Try deleting the video again by clicking the button below</Text>
150
150
  </>
151
151
  )}
152
152
  </Stack>
@@ -32,8 +32,8 @@ import {ResolutionIcon} from '../icons/Resolution'
32
32
  import {StopWatchIcon} from '../icons/StopWatch'
33
33
  import VideoPlayer from '../VideoPlayer'
34
34
  import DeleteDialog from './DeleteDialog'
35
- import useFileDetails, {FileDetailsProps} from './useVideoDetails'
36
- import FileReferences from './VideoReferences'
35
+ import useVideoDetails, {VideoDetailsProps} from './useVideoDetails'
36
+ import VideoReferences from './VideoReferences'
37
37
 
38
38
  const AssetInput: React.FC<{
39
39
  label: string
@@ -54,7 +54,7 @@ const AssetInput: React.FC<{
54
54
  </FormField>
55
55
  )
56
56
 
57
- const VideoDetails: React.FC<FileDetailsProps> = (props) => {
57
+ const VideoDetails: React.FC<VideoDetailsProps> = (props) => {
58
58
  const [tab, setTab] = useState<'details' | 'references'>('details')
59
59
  const {
60
60
  displayInfo,
@@ -68,7 +68,7 @@ const VideoDetails: React.FC<FileDetailsProps> = (props) => {
68
68
  handleClose,
69
69
  confirmClose,
70
70
  saveChanges,
71
- } = useFileDetails(props)
71
+ } = useVideoDetails(props)
72
72
 
73
73
  const isSaving = state === 'saving'
74
74
 
@@ -85,11 +85,10 @@ const VideoDetails: React.FC<FileDetailsProps> = (props) => {
85
85
  <Dialog
86
86
  header={displayInfo.title}
87
87
  zOffset={DIALOGS_Z_INDEX}
88
- id="file-details-dialog"
88
+ id="video-details-dialog"
89
89
  onClose={handleClose}
90
90
  onClickOutside={handleClose}
91
91
  width={2}
92
- style={{minHeight: '50vh'}}
93
92
  position="fixed"
94
93
  footer={
95
94
  <Card padding={3}>
@@ -140,7 +139,7 @@ const VideoDetails: React.FC<FileDetailsProps> = (props) => {
140
139
  <Dialog
141
140
  header={'You have unsaved changes'}
142
141
  zOffset={DIALOGS_Z_INDEX}
143
- id="closing-file-details-dialog"
142
+ id="closing-video-details-dialog"
144
143
  onClose={() => confirmClose(false)}
145
144
  onClickOutside={() => confirmClose(false)}
146
145
  width={1}
@@ -213,22 +212,20 @@ const VideoDetails: React.FC<FileDetailsProps> = (props) => {
213
212
  onClick={() => setTab('details')}
214
213
  selected={tab === 'details'}
215
214
  />
216
- {references && references.length > 0 && (
217
- <Tab
218
- aria-controls="references-panel"
219
- icon={SearchIcon}
220
- id="references-tab"
221
- label={`Used by (${references.length})`}
222
- onClick={() => setTab('references')}
223
- selected={tab === 'references'}
224
- />
225
- )}
215
+ <Tab
216
+ aria-controls="references-panel"
217
+ icon={SearchIcon}
218
+ id="references-tab"
219
+ label={`Used by ${references ? `(${references.length})` : ''}`}
220
+ onClick={() => setTab('references')}
221
+ selected={tab === 'references'}
222
+ />
226
223
  </TabList>
227
224
  <TabPanel aria-labelledby="details-tab" id="details-panel" hidden={tab !== 'details'}>
228
225
  <Stack space={4}>
229
226
  <AssetInput
230
- label="File name"
231
- description="Not visible to users. Useful for finding files later."
227
+ label="Video title or file name"
228
+ description="Not visible to users. Useful for finding videos later."
232
229
  value={filename || ''}
233
230
  onInput={(e) => setFilename(e.currentTarget.value)}
234
231
  disabled={state !== 'idle'}
@@ -282,7 +279,7 @@ const VideoDetails: React.FC<FileDetailsProps> = (props) => {
282
279
  id="references-panel"
283
280
  hidden={tab !== 'references'}
284
281
  >
285
- <FileReferences
282
+ <VideoReferences
286
283
  references={references}
287
284
  isLoaded={!referencesLoading}
288
285
  placement={props.placement}
@@ -20,7 +20,7 @@ const Container = styled(Box)`
20
20
  }
21
21
  `
22
22
 
23
- const FileReferences: React.FC<{
23
+ const VideoReferences: React.FC<{
24
24
  references?: SanityDocument[]
25
25
  isLoaded: boolean
26
26
  placement: PluginPlacement
@@ -32,9 +32,9 @@ const FileReferences: React.FC<{
32
32
 
33
33
  if (!props.references?.length) {
34
34
  return (
35
- <Text size={2} weight="bold" muted style={{marginTop: '1.5rem', textAlign: 'center'}}>
36
- No documents are using this file
37
- </Text>
35
+ <Card border radius={3} padding={3}>
36
+ <Text size={2}>No documents are using this video</Text>
37
+ </Card>
38
38
  )
39
39
  }
40
40
 
@@ -67,4 +67,4 @@ const FileReferences: React.FC<{
67
67
  )
68
68
  }
69
69
 
70
- export default FileReferences
70
+ export default VideoReferences
@@ -7,13 +7,13 @@ import useDocReferences from '../../hooks/useDocReferences'
7
7
  import getVideoMetadata from '../../util/getVideoMetadata'
8
8
  import {PluginPlacement, VideoAssetDocument} from '../../util/types'
9
9
 
10
- export interface FileDetailsProps {
10
+ export interface VideoDetailsProps {
11
11
  placement: PluginPlacement
12
12
  closeDialog: () => void
13
13
  asset: VideoAssetDocument & {autoPlay?: boolean}
14
14
  }
15
15
 
16
- export default function useFileDetails(props: FileDetailsProps) {
16
+ export default function useVideoDetails(props: VideoDetailsProps) {
17
17
  const documentStore = useDocumentStore()
18
18
  const toast = useToast()
19
19
  const client = useClient()
@@ -56,7 +56,12 @@ export default function useFileDetails(props: FileDetailsProps) {
56
56
  try {
57
57
  await client.patch(props.asset._id).set({filename}).commit()
58
58
  setOriginalAsset((prev) => ({...prev, filename}))
59
- toast.push({title: 'File name updated', status: 'success'})
59
+ toast.push({
60
+ title: 'Video title updated',
61
+ description: `New title: ${filename}`,
62
+ status: 'success',
63
+ })
64
+ props.closeDialog()
60
65
  } catch (error) {
61
66
  toast.push({
62
67
  title: 'Failed updating file name',
@@ -6,7 +6,7 @@ import useAssets from '../hooks/useAssets'
6
6
  import type {VideoAssetDocument} from '../util/types'
7
7
  import {SelectSortOptions} from './SelectSortOptions'
8
8
  import SpinnerBox from './SpinnerBox'
9
- import {FileDetailsProps} from './VideoDetails/useVideoDetails'
9
+ import {VideoDetailsProps} from './VideoDetails/useVideoDetails'
10
10
  import VideoDetails from './VideoDetails/VideoDetails'
11
11
  import VideoInBrowser from './VideoInBrowser'
12
12
 
@@ -16,7 +16,7 @@ export interface VideosBrowserProps {
16
16
 
17
17
  export default function VideosBrowser({onSelect}: VideosBrowserProps) {
18
18
  const {assets, isLoading, searchQuery, setSearchQuery, setSort, sort} = useAssets()
19
- const [editedAsset, setEditedAsset] = React.useState<FileDetailsProps['asset'] | null>(null)
19
+ const [editedAsset, setEditedAsset] = React.useState<VideoDetailsProps['asset'] | null>(null)
20
20
  const freshEditedAsset = React.useMemo(
21
21
  () => assets.find((a) => a._id === editedAsset?._id) || editedAsset,
22
22
  [editedAsset, assets]
@@ -24,7 +24,7 @@ export default function VideosBrowser({onSelect}: VideosBrowserProps) {
24
24
 
25
25
  return (
26
26
  <>
27
- <Stack padding={4} space={4}>
27
+ <Stack padding={4} space={4} style={{minHeight: '50vh'}}>
28
28
  <Flex justify="space-between" align="center">
29
29
  <Flex align="center" gap={3}>
30
30
  <TextInput
@@ -33,7 +33,7 @@ export default function VideosBrowser({onSelect}: VideosBrowserProps) {
33
33
  onInput={(e: React.FormEvent<HTMLInputElement>) =>
34
34
  setSearchQuery(e.currentTarget.value)
35
35
  }
36
- placeholder="Search files"
36
+ placeholder="Search videos"
37
37
  />
38
38
  <SelectSortOptions setSort={setSort} sort={sort} />
39
39
  </Flex>
@@ -64,8 +64,8 @@ export default function VideosBrowser({onSelect}: VideosBrowserProps) {
64
64
  {isLoading && <SpinnerBox />}
65
65
 
66
66
  {!isLoading && assets.length === 0 && (
67
- <Card padding={2} marginY={4} border radius={2}>
68
- <Text align="center" muted>
67
+ <Card padding={4} marginY={4} border radius={2} tone="transparent">
68
+ <Text align="center" muted size={3}>
69
69
  {searchQuery ? `No videos found for "${searchQuery}"` : 'No videos in this dataset'}
70
70
  </Text>
71
71
  </Card>
@@ -25,10 +25,14 @@ const useAssetDocuments = createHookFromObservableFactory<
25
25
  const search = createSearchFilter(searchQuery)
26
26
  const filter = [`_type == "mux.videoAsset"`, ...search.filter].filter(Boolean).join(' && ')
27
27
 
28
- const query = ASSET_SORT_OPTIONS[sort].groq
29
- return documentStore.listenQuery(/* groq */ `*[${filter}] | order(${query})`, search.params, {
30
- apiVersion: SANITY_API_VERSION,
31
- })
28
+ const sortFragment = ASSET_SORT_OPTIONS[sort].groq
29
+ return documentStore.listenQuery(
30
+ /* groq */ `*[${filter}] | order(${sortFragment})`,
31
+ search.params,
32
+ {
33
+ apiVersion: SANITY_API_VERSION,
34
+ }
35
+ )
32
36
  })
33
37
 
34
38
  export default function useAssets() {
@@ -45,7 +49,7 @@ export default function useAssets() {
45
49
  ({
46
50
  ...(collated.draft || collated.published || {}),
47
51
  _id: collated.id,
48
- } as VideoAssetDocument)
52
+ }) as VideoAssetDocument
49
53
  ),
50
54
  [assetDocuments]
51
55
  )
@@ -9,5 +9,5 @@ export const DIALOGS_Z_INDEX = 60_000
9
9
 
10
10
  export const THUMBNAIL_ASPECT_RATIO = 16 / 9
11
11
 
12
- /** Thumbnails and input shouldn't go beyond this aspect ratio */
13
- export const MIN_ASPECT_RATIO = 1
12
+ /** To prevent excessive height, thumbnails and input should not go beyond to this aspect ratio. */
13
+ export const MIN_ASPECT_RATIO = 5 / 4
@@ -12,7 +12,7 @@ function tokenize(string: string): string[] {
12
12
  function toGroqParams(terms: string[]): Record<string, string> {
13
13
  const params: Record<string, string> = {}
14
14
  return terms.reduce((acc, term, i) => {
15
- acc[`t${i}`] = `*${term}*` // "t" is short for term
15
+ acc[`t${i}`] = `${term}*` // "t" is short for term
16
16
  return acc
17
17
  }, params)
18
18
  }
@@ -52,7 +52,7 @@ function extractTermsFromQuery(query: string): string[] {
52
52
  }
53
53
 
54
54
  /** Which properties of the video asset document should we match users' queries against */
55
- const SEARCH_PATHS = ['filename', 'assetId', '_id']
55
+ const SEARCH_PATHS = ['filename']
56
56
 
57
57
  /**
58
58
  * Create GROQ constraints, given search terms and the full spec of available document types and fields.