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
@@ -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
@@ -8,6 +8,6 @@ export function usePortalPopoverProps(): PopoverProps {
8
8
  constrainSize: true,
9
9
  floatingBoundary: portal.element,
10
10
  portal: true,
11
- referenceBoundary: portal.element
11
+ referenceBoundary: portal.element,
12
12
  }
13
13
  }
@@ -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 {assetsActions, assetsFetchEpic} from './index'
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))