@nocode-factory/sanity-kit 2.19.0 → 2.20.1

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/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { ClockIcon } from "@sanity/icons/Clock";
5
5
  import { ComponentIcon } from "@sanity/icons/Component";
6
6
  import { DocumentsIcon } from "@sanity/icons/Documents";
7
7
  import { ColorWheelIcon } from "@sanity/icons/ColorWheel";
8
- import { Badge, Box, Button, Card, Container, Flex, Grid, Select, Spinner, Stack, Tab, TabList, TabPanel, Text, TextArea, TextInput } from "@sanity/ui";
8
+ import { Badge, Box, Button, Card, Checkbox, Container, Flex, Grid, Select, Spinner, Stack, Tab, TabList, TabPanel, Text, TextArea, TextInput } from "@sanity/ui";
9
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
10
  import { IntentLink, useRouter } from "sanity/router";
11
11
  import { EyeOpenIcon } from "@sanity/icons/EyeOpen";
@@ -292,7 +292,42 @@ function useKitContext() {
292
292
  if (!value) throw Error("useKitContext doit être appelé dans un outil du plugin @nocode-factory/sanity-kit.");
293
293
  return value;
294
294
  }
295
- const useKitConfig = () => useKitContext().config, BOARD_LAYOUT_TYPE = "ncfBoardLayout", BOARD_LAYOUT_ID = "ncfBoardLayout", BOARD_NODE_TYPE = "ncfBoardNode", SECTION_NODE_TYPE = "ncfSectionNode", NODE_FIELD_TYPE = "ncfNodeField", COLUMN_TYPE = "ncfColumn", COLUMN_OPTION_TYPE = "ncfColumnOption", ANNOTATION_TYPE = "ncfAnnotation", NCF_HIDDEN_TYPES = [BOARD_LAYOUT_TYPE], boardNodeType = defineType({
295
+ const useKitConfig = () => useKitContext().config, TRANSLATION_TODO_TYPE = "ncfTranslationTodo", translationTodoId = (documentId) => `ncfTodo.${documentId.replace(/^drafts\./, "")}`, translationTodoType = defineType({
296
+ name: TRANSLATION_TODO_TYPE,
297
+ title: "À traduire (NCF)",
298
+ type: "document",
299
+ fields: [
300
+ defineField({
301
+ name: "documentId",
302
+ title: "Traduction",
303
+ type: "string",
304
+ readOnly: !0
305
+ }),
306
+ defineField({
307
+ name: "sourceId",
308
+ title: "Version principale",
309
+ type: "string",
310
+ readOnly: !0
311
+ }),
312
+ defineField({
313
+ name: "sourceLanguage",
314
+ title: "Langue principale",
315
+ type: "string",
316
+ readOnly: !0
317
+ }),
318
+ defineField({
319
+ name: "paths",
320
+ title: "Champs à traduire",
321
+ type: "array",
322
+ of: [{ type: "string" }],
323
+ readOnly: !0
324
+ })
325
+ ],
326
+ preview: {
327
+ select: { title: "documentId" },
328
+ prepare: ({ title }) => ({ title: `À traduire : ${title}` })
329
+ }
330
+ }), BOARD_LAYOUT_TYPE = "ncfBoardLayout", BOARD_LAYOUT_ID = "ncfBoardLayout", BOARD_NODE_TYPE = "ncfBoardNode", SECTION_NODE_TYPE = "ncfSectionNode", NODE_FIELD_TYPE = "ncfNodeField", COLUMN_TYPE = "ncfColumn", COLUMN_OPTION_TYPE = "ncfColumnOption", ANNOTATION_TYPE = "ncfAnnotation", NCF_HIDDEN_TYPES = [BOARD_LAYOUT_TYPE, TRANSLATION_TODO_TYPE], boardNodeType = defineType({
296
331
  name: BOARD_NODE_TYPE,
297
332
  title: "Position d'une page",
298
333
  type: "object",
@@ -566,6 +601,7 @@ const useKitConfig = () => useKitContext().config, BOARD_LAYOUT_TYPE = "ncfBoard
566
601
  ],
567
602
  preview: { prepare: () => ({ title: "Disposition du board (NCF)" }) }
568
603
  }),
604
+ translationTodoType,
569
605
  boardNodeType,
570
606
  sectionNodeType,
571
607
  nodeFieldType,
@@ -1381,7 +1417,7 @@ function explainGrantError(error) {
1381
1417
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1382
1418
  * le vérifie.
1383
1419
  */
1384
- const KIT_VERSION = "2.19.0";
1420
+ const KIT_VERSION = "2.20.1";
1385
1421
  /**
1386
1422
  * Signale ce Studio au service du kit, une fois par montage.
1387
1423
  *
@@ -1708,7 +1744,7 @@ function useKitUpdate() {
1708
1744
  !controller.signal.aborted && body?.version && setLatest(body.version);
1709
1745
  }).catch(() => {}), () => controller.abort();
1710
1746
  }, []);
1711
- let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.19.0") > 0);
1747
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.20.1") > 0);
1712
1748
  return {
1713
1749
  current: KIT_VERSION,
1714
1750
  latest,
@@ -6741,7 +6777,7 @@ function flatten(value, prefix = "", out = /* @__PURE__ */ new Map()) {
6741
6777
  }
6742
6778
  return prefix && out.set(prefix, value), out;
6743
6779
  }
