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.
- package/dist/index.d.ts +190 -413
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2532 -3564
- package/dist/index.js.map +1 -1
- package/package.json +29 -35
- package/dist/index.cjs +0 -5753
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -462
- 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 -87
- 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 -492
- package/src/components/DialogConfirm/index.tsx +0 -88
- package/src/components/DialogSearchFacets/index.tsx +0 -42
- package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
- package/src/components/DialogTagCreate/index.tsx +0 -103
- package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
- package/src/components/DialogTagEdit/index.tsx +0 -190
- 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 -420
- 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 -37
- package/src/contexts/DropzoneDispatchContext.tsx +0 -34
- package/src/contexts/ToolOptionsContext.tsx +0 -65
- package/src/formSchema/index.test.ts +0 -56
- package/src/formSchema/index.ts +0 -39
- package/src/hooks/useBreakpointIndex.ts +0 -49
- package/src/hooks/useKeyPress.ts +0 -39
- package/src/hooks/useOnScreen.ts +0 -34
- 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 -825
- 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 -124
- 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 -282
- 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 -379
- package/src/types/sanity-ui.d.ts +0 -6
- 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 -70
- 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,290 +0,0 @@
|
|
|
1
|
-
import {CheckmarkCircleIcon, EditIcon, WarningFilledIcon} from '@sanity/icons'
|
|
2
|
-
import {
|
|
3
|
-
Box,
|
|
4
|
-
Checkbox,
|
|
5
|
-
Container,
|
|
6
|
-
Flex,
|
|
7
|
-
Spinner,
|
|
8
|
-
Text,
|
|
9
|
-
type Theme,
|
|
10
|
-
type ThemeColorSchemeKey,
|
|
11
|
-
Tooltip,
|
|
12
|
-
} from '@sanity/ui'
|
|
13
|
-
import {memo, type MouseEvent, type RefObject} from 'react'
|
|
14
|
-
import {useDispatch} from 'react-redux'
|
|
15
|
-
import {useColorSchemeValue} from 'sanity'
|
|
16
|
-
import {styled, css} from 'styled-components'
|
|
17
|
-
|
|
18
|
-
import {PANEL_HEIGHT} from '../../constants'
|
|
19
|
-
import {useAssetSourceActions} from '../../contexts/AssetSourceDispatchContext'
|
|
20
|
-
import useKeyPress from '../../hooks/useKeyPress'
|
|
21
|
-
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
22
|
-
import {assetsActions, selectAssetById} from '../../modules/assets'
|
|
23
|
-
import {dialogActions} from '../../modules/dialog'
|
|
24
|
-
import {getSchemeColor} from '../../utils/getSchemeColor'
|
|
25
|
-
import imageDprUrl from '../../utils/imageDprUrl'
|
|
26
|
-
import {isFileAsset, isImageAsset} from '../../utils/typeGuards'
|
|
27
|
-
import FileIcon from '../FileIcon'
|
|
28
|
-
import Image from '../Image'
|
|
29
|
-
|
|
30
|
-
type Props = {
|
|
31
|
-
id: string
|
|
32
|
-
selected: boolean
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const CardWrapper = styled(Flex)`
|
|
36
|
-
box-sizing: border-box;
|
|
37
|
-
height: 100%;
|
|
38
|
-
overflow: hidden;
|
|
39
|
-
position: relative;
|
|
40
|
-
width: 100%;
|
|
41
|
-
`
|
|
42
|
-
|
|
43
|
-
const CardContainer = styled(Flex)<{$picked?: boolean; theme: Theme; $updating?: boolean}>(({
|
|
44
|
-
$picked,
|
|
45
|
-
theme,
|
|
46
|
-
$updating,
|
|
47
|
-
}) => {
|
|
48
|
-
return css`
|
|
49
|
-
border: 1px solid transparent;
|
|
50
|
-
height: 100%;
|
|
51
|
-
pointer-events: ${$updating ? 'none' : 'auto'};
|
|
52
|
-
position: relative;
|
|
53
|
-
transition: all 300ms;
|
|
54
|
-
user-select: none;
|
|
55
|
-
width: 100%;
|
|
56
|
-
|
|
57
|
-
border: ${$picked
|
|
58
|
-
? `1px solid ${theme.sanity.color.spot.orange} !important`
|
|
59
|
-
: '1px solid inherit'};
|
|
60
|
-
|
|
61
|
-
${!$updating &&
|
|
62
|
-
css`
|
|
63
|
-
@media (hover: hover) and (pointer: fine) {
|
|
64
|
-
&:hover {
|
|
65
|
-
border: 1px solid var(--card-border-color);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
`}
|
|
69
|
-
`
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const ContextActionContainer = styled<typeof Flex, {$scheme: ThemeColorSchemeKey}>(Flex)(({
|
|
73
|
-
$scheme,
|
|
74
|
-
}) => {
|
|
75
|
-
return css`
|
|
76
|
-
cursor: pointer;
|
|
77
|
-
height: ${PANEL_HEIGHT}px;
|
|
78
|
-
transition: all 300ms;
|
|
79
|
-
@media (hover: hover) and (pointer: fine) {
|
|
80
|
-
&:hover {
|
|
81
|
-
background: ${getSchemeColor($scheme, 'bg')};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
`
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const StyledWarningOutlineIcon = styled(WarningFilledIcon)(({theme}) => {
|
|
88
|
-
return {
|
|
89
|
-
color: theme.sanity.color.spot.red,
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
const CardAsset = (props: Props) => {
|
|
94
|
-
const {id, selected} = props
|
|
95
|
-
|
|
96
|
-
const scheme = useColorSchemeValue()
|
|
97
|
-
|
|
98
|
-
// Refs
|
|
99
|
-
const shiftPressed: RefObject<boolean> = useKeyPress('shift')
|
|
100
|
-
|
|
101
|
-
// Redux
|
|
102
|
-
const dispatch = useDispatch()
|
|
103
|
-
const lastPicked = useTypedSelector((state) => state.assets.lastPicked)
|
|
104
|
-
const item = useTypedSelector((state) => selectAssetById(state, id))
|
|
105
|
-
|
|
106
|
-
const asset = item?.asset
|
|
107
|
-
const error = item?.error
|
|
108
|
-
const isOpaque = item?.asset?.metadata?.isOpaque
|
|
109
|
-
const picked = item?.picked
|
|
110
|
-
const updating = item?.updating
|
|
111
|
-
|
|
112
|
-
const {onSelect} = useAssetSourceActions()
|
|
113
|
-
|
|
114
|
-
// Short circuit if no asset is available
|
|
115
|
-
if (!asset) {
|
|
116
|
-
return null
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Callbacks
|
|
120
|
-
const handleAssetClick = (e: MouseEvent<HTMLDivElement>) => {
|
|
121
|
-
e.stopPropagation()
|
|
122
|
-
|
|
123
|
-
if (onSelect) {
|
|
124
|
-
onSelect([
|
|
125
|
-
{
|
|
126
|
-
kind: 'assetDocumentId',
|
|
127
|
-
value: asset._id,
|
|
128
|
-
},
|
|
129
|
-
])
|
|
130
|
-
} else if (shiftPressed.current) {
|
|
131
|
-
if (picked) {
|
|
132
|
-
dispatch(assetsActions.pick({assetId: asset._id, picked: !picked}))
|
|
133
|
-
} else {
|
|
134
|
-
dispatch(assetsActions.pickRange({startId: lastPicked || asset._id, endId: asset._id}))
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
dispatch(dialogActions.showAssetEdit({assetId: asset._id}))
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const handleContextActionClick = (e: MouseEvent) => {
|
|
142
|
-
e.stopPropagation()
|
|
143
|
-
|
|
144
|
-
if (onSelect) {
|
|
145
|
-
dispatch(dialogActions.showAssetEdit({assetId: asset._id}))
|
|
146
|
-
} else if (shiftPressed.current && !picked) {
|
|
147
|
-
dispatch(assetsActions.pickRange({startId: lastPicked || asset._id, endId: asset._id}))
|
|
148
|
-
} else {
|
|
149
|
-
dispatch(assetsActions.pick({assetId: asset._id, picked: !picked}))
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const opacityContainer = updating ? 0.5 : 1
|
|
154
|
-
const opacityPreview = selected || updating ? 0.25 : 1
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<CardWrapper padding={1}>
|
|
158
|
-
<CardContainer direction="column" $picked={picked} $updating={item.updating}>
|
|
159
|
-
{/* Image */}
|
|
160
|
-
<Box
|
|
161
|
-
flex={1}
|
|
162
|
-
style={{
|
|
163
|
-
cursor: selected ? 'default' : 'pointer',
|
|
164
|
-
position: 'relative',
|
|
165
|
-
}}
|
|
166
|
-
>
|
|
167
|
-
<div onClick={handleAssetClick} style={{height: '100%', opacity: opacityPreview}}>
|
|
168
|
-
{/* File icon */}
|
|
169
|
-
{isFileAsset(asset) && <FileIcon extension={asset.extension} width="80px" />}
|
|
170
|
-
|
|
171
|
-
{/* Image */}
|
|
172
|
-
{isImageAsset(asset) && (
|
|
173
|
-
<Image
|
|
174
|
-
draggable={false}
|
|
175
|
-
$scheme={scheme}
|
|
176
|
-
$showCheckerboard={!isOpaque}
|
|
177
|
-
src={imageDprUrl(asset, {height: 250, width: 250})}
|
|
178
|
-
style={{
|
|
179
|
-
draggable: false,
|
|
180
|
-
transition: 'opacity 1000ms',
|
|
181
|
-
}}
|
|
182
|
-
/>
|
|
183
|
-
)}
|
|
184
|
-
</div>
|
|
185
|
-
|
|
186
|
-
{/* Selected check icon */}
|
|
187
|
-
{selected && !updating && (
|
|
188
|
-
<Flex
|
|
189
|
-
align="center"
|
|
190
|
-
justify="center"
|
|
191
|
-
style={{
|
|
192
|
-
height: '100%',
|
|
193
|
-
left: 0,
|
|
194
|
-
opacity: opacityContainer,
|
|
195
|
-
position: 'absolute',
|
|
196
|
-
top: 0,
|
|
197
|
-
width: '100%',
|
|
198
|
-
}}
|
|
199
|
-
>
|
|
200
|
-
<Text size={2}>
|
|
201
|
-
<CheckmarkCircleIcon />
|
|
202
|
-
</Text>
|
|
203
|
-
</Flex>
|
|
204
|
-
)}
|
|
205
|
-
|
|
206
|
-
{/* Spinner */}
|
|
207
|
-
{updating && (
|
|
208
|
-
<Flex
|
|
209
|
-
align="center"
|
|
210
|
-
justify="center"
|
|
211
|
-
style={{
|
|
212
|
-
height: '100%',
|
|
213
|
-
left: 0,
|
|
214
|
-
position: 'absolute',
|
|
215
|
-
top: 0,
|
|
216
|
-
width: '100%',
|
|
217
|
-
}}
|
|
218
|
-
>
|
|
219
|
-
<Spinner />
|
|
220
|
-
</Flex>
|
|
221
|
-
)}
|
|
222
|
-
</Box>
|
|
223
|
-
|
|
224
|
-
{/* Footer */}
|
|
225
|
-
<ContextActionContainer
|
|
226
|
-
align="center"
|
|
227
|
-
onClick={handleContextActionClick}
|
|
228
|
-
paddingX={1}
|
|
229
|
-
$scheme={scheme}
|
|
230
|
-
style={{opacity: opacityContainer}}
|
|
231
|
-
>
|
|
232
|
-
{onSelect ? (
|
|
233
|
-
<EditIcon
|
|
234
|
-
style={{
|
|
235
|
-
flexShrink: 0,
|
|
236
|
-
opacity: 0.5,
|
|
237
|
-
}}
|
|
238
|
-
/>
|
|
239
|
-
) : (
|
|
240
|
-
<Checkbox
|
|
241
|
-
checked={picked}
|
|
242
|
-
readOnly
|
|
243
|
-
style={{
|
|
244
|
-
flexShrink: 0,
|
|
245
|
-
pointerEvents: 'none',
|
|
246
|
-
transform: 'scale(0.8)',
|
|
247
|
-
}}
|
|
248
|
-
/>
|
|
249
|
-
)}
|
|
250
|
-
|
|
251
|
-
<Box marginLeft={2}>
|
|
252
|
-
<Text muted size={0} textOverflow="ellipsis">
|
|
253
|
-
{asset.originalFilename}
|
|
254
|
-
</Text>
|
|
255
|
-
</Box>
|
|
256
|
-
</ContextActionContainer>
|
|
257
|
-
|
|
258
|
-
{/* TODO: DRY */}
|
|
259
|
-
{/* Error button */}
|
|
260
|
-
{error && (
|
|
261
|
-
<Box
|
|
262
|
-
padding={3}
|
|
263
|
-
style={{
|
|
264
|
-
position: 'absolute',
|
|
265
|
-
right: 0,
|
|
266
|
-
top: 0,
|
|
267
|
-
}}
|
|
268
|
-
>
|
|
269
|
-
<Tooltip
|
|
270
|
-
animate
|
|
271
|
-
content={
|
|
272
|
-
<Container padding={2} width={0}>
|
|
273
|
-
<Text size={1}>{error}</Text>
|
|
274
|
-
</Container>
|
|
275
|
-
}
|
|
276
|
-
placement="left"
|
|
277
|
-
portal
|
|
278
|
-
>
|
|
279
|
-
<Text size={1}>
|
|
280
|
-
<StyledWarningOutlineIcon color="critical" />
|
|
281
|
-
</Text>
|
|
282
|
-
</Tooltip>
|
|
283
|
-
</Box>
|
|
284
|
-
)}
|
|
285
|
-
</CardContainer>
|
|
286
|
-
</CardWrapper>
|
|
287
|
-
)
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export default memo(CardAsset)
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import {CloseIcon} from '@sanity/icons'
|
|
2
|
-
import {Box, Button, Flex, Text} from '@sanity/ui'
|
|
3
|
-
import filesize from 'filesize'
|
|
4
|
-
import {useDispatch} from 'react-redux'
|
|
5
|
-
import {useColorSchemeValue} from 'sanity'
|
|
6
|
-
import {styled} from 'styled-components'
|
|
7
|
-
|
|
8
|
-
import {PANEL_HEIGHT} from '../../constants'
|
|
9
|
-
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
10
|
-
import {selectUploadById, uploadsActions} from '../../modules/uploads'
|
|
11
|
-
import {getSchemeColor} from '../../utils/getSchemeColor'
|
|
12
|
-
import FileIcon from '../FileIcon'
|
|
13
|
-
import Image from '../Image'
|
|
14
|
-
|
|
15
|
-
type Props = {
|
|
16
|
-
id: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const CardWrapper = styled(Flex)`
|
|
20
|
-
box-sizing: border-box;
|
|
21
|
-
height: 100%;
|
|
22
|
-
overflow: hidden;
|
|
23
|
-
position: relative;
|
|
24
|
-
width: 100%;
|
|
25
|
-
`
|
|
26
|
-
|
|
27
|
-
const CardUpload = (props: Props) => {
|
|
28
|
-
const {id} = props
|
|
29
|
-
|
|
30
|
-
const scheme = useColorSchemeValue()
|
|
31
|
-
|
|
32
|
-
// Redux
|
|
33
|
-
const dispatch = useDispatch()
|
|
34
|
-
const item = useTypedSelector((state) => selectUploadById(state, id))
|
|
35
|
-
|
|
36
|
-
if (!item) {
|
|
37
|
-
return null
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const fileSize = filesize(item.size, {base: 10, round: 0})
|
|
41
|
-
const percentLoaded = Math.round(item.percent || 0) // (0 - 100)
|
|
42
|
-
|
|
43
|
-
const isComplete = item.status === 'complete'
|
|
44
|
-
const isUploading = item.status === 'uploading'
|
|
45
|
-
const isQueued = item.status === 'queued'
|
|
46
|
-
|
|
47
|
-
let status
|
|
48
|
-
if (isComplete) {
|
|
49
|
-
status = 'Verifying'
|
|
50
|
-
}
|
|
51
|
-
if (isUploading) {
|
|
52
|
-
status = `${percentLoaded}%`
|
|
53
|
-
}
|
|
54
|
-
if (isQueued) {
|
|
55
|
-
status = 'Queued'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Callbacks
|
|
59
|
-
const handleCancelUpload = () => {
|
|
60
|
-
dispatch(uploadsActions.uploadCancel({hash: item.hash}))
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<CardWrapper padding={1}>
|
|
65
|
-
<Flex
|
|
66
|
-
direction="column"
|
|
67
|
-
flex={1}
|
|
68
|
-
style={{
|
|
69
|
-
background: getSchemeColor(scheme, 'bg'),
|
|
70
|
-
border: '1px solid transparent',
|
|
71
|
-
height: '100%',
|
|
72
|
-
position: 'relative',
|
|
73
|
-
}}
|
|
74
|
-
>
|
|
75
|
-
{/* Progress bar */}
|
|
76
|
-
<div
|
|
77
|
-
style={{
|
|
78
|
-
background: 'var(--card-fg-color)',
|
|
79
|
-
bottom: 0,
|
|
80
|
-
height: '1px',
|
|
81
|
-
left: 0,
|
|
82
|
-
position: 'absolute',
|
|
83
|
-
width: '100%',
|
|
84
|
-
transform: `scaleX(${percentLoaded * 0.01})`,
|
|
85
|
-
transformOrigin: 'bottom left',
|
|
86
|
-
transition: 'all 1000ms ease-out',
|
|
87
|
-
}}
|
|
88
|
-
/>
|
|
89
|
-
|
|
90
|
-
<Box flex={1} style={{position: 'relative'}}>
|
|
91
|
-
{item.assetType === 'image' && item?.objectUrl && (
|
|
92
|
-
<Image
|
|
93
|
-
draggable={false}
|
|
94
|
-
$scheme={scheme}
|
|
95
|
-
src={item.objectUrl}
|
|
96
|
-
style={{
|
|
97
|
-
opacity: 0.4,
|
|
98
|
-
}}
|
|
99
|
-
/>
|
|
100
|
-
)}
|
|
101
|
-
|
|
102
|
-
{item.assetType === 'file' && (
|
|
103
|
-
<div style={{height: '100%', opacity: 0.1}}>
|
|
104
|
-
<FileIcon width="80px" />
|
|
105
|
-
</div>
|
|
106
|
-
)}
|
|
107
|
-
|
|
108
|
-
{/*
|
|
109
|
-
Cancel upload button.
|
|
110
|
-
Assets will only have a `complete` status _after_ it has been created on your dataset.
|
|
111
|
-
As such, we also hide the cancel button when `percentLoaded === 100`, as cancelling when the asset
|
|
112
|
-
has been fully uploaded (even with a status of `progress`) won't stop the asset from being created.
|
|
113
|
-
*/}
|
|
114
|
-
{!isComplete && percentLoaded !== 100 && (
|
|
115
|
-
<Flex
|
|
116
|
-
align="center"
|
|
117
|
-
direction="column"
|
|
118
|
-
justify="center"
|
|
119
|
-
style={{
|
|
120
|
-
height: '100%',
|
|
121
|
-
left: 0,
|
|
122
|
-
position: 'absolute',
|
|
123
|
-
top: 0,
|
|
124
|
-
width: '100%',
|
|
125
|
-
}}
|
|
126
|
-
>
|
|
127
|
-
<Button
|
|
128
|
-
fontSize={4}
|
|
129
|
-
icon={CloseIcon}
|
|
130
|
-
mode="bleed"
|
|
131
|
-
onClick={handleCancelUpload}
|
|
132
|
-
padding={2}
|
|
133
|
-
style={{background: 'none', boxShadow: 'none'}}
|
|
134
|
-
tone="critical"
|
|
135
|
-
/>
|
|
136
|
-
</Flex>
|
|
137
|
-
)}
|
|
138
|
-
</Box>
|
|
139
|
-
|
|
140
|
-
{/* Footer */}
|
|
141
|
-
<Flex
|
|
142
|
-
align="center"
|
|
143
|
-
justify="space-between"
|
|
144
|
-
paddingX={2}
|
|
145
|
-
style={{height: `${PANEL_HEIGHT}px`}}
|
|
146
|
-
>
|
|
147
|
-
<Box flex={1} marginRight={1}>
|
|
148
|
-
<Text size={0} textOverflow="ellipsis">
|
|
149
|
-
{item.name} ({fileSize})
|
|
150
|
-
</Text>
|
|
151
|
-
</Box>
|
|
152
|
-
<Text size={0} style={{flexShrink: 0}} weight="semibold">
|
|
153
|
-
{status}
|
|
154
|
-
</Text>
|
|
155
|
-
</Flex>
|
|
156
|
-
</Flex>
|
|
157
|
-
</CardWrapper>
|
|
158
|
-
)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export default CardUpload
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import {Box, Button, Flex, Inline, useMediaIndex} from '@sanity/ui'
|
|
2
|
-
import {useDispatch} from 'react-redux'
|
|
3
|
-
|
|
4
|
-
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
5
|
-
import {dialogActions} from '../../modules/dialog'
|
|
6
|
-
import {tagsActions} from '../../modules/tags'
|
|
7
|
-
import ButtonViewGroup from '../ButtonViewGroup'
|
|
8
|
-
import OrderSelect from '../OrderSelect'
|
|
9
|
-
import Progress from '../Progress'
|
|
10
|
-
import SearchFacets from '../SearchFacets'
|
|
11
|
-
import SearchFacetsControl from '../SearchFacetsControl'
|
|
12
|
-
import TagIcon from '../TagIcon'
|
|
13
|
-
import TextInputSearch from '../TextInputSearch'
|
|
14
|
-
|
|
15
|
-
const Controls = () => {
|
|
16
|
-
// Redux
|
|
17
|
-
const dispatch = useDispatch()
|
|
18
|
-
const fetching = useTypedSelector((state) => state.assets.fetching)
|
|
19
|
-
const pageIndex = useTypedSelector((state) => state.assets.pageIndex)
|
|
20
|
-
const searchFacets = useTypedSelector((state) => state.search.facets)
|
|
21
|
-
const tagsPanelVisible = useTypedSelector((state) => state.tags.panelVisible)
|
|
22
|
-
|
|
23
|
-
const mediaIndex = useMediaIndex()
|
|
24
|
-
|
|
25
|
-
// Callbacks
|
|
26
|
-
const handleShowSearchFacetDialog = () => {
|
|
27
|
-
dispatch(dialogActions.showSearchFacets())
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const handleShowTagsDialog = () => {
|
|
31
|
-
dispatch(dialogActions.showTags())
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const toggleTagsPanelToggle = () => {
|
|
35
|
-
dispatch(tagsActions.panelVisibleSet({panelVisible: !tagsPanelVisible}))
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<Box
|
|
40
|
-
paddingY={2}
|
|
41
|
-
style={{
|
|
42
|
-
borderBottom: '1px solid var(--card-border-color)',
|
|
43
|
-
zIndex: 2,
|
|
44
|
-
}}
|
|
45
|
-
>
|
|
46
|
-
{/* Rows: search / filters / orders */}
|
|
47
|
-
<Box marginBottom={2}>
|
|
48
|
-
<Flex
|
|
49
|
-
align="flex-start"
|
|
50
|
-
direction={['column', 'column', 'column', 'column', 'row']}
|
|
51
|
-
justify="space-between"
|
|
52
|
-
>
|
|
53
|
-
{/* Search + Filters */}
|
|
54
|
-
<Flex
|
|
55
|
-
flex={1}
|
|
56
|
-
style={{
|
|
57
|
-
alignItems: 'flex-start',
|
|
58
|
-
flex: 1,
|
|
59
|
-
height: '100%',
|
|
60
|
-
justifyContent: mediaIndex < 2 ? 'space-between' : 'flex-start',
|
|
61
|
-
position: 'relative',
|
|
62
|
-
width: '100%',
|
|
63
|
-
}}
|
|
64
|
-
>
|
|
65
|
-
<Box marginX={2} style={{minWidth: '200px'}}>
|
|
66
|
-
{/* Search */}
|
|
67
|
-
<TextInputSearch />
|
|
68
|
-
</Box>
|
|
69
|
-
|
|
70
|
-
<Box display={['none', 'none', 'block']}>
|
|
71
|
-
<SearchFacets />
|
|
72
|
-
|
|
73
|
-
{/* Search Facets Control (add / clear) */}
|
|
74
|
-
<SearchFacetsControl />
|
|
75
|
-
</Box>
|
|
76
|
-
|
|
77
|
-
<Box display={['block', 'block', 'none']} marginX={2}>
|
|
78
|
-
<Inline space={2} style={{whiteSpace: 'nowrap'}}>
|
|
79
|
-
{/* Filters button (small) */}
|
|
80
|
-
<Button
|
|
81
|
-
fontSize={1}
|
|
82
|
-
mode="ghost"
|
|
83
|
-
onClick={handleShowSearchFacetDialog}
|
|
84
|
-
text={`Filters${searchFacets.length > 0 ? ` (${searchFacets.length})` : ''}`}
|
|
85
|
-
tone="primary"
|
|
86
|
-
/>
|
|
87
|
-
|
|
88
|
-
{/* Tags button (small) */}
|
|
89
|
-
<Button
|
|
90
|
-
fontSize={1}
|
|
91
|
-
mode="ghost"
|
|
92
|
-
onClick={handleShowTagsDialog}
|
|
93
|
-
text={`Tags`}
|
|
94
|
-
tone="primary"
|
|
95
|
-
/>
|
|
96
|
-
</Inline>
|
|
97
|
-
</Box>
|
|
98
|
-
</Flex>
|
|
99
|
-
</Flex>
|
|
100
|
-
</Box>
|
|
101
|
-
|
|
102
|
-
<Box>
|
|
103
|
-
<Flex align="center" justify={['space-between']}>
|
|
104
|
-
{/* Views */}
|
|
105
|
-
<Box marginX={2}>
|
|
106
|
-
<ButtonViewGroup />
|
|
107
|
-
</Box>
|
|
108
|
-
|
|
109
|
-
<Flex marginX={2}>
|
|
110
|
-
{/* Orders */}
|
|
111
|
-
<OrderSelect />
|
|
112
|
-
{/* Tags panel toggle */}
|
|
113
|
-
<Box display={['none', 'none', 'block']} marginLeft={2}>
|
|
114
|
-
<Button
|
|
115
|
-
fontSize={1}
|
|
116
|
-
icon={
|
|
117
|
-
<Box style={{transform: 'scale(0.75)'}}>
|
|
118
|
-
<TagIcon />
|
|
119
|
-
</Box>
|
|
120
|
-
}
|
|
121
|
-
onClick={toggleTagsPanelToggle}
|
|
122
|
-
mode={tagsPanelVisible ? 'default' : 'ghost'}
|
|
123
|
-
text={tagsPanelVisible ? 'Tags' : ''}
|
|
124
|
-
/>
|
|
125
|
-
</Box>
|
|
126
|
-
</Flex>
|
|
127
|
-
</Flex>
|
|
128
|
-
</Box>
|
|
129
|
-
|
|
130
|
-
{/* Progress bar */}
|
|
131
|
-
<Progress key={pageIndex} loading={fetching} />
|
|
132
|
-
</Box>
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export default Controls
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import {PlugIcon} from '@sanity/icons'
|
|
2
|
-
import {Box, Flex, Switch, Text, Tooltip} from '@sanity/ui'
|
|
3
|
-
import {type ChangeEvent} from 'react'
|
|
4
|
-
import {useDispatch} from 'react-redux'
|
|
5
|
-
|
|
6
|
-
import useKeyPress from '../../hooks/useKeyPress'
|
|
7
|
-
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
8
|
-
import {debugActions} from '../../modules/debug'
|
|
9
|
-
|
|
10
|
-
const DebugControls = () => {
|
|
11
|
-
// Redux
|
|
12
|
-
const dispatch = useDispatch()
|
|
13
|
-
const badConnection = useTypedSelector((state) => state.debug.badConnection)
|
|
14
|
-
const debugEnabled = useTypedSelector((state) => state.debug.enabled)
|
|
15
|
-
|
|
16
|
-
// Callbacks
|
|
17
|
-
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
18
|
-
const checked = e.target.checked
|
|
19
|
-
|
|
20
|
-
dispatch(debugActions.setBadConnection(checked))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const handleToggleControls = () => {
|
|
24
|
-
dispatch(debugActions.toggleEnabled())
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Close on escape key press
|
|
28
|
-
useKeyPress('alt+ctrl+shift+/', handleToggleControls)
|
|
29
|
-
|
|
30
|
-
if (!debugEnabled) {
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<Box
|
|
36
|
-
padding={4}
|
|
37
|
-
style={{
|
|
38
|
-
bottom: 0,
|
|
39
|
-
left: 0,
|
|
40
|
-
pointerEvents: 'none',
|
|
41
|
-
position: 'fixed',
|
|
42
|
-
width: '100%',
|
|
43
|
-
}}
|
|
44
|
-
>
|
|
45
|
-
{/* Bad connection toggle */}
|
|
46
|
-
<Flex align="center">
|
|
47
|
-
<Box marginRight={3}>
|
|
48
|
-
<Text muted size={1}>
|
|
49
|
-
<PlugIcon />
|
|
50
|
-
</Text>
|
|
51
|
-
</Box>
|
|
52
|
-
<Tooltip
|
|
53
|
-
animate
|
|
54
|
-
content={
|
|
55
|
-
<Box padding={2}>
|
|
56
|
-
<Text muted size={1}>
|
|
57
|
-
{badConnection
|
|
58
|
-
? 'Bad connection: +3000ms & 50% chance to fail'
|
|
59
|
-
: 'No connection throttling'}
|
|
60
|
-
</Text>
|
|
61
|
-
</Box>
|
|
62
|
-
}
|
|
63
|
-
fallbackPlacements={['right', 'left']}
|
|
64
|
-
placement="bottom"
|
|
65
|
-
portal
|
|
66
|
-
>
|
|
67
|
-
<Switch
|
|
68
|
-
checked={badConnection}
|
|
69
|
-
onChange={handleChange}
|
|
70
|
-
style={{
|
|
71
|
-
pointerEvents: 'auto',
|
|
72
|
-
}}
|
|
73
|
-
/>
|
|
74
|
-
</Tooltip>
|
|
75
|
-
</Flex>
|
|
76
|
-
</Box>
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default DebugControls
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {Dialog as SanityDialog} from '@sanity/ui'
|
|
2
|
-
import {type ComponentProps} from 'react'
|
|
3
|
-
|
|
4
|
-
const Dialog = (props: ComponentProps<typeof SanityDialog>) => {
|
|
5
|
-
// HACK: Temporarily force fixed positioning on all @sanity/ui <Dialog /> components.
|
|
6
|
-
// The studio is currently setting absolute positioning on all root-level dialogs on the mobile breakpoint,
|
|
7
|
-
// causing unwanted scroll behaviour.
|
|
8
|
-
return <SanityDialog {...props} style={{position: 'fixed'}} />
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default Dialog
|