@abraca/junis 2.96.0 → 2.99.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 (42) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +13 -0
  3. package/dist/runtime/components/JunBreadcrumbs.vue +40 -4
  4. package/dist/runtime/components/JunCampfireRoster.vue +4 -0
  5. package/dist/runtime/components/JunDocMenuHost.d.vue.ts +3 -0
  6. package/dist/runtime/components/JunDocMenuHost.vue +41 -0
  7. package/dist/runtime/components/JunDocMenuHost.vue.d.ts +3 -0
  8. package/dist/runtime/components/JunHorizontalTimeline.vue +5 -0
  9. package/dist/runtime/components/JunItemMenu.vue +51 -2
  10. package/dist/runtime/components/JunMosaicPane.client.d.vue.ts +11 -0
  11. package/dist/runtime/components/JunMosaicPane.client.vue +14 -2
  12. package/dist/runtime/components/JunMosaicPane.client.vue.d.ts +11 -0
  13. package/dist/runtime/components/JunNavDock.vue +3 -0
  14. package/dist/runtime/components/JunNavMenu.client.vue +4 -0
  15. package/dist/runtime/components/JunNavigation.vue +10 -0
  16. package/dist/runtime/components/JunNotFound.vue +4 -0
  17. package/dist/runtime/components/JunNoteLinks.vue +3 -0
  18. package/dist/runtime/components/JunSearch.client.vue +8 -0
  19. package/dist/runtime/components/JunSectionBar.vue +4 -0
  20. package/dist/runtime/components/JunServiceCard.vue +3 -1
  21. package/dist/runtime/components/JunTravellersChip.vue +3 -0
  22. package/dist/runtime/components/renderers/JunCourseRenderer.vue +8 -0
  23. package/dist/runtime/components/renderers/JunEntryRenderer.vue +4 -0
  24. package/dist/runtime/components/renderers/JunGardenRenderer.vue +94 -36
  25. package/dist/runtime/components/renderers/JunHomeRenderer.vue +4 -0
  26. package/dist/runtime/components/renderers/JunItemRenderer.vue +4 -0
  27. package/dist/runtime/components/renderers/JunMosaicRenderer.vue +1 -0
  28. package/dist/runtime/components/renderers/JunTrackRenderer.vue +3 -0
  29. package/dist/runtime/composables/useJunChrome.d.ts +14 -0
  30. package/dist/runtime/composables/useJunChrome.js +17 -0
  31. package/dist/runtime/composables/useJunDocLinkMenu.d.ts +69 -0
  32. package/dist/runtime/composables/useJunDocLinkMenu.js +99 -0
  33. package/dist/runtime/composables/useJunDocMenuHost.d.ts +18 -0
  34. package/dist/runtime/composables/useJunDocMenuHost.js +26 -0
  35. package/dist/runtime/composables/useJunProseLinkMenu.d.ts +1 -0
  36. package/dist/runtime/composables/useJunProseLinkMenu.js +132 -0
  37. package/dist/runtime/composables/useJunSurface.d.ts +13 -0
  38. package/dist/runtime/composables/useJunSurface.js +4 -0
  39. package/dist/runtime/layouts/jun.vue +7 -0
  40. package/dist/runtime/server/plugins/jun-bootstrap.js +46 -2
  41. package/dist/runtime/server/utils/junServiceFetch.js +22 -10
  42. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ export declare function useJunProseLinkMenu(): void;
