sanity-plugin-media 4.3.1 → 4.3.2
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/LICENSE +4 -4
- package/README.md +12 -12
- package/dist/index.d.mts +263 -195
- package/dist/index.d.ts +263 -195
- package/dist/index.js +83 -203
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -203
- package/dist/index.mjs.map +1 -1
- package/package.json +41 -63
- package/src/__tests__/fixtures/createEpicTestStore.ts +5 -4
- package/src/__tests__/fixtures/mockSanityClient.ts +8 -8
- package/src/__tests__/fixtures/renderWithProviders.tsx +8 -7
- package/src/__tests__/fixtures/rootState.ts +4 -4
- package/src/components/AssetGridVirtualized/index.tsx +8 -7
- package/src/components/AssetMetadata/index.tsx +6 -5
- package/src/components/AssetTableVirtualized/index.tsx +7 -6
- package/src/components/AutoTagInputWrapper/index.tsx +9 -4
- package/src/components/Browser/Browser.test.tsx +9 -8
- package/src/components/Browser/index.tsx +2 -1
- package/src/components/Browser/useBrowserInit.ts +9 -9
- package/src/components/ButtonAssetCopy/index.tsx +1 -0
- package/src/components/ButtonViewGroup/index.tsx +4 -3
- package/src/components/CardAsset/CardAsset.test.tsx +53 -52
- package/src/components/CardAsset/index.tsx +52 -49
- package/src/components/CardUpload/index.tsx +7 -6
- package/src/components/Controls/index.tsx +7 -6
- package/src/components/DebugControls/index.tsx +5 -4
- package/src/components/DialogAssetEdit/Details.tsx +3 -2
- package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +28 -27
- package/src/components/DialogAssetEdit/index.tsx +37 -37
- package/src/components/DialogConfirm/index.tsx +2 -1
- package/src/components/DialogSearchFacets/index.tsx +3 -2
- package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +16 -15
- package/src/components/DialogTagCreate/index.tsx +11 -10
- package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +28 -27
- package/src/components/DialogTagEdit/index.tsx +17 -16
- package/src/components/DialogTags/index.tsx +4 -3
- package/src/components/Dialogs/index.tsx +2 -3
- package/src/components/DocumentList/index.tsx +2 -3
- package/src/components/FileAssetPreview/index.tsx +2 -2
- package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +12 -11
- package/src/components/FormBuilderTool/index.tsx +2 -1
- package/src/components/FormFieldInputLabel/index.tsx +1 -2
- package/src/components/FormFieldInputTags/index.tsx +4 -3
- package/src/components/FormSubmitButton/index.tsx +1 -1
- package/src/components/Header/index.tsx +3 -3
- package/src/components/Image/index.tsx +10 -4
- package/src/components/Items/index.tsx +5 -4
- package/src/components/Notifications/index.tsx +3 -2
- package/src/components/OrderSelect/index.tsx +4 -3
- package/src/components/PickedBar/index.tsx +2 -1
- package/src/components/Progress/index.tsx +3 -3
- package/src/components/ReduxProvider/index.tsx +15 -12
- package/src/components/SearchFacet/index.tsx +3 -2
- package/src/components/SearchFacetNumber/index.tsx +8 -8
- package/src/components/SearchFacetSelect/index.tsx +7 -8
- package/src/components/SearchFacetString/index.tsx +1 -1
- package/src/components/SearchFacetTags/index.tsx +13 -12
- package/src/components/SearchFacets/index.tsx +2 -3
- package/src/components/SearchFacetsControl/index.tsx +13 -12
- package/src/components/TableHeader/index.tsx +18 -17
- package/src/components/TableHeaderItem/index.tsx +4 -4
- package/src/components/TableRowAsset/index.tsx +37 -36
- package/src/components/TableRowUpload/index.tsx +7 -6
- package/src/components/Tag/index.tsx +8 -7
- package/src/components/TagView/index.tsx +2 -2
- package/src/components/TagViewHeader/index.tsx +5 -4
- package/src/components/TagsPanel/index.tsx +3 -3
- package/src/components/TagsVirtualized/index.tsx +25 -24
- package/src/components/TextInputSearch/index.tsx +3 -2
- package/src/components/UploadDropzone/UploadDropzone.test.tsx +8 -7
- package/src/components/UploadDropzone/index.tsx +14 -13
- package/src/config/orders.ts +6 -6
- package/src/config/searchFacets.ts +56 -55
- package/src/constants.ts +15 -14
- package/src/contexts/AssetSourceDispatchContext.tsx +1 -1
- package/src/contexts/ToolOptionsContext.tsx +6 -5
- package/src/formSchema/index.test.ts +6 -5
- package/src/formSchema/index.ts +5 -5
- package/src/hooks/useBreakpointIndex.ts +6 -6
- package/src/hooks/useKeyPress.ts +2 -2
- package/src/hooks/usePortalPopoverProps.ts +1 -1
- package/src/modules/assets/actions.ts +8 -7
- package/src/modules/assets/deleteAndUpdateEpics.test.ts +18 -17
- package/src/modules/assets/fetchEpic.test.ts +12 -11
- package/src/modules/assets/index.ts +134 -133
- package/src/modules/assets/reducer.test.ts +9 -8
- package/src/modules/assets/tagsAndListenerEpics.test.ts +36 -35
- package/src/modules/debug/index.ts +3 -3
- package/src/modules/dialog/actions.ts +2 -2
- package/src/modules/dialog/epics.test.ts +29 -28
- package/src/modules/dialog/index.ts +36 -35
- package/src/modules/dialog/reducer.test.ts +31 -30
- package/src/modules/index.ts +9 -9
- package/src/modules/notifications/epics.test.ts +71 -70
- package/src/modules/notifications/index.ts +50 -49
- package/src/modules/notifications/reducer.test.ts +8 -7
- package/src/modules/search/index.test.ts +2 -1
- package/src/modules/search/index.ts +22 -22
- package/src/modules/selected/index.ts +2 -2
- package/src/modules/selectors.test.ts +4 -3
- package/src/modules/selectors.ts +5 -5
- package/src/modules/tags/epics.test.ts +16 -15
- package/src/modules/tags/index.test.ts +2 -1
- package/src/modules/tags/index.ts +82 -81
- package/src/modules/uploads/actions.ts +3 -3
- package/src/modules/uploads/epics.test.ts +13 -12
- package/src/modules/uploads/index.test.ts +8 -7
- package/src/modules/uploads/index.ts +48 -47
- package/src/operators/checkTagName.test.ts +7 -6
- package/src/operators/checkTagName.ts +6 -5
- package/src/operators/debugThrottle.ts +4 -4
- package/src/plugin.tsx +18 -18
- package/src/schemas/tag.ts +7 -7
- package/src/styled/react-select/creatable.tsx +40 -39
- package/src/styled/react-select/single.tsx +39 -38
- package/src/types/index.ts +4 -3
- package/src/utils/applyMediaTags.ts +11 -10
- package/src/utils/blocksToText.test.ts +5 -4
- package/src/utils/blocksToText.ts +2 -2
- package/src/utils/constructFilter.test.ts +15 -14
- package/src/utils/constructFilter.ts +7 -7
- package/src/utils/generatePreviewBlobUrl.test.ts +6 -5
- package/src/utils/generatePreviewBlobUrl.ts +2 -2
- package/src/utils/getAssetResolution.test.ts +3 -2
- package/src/utils/getDocumentAssetIds.test.ts +7 -6
- package/src/utils/getDocumentAssetIds.ts +2 -2
- package/src/utils/getSchemeColor.test.ts +1 -0
- package/src/utils/getSchemeColor.ts +9 -9
- package/src/utils/getTagSelectOptions.test.ts +6 -5
- package/src/utils/getTagSelectOptions.ts +1 -1
- package/src/utils/getUniqueDocuments.test.ts +4 -3
- package/src/utils/getUniqueDocuments.ts +2 -2
- package/src/utils/imageDprUrl.test.ts +4 -3
- package/src/utils/imageDprUrl.ts +1 -1
- package/src/utils/isSupportedAssetType.test.ts +1 -0
- package/src/utils/mediaField.ts +4 -3
- package/src/utils/sanitizeFormData.test.ts +14 -13
- package/src/utils/typeGuards.test.ts +2 -1
- package/src/utils/uploadSanityAsset.test.ts +5 -4
- package/src/utils/uploadSanityAsset.ts +17 -16
- package/src/utils/withMaxConcurrency.test.ts +5 -4
- package/src/utils/withMaxConcurrency.ts +4 -4
- package/src/utils/zodFormResolver.ts +17 -0
- package/v2-incompatible.js +2 -2
package/src/hooks/useKeyPress.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import isHotkey from 'is-hotkey'
|
|
1
|
+
import {isHotkey} from 'is-hotkey-esm'
|
|
2
2
|
import {type RefObject, useCallback, useEffect, useRef} from 'react'
|
|
3
3
|
|
|
4
4
|
const useKeyPress = (hotkey: string, onPress?: () => void): RefObject<boolean> => {
|
|
@@ -14,7 +14,7 @@ const useKeyPress = (hotkey: string, onPress?: () => void): RefObject<boolean> =
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
[hotkey, onPress]
|
|
17
|
+
[hotkey, onPress],
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
// If released key is our target key then set to false
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {createAction} from '@reduxjs/toolkit'
|
|
2
|
+
|
|
2
3
|
import type {AssetItem, HttpError, Tag} from '../../types'
|
|
3
4
|
|
|
4
5
|
export const ASSETS_ACTIONS = {
|
|
@@ -6,36 +7,36 @@ export const ASSETS_ACTIONS = {
|
|
|
6
7
|
'actions/tagsAddComplete',
|
|
7
8
|
function prepare({assets, tag}: {assets: AssetItem[]; tag: Tag}) {
|
|
8
9
|
return {payload: {assets, tag}}
|
|
9
|
-
}
|
|
10
|
+
},
|
|
10
11
|
),
|
|
11
12
|
tagsAddError: createAction(
|
|
12
13
|
'actions/tagsAddError',
|
|
13
14
|
function prepare({assets, error, tag}: {assets: AssetItem[]; error: HttpError; tag: Tag}) {
|
|
14
15
|
return {payload: {assets, error, tag}}
|
|
15
|
-
}
|
|
16
|
+
},
|
|
16
17
|
),
|
|
17
18
|
tagsAddRequest: createAction(
|
|
18
19
|
'actions/tagsAddRequest',
|
|
19
20
|
function prepare({assets, tag}: {assets: AssetItem[]; tag: Tag}) {
|
|
20
21
|
return {payload: {assets, tag}}
|
|
21
|
-
}
|
|
22
|
+
},
|
|
22
23
|
),
|
|
23
24
|
tagsRemoveComplete: createAction(
|
|
24
25
|
'actions/tagsRemoveComplete',
|
|
25
26
|
function prepare({assets, tag}: {assets: AssetItem[]; tag: Tag}) {
|
|
26
27
|
return {payload: {assets, tag}}
|
|
27
|
-
}
|
|
28
|
+
},
|
|
28
29
|
),
|
|
29
30
|
tagsRemoveError: createAction(
|
|
30
31
|
'actions/tagsRemoveError',
|
|
31
32
|
function prepare({assets, error, tag}: {assets: AssetItem[]; error: HttpError; tag: Tag}) {
|
|
32
33
|
return {payload: {assets, error, tag}}
|
|
33
|
-
}
|
|
34
|
+
},
|
|
34
35
|
),
|
|
35
36
|
tagsRemoveRequest: createAction(
|
|
36
37
|
'actions/tagsRemoveRequest',
|
|
37
38
|
function prepare({assets, tag}: {assets: AssetItem[]; tag: Tag}) {
|
|
38
39
|
return {payload: {assets, tag}}
|
|
39
|
-
}
|
|
40
|
-
)
|
|
40
|
+
},
|
|
41
|
+
),
|
|
41
42
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
// @vitest-environment node
|
|
2
2
|
|
|
3
|
-
import {describe, expect, it, vi} from 'vitest'
|
|
4
3
|
import {of} from 'rxjs'
|
|
4
|
+
import {describe, expect, it, vi} from 'vitest'
|
|
5
|
+
|
|
6
|
+
import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
|
|
7
|
+
import {createMockSanityClient, mockPatchChain} from '../../__tests__/fixtures/mockSanityClient'
|
|
8
|
+
import type {ImageAsset} from '../../types'
|
|
5
9
|
import {
|
|
6
10
|
assetsActions,
|
|
7
11
|
assetsDeleteEpic,
|
|
8
12
|
assetsUpdateEpic,
|
|
9
|
-
initialState as assetsInitialState
|
|
13
|
+
initialState as assetsInitialState,
|
|
10
14
|
} from './index'
|
|
11
|
-
import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
|
|
12
|
-
import {createMockSanityClient, mockPatchChain} from '../../__tests__/fixtures/mockSanityClient'
|
|
13
|
-
import type {ImageAsset} from '../../types'
|
|
14
15
|
|
|
15
16
|
const sampleAsset = {
|
|
16
17
|
_id: 'a1',
|
|
@@ -21,15 +22,15 @@ const sampleAsset = {
|
|
|
21
22
|
originalFilename: 'x.png',
|
|
22
23
|
size: 1,
|
|
23
24
|
mimeType: 'image/png',
|
|
24
|
-
url: ''
|
|
25
|
+
url: '',
|
|
25
26
|
} as ImageAsset
|
|
26
27
|
|
|
27
28
|
describe('assetsDeleteEpic', () => {
|
|
28
29
|
it('dispatches deleteComplete when observable.delete succeeds', async () => {
|
|
29
30
|
const client = createMockSanityClient({
|
|
30
31
|
observable: {
|
|
31
|
-
delete: vi.fn(() => of({}))
|
|
32
|
-
}
|
|
32
|
+
delete: vi.fn(() => of({})),
|
|
33
|
+
},
|
|
33
34
|
})
|
|
34
35
|
|
|
35
36
|
const store = createEpicTestStore(assetsDeleteEpic, client, {
|
|
@@ -38,9 +39,9 @@ describe('assetsDeleteEpic', () => {
|
|
|
38
39
|
assetTypes: ['image'],
|
|
39
40
|
allIds: ['a1'],
|
|
40
41
|
byIds: {
|
|
41
|
-
a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
42
|
+
a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
44
45
|
})
|
|
45
46
|
|
|
46
47
|
store.dispatch(assetsActions.deleteRequest({assets: [sampleAsset]}))
|
|
@@ -57,7 +58,7 @@ describe('assetsUpdateEpic', () => {
|
|
|
57
58
|
const updated = {...sampleAsset, title: 'Updated'}
|
|
58
59
|
const chain = mockPatchChain(updated)
|
|
59
60
|
const client = createMockSanityClient({
|
|
60
|
-
patch: vi.fn(() => chain)
|
|
61
|
+
patch: vi.fn(() => chain),
|
|
61
62
|
})
|
|
62
63
|
|
|
63
64
|
const store = createEpicTestStore(assetsUpdateEpic, client, {
|
|
@@ -66,16 +67,16 @@ describe('assetsUpdateEpic', () => {
|
|
|
66
67
|
assetTypes: ['image'],
|
|
67
68
|
allIds: ['a1'],
|
|
68
69
|
byIds: {
|
|
69
|
-
a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
70
|
+
a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
72
73
|
})
|
|
73
74
|
|
|
74
75
|
store.dispatch(
|
|
75
76
|
assetsActions.updateRequest({
|
|
76
77
|
asset: sampleAsset,
|
|
77
|
-
formData: {title: 'Updated'}
|
|
78
|
-
})
|
|
78
|
+
formData: {title: 'Updated'},
|
|
79
|
+
}),
|
|
79
80
|
)
|
|
80
81
|
|
|
81
82
|
await vi.waitFor(() => {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// @vitest-environment node
|
|
2
2
|
|
|
3
|
-
import {describe, expect, it, vi} from 'vitest'
|
|
4
3
|
import {of, throwError} from 'rxjs'
|
|
5
|
-
import {
|
|
4
|
+
import {describe, expect, it, vi} from 'vitest'
|
|
5
|
+
|
|
6
6
|
import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
|
|
7
7
|
import {createMockSanityClient} from '../../__tests__/fixtures/mockSanityClient'
|
|
8
8
|
import type {ImageAsset} from '../../types'
|
|
9
|
+
import {assetsActions, assetsFetchEpic} from './index'
|
|
9
10
|
|
|
10
11
|
function assertFetchSucceeded(store: ReturnType<typeof createEpicTestStore>, asset: ImageAsset) {
|
|
11
12
|
expect(store.getState().assets.byIds.a1?.asset).toEqual(asset)
|
|
@@ -25,15 +26,15 @@ const sampleAsset = {
|
|
|
25
26
|
originalFilename: 'x.png',
|
|
26
27
|
size: 1,
|
|
27
28
|
mimeType: 'image/png',
|
|
28
|
-
url: ''
|
|
29
|
+
url: '',
|
|
29
30
|
} as ImageAsset
|
|
30
31
|
|
|
31
32
|
describe('assetsFetchEpic', () => {
|
|
32
33
|
it('dispatches fetchComplete when observable.fetch succeeds', async () => {
|
|
33
34
|
const client = createMockSanityClient({
|
|
34
35
|
observable: {
|
|
35
|
-
fetch: vi.fn(() => of({items: [sampleAsset]}))
|
|
36
|
-
}
|
|
36
|
+
fetch: vi.fn(() => of({items: [sampleAsset]})),
|
|
37
|
+
},
|
|
37
38
|
})
|
|
38
39
|
|
|
39
40
|
const store = createEpicTestStore(assetsFetchEpic, client)
|
|
@@ -42,8 +43,8 @@ describe('assetsFetchEpic', () => {
|
|
|
42
43
|
params: {},
|
|
43
44
|
queryFilter: '_type == "sanity.imageAsset"',
|
|
44
45
|
selector: '',
|
|
45
|
-
sort: ''
|
|
46
|
-
})
|
|
46
|
+
sort: '',
|
|
47
|
+
}),
|
|
47
48
|
)
|
|
48
49
|
|
|
49
50
|
await vi.waitFor(() => assertFetchSucceeded(store, sampleAsset))
|
|
@@ -53,8 +54,8 @@ describe('assetsFetchEpic', () => {
|
|
|
53
54
|
const fetchErr = throwError(() => ({message: 'boom', statusCode: 500}))
|
|
54
55
|
const client = createMockSanityClient({
|
|
55
56
|
observable: {
|
|
56
|
-
fetch: vi.fn(() => fetchErr)
|
|
57
|
-
}
|
|
57
|
+
fetch: vi.fn(() => fetchErr),
|
|
58
|
+
},
|
|
58
59
|
})
|
|
59
60
|
|
|
60
61
|
const store = createEpicTestStore(assetsFetchEpic, client)
|
|
@@ -63,8 +64,8 @@ describe('assetsFetchEpic', () => {
|
|
|
63
64
|
params: {},
|
|
64
65
|
queryFilter: '_type == "sanity.imageAsset"',
|
|
65
66
|
selector: '',
|
|
66
|
-
sort: ''
|
|
67
|
-
})
|
|
67
|
+
sort: '',
|
|
68
|
+
}),
|
|
68
69
|
)
|
|
69
70
|
|
|
70
71
|
await vi.waitFor(() => assertFetchFailed(store))
|