@nocode-factory/sanity-kit 2.53.0 → 2.54.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/README.md +31 -0
- package/dist/{finalUrl-CaFXmYvm.js → finalUrl-IXF3zbT9.js} +7 -2
- package/dist/finalUrl-IXF3zbT9.js.map +1 -0
- package/dist/{fixCrossLanguageReferences-w3whO9xM.d.ts → fixCrossLanguageReferences-C1VsmGsJ.d.ts} +21 -2
- package/dist/{fixCrossLanguageReferences-BeXywAAU.js → fixCrossLanguageReferences-CDczoic9.js} +2 -2
- package/dist/{fixCrossLanguageReferences-BeXywAAU.js.map → fixCrossLanguageReferences-CDczoic9.js.map} +1 -1
- package/dist/index.d.ts +173 -7
- package/dist/index.js +715 -26
- 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 +5 -0
- package/src/config/types.ts +21 -0
- package/src/hooks/useCollection.ts +51 -0
- package/src/index.ts +18 -0
- package/src/lib/collectionColumns.ts +114 -0
- package/src/lib/collectionQuery.ts +23 -0
- package/src/lib/collectionRows.ts +92 -0
- package/src/lib/collectionTable.ts +72 -0
- package/src/lib/collectionTypes.ts +49 -0
- package/src/lib/csv.ts +24 -0
- package/src/lib/download.ts +24 -0
- package/src/lib/schemaColumns.ts +18 -5
- package/src/structure/collections.tsx +103 -0
- package/src/tools/collections/CollectionColumnPicker.tsx +122 -0
- package/src/tools/collections/CollectionTable.tsx +259 -0
- package/src/tools/collections/CollectionToolbar.tsx +68 -0
- package/src/version.ts +1 -1
- package/dist/finalUrl-CaFXmYvm.js.map +0 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {Box} from '@sanity/ui'
|
|
2
|
+
import type {StructureBuilder, StructureResolverContext, ListItemBuilder, UserComponent} from 'sanity/structure'
|
|
3
|
+
import {KitProvider} from '../context/KitContext'
|
|
4
|
+
import {resolveConfig} from '../config/resolve'
|
|
5
|
+
import {validateConfig} from '../config/validate'
|
|
6
|
+
import {CollectionTable} from '../tools/collections/CollectionTable'
|
|
7
|
+
import {discoverCollectionTypes, type SchemaTypeInfo} from '../lib/collectionTypes'
|
|
8
|
+
import {humanise} from '../lib/schemaColumns'
|
|
9
|
+
import {NCF_HIDDEN_TYPES} from '../schema/boardLayout'
|
|
10
|
+
import type {ConfigIssue, NcfKitConfig, ResolvedKitConfig} from '../config/types'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Composant de panneau pour une collection. Le type arrive par les `options`
|
|
14
|
+
* du pane de structure ; la configuration est fermée par la fabrique (elle
|
|
15
|
+
* n'est pas sérialisable dans les options).
|
|
16
|
+
*/
|
|
17
|
+
function createCollectionPane(config: ResolvedKitConfig, issues: ConfigIssue[]): UserComponent {
|
|
18
|
+
return function NcfCollectionPane(props) {
|
|
19
|
+
const type = typeof props.options?.type === 'string' ? props.options.type : ''
|
|
20
|
+
return (
|
|
21
|
+
<KitProvider config={config} issues={issues}>
|
|
22
|
+
<Box padding={3} height="fill" overflow="auto">
|
|
23
|
+
{type ? <CollectionTable type={type} /> : null}
|
|
24
|
+
</Box>
|
|
25
|
+
</KitProvider>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Vue table d'UNE collection, à utiliser comme enfant d'une entrée de structure
|
|
32
|
+
* pour que cliquer la collection ouvre la table (au lieu de la liste native) :
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* S.listItem().title('Articles').child(ncfCollectionTable(S, ncfOptions, 'article'))
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function ncfCollectionTable(
|
|
39
|
+
S: StructureBuilder,
|
|
40
|
+
options: NcfKitConfig,
|
|
41
|
+
type: string,
|
|
42
|
+
opts: {title?: string} = {},
|
|
43
|
+
) {
|
|
44
|
+
const config = resolveConfig(options)
|
|
45
|
+
const issues = validateConfig(config)
|
|
46
|
+
const pane = createCollectionPane(config, issues)
|
|
47
|
+
return S.component(pane)
|
|
48
|
+
.id(`ncf-collection-${type}`)
|
|
49
|
+
.title(opts.title ?? type)
|
|
50
|
+
.options({type})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Libellé d'une entrée de collection : config, puis titre du schéma, puis nom humanisé. */
|
|
54
|
+
function labelFor(type: string, config: ResolvedKitConfig, schemaTitle?: string): string {
|
|
55
|
+
return config.collections.labels[type] ?? schemaTitle ?? humanise(type)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Types toujours écartés de la découverte, en plus de l'`exclude` du projet. */
|
|
59
|
+
function reservedExcludes(config: ResolvedKitConfig): string[] {
|
|
60
|
+
return [
|
|
61
|
+
...config.pageTypeNames,
|
|
62
|
+
config.redirectType,
|
|
63
|
+
config.componentPreview.defaultsType,
|
|
64
|
+
...NCF_HIDDEN_TYPES,
|
|
65
|
+
...config.collections.exclude,
|
|
66
|
+
].filter(Boolean)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Entrées « collection » pour la structure du Studio, une par type découvert,
|
|
71
|
+
* chacune ouvrant la vue table. À épandre dans la liste racine :
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* structure: (S, context) =>
|
|
75
|
+
* S.list().title('Contenu').items([..., ...ncfCollections(S, context, ncfOptions)])
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export function ncfCollections(
|
|
79
|
+
S: StructureBuilder,
|
|
80
|
+
context: StructureResolverContext,
|
|
81
|
+
options: NcfKitConfig,
|
|
82
|
+
): ListItemBuilder[] {
|
|
83
|
+
const config = resolveConfig(options)
|
|
84
|
+
|
|
85
|
+
const types: SchemaTypeInfo[] = context.schema
|
|
86
|
+
.getTypeNames()
|
|
87
|
+
.map((name) => ({name, jsonType: context.schema.get(name)?.jsonType}))
|
|
88
|
+
|
|
89
|
+
const discovered = discoverCollectionTypes(types, {
|
|
90
|
+
include: config.collections.include,
|
|
91
|
+
exclude: reservedExcludes(config),
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
return discovered.map((type) => {
|
|
95
|
+
const schemaType = context.schema.get(type)
|
|
96
|
+
const label = labelFor(type, config, schemaType?.title)
|
|
97
|
+
const item = S.listItem()
|
|
98
|
+
.id(`ncf-collection-${type}`)
|
|
99
|
+
.title(label)
|
|
100
|
+
.child(ncfCollectionTable(S, options, type, {title: label}))
|
|
101
|
+
return schemaType?.icon ? item.icon(schemaType.icon) : item
|
|
102
|
+
})
|
|
103
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {useMemo, useState} from 'react'
|
|
2
|
+
import {Box, Button, Flex, Stack, Text} from '@sanity/ui'
|
|
3
|
+
import {CheckmarkIcon} from '@sanity/icons/Checkmark'
|
|
4
|
+
import {ControlsIcon} from '@sanity/icons/Controls'
|
|
5
|
+
import {InlinePopover} from '../../ui/Popover'
|
|
6
|
+
import {BORDER} from '../../ui/tokens'
|
|
7
|
+
import type {CollectionColumn} from '../../lib/collectionColumns'
|
|
8
|
+
|
|
9
|
+
export interface CollectionColumnPickerProps {
|
|
10
|
+
columns: readonly CollectionColumn[]
|
|
11
|
+
/** Clés visibles, dans l'ordre d'affichage. */
|
|
12
|
+
visible: readonly string[]
|
|
13
|
+
onToggle: (key: string) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Choix des colonnes affichées, sans quitter la table (façon tableur). */
|
|
17
|
+
export function CollectionColumnPicker(props: CollectionColumnPickerProps) {
|
|
18
|
+
const {columns, visible, onToggle} = props
|
|
19
|
+
const visibleSet = useMemo(() => new Set(visible), [visible])
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<InlinePopover
|
|
23
|
+
width={264}
|
|
24
|
+
trigger={({toggle}) => (
|
|
25
|
+
<Button
|
|
26
|
+
mode="bleed"
|
|
27
|
+
fontSize={1}
|
|
28
|
+
padding={2}
|
|
29
|
+
icon={ControlsIcon}
|
|
30
|
+
text={`Columns · ${visible.length}`}
|
|
31
|
+
onClick={toggle}
|
|
32
|
+
/>
|
|
33
|
+
)}
|
|
34
|
+
>
|
|
35
|
+
{() => <ColumnList columns={columns} visibleSet={visibleSet} onToggle={onToggle} />}
|
|
36
|
+
</InlinePopover>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function Row(props: {label: string; checked: boolean; onClick: () => void}) {
|
|
41
|
+
return (
|
|
42
|
+
<Flex
|
|
43
|
+
align="center"
|
|
44
|
+
gap={2}
|
|
45
|
+
padding={2}
|
|
46
|
+
onClick={props.onClick}
|
|
47
|
+
style={{cursor: 'pointer', borderRadius: 3}}
|
|
48
|
+
onMouseEnter={(event) => {
|
|
49
|
+
event.currentTarget.style.background = 'var(--card-muted-bg-color, rgba(127,127,127,0.12))'
|
|
50
|
+
}}
|
|
51
|
+
onMouseLeave={(event) => {
|
|
52
|
+
event.currentTarget.style.background = 'transparent'
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<Box style={{width: 14, flex: 'none'}}>
|
|
56
|
+
{props.checked && <CheckmarkIcon style={{fontSize: 14, opacity: 0.7}} />}
|
|
57
|
+
</Box>
|
|
58
|
+
<Text size={1} muted={!props.checked} textOverflow="ellipsis">
|
|
59
|
+
{props.label}
|
|
60
|
+
</Text>
|
|
61
|
+
</Flex>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Au-delà d'une poignée de champs, un filtre apparaît pour en chercher un. */
|
|
66
|
+
function ColumnList(props: {
|
|
67
|
+
columns: readonly CollectionColumn[]
|
|
68
|
+
visibleSet: ReadonlySet<string>
|
|
69
|
+
onToggle: (key: string) => void
|
|
70
|
+
}) {
|
|
71
|
+
const {columns, visibleSet, onToggle} = props
|
|
72
|
+
const [filter, setFilter] = useState('')
|
|
73
|
+
|
|
74
|
+
const matches = useMemo(() => {
|
|
75
|
+
const needle = filter.trim().toLowerCase()
|
|
76
|
+
if (!needle) return columns
|
|
77
|
+
return columns.filter((column) => column.label.toLowerCase().includes(needle))
|
|
78
|
+
}, [columns, filter])
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Stack gap={0}>
|
|
82
|
+
{columns.length > 8 && (
|
|
83
|
+
<Box paddingX={1} paddingBottom={1}>
|
|
84
|
+
<input
|
|
85
|
+
type="text"
|
|
86
|
+
value={filter}
|
|
87
|
+
placeholder="Filter…"
|
|
88
|
+
onChange={(event) => setFilter(event.currentTarget.value)}
|
|
89
|
+
style={{
|
|
90
|
+
width: '100%',
|
|
91
|
+
font: 'inherit',
|
|
92
|
+
fontSize: 12,
|
|
93
|
+
padding: '6px',
|
|
94
|
+
borderRadius: 3,
|
|
95
|
+
border: `1px solid ${BORDER}`,
|
|
96
|
+
background: 'var(--card-bg-color)',
|
|
97
|
+
color: 'var(--card-fg-color)',
|
|
98
|
+
outline: 'none',
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
</Box>
|
|
102
|
+
)}
|
|
103
|
+
|
|
104
|
+
{matches.map((column) => (
|
|
105
|
+
<Row
|
|
106
|
+
key={column.key}
|
|
107
|
+
label={column.label}
|
|
108
|
+
checked={visibleSet.has(column.key)}
|
|
109
|
+
onClick={() => onToggle(column.key)}
|
|
110
|
+
/>
|
|
111
|
+
))}
|
|
112
|
+
|
|
113
|
+
{matches.length === 0 && (
|
|
114
|
+
<Box padding={2}>
|
|
115
|
+
<Text size={0} muted>
|
|
116
|
+
No matching fields.
|
|
117
|
+
</Text>
|
|
118
|
+
</Box>
|
|
119
|
+
)}
|
|
120
|
+
</Stack>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import {useCallback, useMemo, useState} from 'react'
|
|
2
|
+
import {Badge, Box, Flex, Spinner, Stack, Text} from '@sanity/ui'
|
|
3
|
+
import {ChevronDownIcon} from '@sanity/icons/ChevronDown'
|
|
4
|
+
import {ChevronUpIcon} from '@sanity/icons/ChevronUp'
|
|
5
|
+
import {useRouter} from 'sanity/router'
|
|
6
|
+
import {useSchema} from 'sanity'
|
|
7
|
+
import {useCollection} from '../../hooks/useCollection'
|
|
8
|
+
import {filterRows, sortRows, type CollectionSort} from '../../lib/collectionTable'
|
|
9
|
+
import {toCsv} from '../../lib/csv'
|
|
10
|
+
import {downloadText} from '../../lib/download'
|
|
11
|
+
import {deriveCollectionColumns, type CollectionColumn} from '../../lib/collectionColumns'
|
|
12
|
+
import type {SchemaTypeLike} from '../../lib/schemaColumns'
|
|
13
|
+
import type {CollectionRow} from '../../lib/collectionRows'
|
|
14
|
+
import {BORDER, BORDER_SOFT, CELL, TABULAR} from '../../ui/tokens'
|
|
15
|
+
import {QueryError} from '../../ui/QueryError'
|
|
16
|
+
import {CollectionToolbar} from './CollectionToolbar'
|
|
17
|
+
|
|
18
|
+
/** Colonnes montrées par défaut : le titre d'abord, puis les premières. */
|
|
19
|
+
const DEFAULT_MAX = 6
|
|
20
|
+
|
|
21
|
+
function defaultVisible(columns: readonly CollectionColumn[]): string[] {
|
|
22
|
+
const title = columns.find((c) => c.key === 'title') ?? columns.find((c) => c.kind === 'text')
|
|
23
|
+
const ordered = title ? [title, ...columns.filter((c) => c !== title)] : [...columns]
|
|
24
|
+
return ordered.slice(0, DEFAULT_MAX).map((c) => c.key)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CollectionTableProps {
|
|
28
|
+
type: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function CollectionTable({type}: CollectionTableProps) {
|
|
32
|
+
const router = useRouter()
|
|
33
|
+
|
|
34
|
+
// `null` = pas encore de choix explicite → colonnes par défaut.
|
|
35
|
+
const [selected, setSelected] = useState<string[] | null>(null)
|
|
36
|
+
const [sort, setSort] = useState<CollectionSort>({key: null, direction: 'asc'})
|
|
37
|
+
const [search, setSearch] = useState('')
|
|
38
|
+
const [columnFilters, setColumnFilters] = useState<Record<string, string>>({})
|
|
39
|
+
|
|
40
|
+
// Toutes les colonnes viennent du schéma (sans requête) : elles fixent le
|
|
41
|
+
// défaut et alimentent le sélecteur. Seules les visibles sont ensuite
|
|
42
|
+
// projetées par le hook de données.
|
|
43
|
+
const schema = useSchema()
|
|
44
|
+
const allColumns = useMemo(
|
|
45
|
+
() => deriveCollectionColumns(schema.get(type) as SchemaTypeLike | undefined),
|
|
46
|
+
[schema, type],
|
|
47
|
+
)
|
|
48
|
+
const visibleKeys = useMemo(() => selected ?? defaultVisible(allColumns), [selected, allColumns])
|
|
49
|
+
|
|
50
|
+
const {visibleColumns, rows, loading, error, refresh} = useCollection(type, visibleKeys)
|
|
51
|
+
|
|
52
|
+
const visible = useMemo(() => {
|
|
53
|
+
const filtered = filterRows(rows, {search, columns: columnFilters}, visibleColumns)
|
|
54
|
+
return sortRows(filtered, sort, visibleColumns)
|
|
55
|
+
}, [rows, search, columnFilters, visibleColumns, sort])
|
|
56
|
+
|
|
57
|
+
const onToggleColumn = useCallback(
|
|
58
|
+
(key: string) => {
|
|
59
|
+
setSelected((current) => {
|
|
60
|
+
const base = current ?? defaultVisible(allColumns)
|
|
61
|
+
return base.includes(key) ? base.filter((k) => k !== key) : [...base, key]
|
|
62
|
+
})
|
|
63
|
+
// Un filtre sur une colonne qu'on masque n'a plus de sens.
|
|
64
|
+
setColumnFilters((current) => {
|
|
65
|
+
if (!current[key]) return current
|
|
66
|
+
const {[key]: _removed, ...rest} = current
|
|
67
|
+
return rest
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
[allColumns],
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const onSort = useCallback((key: string) => {
|
|
74
|
+
setSort((current) =>
|
|
75
|
+
current.key === key
|
|
76
|
+
? {key, direction: current.direction === 'asc' ? 'desc' : 'asc'}
|
|
77
|
+
: {key, direction: 'asc'},
|
|
78
|
+
)
|
|
79
|
+
}, [])
|
|
80
|
+
|
|
81
|
+
const onExport = useCallback(() => {
|
|
82
|
+
downloadText(`${type}.csv`, toCsv(visible, visibleColumns))
|
|
83
|
+
}, [type, visible, visibleColumns])
|
|
84
|
+
|
|
85
|
+
const onColumnFilter = useCallback((key: string, value: string) => {
|
|
86
|
+
setColumnFilters((current) => ({...current, [key]: value}))
|
|
87
|
+
}, [])
|
|
88
|
+
|
|
89
|
+
if (error) return <QueryError error={error} onRetry={refresh} />
|
|
90
|
+
|
|
91
|
+
const summary =
|
|
92
|
+
visible.length === rows.length
|
|
93
|
+
? `${rows.length} item${rows.length > 1 ? 's' : ''}`
|
|
94
|
+
: `${visible.length} of ${rows.length}`
|
|
95
|
+
|
|
96
|
+
const grid: React.CSSProperties = {
|
|
97
|
+
display: 'grid',
|
|
98
|
+
gridTemplateColumns: visibleColumns
|
|
99
|
+
.map((_, index) => (index === 0 ? 'minmax(200px, 1.6fr)' : 'minmax(150px, 1fr)'))
|
|
100
|
+
.join(' '),
|
|
101
|
+
gap: '0.875rem',
|
|
102
|
+
alignItems: 'center',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Stack gap={4}>
|
|
107
|
+
<CollectionToolbar
|
|
108
|
+
search={search}
|
|
109
|
+
onSearch={setSearch}
|
|
110
|
+
columns={allColumns}
|
|
111
|
+
visible={visibleKeys}
|
|
112
|
+
onToggleColumn={onToggleColumn}
|
|
113
|
+
onExport={onExport}
|
|
114
|
+
onRefresh={refresh}
|
|
115
|
+
busy={loading}
|
|
116
|
+
summary={summary}
|
|
117
|
+
/>
|
|
118
|
+
|
|
119
|
+
{loading && rows.length === 0 ? (
|
|
120
|
+
<Flex align="center" justify="center" padding={6} gap={3}>
|
|
121
|
+
<Spinner muted />
|
|
122
|
+
<Text size={1} muted>
|
|
123
|
+
Loading…
|
|
124
|
+
</Text>
|
|
125
|
+
</Flex>
|
|
126
|
+
) : visibleColumns.length === 0 ? (
|
|
127
|
+
<Box padding={5}>
|
|
128
|
+
<Text size={1} muted align="center">
|
|
129
|
+
No displayable field in this type. Pick columns above.
|
|
130
|
+
</Text>
|
|
131
|
+
</Box>
|
|
132
|
+
) : (
|
|
133
|
+
<Box style={{overflowX: 'auto', border: `1px solid ${BORDER_SOFT}`, borderRadius: 6}}>
|
|
134
|
+
<Box style={{minWidth: 'min-content'}}>
|
|
135
|
+
{/* En-tête : libellé triable + filtre « contient » par colonne. */}
|
|
136
|
+
<Box
|
|
137
|
+
paddingX={3}
|
|
138
|
+
paddingY={2}
|
|
139
|
+
style={{
|
|
140
|
+
...grid,
|
|
141
|
+
alignItems: 'end',
|
|
142
|
+
borderBottom: `1px solid ${BORDER}`,
|
|
143
|
+
position: 'sticky',
|
|
144
|
+
top: 0,
|
|
145
|
+
background: 'var(--card-bg-color, inherit)',
|
|
146
|
+
zIndex: 2,
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
{visibleColumns.map((column) => {
|
|
150
|
+
const active = sort.key === column.key
|
|
151
|
+
const Arrow = sort.direction === 'asc' ? ChevronUpIcon : ChevronDownIcon
|
|
152
|
+
return (
|
|
153
|
+
<Stack key={column.key} gap={2} style={CELL}>
|
|
154
|
+
<Flex
|
|
155
|
+
align="center"
|
|
156
|
+
gap={1}
|
|
157
|
+
onClick={() => onSort(column.key)}
|
|
158
|
+
style={{cursor: 'pointer', userSelect: 'none'}}
|
|
159
|
+
title={`Sort by ${column.label.toLowerCase()}`}
|
|
160
|
+
>
|
|
161
|
+
<Text size={0} weight="medium" muted={!active} textOverflow="ellipsis">
|
|
162
|
+
{column.label}
|
|
163
|
+
</Text>
|
|
164
|
+
{active && <Arrow style={{fontSize: 13, opacity: 0.7, flex: 'none'}} />}
|
|
165
|
+
</Flex>
|
|
166
|
+
<input
|
|
167
|
+
type="text"
|
|
168
|
+
value={columnFilters[column.key] ?? ''}
|
|
169
|
+
placeholder="Filter…"
|
|
170
|
+
onChange={(event) => onColumnFilter(column.key, event.currentTarget.value)}
|
|
171
|
+
style={{
|
|
172
|
+
width: '100%',
|
|
173
|
+
font: 'inherit',
|
|
174
|
+
fontSize: 11,
|
|
175
|
+
padding: '3px 6px',
|
|
176
|
+
borderRadius: 3,
|
|
177
|
+
border: `1px solid ${BORDER_SOFT}`,
|
|
178
|
+
background: 'var(--card-bg-color)',
|
|
179
|
+
color: 'var(--card-fg-color)',
|
|
180
|
+
outline: 'none',
|
|
181
|
+
}}
|
|
182
|
+
/>
|
|
183
|
+
</Stack>
|
|
184
|
+
)
|
|
185
|
+
})}
|
|
186
|
+
</Box>
|
|
187
|
+
|
|
188
|
+
{visible.map((row) => (
|
|
189
|
+
<CollectionRowView
|
|
190
|
+
key={row.id}
|
|
191
|
+
row={row}
|
|
192
|
+
columns={visibleColumns}
|
|
193
|
+
grid={grid}
|
|
194
|
+
onOpen={() => router.navigateIntent('edit', {id: row.id, type})}
|
|
195
|
+
/>
|
|
196
|
+
))}
|
|
197
|
+
|
|
198
|
+
{visible.length === 0 && (
|
|
199
|
+
<Box padding={5}>
|
|
200
|
+
<Text size={1} muted align="center">
|
|
201
|
+
{rows.length === 0 ? 'No item yet.' : 'No match.'}
|
|
202
|
+
</Text>
|
|
203
|
+
</Box>
|
|
204
|
+
)}
|
|
205
|
+
</Box>
|
|
206
|
+
</Box>
|
|
207
|
+
)}
|
|
208
|
+
</Stack>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function CollectionRowView(props: {
|
|
213
|
+
row: CollectionRow
|
|
214
|
+
columns: readonly CollectionColumn[]
|
|
215
|
+
grid: React.CSSProperties
|
|
216
|
+
onOpen: () => void
|
|
217
|
+
}) {
|
|
218
|
+
const {row, columns, grid, onOpen} = props
|
|
219
|
+
const [hovered, setHovered] = useState(false)
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<Box
|
|
223
|
+
paddingX={3}
|
|
224
|
+
paddingY={2}
|
|
225
|
+
onClick={onOpen}
|
|
226
|
+
onMouseEnter={() => setHovered(true)}
|
|
227
|
+
onMouseLeave={() => setHovered(false)}
|
|
228
|
+
style={{
|
|
229
|
+
...grid,
|
|
230
|
+
cursor: 'pointer',
|
|
231
|
+
borderBottom: `1px solid ${BORDER_SOFT}`,
|
|
232
|
+
background: hovered ? 'var(--card-muted-bg-color, rgba(127,127,127,0.08))' : 'transparent',
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
{columns.map((column, index) => {
|
|
236
|
+
const cell = row.cells[column.key]
|
|
237
|
+
const empty = !cell || cell.raw === null || cell.text === ''
|
|
238
|
+
return (
|
|
239
|
+
<Flex key={column.key} align="center" gap={2} style={CELL}>
|
|
240
|
+
<Text
|
|
241
|
+
size={1}
|
|
242
|
+
muted={empty}
|
|
243
|
+
weight={index === 0 ? 'medium' : 'regular'}
|
|
244
|
+
textOverflow="ellipsis"
|
|
245
|
+
style={{flex: 1, minWidth: 0, ...(column.kind === 'number' || column.kind === 'date' ? TABULAR : null)}}
|
|
246
|
+
>
|
|
247
|
+
{empty ? '—' : cell.text}
|
|
248
|
+
</Text>
|
|
249
|
+
{index === 0 && row.draftOnly && (
|
|
250
|
+
<Badge tone="caution" fontSize={0} style={{flex: 'none'}}>
|
|
251
|
+
Draft
|
|
252
|
+
</Badge>
|
|
253
|
+
)}
|
|
254
|
+
</Flex>
|
|
255
|
+
)
|
|
256
|
+
})}
|
|
257
|
+
</Box>
|
|
258
|
+
)
|
|
259
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {Box, Button, Flex, Text, TextInput} from '@sanity/ui'
|
|
2
|
+
import {SearchIcon} from '@sanity/icons/Search'
|
|
3
|
+
import {DownloadIcon} from '@sanity/icons/Download'
|
|
4
|
+
import {RefreshIcon} from '@sanity/icons/Refresh'
|
|
5
|
+
import {CollectionColumnPicker} from './CollectionColumnPicker'
|
|
6
|
+
import type {CollectionColumn} from '../../lib/collectionColumns'
|
|
7
|
+
|
|
8
|
+
export interface CollectionToolbarProps {
|
|
9
|
+
search: string
|
|
10
|
+
onSearch: (value: string) => void
|
|
11
|
+
columns: readonly CollectionColumn[]
|
|
12
|
+
visible: readonly string[]
|
|
13
|
+
onToggleColumn: (key: string) => void
|
|
14
|
+
onExport: () => void
|
|
15
|
+
onRefresh: () => void
|
|
16
|
+
busy: boolean
|
|
17
|
+
/** Résumé « N items » ou « N of M ». */
|
|
18
|
+
summary: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Barre au-dessus de la table : recherche, colonnes, export CSV. */
|
|
22
|
+
export function CollectionToolbar(props: CollectionToolbarProps) {
|
|
23
|
+
const {search, onSearch, columns, visible, onToggleColumn, onExport, onRefresh, busy, summary} = props
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Flex align="center" gap={2} wrap="wrap">
|
|
27
|
+
<Box style={{flex: 1, minWidth: 180}}>
|
|
28
|
+
<TextInput
|
|
29
|
+
icon={SearchIcon}
|
|
30
|
+
fontSize={1}
|
|
31
|
+
padding={2}
|
|
32
|
+
radius={2}
|
|
33
|
+
placeholder="Search"
|
|
34
|
+
value={search}
|
|
35
|
+
onChange={(event) => onSearch(event.currentTarget.value)}
|
|
36
|
+
clearButton={Boolean(search)}
|
|
37
|
+
onClear={() => onSearch('')}
|
|
38
|
+
/>
|
|
39
|
+
</Box>
|
|
40
|
+
|
|
41
|
+
<Text size={1} muted style={{flex: 'none'}}>
|
|
42
|
+
{summary}
|
|
43
|
+
</Text>
|
|
44
|
+
|
|
45
|
+
<Flex gap={1} style={{flex: 'none'}}>
|
|
46
|
+
<CollectionColumnPicker columns={columns} visible={visible} onToggle={onToggleColumn} />
|
|
47
|
+
<Button
|
|
48
|
+
mode="bleed"
|
|
49
|
+
fontSize={1}
|
|
50
|
+
padding={2}
|
|
51
|
+
icon={DownloadIcon}
|
|
52
|
+
text="Export CSV"
|
|
53
|
+
onClick={onExport}
|
|
54
|
+
/>
|
|
55
|
+
<Button
|
|
56
|
+
mode="bleed"
|
|
57
|
+
fontSize={1}
|
|
58
|
+
padding={2}
|
|
59
|
+
icon={RefreshIcon}
|
|
60
|
+
title="Refresh"
|
|
61
|
+
aria-label="Refresh"
|
|
62
|
+
onClick={onRefresh}
|
|
63
|
+
disabled={busy}
|
|
64
|
+
/>
|
|
65
|
+
</Flex>
|
|
66
|
+
</Flex>
|
|
67
|
+
)
|
|
68
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"finalUrl-CaFXmYvm.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 }\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,IAAI,CAAC,WAAW,YAAY,KAAK,OAAO;CACxC,IAAM,YAAY,QAAQ,WAAW,GAAG,IAAI,UAAU,IAAI;CAC1D,OAAO,UAAU,SAAS,IAAI,kBAAkB,SAAS,IAAI;AAC/D;AAEA,SAAS,gBACP,OACA,UACkB;CAClB,IAAI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