sanity-plugin-media 2.3.1 → 2.3.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/README.md +23 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +122 -82
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +121 -81
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DialogAssetEdit/index.tsx +19 -0
- package/src/components/SearchFacetsControl/index.tsx +8 -0
- package/src/config/searchFacets.ts +10 -0
- package/src/constants.ts +1 -0
- package/src/contexts/ToolOptionsContext.tsx +22 -4
- package/src/formSchema/index.ts +1 -0
- package/src/modules/assets/index.ts +4 -0
- package/src/types/index.ts +6 -0
- package/src/utils/constructFilter.ts +1 -1
package/package.json
CHANGED
|
@@ -27,6 +27,7 @@ import FormFieldInputText from '../FormFieldInputText'
|
|
|
27
27
|
import FormFieldInputTextarea from '../FormFieldInputTextarea'
|
|
28
28
|
import FormSubmitButton from '../FormSubmitButton'
|
|
29
29
|
import Image from '../Image'
|
|
30
|
+
import {useToolOptions} from '../../contexts/ToolOptionsContext'
|
|
30
31
|
|
|
31
32
|
type Props = {
|
|
32
33
|
children: ReactNode
|
|
@@ -59,10 +60,14 @@ const DialogAssetEdit = (props: Props) => {
|
|
|
59
60
|
|
|
60
61
|
const assetTagOptions = useTypedSelector(selectTagSelectOptions(currentAsset))
|
|
61
62
|
|
|
63
|
+
// Check if credit line options are configured
|
|
64
|
+
const {creditLine} = useToolOptions()
|
|
65
|
+
|
|
62
66
|
const generateDefaultValues = useCallback(
|
|
63
67
|
(asset?: Asset): AssetFormData => {
|
|
64
68
|
return {
|
|
65
69
|
altText: asset?.altText || '',
|
|
70
|
+
creditLine: asset?.creditLine || '',
|
|
66
71
|
description: asset?.description || '',
|
|
67
72
|
originalFilename: asset?.originalFilename || '',
|
|
68
73
|
opt: {media: {tags: assetTagOptions}},
|
|
@@ -342,6 +347,20 @@ const DialogAssetEdit = (props: Props) => {
|
|
|
342
347
|
rows={5}
|
|
343
348
|
value={currentAsset?.description}
|
|
344
349
|
/>
|
|
350
|
+
{/* CreditLine */}
|
|
351
|
+
{creditLine?.enabled && (
|
|
352
|
+
<FormFieldInputText
|
|
353
|
+
{...register('creditLine')}
|
|
354
|
+
error={errors?.creditLine?.message}
|
|
355
|
+
label="Credit"
|
|
356
|
+
name="creditLine"
|
|
357
|
+
value={currentAsset?.creditLine}
|
|
358
|
+
disabled={
|
|
359
|
+
formUpdating ||
|
|
360
|
+
creditLine?.excludeSources?.includes(currentAsset?.source?.name)
|
|
361
|
+
}
|
|
362
|
+
/>
|
|
363
|
+
)}
|
|
345
364
|
</Stack>
|
|
346
365
|
</TabPanel>
|
|
347
366
|
|
|
@@ -7,6 +7,7 @@ import {FACETS} from '../../constants'
|
|
|
7
7
|
import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
|
|
8
8
|
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
9
9
|
import {searchActions} from '../../modules/search'
|
|
10
|
+
import {useToolOptions} from '../../contexts/ToolOptionsContext'
|
|
10
11
|
|
|
11
12
|
const SearchFacetsControl = () => {
|
|
12
13
|
// Redux
|
|
@@ -17,11 +18,18 @@ const SearchFacetsControl = () => {
|
|
|
17
18
|
|
|
18
19
|
const popoverProps = usePortalPopoverProps()
|
|
19
20
|
|
|
21
|
+
const {creditLine} = useToolOptions()
|
|
22
|
+
|
|
20
23
|
const isTool = !selectedDocument
|
|
21
24
|
|
|
22
25
|
const filteredFacets = FACETS
|
|
23
26
|
// Filter facets based on current context, whether it's invoked as a tool, or via selection through via custom asset source.
|
|
24
27
|
.filter(facet => {
|
|
28
|
+
// Remove credit line filter if it's not enabled
|
|
29
|
+
if (!creditLine?.enabled && facet?.type === 'string' && facet?.name === 'creditLine') {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
if (facet.type === 'group' || facet.type === 'divider') {
|
|
26
34
|
return true
|
|
27
35
|
}
|
|
@@ -19,6 +19,16 @@ export const inputs: Record<SearchFacetName, SearchFacetInputProps> = {
|
|
|
19
19
|
type: 'string',
|
|
20
20
|
value: ''
|
|
21
21
|
},
|
|
22
|
+
creditLine: {
|
|
23
|
+
assetTypes: ['file', 'image'],
|
|
24
|
+
field: 'creditLine',
|
|
25
|
+
name: 'creditLine',
|
|
26
|
+
operatorType: 'empty',
|
|
27
|
+
operatorTypes: ['empty', 'notEmpty', null, 'includes', 'doesNotInclude'],
|
|
28
|
+
title: 'Credit',
|
|
29
|
+
type: 'string',
|
|
30
|
+
value: ''
|
|
31
|
+
},
|
|
22
32
|
description: {
|
|
23
33
|
assetTypes: ['file', 'image'],
|
|
24
34
|
field: 'description',
|
package/src/constants.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {DropzoneOptions} from 'react-dropzone'
|
|
|
4
4
|
|
|
5
5
|
type ContextProps = {
|
|
6
6
|
dropzone: Pick<DropzoneOptions, 'maxSize'>
|
|
7
|
+
creditLine: MediaToolOptions['creditLine']
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
const ToolOptionsContext = createContext<ContextProps | null>(null)
|
|
@@ -13,10 +14,27 @@ type Props = {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export const ToolOptionsProvider = ({options, children}: PropsWithChildren<Props>) => {
|
|
16
|
-
const value = useMemo<ContextProps>(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const value = useMemo<ContextProps>(() => {
|
|
18
|
+
let creditLineExcludeSources
|
|
19
|
+
|
|
20
|
+
if (options?.creditLine?.excludeSources) {
|
|
21
|
+
creditLineExcludeSources = Array.isArray(options?.creditLine?.excludeSources)
|
|
22
|
+
? options.creditLine.excludeSources
|
|
23
|
+
: [options?.creditLine?.excludeSources]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
dropzone: {maxSize: options?.maximumUploadSize},
|
|
28
|
+
creditLine: {
|
|
29
|
+
enabled: options?.creditLine?.enabled || false,
|
|
30
|
+
excludeSources: creditLineExcludeSources
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, [
|
|
34
|
+
options?.creditLine?.enabled,
|
|
35
|
+
options?.creditLine?.excludeSources,
|
|
36
|
+
options?.maximumUploadSize
|
|
37
|
+
])
|
|
20
38
|
|
|
21
39
|
return <ToolOptionsContext.Provider value={value}>{children}</ToolOptionsContext.Provider>
|
|
22
40
|
}
|
package/src/formSchema/index.ts
CHANGED
|
@@ -239,6 +239,7 @@ const assetsSlice = createSlice({
|
|
|
239
239
|
_createdAt,
|
|
240
240
|
_updatedAt,
|
|
241
241
|
altText,
|
|
242
|
+
creditLine,
|
|
242
243
|
description,
|
|
243
244
|
extension,
|
|
244
245
|
metadata {
|
|
@@ -252,6 +253,9 @@ const assetsSlice = createSlice({
|
|
|
252
253
|
},
|
|
253
254
|
originalFilename,
|
|
254
255
|
size,
|
|
256
|
+
source {
|
|
257
|
+
name
|
|
258
|
+
},
|
|
255
259
|
title,
|
|
256
260
|
url
|
|
257
261
|
} ${pipe} ${sort} ${selector},
|
package/src/types/index.ts
CHANGED
|
@@ -12,6 +12,10 @@ import {RootReducerState} from '../modules/types'
|
|
|
12
12
|
|
|
13
13
|
export type MediaToolOptions = {
|
|
14
14
|
maximumUploadSize?: number
|
|
15
|
+
creditLine: {
|
|
16
|
+
enabled: boolean
|
|
17
|
+
excludeSources?: string | string[]
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
type CustomFields = {
|
|
@@ -152,6 +156,7 @@ export type FileAsset = SanityAssetDocument &
|
|
|
152
156
|
export type ImageAsset = SanityImageAssetDocument &
|
|
153
157
|
CustomFields & {
|
|
154
158
|
_type: 'sanity.imageAsset'
|
|
159
|
+
creditLine?: string
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
export type MarkDef = {_key: string; _type: string}
|
|
@@ -238,6 +243,7 @@ export type SearchFacetInputStringProps = SearchFacetInputCommon & {
|
|
|
238
243
|
|
|
239
244
|
export type SearchFacetName =
|
|
240
245
|
| 'altText'
|
|
246
|
+
| 'creditLine'
|
|
241
247
|
| 'description'
|
|
242
248
|
| 'fileName'
|
|
243
249
|
| 'height'
|
|
@@ -85,7 +85,7 @@ const constructFilter = ({
|
|
|
85
85
|
// references(*[_type == "media.tag" && name.current == "${searchQuery.trim()}"]._id)
|
|
86
86
|
...(searchQuery
|
|
87
87
|
? [
|
|
88
|
-
groq`[_id, altText, assetId, description, originalFilename, title, url] match '*${searchQuery.trim()}*'`
|
|
88
|
+
groq`[_id, altText, assetId, creditLine, description, originalFilename, title, url] match '*${searchQuery.trim()}*'`
|
|
89
89
|
]
|
|
90
90
|
: []),
|
|
91
91
|
// Search facets
|