@nocode-factory/sanity-kit 2.10.0 → 2.10.2
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 +1 -1
- package/dist/index.js +88 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config/validate.ts +3 -10
- package/src/form/OverrideInput.tsx +5 -0
- package/src/hooks/useInPresentation.ts +26 -0
- package/src/lib/studioLinks.ts +28 -0
- package/src/tools/createToolComponent.tsx +2 -0
- package/src/ui/PreviewOriginsNotice.tsx +39 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/config/validate.ts
CHANGED
|
@@ -107,16 +107,9 @@ export function validateConfig(config: ResolvedKitConfig): ConfigIssue[] {
|
|
|
107
107
|
seenEnvironments.add(environment.id)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
|
|
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) {
|
|
@@ -8,6 +8,7 @@ import {blockName, componentIntentParams} from '../lib/blocks'
|
|
|
8
8
|
import {useKitClient} from '../hooks/useKitClient'
|
|
9
9
|
import {openComponentDefaults} from '../lib/openComponent'
|
|
10
10
|
import {useComponentDefaults} from '../hooks/useComponentDefaults'
|
|
11
|
+
import {useInPresentation} from '../hooks/useInPresentation'
|
|
11
12
|
import {
|
|
12
13
|
defaultValueAt,
|
|
13
14
|
describeValue,
|
|
@@ -128,10 +129,14 @@ export function createOverrideInput(config: ResolvedKitConfig): ComponentType<In
|
|
|
128
129
|
// En tête du formulaire d'une instance de composant : mène aux valeurs par
|
|
129
130
|
// défaut du composant (son « instance principale »), qui s'appliquent à toutes
|
|
130
131
|
// les instances dont le champ est vide.
|
|
132
|
+
// Pas dans Presentation : on y édite une instance à côté de son rendu, et quitter la
|
|
133
|
+
// page pour les valeurs par défaut y prête à confusion (bouton retiré à la demande).
|
|
131
134
|
function WithMainInstance(props: InputProps & {type: string}) {
|
|
132
135
|
const {type, ...inputProps} = props
|
|
133
136
|
const client = useKitClient()
|
|
134
137
|
const router = useRouter()
|
|
138
|
+
const inPresentation = useInPresentation()
|
|
139
|
+
if (inPresentation) return inputProps.renderDefault(inputProps)
|
|
135
140
|
const open = () =>
|
|
136
141
|
void openComponentDefaults({type, config, hasDefaults: true, client, navigateIntent: (i, p) => router.navigateIntent(i, p)})
|
|
137
142
|
return (
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {useWorkspace} from 'sanity'
|
|
2
|
+
import {useRouterState} from 'sanity/router'
|
|
3
|
+
|
|
4
|
+
/** Noms des outils Presentation du workspace (le nom est configurable). */
|
|
5
|
+
export function presentationToolNames(tools: {name: string}[]): string[] {
|
|
6
|
+
return tools
|
|
7
|
+
.filter((t) => (t as {__internalApplicationType?: string}).__internalApplicationType === 'sanity/presentation' || t.name === 'presentation')
|
|
8
|
+
.map((t) => t.name)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Vrai si l'adresse du Studio est dans un de ces outils (premier segment après la base). */
|
|
12
|
+
export function isInTool(pathname: string, names: string[]): boolean {
|
|
13
|
+
return pathname.split('/').some((segment) => names.includes(segment))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Le formulaire est-il affiché dans Presentation ? Le routeur sert à se mettre à jour
|
|
18
|
+
* quand on change d'outil ; l'adresse dit lequel (le formulaire de Presentation est rendu
|
|
19
|
+
* dans la portée de son outil, qui ne porte pas le nom de l'outil).
|
|
20
|
+
*/
|
|
21
|
+
export function useInPresentation(): boolean {
|
|
22
|
+
const {tools} = useWorkspace()
|
|
23
|
+
useRouterState()
|
|
24
|
+
if (typeof window === 'undefined') return false
|
|
25
|
+
return isInTool(window.location.pathname, presentationToolNames(tools))
|
|
26
|
+
}
|
package/src/lib/studioLinks.ts
CHANGED
|
@@ -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
|
|
|
@@ -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,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