@nocode-factory/sanity-kit 2.17.0 → 2.17.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/web.d.ts CHANGED
@@ -22,6 +22,6 @@ interface PreviewBannerProps {
22
22
  * Rendu hors production seulement : c'est à l'appelant de s'en assurer, avec
23
23
  * `isPreviewSite()`.
24
24
  */
25
- export declare function NcfPreviewBanner(props: PreviewBannerProps): import("react").JSX.Element;
25
+ export declare function NcfPreviewBanner(props: PreviewBannerProps): import("react").JSX.Element | null;
26
26
  export type { PreviewBannerProps };
27
27
  //# sourceMappingURL=web.d.ts.map
package/dist/web.js CHANGED
@@ -8,6 +8,19 @@ function readGrant() {
8
8
  let match = document.cookie.match(/* @__PURE__ */ RegExp("(?:^|; )ncf_preview_grant=([^;]*)"));
9
9
  return match?.[1] ? decodeURIComponent(match[1]) : null;
10
10
  }
11
+ /**
12
+ * Page affichée DANS le Studio (Presentation l'encastre dans un iframe) : le
13
+ * Studio a déjà sa propre bascule brouillons / en ligne, le bandeau ferait doublon
14
+ * et masquerait le bas de la page. Faux au rendu serveur (bandeau rendu), vrai
15
+ * dès l'hydratation dans un iframe (bandeau retiré).
16
+ */
17
+ const readEmbedded = () => {
18
+ try {
19
+ return window.self !== window.top;
20
+ } catch {
21
+ return !0;
22
+ }
23
+ };
11
24
  /** Adresse courante avec la clé de préversion (partageable telle quelle). */
12
25
  function shareableUrl(grant) {
13
26
  let url = new URL(window.location.href);
@@ -29,7 +42,7 @@ function shareableUrl(grant) {
29
42
  * `isPreviewSite()`.
30
43
  */
31
44
  function NcfPreviewBanner(props) {
32
- let { isDraft, togglePath = "/api/draft-mode/toggle", label = "Préversion" } = props, pathname = usePathname(), grant = useSyncExternalStore(noSubscribe, readGrant, () => null), [copied, setCopied] = useState(!1);
45
+ let { isDraft, togglePath = "/api/draft-mode/toggle", label = "Préversion" } = props, pathname = usePathname(), grant = useSyncExternalStore(noSubscribe, readGrant, () => null), [copied, setCopied] = useState(!1), embedded = useSyncExternalStore(noSubscribe, readEmbedded, () => !1);
33
46
  useEffect(() => {
34
47
  if (!grant) return;
35
48
  let url = new URL(window.location.href);
@@ -40,7 +53,7 @@ function NcfPreviewBanner(props) {
40
53
  await navigator.clipboard.writeText(shareableUrl(grant)), setCopied(!0), window.setTimeout(() => setCopied(!1), 2e3);
41
54
  } catch {}
42
55
  }, href = (enable) => `${togglePath}?enable=${enable}&redirect=${back}`;
43
- return /* @__PURE__ */ jsx("div", {
56
+ return embedded ? null : /* @__PURE__ */ jsx("div", {
44
57
  style: {
45
58
  ...anchor(props.position ?? "bottom-left"),
46
59
  zIndex: 2147483e3
package/dist/web.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","names":[],"sources":["../src/web/PreviewBanner.tsx"],"sourcesContent":["'use client'\n\nimport {usePathname} from 'next/navigation'\nimport {useEffect, useState, useSyncExternalStore, type CSSProperties} from 'react'\n\n/** Mêmes noms que le garde (`previewGrant.ts`), sans importer de code serveur. */\nconst GRANT_PARAM = 'ncf_preview'\nconst GRANT_COOKIE = 'ncf_preview_grant'\n\nconst noSubscribe = () => () => {}\nfunction readGrant(): string | null {\n const match = document.cookie.match(new RegExp(`(?:^|; )${GRANT_COOKIE}=([^;]*)`))\n return match?.[1] ? decodeURIComponent(match[1]) : null\n}\n\n/** Adresse courante avec la clé de préversion (partageable telle quelle). */\nfunction shareableUrl(grant: string): string {\n const url = new URL(window.location.href)\n url.searchParams.set(GRANT_PARAM, grant)\n return url.toString()\n}\n\nexport interface PreviewBannerProps {\n /** Le site affiche-t-il actuellement les brouillons ? */\n isDraft: boolean\n /** Chemin de la route de bascule. Défaut : `/api/draft-mode/toggle`. */\n togglePath?: string\n /** Libellé de l'environnement. Défaut : « Préversion ». */\n label?: string\n position?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'\n}\n\n/**\n * Bandeau des environnements de test : il dit où l'on est, et laisse choisir\n * ce qu'on regarde.\n *\n * Sur une préversion, la question du relecteur est toujours la même :\n * « qu'est-ce qui sortira quand je publierai ? ». Y répondre demande de voir\n * les brouillons sur le vrai site, pas dans un aperçu encastré.\n *\n * Les styles sont en ligne, délibérément. Des classes utilitaires obligeraient\n * chaque site à déclarer ce paquet dans ses globs de scan — une dépendance\n * invisible dont l'oubli ne se verrait qu'à l'exécution, par un bandeau nu.\n *\n * Rendu hors production seulement : c'est à l'appelant de s'en assurer, avec\n * `isPreviewSite()`.\n */\nexport function NcfPreviewBanner(props: PreviewBannerProps) {\n const {isDraft, togglePath = '/api/draft-mode/toggle', label = 'Préversion'} = props\n const pathname = usePathname()\n // Clé de préversion mémorisée par le garde (absente avec une session Presentation).\n const grant = useSyncExternalStore(noSubscribe, readGrant, () => null)\n const [copied, setCopied] = useState(false)\n\n // Après une navigation côté client, Next affiche l'URL du lien, sans la clé : on\n // la remet, pour que l'adresse copiée depuis la barre ouvre la préversion chez\n // n'importe qui (un client, sans compte).\n useEffect(() => {\n if (!grant) return\n const url = new URL(window.location.href)\n if (url.searchParams.get(GRANT_PARAM) === grant) return\n url.searchParams.set(GRANT_PARAM, grant)\n window.history.replaceState(window.history.state, '', url.toString())\n }, [grant, pathname])\n\n // Retour de bascule sur la même page, clé comprise.\n const backPath = grant ? `${pathname || '/'}?${GRANT_PARAM}=${encodeURIComponent(grant)}` : pathname || '/'\n const back = encodeURIComponent(backPath)\n\n const share = async () => {\n if (!grant) return\n try {\n await navigator.clipboard.writeText(shareableUrl(grant))\n setCopied(true)\n window.setTimeout(() => setCopied(false), 2000)\n } catch {\n // Presse-papiers refusé : l'adresse de la barre contient déjà la clé.\n }\n }\n\n const href = (enable: boolean) => `${togglePath}?enable=${enable}&redirect=${back}`\n\n return (\n <div style={{...anchor(props.position ?? 'bottom-left'), zIndex: 2147483000}}>\n <div style={shell}>\n <span style={{display: 'inline-flex', alignItems: 'center', gap: 6, fontWeight: 500}}>\n {/* Pastille pleine plutôt qu'un caractère décoratif : elle se lit à\n toutes les tailles et ne dépend d'aucune police. */}\n <span aria-hidden style={dot} />\n {label}\n </span>\n\n <span aria-hidden style={divider} />\n <span style={{opacity: 0.75}}>Données</span>\n\n <span role=\"group\" aria-label=\"Données affichées\" style={{display: 'inline-flex', gap: 2}}>\n <a\n href={href(true)}\n title=\"Ce qui sortira après publication\"\n aria-current={isDraft ? 'true' : undefined}\n style={isDraft ? segmentOn : segmentOff}\n >\n Brouillons\n </a>\n <a\n href={href(false)}\n title=\"Ce que voit le public aujourd'hui\"\n aria-current={isDraft ? undefined : 'true'}\n style={isDraft ? segmentOff : segmentOn}\n >\n En ligne\n </a>\n </span>\n\n {grant && (\n <>\n <span aria-hidden style={divider} />\n <button type=\"button\" onClick={share} title=\"Copier l'adresse de cette page, clé de préversion comprise\" style={shareButton}>\n {copied ? 'Lien copié' : 'Copier le lien'}\n </button>\n </>\n )}\n </div>\n </div>\n )\n}\n\nconst anchor = (position: NonNullable<PreviewBannerProps['position']>): CSSProperties => ({\n position: 'fixed',\n ...(position.startsWith('bottom') ? {bottom: 16} : {top: 16}),\n ...(position.endsWith('left') ? {left: 16} : {right: 16}),\n})\n\nconst shell: CSSProperties = {\n display: 'flex',\n alignItems: 'center',\n gap: 10,\n padding: '6px 12px',\n borderRadius: 999,\n // Ambre : la couleur des environnements de test, assez saturée pour ne pas\n // se confondre avec le site, assez sobre pour ne pas le masquer.\n background: '#fef3c7',\n color: '#451a03',\n border: '1px solid #fcd34d',\n boxShadow: '0 4px 16px rgba(0,0,0,0.14)',\n font: '500 12px/1 ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif',\n}\n\nconst dot: CSSProperties = {\n width: 7,\n height: 7,\n borderRadius: '50%',\n background: '#d97706',\n flex: 'none',\n}\n\nconst divider: CSSProperties = {width: 1, height: 14, background: '#00000022'}\n\nconst segmentBase: CSSProperties = {\n padding: '4px 10px',\n borderRadius: 999,\n textDecoration: 'none',\n fontSize: 12,\n lineHeight: 1,\n whiteSpace: 'nowrap',\n}\n\nconst segmentOn: CSSProperties = {...segmentBase, background: '#451a03', color: '#fffbeb'}\nconst segmentOff: CSSProperties = {...segmentBase, color: '#451a03', opacity: 0.7}\n\nconst shareButton: CSSProperties = {\n ...segmentBase,\n border: 'none',\n background: 'transparent',\n color: '#451a03',\n cursor: 'pointer',\n font: 'inherit',\n textDecoration: 'underline',\n textUnderlineOffset: 3,\n}\n"],"mappings":";;;;AAMA,MAAM,cAAc,eAGd,0BAA0B,CAAC;AACjC,SAAS,YAA2B;CAClC,IAAM,QAAQ,SAAS,OAAO,MAAM,gBAAI,OAAO,mCAAiC,CAAC;CACjF,OAAO,QAAQ,KAAK,mBAAmB,MAAM,EAAE,IAAI;AACrD;;AAGA,SAAS,aAAa,OAAuB;CAC3C,IAAM,MAAM,IAAI,IAAI,OAAO,SAAS,IAAI;CAExC,OADA,IAAI,aAAa,IAAI,aAAa,KAAK,GAChC,IAAI,SAAS;AACtB;;;;;;;;;;;;;;;;AA2BA,SAAgB,iBAAiB,OAA2B;CAC1D,IAAM,EAAC,SAAS,aAAa,0BAA0B,QAAQ,iBAAgB,OACzE,WAAW,YAAY,GAEvB,QAAQ,qBAAqB,aAAa,iBAAiB,IAAI,GAC/D,CAAC,QAAQ,aAAa,SAAS,EAAK;CAK1C,gBAAgB;EACd,IAAI,CAAC,OAAO;EACZ,IAAM,MAAM,IAAI,IAAI,OAAO,SAAS,IAAI;EACpC,IAAI,aAAa,IAAI,WAAW,MAAM,UAC1C,IAAI,aAAa,IAAI,aAAa,KAAK,GACvC,OAAO,QAAQ,aAAa,OAAO,QAAQ,OAAO,IAAI,IAAI,SAAS,CAAC;CACtE,GAAG,CAAC,OAAO,QAAQ,CAAC;CAGpB,IAAM,WAAW,QAAQ,GAAG,YAAY,IAAI,GAAG,YAAY,GAAG,mBAAmB,KAAK,MAAM,YAAY,KAClG,OAAO,mBAAmB,QAAQ,GAElC,QAAQ,YAAY;EACnB,WACL,IAAI;GAGF,AAFA,MAAM,UAAU,UAAU,UAAU,aAAa,KAAK,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I,SAAS,WAAW,QAAQ,IAAI,EAAC,QAAQ,GAAE,IAAI,EAAC,KAAK,GAAE;CAC3D,GAAI,SAAS,SAAS,MAAM,IAAI,EAAC,MAAM,GAAE,IAAI,EAAC,OAAO,GAAE;AACzD,IAEM,QAAuB;CAC3B,SAAS;CACT,YAAY;CACZ,KAAK;CACL,SAAS;CACT,cAAc;CAGd,YAAY;CACZ,OAAO;CACP,QAAQ;CACR,WAAW;CACX,MAAM;AACR,GAEM,MAAqB;CACzB,OAAO;CACP,QAAQ;CACR,cAAc;CACd,YAAY;CACZ,MAAM;AACR,GAEM,UAAyB;CAAC,OAAO;CAAG,QAAQ;CAAI,YAAY;AAAW,GAEvE,cAA6B;CACjC,SAAS;CACT,cAAc;CACd,gBAAgB;CAChB,UAAU;CACV,YAAY;CACZ,YAAY;AACd,GAEM,YAA2B;CAAC,GAAG;CAAa,YAAY;CAAW,OAAO;AAAS,GACnF,aAA4B;CAAC,GAAG;CAAa,OAAO;CAAW,SAAS;AAAG,GAE3E,cAA6B;CACjC,GAAG;CACH,QAAQ;CACR,YAAY;CACZ,OAAO;CACP,QAAQ;CACR,MAAM;CACN,gBAAgB;CAChB,qBAAqB;AACvB"}
1
+ {"version":3,"file":"web.js","names":[],"sources":["../src/web/PreviewBanner.tsx"],"sourcesContent":["'use client'\n\nimport {usePathname} from 'next/navigation'\nimport {useEffect, useState, useSyncExternalStore, type CSSProperties} from 'react'\n\n/** Mêmes noms que le garde (`previewGrant.ts`), sans importer de code serveur. */\nconst GRANT_PARAM = 'ncf_preview'\nconst GRANT_COOKIE = 'ncf_preview_grant'\n\nconst noSubscribe = () => () => {}\nfunction readGrant(): string | null {\n const match = document.cookie.match(new RegExp(`(?:^|; )${GRANT_COOKIE}=([^;]*)`))\n return match?.[1] ? decodeURIComponent(match[1]) : null\n}\n\n/**\n * Page affichée DANS le Studio (Presentation l'encastre dans un iframe) : le\n * Studio a déjà sa propre bascule brouillons / en ligne, le bandeau ferait doublon\n * et masquerait le bas de la page. Faux au rendu serveur (bandeau rendu), vrai\n * dès l'hydratation dans un iframe (bandeau retiré).\n */\nconst readEmbedded = () => {\n try {\n return window.self !== window.top\n } catch {\n // Accès refusé au parent : on est forcément encastré.\n return true\n }\n}\n\n/** Adresse courante avec la clé de préversion (partageable telle quelle). */\nfunction shareableUrl(grant: string): string {\n const url = new URL(window.location.href)\n url.searchParams.set(GRANT_PARAM, grant)\n return url.toString()\n}\n\nexport interface PreviewBannerProps {\n /** Le site affiche-t-il actuellement les brouillons ? */\n isDraft: boolean\n /** Chemin de la route de bascule. Défaut : `/api/draft-mode/toggle`. */\n togglePath?: string\n /** Libellé de l'environnement. Défaut : « Préversion ». */\n label?: string\n position?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'\n}\n\n/**\n * Bandeau des environnements de test : il dit où l'on est, et laisse choisir\n * ce qu'on regarde.\n *\n * Sur une préversion, la question du relecteur est toujours la même :\n * « qu'est-ce qui sortira quand je publierai ? ». Y répondre demande de voir\n * les brouillons sur le vrai site, pas dans un aperçu encastré.\n *\n * Les styles sont en ligne, délibérément. Des classes utilitaires obligeraient\n * chaque site à déclarer ce paquet dans ses globs de scan — une dépendance\n * invisible dont l'oubli ne se verrait qu'à l'exécution, par un bandeau nu.\n *\n * Rendu hors production seulement : c'est à l'appelant de s'en assurer, avec\n * `isPreviewSite()`.\n */\nexport function NcfPreviewBanner(props: PreviewBannerProps) {\n const {isDraft, togglePath = '/api/draft-mode/toggle', label = 'Préversion'} = props\n const pathname = usePathname()\n // Clé de préversion mémorisée par le garde (absente avec une session Presentation).\n const grant = useSyncExternalStore(noSubscribe, readGrant, () => null)\n const [copied, setCopied] = useState(false)\n const embedded = useSyncExternalStore(noSubscribe, readEmbedded, () => false)\n\n // Après une navigation côté client, Next affiche l'URL du lien, sans la clé : on\n // la remet, pour que l'adresse copiée depuis la barre ouvre la préversion chez\n // n'importe qui (un client, sans compte).\n useEffect(() => {\n if (!grant) return\n const url = new URL(window.location.href)\n if (url.searchParams.get(GRANT_PARAM) === grant) return\n url.searchParams.set(GRANT_PARAM, grant)\n window.history.replaceState(window.history.state, '', url.toString())\n }, [grant, pathname])\n\n // Retour de bascule sur la même page, clé comprise.\n const backPath = grant ? `${pathname || '/'}?${GRANT_PARAM}=${encodeURIComponent(grant)}` : pathname || '/'\n const back = encodeURIComponent(backPath)\n\n const share = async () => {\n if (!grant) return\n try {\n await navigator.clipboard.writeText(shareableUrl(grant))\n setCopied(true)\n window.setTimeout(() => setCopied(false), 2000)\n } catch {\n // Presse-papiers refusé : l'adresse de la barre contient déjà la clé.\n }\n }\n\n const href = (enable: boolean) => `${togglePath}?enable=${enable}&redirect=${back}`\n\n // Dans le Studio : rien (voir readEmbedded).\n if (embedded) return null\n\n return (\n <div style={{...anchor(props.position ?? 'bottom-left'), zIndex: 2147483000}}>\n <div style={shell}>\n <span style={{display: 'inline-flex', alignItems: 'center', gap: 6, fontWeight: 500}}>\n {/* Pastille pleine plutôt qu'un caractère décoratif : elle se lit à\n toutes les tailles et ne dépend d'aucune police. */}\n <span aria-hidden style={dot} />\n {label}\n </span>\n\n <span aria-hidden style={divider} />\n <span style={{opacity: 0.75}}>Données</span>\n\n <span role=\"group\" aria-label=\"Données affichées\" style={{display: 'inline-flex', gap: 2}}>\n <a\n href={href(true)}\n title=\"Ce qui sortira après publication\"\n aria-current={isDraft ? 'true' : undefined}\n style={isDraft ? segmentOn : segmentOff}\n >\n Brouillons\n </a>\n <a\n href={href(false)}\n title=\"Ce que voit le public aujourd'hui\"\n aria-current={isDraft ? undefined : 'true'}\n style={isDraft ? segmentOff : segmentOn}\n >\n En ligne\n </a>\n </span>\n\n {grant && (\n <>\n <span aria-hidden style={divider} />\n <button type=\"button\" onClick={share} title=\"Copier l'adresse de cette page, clé de préversion comprise\" style={shareButton}>\n {copied ? 'Lien copié' : 'Copier le lien'}\n </button>\n </>\n )}\n </div>\n </div>\n )\n}\n\nconst anchor = (position: NonNullable<PreviewBannerProps['position']>): CSSProperties => ({\n position: 'fixed',\n ...(position.startsWith('bottom') ? {bottom: 16} : {top: 16}),\n ...(position.endsWith('left') ? {left: 16} : {right: 16}),\n})\n\nconst shell: CSSProperties = {\n display: 'flex',\n alignItems: 'center',\n gap: 10,\n padding: '6px 12px',\n borderRadius: 999,\n // Ambre : la couleur des environnements de test, assez saturée pour ne pas\n // se confondre avec le site, assez sobre pour ne pas le masquer.\n background: '#fef3c7',\n color: '#451a03',\n border: '1px solid #fcd34d',\n boxShadow: '0 4px 16px rgba(0,0,0,0.14)',\n font: '500 12px/1 ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif',\n}\n\nconst dot: CSSProperties = {\n width: 7,\n height: 7,\n borderRadius: '50%',\n background: '#d97706',\n flex: 'none',\n}\n\nconst divider: CSSProperties = {width: 1, height: 14, background: '#00000022'}\n\nconst segmentBase: CSSProperties = {\n padding: '4px 10px',\n borderRadius: 999,\n textDecoration: 'none',\n fontSize: 12,\n lineHeight: 1,\n whiteSpace: 'nowrap',\n}\n\nconst segmentOn: CSSProperties = {...segmentBase, background: '#451a03', color: '#fffbeb'}\nconst segmentOff: CSSProperties = {...segmentBase, color: '#451a03', opacity: 0.7}\n\nconst shareButton: CSSProperties = {\n ...segmentBase,\n border: 'none',\n background: 'transparent',\n color: '#451a03',\n cursor: 'pointer',\n font: 'inherit',\n textDecoration: 'underline',\n textUnderlineOffset: 3,\n}\n"],"mappings":";;;;AAMA,MAAM,cAAc,eAGd,0BAA0B,CAAC;AACjC,SAAS,YAA2B;CAClC,IAAM,QAAQ,SAAS,OAAO,MAAM,gBAAI,OAAO,mCAAiC,CAAC;CACjF,OAAO,QAAQ,KAAK,mBAAmB,MAAM,EAAE,IAAI;AACrD;;;;;;;AAQA,MAAM,qBAAqB;CACzB,IAAI;EACF,OAAO,OAAO,SAAS,OAAO;CAChC,QAAQ;EAEN,OAAO;CACT;AACF;;AAGA,SAAS,aAAa,OAAuB;CAC3C,IAAM,MAAM,IAAI,IAAI,OAAO,SAAS,IAAI;C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,SAAS;CACT,cAAc;CACd,gBAAgB;CAChB,UAAU;CACV,YAAY;CACZ,YAAY;AACd,GAEM,YAA2B;CAAC,GAAG;CAAa,YAAY;CAAW,OAAO;AAAS,GACnF,aAA4B;CAAC,GAAG;CAAa,OAAO;CAAW,SAAS;AAAG,GAE3E,cAA6B;CACjC,GAAG;CACH,QAAQ;CACR,YAAY;CACZ,OAAO;CACP,QAAQ;CACR,MAAM;CACN,gBAAgB;CAChB,qBAAqB;AACvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocode-factory/sanity-kit",
3
- "version": "2.17.0",
3
+ "version": "2.17.2",
4
4
  "description": "Outils Studio de NoCode Factory : Pages (liste + board), Composants, Historique",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -2,6 +2,8 @@ import {useCallback, useMemo, useState} from 'react'
2
2
  import {useKitConfig} from '../context/KitContext'
3
3
  import {useKitClient} from './useKitClient'
4
4
  import {
5
+ defaultEnvironmentId,
6
+ editableEnvironment,
5
7
  customEnvironment,
6
8
  CUSTOM_ENVIRONMENT_ID,
7
9
  effectivePerspective,
@@ -74,7 +76,8 @@ export function usePreviewTargetState(): PreviewTargetState {
74
76
  const scope = `${STORAGE_PREFIX}${client.config().projectId ?? 'sans-projet'}`
75
77
 
76
78
  const environments = config.environments
77
- const fallback = environments[0]?.id ?? null
79
+ // Par défaut la préproduction : c'est là qu'on édite.
80
+ const fallback = defaultEnvironmentId(environments, config.previewUrl)
78
81
 
79
82
  const [environmentId, setStoredEnvironment] = useState<string | null>(() => {
80
83
  const saved = read(`${scope}:environment`)
@@ -141,9 +144,12 @@ export function usePreviewTargetState(): PreviewTargetState {
141
144
  // La production n'a que le contenu en ligne, quel que soit le choix retenu.
142
145
  const shown = effectivePerspective(environment, perspective, config.previewUrl)
143
146
 
147
+ // Presentation s'ouvre toujours sur un environnement éditable (jamais la
148
+ // production) ; production choisie = préproduction, contenu en ligne.
144
149
  const pathFor = useCallback(
145
- (url: string | null) => presentationPath(url, {environment, perspective: shown}),
146
- [environment, shown],
150
+ (url: string | null) =>
151
+ presentationPath(url, {environment: editableEnvironment(environment, allEnvironments, config.previewUrl), perspective: shown}),
152
+ [environment, allEnvironments, config.previewUrl, shown],
147
153
  )
148
154
 
149
155
  const siteUrlFor = useCallback(
@@ -1,7 +1,7 @@
1
1
  import type {SanityClient} from 'sanity'
2
2
  import type {ResolvedKitConfig} from '../config/types'
3
3
  import {componentIntentParams, fillTemplate} from './blocks'
4
- import {presentationPath} from './studioLinks'
4
+ import {editableEnvironment, presentationPath, urlOn} from './studioLinks'
5
5
 
6
6
  /**
7
7
  * Ouvre un composant : Presentation avec son rendu réel et ses valeurs par
@@ -71,6 +71,9 @@ export async function openDesignSystem(options: {
71
71
  navigateIntent('edit', designSystemIntentParams(config, id ?? config.componentPreview.defaultsType))
72
72
  return
73
73
  }
74
- const path = presentationPath(config.previewUrl ? `${config.previewUrl}${config.componentPreview.path}` : null)
74
+ // Sur la préproduction (éditable), jamais sur la production.
75
+ const env = editableEnvironment(config.environments[0] ?? null, config.environments, config.previewUrl)
76
+ const url = urlOn(env, config.componentPreview.path) ?? (config.previewUrl ? `${config.previewUrl}${config.componentPreview.path}` : null)
77
+ const path = presentationPath(url, env ? {environment: env} : {})
75
78
  if (path) navigateUrl(path)
76
79
  }
@@ -82,6 +82,26 @@ export function effectivePerspective(environment: NcfEnvironment | null, perspec
82
82
  return environment && isPublicEnvironment(environment, previewUrl) ? 'published' : perspective
83
83
  }
84
84
 
85
+ /**
86
+ * Environnement où ouvrir Presentation : on n'édite jamais la production (elle ne
87
+ * montre pas les brouillons et ne charge pas l'édition visuelle : « Unable to
88
+ * connect »). Production choisie : la première préversion déclarée, qui montrera
89
+ * le contenu en ligne. Sans préversion : l'environnement choisi, tel quel.
90
+ */
91
+ export function editableEnvironment(
92
+ selected: NcfEnvironment | null,
93
+ environments: readonly NcfEnvironment[],
94
+ previewUrl: string | null | undefined,
95
+ ): NcfEnvironment | null {
96
+ if (!selected || !isPublicEnvironment(selected, previewUrl)) return selected
97
+ return environments.find((e) => !isPublicEnvironment(e, previewUrl)) ?? selected
98
+ }
99
+
100
+ /** Environnement proposé par défaut : la première préversion, sinon le premier déclaré. */
101
+ export function defaultEnvironmentId(environments: readonly NcfEnvironment[], previewUrl: string | null | undefined): string | null {
102
+ return (environments.find((e) => !isPublicEnvironment(e, previewUrl)) ?? environments[0])?.id ?? null
103
+ }
104
+
85
105
  export interface OnlineUrlOptions {
86
106
  /** Chemin de la page (défaut : l'accueil). */
87
107
  path?: string | null
@@ -3,7 +3,7 @@ import {useRouter} from 'sanity/router'
3
3
  import type {ToolMenuProps} from 'sanity'
4
4
  import {InlinePopover} from '../../ui/Popover'
5
5
  import {KitProvider, useKitConfig} from '../../context/KitContext'
6
- import {presentationPath, previewTargets, type PreviewPerspective} from '../../lib/studioLinks'
6
+ import {editableEnvironment, isPublicEnvironment, presentationPath, previewTargets, type PreviewPerspective} from '../../lib/studioLinks'
7
7
  import {useOpenOnline} from '../../hooks/useOpenOnline'
8
8
  import type {ConfigIssue, NcfEnvironment, ResolvedKitConfig} from '../../config/types'
9
9
  import {EyeOpenIcon} from '@sanity/icons/EyeOpen'
@@ -46,8 +46,12 @@ export function NcfPreviewLauncher(props: ToolMenuProps) {
46
46
 
47
47
  // Ouvre l'aperçu DANS le Studio : la page apparaît dans Presentation, sans
48
48
  // quitter le Studio.
49
+ // Jamais la production dans Presentation (pas d'édition possible) : « Prod · En
50
+ // ligne » s'ouvre sur la préproduction, en contenu en ligne.
49
51
  const openInStudio = (environment: NcfEnvironment, perspective: PreviewPerspective) => {
50
- const path = presentationPath(environment.url, {environment, perspective})
52
+ const target = editableEnvironment(environment, environments, config.previewUrl) ?? environment
53
+ const shown = isPublicEnvironment(environment, config.previewUrl) ? 'published' : perspective
54
+ const path = presentationPath(target.url, {environment: target, perspective: shown})
51
55
  if (path) router.navigateUrl({path})
52
56
  }
53
57
 
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.17.0'
6
+ export const KIT_VERSION = '2.17.2'
@@ -13,6 +13,21 @@ function readGrant(): string | null {
13
13
  return match?.[1] ? decodeURIComponent(match[1]) : null
14
14
  }
15
15
 
16
+ /**
17
+ * Page affichée DANS le Studio (Presentation l'encastre dans un iframe) : le
18
+ * Studio a déjà sa propre bascule brouillons / en ligne, le bandeau ferait doublon
19
+ * et masquerait le bas de la page. Faux au rendu serveur (bandeau rendu), vrai
20
+ * dès l'hydratation dans un iframe (bandeau retiré).
21
+ */
22
+ const readEmbedded = () => {
23
+ try {
24
+ return window.self !== window.top
25
+ } catch {
26
+ // Accès refusé au parent : on est forcément encastré.
27
+ return true
28
+ }
29
+ }
30
+
16
31
  /** Adresse courante avec la clé de préversion (partageable telle quelle). */
17
32
  function shareableUrl(grant: string): string {
18
33
  const url = new URL(window.location.href)
@@ -51,6 +66,7 @@ export function NcfPreviewBanner(props: PreviewBannerProps) {
51
66
  // Clé de préversion mémorisée par le garde (absente avec une session Presentation).
52
67
  const grant = useSyncExternalStore(noSubscribe, readGrant, () => null)
53
68
  const [copied, setCopied] = useState(false)
69
+ const embedded = useSyncExternalStore(noSubscribe, readEmbedded, () => false)
54
70
 
55
71
  // Après une navigation côté client, Next affiche l'URL du lien, sans la clé : on
56
72
  // la remet, pour que l'adresse copiée depuis la barre ouvre la préversion chez
@@ -80,6 +96,9 @@ export function NcfPreviewBanner(props: PreviewBannerProps) {
80
96
 
81
97
  const href = (enable: boolean) => `${togglePath}?enable=${enable}&redirect=${back}`
82
98
 
99
+ // Dans le Studio : rien (voir readEmbedded).
100
+ if (embedded) return null
101
+
83
102
  return (
84
103
  <div style={{...anchor(props.position ?? 'bottom-left'), zIndex: 2147483000}}>
85
104
  <div style={shell}>