@@ -0,0 +1,132 @@
1
+ import { onBeforeUnmount, onMounted } from "vue";
2
+ import { useDocSlugs, useDocTree, useRuntimeConfig } from "#imports";
3
+ import { useJunDocMenuHost, useJunMenuTree } from "./useJunDocMenuHost.js";
4
+ import { useJunDocMenu } from "./useJunDocMenu.js";
5
+ import { useJunStudio } from "./useJunStudio.js";
6
+ const PRESS_SLOP_PX = 8;
7
+ const PRESS_MS = 500;
8
+ const CLICK_GUARD_MS = 700;
9
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
+ export function useJunProseLinkMenu() {
11
+ if (!import.meta.client) return;
12
+ const { show, hide } = useJunDocMenuHost();
13
+ const { itemsFor } = useJunDocMenu();
14
+ const { getDocId } = useDocSlugs();
15
+ const { getEntry } = useDocTree();
16
+ const { editing } = useJunStudio();
17
+ const siteTree = useJunMenuTree();
18
+ const config = useRuntimeConfig();
19
+ const docBasePath = config.public.abracadabra?.docBasePath ?? "/doc";
20
+ function docIdAt(target) {
21
+ if (!(target instanceof Element)) return null;
22
+ const el = target.closest("a[href], [data-doc-id]");
23
+ if (!el) return null;
24
+ const stated = el.getAttribute("data-doc-id");
25
+ if (stated && getEntry(stated)) return stated;
26
+ const href = el.getAttribute("href");
27
+ if (!href) return null;
28
+ let url;
29
+ try {
30
+ url = new URL(href, window.location.href);
31
+ } catch {
32
+ return null;
33
+ }
34
+ if (url.origin !== window.location.origin) return null;
35
+ if (!url.pathname || url.pathname === window.location.pathname) {
36
+ if (url.hash) return null;
37
+ }
38
+ const path = url.pathname.replace(/^\/+|\/+$/g, "");
39
+ if (!path) return null;
40
+ const base = docBasePath.replace(/^\/+|\/+$/g, "");
41
+ if (base && path.startsWith(`${base}/`)) {
42
+ const rest = path.slice(base.length + 1);
43
+ if (UUID.test(rest) && getEntry(rest)) return rest;
44
+ const viaSlug = getDocId(rest);
45
+ return viaSlug && getEntry(viaSlug) ? viaSlug : null;
46
+ }
47
+ if (UUID.test(path) && getEntry(path)) return path;
48
+ const id = getDocId(path);
49
+ return id && getEntry(id) ? id : null;
50
+ }
51
+ function itemsForDoc(docId) {
52
+ const entry = getEntry(docId);
53
+ return itemsFor(
54
+ {
55
+ docId,
56
+ label: entry?.label || "Untitled",
57
+ type: entry?.type,
58
+ meta: entry?.meta,
59
+ // Its own surface, so a `registerJunMenuItems()` builder can tell a
60
+ // link inside somebody's writing from a card in a list.
61
+ surface: "page",
62
+ editing: editing.value
63
+ },
64
+ {
65
+ tree: siteTree(),
66
+ // The prose link IS the way there, so "Open" would be a second copy of
67
+ // the thing you just pressed.
68
+ noOpen: true
69
+ }
70
+ );
71
+ }
72
+ function onContextmenu(e) {
73
+ if (e.defaultPrevented) return;
74
+ const docId = docIdAt(e.target);
75
+ if (!docId) return;
76
+ const items = itemsForDoc(docId);
77
+ if (!items.length) return;
78
+ e.preventDefault();
79
+ show(items, e.clientX, e.clientY);
80
+ }
81
+ let timer = null;
82
+ let start = null;
83
+ let suppressClickUntil = 0;
84
+ function cancel() {
85
+ if (timer) clearTimeout(timer);
86
+ timer = null;
87
+ start = null;
88
+ }
89
+ function onPointerdown(e) {
90
+ if (e.pointerType === "mouse" || e.defaultPrevented) return;
91
+ cancel();
92
+ const docId = docIdAt(e.target);
93
+ if (!docId) return;
94
+ start = { x: e.clientX, y: e.clientY };
95
+ const at = { x: e.clientX, y: e.clientY };
96
+ timer = setTimeout(() => {
97
+ timer = null;
98
+ const items = itemsForDoc(docId);
99
+ if (!items.length) return;
100
+ suppressClickUntil = performance.now() + CLICK_GUARD_MS;
101
+ show(items, at.x, at.y);
102
+ }, PRESS_MS);
103
+ }
104
+ function onPointermove(e) {
105
+ if (!start) return;
106
+ if (Math.hypot(e.clientX - start.x, e.clientY - start.y) <= PRESS_SLOP_PX) return;
107
+ cancel();
108
+ hide();
109
+ }
110
+ function onClickCapture(e) {
111
+ if (performance.now() >= suppressClickUntil) return;
112
+ e.preventDefault();
113
+ e.stopPropagation();
114
+ }
115
+ onMounted(() => {
116
+ document.addEventListener("contextmenu", onContextmenu);
117
+ document.addEventListener("pointerdown", onPointerdown);
118
+ document.addEventListener("pointermove", onPointermove, { passive: true });
119
+ document.addEventListener("pointerup", cancel);
120
+ document.addEventListener("pointercancel", cancel);
121
+ document.addEventListener("click", onClickCapture, { capture: true });
122
+ });
123
+ onBeforeUnmount(() => {
124
+ cancel();
125
+ document.removeEventListener("contextmenu", onContextmenu);
126
+ document.removeEventListener("pointerdown", onPointerdown);
127
+ document.removeEventListener("pointermove", onPointermove);
128
+ document.removeEventListener("pointerup", cancel);
129
+ document.removeEventListener("pointercancel", cancel);
130
+ document.removeEventListener("click", onClickCapture, { capture: true });
131
+ });
132
+ }
@@ -17,3 +17,16 @@ import { type ComputedRef } from 'vue';
17
17
  export declare function useJunSurface(): {
18
18
  isEmbedded: ComputedRef<boolean>;
19
19
  };
