@nocode-factory/sanity-kit 2.58.0 → 2.59.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 +24 -2
- package/dist/{finalUrl-IXF3zbT9.js → finalUrl-DYyjKCjh.js} +2 -1
- package/dist/finalUrl-DYyjKCjh.js.map +1 -0
- package/dist/{fixCrossLanguageReferences-CDczoic9.js → fixCrossLanguageReferences-C4A61VWW.js} +2 -2
- package/dist/{fixCrossLanguageReferences-CDczoic9.js.map → fixCrossLanguageReferences-C4A61VWW.js.map} +1 -1
- package/dist/{fixCrossLanguageReferences-C1VsmGsJ.d.ts → fixCrossLanguageReferences-CfFDSTD5.d.ts} +8 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +228 -87
- package/dist/index.js.map +1 -1
- package/dist/jsonld.js +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +2 -2
- package/package.json +1 -1
- package/src/config/resolve.ts +1 -0
- package/src/config/types.ts +7 -1
- package/src/index.ts +9 -3
- package/src/lib/i18nTemplates.ts +38 -4
- package/src/tools/presentation/PagesNavigator.tsx +150 -56
- package/src/version.ts +1 -1
- package/dist/finalUrl-IXF3zbT9.js.map +0 -1
package/dist/jsonld.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as pageTypeFor, t as finalPath, u as toUrl } from "./finalUrl-
|
|
1
|
+
import { o as pageTypeFor, t as finalPath, u as toUrl } from "./finalUrl-DYyjKCjh.js";
|
|
2
2
|
import { c as valueAtKey, f as useOptionalKitConfig, i as guessDocumentTitle, n as DEFAULT_JSONLD_FIELD, r as collectDocumentText, t as generateJsonLd } from "./aiJsonLd-BFyxgYen.js";
|
|
3
3
|
import { useCallback, useMemo, useState } from "react";
|
|
4
4
|
import { defineField, defineType, set, setIfMissing, unset, useFormValue } from "sanity";
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as componentDefaultsMainDocuments, d as requiredUnlessDefault, f as requiredUnlessDefaultFor, i as SiteRoutesRegistry, l as defaultsFieldName, n as fixCrossLanguageReferences, o as DEFAULT_COMPONENT_DEFAULTS_TYPE, r as withSameLanguageReferences, s as componentDefaultsMainDocument, t as CrossLanguageReport, u as defineComponentDefaults } from "./fixCrossLanguageReferences-
|
|
1
|
+
import { c as componentDefaultsMainDocuments, d as requiredUnlessDefault, f as requiredUnlessDefaultFor, i as SiteRoutesRegistry, l as defaultsFieldName, n as fixCrossLanguageReferences, o as DEFAULT_COMPONENT_DEFAULTS_TYPE, r as withSameLanguageReferences, s as componentDefaultsMainDocument, t as CrossLanguageReport, u as defineComponentDefaults } from "./fixCrossLanguageReferences-CfFDSTD5.js";
|
|
2
2
|
import { ComponentType } from "react";
|
|
3
3
|
import { SanityClient } from "sanity";
|
|
4
4
|
import { ListItemBuilder, StructureBuilder } from "sanity/structure";
|
package/dist/schema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as DEFAULT_PAGE_BUILDER_FIELD, i as redirectMapOf, l as toPath, n as followRedirects, r as redirectKey } from "./finalUrl-
|
|
2
|
-
import { a as componentDefaultsMainDocument, c as defineComponentDefaults, d as syncTranslationRedirects, f as translationRedirectId, i as DEFAULT_COMPONENT_DEFAULTS_TYPE, l as requiredUnlessDefault, n as withSameLanguageReferences, o as componentDefaultsMainDocuments, r as pageTypesFromSiteRoutes, s as defaultsFieldName, t as fixCrossLanguageReferences, u as requiredUnlessDefaultFor } from "./fixCrossLanguageReferences-
|
|
1
|
+
import { _ as DEFAULT_PAGE_BUILDER_FIELD, i as redirectMapOf, l as toPath, n as followRedirects, r as redirectKey } from "./finalUrl-DYyjKCjh.js";
|
|
2
|
+
import { a as componentDefaultsMainDocument, c as defineComponentDefaults, d as syncTranslationRedirects, f as translationRedirectId, i as DEFAULT_COMPONENT_DEFAULTS_TYPE, l as requiredUnlessDefault, n as withSameLanguageReferences, o as componentDefaultsMainDocuments, r as pageTypesFromSiteRoutes, s as defaultsFieldName, t as fixCrossLanguageReferences, u as requiredUnlessDefaultFor } from "./fixCrossLanguageReferences-C4A61VWW.js";
|
|
3
3
|
/**
|
|
4
4
|
* Onglets du formulaire d'un document : Content, Sections, SEO, Settings.
|
|
5
5
|
*
|
package/package.json
CHANGED
package/src/config/resolve.ts
CHANGED
|
@@ -99,6 +99,7 @@ export function resolveConfig(input: NcfKitConfig): ResolvedKitConfig {
|
|
|
99
99
|
codedPages: (input.siteRoutes?.fixed ?? [])
|
|
100
100
|
.filter((f) => f.pageSlug && !f.homePage && !f.system && !f.notFound)
|
|
101
101
|
.map((f) => ({pageSlug: f.pageSlug as string, path: normalizePath(f.path), localized: f.localized ?? null})),
|
|
102
|
+
collectionLabels: Object.fromEntries((input.siteRoutes?.collections ?? []).filter((c) => c.type && c.section).map((c) => [c.type as string, c.section as string])),
|
|
102
103
|
redirectType: input.redirectType?.trim() || 'redirect',
|
|
103
104
|
pageTypeNames: pageTypes.map((p) => p.type).filter(Boolean),
|
|
104
105
|
pageBuilderField: input.pageBuilderField?.trim() || DEFAULT_PAGE_BUILDER_FIELD,
|
package/src/config/types.ts
CHANGED
|
@@ -187,7 +187,11 @@ export interface NcfKitConfig {
|
|
|
187
187
|
* pour afficher partout l'URL FINALE d'une page (jamais son slug brut quand une
|
|
188
188
|
* page codée la sert sous une autre adresse).
|
|
189
189
|
*/
|
|
190
|
-
siteRoutes?: {
|
|
190
|
+
siteRoutes?: {
|
|
191
|
+
fixed?: {path: string; pageSlug?: string; homePage?: boolean; system?: boolean; notFound?: boolean; localized?: Record<string, string>}[]
|
|
192
|
+
/** Collections du registre : `section` = nom du dossier de la collection dans la liste des pages de Presentation. */
|
|
193
|
+
collections?: {type?: string; section?: string}[]
|
|
194
|
+
}
|
|
191
195
|
/**
|
|
192
196
|
* Type de document des redirections du Studio (champs `from`, `to`). Une adresse
|
|
193
197
|
* qui est le départ d'une redirection s'affiche avec sa destination (URL finale).
|
|
@@ -319,6 +323,8 @@ export interface ResolvedKitConfig {
|
|
|
319
323
|
pageTypes: ResolvedPageType[]
|
|
320
324
|
/** Pages codées servies sous une autre adresse que le slug de leur document. */
|
|
321
325
|
codedPages: {pageSlug: string; path: string; localized: Record<string, string> | null}[]
|
|
326
|
+
/** Nom affiché du dossier d'une collection (Presentation), par type : `section` du registre. */
|
|
327
|
+
collectionLabels: Record<string, string>
|
|
322
328
|
redirectType: string
|
|
323
329
|
pageTypeNames: string[]
|
|
324
330
|
pageBuilderField: string
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {HistoryTool} from './tools/history/HistoryTool'
|
|
|
19
19
|
import {DesignSystemTool} from './tools/designSystem/DesignSystemTool'
|
|
20
20
|
import {AssetsTool} from './tools/assets/AssetsTool'
|
|
21
21
|
import {BOARD_LAYOUT_TYPE, isKitType, kitSchemaTypes} from './schema/boardLayout'
|
|
22
|
-
import {dropRedundantLanguageTemplates} from './lib/i18nTemplates'
|
|
22
|
+
import {dropRedundantLanguageTemplates, withMasterLanguageBaseTemplates} from './lib/i18nTemplates'
|
|
23
23
|
import type {NcfKitConfig, NcfToolName} from './config/types'
|
|
24
24
|
|
|
25
25
|
/** Noms des outils dans la barre du Studio. Exportés pour filtrer `tools`. */
|
|
@@ -192,7 +192,13 @@ export const ncfKit = definePlugin<NcfKitConfig>((options) => {
|
|
|
192
192
|
schema: {
|
|
193
193
|
types: kitSchemaTypes,
|
|
194
194
|
// La disposition du board est écrite par l'outil, pas créée à la main.
|
|
195
|
-
|
|
195
|
+
// Multilingue : « + Article » crée dans la langue principale (sinon document
|
|
196
|
+
// sans langue, invisible du site ; voir withMasterLanguageBaseTemplates).
|
|
197
|
+
templates: (prev, context) => {
|
|
198
|
+
const kept = prev.filter((template) => !isKitType(template.schemaType))
|
|
199
|
+
const i18n = config.i18n
|
|
200
|
+
return i18n ? withMasterLanguageBaseTemplates(kept, {field: i18n.field, defaultLocale: i18n.defaultLocale}, (type) => hasLanguageField(context.schema.get(type), i18n.field)) : kept
|
|
201
|
+
},
|
|
196
202
|
},
|
|
197
203
|
|
|
198
204
|
document: {
|
|
@@ -200,7 +206,7 @@ export const ncfKit = definePlugin<NcfKitConfig>((options) => {
|
|
|
200
206
|
// « + Français Article » que document-internationalization ajoute à côté
|
|
201
207
|
// du « + Article » de base (voir dropRedundantLanguageTemplates).
|
|
202
208
|
newDocumentOptions: (prev) =>
|
|
203
|
-
dropRedundantLanguageTemplates(prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE)),
|
|
209
|
+
dropRedundantLanguageTemplates(prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE), config.i18n),
|
|
204
210
|
// Pages : « Retirer du site » (dépublication expliquée, liens listés) à la place
|
|
205
211
|
// du « Unpublish » natif, caché et bloqué sans explication par les références.
|
|
206
212
|
// Supprimer la version principale d'un document traduit : suppression de ses
|
package/src/lib/i18nTemplates.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Menu « + » du Studio
|
|
2
|
+
* Menu « + » du Studio (monolingue, et multilingue depuis la 2.59.0). Pur.
|
|
3
3
|
*
|
|
4
4
|
* `@sanity/document-internationalization` ajoute, pour chaque type traduit, un
|
|
5
5
|
* template « paramétré » (`${type}-parameterized`) et un template statique par
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* Avec une seule langue branchée, ces deux-là font doublon avec le « + Article »
|
|
8
8
|
* de base : le menu de création montre « + Article » ET « + Français Article ».
|
|
9
9
|
*
|
|
10
|
-
* On ne garde alors que la base.
|
|
11
|
-
*
|
|
10
|
+
* On ne garde alors que la base. MULTILINGUE (kit configuré avec `i18n`) : la base
|
|
11
|
+
* crée dans la langue principale (withMasterLanguageBaseTemplates) ; on retire son
|
|
12
|
+
* doublon « + Français Article » et le paramétré, les autres langues restent.
|
|
12
13
|
*
|
|
13
14
|
* Détection sans connaître la liste des langues : le template `-parameterized`
|
|
14
15
|
* est la signature du plugin ; s'il n'existe qu'UN statique pour ce type (et que
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
* plusieurs statiques : on laisse tout, par prudence — jamais retirer la seule
|
|
17
18
|
* façon de créer un document.
|
|
18
19
|
*/
|
|
19
|
-
export function dropRedundantLanguageTemplates<T extends {templateId: string}>(options: readonly T[]): T[] {
|
|
20
|
+
export function dropRedundantLanguageTemplates<T extends {templateId: string}>(options: readonly T[], i18n?: {defaultLocale: string} | null): T[] {
|
|
20
21
|
const ids = new Set(options.map((option) => option.templateId))
|
|
21
22
|
const remove = new Set<string>()
|
|
22
23
|
const suffix = '-parameterized'
|
|
@@ -26,6 +27,15 @@ export function dropRedundantLanguageTemplates<T extends {templateId: string}>(o
|
|
|
26
27
|
const base = templateId.slice(0, -suffix.length)
|
|
27
28
|
// Pas de type de base dans le menu : on ne retire rien.
|
|
28
29
|
if (!ids.has(base)) continue
|
|
30
|
+
// MULTILINGUE (kit configuré avec i18n) : la base crée dans la langue principale
|
|
31
|
+
// (withMasterLanguageBaseTemplates), « + Français Article » est donc son doublon
|
|
32
|
+
// exact ; le paramétré n'a pas sa place dans le menu. Les autres langues restent
|
|
33
|
+
// (« + English Article »).
|
|
34
|
+
if (i18n && ids.has(`${base}-${i18n.defaultLocale}`)) {
|
|
35
|
+
remove.add(templateId)
|
|
36
|
+
remove.add(`${base}-${i18n.defaultLocale}`)
|
|
37
|
+
continue
|
|
38
|
+
}
|
|
29
39
|
const statics = options.filter(
|
|
30
40
|
(option) => option.templateId !== templateId && option.templateId.startsWith(`${base}-`),
|
|
31
41
|
)
|
|
@@ -38,3 +48,27 @@ export function dropRedundantLanguageTemplates<T extends {templateId: string}>(o
|
|
|
38
48
|
|
|
39
49
|
return options.filter((option) => !remove.has(option.templateId))
|
|
40
50
|
}
|
|
51
|
+
|
|
52
|
+
type TemplateLike = {id: string; schemaType: string; value?: unknown}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* MULTILINGUE : le template de BASE d'un type traduit (« + Article ») crée un
|
|
56
|
+
* document SANS langue (document-internationalization ne la pose que dans ses
|
|
57
|
+
* templates « + Français Article » / « + English Article »). Un tel document est
|
|
58
|
+
* invisible du site (requêtes filtrées sur la langue) et hors des listes par
|
|
59
|
+
* langue. Le kit fait créer la base dans la langue PRINCIPALE (règle : le contenu
|
|
60
|
+
* naît dans la langue master, les autres langues suivent par traduction). Une
|
|
61
|
+
* langue déjà fixée par le template d'origine est respectée.
|
|
62
|
+
*/
|
|
63
|
+
export function withMasterLanguageBaseTemplates<T extends TemplateLike>(templates: readonly T[], i18n: {field: string; defaultLocale: string}, isTranslated: (schemaType: string) => boolean): T[] {
|
|
64
|
+
return templates.map((template) => {
|
|
65
|
+
if (template.id !== template.schemaType || !isTranslated(template.schemaType)) return template
|
|
66
|
+
const original = template.value
|
|
67
|
+
const value = async (params: unknown, context: unknown) => {
|
|
68
|
+
const resolved = typeof original === 'function' ? await (original as (p: unknown, c: unknown) => unknown)(params, context) : original
|
|
69
|
+
const base = resolved && typeof resolved === 'object' ? (resolved as Record<string, unknown>) : {}
|
|
70
|
+
return base[i18n.field] ? base : {...base, [i18n.field]: i18n.defaultLocale}
|
|
71
|
+
}
|
|
72
|
+
return {...template, value}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {useMemo, useState, type ComponentType} from 'react'
|
|
2
|
-
import {Box, Button, Card, Flex, Spinner, Stack, Text, TextInput} from '@sanity/ui'
|
|
2
|
+
import {Badge, Box, Button, Card, Flex, Spinner, Stack, Text, TextInput} from '@sanity/ui'
|
|
3
|
+
import {ChevronDownIcon} from '@sanity/icons/ChevronDown'
|
|
4
|
+
import {ChevronRightIcon} from '@sanity/icons/ChevronRight'
|
|
5
|
+
import {FolderIcon} from '@sanity/icons/Folder'
|
|
6
|
+
import {useSchema} from 'sanity'
|
|
3
7
|
import {SearchIcon} from '@sanity/icons/Search'
|
|
4
8
|
import {DragHandleIcon} from '@sanity/icons/DragHandle'
|
|
5
9
|
import {usePresentationNavigate, usePresentationParams} from 'sanity/presentation'
|
|
@@ -23,13 +27,31 @@ const pathOf = (preview: string | undefined | null): string | null => {
|
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
/** Dossiers ouverts / fermés, mémorisés dans ce navigateur. */
|
|
31
|
+
const FOLDERS_KEY = 'ncf-presentation-folders'
|
|
32
|
+
const readFolders = (): Record<string, boolean> => {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(window.localStorage.getItem(FOLDERS_KEY) || '{}')
|
|
35
|
+
} catch {
|
|
36
|
+
return {}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type Row = ReturnType<typeof usePages>['rows'][number]
|
|
41
|
+
|
|
26
42
|
/**
|
|
27
43
|
* Liste des pages à gauche de l'aperçu (Presentation) : passer d'une page à l'autre
|
|
28
44
|
* sans repasser par Structure. Langue de la page affichée par défaut, recherche par
|
|
29
45
|
* titre ou adresse ; un clic ouvre la page dans l'aperçu ET son document à côté.
|
|
46
|
+
* - À la racine : l'accueil et les pages ; puis un DOSSIER repliable par collection à
|
|
47
|
+
* pages (préfixe d'adresse, ex. « Actualités /actualites/… »), avec son nombre de
|
|
48
|
+
* fiches, ouvert s'il contient la page affichée ou pendant une recherche.
|
|
49
|
+
* - Glisser-déposer (poignée) : réordonne les pages, dans leur groupe (racine ou
|
|
50
|
+
* dossier). Ordre partagé, repris par l'onglet Pages (tri « manual »).
|
|
30
51
|
*/
|
|
31
52
|
function PagesNavigator() {
|
|
32
53
|
const config = useKitConfig()
|
|
54
|
+
const schema = useSchema()
|
|
33
55
|
const {rows, loading} = usePages()
|
|
34
56
|
const {pageOrder, savePageOrder} = useBoardLayout()
|
|
35
57
|
const params = usePresentationParams(false)
|
|
@@ -38,12 +60,27 @@ function PagesNavigator() {
|
|
|
38
60
|
const shownLocale = localeOfPreview(params?.preview, i18n)
|
|
39
61
|
const [locale, setLocale] = useState<string | null>(null)
|
|
40
62
|
const [search, setSearch] = useState('')
|
|
41
|
-
const [
|
|
63
|
+
const [drag, setDrag] = useState<{id: string; group: string} | null>(null)
|
|
64
|
+
const [open, setOpen] = useState<Record<string, boolean>>(() => (typeof window === 'undefined' ? {} : readFolders()))
|
|
42
65
|
// Langue choisie, sinon celle de la page affichée, sinon la langue principale :
|
|
43
66
|
// le menu montre toujours la langue réellement filtrée.
|
|
44
67
|
const activeLocale = locale ?? shownLocale ?? i18n?.defaultLocale ?? ''
|
|
45
68
|
const current = pathOf(params?.preview)
|
|
46
69
|
|
|
70
|
+
// Collections à pages (préfixe d'adresse) : un dossier chacune.
|
|
71
|
+
const folderTypes = useMemo(
|
|
72
|
+
() =>
|
|
73
|
+
config.pageTypes
|
|
74
|
+
.filter((t) => t.pathPrefix)
|
|
75
|
+
.map((t) => ({
|
|
76
|
+
type: t.type,
|
|
77
|
+
label: config.collectionLabels[t.type] || schema.get(t.type)?.title || t.type,
|
|
78
|
+
prefix: (i18n && (t.localizedPrefixes?.[activeLocale] ?? t.localizedPrefixes?.[i18n.defaultLocale])) || t.pathPrefix || '',
|
|
79
|
+
})),
|
|
80
|
+
[config.pageTypes, config.collectionLabels, schema, i18n, activeLocale],
|
|
81
|
+
)
|
|
82
|
+
const folderOf = useMemo(() => new Set(folderTypes.map((f) => f.type)), [folderTypes])
|
|
83
|
+
|
|
47
84
|
// Ordre de base : alphabétique par adresse, puis l'ordre manuel passe devant.
|
|
48
85
|
const withPath = useMemo(() => rows.filter((r) => r.path !== null).sort((a, b) => (a.path ?? '').localeCompare(b.path ?? '')), [rows])
|
|
49
86
|
|
|
@@ -55,15 +92,95 @@ function PagesNavigator() {
|
|
|
55
92
|
return orderByIds(filtered, pageOrder)
|
|
56
93
|
}, [withPath, search, activeLocale, i18n, pageOrder])
|
|
57
94
|
|
|
58
|
-
|
|
59
|
-
|
|
95
|
+
const groups = useMemo(() => {
|
|
96
|
+
const root = visible.filter((r) => !folderOf.has(r.type))
|
|
97
|
+
const folders = folderTypes.map((f) => ({...f, rows: visible.filter((r) => r.type === f.type)})).filter((f) => f.rows.length)
|
|
98
|
+
return {root, folders}
|
|
99
|
+
}, [visible, folderTypes, folderOf])
|
|
100
|
+
|
|
101
|
+
const groupOf = (row: Row) => (folderOf.has(row.type) ? row.type : '')
|
|
102
|
+
|
|
103
|
+
// Glisser une page la place avant celle survolée (même groupe) ; on réordonne
|
|
104
|
+
// l'ordre manuel COMPLET (ids), pas la vue filtrée, pour ne pas perdre les autres.
|
|
60
105
|
const onReorder = (targetId: string | null) => {
|
|
61
|
-
if (!
|
|
106
|
+
if (!drag) return
|
|
62
107
|
const fullIds = orderByIds(withPath, pageOrder).map((r) => r.id)
|
|
63
|
-
savePageOrder(reorderBefore(fullIds,
|
|
64
|
-
|
|
108
|
+
savePageOrder(reorderBefore(fullIds, drag.id, targetId))
|
|
109
|
+
setDrag(null)
|
|
65
110
|
}
|
|
66
111
|
|
|
112
|
+
const toggle = (type: string, value: boolean) => {
|
|
113
|
+
const next = {...open, [type]: value}
|
|
114
|
+
setOpen(next)
|
|
115
|
+
try {
|
|
116
|
+
window.localStorage.setItem(FOLDERS_KEY, JSON.stringify(next))
|
|
117
|
+
} catch {
|
|
118
|
+
// Stockage indisponible : l'état vaut pour cette page seulement.
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const item = (row: Row, nested = false) => {
|
|
123
|
+
const selected = current !== null && current === ((row.path ?? '').replace(/\/$/, '') || '/')
|
|
124
|
+
const group = groupOf(row)
|
|
125
|
+
return (
|
|
126
|
+
<Card
|
|
127
|
+
key={row.id}
|
|
128
|
+
as="button"
|
|
129
|
+
padding={2}
|
|
130
|
+
radius={2}
|
|
131
|
+
tone={selected ? 'primary' : 'default'}
|
|
132
|
+
pressed={selected}
|
|
133
|
+
draggable
|
|
134
|
+
onDragStart={(event) => {
|
|
135
|
+
setDrag({id: row.id, group})
|
|
136
|
+
event.dataTransfer.effectAllowed = 'move'
|
|
137
|
+
}}
|
|
138
|
+
onDragOver={(event) => {
|
|
139
|
+
if (drag && drag.id !== row.id && drag.group === group) event.preventDefault()
|
|
140
|
+
}}
|
|
141
|
+
onDrop={(event) => {
|
|
142
|
+
event.preventDefault()
|
|
143
|
+
if (drag?.group === group) onReorder(row.id)
|
|
144
|
+
}}
|
|
145
|
+
onDragEnd={() => setDrag(null)}
|
|
146
|
+
style={{textAlign: 'left', cursor: 'pointer', border: 0, width: '100%', opacity: drag?.id === row.id ? 0.4 : 1, marginLeft: nested ? 18 : 0, maxWidth: nested ? 'calc(100% - 18px)' : undefined}}
|
|
147
|
+
onClick={() => navigate(row.path ?? undefined, {type: row.type, id: row.id})}
|
|
148
|
+
>
|
|
149
|
+
<Flex align="center" gap={2}>
|
|
150
|
+
<Text size={1} muted style={{flex: 'none', cursor: 'grab'}} title="Glisser pour réordonner">
|
|
151
|
+
<DragHandleIcon />
|
|
152
|
+
</Text>
|
|
153
|
+
<Stack gap={1} flex={1} style={{minWidth: 0}}>
|
|
154
|
+
<Text size={1} weight={selected ? 'semibold' : 'regular'} textOverflow="ellipsis">
|
|
155
|
+
{row.title || row.path}
|
|
156
|
+
</Text>
|
|
157
|
+
<Text size={0} muted textOverflow="ellipsis">
|
|
158
|
+
{row.path}
|
|
159
|
+
</Text>
|
|
160
|
+
</Stack>
|
|
161
|
+
{row.status !== 'published' && <StatusBadge status={row.status} />}
|
|
162
|
+
</Flex>
|
|
163
|
+
</Card>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Zone de dépôt en fin de groupe (placer une page en dernier).
|
|
168
|
+
const endZone = (group: string, lastId: string | undefined) =>
|
|
169
|
+
drag && drag.group === group ? (
|
|
170
|
+
<Box
|
|
171
|
+
padding={2}
|
|
172
|
+
onDragOver={(event) => event.preventDefault()}
|
|
173
|
+
onDrop={(event) => {
|
|
174
|
+
event.preventDefault()
|
|
175
|
+
// Après la dernière page du groupe : avant celle qui la suit dans l'ordre complet.
|
|
176
|
+
const full = orderByIds(withPath, pageOrder).map((r) => r.id)
|
|
177
|
+
const after = lastId ? full[full.indexOf(lastId) + 1] : undefined
|
|
178
|
+
onReorder(after ?? null)
|
|
179
|
+
}}
|
|
180
|
+
style={{height: 24}}
|
|
181
|
+
/>
|
|
182
|
+
) : null
|
|
183
|
+
|
|
67
184
|
return (
|
|
68
185
|
<Card height="fill" borderRight style={{display: 'flex', flexDirection: 'column', minHeight: 0}}>
|
|
69
186
|
<Stack gap={2} padding={2} style={{flex: 'none'}}>
|
|
@@ -107,60 +224,37 @@ function PagesNavigator() {
|
|
|
107
224
|
</Flex>
|
|
108
225
|
) : (
|
|
109
226
|
<Stack gap={1} padding={1}>
|
|
110
|
-
{
|
|
111
|
-
|
|
227
|
+
{groups.root.map((row) => item(row))}
|
|
228
|
+
{endZone('', groups.root.at(-1)?.id)}
|
|
229
|
+
{groups.folders.map((f) => {
|
|
230
|
+
const hasCurrent = f.rows.some((r) => current === ((r.path ?? '').replace(/\/$/, '') || '/'))
|
|
231
|
+
const isOpen = search.trim() ? true : (open[f.type] ?? hasCurrent)
|
|
112
232
|
return (
|
|
113
|
-
<
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
tone={selected ? 'primary' : 'default'}
|
|
119
|
-
pressed={selected}
|
|
120
|
-
draggable
|
|
121
|
-
onDragStart={(event) => {
|
|
122
|
-
setDragId(row.id)
|
|
123
|
-
event.dataTransfer.effectAllowed = 'move'
|
|
124
|
-
}}
|
|
125
|
-
onDragOver={(event) => {
|
|
126
|
-
if (dragId && dragId !== row.id) event.preventDefault()
|
|
127
|
-
}}
|
|
128
|
-
onDrop={(event) => {
|
|
129
|
-
event.preventDefault()
|
|
130
|
-
onReorder(row.id)
|
|
131
|
-
}}
|
|
132
|
-
onDragEnd={() => setDragId(null)}
|
|
133
|
-
style={{textAlign: 'left', cursor: 'pointer', border: 0, width: '100%', opacity: dragId === row.id ? 0.4 : 1}}
|
|
134
|
-
onClick={() => navigate(row.path ?? undefined, {type: row.type, id: row.id})}
|
|
135
|
-
>
|
|
136
|
-
<Flex align="center" gap={2}>
|
|
137
|
-
<Text size={1} muted style={{flex: 'none', cursor: 'grab'}} title="Glisser pour réordonner">
|
|
138
|
-
<DragHandleIcon />
|
|
139
|
-
</Text>
|
|
140
|
-
<Stack gap={1} flex={1} style={{minWidth: 0}}>
|
|
141
|
-
<Text size={1} weight={selected ? 'semibold' : 'regular'} textOverflow="ellipsis">
|
|
142
|
-
{row.title || row.path}
|
|
233
|
+
<Stack key={f.type} gap={1} marginTop={2}>
|
|
234
|
+
<Card as="button" padding={2} radius={2} style={{textAlign: 'left', cursor: 'pointer', border: 0, width: '100%'}} aria-expanded={isOpen} onClick={() => toggle(f.type, !isOpen)}>
|
|
235
|
+
<Flex align="center" gap={2}>
|
|
236
|
+
<Text size={1} muted>
|
|
237
|
+
{isOpen ? <ChevronDownIcon /> : <ChevronRightIcon />}
|
|
143
238
|
</Text>
|
|
144
|
-
<Text size={
|
|
145
|
-
|
|
239
|
+
<Text size={1}>
|
|
240
|
+
<FolderIcon />
|
|
146
241
|
</Text>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
242
|
+
<Stack gap={2} flex={1} style={{minWidth: 0}}>
|
|
243
|
+
<Text size={1} weight="semibold" textOverflow="ellipsis">
|
|
244
|
+
{f.label}
|
|
245
|
+
</Text>
|
|
246
|
+
<Text size={0} muted>
|
|
247
|
+
{f.prefix}/…
|
|
248
|
+
</Text>
|
|
249
|
+
</Stack>
|
|
250
|
+
<Badge fontSize={0}>{f.rows.length}</Badge>
|
|
251
|
+
</Flex>
|
|
252
|
+
</Card>
|
|
253
|
+
{isOpen && f.rows.map((row) => item(row, true))}
|
|
254
|
+
{isOpen && endZone(f.type, f.rows.at(-1)?.id)}
|
|
255
|
+
</Stack>
|
|
151
256
|
)
|
|
152
257
|
})}
|
|
153
|
-
{dragId ? (
|
|
154
|
-
<Box
|
|
155
|
-
padding={2}
|
|
156
|
-
onDragOver={(event) => event.preventDefault()}
|
|
157
|
-
onDrop={(event) => {
|
|
158
|
-
event.preventDefault()
|
|
159
|
-
onReorder(null)
|
|
160
|
-
}}
|
|
161
|
-
style={{height: 24}}
|
|
162
|
-
/>
|
|
163
|
-
) : null}
|
|
164
258
|
{!visible.length && (
|
|
165
259
|
<Box padding={3}>
|
|
166
260
|
<Text size={1} muted>
|
package/src/version.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"finalUrl-IXF3zbT9.js","names":[],"sources":["../src/config/defaults.ts","../src/config/resolve.ts","../src/lib/paths.ts","../src/lib/finalUrl.ts"],"sourcesContent":["import type {\n NcfBoardTag,\n NcfInternalField,\n NcfComponentPreviewConfig,\n NcfI18nConfig,\n NcfToolsConfig,\n} from './types'\n\nexport const DEFAULT_PAGE_BUILDER_FIELD = 'sections'\nexport const DEFAULT_SLUG_FIELD = 'slug'\nexport const DEFAULT_TITLE_FIELD = 'title'\nexport const DEFAULT_BLOCK_NAMESPACE = ''\n\n/**\n * Chemins essayés pour savoir si une page est indexable. Le premier\n * correspond à la convention du starter (`seo.noindex`), le second couvre les\n * schémas qui portent le drapeau à la racine.\n */\nexport const DEFAULT_NOINDEX_FIELDS = ['seo.noindex', 'noindex']\n\n// Aucune langue par défaut : la langue principale (master) vient TOUJOURS du projet\n// (`defaultLocale`, sinon la première de `locales`). Un site peut avoir le français,\n// l'anglais ou toute autre langue comme master.\nexport const DEFAULT_I18N: Omit<Required<NcfI18nConfig>, 'defaultsSourceLocale' | 'defaultLocale'> = {\n field: 'language',\n locales: [],\n}\n\n/**\n * Convention NoCode Factory : page `/design-system` dans le front, captures\n * dans `/sections/<nom>.png` générées au push par GitHub Actions.\n */\nexport const DEFAULT_COMPONENT_PREVIEW: Required<NcfComponentPreviewConfig> = {\n provider: 'designSystemPage',\n path: '/design-system',\n anchor: '{name}',\n thumbnail: '/sections/{name}.png',\n defaultsType: 'componentDefaults',\n live: '/design-system/composant?type={name}',\n}\n\nexport const DEFAULT_TOOLS: Required<NcfToolsConfig> = {\n pages: true,\n components: true,\n history: true,\n designSystem: true,\n assets: true,\n}\n\n/**\n * Outils rangés dans « Plus » : Vision (console GROQ) et la planification\n * (« Scheduled drafts » quand les Releases sont désactivées, « Releases » sinon :\n * le même outil, nommé `releases` ; `schedules` couvre les anciennes versions).\n */\nexport const DEFAULT_TOOLBAR_MORE = ['vision', 'releases', 'schedules']\n\n/**\n * Étiquettes de suivi par défaut : l'avancement d'une refonte, pas un statut\n * de publication. Elles vivent dans le document de disposition du kit, donc\n * aucun schéma client n'est modifié.\n */\nexport const DEFAULT_BOARD_TAGS: NcfBoardTag[] = [\n {id: 'en-cours', label: 'In progress', color: '#f5a623'},\n {id: 'fait', label: 'Done', color: '#43d675'},\n {id: 'a-relire', label: 'To review', color: '#2276fc'},\n {id: 'a-refondre', label: 'To rework', color: '#f03e3e'},\n]\n\n/**\n * Colonnes de gestion interne par défaut. Volontairement peu nombreuses : ce\n * sont celles qu'on redemande sur tous les projets. `internalFields` les\n * remplace entièrement.\n */\nexport const DEFAULT_INTERNAL_FIELDS: NcfInternalField[] = [\n {id: 'owner', label: 'Owner', type: 'text'},\n {id: 'audience', label: 'Audience', type: 'text'},\n {id: 'role', label: 'Page role', type: 'text'},\n]\n\n/**\n * Service du kit, hébergé par NoCode Factory.\n *\n * Renseigné d'office pour qu'un Studio n'ait rien à configurer : il se\n * signale au démarrage, et c'est ce qui permet de savoir quels projets\n * utilisent le kit. `endpoint` le remplace pour une instance privée.\n */\nexport const DEFAULT_SERVICE_ENDPOINT = 'https://dkoxgivytgsmvqmjvmjt.supabase.co/functions/v1'\n","import {\n DEFAULT_BLOCK_NAMESPACE,\n DEFAULT_BOARD_TAGS,\n DEFAULT_INTERNAL_FIELDS,\n DEFAULT_SERVICE_ENDPOINT,\n DEFAULT_COMPONENT_PREVIEW,\n DEFAULT_I18N,\n DEFAULT_NOINDEX_FIELDS,\n DEFAULT_PAGE_BUILDER_FIELD,\n DEFAULT_SLUG_FIELD,\n DEFAULT_TITLE_FIELD,\n DEFAULT_TOOLBAR_MORE, DEFAULT_TOOLS,\n} from './defaults'\nimport type {\n NcfEnvironment,\n NcfKitConfig,\n NcfPageTypeConfig,\n ResolvedKitConfig,\n ResolvedPageType,\n} from './types'\n\nconst trimTrailingSlash = (url: string) => url.replace(/\\/+$/, '')\n\n/** Garantit un chemin absolu ('accueil' -> '/accueil', '' -> '/'). */\nexport const normalizePath = (path: string): string => {\n const trimmed = path.trim()\n if (!trimmed || trimmed === '/') return '/'\n const withSlash = trimmed.startsWith('/') ? trimmed : `/${trimmed}`\n return withSlash.length > 1 ? trimTrailingSlash(withSlash) : withSlash\n}\n\nfunction resolvePageType(\n entry: NcfPageTypeConfig,\n defaults: {slugField: string; titleField: string},\n): ResolvedPageType {\n if (typeof entry === 'string') {\n return {\n type: entry.trim(),\n slugField: defaults.slugField,\n path: null,\n pathPrefix: null,\n localizedPrefixes: null,\n titleField: defaults.titleField,\n }\n }\n\n // `path` gagne sur `slugField` : une page à chemin fixe (l'accueil) n'a pas\n // de slug à lire, même si le type en porte un par ailleurs.\n const path = typeof entry.path === 'string' ? normalizePath(entry.path) : null\n const slugField =\n entry.slugField === null ? null : (entry.slugField?.trim() || defaults.slugField)\n\n // Un préfixe vide ou '/' vaut « à la racine » : pas de préfixe.\n const prefix = typeof entry.pathPrefix === 'string' ? normalizePath(entry.pathPrefix) : '/'\n\n return {\n type: (entry.type ?? '').trim(),\n slugField: path ? null : slugField,\n path,\n // Conservé même avec `path` (qui gagne au calcul du chemin) : la validation\n // peut ainsi signaler le préfixe inutile.\n pathPrefix: prefix === '/' ? null : prefix,\n localizedPrefixes: entry.localizedPrefixes\n ? Object.fromEntries(Object.entries(entry.localizedPrefixes).map(([l, p]) => [l, normalizePath(p) === '/' ? '' : normalizePath(p)]))\n : null,\n titleField: entry.titleField?.trim() || defaults.titleField,\n }\n}\n\n/** Applique les valeurs par défaut. Ne valide rien : voir `validateConfig`. */\nexport function resolveConfig(input: NcfKitConfig): ResolvedKitConfig {\n const slugField = input.slugField?.trim() || DEFAULT_SLUG_FIELD\n const titleField = input.titleField?.trim() || DEFAULT_TITLE_FIELD\n\n const pageTypes = (Array.isArray(input.pageTypes) ? input.pageTypes : []).map((entry) =>\n resolvePageType(entry, {slugField, titleField}),\n )\n\n const i18n =\n input.i18n === false || input.i18n === undefined\n ? null\n : (() => {\n const locales = (input.i18n.locales ?? DEFAULT_I18N.locales).map((l) => l.trim()).filter(Boolean)\n // Master : `defaultLocale`, sinon la première langue. Jamais une langue écrite\n // dans le kit (absente : signalé par validateConfig).\n const defaultLocale = input.i18n.defaultLocale?.trim() || locales[0] || ''\n return {\n field: input.i18n.field?.trim() || DEFAULT_I18N.field,\n defaultLocale,\n locales,\n // Valeurs par défaut des composants : écrites dans la langue master,\n // traduites vers les autres (sauf choix explicite du projet).\n defaultsSourceLocale: input.i18n.defaultsSourceLocale?.trim() || defaultLocale,\n }\n })()\n\n return {\n pageTypes,\n codedPages: (input.siteRoutes?.fixed ?? [])\n .filter((f) => f.pageSlug && !f.homePage && !f.system && !f.notFound)\n .map((f) => ({pageSlug: f.pageSlug as string, path: normalizePath(f.path), localized: f.localized ?? null})),\n redirectType: input.redirectType?.trim() || 'redirect',\n pageTypeNames: pageTypes.map((p) => p.type).filter(Boolean),\n pageBuilderField: input.pageBuilderField?.trim() || DEFAULT_PAGE_BUILDER_FIELD,\n blockNamespace: input.blockNamespace ?? DEFAULT_BLOCK_NAMESPACE,\n noindexFields: input.noindexField\n ? [input.noindexField].flat().map((field) => field.trim()).filter(Boolean)\n : DEFAULT_NOINDEX_FIELDS,\n previewUrl: input.previewUrl ? trimTrailingSlash(input.previewUrl.trim()) : null,\n environments: resolveEnvironments(input),\n pageThumbnail: input.pageThumbnail?.trim() || null,\n i18n,\n componentPreview: {\n provider: input.componentPreview?.provider ?? DEFAULT_COMPONENT_PREVIEW.provider,\n path: input.componentPreview?.path ?? DEFAULT_COMPONENT_PREVIEW.path,\n anchor: input.componentPreview?.anchor ?? DEFAULT_COMPONENT_PREVIEW.anchor,\n thumbnail: input.componentPreview?.thumbnail ?? DEFAULT_COMPONENT_PREVIEW.thumbnail,\n defaultsType: input.componentPreview?.defaultsType ?? DEFAULT_COMPONENT_PREVIEW.defaultsType,\n live: input.componentPreview?.live ?? DEFAULT_COMPONENT_PREVIEW.live,\n },\n serviceEndpoint:\n input.serviceEndpoint === false\n ? null\n : trimTrailingSlash((input.serviceEndpoint || DEFAULT_SERVICE_ENDPOINT).trim()),\n history: input.history?.projectKey?.trim()\n ? {\n projectKey: input.history.projectKey.trim(),\n endpoint: trimTrailingSlash(\n (input.history.endpoint || input.serviceEndpoint || DEFAULT_SERVICE_ENDPOINT).trim(),\n ),\n }\n : null,\n // Le JSON-LD IA s'appuie sur le même service que la traduction : sans\n // `history.projectKey`, il n'y a pas d'IA à brancher.\n jsonLd:\n input.jsonLd?.enabled && input.history?.projectKey?.trim()\n ? {field: input.jsonLd.field?.trim() || 'jsonLd'}\n : null,\n tools: {...DEFAULT_TOOLS, ...input.tools},\n moreTools: input.moreTools === false ? [] : (input.moreTools ?? DEFAULT_TOOLBAR_MORE),\n boardTags: input.boardTags?.length ? input.boardTags : DEFAULT_BOARD_TAGS,\n internalFields: input.internalFields?.length\n ? input.internalFields\n : DEFAULT_INTERNAL_FIELDS,\n // Additif : le schéma du client fournit déjà l'essentiel, ceci ne sert\n // qu'à ce qu'un parcours de schéma ne sait pas exprimer.\n documentColumns: (input.documentColumns ?? []).map((column) => ({\n key: column.key.trim(),\n label: column.label?.trim() || column.key.trim(),\n paths: [column.path].flat().map((path) => path.trim()).filter(Boolean),\n type: column.type ?? 'text',\n })),\n collections: {\n include: (input.collections?.include ?? []).map((name) => name.trim()).filter(Boolean),\n exclude: (input.collections?.exclude ?? []).map((name) => name.trim()).filter(Boolean),\n labels: input.collections?.labels ?? {},\n },\n }\n}\n\n\n/**\n * Préproduction déduite de la production, par convention.\n *\n * NoCode Factory assigne à chaque projet un domaine Vercel **fixe** pour la\n * branche `preprod`, de la forme `preview-<projet>.vercel.app`. Fixe parce\n * qu'un lien de partage doit survivre au commit suivant : une URL de\n * déploiement change à chaque poussée, un domaine assigné non.\n *\n * La déduire évite de la déclarer neuf fois. Elle n'est proposée que pour un\n * hôte Vercel — ailleurs la convention ne s'applique pas — et `environments`\n * la remplace dès qu'on la déclare explicitement.\n */\nexport function conventionalPreprodUrl(previewUrl: string | null): string | null {\n if (!previewUrl) return null\n try {\n const url = new URL(previewUrl)\n if (!url.hostname.endsWith('.vercel.app')) return null\n // Une préproduction ne se dérive pas d'une préproduction.\n if (url.hostname.startsWith('preview-')) return null\n return `${url.protocol}//preview-${url.hostname}`\n } catch {\n return null\n }\n}\n\n/**\n * Environnements d'aperçu.\n *\n * `previewUrl` en fournit toujours un, nommé « Production » : un projet qui\n * n'en déclare pas d'autres doit quand même pouvoir basculer entre brouillons\n * et contenu en ligne.\n *\n * Quand `environments` mentionne déjà `previewUrl`, on ne le double pas.\n */\nfunction resolveEnvironments(input: NcfKitConfig): NcfEnvironment[] {\n const declared = (input.environments ?? [])\n .map((environment) => ({\n id: environment.id.trim(),\n label: environment.label?.trim() || environment.id.trim(),\n url: trimTrailingSlash((environment.url ?? '').trim()),\n }))\n .filter((environment) => environment.id && environment.url)\n\n const preview = input.previewUrl ? trimTrailingSlash(input.previewUrl.trim()) : null\n if (!preview) return declared\n\n const production = declared.some((environment) => environment.url === preview)\n ? []\n : [{id: 'production', label: 'Production', url: preview}]\n\n // La préproduction conventionnelle complète la liste, sauf si le projet en\n // a déjà déclaré une — sa déclaration explicite fait foi.\n //\n // On compare l'identifiant autant que l'URL : un projet dont le domaine ne\n // suit pas exactement la convention déclare bien un `preprod`, à une autre\n // adresse. En n'écartant que par l'URL, on en ajoutait un second portant le\n // même identifiant, et la configuration devenait invalide.\n const conventional = conventionalPreprodUrl(preview)\n const hasPreprod =\n declared.some(\n (environment) => environment.url === conventional || environment.id === 'preprod',\n ) || input.preprodUrl === false\n\n const preprod =\n conventional && !hasPreprod\n ? [{id: 'preprod', label: 'Staging', url: conventional}]\n : []\n\n return [...production, ...preprod, ...declared]\n}\n","import {normalizePath} from '../config/resolve'\nimport type {ResolvedI18n, ResolvedPageType} from '../config/types'\n\nexport interface PathInput {\n /** Valeur du champ slug (`slug.current`). Peut contenir des `/`. */\n slug?: string | null\n /** Chemin fixe du type de page, s'il en a un. */\n path?: string | null\n /** Préfixe d'URL du type de page ('/blog'), devant le slug. */\n pathPrefix?: string | null\n /** Préfixe par langue (dossiers traduits) : celui de `locale` gagne sur `pathPrefix`. */\n localizedPrefixes?: Record<string, string> | null\n /** Langue du document. */\n locale?: string | null\n}\n\n/**\n * Chemin d'une page sur le site. Le chemin fixe l'emporte sur le slug, le\n * préfixe du type se place devant le slug ('/blog' + 'mon-article'), et la\n * langue par défaut n'est pas préfixée (convention Next.js du starter).\n */\nexport function toPath(input: PathInput, i18n: ResolvedI18n | null): string | null {\n const localized = input.locale ? input.localizedPrefixes?.[input.locale] : undefined\n const raw = localized !== undefined ? localized : input.pathPrefix\n const prefix = typeof raw === 'string' && raw ? normalizePath(raw) : '/'\n const base =\n typeof input.path === 'string' && input.path\n ? normalizePath(input.path)\n : input.slug\n ? normalizePath(prefix === '/' ? input.slug : `${prefix}/${input.slug.replace(/^\\/+/, '')}`)\n : null\n\n if (base === null) return null\n if (!i18n || !input.locale || input.locale === i18n.defaultLocale) return base\n return base === '/' ? `/${input.locale}` : `/${input.locale}${base}`\n}\n\n/** URL absolue d'une page, ou `null` si le front n'est pas configuré. */\nexport function toUrl(previewUrl: string | null, path: string | null): string | null {\n if (!previewUrl || path === null) return null\n return path === '/' ? previewUrl : `${previewUrl}${path}`\n}\n\n/** Segments d'un chemin : '/services/plomberie' -> ['services', 'plomberie']. */\nexport function segments(path: string): string[] {\n return path.split('/').filter(Boolean)\n}\n\n/** Profondeur dans l'arborescence. '/' vaut 0. */\nexport function depth(path: string): number {\n return segments(path).length\n}\n\n/**\n * Chemin du parent, ou `null` à la racine. Sert au placement automatique du\n * board : '/services/plomberie' -> '/services'.\n */\nexport function parentPath(path: string): string | null {\n const parts = segments(path)\n if (parts.length === 0) return null\n if (parts.length === 1) return '/'\n return `/${parts.slice(0, -1).join('/')}`\n}\n\n/** Le type de page correspondant à un document. */\nexport function pageTypeFor(\n type: string,\n pageTypes: ResolvedPageType[],\n): ResolvedPageType | undefined {\n return pageTypes.find((p) => p.type === type)\n}\n","import type {ResolvedKitConfig, ResolvedPageType} from '../config/types'\nimport {toPath} from './paths'\n\n/** Clé de comparaison des redirections (comme le site) : minuscules, sans « / » final, sans ? ni #. */\nexport const redirectKey = (path: string) => {\n const clean = (path.trim().split(/[?#]/)[0] ?? '').toLowerCase()\n return clean.length > 1 ? clean.replace(/\\/+$/, '') : clean\n}\n\n/** Table des redirections du Studio : départ (normalisé) -> destination. */\nexport type RedirectMap = Map<string, string>\n\nexport function redirectMapOf(rows: readonly {from?: string | null; to?: string | null}[]): RedirectMap {\n const map: RedirectMap = new Map()\n for (const r of rows) {\n if (!r.from?.startsWith('/') || !r.to) continue\n const key = redirectKey(r.from)\n if (key !== redirectKey(r.to) && !map.has(key)) map.set(key, r.to.trim())\n }\n return map\n}\n\n/** Destination finale d'une adresse (chaîne de redirections suivie, boucles ignorées). */\nexport function followRedirects(path: string, redirects: RedirectMap | null | undefined): string {\n if (!redirects?.size) return path\n let current = path\n const seen = new Set<string>()\n for (let hop = 0; hop < 5; hop++) {\n const next = redirects.get(redirectKey(current))\n if (!next || seen.has(next)) break\n seen.add(next)\n current = next\n }\n return current\n}\n\n/**\n * URL FINALE d'une page (celle qui répond 200, sans redirection) : adresse réelle\n * d'une page codée (registre `siteRoutes`, dossier de la langue), sinon dossier et\n * slug de la langue ; puis destination si l'adresse est le départ d'une redirection\n * du Studio. Affichée partout dans le kit (onglet Pages, board, Presentation, slug).\n */\nexport function finalPath(\n input: {slug: string | null; locale: string | null},\n pageType: ResolvedPageType | null | undefined,\n config: Pick<ResolvedKitConfig, 'i18n' | 'codedPages'>,\n redirects?: RedirectMap | null,\n): string | null {\n if (!pageType) return null\n const atRoot = !pageType.path && !pageType.pathPrefix && !pageType.localizedPrefixes\n const coded = atRoot && input.slug ? config.codedPages.find((c) => c.pageSlug === input.slug) : undefined\n const path = coded\n ? toPath({path: (input.locale && coded.localized?.[input.locale]) || coded.path, locale: input.locale}, config.i18n)\n : toPath(\n {slug: input.slug, path: pageType.path, pathPrefix: pageType.pathPrefix, localizedPrefixes: pageType.localizedPrefixes, locale: input.locale},\n config.i18n,\n )\n return path === null ? null : followRedirects(path, redirects)\n}\n"],"mappings":"AAQA,MAAa,6BAA6B,YAC7B,qBAAqB,QACrB,sBAAsB,SAQtB,yBAAyB,CAAC,eAAe,SAAS,GAKlD,eAAwF;CACnG,OAAO;CACP,SAAS,CAAC;AACZ,GAMa,4BAAiE;CAC5E,UAAU;CACV,MAAM;CACN,QAAQ;CACR,WAAW;CACX,cAAc;CACd,MAAM;AACR,GAEa,gBAA0C;CACrD,OAAO;CACP,YAAY;CACZ,SAAS;CACT,cAAc;CACd,QAAQ;AACV,GAOa,uBAAuB;CAAC;CAAU;CAAY;AAAW,GAOzD,qBAAoC;CAC/C;EAAC,IAAI;EAAY,OAAO;EAAe,OAAO;CAAS;CACvD;EAAC,IAAI;EAAQ,OAAO;EAAQ,OAAO;CAAS;CAC5C;EAAC,IAAI;EAAY,OAAO;EAAa,OAAO;CAAS;CACrD;EAAC,IAAI;EAAc,OAAO;EAAa,OAAO;CAAS;AACzD,GAOa,0BAA8C;CACzD;EAAC,IAAI;EAAS,OAAO;EAAS,MAAM;CAAM;CAC1C;EAAC,IAAI;EAAY,OAAO;EAAY,MAAM;CAAM;CAChD;EAAC,IAAI;EAAQ,OAAO;EAAa,MAAM;CAAM;AAC/C,GCxDM,qBAAqB,QAAgB,IAAI,QAAQ,QAAQ,EAAE,GAGpD,iBAAiB,SAAyB;CACrD,IAAM,UAAU,KAAK,KAAK;CAC1B,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