@electrolux-oss/sanity-plugin-media 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +29 -22
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ declare const createAssetFormSchema: (
|
|
|
43
43
|
) => z.ZodObject<
|
|
44
44
|
{
|
|
45
45
|
altText: z.ZodOptional<z.ZodString>
|
|
46
|
-
altTexts: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString
|
|
46
|
+
altTexts: z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodNullable<z.ZodString>>>
|
|
47
47
|
creditLine: z.ZodOptional<z.ZodString>
|
|
48
48
|
description: z.ZodOptional<z.ZodString>
|
|
49
49
|
opt: z.ZodObject<
|
package/dist/index.js
CHANGED
|
@@ -465,7 +465,7 @@ const EditIcon = /* @__PURE__ */ forwardRef(function(props, ref) {
|
|
|
465
465
|
], GRID_TEMPLATE_COLUMNS = {
|
|
466
466
|
SMALL: "3rem 100px auto 1.5rem",
|
|
467
467
|
LARGE: "3rem 100px auto 5.5rem 5.5rem 3.5rem 8.5rem 4.75rem 2rem"
|
|
468
|
-
}, PANEL_HEIGHT = 32, TAG_DOCUMENT_NAME = "media.tag", TAGS_PANEL_WIDTH = 250, debugThrottle = (throttled) => function(source) {
|
|
468
|
+
}, EDIT_MEDIA_SOURCE_NAME = "edit-media", PANEL_HEIGHT = 32, TAG_DOCUMENT_NAME = "media.tag", TAGS_PANEL_WIDTH = 250, debugThrottle = (throttled) => function(source) {
|
|
469
469
|
return iif(
|
|
470
470
|
() => !!throttled,
|
|
471
471
|
source.pipe(
|
|
@@ -1769,23 +1769,15 @@ const customScrollbar = css`
|
|
|
1769
1769
|
value: z.string().trim().min(1, { error: "Value cannot be empty" })
|
|
1770
1770
|
}), tagFormSchema = z.object({
|
|
1771
1771
|
name: z.string().min(1, { error: "Name cannot be empty" })
|
|
1772
|
-
}), createAssetFormSchema = (languages, validateAltTexts = !1) => {
|
|
1772
|
+
}), hasText = (text) => !!text?.trim(), createAssetFormSchema = (languages, validateAltTexts = !1) => {
|
|
1773
1773
|
const defaultLanguage = languages.find((lang) => lang.default), createAltTextsSchema = () => {
|
|
1774
|
-
const baseSchema = z.record(z.string(), z.string().
|
|
1775
|
-
return validateAltTexts ? baseSchema.refine(
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
return Object.values(altTexts).some(
|
|
1782
|
-
(text) => text != null && text.trim().length > 0
|
|
1783
|
-
);
|
|
1784
|
-
},
|
|
1785
|
-
{
|
|
1786
|
-
error: 'The default language must have alt text. Please fill in the default language field and click "Save and close".'
|
|
1787
|
-
}
|
|
1788
|
-
) : baseSchema;
|
|
1774
|
+
const baseSchema = z.record(z.string(), z.string().nullish());
|
|
1775
|
+
return validateAltTexts ? defaultLanguage ? baseSchema.refine((altTexts) => hasText(altTexts[defaultLanguage.code]), {
|
|
1776
|
+
error: `Alt text is required for the default language (${defaultLanguage.title}).`,
|
|
1777
|
+
path: [defaultLanguage.code]
|
|
1778
|
+
}) : baseSchema.refine((altTexts) => Object.values(altTexts).some(hasText), {
|
|
1779
|
+
error: "At least one language must have alt text."
|
|
1780
|
+
}) : baseSchema;
|
|
1789
1781
|
};
|
|
1790
1782
|
return z.object({
|
|
1791
1783
|
altText: z.string().trim().optional(),
|
|
@@ -2139,6 +2131,7 @@ const ButtonAssetCopy = ({ disabled, url }) => {
|
|
|
2139
2131
|
...rest,
|
|
2140
2132
|
autoComplete: "off",
|
|
2141
2133
|
autoFocus: !0,
|
|
2134
|
+
customValidity: error,
|
|
2142
2135
|
defaultValue: value,
|
|
2143
2136
|
disabled,
|
|
2144
2137
|
id: name,
|
|
@@ -2562,7 +2555,7 @@ const DialogAssetEdit = (props) => {
|
|
|
2562
2555
|
useEffect(() => {
|
|
2563
2556
|
trigger();
|
|
2564
2557
|
}, [trigger]);
|
|
2565
|
-
const altTextsError = errors?.altTexts?.root?.message || errors?.altTexts?.message, formUpdating = !assetItem || assetItem?.updating, handleClose = useCallback(() => {
|
|
2558
|
+
const defaultLanguageCode = languages.find((language) => language.default)?.code, altTextsError = errors?.altTexts?.root?.message || errors?.altTexts?.message || defaultLanguageCode && errors?.altTexts?.[defaultLanguageCode]?.message, formUpdating = !assetItem || assetItem?.updating, handleClose = useCallback(() => {
|
|
2566
2559
|
dispatch(dialogActions.remove({ id }));
|
|
2567
2560
|
}, [dispatch, id]), handleDelete = useCallback(() => {
|
|
2568
2561
|
assetItem?.asset && dispatch(
|
|
@@ -2630,8 +2623,8 @@ const DialogAssetEdit = (props) => {
|
|
|
2630
2623
|
setValue("opt.media.tags", updatedTags, { shouldDirty: !0 });
|
|
2631
2624
|
}
|
|
2632
2625
|
}, [getValues, lastRemovedTagIds, setValue]), useEffect(() => {
|
|
2633
|
-
assetUpdatedPrev.current !== assetItem?.asset._updatedAt && reset(generateDefaultValues(assetItem?.asset)), assetUpdatedPrev.current = assetItem?.asset._updatedAt;
|
|
2634
|
-
}, [assetItem?.asset, generateDefaultValues, reset]);
|
|
2626
|
+
assetUpdatedPrev.current !== assetItem?.asset._updatedAt && (reset(generateDefaultValues(assetItem?.asset)), trigger()), assetUpdatedPrev.current = assetItem?.asset._updatedAt;
|
|
2627
|
+
}, [assetItem?.asset, generateDefaultValues, reset, trigger]);
|
|
2635
2628
|
const Footer = () => /* @__PURE__ */ jsx(Box, { padding: 3, children: /* @__PURE__ */ jsxs(Flex, { justify: "space-between", children: [
|
|
2636
2629
|
/* @__PURE__ */ jsx(
|
|
2637
2630
|
Button,
|
|
@@ -2748,7 +2741,7 @@ const DialogAssetEdit = (props) => {
|
|
|
2748
2741
|
id: "alt-texts",
|
|
2749
2742
|
children: [
|
|
2750
2743
|
altTextsError && /* @__PURE__ */ jsx(Stack, { marginBottom: 3, children: /* @__PURE__ */ jsx(Card, { padding: [3, 3, 4], radius: 2, shadow: 1, tone: "critical", children: /* @__PURE__ */ jsx(Text, { size: 1, children: altTextsError }) }) }),
|
|
2751
|
-
/* @__PURE__ */ jsx(Stack, { gap: 2, style: { height: "
|
|
2744
|
+
/* @__PURE__ */ jsx(Stack, { gap: 2, style: { height: "55dvh", overflowY: "auto" }, children: languages.map((language) => {
|
|
2752
2745
|
const label = language.default ? `${language.title} (Default)` : language.title;
|
|
2753
2746
|
return /* @__PURE__ */ jsx(
|
|
2754
2747
|
FormFieldInputText,
|
|
@@ -6058,6 +6051,17 @@ const UploadDropzone = (props) => {
|
|
|
6058
6051
|
children: /* @__PURE__ */ jsx(Browser, { document: currentDocument, ...props })
|
|
6059
6052
|
}
|
|
6060
6053
|
) }) });
|
|
6054
|
+
}, isAssetSchemaType = (schemaType) => schemaType ? schemaType.name === "image" || schemaType.name === "file" ? !0 : isAssetSchemaType(schemaType.type) : !1, withoutEditMedia = (sources) => sources ? typeof sources == "function" ? (source) => source.name !== EDIT_MEDIA_SOURCE_NAME && sources(source) : sources.filter(
|
|
6055
|
+
(entry) => (typeof entry == "string" ? entry : entry.name) !== EDIT_MEDIA_SOURCE_NAME
|
|
6056
|
+
) : (source) => source.name !== EDIT_MEDIA_SOURCE_NAME, AssetSourcesInput = (props) => {
|
|
6057
|
+
const { renderDefault, schemaType, value } = props, hideEditMedia = isAssetSchemaType(schemaType) && !value?.asset?._ref, schemaTypeWithoutEditMedia = useMemo(() => {
|
|
6058
|
+
const options = schemaType.options;
|
|
6059
|
+
return {
|
|
6060
|
+
...schemaType,
|
|
6061
|
+
options: { ...options, sources: withoutEditMedia(options?.sources) }
|
|
6062
|
+
};
|
|
6063
|
+
}, [schemaType]);
|
|
6064
|
+
return renderDefault(hideEditMedia ? { ...props, schemaType: schemaTypeWithoutEditMedia } : props);
|
|
6061
6065
|
}, Tool = () => /* @__PURE__ */ jsx(Flex, { direction: "column", height: "fill", flex: 1, children: /* @__PURE__ */ jsx(Browser, {}) }), listeners = /* @__PURE__ */ new Set(), subscribeToUploadRejections = (listener) => (listeners.add(listener), () => {
|
|
6062
6066
|
listeners.delete(listener);
|
|
6063
6067
|
}), withMaximumUploadSize = (source, maximumUploadSize) => {
|
|
@@ -6150,7 +6154,7 @@ const getUploadedAssetId = (patches) => (Array.isArray(patches) ? patches : [pat
|
|
|
6150
6154
|
component: FormBuilderTool
|
|
6151
6155
|
}, editMediaAssetSource = {
|
|
6152
6156
|
icon: EditIcon,
|
|
6153
|
-
name:
|
|
6157
|
+
name: EDIT_MEDIA_SOURCE_NAME,
|
|
6154
6158
|
title: "Edit Media",
|
|
6155
6159
|
component: EditAssetTool
|
|
6156
6160
|
}, tool = {
|
|
@@ -6183,6 +6187,9 @@ const getUploadedAssetId = (patches) => (Array.isArray(patches) ? patches : [pat
|
|
|
6183
6187
|
}
|
|
6184
6188
|
},
|
|
6185
6189
|
form: {
|
|
6190
|
+
components: {
|
|
6191
|
+
input: AssetSourcesInput
|
|
6192
|
+
},
|
|
6186
6193
|
file: {
|
|
6187
6194
|
assetSources: resolveAssetSources
|
|
6188
6195
|
},
|