@nocode-factory/sanity-kit 2.31.0 → 2.32.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocode-factory/sanity-kit",
3
- "version": "2.31.0",
3
+ "version": "2.32.0",
4
4
  "description": "Outils Studio de NoCode Factory : Pages (liste + board), Composants, Historique",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
package/src/index.ts CHANGED
@@ -259,6 +259,7 @@ export {
259
259
  export type {PreviewPerspective, PresentationOptions} from './lib/studioLinks'
260
260
  export {usePreviewTarget} from './context/PreviewTargetContext'
261
261
  export {NcfPreviewHeader, ncfPreviewComponents} from './tools/presentation/PreviewHeader'
262
+ export {ncfPresentationComponents} from './tools/presentation/PagesNavigator'
262
263
  export {NcfPreviewLauncher, createPreviewLauncher} from './tools/navbar/PreviewLauncher'
263
264
  export {NcfKitUpdate} from './tools/navbar/KitUpdate'
264
265
  export {useKitUpdate} from './hooks/useKitUpdate'
@@ -0,0 +1,143 @@
1
+ import {useMemo, useState, type ComponentType} from 'react'
2
+ import {Box, Card, Flex, Select, Spinner, Stack, Text, TextInput} from '@sanity/ui'
3
+ import {SearchIcon} from '@sanity/icons/Search'
4
+ import {usePresentationNavigate, usePresentationParams} from 'sanity/presentation'
5
+ import type {NcfKitConfig} from '../../config/types'
6
+ import {resolveConfig} from '../../config/resolve'
7
+ import {validateConfig} from '../../config/validate'
8
+ import {KitProvider, useKitConfig} from '../../context/KitContext'
9
+ import {usePages} from '../../hooks/usePages'
10
+ import {localeOfPreview} from '../../lib/previewLocale'
11
+ import {StatusBadge} from '../../ui/StatusBadge'
12
+
13
+ const pathOf = (preview: string | undefined | null): string | null => {
14
+ if (!preview) return null
15
+ try {
16
+ return new URL(preview, 'http://preview.local').pathname.replace(/\/$/, '') || '/'
17
+ } catch {
18
+ return null
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Liste des pages à gauche de l'aperçu (Presentation) : passer d'une page à l'autre
24
+ * sans repasser par Structure. Langue de la page affichée par défaut, recherche par
25
+ * titre ou adresse ; un clic ouvre la page dans l'aperçu ET son document à côté.
26
+ */
27
+ function PagesNavigator() {
28
+ const config = useKitConfig()
29
+ const {rows, loading} = usePages()
30
+ const params = usePresentationParams(false)
31
+ const navigate = usePresentationNavigate()
32
+ const i18n = config.i18n
33
+ const shownLocale = localeOfPreview(params?.preview, i18n)
34
+ const [locale, setLocale] = useState<string | null>(null)
35
+ const [search, setSearch] = useState('')
36
+ const activeLocale = locale ?? shownLocale ?? ''
37
+ const current = pathOf(params?.preview)
38
+
39
+ const visible = useMemo(() => {
40
+ const q = search.trim().toLowerCase()
41
+ return rows
42
+ .filter((r) => r.path !== null)
43
+ .filter((r) => !i18n || !activeLocale || r.locale === activeLocale)
44
+ .filter((r) => !q || r.title.toLowerCase().includes(q) || (r.path ?? '').toLowerCase().includes(q))
45
+ .sort((a, b) => (a.path ?? '').localeCompare(b.path ?? ''))
46
+ }, [rows, search, activeLocale, i18n])
47
+
48
+ return (
49
+ <Card height="fill" borderRight style={{display: 'flex', flexDirection: 'column', minHeight: 0}}>
50
+ <Stack gap={2} padding={2} style={{flex: 'none'}}>
51
+ <Text size={1} weight="semibold">
52
+ Pages
53
+ </Text>
54
+ <Flex gap={2}>
55
+ <Box flex={1}>
56
+ <TextInput
57
+ icon={SearchIcon}
58
+ fontSize={1}
59
+ padding={2}
60
+ placeholder="Search"
61
+ value={search}
62
+ onChange={(e) => setSearch(e.currentTarget.value)}
63
+ />
64
+ </Box>
65
+ {i18n && i18n.locales.length > 1 && (
66
+ <Select fontSize={1} padding={2} value={activeLocale} onChange={(e) => setLocale(e.currentTarget.value)} style={{width: 72}}>
67
+ {i18n.locales.map((code) => (
68
+ <option key={code} value={code}>
69
+ {code.toUpperCase()}
70
+ </option>
71
+ ))}
72
+ </Select>
73
+ )}
74
+ </Flex>
75
+ </Stack>
76
+ <Box flex={1} style={{overflowY: 'auto', minHeight: 0}}>
77
+ {loading && !rows.length ? (
78
+ <Flex justify="center" padding={4}>
79
+ <Spinner muted />
80
+ </Flex>
81
+ ) : (
82
+ <Stack gap={1} padding={1}>
83
+ {visible.map((row) => {
84
+ const selected = current !== null && current === ((row.path ?? '').replace(/\/$/, '') || '/')
85
+ return (
86
+ <Card
87
+ key={row.id}
88
+ as="button"
89
+ padding={2}
90
+ radius={2}
91
+ tone={selected ? 'primary' : 'default'}
92
+ pressed={selected}
93
+ style={{textAlign: 'left', cursor: 'pointer', border: 0, width: '100%'}}
94
+ onClick={() => navigate(row.path ?? undefined, {type: row.type, id: row.id})}
95
+ >
96
+ <Flex align="center" gap={2}>
97
+ <Stack gap={1} flex={1} style={{minWidth: 0}}>
98
+ <Text size={1} weight={selected ? 'semibold' : 'regular'} textOverflow="ellipsis">
99
+ {row.title || row.path}
100
+ </Text>
101
+ <Text size={0} muted textOverflow="ellipsis">
102
+ {row.path}
103
+ </Text>
104
+ </Stack>
105
+ {row.status !== 'published' && <StatusBadge status={row.status} />}
106
+ </Flex>
107
+ </Card>
108
+ )
109
+ })}
110
+ {!visible.length && (
111
+ <Box padding={3}>
112
+ <Text size={1} muted>
113
+ No page.
114
+ </Text>
115
+ </Box>
116
+ )}
117
+ </Stack>
118
+ )}
119
+ </Box>
120
+ </Card>
121
+ )
122
+ }
123
+
124
+ /**
125
+ * Composants à passer à `presentationTool` : liste des pages à gauche de l'aperçu
126
+ * (bouton intégré de Presentation pour l'afficher ou la masquer).
127
+ *
128
+ * ```ts
129
+ * presentationTool({components: ncfPresentationComponents(ncfOptions), ...})
130
+ * ```
131
+ */
132
+ export function ncfPresentationComponents(options: NcfKitConfig): {unstable_navigator: {component: ComponentType; minWidth: number; maxWidth: number}} {
133
+ const config = resolveConfig(options)
134
+ const issues = validateConfig(config)
135
+ function NcfPagesNavigator() {
136
+ return (
137
+ <KitProvider config={config} issues={issues}>
138
+ <PagesNavigator />
139
+ </KitProvider>
140
+ )
141
+ }
142
+ return {unstable_navigator: {component: NcfPagesNavigator, minWidth: 220, maxWidth: 420}}
143
+ }
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.31.0'
6
+ export const KIT_VERSION = '2.32.0'