@nocode-factory/sanity-kit 2.49.1 → 2.51.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 (39) hide show
  1. package/README.md +2 -1
  2. package/dist/{finalUrl-C1kzYMzQ.js → finalUrl-CaFXmYvm.js} +3 -2
  3. package/dist/finalUrl-CaFXmYvm.js.map +1 -0
  4. package/dist/{fixCrossLanguageReferences-BZk9CkdI.js → fixCrossLanguageReferences-BeXywAAU.js} +2 -2
  5. package/dist/{fixCrossLanguageReferences-BZk9CkdI.js.map → fixCrossLanguageReferences-BeXywAAU.js.map} +1 -1
  6. package/dist/{fixCrossLanguageReferences-CjL_Xy0U.d.ts → fixCrossLanguageReferences-w3whO9xM.d.ts} +4 -2
  7. package/dist/index.d.ts +287 -5
  8. package/dist/index.js +2119 -181
  9. package/dist/index.js.map +1 -1
  10. package/dist/jsonld.js +1 -1
  11. package/dist/schema.d.ts +1 -1
  12. package/dist/schema.js +2 -2
  13. package/package.json +3 -1
  14. package/src/config/defaults.ts +1 -0
  15. package/src/config/types.ts +3 -1
  16. package/src/context/ComponentMetaContext.tsx +23 -0
  17. package/src/form/ArrayNamesInput.tsx +25 -0
  18. package/src/form/renameArrayMembers.ts +25 -0
  19. package/src/hooks/useAssetMeta.ts +166 -0
  20. package/src/hooks/useAssets.ts +23 -0
  21. package/src/hooks/useComponentMeta.ts +159 -0
  22. package/src/hooks/useComponentNames.ts +39 -0
  23. package/src/index.ts +56 -1
  24. package/src/lib/assets.ts +161 -0
  25. package/src/lib/componentMeta.ts +70 -0
  26. package/src/schema/assetMeta.ts +65 -0
  27. package/src/schema/boardLayout.ts +5 -1
  28. package/src/schema/componentMeta.ts +54 -0
  29. package/src/tools/assets/AssetCard.tsx +86 -0
  30. package/src/tools/assets/AssetDetail.tsx +150 -0
  31. package/src/tools/assets/AssetTable.tsx +122 -0
  32. package/src/tools/assets/AssetsTool.tsx +212 -0
  33. package/src/tools/assets/AssetsToolbar.tsx +98 -0
  34. package/src/tools/assets/FolderSidebar.tsx +177 -0
  35. package/src/tools/components/BlockCard.tsx +20 -12
  36. package/src/tools/components/ComponentEditDialog.tsx +83 -0
  37. package/src/tools/components/ComponentsTool.tsx +190 -84
  38. package/src/version.ts +1 -1
  39. package/dist/finalUrl-C1kzYMzQ.js.map +0 -1
