sanity-plugin-media 2.0.4 → 2.0.5

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-media",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "This version of `sanity-plugin-media` is for Sanity Studio V3.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -20,7 +20,6 @@ import AssetMetadata from '../AssetMetadata'
20
20
  import Dialog from '../Dialog'
21
21
  import DocumentList from '../DocumentList'
22
22
  import FileAssetPreview from '../FileAssetPreview'
23
- import FormFieldInputFilename from '../FormFieldInputFilename'
24
23
  import FormFieldInputTags from '../FormFieldInputTags'
25
24
  import FormFieldInputText from '../FormFieldInputText'
26
25
  import FormFieldInputTextarea from '../FormFieldInputTextarea'
@@ -35,14 +34,9 @@ type Props = {
35
34
  type FormData = yup.InferType<typeof formSchema>
36
35
 
37
36
  const formSchema = yup.object().shape({
38
- originalFilename: yup.string().required('Filename cannot be empty')
37
+ originalFilename: yup.string().trim().required('Filename cannot be empty')
39
38
  })
40
39
 
41
- const getFilenameWithoutExtension = (asset?: Asset): string | undefined => {
42
- const extensionIndex = asset?.originalFilename?.toLowerCase().lastIndexOf(`.${asset.extension}`)
43
- return asset?.originalFilename?.slice(0, extensionIndex)
44
- }
45
-
46
40
  const DialogAssetEdit = (props: Props) => {
47
41
  const {
48
42
  children,
@@ -73,7 +67,7 @@ const DialogAssetEdit = (props: Props) => {
73
67
  const generateDefaultValues = (asset?: Asset) => ({
74
68
  altText: asset?.altText || '',
75
69
  description: asset?.description || '',
76
- originalFilename: asset ? getFilenameWithoutExtension(asset) : undefined,
70
+ originalFilename: asset?.originalFilename || '',
77
71
  opt: {media: {tags: assetTagOptions}},
78
72
  title: asset?.title || ''
79
73
  })
@@ -165,9 +159,7 @@ const DialogAssetEdit = (props: Props) => {
165
159
  _weak: true
166
160
  })) || null
167
161
  }
168
- },
169
- // Append extension to filename
170
- originalFilename: `${sanitizedFormData.originalFilename}.${assetItem?.asset.extension}`
162
+ }
171
163
  }
172
164
  })
173
165
  )
@@ -323,14 +315,13 @@ const DialogAssetEdit = (props: Props) => {
323
315
  value={assetTagOptions}
324
316
  />
325
317
  {/* Filename */}
326
- <FormFieldInputFilename
318
+ <FormFieldInputText
327
319
  disabled={formUpdating}
328
320
  error={errors?.originalFilename}
329
- extension={currentAsset?.extension || ''}
330
321
  label="Filename"
331
322
  name="originalFilename"
332
323
  ref={register}
333
- value={getFilenameWithoutExtension(currentAsset)}
324
+ value={currentAsset?.originalFilename}
334
325
  />
335
326
  {/* Title */}
336
327
  <FormFieldInputText
@@ -1,50 +0,0 @@
1
- import {Box, Flex, TextInput} from '@sanity/ui'
2
- import React, {forwardRef} from 'react'
3
- import {FieldError} from 'react-hook-form'
4
-
5
- import FormFieldInputLabel from '../FormFieldInputLabel'
6
-
7
- type Props = {
8
- description?: string
9
- extension: string
10
- disabled?: boolean
11
- error?: FieldError
12
- label: string
13
- name: string
14
- placeholder?: string
15
- value?: string
16
- }
17
-
18
- type Ref = HTMLInputElement
19
-
20
- const FormFieldInputText = forwardRef<Ref, Props>((props: Props, ref) => {
21
- const {description, disabled, error, extension, label, name, placeholder, value} = props
22
-
23
- return (
24
- <Box>
25
- {/* Label */}
26
- <FormFieldInputLabel description={description} error={error} label={label} name={name} />
27
-
28
- {/* Input */}
29
- <Flex>
30
- <Box style={{flexGrow: 1}}>
31
- <TextInput
32
- autoComplete="off"
33
- autoFocus
34
- defaultValue={value}
35
- disabled={disabled}
36
- id={name}
37
- name={name}
38
- placeholder={placeholder}
39
- ref={ref}
40
- />
41
- </Box>
42
- <Box style={{width: '70px'}}>
43
- <TextInput defaultValue={`.${extension}`} disabled />
44
- </Box>
45
- </Flex>
46
- </Box>
47
- )
48
- })
49
-
50
- export default FormFieldInputText