@nocode-factory/sanity-kit 2.17.0 → 2.17.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 CHANGED
@@ -1303,7 +1303,7 @@ export declare function ActorName(props: {
1303
1303
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1304
1304
  * le vérifie.
1305
1305
  */
1306
- export declare const KIT_VERSION = "2.17.0";
1306
+ export declare const KIT_VERSION = "2.17.2";
1307
1307
  /**
1308
1308
  * Données de la page proposées comme colonnes.
1309
1309
  *
package/dist/index.js CHANGED
@@ -1046,6 +1046,19 @@ function effectivePerspective(environment, perspective, previewUrl) {
1046
1046
  return environment && isPublicEnvironment(environment, previewUrl) ? "published" : perspective;
1047
1047
  }
1048
1048
  /**
1049
+ * Environnement où ouvrir Presentation : on n'édite jamais la production (elle ne
1050
+ * montre pas les brouillons et ne charge pas l'édition visuelle : « Unable to
1051
+ * connect »). Production choisie : la première préversion déclarée, qui montrera
1052
+ * le contenu en ligne. Sans préversion : l'environnement choisi, tel quel.
1053
+ */
1054
+ function editableEnvironment(selected, environments, previewUrl) {
1055
+ return !selected || !isPublicEnvironment(selected, previewUrl) ? selected : environments.find((e) => !isPublicEnvironment(e, previewUrl)) ?? selected;
1056
+ }
1057
+ /** Environnement proposé par défaut : la première préversion, sinon le premier déclaré. */
1058
+ function defaultEnvironmentId(environments, previewUrl) {
1059
+ return (environments.find((e) => !isPublicEnvironment(e, previewUrl)) ?? environments[0])?.id ?? null;
1060
+ }
1061
+ /**
1049
1062
  * URL du vrai site, en ligne, pour un environnement et un état de contenu.
1050
1063
  *
1051
1064
  * - Production : l'URL simple. Elle ne montre jamais de brouillons, et la
@@ -1178,7 +1191,7 @@ function write(key, value) {
1178
1191
  * différents sans se déranger.
1179
1192
  */
1180
1193
  function usePreviewTargetState() {
1181
- let config = useKitConfig(), scope = `ncf-kit:preview-target:${useKitClient().config().projectId ?? "sans-projet"}`, environments = config.environments, fallback = environments[0]?.id ?? null, [environmentId, setStoredEnvironment] = useState(() => {
1194
+ let config = useKitConfig(), scope = `ncf-kit:preview-target:${useKitClient().config().projectId ?? "sans-projet"}`, environments = config.environments, fallback = defaultEnvironmentId(environments, config.previewUrl), [environmentId, setStoredEnvironment] = useState(() => {
1182
1195
  let saved = read(`${scope}:environment`);
1183
1196
  return saved && environments.some((e) => e.id === saved) ? saved : fallback;
1184
1197
  }), [customUrl, setStoredCustomUrl] = useState(() => read(`${scope}:custom`)), [perspective, setStoredPerspective] = useState(() => read(`${scope}:perspective`) === "published" ? "published" : "drafts"), setEnvironment = useCallback((id) => {
@@ -1190,9 +1203,14 @@ function usePreviewTargetState() {
1190
1203
  setEnvironment,
1191
1204
  fallback
1192
1205
  ]), shown = effectivePerspective(environment, perspective, config.previewUrl), pathFor = useCallback((url) => presentationPath(url, {
1193
- environment,
1206
+ environment: editableEnvironment(environment, allEnvironments, config.previewUrl),
1194
1207
  perspective: shown
1195
- }), [environment, shown]), siteUrlFor = useCallback((url) => {
1208
+ }), [
1209
+ environment,
1210
+ allEnvironments,
1211
+ config.previewUrl,
1212
+ shown
1213
+ ]), siteUrlFor = useCallback((url) => {
1196
1214
  if (!url) return null;
1197
1215
  if (!environment) return url;
1198
1216
  try {
@@ -1362,7 +1380,7 @@ function explainGrantError(error) {
1362
1380
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1363
1381
  * le vérifie.
1364
1382
  */
1365
- const KIT_VERSION = "2.17.0";
1383
+ const KIT_VERSION = "2.17.2";
1366
1384
  /**
1367
1385
  * Signale ce Studio au service du kit, une fois par montage.
1368
1386
  *
@@ -1689,7 +1707,7 @@ function useKitUpdate() {
1689
1707
  !controller.signal.aborted && body?.version && setLatest(body.version);
1690
1708
  }).catch(() => {}), () => controller.abort();
1691
1709
  }, []);
1692
- let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.17.0") > 0);
1710
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.17.2") > 0);
1693
1711
  return {
1694
1712
  current: KIT_VERSION,
1695
1713
  latest,
@@ -1947,9 +1965,9 @@ function NcfPreviewLauncher(props) {
1947
1965
  }), /* @__PURE__ */ jsx(NcfKitUpdate, { inline: props.context === "topbar" })]
1948
1966
  });
1949
1967
  let openInStudio = (environment, perspective) => {
1950
- let path = presentationPath(environment.url, {
1951
- environment,
1952
- perspective
1968
+ let target = editableEnvironment(environment, environments, config.previewUrl) ?? environment, shown = isPublicEnvironment(environment, config.previewUrl) ? "published" : perspective, path = presentationPath(target.url, {
1969
+ environment: target,
1970
+ perspective: shown
1953
1971
  });
1954
1972
  path && router.navigateUrl({ path });
1955
1973
  }, openOnline = (environment, perspective) => {
@@ -5917,7 +5935,7 @@ async function openDesignSystem(options) {
5917
5935
  navigateIntent("edit", designSystemIntentParams(config, await defaultsDocumentId(config, client) ?? config.componentPreview.defaultsType));
5918
5936
  return;
5919
5937
  }
5920
- let path = presentationPath(config.previewUrl ? `${config.previewUrl}${config.componentPreview.path}` : null);
5938
+ let env = editableEnvironment(config.environments[0] ?? null, config.environments, config.previewUrl), path = presentationPath(urlOn(env, config.componentPreview.path) ?? (config.previewUrl ? `${config.previewUrl}${config.componentPreview.path}` : null), env ? { environment: env } : {});
5921
5939
  path && navigateUrl(path);
5922
5940
  }
5923
5941
  /** Ouvre un composant (voir openComponentDefaults). `null` : rien à ouvrir. */