sanity-plugin-media 4.3.0 → 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.
Files changed (145) hide show
  1. package/LICENSE +4 -4
  2. package/README.md +12 -12
  3. package/dist/index.d.mts +263 -195
  4. package/dist/index.d.ts +263 -195
  5. package/dist/index.js +83 -203
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +84 -203
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +42 -64
  10. package/src/__tests__/fixtures/createEpicTestStore.ts +5 -4
  11. package/src/__tests__/fixtures/mockSanityClient.ts +8 -8
  12. package/src/__tests__/fixtures/renderWithProviders.tsx +8 -7
  13. package/src/__tests__/fixtures/rootState.ts +4 -4
  14. package/src/components/AssetGridVirtualized/index.tsx +8 -7
  15. package/src/components/AssetMetadata/index.tsx +6 -5
  16. package/src/components/AssetTableVirtualized/index.tsx +7 -6
  17. package/src/components/AutoTagInputWrapper/index.tsx +9 -4
  18. package/src/components/Browser/Browser.test.tsx +9 -8
  19. package/src/components/Browser/index.tsx +2 -1
  20. package/src/components/Browser/useBrowserInit.ts +9 -9
  21. package/src/components/ButtonAssetCopy/index.tsx +1 -0
  22. package/src/components/ButtonViewGroup/index.tsx +4 -3
  23. package/src/components/CardAsset/CardAsset.test.tsx +53 -52
  24. package/src/components/CardAsset/index.tsx +52 -49
  25. package/src/components/CardUpload/index.tsx +7 -6
  26. package/src/components/Controls/index.tsx +7 -6
  27. package/src/components/DebugControls/index.tsx +5 -4
  28. package/src/components/DialogAssetEdit/Details.tsx +3 -2
  29. package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +28 -27
  30. package/src/components/DialogAssetEdit/index.tsx +37 -37
  31. package/src/components/DialogConfirm/index.tsx +2 -1
  32. package/src/components/DialogSearchFacets/index.tsx +3 -2
  33. package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +16 -15
  34. package/src/components/DialogTagCreate/index.tsx +11 -10
  35. package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +28 -27
  36. package/src/components/DialogTagEdit/index.tsx +17 -16
  37. package/src/components/DialogTags/index.tsx +4 -3
  38. package/src/components/Dialogs/index.tsx +2 -3
  39. package/src/components/DocumentList/index.tsx +2 -3
  40. package/src/components/FileAssetPreview/index.tsx +2 -2
  41. package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +12 -11
  42. package/src/components/FormBuilderTool/index.tsx +2 -1
  43. package/src/components/FormFieldInputLabel/index.tsx +1 -2
  44. package/src/components/FormFieldInputTags/index.tsx +4 -3
  45. package/src/components/FormSubmitButton/index.tsx +1 -1
  46. package/src/components/Header/index.tsx +3 -3
  47. package/src/components/Image/index.tsx +10 -4
  48. package/src/components/Items/index.tsx +5 -4
  49. package/src/components/Notifications/index.tsx +3 -2
  50. package/src/components/OrderSelect/index.tsx +4 -3
  51. package/src/components/PickedBar/index.tsx +2 -1
  52. package/src/components/Progress/index.tsx +3 -3
  53. package/src/components/ReduxProvider/index.tsx +15 -12
  54. package/src/components/SearchFacet/index.tsx +3 -2
  55. package/src/components/SearchFacetNumber/index.tsx +8 -8
  56. package/src/components/SearchFacetSelect/index.tsx +7 -8
  57. package/src/components/SearchFacetString/index.tsx +1 -1
  58. package/src/components/SearchFacetTags/index.tsx +13 -12
  59. package/src/components/SearchFacets/index.tsx +2 -3
  60. package/src/components/SearchFacetsControl/index.tsx +13 -12
  61. package/src/components/TableHeader/index.tsx +18 -17
  62. package/src/components/TableHeaderItem/index.tsx +4 -4
  63. package/src/components/TableRowAsset/index.tsx +37 -36
  64. package/src/components/TableRowUpload/index.tsx +7 -6
  65. package/src/components/Tag/index.tsx +8 -7
  66. package/src/components/TagView/index.tsx +2 -2
  67. package/src/components/TagViewHeader/index.tsx +5 -4
  68. package/src/components/TagsPanel/index.tsx +3 -3
  69. package/src/components/TagsVirtualized/index.tsx +25 -24
  70. package/src/components/TextInputSearch/index.tsx +3 -2
  71. package/src/components/UploadDropzone/UploadDropzone.test.tsx +8 -7
  72. package/src/components/UploadDropzone/index.tsx +14 -13
  73. package/src/config/orders.ts +6 -6
  74. package/src/config/searchFacets.ts +56 -55
  75. package/src/constants.ts +15 -14
  76. package/src/contexts/AssetSourceDispatchContext.tsx +1 -1
  77. package/src/contexts/ToolOptionsContext.tsx +6 -5
  78. package/src/formSchema/index.test.ts +6 -5
  79. package/src/formSchema/index.ts +5 -5
  80. package/src/hooks/useBreakpointIndex.ts +6 -6
  81. package/src/hooks/useKeyPress.ts +2 -2
  82. package/src/hooks/usePortalPopoverProps.ts +1 -1
  83. package/src/modules/assets/actions.ts +8 -7
  84. package/src/modules/assets/deleteAndUpdateEpics.test.ts +18 -17
  85. package/src/modules/assets/fetchEpic.test.ts +12 -11
  86. package/src/modules/assets/index.ts +134 -133
  87. package/src/modules/assets/reducer.test.ts +9 -8
  88. package/src/modules/assets/tagsAndListenerEpics.test.ts +36 -35
  89. package/src/modules/debug/index.ts +3 -3
  90. package/src/modules/dialog/actions.ts +2 -2
  91. package/src/modules/dialog/epics.test.ts +29 -28
  92. package/src/modules/dialog/index.ts +36 -35
  93. package/src/modules/dialog/reducer.test.ts +31 -30
  94. package/src/modules/index.ts +9 -9
  95. package/src/modules/notifications/epics.test.ts +71 -70
  96. package/src/modules/notifications/index.ts +50 -49
  97. package/src/modules/notifications/reducer.test.ts +8 -7
  98. package/src/modules/search/index.test.ts +2 -1
  99. package/src/modules/search/index.ts +22 -22
  100. package/src/modules/selected/index.ts +2 -2
  101. package/src/modules/selectors.test.ts +4 -3
  102. package/src/modules/selectors.ts +5 -5
  103. package/src/modules/tags/epics.test.ts +16 -15
  104. package/src/modules/tags/index.test.ts +2 -1
  105. package/src/modules/tags/index.ts +82 -81
  106. package/src/modules/uploads/actions.ts +3 -3
  107. package/src/modules/uploads/epics.test.ts +13 -12
  108. package/src/modules/uploads/index.test.ts +8 -7
  109. package/src/modules/uploads/index.ts +48 -47
  110. package/src/operators/checkTagName.test.ts +7 -6
  111. package/src/operators/checkTagName.ts +6 -5
  112. package/src/operators/debugThrottle.ts +4 -4
  113. package/src/plugin.tsx +18 -18
  114. package/src/schemas/tag.ts +7 -7
  115. package/src/styled/react-select/creatable.tsx +40 -39
  116. package/src/styled/react-select/single.tsx +39 -38
  117. package/src/types/index.ts +4 -3
  118. package/src/utils/applyMediaTags.ts +11 -10
  119. package/src/utils/blocksToText.test.ts +5 -4
  120. package/src/utils/blocksToText.ts +2 -2
  121. package/src/utils/constructFilter.test.ts +15 -14
  122. package/src/utils/constructFilter.ts +7 -7
  123. package/src/utils/generatePreviewBlobUrl.test.ts +6 -5
  124. package/src/utils/generatePreviewBlobUrl.ts +2 -2
  125. package/src/utils/getAssetResolution.test.ts +3 -2
  126. package/src/utils/getDocumentAssetIds.test.ts +7 -6
  127. package/src/utils/getDocumentAssetIds.ts +2 -2
  128. package/src/utils/getSchemeColor.test.ts +1 -0
  129. package/src/utils/getSchemeColor.ts +9 -9
  130. package/src/utils/getTagSelectOptions.test.ts +6 -5
  131. package/src/utils/getTagSelectOptions.ts +1 -1
  132. package/src/utils/getUniqueDocuments.test.ts +4 -3
  133. package/src/utils/getUniqueDocuments.ts +2 -2
  134. package/src/utils/imageDprUrl.test.ts +4 -3
  135. package/src/utils/imageDprUrl.ts +1 -1
  136. package/src/utils/isSupportedAssetType.test.ts +1 -0
  137. package/src/utils/mediaField.ts +4 -3
  138. package/src/utils/sanitizeFormData.test.ts +14 -13
  139. package/src/utils/typeGuards.test.ts +2 -1
  140. package/src/utils/uploadSanityAsset.test.ts +5 -4
  141. package/src/utils/uploadSanityAsset.ts +17 -16
  142. package/src/utils/withMaxConcurrency.test.ts +5 -4
  143. package/src/utils/withMaxConcurrency.ts +4 -4
  144. package/src/utils/zodFormResolver.ts +17 -0
  145. package/v2-incompatible.js +2 -2
