@nocode-factory/sanity-kit 2.9.1 → 2.10.1

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.1",
3
+ "version": "2.10.1",
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
@@ -107,16 +107,9 @@ export function validateConfig(config: ResolvedKitConfig): ConfigIssue[] {
107
107
  seenEnvironments.add(environment.id)
108
108
  }
109
109
 
110
- // Presentation refuse de dialoguer avec une origine non déclarée : l'aperçu
111
- // s'afficherait, mais muet, sans édition visuelle.
112
- if (config.environments.length > 1) {
113
- warn(
114
- 'environments',
115
- `${config.environments.length} environnements sont déclarés. Vérifie que leurs origines figurent dans ` +
116
- '`allowOrigins` de presentationTool — `ncfAllowedOrigins(config)` les produit.',
117
- ['pages'],
118
- )
119
- }
110
+ // allowOrigins de Presentation : vérifié pour de vrai dans l'onglet Pages
111
+ // (PreviewOriginsNotice, qui lit la configuration de l'outil) et par le doctor,
112
+ // plus de rappel systématique ici.
120
113
 
121
114
  /* --- historique --- */
122
115
  if (config.tools.history) {
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
 
@@ -1,6 +1,7 @@
1
1
  import type {SanityClient} from 'sanity'
2
2
  import type {ResolvedKitConfig} from '../config/types'
3
3
  import {componentIntentParams, fillTemplate} from './blocks'
4
+ import {presentationPath} from './studioLinks'
4
5
 
5
6
  /**
6
7
  * Ouvre un composant : Presentation avec son rendu réel et ses valeurs par
@@ -23,12 +24,53 @@ export async function openComponentDefaults(options: {
23
24
  window.open(`${config.previewUrl}${preview.path}#${fillTemplate(preview.anchor, type, config.blockNamespace)}`, '_blank', 'noopener')
24
25
  return
25
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> {
26
33
  const lang = config.i18n?.defaultLocale ?? null
27
- const id = await client
34
+ return client
28
35
  .fetch<string | null>(
29
36
  `*[_type == $type] | order(select($lang != null && ${config.i18n?.field ?? 'language'} == $lang => 0, 1))[0]._id`,
30
- {type: preview.defaultsType, lang},
37
+ {type: config.componentPreview.defaultsType, lang},
31
38
  )
32
39
  .catch(() => null)
33
- navigateIntent('edit', componentIntentParams(type, config.blockNamespace, preview, id ?? preview.defaultsType))
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)
34
76
  }
@@ -169,6 +169,34 @@ export function ncfAllowedOrigins(config: {
169
169
  }
170
170
 
171
171
 
172
+ /**
173
+ * Origines d'aperçu que Presentation refuserait : celles des environnements du kit
174
+ * qui ne correspondent à aucune entrée de `allowOrigins` (motifs avec `*` acceptés)
175
+ * ni à l'origine de son `previewUrl` (toujours autorisée). Sans liste lisible
176
+ * (fonction, absente) : rien n'est signalé, faute de pouvoir vérifier.
177
+ */
178
+ export function missingPreviewOrigins(
179
+ required: string[],
180
+ presentationOptions: {allowOrigins?: unknown; previewUrl?: unknown} | null | undefined,
181
+ ): string[] {
182
+ const allow = presentationOptions?.allowOrigins
183
+ if (!Array.isArray(allow)) return []
184
+ const patterns = allow.filter((p): p is string => typeof p === 'string')
185
+ const preview = presentationOptions?.previewUrl
186
+ const previewOrigin = (() => {
187
+ const raw = typeof preview === 'string' ? preview : (preview as {origin?: unknown} | undefined)?.origin
188
+ if (typeof raw !== 'string') return null
189
+ try {
190
+ return new URL(raw).origin
191
+ } catch {
192
+ return null
193
+ }
194
+ })()
195
+ const matches = (origin: string, pattern: string) =>
196
+ new RegExp(`^${pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*')}$`).test(origin)
197
+ return required.filter((origin) => origin !== previewOrigin && !patterns.some((p) => matches(origin, p)))
198
+ }
199
+
172
200
  /** Identifiant de l'environnement libre, saisi à la volée. */
173
201
  export const CUSTOM_ENVIRONMENT_ID = 'ncf-custom'
174
202
 
@@ -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'
@@ -7,6 +7,7 @@ import {PreviewTargetProvider} from '../context/PreviewTargetContext'
7
7
  import {ConfigIssues} from '../ui/ConfigIssues'
8
8
  import {useRegistration} from '../hooks/useRegistration'
9
9
  import {ProjectStatusNotice} from '../ui/ProjectStatusNotice'
10
+ import {PreviewOriginsNotice} from '../ui/PreviewOriginsNotice'
10
11
  import {issuesForTool} from '../config/validate'
11
12
  import type {ConfigIssue, NcfToolName, ResolvedKitConfig} from '../config/types'
12
13
 
@@ -55,6 +56,7 @@ export function createToolComponent(
55
56
  <Box padding={4} height="fill" overflow="auto">
56
57
  <Stack gap={4}>
57
58
  <ConfigIssues issues={scoped} toolTitle={title} />
59
+ {name === 'pages' && <PreviewOriginsNotice />}
58
60
  <Registered />
59
61
  {blocking ? null : <Component />}
60
62
  </Stack>
@@ -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
+ }
@@ -0,0 +1,39 @@
1
+ import {Card, Container, Stack, Text} from '@sanity/ui'
2
+ import {useWorkspace} from 'sanity'
3
+ import {useKitConfig} from '../context/KitContext'
4
+ import {missingPreviewOrigins, ncfAllowedOrigins} from '../lib/studioLinks'
5
+ import {InlineCode} from './InlineCode'
6
+
7
+ /**
8
+ * Vérifie pour de vrai que Presentation accepte chaque environnement d'aperçu du kit
9
+ * (option `allowOrigins`). Ne s'affiche que s'il en manque : sans elle, l'aperçu de
10
+ * cet environnement s'affiche mais reste muet (ni édition visuelle, ni surlignage).
11
+ */
12
+ export function PreviewOriginsNotice() {
13
+ const config = useKitConfig()
14
+ const {tools} = useWorkspace()
15
+ const presentation = tools.find(
16
+ (tool) => (tool as {__internalApplicationType?: string}).__internalApplicationType === 'sanity/presentation' || tool.name === 'presentation',
17
+ )
18
+ if (!presentation) return null
19
+ const missing = missingPreviewOrigins(ncfAllowedOrigins(config), presentation.options as {allowOrigins?: unknown; previewUrl?: unknown})
20
+ if (missing.length === 0) return null
21
+ return (
22
+ <Container width={2}>
23
+ <Card padding={4} radius={3} shadow={1} tone="caution">
24
+ <Stack gap={3}>
25
+ <Text weight="semibold">Aperçu muet sur {missing.length > 1 ? 'ces environnements' : 'cet environnement'}</Text>
26
+ <Stack gap={2}>
27
+ {missing.map((origin) => (
28
+ <InlineCode key={origin}>{origin}</InlineCode>
29
+ ))}
30
+ </Stack>
31
+ <Text size={1}>
32
+ Presentation n'autorise pas {missing.length > 1 ? 'ces origines' : 'cette origine'} : la page s'affiche sans édition visuelle. Dans sanity.config.ts,
33
+ passer <InlineCode>allowOrigins: ncfAllowedOrigins(options)</InlineCode> à presentationTool.
34
+ </Text>
35
+ </Stack>
36
+ </Card>
37
+ </Container>
38
+ )
39
+ }
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.1'
5
+ export const KIT_VERSION = '2.10.1'