@nocode-factory/sanity-kit 2.68.0-rc.1 → 2.70.0-rc.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +37 -18
  2. package/dist/index.d.ts +48 -16
  3. package/dist/index.js +610 -383
  4. package/dist/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/hooks/useAssets.ts +1 -1
  7. package/src/hooks/useCollection.ts +5 -3
  8. package/src/hooks/useComponentDefaults.ts +1 -1
  9. package/src/hooks/useComponentNames.ts +1 -1
  10. package/src/hooks/usePageContents.ts +0 -1
  11. package/src/hooks/usePages.ts +5 -3
  12. package/src/hooks/useQueryData.ts +27 -59
  13. package/src/hooks/useRedirectMap.ts +1 -1
  14. package/src/hooks/useScheduledReleases.ts +27 -0
  15. package/src/hooks/useTranslationTodo.ts +1 -1
  16. package/src/hooks/useTranslationTodos.ts +0 -1
  17. package/src/lib/collectionRows.ts +26 -26
  18. package/src/lib/colors.ts +3 -6
  19. package/src/lib/pages.ts +16 -3
  20. package/src/lib/status.ts +118 -22
  21. package/src/tools/assets/AssetDetail.tsx +4 -4
  22. package/src/tools/assets/AssetTable.tsx +3 -3
  23. package/src/tools/collections/CollectionTable.tsx +53 -30
  24. package/src/tools/components/ComponentsTool.tsx +25 -2
  25. package/src/tools/pages/FieldValue.tsx +2 -2
  26. package/src/tools/pages/PagesTable.tsx +2 -2
  27. package/src/tools/pages/PagesTool.tsx +25 -2
  28. package/src/tools/pages/PathCell.tsx +1 -1
  29. package/src/tools/pages/TagCell.tsx +2 -2
  30. package/src/tools/pages/board/BoardView.tsx +2 -6
  31. package/src/tools/pages/board/PageNode.tsx +1 -1
  32. package/src/tools/pages/board/PagePanel.tsx +2 -2
  33. package/src/tools/presentation/PagesNavigator.tsx +1 -1
  34. package/src/ui/ActorName.tsx +1 -1
  35. package/src/ui/QuietInput.tsx +1 -1
  36. package/src/ui/StatusBadge.tsx +93 -7
  37. package/src/ui/StatusFilter.tsx +68 -0
  38. package/src/ui/formatDate.ts +2 -2
  39. package/src/version.ts +1 -1
  40. package/src/hooks/sharedListener.ts +0 -101
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
4
4
  * le vérifie.
5
5
  */
6
- export const KIT_VERSION = '2.68.0-rc.1'
6
+ export const KIT_VERSION = '2.70.0-rc.2'
@@ -1,101 +0,0 @@
1
- import type {SanityClient} from 'sanity'
2
-
3
- /**
4
- * UNE écoute Sanity partagée par filtre (types écoutés + publié seulement ou non), quel
5
- * que soit le nombre de vues qui la demandent (onglet Pages, tableaux, médias...). Avant,
6
- * chaque vue ouvrait sa propre connexion, souvent sur les mêmes types.
7
- *
8
- * - Sanity n'envoie qu'un signal « ça a changé » (`includeResult: false`), jamais le
9
- * document entier : à chaque frappe, le document partait vers chaque vue ouverte.
10
- * - Connexion tombée : nouvelle tentative (5 s, puis jusqu'à 60 s), et chaque vue est
11
- * prévenue au retour (des changements ont pu être manqués). Avant, une écoute tombée
12
- * arrêtait la mise à jour sans rien dire.
13
- * - Plus aucune vue abonnée : la connexion est fermée.
14
- */
15
-
16
- type Listener = () => void
17
- type Entry = {
18
- listeners: Set<Listener>
19
- stop: () => void
20
- }
21
-
22
- const entries = new Map<string, Entry>()
23
-
24
- const RETRY_MIN_MS = 5_000
25
- const RETRY_MAX_MS = 60_000
26
-
27
- export function listenFilter(types: readonly string[], publishedOnly: boolean): string {
28
- return publishedOnly ? '*[_type in $types && !(_id in path("drafts.**")) && !(_id in path("versions.**"))]' : '*[_type in $types]'
29
- }
30
-
31
- export function subscribeShared(
32
- client: SanityClient,
33
- types: readonly string[],
34
- publishedOnly: boolean,
35
- listener: Listener,
36
- tag: string,
37
- ): () => void {
38
- const {projectId, dataset} = client.config()
39
- const sorted = [...types].sort()
40
- const key = `${projectId}:${dataset}:${publishedOnly ? 'published' : 'all'}:${sorted.join(',')}`
41
- let entry = entries.get(key)
42
- if (!entry) {
43
- const listeners = new Set<Listener>()
44
- const notify = () => listeners.forEach((l) => l())
45
- let retry = RETRY_MIN_MS
46
- let retryTimer: ReturnType<typeof setTimeout> | undefined
47
- let stopped = false
48
- let unsubscribe = () => {}
49
- const open = (reconnect: boolean) => {
50
- const subscription = client
51
- .listen(listenFilter(sorted, publishedOnly), {types: sorted}, {
52
- visibility: 'query',
53
- events: ['welcome', 'mutation'],
54
- includeResult: false,
55
- includePreviousRevision: false,
56
- tag,
57
- })
58
- .subscribe({
59
- next: (event) => {
60
- if (event.type === 'welcome') {
61
- retry = RETRY_MIN_MS
62
- // Reconnecté : des changements ont pu passer pendant la coupure.
63
- if (reconnect) notify()
64
- return
65
- }
66
- notify()
67
- },
68
- error: () => {
69
- if (stopped) return
70
- retryTimer = setTimeout(() => open(true), retry)
71
- retry = Math.min(retry * 2, RETRY_MAX_MS)
72
- },
73
- })
74
- unsubscribe = () => subscription.unsubscribe()
75
- }
76
- open(false)
77
- entry = {
78
- listeners,
79
- stop: () => {
80
- stopped = true
81
- if (retryTimer) clearTimeout(retryTimer)
82
- unsubscribe()
83
- },
84
- }
85
- entries.set(key, entry)
86
- }
87
- entry.listeners.add(listener)
88
- const current = entry
89
- return () => {
90
- current.listeners.delete(listener)
91
- if (current.listeners.size === 0) {
92
- current.stop()
93
- entries.delete(key)
94
- }
95
- }
96
- }
97
-
98
- /** Nombre d'écoutes ouvertes (tests). */
99
- export function sharedListenerCount(): number {
100
- return entries.size
101
- }