sanity-plugin-media 4.3.6 → 5.0.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/package.json +6 -15
- package/dist/index.cjs +0 -4721
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -239
- package/dist/index.d.cts.map +0 -1
- package/sanity.json +0 -8
- package/src/__tests__/fixtures/createEpicTestStore.ts +0 -28
- package/src/__tests__/fixtures/listenMock.ts +0 -9
- package/src/__tests__/fixtures/mockSanityClient.ts +0 -84
- package/src/__tests__/fixtures/renderWithProviders.tsx +0 -55
- package/src/__tests__/fixtures/rootState.ts +0 -27
- package/src/__tests__/fixtures/withinDialog.ts +0 -28
- package/src/components/AssetGridVirtualized/index.tsx +0 -94
- package/src/components/AssetMetadata/index.tsx +0 -122
- package/src/components/AssetTableVirtualized/index.tsx +0 -73
- package/src/components/AutoTagInputWrapper/index.tsx +0 -85
- package/src/components/Browser/Browser.test.tsx +0 -45
- package/src/components/Browser/index.tsx +0 -90
- package/src/components/Browser/useBrowserInit.ts +0 -126
- package/src/components/ButtonAssetCopy/index.tsx +0 -65
- package/src/components/ButtonViewGroup/index.tsx +0 -39
- package/src/components/CardAsset/CardAsset.test.tsx +0 -323
- package/src/components/CardAsset/index.tsx +0 -290
- package/src/components/CardUpload/index.tsx +0 -161
- package/src/components/Controls/index.tsx +0 -136
- package/src/components/DebugControls/index.tsx +0 -80
- package/src/components/Dialog/index.tsx +0 -11
- package/src/components/DialogAssetEdit/Details.tsx +0 -181
- package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +0 -216
- package/src/components/DialogAssetEdit/index.tsx +0 -493
- package/src/components/DialogConfirm/index.tsx +0 -90
- package/src/components/DialogSearchFacets/index.tsx +0 -42
- package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
- package/src/components/DialogTagCreate/index.tsx +0 -111
- package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
- package/src/components/DialogTagEdit/index.tsx +0 -201
- package/src/components/DialogTags/index.tsx +0 -45
- package/src/components/Dialogs/index.tsx +0 -76
- package/src/components/DocumentList/index.tsx +0 -62
- package/src/components/FileAssetPreview/index.tsx +0 -37
- package/src/components/FileIcon/index.tsx +0 -43
- package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +0 -63
- package/src/components/FormBuilderTool/index.tsx +0 -69
- package/src/components/FormFieldInputLabel/index.tsx +0 -66
- package/src/components/FormFieldInputTags/index.tsx +0 -98
- package/src/components/FormFieldInputText/index.tsx +0 -41
- package/src/components/FormFieldInputTextarea/index.tsx +0 -43
- package/src/components/FormSubmitButton/index.tsx +0 -59
- package/src/components/Header/index.tsx +0 -80
- package/src/components/Image/index.tsx +0 -41
- package/src/components/Items/index.tsx +0 -68
- package/src/components/Notifications/index.tsx +0 -24
- package/src/components/OrderSelect/index.tsx +0 -66
- package/src/components/PickedBar/index.tsx +0 -77
- package/src/components/Progress/index.tsx +0 -38
- package/src/components/ReduxProvider/index.tsx +0 -96
- package/src/components/SearchFacet/index.tsx +0 -66
- package/src/components/SearchFacetNumber/index.tsx +0 -133
- package/src/components/SearchFacetSelect/index.tsx +0 -110
- package/src/components/SearchFacetString/index.tsx +0 -88
- package/src/components/SearchFacetTags/index.tsx +0 -121
- package/src/components/SearchFacets/index.tsx +0 -72
- package/src/components/SearchFacetsControl/index.tsx +0 -140
- package/src/components/TableHeader/index.tsx +0 -110
- package/src/components/TableHeaderItem/index.tsx +0 -61
- package/src/components/TableRowAsset/index.tsx +0 -419
- package/src/components/TableRowUpload/index.tsx +0 -164
- package/src/components/Tag/index.tsx +0 -200
- package/src/components/TagIcon/index.tsx +0 -22
- package/src/components/TagView/index.tsx +0 -39
- package/src/components/TagViewHeader/index.tsx +0 -70
- package/src/components/TagsPanel/index.tsx +0 -40
- package/src/components/TagsVirtualized/index.tsx +0 -160
- package/src/components/TextInputNumber/index.tsx +0 -32
- package/src/components/TextInputSearch/index.tsx +0 -60
- package/src/components/Tool/index.tsx +0 -13
- package/src/components/UploadDropzone/UploadDropzone.test.tsx +0 -40
- package/src/components/UploadDropzone/index.tsx +0 -173
- package/src/config/orders.ts +0 -28
- package/src/config/searchFacets.ts +0 -312
- package/src/constants.ts +0 -87
- package/src/contexts/AssetSourceDispatchContext.tsx +0 -38
- package/src/contexts/DropzoneDispatchContext.tsx +0 -32
- package/src/contexts/ToolOptionsContext.tsx +0 -66
- package/src/formSchema/index.test.ts +0 -56
- package/src/formSchema/index.ts +0 -39
- package/src/hooks/useBreakpointIndex.ts +0 -50
- package/src/hooks/useKeyPress.ts +0 -39
- package/src/hooks/usePortalPopoverProps.ts +0 -13
- package/src/hooks/useTypedSelector.ts +0 -7
- package/src/hooks/useVersionedClient.ts +0 -6
- package/src/index.ts +0 -5
- package/src/modules/assets/actions.ts +0 -42
- package/src/modules/assets/deleteAndUpdateEpics.test.ts +0 -87
- package/src/modules/assets/fetchEpic.test.ts +0 -73
- package/src/modules/assets/index.ts +0 -782
- package/src/modules/assets/reducer.test.ts +0 -91
- package/src/modules/assets/tagsAndListenerEpics.test.ts +0 -206
- package/src/modules/debug/index.ts +0 -28
- package/src/modules/dialog/actions.ts +0 -10
- package/src/modules/dialog/epics.test.ts +0 -168
- package/src/modules/dialog/index.ts +0 -238
- package/src/modules/dialog/reducer.test.ts +0 -185
- package/src/modules/index.ts +0 -117
- package/src/modules/notifications/epics.test.ts +0 -374
- package/src/modules/notifications/index.ts +0 -199
- package/src/modules/notifications/reducer.test.ts +0 -54
- package/src/modules/search/index.test.ts +0 -36
- package/src/modules/search/index.ts +0 -167
- package/src/modules/selected/index.ts +0 -22
- package/src/modules/selectors.test.ts +0 -21
- package/src/modules/selectors.ts +0 -17
- package/src/modules/tags/epics.test.ts +0 -96
- package/src/modules/tags/index.test.ts +0 -42
- package/src/modules/tags/index.ts +0 -540
- package/src/modules/types.ts +0 -3
- package/src/modules/uploads/actions.ts +0 -13
- package/src/modules/uploads/epics.test.ts +0 -109
- package/src/modules/uploads/index.test.ts +0 -59
- package/src/modules/uploads/index.ts +0 -272
- package/src/operators/checkTagName.test.ts +0 -29
- package/src/operators/checkTagName.ts +0 -33
- package/src/operators/debugThrottle.ts +0 -25
- package/src/plugin.tsx +0 -54
- package/src/schemas/tag.ts +0 -28
- package/src/styled/GlobalStyles/index.tsx +0 -40
- package/src/styled/react-select/creatable.tsx +0 -184
- package/src/styled/react-select/single.tsx +0 -184
- package/src/types/index.ts +0 -346
- package/src/types/sanity-ui.d.ts +0 -5
- package/src/utils/applyMediaTags.ts +0 -87
- package/src/utils/blocksToText.test.ts +0 -43
- package/src/utils/blocksToText.ts +0 -27
- package/src/utils/constructFilter.test.ts +0 -120
- package/src/utils/constructFilter.ts +0 -98
- package/src/utils/generatePreviewBlobUrl.test.ts +0 -68
- package/src/utils/generatePreviewBlobUrl.ts +0 -53
- package/src/utils/getAssetResolution.test.ts +0 -13
- package/src/utils/getAssetResolution.ts +0 -7
- package/src/utils/getDocumentAssetIds.test.ts +0 -50
- package/src/utils/getDocumentAssetIds.ts +0 -35
- package/src/utils/getSchemeColor.test.ts +0 -12
- package/src/utils/getSchemeColor.ts +0 -43
- package/src/utils/getTagSelectOptions.test.ts +0 -44
- package/src/utils/getTagSelectOptions.ts +0 -16
- package/src/utils/getUniqueDocuments.test.ts +0 -26
- package/src/utils/getUniqueDocuments.ts +0 -15
- package/src/utils/imageDprUrl.test.ts +0 -46
- package/src/utils/imageDprUrl.ts +0 -27
- package/src/utils/isSupportedAssetType.test.ts +0 -16
- package/src/utils/isSupportedAssetType.ts +0 -15
- package/src/utils/mediaField.ts +0 -73
- package/src/utils/sanitizeFormData.test.ts +0 -59
- package/src/utils/sanitizeFormData.ts +0 -26
- package/src/utils/typeGuards.test.ts +0 -18
- package/src/utils/typeGuards.ts +0 -9
- package/src/utils/uploadSanityAsset.test.ts +0 -29
- package/src/utils/uploadSanityAsset.ts +0 -97
- package/src/utils/withMaxConcurrency.test.ts +0 -43
- package/src/utils/withMaxConcurrency.ts +0 -55
- package/src/utils/zodFormResolver.ts +0 -17
- package/v2-incompatible.js +0 -11
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import {white} from '@sanity/color'
|
|
2
|
-
import {Flex, Text} from '@sanity/ui'
|
|
3
|
-
import {type ReactNode} from 'react'
|
|
4
|
-
import {type DropEvent, type DropzoneOptions, useDropzone} from 'react-dropzone'
|
|
5
|
-
import {useDispatch} from 'react-redux'
|
|
6
|
-
import {styled} from 'styled-components'
|
|
7
|
-
|
|
8
|
-
import {useAssetSourceActions} from '../../contexts/AssetSourceDispatchContext'
|
|
9
|
-
import {DropzoneDispatchProvider} from '../../contexts/DropzoneDispatchContext'
|
|
10
|
-
import {useToolOptions} from '../../contexts/ToolOptionsContext'
|
|
11
|
-
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
12
|
-
import {notificationsActions} from '../../modules/notifications'
|
|
13
|
-
import {uploadsActions} from '../../modules/uploads'
|
|
14
|
-
|
|
15
|
-
type Props = {
|
|
16
|
-
children: ReactNode
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const UploadContainer = styled.div`
|
|
20
|
-
color: white;
|
|
21
|
-
height: 100%;
|
|
22
|
-
min-height: 100%;
|
|
23
|
-
right: 0;
|
|
24
|
-
top: 0;
|
|
25
|
-
width: 100%;
|
|
26
|
-
|
|
27
|
-
&:focus {
|
|
28
|
-
outline: none;
|
|
29
|
-
}
|
|
30
|
-
`
|
|
31
|
-
|
|
32
|
-
const DragActiveContainer = styled.div`
|
|
33
|
-
align-items: center;
|
|
34
|
-
background: rgba(0, 0, 0, 0.75);
|
|
35
|
-
display: flex;
|
|
36
|
-
height: 100%;
|
|
37
|
-
justify-content: center;
|
|
38
|
-
position: absolute;
|
|
39
|
-
right: 0;
|
|
40
|
-
top: 0;
|
|
41
|
-
width: 100%;
|
|
42
|
-
z-index: 3;
|
|
43
|
-
`
|
|
44
|
-
|
|
45
|
-
// Iterate through all files and only return non-folders / packages.
|
|
46
|
-
// We check for files by reading the first byte of the file
|
|
47
|
-
async function filterFiles(fileList: FileList) {
|
|
48
|
-
const files = Array.from(fileList)
|
|
49
|
-
|
|
50
|
-
const filteredFiles: File[] = []
|
|
51
|
-
|
|
52
|
-
for (const file of files) {
|
|
53
|
-
try {
|
|
54
|
-
await file.slice(0, 1).arrayBuffer()
|
|
55
|
-
filteredFiles.push(file)
|
|
56
|
-
} catch {
|
|
57
|
-
// do nothing: file is a package or folder
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return filteredFiles
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const UploadDropzone = (props: Props) => {
|
|
65
|
-
const {children} = props
|
|
66
|
-
|
|
67
|
-
const {
|
|
68
|
-
dropzone: {maxSize},
|
|
69
|
-
directUploads,
|
|
70
|
-
} = useToolOptions()
|
|
71
|
-
|
|
72
|
-
const {onSelect} = useAssetSourceActions()
|
|
73
|
-
|
|
74
|
-
// Redux
|
|
75
|
-
const dispatch = useDispatch()
|
|
76
|
-
const assetTypes = useTypedSelector((state) => state.assets.assetTypes)
|
|
77
|
-
|
|
78
|
-
const isImageAssetType = assetTypes.length === 1 && assetTypes[0] === 'image'
|
|
79
|
-
|
|
80
|
-
// Callbacks
|
|
81
|
-
const handleDrop = async (acceptedFiles: File[]) => {
|
|
82
|
-
acceptedFiles.forEach((file) =>
|
|
83
|
-
dispatch(
|
|
84
|
-
uploadsActions.uploadRequest({
|
|
85
|
-
file,
|
|
86
|
-
forceAsAssetType: assetTypes.length === 1 ? assetTypes[0] : undefined,
|
|
87
|
-
}),
|
|
88
|
-
),
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const handleDropRejected: DropzoneOptions['onDropRejected'] = (rejections) => {
|
|
93
|
-
const errorCodes = rejections.flatMap(({errors}) => errors.map(({code}) => code))
|
|
94
|
-
|
|
95
|
-
if (errorCodes.includes('file-too-large')) {
|
|
96
|
-
dispatch(
|
|
97
|
-
notificationsActions.add({
|
|
98
|
-
status: 'error',
|
|
99
|
-
title: 'One or more files exceed the maximum upload size.',
|
|
100
|
-
}),
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Use custom file selector to obtain files on file drop + change events (excluding folders and packages)
|
|
106
|
-
const handleFileGetter = async (event: DropEvent) => {
|
|
107
|
-
let fileList: FileList | undefined
|
|
108
|
-
if (event.type === 'drop' && 'dataTransfer' in event) {
|
|
109
|
-
fileList = event?.dataTransfer?.files
|
|
110
|
-
}
|
|
111
|
-
if (event.type === 'change') {
|
|
112
|
-
const target = event?.target as HTMLInputElement
|
|
113
|
-
if (target?.files) {
|
|
114
|
-
fileList = target.files
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (!fileList) {
|
|
119
|
-
return []
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Filter out non-folders / packages
|
|
123
|
-
const files: File[] = await filterFiles(fileList)
|
|
124
|
-
|
|
125
|
-
// Dispatch error if some files have been filtered out
|
|
126
|
-
if (fileList?.length !== files.length) {
|
|
127
|
-
dispatch(
|
|
128
|
-
notificationsActions.add({
|
|
129
|
-
status: 'error',
|
|
130
|
-
title: `Unable to upload some items (folders and packages aren't supported)`,
|
|
131
|
-
}),
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return files
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Limit file picking to only images if we're specifically within an image selection context (e.g. picking from image fields)
|
|
139
|
-
const {getRootProps, getInputProps, isDragActive, open} = useDropzone({
|
|
140
|
-
accept: isImageAssetType ? 'image/*' : '',
|
|
141
|
-
getFilesFromEvent: handleFileGetter,
|
|
142
|
-
noClick: true,
|
|
143
|
-
// HACK: Disable drag and drop functionality when in a selecting context
|
|
144
|
-
// (This is currently due to Sanity's native image input taking precedence with drag and drop)
|
|
145
|
-
noDrag: !!onSelect,
|
|
146
|
-
onDrop: handleDrop,
|
|
147
|
-
maxSize,
|
|
148
|
-
onDropRejected: handleDropRejected,
|
|
149
|
-
disabled: !directUploads,
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
return (
|
|
153
|
-
<DropzoneDispatchProvider open={open}>
|
|
154
|
-
<UploadContainer {...getRootProps()}>
|
|
155
|
-
<input {...getInputProps()} />
|
|
156
|
-
|
|
157
|
-
{isDragActive && (
|
|
158
|
-
<DragActiveContainer>
|
|
159
|
-
<Flex direction="column" justify="center" style={{color: white.hex}}>
|
|
160
|
-
<Text size={3} style={{color: 'inherit'}}>
|
|
161
|
-
Drop files to upload
|
|
162
|
-
</Text>
|
|
163
|
-
</Flex>
|
|
164
|
-
</DragActiveContainer>
|
|
165
|
-
)}
|
|
166
|
-
|
|
167
|
-
{children}
|
|
168
|
-
</UploadContainer>
|
|
169
|
-
</DropzoneDispatchProvider>
|
|
170
|
-
)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export default UploadDropzone
|
package/src/config/orders.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type {OrderDirection} from '../types'
|
|
2
|
-
|
|
3
|
-
const ORDER_DICTIONARY: Record<string, {asc: string; desc: string}> = {
|
|
4
|
-
_createdAt: {
|
|
5
|
-
asc: 'Last created: Oldest first',
|
|
6
|
-
desc: 'Last created: Newest first',
|
|
7
|
-
},
|
|
8
|
-
_updatedAt: {
|
|
9
|
-
asc: 'Last updated: Oldest first',
|
|
10
|
-
desc: 'Last updated: Newest first',
|
|
11
|
-
},
|
|
12
|
-
mimeType: {
|
|
13
|
-
asc: 'MIME type: A to Z',
|
|
14
|
-
desc: 'MIME type: Z to A',
|
|
15
|
-
},
|
|
16
|
-
originalFilename: {
|
|
17
|
-
asc: 'File name: A to Z',
|
|
18
|
-
desc: 'File name: Z to A',
|
|
19
|
-
},
|
|
20
|
-
size: {
|
|
21
|
-
asc: 'File size: Smallest first',
|
|
22
|
-
desc: 'File size: Largest first',
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const getOrderTitle = (field: string, direction: OrderDirection): string => {
|
|
27
|
-
return ORDER_DICTIONARY[field]![direction]
|
|
28
|
-
}
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import groq from 'groq'
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
SearchFacetDivider,
|
|
5
|
-
SearchFacetInputProps,
|
|
6
|
-
SearchFacetName,
|
|
7
|
-
SearchFacetOperators,
|
|
8
|
-
} from '../types'
|
|
9
|
-
|
|
10
|
-
export const divider: SearchFacetDivider = {type: 'divider'}
|
|
11
|
-
|
|
12
|
-
export const inputs: Record<SearchFacetName, SearchFacetInputProps> = {
|
|
13
|
-
altText: {
|
|
14
|
-
assetTypes: ['file', 'image'],
|
|
15
|
-
field: 'altText',
|
|
16
|
-
name: 'altText',
|
|
17
|
-
operatorType: 'empty',
|
|
18
|
-
operatorTypes: ['empty', 'notEmpty', null, 'includes', 'doesNotInclude'],
|
|
19
|
-
title: 'Alt text',
|
|
20
|
-
type: 'string',
|
|
21
|
-
value: '',
|
|
22
|
-
},
|
|
23
|
-
creditLine: {
|
|
24
|
-
assetTypes: ['file', 'image'],
|
|
25
|
-
field: 'creditLine',
|
|
26
|
-
name: 'creditLine',
|
|
27
|
-
operatorType: 'empty',
|
|
28
|
-
operatorTypes: ['empty', 'notEmpty', null, 'includes', 'doesNotInclude'],
|
|
29
|
-
title: 'Credit',
|
|
30
|
-
type: 'string',
|
|
31
|
-
value: '',
|
|
32
|
-
},
|
|
33
|
-
description: {
|
|
34
|
-
assetTypes: ['file', 'image'],
|
|
35
|
-
field: 'description',
|
|
36
|
-
name: 'description',
|
|
37
|
-
operatorType: 'empty',
|
|
38
|
-
operatorTypes: ['empty', 'notEmpty', null, 'includes', 'doesNotInclude'],
|
|
39
|
-
title: 'Description',
|
|
40
|
-
type: 'string',
|
|
41
|
-
value: '',
|
|
42
|
-
},
|
|
43
|
-
fileName: {
|
|
44
|
-
assetTypes: ['file', 'image'],
|
|
45
|
-
field: 'originalFilename',
|
|
46
|
-
name: 'filename',
|
|
47
|
-
operatorType: 'includes',
|
|
48
|
-
operatorTypes: ['includes', 'doesNotInclude'],
|
|
49
|
-
title: 'File name',
|
|
50
|
-
type: 'string',
|
|
51
|
-
value: '',
|
|
52
|
-
},
|
|
53
|
-
height: {
|
|
54
|
-
assetTypes: ['image'],
|
|
55
|
-
field: 'metadata.dimensions.height',
|
|
56
|
-
name: 'height',
|
|
57
|
-
operatorType: 'greaterThan',
|
|
58
|
-
operatorTypes: [
|
|
59
|
-
'greaterThan',
|
|
60
|
-
'greaterThanOrEqualTo',
|
|
61
|
-
'lessThan',
|
|
62
|
-
'lessThanOrEqualTo',
|
|
63
|
-
null,
|
|
64
|
-
'equalTo',
|
|
65
|
-
],
|
|
66
|
-
title: 'Height',
|
|
67
|
-
type: 'number',
|
|
68
|
-
value: 400,
|
|
69
|
-
},
|
|
70
|
-
inCurrentDocument: {
|
|
71
|
-
assetTypes: ['file', 'image'],
|
|
72
|
-
name: 'inCurrentDocument',
|
|
73
|
-
operatorType: 'is',
|
|
74
|
-
options: [
|
|
75
|
-
{
|
|
76
|
-
name: 'true',
|
|
77
|
-
title: 'True',
|
|
78
|
-
value: groq`_id in $documentAssetIds`,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: 'false',
|
|
82
|
-
title: 'False',
|
|
83
|
-
value: groq`!(_id in $documentAssetIds)`,
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
selectOnly: true,
|
|
87
|
-
title: 'In use in current document',
|
|
88
|
-
type: 'select',
|
|
89
|
-
value: 'true',
|
|
90
|
-
},
|
|
91
|
-
inUse: {
|
|
92
|
-
assetTypes: ['file', 'image'],
|
|
93
|
-
name: 'inUse',
|
|
94
|
-
operatorType: 'is',
|
|
95
|
-
options: [
|
|
96
|
-
{
|
|
97
|
-
name: 'true',
|
|
98
|
-
title: 'True',
|
|
99
|
-
value: groq`count(*[references(^._id)]) > 0`,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: 'false',
|
|
103
|
-
title: 'False',
|
|
104
|
-
value: groq`count(*[references(^._id)]) == 0`,
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
title: 'In use',
|
|
108
|
-
type: 'select',
|
|
109
|
-
value: 'true',
|
|
110
|
-
},
|
|
111
|
-
isOpaque: {
|
|
112
|
-
assetTypes: ['image'],
|
|
113
|
-
field: 'metadata.isOpaque',
|
|
114
|
-
name: 'isOpaque',
|
|
115
|
-
operatorType: 'equalTo',
|
|
116
|
-
options: [
|
|
117
|
-
{
|
|
118
|
-
name: 'true',
|
|
119
|
-
title: 'True',
|
|
120
|
-
value: `false`,
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
name: 'false',
|
|
124
|
-
title: 'False',
|
|
125
|
-
value: `true`,
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
title: 'Has transparency',
|
|
129
|
-
type: 'select',
|
|
130
|
-
value: 'true',
|
|
131
|
-
},
|
|
132
|
-
orientation: {
|
|
133
|
-
assetTypes: ['image'],
|
|
134
|
-
name: 'orientation',
|
|
135
|
-
operatorType: 'is',
|
|
136
|
-
operatorTypes: ['is', 'isNot'],
|
|
137
|
-
options: [
|
|
138
|
-
{
|
|
139
|
-
name: 'portrait',
|
|
140
|
-
title: 'Portrait',
|
|
141
|
-
value: 'metadata.dimensions.aspectRatio < 1',
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: 'landscape',
|
|
145
|
-
title: 'Landscape',
|
|
146
|
-
value: 'metadata.dimensions.aspectRatio > 1',
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
name: 'square',
|
|
150
|
-
title: 'Square',
|
|
151
|
-
value: 'metadata.dimensions.aspectRatio == 1',
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
title: 'Orientation',
|
|
155
|
-
type: 'select',
|
|
156
|
-
value: 'portrait',
|
|
157
|
-
},
|
|
158
|
-
size: {
|
|
159
|
-
assetTypes: ['file', 'image'],
|
|
160
|
-
field: 'size',
|
|
161
|
-
modifier: 'kb',
|
|
162
|
-
modifiers: [
|
|
163
|
-
{
|
|
164
|
-
name: 'kb',
|
|
165
|
-
title: 'KB',
|
|
166
|
-
fieldModifier: (fieldName) => `round(${fieldName} / 1000)`,
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
name: 'mb',
|
|
170
|
-
title: 'MB',
|
|
171
|
-
fieldModifier: (fieldName) => `round(${fieldName} / 1000000)`,
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
name: 'size',
|
|
175
|
-
operatorType: 'greaterThan',
|
|
176
|
-
operatorTypes: [
|
|
177
|
-
'greaterThan',
|
|
178
|
-
'greaterThanOrEqualTo',
|
|
179
|
-
'lessThan',
|
|
180
|
-
'lessThanOrEqualTo',
|
|
181
|
-
null,
|
|
182
|
-
'equalTo',
|
|
183
|
-
],
|
|
184
|
-
title: 'File size',
|
|
185
|
-
type: 'number',
|
|
186
|
-
value: 0,
|
|
187
|
-
},
|
|
188
|
-
tag: {
|
|
189
|
-
assetTypes: ['file', 'image'],
|
|
190
|
-
field: 'opt.media.tags',
|
|
191
|
-
name: 'tag',
|
|
192
|
-
operatorType: 'references',
|
|
193
|
-
operatorTypes: ['references', 'doesNotReference', null, 'empty', 'notEmpty'],
|
|
194
|
-
title: 'Tags',
|
|
195
|
-
type: 'searchable',
|
|
196
|
-
},
|
|
197
|
-
title: {
|
|
198
|
-
assetTypes: ['file', 'image'],
|
|
199
|
-
field: 'title',
|
|
200
|
-
name: 'title',
|
|
201
|
-
operatorType: 'empty',
|
|
202
|
-
operatorTypes: ['empty', 'notEmpty', null, 'includes', 'doesNotInclude'],
|
|
203
|
-
title: 'Title',
|
|
204
|
-
type: 'string',
|
|
205
|
-
value: '',
|
|
206
|
-
},
|
|
207
|
-
type: {
|
|
208
|
-
assetTypes: ['file', 'image'],
|
|
209
|
-
name: 'type',
|
|
210
|
-
operatorType: 'is',
|
|
211
|
-
operatorTypes: ['is', 'isNot'],
|
|
212
|
-
options: [
|
|
213
|
-
{
|
|
214
|
-
name: 'image',
|
|
215
|
-
title: 'Image',
|
|
216
|
-
value: 'mimeType match "image*"',
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
name: 'video',
|
|
220
|
-
title: 'Video',
|
|
221
|
-
value: 'mimeType match "video*"',
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
name: 'audio',
|
|
225
|
-
title: 'Audio',
|
|
226
|
-
value: 'mimeType match "audio*"',
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
name: 'pdf',
|
|
230
|
-
title: 'PDF',
|
|
231
|
-
value: 'mimeType == "application/pdf"',
|
|
232
|
-
},
|
|
233
|
-
],
|
|
234
|
-
title: 'File type',
|
|
235
|
-
type: 'select',
|
|
236
|
-
value: 'image',
|
|
237
|
-
},
|
|
238
|
-
width: {
|
|
239
|
-
assetTypes: ['image'],
|
|
240
|
-
field: 'metadata.dimensions.width',
|
|
241
|
-
name: 'width',
|
|
242
|
-
operatorType: 'greaterThan',
|
|
243
|
-
operatorTypes: [
|
|
244
|
-
'greaterThan',
|
|
245
|
-
'greaterThanOrEqualTo',
|
|
246
|
-
'lessThan',
|
|
247
|
-
'lessThanOrEqualTo',
|
|
248
|
-
null,
|
|
249
|
-
'equalTo',
|
|
250
|
-
],
|
|
251
|
-
title: 'Width',
|
|
252
|
-
type: 'number',
|
|
253
|
-
value: 400,
|
|
254
|
-
},
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export const operators: SearchFacetOperators = {
|
|
258
|
-
doesNotInclude: {
|
|
259
|
-
fn: (value, field) => (value ? `!(${field} match '*${value}*')` : undefined),
|
|
260
|
-
label: 'does not include',
|
|
261
|
-
},
|
|
262
|
-
doesNotReference: {
|
|
263
|
-
fn: (value, _field) => (value ? `!references('${value}')` : undefined),
|
|
264
|
-
label: 'does not include',
|
|
265
|
-
},
|
|
266
|
-
empty: {
|
|
267
|
-
fn: (_value, field) => `!defined(${field})`,
|
|
268
|
-
hideInput: true,
|
|
269
|
-
label: 'is empty',
|
|
270
|
-
},
|
|
271
|
-
equalTo: {
|
|
272
|
-
fn: (value, field) => (value ? `${field} == ${value}` : undefined),
|
|
273
|
-
label: 'is equal to',
|
|
274
|
-
},
|
|
275
|
-
greaterThan: {
|
|
276
|
-
fn: (value, field) => (value ? `${field} > ${value}` : undefined),
|
|
277
|
-
label: 'is greater than',
|
|
278
|
-
},
|
|
279
|
-
greaterThanOrEqualTo: {
|
|
280
|
-
fn: (value, field) => (value ? `${field} >= ${value}` : undefined),
|
|
281
|
-
label: 'is greater than or equal to',
|
|
282
|
-
},
|
|
283
|
-
includes: {
|
|
284
|
-
fn: (value, field) => (value ? `${field} match '*${value}*'` : undefined),
|
|
285
|
-
label: 'includes',
|
|
286
|
-
},
|
|
287
|
-
is: {
|
|
288
|
-
fn: (value, _field) => `${value}`,
|
|
289
|
-
label: 'is',
|
|
290
|
-
},
|
|
291
|
-
isNot: {
|
|
292
|
-
fn: (value, _field) => `!(${value})`,
|
|
293
|
-
label: 'is not',
|
|
294
|
-
},
|
|
295
|
-
lessThan: {
|
|
296
|
-
fn: (value, field) => (value ? `${field} < ${value}` : undefined),
|
|
297
|
-
label: 'is less than',
|
|
298
|
-
},
|
|
299
|
-
lessThanOrEqualTo: {
|
|
300
|
-
fn: (value, field) => (value ? `${field} <= ${value}` : undefined),
|
|
301
|
-
label: 'is less than or equal to',
|
|
302
|
-
},
|
|
303
|
-
notEmpty: {
|
|
304
|
-
fn: (_value, field) => `defined(${field})`,
|
|
305
|
-
hideInput: true,
|
|
306
|
-
label: 'is not empty',
|
|
307
|
-
},
|
|
308
|
-
references: {
|
|
309
|
-
fn: (value, _field) => (value ? `references('${value}')` : undefined),
|
|
310
|
-
label: 'includes',
|
|
311
|
-
},
|
|
312
|
-
}
|
package/src/constants.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type {AssetSourceComponentProps} from 'sanity'
|
|
2
|
-
|
|
3
|
-
import {divider, inputs} from './config/searchFacets'
|
|
4
|
-
import type {
|
|
5
|
-
SearchFacetInputProps,
|
|
6
|
-
SearchFacetDivider,
|
|
7
|
-
SearchFacetGroup,
|
|
8
|
-
OrderDirection,
|
|
9
|
-
} from './types'
|
|
10
|
-
|
|
11
|
-
export const SUPPORTED_ASSET_TYPES = [
|
|
12
|
-
'file',
|
|
13
|
-
'image',
|
|
14
|
-
] as const satisfies AssetSourceComponentProps['assetType'][]
|
|
15
|
-
|
|
16
|
-
// Sort order dropdown options
|
|
17
|
-
// null values are represented as menu dividers
|
|
18
|
-
export const ORDER_OPTIONS: ({direction: OrderDirection; field: string} | null)[] = [
|
|
19
|
-
{
|
|
20
|
-
direction: 'desc',
|
|
21
|
-
field: '_createdAt',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
direction: 'asc',
|
|
25
|
-
field: '_createdAt',
|
|
26
|
-
},
|
|
27
|
-
// Divider
|
|
28
|
-
null,
|
|
29
|
-
{
|
|
30
|
-
direction: 'desc',
|
|
31
|
-
field: '_updatedAt',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
direction: 'asc' as OrderDirection,
|
|
35
|
-
field: '_updatedAt',
|
|
36
|
-
},
|
|
37
|
-
// Divider
|
|
38
|
-
null,
|
|
39
|
-
{
|
|
40
|
-
direction: 'asc',
|
|
41
|
-
field: 'originalFilename',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
direction: 'desc',
|
|
45
|
-
field: 'originalFilename',
|
|
46
|
-
},
|
|
47
|
-
// Divider
|
|
48
|
-
null,
|
|
49
|
-
{
|
|
50
|
-
direction: 'desc',
|
|
51
|
-
field: 'size',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
direction: 'asc',
|
|
55
|
-
field: 'size',
|
|
56
|
-
},
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
export const FACETS: (SearchFacetDivider | SearchFacetGroup | SearchFacetInputProps)[] = [
|
|
60
|
-
inputs.tag,
|
|
61
|
-
divider,
|
|
62
|
-
inputs.inUse,
|
|
63
|
-
inputs.inCurrentDocument,
|
|
64
|
-
divider,
|
|
65
|
-
inputs.title,
|
|
66
|
-
inputs.altText,
|
|
67
|
-
inputs.creditLine,
|
|
68
|
-
inputs.description,
|
|
69
|
-
divider,
|
|
70
|
-
inputs.isOpaque,
|
|
71
|
-
divider,
|
|
72
|
-
inputs.fileName,
|
|
73
|
-
inputs.size,
|
|
74
|
-
inputs.type,
|
|
75
|
-
divider,
|
|
76
|
-
inputs.orientation,
|
|
77
|
-
inputs.width,
|
|
78
|
-
inputs.height,
|
|
79
|
-
]
|
|
80
|
-
|
|
81
|
-
export const GRID_TEMPLATE_COLUMNS = {
|
|
82
|
-
SMALL: '3rem 100px auto 1.5rem',
|
|
83
|
-
LARGE: '3rem 100px auto 5.5rem 5.5rem 3.5rem 8.5rem 4.75rem 2rem',
|
|
84
|
-
}
|
|
85
|
-
export const PANEL_HEIGHT = 32 // px
|
|
86
|
-
export const TAG_DOCUMENT_NAME = 'media.tag'
|
|
87
|
-
export const TAGS_PANEL_WIDTH = 250 // px
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {type ReactNode, createContext, useContext, useMemo} from 'react'
|
|
2
|
-
import type {AssetSourceComponentProps} from 'sanity'
|
|
3
|
-
|
|
4
|
-
type ContextProps = {
|
|
5
|
-
onSelect?: AssetSourceComponentProps['onSelect']
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
type Props = {
|
|
9
|
-
children: ReactNode
|
|
10
|
-
onSelect?: AssetSourceComponentProps['onSelect']
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const AssetSourceDispatchContext = createContext<ContextProps | undefined>(undefined)
|
|
14
|
-
|
|
15
|
-
export const AssetBrowserDispatchProvider = (props: Props) => {
|
|
16
|
-
const {children, onSelect} = props
|
|
17
|
-
|
|
18
|
-
const contextValue: ContextProps = useMemo(
|
|
19
|
-
() => ({
|
|
20
|
-
onSelect,
|
|
21
|
-
}),
|
|
22
|
-
[onSelect],
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<AssetSourceDispatchContext.Provider value={contextValue}>
|
|
27
|
-
{children}
|
|
28
|
-
</AssetSourceDispatchContext.Provider>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const useAssetSourceActions = () => {
|
|
33
|
-
const context = useContext(AssetSourceDispatchContext)
|
|
34
|
-
if (context === undefined) {
|
|
35
|
-
throw new Error('useAssetSourceActions must be used within an AssetSourceDispatchProvider')
|
|
36
|
-
}
|
|
37
|
-
return context
|
|
38
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {type ReactNode, createContext, useContext, useMemo} from 'react'
|
|
2
|
-
|
|
3
|
-
type ContextProps = {
|
|
4
|
-
open: () => void
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
children: ReactNode
|
|
9
|
-
open: () => void
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const DropzoneDispatchContext = createContext<ContextProps | undefined>(undefined)
|
|
13
|
-
|
|
14
|
-
export const DropzoneDispatchProvider = (props: Props) => {
|
|
15
|
-
const {children, open} = props
|
|
16
|
-
|
|
17
|
-
const contextValue: ContextProps = useMemo(() => ({open}), [open])
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<DropzoneDispatchContext.Provider value={contextValue}>
|
|
21
|
-
{children}
|
|
22
|
-
</DropzoneDispatchContext.Provider>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const useDropzoneActions = () => {
|
|
27
|
-
const context = useContext(DropzoneDispatchContext)
|
|
28
|
-
if (context === undefined) {
|
|
29
|
-
throw new Error('useDropzoneActions must be used within an DropzoneDispatchProvider')
|
|
30
|
-
}
|
|
31
|
-
return context
|
|
32
|
-
}
|