@nocode-factory/sanity-kit 2.60.0 → 2.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
1
  import {createDataAttribute} from '@sanity/visual-editing/create-data-attribute'
2
2
  import {resolveEditInfo, studioPath, type ContentSourceMap, type ContentSourceMapParsedPath} from '@sanity/client/csm'
3
3
  import {vercelStegaClean} from '@vercel/stega'
4
- import {retagInheritedList, type InheritedEdit} from './inherited'
4
+ import {retag, retagInheritedList, type InheritedEdit} from './inherited'
5
+ import {vercelStegaDecode} from '@vercel/stega'
5
6
 
6
7
  /**
7
8
  * ÉDITION DANS L'APERÇU, IMAGES (mode brouillon seulement) : chaque image est
@@ -30,9 +31,11 @@ export type ImageEditValue = {
30
31
  _editPath?: string
31
32
  _editDoc?: string
32
33
  _editType?: string
34
+ /** Image héritée DANS une valeur par défaut (liste...) : champ à recopier d'abord. */
35
+ _editInherited?: {path: string; sourceId: string; sourcePath: string}
33
36
  } | null | undefined
34
37
 
35
- type Marked = {asset: {_ref: string}; _editTarget?: string; _editPath?: string; _editDoc?: string; _editType?: string}
38
+ type Marked = {asset: {_ref: string}; _editTarget?: string; _editPath?: string; _editDoc?: string; _editType?: string; _editInherited?: {path: string; sourceId: string; sourcePath: string}; _editDefaults?: {id: string; path: string}}
36
39
  type Segment = ContentSourceMapParsedPath[number]
37
40
 
