@nocode-factory/sanity-kit 2.52.0 → 2.53.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.
@@ -31,7 +31,7 @@ export function PagesTool() {
31
31
  const config = useKitConfig()
32
32
  const router = useRouter()
33
33
 
34
- const {byId, saveColumns, patchNode, patchField} = useBoardLayout()
34
+ const {byId, saveColumns, patchNode, patchField, pageOrder} = useBoardLayout()
35
35
  const columnOptions = useColumnOptions()
36
36
  const preview = usePreviewTarget()
37
37
  const columns = useInternalColumns()
@@ -45,9 +45,11 @@ export function PagesTool() {
45
45
  const [onlyTodo, setOnlyTodo] = useState(false)
46
46
  const [groupBy, setGroupBy] = useState<GroupBy>('none')
47
47
  const [rawColorBy, setColorBy] = useState<ColorBy>('tag')
48
- // L'ordre du Studio par défaut : aucune colonne n'est marquée triée tant
49
- // que l'éditeur n'en a pas choisi une.
50
- const [sortKey, setSortKey] = useState<SortKey>('structure')
48
+ // `null` = tri automatique : l'ordre manuel (réordonné dans Presentation)
49
+ // s'il existe, sinon l'ordre du Studio. Un clic sur une colonne fige un tri
50
+ // explicite. Aucune colonne n'est marquée triée tant que l'éditeur n'a pas
51
+ // choisi.
52
+ const [sortKey, setSortKey] = useState<SortKey | null>(null)
51
53
  const [sortDirection, setSortDirection] = useState<SortDirection>('asc')
52
54
  const [page, setPage] = useState(0)
53
55
  const [hidden, setHidden] = useState<ReadonlySet<string>>(new Set())
@@ -79,15 +81,19 @@ export function PagesTool() {
79
81
  [config.i18n, rows],
80
82
  )
81
83
 
84
+ // Tri effectif : l'ordre manuel partagé avec Presentation par défaut, sinon
85
+ // l'ordre du Studio ; un clic sur une colonne prend le dessus.
86
+ const effectiveSortKey: SortKey = sortKey ?? (pageOrder.length > 0 ? 'manual' : 'structure')
87
+
82
88
  const visible = useMemo(
83
89
  () =>
84
90
  sortRows(
85
91
  filterRows(rows, {search, locales: locale ? [locale] : undefined}).filter((row) => !onlyTodo || todos.has(row.id)),
86
- sortKey,
92
+ effectiveSortKey,
87
93
  sortDirection,
88
- {typeOrder: config.pageTypeNames},
94
+ {typeOrder: config.pageTypeNames, pageOrder},
89
95
  ),
90
- [rows, search, locale, onlyTodo, todos, sortKey, sortDirection, config.pageTypeNames],
96
+ [rows, search, locale, onlyTodo, todos, effectiveSortKey, sortDirection, config.pageTypeNames, pageOrder],
91
97
  )
92
98
 
93
99
  // Un filtre qui réduit la liste ne doit pas laisser l'utilisateur sur une
@@ -134,7 +140,7 @@ export function PagesTool() {
134
140
  })
135
141
 
136
142
  const onSort = (key: SortKey) => {
137
- if (key === sortKey) setSortDirection((d) => (d === 'asc' ? 'desc' : 'asc'))
143
+ if (key === effectiveSortKey) setSortDirection((d) => (d === 'asc' ? 'desc' : 'asc'))
138
144
  else {
139
145
  setSortKey(key)
140
146
  setSortDirection('asc')
@@ -330,7 +336,7 @@ export function PagesTool() {
330
336
  ) : (
331
337
  <PagesTable
332
338
  groups={groups}
333
- sortKey={sortKey}
339
+ sortKey={effectiveSortKey}
334
340
  sortDirection={sortDirection}
335
341
  onSort={onSort}
336
342
  columns={columns}
@@ -1,13 +1,16 @@
1
1
  import {useMemo, useState, type ComponentType} from 'react'
2
2
  import {Box, Button, Card, Flex, Spinner, Stack, Text, TextInput} from '@sanity/ui'
3
3
  import {SearchIcon} from '@sanity/icons/Search'
4
+ import {DragHandleIcon} from '@sanity/icons/DragHandle'
4
5
  import {usePresentationNavigate, usePresentationParams} from 'sanity/presentation'
5
6
  import type {NcfKitConfig} from '../../config/types'
6
7
  import {resolveConfig} from '../../config/resolve'
7
8
  import {validateConfig} from '../../config/validate'
8
9
  import {KitProvider, useKitConfig} from '../../context/KitContext'
10
+ import {BoardLayoutProvider, useBoardLayout} from '../../context/BoardLayoutContext'
9
11
  import {usePages} from '../../hooks/usePages'
10
12
  import {localeOfPreview} from '../../lib/previewLocale'
13
+ import {orderByIds, reorderBefore} from '../../lib/pageOrder'
11
14
  import {StatusBadge} from '../../ui/StatusBadge'
12
15
  import {NcfPresentationHeader} from './PresentationHeader'
13
16
 
@@ -28,25 +31,38 @@ const pathOf = (preview: string | undefined | null): string | null => {
28
31
  function PagesNavigator() {
29
32
  const config = useKitConfig()
30
33
  const {rows, loading} = usePages()
34
+ const {pageOrder, savePageOrder} = useBoardLayout()
31
35
  const params = usePresentationParams(false)
32
36
  const navigate = usePresentationNavigate()
33
37
  const i18n = config.i18n
34
38
  const shownLocale = localeOfPreview(params?.preview, i18n)
35
39
  const [locale, setLocale] = useState<string | null>(null)
36
40
  const [search, setSearch] = useState('')
41
+ const [dragId, setDragId] = useState<string | null>(null)
37
42
  // Langue choisie, sinon celle de la page affichée, sinon la langue principale :
38
43
  // le menu montre toujours la langue réellement filtrée.
39
44
  const activeLocale = locale ?? shownLocale ?? i18n?.defaultLocale ?? ''
40
45
  const current = pathOf(params?.preview)
41
46
 
47
+ // Ordre de base : alphabétique par adresse, puis l'ordre manuel passe devant.
48
+ const withPath = useMemo(() => rows.filter((r) => r.path !== null).sort((a, b) => (a.path ?? '').localeCompare(b.path ?? '')), [rows])
49
+
42
50
  const visible = useMemo(() => {
43
51
  const q = search.trim().toLowerCase()
44
- return rows
45
- .filter((r) => r.path !== null)
52
+ const filtered = withPath
46
53
  .filter((r) => !i18n || !activeLocale || !r.locale || r.locale === activeLocale)
47
54
  .filter((r) => !q || r.title.toLowerCase().includes(q) || (r.path ?? '').toLowerCase().includes(q))
48
- .sort((a, b) => (a.path ?? '').localeCompare(b.path ?? ''))
49
- }, [rows, search, activeLocale, i18n])
55
+ return orderByIds(filtered, pageOrder)
56
+ }, [withPath, search, activeLocale, i18n, pageOrder])
57
+
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.
60
+ const onReorder = (targetId: string | null) => {
61
+ if (!dragId) return
62
+ const fullIds = orderByIds(withPath, pageOrder).map((r) => r.id)
63
+ savePageOrder(reorderBefore(fullIds, dragId, targetId))
64
+ setDragId(null)
65
+ }
50
66
 
51
67
  return (
52
68
  <Card height="fill" borderRight style={{display: 'flex', flexDirection: 'column', minHeight: 0}}>
@@ -101,10 +117,26 @@ function PagesNavigator() {
101
117
  radius={2}
102
118
  tone={selected ? 'primary' : 'default'}
103
119
  pressed={selected}
104
- style={{textAlign: 'left', cursor: 'pointer', border: 0, width: '100%'}}
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}}
105
134
  onClick={() => navigate(row.path ?? undefined, {type: row.type, id: row.id})}
106
135
  >
107
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>
108
140
  <Stack gap={1} flex={1} style={{minWidth: 0}}>
109
141
  <Text size={1} weight={selected ? 'semibold' : 'regular'} textOverflow="ellipsis">
110
142
  {row.title || row.path}
@@ -118,6 +150,17 @@ function PagesNavigator() {
118
150
  </Card>
119
151
  )
120
152
  })}
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}
121
164
  {!visible.length && (
122
165
  <Box padding={3}>
123
166
  <Text size={1} muted>
@@ -150,7 +193,9 @@ export function ncfPresentationComponents(options: NcfKitConfig): {
150
193
  function NcfPagesNavigator() {
151
194
  return (
152
195
  <KitProvider config={config} issues={issues}>
153
- <PagesNavigator />
196
+ <BoardLayoutProvider>
197
+ <PagesNavigator />
198
+ </BoardLayoutProvider>
154
199
  </KitProvider>
155
200
  )
156
201
  }
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
4
4
  * le vérifie.
5
5
  */
6
- export const KIT_VERSION = '2.52.0'
6
+ export const KIT_VERSION = '2.53.0'