@nocode-factory/sanity-kit 2.10.2 → 2.11.0
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 +102 -72
- package/dist/index.js.map +1 -1
- package/dist/web-server.d.ts +50 -1
- package/dist/web-server.js +123 -8
- package/dist/web-server.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/usePreviewTarget.ts +9 -6
- package/src/lib/studioLinks.ts +39 -5
- package/src/tools/navbar/PreviewLauncher.tsx +47 -57
- package/src/tools/pages/PreviewTarget.tsx +5 -1
- package/src/version.ts +1 -1
- package/src/web/dataMode.ts +27 -0
- package/src/web/draftModeToggle.ts +14 -3
- package/src/web/enableDraftMode.ts +62 -0
- package/src/web/previewGrant.ts +10 -2
- package/src/web/previewSession.ts +54 -0
- package/src/web/server.ts +4 -0
package/dist/index.d.ts
CHANGED
|
@@ -1302,7 +1302,7 @@ export declare function ActorName(props: {
|
|
|
1302
1302
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1303
1303
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1304
1304
|
*/
|
|
1305
|
-
export declare const KIT_VERSION = "2.
|
|
1305
|
+
export declare const KIT_VERSION = "2.11.0";
|
|
1306
1306
|
/**
|
|
1307
1307
|
* Données de la page proposées comme colonnes.
|
|
1308
1308
|
*
|
package/dist/index.js
CHANGED
|
@@ -1018,6 +1018,32 @@ function urlOn(environment, path) {
|
|
|
1018
1018
|
function isPublicEnvironment(environment, previewUrl) {
|
|
1019
1019
|
return environment ? environment.id === "production" || !!previewUrl && trimEnd(environment.url) === trimEnd(previewUrl) : !1;
|
|
1020
1020
|
}
|
|
1021
|
+
function previewTargets(environments, previewUrl) {
|
|
1022
|
+
let previews = environments.filter((e) => !isPublicEnvironment(e, previewUrl)), publics = environments.filter((e) => isPublicEnvironment(e, previewUrl)), name = (e) => e.id === "preprod" ? "Préprod" : e.label;
|
|
1023
|
+
return [...previews.flatMap((environment) => [{
|
|
1024
|
+
environment,
|
|
1025
|
+
perspective: "drafts",
|
|
1026
|
+
label: `${name(environment)} · Brouillons`,
|
|
1027
|
+
hint: "Ce qui sortira après publication",
|
|
1028
|
+
tone: "draft"
|
|
1029
|
+
}, {
|
|
1030
|
+
environment,
|
|
1031
|
+
perspective: "published",
|
|
1032
|
+
label: `${name(environment)} · En ligne`,
|
|
1033
|
+
hint: "Le contenu publié, sur la version de test du site",
|
|
1034
|
+
tone: "live"
|
|
1035
|
+
}]), ...publics.map((environment) => ({
|
|
1036
|
+
environment,
|
|
1037
|
+
perspective: "published",
|
|
1038
|
+
label: "Prod · En ligne",
|
|
1039
|
+
hint: "Le site public, tel que le voient les visiteurs",
|
|
1040
|
+
tone: "prod"
|
|
1041
|
+
}))];
|
|
1042
|
+
}
|
|
1043
|
+
/** La production n'a qu'une perspective : le contenu en ligne. */
|
|
1044
|
+
function effectivePerspective(environment, perspective, previewUrl) {
|
|
1045
|
+
return environment && isPublicEnvironment(environment, previewUrl) ? "published" : perspective;
|
|
1046
|
+
}
|
|
1021
1047
|
/**
|
|
1022
1048
|
* URL du vrai site, en ligne, pour un environnement et un état de contenu.
|
|
1023
1049
|
*
|
|
@@ -1032,8 +1058,8 @@ function onlineUrl(environment, perspective, options = {}) {
|
|
|
1032
1058
|
if (!environment?.url) return null;
|
|
1033
1059
|
let base = trimEnd(environment.url), path = options.path ? options.path.startsWith("/") ? options.path : `/${options.path}` : "/";
|
|
1034
1060
|
if (environment.id === "production" || isPublicEnvironment(environment, options.previewUrl)) return path === "/" ? base : `${base}${path}`;
|
|
1035
|
-
let landing = options.grant ? `${path}${path.includes("?") ? "&" : "?"}ncf_preview=${encodeURIComponent(options.grant)}` : path;
|
|
1036
|
-
return
|
|
1061
|
+
let landing = options.grant ? `${path}${path.includes("?") ? "&" : "?"}ncf_preview=${encodeURIComponent(options.grant)}` : path, redirect = options.grant ? encodeURIComponent(landing) : landing;
|
|
1062
|
+
return `${base}/api/draft-mode/toggle?enable=${perspective === "drafts"}&redirect=${redirect}`;
|
|
1037
1063
|
}
|
|
1038
1064
|
/**
|
|
1039
1065
|
* Liens internes au Studio.
|
|
@@ -1162,10 +1188,10 @@ function usePreviewTargetState() {
|
|
|
1162
1188
|
scope,
|
|
1163
1189
|
setEnvironment,
|
|
1164
1190
|
fallback
|
|
1165
|
-
]), pathFor = useCallback((url) => presentationPath(url, {
|
|
1191
|
+
]), shown = effectivePerspective(environment, perspective, config.previewUrl), pathFor = useCallback((url) => presentationPath(url, {
|
|
1166
1192
|
environment,
|
|
1167
|
-
perspective
|
|
1168
|
-
}), [environment,
|
|
1193
|
+
perspective: shown
|
|
1194
|
+
}), [environment, shown]), siteUrlFor = useCallback((url) => {
|
|
1169
1195
|
if (!url) return null;
|
|
1170
1196
|
if (!environment) return url;
|
|
1171
1197
|
try {
|
|
@@ -1175,13 +1201,13 @@ function usePreviewTargetState() {
|
|
|
1175
1201
|
}
|
|
1176
1202
|
}, [environment]);
|
|
1177
1203
|
return {
|
|
1178
|
-
isProduction: !!(environment &&
|
|
1204
|
+
isProduction: !!(environment && isPublicEnvironment(environment, config.previewUrl)),
|
|
1179
1205
|
environments: allEnvironments,
|
|
1180
1206
|
customUrl,
|
|
1181
1207
|
setCustomUrl,
|
|
1182
1208
|
environment,
|
|
1183
1209
|
environmentId: environment?.id ?? null,
|
|
1184
|
-
perspective,
|
|
1210
|
+
perspective: shown,
|
|
1185
1211
|
setEnvironment,
|
|
1186
1212
|
setPerspective,
|
|
1187
1213
|
pathFor,
|
|
@@ -1334,7 +1360,7 @@ function explainGrantError(error) {
|
|
|
1334
1360
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1335
1361
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1336
1362
|
*/
|
|
1337
|
-
const KIT_VERSION = "2.
|
|
1363
|
+
const KIT_VERSION = "2.11.0";
|
|
1338
1364
|
/**
|
|
1339
1365
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1340
1366
|
*
|
|
@@ -1622,33 +1648,6 @@ function useOpenOnline() {
|
|
|
1622
1648
|
]);
|
|
1623
1649
|
}
|
|
1624
1650
|
/**
|
|
1625
|
-
* Jetons partagés par les vues du kit.
|
|
1626
|
-
*
|
|
1627
|
-
* Mode Operate : la couleur sert l'état et la sélection, jamais la décoration.
|
|
1628
|
-
* Les fonds teintés restent sous le seuil où le texte du Studio perd son
|
|
1629
|
-
* contraste, dans les deux thèmes.
|
|
1630
|
-
*/
|
|
1631
|
-
/** Teinte de fond d'une ligne ou d'une carte porteuse d'un critère. */
|
|
1632
|
-
const TABULAR = { fontVariantNumeric: "tabular-nums" }, MONO = {
|
|
1633
|
-
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
1634
|
-
fontVariantNumeric: "tabular-nums",
|
|
1635
|
-
letterSpacing: "-0.01em"
|
|
1636
|
-
}, CELL = { minWidth: 0 }, BORDER = "var(--card-border-color, rgba(127,127,127,0.22))", OPTION_COLORS = [
|
|
1637
|
-
"#f5a623",
|
|
1638
|
-
"#43d675",
|
|
1639
|
-
"#2276fc",
|
|
1640
|
-
"#f03e3e",
|
|
1641
|
-
"#a855f7",
|
|
1642
|
-
"#8a8a8a"
|
|
1643
|
-
], DIFF = {
|
|
1644
|
-
removedLine: "color-mix(in srgb, #f03e3e 9%, transparent)",
|
|
1645
|
-
addedLine: "color-mix(in srgb, #2f9e44 11%, transparent)",
|
|
1646
|
-
removedWord: "color-mix(in srgb, #f03e3e 26%, transparent)",
|
|
1647
|
-
addedWord: "color-mix(in srgb, #2f9e44 30%, transparent)",
|
|
1648
|
-
removedMark: "#e03131",
|
|
1649
|
-
addedMark: "#2f9e44"
|
|
1650
|
-
};
|
|
1651
|
-
/**
|
|
1652
1651
|
* Comparaison de deux versions sémantiques.
|
|
1653
1652
|
*
|
|
1654
1653
|
* Suffisant pour ce qu'on en fait — savoir si une version publiée dépasse
|
|
@@ -1688,7 +1687,7 @@ function useKitUpdate() {
|
|
|
1688
1687
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1689
1688
|
}).catch(() => {}), () => controller.abort();
|
|
1690
1689
|
}, []);
|
|
1691
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1690
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.11.0") > 0);
|
|
1692
1691
|
return {
|
|
1693
1692
|
current: KIT_VERSION,
|
|
1694
1693
|
latest,
|
|
@@ -1697,6 +1696,33 @@ function useKitUpdate() {
|
|
|
1697
1696
|
};
|
|
1698
1697
|
}
|
|
1699
1698
|
/**
|
|
1699
|
+
* Jetons partagés par les vues du kit.
|
|
1700
|
+
*
|
|
1701
|
+
* Mode Operate : la couleur sert l'état et la sélection, jamais la décoration.
|
|
1702
|
+
* Les fonds teintés restent sous le seuil où le texte du Studio perd son
|
|
1703
|
+
* contraste, dans les deux thèmes.
|
|
1704
|
+
*/
|
|
1705
|
+
/** Teinte de fond d'une ligne ou d'une carte porteuse d'un critère. */
|
|
1706
|
+
const TABULAR = { fontVariantNumeric: "tabular-nums" }, MONO = {
|
|
1707
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
1708
|
+
fontVariantNumeric: "tabular-nums",
|
|
1709
|
+
letterSpacing: "-0.01em"
|
|
1710
|
+
}, CELL = { minWidth: 0 }, BORDER = "var(--card-border-color, rgba(127,127,127,0.22))", OPTION_COLORS = [
|
|
1711
|
+
"#f5a623",
|
|
1712
|
+
"#43d675",
|
|
1713
|
+
"#2276fc",
|
|
1714
|
+
"#f03e3e",
|
|
1715
|
+
"#a855f7",
|
|
1716
|
+
"#8a8a8a"
|
|
1717
|
+
], DIFF = {
|
|
1718
|
+
removedLine: "color-mix(in srgb, #f03e3e 9%, transparent)",
|
|
1719
|
+
addedLine: "color-mix(in srgb, #2f9e44 11%, transparent)",
|
|
1720
|
+
removedWord: "color-mix(in srgb, #f03e3e 26%, transparent)",
|
|
1721
|
+
addedWord: "color-mix(in srgb, #2f9e44 30%, transparent)",
|
|
1722
|
+
removedMark: "#e03131",
|
|
1723
|
+
addedMark: "#2f9e44"
|
|
1724
|
+
};
|
|
1725
|
+
/**
|
|
1700
1726
|
* Signale qu'une version plus récente du kit existe.
|
|
1701
1727
|
*
|
|
1702
1728
|
* **Il ne met pas à jour.** Un Studio tourne dans un navigateur : il ne peut
|
|
@@ -1882,6 +1908,21 @@ function NcfToolButtons(props) {
|
|
|
1882
1908
|
})]
|
|
1883
1909
|
});
|
|
1884
1910
|
}
|
|
1911
|
+
/** Couleurs des trois cibles : brouillons (jaune pastel), préprod en ligne (vert pastel), prod (vert plein). */
|
|
1912
|
+
const TARGET_TONES = {
|
|
1913
|
+
draft: {
|
|
1914
|
+
background: "#fdf1c7",
|
|
1915
|
+
color: "#4a3a07"
|
|
1916
|
+
},
|
|
1917
|
+
live: {
|
|
1918
|
+
background: "#d9f2df",
|
|
1919
|
+
color: "#14532d"
|
|
1920
|
+
},
|
|
1921
|
+
prod: {
|
|
1922
|
+
background: "#15803d",
|
|
1923
|
+
color: "#ffffff"
|
|
1924
|
+
}
|
|
1925
|
+
};
|
|
1885
1926
|
/**
|
|
1886
1927
|
* Lanceur d'aperçu, posé dans la barre du haut à droite des outils.
|
|
1887
1928
|
*
|
|
@@ -1945,55 +1986,43 @@ function NcfPreviewLauncher(props) {
|
|
|
1945
1986
|
muted: !0,
|
|
1946
1987
|
children: "Cliquer : ouvre dans le Studio. L'icône ↗ : ouvre le site en ligne."
|
|
1947
1988
|
})
|
|
1948
|
-
}), environments.map((
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
borderTop: `1px solid ${BORDER}`,
|
|
1952
|
-
marginTop: 4
|
|
1953
|
-
},
|
|
1954
|
-
children: [/* @__PURE__ */ jsx(Box, {
|
|
1955
|
-
paddingX: 2,
|
|
1956
|
-
paddingBottom: 1,
|
|
1957
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1958
|
-
size: 0,
|
|
1959
|
-
weight: "semibold",
|
|
1960
|
-
muted: !0,
|
|
1961
|
-
textOverflow: "ellipsis",
|
|
1962
|
-
children: environment.label
|
|
1963
|
-
})
|
|
1964
|
-
}), PERSPECTIVES.map((option) => /* @__PURE__ */ jsxs(Flex, {
|
|
1989
|
+
}), previewTargets(environments, config.previewUrl).map((target) => {
|
|
1990
|
+
let tone = TARGET_TONES[target.tone];
|
|
1991
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
1965
1992
|
align: "center",
|
|
1966
1993
|
gap: 1,
|
|
1967
1994
|
children: [/* @__PURE__ */ jsx(Flex, {
|
|
1968
1995
|
align: "center",
|
|
1996
|
+
gap: 2,
|
|
1969
1997
|
flex: 1,
|
|
1970
1998
|
padding: 2,
|
|
1971
1999
|
onClick: () => {
|
|
1972
|
-
openInStudio(environment,
|
|
2000
|
+
openInStudio(target.environment, target.perspective), close();
|
|
1973
2001
|
},
|
|
1974
2002
|
style: {
|
|
1975
2003
|
cursor: "pointer",
|
|
1976
|
-
borderRadius:
|
|
1977
|
-
minWidth: 0
|
|
2004
|
+
borderRadius: 6,
|
|
2005
|
+
minWidth: 0,
|
|
2006
|
+
background: tone.background,
|
|
2007
|
+
color: tone.color
|
|
1978
2008
|
},
|
|
1979
2009
|
title: "Ouvrir dans le Studio (Presentation)",
|
|
1980
|
-
onMouseEnter: (event) => {
|
|
1981
|
-
event.currentTarget.style.background = "var(--card-muted-bg-color, rgba(127,127,127,0.12))";
|
|
1982
|
-
},
|
|
1983
|
-
onMouseLeave: (event) => {
|
|
1984
|
-
event.currentTarget.style.background = "transparent";
|
|
1985
|
-
},
|
|
1986
2010
|
children: /* @__PURE__ */ jsxs(Stack, {
|
|
1987
2011
|
gap: 1,
|
|
1988
2012
|
style: { minWidth: 0 },
|
|
1989
2013
|
children: [/* @__PURE__ */ jsx(Text, {
|
|
1990
2014
|
size: 1,
|
|
1991
|
-
|
|
2015
|
+
weight: "semibold",
|
|
2016
|
+
style: { color: tone.color },
|
|
2017
|
+
children: target.label
|
|
1992
2018
|
}), /* @__PURE__ */ jsx(Text, {
|
|
1993
2019
|
size: 0,
|
|
1994
|
-
|
|
2020
|
+
style: {
|
|
2021
|
+
color: tone.color,
|
|
2022
|
+
opacity: .8
|
|
2023
|
+
},
|
|
1995
2024
|
textOverflow: "ellipsis",
|
|
1996
|
-
children:
|
|
2025
|
+
children: target.hint
|
|
1997
2026
|
})]
|
|
1998
2027
|
})
|
|
1999
2028
|
}), /* @__PURE__ */ jsx(Button, {
|
|
@@ -2002,13 +2031,13 @@ function NcfPreviewLauncher(props) {
|
|
|
2002
2031
|
fontSize: 1,
|
|
2003
2032
|
icon: LaunchIcon,
|
|
2004
2033
|
title: "Ouvrir le site en ligne, dans un nouvel onglet",
|
|
2005
|
-
"aria-label": `Ouvrir ${
|
|
2034
|
+
"aria-label": `Ouvrir ${target.label} dans un nouvel onglet`,
|
|
2006
2035
|
onClick: () => {
|
|
2007
|
-
openOnline(environment,
|
|
2036
|
+
openOnline(target.environment, target.perspective), close();
|
|
2008
2037
|
}
|
|
2009
2038
|
})]
|
|
2010
|
-
},
|
|
2011
|
-
}
|
|
2039
|
+
}, `${target.environment.id}-${target.perspective}`);
|
|
2040
|
+
})]
|
|
2012
2041
|
})
|
|
2013
2042
|
})
|
|
2014
2043
|
]
|
|
@@ -2486,21 +2515,22 @@ function FieldLabel(props) {
|
|
|
2486
2515
|
* menu à une entrée occupe la place sans rien offrir.
|
|
2487
2516
|
*/
|
|
2488
2517
|
function PreviewTarget(props) {
|
|
2489
|
-
let { environments, environmentId, perspective, onEnvironment, onPerspective } = props, { onCustomUrl, customUrl, productionUrl } = props, current = environments.find((environment) => environment.id === environmentId);
|
|
2518
|
+
let { environments, environmentId, perspective, onEnvironment, onPerspective } = props, { onCustomUrl, customUrl, productionUrl } = props, current = environments.find((environment) => environment.id === environmentId), onProduction = !!(current && productionUrl && current.url.replace(/\/+$/, "") === productionUrl.replace(/\/+$/, "")) || current?.id === "production";
|
|
2490
2519
|
return /* @__PURE__ */ jsxs(Box, {
|
|
2491
2520
|
style: { flex: "none" },
|
|
2492
2521
|
children: [/* @__PURE__ */ jsx(FieldLabel, { children: "Aperçu" }), /* @__PURE__ */ jsxs(Flex, {
|
|
2493
2522
|
gap: 1,
|
|
2494
2523
|
align: "center",
|
|
2495
2524
|
children: [PERSPECTIVES.map((option) => {
|
|
2496
|
-
let active = option.id === perspective;
|
|
2525
|
+
let active = option.id === perspective, unavailable = onProduction && option.id === "drafts";
|
|
2497
2526
|
return /* @__PURE__ */ jsx(Button, {
|
|
2527
|
+
disabled: unavailable,
|
|
2498
2528
|
mode: active ? "default" : "bleed",
|
|
2499
2529
|
tone: active ? "primary" : "default",
|
|
2500
2530
|
fontSize: 1,
|
|
2501
2531
|
padding: 2,
|
|
2502
2532
|
text: option.label,
|
|
2503
|
-
title: option.hint,
|
|
2533
|
+
title: unavailable ? "La production ne montre que le contenu en ligne : les brouillons se relisent sur la préprod." : option.hint,
|
|
2504
2534
|
"aria-pressed": active,
|
|
2505
2535
|
onClick: () => onPerspective(option.id)
|
|
2506
2536
|
}, option.id);
|