@@ -0,0 +1,122 @@
1
+ import {Badge, Box, Checkbox, Flex, Text} from '@sanity/ui'
2
+ import {assetName, formatBytes, isImageAsset, thumbnailUrl, type AssetDoc, type AssetSortKey, type SortDirection} from '../../lib/assets'
3
+ import {MONO, TABULAR} from '../../ui/tokens'
4
+ import {formatDate} from '../../ui/formatDate'
5
+
6
+ export interface AssetTableProps {
7
+ assets: AssetDoc[]
8
+ selected: Set<string>
9
+ onToggleSelect: (id: string) => void
10
+ onToggleAll: () => void
11
+ onOpen: (asset: AssetDoc) => void
12
+ folderName: (id: string) => string
13
+ folderOf: (assetId: string) => string | null
14
+ sortKey: AssetSortKey
15
+ sortDirection: SortDirection
16
+ onSort: (key: AssetSortKey) => void
17
+ }
18
+
19
+ const COLS: {key: AssetSortKey | null; label: string; align?: 'right'}[] = [
20
+ {key: 'name', label: 'Nom'},
21
+ {key: 'type', label: 'Type'},
22
+ {key: 'size', label: 'Taille', align: 'right'},
23
+ {key: null, label: 'Dimensions', align: 'right'},
24
+ {key: null, label: 'Dossier'},
25
+ {key: null, label: 'Usage', align: 'right'},
26
+ {key: 'date', label: 'Ajouté', align: 'right'},
27
+ ]
28
+
29
+ export function AssetTable(props: AssetTableProps) {
30
+ const {assets, selected, onToggleSelect, onToggleAll, onOpen, folderName, folderOf, sortKey, sortDirection, onSort} = props
31
+ const allSelected = assets.length > 0 && assets.every((a) => selected.has(a._id))
32
+ const arrow = (key: AssetSortKey) => (sortKey === key ? (sortDirection === 'asc' ? ' ↑' : ' ↓') : '')
33
+
34
+ return (
35
+ <Box overflow="auto">
36
+ <table style={{width: '100%', borderCollapse: 'collapse', fontSize: 13}}>
37
+ <thead>
38
+ <tr style={{textAlign: 'left', borderBottom: '1px solid var(--card-border-color)'}}>
39
+ <th style={{padding: '8px 10px', width: 36}}>
40
+ <Checkbox checked={allSelected} indeterminate={!allSelected && assets.some((a) => selected.has(a._id))} onChange={onToggleAll} aria-label="Tout sélectionner" />
41
+ </th>
42
+ {COLS.map((col) => (
43
+ <th
44
+ key={col.label}
45
+ onClick={col.key ? () => onSort(col.key as AssetSortKey) : undefined}
46
+ style={{padding: '8px 10px', whiteSpace: 'nowrap', textAlign: col.align ?? 'left', cursor: col.key ? 'pointer' : 'default', userSelect: 'none'}}
47
+ >
48
+ <Text size={1} weight="medium" muted>
49
+ {col.label}
50
+ {col.key ? arrow(col.key) : ''}
51
+ </Text>
52
+ </th>
53
+ ))}
54
+ </tr>
55
+ </thead>
56
+ <tbody>
57
+ {assets.map((asset) => {
58
+ const thumb = thumbnailUrl(asset, {w: 64, h: 64})
59
+ const folder = folderOf(asset._id)
60
+ return (
61
+ <tr
62
+ key={asset._id}
63
+ onClick={() => onOpen(asset)}
64
+ style={{borderBottom: '1px solid var(--card-border-color)', cursor: 'pointer', background: selected.has(asset._id) ? 'var(--card-badge-primary-bg-color, rgba(45,114,225,0.08))' : undefined}}
65
+ >
66
+ <td style={{padding: '6px 10px'}} onClick={(e) => e.stopPropagation()}>
67
+ <Checkbox checked={selected.has(asset._id)} onChange={() => onToggleSelect(asset._id)} aria-label="Sélectionner" />
68
+ </td>
69
+ <td style={{padding: '6px 10px'}}>
70
+ <Flex align="center" gap={2}>
71
+ <Box style={{width: 32, height: 32, flex: 'none', borderRadius: 4, overflow: 'hidden', background: 'var(--card-muted-bg-color, rgba(127,127,127,0.08))'}}>
72
+ {thumb ? <img src={thumb} alt="" loading="lazy" style={{width: '100%', height: '100%', objectFit: 'cover'}} /> : null}
73
+ </Box>
74
+ <Text size={1} textOverflow="ellipsis">
75
+ {assetName(asset)}
76
+ </Text>
77
+ </Flex>
78
+ </td>
79
+ <td style={{padding: '6px 10px', whiteSpace: 'nowrap'}}>
80
+ <Text size={1} muted style={MONO}>
81
+ {asset.extension?.toUpperCase() || (isImageAsset(asset) ? 'IMG' : 'FICHIER')}
82
+ </Text>
83
+ </td>
84
+ <td style={{padding: '6px 10px', textAlign: 'right', whiteSpace: 'nowrap'}}>
85
+ <Text size={1} style={TABULAR}>
86
+ {formatBytes(asset.size)}
87
+ </Text>
88
+ </td>
89
+ <td style={{padding: '6px 10px', textAlign: 'right', whiteSpace: 'nowrap'}}>
90
+ <Text size={1} muted style={TABULAR}>
91
+ {asset.dimensions?.width ? `${asset.dimensions.width}×${asset.dimensions.height}` : '—'}
92
+ </Text>
93
+ </td>
94
+ <td style={{padding: '6px 10px', whiteSpace: 'nowrap'}}>
95
+ <Text size={1} muted textOverflow="ellipsis">
96
+ {folder ? folderName(folder) : '—'}
97
+ </Text>
98
+ </td>
99
+ <td style={{padding: '6px 10px', textAlign: 'right', whiteSpace: 'nowrap'}}>
100
+ {asset.uses === 0 ? (
101
+ <Badge tone="caution" fontSize={0}>
102
+ 0
103
+ </Badge>
104
+ ) : (
105
+ <Text size={1} style={TABULAR}>
106
+ {asset.uses ?? '—'}
107
+ </Text>
108
+ )}
109
+ </td>
110
+ <td style={{padding: '6px 10px', textAlign: 'right', whiteSpace: 'nowrap'}}>
111
+ <Text size={1} muted style={TABULAR}>
112
+ {formatDate(asset._createdAt)}
113
+ </Text>
114
+ </td>
115
+ </tr>
116
+ )
117
+ })}
118
+ </tbody>
119
+ </table>
120
+ </Box>
121
+ )
122
+ }
@@ -0,0 +1,212 @@
1
+ import {useCallback, useMemo, useState} from 'react'
2
+ import {Box, Button, Card, Flex, Grid, Select, Spinner, Stack, Text} from '@sanity/ui'
3
+ import {QueryError} from '../../ui/QueryError'
4
+ import {useAssets} from '../../hooks/useAssets'
5
+ import {useAssetMeta} from '../../hooks/useAssetMeta'
6
+ import {
7
+ assignmentMap,
8
+ assetsInFolder,
9
+ countByFolder,
10
+ filterAssets,
11
+ sortAssets,
12
+ type AssetDoc,
13
+ type AssetSortKey,
14
+ type AssetTypeFilter,
15
+ type AssetUsageFilter,
16
+ type FolderSelection,
17
+ type SortDirection,
18
+ } from '../../lib/assets'
19
+ import {FolderSidebar} from './FolderSidebar'
20
+ import {AssetsToolbar, type AssetView} from './AssetsToolbar'
21
+ import {AssetCard} from './AssetCard'
22
+ import {AssetTable} from './AssetTable'
23
+ import {AssetDetail} from './AssetDetail'
24
+
25
+ export function AssetsTool() {
26
+ const {data, loading, error, refresh} = useAssets()
27
+ const meta = useAssetMeta()
28
+ const assets = useMemo(() => data ?? [], [data])
29
+
30
+ const [search, setSearch] = useState('')
31
+ const [type, setType] = useState<AssetTypeFilter>('all')
32
+ const [usage, setUsage] = useState<AssetUsageFilter>('all')
33
+ const [sort, setSort] = useState<AssetSortKey>('date')
34
+ const [direction, setDirection] = useState<SortDirection>('desc')
35
+ const [view, setView] = useState<AssetView>('grid')
36
+ const [selection, setSelection] = useState<FolderSelection>(null)
37
+ const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set())
38
+ const [openedId, setOpenedId] = useState<string | null>(null)
39
+
40
+ const folderMap = useMemo(() => assignmentMap(meta.assignments), [meta.assignments])
41
+ const counts = useMemo(() => countByFolder(assets, folderMap), [assets, folderMap])
42
+ const folderName = useCallback((id: string) => meta.folders.find((f) => f.id === id)?.name ?? id, [meta.folders])
43
+ const folderOf = useCallback((assetId: string) => folderMap.get(assetId) ?? null, [folderMap])
44
+
45
+ const visible = useMemo(() => {
46
+ const inFolder = assetsInFolder(assets, folderMap, selection)
47
+ return sortAssets(filterAssets(inFolder, {search, type, usage}), sort, direction)
48
+ }, [assets, folderMap, selection, search, type, usage, sort, direction])
49
+
50
+ const opened = openedId ? assets.find((a) => a._id === openedId) ?? null : null
51
+
52
+ const toggleSelect = useCallback((id: string) => {
53
+ setSelectedIds((prev) => {
54
+ const next = new Set(prev)
55
+ if (next.has(id)) next.delete(id)
56
+ else next.add(id)
57
+ return next
58
+ })
59
+ }, [])
60
+ const toggleAll = useCallback(() => {
61
+ setSelectedIds((prev) => {
62
+ const allVisible = visible.every((a) => prev.has(a._id))
63
+ if (allVisible) {
64
+ const next = new Set(prev)
65
+ for (const a of visible) next.delete(a._id)
66
+ return next
67
+ }
68
+ const next = new Set(prev)
69
+ for (const a of visible) next.add(a._id)
70
+ return next
71
+ })
72
+ }, [visible])
73
+ const clearSelection = useCallback(() => setSelectedIds(new Set()), [])
74
+
75
+ const moveSelected = useCallback(
76
+ (folder: string | null) => {
77
+ meta.moveAssets([...selectedIds], folder)
78
+ clearSelection()
79
+ },
80
+ [meta, selectedIds, clearSelection],
81
+ )
82
+
83
+ if (loading && assets.length === 0) {
84
+ return (
85
+ <Flex align="center" justify="center" padding={6}>
86
+ <Spinner muted />
87
+ </Flex>
88
+ )
89
+ }
90
+ if (error) return <QueryError error={error} onRetry={refresh} />
91
+
92
+ return (
93
+ <Flex gap={4} align="stretch" style={{minHeight: 420}}>
94
+ <Box style={{width: 220, flex: 'none'}}>
95
+ <FolderSidebar
96
+ folders={meta.folders}
97
+ counts={counts}
98
+ total={assets.length}
99
+ selection={selection}
100
+ onSelect={setSelection}
101
+ onCreate={meta.createFolder}
102
+ onRename={meta.renameFolder}
103
+ onDelete={(id) => {
104
+ if (selection === id) setSelection(null)
105
+ meta.deleteFolder(id)
106
+ }}
107
+ />
108
+ </Box>
109
+
110
+ <Stack gap={3} flex={1} style={{minWidth: 0}}>
111
+ <AssetsToolbar
112
+ search={search}
113
+ onSearch={setSearch}
114
+ type={type}
115
+ onType={setType}
116
+ usage={usage}
117
+ onUsage={setUsage}
118
+ sort={sort}
119
+ direction={direction}
120
+ onSort={(k, d) => {
121
+ setSort(k)
122
+ setDirection(d)
123
+ }}
124
+ view={view}
125
+ onView={setView}
126
+ onRefresh={refresh}
127
+ busy={loading}
128
+ />
129
+
130
+ {selectedIds.size > 0 ? (
131
+ <Card tone="primary" border radius={2} padding={2}>
132
+ <Flex align="center" gap={3} wrap="wrap">
133
+ <Text size={1} weight="medium">
134
+ {selectedIds.size} sélectionné{selectedIds.size > 1 ? 's' : ''}
135
+ </Text>
136
+ <Flex align="center" gap={2}>
137
+ <Text size={1} muted>
138
+ Déplacer vers
139
+ </Text>
140
+ <Select
141
+ fontSize={1}
142
+ value=""
143
+ onChange={(e) => {
144
+ const v = e.currentTarget.value
145
+ if (v === '__none') moveSelected(null)
146
+ else if (v) moveSelected(v)
147
+ }}
148
+ style={{width: 170}}
149
+ >
150
+ <option value="">Choisir…</option>
151
+ <option value="__none">Non classé</option>
152
+ {meta.folders.map((f) => (
153
+ <option key={f.id} value={f.id}>
154
+ {f.name}
155
+ </option>
156
+ ))}
157
+ </Select>
158
+ </Flex>
159
+ <Box flex={1} />
160
+ <Button text="Désélectionner" mode="bleed" fontSize={1} onClick={clearSelection} />
161
+ </Flex>
162
+ </Card>
163
+ ) : null}
164
+
165
+ <Text size={1} muted>
166
+ {visible.length} média{visible.length > 1 ? 's' : ''}
167
+ {visible.length !== assets.length ? ` sur ${assets.length}` : ''}
168
+ </Text>
169
+
170
+ {visible.length === 0 ? (
171
+ <Card border radius={2} padding={5} tone="transparent">
172
+ <Text size={1} muted align="center">
173
+ Aucun média {search || type !== 'all' || usage !== 'all' ? 'ne correspond aux filtres' : selection ? 'dans ce dossier' : 'pour l’instant'}.
174
+ </Text>
175
+ </Card>
176
+ ) : view === 'grid' ? (
177
+ <Grid gridTemplateColumns={[2, 3, 4, 5]} gap={3}>
178
+ {visible.map((asset) => (
179
+ <AssetCard
180
+ key={asset._id}
181
+ asset={asset}
182
+ selected={selectedIds.has(asset._id)}
183
+ onToggleSelect={() => toggleSelect(asset._id)}
184
+ onOpen={() => setOpenedId(asset._id)}
185
+ />
186
+ ))}
187
+ </Grid>
188
+ ) : (
189
+ <AssetTable
190
+ assets={visible}
191
+ selected={selectedIds}
192
+ onToggleSelect={toggleSelect}
193
+ onToggleAll={toggleAll}
194
+ onOpen={(asset) => setOpenedId(asset._id)}
195
+ folderName={folderName}
196
+ folderOf={folderOf}
197
+ sortKey={sort}
198
+ sortDirection={direction}
199
+ onSort={(key) => {
200
+ setSort(key)
201
+ setDirection((d) => (sort === key && d === 'asc' ? 'desc' : 'asc'))
202
+ }}
203
+ />
204
+ )}
205
+ </Stack>
206
+
207
+ {opened ? (
208
+ <AssetDetail asset={opened} folders={meta.folders} folder={folderOf(opened._id)} onMove={(folder) => meta.moveAsset(opened._id, folder)} onClose={() => setOpenedId(null)} />
209
+ ) : null}
210
+ </Flex>
211
+ )
212
+ }
@@ -0,0 +1,98 @@
1
+ import {Box, Button, Flex, Select, TextInput} from '@sanity/ui'
2
+ import {SearchIcon} from '@sanity/icons/Search'
3
+ import {SyncIcon} from '@sanity/icons/Sync'
4
+ import {ThLargeIcon} from '@sanity/icons/ThLarge'
5
+ import {ThListIcon} from '@sanity/icons/ThList'
6
+ import type {AssetSortKey, AssetTypeFilter, AssetUsageFilter, SortDirection} from '../../lib/assets'
7
+
8
+ export type AssetView = 'grid' | 'table'
9
+
10
+ export interface AssetsToolbarProps {
11
+ search: string
12
+ onSearch: (value: string) => void
13
+ type: AssetTypeFilter
14
+ onType: (value: AssetTypeFilter) => void
15
+ usage: AssetUsageFilter
16
+ onUsage: (value: AssetUsageFilter) => void
17
+ sort: AssetSortKey
18
+ direction: SortDirection
19
+ onSort: (key: AssetSortKey, direction: SortDirection) => void
20
+ view: AssetView
21
+ onView: (view: AssetView) => void
22
+ onRefresh: () => void
23
+ busy: boolean
24
+ }
25
+
26
+ export function AssetsToolbar(props: AssetsToolbarProps) {
27
+ return (
28
+ <Flex gap={2} align="center" wrap="wrap">
29
+ <Box flex={1} style={{minWidth: 180}}>
30
+ <TextInput
31
+ value={props.search}
32
+ onChange={(event) => props.onSearch(event.currentTarget.value)}
33
+ placeholder="Rechercher un média"
34
+ icon={SearchIcon}
35
+ clearButton={props.search.length > 0}
36
+ onClear={() => props.onSearch('')}
37
+ fontSize={1}
38
+ radius={2}
39
+ />
40
+ </Box>
41
+
42
+ <Select fontSize={1} value={props.type} onChange={(e) => props.onType(e.currentTarget.value as AssetTypeFilter)} style={{flex: 'none', width: 120}}>
43
+ <option value="all">Tous types</option>
44
+ <option value="image">Images</option>
45
+ <option value="file">Fichiers</option>
46
+ </Select>
47
+
48
+ <Select fontSize={1} value={props.usage} onChange={(e) => props.onUsage(e.currentTarget.value as AssetUsageFilter)} style={{flex: 'none', width: 130}}>
49
+ <option value="all">Tout usage</option>
50
+ <option value="used">Utilisés</option>
51
+ <option value="unused">Inutilisés</option>
52
+ </Select>
53
+
54
+ <Select
55
+ fontSize={1}
56
+ value={`${props.sort}:${props.direction}`}
57
+ onChange={(e) => {
58
+ const [key, dir] = e.currentTarget.value.split(':') as [AssetSortKey, SortDirection]
59
+ props.onSort(key, dir)
60
+ }}
61
+ style={{flex: 'none', width: 170}}
62
+ >
63
+ <option value="date:desc">Plus récents</option>
64
+ <option value="date:asc">Plus anciens</option>
65
+ <option value="name:asc">Nom (A→Z)</option>
66
+ <option value="name:desc">Nom (Z→A)</option>
67
+ <option value="size:desc">Plus lourds</option>
68
+ <option value="size:asc">Plus légers</option>
69
+ <option value="type:asc">Type</option>
70
+ </Select>
71
+
72
+ <Flex style={{flex: 'none'}} gap={1}>
73
+ <Button
74
+ icon={ThLargeIcon}
75
+ mode={props.view === 'grid' ? 'default' : 'bleed'}
76
+ tone={props.view === 'grid' ? 'primary' : 'default'}
77
+ padding={2}
78
+ fontSize={1}
79
+ title="Grille"
80
+ aria-label="Grille"
81
+ onClick={() => props.onView('grid')}
82
+ />
83
+ <Button
84
+ icon={ThListIcon}
85
+ mode={props.view === 'table' ? 'default' : 'bleed'}
86
+ tone={props.view === 'table' ? 'primary' : 'default'}
87
+ padding={2}
88
+ fontSize={1}
89
+ title="Table"
90
+ aria-label="Table"
91
+ onClick={() => props.onView('table')}
92
+ />
93
+ </Flex>
94
+
95
+ <Button icon={SyncIcon} mode="bleed" padding={2} fontSize={1} title="Rafraîchir" aria-label="Rafraîchir" onClick={props.onRefresh} disabled={props.busy} />
96
+ </Flex>
97
+ )
98
+ }
@@ -0,0 +1,177 @@
1
+ import {useState} from 'react'
2
+ import {Box, Button, Dialog, Flex, Stack, Text, TextInput} from '@sanity/ui'
3
+ import {AddIcon} from '@sanity/icons/Add'
4
+ import {FolderIcon} from '@sanity/icons/Folder'
5
+ import {EditIcon} from '@sanity/icons/Edit'
6
+ import {TrashIcon} from '@sanity/icons/Trash'
7
+ import type {AssetFolder, FolderSelection} from '../../lib/assets'
8
+ import {TABULAR} from '../../ui/tokens'
9
+
10
+ export interface FolderSidebarProps {
11
+ folders: AssetFolder[]
12
+ counts: Map<string, number>
13
+ total: number
14
+ selection: FolderSelection
15
+ onSelect: (selection: FolderSelection) => void
16
+ onCreate: (name: string) => void
17
+ onRename: (id: string, name: string) => void
18
+ onDelete: (id: string) => void
19
+ }
20
+
21
+ function Row(props: {label: string; count?: number; active: boolean; onClick: () => void; icon?: React.ReactNode; actions?: React.ReactNode}) {
22
+ return (
23
+ <Flex align="center" gap={1}>
24
+ <Button
25
+ mode={props.active ? 'default' : 'bleed'}
26
+ tone={props.active ? 'primary' : 'default'}
27
+ onClick={props.onClick}
28
+ justify="flex-start"
29
+ style={{flex: 1, minWidth: 0}}
30
+ padding={2}
31
+ fontSize={1}
32
+ >
33
+ <Flex align="center" gap={2} style={{width: '100%'}}>
34
+ {props.icon ? <Text size={1}>{props.icon}</Text> : null}
35
+ <Text size={1} textOverflow="ellipsis" style={{flex: 1, textAlign: 'left'}}>
36
+ {props.label}
37
+ </Text>
38
+ {typeof props.count === 'number' ? (
39
+ <Text size={0} muted style={{...TABULAR, flex: 'none'}}>
40
+ {props.count}
41
+ </Text>
42
+ ) : null}
43
+ </Flex>
44
+ </Button>
45
+ {props.actions ? <Box style={{flex: 'none'}}>{props.actions}</Box> : null}
46
+ </Flex>
47
+ )
48
+ }
49
+
50
+ export function FolderSidebar(props: FolderSidebarProps) {
51
+ const {folders, counts, total, selection, onSelect, onCreate, onRename, onDelete} = props
52
+ const [creating, setCreating] = useState(false)
53
+ const [renaming, setRenaming] = useState<AssetFolder | null>(null)
54
+ const [deleting, setDeleting] = useState<AssetFolder | null>(null)
55
+ const [name, setName] = useState('')
56
+
57
+ const openCreate = () => {
58
+ setName('')
59
+ setCreating(true)
60
+ }
61
+ const openRename = (folder: AssetFolder) => {
62
+ setName(folder.name)
63
+ setRenaming(folder)
64
+ }
65
+
66
+ return (
67
+ <Stack gap={2}>
68
+ <Flex align="center" justify="space-between">
69
+ <Text size={1} weight="semibold" muted>
70
+ Dossiers
71
+ </Text>
72
+ <Button icon={AddIcon} mode="bleed" fontSize={1} padding={2} title="Nouveau dossier" aria-label="Nouveau dossier" onClick={openCreate} />
73
+ </Flex>
74
+
75
+ <Stack gap={1}>
76
+ <Row label="Tous les médias" count={total} active={selection === null} onClick={() => onSelect(null)} />
77
+ <Row label="Non classés" count={counts.get('') ?? 0} active={selection === ''} onClick={() => onSelect('')} />
78
+ {folders.map((folder) => (
79
+ <Row
80
+ key={folder.id}
81
+ label={folder.name}
82
+ count={counts.get(folder.id) ?? 0}
83
+ active={selection === folder.id}
84
+ onClick={() => onSelect(folder.id)}
85
+ icon={<FolderIcon />}
86
+ actions={
87
+ <Flex gap={1}>
88
+ <Button icon={EditIcon} mode="bleed" fontSize={0} padding={2} title="Renommer" aria-label="Renommer" onClick={() => openRename(folder)} />
89
+ <Button icon={TrashIcon} mode="bleed" tone="critical" fontSize={0} padding={2} title="Supprimer" aria-label="Supprimer" onClick={() => setDeleting(folder)} />
90
+ </Flex>
91
+ }
92
+ />
93
+ ))}
94
+ </Stack>
95
+
96
+ {creating || renaming ? (
97
+ <Dialog
98
+ id="asset-folder-dialog"
99
+ header={renaming ? 'Renommer le dossier' : 'Nouveau dossier'}
100
+ onClose={() => {
101
+ setCreating(false)
102
+ setRenaming(null)
103
+ }}
104
+ width={0}
105
+ footer={
106
+ <Flex justify="flex-end" gap={2} padding={2}>
107
+ <Button
108
+ text="Annuler"
109
+ mode="bleed"
110
+ onClick={() => {
111
+ setCreating(false)
112
+ setRenaming(null)
113
+ }}
114
+ />
115
+ <Button
116
+ text={renaming ? 'Renommer' : 'Créer'}
117
+ tone="primary"
118
+ disabled={!name.trim()}
119
+ onClick={() => {
120
+ if (renaming) onRename(renaming.id, name)
121
+ else onCreate(name)
122
+ setCreating(false)
123
+ setRenaming(null)
124
+ }}
125
+ />
126
+ </Flex>
127
+ }
128
+ >
129
+ <Box padding={4}>
130
+ <TextInput
131
+ value={name}
132
+ autoFocus
133
+ placeholder="Nom du dossier"
134
+ onChange={(event) => setName(event.currentTarget.value)}
135
+ onKeyDown={(event) => {
136
+ if (event.key === 'Enter' && name.trim()) {
137
+ if (renaming) onRename(renaming.id, name)
138
+ else onCreate(name)
139
+ setCreating(false)
140
+ setRenaming(null)
141
+ }
142
+ }}
143
+ />
144
+ </Box>
145
+ </Dialog>
146
+ ) : null}
147
+
148
+ {deleting ? (
149
+ <Dialog
150
+ id="asset-folder-delete"
151
+ header="Supprimer le dossier"
152
+ onClose={() => setDeleting(null)}
153
+ width={0}
154
+ footer={
155
+ <Flex justify="flex-end" gap={2} padding={2}>
156
+ <Button text="Annuler" mode="bleed" onClick={() => setDeleting(null)} />
157
+ <Button
158
+ text="Supprimer"
159
+ tone="critical"
160
+ onClick={() => {
161
+ onDelete(deleting.id)
162
+ setDeleting(null)
163
+ }}
164
+ />
165
+ </Flex>
166
+ }
167
+ >
168
+ <Box padding={4}>
169
+ <Text size={1}>
170
+ Supprimer « {deleting.name} » ? Les médias qu'il contient ne sont pas supprimés : ils redeviennent « Non classés ».
171
+ </Text>
172
+ </Box>
173
+ </Dialog>
174
+ ) : null}
175
+ </Stack>
176
+ )
177
+ }
@@ -1,5 +1,6 @@
1
1
  import {useState} from 'react'
