sanity-plugin-media 4.3.6 → 5.0.0

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 (162) hide show
  1. package/package.json +6 -15
  2. package/dist/index.cjs +0 -4721
  3. package/dist/index.cjs.map +0 -1
  4. package/dist/index.d.cts +0 -239
  5. package/dist/index.d.cts.map +0 -1
  6. package/sanity.json +0 -8
  7. package/src/__tests__/fixtures/createEpicTestStore.ts +0 -28
  8. package/src/__tests__/fixtures/listenMock.ts +0 -9
  9. package/src/__tests__/fixtures/mockSanityClient.ts +0 -84
  10. package/src/__tests__/fixtures/renderWithProviders.tsx +0 -55
  11. package/src/__tests__/fixtures/rootState.ts +0 -27
  12. package/src/__tests__/fixtures/withinDialog.ts +0 -28
  13. package/src/components/AssetGridVirtualized/index.tsx +0 -94
  14. package/src/components/AssetMetadata/index.tsx +0 -122
  15. package/src/components/AssetTableVirtualized/index.tsx +0 -73
  16. package/src/components/AutoTagInputWrapper/index.tsx +0 -85
  17. package/src/components/Browser/Browser.test.tsx +0 -45
  18. package/src/components/Browser/index.tsx +0 -90
  19. package/src/components/Browser/useBrowserInit.ts +0 -126
  20. package/src/components/ButtonAssetCopy/index.tsx +0 -65
  21. package/src/components/ButtonViewGroup/index.tsx +0 -39
  22. package/src/components/CardAsset/CardAsset.test.tsx +0 -323
  23. package/src/components/CardAsset/index.tsx +0 -290
  24. package/src/components/CardUpload/index.tsx +0 -161
  25. package/src/components/Controls/index.tsx +0 -136
  26. package/src/components/DebugControls/index.tsx +0 -80
  27. package/src/components/Dialog/index.tsx +0 -11
  28. package/src/components/DialogAssetEdit/Details.tsx +0 -181
  29. package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +0 -216
  30. package/src/components/DialogAssetEdit/index.tsx +0 -493
  31. package/src/components/DialogConfirm/index.tsx +0 -90
  32. package/src/components/DialogSearchFacets/index.tsx +0 -42
  33. package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
  34. package/src/components/DialogTagCreate/index.tsx +0 -111
  35. package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
  36. package/src/components/DialogTagEdit/index.tsx +0 -201
  37. package/src/components/DialogTags/index.tsx +0 -45
  38. package/src/components/Dialogs/index.tsx +0 -76
  39. package/src/components/DocumentList/index.tsx +0 -62
  40. package/src/components/FileAssetPreview/index.tsx +0 -37
  41. package/src/components/FileIcon/index.tsx +0 -43
  42. package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +0 -63
  43. package/src/components/FormBuilderTool/index.tsx +0 -69
  44. package/src/components/FormFieldInputLabel/index.tsx +0 -66
  45. package/src/components/FormFieldInputTags/index.tsx +0 -98
  46. package/src/components/FormFieldInputText/index.tsx +0 -41
  47. package/src/components/FormFieldInputTextarea/index.tsx +0 -43
  48. package/src/components/FormSubmitButton/index.tsx +0 -59
  49. package/src/components/Header/index.tsx +0 -80
  50. package/src/components/Image/index.tsx +0 -41
  51. package/src/components/Items/index.tsx +0 -68
  52. package/src/components/Notifications/index.tsx +0 -24
  53. package/src/components/OrderSelect/index.tsx +0 -66
  54. package/src/components/PickedBar/index.tsx +0 -77
  55. package/src/components/Progress/index.tsx +0 -38
  56. package/src/components/ReduxProvider/index.tsx +0 -96
  57. package/src/components/SearchFacet/index.tsx +0 -66
  58. package/src/components/SearchFacetNumber/index.tsx +0 -133
  59. package/src/components/SearchFacetSelect/index.tsx +0 -110
  60. package/src/components/SearchFacetString/index.tsx +0 -88
  61. package/src/components/SearchFacetTags/index.tsx +0 -121
  62. package/src/components/SearchFacets/index.tsx +0 -72
  63. package/src/components/SearchFacetsControl/index.tsx +0 -140
  64. package/src/components/TableHeader/index.tsx +0 -110
  65. package/src/components/TableHeaderItem/index.tsx +0 -61
  66. package/src/components/TableRowAsset/index.tsx +0 -419
  67. package/src/components/TableRowUpload/index.tsx +0 -164
  68. package/src/components/Tag/index.tsx +0 -200
  69. package/src/components/TagIcon/index.tsx +0 -22
  70. package/src/components/TagView/index.tsx +0 -39
  71. package/src/components/TagViewHeader/index.tsx +0 -70
  72. package/src/components/TagsPanel/index.tsx +0 -40
  73. package/src/components/TagsVirtualized/index.tsx +0 -160
  74. package/src/components/TextInputNumber/index.tsx +0 -32
  75. package/src/components/TextInputSearch/index.tsx +0 -60
  76. package/src/components/Tool/index.tsx +0 -13
  77. package/src/components/UploadDropzone/UploadDropzone.test.tsx +0 -40
  78. package/src/components/UploadDropzone/index.tsx +0 -173
  79. package/src/config/orders.ts +0 -28
  80. package/src/config/searchFacets.ts +0 -312
  81. package/src/constants.ts +0 -87
  82. package/src/contexts/AssetSourceDispatchContext.tsx +0 -38
  83. package/src/contexts/DropzoneDispatchContext.tsx +0 -32
  84. package/src/contexts/ToolOptionsContext.tsx +0 -66
  85. package/src/formSchema/index.test.ts +0 -56
  86. package/src/formSchema/index.ts +0 -39
  87. package/src/hooks/useBreakpointIndex.ts +0 -50
  88. package/src/hooks/useKeyPress.ts +0 -39
  89. package/src/hooks/usePortalPopoverProps.ts +0 -13
  90. package/src/hooks/useTypedSelector.ts +0 -7
  91. package/src/hooks/useVersionedClient.ts +0 -6
  92. package/src/index.ts +0 -5
  93. package/src/modules/assets/actions.ts +0 -42
  94. package/src/modules/assets/deleteAndUpdateEpics.test.ts +0 -87
  95. package/src/modules/assets/fetchEpic.test.ts +0 -73
  96. package/src/modules/assets/index.ts +0 -782
  97. package/src/modules/assets/reducer.test.ts +0 -91
  98. package/src/modules/assets/tagsAndListenerEpics.test.ts +0 -206
  99. package/src/modules/debug/index.ts +0 -28
  100. package/src/modules/dialog/actions.ts +0 -10
  101. package/src/modules/dialog/epics.test.ts +0 -168
  102. package/src/modules/dialog/index.ts +0 -238
  103. package/src/modules/dialog/reducer.test.ts +0 -185
  104. package/src/modules/index.ts +0 -117
  105. package/src/modules/notifications/epics.test.ts +0 -374
  106. package/src/modules/notifications/index.ts +0 -199
  107. package/src/modules/notifications/reducer.test.ts +0 -54
  108. package/src/modules/search/index.test.ts +0 -36
  109. package/src/modules/search/index.ts +0 -167
  110. package/src/modules/selected/index.ts +0 -22
  111. package/src/modules/selectors.test.ts +0 -21
  112. package/src/modules/selectors.ts +0 -17
  113. package/src/modules/tags/epics.test.ts +0 -96
  114. package/src/modules/tags/index.test.ts +0 -42
  115. package/src/modules/tags/index.ts +0 -540
  116. package/src/modules/types.ts +0 -3
  117. package/src/modules/uploads/actions.ts +0 -13
  118. package/src/modules/uploads/epics.test.ts +0 -109
  119. package/src/modules/uploads/index.test.ts +0 -59
  120. package/src/modules/uploads/index.ts +0 -272
  121. package/src/operators/checkTagName.test.ts +0 -29
  122. package/src/operators/checkTagName.ts +0 -33
  123. package/src/operators/debugThrottle.ts +0 -25
  124. package/src/plugin.tsx +0 -54
  125. package/src/schemas/tag.ts +0 -28
  126. package/src/styled/GlobalStyles/index.tsx +0 -40
  127. package/src/styled/react-select/creatable.tsx +0 -184
  128. package/src/styled/react-select/single.tsx +0 -184
  129. package/src/types/index.ts +0 -346
  130. package/src/types/sanity-ui.d.ts +0 -5
  131. package/src/utils/applyMediaTags.ts +0 -87
  132. package/src/utils/blocksToText.test.ts +0 -43
  133. package/src/utils/blocksToText.ts +0 -27
  134. package/src/utils/constructFilter.test.ts +0 -120
  135. package/src/utils/constructFilter.ts +0 -98
  136. package/src/utils/generatePreviewBlobUrl.test.ts +0 -68
  137. package/src/utils/generatePreviewBlobUrl.ts +0 -53
  138. package/src/utils/getAssetResolution.test.ts +0 -13
  139. package/src/utils/getAssetResolution.ts +0 -7
  140. package/src/utils/getDocumentAssetIds.test.ts +0 -50
  141. package/src/utils/getDocumentAssetIds.ts +0 -35
  142. package/src/utils/getSchemeColor.test.ts +0 -12
  143. package/src/utils/getSchemeColor.ts +0 -43
  144. package/src/utils/getTagSelectOptions.test.ts +0 -44
  145. package/src/utils/getTagSelectOptions.ts +0 -16
  146. package/src/utils/getUniqueDocuments.test.ts +0 -26
  147. package/src/utils/getUniqueDocuments.ts +0 -15
  148. package/src/utils/imageDprUrl.test.ts +0 -46
  149. package/src/utils/imageDprUrl.ts +0 -27
  150. package/src/utils/isSupportedAssetType.test.ts +0 -16
  151. package/src/utils/isSupportedAssetType.ts +0 -15
  152. package/src/utils/mediaField.ts +0 -73
  153. package/src/utils/sanitizeFormData.test.ts +0 -59
  154. package/src/utils/sanitizeFormData.ts +0 -26
  155. package/src/utils/typeGuards.test.ts +0 -18
  156. package/src/utils/typeGuards.ts +0 -9
  157. package/src/utils/uploadSanityAsset.test.ts +0 -29
  158. package/src/utils/uploadSanityAsset.ts +0 -97
  159. package/src/utils/withMaxConcurrency.test.ts +0 -43
  160. package/src/utils/withMaxConcurrency.ts +0 -55
  161. package/src/utils/zodFormResolver.ts +0 -17
  162. package/v2-incompatible.js +0 -11
