@abraca/junis 2.101.0 → 2.103.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/module.json +1 -1
- package/dist/module.mjs +54 -2
- package/dist/runtime/components/JunBreadcrumbs.vue +4 -2
- package/dist/runtime/components/JunCampfirePresence.client.vue +16 -13
- package/dist/runtime/components/JunCollectionIntro.vue +1 -1
- package/dist/runtime/components/JunEditor.d.ts +19 -0
- package/dist/runtime/components/JunEditor.js +9 -0
- package/dist/runtime/components/JunFooter.vue +5 -3
- package/dist/runtime/components/JunNavigation.vue +17 -12
- package/dist/runtime/components/JunNodePanel.client.vue +7 -1
- package/dist/runtime/components/JunSettings.client.vue +7 -1
- package/dist/runtime/components/renderers/JunCinemaRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunDeckRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunEntryRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunHomeRenderer.vue +5 -3
- package/dist/runtime/components/renderers/JunItemRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunJournalRenderer.vue +6 -2
- package/dist/runtime/components/renderers/JunLibraryRenderer.vue +3 -3
- package/dist/runtime/components/renderers/JunLiveRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunMosaicRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunMovieRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunNowRenderer.vue +2 -2
- package/dist/runtime/components/renderers/JunPollRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunProjectRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunServicesRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunStatsRenderer.vue +4 -2
- package/dist/runtime/components/renderers/JunThreadRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunTrackRenderer.vue +1 -1
- package/dist/runtime/components/renderers/JunUsesRenderer.vue +1 -1
- package/dist/runtime/composables/useJunChrome.js +105 -17
- package/dist/runtime/composables/useJunCurrentDoc.js +6 -5
- package/dist/runtime/composables/useJunNavItems.js +4 -4
- package/dist/runtime/composables/useJunNavSettings.js +4 -3
- package/dist/runtime/composables/useJunOffline.js +1 -1
- package/dist/runtime/composables/useJunRootId.d.ts +18 -0
- package/dist/runtime/composables/useJunRootId.js +7 -0
- package/dist/runtime/composables/useJunSiteConfig.d.ts +8 -1
- package/dist/runtime/composables/useJunSiteConfig.js +27 -15
- package/dist/runtime/lazy/junSdkBackground.d.ts +10 -0
- package/dist/runtime/lazy/junSdkBackground.js +1 -0
- package/dist/runtime/plugins/jun-doc-tree.js +8 -0
- package/dist/runtime/plugins/jun-editor-defer.client.d.ts +2 -0
- package/dist/runtime/plugins/jun-editor-defer.client.js +12 -0
- package/dist/runtime/plugins/jun-editor-defer.server.d.ts +2 -0
- package/dist/runtime/plugins/jun-editor-defer.server.js +10 -0
- package/dist/runtime/plugins/jun-fresh-server.client.js +46 -31
- package/dist/runtime/plugins/jun-site-config.js +8 -0
- package/dist/runtime/server/plugins/jun-bootstrap.js +7 -2
- package/dist/runtime/server/utils/junCache.js +25 -2
- package/dist/runtime/utils/junDate.js +6 -2
- package/dist/runtime/utils/junSsrMemo.d.ts +19 -0
- package/dist/runtime/utils/junSsrMemo.js +11 -0
- package/package.json +1 -1
|
@@ -130,37 +130,74 @@ function leadingBarBottom(panel, pr) {
|
|
|
130
130
|
return found;
|
|
131
131
|
}
|
|
132
132
|
let writing = false;
|
|
133
|
+
const LIVE_SELECTOR = ".jun-bar";
|
|
134
|
+
const rootPending = /* @__PURE__ */ new Map();
|
|
135
|
+
let liveEls = [];
|
|
136
|
+
function clearLive(els) {
|
|
137
|
+
for (const el of els) {
|
|
138
|
+
for (const name of rootPending.keys()) el.style.removeProperty(name);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function flushRoot() {
|
|
142
|
+
if (!rootPending.size) return;
|
|
143
|
+
writing = true;
|
|
144
|
+
const style = document.documentElement.style;
|
|
145
|
+
for (const [name, value] of rootPending) {
|
|
146
|
+
if (value === null) style.removeProperty(name);
|
|
147
|
+
else style.setProperty(name, value);
|
|
148
|
+
}
|
|
149
|
+
clearLive(liveEls);
|
|
150
|
+
writing = false;
|
|
151
|
+
rootPending.clear();
|
|
152
|
+
liveEls = [];
|
|
153
|
+
}
|
|
133
154
|
function publish() {
|
|
134
155
|
const next = measure();
|
|
135
|
-
const
|
|
136
|
-
let changed = false;
|
|
137
|
-
writing = true;
|
|
156
|
+
const changes = [];
|
|
138
157
|
for (const edge of EDGES) {
|
|
139
158
|
if (Math.abs(next.edges[edge] - published.edges[edge]) < 0.5) continue;
|
|
140
159
|
published.edges[edge] = next.edges[edge];
|
|
141
|
-
|
|
142
|
-
changed = true;
|
|
160
|
+
changes.push([`--jun-chrome-${edge}`, `${Math.round(next.edges[edge])}px`]);
|
|
143
161
|
}
|
|
144
162
|
for (const key of ALIGN) {
|
|
145
163
|
if (Math.abs(next.align[key] - published.align[key]) < 0.5) continue;
|
|
146
164
|
published.align[key] = next.align[key];
|
|
147
|
-
|
|
148
|
-
changed = true;
|
|
165
|
+
changes.push([`--jun-chrome-${key}`, `${Math.round(next.align[key])}px`]);
|
|
149
166
|
}
|
|
150
167
|
if (next.radius !== published.radius) {
|
|
151
168
|
published.radius = next.radius;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
169
|
+
changes.push(["--jun-chrome-radius", next.radius || null]);
|
|
170
|
+
}
|
|
171
|
+
if (!changes.length) return false;
|
|
172
|
+
const current = Array.from(document.querySelectorAll(LIVE_SELECTOR));
|
|
173
|
+
clearLive(liveEls.filter((el) => !current.includes(el)));
|
|
174
|
+
liveEls = current;
|
|
175
|
+
writing = true;
|
|
176
|
+
if (!liveEls.length) {
|
|
177
|
+
const style = document.documentElement.style;
|
|
178
|
+
for (const [name, value] of changes) {
|
|
179
|
+
rootPending.delete(name);
|
|
180
|
+
if (value === null) style.removeProperty(name);
|
|
181
|
+
else style.setProperty(name, value);
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
for (const [name, value] of changes) rootPending.set(name, value);
|
|
185
|
+
for (const el of liveEls) {
|
|
186
|
+
for (const [name, value] of rootPending) {
|
|
187
|
+
if (value === null) el.style.removeProperty(name);
|
|
188
|
+
else el.style.setProperty(name, value);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
155
191
|
}
|
|
156
192
|
writing = false;
|
|
157
|
-
return
|
|
193
|
+
return true;
|
|
158
194
|
}
|
|
159
195
|
function frame() {
|
|
160
196
|
raf = 0;
|
|
161
|
-
if (!consumers) return;
|
|
197
|
+
if (!consumers) return flushRoot();
|
|
162
198
|
if (publish()) quietUntil = performance.now() + SETTLE_MS;
|
|
163
199
|
if (performance.now() < quietUntil) raf = requestAnimationFrame(frame);
|
|
200
|
+
else flushRoot();
|
|
164
201
|
}
|
|
165
202
|
function nudge() {
|
|
166
203
|
if (!consumers || writing) return;
|
|
@@ -169,12 +206,62 @@ function nudge() {
|
|
|
169
206
|
}
|
|
170
207
|
let navObserver = null;
|
|
171
208
|
let resizeObserver = null;
|
|
209
|
+
const CHROME_SELECTOR = ".jun-nav-panel, .jun-player, [data-jun-chrome-edge]";
|
|
210
|
+
const GEOMETRY_PROPERTY = /^(?:transform|translate|scale|rotate|top|right|bottom|left|inset|width|height|max-|min-|margin|padding|all$)/;
|
|
211
|
+
function onTransition(e) {
|
|
212
|
+
const t = e.target;
|
|
213
|
+
if (!(t instanceof Element)) return;
|
|
214
|
+
const prop = e.propertyName;
|
|
215
|
+
if (prop && !GEOMETRY_PROPERTY.test(prop)) {
|
|
216
|
+
if (t.matches("[data-jun-chrome-edge], .jun-player")) nudge();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (t.closest(CHROME_SELECTOR)) return nudge();
|
|
220
|
+
if (t.childElementCount === 0) return;
|
|
221
|
+
for (const el of chromeElements()) {
|
|
222
|
+
if (t.contains(el)) return nudge();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
let chromeCache = [];
|
|
226
|
+
let chromeCacheAt = -Infinity;
|
|
227
|
+
function chromeElements() {
|
|
228
|
+
const now = performance.now();
|
|
229
|
+
if (now - chromeCacheAt > 250) {
|
|
230
|
+
chromeCache = Array.from(document.querySelectorAll(CHROME_SELECTOR));
|
|
231
|
+
chromeCacheAt = now;
|
|
232
|
+
}
|
|
233
|
+
return chromeCache;
|
|
234
|
+
}
|
|
235
|
+
let lastStyleSig = "";
|
|
236
|
+
function styleSignature() {
|
|
237
|
+
const style = document.documentElement.style;
|
|
238
|
+
let sig = "";
|
|
239
|
+
for (let i = 0; i < style.length; i++) {
|
|
240
|
+
const name = style[i];
|
|
241
|
+
if (!name.startsWith("--jun-") || name.startsWith("--jun-chrome-") || name.startsWith("--jun-palette-")) continue;
|
|
242
|
+
sig += `${name}:${style.getPropertyValue(name)};`;
|
|
243
|
+
}
|
|
244
|
+
return sig;
|
|
245
|
+
}
|
|
246
|
+
function onRootMutation(records) {
|
|
247
|
+
let hit = false;
|
|
248
|
+
for (const r of records) {
|
|
249
|
+
if (r.attributeName === "data-jun-nav") hit = true;
|
|
250
|
+
}
|
|
251
|
+
const sig = styleSignature();
|
|
252
|
+
if (sig !== lastStyleSig) {
|
|
253
|
+
lastStyleSig = sig;
|
|
254
|
+
hit = true;
|
|
255
|
+
}
|
|
256
|
+
if (hit) nudge();
|
|
257
|
+
}
|
|
172
258
|
function attach() {
|
|
173
259
|
window.addEventListener("resize", nudge, { passive: true });
|
|
174
260
|
window.addEventListener("scroll", nudge, { passive: true });
|
|
175
|
-
document.addEventListener("transitionrun",
|
|
176
|
-
document.addEventListener("transitionend",
|
|
177
|
-
|
|
261
|
+
document.addEventListener("transitionrun", onTransition, { passive: true, capture: true });
|
|
262
|
+
document.addEventListener("transitionend", onTransition, { passive: true, capture: true });
|
|
263
|
+
lastStyleSig = styleSignature();
|
|
264
|
+
navObserver = new MutationObserver(onRootMutation);
|
|
178
265
|
navObserver.observe(document.documentElement, {
|
|
179
266
|
attributes: true,
|
|
180
267
|
attributeFilter: ["data-jun-nav", "style"]
|
|
@@ -187,14 +274,15 @@ function attach() {
|
|
|
187
274
|
function detach() {
|
|
188
275
|
window.removeEventListener("resize", nudge);
|
|
189
276
|
window.removeEventListener("scroll", nudge);
|
|
190
|
-
document.removeEventListener("transitionrun",
|
|
191
|
-
document.removeEventListener("transitionend",
|
|
277
|
+
document.removeEventListener("transitionrun", onTransition, true);
|
|
278
|
+
document.removeEventListener("transitionend", onTransition, true);
|
|
192
279
|
navObserver?.disconnect();
|
|
193
280
|
navObserver = null;
|
|
194
281
|
resizeObserver?.disconnect();
|
|
195
282
|
resizeObserver = null;
|
|
196
283
|
if (raf) cancelAnimationFrame(raf);
|
|
197
284
|
raf = 0;
|
|
285
|
+
flushRoot();
|
|
198
286
|
}
|
|
199
287
|
export function junChromeNudge() {
|
|
200
288
|
if (import.meta.client) nudge();
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { useRoute, useSlugRoute } from "#imports";
|
|
3
|
+
import { useJunRootId } from "./useJunRootId.js";
|
|
3
4
|
export function useJunCurrentDoc() {
|
|
4
5
|
const { docId } = useSlugRoute();
|
|
5
6
|
const route = useRoute();
|
|
6
|
-
const
|
|
7
|
+
const rootId = useJunRootId();
|
|
7
8
|
const currentDocId = computed(
|
|
8
|
-
() => docId.value ?? (route.path === "/" ?
|
|
9
|
+
() => docId.value ?? (route.path === "/" ? rootId.value : null)
|
|
9
10
|
);
|
|
10
11
|
const isRoot = computed(
|
|
11
|
-
() => !!currentDocId.value && currentDocId.value ===
|
|
12
|
+
() => !!currentDocId.value && currentDocId.value === rootId.value
|
|
12
13
|
);
|
|
13
|
-
return { currentDocId, isRoot, spaceDocId:
|
|
14
|
+
return { currentDocId, isRoot, spaceDocId: rootId };
|
|
14
15
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { computed, onMounted, ref, watch } from "vue";
|
|
2
2
|
import {
|
|
3
|
-
useAbracadabra,
|
|
4
3
|
useDocSlugs,
|
|
5
4
|
useDocTree,
|
|
6
5
|
useRoute,
|
|
7
6
|
useSlugRoute
|
|
8
7
|
} from "#imports";
|
|
8
|
+
import { useJunRootId } from "./useJunRootId.js";
|
|
9
9
|
import { useJunDocIcon, useJunOptions, useJunPageType } from "./useJunOptions.js";
|
|
10
10
|
import { useJunNavSettings } from "./useJunNavSettings.js";
|
|
11
11
|
import { junDedupeTravellers, useJunTravellers } from "./useJunPresence.js";
|
|
12
12
|
const SEEN_KEY = "jun_seen_v1";
|
|
13
13
|
export function useJunNavItems(items, options = {}) {
|
|
14
14
|
const route = useRoute();
|
|
15
|
-
const
|
|
15
|
+
const rootId = useJunRootId();
|
|
16
16
|
const { typeIds } = useJunOptions();
|
|
17
17
|
const { resolveType } = useJunPageType();
|
|
18
18
|
const { entries: treeEntries, getEntry } = useDocTree();
|
|
@@ -143,7 +143,7 @@ export function useJunNavItems(items, options = {}) {
|
|
|
143
143
|
if (!entry) break;
|
|
144
144
|
trail.unshift(cursor);
|
|
145
145
|
const parent = entry.parentId ?? null;
|
|
146
|
-
if (!parent || parent ===
|
|
146
|
+
if (!parent || parent === rootId.value) break;
|
|
147
147
|
cursor = parent;
|
|
148
148
|
}
|
|
149
149
|
return trail;
|
|
@@ -160,7 +160,7 @@ export function useJunNavItems(items, options = {}) {
|
|
|
160
160
|
const entry = getEntry(cursor);
|
|
161
161
|
if (!entry) return null;
|
|
162
162
|
const parent = entry.parentId ?? null;
|
|
163
|
-
if (!parent || parent ===
|
|
163
|
+
if (!parent || parent === rootId.value) return cursor;
|
|
164
164
|
cursor = parent;
|
|
165
165
|
}
|
|
166
166
|
return null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { useDocTree, useRoute, useSlugRoute } from "#imports";
|
|
3
|
+
import { useJunRootId } from "./useJunRootId.js";
|
|
3
4
|
import { junNavFlag, junNavPick, junNavPreview } from "../utils/junNavValue.js";
|
|
4
5
|
import { useJunOptions } from "./useJunOptions.js";
|
|
5
6
|
import { useJunEffectiveConfig } from "./useJunSiteConfig.js";
|
|
@@ -34,12 +35,12 @@ export const JUN_NAV_BREAKPOINT_PX = {
|
|
|
34
35
|
export function useJunNavSettings() {
|
|
35
36
|
const { navigation, brand } = useJunOptions();
|
|
36
37
|
const route = useRoute();
|
|
37
|
-
const
|
|
38
|
+
const rootId = useJunRootId();
|
|
38
39
|
const { getEntry } = useDocTree();
|
|
39
40
|
const { docId } = useSlugRoute();
|
|
40
41
|
const preview = computed(() => junNavPreview(route.query["jun-nav"]));
|
|
41
42
|
const docNav = computed(() => {
|
|
42
|
-
const id = docId.value ?? (route.path === "/" ?
|
|
43
|
+
const id = docId.value ?? (route.path === "/" ? rootId.value : null);
|
|
43
44
|
if (!id) return {};
|
|
44
45
|
const view = getEntry(id)?.meta?.junView;
|
|
45
46
|
const stored = view && typeof view === "object" ? view : {};
|
|
@@ -229,7 +229,7 @@ export function useJunOffline() {
|
|
|
229
229
|
syncedDocs.value = 0;
|
|
230
230
|
syncTotal.value = 0;
|
|
231
231
|
try {
|
|
232
|
-
const { BackgroundSyncManager } = await import("
|
|
232
|
+
const { BackgroundSyncManager } = await import("../lazy/junSdkBackground.js");
|
|
233
233
|
const manager = new BackgroundSyncManager(provider.value, client.value, null, {
|
|
234
234
|
// Two at a time, with a gap. This opens a real WebSocket per document
|
|
235
235
|
// against the site's own backend; a visitor's button press must not
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The space root's id, for READING the tree during render.
|
|
3
|
+
*
|
|
4
|
+
* `abra.spaceDocId` comes from the live connection, so in the browser it is
|
|
5
|
+
* null until `init()` resolves — which is exactly the hydration window — while
|
|
6
|
+
* the server knows it from the start. Anything that decides markup from it
|
|
7
|
+
* (the front page's section list, the breadcrumb climb, which settings apply
|
|
8
|
+
* on `/`) therefore rendered one thing on the server and another while
|
|
9
|
+
* hydrating: the front page threw away every server-rendered section and
|
|
10
|
+
* rebuilt them, and `parity:nav` has reported the mismatch on every first
|
|
11
|
+
* visit. `useDocTree()` already falls back to the SSR snapshot's root for the
|
|
12
|
+
* same reason; this is that fallback, for everything else.
|
|
13
|
+
*
|
|
14
|
+
* READS only. A WRITE must use `abra.spaceDocId` — the snapshot is a
|
|
15
|
+
* photograph of the tree, not a connection to it.
|
|
16
|
+
*/
|
|
17
|
+
import { type ComputedRef } from 'vue';
|
|
18
|
+
export declare function useJunRootId(): ComputedRef<string | null>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { useAbracadabra, useDocTreeSnapshot } from "#imports";
|
|
3
|
+
export function useJunRootId() {
|
|
4
|
+
const abra = useAbracadabra();
|
|
5
|
+
const snapshot = useDocTreeSnapshot();
|
|
6
|
+
return computed(() => abra.spaceDocId.value ?? snapshot.value?.rootId ?? null);
|
|
7
|
+
}
|
|
@@ -359,7 +359,14 @@ export declare const JUN_SITE_CONFIG_KEY = "junSite";
|
|
|
359
359
|
export declare function junConfigFromEntry(entry: {
|
|
360
360
|
meta?: Record<string, unknown>;
|
|
361
361
|
} | undefined | null): JunSiteConfig;
|
|
362
|
-
|
|
362
|
+
type JunSiteConfigHandle = ReturnType<typeof createJunSiteConfig>;
|
|
363
|
+
/**
|
|
364
|
+
* One per app. It reads only app-global state, and each call used to build its
|
|
365
|
+
* own `useChildTree` — two more Y.Map observers and two more deep-reactive
|
|
366
|
+
* copies of the whole tree — plus its own entries scan, at eleven call sites.
|
|
367
|
+
*/
|
|
368
|
+
export declare function useJunSiteConfig(): JunSiteConfigHandle;
|
|
369
|
+
declare function createJunSiteConfig(): {
|
|
363
370
|
docId: ComputedRef<string | null>;
|
|
364
371
|
candidates: ComputedRef<TreeEntry[]>;
|
|
365
372
|
config: ComputedRef<JunSiteConfig>;
|
|
@@ -1,37 +1,49 @@
|
|
|
1
|
-
import { computed, watch } from "vue";
|
|
1
|
+
import { computed, effectScope, watch } from "vue";
|
|
2
2
|
import { useNuxtData, useState } from "#app";
|
|
3
|
-
import { useAbracadabra, useChildTree, useDocTree, useJunBrand } from "#imports";
|
|
3
|
+
import { useAbracadabra, useChildTree, useDocTree, useJunBrand, useNuxtApp } from "#imports";
|
|
4
|
+
import { useJunRootId } from "./useJunRootId.js";
|
|
4
5
|
import { JUN_SITE_CONFIG_STATE } from "../plugins/jun-site-config.js";
|
|
5
6
|
import { useJunStudio } from "./useJunStudio.js";
|
|
7
|
+
import { junSsrMemo } from "../utils/junSsrMemo.js";
|
|
6
8
|
export const JUN_SITE_CONFIG_KEY = "junSite";
|
|
7
9
|
export function junConfigFromEntry(entry) {
|
|
8
10
|
const nested = entry?.meta?.[JUN_SITE_CONFIG_KEY];
|
|
9
11
|
return nested && typeof nested === "object" ? nested : {};
|
|
10
12
|
}
|
|
11
13
|
export function useJunSiteConfig() {
|
|
14
|
+
const nuxtApp = useNuxtApp();
|
|
15
|
+
let handle = nuxtApp._junSiteConfig;
|
|
16
|
+
if (!handle) {
|
|
17
|
+
handle = effectScope(true).run(() => createJunSiteConfig());
|
|
18
|
+
nuxtApp._junSiteConfig = handle;
|
|
19
|
+
}
|
|
20
|
+
return handle;
|
|
21
|
+
}
|
|
22
|
+
function createJunSiteConfig() {
|
|
12
23
|
const abra = useAbracadabra();
|
|
13
24
|
const brand = useJunBrand();
|
|
14
25
|
const { entries, getEntry } = useDocTree();
|
|
15
26
|
const tree = useChildTree(abra.doc, "jun-site-config");
|
|
16
|
-
const docId =
|
|
17
|
-
const
|
|
18
|
-
() =>
|
|
27
|
+
const docId = useJunRootId();
|
|
28
|
+
const candidatesOf = junSsrMemo(
|
|
29
|
+
(all) => all.filter(
|
|
19
30
|
(e) => e.meta?.siteConfig === true && !e.trashed
|
|
20
31
|
)
|
|
21
32
|
);
|
|
22
|
-
const
|
|
23
|
-
|
|
33
|
+
const candidates = computed(() => candidatesOf(entries.value));
|
|
34
|
+
const legacyOf = junSsrMemo((all, space) => {
|
|
24
35
|
if (all.length === 0) return {};
|
|
25
|
-
const space = abra.spaceDocId.value;
|
|
26
36
|
const parented = space ? all.filter((e) => e.parentId === space) : [];
|
|
27
37
|
const pool = parented.length ? parented : all;
|
|
28
38
|
const winner = [...pool].sort((a, b) => (a.createdAt ?? 0) - (b.createdAt ?? 0) || (a.id < b.id ? -1 : 1))[0];
|
|
29
39
|
return winner.meta ?? {};
|
|
30
40
|
});
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
...
|
|
41
|
+
const legacyConfig = computed(() => legacyOf(candidates.value, docId.value));
|
|
42
|
+
const configOf = junSsrMemo((legacy, entry) => ({
|
|
43
|
+
...legacy,
|
|
44
|
+
...junConfigFromEntry(entry)
|
|
34
45
|
}));
|
|
46
|
+
const config = computed(() => configOf(legacyConfig.value, docId.value ? getEntry(docId.value) : void 0));
|
|
35
47
|
function ensure() {
|
|
36
48
|
const id = abra.spaceDocId.value;
|
|
37
49
|
if (!id) return null;
|
|
@@ -64,11 +76,11 @@ export function useJunEffectiveConfig() {
|
|
|
64
76
|
const { config } = useJunSiteConfig();
|
|
65
77
|
const ssrState = useState(JUN_SITE_CONFIG_STATE, () => ({}));
|
|
66
78
|
const { data: ssrPayload } = useNuxtData("jun-site-config");
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
return { ...ssr, ...config.value };
|
|
79
|
+
const effectiveOf = junSsrMemo((seeded, payload, live) => {
|
|
80
|
+
const ssr = seeded && Object.keys(seeded).length ? seeded : payload ?? {};
|
|
81
|
+
return { ...ssr, ...live };
|
|
71
82
|
});
|
|
83
|
+
return computed(() => effectiveOf(ssrState.value, ssrPayload.value, config.value));
|
|
72
84
|
}
|
|
73
85
|
let migrationArmed = false;
|
|
74
86
|
const NON_CONFIG_KEYS = /* @__PURE__ */ new Set(["siteConfig", "hidden", "icon", "slugAliases", "order"]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `BackgroundSyncManager`, and nothing else from `@abraca/dabra`.
|
|
3
|
+
*
|
|
4
|
+
* A namespace import of the package — `import('@abraca/dabra')` — keeps every
|
|
5
|
+
* export of the SDK alive, because Rollup cannot prove which properties of the
|
|
6
|
+
* module object will be read. This module gives the offline panel's lazy
|
|
7
|
+
* import a namespace with one static re-export instead. Same rule as
|
|
8
|
+
* `@abraca/nuxt`'s `utils/sdkCore.ts`.
|
|
9
|
+
*/
|
|
10
|
+
export { BackgroundSyncManager } from '@abraca/dabra';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BackgroundSyncManager } from "@abraca/dabra";
|
|
@@ -4,6 +4,14 @@ const KEY = "jun-doc-tree";
|
|
|
4
4
|
export default defineNuxtPlugin({
|
|
5
5
|
name: "jun:doc-tree",
|
|
6
6
|
enforce: "pre",
|
|
7
|
+
// Parallel: `jun:doc-tree` and `jun:site-config` are independent internal
|
|
8
|
+
// fetches, and awaited in sequence they were two round trips through the
|
|
9
|
+
// Nitro stack before a server render could start. Nuxt still awaits every
|
|
10
|
+
// parallel plugin before `app:created` — where the initial navigation and
|
|
11
|
+
// route middleware run — so nothing downstream can observe either one
|
|
12
|
+
// unfinished. Nothing reads their state during another plugin's setup
|
|
13
|
+
// (`plugin-abracadabra.server` reads the snapshot through a computed).
|
|
14
|
+
parallel: true,
|
|
7
15
|
async setup(nuxtApp) {
|
|
8
16
|
const state = useDocTreeSnapshot();
|
|
9
17
|
if (nuxtApp.payload.data[KEY] !== void 0) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
2
|
+
import { loadAEditor } from "#build/jun-editor.mjs";
|
|
3
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
|
+
nuxtApp.hooks.hookOnce("app:suspense:resolve", () => {
|
|
5
|
+
const warm = () => {
|
|
6
|
+
loadAEditor().catch(() => {
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
if (typeof requestIdleCallback === "function") requestIdleCallback(warm, { timeout: 5e3 });
|
|
10
|
+
else setTimeout(warm, 1500);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
2
|
+
import { AEDITOR_SSR_ID } from "#build/jun-editor.mjs";
|
|
3
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
|
+
if (!AEDITOR_SSR_ID) return;
|
|
5
|
+
nuxtApp.hook("app:rendered", ({ ssrContext }) => {
|
|
6
|
+
if (!ssrContext) return;
|
|
7
|
+
ssrContext["~lazyHydratedModules"] ||= /* @__PURE__ */ new Set();
|
|
8
|
+
ssrContext["~lazyHydratedModules"].add(AEDITOR_SSR_ID);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -3,40 +3,55 @@ import { defineNuxtPlugin, useRuntimeConfig } from "#imports";
|
|
|
3
3
|
export default defineNuxtPlugin({
|
|
4
4
|
name: "jun:fresh-server",
|
|
5
5
|
enforce: "pre",
|
|
6
|
-
async
|
|
6
|
+
// NOT async, and that is the point of this shape. The guard used to be an
|
|
7
|
+
// `async setup()` that awaited a backend round trip (up to its 4 s timeout)
|
|
8
|
+
// plus IndexedDB work — and Nuxt awaits every async plugin before it
|
|
9
|
+
// hydrates, so every page load of every site held its first interactive
|
|
10
|
+
// frame hostage to cache hygiene that is a no-op 99.9% of the time.
|
|
11
|
+
//
|
|
12
|
+
// What the guard actually has to precede is the first PROVIDER, not
|
|
13
|
+
// hydration. `@abraca/nuxt` awaits `abracadabra:before-connect` right before
|
|
14
|
+
// it opens the socket and the first IndexedDB store; the check starts here,
|
|
15
|
+
// at plugin time, and is merely awaited there — by which point the SDK
|
|
16
|
+
// import and the auth round trips have run in parallel with it.
|
|
17
|
+
setup(nuxtApp) {
|
|
7
18
|
if (import.meta.server) return;
|
|
8
19
|
const config = useRuntimeConfig().public;
|
|
9
20
|
const url = config.abracadabra?.url ?? config.jun?.serverUrl;
|
|
10
21
|
if (!url) return;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const parsed = new URL(url, window.location.origin);
|
|
15
|
-
origin = parsed.origin;
|
|
16
|
-
host = parsed.host;
|
|
17
|
-
} catch {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
const controller = new AbortController();
|
|
22
|
-
const timer = setTimeout(() => controller.abort(), 4e3);
|
|
23
|
-
const info = await fetch(`${origin}/info`, { signal: controller.signal }).finally(() => clearTimeout(timer));
|
|
24
|
-
if (!info.ok) return;
|
|
25
|
-
const serverId = (await info.json())?.server_id;
|
|
26
|
-
if (typeof serverId !== "string" || !serverId) return;
|
|
27
|
-
const outcome = await dropCachesIfServerReplaced(host, serverId);
|
|
28
|
-
if (!outcome) return;
|
|
29
|
-
const moved = `${outcome.previousServerId?.slice(0, 8)} \u2192 ${serverId.slice(0, 8)}`;
|
|
30
|
-
if (outcome.blocked.length) {
|
|
31
|
-
console.warn(
|
|
32
|
-
`[jun] ${origin} has a new database (${moved}), but ${outcome.blocked.length} cache(s) could not be cleared \u2014 something already had them open, so this tab may re-push a tree that no longer exists. Reload it. Blocked: ${outcome.blocked.join(", ")}`
|
|
33
|
-
);
|
|
34
|
-
} else {
|
|
35
|
-
console.info(
|
|
36
|
-
`[jun] ${origin} has a new database (${moved}); cleared ${outcome.cleared.length} local cache(s) so this tab does not re-push a tree that no longer exists.`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
} catch {
|
|
40
|
-
}
|
|
22
|
+
const check = checkServer(url);
|
|
23
|
+
nuxtApp.hook("abracadabra:before-connect", () => check);
|
|
41
24
|
}
|
|
42
25
|
});
|
|
26
|
+
async function checkServer(url) {
|
|
27
|
+
let origin;
|
|
28
|
+
let host;
|
|
29
|
+
try {
|
|
30
|
+
const parsed = new URL(url, window.location.origin);
|
|
31
|
+
origin = parsed.origin;
|
|
32
|
+
host = parsed.host;
|
|
33
|
+
} catch {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
const timer = setTimeout(() => controller.abort(), 4e3);
|
|
39
|
+
const info = await fetch(`${origin}/info`, { signal: controller.signal }).finally(() => clearTimeout(timer));
|
|
40
|
+
if (!info.ok) return;
|
|
41
|
+
const serverId = (await info.json())?.server_id;
|
|
42
|
+
if (typeof serverId !== "string" || !serverId) return;
|
|
43
|
+
const outcome = await dropCachesIfServerReplaced(host, serverId);
|
|
44
|
+
if (!outcome) return;
|
|
45
|
+
const moved = `${outcome.previousServerId?.slice(0, 8)} \u2192 ${serverId.slice(0, 8)}`;
|
|
46
|
+
if (outcome.blocked.length) {
|
|
47
|
+
console.warn(
|
|
48
|
+
`[jun] ${origin} has a new database (${moved}), but ${outcome.blocked.length} cache(s) could not be cleared \u2014 something already had them open, so this tab may re-push a tree that no longer exists. Reload it. Blocked: ${outcome.blocked.join(", ")}`
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
console.info(
|
|
52
|
+
`[jun] ${origin} has a new database (${moved}); cleared ${outcome.cleared.length} local cache(s) so this tab does not re-push a tree that no longer exists.`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -4,6 +4,14 @@ export const JUN_SITE_CONFIG_STATE = "jun:site-config";
|
|
|
4
4
|
export default defineNuxtPlugin({
|
|
5
5
|
name: "jun:site-config",
|
|
6
6
|
enforce: "pre",
|
|
7
|
+
// Parallel: `jun:doc-tree` and `jun:site-config` are independent internal
|
|
8
|
+
// fetches, and awaited in sequence they were two round trips through the
|
|
9
|
+
// Nitro stack before a server render could start. Nuxt still awaits every
|
|
10
|
+
// parallel plugin before `app:created` — where the initial navigation and
|
|
11
|
+
// route middleware run — so nothing downstream can observe either one
|
|
12
|
+
// unfinished. Nothing reads their state during another plugin's setup
|
|
13
|
+
// (`plugin-abracadabra.server` reads the snapshot through a computed).
|
|
14
|
+
parallel: true,
|
|
7
15
|
async setup(nuxtApp) {
|
|
8
16
|
const state = useState(JUN_SITE_CONFIG_STATE, () => ({}));
|
|
9
17
|
if (nuxtApp.payload.data[KEY] !== void 0) {
|
|
@@ -2,6 +2,7 @@ import * as Y from "yjs";
|
|
|
2
2
|
import { AbracadabraProvider } from "@abraca/dabra";
|
|
3
3
|
import { markdownToFragmentNodes } from "@abraca/convert";
|
|
4
4
|
import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
|
|
5
|
+
import junSeedModule from "#jun-seed";
|
|
5
6
|
import { junSeedFinished, junSeedStarted } from "../utils/junSeedGate.js";
|
|
6
7
|
const BOOT_DELAY_MS = 4e3;
|
|
7
8
|
const SYNC_TIMEOUT_MS = 1e4;
|
|
@@ -487,8 +488,12 @@ function defaultTree(typeIds) {
|
|
|
487
488
|
return nodes;
|
|
488
489
|
}
|
|
489
490
|
export default defineNitroPlugin((nitroApp) => {
|
|
490
|
-
const
|
|
491
|
-
|
|
491
|
+
const override = useRuntimeConfig().jun?.seed ?? {};
|
|
492
|
+
const seed = { ...junSeedModule };
|
|
493
|
+
for (const [key, value] of Object.entries(override)) {
|
|
494
|
+
if (value !== void 0) seed[key] = value;
|
|
495
|
+
}
|
|
496
|
+
if (seed.enabled === false) return;
|
|
492
497
|
nitroApp.hooks.hook("abracadabra:before-runners", () => {
|
|
493
498
|
registerServerPlugin({
|
|
494
499
|
name: "jun:bootstrap",
|
|
@@ -3,10 +3,33 @@ export function junRootDocId() {
|
|
|
3
3
|
const pub = useRuntimeConfig().public;
|
|
4
4
|
return pub?.abracadabra?.entryDocId || process.env.ABRA_ENTRY_DOC_ID || "";
|
|
5
5
|
}
|
|
6
|
+
const parsedItems = /* @__PURE__ */ new Map();
|
|
7
|
+
async function junReadCached(key) {
|
|
8
|
+
const storage = useStorage();
|
|
9
|
+
let mtime = Number.NaN;
|
|
10
|
+
let size;
|
|
11
|
+
try {
|
|
12
|
+
const meta = await storage.getMeta(key, { nativeOnly: true });
|
|
13
|
+
if (meta?.mtime) mtime = new Date(meta.mtime).getTime();
|
|
14
|
+
if (typeof meta?.size === "number") size = meta.size;
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
17
|
+
if (!Number.isFinite(mtime)) return storage.getItem(key);
|
|
18
|
+
const stamp = `${mtime}:${size ?? ""}`;
|
|
19
|
+
const hit = parsedItems.get(key);
|
|
20
|
+
if (hit?.stamp === stamp) return hit.value;
|
|
21
|
+
const value = storage.getItem(key);
|
|
22
|
+
const slot = { stamp, value };
|
|
23
|
+
parsedItems.set(key, slot);
|
|
24
|
+
value.catch(() => {
|
|
25
|
+
if (parsedItems.get(key) === slot) parsedItems.delete(key);
|
|
26
|
+
});
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
6
29
|
export async function junDocTree() {
|
|
7
30
|
const rootDocId = junRootDocId();
|
|
8
31
|
if (!rootDocId) return {};
|
|
9
|
-
const json = await
|
|
32
|
+
const json = await junReadCached(
|
|
10
33
|
`doc-cache:json:${rootDocId}`
|
|
11
34
|
);
|
|
12
35
|
return json?.["doc-tree"] ?? {};
|
|
@@ -26,7 +49,7 @@ export async function junHeartbeat() {
|
|
|
26
49
|
return beat && typeof beat.at === "number" ? beat : null;
|
|
27
50
|
}
|
|
28
51
|
export async function junSlugMap() {
|
|
29
|
-
const map = await
|
|
52
|
+
const map = await junReadCached(
|
|
30
53
|
"doc-cache:slug-map"
|
|
31
54
|
);
|
|
32
55
|
return map?.idToSlug ?? {};
|
|
@@ -3,19 +3,23 @@ function parse(value) {
|
|
|
3
3
|
const d = new Date(value);
|
|
4
4
|
return Number.isNaN(d.getTime()) ? null : d;
|
|
5
5
|
}
|
|
6
|
+
let _long = null;
|
|
7
|
+
let _short = null;
|
|
6
8
|
export function junDateLong(value) {
|
|
7
9
|
const d = parse(value);
|
|
8
10
|
if (!d) return value ? String(value) : "";
|
|
9
|
-
|
|
11
|
+
_long ??= new Intl.DateTimeFormat(void 0, {
|
|
10
12
|
year: "numeric",
|
|
11
13
|
month: "long",
|
|
12
14
|
day: "numeric"
|
|
13
15
|
});
|
|
16
|
+
return _long.format(d);
|
|
14
17
|
}
|
|
15
18
|
export function junDateShort(value) {
|
|
16
19
|
const d = parse(value);
|
|
17
20
|
if (!d) return value ? String(value) : "";
|
|
18
|
-
|
|
21
|
+
_short ??= new Intl.DateTimeFormat(void 0, { month: "short", day: "numeric" });
|
|
22
|
+
return _short.format(d);
|
|
19
23
|
}
|
|
20
24
|
export function junDateIso(value) {
|
|
21
25
|
return parse(value)?.toISOString().slice(0, 10) ?? "";
|