@nocode-factory/sanity-kit 2.23.0 → 2.25.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 +4 -0
- package/dist/index.d.ts +28 -2
- package/dist/index.js +200 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/form/LanguageMismatch.tsx +85 -0
- package/src/form/PublishedHint.tsx +35 -0
- package/src/index.ts +8 -1
- package/src/lib/mainDocuments.ts +72 -0
- package/src/lib/previewLocale.ts +17 -0
- package/src/lib/siteRoutes.ts +1 -1
- package/src/tools/navbar/DraftsOnLoad.tsx +25 -0
- package/src/tools/navbar/PreviewLauncher.tsx +2 -0
- package/src/version.ts +1 -1
package/bin/ncf-kit.mjs
CHANGED
|
@@ -373,6 +373,10 @@ async function doctor() {
|
|
|
373
373
|
}
|
|
374
374
|
const ci = walk(join(root, '.github', 'workflows')).some((f) => /check-translations/.test(read(f)))
|
|
375
375
|
ci ? ok('Langues : contrôle des données', 'check-translations en CI') : warn('Langues : contrôle des données', need('un contrôle des données en CI', 'pages sans traduction reliée, liens vers une autre langue', 'studio/scripts/check-translations.ts et son étape dans .github/workflows/ci.yml (voir le starter).'))
|
|
376
|
+
// Presentation : le panneau de droite suit la page affichée DANS SA LANGUE.
|
|
377
|
+
config.includes('ncfMainDocuments(')
|
|
378
|
+
? ok('Langues : panneau de Presentation', 'ncfMainDocuments')
|
|
379
|
+
: ko('Langues : panneau de Presentation', need('ncfMainDocuments dans presentationTool', 'en changeant de langue dans l\'aperçu, le panneau de droite doit éditer le document de cette langue', 'resolve: {mainDocuments: defineDocuments(ncfMainDocuments(ncfOptions, {siteRoutes: routes}))} (voir sanity.config.ts du starter).'))
|
|
376
380
|
const rules = read(join(root, 'CLAUDE.md'))
|
|
377
381
|
rules && !/trois règles/i.test(rules) && warn('Langues : consignes', need('les trois règles des langues dans CLAUDE.md', 'Claude ne les connaîtrait pas dans ce projet', 'recopier le bloc « LANGUES » du CLAUDE.md du starter.'))
|
|
378
382
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -676,6 +676,7 @@ interface SiteRoutesRegistry {
|
|
|
676
676
|
homePage?: boolean;
|
|
677
677
|
system?: boolean;
|
|
678
678
|
notFound?: boolean;
|
|
679
|
+
pageSlug?: string;
|
|
679
680
|
}[];
|
|
680
681
|
collections?: {
|
|
681
682
|
type: string;
|
|
@@ -1339,7 +1340,7 @@ export declare function ActorName(props: {
|
|
|
1339
1340
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1340
1341
|
* le vérifie.
|
|
1341
1342
|
*/
|
|
1342
|
-
export declare const KIT_VERSION = "2.
|
|
1343
|
+
export declare const KIT_VERSION = "2.25.0";
|
|
1343
1344
|
/**
|
|
1344
1345
|
* Données de la page proposées comme colonnes.
|
|
1345
1346
|
*
|
|
@@ -1803,6 +1804,31 @@ export declare function blockName(type: string, namespace: string): string;
|
|
|
1803
1804
|
export declare function fillTemplate(template: string, type: string, namespace: string): string;
|
|
1804
1805
|
/** Libellé lisible par défaut : 'imageText' -> 'Image text'. */
|
|
1805
1806
|
export declare function humanizeBlockName(type: string, namespace: string): string;
|
|
1807
|
+
/** Une entrée de `presentationTool({resolve: {mainDocuments: defineDocuments([...])}})`. */
|
|
1808
|
+
interface MainDocumentRoute {
|
|
1809
|
+
route: string;
|
|
1810
|
+
filter: string;
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* Presentation : le document du panneau de droite est TOUJOURS celui de la page
|
|
1814
|
+
* affichée, DANS SA LANGUE. Sans cette liste, changer de langue (ou de page) dans
|
|
1815
|
+
* l'aperçu laisse le panneau sur l'ancien document : on modifie le français en
|
|
1816
|
+
* regardant l'anglais.
|
|
1817
|
+
*
|
|
1818
|
+
* Une route par adresse et par langue (langue principale sans préfixe, les autres
|
|
1819
|
+
* sous /<langue>) : accueil, pages codées du registre (`pageSlug`), collections
|
|
1820
|
+
* (`<préfixe>/:slug`), design system (valeurs par défaut des composants). Ordre :
|
|
1821
|
+
* langues préfixées d'abord, puis du plus précis au plus général (`/:slug` en
|
|
1822
|
+
* dernier), pour que `/en` ne soit pas lu comme la page de slug « en ».
|
|
1823
|
+
*
|
|
1824
|
+
* ```ts
|
|
1825
|
+
* presentationTool({resolve: {mainDocuments: defineDocuments(ncfMainDocuments(ncfOptions, {siteRoutes: routes}))}})
|
|
1826
|
+
* ```
|
|
1827
|
+
*/
|
|
1828
|
+
export declare function ncfMainDocuments(options: NcfKitConfig, extra?: {
|
|
1829
|
+
siteRoutes?: SiteRoutesRegistry;
|
|
1830
|
+
designSystemRoutes?: string[];
|
|
1831
|
+
}): MainDocumentRoute[];
|
|
1806
1832
|
/** Noms des outils dans la barre du Studio. Exportés pour filtrer `tools`. */
|
|
1807
1833
|
export declare const NCF_PAGES_TOOL = "ncf-pages";
|
|
1808
1834
|
export declare const NCF_COMPONENTS_TOOL = "ncf-components";
|
|
@@ -1810,5 +1836,5 @@ export declare const NCF_HISTORY_TOOL = "ncf-history";
|
|
|
1810
1836
|
export declare const NCF_DESIGN_SYSTEM_TOOL = "ncf-design-system";
|
|
1811
1837
|
export declare const NCF_TOOL_NAMES: readonly ["ncf-pages", "ncf-components", "ncf-history", "ncf-design-system"];
|
|
1812
1838
|
export declare const ncfKit: import("sanity").Plugin<NcfKitConfig>;
|
|
1813
|
-
export { type AddColumnInput, type Annotation, type AnnotationsState, type BlockOccurrence, type BlockTypeInfo, type BoardEdge, type BoardGraph, type BoardLayoutState, type BoardNode, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, type Change, type ChangeKind, type CollectedLinks, type ColorBy, type ColorOptions, type ConfigIssue, DEFAULT_COMPONENT_DEFAULTS_TYPE, type DeriveOptions, type GroupBy, type GroupOptions, type HistoryDetail, type HistoryEvent, type IssueLevel, type KitContextValue, type KitUpdate, type LayoutMode, type MergedDoc, type NcfBoardTag, type NcfComponentPreviewConfig, type NcfDocumentColumn, type NcfEnvironment, type NcfHistoryConfig, type NcfI18nConfig, type NcfInternalField, type NcfInternalFieldOption, type NcfKitConfig, type NcfPageTypeConfig, type NcfPageTypeInput, type NcfToolName, type NcfToolsConfig, type NodeLayout, type NodePosition, type OccurrenceInput, type OccurrencePage, type OccurrencesState, type PageContent, type PageContentsState, type PageDoc, type PageFilters, type PageRow, type PageStatus, type PagesState, type PathInput, type Positioned, type PresentationOptions, type PreviewGrant, type PreviewPerspective, type PreviewTargetState, type ProjectStatus, type Registration, type ResolvedComponentPreview, type ResolvedDocumentColumn, type ResolvedHistory, type ResolvedI18n, type ResolvedKitConfig, type ResolvedPageType, type RowColor, type RowGroup, type SchemaFieldLike, type SchemaTypeLike, type SectionLayout, type SectionMapNode, type SectionOrder, type SectionsMapOptions, type Segment, type SiteRoutesRegistry, type SortDirection, type SortKey, type ThumbnailInput, type VersionedDoc, componentDefaultsMainDocument, componentDefaultsMainDocuments, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
|
|
1839
|
+
export { type AddColumnInput, type Annotation, type AnnotationsState, type BlockOccurrence, type BlockTypeInfo, type BoardEdge, type BoardGraph, type BoardLayoutState, type BoardNode, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, type Change, type ChangeKind, type CollectedLinks, type ColorBy, type ColorOptions, type ConfigIssue, DEFAULT_COMPONENT_DEFAULTS_TYPE, type DeriveOptions, type GroupBy, type GroupOptions, type HistoryDetail, type HistoryEvent, type IssueLevel, type KitContextValue, type KitUpdate, type LayoutMode, type MainDocumentRoute, type MergedDoc, type NcfBoardTag, type NcfComponentPreviewConfig, type NcfDocumentColumn, type NcfEnvironment, type NcfHistoryConfig, type NcfI18nConfig, type NcfInternalField, type NcfInternalFieldOption, type NcfKitConfig, type NcfPageTypeConfig, type NcfPageTypeInput, type NcfToolName, type NcfToolsConfig, type NodeLayout, type NodePosition, type OccurrenceInput, type OccurrencePage, type OccurrencesState, type PageContent, type PageContentsState, type PageDoc, type PageFilters, type PageRow, type PageStatus, type PagesState, type PathInput, type Positioned, type PresentationOptions, type PreviewGrant, type PreviewPerspective, type PreviewTargetState, type ProjectStatus, type Registration, type ResolvedComponentPreview, type ResolvedDocumentColumn, type ResolvedHistory, type ResolvedI18n, type ResolvedKitConfig, type ResolvedPageType, type RowColor, type RowGroup, type SchemaFieldLike, type SchemaTypeLike, type SectionLayout, type SectionMapNode, type SectionOrder, type SectionsMapOptions, type Segment, type SiteRoutesRegistry, type SortDirection, type SortKey, type ThumbnailInput, type VersionedDoc, componentDefaultsMainDocument, componentDefaultsMainDocuments, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
|
|
1814
1840
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as defineComponentDefaults, i as defaultsFieldName, n as componentDefaultsMainDocument, o as requiredUnlessDefault, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-BY3hQ6aD.js";
|
|
2
2
|
import { createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, useSchema, useUser, useWorkspace } from "sanity";
|
|
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";
|
|
5
5
|
import { ComponentIcon } from "@sanity/icons/Component";
|
|
6
6
|
import { DocumentsIcon } from "@sanity/icons/Documents";
|
|
@@ -37,6 +37,7 @@ import { RestoreIcon } from "@sanity/icons/Restore";
|
|
|
37
37
|
import { UndoIcon } from "@sanity/icons/Undo";
|
|
38
38
|
import { Tooltip } from "@sanity/ui/tooltip";
|
|
39
39
|
import { EyeClosedIcon } from "@sanity/icons/EyeClosed";
|
|
40
|
+
import { usePresentationNavigate, usePresentationParams } from "sanity/presentation";
|
|
40
41
|
import { useToast } from "@sanity/ui/toast";
|
|
41
42
|
const DEFAULT_PAGE_BUILDER_FIELD = "sections", DEFAULT_SLUG_FIELD = "slug", DEFAULT_TITLE_FIELD = "title", DEFAULT_NOINDEX_FIELDS = ["seo.noindex", "noindex"], DEFAULT_I18N = {
|
|
42
43
|
field: "language",
|
|
@@ -1418,7 +1419,7 @@ function explainGrantError(error) {
|
|
|
1418
1419
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1419
1420
|
* le vérifie.
|
|
1420
1421
|
*/
|
|
1421
|
-
const KIT_VERSION = "2.
|
|
1422
|
+
const KIT_VERSION = "2.25.0";
|
|
1422
1423
|
/**
|
|
1423
1424
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1424
1425
|
*
|
|
@@ -1584,6 +1585,22 @@ function createToolComponent(args) {
|
|
|
1584
1585
|
});
|
|
1585
1586
|
};
|
|
1586
1587
|
}
|
|
1588
|
+
let checked = !1;
|
|
1589
|
+
/**
|
|
1590
|
+
* À l'ouverture du Studio, on édite : vue « Drafts », jamais « Published ». Un lien
|
|
1591
|
+
* « Prod · En ligne » (perspective=published dans l'adresse) ou un Studio rechargé
|
|
1592
|
+
* sur cette vue rouvrait sinon en lecture seule. Ensuite, le choix de l'utilisateur
|
|
1593
|
+
* est respecté jusqu'au prochain chargement.
|
|
1594
|
+
*/
|
|
1595
|
+
function DraftsOnLoad() {
|
|
1596
|
+
let { selectedPerspectiveName } = usePerspective(), setPerspective = useSetPerspective();
|
|
1597
|
+
return useEffect(() => {
|
|
1598
|
+
if (checked) return;
|
|
1599
|
+
checked = !0;
|
|
1600
|
+
let fromUrl = typeof window < "u" && new URLSearchParams(window.location.search).get("perspective") === "published";
|
|
1601
|
+
(selectedPerspectiveName === "published" || fromUrl) && setPerspective("drafts");
|
|
1602
|
+
}, [selectedPerspectiveName, setPerspective]), null;
|
|
1603
|
+
}
|
|
1587
1604
|
/**
|
|
1588
1605
|
* Petit panneau ancré à son déclencheur.
|
|
1589
1606
|
*
|
|
@@ -1745,7 +1762,7 @@ function useKitUpdate() {
|
|
|
1745
1762
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1746
1763
|
}).catch(() => {}), () => controller.abort();
|
|
1747
1764
|
}, []);
|
|
1748
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1765
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.25.0") > 0);
|
|
1749
1766
|
return {
|
|
1750
1767
|
current: KIT_VERSION,
|
|
1751
1768
|
latest,
|
|
@@ -2109,10 +2126,10 @@ function NcfPreviewLauncher(props) {
|
|
|
2109
2126
|
*/
|
|
2110
2127
|
function createPreviewLauncher(config, issues) {
|
|
2111
2128
|
return function NcfToolMenu(props) {
|
|
2112
|
-
return /* @__PURE__ */
|
|
2129
|
+
return /* @__PURE__ */ jsxs(KitProvider, {
|
|
2113
2130
|
config,
|
|
2114
2131
|
issues,
|
|
2115
|
-
children: /* @__PURE__ */ jsx(NcfPreviewLauncher, { ...props })
|
|
2132
|
+
children: [/* @__PURE__ */ jsx(DraftsOnLoad, {}), /* @__PURE__ */ jsx(NcfPreviewLauncher, { ...props })]
|
|
2116
2133
|
});
|
|
2117
2134
|
};
|
|
2118
2135
|
}
|
|
@@ -8117,6 +8134,133 @@ function withTranslationTodo(Inner, config) {
|
|
|
8117
8134
|
}
|
|
8118
8135
|
return TranslationTodoInput;
|
|
8119
8136
|
}
|
|
8137
|
+
const LEAF = /* @__PURE__ */ new Set([
|
|
8138
|
+
"string",
|
|
8139
|
+
"number",
|
|
8140
|
+
"boolean"
|
|
8141
|
+
]);
|
|
8142
|
+
/**
|
|
8143
|
+
* Vue « Published » : le formulaire est en lecture seule et rien ne dit pourquoi.
|
|
8144
|
+
* Au survol d'un champ : « Switch to Drafts to edit ». La structure ne change
|
|
8145
|
+
* qu'avec la vue (jamais pendant la frappe : le champ n'est pas recréé).
|
|
8146
|
+
*/
|
|
8147
|
+
function withPublishedHint(Inner) {
|
|
8148
|
+
function PublishedHint(props) {
|
|
8149
|
+
let { selectedPerspectiveName } = usePerspective(), inner = createElement(Inner, props);
|
|
8150
|
+
return selectedPerspectiveName !== "published" || !LEAF.has(props.schemaType.jsonType) ? inner : /* @__PURE__ */ jsx(Tooltip, {
|
|
8151
|
+
portal: !0,
|
|
8152
|
+
placement: "top",
|
|
8153
|
+
content: /* @__PURE__ */ jsx(Box, {
|
|
8154
|
+
padding: 2,
|
|
8155
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
8156
|
+
size: 1,
|
|
8157
|
+
children: "Switch to Drafts to edit"
|
|
8158
|
+
})
|
|
8159
|
+
}),
|
|
8160
|
+
children: /* @__PURE__ */ jsx("div", { children: inner })
|
|
8161
|
+
});
|
|
8162
|
+
}
|
|
8163
|
+
return PublishedHint;
|
|
8164
|
+
}
|
|
8165
|
+
/**
|
|
8166
|
+
* Langue de la page affichée dans l'aperçu, d'après son adresse : premier segment
|
|
8167
|
+
* s'il est une langue autre que la principale (/en/...), sinon la langue principale.
|
|
8168
|
+
*/
|
|
8169
|
+
function localeOfPreview(preview, i18n) {
|
|
8170
|
+
if (!i18n || !preview) return null;
|
|
8171
|
+
let pathname;
|
|
8172
|
+
try {
|
|
8173
|
+
pathname = new URL(preview, "http://preview.local").pathname;
|
|
8174
|
+
} catch {
|
|
8175
|
+
return null;
|
|
8176
|
+
}
|
|
8177
|
+
let first = pathname.split("/").filter(Boolean)[0];
|
|
8178
|
+
return first && first !== i18n.defaultLocale && i18n.locales.includes(first) ? first : i18n.defaultLocale;
|
|
8179
|
+
}
|
|
8180
|
+
/**
|
|
8181
|
+
* Presentation : le panneau d'édition DOIT montrer la langue de l'aperçu. Si le
|
|
8182
|
+
* document édité n'est pas dans la langue de la page affichée (ex. aperçu EN, panneau
|
|
8183
|
+
* FR), un bandeau le dit en haut du formulaire, avec un bouton qui ouvre la bonne
|
|
8184
|
+
* version. Évite de modifier le français en croyant modifier l'anglais.
|
|
8185
|
+
* Structure stable : le formulaire garde sa place, que le bandeau soit là ou non.
|
|
8186
|
+
*/
|
|
8187
|
+
function withLanguageMismatch(Inner, config) {
|
|
8188
|
+
let i18n = config.i18n;
|
|
8189
|
+
function LanguageMismatch(props) {
|
|
8190
|
+
let inner = createElement(Inner, props);
|
|
8191
|
+
return !i18n || props.path.length > 0 ? inner : /* @__PURE__ */ jsxs(Stack, {
|
|
8192
|
+
gap: 4,
|
|
8193
|
+
children: [/* @__PURE__ */ jsx(MismatchCheck, {}), inner]
|
|
8194
|
+
});
|
|
8195
|
+
}
|
|
8196
|
+
function MismatchCheck() {
|
|
8197
|
+
let params = usePresentationParams(!1), language = useFormValue([i18n?.field ?? "language"]), shown = localeOfPreview(params?.preview, i18n);
|
|
8198
|
+
return !params || !language || !shown || language === shown ? null : /* @__PURE__ */ jsx(MismatchBanner, {
|
|
8199
|
+
editing: language,
|
|
8200
|
+
shown
|
|
8201
|
+
});
|
|
8202
|
+
}
|
|
8203
|
+
function MismatchBanner(props) {
|
|
8204
|
+
let { editing, shown } = props, navigate = usePresentationNavigate(), client = useKitClient(), id = useFormValue(["_id"])?.replace(/^drafts\./, ""), type = useFormValue(["_type"]), [target, setTarget] = useState(void 0);
|
|
8205
|
+
return useEffect(() => {
|
|
8206
|
+
if (!id) return;
|
|
8207
|
+
let alive = !0;
|
|
8208
|
+
return client.fetch("*[_type == \"translation.metadata\" && references($id)][0].translations[_key == $lang || language == $lang][0].value._ref", {
|
|
8209
|
+
id,
|
|
8210
|
+
lang: shown
|
|
8211
|
+
}).then((ref) => alive && setTarget(ref ?? null)).catch(() => alive && setTarget(null)), () => {
|
|
8212
|
+
alive = !1;
|
|
8213
|
+
};
|
|
8214
|
+
}, [
|
|
8215
|
+
client,
|
|
8216
|
+
id,
|
|
8217
|
+
shown
|
|
8218
|
+
]), /* @__PURE__ */ jsx(Card, {
|
|
8219
|
+
tone: "caution",
|
|
8220
|
+
padding: 3,
|
|
8221
|
+
radius: 2,
|
|
8222
|
+
border: !0,
|
|
8223
|
+
children: /* @__PURE__ */ jsxs(Flex, {
|
|
8224
|
+
align: "center",
|
|
8225
|
+
gap: 3,
|
|
8226
|
+
wrap: "wrap",
|
|
8227
|
+
children: [/* @__PURE__ */ jsxs(Text, {
|
|
8228
|
+
size: 1,
|
|
8229
|
+
weight: "semibold",
|
|
8230
|
+
style: {
|
|
8231
|
+
flex: 1,
|
|
8232
|
+
minWidth: 200
|
|
8233
|
+
},
|
|
8234
|
+
children: [
|
|
8235
|
+
"You are editing the ",
|
|
8236
|
+
editing.toUpperCase(),
|
|
8237
|
+
" version. The preview shows ",
|
|
8238
|
+
shown.toUpperCase(),
|
|
8239
|
+
"."
|
|
8240
|
+
]
|
|
8241
|
+
}), target && type ? /* @__PURE__ */ jsx(Button, {
|
|
8242
|
+
tone: "caution",
|
|
8243
|
+
fontSize: 1,
|
|
8244
|
+
padding: 2,
|
|
8245
|
+
text: `Edit the ${shown.toUpperCase()} version`,
|
|
8246
|
+
onClick: () => navigate(void 0, {
|
|
8247
|
+
type,
|
|
8248
|
+
id: target
|
|
8249
|
+
})
|
|
8250
|
+
}) : target === null ? /* @__PURE__ */ jsxs(Text, {
|
|
8251
|
+
size: 1,
|
|
8252
|
+
muted: !0,
|
|
8253
|
+
children: [
|
|
8254
|
+
"No ",
|
|
8255
|
+
shown.toUpperCase(),
|
|
8256
|
+
" version of this document yet."
|
|
8257
|
+
]
|
|
8258
|
+
}) : null]
|
|
8259
|
+
})
|
|
8260
|
+
});
|
|
8261
|
+
}
|
|
8262
|
+
return LanguageMismatch;
|
|
8263
|
+
}
|
|
8120
8264
|
const VALUE_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
8121
8265
|
"image",
|
|
8122
8266
|
"file",
|
|
@@ -8570,6 +8714,55 @@ function NcfPreviewHeader(props) {
|
|
|
8570
8714
|
function ncfPreviewComponents() {
|
|
8571
8715
|
return { unstable_header: { component: NcfPreviewHeader } };
|
|
8572
8716
|
}
|
|
8717
|
+
const SAFE = /^[A-Za-z0-9_.-]+$/, quote = (value) => JSON.stringify(value);
|
|
8718
|
+
/**
|
|
8719
|
+
* Presentation : le document du panneau de droite est TOUJOURS celui de la page
|
|
8720
|
+
* affichée, DANS SA LANGUE. Sans cette liste, changer de langue (ou de page) dans
|
|
8721
|
+
* l'aperçu laisse le panneau sur l'ancien document : on modifie le français en
|
|
8722
|
+
* regardant l'anglais.
|
|
8723
|
+
*
|
|
8724
|
+
* Une route par adresse et par langue (langue principale sans préfixe, les autres
|
|
8725
|
+
* sous /<langue>) : accueil, pages codées du registre (`pageSlug`), collections
|
|
8726
|
+
* (`<préfixe>/:slug`), design system (valeurs par défaut des composants). Ordre :
|
|
8727
|
+
* langues préfixées d'abord, puis du plus précis au plus général (`/:slug` en
|
|
8728
|
+
* dernier), pour que `/en` ne soit pas lu comme la page de slug « en ».
|
|
8729
|
+
*
|
|
8730
|
+
* ```ts
|
|
8731
|
+
* presentationTool({resolve: {mainDocuments: defineDocuments(ncfMainDocuments(ncfOptions, {siteRoutes: routes}))}})
|
|
8732
|
+
* ```
|
|
8733
|
+
*/
|
|
8734
|
+
function ncfMainDocuments(options, extra = {}) {
|
|
8735
|
+
let config = resolveConfig(options), i18n = config.i18n, field = i18n?.field ?? "language", locales = i18n ? [...i18n.locales.filter((l) => l !== i18n.defaultLocale), i18n.defaultLocale] : [null], slugTypes = config.pageTypes.filter((t) => t.slugField && !t.path), defaultsType = config.componentPreview.defaultsType, designSystem = extra.designSystemRoutes ?? ["/design-system/composant", "/design-system"], out = [];
|
|
8736
|
+
for (let locale of locales) {
|
|
8737
|
+
if (locale !== null && !SAFE.test(locale)) continue;
|
|
8738
|
+
let prefix = locale === null || locale === i18n?.defaultLocale ? "" : `/${locale}`, lang = locale === null ? "" : ` && ${field} == ${quote(locale)}`, at = (path) => path === "/" || path === "" ? prefix || "/" : `${prefix}${path}`;
|
|
8739
|
+
for (let route of designSystem) out.push({
|
|
8740
|
+
route: at(route),
|
|
8741
|
+
filter: `_type == ${quote(defaultsType)}${lang}`
|
|
8742
|
+
});
|
|
8743
|
+
for (let fixed of extra.siteRoutes?.fixed ?? []) {
|
|
8744
|
+
if (!fixed.pageSlug || fixed.system || fixed.notFound || !SAFE.test(fixed.pageSlug)) continue;
|
|
8745
|
+
let types = slugTypes.filter((t) => !t.pathPrefix || t.pathPrefix === "/").map((t) => quote(t.type)).join(", ");
|
|
8746
|
+
types && out.push({
|
|
8747
|
+
route: at(fixed.path),
|
|
8748
|
+
filter: `_type in [${types}] && slug.current == ${quote(fixed.pageSlug)}${lang}`
|
|
8749
|
+
});
|
|
8750
|
+
}
|
|
8751
|
+
for (let t of config.pageTypes) t.path && out.push({
|
|
8752
|
+
route: at(t.path),
|
|
8753
|
+
filter: `_type == ${quote(t.type)}${lang}`
|
|
8754
|
+
});
|
|
8755
|
+
let collections = [...slugTypes].sort((a, b) => (b.pathPrefix ?? "").length - (a.pathPrefix ?? "").length);
|
|
8756
|
+
for (let t of collections) {
|
|
8757
|
+
let base = t.pathPrefix && t.pathPrefix !== "/" ? t.pathPrefix : "";
|
|
8758
|
+
out.push({
|
|
8759
|
+
route: at(`${base}/:slug`),
|
|
8760
|
+
filter: `_type == ${quote(t.type)} && ${t.slugField}.current == $slug${lang}`
|
|
8761
|
+
});
|
|
8762
|
+
}
|
|
8763
|
+
}
|
|
8764
|
+
return out;
|
|
8765
|
+
}
|
|
8573
8766
|
/**
|
|
8574
8767
|
* Plugin Studio de NoCode Factory : Pages, Composants, Historique.
|
|
8575
8768
|
*
|
|
@@ -8593,7 +8786,7 @@ function createKitInput(config) {
|
|
|
8593
8786
|
function KitInput(props) {
|
|
8594
8787
|
return isSlugInput(props) ? createElement(SlugUrl, props) : createElement(Override, props);
|
|
8595
8788
|
}
|
|
8596
|
-
return config.i18n ? withTranslationTodo(KitInput, config) : KitInput;
|
|
8789
|
+
return withPublishedHint(config.i18n ? withLanguageMismatch(withTranslationTodo(KitInput, config), config) : KitInput);
|
|
8597
8790
|
}
|
|
8598
8791
|
const ncfKit = definePlugin((options) => {
|
|
8599
8792
|
let config = resolveConfig(options), issues = validateConfig(config);
|
|
@@ -8673,6 +8866,6 @@ const ncfKit = definePlugin((options) => {
|
|
|
8673
8866
|
form: { components: { input: createKitInput(config) } }
|
|
8674
8867
|
};
|
|
8675
8868
|
});
|
|
8676
|
-
export { ANNOTATION_TYPE, ActorName, BOARD_LAYOUT_ID, BOARD_LAYOUT_TYPE, BRAIN_NODE_SIZE, BoardLayoutProvider, COLUMN_TYPE, CONTENT_SCAN_LIMIT, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, CUSTOM_ENVIRONMENT_ID, DATA_PREFIX, DEFAULT_BOARD_TAGS, DEFAULT_COMPONENT_DEFAULTS_TYPE, DEFAULT_COMPONENT_PREVIEW, DEFAULT_I18N, DEFAULT_INTERNAL_FIELDS, DEFAULT_MORE_TOOLS, DEFAULT_PAGE_BUILDER_FIELD, DEFAULT_SLUG_FIELD, DEFAULT_TITLE_FIELD, KIT_API_VERSION, KIT_VERSION, NCF_COMPONENTS_TOOL, NCF_DESIGN_SYSTEM_TOOL, NCF_HIDDEN_TYPES, NCF_HISTORY_TOOL, NCF_MORE_TOOL, NCF_PAGES_TOOL, NCF_TOOL_NAMES, NODE_FIELD_TYPE, NODE_HEIGHT, NODE_WIDTH, NcfKitUpdate, NcfPreviewHeader, NcfPreviewLauncher, PERSPECTIVES, PROJECTION, SECTION_NODE_TYPE, STATUS_COLORS, STATUS_LABELS, SharePreview, UNSET_LABEL, addColumn, addColumnOption, announce, applySavedPositions, baseId, blockName, blockTypesFromSchema, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, compareVersions, componentDefaultsMainDocument, componentDefaultsMainDocuments, createPreviewLauncher, customEnvironment, defaultNodeSize, defaultsFieldName, defineComponentDefaults, depth, deriveDocumentColumns, diffDocuments, diffWords, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterRows, flatten, formatDocumentValue, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isKitType, isPrerelease, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, ncfAllowedOrigins, ncfKit, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, requestPreviewGrant, requiredUnlessDefault, requiredUnlessDefaultFor, resolveColorBy, resolveConfig, segments, slugKey, sortRows, summarize, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upsertLayout, urlOn, useAnnotations, useBoardLayout, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useKitUpdate, useOccurrences, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withMoreTool };
|
|
8869
|
+
export { ANNOTATION_TYPE, ActorName, BOARD_LAYOUT_ID, BOARD_LAYOUT_TYPE, BRAIN_NODE_SIZE, BoardLayoutProvider, COLUMN_TYPE, CONTENT_SCAN_LIMIT, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, CUSTOM_ENVIRONMENT_ID, DATA_PREFIX, DEFAULT_BOARD_TAGS, DEFAULT_COMPONENT_DEFAULTS_TYPE, DEFAULT_COMPONENT_PREVIEW, DEFAULT_I18N, DEFAULT_INTERNAL_FIELDS, DEFAULT_MORE_TOOLS, DEFAULT_PAGE_BUILDER_FIELD, DEFAULT_SLUG_FIELD, DEFAULT_TITLE_FIELD, KIT_API_VERSION, KIT_VERSION, NCF_COMPONENTS_TOOL, NCF_DESIGN_SYSTEM_TOOL, NCF_HIDDEN_TYPES, NCF_HISTORY_TOOL, NCF_MORE_TOOL, NCF_PAGES_TOOL, NCF_TOOL_NAMES, NODE_FIELD_TYPE, NODE_HEIGHT, NODE_WIDTH, NcfKitUpdate, NcfPreviewHeader, NcfPreviewLauncher, PERSPECTIVES, PROJECTION, SECTION_NODE_TYPE, STATUS_COLORS, STATUS_LABELS, SharePreview, UNSET_LABEL, addColumn, addColumnOption, announce, applySavedPositions, baseId, blockName, blockTypesFromSchema, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, compareVersions, componentDefaultsMainDocument, componentDefaultsMainDocuments, createPreviewLauncher, customEnvironment, defaultNodeSize, defaultsFieldName, defineComponentDefaults, depth, deriveDocumentColumns, diffDocuments, diffWords, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterRows, flatten, formatDocumentValue, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isKitType, isPrerelease, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, ncfAllowedOrigins, ncfKit, ncfMainDocuments, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, requestPreviewGrant, requiredUnlessDefault, requiredUnlessDefaultFor, resolveColorBy, resolveConfig, segments, slugKey, sortRows, summarize, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upsertLayout, urlOn, useAnnotations, useBoardLayout, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useKitUpdate, useOccurrences, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withMoreTool };
|
|
8677
8870
|
|
|
8678
8871
|
//# sourceMappingURL=index.js.map
|