@nocode-factory/sanity-kit 2.0.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 (95) hide show
  1. package/bin/ncf-kit.mjs +201 -0
  2. package/dist/index.d.ts +1643 -0
  3. package/dist/index.js +6632 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/web-server.d.ts +46 -0
  6. package/dist/web-server.js +51 -0
  7. package/dist/web-server.js.map +1 -0
  8. package/dist/web.d.ts +27 -0
  9. package/dist/web.js +117 -0
  10. package/dist/web.js.map +1 -0
  11. package/package.json +90 -0
  12. package/scripts/use-client.mjs +20 -0
  13. package/src/config/defaults.ts +74 -0
  14. package/src/config/resolve.ts +153 -0
  15. package/src/config/types.ts +290 -0
  16. package/src/config/validate.ts +193 -0
  17. package/src/context/BoardLayoutContext.tsx +24 -0
  18. package/src/context/KitContext.tsx +30 -0
  19. package/src/context/PreviewTargetContext.tsx +27 -0
  20. package/src/hooks/useAnnotations.ts +60 -0
  21. package/src/hooks/useBoardLayout.ts +398 -0
  22. package/src/hooks/useColumnOptions.ts +47 -0
  23. package/src/hooks/useDocumentColumns.ts +61 -0
  24. package/src/hooks/useHistory.ts +89 -0
  25. package/src/hooks/useInternalColumns.ts +19 -0
  26. package/src/hooks/useKitClient.ts +15 -0
  27. package/src/hooks/useOccurrences.ts +62 -0
  28. package/src/hooks/usePageContents.ts +65 -0
  29. package/src/hooks/usePages.ts +41 -0
  30. package/src/hooks/usePreviewTarget.ts +162 -0
  31. package/src/hooks/useQueryData.ts +103 -0
  32. package/src/hooks/useRegistration.ts +50 -0
  33. package/src/index.ts +280 -0
  34. package/src/lib/blocks.ts +38 -0
  35. package/src/lib/colors.ts +103 -0
  36. package/src/lib/columns.ts +137 -0
  37. package/src/lib/diff.ts +200 -0
  38. package/src/lib/elkLayout.ts +124 -0
  39. package/src/lib/graph.ts +238 -0
  40. package/src/lib/grouping.ts +116 -0
  41. package/src/lib/links.ts +70 -0
  42. package/src/lib/occurrences.ts +93 -0
  43. package/src/lib/pageThumbnail.ts +43 -0
  44. package/src/lib/pages.ts +199 -0
  45. package/src/lib/paths.ts +68 -0
  46. package/src/lib/query.ts +113 -0
  47. package/src/lib/schemaColumns.ts +162 -0
  48. package/src/lib/schemaTypes.ts +75 -0
  49. package/src/lib/sectionsMap.ts +83 -0
  50. package/src/lib/service.ts +88 -0
  51. package/src/lib/siteRoutes.ts +43 -0
  52. package/src/lib/status.ts +122 -0
  53. package/src/lib/studioLinks.ts +137 -0
  54. package/src/schema/boardLayout.ts +190 -0
  55. package/src/tools/components/BlockCard.tsx +79 -0
  56. package/src/tools/components/ComponentsTool.tsx +171 -0
  57. package/src/tools/components/map/SectionNode.tsx +109 -0
  58. package/src/tools/components/map/SectionsMap.tsx +339 -0
  59. package/src/tools/createToolComponent.tsx +67 -0
  60. package/src/tools/history/ChangeRow.tsx +87 -0
  61. package/src/tools/history/DiffPanel.tsx +227 -0
  62. package/src/tools/history/HistoryTool.tsx +230 -0
  63. package/src/tools/more/MoreTool.tsx +82 -0
  64. package/src/tools/pages/ColumnHeader.tsx +216 -0
  65. package/src/tools/pages/ColumnVisibility.tsx +173 -0
  66. package/src/tools/pages/FieldValue.tsx +327 -0
  67. package/src/tools/pages/PagesTable.tsx +394 -0
  68. package/src/tools/pages/PagesTool.tsx +333 -0
  69. package/src/tools/pages/PagesToolbar.tsx +53 -0
  70. package/src/tools/pages/PathCell.tsx +71 -0
  71. package/src/tools/pages/PreviewTarget.tsx +226 -0
  72. package/src/tools/pages/TagCell.tsx +124 -0
  73. package/src/tools/pages/ViewTabs.tsx +57 -0
  74. package/src/tools/pages/board/BoardView.tsx +661 -0
  75. package/src/tools/pages/board/PageNode.tsx +306 -0
  76. package/src/tools/pages/board/PagePanel.tsx +228 -0
  77. package/src/tools/presentation/PreviewHeader.tsx +75 -0
  78. package/src/tools/shared/AnnotationNode.tsx +126 -0
  79. package/src/ui/ActorName.tsx +20 -0
  80. package/src/ui/ConfigIssues.tsx +41 -0
  81. package/src/ui/InlineCode.tsx +22 -0
  82. package/src/ui/Popover.tsx +85 -0
  83. package/src/ui/ProjectStatusNotice.tsx +58 -0
  84. package/src/ui/QueryError.tsx +16 -0
  85. package/src/ui/QuietInput.tsx +64 -0
  86. package/src/ui/StatusBadge.tsx +11 -0
  87. package/src/ui/ToolPlaceholder.tsx +23 -0
  88. package/src/ui/formatDate.ts +14 -0
  89. package/src/ui/tokens.ts +54 -0
  90. package/src/version.ts +5 -0
  91. package/src/web/PreviewBanner.tsx +115 -0
  92. package/src/web/draftModeToggle.ts +56 -0
  93. package/src/web/environment.ts +21 -0
  94. package/src/web/index.ts +15 -0
  95. package/src/web/server.ts +11 -0