6744
- const same$1 = (a, b) => a === b || Number.isNaN(a) && Number.isNaN(b) || JSON.stringify(a) === JSON.stringify(b);
6780
+ const same$2 = (a, b) => a === b || Number.isNaN(a) && Number.isNaN(b) || JSON.stringify(a) === JSON.stringify(b);
6745
6781
  /**
6746
6782
  * Modifications entre deux états, triées par chemin.
6747
6783
  *
@@ -6754,7 +6790,7 @@ function diffDocuments(before, after) {
6754
6790
  for (let path of paths) {
6755
6791
  let had = left.has(path), has = right.has(path), valueBefore = left.get(path), valueAfter = right.get(path);
6756
6792
  if (had && has) {
6757
- same$1(valueBefore, valueAfter) || changes.push({
6793
+ same$2(valueBefore, valueAfter) || changes.push({
6758
6794
  path,
6759
6795
  kind: "changed",
6760
6796
  before: valueBefore,
@@ -6837,27 +6873,27 @@ const isTextChange = (before, after) => typeof before == "string" && typeof afte
6837
6873
  "_createdAt",
6838
6874
  "_id",
6839
6875
  "_type"
6840
- ]), isObject = (v) => typeof v == "object" && !!v && !Array.isArray(v), same = (a, b) => JSON.stringify(a) === JSON.stringify(b), keyed = (v) => Array.isArray(v) && v.every((item) => isObject(item) && typeof item._key == "string"), ABSENT = Symbol("absent");
6876
+ ]), isObject = (v) => typeof v == "object" && !!v && !Array.isArray(v), same$1 = (a, b) => JSON.stringify(a) === JSON.stringify(b), keyed$1 = (v) => Array.isArray(v) && v.every((item) => isObject(item) && typeof item._key == "string"), ABSENT$1 = Symbol("absent");
6841
6877
  function revert(current, before, after, path, out) {
6842
- if (same(before, after)) return current;
6843
- if (same(current, after)) return out.reverted++, before;
6878
+ if (same$1(before, after)) return current;
6879
+ if (same$1(current, after)) return out.reverted++, before;
6844
6880
  if (isObject(current) && isObject(before) && isObject(after)) {
6845
6881
  let result = { ...current };
6846
6882
  for (let key of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])) {
6847
6883
  if (SYSTEM_KEYS.has(key)) continue;
6848
- let v = revert(key in current ? current[key] : ABSENT, key in before ? before[key] : ABSENT, key in after ? after[key] : ABSENT, path ? `${path}.${key}` : key, out);
6849
- v === ABSENT ? delete result[key] : result[key] = v;
6884
+ let v = revert(key in current ? current[key] : ABSENT$1, key in before ? before[key] : ABSENT$1, key in after ? after[key] : ABSENT$1, path ? `${path}.${key}` : key, out);
6885
+ v === ABSENT$1 ? delete result[key] : result[key] = v;
6850
6886
  }
6851
6887
  return result;
6852
6888
  }
6853
- if (keyed(current) && keyed(before) && keyed(after)) {
6889
+ if (keyed$1(current) && keyed$1(before) && keyed$1(after)) {
6854
6890
  let result = [...current], at = (list, key) => list.findIndex((item) => item._key === key);
6855
6891
  for (let key of /* @__PURE__ */ new Set([...before.map((i) => i._key), ...after.map((i) => i._key)])) {
6856
6892
  let b = before[at(before, key)], a = after[at(after, key)], index = at(result, key), label = `${path}[${key}]`;
6857
6893
  if (index >= 0) {
6858
- let v = revert(result[index], b ?? ABSENT, a ?? ABSENT, label, out);
6859
- v === ABSENT ? result.splice(index, 1) : result[index] = v;
6860
- } else b && !a ? (result.splice(Math.min(at(before, key), result.length), 0, b), out.reverted++) : b && a && !same(a, b) && out.conflicts.push(label);
6894
+ let v = revert(result[index], b ?? ABSENT$1, a ?? ABSENT$1, label, out);
6895
+ v === ABSENT$1 ? result.splice(index, 1) : result[index] = v;
6896
+ } else b && !a ? (result.splice(Math.min(at(before, key), result.length), 0, b), out.reverted++) : b && a && !same$1(a, b) && out.conflicts.push(label);
6861
6897
  }
6862
6898
  return result;
6863
6899
  }
@@ -7546,14 +7582,14 @@ function DesignSystemTool() {
7546
7582
  })
7547
7583
  });
7548
7584
  }
