sanity-plugin-media 2.4.2 → 3.0.1

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 (50) hide show
  1. package/dist/index.d.mts +7 -4
  2. package/dist/index.d.ts +7 -4
  3. package/dist/index.js +438 -285
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +457 -305
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +39 -33
  8. package/src/components/AssetGridVirtualized/index.tsx +13 -3
  9. package/src/components/Browser/index.tsx +30 -41
  10. package/src/components/ButtonAssetCopy/index.tsx +1 -1
  11. package/src/components/ButtonViewGroup/index.tsx +0 -1
  12. package/src/components/CardAsset/index.tsx +13 -14
  13. package/src/components/CardUpload/index.tsx +1 -1
  14. package/src/components/Controls/index.tsx +0 -1
  15. package/src/components/DebugControls/index.tsx +1 -0
  16. package/src/components/DialogAssetEdit/index.tsx +10 -3
  17. package/src/components/DialogConfirm/index.tsx +8 -1
  18. package/src/components/DialogSearchFacets/index.tsx +1 -1
  19. package/src/components/DialogTagCreate/index.tsx +1 -1
  20. package/src/components/DialogTagEdit/index.tsx +1 -1
  21. package/src/components/DialogTags/index.tsx +1 -1
  22. package/src/components/Dialogs/index.tsx +1 -1
  23. package/src/components/DocumentList/index.tsx +1 -1
  24. package/src/components/FileAssetPreview/index.tsx +1 -1
  25. package/src/components/FormFieldInputLabel/index.tsx +2 -1
  26. package/src/components/FormSubmitButton/index.tsx +1 -0
  27. package/src/components/Header/index.tsx +1 -1
  28. package/src/components/Image/index.tsx +4 -4
  29. package/src/components/OrderSelect/index.tsx +0 -1
  30. package/src/components/Progress/index.tsx +0 -1
  31. package/src/components/ReduxProvider/index.tsx +0 -1
  32. package/src/components/SearchFacet/index.tsx +4 -9
  33. package/src/components/SearchFacetNumber/index.tsx +1 -1
  34. package/src/components/SearchFacetSelect/index.tsx +1 -1
  35. package/src/components/SearchFacetTags/index.tsx +1 -1
  36. package/src/components/SearchFacets/index.tsx +1 -1
  37. package/src/components/SearchFacetsControl/index.tsx +1 -1
  38. package/src/components/TableHeader/index.tsx +4 -6
  39. package/src/components/TableHeaderItem/index.tsx +1 -1
  40. package/src/components/TableRowAsset/index.tsx +38 -46
  41. package/src/components/TableRowUpload/index.tsx +6 -1
  42. package/src/components/Tag/index.tsx +1 -0
  43. package/src/components/TagIcon/index.tsx +0 -2
  44. package/src/components/TagView/index.tsx +1 -1
  45. package/src/components/TagsPanel/index.tsx +1 -1
  46. package/src/components/Tool/index.tsx +1 -1
  47. package/src/hooks/usePortalPopoverProps.ts +1 -0
  48. package/src/plugin.tsx +0 -1
  49. package/src/styled/react-select/creatable.tsx +0 -9
  50. package/src/styled/react-select/single.tsx +0 -8
@@ -6,7 +6,7 @@ import type {
6
6
  SearchFacetOperatorType,
7
7
  WithId
8
8
  } from '../../types'
9
- import React from 'react'
9
+
10
10
  import {useDispatch} from 'react-redux'
11
11
 
12
12
  import {operators} from '../../config/searchFacets'
