@abraca/junis 2.85.0 → 2.87.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.
Files changed (161) hide show
  1. package/dist/module.d.mts +17 -2
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +253 -21
  4. package/dist/runtime/assets/css/jun.css +1 -1
  5. package/dist/runtime/components/JunCampfirePresence.client.vue +75 -10
  6. package/dist/runtime/components/JunCollectionIntro.d.vue.ts +11 -0
  7. package/dist/runtime/components/JunCollectionIntro.vue +45 -0
  8. package/dist/runtime/components/JunCollectionIntro.vue.d.ts +11 -0
  9. package/dist/runtime/components/JunConfigRow.d.vue.ts +43 -0
  10. package/dist/runtime/components/JunConfigRow.vue +34 -0
  11. package/dist/runtime/components/JunConfigRow.vue.d.ts +43 -0
  12. package/dist/runtime/components/JunDocSurface.vue +3 -0
  13. package/dist/runtime/components/JunFooter.vue +1 -1
  14. package/dist/runtime/components/JunHorizontalTimeline.d.vue.ts +30 -0
  15. package/dist/runtime/components/JunHorizontalTimeline.vue.d.ts +30 -0
  16. package/dist/runtime/components/JunLinksRow.d.vue.ts +16 -1
  17. package/dist/runtime/components/JunLinksRow.vue +17 -7
  18. package/dist/runtime/components/JunLinksRow.vue.d.ts +16 -1
  19. package/dist/runtime/components/JunMedia.client.d.vue.ts +1 -1
  20. package/dist/runtime/components/JunMedia.client.vue.d.ts +1 -1
  21. package/dist/runtime/components/JunNavigation.vue +21 -4
  22. package/dist/runtime/components/JunNoteLinks.d.vue.ts +6 -0
  23. package/dist/runtime/components/JunNoteLinks.vue +57 -0
  24. package/dist/runtime/components/JunNoteLinks.vue.d.ts +6 -0
  25. package/dist/runtime/components/JunPageHero.d.vue.ts +8 -2
  26. package/dist/runtime/components/JunPageHero.vue +15 -3
  27. package/dist/runtime/components/JunPageHero.vue.d.ts +8 -2
  28. package/dist/runtime/components/JunReaders.d.vue.ts +11 -0
  29. package/dist/runtime/components/JunReaders.vue +99 -0
  30. package/dist/runtime/components/JunReaders.vue.d.ts +11 -0
  31. package/dist/runtime/components/JunSearch.client.vue +2 -2
  32. package/dist/runtime/components/JunSectionPresence.d.vue.ts +17 -0
  33. package/dist/runtime/components/JunSectionPresence.vue +99 -0
  34. package/dist/runtime/components/JunSectionPresence.vue.d.ts +17 -0
  35. package/dist/runtime/components/JunThreadComposer.d.vue.ts +37 -0
  36. package/dist/runtime/components/JunThreadComposer.vue +54 -0
  37. package/dist/runtime/components/JunThreadComposer.vue.d.ts +37 -0
  38. package/dist/runtime/components/JunTravellersChip.vue +35 -5
  39. package/dist/runtime/components/JunVideoEmbed.client.d.vue.ts +1 -1
  40. package/dist/runtime/components/JunVideoEmbed.client.vue.d.ts +1 -1
  41. package/dist/runtime/components/JunViewControl.d.vue.ts +29 -0
  42. package/dist/runtime/components/JunViewControl.vue +340 -0
  43. package/dist/runtime/components/JunViewControl.vue.d.ts +29 -0
  44. package/dist/runtime/components/JunViewControls.d.vue.ts +27 -0
  45. package/dist/runtime/components/JunViewControls.vue +94 -0
  46. package/dist/runtime/components/JunViewControls.vue.d.ts +27 -0
  47. package/dist/runtime/components/renderers/JunAppsRenderer.vue +45 -4
  48. package/dist/runtime/components/renderers/JunCinemaRenderer.vue +42 -4
  49. package/dist/runtime/components/renderers/JunConfigRenderer.vue +348 -225
  50. package/dist/runtime/components/renderers/JunCourseRenderer.d.vue.ts +10 -0
  51. package/dist/runtime/components/renderers/JunCourseRenderer.vue +229 -0
  52. package/dist/runtime/components/renderers/JunCourseRenderer.vue.d.ts +10 -0
  53. package/dist/runtime/components/renderers/JunCvRenderer.vue +44 -6
  54. package/dist/runtime/components/renderers/JunDeckRenderer.d.vue.ts +9 -0
  55. package/dist/runtime/components/renderers/JunDeckRenderer.vue +370 -0
  56. package/dist/runtime/components/renderers/JunDeckRenderer.vue.d.ts +9 -0
  57. package/dist/runtime/components/renderers/JunEntryRenderer.vue +151 -23
  58. package/dist/runtime/components/renderers/JunFestivalRenderer.vue +41 -4
  59. package/dist/runtime/components/renderers/JunGardenRenderer.d.vue.ts +10 -0
  60. package/dist/runtime/components/renderers/JunGardenRenderer.vue +280 -0
  61. package/dist/runtime/components/renderers/JunGardenRenderer.vue.d.ts +10 -0
  62. package/dist/runtime/components/renderers/JunGlobeRenderer.vue +43 -26
  63. package/dist/runtime/components/renderers/JunGuestbookRenderer.vue +96 -14
  64. package/dist/runtime/components/renderers/JunHomeRenderer.vue +28 -129
  65. package/dist/runtime/components/renderers/JunItemRenderer.d.vue.ts +10 -0
  66. package/dist/runtime/components/renderers/JunItemRenderer.vue +398 -0
  67. package/dist/runtime/components/renderers/JunItemRenderer.vue.d.ts +10 -0
  68. package/dist/runtime/components/renderers/JunJournalRenderer.vue +141 -11
  69. package/dist/runtime/components/renderers/JunLibraryRenderer.vue +295 -12
  70. package/dist/runtime/components/renderers/JunLinksRenderer.vue +33 -1
  71. package/dist/runtime/components/renderers/JunLiveRenderer.vue +37 -1
  72. package/dist/runtime/components/renderers/JunMosaicRenderer.vue +3 -2
  73. package/dist/runtime/components/renderers/JunMovieRenderer.vue +32 -5
  74. package/dist/runtime/components/renderers/JunNowRenderer.vue +38 -5
  75. package/dist/runtime/components/renderers/JunPollRenderer.d.vue.ts +9 -0
  76. package/dist/runtime/components/renderers/JunPollRenderer.vue +231 -0
  77. package/dist/runtime/components/renderers/JunPollRenderer.vue.d.ts +9 -0
  78. package/dist/runtime/components/renderers/JunProjectRenderer.vue +74 -18
  79. package/dist/runtime/components/renderers/JunServicesRenderer.vue +40 -2
  80. package/dist/runtime/components/renderers/JunStatsRenderer.vue +37 -50
  81. package/dist/runtime/components/renderers/JunThreadRenderer.d.vue.ts +9 -0
  82. package/dist/runtime/components/renderers/JunThreadRenderer.vue +304 -0
  83. package/dist/runtime/components/renderers/JunThreadRenderer.vue.d.ts +9 -0
  84. package/dist/runtime/components/renderers/JunTrackRenderer.vue +32 -4
  85. package/dist/runtime/components/renderers/JunUsesRenderer.vue +51 -5
  86. package/dist/runtime/components/renderers/JunWallRenderer.vue +60 -5
  87. package/dist/runtime/composables/useJunDeck.d.ts +66 -0
  88. package/dist/runtime/composables/useJunDeck.js +61 -0
  89. package/dist/runtime/composables/useJunDocPage.d.ts +14 -11
  90. package/dist/runtime/composables/useJunDocPage.js +67 -3
  91. package/dist/runtime/composables/useJunFollow.d.ts +65 -9
  92. package/dist/runtime/composables/useJunFollow.js +237 -20
  93. package/dist/runtime/composables/useJunGarden.d.ts +67 -0
  94. package/dist/runtime/composables/useJunGarden.js +92 -0
  95. package/dist/runtime/composables/useJunPresence.d.ts +26 -0
  96. package/dist/runtime/composables/useJunPresence.js +9 -2
  97. package/dist/runtime/composables/useJunSections.d.ts +73 -0
  98. package/dist/runtime/composables/useJunSections.js +117 -0
  99. package/dist/runtime/composables/useJunSettings.d.ts +1 -1
  100. package/dist/runtime/composables/useJunSettings.js +5 -1
  101. package/dist/runtime/composables/useJunSiteConfig.d.ts +37 -0
  102. package/dist/runtime/composables/useJunTheme.js +40 -2
  103. package/dist/runtime/composables/useJunViewOptions.d.ts +85 -0
  104. package/dist/runtime/composables/useJunViewOptions.js +63 -0
  105. package/dist/runtime/pages/doc.vue +52 -42
  106. package/dist/runtime/pages/index.vue +61 -35
  107. package/dist/runtime/plugins/jun-doc-tree.d.ts +2 -0
  108. package/dist/runtime/plugins/jun-doc-tree.js +26 -0
  109. package/dist/runtime/server/api/health.get.d.ts +19 -0
  110. package/dist/runtime/server/api/health.get.js +40 -0
  111. package/dist/runtime/server/api/links.get.d.ts +19 -0
  112. package/dist/runtime/server/api/links.get.js +37 -0
  113. package/dist/runtime/server/api/resolve/[...slug].get.d.ts +9 -0
  114. package/dist/runtime/server/api/resolve/[...slug].get.js +7 -2
  115. package/dist/runtime/server/api/stats.get.js +2 -1
  116. package/dist/runtime/server/api/tree.get.d.ts +9 -0
  117. package/dist/runtime/server/api/tree.get.js +23 -0
  118. package/dist/runtime/server/janitor/junJanitorActor.d.ts +13 -0
  119. package/dist/runtime/server/janitor/junJanitorActor.js +36 -5
  120. package/dist/runtime/server/janitor/junJanitorChores.js +8 -0
  121. package/dist/runtime/server/plugins/jun-bootstrap.js +103 -15
  122. package/dist/runtime/server/plugins/jun-doc-cache.js +42 -4
  123. package/dist/runtime/server/plugins/jun-janitor.js +7 -0
  124. package/dist/runtime/server/plugins/jun-rpc.js +293 -0
  125. package/dist/runtime/server/plugins/jun-watchdog.d.ts +2 -0
  126. package/dist/runtime/server/plugins/jun-watchdog.js +54 -0
  127. package/dist/runtime/server/routes/sitemap.xml.get.js +2 -0
  128. package/dist/runtime/server/utils/junBoot.d.ts +1 -0
  129. package/dist/runtime/server/utils/junBoot.js +4 -0
  130. package/dist/runtime/server/utils/junCache.d.ts +17 -0
  131. package/dist/runtime/server/utils/junCache.js +5 -0
  132. package/dist/runtime/server/utils/junSeedGate.d.ts +68 -0
  133. package/dist/runtime/server/utils/junSeedGate.js +41 -0
  134. package/dist/runtime/types.d.ts +57 -1
  135. package/dist/runtime/utils/junCourse.d.ts +106 -0
  136. package/dist/runtime/utils/junCourse.js +65 -0
  137. package/dist/runtime/utils/junGarden.d.ts +193 -0
  138. package/dist/runtime/utils/junGarden.js +233 -0
  139. package/dist/runtime/utils/junMetaSchemas.js +8 -1
  140. package/dist/runtime/utils/junModeration.d.ts +67 -0
  141. package/dist/runtime/utils/junModeration.js +20 -0
  142. package/dist/runtime/utils/junMotion.d.ts +26 -0
  143. package/dist/runtime/utils/junMotion.js +31 -0
  144. package/dist/runtime/utils/junPeople.d.ts +43 -0
  145. package/dist/runtime/utils/junPeople.js +9 -0
  146. package/dist/runtime/utils/junPoll.d.ts +79 -0
  147. package/dist/runtime/utils/junPoll.js +82 -0
  148. package/dist/runtime/utils/junReadiness.d.ts +131 -0
  149. package/dist/runtime/utils/junReadiness.js +69 -0
  150. package/dist/runtime/utils/junSections.d.ts +115 -0
  151. package/dist/runtime/utils/junSections.js +45 -0
  152. package/dist/runtime/utils/junSlides.d.ts +66 -0
  153. package/dist/runtime/utils/junSlides.js +47 -0
  154. package/dist/runtime/utils/junThread.d.ts +81 -0
  155. package/dist/runtime/utils/junThread.js +75 -0
  156. package/dist/runtime/utils/junViewSpecs.d.ts +671 -0
  157. package/dist/runtime/utils/junViewSpecs.js +534 -0
  158. package/dist/runtime/utils/junViewValues.d.ts +125 -0
  159. package/dist/runtime/utils/junViewValues.js +104 -0
  160. package/dist/types.d.mts +1 -1
  161. package/package.json +5 -1
