@nocode-factory/sanity-kit 2.9.0 → 2.10.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/dist/schema.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as requiredUnlessDefault, i as defineComponentDefaults, n as componentDefaultsMainDocument, o as requiredUnlessDefaultFor, r as defaultsFieldName, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-CbOXLaYE.js";
2
- export { DEFAULT_COMPONENT_DEFAULTS_TYPE, componentDefaultsMainDocument, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
1
+ import { a as defineComponentDefaults, i as defaultsFieldName, n as componentDefaultsMainDocument, o as requiredUnlessDefault, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-CNiuukLt.js";
2
+ export { DEFAULT_COMPONENT_DEFAULTS_TYPE, componentDefaultsMainDocument, componentDefaultsMainDocuments, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
package/dist/schema.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as requiredUnlessDefault, i as defineComponentDefaults, n as componentDefaultsMainDocument, o as requiredUnlessDefaultFor, r as defaultsFieldName, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-YFpAqFb4.js";
2
- export { DEFAULT_COMPONENT_DEFAULTS_TYPE, componentDefaultsMainDocument, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
1
+ import { a as defineComponentDefaults, i as defaultsFieldName, n as componentDefaultsMainDocument, o as requiredUnlessDefault, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-BY3hQ6aD.js";
2
+ export { DEFAULT_COMPONENT_DEFAULTS_TYPE, componentDefaultsMainDocument, componentDefaultsMainDocuments, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocode-factory/sanity-kit",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "Outils Studio de NoCode Factory : Pages (liste + board), Composants, Historique",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -41,8 +41,16 @@ export const DEFAULT_TOOLS: Required<NcfToolsConfig> = {
41
41
  pages: true,
42
42
  components: true,
43
43
  history: true,
44
+ designSystem: true,
44
45
  }
45
46
 
47
+ /**
48
+ * Outils rangés dans « Plus » : Vision (console GROQ) et la planification
49
+ * (« Scheduled drafts » quand les Releases sont désactivées, « Releases » sinon :
50
+ * le même outil, nommé `releases` ; `schedules` couvre les anciennes versions).
51
+ */
52
+ export const DEFAULT_TOOLBAR_MORE = ['vision', 'releases', 'schedules']
53
+
46
54
  /**
47
55
  * Étiquettes de suivi par défaut : l'avancement d'une refonte, pas un statut
48
56
  * de publication. Elles vivent dans le document de disposition du kit, donc
@@ -9,7 +9,7 @@ import {
9
9
  DEFAULT_PAGE_BUILDER_FIELD,
10
10
  DEFAULT_SLUG_FIELD,
11
11
  DEFAULT_TITLE_FIELD,
12
- DEFAULT_TOOLS,
12
+ DEFAULT_TOOLBAR_MORE, DEFAULT_TOOLS,
13
13
  } from './defaults'
14
14
  import type {
15
15
  NcfEnvironment,
@@ -114,6 +114,7 @@ export function resolveConfig(input: NcfKitConfig): ResolvedKitConfig {
114
114
  }
115
115
  : null,
116
116
  tools: {...DEFAULT_TOOLS, ...input.tools},
117
+ moreTools: input.moreTools === false ? [] : (input.moreTools ?? DEFAULT_TOOLBAR_MORE),
117
118
  boardTags: input.boardTags?.length ? input.boardTags : DEFAULT_BOARD_TAGS,
118
119
  internalFields: input.internalFields?.length
119
120
  ? input.internalFields
@@ -143,6 +143,8 @@ export interface NcfToolsConfig {
143
143
  pages?: boolean
144
144
  components?: boolean
145
145
  history?: boolean
146
+ /** Bouton « Design system » : ouvre la page /design-system dans Presentation. */
147
+ designSystem?: boolean
146
148
  }
147
149
 
148
150
  export interface NcfKitConfig {
@@ -200,6 +202,12 @@ export interface NcfKitConfig {
200
202
  serviceEndpoint?: string | false
201
203
  /** Permet de n'activer qu'une partie des outils. */
202
204
  tools?: NcfToolsConfig
205
+ /**
206
+ * Outils techniques rangés dans le menu « Plus » de la barre du Studio, pour ne
207
+ * pas encombrer le marketing. Par défaut : Vision et la planification
208
+ * (« Scheduled drafts » / Releases, nom d'outil `releases`). `false` : aucun.
209
+ */
210
+ moreTools?: string[] | false
203
211
  /**
204
212
  * Étiquettes de suivi du board. Remplacent entièrement les valeurs par
205
213
  * défaut quand elles sont fournies.
@@ -259,6 +267,8 @@ export interface ResolvedKitConfig {
259
267
  /** `null` quand on a explicitement coupé les appels sortants. */
260
268
  serviceEndpoint: string | null
261
269
  tools: Required<NcfToolsConfig>
270
+ /** Outils rangés dans le menu « Plus » de la barre (noms d'outils). */
271
+ moreTools: string[]
262
272
  boardTags: NcfBoardTag[]
263
273
  internalFields: NcfInternalField[]
264
274
  documentColumns: ResolvedDocumentColumn[]
@@ -297,7 +307,7 @@ export interface ConfigIssue {
297
307
  tools?: NcfToolName[]
298
308
  }
299
309
 
300
- export type NcfToolName = 'pages' | 'components' | 'history'
310
+ export type NcfToolName = 'pages' | 'components' | 'history' | 'designSystem'
301
311
 
302
312
  export interface KitContextValue {
303
313
  config: ResolvedKitConfig
@@ -1,11 +1,12 @@
1
1
  import {useState, type ComponentType} from 'react'
2
2
  import {set, unset, useFormValue, useSchema, type InputProps} from 'sanity'
3
3
  import {useRouter} from 'sanity/router'
4
- import {Box, Flex, Stack, Text} from '@sanity/ui'
4
+ import {Box, Button, Flex, Stack, Text} from '@sanity/ui'
5
5
  import {Tooltip} from '@sanity/ui/tooltip'
6
6
  import type {ResolvedKitConfig} from '../config/types'
7
7
  import {blockName, componentIntentParams} from '../lib/blocks'
8
8
  import {useKitClient} from '../hooks/useKitClient'
9
+ import {openComponentDefaults} from '../lib/openComponent'
9
10
  import {useComponentDefaults} from '../hooks/useComponentDefaults'
10
11
  import {
11
12
  defaultValueAt,
@@ -46,6 +47,17 @@ export function createOverrideInput(config: ResolvedKitConfig): ComponentType<In
46
47
  const parent = useFormValue((path.length > 1 ? path.slice(0, -1) : path) as never)
47
48
  const resolved = resolveFieldPath(path, anchor, instance, namespace)
48
49
 
50
+ // L'instance elle-même (l'objet section) : bouton « Modifier l'instance principale ».
51
+ const own = props.value as {_type?: unknown} | undefined
52
+ if (
53
+ props.schemaType.jsonType === 'object' &&
54
+ typeof own?._type === 'string' &&
55
+ own._type.startsWith(namespace) &&
56
+ props.path.length > 0 &&
57
+ schema.get(defaultsType)
58
+ )
59
+ return <WithMainInstance {...props} type={own._type} />
60
+
49
61
  if (!resolved || !schema.get(defaultsType) || !carriesDot(props.schemaType)) return props.renderDefault(props)
50
62
  const shortName = blockName((instance as {_type: string})._type, namespace)
51
63
  return <WithDot {...props} rel={resolved.path} inList={resolved.inList} shortName={shortName} parent={parent} />
@@ -113,6 +125,33 @@ export function createOverrideInput(config: ResolvedKitConfig): ComponentType<In
113
125
  )
114
126
  }
115
127
 
128
+ // En tête du formulaire d'une instance de composant : mène aux valeurs par
129
+ // défaut du composant (son « instance principale »), qui s'appliquent à toutes
130
+ // les instances dont le champ est vide.
131
+ function WithMainInstance(props: InputProps & {type: string}) {
132
+ const {type, ...inputProps} = props
133
+ const client = useKitClient()
134
+ const router = useRouter()
135
+ const open = () =>
136
+ void openComponentDefaults({type, config, hasDefaults: true, client, navigateIntent: (i, p) => router.navigateIntent(i, p)})
137
+ return (
138
+ <Stack gap={3}>
139
+ <Flex justify="flex-end">
140
+ <Button
141
+ mode="ghost"
142
+ tone="primary"
143
+ fontSize={1}
144
+ padding={2}
145
+ text="Modifier l'instance principale"
146
+ title="Valeurs par défaut du composant : elles s'appliquent à toutes ses instances dont le champ est vide"
147
+ onClick={open}
148
+ />
149
+ </Flex>
150
+ {inputProps.renderDefault(inputProps)}
151
+ </Stack>
152
+ )
153
+ }
154
+
116
155
  return OverrideInput
117
156
  }
118
157
 
@@ -2,15 +2,10 @@ import {useCallback} from 'react'
2
2
  import {useSchema} from 'sanity'
3
3
  import {useRouter} from 'sanity/router'
4
4
  import {useKitConfig} from '../context/KitContext'
5
- import {componentIntentParams, fillTemplate} from '../lib/blocks'
5
+ import {openComponentDefaults} from '../lib/openComponent'
6
6
  import {useKitClient} from './useKitClient'
7
7
 
8
- /**
9
- * Ouvre un composant : Presentation avec son rendu réel et ses valeurs par
10
- * défaut côte à côte. Sans document de valeurs par défaut dans le schéma : la
11
- * démo du design system dans un nouvel onglet. `null` : rien à ouvrir.
12
- * Partagé par la grille et la vue Map de l'onglet Composants.
13
- */
8
+ /** Ouvre un composant (voir openComponentDefaults). `null` : rien à ouvrir. */
14
9
  export function useOpenComponent(): ((type: string) => void) | null {
15
10
  const config = useKitConfig()
16
11
  const schema = useSchema()
@@ -20,22 +15,8 @@ export function useOpenComponent(): ((type: string) => void) | null {
20
15
  const hasDefaults = Boolean(schema.get(preview.defaultsType))
21
16
 
22
17
  const open = useCallback(
23
- async (type: string) => {
24
- if (!hasDefaults) {
25
- if (config.previewUrl)
26
- window.open(`${config.previewUrl}${preview.path}#${fillTemplate(preview.anchor, type, config.blockNamespace)}`, '_blank', 'noopener')
27
- return
28
- }
29
- const lang = config.i18n?.defaultLocale ?? null
30
- const id = await client
31
- .fetch<string | null>(
32
- `*[_type == $type] | order(select($lang != null && ${config.i18n?.field ?? 'language'} == $lang => 0, 1))[0]._id`,
33
- {type: preview.defaultsType, lang},
34
- )
35
- .catch(() => null)
36
- router.navigateIntent('edit', componentIntentParams(type, config.blockNamespace, preview, id ?? preview.defaultsType))
37
- },
38
- [hasDefaults, config, preview, client, router],
18
+ (type: string) => openComponentDefaults({type, config, hasDefaults, client, navigateIntent: (i, p) => router.navigateIntent(i, p)}),
19
+ [hasDefaults, config, client, router],
39
20
  )
40
21
 
41
22
  if (!hasDefaults && !config.previewUrl) return null
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import {definePlugin, type Tool} from 'sanity'
2
2
  import {ClockIcon} from '@sanity/icons/Clock'
3
3
  import {ComponentIcon} from '@sanity/icons/Component'
4
4
  import {DocumentsIcon} from '@sanity/icons/Documents'
5
+ import {ColorWheelIcon} from '@sanity/icons/ColorWheel'
5
6
 
6
7
  import {resolveConfig} from './config/resolve'
7
8
  import {validateConfig} from './config/validate'
@@ -10,6 +11,7 @@ import {createPreviewLauncher} from './tools/navbar/PreviewLauncher'
10
11
  import {PagesTool} from './tools/pages/PagesTool'
11
12
  import {ComponentsTool} from './tools/components/ComponentsTool'
12
13
  import {HistoryTool} from './tools/history/HistoryTool'
14
+ import {DesignSystemTool} from './tools/designSystem/DesignSystemTool'
13
15
  import {BOARD_LAYOUT_TYPE, isKitType, kitSchemaTypes} from './schema/boardLayout'
14
16
  import type {NcfKitConfig, NcfToolName} from './config/types'
15
17
 
@@ -17,11 +19,13 @@ import type {NcfKitConfig, NcfToolName} from './config/types'
17
19
  export const NCF_PAGES_TOOL = 'ncf-pages'
18
20
  export const NCF_COMPONENTS_TOOL = 'ncf-components'
19
21
  export const NCF_HISTORY_TOOL = 'ncf-history'
22
+ export const NCF_DESIGN_SYSTEM_TOOL = 'ncf-design-system'
20
23
 
21
24
  export const NCF_TOOL_NAMES = [
22
25
  NCF_PAGES_TOOL,
23
26
  NCF_COMPONENTS_TOOL,
24
27
  NCF_HISTORY_TOOL,
28
+ NCF_DESIGN_SYSTEM_TOOL,
25
29
  ] as const
26
30
 
27
31
  /**
@@ -86,6 +90,22 @@ export const ncfKit = definePlugin<NcfKitConfig>((options) => {
86
90
  }),
87
91
  },
88
92
  },
93
+ {
94
+ // Raccourci vers la page /design-system (Presentation + valeurs par défaut).
95
+ name: 'designSystem',
96
+ tool: {
97
+ name: NCF_DESIGN_SYSTEM_TOOL,
98
+ title: 'Design system',
99
+ icon: ColorWheelIcon,
100
+ component: createToolComponent({
101
+ name: 'designSystem',
102
+ title: 'Design system',
103
+ config,
104
+ issues,
105
+ Component: DesignSystemTool,
106
+ }),
107
+ },
108
+ },
89
109
  ]
90
110
 
91
111
  return {
@@ -108,8 +128,9 @@ export const ncfKit = definePlugin<NcfKitConfig>((options) => {
108
128
  // comme dans le volet latéral. Posé par le plugin : il n'y a rien à
109
129
  // brancher dans la configuration d'un projet.
110
130
  //
111
- // Le menu des outils est rendu tel quel — un plugin qui le remplacerait
112
- // ferait disparaître « Plus » et tout ce qu'un autre y aurait mis.
131
+ // Le kit rend aussi les boutons d'outils : outils du quotidien en boutons,
132
+ // outils techniques (Vision, planification) dans « Plus » (option moreTools).
133
+ // Un projet n'a donc plus de menu d'outils à écrire.
113
134
  studio: {
114
135
  components: {toolMenu: createPreviewLauncher(config, issues)},
115
136
  },
@@ -131,6 +152,7 @@ export {
131
152
  requiredUnlessDefaultFor,
132
153
  defaultsFieldName,
133
154
  componentDefaultsMainDocument,
155
+ componentDefaultsMainDocuments,
134
156
  DEFAULT_COMPONENT_DEFAULTS_TYPE,
135
157
  } from './schema/componentDefaults'
136
158
 
@@ -0,0 +1,76 @@
1
+ import type {SanityClient} from 'sanity'
2
+ import type {ResolvedKitConfig} from '../config/types'
3
+ import {componentIntentParams, fillTemplate} from './blocks'
4
+ import {presentationPath} from './studioLinks'
5
+
6
+ /**
7
+ * Ouvre un composant : Presentation avec son rendu réel et ses valeurs par
8
+ * défaut côte à côte (le document des valeurs par défaut, champ du composant).
9
+ * Sans document de valeurs par défaut dans le schéma : la démo du design system
10
+ * dans un nouvel onglet. Partagé par l'onglet Composants (grille, Map) et le
11
+ * bouton « Modifier l'instance principale » des formulaires.
12
+ */
13
+ export async function openComponentDefaults(options: {
14
+ type: string
15
+ config: ResolvedKitConfig
16
+ hasDefaults: boolean
17
+ client: SanityClient
18
+ navigateIntent: (intent: string, params: Record<string, string>) => void
19
+ }): Promise<void> {
20
+ const {type, config, hasDefaults, client, navigateIntent} = options
21
+ const preview = config.componentPreview
22
+ if (!hasDefaults) {
23
+ if (config.previewUrl)
24
+ window.open(`${config.previewUrl}${preview.path}#${fillTemplate(preview.anchor, type, config.blockNamespace)}`, '_blank', 'noopener')
25
+ return
26
+ }
27
+ const id = await defaultsDocumentId(config, client)
28
+ navigateIntent('edit', componentIntentParams(type, config.blockNamespace, preview, id ?? preview.defaultsType))
29
+ }
30
+
31
+ /** Document des valeurs par défaut (langue par défaut en priorité), ou null. */
32
+ async function defaultsDocumentId(config: ResolvedKitConfig, client: SanityClient): Promise<string | null> {
33
+ const lang = config.i18n?.defaultLocale ?? null
34
+ return client
35
+ .fetch<string | null>(
36
+ `*[_type == $type] | order(select($lang != null && ${config.i18n?.field ?? 'language'} == $lang => 0, 1))[0]._id`,
37
+ {type: config.componentPreview.defaultsType, lang},
38
+ )
39
+ .catch(() => null)
40
+ }
41
+
42
+ /**
43
+ * Paramètres de l'intention qui ouvre la page du design system dans Presentation,
44
+ * avec le document des valeurs par défaut des composants à côté : un style changé
45
+ * sur cette page change le composant partout où il n'est pas surchargé.
46
+ */
47
+ export function designSystemIntentParams(config: ResolvedKitConfig, documentId: string): Record<string, string> {
48
+ return {
49
+ id: documentId.replace(/^drafts\./, ''),
50
+ type: config.componentPreview.defaultsType,
51
+ mode: 'presentation',
52
+ preview: config.componentPreview.path,
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Ouvre le design system : Presentation sur la page `/design-system`, document des
58
+ * valeurs par défaut à côté. Sans valeurs par défaut dans le schéma : la page seule
59
+ * dans Presentation.
60
+ */
61
+ export async function openDesignSystem(options: {
62
+ config: ResolvedKitConfig
63
+ hasDefaults: boolean
64
+ client: SanityClient
65
+ navigateIntent: (intent: string, params: Record<string, string>) => void
66
+ navigateUrl: (path: string) => void
67
+ }): Promise<void> {
68
+ const {config, hasDefaults, client, navigateIntent, navigateUrl} = options
69
+ if (hasDefaults) {
70
+ const id = await defaultsDocumentId(config, client)
71
+ navigateIntent('edit', designSystemIntentParams(config, id ?? config.componentPreview.defaultsType))
72
+ return
73
+ }
74
+ const path = presentationPath(config.previewUrl ? `${config.previewUrl}${config.componentPreview.path}` : null)
75
+ if (path) navigateUrl(path)
76
+ }
@@ -104,3 +104,18 @@ export function componentDefaultsMainDocument(options: {language?: string; route
104
104
  const safeLang = language && /^[a-z]{2}(-[A-Za-z]{2})?$/.test(language) ? language : null
105
105
  return {route, filter: `_type == "${type}"${safeLang ? ` && language == "${safeLang}"` : ''}`}
106
106
  }
107
+
108
+ /**
109
+ * Presentation : les pages du design system ont pour document principal les valeurs
110
+ * par défaut des composants. `/design-system` (toute la bibliothèque) et
111
+ * `/design-system/composant` (un composant seul) : cliquer un composant ouvre ses
112
+ * réglages globaux, et un style changé change le composant partout où il n'est
113
+ * pas surchargé.
114
+ * `presentationTool({resolve: {mainDocuments: defineDocuments(componentDefaultsMainDocuments({language: 'fr'}))}})`
115
+ */
116
+ export function componentDefaultsMainDocuments(
117
+ options: {language?: string; type?: string; routes?: string[]} = {},
118
+ ): {route: string; filter: string}[] {
119
+ const {routes = ['/design-system/composant', '/design-system'], ...rest} = options
120
+ return routes.map((route) => componentDefaultsMainDocument({...rest, route}))
121
+ }
@@ -13,5 +13,6 @@ export {
13
13
  requiredUnlessDefaultFor,
14
14
  defaultsFieldName,
15
15
  componentDefaultsMainDocument,
16
+ componentDefaultsMainDocuments,
16
17
  DEFAULT_COMPONENT_DEFAULTS_TYPE,
17
18
  } from './componentDefaults'
@@ -0,0 +1,62 @@
1
+ import {useCallback, useEffect, useRef} from 'react'
2
+ import {Button, Card, Flex, Stack, Text} from '@sanity/ui'
3
+ import {useSchema} from 'sanity'
4
+ import {useRouter} from 'sanity/router'
5
+ import {useKitConfig} from '../../context/KitContext'
6
+ import {useKitClient} from '../../hooks/useKitClient'
7
+ import {openDesignSystem} from '../../lib/openComponent'
8
+
9
+ /**
10
+ * Onglet « Design system » : un raccourci, pas un écran. Il ouvre aussitôt la page
11
+ * `/design-system` du site dans Presentation, avec le document des valeurs par
12
+ * défaut des composants à côté. Cliquer un composant sur la page ouvre ses
13
+ * réglages globaux : un style changé ici change le composant partout où il n'est
14
+ * pas surchargé.
15
+ */
16
+ export function DesignSystemTool() {
17
+ const config = useKitConfig()
18
+ const schema = useSchema()
19
+ const router = useRouter()
20
+ const client = useKitClient()
21
+ const hasDefaults = Boolean(schema.get(config.componentPreview.defaultsType))
22
+ const opened = useRef(false)
23
+
24
+ const open = useCallback(
25
+ () =>
26
+ void openDesignSystem({
27
+ config,
28
+ hasDefaults,
29
+ client,
30
+ navigateIntent: (intent, params) => router.navigateIntent(intent, params),
31
+ navigateUrl: (path) => router.navigateUrl({path}),
32
+ }),
33
+ [config, hasDefaults, client, router],
34
+ )
35
+
36
+ useEffect(() => {
37
+ if (opened.current) return
38
+ opened.current = true
39
+ open()
40
+ }, [open])
41
+
42
+ const available = hasDefaults || Boolean(config.previewUrl)
43
+ return (
44
+ <Card padding={4} radius={2} tone={available ? 'default' : 'caution'} border>
45
+ <Stack gap={3}>
46
+ <Text size={1} weight="semibold">
47
+ Design system
48
+ </Text>
49
+ <Text size={1} muted>
50
+ {available
51
+ ? `Ouverture de la page ${config.componentPreview.path} dans Presentation, avec les valeurs par défaut des composants. Un style changé ici change le composant partout où il n’est pas surchargé.`
52
+ : 'Ni document de valeurs par défaut des composants, ni previewUrl : rien à ouvrir. Voir la checklist du kit (README).'}
53
+ </Text>
54
+ {available && (
55
+ <Flex>
56
+ <Button text="Ouvrir le design system" tone="primary" fontSize={1} onClick={open} />
57
+ </Flex>
58
+ )}
59
+ </Stack>
60
+ </Card>
61
+ )
62
+ }
@@ -10,6 +10,7 @@ import {EyeOpenIcon} from '@sanity/icons/EyeOpen'
10
10
  import {LaunchIcon} from '@sanity/icons/Launch'
11
11
  import {BORDER} from '../../ui/tokens'
12
12
  import {NcfKitUpdate} from './KitUpdate'
13
+ import {NcfToolButtons} from './ToolButtons'
13
14
 
14
15
  /**
15
16
  * Lanceur d'aperçu, posé dans la barre du haut à droite des outils.
@@ -31,7 +32,7 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
31
32
  if (environments.length === 0) {
32
33
  return (
33
34
  <Flex align="center" gap={2}>
34
- {props.renderDefault(props)}
35
+ <NcfToolButtons {...props} more={config.moreTools} />
35
36
  <NcfKitUpdate inline={props.context === 'topbar'} />
36
37
  </Flex>
37
38
  )
@@ -61,7 +62,7 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
61
62
  direction={inline ? 'row' : 'column'}
62
63
  gap={inline ? 2 : 1}
63
64
  >
64
- {props.renderDefault(props)}
65
+ <NcfToolButtons {...props} more={config.moreTools} />
65
66
 
66
67
  <NcfKitUpdate inline={inline} />
67
68
 
@@ -0,0 +1,87 @@
1
+ import {forwardRef, useCallback, useMemo, type ComponentProps, type ReactNode} from 'react'
2
+ import {ToolLink, type Tool, type ToolMenuProps} from 'sanity'
3
+ import {Button, Flex, Stack} from '@sanity/ui'
4
+ import {Menu, MenuButton, MenuItem} from '@sanity/ui/menu'
5
+ import {EllipsisHorizontalIcon} from '@sanity/icons/EllipsisHorizontal'
6
+
7
+ /**
8
+ * Sépare les outils de la barre : ceux du quotidien restent en boutons, les outils
9
+ * techniques (`more`) passent dans le menu « Plus ». L'ordre d'origine est gardé.
10
+ */
11
+ export function splitTools<T extends {name: string}>(tools: T[], more: string[]): [T[], T[]] {
12
+ return [tools.filter((t) => !more.includes(t.name)), tools.filter((t) => more.includes(t.name))]
13
+ }
14
+
15
+ // ToolLink exige `children` dans ses types alors que Button / MenuItem (prop `as`)
16
+ // fournissent le contenu eux-mêmes : enveloppe au typage compatible.
17
+ const ToolAnchor = forwardRef<HTMLAnchorElement, Omit<ComponentProps<typeof ToolLink>, 'children'> & {children?: ReactNode}>(
18
+ function ToolAnchor({children, ...props}, ref) {
19
+ return (
20
+ <ToolLink {...props} ref={ref}>
21
+ {children}
22
+ </ToolLink>
23
+ )
24
+ },
25
+ )
26
+
27
+ /**
28
+ * Barre d'outils du Studio : les outils du quotidien en boutons (dont « Design
29
+ * system »), les outils techniques (Vision, planification) dans « Plus ». Dans le
30
+ * volet latéral (mobile), tout est listé.
31
+ */
32
+ export function NcfToolButtons(props: ToolMenuProps & {more: string[]}) {
33
+ const {activeToolName, context, tools, closeSidebar, isSidebarOpen, more: moreNames} = props
34
+ const [main, more] = useMemo(() => splitTools(tools, moreNames), [tools, moreNames])
35
+ const isSidebar = context === 'sidebar'
36
+ const onClick = useCallback(() => {
37
+ if (isSidebar && isSidebarOpen) closeSidebar()
38
+ }, [closeSidebar, isSidebar, isSidebarOpen])
39
+
40
+ const button = (tool: Tool) => (
41
+ <Button
42
+ key={tool.name}
43
+ as={ToolAnchor}
44
+ name={tool.name}
45
+ icon={tool.icon}
46
+ text={tool.title || tool.name}
47
+ mode="bleed"
48
+ selected={activeToolName === tool.name}
49
+ justify={isSidebar ? 'flex-start' : undefined}
50
+ onClick={onClick}
51
+ fontSize={1}
52
+ padding={3}
53
+ />
54
+ )
55
+
56
+ if (isSidebar) return <Stack gap={1}>{[...main, ...more].map(button)}</Stack>
57
+
58
+ return (
59
+ <Flex gap={1} align="center">
60
+ {main.map(button)}
61
+ {more.length > 0 && (
62
+ <MenuButton
63
+ id="ncf-tool-menu-more"
64
+ button={
65
+ <Button
66
+ icon={EllipsisHorizontalIcon}
67
+ text="Plus"
68
+ mode="bleed"
69
+ fontSize={1}
70
+ padding={3}
71
+ selected={more.some((t) => t.name === activeToolName)}
72
+ title={`Outils techniques (${more.map((t) => t.title || t.name).join(', ')})`}
73
+ />
74
+ }
75
+ menu={
76
+ <Menu>
77
+ {more.map((tool) => (
78
+ <MenuItem key={tool.name} as={ToolAnchor} name={tool.name} icon={tool.icon} text={tool.title || tool.name} pressed={activeToolName === tool.name} />
79
+ ))}
80
+ </Menu>
81
+ }
82
+ popover={{portal: true, placement: 'bottom-end'}}
83
+ />
84
+ )}
85
+ </Flex>
86
+ )
87
+ }
package/src/version.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * Version du kit, rapportée au service pour savoir quels projets tournent sur
3
3
  * quelle version. Tenue à jour avec `package.json`.
4
4
  */
5
- export const KIT_VERSION = '2.9.0'
5
+ export const KIT_VERSION = '2.10.0'