sanity-plugin-media 4.3.1 → 4.3.3
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.mjs → index.cjs} +1115 -1242
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +462 -0
- package/dist/index.d.ts +263 -195
- package/dist/index.js +1125 -1237
- package/dist/index.js.map +1 -1
- package/package.json +45 -68
- 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/dist/index.d.mts +0 -394
- package/dist/index.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,63 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-media",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.3",
|
|
4
4
|
"description": "This version of `sanity-plugin-media` is for Sanity Studio V3.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"asset",
|
|
7
|
+
"browser",
|
|
7
8
|
"cms",
|
|
9
|
+
"content",
|
|
8
10
|
"headless",
|
|
9
11
|
"realtime",
|
|
10
|
-
"
|
|
11
|
-
"sanity-plugin"
|
|
12
|
-
"asset",
|
|
13
|
-
"browser"
|
|
12
|
+
"sanity",
|
|
13
|
+
"sanity-plugin"
|
|
14
14
|
],
|
|
15
|
-
"homepage": "https://github.com/sanity-io/sanity-plugin-media#readme",
|
|
15
|
+
"homepage": "https://github.com/sanity-io/plugins/tree/main/plugins/sanity-plugin-media#readme",
|
|
16
16
|
"bugs": {
|
|
17
|
-
"url": "https://github.com/sanity-io/
|
|
18
|
-
},
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "git@github.com:sanity-io/sanity-plugin-media.git"
|
|
17
|
+
"url": "https://github.com/sanity-io/plugins/issues"
|
|
22
18
|
},
|
|
23
19
|
"license": "MIT",
|
|
24
20
|
"author": "Sanity.io <hello@sanity.io>",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"require": "./dist/index.js",
|
|
30
|
-
"import": "./dist/index.mjs",
|
|
31
|
-
"default": "./dist/index.mjs"
|
|
32
|
-
},
|
|
33
|
-
"./package.json": "./package.json"
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+ssh://git@github.com/sanity-io/plugins.git",
|
|
24
|
+
"directory": "plugins/sanity-plugin-media"
|
|
34
25
|
},
|
|
35
|
-
"main": "./dist/index.js",
|
|
36
|
-
"module": "./dist/index.mjs",
|
|
37
|
-
"types": "./dist/index.d.ts",
|
|
38
26
|
"files": [
|
|
39
27
|
"dist",
|
|
40
28
|
"sanity.json",
|
|
41
29
|
"src",
|
|
42
30
|
"v2-incompatible.js"
|
|
43
31
|
],
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"watch": "pkg-utils watch --strict"
|
|
32
|
+
"type": "module",
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"source": "./src/index.ts",
|
|
38
|
+
"import": "./dist/index.js",
|
|
39
|
+
"require": "./dist/index.cjs",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
56
43
|
},
|
|
57
44
|
"dependencies": {
|
|
58
45
|
"@hookform/resolvers": "^3.1.1",
|
|
59
46
|
"@reduxjs/toolkit": "^2.6.0",
|
|
60
|
-
"@sanity/client": "^7.
|
|
47
|
+
"@sanity/client": "^7.23.0",
|
|
61
48
|
"@sanity/color": "^3.0.6",
|
|
62
49
|
"@sanity/icons": "^3.7.0",
|
|
63
50
|
"@sanity/incompatible-plugin": "^1.0.5",
|
|
@@ -83,43 +70,23 @@
|
|
|
83
70
|
"zod": "^3.21.4"
|
|
84
71
|
},
|
|
85
72
|
"devDependencies": {
|
|
86
|
-
"@
|
|
87
|
-
"@
|
|
88
|
-
"@sanity/pkg-utils": "^7.1.1",
|
|
89
|
-
"@sanity/plugin-kit": "^4.0.19",
|
|
90
|
-
"@sanity/semantic-release-preset": "^2.0.5",
|
|
91
|
-
"@sanity/vision": "^3.80.1",
|
|
73
|
+
"@sanity/pkg-utils": "^10.5.6",
|
|
74
|
+
"@sanity/vision": "^6.1.0",
|
|
92
75
|
"@testing-library/jest-dom": "^6.6.3",
|
|
93
76
|
"@testing-library/react": "^16.2.0",
|
|
94
77
|
"@testing-library/user-event": "^14.6.1",
|
|
95
|
-
"@types/is-hotkey": "^0.1.10",
|
|
96
78
|
"@types/pluralize": "^0.0.33",
|
|
97
|
-
"@types/react": "^19.
|
|
98
|
-
"@types/react-dom": "^19.
|
|
79
|
+
"@types/react": "^19.2.17",
|
|
80
|
+
"@types/react-dom": "^19.2.3",
|
|
99
81
|
"@types/react-file-icon": "^1.0.4",
|
|
100
|
-
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
101
|
-
"@typescript-eslint/parser": "^5.62.0",
|
|
102
|
-
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
103
|
-
"eslint": "^8.57.1",
|
|
104
|
-
"eslint-config-prettier": "^8.10.0",
|
|
105
|
-
"eslint-config-sanity": "^6.0.0",
|
|
106
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
107
|
-
"eslint-plugin-react": "^7.37.4",
|
|
108
|
-
"eslint-plugin-react-hooks": "^4.6.2",
|
|
109
|
-
"husky": "^8.0.2",
|
|
110
82
|
"jsdom": "^25.0.1",
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"prettier-plugin-packagejson": "^2.5.10",
|
|
114
|
-
"react": "^19.0.0",
|
|
115
|
-
"react-dom": "^19.0.0",
|
|
83
|
+
"react": "^19.2.7",
|
|
84
|
+
"react-dom": "^19.2.7",
|
|
116
85
|
"react-is": "^19.0.0",
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"standard-version": "^9.5.0",
|
|
120
|
-
"styled-components": "^6.1.16",
|
|
86
|
+
"sanity": "^6.1.0",
|
|
87
|
+
"styled-components": "^6.4.2",
|
|
121
88
|
"typescript": "5.8.2",
|
|
122
|
-
"
|
|
89
|
+
"@sanity/plugin-kit": "5.0.0"
|
|
123
90
|
},
|
|
124
91
|
"peerDependencies": {
|
|
125
92
|
"react": "^18.3 || ^19",
|
|
@@ -129,6 +96,16 @@
|
|
|
129
96
|
"styled-components": "^6.1"
|
|
130
97
|
},
|
|
131
98
|
"engines": {
|
|
132
|
-
"node": ">=
|
|
99
|
+
"node": ">=20.19 <22 || >=22.12"
|
|
100
|
+
},
|
|
101
|
+
"sanityPlugin": {
|
|
102
|
+
"verifyPackage": {
|
|
103
|
+
"eslintImports": false,
|
|
104
|
+
"scripts": false
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"scripts": {
|
|
108
|
+
"build": "plugin-kit verify-package --silent && pkg-utils build --strict --check --clean",
|
|
109
|
+
"watch": "pkg-utils watch --strict"
|
|
133
110
|
}
|
|
134
|
-
}
|
|
111
|
+
}
|
|
@@ -2,6 +2,7 @@ import {configureStore, type AnyAction, type EnhancedStore} from '@reduxjs/toolk
|
|
|
2
2
|
import type {SanityClient} from '@sanity/client'
|
|
3
3
|
import type {Epic} from 'redux-observable'
|
|
4
4
|
import {createEpicMiddleware} from 'redux-observable'
|
|
5
|
+
|
|
5
6
|
import {rootReducer} from '../../modules'
|
|
6
7
|
import type {RootReducerState} from '../../modules/types'
|
|
7
8
|
import {createTestRootState} from './rootState'
|
|
@@ -9,17 +10,17 @@ import {createTestRootState} from './rootState'
|
|
|
9
10
|
export function createEpicTestStore(
|
|
10
11
|
epic: Epic<AnyAction, AnyAction, RootReducerState, {client: SanityClient}>,
|
|
11
12
|
mockClient: SanityClient,
|
|
12
|
-
preloaded?: Partial<RootReducerState
|
|
13
|
+
preloaded?: Partial<RootReducerState>,
|
|
13
14
|
): EnhancedStore<RootReducerState, AnyAction> {
|
|
14
15
|
const epicMiddleware = createEpicMiddleware<AnyAction, AnyAction, RootReducerState>({
|
|
15
|
-
dependencies: {client: mockClient}
|
|
16
|
+
dependencies: {client: mockClient},
|
|
16
17
|
})
|
|
17
18
|
|
|
18
19
|
const store = configureStore({
|
|
19
20
|
reducer: rootReducer,
|
|
20
|
-
middleware: getDefaultMiddleware =>
|
|
21
|
+
middleware: (getDefaultMiddleware) =>
|
|
21
22
|
getDefaultMiddleware({serializableCheck: false, thunk: false}).concat(epicMiddleware),
|
|
22
|
-
preloadedState: createTestRootState(preloaded)
|
|
23
|
+
preloadedState: createTestRootState(preloaded),
|
|
23
24
|
})
|
|
24
25
|
|
|
25
26
|
epicMiddleware.run(epic)
|
|
@@ -20,7 +20,7 @@ export function createMockSanityClient(
|
|
|
20
20
|
observable?: Partial<MockSanityClient['observable']> & {
|
|
21
21
|
assets?: Partial<MockSanityClient['observable']['assets']>
|
|
22
22
|
}
|
|
23
|
-
} = {}
|
|
23
|
+
} = {},
|
|
24
24
|
): SanityClient {
|
|
25
25
|
const {observable: observableOverrides, ...restOverrides} = overrides
|
|
26
26
|
|
|
@@ -29,8 +29,8 @@ export function createMockSanityClient(
|
|
|
29
29
|
delete: vi.fn(() => of({})),
|
|
30
30
|
create: vi.fn(() => of({_id: 'new'})),
|
|
31
31
|
assets: {
|
|
32
|
-
upload: vi.fn(() => of({type: 'complete', body: {document: {_id: 'up'}}}))
|
|
33
|
-
}
|
|
32
|
+
upload: vi.fn(() => of({type: 'complete', body: {document: {_id: 'up'}}})),
|
|
33
|
+
},
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const observable: MockSanityClient['observable'] = {
|
|
@@ -38,8 +38,8 @@ export function createMockSanityClient(
|
|
|
38
38
|
...(observableOverrides ?? {}),
|
|
39
39
|
assets: {
|
|
40
40
|
...observableBase.assets,
|
|
41
|
-
...(observableOverrides?.assets ?? {})
|
|
42
|
-
}
|
|
41
|
+
...(observableOverrides?.assets ?? {}),
|
|
42
|
+
},
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const client: MockSanityClient = {
|
|
@@ -48,7 +48,7 @@ export function createMockSanityClient(
|
|
|
48
48
|
listen: vi.fn(() => new Subject()),
|
|
49
49
|
patch: vi.fn(),
|
|
50
50
|
transaction: vi.fn(),
|
|
51
|
-
...restOverrides
|
|
51
|
+
...restOverrides,
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
return client as unknown as SanityClient
|
|
@@ -63,7 +63,7 @@ export function mockPatchChain(result: unknown): {
|
|
|
63
63
|
const chain = {
|
|
64
64
|
set: vi.fn(),
|
|
65
65
|
setIfMissing: vi.fn(),
|
|
66
|
-
commit
|
|
66
|
+
commit,
|
|
67
67
|
}
|
|
68
68
|
chain.set.mockImplementation(() => chain)
|
|
69
69
|
chain.setIfMissing.mockImplementation(() => chain)
|
|
@@ -78,7 +78,7 @@ export function mockTransactionCommit(resolved: unknown = undefined): {
|
|
|
78
78
|
const tx = {
|
|
79
79
|
patch: vi.fn().mockReturnThis(),
|
|
80
80
|
delete: vi.fn().mockReturnThis(),
|
|
81
|
-
commit: vi.fn().mockResolvedValue(resolved)
|
|
81
|
+
commit: vi.fn().mockResolvedValue(resolved),
|
|
82
82
|
}
|
|
83
83
|
return tx
|
|
84
84
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import type {ReactElement, ReactNode} from 'react'
|
|
2
1
|
import {configureStore} from '@reduxjs/toolkit'
|
|
3
2
|
import {studioTheme, ThemeProvider, ToastProvider} from '@sanity/ui'
|
|
4
|
-
import {ColorSchemeProvider} from 'sanity'
|
|
5
|
-
import {Provider} from 'react-redux'
|
|
6
3
|
import {render} from '@testing-library/react'
|
|
4
|
+
import type {ReactElement, ReactNode} from 'react'
|
|
5
|
+
import {Provider} from 'react-redux'
|
|
6
|
+
import {ColorSchemeProvider} from 'sanity'
|
|
7
|
+
import type {AssetSourceComponentProps} from 'sanity'
|
|
8
|
+
|
|
7
9
|
import {AssetBrowserDispatchProvider} from '../../contexts/AssetSourceDispatchContext'
|
|
8
10
|
import {ToolOptionsProvider} from '../../contexts/ToolOptionsContext'
|
|
9
11
|
import {rootReducer} from '../../modules'
|
|
10
12
|
import type {RootReducerState} from '../../modules/types'
|
|
11
13
|
import type {MediaToolOptions} from '../../types'
|
|
12
14
|
import {createTestRootState} from './rootState'
|
|
13
|
-
import type {AssetSourceComponentProps} from 'sanity'
|
|
14
15
|
|
|
15
16
|
type Opts = {
|
|
16
17
|
onSelect?: AssetSourceComponentProps['onSelect']
|
|
@@ -23,15 +24,15 @@ export function renderWithProviders(ui: ReactElement, opts: Opts = {}) {
|
|
|
23
24
|
|
|
24
25
|
const store = configureStore({
|
|
25
26
|
reducer: rootReducer,
|
|
26
|
-
middleware: getDefaultMiddleware =>
|
|
27
|
+
middleware: (getDefaultMiddleware) =>
|
|
27
28
|
getDefaultMiddleware({thunk: false, serializableCheck: false}),
|
|
28
|
-
preloadedState: createTestRootState(preloaded)
|
|
29
|
+
preloadedState: createTestRootState(preloaded),
|
|
29
30
|
})
|
|
30
31
|
|
|
31
32
|
const options: MediaToolOptions = {
|
|
32
33
|
creditLine: {enabled: false},
|
|
33
34
|
directUploads: true,
|
|
34
|
-
...toolOptions
|
|
35
|
+
...toolOptions,
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
const wrap = (node: ReactNode) => (
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {RootReducerState} from '../../modules/types'
|
|
2
1
|
import {initialState as assetsInitialState} from '../../modules/assets'
|
|
2
|
+
import type {RootReducerState} from '../../modules/types'
|
|
3
3
|
|
|
4
4
|
export function createTestRootState(overrides: Partial<RootReducerState> = {}): RootReducerState {
|
|
5
5
|
const base: RootReducerState = {
|
|
6
6
|
assets: {
|
|
7
7
|
...assetsInitialState,
|
|
8
|
-
assetTypes: ['file', 'image']
|
|
8
|
+
assetTypes: ['file', 'image'],
|
|
9
9
|
},
|
|
10
10
|
debug: {badConnection: false, enabled: false},
|
|
11
11
|
dialog: {items: []},
|
|
@@ -18,9 +18,9 @@ export function createTestRootState(overrides: Partial<RootReducerState> = {}):
|
|
|
18
18
|
creating: false,
|
|
19
19
|
fetchCount: -1,
|
|
20
20
|
fetching: false,
|
|
21
|
-
panelVisible: true
|
|
21
|
+
panelVisible: true,
|
|
22
22
|
},
|
|
23
|
-
uploads: {allIds: [], byIds: {}}
|
|
23
|
+
uploads: {allIds: [], byIds: {}},
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
return {...base, ...overrides} as RootReducerState
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {CardAssetData, CardUploadData} from '../../types'
|
|
2
1
|
import {memo, forwardRef} from 'react'
|
|
3
2
|
import {VirtuosoGrid} from 'react-virtuoso'
|
|
4
3
|
import {styled} from 'styled-components'
|
|
4
|
+
|
|
5
5
|
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
6
|
+
import type {CardAssetData, CardUploadData} from '../../types'
|
|
6
7
|
import CardAsset from '../CardAsset'
|
|
7
8
|
import CardUpload from '../CardUpload'
|
|
8
9
|
|
|
@@ -25,7 +26,7 @@ const VirtualCell = memo(
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
return null
|
|
28
|
-
}
|
|
29
|
+
},
|
|
29
30
|
)
|
|
30
31
|
|
|
31
32
|
const StyledItemContainer = styled.div`
|
|
@@ -57,9 +58,9 @@ const AssetGridVirtualized = (props: Props) => {
|
|
|
57
58
|
const {items, onLoadMore} = props
|
|
58
59
|
|
|
59
60
|
// Redux
|
|
60
|
-
const selectedAssets = useTypedSelector(state => state.selected.assets)
|
|
61
|
+
const selectedAssets = useTypedSelector((state) => state.selected.assets)
|
|
61
62
|
|
|
62
|
-
const selectedIds = (selectedAssets && selectedAssets.map(asset => asset._id)) || []
|
|
63
|
+
const selectedIds = (selectedAssets && selectedAssets.map((asset) => asset._id)) || []
|
|
63
64
|
const totalCount = items?.length
|
|
64
65
|
|
|
65
66
|
if (totalCount === 0) {
|
|
@@ -69,16 +70,16 @@ const AssetGridVirtualized = (props: Props) => {
|
|
|
69
70
|
return (
|
|
70
71
|
<VirtuosoGrid
|
|
71
72
|
className="media__custom-scrollbar"
|
|
72
|
-
computeItemKey={index => {
|
|
73
|
+
computeItemKey={(index) => {
|
|
73
74
|
const item = items[index]
|
|
74
75
|
return item?.id
|
|
75
76
|
}}
|
|
76
77
|
components={{
|
|
77
78
|
Item: ItemContainer,
|
|
78
|
-
List: ListContainer
|
|
79
|
+
List: ListContainer,
|
|
79
80
|
}}
|
|
80
81
|
endReached={onLoadMore}
|
|
81
|
-
itemContent={index => {
|
|
82
|
+
itemContent={(index) => {
|
|
82
83
|
const item = items[index]
|
|
83
84
|
const selected = selectedIds.includes(item?.id)
|
|
84
85
|
return <VirtualCell item={item} selected={selected} />
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {DownloadIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Button, Flex, Inline, Stack, Text} from '@sanity/ui'
|
|
3
|
-
import
|
|
4
|
-
import { format } from 'date-fns'
|
|
3
|
+
import {format} from 'date-fns'
|
|
5
4
|
import filesize from 'filesize'
|
|
6
5
|
import {type ReactNode} from 'react'
|
|
6
|
+
|
|
7
|
+
import type {Asset, AssetItem} from '../../types'
|
|
7
8
|
import getAssetResolution from '../../utils/getAssetResolution'
|
|
8
9
|
import {isImageAsset} from '../../utils/typeGuards'
|
|
9
10
|
import ButtonAssetCopy from '../ButtonAssetCopy'
|
|
@@ -20,7 +21,7 @@ const Row = ({label, value}: {label: string; value: ReactNode}) => {
|
|
|
20
21
|
size={1}
|
|
21
22
|
style={{
|
|
22
23
|
opacity: 0.8,
|
|
23
|
-
width: '40%'
|
|
24
|
+
width: '40%',
|
|
24
25
|
}}
|
|
25
26
|
textOverflow="ellipsis"
|
|
26
27
|
>
|
|
@@ -31,7 +32,7 @@ const Row = ({label, value}: {label: string; value: ReactNode}) => {
|
|
|
31
32
|
style={{
|
|
32
33
|
opacity: 0.4,
|
|
33
34
|
textAlign: 'right',
|
|
34
|
-
width: '60%'
|
|
35
|
+
width: '60%',
|
|
35
36
|
}}
|
|
36
37
|
textOverflow="ellipsis"
|
|
37
38
|
>
|
|
@@ -76,7 +77,7 @@ const AssetMetadata = (props: Props) => {
|
|
|
76
77
|
style={{
|
|
77
78
|
background: 'var(--card-border-color)',
|
|
78
79
|
height: '1px',
|
|
79
|
-
width: '100%'
|
|
80
|
+
width: '100%',
|
|
80
81
|
}}
|
|
81
82
|
/>
|
|
82
83
|
<Box>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {CardAssetData, CardUploadData} from '../../types'
|
|
2
1
|
import {Box} from '@sanity/ui'
|
|
3
2
|
import {memo} from 'react'
|
|
4
3
|
import {GroupedVirtuoso} from 'react-virtuoso'
|
|
4
|
+
|
|
5
5
|
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
6
|
+
import type {CardAssetData, CardUploadData} from '../../types'
|
|
6
7
|
import TableHeader from '../TableHeader'
|
|
7
8
|
import TableRowAsset from '../TableRowAsset'
|
|
8
9
|
import TableRowUpload from '../TableRowUpload'
|
|
@@ -31,16 +32,16 @@ const VirtualRow = memo(
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
return null
|
|
34
|
-
}
|
|
35
|
+
},
|
|
35
36
|
)
|
|
36
37
|
|
|
37
38
|
const AssetTableVirtualized = (props: Props) => {
|
|
38
39
|
const {items, onLoadMore} = props
|
|
39
40
|
|
|
40
41
|
// Redux
|
|
41
|
-
const selectedAssets = useTypedSelector(state => state.selected.assets)
|
|
42
|
+
const selectedAssets = useTypedSelector((state) => state.selected.assets)
|
|
42
43
|
|
|
43
|
-
const selectedIds = (selectedAssets && selectedAssets.map(asset => asset._id)) || []
|
|
44
|
+
const selectedIds = (selectedAssets && selectedAssets.map((asset) => asset._id)) || []
|
|
44
45
|
const totalCount = items?.length
|
|
45
46
|
|
|
46
47
|
if (totalCount === 0) {
|
|
@@ -50,7 +51,7 @@ const AssetTableVirtualized = (props: Props) => {
|
|
|
50
51
|
return (
|
|
51
52
|
<GroupedVirtuoso
|
|
52
53
|
className="media__custom-scrollbar"
|
|
53
|
-
computeItemKey={index => {
|
|
54
|
+
computeItemKey={(index) => {
|
|
54
55
|
const item = items[index]
|
|
55
56
|
return item?.id || index
|
|
56
57
|
}}
|
|
@@ -59,7 +60,7 @@ const AssetTableVirtualized = (props: Props) => {
|
|
|
59
60
|
groupContent={() => {
|
|
60
61
|
return <TableHeader />
|
|
61
62
|
}}
|
|
62
|
-
itemContent={index => {
|
|
63
|
+
itemContent={(index) => {
|
|
63
64
|
const item = items[index]
|
|
64
65
|
const selected = selectedIds.includes(item?.id)
|
|
65
66
|
return <VirtualRow item={item} selected={selected} />
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {useToast} from '@sanity/ui'
|
|
2
2
|
import {useEffect, useRef} from 'react'
|
|
3
3
|
import {type InputProps} from 'sanity'
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
import {useToolOptions} from '../../contexts/ToolOptionsContext'
|
|
6
6
|
import useVersionedClient from '../../hooks/useVersionedClient'
|
|
7
|
+
import {applyMediaTags} from '../../utils/applyMediaTags'
|
|
7
8
|
|
|
8
9
|
type AssetValue = {
|
|
9
10
|
_type: 'image' | 'file'
|
|
@@ -68,11 +69,15 @@ export function AutoTagInput(props: AutoTagInputProps) {
|
|
|
68
69
|
client,
|
|
69
70
|
assetId: currentAssetRef,
|
|
70
71
|
mediaTags,
|
|
71
|
-
createTagsOnUpload
|
|
72
|
-
}).catch(err => {
|
|
72
|
+
createTagsOnUpload,
|
|
73
|
+
}).catch((err) => {
|
|
73
74
|
console.error('[sanity-plugin-media] Failed to apply auto-tags:', err)
|
|
74
75
|
const label = mediaTags.length === 1 ? 'tag' : 'tags'
|
|
75
|
-
toast.push({
|
|
76
|
+
toast.push({
|
|
77
|
+
closable: true,
|
|
78
|
+
status: 'error',
|
|
79
|
+
title: `Failed to apply the media ${label} ${mediaTags.join(', ')}`,
|
|
80
|
+
})
|
|
76
81
|
})
|
|
77
82
|
}, [currentAssetRef, mediaTags, client, createTagsOnUpload])
|
|
78
83
|
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {describe, expect, it, vi, beforeEach} from 'vitest'
|
|
2
|
-
import {render, screen, waitFor} from '@testing-library/react'
|
|
3
1
|
import {studioTheme, ThemeProvider, ToastProvider} from '@sanity/ui'
|
|
4
|
-
import {
|
|
2
|
+
import {render, screen, waitFor} from '@testing-library/react'
|
|
5
3
|
import {of} from 'rxjs'
|
|
6
|
-
import
|
|
4
|
+
import {ColorSchemeProvider} from 'sanity'
|
|
5
|
+
import {describe, expect, it, vi, beforeEach} from 'vitest'
|
|
6
|
+
|
|
7
7
|
import {createListenMock} from '../../__tests__/fixtures/listenMock'
|
|
8
8
|
import {createMockSanityClient} from '../../__tests__/fixtures/mockSanityClient'
|
|
9
9
|
import {ToolOptionsProvider} from '../../contexts/ToolOptionsContext'
|
|
10
10
|
import useVersionedClient from '../../hooks/useVersionedClient'
|
|
11
|
+
import Browser from './index'
|
|
11
12
|
|
|
12
13
|
vi.mock('../../hooks/useVersionedClient', () => ({
|
|
13
|
-
default: vi.fn()
|
|
14
|
+
default: vi.fn(),
|
|
14
15
|
}))
|
|
15
16
|
|
|
16
17
|
describe('Browser', () => {
|
|
@@ -19,8 +20,8 @@ describe('Browser', () => {
|
|
|
19
20
|
vi.mocked(useVersionedClient).mockReturnValue(
|
|
20
21
|
createMockSanityClient({
|
|
21
22
|
listen: createListenMock(),
|
|
22
|
-
observable: {fetch}
|
|
23
|
-
})
|
|
23
|
+
observable: {fetch},
|
|
24
|
+
}),
|
|
24
25
|
)
|
|
25
26
|
})
|
|
26
27
|
|
|
@@ -34,7 +35,7 @@ describe('Browser', () => {
|
|
|
34
35
|
</ToolOptionsProvider>
|
|
35
36
|
</ToastProvider>
|
|
36
37
|
</ThemeProvider>
|
|
37
|
-
</ColorSchemeProvider
|
|
38
|
+
</ColorSchemeProvider>,
|
|
38
39
|
)
|
|
39
40
|
|
|
40
41
|
await waitFor(() => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {Card, Flex, PortalProvider} from '@sanity/ui'
|
|
2
2
|
import {useState} from 'react'
|
|
3
3
|
import {type AssetSourceComponentProps, type SanityDocument} from 'sanity'
|
|
4
|
+
|
|
4
5
|
import {AssetBrowserDispatchProvider} from '../../contexts/AssetSourceDispatchContext'
|
|
5
6
|
import useVersionedClient from '../../hooks/useVersionedClient'
|
|
6
7
|
import GlobalStyle from '../../styled/GlobalStyles'
|
|
@@ -27,7 +28,7 @@ type Props = {
|
|
|
27
28
|
|
|
28
29
|
const BrowserContent = ({
|
|
29
30
|
onClose,
|
|
30
|
-
schemaType
|
|
31
|
+
schemaType,
|
|
31
32
|
}: {
|
|
32
33
|
onClose?: AssetSourceComponentProps['onClose']
|
|
33
34
|
schemaType?: AssetSourceComponentProps['schemaType']
|
|
@@ -2,22 +2,22 @@ import type {MutationEvent, SanityClient} from '@sanity/client'
|
|
|
2
2
|
import groq from 'groq'
|
|
3
3
|
import {useEffect} from 'react'
|
|
4
4
|
import {useDispatch, useSelector} from 'react-redux'
|
|
5
|
-
import type {AssetSourceComponentProps} from 'sanity'
|
|
6
5
|
import type {Dispatch} from 'redux'
|
|
6
|
+
import type {AssetSourceComponentProps} from 'sanity'
|
|
7
7
|
|
|
8
8
|
import {inputs} from '../../config/searchFacets'
|
|
9
9
|
import {TAG_DOCUMENT_NAME} from '../../constants'
|
|
10
|
+
import {assetsActions} from '../../modules/assets'
|
|
10
11
|
import {searchActions} from '../../modules/search'
|
|
11
12
|
import {tagsActions} from '../../modules/tags'
|
|
12
13
|
import type {RootReducerState} from '../../modules/types'
|
|
13
14
|
import type {Asset, Tag} from '../../types'
|
|
14
|
-
import {assetsActions} from '../../modules/assets'
|
|
15
15
|
|
|
16
16
|
function getMediaTagNames(schemaType?: AssetSourceComponentProps['schemaType']): string[] {
|
|
17
17
|
const mediaTags = (schemaType?.options as {mediaTags?: string[]} | undefined)?.mediaTags
|
|
18
18
|
if (!mediaTags?.length) return []
|
|
19
19
|
const unique = new Set(
|
|
20
|
-
mediaTags.map(t => t?.trim()).filter((t): t is string => Boolean(t?.length))
|
|
20
|
+
mediaTags.map((t) => t?.trim()).filter((t): t is string => Boolean(t?.length)),
|
|
21
21
|
)
|
|
22
22
|
return Array.from(unique)
|
|
23
23
|
}
|
|
@@ -64,7 +64,7 @@ function createTagHandler(dispatch: Dispatch) {
|
|
|
64
64
|
|
|
65
65
|
export function useBrowserInit(
|
|
66
66
|
client: SanityClient,
|
|
67
|
-
schemaType?: AssetSourceComponentProps['schemaType']
|
|
67
|
+
schemaType?: AssetSourceComponentProps['schemaType'],
|
|
68
68
|
): void {
|
|
69
69
|
const dispatch = useDispatch()
|
|
70
70
|
const tagsByIds = useSelector((state: RootReducerState) => state.tags.byIds)
|
|
@@ -82,7 +82,7 @@ export function useBrowserInit(
|
|
|
82
82
|
|
|
83
83
|
const assetSubscription = client
|
|
84
84
|
.listen(
|
|
85
|
-
groq`*[_type in ["sanity.fileAsset", "sanity.imageAsset"] && !(_id in path("drafts.**"))]
|
|
85
|
+
groq`*[_type in ["sanity.fileAsset", "sanity.imageAsset"] && !(_id in path("drafts.**"))]`,
|
|
86
86
|
)
|
|
87
87
|
.subscribe(createAssetHandler(dispatch))
|
|
88
88
|
|
|
@@ -106,7 +106,7 @@ export function useBrowserInit(
|
|
|
106
106
|
if (tagFacetInput.type !== 'searchable') return
|
|
107
107
|
|
|
108
108
|
const resolvedTags = tagNames
|
|
109
|
-
.map(name => Object.values(tagsByIds).find(item => item.tag.name.current === name))
|
|
109
|
+
.map((name) => Object.values(tagsByIds).find((item) => item.tag.name.current === name))
|
|
110
110
|
.filter((item): item is NonNullable<typeof item> => Boolean(item))
|
|
111
111
|
|
|
112
112
|
dispatch(searchActions.facetsClear())
|
|
@@ -117,9 +117,9 @@ export function useBrowserInit(
|
|
|
117
117
|
facet: {
|
|
118
118
|
...tagFacetInput,
|
|
119
119
|
operatorType: 'references',
|
|
120
|
-
value: {label: tagItem.tag.name.current, value: tagItem.tag._id}
|
|
121
|
-
}
|
|
122
|
-
})
|
|
120
|
+
value: {label: tagItem.tag.name.current, value: tagItem.tag._id},
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
123
|
)
|
|
124
124
|
}
|
|
125
125
|
}, [tagsFetchCount, hasMediaTags]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
@@ -2,6 +2,7 @@ import {ClipboardIcon} from '@sanity/icons'
|
|
|
2
2
|
import {Button, Popover, Text} from '@sanity/ui'
|
|
3
3
|
import copy from 'copy-to-clipboard'
|
|
4
4
|
import {useEffect, useRef, useState} from 'react'
|
|
5
|
+
|
|
5
6
|
import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
|
|
6
7
|
|
|
7
8
|
type Props = {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {ThLargeIcon, ThListIcon} from '@sanity/icons'
|
|
2
2
|
import {Button, Inline} from '@sanity/ui'
|
|
3
3
|
import {useDispatch} from 'react-redux'
|
|
4
|
+
|
|
4
5
|
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
5
6
|
import {assetsActions} from '../../modules/assets'
|
|
6
7
|
|
|
7
8
|
const ButtonViewGroup = () => {
|
|
8
9
|
// Redux
|
|
9
10
|
const dispatch = useDispatch()
|
|
10
|
-
const view = useTypedSelector(state => state.assets.view)
|
|
11
|
+
const view = useTypedSelector((state) => state.assets.view)
|
|
11
12
|
|
|
12
13
|
return (
|
|
13
14
|
<Inline space={0} style={{whiteSpace: 'nowrap'}}>
|
|
@@ -18,7 +19,7 @@ const ButtonViewGroup = () => {
|
|
|
18
19
|
onClick={() => dispatch(assetsActions.viewSet({view: 'grid'}))}
|
|
19
20
|
style={{
|
|
20
21
|
borderBottomRightRadius: 0,
|
|
21
|
-
borderTopRightRadius: 0
|
|
22
|
+
borderTopRightRadius: 0,
|
|
22
23
|
}}
|
|
23
24
|
/>
|
|
24
25
|
<Button
|
|
@@ -28,7 +29,7 @@ const ButtonViewGroup = () => {
|
|
|
28
29
|
onClick={() => dispatch(assetsActions.viewSet({view: 'table'}))}
|
|
29
30
|
style={{
|
|
30
31
|
borderBottomLeftRadius: 0,
|
|
31
|
-
borderTopLeftRadius: 0
|
|
32
|
+
borderTopLeftRadius: 0,
|
|
32
33
|
}}
|
|
33
34
|
/>
|
|
34
35
|
</Inline>
|