@nocode-factory/sanity-kit 2.17.1 → 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/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/web.d.ts +1 -1
- package/dist/web.js +15 -2
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
- package/src/version.ts +1 -1
- package/src/web/PreviewBanner.tsx +19 -0
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;
|
|
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":"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"}
|
package/package.json
CHANGED
package/src/version.ts
CHANGED
|
@@ -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}>
|