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,492 +0,0 @@
1
- import type {MutationEvent} from '@sanity/client'
2
- import {Box, Button, Card, Flex, Stack, Tab, TabList, TabPanel, Text} from '@sanity/ui'
3
- import groq from 'groq'
4
- import {type ReactNode, useCallback, useEffect, useMemo, useRef, useState} from 'react'
5
- import {type SubmitHandler, useForm} from 'react-hook-form'
6
- import {useDispatch} from 'react-redux'
7
- import {WithReferringDocuments, useColorSchemeValue, useDocumentStore} from 'sanity'
8
-
9
- import {useToolOptions} from '../../contexts/ToolOptionsContext'
10
- import {getAssetFormSchema} from '../../formSchema'
11
- import useTypedSelector from '../../hooks/useTypedSelector'
12
- import useVersionedClient from '../../hooks/useVersionedClient'
13
- import {assetsActions, selectAssetById} from '../../modules/assets'
14
- import {dialogActions} from '../../modules/dialog'
15
- import {selectTags, selectTagSelectOptions, tagsActions} from '../../modules/tags'
16
- import type {Asset, AssetFormData, DialogAssetEditProps, TagSelectOption} from '../../types'
17
- import getTagSelectOptions from '../../utils/getTagSelectOptions'
18
- import {getUniqueDocuments} from '../../utils/getUniqueDocuments'
19
- import imageDprUrl from '../../utils/imageDprUrl'
20
- import sanitizeFormData from '../../utils/sanitizeFormData'
21
- import {isFileAsset, isImageAsset} from '../../utils/typeGuards'
22
- import zodFormResolver from '../../utils/zodFormResolver'
23
- import AssetMetadata from '../AssetMetadata'
24
- import Dialog from '../Dialog'
25
- import DocumentList from '../DocumentList'
26
- import FileAssetPreview from '../FileAssetPreview'
27
- import FormSubmitButton from '../FormSubmitButton'
28
- import Image from '../Image'
29
- import Details, {type DetailsProps} from './Details'
30
-
31
- function renderDefaultDetails(props: DetailsProps) {
32
- return <Details {...props} />
33
- }
34
-
35
- type Props = {
36
- children: ReactNode
37
- dialog: DialogAssetEditProps
38
- }
39
-
40
- const DialogAssetEdit = (props: Props) => {
41
- const {
42
- children,
43
- dialog: {assetId, id, lastCreatedTag, lastRemovedTagIds},
44
- } = props
45
-
46
- const client = useVersionedClient()
47
- const scheme = useColorSchemeValue()
48
-
49
- const documentStore = useDocumentStore()
50
-
51
- const dispatch = useDispatch()
52
- const assetItem = useTypedSelector((state) => selectAssetById(state, String(assetId))) // TODO: check casting
53
- const tags = useTypedSelector(selectTags)
54
-
55
- const assetUpdatedPrev = useRef<string | undefined>(undefined)
56
-
57
- // Generate a snapshot of the current asset
58
- const [assetSnapshot, setAssetSnapshot] = useState(assetItem?.asset)
59
- const [tabSection, setTabSection] = useState<'details' | 'references'>('details')
60
-
61
- const currentAsset = assetItem ? assetItem?.asset : assetSnapshot
62
- const allTagOptions = getTagSelectOptions(tags)
63
-
64
- const assetTagOptions = useTypedSelector(selectTagSelectOptions(currentAsset))
65
-
66
- // Check if credit line options are configured
67
- const {creditLine, components: {details: CustomDetails} = {}, locales} = useToolOptions()
68
-
69
- const generateDefaultValues = useCallback(
70
- (asset?: Asset): AssetFormData => {
71
- if (locales && locales.length > 0) {
72
- const makeLocaleObj = (field?: Record<string, string> | string) => {
73
- const obj: Record<string, string> = {}
74
- for (let i = 0; i < locales.length; i++) {
75
- const locale = locales[i]
76
- if (typeof field === 'object' && field && field[locale.id]) {
77
- obj[locale.id] = field[locale.id]
78
- } else if (typeof field === 'string') {
79
- // Only populate the first locale to avoid spreading a legacy value
80
- // across all languages; the user should fill in other translations manually
81
- obj[locale.id] = i === 0 ? field : ''
82
- } else {
83
- obj[locale.id] = ''
84
- }
85
- }
86
- return obj
87
- }
88
- return {
89
- altText: makeLocaleObj(asset?.altText),
90
- creditLine: makeLocaleObj(asset?.creditLine),
91
- description: makeLocaleObj(asset?.description),
92
- originalFilename: asset?.originalFilename || '',
93
- opt: {media: {tags: assetTagOptions}},
94
- title: makeLocaleObj(asset?.title),
95
- }
96
- }
97
- // Normalize: if a field is a localized object but locales are disabled, pick first non-empty value
98
- const flattenField = (field: unknown): string => {
99
- if (typeof field === 'string') return field
100
- if (typeof field === 'object' && field !== null) {
101
- const values = Object.values(field as Record<string, string>)
102
- return values.find((v) => v) || ''
103
- }
104
- return ''
105
- }
106
- return {
107
- altText: flattenField(asset?.altText),
108
- creditLine: flattenField(asset?.creditLine),
109
- description: flattenField(asset?.description),
110
- originalFilename: asset?.originalFilename || '',
111
- opt: {media: {tags: assetTagOptions}},
112
- title: flattenField(asset?.title),
113
- }
114
- },
115
- [assetTagOptions, locales],
116
- )
117
-
118
- const {
119
- control,
120
- // Read the formState before render to subscribe the form state through Proxy
121
- formState: {errors, isDirty, isValid},
122
- getValues,
123
- handleSubmit,
124
- register,
125
- reset,
126
- setValue,
127
- } = useForm<AssetFormData>({
128
- defaultValues: generateDefaultValues(assetItem?.asset),
129
- mode: 'onChange',
130
- resolver: zodFormResolver<AssetFormData>(getAssetFormSchema(locales)),
131
- })
132
-
133
- const formUpdating = !assetItem || assetItem?.updating
134
-
135
- const handleClose = useCallback(() => {
136
- dispatch(dialogActions.remove({id}))
137
- }, [dispatch, id])
138
-
139
- const handleDelete = useCallback(() => {
140
- if (!assetItem?.asset) {
141
- return
142
- }
143
-
144
- dispatch(
145
- dialogActions.showConfirmDeleteAssets({
146
- assets: [assetItem],
147
- closeDialogId: assetItem?.asset._id,
148
- }),
149
- )
150
- }, [assetItem, dispatch])
151
-
152
- const handleAssetUpdate = useCallback((update: MutationEvent) => {
153
- const {result, transition} = update
154
- if (result && transition === 'update') {
155
- // Regenerate asset snapshot
156
- setAssetSnapshot(result as Asset)
157
- }
158
- }, [])
159
-
160
- const handleCreateTag = useCallback(
161
- (tagName: string) => {
162
- // Dispatch action to create new tag
163
- dispatch(
164
- tagsActions.createRequest({
165
- assetId: currentAsset?._id,
166
- name: tagName,
167
- }),
168
- )
169
- },
170
- [currentAsset?._id, dispatch],
171
- )
172
-
173
- // Detect if asset has localized fields (objects) with keys not in the configured locales
174
- const hasOrphanedLocales = useMemo(() => {
175
- if (!currentAsset) return false
176
- const isLocaleObj = (v: unknown) => typeof v === 'object' && v !== null && !Array.isArray(v)
177
- const fields = [
178
- currentAsset.title,
179
- currentAsset.altText,
180
- currentAsset.description,
181
- ...(currentAsset._type === 'sanity.imageAsset' ? [currentAsset.creditLine] : []),
182
- ]
183
- const anyLocalized = fields.some((f) => isLocaleObj(f))
184
- if (!anyLocalized) return false
185
- if (!locales || locales.length === 0) return true
186
- const configuredIds = new Set(locales.map((l) => l.id))
187
- return fields.some((f) => {
188
- if (!isLocaleObj(f)) return false
189
- return Object.keys(f as object).some((k) => !configuredIds.has(k))
190
- })
191
- }, [currentAsset, locales])
192
-
193
- const handleCleanupLocales = useCallback(async () => {
194
- if (!currentAsset) return
195
-
196
- const cleanField = (field: unknown): unknown => {
197
- if (typeof field !== 'object' || field === null || Array.isArray(field)) return field
198
- const obj = field as Record<string, string>
199
- if (!locales || locales.length === 0) {
200
- // Pick the first non-empty value sorted by key for determinism
201
- const sorted = Object.keys(obj).sort()
202
- return sorted.map((k) => obj[k]).find((v) => v) || ''
203
- }
204
- const configuredIds = new Set(locales.map((l) => l.id))
205
- const cleaned: Record<string, string> = {}
206
- for (const [key, val] of Object.entries(obj)) {
207
- if (configuredIds.has(key)) cleaned[key] = val
208
- }
209
- return cleaned
210
- }
211
-
212
- await client
213
- .patch(currentAsset._id)
214
- .set({
215
- title: cleanField(currentAsset.title),
216
- altText: cleanField(currentAsset.altText),
217
- description: cleanField(currentAsset.description),
218
- ...(currentAsset._type === 'sanity.imageAsset' && {
219
- creditLine: cleanField(currentAsset.creditLine),
220
- }),
221
- })
222
- .commit()
223
- }, [client, currentAsset, locales])
224
-
225
- // Submit react-hook-form
226
- const onSubmit: SubmitHandler<AssetFormData> = useCallback(
227
- (formData) => {
228
- if (!assetItem?.asset) {
229
- return
230
- }
231
-
232
- const sanitizedFormData = sanitizeFormData(formData)
233
-
234
- dispatch(
235
- assetsActions.updateRequest({
236
- asset: assetItem?.asset,
237
- closeDialogId: assetItem?.asset._id,
238
- formData: {
239
- ...sanitizedFormData,
240
- // Map tags to sanity references
241
- opt: {
242
- media: {
243
- ...sanitizedFormData.opt.media,
244
- tags:
245
- sanitizedFormData.opt.media.tags?.map((tag: TagSelectOption) => ({
246
- _ref: tag.value,
247
- _type: 'reference',
248
- _weak: true,
249
- })) || null,
250
- },
251
- },
252
- },
253
- }),
254
- )
255
- },
256
- [assetItem?.asset, dispatch],
257
- )
258
-
259
- // Listen for asset mutations and update snapshot
260
- useEffect(() => {
261
- if (!assetItem?.asset) {
262
- return undefined
263
- }
264
-
265
- // Remember that Sanity listeners ignore joins, order clauses and projections
266
- const subscriptionAsset = client
267
- .listen(groq`*[_id == $id]`, {id: assetItem?.asset._id})
268
- .subscribe(handleAssetUpdate)
269
-
270
- return () => {
271
- subscriptionAsset?.unsubscribe()
272
- }
273
- }, [assetItem?.asset, client, handleAssetUpdate])
274
-
275
- // Update tags form field (react-select) when a new _inline_ tag has been created
276
- useEffect(() => {
277
- if (lastCreatedTag) {
278
- const existingTags = (getValues('opt.media.tags') as TagSelectOption[]) || []
279
- const updatedTags = existingTags.concat([lastCreatedTag])
280
- setValue('opt.media.tags', updatedTags, {shouldDirty: true})
281
- }
282
- }, [getValues, lastCreatedTag, setValue])
283
-
284
- // Update tags form field (react-select) when an _inline_ tag has been removed elsewhere
285
- useEffect(() => {
286
- if (lastRemovedTagIds) {
287
- const existingTags = (getValues('opt.media.tags') as TagSelectOption[]) || []
288
- const updatedTags = existingTags.filter((tag) => {
289
- return !lastRemovedTagIds.includes(tag.value)
290
- })
291
-
292
- setValue('opt.media.tags', updatedTags, {shouldDirty: true})
293
- }
294
- }, [getValues, lastRemovedTagIds, setValue])
295
-
296
- // Reset react-hook-form local state on mount and every time the asset has been updated elsewhere
297
- useEffect(() => {
298
- if (assetUpdatedPrev.current !== assetItem?.asset._updatedAt) {
299
- reset(generateDefaultValues(assetItem?.asset))
300
- }
301
- assetUpdatedPrev.current = assetItem?.asset._updatedAt
302
- }, [assetItem?.asset, generateDefaultValues, reset])
303
-
304
- const Footer = () => (
305
- <Box padding={3}>
306
- <Stack space={3}>
307
- {hasOrphanedLocales && (
308
- <Card padding={3} radius={2} shadow={1} tone="caution">
309
- <Flex align="center" justify="space-between" gap={3}>
310
- <Text size={1}>
311
- This asset has localized fields that are no longer configured. Clean them up to
312
- avoid validation errors.
313
- </Text>
314
- <Button
315
- fontSize={1}
316
- mode="ghost"
317
- onClick={handleCleanupLocales}
318
- text="Cleanup localized fields"
319
- tone="caution"
320
- />
321
- </Flex>
322
- </Card>
323
- )}
324
- <Flex justify="space-between">
325
- {/* Delete button */}
326
- <Button
327
- disabled={formUpdating}
328
- fontSize={1}
329
- mode="bleed"
330
- onClick={handleDelete}
331
- text="Delete"
332
- tone="critical"
333
- />
334
-
335
- {/* Submit button */}
336
- <FormSubmitButton
337
- disabled={formUpdating || !isDirty || !isValid || hasOrphanedLocales}
338
- isValid={isValid}
339
- lastUpdated={currentAsset?._updatedAt}
340
- onClick={handleSubmit(onSubmit)}
341
- />
342
- </Flex>
343
- </Stack>
344
- </Box>
345
- )
346
-
347
- if (!currentAsset) {
348
- return null
349
- }
350
-
351
- const detailsProps = {
352
- control,
353
- errors,
354
- formUpdating,
355
- register,
356
- setValue,
357
- assetTagOptions,
358
- allTagOptions,
359
- handleCreateTag,
360
- currentAsset,
361
- creditLine,
362
- locales,
363
- }
364
-
365
- return (
366
- <Dialog
367
- animate
368
- footer={<Footer />}
369
- header="Asset details"
370
- id={id}
371
- onClose={handleClose}
372
- width={3}
373
- >
374
- {/*
375
- We reverse direction to ensure the download button doesn't appear (in the DOM) before other tabbable items.
376
- This ensures that the dialog doesn't scroll down to the download button (which on smaller screens, can sometimes
377
- be below the fold).
378
- */}
379
- <Flex direction={['column-reverse', 'column-reverse', 'row-reverse']}>
380
- <Box flex={1} marginTop={[5, 5, 0]} padding={4}>
381
- <WithReferringDocuments documentStore={documentStore} id={currentAsset._id}>
382
- {({isLoading, referringDocuments}) => {
383
- const uniqueReferringDocuments = getUniqueDocuments(referringDocuments)
384
- return (
385
- <>
386
- {/* Tabs */}
387
- <TabList space={2}>
388
- <Tab
389
- aria-controls="details-panel"
390
- disabled={formUpdating}
391
- id="details-tab"
392
- label="Details"
393
- onClick={() => setTabSection('details')}
394
- selected={tabSection === 'details'}
395
- size={2}
396
- />
397
- <Tab
398
- aria-controls="references-panel"
399
- disabled={formUpdating}
400
- id="references-tab"
401
- label={`References${
402
- !isLoading && Array.isArray(uniqueReferringDocuments)
403
- ? ` (${uniqueReferringDocuments.length})`
404
- : ''
405
- }`}
406
- onClick={() => setTabSection('references')}
407
- selected={tabSection === 'references'}
408
- size={2}
409
- />
410
- </TabList>
411
-
412
- {/* Form fields */}
413
- <Box as="form" marginTop={4} onSubmit={handleSubmit(onSubmit)}>
414
- {/* Deleted notification */}
415
- {!assetItem && (
416
- <Card marginBottom={3} padding={3} radius={2} shadow={1} tone="critical">
417
- <Text size={1}>This file cannot be found – it may have been deleted.</Text>
418
- </Card>
419
- )}
420
-
421
- {/* Hidden button to enable enter key submissions */}
422
- <button style={{display: 'none'}} tabIndex={-1} type="submit" />
423
-
424
- {/* Panel: details */}
425
- <TabPanel
426
- aria-labelledby="details"
427
- hidden={tabSection !== 'details'}
428
- id="details-panel"
429
- >
430
- {CustomDetails ? (
431
- <CustomDetails
432
- {...detailsProps}
433
- renderDefaultDetails={renderDefaultDetails}
434
- />
435
- ) : (
436
- <Details {...detailsProps} />
437
- )}
438
- </TabPanel>
439
-
440
- {/* Panel: References */}
441
- <TabPanel
442
- aria-labelledby="references"
443
- hidden={tabSection !== 'references'}
444
- id="references-panel"
445
- >
446
- <Box marginTop={5}>
447
- {assetItem?.asset && (
448
- <DocumentList
449
- documents={uniqueReferringDocuments}
450
- isLoading={isLoading}
451
- />
452
- )}
453
- </Box>
454
- </TabPanel>
455
- </Box>
456
- </>
457
- )
458
- }}
459
- </WithReferringDocuments>
460
- </Box>
461
-
462
- <Box flex={1} padding={4}>
463
- <Box style={{aspectRatio: '1'}}>
464
- {/* File */}
465
- {isFileAsset(currentAsset) && <FileAssetPreview asset={currentAsset} />}
466
-
467
- {/* Image */}
468
- {isImageAsset(currentAsset) && (
469
- <Image
470
- draggable={false}
471
- $scheme={scheme}
472
- $showCheckerboard={!currentAsset?.metadata?.isOpaque}
473
- src={imageDprUrl(currentAsset, {height: 600, width: 600})}
474
- />
475
- )}
476
- </Box>
477
-
478
- {/* Metadata */}
479
- {currentAsset && (
480
- <Box marginTop={4}>
481
- <AssetMetadata asset={currentAsset} item={assetItem} />
482
- </Box>
483
- )}
484
- </Box>
485
- </Flex>
486
-
487
- {children}
488
- </Dialog>
489
- )
490
- }
491
-
492
- export default DialogAssetEdit
@@ -1,88 +0,0 @@
1
- import {WarningOutlineIcon} from '@sanity/icons'
2
- import {Box, Button, Flex, Stack, Text} from '@sanity/ui'
3
- import {type ReactNode} from 'react'
4
- import {useDispatch} from 'react-redux'
5
-
6
- import {dialogActions} from '../../modules/dialog'
7
- import type {DialogConfirmProps} from '../../types'
8
- import Dialog from '../Dialog'
9
-
10
- type Props = {
11
- children?: ReactNode
12
- dialog: DialogConfirmProps
13
- }
14
-
15
- const DialogConfirm = (props: Props) => {
16
- const {children, dialog} = props
17
-
18
- // Redux
19
- const dispatch = useDispatch()
20
-
21
- // Callbacks
22
- const handleClose = () => {
23
- dispatch(dialogActions.remove({id: dialog?.id}))
24
- }
25
-
26
- const handleConfirm = () => {
27
- // Close target dialog, if provided
28
- if (dialog?.closeDialogId) {
29
- dispatch(dialogActions.remove({id: dialog?.closeDialogId}))
30
- }
31
-
32
- if (dialog?.confirmCallbackAction) {
33
- dispatch(dialog.confirmCallbackAction)
34
- }
35
-
36
- // Close self
37
- handleClose()
38
- }
39
-
40
- const Footer = () => (
41
- <Box padding={3}>
42
- <Flex justify="space-between">
43
- <Button fontSize={1} mode="bleed" onClick={handleClose} text="Cancel" />
44
- <Button
45
- fontSize={1}
46
- onClick={handleConfirm}
47
- text={dialog?.confirmText}
48
- tone={dialog?.tone}
49
- />
50
- </Flex>
51
- </Box>
52
- )
53
-
54
- const Header = () => (
55
- <Flex align="center">
56
- <Box paddingX={1}>
57
- <WarningOutlineIcon />
58
- </Box>
59
- <Box marginLeft={2}>{dialog?.headerTitle}</Box>
60
- </Flex>
61
- )
62
-
63
- return (
64
- <Dialog
65
- animate
66
- footer={<Footer />}
67
- header={<Header />}
68
- id="confirm"
69
- onClose={handleClose}
70
- width={1}
71
- >
72
- <Box paddingX={4} paddingY={4}>
73
- <Stack space={3}>
74
- {dialog?.title && <Text size={1}>{dialog.title}</Text>}
75
- {dialog?.description && (
76
- <Text muted size={1}>
77
- <em>{dialog.description}</em>
78
- </Text>
79
- )}
80
- </Stack>
81
- </Box>
82
-
83
- {children}
84
- </Dialog>
85
- )
86
- }
87
-
88
- export default DialogConfirm
@@ -1,42 +0,0 @@
1
- import {Box} from '@sanity/ui'
2
- import {type ReactNode, useCallback} from 'react'
3
- import {useDispatch} from 'react-redux'
4
-
5
- import {dialogActions} from '../../modules/dialog'
6
- import type {DialogSearchFacetsProps} from '../../types'
7
- import Dialog from '../Dialog'
8
- import SearchFacets from '../SearchFacets'
9
- import SearchFacetsControl from '../SearchFacetsControl'
10
-
11
- type Props = {
12
- children: ReactNode
13
- dialog: DialogSearchFacetsProps
14
- }
15
-
16
- const DialogSearchFacets = (props: Props) => {
17
- const {
18
- children,
19
- dialog: {id},
20
- } = props
21
-
22
- // Redux
23
- const dispatch = useDispatch()
24
-
25
- // Callbacks
26
- const handleClose = useCallback(() => {
27
- dispatch(dialogActions.clear())
28
- }, [])
29
-
30
- return (
31
- <Dialog animate header="Filters" id={id} onClose={handleClose} width={1}>
32
- <Box padding={3}>
33
- <SearchFacets layout="stack" />
34
- <SearchFacetsControl />
35
- </Box>
36
-
37
- {children}
38
- </Dialog>
39
- )
40
- }
41
-
42
- export default DialogSearchFacets