@nocode-factory/sanity-kit 2.33.2 → 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 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 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.
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.33.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.33.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.33.2") > 0);
1730
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.34.0") > 0);
1730
1731
  return {
1731
1732
  current: KIT_VERSION,
1732
1733
  latest,
@@ -9451,57 +9452,155 @@ function NcfPreviewHeader(props) {
9451
9452
  function ncfPreviewComponents() {
9452
9453
  return { unstable_header: { component: NcfPreviewHeader } };
9453
9454
  }
9454
- const KEY_TABLET = "ncf.presentation.tablet", KEY_HIDE = "ncf.presentation.hideForm", load = (key) => {
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) === "1";
9513
+ return window.localStorage.getItem(key);
9457
9514
  } catch {
9458
- return !1;
9515
+ return null;
9459
9516
  }
9460
- }, save = (key, on) => {
9517
+ }, write = (key, value) => {
9461
9518
  try {
9462
- window.localStorage.setItem(key, on ? "1" : "0");
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 d'adresse native, plus
9467
- * - « Tablet » : aperçu à 768 px, centré (Presentation n'a qu'ordinateur et mobile) ;
9468
- * - « Hide edit panel » : masque le formulaire à droite, l'aperçu prend la place
9469
- * (la liste des pages à gauche reste).
9470
- * Choix mémorisés dans le navigateur. Aucune donnée touchée : seulement l'affichage.
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), [tablet, setTablet] = useState(() => load(KEY_TABLET)), [hideForm, setHideForm] = useState(() => load(KEY_HIDE));
9474
- return useEffect(() => {
9475
- let iframe = previewPanel()?.querySelector("iframe") ?? ref.current?.closest("div[style]")?.parentElement?.querySelector("iframe") ?? null;
9476
- 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")), () => {
9477
- for (let p of [
9478
- "max-width",
9479
- "margin-left",
9480
- "margin-right",
9481
- "display"
9482
- ]) iframe.style.removeProperty(p);
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();
9486
- if (!panel || !content || !hideForm) return;
9555
+ if (!content || !hideForm) return;
9487
9556
  let hidden = [content], handle = content.previousElementSibling;
9488
9557
  handle && handle !== panel && !handle.id && hidden.push(handle);
9489
9558
  let apply = () => {
9490
9559
  for (let h of hidden) h.style.getPropertyValue("display") !== "none" && h.style.setProperty("display", "none", "important");
9491
- panel.style.getPropertyPriority("flex-grow") !== "important" && panel.style.setProperty("flex-grow", "1000", "important");
9492
9560
  };
9493
9561
  apply();
9494
9562
  let observer = new MutationObserver(apply);
9495
- for (let el of [panel, ...hidden]) observer.observe(el, {
9563
+ for (let el of hidden) observer.observe(el, {
9496
9564
  attributes: !0,
9497
9565
  attributeFilter: ["style"]
9498
9566
  });
9499
9567
  return () => {
9500
9568
  observer.disconnect();
9501
9569
  for (let h of hidden) h.style.removeProperty("display");
9502
- panel.style.removeProperty("flex-grow");
9503
9570
  };
9504
- }), /* @__PURE__ */ jsxs(Flex, {
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, {
9505
9604
  ref,
9506
9605
  align: "center",
9507
9606
  gap: 1,
@@ -9512,18 +9611,7 @@ function NcfPresentationHeader(props) {
9512
9611
  style: { minWidth: 0 },
9513
9612
  children: props.renderDefault(props)
9514
9613
  }),
9515
- /* @__PURE__ */ jsx(Button, {
9516
- icon: TabletDeviceIcon,
9517
- mode: tablet ? "default" : "bleed",
9518
- tone: tablet ? "primary" : "default",
9519
- padding: 2,
9520
- fontSize: 1,
9521
- title: tablet ? "Back to full width" : "Tablet (768px)",
9522
- "aria-pressed": tablet,
9523
- onClick: () => {
9524
- setTablet(!tablet), save(KEY_TABLET, !tablet);
9525
- }
9526
- }),
9614
+ slot ? createPortal(deviceMenu, slot) : deviceMenu,
9527
9615
  /* @__PURE__ */ jsx(Button, {
9528
9616
  icon: PanelRightIcon,
9529
9617
  mode: hideForm ? "default" : "bleed",
@@ -9533,7 +9621,7 @@ function NcfPresentationHeader(props) {
9533
9621
  title: hideForm ? "Show edit panel" : "Hide edit panel",
9534
9622
  "aria-pressed": hideForm,
9535
9623
  onClick: () => {
9536
- setHideForm(!hideForm), save(KEY_HIDE, !hideForm);
9624
+ setHideForm(!hideForm), write(KEY_HIDE, hideForm ? "0" : "1");
9537
9625
  }
9538
9626
  })
9539
9627
  ]