@@ -1,29 +1,232 @@
1
- import { computed, watch, watchEffect } from "vue";
2
1
  import {
2
+ computed,
3
+ effectScope,
4
+ ref,
5
+ watch,
6
+ watchEffect
7
+ } from "vue";
8
+ import {
9
+ isJunOwnerOnlyDoc,
3
10
  useAAFollowPeer,
4
11
  useAbracadabra,
5
12
  useAwareness,
13
+ useDocTree,
14
+ useJunStudio,
6
15
  useRoute,
7
16
  useRouter
8
17
  } from "#imports";
9
- export function useJunFollow() {
10
- const { setField, states } = useAwareness();
11
- const { isReady } = useAbracadabra();
18
+ const LEADER_GRACE_MS = 6e3;
19
+ const SCROLL_EPSILON = 2e-3;
20
+ const SETTLE_MS = 1600;
21
+ function createFollow() {
22
+ const { setField, states, localState } = useAwareness();
23
+ const { isReady, provider } = useAbracadabra();
24
+ const { getEntry } = useDocTree();
25
+ const { canEdit } = useJunStudio();
12
26
  const route = useRoute();
13
27
  const router = useRouter();
14
- const { follow, unfollow, followingClientId, followingUser, isFollowing } = useAAFollowPeer();
15
- if (import.meta.client) {
16
- watchEffect(() => {
17
- if (!isReady.value) return;
18
- setField("route", route.fullPath);
19
- });
20
- const leaderRoute = computed(() => {
21
- if (followingClientId.value == null) return void 0;
22
- return states.value.get(followingClientId.value)?.route;
23
- });
24
- watch(leaderRoute, (p) => {
25
- if (p && p !== route.fullPath) router.push(p);
26
- });
28
+ const {
29
+ follow: rawFollow,
30
+ unfollow: rawUnfollow,
31
+ followingClientId,
32
+ followingPublicKey,
33
+ followingUser,
34
+ isFollowing
35
+ } = useAAFollowPeer({ breakOn: "none" });
36
+ const notice = ref(null);
37
+ let noticeTimer = null;
38
+ function say(line) {
39
+ if (noticeTimer) clearTimeout(noticeTimer);
40
+ notice.value = line;
41
+ if (line) noticeTimer = setTimeout(() => notice.value = null, 5e3);
42
+ }
43
+ const myClientId = computed(() => provider.value?.awareness?.clientID ?? null);
44
+ const myPublicKey = computed(() => {
45
+ const user = localState.value.user;
46
+ return typeof user?.publicKey === "string" ? user.publicKey : null;
47
+ });
48
+ const followers = computed(() => {
49
+ const me = myPublicKey.value;
50
+ if (!me) return [];
51
+ const seen = /* @__PURE__ */ new Set();
52
+ const out = [];
53
+ for (const [clientId, st] of states.value) {
54
+ if (clientId === myClientId.value) continue;
55
+ const state = st;
56
+ if (state?.following !== me) continue;
57
+ const key = state.user?.publicKey;
58
+ if (!key || seen.has(key)) continue;
59
+ seen.add(key);
60
+ out.push({
61
+ clientId,
62
+ name: state.user?.name || "Traveller",
63
+ color: state.user?.color || "var(--ui-text-muted)",
64
+ publicKey: key
65
+ });
66
+ }
67
+ return out;
68
+ });
69
+ if (import.meta.server) {
70
+ return {
71
+ toggle: () => {
72
+ },
73
+ follow: () => {
74
+ },
75
+ unfollow: () => {
76
+ },
77
+ followingClientId,
78
+ followingPublicKey,
79
+ followingUser,
80
+ isFollowing,
81
+ followers,
82
+ notice
83
+ };
84
+ }
85
+ watchEffect(() => {
86
+ if (!isReady.value) return;
87
+ setField("route", route.fullPath);
88
+ });
89
+ watchEffect(() => {
90
+ if (!isReady.value) return;
91
+ setField("following", followingPublicKey.value ?? null);
92
+ });
93
+ let scrollRaf = 0;
94
+ let lastSent = -1;
95
+ function scrollRatio() {
96
+ const max = document.documentElement.scrollHeight - window.innerHeight;
97
+ if (max <= 0) return 0;
98
+ return Math.min(1, Math.max(0, window.scrollY / max));
99
+ }
100
+ function sendScroll() {
101
+ scrollRaf = 0;
102
+ const r = scrollRatio();
103
+ if (Math.abs(r - lastSent) < SCROLL_EPSILON) return;
104
+ lastSent = r;
105
+ setField("scroll", r);
106
+ }
107
+ function onScroll() {
108
+ if (!scrollRaf) scrollRaf = requestAnimationFrame(sendScroll);
109
+ }
110
+ watch(
111
+ () => followers.value.length > 0,
112
+ (led) => {
113
+ if (led) {
114
+ window.addEventListener("scroll", onScroll, { passive: true });
115
+ lastSent = -1;
116
+ sendScroll();
117
+ } else {
118
+ window.removeEventListener("scroll", onScroll);
119
+ if (scrollRaf) cancelAnimationFrame(scrollRaf);
120
+ scrollRaf = 0;
121
+ setField("scroll", null);
122
+ }
123
+ },
124
+ { immediate: true }
125
+ );
126
+ const leaderState = computed(() => {
127
+ const cid = followingClientId.value;
128
+ if (cid == null) return void 0;
129
+ return states.value.get(cid);
130
+ });
131
+ const leaderRoute = computed(() => leaderState.value?.route);
132
+ const leaderPrivate = computed(() => {
133
+ if (canEdit.value) return false;
134
+ const id = leaderState.value?.docId;
135
+ if (typeof id !== "string" || !id) return false;
136
+ return isJunOwnerOnlyDoc(getEntry(id));
137
+ });
138
+ const leaderScroll = computed(
139
+ () => typeof leaderState.value?.scroll === "number" ? leaderState.value.scroll : null
140
+ );
141
+ function goTo(path) {
142
+ if (path === route.fullPath) return;
143
+ void router.push(path);
144
+ settleUntil = Date.now() + SETTLE_MS;
145
+ scheduleApply();
146
+ }
147
+ watch([leaderRoute, leaderPrivate], ([p, priv]) => {
148
+ if (!p) return;
149
+ if (priv) {
150
+ const who = followingUser.value?.name ?? "They";
151
+ say(`${who} stepped somewhere private \u2014 waiting here`);
152
+ return;
153
+ }
154
+ goTo(p);
155
+ });
156
+ let applyRaf = 0;
157
+ let settleUntil = 0;
158
+ function applyScroll() {
159
+ applyRaf = 0;
160
+ const r = leaderScroll.value;
161
+ if (r == null || !isFollowing.value) return;
162
+ const max = document.documentElement.scrollHeight - window.innerHeight;
163
+ if (max > 0) {
164
+ const top = r * max;
165
+ if (Math.abs(window.scrollY - top) > 24) window.scrollTo(0, top);
166
+ }
167
+ if (Date.now() < settleUntil) scheduleApply();
168
+ }
169
+ function scheduleApply() {
170
+ if (!applyRaf) applyRaf = requestAnimationFrame(applyScroll);
171
+ }
172
+ watch(leaderScroll, (r) => {
173
+ if (r == null) return;
174
+ settleUntil = Date.now() + SETTLE_MS;
175
+ scheduleApply();
176
+ });
177
+ new ResizeObserver(() => {
178
+ if (isFollowing.value && leaderScroll.value != null) scheduleApply();
179
+ }).observe(document.documentElement);
180
+ function unfollow(reason) {
181
+ if (!isFollowing.value) return;
182
+ const who = followingUser.value?.name;
183
+ rawUnfollow();
184
+ settleUntil = 0;
185
+ say(reason ? who ? `${reason} \u2014 no longer following ${who}` : reason : null);
186
+ }
187
+ function onDocumentClick(e) {
188
+ if (!isFollowing.value) return;
189
+ const target = e.target;
190
+ if (target?.closest("[data-jun-follow-ui]")) return;
191
+ const link = target?.closest("a[href]");
192
+ if (!link) return;
193
+ if (link.target === "_blank") return;
194
+ unfollow("You took the wheel");
195
+ }
196
+ function onKeyDown(e) {
197
+ if (e.key === "Escape") unfollow();
198
+ }
199
+ function onPopState() {
200
+ unfollow("You went back");
201
+ }
202
+ document.addEventListener("click", onDocumentClick, true);
203
+ window.addEventListener("keydown", onKeyDown);
204
+ window.addEventListener("popstate", onPopState);
205
+ let goneTimer = null;
206
+ watch(
207
+ () => isFollowing.value && followingClientId.value == null,
208
+ (absent) => {
209
+ if (goneTimer) {
210
+ clearTimeout(goneTimer);
211
+ goneTimer = null;
212
+ }
213
+ if (!absent) return;
214
+ const who = followingUser.value?.name ?? "Your companion";
215
+ goneTimer = setTimeout(() => {
216
+ goneTimer = null;
217
+ if (!isFollowing.value || followingClientId.value != null) return;
218
+ rawUnfollow();
219
+ say(`${who} left`);
220
+ }, LEADER_GRACE_MS);
221
+ }
222
+ );
223
+ function follow(clientId) {
224
+ rawFollow(clientId);
225
+ say(null);
226
+ const st = states.value.get(clientId);
227
+ if (st?.route) goTo(st.route);
228
+ settleUntil = Date.now() + SETTLE_MS;
229
+ scheduleApply();
27
230
  }
28
231
  function toggle(clientId) {
29
232
  if (followingClientId.value === clientId) {
@@ -31,8 +234,22 @@ export function useJunFollow() {
31
234
  return;
32
235
  }
33
236
  follow(clientId);
34
- const st = states.value.get(clientId);
35
- if (st?.route && st.route !== route.fullPath) router.push(st.route);
36
237
  }
37
- return { toggle, unfollow, followingClientId, followingUser, isFollowing };
238
+ return {
239
+ toggle,
240
+ follow,
241
+ unfollow,
242
+ followingClientId,
243
+ followingPublicKey,
244
+ followingUser,
245
+ isFollowing,
246
+ followers,
247
+ notice
248
+ };
249
+ }
250
+ let shared = null;
251
+ export function useJunFollow() {
252
+ if (import.meta.server) return createFollow();
253
+ if (!shared) shared = effectScope(true).run(() => createFollow());
254
+ return shared;
38
255
  }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * useJunGarden — the link graph, as a page can use it.
3
+ *
4
+ * Two halves, and the split is the same one `stats` makes:
5
+ *
6
+ * - **The edges come from the SERVER** (`<apiBase>/links`). Document BODIES exist
7
+ * only in the SSR doc cache — the live tree carries labels and meta, not prose —
8
+ * so a browser cannot know what links to what without loading every document,
9
+ * which is a socket and a sync per note before anything appears.
10
+ * - **The labels and the membership come from the LIVE TREE** when it has arrived.
11
+ * Renaming a note re-labels every citation of it immediately, and a note created
12
+ * a moment ago is in the garden before the next cache sweep.
13
+ *
14
+ * So the graph is correct on the first byte and current after hydration, and
15
+ * neither side has to be complete for the page to render.
16
+ */
17
+ import { type ComputedRef } from 'vue';
18
+ import { type JunGardenEdge, type JunGardenNote, type JunGardenSort } from '../utils/junGarden.js';
19
+ export interface JunLinkGraphNode {
20
+ id: string;
21
+ label: string;
22
+ href: string;
23
+ type: string;
24
+ parentId?: string | null;
25
+ updatedAt: number;
26
+ maturity: string | null;
27
+ }
28
+ export interface JunLinkGraph {
29
+ nodes: JunLinkGraphNode[];
30
+ edges: JunGardenEdge[];
31
+ scanned: number;
32
+ generatedAt: number;
33
+ }
34
+ /**
35
+ * The whole site's graph, once per page.
36
+ *
37
+ * **The shape is validated, not assumed.** Every one of this module's API routes
38
+ * is behind a flag, and a route that was not registered does NOT 404 — the request
39
+ * falls through to the SPA catch-all and resolves with the page's HTML. That is not
40
+ * a thrown error, so a `try`/`catch` never sees it; only checking the shape does.
41
+ */
42
+ export declare function useJunLinkGraph(): {
43
+ graph: ComputedRef<JunLinkGraph>;
44
+ refresh: () => Promise<void>;
45
+ };
46
+ export interface JunGardenApi {
47
+ /** The garden's notes, ordered by the page's sort setting. */
48
+ notes: ComputedRef<JunGardenNote[]>;
49
+ /** The ones nothing points at. */
50
+ orphans: ComputedRef<JunGardenNote[]>;
51
+ counts: ComputedRef<{
52
+ notes: number;
53
+ links: number;
54
+ orphans: number;
55
+ evergreen: number;
56
+ }>;
57
+ edges: ComputedRef<JunGardenEdge[]>;
58
+ /** False until the endpoint has answered with a body it could read. */
59
+ ready: ComputedRef<boolean>;
60
+ }
61
+ /**
62
+ * One garden's notes — every document UNDER `docId`, at any depth.
63
+ *
64
+ * Depth rather than direct children, because a garden with sections is still one
65
+ * garden and a note filed inside one must not drop out of the graph it belongs to.
66
+ */
67
+ export declare function useJunGarden(docId: string, sort: ComputedRef<JunGardenSort> | (() => JunGardenSort)): JunGardenApi;
@@ -0,0 +1,92 @@
1
+ import { computed } from "vue";
2
+ import { useDocSlugs, useDocTree, useJunOptions } from "#imports";
3
+ import { useFetch } from "#app";
4
+ import {
5
+ junGardenCounts,
6
+ junGardenNotes,
7
+ junGardenOrphans,
8
+ junGardenSort
9
+ } from "../utils/junGarden.js";
10
+ import { isJunOwnerOnlyDoc } from "../utils/junVisibility.js";
11
+ const EMPTY = { nodes: [], edges: [], scanned: 0, generatedAt: 0 };
12
+ export function useJunLinkGraph() {
13
+ const opts = useJunOptions();
14
+ const { data, refresh } = useFetch(`${opts.apiBase}/links`, {
15
+ key: "jun-links",
16
+ default: () => EMPTY
17
+ });
18
+ const graph = computed(() => {
19
+ const d = data.value;
20
+ if (!d || typeof d !== "object") return EMPTY;
21
+ const g = d;
22
+ if (!Array.isArray(g.nodes) || !Array.isArray(g.edges)) return EMPTY;
23
+ return {
24
+ nodes: g.nodes,
25
+ edges: g.edges,
26
+ scanned: typeof g.scanned === "number" ? g.scanned : 0,
27
+ generatedAt: typeof g.generatedAt === "number" ? g.generatedAt : 0
28
+ };
29
+ });
30
+ return { graph, refresh: async () => void await refresh() };
31
+ }
32
+ export function useJunGarden(docId, sort) {
33
+ const { graph } = useJunLinkGraph();
34
+ const { entries } = useDocTree();
35
+ const { getDocUrl } = useDocSlugs();
36
+ const allEntries = computed(() => {
37
+ const live = entries.value ?? [];
38
+ if (live.length) {
39
+ return live.filter((e) => !e.trashed && !isJunOwnerOnlyDoc(e)).map((e) => ({
40
+ id: e.id,
41
+ label: e.label,
42
+ href: getDocUrl(e.id),
43
+ type: e.type,
44
+ updatedAt: e.updatedAt ?? e.createdAt ?? 0,
45
+ meta: e.meta
46
+ }));
47
+ }
48
+ return graph.value.nodes.map((n) => ({
49
+ id: n.id,
50
+ label: n.label,
51
+ href: n.href,
52
+ type: n.type,
53
+ updatedAt: n.updatedAt,
54
+ meta: n.maturity ? { maturity: n.maturity } : void 0
55
+ }));
56
+ });
57
+ const parentOf = computed(() => {
58
+ const map = /* @__PURE__ */ new Map();
59
+ const live = entries.value ?? [];
60
+ if (live.length) {
61
+ for (const e of live) map.set(e.id, e.parentId ?? null);
62
+ return map;
63
+ }
64
+ for (const n of graph.value.nodes) map.set(n.id, n.parentId ?? null);
65
+ return map;
66
+ });
67
+ const scope = computed(() => {
68
+ const out = /* @__PURE__ */ new Set();
69
+ for (const id of parentOf.value.keys()) {
70
+ let at = parentOf.value.get(id) ?? null;
71
+ let steps = 0;
72
+ while (at && steps++ <= parentOf.value.size) {
73
+ if (at === docId) {
74
+ out.add(id);
75
+ break;
76
+ }
77
+ at = parentOf.value.get(at) ?? null;
78
+ }
79
+ }
80
+ return out;
81
+ });
82
+ const edges = computed(() => graph.value.edges);
83
+ const unsorted = computed(() => junGardenNotes(allEntries.value, edges.value, scope.value));
84
+ const notes = computed(() => junGardenSort(
85
+ unsorted.value,
86
+ typeof sort === "function" ? sort() : sort.value
87
+ ));
88
+ const orphans = computed(() => junGardenOrphans(notes.value));
89
+ const counts = computed(() => junGardenCounts(unsorted.value));
90
+ const ready = computed(() => graph.value.generatedAt > 0);
91
+ return { notes, orphans, counts, edges, ready };
92
+ }
@@ -24,9 +24,35 @@ export interface JunTraveller {
24
24
  idle: boolean;
25
25
  docId: string | null;
26
26
  page: string | null;
27
+ /**
28
+ * The PERSON behind the session. Awareness is per tab, so anything counting
29
+ * people rather than connections deduplicates on this — see the standing rule
30
+ * in `CLAUDE.md`. Null only for a peer whose state carries no key at all.
31
+ */
32
+ publicKey: string | null;
27
33
  }
28
34
  export declare function useJunPresenceBroadcast(): void;
35
+ /**
36
+ * One entry per PERSON, from a list with one entry per SESSION.
37
+ *
38
+ * Awareness is per tab. A visitor reading in two windows is one companion, and
39
+ * `CLAUDE.md` has said so since the hearth's roster was written — but only the
40
+ * roster and the readers strip did it, so the navbar reported **"2 travellers
41
+ * here"** for one person with a second tab open, `byDocId` handed the same
42
+ * double to anything else that asked, and the travellers chip listed the same
43
+ * handle twice.
44
+ *
45
+ * The rule itself now lives in `utils/junPeople.ts`, with no imports, because
46
+ * section presence needs it for a different payload and because a rule this
47
+ * easy to get subtly wrong deserved a test — which it could not have while it
48
+ * lived in a file that imports `#imports`. See `test/sections.test.mts`.
49
+ */
50
+ export declare function junDedupeTravellers(list: JunTraveller[]): JunTraveller[];
29
51
  export declare function useJunTravellers(): {
52
+ /** One entry per SESSION. Prefer `people` unless you mean connections. */
30
53
  travellers: ComputedRef<JunTraveller[]>;
54
+ /** One entry per PERSON. What anything user-facing should count. */
55
+ people: ComputedRef<JunTraveller[]>;
56
+ /** Who is on each document, per PERSON. */
31
57
  byDocId: ComputedRef<Map<string, JunTraveller[]>>;
32
58
  };
@@ -6,6 +6,7 @@ import {
6
6
  useRoute,
7
7
  useSlugRoute
8
8
  } from "#imports";
9
+ import { junDedupePeople } from "../utils/junPeople.js";
9
10
  export function useJunPresenceBroadcast() {
10
11
  if (import.meta.server) return;
11
12
  const { setField } = useAwareness();
@@ -24,6 +25,9 @@ export function useJunPresenceBroadcast() {
24
25
  { immediate: true }
25
26
  );
26
27
  }
28
+ export function junDedupeTravellers(list) {
29
+ return junDedupePeople(list);
30
+ }
27
31
  export function useJunTravellers() {
28
32
  const { peers } = useAwarenessPeers();
29
33
  const travellers = computed(
@@ -35,10 +39,12 @@ export function useJunTravellers() {
35
39
  color: p.user?.color || "var(--ui-text-muted)",
36
40
  idle: p.idle,
37
41
  docId: typeof state.docId === "string" ? state.docId : null,
38
- page: typeof state.page === "string" ? state.page : null
42
+ page: typeof state.page === "string" ? state.page : null,
43
+ publicKey: typeof p.user?.publicKey === "string" ? p.user.publicKey : null
39
44
  };
40
45
  })
41
46
  );
47
+ const people = computed(() => junDedupeTravellers(travellers.value));
42
48
  const byDocId = computed(() => {
43
49
  const map = /* @__PURE__ */ new Map();
44
50
  for (const t of travellers.value) {
@@ -47,7 +53,8 @@ export function useJunTravellers() {
47
53
  list.push(t);
48
54
  map.set(t.docId, list);
49
55
  }
56
+ for (const [id, list] of map) map.set(id, junDedupeTravellers(list));
50
57
  return map;
51
58
  });
52
- return { travellers, byDocId };
59
+ return { travellers, people, byDocId };
53
60
  }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * useJunSections — *where in this page* somebody is, on top of *which page*.
3
+ *
4
+ * Presence answered "who is on this document" (`useJunPresence`) and, since last
5
+ * round, "who is reading it" as a strip of chips. On a `/docs` entry or a project
6
+ * write-up that is still a coarse answer: two people can be on the same page and
7
+ * three screens apart, which is exactly when knowing would matter — it is the
8
+ * difference between "somebody is here" and "somebody is reading the paragraph
9
+ * you are about to change".
10
+ *
11
+ * Two halves, deliberately separate, and the separation is load-bearing:
12
+ *
13
+ * - **`useJunSectionMarks()`** — the READ side. Nothing but awareness: no
14
+ * presence, no follow. That is what lets the follow banner name a leader's
15
+ * section without `useJunFollow` importing this file, which would be a cycle
16
+ * (`useJunFollow` → sections → presence → … ).
17
+ * - **`useJunSectionScan()`** — the MEASURE side. Finds headings in a container
18
+ * and answers which one the local reader is at, at any moment.
19
+ *
20
+ * The broadcast itself lives in `<JunSectionPresence>`, which is the one place
21
+ * that legitimately knows both who is watching (presence, follow) and what the
22
+ * page looks like (the scan).
23
+ *
24
+ * > **Reading is not mutating.** `querySelectorAll`, `textContent` and
25
+ * > `getBoundingClientRect` against ProseMirror's DOM are all reads. Nothing here
26
+ * > writes an attribute, a class or a node into it — see the standing rule in
27
+ * > `CLAUDE.md`, and `utils/junSections.ts` for why an `id` per heading (the
28
+ * > obvious implementation) is not available to this module.
29
+ */
30
+ import { type ComputedRef, type Ref } from 'vue';
31
+ import { type JunHeading, type JunSectionMark } from '../utils/junSections.js';
32
+ /** The awareness field. Namespaced by `useAAEphemeral` as `peer:junSection`. */
33
+ export declare const JUN_SECTION_FIELD = "junSection";
34
+ export interface JunSectionPeer {
35
+ clientId: number;
36
+ name: string;
37
+ color: string;
38
+ publicKey: string | null;
39
+ mark: JunSectionMark;
40
+ }
41
+ /**
42
+ * Every peer's current section, and a way to write your own.
43
+ *
44
+ * Awareness-only, so it is safe to call from anywhere — including from the
45
+ * campfire banner, which is inside the follow machinery this must not depend on.
46
+ */
47
+ export declare function useJunSectionMarks(): {
48
+ peers: ComputedRef<JunSectionPeer[]>;
49
+ /** The section a given session is in, or null. Used to name a leader's place. */
50
+ markFor: (clientId: number | null) => JunSectionMark | null;
51
+ setLocal: (mark: JunSectionMark | null) => void;
52
+ };
53
+ /**
54
+ * The headings inside `container`, and which one the local reader is at.
55
+ *
56
+ * Three things move underneath this, and all three are watched:
57
+ *
58
+ * - **the prose arrives late.** The renderer mounts before the CRDT hands over
59
+ * the document, so a one-shot scan on mount finds an empty container on every
60
+ * cold navigation. `MutationObserver`.
61
+ * - **the box changes height** — images load, an editor toolbar appears, the
62
+ * window is resized — which moves every offset below it. `ResizeObserver`.
63
+ * - **the reader scrolls.** rAF-coalesced, because a scroll handler that
64
+ * measures on every event measures forty times per flick.
65
+ */
66
+ export declare function useJunSectionScan(container: Ref<HTMLElement | null>): {
67
+ headings: Ref<JunHeading[]>;
68
+ currentIndex: Ref<number>;
69
+ /** Re-measure now. The broadcaster calls this when it starts caring. */
70
+ measure: () => void;
71
+ };
72
+ /** `"Slugs come from labels"`, shortened for a chip or a title. */
73
+ export declare function junSectionText(mark: JunSectionMark | null, max?: number): string;