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,419 +0,0 @@
|
|
|
1
|
-
import {CheckmarkCircleIcon, EditIcon, WarningFilledIcon} from '@sanity/icons'
|
|
2
|
-
import {
|
|
3
|
-
Box,
|
|
4
|
-
Checkbox,
|
|
5
|
-
Container,
|
|
6
|
-
Flex,
|
|
7
|
-
Grid,
|
|
8
|
-
Spinner,
|
|
9
|
-
Text,
|
|
10
|
-
type ThemeColorSchemeKey,
|
|
11
|
-
Tooltip,
|
|
12
|
-
useMediaIndex,
|
|
13
|
-
} from '@sanity/ui'
|
|
14
|
-
import {formatRelative} from 'date-fns'
|
|
15
|
-
import filesize from 'filesize'
|
|
16
|
-
import {
|
|
17
|
-
memo,
|
|
18
|
-
type MouseEvent,
|
|
19
|
-
type RefObject,
|
|
20
|
-
useCallback,
|
|
21
|
-
useEffect,
|
|
22
|
-
useRef,
|
|
23
|
-
useState,
|
|
24
|
-
} from 'react'
|
|
25
|
-
import {useDispatch} from 'react-redux'
|
|
26
|
-
import {WithReferringDocuments, useColorSchemeValue} from 'sanity'
|
|
27
|
-
import {styled, css} from 'styled-components'
|
|
28
|
-
|
|
29
|
-
import {GRID_TEMPLATE_COLUMNS} from '../../constants'
|
|
30
|
-
import {useAssetSourceActions} from '../../contexts/AssetSourceDispatchContext'
|
|
31
|
-
import useKeyPress from '../../hooks/useKeyPress'
|
|
32
|
-
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
33
|
-
import {assetsActions, selectAssetById} from '../../modules/assets'
|
|
34
|
-
import {dialogActions} from '../../modules/dialog'
|
|
35
|
-
import getAssetResolution from '../../utils/getAssetResolution'
|
|
36
|
-
import {getSchemeColor} from '../../utils/getSchemeColor'
|
|
37
|
-
import {getUniqueDocuments} from '../../utils/getUniqueDocuments'
|
|
38
|
-
import imageDprUrl from '../../utils/imageDprUrl'
|
|
39
|
-
import {isFileAsset, isImageAsset} from '../../utils/typeGuards'
|
|
40
|
-
import FileIcon from '../FileIcon'
|
|
41
|
-
import Image from '../Image'
|
|
42
|
-
|
|
43
|
-
// Duration (ms) to wait before reference counts (and associated listeners) are rendered
|
|
44
|
-
const REFERENCE_COUNT_VISIBILITY_DELAY = 750
|
|
45
|
-
|
|
46
|
-
type Props = {
|
|
47
|
-
id: string
|
|
48
|
-
selected: boolean
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const ContainerGrid = styled<
|
|
52
|
-
typeof Grid,
|
|
53
|
-
{$selected?: boolean; $scheme: ThemeColorSchemeKey; $updating?: boolean}
|
|
54
|
-
>(Grid)(({$scheme, $selected, $updating}) => {
|
|
55
|
-
return css`
|
|
56
|
-
align-items: center;
|
|
57
|
-
cursor: ${$selected ? 'default' : 'pointer'};
|
|
58
|
-
height: 100%;
|
|
59
|
-
pointer-events: ${$updating ? 'none' : 'auto'};
|
|
60
|
-
user-select: none;
|
|
61
|
-
white-space: nowrap;
|
|
62
|
-
|
|
63
|
-
${!$updating &&
|
|
64
|
-
css`
|
|
65
|
-
@media (hover: hover) and (pointer: fine) {
|
|
66
|
-
&:hover {
|
|
67
|
-
background: ${getSchemeColor($scheme, 'bg')};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
`}
|
|
71
|
-
`
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const ContextActionContainer = styled<typeof Flex, {$scheme: ThemeColorSchemeKey}>(Flex)(({
|
|
75
|
-
$scheme,
|
|
76
|
-
}) => {
|
|
77
|
-
return css`
|
|
78
|
-
cursor: pointer;
|
|
79
|
-
@media (hover: hover) and (pointer: fine) {
|
|
80
|
-
&:hover {
|
|
81
|
-
background: ${getSchemeColor($scheme, 'bg2')};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
`
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const StyledWarningIcon = styled(WarningFilledIcon)(({theme}) => {
|
|
88
|
-
return {
|
|
89
|
-
color: theme.sanity.color.spot.red,
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
const TableRowAsset = (props: Props) => {
|
|
94
|
-
const {id, selected} = props
|
|
95
|
-
|
|
96
|
-
const scheme = useColorSchemeValue()
|
|
97
|
-
|
|
98
|
-
const shiftPressed: RefObject<boolean> = useKeyPress('shift')
|
|
99
|
-
|
|
100
|
-
const [referenceCountVisible, setReferenceCountVisible] = useState(false)
|
|
101
|
-
const refCountVisibleTimeout = useRef<ReturnType<typeof window.setTimeout>>(null)
|
|
102
|
-
|
|
103
|
-
const dispatch = useDispatch()
|
|
104
|
-
const lastPicked = useTypedSelector((state) => state.assets.lastPicked)
|
|
105
|
-
const item = useTypedSelector((state) => selectAssetById(state, id))
|
|
106
|
-
|
|
107
|
-
const mediaIndex = useMediaIndex()
|
|
108
|
-
|
|
109
|
-
const asset = item?.asset
|
|
110
|
-
const error = item?.error
|
|
111
|
-
const isOpaque = item?.asset?.metadata?.isOpaque
|
|
112
|
-
const picked = item?.picked
|
|
113
|
-
const updating = item?.updating
|
|
114
|
-
|
|
115
|
-
const {onSelect} = useAssetSourceActions()
|
|
116
|
-
|
|
117
|
-
const handleContextActionClick = useCallback(
|
|
118
|
-
(e: MouseEvent<HTMLDivElement>) => {
|
|
119
|
-
e.stopPropagation()
|
|
120
|
-
|
|
121
|
-
if (!asset) return
|
|
122
|
-
if (onSelect) {
|
|
123
|
-
dispatch(dialogActions.showAssetEdit({assetId: asset._id}))
|
|
124
|
-
} else if (shiftPressed.current && !picked) {
|
|
125
|
-
dispatch(assetsActions.pickRange({startId: lastPicked || asset._id, endId: asset._id}))
|
|
126
|
-
} else {
|
|
127
|
-
dispatch(assetsActions.pick({assetId: asset._id, picked: !picked}))
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
[asset, dispatch, lastPicked, onSelect, picked, shiftPressed],
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
const handleClick = useCallback(
|
|
134
|
-
(e: MouseEvent<HTMLDivElement>) => {
|
|
135
|
-
e.stopPropagation()
|
|
136
|
-
|
|
137
|
-
if (!asset) return
|
|
138
|
-
if (onSelect) {
|
|
139
|
-
onSelect([{kind: 'assetDocumentId', value: asset._id}])
|
|
140
|
-
} else if (shiftPressed.current) {
|
|
141
|
-
if (picked) {
|
|
142
|
-
dispatch(assetsActions.pick({assetId: asset._id, picked: !picked}))
|
|
143
|
-
} else {
|
|
144
|
-
dispatch(assetsActions.pickRange({startId: lastPicked || asset._id, endId: asset._id}))
|
|
145
|
-
}
|
|
146
|
-
} else {
|
|
147
|
-
dispatch(dialogActions.showAssetEdit({assetId: asset._id}))
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
[asset, dispatch, lastPicked, onSelect, picked, shiftPressed],
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
const opacityCell = updating ? 0.5 : 1
|
|
154
|
-
const opacityPreview = selected || updating ? 0.1 : 1
|
|
155
|
-
|
|
156
|
-
// Display reference count after an initial delay to prevent over-eager fetching
|
|
157
|
-
useEffect(() => {
|
|
158
|
-
refCountVisibleTimeout.current = setTimeout(
|
|
159
|
-
() => setReferenceCountVisible(true),
|
|
160
|
-
REFERENCE_COUNT_VISIBILITY_DELAY,
|
|
161
|
-
)
|
|
162
|
-
return () => {
|
|
163
|
-
if (refCountVisibleTimeout.current) {
|
|
164
|
-
clearTimeout(refCountVisibleTimeout.current)
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}, [])
|
|
168
|
-
|
|
169
|
-
// Short circuit if no asset is available
|
|
170
|
-
if (!asset) {
|
|
171
|
-
return null
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return (
|
|
175
|
-
<ContainerGrid
|
|
176
|
-
onClick={selected ? undefined : handleClick}
|
|
177
|
-
$scheme={scheme}
|
|
178
|
-
$selected={selected}
|
|
179
|
-
style={{
|
|
180
|
-
gridColumnGap: mediaIndex < 3 ? 0 : '16px',
|
|
181
|
-
gridRowGap: 0,
|
|
182
|
-
gridTemplateColumns:
|
|
183
|
-
mediaIndex < 3 ? GRID_TEMPLATE_COLUMNS.SMALL : GRID_TEMPLATE_COLUMNS.LARGE,
|
|
184
|
-
gridTemplateRows: mediaIndex < 3 ? 'auto' : '1fr',
|
|
185
|
-
}}
|
|
186
|
-
$updating={item.updating}
|
|
187
|
-
>
|
|
188
|
-
{/* Picked checkbox */}
|
|
189
|
-
<ContextActionContainer
|
|
190
|
-
onClick={handleContextActionClick}
|
|
191
|
-
$scheme={scheme}
|
|
192
|
-
style={{
|
|
193
|
-
alignItems: 'center',
|
|
194
|
-
gridColumn: 1,
|
|
195
|
-
gridRowStart: 1,
|
|
196
|
-
gridRowEnd: 'span 5',
|
|
197
|
-
height: '100%',
|
|
198
|
-
justifyContent: 'center',
|
|
199
|
-
opacity: opacityCell,
|
|
200
|
-
position: 'relative',
|
|
201
|
-
}}
|
|
202
|
-
>
|
|
203
|
-
{onSelect ? (
|
|
204
|
-
<EditIcon
|
|
205
|
-
style={{
|
|
206
|
-
flexShrink: 0,
|
|
207
|
-
opacity: 0.5,
|
|
208
|
-
}}
|
|
209
|
-
/>
|
|
210
|
-
) : (
|
|
211
|
-
<Checkbox
|
|
212
|
-
checked={picked}
|
|
213
|
-
readOnly
|
|
214
|
-
style={{
|
|
215
|
-
pointerEvents: 'none', // TODO: consider alternative for usability
|
|
216
|
-
transform: 'scale(0.8)',
|
|
217
|
-
}}
|
|
218
|
-
/>
|
|
219
|
-
)}
|
|
220
|
-
</ContextActionContainer>
|
|
221
|
-
|
|
222
|
-
{/* Preview image + spinner */}
|
|
223
|
-
<Box
|
|
224
|
-
style={{
|
|
225
|
-
gridColumn: 2,
|
|
226
|
-
gridRowStart: 1,
|
|
227
|
-
gridRowEnd: 'span 5',
|
|
228
|
-
height: '90px',
|
|
229
|
-
width: '100px',
|
|
230
|
-
}}
|
|
231
|
-
>
|
|
232
|
-
<Flex align="center" justify="center" style={{height: '100%', position: 'relative'}}>
|
|
233
|
-
<Box style={{height: '100%', opacity: opacityPreview, position: 'relative'}}>
|
|
234
|
-
{/* File icon */}
|
|
235
|
-
{isFileAsset(asset) && <FileIcon extension={asset.extension} width="40px" />}
|
|
236
|
-
|
|
237
|
-
{/* Image */}
|
|
238
|
-
{isImageAsset(asset) && (
|
|
239
|
-
<Image
|
|
240
|
-
draggable={false}
|
|
241
|
-
$scheme={scheme}
|
|
242
|
-
$showCheckerboard={!isOpaque}
|
|
243
|
-
src={imageDprUrl(asset, {height: 100, width: 100})}
|
|
244
|
-
/>
|
|
245
|
-
)}
|
|
246
|
-
</Box>
|
|
247
|
-
|
|
248
|
-
{/* Spinner */}
|
|
249
|
-
{updating && (
|
|
250
|
-
<Flex
|
|
251
|
-
align="center"
|
|
252
|
-
justify="center"
|
|
253
|
-
style={{
|
|
254
|
-
height: '100%',
|
|
255
|
-
left: 0,
|
|
256
|
-
position: 'absolute',
|
|
257
|
-
top: 0,
|
|
258
|
-
width: '100%',
|
|
259
|
-
}}
|
|
260
|
-
>
|
|
261
|
-
<Spinner />
|
|
262
|
-
</Flex>
|
|
263
|
-
)}
|
|
264
|
-
|
|
265
|
-
{/* Selected check icon */}
|
|
266
|
-
{selected && !updating && (
|
|
267
|
-
<Flex
|
|
268
|
-
align="center"
|
|
269
|
-
justify="center"
|
|
270
|
-
style={{
|
|
271
|
-
height: '100%',
|
|
272
|
-
left: 0,
|
|
273
|
-
position: 'absolute',
|
|
274
|
-
top: 0,
|
|
275
|
-
width: '100%',
|
|
276
|
-
}}
|
|
277
|
-
>
|
|
278
|
-
<Text size={2}>
|
|
279
|
-
<CheckmarkCircleIcon />
|
|
280
|
-
</Text>
|
|
281
|
-
</Flex>
|
|
282
|
-
)}
|
|
283
|
-
</Flex>
|
|
284
|
-
</Box>
|
|
285
|
-
|
|
286
|
-
{/* Filename */}
|
|
287
|
-
<Box
|
|
288
|
-
marginLeft={mediaIndex < 3 ? 3 : 0}
|
|
289
|
-
style={{
|
|
290
|
-
gridColumn: 3,
|
|
291
|
-
gridRow: mediaIndex < 3 ? 2 : 'auto',
|
|
292
|
-
opacity: opacityCell,
|
|
293
|
-
}}
|
|
294
|
-
>
|
|
295
|
-
<Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
|
|
296
|
-
{asset.originalFilename}
|
|
297
|
-
</Text>
|
|
298
|
-
</Box>
|
|
299
|
-
|
|
300
|
-
{/* Resolution */}
|
|
301
|
-
<Box
|
|
302
|
-
marginLeft={mediaIndex < 3 ? 3 : 0}
|
|
303
|
-
style={{
|
|
304
|
-
gridColumn: mediaIndex < 3 ? 3 : 4,
|
|
305
|
-
gridRow: mediaIndex < 3 ? 3 : 'auto',
|
|
306
|
-
opacity: opacityCell,
|
|
307
|
-
}}
|
|
308
|
-
>
|
|
309
|
-
<Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
|
|
310
|
-
{isImageAsset(asset) && getAssetResolution(asset)}
|
|
311
|
-
</Text>
|
|
312
|
-
</Box>
|
|
313
|
-
|
|
314
|
-
{/* MIME type */}
|
|
315
|
-
<Box
|
|
316
|
-
style={{
|
|
317
|
-
display: mediaIndex < 3 ? 'none' : 'block',
|
|
318
|
-
gridColumn: 5,
|
|
319
|
-
gridRow: 'auto',
|
|
320
|
-
opacity: opacityCell,
|
|
321
|
-
}}
|
|
322
|
-
>
|
|
323
|
-
<Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
|
|
324
|
-
{asset.mimeType}
|
|
325
|
-
</Text>
|
|
326
|
-
</Box>
|
|
327
|
-
|
|
328
|
-
{/* Size */}
|
|
329
|
-
<Box
|
|
330
|
-
style={{
|
|
331
|
-
display: mediaIndex < 3 ? 'none' : 'block',
|
|
332
|
-
gridColumn: 6,
|
|
333
|
-
gridRow: 'auto',
|
|
334
|
-
opacity: opacityCell,
|
|
335
|
-
}}
|
|
336
|
-
>
|
|
337
|
-
<Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
|
|
338
|
-
{filesize(asset.size, {base: 10, round: 0})}
|
|
339
|
-
</Text>
|
|
340
|
-
</Box>
|
|
341
|
-
|
|
342
|
-
{/* Last updated */}
|
|
343
|
-
<Box
|
|
344
|
-
marginLeft={mediaIndex < 3 ? 3 : 0}
|
|
345
|
-
style={{
|
|
346
|
-
gridColumn: mediaIndex < 3 ? 3 : 7,
|
|
347
|
-
gridRow: mediaIndex < 3 ? 4 : 'auto',
|
|
348
|
-
opacity: opacityCell,
|
|
349
|
-
}}
|
|
350
|
-
>
|
|
351
|
-
<Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
|
|
352
|
-
{formatRelative(new Date(asset._updatedAt), new Date())}
|
|
353
|
-
</Text>
|
|
354
|
-
</Box>
|
|
355
|
-
|
|
356
|
-
{/* References */}
|
|
357
|
-
<Box
|
|
358
|
-
style={{
|
|
359
|
-
display: mediaIndex < 3 ? 'none' : 'block',
|
|
360
|
-
gridColumn: 8,
|
|
361
|
-
gridRow: 'auto',
|
|
362
|
-
opacity: opacityCell,
|
|
363
|
-
}}
|
|
364
|
-
>
|
|
365
|
-
<Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
|
|
366
|
-
{referenceCountVisible ? (
|
|
367
|
-
<WithReferringDocuments id={id}>
|
|
368
|
-
{({isLoading, referringDocuments}) => {
|
|
369
|
-
const uniqueDocuments = getUniqueDocuments(referringDocuments)
|
|
370
|
-
return isLoading ? (
|
|
371
|
-
<>-</>
|
|
372
|
-
) : (
|
|
373
|
-
<>{Array.isArray(uniqueDocuments) ? uniqueDocuments.length : 0}</>
|
|
374
|
-
)
|
|
375
|
-
}}
|
|
376
|
-
</WithReferringDocuments>
|
|
377
|
-
) : (
|
|
378
|
-
<>-</>
|
|
379
|
-
)}
|
|
380
|
-
</Text>
|
|
381
|
-
</Box>
|
|
382
|
-
|
|
383
|
-
{/* Error */}
|
|
384
|
-
<Flex
|
|
385
|
-
align="center"
|
|
386
|
-
justify="center"
|
|
387
|
-
style={{
|
|
388
|
-
gridColumn: mediaIndex < 3 ? 4 : 9,
|
|
389
|
-
gridRowStart: '1',
|
|
390
|
-
gridRowEnd: mediaIndex < 3 ? 'span 5' : 'auto',
|
|
391
|
-
opacity: opacityCell,
|
|
392
|
-
}}
|
|
393
|
-
>
|
|
394
|
-
{/* TODO: DRY */}
|
|
395
|
-
{/* Error button */}
|
|
396
|
-
{error && (
|
|
397
|
-
<Box padding={2}>
|
|
398
|
-
<Tooltip
|
|
399
|
-
animate
|
|
400
|
-
content={
|
|
401
|
-
<Container padding={2} width={0}>
|
|
402
|
-
<Text size={1}>{error}</Text>
|
|
403
|
-
</Container>
|
|
404
|
-
}
|
|
405
|
-
placement="left"
|
|
406
|
-
portal
|
|
407
|
-
>
|
|
408
|
-
<Text size={1}>
|
|
409
|
-
<StyledWarningIcon color="critical" />
|
|
410
|
-
</Text>
|
|
411
|
-
</Tooltip>
|
|
412
|
-
</Box>
|
|
413
|
-
)}
|
|
414
|
-
</Flex>
|
|
415
|
-
</ContainerGrid>
|
|
416
|
-
)
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
export default memo(TableRowAsset)
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import {CloseIcon} from '@sanity/icons'
|
|
2
|
-
import {Box, Button, Flex, Grid, Stack, Text, useMediaIndex} from '@sanity/ui'
|
|
3
|
-
import filesize from 'filesize'
|
|
4
|
-
import {useDispatch} from 'react-redux'
|
|
5
|
-
import {useColorSchemeValue} from 'sanity'
|
|
6
|
-
|
|
7
|
-
import {GRID_TEMPLATE_COLUMNS} from '../../constants'
|
|
8
|
-
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
9
|
-
import {selectUploadById, uploadsActions} from '../../modules/uploads'
|
|
10
|
-
import {getSchemeColor} from '../../utils/getSchemeColor'
|
|
11
|
-
import FileIcon from '../FileIcon'
|
|
12
|
-
import Image from '../Image'
|
|
13
|
-
|
|
14
|
-
type Props = {
|
|
15
|
-
id: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const TableRowUpload = (props: Props) => {
|
|
19
|
-
const {id} = props
|
|
20
|
-
|
|
21
|
-
const scheme = useColorSchemeValue()
|
|
22
|
-
|
|
23
|
-
// Redux
|
|
24
|
-
const dispatch = useDispatch()
|
|
25
|
-
const item = useTypedSelector((state) => selectUploadById(state, id))
|
|
26
|
-
|
|
27
|
-
const mediaIndex = useMediaIndex()
|
|
28
|
-
|
|
29
|
-
if (!item) {
|
|
30
|
-
return null
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const fileSize = filesize(item.size, {base: 10, round: 0})
|
|
34
|
-
const percentLoaded = Math.round(item.percent || 0) // (0 - 100)
|
|
35
|
-
|
|
36
|
-
const isComplete = item.status === 'complete'
|
|
37
|
-
const isUploading = item.status === 'uploading'
|
|
38
|
-
const isQueued = item.status === 'queued'
|
|
39
|
-
|
|
40
|
-
let status
|
|
41
|
-
if (isComplete) {
|
|
42
|
-
status = 'Verifying'
|
|
43
|
-
}
|
|
44
|
-
if (isUploading) {
|
|
45
|
-
status = `${percentLoaded}%`
|
|
46
|
-
}
|
|
47
|
-
if (isQueued) {
|
|
48
|
-
status = 'Queued'
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Callbacks
|
|
52
|
-
const handleCancelUpload = () => {
|
|
53
|
-
dispatch(uploadsActions.uploadCancel({hash: item.hash}))
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<Grid
|
|
58
|
-
style={{
|
|
59
|
-
alignItems: 'center',
|
|
60
|
-
background: getSchemeColor(scheme, 'bg'),
|
|
61
|
-
gridColumnGap: mediaIndex < 3 ? 0 : '16px',
|
|
62
|
-
gridRowGap: 0,
|
|
63
|
-
gridTemplateColumns:
|
|
64
|
-
mediaIndex < 3 ? GRID_TEMPLATE_COLUMNS.SMALL : GRID_TEMPLATE_COLUMNS.LARGE,
|
|
65
|
-
gridTemplateRows: mediaIndex < 3 ? 'auto' : '1fr',
|
|
66
|
-
height: '100%',
|
|
67
|
-
position: 'relative',
|
|
68
|
-
}}
|
|
69
|
-
>
|
|
70
|
-
{/* Progress bar */}
|
|
71
|
-
<div
|
|
72
|
-
style={{
|
|
73
|
-
background: 'var(--card-fg-color)',
|
|
74
|
-
bottom: 0,
|
|
75
|
-
height: '1px',
|
|
76
|
-
left: 0,
|
|
77
|
-
position: 'absolute',
|
|
78
|
-
width: '100%',
|
|
79
|
-
transform: `scaleX(${percentLoaded * 0.01})`,
|
|
80
|
-
transformOrigin: 'bottom left',
|
|
81
|
-
transition: 'all 1000ms ease-out',
|
|
82
|
-
}}
|
|
83
|
-
/>
|
|
84
|
-
|
|
85
|
-
{/* Image */}
|
|
86
|
-
<Box
|
|
87
|
-
style={{
|
|
88
|
-
gridColumn: 2,
|
|
89
|
-
gridRowStart: mediaIndex < 3 ? 1 : 'auto',
|
|
90
|
-
gridRowEnd: mediaIndex < 3 ? 'span 4' : 'auto',
|
|
91
|
-
height: '90px',
|
|
92
|
-
width: '100px',
|
|
93
|
-
}}
|
|
94
|
-
>
|
|
95
|
-
<Box style={{height: '100%', position: 'relative'}}>
|
|
96
|
-
{item.assetType === 'image' && item?.objectUrl && (
|
|
97
|
-
<Image
|
|
98
|
-
draggable={false}
|
|
99
|
-
$scheme={scheme}
|
|
100
|
-
src={item.objectUrl}
|
|
101
|
-
style={{opacity: 0.25}}
|
|
102
|
-
/>
|
|
103
|
-
)}
|
|
104
|
-
|
|
105
|
-
{item.assetType === 'file' && (
|
|
106
|
-
<div style={{height: '100%', opacity: 0.1}}>
|
|
107
|
-
<FileIcon width="40px" />
|
|
108
|
-
</div>
|
|
109
|
-
)}
|
|
110
|
-
|
|
111
|
-
{/*
|
|
112
|
-
Cancel upload button.
|
|
113
|
-
Assets will only have a `complete` status _after_ it has been created on your dataset.
|
|
114
|
-
As such, we also hide the cancel button when `percentLoaded === 100`, as cancelling when the asset
|
|
115
|
-
has been fully uploaded (even with a status of `progress`) won't stop the asset from being created.
|
|
116
|
-
*/}
|
|
117
|
-
{!isComplete && percentLoaded !== 100 && (
|
|
118
|
-
<Flex
|
|
119
|
-
align="center"
|
|
120
|
-
justify="center"
|
|
121
|
-
style={{
|
|
122
|
-
position: 'absolute',
|
|
123
|
-
height: '100%',
|
|
124
|
-
left: 0,
|
|
125
|
-
top: 0,
|
|
126
|
-
width: '100%',
|
|
127
|
-
}}
|
|
128
|
-
>
|
|
129
|
-
<Button
|
|
130
|
-
fontSize={3}
|
|
131
|
-
icon={CloseIcon}
|
|
132
|
-
mode="bleed"
|
|
133
|
-
onClick={handleCancelUpload}
|
|
134
|
-
padding={2}
|
|
135
|
-
style={{background: 'none', boxShadow: 'none'}}
|
|
136
|
-
tone="critical"
|
|
137
|
-
/>
|
|
138
|
-
</Flex>
|
|
139
|
-
)}
|
|
140
|
-
</Box>
|
|
141
|
-
</Box>
|
|
142
|
-
|
|
143
|
-
{/* Filename */}
|
|
144
|
-
<Box
|
|
145
|
-
style={{
|
|
146
|
-
gridColumn: mediaIndex < 3 ? 3 : '3/8',
|
|
147
|
-
gridRow: mediaIndex < 3 ? '2/4' : 'auto',
|
|
148
|
-
marginLeft: mediaIndex < 3 ? 3 : 0,
|
|
149
|
-
}}
|
|
150
|
-
>
|
|
151
|
-
<Stack space={3}>
|
|
152
|
-
<Text muted size={1} textOverflow="ellipsis">
|
|
153
|
-
{item.name} ({fileSize})
|
|
154
|
-
</Text>
|
|
155
|
-
<Text size={1} textOverflow="ellipsis" weight="semibold">
|
|
156
|
-
{status}
|
|
157
|
-
</Text>
|
|
158
|
-
</Stack>
|
|
159
|
-
</Box>
|
|
160
|
-
</Grid>
|
|
161
|
-
)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export default TableRowUpload
|