2
- import {Box, Card, Flex, Stack, Text} from '@sanity/ui'
2
+ import {Box, Button, Card, Flex, Stack, Text} from '@sanity/ui'
3
+ import {EditIcon} from '@sanity/icons/Edit'
3
4
  import {blockName, humanizeBlockName} from '../../lib/blocks'
4
5
  import {MONO, TABULAR} from '../../ui/tokens'
5
6
  import type {BlockOccurrence} from '../../lib/occurrences'
@@ -12,6 +13,8 @@ export interface BlockCardProps {
12
13
  thumbnailUrl: string | null
13
14
  /** Au clic : rendu réel du composant et réglage de ses valeurs par défaut. */
14
15
  onOpen?: () => void
16
+ /** Renommer / ranger dans un groupe. Masqué si absent. */
17
+ onEdit?: () => void
15
18
  }
16
19
 
17
20
  /**
@@ -23,21 +26,26 @@ export interface BlockCardProps {
23
26
  * à le lire.
24
27
  */
25
28
  export function BlockCard(props: BlockCardProps) {
26
- const {block, occurrence, namespace, thumbnailUrl, onOpen} = props
29
+ const {block, occurrence, namespace, thumbnailUrl, onOpen, onEdit} = props
27
30
  const [failed, setFailed] = useState(false)
28
31
  const unused = occurrence.count === 0
29
32
 
30
33
  return (
31
- <Card
32
- radius={3}
33
- shadow={1}
34
- padding={0}
35
- as={onOpen ? 'button' : undefined}
36
- onClick={onOpen}
37
- title={onOpen ? 'See the real component and set its default values' : undefined}
38
- style={{height: '100%', overflow: 'hidden', width: '100%', textAlign: 'left', cursor: onOpen ? 'pointer' : undefined}}
39
- >
40
- <Stack gap={0} style={{height: '100%'}}>
34
+ <Card radius={3} shadow={1} padding={0} style={{height: '100%', overflow: 'hidden', position: 'relative'}}>
35
+ {onEdit ? (
36
+ <Box style={{position: 'absolute', top: 6, right: 6, zIndex: 1}} onClick={(event) => event.stopPropagation()}>
37
+ <Card radius={2} shadow={1}>
38
+ <Button icon={EditIcon} mode="bleed" padding={2} fontSize={1} title="Renommer / ranger" aria-label="Renommer / ranger" onClick={onEdit} />
39
+ </Card>
40
+ </Box>
41
+ ) : null}
42
+ <Stack
43
+ gap={0}
44
+ as={onOpen ? 'button' : undefined}
45
+ onClick={onOpen}
46
+ title={onOpen ? 'See the real component and set its default values' : undefined}
47
+ style={{height: '100%', width: '100%', textAlign: 'left', cursor: onOpen ? 'pointer' : undefined, background: 'transparent', border: 0, padding: 0}}
48
+ >
41
49
  <Box
42
50
  style={{
43
51
  aspectRatio: '16 / 10',