@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.
- package/README.md +2 -1
- 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 +287 -5
- package/dist/index.js +2119 -181
- package/dist/index.js.map +1 -1
- package/dist/jsonld.js +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/ComponentMetaContext.tsx +23 -0
- package/src/form/ArrayNamesInput.tsx +25 -0
- package/src/form/renameArrayMembers.ts +25 -0
- package/src/hooks/useAssetMeta.ts +166 -0
- package/src/hooks/useAssets.ts +23 -0
- package/src/hooks/useComponentMeta.ts +159 -0
- package/src/hooks/useComponentNames.ts +39 -0
- package/src/index.ts +56 -1
- package/src/lib/assets.ts +161 -0
- package/src/lib/componentMeta.ts +70 -0
- package/src/schema/assetMeta.ts +65 -0
- package/src/schema/boardLayout.ts +5 -1
- package/src/schema/componentMeta.ts +54 -0
- 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/components/BlockCard.tsx +20 -12
- package/src/tools/components/ComponentEditDialog.tsx +83 -0
- package/src/tools/components/ComponentsTool.tsx +190 -84
- package/src/version.ts +1 -1
- package/dist/finalUrl-C1kzYMzQ.js.map +0 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types et transformations pures de l'outil Assets (gestionnaire de médias).
|
|
3
|
+
* Rien d'ici ne dépend de React ni de Sanity : tout est testable.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface AssetDimensions {
|
|
7
|
+
width?: number
|
|
8
|
+
height?: number
|
|
9
|
+
aspectRatio?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Un asset du dataset (`sanity.imageAsset` ou `sanity.fileAsset`). */
|
|
13
|
+
export interface AssetDoc {
|
|
14
|
+
_id: string
|
|
15
|
+
_type: 'sanity.imageAsset' | 'sanity.fileAsset'
|
|
16
|
+
_createdAt: string
|
|
17
|
+
_updatedAt?: string
|
|
18
|
+
originalFilename?: string
|
|
19
|
+
extension?: string
|
|
20
|
+
mimeType?: string
|
|
21
|
+
size?: number
|
|
22
|
+
url?: string
|
|
23
|
+
title?: string
|
|
24
|
+
altText?: string
|
|
25
|
+
description?: string
|
|
26
|
+
dimensions?: AssetDimensions
|
|
27
|
+
lqip?: string
|
|
28
|
+
/** Nombre de documents qui référencent l'asset (utilisé / inutilisé). */
|
|
29
|
+
uses?: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Dossier d'organisation (géré par le kit, singleton `ncfAssetMeta`). */
|
|
33
|
+
export interface AssetFolder {
|
|
34
|
+
id: string
|
|
35
|
+
name: string
|
|
36
|
+
parent?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const isImageAsset = (asset: {_type?: string}): boolean => asset._type === 'sanity.imageAsset'
|
|
40
|
+
|
|
41
|
+
/** Nom affiché : titre saisi, sinon nom de fichier, sinon id. */
|
|
42
|
+
export function assetName(asset: AssetDoc): string {
|
|
43
|
+
return asset.title?.trim() || asset.originalFilename || asset._id
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Taille lisible (o / Ko / Mo / Go). */
|
|
47
|
+
export function formatBytes(size: number | undefined): string {
|
|
48
|
+
if (!size || size <= 0) return '—'
|
|
49
|
+
const units = ['o', 'Ko', 'Mo', 'Go', 'To']
|
|
50
|
+
let value = size
|
|
51
|
+
let unit = 0
|
|
52
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
53
|
+
value /= 1024
|
|
54
|
+
unit += 1
|
|
55
|
+
}
|
|
56
|
+
const rounded = unit === 0 ? value : value < 10 ? Math.round(value * 10) / 10 : Math.round(value)
|
|
57
|
+
return `${rounded} ${units[unit]}`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* URL de vignette depuis l'URL CDN de l'asset (paramètres de transformation
|
|
62
|
+
* Sanity). Renvoie `undefined` pour un non-image (pas de rendu).
|
|
63
|
+
*/
|
|
64
|
+
export function thumbnailUrl(asset: Pick<AssetDoc, 'url' | '_type'>, opts: {w?: number; h?: number} = {}): string | undefined {
|
|
65
|
+
if (!asset.url || !isImageAsset(asset)) return undefined
|
|
66
|
+
const params = new URLSearchParams()
|
|
67
|
+
if (opts.w) params.set('w', String(opts.w))
|
|
68
|
+
if (opts.h) params.set('h', String(opts.h))
|
|
69
|
+
params.set('fit', 'crop')
|
|
70
|
+
params.set('auto', 'format')
|
|
71
|
+
return `${asset.url}?${params.toString()}`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type AssetSortKey = 'date' | 'name' | 'size' | 'type'
|
|
75
|
+
export type SortDirection = 'asc' | 'desc'
|
|
76
|
+
export type AssetTypeFilter = 'all' | 'image' | 'file'
|
|
77
|
+
export type AssetUsageFilter = 'all' | 'used' | 'unused'
|
|
78
|
+
|
|
79
|
+
export interface AssetFilter {
|
|
80
|
+
search?: string
|
|
81
|
+
type?: AssetTypeFilter
|
|
82
|
+
usage?: AssetUsageFilter
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function matchesSearch(asset: AssetDoc, query: string): boolean {
|
|
86
|
+
const haystack = [asset.title, asset.originalFilename, asset.altText, asset.description, asset.extension]
|
|
87
|
+
.filter(Boolean)
|
|
88
|
+
.join(' ')
|
|
89
|
+
.toLowerCase()
|
|
90
|
+
return haystack.includes(query)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Filtre par recherche, type (image/fichier) et usage. */
|
|
94
|
+
export function filterAssets(assets: readonly AssetDoc[], filter: AssetFilter = {}): AssetDoc[] {
|
|
95
|
+
const query = filter.search?.trim().toLowerCase() ?? ''
|
|
96
|
+
const type = filter.type ?? 'all'
|
|
97
|
+
const usage = filter.usage ?? 'all'
|
|
98
|
+
return assets.filter((asset) => {
|
|
99
|
+
if (query && !matchesSearch(asset, query)) return false
|
|
100
|
+
if (type === 'image' && !isImageAsset(asset)) return false
|
|
101
|
+
if (type === 'file' && isImageAsset(asset)) return false
|
|
102
|
+
if (usage === 'used' && !(asset.uses && asset.uses > 0)) return false
|
|
103
|
+
if (usage === 'unused' && asset.uses && asset.uses > 0) return false
|
|
104
|
+
return true
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Tri stable par date / nom / taille / type. */
|
|
109
|
+
export function sortAssets(assets: readonly AssetDoc[], key: AssetSortKey, direction: SortDirection = 'desc'): AssetDoc[] {
|
|
110
|
+
const factor = direction === 'asc' ? 1 : -1
|
|
111
|
+
const compare = (a: AssetDoc, b: AssetDoc): number => {
|
|
112
|
+
switch (key) {
|
|
113
|
+
case 'name':
|
|
114
|
+
return assetName(a).localeCompare(assetName(b), 'fr', {numeric: true})
|
|
115
|
+
case 'size':
|
|
116
|
+
return (a.size ?? 0) - (b.size ?? 0)
|
|
117
|
+
case 'type':
|
|
118
|
+
return (a.extension ?? a._type).localeCompare(b.extension ?? b._type)
|
|
119
|
+
case 'date':
|
|
120
|
+
default:
|
|
121
|
+
return (a._createdAt < b._createdAt ? -1 : a._createdAt > b._createdAt ? 1 : 0)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return [...assets].sort((a, b) => factor * compare(a, b))
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* --- Dossiers (un seul emplacement par asset) --- */
|
|
128
|
+
|
|
129
|
+
export interface AssetAssignment {
|
|
130
|
+
/** `_id` de l'asset. */
|
|
131
|
+
assetId: string
|
|
132
|
+
/** Id du dossier, ou null (non classé). */
|
|
133
|
+
folder: string | null
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Map assetId -> id de dossier, à partir des affectations stockées. */
|
|
137
|
+
export function assignmentMap(assignments: readonly AssetAssignment[]): Map<string, string> {
|
|
138
|
+
const map = new Map<string, string>()
|
|
139
|
+
for (const {assetId, folder} of assignments) if (folder) map.set(assetId, folder)
|
|
140
|
+
return map
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Sélecteur de dossier courant. `null` = tout, `''` = non classés. */
|
|
144
|
+
export type FolderSelection = string | null
|
|
145
|
+
|
|
146
|
+
/** Assets du dossier sélectionné (`null` = tous, `''` = sans dossier). */
|
|
147
|
+
export function assetsInFolder(assets: readonly AssetDoc[], folders: Map<string, string>, selection: FolderSelection): AssetDoc[] {
|
|
148
|
+
if (selection === null) return [...assets]
|
|
149
|
+
if (selection === '') return assets.filter((asset) => !folders.has(asset._id))
|
|
150
|
+
return assets.filter((asset) => folders.get(asset._id) === selection)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Nombre d'assets par dossier (+ `''` pour les non classés). */
|
|
154
|
+
export function countByFolder(assets: readonly AssetDoc[], folders: Map<string, string>): Map<string, number> {
|
|
155
|
+
const counts = new Map<string, number>()
|
|
156
|
+
for (const asset of assets) {
|
|
157
|
+
const folder = folders.get(asset._id) ?? ''
|
|
158
|
+
counts.set(folder, (counts.get(folder) ?? 0) + 1)
|
|
159
|
+
}
|
|
160
|
+
return counts
|
|
161
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types et transformations pures de l'organisation des composants (groupes +
|
|
3
|
+
* noms marketing). Rien ici ne dépend de React ni de Sanity.
|
|
4
|
+
*/
|
|
5
|
+
import type {BlockTypeInfo} from './schemaTypes'
|
|
6
|
+
|
|
7
|
+
export interface ComponentGroup {
|
|
8
|
+
id: string
|
|
9
|
+
name: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Entrée d'organisation d'un composant, repérée par son TYPE. */
|
|
13
|
+
export interface ComponentEntry {
|
|
14
|
+
/** Type du composant (ex. `section.hero`). */
|
|
15
|
+
type: string
|
|
16
|
+
/** Nom marketing personnalisé (sinon le titre du schéma). */
|
|
17
|
+
name?: string
|
|
18
|
+
/** Id du groupe, ou absent (non groupé). */
|
|
19
|
+
group?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Map type -> nom personnalisé (ignore les vides). */
|
|
23
|
+
export function nameMap(entries: readonly ComponentEntry[]): Map<string, string> {
|
|
24
|
+
const map = new Map<string, string>()
|
|
25
|
+
for (const entry of entries) if (entry.name?.trim()) map.set(entry.type, entry.name.trim())
|
|
26
|
+
return map
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Map type -> id de groupe (ignore les vides). */
|
|
30
|
+
export function groupMap(entries: readonly ComponentEntry[]): Map<string, string> {
|
|
31
|
+
const map = new Map<string, string>()
|
|
32
|
+
for (const entry of entries) if (entry.group) map.set(entry.type, entry.group)
|
|
33
|
+
return map
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Applique le nom marketing au `title` d'un composant (garde `name`/type). */
|
|
37
|
+
export function withCustomNames(blocks: readonly BlockTypeInfo[], names: Map<string, string>): BlockTypeInfo[] {
|
|
38
|
+
return blocks.map((block) => (names.has(block.name) ? {...block, title: names.get(block.name) as string} : block))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ComponentGrouping {
|
|
42
|
+
/** Groupes dans l'ordre déclaré, avec leurs composants (dans l'ordre d'entrée). */
|
|
43
|
+
grouped: {group: ComponentGroup; blocks: BlockTypeInfo[]}[]
|
|
44
|
+
/** Composants sans groupe. */
|
|
45
|
+
ungrouped: BlockTypeInfo[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Répartit les composants par groupe (ordre des groupes préservé). */
|
|
49
|
+
export function groupComponents(
|
|
50
|
+
blocks: readonly BlockTypeInfo[],
|
|
51
|
+
groupOf: Map<string, string>,
|
|
52
|
+
groups: readonly ComponentGroup[],
|
|
53
|
+
): ComponentGrouping {
|
|
54
|
+
const byGroup = new Map<string, BlockTypeInfo[]>()
|
|
55
|
+
const ungrouped: BlockTypeInfo[] = []
|
|
56
|
+
for (const block of blocks) {
|
|
57
|
+
const group = groupOf.get(block.name)
|
|
58
|
+
if (group && groups.some((g) => g.id === group)) {
|
|
59
|
+
const list = byGroup.get(group) ?? []
|
|
60
|
+
list.push(block)
|
|
61
|
+
byGroup.set(group, list)
|
|
62
|
+
} else {
|
|
63
|
+
ungrouped.push(block)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
grouped: groups.map((group) => ({group, blocks: byGroup.get(group.id) ?? []})),
|
|
68
|
+
ungrouped,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {defineField, defineType} from 'sanity'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Métadonnées d'organisation des assets, propres au kit : dossiers et
|
|
5
|
+
* affectation d'un asset à un dossier. Document unique, écrit par l'outil
|
|
6
|
+
* Assets : jamais édité à la main (absent de « Créer »), comme le board.
|
|
7
|
+
*
|
|
8
|
+
* Les assets sont désignés par leur `_id` (chaîne), SANS référence Sanity :
|
|
9
|
+
* supprimer un asset ou vider son dossier ne doit jamais se bloquer l'un
|
|
10
|
+
* l'autre. Zéro schéma à déclarer côté projet : ces types arrivent par le
|
|
11
|
+
* plugin (kitSchemaTypes).
|
|
12
|
+
*/
|
|
13
|
+
export const ASSET_META_TYPE = 'ncfAssetMeta'
|
|
14
|
+
export const ASSET_META_ID = 'ncfAssetMeta'
|
|
15
|
+
export const ASSET_FOLDER_TYPE = 'ncfAssetFolder'
|
|
16
|
+
export const ASSET_ASSIGNMENT_TYPE = 'ncfAssetAssignment'
|
|
17
|
+
|
|
18
|
+
const assetFolderType = defineType({
|
|
19
|
+
name: ASSET_FOLDER_TYPE,
|
|
20
|
+
title: 'Asset folder',
|
|
21
|
+
type: 'object',
|
|
22
|
+
fields: [
|
|
23
|
+
defineField({name: 'id', title: 'Id', type: 'string'}),
|
|
24
|
+
defineField({name: 'name', title: 'Name', type: 'string'}),
|
|
25
|
+
// Dossier parent (id) : réservé à une future arborescence ; vide = racine.
|
|
26
|
+
defineField({name: 'parent', title: 'Parent', type: 'string'}),
|
|
27
|
+
],
|
|
28
|
+
preview: {select: {title: 'name', subtitle: 'id'}},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const assetAssignmentType = defineType({
|
|
32
|
+
name: ASSET_ASSIGNMENT_TYPE,
|
|
33
|
+
title: 'Asset folder assignment',
|
|
34
|
+
type: 'object',
|
|
35
|
+
fields: [
|
|
36
|
+
// `_key` de l'entrée = `_id` de l'asset (un seul dossier par asset).
|
|
37
|
+
defineField({name: 'folder', title: 'Folder', type: 'string'}),
|
|
38
|
+
],
|
|
39
|
+
preview: {select: {title: 'folder'}},
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const assetMetaType = defineType({
|
|
43
|
+
name: ASSET_META_TYPE,
|
|
44
|
+
title: 'Asset organization (NCF)',
|
|
45
|
+
type: 'document',
|
|
46
|
+
fields: [
|
|
47
|
+
defineField({
|
|
48
|
+
name: 'folders',
|
|
49
|
+
title: 'Folders',
|
|
50
|
+
type: 'array',
|
|
51
|
+
of: [{type: ASSET_FOLDER_TYPE}],
|
|
52
|
+
}),
|
|
53
|
+
defineField({
|
|
54
|
+
name: 'assignments',
|
|
55
|
+
title: 'Folder assignments',
|
|
56
|
+
type: 'array',
|
|
57
|
+
of: [{type: ASSET_ASSIGNMENT_TYPE}],
|
|
58
|
+
}),
|
|
59
|
+
defineField({name: 'updatedBy', title: 'Modified by', type: 'string', readOnly: true}),
|
|
60
|
+
],
|
|
61
|
+
preview: {prepare: () => ({title: 'Asset organization (NCF)'})},
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
/** Types du singleton d'assets, à concaténer dans kitSchemaTypes. */
|
|
65
|
+
export const assetMetaSchemaTypes = [assetMetaType, assetFolderType, assetAssignmentType]
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {defineField, defineType} from 'sanity'
|
|
2
2
|
import {TRANSLATION_TODO_TYPE, translationTodoType} from './translationTodo'
|
|
3
|
+
import {ASSET_META_TYPE, assetMetaSchemaTypes} from './assetMeta'
|
|
4
|
+
import {COMPONENT_META_TYPE, componentMetaSchemaTypes} from './componentMeta'
|
|
3
5
|
|
|
4
6
|
/** Type et identifiant du singleton portant la disposition du board. */
|
|
5
7
|
export const BOARD_LAYOUT_TYPE = 'ncfBoardLayout'
|
|
@@ -12,7 +14,7 @@ export const COLUMN_OPTION_TYPE = 'ncfColumnOption'
|
|
|
12
14
|
export const ANNOTATION_TYPE = 'ncfAnnotation'
|
|
13
15
|
|
|
14
16
|
/** Types déclarés par le kit : à masquer de la structure du Studio hôte. */
|
|
15
|
-
export const NCF_HIDDEN_TYPES = [BOARD_LAYOUT_TYPE, TRANSLATION_TODO_TYPE] as const
|
|
17
|
+
export const NCF_HIDDEN_TYPES = [BOARD_LAYOUT_TYPE, TRANSLATION_TODO_TYPE, ASSET_META_TYPE, COMPONENT_META_TYPE] as const
|
|
16
18
|
|
|
17
19
|
const boardNodeType = defineType({
|
|
18
20
|
name: BOARD_NODE_TYPE,
|
|
@@ -185,6 +187,8 @@ export const kitSchemaTypes = [
|
|
|
185
187
|
columnType,
|
|
186
188
|
columnOptionType,
|
|
187
189
|
annotationType,
|
|
190
|
+
...assetMetaSchemaTypes,
|
|
191
|
+
...componentMetaSchemaTypes,
|
|
188
192
|
]
|
|
189
193
|
|
|
190
194
|
/** Vrai pour les types techniques du kit. */
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {defineField, defineType} from 'sanity'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Organisation des composants (types de sections/blocs), propre au kit :
|
|
5
|
+
* nom marketing personnalisé et groupe de chaque composant, et liste des
|
|
6
|
+
* groupes. Document unique, écrit par l'onglet Composants ; jamais édité à la
|
|
7
|
+
* main (absent de « Créer »), comme le board et l'organisation des assets.
|
|
8
|
+
*
|
|
9
|
+
* Les composants sont désignés par leur TYPE (chaîne, ex. `section.hero`),
|
|
10
|
+
* SANS référence Sanity : le nom et le groupe sont de l'affichage, ils ne
|
|
11
|
+
* doivent jamais bloquer quoi que ce soit. Zéro schéma à déclarer côté projet.
|
|
12
|
+
*/
|
|
13
|
+
export const COMPONENT_META_TYPE = 'ncfComponentMeta'
|
|
14
|
+
export const COMPONENT_META_ID = 'ncfComponentMeta'
|
|
15
|
+
export const COMPONENT_GROUP_TYPE = 'ncfComponentGroup'
|
|
16
|
+
export const COMPONENT_ENTRY_TYPE = 'ncfComponentEntry'
|
|
17
|
+
|
|
18
|
+
const componentGroupType = defineType({
|
|
19
|
+
name: COMPONENT_GROUP_TYPE,
|
|
20
|
+
title: 'Component group',
|
|
21
|
+
type: 'object',
|
|
22
|
+
fields: [
|
|
23
|
+
defineField({name: 'id', title: 'Id', type: 'string'}),
|
|
24
|
+
defineField({name: 'name', title: 'Name', type: 'string'}),
|
|
25
|
+
],
|
|
26
|
+
preview: {select: {title: 'name', subtitle: 'id'}},
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const componentEntryType = defineType({
|
|
30
|
+
name: COMPONENT_ENTRY_TYPE,
|
|
31
|
+
title: 'Component organization',
|
|
32
|
+
type: 'object',
|
|
33
|
+
fields: [
|
|
34
|
+
// `_key` de l'entrée = TYPE du composant (ex. `section.hero`).
|
|
35
|
+
defineField({name: 'name', title: 'Custom name', type: 'string'}),
|
|
36
|
+
defineField({name: 'group', title: 'Group', type: 'string'}),
|
|
37
|
+
],
|
|
38
|
+
preview: {select: {title: 'name', subtitle: 'group'}},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const componentMetaType = defineType({
|
|
42
|
+
name: COMPONENT_META_TYPE,
|
|
43
|
+
title: 'Component organization (NCF)',
|
|
44
|
+
type: 'document',
|
|
45
|
+
fields: [
|
|
46
|
+
defineField({name: 'groups', title: 'Groups', type: 'array', of: [{type: COMPONENT_GROUP_TYPE}]}),
|
|
47
|
+
defineField({name: 'components', title: 'Components', type: 'array', of: [{type: COMPONENT_ENTRY_TYPE}]}),
|
|
48
|
+
defineField({name: 'updatedBy', title: 'Modified by', type: 'string', readOnly: true}),
|
|
49
|
+
],
|
|
50
|
+
preview: {prepare: () => ({title: 'Component organization (NCF)'})},
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
/** Types du singleton des composants, à concaténer dans kitSchemaTypes. */
|
|
54
|
+
export const componentMetaSchemaTypes = [componentMetaType, componentGroupType, componentEntryType]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {useState} from 'react'
|
|
2
|
+
import {Badge, Box, Card, Checkbox, Flex, Stack, Text} from '@sanity/ui'
|
|
3
|
+
import {DocumentIcon} from '@sanity/icons/Document'
|
|
4
|
+
import {assetName, formatBytes, isImageAsset, thumbnailUrl, type AssetDoc} from '../../lib/assets'
|
|
5
|
+
import {MONO} from '../../ui/tokens'
|
|
6
|
+
|
|
7
|
+
export interface AssetCardProps {
|
|
8
|
+
asset: AssetDoc
|
|
9
|
+
selected: boolean
|
|
10
|
+
onToggleSelect: () => void
|
|
11
|
+
onOpen: () => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Tuile d'un asset dans la grille : aperçu, nom, taille, type, usage. */
|
|
15
|
+
export function AssetCard(props: AssetCardProps) {
|
|
16
|
+
const {asset, selected, onToggleSelect, onOpen} = props
|
|
17
|
+
const [failed, setFailed] = useState(false)
|
|
18
|
+
const thumb = thumbnailUrl(asset, {w: 320, h: 220})
|
|
19
|
+
const unused = asset.uses === 0
|
|
20
|
+
const meta = [formatBytes(asset.size), asset.dimensions?.width ? `${asset.dimensions.width}×${asset.dimensions.height}` : null, asset.extension?.toUpperCase()]
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.join(' · ')
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Card
|
|
26
|
+
radius={3}
|
|
27
|
+
shadow={1}
|
|
28
|
+
padding={0}
|
|
29
|
+
tone={selected ? 'primary' : 'default'}
|
|
30
|
+
style={{height: '100%', overflow: 'hidden', position: 'relative'}}
|
|
31
|
+
>
|
|
32
|
+
{/* Sélection : coin haut-gauche, n'ouvre pas le détail. */}
|
|
33
|
+
<Box style={{position: 'absolute', top: 8, left: 8, zIndex: 1}} onClick={(e) => e.stopPropagation()}>
|
|
34
|
+
<Card radius={2} padding={1} tone="default" style={{opacity: selected ? 1 : 0.85}}>
|
|
35
|
+
<Checkbox checked={selected} onChange={onToggleSelect} aria-label="Sélectionner" />
|
|
36
|
+
</Card>
|
|
37
|
+
</Box>
|
|
38
|
+
|
|
39
|
+
<Stack
|
|
40
|
+
gap={0}
|
|
41
|
+
as="button"
|
|
42
|
+
onClick={onOpen}
|
|
43
|
+
style={{height: '100%', width: '100%', textAlign: 'left', cursor: 'pointer', background: 'transparent', border: 0, padding: 0}}
|
|
44
|
+
>
|
|
45
|
+
<Box style={{aspectRatio: '16 / 11', overflow: 'hidden', background: 'var(--card-muted-bg-color, rgba(127,127,127,0.08))'}}>
|
|
46
|
+
{thumb && !failed ? (
|
|
47
|
+
<img
|
|
48
|
+
src={thumb}
|
|
49
|
+
alt=""
|
|
50
|
+
loading="lazy"
|
|
51
|
+
onError={() => setFailed(true)}
|
|
52
|
+
style={{width: '100%', height: '100%', objectFit: 'cover', display: 'block'}}
|
|
53
|
+
/>
|
|
54
|
+
) : (
|
|
55
|
+
<Flex align="center" justify="center" direction="column" gap={2} style={{height: '100%'}} padding={3}>
|
|
56
|
+
<Text size={3} muted>
|
|
57
|
+
<DocumentIcon />
|
|
58
|
+
</Text>
|
|
59
|
+
<Text size={0} muted>
|
|
60
|
+
{asset.extension?.toUpperCase() || (isImageAsset(asset) ? 'IMAGE' : 'FICHIER')}
|
|
61
|
+
</Text>
|
|
62
|
+
</Flex>
|
|
63
|
+
)}
|
|
64
|
+
</Box>
|
|
65
|
+
|
|
66
|
+
<Box padding={3}>
|
|
67
|
+
<Stack gap={2}>
|
|
68
|
+
<Flex align="center" gap={2} justify="space-between">
|
|
69
|
+
<Text size={1} weight="medium" textOverflow="ellipsis" style={{minWidth: 0}}>
|
|
70
|
+
{assetName(asset)}
|
|
71
|
+
</Text>
|
|
72
|
+
{unused ? (
|
|
73
|
+
<Badge tone="caution" fontSize={0} style={{flex: 'none'}} title="Aucun document ne l’utilise">
|
|
74
|
+
inutilisé
|
|
75
|
+
</Badge>
|
|
76
|
+
) : null}
|
|
77
|
+
</Flex>
|
|
78
|
+
<Text size={0} muted textOverflow="ellipsis" style={MONO}>
|
|
79
|
+
{meta}
|
|
80
|
+
</Text>
|
|
81
|
+
</Stack>
|
|
82
|
+
</Box>
|
|
83
|
+
</Stack>
|
|
84
|
+
</Card>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
@@ -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
|
+
}
|