@nocode-factory/sanity-kit 2.56.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.
Files changed (47) hide show
  1. package/README.md +45 -8
  2. package/bin/item-types.mjs +131 -0
  3. package/bin/ncf-kit.mjs +121 -2
  4. package/dist/{finalUrl-IXF3zbT9.js → finalUrl-DYyjKCjh.js} +2 -1
  5. package/dist/finalUrl-DYyjKCjh.js.map +1 -0
  6. package/dist/{fixCrossLanguageReferences-CDczoic9.js → fixCrossLanguageReferences-C4A61VWW.js} +2 -2
  7. package/dist/{fixCrossLanguageReferences-CDczoic9.js.map → fixCrossLanguageReferences-C4A61VWW.js.map} +1 -1
  8. package/dist/{fixCrossLanguageReferences-C1VsmGsJ.d.ts → fixCrossLanguageReferences-CfFDSTD5.d.ts} +8 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +7240 -7011
  11. package/dist/index.js.map +1 -1
  12. package/dist/inherited-DZvM35P6.js +101 -0
  13. package/dist/inherited-DZvM35P6.js.map +1 -0
  14. package/dist/jsonld.js +1 -1
  15. package/dist/protocol-Bl7Yj2Ro.js +31 -0
  16. package/dist/protocol-Bl7Yj2Ro.js.map +1 -0
  17. package/dist/schema.d.ts +1 -1
  18. package/dist/schema.js +2 -2
  19. package/dist/web-edit.d.ts +192 -0
  20. package/dist/web-edit.js +144 -0
  21. package/dist/web-edit.js.map +1 -0
  22. package/dist/web-editing.d.ts +51 -0
  23. package/dist/web-editing.js +693 -0
  24. package/dist/web-editing.js.map +1 -0
  25. package/package.json +22 -2
  26. package/scripts/use-client.mjs +1 -1
  27. package/src/config/resolve.ts +1 -0
  28. package/src/config/types.ts +7 -1
  29. package/src/form/AssetSourceBrowser.tsx +68 -39
  30. package/src/index.ts +12 -5
  31. package/src/lib/i18nTemplates.ts +38 -4
  32. package/src/tools/collections/CollectionTable.tsx +116 -89
  33. package/src/tools/presentation/PagesNavigator.tsx +150 -56
  34. package/src/ui/PreviewEditBridge.tsx +74 -0
  35. package/src/version.ts +1 -1
  36. package/src/web/edit/ImageReplaceLayer.tsx +174 -0
  37. package/src/web/edit/InlineTextEditor.tsx +365 -0
  38. package/src/web/edit/InlineTextOverlay.tsx +43 -0
  39. package/src/web/edit/PreviewEditing.tsx +191 -0
  40. package/src/web/edit/index.ts +18 -0
  41. package/src/web/edit/inherited.ts +174 -0
  42. package/src/web/edit/labels.ts +37 -0
  43. package/src/web/edit/protocol.ts +47 -0
  44. package/src/web/edit/store.ts +98 -0
  45. package/src/web/edit/targets.ts +186 -0
  46. package/src/web/editing.ts +18 -0
  47. package/dist/finalUrl-IXF3zbT9.js.map +0 -1
@@ -1,7 +1,8 @@
1
- import {useCallback, useMemo, useRef, useState} from 'react'
1
+ import {useCallback, useMemo, useRef, useState, type ComponentType} from 'react'
2
2
  import {Badge, Box, Flex, Spinner, Stack, Text} from '@sanity/ui'
3
3
  import {ChevronDownIcon} from '@sanity/icons/ChevronDown'
4
4
  import {ChevronUpIcon} from '@sanity/icons/ChevronUp'
5
+ import {DocumentIcon} from '@sanity/icons/Document'
5
6
  import {usePaneRouter} from 'sanity/structure'
6
7
  import {useRouter} from 'sanity/router'
7
8
  import {useSchema} from 'sanity'
