@nocode-factory/sanity-kit 2.10.0 → 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/index.d.ts +1 -1
- package/dist/index.js +67 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config/validate.ts +3 -10
- 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) {
|
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