@nocode-factory/sanity-kit 2.33.3 → 2.34.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 +7 -6
- package/dist/index.js +135 -45
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/src/tools/presentation/PresentationHeader.tsx +101 -45
- package/src/version.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1159,11 +1159,12 @@ export declare function ncfPreviewComponents(): {
|
|
|
1159
1159
|
};
|
|
1160
1160
|
};
|
|
1161
1161
|
/**
|
|
1162
|
-
* En-tête de l'aperçu (Presentation) : la barre
|
|
1163
|
-
* -
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
1166
|
-
*
|
|
1162
|
+
* En-tête de l'aperçu (Presentation) : la barre native, plus
|
|
1163
|
+
* - un menu d'APPAREILS, posé juste à côté du bouton mobile natif : iPhone 12 Pro
|
|
1164
|
+
* (390×844), iPad Air (820×1180)... L'aperçu prend les dimensions de l'appareil,
|
|
1165
|
+
* affichées à côté de l'icône ;
|
|
1166
|
+
* - « Hide edit panel » : masque le formulaire à droite (la liste des pages reste).
|
|
1167
|
+
* Choix mémorisés dans le navigateur. Seulement l'affichage : aucune donnée touchée.
|
|
1167
1168
|
*/
|
|
1168
1169
|
declare function NcfPresentationHeader(props: PreviewHeaderProps): import("react").JSX.Element;
|
|
1169
1170
|
/**
|
|
@@ -1388,7 +1389,7 @@ export declare function ActorName(props: {
|
|
|
1388
1389
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1389
1390
|
* le vérifie.
|
|
1390
1391
|
*/
|
|
1391
|
-
export declare const KIT_VERSION = "2.
|
|
1392
|
+
export declare const KIT_VERSION = "2.34.0";
|
|
1392
1393
|
/**
|
|
1393
1394
|
* Données de la page proposées comme colonnes.
|
|
1394
1395
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as DEFAULT_TOOLBAR_MORE, a as defineComponentDefaults, c as DEFAULT_BOARD_TAGS, d as DEFAULT_INTERNAL_FIELDS, f as DEFAULT_NOINDEX_FIELDS, g as DEFAULT_TITLE_FIELD, h as DEFAULT_SLUG_FIELD, i as defaultsFieldName, l as DEFAULT_COMPONENT_PREVIEW, n as componentDefaultsMainDocument, o as requiredUnlessDefault, p as DEFAULT_PAGE_BUILDER_FIELD, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE, u as DEFAULT_I18N, v as DEFAULT_TOOLS } from "./componentDefaults-CelL5Ain.js";
|
|
2
|
-
import { createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, usePerspective, useSchema, useSetPerspective, useUser, useWorkspace } from "sanity";
|
|
4
4
|
import { ClockIcon } from "@sanity/icons/Clock";
|
|
5
5
|
import { ComponentIcon } from "@sanity/icons/Component";
|
|
@@ -13,7 +13,7 @@ import { LaunchIcon } from "@sanity/icons/Launch";
|
|
|
13
13
|
import { ArrowUpIcon } from "@sanity/icons/ArrowUp";
|
|
14
14
|
import { CheckmarkIcon } from "@sanity/icons/Checkmark";
|
|
15
15
|
import { CopyIcon } from "@sanity/icons/Copy";
|
|
16
|
-
import { Menu, MenuButton, MenuItem } from "@sanity/ui/menu";
|
|
16
|
+
import { Menu, MenuButton, MenuDivider, MenuItem } from "@sanity/ui/menu";
|
|
17
17
|
import { EllipsisHorizontalIcon } from "@sanity/icons/EllipsisHorizontal";
|
|
18
18
|
import { CloseIcon } from "@sanity/icons/Close";
|
|
19
19
|
import { EarthGlobeIcon } from "@sanity/icons/EarthGlobe";
|
|
@@ -40,6 +40,7 @@ import { Tooltip } from "@sanity/ui/tooltip";
|
|
|
40
40
|
import { EyeClosedIcon } from "@sanity/icons/EyeClosed";
|
|
41
41
|
import { usePresentationNavigate, usePresentationParams } from "sanity/presentation";
|
|
42
42
|
import { useToast } from "@sanity/ui/toast";
|
|
43
|
+
import { createPortal } from "react-dom";
|
|
43
44
|
import { TabletDeviceIcon } from "@sanity/icons/TabletDevice";
|
|
44
45
|
import { PanelRightIcon } from "@sanity/icons/PanelRight";
|
|
45
46
|
const trimTrailingSlash = (url) => url.replace(/\/+$/, ""), normalizePath = (path) => {
|
|
@@ -1173,14 +1174,14 @@ function customEnvironment(raw) {
|
|
|
1173
1174
|
}
|
|
1174
1175
|
}
|
|
1175
1176
|
/** Lit une préférence locale sans jamais faire échouer le montage. */
|
|
1176
|
-
function read(key) {
|
|
1177
|
+
function read$1(key) {
|
|
1177
1178
|
try {
|
|
1178
1179
|
return window.localStorage.getItem(key);
|
|
1179
1180
|
} catch {
|
|
1180
1181
|
return null;
|
|
1181
1182
|
}
|
|
1182
1183
|
}
|
|
1183
|
-
function write(key, value) {
|
|
1184
|
+
function write$1(key, value) {
|
|
1184
1185
|
try {
|
|
1185
1186
|
window.localStorage.setItem(key, value);
|
|
1186
1187
|
} catch {}
|
|
@@ -1195,13 +1196,13 @@ function write(key, value) {
|
|
|
1195
1196
|
*/
|
|
1196
1197
|
function usePreviewTargetState() {
|
|
1197
1198
|
let config = useKitConfig(), scope = `ncf-kit:preview-target:${useKitClient().config().projectId ?? "sans-projet"}`, environments = config.environments, fallback = defaultEnvironmentId(environments, config.previewUrl), [environmentId, setStoredEnvironment] = useState(() => {
|
|
1198
|
-
let saved = read(`${scope}:environment`);
|
|
1199
|
+
let saved = read$1(`${scope}:environment`);
|
|
1199
1200
|
return saved && environments.some((e) => e.id === saved) ? saved : fallback;
|
|
1200
|
-
}), [customUrl, setStoredCustomUrl] = useState(() => read(`${scope}:custom`)), [perspective, setStoredPerspective] = useState(() => read(`${scope}:perspective`) === "published" ? "published" : "drafts"), setEnvironment = useCallback((id) => {
|
|
1201
|
-
setStoredEnvironment(id), write(`${scope}:environment`, id);
|
|
1201
|
+
}), [customUrl, setStoredCustomUrl] = useState(() => read$1(`${scope}:custom`)), [perspective, setStoredPerspective] = useState(() => read$1(`${scope}:perspective`) === "published" ? "published" : "drafts"), setEnvironment = useCallback((id) => {
|
|
1202
|
+
setStoredEnvironment(id), write$1(`${scope}:environment`, id);
|
|
1202
1203
|
}, [scope]), setPerspective = useCallback((next) => {
|
|
1203
|
-
setStoredPerspective(next), write(`${scope}:perspective`, next);
|
|
1204
|
-
}, [scope]), custom = useMemo(() => customUrl ? customEnvironment(customUrl) : null, [customUrl]), allEnvironments = useMemo(() => custom ? [...environments, custom] : environments, [environments, custom]), environment = useMemo(() => allEnvironments.find((item) => item.id === environmentId) ?? allEnvironments[0] ?? null, [allEnvironments, environmentId]), setCustomUrl = useCallback((url) => url.trim() ? customEnvironment(url) ? (setStoredCustomUrl(url), write(`${scope}:custom`, url), setEnvironment(CUSTOM_ENVIRONMENT_ID), !0) : !1 : (setStoredCustomUrl(null), write(`${scope}:custom`, ""), setEnvironment(fallback ?? ""), !0), [
|
|
1204
|
+
setStoredPerspective(next), write$1(`${scope}:perspective`, next);
|
|
1205
|
+
}, [scope]), custom = useMemo(() => customUrl ? customEnvironment(customUrl) : null, [customUrl]), allEnvironments = useMemo(() => custom ? [...environments, custom] : environments, [environments, custom]), environment = useMemo(() => allEnvironments.find((item) => item.id === environmentId) ?? allEnvironments[0] ?? null, [allEnvironments, environmentId]), setCustomUrl = useCallback((url) => url.trim() ? customEnvironment(url) ? (setStoredCustomUrl(url), write$1(`${scope}:custom`, url), setEnvironment(CUSTOM_ENVIRONMENT_ID), !0) : !1 : (setStoredCustomUrl(null), write$1(`${scope}:custom`, ""), setEnvironment(fallback ?? ""), !0), [
|
|
1205
1206
|
scope,
|
|
1206
1207
|
setEnvironment,
|
|
1207
1208
|
fallback
|
|
@@ -1383,7 +1384,7 @@ function explainGrantError(error) {
|
|
|
1383
1384
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1384
1385
|
* le vérifie.
|
|
1385
1386
|
*/
|
|
1386
|
-
const KIT_VERSION = "2.
|
|
1387
|
+
const KIT_VERSION = "2.34.0";
|
|
1387
1388
|
/**
|
|
1388
1389
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1389
1390
|
*
|
|
@@ -1726,7 +1727,7 @@ function useKitUpdate() {
|
|
|
1726
1727
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1727
1728
|
}).catch(() => {}), () => controller.abort();
|
|
1728
1729
|
}, []);
|
|
1729
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1730
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.34.0") > 0);
|
|
1730
1731
|
return {
|
|
1731
1732
|
current: KIT_VERSION,
|
|
1732
1733
|
latest,
|
|
@@ -9451,35 +9452,103 @@ function NcfPreviewHeader(props) {
|
|
|
9451
9452
|
function ncfPreviewComponents() {
|
|
9452
9453
|
return { unstable_header: { component: NcfPreviewHeader } };
|
|
9453
9454
|
}
|
|
9454
|
-
|
|
9455
|
+
/** Appareils proposés (dimensions CSS de l'écran, portrait). */
|
|
9456
|
+
const PREVIEW_DEVICES = [
|
|
9457
|
+
{
|
|
9458
|
+
id: "iphone-se",
|
|
9459
|
+
label: "iPhone SE",
|
|
9460
|
+
width: 375,
|
|
9461
|
+
height: 667
|
|
9462
|
+
},
|
|
9463
|
+
{
|
|
9464
|
+
id: "iphone-12-pro",
|
|
9465
|
+
label: "iPhone 12 Pro",
|
|
9466
|
+
width: 390,
|
|
9467
|
+
height: 844
|
|
9468
|
+
},
|
|
9469
|
+
{
|
|
9470
|
+
id: "iphone-15-pro-max",
|
|
9471
|
+
label: "iPhone 15 Pro Max",
|
|
9472
|
+
width: 430,
|
|
9473
|
+
height: 932
|
|
9474
|
+
},
|
|
9475
|
+
{
|
|
9476
|
+
id: "pixel-7",
|
|
9477
|
+
label: "Pixel 7",
|
|
9478
|
+
width: 412,
|
|
9479
|
+
height: 915
|
|
9480
|
+
},
|
|
9481
|
+
{
|
|
9482
|
+
id: "galaxy-s20",
|
|
9483
|
+
label: "Galaxy S20",
|
|
9484
|
+
width: 360,
|
|
9485
|
+
height: 800
|
|
9486
|
+
},
|
|
9487
|
+
{
|
|
9488
|
+
id: "ipad-mini",
|
|
9489
|
+
label: "iPad Mini",
|
|
9490
|
+
width: 768,
|
|
9491
|
+
height: 1024
|
|
9492
|
+
},
|
|
9493
|
+
{
|
|
9494
|
+
id: "ipad-air",
|
|
9495
|
+
label: "iPad Air",
|
|
9496
|
+
width: 820,
|
|
9497
|
+
height: 1180
|
|
9498
|
+
},
|
|
9499
|
+
{
|
|
9500
|
+
id: "ipad-pro-11",
|
|
9501
|
+
label: "iPad Pro 11\"",
|
|
9502
|
+
width: 834,
|
|
9503
|
+
height: 1194
|
|
9504
|
+
},
|
|
9505
|
+
{
|
|
9506
|
+
id: "ipad-pro-13",
|
|
9507
|
+
label: "iPad Pro 12.9\"",
|
|
9508
|
+
width: 1024,
|
|
9509
|
+
height: 1366
|
|
9510
|
+
}
|
|
9511
|
+
], KEY_DEVICE = "ncf.presentation.device", KEY_HIDE = "ncf.presentation.hideForm", read = (key) => {
|
|
9455
9512
|
try {
|
|
9456
|
-
return window.localStorage.getItem(key)
|
|
9513
|
+
return window.localStorage.getItem(key);
|
|
9457
9514
|
} catch {
|
|
9458
|
-
return
|
|
9515
|
+
return null;
|
|
9459
9516
|
}
|
|
9460
|
-
},
|
|
9517
|
+
}, write = (key, value) => {
|
|
9461
9518
|
try {
|
|
9462
|
-
window.localStorage.setItem(key,
|
|
9519
|
+
value === null ? window.localStorage.removeItem(key) : window.localStorage.setItem(key, value);
|
|
9463
9520
|
} catch {}
|
|
9464
9521
|
}, previewPanel = () => document.getElementById("presentation-narrow-panel-preview"), contentPanel = () => document.getElementById("presentation-narrow-panel-content");
|
|
9465
9522
|
/**
|
|
9466
|
-
* En-tête de l'aperçu (Presentation) : la barre
|
|
9467
|
-
* -
|
|
9468
|
-
*
|
|
9469
|
-
*
|
|
9470
|
-
*
|
|
9523
|
+
* En-tête de l'aperçu (Presentation) : la barre native, plus
|
|
9524
|
+
* - un menu d'APPAREILS, posé juste à côté du bouton mobile natif : iPhone 12 Pro
|
|
9525
|
+
* (390×844), iPad Air (820×1180)... L'aperçu prend les dimensions de l'appareil,
|
|
9526
|
+
* affichées à côté de l'icône ;
|
|
9527
|
+
* - « Hide edit panel » : masque le formulaire à droite (la liste des pages reste).
|
|
9528
|
+
* Choix mémorisés dans le navigateur. Seulement l'affichage : aucune donnée touchée.
|
|
9471
9529
|
*/
|
|
9472
9530
|
function NcfPresentationHeader(props) {
|
|
9473
|
-
let ref = useRef(null), [
|
|
9474
|
-
|
|
9475
|
-
let
|
|
9476
|
-
if (
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9531
|
+
let ref = useRef(null), [deviceId, setDeviceId] = useState(() => read(KEY_DEVICE) ?? null), [hideForm, setHideForm] = useState(() => read(KEY_HIDE) === "1"), [slot, setSlot] = useState(null), device = PREVIEW_DEVICES.find((d) => d.id === deviceId) ?? null;
|
|
9532
|
+
useLayoutEffect(() => {
|
|
9533
|
+
let root = ref.current, button = (root?.querySelector("[data-sanity-icon=\"mobile-device\"], [data-sanity-icon=\"desktop\"]"))?.closest("button") ?? null;
|
|
9534
|
+
if (!button) return;
|
|
9535
|
+
let target = root?.querySelector("[data-ncf-device-slot]") ?? null;
|
|
9536
|
+
target || (target = document.createElement("span"), target.setAttribute("data-ncf-device-slot", ""), target.style.display = "inline-flex", button.insertAdjacentElement("afterend", target)), target !== slot && setSlot(target);
|
|
9537
|
+
}), useEffect(() => {
|
|
9538
|
+
let iframe = previewPanel()?.querySelector("iframe") ?? null;
|
|
9539
|
+
if (!iframe || !device) return;
|
|
9540
|
+
let set = [
|
|
9541
|
+
["width", `${device.width}px`],
|
|
9542
|
+
["max-width", "100%"],
|
|
9543
|
+
["height", `${device.height}px`],
|
|
9544
|
+
["margin-left", "auto"],
|
|
9545
|
+
["margin-right", "auto"],
|
|
9546
|
+
["display", "block"],
|
|
9547
|
+
["flex", "none"]
|
|
9548
|
+
];
|
|
9549
|
+
for (let [p, v] of set) iframe.style.setProperty(p, v, "important");
|
|
9550
|
+
return () => {
|
|
9551
|
+
for (let [p] of set) iframe.style.removeProperty(p);
|
|
9483
9552
|
};
|
|
9484
9553
|
}), useEffect(() => {
|
|
9485
9554
|
let panel = previewPanel(), content = contentPanel();
|
|
@@ -9499,7 +9568,39 @@ function NcfPresentationHeader(props) {
|
|
|
9499
9568
|
observer.disconnect();
|
|
9500
9569
|
for (let h of hidden) h.style.removeProperty("display");
|
|
9501
9570
|
};
|
|
9502
|
-
})
|
|
9571
|
+
});
|
|
9572
|
+
let choose = (id) => {
|
|
9573
|
+
setDeviceId(id), write(KEY_DEVICE, id);
|
|
9574
|
+
}, deviceMenu = /* @__PURE__ */ jsx(MenuButton, {
|
|
9575
|
+
id: "ncf-preview-device",
|
|
9576
|
+
button: /* @__PURE__ */ jsx(Button, {
|
|
9577
|
+
icon: TabletDeviceIcon,
|
|
9578
|
+
text: device ? `${device.width}×${device.height}` : void 0,
|
|
9579
|
+
mode: device ? "default" : "bleed",
|
|
9580
|
+
tone: device ? "primary" : "default",
|
|
9581
|
+
padding: 2,
|
|
9582
|
+
fontSize: 1,
|
|
9583
|
+
title: device ? `${device.label} (${device.width}×${device.height})` : "Preview on a device"
|
|
9584
|
+
}),
|
|
9585
|
+
menu: /* @__PURE__ */ jsxs(Menu, { children: [
|
|
9586
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
9587
|
+
text: "Full width",
|
|
9588
|
+
pressed: !device,
|
|
9589
|
+
onClick: () => choose(null)
|
|
9590
|
+
}),
|
|
9591
|
+
/* @__PURE__ */ jsx(MenuDivider, {}),
|
|
9592
|
+
PREVIEW_DEVICES.map((d) => /* @__PURE__ */ jsx(MenuItem, {
|
|
9593
|
+
text: `${d.label} ${d.width}×${d.height}`,
|
|
9594
|
+
pressed: d.id === deviceId,
|
|
9595
|
+
onClick: () => choose(d.id)
|
|
9596
|
+
}, d.id))
|
|
9597
|
+
] }),
|
|
9598
|
+
popover: {
|
|
9599
|
+
portal: !0,
|
|
9600
|
+
placement: "bottom-end"
|
|
9601
|
+
}
|
|
9602
|
+
});
|
|
9603
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
9503
9604
|
ref,
|
|
9504
9605
|
align: "center",
|
|
9505
9606
|
gap: 1,
|
|
@@ -9510,18 +9611,7 @@ function NcfPresentationHeader(props) {
|
|
|
9510
9611
|
style: { minWidth: 0 },
|
|
9511
9612
|
children: props.renderDefault(props)
|
|
9512
9613
|
}),
|
|
9513
|
-
|
|
9514
|
-
icon: TabletDeviceIcon,
|
|
9515
|
-
mode: tablet ? "default" : "bleed",
|
|
9516
|
-
tone: tablet ? "primary" : "default",
|
|
9517
|
-
padding: 2,
|
|
9518
|
-
fontSize: 1,
|
|
9519
|
-
title: tablet ? "Back to full width" : "Tablet (768px)",
|
|
9520
|
-
"aria-pressed": tablet,
|
|
9521
|
-
onClick: () => {
|
|
9522
|
-
setTablet(!tablet), save(KEY_TABLET, !tablet);
|
|
9523
|
-
}
|
|
9524
|
-
}),
|
|
9614
|
+
slot ? createPortal(deviceMenu, slot) : deviceMenu,
|
|
9525
9615
|
/* @__PURE__ */ jsx(Button, {
|
|
9526
9616
|
icon: PanelRightIcon,
|
|
9527
9617
|
mode: hideForm ? "default" : "bleed",
|
|
@@ -9531,7 +9621,7 @@ function NcfPresentationHeader(props) {
|
|
|
9531
9621
|
title: hideForm ? "Show edit panel" : "Hide edit panel",
|
|
9532
9622
|
"aria-pressed": hideForm,
|
|
9533
9623
|
onClick: () => {
|
|
9534
|
-
setHideForm(!hideForm),
|
|
9624
|
+
setHideForm(!hideForm), write(KEY_HIDE, hideForm ? "0" : "1");
|
|
9535
9625
|
}
|
|
9536
9626
|
})
|
|
9537
9627
|
]
|