20
+ /**
21
+ * Declare that every renderer mounted below this component is on a bounded
22
+ * PANEL surface rather than owning the viewport.
23
+ *
24
+ * The mirror of `useJunSurface()`, and guarded the same way for the same
25
+ * reason: an auto-import that never resolved compiles to a FREE IDENTIFIER,
26
+ * which throws a `ReferenceError` on call and takes the whole component down
27
+ * with it. `provideRendererSurface` landed upstream in 2.62 and this module's
28
+ * floor is well past that, so the guard is belt and braces — but a component
29
+ * that silently does not declare its surface is a much smaller failure than one
30
+ * that does not render, and this is the only way to choose which.
31
+ */
32
+ export declare function provideJunPanelSurface(): void;
@@ -6,3 +6,7 @@ export function useJunSurface() {
6
6
  const { isEmbedded } = useRendererSurface();
7
7
  return { isEmbedded };
8
8
  }
9
+ export function provideJunPanelSurface() {
10
+ if (typeof provideRendererSurface !== "function") return;
11
+ provideRendererSurface("panel");
12
+ }
@@ -207,6 +207,13 @@ if (import.meta.client && contextMenu.suppressNative) {
207
207
  <JunNodePanel />
208
208
  </ClientOnly>
209
209
 
210
+ <!-- The document menu, for every surface that links to a document and has
211
+ nowhere to put a wrapper: breadcrumbs, "read next", a garden's graph
212
+ nodes, the nav's sub-page flyout, a course's steps. Mounted once, here,
213
+ so it survives the navigation its own items trigger — and it renders
214
+ nothing at all until something is pressed. See `useJunDocMenuHost`. -->
215
+ <JunDocMenuHost />
216
+
210
217
  <!-- The owner studio: login modal and edit-mode dock. Invisible to visitors. -->
211
218
  <template v-if="features.studio">
212
219
  <JunStudioLogin />
@@ -342,15 +342,59 @@ function defaultTree(typeIds) {
342
342
  // Real, keyless references so a fresh deployment shows genuine figures
343
343
  // rather than an empty grid — and so a broken adapter is visible on the
344
344
  // first boot rather than the first time an owner tries one.
345
+ //
346
+ // ONE PER ADAPTER, and that is the point of the list rather than a
347
+ // preference for variety. The seed carried `github-repo` and `npm`
348
+ // only, so five of the seven adapters were never exercised by anything:
349
+ // not the demo, not `pnpm parity`, not a first boot. The npm one was
350
+ // broken for every package whose registry document is over a megabyte
351
+ // — `nuxt`, `react`, `typescript`, the three most likely things anybody
352
+ // would put on this page — and it presented as "sometimes it works",
353
+ // because the seeded package (`yjs`) is small.
354
+ //
355
+ // `group` sorts them into headings, which is also the only thing that
356
+ // exercises that field.
345
357
  {
346
358
  label: "nuxt/nuxt",
347
359
  type: "doc",
348
- meta: { provider: "github-repo", ref: "nuxt/nuxt" }
360
+ meta: { provider: "github-repo", ref: "nuxt/nuxt", group: "Code" }
361
+ },
362
+ {
363
+ label: "nuxt",
364
+ type: "doc",
365
+ meta: { provider: "github-user", ref: "nuxt", group: "Code" }
349
366
  },
350
367
  {
351
368
  label: "yjs",
352
369
  type: "doc",
353
- meta: { provider: "npm", ref: "yjs" }
370
+ meta: { provider: "npm", ref: "yjs", group: "Packages" }
371
+ },
372
+ // The package the 1 MB body cap used to break. It is seeded precisely
373
+ // so that regression cannot come back unnoticed.
374
+ {
375
+ label: "nuxt (npm)",
376
+ type: "doc",
377
+ meta: { provider: "npm", ref: "nuxt", group: "Packages" }
378
+ },
379
+ {
380
+ label: "serde",
381
+ type: "doc",
382
+ meta: { provider: "crates", ref: "serde", group: "Packages" }
383
+ },
384
+ {
385
+ label: "The Nuxt blog",
386
+ type: "doc",
387
+ meta: { provider: "rss", ref: "https://nuxt.com/blog/rss.xml", group: "Feeds" }
388
+ },
389
+ {
390
+ label: "nuxt.com",
391
+ type: "doc",
392
+ meta: { provider: "http", ref: "https://nuxt.com", group: "Watching" }
393
+ },
394
+ {
395
+ label: "Nuxt",
396
+ type: "doc",
397
+ meta: { provider: "og", ref: "https://nuxt.com", group: "Watching" }
354
398
  }
355
399
  ]
356
400
  });
