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.
- package/package.json +6 -15
- package/dist/index.cjs +0 -4721
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -239
- package/dist/index.d.cts.map +0 -1
- 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 -85
- 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 -493
- package/src/components/DialogConfirm/index.tsx +0 -90
- package/src/components/DialogSearchFacets/index.tsx +0 -42
- package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
- package/src/components/DialogTagCreate/index.tsx +0 -111
- package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
- package/src/components/DialogTagEdit/index.tsx +0 -201
- 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 -419
- 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 -38
- package/src/contexts/DropzoneDispatchContext.tsx +0 -32
- package/src/contexts/ToolOptionsContext.tsx +0 -66
- package/src/formSchema/index.test.ts +0 -56
- package/src/formSchema/index.ts +0 -39
- package/src/hooks/useBreakpointIndex.ts +0 -50
- package/src/hooks/useKeyPress.ts +0 -39
- 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 -782
- 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 -117
- 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 -272
- 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 -346
- package/src/types/sanity-ui.d.ts +0 -5
- 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 -68
- 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,239 +0,0 @@
|
|
|
1
|
-
import { SanityAssetDocument, SanityImageAssetDocument } from "@sanity/client";
|
|
2
|
-
import { ComponentType, JSX } from "react";
|
|
3
|
-
import * as z from "zod";
|
|
4
|
-
import { Control, FieldErrors, UseFormRegister } from "react-hook-form";
|
|
5
|
-
import { FieldDefinitionBase, FileDefinition, ImageDefinition, InputProps, WidenInitialValue, WidenValidation } from "sanity";
|
|
6
|
-
type DetailsProps = {
|
|
7
|
-
formUpdating: boolean;
|
|
8
|
-
handleCreateTag: (title: string) => void;
|
|
9
|
-
control: Control<AssetFormData>;
|
|
10
|
-
errors: FieldErrors<AssetFormData>;
|
|
11
|
-
register: UseFormRegister<AssetFormData>;
|
|
12
|
-
allTagOptions: TagSelectOption[];
|
|
13
|
-
assetTagOptions: TagSelectOption[] | null;
|
|
14
|
-
currentAsset: Asset;
|
|
15
|
-
creditLine?: {
|
|
16
|
-
enabled: boolean;
|
|
17
|
-
excludeSources?: string | string[] | undefined;
|
|
18
|
-
};
|
|
19
|
-
locales?: Locale[];
|
|
20
|
-
};
|
|
21
|
-
declare const tagOptionSchema: z.ZodObject<{
|
|
22
|
-
label: z.ZodString;
|
|
23
|
-
value: z.ZodString;
|
|
24
|
-
}, "strip", z.ZodTypeAny, {
|
|
25
|
-
value: string;
|
|
26
|
-
label: string;
|
|
27
|
-
}, {
|
|
28
|
-
value: string;
|
|
29
|
-
label: string;
|
|
30
|
-
}>;
|
|
31
|
-
declare function getAssetFormSchema(locales?: {
|
|
32
|
-
id: string;
|
|
33
|
-
}[]): z.ZodObject<{
|
|
34
|
-
altText: z.ZodOptional<z.ZodString> | z.ZodObject<Record<string, z.ZodTypeAny>, "passthrough", z.ZodTypeAny, z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough">, z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough">>;
|
|
35
|
-
creditLine: z.ZodOptional<z.ZodString> | z.ZodObject<Record<string, z.ZodTypeAny>, "passthrough", z.ZodTypeAny, z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough">, z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough">>;
|
|
36
|
-
description: z.ZodOptional<z.ZodString> | z.ZodObject<Record<string, z.ZodTypeAny>, "passthrough", z.ZodTypeAny, z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough">, z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough">>;
|
|
37
|
-
opt: z.ZodObject<{
|
|
38
|
-
media: z.ZodObject<{
|
|
39
|
-
tags: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
40
|
-
label: z.ZodString;
|
|
41
|
-
value: z.ZodString;
|
|
42
|
-
}, "strip", z.ZodTypeAny, {
|
|
43
|
-
value: string;
|
|
44
|
-
label: string;
|
|
45
|
-
}, {
|
|
46
|
-
value: string;
|
|
47
|
-
label: string;
|
|
48
|
-
}>, "many">>;
|
|
49
|
-
}, "strip", z.ZodTypeAny, {
|
|
50
|
-
tags: {
|
|
51
|
-
value: string;
|
|
52
|
-
label: string;
|
|
53
|
-
}[] | null;
|
|
54
|
-
}, {
|
|
55
|
-
tags: {
|
|
56
|
-
value: string;
|
|
57
|
-
label: string;
|
|
58
|
-
}[] | null;
|
|
59
|
-
}>;
|
|
60
|
-
}, "strip", z.ZodTypeAny, {
|
|
61
|
-
media: {
|
|
62
|
-
tags: {
|
|
63
|
-
value: string;
|
|
64
|
-
label: string;
|
|
65
|
-
}[] | null;
|
|
66
|
-
};
|
|
67
|
-
}, {
|
|
68
|
-
media: {
|
|
69
|
-
tags: {
|
|
70
|
-
value: string;
|
|
71
|
-
label: string;
|
|
72
|
-
}[] | null;
|
|
73
|
-
};
|
|
74
|
-
}>;
|
|
75
|
-
originalFilename: z.ZodString;
|
|
76
|
-
title: z.ZodOptional<z.ZodString> | z.ZodObject<Record<string, z.ZodTypeAny>, "passthrough", z.ZodTypeAny, z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough">, z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough">>;
|
|
77
|
-
}, "strip", z.ZodTypeAny, {
|
|
78
|
-
originalFilename: string;
|
|
79
|
-
opt: {
|
|
80
|
-
media: {
|
|
81
|
-
tags: {
|
|
82
|
-
value: string;
|
|
83
|
-
label: string;
|
|
84
|
-
}[] | null;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
altText?: string | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough"> | undefined;
|
|
88
|
-
description?: string | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough"> | undefined;
|
|
89
|
-
title?: string | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough"> | undefined;
|
|
90
|
-
creditLine?: string | z.objectOutputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough"> | undefined;
|
|
91
|
-
}, {
|
|
92
|
-
originalFilename: string;
|
|
93
|
-
opt: {
|
|
94
|
-
media: {
|
|
95
|
-
tags: {
|
|
96
|
-
value: string;
|
|
97
|
-
label: string;
|
|
98
|
-
}[] | null;
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
altText?: string | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough"> | undefined;
|
|
102
|
-
description?: string | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough"> | undefined;
|
|
103
|
-
title?: string | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough"> | undefined;
|
|
104
|
-
creditLine?: string | z.objectInputType<Record<string, z.ZodTypeAny>, z.ZodTypeAny, "passthrough"> | undefined;
|
|
105
|
-
}>;
|
|
106
|
-
type MediaTagsOptions = {
|
|
107
|
-
mediaTags?: string[];
|
|
108
|
-
};
|
|
109
|
-
type MediaToolOptions = {
|
|
110
|
-
maximumUploadSize?: number;
|
|
111
|
-
createTagsOnUpload?: boolean;
|
|
112
|
-
components?: {
|
|
113
|
-
details?: ComponentType<DetailsProps & {
|
|
114
|
-
renderDefaultDetails: (props: DetailsProps) => JSX.Element;
|
|
115
|
-
}>;
|
|
116
|
-
};
|
|
117
|
-
creditLine?: {
|
|
118
|
-
enabled: boolean;
|
|
119
|
-
excludeSources?: string | string[];
|
|
120
|
-
};
|
|
121
|
-
directUploads?: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* Optional locales following Sanity recommended scheme: [{ id, title }]
|
|
124
|
-
* https://www.sanity.io/docs/studio/localization#k4da239411955
|
|
125
|
-
*/
|
|
126
|
-
locales?: Locale[];
|
|
127
|
-
};
|
|
128
|
-
type Locale = {
|
|
129
|
-
title: string;
|
|
130
|
-
id: string;
|
|
131
|
-
[key: string]: unknown;
|
|
132
|
-
};
|
|
133
|
-
type LocalizedString = string | Record<string, string>;
|
|
134
|
-
type CustomFields = {
|
|
135
|
-
altText?: LocalizedString;
|
|
136
|
-
description?: LocalizedString;
|
|
137
|
-
opt?: {
|
|
138
|
-
media?: {
|
|
139
|
-
tags?: SanityReference[];
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
title?: LocalizedString;
|
|
143
|
-
};
|
|
144
|
-
type Asset = FileAsset | ImageAsset;
|
|
145
|
-
type AssetFormData = z.infer<ReturnType<typeof getAssetFormSchema>>;
|
|
146
|
-
type FileAsset = SanityAssetDocument & CustomFields & {
|
|
147
|
-
_type: 'sanity.fileAsset';
|
|
148
|
-
};
|
|
149
|
-
type ImageAsset = SanityImageAssetDocument & CustomFields & {
|
|
150
|
-
_type: 'sanity.imageAsset';
|
|
151
|
-
creditLine?: LocalizedString;
|
|
152
|
-
};
|
|
153
|
-
type SanityReference = {
|
|
154
|
-
_ref: string;
|
|
155
|
-
_type: 'reference';
|
|
156
|
-
_weak?: boolean;
|
|
157
|
-
};
|
|
158
|
-
type TagSelectOption = z.infer<typeof tagOptionSchema>;
|
|
159
|
-
declare const mediaAssetSource: {
|
|
160
|
-
component: (props: import("sanity").AssetSourceComponentProps) => import("react").JSX.Element;
|
|
161
|
-
icon: import("react").ForwardRefExoticComponent<Omit<import("react").SVGProps<SVGSVGElement>, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
|
|
162
|
-
name: string;
|
|
163
|
-
title: string;
|
|
164
|
-
};
|
|
165
|
-
declare const media: import("sanity").Plugin<void | MediaToolOptions>;
|
|
166
|
-
type AutoTagInputProps = InputProps & {
|
|
167
|
-
mediaTags?: string[];
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* Input component that automatically applies media tags when an asset is selected or uploaded.
|
|
171
|
-
*
|
|
172
|
-
* Apply explicitly to image/file fields that should be auto-tagged:
|
|
173
|
-
* ```ts
|
|
174
|
-
* import {AutoTagInput} from 'sanity-plugin-media'
|
|
175
|
-
*
|
|
176
|
-
* defineField({
|
|
177
|
-
* type: 'image',
|
|
178
|
-
* options: { mediaTags: ['product'] }, // also pre-filters the media browser
|
|
179
|
-
* components: { input: AutoTagInput },
|
|
180
|
-
* })
|
|
181
|
-
* ```
|
|
182
|
-
*
|
|
183
|
-
* Pass `mediaTags` as a prop to override or use without `options`:
|
|
184
|
-
* ```ts
|
|
185
|
-
* components: { input: (props) => <AutoTagInput {...props} mediaTags={['product']} /> }
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
declare function AutoTagInput(props: AutoTagInputProps): import("react").JSX.Element;
|
|
189
|
-
type ImageMediaFieldConfig = Omit<ImageDefinition, 'options'> & FieldDefinitionBase & {
|
|
190
|
-
name: string;
|
|
191
|
-
mediaTags: string[];
|
|
192
|
-
options?: ImageDefinition['options'];
|
|
193
|
-
};
|
|
194
|
-
type FileMediaFieldConfig = Omit<FileDefinition, 'options'> & FieldDefinitionBase & {
|
|
195
|
-
name: string;
|
|
196
|
-
mediaTags: string[];
|
|
197
|
-
options?: FileDefinition['options'];
|
|
198
|
-
};
|
|
199
|
-
type ImageMediaFieldResult = Omit<ImageDefinition, 'options'> & FieldDefinitionBase & {
|
|
200
|
-
options?: ImageDefinition['options'] & {
|
|
201
|
-
mediaTags: string[];
|
|
202
|
-
};
|
|
203
|
-
components: {
|
|
204
|
-
input: typeof AutoTagInput;
|
|
205
|
-
};
|
|
206
|
-
} & WidenValidation & WidenInitialValue;
|
|
207
|
-
type FileMediaFieldResult = Omit<FileDefinition, 'options'> & FieldDefinitionBase & {
|
|
208
|
-
options?: FileDefinition['options'] & {
|
|
209
|
-
mediaTags: string[];
|
|
210
|
-
};
|
|
211
|
-
components: {
|
|
212
|
-
input: typeof AutoTagInput;
|
|
213
|
-
};
|
|
214
|
-
} & WidenValidation & WidenInitialValue;
|
|
215
|
-
/**
|
|
216
|
-
* Defines an image or file field with automatic media tag application when an asset is selected.
|
|
217
|
-
*
|
|
218
|
-
* Pass `mediaTags` at the top level — they are moved into `options.mediaTags` (for media browser
|
|
219
|
-
* pre-filtering) and wire up {@link AutoTagInput} as the field component automatically:
|
|
220
|
-
* ```ts
|
|
221
|
-
* import {mediaField} from 'sanity-plugin-media'
|
|
222
|
-
*
|
|
223
|
-
* mediaField({
|
|
224
|
-
* name: 'coverImage',
|
|
225
|
-
* type: 'image',
|
|
226
|
-
* mediaTags: ['product-cover'],
|
|
227
|
-
* options: { hotspot: true },
|
|
228
|
-
* })
|
|
229
|
-
* ```
|
|
230
|
-
*
|
|
231
|
-
* For file fields, set `type: 'file'`:
|
|
232
|
-
* ```ts
|
|
233
|
-
* mediaField({ name: 'drawing', type: 'file', mediaTags: ['model-drawing'] })
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
|
-
declare function mediaField(config: ImageMediaFieldConfig): ImageMediaFieldResult;
|
|
237
|
-
declare function mediaField(config: FileMediaFieldConfig): FileMediaFieldResult;
|
|
238
|
-
export { AutoTagInput, type AutoTagInputProps, type MediaTagsOptions, type MediaToolOptions, media, mediaAssetSource, mediaField };
|
|
239
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/components/DialogAssetEdit/Details.tsx","../src/formSchema/index.ts","../src/types/index.ts","../src/plugin.tsx","../src/components/AutoTagInputWrapper/index.tsx","../src/utils/mediaField.ts"],"mappings":"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"}
|
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): {
|
|
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
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import {memo, forwardRef} from 'react'
|
|
2
|
-
import {VirtuosoGrid} from 'react-virtuoso'
|
|
3
|
-
import {styled} from 'styled-components'
|
|
4
|
-
|
|
5
|
-
import useTypedSelector from '../../hooks/useTypedSelector'
|
|
6
|
-
import type {CardAssetData, CardUploadData} from '../../types'
|
|
7
|
-
import CardAsset from '../CardAsset'
|
|
8
|
-
import CardUpload from '../CardUpload'
|
|
9
|
-
|
|
10
|
-
type Props = {
|
|
11
|
-
items: (CardAssetData | CardUploadData)[]
|
|
12
|
-
onLoadMore?: () => void
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const CARD_HEIGHT = 220
|
|
16
|
-
const CARD_WIDTH = 240
|
|
17
|
-
|
|
18
|
-
const VirtualCell = memo(
|
|
19
|
-
({item, selected}: {item: CardAssetData | CardUploadData; selected: boolean}) => {
|
|
20
|
-
if (item?.type === 'asset') {
|
|
21
|
-
return <CardAsset id={item.id} selected={selected} />
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (item?.type === 'upload') {
|
|
25
|
-
return <CardUpload id={item.id} />
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return null
|
|
29
|
-
},
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
const StyledItemContainer = styled.div`
|
|
33
|
-
height: ${CARD_HEIGHT}px;
|
|
34
|
-
width: ${CARD_WIDTH}px;
|
|
35
|
-
`
|
|
36
|
-
|
|
37
|
-
const ItemContainer = forwardRef<HTMLDivElement, any>((props, ref) => {
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- we're doing this to avoid sc warnings about `context` passed as an attribute
|
|
39
|
-
const {context, ...rest} = props
|
|
40
|
-
return <StyledItemContainer ref={ref} {...rest} />
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
const StyledListContainer = styled.div`
|
|
44
|
-
display: grid;
|
|
45
|
-
grid-template-columns: repeat(auto-fill, ${CARD_WIDTH}px);
|
|
46
|
-
grid-template-rows: repeat(auto-fill, ${CARD_HEIGHT}px);
|
|
47
|
-
justify-content: center;
|
|
48
|
-
margin: 0 auto;
|
|
49
|
-
`
|
|
50
|
-
|
|
51
|
-
const ListContainer = forwardRef<HTMLDivElement, any>((props, ref) => {
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- we're doing this to avoid sc warnings about `context` passed as an attribute
|
|
53
|
-
const {context, ...rest} = props
|
|
54
|
-
return <StyledListContainer ref={ref} {...rest} />
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
const AssetGridVirtualized = (props: Props) => {
|
|
58
|
-
const {items, onLoadMore} = props
|
|
59
|
-
|
|
60
|
-
// Redux
|
|
61
|
-
const selectedAssets = useTypedSelector((state) => state.selected.assets)
|
|
62
|
-
|
|
63
|
-
const selectedIds = (selectedAssets && selectedAssets.map((asset) => asset._id)) || []
|
|
64
|
-
const totalCount = items?.length
|
|
65
|
-
|
|
66
|
-
if (totalCount === 0) {
|
|
67
|
-
return null
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<VirtuosoGrid
|
|
72
|
-
className="media__custom-scrollbar"
|
|
73
|
-
computeItemKey={(index) => {
|
|
74
|
-
const item = items[index]
|
|
75
|
-
return item?.id ?? index
|
|
76
|
-
}}
|
|
77
|
-
components={{
|
|
78
|
-
Item: ItemContainer,
|
|
79
|
-
List: ListContainer,
|
|
80
|
-
}}
|
|
81
|
-
endReached={onLoadMore}
|
|
82
|
-
itemContent={(index) => {
|
|
83
|
-
const item = items[index]!
|
|
84
|
-
const selected = selectedIds.includes(item.id)
|
|
85
|
-
return <VirtualCell item={item} selected={selected} />
|
|
86
|
-
}}
|
|
87
|
-
overscan={48}
|
|
88
|
-
style={{overflowX: 'hidden', overflowY: 'scroll'}}
|
|
89
|
-
totalCount={totalCount}
|
|
90
|
-
/>
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export default AssetGridVirtualized
|