@nocode-factory/sanity-kit 2.67.0 → 2.68.0-rc.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/CHANGELOG.md +25 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +97 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/sharedListener.ts +101 -0
- package/src/hooks/useAssets.ts +1 -1
- package/src/hooks/useCollection.ts +1 -0
- package/src/hooks/useComponentDefaults.ts +1 -1
- package/src/hooks/useComponentNames.ts +1 -1
- package/src/hooks/usePageContents.ts +1 -0
- package/src/hooks/usePages.ts +1 -0
- package/src/hooks/useQueryData.ts +58 -21
- package/src/hooks/useRedirectMap.ts +1 -1
- package/src/hooks/useTranslationTodo.ts +1 -1
- package/src/hooks/useTranslationTodos.ts +1 -0
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Journal des versions
|
|
2
2
|
|
|
3
|
+
## 2.68.0 : le Studio interroge moins Sanity
|
|
4
|
+
|
|
5
|
+
### Changé
|
|
6
|
+
|
|
7
|
+
- **Listes du Studio** (onglet Pages, tableaux des collections, médias, traductions,
|
|
8
|
+
redirections) : avant, chaque frappe dans n'importe quel document relançait toute la
|
|
9
|
+
liste, environ une fois par seconde, et chaque vue envoyait le document entier à chaque
|
|
10
|
+
frappe. Désormais :
|
|
11
|
+
- Sanity n'envoie qu'un signal « ça a changé », jamais le document ;
|
|
12
|
+
- une seule écoute partagée par types, quel que soit le nombre de vues ouvertes, avec
|
|
13
|
+
reconnexion automatique si elle tombe (avant : la liste s'arrêtait de suivre sans
|
|
14
|
+
rien dire) ;
|
|
15
|
+
- au plus un rechargement toutes les 3 secondes pendant une saisie ;
|
|
16
|
+
- onglet du navigateur caché : rien n'est rechargé, la liste se met à jour au retour ;
|
|
17
|
+
- la liste des redirections (publiées seulement) ne réagit plus aux brouillons.
|
|
18
|
+
Pour l'utilisateur : les listes suivent avec 1 à 3 secondes de délai pendant une saisie ;
|
|
19
|
+
le bouton de rafraîchissement force toujours la mise à jour.
|
|
20
|
+
- **Étiquette sur chaque requête du kit** (`ncf-kit.pages`, `ncf-kit.collection.<type>`,
|
|
21
|
+
`ncf-kit.assets`...) : visible dans les journaux de requêtes de Sanity (sanity.io/manage,
|
|
22
|
+
projet, Usage, téléchargement des journaux), pour savoir qui consomme quoi.
|
|
23
|
+
|
|
24
|
+
### À brancher dans le projet
|
|
25
|
+
|
|
26
|
+
- Rien. Redéployer le Studio (`npm run deploy` dans studio/) : tout se passe dans le Studio.
|
|
27
|
+
|
|
3
28
|
## 2.67.0 : un seul interrupteur d'édition, celui de Sanity
|
|
4
29
|
|
|
5
30
|
### Changé
|
package/dist/index.d.ts
CHANGED
|
@@ -1483,7 +1483,7 @@ export declare function ActorName(props: {
|
|
|
1483
1483
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1484
1484
|
* le vérifie.
|
|
1485
1485
|
*/
|
|
1486
|
-
export declare const KIT_VERSION = "2.
|
|
1486
|
+
export declare const KIT_VERSION = "2.68.0-rc.1";
|
|
1487
1487
|
/**
|
|
1488
1488
|
* Données de la page proposées comme colonnes.
|
|
1489
1489
|
*
|
package/dist/index.js
CHANGED
|
@@ -1423,7 +1423,7 @@ function explainGrantError(error) {
|
|
|
1423
1423
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1424
1424
|
* le vérifie.
|
|
1425
1425
|
*/
|
|
1426
|
-
const KIT_VERSION = "2.
|
|
1426
|
+
const KIT_VERSION = "2.68.0-rc.1";
|
|
1427
1427
|
/**
|
|
1428
1428
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1429
1429
|
*
|
|
@@ -1931,7 +1931,7 @@ function useKitUpdate() {
|
|
|
1931
1931
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1932
1932
|
}).catch(() => {}), () => controller.abort();
|
|
1933
1933
|
}, []);
|
|
1934
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1934
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.68.0-rc.1") > 0);
|
|
1935
1935
|
return {
|
|
1936
1936
|
current: KIT_VERSION,
|
|
1937
1937
|
latest,
|
|
@@ -2300,19 +2300,64 @@ function createPreviewLauncher(config, issues) {
|
|
|
2300
2300
|
});
|
|
2301
2301
|
};
|
|
2302
2302
|
}
|
|
2303
|
+
const entries = /* @__PURE__ */ new Map(), RETRY_MIN_MS = 5e3;
|
|
2304
|
+
function listenFilter(types, publishedOnly) {
|
|
2305
|
+
return publishedOnly ? "*[_type in $types && !(_id in path(\"drafts.**\")) && !(_id in path(\"versions.**\"))]" : "*[_type in $types]";
|
|
2306
|
+
}
|
|
2307
|
+
function subscribeShared(client, types, publishedOnly, listener, tag) {
|
|
2308
|
+
let { projectId, dataset } = client.config(), sorted = [...types].sort(), key = `${projectId}:${dataset}:${publishedOnly ? "published" : "all"}:${sorted.join(",")}`, entry = entries.get(key);
|
|
2309
|
+
if (!entry) {
|
|
2310
|
+
let listeners = /* @__PURE__ */ new Set(), notify = () => listeners.forEach((l) => l()), retry = RETRY_MIN_MS, retryTimer, stopped = !1, unsubscribe = () => {}, open = (reconnect) => {
|
|
2311
|
+
let subscription = client.listen(listenFilter(sorted, publishedOnly), { types: sorted }, {
|
|
2312
|
+
visibility: "query",
|
|
2313
|
+
events: ["welcome", "mutation"],
|
|
2314
|
+
includeResult: !1,
|
|
2315
|
+
includePreviousRevision: !1,
|
|
2316
|
+
tag
|
|
2317
|
+
}).subscribe({
|
|
2318
|
+
next: (event) => {
|
|
2319
|
+
if (event.type === "welcome") {
|
|
2320
|
+
retry = RETRY_MIN_MS, reconnect && notify();
|
|
2321
|
+
return;
|
|
2322
|
+
}
|
|
2323
|
+
notify();
|
|
2324
|
+
},
|
|
2325
|
+
error: () => {
|
|
2326
|
+
stopped || (retryTimer = setTimeout(() => open(!0), retry), retry = Math.min(retry * 2, 6e4));
|
|
2327
|
+
}
|
|
2328
|
+
});
|
|
2329
|
+
unsubscribe = () => subscription.unsubscribe();
|
|
2330
|
+
};
|
|
2331
|
+
open(!1), entry = {
|
|
2332
|
+
listeners,
|
|
2333
|
+
stop: () => {
|
|
2334
|
+
stopped = !0, retryTimer && clearTimeout(retryTimer), unsubscribe();
|
|
2335
|
+
}
|
|
2336
|
+
}, entries.set(key, entry);
|
|
2337
|
+
}
|
|
2338
|
+
entry.listeners.add(listener);
|
|
2339
|
+
let current = entry;
|
|
2340
|
+
return () => {
|
|
2341
|
+
current.listeners.delete(listener), current.listeners.size === 0 && (current.stop(), entries.delete(key));
|
|
2342
|
+
};
|
|
2343
|
+
}
|
|
2344
|
+
/** Étiquette acceptée par Sanity : lettres, chiffres, . _ - (75 caractères au plus). */
|
|
2345
|
+
function kitTag(tag) {
|
|
2346
|
+
return `ncf-kit.${(tag ?? "query").replace(/[^a-zA-Z0-9._-]/g, "-").slice(0, 66)}`;
|
|
2347
|
+
}
|
|
2303
2348
|
/**
|
|
2304
2349
|
* Exécute une requête GROQ et la rejoue quand le contenu change.
|
|
2305
2350
|
*
|
|
2306
|
-
* Le rafraîchissement passe par un
|
|
2351
|
+
* Le rafraîchissement passe par un signal d'écoute puis une nouvelle requête, plutôt
|
|
2307
2352
|
* que par l'application des mutations reçues : c'est plus lent mais toujours
|
|
2308
2353
|
* cohérent, y compris quand une publication modifie plusieurs documents.
|
|
2309
2354
|
*/
|
|
2310
2355
|
function useQueryData(query, params, options = {}) {
|
|
2311
|
-
let client = useKitClient(), { listenTypes, enabled = !0 } = options, [data, setData] = useState(null), [loading, setLoading] = useState(enabled), [error, setError] = useState(null), [tick, setTick] = useState(0), refresh = useCallback(() => setTick((n) => n + 1), []), paramsKey = JSON.stringify(params), stableParams = useMemo(() => JSON.parse(paramsKey), [paramsKey]);
|
|
2356
|
+
let client = useKitClient(), { listenTypes, enabled = !0, publishedOnly = !1 } = options, tag = kitTag(options.tag), [data, setData] = useState(null), [loading, setLoading] = useState(enabled), [error, setError] = useState(null), [tick, setTick] = useState(0), refresh = useCallback(() => setTick((n) => n + 1), []), paramsKey = JSON.stringify(params), stableParams = useMemo(() => JSON.parse(paramsKey), [paramsKey]);
|
|
2312
2357
|
useEffect(() => {
|
|
2313
2358
|
if (!enabled) return;
|
|
2314
2359
|
let cancelled = !1;
|
|
2315
|
-
return setLoading(!0), client.fetch(query, stableParams).then((result) => {
|
|
2360
|
+
return setLoading(!0), client.fetch(query, stableParams, { tag }).then((result) => {
|
|
2316
2361
|
cancelled || (setData(result), setError(null));
|
|
2317
2362
|
}).catch((cause) => {
|
|
2318
2363
|
cancelled || setError(cause instanceof Error ? cause : Error(String(cause)));
|
|
@@ -2333,22 +2378,28 @@ function useQueryData(query, params, options = {}) {
|
|
|
2333
2378
|
let typesKey = (listenTypes ?? []).join(",");
|
|
2334
2379
|
return useEffect(() => {
|
|
2335
2380
|
if (!enabled || !typesKey) return;
|
|
2336
|
-
let
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2381
|
+
let timer, lastRefresh = Date.now(), staleWhileHidden = !1, run = () => {
|
|
2382
|
+
if (timer = void 0, typeof document < "u" && document.hidden) {
|
|
2383
|
+
staleWhileHidden = !0;
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
lastRefresh = Date.now(), refreshRef.current();
|
|
2387
|
+
}, onChange = () => {
|
|
2388
|
+
if (timer) return;
|
|
2389
|
+
let wait = Math.max(600, 3e3 - (Date.now() - lastRefresh));
|
|
2390
|
+
timer = setTimeout(run, wait);
|
|
2391
|
+
}, onVisible = () => {
|
|
2392
|
+
!document.hidden && staleWhileHidden && (staleWhileHidden = !1, lastRefresh = Date.now(), refreshRef.current());
|
|
2393
|
+
}, unsubscribe = subscribeShared(client, typesKey.split(","), publishedOnly, onChange, tag);
|
|
2394
|
+
return document.addEventListener("visibilitychange", onVisible), () => {
|
|
2395
|
+
timer && clearTimeout(timer), unsubscribe(), document.removeEventListener("visibilitychange", onVisible);
|
|
2347
2396
|
};
|
|
2348
2397
|
}, [
|
|
2349
2398
|
client,
|
|
2350
2399
|
typesKey,
|
|
2351
|
-
enabled
|
|
2400
|
+
enabled,
|
|
2401
|
+
publishedOnly,
|
|
2402
|
+
tag
|
|
2352
2403
|
]), {
|
|
2353
2404
|
data,
|
|
2354
2405
|
loading,
|
|
@@ -2364,7 +2415,10 @@ const ASSET_TYPES = ["sanity.imageAsset", "sanity.fileAsset"];
|
|
|
2364
2415
|
* pris au prochain rafraîchissement.
|
|
2365
2416
|
*/
|
|
2366
2417
|
function useAssets() {
|
|
2367
|
-
return useQueryData("*[_type in $types]{\n _id, _type, _createdAt, _updatedAt, originalFilename, extension, mimeType, size, url,\n title, altText, description,\n \"dimensions\": metadata.dimensions, \"lqip\": metadata.lqip,\n \"uses\": count(*[references(^._id)])\n } | order(_createdAt desc)", { types: ASSET_TYPES }, {
|
|
2418
|
+
return useQueryData("*[_type in $types]{\n _id, _type, _createdAt, _updatedAt, originalFilename, extension, mimeType, size, url,\n title, altText, description,\n \"dimensions\": metadata.dimensions, \"lqip\": metadata.lqip,\n \"uses\": count(*[references(^._id)])\n } | order(_createdAt desc)", { types: ASSET_TYPES }, {
|
|
2419
|
+
listenTypes: ASSET_TYPES,
|
|
2420
|
+
tag: "assets"
|
|
2421
|
+
});
|
|
2368
2422
|
}
|
|
2369
2423
|
const newId$1 = () => `f${Math.random().toString(36).slice(2, 10)}`;
|
|
2370
2424
|
/**
|
|
@@ -3351,7 +3405,11 @@ function localesInRows(rows) {
|
|
|
3351
3405
|
}
|
|
3352
3406
|
/** Redirections publiées du Studio, tenues à jour : pour afficher les URL finales. */
|
|
3353
3407
|
function useRedirectMap(redirectType) {
|
|
3354
|
-
let { data } = useQueryData("*[_type == $type && defined(from) && defined(to) && !(_id in path(\"drafts.**\"))]{from, to}", useMemo(() => ({ type: redirectType }), [redirectType]), {
|
|
3408
|
+
let { data } = useQueryData("*[_type == $type && defined(from) && defined(to) && !(_id in path(\"drafts.**\"))]{from, to}", useMemo(() => ({ type: redirectType }), [redirectType]), {
|
|
3409
|
+
listenTypes: useMemo(() => [redirectType], [redirectType]),
|
|
3410
|
+
publishedOnly: !0,
|
|
3411
|
+
tag: "redirect-map"
|
|
3412
|
+
});
|
|
3355
3413
|
return useMemo(() => redirectMapOf(data ?? []), [data]);
|
|
3356
3414
|
}
|
|
3357
3415
|
/**
|
|
@@ -3369,7 +3427,10 @@ function usePages(documentColumns = []) {
|
|
|
3369
3427
|
config,
|
|
3370
3428
|
pageBuilderField,
|
|
3371
3429
|
columns
|
|
3372
|
-
]), useMemo(() => ({ types: config.pageTypeNames }), [config.pageTypeNames]), {
|
|
3430
|
+
]), useMemo(() => ({ types: config.pageTypeNames }), [config.pageTypeNames]), {
|
|
3431
|
+
listenTypes: config.pageTypeNames,
|
|
3432
|
+
tag: "pages"
|
|
3433
|
+
}), redirects = useRedirectMap(config.redirectType);
|
|
3373
3434
|
return {
|
|
3374
3435
|
rows: useMemo(() => data ? buildPageRows(data, config, columns, redirects) : [], [
|
|
3375
3436
|
data,
|
|
@@ -4610,6 +4671,7 @@ function LanguagesSync() {
|
|
|
4610
4671
|
function useTranslationTodos() {
|
|
4611
4672
|
let config = useKitConfig(), { data } = useQueryData("*[_type == $type && count(paths) > 0]{documentId, \"count\": count(paths)}", useMemo(() => ({ type: TRANSLATION_TODO_TYPE }), []), {
|
|
4612
4673
|
listenTypes: [TRANSLATION_TODO_TYPE],
|
|
4674
|
+
tag: "translation-todos",
|
|
4613
4675
|
enabled: !!config.i18n
|
|
4614
4676
|
});
|
|
4615
4677
|
return useMemo(() => new Map((data ?? []).map((t) => [t.documentId, t.count])), [data]);
|
|
@@ -6336,7 +6398,10 @@ function usePageContents() {
|
|
|
6336
6398
|
let config = useKitConfig(), { field: pageBuilderField } = usePageBuilder(), { data, loading, error, refresh } = useQueryData(useMemo(() => buildContentsQuery({
|
|
6337
6399
|
...config,
|
|
6338
6400
|
pageBuilderField
|
|
6339
|
-
}, CONTENT_SCAN_LIMIT), [config, pageBuilderField]), useMemo(() => ({ types: config.pageTypeNames }), [config.pageTypeNames]), {
|
|
6401
|
+
}, CONTENT_SCAN_LIMIT), [config, pageBuilderField]), useMemo(() => ({ types: config.pageTypeNames }), [config.pageTypeNames]), {
|
|
6402
|
+
listenTypes: config.pageTypeNames,
|
|
6403
|
+
tag: "page-contents"
|
|
6404
|
+
});
|
|
6340
6405
|
return {
|
|
6341
6406
|
contents: useMemo(() => {
|
|
6342
6407
|
let map = /* @__PURE__ */ new Map();
|
|
@@ -11031,7 +11096,8 @@ function entryFor$1(client, type, languageField, language) {
|
|
|
11031
11096
|
load();
|
|
11032
11097
|
let sub = client.listen(`*[${filter}]`, params, {
|
|
11033
11098
|
visibility: "query",
|
|
11034
|
-
includeResult: !1
|
|
11099
|
+
includeResult: !1,
|
|
11100
|
+
tag: "ncf-kit.component-defaults"
|
|
11035
11101
|
}).subscribe({ next: () => void load() });
|
|
11036
11102
|
e.stop = () => sub.unsubscribe();
|
|
11037
11103
|
}
|
|
@@ -11582,7 +11648,9 @@ function useComponentNames() {
|
|
|
11582
11648
|
load();
|
|
11583
11649
|
let subscription = client.listen("*[_id == $id]", { id: COMPONENT_META_ID }, {
|
|
11584
11650
|
visibility: "query",
|
|
11585
|
-
events: ["mutation"]
|
|
11651
|
+
events: ["mutation"],
|
|
11652
|
+
includeResult: !1,
|
|
11653
|
+
tag: "ncf-kit.component-names"
|
|
11586
11654
|
}).subscribe({
|
|
11587
11655
|
next: () => void load(),
|
|
11588
11656
|
error: () => {}
|
|
@@ -11635,7 +11703,8 @@ function entryFor(client, documentId) {
|
|
|
11635
11703
|
load();
|
|
11636
11704
|
let sub = client.listen("*[_id == $id]", { id }, {
|
|
11637
11705
|
visibility: "query",
|
|
11638
|
-
includeResult: !1
|
|
11706
|
+
includeResult: !1,
|
|
11707
|
+
tag: "ncf-kit.translation-todo"
|
|
11639
11708
|
}).subscribe({ next: () => void load() });
|
|
11640
11709
|
e.stop = () => sub.unsubscribe();
|
|
11641
11710
|
}
|
|
@@ -13555,7 +13624,10 @@ function useCollection(type, visibleKeys, options = {}) {
|
|
|
13555
13624
|
let { filter, params: extraParams } = options, schema = useSchema(), allColumns = useMemo(() => deriveCollectionColumns(schema.get(type)), [schema, type]), visibleColumns = useMemo(() => visibleKeys.map((key) => allColumns.find((c) => c.key === key)).filter((c) => !!c), [allColumns, visibleKeys]), { data, loading, error, refresh } = useQueryData(useMemo(() => buildCollectionQuery(visibleColumns, filter), [visibleColumns, filter]), {
|
|
13556
13625
|
type,
|
|
13557
13626
|
...extraParams
|
|
13558
|
-
}, {
|
|
13627
|
+
}, {
|
|
13628
|
+
listenTypes: [type],
|
|
13629
|
+
tag: `collection.${type}`
|
|
13630
|
+
});
|
|
13559
13631
|
return {
|
|
13560
13632
|
allColumns,
|
|
13561
13633
|
visibleColumns,
|