@nocode-factory/sanity-kit 2.49.0 → 2.50.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/README.md +2 -1
- package/bin/ncf-kit.mjs +15 -0
- package/dist/{aiJsonLd-DiYeDzou.js → aiJsonLd-BFyxgYen.js} +15 -3
- package/dist/aiJsonLd-BFyxgYen.js.map +1 -0
- package/dist/{finalUrl-C1kzYMzQ.js → finalUrl-CaFXmYvm.js} +3 -2
- package/dist/finalUrl-CaFXmYvm.js.map +1 -0
- package/dist/{fixCrossLanguageReferences-BZk9CkdI.js → fixCrossLanguageReferences-BeXywAAU.js} +2 -2
- package/dist/{fixCrossLanguageReferences-BZk9CkdI.js.map → fixCrossLanguageReferences-BeXywAAU.js.map} +1 -1
- package/dist/{fixCrossLanguageReferences-CjL_Xy0U.d.ts → fixCrossLanguageReferences-w3whO9xM.d.ts} +4 -2
- package/dist/index.d.ts +237 -6
- package/dist/index.js +1648 -159
- package/dist/index.js.map +1 -1
- package/dist/jsonld.js +14 -7
- package/dist/jsonld.js.map +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +2 -2
- package/package.json +3 -1
- package/src/config/defaults.ts +1 -0
- package/src/config/types.ts +3 -1
- package/src/context/KitContext.tsx +15 -1
- package/src/form/JsonLdInput.tsx +21 -6
- package/src/hooks/useAssetMeta.ts +166 -0
- package/src/hooks/useAssets.ts +23 -0
- package/src/hooks/useOccurrences.ts +4 -2
- package/src/hooks/usePageBuilder.ts +22 -0
- package/src/hooks/usePageContents.ts +8 -1
- package/src/hooks/usePages.ts +5 -1
- package/src/index.ts +50 -1
- package/src/lib/assets.ts +161 -0
- package/src/lib/schemaTypes.ts +105 -0
- package/src/schema/assetMeta.ts +65 -0
- package/src/schema/boardLayout.ts +3 -1
- package/src/tools/assets/AssetCard.tsx +86 -0
- package/src/tools/assets/AssetDetail.tsx +150 -0
- package/src/tools/assets/AssetTable.tsx +122 -0
- package/src/tools/assets/AssetsTool.tsx +212 -0
- package/src/tools/assets/AssetsToolbar.tsx +98 -0
- package/src/tools/assets/FolderSidebar.tsx +177 -0
- package/src/tools/createToolComponent.tsx +39 -10
- package/src/version.ts +1 -1
- package/dist/aiJsonLd-DiYeDzou.js.map +0 -1
- package/dist/finalUrl-C1kzYMzQ.js.map +0 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {useEffect, useState} from 'react'
|
|
2
|
+
import {Box, Button, Card, Flex, Grid, Label, Select, Stack, Text, TextArea, TextInput} from '@sanity/ui'
|
|
3
|
+
import {CloseIcon} from '@sanity/icons/Close'
|
|
4
|
+
import {CopyIcon} from '@sanity/icons/Copy'
|
|
5
|
+
import {LaunchIcon} from '@sanity/icons/Launch'
|
|
6
|
+
import {useKitClient} from '../../hooks/useKitClient'
|
|
7
|
+
import {assetName, formatBytes, isImageAsset, thumbnailUrl, type AssetDoc, type AssetFolder} from '../../lib/assets'
|
|
8
|
+
import {MONO} from '../../ui/tokens'
|
|
9
|
+
import {formatDate} from '../../ui/formatDate'
|
|
10
|
+
|
|
11
|
+
export interface AssetDetailProps {
|
|
12
|
+
asset: AssetDoc
|
|
13
|
+
folders: AssetFolder[]
|
|
14
|
+
folder: string | null
|
|
15
|
+
onMove: (folder: string | null) => void
|
|
16
|
+
onClose: () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function Metric(props: {label: string; value: string}) {
|
|
20
|
+
return (
|
|
21
|
+
<Stack gap={2}>
|
|
22
|
+
<Label size={0} muted>
|
|
23
|
+
{props.label}
|
|
24
|
+
</Label>
|
|
25
|
+
<Text size={1} style={MONO} textOverflow="ellipsis">
|
|
26
|
+
{props.value}
|
|
27
|
+
</Text>
|
|
28
|
+
</Stack>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function AssetDetail(props: AssetDetailProps) {
|
|
33
|
+
const {asset, folders, folder, onMove, onClose} = props
|
|
34
|
+
const client = useKitClient()
|
|
35
|
+
const [title, setTitle] = useState(asset.title ?? '')
|
|
36
|
+
const [alt, setAlt] = useState(asset.altText ?? '')
|
|
37
|
+
const [description, setDescription] = useState(asset.description ?? '')
|
|
38
|
+
const [copied, setCopied] = useState(false)
|
|
39
|
+
|
|
40
|
+
// Repart des valeurs de l'asset sélectionné quand il change.
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
setTitle(asset.title ?? '')
|
|
43
|
+
setAlt(asset.altText ?? '')
|
|
44
|
+
setDescription(asset.description ?? '')
|
|
45
|
+
}, [asset._id, asset.title, asset.altText, asset.description])
|
|
46
|
+
|
|
47
|
+
const save = (patch: Record<string, unknown>) => {
|
|
48
|
+
void client.patch(asset._id).set(patch).commit().catch(() => {})
|
|
49
|
+
}
|
|
50
|
+
const commit = (field: 'title' | 'altText' | 'description', value: string, original: string | undefined) => {
|
|
51
|
+
const next = value.trim()
|
|
52
|
+
if (next === (original ?? '')) return
|
|
53
|
+
save({[field]: next || undefined})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const preview = thumbnailUrl(asset, {w: 640})
|
|
57
|
+
const copyUrl = () => {
|
|
58
|
+
if (!asset.url) return
|
|
59
|
+
void navigator.clipboard?.writeText(asset.url).then(() => {
|
|
60
|
+
setCopied(true)
|
|
61
|
+
setTimeout(() => setCopied(false), 1500)
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Card borderLeft height="fill" style={{width: 340, flex: 'none'}} overflow="auto" tone="transparent">
|
|
67
|
+
<Stack gap={4} padding={4}>
|
|
68
|
+
<Flex align="center" justify="space-between" gap={2}>
|
|
69
|
+
<Text size={1} weight="semibold" textOverflow="ellipsis">
|
|
70
|
+
{assetName(asset)}
|
|
71
|
+
</Text>
|
|
72
|
+
<Button icon={CloseIcon} mode="bleed" padding={2} fontSize={1} aria-label="Fermer" onClick={onClose} />
|
|
73
|
+
</Flex>
|
|
74
|
+
|
|
75
|
+
<Card radius={2} border overflow="hidden" tone="transparent" style={{background: 'var(--card-muted-bg-color, rgba(127,127,127,0.08))'}}>
|
|
76
|
+
{preview ? (
|
|
77
|
+
<img src={preview} alt={asset.altText ?? ''} style={{width: '100%', display: 'block', maxHeight: 280, objectFit: 'contain'}} />
|
|
78
|
+
) : (
|
|
79
|
+
<Flex align="center" justify="center" padding={5}>
|
|
80
|
+
<Text size={1} muted>
|
|
81
|
+
{asset.extension?.toUpperCase() || 'Fichier'} — pas d'aperçu
|
|
82
|
+
</Text>
|
|
83
|
+
</Flex>
|
|
84
|
+
)}
|
|
85
|
+
</Card>
|
|
86
|
+
|
|
87
|
+
<Flex gap={2}>
|
|
88
|
+
<Button icon={CopyIcon} text={copied ? 'Copié' : "Copier l'URL"} mode="ghost" fontSize={1} onClick={copyUrl} disabled={!asset.url} style={{flex: 1}} />
|
|
89
|
+
<Button
|
|
90
|
+
icon={LaunchIcon}
|
|
91
|
+
text="Ouvrir"
|
|
92
|
+
mode="ghost"
|
|
93
|
+
fontSize={1}
|
|
94
|
+
onClick={() => asset.url && window.open(asset.url, '_blank', 'noopener')}
|
|
95
|
+
disabled={!asset.url}
|
|
96
|
+
style={{flex: 1}}
|
|
97
|
+
/>
|
|
98
|
+
</Flex>
|
|
99
|
+
|
|
100
|
+
<Stack gap={3}>
|
|
101
|
+
<Stack gap={2}>
|
|
102
|
+
<Label size={0} muted>
|
|
103
|
+
Dossier
|
|
104
|
+
</Label>
|
|
105
|
+
<Select fontSize={1} value={folder ?? ''} onChange={(event) => onMove(event.currentTarget.value || null)}>
|
|
106
|
+
<option value="">Non classé</option>
|
|
107
|
+
{folders.map((f) => (
|
|
108
|
+
<option key={f.id} value={f.id}>
|
|
109
|
+
{f.name}
|
|
110
|
+
</option>
|
|
111
|
+
))}
|
|
112
|
+
</Select>
|
|
113
|
+
</Stack>
|
|
114
|
+
|
|
115
|
+
<Stack gap={2}>
|
|
116
|
+
<Label size={0} muted>
|
|
117
|
+
Titre
|
|
118
|
+
</Label>
|
|
119
|
+
<TextInput fontSize={1} value={title} onChange={(e) => setTitle(e.currentTarget.value)} onBlur={() => commit('title', title, asset.title)} placeholder="Titre du média" />
|
|
120
|
+
</Stack>
|
|
121
|
+
|
|
122
|
+
{isImageAsset(asset) ? (
|
|
123
|
+
<Stack gap={2}>
|
|
124
|
+
<Label size={0} muted>
|
|
125
|
+
Texte alternatif (alt)
|
|
126
|
+
</Label>
|
|
127
|
+
<TextInput fontSize={1} value={alt} onChange={(e) => setAlt(e.currentTarget.value)} onBlur={() => commit('altText', alt, asset.altText)} placeholder="Décrit l'image (SEO, accessibilité)" />
|
|
128
|
+
</Stack>
|
|
129
|
+
) : null}
|
|
130
|
+
|
|
131
|
+
<Stack gap={2}>
|
|
132
|
+
<Label size={0} muted>
|
|
133
|
+
Description
|
|
134
|
+
</Label>
|
|
135
|
+
<TextArea fontSize={1} rows={2} value={description} onChange={(e) => setDescription(e.currentTarget.value)} onBlur={() => commit('description', description, asset.description)} />
|
|
136
|
+
</Stack>
|
|
137
|
+
</Stack>
|
|
138
|
+
|
|
139
|
+
<Grid gridTemplateColumns={[1, 2]} gap={3}>
|
|
140
|
+
<Metric label="Fichier" value={asset.originalFilename ?? '—'} />
|
|
141
|
+
<Metric label="Type" value={asset.extension?.toUpperCase() || asset._type.replace('sanity.', '')} />
|
|
142
|
+
<Metric label="Taille" value={formatBytes(asset.size)} />
|
|
143
|
+
<Metric label="Dimensions" value={asset.dimensions?.width ? `${asset.dimensions.width}×${asset.dimensions.height}` : '—'} />
|
|
144
|
+
<Metric label="Usage" value={asset.uses === undefined ? '—' : `${asset.uses}`} />
|
|
145
|
+
<Metric label="Ajouté" value={formatDate(asset._createdAt)} />
|
|
146
|
+
</Grid>
|
|
147
|
+
</Stack>
|
|
148
|
+
</Card>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
@@ -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
|
+
}
|