7549
- const store = /* @__PURE__ */ new Map();
7550
- function entryFor(client, type, languageField, language) {
7551
- let { projectId, dataset } = client.config(), key = `${projectId}:${dataset}:${type}:${language ?? ""}`, entry = store.get(key);
7585
+ const store$1 = /* @__PURE__ */ new Map();
7586
+ function entryFor$1(client, type, languageField, language) {
7587
+ let { projectId, dataset } = client.config(), key = `${projectId}:${dataset}:${type}:${language ?? ""}`, entry = store$1.get(key);
7552
7588
  entry || (entry = {
7553
7589
  value: null,
7554
7590
  listeners: /* @__PURE__ */ new Set(),
7555
7591
  stop: null
7556
- }, store.set(key, entry));
7592
+ }, store$1.set(key, entry));
7557
7593
  let e = entry;
7558
7594
  if (!e.stop) {
7559
7595
  let filter = `_type == $type && ($language == null || !defined(${languageField}) || ${languageField} == $language)`, params = {
@@ -7572,7 +7608,7 @@ function entryFor(client, type, languageField, language) {
7572
7608
  return [key, e];
7573
7609
  }
7574
7610
  function useComponentDefaults(client, type, languageField, language) {
7575
- let [, entry] = entryFor(client, type, languageField, language), value = useSyncExternalStore((listener) => (entry.listeners.add(listener), () => {
7611
+ let [, entry] = entryFor$1(client, type, languageField, language), value = useSyncExternalStore((listener) => (entry.listeners.add(listener), () => {
7576
7612
  entry.listeners.delete(listener);
7577
7613
  }), () => entry.value);
7578
7614
  return useEffect(() => () => {
@@ -7713,34 +7749,28 @@ function createOverrideInput(config) {
7713
7749
  });
7714
7750
  }
7715
7751
  function WithDot(props) {
7716
- let { rel, inList, shortName, parent, ...inputProps } = props, client = useKitClient(), languageField = config.i18n?.field ?? "language", language = useFormValue([languageField]) ?? null, inherited = defaultValueAt(useComponentDefaults(client, defaultsType, languageField, language), shortName, rel), field = rel[rel.length - 1] ?? "", router = useRouter();
7717
- if (isEmptyValue(inputProps.value) && !isEmptyValue(inherited)) {
7718
- let st = inputProps.schemaType, placeholder = (st.jsonType === "string" || st.jsonType === "number") && !st.options?.list?.length ? inheritedPlaceholder(inherited) : null, withPlaceholder = placeholder === null ? inputProps : {
7719
- ...inputProps,
7720
- elementProps: {
7721
- ...inputProps.elementProps,
7722
- placeholder
7723
- }
7724
- };
7725
- return /* @__PURE__ */ jsxs(Stack, {
7726
- gap: 2,
7727
- children: [inputProps.renderDefault(withPlaceholder), placeholder === null && /* @__PURE__ */ jsxs(Text, {
7728
- size: 0,
7729
- muted: !0,
7730
- children: ["Valeur par défaut du composant : ", describeValue(inherited)]
7731
- })]
7732
- });
7733
- }
7734
- if (!isOverride(inputProps.value, inherited, field, parent)) return inputProps.renderDefault(inputProps);
7735
- let action = resetAction(inherited), onClick = action.kind === "noDefault" ? () => router.navigateIntent("edit", componentIntentParams(`${namespace}${shortName}`, namespace, config.componentPreview, defaultsType)) : inList ? () => inputProps.onChange(set(structuredClone(inherited))) : () => inputProps.onChange(unset());
7752
+ let { rel, inList, shortName, parent, ...inputProps } = props, client = useKitClient(), languageField = config.i18n?.field ?? "language", language = useFormValue([languageField]) ?? null, inherited = defaultValueAt(useComponentDefaults(client, defaultsType, languageField, language), shortName, rel), field = rel[rel.length - 1] ?? "", router = useRouter(), inherits = isEmptyValue(inputProps.value) && !isEmptyValue(inherited), st = inputProps.schemaType, freeText = (st.jsonType === "string" || st.jsonType === "number") && !st.options?.list?.length, placeholder = inherits && freeText ? inheritedPlaceholder(inherited) : null, shown = placeholder === null ? inputProps : {
7753
+ ...inputProps,
7754
+ elementProps: {
7755
+ ...inputProps.elementProps,
7756
+ placeholder
7757
+ }
7758
+ }, override = !inherits && isOverride(inputProps.value, inherited, field, parent), action = resetAction(inherited), onClick = action.kind === "noDefault" ? () => router.navigateIntent("edit", componentIntentParams(`${namespace}${shortName}`, namespace, config.componentPreview, defaultsType)) : inList ? () => inputProps.onChange(set(structuredClone(inherited))) : () => inputProps.onChange(unset());
7736
7759
  return /* @__PURE__ */ jsxs(Flex, {
7737
7760
  align: "flex-start",
7738
7761
  gap: 2,
7739
- children: [/* @__PURE__ */ jsx(Box, {
7762
+ children: [/* @__PURE__ */ jsxs(Box, {
7740
7763
  flex: 1,
7741
7764
  style: { minWidth: 0 },
7742
- children: inputProps.renderDefault(inputProps)
7743
- }), /* @__PURE__ */ jsx(OverrideDot, {
7765
+ children: [inputProps.renderDefault(shown), inherits && placeholder === null && /* @__PURE__ */ jsx(Box, {
7766
+ marginTop: 2,
7767
+ children: /* @__PURE__ */ jsxs(Text, {
7768
+ size: 0,
7769
+ muted: !0,
7770
+ children: ["Valeur par défaut du composant : ", describeValue(inherited)]
7771
+ })
7772
+ })]
7773
+ }), override && /* @__PURE__ */ jsx(OverrideDot, {
7744
7774
  hasDefault: action.kind !== "noDefault",
7745
7775
  full: describeValue(inherited),
7746
7776
  short: shortValue(inherited),
@@ -7902,16 +7932,14 @@ function createSlugUrlInput(config) {
7902
7932
  path: pageType.path,
7903
7933
  pathPrefix: pageType.pathPrefix,
7904
7934
  locale
7905
- }, config.i18n) : null, url = toUrl(config.previewUrl, path);
7906
- if (!url) return props.renderDefault(props);
7907
- let copy = () => {
7908
- navigator.clipboard.writeText(url).then(() => {
7935
+ }, config.i18n) : null, url = toUrl(config.previewUrl, path), copy = () => {
7936
+ url && navigator.clipboard.writeText(url).then(() => {
7909
7937
  setCopied(!0), window.setTimeout(() => setCopied(!1), 1500);
7910
7938
  });
7911
7939
  };
7912
7940
  return /* @__PURE__ */ jsxs(Stack, {
7913
7941
  gap: 2,
7914
- children: [props.renderDefault(props), /* @__PURE__ */ jsx(Card, {
7942
+ children: [props.renderDefault(props), url && /* @__PURE__ */ jsx(Card, {
7915
7943
  tone: "primary",
7916
7944
  padding: 2,
7917
7945
  radius: 2,
@@ -7962,6 +7990,411 @@ function isSlugInput(props) {
7962
7990
  }
7963
7991
  return !1;
7964
7992
  }
7993
+ const store = /* @__PURE__ */ new Map();
7994
+ function entryFor(client, documentId) {
7995
+ let { projectId, dataset } = client.config(), id = translationTodoId(documentId), key = `${projectId}:${dataset}:${id}`, entry = store.get(key);
7996
+ entry || (entry = {
7997
+ value: null,
7998
+ listeners: /* @__PURE__ */ new Set(),
7999
+ stop: null
8000
+ }, store.set(key, entry));
8001
+ let e = entry;
8002
+ if (!e.stop) {
8003
+ let load = () => client.fetch("*[_id == $id][0]{_id, sourceLanguage, paths}", { id }).then((value) => {
8004
+ e.value = value, e.listeners.forEach((l) => l());
8005
+ }).catch(() => {});
8006
+ load();
8007
+ let sub = client.listen("*[_id == $id]", { id }, {
8008
+ visibility: "query",
8009
+ includeResult: !1
8010
+ }).subscribe({ next: () => void load() });
8011
+ e.stop = () => sub.unsubscribe();
8012
+ }
8013
+ return e;
8014
+ }
8015
+ function useTranslationTodo(client, documentId) {
8016
+ let entry = documentId ? entryFor(client, documentId) : null, value = useSyncExternalStore((listener) => entry ? (entry.listeners.add(listener), () => {
8017
+ entry.listeners.delete(listener);
8018
+ }) : () => {}, () => entry?.value ?? null);
8019
+ return useEffect(() => () => {
8020
+ entry && entry.listeners.size === 0 && entry.stop && (entry.stop(), entry.stop = null);
8021
+ }, [entry]), value;
8022
+ }
8023
+ /** Chemin lisible d'un champ du formulaire, au format de la propagation (`sections[a].title`). */
8024
+ function fieldPathKey(path) {
8025
+ let out = "";
8026
+ for (let seg of path) typeof seg == "string" ? out += out ? `.${seg}` : seg : seg && typeof seg == "object" && "_key" in seg ? out += `[${String(seg._key)}]` : typeof seg == "number" && (out += `[${seg}]`);
8027
+ return out;
8028
+ }
8029
+ /**
8030
+ * Sous un champ d'une traduction modifié dans la version principale (propagation) :
8031
+ * « À traduire », avec « Marquer comme traduit » qui le retire de la liste.
8032
+ */
8033
+ function withTranslationTodo(Inner, config) {
8034
+ function TranslationTodoInput(props) {
8035
+ let id = useFormValue(["_id"]), client = useKitClient(), todo = useTranslationTodo(client, config.i18n ? id : void 0), [busy, setBusy] = useState(!1), key = fieldPathKey(props.path), inner = createElement(Inner, props), show = !!todo?.paths?.includes(key), done = () => {
8036
+ todo && (setBusy(!0), client.patch(todo._id).set({ paths: (todo.paths ?? []).filter((p) => p !== key) }).commit().finally(() => setBusy(!1)));
8037
+ };
8038
+ return /* @__PURE__ */ jsxs(Stack, {
8039
+ gap: 2,
8040
+ children: [inner, show && /* @__PURE__ */ jsx(Card, {
8041
+ tone: "caution",
8042
+ padding: 2,
8043
+ radius: 2,
8044
+ border: !0,
8045
+ children: /* @__PURE__ */ jsxs(Flex, {
8046
+ align: "center",
8047
+ gap: 2,
8048
+ children: [/* @__PURE__ */ jsxs(Text, {
8049
+ size: 1,
8050
+ style: { flex: 1 },
8051
+ children: [
8052
+ "À traduire : modifié dans la version ",
8053
+ (todo?.sourceLanguage ?? "").toUpperCase(),
8054
+ "."
8055
+ ]
8056
+ }), /* @__PURE__ */ jsx(Button, {
8057
+ mode: "ghost",
8058
+ fontSize: 1,
8059
+ padding: 2,
8060
+ text: "Marquer comme traduit",
8061
+ disabled: busy,
8062
+ onClick: done
8063
+ })]
8064
+ })
8065
+ })]
8066
+ });
8067
+ }
8068
+ return TranslationTodoInput;
8069
+ }
8070
+ const VALUE_TYPE_NAMES = /* @__PURE__ */ new Set([
8071
+ "image",
8072
+ "file",
8073
+ "reference",
8074
+ "crossDatasetReference",
8075
+ "slug",
8076
+ "geopoint",
8077
+ "url",
8078
+ "email",
8079
+ "date",
8080
+ "datetime",
8081
+ "number",
8082
+ "boolean"
8083
+ ]), SKIP_KEYS = /* @__PURE__ */ new Set(["language", "slug"]), isObj = (v) => typeof v == "object" && !!v && !Array.isArray(v), same = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null), keyed = (v) => Array.isArray(v) && v.length > 0 && v.every((i) => isObj(i) && typeof i._key == "string");
8084
+ function typeNames(t) {
8085
+ let out = [];
8086
+ for (let c = t; c; c = c.type) c.name && out.push(c.name);
8087
+ return out;
8088
+ }
8089
+ /** Nature d'un champ d'après son schéma (et sa valeur, faute de schéma). */
8090
+ function kindOf(t, value) {
8091
+ if (t) {
8092
+ if (typeNames(t).some((n) => VALUE_TYPE_NAMES.has(n)) || t.to) return "value";
8093
+ if (t.jsonType === "array") {
8094
+ let of = t.of ?? [];
8095
+ if (of.some((m) => typeNames(m).includes("block"))) return "text";
8096
+ if (of.some((m) => m.jsonType === "object" || typeNames(m).includes("object"))) return "list";
8097
+ let prim = of[0];
8098
+ return prim && prim.jsonType === "string" && !prim.options?.list?.length ? "text" : "value";
8099
+ }
8100
+ return t.jsonType === "object" ? "object" : t.jsonType === "string" ? t.options?.list?.length ? "value" : "text" : "value";
8101
+ }
8102
+ return keyed(value) ? "list" : isObj(value) ? "object" : "value";
8103
+ }
8104
+ function fieldType(t, name) {
8105
+ for (let c = t; c; c = c.type) {
8106
+ let f = c.fields?.find((x) => x.name === name);
8107
+ if (f) return f.type;
8108
+ }
8109
+ }
8110
+ function itemType(t, item) {
8111
+ let of;
8112
+ for (let c = t; c && !of; c = c.type) of = c.of;
8113
+ if (of?.length) return of.find((m) => typeNames(m).includes(item._type)) ?? (of.length === 1 ? of[0] : void 0);
8114
+ }
8115
+ /** Tous les textes d'un élément ajouté : à traduire. */
8116
+ function collectTexts(value, t, path, acc) {
8117
+ let kind = kindOf(t, value);
8118
+ if (kind === "text") value != null && value !== "" && acc.toTranslate.push(path);
8119
+ else if (kind === "object" && isObj(value)) for (let [k, v] of Object.entries(value)) k.startsWith("_") || collectTexts(v, fieldType(t, k), `${path}.${k}`, acc);
8120
+ else if (kind === "list" && Array.isArray(value)) for (let item of value) isObj(item) && collectTexts(item, itemType(t, item), `${path}[${String(item._key)}]`, acc);
8121
+ }
8122
+ const ABSENT = Symbol("absent");
8123
+ function merge(target, before, after, t, path, acc) {
8124
+ if (same(before, after)) return target === void 0 ? ABSENT : target;
8125
+ let kind = kindOf(t, after ?? before);
8126
+ if (kind === "text") return after == null || after === "" ? (target != null && target !== "" && acc.toTranslate.push(path), target === void 0 ? ABSENT : target) : (acc.toTranslate.push(path), target == null || target === "" || same(target, before) ? after : target);
8127
+ if (kind === "value") return acc.copied.push(path), after === void 0 ? ABSENT : after;
8128
+ if (kind === "object") {
8129
+ if (!isObj(after)) return acc.copied.push(path), after === void 0 ? ABSENT : after;
8130
+ let base = isObj(target) ? { ...target } : { _type: after._type }, b = isObj(before) ? before : {};
8131
+ for (let k of /* @__PURE__ */ new Set([...Object.keys(b), ...Object.keys(after)])) {
8132
+ if (k.startsWith("_") || SKIP_KEYS.has(k)) continue;
8133
+ let v = merge(base[k], b[k], after[k], fieldType(t, k), path ? `${path}.${k}` : k, acc);
8134
+ v === ABSENT ? delete base[k] : base[k] = v;
8135
+ }
8136
+ return base;
8137
+ }
8138
+ let tgt = Array.isArray(target) ? target.filter(isObj) : [], bef = Array.isArray(before) ? before.filter(isObj) : [], aft = Array.isArray(after) ? after.filter(isObj) : [], byKey = (list) => new Map(list.map((i) => [i._key, i])), tMap = byKey(tgt), bMap = byKey(bef), aMap = byKey(aft), result = [];
8139
+ for (let item of aft) {
8140
+ let key = item._key, it = itemType(t, item);
8141
+ if (tMap.has(key)) {
8142
+ let merged = merge(tMap.get(key), bMap.get(key), item, it, `${path}[${key}]`, acc);
8143
+ result.push(merged === ABSENT ? item : merged);
8144
+ } else result.push(structuredClone(item)), acc.added++, collectTexts(item, it, `${path}[${key}]`, acc);
8145
+ }
8146
+ for (let key of bMap.keys()) !aMap.has(key) && tMap.has(key) && acc.removed++;
8147
+ tgt.forEach((item, index) => {
8148
+ let key = item._key;
8149
+ if (bMap.has(key) || aMap.has(key)) return;
8150
+ let prev = tgt.slice(0, index).reverse().find((p) => result.some((r) => r._key === p._key)), at = prev ? result.findIndex((r) => r._key === prev._key) + 1 : 0;
8151
+ result.splice(at, 0, item);
8152
+ });
8153
+ let common = (list) => list.map((i) => i._key).filter((k) => tMap.has(k) && aMap.has(k));
8154
+ return same(common(tgt), common(aft)) || (acc.moved = !0), result;
8155
+ }
8156
+ /**
8157
+ * Applique la modification `before` → `after` (version principale) à `target`
8158
+ * (brouillon ou version publiée de la traduction). `documentType` : schéma du
8159
+ * document, pour distinguer textes et valeurs.
8160
+ */
8161
+ function propagate(target, before, after, documentType) {
8162
+ let acc = {
8163
+ toTranslate: [],
8164
+ copied: [],
8165
+ added: 0,
8166
+ removed: 0,
8167
+ moved: !1
8168
+ }, merged = merge(target ?? {}, before ?? {}, after, documentType, "", acc);
8169
+ return {
8170
+ document: {
8171
+ ...target ?? {},
8172
+ ...isObj(merged) ? merged : {}
8173
+ },
8174
+ ...acc
8175
+ };
8176
+ }
8177
+ /** La propagation changerait-elle quelque chose ? */
8178
+ function hasChanges(r) {
8179
+ return r.toTranslate.length > 0 || r.copied.length > 0 || r.added > 0 || r.removed > 0 || r.moved;
8180
+ }
8181
+ /**
8182
+ * Publier la version PRINCIPALE d'une page qui a des traductions : la publication
8183
+ * part normalement, puis « Propager aux autres langues ? » propose d'appliquer aux
8184
+ * BROUILLONS des traductions la structure (sections ajoutées, supprimées, déplacées)
8185
+ * et les valeurs non textuelles (images, liens, options…). Les textes traduits ne
8186
+ * sont jamais écrasés : les textes modifiés sont marqués « à traduire ». Rien n'est
8187
+ * publié dans les autres langues : on relit, on traduit, on publie.
8188
+ */
8189
+ function withPropagation(Publish, config) {
8190
+ let i18n = config.i18n, Wrapped = (props) => {
8191
+ let base = Publish(props), [run, setRun] = useState(null), current = props.draft ?? props.published;
8192
+ return !base || !i18n || current?.[i18n.field] !== i18n.defaultLocale ? base : {
8193
+ ...base,
8194
+ onHandle: () => {
8195
+ let before = props.published, after = props.draft;
8196
+ base.onHandle?.(), before && after && setRun({
8197
+ before,
8198
+ after
8199
+ });
8200
+ },
8201
+ dialog: run ? {
8202
+ type: "dialog",
8203
+ header: "Propager aux autres langues ?",
8204
+ width: "medium",
8205
+ onClose: () => {
8206
+ setRun(null), props.onComplete();
8207
+ },
8208
+ content: /* @__PURE__ */ jsx(PropagateDialog, {
8209
+ config,
8210
+ id: props.id,
8211
+ type: props.type,
8212
+ before: run.before,
8213
+ after: run.after,
8214
+ onDone: () => {
8215
+ setRun(null), props.onComplete();
8216
+ }
8217
+ })
8218
+ } : base.dialog
8219
+ };
8220
+ };
8221
+ return Wrapped.action = Publish.action, Wrapped;
8222
+ }
8223
+ function PropagateDialog(props) {
8224
+ let { config, id, type, before, after, onDone } = props, client = useKitClient(), schema = useSchema(), field = config.i18n?.field ?? "language", source = String(after[field] ?? ""), [targets, setTargets] = useState(null), [busy, setBusy] = useState(!1), [done, setDone] = useState(null), [error, setError] = useState(null);
8225
+ useEffect(() => {
8226
+ let documentType = schema.get(type);
8227
+ (async () => {
8228
+ let translations = await client.fetch("*[_type == \"translation.metadata\" && references($id)][0].translations[]{language, \"id\": value._ref}", { id }), list = [];
8229
+ for (let t of translations ?? []) {
8230
+ if (!t?.id || t.id === id || t.language === source) continue;
8231
+ let target = await client.getDocument(`drafts.${t.id}`) ?? await client.getDocument(t.id) ?? null;
8232
+ if (!target) continue;
8233
+ let result = propagate(target, before, after, documentType);
8234
+ list.push({
8235
+ language: t.language,
8236
+ id: t.id,
8237
+ result,
8238
+ selected: hasChanges(result)
8239
+ });
8240
+ }
8241
+ setTargets(list);
8242
+ })().catch(() => setTargets([]));
8243
+ }, [
8244
+ client,
8245
+ schema,
8246
+ id,
8247
+ type,
8248
+ before,
8249
+ after,
8250
+ source
8251
+ ]);
8252
+ let apply = async () => {
8253
+ setBusy(!0), setError(null);
8254
+ try {
8255
+ let applied = [];
8256
+ for (let t of targets ?? []) {
8257
+ if (!t.selected) continue;
8258
+ let { _rev, _createdAt, _updatedAt, ...doc } = t.result.document;
8259
+ if (await client.createOrReplace({
8260
+ ...doc,
8261
+ _id: `drafts.${t.id}`,
8262
+ _type: type
8263
+ }), t.result.toTranslate.length) {
8264
+ let todoId = translationTodoId(t.id), existing = await client.fetch("*[_id == $todoId][0].paths", { todoId });
8265
+ await client.createOrReplace({
8266
+ _id: todoId,
8267
+ _type: TRANSLATION_TODO_TYPE,
8268
+ documentId: t.id,
8269
+ sourceId: id,
8270
+ sourceLanguage: source,
8271
+ paths: [.../* @__PURE__ */ new Set([...existing ?? [], ...t.result.toTranslate])]
8272
+ });
8273
+ }
8274
+ applied.push(t.language.toUpperCase());
8275
+ }
8276
+ setDone(applied);
8277
+ } catch (cause) {
8278
+ setError(`La propagation a échoué, rien n'a été publié. (${(cause instanceof Error ? cause.message : String(cause)).slice(0, 140)})`);
8279
+ } finally {
8280
+ setBusy(!1);
8281
+ }
8282
+ };
8283
+ return done ? /* @__PURE__ */ jsxs(Stack, {
8284
+ gap: 4,
8285
+ padding: 4,
8286
+ children: [/* @__PURE__ */ jsx(Text, {
8287
+ size: 1,
8288
+ children: done.length ? `Brouillons mis à jour : ${done.join(", ")}. Relisez, traduisez les champs marqués « À traduire », puis publiez chaque langue.` : "Rien n’a été propagé."
8289
+ }), /* @__PURE__ */ jsx(Flex, {
8290
+ justify: "flex-end",
8291
+ children: /* @__PURE__ */ jsx(Button, {
8292
+ text: "Fermer",
8293
+ mode: "ghost",
8294
+ onClick: onDone
8295
+ })
8296
+ })]
8297
+ }) : targets ? targets.some((t) => hasChanges(t.result)) ? /* @__PURE__ */ jsxs(Stack, {
8298
+ gap: 4,
8299
+ padding: 4,
8300
+ children: [
8301
+ /* @__PURE__ */ jsxs(Text, {
8302
+ size: 1,
8303
+ children: [
8304
+ "La version ",
8305
+ source.toUpperCase(),
8306
+ " est publiée. Appliquer ses changements aux brouillons des autres langues ? Les textes traduits ne sont jamais écrasés : les textes modifiés sont marqués « À traduire ». Rien n’est publié."
8307
+ ]
8308
+ }),
8309
+ /* @__PURE__ */ jsx(Stack, {
8310
+ gap: 3,
8311
+ children: targets.map((t, index) => /* @__PURE__ */ jsx(Card, {
8312
+ padding: 3,
8313
+ radius: 2,
8314
+ border: !0,
8315
+ children: /* @__PURE__ */ jsxs(Flex, {
8316
+ gap: 3,
8317
+ align: "flex-start",
8318
+ children: [/* @__PURE__ */ jsx(Checkbox, {
8319
+ checked: t.selected,
8320
+ disabled: !hasChanges(t.result),
8321
+ onChange: () => setTargets(targets.map((x, i) => i === index ? {
8322
+ ...x,
8323
+ selected: !x.selected
8324
+ } : x))
8325
+ }), /* @__PURE__ */ jsx(Box, {
8326
+ flex: 1,
8327
+ children: /* @__PURE__ */ jsxs(Stack, {
8328
+ gap: 2,
8329
+ children: [/* @__PURE__ */ jsx(Text, {
8330
+ size: 1,
8331
+ weight: "semibold",
8332
+ children: t.language.toUpperCase()
8333
+ }), /* @__PURE__ */ jsx(Text, {
8334
+ size: 1,
8335
+ muted: !0,
8336
+ children: summary(t.result)
8337
+ })]
8338
+ })
8339
+ })]
8340
+ })
8341
+ }, t.id))
8342
+ }),
8343
+ error && /* @__PURE__ */ jsx(Card, {
8344
+ tone: "critical",
8345
+ padding: 3,
8346
+ radius: 2,
8347
+ children: /* @__PURE__ */ jsx(Text, {
8348
+ size: 1,
8349
+ children: error
8350
+ })
8351
+ }),
8352
+ /* @__PURE__ */ jsxs(Flex, {
8353
+ justify: "flex-end",
8354
+ gap: 2,
8355
+ children: [/* @__PURE__ */ jsx(Button, {
8356
+ text: "Ignorer",
8357
+ mode: "ghost",
8358
+ onClick: onDone,
8359
+ disabled: busy
8360
+ }), /* @__PURE__ */ jsx(Button, {
8361
+ text: busy ? "Propagation…" : "Propager",
8362
+ tone: "primary",
8363
+ onClick: () => void apply(),
8364
+ disabled: busy || !targets.some((t) => t.selected)
8365
+ })]
8366
+ })
8367
+ ]
8368
+ }) : /* @__PURE__ */ jsxs(Stack, {
8369
+ gap: 4,
8370
+ padding: 4,
8371
+ children: [/* @__PURE__ */ jsx(Text, {
8372
+ size: 1,
8373
+ children: "Aucune traduction à mettre à jour."
8374
+ }), /* @__PURE__ */ jsx(Flex, {
8375
+ justify: "flex-end",
8376
+ children: /* @__PURE__ */ jsx(Button, {
8377
+ text: "Fermer",
8378
+ mode: "ghost",
8379
+ onClick: onDone
8380
+ })
8381
+ })]
8382
+ }) : /* @__PURE__ */ jsxs(Flex, {
8383
+ align: "center",
8384
+ gap: 3,
8385
+ padding: 4,
8386
+ children: [/* @__PURE__ */ jsx(Spinner, { muted: !0 }), /* @__PURE__ */ jsx(Text, {
8387
+ size: 1,
8388
+ muted: !0,
8389
+ children: "Comparaison avec les traductions…"
8390
+ })]
8391
+ });
8392
+ }
8393
+ function summary(r) {
8394
+ if (!hasChanges(r)) return "Déjà à jour.";
8395
+ let parts = [];
8396
+ return r.added && parts.push(`${r.added} élément${r.added > 1 ? "s" : ""} ajouté${r.added > 1 ? "s" : ""}`), r.removed && parts.push(`${r.removed} supprimé${r.removed > 1 ? "s" : ""}`), r.moved && parts.push("ordre mis à jour"), r.copied.length && parts.push(`${r.copied.length} valeur${r.copied.length > 1 ? "s" : ""} recopiée${r.copied.length > 1 ? "s" : ""} (images, liens, options…)`), r.toTranslate.length && parts.push(`${r.toTranslate.length} texte${r.toTranslate.length > 1 ? "s" : ""} à traduire`), parts.join(" · ");
8397
+ }
7965
8398
  /**
7966
8399
  * `pageTypes` déduits du registre du starter, pour ne pas redire au kit ce que
7967
8400
  * le site sait déjà : l'accueil (chemin fixe `/`) et chaque collection avec
@@ -8148,7 +8581,7 @@ function createKitInput(config) {
8148
8581
  function KitInput(props) {
8149
8582
  return isSlugInput(props) ? createElement(SlugUrl, props) : createElement(Override, props);
8150
8583
  }
8151
- return KitInput;
8584
+ return config.i18n ? withTranslationTodo(KitInput, config) : KitInput;
8152
8585
  }
8153
8586
  const ncfKit = definePlugin((options) => {
8154
8587
  let config = resolveConfig(options), issues = validateConfig(config);
@@ -8222,7 +8655,7 @@ const ncfKit = definePlugin((options) => {
8222
8655
  },
8223
8656
  document: {
8224
8657
  newDocumentOptions: (prev) => prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE),
8225
- actions: (prev, context) => config.pageTypeNames.includes(context.schemaType) ? prev.map((action) => action.action === "unpublish" ? RemoveFromSiteAction : action) : prev
8658
+ actions: (prev, context) => config.pageTypeNames.includes(context.schemaType) ? prev.map((action) => action.action === "unpublish" ? RemoveFromSiteAction : action.action === "publish" && config.i18n ? withPropagation(action, config) : action) : prev
8226
8659
  },
8227
8660
  studio: { components: { toolMenu: createPreviewLauncher(config, issues) } },
8228
8661
  form: { components: { input: createKitInput(config) } }