@nocode-factory/sanity-kit 2.70.2 → 2.70.4-rc.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocode-factory/sanity-kit",
3
- "version": "2.70.2",
3
+ "version": "2.70.4-rc.1",
4
4
  "description": "Outils Studio de NoCode Factory : Pages (liste + board), Composants, Historique",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -29,7 +29,7 @@ export function upgradePrompt(latest: string | null): string {
29
29
  `1. From studio/, run \`${UPGRADE_COMMAND}\` (never a plain npm install: it shows nothing of what is left to do).`,
30
30
  `2. Wire everything it lists under "À brancher dans le projet", taking the code from the starter (nocode-factory/sanity-next-starter).`,
31
31
  `3. Fix every ✖ reported by \`npx ncf-kit doctor\` until there are none (list items without _type: \`npx ncf-kit item-types\`, then \`--apply\`).`,
32
- `4. Typecheck and build web/, deploy the Studio (\`npm run deploy\` in studio/), push a branch to preprod (not main), then tell me in plain words what changed and what to check.`,
32
+ `4. Typecheck and build web/, deploy the Studio (\`npm run deploy\` in studio/), commit on \`preprod\` and push \`preprod\` (never another branch, never \`main\`: production only after my explicit validation), then tell me in plain words what changed and what to check.`,
33
33
  ].join('\n')
34
34
  }
35
35
 
package/src/index.ts CHANGED
@@ -536,4 +536,4 @@ export type {AnnotationsState} from './hooks/useAnnotations'
536
536
  export type {PathInput} from './lib/paths'
537
537
 
538
538
  export {ncfMainDocuments} from './lib/mainDocuments'
539
- export type {MainDocumentRoute} from './lib/mainDocuments'
539
+ export type {MainDocumentRoute, MainDocumentContext} from './lib/mainDocuments'
@@ -2,10 +2,22 @@ import type {NcfKitConfig} from '../config/types'
2
2
  import {resolveConfig} from '../config/resolve'
3
3
  import type {SiteRoutesRegistry} from './siteRoutes'
4
4
 
5
+ /**
6
+ * Contexte passé par Presentation à `resolve`. Le type de Sanity annonce des textes,
7
+ * mais un paramètre répété (`:slug+`) arrive en LISTE de segments (Sanity >= 6.24).
8
+ */
9
+ export interface MainDocumentContext {
10
+ params: Record<string, string | string[] | undefined>
11
+ }
12
+
5
13
  /** Une entrée de `presentationTool({resolve: {mainDocuments: defineDocuments([...])}})`. */
6
- export interface MainDocumentRoute {
7
- route: string
8
- filter: string
14
+ export type MainDocumentRoute =
15
+ | {route: string; filter: string}
16
+ | {route: string; resolve: (ctx: MainDocumentContext) => {filter: string; params: Record<string, string>}}
17
+
18
+ /** `$slug` en texte : segments d'un paramètre répété recollés par « / ». */
19
+ export function slugParam(value: string | string[] | undefined): string {
20
+ return Array.isArray(value) ? value.join('/') : (value ?? '')
9
21
  }
10
22
 
11
23
  const SAFE = /^[A-Za-z0-9_.-]+$/
@@ -78,11 +90,14 @@ export function ncfMainDocuments(
78
90
  }
79
91
  for (const [base, types] of byBase) {
80
92
  const match = types.map((t) => `(_type == ${quote(t.type)} && ${t.slugField}.current == $slug)`)
81
- // `:slug+` : un slug peut avoir plusieurs niveaux (« telecom/projets ») ; la valeur
82
- // transmise à $slug est alors le slug complet (URLPattern de Presentation).
93
+ const filter = types.length === 1 && types[0] ? `_type == ${quote(types[0].type)} && ${types[0].slugField}.current == $slug${lang}` : `(${match.join(' || ')})${lang}`
94
+ // `:slug+` : un slug peut avoir plusieurs niveaux (« telecom/projets »). Sanity
95
+ // (>= 6.24) passe ce paramètre répété en LISTE de segments (["about-us"]) : sans
96
+ // les recoller, `slug.current == $slug` ne trouve rien, le document principal vaut
97
+ // null et Presentation plante (« reading '_id' »). Un texte reste inchangé.
83
98
  out.push({
84
99
  route: at(`${base}/:slug+`),
85
- filter: types.length === 1 && types[0] ? `_type == ${quote(types[0].type)} && ${types[0].slugField}.current == $slug${lang}` : `(${match.join(' || ')})${lang}`,
100
+ resolve: (ctx) => ({filter, params: {slug: slugParam(ctx.params.slug)}}),
86
101
  })
87
102
  }
88
103
  }
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
4
4
  * le vérifie.
5
5
  */
6
- export const KIT_VERSION = '2.70.2'
6
+ export const KIT_VERSION = '2.70.4-rc.1'