@nocode-factory/sanity-kit 2.35.0 → 2.36.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
@@ -1389,7 +1389,7 @@ export declare function ActorName(props: {
1389
1389
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1390
1390
  * le vérifie.
1391
1391
  */
1392
- export declare const KIT_VERSION = "2.35.0";
1392
+ export declare const KIT_VERSION = "2.36.0";
1393
1393
  /**
1394
1394
  * Données de la page proposées comme colonnes.
1395
1395
  *
package/dist/index.js CHANGED
@@ -1384,7 +1384,7 @@ function explainGrantError(error) {
1384
1384
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1385
1385
  * le vérifie.
1386
1386
  */
1387
- const KIT_VERSION = "2.35.0";
1387
+ const KIT_VERSION = "2.36.0";
1388
1388
  /**
1389
1389
  * Signale ce Studio au service du kit, une fois par montage.
1390
1390
  *
@@ -1727,7 +1727,7 @@ function useKitUpdate() {
1727
1727
  !controller.signal.aborted && body?.version && setLatest(body.version);
1728
1728
  }).catch(() => {}), () => controller.abort();
1729
1729
  }, []);
1730
- let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.35.0") > 0);
1730
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.36.0") > 0);
1731
1731
  return {
1732
1732
  current: KIT_VERSION,
1733
1733
  latest,
@@ -8628,23 +8628,56 @@ function OverrideDot(props) {
8628
8628
  * leurs liens vers elle disparaîtront du site. Une référence FORTE (non `weak`)
8629
8629
  * empêche Sanity de dépublier : le message l'explique au lieu d'une erreur brute.
8630
8630
  */
8631
- const RemoveFromSiteAction = (props) => {
8632
- let client = useKitClient(), [open, setOpen] = useState(!1), [referrers, setReferrers] = useState(null), [busy, setBusy] = useState(!1), [error, setError] = useState(null);
8633
- if (useEffect(() => {
8634
- open && (setReferrers(null), client.fetch("*[references($id) && !(_id in path(\"drafts.**\")) && _type != \"translation.metadata\"]{_id, _type, \"title\": coalesce(title, name, _id)}", { id: props.id }).then(setReferrers).catch(() => setReferrers([])));
8631
+ const RemoveFromSiteAction = createRemoveFromSite();
8632
+ /**
8633
+ * Variante multilingue : sur la version PRINCIPALE d'un document traduit (page ou
8634
+ * fiche de collection), la fenêtre propose aussi de retirer du site ses autres
8635
+ * langues publiées (cochées par défaut), en une seule opération.
8636
+ */
8637
+ function createRemoveFromSite(config, masterLocale) {
8638
+ let i18n = config?.i18n, master = masterLocale ?? i18n?.defaultLocale, Action = (props) => useRemoveFromSite(props, i18n?.field, master);
8639
+ return Action.action = "unpublish", Action;
8640
+ }
8641
+ function useRemoveFromSite(props, field, master) {
8642
+ let client = useKitClient(), current = props.draft ?? props.published, isMaster = !!field && !!master && current?.[field] === master, [versions, setVersions] = useState([]), [open, setOpen] = useState(!1), [referrers, setReferrers] = useState(null), [busy, setBusy] = useState(!1), [error, setError] = useState(null);
8643
+ useEffect(() => {
8644
+ if (!open || !isMaster) return;
8645
+ let alive = !0;
8646
+ return translationsOf(client, props.id).then(async (list) => {
8647
+ let others = list.filter((t) => t.id !== props.id), live = new Set(await client.fetch("*[_id in $ids]._id", { ids: others.map((t) => t.id) }));
8648
+ alive && setVersions(others.filter((t) => live.has(t.id)).map((t) => ({
8649
+ ...t,
8650
+ selected: !0
8651
+ })));
8652
+ }).catch(() => alive && setVersions([])), () => {
8653
+ alive = !1;
8654
+ };
8635
8655
  }, [
8636
8656
  open,
8657
+ isMaster,
8637
8658
  client,
8638
8659
  props.id
8660
+ ]);
8661
+ let ids = [props.id, ...versions.filter((v) => v.selected).map((v) => v.id)];
8662
+ if (useEffect(() => {
8663
+ open && (setReferrers(null), client.fetch("*[references($ids) && !(_id in path(\"drafts.**\")) && !(_id in $ids) && _type != \"translation.metadata\"]{_id, _type, \"title\": coalesce(title, name, _id)}", { ids }).then(setReferrers).catch(() => setReferrers([])));
8664
+ }, [
8665
+ open,
8666
+ client,
8667
+ ids.join(",")
8639
8668
  ]), !props.published) return null;
8640
8669
  let confirm = async () => {
8641
8670
  setBusy(!0), setError(null);
8642
8671
  try {
8643
- let { _rev, _updatedAt, ...published } = props.published, tx = client.transaction();
8644
- props.draft || tx.createIfNotExists({
8645
- ...published,
8646
- _id: `drafts.${props.id}`
8647
- }), tx.delete(props.id), await tx.commit(), setOpen(!1), props.onComplete();
8672
+ let tx = client.transaction(), docs = await client.fetch("*[_id in $ids]", { ids }), drafts = new Set(await client.fetch("*[_id in $drafts]._id", { drafts: ids.map((id) => `drafts.${id}`) }));
8673
+ for (let doc of docs) {
8674
+ let { _rev, _updatedAt, ...published } = doc, id = String(doc._id);
8675
+ drafts.has(`drafts.${id}`) || tx.createIfNotExists({
8676
+ ...published,
8677
+ _id: `drafts.${id}`
8678
+ }), tx.delete(id);
8679
+ }
8680
+ await tx.commit(), setOpen(!1), props.onComplete();
8648
8681
  } catch (cause) {
8649
8682
  let message = cause instanceof Error ? cause.message : String(cause);
8650
8683
  setError(/referenc/i.test(message) ? "Sanity refused: a published document points to this page with a strong reference. Remove or change that link, then try again." : `Removal failed, nothing was changed. (${message.slice(0, 140)})`);
@@ -8671,16 +8704,44 @@ const RemoveFromSiteAction = (props) => {
8671
8704
  children: [
8672
8705
  /* @__PURE__ */ jsx(Text, {
8673
8706
  size: 1,
8674
- children: "The page leaves the site (production and staging \"Published\"). All its content stays in the draft: to put it back online, publish it."
8707
+ children: "It leaves the site (production and staging \"Published\"). All its content stays in the draft: to put it back online, publish it."
8708
+ }),
8709
+ versions.length > 0 && /* @__PURE__ */ jsxs(Stack, {
8710
+ gap: 2,
8711
+ children: [/* @__PURE__ */ jsx(Text, {
8712
+ size: 1,
8713
+ weight: "semibold",
8714
+ children: "Also remove the other languages from the site:"
8715
+ }), versions.map((v, index) => /* @__PURE__ */ jsx(Card, {
8716
+ padding: 2,
8717
+ radius: 2,
8718
+ border: !0,
8719
+ children: /* @__PURE__ */ jsxs(Flex, {
8720
+ as: "label",
8721
+ gap: 3,
8722
+ align: "center",
8723
+ children: [/* @__PURE__ */ jsx(Checkbox, {
8724
+ checked: v.selected,
8725
+ disabled: busy,
8726
+ onChange: () => setVersions(versions.map((x, i) => i === index ? {
8727
+ ...x,
8728
+ selected: !x.selected
8729
+ } : x))
8730
+ }), /* @__PURE__ */ jsx(Text, {
8731
+ size: 1,
8732
+ children: v.language.toUpperCase()
8733
+ })]
8734
+ })
8735
+ }, v.id))]
8675
8736
  }),
8676
8737
  referrers === null ? /* @__PURE__ */ jsx(Text, {
8677
8738
  size: 1,
8678
8739
  muted: !0,
8679
- children: "Looking for links to this page…"
8740
+ children: "Looking for links…"
8680
8741
  }) : referrers.length > 0 ? /* @__PURE__ */ jsxs(Text, {
8681
8742
  size: 1,
8682
8743
  children: [
8683
- "These published documents point to it; their links to this page will disappear from the site:",
8744
+ "These published documents point to it; their links will disappear from the site:",
8684
8745
  " ",
8685
8746
  referrers.map((r) => r.title || r._id).join(", "),
8686
8747
  "."
@@ -8688,7 +8749,7 @@ const RemoveFromSiteAction = (props) => {
8688
8749
  }) : /* @__PURE__ */ jsx(Text, {
8689
8750
  size: 1,
8690
8751
  muted: !0,
8691
- children: "No published document points to this page."
8752
+ children: "No published document points to it."
8692
8753
  }),
8693
8754
  error && /* @__PURE__ */ jsx(Text, {
8694
8755
  size: 1,
@@ -8699,8 +8760,7 @@ const RemoveFromSiteAction = (props) => {
8699
8760
  })
8700
8761
  }
8701
8762
  };
8702
- };
8703
- RemoveFromSiteAction.action = "unpublish";
8763
+ }
8704
8764
  /**
8705
8765
  * Sous le champ Slug d'une page (types de pages du kit) : l'adresse COMPLÈTE de la
8706
8766
  * page sur le site en ligne, avec « Copier » et « Ouvrir ». Le slug seul ne dit pas
@@ -9325,6 +9385,184 @@ function summary(r) {
9325
9385
  let parts = [];
9326
9386
  return r.added && parts.push(`${r.added} item${r.added > 1 ? "s" : ""} added`), r.removed && parts.push(`${r.removed} removed`), r.moved && parts.push("order updated"), r.copied.length && parts.push(`${r.copied.length} value${r.copied.length > 1 ? "s" : ""} copied (images, links, options…)`), r.toTranslate.length && parts.push(`${r.toTranslate.length} text${r.toTranslate.length > 1 ? "s" : ""} to translate`), parts.join(" · ");
9327
9387
  }
9388
+ /** Identifiants publiés + brouillons d'une liste de documents. */
9389
+ const withDrafts = (ids) => ids.flatMap((id) => [id, `drafts.${id}`]);
9390
+ /**
9391
+ * Supprimer la version PRINCIPALE d'un document traduit (page, fiche de collection,
9392
+ * réglage par langue) : la fenêtre propose de supprimer aussi ses autres langues
9393
+ * (cochées par défaut), en une fois. Bloqué, avec la liste, si un autre document y
9394
+ * fait encore référence (comme la suppression native de Sanity). Les liens de
9395
+ * traduction sont nettoyés. Sans traduction, ou depuis une autre langue : la
9396
+ * suppression native, inchangée.
9397
+ */
9398
+ function withTranslationDelete(Delete, config, masterLocale) {
9399
+ let i18n = config.i18n, master = masterLocale ?? i18n?.defaultLocale, Wrapped = (props) => {
9400
+ let base = Delete(props), client = useKitClient(), [versions, setVersions] = useState(null), current = props.draft ?? props.published;
9401
+ useEffect(() => {
9402
+ if (!i18n || current?.[i18n.field] !== master) return;
9403
+ let alive = !0;
9404
+ return translationsOf(client, props.id).then((list) => alive && setVersions(list.filter((t) => t.id !== props.id).map((t) => ({
9405
+ ...t,
9406
+ selected: !0
9407
+ })))).catch(() => alive && setVersions([])), () => {
9408
+ alive = !1;
9409
+ };
9410
+ }, [
9411
+ client,
9412
+ props.id,
9413
+ current?.[i18n?.field ?? "language"]
9414
+ ]);
9415
+ let [open, setOpen] = useState(!1);
9416
+ return !base || !i18n || current?.[i18n.field] !== master || !versions?.length ? base : {
9417
+ ...base,
9418
+ onHandle: () => setOpen(!0),
9419
+ dialog: open ? {
9420
+ type: "dialog",
9421
+ header: "Delete this document",
9422
+ width: "medium",
9423
+ onClose: () => setOpen(!1),
9424
+ content: /* @__PURE__ */ jsx(DeleteDialog, {
9425
+ id: props.id,
9426
+ language: String(current?.[i18n.field] ?? ""),
9427
+ versions,
9428
+ onDone: () => {
9429
+ setOpen(!1), props.onComplete();
9430
+ }
9431
+ })
9432
+ } : base.dialog
9433
+ };
9434
+ };
9435
+ return Wrapped;
9436
+ }
9437
+ function DeleteDialog(props) {
9438
+ let { id, language, onDone } = props, client = useKitClient(), toast = useToast(), [versions, setVersions] = useState(props.versions), [referrers, setReferrers] = useState(null), [busy, setBusy] = useState(!1), [error, setError] = useState(null), ids = [id, ...versions.filter((v) => v.selected).map((v) => v.id)], key = ids.join(",");
9439
+ useEffect(() => {
9440
+ setReferrers(null);
9441
+ let all = withDrafts(ids);
9442
+ client.fetch("*[references($ids) && !(_id in $all) && _type != \"translation.metadata\"]{_id, _type, \"title\": coalesce(title, name, heading, _id)}", {
9443
+ ids,
9444
+ all
9445
+ }).then(setReferrers).catch(() => setReferrers([]));
9446
+ }, [client, key]);
9447
+ let remove = async () => {
9448
+ setBusy(!0), setError(null);
9449
+ try {
9450
+ let tx = client.transaction();
9451
+ for (let docId of withDrafts(ids)) tx.delete(docId);
9452
+ let meta = await client.fetch("*[_type == \"translation.metadata\" && references($id)][0]{_id, translations}", { id });
9453
+ if (meta) {
9454
+ let gone = (meta.translations ?? []).filter((t) => ids.includes(t.value?._ref ?? ""));
9455
+ (meta.translations ?? []).length - gone.length > 1 ? tx.patch(meta._id, (p) => p.unset(gone.map((t) => `translations[_key == "${t._key}"]`))) : tx.delete(meta._id);
9456
+ }
9457
+ await tx.commit({ visibility: "async" }), toast.push({
9458
+ status: "success",
9459
+ title: `Deleted: ${[language, ...versions.filter((v) => v.selected).map((v) => v.language)].map((l) => l.toUpperCase()).join(", ")}`,
9460
+ duration: 6e3
9461
+ }), onDone();
9462
+ } catch (cause) {
9463
+ setError(`Failed. (${(cause instanceof Error ? cause.message : String(cause)).slice(0, 160)})`), setBusy(!1);
9464
+ }
9465
+ }, blocked = !!referrers?.length;
9466
+ return /* @__PURE__ */ jsxs(Stack, {
9467
+ gap: 4,
9468
+ padding: 4,
9469
+ children: [
9470
+ /* @__PURE__ */ jsxs(Text, {
9471
+ size: 1,
9472
+ children: [
9473
+ "The ",
9474
+ language.toUpperCase(),
9475
+ " version will be deleted for good (published and draft). Delete the other language versions too?"
9476
+ ]
9477
+ }),
9478
+ /* @__PURE__ */ jsx(Stack, {
9479
+ gap: 2,
9480
+ children: versions.map((v, index) => /* @__PURE__ */ jsx(Card, {
9481
+ padding: 3,
9482
+ radius: 2,
9483
+ border: !0,
9484
+ children: /* @__PURE__ */ jsxs(Flex, {
9485
+ as: "label",
9486
+ gap: 3,
9487
+ align: "center",
9488
+ children: [/* @__PURE__ */ jsx(Checkbox, {
9489
+ checked: v.selected,
9490
+ disabled: busy,
9491
+ onChange: () => setVersions(versions.map((x, i) => i === index ? {
9492
+ ...x,
9493
+ selected: !x.selected
9494
+ } : x))
9495
+ }), /* @__PURE__ */ jsx(Text, {
9496
+ size: 1,
9497
+ weight: "semibold",
9498
+ children: v.language.toUpperCase()
9499
+ })]
9500
+ })
9501
+ }, v.id))
9502
+ }),
9503
+ referrers === null ? /* @__PURE__ */ jsx(Flex, {
9504
+ justify: "center",
9505
+ children: /* @__PURE__ */ jsx(Spinner, { muted: !0 })
9506
+ }) : blocked ? /* @__PURE__ */ jsx(Card, {
9507
+ tone: "critical",
9508
+ padding: 3,
9509
+ radius: 2,
9510
+ children: /* @__PURE__ */ jsxs(Stack, {
9511
+ gap: 2,
9512
+ children: [
9513
+ /* @__PURE__ */ jsx(Text, {
9514
+ size: 1,
9515
+ children: "Still referenced by these documents: remove the references first."
9516
+ }),
9517
+ referrers.slice(0, 8).map((r) => /* @__PURE__ */ jsxs(Text, {
9518
+ size: 1,
9519
+ muted: !0,
9520
+ children: [
9521
+ r.title,
9522
+ " (",
9523
+ r._type,
9524
+ ")"
9525
+ ]
9526
+ }, r._id)),
9527
+ referrers.length > 8 && /* @__PURE__ */ jsxs(Text, {
9528
+ size: 1,
9529
+ muted: !0,
9530
+ children: [
9531
+ "…and ",
9532
+ referrers.length - 8,
9533
+ " more"
9534
+ ]
9535
+ })
9536
+ ]
9537
+ })
9538
+ }) : null,
9539
+ error && /* @__PURE__ */ jsx(Card, {
9540
+ tone: "critical",
9541
+ padding: 3,
9542
+ radius: 2,
9543
+ children: /* @__PURE__ */ jsx(Text, {
9544
+ size: 1,
9545
+ children: error
9546
+ })
9547
+ }),
9548
+ /* @__PURE__ */ jsxs(Flex, {
9549
+ justify: "flex-end",
9550
+ gap: 2,
9551
+ children: [/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Button, {
9552
+ text: "Cancel",
9553
+ mode: "ghost",
9554
+ onClick: onDone,
9555
+ disabled: busy
9556
+ }) }), /* @__PURE__ */ jsx(Button, {
9557
+ text: busy ? "Deleting…" : `Delete ${ids.length > 1 ? `${ids.length} versions` : `${language.toUpperCase()} only`}`,
9558
+ tone: "critical",
9559
+ onClick: () => void remove(),
9560
+ disabled: busy || referrers === null || blocked
9561
+ })]
9562
+ })
9563
+ ]
9564
+ });
9565
+ }
9328
9566
  /**
9329
9567
  * `pageTypes` déduits du registre du starter, pour ne pas redire au kit ce que
9330
9568
  * le site sait déjà : l'accueil (chemin fixe `/`) et chaque collection avec
@@ -9966,7 +10204,7 @@ const ncfKit = definePlugin((options) => {
9966
10204
  },
9967
10205
  document: {
9968
10206
  newDocumentOptions: (prev) => prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE),
9969
- actions: (prev, context) => config.pageTypeNames.includes(context.schemaType) ? prev.map((action) => action.action === "unpublish" ? RemoveFromSiteAction : action.action === "publish" && config.i18n ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action) : context.schemaType === config.componentPreview.defaultsType && config.i18n ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, config.i18n?.defaultsSourceLocale) : action) : config.i18n && !isKitType(context.schemaType) && hasLanguageField(context.schema.get(context.schemaType), config.i18n.field) ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action) : prev
10207
+ actions: (prev, context) => config.pageTypeNames.includes(context.schemaType) ? prev.map((action) => action.action === "unpublish" ? config.i18n ? createRemoveFromSite(config) : RemoveFromSiteAction : action.action === "publish" && config.i18n ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action.action === "delete" && config.i18n ? withTranslationDelete(action, config) : action) : context.schemaType === config.componentPreview.defaultsType && config.i18n ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, config.i18n?.defaultsSourceLocale) : action.action === "delete" ? withTranslationDelete(action, config, config.i18n?.defaultsSourceLocale) : action) : config.i18n && !isKitType(context.schemaType) && hasLanguageField(context.schema.get(context.schemaType), config.i18n.field) ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action.action === "delete" ? withTranslationDelete(action, config) : action.action === "unpublish" ? createRemoveFromSite(config) : action) : prev
9970
10208
  },
9971
10209
  studio: { components: { toolMenu: createPreviewLauncher(config, issues) } },
9972
10210
  form: { components: { input: createKitInput(config) } }