@nocode-factory/sanity-kit 2.6.0 → 2.6.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 +1 -1
- package/dist/index.js +105 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useOpenOnline.ts +90 -0
- package/src/lib/studioLinks.ts +52 -8
- package/src/tools/navbar/PreviewLauncher.tsx +7 -7
- package/src/tools/pages/PathCell.tsx +24 -0
- package/src/tools/pages/board/PagePanel.tsx +13 -2
- package/src/version.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1270,7 +1270,7 @@ export declare function ActorName(props: {
|
|
|
1270
1270
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1271
1271
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1272
1272
|
*/
|
|
1273
|
-
export declare const KIT_VERSION = "2.6.
|
|
1273
|
+
export declare const KIT_VERSION = "2.6.1";
|
|
1274
1274
|
/**
|
|
1275
1275
|
* Données de la page proposées comme colonnes.
|
|
1276
1276
|
*
|
package/dist/index.js
CHANGED
|
@@ -996,17 +996,30 @@ function urlOn(environment, path) {
|
|
|
996
996
|
return environment?.url ? path ? `${trimEnd(environment.url)}${path.startsWith("/") ? path : `/${path}`}` : trimEnd(environment.url) : null;
|
|
997
997
|
}
|
|
998
998
|
/**
|
|
999
|
+
* L'environnement est-il le site public ?
|
|
1000
|
+
*
|
|
1001
|
+
* La production n'a ni garde ni brouillons : on y va par l'URL simple. Tout le
|
|
1002
|
+
* reste est une préversion, gardée — y compris une adresse collée à la volée.
|
|
1003
|
+
*/
|
|
1004
|
+
function isPublicEnvironment(environment, previewUrl) {
|
|
1005
|
+
return environment ? environment.id === "production" || !!previewUrl && trimEnd(environment.url) === trimEnd(previewUrl) : !1;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
999
1008
|
* URL du vrai site, en ligne, pour un environnement et un état de contenu.
|
|
1000
1009
|
*
|
|
1001
|
-
*
|
|
1002
|
-
* de
|
|
1003
|
-
*
|
|
1004
|
-
*
|
|
1010
|
+
* - Production : l'URL simple. Elle ne montre jamais de brouillons, et la
|
|
1011
|
+
* route de bascule y refuserait.
|
|
1012
|
+
* - Préversion, brouillons : la route de bascule pose le cookie de mode
|
|
1013
|
+
* brouillon, puis renvoie vers la page **avec le laissez-passer** — c'est la
|
|
1014
|
+
* page d'arrivée que la garde contrôle, pas la route, toujours ouverte.
|
|
1015
|
+
* - Préversion, en ligne : la page avec le laissez-passer.
|
|
1005
1016
|
*/
|
|
1006
|
-
function onlineUrl(environment, perspective) {
|
|
1017
|
+
function onlineUrl(environment, perspective, options = {}) {
|
|
1007
1018
|
if (!environment?.url) return null;
|
|
1008
|
-
let base = environment.url.
|
|
1009
|
-
|
|
1019
|
+
let base = trimEnd(environment.url), path = options.path ? options.path.startsWith("/") ? options.path : `/${options.path}` : "/";
|
|
1020
|
+
if (environment.id === "production" || isPublicEnvironment(environment, options.previewUrl)) return path === "/" ? base : `${base}${path}`;
|
|
1021
|
+
let landing = options.grant ? `${path}${path.includes("?") ? "&" : "?"}ncf_preview=${encodeURIComponent(options.grant)}` : path;
|
|
1022
|
+
return perspective === "drafts" ? `${base}/api/draft-mode/toggle?enable=true&redirect=${options.grant ? encodeURIComponent(landing) : landing}` : landing === "/" ? base : `${base}${landing}`;
|
|
1010
1023
|
}
|
|
1011
1024
|
/**
|
|
1012
1025
|
* Liens internes au Studio.
|
|
@@ -1287,7 +1300,7 @@ function explainGrantError(error) {
|
|
|
1287
1300
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1288
1301
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1289
1302
|
*/
|
|
1290
|
-
const KIT_VERSION = "2.6.
|
|
1303
|
+
const KIT_VERSION = "2.6.1";
|
|
1291
1304
|
/**
|
|
1292
1305
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1293
1306
|
*
|
|
@@ -1472,6 +1485,65 @@ function InlinePopover(props) {
|
|
|
1472
1485
|
})
|
|
1473
1486
|
})] });
|
|
1474
1487
|
}
|
|
1488
|
+
/** Libellé des laissez-passer délivrés pour soi, distinct des liens partagés. */
|
|
1489
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1490
|
+
/**
|
|
1491
|
+
* Ouvre le vrai site, en ligne, dans un nouvel onglet.
|
|
1492
|
+
*
|
|
1493
|
+
* Sur une préversion gardée par `ncfPreviewGuard`, un lien nu tombe sur
|
|
1494
|
+
* « Cette version du site est privée » — même pour l'éditeur connecté au
|
|
1495
|
+
* Studio. On demande donc au service un laissez-passer pour soi (le même que
|
|
1496
|
+
* « Partager la préversion », délivré seulement à qui a accès au projet Sanity)
|
|
1497
|
+
* et on le pose sur l'URL.
|
|
1498
|
+
*
|
|
1499
|
+
* L'onglet est ouvert **avant** l'appel réseau : un navigateur bloque une
|
|
1500
|
+
* fenêtre ouverte après un `await`, faute de geste de l'utilisateur.
|
|
1501
|
+
*/
|
|
1502
|
+
function useOpenOnline() {
|
|
1503
|
+
let config = useKitConfig(), client = useKitClient();
|
|
1504
|
+
return useCallback(async (environment, options = {}) => {
|
|
1505
|
+
let perspective = options.perspective ?? "published", plain = onlineUrl(environment, perspective, {
|
|
1506
|
+
path: options.path,
|
|
1507
|
+
previewUrl: config.previewUrl
|
|
1508
|
+
});
|
|
1509
|
+
if (!environment || !plain) return;
|
|
1510
|
+
if (isPublicEnvironment(environment, config.previewUrl) || !config.serviceEndpoint) {
|
|
1511
|
+
window.open(plain, "_blank", "noopener");
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
let tab = window.open("about:blank", "_blank");
|
|
1515
|
+
if (tab) {
|
|
1516
|
+
tab.opener = null, tab.document.title = "Ouverture de la préversion…", tab.document.body.innerHTML = "<p style=\"font:15px/1.6 system-ui,sans-serif;color:#57534e;padding:2rem\">Ouverture de la préversion…</p>";
|
|
1517
|
+
try {
|
|
1518
|
+
let { projectId, dataset, token } = client.config();
|
|
1519
|
+
if (!projectId || !dataset) throw Error("unknown_project");
|
|
1520
|
+
let key = `${config.serviceEndpoint}|${projectId}|${dataset}`, grant = cache.get(key);
|
|
1521
|
+
(!grant || new Date(grant.expiresAt).getTime() - Date.now() < 36e5) && (grant = await requestPreviewGrant(config.serviceEndpoint, {
|
|
1522
|
+
projectId,
|
|
1523
|
+
dataset,
|
|
1524
|
+
sanityToken: token ?? "",
|
|
1525
|
+
label: "Ouverture depuis le Studio",
|
|
1526
|
+
days: 1
|
|
1527
|
+
}), cache.set(key, grant));
|
|
1528
|
+
let signed = onlineUrl(environment, perspective, {
|
|
1529
|
+
path: options.path,
|
|
1530
|
+
grant: grant.token,
|
|
1531
|
+
previewUrl: config.previewUrl
|
|
1532
|
+
});
|
|
1533
|
+
tab.location.href = signed ?? plain;
|
|
1534
|
+
} catch (cause) {
|
|
1535
|
+
let message = explainGrantError(cause);
|
|
1536
|
+
tab.document.title = "Préversion indisponible", tab.document.body.innerHTML = "<main style=\"font:15px/1.6 system-ui,sans-serif;color:#1c1917;padding:2rem;max-width:32rem\"><h1 style=\"font-size:18px\">Impossible d'ouvrir la préversion</h1><p style=\"color:#57534e\"></p></main>";
|
|
1537
|
+
let paragraph = tab.document.querySelector("p");
|
|
1538
|
+
paragraph && (paragraph.textContent = message);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
}, [
|
|
1542
|
+
client,
|
|
1543
|
+
config.previewUrl,
|
|
1544
|
+
config.serviceEndpoint
|
|
1545
|
+
]);
|
|
1546
|
+
}
|
|
1475
1547
|
/**
|
|
1476
1548
|
* Jetons partagés par les vues du kit.
|
|
1477
1549
|
*
|
|
@@ -1539,7 +1611,7 @@ function useKitUpdate() {
|
|
|
1539
1611
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1540
1612
|
}).catch(() => {}), () => controller.abort();
|
|
1541
1613
|
}, []);
|
|
1542
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.6.
|
|
1614
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.6.1") > 0);
|
|
1543
1615
|
return {
|
|
1544
1616
|
current: KIT_VERSION,
|
|
1545
1617
|
latest,
|
|
@@ -1676,7 +1748,7 @@ function NcfKitUpdate(props) {
|
|
|
1676
1748
|
* regarde ailleurs.
|
|
1677
1749
|
*/
|
|
1678
1750
|
function NcfPreviewLauncher(props) {
|
|
1679
|
-
let config = useKitConfig(), router = useRouter(), environments = config.environments;
|
|
1751
|
+
let config = useKitConfig(), router = useRouter(), open = useOpenOnline(), environments = config.environments;
|
|
1680
1752
|
if (environments.length === 0) return /* @__PURE__ */ jsxs(Flex, {
|
|
1681
1753
|
align: "center",
|
|
1682
1754
|
gap: 2,
|
|
@@ -1689,8 +1761,7 @@ function NcfPreviewLauncher(props) {
|
|
|
1689
1761
|
});
|
|
1690
1762
|
path && router.navigateUrl({ path });
|
|
1691
1763
|
}, openOnline = (environment, perspective) => {
|
|
1692
|
-
|
|
1693
|
-
target && window.open(target, "_blank", "noopener");
|
|
1764
|
+
open(environment, { perspective });
|
|
1694
1765
|
}, inline = props.context === "topbar";
|
|
1695
1766
|
return /* @__PURE__ */ jsxs(Flex, {
|
|
1696
1767
|
align: inline ? "center" : "stretch",
|
|
@@ -3403,7 +3474,7 @@ function AddColumn(props) {
|
|
|
3403
3474
|
* concurrence plus le segment qui la distingue.
|
|
3404
3475
|
*/
|
|
3405
3476
|
function PathCell(props) {
|
|
3406
|
-
let { path, locale, showLocale, url } = props;
|
|
3477
|
+
let { path, locale, showLocale, url } = props, config = useKitConfig(), { environment, perspective } = usePreviewTarget(), open = useOpenOnline(), guarded = !!environment && !isPublicEnvironment(environment, config.previewUrl);
|
|
3407
3478
|
if (!path) return /* @__PURE__ */ jsx(Text, {
|
|
3408
3479
|
size: 1,
|
|
3409
3480
|
muted: !0,
|
|
@@ -3430,6 +3501,12 @@ function PathCell(props) {
|
|
|
3430
3501
|
target: "_blank",
|
|
3431
3502
|
rel: "noreferrer",
|
|
3432
3503
|
title: `Ouvrir ${url}`,
|
|
3504
|
+
onClick: (event) => {
|
|
3505
|
+
guarded && (event.preventDefault(), open(environment, {
|
|
3506
|
+
path: pathnameOf(url),
|
|
3507
|
+
perspective
|
|
3508
|
+
}));
|
|
3509
|
+
},
|
|
3433
3510
|
style: {
|
|
3434
3511
|
color: "inherit",
|
|
3435
3512
|
textDecoration: "none",
|
|
@@ -3455,6 +3532,14 @@ function PathCell(props) {
|
|
|
3455
3532
|
})]
|
|
3456
3533
|
});
|
|
3457
3534
|
}
|
|
3535
|
+
/** Chemin d'une URL absolue, ou la valeur telle quelle. */
|
|
3536
|
+
function pathnameOf(url) {
|
|
3537
|
+
try {
|
|
3538
|
+
return new URL(url).pathname;
|
|
3539
|
+
} catch {
|
|
3540
|
+
return url;
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3458
3543
|
/**
|
|
3459
3544
|
* Étiquette d'une page, modifiable sur place.
|
|
3460
3545
|
*
|
|
@@ -4032,7 +4117,7 @@ function pageThumbnailUrl(template, previewUrl, input) {
|
|
|
4032
4117
|
* sélecteur, et c'est pourtant là qu'on veut qualifier les pages.
|
|
4033
4118
|
*/
|
|
4034
4119
|
function PagePanel(props) {
|
|
4035
|
-
let { row, thumbnailUrl, tag, tags, colorLabel, color, incoming, outgoing, columns, values, onTag, onField, onAddOption, onRemoveOption, onOptionColor, onOpen, onClose } = props, [failed, setFailed] = useState(!1), { siteUrlFor, environments, environment } = usePreviewTarget(), siteUrl = siteUrlFor(row.url);
|
|
4120
|
+
let { row, thumbnailUrl, tag, tags, colorLabel, color, incoming, outgoing, columns, values, onTag, onField, onAddOption, onRemoveOption, onOptionColor, onOpen, onClose } = props, [failed, setFailed] = useState(!1), { siteUrlFor, environments, environment, perspective } = usePreviewTarget(), openOnline = useOpenOnline(), config = useKitConfig(), siteUrl = siteUrlFor(row.url);
|
|
4036
4121
|
return /* @__PURE__ */ jsx(Card, {
|
|
4037
4122
|
radius: 3,
|
|
4038
4123
|
shadow: 1,
|
|
@@ -4218,6 +4303,12 @@ function PagePanel(props) {
|
|
|
4218
4303
|
href: siteUrl,
|
|
4219
4304
|
target: "_blank",
|
|
4220
4305
|
rel: "noreferrer",
|
|
4306
|
+
onClick: (event) => {
|
|
4307
|
+
environment && !isPublicEnvironment(environment, config.previewUrl) && (event.preventDefault(), openOnline(environment, {
|
|
4308
|
+
path: new URL(siteUrl).pathname,
|
|
4309
|
+
perspective
|
|
4310
|
+
}));
|
|
4311
|
+
},
|
|
4221
4312
|
mode: "ghost",
|
|
4222
4313
|
fontSize: 1,
|
|
4223
4314
|
padding: 2,
|