@@ -1,96 +0,0 @@
1
- import {type AnyAction, configureStore, type Store} from '@reduxjs/toolkit'
2
- import type {SanityClient} from '@sanity/client'
3
- import {Component, type ReactNode} from 'react'
4
- import {Provider} from 'react-redux'
5
- import {createEpicMiddleware} from 'redux-observable'
6
- import type {AssetSourceComponentProps, SanityDocument} from 'sanity'
7
-
8
- import {rootEpic, rootReducer} from '../../modules'
9
- import {initialState as assetsInitialState} from '../../modules/assets'
10
- // import {assetsActions} from '../../modules/assets'
11
- // import {searchActions} from '../../modules/search'
12
- // import {uploadsActions} from '../../modules/uploads'
13
- import type {RootReducerState} from '../../modules/types'
14
- import getDocumentAssetIds from '../../utils/getDocumentAssetIds'
15
- import {isSupportedAssetType} from '../../utils/isSupportedAssetType'
16
-
17
- type Props = {
18
- assetType?: AssetSourceComponentProps['assetType']
19
- children?: ReactNode
20
- client: SanityClient
21
- document?: SanityDocument
22
- selectedAssets?: AssetSourceComponentProps['selectedAssets']
23
- }
24
-
25
- class ReduxProvider extends Component<Props> {
26
- store: Store
27
-
28
- constructor(props: Props) {
29
- super(props)
30
-
31
- // Initialize redux store + middleware
32
- const epicMiddleware = createEpicMiddleware<AnyAction, AnyAction, RootReducerState>({
33
- dependencies: {
34
- client: props.client, // inject sanity client as a dependency to all epics
35
- },
36
- })
37
- this.store = configureStore({
38
- reducer: rootReducer,
39
- middleware: (getDefaultMiddleware) =>
40
- getDefaultMiddleware({
41
- /*
42
- serializableCheck: {
43
- ignoredActions: [
44
- assetsActions.deleteError.type,
45
- uploadsActions.uploadRequest.type,
46
- uploadsActions.uploadStart.type,
47
- ]
48
- },
49
- */
50
- // TODO: remove once we're no longer storing non-serializable data in the store
51
- serializableCheck: false,
52
- thunk: false,
53
- }).prepend(epicMiddleware),
54
- devTools: true,
55
- preloadedState: {
56
- assets: {
57
- ...assetsInitialState,
58
- assetTypes: isSupportedAssetType(props?.assetType)
59
- ? [props.assetType]
60
- : ['file', 'image'],
61
- },
62
- debug: {
63
- badConnection: false,
64
- enabled: false,
65
- },
66
- dialog: {items: []},
67
- notifications: {items: []},
68
- search: {facets: [], query: ''},
69
- selected: {
70
- assets: props.selectedAssets || [],
71
- document: props.document,
72
- documentAssetIds: props.document ? getDocumentAssetIds(props.document) : [],
73
- },
74
- tags: {
75
- allIds: [],
76
- byIds: {},
77
- creating: false,
78
- fetchCount: -1,
79
- fetching: false,
80
- panelVisible: true,
81
- },
82
- uploads: {
83
- allIds: [],
84
- byIds: {},
85
- },
86
- },
87
- })
88
- epicMiddleware.run(rootEpic)
89
- }
90
-
91
- override render() {
92
- return <Provider store={this.store}>{this.props.children}</Provider>
93
- }
94
- }
95
-
96
- export default ReduxProvider
@@ -1,66 +0,0 @@
1
- import {CloseIcon} from '@sanity/icons'
2
- import {Box, Flex, Label, rem, Text, type ThemeColorSchemeKey} from '@sanity/ui'
3
- import {type ReactNode} from 'react'
4
- import {useDispatch} from 'react-redux'
5
- import {useColorSchemeValue} from 'sanity'
6
- import {styled, css} from 'styled-components'
7
-
8
- import {searchActions} from '../../modules/search'
9
- import type {SearchFacetInputProps, WithId} from '../../types'
10
- import {getSchemeColor} from '../../utils/getSchemeColor'
11
-
12
- type Props = {
13
- children: ReactNode
14
- facet: WithId<SearchFacetInputProps>
15
- }
16
-
17
- const Container = styled<typeof Box, {$scheme: ThemeColorSchemeKey}>(Box)(({$scheme, theme}) => {
18
- return css`
19
- background: ${getSchemeColor($scheme, 'bg')};
20
- border-radius: ${rem(theme.sanity.radius[2]!)};
21
- `
22
- })
23
-
24
- const SearchFacet = (props: Props) => {
25
- const {children, facet} = props
26
-
27
- const scheme = useColorSchemeValue()
28
-
29
- // Redux
30
- const dispatch = useDispatch()
31
-
32
- const handleClose = () => {
33
- dispatch(searchActions.facetsRemoveById({facetId: facet.id}))
34
- }
35
-
36
- return (
37
- <Container padding={[2, 2, 1]} $scheme={scheme}>
38
- <Flex align={['flex-start', 'flex-start', 'center']} direction={['column', 'column', 'row']}>
39
- {/* Title */}
40
- <Box paddingBottom={[3, 3, 0]} paddingLeft={1} paddingRight={2} paddingTop={[1, 1, 0]}>
41
- <Label
42
- size={0}
43
- style={{
44
- whiteSpace: 'nowrap',
45
- }}
46
- >
47
- {facet.title}
48
- </Label>
49
- </Box>
50
-
51
- <Flex align="center">
52
- {children}
53
-
54
- {/* Close button */}
55
- <Box marginLeft={1} paddingX={2}>
56
- <Text muted size={0}>
57
- <CloseIcon onClick={handleClose} />
58
- </Text>
59
- </Box>
60
- </Flex>
61
- </Flex>
62
- </Container>
63
- )
64
- }
65
-
66
- export default SearchFacet
@@ -1,133 +0,0 @@
1
- import {SelectIcon} from '@sanity/icons'
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'
8
- import type {
9
- SearchFacetInputNumberModifier,
10
- SearchFacetInputNumberProps,
11
- SearchFacetOperatorType,
12
- WithId,
13
- } from '../../types'
14
- import SearchFacet from '../SearchFacet'
15
- import TextInputNumber from '../TextInputNumber'
16
-
17
- type Props = {
18
- facet: WithId<SearchFacetInputNumberProps>
19
- }
20
-
21
- const SearchFacetNumber = ({facet}: Props) => {
22
- // Redux
23
- const dispatch = useDispatch()
24
-
25
- const popoverProps = usePortalPopoverProps()
26
-
27
- const modifiers = facet?.modifiers
28
- const selectedModifier = facet?.modifier
29
- ? modifiers?.find((modifier) => modifier.name === facet?.modifier)
30
- : modifiers?.[0]
31
-
32
- const handleOperatorItemClick = (operatorType: SearchFacetOperatorType) => {
33
- dispatch(searchActions.facetsUpdateById({id: facet.id, operatorType}))
34
- }
35
-
36
- const handleModifierClick = (modifier: SearchFacetInputNumberModifier) => {
37
- dispatch(searchActions.facetsUpdateById({id: facet.id, modifier: modifier.name}))
38
- }
39
-
40
- const handleValueChange = (value: number) => {
41
- dispatch(searchActions.facetsUpdateById({id: facet.id, value}))
42
- }
43
-
44
- const selectedOperatorType: SearchFacetOperatorType = facet.operatorType ?? 'greaterThan'
45
-
46
- return (
47
- <SearchFacet facet={facet}>
48
- {/* Optional operators */}
49
- {facet?.operatorTypes && (
50
- <MenuButton
51
- button={
52
- <Button
53
- fontSize={1}
54
- iconRight={SelectIcon}
55
- padding={2}
56
- text={operators[selectedOperatorType].label}
57
- />
58
- }
59
- id="operators"
60
- menu={
61
- <Menu>
62
- {facet.operatorTypes.map((operatorType, index) => {
63
- if (operatorType) {
64
- const selected = operatorType === selectedOperatorType
65
- return (
66
- <MenuItem
67
- disabled={selected}
68
- fontSize={1}
69
- key={operatorType}
70
- onClick={() => handleOperatorItemClick(operatorType)}
71
- padding={2}
72
- text={operators[operatorType].label}
73
- />
74
- )
75
- }
76
-
77
- return <MenuDivider key={index} />
78
- })}
79
- </Menu>
80
- }
81
- popover={popoverProps}
82
- />
83
- )}
84
-
85
- {/* Value */}
86
- <Box marginX={1} style={{maxWidth: '50px'}}>
87
- <TextInputNumber
88
- fontSize={1}
89
- onValueChange={handleValueChange}
90
- padding={2}
91
- radius={2}
92
- width={2}
93
- value={facet?.value}
94
- />
95
- </Box>
96
-
97
- {/* Modifiers */}
98
- {modifiers && (
99
- <MenuButton
100
- button={
101
- <Button
102
- fontSize={1}
103
- iconRight={SelectIcon}
104
- padding={2}
105
- text={selectedModifier?.title}
106
- />
107
- }
108
- id="modifier"
109
- menu={
110
- <Menu>
111
- {modifiers.map((modifier) => {
112
- const selected = modifier.name === facet.modifier
113
- return (
114
- <MenuItem
115
- disabled={selected}
116
- fontSize={1}
117
- key={modifier.name}
118
- onClick={() => handleModifierClick(modifier)}
119
- padding={2}
120
- text={modifier.title}
121
- />
122
- )
123
- })}
124
- </Menu>
125
- }
126
- popover={popoverProps}
127
- />
128
- )}
129
- </SearchFacet>
130
- )
131
- }
132
-
133
- export default SearchFacetNumber
@@ -1,110 +0,0 @@
1
- import {SelectIcon} from '@sanity/icons'
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'
8
- import type {
9
- SearchFacetInputSelectListItemProps,
10
- SearchFacetInputSelectProps,
11
- SearchFacetOperatorType,
12
- WithId,
13
- } from '../../types'
14
- import SearchFacet from '../SearchFacet'
15
-
16
- type Props = {
17
- facet: WithId<SearchFacetInputSelectProps>
18
- }
19
-
20
- const SearchFacetSelect = ({facet}: Props) => {
21
- // Redux
22
- const dispatch = useDispatch()
23
-
24
- const popoverProps = usePortalPopoverProps()
25
-
26
- const options = facet?.options
27
-
28
- const selectedItem = options?.find((v) => v.name === facet?.value)
29
-
30
- const handleListItemClick = (option: SearchFacetInputSelectListItemProps) => {
31
- dispatch(searchActions.facetsUpdate({name: facet.name, value: option.name}))
32
- }
33
-
34
- const handleOperatorItemClick = (operatorType: SearchFacetOperatorType) => {
35
- dispatch(searchActions.facetsUpdate({name: facet.name, operatorType}))
36
- }
37
-
38
- const selectedOperatorType: SearchFacetOperatorType = facet?.operatorType ?? 'is'
39
-
40
- return (
41
- <SearchFacet facet={facet}>
42
- {/* Optional operators */}
43
- {facet?.operatorTypes && (
44
- <MenuButton
45
- button={
46
- <Box marginRight={1}>
47
- <Button
48
- fontSize={1}
49
- iconRight={SelectIcon}
50
- padding={2}
51
- text={operators[selectedOperatorType].label}
52
- />
53
- </Box>
54
- }
55
- id="operators"
56
- menu={
57
- <Menu>
58
- {facet.operatorTypes.map((operatorType, index) => {
59
- if (operatorType) {
60
- const selected = operatorType === selectedOperatorType
61
- return (
62
- <MenuItem
63
- disabled={selected}
64
- fontSize={1}
65
- key={operatorType}
66
- onClick={() => handleOperatorItemClick(operatorType)}
67
- padding={2}
68
- text={operators[operatorType].label}
69
- />
70
- )
71
- }
72
-
73
- return <MenuDivider key={index} />
74
- })}
75
- </Menu>
76
- }
77
- popover={popoverProps}
78
- />
79
- )}
80
-
81
- {/* List */}
82
- <MenuButton
83
- button={
84
- <Button fontSize={1} iconRight={SelectIcon} padding={2} text={selectedItem?.title} />
85
- }
86
- id="list"
87
- menu={
88
- <Menu>
89
- {options?.map((item) => {
90
- const selected = item.name === selectedItem?.name
91
- return (
92
- <MenuItem
93
- disabled={selected}
94
- fontSize={1}
95
- key={item.name}
96
- onClick={() => handleListItemClick(item)}
97
- padding={2}
98
- text={item.title}
99
- />
100
- )
101
- })}
102
- </Menu>
103
- }
104
- popover={popoverProps}
105
- />
106
- </SearchFacet>
107
- )
108
- }
109
-
110
- export default SearchFacetSelect
@@ -1,88 +0,0 @@
1
- import {SelectIcon} from '@sanity/icons'
2
- import {Box, Button, Menu, MenuButton, MenuDivider, MenuItem, TextInput} from '@sanity/ui'
3
- import {type ChangeEvent} from 'react'
4
- import {useDispatch} from 'react-redux'
5
-
6
- import {operators} from '../../config/searchFacets'
7
- import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
8
- import {searchActions} from '../../modules/search'
9
- import type {SearchFacetInputStringProps, SearchFacetOperatorType, WithId} from '../../types'
10
- import SearchFacet from '../SearchFacet'
11
-
12
- type Props = {
13
- facet: WithId<SearchFacetInputStringProps>
14
- }
15
-
16
- const SearchFacetString = ({facet}: Props) => {
17
- // Redux
18
- const dispatch = useDispatch()
19
-
20
- const popoverProps = usePortalPopoverProps()
21
-
22
- const handleOperatorItemClick = (operatorType: SearchFacetOperatorType) => {
23
- dispatch(searchActions.facetsUpdateById({id: facet.id, operatorType}))
24
- }
25
-
26
- const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
27
- dispatch(searchActions.facetsUpdateById({id: facet.id, value: e.target.value}))
28
- }
29
-
30
- const selectedOperatorType: SearchFacetOperatorType = facet.operatorType
31
-
32
- return (
33
- <SearchFacet facet={facet}>
34
- {/* Optional operators */}
35
- {facet?.operatorTypes && (
36
- <MenuButton
37
- button={
38
- <Button
39
- fontSize={1}
40
- iconRight={SelectIcon}
41
- padding={2}
42
- text={operators[selectedOperatorType].label}
43
- />
44
- }
45
- id="operators"
46
- menu={
47
- <Menu>
48
- {facet.operatorTypes.map((operatorType, index) => {
49
- if (operatorType) {
50
- const selected = operatorType === selectedOperatorType
51
- return (
52
- <MenuItem
53
- disabled={selected}
54
- fontSize={1}
55
- key={operatorType}
56
- onClick={() => handleOperatorItemClick(operatorType)}
57
- padding={2}
58
- text={operators[operatorType].label}
59
- />
60
- )
61
- }
62
-
63
- return <MenuDivider key={index} />
64
- })}
65
- </Menu>
66
- }
67
- popover={popoverProps}
68
- />
69
- )}
70
-
71
- {/* Value */}
72
- {!operators[selectedOperatorType].hideInput && (
73
- <Box marginLeft={1} style={{maxWidth: '125px'}}>
74
- <TextInput
75
- fontSize={1}
76
- onChange={handleChange}
77
- padding={2}
78
- radius={2}
79
- width={2}
80
- value={facet?.value}
81
- />
82
- </Box>
83
- )}
84
- </SearchFacet>
85
- )
86
- }
87
-
88
- export default SearchFacetString
@@ -1,121 +0,0 @@
1
- import {SelectIcon} from '@sanity/icons'
2
- import {Box, Button, Menu, MenuButton, MenuDivider, MenuItem} from '@sanity/ui'
3
- import {useDispatch} from 'react-redux'
4
- import Select from 'react-select'
5
- import {useColorSchemeValue} from 'sanity'
6
-
7
- import {operators} from '../../config/searchFacets'
8
- import {usePortalPopoverProps} from '../../hooks/usePortalPopoverProps'
9
- import useTypedSelector from '../../hooks/useTypedSelector'
10
- import {searchActions} from '../../modules/search'
11
- import {selectTags} from '../../modules/tags'
12
- import {reactSelectComponents, reactSelectStyles} from '../../styled/react-select/single'
13
- import type {
14
- TagSelectOption,
15
- SearchFacetInputSearchableProps,
16
- SearchFacetOperatorType,
17
- WithId,
18
- } from '../../types'
19
- import getTagSelectOptions from '../../utils/getTagSelectOptions'
20
- import SearchFacet from '../SearchFacet'
21
-
22
- type Props = {
23
- facet: WithId<SearchFacetInputSearchableProps>
24
- }
25
-
26
- const SearchFacetTags = ({facet}: Props) => {
27
- const scheme = useColorSchemeValue()
28
-
29
- // Redux
30
- const dispatch = useDispatch()
31
- const tags = useTypedSelector((state) => selectTags(state))
32
- const tagsFetching = useTypedSelector((state) => state.tags.fetching)
33
- const allTagOptions = getTagSelectOptions(tags)
34
-
35
- const popoverProps = usePortalPopoverProps()
36
-
37
- const handleChange = (option: TagSelectOption) => {
38
- dispatch(
39
- searchActions.facetsUpdateById({
40
- id: facet.id,
41
- value: option,
42
- }),
43
- )
44
- }
45
-
46
- const handleOperatorItemClick = (operatorType: SearchFacetOperatorType) => {
47
- dispatch(
48
- searchActions.facetsUpdateById({
49
- id: facet.id,
50
- operatorType,
51
- }),
52
- )
53
- }
54
-
55
- const selectedOperatorType: SearchFacetOperatorType = facet.operatorType
56
-
57
- return (
58
- <SearchFacet facet={facet}>
59
- {/* Optional operators */}
60
- {facet?.operatorTypes && (
61
- <MenuButton
62
- button={
63
- <Button
64
- fontSize={1}
65
- iconRight={SelectIcon}
66
- padding={2}
67
- text={operators[selectedOperatorType].label}
68
- />
69
- }
70
- id="operators"
71
- menu={
72
- <Menu>
73
- {facet.operatorTypes.map((operatorType, index) => {
74
- if (operatorType) {
75
- const selected = operatorType === selectedOperatorType
76
- return (
77
- <MenuItem
78
- disabled={selected}
79
- fontSize={1}
80
- key={operatorType}
81
- onClick={() => handleOperatorItemClick(operatorType)}
82
- padding={2}
83
- space={4}
84
- style={{minWidth: '150px'}}
85
- text={operators[operatorType].label}
86
- />
87
- )
88
- }
89
-
90
- return <MenuDivider key={index} />
91
- })}
92
- </Menu>
93
- }
94
- popover={popoverProps}
95
- />
96
- )}
97
-
98
- {/* Value */}
99
- {!operators[selectedOperatorType].hideInput && (
100
- <Box marginX={1} style={{width: '160px'}}>
101
- <Select
102
- components={reactSelectComponents}
103
- instanceId="facet-searchable"
104
- isClearable
105
- isDisabled={tagsFetching}
106
- isSearchable
107
- name="tags"
108
- noOptionsMessage={() => 'No tags'}
109
- onChange={(value: any) => handleChange(value as TagSelectOption)}
110
- options={allTagOptions}
111
- placeholder={tagsFetching ? 'Loading...' : 'Select...'}
112
- styles={reactSelectStyles(scheme)}
113
- value={facet?.value}
114
- />
115
- </Box>
116
- )}
117
- </SearchFacet>
118
- )
119
- }
120
-
121
- export default SearchFacetTags
@@ -1,72 +0,0 @@
1
- import {Box, Flex, Inline, rem, type Theme} from '@sanity/ui'
2
- import {styled, css} from 'styled-components'
3
-
4
- import useTypedSelector from '../../hooks/useTypedSelector'
5
- import SearchFacetNumber from '../SearchFacetNumber'
6
- import SearchFacetSelect from '../SearchFacetSelect'
7
- import SearchFacetString from '../SearchFacetString'
8
- import SearchFacetTags from '../SearchFacetTags'
9
-
10
- type Props = {
11
- layout?: 'inline' | 'stack'
12
- }
13
-
14
- const StackContainer = styled(Flex)(({theme}: {theme: Theme}) => {
15
- return css`
16
- > * {
17
- margin-bottom: ${rem(theme.sanity.space[2]!)};
18
- }
19
- `
20
- })
21
-
22
- const SearchFacets = (props: Props) => {
23
- const {layout = 'inline'} = props
24
-
25
- // Redux
26
- const searchFacets = useTypedSelector((state) => state.search.facets)
27
-
28
- const Items = searchFacets.map((facet) => {
29
- const key = facet.id
30
- if (facet.type === 'number') {
31
- return <SearchFacetNumber facet={facet} key={key} />
32
- }
33
-
34
- if (facet.type === 'searchable') {
35
- return <SearchFacetTags facet={facet} key={key} />
36
- }
37
-
38
- if (facet.type === 'select') {
39
- return <SearchFacetSelect facet={facet} key={key} />
40
- }
41
-
42
- if (facet.type === 'string') {
43
- return <SearchFacetString facet={facet} key={key} />
44
- }
45
-
46
- return null
47
- })
48
-
49
- if (layout === 'inline') {
50
- if (searchFacets.length === 0) {
51
- return null
52
- }
53
-
54
- return (
55
- <Box marginBottom={2}>
56
- <Inline space={2}>{Items}</Inline>
57
- </Box>
58
- )
59
- }
60
-
61
- if (layout === 'stack') {
62
- return (
63
- <StackContainer align="flex-start" direction="column">
64
- {Items}
65
- </StackContainer>
66
- )
67
- }
68
-
69
- throw Error('Invalid layout')
70
- }
71
-
72
- export default SearchFacets