@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.
- package/bin/ncf-kit.mjs +201 -0
- package/dist/index.d.ts +1643 -0
- package/dist/index.js +6632 -0
- package/dist/index.js.map +1 -0
- package/dist/web-server.d.ts +46 -0
- package/dist/web-server.js +51 -0
- package/dist/web-server.js.map +1 -0
- package/dist/web.d.ts +27 -0
- package/dist/web.js +117 -0
- package/dist/web.js.map +1 -0
- package/package.json +90 -0
- package/scripts/use-client.mjs +20 -0
- package/src/config/defaults.ts +74 -0
- package/src/config/resolve.ts +153 -0
- package/src/config/types.ts +290 -0
- package/src/config/validate.ts +193 -0
- package/src/context/BoardLayoutContext.tsx +24 -0
- package/src/context/KitContext.tsx +30 -0
- package/src/context/PreviewTargetContext.tsx +27 -0
- package/src/hooks/useAnnotations.ts +60 -0
- package/src/hooks/useBoardLayout.ts +398 -0
- package/src/hooks/useColumnOptions.ts +47 -0
- package/src/hooks/useDocumentColumns.ts +61 -0
- package/src/hooks/useHistory.ts +89 -0
- package/src/hooks/useInternalColumns.ts +19 -0
- package/src/hooks/useKitClient.ts +15 -0
- package/src/hooks/useOccurrences.ts +62 -0
- package/src/hooks/usePageContents.ts +65 -0
- package/src/hooks/usePages.ts +41 -0
- package/src/hooks/usePreviewTarget.ts +162 -0
- package/src/hooks/useQueryData.ts +103 -0
- package/src/hooks/useRegistration.ts +50 -0
- package/src/index.ts +280 -0
- package/src/lib/blocks.ts +38 -0
- package/src/lib/colors.ts +103 -0
- package/src/lib/columns.ts +137 -0
- package/src/lib/diff.ts +200 -0
- package/src/lib/elkLayout.ts +124 -0
- package/src/lib/graph.ts +238 -0
- package/src/lib/grouping.ts +116 -0
- package/src/lib/links.ts +70 -0
- package/src/lib/occurrences.ts +93 -0
- package/src/lib/pageThumbnail.ts +43 -0
- package/src/lib/pages.ts +199 -0
- package/src/lib/paths.ts +68 -0
- package/src/lib/query.ts +113 -0
- package/src/lib/schemaColumns.ts +162 -0
- package/src/lib/schemaTypes.ts +75 -0
- package/src/lib/sectionsMap.ts +83 -0
- package/src/lib/service.ts +88 -0
- package/src/lib/siteRoutes.ts +43 -0
- package/src/lib/status.ts +122 -0
- package/src/lib/studioLinks.ts +137 -0
- package/src/schema/boardLayout.ts +190 -0
- package/src/tools/components/BlockCard.tsx +79 -0
- package/src/tools/components/ComponentsTool.tsx +171 -0
- package/src/tools/components/map/SectionNode.tsx +109 -0
- package/src/tools/components/map/SectionsMap.tsx +339 -0
- package/src/tools/createToolComponent.tsx +67 -0
- package/src/tools/history/ChangeRow.tsx +87 -0
- package/src/tools/history/DiffPanel.tsx +227 -0
- package/src/tools/history/HistoryTool.tsx +230 -0
- package/src/tools/more/MoreTool.tsx +82 -0
- package/src/tools/pages/ColumnHeader.tsx +216 -0
- package/src/tools/pages/ColumnVisibility.tsx +173 -0
- package/src/tools/pages/FieldValue.tsx +327 -0
- package/src/tools/pages/PagesTable.tsx +394 -0
- package/src/tools/pages/PagesTool.tsx +333 -0
- package/src/tools/pages/PagesToolbar.tsx +53 -0
- package/src/tools/pages/PathCell.tsx +71 -0
- package/src/tools/pages/PreviewTarget.tsx +226 -0
- package/src/tools/pages/TagCell.tsx +124 -0
- package/src/tools/pages/ViewTabs.tsx +57 -0
- package/src/tools/pages/board/BoardView.tsx +661 -0
- package/src/tools/pages/board/PageNode.tsx +306 -0
- package/src/tools/pages/board/PagePanel.tsx +228 -0
- package/src/tools/presentation/PreviewHeader.tsx +75 -0
- package/src/tools/shared/AnnotationNode.tsx +126 -0
- package/src/ui/ActorName.tsx +20 -0
- package/src/ui/ConfigIssues.tsx +41 -0
- package/src/ui/InlineCode.tsx +22 -0
- package/src/ui/Popover.tsx +85 -0
- package/src/ui/ProjectStatusNotice.tsx +58 -0
- package/src/ui/QueryError.tsx +16 -0
- package/src/ui/QuietInput.tsx +64 -0
- package/src/ui/StatusBadge.tsx +11 -0
- package/src/ui/ToolPlaceholder.tsx +23 -0
- package/src/ui/formatDate.ts +14 -0
- package/src/ui/tokens.ts +54 -0
- package/src/version.ts +5 -0
- package/src/web/PreviewBanner.tsx +115 -0
- package/src/web/draftModeToggle.ts +56 -0
- package/src/web/environment.ts +21 -0
- package/src/web/index.ts +15 -0
- package/src/web/server.ts +11 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import {memo, useState} from 'react'
|
|
2
|
+
import {
|
|
3
|
+
Handle,
|
|
4
|
+
NodeResizer,
|
|
5
|
+
Position,
|
|
6
|
+
useViewport,
|
|
7
|
+
type Node,
|
|
8
|
+
type NodeProps,
|
|
9
|
+
} from '@xyflow/react'
|
|
10
|
+
import {Box, Card, Flex, Select, Stack, Text} from '@sanity/ui'
|
|
11
|
+
import {StatusBadge} from '../../../ui/StatusBadge'
|
|
12
|
+
import type {PageRow} from '../../../lib/pages'
|
|
13
|
+
import type {NcfBoardTag} from '../../../config/types'
|
|
14
|
+
import {
|
|
15
|
+
BRAIN_NODE_SIZE,
|
|
16
|
+
NODE_HEIGHT,
|
|
17
|
+
NODE_WIDTH,
|
|
18
|
+
SHOT_NODE_HEIGHT,
|
|
19
|
+
SHOT_NODE_WIDTH,
|
|
20
|
+
} from '../../../lib/elkLayout'
|
|
21
|
+
import type {LayoutMode} from '../../../lib/elkLayout'
|
|
22
|
+
import {usePreviewTarget} from '../../../context/PreviewTargetContext'
|
|
23
|
+
|
|
24
|
+
export interface PageNodeData extends Record<string, unknown> {
|
|
25
|
+
row: PageRow
|
|
26
|
+
mode: LayoutMode
|
|
27
|
+
tag: string | null
|
|
28
|
+
tags: NcfBoardTag[]
|
|
29
|
+
/** Couleur du critère choisi (étiquette, statut, champ interne…). */
|
|
30
|
+
color: string | null
|
|
31
|
+
width?: number | undefined
|
|
32
|
+
height?: number | undefined
|
|
33
|
+
/** Capture de la page publiée, ou `null` pour retomber sur l'iframe. */
|
|
34
|
+
thumbnailUrl: string | null
|
|
35
|
+
/** Nombre de liens, entrants et sortants : dimensionne la pastille. */
|
|
36
|
+
degree: number
|
|
37
|
+
onTag: (documentId: string, tag: string | null) => void
|
|
38
|
+
onResize: (documentId: string, size: {width: number; height: number}) => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type PageFlowNode = Node<PageNodeData, 'page'>
|
|
42
|
+
|
|
43
|
+
/** En dessous, une iframe serait illisible : inutile de la charger. */
|
|
44
|
+
const ZOOM_THRESHOLD = 0.75
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Facteur de contre-échelle du texte.
|
|
48
|
+
*
|
|
49
|
+
* Le canvas réduit tout uniformément : à mi-zoom, un titre de 13 px en fait
|
|
50
|
+
* 6,5 et devient illisible. On agrandit donc la police à l'inverse du zoom,
|
|
51
|
+
* borné pour que le texte ne dévore pas la carte quand on dézoome à fond.
|
|
52
|
+
*/
|
|
53
|
+
const textScaleFor = (zoom: number): number => Math.min(2.4, Math.max(1, 1 / zoom))
|
|
54
|
+
|
|
55
|
+
/** Largeur simulée du navigateur dans la vignette. */
|
|
56
|
+
const IFRAME_WIDTH = 1280
|
|
57
|
+
|
|
58
|
+
function BrainNode(props: {data: PageNodeData; selected: boolean}) {
|
|
59
|
+
const {row, degree, color} = props.data
|
|
60
|
+
const {zoom} = useViewport()
|
|
61
|
+
const textScale = textScaleFor(zoom)
|
|
62
|
+
// Plus une page est liée, plus sa pastille est grosse — la lecture
|
|
63
|
+
// immédiate d'un graphe de connaissances.
|
|
64
|
+
const size = Math.min(BRAIN_NODE_SIZE * 1.8, BRAIN_NODE_SIZE * (0.6 + degree * 0.18))
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Flex
|
|
68
|
+
direction="column"
|
|
69
|
+
align="center"
|
|
70
|
+
gap={2}
|
|
71
|
+
style={{width: BRAIN_NODE_SIZE * 2}}
|
|
72
|
+
>
|
|
73
|
+
<Box
|
|
74
|
+
style={{
|
|
75
|
+
width: size,
|
|
76
|
+
height: size,
|
|
77
|
+
borderRadius: '50%',
|
|
78
|
+
background: color ?? 'var(--card-muted-fg-color, #8a8a8a)',
|
|
79
|
+
opacity: degree === 0 ? 0.45 : 1,
|
|
80
|
+
border: props.selected
|
|
81
|
+
? '3px solid var(--card-focus-ring-color, #2276fc)'
|
|
82
|
+
: '2px solid var(--card-bg-color)',
|
|
83
|
+
cursor: 'pointer',
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
<Text
|
|
87
|
+
size={0}
|
|
88
|
+
align="center"
|
|
89
|
+
textOverflow="ellipsis"
|
|
90
|
+
style={{fontSize: Math.round(11 * textScale), lineHeight: 1.3}}
|
|
91
|
+
>
|
|
92
|
+
{row.title}
|
|
93
|
+
</Text>
|
|
94
|
+
</Flex>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function TreeNode(props: NodeProps<PageFlowNode> & {data: PageNodeData}) {
|
|
99
|
+
const {row, tags, tag, color, width, height, thumbnailUrl, onTag, onResize} = props.data
|
|
100
|
+
const {zoom} = useViewport()
|
|
101
|
+
const [hovered, setHovered] = useState(false)
|
|
102
|
+
const [thumbnailFailed, setThumbnailFailed] = useState(false)
|
|
103
|
+
|
|
104
|
+
const useScreenshotSize = Boolean(thumbnailUrl) && !thumbnailFailed
|
|
105
|
+
const nodeWidth = width ?? (useScreenshotSize ? SHOT_NODE_WIDTH : NODE_WIDTH)
|
|
106
|
+
const nodeHeight = height ?? (useScreenshotSize ? SHOT_NODE_HEIGHT : NODE_HEIGHT)
|
|
107
|
+
const textScale = textScaleFor(zoom)
|
|
108
|
+
const scale = nodeWidth / IFRAME_WIDTH
|
|
109
|
+
|
|
110
|
+
// La capture montre la page entière et coûte une image ; l'iframe ne montre
|
|
111
|
+
// que le haut et coûte un rendu complet. On préfère donc la capture, et on
|
|
112
|
+
// ne retombe sur l'iframe que s'il n'y en a pas, ou si elle manque.
|
|
113
|
+
const {siteUrlFor} = usePreviewTarget()
|
|
114
|
+
// L'aperçu d'une carte montre la version du site choisie dans la barre.
|
|
115
|
+
const siteUrl = siteUrlFor(row.url)
|
|
116
|
+
|
|
117
|
+
const useScreenshot = useScreenshotSize
|
|
118
|
+
// Chargement paresseux de l'iframe : survol, ou zoom suffisant pour qu'on y
|
|
119
|
+
// voie quelque chose. Sans ça, 100 pages ouvriraient 100 iframes d'un coup.
|
|
120
|
+
const showIframe = !useScreenshot && Boolean(siteUrl) && (hovered || zoom >= ZOOM_THRESHOLD)
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<>
|
|
124
|
+
<NodeResizer
|
|
125
|
+
minWidth={NODE_WIDTH}
|
|
126
|
+
minHeight={140}
|
|
127
|
+
isVisible={props.selected}
|
|
128
|
+
onResizeEnd={(_event, params) =>
|
|
129
|
+
onResize(props.id, {width: Math.round(params.width), height: Math.round(params.height)})
|
|
130
|
+
}
|
|
131
|
+
/>
|
|
132
|
+
<Card
|
|
133
|
+
radius={3}
|
|
134
|
+
shadow={props.selected ? 3 : 1}
|
|
135
|
+
padding={0}
|
|
136
|
+
tone={row.status === 'draft' ? 'transparent' : 'default'}
|
|
137
|
+
style={{
|
|
138
|
+
width: nodeWidth,
|
|
139
|
+
height: nodeHeight,
|
|
140
|
+
overflow: 'hidden',
|
|
141
|
+
// Colonne : l'aperçu prend la place restante, le bloc de texte garde
|
|
142
|
+
// sa hauteur naturelle. Une hauteur calculée le rognait dès que la
|
|
143
|
+
// contre-échelle du zoom agrandissait la police.
|
|
144
|
+
display: 'flex',
|
|
145
|
+
flexDirection: 'column',
|
|
146
|
+
outline: props.selected ? '2px solid var(--card-focus-ring-color, #2276fc)' : 'none',
|
|
147
|
+
}}
|
|
148
|
+
onMouseEnter={() => setHovered(true)}
|
|
149
|
+
onMouseLeave={() => setHovered(false)}
|
|
150
|
+
>
|
|
151
|
+
<Box
|
|
152
|
+
// `nowheel` : sans elle, la molette zoomerait le canvas au lieu de
|
|
153
|
+
// faire défiler la capture.
|
|
154
|
+
className={useScreenshot ? 'nowheel' : undefined}
|
|
155
|
+
style={{
|
|
156
|
+
flex: 1,
|
|
157
|
+
minHeight: 0,
|
|
158
|
+
overflowX: 'hidden',
|
|
159
|
+
overflowY: useScreenshot ? 'auto' : 'hidden',
|
|
160
|
+
position: 'relative',
|
|
161
|
+
background: 'var(--card-muted-bg-color, rgba(127,127,127,0.12))',
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
{/* La carte reste neutre : la couleur du critère tient dans une
|
|
165
|
+
pastille, pour ne pas concurrencer la capture. */}
|
|
166
|
+
{color && (
|
|
167
|
+
<Box
|
|
168
|
+
title={tags.find((t) => t.id === tag)?.label ?? undefined}
|
|
169
|
+
style={{
|
|
170
|
+
position: 'sticky',
|
|
171
|
+
top: 6,
|
|
172
|
+
left: 6,
|
|
173
|
+
float: 'left',
|
|
174
|
+
marginBottom: -12,
|
|
175
|
+
zIndex: 1,
|
|
176
|
+
width: 12,
|
|
177
|
+
height: 12,
|
|
178
|
+
borderRadius: '50%',
|
|
179
|
+
background: color,
|
|
180
|
+
// Anneau de contraste : la pastille doit rester lisible sur
|
|
181
|
+
// une capture claire comme sur une capture sombre.
|
|
182
|
+
boxShadow: '0 0 0 2px rgba(255,255,255,0.85), 0 1px 3px rgba(0,0,0,0.4)',
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
)}
|
|
186
|
+
{useScreenshot ? (
|
|
187
|
+
<img
|
|
188
|
+
src={thumbnailUrl ?? ''}
|
|
189
|
+
alt=""
|
|
190
|
+
loading="lazy"
|
|
191
|
+
onError={() => setThumbnailFailed(true)}
|
|
192
|
+
// Pleine largeur, hauteur naturelle : la page entière est là,
|
|
193
|
+
// on la parcourt en faisant défiler la carte.
|
|
194
|
+
style={{width: '100%', height: 'auto', display: 'block'}}
|
|
195
|
+
/>
|
|
196
|
+
) : showIframe ? (
|
|
197
|
+
<iframe
|
|
198
|
+
src={siteUrl ?? ''}
|
|
199
|
+
title={row.title}
|
|
200
|
+
loading="lazy"
|
|
201
|
+
tabIndex={-1}
|
|
202
|
+
scrolling="no"
|
|
203
|
+
style={{
|
|
204
|
+
width: IFRAME_WIDTH,
|
|
205
|
+
// Une règle globale `iframe {max-width: 100%}` ramènerait
|
|
206
|
+
// l'iframe à la largeur du nœud, et le site rendrait sa
|
|
207
|
+
// version mobile au lieu de l'aperçu desktop attendu.
|
|
208
|
+
maxWidth: 'none',
|
|
209
|
+
minWidth: IFRAME_WIDTH,
|
|
210
|
+
// L'iframe est réduite par `scale` : sa hauteur avant
|
|
211
|
+
// réduction doit donc être divisée d'autant pour remplir
|
|
212
|
+
// exactement la zone d'aperçu, dont la hauteur est fluide.
|
|
213
|
+
height: `calc(100% / ${scale})`,
|
|
214
|
+
border: 0,
|
|
215
|
+
transform: `scale(${scale})`,
|
|
216
|
+
transformOrigin: 'top left',
|
|
217
|
+
// L'aperçu est décoratif : il ne doit jamais voler le geste
|
|
218
|
+
// de déplacement du nœud.
|
|
219
|
+
pointerEvents: 'none',
|
|
220
|
+
}}
|
|
221
|
+
/>
|
|
222
|
+
) : (
|
|
223
|
+
<Flex align="center" justify="center" style={{height: '100%'}}>
|
|
224
|
+
<Text size={0} muted>
|
|
225
|
+
{thumbnailFailed
|
|
226
|
+
? 'Capture non générée'
|
|
227
|
+
: siteUrl
|
|
228
|
+
? 'Survoler pour l’aperçu'
|
|
229
|
+
: 'Pas d’aperçu'}
|
|
230
|
+
</Text>
|
|
231
|
+
</Flex>
|
|
232
|
+
)}
|
|
233
|
+
</Box>
|
|
234
|
+
|
|
235
|
+
<Box padding={2} style={{flex: 'none'}}>
|
|
236
|
+
<Stack gap={2}>
|
|
237
|
+
<Text
|
|
238
|
+
size={1}
|
|
239
|
+
weight="semibold"
|
|
240
|
+
textOverflow="ellipsis"
|
|
241
|
+
style={{fontSize: Math.round(13 * textScale), lineHeight: 1.3}}
|
|
242
|
+
>
|
|
243
|
+
{row.title}
|
|
244
|
+
</Text>
|
|
245
|
+
<Text
|
|
246
|
+
size={0}
|
|
247
|
+
muted
|
|
248
|
+
textOverflow="ellipsis"
|
|
249
|
+
style={{fontSize: Math.round(11 * textScale), lineHeight: 1.3}}
|
|
250
|
+
>
|
|
251
|
+
{row.path}
|
|
252
|
+
</Text>
|
|
253
|
+
{/* Dézoomé, un menu déroulant est inutilisable : on n'affiche plus
|
|
254
|
+
que l'étiquette, en toutes lettres. */}
|
|
255
|
+
{textScale > 1.25 ? (
|
|
256
|
+
<Text
|
|
257
|
+
size={0}
|
|
258
|
+
muted
|
|
259
|
+
textOverflow="ellipsis"
|
|
260
|
+
style={{fontSize: Math.round(11 * textScale), lineHeight: 1.3}}
|
|
261
|
+
>
|
|
262
|
+
{tags.find((t) => t.id === tag)?.label ?? 'Sans étiquette'}
|
|
263
|
+
</Text>
|
|
264
|
+
) : (
|
|
265
|
+
<Flex gap={2} align="center">
|
|
266
|
+
<StatusBadge status={row.status} />
|
|
267
|
+
{/* `nodrag` : sans ça, ouvrir le menu déplacerait le nœud. */}
|
|
268
|
+
<Select
|
|
269
|
+
className="nodrag"
|
|
270
|
+
fontSize={0}
|
|
271
|
+
padding={1}
|
|
272
|
+
value={tag ?? ''}
|
|
273
|
+
onChange={(event) => onTag(props.id, event.currentTarget.value || null)}
|
|
274
|
+
>
|
|
275
|
+
<option value="">Sans étiquette</option>
|
|
276
|
+
{tags.map((option) => (
|
|
277
|
+
<option key={option.id} value={option.id}>
|
|
278
|
+
{option.label}
|
|
279
|
+
</option>
|
|
280
|
+
))}
|
|
281
|
+
</Select>
|
|
282
|
+
</Flex>
|
|
283
|
+
)}
|
|
284
|
+
</Stack>
|
|
285
|
+
</Box>
|
|
286
|
+
</Card>
|
|
287
|
+
</>
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function PageNodeComponent(props: NodeProps<PageFlowNode>) {
|
|
292
|
+
const data = props.data
|
|
293
|
+
return (
|
|
294
|
+
<>
|
|
295
|
+
<Handle type="target" position={Position.Top} style={{opacity: 0}} />
|
|
296
|
+
{data.mode === 'brain' ? (
|
|
297
|
+
<BrainNode data={data} selected={Boolean(props.selected)} />
|
|
298
|
+
) : (
|
|
299
|
+
<TreeNode {...props} data={data} />
|
|
300
|
+
)}
|
|
301
|
+
<Handle type="source" position={Position.Bottom} style={{opacity: 0}} />
|
|
302
|
+
</>
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export const PageNode = memo(PageNodeComponent)
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {useState} from 'react'
|
|
2
|
+
import {Box, Button, Card, Flex, Select, Stack, Text} from '@sanity/ui'
|
|
3
|
+
import {IntentLink} from 'sanity/router'
|
|
4
|
+
import {CloseIcon} from '@sanity/icons/Close'
|
|
5
|
+
import {LaunchIcon} from '@sanity/icons/Launch'
|
|
6
|
+
import {MONO} from '../../../ui/tokens'
|
|
7
|
+
import {StatusBadge} from '../../../ui/StatusBadge'
|
|
8
|
+
import {FieldValue} from '../FieldValue'
|
|
9
|
+
import {usePreviewTarget} from '../../../context/PreviewTargetContext'
|
|
10
|
+
import type {NcfBoardTag, NcfInternalField} from '../../../config/types'
|
|
11
|
+
import type {PageRow} from '../../../lib/pages'
|
|
12
|
+
|
|
13
|
+
export interface PagePanelProps {
|
|
14
|
+
row: PageRow
|
|
15
|
+
thumbnailUrl: string | null
|
|
16
|
+
tag: string | null
|
|
17
|
+
tags: readonly NcfBoardTag[]
|
|
18
|
+
colorLabel: string | null
|
|
19
|
+
color: string | null
|
|
20
|
+
incoming: number
|
|
21
|
+
outgoing: number
|
|
22
|
+
/** Colonnes de gestion interne, éditables depuis la fiche. */
|
|
23
|
+
columns: readonly NcfInternalField[]
|
|
24
|
+
values: Readonly<Record<string, string>>
|
|
25
|
+
onTag: (documentId: string, tag: string | null) => void
|
|
26
|
+
onField: (documentId: string, columnId: string, value: string) => void
|
|
27
|
+
onAddOption: (columnId: string, label: string) => void
|
|
28
|
+
onRemoveOption: (columnId: string, optionId: string) => void
|
|
29
|
+
onOptionColor: (columnId: string, optionId: string, color: string | null) => void
|
|
30
|
+
onOpen: () => void
|
|
31
|
+
onClose: () => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Fiche d'une page sélectionnée sur le board.
|
|
36
|
+
*
|
|
37
|
+
* Indispensable en vue cerveau : une pastille ne peut porter ni aperçu ni
|
|
38
|
+
* sélecteur, et c'est pourtant là qu'on veut qualifier les pages.
|
|
39
|
+
*/
|
|
40
|
+
export function PagePanel(props: PagePanelProps) {
|
|
41
|
+
const {
|
|
42
|
+
row,
|
|
43
|
+
thumbnailUrl,
|
|
44
|
+
tag,
|
|
45
|
+
tags,
|
|
46
|
+
colorLabel,
|
|
47
|
+
color,
|
|
48
|
+
incoming,
|
|
49
|
+
outgoing,
|
|
50
|
+
columns,
|
|
51
|
+
values,
|
|
52
|
+
onTag,
|
|
53
|
+
onField,
|
|
54
|
+
onAddOption,
|
|
55
|
+
onRemoveOption,
|
|
56
|
+
onOptionColor,
|
|
57
|
+
onOpen,
|
|
58
|
+
onClose,
|
|
59
|
+
} = props
|
|
60
|
+
const [failed, setFailed] = useState(false)
|
|
61
|
+
const {siteUrlFor, environments, environment} = usePreviewTarget()
|
|
62
|
+
const siteUrl = siteUrlFor(row.url)
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Card
|
|
66
|
+
radius={3}
|
|
67
|
+
shadow={1}
|
|
68
|
+
padding={3}
|
|
69
|
+
style={{width: 300, flex: 'none', height: '70vh', overflow: 'auto'}}
|
|
70
|
+
>
|
|
71
|
+
<Stack gap={3}>
|
|
72
|
+
<Flex align="flex-start" justify="space-between" gap={2}>
|
|
73
|
+
<Text size={1} weight="semibold">
|
|
74
|
+
{row.title}
|
|
75
|
+
</Text>
|
|
76
|
+
<Button
|
|
77
|
+
mode="bleed"
|
|
78
|
+
padding={1}
|
|
79
|
+
fontSize={0}
|
|
80
|
+
icon={CloseIcon}
|
|
81
|
+
aria-label="Fermer"
|
|
82
|
+
onClick={onClose}
|
|
83
|
+
/>
|
|
84
|
+
</Flex>
|
|
85
|
+
|
|
86
|
+
<Box
|
|
87
|
+
style={{
|
|
88
|
+
aspectRatio: '3 / 4',
|
|
89
|
+
borderRadius: 3,
|
|
90
|
+
overflow: 'hidden',
|
|
91
|
+
background: 'var(--card-muted-bg-color, rgba(127,127,127,0.12))',
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
{thumbnailUrl && !failed ? (
|
|
95
|
+
<img
|
|
96
|
+
src={thumbnailUrl}
|
|
97
|
+
alt=""
|
|
98
|
+
onError={() => setFailed(true)}
|
|
99
|
+
style={{
|
|
100
|
+
width: '100%',
|
|
101
|
+
height: '100%',
|
|
102
|
+
objectFit: 'contain',
|
|
103
|
+
objectPosition: 'top',
|
|
104
|
+
display: 'block',
|
|
105
|
+
}}
|
|
106
|
+
/>
|
|
107
|
+
) : (
|
|
108
|
+
<Flex align="center" justify="center" style={{height: '100%'}} padding={3}>
|
|
109
|
+
<Text size={0} muted align="center">
|
|
110
|
+
{failed ? 'Capture non générée' : 'Pas de capture'}
|
|
111
|
+
</Text>
|
|
112
|
+
</Flex>
|
|
113
|
+
)}
|
|
114
|
+
</Box>
|
|
115
|
+
|
|
116
|
+
<Flex gap={2} align="center" wrap="wrap">
|
|
117
|
+
<StatusBadge status={row.status} />
|
|
118
|
+
{/* Pastille + libellé plutôt qu'un badge coloré : le contraste du
|
|
119
|
+
texte sur une couleur arbitraire n'est jamais garanti. */}
|
|
120
|
+
{colorLabel && color && (
|
|
121
|
+
<Flex gap={2} align="center">
|
|
122
|
+
<Box
|
|
123
|
+
style={{
|
|
124
|
+
width: 10,
|
|
125
|
+
height: 10,
|
|
126
|
+
borderRadius: '50%',
|
|
127
|
+
background: color,
|
|
128
|
+
flex: 'none',
|
|
129
|
+
}}
|
|
130
|
+
/>
|
|
131
|
+
<Text size={0} muted>
|
|
132
|
+
{colorLabel}
|
|
133
|
+
</Text>
|
|
134
|
+
</Flex>
|
|
135
|
+
)}
|
|
136
|
+
</Flex>
|
|
137
|
+
|
|
138
|
+
<Text size={1} textOverflow="ellipsis" style={MONO}>
|
|
139
|
+
{row.path ?? '—'}
|
|
140
|
+
</Text>
|
|
141
|
+
|
|
142
|
+
<Text size={0} muted>
|
|
143
|
+
{incoming} lien(s) entrant(s) · {outgoing} sortant(s)
|
|
144
|
+
</Text>
|
|
145
|
+
|
|
146
|
+
<Stack gap={2}>
|
|
147
|
+
<Text size={0} weight="semibold" muted>
|
|
148
|
+
Étiquette
|
|
149
|
+
</Text>
|
|
150
|
+
<Select
|
|
151
|
+
fontSize={1}
|
|
152
|
+
value={tag ?? ''}
|
|
153
|
+
onChange={(event) => onTag(row.id, event.currentTarget.value || null)}
|
|
154
|
+
>
|
|
155
|
+
<option value="">Sans étiquette</option>
|
|
156
|
+
{tags.map((option) => (
|
|
157
|
+
<option key={option.id} value={option.id}>
|
|
158
|
+
{option.label}
|
|
159
|
+
</option>
|
|
160
|
+
))}
|
|
161
|
+
</Select>
|
|
162
|
+
</Stack>
|
|
163
|
+
|
|
164
|
+
{columns.length > 0 && (
|
|
165
|
+
<Stack gap={2}>
|
|
166
|
+
<Text size={0} weight="semibold" muted>
|
|
167
|
+
Gestion interne
|
|
168
|
+
</Text>
|
|
169
|
+
{columns.map((column) => (
|
|
170
|
+
<Flex key={column.id} align="center" gap={2}>
|
|
171
|
+
<Box style={{width: 96, flex: 'none'}}>
|
|
172
|
+
<Text size={0} muted textOverflow="ellipsis">
|
|
173
|
+
{column.label || column.id}
|
|
174
|
+
</Text>
|
|
175
|
+
</Box>
|
|
176
|
+
<Box flex={1} style={{minWidth: 0}}>
|
|
177
|
+
<FieldValue
|
|
178
|
+
bordered
|
|
179
|
+
column={column}
|
|
180
|
+
value={values[column.id] ?? ''}
|
|
181
|
+
onChange={(next) => onField(row.id, column.id, next)}
|
|
182
|
+
onAddOption={(label) => onAddOption(column.id, label)}
|
|
183
|
+
onRemoveOption={(optionId) => onRemoveOption(column.id, optionId)}
|
|
184
|
+
onOptionColor={(optionId, next) => onOptionColor(column.id, optionId, next)}
|
|
185
|
+
/>
|
|
186
|
+
</Box>
|
|
187
|
+
</Flex>
|
|
188
|
+
))}
|
|
189
|
+
</Stack>
|
|
190
|
+
)}
|
|
191
|
+
|
|
192
|
+
<Flex gap={2} wrap="wrap">
|
|
193
|
+
<Button
|
|
194
|
+
mode="default"
|
|
195
|
+
fontSize={1}
|
|
196
|
+
padding={2}
|
|
197
|
+
text="Ouvrir la page"
|
|
198
|
+
title="Ouvre dans Presentation"
|
|
199
|
+
onClick={onOpen}
|
|
200
|
+
/>
|
|
201
|
+
<IntentLink
|
|
202
|
+
intent="edit"
|
|
203
|
+
params={{id: row.id, type: row.type}}
|
|
204
|
+
style={{textDecoration: 'none'}}
|
|
205
|
+
>
|
|
206
|
+
<Button mode="ghost" fontSize={1} padding={2} text="Modifier" as="span" />
|
|
207
|
+
</IntentLink>
|
|
208
|
+
{siteUrl && (
|
|
209
|
+
<Button
|
|
210
|
+
as="a"
|
|
211
|
+
href={siteUrl}
|
|
212
|
+
target="_blank"
|
|
213
|
+
rel="noreferrer"
|
|
214
|
+
mode="ghost"
|
|
215
|
+
fontSize={1}
|
|
216
|
+
padding={2}
|
|
217
|
+
icon={LaunchIcon}
|
|
218
|
+
// Le libellé nomme l'environnement dès qu'il y a un choix :
|
|
219
|
+
// « Voir en ligne » serait faux en pointant une recette.
|
|
220
|
+
text={environments.length > 1 ? (environment?.label ?? 'Voir') : 'Voir en ligne'}
|
|
221
|
+
title={siteUrl}
|
|
222
|
+
/>
|
|
223
|
+
)}
|
|
224
|
+
</Flex>
|
|
225
|
+
</Stack>
|
|
226
|
+
</Card>
|
|
227
|
+
)
|
|
228
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {Box, Button, Card, Flex, Text} from '@sanity/ui'
|
|
2
|
+
import {useRouter} from 'sanity/router'
|
|
3
|
+
import type {PreviewHeaderProps} from 'sanity/presentation'
|
|
4
|
+
import {PERSPECTIVES, type PreviewPerspective} from '../../lib/studioLinks'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Bascule brouillons / en ligne, posée dans l'aperçu lui-même.
|
|
8
|
+
*
|
|
9
|
+
* Le choix se fait là où l'on regarde. Le mettre ailleurs — dans une autre
|
|
10
|
+
* barre, dans un autre onglet — obligerait à sortir de la page pour changer
|
|
11
|
+
* ce qu'on y voit, et on reviendrait sans savoir ce qu'on regarde.
|
|
12
|
+
*
|
|
13
|
+
* Presentation lit la perspective dans l'URL du Studio : on l'y écrit plutôt
|
|
14
|
+
* que d'en tenir une copie, de sorte que l'adresse partagée montre la même
|
|
15
|
+
* chose à qui l'ouvre.
|
|
16
|
+
*/
|
|
17
|
+
export function NcfPreviewHeader(props: PreviewHeaderProps) {
|
|
18
|
+
const router = useRouter()
|
|
19
|
+
const current: PreviewPerspective = props.perspective === 'published' ? 'published' : 'drafts'
|
|
20
|
+
|
|
21
|
+
const choose = (next: PreviewPerspective) => {
|
|
22
|
+
if (next === current) return
|
|
23
|
+
const url = new URL(window.location.href)
|
|
24
|
+
// `drafts` est l'état par défaut de Presentation : on retire le paramètre
|
|
25
|
+
// plutôt que d'alourdir l'adresse.
|
|
26
|
+
if (next === 'drafts') url.searchParams.delete('perspective')
|
|
27
|
+
else url.searchParams.set('perspective', next)
|
|
28
|
+
router.navigateUrl({path: `${url.pathname}${url.search}`})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Card borderBottom style={{flex: 'none'}}>
|
|
33
|
+
<Flex align="center" gap={2} paddingX={2} paddingY={1} wrap="wrap">
|
|
34
|
+
<Box flex={1} style={{minWidth: 160}}>
|
|
35
|
+
{props.renderDefault(props)}
|
|
36
|
+
</Box>
|
|
37
|
+
|
|
38
|
+
<Flex align="center" gap={2} style={{flex: 'none'}}>
|
|
39
|
+
<Text size={0} muted>
|
|
40
|
+
Données
|
|
41
|
+
</Text>
|
|
42
|
+
<Flex gap={1}>
|
|
43
|
+
{PERSPECTIVES.map((option) => {
|
|
44
|
+
const active = option.id === current
|
|
45
|
+
return (
|
|
46
|
+
<Button
|
|
47
|
+
key={option.id}
|
|
48
|
+
mode={active ? 'default' : 'bleed'}
|
|
49
|
+
tone={active ? 'primary' : 'default'}
|
|
50
|
+
fontSize={1}
|
|
51
|
+
padding={2}
|
|
52
|
+
text={option.label}
|
|
53
|
+
title={option.hint}
|
|
54
|
+
aria-pressed={active}
|
|
55
|
+
onClick={() => choose(option.id)}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
})}
|
|
59
|
+
</Flex>
|
|
60
|
+
</Flex>
|
|
61
|
+
</Flex>
|
|
62
|
+
</Card>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* À passer à `presentationTool` pour que la bascule apparaisse dans l'aperçu :
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* presentationTool({components: ncfPreviewComponents(), previewUrl: …})
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function ncfPreviewComponents() {
|
|
74
|
+
return {unstable_header: {component: NcfPreviewHeader}}
|
|
75
|
+
}
|