@@ -0,0 +1,67 @@
1
+ import {Box, Stack} from '@sanity/ui'
2
+ import type {ComponentType} from 'react'
3
+ import type {Tool} from 'sanity'
4
+ import {KitProvider} from '../context/KitContext'
5
+ import {BoardLayoutProvider} from '../context/BoardLayoutContext'
6
+ import {PreviewTargetProvider} from '../context/PreviewTargetContext'
7
+ import {ConfigIssues} from '../ui/ConfigIssues'
8
+ import {useRegistration} from '../hooks/useRegistration'
9
+ import {ProjectStatusNotice} from '../ui/ProjectStatusNotice'
10
+ import {issuesForTool} from '../config/validate'
11
+ import type {ConfigIssue, NcfToolName, ResolvedKitConfig} from '../config/types'
12
+
13
+ export interface CreateToolComponentArgs {
14
+ name: NcfToolName
15
+ title: string
16
+ config: ResolvedKitConfig
17
+ issues: ConfigIssue[]
18
+ Component: ComponentType
19
+ }
20
+
21
+ /**
22
+ * Signale la présence du Studio et rend l'avis qui en découle.
23
+ *
24
+ * Monté dans l'enveloppe plutôt que dans chaque outil : le signalement doit
25
+ * avoir lieu quel que soit l'onglet ouvert, et une seule fois.
26
+ */
27
+ function Registered() {
28
+ const registration = useRegistration()
29
+ return <ProjectStatusNotice registration={registration} />
30
+ }
31
+
32
+ /** Props que le Studio passe au composant racine d'un outil. */
33
+ export interface ToolComponentProps {
34
+ tool: Tool
35
+ }
36
+
37
+ /**
38
+ * Enveloppe commune aux trois outils : fournit la configuration, affiche les
39
+ * problèmes qui concernent cet outil, et ne monte son contenu que si rien ne
40
+ * le bloque. Un `ncfKit()` mal configuré n'empêche jamais le Studio de
41
+ * démarrer : il rend un message dans l'onglet fautif.
42
+ */
43
+ export function createToolComponent(
44
+ args: CreateToolComponentArgs,
45
+ ): ComponentType<ToolComponentProps> {
46
+ const {name, title, config, issues, Component} = args
47
+ const scoped = issuesForTool(issues, name)
48
+ const blocking = scoped.some((issue) => issue.level === 'error')
49
+
50
+ return function NcfToolRoot() {
51
+ return (
52
+ <KitProvider config={config} issues={issues}>
53
+ <BoardLayoutProvider>
54
+ <PreviewTargetProvider>
55
+ <Box padding={4} height="fill" overflow="auto">
56
+ <Stack gap={4}>
57
+ <ConfigIssues issues={scoped} toolTitle={title} />
58
+ <Registered />
59
+ {blocking ? null : <Component />}
60
+ </Stack>
61
+ </Box>
62
+ </PreviewTargetProvider>
63
+ </BoardLayoutProvider>
64
+ </KitProvider>
65
+ )
66
+ }
67
+ }
@@ -0,0 +1,87 @@
1
+ import {Box, Flex, Text} from '@sanity/ui'
2
+ import {diffWords, isTextChange, summarize, type Change} from '../../lib/diff'
3
+ import {DIFF, MONO} from '../../ui/tokens'
4
+
5
+ const MARK: Record<'removed' | 'added', {sign: string; line: string; color: string}> = {
6
+ removed: {sign: '−', line: DIFF.removedLine, color: DIFF.removedMark},
7
+ added: {sign: '+', line: DIFF.addedLine, color: DIFF.addedMark},
8
+ }
9
+
10
+ /**
11
+ * Une modification, présentée comme un diff.
12
+ *
13
+ * Deux lignes signées, et pour deux textes, le mot exactement remplacé est
14
+ * surligné dans la ligne. Dire « ce champ a changé » ne dit pas *ce qui* a
15
+ * changé : sur une meta description, l'œil doit tomber sur les deux mots
16
+ * remplacés, pas relire la phrase.
17
+ */
18
+ export function ChangeRow(props: {change: Change}) {
19
+ const {change} = props
20
+ const word = isTextChange(change.before, change.after)
21
+ ? diffWords(change.before as string, change.after as string)
22
+ : null
23
+
24
+ return (
25
+ <Box>
26
+ <Box paddingX={2} paddingY={1}>
27
+ <Text size={0} muted style={MONO} textOverflow="ellipsis" title={change.path}>
28
+ {change.path}
29
+ </Text>
30
+ </Box>
31
+
32
+ {change.kind !== 'added' && (
33
+ <Line
34
+ kind="removed"
35
+ value={change.before}
36
+ segments={word?.filter((segment) => segment.kind !== 'added')}
37
+ />
38
+ )}
39
+ {change.kind !== 'removed' && (
40
+ <Line
41
+ kind="added"
42
+ value={change.after}
43
+ segments={word?.filter((segment) => segment.kind !== 'removed')}
44
+ />
45
+ )}
46
+ </Box>
47
+ )
48
+ }
49
+
50
+ function Line(props: {
51
+ kind: 'removed' | 'added'
52
+ value: unknown
53
+ segments?: {text: string; kind: string}[]
54
+ }) {
55
+ const mark = MARK[props.kind]
56
+ const highlight = props.kind === 'removed' ? DIFF.removedWord : DIFF.addedWord
57
+
58
+ return (
59
+ <Flex gap={2} padding={2} style={{background: mark.line, alignItems: 'flex-start'}}>
60
+ <Box style={{width: 12, flex: 'none'}}>
61
+ <Text size={1} weight="semibold" style={{color: mark.color, ...MONO}}>
62
+ {mark.sign}
63
+ </Text>
64
+ </Box>
65
+ <Box flex={1} style={{minWidth: 0}}>
66
+ <Text size={1} style={{...MONO, whiteSpace: 'pre-wrap', wordBreak: 'break-word'}}>
67
+ {props.segments
68
+ ? props.segments.map((segment, index) => (
69
+ <span
70
+ // Les segments n'ont pas d'identité propre : leur position
71
+ // dans une liste qui ne se réordonne jamais suffit.
72
+ key={index}
73
+ style={
74
+ segment.kind === 'same'
75
+ ? undefined
76
+ : {background: highlight, borderRadius: 2, padding: '0 1px'}
77
+ }
78
+ >
79
+ {segment.text}
80
+ </span>
81
+ ))
82
+ : summarize(props.value, 400)}
83
+ </Text>
84
+ </Box>
85
+ </Flex>
86
+ )
87
+ }
@@ -0,0 +1,227 @@
1
+ import {useEffect, useState} from 'react'
2
+ import {Box, Button, Card, Flex, Spinner, Stack, Text} from '@sanity/ui'
3
+ import {CloseIcon} from '@sanity/icons/Close'
4
+ import {RestoreIcon} from '@sanity/icons/Restore'
5
+ import {IntentLink} from 'sanity/router'
6
+ import {useKitConfig} from '../../context/KitContext'
7
+ import {useKitClient} from '../../hooks/useKitClient'
8
+ import {fetchDetail, type HistoryDetail, type HistoryEvent} from '../../lib/service'
9
+ import {diffDocuments} from '../../lib/diff'
10
+ import {ChangeRow} from './ChangeRow'
11
+ import {BORDER} from '../../ui/tokens'
12
+ import {ActorName} from '../../ui/ActorName'
13
+
14
+ export interface DiffPanelProps {
15
+ event: HistoryEvent
16
+ onClose: () => void
17
+ }
18
+
19
+ /**
20
+ * Ce qui a changé lors d'un événement, et de quoi revenir en arrière.
21
+ *
22
+ * La restauration passe par le client du Studio, donc par les droits de
23
+ * l'éditeur connecté : le kit n'a jamais d'accès en écriture au contenu d'un
24
+ * client, et une restauration reste attribuée à qui l'a demandée.
25
+ */
26
+ export function DiffPanel(props: DiffPanelProps) {
27
+ const {event, onClose} = props
28
+ const config = useKitConfig()
29
+ const client = useKitClient()
30
+
31
+ const [detail, setDetail] = useState<HistoryDetail | null>(null)
32
+ const [loading, setLoading] = useState(true)
33
+ const [error, setError] = useState<string | null>(null)
34
+ const [restoring, setRestoring] = useState(false)
35
+ const [restored, setRestored] = useState<string | null>(null)
36
+
37
+ useEffect(() => {
38
+ if (!config.history) return undefined
39
+ const controller = new AbortController()
40
+ setLoading(true)
41
+ setError(null)
42
+ setRestored(null)
43
+
44
+ fetchDetail(config.history.endpoint, config.history.projectKey, event.id, controller.signal)
45
+ .then((result) => {
46
+ if (!controller.signal.aborted) setDetail(result)
47
+ })
48
+ .catch(() => {
49
+ if (!controller.signal.aborted) setError("Ce détail n'a pas pu être chargé.")
50
+ })
51
+ .finally(() => {
52
+ if (!controller.signal.aborted) setLoading(false)
53
+ })
54
+
55
+ return () => controller.abort()
56
+ }, [config.history, event.id])
57
+
58
+ const snapshot = detail?.current.snapshot ?? null
59
+ const changes = detail ? diffDocuments(detail.previous?.snapshot ?? null, snapshot) : []
60
+
61
+ const restore = async () => {
62
+ if (!snapshot) return
63
+ setRestoring(true)
64
+ setError(null)
65
+ try {
66
+ // `createOrReplace` et non `patch` : un `patch` exige un document
67
+ // existant, et échouerait donc sur une suppression — c'est-à-dire
68
+ // précisément quand une restauration compte le plus.
69
+ //
70
+ // On écrit dans le brouillon, jamais par-dessus la version publiée :
71
+ // l'éditeur relit et publie. Une restauration ne doit pas mettre en
72
+ // ligne un état ancien sans que personne l'ait vu.
73
+ const {_rev, _createdAt, _updatedAt, ...content} = snapshot as Record<string, unknown>
74
+ const base = event.document_id.replace(/^drafts\./, '')
75
+
76
+ await client.createOrReplace({
77
+ ...content,
78
+ _id: `drafts.${base}`,
79
+ _type: event.document_type,
80
+ } as {_id: string; _type: string})
81
+
82
+ setRestored(base)
83
+ } catch (cause) {
84
+ setError(explainRestore(cause))
85
+ } finally {
86
+ setRestoring(false)
87
+ }
88
+ }
89
+
90
+ return (
91
+ <Card radius={3} shadow={1} padding={3} style={{width: 420, flex: 'none', overflow: 'auto'}}>
92
+ <Stack gap={3}>
93
+ <Flex align="flex-start" justify="space-between" gap={2}>
94
+ <Stack gap={2} flex={1} style={{minWidth: 0}}>
95
+ <Text size={1} weight="semibold" textOverflow="ellipsis">
96
+ {event.document_id}
97
+ </Text>
98
+ <Flex gap={2} align="center">
99
+ <Text size={0} muted>
100
+ {new Date(event.occurred_at).toLocaleString('fr-FR')} ·
101
+ </Text>
102
+ <ActorName actorId={event.actor_id} actorName={event.actor_name} />
103
+ </Flex>
104
+ </Stack>
105
+ <Button
106
+ mode="bleed"
107
+ padding={1}
108
+ fontSize={0}
109
+ icon={CloseIcon}
110
+ aria-label="Fermer"
111
+ onClick={onClose}
112
+ />
113
+ </Flex>
114
+
115
+ {loading && (
116
+ <Flex align="center" gap={2} padding={3}>
117
+ <Spinner muted />
118
+ <Text size={1} muted>
119
+ Chargement…
120
+ </Text>
121
+ </Flex>
122
+ )}
123
+
124
+ {error && (
125
+ <Card padding={3} radius={2} tone="critical">
126
+ <Text size={1}>{error}</Text>
127
+ </Card>
128
+ )}
129
+
130
+ {restored && (
131
+ <Card padding={3} radius={2} tone="positive">
132
+ <Stack gap={3}>
133
+ <Text size={1}>
134
+ État restauré <b>en brouillon</b>. Rien n'est encore en ligne : ouvrez le
135
+ document, vérifiez, puis publiez.
136
+ </Text>
137
+ <IntentLink
138
+ intent="edit"
139
+ params={{id: restored, type: event.document_type}}
140
+ style={{textDecoration: 'none'}}
141
+ >
142
+ <Button mode="ghost" fontSize={1} padding={2} text="Ouvrir le brouillon" as="span" />
143
+ </IntentLink>
144
+ </Stack>
145
+ </Card>
146
+ )}
147
+
148
+ {!loading && detail && (
149
+ <>
150
+ {!detail.previous && (
151
+ <Text size={0} muted>
152
+ Premier état connu : tout apparaît comme ajouté.
153
+ </Text>
154
+ )}
155
+
156
+ {changes.length === 0 ? (
157
+ <Text size={1} muted>
158
+ Aucune modification de contenu — seuls des champs système ont bougé.
159
+ </Text>
160
+ ) : (
161
+ <Stack gap={2}>
162
+ <Text size={0} weight="semibold" muted>
163
+ {changes.length} modification{changes.length > 1 ? 's' : ''}
164
+ </Text>
165
+ <Card radius={2} border style={{overflow: 'hidden'}}>
166
+ <Stack>
167
+ {changes.map((change, index) => (
168
+ <Box
169
+ key={change.path}
170
+ style={
171
+ index > 0
172
+ ? {borderTop: `1px solid ${BORDER}`}
173
+ : undefined
174
+ }
175
+ >
176
+ <ChangeRow change={change} />
177
+ </Box>
178
+ ))}
179
+ </Stack>
180
+ </Card>
181
+ </Stack>
182
+ )}
183
+
184
+ {snapshot && (
185
+ <Box style={{borderTop: `1px solid ${BORDER}`, paddingTop: 12}}>
186
+ <Stack gap={2}>
187
+ <Button
188
+ mode="ghost"
189
+ tone="caution"
190
+ fontSize={1}
191
+ padding={3}
192
+ icon={RestoreIcon}
193
+ text={restoring ? 'Restauration…' : 'Restaurer cet état'}
194
+ disabled={restoring}
195
+ onClick={restore}
196
+ />
197
+ <Text size={0} muted>
198
+ Recrée cet état dans le brouillon du document, avec vos droits. La
199
+ version en ligne n'est pas touchée tant que vous ne publiez pas. Un
200
+ brouillon en cours serait remplacé.
201
+ </Text>
202
+ </Stack>
203
+ </Box>
204
+ )}
205
+ </>
206
+ )}
207
+ </Stack>
208
+ </Card>
209
+ )
210
+ }
211
+
212
+
213
+
214
+ /** Traduit l'échec d'une restauration en une phrase actionnable. */
215
+ function explainRestore(cause: unknown): string {
216
+ const message = cause instanceof Error ? cause.message : String(cause)
217
+ if (/permission|insufficient|not allowed/i.test(message)) {
218
+ return "Vos droits sur ce dataset ne permettent pas d'écrire ce document."
219
+ }
220
+ if (/schema|unknown type|invalid/i.test(message)) {
221
+ return (
222
+ "Cet état ne correspond plus au schéma actuel : le type a changé depuis. " +
223
+ 'Restauration impossible sans intervention.'
224
+ )
225
+ }
226
+ return `La restauration a échoué, rien n'a été modifié. (${message.slice(0, 120)})`
227
+ }
@@ -0,0 +1,230 @@
1
+ import {useMemo, useState} from 'react'
2
+ import {Badge, Box, Button, Card, Flex, Spinner, Stack, Text, TextInput} from '@sanity/ui'
3
+ import {RefreshIcon} from '@sanity/icons/Refresh'
4
+ import {useKitConfig} from '../../context/KitContext'
5
+ import {useHistory} from '../../hooks/useHistory'
6
+ import {DiffPanel} from './DiffPanel'
7
+ import {BORDER, MONO} from '../../ui/tokens'
8
+ import {ActorName} from '../../ui/ActorName'
9
+ import type {HistoryEvent} from '../../lib/service'
10
+
11
+ const OPERATION: Record<string, {label: string; tone: 'positive' | 'primary' | 'critical'}> = {
12
+ create: {label: 'création', tone: 'positive'},
13
+ update: {label: 'modification', tone: 'primary'},
14
+ delete: {label: 'suppression', tone: 'critical'},
15
+ }
16
+
17
+ type Scope = 'all' | 'published'
18
+
19
+ /**
20
+ * Modifier dans le Studio écrit un brouillon ; publier touche la version en
21
+ * ligne. Les deux sont enregistrés, et la distinction est le premier tri
22
+ * qu'on veut faire : « qu'est-ce qui est parti en ligne ? » n'est pas
23
+ * « qu'est-ce qui a été touché ? ».
24
+ */
25
+ const SCOPES: {id: Scope; label: string}[] = [
26
+ {id: 'all', label: 'Tout'},
27
+ {id: 'published', label: 'En ligne'},
28
+ ]
29
+
30
+ /** Journal des modifications du dataset, alimenté par les webhooks Sanity. */
31
+ export function HistoryTool() {
32
+ const config = useKitConfig()
33
+ const [search, setSearch] = useState('')
34
+ const [selected, setSelected] = useState<HistoryEvent | null>(null)
35
+ const [scope, setScope] = useState<Scope>('all')
36
+ const {events, loading, error, hasMore, loadMore, refresh} = useHistory()
37
+
38
+ const visible = useMemo(() => {
39
+ const scoped = scope === 'published' ? events.filter((event) => !event.is_draft) : events
40
+ const needle = search.trim().toLowerCase()
41
+ if (!needle) return scoped
42
+ return scoped.filter(
43
+ (event) =>
44
+ event.document_id.toLowerCase().includes(needle) ||
45
+ event.document_type.toLowerCase().includes(needle) ||
46
+ (event.actor_name ?? '').toLowerCase().includes(needle) ||
47
+ (event.actor_id ?? '').toLowerCase().includes(needle),
48
+ )
49
+ }, [events, search, scope])
50
+
51
+ if (!config.history) {
52
+ return (
53
+ <Box padding={4}>
54
+ <Card padding={4} radius={3} tone="caution">
55
+ <Stack gap={3}>
56
+ <Text size={1} weight="semibold">
57
+ Historique non configuré
58
+ </Text>
59
+ <Text size={1}>
60
+ Aucune clé de lecture. Dans le dossier du studio, la commande suivante active le projet,
61
+ écrit la clé dans <code>.env</code> et crée le webhook du journal :
62
+ </Text>
63
+ <Text size={0} style={MONO}>
64
+ npx ncf-kit setup --types page,homePage
65
+ </Text>
66
+ <Text size={0} muted>
67
+ Puis <code>history: {'{'}projectKey: process.env.SANITY_STUDIO_NCF_PROJECT_KEY{'}'}</code> dans
68
+ sanity.config.ts et redéployez le studio. Ou masquez cet onglet avec{' '}
69
+ <code>tools: {'{'}history: false{'}'}</code>.
70
+ </Text>
71
+ </Stack>
72
+ </Card>
73
+ </Box>
74
+ )
75
+ }
76
+
77
+ return (
78
+ <Flex gap={3} padding={4} style={{height: '100%', alignItems: 'flex-start'}}>
79
+ <Stack gap={3} flex={1} style={{minWidth: 0}}>
80
+ <Flex gap={2} align="center">
81
+ <Box flex={1}>
82
+ <TextInput
83
+ fontSize={1}
84
+ padding={3}
85
+ radius={2}
86
+ placeholder="Filtrer par document, type ou auteur…"
87
+ value={search}
88
+ onChange={(event) => setSearch(event.currentTarget.value)}
89
+ />
90
+ </Box>
91
+ <Flex gap={1} style={{flex: 'none'}}>
92
+ {SCOPES.map((option) => (
93
+ <Button
94
+ key={option.id}
95
+ mode={scope === option.id ? 'default' : 'bleed'}
96
+ fontSize={1}
97
+ padding={3}
98
+ text={option.label}
99
+ onClick={() => setScope(option.id)}
100
+ />
101
+ ))}
102
+ </Flex>
103
+ <Button
104
+ mode="bleed"
105
+ fontSize={1}
106
+ padding={3}
107
+ icon={RefreshIcon}
108
+ text="Actualiser"
109
+ onClick={refresh}
110
+ />
111
+ </Flex>
112
+
113
+ {error && (
114
+ <Card padding={3} radius={2} tone="critical">
115
+ <Text size={1}>{error}</Text>
116
+ </Card>
117
+ )}
118
+
119
+ {loading && events.length === 0 && (
120
+ <Flex align="center" gap={2} padding={4}>
121
+ <Spinner muted />
122
+ <Text size={1} muted>
123
+ Chargement du journal…
124
+ </Text>
125
+ </Flex>
126
+ )}
127
+
128
+ {!loading && !error && events.length === 0 && (
129
+ <Card padding={4} radius={3} tone="transparent" border>
130
+ <Stack gap={3}>
131
+ <Text size={1} weight="semibold">
132
+ Aucun changement enregistré
133
+ </Text>
134
+ <Text size={1} muted>
135
+ Le journal se remplit à partir du webhook Sanity de ce projet. S'il vient
136
+ d'être posé, seules les modifications à venir y figureront : rien n'est
137
+ reconstitué rétroactivement. Vérifiez aussi que le webhook vise bien le
138
+ dataset de ce Studio.
139
+ </Text>
140
+ </Stack>
141
+ </Card>
142
+ )}
143
+
144
+ {visible.length > 0 && (
145
+ <Card radius={3} shadow={1} padding={0} style={{overflow: 'hidden'}}>
146
+ <Stack>
147
+ {visible.map((event) => {
148
+ const kind = OPERATION[event.operation] ?? OPERATION.update
149
+ const active = selected?.id === event.id
150
+ return (
151
+ <Flex
152
+ key={event.id}
153
+ align="center"
154
+ gap={3}
155
+ padding={3}
156
+ onClick={() => setSelected(active ? null : event)}
157
+ style={{
158
+ cursor: 'pointer',
159
+ borderBottom: `1px solid ${BORDER}`,
160
+ background: active
161
+ ? 'var(--card-muted-bg-color, rgba(127,127,127,0.12))'
162
+ : 'transparent',
163
+ }}
164
+ >
165
+ <Box style={{width: 96, flex: 'none'}}>
166
+ <Badge tone={kind?.tone} fontSize={0} padding={1}>
167
+ {kind?.label}
168
+ </Badge>
169
+ </Box>
170
+ <Box style={{width: 76, flex: 'none'}}>
171
+ {/* Ce qui est en ligne se distingue d'un travail en
172
+ cours : c'est la question qu'on se pose en premier. */}
173
+ <Badge
174
+ tone={event.is_draft ? 'caution' : 'positive'}
175
+ fontSize={0}
176
+ padding={1}
177
+ >
178
+ {event.is_draft ? 'brouillon' : 'en ligne'}
179
+ </Badge>
180
+ </Box>
181
+ <Box flex={1} style={{minWidth: 0}}>
182
+ <Text size={1} textOverflow="ellipsis" style={MONO}>
183
+ {event.document_id}
184
+ </Text>
185
+ </Box>
186
+ <Box style={{width: 140, flex: 'none'}}>
187
+ <ActorName actorId={event.actor_id} actorName={event.actor_name} />
188
+ </Box>
189
+ <Box style={{width: 140, flex: 'none'}}>
190
+ <Text size={0} muted>
191
+ {new Date(event.occurred_at).toLocaleString('fr-FR', {
192
+ day: '2-digit',
193
+ month: '2-digit',
194
+ hour: '2-digit',
195
+ minute: '2-digit',
196
+ })}
197
+ </Text>
198
+ </Box>
199
+ </Flex>
200
+ )
201
+ })}
202
+ </Stack>
203
+ </Card>
204
+ )}
205
+
206
+ {hasMore && !search && (
207
+ <Flex justify="center">
208
+ <Button
209
+ mode="ghost"
210
+ fontSize={1}
211
+ padding={3}
212
+ text={loading ? 'Chargement…' : 'Charger plus'}
213
+ disabled={loading}
214
+ onClick={loadMore}
215
+ />
216
+ </Flex>
217
+ )}
218
+
219
+ {search && visible.length === 0 && events.length > 0 && (
220
+ <Text size={1} muted>
221
+ Aucun événement ne correspond. Le filtre ne porte que sur les événements déjà
222
+ chargés.
223
+ </Text>
224
+ )}
225
+ </Stack>
226
+
227
+ {selected && <DiffPanel event={selected} onClose={() => setSelected(null)} />}
228
+ </Flex>
229
+ )
230
+ }
@@ -0,0 +1,82 @@
1
+ import {useState, type ComponentType} from 'react'
2
+ import type {Tool} from 'sanity'
3
+ import {Box, Card, Flex, Tab, TabList, TabPanel} from '@sanity/ui'
4
+ import {EllipsisHorizontalIcon} from '@sanity/icons/EllipsisHorizontal'
5
+
6
+ /** Nom de l'onglet « Plus » dans la barre du Studio. */
7
+ export const NCF_MORE_TOOL = 'ncf-more'
8
+
9
+ /** Outils qu'on range par défaut : utiles aux développeurs, pas aux éditeurs. */
10
+ export const DEFAULT_MORE_TOOLS = ['vision', 'releases']
11
+
12
+ interface MoreToolOptions {
13
+ tools: Tool[]
14
+ }
15
+
16
+ /**
17
+ * Onglet « Plus » : les outils rarement ouverts vivent dans des sous-onglets,
18
+ * avec leur composant d'origine. Seul leur emplacement change.
19
+ */
20
+ function MoreToolComponent(props: {tool: Tool<MoreToolOptions>}) {
21
+ const tools = props.tool.options?.tools ?? []
22
+ const [current, setCurrent] = useState(tools[0]?.name)
23
+ const active = tools.find((tool) => tool.name === current) ?? tools[0]
24
+ const Component = active?.component as ComponentType<{tool: Tool}> | undefined
25
+
26
+ return (
27
+ <Flex direction="column" height="fill">
28
+ <Card borderBottom paddingX={3} paddingTop={2}>
29
+ <TabList gap={1}>
30
+ {tools.map((tool) => (
31
+ <Tab
32
+ key={tool.name}
33
+ id={`ncf-more-tab-${tool.name}`}
34
+ aria-controls={`ncf-more-panel-${tool.name}`}
35
+ label={typeof tool.title === 'string' ? tool.title : tool.name}
36
+ selected={active?.name === tool.name}
37
+ onClick={() => setCurrent(tool.name)}
38
+ />
39
+ ))}
40
+ </TabList>
41
+ </Card>
42
+ <Box flex={1} style={{minHeight: 0, overflow: 'auto'}}>
43
+ {active && Component ? (
44
+ <TabPanel
45
+ id={`ncf-more-panel-${active.name}`}
46
+ aria-labelledby={`ncf-more-tab-${active.name}`}
47
+ style={{height: '100%'}}
48
+ >
49
+ <Component tool={active} />
50
+ </TabPanel>
51
+ ) : null}
52
+ </Box>
53
+ </Flex>
54
+ )
55
+ }
56
+
57
+ /**
58
+ * Range les outils nommés dans un onglet « Plus » en fin de barre.
59
+ *
60
+ * À appeler dans le `tools` du workspace, pas dans un plugin : c'est le seul
61
+ * endroit qui voit tous les outils, ceux des plugins déclarés après le kit et
62
+ * ceux du Studio lui-même (Releases).
63
+ *
64
+ * ```ts
65
+ * tools: (prev) => withMoreTool(prev, ['vision', 'releases'])
66
+ * ```
67
+ *
68
+ * Aucun des outils nommés n'est présent : la barre est rendue telle quelle.
69
+ */
70
+ export function withMoreTool(tools: Tool[], names: string[] = DEFAULT_MORE_TOOLS): Tool[] {
71
+ const hidden = tools.filter((tool) => names.includes(tool.name))
72
+ if (hidden.length === 0) return tools
73
+
74
+ const more: Tool<MoreToolOptions> = {
75
+ name: NCF_MORE_TOOL,
76
+ title: 'Plus',
77
+ icon: EllipsisHorizontalIcon,
78
+ component: MoreToolComponent,
79
+ options: {tools: hidden},
80
+ }
81
+ return [...tools.filter((tool) => !names.includes(tool.name)), more]
82
+ }