@nocode-factory/sanity-kit 2.10.0 → 2.10.2
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 +88 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config/validate.ts +3 -10
- package/src/form/OverrideInput.tsx +5 -0
- package/src/hooks/useInPresentation.ts +26 -0
- package/src/lib/studioLinks.ts +28 -0
- package/src/tools/createToolComponent.tsx +2 -0
- package/src/ui/PreviewOriginsNotice.tsx +39 -0
- package/src/version.ts +1 -1
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.10.
|
|
1305
|
+
export declare const KIT_VERSION = "2.10.2";
|
|
1306
1306
|
/**
|
|
1307
1307
|
* Données de la page proposées comme colonnes.
|
|
1308
1308
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as defineComponentDefaults, i as defaultsFieldName, n as componentDefaultsMainDocument, o as requiredUnlessDefault, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-BY3hQ6aD.js";
|
|
2
|
-
import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, useSchema, useUser } from "sanity";
|
|
2
|
+
import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, useSchema, useUser, useWorkspace } from "sanity";
|
|
3
3
|
import { ClockIcon } from "@sanity/icons/Clock";
|
|
4
4
|
import { ComponentIcon } from "@sanity/icons/Component";
|
|
5
5
|
import { DocumentsIcon } from "@sanity/icons/Documents";
|
|
@@ -7,7 +7,7 @@ import { ColorWheelIcon } from "@sanity/icons/ColorWheel";
|
|
|
7
7
|
import { Badge, Box, Button, Card, Container, Flex, Grid, Select, Spinner, Stack, Tab, TabList, TabPanel, Text, TextArea, TextInput } from "@sanity/ui";
|
|
8
8
|
import { createContext, forwardRef, memo, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
9
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { IntentLink, useRouter } from "sanity/router";
|
|
10
|
+
import { IntentLink, useRouter, useRouterState } from "sanity/router";
|
|
11
11
|
import { EyeOpenIcon } from "@sanity/icons/EyeOpen";
|
|
12
12
|
import { LaunchIcon } from "@sanity/icons/Launch";
|
|
13
13
|
import { ArrowUpIcon } from "@sanity/icons/ArrowUp";
|
|
@@ -252,7 +252,7 @@ function validateConfig(config) {
|
|
|
252
252
|
}), config.previewUrl && !isAbsoluteHttpUrl(config.previewUrl) && error("previewUrl", `« ${config.previewUrl} » n'est pas une URL absolue. Attendu : https://exemple.fr`), config.componentPreview.provider === "designSystemPage" && (config.previewUrl || warn("previewUrl", "Aperçu des composants actif mais `previewUrl` est absent : les vignettes et les liens vers la page design system seront désactivés.", ["components"]), !config.componentPreview.thumbnail.includes("{name}") && !config.componentPreview.thumbnail.includes("{kebab}") && warn("componentPreview.thumbnail", "Le gabarit ne contient ni {name} ni {kebab} : tous les blocs afficheront la même image.", ["components"]));
|
|
253
253
|
let seenEnvironments = /* @__PURE__ */ new Set();
|
|
254
254
|
for (let environment of config.environments) isAbsoluteHttpUrl(environment.url) || error(`environments.${environment.id}.url`, `« ${environment.url} » n'est pas une URL absolue. L'aperçu ne pourra pas charger cet environnement.`, ["pages"]), seenEnvironments.has(environment.id) && error("environments", `Deux environnements portent l'identifiant « ${environment.id} » : le choix retenu serait imprévisible.`, ["pages"]), seenEnvironments.add(environment.id);
|
|
255
|
-
config.
|
|
255
|
+
config.tools.history && (config.history ? ((!config.history.endpoint || !isAbsoluteHttpUrl(config.history.endpoint)) && error("history.endpoint", `« ${config.history.endpoint || ""} » n'est pas une URL absolue vers l'Edge Function de lecture.`, ["history"]), config.history.projectKey?.trim() || error("history.projectKey", "`history.projectKey` est vide.", ["history"]), /^eyJ|^sb_secret_|service_role/i.test(config.history.projectKey ?? "") && error("history.projectKey", "Cette valeur ressemble à une clé Supabase. Le Studio est public : n'y place jamais qu'un identifiant de projet opaque, sans droit d'écriture.", ["history"])) : warn("history", "L'onglet Historique est activé mais aucune clé de lecture n'est configurée. Lance `npx ncf-kit setup` dans le dossier du studio (elle est écrite dans .env), ou passe tools: {history: false}.", ["history"]));
|
|
256
256
|
let fieldIds = /* @__PURE__ */ new Set();
|
|
257
257
|
return config.internalFields.forEach((field, index) => {
|
|
258
258
|
let at = `internalFields[${index}]`;
|
|
@@ -1082,6 +1082,26 @@ function ncfAllowedOrigins(config) {
|
|
|
1082
1082
|
}).filter((origin) => !!origin);
|
|
1083
1083
|
return [...new Set(origins)];
|
|
1084
1084
|
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Origines d'aperçu que Presentation refuserait : celles des environnements du kit
|
|
1087
|
+
* qui ne correspondent à aucune entrée de `allowOrigins` (motifs avec `*` acceptés)
|
|
1088
|
+
* ni à l'origine de son `previewUrl` (toujours autorisée). Sans liste lisible
|
|
1089
|
+
* (fonction, absente) : rien n'est signalé, faute de pouvoir vérifier.
|
|
1090
|
+
*/
|
|
1091
|
+
function missingPreviewOrigins(required, presentationOptions) {
|
|
1092
|
+
let allow = presentationOptions?.allowOrigins;
|
|
1093
|
+
if (!Array.isArray(allow)) return [];
|
|
1094
|
+
let patterns = allow.filter((p) => typeof p == "string"), preview = presentationOptions?.previewUrl, previewOrigin = (() => {
|
|
1095
|
+
let raw = typeof preview == "string" ? preview : preview?.origin;
|
|
1096
|
+
if (typeof raw != "string") return null;
|
|
1097
|
+
try {
|
|
1098
|
+
return new URL(raw).origin;
|
|
1099
|
+
} catch {
|
|
1100
|
+
return null;
|
|
1101
|
+
}
|
|
1102
|
+
})(), matches = (origin, pattern) => RegExp(`^${pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`).test(origin);
|
|
1103
|
+
return required.filter((origin) => origin !== previewOrigin && !patterns.some((p) => matches(origin, p)));
|
|
1104
|
+
}
|
|
1085
1105
|
/** Identifiant de l'environnement libre, saisi à la volée. */
|
|
1086
1106
|
const CUSTOM_ENVIRONMENT_ID = "ncf-custom";
|
|
1087
1107
|
/**
|
|
@@ -1314,7 +1334,7 @@ function explainGrantError(error) {
|
|
|
1314
1334
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1315
1335
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1316
1336
|
*/
|
|
1317
|
-
const KIT_VERSION = "2.10.
|
|
1337
|
+
const KIT_VERSION = "2.10.2";
|
|
1318
1338
|
/**
|
|
1319
1339
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1320
1340
|
*
|
|
@@ -1397,6 +1417,48 @@ function ProjectStatusNotice(props) {
|
|
|
1397
1417
|
});
|
|
1398
1418
|
}
|
|
1399
1419
|
/**
|
|
1420
|
+
* Vérifie pour de vrai que Presentation accepte chaque environnement d'aperçu du kit
|
|
1421
|
+
* (option `allowOrigins`). Ne s'affiche que s'il en manque : sans elle, l'aperçu de
|
|
1422
|
+
* cet environnement s'affiche mais reste muet (ni édition visuelle, ni surlignage).
|
|
1423
|
+
*/
|
|
1424
|
+
function PreviewOriginsNotice() {
|
|
1425
|
+
let config = useKitConfig(), { tools } = useWorkspace(), presentation = tools.find((tool) => tool.__internalApplicationType === "sanity/presentation" || tool.name === "presentation");
|
|
1426
|
+
if (!presentation) return null;
|
|
1427
|
+
let missing = missingPreviewOrigins(ncfAllowedOrigins(config), presentation.options);
|
|
1428
|
+
return missing.length === 0 ? null : /* @__PURE__ */ jsx(Container, {
|
|
1429
|
+
width: 2,
|
|
1430
|
+
children: /* @__PURE__ */ jsx(Card, {
|
|
1431
|
+
padding: 4,
|
|
1432
|
+
radius: 3,
|
|
1433
|
+
shadow: 1,
|
|
1434
|
+
tone: "caution",
|
|
1435
|
+
children: /* @__PURE__ */ jsxs(Stack, {
|
|
1436
|
+
gap: 3,
|
|
1437
|
+
children: [
|
|
1438
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
1439
|
+
weight: "semibold",
|
|
1440
|
+
children: ["Aperçu muet sur ", missing.length > 1 ? "ces environnements" : "cet environnement"]
|
|
1441
|
+
}),
|
|
1442
|
+
/* @__PURE__ */ jsx(Stack, {
|
|
1443
|
+
gap: 2,
|
|
1444
|
+
children: missing.map((origin) => /* @__PURE__ */ jsx(InlineCode, { children: origin }, origin))
|
|
1445
|
+
}),
|
|
1446
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
1447
|
+
size: 1,
|
|
1448
|
+
children: [
|
|
1449
|
+
"Presentation n'autorise pas ",
|
|
1450
|
+
missing.length > 1 ? "ces origines" : "cette origine",
|
|
1451
|
+
" : la page s'affiche sans édition visuelle. Dans sanity.config.ts, passer ",
|
|
1452
|
+
/* @__PURE__ */ jsx(InlineCode, { children: "allowOrigins: ncfAllowedOrigins(options)" }),
|
|
1453
|
+
" à presentationTool."
|
|
1454
|
+
]
|
|
1455
|
+
})
|
|
1456
|
+
]
|
|
1457
|
+
})
|
|
1458
|
+
})
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1400
1462
|
* Signale la présence du Studio et rend l'avis qui en découle.
|
|
1401
1463
|
*
|
|
1402
1464
|
* Monté dans l'enveloppe plutôt que dans chaque outil : le signalement doit
|
|
@@ -1429,6 +1491,7 @@ function createToolComponent(args) {
|
|
|
1429
1491
|
issues: scoped,
|
|
1430
1492
|
toolTitle: title
|
|
1431
1493
|
}),
|
|
1494
|
+
name === "pages" && /* @__PURE__ */ jsx(PreviewOriginsNotice, {}),
|
|
1432
1495
|
/* @__PURE__ */ jsx(Registered, {}),
|
|
1433
1496
|
blocking ? null : /* @__PURE__ */ jsx(Component, {})
|
|
1434
1497
|
]
|
|
@@ -1625,7 +1688,7 @@ function useKitUpdate() {
|
|
|
1625
1688
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1626
1689
|
}).catch(() => {}), () => controller.abort();
|
|
1627
1690
|
}, []);
|
|
1628
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.10.
|
|
1691
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.10.2") > 0);
|
|
1629
1692
|
return {
|
|
1630
1693
|
current: KIT_VERSION,
|
|
1631
1694
|
latest,
|
|
@@ -7355,6 +7418,23 @@ function useComponentDefaults(client, type, languageField, language) {
|
|
|
7355
7418
|
entry.listeners.size === 0 && entry.stop && (entry.stop(), entry.stop = null);
|
|
7356
7419
|
}, [entry]), value;
|
|
7357
7420
|
}
|
|
7421
|
+
/** Noms des outils Presentation du workspace (le nom est configurable). */
|
|
7422
|
+
function presentationToolNames(tools) {
|
|
7423
|
+
return tools.filter((t) => t.__internalApplicationType === "sanity/presentation" || t.name === "presentation").map((t) => t.name);
|
|
7424
|
+
}
|
|
7425
|
+
/** Vrai si l'adresse du Studio est dans un de ces outils (premier segment après la base). */
|
|
7426
|
+
function isInTool(pathname, names) {
|
|
7427
|
+
return pathname.split("/").some((segment) => names.includes(segment));
|
|
7428
|
+
}
|
|
7429
|
+
/**
|
|
7430
|
+
* Le formulaire est-il affiché dans Presentation ? Le routeur sert à se mettre à jour
|
|
7431
|
+
* quand on change d'outil ; l'adresse dit lequel (le formulaire de Presentation est rendu
|
|
7432
|
+
* dans la portée de son outil, qui ne porte pas le nom de l'outil).
|
|
7433
|
+
*/
|
|
7434
|
+
function useInPresentation() {
|
|
7435
|
+
let { tools } = useWorkspace();
|
|
7436
|
+
return useRouterState(), typeof window > "u" ? !1 : isInTool(window.location.pathname, presentationToolNames(tools));
|
|
7437
|
+
}
|
|
7358
7438
|
const LINK_TARGET_FIELDS = [
|
|
7359
7439
|
"page",
|
|
7360
7440
|
"fixedPath",
|
|
@@ -7529,7 +7609,9 @@ function createOverrideInput(config) {
|
|
|
7529
7609
|
});
|
|
7530
7610
|
}
|
|
7531
7611
|
function WithMainInstance(props) {
|
|
7532
|
-
let { type, ...inputProps } = props, client = useKitClient(), router = useRouter()
|
|
7612
|
+
let { type, ...inputProps } = props, client = useKitClient(), router = useRouter();
|
|
7613
|
+
if (useInPresentation()) return inputProps.renderDefault(inputProps);
|
|
7614
|
+
let open = () => void openComponentDefaults({
|
|
7533
7615
|
type,
|
|
7534
7616
|
config,
|
|
7535
7617
|
hasDefaults: !0,
|