@nocode-factory/sanity-kit 2.14.0 → 2.14.1

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
@@ -1309,7 +1309,7 @@ export declare function ActorName(props: {
1309
1309
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1310
1310
  * le vérifie.
1311
1311
  */
1312
- export declare const KIT_VERSION = "2.14.0";
1312
+ export declare const KIT_VERSION = "2.14.1";
1313
1313
  /**
1314
1314
  * Données de la page proposées comme colonnes.
1315
1315
  *
package/dist/index.js CHANGED
@@ -1364,7 +1364,7 @@ function explainGrantError(error) {
1364
1364
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1365
1365
  * le vérifie.
1366
1366
  */
1367
- const KIT_VERSION = "2.14.0";
1367
+ const KIT_VERSION = "2.14.1";
1368
1368
  /**
1369
1369
  * Signale ce Studio au service du kit, une fois par montage.
1370
1370
  *
@@ -1691,7 +1691,7 @@ function useKitUpdate() {
1691
1691
  !controller.signal.aborted && body?.version && setLatest(body.version);
1692
1692
  }).catch(() => {}), () => controller.abort();
1693
1693
  }, []);
1694
- let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.14.0") > 0);
1694
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.14.1") > 0);
1695
1695
  return {
1696
1696
  current: KIT_VERSION,
1697
1697
  latest,
@@ -7475,9 +7475,9 @@ function sinceLabel(iso, now = Date.now()) {
7475
7475
  * suppression relance la requête (regroupées, une fois par demi-seconde au plus).
7476
7476
  */
7477
7477
  function useDrafts(currentId) {
7478
- let client = useKitClient(), schema = useSchema(), [rows, setRows] = useState(null);
7479
- return useEffect(() => {
7480
- let cancelled = !1, timer, load = async () => {
7478
+ let client = useKitClient(), schema = useSchema(), [rows, setRows] = useState(null), [reloadKey, setReloadKey] = useState(0);
7479
+ useEffect(() => {
7480
+ let cancelled = !1, timer, retry, subscription, load = async () => {
7481
7481
  let drafts = await client.fetch("*[_id in path(\"drafts.**\")]{_id, _rev, _type, _updatedAt}"), published = await client.fetch("*[_id in $ids]._id", { ids: drafts.map((d) => publishedIdOf(d._id)) });
7482
7482
  cancelled || setRows({
7483
7483
  drafts,
@@ -7485,30 +7485,42 @@ function useDrafts(currentId) {
7485
7485
  });
7486
7486
  };
7487
7487
  load().catch(() => {
7488
- cancelled || setRows({
7488
+ cancelled || setRows((prev) => prev ?? {
7489
7489
  drafts: [],
7490
7490
  published: []
7491
7491
  });
7492
7492
  });
7493
- let subscription = client.listen("*[_id in path(\"drafts.**\") || _id in path(\"*\")]", {}, {
7494
- visibility: "query",
7495
- includeResult: !1,
7496
- events: ["mutation"]
7497
- }).subscribe(() => {
7498
- clearTimeout(timer), timer = setTimeout(() => void load().catch(() => {}), 500);
7499
- });
7500
- return () => {
7501
- cancelled = !0, clearTimeout(timer), subscription.unsubscribe();
7493
+ let listen = (delay) => {
7494
+ subscription = client.listen("*[_id in path(\"drafts.**\") || _id in path(\"*\")]", {}, {
7495
+ visibility: "query",
7496
+ includeResult: !1,
7497
+ events: ["mutation"]
7498
+ }).subscribe({
7499
+ next: () => {
7500
+ clearTimeout(timer), timer = setTimeout(() => void load().catch(() => {}), 500);
7501
+ },
7502
+ error: () => {
7503
+ cancelled || (retry = setTimeout(() => listen(Math.min(delay * 2, 12e4)), delay));
7504
+ }
7505
+ });
7502
7506
  };
7503
- }, [client]), useMemo(() => rows ? publishableDrafts(rows.drafts, rows.published, {
7504
- isDocumentType: (type) => schema.get(type)?.jsonType === "object" && isDocumentSchema(schema.get(type)),
7505
- isInternalType: isKitType,
7506
- currentId
7507
- }) : null, [
7508
- rows,
7509
- schema,
7510
- currentId
7511
- ]);
7507
+ return listen(15e3), () => {
7508
+ cancelled = !0, clearTimeout(timer), clearTimeout(retry), subscription?.unsubscribe();
7509
+ };
7510
+ }, [client, reloadKey]);
7511
+ let reload = useCallback(() => setReloadKey((k) => k + 1), []);
7512
+ return {
7513
+ drafts: useMemo(() => rows ? publishableDrafts(rows.drafts, rows.published, {
7514
+ isDocumentType: (type) => schema.get(type)?.jsonType === "object" && isDocumentSchema(schema.get(type)),
7515
+ isInternalType: isKitType,
7516
+ currentId
7517
+ }) : null, [
7518
+ rows,
7519
+ schema,
7520
+ currentId
7521
+ ]),
7522
+ reload
7523
+ };
7512
7524
  }
7513
7525
  function isDocumentSchema(type) {
7514
7526
  let current = type;
@@ -7529,7 +7541,7 @@ function isDocumentSchema(type) {
7529
7541
  */
7530
7542
  function createBatchPublishAction(original) {
7531
7543
  let BatchPublishAction = (props) => {
7532
- let base = original(props), drafts = useDrafts(props.id), [open, setOpen] = useState(!1);
7544
+ let base = original(props), { drafts, reload } = useDrafts(props.id), [open, setOpen] = useState(!1);
7533
7545
  if (!base || props.release || props.version || !drafts) return base;
7534
7546
  let current = publishedIdOf(props.id);
7535
7547
  return drafts.filter((d) => d.publishedId !== current).length === 0 ? base : {
@@ -7538,7 +7550,9 @@ function createBatchPublishAction(original) {
7538
7550
  title: "Choisir les brouillons à publier, ensemble",
7539
7551
  icon: PublishIcon,
7540
7552
  disabled: !1,
7541
- onHandle: () => setOpen(!0),
7553
+ onHandle: () => {
7554
+ reload(), setOpen(!0);
7555
+ },
7542
7556
  dialog: open ? {
7543
7557
  type: "dialog",
7544
7558
  width: "medium",