@nocode-factory/sanity-kit 2.17.0 → 2.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocode-factory/sanity-kit",
3
- "version": "2.17.0",
3
+ "version": "2.17.1",
4
4
  "description": "Outils Studio de NoCode Factory : Pages (liste + board), Composants, Historique",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -2,6 +2,8 @@ import {useCallback, useMemo, useState} from 'react'
2
2
  import {useKitConfig} from '../context/KitContext'
3
3
  import {useKitClient} from './useKitClient'
4
4
  import {
5
+ defaultEnvironmentId,
6
+ editableEnvironment,
5
7
  customEnvironment,
6
8
  CUSTOM_ENVIRONMENT_ID,
7
9
  effectivePerspective,
@@ -74,7 +76,8 @@ export function usePreviewTargetState(): PreviewTargetState {
74
76
  const scope = `${STORAGE_PREFIX}${client.config().projectId ?? 'sans-projet'}`
75
77
 
76
78
  const environments = config.environments
77
- const fallback = environments[0]?.id ?? null
79
+ // Par défaut la préproduction : c'est là qu'on édite.
80
+ const fallback = defaultEnvironmentId(environments, config.previewUrl)
78
81
 
79
82
  const [environmentId, setStoredEnvironment] = useState<string | null>(() => {
80
83
  const saved = read(`${scope}:environment`)
@@ -141,9 +144,12 @@ export function usePreviewTargetState(): PreviewTargetState {
141
144
  // La production n'a que le contenu en ligne, quel que soit le choix retenu.
142
145
  const shown = effectivePerspective(environment, perspective, config.previewUrl)
143
146
 
147
+ // Presentation s'ouvre toujours sur un environnement éditable (jamais la
148
+ // production) ; production choisie = préproduction, contenu en ligne.
144
149
  const pathFor = useCallback(
145
- (url: string | null) => presentationPath(url, {environment, perspective: shown}),
146
- [environment, shown],
150
+ (url: string | null) =>
151
+ presentationPath(url, {environment: editableEnvironment(environment, allEnvironments, config.previewUrl), perspective: shown}),
152
+ [environment, allEnvironments, config.previewUrl, shown],
147
153
  )
148
154
 
149
155
  const siteUrlFor = useCallback(
@@ -1,7 +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
+ import {editableEnvironment, presentationPath, urlOn} from './studioLinks'
5
5
 
6
6
  /**
7
7
  * Ouvre un composant : Presentation avec son rendu réel et ses valeurs par
@@ -71,6 +71,9 @@ export async function openDesignSystem(options: {
71
71
  navigateIntent('edit', designSystemIntentParams(config, id ?? config.componentPreview.defaultsType))
72
72
  return
73
73
  }
74
- const path = presentationPath(config.previewUrl ? `${config.previewUrl}${config.componentPreview.path}` : null)
74
+ // Sur la préproduction (éditable), jamais sur la production.
75
+ const env = editableEnvironment(config.environments[0] ?? null, config.environments, config.previewUrl)
76
+ const url = urlOn(env, config.componentPreview.path) ?? (config.previewUrl ? `${config.previewUrl}${config.componentPreview.path}` : null)
77
+ const path = presentationPath(url, env ? {environment: env} : {})
75
78
  if (path) navigateUrl(path)
76
79
  }
@@ -82,6 +82,26 @@ export function effectivePerspective(environment: NcfEnvironment | null, perspec
82
82
  return environment && isPublicEnvironment(environment, previewUrl) ? 'published' : perspective
83
83
  }
84
84
 
85
+ /**
86
+ * Environnement où ouvrir Presentation : on n'édite jamais la production (elle ne
87
+ * montre pas les brouillons et ne charge pas l'édition visuelle : « Unable to
88
+ * connect »). Production choisie : la première préversion déclarée, qui montrera
89
+ * le contenu en ligne. Sans préversion : l'environnement choisi, tel quel.
90
+ */
91
+ export function editableEnvironment(
92
+ selected: NcfEnvironment | null,
93
+ environments: readonly NcfEnvironment[],
94
+ previewUrl: string | null | undefined,
95
+ ): NcfEnvironment | null {
96
+ if (!selected || !isPublicEnvironment(selected, previewUrl)) return selected
97
+ return environments.find((e) => !isPublicEnvironment(e, previewUrl)) ?? selected
98
+ }
99
+
100
+ /** Environnement proposé par défaut : la première préversion, sinon le premier déclaré. */
101
+ export function defaultEnvironmentId(environments: readonly NcfEnvironment[], previewUrl: string | null | undefined): string | null {
102
+ return (environments.find((e) => !isPublicEnvironment(e, previewUrl)) ?? environments[0])?.id ?? null
103
+ }
104
+
85
105
  export interface OnlineUrlOptions {
86
106
  /** Chemin de la page (défaut : l'accueil). */
87
107
  path?: string | null
@@ -3,7 +3,7 @@ import {useRouter} from 'sanity/router'
3
3
  import type {ToolMenuProps} from 'sanity'
4
4
  import {InlinePopover} from '../../ui/Popover'
5
5
  import {KitProvider, useKitConfig} from '../../context/KitContext'
6
- import {presentationPath, previewTargets, type PreviewPerspective} from '../../lib/studioLinks'
6
+ import {editableEnvironment, isPublicEnvironment, presentationPath, previewTargets, type PreviewPerspective} from '../../lib/studioLinks'
7
7
  import {useOpenOnline} from '../../hooks/useOpenOnline'
8
8
  import type {ConfigIssue, NcfEnvironment, ResolvedKitConfig} from '../../config/types'
9
9
  import {EyeOpenIcon} from '@sanity/icons/EyeOpen'
@@ -46,8 +46,12 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
46
46
 
47
47
  // Ouvre l'aperçu DANS le Studio : la page apparaît dans Presentation, sans
48
48
  // quitter le Studio.
49
+ // Jamais la production dans Presentation (pas d'édition possible) : « Prod · En
50
+ // ligne » s'ouvre sur la préproduction, en contenu en ligne.
49
51
  const openInStudio = (environment: NcfEnvironment, perspective: PreviewPerspective) => {
50
- const path = presentationPath(environment.url, {environment, perspective})
52
+ const target = editableEnvironment(environment, environments, config.previewUrl) ?? environment
53
+ const shown = isPublicEnvironment(environment, config.previewUrl) ? 'published' : perspective
54
+ const path = presentationPath(target.url, {environment: target, perspective: shown})
51
55
  if (path) router.navigateUrl({path})
52
56
  }
53
57
 
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
4
4
  * le vérifie.
5
5
  */
6
- export const KIT_VERSION = '2.17.0'
6
+ export const KIT_VERSION = '2.17.1'