@nocode-factory/sanity-kit 2.44.2 → 2.46.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/{fixCrossLanguageReferences-DQ6bDuSZ.js → fixCrossLanguageReferences-CQGzpNii.js} +2 -2
- package/dist/{fixCrossLanguageReferences-DQ6bDuSZ.js.map → fixCrossLanguageReferences-CQGzpNii.js.map} +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +64 -10
- package/dist/index.js.map +1 -1
- package/dist/schema.js +1 -1
- package/package.json +1 -1
- package/src/form/OverrideInput.tsx +11 -2
- package/src/index.ts +3 -1
- package/src/lib/overrides.ts +25 -0
- package/src/lib/propagate.ts +4 -1
- package/src/lib/studioLinks.ts +15 -0
- package/src/schema/componentDefaults.ts +3 -1
- package/src/tools/navbar/PreviewLauncher.tsx +8 -3
- package/src/ui/HelpTextStyle.tsx +34 -0
- package/src/version.ts +1 -1
package/dist/schema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as DEFAULT_PAGE_BUILDER_FIELD, S as toPath, _ as redirectMapOf, a as componentDefaultsMainDocument, c as defineComponentDefaults, d as syncTranslationRedirects, f as translationRedirectId, g as redirectKey, h as followRedirects, i as DEFAULT_COMPONENT_DEFAULTS_TYPE, l as requiredUnlessDefault, n as withSameLanguageReferences, o as componentDefaultsMainDocuments, r as pageTypesFromSiteRoutes, s as defaultsFieldName, t as fixCrossLanguageReferences, u as requiredUnlessDefaultFor } from "./fixCrossLanguageReferences-
|
|
1
|
+
import { A as DEFAULT_PAGE_BUILDER_FIELD, S as toPath, _ as redirectMapOf, a as componentDefaultsMainDocument, c as defineComponentDefaults, d as syncTranslationRedirects, f as translationRedirectId, g as redirectKey, h as followRedirects, i as DEFAULT_COMPONENT_DEFAULTS_TYPE, l as requiredUnlessDefault, n as withSameLanguageReferences, o as componentDefaultsMainDocuments, r as pageTypesFromSiteRoutes, s as defaultsFieldName, t as fixCrossLanguageReferences, u as requiredUnlessDefaultFor } from "./fixCrossLanguageReferences-CQGzpNii.js";
|
|
2
2
|
/**
|
|
3
3
|
* Onglets du formulaire d'un document : Content, Sections, SEO, Settings.
|
|
4
4
|
*
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
inheritedPlaceholder,
|
|
17
17
|
isEmptyValue,
|
|
18
18
|
isOverride,
|
|
19
|
+
preselectsDefault,
|
|
19
20
|
resetAction,
|
|
20
21
|
resolveFieldPath,
|
|
21
22
|
shortValue,
|
|
@@ -113,10 +114,15 @@ export function createOverrideInput(config: ResolvedKitConfig): ComponentType<In
|
|
|
113
114
|
const st = inputProps.schemaType as {jsonType?: string; options?: {list?: unknown[]}}
|
|
114
115
|
const freeText = (st.jsonType === 'string' || st.jsonType === 'number') && !st.options?.list?.length
|
|
115
116
|
const placeholder = inherits && freeText ? inheritedPlaceholder(inherited) : null
|
|
117
|
+
// Choix (liste) et cases à cocher : montrer la valeur par défaut
|
|
118
|
+
// pré-sélectionnée dans le contrôle, sans l'écrire — le champ reste hérité.
|
|
119
|
+
const preselect = inherits && placeholder === null && preselectsDefault(st, inherited)
|
|
116
120
|
const shown =
|
|
117
121
|
placeholder !== null
|
|
118
122
|
? ({...inputProps, elementProps: {...(inputProps.elementProps as object), placeholder}} as InputProps)
|
|
119
|
-
:
|
|
123
|
+
: preselect
|
|
124
|
+
? ({...inputProps, value: inherited} as InputProps)
|
|
125
|
+
: inputProps
|
|
120
126
|
|
|
121
127
|
// « Réinitialiser » remet le champ en HÉRITAGE (vidé en base) : il suit la
|
|
122
128
|
// valeur par défaut, aujourd'hui comme après ses changements. Sans valeur par
|
|
@@ -160,7 +166,7 @@ export function createOverrideInput(config: ResolvedKitConfig): ComponentType<In
|
|
|
160
166
|
)}
|
|
161
167
|
</Flex>
|
|
162
168
|
)}
|
|
163
|
-
{inherits && placeholder === null && (
|
|
169
|
+
{inherits && placeholder === null && !preselect && (
|
|
164
170
|
<Flex align="center" gap={2} marginTop={2} wrap="wrap">
|
|
165
171
|
<Text size={0} muted>
|
|
166
172
|
Component default value: {describeValue(inherited)}
|
|
@@ -196,6 +202,9 @@ export function createOverrideInput(config: ResolvedKitConfig): ComponentType<In
|
|
|
196
202
|
// (image, référence, ou objet à saisie personnalisée comme une couleur de charte).
|
|
197
203
|
type TypeChain = {name?: string; type?: TypeChain; components?: {input?: unknown}}
|
|
198
204
|
function carriesDot(schemaType: InputProps['schemaType']): boolean {
|
|
205
|
+
// Champ propre à l'instance (options.instanceOnly, ex. ancre) : pas de valeur par
|
|
206
|
+
// défaut, donc ni pastille ni héritage.
|
|
207
|
+
if ((schemaType.options as {instanceOnly?: boolean} | undefined)?.instanceOnly) return false
|
|
199
208
|
if (schemaType.jsonType !== 'object') return true
|
|
200
209
|
let t: TypeChain | undefined = schemaType as unknown as TypeChain
|
|
201
210
|
while (t) {
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {resolveConfig} from './config/resolve'
|
|
|
10
10
|
import {validateConfig} from './config/validate'
|
|
11
11
|
import {createToolComponent} from './tools/createToolComponent'
|
|
12
12
|
import {createPreviewLauncher} from './tools/navbar/PreviewLauncher'
|
|
13
|
+
import {HelpTextStyle} from './ui/HelpTextStyle'
|
|
13
14
|
import {PagesTool} from './tools/pages/PagesTool'
|
|
14
15
|
import {ComponentsTool} from './tools/components/ComponentsTool'
|
|
15
16
|
import {HistoryTool} from './tools/history/HistoryTool'
|
|
@@ -186,7 +187,7 @@ export const ncfKit = definePlugin<NcfKitConfig>((options) => {
|
|
|
186
187
|
// outils techniques (Vision, planification) dans « Plus » (option moreTools).
|
|
187
188
|
// Un projet n'a donc plus de menu d'outils à écrire.
|
|
188
189
|
studio: {
|
|
189
|
-
components: {toolMenu: createPreviewLauncher(config, issues)},
|
|
190
|
+
components: {toolMenu: createPreviewLauncher(config, issues), layout: HelpTextStyle},
|
|
190
191
|
},
|
|
191
192
|
|
|
192
193
|
// Pastille bleue sur les champs d'une instance de composant qui surchargent
|
|
@@ -289,6 +290,7 @@ export {NcfPreviewHeader, ncfPreviewComponents} from './tools/presentation/Previ
|
|
|
289
290
|
export {ncfPresentationComponents} from './tools/presentation/PagesNavigator'
|
|
290
291
|
export {NcfPreviewLauncher, createPreviewLauncher} from './tools/navbar/PreviewLauncher'
|
|
291
292
|
export {NcfKitUpdate} from './tools/navbar/KitUpdate'
|
|
293
|
+
export {HelpTextStyle} from './ui/HelpTextStyle'
|
|
292
294
|
export {useKitUpdate} from './hooks/useKitUpdate'
|
|
293
295
|
export type {KitUpdate} from './hooks/useKitUpdate'
|
|
294
296
|
export {compareVersions, isPrerelease} from './lib/version'
|
package/src/lib/overrides.ts
CHANGED
|
@@ -168,3 +168,28 @@ export function shortValue(value: unknown, max = 32): string {
|
|
|
168
168
|
const d = describeValue(value)
|
|
169
169
|
return d.length > max ? `${d.slice(0, max - 1)}…` : d
|
|
170
170
|
}
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Un champ hérité doit-il afficher la valeur par défaut **pré-sélectionnée**
|
|
175
|
+
* dans son contrôle ?
|
|
176
|
+
*
|
|
177
|
+
* Oui pour un choix (liste d'options : style, taille, position, niveau de
|
|
178
|
+
* titre…) et pour une case à cocher : l'éditeur voit ce qui s'appliquera, au
|
|
179
|
+
* lieu d'un contrôle vide doublé d'une mention. La valeur n'est pas écrite —
|
|
180
|
+
* le champ reste vide, donc hérité ; choisir autre chose l'emporte et fait
|
|
181
|
+
* apparaître la pastille de réinitialisation.
|
|
182
|
+
*
|
|
183
|
+
* Non pour le texte libre (déjà traité par un placeholder grisé) ni pour les
|
|
184
|
+
* objets, listes et images (pas de « valeur sélectionnée » à montrer).
|
|
185
|
+
*/
|
|
186
|
+
export function preselectsDefault(
|
|
187
|
+
schemaType: {jsonType?: string; options?: {list?: unknown[]}} | undefined,
|
|
188
|
+
inherited: unknown,
|
|
189
|
+
): boolean {
|
|
190
|
+
if (isEmptyValue(inherited)) return false
|
|
191
|
+
const jt = schemaType?.jsonType
|
|
192
|
+
if (jt === 'boolean') return true
|
|
193
|
+
if ((jt === 'string' || jt === 'number') && (schemaType?.options?.list?.length ?? 0) > 0) return true
|
|
194
|
+
return false
|
|
195
|
+
}
|
package/src/lib/propagate.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface SchemaTypeLike {
|
|
|
27
27
|
fields?: {name: string; type: SchemaTypeLike}[]
|
|
28
28
|
of?: SchemaTypeLike[]
|
|
29
29
|
to?: unknown
|
|
30
|
-
options?: {list?: unknown[]}
|
|
30
|
+
options?: {list?: unknown[]; instanceOnly?: boolean}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface PropagationResult {
|
|
@@ -58,6 +58,9 @@ function typeNames(t: SchemaTypeLike | undefined): string[] {
|
|
|
58
58
|
export function kindOf(t: SchemaTypeLike | undefined, value: unknown): FieldKind {
|
|
59
59
|
if (t) {
|
|
60
60
|
const names = typeNames(t)
|
|
61
|
+
// Champ propre à l'instance (options.instanceOnly, ex. ancre d'une section) :
|
|
62
|
+
// une valeur recopiée telle quelle, jamais traduite.
|
|
63
|
+
if (t.options?.instanceOnly) return 'value'
|
|
61
64
|
if (names.some((n) => VALUE_TYPE_NAMES.has(n)) || t.to) return 'value'
|
|
62
65
|
if (t.jsonType === 'array') {
|
|
63
66
|
const of = t.of ?? []
|
package/src/lib/studioLinks.ts
CHANGED
|
@@ -187,6 +187,21 @@ function pathOf(url: string | null | undefined): string | null {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Chemin de la page actuellement montrée dans Presentation.
|
|
192
|
+
*
|
|
193
|
+
* Presentation garde l'adresse prévisualisée dans le paramètre `preview` de
|
|
194
|
+
* l'URL du Studio — une URL complète (`https://site.fr/a-propos`) ou un chemin.
|
|
195
|
+
* Le lanceur s'en sert pour rouvrir la MÊME page sur un autre environnement,
|
|
196
|
+
* au lieu de retomber sur l'accueil.
|
|
197
|
+
*
|
|
198
|
+
* Rend `null` hors de Presentation, ou si le paramètre est absent.
|
|
199
|
+
*/
|
|
200
|
+
export function previewPathFromLocation(search: string): string | null {
|
|
201
|
+
const preview = new URLSearchParams(search).get('preview')
|
|
202
|
+
return preview ? pathOf(preview) : null
|
|
203
|
+
}
|
|
204
|
+
|
|
190
205
|
/** Lien d'édition classique, pour les cas où l'on veut le formulaire. */
|
|
191
206
|
export function editIntentPath(id: string, type: string): string {
|
|
192
207
|
return `/intent/edit/id=${encodeURIComponent(id)};type=${encodeURIComponent(type)}/`
|
|
@@ -52,7 +52,9 @@ export function defineComponentDefaults(options: {sections: readonly unknown[];
|
|
|
52
52
|
type: 'object',
|
|
53
53
|
description: 'Default values of this component. Empty = design system value.',
|
|
54
54
|
options: {collapsible: true, collapsed: true},
|
|
55
|
-
|
|
55
|
+
// Un champ propre à l'instance (options.instanceOnly, ex. ancre) n'a pas de
|
|
56
|
+
// valeur par défaut : absent des réglages du composant.
|
|
57
|
+
fields: t.fields.filter((f) => !(f.options as {instanceOnly?: boolean} | undefined)?.instanceOnly).map(relax) as never,
|
|
56
58
|
}),
|
|
57
59
|
),
|
|
58
60
|
preview: {prepare: () => ({title: title.replace(/^\S+\s/, '')})},
|
|
@@ -4,7 +4,7 @@ import {useRouter} from 'sanity/router'
|
|
|
4
4
|
import type {ToolMenuProps} from 'sanity'
|
|
5
5
|
import {InlinePopover} from '../../ui/Popover'
|
|
6
6
|
import {KitProvider, useKitConfig} from '../../context/KitContext'
|
|
7
|
-
import {editableEnvironment, isPublicEnvironment, presentationPath, previewTargets, type PreviewPerspective} from '../../lib/studioLinks'
|
|
7
|
+
import {editableEnvironment, isPublicEnvironment, presentationPath, previewPathFromLocation, previewTargets, type PreviewPerspective} from '../../lib/studioLinks'
|
|
8
8
|
import {useOpenOnline} from '../../hooks/useOpenOnline'
|
|
9
9
|
import type {ConfigIssue, NcfEnvironment, ResolvedKitConfig} from '../../config/types'
|
|
10
10
|
import {EyeOpenIcon} from '@sanity/icons/EyeOpen'
|
|
@@ -52,7 +52,11 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
|
|
|
52
52
|
const openInStudio = (environment: NcfEnvironment, perspective: PreviewPerspective) => {
|
|
53
53
|
const target = editableEnvironment(environment, environments, config.previewUrl) ?? environment
|
|
54
54
|
const shown = isPublicEnvironment(environment, config.previewUrl) ? 'published' : perspective
|
|
55
|
-
|
|
55
|
+
// La page actuellement dans Presentation, pour la rouvrir sur l'autre
|
|
56
|
+
// environnement plutôt que de retomber sur l'accueil. `preview` porte une
|
|
57
|
+
// URL complète ; on n'en garde que le chemin, appliqué à la cible.
|
|
58
|
+
const current = typeof window === 'undefined' ? null : previewPathFromLocation(window.location.search)
|
|
59
|
+
const path = presentationPath(current ?? target.url, {environment: target, perspective: shown})
|
|
56
60
|
if (path) router.navigateUrl({path})
|
|
57
61
|
}
|
|
58
62
|
|
|
@@ -60,7 +64,8 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
|
|
|
60
64
|
// avec un laissez-passer : sans lui, la garde du site refuse l'accès, même à
|
|
61
65
|
// l'éditeur connecté. « Brouillons » passe par la route de bascule du site.
|
|
62
66
|
const openOnline = (environment: NcfEnvironment, perspective: PreviewPerspective) => {
|
|
63
|
-
|
|
67
|
+
const current = typeof window === 'undefined' ? null : previewPathFromLocation(window.location.search)
|
|
68
|
+
void open(environment, {perspective, path: current})
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
// En colonne dans le volet latéral, en ligne dans la barre : le menu des
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {LayoutProps} from 'sanity'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Textes d'aide (descriptions de champ) : plus petits, plus gris, en italique.
|
|
5
|
+
*
|
|
6
|
+
* Sanity les rend déjà discrets ; on accentue la hiérarchie pour que le
|
|
7
|
+
* libellé prime et que l'aide se lise comme une note. Elles portent toutes un
|
|
8
|
+
* `id="desc_…"` — un point d'accroche stable, préférable à un sélecteur de
|
|
9
|
+
* classe qui bougerait d'une version à l'autre.
|
|
10
|
+
*
|
|
11
|
+
* `!important` assumé : c'est une surcharge de thème voulue, qui doit gagner
|
|
12
|
+
* sur le style par défaut quel que soit l'ordre d'injection des feuilles.
|
|
13
|
+
*/
|
|
14
|
+
const CSS = `
|
|
15
|
+
[id^="desc_"] {
|
|
16
|
+
font-size: 0.72rem !important;
|
|
17
|
+
font-style: italic !important;
|
|
18
|
+
line-height: 1.45 !important;
|
|
19
|
+
opacity: 0.72;
|
|
20
|
+
}
|
|
21
|
+
`
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Posé sur `studio.components.layout` : rend le Studio tel quel, et ajoute la
|
|
25
|
+
* feuille de style. Un seul `<style>` pour tout le Studio.
|
|
26
|
+
*/
|
|
27
|
+
export function HelpTextStyle(props: LayoutProps) {
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
<style data-ncf="help-text">{CSS}</style>
|
|
31
|
+
{props.renderDefault(props)}
|
|
32
|
+
</>
|
|
33
|
+
)
|
|
34
|
+
}
|
package/src/version.ts
CHANGED