@@ -12,7 +13,7 @@ import {downloadText} from '../../lib/download'
12
13
  import {deriveCollectionColumns, type CollectionColumn} from '../../lib/collectionColumns'
13
14
  import type {SchemaTypeLike} from '../../lib/schemaColumns'
14
15
  import type {CollectionRow} from '../../lib/collectionRows'
15
- import {BORDER, BORDER_SOFT, CELL, TABULAR} from '../../ui/tokens'
16
+ import {BORDER, BORDER_SOFT, TABULAR} from '../../ui/tokens'
16
17
  import {QueryError} from '../../ui/QueryError'
17
18
  import {CollectionToolbar, type CollectionView} from './CollectionToolbar'
18
19
 
@@ -20,6 +21,8 @@ import {CollectionToolbar, type CollectionView} from './CollectionToolbar'
20
21
  const DEFAULT_MAX = 6
21
22
  /** Largeur minimale d'une colonne au redimensionnement. */
22
23
  const MIN_WIDTH = 80
24
+ /** Côté de la vignette d'icône (vue liste), calé sur la liste native de Sanity. */
25
+ const MEDIA = '2.0625rem'
23
26
 
24
27
  function defaultVisible(columns: readonly CollectionColumn[]): string[] {
25
28
  const title = columns.find((c) => c.key === 'title') ?? columns.find((c) => c.kind === 'text')
@@ -29,7 +32,7 @@ function defaultVisible(columns: readonly CollectionColumn[]): string[] {
29
32
 
30
33
  /** Largeur par défaut d'une colonne : le titre large, le reste selon le type. */
31
34
  function defaultWidth(column: CollectionColumn, isFirst: boolean): number {
32
- if (isFirst) return 320
35
+ if (isFirst) return 340
33
36
  switch (column.kind) {
34
37
  case 'number':
35
38
  return 110
@@ -79,25 +82,23 @@ export function CollectionTable({type, filter, params, newTemplate}: CollectionT
79
82
  const [selected, setSelected] = useState<string[] | null>(null)
80
83
  const [sort, setSort] = useState<CollectionSort>({key: null, direction: 'asc'})
81
84
  const [search, setSearch] = useState('')
82
- const [columnFilters, setColumnFilters] = useState<Record<string, string>>({})
83
85
  const [widths, setWidths] = useState<Record<string, number>>({})
84
86
 
85
87
  // Toutes les colonnes viennent du schéma (sans requête) : elles fixent le
86
88
  // défaut et alimentent le sélecteur. Seules les visibles sont ensuite
87
89
  // projetées par le hook de données.
88
90
  const schema = useSchema()
89
- const allColumns = useMemo(
90
- () => deriveCollectionColumns(schema.get(type) as SchemaTypeLike | undefined),
91
- [schema, type],
92
- )
91
+ const schemaType = schema.get(type) as SchemaTypeLike | undefined
92
+ const TypeIcon = (schemaType as {icon?: ComponentType} | undefined)?.icon
93
+ const allColumns = useMemo(() => deriveCollectionColumns(schemaType), [schemaType])
93
94
  const visibleKeys = useMemo(() => selected ?? defaultVisible(allColumns), [selected, allColumns])
94
95
 
95
96
  const {visibleColumns, rows, loading, error, refresh} = useCollection(type, visibleKeys, {filter, params})
96
97
 
97
98
  const visible = useMemo(() => {
98
- const filtered = filterRows(rows, {search, columns: columnFilters}, visibleColumns)
99
+ const filtered = filterRows(rows, {search, columns: {}}, visibleColumns)
99
100
  return sortRows(filtered, sort, visibleColumns)
100
- }, [rows, search, columnFilters, visibleColumns, sort])
101
+ }, [rows, search, visibleColumns, sort])
101
102
 
102
103
  // Largeur effective de chaque colonne visible (état ou défaut selon le type).
103
104
  const cols = useMemo(
@@ -112,12 +113,6 @@ export function CollectionTable({type, filter, params, newTemplate}: CollectionT
112
113
  const base = current ?? defaultVisible(allColumns)
113
114
  return base.includes(key) ? base.filter((k) => k !== key) : [...base, key]
114
115
  })
115
- // Un filtre sur une colonne qu'on masque n'a plus de sens.
116
- setColumnFilters((current) => {
117
- if (!current[key]) return current
118
- const {[key]: _removed, ...rest} = current
119
- return rest
120
- })
121
116
  },
122
117
  [allColumns],
123
118
  )
@@ -134,10 +129,6 @@ export function CollectionTable({type, filter, params, newTemplate}: CollectionT
134
129
  downloadText(`${type}.csv`, toCsv(visible, visibleColumns))
135
130
  }, [type, visible, visibleColumns])