package/package.json CHANGED
@@ -1,28 +1,38 @@
1
1
  {
2
2
  "name": "sanity-plugin-media",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
4
4
  "description": "This version of `sanity-plugin-media` is for Sanity Studio V3.",
5
5
  "keywords": [
6
- "sanity",
6
+ "asset",
7
+ "browser",
7
8
  "cms",
9
+ "content",
8
10
  "headless",
9
11
  "realtime",
10
- "content",
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/sanity-plugin-media/issues"
17
+ "url": "https://github.com/sanity-io/plugins/issues"
18
18
  },
19
+ "license": "MIT",
20
+ "author": "Sanity.io <hello@sanity.io>",
19
21
  "repository": {
20
22
  "type": "git",
21
- "url": "git@github.com:sanity-io/sanity-plugin-media.git"
23
+ "url": "git+ssh://git@github.com/sanity-io/plugins.git",
24
+ "directory": "plugins/sanity-plugin-media"
22
25
  },
23
- "license": "MIT",
24
- "author": "Sanity.io <hello@sanity.io>",
26
+ "files": [
27
+ "dist",
28
+ "sanity.json",
29
+ "src",
30
+ "v2-incompatible.js"
31
+ ],
25
32
  "type": "commonjs",
33
+ "main": "./dist/index.js",
34
+ "module": "./dist/index.mjs",
35
+ "types": "./dist/index.d.ts",
26
36
  "exports": {
27
37
  ".": {
28
38
  "source": "./src/index.ts",
@@ -32,32 +42,10 @@
32
42
  },
33
43
  "./package.json": "./package.json"
34
44
  },
35
- "main": "./dist/index.js",
36
- "module": "./dist/index.mjs",
37
- "types": "./dist/index.d.ts",
38
- "files": [
39
- "dist",
40
- "sanity.json",
41
- "src",
42
- "v2-incompatible.js"
43
- ],
44
- "scripts": {
45
- "build": "plugin-kit verify-package --silent && pkg-utils build --strict --check --clean",
46
- "clean": "rimraf dist",
47
- "dev": "sanity dev",
48
- "format": "prettier --write --cache --ignore-unknown .",
49
- "link-watch": "plugin-kit link-watch",
50
- "lint": "eslint .",
51
- "test": "vitest run",
52
- "test:watch": "vitest",
53
- "prepare": "husky install",
54
- "prepublishOnly": "npm run build",
55
- "watch": "pkg-utils watch --strict"
56
- },
57
45
  "dependencies": {
58
46
  "@hookform/resolvers": "^3.1.1",
59
47
  "@reduxjs/toolkit": "^2.6.0",
60
- "@sanity/client": "^7.13.2",
48
+ "@sanity/client": "^7.23.0",
61
49
  "@sanity/color": "^3.0.6",
62
50
  "@sanity/icons": "^3.7.0",
63
51
  "@sanity/incompatible-plugin": "^1.0.5",
@@ -83,52 +71,42 @@
83
71
  "zod": "^3.21.4"
84
72
  },
85
73
  "devDependencies": {
86
- "@commitlint/cli": "^17.8.1",
87
- "@commitlint/config-conventional": "^17.8.1",
88
74
  "@sanity/pkg-utils": "^7.1.1",
89
75
  "@sanity/plugin-kit": "^4.0.19",
90
- "@sanity/semantic-release-preset": "^2.0.5",
91
- "@sanity/vision": "^3.80.1",
76
+ "@sanity/vision": "^6.1.0",
92
77
  "@testing-library/jest-dom": "^6.6.3",
93
78
  "@testing-library/react": "^16.2.0",
94
79
  "@testing-library/user-event": "^14.6.1",
95
- "@types/is-hotkey": "^0.1.10",
96
80
  "@types/pluralize": "^0.0.33",
97
- "@types/react": "^19.0.12",
98
- "@types/react-dom": "^19.0.4",
81
+ "@types/react": "^19.2.17",
82
+ "@types/react-dom": "^19.2.3",
99
83
  "@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
84
  "jsdom": "^25.0.1",
111
- "lint-staged": "^13.0.3",
112
- "prettier": "^2.8.8",
113
- "prettier-plugin-packagejson": "^2.5.10",
114
- "react": "^19.0.0",
115
- "react-dom": "^19.0.0",
85
+ "react": "^19.2.7",
86
+ "react-dom": "^19.2.7",
116
87
  "react-is": "^19.0.0",
117
- "rimraf": "^3.0.2",
118
- "sanity": "^3.80.1",
119
- "standard-version": "^9.5.0",
120
- "styled-components": "^6.1.16",
121
- "typescript": "5.8.2",
122
- "vitest": "^3.0.5"
88
+ "sanity": "^6.1.0",
89
+ "styled-components": "^6.4.2",
90
+ "typescript": "5.8.2"
123
91
  },
124
92
  "peerDependencies": {
125
93
  "react": "^18.3 || ^19",
126
94
  "react-dom": "^18.3 || ^19",
127
95
  "react-is": "^18.3 || ^19",
128
- "sanity": "^3.78 || ^4.0.0-0 || ^5",
96
+ "sanity": "^3.78 || ^4.0.0-0 || ^5 || ^6.0.0-0",
129
97
  "styled-components": "^6.1"
130
98
  },
131
99
  "engines": {
132
100
  "node": ">=18"
101
+ },
102
+ "sanityPlugin": {
103
+ "verifyPackage": {
104
+ "eslintImports": false,
105
+ "scripts": false
106
+ }
107
+ },
108
+ "scripts": {
109
+ "build": "plugin-kit verify-package --silent && pkg-utils build --strict --check --clean",
110
+ "watch": "pkg-utils watch --strict"
133
111
  }
134
- }
112
+ }
@@ -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 type {Asset, AssetItem} from '../../types'
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
- import {applyMediaTags} from '../../utils/applyMediaTags'
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({closable: true, status: 'error', title: `Failed to apply the media ${label} ${mediaTags.join(', ')}`})
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 {ColorSchemeProvider} from 'sanity'
2
+ import {render, screen, waitFor} from '@testing-library/react'
5
3
  import {of} from 'rxjs'
6
- import Browser from './index'
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>