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.
- package/LICENSE +4 -4
- package/README.md +12 -12
- package/dist/index.d.mts +263 -195
- package/dist/index.d.ts +263 -195
- package/dist/index.js +83 -203
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -203
- package/dist/index.mjs.map +1 -1
- package/package.json +42 -64
- 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
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {type AnyAction, configureStore, type Store} from '@reduxjs/toolkit'
|
|
2
2
|
import type {SanityClient} from '@sanity/client'
|
|
3
|
-
import type {AssetSourceComponentProps, SanityDocument} from 'sanity'
|
|
4
3
|
import {Component, type ReactNode} from 'react'
|
|
5
4
|
import {Provider} from 'react-redux'
|
|
6
5
|
import {createEpicMiddleware} from 'redux-observable'
|
|
6
|
+
import type {AssetSourceComponentProps, SanityDocument} from 'sanity'
|
|
7
|
+
|
|
7
8
|
import {rootEpic, rootReducer} from '../../modules'
|
|
8
9
|
import {initialState as assetsInitialState} from '../../modules/assets'
|
|
9
10
|
// import {assetsActions} from '../../modules/assets'
|
|
@@ -30,12 +31,12 @@ class ReduxProvider extends Component<Props> {
|
|
|
30
31
|
// Initialize redux store + middleware
|
|
31
32
|
const epicMiddleware = createEpicMiddleware<AnyAction, AnyAction, RootReducerState>({
|
|
32
33
|
dependencies: {
|
|
33
|
-
client: props.client // inject sanity client as a dependency to all epics
|
|
34
|
-
}
|
|
34
|
+
client: props.client, // inject sanity client as a dependency to all epics
|
|
35
|
+
},
|
|
35
36
|
})
|
|
36
37
|
this.store = configureStore({
|
|
37
38
|
reducer: rootReducer,
|
|
38
|
-
middleware: getDefaultMiddleware =>
|
|
39
|
+
middleware: (getDefaultMiddleware) =>
|
|
39
40
|
getDefaultMiddleware({
|
|
40
41
|
/*
|
|
41
42
|
serializableCheck: {
|
|
@@ -48,17 +49,19 @@ class ReduxProvider extends Component<Props> {
|
|
|
48
49
|
*/
|
|
49
50
|
// TODO: remove once we're no longer storing non-serializable data in the store
|
|
50
51
|
serializableCheck: false,
|
|
51
|
-
thunk: false
|
|
52
|
+
thunk: false,
|
|
52
53
|
}).prepend(epicMiddleware),
|
|
53
54
|
devTools: true,
|
|
54
55
|
preloadedState: {
|
|
55
56
|
assets: {
|
|
56
57
|
...assetsInitialState,
|
|
57
|
-
assetTypes: isSupportedAssetType(props?.assetType)
|
|
58
|
+
assetTypes: isSupportedAssetType(props?.assetType)
|
|
59
|
+
? [props.assetType]
|
|
60
|
+
: ['file', 'image'],
|
|
58
61
|
},
|
|
59
62
|
debug: {
|
|
60
63
|
badConnection: false,
|
|
61
|
-
enabled: false
|
|
64
|
+
enabled: false,
|
|
62
65
|
},
|
|
63
66
|
dialog: {items: []},
|
|
64
67
|
notifications: {items: []},
|
|
@@ -66,7 +69,7 @@ class ReduxProvider extends Component<Props> {
|
|
|
66
69
|
selected: {
|
|
67
70
|
assets: props.selectedAssets || [],
|
|
68
71
|
document: props.document,
|
|
69
|
-
documentAssetIds: props.document ? getDocumentAssetIds(props.document) : []
|
|
72
|
+
documentAssetIds: props.document ? getDocumentAssetIds(props.document) : [],
|
|
70
73
|
},
|
|
71
74
|
tags: {
|
|
72
75
|
allIds: [],
|
|
@@ -74,13 +77,13 @@ class ReduxProvider extends Component<Props> {
|
|
|
74
77
|
creating: false,
|
|
75
78
|
fetchCount: -1,
|
|
76
79
|
fetching: false,
|
|
77
|
-
panelVisible: true
|
|
80
|
+
panelVisible: true,
|
|
78
81
|
},
|
|
79
82
|
uploads: {
|
|
80
83
|
allIds: [],
|
|
81
|
-
byIds: {}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
+
byIds: {},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
84
87
|
})
|
|
85
88
|
epicMiddleware.run(rootEpic)
|
|
86
89
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {CloseIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Flex, Label, rem, Text, type ThemeColorSchemeKey} from '@sanity/ui'
|
|
3
|
-
import type {SearchFacetInputProps, WithId} from '../../types'
|
|
4
3
|
import {type ReactNode} from 'react'
|
|
5
4
|
import {useDispatch} from 'react-redux'
|
|
6
5
|
import {useColorSchemeValue} from 'sanity'
|
|
7
6
|
import {styled, css} from 'styled-components'
|
|
7
|
+
|
|
8
8
|
import {searchActions} from '../../modules/search'
|
|
9
|
+
import type {SearchFacetInputProps, WithId} from '../../types'
|
|
9
10
|
import {getSchemeColor} from '../../utils/getSchemeColor'
|
|
10
11
|
|
|
11
12
|
type Props = {
|
|
@@ -40,7 +41,7 @@ const SearchFacet = (props: Props) => {
|
|
|
40
41
|
<Label
|
|
41
42
|
size={0}
|
|
42
43
|
style={{
|
|
43
|
-
whiteSpace: 'nowrap'
|
|
44
|
+
whiteSpace: 'nowrap',
|
|
44
45
|
}}
|
|
45
46
|
>
|
|
46
47
|
{facet.title}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {SelectIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Button, Menu, MenuButton, MenuDivider, MenuItem} from '@sanity/ui'
|
|
3
|
+
import {useDispatch} from 'react-redux'
|
|
4
|
+
|
|
5
|
+
import {operators} from '../../config/searchFacets'
|
|
6
|
+
import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
|
|
7
|
+
import {searchActions} from '../../modules/search'
|
|
3
8
|
import type {
|
|
4
9
|
SearchFacetInputNumberModifier,
|
|
5
10
|
SearchFacetInputNumberProps,
|
|
6
11
|
SearchFacetOperatorType,
|
|
7
|
-
WithId
|
|
12
|
+
WithId,
|
|
8
13
|
} from '../../types'
|
|
9
|
-
|
|
10
|
-
import {useDispatch} from 'react-redux'
|
|
11
|
-
import {operators} from '../../config/searchFacets'
|
|
12
|
-
import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
|
|
13
|
-
import {searchActions} from '../../modules/search'
|
|
14
14
|
import SearchFacet from '../SearchFacet'
|
|
15
15
|
import TextInputNumber from '../TextInputNumber'
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ const SearchFacetNumber = ({facet}: Props) => {
|
|
|
26
26
|
|
|
27
27
|
const modifiers = facet?.modifiers
|
|
28
28
|
const selectedModifier = facet?.modifier
|
|
29
|
-
? modifiers?.find(modifier => modifier.name === facet?.modifier)
|
|
29
|
+
? modifiers?.find((modifier) => modifier.name === facet?.modifier)
|
|
30
30
|
: modifiers?.[0]
|
|
31
31
|
|
|
32
32
|
const handleOperatorItemClick = (operatorType: SearchFacetOperatorType) => {
|
|
@@ -108,7 +108,7 @@ const SearchFacetNumber = ({facet}: Props) => {
|
|
|
108
108
|
id="modifier"
|
|
109
109
|
menu={
|
|
110
110
|
<Menu>
|
|
111
|
-
{modifiers.map(modifier => {
|
|
111
|
+
{modifiers.map((modifier) => {
|
|
112
112
|
const selected = modifier.name === facet.modifier
|
|
113
113
|
return (
|
|
114
114
|
<MenuItem
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import {SelectIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Button, Menu, MenuButton, MenuDivider, MenuItem} from '@sanity/ui'
|
|
3
|
+
import {useDispatch} from 'react-redux'
|
|
4
|
+
|
|
5
|
+
import {operators} from '../../config/searchFacets'
|
|
6
|
+
import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
|
|
7
|
+
import {searchActions} from '../../modules/search'
|
|
3
8
|
import type {
|
|
4
9
|
SearchFacetInputSelectListItemProps,
|
|
5
10
|
SearchFacetInputSelectProps,
|
|
6
11
|
SearchFacetOperatorType,
|
|
7
|
-
WithId
|
|
12
|
+
WithId,
|
|
8
13
|
} from '../../types'
|
|
9
|
-
|
|
10
|
-
import {useDispatch} from 'react-redux'
|
|
11
|
-
|
|
12
|
-
import {operators} from '../../config/searchFacets'
|
|
13
|
-
import {searchActions} from '../../modules/search'
|
|
14
14
|
import SearchFacet from '../SearchFacet'
|
|
15
|
-
import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
|
|
16
15
|
|
|
17
16
|
type Props = {
|
|
18
17
|
facet: WithId<SearchFacetInputSelectProps>
|
|
@@ -26,7 +25,7 @@ const SearchFacetSelect = ({facet}: Props) => {
|
|
|
26
25
|
|
|
27
26
|
const options = facet?.options
|
|
28
27
|
|
|
29
|
-
const selectedItem = options?.find(v => v.name === facet?.value)
|
|
28
|
+
const selectedItem = options?.find((v) => v.name === facet?.value)
|
|
30
29
|
|
|
31
30
|
const handleListItemClick = (option: SearchFacetInputSelectListItemProps) => {
|
|
32
31
|
dispatch(searchActions.facetsUpdate({name: facet.name, value: option.name}))
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {SelectIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Button, Menu, MenuButton, MenuDivider, MenuItem, TextInput} from '@sanity/ui'
|
|
3
|
-
import type {SearchFacetInputStringProps, SearchFacetOperatorType, WithId} from '../../types'
|
|
4
3
|
import {type ChangeEvent} from 'react'
|
|
5
4
|
import {useDispatch} from 'react-redux'
|
|
6
5
|
|
|
7
6
|
import {operators} from '../../config/searchFacets'
|
|
8
7
|
import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
|
|
9
8
|
import {searchActions} from '../../modules/search'
|
|
9
|
+
import type {SearchFacetInputStringProps, SearchFacetOperatorType, WithId} from '../../types'
|
|
10
10
|
import SearchFacet from '../SearchFacet'
|
|
11
11
|
|
|
12
12
|
type Props = {
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import {SelectIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Button, Menu, MenuButton, MenuDivider, MenuItem} from '@sanity/ui'
|
|
3
|
-
import type {
|
|
4
|
-
TagSelectOption,
|
|
5
|
-
SearchFacetInputSearchableProps,
|
|
6
|
-
SearchFacetOperatorType,
|
|
7
|
-
WithId
|
|
8
|
-
} from '../../types'
|
|
9
3
|
import {useDispatch} from 'react-redux'
|
|
10
4
|
import Select from 'react-select'
|
|
11
5
|
import {useColorSchemeValue} from 'sanity'
|
|
6
|
+
|
|
12
7
|
import {operators} from '../../config/searchFacets'
|
|
13
8
|
import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
|
|
14
9
|
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
15
10
|
import {searchActions} from '../../modules/search'
|
|
16
11
|
import {selectTags} from '../../modules/tags'
|
|
17
12
|
import {reactSelectComponents, reactSelectStyles} from '../../styled/react-select/single'
|
|
13
|
+
import type {
|
|
14
|
+
TagSelectOption,
|
|
15
|
+
SearchFacetInputSearchableProps,
|
|
16
|
+
SearchFacetOperatorType,
|
|
17
|
+
WithId,
|
|
18
|
+
} from '../../types'
|
|
18
19
|
import getTagSelectOptions from '../../utils/getTagSelectOptions'
|
|
19
20
|
import SearchFacet from '../SearchFacet'
|
|
20
21
|
|
|
@@ -27,8 +28,8 @@ const SearchFacetTags = ({facet}: Props) => {
|
|
|
27
28
|
|
|
28
29
|
// Redux
|
|
29
30
|
const dispatch = useDispatch()
|
|
30
|
-
const tags = useTypedSelector(state => selectTags(state))
|
|
31
|
-
const tagsFetching = useTypedSelector(state => state.tags.fetching)
|
|
31
|
+
const tags = useTypedSelector((state) => selectTags(state))
|
|
32
|
+
const tagsFetching = useTypedSelector((state) => state.tags.fetching)
|
|
32
33
|
const allTagOptions = getTagSelectOptions(tags)
|
|
33
34
|
|
|
34
35
|
const popoverProps = usePortalPopoverProps()
|
|
@@ -37,8 +38,8 @@ const SearchFacetTags = ({facet}: Props) => {
|
|
|
37
38
|
dispatch(
|
|
38
39
|
searchActions.facetsUpdateById({
|
|
39
40
|
id: facet.id,
|
|
40
|
-
value: option
|
|
41
|
-
})
|
|
41
|
+
value: option,
|
|
42
|
+
}),
|
|
42
43
|
)
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -46,8 +47,8 @@ const SearchFacetTags = ({facet}: Props) => {
|
|
|
46
47
|
dispatch(
|
|
47
48
|
searchActions.facetsUpdateById({
|
|
48
49
|
id: facet.id,
|
|
49
|
-
operatorType
|
|
50
|
-
})
|
|
50
|
+
operatorType,
|
|
51
|
+
}),
|
|
51
52
|
)
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {Box, Flex, Inline, rem, type Theme} from '@sanity/ui'
|
|
2
|
-
|
|
3
2
|
import {styled, css} from 'styled-components'
|
|
4
3
|
|
|
5
4
|
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
@@ -24,9 +23,9 @@ const SearchFacets = (props: Props) => {
|
|
|
24
23
|
const {layout = 'inline'} = props
|
|
25
24
|
|
|
26
25
|
// Redux
|
|
27
|
-
const searchFacets = useTypedSelector(state => state.search.facets)
|
|
26
|
+
const searchFacets = useTypedSelector((state) => state.search.facets)
|
|
28
27
|
|
|
29
|
-
const Items = searchFacets.map(facet => {
|
|
28
|
+
const Items = searchFacets.map((facet) => {
|
|
30
29
|
const key = facet.id
|
|
31
30
|
if (facet.type === 'number') {
|
|
32
31
|
return <SearchFacetNumber facet={facet} key={key} />
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {AddIcon} from '@sanity/icons'
|
|
2
2
|
import {Button, Flex, Menu, MenuButton, MenuDivider, MenuGroup, MenuItem} from '@sanity/ui'
|
|
3
|
-
import type {SearchFacetDivider, SearchFacetGroup, SearchFacetInputProps} from '../../types'
|
|
4
|
-
|
|
5
3
|
import {useDispatch} from 'react-redux'
|
|
4
|
+
|
|
6
5
|
import {FACETS} from '../../constants'
|
|
6
|
+
import {useToolOptions} from '../../contexts/ToolOptionsContext'
|
|
7
7
|
import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
|
|
8
8
|
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
9
9
|
import {searchActions} from '../../modules/search'
|
|
10
|
-
import {
|
|
10
|
+
import type {SearchFacetDivider, SearchFacetGroup, SearchFacetInputProps} from '../../types'
|
|
11
11
|
|
|
12
12
|
const SearchFacetsControl = () => {
|
|
13
13
|
// Redux
|
|
14
14
|
const dispatch = useDispatch()
|
|
15
|
-
const assetTypes = useTypedSelector(state => state.assets.assetTypes)
|
|
16
|
-
const searchFacets = useTypedSelector(state => state.search.facets)
|
|
17
|
-
const selectedDocument = useTypedSelector(state => state.selected.document)
|
|
15
|
+
const assetTypes = useTypedSelector((state) => state.assets.assetTypes)
|
|
16
|
+
const searchFacets = useTypedSelector((state) => state.search.facets)
|
|
17
|
+
const selectedDocument = useTypedSelector((state) => state.selected.document)
|
|
18
18
|
|
|
19
19
|
const popoverProps = usePortalPopoverProps()
|
|
20
20
|
|
|
@@ -24,7 +24,7 @@ const SearchFacetsControl = () => {
|
|
|
24
24
|
|
|
25
25
|
const filteredFacets = FACETS
|
|
26
26
|
// Filter facets based on current context, whether it's invoked as a tool, or via selection through via custom asset source.
|
|
27
|
-
.filter(facet => {
|
|
27
|
+
.filter((facet) => {
|
|
28
28
|
// Remove credit line filter if it's not enabled
|
|
29
29
|
if (!creditLine?.enabled && facet?.type === 'string' && facet?.name === 'creditLine') {
|
|
30
30
|
return false
|
|
@@ -38,8 +38,8 @@ const SearchFacetsControl = () => {
|
|
|
38
38
|
return !facet?.selectOnly
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const matchingAssetTypes = facet.assetTypes.filter(assetType =>
|
|
42
|
-
assetTypes.includes(assetType)
|
|
41
|
+
const matchingAssetTypes = facet.assetTypes.filter((assetType) =>
|
|
42
|
+
assetTypes.includes(assetType),
|
|
43
43
|
)
|
|
44
44
|
return matchingAssetTypes.length > 0
|
|
45
45
|
})
|
|
@@ -61,7 +61,7 @@ const SearchFacetsControl = () => {
|
|
|
61
61
|
|
|
62
62
|
const renderMenuFacets = (
|
|
63
63
|
facets: (SearchFacetDivider | SearchFacetGroup | SearchFacetInputProps)[],
|
|
64
|
-
level: number = 0
|
|
64
|
+
level: number = 0,
|
|
65
65
|
) => {
|
|
66
66
|
return (
|
|
67
67
|
<>
|
|
@@ -80,7 +80,8 @@ const SearchFacetsControl = () => {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
if (facet) {
|
|
83
|
-
const disabled =
|
|
83
|
+
const disabled =
|
|
84
|
+
!facet.operatorTypes && !!searchFacets.find((v) => v.name === facet.name)
|
|
84
85
|
|
|
85
86
|
return (
|
|
86
87
|
<MenuItem
|
|
@@ -119,7 +120,7 @@ const SearchFacetsControl = () => {
|
|
|
119
120
|
menu={<Menu>{renderMenuFacets(filteredFacets)}</Menu>}
|
|
120
121
|
popover={{
|
|
121
122
|
...popoverProps,
|
|
122
|
-
placement: 'right-start'
|
|
123
|
+
placement: 'right-start',
|
|
123
124
|
}}
|
|
124
125
|
/>
|
|
125
126
|
|
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
import {Checkbox, Flex, Grid, type ThemeColorSchemeKey, useMediaIndex} from '@sanity/ui'
|
|
2
2
|
import {type MouseEvent} from 'react'
|
|
3
3
|
import {useDispatch} from 'react-redux'
|
|
4
|
+
import {useColorSchemeValue} from 'sanity'
|
|
4
5
|
import {styled, css} from 'styled-components'
|
|
6
|
+
|
|
5
7
|
import {GRID_TEMPLATE_COLUMNS, PANEL_HEIGHT} from '../../constants'
|
|
6
8
|
import {useAssetSourceActions} from '../../contexts/AssetSourceDispatchContext'
|
|
7
9
|
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
8
10
|
import {assetsActions, selectAssetsLength, selectAssetsPickedLength} from '../../modules/assets'
|
|
9
|
-
import TableHeaderItem from '../TableHeaderItem'
|
|
10
|
-
import {useColorSchemeValue} from 'sanity'
|
|
11
11
|
import {getSchemeColor} from '../../utils/getSchemeColor'
|
|
12
|
+
import TableHeaderItem from '../TableHeaderItem'
|
|
12
13
|
|
|
13
14
|
// TODO: DRY
|
|
14
|
-
const ContextActionContainer = styled<typeof Flex, {$scheme: ThemeColorSchemeKey}>(Flex)(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
15
|
+
const ContextActionContainer = styled<typeof Flex, {$scheme: ThemeColorSchemeKey}>(Flex)(({
|
|
16
|
+
$scheme,
|
|
17
|
+
}) => {
|
|
18
|
+
return css`
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
@media (hover: hover) and (pointer: fine) {
|
|
21
|
+
&:hover {
|
|
22
|
+
background: ${getSchemeColor($scheme, 'bg')};
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
24
|
+
}
|
|
25
|
+
`
|
|
26
|
+
})
|
|
26
27
|
|
|
27
28
|
const TableHeader = () => {
|
|
28
29
|
const scheme = useColorSchemeValue()
|
|
29
30
|
|
|
30
31
|
// Redux
|
|
31
32
|
const dispatch = useDispatch()
|
|
32
|
-
const fetching = useTypedSelector(state => state.assets.fetching)
|
|
33
|
+
const fetching = useTypedSelector((state) => state.assets.fetching)
|
|
33
34
|
const itemsLength = useTypedSelector(selectAssetsLength)
|
|
34
35
|
const numPickedAssets = useTypedSelector(selectAssetsPickedLength)
|
|
35
36
|
|
|
@@ -67,7 +68,7 @@ const TableHeader = () => {
|
|
|
67
68
|
top: 0,
|
|
68
69
|
visibility: mediaIndex < 3 ? 'hidden' : 'visible',
|
|
69
70
|
width: '100%',
|
|
70
|
-
zIndex: 1 // force stacking context
|
|
71
|
+
zIndex: 1, // force stacking context
|
|
71
72
|
}}
|
|
72
73
|
>
|
|
73
74
|
{onSelect ? (
|
|
@@ -80,7 +81,7 @@ const TableHeader = () => {
|
|
|
80
81
|
$scheme={scheme}
|
|
81
82
|
style={{
|
|
82
83
|
height: '100%',
|
|
83
|
-
position: 'relative'
|
|
84
|
+
position: 'relative',
|
|
84
85
|
}}
|
|
85
86
|
>
|
|
86
87
|
<Checkbox
|
|
@@ -88,7 +89,7 @@ const TableHeader = () => {
|
|
|
88
89
|
readOnly
|
|
89
90
|
style={{
|
|
90
91
|
pointerEvents: 'none', // TODO: consider alternative for usability
|
|
91
|
-
transform: 'scale(0.8)'
|
|
92
|
+
transform: 'scale(0.8)',
|
|
92
93
|
}}
|
|
93
94
|
/>
|
|
94
95
|
</ContextActionContainer>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ChevronDownIcon, ChevronUpIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Label} from '@sanity/ui'
|
|
3
|
-
|
|
4
3
|
import {useDispatch} from 'react-redux'
|
|
4
|
+
|
|
5
5
|
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
6
6
|
import {assetsActions} from '../../modules/assets'
|
|
7
7
|
|
|
@@ -15,7 +15,7 @@ const TableHeaderItem = (props: Props) => {
|
|
|
15
15
|
|
|
16
16
|
// Redux
|
|
17
17
|
const dispatch = useDispatch()
|
|
18
|
-
const order = useTypedSelector(state => state.assets.order)
|
|
18
|
+
const order = useTypedSelector((state) => state.assets.order)
|
|
19
19
|
|
|
20
20
|
const isActive = order.field === field
|
|
21
21
|
|
|
@@ -40,12 +40,12 @@ const TableHeaderItem = (props: Props) => {
|
|
|
40
40
|
style={{
|
|
41
41
|
cursor: field ? 'pointer' : 'default',
|
|
42
42
|
display: 'inline',
|
|
43
|
-
whiteSpace: 'nowrap'
|
|
43
|
+
whiteSpace: 'nowrap',
|
|
44
44
|
}}
|
|
45
45
|
>
|
|
46
46
|
<span
|
|
47
47
|
style={{
|
|
48
|
-
marginRight: '0.4em'
|
|
48
|
+
marginRight: '0.4em',
|
|
49
49
|
}}
|
|
50
50
|
>
|
|
51
51
|
{title}
|