@@ -105,7 +105,7 @@ const SearchFacetTags = ({facet}: Props) => {
105
105
  isSearchable
106
106
  name="tags"
107
107
  noOptionsMessage={() => 'No tags'}
108
- onChange={value => handleChange(value as TagSelectOption)}
108
+ onChange={(value: any) => handleChange(value as TagSelectOption)}
109
109
  options={allTagOptions}
110
110
  placeholder={tagsFetching ? 'Loading...' : 'Select...'}
111
111
  styles={reactSelectStyles(scheme)}
@@ -1,5 +1,5 @@
1
1
  import {Box, Flex, Inline, rem, type Theme} from '@sanity/ui'
2
- import React from 'react'
2
+
3
3
  import {styled, css} from 'styled-components'
4
4
 
5
5
  import useTypedSelector from '../../hooks/useTypedSelector'
@@ -1,7 +1,7 @@
1
1
  import {AddIcon} from '@sanity/icons'
2
2
  import {Button, Flex, Menu, MenuButton, MenuDivider, MenuGroup, MenuItem} from '@sanity/ui'
3
3
  import type {SearchFacetDivider, SearchFacetGroup, SearchFacetInputProps} from '../../types'
4
- import React from 'react'
4
+
5
5
  import {useDispatch} from 'react-redux'
6
6
  import {FACETS} from '../../constants'
7
7
  import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
@@ -11,14 +11,13 @@ import {useColorSchemeValue} from 'sanity'
11
11
  import {getSchemeColor} from '../../utils/getSchemeColor'
12
12
 
13
13
  // TODO: DRY
14
- const ContextActionContainer = styled(Flex)(
15
- // @ts-expect-error - fix typings later
16
- ({scheme}: {scheme: ThemeColorSchemeKey}) => {
14
+ const ContextActionContainer = styled<typeof Flex, {$scheme: ThemeColorSchemeKey}>(Flex)(
15
+ ({$scheme}) => {
17
16
  return css`
18
17
  cursor: pointer;
19
18
  @media (hover: hover) and (pointer: fine) {
20
19
  &:hover {
21
- background: ${getSchemeColor(scheme, 'bg')};
20
+ background: ${getSchemeColor($scheme, 'bg')};
22
21
  }
23
22
  }
24
23
  `
@@ -78,8 +77,7 @@ const TableHeader = () => {
78
77
  align="center"
79
78
  justify="center"
80
79
  onClick={handleContextActionClick}
81
- // @ts-expect-error - fix typings later
82
- scheme={scheme}
80
+ $scheme={scheme}
83
81
  style={{
84
82
  height: '100%',
85
83
  position: 'relative'
@@ -1,6 +1,6 @@
1
1
  import {ChevronDownIcon, ChevronUpIcon} from '@sanity/icons'
2
2
  import {Box, Label} from '@sanity/ui'
3
- import React from 'react'
3
+
4
4
  import {useDispatch} from 'react-redux'
5
5
  import useTypedSelector from '../../hooks/useTypedSelector'
6
6
  import {assetsActions} from '../../modules/assets'
@@ -47,49 +47,42 @@ type Props = {
47
47
  selected: boolean
48
48
  }
49
49
 
50
- const ContainerGrid = styled(Grid)(
51
- // @ts-expect-error - fix typings later
52
- ({
53
- scheme,
54
- selected,
55
- updating
56
- }: {
57
- selected?: boolean
58
- scheme: ThemeColorSchemeKey
59
- updating?: boolean
60
- }) => {
50
+ const ContainerGrid = styled<
51
+ typeof Grid,
52
+ {$selected?: boolean; $scheme: ThemeColorSchemeKey; $updating?: boolean}
53
+ >(Grid)(({$scheme, $selected, $updating}) => {
54
+ return css`
55
+ align-items: center;
56
+ cursor: ${$selected ? 'default' : 'pointer'};
57
+ height: 100%;
58
+ pointer-events: ${$updating ? 'none' : 'auto'};
59
+ user-select: none;
60
+ white-space: nowrap;
61
+
62
+ ${!$updating &&
63
+ css`
64
+ @media (hover: hover) and (pointer: fine) {
65
+ &:hover {
66
+ background: ${getSchemeColor($scheme, 'bg')};
67
+ }
68
+ }
69
+ `}
70
+ `
71
+ })
72
+
73
+ const ContextActionContainer = styled<typeof Flex, {$scheme: ThemeColorSchemeKey}>(Flex)(
74
+ ({$scheme}) => {
61
75
  return css`
62
- align-items: center;
63
- cursor: ${selected ? 'default' : 'pointer'};
64
- height: 100%;
65
- pointer-events: ${updating ? 'none' : 'auto'};
66
- user-select: none;
67
- white-space: nowrap;
68
-
69
- ${!updating &&
70
- css`
71
- @media (hover: hover) and (pointer: fine) {
72
- &:hover {
73
- background: ${getSchemeColor(scheme, 'bg')};
74
- }
76
+ cursor: pointer;
77
+ @media (hover: hover) and (pointer: fine) {
78
+ &:hover {
79
+ background: ${getSchemeColor($scheme, 'bg2')};
75
80
  }
76
- `}
81
+ }
77
82
  `
78
83
  }
79
84
  )
80
85
 
81
- // @ts-expect-error - fix typings later
82
- const ContextActionContainer = styled(Flex)(({scheme}: {scheme: ThemeColorSchemeKey}) => {
83
- return css`
84
- cursor: pointer;
85
- @media (hover: hover) and (pointer: fine) {
86
- &:hover {
87
- background: ${getSchemeColor(scheme, 'bg2')};
88
- }
89
- }
90
- `
91
- })
92
-
93
86
  const StyledWarningIcon = styled(WarningFilledIcon)(({theme}) => {
94
87
  return {
95
88
  color: theme.sanity.color.spot.red
@@ -105,7 +98,7 @@ const TableRowAsset = (props: Props) => {
105
98
  const shiftPressed: RefObject<boolean> = useKeyPress('shift')
106
99
 
107
100
  const [referenceCountVisible, setReferenceCountVisible] = useState(false)
108
- const refCountVisibleTimeout = useRef<ReturnType<typeof window.setTimeout>>()
101
+ const refCountVisibleTimeout = useRef<ReturnType<typeof window.setTimeout>>(null)
109
102
 
110
103
  const dispatch = useDispatch()
111
104
  const lastPicked = useTypedSelector(state => state.assets.lastPicked)
@@ -181,9 +174,8 @@ const TableRowAsset = (props: Props) => {
181
174
  return (
182
175
  <ContainerGrid
183
176
  onClick={selected ? undefined : handleClick}
184
- // @ts-expect-error - fix typings later
185
- scheme={scheme}
186
- selected={selected}
177
+ $scheme={scheme}
178
+ $selected={selected}
187
179
  style={{
188
180
  gridColumnGap: mediaIndex < 3 ? 0 : '16px',
189
181
  gridRowGap: 0,
@@ -191,13 +183,12 @@ const TableRowAsset = (props: Props) => {
191
183
  mediaIndex < 3 ? GRID_TEMPLATE_COLUMNS.SMALL : GRID_TEMPLATE_COLUMNS.LARGE,
192
184
  gridTemplateRows: mediaIndex < 3 ? 'auto' : '1fr'
193
185
  }}
194
- updating={item.updating}
186
+ $updating={item.updating}
195
187
  >
196
188
  {/* Picked checkbox */}
197
189
  <ContextActionContainer
198
190
  onClick={handleContextActionClick}
199
- // @ts-expect-error - fix typings later
200
- scheme={scheme}
191
+ $scheme={scheme}
201
192
  style={{
202
193
  alignItems: 'center',
203
194
  gridColumn: 1,
@@ -247,8 +238,8 @@ const TableRowAsset = (props: Props) => {
247
238
  {isImageAsset(asset) && (
248
239
  <Image
249
240
  draggable={false}
250
- scheme={scheme}
251
- showCheckerboard={!isOpaque}
241
+ $scheme={scheme}
242
+ $showCheckerboard={!isOpaque}
252
243
  src={imageDprUrl(asset, {height: 100, width: 100})}
253
244
  />
254
245
  )}
@@ -405,6 +396,7 @@ const TableRowAsset = (props: Props) => {
405
396
  {error && (
406
397
  <Box padding={2}>
407
398
  <Tooltip
399
+ animate
408
400
  content={
409
401
  <Container padding={2} width={0}>
410
402
  <Text size={1}>{error}</Text>
@@ -93,7 +93,12 @@ const TableRowUpload = (props: Props) => {
93
93
  >
94
94
  <Box style={{height: '100%', position: 'relative'}}>
95
95
  {item.assetType === 'image' && item?.objectUrl && (
96
- <Image draggable={false} scheme={scheme} src={item.objectUrl} style={{opacity: 0.25}} />
96
+ <Image
97
+ draggable={false}
98
+ $scheme={scheme}
99
+ src={item.objectUrl}
100
+ style={{opacity: 0.25}}
101
+ />
97
102
  )}
98
103
 
99
104
  {item.assetType === 'file' && (
@@ -46,6 +46,7 @@ const TagButton = (props: TagButtonProps) => {
46
46
 
47
47
  return (
48
48
  <Tooltip
49
+ animate
49
50
  content={
50
51
  <Container padding={2} width={0}>
51
52
  <Text muted size={1}>
@@ -1,5 +1,3 @@
1
- import React from 'react'
2
-
3
1
  const TagIcon = () => (
4
2
  <svg
5
3
  data-sanity-icon="media__tag" // For icon usage with @sanity/ui <Button />
@@ -1,5 +1,5 @@
1
1
  import {Box, Flex, Text} from '@sanity/ui'
2
- import React from 'react'
2
+
3
3
  import useTypedSelector from '../../hooks/useTypedSelector'
4
4
  import {selectAssetsPickedLength} from '../../modules/assets'
5
5
  import {selectTags} from '../../modules/tags'
@@ -1,5 +1,5 @@
1
1
  import {Box} from '@sanity/ui'
2
- import React from 'react'
2
+
3
3
  import {TAGS_PANEL_WIDTH} from '../../constants'
4
4
  import useTypedSelector from '../../hooks/useTypedSelector'
5
5
  import TagView from '../TagView'
@@ -1,5 +1,5 @@
1
1
  import {Flex} from '@sanity/ui'
2
- import React from 'react'
2
+
3
3
  import Browser from '../Browser'
4
4
 
5
5
  const Tool = () => {
@@ -4,6 +4,7 @@ export function usePortalPopoverProps(): PopoverProps {
4
4
  const portal = usePortal()
5
5
 
6
6
  return {
7
+ animate: true,
7
8
  constrainSize: true,
8
9
  floatingBoundary: portal.element,
9
10
  portal: true,
package/src/plugin.tsx CHANGED
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import {type AssetSource, type Tool as SanityTool, definePlugin} from 'sanity'
3
2
  import {ImageIcon} from '@sanity/icons'
4
3
  import FormBuilderTool from './components/FormBuilderTool'
@@ -8,7 +8,6 @@ const {radius: themeRadius, space: themeSpace} = studioTheme
8
8
 
9
9
  export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig => {
10
10
  return {
11
- // @ts-expect-error - fix typings later
12
11
  control: (styles, {isFocused}) => {
13
12
  let boxShadow = `inset 0 0 0 1px var(--card-border-color)`
14
13
  if (isFocused) {
@@ -34,12 +33,10 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
34
33
  }
35
34
  }
36
35
  },
37
- // @ts-expect-error - fix typings later
38
36
  indicatorsContainer: (styles, {isDisabled}) => ({
39
37
  ...styles,
40
38
  opacity: isDisabled ? 0.25 : 1
41
39
  }),
42
- // @ts-expect-error - fix typings later
43
40
  input: styles => ({
44
41
  ...styles,
45
42
  color: 'var(--card-fg-color)',
@@ -49,7 +46,6 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
49
46
  menuList: styles => ({
50
47
  ...styles
51
48
  }),
52
- // @ts-expect-error - fix typings later
53
49
  multiValue: (styles, {isDisabled}) => ({
54
50
  ...styles,
55
51
  backgroundColor: getSchemeColor(scheme, 'mutedHoveredBg'),
@@ -61,7 +57,6 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
61
57
  fontSize: 'inherit',
62
58
  padding: 0
63
59
  }),
64
- // @ts-expect-error - fix typings later
65
60
  multiValueRemove: styles => ({
66
61
  ...styles,
67
62
  borderTopLeftRadius: 0,
@@ -71,13 +66,11 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
71
66
  backgroundColor: getSchemeColor(scheme, 'mutedSelectedBg')
72
67
  }
73
68
  }),
74
- // @ts-expect-error - fix typings later
75
69
  noOptionsMessage: styles => ({
76
70
  ...styles,
77
71
  fontFamily: studioTheme.fonts.text.family,
78
72
  lineHeight: '1em'
79
73
  }),
80
- // @ts-expect-error - fix typings later
81
74
  option: (styles, {isFocused}) => ({
82
75
  ...styles,
83
76
  backgroundColor: isFocused ? getSchemeColor(scheme, 'spotBlue') : 'transparent',
@@ -89,12 +82,10 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
89
82
  color: getSchemeColor(scheme, 'bg')
90
83
  }
91
84
  }),
92
- // @ts-expect-error - fix typings later
93
85
  placeholder: styles => ({
94
86
  ...styles,
95
87
  marginLeft: rem(themeSpace[2])
96
88
  }),
97
- // @ts-expect-error - fix typings later
98
89
  valueContainer: styles => ({
99
90
  ...styles,
100
91
  margin: 0,
@@ -14,7 +14,6 @@ const {
14
14
 
15
15
  export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig => {
16
16
  return {
17
- // @ts-expect-error - fix typings later
18
17
  control: (styles, {isDisabled, isFocused}) => {
19
18
  let boxShadow = `inset 0 0 0 1px var(--card-border-color)`
20
19
  if (isFocused) {
@@ -40,7 +39,6 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
40
39
  }
41
40
  }
42
41
  },
43
- // @ts-expect-error - fix typings later
44
42
  input: styles => ({
45
43
  ...styles,
46
44
  color: 'var(--card-fg-color)',
@@ -48,19 +46,16 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
48
46
  fontSize: themeTextSizes[1].fontSize,
49
47
  marginLeft: rem(themeSpace[2])
50
48
  }),
51
- // @ts-expect-error - fix typings later
52
49
  menuList: styles => ({
53
50
  ...styles,
54
51
  padding: 0
55
52
  }),
56
- // @ts-expect-error - fix typings later
57
53
  noOptionsMessage: styles => ({
58
54
  ...styles,
59
55
  fontFamily: studioTheme.fonts.text.family,
60
56
  fontSize: themeTextSizes[1].fontSize,
61
57
  lineHeight: '1em'
62
58
  }),
63
- // @ts-expect-error - fix typings later
64
59
  option: (styles, {isFocused}) => ({
65
60
  ...styles,
66
61
  backgroundColor: isFocused ? getSchemeColor(scheme, 'spotBlue') : 'transparent',
@@ -75,14 +70,12 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
75
70
  color: getSchemeColor(scheme, 'bg')
76
71
  }
77
72
  }),
78
- // @ts-expect-error - fix typings later
79
73
  placeholder: styles => ({
80
74
  ...styles,
81
75
  fontSize: themeTextSizes[1].fontSize,
82
76
  marginLeft: rem(themeSpace[2]),
83
77
  paddingLeft: 0
84
78
  }),
85
- // @ts-expect-error - fix typings later
86
79
  singleValue: styles => ({
87
80
  ...styles,
88
81
  alignItems: 'center',
@@ -90,7 +83,6 @@ export const reactSelectStyles = (scheme: ThemeColorSchemeKey): StylesConfig =>
90
83
  height: '100%',
91
84
  marginLeft: rem(themeSpace[2])
92
85
  }),
93
- // @ts-expect-error - fix typings later
94
86
  valueContainer: styles => ({
95
87
  ...styles,
96
88
  margin: 0,