sanity-plugin-media 4.3.5 → 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.
Files changed (166) hide show
  1. package/dist/index.d.ts +190 -413
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +2532 -3564
  4. package/dist/index.js.map +1 -1
  5. package/package.json +29 -35
  6. package/dist/index.cjs +0 -5753
  7. package/dist/index.cjs.map +0 -1
  8. package/dist/index.d.cts +0 -462
  9. package/sanity.json +0 -8
  10. package/src/__tests__/fixtures/createEpicTestStore.ts +0 -28
  11. package/src/__tests__/fixtures/listenMock.ts +0 -9
  12. package/src/__tests__/fixtures/mockSanityClient.ts +0 -84
  13. package/src/__tests__/fixtures/renderWithProviders.tsx +0 -55
  14. package/src/__tests__/fixtures/rootState.ts +0 -27
  15. package/src/__tests__/fixtures/withinDialog.ts +0 -28
  16. package/src/components/AssetGridVirtualized/index.tsx +0 -94
  17. package/src/components/AssetMetadata/index.tsx +0 -122
  18. package/src/components/AssetTableVirtualized/index.tsx +0 -73
  19. package/src/components/AutoTagInputWrapper/index.tsx +0 -87
  20. package/src/components/Browser/Browser.test.tsx +0 -45
  21. package/src/components/Browser/index.tsx +0 -90
  22. package/src/components/Browser/useBrowserInit.ts +0 -126
  23. package/src/components/ButtonAssetCopy/index.tsx +0 -65
  24. package/src/components/ButtonViewGroup/index.tsx +0 -39
  25. package/src/components/CardAsset/CardAsset.test.tsx +0 -323
  26. package/src/components/CardAsset/index.tsx +0 -290
  27. package/src/components/CardUpload/index.tsx +0 -161
  28. package/src/components/Controls/index.tsx +0 -136
  29. package/src/components/DebugControls/index.tsx +0 -80
  30. package/src/components/Dialog/index.tsx +0 -11
  31. package/src/components/DialogAssetEdit/Details.tsx +0 -181
  32. package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +0 -216
  33. package/src/components/DialogAssetEdit/index.tsx +0 -492
  34. package/src/components/DialogConfirm/index.tsx +0 -88
  35. package/src/components/DialogSearchFacets/index.tsx +0 -42
  36. package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
  37. package/src/components/DialogTagCreate/index.tsx +0 -103
  38. package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
  39. package/src/components/DialogTagEdit/index.tsx +0 -190
  40. package/src/components/DialogTags/index.tsx +0 -45
  41. package/src/components/Dialogs/index.tsx +0 -76
  42. package/src/components/DocumentList/index.tsx +0 -62
  43. package/src/components/FileAssetPreview/index.tsx +0 -37
  44. package/src/components/FileIcon/index.tsx +0 -43
  45. package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +0 -63
  46. package/src/components/FormBuilderTool/index.tsx +0 -69
  47. package/src/components/FormFieldInputLabel/index.tsx +0 -66
  48. package/src/components/FormFieldInputTags/index.tsx +0 -98
  49. package/src/components/FormFieldInputText/index.tsx +0 -41
  50. package/src/components/FormFieldInputTextarea/index.tsx +0 -43
  51. package/src/components/FormSubmitButton/index.tsx +0 -59
  52. package/src/components/Header/index.tsx +0 -80
  53. package/src/components/Image/index.tsx +0 -41
  54. package/src/components/Items/index.tsx +0 -68
  55. package/src/components/Notifications/index.tsx +0 -24
  56. package/src/components/OrderSelect/index.tsx +0 -66
  57. package/src/components/PickedBar/index.tsx +0 -77
  58. package/src/components/Progress/index.tsx +0 -38
  59. package/src/components/ReduxProvider/index.tsx +0 -96
  60. package/src/components/SearchFacet/index.tsx +0 -66
  61. package/src/components/SearchFacetNumber/index.tsx +0 -133
  62. package/src/components/SearchFacetSelect/index.tsx +0 -110
  63. package/src/components/SearchFacetString/index.tsx +0 -88
  64. package/src/components/SearchFacetTags/index.tsx +0 -121
  65. package/src/components/SearchFacets/index.tsx +0 -72
  66. package/src/components/SearchFacetsControl/index.tsx +0 -140
  67. package/src/components/TableHeader/index.tsx +0 -110
  68. package/src/components/TableHeaderItem/index.tsx +0 -61
  69. package/src/components/TableRowAsset/index.tsx +0 -420
  70. package/src/components/TableRowUpload/index.tsx +0 -164
  71. package/src/components/Tag/index.tsx +0 -200
  72. package/src/components/TagIcon/index.tsx +0 -22
  73. package/src/components/TagView/index.tsx +0 -39
  74. package/src/components/TagViewHeader/index.tsx +0 -70
  75. package/src/components/TagsPanel/index.tsx +0 -40
  76. package/src/components/TagsVirtualized/index.tsx +0 -160
  77. package/src/components/TextInputNumber/index.tsx +0 -32
  78. package/src/components/TextInputSearch/index.tsx +0 -60
  79. package/src/components/Tool/index.tsx +0 -13
  80. package/src/components/UploadDropzone/UploadDropzone.test.tsx +0 -40
  81. package/src/components/UploadDropzone/index.tsx +0 -173
  82. package/src/config/orders.ts +0 -28
  83. package/src/config/searchFacets.ts +0 -312
  84. package/src/constants.ts +0 -87
  85. package/src/contexts/AssetSourceDispatchContext.tsx +0 -37
  86. package/src/contexts/DropzoneDispatchContext.tsx +0 -34
  87. package/src/contexts/ToolOptionsContext.tsx +0 -65
  88. package/src/formSchema/index.test.ts +0 -56
  89. package/src/formSchema/index.ts +0 -39
  90. package/src/hooks/useBreakpointIndex.ts +0 -49
  91. package/src/hooks/useKeyPress.ts +0 -39
  92. package/src/hooks/useOnScreen.ts +0 -34
  93. package/src/hooks/usePortalPopoverProps.ts +0 -13
  94. package/src/hooks/useTypedSelector.ts +0 -7
  95. package/src/hooks/useVersionedClient.ts +0 -6
  96. package/src/index.ts +0 -5
  97. package/src/modules/assets/actions.ts +0 -42
  98. package/src/modules/assets/deleteAndUpdateEpics.test.ts +0 -87
  99. package/src/modules/assets/fetchEpic.test.ts +0 -73
  100. package/src/modules/assets/index.ts +0 -825
  101. package/src/modules/assets/reducer.test.ts +0 -91
  102. package/src/modules/assets/tagsAndListenerEpics.test.ts +0 -206
  103. package/src/modules/debug/index.ts +0 -28
  104. package/src/modules/dialog/actions.ts +0 -10
  105. package/src/modules/dialog/epics.test.ts +0 -168
  106. package/src/modules/dialog/index.ts +0 -238
  107. package/src/modules/dialog/reducer.test.ts +0 -185
  108. package/src/modules/index.ts +0 -124
  109. package/src/modules/notifications/epics.test.ts +0 -374
  110. package/src/modules/notifications/index.ts +0 -199
  111. package/src/modules/notifications/reducer.test.ts +0 -54
  112. package/src/modules/search/index.test.ts +0 -36
  113. package/src/modules/search/index.ts +0 -167
  114. package/src/modules/selected/index.ts +0 -22
  115. package/src/modules/selectors.test.ts +0 -21
  116. package/src/modules/selectors.ts +0 -17
  117. package/src/modules/tags/epics.test.ts +0 -96
  118. package/src/modules/tags/index.test.ts +0 -42
  119. package/src/modules/tags/index.ts +0 -540
  120. package/src/modules/types.ts +0 -3
  121. package/src/modules/uploads/actions.ts +0 -13
  122. package/src/modules/uploads/epics.test.ts +0 -109
  123. package/src/modules/uploads/index.test.ts +0 -59
  124. package/src/modules/uploads/index.ts +0 -282
  125. package/src/operators/checkTagName.test.ts +0 -29
  126. package/src/operators/checkTagName.ts +0 -33
  127. package/src/operators/debugThrottle.ts +0 -25
  128. package/src/plugin.tsx +0 -54
  129. package/src/schemas/tag.ts +0 -28
  130. package/src/styled/GlobalStyles/index.tsx +0 -40
  131. package/src/styled/react-select/creatable.tsx +0 -184
  132. package/src/styled/react-select/single.tsx +0 -184
  133. package/src/types/index.ts +0 -379
  134. package/src/types/sanity-ui.d.ts +0 -6
  135. package/src/utils/applyMediaTags.ts +0 -87
  136. package/src/utils/blocksToText.test.ts +0 -43
  137. package/src/utils/blocksToText.ts +0 -27
  138. package/src/utils/constructFilter.test.ts +0 -120
  139. package/src/utils/constructFilter.ts +0 -98
  140. package/src/utils/generatePreviewBlobUrl.test.ts +0 -70
  141. package/src/utils/generatePreviewBlobUrl.ts +0 -53
  142. package/src/utils/getAssetResolution.test.ts +0 -13
  143. package/src/utils/getAssetResolution.ts +0 -7
  144. package/src/utils/getDocumentAssetIds.test.ts +0 -50
  145. package/src/utils/getDocumentAssetIds.ts +0 -35
  146. package/src/utils/getSchemeColor.test.ts +0 -12
  147. package/src/utils/getSchemeColor.ts +0 -43
  148. package/src/utils/getTagSelectOptions.test.ts +0 -44
  149. package/src/utils/getTagSelectOptions.ts +0 -16
  150. package/src/utils/getUniqueDocuments.test.ts +0 -26
  151. package/src/utils/getUniqueDocuments.ts +0 -15
  152. package/src/utils/imageDprUrl.test.ts +0 -46
  153. package/src/utils/imageDprUrl.ts +0 -27
  154. package/src/utils/isSupportedAssetType.test.ts +0 -16
  155. package/src/utils/isSupportedAssetType.ts +0 -15
  156. package/src/utils/mediaField.ts +0 -73
  157. package/src/utils/sanitizeFormData.test.ts +0 -59
  158. package/src/utils/sanitizeFormData.ts +0 -26
  159. package/src/utils/typeGuards.test.ts +0 -18
  160. package/src/utils/typeGuards.ts +0 -9
  161. package/src/utils/uploadSanityAsset.test.ts +0 -29
  162. package/src/utils/uploadSanityAsset.ts +0 -97
  163. package/src/utils/withMaxConcurrency.test.ts +0 -43
  164. package/src/utils/withMaxConcurrency.ts +0 -55
  165. package/src/utils/zodFormResolver.ts +0 -17
  166. package/v2-incompatible.js +0 -11
