@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,126 @@
|
|
|
1
|
+
import {memo, useState} from 'react'
|
|
2
|
+
import {NodeResizer, useViewport, type Node, type NodeProps} from '@xyflow/react'
|
|
3
|
+
import {Box, Button, Card, Flex, TextArea} from '@sanity/ui'
|
|
4
|
+
import {TrashIcon} from '@sanity/icons/Trash'
|
|
5
|
+
import type {Annotation} from '../../lib/graph'
|
|
6
|
+
import {withAlpha} from '../../lib/colors'
|
|
7
|
+
|
|
8
|
+
export interface AnnotationNodeData extends Record<string, unknown> {
|
|
9
|
+
annotation: Annotation
|
|
10
|
+
onChange: (id: string, patch: Partial<Annotation>) => void
|
|
11
|
+
onRemove: (id: string) => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type AnnotationFlowNode = Node<AnnotationNodeData, 'annotation'>
|
|
15
|
+
|
|
16
|
+
export const ANNOTATION_COLORS = [
|
|
17
|
+
'#f5a623',
|
|
18
|
+
'#43d675',
|
|
19
|
+
'#2276fc',
|
|
20
|
+
'#f03e3e',
|
|
21
|
+
'#8a8a8a',
|
|
22
|
+
] as const
|
|
23
|
+
|
|
24
|
+
/** Contre-échelle du texte : voir `textScaleFor` du nœud de page. */
|
|
25
|
+
const textScaleFor = (zoom: number): number => Math.min(2.4, Math.max(1, 1 / zoom))
|
|
26
|
+
|
|
27
|
+
function AnnotationNodeComponent(props: NodeProps<AnnotationFlowNode>) {
|
|
28
|
+
const {annotation, onChange, onRemove} = props.data
|
|
29
|
+
const [editing, setEditing] = useState(false)
|
|
30
|
+
const {zoom} = useViewport()
|
|
31
|
+
const textScale = textScaleFor(zoom)
|
|
32
|
+
const color = annotation.color ?? ANNOTATION_COLORS[0]
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<>
|
|
36
|
+
<NodeResizer
|
|
37
|
+
minWidth={80}
|
|
38
|
+
minHeight={48}
|
|
39
|
+
isVisible={props.selected}
|
|
40
|
+
onResizeEnd={(_event, params) =>
|
|
41
|
+
onChange(annotation.id, {
|
|
42
|
+
width: Math.round(params.width),
|
|
43
|
+
height: Math.round(params.height),
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
/>
|
|
47
|
+
<Card
|
|
48
|
+
radius={2}
|
|
49
|
+
padding={2}
|
|
50
|
+
style={{
|
|
51
|
+
width: annotation.width,
|
|
52
|
+
height: annotation.height,
|
|
53
|
+
// Une forme est un aplat, une note garde un fond lisible.
|
|
54
|
+
background: withAlpha(color, annotation.kind === 'rect' ? 0.28 : 0.14),
|
|
55
|
+
border: `1px ${annotation.kind === 'rect' ? 'solid' : 'dashed'} ${color}`,
|
|
56
|
+
overflow: 'hidden',
|
|
57
|
+
}}
|
|
58
|
+
onDoubleClick={() => setEditing(true)}
|
|
59
|
+
>
|
|
60
|
+
{editing ? (
|
|
61
|
+
<TextArea
|
|
62
|
+
className="nodrag"
|
|
63
|
+
autoFocus
|
|
64
|
+
fontSize={1}
|
|
65
|
+
padding={1}
|
|
66
|
+
defaultValue={annotation.text ?? ''}
|
|
67
|
+
style={{height: '100%', background: 'transparent'}}
|
|
68
|
+
onBlur={(event) => {
|
|
69
|
+
onChange(annotation.id, {text: event.currentTarget.value})
|
|
70
|
+
setEditing(false)
|
|
71
|
+
}}
|
|
72
|
+
/>
|
|
73
|
+
) : (
|
|
74
|
+
<Box
|
|
75
|
+
style={{
|
|
76
|
+
height: '100%',
|
|
77
|
+
whiteSpace: 'pre-wrap',
|
|
78
|
+
fontSize: Math.round(13 * textScale),
|
|
79
|
+
lineHeight: 1.4,
|
|
80
|
+
color: 'var(--card-fg-color)',
|
|
81
|
+
opacity: annotation.text ? 1 : 0.5,
|
|
82
|
+
overflow: 'hidden',
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
{annotation.text || 'Double-clic pour écrire'}
|
|
86
|
+
</Box>
|
|
87
|
+
)}
|
|
88
|
+
|
|
89
|
+
{props.selected && (
|
|
90
|
+
<Flex
|
|
91
|
+
gap={1}
|
|
92
|
+
style={{position: 'absolute', top: 2, right: 2}}
|
|
93
|
+
className="nodrag"
|
|
94
|
+
>
|
|
95
|
+
{ANNOTATION_COLORS.map((value) => (
|
|
96
|
+
<Box
|
|
97
|
+
key={value}
|
|
98
|
+
onClick={() => onChange(annotation.id, {color: value})}
|
|
99
|
+
style={{
|
|
100
|
+
width: 12,
|
|
101
|
+
height: 12,
|
|
102
|
+
borderRadius: 2,
|
|
103
|
+
background: value,
|
|
104
|
+
cursor: 'pointer',
|
|
105
|
+
outline: value === color ? '2px solid var(--card-fg-color)' : 'none',
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
))}
|
|
109
|
+
<Button
|
|
110
|
+
mode="bleed"
|
|
111
|
+
padding={1}
|
|
112
|
+
fontSize={0}
|
|
113
|
+
icon={TrashIcon}
|
|
114
|
+
tone="critical"
|
|
115
|
+
title="Supprimer l’annotation"
|
|
116
|
+
aria-label="Supprimer l’annotation"
|
|
117
|
+
onClick={() => onRemove(annotation.id)}
|
|
118
|
+
/>
|
|
119
|
+
</Flex>
|
|
120
|
+
)}
|
|
121
|
+
</Card>
|
|
122
|
+
</>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const AnnotationNode = memo(AnnotationNodeComponent)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {Text} from '@sanity/ui'
|
|
2
|
+
import {useUser} from 'sanity'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Nom de l'auteur d'un changement.
|
|
6
|
+
*
|
|
7
|
+
* Le webhook ne transmet qu'un identifiant — `identity()` en GROQ. Le résoudre
|
|
8
|
+
* ici plutôt qu'à l'ingestion évite de stocker des noms qui se périment et
|
|
9
|
+
* d'avoir à détenir un jeton Sanity par client.
|
|
10
|
+
*/
|
|
11
|
+
export function ActorName(props: {actorId: string | null; actorName: string | null}) {
|
|
12
|
+
const [user] = useUser(props.actorId ?? '')
|
|
13
|
+
const label = props.actorName || user?.displayName || (props.actorId ? 'Compte inconnu' : '—')
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Text size={0} muted textOverflow="ellipsis" title={props.actorId ?? undefined}>
|
|
17
|
+
{label}
|
|
18
|
+
</Text>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {Card, Container, Stack, Text} from '@sanity/ui'
|
|
2
|
+
import {InlineCode} from '../ui/InlineCode'
|
|
3
|
+
import type {ConfigIssue} from '../config/types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Rend les problèmes de configuration à l'intérieur de l'outil concerné.
|
|
7
|
+
* Le Studio reste utilisable : on n'interrompt jamais son rendu.
|
|
8
|
+
*/
|
|
9
|
+
export function ConfigIssues(props: {issues: ConfigIssue[]; toolTitle: string}) {
|
|
10
|
+
const {issues, toolTitle} = props
|
|
11
|
+
if (issues.length === 0) return null
|
|
12
|
+
|
|
13
|
+
const blocking = issues.some((issue) => issue.level === 'error')
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Container width={2}>
|
|
17
|
+
<Stack gap={3}>
|
|
18
|
+
<Card padding={4} radius={3} shadow={1} tone={blocking ? 'critical' : 'caution'}>
|
|
19
|
+
<Stack gap={4}>
|
|
20
|
+
<Text weight="semibold">
|
|
21
|
+
{blocking
|
|
22
|
+
? `« ${toolTitle} » est désactivé : la configuration de ncfKit() est incomplète.`
|
|
23
|
+
: `« ${toolTitle} » fonctionne en mode dégradé.`}
|
|
24
|
+
</Text>
|
|
25
|
+
<Stack gap={3} as="ul">
|
|
26
|
+
{issues.map((issue) => (
|
|
27
|
+
<Stack gap={2} as="li" key={`${issue.level}-${issue.path}-${issue.message}`}>
|
|
28
|
+
<InlineCode>{issue.path}</InlineCode>
|
|
29
|
+
<Text size={1}>{issue.message}</Text>
|
|
30
|
+
</Stack>
|
|
31
|
+
))}
|
|
32
|
+
</Stack>
|
|
33
|
+
<Text size={1} muted>
|
|
34
|
+
À corriger dans l'appel à ncfKit() de sanity.config.ts.
|
|
35
|
+
</Text>
|
|
36
|
+
</Stack>
|
|
37
|
+
</Card>
|
|
38
|
+
</Stack>
|
|
39
|
+
</Container>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {ReactNode} from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Code en ligne. `Code` de `@sanity/ui/code` est un bloc pleine largeur :
|
|
5
|
+
* utilisé au fil d'une phrase, il la casse en bandes grises.
|
|
6
|
+
*/
|
|
7
|
+
export function InlineCode(props: {children: ReactNode}) {
|
|
8
|
+
return (
|
|
9
|
+
<span
|
|
10
|
+
style={{
|
|
11
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',
|
|
12
|
+
fontSize: '0.9em',
|
|
13
|
+
padding: '0.1em 0.35em',
|
|
14
|
+
borderRadius: '3px',
|
|
15
|
+
background: 'var(--card-code-bg-color, rgba(127, 127, 127, 0.15))',
|
|
16
|
+
whiteSpace: 'nowrap',
|
|
17
|
+
}}
|
|
18
|
+
>
|
|
19
|
+
{props.children}
|
|
20
|
+
</span>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {useEffect, useRef, useState, type ReactNode} from 'react'
|
|
2
|
+
import {Card} from '@sanity/ui'
|
|
3
|
+
|
|
4
|
+
export interface InlinePopoverProps {
|
|
5
|
+
/** Contenu du déclencheur, rendu tel quel. */
|
|
6
|
+
trigger: (props: {open: boolean; toggle: () => void}) => ReactNode
|
|
7
|
+
children: (props: {close: () => void}) => ReactNode
|
|
8
|
+
width?: number
|
|
9
|
+
/**
|
|
10
|
+
* Signale l'ouverture au parent. Utile quand le déclencheur n'est monté
|
|
11
|
+
* qu'au survol : il doit le rester tant que le panneau est ouvert.
|
|
12
|
+
*/
|
|
13
|
+
onOpenChange?: (open: boolean) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Petit panneau ancré à son déclencheur.
|
|
18
|
+
*
|
|
19
|
+
* Positionné en `fixed` et non en `absolute` : le tableau défile
|
|
20
|
+
* horizontalement, et un panneau posé dans ce conteneur serait rogné.
|
|
21
|
+
*/
|
|
22
|
+
export function InlinePopover(props: InlinePopoverProps) {
|
|
23
|
+
const {trigger, children, width = 200, onOpenChange} = props
|
|
24
|
+
const [open, setOpen] = useState(false)
|
|
25
|
+
const [at, setAt] = useState<{top: number; left: number} | null>(null)
|
|
26
|
+
const anchor = useRef<HTMLSpanElement>(null)
|
|
27
|
+
const panel = useRef<HTMLDivElement>(null)
|
|
28
|
+
|
|
29
|
+
const toggle = () => {
|
|
30
|
+
const rect = anchor.current?.getBoundingClientRect()
|
|
31
|
+
if (rect) {
|
|
32
|
+
// Bascule au-dessus quand il n'y a pas la place en dessous.
|
|
33
|
+
const below = window.innerHeight - rect.bottom
|
|
34
|
+
setAt({
|
|
35
|
+
top: below > 240 ? rect.bottom + 4 : Math.max(8, rect.top - 244),
|
|
36
|
+
left: Math.min(rect.left, window.innerWidth - width - 12),
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
setOpen((value) => {
|
|
40
|
+
onOpenChange?.(!value)
|
|
41
|
+
return !value
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const close = () => {
|
|
46
|
+
setOpen(false)
|
|
47
|
+
onOpenChange?.(false)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!open) return undefined
|
|
52
|
+
const onDown = (event: MouseEvent) => {
|
|
53
|
+
const target = event.target as Node
|
|
54
|
+
if (panel.current?.contains(target) || anchor.current?.contains(target)) return
|
|
55
|
+
close()
|
|
56
|
+
}
|
|
57
|
+
const onKey = (event: KeyboardEvent) => {
|
|
58
|
+
if (event.key === 'Escape') close()
|
|
59
|
+
}
|
|
60
|
+
document.addEventListener('mousedown', onDown)
|
|
61
|
+
document.addEventListener('keydown', onKey)
|
|
62
|
+
return () => {
|
|
63
|
+
document.removeEventListener('mousedown', onDown)
|
|
64
|
+
document.removeEventListener('keydown', onKey)
|
|
65
|
+
}
|
|
66
|
+
}, [open])
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<span ref={anchor} style={{display: 'block', minWidth: 0}}>
|
|
71
|
+
{trigger({open, toggle})}
|
|
72
|
+
</span>
|
|
73
|
+
{open && at && (
|
|
74
|
+
<div
|
|
75
|
+
ref={panel}
|
|
76
|
+
style={{position: 'fixed', top: at.top, left: at.left, width, zIndex: 1000}}
|
|
77
|
+
>
|
|
78
|
+
<Card radius={3} shadow={3} padding={1} style={{maxHeight: 240, overflowY: 'auto'}}>
|
|
79
|
+
{children({close})}
|
|
80
|
+
</Card>
|
|
81
|
+
</div>
|
|
82
|
+
)}
|
|
83
|
+
</>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {Card, Stack, Text} from '@sanity/ui'
|
|
2
|
+
import type {Registration} from '../lib/service'
|
|
3
|
+
import {useKitConfig} from '../context/KitContext'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Avis affiché quand le projet n'est plus actif chez NoCode Factory.
|
|
7
|
+
*
|
|
8
|
+
* Rien n'est bloqué : les outils Pages et Composants ne lisent que le contenu
|
|
9
|
+
* du client, avec ses propres droits. Couper l'accès ne protégerait rien et
|
|
10
|
+
* punirait un éditeur pour une question commerciale qui ne le concerne pas.
|
|
11
|
+
*
|
|
12
|
+
* Un projet inconnu du registre n'affiche rien du tout : le découvrir suffit.
|
|
13
|
+
*/
|
|
14
|
+
export function ProjectStatusNotice(props: {registration: Registration | null}) {
|
|
15
|
+
const config = useKitConfig()
|
|
16
|
+
const status = props.registration?.status
|
|
17
|
+
|
|
18
|
+
if (!status || status === 'active') return null
|
|
19
|
+
|
|
20
|
+
// Découvert mais jamais activé : rien à dire tant que personne n'attend le
|
|
21
|
+
// journal. Dès qu'une clé est configurée, on explique pourquoi il est vide.
|
|
22
|
+
if (status === 'unregistered') {
|
|
23
|
+
if (!config.history) return null
|
|
24
|
+
return (
|
|
25
|
+
<Card padding={3} radius={2} tone="caution">
|
|
26
|
+
<Stack gap={2}>
|
|
27
|
+
<Text size={1} weight="semibold">
|
|
28
|
+
Le journal n'est pas encore activé pour ce projet.
|
|
29
|
+
</Text>
|
|
30
|
+
<Text size={0} muted>
|
|
31
|
+
NoCode Factory l'active en lançant <code>npx ncf-kit setup</code> dans le dossier du studio.
|
|
32
|
+
</Text>
|
|
33
|
+
</Stack>
|
|
34
|
+
</Card>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const message =
|
|
39
|
+
status === 'expired'
|
|
40
|
+
? "L'accès à ce projet a expiré."
|
|
41
|
+
: status === 'suspended'
|
|
42
|
+
? 'Ce projet est suspendu.'
|
|
43
|
+
: "Ce projet n'est plus autorisé."
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Card padding={3} radius={2} tone="caution">
|
|
47
|
+
<Stack gap={2}>
|
|
48
|
+
<Text size={1} weight="semibold">
|
|
49
|
+
{message}
|
|
50
|
+
</Text>
|
|
51
|
+
<Text size={0} muted>
|
|
52
|
+
Les outils restent utilisables, mais le journal des modifications est arrêté.
|
|
53
|
+
Contactez NoCode Factory pour rétablir le service.
|
|
54
|
+
</Text>
|
|
55
|
+
</Stack>
|
|
56
|
+
</Card>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {Button, Card, Stack, Text} from '@sanity/ui'
|
|
2
|
+
|
|
3
|
+
/** Échec de requête : on dit quoi, et on laisse réessayer sur place. */
|
|
4
|
+
export function QueryError(props: {error: Error; onRetry: () => void}) {
|
|
5
|
+
return (
|
|
6
|
+
<Card padding={4} radius={3} shadow={1} tone="critical">
|
|
7
|
+
<Stack gap={4}>
|
|
8
|
+
<Text weight="semibold">La requête a échoué.</Text>
|
|
9
|
+
<Text size={1}>{props.error.message}</Text>
|
|
10
|
+
<div>
|
|
11
|
+
<Button text="Réessayer" mode="ghost" onClick={props.onRetry} />
|
|
12
|
+
</div>
|
|
13
|
+
</Stack>
|
|
14
|
+
</Card>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {BORDER} from './tokens'
|
|
2
|
+
|
|
3
|
+
export interface QuietInputProps {
|
|
4
|
+
value: string
|
|
5
|
+
placeholder?: string
|
|
6
|
+
/** Cadre visible au repos, hors d'un tableau où il concurrencerait la donnée. */
|
|
7
|
+
bordered?: boolean
|
|
8
|
+
onCommit: (value: string) => void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Champ de saisie d'une cellule de tableau.
|
|
13
|
+
*
|
|
14
|
+
* Un champ natif plutôt qu'un composant du Studio : l'anneau de `TextInput`
|
|
15
|
+
* est dessiné par un élément frère qu'on ne peut pas discipliner de
|
|
16
|
+
* l'extérieur, et une bordure par cellule concurrence la donnée. Ici le champ
|
|
17
|
+
* se lit comme du texte et ne montre son cadre qu'au survol de la ligne ou au
|
|
18
|
+
* focus.
|
|
19
|
+
*/
|
|
20
|
+
export function QuietInput(props: QuietInputProps) {
|
|
21
|
+
return (
|
|
22
|
+
<input
|
|
23
|
+
type="text"
|
|
24
|
+
// `key` sur la valeur : sans ça, un champ non contrôlé garderait
|
|
25
|
+
// l'ancienne saisie après un changement venu d'ailleurs.
|
|
26
|
+
key={props.value}
|
|
27
|
+
defaultValue={props.value}
|
|
28
|
+
placeholder={props.placeholder ?? '—'}
|
|
29
|
+
// `onBlur` plutôt que `onChange` : on n'écrit pas dans Sanity à chaque
|
|
30
|
+
// frappe.
|
|
31
|
+
onBlur={(event) => {
|
|
32
|
+
if (event.currentTarget.value !== props.value) props.onCommit(event.currentTarget.value)
|
|
33
|
+
}}
|
|
34
|
+
onKeyDown={(event) => {
|
|
35
|
+
if (event.key === 'Enter') event.currentTarget.blur()
|
|
36
|
+
if (event.key === 'Escape') {
|
|
37
|
+
event.currentTarget.value = props.value
|
|
38
|
+
event.currentTarget.blur()
|
|
39
|
+
}
|
|
40
|
+
}}
|
|
41
|
+
style={{
|
|
42
|
+
width: '100%',
|
|
43
|
+
font: 'inherit',
|
|
44
|
+
fontSize: 12,
|
|
45
|
+
padding: '4px 6px',
|
|
46
|
+
borderRadius: 3,
|
|
47
|
+
border: `1px solid ${props.bordered ? BORDER : 'transparent'}`,
|
|
48
|
+
background: props.bordered ? 'var(--card-bg-color)' : 'transparent',
|
|
49
|
+
color: 'var(--card-fg-color)',
|
|
50
|
+
outline: 'none',
|
|
51
|
+
}}
|
|
52
|
+
onFocus={(event) => {
|
|
53
|
+
event.currentTarget.style.border = `1px solid ${BORDER}`
|
|
54
|
+
event.currentTarget.style.background = 'var(--card-bg-color)'
|
|
55
|
+
}}
|
|
56
|
+
onBlurCapture={(event) => {
|
|
57
|
+
event.currentTarget.style.border = `1px solid ${props.bordered ? BORDER : 'transparent'}`
|
|
58
|
+
event.currentTarget.style.background = props.bordered
|
|
59
|
+
? 'var(--card-bg-color)'
|
|
60
|
+
: 'transparent'
|
|
61
|
+
}}
|
|
62
|
+
/>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {Badge} from '@sanity/ui'
|
|
2
|
+
import {STATUS_LABELS, type PageStatus} from '../lib/status'
|
|
3
|
+
|
|
4
|
+
export function StatusBadge(props: {status: PageStatus}) {
|
|
5
|
+
const {label, tone} = STATUS_LABELS[props.status]
|
|
6
|
+
return (
|
|
7
|
+
<Badge tone={tone} fontSize={0} title={STATUS_LABELS[props.status].help}>
|
|
8
|
+
{label}
|
|
9
|
+
</Badge>
|
|
10
|
+
)
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {Card, Container, Stack, Text} from '@sanity/ui'
|
|
2
|
+
import type {ReactNode} from 'react'
|
|
3
|
+
|
|
4
|
+
/** Coquille d'un outil pas encore implémenté (socle de phase 1). */
|
|
5
|
+
export function ToolPlaceholder(props: {title: string; phase: string; children?: ReactNode}) {
|
|
6
|
+
const {title, phase, children} = props
|
|
7
|
+
return (
|
|
8
|
+
<Container width={3}>
|
|
9
|
+
<Card padding={4} radius={3} shadow={1} tone="transparent">
|
|
10
|
+
<Stack gap={4}>
|
|
11
|
+
<Text size={3} weight="semibold">
|
|
12
|
+
{title}
|
|
13
|
+
</Text>
|
|
14
|
+
<Text size={1} muted>
|
|
15
|
+
Arrive en {phase}. Le socle du plugin est en place : configuration lue, validée, et
|
|
16
|
+
outil monté dans le Studio.
|
|
17
|
+
</Text>
|
|
18
|
+
{children}
|
|
19
|
+
</Stack>
|
|
20
|
+
</Card>
|
|
21
|
+
</Container>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const formatter = new Intl.DateTimeFormat('fr-FR', {
|
|
2
|
+
day: '2-digit',
|
|
3
|
+
month: '2-digit',
|
|
4
|
+
year: 'numeric',
|
|
5
|
+
hour: '2-digit',
|
|
6
|
+
minute: '2-digit',
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
/** Date lisible, ou un tiret cadratin quand il n'y en a pas. */
|
|
10
|
+
export function formatDate(value: string | null | undefined): string {
|
|
11
|
+
if (!value) return '—'
|
|
12
|
+
const date = new Date(value)
|
|
13
|
+
return Number.isNaN(date.getTime()) ? '—' : formatter.format(date)
|
|
14
|
+
}
|
package/src/ui/tokens.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jetons partagés par les vues du kit.
|
|
3
|
+
*
|
|
4
|
+
* Mode Operate : la couleur sert l'état et la sélection, jamais la décoration.
|
|
5
|
+
* Les fonds teintés restent sous le seuil où le texte du Studio perd son
|
|
6
|
+
* contraste, dans les deux thèmes.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Teinte de fond d'une ligne ou d'une carte porteuse d'un critère. */
|
|
10
|
+
export const TINT_ALPHA = 0.07
|
|
11
|
+
/** Même teinte, au survol d'une ligne. */
|
|
12
|
+
export const TINT_ALPHA_HOVER = 0.12
|
|
13
|
+
|
|
14
|
+
/** Chiffres et dates alignés en colonne. */
|
|
15
|
+
export const TABULAR: React.CSSProperties = {fontVariantNumeric: 'tabular-nums'}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Chemins et identifiants techniques. La police à chasse fixe est ici de la
|
|
19
|
+
* donnée, pas un costume : elle rend un slug lisible d'un coup d'œil et aligne
|
|
20
|
+
* les segments d'une ligne à l'autre.
|
|
21
|
+
*/
|
|
22
|
+
export const MONO: React.CSSProperties = {
|
|
23
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',
|
|
24
|
+
fontVariantNumeric: 'tabular-nums',
|
|
25
|
+
letterSpacing: '-0.01em',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Cellule de grille : se laisse rétrécir sans pousser ses voisines. */
|
|
29
|
+
export const CELL: React.CSSProperties = {minWidth: 0}
|
|
30
|
+
|
|
31
|
+
export const BORDER = 'var(--card-border-color, rgba(127,127,127,0.22))'
|
|
32
|
+
export const BORDER_SOFT = 'var(--card-border-color, rgba(127,127,127,0.12))'
|
|
33
|
+
|
|
34
|
+
/** Palette proposée pour colorer un choix de liste. */
|
|
35
|
+
export const OPTION_COLORS = ['#f5a623', '#43d675', '#2276fc', '#f03e3e', '#a855f7', '#8a8a8a']
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Tons du diff, dans l'esprit d'un diff de code.
|
|
39
|
+
*
|
|
40
|
+
* Des fonds très peu saturés plutôt que du rouge et du vert francs : ce qu'on
|
|
41
|
+
* lit, c'est le texte, et un aplat vif le rendrait moins lisible qu'avant. Le
|
|
42
|
+
* mot exactement remplacé porte un fond plus marqué que sa ligne.
|
|
43
|
+
*
|
|
44
|
+
* `color-mix` laisse le thème du Studio décider du fond réel, donc ces tons
|
|
45
|
+
* suivent le mode clair comme le mode sombre.
|
|
46
|
+
*/
|
|
47
|
+
export const DIFF = {
|
|
48
|
+
removedLine: 'color-mix(in srgb, #f03e3e 9%, transparent)',
|
|
49
|
+
addedLine: 'color-mix(in srgb, #2f9e44 11%, transparent)',
|
|
50
|
+
removedWord: 'color-mix(in srgb, #f03e3e 26%, transparent)',
|
|
51
|
+
addedWord: 'color-mix(in srgb, #2f9e44 30%, transparent)',
|
|
52
|
+
removedMark: '#e03131',
|
|
53
|
+
addedMark: '#2f9e44',
|
|
54
|
+
} as const
|
package/src/version.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {usePathname} from 'next/navigation'
|
|
4
|
+
import type {CSSProperties} from 'react'
|
|
5
|
+
|
|
6
|
+
export interface PreviewBannerProps {
|
|
7
|
+
/** Le site affiche-t-il actuellement les brouillons ? */
|
|
8
|
+
isDraft: boolean
|
|
9
|
+
/** Chemin de la route de bascule. Défaut : `/api/draft-mode/toggle`. */
|
|
10
|
+
togglePath?: string
|
|
11
|
+
/** Libellé de l'environnement. Défaut : « Préversion ». */
|
|
12
|
+
label?: string
|
|
13
|
+
position?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Bandeau des environnements de test : il dit où l'on est, et laisse choisir
|
|
18
|
+
* ce qu'on regarde.
|
|
19
|
+
*
|
|
20
|
+
* Sur une préversion, la question du relecteur est toujours la même :
|
|
21
|
+
* « qu'est-ce qui sortira quand je publierai ? ». Y répondre demande de voir
|
|
22
|
+
* les brouillons sur le vrai site, pas dans un aperçu encastré.
|
|
23
|
+
*
|
|
24
|
+
* Les styles sont en ligne, délibérément. Des classes utilitaires obligeraient
|
|
25
|
+
* chaque site à déclarer ce paquet dans ses globs de scan — une dépendance
|
|
26
|
+
* invisible dont l'oubli ne se verrait qu'à l'exécution, par un bandeau nu.
|
|
27
|
+
*
|
|
28
|
+
* Rendu hors production seulement : c'est à l'appelant de s'en assurer, avec
|
|
29
|
+
* `isPreviewSite()`.
|
|
30
|
+
*/
|
|
31
|
+
export function NcfPreviewBanner(props: PreviewBannerProps) {
|
|
32
|
+
const {isDraft, togglePath = '/api/draft-mode/toggle', label = 'Préversion'} = props
|
|
33
|
+
const pathname = usePathname()
|
|
34
|
+
const back = encodeURIComponent(pathname || '/')
|
|
35
|
+
|
|
36
|
+
const href = (enable: boolean) => `${togglePath}?enable=${enable}&redirect=${back}`
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div style={{...anchor(props.position ?? 'bottom-left'), zIndex: 2147483000}}>
|
|
40
|
+
<div style={shell}>
|
|
41
|
+
<span style={{display: 'inline-flex', alignItems: 'center', gap: 6, fontWeight: 500}}>
|
|
42
|
+
{/* Pastille pleine plutôt qu'un caractère décoratif : elle se lit à
|
|
43
|
+
toutes les tailles et ne dépend d'aucune police. */}
|
|
44
|
+
<span aria-hidden style={dot} />
|
|
45
|
+
{label}
|
|
46
|
+
</span>
|
|
47
|
+
|
|
48
|
+
<span aria-hidden style={divider} />
|
|
49
|
+
<span style={{opacity: 0.75}}>Données</span>
|
|
50
|
+
|
|
51
|
+
<span role="group" aria-label="Données affichées" style={{display: 'inline-flex', gap: 2}}>
|
|
52
|
+
<a
|
|
53
|
+
href={href(true)}
|
|
54
|
+
title="Ce qui sortira après publication"
|
|
55
|
+
aria-current={isDraft ? 'true' : undefined}
|
|
56
|
+
style={isDraft ? segmentOn : segmentOff}
|
|
57
|
+
>
|
|
58
|
+
Brouillons
|
|
59
|
+
</a>
|
|
60
|
+
<a
|
|
61
|
+
href={href(false)}
|
|
62
|
+
title="Ce que voit le public aujourd'hui"
|
|
63
|
+
aria-current={isDraft ? undefined : 'true'}
|
|
64
|
+
style={isDraft ? segmentOff : segmentOn}
|
|
65
|
+
>
|
|
66
|
+
En ligne
|
|
67
|
+
</a>
|
|
68
|
+
</span>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const anchor = (position: NonNullable<PreviewBannerProps['position']>): CSSProperties => ({
|
|
75
|
+
position: 'fixed',
|
|
76
|
+
...(position.startsWith('bottom') ? {bottom: 16} : {top: 16}),
|
|
77
|
+
...(position.endsWith('left') ? {left: 16} : {right: 16}),
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const shell: CSSProperties = {
|
|
81
|
+
display: 'flex',
|
|
82
|
+
alignItems: 'center',
|
|
83
|
+
gap: 10,
|
|
84
|
+
padding: '6px 12px',
|
|
85
|
+
borderRadius: 999,
|
|
86
|
+
// Ambre : la couleur des environnements de test, assez saturée pour ne pas
|
|
87
|
+
// se confondre avec le site, assez sobre pour ne pas le masquer.
|
|
88
|
+
background: '#fef3c7',
|
|
89
|
+
color: '#451a03',
|
|
90
|
+
border: '1px solid #fcd34d',
|
|
91
|
+
boxShadow: '0 4px 16px rgba(0,0,0,0.14)',
|
|
92
|
+
font: '500 12px/1 ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif',
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const dot: CSSProperties = {
|
|
96
|
+
width: 7,
|
|
97
|
+
height: 7,
|
|
98
|
+
borderRadius: '50%',
|
|
99
|
+
background: '#d97706',
|
|
100
|
+
flex: 'none',
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const divider: CSSProperties = {width: 1, height: 14, background: '#00000022'}
|
|
104
|
+
|
|
105
|
+
const segmentBase: CSSProperties = {
|
|
106
|
+
padding: '4px 10px',
|
|
107
|
+
borderRadius: 999,
|
|
108
|
+
textDecoration: 'none',
|
|
109
|
+
fontSize: 12,
|
|
110
|
+
lineHeight: 1,
|
|
111
|
+
whiteSpace: 'nowrap',
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const segmentOn: CSSProperties = {...segmentBase, background: '#451a03', color: '#fffbeb'}
|
|
115
|
+
const segmentOff: CSSProperties = {...segmentBase, color: '#451a03', opacity: 0.7}
|