sanity-plugin-cloudinary

2.1.02.1.1
~

Modified (5 files)

Index: package/dist/index.js
===================================================================
--- package/dist/index.js
+++ package/dist/index.js
@@ -1,4 +1,5 @@
+import "@sanity/ui/styles.css";
 import { ArrayOfObjectsFunctions, DiffFromTo, PatchEvent, definePlugin, defineType, getPublishedId, insert, isArrayOfObjectsInputProps, set, setIfMissing, unset, useClient } from "sanity";
 import { c } from "react/compiler-runtime";
 import { PlugIcon } from "@sanity/icons/Plug";
 import { SettingsView, useSecrets } from "@sanity/studio-secrets";
Index: package/package.json
===================================================================
--- package/package.json
+++ package/package.json
@@ -1,7 +1,7 @@
 {
   "name": "sanity-plugin-cloudinary",
-  "version": "2.1.0",
+  "version": "2.1.1",
   "description": "Cloudinary integration for Sanity Studio.",
   "keywords": [
     "sanity",
     "sanity-plugin"
@@ -28,11 +28,11 @@
   },
   "dependencies": {
     "@cloudinary/url-gen": "^1.22.0",
     "@sanity/icons": "^5.2.1",
-    "@sanity/ui": "^3.5.1",
+    "@sanity/ui": "^4.0.0",
     "nanoid": "^6.0.0",
-    "@sanity/studio-secrets": "^4.0.15"
+    "@sanity/studio-secrets": "^4.0.16"
   },
   "devDependencies": {
     "@sanity/tsconfig": "^2.2.1",
     "@sanity/tsdown-config": "^0.21.2",
@@ -40,9 +40,9 @@
     "@types/react-dom": "^19.2.4",
     "babel-plugin-react-compiler": "^1.0.0",
     "react": "^19.2.8",
     "react-dom": "^19.2.8",
-    "sanity": "^6.7.0",
+    "sanity": "^6.9.0",
     "styled-components": "^6.4.4",
     "tsdown": "^0.22.14"
   },
   "peerDependencies": {
Index: package/dist/index.d.ts.map
===================================================================
--- package/dist/index.d.ts.map
+++ package/dist/index.d.ts.map
@@ -1,1 +1,1 @@
-{"version":3,"file":"index.d.ts","names":[],"sources":["../src/schema/cloudinaryAsset.ts","../src/schema/cloudinaryAssetContext.ts","../src/schema/cloudinaryAssetContextCustom.ts","../src/schema/cloudinaryAssetDerived.ts","../src/schema/cloudinaryAssetDocument.ts","../src/schema/cloudinaryAssetReference.ts","../src/types.ts","../src/index.ts"],"mappings":";cAMa;;;IAAA;;;;;KAAA;;UCJI;EACf;;cAGW;;;;;;KCJD;EACV;EACA;;cAGW;;;;;;KCLD;EACV;EACA;EACA;;cAGW;;;;;;cCJA;;;IAAA;;;;;;;;;;KAAA;;cCAA;;;IAAA;;;;;;;;;;KAAA;;UC8BI;EACf,OAAO;IAAU;IAAY;;EAC7B;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV;;KAGU;EACV;EACA;EACA;EACA;EACA;IACE;IACA;IACA;;EAEF;EACA;;QAGM;YACI;IAER;MACE,mBAAmB,aAAa;MAChC,qBAAqB,aAAa,oBAAoB;;;;cCjD/C,4CAAyB;cAczB,yCAAsB;cA2BtB,uBAAuB;cAQvB,8CAA2B"}
\ No newline at end of file
+{"version":3,"file":"index.d.ts","names":[],"sources":["../src/schema/cloudinaryAsset.ts","../src/schema/cloudinaryAssetContext.ts","../src/schema/cloudinaryAssetContextCustom.ts","../src/schema/cloudinaryAssetDerived.ts","../src/schema/cloudinaryAssetDocument.ts","../src/components/CloudinaryReferenceInput.tsx","../src/schema/cloudinaryAssetReference.ts","../src/types.ts","../src/index.ts"],"mappings":";;cAMa;;;;;;;;;;;;;;;;;;;;;;;MA4FP;MACA;MACA;;;;;;;;;;;;UClGW;EACf;;cAGW;;;;;;;;KCJD;EACV;EACA;;cAGW;;;;;;;;KCLD;EACV;EACA;EACA;;cAGW;;;;;;;;;;;cCJA;;;;;;;;;;;;MAgBP;MACA;MACA;MACA;MACA;MAEA;MACA;MACA;;uBAxBO;;;;;;;cCsBP,2BAAwB,OAAW,qCAAgB,IAAA;cCtB5C;;;;;;;;;;;;;IAaT,cAAK;;;;MAIH;MACA;MACA;MACA;MACA;MACA;MACA;MACA;;uBAXG;;;;;;;UCiBQ;EACf,OAAO;IAAU;IAAY;;EAC7B;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV;;KAGU;EACV;EACA;EACA;EACA;EACA;IACE;IACA;IACA;;EAEF;EACA;;QAGM;YACI;IAER;MACE,mBAAmB,aAAa;MAChC,qBAAqB,aAAa,oBAAoB;;;;cChD/C,4CAAyB;cAczB,yCAAsB;cA2BtB,uBAAuB;cAQvB,8CAA2B"}
\ No newline at end of file
Index: package/dist/index.js.map
===================================================================
--- package/dist/index.js.map
+++ package/dist/index.js.map
@@ -1,1 +1,1 @@
-{"version":3,"file":"index.js","names":["CloudConfig","CloudinaryImage","scale","CloudinaryAsset","CloudinaryAssetResponse","CloudinaryMediaLibrary","InsertHandlerParams","ShowHandlerParams","widgetSrc","assetUrl","asset","Partial","Pick","cloudName","derived","public_id","resource_type","type","resize","width","toURL","secure_url","url","normalizeCloudinaryAsset","Record","assetWithoutNulls","Object","fromEntries","entries","filter","_","assetValue","requiredFields","format","height","bytes","tags","updatedAsset","id","context","objectWithRenamedKeys","custom","map","contextKey","contextValue","replace","derivedItem","_type","raw_transformation","openMediaSelector","apiKey","multiple","insertHandler","params","selectedAsset","showHandler","folder","path","loadJS","cloudinary","options","cloud_name","api_key","insert_caption","callbacks","openMediaLibrary","createMediaLibrary","inlineContainer","libraryCreated","library","inline_container","remove_header","callback","NonNullable","Window","window","settled","handleLoad","existingScript","document","getElementById","addEventListener","once","script","createElement","src","body","appendChild","encodeSourceId","btoa","JSON","stringify","encodeFilename","split","slice","decodeSourceId","sourceId","sourceIdDecoded","parse","atob","SettingsView","Secrets","cloudName","apiKey","pluginConfigKeys","key","title","description","namespace","Props","onClose","SecretsConfigView","props","$","_c","t0","PlugIcon","useSecrets","Box","Button","Dialog","Flex","Spinner","Stack","Text","useCallback","useEffect","useRef","useState","AssetSourceComponentProps","ImageAsset","styled","CloudinaryMediaLibrary","InsertHandlerParams","createMediaLibrary","decodeSourceId","encodeFilename","encodeSourceId","SecretsConfigView","namespace","Secrets","Widget","div","CloudinaryAssetSource","props","$","_c","onClose","dialogHeaderTitle","loadingMessage","setLoadingMessage","library","undefined","contentRef","secrets","cloudName","apiKey","widgetId","_temp","showSettings","setShowSettings","propsRef","t0","t1","current","t2","hide","handleClose","t3","t4","inlineContainer","libraryCreated","lib","selectedAssets","firstSelectedAsset","iframe","firstChild","HTMLIFrameElement","asset","selectionType","source","id","folder","path","public_id","split","slice","join","resource_type","show","style","visibility","insertHandler","t5","assets","imageAssets","filter","_temp2","length","Error","onSelect","map","asset_1","url","derived","secure_url","kind","value","assetDocumentProps","_type","originalFilename","name","hasConfig","t6","t7","Symbol","for","t8","t9","t10","t11","t12","t13","t14","asset_0","Date","now","CloudinaryIcon","$","_c","t0","Symbol","for","CSSProperties","PlayerKind","VideoPlayerProps","src","kind","VideoPlayer","props","$","_c","t0","Symbol","for","width","height","style","t1","useSecrets","DiffFromTo","CloudinaryAsset","assetUrl","namespace","Secrets","VideoPlayer","Props","value","CloudinaryDiffPreview","t0","$","_c","secrets","cloudName","t1","url","resource_type","t2","Symbol","for","display","flexWrap","justifyContent","t3","maxWidth","height","DiffProps","diff","schemaType","AssetDiff","DocumentIcon","useSecrets","Flex","Text","CloudinaryAsset","assetUrl","namespace","Secrets","VideoPlayer","ComponentProps","layout","value","AssetPreview","t0","$","_c","secrets","cloudName","t1","Symbol","for","bb0","url","resource_type","t2","t3","maxWidth","marginLeft","t4","display_name","t5","previewSrc","format","replace","width","height","display","PlugIcon","Button","Flex","Grid","Stack","useCallback","ObjectInputProps","PatchEvent","unset","styled","CloudinaryAsset","AssetPreview","SetupButtonContainer","div","WidgetInputProps","openMediaSelector","onSetup","WidgetInput","props","$","_c","onChange","readOnly","value","t0","from","removeValue","t1","t2","Symbol","for","textAlign","width","t3","t4","t5","gridTemplateColumns","t6","t7","t8","t9","t10","useSecrets","nanoid","useCallback","useState","ObjectInputProps","PatchEvent","set","CloudinaryAsset","InsertHandlerParams","normalizeCloudinaryAsset","openMediaSelector","SecretsConfigView","namespace","Secrets","WidgetInput","CloudinaryInput","props","$","_c","showSettings","setShowSettings","secrets","onChange","schemaType","type","value","undefined","valueKey","_key","t0","payload","asset","assets","from","_type","name","_version","handleSelect","t1","cloudName","apiKey","action","t2","t3","Symbol","for","t4","t5","defineType","AssetDiff","AssetPreview","CloudinaryInput","cloudinaryAssetSchema","type","name","fields","of","components","input","diff","preview","select","url","resource_type","derived","prepare","title","value","PlugIcon","useSecrets","Box","Button","Flex","useCallback","useState","ArrayInputFunctionsProps","ArrayOfObjectsFunctions","ArraySchemaType","insert","ObjectSchemaType","PatchEvent","setIfMissing","cloudinaryAssetSchema","InsertHandlerParams","openMediaSelector","SecretsConfigView","namespace","ApiConfig","cloudName","apiKey","AssetListFunctions","props","$","_c","onValueCreate","onChange","secrets","loading","showSettings","setShowSettings","t0","Symbol","for","show","t1","hide","t2","schemaType","of","find","_temp","cloudinaryType","Error","name","map","_temp2","join","t3","selected","items","assets","asset","Object","assign","_version","from","handleSelect","t4","handleOpenSelector","t5","t6","t7","readOnly","width","t8","t","t_0","defineType","CloudinaryAssetContext","custom","cloudinaryAssetContext","type","name","fields","defineType","CloudinaryAssetContextCustom","alt","caption","cloudinaryAssetContextCustom","type","name","fields","defineType","CloudinaryAssetDerived","raw_transformation","url","secure_url","cloudinaryAssetDerivedSchema","type","name","fields","defineType","cloudinaryAssetSchema","cloudinaryAssetDocument","name","title","type","liveEdit","fields","preview","select","caption","alt","publicId","resourceType","format","secureUrl","url","derivedUrl","prepare","selection","formatInfo","subtitle","media","undefined","replace","useEffect","useState","useClient","CloudinaryAsset","AssetPreview","API_VERSION","ReferencePreviewProps","value","_ref","revision","ReferencePreview","props","$","_c","t0","undefined","t1","Symbol","for","apiVersion","client","ref","result","setResult","t2","t3","cancelled","getDocument","then","document","asset","catch","err","console","error","t4","PlugIcon","useSecrets","Button","Flex","Grid","Stack","nanoid","useCallback","useMemo","useRef","useState","ObjectInputProps","getPublishedId","PatchEvent","set","unset","useClient","cloudinaryAssetSchema","InsertHandlerParams","normalizeCloudinaryAsset","openMediaSelector","ReferencePreview","SecretsConfigView","namespace","Secrets","API_VERSION","SELECTOR_FALLBACK_TIMEOUT","FolderOption","path","resource_type","ReferenceValue","_key","_type","asset","_ref","_weak","CloudinaryReferenceInput","props","onChange","value","schemaType","readOnly","showSettings","setShowSettings","isLoading","setIsLoading","previewRevision","setPreviewRevision","fallbackTimerRef","ReturnType","setTimeout","undefined","saveInProgressRef","secrets","loading","secretsLoading","client","apiVersion","publishedClient","withConfig","perspective","cloudName","apiKey","hasConfig","Boolean","currentValue","valueKey","schemaTypeName","name","actionsDisabled","folder","options","folderOption","setAssetReference","documentId","from","handleSelect","payload","assets","normalizedAsset","Record","_version","current","ExistingAssetDoc","_id","id","existingAsset","fetch","public_id","publicId","resourceType","type","publishedId","assetToStore","patch","commit","newAsset","create","revision","err","console","error","handleOpenSelector","clearTimeout","reference","selectButtonText","textAlign","width","gridTemplateColumns","defineType","CloudinaryReferenceInput","cloudinaryAssetReference","name","title","type","fields","to","weak","components","input","preview","select","caption","alt","publicId","resourceType","format","secureUrl","url","derivedUrl","prepare","selection","formatInfo","subtitle","media","undefined","replace","AssetSource","definePlugin","isArrayOfObjectsInputProps","CloudinaryAssetSource","CloudinaryIcon","AssetListFunctions","cloudinaryAssetSchema","cloudinaryAssetContext","cloudinaryAssetContextCustom","cloudinaryAssetDerivedSchema","cloudinaryAssetDocument","cloudinaryAssetReference","CloudinaryAssetContext","CloudinaryAssetDerived","CloudinaryAssetContextCustom","AssetDocument","CloudinaryAsset","cloudinaryReferencePlugin","name","schema","types","cloudinarySchemaPlugin","form","components","input","props","cloudinaryType","schemaType","of","find","t","renderDefault","arrayFunctions","cloudinaryImageSource","title","icon","component","cloudinaryAssetSourcePlugin","image","assetSources"],"sources":["../src/utils.ts","../src/components/SecretsConfigView.tsx","../src/components/asset-source/CloudinaryAssetSource.tsx","../src/components/asset-source/Icon.tsx","../src/components/VideoPlayer.tsx","../src/components/AssetDiff.tsx","../src/components/AssetPreview.tsx","../src/components/WidgetInput.tsx","../src/components/CloudinaryInput.tsx","../src/schema/cloudinaryAsset.ts","../src/components/AssetListFunctions.tsx","../src/schema/cloudinaryAssetContext.ts","../src/schema/cloudinaryAssetContextCustom.ts","../src/schema/cloudinaryAssetDerived.ts","../src/schema/cloudinaryAssetDocument.ts","../src/components/ReferencePreview.tsx","../src/components/CloudinaryReferenceInput.tsx","../src/schema/cloudinaryAssetReference.ts","../src/index.ts"],"sourcesContent":["import {CloudConfig, CloudinaryImage} from '@cloudinary/url-gen'\nimport {scale} from '@cloudinary/url-gen/actions/resize'\n\nimport type {\n  CloudinaryAsset,\n  CloudinaryAssetResponse,\n  CloudinaryMediaLibrary,\n  InsertHandlerParams,\n  ShowHandlerParams,\n} from './types'\n\nconst widgetSrc = 'https://media-library.cloudinary.com/global/all.js'\n\nexport function assetUrl(\n  asset: Partial<\n    Pick<\n      CloudinaryAsset,\n      'url' | 'secure_url' | 'derived' | 'public_id' | 'format' | 'resource_type' | 'type'\n    >\n  >,\n  cloudName?: string,\n): string | undefined {\n  const [derived] = asset.derived ?? []\n\n  // When the cloud name and public id are known and there is no Media Library\n  // derived transform, build an on-the-fly preview with url-gen instead of\n  // serving the full-size original. Scaling to a 400px width keeps previews\n  // crisp while avoiding multi-megabyte source downloads.\n  // Only public `upload` images use CloudinaryImage — video/raw would get an\n  // /image/upload URL that breaks VideoPlayer/raw previews, and private or\n  // authenticated assets need their stored (often signed) URL rather than an\n  // unsigned /upload/ path. Derived transforms are preferred over the scaled\n  // original so Studio still shows the editor's chosen crop/effects.\n  if (\n    cloudName &&\n    asset.public_id &&\n    !derived &&\n    asset.resource_type !== 'video' &&\n    asset.resource_type !== 'raw' &&\n    (!asset.type || asset.type === 'upload')\n  ) {\n    return new CloudinaryImage(asset.public_id, new CloudConfig({cloudName}))\n      .resize(scale().width(400))\n      .toURL()\n  }\n\n  if (derived) {\n    if (derived.secure_url) {\n      return derived.secure_url\n    }\n    return derived.url\n  }\n  if (asset.secure_url) {\n    return asset.secure_url\n  }\n  return asset.url\n}\n\n/**\n * Normalize a Media Library payload into a shape that matches the `cloudinary.asset`\n * schema: drop nulls, sanitize context keys, and tag derived items with `_type`.\n */\nexport function normalizeCloudinaryAsset(asset: CloudinaryAssetResponse): Record<string, unknown> {\n  const assetWithoutNulls = Object.fromEntries(\n    Object.entries(asset).filter(([_, assetValue]) => assetValue !== null),\n  ) as CloudinaryAssetResponse\n\n  const requiredFields = {\n    public_id: asset.public_id,\n    resource_type: asset.resource_type,\n    type: asset.type,\n    url: asset.url,\n    secure_url: asset.secure_url,\n    format: asset.format,\n    width: asset.width,\n    height: asset.height,\n    bytes: asset.bytes,\n    tags: asset.tags,\n  }\n\n  let updatedAsset: Record<string, unknown> = {\n    ...assetWithoutNulls,\n    ...requiredFields,\n  }\n\n  // Only persist Cloudinary's asset id when the Media Library actually provides one.\n  // Do not delete a missing id here — callers that replace a whole asset object should\n  // preserve any previously stored id themselves (see CloudinaryReferenceInput).\n  if (asset.id) {\n    updatedAsset['id'] = asset.id\n  }\n\n  // Sanity object keys cannot contain special characters, so rename Cloudinary context keys\n  if (asset.context) {\n    const objectWithRenamedKeys = Object.fromEntries(\n      Object.entries(asset.context.custom).map(([contextKey, contextValue]) => {\n        return [contextKey.replace(/[^a-zA-Z0-9_]|-/g, '_'), contextValue]\n      }),\n    )\n\n    updatedAsset = {\n      ...updatedAsset,\n      context: {\n        ...asset.context,\n        custom: objectWithRenamedKeys,\n      },\n    }\n  }\n\n  if (asset.derived) {\n    updatedAsset = {\n      ...updatedAsset,\n      derived: asset.derived.map((derivedItem) => ({\n        _type: 'derived',\n        url: derivedItem.url,\n        secure_url: derivedItem.secure_url,\n        raw_transformation: derivedItem.raw_transformation,\n      })),\n    }\n  }\n\n  return updatedAsset\n}\n\nexport const openMediaSelector = (\n  cloudName: string,\n  apiKey: string,\n  multiple: boolean,\n  insertHandler: (params: InsertHandlerParams) => void,\n  selectedAsset?: CloudinaryAsset,\n  showHandler?: (params: ShowHandlerParams) => void,\n  folder?: {resource_type?: 'image' | 'video'; path?: string},\n) => {\n  loadJS(widgetSrc, (cloudinary) => {\n    const options: Record<string, any> = {\n      cloud_name: cloudName,\n      api_key: apiKey,\n      insert_caption: 'Select',\n      multiple,\n    }\n\n    if (selectedAsset) {\n      options['asset'] = {\n        public_id: selectedAsset.public_id,\n        type: selectedAsset.type,\n        resource_type: selectedAsset.resource_type,\n      }\n    }\n\n    if (folder?.path || folder?.resource_type) {\n      options['folder'] = {\n        ...(folder.path ? {path: folder.path} : {}),\n        ...(folder.resource_type ? {resource_type: folder.resource_type} : {}),\n      }\n    }\n\n    const callbacks: {\n      insertHandler: (params: InsertHandlerParams) => void\n      showHandler?: (params: ShowHandlerParams) => void\n    } = {insertHandler}\n\n    if (showHandler) {\n      callbacks.showHandler = showHandler\n    }\n\n    cloudinary.openMediaLibrary(options, callbacks)\n  })\n}\n\nexport const createMediaLibrary = ({\n  cloudName,\n  apiKey,\n  inlineContainer,\n  libraryCreated,\n  insertHandler,\n}: {\n  cloudName: string\n  apiKey: string\n  inlineContainer: string\n  libraryCreated: (library: CloudinaryMediaLibrary) => void\n  insertHandler: (params: InsertHandlerParams) => void\n}) => {\n  loadJS(widgetSrc, (cloudinary) => {\n    const options: Record<string, any> = {\n      cloud_name: cloudName,\n      api_key: apiKey,\n      insert_caption: 'Select',\n      inline_container: inlineContainer,\n      remove_header: true,\n    }\n\n    libraryCreated(cloudinary.createMediaLibrary(options, {insertHandler}))\n  })\n}\n\nfunction loadJS(url: string, callback: (cloudinary: NonNullable<Window['cloudinary']>) => void) {\n  // The widget exposes `window.cloudinary` only once the script has finished\n  // loading. When it's already available, run the callback right away.\n  if (window.cloudinary) {\n    callback(window.cloudinary)\n    return\n  }\n\n  // Guard against double-invocation if load fires in the same tick as the\n  // post-listener readiness re-check below.\n  let settled = false\n  const handleLoad = () => {\n    if (settled || !window.cloudinary) {\n      return\n    }\n    settled = true\n    callback(window.cloudinary)\n  }\n\n  const existingScript = document.getElementById('damWidget')\n  if (existingScript) {\n    // Another input already injected the script, but it hasn't finished\n    // loading yet (the global isn't ready). Wait for the load event instead\n    // of invoking the callback too early.\n    existingScript.addEventListener('load', handleLoad, {once: true})\n    // Re-check immediately: the load event may have fired between the initial\n    // `window.cloudinary` check and registering this listener, in which case\n    // the event will never fire again and the callback would otherwise hang.\n    handleLoad()\n    return\n  }\n\n  const script = document.createElement('script')\n  script.src = url\n  script.id = 'damWidget'\n  script.addEventListener('load', handleLoad, {once: true})\n  document.body.appendChild(script)\n}\n\nexport function encodeSourceId(asset: CloudinaryAssetResponse): string {\n  const {resource_type, public_id, type} = asset\n  return btoa(JSON.stringify({public_id, resource_type, type})) // Sort keys alphabetically!\n}\n\nexport function encodeFilename(asset: CloudinaryAssetResponse) {\n  return `${asset.public_id.split('/').slice(-1)[0]}.${asset.format}`\n}\n\nexport function decodeSourceId(sourceId: string): CloudinaryAssetResponse | undefined {\n  let sourceIdDecoded: any\n  try {\n    sourceIdDecoded = JSON.parse(atob(sourceId))\n  } catch {\n    // Do nothing\n  }\n  return sourceIdDecoded\n}\n","import {SettingsView} from '@sanity/studio-secrets'\n\nexport type Secrets = {\n  cloudName: string\n  apiKey: string\n}\n\nconst pluginConfigKeys = [\n  {\n    key: 'cloudName',\n    title: 'Cloud name',\n    description: '',\n  },\n  {\n    key: 'apiKey',\n    title: 'API key',\n    description: '',\n  },\n]\n\nexport const namespace = 'cloudinary'\n\ntype Props = {\n  onClose: () => void\n}\n\nconst SecretsConfigView = (props: Props) => {\n  return (\n    <SettingsView\n      title=\"Cloudinary config\"\n      namespace={namespace}\n      keys={pluginConfigKeys}\n      onClose={props.onClose}\n    />\n  )\n}\n\nexport default SecretsConfigView\n","import {PlugIcon} from '@sanity/icons/Plug'\nimport {useSecrets} from '@sanity/studio-secrets'\nimport {Box, Button, Dialog, Flex, Spinner, Stack, Text} from '@sanity/ui'\nimport {useCallback, useEffect, useRef, useState} from 'react'\nimport type {AssetSourceComponentProps, ImageAsset} from 'sanity'\nimport {styled} from 'styled-components'\n\nimport type {CloudinaryMediaLibrary, InsertHandlerParams} from '../../types'\nimport {createMediaLibrary, decodeSourceId, encodeFilename, encodeSourceId} from '../../utils'\nimport SecretsConfigView, {namespace, type Secrets} from '../SecretsConfigView'\n\nconst Widget = styled.div`\n  height: 70vh;\n`\n\nexport function CloudinaryAssetSource(props: AssetSourceComponentProps) {\n  const {onClose, dialogHeaderTitle} = props\n\n  const [loadingMessage, setLoadingMessage] = useState<string | undefined>(\n    'Loading Cloudinary Media Library',\n  )\n  const library = useRef<CloudinaryMediaLibrary | undefined>(undefined)\n  const contentRef = useRef<HTMLDivElement | null>(null)\n  const {secrets} = useSecrets<Secrets>(namespace)\n  const cloudName = secrets?.cloudName\n  const apiKey = secrets?.apiKey\n  const [widgetId] = useState(() => `cloudinaryWidget-${Date.now()}`)\n  const [showSettings, setShowSettings] = useState(false)\n\n  const propsRef = useRef(props)\n\n  useEffect(() => {\n    // because we have to access props after loading js in a callback,\n    // we cannot pass props as dependencies as that will cause infinite updates\n    // this takes a snapshot of props, so we can access them later\n    propsRef.current = props\n  }, [props])\n\n  const handleClose = useCallback(() => {\n    if (library.current) {\n      library.current.hide()\n    }\n    onClose()\n  }, [onClose, library])\n\n  useEffect(() => {\n    if (!cloudName || !apiKey) {\n      return\n    }\n\n    createMediaLibrary({\n      cloudName,\n      apiKey,\n      inlineContainer: `#${widgetId}`,\n      libraryCreated: (lib: CloudinaryMediaLibrary) => {\n        library.current = lib\n        const selectedAssets = propsRef.current.selectedAssets\n        const firstSelectedAsset = selectedAssets ? selectedAssets[0] : null\n\n        const iframe: ChildNode | null | undefined =\n          contentRef.current && contentRef.current.firstChild\n        if (iframe && iframe instanceof HTMLIFrameElement) {\n          setLoadingMessage(undefined)\n          let asset\n          if (\n            propsRef.current.selectionType === 'single' &&\n            firstSelectedAsset &&\n            firstSelectedAsset.source &&\n            firstSelectedAsset.source.id\n          ) {\n            asset = decodeSourceId(firstSelectedAsset.source.id)\n          }\n          const folder = asset\n            ? {\n                path: asset.public_id.split('/').slice(0, -1).join('/'),\n                resource_type: 'image',\n              }\n            : {path: '', resource_type: 'image'}\n          if (lib && contentRef.current) {\n            lib.show({folder, asset})\n            contentRef.current.style.visibility = 'visible'\n          }\n        }\n      },\n      insertHandler: ({assets}: InsertHandlerParams) => {\n        if (!library.current) {\n          return\n        }\n        const imageAssets = assets.filter((asset) => asset.resource_type === 'image')\n        if (imageAssets.length === 0) {\n          throw new Error('The selection did not contain any images.')\n        }\n        library.current.hide()\n        propsRef.current.onSelect(\n          imageAssets.map((asset) => {\n            const url =\n              asset.derived && asset.derived[0] ? asset.derived[0].secure_url : asset.secure_url\n            return {\n              kind: 'url',\n              value: url,\n              assetDocumentProps: {\n                _type: 'sanity.imageAsset',\n                originalFilename: encodeFilename(asset),\n                source: {\n                  id: encodeSourceId(asset),\n                  name: `cloudinary:${cloudName}`,\n                },\n              } as ImageAsset,\n            }\n          }),\n        )\n      },\n    })\n  }, [cloudName, apiKey, widgetId])\n\n  const hasConfig = apiKey && cloudName\n  return (\n    <Dialog\n      id=\"cloudinary-asset-source\"\n      header={dialogHeaderTitle ?? 'Select image from Cloudinary'}\n      onClose={handleClose}\n      open\n      width={4}\n    >\n      <Box padding={4}>\n        {showSettings && <SecretsConfigView onClose={() => setShowSettings(false)} />}\n        <Flex flex={1} justify=\"flex-end\">\n          <Button\n            color=\"primary\"\n            icon={PlugIcon}\n            mode=\"bleed\"\n            title=\"Configure\"\n            onClick={() => setShowSettings(true)}\n            tabIndex={0}\n            text={hasConfig ? undefined : 'Configure Cloudinary plugin'}\n          />\n        </Flex>\n\n        {hasConfig && loadingMessage && (\n          <Stack gap={3}>\n            <Flex align=\"center\" justify=\"center\">\n              <Spinner muted />\n            </Flex>\n            <Text size={1} muted align=\"center\">\n              {loadingMessage}\n            </Text>\n          </Stack>\n        )}\n\n        <Widget style={{visibility: 'hidden'}} ref={contentRef} id={widgetId} />\n      </Box>\n    </Dialog>\n  )\n}\n","export function CloudinaryIcon() {\n  return (\n    <svg\n      version=\"1.1\"\n      id=\"Layer_1\"\n      x=\"0px\"\n      y=\"0px\"\n      width=\"1em\"\n      height=\"1em\"\n      viewBox=\"0 0 141.732 141.747\"\n      enableBackground=\"new 0 0 141.732 141.747\"\n    >\n      <g>\n        <path\n          fill=\"#0071CE\"\n          d=\"M115.585,109.242c-1.609,0-3.107-1.024-3.635-2.637c-0.657-2.008,0.438-4.169,2.447-4.826\n        c7.278-2.382,11.98-8.761,11.98-16.252c0-9.487-7.718-17.206-17.205-17.206c-0.659,0-1.368,0.052-2.231,0.164l-3.741,0.485\n        l-0.537-3.735c-2.299-16.016-16.251-28.094-32.454-28.094c-13.395,0-25.32,8.019-30.377,20.43l-0.952,2.335l-2.52,0.046\n        c-11.581,0.213-21.003,9.804-21.003,21.379c0,8.45,4.906,16.156,12.498,19.631c1.921,0.88,2.766,3.15,1.886,5.071\n        c-0.88,1.921-3.149,2.764-5.07,1.887C14.363,103.202,7.703,92.766,7.703,81.331c0-14.88,11.465-27.345,26.028-28.876\n        c6.71-14.03,20.773-22.965,36.477-22.965c18.796,0,35.135,13.178,39.372,31.184c13.519,0.219,24.45,11.284,24.45,24.854\n        c0,10.693-6.934,20.146-17.253,23.523C116.382,109.18,115.98,109.242,115.585,109.242z\"\n        />\n        <path\n          fill=\"#DC8327\"\n          d=\"M57.12,111.02c-0.001-0.001-0.001-0.001-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001\n        c0,0-0.001-0.001-0.001-0.001l-0.001-0.001c0,0-0.001,0-0.001-0.001h-0.001l-0.001-0.001c0.001-0.001-0.001-0.001-0.001-0.001\n        l-0.001-0.001c0,0-0.001,0-0.001,0l-0.001-0.001c0.001,0.001-0.001-0.001-0.001-0.001s-0.002-0.001-0.003-0.001l-0.001-0.001H57.1\n        c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001c-0.003-0.001-0.002-0.001-0.003-0.001c-0.001,0.001-0.001-0.001-0.002-0.001\n        l-0.001-0.001c0,0-0.001-0.001-0.002-0.001l-0.001-0.001c-0.001-0.001-0.003-0.001-0.004-0.001s-0.003-0.001-0.004-0.001\n        c-0.001-0.001-0.001-0.001-0.002-0.001h-0.001c-0.001-0.001-0.002-0.001-0.003-0.001c-0.001-0.001-0.003-0.001-0.003-0.001\n        c-0.001,0-0.001,0-0.001,0l-0.002-0.001c-0.001,0-0.001-0.001-0.001-0.001h-0.001c-0.059-0.021-0.122-0.034-0.188-0.037h-0.002\n        h-0.002c-0.001,0-0.001,0-0.002,0c0,0,0,0-0.001,0c0,0-0.001,0-0.001,0h-0.001c-0.001-0.001-0.001-0.001-0.001-0.001\n        c-0.001,0-0.002,0-0.002,0c-0.001,0-0.002,0-0.002,0h-0.001h-0.001h-0.001c-0.001,0-0.002,0-0.002,0h-0.001H56.86h-0.001h-0.001\n        c-0.001,0-0.001,0-0.001,0h-0.001h-0.001h-0.001h-0.001c-0.001,0-0.001,0-0.001,0c-1.656,0-3.011-1.348-3.021-3V74.29h2.567\n        c0.004,0,0.009,0,0.013,0c0.393,0.017,0.661-0.285,0.661-0.648c0-0.271-0.166-0.503-0.402-0.6l-12.379-8.544\n        c-0.222-0.153-0.515-0.153-0.737,0l-12.476,8.611c-0.234,0.161-0.335,0.456-0.251,0.727c0.085,0.271,0.335,0.455,0.619,0.455h2.58\n        l0.002,33.674c0.013,2.328,1.883,4.228,4.262,4.288c0.027,0.003,0.053,0.005,0.08,0.005h18.481c0.004,0,0.007,0,0.011,0\n        c0.17-0.003,0.324-0.071,0.438-0.18c0,0,0,0,0.001-0.001c0.002-0.002,0.004-0.004,0.005-0.005c0.001-0.001,0.002-0.001,0.003-0.003\n        c0,0,0.001-0.001,0.001-0.001l0.001-0.001l0.001-0.001l0.001-0.001l0.001-0.001c0.001-0.001,0.001-0.001,0.001-0.001\n        c0.002-0.001,0.001-0.001,0.002-0.002c0,0,0,0,0.001-0.001l0.001-0.001c0,0,0,0,0.001-0.001c0.112-0.116,0.182-0.273,0.183-0.447\n        v-0.002v-0.001v-0.001v-0.001v-0.001v-0.001v-0.001v-0.002C57.498,111.345,57.343,111.121,57.12,111.02z\"\n        />\n        <path\n          fill=\"#F4B21B\"\n          d=\"M83.889,111.02c0,0-0.001-0.001-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001\n        c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001h-0.001c0,0-0.001-0.001-0.001-0.001c0,0-0.001-0.001-0.001-0.001\n        c0.001-0.001-0.001-0.001-0.002-0.001l-0.001-0.001h-0.001c-0.001,0-0.001-0.001-0.001-0.001c-0.002,0.001-0.002-0.001-0.002-0.001\n        l-0.002-0.001l-0.001-0.001h-0.001c0,0-0.001-0.001-0.001-0.001l-0.001-0.001c-0.001-0.001-0.002-0.001-0.002-0.001\n        c-0.001,0.001-0.001-0.001-0.003-0.001l-0.001-0.001l-0.001-0.001c0,0-0.001,0-0.002-0.001c-0.001-0.001-0.003-0.001-0.004-0.001\n        s-0.003-0.001-0.004-0.001c-0.001-0.001-0.001-0.001-0.002-0.001c-0.001,0-0.001,0-0.002-0.001c0,0-0.001,0-0.002-0.001\n        c-0.003-0.001-0.001-0.001-0.002-0.001c-0.003,0-0.001,0-0.002-0.001c0,0-0.001-0.001-0.002-0.001l-0.001-0.001h-0.001\n        c-0.059-0.021-0.122-0.034-0.188-0.037h-0.002c-0.001,0-0.001,0-0.001,0c-0.001,0-0.002,0-0.002,0s-0.001,0-0.001,0h-0.001h-0.001\n        l-0.001-0.001c-0.001,0-0.002,0-0.002,0c-0.001,0-0.002,0-0.002,0h-0.001c-0.001,0-0.001,0-0.001,0h-0.001\n        c-0.001,0-0.002,0-0.002,0s-0.001,0-0.002,0h-0.001c0,0-0.001,0-0.001,0h-0.001c-0.001,0-0.001,0-0.001,0h-0.001h-0.001h-0.001\n        h-0.001c-0.001,0-0.001,0-0.001,0c-1.655,0-3.01-1.348-3.02-3V81.829h2.579c0.009-0.001,0.016-0.001,0.026,0\n        c0.358,0,0.648-0.29,0.648-0.648c0-0.271-0.166-0.503-0.402-0.6l-12.38-8.544c-0.222-0.153-0.515-0.153-0.737,0L57.86,80.647\n        c-0.234,0.161-0.335,0.456-0.251,0.727c0.085,0.271,0.335,0.455,0.619,0.455h2.568l0.002,26.135\n        c0.011,2.329,1.884,4.23,4.264,4.289c0.026,0.003,0.052,0.004,0.078,0.004h18.481c0.004,0,0.007,0,0.011,0\n        c0.17-0.003,0.324-0.071,0.438-0.18c0,0,0,0,0.001-0.001c0.002-0.002,0.006-0.004,0.005-0.005c0.001-0.001,0.002-0.001,0.003-0.003\n        c0.001-0.001,0.001-0.001,0.001-0.001l0.001-0.001l0.001-0.001c0,0,0.001,0,0.001-0.001l0.001-0.001\n        c0.001,0,0.001-0.001,0.001-0.001c0.003-0.001,0.002-0.001,0.002-0.002c0,0,0,0,0.001-0.001c0,0,0,0,0.001-0.001\n        c0,0,0,0,0.001-0.001c0.112-0.116,0.182-0.273,0.183-0.447v-0.002v-0.001v-0.001v-0.001v-0.001v-0.001v-0.001v-0.002\n        C84.267,111.345,84.112,111.121,83.889,111.02z\"\n        />\n        <path\n          fill=\"#F2D864\"\n          d=\"M110.667,111.02l-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001\n        c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001c-0.001,0-0.001,0-0.001-0.001h-0.001l-0.001-0.001\n        c-0.001-0.001-0.001-0.001-0.001-0.001s-0.001,0-0.001-0.001h-0.001c0,0-0.001-0.001-0.001-0.001\n        c-0.001,0.001-0.001-0.001-0.002-0.001c0.001-0.001-0.001-0.001-0.002-0.001l-0.001-0.001c-0.001,0-0.001,0-0.001,0\n        c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001c-0.003-0.001-0.002-0.001-0.002-0.001c-0.001,0.001-0.001-0.001-0.003-0.001\n        l-0.001-0.001c0.001-0.001-0.001-0.001-0.002-0.001c0,0-0.001,0-0.001-0.001c-0.001-0.001-0.003-0.001-0.004-0.001\n        s-0.003-0.001-0.004-0.001l-0.002-0.001c0,0-0.001,0-0.002-0.001l-0.002-0.001c-0.003-0.001-0.003-0.001-0.002-0.001\n        c-0.003,0-0.003,0-0.002-0.001c-0.001,0-0.001-0.001-0.001-0.001c-0.001,0-0.002-0.001-0.002-0.001h-0.001\n        c-0.059-0.021-0.122-0.034-0.188-0.037h-0.001c-0.001,0-0.002,0-0.002,0c-0.001,0-0.002,0-0.003,0h-0.001h-0.001h-0.001\n        c-0.001-0.001-0.001-0.001-0.002-0.001c0,0-0.001,0-0.002,0c0,0-0.001,0-0.002,0h-0.001c0,0-0.001,0-0.001,0h-0.001\n        c-0.001,0-0.002,0-0.002,0h-0.002c0,0,0,0-0.001,0c0,0-0.001,0-0.001,0h-0.001c0,0-0.001,0-0.001,0h-0.001h-0.001h-0.001H110.4\n        c0,0-0.001,0-0.001,0c-1.655,0-3.01-1.348-3.02-3V89.365h2.573c0.004,0,0.009,0,0.013,0c0.365-0.009,0.661-0.285,0.661-0.648\n        c0-0.271-0.166-0.503-0.402-0.6l-12.38-8.544c-0.221-0.153-0.515-0.153-0.737,0l-12.476,8.61c-0.234,0.161-0.335,0.456-0.251,0.727\n        c0.085,0.271,0.335,0.455,0.619,0.455h2.573l0.002,18.599c0.013,2.329,1.885,4.231,4.264,4.289\n        c0.026,0.003,0.052,0.004,0.078,0.004h18.481c0.004,0,0.007,0,0.011,0c0.17-0.003,0.324-0.071,0.438-0.18l0.001-0.001\n        c0.002-0.002,0.005-0.004,0.005-0.005c0.001-0.001,0.002-0.001,0.003-0.003c0,0,0.001-0.001,0.001-0.001l0.001-0.001l0.001-0.001\n        l0.001-0.001l0.001-0.001l0.001-0.001c0.003-0.001,0.001-0.001,0.002-0.002c0,0,0,0,0.001-0.001l0.001-0.001c0,0,0,0,0.001-0.001\n        c0.112-0.116,0.182-0.273,0.183-0.447v-0.002v-0.001v-0.001v-0.001v-0.001v-0.001v-0.001v-0.002\n        C111.045,111.345,110.889,111.121,110.667,111.02z\"\n        />\n      </g>\n    </svg>\n  )\n}\n","import type {CSSProperties} from 'react'\n\ntype PlayerKind = 'player' | 'diff'\n\nexport type VideoPlayerProps = {\n  src: string\n  kind: PlayerKind\n}\n\nexport default function VideoPlayer(props: VideoPlayerProps) {\n  const {src} = props\n\n  const style: CSSProperties = {\n    width: '100%',\n    height: 'auto',\n  }\n\n  return (\n    // Cloudinary videos are user-uploaded and have no caption files to point a\n    // `<track>` at; a `src`-less `<track>` would be invalid HTML, so omit it.\n    // eslint-disable-next-line jsx-a11y/media-has-caption -- no captions available for arbitrary Cloudinary videos\n    <video controls aria-label=\"Cloudinary video preview\" style={style}>\n      <source src={src} type=\"video/mp4\" />\n    </video>\n  )\n}\n","import {useSecrets} from '@sanity/studio-secrets'\nimport {DiffFromTo} from 'sanity'\n\nimport type {CloudinaryAsset} from '../types'\nimport {assetUrl} from '../utils'\nimport {namespace, type Secrets} from './SecretsConfigView'\nimport VideoPlayer from './VideoPlayer'\n\ntype Props = {\n  value: CloudinaryAsset | undefined\n}\n\nconst CloudinaryDiffPreview = ({value}: Props) => {\n  const {secrets} = useSecrets<Secrets>(namespace)\n  const cloudName = secrets?.cloudName\n\n  if (!value) {\n    return null\n  }\n\n  const url = assetUrl(value, cloudName)\n\n  if (value.resource_type === 'video' && url) {\n    return (\n      <section\n        style={{\n          display: 'flex',\n          flexWrap: 'wrap',\n          justifyContent: 'space-between',\n        }}\n      >\n        <VideoPlayer src={url} kind=\"diff\" />\n      </section>\n    )\n  }\n\n  return <img alt=\"preview\" src={url} style={{maxWidth: '100%', height: 'auto'}} />\n}\n\ntype DiffProps = {\n  diff: any\n  schemaType: any\n}\n\nconst AssetDiff = ({diff, schemaType}: DiffProps) => {\n  return <DiffFromTo diff={diff} schemaType={schemaType} previewComponent={CloudinaryDiffPreview} />\n}\n\nexport default AssetDiff\n","import {DocumentIcon} from '@sanity/icons/Document'\nimport {useSecrets} from '@sanity/studio-secrets'\nimport {Flex, Text} from '@sanity/ui'\n\nimport type {CloudinaryAsset} from '../types'\nimport {assetUrl} from '../utils'\nimport {namespace, type Secrets} from './SecretsConfigView'\nimport VideoPlayer from './VideoPlayer'\n\ninterface ComponentProps {\n  layout?: 'default' | 'block'\n  value: CloudinaryAsset | undefined\n}\n\nconst AssetPreview = ({value, layout}: ComponentProps) => {\n  const {secrets} = useSecrets<Secrets>(namespace)\n  const cloudName = secrets?.cloudName\n\n  if (!value || !cloudName) {\n    return null\n  }\n\n  const url = assetUrl(value, cloudName)\n  if (!url) {\n    return null\n  }\n\n  switch (value.resource_type) {\n    case 'video':\n      return (\n        <Flex\n          align=\"center\"\n          style={{\n            maxWidth: layout === 'default' ? '80px' : '100%',\n          }}\n        >\n          <VideoPlayer src={url} kind=\"player\" />\n        </Flex>\n      )\n    case 'raw':\n      return (\n        <Flex align=\"center\">\n          <DocumentIcon />\n          <Text size={1} style={{marginLeft: '0.5em'}}>\n            {value.display_name ?? 'Raw file'}\n          </Text>\n        </Flex>\n      )\n    default: {\n      // Cloudinary returns resource_type as \"image\" even for PDFs, so we check\n      // the format to handle PDFs specifically: convert the first page to JPG\n      // and overlay a \"PDF\" label for thumbnail clarity.\n      const previewSrc =\n        value.format === 'pdf'\n          ? url.replace(\n              'image/upload',\n              'image/upload/f_jpg,pg_1,l_text:Verdana_75_letter_spacing_14:PDF',\n            )\n          : url\n\n      return layout === 'default' ? (\n        <Flex align=\"center\" justify=\"center\" style={{width: '100%'}}>\n          <img\n            alt=\"preview\"\n            src={previewSrc}\n            style={{maxWidth: '80px', height: 'auto', display: 'block'}}\n          />\n        </Flex>\n      ) : (\n        <div style={{width: '100%'}}>\n          <img\n            alt=\"preview\"\n            src={previewSrc}\n            style={{width: '100%', height: 'auto', display: 'block'}}\n          />\n        </div>\n      )\n    }\n  }\n}\n\nexport default AssetPreview\n","import {PlugIcon} from '@sanity/icons/Plug'\nimport {Button, Flex, Grid, Stack} from '@sanity/ui'\nimport {useCallback} from 'react'\nimport {type ObjectInputProps, PatchEvent, unset} from 'sanity'\nimport {styled} from 'styled-components'\n\nimport type {CloudinaryAsset} from '../types'\nimport AssetPreview from './AssetPreview'\n\nconst SetupButtonContainer = styled.div`\n  position: relative;\n  display: block;\n  font-size: 0.8em;\n  transform: translate(0%, -10%);\n`\n\ntype WidgetInputProps = ObjectInputProps & {openMediaSelector: () => void; onSetup: () => void}\n\nconst WidgetInput = (props: WidgetInputProps) => {\n  const {onChange, readOnly, value, openMediaSelector} = props\n\n  const removeValue = useCallback(() => {\n    onChange(PatchEvent.from([unset()]))\n  }, [onChange])\n\n  return (\n    <Stack>\n      <SetupButtonContainer>\n        <Flex flex={1} justify=\"flex-end\">\n          <Button\n            color=\"primary\"\n            icon={PlugIcon}\n            mode=\"bleed\"\n            title=\"Configure\"\n            onClick={props.onSetup}\n            tabIndex={0}\n          />\n        </Flex>\n      </SetupButtonContainer>\n\n      <Flex style={{textAlign: 'center', width: '100%'}} marginBottom={2}>\n        <AssetPreview value={value as CloudinaryAsset} />\n      </Flex>\n\n      <Grid gap={1} style={{gridTemplateColumns: 'repeat(auto-fit, minmax(100px, 1fr))'}}>\n        <Button\n          disabled={readOnly}\n          mode=\"ghost\"\n          title=\"Select an asset\"\n          tone=\"default\"\n          onClick={openMediaSelector}\n          text=\"Select…\"\n        />\n        <Button\n          disabled={readOnly || !value}\n          tone=\"critical\"\n          mode=\"ghost\"\n          title=\"Remove asset\"\n          text=\"Remove\"\n          onClick={removeValue}\n        />\n      </Grid>\n    </Stack>\n  )\n}\n\nexport default WidgetInput\n","import {useSecrets} from '@sanity/studio-secrets'\nimport {nanoid} from 'nanoid'\nimport {useCallback, useState} from 'react'\nimport {type ObjectInputProps, PatchEvent, set} from 'sanity'\n\nimport type {CloudinaryAsset, InsertHandlerParams} from '../types'\nimport {normalizeCloudinaryAsset, openMediaSelector} from '../utils'\nimport SecretsConfigView, {namespace, type Secrets} from './SecretsConfigView'\nimport WidgetInput from './WidgetInput'\n\nconst CloudinaryInput = (props: ObjectInputProps) => {\n  const [showSettings, setShowSettings] = useState(false)\n  const {secrets} = useSecrets<Secrets>(namespace)\n  const {onChange, schemaType: type} = props\n  const value = (props.value as CloudinaryAsset) || undefined\n  const valueKey = value?._key\n\n  const handleSelect = useCallback(\n    (payload: InsertHandlerParams) => {\n      const [asset] = payload.assets\n\n      if (!asset) {\n        return\n      }\n\n      onChange(\n        PatchEvent.from([\n          set({\n            _type: type.name,\n            _version: 1,\n            _key: valueKey || nanoid(),\n            ...normalizeCloudinaryAsset(asset),\n          }),\n        ]),\n      )\n    },\n    [onChange, type, valueKey],\n  )\n\n  const action = secrets\n    ? () =>\n        openMediaSelector(\n          secrets.cloudName,\n          secrets.apiKey,\n          false, // single selection\n          handleSelect,\n          value,\n        )\n    : () => setShowSettings(true)\n\n  return (\n    <>\n      {showSettings && <SecretsConfigView onClose={() => setShowSettings(false)} />}\n      <WidgetInput onSetup={() => setShowSettings(true)} openMediaSelector={action} {...props} />\n    </>\n  )\n}\n\nexport default CloudinaryInput\n","import {defineType} from 'sanity'\n\nimport AssetDiff from '../components/AssetDiff'\nimport AssetPreview from '../components/AssetPreview'\nimport CloudinaryInput from '../components/CloudinaryInput'\n\nexport const cloudinaryAssetSchema = defineType({\n  type: 'object',\n  name: 'cloudinary.asset',\n  fields: [\n    {\n      type: 'string',\n      name: 'id',\n      // Cloudinary asset id (used by cloudinaryAssetDocument lookups)\n    },\n    {\n      type: 'string',\n      name: 'public_id',\n    },\n    {\n      type: 'string',\n      name: 'resource_type',\n      // \"image\", \"?\"\n    },\n    {\n      type: 'string',\n      name: 'type',\n      // \"upload\", \"?\"\n    },\n    {\n      type: 'string',\n      name: 'format',\n      // \"jpg\"\n    },\n    {\n      type: 'number',\n      name: 'version',\n    },\n    {\n      type: 'url',\n      name: 'url',\n    },\n    {\n      type: 'url',\n      name: 'secure_url',\n    },\n    {\n      type: 'number',\n      name: 'width',\n    },\n    {\n      type: 'number',\n      name: 'height',\n    },\n    {\n      type: 'number',\n      name: 'bytes',\n    },\n    {\n      type: 'number',\n      name: 'duration',\n      // can be null\n    },\n    {\n      type: 'array',\n      name: 'tags',\n      of: [{type: 'string'}],\n    },\n    {\n      type: 'datetime',\n      name: 'created_at',\n    },\n    {\n      type: 'array',\n      name: 'derived',\n      of: [{type: 'cloudinary.assetDerived', name: 'derived'}],\n    },\n    {\n      type: 'string',\n      name: 'access_mode',\n    },\n    {\n      type: 'cloudinary.assetContext',\n      name: 'context',\n    },\n    // metadata array of unknown content\n  ],\n  // The custom preview component receives legacy props that don't match the\n  // PreviewProps type, so the components block is widened to keep type checking happy.\n  ...({\n    components: {\n      input: CloudinaryInput,\n      diff: AssetDiff,\n      preview: AssetPreview,\n    },\n  } as {}),\n  preview: {\n    select: {\n      url: 'url',\n      resource_type: 'resource_type',\n      derived: 'derived.0.url',\n    },\n    prepare({url, derived, resource_type}) {\n      return {\n        title: url,\n        value: {\n          title: url,\n          resource_type,\n          url: derived || url,\n        },\n      }\n    },\n  },\n})\n","import {PlugIcon} from '@sanity/icons/Plug'\nimport {useSecrets} from '@sanity/studio-secrets'\nimport {Box, Button, Flex} from '@sanity/ui'\nimport {useCallback, useState} from 'react'\nimport {\n  type ArrayInputFunctionsProps,\n  ArrayOfObjectsFunctions,\n  type ArraySchemaType,\n  insert,\n  type ObjectSchemaType,\n  PatchEvent,\n  setIfMissing,\n} from 'sanity'\n\nimport {cloudinaryAssetSchema} from '../schema/cloudinaryAsset'\nimport type {InsertHandlerParams} from '../types'\nimport {openMediaSelector} from '../utils'\nimport SecretsConfigView, {namespace} from './SecretsConfigView'\n\ninterface ApiConfig {\n  cloudName: string\n  apiKey: string\n}\n\nexport const AssetListFunctions = (\n  props: ArrayInputFunctionsProps<{_key: string}, ArraySchemaType>,\n) => {\n  const {onValueCreate, onChange} = props\n\n  const {secrets, loading} = useSecrets<ApiConfig>(namespace)\n  const [showSettings, setShowSettings] = useState(false)\n\n  const show = useCallback(() => setShowSettings(true), [setShowSettings])\n  const hide = useCallback(() => setShowSettings(false), [setShowSettings])\n\n  const cloudinaryType = props.schemaType.of.find(\n    (t: {name: string}) => t.name === cloudinaryAssetSchema.name,\n  ) as ObjectSchemaType | undefined\n\n  if (!cloudinaryType) {\n    throw new Error(`AssetListFunctions can only be used in array.of ${\n      cloudinaryAssetSchema.name\n    }, but it was array.of\n    ${props.schemaType.of.map((t) => t.name).join(', ')}`)\n  }\n\n  const handleSelect = useCallback(\n    (selected: InsertHandlerParams) => {\n      const items = selected.assets.map((asset) =>\n        Object.assign(\n          {},\n          asset,\n          {\n            // Schema version. In case we ever change our schema.\n            _version: 1,\n          },\n          onValueCreate(cloudinaryType as any), // onValueCreate is mistyped\n        ),\n      )\n      onChange(PatchEvent.from([setIfMissing([]), insert(items, 'after', [-1])]))\n    },\n    [onValueCreate, onChange, cloudinaryType],\n  )\n\n  const handleOpenSelector = useCallback(\n    () =>\n      secrets &&\n      openMediaSelector(\n        secrets.cloudName,\n        secrets.apiKey,\n        true, // multi-selection\n        handleSelect,\n      ),\n    [secrets, handleSelect],\n  )\n  return (\n    <Flex gap={2} flex={1}>\n      {showSettings && <SecretsConfigView onClose={hide} />}\n      <Box flex={1}>\n        <ArrayOfObjectsFunctions {...props} />\n      </Box>\n      {cloudinaryType && (\n        <>\n          <Box flex={1}>\n            <Button\n              style={{width: '100%'}}\n              disabled={props.readOnly || loading}\n              mode=\"bleed\"\n              text=\"Add multiple\"\n              onClick={handleOpenSelector}\n            />\n          </Box>\n          <Box>\n            <Button onClick={show} icon={PlugIcon} mode=\"bleed\" title={'Configure'} />\n          </Box>\n        </>\n      )}\n    </Flex>\n  )\n}\n","import {defineType} from 'sanity'\n\nexport interface CloudinaryAssetContext {\n  custom: object\n}\n\nexport const cloudinaryAssetContext = defineType({\n  type: 'object',\n  name: 'cloudinary.assetContext',\n  fields: [\n    {\n      type: 'cloudinary.assetContextCustom',\n      name: 'custom',\n    },\n  ],\n})\n","import {defineType} from 'sanity'\n\nexport type CloudinaryAssetContextCustom = {\n  alt: string\n  caption: string\n}\n\nexport const cloudinaryAssetContextCustom = defineType({\n  type: 'object',\n  name: 'cloudinary.assetContextCustom',\n  fields: [\n    {\n      type: 'string',\n      name: 'alt',\n    },\n    {\n      type: 'string',\n      name: 'caption',\n    },\n  ],\n})\n","import {defineType} from 'sanity'\n\nexport type CloudinaryAssetDerived = {\n  raw_transformation: string\n  url: string\n  secure_url: string\n}\n\nexport const cloudinaryAssetDerivedSchema = defineType({\n  type: 'object',\n  name: 'cloudinary.assetDerived',\n  fields: [\n    {\n      type: 'string',\n      name: 'raw_transformation',\n    },\n    {\n      type: 'url',\n      name: 'url',\n    },\n    {\n      type: 'url',\n      name: 'secure_url',\n    },\n  ],\n})\n","import {defineType} from 'sanity'\n\nimport {cloudinaryAssetSchema} from './cloudinaryAsset'\n\nexport const cloudinaryAssetDocument = defineType({\n  name: 'cloudinaryAssetDocument',\n  title: 'Cloudinary Asset',\n  type: 'document',\n  // Shared assets are patched in place by the reference input; liveEdit avoids\n  // desk drafts that could later publish over those updates.\n  liveEdit: true,\n  fields: [\n    {\n      name: 'asset',\n      type: cloudinaryAssetSchema.name,\n      title: 'Cloudinary Asset',\n    },\n  ],\n  preview: {\n    select: {\n      caption: 'asset.context.custom.caption',\n      alt: 'asset.context.custom.alt',\n      publicId: 'asset.public_id',\n      resourceType: 'asset.resource_type',\n      format: 'asset.format',\n      // Desk list `media` needs a URL (or React element), not the raw asset object\n      secureUrl: 'asset.secure_url',\n      url: 'asset.url',\n      derivedUrl: 'asset.derived.0.secure_url',\n    },\n    prepare(selection) {\n      const {caption, alt, publicId, resourceType, format, secureUrl, url, derivedUrl} =\n        selection as {\n          caption?: string\n          alt?: string\n          publicId?: string\n          resourceType?: string\n          format?: string\n          secureUrl?: string\n          url?: string\n          derivedUrl?: string\n        }\n\n      // Prefer caption/alt from Cloudinary context; fall back to public_id\n      const title = caption || alt || publicId || 'Untitled Asset'\n\n      const type = resourceType || 'image'\n      const formatInfo = format ? `(${format})` : ''\n      const subtitle = `${type} ${formatInfo}`\n\n      let media = derivedUrl || secureUrl || url\n      // Desk/list media is rendered as an <img>; only pass image (and PDF) URLs\n      if (type !== 'image' || !media) {\n        media = undefined\n      } else if (format === 'pdf') {\n        media = media.replace(\n          'image/upload',\n          'image/upload/f_jpg,pg_1,l_text:Verdana_75_letter_spacing_14:PDF',\n        )\n      }\n\n      return {\n        title,\n        subtitle,\n        media,\n      }\n    },\n  },\n})\n","import {useEffect, useState} from 'react'\nimport {useClient} from 'sanity'\n\nimport type {CloudinaryAsset} from '../types'\nimport AssetPreview from './AssetPreview'\n\nconst API_VERSION = '2023-01-01'\n\ninterface ReferencePreviewProps {\n  value?: {_ref?: string}\n  /** Bump to force a refetch when the referenced document is updated in place */\n  revision?: number\n}\n\nconst ReferencePreview = (props: ReferencePreviewProps) => {\n  const {value, revision = 0} = props\n  const client = useClient({apiVersion: API_VERSION})\n  const ref = value?._ref\n  const [result, setResult] = useState<{\n    ref: string\n    revision: number\n    asset: CloudinaryAsset | null\n  } | null>(null)\n\n  useEffect(() => {\n    if (!ref) {\n      return undefined\n    }\n\n    let cancelled = false\n    client\n      .getDocument<{asset?: CloudinaryAsset}>(ref)\n      .then((document) => {\n        if (!cancelled) {\n          setResult({ref, revision, asset: document?.asset ?? null})\n        }\n        return null\n      })\n      .catch((err) => {\n        if (!cancelled) {\n          setResult({ref, revision, asset: null})\n        }\n        console.error('Error fetching referenced asset:', err)\n      })\n\n    return () => {\n      cancelled = true\n    }\n  }, [ref, client, revision])\n\n  if (!ref) {\n    return null\n  }\n\n  // Derive loading/asset from the fetched result for the current ref+revision\n  if (result?.ref !== ref || result.revision !== revision) {\n    return <div>Loading asset...</div>\n  }\n\n  if (!result.asset) {\n    return null\n  }\n\n  return <AssetPreview value={result.asset} layout=\"block\" />\n}\n\nexport default ReferencePreview\n","import {PlugIcon} from '@sanity/icons/Plug'\nimport {useSecrets} from '@sanity/studio-secrets'\nimport {Button, Flex, Grid, Stack} from '@sanity/ui'\nimport {nanoid} from 'nanoid'\nimport {useCallback, useMemo, useRef, useState} from 'react'\nimport {type ObjectInputProps, getPublishedId, PatchEvent, set, unset, useClient} from 'sanity'\n\nimport {cloudinaryAssetSchema} from '../schema/cloudinaryAsset'\nimport type {InsertHandlerParams} from '../types'\nimport {normalizeCloudinaryAsset, openMediaSelector} from '../utils'\nimport ReferencePreview from './ReferencePreview'\nimport SecretsConfigView, {namespace, type Secrets} from './SecretsConfigView'\n\nconst API_VERSION = '2023-01-01'\n\n// Fallback so the button doesn't stay disabled if the media library never reports it opened\nconst SELECTOR_FALLBACK_TIMEOUT = 30_000\n\ntype FolderOption = {path?: string; resource_type?: 'image' | 'video'}\n\ntype ReferenceValue = {\n  _key?: string\n  _type?: string\n  asset?: {_type?: 'reference'; _ref?: string; _weak?: boolean}\n}\n\nconst CloudinaryReferenceInput = (props: ObjectInputProps) => {\n  const {onChange, value, schemaType, readOnly} = props\n  const [showSettings, setShowSettings] = useState(false)\n  const [isLoading, setIsLoading] = useState(false)\n  const [previewRevision, setPreviewRevision] = useState(0)\n  const fallbackTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n  const saveInProgressRef = useRef(false)\n  const {secrets, loading: secretsLoading} = useSecrets<Secrets>(namespace)\n  const client = useClient({apiVersion: API_VERSION})\n  // Lookups should see published docs only so we never store drafts.* in _ref\n  const publishedClient = useMemo(() => client.withConfig({perspective: 'published'}), [client])\n\n  const cloudName = secrets?.cloudName\n  const apiKey = secrets?.apiKey\n  const hasConfig = Boolean(apiKey && cloudName)\n  const currentValue = value as ReferenceValue | undefined\n  const valueKey = currentValue?._key\n  const schemaTypeName = schemaType.name\n  const actionsDisabled = Boolean(readOnly) || isLoading || secretsLoading\n\n  const folder = (schemaType.options as {folder?: FolderOption} | undefined)?.folder\n  const folderOption = useMemo(\n    () =>\n      folder?.path || folder?.resource_type\n        ? {path: folder.path, resource_type: folder.resource_type}\n        : undefined,\n    [folder],\n  )\n\n  const setAssetReference = useCallback(\n    (documentId: string) => {\n      onChange(\n        PatchEvent.from(\n          set({\n            _type: schemaTypeName,\n            // Preserve array item identity when this field is used inside an array\n            ...(valueKey ? {_key: valueKey} : {}),\n            asset: {\n              _type: 'reference',\n              _ref: getPublishedId(documentId),\n              _weak: true,\n            },\n          }),\n        ),\n      )\n    },\n    [onChange, schemaTypeName, valueKey],\n  )\n\n  const handleSelect = useCallback(\n    async (payload: InsertHandlerParams) => {\n      if (readOnly) {\n        return\n      }\n\n      const [asset] = payload.assets\n\n      if (!asset) {\n        return\n      }\n\n      const normalizedAsset: Record<string, unknown> = {\n        _type: cloudinaryAssetSchema.name,\n        _key: nanoid(),\n        _version: 1,\n        ...normalizeCloudinaryAsset(asset),\n      }\n\n      setIsLoading(true)\n      saveInProgressRef.current = true\n      try {\n        type ExistingAssetDoc = {_id: string; asset?: {id?: string}}\n\n        // Prefer Cloudinary asset `id` when present; if that misses (or id is\n        // absent), fall back to public_id + resource_type + type so we still\n        // reuse an existing shared document.\n        let existingAsset: ExistingAssetDoc | null = null\n\n        if (asset.id) {\n          existingAsset = await publishedClient.fetch<ExistingAssetDoc | null>(\n            `*[_type == \"cloudinaryAssetDocument\" && asset.id == $id][0]{_id, asset}`,\n            {id: asset.id},\n          )\n        }\n\n        if (!existingAsset && asset.public_id) {\n          existingAsset = await publishedClient.fetch<ExistingAssetDoc | null>(\n            `*[_type == \"cloudinaryAssetDocument\" && asset.public_id == $publicId && asset.resource_type == $resourceType && asset.type == $type][0]{_id, asset}`,\n            {\n              publicId: asset.public_id,\n              resourceType: asset.resource_type,\n              type: asset.type,\n            },\n          )\n        }\n\n        if (existingAsset) {\n          const publishedId = getPublishedId(existingAsset._id)\n          // Preserve a previously stored Cloudinary id if this selection omits it\n          const assetToStore =\n            normalizedAsset['id'] || !existingAsset.asset?.id\n              ? normalizedAsset\n              : {...normalizedAsset, id: existingAsset.asset.id}\n\n          await client.patch(publishedId).set({asset: assetToStore}).commit()\n          setAssetReference(publishedId)\n        } else {\n          // Create a new asset document and reference it (let Sanity assign a valid _id)\n          const newAsset = await client.create({\n            _type: 'cloudinaryAssetDocument',\n            asset: normalizedAsset,\n          })\n          setAssetReference(newAsset._id)\n        }\n\n        // Force preview refresh when the same document is updated in place\n        setPreviewRevision((revision) => revision + 1)\n      } catch (err) {\n        console.error('Error creating/updating Cloudinary asset:', err)\n      } finally {\n        saveInProgressRef.current = false\n        setIsLoading(false)\n      }\n    },\n    [readOnly, client, publishedClient, setAssetReference],\n  )\n\n  const handleOpenSelector = useCallback(() => {\n    if (readOnly || secretsLoading) {\n      return\n    }\n\n    if (!cloudName || !apiKey) {\n      setShowSettings(true)\n      return\n    }\n\n    setIsLoading(true)\n\n    if (fallbackTimerRef.current) {\n      clearTimeout(fallbackTimerRef.current)\n    }\n\n    try {\n      openMediaSelector(\n        cloudName,\n        apiKey,\n        false, // single selection\n        (payload) => {\n          if (fallbackTimerRef.current) {\n            clearTimeout(fallbackTimerRef.current)\n            fallbackTimerRef.current = undefined\n          }\n          // handleSelect manages isLoading for the create/patch work\n          void handleSelect(payload)\n        },\n        undefined,\n        () => {\n          // Don't clear loading while create/patch is in flight — closing the\n          // library after insert can fire showHandler mid-save.\n          if (saveInProgressRef.current) {\n            return\n          }\n          setIsLoading(false)\n        },\n        folderOption,\n      )\n\n      fallbackTimerRef.current = setTimeout(() => {\n        if (!saveInProgressRef.current) {\n          setIsLoading(false)\n        }\n      }, SELECTOR_FALLBACK_TIMEOUT)\n    } catch (error) {\n      console.error('Error opening Cloudinary media selector:', error)\n      setIsLoading(false)\n    }\n  }, [readOnly, secretsLoading, cloudName, apiKey, handleSelect, folderOption])\n\n  const reference = currentValue?.asset\n\n  let selectButtonText = 'Configure Cloudinary to Select Assets'\n  if (secretsLoading) {\n    selectButtonText = 'Loading Cloudinary config...'\n  } else if (hasConfig) {\n    selectButtonText = isLoading ? 'Opening Media Library...' : 'Select Asset'\n  }\n\n  return (\n    <Stack gap={3}>\n      {showSettings && <SecretsConfigView onClose={() => setShowSettings(false)} />}\n\n      <Flex justify=\"flex-end\">\n        <Button\n          color=\"primary\"\n          icon={PlugIcon}\n          mode=\"bleed\"\n          title=\"Configure\"\n          onClick={() => setShowSettings(true)}\n          text={hasConfig || secretsLoading ? undefined : 'Configure Cloudinary plugin'}\n          disabled={Boolean(readOnly) || secretsLoading}\n        />\n      </Flex>\n\n      <Flex marginBottom={2} style={{textAlign: 'center', width: '100%'}}>\n        <ReferencePreview value={reference} revision={previewRevision} />\n      </Flex>\n\n      <Stack gap={2}>\n        <Grid gap={1} style={{gridTemplateColumns: 'repeat(auto-fit, minmax(100px, 1fr))'}}>\n          <Button\n            text={selectButtonText}\n            onClick={handleOpenSelector}\n            tone=\"primary\"\n            mode=\"ghost\"\n            disabled={actionsDisabled}\n            loading={isLoading || secretsLoading}\n          />\n\n          {reference?._ref ? (\n            <Button\n              text=\"Remove\"\n              tone=\"critical\"\n              mode=\"ghost\"\n              onClick={() => onChange(PatchEvent.from(unset()))}\n              disabled={actionsDisabled}\n            />\n          ) : null}\n        </Grid>\n      </Stack>\n    </Stack>\n  )\n}\n\nexport default CloudinaryReferenceInput\n","import {defineType} from 'sanity'\n\nimport CloudinaryReferenceInput from '../components/CloudinaryReferenceInput'\n\nexport const cloudinaryAssetReference = defineType({\n  name: 'cloudinaryAssetReference',\n  title: 'Cloudinary Asset Reference',\n  type: 'object',\n  fields: [\n    {\n      name: 'asset',\n      type: 'reference',\n      to: [{type: 'cloudinaryAssetDocument'}],\n      weak: true,\n    },\n  ],\n  components: {\n    input: CloudinaryReferenceInput,\n  },\n  preview: {\n    select: {\n      caption: 'asset.asset.context.custom.caption',\n      alt: 'asset.asset.context.custom.alt',\n      publicId: 'asset.asset.public_id',\n      resourceType: 'asset.asset.resource_type',\n      format: 'asset.asset.format',\n      secureUrl: 'asset.asset.secure_url',\n      url: 'asset.asset.url',\n      derivedUrl: 'asset.asset.derived.0.secure_url',\n    },\n    prepare(selection) {\n      const {caption, alt, publicId, resourceType, format, secureUrl, url, derivedUrl} =\n        selection as {\n          caption?: string\n          alt?: string\n          publicId?: string\n          resourceType?: string\n          format?: string\n          secureUrl?: string\n          url?: string\n          derivedUrl?: string\n        }\n\n      const title = caption || alt || publicId || 'Untitled Asset'\n      const type = resourceType || 'image'\n      const formatInfo = format ? `(${format})` : ''\n      const subtitle = `${type} ${formatInfo}`\n\n      let media = derivedUrl || secureUrl || url\n      // Desk/list media is rendered as an <img>; only pass image (and PDF) URLs\n      if (type !== 'image' || !media) {\n        media = undefined\n      } else if (format === 'pdf') {\n        media = media.replace(\n          'image/upload',\n          'image/upload/f_jpg,pg_1,l_text:Verdana_75_letter_spacing_14:PDF',\n        )\n      }\n\n      return {\n        title,\n        subtitle,\n        media,\n      }\n    },\n  },\n})\n","import {type AssetSource, definePlugin, isArrayOfObjectsInputProps} from 'sanity'\n\nimport {CloudinaryAssetSource} from './components/asset-source/CloudinaryAssetSource'\nimport {CloudinaryIcon} from './components/asset-source/Icon'\nimport {AssetListFunctions} from './components/AssetListFunctions'\nimport {cloudinaryAssetSchema} from './schema/cloudinaryAsset'\nimport {cloudinaryAssetContext} from './schema/cloudinaryAssetContext'\nimport {cloudinaryAssetContextCustom} from './schema/cloudinaryAssetContextCustom'\nimport {cloudinaryAssetDerivedSchema} from './schema/cloudinaryAssetDerived'\nimport {cloudinaryAssetDocument} from './schema/cloudinaryAssetDocument'\nimport {cloudinaryAssetReference} from './schema/cloudinaryAssetReference'\n\nexport {type CloudinaryAssetContext} from './schema/cloudinaryAssetContext'\nexport {type CloudinaryAssetDerived} from './schema/cloudinaryAssetDerived'\nexport {type CloudinaryAssetContextCustom} from './schema/cloudinaryAssetContextCustom'\n\nexport type {AssetDocument, CloudinaryAsset} from './types'\n\nexport {\n  cloudinaryAssetSchema,\n  cloudinaryAssetDerivedSchema,\n  cloudinaryAssetContext,\n  cloudinaryAssetContextCustom,\n  cloudinaryAssetDocument,\n  cloudinaryAssetReference,\n}\n\nexport const cloudinaryReferencePlugin = definePlugin({\n  name: 'cloudinary-reference',\n  schema: {\n    types: [\n      cloudinaryAssetDocument,\n      cloudinaryAssetReference,\n      cloudinaryAssetSchema,\n      cloudinaryAssetDerivedSchema,\n      cloudinaryAssetContext,\n      cloudinaryAssetContextCustom,\n    ],\n  },\n})\n\nexport const cloudinarySchemaPlugin = definePlugin({\n  name: 'cloudinary-schema',\n  form: {\n    components: {\n      input: (props) => {\n        if (isArrayOfObjectsInputProps(props)) {\n          const cloudinaryType = props.schemaType.of.find(\n            (t: {name: string}) => t.name === cloudinaryAssetSchema.name,\n          )\n          if (cloudinaryType) {\n            return props.renderDefault({...props, arrayFunctions: AssetListFunctions})\n          }\n        }\n        return props.renderDefault(props)\n      },\n    },\n  },\n  schema: {\n    types: [\n      cloudinaryAssetSchema,\n      cloudinaryAssetDerivedSchema,\n      cloudinaryAssetContext,\n      cloudinaryAssetContextCustom,\n    ],\n  },\n})\n\nexport const cloudinaryImageSource: AssetSource = {\n  name: 'cloudinary-image',\n  // oxlint-disable-next-line no-deprecated -- `i18nKey` requires a locale bundle; a plain title is intentional here\n  title: 'Cloudinary',\n  icon: CloudinaryIcon,\n  component: CloudinaryAssetSource,\n}\n\nexport const cloudinaryAssetSourcePlugin = definePlugin({\n  name: 'cloudinary-asset-source',\n  form: {\n    image: {\n      assetSources: [cloudinaryImageSource],\n    },\n  },\n})\n"],"mappings":";;;;;;;;;;;;AAWA,MAAMQ,YAAY;AAElB,SAAgBC,SACdC,OAMAG,WACoB;CACpB,IAAM,CAACC,WAAWJ,MAAMI,WAAW,CAAA;CAiCnC,OArBED,aACAH,MAAMK,aACN,CAACD,WACDJ,MAAMM,kBAAkB,WACxBN,MAAMM,kBAAkB,UACvB,CAACN,MAAMO,QAAQP,MAAMO,SAAS,YAExB,IAAIhB,gBAAgBS,MAAMK,WAAW,IAAIf,YAAY,EAACa,UAAS,CAAC,CAAC,CAAC,CACtEK,OAAOhB,MAAM,CAAC,CAACiB,MAAM,GAAG,CAAC,CAAC,CAC1BC,MAAM,IAGPN,UACEA,QAAQO,aACHP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Y,kBACtCV,OAAOW,gBAAgB,SAEvBQ,WAAW,GAAGnB,KAAI,GADLY,SAAS,IAAIA,OAAM,KAAM,MAGxCQ,QAAQL,cAAcF,aAAaC;GAWvC,OATId,SAAS,WAAW,CAACoB,QACvBA,QAAQC,KAAAA,IACCT,WAAW,UACpBQ,QAAQA,MAAME,QACZ,gBACA,iEACF,IAGK;IACLvB;IACAoB;IACAC;GACF;EACF;CACF;AACF,CAAC,GCvCYoB,4BAA4BhB,aAAa;CACpDiB,MAAM;CACNC,QAAQ,EACNC,OAAO;EACLV;EACAC;EACAL;EACAG;EACAF;EACAC;CAA4B,EAEhC;AACF,CAAC,GAEYa,yBAAyBpB,aAAa;CACjDiB,MAAM;CACNI,MAAM,EACJC,YAAY,EACVC,QAAQC,UACFvB,2BAA2BuB,KAAK,KACXA,MAAME,WAAWC,GAAGC,MACxCC,MAAsBA,EAAEZ,SAASZ,sBAAsBY,IAEtDQ,IACKD,MAAMM,cAAc;EAAC,GAAGN;EAAOO,gBAAgB3B;CAAkB,CAAC,IAGtEoB,MAAMM,cAAcN,KAAK,EAEpC,EACF;CACAN,QAAQ,EACNC,OAAO;EACLd;EACAG;EACAF;EACAC;CAA4B,EAEhC;AACF,CAAC,GAEYyB,wBAAqC;CAChDf,MAAM;CAENgB,OAAO;CACPC,MAAM/B;CACNgC,WAAWjC;AACb,GAEakC,8BAA8BpC,aAAa;CACtDiB,MAAM;CACNI,MAAM,EACJgB,OAAO,EACLC,cAAc,CAACN,qBAAqB,EACtC,EACF;AACF,CAAC"}
\ No newline at end of file
+{"version":3,"file":"index.js","names":["CloudConfig","CloudinaryImage","scale","CloudinaryAsset","CloudinaryAssetResponse","CloudinaryMediaLibrary","InsertHandlerParams","ShowHandlerParams","widgetSrc","assetUrl","asset","Partial","Pick","cloudName","derived","public_id","resource_type","type","resize","width","toURL","secure_url","url","normalizeCloudinaryAsset","Record","assetWithoutNulls","Object","fromEntries","entries","filter","_","assetValue","requiredFields","format","height","bytes","tags","updatedAsset","id","context","objectWithRenamedKeys","custom","map","contextKey","contextValue","replace","derivedItem","_type","raw_transformation","openMediaSelector","apiKey","multiple","insertHandler","params","selectedAsset","showHandler","folder","path","loadJS","cloudinary","options","cloud_name","api_key","insert_caption","callbacks","openMediaLibrary","createMediaLibrary","inlineContainer","libraryCreated","library","inline_container","remove_header","callback","NonNullable","Window","window","settled","handleLoad","existingScript","document","getElementById","addEventListener","once","script","createElement","src","body","appendChild","encodeSourceId","btoa","JSON","stringify","encodeFilename","split","slice","decodeSourceId","sourceId","sourceIdDecoded","parse","atob","SettingsView","Secrets","cloudName","apiKey","pluginConfigKeys","key","title","description","namespace","Props","onClose","SecretsConfigView","props","$","_c","t0","PlugIcon","useSecrets","Box","Button","Dialog","Flex","Spinner","Stack","Text","useCallback","useEffect","useRef","useState","AssetSourceComponentProps","ImageAsset","styled","CloudinaryMediaLibrary","InsertHandlerParams","createMediaLibrary","decodeSourceId","encodeFilename","encodeSourceId","SecretsConfigView","namespace","Secrets","Widget","div","CloudinaryAssetSource","props","$","_c","onClose","dialogHeaderTitle","loadingMessage","setLoadingMessage","library","undefined","contentRef","secrets","cloudName","apiKey","widgetId","_temp","showSettings","setShowSettings","propsRef","t0","t1","current","t2","hide","handleClose","t3","t4","inlineContainer","libraryCreated","lib","selectedAssets","firstSelectedAsset","iframe","firstChild","HTMLIFrameElement","asset","selectionType","source","id","folder","path","public_id","split","slice","join","resource_type","show","style","visibility","insertHandler","t5","assets","imageAssets","filter","_temp2","length","Error","onSelect","map","asset_1","url","derived","secure_url","kind","value","assetDocumentProps","_type","originalFilename","name","hasConfig","t6","t7","Symbol","for","t8","t9","t10","t11","t12","t13","t14","asset_0","Date","now","CloudinaryIcon","$","_c","t0","Symbol","for","CSSProperties","PlayerKind","VideoPlayerProps","src","kind","VideoPlayer","props","$","_c","t0","Symbol","for","width","height","style","t1","useSecrets","DiffFromTo","CloudinaryAsset","assetUrl","namespace","Secrets","VideoPlayer","Props","value","CloudinaryDiffPreview","t0","$","_c","secrets","cloudName","t1","url","resource_type","t2","Symbol","for","display","flexWrap","justifyContent","t3","maxWidth","height","DiffProps","diff","schemaType","AssetDiff","DocumentIcon","useSecrets","Flex","Text","CloudinaryAsset","assetUrl","namespace","Secrets","VideoPlayer","ComponentProps","layout","value","AssetPreview","t0","$","_c","secrets","cloudName","t1","Symbol","for","bb0","url","resource_type","t2","t3","maxWidth","marginLeft","t4","display_name","t5","previewSrc","format","replace","width","height","display","PlugIcon","Button","Flex","Grid","Stack","useCallback","ObjectInputProps","PatchEvent","unset","styled","CloudinaryAsset","AssetPreview","SetupButtonContainer","div","WidgetInputProps","openMediaSelector","onSetup","WidgetInput","props","$","_c","onChange","readOnly","value","t0","from","removeValue","t1","t2","Symbol","for","textAlign","width","t3","t4","t5","gridTemplateColumns","t6","t7","t8","t9","t10","useSecrets","nanoid","useCallback","useState","ObjectInputProps","PatchEvent","set","CloudinaryAsset","InsertHandlerParams","normalizeCloudinaryAsset","openMediaSelector","SecretsConfigView","namespace","Secrets","WidgetInput","CloudinaryInput","props","$","_c","showSettings","setShowSettings","secrets","onChange","schemaType","type","value","undefined","valueKey","_key","t0","payload","asset","assets","from","_type","name","_version","handleSelect","t1","cloudName","apiKey","action","t2","t3","Symbol","for","t4","t5","defineType","AssetDiff","AssetPreview","CloudinaryInput","cloudinaryAssetSchema","type","name","fields","of","components","input","diff","preview","select","url","resource_type","derived","prepare","title","value","PlugIcon","useSecrets","Box","Button","Flex","useCallback","useState","ArrayInputFunctionsProps","ArrayOfObjectsFunctions","ArraySchemaType","insert","ObjectSchemaType","PatchEvent","setIfMissing","cloudinaryAssetSchema","InsertHandlerParams","openMediaSelector","SecretsConfigView","namespace","ApiConfig","cloudName","apiKey","AssetListFunctions","props","$","_c","onValueCreate","onChange","secrets","loading","showSettings","setShowSettings","t0","Symbol","for","show","t1","hide","t2","schemaType","of","find","_temp","cloudinaryType","Error","name","map","_temp2","join","t3","selected","items","assets","asset","Object","assign","_version","from","handleSelect","t4","handleOpenSelector","t5","t6","t7","readOnly","width","t8","t","t_0","defineType","CloudinaryAssetContext","custom","cloudinaryAssetContext","type","name","fields","defineType","CloudinaryAssetContextCustom","alt","caption","cloudinaryAssetContextCustom","type","name","fields","defineType","CloudinaryAssetDerived","raw_transformation","url","secure_url","cloudinaryAssetDerivedSchema","type","name","fields","defineType","cloudinaryAssetSchema","cloudinaryAssetDocument","name","title","type","liveEdit","fields","preview","select","caption","alt","publicId","resourceType","format","secureUrl","url","derivedUrl","prepare","selection","formatInfo","subtitle","media","undefined","replace","useEffect","useState","useClient","CloudinaryAsset","AssetPreview","API_VERSION","ReferencePreviewProps","value","_ref","revision","ReferencePreview","props","$","_c","t0","undefined","t1","Symbol","for","apiVersion","client","ref","result","setResult","t2","t3","cancelled","getDocument","then","document","asset","catch","err","console","error","t4","PlugIcon","useSecrets","Button","Flex","Grid","Stack","nanoid","useCallback","useMemo","useRef","useState","ObjectInputProps","getPublishedId","PatchEvent","set","unset","useClient","cloudinaryAssetSchema","InsertHandlerParams","normalizeCloudinaryAsset","openMediaSelector","ReferencePreview","SecretsConfigView","namespace","Secrets","API_VERSION","SELECTOR_FALLBACK_TIMEOUT","FolderOption","path","resource_type","ReferenceValue","_key","_type","asset","_ref","_weak","CloudinaryReferenceInput","props","onChange","value","schemaType","readOnly","showSettings","setShowSettings","isLoading","setIsLoading","previewRevision","setPreviewRevision","fallbackTimerRef","ReturnType","setTimeout","undefined","saveInProgressRef","secrets","loading","secretsLoading","client","apiVersion","publishedClient","withConfig","perspective","cloudName","apiKey","hasConfig","Boolean","currentValue","valueKey","schemaTypeName","name","actionsDisabled","folder","options","folderOption","setAssetReference","documentId","from","handleSelect","payload","assets","normalizedAsset","Record","_version","current","ExistingAssetDoc","_id","id","existingAsset","fetch","public_id","publicId","resourceType","type","publishedId","assetToStore","patch","commit","newAsset","create","revision","err","console","error","handleOpenSelector","clearTimeout","reference","selectButtonText","textAlign","width","gridTemplateColumns","defineType","CloudinaryReferenceInput","cloudinaryAssetReference","name","title","type","fields","to","weak","components","input","preview","select","caption","alt","publicId","resourceType","format","secureUrl","url","derivedUrl","prepare","selection","formatInfo","subtitle","media","undefined","replace","AssetSource","definePlugin","isArrayOfObjectsInputProps","CloudinaryAssetSource","CloudinaryIcon","AssetListFunctions","cloudinaryAssetSchema","cloudinaryAssetContext","cloudinaryAssetContextCustom","cloudinaryAssetDerivedSchema","cloudinaryAssetDocument","cloudinaryAssetReference","CloudinaryAssetContext","CloudinaryAssetDerived","CloudinaryAssetContextCustom","AssetDocument","CloudinaryAsset","cloudinaryReferencePlugin","name","schema","types","cloudinarySchemaPlugin","form","components","input","props","cloudinaryType","schemaType","of","find","t","renderDefault","arrayFunctions","cloudinaryImageSource","title","icon","component","cloudinaryAssetSourcePlugin","image","assetSources"],"sources":["../src/utils.ts","../src/components/SecretsConfigView.tsx","../src/components/asset-source/CloudinaryAssetSource.tsx","../src/components/asset-source/Icon.tsx","../src/components/VideoPlayer.tsx","../src/components/AssetDiff.tsx","../src/components/AssetPreview.tsx","../src/components/WidgetInput.tsx","../src/components/CloudinaryInput.tsx","../src/schema/cloudinaryAsset.ts","../src/components/AssetListFunctions.tsx","../src/schema/cloudinaryAssetContext.ts","../src/schema/cloudinaryAssetContextCustom.ts","../src/schema/cloudinaryAssetDerived.ts","../src/schema/cloudinaryAssetDocument.ts","../src/components/ReferencePreview.tsx","../src/components/CloudinaryReferenceInput.tsx","../src/schema/cloudinaryAssetReference.ts","../src/index.ts"],"sourcesContent":["import {CloudConfig, CloudinaryImage} from '@cloudinary/url-gen'\nimport {scale} from '@cloudinary/url-gen/actions/resize'\n\nimport type {\n  CloudinaryAsset,\n  CloudinaryAssetResponse,\n  CloudinaryMediaLibrary,\n  InsertHandlerParams,\n  ShowHandlerParams,\n} from './types'\n\nconst widgetSrc = 'https://media-library.cloudinary.com/global/all.js'\n\nexport function assetUrl(\n  asset: Partial<\n    Pick<\n      CloudinaryAsset,\n      'url' | 'secure_url' | 'derived' | 'public_id' | 'format' | 'resource_type' | 'type'\n    >\n  >,\n  cloudName?: string,\n): string | undefined {\n  const [derived] = asset.derived ?? []\n\n  // When the cloud name and public id are known and there is no Media Library\n  // derived transform, build an on-the-fly preview with url-gen instead of\n  // serving the full-size original. Scaling to a 400px width keeps previews\n  // crisp while avoiding multi-megabyte source downloads.\n  // Only public `upload` images use CloudinaryImage — video/raw would get an\n  // /image/upload URL that breaks VideoPlayer/raw previews, and private or\n  // authenticated assets need their stored (often signed) URL rather than an\n  // unsigned /upload/ path. Derived transforms are preferred over the scaled\n  // original so Studio still shows the editor's chosen crop/effects.\n  if (\n    cloudName &&\n    asset.public_id &&\n    !derived &&\n    asset.resource_type !== 'video' &&\n    asset.resource_type !== 'raw' &&\n    (!asset.type || asset.type === 'upload')\n  ) {\n    return new CloudinaryImage(asset.public_id, new CloudConfig({cloudName}))\n      .resize(scale().width(400))\n      .toURL()\n  }\n\n  if (derived) {\n    if (derived.secure_url) {\n      return derived.secure_url\n    }\n    return derived.url\n  }\n  if (asset.secure_url) {\n    return asset.secure_url\n  }\n  return asset.url\n}\n\n/**\n * Normalize a Media Library payload into a shape that matches the `cloudinary.asset`\n * schema: drop nulls, sanitize context keys, and tag derived items with `_type`.\n */\nexport function normalizeCloudinaryAsset(asset: CloudinaryAssetResponse): Record<string, unknown> {\n  const assetWithoutNulls = Object.fromEntries(\n    Object.entries(asset).filter(([_, assetValue]) => assetValue !== null),\n  ) as CloudinaryAssetResponse\n\n  const requiredFields = {\n    public_id: asset.public_id,\n    resource_type: asset.resource_type,\n    type: asset.type,\n    url: asset.url,\n    secure_url: asset.secure_url,\n    format: asset.format,\n    width: asset.width,\n    height: asset.height,\n    bytes: asset.bytes,\n    tags: asset.tags,\n  }\n\n  let updatedAsset: Record<string, unknown> = {\n    ...assetWithoutNulls,\n    ...requiredFields,\n  }\n\n  // Only persist Cloudinary's asset id when the Media Library actually provides one.\n  // Do not delete a missing id here — callers that replace a whole asset object should\n  // preserve any previously stored id themselves (see CloudinaryReferenceInput).\n  if (asset.id) {\n    updatedAsset['id'] = asset.id\n  }\n\n  // Sanity object keys cannot contain special characters, so rename Cloudinary context keys\n  if (asset.context) {\n    const objectWithRenamedKeys = Object.fromEntries(\n      Object.entries(asset.context.custom).map(([contextKey, contextValue]) => {\n        return [contextKey.replace(/[^a-zA-Z0-9_]|-/g, '_'), contextValue]\n      }),\n    )\n\n    updatedAsset = {\n      ...updatedAsset,\n      context: {\n        ...asset.context,\n        custom: objectWithRenamedKeys,\n      },\n    }\n  }\n\n  if (asset.derived) {\n    updatedAsset = {\n      ...updatedAsset,\n      derived: asset.derived.map((derivedItem) => ({\n        _type: 'derived',\n        url: derivedItem.url,\n        secure_url: derivedItem.secure_url,\n        raw_transformation: derivedItem.raw_transformation,\n      })),\n    }\n  }\n\n  return updatedAsset\n}\n\nexport const openMediaSelector = (\n  cloudName: string,\n  apiKey: string,\n  multiple: boolean,\n  insertHandler: (params: InsertHandlerParams) => void,\n  selectedAsset?: CloudinaryAsset,\n  showHandler?: (params: ShowHandlerParams) => void,\n  folder?: {resource_type?: 'image' | 'video'; path?: string},\n) => {\n  loadJS(widgetSrc, (cloudinary) => {\n    const options: Record<string, any> = {\n      cloud_name: cloudName,\n      api_key: apiKey,\n      insert_caption: 'Select',\n      multiple,\n    }\n\n    if (selectedAsset) {\n      options['asset'] = {\n        public_id: selectedAsset.public_id,\n        type: selectedAsset.type,\n        resource_type: selectedAsset.resource_type,\n      }\n    }\n\n    if (folder?.path || folder?.resource_type) {\n      options['folder'] = {\n        ...(folder.path ? {path: folder.path} : {}),\n        ...(folder.resource_type ? {resource_type: folder.resource_type} : {}),\n      }\n    }\n\n    const callbacks: {\n      insertHandler: (params: InsertHandlerParams) => void\n      showHandler?: (params: ShowHandlerParams) => void\n    } = {insertHandler}\n\n    if (showHandler) {\n      callbacks.showHandler = showHandler\n    }\n\n    cloudinary.openMediaLibrary(options, callbacks)\n  })\n}\n\nexport const createMediaLibrary = ({\n  cloudName,\n  apiKey,\n  inlineContainer,\n  libraryCreated,\n  insertHandler,\n}: {\n  cloudName: string\n  apiKey: string\n  inlineContainer: string\n  libraryCreated: (library: CloudinaryMediaLibrary) => void\n  insertHandler: (params: InsertHandlerParams) => void\n}) => {\n  loadJS(widgetSrc, (cloudinary) => {\n    const options: Record<string, any> = {\n      cloud_name: cloudName,\n      api_key: apiKey,\n      insert_caption: 'Select',\n      inline_container: inlineContainer,\n      remove_header: true,\n    }\n\n    libraryCreated(cloudinary.createMediaLibrary(options, {insertHandler}))\n  })\n}\n\nfunction loadJS(url: string, callback: (cloudinary: NonNullable<Window['cloudinary']>) => void) {\n  // The widget exposes `window.cloudinary` only once the script has finished\n  // loading. When it's already available, run the callback right away.\n  if (window.cloudinary) {\n    callback(window.cloudinary)\n    return\n  }\n\n  // Guard against double-invocation if load fires in the same tick as the\n  // post-listener readiness re-check below.\n  let settled = false\n  const handleLoad = () => {\n    if (settled || !window.cloudinary) {\n      return\n    }\n    settled = true\n    callback(window.cloudinary)\n  }\n\n  const existingScript = document.getElementById('damWidget')\n  if (existingScript) {\n    // Another input already injected the script, but it hasn't finished\n    // loading yet (the global isn't ready). Wait for the load event instead\n    // of invoking the callback too early.\n    existingScript.addEventListener('load', handleLoad, {once: true})\n    // Re-check immediately: the load event may have fired between the initial\n    // `window.cloudinary` check and registering this listener, in which case\n    // the event will never fire again and the callback would otherwise hang.\n    handleLoad()\n    return\n  }\n\n  const script = document.createElement('script')\n  script.src = url\n  script.id = 'damWidget'\n  script.addEventListener('load', handleLoad, {once: true})\n  document.body.appendChild(script)\n}\n\nexport function encodeSourceId(asset: CloudinaryAssetResponse): string {\n  const {resource_type, public_id, type} = asset\n  return btoa(JSON.stringify({public_id, resource_type, type})) // Sort keys alphabetically!\n}\n\nexport function encodeFilename(asset: CloudinaryAssetResponse) {\n  return `${asset.public_id.split('/').slice(-1)[0]}.${asset.format}`\n}\n\nexport function decodeSourceId(sourceId: string): CloudinaryAssetResponse | undefined {\n  let sourceIdDecoded: any\n  try {\n    sourceIdDecoded = JSON.parse(atob(sourceId))\n  } catch {\n    // Do nothing\n  }\n  return sourceIdDecoded\n}\n","import {SettingsView} from '@sanity/studio-secrets'\n\nexport type Secrets = {\n  cloudName: string\n  apiKey: string\n}\n\nconst pluginConfigKeys = [\n  {\n    key: 'cloudName',\n    title: 'Cloud name',\n    description: '',\n  },\n  {\n    key: 'apiKey',\n    title: 'API key',\n    description: '',\n  },\n]\n\nexport const namespace = 'cloudinary'\n\ntype Props = {\n  onClose: () => void\n}\n\nconst SecretsConfigView = (props: Props) => {\n  return (\n    <SettingsView\n      title=\"Cloudinary config\"\n      namespace={namespace}\n      keys={pluginConfigKeys}\n      onClose={props.onClose}\n    />\n  )\n}\n\nexport default SecretsConfigView\n","import {PlugIcon} from '@sanity/icons/Plug'\nimport {useSecrets} from '@sanity/studio-secrets'\nimport {Box, Button, Dialog, Flex, Spinner, Stack, Text} from '@sanity/ui'\nimport {useCallback, useEffect, useRef, useState} from 'react'\nimport type {AssetSourceComponentProps, ImageAsset} from 'sanity'\nimport {styled} from 'styled-components'\n\nimport type {CloudinaryMediaLibrary, InsertHandlerParams} from '../../types'\nimport {createMediaLibrary, decodeSourceId, encodeFilename, encodeSourceId} from '../../utils'\nimport SecretsConfigView, {namespace, type Secrets} from '../SecretsConfigView'\n\nconst Widget = styled.div`\n  height: 70vh;\n`\n\nexport function CloudinaryAssetSource(props: AssetSourceComponentProps) {\n  const {onClose, dialogHeaderTitle} = props\n\n  const [loadingMessage, setLoadingMessage] = useState<string | undefined>(\n    'Loading Cloudinary Media Library',\n  )\n  const library = useRef<CloudinaryMediaLibrary | undefined>(undefined)\n  const contentRef = useRef<HTMLDivElement | null>(null)\n  const {secrets} = useSecrets<Secrets>(namespace)\n  const cloudName = secrets?.cloudName\n  const apiKey = secrets?.apiKey\n  const [widgetId] = useState(() => `cloudinaryWidget-${Date.now()}`)\n  const [showSettings, setShowSettings] = useState(false)\n\n  const propsRef = useRef(props)\n\n  useEffect(() => {\n    // because we have to access props after loading js in a callback,\n    // we cannot pass props as dependencies as that will cause infinite updates\n    // this takes a snapshot of props, so we can access them later\n    propsRef.current = props\n  }, [props])\n\n  const handleClose = useCallback(() => {\n    if (library.current) {\n      library.current.hide()\n    }\n    onClose()\n  }, [onClose, library])\n\n  useEffect(() => {\n    if (!cloudName || !apiKey) {\n      return\n    }\n\n    createMediaLibrary({\n      cloudName,\n      apiKey,\n      inlineContainer: `#${widgetId}`,\n      libraryCreated: (lib: CloudinaryMediaLibrary) => {\n        library.current = lib\n        const selectedAssets = propsRef.current.selectedAssets\n        const firstSelectedAsset = selectedAssets ? selectedAssets[0] : null\n\n        const iframe: ChildNode | null | undefined =\n          contentRef.current && contentRef.current.firstChild\n        if (iframe && iframe instanceof HTMLIFrameElement) {\n          setLoadingMessage(undefined)\n          let asset\n          if (\n            propsRef.current.selectionType === 'single' &&\n            firstSelectedAsset &&\n            firstSelectedAsset.source &&\n            firstSelectedAsset.source.id\n          ) {\n            asset = decodeSourceId(firstSelectedAsset.source.id)\n          }\n          const folder = asset\n            ? {\n                path: asset.public_id.split('/').slice(0, -1).join('/'),\n                resource_type: 'image',\n              }\n            : {path: '', resource_type: 'image'}\n          if (lib && contentRef.current) {\n            lib.show({folder, asset})\n            contentRef.current.style.visibility = 'visible'\n          }\n        }\n      },\n      insertHandler: ({assets}: InsertHandlerParams) => {\n        if (!library.current) {\n          return\n        }\n        const imageAssets = assets.filter((asset) => asset.resource_type === 'image')\n        if (imageAssets.length === 0) {\n          throw new Error('The selection did not contain any images.')\n        }\n        library.current.hide()\n        propsRef.current.onSelect(\n          imageAssets.map((asset) => {\n            const url =\n              asset.derived && asset.derived[0] ? asset.derived[0].secure_url : asset.secure_url\n            return {\n              kind: 'url',\n              value: url,\n              assetDocumentProps: {\n                _type: 'sanity.imageAsset',\n                originalFilename: encodeFilename(asset),\n                source: {\n                  id: encodeSourceId(asset),\n                  name: `cloudinary:${cloudName}`,\n                },\n              } as ImageAsset,\n            }\n          }),\n        )\n      },\n    })\n  }, [cloudName, apiKey, widgetId])\n\n  const hasConfig = apiKey && cloudName\n  return (\n    <Dialog\n      id=\"cloudinary-asset-source\"\n      header={dialogHeaderTitle ?? 'Select image from Cloudinary'}\n      onClose={handleClose}\n      open\n      width={4}\n    >\n      <Box padding={4}>\n        {showSettings && <SecretsConfigView onClose={() => setShowSettings(false)} />}\n        <Flex flex={1} justify=\"flex-end\">\n          <Button\n            color=\"primary\"\n            icon={PlugIcon}\n            mode=\"bleed\"\n            title=\"Configure\"\n            onClick={() => setShowSettings(true)}\n            tabIndex={0}\n            text={hasConfig ? undefined : 'Configure Cloudinary plugin'}\n          />\n        </Flex>\n\n        {hasConfig && loadingMessage && (\n          <Stack gap={3}>\n            <Flex align=\"center\" justify=\"center\">\n              <Spinner muted />\n            </Flex>\n            <Text size={1} muted align=\"center\">\n              {loadingMessage}\n            </Text>\n          </Stack>\n        )}\n\n        <Widget style={{visibility: 'hidden'}} ref={contentRef} id={widgetId} />\n      </Box>\n    </Dialog>\n  )\n}\n","export function CloudinaryIcon() {\n  return (\n    <svg\n      version=\"1.1\"\n      id=\"Layer_1\"\n      x=\"0px\"\n      y=\"0px\"\n      width=\"1em\"\n      height=\"1em\"\n      viewBox=\"0 0 141.732 141.747\"\n      enableBackground=\"new 0 0 141.732 141.747\"\n    >\n      <g>\n        <path\n          fill=\"#0071CE\"\n          d=\"M115.585,109.242c-1.609,0-3.107-1.024-3.635-2.637c-0.657-2.008,0.438-4.169,2.447-4.826\n        c7.278-2.382,11.98-8.761,11.98-16.252c0-9.487-7.718-17.206-17.205-17.206c-0.659,0-1.368,0.052-2.231,0.164l-3.741,0.485\n        l-0.537-3.735c-2.299-16.016-16.251-28.094-32.454-28.094c-13.395,0-25.32,8.019-30.377,20.43l-0.952,2.335l-2.52,0.046\n        c-11.581,0.213-21.003,9.804-21.003,21.379c0,8.45,4.906,16.156,12.498,19.631c1.921,0.88,2.766,3.15,1.886,5.071\n        c-0.88,1.921-3.149,2.764-5.07,1.887C14.363,103.202,7.703,92.766,7.703,81.331c0-14.88,11.465-27.345,26.028-28.876\n        c6.71-14.03,20.773-22.965,36.477-22.965c18.796,0,35.135,13.178,39.372,31.184c13.519,0.219,24.45,11.284,24.45,24.854\n        c0,10.693-6.934,20.146-17.253,23.523C116.382,109.18,115.98,109.242,115.585,109.242z\"\n        />\n        <path\n          fill=\"#DC8327\"\n          d=\"M57.12,111.02c-0.001-0.001-0.001-0.001-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001\n        c0,0-0.001-0.001-0.001-0.001l-0.001-0.001c0,0-0.001,0-0.001-0.001h-0.001l-0.001-0.001c0.001-0.001-0.001-0.001-0.001-0.001\n        l-0.001-0.001c0,0-0.001,0-0.001,0l-0.001-0.001c0.001,0.001-0.001-0.001-0.001-0.001s-0.002-0.001-0.003-0.001l-0.001-0.001H57.1\n        c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001c-0.003-0.001-0.002-0.001-0.003-0.001c-0.001,0.001-0.001-0.001-0.002-0.001\n        l-0.001-0.001c0,0-0.001-0.001-0.002-0.001l-0.001-0.001c-0.001-0.001-0.003-0.001-0.004-0.001s-0.003-0.001-0.004-0.001\n        c-0.001-0.001-0.001-0.001-0.002-0.001h-0.001c-0.001-0.001-0.002-0.001-0.003-0.001c-0.001-0.001-0.003-0.001-0.003-0.001\n        c-0.001,0-0.001,0-0.001,0l-0.002-0.001c-0.001,0-0.001-0.001-0.001-0.001h-0.001c-0.059-0.021-0.122-0.034-0.188-0.037h-0.002\n        h-0.002c-0.001,0-0.001,0-0.002,0c0,0,0,0-0.001,0c0,0-0.001,0-0.001,0h-0.001c-0.001-0.001-0.001-0.001-0.001-0.001\n        c-0.001,0-0.002,0-0.002,0c-0.001,0-0.002,0-0.002,0h-0.001h-0.001h-0.001c-0.001,0-0.002,0-0.002,0h-0.001H56.86h-0.001h-0.001\n        c-0.001,0-0.001,0-0.001,0h-0.001h-0.001h-0.001h-0.001c-0.001,0-0.001,0-0.001,0c-1.656,0-3.011-1.348-3.021-3V74.29h2.567\n        c0.004,0,0.009,0,0.013,0c0.393,0.017,0.661-0.285,0.661-0.648c0-0.271-0.166-0.503-0.402-0.6l-12.379-8.544\n        c-0.222-0.153-0.515-0.153-0.737,0l-12.476,8.611c-0.234,0.161-0.335,0.456-0.251,0.727c0.085,0.271,0.335,0.455,0.619,0.455h2.58\n        l0.002,33.674c0.013,2.328,1.883,4.228,4.262,4.288c0.027,0.003,0.053,0.005,0.08,0.005h18.481c0.004,0,0.007,0,0.011,0\n        c0.17-0.003,0.324-0.071,0.438-0.18c0,0,0,0,0.001-0.001c0.002-0.002,0.004-0.004,0.005-0.005c0.001-0.001,0.002-0.001,0.003-0.003\n        c0,0,0.001-0.001,0.001-0.001l0.001-0.001l0.001-0.001l0.001-0.001l0.001-0.001c0.001-0.001,0.001-0.001,0.001-0.001\n        c0.002-0.001,0.001-0.001,0.002-0.002c0,0,0,0,0.001-0.001l0.001-0.001c0,0,0,0,0.001-0.001c0.112-0.116,0.182-0.273,0.183-0.447\n        v-0.002v-0.001v-0.001v-0.001v-0.001v-0.001v-0.001v-0.002C57.498,111.345,57.343,111.121,57.12,111.02z\"\n        />\n        <path\n          fill=\"#F4B21B\"\n          d=\"M83.889,111.02c0,0-0.001-0.001-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001\n        c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001h-0.001c0,0-0.001-0.001-0.001-0.001c0,0-0.001-0.001-0.001-0.001\n        c0.001-0.001-0.001-0.001-0.002-0.001l-0.001-0.001h-0.001c-0.001,0-0.001-0.001-0.001-0.001c-0.002,0.001-0.002-0.001-0.002-0.001\n        l-0.002-0.001l-0.001-0.001h-0.001c0,0-0.001-0.001-0.001-0.001l-0.001-0.001c-0.001-0.001-0.002-0.001-0.002-0.001\n        c-0.001,0.001-0.001-0.001-0.003-0.001l-0.001-0.001l-0.001-0.001c0,0-0.001,0-0.002-0.001c-0.001-0.001-0.003-0.001-0.004-0.001\n        s-0.003-0.001-0.004-0.001c-0.001-0.001-0.001-0.001-0.002-0.001c-0.001,0-0.001,0-0.002-0.001c0,0-0.001,0-0.002-0.001\n        c-0.003-0.001-0.001-0.001-0.002-0.001c-0.003,0-0.001,0-0.002-0.001c0,0-0.001-0.001-0.002-0.001l-0.001-0.001h-0.001\n        c-0.059-0.021-0.122-0.034-0.188-0.037h-0.002c-0.001,0-0.001,0-0.001,0c-0.001,0-0.002,0-0.002,0s-0.001,0-0.001,0h-0.001h-0.001\n        l-0.001-0.001c-0.001,0-0.002,0-0.002,0c-0.001,0-0.002,0-0.002,0h-0.001c-0.001,0-0.001,0-0.001,0h-0.001\n        c-0.001,0-0.002,0-0.002,0s-0.001,0-0.002,0h-0.001c0,0-0.001,0-0.001,0h-0.001c-0.001,0-0.001,0-0.001,0h-0.001h-0.001h-0.001\n        h-0.001c-0.001,0-0.001,0-0.001,0c-1.655,0-3.01-1.348-3.02-3V81.829h2.579c0.009-0.001,0.016-0.001,0.026,0\n        c0.358,0,0.648-0.29,0.648-0.648c0-0.271-0.166-0.503-0.402-0.6l-12.38-8.544c-0.222-0.153-0.515-0.153-0.737,0L57.86,80.647\n        c-0.234,0.161-0.335,0.456-0.251,0.727c0.085,0.271,0.335,0.455,0.619,0.455h2.568l0.002,26.135\n        c0.011,2.329,1.884,4.23,4.264,4.289c0.026,0.003,0.052,0.004,0.078,0.004h18.481c0.004,0,0.007,0,0.011,0\n        c0.17-0.003,0.324-0.071,0.438-0.18c0,0,0,0,0.001-0.001c0.002-0.002,0.006-0.004,0.005-0.005c0.001-0.001,0.002-0.001,0.003-0.003\n        c0.001-0.001,0.001-0.001,0.001-0.001l0.001-0.001l0.001-0.001c0,0,0.001,0,0.001-0.001l0.001-0.001\n        c0.001,0,0.001-0.001,0.001-0.001c0.003-0.001,0.002-0.001,0.002-0.002c0,0,0,0,0.001-0.001c0,0,0,0,0.001-0.001\n        c0,0,0,0,0.001-0.001c0.112-0.116,0.182-0.273,0.183-0.447v-0.002v-0.001v-0.001v-0.001v-0.001v-0.001v-0.001v-0.002\n        C84.267,111.345,84.112,111.121,83.889,111.02z\"\n        />\n        <path\n          fill=\"#F2D864\"\n          d=\"M110.667,111.02l-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001\n        c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001c-0.001,0-0.001,0-0.001-0.001h-0.001l-0.001-0.001\n        c-0.001-0.001-0.001-0.001-0.001-0.001s-0.001,0-0.001-0.001h-0.001c0,0-0.001-0.001-0.001-0.001\n        c-0.001,0.001-0.001-0.001-0.002-0.001c0.001-0.001-0.001-0.001-0.002-0.001l-0.001-0.001c-0.001,0-0.001,0-0.001,0\n        c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001c-0.003-0.001-0.002-0.001-0.002-0.001c-0.001,0.001-0.001-0.001-0.003-0.001\n        l-0.001-0.001c0.001-0.001-0.001-0.001-0.002-0.001c0,0-0.001,0-0.001-0.001c-0.001-0.001-0.003-0.001-0.004-0.001\n        s-0.003-0.001-0.004-0.001l-0.002-0.001c0,0-0.001,0-0.002-0.001l-0.002-0.001c-0.003-0.001-0.003-0.001-0.002-0.001\n        c-0.003,0-0.003,0-0.002-0.001c-0.001,0-0.001-0.001-0.001-0.001c-0.001,0-0.002-0.001-0.002-0.001h-0.001\n        c-0.059-0.021-0.122-0.034-0.188-0.037h-0.001c-0.001,0-0.002,0-0.002,0c-0.001,0-0.002,0-0.003,0h-0.001h-0.001h-0.001\n        c-0.001-0.001-0.001-0.001-0.002-0.001c0,0-0.001,0-0.002,0c0,0-0.001,0-0.002,0h-0.001c0,0-0.001,0-0.001,0h-0.001\n        c-0.001,0-0.002,0-0.002,0h-0.002c0,0,0,0-0.001,0c0,0-0.001,0-0.001,0h-0.001c0,0-0.001,0-0.001,0h-0.001h-0.001h-0.001H110.4\n        c0,0-0.001,0-0.001,0c-1.655,0-3.01-1.348-3.02-3V89.365h2.573c0.004,0,0.009,0,0.013,0c0.365-0.009,0.661-0.285,0.661-0.648\n        c0-0.271-0.166-0.503-0.402-0.6l-12.38-8.544c-0.221-0.153-0.515-0.153-0.737,0l-12.476,8.61c-0.234,0.161-0.335,0.456-0.251,0.727\n        c0.085,0.271,0.335,0.455,0.619,0.455h2.573l0.002,18.599c0.013,2.329,1.885,4.231,4.264,4.289\n        c0.026,0.003,0.052,0.004,0.078,0.004h18.481c0.004,0,0.007,0,0.011,0c0.17-0.003,0.324-0.071,0.438-0.18l0.001-0.001\n        c0.002-0.002,0.005-0.004,0.005-0.005c0.001-0.001,0.002-0.001,0.003-0.003c0,0,0.001-0.001,0.001-0.001l0.001-0.001l0.001-0.001\n        l0.001-0.001l0.001-0.001l0.001-0.001c0.003-0.001,0.001-0.001,0.002-0.002c0,0,0,0,0.001-0.001l0.001-0.001c0,0,0,0,0.001-0.001\n        c0.112-0.116,0.182-0.273,0.183-0.447v-0.002v-0.001v-0.001v-0.001v-0.001v-0.001v-0.001v-0.002\n        C111.045,111.345,110.889,111.121,110.667,111.02z\"\n        />\n      </g>\n    </svg>\n  )\n}\n","import type {CSSProperties} from 'react'\n\ntype PlayerKind = 'player' | 'diff'\n\nexport type VideoPlayerProps = {\n  src: string\n  kind: PlayerKind\n}\n\nexport default function VideoPlayer(props: VideoPlayerProps) {\n  const {src} = props\n\n  const style: CSSProperties = {\n    width: '100%',\n    height: 'auto',\n  }\n\n  return (\n    // Cloudinary videos are user-uploaded and have no caption files to point a\n    // `<track>` at; a `src`-less `<track>` would be invalid HTML, so omit it.\n    // eslint-disable-next-line jsx-a11y/media-has-caption -- no captions available for arbitrary Cloudinary videos\n    <video controls aria-label=\"Cloudinary video preview\" style={style}>\n      <source src={src} type=\"video/mp4\" />\n    </video>\n  )\n}\n","import {useSecrets} from '@sanity/studio-secrets'\nimport {DiffFromTo} from 'sanity'\n\nimport type {CloudinaryAsset} from '../types'\nimport {assetUrl} from '../utils'\nimport {namespace, type Secrets} from './SecretsConfigView'\nimport VideoPlayer from './VideoPlayer'\n\ntype Props = {\n  value: CloudinaryAsset | undefined\n}\n\nconst CloudinaryDiffPreview = ({value}: Props) => {\n  const {secrets} = useSecrets<Secrets>(namespace)\n  const cloudName = secrets?.cloudName\n\n  if (!value) {\n    return null\n  }\n\n  const url = assetUrl(value, cloudName)\n\n  if (value.resource_type === 'video' && url) {\n    return (\n      <section\n        style={{\n          display: 'flex',\n          flexWrap: 'wrap',\n          justifyContent: 'space-between',\n        }}\n      >\n        <VideoPlayer src={url} kind=\"diff\" />\n      </section>\n    )\n  }\n\n  return <img alt=\"preview\" src={url} style={{maxWidth: '100%', height: 'auto'}} />\n}\n\ntype DiffProps = {\n  diff: any\n  schemaType: any\n}\n\nconst AssetDiff = ({diff, schemaType}: DiffProps) => {\n  return <DiffFromTo diff={diff} schemaType={schemaType} previewComponent={CloudinaryDiffPreview} />\n}\n\nexport default AssetDiff\n","import {DocumentIcon} from '@sanity/icons/Document'\nimport {useSecrets} from '@sanity/studio-secrets'\nimport {Flex, Text} from '@sanity/ui'\n\nimport type {CloudinaryAsset} from '../types'\nimport {assetUrl} from '../utils'\nimport {namespace, type Secrets} from './SecretsConfigView'\nimport VideoPlayer from './VideoPlayer'\n\ninterface ComponentProps {\n  layout?: 'default' | 'block'\n  value: CloudinaryAsset | undefined\n}\n\nconst AssetPreview = ({value, layout}: ComponentProps) => {\n  const {secrets} = useSecrets<Secrets>(namespace)\n  const cloudName = secrets?.cloudName\n\n  if (!value || !cloudName) {\n    return null\n  }\n\n  const url = assetUrl(value, cloudName)\n  if (!url) {\n    return null\n  }\n\n  switch (value.resource_type) {\n    case 'video':\n      return (\n        <Flex\n          align=\"center\"\n          style={{\n            maxWidth: layout === 'default' ? '80px' : '100%',\n          }}\n        >\n          <VideoPlayer src={url} kind=\"player\" />\n        </Flex>\n      )\n    case 'raw':\n      return (\n        <Flex align=\"center\">\n          <DocumentIcon />\n          <Text size={1} style={{marginLeft: '0.5em'}}>\n            {value.display_name ?? 'Raw file'}\n          </Text>\n        </Flex>\n      )\n    default: {\n      // Cloudinary returns resource_type as \"image\" even for PDFs, so we check\n      // the format to handle PDFs specifically: convert the first page to JPG\n      // and overlay a \"PDF\" label for thumbnail clarity.\n      const previewSrc =\n        value.format === 'pdf'\n          ? url.replace(\n              'image/upload',\n              'image/upload/f_jpg,pg_1,l_text:Verdana_75_letter_spacing_14:PDF',\n            )\n          : url\n\n      return layout === 'default' ? (\n        <Flex align=\"center\" justify=\"center\" style={{width: '100%'}}>\n          <img\n            alt=\"preview\"\n            src={previewSrc}\n            style={{maxWidth: '80px', height: 'auto', display: 'block'}}\n          />\n        </Flex>\n      ) : (\n        <div style={{width: '100%'}}>\n          <img\n            alt=\"preview\"\n            src={previewSrc}\n            style={{width: '100%', height: 'auto', display: 'block'}}\n          />\n        </div>\n      )\n    }\n  }\n}\n\nexport default AssetPreview\n","import {PlugIcon} from '@sanity/icons/Plug'\nimport {Button, Flex, Grid, Stack} from '@sanity/ui'\nimport {useCallback} from 'react'\nimport {type ObjectInputProps, PatchEvent, unset} from 'sanity'\nimport {styled} from 'styled-components'\n\nimport type {CloudinaryAsset} from '../types'\nimport AssetPreview from './AssetPreview'\n\nconst SetupButtonContainer = styled.div`\n  position: relative;\n  display: block;\n  font-size: 0.8em;\n  transform: translate(0%, -10%);\n`\n\ntype WidgetInputProps = ObjectInputProps & {openMediaSelector: () => void; onSetup: () => void}\n\nconst WidgetInput = (props: WidgetInputProps) => {\n  const {onChange, readOnly, value, openMediaSelector} = props\n\n  const removeValue = useCallback(() => {\n    onChange(PatchEvent.from([unset()]))\n  }, [onChange])\n\n  return (\n    <Stack>\n      <SetupButtonContainer>\n        <Flex flex={1} justify=\"flex-end\">\n          <Button\n            color=\"primary\"\n            icon={PlugIcon}\n            mode=\"bleed\"\n            title=\"Configure\"\n            onClick={props.onSetup}\n            tabIndex={0}\n          />\n        </Flex>\n      </SetupButtonContainer>\n\n      <Flex style={{textAlign: 'center', width: '100%'}} marginBottom={2}>\n        <AssetPreview value={value as CloudinaryAsset} />\n      </Flex>\n\n      <Grid gap={1} style={{gridTemplateColumns: 'repeat(auto-fit, minmax(100px, 1fr))'}}>\n        <Button\n          disabled={readOnly}\n          mode=\"ghost\"\n          title=\"Select an asset\"\n          tone=\"default\"\n          onClick={openMediaSelector}\n          text=\"Select…\"\n        />\n        <Button\n          disabled={readOnly || !value}\n          tone=\"critical\"\n          mode=\"ghost\"\n          title=\"Remove asset\"\n          text=\"Remove\"\n          onClick={removeValue}\n        />\n      </Grid>\n    </Stack>\n  )\n}\n\nexport default WidgetInput\n","import {useSecrets} from '@sanity/studio-secrets'\nimport {nanoid} from 'nanoid'\nimport {useCallback, useState} from 'react'\nimport {type ObjectInputProps, PatchEvent, set} from 'sanity'\n\nimport type {CloudinaryAsset, InsertHandlerParams} from '../types'\nimport {normalizeCloudinaryAsset, openMediaSelector} from '../utils'\nimport SecretsConfigView, {namespace, type Secrets} from './SecretsConfigView'\nimport WidgetInput from './WidgetInput'\n\nconst CloudinaryInput = (props: ObjectInputProps) => {\n  const [showSettings, setShowSettings] = useState(false)\n  const {secrets} = useSecrets<Secrets>(namespace)\n  const {onChange, schemaType: type} = props\n  const value = (props.value as CloudinaryAsset) || undefined\n  const valueKey = value?._key\n\n  const handleSelect = useCallback(\n    (payload: InsertHandlerParams) => {\n      const [asset] = payload.assets\n\n      if (!asset) {\n        return\n      }\n\n      onChange(\n        PatchEvent.from([\n          set({\n            _type: type.name,\n            _version: 1,\n            _key: valueKey || nanoid(),\n            ...normalizeCloudinaryAsset(asset),\n          }),\n        ]),\n      )\n    },\n    [onChange, type, valueKey],\n  )\n\n  const action = secrets\n    ? () =>\n        openMediaSelector(\n          secrets.cloudName,\n          secrets.apiKey,\n          false, // single selection\n          handleSelect,\n          value,\n        )\n    : () => setShowSettings(true)\n\n  return (\n    <>\n      {showSettings && <SecretsConfigView onClose={() => setShowSettings(false)} />}\n      <WidgetInput onSetup={() => setShowSettings(true)} openMediaSelector={action} {...props} />\n    </>\n  )\n}\n\nexport default CloudinaryInput\n","import {defineType} from 'sanity'\n\nimport AssetDiff from '../components/AssetDiff'\nimport AssetPreview from '../components/AssetPreview'\nimport CloudinaryInput from '../components/CloudinaryInput'\n\nexport const cloudinaryAssetSchema = defineType({\n  type: 'object',\n  name: 'cloudinary.asset',\n  fields: [\n    {\n      type: 'string',\n      name: 'id',\n      // Cloudinary asset id (used by cloudinaryAssetDocument lookups)\n    },\n    {\n      type: 'string',\n      name: 'public_id',\n    },\n    {\n      type: 'string',\n      name: 'resource_type',\n      // \"image\", \"?\"\n    },\n    {\n      type: 'string',\n      name: 'type',\n      // \"upload\", \"?\"\n    },\n    {\n      type: 'string',\n      name: 'format',\n      // \"jpg\"\n    },\n    {\n      type: 'number',\n      name: 'version',\n    },\n    {\n      type: 'url',\n      name: 'url',\n    },\n    {\n      type: 'url',\n      name: 'secure_url',\n    },\n    {\n      type: 'number',\n      name: 'width',\n    },\n    {\n      type: 'number',\n      name: 'height',\n    },\n    {\n      type: 'number',\n      name: 'bytes',\n    },\n    {\n      type: 'number',\n      name: 'duration',\n      // can be null\n    },\n    {\n      type: 'array',\n      name: 'tags',\n      of: [{type: 'string'}],\n    },\n    {\n      type: 'datetime',\n      name: 'created_at',\n    },\n    {\n      type: 'array',\n      name: 'derived',\n      of: [{type: 'cloudinary.assetDerived', name: 'derived'}],\n    },\n    {\n      type: 'string',\n      name: 'access_mode',\n    },\n    {\n      type: 'cloudinary.assetContext',\n      name: 'context',\n    },\n    // metadata array of unknown content\n  ],\n  // The custom preview component receives legacy props that don't match the\n  // PreviewProps type, so the components block is widened to keep type checking happy.\n  ...({\n    components: {\n      input: CloudinaryInput,\n      diff: AssetDiff,\n      preview: AssetPreview,\n    },\n  } as {}),\n  preview: {\n    select: {\n      url: 'url',\n      resource_type: 'resource_type',\n      derived: 'derived.0.url',\n    },\n    prepare({url, derived, resource_type}) {\n      return {\n        title: url,\n        value: {\n          title: url,\n          resource_type,\n          url: derived || url,\n        },\n      }\n    },\n  },\n})\n","import {PlugIcon} from '@sanity/icons/Plug'\nimport {useSecrets} from '@sanity/studio-secrets'\nimport {Box, Button, Flex} from '@sanity/ui'\nimport {useCallback, useState} from 'react'\nimport {\n  type ArrayInputFunctionsProps,\n  ArrayOfObjectsFunctions,\n  type ArraySchemaType,\n  insert,\n  type ObjectSchemaType,\n  PatchEvent,\n  setIfMissing,\n} from 'sanity'\n\nimport {cloudinaryAssetSchema} from '../schema/cloudinaryAsset'\nimport type {InsertHandlerParams} from '../types'\nimport {openMediaSelector} from '../utils'\nimport SecretsConfigView, {namespace} from './SecretsConfigView'\n\ninterface ApiConfig {\n  cloudName: string\n  apiKey: string\n}\n\nexport const AssetListFunctions = (\n  props: ArrayInputFunctionsProps<{_key: string}, ArraySchemaType>,\n) => {\n  const {onValueCreate, onChange} = props\n\n  const {secrets, loading} = useSecrets<ApiConfig>(namespace)\n  const [showSettings, setShowSettings] = useState(false)\n\n  const show = useCallback(() => setShowSettings(true), [setShowSettings])\n  const hide = useCallback(() => setShowSettings(false), [setShowSettings])\n\n  const cloudinaryType = props.schemaType.of.find(\n    (t: {name: string}) => t.name === cloudinaryAssetSchema.name,\n  ) as ObjectSchemaType | undefined\n\n  if (!cloudinaryType) {\n    throw new Error(`AssetListFunctions can only be used in array.of ${\n      cloudinaryAssetSchema.name\n    }, but it was array.of\n    ${props.schemaType.of.map((t) => t.name).join(', ')}`)\n  }\n\n  const handleSelect = useCallback(\n    (selected: InsertHandlerParams) => {\n      const items = selected.assets.map((asset) =>\n        Object.assign(\n          {},\n          asset,\n          {\n            // Schema version. In case we ever change our schema.\n            _version: 1,\n          },\n          onValueCreate(cloudinaryType as any), // onValueCreate is mistyped\n        ),\n      )\n      onChange(PatchEvent.from([setIfMissing([]), insert(items, 'after', [-1])]))\n    },\n    [onValueCreate, onChange, cloudinaryType],\n  )\n\n  const handleOpenSelector = useCallback(\n    () =>\n      secrets &&\n      openMediaSelector(\n        secrets.cloudName,\n        secrets.apiKey,\n        true, // multi-selection\n        handleSelect,\n      ),\n    [secrets, handleSelect],\n  )\n  return (\n    <Flex gap={2} flex={1}>\n      {showSettings && <SecretsConfigView onClose={hide} />}\n      <Box flex={1}>\n        <ArrayOfObjectsFunctions {...props} />\n      </Box>\n      {cloudinaryType && (\n        <>\n          <Box flex={1}>\n            <Button\n              style={{width: '100%'}}\n              disabled={props.readOnly || loading}\n              mode=\"bleed\"\n              text=\"Add multiple\"\n              onClick={handleOpenSelector}\n            />\n          </Box>\n          <Box>\n            <Button onClick={show} icon={PlugIcon} mode=\"bleed\" title={'Configure'} />\n          </Box>\n        </>\n      )}\n    </Flex>\n  )\n}\n","import {defineType} from 'sanity'\n\nexport interface CloudinaryAssetContext {\n  custom: object\n}\n\nexport const cloudinaryAssetContext = defineType({\n  type: 'object',\n  name: 'cloudinary.assetContext',\n  fields: [\n    {\n      type: 'cloudinary.assetContextCustom',\n      name: 'custom',\n    },\n  ],\n})\n","import {defineType} from 'sanity'\n\nexport type CloudinaryAssetContextCustom = {\n  alt: string\n  caption: string\n}\n\nexport const cloudinaryAssetContextCustom = defineType({\n  type: 'object',\n  name: 'cloudinary.assetContextCustom',\n  fields: [\n    {\n      type: 'string',\n      name: 'alt',\n    },\n    {\n      type: 'string',\n      name: 'caption',\n    },\n  ],\n})\n","import {defineType} from 'sanity'\n\nexport type CloudinaryAssetDerived = {\n  raw_transformation: string\n  url: string\n  secure_url: string\n}\n\nexport const cloudinaryAssetDerivedSchema = defineType({\n  type: 'object',\n  name: 'cloudinary.assetDerived',\n  fields: [\n    {\n      type: 'string',\n      name: 'raw_transformation',\n    },\n    {\n      type: 'url',\n      name: 'url',\n    },\n    {\n      type: 'url',\n      name: 'secure_url',\n    },\n  ],\n})\n","import {defineType} from 'sanity'\n\nimport {cloudinaryAssetSchema} from './cloudinaryAsset'\n\nexport const cloudinaryAssetDocument = defineType({\n  name: 'cloudinaryAssetDocument',\n  title: 'Cloudinary Asset',\n  type: 'document',\n  // Shared assets are patched in place by the reference input; liveEdit avoids\n  // desk drafts that could later publish over those updates.\n  liveEdit: true,\n  fields: [\n    {\n      name: 'asset',\n      type: cloudinaryAssetSchema.name,\n      title: 'Cloudinary Asset',\n    },\n  ],\n  preview: {\n    select: {\n      caption: 'asset.context.custom.caption',\n      alt: 'asset.context.custom.alt',\n      publicId: 'asset.public_id',\n      resourceType: 'asset.resource_type',\n      format: 'asset.format',\n      // Desk list `media` needs a URL (or React element), not the raw asset object\n      secureUrl: 'asset.secure_url',\n      url: 'asset.url',\n      derivedUrl: 'asset.derived.0.secure_url',\n    },\n    prepare(selection) {\n      const {caption, alt, publicId, resourceType, format, secureUrl, url, derivedUrl} =\n        selection as {\n          caption?: string\n          alt?: string\n          publicId?: string\n          resourceType?: string\n          format?: string\n          secureUrl?: string\n          url?: string\n          derivedUrl?: string\n        }\n\n      // Prefer caption/alt from Cloudinary context; fall back to public_id\n      const title = caption || alt || publicId || 'Untitled Asset'\n\n      const type = resourceType || 'image'\n      const formatInfo = format ? `(${format})` : ''\n      const subtitle = `${type} ${formatInfo}`\n\n      let media = derivedUrl || secureUrl || url\n      // Desk/list media is rendered as an <img>; only pass image (and PDF) URLs\n      if (type !== 'image' || !media) {\n        media = undefined\n      } else if (format === 'pdf') {\n        media = media.replace(\n          'image/upload',\n          'image/upload/f_jpg,pg_1,l_text:Verdana_75_letter_spacing_14:PDF',\n        )\n      }\n\n      return {\n        title,\n        subtitle,\n        media,\n      }\n    },\n  },\n})\n","import {useEffect, useState} from 'react'\nimport {useClient} from 'sanity'\n\nimport type {CloudinaryAsset} from '../types'\nimport AssetPreview from './AssetPreview'\n\nconst API_VERSION = '2023-01-01'\n\ninterface ReferencePreviewProps {\n  value?: {_ref?: string}\n  /** Bump to force a refetch when the referenced document is updated in place */\n  revision?: number\n}\n\nconst ReferencePreview = (props: ReferencePreviewProps) => {\n  const {value, revision = 0} = props\n  const client = useClient({apiVersion: API_VERSION})\n  const ref = value?._ref\n  const [result, setResult] = useState<{\n    ref: string\n    revision: number\n    asset: CloudinaryAsset | null\n  } | null>(null)\n\n  useEffect(() => {\n    if (!ref) {\n      return undefined\n    }\n\n    let cancelled = false\n    client\n      .getDocument<{asset?: CloudinaryAsset}>(ref)\n      .then((document) => {\n        if (!cancelled) {\n          setResult({ref, revision, asset: document?.asset ?? null})\n        }\n        return null\n      })\n      .catch((err) => {\n        if (!cancelled) {\n          setResult({ref, revision, asset: null})\n        }\n        console.error('Error fetching referenced asset:', err)\n      })\n\n    return () => {\n      cancelled = true\n    }\n  }, [ref, client, revision])\n\n  if (!ref) {\n    return null\n  }\n\n  // Derive loading/asset from the fetched result for the current ref+revision\n  if (result?.ref !== ref || result.revision !== revision) {\n    return <div>Loading asset...</div>\n  }\n\n  if (!result.asset) {\n    return null\n  }\n\n  return <AssetPreview value={result.asset} layout=\"block\" />\n}\n\nexport default ReferencePreview\n","import {PlugIcon} from '@sanity/icons/Plug'\nimport {useSecrets} from '@sanity/studio-secrets'\nimport {Button, Flex, Grid, Stack} from '@sanity/ui'\nimport {nanoid} from 'nanoid'\nimport {useCallback, useMemo, useRef, useState} from 'react'\nimport {type ObjectInputProps, getPublishedId, PatchEvent, set, unset, useClient} from 'sanity'\n\nimport {cloudinaryAssetSchema} from '../schema/cloudinaryAsset'\nimport type {InsertHandlerParams} from '../types'\nimport {normalizeCloudinaryAsset, openMediaSelector} from '../utils'\nimport ReferencePreview from './ReferencePreview'\nimport SecretsConfigView, {namespace, type Secrets} from './SecretsConfigView'\n\nconst API_VERSION = '2023-01-01'\n\n// Fallback so the button doesn't stay disabled if the media library never reports it opened\nconst SELECTOR_FALLBACK_TIMEOUT = 30_000\n\ntype FolderOption = {path?: string; resource_type?: 'image' | 'video'}\n\ntype ReferenceValue = {\n  _key?: string\n  _type?: string\n  asset?: {_type?: 'reference'; _ref?: string; _weak?: boolean}\n}\n\nconst CloudinaryReferenceInput = (props: ObjectInputProps) => {\n  const {onChange, value, schemaType, readOnly} = props\n  const [showSettings, setShowSettings] = useState(false)\n  const [isLoading, setIsLoading] = useState(false)\n  const [previewRevision, setPreviewRevision] = useState(0)\n  const fallbackTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n  const saveInProgressRef = useRef(false)\n  const {secrets, loading: secretsLoading} = useSecrets<Secrets>(namespace)\n  const client = useClient({apiVersion: API_VERSION})\n  // Lookups should see published docs only so we never store drafts.* in _ref\n  const publishedClient = useMemo(() => client.withConfig({perspective: 'published'}), [client])\n\n  const cloudName = secrets?.cloudName\n  const apiKey = secrets?.apiKey\n  const hasConfig = Boolean(apiKey && cloudName)\n  const currentValue = value as ReferenceValue | undefined\n  const valueKey = currentValue?._key\n  const schemaTypeName = schemaType.name\n  const actionsDisabled = Boolean(readOnly) || isLoading || secretsLoading\n\n  const folder = (schemaType.options as {folder?: FolderOption} | undefined)?.folder\n  const folderOption = useMemo(\n    () =>\n      folder?.path || folder?.resource_type\n        ? {path: folder.path, resource_type: folder.resource_type}\n        : undefined,\n    [folder],\n  )\n\n  const setAssetReference = useCallback(\n    (documentId: string) => {\n      onChange(\n        PatchEvent.from(\n          set({\n            _type: schemaTypeName,\n            // Preserve array item identity when this field is used inside an array\n            ...(valueKey ? {_key: valueKey} : {}),\n            asset: {\n              _type: 'reference',\n              _ref: getPublishedId(documentId),\n              _weak: true,\n            },\n          }),\n        ),\n      )\n    },\n    [onChange, schemaTypeName, valueKey],\n  )\n\n  const handleSelect = useCallback(\n    async (payload: InsertHandlerParams) => {\n      if (readOnly) {\n        return\n      }\n\n      const [asset] = payload.assets\n\n      if (!asset) {\n        return\n      }\n\n      const normalizedAsset: Record<string, unknown> = {\n        _type: cloudinaryAssetSchema.name,\n        _key: nanoid(),\n        _version: 1,\n        ...normalizeCloudinaryAsset(asset),\n      }\n\n      setIsLoading(true)\n      saveInProgressRef.current = true\n      try {\n        type ExistingAssetDoc = {_id: string; asset?: {id?: string}}\n\n        // Prefer Cloudinary asset `id` when present; if that misses (or id is\n        // absent), fall back to public_id + resource_type + type so we still\n        // reuse an existing shared document.\n        let existingAsset: ExistingAssetDoc | null = null\n\n        if (asset.id) {\n          existingAsset = await publishedClient.fetch<ExistingAssetDoc | null>(\n            `*[_type == \"cloudinaryAssetDocument\" && asset.id == $id][0]{_id, asset}`,\n            {id: asset.id},\n          )\n        }\n\n        if (!existingAsset && asset.public_id) {\n          existingAsset = await publishedClient.fetch<ExistingAssetDoc | null>(\n            `*[_type == \"cloudinaryAssetDocument\" && asset.public_id == $publicId && asset.resource_type == $resourceType && asset.type == $type][0]{_id, asset}`,\n            {\n              publicId: asset.public_id,\n              resourceType: asset.resource_type,\n              type: asset.type,\n            },\n          )\n        }\n\n        if (existingAsset) {\n          const publishedId = getPublishedId(existingAsset._id)\n          // Preserve a previously stored Cloudinary id if this selection omits it\n          const assetToStore =\n            normalizedAsset['id'] || !existingAsset.asset?.id\n              ? normalizedAsset\n              : {...normalizedAsset, id: existingAsset.asset.id}\n\n          await client.patch(publishedId).set({asset: assetToStore}).commit()\n          setAssetReference(publishedId)\n        } else {\n          // Create a new asset document and reference it (let Sanity assign a valid _id)\n          const newAsset = await client.create({\n            _type: 'cloudinaryAssetDocument',\n            asset: normalizedAsset,\n          })\n          setAssetReference(newAsset._id)\n        }\n\n        // Force preview refresh when the same document is updated in place\n        setPreviewRevision((revision) => revision + 1)\n      } catch (err) {\n        console.error('Error creating/updating Cloudinary asset:', err)\n      } finally {\n        saveInProgressRef.current = false\n        setIsLoading(false)\n      }\n    },\n    [readOnly, client, publishedClient, setAssetReference],\n  )\n\n  const handleOpenSelector = useCallback(() => {\n    if (readOnly || secretsLoading) {\n      return\n    }\n\n    if (!cloudName || !apiKey) {\n      setShowSettings(true)\n      return\n    }\n\n    setIsLoading(true)\n\n    if (fallbackTimerRef.current) {\n      clearTimeout(fallbackTimerRef.current)\n    }\n\n    try {\n      openMediaSelector(\n        cloudName,\n        apiKey,\n        false, // single selection\n        (payload) => {\n          if (fallbackTimerRef.current) {\n            clearTimeout(fallbackTimerRef.current)\n            fallbackTimerRef.current = undefined\n          }\n          // handleSelect manages isLoading for the create/patch work\n          void handleSelect(payload)\n        },\n        undefined,\n        () => {\n          // Don't clear loading while create/patch is in flight — closing the\n          // library after insert can fire showHandler mid-save.\n          if (saveInProgressRef.current) {\n            return\n          }\n          setIsLoading(false)\n        },\n        folderOption,\n      )\n\n      fallbackTimerRef.current = setTimeout(() => {\n        if (!saveInProgressRef.current) {\n          setIsLoading(false)\n        }\n      }, SELECTOR_FALLBACK_TIMEOUT)\n    } catch (error) {\n      console.error('Error opening Cloudinary media selector:', error)\n      setIsLoading(false)\n    }\n  }, [readOnly, secretsLoading, cloudName, apiKey, handleSelect, folderOption])\n\n  const reference = currentValue?.asset\n\n  let selectButtonText = 'Configure Cloudinary to Select Assets'\n  if (secretsLoading) {\n    selectButtonText = 'Loading Cloudinary config...'\n  } else if (hasConfig) {\n    selectButtonText = isLoading ? 'Opening Media Library...' : 'Select Asset'\n  }\n\n  return (\n    <Stack gap={3}>\n      {showSettings && <SecretsConfigView onClose={() => setShowSettings(false)} />}\n\n      <Flex justify=\"flex-end\">\n        <Button\n          color=\"primary\"\n          icon={PlugIcon}\n          mode=\"bleed\"\n          title=\"Configure\"\n          onClick={() => setShowSettings(true)}\n          text={hasConfig || secretsLoading ? undefined : 'Configure Cloudinary plugin'}\n          disabled={Boolean(readOnly) || secretsLoading}\n        />\n      </Flex>\n\n      <Flex marginBottom={2} style={{textAlign: 'center', width: '100%'}}>\n        <ReferencePreview value={reference} revision={previewRevision} />\n      </Flex>\n\n      <Stack gap={2}>\n        <Grid gap={1} style={{gridTemplateColumns: 'repeat(auto-fit, minmax(100px, 1fr))'}}>\n          <Button\n            text={selectButtonText}\n            onClick={handleOpenSelector}\n            tone=\"primary\"\n            mode=\"ghost\"\n            disabled={actionsDisabled}\n            loading={isLoading || secretsLoading}\n          />\n\n          {reference?._ref ? (\n            <Button\n              text=\"Remove\"\n              tone=\"critical\"\n              mode=\"ghost\"\n              onClick={() => onChange(PatchEvent.from(unset()))}\n              disabled={actionsDisabled}\n            />\n          ) : null}\n        </Grid>\n      </Stack>\n    </Stack>\n  )\n}\n\nexport default CloudinaryReferenceInput\n","import {defineType} from 'sanity'\n\nimport CloudinaryReferenceInput from '../components/CloudinaryReferenceInput'\n\nexport const cloudinaryAssetReference = defineType({\n  name: 'cloudinaryAssetReference',\n  title: 'Cloudinary Asset Reference',\n  type: 'object',\n  fields: [\n    {\n      name: 'asset',\n      type: 'reference',\n      to: [{type: 'cloudinaryAssetDocument'}],\n      weak: true,\n    },\n  ],\n  components: {\n    input: CloudinaryReferenceInput,\n  },\n  preview: {\n    select: {\n      caption: 'asset.asset.context.custom.caption',\n      alt: 'asset.asset.context.custom.alt',\n      publicId: 'asset.asset.public_id',\n      resourceType: 'asset.asset.resource_type',\n      format: 'asset.asset.format',\n      secureUrl: 'asset.asset.secure_url',\n      url: 'asset.asset.url',\n      derivedUrl: 'asset.asset.derived.0.secure_url',\n    },\n    prepare(selection) {\n      const {caption, alt, publicId, resourceType, format, secureUrl, url, derivedUrl} =\n        selection as {\n          caption?: string\n          alt?: string\n          publicId?: string\n          resourceType?: string\n          format?: string\n          secureUrl?: string\n          url?: string\n          derivedUrl?: string\n        }\n\n      const title = caption || alt || publicId || 'Untitled Asset'\n      const type = resourceType || 'image'\n      const formatInfo = format ? `(${format})` : ''\n      const subtitle = `${type} ${formatInfo}`\n\n      let media = derivedUrl || secureUrl || url\n      // Desk/list media is rendered as an <img>; only pass image (and PDF) URLs\n      if (type !== 'image' || !media) {\n        media = undefined\n      } else if (format === 'pdf') {\n        media = media.replace(\n          'image/upload',\n          'image/upload/f_jpg,pg_1,l_text:Verdana_75_letter_spacing_14:PDF',\n        )\n      }\n\n      return {\n        title,\n        subtitle,\n        media,\n      }\n    },\n  },\n})\n","import '@sanity/ui/styles.css'\nimport {type AssetSource, definePlugin, isArrayOfObjectsInputProps} from 'sanity'\n\nimport {CloudinaryAssetSource} from './components/asset-source/CloudinaryAssetSource'\nimport {CloudinaryIcon} from './components/asset-source/Icon'\nimport {AssetListFunctions} from './components/AssetListFunctions'\nimport {cloudinaryAssetSchema} from './schema/cloudinaryAsset'\nimport {cloudinaryAssetContext} from './schema/cloudinaryAssetContext'\nimport {cloudinaryAssetContextCustom} from './schema/cloudinaryAssetContextCustom'\nimport {cloudinaryAssetDerivedSchema} from './schema/cloudinaryAssetDerived'\nimport {cloudinaryAssetDocument} from './schema/cloudinaryAssetDocument'\nimport {cloudinaryAssetReference} from './schema/cloudinaryAssetReference'\n\nexport {type CloudinaryAssetContext} from './schema/cloudinaryAssetContext'\nexport {type CloudinaryAssetDerived} from './schema/cloudinaryAssetDerived'\nexport {type CloudinaryAssetContextCustom} from './schema/cloudinaryAssetContextCustom'\n\nexport type {AssetDocument, CloudinaryAsset} from './types'\n\nexport {\n  cloudinaryAssetSchema,\n  cloudinaryAssetDerivedSchema,\n  cloudinaryAssetContext,\n  cloudinaryAssetContextCustom,\n  cloudinaryAssetDocument,\n  cloudinaryAssetReference,\n}\n\nexport const cloudinaryReferencePlugin = definePlugin({\n  name: 'cloudinary-reference',\n  schema: {\n    types: [\n      cloudinaryAssetDocument,\n      cloudinaryAssetReference,\n      cloudinaryAssetSchema,\n      cloudinaryAssetDerivedSchema,\n      cloudinaryAssetContext,\n      cloudinaryAssetContextCustom,\n    ],\n  },\n})\n\nexport const cloudinarySchemaPlugin = definePlugin({\n  name: 'cloudinary-schema',\n  form: {\n    components: {\n      input: (props) => {\n        if (isArrayOfObjectsInputProps(props)) {\n          const cloudinaryType = props.schemaType.of.find(\n            (t: {name: string}) => t.name === cloudinaryAssetSchema.name,\n          )\n          if (cloudinaryType) {\n            return props.renderDefault({...props, arrayFunctions: AssetListFunctions})\n          }\n        }\n        return props.renderDefault(props)\n      },\n    },\n  },\n  schema: {\n    types: [\n      cloudinaryAssetSchema,\n      cloudinaryAssetDerivedSchema,\n      cloudinaryAssetContext,\n      cloudinaryAssetContextCustom,\n    ],\n  },\n})\n\nexport const cloudinaryImageSource: AssetSource = {\n  name: 'cloudinary-image',\n  // oxlint-disable-next-line no-deprecated -- `i18nKey` requires a locale bundle; a plain title is intentional here\n  title: 'Cloudinary',\n  icon: CloudinaryIcon,\n  component: CloudinaryAssetSource,\n}\n\nexport const cloudinaryAssetSourcePlugin = definePlugin({\n  name: 'cloudinary-asset-source',\n  form: {\n    image: {\n      assetSources: [cloudinaryImageSource],\n    },\n  },\n})\n"],"mappings":";;;;;;;;;;;;;AAWA,MAAMQ,YAAY;AAElB,SAAgBC,SACdC,OAMAG,WACoB;CACpB,IAAM,CAACC,WAAWJ,MAAMI,WAAW,CAAA;CAiCnC,OArBED,aACAH,MAAMK,aACN,CAACD,WACDJ,MAAMM,kBAAkB,WACxBN,MAAMM,kBAAkB,UACvB,CAACN,MAAMO,QAAQP,MAAMO,SAAS,YAExB,IAAIhB,gBAAgBS,MAAMK,WAAW,IAAIf,YAAY,EAACa,UAAS,CAAC,CAAC,CAAC,CACtEK,OAAOhB,MAAM,CAAC,CAACiB,MAAM,GAAG,CAAC,CAAC,CAC1BC,MAAM,IAGPN,UACEA,QAAQO,aACHP,QAAQO,aAEVP,QAAQQ,MAEbZ,MAAMW,aACDX,MAAMW,aAERX,MAAMY;AACf;;;;;AAMA,SAAgBC,yBAAyBb,OAAyD;CAChG,IAAMe,oBAAoBC,OAAOC,YAC/BD,OAAOE,QAAQlB,KAAK,CAAC,CAACmB,QAAQ,CAACC,GAAGC,gBAAgBA,eAAe,IAAI,CACvE,GAEMC,iBAAiB;EACrBjB,WAAWL,MAAMK;EACjBC,eAAeN,MAAMM;EACrBC,MAAMP,MAAMO;EACZK,KAAKZ,MAAMY;EACXD,YAAYX,MAAMW;EAClBY,QAAQvB,MAAMuB;EACdd,OAAOT,MAAMS;EACbe,QAAQxB,MAAMwB;EACdC,OAAOzB,MAAMyB;EACbC,MAAM1B,MAAM0B;CACd,GAEIC,eAAwC;EAC1C,GAAGZ;EACH,GAAGO;CACL;CAUA,IALItB,MAAM4B,OACRD,aAAa,KAAQ3B,MAAM4B,KAIzB5B,MAAM6B,SA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AMM,cAAc;EAAC,GAAGN;EAAOO,gBAAgB3B;CAAkB,CAAC,IAGtEoB,MAAMM,cAAcN,KAAK,EAEpC,EACF;CACAN,QAAQ,EACNC,OAAO;EACLd;EACAG;EACAF;EACAC;CAA4B,EAEhC;AACF,CAAC,GAEYyB,wBAAqC;CAChDf,MAAM;CAENgB,OAAO;CACPC,MAAM/B;CACNgC,WAAWjC;AACb,GAEakC,8BAA8BpC,aAAa;CACtDiB,MAAM;CACNI,MAAM,EACJgB,OAAO,EACLC,cAAc,CAACN,qBAAqB,EACtC,EACF;AACF,CAAC"}
\ No newline at end of file
Index: package/dist/index.d.ts
===================================================================
--- package/dist/index.d.ts
+++ package/dist/index.d.ts
@@ -1,33 +1,65 @@
-import { AssetSource } from "sanity";
+import "@sanity/ui/styles.css";
+import { AssetSource, ObjectInputProps } from "sanity";
 declare const cloudinaryAssetSchema: {
   type: "object";
   name: "cloudinary.asset";
-} & Omit<import("sanity").ObjectDefinition, "preview"> & {
-  preview?: import("sanity").PreviewConfig<{
-    url: string;
-    resource_type: string;
-    derived: string;
-  }, Record<"derived" | "resource_type" | "url", any>> | undefined;
+  fields: ({
+    type: "array";
+    name: string;
+    of: {
+      type: "string";
+    }[];
+  } | {
+    type: "array";
+    name: string;
+    of: {
+      type: string;
+      name: string;
+    }[];
+  } | {
+    of?: undefined;
+    type: string;
+    name: string;
+  })[];
+  preview: {
+    select: {
+      url: string;
+      resource_type: string;
+      derived: string;
+    };
+    prepare({ url, derived, resource_type }: Record<"derived" | "resource_type" | "url", any>): {
+      title: any;
+      value: {
+        title: any;
+        resource_type: any;
+        url: any;
+      };
+    };
+  };
 };
 interface CloudinaryAssetContext {
   custom: object;
 }
 declare const cloudinaryAssetContext: {
   type: "object";
   name: "cloudinary.assetContext";
-} & Omit<import("sanity").ObjectDefinition, "preview"> & {
-  preview?: import("sanity").PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
+  fields: {
+    type: string;
+    name: string;
+  }[];
 };
 type CloudinaryAssetContextCustom = {
   alt: string;
   caption: string;
 };
 declare const cloudinaryAssetContextCustom: {
   type: "object";
   name: "cloudinary.assetContextCustom";
-} & Omit<import("sanity").ObjectDefinition, "preview"> & {
-  preview?: import("sanity").PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
+  fields: {
+    type: "string";
+    name: string;
+  }[];
 };
 type CloudinaryAssetDerived = {
   raw_transformation: string;
   url: string;
@@ -35,40 +67,77 @@
 };
 declare const cloudinaryAssetDerivedSchema: {
   type: "object";
   name: "cloudinary.assetDerived";
-} & Omit<import("sanity").ObjectDefinition, "preview"> & {
-  preview?: import("sanity").PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
+  fields: ({
+    type: "string";
+    name: string;
+  } | {
+    type: "url";
+    name: string;
+  })[];
 };
 declare const cloudinaryAssetDocument: {
-  type: "document";
   name: "cloudinaryAssetDocument";
-} & Omit<import("sanity").DocumentDefinition, "preview"> & {
-  preview?: import("sanity").PreviewConfig<{
-    caption: string;
-    alt: string;
-    publicId: string;
-    resourceType: string;
-    format: string;
-    secureUrl: string;
-    url: string;
-    derivedUrl: string;
-  }, Record<"alt" | "caption" | "derivedUrl" | "format" | "publicId" | "resourceType" | "secureUrl" | "url", any>> | undefined;
+  title: string;
+  type: "document";
+  liveEdit: true;
+  fields: {
+    name: string;
+    type: "cloudinary.asset";
+    title: string;
+  }[];
+  preview: {
+    select: {
+      caption: string;
+      alt: string;
+      publicId: string;
+      resourceType: string;
+      format: string;
+      secureUrl: string;
+      url: string;
+      derivedUrl: string;
+    };
+    prepare(selection: Record<"alt" | "caption" | "derivedUrl" | "format" | "publicId" | "resourceType" | "secureUrl" | "url", any>): {
+      title: string;
+      subtitle: string;
+      media: string | undefined;
+    };
+  };
 };
+declare const CloudinaryReferenceInput: (props: ObjectInputProps) => import("react").JSX.Element;
 declare const cloudinaryAssetReference: {
-  type: "object";
   name: "cloudinaryAssetReference";
-} & Omit<import("sanity").ObjectDefinition, "preview"> & {
-  preview?: import("sanity").PreviewConfig<{
-    caption: string;
-    alt: string;
-    publicId: string;
-    resourceType: string;
-    format: string;
-    secureUrl: string;
-    url: string;
-    derivedUrl: string;
-  }, Record<"alt" | "caption" | "derivedUrl" | "format" | "publicId" | "resourceType" | "secureUrl" | "url", any>> | undefined;
+  title: string;
+  type: "object";
+  fields: {
+    name: string;
+    type: "reference";
+    to: {
+      type: string;
+    }[];
+    weak: true;
+  }[];
+  components: {
+    input: typeof CloudinaryReferenceInput;
+  };
+  preview: {
+    select: {
+      caption: string;
+      alt: string;
+      publicId: string;
+      resourceType: string;
+      format: string;
+      secureUrl: string;
+      url: string;
+      derivedUrl: string;
+    };
+    prepare(selection: Record<"alt" | "caption" | "derivedUrl" | "format" | "publicId" | "resourceType" | "secureUrl" | "url", any>): {
+      title: string;
+      subtitle: string;
+      media: string | undefined;
+    };
+  };
 };
 interface CloudinaryMediaLibrary {
   show: (config?: {
     asset: any;