@@ -1,420 +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
- // eslint-disable-next-line complexity
94
- const TableRowAsset = (props: Props) => {
95
- const {id, selected} = props
96
-
97
- const scheme = useColorSchemeValue()
98
-
99
- const shiftPressed: RefObject<boolean> = useKeyPress('shift')
100
-
101
- const [referenceCountVisible, setReferenceCountVisible] = useState(false)
102
- const refCountVisibleTimeout = useRef<ReturnType<typeof window.setTimeout>>(null)
103
-
104
- const dispatch = useDispatch()
105
- const lastPicked = useTypedSelector((state) => state.assets.lastPicked)
106
- const item = useTypedSelector((state) => selectAssetById(state, id))
107
-
108
- const mediaIndex = useMediaIndex()
109
-
110
- const asset = item?.asset
111
- const error = item?.error
112
- const isOpaque = item?.asset?.metadata?.isOpaque
113
- const picked = item?.picked
114
- const updating = item?.updating
115
-
116
- const {onSelect} = useAssetSourceActions()
117
-
118
- const handleContextActionClick = useCallback(
119
- (e: MouseEvent<HTMLDivElement>) => {
120
- e.stopPropagation()
121
-
122
- if (!asset) return
123
- if (onSelect) {
124
- dispatch(dialogActions.showAssetEdit({assetId: asset._id}))
125
- } else if (shiftPressed.current && !picked) {
126
- dispatch(assetsActions.pickRange({startId: lastPicked || asset._id, endId: asset._id}))
127
- } else {
128
- dispatch(assetsActions.pick({assetId: asset._id, picked: !picked}))
129
- }
130
- },
131
- [asset, dispatch, lastPicked, onSelect, picked, shiftPressed],
132
- )
133
-
134
- const handleClick = useCallback(
135
- (e: MouseEvent<HTMLDivElement>) => {
136
- e.stopPropagation()
137
-
138
- if (!asset) return
139
- if (onSelect) {
140
- onSelect([{kind: 'assetDocumentId', value: asset._id}])
141
- } else if (shiftPressed.current) {
142
- if (picked) {
143
- dispatch(assetsActions.pick({assetId: asset._id, picked: !picked}))
144
- } else {
145
- dispatch(assetsActions.pickRange({startId: lastPicked || asset._id, endId: asset._id}))
146
- }
147
- } else {
148
- dispatch(dialogActions.showAssetEdit({assetId: asset._id}))
149
- }
150
- },
151
- [asset, dispatch, lastPicked, onSelect, picked, shiftPressed],
152
- )
153
-
154
- const opacityCell = updating ? 0.5 : 1
155
- const opacityPreview = selected || updating ? 0.1 : 1
156
-
157
- // Display reference count after an initial delay to prevent over-eager fetching
158
- useEffect(() => {
159
- refCountVisibleTimeout.current = setTimeout(
160
- () => setReferenceCountVisible(true),
161
- REFERENCE_COUNT_VISIBILITY_DELAY,
162
- )
163
- return () => {
164
- if (refCountVisibleTimeout.current) {
165
- clearTimeout(refCountVisibleTimeout.current)
166
- }
167
- }
168
- }, [])
169
-
170
- // Short circuit if no asset is available
171
- if (!asset) {
172
- return null
173
- }
174
-
175
- return (
176
- <ContainerGrid
177
- onClick={selected ? undefined : handleClick}
178
- $scheme={scheme}
179
- $selected={selected}
180
- style={{
181
- gridColumnGap: mediaIndex < 3 ? 0 : '16px',
182
- gridRowGap: 0,
183
- gridTemplateColumns:
184
- mediaIndex < 3 ? GRID_TEMPLATE_COLUMNS.SMALL : GRID_TEMPLATE_COLUMNS.LARGE,
185
- gridTemplateRows: mediaIndex < 3 ? 'auto' : '1fr',
186
- }}
187
- $updating={item.updating}
188
- >
189
- {/* Picked checkbox */}
190
- <ContextActionContainer
191
- onClick={handleContextActionClick}
192
- $scheme={scheme}
193
- style={{
194
- alignItems: 'center',
195
- gridColumn: 1,
196
- gridRowStart: 1,
197
- gridRowEnd: 'span 5',
198
- height: '100%',
199
- justifyContent: 'center',
200
- opacity: opacityCell,
201
- position: 'relative',
202
- }}
203
- >
204
- {onSelect ? (
205
- <EditIcon
206
- style={{
207
- flexShrink: 0,
208
- opacity: 0.5,
209
- }}
210
- />
211
- ) : (
212
- <Checkbox
213
- checked={picked}
214
- readOnly
215
- style={{
216
- pointerEvents: 'none', // TODO: consider alternative for usability
217
- transform: 'scale(0.8)',
218
- }}
219
- />
220
- )}
221
- </ContextActionContainer>
222
-
223
- {/* Preview image + spinner */}
224
- <Box
225
- style={{
226
- gridColumn: 2,
227
- gridRowStart: 1,
228
- gridRowEnd: 'span 5',
229
- height: '90px',
230
- width: '100px',
231
- }}
232
- >
233
- <Flex align="center" justify="center" style={{height: '100%', position: 'relative'}}>
234
- <Box style={{height: '100%', opacity: opacityPreview, position: 'relative'}}>
235
- {/* File icon */}
236
- {isFileAsset(asset) && <FileIcon extension={asset.extension} width="40px" />}
237
-
238
- {/* Image */}
239
- {isImageAsset(asset) && (
240
- <Image
241
- draggable={false}
242
- $scheme={scheme}
243
- $showCheckerboard={!isOpaque}
244
- src={imageDprUrl(asset, {height: 100, width: 100})}
245
- />
246
- )}
247
- </Box>
248
-
249
- {/* Spinner */}
250
- {updating && (
251
- <Flex
252
- align="center"
253
- justify="center"
254
- style={{
255
- height: '100%',
256
- left: 0,
257
- position: 'absolute',
258
- top: 0,
259
- width: '100%',
260
- }}
261
- >
262
- <Spinner />
263
- </Flex>
264
- )}
265
-
266
- {/* Selected check icon */}
267
- {selected && !updating && (
268
- <Flex
269
- align="center"
270
- justify="center"
271
- style={{
272
- height: '100%',
273
- left: 0,
274
- position: 'absolute',
275
- top: 0,
276
- width: '100%',
277
- }}
278
- >
279
- <Text size={2}>
280
- <CheckmarkCircleIcon />
281
- </Text>
282
- </Flex>
283
- )}
284
- </Flex>
285
- </Box>
286
-
287
- {/* Filename */}
288
- <Box
289
- marginLeft={mediaIndex < 3 ? 3 : 0}
290
- style={{
291
- gridColumn: 3,
292
- gridRow: mediaIndex < 3 ? 2 : 'auto',
293
- opacity: opacityCell,
294
- }}
295
- >
296
- <Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
297
- {asset.originalFilename}
298
- </Text>
299
- </Box>
300
-
301
- {/* Resolution */}
302
- <Box
303
- marginLeft={mediaIndex < 3 ? 3 : 0}
304
- style={{
305
- gridColumn: mediaIndex < 3 ? 3 : 4,
306
- gridRow: mediaIndex < 3 ? 3 : 'auto',
307
- opacity: opacityCell,
308
- }}
309
- >
310
- <Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
311
- {isImageAsset(asset) && getAssetResolution(asset)}
312
- </Text>
313
- </Box>
314
-
315
- {/* MIME type */}
316
- <Box
317
- style={{
318
- display: mediaIndex < 3 ? 'none' : 'block',
319
- gridColumn: 5,
320
- gridRow: 'auto',
321
- opacity: opacityCell,
322
- }}
323
- >
324
- <Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
325
- {asset.mimeType}
326
- </Text>
327
- </Box>
328
-
329
- {/* Size */}
330
- <Box
331
- style={{
332
- display: mediaIndex < 3 ? 'none' : 'block',
333
- gridColumn: 6,
334
- gridRow: 'auto',
335
- opacity: opacityCell,
336
- }}
337
- >
338
- <Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
339
- {filesize(asset.size, {base: 10, round: 0})}
340
- </Text>
341
- </Box>
342
-
343
- {/* Last updated */}
344
- <Box
345
- marginLeft={mediaIndex < 3 ? 3 : 0}
346
- style={{
347
- gridColumn: mediaIndex < 3 ? 3 : 7,
348
- gridRow: mediaIndex < 3 ? 4 : 'auto',
349
- opacity: opacityCell,
350
- }}
351
- >
352
- <Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
353
- {formatRelative(new Date(asset._updatedAt), new Date())}
354
- </Text>
355
- </Box>
356
-
357
- {/* References */}
358
- <Box
359
- style={{
360
- display: mediaIndex < 3 ? 'none' : 'block',
361
- gridColumn: 8,
362
- gridRow: 'auto',
363
- opacity: opacityCell,
364
- }}
365
- >
366
- <Text muted size={1} style={{lineHeight: '2em'}} textOverflow="ellipsis">
367
- {referenceCountVisible ? (
368
- <WithReferringDocuments id={id}>
369
- {({isLoading, referringDocuments}) => {
370
- const uniqueDocuments = getUniqueDocuments(referringDocuments)
371
- return isLoading ? (
372
- <>-</>
373
- ) : (
374
- <>{Array.isArray(uniqueDocuments) ? uniqueDocuments.length : 0}</>
375
- )
376
- }}
377
- </WithReferringDocuments>
378
- ) : (
379
- <>-</>
380
- )}
381
- </Text>
382
- </Box>
383
-
384
- {/* Error */}
385
- <Flex
386
- align="center"
387
- justify="center"
388
- style={{
389
- gridColumn: mediaIndex < 3 ? 4 : 9,
390
- gridRowStart: '1',
391
- gridRowEnd: mediaIndex < 3 ? 'span 5' : 'auto',
392
- opacity: opacityCell,
393
- }}
394
- >
395
- {/* TODO: DRY */}
396
- {/* Error button */}
397
- {error && (
398
- <Box padding={2}>
399
- <Tooltip
400
- animate
401
- content={
402
- <Container padding={2} width={0}>
403
- <Text size={1}>{error}</Text>
404
- </Container>
405
- }
406
- placement="left"
407
- portal
408
- >
409
- <Text size={1}>
410
- <StyledWarningIcon color="critical" />
411
- </Text>
412
- </Tooltip>
413
- </Box>
414
- )}
415
- </Flex>
416
- </ContainerGrid>
417
- )
418
- }
419
-
420
- 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