38
41
  function isImageValue(value: unknown): value is Marked {
@@ -71,10 +74,16 @@ export function annotateImageEditTargets<T>(data: T, sourceMap: ContentSourceMap
71
74
  const defaultsType = options.defaultsType ?? 'componentDefaults'
72
75
  const fromSourceMap = (value: Marked, path: ContentSourceMapParsedPath) => {
73
76
  const info = resolveEditInfo({studioUrl: options.studioUrl, resultSourceMap: sourceMap, resultPath: [...path, 'asset', '_ref']})
74
- if (!info || info.type === defaultsType) return
77
+ if (!info) return
75
78
  const full = typeof info.path === 'string' ? info.path : studioPath.toString(info.path as never)
76
79
  const imagePath = full.replace(/\.asset\._ref$/, '')
77
80
  if (!imagePath || imagePath === full) return
81
+ // Image des valeurs par défaut : pas de repère (il modifierait TOUTES les pages), mais
82
+ // sa source brute, pour la recopier dans la page au remplacement.
83
+ if (info.type === defaultsType) {
84
+ value._editDefaults = {id: info.id.replace(/^drafts\./, ''), path: imagePath}
85
+ return
86
+ }
78
87
  mark(value, info.id, info.type, imagePath, {
79
88
  baseUrl: info.baseUrl,
80
89
  workspace: info.workspace,
@@ -129,18 +138,80 @@ export function withPreviewEditTargets(onInherit: OnInherit, source: Source, key
129
138
  }
130
139
  return (value, path) => {
131
140
  const out = onInherit(value, path)
132
- if (out && typeof out === 'object' && !Array.isArray(out)) {
133
- const copy = isImageValue(out) ? {...out} : out
134
- markInherited(copy, `${base}.${path.join('.')}`)
141
+ const entryPath = `${base}.${path.join('.')}`
142
+ if (typeof out === 'string') {
143
+ collected.push({path: entryPath, value: vercelStegaClean(out)})
144
+ return out
145
+ }
146
+ if (!out || typeof out !== 'object') return out
147
+ // Image héritée seule : elle vise le champ de l'instance (choisir crée l'image de la page).
148
+ if (isImageValue(out)) {
149
+ const copy = {...out}
150
+ markInherited(copy, entryPath)
135
151
  return copy
136
152
  }
137
- if (typeof out === 'string') collected.push({path: `${base}.${path.join('.')}`, value: vercelStegaClean(out)})
138
- // Liste héritée directement par un champ de la section (le parent existe dans la page).
139
- if (Array.isArray(out) && path.length === 1) return retagInheritedList(out, `${base}.${path[0]}`, source, collected)
153
+ // Valeur héritée de N'IMPORTE QUELLE forme (liste, objet) : chaque texte et chaque image
154
+ // vise son chemin EXACT dans la page ; à la première modification, la valeur brute des
155
+ // valeurs par défaut est recopiée dans la page (source lue dans les marqueurs).
156
+ const raw = defaultsSourceOf(value, path[path.length - 1] as string)
157
+ if (raw) {
158
+ collected.push({path: entryPath, source: raw})
159
+ return retagDeep(out, entryPath, {...source, id: pageId}, {path: entryPath, sourceId: raw.id, sourcePath: raw.path}, options)
160
+ }
161
+ // Sans source repérable : l'ancienne règle (listes simples seulement).
162
+ if (Array.isArray(out) && path.length === 1) return retagInheritedList(out, entryPath, source, collected)
163
+ markInherited(out, entryPath)
140
164
  return out
141
165
  }
142
166
  }
143
167
 
168
+ /** Champ des valeurs par défaut d'où vient une valeur héritée : lu dans un texte (stega) ou une image. */
169
+ function defaultsSourceOf(value: unknown, field: string): {id: string; path: string} | null {
170
+ let found: {id: string; full: string} | null = null
171
+ const visit = (v: unknown) => {
172
+ if (found || v === null || v === undefined) return
173
+ if (typeof v === 'string') {
174
+ const info = vercelStegaDecode(v) as {href?: string} | undefined
175
+ if (!info?.href) return
176
+ const href = decodeURIComponent(info.href)
177
+ const id = /[;/]id=([^;?&]+)/.exec(href)?.[1]
178
+ const full = /;path=([^;?&]+)/.exec(href)?.[1]
179
+ if (id && full) found = {id: id.replace(/^drafts\./, ''), full}
180
+ return
181
+ }
182
+ if (Array.isArray(v)) return v.forEach(visit)
183
+ if (typeof v === 'object') {
184
+ const d = (v as Marked)._editDefaults
185
+ if (d) found = {id: d.id, full: d.path}
186
+ else for (const [k, x] of Object.entries(v)) if (!k.startsWith('_')) visit(x)
187
+ }
188
+ }
189
+ visit(value)
190
+ if (!found) return null
191
+ const {id, full} = found as {id: string; full: string}
192
+ // Chemin du champ dans le document des valeurs par défaut : jusqu'au segment `field`.
193
+ const m = new RegExp(`^(.*?(?:^|\\.)${field.replace(/[^\w]/g, '')})(?=[.[]|$)`).exec(full)
194
+ return m?.[1] ? {id, path: m[1]} : null
195
+ }
196
+
197
+ /** Réétiquette chaque texte et marque chaque image d'une valeur héritée, à son chemin exact. */
198
+ function retagDeep(value: unknown, path: string, page: {id: string; type: string}, inherited: {path: string; sourceId: string; sourcePath: string}, options: ImageEditOptions): unknown {
199
+ if (typeof value === 'string') return retag(value, page, path)
200
+ if (Array.isArray(value))
201
+ return value.map((item, index) => {
202
+ const k = item && typeof item === 'object' ? (item as {_key?: unknown})._key : undefined
203
+ return retagDeep(item, typeof k === 'string' ? `${path}[_key=="${k}"]` : `${path}[${index}]`, page, inherited, options)
204
+ })
205
+ if (!value || typeof value !== 'object') return value
206
+ if (isImageValue(value)) {
207
+ const copy: Marked = {...value}
208
+ mark(copy, page.id, page.type, path, {baseUrl: options.studioUrl})
209
+ copy._editInherited = inherited
210
+ return copy
211
+ }
212
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, k.startsWith('_') ? v : retagDeep(v, `${path}.${k}`, page, inherited, options)]))
213
+ }
214
+
144
215
  /**
145
216
  * Chemin EXACT des images qui appartiennent à la page, recalculé avec les clés
146
217
  * `_key` de la section. La carte des sources donne parfois un rang au lieu de la
@@ -168,12 +239,18 @@ export function rekeyOwnImageTargets<T>(section: T, source: Source, key: string
168
239
  return section
169
240
  }
170
241
 
171
- export type ImageEditAttributes = {'data-sanity'?: string; 'data-edit-image'?: string; 'data-edit-doc'?: string; 'data-edit-type'?: string}
242
+ export type ImageEditAttributes = {'data-sanity'?: string; 'data-edit-image'?: string; 'data-edit-doc'?: string; 'data-edit-type'?: string; 'data-edit-inherited'?: string}
172
243
 
173
244
  /** Attributs à poser sur le cadre d'une image marquée ; vide pour les visiteurs. */
174
245
  export function imageEditAttributes(image: ImageEditValue): ImageEditAttributes {
175
246
  if (!image?._editTarget || !image._editPath || !image._editDoc || !image._editType) return {}
176
- return {'data-sanity': image._editTarget, 'data-edit-image': image._editPath, 'data-edit-doc': image._editDoc, 'data-edit-type': image._editType}
247
+ return {
248
+ 'data-sanity': image._editTarget,
249
+ 'data-edit-image': image._editPath,
250
+ 'data-edit-doc': image._editDoc,
251
+ 'data-edit-type': image._editType,
252
+ ...(image._editInherited ? {'data-edit-inherited': JSON.stringify(image._editInherited)} : {}),
253
+ }
177
254
  }
178
255
 
179
256
  /**
@@ -1 +0,0 @@
1
- {"version":3,"file":"inherited-DZvM35P6.js","names":[],"sources":["../src/web/edit/inherited.ts"],"sourcesContent":["import {vercelStegaClean, vercelStegaCombine, vercelStegaDecode} from '@vercel/stega'\nimport {createEditUrl} from '@sanity/client/csm'\n\n/**\n * ÉDITION DANS L'APERÇU, valeurs HÉRITÉES des valeurs par défaut du composant\n * (champ vide dans la page : le site affiche la valeur par défaut).\n *\n * `reattributeTo` fait déjà pointer chaque texte hérité vers le champ de\n * l'INSTANCE (et non vers le document des valeurs par défaut). Ici, deux cas que\n * Sanity ne sait pas éditer sur place :\n *\n * - **Texte hérité** (`value`) : l'éditeur doit partir de la valeur par défaut\n * EXACTE, jamais du texte affiché que le composant met en forme (guillemets\n * ajoutés, retours à la ligne rendus en espaces).\n * - **Liste héritée** (`items`) : liste SIMPLE (textes, nombres, cases) ou TEXTE\n * RICHE sans lien (titre en lignes, italique). La page n'a pas encore ses\n * éléments, Sanity n'y active aucun composant. Chaque texte vise sa ligne exacte\n * (`…titleLines[_key==\"k\"].text`, `…title[_key==\"b\"].children[_key==\"s\"].text`) ;\n * à l'enregistrement, la liste par défaut est RECOPIÉE dans la page avec la\n * ligne modifiée, en un seul patch du brouillon (comme « Edit default items »).\n * La valeur par défaut du composant ne change jamais.\n *\n * Une liste avec liens, images ou références reste gérée dans le panneau : la\n * recopier depuis l'aperçu risquerait d'abîmer les données.\n *\n * Ces entrées sont jointes à la page en mode brouillon seulement\n * (`<script type=\"application/json\" data-ncf-inherited-…>`, voir\n * `inheritedEditScriptProps`).\n */\nexport type InheritedEdit = {path: string; items: Record<string, unknown>[]} | {path: string; value: string}\n\ntype Source = {id: string; type: string}\n\nconst isPrimitive = (v: unknown) => typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean'\n\nfunction isSimpleList(value: unknown): value is Record<string, unknown>[] {\n return (\n Array.isArray(value) &&\n value.length > 0 &&\n value.every(\n (item) =>\n item &&\n typeof item === 'object' &&\n !Array.isArray(item) &&\n typeof (item as {_key?: unknown})._key === 'string' &&\n (item as {_type?: unknown})._type !== 'block' &&\n Object.entries(item as Record<string, unknown>).every(([k, v]) => (k.startsWith('_') ? k === '_key' || k === '_type' : isPrimitive(v))),\n )\n )\n}\n\ntype Block = {_key: string; _type: 'block'; children: {_key: string; _type: 'span'; text: string}[]; markDefs?: unknown[]}\nfunction isPlainBlocks(value: unknown): value is Block[] {\n return (\n Array.isArray(value) &&\n value.length > 0 &&\n value.every(\n (b) =>\n b?._type === 'block' &&\n typeof b._key === 'string' &&\n !b.markDefs?.length &&\n Array.isArray(b.children) &&\n b.children.every(\n (c: {_type?: unknown; _key?: unknown; text?: unknown}) => c?._type === 'span' && typeof c._key === 'string' && typeof c.text === 'string',\n ),\n )\n )\n}\n\n/** Réétiquette un texte (stega) vers un autre chemin du document de la page. */\nfunction retag(text: string, source: Source, path: string): string {\n const info = vercelStegaDecode(text) as {origin?: string; href?: string} | undefined\n if (!info?.href) return text\n const url = new URL(info.href, 'https://studio.invalid')\n const baseUrl = url.searchParams.get('baseUrl')\n if (!baseUrl) return text\n const href = createEditUrl({\n baseUrl,\n workspace: url.searchParams.get('workspace') ?? undefined,\n tool: url.searchParams.get('tool') ?? undefined,\n id: `drafts.${source.id.replace(/^drafts\\./, '')}`,\n type: source.type,\n path,\n })\n return vercelStegaCombine(vercelStegaClean(text), {origin: info.origin ?? 'sanity.io', href})\n}\n\n/**\n * Liste héritée (déjà réétiquetée par `reattributeTo`) : renvoie la liste avec\n * chaque texte pointé vers sa ligne et inscrit la liste par défaut (textes\n * nettoyés) dans `collected`. Toute autre valeur est rendue telle quelle.\n */\nexport function retagInheritedList(value: unknown, listPath: string, source: Source, collected: InheritedEdit[]): unknown {\n if (isPlainBlocks(value)) {\n collected.push({path: listPath, items: vercelStegaClean(value) as Record<string, unknown>[]})\n return value.map((b) => ({\n ...b,\n children: b.children.map((c) => ({...c, text: retag(c.text, source, `${listPath}[_key==\"${b._key}\"].children[_key==\"${c._key}\"].text`)})),\n }))\n }\n if (!isSimpleList(value)) return value\n collected.push({\n path: listPath,\n items: value.map((item) => Object.fromEntries(Object.entries(item).map(([k, v]) => [k, typeof v === 'string' ? vercelStegaClean(v) : v]))),\n })\n return value.map((item) =>\n Object.fromEntries(\n Object.entries(item).map(([k, v]) => [k, typeof v === 'string' && !k.startsWith('_') ? retag(v, source, `${listPath}[_key==\"${item._key as string}\"].${k}`) : v]),\n ),\n )\n}\n\n/** Attributs du `<script>` qui joint une entrée héritée à la page (mode brouillon). */\nexport function inheritedEditScriptProps(entry: InheritedEdit) {\n return {\n type: 'application/json',\n ...('items' in entry ? {'data-ncf-inherited-list': entry.path} : {'data-ncf-inherited-value': entry.path}),\n dangerouslySetInnerHTML: {__html: JSON.stringify('items' in entry ? entry.items : entry.value).replace(/</g, '\\\\u003c')},\n }\n}\n\n/* ------------------------------------------------------------------------- */\n/* Côté éditeur : lecture et recopie (pur, testé) */\n/* ------------------------------------------------------------------------- */\n\ntype Step = {key: string} | {field: string}\n\n/** Étapes d'un chemin RELATIF à la liste : `[_key==\"b\"].children[_key==\"s\"].text`. */\nfunction steps(listPath: string, path: string): Step[] | null {\n if (!path.startsWith(`${listPath}[`)) return null\n const rest = path.slice(listPath.length)\n const out: Step[] = []\n let consumed = 0\n for (const m of rest.matchAll(/\\[_key==\"([^\"]+)\"\\]|\\.(\\w+)/g)) {\n if (m.index !== consumed) return null\n consumed += m[0].length\n out.push(m[1] ? {key: m[1]} : {field: m[2] as string})\n }\n return consumed === rest.length && out.length > 0 && 'key' in out[0]! ? out : null\n}\n\n/** Texte exact d'une ligne de liste héritée, ou null. */\nexport function inheritedListValue(list: {path: string; items: Record<string, unknown>[]}, path: string): string | null {\n const s = steps(list.path, path)\n if (!s) return null\n let value: unknown = list.items\n for (const step of s) {\n if ('key' in step) value = Array.isArray(value) ? value.find((v) => v?._key === step.key) : undefined\n else value = value && typeof value === 'object' ? (value as Record<string, unknown>)[step.field] : undefined\n }\n return typeof value === 'string' ? value : null\n}\n\n/** Liste par défaut recopiée avec la ligne `path` remplacée par `next`, ou null. */\nexport function materializeInheritedList(list: {path: string; items: Record<string, unknown>[]}, path: string, next: string): Record<string, unknown>[] | null {\n const s = steps(list.path, path)\n if (!s) return null\n const write = (value: unknown, i: number): unknown => {\n if (i === s.length) return next\n const step = s[i]!\n if ('key' in step) {\n if (!Array.isArray(value) || !value.some((v) => v?._key === step.key)) throw new Error('absent')\n return value.map((v) => (v?._key === step.key ? write(v, i + 1) : v))\n }\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('absent')\n const obj = value as Record<string, unknown>\n return {...obj, [step.field]: write(obj[step.field], i + 1)}\n }\n try {\n return write(list.items, 0) as Record<string, unknown>[]\n } catch {\n return null\n }\n}\n"],"mappings":";;AAiCA,MAAM,eAAe,MAAe,OAAO,KAAM,YAAY,OAAO,KAAM,YAAY,OAAO,KAAM;AAEnG,SAAS,aAAa,OAAoD;CACxE,OACE,MAAM,QAAQ,KAAK,KACnB,MAAM,SAAS,KACf,MAAM,OACH,SACC,QACA,OAAO,QAAS,YAChB,CAAC,MAAM,QAAQ,IAAI,KACnB,OAAQ,KAA0B,QAAS,YAC1C,KAA2B,UAAU,WACtC,OAAO,QAAQ,IAA+B,CAAC,CAAC,OAAO,CAAC,GAAG,OAAQ,EAAE,WAAW,GAAG,IAAI,MAAM,UAAU,MAAM,UAAU,YAAY,CAAC,CAAE,CAC1I;AAEJ;AAGA,SAAS,cAAc,OAAkC;CACvD,OACE,MAAM,QAAQ,KAAK,KACnB,MAAM,SAAS,KACf,MAAM,OACH,MACC,GAAG,UAAU,WACb,OAAO,EAAE,QAAS,YAClB,CAAC,EAAE,UAAU,UACb,MAAM,QAAQ,EAAE,QAAQ,KACxB,EAAE,SAAS,OACR,MAAyD,GAAG,UAAU,UAAU,OAAO,EAAE,QAAS,YAAY,OAAO,EAAE,QAAS,QACnI,CACJ;AAEJ;;AAGA,SAAS,MAAM,MAAc,QAAgB,MAAsB;CACjE,IAAM,OAAO,kBAAkB,IAAI;CACnC,IAAI,CAAC,MAAM,MAAM,OAAO;CACxB,IAAM,MAAM,IAAI,IAAI,KAAK,MAAM,wBAAwB,GACjD,UAAU,IAAI,aAAa,IAAI,SAAS;CAC9C,IAAI,CAAC,S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AI,SAAS,MAAM;GACjB,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,CAAC,MAAM,MAAM,MAAM,GAAG,SAAS,KAAK,GAAG,GAAG,MAAU,MAAM,QAAQ;GAC/F,OAAO,MAAM,KAAK,MAAO,GAAG,SAAS,KAAK,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAE;EACtE;EACA,IAAI,CAAC,SAAS,OAAO,SAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,MAAU,MAAM,QAAQ;EACzF,IAAM,MAAM;EACZ,OAAO;GAAC,GAAG;IAAM,KAAK,QAAQ,MAAM,IAAI,KAAK,QAAQ,IAAI,CAAC;EAAC;CAC7D;CACA,IAAI;EACF,OAAO,MAAM,KAAK,OAAO,CAAC;CAC5B,QAAQ;EACN,OAAO;CACT;AACF"}
@@ -1,31 +0,0 @@
1
- /**
2
- * Message « remplacer cette image » envoyé par l'aperçu (Presentation) au Studio.
3
- *
4
- * Partagé par le front (`NcfPreviewEditing`, couche des images) et le Studio
5
- * (pont monté par le plugin, qui ouvre la médiathèque). Module pur : ni React,
6
- * ni `sanity`, importable des deux côtés.
7
- */
8
- const REPLACE_IMAGE_MESSAGE = "ncf-kit/replace-image", SAFE_PATH = /^[A-Za-z0-9_\-.[\]="]+$/;
9
- /** Le message reçu est-il une demande de remplacement bien formée ? */
10
- function isReplaceImageRequest(data) {
11
- if (!data || typeof data != "object") return !1;
12
- let d = data;
13
- return d.type === "ncf-kit/replace-image" && typeof d.documentId == "string" && d.documentId.length > 0 && typeof d.path == "string" && SAFE_PATH.test(d.path) && (d.documentType === null || d.documentType === void 0 || typeof d.documentType == "string");
14
- }
15
- /**
16
- * Patch du remplacement : l'image choisie remplace celle du champ. Cadrage et
17
- * point focal sont retirés : calés sur l'ancienne photo, ils seraient faux.
18
- */
19
- function replaceImagePatch(path, assetId) {
20
- return [
21
- { setIfMissing: { [path]: { _type: "image" } } },
22
- { set: { [`${path}.asset`]: {
23
- _type: "reference",
24
- _ref: assetId
25
- } } },
26
- { unset: [`${path}.crop`, `${path}.hotspot`] }
27
- ];
28
- }
29
- export { isReplaceImageRequest as n, replaceImagePatch as r, REPLACE_IMAGE_MESSAGE as t };
30
-
31
- //# sourceMappingURL=protocol-Bl7Yj2Ro.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocol-Bl7Yj2Ro.js","names":[],"sources":["../src/web/edit/protocol.ts"],"sourcesContent":["/**\n * Message « remplacer cette image » envoyé par l'aperçu (Presentation) au Studio.\n *\n * Partagé par le front (`NcfPreviewEditing`, couche des images) et le Studio\n * (pont monté par le plugin, qui ouvre la médiathèque). Module pur : ni React,\n * ni `sanity`, importable des deux côtés.\n */\nexport const REPLACE_IMAGE_MESSAGE = 'ncf-kit/replace-image'\n\nexport type ReplaceImageRequest = {\n type: typeof REPLACE_IMAGE_MESSAGE\n /** Document à modifier (sans préfixe `drafts.`). */\n documentId: string\n /** Type du document, quand le front le connaît ; sinon le Studio le lit. */\n documentType: string | null\n /** Chemin EXACT du champ image (`sections[_key==\"a\"].items[_key==\"b\"].image`). */\n path: string\n}\n\n/** Chemin de champ Sanity sûr : lettres, chiffres, clés entre guillemets, rien d'autre. */\nconst SAFE_PATH = /^[A-Za-z0-9_\\-.[\\]=\"]+$/\n\n/** Le message reçu est-il une demande de remplacement bien formée ? */\nexport function isReplaceImageRequest(data: unknown): data is ReplaceImageRequest {\n if (!data || typeof data !== 'object') return false\n const d = data as Record<string, unknown>\n return (\n d.type === REPLACE_IMAGE_MESSAGE &&\n typeof d.documentId === 'string' &&\n d.documentId.length > 0 &&\n typeof d.path === 'string' &&\n SAFE_PATH.test(d.path) &&\n (d.documentType === null || d.documentType === undefined || typeof d.documentType === 'string')\n )\n}\n\n/**\n * Patch du remplacement : l'image choisie remplace celle du champ. Cadrage et\n * point focal sont retirés : calés sur l'ancienne photo, ils seraient faux.\n */\nexport function replaceImagePatch(path: string, assetId: string) {\n return [\n {setIfMissing: {[path]: {_type: 'image'}}},\n {set: {[`${path}.asset`]: {_type: 'reference', _ref: assetId}}},\n {unset: [`${path}.crop`, `${path}.hotspot`]},\n ]\n}\n"],"mappings":";;;;;;;AAOA,MAAa,wBAAwB,yBAa/B,YAAY;;AAGlB,SAAgB,sBAAsB,MAA4C;CAChF,IAAI,CAAC,QAAQ,OAAO,QAAS,UAAU,OAAO;CAC9C,IAAM,IAAI;CACV,OACE,EAAE,SAAA,2BACF,OAAO,EAAE,cAAe,YACxB,EAAE,WAAW,SAAS,KACtB,OAAO,EAAE,QAAS,YAClB,UAAU,KAAK,EAAE,IAAI,MACpB,EAAE,iBAAiB,QAAQ,EAAE,iBAAiB,KAAA,KAAa,OAAO,EAAE,gBAAiB;AAE1F;;;;;AAMA,SAAgB,kBAAkB,MAAc,SAAiB;CAC/D,OAAO;EACL,EAAC,cAAc,GAAE,OAAO,EAAC,OAAO,QAAO,EAAC,EAAC;EACzC,EAAC,KAAK,GAAE,GAAG,KAAK,UAAU;GAAC,OAAO;GAAa,MAAM;EAAO,EAAC,EAAC;EAC9D,EAAC,OAAO,CAAC,GAAG,KAAK,QAAQ,GAAG,KAAK,SAAS,EAAC;CAC7C;AACF"}