@nocode-factory/sanity-kit 2.2.2 → 2.3.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/index.d.ts +21 -2
- package/dist/index.js +206 -93
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +12 -0
- package/src/tools/navbar/PreviewLauncher.tsx +129 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {DocumentsIcon} from '@sanity/icons/Documents'
|
|
|
6
6
|
import {resolveConfig} from './config/resolve'
|
|
7
7
|
import {validateConfig} from './config/validate'
|
|
8
8
|
import {createToolComponent} from './tools/createToolComponent'
|
|
9
|
+
import {createPreviewLauncher} from './tools/navbar/PreviewLauncher'
|
|
9
10
|
import {PagesTool} from './tools/pages/PagesTool'
|
|
10
11
|
import {ComponentsTool} from './tools/components/ComponentsTool'
|
|
11
12
|
import {HistoryTool} from './tools/history/HistoryTool'
|
|
@@ -100,6 +101,16 @@ export const ncfKit = definePlugin<NcfKitConfig>((options) => {
|
|
|
100
101
|
newDocumentOptions: (prev) =>
|
|
101
102
|
prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE),
|
|
102
103
|
},
|
|
104
|
+
|
|
105
|
+
// Le lanceur d'aperçu s'ajoute à droite des outils, dans la barre du haut
|
|
106
|
+
// comme dans le volet latéral. Posé par le plugin : il n'y a rien à
|
|
107
|
+
// brancher dans la configuration d'un projet.
|
|
108
|
+
//
|
|
109
|
+
// Le menu des outils est rendu tel quel — un plugin qui le remplacerait
|
|
110
|
+
// ferait disparaître « Plus » et tout ce qu'un autre y aurait mis.
|
|
111
|
+
studio: {
|
|
112
|
+
components: {toolMenu: createPreviewLauncher(config, issues)},
|
|
113
|
+
},
|
|
103
114
|
}
|
|
104
115
|
})
|
|
105
116
|
|
|
@@ -172,6 +183,7 @@ export {
|
|
|
172
183
|
export type {PreviewPerspective, PresentationOptions} from './lib/studioLinks'
|
|
173
184
|
export {usePreviewTarget} from './context/PreviewTargetContext'
|
|
174
185
|
export {NcfPreviewHeader, ncfPreviewComponents} from './tools/presentation/PreviewHeader'
|
|
186
|
+
export {NcfPreviewLauncher, createPreviewLauncher} from './tools/navbar/PreviewLauncher'
|
|
175
187
|
export {SharePreview} from './tools/pages/SharePreview'
|
|
176
188
|
export {requestPreviewGrant, explainGrantError} from './lib/service'
|
|
177
189
|
export type {PreviewGrant} from './lib/service'
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {Box, Button, Flex, Stack, Text} from '@sanity/ui'
|
|
2
|
+
import {useRouter} from 'sanity/router'
|
|
3
|
+
import type {ToolMenuProps} from 'sanity'
|
|
4
|
+
import {InlinePopover} from '../../ui/Popover'
|
|
5
|
+
import {KitProvider, useKitConfig} from '../../context/KitContext'
|
|
6
|
+
import {presentationPath, PERSPECTIVES, type PreviewPerspective} from '../../lib/studioLinks'
|
|
7
|
+
import type {ConfigIssue, NcfEnvironment, ResolvedKitConfig} from '../../config/types'
|
|
8
|
+
import {EyeOpenIcon} from '@sanity/icons/EyeOpen'
|
|
9
|
+
import {LaunchIcon} from '@sanity/icons/Launch'
|
|
10
|
+
import {BORDER} from '../../ui/tokens'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Lanceur d'aperçu, posé dans la barre du haut à droite des outils.
|
|
14
|
+
*
|
|
15
|
+
* Deux questions, une seule poignée : **quelle version du site**, et **quel
|
|
16
|
+
* état du contenu**. On choisit, on ouvre.
|
|
17
|
+
*
|
|
18
|
+
* Volontairement sans mémoire, contrairement au sélecteur de l'onglet Pages :
|
|
19
|
+
* ici on lance une consultation, on ne règle pas un mode de travail. Un
|
|
20
|
+
* bouton de barre qui retiendrait un état finirait par mentir sur ce qu'on
|
|
21
|
+
* regarde ailleurs.
|
|
22
|
+
*/
|
|
23
|
+
export function NcfPreviewLauncher(props: ToolMenuProps) {
|
|
24
|
+
const config = useKitConfig()
|
|
25
|
+
const router = useRouter()
|
|
26
|
+
const environments = config.environments
|
|
27
|
+
|
|
28
|
+
if (environments.length === 0) return props.renderDefault(props)
|
|
29
|
+
|
|
30
|
+
const open = (environment: NcfEnvironment, perspective: PreviewPerspective) => {
|
|
31
|
+
const path = presentationPath(environment.url, {environment, perspective})
|
|
32
|
+
if (path) router.navigateUrl({path})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// En colonne dans le volet latéral, en ligne dans la barre : le menu des
|
|
36
|
+
// outils change de forme selon la place, le lanceur doit suivre.
|
|
37
|
+
const inline = props.context === 'topbar'
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Flex
|
|
41
|
+
align={inline ? 'center' : 'stretch'}
|
|
42
|
+
direction={inline ? 'row' : 'column'}
|
|
43
|
+
gap={inline ? 2 : 1}
|
|
44
|
+
>
|
|
45
|
+
{props.renderDefault(props)}
|
|
46
|
+
|
|
47
|
+
<InlinePopover
|
|
48
|
+
width={248}
|
|
49
|
+
trigger={({toggle}) => (
|
|
50
|
+
<Button
|
|
51
|
+
mode="bleed"
|
|
52
|
+
fontSize={1}
|
|
53
|
+
padding={inline ? 2 : 3}
|
|
54
|
+
icon={EyeOpenIcon}
|
|
55
|
+
text="Prévisualiser"
|
|
56
|
+
title="Ouvrir le site dans l'aperçu"
|
|
57
|
+
justify={inline ? undefined : 'flex-start'}
|
|
58
|
+
onClick={toggle}
|
|
59
|
+
/>
|
|
60
|
+
)}
|
|
61
|
+
>
|
|
62
|
+
{({close}) => (
|
|
63
|
+
<Stack gap={1}>
|
|
64
|
+
{environments.map((environment, index) => (
|
|
65
|
+
<Box
|
|
66
|
+
key={environment.id}
|
|
67
|
+
paddingTop={index === 0 ? 1 : 3}
|
|
68
|
+
style={
|
|
69
|
+
index === 0 ? undefined : {borderTop: `1px solid ${BORDER}`, marginTop: 4}
|
|
70
|
+
}
|
|
71
|
+
>
|
|
72
|
+
<Box paddingX={2} paddingBottom={1}>
|
|
73
|
+
<Text size={0} weight="semibold" muted textOverflow="ellipsis">
|
|
74
|
+
{environment.label}
|
|
75
|
+
</Text>
|
|
76
|
+
</Box>
|
|
77
|
+
{PERSPECTIVES.map((option) => (
|
|
78
|
+
<Flex
|
|
79
|
+
key={option.id}
|
|
80
|
+
align="center"
|
|
81
|
+
gap={2}
|
|
82
|
+
padding={2}
|
|
83
|
+
onClick={() => {
|
|
84
|
+
open(environment, option.id)
|
|
85
|
+
close()
|
|
86
|
+
}}
|
|
87
|
+
style={{cursor: 'pointer', borderRadius: 3}}
|
|
88
|
+
onMouseEnter={(event) => {
|
|
89
|
+
event.currentTarget.style.background =
|
|
90
|
+
'var(--card-muted-bg-color, rgba(127,127,127,0.12))'
|
|
91
|
+
}}
|
|
92
|
+
onMouseLeave={(event) => {
|
|
93
|
+
event.currentTarget.style.background = 'transparent'
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<Stack gap={1} flex={1} style={{minWidth: 0}}>
|
|
97
|
+
<Text size={1}>{option.label}</Text>
|
|
98
|
+
<Text size={0} muted textOverflow="ellipsis">
|
|
99
|
+
{option.hint}
|
|
100
|
+
</Text>
|
|
101
|
+
</Stack>
|
|
102
|
+
<LaunchIcon style={{fontSize: 14, opacity: 0.5, flex: 'none'}} />
|
|
103
|
+
</Flex>
|
|
104
|
+
))}
|
|
105
|
+
</Box>
|
|
106
|
+
))}
|
|
107
|
+
</Stack>
|
|
108
|
+
)}
|
|
109
|
+
</InlinePopover>
|
|
110
|
+
</Flex>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Le lanceur, muni de la configuration du kit.
|
|
117
|
+
*
|
|
118
|
+
* Le menu des outils est rendu hors de l'arbre des outils : il n'hérite donc
|
|
119
|
+
* d'aucun de leurs contextes, et doit porter le sien.
|
|
120
|
+
*/
|
|
121
|
+
export function createPreviewLauncher(config: ResolvedKitConfig, issues: ConfigIssue[]) {
|
|
122
|
+
return function NcfToolMenu(props: ToolMenuProps) {
|
|
123
|
+
return (
|
|
124
|
+
<KitProvider config={config} issues={issues}>
|
|
125
|
+
<NcfPreviewLauncher {...props} />
|
|
126
|
+
</KitProvider>
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
}
|
package/src/version.ts
CHANGED