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.
Files changed (162) hide show
  1. package/package.json +6 -15
  2. package/dist/index.cjs +0 -4721
  3. package/dist/index.cjs.map +0 -1
  4. package/dist/index.d.cts +0 -239
  5. package/dist/index.d.cts.map +0 -1
  6. package/sanity.json +0 -8
  7. package/src/__tests__/fixtures/createEpicTestStore.ts +0 -28
  8. package/src/__tests__/fixtures/listenMock.ts +0 -9
  9. package/src/__tests__/fixtures/mockSanityClient.ts +0 -84
  10. package/src/__tests__/fixtures/renderWithProviders.tsx +0 -55
  11. package/src/__tests__/fixtures/rootState.ts +0 -27
  12. package/src/__tests__/fixtures/withinDialog.ts +0 -28
  13. package/src/components/AssetGridVirtualized/index.tsx +0 -94
  14. package/src/components/AssetMetadata/index.tsx +0 -122
  15. package/src/components/AssetTableVirtualized/index.tsx +0 -73
  16. package/src/components/AutoTagInputWrapper/index.tsx +0 -85
  17. package/src/components/Browser/Browser.test.tsx +0 -45
  18. package/src/components/Browser/index.tsx +0 -90
  19. package/src/components/Browser/useBrowserInit.ts +0 -126
  20. package/src/components/ButtonAssetCopy/index.tsx +0 -65
  21. package/src/components/ButtonViewGroup/index.tsx +0 -39
  22. package/src/components/CardAsset/CardAsset.test.tsx +0 -323
  23. package/src/components/CardAsset/index.tsx +0 -290
  24. package/src/components/CardUpload/index.tsx +0 -161
  25. package/src/components/Controls/index.tsx +0 -136
  26. package/src/components/DebugControls/index.tsx +0 -80
  27. package/src/components/Dialog/index.tsx +0 -11
  28. package/src/components/DialogAssetEdit/Details.tsx +0 -181
  29. package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +0 -216
  30. package/src/components/DialogAssetEdit/index.tsx +0 -493
  31. package/src/components/DialogConfirm/index.tsx +0 -90
  32. package/src/components/DialogSearchFacets/index.tsx +0 -42
  33. package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
  34. package/src/components/DialogTagCreate/index.tsx +0 -111
  35. package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
  36. package/src/components/DialogTagEdit/index.tsx +0 -201
  37. package/src/components/DialogTags/index.tsx +0 -45
  38. package/src/components/Dialogs/index.tsx +0 -76
  39. package/src/components/DocumentList/index.tsx +0 -62
  40. package/src/components/FileAssetPreview/index.tsx +0 -37
  41. package/src/components/FileIcon/index.tsx +0 -43
  42. package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +0 -63
  43. package/src/components/FormBuilderTool/index.tsx +0 -69
  44. package/src/components/FormFieldInputLabel/index.tsx +0 -66
  45. package/src/components/FormFieldInputTags/index.tsx +0 -98
  46. package/src/components/FormFieldInputText/index.tsx +0 -41
  47. package/src/components/FormFieldInputTextarea/index.tsx +0 -43
  48. package/src/components/FormSubmitButton/index.tsx +0 -59
  49. package/src/components/Header/index.tsx +0 -80
  50. package/src/components/Image/index.tsx +0 -41
  51. package/src/components/Items/index.tsx +0 -68
  52. package/src/components/Notifications/index.tsx +0 -24
  53. package/src/components/OrderSelect/index.tsx +0 -66
  54. package/src/components/PickedBar/index.tsx +0 -77
  55. package/src/components/Progress/index.tsx +0 -38
  56. package/src/components/ReduxProvider/index.tsx +0 -96
  57. package/src/components/SearchFacet/index.tsx +0 -66
  58. package/src/components/SearchFacetNumber/index.tsx +0 -133
  59. package/src/components/SearchFacetSelect/index.tsx +0 -110
  60. package/src/components/SearchFacetString/index.tsx +0 -88
  61. package/src/components/SearchFacetTags/index.tsx +0 -121
  62. package/src/components/SearchFacets/index.tsx +0 -72
  63. package/src/components/SearchFacetsControl/index.tsx +0 -140
  64. package/src/components/TableHeader/index.tsx +0 -110
  65. package/src/components/TableHeaderItem/index.tsx +0 -61
  66. package/src/components/TableRowAsset/index.tsx +0 -419
  67. package/src/components/TableRowUpload/index.tsx +0 -164
  68. package/src/components/Tag/index.tsx +0 -200
  69. package/src/components/TagIcon/index.tsx +0 -22
  70. package/src/components/TagView/index.tsx +0 -39
  71. package/src/components/TagViewHeader/index.tsx +0 -70
  72. package/src/components/TagsPanel/index.tsx +0 -40
  73. package/src/components/TagsVirtualized/index.tsx +0 -160
  74. package/src/components/TextInputNumber/index.tsx +0 -32
  75. package/src/components/TextInputSearch/index.tsx +0 -60
  76. package/src/components/Tool/index.tsx +0 -13
  77. package/src/components/UploadDropzone/UploadDropzone.test.tsx +0 -40
  78. package/src/components/UploadDropzone/index.tsx +0 -173
  79. package/src/config/orders.ts +0 -28
  80. package/src/config/searchFacets.ts +0 -312
  81. package/src/constants.ts +0 -87
  82. package/src/contexts/AssetSourceDispatchContext.tsx +0 -38
  83. package/src/contexts/DropzoneDispatchContext.tsx +0 -32
  84. package/src/contexts/ToolOptionsContext.tsx +0 -66
  85. package/src/formSchema/index.test.ts +0 -56
  86. package/src/formSchema/index.ts +0 -39
  87. package/src/hooks/useBreakpointIndex.ts +0 -50
  88. package/src/hooks/useKeyPress.ts +0 -39
  89. package/src/hooks/usePortalPopoverProps.ts +0 -13
  90. package/src/hooks/useTypedSelector.ts +0 -7
  91. package/src/hooks/useVersionedClient.ts +0 -6
  92. package/src/index.ts +0 -5
  93. package/src/modules/assets/actions.ts +0 -42
  94. package/src/modules/assets/deleteAndUpdateEpics.test.ts +0 -87
  95. package/src/modules/assets/fetchEpic.test.ts +0 -73
  96. package/src/modules/assets/index.ts +0 -782
  97. package/src/modules/assets/reducer.test.ts +0 -91
  98. package/src/modules/assets/tagsAndListenerEpics.test.ts +0 -206
  99. package/src/modules/debug/index.ts +0 -28
  100. package/src/modules/dialog/actions.ts +0 -10
  101. package/src/modules/dialog/epics.test.ts +0 -168
  102. package/src/modules/dialog/index.ts +0 -238
  103. package/src/modules/dialog/reducer.test.ts +0 -185
  104. package/src/modules/index.ts +0 -117
  105. package/src/modules/notifications/epics.test.ts +0 -374
  106. package/src/modules/notifications/index.ts +0 -199
  107. package/src/modules/notifications/reducer.test.ts +0 -54
  108. package/src/modules/search/index.test.ts +0 -36
  109. package/src/modules/search/index.ts +0 -167
  110. package/src/modules/selected/index.ts +0 -22
  111. package/src/modules/selectors.test.ts +0 -21
  112. package/src/modules/selectors.ts +0 -17
  113. package/src/modules/tags/epics.test.ts +0 -96
  114. package/src/modules/tags/index.test.ts +0 -42
  115. package/src/modules/tags/index.ts +0 -540
  116. package/src/modules/types.ts +0 -3
  117. package/src/modules/uploads/actions.ts +0 -13
  118. package/src/modules/uploads/epics.test.ts +0 -109
  119. package/src/modules/uploads/index.test.ts +0 -59
  120. package/src/modules/uploads/index.ts +0 -272
  121. package/src/operators/checkTagName.test.ts +0 -29
  122. package/src/operators/checkTagName.ts +0 -33
  123. package/src/operators/debugThrottle.ts +0 -25
  124. package/src/plugin.tsx +0 -54
  125. package/src/schemas/tag.ts +0 -28
  126. package/src/styled/GlobalStyles/index.tsx +0 -40
  127. package/src/styled/react-select/creatable.tsx +0 -184
  128. package/src/styled/react-select/single.tsx +0 -184
  129. package/src/types/index.ts +0 -346
  130. package/src/types/sanity-ui.d.ts +0 -5
  131. package/src/utils/applyMediaTags.ts +0 -87
  132. package/src/utils/blocksToText.test.ts +0 -43
  133. package/src/utils/blocksToText.ts +0 -27
  134. package/src/utils/constructFilter.test.ts +0 -120
  135. package/src/utils/constructFilter.ts +0 -98
  136. package/src/utils/generatePreviewBlobUrl.test.ts +0 -68
  137. package/src/utils/generatePreviewBlobUrl.ts +0 -53
  138. package/src/utils/getAssetResolution.test.ts +0 -13
  139. package/src/utils/getAssetResolution.ts +0 -7
  140. package/src/utils/getDocumentAssetIds.test.ts +0 -50
  141. package/src/utils/getDocumentAssetIds.ts +0 -35
  142. package/src/utils/getSchemeColor.test.ts +0 -12
  143. package/src/utils/getSchemeColor.ts +0 -43
  144. package/src/utils/getTagSelectOptions.test.ts +0 -44
  145. package/src/utils/getTagSelectOptions.ts +0 -16
  146. package/src/utils/getUniqueDocuments.test.ts +0 -26
  147. package/src/utils/getUniqueDocuments.ts +0 -15
  148. package/src/utils/imageDprUrl.test.ts +0 -46
  149. package/src/utils/imageDprUrl.ts +0 -27
  150. package/src/utils/isSupportedAssetType.test.ts +0 -16
  151. package/src/utils/isSupportedAssetType.ts +0 -15
  152. package/src/utils/mediaField.ts +0 -73
  153. package/src/utils/sanitizeFormData.test.ts +0 -59
  154. package/src/utils/sanitizeFormData.ts +0 -26
  155. package/src/utils/typeGuards.test.ts +0 -18
  156. package/src/utils/typeGuards.ts +0 -9
  157. package/src/utils/uploadSanityAsset.test.ts +0 -29
  158. package/src/utils/uploadSanityAsset.ts +0 -97
  159. package/src/utils/withMaxConcurrency.test.ts +0 -43
  160. package/src/utils/withMaxConcurrency.ts +0 -55
  161. package/src/utils/zodFormResolver.ts +0 -17
  162. package/v2-incompatible.js +0 -11
