@nocode-factory/sanity-kit 2.32.0 → 2.33.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 CHANGED
@@ -1158,9 +1158,18 @@ export declare function ncfPreviewComponents(): {
1158
1158
  component: typeof NcfPreviewHeader;
1159
1159
  };
1160
1160
  };
1161
+ /**
1162
+ * En-tête de l'aperçu (Presentation) : la barre d'adresse native, plus
1163
+ * - « Tablet » : aperçu à 768 px, centré (Presentation n'a qu'ordinateur et mobile) ;
1164
+ * - « Hide edit panel » : masque le formulaire à droite, l'aperçu prend la place
1165
+ * (la liste des pages à gauche reste).
1166
+ * Choix mémorisés dans le navigateur. Aucune donnée touchée : seulement l'affichage.
1167
+ */
1168
+ declare function NcfPresentationHeader(props: PreviewHeaderProps): import("react").JSX.Element;
1161
1169
  /**
1162
1170
  * Composants à passer à `presentationTool` : liste des pages à gauche de l'aperçu
1163
- * (bouton intégré de Presentation pour l'afficher ou la masquer).
1171
+ * (bouton intégré de Presentation pour l'afficher ou la masquer), et en-tête avec
1172
+ * le format tablette et « Hide edit panel ».
1164
1173
  *
1165
1174
  * ```ts
1166
1175
  * presentationTool({components: ncfPresentationComponents(ncfOptions), ...})
@@ -1172,6 +1181,9 @@ export declare function ncfPresentationComponents(options: NcfKitConfig): {
1172
1181
  minWidth: number;
1173
1182
  maxWidth: number;
1174
1183
  };
1184
+ unstable_header: {
1185
+ component: typeof NcfPresentationHeader;
1186
+ };
1175
1187
  };
1176
1188
  /**
1177
1189
  * Lanceur d'aperçu, posé dans la barre du haut à droite des outils.
@@ -1376,7 +1388,7 @@ export declare function ActorName(props: {
1376
1388
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1377
1389
  * le vérifie.
1378
1390
  */
1379
- export declare const KIT_VERSION = "2.32.0";
1391
+ export declare const KIT_VERSION = "2.33.0";
1380
1392
  /**
1381
1393
  * Données de la page proposées comme colonnes.
1382
1394
  *
package/dist/index.js CHANGED
@@ -40,6 +40,8 @@ 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 { TabletDeviceIcon } from "@sanity/icons/TabletDevice";
44
+ import { PanelRightIcon } from "@sanity/icons/PanelRight";
43
45
  const trimTrailingSlash = (url) => url.replace(/\/+$/, ""), normalizePath = (path) => {
44
46
  let trimmed = path.trim();
45
47
  if (!trimmed || trimmed === "/") return "/";
@@ -1381,7 +1383,7 @@ function explainGrantError(error) {
1381
1383
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1382
1384
  * le vérifie.
1383
1385
  */
