@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,5 +1,38 @@
1
- import { createEditUrl } from "@sanity/client/csm";
2
1
  import { vercelStegaClean, vercelStegaCombine, vercelStegaDecode } from "@vercel/stega";
2
+ import { createEditUrl } from "@sanity/client/csm";
3
+ /**
4
+ * Message « remplacer cette image » envoyé par l'aperçu (Presentation) au Studio.
5
+ *
6
+ * Partagé par le front (`NcfPreviewEditing`, couche des images) et le Studio
7
+ * (pont monté par le plugin, qui ouvre la médiathèque). Module pur : ni React,
8
+ * ni `sanity`, importable des deux côtés.
9
+ */
10
+ const REPLACE_IMAGE_MESSAGE = "ncf-kit/replace-image", SAFE_PATH = /^[A-Za-z0-9_\-.[\]="]+$/;
11
+ /** Le message reçu est-il une demande de remplacement bien formée ? */
12
+ function isReplaceImageRequest(data) {
13
+ if (!data || typeof data != "object") return !1;
14
+ let d = data;
15
+ 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") && (d.inherited === null || d.inherited === void 0 || isInherited(d.inherited));
16
+ }
17
+ function isInherited(v) {
18
+ if (!v || typeof v != "object") return !1;
19
+ let i = v;
20
+ return typeof i.path == "string" && SAFE_PATH.test(i.path) && typeof i.sourcePath == "string" && SAFE_PATH.test(i.sourcePath) && typeof i.sourceId == "string" && /^[\w.-]+$/.test(i.sourceId);
21
+ }
22
+ /**
23
+ * Patch du remplacement : l'image choisie remplace celle du champ. Cadrage et
24
+ * point focal sont retirés : calés sur l'ancienne photo, ils seraient faux.
25
+ */
26
+ function replaceImagePatch(path, assetId) {
27
+ return [
28
+ { setIfMissing: { [path]: { _type: "image" } } },
29
+ { set: { [`${path}.asset`]: {
30
+ _type: "reference",
31
+ _ref: assetId
32
+ } } },
33
+ { unset: [`${path}.crop`, `${path}.hotspot`] }
34
+ ];
35
+ }
3
36
  const isPrimitive = (v) => typeof v == "string" || typeof v == "number" || typeof v == "boolean";
4
37
  function isSimpleList(value) {
5
38
  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)));
@@ -50,8 +83,8 @@ function retagInheritedList(value, listPath, source, collected) {
50
83
  function inheritedEditScriptProps(entry) {
51
84
  return {
52
85
  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") }
86
+ ..."items" in entry ? { "data-ncf-inherited-list": entry.path } : "source" in entry ? { "data-ncf-inherited-source": entry.path } : { "data-ncf-inherited-value": entry.path },
87
+ dangerouslySetInnerHTML: { __html: JSON.stringify("items" in entry ? entry.items : "source" in entry ? entry.source : entry.value).replace(/</g, "\\u003c") }
55
88
  };
56
89
  }
57
90
  /** Étapes d'un chemin RELATIF à la liste : `[_key=="b"].children[_key=="s"].text`. */
@@ -96,6 +129,56 @@ function materializeInheritedList(list, path, next) {
96
129
  return null;
97
130
  }
98
131
  }
99
- export { retagInheritedList as i, inheritedListValue as n, materializeInheritedList as r, inheritedEditScriptProps as t };
132
+ /** `sections[_key=="a"].items[2].title` → étapes ; null si le chemin est illisible. */
133
+ function parsePath(path) {
134
+ let out = [], consumed = 0;
135
+ for (let m of path.matchAll(/\[_key=="([^"]+)"\]|\[(\d+)\]|\.?([A-Za-z_][\w-]*)/g)) {
136
+ if (m.index !== consumed) return null;
137
+ consumed += m[0].length, out.push(m[1] === void 0 ? m[2] === void 0 ? { field: m[3] } : { index: Number(m[2]) } : { key: m[1] });
138
+ }
139
+ return consumed === path.length && out.length ? out : null;
140
+ }
141
+ /** Valeur au chemin (étapes), ou undefined. */
142
+ function readAt(root, steps) {
143
+ let value = root;
144
+ for (let step of steps) if (value = "key" in step ? Array.isArray(value) ? value.find((v) => v?._key === step.key) : void 0 : "index" in step ? Array.isArray(value) ? value[step.index] : void 0 : value && typeof value == "object" && !Array.isArray(value) ? value[step.field] : void 0, value === void 0) return;
145
+ return value;
146
+ }
147
+ /** Copie de `root` avec `next` écrit au chemin ; null si un élément du chemin manque. */
148
+ function writeAt(root, steps, next) {
149
+ let write = (value, i) => {
150
+ if (i === steps.length) return next;
151
+ let step = steps[i];
152
+ if ("key" in step || "index" in step) {
153
+ if (!Array.isArray(value)) throw Error("absent");
154
+ let at = "key" in step ? value.findIndex((v) => v?._key === step.key) : step.index;
155
+ if (at < 0 || at >= value.length) throw Error("absent");
156
+ return value.map((v, j) => j === at ? write(v, i + 1) : v);
157
+ }
158
+ if (value !== void 0 && (typeof value != "object" || !value || Array.isArray(value)) || value === void 0 && i < steps.length - 1 && !("field" in steps[i + 1])) throw Error("absent");
159
+ let obj = value ?? {};
160
+ return {
161
+ ...obj,
162
+ [step.field]: write(obj[step.field], i + 1)
163
+ };
164
+ };
165
+ try {
166
+ return write(root, 0);
167
+ } catch {
168
+ return null;
169
+ }
170
+ }
171
+ /**
172
+ * Entrée héritée qui couvre `path` (le chemin d'un texte ou d'une image dans la page) :
173
+ * son chemin est un préfixe exact (suivi de `[` ou `.`). Renvoie aussi le reste du chemin.
174
+ */
175
+ function coveringEntry(entries, path) {
176
+ let entry = entries.filter((e) => path.startsWith(`${e.path}[`) || path.startsWith(`${e.path}.`)).sort((a, b) => b.path.length - a.path.length)[0];
177
+ return entry ? {
178
+ entry,
179
+ rest: path.slice(entry.path.length)
180
+ } : null;
181
+ }
182
+ export { parsePath as a, retagInheritedList as c, isReplaceImageRequest as d, replaceImagePatch as f, materializeInheritedList as i, writeAt as l, inheritedEditScriptProps as n, readAt as o, inheritedListValue as r, retag as s, coveringEntry as t, REPLACE_IMAGE_MESSAGE as u };
100
183
 
