sanity-plugin-media 4.3.5 → 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.
- package/dist/index.d.ts +190 -413
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2532 -3564
- package/dist/index.js.map +1 -1
- package/package.json +29 -35
- package/dist/index.cjs +0 -5753
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -462
- package/sanity.json +0 -8
- package/src/__tests__/fixtures/createEpicTestStore.ts +0 -28
- package/src/__tests__/fixtures/listenMock.ts +0 -9
- package/src/__tests__/fixtures/mockSanityClient.ts +0 -84
- package/src/__tests__/fixtures/renderWithProviders.tsx +0 -55
- package/src/__tests__/fixtures/rootState.ts +0 -27
- package/src/__tests__/fixtures/withinDialog.ts +0 -28
- package/src/components/AssetGridVirtualized/index.tsx +0 -94
- package/src/components/AssetMetadata/index.tsx +0 -122
- package/src/components/AssetTableVirtualized/index.tsx +0 -73
- package/src/components/AutoTagInputWrapper/index.tsx +0 -87
- package/src/components/Browser/Browser.test.tsx +0 -45
- package/src/components/Browser/index.tsx +0 -90
- package/src/components/Browser/useBrowserInit.ts +0 -126
- package/src/components/ButtonAssetCopy/index.tsx +0 -65
- package/src/components/ButtonViewGroup/index.tsx +0 -39
- package/src/components/CardAsset/CardAsset.test.tsx +0 -323
- package/src/components/CardAsset/index.tsx +0 -290
- package/src/components/CardUpload/index.tsx +0 -161
- package/src/components/Controls/index.tsx +0 -136
- package/src/components/DebugControls/index.tsx +0 -80
- package/src/components/Dialog/index.tsx +0 -11
- package/src/components/DialogAssetEdit/Details.tsx +0 -181
- package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +0 -216
- package/src/components/DialogAssetEdit/index.tsx +0 -492
- package/src/components/DialogConfirm/index.tsx +0 -88
- package/src/components/DialogSearchFacets/index.tsx +0 -42
- package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
- package/src/components/DialogTagCreate/index.tsx +0 -103
- package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
- package/src/components/DialogTagEdit/index.tsx +0 -190
- package/src/components/DialogTags/index.tsx +0 -45
- package/src/components/Dialogs/index.tsx +0 -76
- package/src/components/DocumentList/index.tsx +0 -62
- package/src/components/FileAssetPreview/index.tsx +0 -37
- package/src/components/FileIcon/index.tsx +0 -43
- package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +0 -63
- package/src/components/FormBuilderTool/index.tsx +0 -69
- package/src/components/FormFieldInputLabel/index.tsx +0 -66
- package/src/components/FormFieldInputTags/index.tsx +0 -98
- package/src/components/FormFieldInputText/index.tsx +0 -41
- package/src/components/FormFieldInputTextarea/index.tsx +0 -43
- package/src/components/FormSubmitButton/index.tsx +0 -59
- package/src/components/Header/index.tsx +0 -80
- package/src/components/Image/index.tsx +0 -41
- package/src/components/Items/index.tsx +0 -68
- package/src/components/Notifications/index.tsx +0 -24
- package/src/components/OrderSelect/index.tsx +0 -66
- package/src/components/PickedBar/index.tsx +0 -77
- package/src/components/Progress/index.tsx +0 -38
- package/src/components/ReduxProvider/index.tsx +0 -96
- package/src/components/SearchFacet/index.tsx +0 -66
- package/src/components/SearchFacetNumber/index.tsx +0 -133
- package/src/components/SearchFacetSelect/index.tsx +0 -110
- package/src/components/SearchFacetString/index.tsx +0 -88
- package/src/components/SearchFacetTags/index.tsx +0 -121
- package/src/components/SearchFacets/index.tsx +0 -72
- package/src/components/SearchFacetsControl/index.tsx +0 -140
- package/src/components/TableHeader/index.tsx +0 -110
- package/src/components/TableHeaderItem/index.tsx +0 -61
- package/src/components/TableRowAsset/index.tsx +0 -420
- package/src/components/TableRowUpload/index.tsx +0 -164
- package/src/components/Tag/index.tsx +0 -200
- package/src/components/TagIcon/index.tsx +0 -22
- package/src/components/TagView/index.tsx +0 -39
- package/src/components/TagViewHeader/index.tsx +0 -70
- package/src/components/TagsPanel/index.tsx +0 -40
- package/src/components/TagsVirtualized/index.tsx +0 -160
- package/src/components/TextInputNumber/index.tsx +0 -32
- package/src/components/TextInputSearch/index.tsx +0 -60
- package/src/components/Tool/index.tsx +0 -13
- package/src/components/UploadDropzone/UploadDropzone.test.tsx +0 -40
- package/src/components/UploadDropzone/index.tsx +0 -173
- package/src/config/orders.ts +0 -28
- package/src/config/searchFacets.ts +0 -312
- package/src/constants.ts +0 -87
- package/src/contexts/AssetSourceDispatchContext.tsx +0 -37
- package/src/contexts/DropzoneDispatchContext.tsx +0 -34
- package/src/contexts/ToolOptionsContext.tsx +0 -65
- package/src/formSchema/index.test.ts +0 -56
- package/src/formSchema/index.ts +0 -39
- package/src/hooks/useBreakpointIndex.ts +0 -49
- package/src/hooks/useKeyPress.ts +0 -39
- package/src/hooks/useOnScreen.ts +0 -34
- package/src/hooks/usePortalPopoverProps.ts +0 -13
- package/src/hooks/useTypedSelector.ts +0 -7
- package/src/hooks/useVersionedClient.ts +0 -6
- package/src/index.ts +0 -5
- package/src/modules/assets/actions.ts +0 -42
- package/src/modules/assets/deleteAndUpdateEpics.test.ts +0 -87
- package/src/modules/assets/fetchEpic.test.ts +0 -73
- package/src/modules/assets/index.ts +0 -825
- package/src/modules/assets/reducer.test.ts +0 -91
- package/src/modules/assets/tagsAndListenerEpics.test.ts +0 -206
- package/src/modules/debug/index.ts +0 -28
- package/src/modules/dialog/actions.ts +0 -10
- package/src/modules/dialog/epics.test.ts +0 -168
- package/src/modules/dialog/index.ts +0 -238
- package/src/modules/dialog/reducer.test.ts +0 -185
- package/src/modules/index.ts +0 -124
- package/src/modules/notifications/epics.test.ts +0 -374
- package/src/modules/notifications/index.ts +0 -199
- package/src/modules/notifications/reducer.test.ts +0 -54
- package/src/modules/search/index.test.ts +0 -36
- package/src/modules/search/index.ts +0 -167
- package/src/modules/selected/index.ts +0 -22
- package/src/modules/selectors.test.ts +0 -21
- package/src/modules/selectors.ts +0 -17
- package/src/modules/tags/epics.test.ts +0 -96
- package/src/modules/tags/index.test.ts +0 -42
- package/src/modules/tags/index.ts +0 -540
- package/src/modules/types.ts +0 -3
- package/src/modules/uploads/actions.ts +0 -13
- package/src/modules/uploads/epics.test.ts +0 -109
- package/src/modules/uploads/index.test.ts +0 -59
- package/src/modules/uploads/index.ts +0 -282
- package/src/operators/checkTagName.test.ts +0 -29
- package/src/operators/checkTagName.ts +0 -33
- package/src/operators/debugThrottle.ts +0 -25
- package/src/plugin.tsx +0 -54
- package/src/schemas/tag.ts +0 -28
- package/src/styled/GlobalStyles/index.tsx +0 -40
- package/src/styled/react-select/creatable.tsx +0 -184
- package/src/styled/react-select/single.tsx +0 -184
- package/src/types/index.ts +0 -379
- package/src/types/sanity-ui.d.ts +0 -6
- package/src/utils/applyMediaTags.ts +0 -87
- package/src/utils/blocksToText.test.ts +0 -43
- package/src/utils/blocksToText.ts +0 -27
- package/src/utils/constructFilter.test.ts +0 -120
- package/src/utils/constructFilter.ts +0 -98
- package/src/utils/generatePreviewBlobUrl.test.ts +0 -70
- package/src/utils/generatePreviewBlobUrl.ts +0 -53
- package/src/utils/getAssetResolution.test.ts +0 -13
- package/src/utils/getAssetResolution.ts +0 -7
- package/src/utils/getDocumentAssetIds.test.ts +0 -50
- package/src/utils/getDocumentAssetIds.ts +0 -35
- package/src/utils/getSchemeColor.test.ts +0 -12
- package/src/utils/getSchemeColor.ts +0 -43
- package/src/utils/getTagSelectOptions.test.ts +0 -44
- package/src/utils/getTagSelectOptions.ts +0 -16
- package/src/utils/getUniqueDocuments.test.ts +0 -26
- package/src/utils/getUniqueDocuments.ts +0 -15
- package/src/utils/imageDprUrl.test.ts +0 -46
- package/src/utils/imageDprUrl.ts +0 -27
- package/src/utils/isSupportedAssetType.test.ts +0 -16
- package/src/utils/isSupportedAssetType.ts +0 -15
- package/src/utils/mediaField.ts +0 -73
- package/src/utils/sanitizeFormData.test.ts +0 -59
- package/src/utils/sanitizeFormData.ts +0 -26
- package/src/utils/typeGuards.test.ts +0 -18
- package/src/utils/typeGuards.ts +0 -9
- package/src/utils/uploadSanityAsset.test.ts +0 -29
- package/src/utils/uploadSanityAsset.ts +0 -97
- package/src/utils/withMaxConcurrency.test.ts +0 -43
- package/src/utils/withMaxConcurrency.ts +0 -55
- package/src/utils/zodFormResolver.ts +0 -17
- package/v2-incompatible.js +0 -11
package/dist/index.d.cts
DELETED
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
import { AssetSourceComponentProps } from "sanity";
|
|
2
|
-
import type { ComponentType } from "react";
|
|
3
|
-
import { Control } from "react-hook-form";
|
|
4
|
-
import type { FieldDefinitionBase } from "sanity";
|
|
5
|
-
import { FieldErrors } from "react-hook-form";
|
|
6
|
-
import type { FileDefinition } from "sanity";
|
|
7
|
-
import { ForwardRefExoticComponent } from "react";
|
|
8
|
-
import type { ImageDefinition } from "sanity";
|
|
9
|
-
import { InputProps } from "sanity";
|
|
10
|
-
import { JSX } from "react";
|
|
11
|
-
import { Plugin as Plugin_2 } from "sanity";
|
|
12
|
-
import { RefAttributes } from "react";
|
|
13
|
-
import type { SanityAssetDocument } from "@sanity/client";
|
|
14
|
-
import type { SanityImageAssetDocument } from "@sanity/client";
|
|
15
|
-
import { SVGProps } from "react";
|
|
16
|
-
import { UseFormRegister } from "react-hook-form";
|
|
17
|
-
import type { WidenInitialValue } from "sanity";
|
|
18
|
-
import type { WidenValidation } from "sanity";
|
|
19
|
-
import * as z from "zod";
|
|
20
|
-
|
|
21
|
-
declare type Asset = FileAsset | ImageAsset;
|
|
22
|
-
|
|
23
|
-
declare type AssetFormData = z.infer<ReturnType<typeof getAssetFormSchema>>;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Input component that automatically applies media tags when an asset is selected or uploaded.
|
|
27
|
-
*
|
|
28
|
-
* Apply explicitly to image/file fields that should be auto-tagged:
|
|
29
|
-
* ```ts
|
|
30
|
-
* import {AutoTagInput} from 'sanity-plugin-media'
|
|
31
|
-
*
|
|
32
|
-
* defineField({
|
|
33
|
-
* type: 'image',
|
|
34
|
-
* options: { mediaTags: ['product'] }, // also pre-filters the media browser
|
|
35
|
-
* components: { input: AutoTagInput },
|
|
36
|
-
* })
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* Pass `mediaTags` as a prop to override or use without `options`:
|
|
40
|
-
* ```ts
|
|
41
|
-
* components: { input: (props) => <AutoTagInput {...props} mediaTags={['product']} /> }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function AutoTagInput(props: AutoTagInputProps): JSX;
|
|
45
|
-
|
|
46
|
-
export declare type AutoTagInputProps = InputProps & {
|
|
47
|
-
mediaTags?: string[];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
declare type CustomFields = {
|
|
51
|
-
altText?: LocalizedString;
|
|
52
|
-
description?: LocalizedString;
|
|
53
|
-
opt?: {
|
|
54
|
-
media?: {
|
|
55
|
-
tags?: SanityReference[];
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
title?: LocalizedString;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
declare type DetailsProps = {
|
|
62
|
-
formUpdating: boolean;
|
|
63
|
-
handleCreateTag: (title: string) => void;
|
|
64
|
-
control: Control<AssetFormData>;
|
|
65
|
-
errors: FieldErrors<AssetFormData>;
|
|
66
|
-
register: UseFormRegister<AssetFormData>;
|
|
67
|
-
allTagOptions: TagSelectOption[];
|
|
68
|
-
assetTagOptions: TagSelectOption[] | null;
|
|
69
|
-
currentAsset: Asset;
|
|
70
|
-
creditLine?: {
|
|
71
|
-
enabled: boolean;
|
|
72
|
-
excludeSources?: string | string[] | undefined;
|
|
73
|
-
};
|
|
74
|
-
locales?: Locale[];
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
declare type FileAsset = SanityAssetDocument &
|
|
78
|
-
CustomFields & {
|
|
79
|
-
_type: "sanity.fileAsset";
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
declare type FileMediaFieldConfig = Omit<FileDefinition, "options"> &
|
|
83
|
-
FieldDefinitionBase & {
|
|
84
|
-
name: string;
|
|
85
|
-
mediaTags: string[];
|
|
86
|
-
options?: FileDefinition["options"];
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
declare type FileMediaFieldResult = Omit<FileDefinition, "options"> &
|
|
90
|
-
FieldDefinitionBase & {
|
|
91
|
-
options?: FileDefinition["options"] & {
|
|
92
|
-
mediaTags: string[];
|
|
93
|
-
};
|
|
94
|
-
components: {
|
|
95
|
-
input: typeof AutoTagInput;
|
|
96
|
-
};
|
|
97
|
-
} & WidenValidation &
|
|
98
|
-
WidenInitialValue;
|
|
99
|
-
|
|
100
|
-
declare function getAssetFormSchema(
|
|
101
|
-
locales?: {
|
|
102
|
-
id: string;
|
|
103
|
-
}[],
|
|
104
|
-
): z.ZodObject<
|
|
105
|
-
{
|
|
106
|
-
altText:
|
|
107
|
-
| z.ZodOptional<z.ZodString>
|
|
108
|
-
| z.ZodObject<
|
|
109
|
-
Record<string, z.ZodTypeAny>,
|
|
110
|
-
"passthrough",
|
|
111
|
-
z.ZodTypeAny,
|
|
112
|
-
z.objectOutputType<
|
|
113
|
-
Record<string, z.ZodTypeAny>,
|
|
114
|
-
z.ZodTypeAny,
|
|
115
|
-
"passthrough"
|
|
116
|
-
>,
|
|
117
|
-
z.objectInputType<
|
|
118
|
-
Record<string, z.ZodTypeAny>,
|
|
119
|
-
z.ZodTypeAny,
|
|
120
|
-
"passthrough"
|
|
121
|
-
>
|
|
122
|
-
>;
|
|
123
|
-
creditLine:
|
|
124
|
-
| z.ZodOptional<z.ZodString>
|
|
125
|
-
| z.ZodObject<
|
|
126
|
-
Record<string, z.ZodTypeAny>,
|
|
127
|
-
"passthrough",
|
|
128
|
-
z.ZodTypeAny,
|
|
129
|
-
z.objectOutputType<
|
|
130
|
-
Record<string, z.ZodTypeAny>,
|
|
131
|
-
z.ZodTypeAny,
|
|
132
|
-
"passthrough"
|
|
133
|
-
>,
|
|
134
|
-
z.objectInputType<
|
|
135
|
-
Record<string, z.ZodTypeAny>,
|
|
136
|
-
z.ZodTypeAny,
|
|
137
|
-
"passthrough"
|
|
138
|
-
>
|
|
139
|
-
>;
|
|
140
|
-
description:
|
|
141
|
-
| z.ZodOptional<z.ZodString>
|
|
142
|
-
| z.ZodObject<
|
|
143
|
-
Record<string, z.ZodTypeAny>,
|
|
144
|
-
"passthrough",
|
|
145
|
-
z.ZodTypeAny,
|
|
146
|
-
z.objectOutputType<
|
|
147
|
-
Record<string, z.ZodTypeAny>,
|
|
148
|
-
z.ZodTypeAny,
|
|
149
|
-
"passthrough"
|
|
150
|
-
>,
|
|
151
|
-
z.objectInputType<
|
|
152
|
-
Record<string, z.ZodTypeAny>,
|
|
153
|
-
z.ZodTypeAny,
|
|
154
|
-
"passthrough"
|
|
155
|
-
>
|
|
156
|
-
>;
|
|
157
|
-
opt: z.ZodObject<
|
|
158
|
-
{
|
|
159
|
-
media: z.ZodObject<
|
|
160
|
-
{
|
|
161
|
-
tags: z.ZodNullable<
|
|
162
|
-
z.ZodArray<
|
|
163
|
-
z.ZodObject<
|
|
164
|
-
{
|
|
165
|
-
label: z.ZodString;
|
|
166
|
-
value: z.ZodString;
|
|
167
|
-
},
|
|
168
|
-
"strip",
|
|
169
|
-
z.ZodTypeAny,
|
|
170
|
-
{
|
|
171
|
-
value: string;
|
|
172
|
-
label: string;
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
value: string;
|
|
176
|
-
label: string;
|
|
177
|
-
}
|
|
178
|
-
>,
|
|
179
|
-
"many"
|
|
180
|
-
>
|
|
181
|
-
>;
|
|
182
|
-
},
|
|
183
|
-
"strip",
|
|
184
|
-
z.ZodTypeAny,
|
|
185
|
-
{
|
|
186
|
-
tags:
|
|
187
|
-
| {
|
|
188
|
-
value: string;
|
|
189
|
-
label: string;
|
|
190
|
-
}[]
|
|
191
|
-
| null;
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
tags:
|
|
195
|
-
| {
|
|
196
|
-
value: string;
|
|
197
|
-
label: string;
|
|
198
|
-
}[]
|
|
199
|
-
| null;
|
|
200
|
-
}
|
|
201
|
-
>;
|
|
202
|
-
},
|
|
203
|
-
"strip",
|
|
204
|
-
z.ZodTypeAny,
|
|
205
|
-
{
|
|
206
|
-
media: {
|
|
207
|
-
tags:
|
|
208
|
-
| {
|
|
209
|
-
value: string;
|
|
210
|
-
label: string;
|
|
211
|
-
}[]
|
|
212
|
-
| null;
|
|
213
|
-
};
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
media: {
|
|
217
|
-
tags:
|
|
218
|
-
| {
|
|
219
|
-
value: string;
|
|
220
|
-
label: string;
|
|
221
|
-
}[]
|
|
222
|
-
| null;
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
>;
|
|
226
|
-
originalFilename: z.ZodString;
|
|
227
|
-
title:
|
|
228
|
-
| z.ZodOptional<z.ZodString>
|
|
229
|
-
| z.ZodObject<
|
|
230
|
-
Record<string, z.ZodTypeAny>,
|
|
231
|
-
"passthrough",
|
|
232
|
-
z.ZodTypeAny,
|
|
233
|
-
z.objectOutputType<
|
|
234
|
-
Record<string, z.ZodTypeAny>,
|
|
235
|
-
z.ZodTypeAny,
|
|
236
|
-
"passthrough"
|
|
237
|
-
>,
|
|
238
|
-
z.objectInputType<
|
|
239
|
-
Record<string, z.ZodTypeAny>,
|
|
240
|
-
z.ZodTypeAny,
|
|
241
|
-
"passthrough"
|
|
242
|
-
>
|
|
243
|
-
>;
|
|
244
|
-
},
|
|
245
|
-
"strip",
|
|
246
|
-
z.ZodTypeAny,
|
|
247
|
-
{
|
|
248
|
-
originalFilename: string;
|
|
249
|
-
opt: {
|
|
250
|
-
media: {
|
|
251
|
-
tags:
|
|
252
|
-
| {
|
|
253
|
-
value: string;
|
|
254
|
-
label: string;
|
|
255
|
-
}[]
|
|
256
|
-
| null;
|
|
257
|
-
};
|
|
258
|
-
};
|
|
259
|
-
altText?:
|
|
260
|
-
| string
|
|
261
|
-
| z.objectOutputType<
|
|
262
|
-
Record<string, z.ZodTypeAny>,
|
|
263
|
-
z.ZodTypeAny,
|
|
264
|
-
"passthrough"
|
|
265
|
-
>
|
|
266
|
-
| undefined;
|
|
267
|
-
description?:
|
|
268
|
-
| string
|
|
269
|
-
| z.objectOutputType<
|
|
270
|
-
Record<string, z.ZodTypeAny>,
|
|
271
|
-
z.ZodTypeAny,
|
|
272
|
-
"passthrough"
|
|
273
|
-
>
|
|
274
|
-
| undefined;
|
|
275
|
-
title?:
|
|
276
|
-
| string
|
|
277
|
-
| z.objectOutputType<
|
|
278
|
-
Record<string, z.ZodTypeAny>,
|
|
279
|
-
z.ZodTypeAny,
|
|
280
|
-
"passthrough"
|
|
281
|
-
>
|
|
282
|
-
| undefined;
|
|
283
|
-
creditLine?:
|
|
284
|
-
| string
|
|
285
|
-
| z.objectOutputType<
|
|
286
|
-
Record<string, z.ZodTypeAny>,
|
|
287
|
-
z.ZodTypeAny,
|
|
288
|
-
"passthrough"
|
|
289
|
-
>
|
|
290
|
-
| undefined;
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
originalFilename: string;
|
|
294
|
-
opt: {
|
|
295
|
-
media: {
|
|
296
|
-
tags:
|
|
297
|
-
| {
|
|
298
|
-
value: string;
|
|
299
|
-
label: string;
|
|
300
|
-
}[]
|
|
301
|
-
| null;
|
|
302
|
-
};
|
|
303
|
-
};
|
|
304
|
-
altText?:
|
|
305
|
-
| string
|
|
306
|
-
| z.objectInputType<
|
|
307
|
-
Record<string, z.ZodTypeAny>,
|
|
308
|
-
z.ZodTypeAny,
|
|
309
|
-
"passthrough"
|
|
310
|
-
>
|
|
311
|
-
| undefined;
|
|
312
|
-
description?:
|
|
313
|
-
| string
|
|
314
|
-
| z.objectInputType<
|
|
315
|
-
Record<string, z.ZodTypeAny>,
|
|
316
|
-
z.ZodTypeAny,
|
|
317
|
-
"passthrough"
|
|
318
|
-
>
|
|
319
|
-
| undefined;
|
|
320
|
-
title?:
|
|
321
|
-
| string
|
|
322
|
-
| z.objectInputType<
|
|
323
|
-
Record<string, z.ZodTypeAny>,
|
|
324
|
-
z.ZodTypeAny,
|
|
325
|
-
"passthrough"
|
|
326
|
-
>
|
|
327
|
-
| undefined;
|
|
328
|
-
creditLine?:
|
|
329
|
-
| string
|
|
330
|
-
| z.objectInputType<
|
|
331
|
-
Record<string, z.ZodTypeAny>,
|
|
332
|
-
z.ZodTypeAny,
|
|
333
|
-
"passthrough"
|
|
334
|
-
>
|
|
335
|
-
| undefined;
|
|
336
|
-
}
|
|
337
|
-
>;
|
|
338
|
-
|
|
339
|
-
declare type ImageAsset = SanityImageAssetDocument &
|
|
340
|
-
CustomFields & {
|
|
341
|
-
_type: "sanity.imageAsset";
|
|
342
|
-
creditLine?: LocalizedString;
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
declare type ImageMediaFieldConfig = Omit<ImageDefinition, "options"> &
|
|
346
|
-
FieldDefinitionBase & {
|
|
347
|
-
name: string;
|
|
348
|
-
mediaTags: string[];
|
|
349
|
-
options?: ImageDefinition["options"];
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
declare type ImageMediaFieldResult = Omit<ImageDefinition, "options"> &
|
|
353
|
-
FieldDefinitionBase & {
|
|
354
|
-
options?: ImageDefinition["options"] & {
|
|
355
|
-
mediaTags: string[];
|
|
356
|
-
};
|
|
357
|
-
components: {
|
|
358
|
-
input: typeof AutoTagInput;
|
|
359
|
-
};
|
|
360
|
-
} & WidenValidation &
|
|
361
|
-
WidenInitialValue;
|
|
362
|
-
|
|
363
|
-
declare type Locale = {
|
|
364
|
-
title: string;
|
|
365
|
-
id: string;
|
|
366
|
-
[key: string]: unknown;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
declare type LocalizedString = string | Record<string, string>;
|
|
370
|
-
|
|
371
|
-
export declare const media: Plugin_2<void | MediaToolOptions>;
|
|
372
|
-
|
|
373
|
-
export declare const mediaAssetSource: {
|
|
374
|
-
component: (props: AssetSourceComponentProps) => JSX;
|
|
375
|
-
icon: ForwardRefExoticComponent<
|
|
376
|
-
Omit<SVGProps<SVGSVGElement>, "ref"> & RefAttributes<SVGSVGElement>
|
|
377
|
-
>;
|
|
378
|
-
name: string;
|
|
379
|
-
title: string;
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Defines an image or file field with automatic media tag application when an asset is selected.
|
|
384
|
-
*
|
|
385
|
-
* Pass `mediaTags` at the top level — they are moved into `options.mediaTags` (for media browser
|
|
386
|
-
* pre-filtering) and wire up {@link AutoTagInput} as the field component automatically:
|
|
387
|
-
* ```ts
|
|
388
|
-
* import {mediaField} from 'sanity-plugin-media'
|
|
389
|
-
*
|
|
390
|
-
* mediaField({
|
|
391
|
-
* name: 'coverImage',
|
|
392
|
-
* type: 'image',
|
|
393
|
-
* mediaTags: ['product-cover'],
|
|
394
|
-
* options: { hotspot: true },
|
|
395
|
-
* })
|
|
396
|
-
* ```
|
|
397
|
-
*
|
|
398
|
-
* For file fields, set `type: 'file'`:
|
|
399
|
-
* ```ts
|
|
400
|
-
* mediaField({ name: 'drawing', type: 'file', mediaTags: ['model-drawing'] })
|
|
401
|
-
* ```
|
|
402
|
-
*/
|
|
403
|
-
export declare function mediaField(
|
|
404
|
-
config: ImageMediaFieldConfig,
|
|
405
|
-
): ImageMediaFieldResult;
|
|
406
|
-
|
|
407
|
-
export declare function mediaField(
|
|
408
|
-
config: FileMediaFieldConfig,
|
|
409
|
-
): FileMediaFieldResult;
|
|
410
|
-
|
|
411
|
-
export declare type MediaTagsOptions = {
|
|
412
|
-
mediaTags?: string[];
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
export declare type MediaToolOptions = {
|
|
416
|
-
maximumUploadSize?: number;
|
|
417
|
-
createTagsOnUpload?: boolean;
|
|
418
|
-
components?: {
|
|
419
|
-
details?: ComponentType<
|
|
420
|
-
DetailsProps & {
|
|
421
|
-
renderDefaultDetails: (props: DetailsProps) => JSX.Element;
|
|
422
|
-
}
|
|
423
|
-
>;
|
|
424
|
-
};
|
|
425
|
-
creditLine?: {
|
|
426
|
-
enabled: boolean;
|
|
427
|
-
excludeSources?: string | string[];
|
|
428
|
-
};
|
|
429
|
-
directUploads?: boolean;
|
|
430
|
-
/**
|
|
431
|
-
* Optional locales following Sanity recommended scheme: [{ id, title }]
|
|
432
|
-
* https://www.sanity.io/docs/studio/localization#k4da239411955
|
|
433
|
-
*/
|
|
434
|
-
locales?: Locale[];
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
declare type SanityReference = {
|
|
438
|
-
_ref: string;
|
|
439
|
-
_type: "reference";
|
|
440
|
-
_weak?: boolean;
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
declare const tagOptionSchema: z.ZodObject<
|
|
444
|
-
{
|
|
445
|
-
label: z.ZodString;
|
|
446
|
-
value: z.ZodString;
|
|
447
|
-
},
|
|
448
|
-
"strip",
|
|
449
|
-
z.ZodTypeAny,
|
|
450
|
-
{
|
|
451
|
-
value: string;
|
|
452
|
-
label: string;
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
value: string;
|
|
456
|
-
label: string;
|
|
457
|
-
}
|
|
458
|
-
>;
|
|
459
|
-
|
|
460
|
-
declare type TagSelectOption = z.infer<typeof tagOptionSchema>;
|
|
461
|
-
|
|
462
|
-
export {};
|
package/sanity.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {configureStore, type AnyAction, type EnhancedStore} from '@reduxjs/toolkit'
|
|
2
|
-
import type {SanityClient} from '@sanity/client'
|
|
3
|
-
import type {Epic} from 'redux-observable'
|
|
4
|
-
import {createEpicMiddleware} from 'redux-observable'
|
|
5
|
-
|
|
6
|
-
import {rootReducer} from '../../modules'
|
|
7
|
-
import type {RootReducerState} from '../../modules/types'
|
|
8
|
-
import {createTestRootState} from './rootState'
|
|
9
|
-
|
|
10
|
-
export function createEpicTestStore(
|
|
11
|
-
epic: Epic<AnyAction, AnyAction, RootReducerState, {client: SanityClient}>,
|
|
12
|
-
mockClient: SanityClient,
|
|
13
|
-
preloaded?: Partial<RootReducerState>,
|
|
14
|
-
): EnhancedStore<RootReducerState, AnyAction> {
|
|
15
|
-
const epicMiddleware = createEpicMiddleware<AnyAction, AnyAction, RootReducerState>({
|
|
16
|
-
dependencies: {client: mockClient},
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const store = configureStore({
|
|
20
|
-
reducer: rootReducer,
|
|
21
|
-
middleware: (getDefaultMiddleware) =>
|
|
22
|
-
getDefaultMiddleware({serializableCheck: false, thunk: false}).concat(epicMiddleware),
|
|
23
|
-
preloadedState: createTestRootState(preloaded),
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
epicMiddleware.run(epic)
|
|
27
|
-
return store
|
|
28
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {vi} from 'vitest'
|
|
2
|
-
|
|
3
|
-
/** Flat mock for client.listen() without deep callback nesting (ESLint max-nested-callbacks). */
|
|
4
|
-
export function createListenMock(): ReturnType<typeof vi.fn> {
|
|
5
|
-
const unsubscribe = vi.fn()
|
|
6
|
-
const subscribe = vi.fn()
|
|
7
|
-
subscribe.mockReturnValue({unsubscribe})
|
|
8
|
-
return vi.fn().mockReturnValue({subscribe})
|
|
9
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type {SanityClient} from '@sanity/client'
|
|
2
|
-
import {Subject, of} from 'rxjs'
|
|
3
|
-
import {vi} from 'vitest'
|
|
4
|
-
|
|
5
|
-
export type MockSanityClient = {
|
|
6
|
-
observable: {
|
|
7
|
-
fetch: ReturnType<typeof vi.fn>
|
|
8
|
-
delete: ReturnType<typeof vi.fn>
|
|
9
|
-
create: ReturnType<typeof vi.fn>
|
|
10
|
-
assets: {upload: ReturnType<typeof vi.fn>}
|
|
11
|
-
}
|
|
12
|
-
fetch: ReturnType<typeof vi.fn>
|
|
13
|
-
listen: ReturnType<typeof vi.fn>
|
|
14
|
-
patch: ReturnType<typeof vi.fn>
|
|
15
|
-
transaction: ReturnType<typeof vi.fn>
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function createMockSanityClient(
|
|
19
|
-
overrides: Partial<Omit<MockSanityClient, 'observable'>> & {
|
|
20
|
-
observable?: Partial<MockSanityClient['observable']> & {
|
|
21
|
-
assets?: Partial<MockSanityClient['observable']['assets']>
|
|
22
|
-
}
|
|
23
|
-
} = {},
|
|
24
|
-
): SanityClient {
|
|
25
|
-
const {observable: observableOverrides, ...restOverrides} = overrides
|
|
26
|
-
|
|
27
|
-
const observableBase: MockSanityClient['observable'] = {
|
|
28
|
-
fetch: vi.fn(() => of({items: []})),
|
|
29
|
-
delete: vi.fn(() => of({})),
|
|
30
|
-
create: vi.fn(() => of({_id: 'new'})),
|
|
31
|
-
assets: {
|
|
32
|
-
upload: vi.fn(() => of({type: 'complete', body: {document: {_id: 'up'}}})),
|
|
33
|
-
},
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const observable: MockSanityClient['observable'] = {
|
|
37
|
-
...observableBase,
|
|
38
|
-
...(observableOverrides ?? {}),
|
|
39
|
-
assets: {
|
|
40
|
-
...observableBase.assets,
|
|
41
|
-
...(observableOverrides?.assets ?? {}),
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const client: MockSanityClient = {
|
|
46
|
-
observable,
|
|
47
|
-
fetch: vi.fn(() => Promise.resolve(0)),
|
|
48
|
-
listen: vi.fn(() => new Subject()),
|
|
49
|
-
patch: vi.fn(),
|
|
50
|
-
transaction: vi.fn(),
|
|
51
|
-
...restOverrides,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return client as unknown as SanityClient
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function mockPatchChain(result: unknown): {
|
|
58
|
-
set: ReturnType<typeof vi.fn>
|
|
59
|
-
setIfMissing: ReturnType<typeof vi.fn>
|
|
60
|
-
commit: ReturnType<typeof vi.fn>
|
|
61
|
-
} {
|
|
62
|
-
const commit = vi.fn().mockResolvedValue(result)
|
|
63
|
-
const chain = {
|
|
64
|
-
set: vi.fn(),
|
|
65
|
-
setIfMissing: vi.fn(),
|
|
66
|
-
commit,
|
|
67
|
-
}
|
|
68
|
-
chain.set.mockImplementation(() => chain)
|
|
69
|
-
chain.setIfMissing.mockImplementation(() => chain)
|
|
70
|
-
return chain
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function mockTransactionCommit(resolved: unknown = undefined): {
|
|
74
|
-
patch: ReturnType<typeof vi.fn>
|
|
75
|
-
delete: ReturnType<typeof vi.fn>
|
|
76
|
-
commit: ReturnType<typeof vi.fn>
|
|
77
|
-
} {
|
|
78
|
-
const tx = {
|
|
79
|
-
patch: vi.fn().mockReturnThis(),
|
|
80
|
-
delete: vi.fn().mockReturnThis(),
|
|
81
|
-
commit: vi.fn().mockResolvedValue(resolved),
|
|
82
|
-
}
|
|
83
|
-
return tx
|
|
84
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {configureStore} from '@reduxjs/toolkit'
|
|
2
|
-
import {studioTheme, ThemeProvider, ToastProvider} from '@sanity/ui'
|
|
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
|
-
|
|
9
|
-
import {AssetBrowserDispatchProvider} from '../../contexts/AssetSourceDispatchContext'
|
|
10
|
-
import {ToolOptionsProvider} from '../../contexts/ToolOptionsContext'
|
|
11
|
-
import {rootReducer} from '../../modules'
|
|
12
|
-
import type {RootReducerState} from '../../modules/types'
|
|
13
|
-
import type {MediaToolOptions} from '../../types'
|
|
14
|
-
import {createTestRootState} from './rootState'
|
|
15
|
-
|
|
16
|
-
type Opts = {
|
|
17
|
-
onSelect?: AssetSourceComponentProps['onSelect']
|
|
18
|
-
preloaded?: Partial<RootReducerState>
|
|
19
|
-
toolOptions?: Partial<MediaToolOptions>
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function renderWithProviders(ui: ReactElement, opts: Opts = {}) {
|
|
23
|
-
const {onSelect, preloaded, toolOptions} = opts
|
|
24
|
-
|
|
25
|
-
const store = configureStore({
|
|
26
|
-
reducer: rootReducer,
|
|
27
|
-
middleware: (getDefaultMiddleware) =>
|
|
28
|
-
getDefaultMiddleware({thunk: false, serializableCheck: false}),
|
|
29
|
-
preloadedState: createTestRootState(preloaded),
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const options: MediaToolOptions = {
|
|
33
|
-
creditLine: {enabled: false},
|
|
34
|
-
directUploads: true,
|
|
35
|
-
...toolOptions,
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const wrap = (node: ReactNode) => (
|
|
39
|
-
<Provider store={store}>
|
|
40
|
-
<ColorSchemeProvider scheme="light">
|
|
41
|
-
<ToolOptionsProvider options={options}>
|
|
42
|
-
<ThemeProvider theme={studioTheme}>
|
|
43
|
-
<ToastProvider>
|
|
44
|
-
<AssetBrowserDispatchProvider onSelect={onSelect}>
|
|
45
|
-
{node}
|
|
46
|
-
</AssetBrowserDispatchProvider>
|
|
47
|
-
</ToastProvider>
|
|
48
|
-
</ThemeProvider>
|
|
49
|
-
</ToolOptionsProvider>
|
|
50
|
-
</ColorSchemeProvider>
|
|
51
|
-
</Provider>
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
return {store, ...render(wrap(ui))}
|
|
55
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {initialState as assetsInitialState} from '../../modules/assets'
|
|
2
|
-
import type {RootReducerState} from '../../modules/types'
|
|
3
|
-
|
|
4
|
-
export function createTestRootState(overrides: Partial<RootReducerState> = {}): RootReducerState {
|
|
5
|
-
const base: RootReducerState = {
|
|
6
|
-
assets: {
|
|
7
|
-
...assetsInitialState,
|
|
8
|
-
assetTypes: ['file', 'image'],
|
|
9
|
-
},
|
|
10
|
-
debug: {badConnection: false, enabled: false},
|
|
11
|
-
dialog: {items: []},
|
|
12
|
-
notifications: {items: []},
|
|
13
|
-
search: {facets: [], query: ''},
|
|
14
|
-
selected: {assets: [], document: undefined, documentAssetIds: []},
|
|
15
|
-
tags: {
|
|
16
|
-
allIds: [],
|
|
17
|
-
byIds: {},
|
|
18
|
-
creating: false,
|
|
19
|
-
fetchCount: -1,
|
|
20
|
-
fetching: false,
|
|
21
|
-
panelVisible: true,
|
|
22
|
-
},
|
|
23
|
-
uploads: {allIds: [], byIds: {}},
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return {...base, ...overrides} as RootReducerState
|
|
27
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {within, type Screen} from '@testing-library/react'
|
|
2
|
-
|
|
3
|
-
/** Topmost Sanity dialog matching `name` (handles animated duplicate layers). */
|
|
4
|
-
export function getDialogRoot(name: RegExp, base: Screen): HTMLElement {
|
|
5
|
-
const dialogs = base.getAllByRole('dialog', {name})
|
|
6
|
-
const el = dialogs.at(-1)
|
|
7
|
-
if (!el) {
|
|
8
|
-
throw new Error(`No dialog found matching ${name}`)
|
|
9
|
-
}
|
|
10
|
-
return el
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Scoped queries for that dialog. */
|
|
14
|
-
export function withinDialog(name: RegExp, base: Screen) {
|
|
15
|
-
return within(getDialogRoot(name, base))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Sanity `TextInput` is not always exposed as a labellable control; use the native input by `name`.
|
|
20
|
-
*/
|
|
21
|
-
export function inputByName(dialogName: RegExp, base: Screen, name: string): HTMLInputElement {
|
|
22
|
-
const root = getDialogRoot(dialogName, base)
|
|
23
|
-
const input = root.querySelector(`input[name="${name}"]`)
|
|
24
|
-
if (!input || !(input instanceof HTMLInputElement)) {
|
|
25
|
-
throw new Error(`No input name="${name}" in dialog matching ${dialogName}`)
|
|
26
|
-
}
|
|
27
|
-
return input
|
|
28
|
-
}
|