1384
- const KIT_VERSION = "2.32.0";
1386
+ const KIT_VERSION = "2.33.0";
1385
1387
  /**
1386
1388
  * Signale ce Studio au service du kit, une fois par montage.
1387
1389
  *
@@ -1724,7 +1726,7 @@ function useKitUpdate() {
1724
1726
  !controller.signal.aborted && body?.version && setLatest(body.version);
1725
1727
  }).catch(() => {}), () => controller.abort();
1726
1728
  }, []);
1727
- let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.32.0") > 0);
1729
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.33.0") > 0);
1728
1730
  return {
1729
1731
  current: KIT_VERSION,
1730
1732
  latest,
@@ -9449,6 +9451,102 @@ function NcfPreviewHeader(props) {
9449
9451
  function ncfPreviewComponents() {
9450
9452
  return { unstable_header: { component: NcfPreviewHeader } };
9451
9453
  }
9454
+ const KEY_TABLET = "ncf.presentation.tablet", KEY_HIDE = "ncf.presentation.hideForm", load = (key) => {
9455
+ try {
9456
+ return window.localStorage.getItem(key) === "1";
9457
+ } catch {
9458
+ return !1;
9459
+ }
9460
+ }, save = (key, on) => {
9461
+ try {
9462
+ window.localStorage.setItem(key, on ? "1" : "0");
9463
+ } catch {}
9464
+ };
9465
+ /** Panneau (enfant direct du conteneur des panneaux de Presentation) qui contient `el`. */
9466
+ function panelOf(el) {
9467
+ for (let node = el; node?.parentElement; node = node.parentElement) {
9468
+ let sibling = node.nextElementSibling;
9469
+ if (node.style.flexGrow !== "" && sibling && sibling.style.flexGrow !== "") return node;
9470
+ }
9471
+ return null;
9472
+ }
9473
+ /**
9474
+ * En-tête de l'aperçu (Presentation) : la barre d'adresse native, plus
9475
+ * - « Tablet » : aperçu à 768 px, centré (Presentation n'a qu'ordinateur et mobile) ;
9476
+ * - « Hide edit panel » : masque le formulaire à droite, l'aperçu prend la place
9477
+ * (la liste des pages à gauche reste).
9478
+ * Choix mémorisés dans le navigateur. Aucune donnée touchée : seulement l'affichage.
9479
+ */
9480
+ function NcfPresentationHeader(props) {
9481
+ let ref = useRef(null), [tablet, setTablet] = useState(() => load(KEY_TABLET)), [hideForm, setHideForm] = useState(() => load(KEY_HIDE));
9482
+ return useEffect(() => {
9483
+ let iframe = panelOf(ref.current)?.querySelector("iframe") ?? null;
9484
+ if (iframe) return tablet && (iframe.style.setProperty("max-width", "768px", "important"), iframe.style.setProperty("margin-left", "auto", "important"), iframe.style.setProperty("margin-right", "auto", "important"), iframe.style.setProperty("display", "block", "important")), () => {
9485
+ for (let p of [
9486
+ "max-width",
9487
+ "margin-left",
9488
+ "margin-right",
9489
+ "display"
9490
+ ]) iframe.style.removeProperty(p);
9491
+ };
9492
+ }), useEffect(() => {
9493
+ let panel = panelOf(ref.current);
9494
+ if (!panel || !hideForm) return;
9495
+ let hidden = [];
9496
+ for (let next = panel.nextElementSibling; next; next = next.nextElementSibling) hidden.push(next);
9497
+ let apply = () => {
9498
+ for (let h of hidden) h.style.getPropertyValue("display") !== "none" && h.style.setProperty("display", "none", "important");
9499
+ panel.style.getPropertyPriority("flex-grow") !== "important" && panel.style.setProperty("flex-grow", "1000", "important");
9500
+ };
9501
+ apply();
9502
+ let observer = new MutationObserver(apply);
9503
+ for (let el of [panel, ...hidden]) observer.observe(el, {
9504
+ attributes: !0,
9505
+ attributeFilter: ["style"]
9506
+ });
9507
+ return () => {
9508
+ observer.disconnect();
9509
+ for (let h of hidden) h.style.removeProperty("display");
9510
+ panel.style.removeProperty("flex-grow");
9511
+ };
9512
+ }), /* @__PURE__ */ jsxs(Flex, {
9513
+ ref,
9514
+ align: "center",
9515
+ gap: 1,
9516
+ style: { width: "100%" },
9517
+ children: [
9518
+ /* @__PURE__ */ jsx(Box, {
9519
+ flex: 1,
9520
+ style: { minWidth: 0 },
9521
+ children: props.renderDefault(props)
9522
+ }),
9523
+ /* @__PURE__ */ jsx(Button, {
9524
+ icon: TabletDeviceIcon,
9525
+ mode: tablet ? "default" : "bleed",
9526
+ tone: tablet ? "primary" : "default",
9527
+ padding: 2,
9528
+ fontSize: 1,
9529
+ title: tablet ? "Back to full width" : "Tablet (768px)",
9530
+ "aria-pressed": tablet,
9531
+ onClick: () => {
9532
+ setTablet(!tablet), save(KEY_TABLET, !tablet);
9533
+ }
9534
+ }),
9535
+ /* @__PURE__ */ jsx(Button, {
9536
+ icon: PanelRightIcon,
9537
+ mode: hideForm ? "default" : "bleed",
9538
+ tone: hideForm ? "primary" : "default",
9539
+ padding: 2,
9540
+ fontSize: 1,
9541
+ title: hideForm ? "Show edit panel" : "Hide edit panel",
9542
+ "aria-pressed": hideForm,
9543
+ onClick: () => {
9544
+ setHideForm(!hideForm), save(KEY_HIDE, !hideForm);
9545
+ }
9546
+ })
9547
+ ]
9548
+ });
9549
+ }
9452
9550
  const pathOf = (preview) => {
9453
9551
  if (!preview) return null;
9454
9552
  try {
@@ -9463,9 +9561,9 @@ const pathOf = (preview) => {
9463
9561
  * titre ou adresse ; un clic ouvre la page dans l'aperçu ET son document à côté.
9464
9562
  */
9465
9563
  function PagesNavigator() {
9466
- let config = useKitConfig(), { rows, loading } = usePages(), params = usePresentationParams(!1), navigate = usePresentationNavigate(), i18n = config.i18n, shownLocale = localeOfPreview(params?.preview, i18n), [locale, setLocale] = useState(null), [search, setSearch] = useState(""), activeLocale = locale ?? shownLocale ?? "", current = pathOf(params?.preview), visible = useMemo(() => {
9564
+ let config = useKitConfig(), { rows, loading } = usePages(), params = usePresentationParams(!1), navigate = usePresentationNavigate(), i18n = config.i18n, shownLocale = localeOfPreview(params?.preview, i18n), [locale, setLocale] = useState(null), [search, setSearch] = useState(""), activeLocale = locale ?? shownLocale ?? i18n?.defaultLocale ?? "", current = pathOf(params?.preview), visible = useMemo(() => {
9467
9565
  let q = search.trim().toLowerCase();
9468
- return rows.filter((r) => r.path !== null).filter((r) => !i18n || !activeLocale || r.locale === activeLocale).filter((r) => !q || r.title.toLowerCase().includes(q) || (r.path ?? "").toLowerCase().includes(q)).sort((a, b) => (a.path ?? "").localeCompare(b.path ?? ""));
9566
+ return rows.filter((r) => r.path !== null).filter((r) => !i18n || !activeLocale || !r.locale || r.locale === activeLocale).filter((r) => !q || r.title.toLowerCase().includes(q) || (r.path ?? "").toLowerCase().includes(q)).sort((a, b) => (a.path ?? "").localeCompare(b.path ?? ""));
9469
9567
  }, [
9470
9568
  rows,
9471
9569
  search,
@@ -9505,7 +9603,7 @@ function PagesNavigator() {
9505
9603
  padding: 2,
9506
9604
  value: activeLocale,
9507
9605
  onChange: (e) => setLocale(e.currentTarget.value),
9508
- style: { width: 72 },
9606
+ style: { width: 88 },
9509
9607
  children: i18n.locales.map((code) => /* @__PURE__ */ jsx("option", {
9510
9608
  value: code,
9511
9609
  children: code.toUpperCase()
@@ -9578,7 +9676,8 @@ function PagesNavigator() {
9578
9676
  }
9579
9677
  /**
9580
9678
  * Composants à passer à `presentationTool` : liste des pages à gauche de l'aperçu
9581
- * (bouton intégré de Presentation pour l'afficher ou la masquer).
9679
+ * (bouton intégré de Presentation pour l'afficher ou la masquer), et en-tête avec
9680
+ * le format tablette et « Hide edit panel ».
9582
9681
  *
9583
9682
  * ```ts
9584
9683
  * presentationTool({components: ncfPresentationComponents(ncfOptions), ...})
@@ -9593,11 +9692,14 @@ function ncfPresentationComponents(options) {
9593
9692
  children: /* @__PURE__ */ jsx(PagesNavigator, {})
9594
9693
  });
9595
9694
  }
9596
- return { unstable_navigator: {
9597
- component: NcfPagesNavigator,
9598
- minWidth: 220,
9599
- maxWidth: 420
9600
- } };
9695
+ return {
9696
+ unstable_navigator: {
9697
+ component: NcfPagesNavigator,
9698
+ minWidth: 220,
9699
+ maxWidth: 420
9700
+ },
9701
+ unstable_header: { component: NcfPresentationHeader }
9702
+ };
9601
9703
  }
9602
9704
  const SAFE = /^[A-Za-z0-9_.-]+$/, quote = (value) => JSON.stringify(value);
9603
9705
  /**