101
- //# sourceMappingURL=inherited-DZvM35P6.js.map
184
+ //# sourceMappingURL=inherited-BveIuNhM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inherited-BveIuNhM.js","names":[],"sources":["../src/web/edit/protocol.ts","../src/web/edit/inherited.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 * Image DANS une valeur héritée des valeurs par défaut (liste...) que la page n'a pas\n * encore : le champ `path` de la page reçoit d'abord la valeur brute du champ\n * `sourcePath` du document `sourceId` (recopie, comme « Edit default items »).\n */\n inherited?: {path: string; sourceId: string; sourcePath: string} | null\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 (d.inherited === null || d.inherited === undefined || isInherited(d.inherited))\n )\n}\n\nfunction isInherited(v: unknown): v is NonNullable<ReplaceImageRequest['inherited']> {\n if (!v || typeof v !== 'object') return false\n const i = v as Record<string, unknown>\n return typeof i.path === 'string' && SAFE_PATH.test(i.path) && typeof i.sourcePath === 'string' && SAFE_PATH.test(i.sourcePath) && typeof i.sourceId === 'string' && /^[\\w.-]+$/.test(i.sourceId)\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","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 =\n | {path: string; items: Record<string, unknown>[]}\n | {path: string; value: string}\n /**\n * Valeur héritée de N'IMPORTE QUELLE forme (liste avec images, liens, texte riche,\n * objet) : sa source BRUTE est le champ du document des valeurs par défaut\n * (`source.id`, `source.path`), relu tel qu'enregistré au moment de la recopie (jamais\n * la version projetée par la requête du site, qui peut porter des champs vides ou\n * résolus). Même recopie que « Edit default items » du kit.\n */\n | {path: string; source: {id: string; path: 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. */\nexport function 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} : 'source' in entry ? {'data-ncf-inherited-source': entry.path} : {'data-ncf-inherited-value': entry.path}),\n dangerouslySetInnerHTML: {__html: JSON.stringify('items' in entry ? entry.items : 'source' in entry ? entry.source : 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\n/* ------------------------------------------------------------------------- */\n/* Chemins Sanity : lecture et écriture dans une valeur brute (pur, testé) */\n/* ------------------------------------------------------------------------- */\n\nexport type PathStep = {key: string} | {index: number} | {field: string}\n\n/** `sections[_key==\"a\"].items[2].title` → étapes ; null si le chemin est illisible. */\nexport function parsePath(path: string): PathStep[] | null {\n const out: PathStep[] = []\n let consumed = 0\n for (const m of path.matchAll(/\\[_key==\"([^\"]+)\"\\]|\\[(\\d+)\\]|\\.?([A-Za-z_][\\w-]*)/g)) {\n if (m.index !== consumed) return null\n consumed += m[0].length\n out.push(m[1] !== undefined ? {key: m[1]} : m[2] !== undefined ? {index: Number(m[2])} : {field: m[3] as string})\n }\n return consumed === path.length && out.length ? out : null\n}\n\n/** Valeur au chemin (étapes), ou undefined. */\nexport function readAt(root: unknown, steps: PathStep[]): unknown {\n let value = root\n for (const step of steps) {\n if ('key' in step) value = Array.isArray(value) ? value.find((v) => v?._key === step.key) : undefined\n else if ('index' in step) value = Array.isArray(value) ? value[step.index] : undefined\n else value = value && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>)[step.field] : undefined\n if (value === undefined) return undefined\n }\n return value\n}\n\n/** Copie de `root` avec `next` écrit au chemin ; null si un élément du chemin manque. */\nexport function writeAt(root: unknown, steps: PathStep[], next: unknown): unknown {\n const write = (value: unknown, i: number): unknown => {\n if (i === steps.length) return next\n const step = steps[i]!\n if ('key' in step || 'index' in step) {\n if (!Array.isArray(value)) throw new Error('absent')\n const at = 'key' in step ? value.findIndex((v) => v?._key === step.key) : step.index\n if (at < 0 || at >= value.length) throw new Error('absent')\n return value.map((v, j) => (j === at ? write(v, i + 1) : v))\n }\n if (value !== undefined && (typeof value !== 'object' || value === null || Array.isArray(value))) throw new Error('absent')\n if (value === undefined && i < steps.length - 1 && !('field' in steps[i + 1]!)) 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(root, 0)\n } catch {\n return null\n }\n}\n\n/**\n * Entrée héritée qui couvre `path` (le chemin d'un texte ou d'une image dans la page) :\n * son chemin est un préfixe exact (suivi de `[` ou `.`). Renvoie aussi le reste du chemin.\n */\nexport function coveringEntry<T extends {path: string}>(entries: T[], path: string): {entry: T; rest: string} | null {\n const entry = entries.filter((e) => path.startsWith(`${e.path}[`) || path.startsWith(`${e.path}.`)).sort((a, b) => b.path.length - a.path.length)[0]\n return entry ? {entry, rest: path.slice(entry.path.length)} : null\n}\n"],"mappings":";;;;;;;;;AAOA,MAAa,wBAAwB,yBAmB/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,cACrF,EAAE,cAAc,QAAQ,EAAE,cAAc,KAAA,KAAa,YAAY,EAAE,SAAS;AAEjF;AAEA,SAAS,YAAY,GAAgE;CACnF,IAAI,CAAC,KAAK,OAAO,KAAM,UAAU,OAAO;CACxC,IAAM,IAAI;CACV,OAAO,OAAO,EAAE,QAAS,YAAY,UAAU,KAAK,EAAE,IAAI,KAAK,OAAO,EAAE,cAAe,YAAY,UAAU,KAAK,EAAE,UAAU,KAAK,OAAO,EAAE,YAAa,YAAY,YAAY,KAAK,EAAE,QAAQ;AAClM;;;;;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;AChBA,MAAM,eAAe,MAAe,OAAO,KAAM,YAAY,OAAO,KAAM,YAAY,OAAO,KAAM;AAEnG,SAAS,aAAa,O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AAK,SAAS,OAAO,MAAM,WAAW,MAAM,GAAG,SAAS,KAAK,GAAG,IAAI,KAAK;GAC/E,IAAI,KAAK,KAAK,MAAM,MAAM,QAAQ,MAAU,MAAM,QAAQ;GAC1D,OAAO,MAAM,KAAK,GAAG,MAAO,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC,IAAI,CAAE;EAC7D;EAEA,IADI,UAAU,KAAA,MAAc,OAAO,SAAU,aAAY,SAAkB,MAAM,QAAQ,KAAK,MAC1F,UAAU,KAAA,KAAa,IAAI,MAAM,SAAS,KAAK,EAAE,WAAW,MAAM,IAAI,KAAM,MAAU,MAAM,QAAQ;EACxG,IAAM,MAAO,SAAS,CAAC;EACvB,OAAO;GAAC,GAAG;IAAM,KAAK,QAAQ,MAAM,IAAI,KAAK,QAAQ,IAAI,CAAC;EAAC;CAC7D;CACA,IAAI;EACF,OAAO,MAAM,MAAM,CAAC;CACtB,QAAQ;EACN,OAAO;CACT;AACF;;;;;AAMA,SAAgB,cAAwC,SAAc,MAA+C;CACnH,IAAM,QAAQ,QAAQ,QAAQ,MAAM,KAAK,WAAW,GAAG,EAAE,KAAK,EAAE,KAAK,KAAK,WAAW,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,CAAC,CAAC;CAClJ,OAAO,QAAQ;EAAC;EAAO,MAAM,KAAK,MAAM,MAAM,KAAK,MAAM;CAAC,IAAI;AAChE"}
@@ -1,5 +1,5 @@
1
- import { createEditUrl } from "@sanity/client/csm";
2
1
  import { vercelStegaClean, vercelStegaCombine, vercelStegaDecode } from "@vercel/stega";
