@nocode-factory/sanity-kit 2.4.0 → 2.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocode-factory/sanity-kit",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "description": "Outils Studio de NoCode Factory : Pages (liste + board), Composants, Historique",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -30,6 +30,26 @@ export function urlOn(environment: NcfEnvironment | null, path: string | null):
30
30
  return `${trimEnd(environment.url)}${path.startsWith('/') ? path : `/${path}`}`
31
31
  }
32
32
 
33
+ /**
34
+ * URL du vrai site, en ligne, pour un environnement et un état de contenu.
35
+ *
36
+ * Les brouillons passent par la route de bascule du site, qui pose le cookie
37
+ * de mode brouillon puis renvoie à l'accueil. La production ne montre jamais
38
+ * de brouillons : on y retombe sur l'URL simple, et la route refuserait de
39
+ * toute façon.
40
+ */
41
+ export function onlineUrl(
42
+ environment: NcfEnvironment | null,
43
+ perspective: PreviewPerspective,
44
+ ): string | null {
45
+ if (!environment?.url) return null
46
+ const base = environment.url.replace(/\/+$/, '')
47
+ if (perspective === 'drafts' && environment.id !== 'production') {
48
+ return `${base}/api/draft-mode/toggle?enable=true&redirect=/`
49
+ }
50
+ return base
51
+ }
52
+
33
53
  export interface PresentationOptions {
34
54
  /** Front à charger dans l'aperçu. */
35
55
  environment?: NcfEnvironment | 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, PERSPECTIVES, type PreviewPerspective} from '../../lib/studioLinks'
6
+ import {presentationPath, onlineUrl, PERSPECTIVES, type PreviewPerspective} from '../../lib/studioLinks'
7
7
  import type {ConfigIssue, NcfEnvironment, ResolvedKitConfig} from '../../config/types'
8
8
  import {EyeOpenIcon} from '@sanity/icons/EyeOpen'
9
9
  import {LaunchIcon} from '@sanity/icons/Launch'
@@ -35,11 +35,22 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
35
35
  )
36
36
  }
37
37
 
38
- const open = (environment: NcfEnvironment, perspective: PreviewPerspective) => {
38
+ // Ouvre l'aperçu DANS le Studio : la page apparaît dans Presentation, sans
39
+ // quitter le Studio.
40
+ const openInStudio = (environment: NcfEnvironment, perspective: PreviewPerspective) => {
39
41
  const path = presentationPath(environment.url, {environment, perspective})
40
42
  if (path) router.navigateUrl({path})
41
43
  }
42
44
 
45
+ // Ouvre le vrai site EN LIGNE, dans un nouvel onglet. La perspective est
46
+ // respectée en passant par la route de bascule du site : « brouillons »
47
+ // l'active, « en ligne » la coupe. Un site sans cette route — ou la
48
+ // production, qui refuse les brouillons — retombe sur l'URL simple.
49
+ const openOnline = (environment: NcfEnvironment, perspective: PreviewPerspective) => {
50
+ const target = onlineUrl(environment, perspective)
51
+ if (target) window.open(target, '_blank', 'noopener')
52
+ }
53
+
43
54
  // En colonne dans le volet latéral, en ligne dans la barre : le menu des
44
55
  // outils change de forme selon la place, le lanceur doit suivre.
45
56
  const inline = props.context === 'topbar'
@@ -71,6 +82,11 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
71
82
  >
72
83
  {({close}) => (
73
84
  <Stack gap={1}>
85
+ <Box paddingX={2} paddingTop={1} paddingBottom={2}>
86
+ <Text size={0} muted>
87
+ Cliquer : ouvre dans le Studio. L'icône ↗ : ouvre le site en ligne.
88
+ </Text>
89
+ </Box>
74
90
  {environments.map((environment, index) => (
75
91
  <Box
76
92
  key={environment.id}
@@ -85,31 +101,44 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
85
101
  </Text>
86
102
  </Box>
87
103
  {PERSPECTIVES.map((option) => (
88
- <Flex
89
- key={option.id}
90
- align="center"
91
- gap={2}
92
- padding={2}
93
- onClick={() => {
94
- open(environment, option.id)
95
- close()
96
- }}
97
- style={{cursor: 'pointer', borderRadius: 3}}
98
- onMouseEnter={(event) => {
99
- event.currentTarget.style.background =
100
- 'var(--card-muted-bg-color, rgba(127,127,127,0.12))'
101
- }}
102
- onMouseLeave={(event) => {
103
- event.currentTarget.style.background = 'transparent'
104
- }}
105
- >
106
- <Stack gap={1} flex={1} style={{minWidth: 0}}>
107
- <Text size={1}>{option.label}</Text>
108
- <Text size={0} muted textOverflow="ellipsis">
109
- {option.hint}
110
- </Text>
111
- </Stack>
112
- <LaunchIcon style={{fontSize: 14, opacity: 0.5, flex: 'none'}} />
104
+ <Flex key={option.id} align="center" gap={1}>
105
+ <Flex
106
+ align="center"
107
+ flex={1}
108
+ padding={2}
109
+ onClick={() => {
110
+ openInStudio(environment, option.id)
111
+ close()
112
+ }}
113
+ style={{cursor: 'pointer', borderRadius: 3, minWidth: 0}}
114
+ title="Ouvrir dans le Studio (Presentation)"
115
+ onMouseEnter={(event) => {
116
+ event.currentTarget.style.background =
117
+ 'var(--card-muted-bg-color, rgba(127,127,127,0.12))'
118
+ }}
119
+ onMouseLeave={(event) => {
120
+ event.currentTarget.style.background = 'transparent'
121
+ }}
122
+ >
123
+ <Stack gap={1} style={{minWidth: 0}}>
124
+ <Text size={1}>{option.label}</Text>
125
+ <Text size={0} muted textOverflow="ellipsis">
126
+ {option.hint}
127
+ </Text>
128
+ </Stack>
129
+ </Flex>
130
+ <Button
131
+ mode="bleed"
132
+ padding={2}
133
+ fontSize={1}
134
+ icon={LaunchIcon}
135
+ title="Ouvrir le site en ligne, dans un nouvel onglet"
136
+ aria-label={`Ouvrir ${environment.label} en ligne (${option.label})`}
137
+ onClick={() => {
138
+ openOnline(environment, option.id)
139
+ close()
140
+ }}
141
+ />
113
142
  </Flex>
114
143
  ))}
115
144
  </Box>
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.4.0'
5
+ export const KIT_VERSION = '2.6.0'