@madebywild/sanity-media-field
v1.3.0
Published
> [!IMPORTANT] > This package is primarily intended for internal use.
Downloads
505
Readme
[!IMPORTANT] This package is primarily intended for internal use.
@madebywild/sanity-media-field
Sanity media field that combines image, video, and motion inputs.
Install
pnpm add @madebywild/sanity-media-fieldConfigure Plugin
import { defineConfig } from "sanity";
import { wildSanityMediaFieldPlugin } from "@madebywild/sanity-media-field";
export default defineConfig({
plugins: [wildSanityMediaFieldPlugin()],
});Use in Schema
import { defineField } from "sanity";
import { requireMedia } from "@madebywild/sanity-media-field";
defineField({
name: "heroMedia",
type: "wild.media",
validation: (R) => requireMedia(R),
options: {
inline: true,
allowedKinds: ["image", "video"],
disallowedKinds: ["motion"],
// enabled by default; supports a boolean or { enabled, altText, imagePrompt }
aiAssistant: { imagePrompt: false },
extensions: {
// each supports `true` or { enabled: true/false }
caption: true,
customRatio: { enabled: true },
videoOptions: { enabled: true },
},
},
});AI Assistant
The media field integrates with Sanity AI Assist. When enabled, the image input gains:
- an
altTextfield that AI Assist automatically fills with a generated image description whenever the image changes. - an
imagePromptfield that generates a new image asset from the prompt when an AI Assist instruction writes to it.
Requires @sanity/assist to be installed and configured in the studio. Without it, the fields still render but stay inert: nothing is ever generated, and imagePrompt does nothing. If your studio doesn't use AI Assist, consider disabling imagePrompt (or the assistant entirely) to avoid showing a dead field.
The AI assistant and both of its features are enabled by default and stay enabled unless explicitly disabled in the plugin config or on the field level. Both levels are merged per option, with field-level options taking precedence:
// Plugin level: disable the image prompt field for all media fields.
wildSanityMediaFieldPlugin({ aiAssistant: { imagePrompt: false } });
// Field level: overrides the plugin config per option.
defineField({
name: "heroMedia",
type: "wild.media",
options: {
// Disable the AI assistant entirely for this field...
aiAssistant: false,
// ...or toggle individual features:
// aiAssistant: { imagePrompt: true, altText: false },
},
});Disabling the AI assistant (at either level) only hides the inputs. The altText and imagePrompt fields remain part of the schema, and existing values are preserved and stay queryable via GROQ. In a studio with @sanity/assist installed, alt text auto-generation still runs when the image changes, even where the field is hidden. The only way to fully opt out of the AI Assist behavior is to not install @sanity/assist in the studio.
