@nocode-factory/sanity-kit 2.37.0 → 2.38.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/dist/fixCrossLanguageReferences-CTQ58gmP.js +519 -0
- package/dist/fixCrossLanguageReferences-CTQ58gmP.js.map +1 -0
- package/dist/fixCrossLanguageReferences-D4phJn84.d.ts +427 -0
- package/dist/index.d.ts +3 -351
- package/dist/index.js +76 -300
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +43 -2
- package/dist/schema.js +2 -2
- package/package.json +1 -1
- package/src/actions/DeleteTranslations.tsx +34 -7
- package/src/actions/TranslationRedirects.tsx +36 -0
- package/src/index.ts +2 -1
- package/src/lib/translateDocument.ts +7 -0
- package/src/lib/translationRedirects.ts +123 -0
- package/src/schema/index.ts +4 -0
- package/src/version.ts +1 -1
- package/dist/componentDefaults-CNiuukLt.d.ts +0 -78
- package/dist/componentDefaults-CelL5Ain.js +0 -149
- package/dist/componentDefaults-CelL5Ain.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { C as DEFAULT_I18N, D as DEFAULT_TITLE_FIELD, E as DEFAULT_SLUG_FIELD, S as DEFAULT_COMPONENT_PREVIEW, T as DEFAULT_PAGE_BUILDER_FIELD, _ as toPath, a as componentDefaultsMainDocuments, b as resolveConfig, c as requiredUnlessDefault, d as translationRedirectId, f as translationRedirectOptions, g as segments, h as parentPath, i as componentDefaultsMainDocument, l as requiredUnlessDefaultFor, m as pageTypeFor, n as withSameLanguageReferences, o as defaultsFieldName, p as depth, r as DEFAULT_COMPONENT_DEFAULTS_TYPE, s as defineComponentDefaults, t as fixCrossLanguageReferences, u as syncTranslationRedirects, v as toUrl, w as DEFAULT_INTERNAL_FIELDS, x as DEFAULT_BOARD_TAGS, y as normalizePath } from "./fixCrossLanguageReferences-CTQ58gmP.js";
|
|
2
2
|
import { createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, usePerspective, useSchema, useSetPerspective, useUser, useWorkspace } from "sanity";
|
|
4
4
|
import { ClockIcon } from "@sanity/icons/Clock";
|
|
@@ -43,130 +43,6 @@ import { useToast } from "@sanity/ui/toast";
|
|
|
43
43
|
import { createPortal } from "react-dom";
|
|
44
44
|
import { TabletDeviceIcon } from "@sanity/icons/TabletDevice";
|
|
45
45
|
import { PanelRightIcon } from "@sanity/icons/PanelRight";
|
|
46
|
-
const trimTrailingSlash = (url) => url.replace(/\/+$/, ""), normalizePath = (path) => {
|
|
47
|
-
let trimmed = path.trim();
|
|
48
|
-
if (!trimmed || trimmed === "/") return "/";
|
|
49
|
-
let withSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
50
|
-
return withSlash.length > 1 ? trimTrailingSlash(withSlash) : withSlash;
|
|
51
|
-
};
|
|
52
|
-
function resolvePageType(entry, defaults) {
|
|
53
|
-
if (typeof entry == "string") return {
|
|
54
|
-
type: entry.trim(),
|
|
55
|
-
slugField: defaults.slugField,
|
|
56
|
-
path: null,
|
|
57
|
-
pathPrefix: null,
|
|
58
|
-
titleField: defaults.titleField
|
|
59
|
-
};
|
|
60
|
-
let path = typeof entry.path == "string" ? normalizePath(entry.path) : null, slugField = entry.slugField === null ? null : entry.slugField?.trim() || defaults.slugField, prefix = typeof entry.pathPrefix == "string" ? normalizePath(entry.pathPrefix) : "/";
|
|
61
|
-
return {
|
|
62
|
-
type: (entry.type ?? "").trim(),
|
|
63
|
-
slugField: path ? null : slugField,
|
|
64
|
-
path,
|
|
65
|
-
pathPrefix: prefix === "/" ? null : prefix,
|
|
66
|
-
titleField: entry.titleField?.trim() || defaults.titleField
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/** Applique les valeurs par défaut. Ne valide rien : voir `validateConfig`. */
|
|
70
|
-
function resolveConfig(input) {
|
|
71
|
-
let slugField = input.slugField?.trim() || "slug", titleField = input.titleField?.trim() || "title", pageTypes = (Array.isArray(input.pageTypes) ? input.pageTypes : []).map((entry) => resolvePageType(entry, {
|
|
72
|
-
slugField,
|
|
73
|
-
titleField
|
|
74
|
-
})), i18n = input.i18n === !1 || input.i18n === void 0 ? null : {
|
|
75
|
-
field: input.i18n.field?.trim() || DEFAULT_I18N.field,
|
|
76
|
-
defaultLocale: input.i18n.defaultLocale?.trim() || DEFAULT_I18N.defaultLocale,
|
|
77
|
-
locales: input.i18n.locales ?? DEFAULT_I18N.locales,
|
|
78
|
-
defaultsSourceLocale: input.i18n.defaultsSourceLocale?.trim() || ((input.i18n.locales ?? DEFAULT_I18N.locales).includes("en") ? "en" : input.i18n.defaultLocale?.trim() || DEFAULT_I18N.defaultLocale)
|
|
79
|
-
};
|
|
80
|
-
return {
|
|
81
|
-
pageTypes,
|
|
82
|
-
pageTypeNames: pageTypes.map((p) => p.type).filter(Boolean),
|
|
83
|
-
pageBuilderField: input.pageBuilderField?.trim() || "sections",
|
|
84
|
-
blockNamespace: input.blockNamespace ?? "",
|
|
85
|
-
noindexFields: input.noindexField ? [input.noindexField].flat().map((field) => field.trim()).filter(Boolean) : DEFAULT_NOINDEX_FIELDS,
|
|
86
|
-
previewUrl: input.previewUrl ? trimTrailingSlash(input.previewUrl.trim()) : null,
|
|
87
|
-
environments: resolveEnvironments(input),
|
|
88
|
-
pageThumbnail: input.pageThumbnail?.trim() || null,
|
|
89
|
-
i18n,
|
|
90
|
-
componentPreview: {
|
|
91
|
-
provider: input.componentPreview?.provider ?? DEFAULT_COMPONENT_PREVIEW.provider,
|
|
92
|
-
path: input.componentPreview?.path ?? DEFAULT_COMPONENT_PREVIEW.path,
|
|
93
|
-
anchor: input.componentPreview?.anchor ?? DEFAULT_COMPONENT_PREVIEW.anchor,
|
|
94
|
-
thumbnail: input.componentPreview?.thumbnail ?? DEFAULT_COMPONENT_PREVIEW.thumbnail,
|
|
95
|
-
defaultsType: input.componentPreview?.defaultsType ?? DEFAULT_COMPONENT_PREVIEW.defaultsType,
|
|
96
|
-
live: input.componentPreview?.live ?? DEFAULT_COMPONENT_PREVIEW.live
|
|
97
|
-
},
|
|
98
|
-
serviceEndpoint: input.serviceEndpoint === !1 ? null : trimTrailingSlash((input.serviceEndpoint || "https://dkoxgivytgsmvqmjvmjt.supabase.co/functions/v1").trim()),
|
|
99
|
-
history: input.history?.projectKey?.trim() ? {
|
|
100
|
-
projectKey: input.history.projectKey.trim(),
|
|
101
|
-
endpoint: trimTrailingSlash((input.history.endpoint || input.serviceEndpoint || "https://dkoxgivytgsmvqmjvmjt.supabase.co/functions/v1").trim())
|
|
102
|
-
} : null,
|
|
103
|
-
tools: {
|
|
104
|
-
...DEFAULT_TOOLS,
|
|
105
|
-
...input.tools
|
|
106
|
-
},
|
|
107
|
-
moreTools: input.moreTools === !1 ? [] : input.moreTools ?? DEFAULT_TOOLBAR_MORE,
|
|
108
|
-
boardTags: input.boardTags?.length ? input.boardTags : DEFAULT_BOARD_TAGS,
|
|
109
|
-
internalFields: input.internalFields?.length ? input.internalFields : DEFAULT_INTERNAL_FIELDS,
|
|
110
|
-
documentColumns: (input.documentColumns ?? []).map((column) => ({
|
|
111
|
-
key: column.key.trim(),
|
|
112
|
-
label: column.label?.trim() || column.key.trim(),
|
|
113
|
-
paths: [column.path].flat().map((path) => path.trim()).filter(Boolean),
|
|
114
|
-
type: column.type ?? "text"
|
|
115
|
-
}))
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Préproduction déduite de la production, par convention.
|
|
120
|
-
*
|
|
121
|
-
* NoCode Factory assigne à chaque projet un domaine Vercel **fixe** pour la
|
|
122
|
-
* branche `preprod`, de la forme `preview-<projet>.vercel.app`. Fixe parce
|
|
123
|
-
* qu'un lien de partage doit survivre au commit suivant : une URL de
|
|
124
|
-
* déploiement change à chaque poussée, un domaine assigné non.
|
|
125
|
-
*
|
|
126
|
-
* La déduire évite de la déclarer neuf fois. Elle n'est proposée que pour un
|
|
127
|
-
* hôte Vercel — ailleurs la convention ne s'applique pas — et `environments`
|
|
128
|
-
* la remplace dès qu'on la déclare explicitement.
|
|
129
|
-
*/
|
|
130
|
-
function conventionalPreprodUrl(previewUrl) {
|
|
131
|
-
if (!previewUrl) return null;
|
|
132
|
-
try {
|
|
133
|
-
let url = new URL(previewUrl);
|
|
134
|
-
return !url.hostname.endsWith(".vercel.app") || url.hostname.startsWith("preview-") ? null : `${url.protocol}//preview-${url.hostname}`;
|
|
135
|
-
} catch {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Environnements d'aperçu.
|
|
141
|
-
*
|
|
142
|
-
* `previewUrl` en fournit toujours un, nommé « Production » : un projet qui
|
|
143
|
-
* n'en déclare pas d'autres doit quand même pouvoir basculer entre brouillons
|
|
144
|
-
* et contenu en ligne.
|
|
145
|
-
*
|
|
146
|
-
* Quand `environments` mentionne déjà `previewUrl`, on ne le double pas.
|
|
147
|
-
*/
|
|
148
|
-
function resolveEnvironments(input) {
|
|
149
|
-
let declared = (input.environments ?? []).map((environment) => ({
|
|
150
|
-
id: environment.id.trim(),
|
|
151
|
-
label: environment.label?.trim() || environment.id.trim(),
|
|
152
|
-
url: trimTrailingSlash((environment.url ?? "").trim())
|
|
153
|
-
})).filter((environment) => environment.id && environment.url), preview = input.previewUrl ? trimTrailingSlash(input.previewUrl.trim()) : null;
|
|
154
|
-
if (!preview) return declared;
|
|
155
|
-
let production = declared.some((environment) => environment.url === preview) ? [] : [{
|
|
156
|
-
id: "production",
|
|
157
|
-
label: "Production",
|
|
158
|
-
url: preview
|
|
159
|
-
}], conventional = conventionalPreprodUrl(preview), hasPreprod = declared.some((environment) => environment.url === conventional || environment.id === "preprod") || input.preprodUrl === !1, preprod = conventional && !hasPreprod ? [{
|
|
160
|
-
id: "preprod",
|
|
161
|
-
label: "Staging",
|
|
162
|
-
url: conventional
|
|
163
|
-
}] : [];
|
|
164
|
-
return [
|
|
165
|
-
...production,
|
|
166
|
-
...preprod,
|
|
167
|
-
...declared
|
|
168
|
-
];
|
|
169
|
-
}
|
|
170
46
|
const isAbsoluteHttpUrl = (value) => {
|
|
171
47
|
try {
|
|
172
48
|
let url = new URL(value);
|
|
@@ -1384,7 +1260,7 @@ function explainGrantError(error) {
|
|
|
1384
1260
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1385
1261
|
* le vérifie.
|
|
1386
1262
|
*/
|
|
1387
|
-
const KIT_VERSION = "2.
|
|
1263
|
+
const KIT_VERSION = "2.38.0";
|
|
1388
1264
|
/**
|
|
1389
1265
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1390
1266
|
*
|
|
@@ -1727,7 +1603,7 @@ function useKitUpdate() {
|
|
|
1727
1603
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1728
1604
|
}).catch(() => {}), () => controller.abort();
|
|
1729
1605
|
}, []);
|
|
1730
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1606
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.38.0") > 0);
|
|
1731
1607
|
return {
|
|
1732
1608
|
current: KIT_VERSION,
|
|
1733
1609
|
latest,
|
|
@@ -2173,39 +2049,6 @@ function buildContentsQuery(config, limit) {
|
|
|
2173
2049
|
].join("\n");
|
|
2174
2050
|
}
|
|
2175
2051
|
/**
|
|
2176
|
-
* Chemin d'une page sur le site. Le chemin fixe l'emporte sur le slug, le
|
|
2177
|
-
* préfixe du type se place devant le slug ('/blog' + 'mon-article'), et la
|
|
2178
|
-
* langue par défaut n'est pas préfixée (convention Next.js du starter).
|
|
2179
|
-
*/
|
|
2180
|
-
function toPath(input, i18n) {
|
|
2181
|
-
let prefix = typeof input.pathPrefix == "string" && input.pathPrefix ? normalizePath(input.pathPrefix) : "/", base = typeof input.path == "string" && input.path ? normalizePath(input.path) : input.slug ? normalizePath(prefix === "/" ? input.slug : `${prefix}/${input.slug.replace(/^\/+/, "")}`) : null;
|
|
2182
|
-
return base === null ? null : !i18n || !input.locale || input.locale === i18n.defaultLocale ? base : base === "/" ? `/${input.locale}` : `/${input.locale}${base}`;
|
|
2183
|
-
}
|
|
2184
|
-
/** URL absolue d'une page, ou `null` si le front n'est pas configuré. */
|
|
2185
|
-
function toUrl(previewUrl, path) {
|
|
2186
|
-
return !previewUrl || path === null ? null : path === "/" ? previewUrl : `${previewUrl}${path}`;
|
|
2187
|
-
}
|
|
2188
|
-
/** Segments d'un chemin : '/services/plomberie' -> ['services', 'plomberie']. */
|
|
2189
|
-
function segments(path) {
|
|
2190
|
-
return path.split("/").filter(Boolean);
|
|
2191
|
-
}
|
|
2192
|
-
/** Profondeur dans l'arborescence. '/' vaut 0. */
|
|
2193
|
-
function depth(path) {
|
|
2194
|
-
return segments(path).length;
|
|
2195
|
-
}
|
|
2196
|
-
/**
|
|
2197
|
-
* Chemin du parent, ou `null` à la racine. Sert au placement automatique du
|
|
2198
|
-
* board : '/services/plomberie' -> '/services'.
|
|
2199
|
-
*/
|
|
2200
|
-
function parentPath(path) {
|
|
2201
|
-
let parts = segments(path);
|
|
2202
|
-
return parts.length === 0 ? null : parts.length === 1 ? "/" : `/${parts.slice(0, -1).join("/")}`;
|
|
2203
|
-
}
|
|
2204
|
-
/** Le type de page correspondant à un document. */
|
|
2205
|
-
function pageTypeFor(type, pageTypes) {
|
|
2206
|
-
return pageTypes.find((p) => p.type === type);
|
|
2207
|
-
}
|
|
2208
|
-
/**
|
|
2209
2052
|
* Met une valeur du document en forme pour une cellule.
|
|
2210
2053
|
*
|
|
2211
2054
|
* Ce qui ne tient pas sur une ligne — un objet, un tableau de sections — n'est
|
|
@@ -2960,22 +2803,22 @@ async function localizeReferences(client, value, language) {
|
|
|
2960
2803
|
for (let row of rows ?? []) row?.from && row.to && row.to !== row.from && map.set(row.from, row.to);
|
|
2961
2804
|
return map.size ? replaceRefs(value, map) : value;
|
|
2962
2805
|
}
|
|
2963
|
-
const isObj$
|
|
2806
|
+
const isObj$1 = (v) => typeof v == "object" && !!v && !Array.isArray(v);
|
|
2964
2807
|
/** Textes d'une valeur, dans l'ordre. */
|
|
2965
2808
|
function collectTexts$1(value) {
|
|
2966
2809
|
if (typeof value == "string") return [value];
|
|
2967
2810
|
if (!Array.isArray(value)) return [];
|
|
2968
2811
|
let out = [];
|
|
2969
2812
|
for (let item of value) if (typeof item == "string") out.push(item);
|
|
2970
|
-
else if (isObj$
|
|
2813
|
+
else if (isObj$1(item) && Array.isArray(item.children)) for (let child of item.children) isObj$1(child) && typeof child.text == "string" && out.push(child.text);
|
|
2971
2814
|
return out;
|
|
2972
2815
|
}
|
|
2973
2816
|
/** La même valeur avec ses textes remplacés (dans l'ordre de `collectTexts`). */
|
|
2974
2817
|
function replaceTexts(value, texts) {
|
|
2975
2818
|
let i = 0, next = () => texts[i++] ?? "";
|
|
2976
|
-
return typeof value == "string" ? next() : Array.isArray(value) ? value.map((item) => typeof item == "string" ? next() : isObj$
|
|
2819
|
+
return typeof value == "string" ? next() : Array.isArray(value) ? value.map((item) => typeof item == "string" ? next() : isObj$1(item) && Array.isArray(item.children) ? {
|
|
2977
2820
|
...item,
|
|
2978
|
-
children: item.children.map((child) => isObj$
|
|
2821
|
+
children: item.children.map((child) => isObj$1(child) && typeof child.text == "string" ? {
|
|
2979
2822
|
...child,
|
|
2980
2823
|
text: next()
|
|
2981
2824
|
} : child)
|
|
@@ -2988,14 +2831,14 @@ function parsePathKey(path) {
|
|
|
2988
2831
|
return out;
|
|
2989
2832
|
}
|
|
2990
2833
|
function itemOf(list, key) {
|
|
2991
|
-
return list.find((i) => isObj$
|
|
2834
|
+
return list.find((i) => isObj$1(i) && i._key === key) ?? (/^\d+$/.test(key) ? list[Number(key)] : void 0);
|
|
2992
2835
|
}
|
|
2993
2836
|
/** Valeur d'un document au chemin `sections[a].title`. */
|
|
2994
2837
|
function valueAtKey(doc, path) {
|
|
2995
2838
|
let cur = doc;
|
|
2996
2839
|
for (let seg of parsePathKey(path)) {
|
|
2997
2840
|
if (cur == null) return;
|
|
2998
|
-
cur = "field" in seg ? isObj$
|
|
2841
|
+
cur = "field" in seg ? isObj$1(cur) ? cur[seg.field] : void 0 : Array.isArray(cur) ? itemOf(cur, seg.item) : void 0;
|
|
2999
2842
|
}
|
|
3000
2843
|
return cur;
|
|
3001
2844
|
}
|
|
@@ -3004,10 +2847,10 @@ function setAtKey(doc, path, value) {
|
|
|
3004
2847
|
let segs = parsePathKey(path), cur = doc;
|
|
3005
2848
|
for (let n = 0; n < segs.length - 1; n++) {
|
|
3006
2849
|
let seg = segs[n];
|
|
3007
|
-
if (cur = "field" in seg ? isObj$
|
|
2850
|
+
if (cur = "field" in seg ? isObj$1(cur) ? cur[seg.field] : void 0 : Array.isArray(cur) ? itemOf(cur, seg.item) : void 0, cur == null) return !1;
|
|
3008
2851
|
}
|
|
3009
2852
|
let last = segs[segs.length - 1];
|
|
3010
|
-
return !last || !("field" in last) || !isObj$
|
|
2853
|
+
return !last || !("field" in last) || !isObj$1(cur) ? !1 : (cur[last.field] = value, !0);
|
|
3011
2854
|
}
|
|
3012
2855
|
const MESSAGES = {
|
|
3013
2856
|
daily_limit: "Daily AI translation limit reached for this project.",
|
|
@@ -3059,7 +2902,7 @@ const VALUE_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
|
3059
2902
|
"datetime",
|
|
3060
2903
|
"number",
|
|
3061
2904
|
"boolean"
|
|
3062
|
-
]), SKIP_KEYS = /* @__PURE__ */ new Set(["language", "slug"]), isObj
|
|
2905
|
+
]), SKIP_KEYS = /* @__PURE__ */ new Set(["language", "slug"]), isObj = (v) => typeof v == "object" && !!v && !Array.isArray(v), same$2 = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null), keyed$1 = (v) => Array.isArray(v) && v.length > 0 && v.every((i) => isObj(i) && typeof i._key == "string");
|
|
3063
2906
|
function typeNames(t) {
|
|
3064
2907
|
let out = [];
|
|
3065
2908
|
for (let c = t; c; c = c.type) c.name && out.push(c.name);
|
|
@@ -3078,7 +2921,7 @@ function kindOf(t, value) {
|
|
|
3078
2921
|
}
|
|
3079
2922
|
return t.jsonType === "object" ? "object" : t.jsonType === "string" ? t.options?.list?.length ? "value" : "text" : "value";
|
|
3080
2923
|
}
|
|
3081
|
-
return keyed$1(value) ? "list" : isObj
|
|
2924
|
+
return keyed$1(value) ? "list" : isObj(value) ? "object" : "value";
|
|
3082
2925
|
}
|
|
3083
2926
|
function fieldType(t, name) {
|
|
3084
2927
|
for (let c = t; c; c = c.type) {
|
|
@@ -3095,8 +2938,8 @@ function itemType(t, item) {
|
|
|
3095
2938
|
function collectTexts(value, t, path, acc) {
|
|
3096
2939
|
let kind = kindOf(t, value);
|
|
3097
2940
|
if (kind === "text") value != null && value !== "" && acc.toTranslate.push(path);
|
|
3098
|
-
else if (kind === "object" && isObj
|
|
3099
|
-
else if (kind === "list" && Array.isArray(value)) for (let item of value) isObj
|
|
2941
|
+
else if (kind === "object" && isObj(value)) for (let [k, v] of Object.entries(value)) k.startsWith("_") || collectTexts(v, fieldType(t, k), `${path}.${k}`, acc);
|
|
2942
|
+
else if (kind === "list" && Array.isArray(value)) for (let item of value) isObj(item) && collectTexts(item, itemType(t, item), `${path}[${String(item._key)}]`, acc);
|
|
3100
2943
|
}
|
|
3101
2944
|
const ABSENT$1 = Symbol("absent");
|
|
3102
2945
|
function merge(target, before, after, t, path, acc) {
|
|
@@ -3105,8 +2948,8 @@ function merge(target, before, after, t, path, acc) {
|
|
|
3105
2948
|
if (kind === "text") return after == null || after === "" ? (target != null && target !== "" && acc.toTranslate.push(path), target === void 0 ? ABSENT$1 : target) : (acc.toTranslate.push(path), target == null || target === "" || same$2(target, before) ? after : target);
|
|
3106
2949
|
if (kind === "value") return acc.copied.push(path), after === void 0 ? ABSENT$1 : after;
|
|
3107
2950
|
if (kind === "object") {
|
|
3108
|
-
if (!isObj
|
|
3109
|
-
let base = isObj
|
|
2951
|
+
if (!isObj(after)) return acc.copied.push(path), after === void 0 ? ABSENT$1 : after;
|
|
2952
|
+
let base = isObj(target) ? { ...target } : { _type: after._type }, b = isObj(before) ? before : {};
|
|
3110
2953
|
for (let k of /* @__PURE__ */ new Set([...Object.keys(b), ...Object.keys(after)])) {
|
|
3111
2954
|
if (k.startsWith("_") || SKIP_KEYS.has(k)) continue;
|
|
3112
2955
|
let v = merge(base[k], b[k], after[k], fieldType(t, k), path ? `${path}.${k}` : k, acc);
|
|
@@ -3114,7 +2957,7 @@ function merge(target, before, after, t, path, acc) {
|
|
|
3114
2957
|
}
|
|
3115
2958
|
return base;
|
|
3116
2959
|
}
|
|
3117
|
-
let tgt = Array.isArray(target) ? target.filter(isObj
|
|
2960
|
+
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 = [];
|
|
3118
2961
|
for (let item of aft) {
|
|
3119
2962
|
let key = item._key, it = itemType(t, item);
|
|
3120
2963
|
if (tMap.has(key)) {
|
|
@@ -3148,7 +2991,7 @@ function propagate(target, before, after, documentType) {
|
|
|
3148
2991
|
return {
|
|
3149
2992
|
document: {
|
|
3150
2993
|
...target ?? {},
|
|
3151
|
-
...isObj
|
|
2994
|
+
...isObj(merged) ? merged : {}
|
|
3152
2995
|
},
|
|
3153
2996
|
...acc
|
|
3154
2997
|
};
|
|
@@ -3283,8 +3126,9 @@ async function createTranslatedVersion(opts) {
|
|
|
3283
3126
|
current: slug
|
|
3284
3127
|
};
|
|
3285
3128
|
}
|
|
3129
|
+
slugField && remaining.includes(pageType?.titleField ?? "title") && !remaining.includes(slugField) && (remaining = [...remaining, slugField]);
|
|
3286
3130
|
let published = ai && !remaining.length && !aiError;
|
|
3287
|
-
|
|
3131
|
+
await client.createOrReplace({
|
|
3288
3132
|
...doc,
|
|
3289
3133
|
_id: published ? id : `drafts.${id}`,
|
|
3290
3134
|
_type: type
|
|
@@ -3301,7 +3145,9 @@ async function createTranslatedVersion(opts) {
|
|
|
3301
3145
|
}), await linkTranslations(client, sourceId, sourceLanguage, type, [{
|
|
3302
3146
|
language,
|
|
3303
3147
|
id
|
|
3304
|
-
}])
|
|
3148
|
+
}]);
|
|
3149
|
+
let redirects = published ? translationRedirectOptions(config) : null;
|
|
3150
|
+
return redirects && await syncTranslationRedirects(client, redirects, [sourceId]).catch(() => {}), {
|
|
3305
3151
|
id,
|
|
3306
3152
|
published,
|
|
3307
3153
|
aiError
|
|
@@ -9396,7 +9242,7 @@ const withDrafts = (ids) => ids.flatMap((id) => [id, `drafts.${id}`]);
|
|
|
9396
9242
|
* suppression native, inchangée.
|
|
9397
9243
|
*/
|
|
9398
9244
|
function withTranslationDelete(Delete, config, masterLocale) {
|
|
9399
|
-
let i18n = config.i18n, master = masterLocale ?? i18n?.defaultLocale, Wrapped = (props) => {
|
|
9245
|
+
let i18n = config.i18n, master = masterLocale ?? i18n?.defaultLocale, redirects = translationRedirectOptions(config), Wrapped = (props) => {
|
|
9400
9246
|
let base = Delete(props), client = useKitClient(), [versions, setVersions] = useState(null), current = props.draft ?? props.published;
|
|
9401
9247
|
useEffect(() => {
|
|
9402
9248
|
if (!i18n || current?.[i18n.field] !== master) return;
|
|
@@ -9412,8 +9258,8 @@ function withTranslationDelete(Delete, config, masterLocale) {
|
|
|
9412
9258
|
props.id,
|
|
9413
9259
|
current?.[i18n?.field ?? "language"]
|
|
9414
9260
|
]);
|
|
9415
|
-
let [open, setOpen] = useState(!1);
|
|
9416
|
-
return !base || !i18n ||
|
|
9261
|
+
let [open, setOpen] = useState(!1), isMaster = !!i18n && current?.[i18n.field] === master, hasPage = !!redirects?.types.some((t) => t.type === props.type);
|
|
9262
|
+
return !base || !i18n || (isMaster ? versions === null || !versions.length && !hasPage : !hasPage) ? base : {
|
|
9417
9263
|
...base,
|
|
9418
9264
|
onHandle: () => setOpen(!0),
|
|
9419
9265
|
dialog: open ? {
|
|
@@ -9424,7 +9270,8 @@ function withTranslationDelete(Delete, config, masterLocale) {
|
|
|
9424
9270
|
content: /* @__PURE__ */ jsx(DeleteDialog, {
|
|
9425
9271
|
id: props.id,
|
|
9426
9272
|
language: String(current?.[i18n.field] ?? ""),
|
|
9427
|
-
versions,
|
|
9273
|
+
versions: isMaster ? versions ?? [] : [],
|
|
9274
|
+
redirects: hasPage ? redirects : null,
|
|
9428
9275
|
onDone: () => {
|
|
9429
9276
|
setOpen(!1), props.onComplete();
|
|
9430
9277
|
}
|
|
@@ -9435,7 +9282,7 @@ function withTranslationDelete(Delete, config, masterLocale) {
|
|
|
9435
9282
|
return Wrapped;
|
|
9436
9283
|
}
|
|
9437
9284
|
function DeleteDialog(props) {
|
|
9438
|
-
let { id, language, onDone } = props, client = useKitClient(), toast = useToast(), [versions, setVersions] = useState(props.versions), [referrers, setReferrers] = useState(null), [busy, setBusy] = useState(!1), [error, setError] = useState(null), ids = [id, ...versions.filter((v) => v.selected).map((v) => v.id)], key = ids.join(",");
|
|
9285
|
+
let { id, language, onDone, redirects } = props, client = useKitClient(), toast = useToast(), [versions, setVersions] = useState(props.versions), [referrers, setReferrers] = useState(null), [busy, setBusy] = useState(!1), [error, setError] = useState(null), ids = [id, ...versions.filter((v) => v.selected).map((v) => v.id)], key = ids.join(",");
|
|
9439
9286
|
useEffect(() => {
|
|
9440
9287
|
setReferrers(null);
|
|
9441
9288
|
let all = withDrafts(ids);
|
|
@@ -9454,6 +9301,22 @@ function DeleteDialog(props) {
|
|
|
9454
9301
|
let gone = (meta.translations ?? []).filter((t) => ids.includes(t.value?._ref ?? ""));
|
|
9455
9302
|
(meta.translations ?? []).length - gone.length > 1 ? tx.patch(meta._id, (p) => p.unset(gone.map((t) => `translations[_key == "${t._key}"]`))) : tx.delete(meta._id);
|
|
9456
9303
|
}
|
|
9304
|
+
if (redirects) {
|
|
9305
|
+
let field = redirects.field ?? "language", gone = await client.fetch(`*[_id in $ids]{_type, "slug": slug.current, "language": ${field}}`, { ids }), i18nPaths = {
|
|
9306
|
+
field,
|
|
9307
|
+
defaultLocale: redirects.defaultLocale,
|
|
9308
|
+
locales: [],
|
|
9309
|
+
defaultsSourceLocale: redirects.defaultLocale
|
|
9310
|
+
}, paths = gone.map((d) => toPath({
|
|
9311
|
+
slug: d.slug,
|
|
9312
|
+
pathPrefix: redirects.types.find((t) => t.type === d._type)?.pathPrefix,
|
|
9313
|
+
locale: d.language
|
|
9314
|
+
}, i18nPaths)).filter((x) => !!x), redirectType = redirects.redirectType ?? "redirect", leading = paths.length ? await client.fetch("*[_type == $redirectType && to in $paths]._id", {
|
|
9315
|
+
redirectType,
|
|
9316
|
+
paths
|
|
9317
|
+
}) : [];
|
|
9318
|
+
for (let rid of /* @__PURE__ */ new Set([...leading, ...ids.map(translationRedirectId)])) tx.delete(rid);
|
|
9319
|
+
}
|
|
9457
9320
|
await tx.commit({ visibility: "async" }), toast.push({
|
|
9458
9321
|
status: "success",
|
|
9459
9322
|
title: `Deleted: ${[language, ...versions.filter((v) => v.selected).map((v) => v.language)].map((l) => l.toUpperCase()).join(", ")}`,
|
|
@@ -9472,10 +9335,12 @@ function DeleteDialog(props) {
|
|
|
9472
9335
|
children: [
|
|
9473
9336
|
"The ",
|
|
9474
9337
|
language.toUpperCase(),
|
|
9475
|
-
" version will be deleted for good (published and draft).
|
|
9338
|
+
" version will be deleted for good (published and draft).",
|
|
9339
|
+
versions.length ? " Delete the other language versions too?" : "",
|
|
9340
|
+
redirects ? " Redirects leading to it are removed." : ""
|
|
9476
9341
|
]
|
|
9477
9342
|
}),
|
|
9478
|
-
/* @__PURE__ */ jsx(Stack, {
|
|
9343
|
+
versions.length > 0 && /* @__PURE__ */ jsx(Stack, {
|
|
9479
9344
|
gap: 2,
|
|
9480
9345
|
children: versions.map((v, index) => /* @__PURE__ */ jsx(Card, {
|
|
9481
9346
|
padding: 3,
|
|
@@ -9564,6 +9429,31 @@ function DeleteDialog(props) {
|
|
|
9564
9429
|
});
|
|
9565
9430
|
}
|
|
9566
9431
|
/**
|
|
9432
|
+
* Publier une version d'une page ou d'une fiche traduite : les redirections
|
|
9433
|
+
* « slug d'origine dans cette langue → slug traduit » de son groupe de traductions
|
|
9434
|
+
* sont mises à jour (créées, corrigées si un slug change, retirées si inutiles).
|
|
9435
|
+
* Jamais bloquant : un échec est seulement signalé dans la console.
|
|
9436
|
+
*/
|
|
9437
|
+
function withTranslationRedirects(Publish, config) {
|
|
9438
|
+
let options = translationRedirectOptions(config);
|
|
9439
|
+
if (!options) return Publish;
|
|
9440
|
+
let Wrapped = (props) => {
|
|
9441
|
+
let base = Publish(props), client = useKitClient();
|
|
9442
|
+
return base && {
|
|
9443
|
+
...base,
|
|
9444
|
+
onHandle: () => {
|
|
9445
|
+
let draft = props.draft, slugField = options.types.find((t) => t.type === props.type)?.slugField ?? "slug", slug = draft?.[slugField]?.current, language = draft?.[options.field ?? "language"];
|
|
9446
|
+
base.onHandle?.(), syncTranslationRedirects(client, options, [props.id], {
|
|
9447
|
+
id: props.id,
|
|
9448
|
+
slug,
|
|
9449
|
+
language
|
|
9450
|
+
}).catch((cause) => console.error("Redirections de traduction non mises à jour :", cause));
|
|
9451
|
+
}
|
|
9452
|
+
};
|
|
9453
|
+
};
|
|
9454
|
+
return Wrapped;
|
|
9455
|
+
}
|
|
9456
|
+
/**
|
|
9567
9457
|
* `pageTypes` déduits du registre du starter, pour ne pas redire au kit ce que
|
|
9568
9458
|
* le site sait déjà : l'accueil (chemin fixe `/`) et chaque collection avec
|
|
9569
9459
|
* son préfixe d'URL (`/blog`, `/produits`, ou la racine).
|
|
@@ -9658,120 +9548,6 @@ function withMoreTool(tools, names = DEFAULT_MORE_TOOLS) {
|
|
|
9658
9548
|
};
|
|
9659
9549
|
return [...tools.filter((tool) => !names.includes(tool.name)), more];
|
|
9660
9550
|
}
|
|
9661
|
-
const isObj$1 = (v) => {
|
|
9662
|
-
if (!v || typeof v != "object" || Array.isArray(v) || "$$typeof" in v) return !1;
|
|
9663
|
-
let proto = Object.getPrototypeOf(v);
|
|
9664
|
-
return proto === Object.prototype || proto === null;
|
|
9665
|
-
};
|
|
9666
|
-
/**
|
|
9667
|
-
* RÈGLE D'OR DU MULTILINGUE : une référence ne propose que des documents de la
|
|
9668
|
-
* MÊME langue que le document en cours (un article EN ne voit que les catégories EN,
|
|
9669
|
-
* une page FR que les pages FR). Les documents sans langue (logos, régions, assets…)
|
|
9670
|
-
* restent proposés. Un document commun à toutes les langues (Navigation…) vise la
|
|
9671
|
-
* langue principale.
|
|
9672
|
-
*
|
|
9673
|
-
* Pose ce filtre sur TOUS les champs de référence des types donnés (champs, listes,
|
|
9674
|
-
* objets imbriqués, annotations du texte riche), combiné avec un filtre déjà présent.
|
|
9675
|
-
* À appliquer aux types du projet :
|
|
9676
|
-
*
|
|
9677
|
-
* ```ts
|
|
9678
|
-
* schema: {types: withSameLanguageReferences(schemaTypes, ncfOptions)}
|
|
9679
|
-
* ```
|
|
9680
|
-
*/
|
|
9681
|
-
function withSameLanguageReferences(types, options) {
|
|
9682
|
-
let i18n = options.i18n;
|
|
9683
|
-
if (!i18n) return types;
|
|
9684
|
-
let field = i18n.field ?? "language", fallback = i18n.defaultLocale ?? i18n.locales?.[0], condition = `(!defined(${field}) || ${field} == $ncfLanguage)`, languageOf = (document) => typeof document?.[field] == "string" && document[field] || fallback, wrap = (opts) => {
|
|
9685
|
-
let previous = opts?.filter, previousParams = opts?.filterParams ?? {}, filter = async (context) => {
|
|
9686
|
-
let base = typeof previous == "function" ? await previous(context) ?? {} : typeof previous == "string" ? {
|
|
9687
|
-
filter: previous,
|
|
9688
|
-
params: previousParams
|
|
9689
|
-
} : {};
|
|
9690
|
-
return {
|
|
9691
|
-
filter: base.filter ? `(${base.filter}) && ${condition}` : condition,
|
|
9692
|
-
params: {
|
|
9693
|
-
...base.params ?? {},
|
|
9694
|
-
ncfLanguage: languageOf(context.document)
|
|
9695
|
-
}
|
|
9696
|
-
};
|
|
9697
|
-
}, { filterParams: _ignored, ...rest } = opts ?? {};
|
|
9698
|
-
return {
|
|
9699
|
-
...rest,
|
|
9700
|
-
filter
|
|
9701
|
-
};
|
|
9702
|
-
}, visit = (node) => {
|
|
9703
|
-
if (Array.isArray(node)) return node.map(visit);
|
|
9704
|
-
if (!isObj$1(node)) return node;
|
|
9705
|
-
let out = {};
|
|
9706
|
-
for (let [key, value] of Object.entries(node)) out[key] = key === "options" || key === "initialValue" || key === "validation" ? value : visit(value);
|
|
9707
|
-
return node.type === "reference" && Array.isArray(node.to) && (out.options = wrap(node.options)), out;
|
|
9708
|
-
};
|
|
9709
|
-
return types.map((t) => visit(t));
|
|
9710
|
-
}
|
|
9711
|
-
const isObj = (v) => !!v && typeof v == "object" && !Array.isArray(v), bare = (id) => id.replace(/^drafts\./, "");
|
|
9712
|
-
/** Références d'une valeur, avec leur chemin de patch (`a.b[_key=="x"].c`). */
|
|
9713
|
-
function refs(value, path, out) {
|
|
9714
|
-
if (Array.isArray(value)) {
|
|
9715
|
-
value.forEach((item, i) => refs(item, `${path}[${isObj(item) && typeof item._key == "string" ? `_key=="${item._key}"` : i}]`, out));
|
|
9716
|
-
return;
|
|
9717
|
-
}
|
|
9718
|
-
if (isObj(value)) {
|
|
9719
|
-
typeof value._ref == "string" && !/^(image|file)-/.test(value._ref) && out.push({
|
|
9720
|
-
path: `${path}._ref`,
|
|
9721
|
-
ref: value._ref
|
|
9722
|
-
});
|
|
9723
|
-
for (let [k, v] of Object.entries(value)) k.startsWith("_") || refs(v, path ? `${path}.${k}` : k, out);
|
|
9724
|
-
}
|
|
9725
|
-
}
|
|
9726
|
-
/**
|
|
9727
|
-
* RÈGLE D'OR DU MULTILINGUE, côté données : chaque référence d'un document vise un
|
|
9728
|
-
* document de SA langue (document sans langue : la langue principale). Une
|
|
9729
|
-
* référence croisée est repointée vers la traduction de la bonne langue (liens de
|
|
9730
|
-
* traduction) ; sans traduction, elle est signalée et laissée. Publiés et
|
|
9731
|
-
* brouillons. `apply: false` : simulation.
|
|
9732
|
-
*
|
|
9733
|
-
* ```ts
|
|
9734
|
-
* // studio/scripts/references-same-language.ts (sanity exec --with-user-token)
|
|
9735
|
-
* const report = await fixCrossLanguageReferences(getCliClient(...), {defaultLocale: 'fr', apply})
|
|
9736
|
-
* ```
|
|
9737
|
-
*/
|
|
9738
|
-
async function fixCrossLanguageReferences(client, options) {
|
|
9739
|
-
let field = options.field ?? "language", c = client.withConfig({ perspective: "raw" }), docs = await c.fetch("*[!(_type match \"system.*\") && !(_type match \"sanity.*\") && !(_type match \"ncf.*\") && _type != \"translation.metadata\"]"), language = /* @__PURE__ */ new Map();
|
|
9740
|
-
for (let d of docs) typeof d[field] == "string" && language.set(bare(String(d._id)), String(d[field]));
|
|
9741
|
-
let metas = await c.fetch("*[_type == \"translation.metadata\"]{translations}"), equivalent = /* @__PURE__ */ new Map();
|
|
9742
|
-
for (let m of metas) {
|
|
9743
|
-
let group = /* @__PURE__ */ new Map();
|
|
9744
|
-
for (let t of m.translations ?? []) t.value?._ref && group.set(t.language ?? t._key ?? "", t.value._ref);
|
|
9745
|
-
for (let id of group.values()) equivalent.set(id, group);
|
|
9746
|
-
}
|
|
9747
|
-
let report = {
|
|
9748
|
-
fixed: [],
|
|
9749
|
-
missing: []
|
|
9750
|
-
};
|
|
9751
|
-
for (let d of docs) {
|
|
9752
|
-
let own = typeof d[field] == "string" ? String(d[field]) : options.defaultLocale, found = [];
|
|
9753
|
-
for (let [k, v] of Object.entries(d)) k.startsWith("_") || refs(v, k, found);
|
|
9754
|
-
let set = {};
|
|
9755
|
-
for (let { path, ref } of found) {
|
|
9756
|
-
let target = language.get(bare(ref));
|
|
9757
|
-
if (!target || target === own) continue;
|
|
9758
|
-
let to = equivalent.get(bare(ref))?.get(own);
|
|
9759
|
-
to ? (set[path] = to, report.fixed.push({
|
|
9760
|
-
documentId: String(d._id),
|
|
9761
|
-
path,
|
|
9762
|
-
from: ref,
|
|
9763
|
-
to
|
|
9764
|
-
})) : report.missing.push({
|
|
9765
|
-
documentId: String(d._id),
|
|
9766
|
-
path,
|
|
9767
|
-
ref,
|
|
9768
|
-
language: own
|
|
9769
|
-
});
|
|
9770
|
-
}
|
|
9771
|
-
options.apply && Object.keys(set).length && await c.patch(String(d._id)).ifRevisionId(String(d._rev)).set(set).commit({ visibility: "async" });
|
|
9772
|
-
}
|
|
9773
|
-
return report;
|
|
9774
|
-
}
|
|
9775
9551
|
/**
|
|
9776
9552
|
* Bascule brouillons / en ligne, posée dans l'aperçu lui-même.
|
|
9777
9553
|
*
|
|
@@ -10318,7 +10094,7 @@ const ncfKit = definePlugin((options) => {
|
|
|
10318
10094
|
},
|
|
10319
10095
|
document: {
|
|
10320
10096
|
newDocumentOptions: (prev) => prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE),
|
|
10321
|
-
actions: (prev, context) => config.pageTypeNames.includes(context.schemaType) ? prev.map((action) => action.action === "unpublish" ? config.i18n ? createRemoveFromSite(config) : RemoveFromSiteAction : action.action === "publish" && config.i18n ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action.action === "delete" && config.i18n ? withTranslationDelete(action, config) : action) : context.schemaType === config.componentPreview.defaultsType && config.i18n ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, config.i18n?.defaultsSourceLocale) : action.action === "delete" ? withTranslationDelete(action, config, config.i18n?.defaultsSourceLocale) : action) : config.i18n && !isKitType(context.schemaType) && hasLanguageField(context.schema.get(context.schemaType), config.i18n.field) ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action.action === "delete" ? withTranslationDelete(action, config) : action.action === "unpublish" ? createRemoveFromSite(config) : action) : prev
|
|
10097
|
+
actions: (prev, context) => config.pageTypeNames.includes(context.schemaType) ? prev.map((action) => action.action === "unpublish" ? config.i18n ? createRemoveFromSite(config) : RemoveFromSiteAction : action.action === "publish" && config.i18n ? withTranslationRedirects(withPropagation(action, config, void 0, { allowCreate: !0 }), config) : action.action === "delete" && config.i18n ? withTranslationDelete(action, config) : action) : context.schemaType === config.componentPreview.defaultsType && config.i18n ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, config.i18n?.defaultsSourceLocale) : action.action === "delete" ? withTranslationDelete(action, config, config.i18n?.defaultsSourceLocale) : action) : config.i18n && !isKitType(context.schemaType) && hasLanguageField(context.schema.get(context.schemaType), config.i18n.field) ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action.action === "delete" ? withTranslationDelete(action, config) : action.action === "unpublish" ? createRemoveFromSite(config) : action) : prev
|
|
10322
10098
|
},
|
|
10323
10099
|
studio: { components: { toolMenu: createPreviewLauncher(config, issues) } },
|
|
10324
10100
|
form: { components: { input: createKitInput(config) } }
|