2
+ import { createEditUrl } from "@sanity/client/csm";
3
3
  /**
4
4
  * VALEURS PAR DÉFAUT DES COMPOSANTS, côté site. Module neutre (ni `'use client'`
5
5
  * ni API serveur) : utilisable dans un composant serveur, un composant client et
@@ -31,6 +31,20 @@ type InheritedEdit = {
31
31
  } | {
32
32
  path: string;
33
33
  value: string;
34
+ } |
35
+ /**
36
+ * Valeur héritée de N'IMPORTE QUELLE forme (liste avec images, liens, texte riche,
37
+ * objet) : sa source BRUTE est le champ du document des valeurs par défaut
38
+ * (`source.id`, `source.path`), relu tel qu'enregistré au moment de la recopie (jamais
39
+ * la version projetée par la requête du site, qui peut porter des champs vides ou
40
+ * résolus). Même recopie que « Edit default items » du kit.
41
+ */
42
+ {
43
+ path: string;
44
+ source: {
45
+ id: string;
46
+ path: string;
47
+ };
34
48
  };
35
49
  type Source$1 = {
36
50
  id: string;
@@ -49,6 +63,12 @@ export declare function inheritedEditScriptProps(entry: InheritedEdit): {
49
63
  };
50
64
  'data-ncf-inherited-list': string;
51
65
  type: string;
66
+ } | {
67
+ dangerouslySetInnerHTML: {
68
+ __html: string;
69
+ };
70
+ 'data-ncf-inherited-source': string;
71
+ type: string;
52
72
  } | {
53
73
  dangerouslySetInnerHTML: {
54
74
  __html: string;
@@ -94,6 +114,12 @@ type ImageEditValue = {
94
114
  _editPath?: string;
95
115
  _editDoc?: string;
96
116
  _editType?: string;
117
+ /** Image héritée DANS une valeur par défaut (liste...) : champ à recopier d'abord. */
118
+ _editInherited?: {
119
+ path: string;
120
+ sourceId: string;
121
+ sourcePath: string;
122
+ };
97
123
  } | null | undefined;
98
124
  type ImageEditOptions = {
99
125
  /** Adresse du Studio (celle de `stega.studioUrl`). */
@@ -135,6 +161,7 @@ type ImageEditAttributes = {
135
161
  'data-edit-image'?: string;
136
162
  'data-edit-doc'?: string;
137
163
  'data-edit-type'?: string;
164
+ 'data-edit-inherited'?: string;
138
165
  };
139
166
  /** Attributs à poser sur le cadre d'une image marquée ; vide pour les visiteurs. */
140
167
  export declare function imageEditAttributes(image: ImageEditValue): ImageEditAttributes;
@@ -159,6 +186,16 @@ type ReplaceImageRequest = {
159
186
  documentType: string | null;
160
187
  /** Chemin EXACT du champ image (`sections[_key=="a"].items[_key=="b"].image`). */
161
188
  path: string;
189
+ /**
190
+ * Image DANS une valeur héritée des valeurs par défaut (liste...) que la page n'a pas
191
+ * encore : le champ `path` de la page reçoit d'abord la valeur brute du champ
192
+ * `sourcePath` du document `sourceId` (recopie, comme « Edit default items »).
193
+ */
194
+ inherited?: {
195
+ path: string;
196
+ sourceId: string;
197
+ sourcePath: string;
198
+ } | null;
162
199
  };
163
200
  /** Le message reçu est-il une demande de remplacement bien formée ? */
164
201
  export declare function isReplaceImageRequest(data: unknown): data is ReplaceImageRequest;
package/dist/web-edit.js CHANGED
@@ -1,7 +1,6 @@
1
- import { n as isReplaceImageRequest, r as replaceImagePatch, t as REPLACE_IMAGE_MESSAGE } from "./protocol-Bl7Yj2Ro.js";
2
- import { i as retagInheritedList, n as inheritedListValue, r as materializeInheritedList, t as inheritedEditScriptProps } from "./inherited-DZvM35P6.js";
1
+ import { c as retagInheritedList, d as isReplaceImageRequest, f as replaceImagePatch, i as materializeInheritedList, n as inheritedEditScriptProps, r as inheritedListValue, s as retag, u as REPLACE_IMAGE_MESSAGE } from "./inherited-BveIuNhM.js";
2
+ import { vercelStegaClean, vercelStegaDecode } from "@vercel/stega";
3
3
  import { resolveEditInfo, studioPath } from "@sanity/client/csm";
4
- import { vercelStegaClean } from "@vercel/stega";
5
4
  import { createDataAttribute } from "@sanity/visual-editing/create-data-attribute";
6
5
  function isImageValue(value) {
7
6
  if (!value || typeof value != "object" || Array.isArray(value)) return !1;
@@ -39,15 +38,24 @@ function annotateImageEditTargets(data, sourceMap, options) {
39
38
  "_ref"
40
39
  ]
41
40
  });
42
- if (!info || info.type === defaultsType) return;
41
+ if (!info) return;
43
42
  let full = typeof info.path == "string" ? info.path : studioPath.toString(info.path), imagePath = full.replace(/\.asset\._ref$/, "");
44
- imagePath && imagePath !== full && mark(value, info.id, info.type, imagePath, {
45
- baseUrl: info.baseUrl,
46
- workspace: info.workspace,
47
- tool: info.tool,
48
- projectId: info.projectId,
49
- dataset: info.dataset
50
- });
43
+ if (imagePath && imagePath !== full) {
44
+ if (info.type === defaultsType) {
45
+ value._editDefaults = {
46
+ id: info.id.replace(/^drafts\./, ""),
47
+ path: imagePath
48
+ };
49
+ return;
50
+ }
51
+ mark(value, info.id, info.type, imagePath, {
52
+ baseUrl: info.baseUrl,
53
+ workspace: info.workspace,
54
+ tool: info.tool,
55
+ projectId: info.projectId,
56
+ dataset: info.dataset
57
+ });
58
+ }
51
59
  }, visit = (value, path) => {
52
60
  if (Array.isArray(value)) {
53
61
  value.forEach((item, index) => {
@@ -86,17 +94,76 @@ function withPreviewEditTargets(onInherit, source, key, collected, options) {
86
94
  }
87
95
  };
88
96
  return (value, path) => {
89
- let out = onInherit(value, path);
90
- if (out && typeof out == "object" && !Array.isArray(out)) {
91
- let copy = isImageValue(out) ? { ...out } : out;
92
- return markInherited(copy, `${base}.${path.join(".")}`), copy;
93
- }
94
- return typeof out == "string" && collected.push({
95
- path: `${base}.${path.join(".")}`,
97
+ let out = onInherit(value, path), entryPath = `${base}.${path.join(".")}`;
98
+ if (typeof out == "string") return collected.push({
99
+ path: entryPath,
96
100
  value: vercelStegaClean(out)
97
- }), Array.isArray(out) && path.length === 1 ? retagInheritedList(out, `${base}.${path[0]}`, source, collected) : out;
101
+ }), out;
102
+ if (!out || typeof out != "object") return out;
103
+ if (isImageValue(out)) {
104
+ let copy = { ...out };
105
+ return markInherited(copy, entryPath), copy;
106
+ }
107
+ let raw = defaultsSourceOf(value, path[path.length - 1]);
108
+ return raw ? (collected.push({
109
+ path: entryPath,
110
+ source: raw
111
+ }), retagDeep(out, entryPath, {
112
+ ...source,
113
+ id: pageId
114
+ }, {
115
+ path: entryPath,
116
+ sourceId: raw.id,
117
+ sourcePath: raw.path
118
+ }, options)) : Array.isArray(out) && path.length === 1 ? retagInheritedList(out, entryPath, source, collected) : (markInherited(out, entryPath), out);
98
119
  };
99
120
  }
121
+ /** Champ des valeurs par défaut d'où vient une valeur héritée : lu dans un texte (stega) ou une image. */
122
+ function defaultsSourceOf(value, field) {
123
+ let found = null, visit = (v) => {
124
+ if (!(found || v == null)) {
125
+ if (typeof v == "string") {
126
+ let info = vercelStegaDecode(v);
127
+ if (!info?.href) return;
128
+ let href = decodeURIComponent(info.href), id = /[;/]id=([^;?&]+)/.exec(href)?.[1], full = /;path=([^;?&]+)/.exec(href)?.[1];
129
+ id && full && (found = {
130
+ id: id.replace(/^drafts\./, ""),
131
+ full
132
+ });
133
+ return;
134
+ }
135
+ if (Array.isArray(v)) return v.forEach(visit);
136
+ if (typeof v == "object") {
137
+ let d = v._editDefaults;
138
+ if (d) found = {
139
+ id: d.id,
140
+ full: d.path
141
+ };
142
+ else for (let [k, x] of Object.entries(v)) k.startsWith("_") || visit(x);
143
+ }
144
+ }
145
+ };
146
+ if (visit(value), !found) return null;
147
+ let { id, full } = found, m = RegExp(`^(.*?(?:^|\\.)${field.replace(/[^\w]/g, "")})(?=[.[]|$)`).exec(full);
148
+ return m?.[1] ? {
149
+ id,
150
+ path: m[1]
151
+ } : null;
152
+ }
153
+ /** Réétiquette chaque texte et marque chaque image d'une valeur héritée, à son chemin exact. */
154
+ function retagDeep(value, path, page, inherited, options) {
155
+ if (typeof value == "string") return retag(value, page, path);
156
+ if (Array.isArray(value)) return value.map((item, index) => {
157
+ let k = item && typeof item == "object" ? item._key : void 0;
158
+ return retagDeep(item, typeof k == "string" ? `${path}[_key=="${k}"]` : `${path}[${index}]`, page, inherited, options);
159
+ });
160
+ if (!value || typeof value != "object") return value;
161
+ if (isImageValue(value)) {
162
+ let copy = { ...value };
163
+ return mark(copy, page.id, page.type, path, { baseUrl: options.studioUrl }), copy._editInherited = inherited, copy;
164
+ }
165
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, k.startsWith("_") ? v : retagDeep(v, `${path}.${k}`, page, inherited, options)]));
166
+ }
100
167
  /**
101
168
  * Chemin EXACT des images qui appartiennent à la page, recalculé avec les clés
102
169
  * `_key` de la section. La carte des sources donne parfois un rang au lieu de la
@@ -128,7 +195,8 @@ function imageEditAttributes(image) {
128
195
  "data-sanity": image._editTarget,
129
196
  "data-edit-image": image._editPath,
130
197
  "data-edit-doc": image._editDoc,
131
- "data-edit-type": image._editType
198
+ "data-edit-type": image._editType,
199
+ ...image._editInherited ? { "data-edit-inherited": JSON.stringify(image._editInherited) } : {}
132
200
  };
133
201
  }
134
202
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"web-edit.js","names":[],"sources":["../src/web/edit/targets.ts"],"sourcesContent":["import {createDataAttribute} from '@sanity/visual-editing/create-data-attribute'\nimport {resolveEditInfo, studioPath, type ContentSourceMap, type ContentSourceMapParsedPath} from '@sanity/client/csm'\nimport {vercelStegaClean} from '@vercel/stega'\nimport {retagInheritedList, type InheritedEdit} from './inherited'\n\n/**\n * ÉDITION DANS L'APERÇU, IMAGES (mode brouillon seulement) : chaque image est\n * cliquable dans Presentation, alt rempli ou non, et porte son document et son\n * chemin EXACTS pour la pastille « Replace this image » (`NcfPreviewEditing`).\n *\n * Sanity ne repère d'ordinaire une image que par son alt (texte encodé en stega) :\n * une image sans alt n'avait aucun overlay. Ici, la carte des sources (Content\n * Source Map, renvoyée par `sanityFetch` en brouillon) donne pour chaque image son\n * document et son champ ; on les attache à la valeur (`_editTarget`, `_editPath`,\n * `_editDoc`, `_editType`), que le composant pose avec `imageEditAttributes`.\n *\n * Câblage d'un projet (starter) :\n * - `annotateImageEditTargets(data, sourceMap, {studioUrl})` sur le résultat de\n * `sanityFetch` en brouillon ;\n * - `withPreviewEditTargets(reattributeTo(source, key), source, key, collected, {studioUrl})`\n * comme rappel d'héritage de `applyDefaults` ;\n * - `rekeyOwnImageTargets(section, source, key, {studioUrl})` sur chaque section ;\n * - `imageEditAttributes(image)` / `imageAlt(image)` sur chaque image affichée.\n */\n\nexport type ImageEditValue = {\n asset?: {_ref?: string}\n alt?: string\n _editTarget?: string\n _editPath?: string\n _editDoc?: string\n _editType?: string\n} | null | undefined\n\ntype Marked = {asset: {_ref: string}; _editTarget?: string; _editPath?: string; _editDoc?: string; _editType?: string}\ntype Segment = ContentSourceMapParsedPath[number]\n\nfunction isImageValue(value: unknown): value is Marked {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false\n const ref = (value as {asset?: {_ref?: unknown}}).asset?._ref\n return typeof ref === 'string' && ref.startsWith('image-')\n}\n\n/**\n * Pose le repère Sanity et le chemin exact. Image élément de liste\n * (`…images[_key==\"i3\"]`) : Sanity n'active pas un repère placé dans un élément de\n * liste d'images ; le repère vise la liste, le chemin exact reste dans `_editPath`.\n */\nfunction mark(value: Marked, id: string, type: string, path: string, extra: Record<string, string | undefined> & {baseUrl: string}) {\n const inList = /\\[[^\\]]+\\]$/.test(path)\n value._editTarget = createDataAttribute({...extra, id, type, path: inList ? path.replace(/\\[[^\\]]+\\]$/, '') : path}).toString()\n value._editPath = path\n value._editDoc = id.replace(/^drafts\\./, '')\n value._editType = type\n}\n\nexport type ImageEditOptions = {\n /** Adresse du Studio (celle de `stega.studioUrl`). */\n studioUrl: string\n /** Type du document des valeurs par défaut des composants (jamais marqué). */\n defaultsType?: string\n}\n\n/**\n * Marque chaque image du résultat d'une requête en brouillon. Une image venue du\n * document des valeurs par défaut n'est pas marquée ici (un clic modifierait\n * l'image de TOUTES les pages) : `withPreviewEditTargets` la fait viser l'instance.\n */\nexport function annotateImageEditTargets<T>(data: T, sourceMap: ContentSourceMap | null | undefined, options: ImageEditOptions): T {\n if (!sourceMap) return data\n const defaultsType = options.defaultsType ?? 'componentDefaults'\n const fromSourceMap = (value: Marked, path: ContentSourceMapParsedPath) => {\n const info = resolveEditInfo({studioUrl: options.studioUrl, resultSourceMap: sourceMap, resultPath: [...path, 'asset', '_ref']})\n if (!info || info.type === defaultsType) return\n const full = typeof info.path === 'string' ? info.path : studioPath.toString(info.path as never)\n const imagePath = full.replace(/\\.asset\\._ref$/, '')\n if (!imagePath || imagePath === full) return\n mark(value, info.id, info.type, imagePath, {\n baseUrl: info.baseUrl,\n workspace: info.workspace,\n tool: info.tool,\n projectId: info.projectId,\n dataset: info.dataset,\n })\n }\n const visit = (value: unknown, path: ContentSourceMapParsedPath) => {\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n const key = item && typeof item === 'object' && typeof (item as {_key?: unknown})._key === 'string' ? (item as {_key: string})._key : null\n const segment: Segment = key ? {_key: key, _index: index} : index\n visit(item, [...path, segment])\n })\n return\n }\n if (!value || typeof value !== 'object') return\n if (isImageValue(value) && !value._editTarget) fromSourceMap(value, path)\n for (const [key, child] of Object.entries(value)) {\n if (key.startsWith('_edit')) continue\n visit(child, [...path, key])\n }\n }\n visit(data, [])\n return data\n}\n\ntype OnInherit = (value: unknown, path: string[]) => unknown\ntype Source = {id: string; type: string; path: string; single?: boolean}\n\nconst sectionBase = (source: Source, key: string | undefined) => (key && !source.single ? `${source.path}[_key==\"${key}\"]` : source.path)\n\n/**\n * Rappel d'héritage pour `applyDefaults` (en aperçu), autour de `reattributeTo` :\n * - image héritée : vise le champ image de L'INSTANCE (choisir une image crée une\n * image propre à la page, la valeur par défaut ne change pas) ;\n * - texte hérité : sa valeur par défaut exacte est jointe (`collected`) ;\n * - liste simple ou texte riche hérité : modifiable ligne à ligne (voir `inherited.ts`).\n * `collected` est à rendre par la section avec `inheritedEditScriptProps`.\n */\nexport function withPreviewEditTargets(onInherit: OnInherit, source: Source, key: string | undefined, collected: InheritedEdit[], options: ImageEditOptions): OnInherit {\n const base = sectionBase(source, key)\n const pageId = source.id.replace(/^drafts\\./, '')\n const markInherited = (value: unknown, path: string) => {\n if (Array.isArray(value) || !value || typeof value !== 'object') return\n if (isImageValue(value)) {\n mark(value, pageId, source.type, path, {baseUrl: options.studioUrl})\n return\n }\n for (const [k, child] of Object.entries(value)) if (!k.startsWith('_')) markInherited(child, `${path}.${k}`)\n }\n return (value, path) => {\n const out = onInherit(value, path)\n if (out && typeof out === 'object' && !Array.isArray(out)) {\n const copy = isImageValue(out) ? {...out} : out\n markInherited(copy, `${base}.${path.join('.')}`)\n return copy\n }\n if (typeof out === 'string') collected.push({path: `${base}.${path.join('.')}`, value: vercelStegaClean(out)})\n // Liste héritée directement par un champ de la section (le parent existe dans la page).\n if (Array.isArray(out) && path.length === 1) return retagInheritedList(out, `${base}.${path[0]}`, source, collected)\n return out\n }\n}\n\n/**\n * Chemin EXACT des images qui appartiennent à la page, recalculé avec les clés\n * `_key` de la section. La carte des sources donne parfois un rang au lieu de la\n * clé (`images:0`) : Sanity ne retrouve alors pas le champ. Une image d'un AUTRE\n * document (carte liée, témoignage...) garde son repère.\n */\nexport function rekeyOwnImageTargets<T>(section: T, source: Source, key: string | undefined, options: ImageEditOptions): T {\n const pageId = source.id.replace(/^drafts\\./, '')\n const visit = (value: unknown, path: string) => {\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n const k = item && typeof item === 'object' ? (item as {_key?: unknown})._key : undefined\n visit(item, typeof k === 'string' ? `${path}[_key==\"${k}\"]` : `${path}[${index}]`)\n })\n return\n }\n if (!value || typeof value !== 'object') return\n if (isImageValue(value) && value._editDoc) {\n if (value._editDoc === pageId) mark(value, pageId, source.type, path, {baseUrl: options.studioUrl})\n return\n }\n for (const [k, child] of Object.entries(value)) if (!k.startsWith('_')) visit(child, `${path}.${k}`)\n }\n visit(section, sectionBase(source, key))\n return section\n}\n\nexport type ImageEditAttributes = {'data-sanity'?: string; 'data-edit-image'?: string; 'data-edit-doc'?: string; 'data-edit-type'?: string}\n\n/** Attributs à poser sur le cadre d'une image marquée ; vide pour les visiteurs. */\nexport function imageEditAttributes(image: ImageEditValue): ImageEditAttributes {\n if (!image?._editTarget || !image._editPath || !image._editDoc || !image._editType) return {}\n return {'data-sanity': image._editTarget, 'data-edit-image': image._editPath, 'data-edit-doc': image._editDoc, 'data-edit-type': image._editType}\n}\n\n/**\n * Alt d'une image marquée : nettoyé de ses marqueurs (sinon Sanity la prendrait\n * pour un texte et le clic ouvrirait l'alt au lieu de l'image).\n */\nexport function imageAlt(image: ImageEditValue, alt?: string): string {\n const value = alt ?? image?.alt ?? ''\n return image?._editTarget ? vercelStegaClean(value) : value\n}\n"],"mappings":";;;;;AAq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AM;EAAa,mBAAmB,MAAM;EAAW,iBAAiB,MAAM;EAAU,kBAAkB,MAAM;CAAS;AAClJ;;;;;AAMA,SAAgB,SAAS,OAAuB,KAAsB;CACpE,IAAM,QAAQ,OAAO,OAAO,OAAO;CACnC,OAAO,OAAO,cAAc,iBAAiB,KAAK,IAAI;AACxD"}
1
+ {"version":3,"file":"web-edit.js","names":[],"sources":["../src/web/edit/targets.ts"],"sourcesContent":["import {createDataAttribute} from '@sanity/visual-editing/create-data-attribute'\nimport {resolveEditInfo, studioPath, type ContentSourceMap, type ContentSourceMapParsedPath} from '@sanity/client/csm'\nimport {vercelStegaClean} from '@vercel/stega'\nimport {retag, retagInheritedList, type InheritedEdit} from './inherited'\nimport {vercelStegaDecode} from '@vercel/stega'\n\n/**\n * ÉDITION DANS L'APERÇU, IMAGES (mode brouillon seulement) : chaque image est\n * cliquable dans Presentation, alt rempli ou non, et porte son document et son\n * chemin EXACTS pour la pastille « Replace this image » (`NcfPreviewEditing`).\n *\n * Sanity ne repère d'ordinaire une image que par son alt (texte encodé en stega) :\n * une image sans alt n'avait aucun overlay. Ici, la carte des sources (Content\n * Source Map, renvoyée par `sanityFetch` en brouillon) donne pour chaque image son\n * document et son champ ; on les attache à la valeur (`_editTarget`, `_editPath`,\n * `_editDoc`, `_editType`), que le composant pose avec `imageEditAttributes`.\n *\n * Câblage d'un projet (starter) :\n * - `annotateImageEditTargets(data, sourceMap, {studioUrl})` sur le résultat de\n * `sanityFetch` en brouillon ;\n * - `withPreviewEditTargets(reattributeTo(source, key), source, key, collected, {studioUrl})`\n * comme rappel d'héritage de `applyDefaults` ;\n * - `rekeyOwnImageTargets(section, source, key, {studioUrl})` sur chaque section ;\n * - `imageEditAttributes(image)` / `imageAlt(image)` sur chaque image affichée.\n */\n\nexport type ImageEditValue = {\n asset?: {_ref?: string}\n alt?: string\n _editTarget?: string\n _editPath?: string\n _editDoc?: string\n _editType?: string\n /** Image héritée DANS une valeur par défaut (liste...) : champ à recopier d'abord. */\n _editInherited?: {path: string; sourceId: string; sourcePath: string}\n} | null | undefined\n\ntype Marked = {asset: {_ref: string}; _editTarget?: string; _editPath?: string; _editDoc?: string; _editType?: string; _editInherited?: {path: string; sourceId: string; sourcePath: string}; _editDefaults?: {id: string; path: string}}\ntype Segment = ContentSourceMapParsedPath[number]\n\nfunction isImageValue(value: unknown): value is Marked {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false\n const ref = (value as {asset?: {_ref?: unknown}}).asset?._ref\n return typeof ref === 'string' && ref.startsWith('image-')\n}\n\n/**\n * Pose le repère Sanity et le chemin exact. Image élément de liste\n * (`…images[_key==\"i3\"]`) : Sanity n'active pas un repère placé dans un élément de\n * liste d'images ; le repère vise la liste, le chemin exact reste dans `_editPath`.\n */\nfunction mark(value: Marked, id: string, type: string, path: string, extra: Record<string, string | undefined> & {baseUrl: string}) {\n const inList = /\\[[^\\]]+\\]$/.test(path)\n value._editTarget = createDataAttribute({...extra, id, type, path: inList ? path.replace(/\\[[^\\]]+\\]$/, '') : path}).toString()\n value._editPath = path\n value._editDoc = id.replace(/^drafts\\./, '')\n value._editType = type\n}\n\nexport type ImageEditOptions = {\n /** Adresse du Studio (celle de `stega.studioUrl`). */\n studioUrl: string\n /** Type du document des valeurs par défaut des composants (jamais marqué). */\n defaultsType?: string\n}\n\n/**\n * Marque chaque image du résultat d'une requête en brouillon. Une image venue du\n * document des valeurs par défaut n'est pas marquée ici (un clic modifierait\n * l'image de TOUTES les pages) : `withPreviewEditTargets` la fait viser l'instance.\n */\nexport function annotateImageEditTargets<T>(data: T, sourceMap: ContentSourceMap | null | undefined, options: ImageEditOptions): T {\n if (!sourceMap) return data\n const defaultsType = options.defaultsType ?? 'componentDefaults'\n const fromSourceMap = (value: Marked, path: ContentSourceMapParsedPath) => {\n const info = resolveEditInfo({studioUrl: options.studioUrl, resultSourceMap: sourceMap, resultPath: [...path, 'asset', '_ref']})\n if (!info) return\n const full = typeof info.path === 'string' ? info.path : studioPath.toString(info.path as never)\n const imagePath = full.replace(/\\.asset\\._ref$/, '')\n if (!imagePath || imagePath === full) return\n // Image des valeurs par défaut : pas de repère (il modifierait TOUTES les pages), mais\n // sa source brute, pour la recopier dans la page au remplacement.\n if (info.type === defaultsType) {\n value._editDefaults = {id: info.id.replace(/^drafts\\./, ''), path: imagePath}\n return\n }\n mark(value, info.id, info.type, imagePath, {\n baseUrl: info.baseUrl,\n workspace: info.workspace,\n tool: info.tool,\n projectId: info.projectId,\n dataset: info.dataset,\n })\n }\n const visit = (value: unknown, path: ContentSourceMapParsedPath) => {\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n const key = item && typeof item === 'object' && typeof (item as {_key?: unknown})._key === 'string' ? (item as {_key: string})._key : null\n const segment: Segment = key ? {_key: key, _index: index} : index\n visit(item, [...path, segment])\n })\n return\n }\n if (!value || typeof value !== 'object') return\n if (isImageValue(value) && !value._editTarget) fromSourceMap(value, path)\n for (const [key, child] of Object.entries(value)) {\n if (key.startsWith('_edit')) continue\n visit(child, [...path, key])\n }\n }\n visit(data, [])\n return data\n}\n\ntype OnInherit = (value: unknown, path: string[]) => unknown\ntype Source = {id: string; type: string; path: string; single?: boolean}\n\nconst sectionBase = (source: Source, key: string | undefined) => (key && !source.single ? `${source.path}[_key==\"${key}\"]` : source.path)\n\n/**\n * Rappel d'héritage pour `applyDefaults` (en aperçu), autour de `reattributeTo` :\n * - image héritée : vise le champ image de L'INSTANCE (choisir une image crée une\n * image propre à la page, la valeur par défaut ne change pas) ;\n * - texte hérité : sa valeur par défaut exacte est jointe (`collected`) ;\n * - liste simple ou texte riche hérité : modifiable ligne à ligne (voir `inherited.ts`).\n * `collected` est à rendre par la section avec `inheritedEditScriptProps`.\n */\nexport function withPreviewEditTargets(onInherit: OnInherit, source: Source, key: string | undefined, collected: InheritedEdit[], options: ImageEditOptions): OnInherit {\n const base = sectionBase(source, key)\n const pageId = source.id.replace(/^drafts\\./, '')\n const markInherited = (value: unknown, path: string) => {\n if (Array.isArray(value) || !value || typeof value !== 'object') return\n if (isImageValue(value)) {\n mark(value, pageId, source.type, path, {baseUrl: options.studioUrl})\n return\n }\n for (const [k, child] of Object.entries(value)) if (!k.startsWith('_')) markInherited(child, `${path}.${k}`)\n }\n return (value, path) => {\n const out = onInherit(value, path)\n const entryPath = `${base}.${path.join('.')}`\n if (typeof out === 'string') {\n collected.push({path: entryPath, value: vercelStegaClean(out)})\n return out\n }\n if (!out || typeof out !== 'object') return out\n // Image héritée seule : elle vise le champ de l'instance (choisir crée l'image de la page).\n if (isImageValue(out)) {\n const copy = {...out}\n markInherited(copy, entryPath)\n return copy\n }\n // Valeur héritée de N'IMPORTE QUELLE forme (liste, objet) : chaque texte et chaque image\n // vise son chemin EXACT dans la page ; à la première modification, la valeur brute des\n // valeurs par défaut est recopiée dans la page (source lue dans les marqueurs).\n const raw = defaultsSourceOf(value, path[path.length - 1] as string)\n if (raw) {\n collected.push({path: entryPath, source: raw})\n return retagDeep(out, entryPath, {...source, id: pageId}, {path: entryPath, sourceId: raw.id, sourcePath: raw.path}, options)\n }\n // Sans source repérable : l'ancienne règle (listes simples seulement).\n if (Array.isArray(out) && path.length === 1) return retagInheritedList(out, entryPath, source, collected)\n markInherited(out, entryPath)\n return out\n }\n}\n\n/** Champ des valeurs par défaut d'où vient une valeur héritée : lu dans un texte (stega) ou une image. */\nfunction defaultsSourceOf(value: unknown, field: string): {id: string; path: string} | null {\n let found: {id: string; full: string} | null = null\n const visit = (v: unknown) => {\n if (found || v === null || v === undefined) return\n if (typeof v === 'string') {\n const info = vercelStegaDecode(v) as {href?: string} | undefined\n if (!info?.href) return\n const href = decodeURIComponent(info.href)\n const id = /[;/]id=([^;?&]+)/.exec(href)?.[1]\n const full = /;path=([^;?&]+)/.exec(href)?.[1]\n if (id && full) found = {id: id.replace(/^drafts\\./, ''), full}\n return\n }\n if (Array.isArray(v)) return v.forEach(visit)\n if (typeof v === 'object') {\n const d = (v as Marked)._editDefaults\n if (d) found = {id: d.id, full: d.path}\n else for (const [k, x] of Object.entries(v)) if (!k.startsWith('_')) visit(x)\n }\n }\n visit(value)\n if (!found) return null\n const {id, full} = found as {id: string; full: string}\n // Chemin du champ dans le document des valeurs par défaut : jusqu'au segment `field`.\n const m = new RegExp(`^(.*?(?:^|\\\\.)${field.replace(/[^\\w]/g, '')})(?=[.[]|$)`).exec(full)\n return m?.[1] ? {id, path: m[1]} : null\n}\n\n/** Réétiquette chaque texte et marque chaque image d'une valeur héritée, à son chemin exact. */\nfunction retagDeep(value: unknown, path: string, page: {id: string; type: string}, inherited: {path: string; sourceId: string; sourcePath: string}, options: ImageEditOptions): unknown {\n if (typeof value === 'string') return retag(value, page, path)\n if (Array.isArray(value))\n return value.map((item, index) => {\n const k = item && typeof item === 'object' ? (item as {_key?: unknown})._key : undefined\n return retagDeep(item, typeof k === 'string' ? `${path}[_key==\"${k}\"]` : `${path}[${index}]`, page, inherited, options)\n })\n if (!value || typeof value !== 'object') return value\n if (isImageValue(value)) {\n const copy: Marked = {...value}\n mark(copy, page.id, page.type, path, {baseUrl: options.studioUrl})\n copy._editInherited = inherited\n return copy\n }\n return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, k.startsWith('_') ? v : retagDeep(v, `${path}.${k}`, page, inherited, options)]))\n}\n\n/**\n * Chemin EXACT des images qui appartiennent à la page, recalculé avec les clés\n * `_key` de la section. La carte des sources donne parfois un rang au lieu de la\n * clé (`images:0`) : Sanity ne retrouve alors pas le champ. Une image d'un AUTRE\n * document (carte liée, témoignage...) garde son repère.\n */\nexport function rekeyOwnImageTargets<T>(section: T, source: Source, key: string | undefined, options: ImageEditOptions): T {\n const pageId = source.id.replace(/^drafts\\./, '')\n const visit = (value: unknown, path: string) => {\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n const k = item && typeof item === 'object' ? (item as {_key?: unknown})._key : undefined\n visit(item, typeof k === 'string' ? `${path}[_key==\"${k}\"]` : `${path}[${index}]`)\n })\n return\n }\n if (!value || typeof value !== 'object') return\n if (isImageValue(value) && value._editDoc) {\n if (value._editDoc === pageId) mark(value, pageId, source.type, path, {baseUrl: options.studioUrl})\n return\n }\n for (const [k, child] of Object.entries(value)) if (!k.startsWith('_')) visit(child, `${path}.${k}`)\n }\n visit(section, sectionBase(source, key))\n return section\n}\n\nexport type ImageEditAttributes = {'data-sanity'?: string; 'data-edit-image'?: string; 'data-edit-doc'?: string; 'data-edit-type'?: string; 'data-edit-inherited'?: string}\n\n/** Attributs à poser sur le cadre d'une image marquée ; vide pour les visiteurs. */\nexport function imageEditAttributes(image: ImageEditValue): ImageEditAttributes {\n if (!image?._editTarget || !image._editPath || !image._editDoc || !image._editType) return {}\n return {\n 'data-sanity': image._editTarget,\n 'data-edit-image': image._editPath,\n 'data-edit-doc': image._editDoc,\n 'data-edit-type': image._editType,\n ...(image._editInherited ? {'data-edit-inherited': JSON.stringify(image._editInherited)} : {}),\n }\n}\n\n/**\n * Alt d'une image marquée : nettoyé de ses marqueurs (sinon Sanity la prendrait\n * pour un texte et le clic ouvrirait l'alt au lieu de l'image).\n */\nexport function imageAlt(image: ImageEditValue, alt?: string): string {\n const value = alt ?? image?.alt ?? ''\n return image?._editTarget ? vercelStegaClean(value) : value\n}\n"],"mappings":";;;;AAwCA,SAAS,aAAa,OAAiC;CACrD,IAAI,CAAC,SAAS,OAAO,SAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,OAAO;CACxE,IAAM,MAAO,MAAqC,OAAO;CACzD,OAAO,OAAO,OAAQ,YAAY,IAAI,WAAW,QAAQ;AAC3D;;;;;;AAOA,SAAS,KAAK,OAAe,IAAY,MAAc,MAAc,OAA+D;CAClI,IAAM,SAAS,cAAc,KAAK,IAAI;CAItC,AAHA,MAAM,cAAc,oBAAoB;EAAC,GAAG;EAAO;EAAI;EAAM,MAAM,SAAS,KAAK,QAAQ,eAAe,EAAE,IAAI;CAAI,CAAC,CAAC,CAAC,SAAS,GAC9H,MAAM,YAAY,MAClB,MAAM,WAAW,GAAG,QAAQ,aAAa,EAAE,GAC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EAAC,SAAS,QAAQ,UAAS,CAAC;IAClG;GACF;GACA,KAAK,IAAM,CAAC,GAAG,UAAU,OAAO,QAAQ,KAAK,GAAG,AAAK,EAAE,WAAW,GAAG,KAAG,MAAM,OAAO,GAAG,KAAK,GAAG,GAAG;EADnG;CAEF;CAEA,OADA,MAAM,SAAS,YAAY,QAAQ,GAAG,CAAC,GAChC;AACT;;AAKA,SAAgB,oBAAoB,OAA4C;CAE9E,OADI,CAAC,OAAO,eAAe,CAAC,MAAM,aAAa,CAAC,MAAM,YAAY,CAAC,MAAM,YAAkB,CAAC,IACrF;EACL,eAAe,MAAM;EACrB,mBAAmB,MAAM;EACzB,iBAAiB,MAAM;EACvB,kBAAkB,MAAM;EACxB,GAAI,MAAM,iBAAiB,EAAC,uBAAuB,KAAK,UAAU,MAAM,cAAc,EAAC,IAAI,CAAC;CAC9F;AACF;;;;;AAMA,SAAgB,SAAS,OAAuB,KAAsB;CACpE,IAAM,QAAQ,OAAO,OAAO,OAAO;CACnC,OAAO,OAAO,cAAc,iBAAiB,KAAK,IAAI;AACxD"}
@@ -18,6 +18,9 @@ type PreviewEditingLabels = {
18
18
  editMode: string;
19
19
  browseMode: string;
20
20
  modeLabel: string;
21
+ /** Contrôle automatique : « {n} à vérifier » (éléments non modifiables sur place). */
22
+ auditIssues: string;
23
+ auditHelp: string;
21
24
  };
22
25
  export declare const DEFAULT_PREVIEW_EDITING_LABELS: PreviewEditingLabels;
23
26
  /**
@@ -41,7 +44,7 @@ type NcfPreviewEditingProps = {
41
44
  labels?: Partial<PreviewEditingLabels>;
42
45
  /**
43
46
  * `'toggle'` (défaut) : interrupteur « Edit mode / Browse mode » du kit, en bas
44
- * à gauche de l'aperçu, mémorisé. Une fonction : le projet décide (ex. son propre
47
+ * à droite de l'aperçu, mémorisé. Une fonction : le projet décide (ex. son propre
45
48
  * interrupteur d'animations) ; le kit n'affiche alors rien.
46
49
  */
47
50
  editMode?: 'toggle' | (() => boolean);