@nocode-factory/sanity-kit 2.70.2 → 2.71.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/{finalUrl-DYyjKCjh.js → finalUrl-D-rEV9jn.js} +6 -1
- package/dist/finalUrl-D-rEV9jn.js.map +1 -0
- package/dist/{fixCrossLanguageReferences-C4A61VWW.js → fixCrossLanguageReferences-C2WQFnlM.js} +2 -2
- package/dist/{fixCrossLanguageReferences-C4A61VWW.js.map → fixCrossLanguageReferences-C2WQFnlM.js.map} +1 -1
- package/dist/{fixCrossLanguageReferences-CfFDSTD5.d.ts → fixCrossLanguageReferences-rqwx8yPd.d.ts} +35 -1
- package/dist/index.d.ts +17 -2
- package/dist/index.js +295 -12
- 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 +7 -0
- package/src/config/types.ts +37 -0
- package/src/index.ts +1 -0
- package/src/structure/toolLinkItem.tsx +43 -0
- package/src/tools/navbar/PreviewLauncher.tsx +2 -2
- package/src/tools/navbar/ToolButtons.tsx +180 -4
- package/src/tools/presentation/PagesNavigator.tsx +53 -3
- package/src/version.ts +1 -1
- package/dist/finalUrl-DYyjKCjh.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-D-rEV9jn.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-rqwx8yPd.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-D-rEV9jn.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-C2WQFnlM.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
|
@@ -139,6 +139,13 @@ export function resolveConfig(input: NcfKitConfig): ResolvedKitConfig {
|
|
|
139
139
|
: null,
|
|
140
140
|
tools: {...DEFAULT_TOOLS, ...input.tools},
|
|
141
141
|
moreTools: input.moreTools === false ? [] : (input.moreTools ?? DEFAULT_TOOLBAR_MORE),
|
|
142
|
+
navigation: input.navigation?.grouped
|
|
143
|
+
? {
|
|
144
|
+
settingsTool: input.navigation.settingsTool || 'settings',
|
|
145
|
+
settingsItems: input.navigation.settingsItems ?? [],
|
|
146
|
+
newPageType: input.navigation.newPageType || 'page',
|
|
147
|
+
}
|
|
148
|
+
: null,
|
|
142
149
|
boardTags: input.boardTags?.length ? input.boardTags : DEFAULT_BOARD_TAGS,
|
|
143
150
|
internalFields: input.internalFields?.length
|
|
144
151
|
? input.internalFields
|
package/src/config/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {ComponentType} from 'react'
|
|
1
2
|
/**
|
|
2
3
|
* Configuration publique du plugin. Tout est optionnel sauf `pageTypes` :
|
|
3
4
|
* le kit ne doit rien savoir du contenu d'un projet client.
|
|
@@ -258,6 +259,13 @@ export interface NcfKitConfig {
|
|
|
258
259
|
* (« Scheduled drafts » / Releases, nom d'outil `releases`). `false` : aucun.
|
|
259
260
|
*/
|
|
260
261
|
moreTools?: string[] | false
|
|
262
|
+
/**
|
|
263
|
+
* Navigation regroupée de la barre du Studio (kit >= 2.71.0), ÉTEINTE par défaut :
|
|
264
|
+
* Presentation, Pages, CMS en onglets, puis les menus Settings (réglages du projet,
|
|
265
|
+
* History, planification) et Design (Components, Assets, Design system) ; « ··· »
|
|
266
|
+
* garde les outils techniques restants (Vision). Allumée dans le starter.
|
|
267
|
+
*/
|
|
268
|
+
navigation?: NcfNavigationConfig
|
|
261
269
|
/**
|
|
262
270
|
* Étiquettes de suivi du board. Remplacent entièrement les valeurs par
|
|
263
271
|
* défaut quand elles sont fournies.
|
|
@@ -343,6 +351,8 @@ export interface ResolvedKitConfig {
|
|
|
343
351
|
tools: Required<NcfToolsConfig>
|
|
344
352
|
/** Outils rangés dans le menu « Plus » de la barre (noms d'outils). */
|
|
345
353
|
moreTools: string[]
|
|
354
|
+
/** `null` = barre d'origine (un bouton par outil). */
|
|
355
|
+
navigation: ResolvedNavigation | null
|
|
346
356
|
boardTags: NcfBoardTag[]
|
|
347
357
|
internalFields: NcfInternalField[]
|
|
348
358
|
documentColumns: ResolvedDocumentColumn[]
|
|
@@ -399,3 +409,30 @@ export interface KitContextValue {
|
|
|
399
409
|
config: ResolvedKitConfig
|
|
400
410
|
issues: ConfigIssue[]
|
|
401
411
|
}
|
|
412
|
+
|
|
413
|
+
/** Une entrée « réglage » du menu Settings : un volet de l'outil de réglages. */
|
|
414
|
+
export interface NcfSettingsItem {
|
|
415
|
+
/** Id de l'élément dans la structure de l'outil de réglages (chemin `/<outil>/<id>`). */
|
|
416
|
+
id: string
|
|
417
|
+
title: string
|
|
418
|
+
/** Une ligne sous le titre (ce qu'on y règle). */
|
|
419
|
+
hint?: string
|
|
420
|
+
icon?: ComponentType
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface NcfNavigationConfig {
|
|
424
|
+
/** Allume la navigation regroupée. */
|
|
425
|
+
grouped?: boolean
|
|
426
|
+
/** Outil de structure des réglages (nom de l'outil), par défaut `settings`. */
|
|
427
|
+
settingsTool?: string
|
|
428
|
+
/** Entrées de réglages en tête du menu Settings (Company, SEO defaults, Redirects…). */
|
|
429
|
+
settingsItems?: NcfSettingsItem[]
|
|
430
|
+
/** Type de page créé par « New page » dans Presentation, par défaut `page`. */
|
|
431
|
+
newPageType?: string
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export interface ResolvedNavigation {
|
|
435
|
+
settingsTool: string
|
|
436
|
+
settingsItems: NcfSettingsItem[]
|
|
437
|
+
newPageType: string
|
|
438
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -310,6 +310,7 @@ export {useKitConfig, useKitContext, useOptionalKitConfig, useOptionalKitContext
|
|
|
310
310
|
export {toPath, toUrl, segments, depth, parentPath, pageTypeFor} from './lib/paths'
|
|
311
311
|
export {pageTypesFromSiteRoutes, type SiteRoutesRegistry} from './lib/siteRoutes'
|
|
312
312
|
export {withMoreTool, NCF_MORE_TOOL, DEFAULT_MORE_TOOLS} from './tools/more/MoreTool'
|
|
313
|
+
export {ncfToolLinkItem} from './structure/toolLinkItem'
|
|
313
314
|
export {
|
|
314
315
|
buildPageRows,
|
|
315
316
|
formatDocumentValue,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {useEffect, type ComponentType} from 'react'
|
|
2
|
+
import {Flex, Spinner, Text} from '@sanity/ui'
|
|
3
|
+
import {useWorkspace} from 'sanity'
|
|
4
|
+
import {useRouter} from 'sanity/router'
|
|
5
|
+
import type {ListItemBuilder, StructureBuilder} from 'sanity/structure'
|
|
6
|
+
|
|
7
|
+
/** Volet qui ouvre aussitôt un outil du Studio (History, Releases…). */
|
|
8
|
+
function OpenToolPane(props: {options?: {tool?: string; title?: string}}) {
|
|
9
|
+
const tool = props.options?.tool ?? ''
|
|
10
|
+
const router = useRouter()
|
|
11
|
+
const {basePath} = useWorkspace()
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (tool) router.navigateUrl({path: `${basePath.replace(/\/$/, '')}/${tool}`, replace: true})
|
|
14
|
+
}, [router, basePath, tool])
|
|
15
|
+
return (
|
|
16
|
+
<Flex align="center" justify="center" gap={3} padding={5}>
|
|
17
|
+
<Spinner muted />
|
|
18
|
+
<Text size={1} muted>
|
|
19
|
+
Opening {props.options?.title ?? tool}…
|
|
20
|
+
</Text>
|
|
21
|
+
</Flex>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Entrée de structure qui OUVRE un outil du Studio (navigation regroupée : History et
|
|
27
|
+
* Releases dans la colonne de Settings, comme dans le menu Settings de la barre). Un
|
|
28
|
+
* outil ne s'affiche pas dans une colonne : un clic ouvre l'outil, en pleine page.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* ncfToolLinkItem(S, {id: 'history', title: 'History', tool: 'ncf-history'})
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function ncfToolLinkItem(
|
|
35
|
+
S: StructureBuilder,
|
|
36
|
+
options: {id: string; title: string; tool: string; icon?: ComponentType},
|
|
37
|
+
): ListItemBuilder {
|
|
38
|
+
const item = S.listItem()
|
|
39
|
+
.id(options.id)
|
|
40
|
+
.title(options.title)
|
|
41
|
+
.child(S.component(OpenToolPane as never).id(`${options.id}-open`).title(options.title).options({tool: options.tool, title: options.title}))
|
|
42
|
+
return options.icon ? item.icon(options.icon) : item
|
|
43
|
+
}
|
|
@@ -44,7 +44,7 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
|
|
|
44
44
|
if (environments.length === 0) {
|
|
45
45
|
return (
|
|
46
46
|
<Flex align="center" gap={2}>
|
|
47
|
-
<NcfToolButtons {...props} more={config.moreTools} />
|
|
47
|
+
<NcfToolButtons {...props} more={config.moreTools} navigation={config.navigation} />
|
|
48
48
|
{topbar && <NcfKitUpdate inline />}
|
|
49
49
|
</Flex>
|
|
50
50
|
)
|
|
@@ -83,7 +83,7 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
|
|
|
83
83
|
direction={inline ? 'row' : 'column'}
|
|
84
84
|
gap={inline ? 2 : 1}
|
|
85
85
|
>
|
|
86
|
-
<NcfToolButtons {...props} more={config.moreTools} />
|
|
86
|
+
<NcfToolButtons {...props} more={config.moreTools} navigation={config.navigation} />
|
|
87
87
|
|
|
88
88
|
{inline && <NcfKitUpdate inline />}
|
|
89
89
|
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import {forwardRef, useCallback, useMemo, type ComponentProps, type ReactNode} from 'react'
|
|
2
|
-
import {ToolLink, type Tool, type ToolMenuProps} from 'sanity'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import {ToolLink, useWorkspace, type Tool, type ToolMenuProps} from 'sanity'
|
|
3
|
+
import {useRouter} from 'sanity/router'
|
|
4
|
+
import {Box, Button, Flex, Stack, Text} from '@sanity/ui'
|
|
5
|
+
import {Menu, MenuButton, MenuDivider, MenuItem} from '@sanity/ui/menu'
|
|
5
6
|
import {EllipsisHorizontalIcon} from '@sanity/icons/EllipsisHorizontal'
|
|
7
|
+
import {CogIcon} from '@sanity/icons/Cog'
|
|
8
|
+
import {ComponentIcon} from '@sanity/icons/Component'
|
|
9
|
+
import {ChevronDownIcon} from '@sanity/icons/ChevronDown'
|
|
10
|
+
import type {ResolvedNavigation} from '../../config/types'
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Sépare les outils de la barre : ceux du quotidien restent en boutons, les outils
|
|
@@ -29,7 +34,12 @@ const ToolAnchor = forwardRef<HTMLAnchorElement, Omit<ComponentProps<typeof Tool
|
|
|
29
34
|
* system »), les outils techniques (Vision, planification) dans « Plus ». Dans le
|
|
30
35
|
* volet latéral (mobile), tout est listé.
|
|
31
36
|
*/
|
|
32
|
-
export function NcfToolButtons(props: ToolMenuProps & {more: string[]}) {
|
|
37
|
+
export function NcfToolButtons(props: ToolMenuProps & {more: string[]; navigation?: ResolvedNavigation | null}) {
|
|
38
|
+
if (props.navigation) return <NcfGroupedToolButtons {...props} navigation={props.navigation} />
|
|
39
|
+
return <NcfFlatToolButtons {...props} />
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function NcfFlatToolButtons(props: ToolMenuProps & {more: string[]}) {
|
|
33
43
|
const {activeToolName, context, tools, closeSidebar, isSidebarOpen, more: moreNames} = props
|
|
34
44
|
const [main, more] = useMemo(() => splitTools(tools, moreNames), [tools, moreNames])
|
|
35
45
|
const isSidebar = context === 'sidebar'
|
|
@@ -85,3 +95,169 @@ export function NcfToolButtons(props: ToolMenuProps & {more: string[]}) {
|
|
|
85
95
|
</Flex>
|
|
86
96
|
)
|
|
87
97
|
}
|
|
98
|
+
|
|
99
|
+
/** Outils du menu Design (navigation regroupée), dans cet ordre. */
|
|
100
|
+
export const NAV_DESIGN_TOOLS = ['ncf-components', 'ncf-assets', 'ncf-design-system']
|
|
101
|
+
/**
|
|
102
|
+
* Outils ajoutés au menu Settings après les réglages : historique et planification
|
|
103
|
+
* (Releases / Scheduled drafts). L'ancien outil « Schedules » reste dans « ··· ».
|
|
104
|
+
*/
|
|
105
|
+
export const NAV_SETTINGS_TOOLS = ['ncf-history', 'releases']
|
|
106
|
+
/** Onglets du quotidien, dans cet ordre (le CMS = l'outil de structure). */
|
|
107
|
+
export const NAV_MAIN_TOOLS = ['presentation', 'ncf-pages', 'structure']
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Répartit les outils de la navigation regroupée : onglets (Presentation, Pages,
|
|
111
|
+
* CMS, puis les outils non classés), Settings, Design, « ··· » (outils techniques).
|
|
112
|
+
* L'outil des réglages lui-même n'a pas d'onglet : on y entre par le menu Settings.
|
|
113
|
+
*/
|
|
114
|
+
export function groupTools<T extends {name: string}>(
|
|
115
|
+
tools: T[],
|
|
116
|
+
more: string[],
|
|
117
|
+
settingsTool: string,
|
|
118
|
+
): {main: T[]; settings: T[]; design: T[]; more: T[]} {
|
|
119
|
+
const byName = (names: string[]) => names.map((n) => tools.find((t) => t.name === n)).filter((t): t is T => Boolean(t))
|
|
120
|
+
const classed = new Set([...NAV_MAIN_TOOLS, ...NAV_DESIGN_TOOLS, ...NAV_SETTINGS_TOOLS, ...more, settingsTool])
|
|
121
|
+
return {
|
|
122
|
+
main: [...byName(NAV_MAIN_TOOLS), ...tools.filter((t) => !classed.has(t.name))],
|
|
123
|
+
settings: byName(NAV_SETTINGS_TOOLS),
|
|
124
|
+
design: byName(NAV_DESIGN_TOOLS),
|
|
125
|
+
more: tools.filter((t) => more.includes(t.name) && !NAV_SETTINGS_TOOLS.includes(t.name)),
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Une entrée de menu qui est un lien (ToolLink) ne se souligne pas. */
|
|
130
|
+
const NO_UNDERLINE = {textDecoration: 'none'} as const
|
|
131
|
+
|
|
132
|
+
/** Libellé d'un outil : son titre, ou son nom. */
|
|
133
|
+
const titleOf = (tool: Tool) => (typeof tool.title === 'string' && tool.title) || tool.name
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Navigation regroupée (option `navigation.grouped`) : Presentation, Pages, CMS en
|
|
137
|
+
* onglets ; Settings (réglages du projet, History, planification) et Design
|
|
138
|
+
* (Components, Assets, Design system) en menus ; « ··· » pour les outils techniques.
|
|
139
|
+
* Dans le volet latéral (fenêtre étroite) : les mêmes groupes, à plat.
|
|
140
|
+
*/
|
|
141
|
+
function NcfGroupedToolButtons(props: ToolMenuProps & {more: string[]; navigation: ResolvedNavigation}) {
|
|
142
|
+
const {activeToolName, context, tools, closeSidebar, isSidebarOpen, more: moreNames, navigation} = props
|
|
143
|
+
const router = useRouter()
|
|
144
|
+
const {basePath} = useWorkspace()
|
|
145
|
+
const groups = useMemo(() => groupTools(tools, moreNames, navigation.settingsTool), [tools, moreNames, navigation.settingsTool])
|
|
146
|
+
const settingsToolPresent = tools.some((t) => t.name === navigation.settingsTool)
|
|
147
|
+
const items = settingsToolPresent ? navigation.settingsItems : []
|
|
148
|
+
const isSidebar = context === 'sidebar'
|
|
149
|
+
const onClick = useCallback(() => {
|
|
150
|
+
if (isSidebar && isSidebarOpen) closeSidebar()
|
|
151
|
+
}, [closeSidebar, isSidebar, isSidebarOpen])
|
|
152
|
+
const openSetting = useCallback(
|
|
153
|
+
(id: string) => {
|
|
154
|
+
router.navigateUrl({path: `${basePath.replace(/\/$/, '')}/${navigation.settingsTool}/${id}`})
|
|
155
|
+
onClick()
|
|
156
|
+
},
|
|
157
|
+
[router, basePath, navigation.settingsTool, onClick],
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
const button = (tool: Tool) => (
|
|
161
|
+
<Button
|
|
162
|
+
key={tool.name}
|
|
163
|
+
as={ToolAnchor}
|
|
164
|
+
name={tool.name}
|
|
165
|
+
icon={tool.icon}
|
|
166
|
+
text={titleOf(tool)}
|
|
167
|
+
mode="bleed"
|
|
168
|
+
selected={activeToolName === tool.name}
|
|
169
|
+
justify={isSidebar ? 'flex-start' : undefined}
|
|
170
|
+
onClick={onClick}
|
|
171
|
+
fontSize={1}
|
|
172
|
+
padding={3}
|
|
173
|
+
/>
|
|
174
|
+
)
|
|
175
|
+
const toolItem = (tool: Tool) => (
|
|
176
|
+
<MenuItem key={tool.name} as={ToolAnchor} name={tool.name} icon={tool.icon} text={titleOf(tool)} pressed={activeToolName === tool.name} style={NO_UNDERLINE} />
|
|
177
|
+
)
|
|
178
|
+
const settingItem = (item: (typeof items)[number]) => (
|
|
179
|
+
<MenuItem key={item.id} icon={item.icon} onClick={() => openSetting(item.id)} pressed={activeToolName === navigation.settingsTool}>
|
|
180
|
+
<Stack gap={2}>
|
|
181
|
+
<Text size={1}>{item.title}</Text>
|
|
182
|
+
{item.hint ? (
|
|
183
|
+
<Text size={0} muted>
|
|
184
|
+
{item.hint}
|
|
185
|
+
</Text>
|
|
186
|
+
) : null}
|
|
187
|
+
</Stack>
|
|
188
|
+
</MenuItem>
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
const settingsActive = activeToolName === navigation.settingsTool || groups.settings.some((t) => t.name === activeToolName)
|
|
192
|
+
const designActive = groups.design.some((t) => t.name === activeToolName)
|
|
193
|
+
|
|
194
|
+
if (isSidebar) {
|
|
195
|
+
const heading = (label: string) => (
|
|
196
|
+
<Box paddingX={3} paddingTop={3} paddingBottom={1}>
|
|
197
|
+
<Text size={0} muted weight="medium">
|
|
198
|
+
{label}
|
|
199
|
+
</Text>
|
|
200
|
+
</Box>
|
|
201
|
+
)
|
|
202
|
+
return (
|
|
203
|
+
<Stack gap={1}>
|
|
204
|
+
{groups.main.map(button)}
|
|
205
|
+
{items.length + groups.settings.length > 0 && heading('Settings')}
|
|
206
|
+
{items.map((item) => (
|
|
207
|
+
<Button key={item.id} icon={item.icon} text={item.title} mode="bleed" justify="flex-start" fontSize={1} padding={3} onClick={() => openSetting(item.id)} />
|
|
208
|
+
))}
|
|
209
|
+
{groups.settings.map(button)}
|
|
210
|
+
{groups.design.length > 0 && heading('Design')}
|
|
211
|
+
{groups.design.map(button)}
|
|
212
|
+
{groups.more.length > 0 && heading('More')}
|
|
213
|
+
{groups.more.map(button)}
|
|
214
|
+
</Stack>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const dropdown = (id: string, label: string, icon: typeof CogIcon, selected: boolean, menu: ReactNode) => (
|
|
219
|
+
<MenuButton
|
|
220
|
+
id={id}
|
|
221
|
+
button={<Button icon={icon} iconRight={ChevronDownIcon} text={label} mode="bleed" fontSize={1} padding={3} selected={selected} />}
|
|
222
|
+
menu={<Menu>{menu}</Menu>}
|
|
223
|
+
popover={{portal: true, placement: 'bottom-start'}}
|
|
224
|
+
/>
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<Flex gap={1} align="center">
|
|
229
|
+
{groups.main.map(button)}
|
|
230
|
+
{items.length + groups.settings.length > 0 &&
|
|
231
|
+
dropdown(
|
|
232
|
+
'ncf-tool-menu-settings',
|
|
233
|
+
'Settings',
|
|
234
|
+
CogIcon,
|
|
235
|
+
settingsActive,
|
|
236
|
+
<>
|
|
237
|
+
{items.map(settingItem)}
|
|
238
|
+
{items.length > 0 && groups.settings.length > 0 && <MenuDivider />}
|
|
239
|
+
{groups.settings.map(toolItem)}
|
|
240
|
+
</>,
|
|
241
|
+
)}
|
|
242
|
+
{groups.design.length > 0 && dropdown('ncf-tool-menu-design', 'Design', ComponentIcon, designActive, <>{groups.design.map(toolItem)}</>)}
|
|
243
|
+
{groups.more.length > 0 && (
|
|
244
|
+
<MenuButton
|
|
245
|
+
id="ncf-tool-menu-more"
|
|
246
|
+
button={
|
|
247
|
+
<Button
|
|
248
|
+
icon={EllipsisHorizontalIcon}
|
|
249
|
+
mode="bleed"
|
|
250
|
+
fontSize={1}
|
|
251
|
+
padding={3}
|
|
252
|
+
selected={groups.more.some((t) => t.name === activeToolName)}
|
|
253
|
+
title={`Technical tools (${groups.more.map(titleOf).join(', ')})`}
|
|
254
|
+
aria-label="More tools"
|
|
255
|
+
/>
|
|
256
|
+
}
|
|
257
|
+
menu={<Menu>{groups.more.map(toolItem)}</Menu>}
|
|
258
|
+
popover={{portal: true, placement: 'bottom-end'}}
|
|
259
|
+
/>
|
|
260
|
+
)}
|
|
261
|
+
</Flex>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
@@ -7,6 +7,9 @@ import {useSchema} from 'sanity'
|
|
|
7
7
|
import {SearchIcon} from '@sanity/icons/Search'
|
|
8
8
|
import {DragHandleIcon} from '@sanity/icons/DragHandle'
|
|
9
9
|
import {usePresentationNavigate, usePresentationParams} from 'sanity/presentation'
|
|
10
|
+
import {useRouter} from 'sanity/router'
|
|
11
|
+
import {Menu, MenuButton, MenuItem} from '@sanity/ui/menu'
|
|
12
|
+
import {AddIcon} from '@sanity/icons/Add'
|
|
10
13
|
import type {NcfKitConfig} from '../../config/types'
|
|
11
14
|
import {resolveConfig} from '../../config/resolve'
|
|
12
15
|
import {validateConfig} from '../../config/validate'
|
|
@@ -184,9 +187,12 @@ function PagesNavigator() {
|
|
|
184
187
|
return (
|
|
185
188
|
<Card height="fill" borderRight style={{display: 'flex', flexDirection: 'column', minHeight: 0}}>
|
|
186
189
|
<Stack gap={2} padding={2} style={{flex: 'none'}}>
|
|
187
|
-
<
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
<Flex align="center" justify="space-between" gap={2}>
|
|
191
|
+
<Text size={1} weight="semibold">
|
|
192
|
+
Pages
|
|
193
|
+
</Text>
|
|
194
|
+
{config.navigation && <NewPageButton type={config.navigation.newPageType} locales={i18n?.locales ?? []} />}
|
|
195
|
+
</Flex>
|
|
190
196
|
<TextInput
|
|
191
197
|
icon={SearchIcon}
|
|
192
198
|
fontSize={1}
|
|
@@ -298,3 +304,47 @@ export function ncfPresentationComponents(options: NcfKitConfig): {
|
|
|
298
304
|
unstable_header: {component: NcfPresentationHeader},
|
|
299
305
|
}
|
|
300
306
|
}
|
|
307
|
+
|
|
308
|
+
/** Nom d'une langue dans cette langue (« Français », « English »), sinon son code. */
|
|
309
|
+
function languageName(code: string): string {
|
|
310
|
+
try {
|
|
311
|
+
const name = new Intl.DisplayNames([code], {type: 'language'}).of(code)
|
|
312
|
+
return name ? name.charAt(0).toLocaleUpperCase(code) + name.slice(1) : code.toUpperCase()
|
|
313
|
+
} catch {
|
|
314
|
+
return code.toUpperCase()
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* « New page » du panneau Pages de Presentation (navigation regroupée) : ouvre le
|
|
320
|
+
* formulaire d'une nouvelle page, dans la langue choisie (modèle `<type>-<langue>`,
|
|
321
|
+
* le document naît avec son champ language). Une seule langue : un bouton direct.
|
|
322
|
+
*/
|
|
323
|
+
function NewPageButton(props: {type: string; locales: string[]}) {
|
|
324
|
+
const {type, locales} = props
|
|
325
|
+
const router = useRouter()
|
|
326
|
+
const schema = useSchema()
|
|
327
|
+
const schemaType = schema.get(type) as {title?: string; icon?: ComponentType} | undefined
|
|
328
|
+
if (!schemaType) return null
|
|
329
|
+
const label = schemaType.title || type
|
|
330
|
+
const create = (locale?: string) =>
|
|
331
|
+
router.navigateIntent('create', locale ? {type, template: `${type}-${locale}`} : {type})
|
|
332
|
+
|
|
333
|
+
if (locales.length <= 1) {
|
|
334
|
+
return <Button icon={AddIcon} text="New page" mode="ghost" tone="primary" fontSize={1} padding={2} onClick={() => create(locales[0])} />
|
|
335
|
+
}
|
|
336
|
+
return (
|
|
337
|
+
<MenuButton
|
|
338
|
+
id="ncf-presentation-new-page"
|
|
339
|
+
button={<Button icon={AddIcon} text="New page" mode="ghost" tone="primary" fontSize={1} padding={2} />}
|
|
340
|
+
menu={
|
|
341
|
+
<Menu>
|
|
342
|
+
{locales.map((code) => (
|
|
343
|
+
<MenuItem key={code} icon={schemaType.icon} text={`${label} (${languageName(code)})`} onClick={() => create(code)} />
|
|
344
|
+
))}
|
|
345
|
+
</Menu>
|
|
346
|
+
}
|
|
347
|
+
popover={{portal: true, placement: 'bottom-end'}}
|
|
348
|
+
/>
|
|
349
|
+
)
|
|
350
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"finalUrl-DYyjKCjh.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 collectionLabels: Object.fromEntries((input.siteRoutes?.collections ?? []).filter((c) => c.type && c.section).map((c) => [c.type as string, c.section as string])),\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;E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