@nocode-factory/sanity-kit 2.37.0 → 2.37.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 CHANGED
@@ -1,306 +1,7 @@
1
- import { a as defineComponentDefaults, i as defaultsFieldName, n as componentDefaultsMainDocument, o as requiredUnlessDefault, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-CNiuukLt.js";
1
+ import { A as ResolvedI18n, C as NcfPageTypeConfig, D as ResolvedComponentPreview, E as NcfToolsConfig, M as ResolvedPageType, O as ResolvedDocumentColumn, S as NcfKitConfig, T as NcfToolName, _ as NcfEnvironment, a as componentDefaultsMainDocument, b as NcfInternalField, c as defineComponentDefaults, d as ConfigIssue, f as IssueLevel, g as NcfDocumentColumn, h as NcfComponentPreviewConfig, i as DEFAULT_COMPONENT_DEFAULTS_TYPE, j as ResolvedKitConfig, k as ResolvedHistory, l as requiredUnlessDefault, m as NcfBoardTag, n as fixCrossLanguageReferences, o as componentDefaultsMainDocuments, p as KitContextValue, r as withSameLanguageReferences, s as defaultsFieldName, t as CrossLanguageReport, u as requiredUnlessDefaultFor, v as NcfHistoryConfig, w as NcfPageTypeInput, x as NcfInternalFieldOption, y as NcfI18nConfig } from "./fixCrossLanguageReferences-D4phJn84.js";
2
2
  import { ComponentType, ReactNode } from "react";
3
3
  import { SanityClient, Schema, Tool, ToolMenuProps } from "sanity";
4
4
  import { PreviewHeaderProps } from "sanity/presentation";
5
- /**
6
- * Configuration publique du plugin. Tout est optionnel sauf `pageTypes` :
7
- * le kit ne doit rien savoir du contenu d'un projet client.
8
- */
9
- /** Un type de document considéré comme une page du site. */
10
- interface NcfPageTypeInput {
11
- /** Nom du type de document Sanity (ex. 'page'). */
12
- type: string;
13
- /**
14
- * Champ de type `slug` portant l'URL. Hérite de `slugField` global.
15
- * Mettre à `null` pour un type sans slug : `path` devient obligatoire.
16
- */
17
- slugField?: string | null;
18
- /**
19
- * Chemin fixe, pour les pages sans slug (ex. l'accueil : '/').
20
- * Prioritaire sur `slugField` quand les deux sont renseignés.
21
- */
22
- path?: string;
23
- /**
24
- * Préfixe d'URL placé devant le slug, pour les collections servies sous un
25
- * répertoire : `pathPrefix: '/blog'` donne `/blog/<slug>`. Sans effet avec
26
- * `path`. C'est la clé `pathPrefix` du registre `site-routes.json` du starter.
27
- */
28
- pathPrefix?: string;
29
- /** Champ portant le titre affiché. Hérite de `titleField` global. */
30
- titleField?: string;
31
- }
32
- type NcfPageTypeConfig = string | NcfPageTypeInput;
33
- /** Sites multilingues (ex. @sanity/document-internationalization). */
34
- interface NcfI18nConfig {
35
- /** Champ portant le code de langue sur le document. */
36
- field?: string;
37
- /** Langue servie à la racine, sans préfixe d'URL. */
38
- defaultLocale?: string;
39
- /** Langues attendues. Vide = déduites des documents rencontrés. */
40
- locales?: string[];
41
- /**
42
- * Langue SOURCE des valeurs par défaut des composants (défaut : `en` si le site
43
- * l'a, sinon la langue principale). Publier ses valeurs par défaut propose de
44
- * retraduire celles des autres langues ; un champ qui hérite d'une valeur par
45
- * défaut non traduite propose « Translate default with AI ».
46
- */
47
- defaultsSourceLocale?: string;
48
- }
49
- /**
50
- * Aperçu visuel des blocs du page builder. Aujourd'hui un seul fournisseur :
51
- * la page « design system » du front, avec les captures générées par la CI.
52
- * Storybook viendra s'ajouter ici le jour où un projet en aura un.
53
- */
54
- interface NcfComponentPreviewConfig {
55
- provider?: 'designSystemPage' | 'none';
56
- /** Chemin de la page de démonstration, relatif à `previewUrl`. */
57
- path?: string;
58
- /** Ancre vers le bloc sur cette page. Gabarit : {name} / {kebab}. */
59
- anchor?: string;
60
- /** Chemin de la capture, relatif à `previewUrl`. Gabarit : {name} / {kebab}. */
61
- thumbnail?: string;
62
- /**
63
- * Type du document des valeurs par défaut des composants (un champ par
64
- * composant, nommé `{name}`). Présent dans le schéma : un clic sur un composant
65
- * ouvre Presentation avec son rendu réel et ses valeurs par défaut côte à côte.
66
- */
67
- defaultsType?: string;
68
- /** Page qui rend un composant seul, avec ses valeurs par défaut. Gabarit : {name} / {kebab}. */
69
- live?: string;
70
- }
71
- /** Journal des modifications (phase 2). */
72
- interface NcfHistoryConfig {
73
- /**
74
- * Clé de lecture du projet, écrite dans `studio/.env` par `npx ncf-kit setup`
75
- * (variable `SANITY_STUDIO_NCF_PROJECT_KEY`). Elle voyage dans le bundle du
76
- * Studio : imprévisible, pas confidentielle. Jamais une clé d'écriture.
77
- * Vide ou absente : l'onglet Historique explique comment l'obtenir.
78
- */
79
- projectKey?: string;
80
- /** Base des Edge Functions. Par défaut, le service du kit. */
81
- endpoint?: string;
82
- }
83
- /** Étiquette de suivi posable sur une page dans le board. */
84
- interface NcfBoardTag {
85
- /** Identifiant stable, enregistré dans le document de disposition. */
86
- id: string;
87
- label: string;
88
- /** Couleur CSS de la pastille et de la bordure du nœud. */
89
- color: string;
90
- }
91
- /** Choix possible d'un champ de gestion interne de type « select ». */
92
- interface NcfInternalFieldOption {
93
- id: string;
94
- label: string;
95
- /** Couleur de la pastille. Sans elle, le choix s'affiche en texte. */
96
- color?: string;
97
- }
98
- /**
99
- * Champ de suivi éditorial, libre. Autant qu'on veut : responsable, cible,
100
- * rôle de la page… Ces valeurs vivent dans le document du kit, jamais dans le
101
- * schéma du client.
102
- */
103
- interface NcfInternalField {
104
- /** Identifiant stable, enregistré avec la valeur. */
105
- id: string;
106
- label: string;
107
- /** `text` par défaut. `select` exige `options`. */
108
- type?: 'text' | 'select';
109
- options?: NcfInternalFieldOption[];
110
- }
111
- /**
112
- * Donnée du document de la page, affichable telle quelle dans une colonne.
113
- *
114
- * Réservé aux valeurs qui tiennent sur une ligne : une meta description, un
115
- * booléen d'indexabilité, une date. Surtout pas un tableau de sections, qu'on
116
- * ne saurait pas rendre dans une cellule.
117
- */
118
- interface NcfDocumentColumn {
119
- /** Identifiant stable. Lettres, chiffres et tirets. */
120
- key: string;
121
- label: string;
122
- /** Chemins essayés dans l'ordre, le premier renseigné gagne. */
123
- path: string | string[];
124
- /** `text` par défaut. `boolean` affiche Oui/Non. */
125
- type?: 'text' | 'boolean' | 'number';
126
- }
127
- /**
128
- * Une version du front déployée quelque part : production, préproduction,
129
- * branche de recette.
130
- *
131
- * Le code change d'un environnement à l'autre, **pas les données** : c'est
132
- * toujours le même dataset qu'on regarde. Voir le contenu de production dans
133
- * le front d'une branche est justement l'intérêt.
134
- */
135
- interface NcfEnvironment {
136
- /** Identifiant stable, retenu d'une session à l'autre. */
137
- id: string;
138
- label: string;
139
- /** Base URL du front, sans slash final. */
140
- url: string;
141
- }
142
- interface NcfToolsConfig {
143
- pages?: boolean;
144
- components?: boolean;
145
- history?: boolean;
146
- /** Bouton « Design system » : ouvre la page /design-system dans Presentation. */
147
- designSystem?: boolean;
148
- }
149
- interface NcfKitConfig {
150
- /** Types de documents traités comme des pages. Au moins un. */
151
- pageTypes: NcfPageTypeConfig[];
152
- /** Champ tableau du page builder. */
153
- pageBuilderField?: string;
154
- /**
155
- * Préfixe commun aux types de blocs, retiré pour l'affichage et les gabarits
156
- * d'URL. Ex. 'section.' pour des blocs nommés `section.hero`.
157
- */
158
- blockNamespace?: string;
159
- /** Champ slug par défaut des `pageTypes`. */
160
- slugField?: string;
161
- /** Champ titre par défaut des `pageTypes`. */
162
- titleField?: string;
163
- /**
164
- * Champ booléen marquant une page comme non indexable. Plusieurs chemins
165
- * sont essayés dans l'ordre, le premier renseigné gagne.
166
- * Défaut : `['seo.noindex', 'noindex']`.
167
- */
168
- noindexField?: string | string[];
169
- /** Base URL du front, sans slash final. */
170
- previewUrl?: string;
171
- /**
172
- * Fronts déployés entre lesquels basculer dans l'aperçu. Sans eux, le seul
173
- * environnement proposé est `previewUrl`.
174
- *
175
- * Leurs origines doivent figurer dans `allowOrigins` de `presentationTool` :
176
- * `ncfAllowedOrigins(config)` les produit.
177
- */
178
- environments?: NcfEnvironment[];
179
- /**
180
- * `false` retire la préproduction déduite par convention
181
- * (`preview-<projet>.vercel.app`). Utile pour un projet qui n'en a pas.
182
- */
183
- preprodUrl?: false;
184
- /**
185
- * Gabarit d'URL de la capture d'une page, pour afficher la page entière dans
186
- * le board plutôt qu'une iframe tronquée. Variables : {slug} (chemin sans
187
- * slash de tête, avec des tirets), {locale}, {id}.
188
- *
189
- * Chemin relatif à `previewUrl` (« /pages/{slug}.png ») ou URL absolue.
190
- * Vide : le board retombe sur l'aperçu iframe en direct.
191
- */
192
- pageThumbnail?: string;
193
- /** `false` (défaut) pour un site monolingue. */
194
- i18n?: NcfI18nConfig | false;
195
- componentPreview?: NcfComponentPreviewConfig;
196
- history?: NcfHistoryConfig;
197
- /**
198
- * Base des Edge Functions du kit, pour l'enregistrement et l'historique.
199
- * `false` coupe tout appel sortant, y compris le signalement de présence.
200
- */
201
- serviceEndpoint?: string | false;
202
- /** Permet de n'activer qu'une partie des outils. */
203
- tools?: NcfToolsConfig;
204
- /**
205
- * Outils techniques rangés dans le menu « Plus » de la barre du Studio, pour ne
206
- * pas encombrer le marketing. Par défaut : Vision et la planification
207
- * (« Scheduled drafts » / Releases, nom d'outil `releases`). `false` : aucun.
208
- */
209
- moreTools?: string[] | false;
210
- /**
211
- * Étiquettes de suivi du board. Remplacent entièrement les valeurs par
212
- * défaut quand elles sont fournies.
213
- */
214
- boardTags?: NcfBoardTag[];
215
- /**
216
- * Colonnes de l'onglet « Gestion interne » de la liste des pages.
217
- * Remplacent entièrement les valeurs par défaut quand elles sont fournies.
218
- */
219
- internalFields?: NcfInternalField[];
220
- /**
221
- * Données du document affichables en colonne, proposées dans le sélecteur de
222
- * colonnes. Masquées tant que personne ne les coche.
223
- * Défaut : meta description, titre SEO, indexabilité.
224
- */
225
- documentColumns?: NcfDocumentColumn[];
226
- }
227
- interface ResolvedPageType {
228
- type: string;
229
- slugField: string | null;
230
- path: string | null;
231
- /** Préfixe normalisé ('/blog'), `null` pour une collection à la racine. */
232
- pathPrefix: string | null;
233
- titleField: string;
234
- }
235
- interface ResolvedI18n {
236
- field: string;
237
- defaultLocale: string;
238
- locales: string[];
239
- defaultsSourceLocale: string;
240
- }
241
- interface ResolvedComponentPreview {
242
- provider: 'designSystemPage' | 'none';
243
- path: string;
244
- anchor: string;
245
- thumbnail: string;
246
- defaultsType: string;
247
- live: string;
248
- }
249
- interface ResolvedKitConfig {
250
- pageTypes: ResolvedPageType[];
251
- pageTypeNames: string[];
252
- pageBuilderField: string;
253
- blockNamespace: string;
254
- noindexFields: string[];
255
- previewUrl: string | null;
256
- environments: NcfEnvironment[];
257
- pageThumbnail: string | null;
258
- i18n: ResolvedI18n | null;
259
- componentPreview: ResolvedComponentPreview;
260
- history: ResolvedHistory | null;
261
- /** `null` quand on a explicitement coupé les appels sortants. */
262
- serviceEndpoint: string | null;
263
- tools: Required<NcfToolsConfig>;
264
- /** Outils rangés dans le menu « Plus » de la barre (noms d'outils). */
265
- moreTools: string[];
266
- boardTags: NcfBoardTag[];
267
- internalFields: NcfInternalField[];
268
- documentColumns: ResolvedDocumentColumn[];
269
- }
270
- interface ResolvedHistory {
271
- projectKey: string;
272
- endpoint: string;
273
- }
274
- interface ResolvedDocumentColumn {
275
- key: string;
276
- label: string;
277
- /** Chemins retenus, nettoyés. */
278
- paths: string[];
279
- type: 'text' | 'boolean' | 'number';
280
- /**
281
- * Inverse un booléen à l'affichage. Sert à `noindex`, qu'on veut lire
282
- * « Indexable : oui » plutôt que « Noindex : non ».
283
- */
284
- invert?: boolean;
285
- }
286
- type IssueLevel = 'error' | 'warning';
287
- /**
288
- * Un problème de configuration. `error` neutralise l'outil concerné (mais pas
289
- * le Studio) ; `warning` laisse l'outil fonctionner en mode dégradé.
290
- */
291
- interface ConfigIssue {
292
- level: IssueLevel;
293
- /** Chemin de l'option fautive, ex. 'pageTypes[1].slugField'. */
294
- path: string;
295
- message: string;
296
- /** Quels outils sont concernés. Vide = tous. */
297
- tools?: NcfToolName[];
298
- }
299
- type NcfToolName = 'pages' | 'components' | 'history' | 'designSystem';
300
- interface KitContextValue {
301
- config: ResolvedKitConfig;
302
- issues: ConfigIssue[];
303
- }
304
5
  /** Garantit un chemin absolu ('accueil' -> '/accueil', '' -> '/'). */
305
6
  export declare const normalizePath: (path: string) => string;
306
7
  /** Applique les valeurs par défaut. Ne valide rien : voir `validateConfig`. */
@@ -1134,55 +835,6 @@ interface PreviewTargetState {
1134
835
  isProduction: boolean;
1135
836
  }
1136
837
  export declare function usePreviewTarget(): PreviewTargetState;
1137
- /**
1138
- * RÈGLE D'OR DU MULTILINGUE : une référence ne propose que des documents de la
1139
- * MÊME langue que le document en cours (un article EN ne voit que les catégories EN,
1140
- * une page FR que les pages FR). Les documents sans langue (logos, régions, assets…)
1141
- * restent proposés. Un document commun à toutes les langues (Navigation…) vise la
1142
- * langue principale.
1143
- *
1144
- * Pose ce filtre sur TOUS les champs de référence des types donnés (champs, listes,
1145
- * objets imbriqués, annotations du texte riche), combiné avec un filtre déjà présent.
1146
- * À appliquer aux types du projet :
1147
- *
1148
- * ```ts
1149
- * schema: {types: withSameLanguageReferences(schemaTypes, ncfOptions)}
1150
- * ```
1151
- */
1152
- export declare function withSameLanguageReferences<T>(types: T[], options: Pick<NcfKitConfig, 'i18n'>): T[];
1153
- interface CrossLanguageReport {
1154
- /** Références repointées (ou à repointer en simulation). */
1155
- fixed: {
1156
- documentId: string;
1157
- path: string;
1158
- from: string;
1159
- to: string;
1160
- }[];
1161
- /** Références croisées sans équivalent dans la langue du document (laissées). */
1162
- missing: {
1163
- documentId: string;
1164
- path: string;
1165
- ref: string;
1166
- language: string;
1167
- }[];
1168
- }
1169
- /**
1170
- * RÈGLE D'OR DU MULTILINGUE, côté données : chaque référence d'un document vise un
1171
- * document de SA langue (document sans langue : la langue principale). Une
1172
- * référence croisée est repointée vers la traduction de la bonne langue (liens de
1173
- * traduction) ; sans traduction, elle est signalée et laissée. Publiés et
1174
- * brouillons. `apply: false` : simulation.
1175
- *
1176
- * ```ts
1177
- * // studio/scripts/references-same-language.ts (sanity exec --with-user-token)
1178
- * const report = await fixCrossLanguageReferences(getCliClient(...), {defaultLocale: 'fr', apply})
1179
- * ```
1180
- */
1181
- export declare function fixCrossLanguageReferences(client: SanityClient, options: {
1182
- field?: string;
1183
- defaultLocale: string;
1184
- apply?: boolean;
1185
- }): Promise<CrossLanguageReport>;
1186
838
  /**
1187
839
  * Bascule brouillons / en ligne, posée dans l'aperçu lui-même.
1188
840
  *
@@ -1438,7 +1090,7 @@ export declare function ActorName(props: {
1438
1090
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1439
1091
  * le vérifie.
1440
1092
  */
1441
- export declare const KIT_VERSION = "2.37.0";
1093
+ export declare const KIT_VERSION = "2.37.1";
1442
1094
  /**
1443
1095
  * Données de la page proposées comme colonnes.
1444
1096
  *
@@ -1934,5 +1586,5 @@ export declare const NCF_HISTORY_TOOL = "ncf-history";
1934
1586
  export declare const NCF_DESIGN_SYSTEM_TOOL = "ncf-design-system";
1935
1587
  export declare const NCF_TOOL_NAMES: readonly ["ncf-pages", "ncf-components", "ncf-history", "ncf-design-system"];
1936
1588
  export declare const ncfKit: import("sanity").Plugin<NcfKitConfig>;
1937
- export { type AddColumnInput, type Annotation, type AnnotationsState, type BlockOccurrence, type BlockTypeInfo, type BoardEdge, type BoardGraph, type BoardLayoutState, type BoardNode, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, type Change, type ChangeKind, type CollectedLinks, type ColorBy, type ColorOptions, type ConfigIssue, type CrossLanguageReport, DEFAULT_COMPONENT_DEFAULTS_TYPE, type DeriveOptions, type GroupBy, type GroupOptions, type HistoryDetail, type HistoryEvent, type IssueLevel, type KitContextValue, type KitUpdate, type LayoutMode, type MainDocumentRoute, type MergedDoc, type NcfBoardTag, type NcfComponentPreviewConfig, type NcfDocumentColumn, type NcfEnvironment, type NcfHistoryConfig, type NcfI18nConfig, type NcfInternalField, type NcfInternalFieldOption, type NcfKitConfig, type NcfPageTypeConfig, type NcfPageTypeInput, type NcfToolName, type NcfToolsConfig, type NodeLayout, type NodePosition, type OccurrenceInput, type OccurrencePage, type OccurrencesState, type PageContent, type PageContentsState, type PageDoc, type PageFilters, type PageRow, type PageStatus, type PagesState, type PathInput, type Positioned, type PresentationOptions, type PreviewGrant, type PreviewPerspective, type PreviewTargetState, type ProjectStatus, type Registration, type ResolvedComponentPreview, type ResolvedDocumentColumn, type ResolvedHistory, type ResolvedI18n, type ResolvedKitConfig, type ResolvedPageType, type RowColor, type RowGroup, type SchemaFieldLike, type SchemaTypeLike, type SectionLayout, type SectionMapNode, type SectionOrder, type SectionsMapOptions, type Segment, type SiteRoutesRegistry, type SortDirection, type SortKey, type ThumbnailInput, type VersionedDoc, componentDefaultsMainDocument, componentDefaultsMainDocuments, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
1589
+ export { type AddColumnInput, type Annotation, type AnnotationsState, type BlockOccurrence, type BlockTypeInfo, type BoardEdge, type BoardGraph, type BoardLayoutState, type BoardNode, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, type Change, type ChangeKind, type CollectedLinks, type ColorBy, type ColorOptions, type ConfigIssue, type CrossLanguageReport, DEFAULT_COMPONENT_DEFAULTS_TYPE, type DeriveOptions, type GroupBy, type GroupOptions, type HistoryDetail, type HistoryEvent, type IssueLevel, type KitContextValue, type KitUpdate, type LayoutMode, type MainDocumentRoute, type MergedDoc, type NcfBoardTag, type NcfComponentPreviewConfig, type NcfDocumentColumn, type NcfEnvironment, type NcfHistoryConfig, type NcfI18nConfig, type NcfInternalField, type NcfInternalFieldOption, type NcfKitConfig, type NcfPageTypeConfig, type NcfPageTypeInput, type NcfToolName, type NcfToolsConfig, type NodeLayout, type NodePosition, type OccurrenceInput, type OccurrencePage, type OccurrencesState, type PageContent, type PageContentsState, type PageDoc, type PageFilters, type PageRow, type PageStatus, type PagesState, type PathInput, type Positioned, type PresentationOptions, type PreviewGrant, type PreviewPerspective, type PreviewTargetState, type ProjectStatus, type Registration, type ResolvedComponentPreview, type ResolvedDocumentColumn, type ResolvedHistory, type ResolvedI18n, type ResolvedKitConfig, type ResolvedPageType, type RowColor, type RowGroup, type SchemaFieldLike, type SchemaTypeLike, type SectionLayout, type SectionMapNode, type SectionOrder, type SectionsMapOptions, type Segment, type SiteRoutesRegistry, type SortDirection, type SortKey, type ThumbnailInput, type VersionedDoc, componentDefaultsMainDocument, componentDefaultsMainDocuments, defaultsFieldName, defineComponentDefaults, fixCrossLanguageReferences, requiredUnlessDefault, requiredUnlessDefaultFor, withSameLanguageReferences };
1938
1590
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as DEFAULT_TOOLBAR_MORE, a as defineComponentDefaults, c as DEFAULT_BOARD_TAGS, d as DEFAULT_INTERNAL_FIELDS, f as DEFAULT_NOINDEX_FIELDS, g as DEFAULT_TITLE_FIELD, h as DEFAULT_SLUG_FIELD, i as defaultsFieldName, l as DEFAULT_COMPONENT_PREVIEW, n as componentDefaultsMainDocument, o as requiredUnlessDefault, p as DEFAULT_PAGE_BUILDER_FIELD, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE, u as DEFAULT_I18N, v as DEFAULT_TOOLS } from "./componentDefaults-CelL5Ain.js";
1
+ import { _ as DEFAULT_SLUG_FIELD, a as componentDefaultsMainDocuments, b as DEFAULT_TOOLS, c as requiredUnlessDefault, d as DEFAULT_COMPONENT_PREVIEW, f as DEFAULT_I18N, h as DEFAULT_PAGE_BUILDER_FIELD, i as componentDefaultsMainDocument, l as requiredUnlessDefaultFor, m as DEFAULT_NOINDEX_FIELDS, n as withSameLanguageReferences, o as defaultsFieldName, p as DEFAULT_INTERNAL_FIELDS, r as DEFAULT_COMPONENT_DEFAULTS_TYPE, s as defineComponentDefaults, t as fixCrossLanguageReferences, u as DEFAULT_BOARD_TAGS, v as DEFAULT_TITLE_FIELD, y as DEFAULT_TOOLBAR_MORE } from "./fixCrossLanguageReferences-CagQ_Vvk.js";
2
2
  import { createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
3
  import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, usePerspective, useSchema, useSetPerspective, useUser, useWorkspace } from "sanity";
4
4
  import { ClockIcon } from "@sanity/icons/Clock";
@@ -1384,7 +1384,7 @@ function explainGrantError(error) {
1384
1384
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1385
1385
  * le vérifie.
1386
1386
  */
1387
- const KIT_VERSION = "2.37.0";
1387
+ const KIT_VERSION = "2.37.1";
1388
1388
  /**
1389
1389
  * Signale ce Studio au service du kit, une fois par montage.
1390
1390
  *
@@ -1727,7 +1727,7 @@ function useKitUpdate() {
1727
1727
  !controller.signal.aborted && body?.version && setLatest(body.version);
1728
1728
  }).catch(() => {}), () => controller.abort();
1729
1729
  }, []);
1730
- let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.37.0") > 0);
1730
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.37.1") > 0);
1731
1731
  return {
1732
1732
  current: KIT_VERSION,
1733
1733
  latest,
@@ -2960,22 +2960,22 @@ async function localizeReferences(client, value, language) {
2960
2960
  for (let row of rows ?? []) row?.from && row.to && row.to !== row.from && map.set(row.from, row.to);
2961
2961
  return map.size ? replaceRefs(value, map) : value;
2962
2962
  }
2963
- const isObj$3 = (v) => typeof v == "object" && !!v && !Array.isArray(v);
2963
+ const isObj$1 = (v) => typeof v == "object" && !!v && !Array.isArray(v);
2964
2964
  /** Textes d'une valeur, dans l'ordre. */
2965
2965
  function collectTexts$1(value) {
2966
2966
  if (typeof value == "string") return [value];
2967
2967
  if (!Array.isArray(value)) return [];
2968
2968
  let out = [];
2969
2969
  for (let item of value) if (typeof item == "string") out.push(item);
2970
- else if (isObj$3(item) && Array.isArray(item.children)) for (let child of item.children) isObj$3(child) && typeof child.text == "string" && out.push(child.text);
2970
+ else if (isObj$1(item) && Array.isArray(item.children)) for (let child of item.children) isObj$1(child) && typeof child.text == "string" && out.push(child.text);
2971
2971
  return out;
2972
2972
  }
2973
2973
  /** La même valeur avec ses textes remplacés (dans l'ordre de `collectTexts`). */
2974
2974
  function replaceTexts(value, texts) {
2975
2975
  let i = 0, next = () => texts[i++] ?? "";
2976
- return typeof value == "string" ? next() : Array.isArray(value) ? value.map((item) => typeof item == "string" ? next() : isObj$3(item) && Array.isArray(item.children) ? {
2976
+ return typeof value == "string" ? next() : Array.isArray(value) ? value.map((item) => typeof item == "string" ? next() : isObj$1(item) && Array.isArray(item.children) ? {
2977
2977
  ...item,
2978
- children: item.children.map((child) => isObj$3(child) && typeof child.text == "string" ? {
2978
+ children: item.children.map((child) => isObj$1(child) && typeof child.text == "string" ? {
2979
2979
  ...child,
2980
2980
  text: next()
2981
2981
  } : child)
@@ -2988,14 +2988,14 @@ function parsePathKey(path) {
2988
2988
  return out;
2989
2989
  }
2990
2990
  function itemOf(list, key) {
2991
- return list.find((i) => isObj$3(i) && i._key === key) ?? (/^\d+$/.test(key) ? list[Number(key)] : void 0);
2991
+ return list.find((i) => isObj$1(i) && i._key === key) ?? (/^\d+$/.test(key) ? list[Number(key)] : void 0);
2992
2992
  }
2993
2993
  /** Valeur d'un document au chemin `sections[a].title`. */
2994
2994
  function valueAtKey(doc, path) {
2995
2995
  let cur = doc;
2996
2996
  for (let seg of parsePathKey(path)) {
2997
2997
  if (cur == null) return;
2998
- cur = "field" in seg ? isObj$3(cur) ? cur[seg.field] : void 0 : Array.isArray(cur) ? itemOf(cur, seg.item) : void 0;
2998
+ cur = "field" in seg ? isObj$1(cur) ? cur[seg.field] : void 0 : Array.isArray(cur) ? itemOf(cur, seg.item) : void 0;
2999
2999
  }
3000
3000
  return cur;
3001
3001
  }
@@ -3004,10 +3004,10 @@ function setAtKey(doc, path, value) {
3004
3004
  let segs = parsePathKey(path), cur = doc;
3005
3005
  for (let n = 0; n < segs.length - 1; n++) {
3006
3006
  let seg = segs[n];
3007
- if (cur = "field" in seg ? isObj$3(cur) ? cur[seg.field] : void 0 : Array.isArray(cur) ? itemOf(cur, seg.item) : void 0, cur == null) return !1;
3007
+ if (cur = "field" in seg ? isObj$1(cur) ? cur[seg.field] : void 0 : Array.isArray(cur) ? itemOf(cur, seg.item) : void 0, cur == null) return !1;
3008
3008
  }
3009
3009
  let last = segs[segs.length - 1];
3010
- return !last || !("field" in last) || !isObj$3(cur) ? !1 : (cur[last.field] = value, !0);
3010
+ return !last || !("field" in last) || !isObj$1(cur) ? !1 : (cur[last.field] = value, !0);
3011
3011
  }
3012
3012
  const MESSAGES = {
3013
3013
  daily_limit: "Daily AI translation limit reached for this project.",
@@ -3059,7 +3059,7 @@ const VALUE_TYPE_NAMES = /* @__PURE__ */ new Set([
3059
3059
  "datetime",
3060
3060
  "number",
3061
3061
  "boolean"
3062
- ]), SKIP_KEYS = /* @__PURE__ */ new Set(["language", "slug"]), isObj$2 = (v) => typeof v == "object" && !!v && !Array.isArray(v), same$2 = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null), keyed$1 = (v) => Array.isArray(v) && v.length > 0 && v.every((i) => isObj$2(i) && typeof i._key == "string");
3062
+ ]), SKIP_KEYS = /* @__PURE__ */ new Set(["language", "slug"]), isObj = (v) => typeof v == "object" && !!v && !Array.isArray(v), same$2 = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null), keyed$1 = (v) => Array.isArray(v) && v.length > 0 && v.every((i) => isObj(i) && typeof i._key == "string");
3063
3063
  function typeNames(t) {
3064
3064
  let out = [];
3065
3065
  for (let c = t; c; c = c.type) c.name && out.push(c.name);
@@ -3078,7 +3078,7 @@ function kindOf(t, value) {
3078
3078
  }
3079
3079
  return t.jsonType === "object" ? "object" : t.jsonType === "string" ? t.options?.list?.length ? "value" : "text" : "value";
3080
3080
  }
3081
- return keyed$1(value) ? "list" : isObj$2(value) ? "object" : "value";
3081
+ return keyed$1(value) ? "list" : isObj(value) ? "object" : "value";
3082
3082
  }
3083
3083
  function fieldType(t, name) {
3084
3084
  for (let c = t; c; c = c.type) {
@@ -3095,8 +3095,8 @@ function itemType(t, item) {
3095
3095
  function collectTexts(value, t, path, acc) {
3096
3096
  let kind = kindOf(t, value);
3097
3097
  if (kind === "text") value != null && value !== "" && acc.toTranslate.push(path);
3098
- else if (kind === "object" && isObj$2(value)) for (let [k, v] of Object.entries(value)) k.startsWith("_") || collectTexts(v, fieldType(t, k), `${path}.${k}`, acc);
3099
- else if (kind === "list" && Array.isArray(value)) for (let item of value) isObj$2(item) && collectTexts(item, itemType(t, item), `${path}[${String(item._key)}]`, acc);
3098
+ else if (kind === "object" && isObj(value)) for (let [k, v] of Object.entries(value)) k.startsWith("_") || collectTexts(v, fieldType(t, k), `${path}.${k}`, acc);
3099
+ else if (kind === "list" && Array.isArray(value)) for (let item of value) isObj(item) && collectTexts(item, itemType(t, item), `${path}[${String(item._key)}]`, acc);
3100
3100
  }
3101
3101
  const ABSENT$1 = Symbol("absent");
3102
3102
  function merge(target, before, after, t, path, acc) {
@@ -3105,8 +3105,8 @@ function merge(target, before, after, t, path, acc) {
3105
3105
  if (kind === "text") return after == null || after === "" ? (target != null && target !== "" && acc.toTranslate.push(path), target === void 0 ? ABSENT$1 : target) : (acc.toTranslate.push(path), target == null || target === "" || same$2(target, before) ? after : target);
3106
3106
  if (kind === "value") return acc.copied.push(path), after === void 0 ? ABSENT$1 : after;
3107
3107
  if (kind === "object") {
3108
- if (!isObj$2(after)) return acc.copied.push(path), after === void 0 ? ABSENT$1 : after;
3109
- let base = isObj$2(target) ? { ...target } : { _type: after._type }, b = isObj$2(before) ? before : {};
3108
+ if (!isObj(after)) return acc.copied.push(path), after === void 0 ? ABSENT$1 : after;
3109
+ let base = isObj(target) ? { ...target } : { _type: after._type }, b = isObj(before) ? before : {};
3110
3110
  for (let k of /* @__PURE__ */ new Set([...Object.keys(b), ...Object.keys(after)])) {
3111
3111
  if (k.startsWith("_") || SKIP_KEYS.has(k)) continue;
3112
3112
  let v = merge(base[k], b[k], after[k], fieldType(t, k), path ? `${path}.${k}` : k, acc);
@@ -3114,7 +3114,7 @@ function merge(target, before, after, t, path, acc) {
3114
3114
  }
3115
3115
  return base;
3116
3116
  }
3117
- let tgt = Array.isArray(target) ? target.filter(isObj$2) : [], bef = Array.isArray(before) ? before.filter(isObj$2) : [], aft = Array.isArray(after) ? after.filter(isObj$2) : [], byKey = (list) => new Map(list.map((i) => [i._key, i])), tMap = byKey(tgt), bMap = byKey(bef), aMap = byKey(aft), result = [];
3117
+ let tgt = Array.isArray(target) ? target.filter(isObj) : [], bef = Array.isArray(before) ? before.filter(isObj) : [], aft = Array.isArray(after) ? after.filter(isObj) : [], byKey = (list) => new Map(list.map((i) => [i._key, i])), tMap = byKey(tgt), bMap = byKey(bef), aMap = byKey(aft), result = [];
3118
3118
  for (let item of aft) {
3119
3119
  let key = item._key, it = itemType(t, item);
3120
3120
  if (tMap.has(key)) {
@@ -3148,7 +3148,7 @@ function propagate(target, before, after, documentType) {
3148
3148
  return {
3149
3149
  document: {
3150
3150
  ...target ?? {},
3151
- ...isObj$2(merged) ? merged : {}
3151
+ ...isObj(merged) ? merged : {}
3152
3152
  },
3153
3153
  ...acc
3154
3154
  };
@@ -9658,120 +9658,6 @@ function withMoreTool(tools, names = DEFAULT_MORE_TOOLS) {
9658
9658
  };
9659
9659
  return [...tools.filter((tool) => !names.includes(tool.name)), more];
9660
9660
  }
9661
- const isObj$1 = (v) => {
9662
- if (!v || typeof v != "object" || Array.isArray(v) || "$$typeof" in v) return !1;
9663
- let proto = Object.getPrototypeOf(v);
9664
- return proto === Object.prototype || proto === null;
9665
- };
9666
- /**
9667
- * RÈGLE D'OR DU MULTILINGUE : une référence ne propose que des documents de la
9668
- * MÊME langue que le document en cours (un article EN ne voit que les catégories EN,
9669
- * une page FR que les pages FR). Les documents sans langue (logos, régions, assets…)
9670
- * restent proposés. Un document commun à toutes les langues (Navigation…) vise la
9671
- * langue principale.
9672
- *
9673
- * Pose ce filtre sur TOUS les champs de référence des types donnés (champs, listes,
9674
- * objets imbriqués, annotations du texte riche), combiné avec un filtre déjà présent.
9675
- * À appliquer aux types du projet :
9676
- *
9677
- * ```ts
9678
- * schema: {types: withSameLanguageReferences(schemaTypes, ncfOptions)}
9679
- * ```
9680
- */
9681
- function withSameLanguageReferences(types, options) {
9682
- let i18n = options.i18n;
9683
- if (!i18n) return types;
9684
- let field = i18n.field ?? "language", fallback = i18n.defaultLocale ?? i18n.locales?.[0], condition = `(!defined(${field}) || ${field} == $ncfLanguage)`, languageOf = (document) => typeof document?.[field] == "string" && document[field] || fallback, wrap = (opts) => {
9685
- let previous = opts?.filter, previousParams = opts?.filterParams ?? {}, filter = async (context) => {
9686
- let base = typeof previous == "function" ? await previous(context) ?? {} : typeof previous == "string" ? {
9687
- filter: previous,
9688
- params: previousParams
9689
- } : {};
9690
- return {
9691
- filter: base.filter ? `(${base.filter}) && ${condition}` : condition,
9692
- params: {
9693
- ...base.params ?? {},
9694
- ncfLanguage: languageOf(context.document)
9695
- }
9696
- };
9697
- }, { filterParams: _ignored, ...rest } = opts ?? {};
9698
- return {
9699
- ...rest,
9700
- filter
9701
- };
9702
- }, visit = (node) => {
9703
- if (Array.isArray(node)) return node.map(visit);
9704
- if (!isObj$1(node)) return node;
9705
- let out = {};
9706
- for (let [key, value] of Object.entries(node)) out[key] = key === "options" || key === "initialValue" || key === "validation" ? value : visit(value);
9707
- return node.type === "reference" && Array.isArray(node.to) && (out.options = wrap(node.options)), out;
9708
- };
9709
- return types.map((t) => visit(t));
9710
- }
9711
- const isObj = (v) => !!v && typeof v == "object" && !Array.isArray(v), bare = (id) => id.replace(/^drafts\./, "");
9712
- /** Références d'une valeur, avec leur chemin de patch (`a.b[_key=="x"].c`). */
9713
- function refs(value, path, out) {
9714
- if (Array.isArray(value)) {
9715
- value.forEach((item, i) => refs(item, `${path}[${isObj(item) && typeof item._key == "string" ? `_key=="${item._key}"` : i}]`, out));
9716
- return;
9717
- }
9718
- if (isObj(value)) {
9719
- typeof value._ref == "string" && !/^(image|file)-/.test(value._ref) && out.push({
9720
- path: `${path}._ref`,
9721
- ref: value._ref
9722
- });
9723
- for (let [k, v] of Object.entries(value)) k.startsWith("_") || refs(v, path ? `${path}.${k}` : k, out);
9724
- }
9725
- }
9726
- /**
9727
- * RÈGLE D'OR DU MULTILINGUE, côté données : chaque référence d'un document vise un
9728
- * document de SA langue (document sans langue : la langue principale). Une
9729
- * référence croisée est repointée vers la traduction de la bonne langue (liens de
9730
- * traduction) ; sans traduction, elle est signalée et laissée. Publiés et
9731
- * brouillons. `apply: false` : simulation.
9732
- *
9733
- * ```ts
9734
- * // studio/scripts/references-same-language.ts (sanity exec --with-user-token)
9735
- * const report = await fixCrossLanguageReferences(getCliClient(...), {defaultLocale: 'fr', apply})
9736
- * ```
9737
- */
9738
- async function fixCrossLanguageReferences(client, options) {
9739
- let field = options.field ?? "language", c = client.withConfig({ perspective: "raw" }), docs = await c.fetch("*[!(_type match \"system.*\") && !(_type match \"sanity.*\") && !(_type match \"ncf.*\") && _type != \"translation.metadata\"]"), language = /* @__PURE__ */ new Map();
9740
- for (let d of docs) typeof d[field] == "string" && language.set(bare(String(d._id)), String(d[field]));
9741
- let metas = await c.fetch("*[_type == \"translation.metadata\"]{translations}"), equivalent = /* @__PURE__ */ new Map();
9742
- for (let m of metas) {
9743
- let group = /* @__PURE__ */ new Map();
9744
- for (let t of m.translations ?? []) t.value?._ref && group.set(t.language ?? t._key ?? "", t.value._ref);
9745
- for (let id of group.values()) equivalent.set(id, group);
9746
- }
9747
- let report = {
9748
- fixed: [],
9749
- missing: []
9750
- };
9751
- for (let d of docs) {
9752
- let own = typeof d[field] == "string" ? String(d[field]) : options.defaultLocale, found = [];
9753
- for (let [k, v] of Object.entries(d)) k.startsWith("_") || refs(v, k, found);
9754
- let set = {};
9755
- for (let { path, ref } of found) {
9756
- let target = language.get(bare(ref));
9757
- if (!target || target === own) continue;
9758
- let to = equivalent.get(bare(ref))?.get(own);
9759
- to ? (set[path] = to, report.fixed.push({
9760
- documentId: String(d._id),
9761
- path,
9762
- from: ref,
9763
- to
9764
- })) : report.missing.push({
9765
- documentId: String(d._id),
9766
- path,
9767
- ref,
9768
- language: own
9769
- });
9770
- }
9771
- options.apply && Object.keys(set).length && await c.patch(String(d._id)).ifRevisionId(String(d._rev)).set(set).commit({ visibility: "async" });
9772
- }
9773
- return report;
9774
- }
9775
9661
  /**
9776
9662
  * Bascule brouillons / en ligne, posée dans l'aperçu lui-même.
9777
9663
  *