@@ -1,59 +0,0 @@
1
- // @vitest-environment node
2
-
3
- import {describe, expect, it} from 'vitest'
4
-
5
- import type {UploadItem} from '../../types'
6
- import uploadsReducer, {uploadsActions} from './index'
7
-
8
- describe('uploads slice', () => {
9
- it('uploadStart adds item to queue', () => {
10
- let state = uploadsReducer(undefined, {type: '@@INIT'} as never)
11
- const uploadItem = {
12
- _type: 'upload',
13
- assetType: 'image',
14
- hash: 'abc',
15
- name: 'x.png',
16
- size: 1,
17
- status: 'queued',
18
- } as UploadItem
19
-
20
- state = uploadsReducer(
21
- state,
22
- uploadsActions.uploadStart({
23
- file: new File([], 'x.png'),
24
- uploadItem,
25
- }),
26
- )
27
-
28
- expect(state.allIds).toEqual(['abc'])
29
- expect(state.byIds['abc']).toMatchObject({hash: 'abc', status: 'queued'})
30
- })
31
-
32
- it('uploadProgress updates percent and status', () => {
33
- let state = uploadsReducer(undefined, {type: '@@INIT'} as never)
34
- const uploadItem = {
35
- _type: 'upload',
36
- assetType: 'image',
37
- hash: 'h1',
38
- name: 'x.png',
39
- size: 1,
40
- status: 'queued',
41
- percent: 0,
42
- } as UploadItem
43
-
44
- state = uploadsReducer(
45
- state,
46
- uploadsActions.uploadStart({file: new File([], 'x.png'), uploadItem}),
47
- )
48
- state = uploadsReducer(
49
- state,
50
- uploadsActions.uploadProgress({
51
- uploadHash: 'h1',
52
- event: {percent: 42, stage: 'upload'} as any,
53
- }),
54
- )
55
-
56
- expect(state.byIds['h1']!.percent).toBe(42)
57
- expect(state.byIds['h1']!.status).toBe('uploading')
58
- })
59
- })
@@ -1,272 +0,0 @@
1
- import {createSelector, createSlice, type PayloadAction} from '@reduxjs/toolkit'
2
- import type {ClientError, SanityAssetDocument, SanityImageAssetDocument} from '@sanity/client'
3
- import groq from 'groq'
4
- import {empty, merge, of} from 'rxjs'
5
- import {catchError, delay, filter, mergeMap, takeUntil, withLatestFrom} from 'rxjs/operators'
6
-
7
- import type {HttpError, MyEpic, SanityUploadProgressEvent, UploadItem} from '../../types'
8
- import constructFilter from '../../utils/constructFilter'
9
- import {generatePreviewBlobUrl$} from '../../utils/generatePreviewBlobUrl'
10
- import {hashFile$, uploadAsset$} from '../../utils/uploadSanityAsset'
11
- import {assetsActions} from '../assets'
12
- import type {RootReducerState} from '../types'
13
- import {UPLOADS_ACTIONS} from './actions'
14
-
15
- export type UploadsReducerState = {
16
- allIds: string[]
17
- byIds: Record<string, UploadItem>
18
- }
19
-
20
- const initialState = {
21
- allIds: [],
22
- byIds: {},
23
- } as UploadsReducerState
24
-
25
- const uploadsSlice = createSlice({
26
- name: 'uploads',
27
- initialState,
28
- extraReducers: (builder) => {
29
- builder //
30
- .addCase(UPLOADS_ACTIONS.uploadComplete, (state, action) => {
31
- const {asset} = action.payload
32
- if (state.byIds[asset.sha1hash]) {
33
- state.byIds[asset.sha1hash]!.status = 'complete'
34
- }
35
- })
36
- },
37
- reducers: {
38
- checkRequest(
39
- _state,
40
- _action: PayloadAction<{assets: (SanityAssetDocument | SanityImageAssetDocument)[]}>,
41
- ) {
42
- //
43
- },
44
- checkComplete(state, action: PayloadAction<{results: Record<string, string | null>}>) {
45
- const {results} = action.payload
46
-
47
- const assetHashes = Object.keys(results)
48
-
49
- assetHashes.forEach((hash) => {
50
- const deleteIndex = state.allIds.indexOf(hash)
51
- if (deleteIndex >= 0) {
52
- state.allIds.splice(deleteIndex, 1)
53
- }
54
-
55
- if (state.byIds[hash]) {
56
- const blobUrl = state.byIds[hash].objectUrl
57
- if (blobUrl) {
58
- window.URL.revokeObjectURL(blobUrl)
59
- }
60
-
61
- delete state.byIds[hash]
62
- }
63
- })
64
- },
65
- previewReady(state, action: PayloadAction<{hash: string; blobUrl: string}>) {
66
- const {blobUrl, hash} = action.payload
67
- if (state.byIds[hash]) {
68
- state.byIds[hash].objectUrl = blobUrl
69
- }
70
- },
71
- uploadCancel(state, action: PayloadAction<{hash: string}>) {
72
- const {hash} = action.payload
73
- const deleteIndex = state.allIds.indexOf(hash)
74
- if (deleteIndex >= 0) {
75
- state.allIds.splice(deleteIndex, 1)
76
- }
77
- if (state.byIds[hash]) {
78
- delete state.byIds[hash]
79
- }
80
- },
81
- uploadError(state, action: PayloadAction<{error: HttpError; hash: string}>) {
82
- const {hash} = action.payload
83
- const deleteIndex = state.allIds.indexOf(hash)
84
- if (deleteIndex >= 0) {
85
- state.allIds.splice(deleteIndex, 1)
86
- }
87
- delete state.byIds[hash]
88
- },
89
- uploadRequest(
90
- _state,
91
- _action: PayloadAction<{file: File; forceAsAssetType?: 'file' | 'image'}>,
92
- ) {
93
- //
94
- },
95
- uploadProgress(
96
- state,
97
- action: PayloadAction<{event: SanityUploadProgressEvent; uploadHash: string}>,
98
- ) {
99
- const {event, uploadHash} = action.payload
100
- state.byIds[uploadHash]!.percent = event.percent
101
- state.byIds[uploadHash]!.status = 'uploading'
102
- },
103
- uploadStart(state, action: PayloadAction<{file: File; uploadItem: UploadItem}>) {
104
- const {uploadItem} = action.payload
105
- if (!state.allIds.includes(uploadItem.hash)) {
106
- state.allIds.push(uploadItem.hash)
107
- }
108
- state.byIds[uploadItem.hash] = uploadItem
109
- },
110
- },
111
- })
112
-
113
- // Epics
114
-
115
- export const uploadsAssetStartEpic: MyEpic = (action$, _state$, {client}) =>
116
- action$.pipe(
117
- filter(uploadsActions.uploadStart.match),
118
- mergeMap((action) => {
119
- const {file, uploadItem} = action.payload
120
-
121
- return merge(
122
- // Generate low res preview
123
- of(null).pipe(
124
- mergeMap(() => generatePreviewBlobUrl$(file)),
125
- mergeMap((url) => {
126
- return of(
127
- uploadsActions.previewReady({
128
- blobUrl: url,
129
- hash: uploadItem.hash,
130
- }),
131
- )
132
- }),
133
- ),
134
- // Upload asset and receive progress / complete events
135
- of(null).pipe(
136
- // delay(500000), // debug uploads
137
- mergeMap(() => uploadAsset$(client, uploadItem.assetType, file, uploadItem.hash)),
138
- takeUntil(
139
- action$.pipe(
140
- filter(uploadsActions.uploadCancel.match),
141
- filter((v) => v.payload.hash === uploadItem.hash),
142
- ),
143
- ),
144
- mergeMap((event) => {
145
- if (event?.type === 'complete') {
146
- return of(
147
- UPLOADS_ACTIONS.uploadComplete({
148
- asset: event.asset,
149
- }),
150
- )
151
- }
152
- if (event?.type === 'progress' && event?.stage === 'upload') {
153
- return of(
154
- uploadsActions.uploadProgress({
155
- event,
156
- uploadHash: uploadItem.hash,
157
- }),
158
- )
159
- }
160
- return empty()
161
- }),
162
- catchError((error: ClientError) =>
163
- of(
164
- uploadsActions.uploadError({
165
- error: {
166
- message: error?.message || 'Internal error',
167
- statusCode: error?.statusCode || 500,
168
- },
169
- hash: uploadItem.hash,
170
- }),
171
- ),
172
- ),
173
- ),
174
- )
175
- }),
176
- )
177
-
178
- export const uploadsAssetUploadEpic: MyEpic = (action$, state$) =>
179
- action$.pipe(
180
- filter(uploadsActions.uploadRequest.match),
181
- withLatestFrom(state$),
182
- mergeMap(([action, state]) => {
183
- const {file, forceAsAssetType} = action.payload
184
-
185
- return of(action).pipe(
186
- // Generate SHA1 hash from local file
187
- // This will throw in insecure contexts (non-localhost / https)
188
- mergeMap(() => hashFile$(file)),
189
- // Ignore if the file exists and is currently being uploaded
190
- filter((hash) => {
191
- const exists = !!state.uploads.byIds[hash]
192
- return !exists
193
- }),
194
- // Dispatch start action and begin upload process
195
- mergeMap((hash) => {
196
- const assetType = forceAsAssetType || (file.type.indexOf('image') >= 0 ? 'image' : 'file')
197
- const uploadItem = {
198
- _type: 'upload',
199
- assetType,
200
- hash,
201
- name: file.name,
202
- size: file.size,
203
- status: 'queued',
204
- } as UploadItem
205
- return of(uploadsActions.uploadStart({file, uploadItem}))
206
- }),
207
- )
208
- }),
209
- )
210
-
211
- export const uploadsCompleteQueueEpic: MyEpic = (action$) =>
212
- action$.pipe(
213
- filter(UPLOADS_ACTIONS.uploadComplete.match),
214
- mergeMap((action) => {
215
- return of(
216
- uploadsActions.checkRequest({
217
- assets: [action.payload.asset],
218
- }),
219
- )
220
- }),
221
- )
222
-
223
- export const uploadsCheckRequestEpic: MyEpic = (action$, state$, {client}) =>
224
- action$.pipe(
225
- filter(uploadsActions.checkRequest.match),
226
- withLatestFrom(state$),
227
- mergeMap(([action, state]) => {
228
- const {assets} = action.payload
229
-
230
- const documentIds = assets.map((asset) => asset._id)
231
-
232
- const constructedFilter = constructFilter({
233
- assetTypes: state.assets.assetTypes,
234
- searchFacets: state.search.facets,
235
- searchQuery: state.search.query,
236
- })
237
-
238
- const query = groq`
239
- *[${constructedFilter} && _id in $documentIds].sha1hash
240
- `
241
-
242
- return of(action).pipe(
243
- delay(1000), // give Sanity some time to register the recently uploaded asset
244
- mergeMap(() => client.observable.fetch<string[]>(query, {documentIds})),
245
- mergeMap((resultHashes) => {
246
- const checkedResults = assets.reduce((acc: Record<string, string | null>, asset) => {
247
- acc[asset.sha1hash] = resultHashes.includes(asset.sha1hash) ? asset._id : null
248
- return acc
249
- }, {})
250
-
251
- return of(
252
- uploadsActions.checkComplete({results: checkedResults}), //
253
- assetsActions.insertUploads({results: checkedResults}),
254
- )
255
- }),
256
- )
257
- }),
258
- )
259
-
260
- // Selectors
261
-
262
- export const selectUploadById = createSelector(
263
- [
264
- (state: RootReducerState) => state.uploads.byIds,
265
- (_state: RootReducerState, uploadId: string) => uploadId,
266
- ],
267
- (byIds, uploadId) => byIds[uploadId],
268
- )
269
-
270
- export const uploadsActions = {...uploadsSlice.actions}
271
-
272
- export default uploadsSlice.reducer
@@ -1,29 +0,0 @@
1
- // @vitest-environment node
2
-
3
- import type {SanityClient} from '@sanity/client'
4
- import {firstValueFrom, of} from 'rxjs'
5
- import {describe, expect, it, vi} from 'vitest'
6
-
7
- import checkTagName from './checkTagName'
8
-
9
- describe('checkTagName', () => {
10
- it('errors with 409 when a tag with the same slug exists', async () => {
11
- const client = {
12
- fetch: vi.fn().mockResolvedValue(1),
13
- } as unknown as SanityClient
14
-
15
- await expect(
16
- firstValueFrom(of(null).pipe(checkTagName(client, 'existing'))),
17
- ).rejects.toMatchObject({statusCode: 409, message: 'Tag already exists'})
18
- })
19
-
20
- it('emits true when name is available', async () => {
21
- const client = {
22
- fetch: vi.fn().mockResolvedValue(0),
23
- } as unknown as SanityClient
24
-
25
- await expect(firstValueFrom(of(null).pipe(checkTagName(client, 'fresh-name')))).resolves.toBe(
26
- true,
27
- )
28
- })
29
- })
@@ -1,33 +0,0 @@
1
- import type {SanityClient} from '@sanity/client'
2
- import groq from 'groq'
3
- import {from, Observable, of, throwError} from 'rxjs'
4
- import {mergeMap} from 'rxjs/operators'
5
-
6
- import {TAG_DOCUMENT_NAME} from '../constants'
7
- import type {HttpError} from '../types'
8
-
9
- const checkTagName = (client: SanityClient, name: string) => {
10
- return function <T>(source: Observable<T>): Observable<boolean> {
11
- return source.pipe(
12
- mergeMap(() => {
13
- return from(
14
- client.fetch(groq`count(*[_type == "${TAG_DOCUMENT_NAME}" && name.current == $name])`, {
15
- name,
16
- }),
17
- ) as Observable<number>
18
- }),
19
- mergeMap((existingTagCount: number) => {
20
- if (existingTagCount > 0) {
21
- return throwError({
22
- message: 'Tag already exists',
23
- statusCode: 409,
24
- } as HttpError)
25
- }
26
-
27
- return of(true)
28
- }),
29
- )
30
- }
31
- }
32
-
33
- export default checkTagName
@@ -1,25 +0,0 @@
1
- import {iif, type Observable, of, throwError} from 'rxjs'
2
- import {delay, mergeMap} from 'rxjs/operators'
3
-
4
- const debugThrottle = (throttled?: boolean) => {
5
- return function <T>(source: Observable<T>): Observable<T> {
6
- return iif(
7
- () => !!throttled,
8
- source.pipe(
9
- delay(3000),
10
- mergeMap((v) => {
11
- if (Math.random() > 0.5) {
12
- return throwError({
13
- message: 'Test error',
14
- statusCode: 500,
15
- })
16
- }
17
- return of(v)
18
- }),
19
- ),
20
- source,
21
- )
22
- }
23
- }
24
-
25
- export default debugThrottle
package/src/plugin.tsx DELETED
@@ -1,54 +0,0 @@
1
- import {ImageIcon} from '@sanity/icons'
2
- import {type AssetSource, type Tool as SanityTool, definePlugin} from 'sanity'
3
-
4
- import FormBuilderTool from './components/FormBuilderTool'
5
- import Tool from './components/Tool'
6
- import {ToolOptionsProvider} from './contexts/ToolOptionsContext'
7
- import mediaTag from './schemas/tag'
8
- import type {MediaToolOptions} from './types'
9
-
10
- const plugin = {
11
- icon: ImageIcon,
12
- name: 'media',
13
- title: 'Media',
14
- }
15
-
16
- export const mediaAssetSource = {
17
- ...plugin,
18
- component: FormBuilderTool,
19
- } satisfies AssetSource
20
-
21
- const tool = {
22
- ...plugin,
23
- component: Tool,
24
- __internalApplicationType: 'sanity/media',
25
- } satisfies SanityTool
26
-
27
- export const media = definePlugin<MediaToolOptions | void>((options) => ({
28
- name: 'media',
29
- studio: {
30
- components: {
31
- layout: (props) => (
32
- <ToolOptionsProvider options={options}>{props.renderDefault(props)}</ToolOptionsProvider>
33
- ),
34
- },
35
- },
36
- form: {
37
- file: {
38
- assetSources: (prev) => {
39
- return [...prev, mediaAssetSource]
40
- },
41
- },
42
- image: {
43
- assetSources: (prev) => {
44
- return [...prev, mediaAssetSource]
45
- },
46
- },
47
- },
48
- schema: {
49
- types: [mediaTag],
50
- },
51
- tools: (prev) => {
52
- return [...prev, tool]
53
- },
54
- }))
@@ -1,28 +0,0 @@
1
- import TagIcon from '../components/TagIcon'
2
- import {TAG_DOCUMENT_NAME} from '../constants'
3
-
4
- export default {
5
- title: 'Media Tag',
6
- icon: TagIcon,
7
- name: TAG_DOCUMENT_NAME,
8
- type: 'document',
9
- fields: [
10
- {
11
- title: 'Name',
12
- name: 'name',
13
- type: 'slug',
14
- },
15
- ],
16
- preview: {
17
- select: {
18
- name: 'name',
19
- },
20
- prepare(selection: any) {
21
- const {name} = selection
22
- return {
23
- media: TagIcon,
24
- title: name?.current,
25
- }
26
- },
27
- },
28
- }
@@ -1,40 +0,0 @@
1
- import {createGlobalStyle, css} from 'styled-components'
2
-
3
- const customScrollbar = css`
4
- ::-webkit-scrollbar {
5
- width: 14px;
6
- }
7
-
8
- ::-webkit-scrollbar-thumb {
9
- border-radius: 10px;
10
- border: 4px solid rgba(0, 0, 0, 0);
11
- background: var(--card-border-color);
12
- background-clip: padding-box;
13
-
14
- &:hover {
15
- background: var(--card-muted-fg-color);
16
- background-clip: padding-box;
17
- }
18
- }
19
- `
20
-
21
- const GlobalStyle = createGlobalStyle`
22
- .media__custom-scrollbar {
23
- ${customScrollbar}
24
- }
25
-
26
- // @sanity/ui overrides
27
-
28
- // Custom scrollbar on Box (used in Dialogs)
29
- div[data-ui="Box"] {
30
- ${customScrollbar}
31
- }
32
-
33
- // Dialog background color
34
- div[data-ui="Dialog"] {
35
- background-color: rgba(15, 17, 18, 0.9);
36
- }
37
-
38
- `
39
-
40
- export default GlobalStyle