@nocode-factory/sanity-kit 2.37.1 → 2.39.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/bin/ncf-kit.mjs +11 -0
- package/dist/fixCrossLanguageReferences-DIdE0jOt.js +521 -0
- package/dist/fixCrossLanguageReferences-DIdE0jOt.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +70 -180
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +42 -1
- 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/config/defaults.ts +4 -2
- package/src/config/resolve.ts +14 -8
- package/src/config/validate.ts +8 -0
- package/src/index.ts +2 -1
- package/src/lib/grouping.ts +1 -1
- package/src/lib/pages.ts +6 -6
- package/src/lib/sectionsMap.ts +1 -1
- package/src/lib/translateDocument.ts +7 -0
- package/src/lib/translationRedirects.ts +123 -0
- package/src/schema/index.ts +1 -0
- package/src/tools/components/ComponentsTool.tsx +1 -1
- package/src/version.ts +1 -1
- package/dist/fixCrossLanguageReferences-CagQ_Vvk.js +0 -263
- package/dist/fixCrossLanguageReferences-CagQ_Vvk.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function hasBlockingIssue(issues: ConfigIssue[], tool: NcfToolNam
|
|
|
18
18
|
export declare const DEFAULT_PAGE_BUILDER_FIELD = "sections";
|
|
19
19
|
export declare const DEFAULT_SLUG_FIELD = "slug";
|
|
20
20
|
export declare const DEFAULT_TITLE_FIELD = "title";
|
|
21
|
-
export declare const DEFAULT_I18N: Omit<Required<NcfI18nConfig>, 'defaultsSourceLocale'>;
|
|
21
|
+
export declare const DEFAULT_I18N: Omit<Required<NcfI18nConfig>, 'defaultsSourceLocale' | 'defaultLocale'>;
|
|
22
22
|
/**
|
|
23
23
|
* Convention NoCode Factory : page `/design-system` dans le front, captures
|
|
24
24
|
* dans `/sections/<nom>.png` générées au push par GitHub Actions.
|
|
@@ -1090,7 +1090,7 @@ export declare function ActorName(props: {
|
|
|
1090
1090
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1091
1091
|
* le vérifie.
|
|
1092
1092
|
*/
|
|
1093
|
-
export declare const KIT_VERSION = "2.
|
|
1093
|
+
export declare const KIT_VERSION = "2.39.0";
|
|
1094
1094
|
/**
|
|
1095
1095
|
* Données de la page proposées comme colonnes.
|
|
1096
1096
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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-DIdE0jOt.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);
|
|
@@ -192,7 +68,7 @@ function validateConfig(config) {
|
|
|
192
68
|
message,
|
|
193
69
|
...tools ? { tools } : {}
|
|
194
70
|
});
|
|
195
|
-
config.pageTypes.length === 0 && error("pageTypes", "`pageTypes` is empty. Declare at least one document type, e.g. pageTypes: ['page'].");
|
|
71
|
+
config.i18n && !config.i18n.defaultLocale && error("i18n.defaultLocale", "Multilingual site without a main language: set `i18n.defaultLocale` (or `i18n.locales`, the first one is the main language). The kit never assumes a language."), config.pageTypes.length === 0 && error("pageTypes", "`pageTypes` is empty. Declare at least one document type, e.g. pageTypes: ['page'].");
|
|
196
72
|
let seen = /* @__PURE__ */ new Set();
|
|
197
73
|
config.pageTypes.forEach((pageType, index) => {
|
|
198
74
|
let at = `pageTypes[${index}]`;
|
|
@@ -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.39.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.39.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
|
|
@@ -2250,12 +2093,12 @@ const STATUS_ORDER = {
|
|
|
2250
2093
|
let index = order.indexOf(row.type);
|
|
2251
2094
|
return index === -1 ? order.length : index;
|
|
2252
2095
|
};
|
|
2253
|
-
return rank(a) - rank(b) || a.title.localeCompare(b.title, "
|
|
2096
|
+
return rank(a) - rank(b) || a.title.localeCompare(b.title, void 0, { sensitivity: "base" });
|
|
2254
2097
|
}
|
|
2255
|
-
case "title": return a.title.localeCompare(b.title, "
|
|
2256
|
-
case "type": return a.type.localeCompare(b.type, "
|
|
2257
|
-
case "path": return a.path === null || b.path === null ? Number(a.path === null) - Number(b.path === null) : a.path.localeCompare(b.path, "
|
|
2258
|
-
case "status": return STATUS_ORDER[a.status] - STATUS_ORDER[b.status] || a.title.localeCompare(b.title, "
|
|
2098
|
+
case "title": return a.title.localeCompare(b.title, void 0, { sensitivity: "base" });
|
|
2099
|
+
case "type": return a.type.localeCompare(b.type, void 0, { sensitivity: "base" }) || a.title.localeCompare(b.title, void 0, { sensitivity: "base" });
|
|
2100
|
+
case "path": return a.path === null || b.path === null ? Number(a.path === null) - Number(b.path === null) : a.path.localeCompare(b.path, void 0, { sensitivity: "base" });
|
|
2101
|
+
case "status": return STATUS_ORDER[a.status] - STATUS_ORDER[b.status] || a.title.localeCompare(b.title, void 0, { sensitivity: "base" });
|
|
2259
2102
|
case "updatedAt": return (a.updatedAt ?? "").localeCompare(b.updatedAt ?? "");
|
|
2260
2103
|
case "blockCount": return a.blockCount - b.blockCount;
|
|
2261
2104
|
}
|
|
@@ -2264,7 +2107,7 @@ function sortRows(rows, key, direction, options = {}) {
|
|
|
2264
2107
|
let sorted = [...rows].sort((a, b) => compare(a, b, key, options));
|
|
2265
2108
|
return direction === "asc" ? sorted : sorted.reverse();
|
|
2266
2109
|
}
|
|
2267
|
-
const normalize = (value) => value.toLocaleLowerCase(
|
|
2110
|
+
const normalize = (value) => value.toLocaleLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "");
|
|
2268
2111
|
function filterRows(rows, filters) {
|
|
2269
2112
|
let search = filters.search?.trim() ? normalize(filters.search.trim()) : null;
|
|
2270
2113
|
return rows.filter((row) => !(filters.types?.length && !filters.types.includes(row.type) || filters.statuses?.length && !filters.statuses.includes(row.status) || filters.locales?.length && row.locale && !filters.locales.includes(row.locale) || search && !`${normalize(row.title)} ${normalize(row.path ?? "")}`.includes(search)));
|
|
@@ -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
|
|
@@ -3669,7 +3515,7 @@ function groupPageRows(rows, groupBy, options) {
|
|
|
3669
3515
|
return (fieldId ? options.fields.find((f) => f.id === fieldId) : void 0)?.options?.map((option) => option.id) ?? [];
|
|
3670
3516
|
})(), seen = /* @__PURE__ */ new Set(), ordered = [];
|
|
3671
3517
|
for (let value of configured) buckets.has(value) && (ordered.push(value), seen.add(value));
|
|
3672
|
-
for (let value of [...buckets.keys()].sort((a, b) => a.localeCompare(b, "
|
|
3518
|
+
for (let value of [...buckets.keys()].sort((a, b) => a.localeCompare(b, void 0, { sensitivity: "base" }))) value && !seen.has(value) && ordered.push(value);
|
|
3673
3519
|
return buckets.has("") && ordered.push(""), ordered.map((value) => ({
|
|
3674
3520
|
key: value,
|
|
3675
3521
|
...describe(value, groupBy, options),
|
|
@@ -6807,7 +6653,7 @@ function BlockCard(props) {
|
|
|
6807
6653
|
* publication et il faut la relire entièrement.
|
|
6808
6654
|
*/
|
|
6809
6655
|
function compareBy(order) {
|
|
6810
|
-
return order === "usage" ? (a, b) => b.occurrence.count - a.occurrence.count : order === "unused" ? (a, b) => a.occurrence.count - b.occurrence.count : (a, b) => a.block.name.localeCompare(b.block.name, "
|
|
6656
|
+
return order === "usage" ? (a, b) => b.occurrence.count - a.occurrence.count : order === "unused" ? (a, b) => a.occurrence.count - b.occurrence.count : (a, b) => a.block.name.localeCompare(b.block.name, void 0, { sensitivity: "base" });
|
|
6811
6657
|
}
|
|
6812
6658
|
/**
|
|
6813
6659
|
* Disposition de la carte des sections.
|
|
@@ -7269,7 +7115,7 @@ function ComponentsTool() {
|
|
|
7269
7115
|
occurrence,
|
|
7270
7116
|
block: byName.get(occurrence.type)
|
|
7271
7117
|
})).filter((row) => !!row.block);
|
|
7272
|
-
return order === "schema" ? rows : order === "type" ? [...rows].sort((a, b) => a.block.name.localeCompare(b.block.name, "
|
|
7118
|
+
return order === "schema" ? rows : order === "type" ? [...rows].sort((a, b) => a.block.name.localeCompare(b.block.name, void 0, { sensitivity: "base" })) : order === "unused" ? [...rows].sort((a, b) => a.occurrence.count - b.occurrence.count) : [...rows].sort((a, b) => b.occurrence.count - a.occurrence.count);
|
|
7273
7119
|
}, [
|
|
7274
7120
|
occurrences,
|
|
7275
7121
|
blockTypes,
|
|
@@ -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).
|
|
@@ -10204,7 +10094,7 @@ const ncfKit = definePlugin((options) => {
|
|
|
10204
10094
|
},
|
|
10205
10095
|
document: {
|
|
10206
10096
|
newDocumentOptions: (prev) => prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE),
|
|
10207
|
-
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
|
|
10208
10098
|
},
|
|
10209
10099
|
studio: { components: { toolMenu: createPreviewLauncher(config, issues) } },
|
|
10210
10100
|
form: { components: { input: createKitInput(config) } }
|