@nocode-factory/sanity-kit 2.60.0 → 2.61.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -2
- package/README.md +5 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +44 -12
- package/dist/index.js.map +1 -1
- package/dist/inherited-BJxEcInY.js +195 -0
- package/dist/inherited-BJxEcInY.js.map +1 -0
- package/dist/web-defaults.js +1 -1
- package/dist/web-edit.d.ts +37 -0
- package/dist/web-edit.js +88 -20
- package/dist/web-edit.js.map +1 -1
- package/dist/web-editing.d.ts +6 -1
- package/dist/web-editing.js +299 -42
- package/dist/web-editing.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/ui/PreviewEditBridge.tsx +47 -9
- package/src/version.ts +1 -1
- package/src/web/edit/EditAudit.tsx +136 -0
- package/src/web/edit/ImageReplaceLayer.tsx +7 -0
- package/src/web/edit/InlineTextEditor.tsx +177 -10
- package/src/web/edit/PreviewEditing.tsx +4 -2
- package/src/web/edit/inherited.ts +76 -4
- package/src/web/edit/labels.ts +8 -0
- package/src/web/edit/protocol.ts +31 -1
- package/src/web/edit/store.ts +6 -1
- package/src/web/edit/targets.ts +88 -11
- package/dist/inherited-DZvM35P6.js +0 -101
- package/dist/inherited-DZvM35P6.js.map +0 -1
- package/dist/protocol-Bl7Yj2Ro.js +0 -31
- package/dist/protocol-Bl7Yj2Ro.js.map +0 -1
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { createEditUrl } from "@sanity/client/csm";
|
|
2
|
-
import { vercelStegaClean, vercelStegaCombine, vercelStegaDecode } from "@vercel/stega";
|
|
3
|
-
const isPrimitive = (v) => typeof v == "string" || typeof v == "number" || typeof v == "boolean";
|
|
4
|
-
function isSimpleList(value) {
|
|
5
|
-
return Array.isArray(value) && value.length > 0 && value.every((item) => item && typeof item == "object" && !Array.isArray(item) && typeof item._key == "string" && item._type !== "block" && Object.entries(item).every(([k, v]) => k.startsWith("_") ? k === "_key" || k === "_type" : isPrimitive(v)));
|
|
6
|
-
}
|
|
7
|
-
function isPlainBlocks(value) {
|
|
8
|
-
return Array.isArray(value) && value.length > 0 && value.every((b) => b?._type === "block" && typeof b._key == "string" && !b.markDefs?.length && Array.isArray(b.children) && b.children.every((c) => c?._type === "span" && typeof c._key == "string" && typeof c.text == "string"));
|
|
9
|
-
}
|
|
10
|
-
/** Réétiquette un texte (stega) vers un autre chemin du document de la page. */
|
|
11
|
-
function retag(text, source, path) {
|
|
12
|
-
let info = vercelStegaDecode(text);
|
|
13
|
-
if (!info?.href) return text;
|
|
14
|
-
let url = new URL(info.href, "https://studio.invalid"), baseUrl = url.searchParams.get("baseUrl");
|
|
15
|
-
if (!baseUrl) return text;
|
|
16
|
-
let href = createEditUrl({
|
|
17
|
-
baseUrl,
|
|
18
|
-
workspace: url.searchParams.get("workspace") ?? void 0,
|
|
19
|
-
tool: url.searchParams.get("tool") ?? void 0,
|
|
20
|
-
id: `drafts.${source.id.replace(/^drafts\./, "")}`,
|
|
21
|
-
type: source.type,
|
|
22
|
-
path
|
|
23
|
-
});
|
|
24
|
-
return vercelStegaCombine(vercelStegaClean(text), {
|
|
25
|
-
origin: info.origin ?? "sanity.io",
|
|
26
|
-
href
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Liste héritée (déjà réétiquetée par `reattributeTo`) : renvoie la liste avec
|
|
31
|
-
* chaque texte pointé vers sa ligne et inscrit la liste par défaut (textes
|
|
32
|
-
* nettoyés) dans `collected`. Toute autre valeur est rendue telle quelle.
|
|
33
|
-
*/
|
|
34
|
-
function retagInheritedList(value, listPath, source, collected) {
|
|
35
|
-
return isPlainBlocks(value) ? (collected.push({
|
|
36
|
-
path: listPath,
|
|
37
|
-
items: vercelStegaClean(value)
|
|
38
|
-
}), value.map((b) => ({
|
|
39
|
-
...b,
|
|
40
|
-
children: b.children.map((c) => ({
|
|
41
|
-
...c,
|
|
42
|
-
text: retag(c.text, source, `${listPath}[_key=="${b._key}"].children[_key=="${c._key}"].text`)
|
|
43
|
-
}))
|
|
44
|
-
}))) : isSimpleList(value) ? (collected.push({
|
|
45
|
-
path: listPath,
|
|
46
|
-
items: value.map((item) => Object.fromEntries(Object.entries(item).map(([k, v]) => [k, typeof v == "string" ? vercelStegaClean(v) : v])))
|
|
47
|
-
}), value.map((item) => Object.fromEntries(Object.entries(item).map(([k, v]) => [k, typeof v == "string" && !k.startsWith("_") ? retag(v, source, `${listPath}[_key=="${item._key}"].${k}`) : v])))) : value;
|
|
48
|
-
}
|
|
49
|
-
/** Attributs du `<script>` qui joint une entrée héritée à la page (mode brouillon). */
|
|
50
|
-
function inheritedEditScriptProps(entry) {
|
|
51
|
-
return {
|
|
52
|
-
type: "application/json",
|
|
53
|
-
..."items" in entry ? { "data-ncf-inherited-list": entry.path } : { "data-ncf-inherited-value": entry.path },
|
|
54
|
-
dangerouslySetInnerHTML: { __html: JSON.stringify("items" in entry ? entry.items : entry.value).replace(/</g, "\\u003c") }
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/** Étapes d'un chemin RELATIF à la liste : `[_key=="b"].children[_key=="s"].text`. */
|
|
58
|
-
function steps(listPath, path) {
|
|
59
|
-
if (!path.startsWith(`${listPath}[`)) return null;
|
|
60
|
-
let rest = path.slice(listPath.length), out = [], consumed = 0;
|
|
61
|
-
for (let m of rest.matchAll(/\[_key=="([^"]+)"\]|\.(\w+)/g)) {
|
|
62
|
-
if (m.index !== consumed) return null;
|
|
63
|
-
consumed += m[0].length, out.push(m[1] ? { key: m[1] } : { field: m[2] });
|
|
64
|
-
}
|
|
65
|
-
return consumed === rest.length && out.length > 0 && "key" in out[0] ? out : null;
|
|
66
|
-
}
|
|
67
|
-
/** Texte exact d'une ligne de liste héritée, ou null. */
|
|
68
|
-
function inheritedListValue(list, path) {
|
|
69
|
-
let s = steps(list.path, path);
|
|
70
|
-
if (!s) return null;
|
|
71
|
-
let value = list.items;
|
|
72
|
-
for (let step of s) value = "key" in step ? Array.isArray(value) ? value.find((v) => v?._key === step.key) : void 0 : value && typeof value == "object" ? value[step.field] : void 0;
|
|
73
|
-
return typeof value == "string" ? value : null;
|
|
74
|
-
}
|
|
75
|
-
/** Liste par défaut recopiée avec la ligne `path` remplacée par `next`, ou null. */
|
|
76
|
-
function materializeInheritedList(list, path, next) {
|
|
77
|
-
let s = steps(list.path, path);
|
|
78
|
-
if (!s) return null;
|
|
79
|
-
let write = (value, i) => {
|
|
80
|
-
if (i === s.length) return next;
|
|
81
|
-
let step = s[i];
|
|
82
|
-
if ("key" in step) {
|
|
83
|
-
if (!Array.isArray(value) || !value.some((v) => v?._key === step.key)) throw Error("absent");
|
|
84
|
-
return value.map((v) => v?._key === step.key ? write(v, i + 1) : v);
|
|
85
|
-
}
|
|
86
|
-
if (!value || typeof value != "object" || Array.isArray(value)) throw Error("absent");
|
|
87
|
-
let obj = value;
|
|
88
|
-
return {
|
|
89
|
-
...obj,
|
|
90
|
-
[step.field]: write(obj[step.field], i + 1)
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
try {
|
|
94
|
-
return write(list.items, 0);
|
|
95
|
-
} catch {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
export { retagInheritedList as i, inheritedListValue as n, materializeInheritedList as r, inheritedEditScriptProps as t };
|
|
100
|
-
|
|
101
|
-
//# sourceMappingURL=inherited-DZvM35P6.js.map
|
|
@@ -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,SAAS,OAAO;CACrB,IAAM,OAAO,cAAc;EACzB;EACA,WAAW,IAAI,aAAa,IAAI,WAAW,KAAK,KAAA;EAChD,MAAM,IAAI,aAAa,IAAI,MAAM,KAAK,KAAA;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/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"}
|