@nocode-factory/sanity-kit 2.54.0 → 2.58.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 +61 -6
- package/bin/item-types.mjs +131 -0
- package/bin/ncf-kit.mjs +97 -0
- package/dist/index.d.ts +48 -4
- package/dist/index.js +7222 -6916
- package/dist/index.js.map +1 -1
- package/dist/inherited-DZvM35P6.js +101 -0
- package/dist/inherited-DZvM35P6.js.map +1 -0
- package/dist/protocol-Bl7Yj2Ro.js +31 -0
- package/dist/protocol-Bl7Yj2Ro.js.map +1 -0
- package/dist/web-edit.d.ts +192 -0
- package/dist/web-edit.js +144 -0
- package/dist/web-edit.js.map +1 -0
- package/dist/web-editing.d.ts +51 -0
- package/dist/web-editing.js +693 -0
- package/dist/web-editing.js.map +1 -0
- package/package.json +22 -2
- package/scripts/use-client.mjs +1 -1
- package/src/form/AssetSourceBrowser.tsx +68 -39
- package/src/hooks/useCollection.ts +19 -3
- package/src/index.ts +3 -2
- package/src/lib/collectionQuery.ts +10 -2
- package/src/structure/collections.tsx +35 -5
- package/src/tools/collections/CollectionTable.tsx +295 -89
- package/src/tools/collections/CollectionToolbar.tsx +53 -4
- package/src/ui/PreviewEditBridge.tsx +74 -0
- package/src/version.ts +1 -1
- package/src/web/edit/ImageReplaceLayer.tsx +174 -0
- package/src/web/edit/InlineTextEditor.tsx +365 -0
- package/src/web/edit/InlineTextOverlay.tsx +43 -0
- package/src/web/edit/PreviewEditing.tsx +191 -0
- package/src/web/edit/index.ts +18 -0
- package/src/web/edit/inherited.ts +174 -0
- package/src/web/edit/labels.ts +37 -0
- package/src/web/edit/protocol.ts +47 -0
- package/src/web/edit/store.ts +98 -0
- package/src/web/edit/targets.ts +186 -0
- package/src/web/editing.ts +18 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {useCallback, useMemo, useState} from 'react'
|
|
1
|
+
import {useCallback, useMemo, useRef, useState, type ComponentType} from 'react'
|
|
2
2
|
import {Badge, Box, Flex, Spinner, Stack, Text} from '@sanity/ui'
|
|
3
3
|
import {ChevronDownIcon} from '@sanity/icons/ChevronDown'
|
|
4
4
|
import {ChevronUpIcon} from '@sanity/icons/ChevronUp'
|
|
5
|
+
import {DocumentIcon} from '@sanity/icons/Document'
|
|
6
|
+
import {usePaneRouter} from 'sanity/structure'
|
|
5
7
|
import {useRouter} from 'sanity/router'
|
|
6
8
|
import {useSchema} from 'sanity'
|
|
7
9
|
import {useCollection} from '../../hooks/useCollection'
|
|
@@ -11,12 +13,16 @@ import {downloadText} from '../../lib/download'
|
|
|
11
13
|
import {deriveCollectionColumns, type CollectionColumn} from '../../lib/collectionColumns'
|
|
12
14
|
import type {SchemaTypeLike} from '../../lib/schemaColumns'
|
|
13
15
|
import type {CollectionRow} from '../../lib/collectionRows'
|
|
14
|
-
import {BORDER, BORDER_SOFT,
|
|
16
|
+
import {BORDER, BORDER_SOFT, TABULAR} from '../../ui/tokens'
|
|
15
17
|
import {QueryError} from '../../ui/QueryError'
|
|
16
|
-
import {CollectionToolbar} from './CollectionToolbar'
|
|
18
|
+
import {CollectionToolbar, type CollectionView} from './CollectionToolbar'
|
|
17
19
|
|
|
18
20
|
/** Colonnes montrées par défaut : le titre d'abord, puis les premières. */
|
|
19
21
|
const DEFAULT_MAX = 6
|
|
22
|
+
/** Largeur minimale d'une colonne au redimensionnement. */
|
|
23
|
+
const MIN_WIDTH = 80
|
|
24
|
+
/** Côté de la vignette d'icône (vue liste), calé sur la liste native de Sanity. */
|
|
25
|
+
const MEDIA = '2.0625rem'
|
|
20
26
|
|
|
21
27
|
function defaultVisible(columns: readonly CollectionColumn[]): string[] {
|
|
22
28
|
const title = columns.find((c) => c.key === 'title') ?? columns.find((c) => c.kind === 'text')
|
|
@@ -24,35 +30,82 @@ function defaultVisible(columns: readonly CollectionColumn[]): string[] {
|
|
|
24
30
|
return ordered.slice(0, DEFAULT_MAX).map((c) => c.key)
|
|
25
31
|
}
|
|
26
32
|
|
|
33
|
+
/** Largeur par défaut d'une colonne : le titre large, le reste selon le type. */
|
|
34
|
+
function defaultWidth(column: CollectionColumn, isFirst: boolean): number {
|
|
35
|
+
if (isFirst) return 340
|
|
36
|
+
switch (column.kind) {
|
|
37
|
+
case 'number':
|
|
38
|
+
return 110
|
|
39
|
+
case 'boolean':
|
|
40
|
+
return 90
|
|
41
|
+
case 'date':
|
|
42
|
+
return 150
|
|
43
|
+
case 'reference':
|
|
44
|
+
return 200
|
|
45
|
+
default:
|
|
46
|
+
return 190
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Déplace `fromKey` à la position de `toKey` dans la liste des clés. */
|
|
51
|
+
function moveKey(keys: string[], fromKey: string, toKey: string): string[] {
|
|
52
|
+
const from = keys.indexOf(fromKey)
|
|
53
|
+
const to = keys.indexOf(toKey)
|
|
54
|
+
if (from < 0 || to < 0 || from === to) return keys
|
|
55
|
+
const next = [...keys]
|
|
56
|
+
next.splice(from, 1)
|
|
57
|
+
next.splice(to, 0, fromKey)
|
|
58
|
+
return next
|
|
59
|
+
}
|
|
60
|
+
|
|
27
61
|
export interface CollectionTableProps {
|
|
28
62
|
type: string
|
|
63
|
+
/** Prédicat GROQ supplémentaire (ex. `language == $lang`) — niveau feuille. */
|
|
64
|
+
filter?: string
|
|
65
|
+
/** Valeurs des paramètres du `filter` (ex. `{lang: 'fr'}`). */
|
|
66
|
+
params?: Record<string, unknown>
|
|
67
|
+
/** Template de création à appliquer au « + » (ex. `article-fr`) : garde la
|
|
68
|
+
* création pré-taguée (langue, catégorie…) du niveau feuille. Sans lui, le
|
|
69
|
+
* « + » crée un document nu du type. */
|
|
70
|
+
newTemplate?: string
|
|
29
71
|
}
|
|
30
72
|
|
|
31
|
-
export function CollectionTable({type}: CollectionTableProps) {
|
|
73
|
+
export function CollectionTable({type, filter, params, newTemplate}: CollectionTableProps) {
|
|
32
74
|
const router = useRouter()
|
|
75
|
+
// Ouverture par VOLET ENFANT : le document s'ouvre à droite, les volets
|
|
76
|
+
// précédents se réduisent sans se fermer (le pane déclare un résolveur
|
|
77
|
+
// d'enfant, cf. `ncfCollectionTable`).
|
|
78
|
+
const {ChildLink} = usePaneRouter()
|
|
33
79
|
|
|
80
|
+
const [view, setView] = useState<CollectionView>('table')
|
|
34
81
|
// `null` = pas encore de choix explicite → colonnes par défaut.
|
|
35
82
|
const [selected, setSelected] = useState<string[] | null>(null)
|
|
36
83
|
const [sort, setSort] = useState<CollectionSort>({key: null, direction: 'asc'})
|
|
37
84
|
const [search, setSearch] = useState('')
|
|
38
|
-
const [
|
|
85
|
+
const [widths, setWidths] = useState<Record<string, number>>({})
|
|
39
86
|
|
|
40
87
|
// Toutes les colonnes viennent du schéma (sans requête) : elles fixent le
|
|
41
88
|
// défaut et alimentent le sélecteur. Seules les visibles sont ensuite
|
|
42
89
|
// projetées par le hook de données.
|
|
43
90
|
const schema = useSchema()
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
91
|
+
const schemaType = schema.get(type) as SchemaTypeLike | undefined
|
|
92
|
+
const TypeIcon = (schemaType as {icon?: ComponentType} | undefined)?.icon
|
|
93
|
+
const allColumns = useMemo(() => deriveCollectionColumns(schemaType), [schemaType])
|
|
48
94
|
const visibleKeys = useMemo(() => selected ?? defaultVisible(allColumns), [selected, allColumns])
|
|
49
95
|
|
|
50
|
-
const {visibleColumns, rows, loading, error, refresh} = useCollection(type, visibleKeys)
|
|
96
|
+
const {visibleColumns, rows, loading, error, refresh} = useCollection(type, visibleKeys, {filter, params})
|
|
51
97
|
|
|
52
98
|
const visible = useMemo(() => {
|
|
53
|
-
const filtered = filterRows(rows, {search, columns:
|
|
99
|
+
const filtered = filterRows(rows, {search, columns: {}}, visibleColumns)
|
|
54
100
|
return sortRows(filtered, sort, visibleColumns)
|
|
55
|
-
}, [rows, search,
|
|
101
|
+
}, [rows, search, visibleColumns, sort])
|
|
102
|
+
|
|
103
|
+
// Largeur effective de chaque colonne visible (état ou défaut selon le type).
|
|
104
|
+
const cols = useMemo(
|
|
105
|
+
() => visibleColumns.map((column, index) => ({column, width: widths[column.key] ?? defaultWidth(column, index === 0)})),
|
|
106
|
+
[visibleColumns, widths],
|
|
107
|
+
)
|
|
108
|
+
const totalWidth = useMemo(() => cols.reduce((sum, c) => sum + c.width, 0), [cols])
|
|
56
109
|
|
|
57
110
|
const onToggleColumn = useCallback(
|
|
58
111
|
(key: string) => {
|
|
@@ -60,12 +113,6 @@ export function CollectionTable({type}: CollectionTableProps) {
|
|
|
60
113
|
const base = current ?? defaultVisible(allColumns)
|
|
61
114
|
return base.includes(key) ? base.filter((k) => k !== key) : [...base, key]
|
|
62
115
|
})
|
|
63
|
-
// Un filtre sur une colonne qu'on masque n'a plus de sens.
|
|
64
|
-
setColumnFilters((current) => {
|
|
65
|
-
if (!current[key]) return current
|
|
66
|
-
const {[key]: _removed, ...rest} = current
|
|
67
|
-
return rest
|
|
68
|
-
})
|
|
69
116
|
},
|
|
70
117
|
[allColumns],
|
|
71
118
|
)
|
|
@@ -82,9 +129,44 @@ export function CollectionTable({type}: CollectionTableProps) {
|
|
|
82
129
|
downloadText(`${type}.csv`, toCsv(visible, visibleColumns))
|
|
83
130
|
}, [type, visible, visibleColumns])
|
|
84
131
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
132
|
+
// Création : applique le template du niveau feuille (langue, catégorie…) s'il
|
|
133
|
+
// est fourni, sinon un document nu du type.
|
|
134
|
+
const onCreate = useCallback(() => {
|
|
135
|
+
router.navigateIntent('create', newTemplate ? {type, template: newTemplate} : {type})
|
|
136
|
+
}, [router, type, newTemplate])
|
|
137
|
+
|
|
138
|
+
// --- Réordonnancement des colonnes (glisser l'en-tête) ---
|
|
139
|
+
const dragKeyRef = useRef<string | null>(null)
|
|
140
|
+
const [dragOverKey, setDragOverKey] = useState<string | null>(null)
|
|
141
|
+
const onReorder = useCallback(
|
|
142
|
+
(toKey: string) => {
|
|
143
|
+
const fromKey = dragKeyRef.current
|
|
144
|
+
dragKeyRef.current = null
|
|
145
|
+
setDragOverKey(null)
|
|
146
|
+
if (!fromKey || fromKey === toKey) return
|
|
147
|
+
setSelected((current) => moveKey(current ?? defaultVisible(allColumns), fromKey, toKey))
|
|
148
|
+
},
|
|
149
|
+
[allColumns],
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
// --- Redimensionnement d'une colonne (glisser la poignée à droite) ---
|
|
153
|
+
const onResizeStart = useCallback(
|
|
154
|
+
(key: string, startW: number) => (event: React.PointerEvent) => {
|
|
155
|
+
event.preventDefault()
|
|
156
|
+
event.stopPropagation()
|
|
157
|
+
const startX = event.clientX
|
|
158
|
+
const onMove = (ev: PointerEvent) => {
|
|
159
|
+
setWidths((current) => ({...current, [key]: Math.max(MIN_WIDTH, startW + (ev.clientX - startX))}))
|
|
160
|
+
}
|
|
161
|
+
const onUp = () => {
|
|
162
|
+
window.removeEventListener('pointermove', onMove)
|
|
163
|
+
window.removeEventListener('pointerup', onUp)
|
|
164
|
+
}
|
|
165
|
+
window.addEventListener('pointermove', onMove)
|
|
166
|
+
window.addEventListener('pointerup', onUp)
|
|
167
|
+
},
|
|
168
|
+
[],
|
|
169
|
+
)
|
|
88
170
|
|
|
89
171
|
if (error) return <QueryError error={error} onRetry={refresh} />
|
|
90
172
|
|
|
@@ -93,18 +175,18 @@ export function CollectionTable({type}: CollectionTableProps) {
|
|
|
93
175
|
? `${rows.length} item${rows.length > 1 ? 's' : ''}`
|
|
94
176
|
: `${visible.length} of ${rows.length}`
|
|
95
177
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
alignItems: 'center',
|
|
103
|
-
}
|
|
178
|
+
const titleKey = visibleColumns[0]?.key
|
|
179
|
+
// Sous-titre de la vue liste : un slug/chemin/URL si présent, sinon la
|
|
180
|
+
// première colonne texte après le titre (façon liste native).
|
|
181
|
+
const subtitleKey =
|
|
182
|
+
visibleColumns.find((c, i) => i > 0 && /slug|path|url|email/i.test(c.key))?.key ??
|
|
183
|
+
visibleColumns.find((c, i) => i > 0 && c.kind === 'text')?.key
|
|
104
184
|
|
|
105
185
|
return (
|
|
106
|
-
<Stack gap={
|
|
186
|
+
<Stack gap={3}>
|
|
107
187
|
<CollectionToolbar
|
|
188
|
+
view={view}
|
|
189
|
+
onView={setView}
|
|
108
190
|
search={search}
|
|
109
191
|
onSearch={setSearch}
|
|
110
192
|
columns={allColumns}
|
|
@@ -112,6 +194,7 @@ export function CollectionTable({type}: CollectionTableProps) {
|
|
|
112
194
|
onToggleColumn={onToggleColumn}
|
|
113
195
|
onExport={onExport}
|
|
114
196
|
onRefresh={refresh}
|
|
197
|
+
onCreate={onCreate}
|
|
115
198
|
busy={loading}
|
|
116
199
|
summary={summary}
|
|
117
200
|
/>
|
|
@@ -129,79 +212,119 @@ export function CollectionTable({type}: CollectionTableProps) {
|
|
|
129
212
|
No displayable field in this type. Pick columns above.
|
|
130
213
|
</Text>
|
|
131
214
|
</Box>
|
|
215
|
+
) : view === 'list' ? (
|
|
216
|
+
<Box style={{border: `1px solid ${BORDER_SOFT}`, borderRadius: 6, overflow: 'hidden'}}>
|
|
217
|
+
<style>{`.ncf-coll-body a{display:block;color:inherit;text-decoration:none}`}</style>
|
|
218
|
+
<Box className="ncf-coll-body">
|
|
219
|
+
{visible.map((row) => (
|
|
220
|
+
<ChildLink key={row.id} childId={row.id}>
|
|
221
|
+
<ListRowView row={row} titleKey={titleKey} subtitleKey={subtitleKey} Icon={TypeIcon} />
|
|
222
|
+
</ChildLink>
|
|
223
|
+
))}
|
|
224
|
+
{visible.length === 0 && (
|
|
225
|
+
<Box padding={5}>
|
|
226
|
+
<Text size={1} muted align="center">
|
|
227
|
+
{rows.length === 0 ? 'No item yet.' : 'No match.'}
|
|
228
|
+
</Text>
|
|
229
|
+
</Box>
|
|
230
|
+
)}
|
|
231
|
+
</Box>
|
|
232
|
+
</Box>
|
|
132
233
|
) : (
|
|
133
234
|
<Box style={{overflowX: 'auto', border: `1px solid ${BORDER_SOFT}`, borderRadius: 6}}>
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
|
|
235
|
+
<style>{`.ncf-coll-body a{display:contents;color:inherit;text-decoration:none}`}</style>
|
|
236
|
+
<Box style={{width: totalWidth, minWidth: '100%'}}>
|
|
237
|
+
{/* En-tête : libellé triable + déplaçable, poignée de largeur. */}
|
|
238
|
+
<Flex
|
|
137
239
|
paddingX={3}
|
|
138
|
-
paddingY={
|
|
240
|
+
paddingY={3}
|
|
241
|
+
align="center"
|
|
139
242
|
style={{
|
|
140
|
-
...grid,
|
|
141
|
-
alignItems: 'end',
|
|
142
243
|
borderBottom: `1px solid ${BORDER}`,
|
|
143
244
|
position: 'sticky',
|
|
144
245
|
top: 0,
|
|
145
|
-
background: 'var(--card-bg-color, inherit)',
|
|
246
|
+
background: 'var(--card-muted-bg-color, var(--card-bg-color, inherit))',
|
|
146
247
|
zIndex: 2,
|
|
147
248
|
}}
|
|
148
249
|
>
|
|
149
|
-
{
|
|
250
|
+
{cols.map(({column, width}) => {
|
|
150
251
|
const active = sort.key === column.key
|
|
151
252
|
const Arrow = sort.direction === 'asc' ? ChevronUpIcon : ChevronDownIcon
|
|
253
|
+
const alignEnd = column.kind === 'number'
|
|
152
254
|
return (
|
|
153
|
-
<
|
|
255
|
+
<Box
|
|
256
|
+
key={column.key}
|
|
257
|
+
paddingRight={2}
|
|
258
|
+
onDragOver={(e) => {
|
|
259
|
+
if (dragKeyRef.current && dragKeyRef.current !== column.key) {
|
|
260
|
+
e.preventDefault()
|
|
261
|
+
setDragOverKey(column.key)
|
|
262
|
+
}
|
|
263
|
+
}}
|
|
264
|
+
onDrop={() => onReorder(column.key)}
|
|
265
|
+
style={{
|
|
266
|
+
width,
|
|
267
|
+
flex: 'none',
|
|
268
|
+
position: 'relative',
|
|
269
|
+
boxSizing: 'border-box',
|
|
270
|
+
borderLeft: dragOverKey === column.key ? `2px solid var(--card-focus-ring-color, #2276fc)` : '2px solid transparent',
|
|
271
|
+
}}
|
|
272
|
+
>
|
|
154
273
|
<Flex
|
|
155
274
|
align="center"
|
|
156
275
|
gap={1}
|
|
276
|
+
justify={alignEnd ? 'flex-end' : 'flex-start'}
|
|
277
|
+
draggable
|
|
278
|
+
onDragStart={() => {
|
|
279
|
+
dragKeyRef.current = column.key
|
|
280
|
+
}}
|
|
281
|
+
onDragEnd={() => {
|
|
282
|
+
dragKeyRef.current = null
|
|
283
|
+
setDragOverKey(null)
|
|
284
|
+
}}
|
|
157
285
|
onClick={() => onSort(column.key)}
|
|
158
|
-
style={{cursor: '
|
|
159
|
-
title={`Sort by ${column.label.toLowerCase()}`}
|
|
286
|
+
style={{cursor: 'grab', userSelect: 'none'}}
|
|
287
|
+
title={`Sort by ${column.label.toLowerCase()} — drag to reorder`}
|
|
160
288
|
>
|
|
161
|
-
<Text size={
|
|
289
|
+
<Text size={1} weight="semibold" muted={!active} textOverflow="ellipsis">
|
|
162
290
|
{column.label}
|
|
163
291
|
</Text>
|
|
164
|
-
{active && <Arrow style={{fontSize:
|
|
292
|
+
{active && <Arrow style={{fontSize: 14, opacity: 0.7, flex: 'none'}} />}
|
|
165
293
|
</Flex>
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
onChange={(event) => onColumnFilter(column.key, event.currentTarget.value)}
|
|
294
|
+
{/* Poignée de redimensionnement (bord droit). */}
|
|
295
|
+
<div
|
|
296
|
+
onPointerDown={onResizeStart(column.key, width)}
|
|
297
|
+
title="Drag to resize"
|
|
171
298
|
style={{
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
color: 'var(--card-fg-color)',
|
|
180
|
-
outline: 'none',
|
|
299
|
+
position: 'absolute',
|
|
300
|
+
top: 0,
|
|
301
|
+
right: 0,
|
|
302
|
+
width: 9,
|
|
303
|
+
height: '100%',
|
|
304
|
+
cursor: 'col-resize',
|
|
305
|
+
touchAction: 'none',
|
|
181
306
|
}}
|
|
182
307
|
/>
|
|
183
|
-
</
|
|
308
|
+
</Box>
|
|
184
309
|
)
|
|
185
310
|
})}
|
|
186
|
-
</
|
|
311
|
+
</Flex>
|
|
187
312
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
key={row.id}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
onOpen={() => router.navigateIntent('edit', {id: row.id, type})}
|
|
195
|
-
/>
|
|
196
|
-
))}
|
|
313
|
+
<Box className="ncf-coll-body">
|
|
314
|
+
{visible.map((row) => (
|
|
315
|
+
<ChildLink key={row.id} childId={row.id}>
|
|
316
|
+
<TableRowView row={row} cols={cols} Icon={TypeIcon} />
|
|
317
|
+
</ChildLink>
|
|
318
|
+
))}
|
|
197
319
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
320
|
+
{visible.length === 0 && (
|
|
321
|
+
<Box padding={5}>
|
|
322
|
+
<Text size={1} muted align="center">
|
|
323
|
+
{rows.length === 0 ? 'No item yet.' : 'No match.'}
|
|
324
|
+
</Text>
|
|
325
|
+
</Box>
|
|
326
|
+
)}
|
|
327
|
+
</Box>
|
|
205
328
|
</Box>
|
|
206
329
|
</Box>
|
|
207
330
|
)}
|
|
@@ -209,44 +332,73 @@ export function CollectionTable({type}: CollectionTableProps) {
|
|
|
209
332
|
)
|
|
210
333
|
}
|
|
211
334
|
|
|
212
|
-
|
|
335
|
+
/** Pastille de statut : vert = publié, ambre = brouillon jamais publié. */
|
|
336
|
+
function StatusDot(props: {draftOnly?: boolean}) {
|
|
337
|
+
return (
|
|
338
|
+
<span
|
|
339
|
+
title={props.draftOnly ? 'Not published' : 'Published'}
|
|
340
|
+
style={{
|
|
341
|
+
flex: 'none',
|
|
342
|
+
width: 9,
|
|
343
|
+
height: 9,
|
|
344
|
+
borderRadius: '50%',
|
|
345
|
+
background: props.draftOnly ? '#f5a623' : '#43d675',
|
|
346
|
+
}}
|
|
347
|
+
/>
|
|
348
|
+
)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Ligne de la vue TABLE : une cellule par colonne, largeurs fixes. */
|
|
352
|
+
function TableRowView(props: {
|
|
213
353
|
row: CollectionRow
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
onOpen: () => void
|
|
354
|
+
cols: readonly {column: CollectionColumn; width: number}[]
|
|
355
|
+
Icon?: ComponentType
|
|
217
356
|
}) {
|
|
218
|
-
const {row,
|
|
357
|
+
const {row, cols, Icon} = props
|
|
219
358
|
const [hovered, setHovered] = useState(false)
|
|
220
359
|
|
|
221
360
|
return (
|
|
222
|
-
<
|
|
361
|
+
<Flex
|
|
223
362
|
paddingX={3}
|
|
224
363
|
paddingY={2}
|
|
225
|
-
|
|
364
|
+
align="center"
|
|
226
365
|
onMouseEnter={() => setHovered(true)}
|
|
227
366
|
onMouseLeave={() => setHovered(false)}
|
|
228
367
|
style={{
|
|
229
|
-
...grid,
|
|
230
368
|
cursor: 'pointer',
|
|
231
369
|
borderBottom: `1px solid ${BORDER_SOFT}`,
|
|
232
370
|
background: hovered ? 'var(--card-muted-bg-color, rgba(127,127,127,0.08))' : 'transparent',
|
|
233
371
|
}}
|
|
234
372
|
>
|
|
235
|
-
{
|
|
373
|
+
{cols.map(({column, width}, index) => {
|
|
236
374
|
const cell = row.cells[column.key]
|
|
237
375
|
const empty = !cell || cell.raw === null || cell.text === ''
|
|
376
|
+
const first = index === 0
|
|
377
|
+
const alignEnd = column.kind === 'number'
|
|
238
378
|
return (
|
|
239
|
-
<Flex
|
|
379
|
+
<Flex
|
|
380
|
+
key={column.key}
|
|
381
|
+
align="center"
|
|
382
|
+
gap={2}
|
|
383
|
+
paddingRight={2}
|
|
384
|
+
justify={alignEnd ? 'flex-end' : 'flex-start'}
|
|
385
|
+
style={{width, flex: 'none', boxSizing: 'border-box'}}
|
|
386
|
+
>
|
|
387
|
+
{first && (
|
|
388
|
+
<Text size={1} muted style={{flex: 'none', display: 'flex'}}>
|
|
389
|
+
{Icon ? <Icon /> : <DocumentIcon />}
|
|
390
|
+
</Text>
|
|
391
|
+
)}
|
|
240
392
|
<Text
|
|
241
393
|
size={1}
|
|
242
394
|
muted={empty}
|
|
243
|
-
weight={
|
|
395
|
+
weight={first ? 'medium' : 'regular'}
|
|
244
396
|
textOverflow="ellipsis"
|
|
245
|
-
style={{flex: 1, minWidth: 0, ...(column.kind === 'number' || column.kind === 'date' ? TABULAR : null)}}
|
|
397
|
+
style={{flex: alignEnd ? 'none' : 1, minWidth: 0, ...(column.kind === 'number' || column.kind === 'date' ? TABULAR : null)}}
|
|
246
398
|
>
|
|
247
399
|
{empty ? '—' : cell.text}
|
|
248
400
|
</Text>
|
|
249
|
-
{
|
|
401
|
+
{first && row.draftOnly && (
|
|
250
402
|
<Badge tone="caution" fontSize={0} style={{flex: 'none'}}>
|
|
251
403
|
Draft
|
|
252
404
|
</Badge>
|
|
@@ -254,6 +406,60 @@ function CollectionRowView(props: {
|
|
|
254
406
|
</Flex>
|
|
255
407
|
)
|
|
256
408
|
})}
|
|
257
|
-
</
|
|
409
|
+
</Flex>
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** Ligne de la vue LISTE : vignette + titre + sous-titre, façon liste native. */
|
|
414
|
+
function ListRowView(props: {row: CollectionRow; titleKey?: string; subtitleKey?: string; Icon?: ComponentType}) {
|
|
415
|
+
const {row, titleKey, subtitleKey, Icon} = props
|
|
416
|
+
const [hovered, setHovered] = useState(false)
|
|
417
|
+
const title = titleKey ? row.cells[titleKey]?.text : ''
|
|
418
|
+
const subtitle = subtitleKey ? row.cells[subtitleKey]?.text : ''
|
|
419
|
+
|
|
420
|
+
return (
|
|
421
|
+
<Flex
|
|
422
|
+
align="center"
|
|
423
|
+
gap={3}
|
|
424
|
+
padding={2}
|
|
425
|
+
onMouseEnter={() => setHovered(true)}
|
|
426
|
+
onMouseLeave={() => setHovered(false)}
|
|
427
|
+
style={{
|
|
428
|
+
cursor: 'pointer',
|
|
429
|
+
borderBottom: `1px solid ${BORDER_SOFT}`,
|
|
430
|
+
background: hovered ? 'var(--card-muted-bg-color, rgba(127,127,127,0.08))' : 'transparent',
|
|
431
|
+
}}
|
|
432
|
+
>
|
|
433
|
+
{/* Vignette : icône du type dans un cadre, calée sur la liste native. */}
|
|
434
|
+
<Flex
|
|
435
|
+
align="center"
|
|
436
|
+
justify="center"
|
|
437
|
+
style={{
|
|
438
|
+
width: MEDIA,
|
|
439
|
+
height: MEDIA,
|
|
440
|
+
flex: 'none',
|
|
441
|
+
border: `1px solid ${BORDER_SOFT}`,
|
|
442
|
+
borderRadius: 3,
|
|
443
|
+
color: 'var(--card-muted-fg-color)',
|
|
444
|
+
}}
|
|
445
|
+
>
|
|
446
|
+
<Text size={2} muted style={{display: 'flex'}}>
|
|
447
|
+
{Icon ? <Icon /> : <DocumentIcon />}
|
|
448
|
+
</Text>
|
|
449
|
+
</Flex>
|
|
450
|
+
|
|
451
|
+
<Stack gap={2} flex={1} style={{minWidth: 0}}>
|
|
452
|
+
<Text size={1} textOverflow="ellipsis">
|
|
453
|
+
{title || 'Untitled'}
|
|
454
|
+
</Text>
|
|
455
|
+
{subtitle ? (
|
|
456
|
+
<Text size={1} muted textOverflow="ellipsis">
|
|
457
|
+
{subtitle}
|
|
458
|
+
</Text>
|
|
459
|
+
) : null}
|
|
460
|
+
</Stack>
|
|
461
|
+
|
|
462
|
+
<StatusDot draftOnly={row.draftOnly} />
|
|
463
|
+
</Flex>
|
|
258
464
|
)
|
|
259
465
|
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import {Box, Button, Flex, Text, TextInput} from '@sanity/ui'
|
|
1
|
+
import {Box, Button, Card, Flex, Text, TextInput} from '@sanity/ui'
|
|
2
2
|
import {SearchIcon} from '@sanity/icons/Search'
|
|
3
3
|
import {DownloadIcon} from '@sanity/icons/Download'
|
|
4
4
|
import {RefreshIcon} from '@sanity/icons/Refresh'
|
|
5
|
+
import {AddIcon} from '@sanity/icons/Add'
|
|
6
|
+
import {ThLargeIcon} from '@sanity/icons/ThLarge'
|
|
7
|
+
import {UlistIcon} from '@sanity/icons/Ulist'
|
|
5
8
|
import {CollectionColumnPicker} from './CollectionColumnPicker'
|
|
6
9
|
import type {CollectionColumn} from '../../lib/collectionColumns'
|
|
7
10
|
|
|
11
|
+
/** Vue courante de la collection : liste compacte ou table. */
|
|
12
|
+
export type CollectionView = 'list' | 'table'
|
|
13
|
+
|
|
8
14
|
export interface CollectionToolbarProps {
|
|
15
|
+
view: CollectionView
|
|
16
|
+
onView: (view: CollectionView) => void
|
|
9
17
|
search: string
|
|
10
18
|
onSearch: (value: string) => void
|
|
11
19
|
columns: readonly CollectionColumn[]
|
|
@@ -13,17 +21,45 @@ export interface CollectionToolbarProps {
|
|
|
13
21
|
onToggleColumn: (key: string) => void
|
|
14
22
|
onExport: () => void
|
|
15
23
|
onRefresh: () => void
|
|
24
|
+
/** Création d'un item (template du niveau feuille appliqué par l'appelant). */
|
|
25
|
+
onCreate?: () => void
|
|
16
26
|
busy: boolean
|
|
17
27
|
/** Résumé « N items » ou « N of M ». */
|
|
18
28
|
summary: string
|
|
19
29
|
}
|
|
20
30
|
|
|
21
|
-
/** Barre au-dessus de la
|
|
31
|
+
/** Barre au-dessus de la collection : switch de vue, création, recherche, colonnes, export. */
|
|
22
32
|
export function CollectionToolbar(props: CollectionToolbarProps) {
|
|
23
|
-
const {search, onSearch, columns, visible, onToggleColumn, onExport, onRefresh, busy, summary} = props
|
|
33
|
+
const {view, onView, search, onSearch, columns, visible, onToggleColumn, onExport, onRefresh, onCreate, busy, summary} = props
|
|
24
34
|
|
|
25
35
|
return (
|
|
26
36
|
<Flex align="center" gap={2} wrap="wrap">
|
|
37
|
+
{/* Switch Liste / Table. */}
|
|
38
|
+
<Card radius={2} border style={{flex: 'none'}}>
|
|
39
|
+
<Flex>
|
|
40
|
+
<Button
|
|
41
|
+
mode={view === 'list' ? 'default' : 'bleed'}
|
|
42
|
+
tone={view === 'list' ? 'primary' : 'default'}
|
|
43
|
+
fontSize={1}
|
|
44
|
+
padding={2}
|
|
45
|
+
icon={UlistIcon}
|
|
46
|
+
title="List view"
|
|
47
|
+
aria-label="List view"
|
|
48
|
+
onClick={() => onView('list')}
|
|
49
|
+
/>
|
|
50
|
+
<Button
|
|
51
|
+
mode={view === 'table' ? 'default' : 'bleed'}
|
|
52
|
+
tone={view === 'table' ? 'primary' : 'default'}
|
|
53
|
+
fontSize={1}
|
|
54
|
+
padding={2}
|
|
55
|
+
icon={ThLargeIcon}
|
|
56
|
+
title="Table view"
|
|
57
|
+
aria-label="Table view"
|
|
58
|
+
onClick={() => onView('table')}
|
|
59
|
+
/>
|
|
60
|
+
</Flex>
|
|
61
|
+
</Card>
|
|
62
|
+
|
|
27
63
|
<Box style={{flex: 1, minWidth: 180}}>
|
|
28
64
|
<TextInput
|
|
29
65
|
icon={SearchIcon}
|
|
@@ -43,7 +79,20 @@ export function CollectionToolbar(props: CollectionToolbarProps) {
|
|
|
43
79
|
</Text>
|
|
44
80
|
|
|
45
81
|
<Flex gap={1} style={{flex: 'none'}}>
|
|
46
|
-
|
|
82
|
+
{onCreate && (
|
|
83
|
+
<Button
|
|
84
|
+
mode="ghost"
|
|
85
|
+
tone="primary"
|
|
86
|
+
fontSize={1}
|
|
87
|
+
padding={2}
|
|
88
|
+
icon={AddIcon}
|
|
89
|
+
text="New"
|
|
90
|
+
onClick={onCreate}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
{view === 'table' && (
|
|
94
|
+
<CollectionColumnPicker columns={columns} visible={visible} onToggle={onToggleColumn} />
|
|
95
|
+
)}
|
|
47
96
|
<Button
|
|
48
97
|
mode="bleed"
|
|
49
98
|
fontSize={1}
|