136
131
 
137
- const onColumnFilter = useCallback((key: string, value: string) => {
138
- setColumnFilters((current) => ({...current, [key]: value}))
139
- }, [])
140
-
141
132
  // Création : applique le template du niveau feuille (langue, catégorie…) s'il
142
133
  // est fourni, sinon un document nu du type.
143
134
  const onCreate = useCallback(() => {
@@ -184,7 +175,12 @@ export function CollectionTable({type, filter, params, newTemplate}: CollectionT
184
175
  ? `${rows.length} item${rows.length > 1 ? 's' : ''}`
185
176
  : `${visible.length} of ${rows.length}`
186
177
 
187
- const subtitleKey = visibleColumns.find((c, i) => i > 0 && c.kind === 'text')?.key
178
+ const titleKey = visibleColumns[0]?.key
179
+ // Sous-titre de la vue liste : un slug/chemin/URL si présent, sinon la
180
+ // première colonne texte après le titre (façon liste native).
181
+ const subtitleKey =
182
+ visibleColumns.find((c, i) => i > 0 && /slug|path|url|email/i.test(c.key))?.key ??
183
+ visibleColumns.find((c, i) => i > 0 && c.kind === 'text')?.key
188
184
 
189
185
  return (
190
186
  <Stack gap={3}>
@@ -217,12 +213,12 @@ export function CollectionTable({type, filter, params, newTemplate}: CollectionT
217
213
  </Text>
218
214
  </Box>
219
215
  ) : view === 'list' ? (
220
- <Box style={{border: `1px solid ${BORDER_SOFT}`, borderRadius: 6}}>
221
- <style>{`.ncf-coll-body a{display:contents;color:inherit;text-decoration:none}`}</style>
216
+ <Box style={{border: `1px solid ${BORDER_SOFT}`, borderRadius: 6, overflow: 'hidden'}}>
217
+ <style>{`.ncf-coll-body a{display:block;color:inherit;text-decoration:none}`}</style>
222
218
  <Box className="ncf-coll-body">
223
219
  {visible.map((row) => (
224
220
  <ChildLink key={row.id} childId={row.id}>
225
- <ListRowView row={row} titleKey={visibleColumns[0]?.key} subtitleKey={subtitleKey} />
221
+ <ListRowView row={row} titleKey={titleKey} subtitleKey={subtitleKey} Icon={TypeIcon} />
226
222
  </ChildLink>
227
223
  ))}
228
224
  {visible.length === 0 && (
@@ -238,22 +234,23 @@ export function CollectionTable({type, filter, params, newTemplate}: CollectionT
238
234
  <Box style={{overflowX: 'auto', border: `1px solid ${BORDER_SOFT}`, borderRadius: 6}}>
239
235
  <style>{`.ncf-coll-body a{display:contents;color:inherit;text-decoration:none}`}</style>
240
236
  <Box style={{width: totalWidth, minWidth: '100%'}}>
241
- {/* En-tête : libellé triable + déplaçable, poignée de largeur, filtre. */}
237
+ {/* En-tête : libellé triable + déplaçable, poignée de largeur. */}
242
238
  <Flex
243
239
  paddingX={3}
244
- paddingY={2}
245
- align="flex-end"
240
+ paddingY={3}
241
+ align="center"
246
242
  style={{
247
243
  borderBottom: `1px solid ${BORDER}`,
248
244
  position: 'sticky',
249
245
  top: 0,
250
- background: 'var(--card-bg-color, inherit)',
246
+ background: 'var(--card-muted-bg-color, var(--card-bg-color, inherit))',
251
247
  zIndex: 2,
252
248
  }}
253
249
  >
254
250
  {cols.map(({column, width}) => {
255
251
  const active = sort.key === column.key
256
252
  const Arrow = sort.direction === 'asc' ? ChevronUpIcon : ChevronDownIcon
253
+ const alignEnd = column.kind === 'number'
257
254
  return (
258
255
  <Box
259
256
  key={column.key}
@@ -273,46 +270,27 @@ export function CollectionTable({type, filter, params, newTemplate}: CollectionT
273
270
  borderLeft: dragOverKey === column.key ? `2px solid var(--card-focus-ring-color, #2276fc)` : '2px solid transparent',
274
271
  }}
275
272
  >
276
- <Stack gap={2} style={CELL}>
277
- <Flex
278
- align="center"
279
- gap={1}
280
- draggable
281
- onDragStart={() => {
282
- dragKeyRef.current = column.key
283
- }}
284
- onDragEnd={() => {
285
- dragKeyRef.current = null
286
- setDragOverKey(null)
287
- }}
288
- onClick={() => onSort(column.key)}
289
- style={{cursor: 'grab', userSelect: 'none'}}
290
- title={`Sort by ${column.label.toLowerCase()} — drag to reorder`}
291
- >
292
- <Text size={0} weight="medium" muted={!active} textOverflow="ellipsis">
293
- {column.label}
294
- </Text>
295
- {active && <Arrow style={{fontSize: 12, opacity: 0.7, flex: 'none'}} />}
296
- </Flex>
297
- <input
298
- type="text"
299
- value={columnFilters[column.key] ?? ''}
300
- placeholder="Filter…"
301
- onChange={(event) => onColumnFilter(column.key, event.currentTarget.value)}
302
- style={{
303
- width: '100%',
304
- boxSizing: 'border-box',
305
- font: 'inherit',
306
- fontSize: 11,
307
- padding: '3px 6px',
308
- borderRadius: 3,
309
- border: `1px solid ${BORDER_SOFT}`,
310
- background: 'var(--card-bg-color)',
311
- color: 'var(--card-fg-color)',
312
- outline: 'none',
313
- }}
314
- />
315
- </Stack>
273
+ <Flex
274
+ align="center"
275
+ gap={1}
276
+ justify={alignEnd ? 'flex-end' : 'flex-start'}
277
+ draggable
278
+ onDragStart={() => {
279
+ dragKeyRef.current = column.key
280
+ }}
281
+ onDragEnd={() => {
282
+ dragKeyRef.current = null
283
+ setDragOverKey(null)
284
+ }}
285
+ onClick={() => onSort(column.key)}
286
+ style={{cursor: 'grab', userSelect: 'none'}}
287
+ title={`Sort by ${column.label.toLowerCase()} — drag to reorder`}
288
+ >
289
+ <Text size={1} weight="semibold" muted={!active} textOverflow="ellipsis">
290
+ {column.label}
291
+ </Text>
292
+ {active && <Arrow style={{fontSize: 14, opacity: 0.7, flex: 'none'}} />}
293
+ </Flex>
316
294
  {/* Poignée de redimensionnement (bord droit). */}
317
295
  <div
318
296
  onPointerDown={onResizeStart(column.key, width)}
@@ -335,7 +313,7 @@ export function CollectionTable({type, filter, params, newTemplate}: CollectionT
335
313
  <Box className="ncf-coll-body">
336
314
  {visible.map((row) => (
337
315
  <ChildLink key={row.id} childId={row.id}>
338
- <TableRowView row={row} cols={cols} />
316
+ <TableRowView row={row} cols={cols} Icon={TypeIcon} />
339
317
  </ChildLink>
340
318
  ))}
341
319
 
@@ -354,15 +332,36 @@ export function CollectionTable({type, filter, params, newTemplate}: CollectionT
354
332
  )
355
333
  }
356
334
 
335
+ /** Pastille de statut : vert = publié, ambre = brouillon jamais publié. */
336
+ function StatusDot(props: {draftOnly?: boolean}) {
337
+ return (
338
+ <span
339
+ title={props.draftOnly ? 'Not published' : 'Published'}
340
+ style={{
341
+ flex: 'none',
342
+ width: 9,
343
+ height: 9,
344
+ borderRadius: '50%',
345
+ background: props.draftOnly ? '#f5a623' : '#43d675',
346
+ }}
347
+ />
348
+ )
349
+ }
350
+
357
351
  /** Ligne de la vue TABLE : une cellule par colonne, largeurs fixes. */
358
- function TableRowView(props: {row: CollectionRow; cols: readonly {column: CollectionColumn; width: number}[]}) {
359
- const {row, cols} = props
352
+ function TableRowView(props: {
353
+ row: CollectionRow
354
+ cols: readonly {column: CollectionColumn; width: number}[]
355
+ Icon?: ComponentType
356
+ }) {
357
+ const {row, cols, Icon} = props
360
358
  const [hovered, setHovered] = useState(false)
361
359
 
362
360
  return (
363
361
  <Flex
364
362
  paddingX={3}
365
363
  paddingY={2}
364
+ align="center"
366
365
  onMouseEnter={() => setHovered(true)}
367
366
  onMouseLeave={() => setHovered(false)}
368
367
  style={{
@@ -374,18 +373,32 @@ function TableRowView(props: {row: CollectionRow; cols: readonly {column: Collec
374
373
  {cols.map(({column, width}, index) => {
375
374
  const cell = row.cells[column.key]
376
375
  const empty = !cell || cell.raw === null || cell.text === ''
376
+ const first = index === 0
377
+ const alignEnd = column.kind === 'number'
377
378
  return (
378
- <Flex key={column.key} align="center" gap={2} paddingRight={2} style={{width, flex: 'none', boxSizing: 'border-box'}}>
379
+ <Flex
380
+ key={column.key}
381
+ align="center"
382
+ gap={2}
383
+ paddingRight={2}
384
+ justify={alignEnd ? 'flex-end' : 'flex-start'}
385
+ style={{width, flex: 'none', boxSizing: 'border-box'}}
386
+ >
387
+ {first && (
388
+ <Text size={1} muted style={{flex: 'none', display: 'flex'}}>
389
+ {Icon ? <Icon /> : <DocumentIcon />}
390
+ </Text>
391
+ )}
379
392
  <Text
380
- size={0}
393
+ size={1}
381
394
  muted={empty}
382
- weight={index === 0 ? 'medium' : 'regular'}
395
+ weight={first ? 'medium' : 'regular'}
383
396
  textOverflow="ellipsis"
384
- style={{flex: 1, minWidth: 0, ...(column.kind === 'number' || column.kind === 'date' ? TABULAR : null)}}
397
+ style={{flex: alignEnd ? 'none' : 1, minWidth: 0, ...(column.kind === 'number' || column.kind === 'date' ? TABULAR : null)}}
385
398
  >
386
399
  {empty ? '—' : cell.text}
387
400
  </Text>
388
- {index === 0 && row.draftOnly && (
401
+ {first && row.draftOnly && (
389
402
  <Badge tone="caution" fontSize={0} style={{flex: 'none'}}>
390
403
  Draft
391
404
  </Badge>
@@ -397,9 +410,9 @@ function TableRowView(props: {row: CollectionRow; cols: readonly {column: Collec
397
410
  )
398
411
  }
399
412
 
400
- /** Ligne de la vue LISTE : titre + sous-titre, façon liste native. */
401
- function ListRowView(props: {row: CollectionRow; titleKey?: string; subtitleKey?: string}) {
402
- const {row, titleKey, subtitleKey} = props
413
+ /** Ligne de la vue LISTE : vignette + titre + sous-titre, façon liste native. */
414
+ function ListRowView(props: {row: CollectionRow; titleKey?: string; subtitleKey?: string; Icon?: ComponentType}) {
415
+ const {row, titleKey, subtitleKey, Icon} = props
403
416
  const [hovered, setHovered] = useState(false)
404
417
  const title = titleKey ? row.cells[titleKey]?.text : ''
405
418
  const subtitle = subtitleKey ? row.cells[subtitleKey]?.text : ''
@@ -407,9 +420,8 @@ function ListRowView(props: {row: CollectionRow; titleKey?: string; subtitleKey?
407
420
  return (
408
421
  <Flex
409
422
  align="center"
410
- gap={2}
411
- paddingX={3}
412
- paddingY={2}
423
+ gap={3}
424
+ padding={2}
413
425
  onMouseEnter={() => setHovered(true)}
414
426
  onMouseLeave={() => setHovered(false)}
415
427
  style={{
@@ -418,21 +430,36 @@ function ListRowView(props: {row: CollectionRow; titleKey?: string; subtitleKey?
418
430
  background: hovered ? 'var(--card-muted-bg-color, rgba(127,127,127,0.08))' : 'transparent',
419
431
  }}
420
432
  >
433
+ {/* Vignette : icône du type dans un cadre, calée sur la liste native. */}
434
+ <Flex
435
+ align="center"
436
+ justify="center"
437
+ style={{
438
+ width: MEDIA,
439
+ height: MEDIA,
440
+ flex: 'none',
441
+ border: `1px solid ${BORDER_SOFT}`,
442
+ borderRadius: 3,
443
+ color: 'var(--card-muted-fg-color)',
444
+ }}
445
+ >
446
+ <Text size={2} muted style={{display: 'flex'}}>
447
+ {Icon ? <Icon /> : <DocumentIcon />}
448
+ </Text>
449
+ </Flex>
450
+
421
451
  <Stack gap={2} flex={1} style={{minWidth: 0}}>
422
- <Text size={1} weight="medium" textOverflow="ellipsis">
452
+ <Text size={1} textOverflow="ellipsis">
423
453
  {title || 'Untitled'}
424
454
  </Text>
425
455
  {subtitle ? (
426
- <Text size={0} muted textOverflow="ellipsis">
456
+ <Text size={1} muted textOverflow="ellipsis">
427
457
  {subtitle}
428
458
  </Text>
429
459
  ) : null}
430
460
  </Stack>
431
- {row.draftOnly && (
432
- <Badge tone="caution" fontSize={0} style={{flex: 'none'}}>
433
- Draft
434
- </Badge>
435
- )}
461
+
462
+ <StatusDot draftOnly={row.draftOnly} />
436
463
  </Flex>
437
464
  )
438
465
  }
@@ -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 [dragId, setDragId] = useState<string | null>(null)
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
- // Glisser une page la place avant celle survolée ; on réordonne l'ordre
59
- // manuel COMPLET (ids), pas la vue filtrée, pour ne pas perdre les autres.
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 (!dragId) return
106
+ if (!drag) return
62
107
  const fullIds = orderByIds(withPath, pageOrder).map((r) => r.id)
63
- savePageOrder(reorderBefore(fullIds, dragId, targetId))
64
- setDragId(null)
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
- {visible.map((row) => {
111
- const selected = current !== null && current === ((row.path ?? '').replace(/\/$/, '') || '/')
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
- <Card
114
- key={row.id}
115
- as="button"
116
- padding={2}
117
- radius={2}
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={0} muted textOverflow="ellipsis">
145
- {row.path}
239
+ <Text size={1}>
240
+ <FolderIcon />
146
241
  </Text>
147
- </Stack>
148
- {row.status !== 'published' && <StatusBadge status={row.status} />}
149
- </Flex>
150
- </Card>
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>