@@ -84,34 +84,37 @@ async function safeFetch(url, init = {}) {
84
84
  target = new URL(location, u).toString();
85
85
  continue;
86
86
  }
87
- const text = await readCapped(res);
88
- return { status: res.status, text, ms: Date.now() - started };
87
+ const { text, truncated } = await readCapped(res);
88
+ return { status: res.status, text, ms: Date.now() - started, truncated };
89
89
  }
90
90
  throw new JunServiceError("Too many redirects");
91
91
  }
92
92
  async function readCapped(res) {
93
93
  const reader = res.body?.getReader();
94
- if (!reader) return "";
94
+ if (!reader) return { text: "", truncated: false };
95
95
  const decoder = new TextDecoder();
96
96
  let out = "";
97
97
  let total = 0;
98
+ let truncated = false;
98
99
  for (; ; ) {
99
100
  const { done, value } = await reader.read();
100
101
  if (done) break;
101
102
  total += value.byteLength;
102
103
  if (total > MAX_BYTES) {
104
+ truncated = true;
103
105
  void reader.cancel();
104
106
  break;
105
107
  }
106
108
  out += decoder.decode(value, { stream: true });
107
109
  }
108
- return out;
110
+ return { text: out, truncated };
109
111
  }
110
112
  async function fetchJson(url, headers) {
111
- const { status, text } = await safeFetch(url, { accept: "application/json", headers });
113
+ const { status, text, truncated } = await safeFetch(url, { accept: "application/json", headers });
112
114
  if (status === 404) throw new JunServiceError("Not found", 404);
113
115
  if (status === 403 || status === 429) throw new JunServiceError("Rate limited", 429);
114
116
  if (status >= 400) throw new JunServiceError(`Upstream said ${status}`);
117
+ if (truncated) throw new JunServiceError("That answer was too large to read");
115
118
  try {
116
119
  return JSON.parse(text);
117
120
  } catch {
@@ -169,7 +172,7 @@ const GITHUB_USER = async (ref, ctx) => {
169
172
  const NPM = async (ref) => {
170
173
  if (!/^(?:@[\w.-]+\/)?[\w.-]+$/.test(ref)) throw new JunServiceError("Expected a package name", 400);
171
174
  const encoded = ref.replace("/", "%2F");
172
- const pkg = await fetchJson(`https://registry.npmjs.org/${encoded}`);
175
+ const pkg = await fetchJson(`https://registry.npmjs.org/${encoded}/latest`);
173
176
  let weekly = "\u2014";
174
177
  try {
175
178
  const dl = await fetchJson(
@@ -178,7 +181,16 @@ const NPM = async (ref) => {
178
181
  weekly = compact(dl.downloads);
179
182
  } catch {
180
183
  }
181
- const latest = pkg["dist-tags"]?.latest ?? "";
184
+ let modified;
185
+ try {
186
+ const abbreviated = await fetchJson(
187
+ `https://registry.npmjs.org/${encoded}`,
188
+ { accept: "application/vnd.npm.install-v1+json" }
189
+ );
190
+ modified = abbreviated.modified;
191
+ } catch {
192
+ }
193
+ const licence = typeof pkg.license === "string" ? pkg.license : pkg.license?.type ?? "\u2014";
182
194
  return {
183
195
  provider: "npm",
184
196
  ref,
@@ -186,11 +198,11 @@ const NPM = async (ref) => {
186
198
  subtitle: pkg.description ?? "",
187
199
  url: `https://www.npmjs.com/package/${ref}`,
188
200
  stats: [
189
- { label: "version", value: latest || "\u2014" },
201
+ { label: "version", value: pkg.version || "\u2014" },
190
202
  { label: "weekly", value: weekly },
191
- { label: "licence", value: pkg.license ?? "\u2014" }
203
+ { label: "licence", value: licence || "\u2014" }
192
204
  ],
193
- timestamp: latest ? pkg.time?.[latest] : pkg.time?.modified,
205
+ timestamp: modified,
194
206
  fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
195
207
  };
196
208
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/junis",
3
- "version": "2.96.0",
3
+ "version": "2.99.0",
4
4
  "description": "Website-builder Nuxt module for the Abracadabra CRDT platform — page-type renderers, presence chrome, studio editing and SSR, all driven by documents",
5
5
  "repository": "abracadabra/jun-is",
6
6
  "license": "MIT",