@abraca/nuxt 2.86.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.
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "2.86.0",
7
+ "version": "2.87.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -34,6 +34,15 @@ type __VLS_Props = {
34
34
  label?: string;
35
35
  meta?: Record<string, unknown>;
36
36
  } | null;
37
+ /**
38
+ * Rendered HTML of this document's BODY from the app's server-side cache.
39
+ *
40
+ * Provided to descendants (see `useSsrBodyHtml`) so `<AEditor>` — which may be
41
+ * several renderer-specific components deep — can paint real prose during SSR
42
+ * instead of its skeleton. Falls back to `/api/_abracadabra/render/:docId`
43
+ * when the app does not pass one.
44
+ */
45
+ ssrHtml?: string | null;
37
46
  /**
38
47
  * Forward to editor-type renderers (`doc`/`prose` → <AEditor>): show the
39
48
  * built-in sub-page list (<ADocSubPageList>) below the body. Default: true.
@@ -2,6 +2,8 @@
2
2
  import { computed, watch, shallowRef } from "vue";
3
3
  import { useFetch } from "#imports";
4
4
  import { useAbracadabra } from "../composables/useAbracadabra";
5
+ import { useDocTreeSnapshot } from "../composables/useDocTreeSnapshot";
6
+ import { provideSsrBodyHtml } from "../composables/useSsrBodyHtml";
5
7
  import { useSpaceConnections } from "../composables/useSpaceConnections";
6
8
  import { usePluginRegistry } from "../composables/usePluginRegistry";
7
9
  import { useDocumentPermissions } from "../composables/useDocumentPermissions";
@@ -15,14 +17,26 @@ const props = defineProps({
15
17
  rendererClass: { type: String, required: false },
16
18
  canvasClass: { type: String, required: false, default: "flex flex-col w-full h-[70vh] min-h-[420px]" },
17
19
  entry: { type: [Object, null], required: false },
20
+ ssrHtml: { type: [String, null], required: false },
18
21
  showSubPages: { type: Boolean, required: false, default: true }
19
22
  });
20
23
  const abra = useAbracadabra();
21
24
  const { resolveEntry, findDocSpaceId, getProviderForDoc, connectSpace, connections } = useSpaceConnections();
22
25
  const resolvedEntry = computed(() => resolveEntry(props.docId));
23
- const docTitle = computed(() => props.entry?.label ?? resolvedEntry.value?.label ?? "Untitled");
24
- const docType = computed(() => props.entry?.type ?? resolvedEntry.value?.type ?? "doc");
25
- const docMeta = computed(() => props.entry?.meta ?? resolvedEntry.value?.meta ?? {});
26
+ const snapshot = useDocTreeSnapshot();
27
+ const snapshotEntry = computed(
28
+ () => snapshot.value?.entries?.[props.docId]
29
+ );
30
+ const docTitle = computed(
31
+ () => props.entry?.label ?? snapshotEntry.value?.label ?? resolvedEntry.value?.label ?? "Untitled"
32
+ );
33
+ const docType = computed(
34
+ () => props.entry?.type ?? snapshotEntry.value?.type ?? resolvedEntry.value?.type ?? "doc"
35
+ );
36
+ const docMeta = computed(
37
+ () => props.entry?.meta ?? snapshotEntry.value?.meta ?? resolvedEntry.value?.meta ?? {}
38
+ );
39
+ const canRenderOffline = computed(() => !!(props.entry?.type ?? snapshotEntry.value?.type));
26
40
  const registry = usePluginRegistry();
27
41
  const docTypeDef = computed(() => resolveDocType(docType.value, registry));
28
42
  const childProvider = shallowRef(null);
@@ -59,6 +73,10 @@ const { data: ssrContent } = useFetch(
59
73
  () => `/api/_abracadabra/render/${props.docId}`,
60
74
  { key: `render-${props.docId}`, server: true, lazy: true }
61
75
  );
76
+ provideSsrBodyHtml(computed(() => {
77
+ const html = props.ssrHtml || ssrContent.value?.html || "";
78
+ return html ? { docId: props.docId, html } : null;
79
+ }));
62
80
  const resolvedClass = computed(
63
81
  () => docTypeDef.value.hasEditor ? props.editorClass ?? void 0 : props.rendererClass ?? void 0
64
82
  );
@@ -71,8 +89,8 @@ const wrapperClass = computed(
71
89
  </script>
72
90
 
73
91
  <template>
74
- <!-- Loading state -->
75
- <div v-if="!abra.isReady.value">
92
+ <!-- Loading state — only when we cannot draw the real thing yet. -->
93
+ <div v-if="!abra.isReady.value && !canRenderOffline">
76
94
  <!-- SSR: show pre-rendered HTML while client hydrates -->
77
95
  <!-- eslint-disable vue/no-v-html -->
78
96
  <div
@@ -94,9 +112,10 @@ const wrapperClass = computed(
94
112
  </slot>
95
113
  </div>
96
114
 
97
- <!-- Connection error -->
115
+ <!-- Connection error. Not while we can still draw from a snapshot: a page
116
+ that renders is better than an alert, and the socket may yet arrive. -->
98
117
  <slot
99
- v-else-if="abra.connectionError.value && !abra.synced.value"
118
+ v-else-if="abra.connectionError.value && !abra.synced.value && !canRenderOffline"
100
119
  name="error"
101
120
  :error="abra.connectionError.value"
102
121
  >
@@ -34,6 +34,15 @@ type __VLS_Props = {
34
34
  label?: string;
35
35
  meta?: Record<string, unknown>;
36
36
  } | null;
37
+ /**
38
+ * Rendered HTML of this document's BODY from the app's server-side cache.
39
+ *
40
+ * Provided to descendants (see `useSsrBodyHtml`) so `<AEditor>` — which may be
41
+ * several renderer-specific components deep — can paint real prose during SSR
42
+ * instead of its skeleton. Falls back to `/api/_abracadabra/render/:docId`
43
+ * when the app does not pass one.
44
+ */
45
+ ssrHtml?: string | null;
37
46
  /**
38
47
  * Forward to editor-type renderers (`doc`/`prose` → <AEditor>): show the
39
48
  * built-in sub-page list (<ADocSubPageList>) below the body. Default: true.
@@ -3,6 +3,8 @@ import { shallowRef, ref, watch, watchEffect, computed, nextTick, onBeforeUnmoun
3
3
  import { useNuxtApp, navigateTo, useRuntimeConfig } from "#imports";
4
4
  import { Fragment } from "@tiptap/pm/model";
5
5
  import { useSyncedMap } from "../composables/useYDoc";
6
+ import { useSsrBodyHtmlFor } from "../composables/useSsrBodyHtml";
7
+ import { useDocTreeSnapshot } from "../composables/useDocTreeSnapshot";
6
8
  import { resolveDocType, GEO_TYPE_META_SCHEMAS } from "../utils/docTypes";
7
9
  import { schemaFieldToAttrs, userFieldToAttrs, inferFieldAttrs, AUTO_DETECT_EXCLUDED } from "../extensions/meta-field";
8
10
  import { DATE_SIBLING_KEY } from "../utils/dateField";
@@ -58,6 +60,8 @@ const emit = defineEmits(["ready", "update", "rename", "updateMeta"]);
58
60
  const model = defineModel({ type: null });
59
61
  const { doc, provider, registry, effectiveRole, client } = useNuxtApp().$abracadabra;
60
62
  const { connections, getProviderForDoc, getDocForDoc } = useSpaceConnections();
63
+ const ssrBodyHtml = useSsrBodyHtmlFor(() => props.docId);
64
+ const hasSsrDocContext = useDocTreeSnapshot();
61
65
  const ownerProvider = computed(() => getProviderForDoc(props.docId) ?? provider.value);
62
66
  const ownerDoc = shallowRef(getDocForDoc(props.docId) ?? doc.value);
63
67
  watch(() => [doc.value, connections.size], () => {
@@ -1211,7 +1215,25 @@ function onPlusClick(e, onClick) {
1211
1215
  </div>
1212
1216
 
1213
1217
  <template #fallback>
1218
+ <!-- The document's real prose, from the app's server-side cache. This
1219
+ is what a crawler indexes and what a cold reader sees first: the
1220
+ body lives in a Y.XmlFragment, which is empty for the whole of SSR,
1221
+ so without it every prose page server-rendered three pulsing grey
1222
+ bars. Falls back to the skeleton only when no cache is available. -->
1223
+ <!-- eslint-disable vue/no-v-html -->
1214
1224
  <div
1225
+ v-if="ssrBodyHtml"
1226
+ class="p-6"
1227
+ :class="{ 'prose-variant': variant === 'prose' }"
1228
+ >
1229
+ <div
1230
+ class="prose dark:prose-invert max-w-none"
1231
+ v-html="ssrBodyHtml"
1232
+ />
1233
+ </div>
1234
+ <!-- eslint-enable vue/no-v-html -->
1235
+ <div
1236
+ v-else-if="!hasSsrDocContext"
1215
1237
  class="p-6 space-y-3"
1216
1238
  :class="{ 'prose-variant': variant === 'prose' }"
1217
1239
  >
@@ -14,13 +14,13 @@ type __VLS_Props = {
14
14
  extraItems?: DropdownMenuItem[][];
15
15
  };
16
16
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
17
+ logout: () => any;
17
18
  "open-settings": () => any;
18
19
  "open-account": () => any;
19
- logout: () => any;
20
20
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
21
+ onLogout?: (() => any) | undefined;
21
22
  "onOpen-settings"?: (() => any) | undefined;
22
23
  "onOpen-account"?: (() => any) | undefined;
23
- onLogout?: (() => any) | undefined;
24
24
  }>, {
25
25
  color: string;
26
26
  collapsed: boolean;
@@ -14,13 +14,13 @@ type __VLS_Props = {
14
14
  extraItems?: DropdownMenuItem[][];
15
15
  };
16
16
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
17
+ logout: () => any;
17
18
  "open-settings": () => any;
18
19
  "open-account": () => any;
19
- logout: () => any;
20
20
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
21
+ onLogout?: (() => any) | undefined;
21
22
  "onOpen-settings"?: (() => any) | undefined;
22
23
  "onOpen-account"?: (() => any) | undefined;
23
- onLogout?: (() => any) | undefined;
24
24
  }>, {
25
25
  color: string;
26
26
  collapsed: boolean;
@@ -1,6 +1,7 @@
1
1
  import { computed } from "vue";
2
2
  import { useSyncedMap } from "./useYDoc.js";
3
3
  import { useAbracadabra } from "./useAbracadabra.js";
4
+ import { useDocTreeSnapshot } from "./useDocTreeSnapshot.js";
4
5
  import { isDescendantInMap } from "../utils/docDragDrop.js";
5
6
  export function useChildTree(rootDoc, parentDocId, options) {
6
7
  const abraState = (() => {
@@ -12,9 +13,15 @@ export function useChildTree(rootDoc, parentDocId, options) {
12
13
  })();
13
14
  const treeMap = useSyncedMap(rootDoc, "doc-tree");
14
15
  const trashMap = useSyncedMap(rootDoc, "doc-trash");
16
+ const snapshot = useDocTreeSnapshot();
17
+ const source = computed(() => {
18
+ const live = treeMap.data;
19
+ if (live && Object.keys(live).length > 0) return live;
20
+ return snapshot.value?.entries ?? {};
21
+ });
15
22
  const entries = computed(() => {
16
23
  const result = [];
17
- for (const [id, v] of Object.entries(treeMap.data)) {
24
+ for (const [id, v] of Object.entries(source.value)) {
18
25
  if (id === parentDocId && options?.isSpaceRoot) continue;
19
26
  let pid = v.parentId ?? null;
20
27
  if (options?.isSpaceRoot && pid === null) pid = parentDocId;
@@ -3,16 +3,23 @@ import { buildSlugMap } from "../utils/slugify.js";
3
3
  import { useRuntimeConfig } from "#imports";
4
4
  import { useAbracadabra } from "./useAbracadabra.js";
5
5
  import { useSyncedMap } from "./useYDoc.js";
6
+ import { useDocTreeSnapshot } from "./useDocTreeSnapshot.js";
6
7
  export function useDocSlugs() {
7
8
  const abra = useAbracadabra();
8
9
  const config = useRuntimeConfig();
9
10
  const docBasePath = config.public?.abracadabra?.docBasePath ?? "/doc";
10
11
  const treeMap = useSyncedMap(abra.doc, "doc-tree");
12
+ const snapshot = useDocTreeSnapshot();
13
+ const source = computed(() => {
14
+ const live = treeMap.data;
15
+ if (live && Object.keys(live).length > 0) return live;
16
+ return snapshot.value?.entries ?? {};
17
+ });
11
18
  const entries = computed(
12
- () => Object.entries(treeMap.data).map(([id, entry]) => ({ id, ...entry }))
19
+ () => Object.entries(source.value).map(([id, entry]) => ({ id, ...entry }))
13
20
  );
14
21
  const slugMap = computed(
15
- () => buildSlugMap(entries.value, abra.spaceDocId?.value ?? null)
22
+ () => buildSlugMap(entries.value, abra.spaceDocId?.value ?? snapshot.value?.rootId ?? null)
16
23
  );
17
24
  const getSlug = (docId) => slugMap.value.idToSlug[docId] ?? docId;
18
25
  const getDocId = (slug) => slugMap.value.slugToId[slug] ?? null;
@@ -8,6 +8,7 @@
8
8
  import { type ComputedRef } from 'vue';
9
9
  import type { TreeEntry } from '../types.js';
10
10
  import { useSyncedMap } from './useYDoc.js';
11
+ export { useDocTreeSnapshot, ABRA_DOC_TREE_SNAPSHOT_STATE, type DocTreeSnapshot } from './useDocTreeSnapshot.js';
11
12
  export interface DocTreeReturn {
12
13
  /** All tree entries with `id` populated from map keys */
13
14
  entries: ComputedRef<(TreeEntry & {
@@ -2,9 +2,11 @@ import { computed, shallowRef, watch } from "vue";
2
2
  import { resolveDocType } from "../utils/docTypes.js";
3
3
  import { buildSlugMap } from "../utils/slugify.js";
4
4
  import { useRuntimeConfig } from "#imports";
5
+ import { useDocTreeSnapshot } from "./useDocTreeSnapshot.js";
5
6
  import { useAbracadabra } from "./useAbracadabra.js";
6
7
  import { useSpaceConnections } from "./useSpaceConnections.js";
7
8
  import { useSyncedMap } from "./useYDoc.js";
9
+ export { useDocTreeSnapshot, ABRA_DOC_TREE_SNAPSHOT_STATE } from "./useDocTreeSnapshot.js";
8
10
  export function useDocTree(docId) {
9
11
  const abra = useAbracadabra();
10
12
  const { connections, getDocForDoc, findDocSpaceId } = useSpaceConnections();
@@ -27,11 +29,17 @@ export function useDocTree(docId) {
27
29
  }, { immediate: true });
28
30
  }
29
31
  const treeMap = useSyncedMap(boundDoc, "doc-tree");
32
+ const snapshot = useDocTreeSnapshot();
33
+ const source = computed(() => {
34
+ const live = treeMap.data;
35
+ if (live && Object.keys(live).length > 0) return live;
36
+ return snapshot.value?.entries ?? {};
37
+ });
30
38
  const spaceDocId = computed(
31
- () => docId ? findDocSpaceId(docId) ?? abra.spaceDocId.value : abra.spaceDocId.value
39
+ () => (docId ? findDocSpaceId(docId) ?? abra.spaceDocId.value : abra.spaceDocId.value) ?? snapshot.value?.rootId ?? null
32
40
  );
33
41
  const entries = computed(
34
- () => Object.entries(treeMap.data).filter(([id]) => id !== spaceDocId.value).map(([id, entry]) => ({ id, ...entry }))
42
+ () => Object.entries(source.value).filter(([id]) => id !== spaceDocId.value).map(([id, entry]) => ({ id, ...entry }))
35
43
  );
36
44
  const topLevelDocs = computed(
37
45
  () => entries.value.filter(
@@ -40,7 +48,7 @@ export function useDocTree(docId) {
40
48
  );
41
49
  const firstDocId = computed(() => topLevelDocs.value[0]?.id ?? null);
42
50
  const getEntry = (id) => {
43
- const raw = treeMap.data[id];
51
+ const raw = source.value[id];
44
52
  return raw ? { id, ...raw } : void 0;
45
53
  };
46
54
  const slugMap = computed(() => buildSlugMap(entries.value, spaceDocId.value ?? null));
@@ -0,0 +1,8 @@
1
+ export interface DocTreeSnapshot {
2
+ /** The space document's id — what "top level" is measured against. */
3
+ rootId?: string | null;
4
+ /** Tree entries by id, in the same shape the `doc-tree` map holds. */
5
+ entries: Record<string, unknown>;
6
+ }
7
+ export declare const ABRA_DOC_TREE_SNAPSHOT_STATE = "abracadabra:doc-tree-snapshot";
8
+ export declare function useDocTreeSnapshot(): import("vue").Ref<DocTreeSnapshot | null, DocTreeSnapshot | null>;
@@ -0,0 +1,5 @@
1
+ import { useState } from "#imports";
2
+ export const ABRA_DOC_TREE_SNAPSHOT_STATE = "abracadabra:doc-tree-snapshot";
3
+ export function useDocTreeSnapshot() {
4
+ return useState(ABRA_DOC_TREE_SNAPSHOT_STATE, () => null);
5
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The cached HTML of a document's BODY, for the window before the CRDT arrives.
3
+ *
4
+ * ## Why
5
+ *
6
+ * A document's prose lives in a Y.XmlFragment, which is empty for the whole of
7
+ * SSR — so `<AEditor>` renders a skeleton on the server, and any page whose
8
+ * content is prose shipped three pulsing grey bars to a crawler. Apps papered
9
+ * over this by wrapping the whole page in `<ClientOnly>` and putting cached HTML
10
+ * in the fallback, which works right up until you want the RENDERER to server-
11
+ * render too: then the renderer draws, the editor inside it draws a skeleton,
12
+ * and the prose is gone.
13
+ *
14
+ * So the cached body travels as context instead. `<ADocRenderer>` provides it,
15
+ * `<AEditor>` consumes it, and nothing in between has to thread a prop through
16
+ * — which matters because the editor is often several renderer-specific
17
+ * components deep (a collection's intro, an item's body).
18
+ *
19
+ * ## Keyed by docId, deliberately
20
+ *
21
+ * A page can host editors for OTHER documents — a mosaic pane, an embedded
22
+ * child, a preview. An unkeyed provide would hand every one of them the host
23
+ * page's prose, which is worse than a skeleton: it is confidently wrong content
24
+ * under someone else's title. Consumers must compare `docId` before using
25
+ * `html`, and `useSsrBodyHtmlFor()` does that for them.
26
+ */
27
+ import { type ComputedRef, type InjectionKey } from 'vue';
28
+ export interface SsrBodyHtml {
29
+ /** The document this HTML belongs to. */
30
+ docId: string;
31
+ /** Rendered body HTML from the app's server-side document cache. */
32
+ html: string;
33
+ }
34
+ export declare const ABRA_SSR_BODY_HTML: InjectionKey<ComputedRef<SsrBodyHtml | null>>;
35
+ /** Publish the cached body for `docId` to descendants. */
36
+ export declare function provideSsrBodyHtml(value: ComputedRef<SsrBodyHtml | null>): void;
37
+ /**
38
+ * The cached body for THIS document, or `''` when there is none for it.
39
+ *
40
+ * Returns `''` rather than the ancestor's HTML when the ids differ — see the
41
+ * keying note above.
42
+ */
43
+ export declare function useSsrBodyHtmlFor(docId: () => string | undefined | null): ComputedRef<string>;
@@ -0,0 +1,14 @@
1
+ import { computed, inject, provide } from "vue";
2
+ export const ABRA_SSR_BODY_HTML = Symbol("abracadabra:ssr-body-html");
3
+ export function provideSsrBodyHtml(value) {
4
+ provide(ABRA_SSR_BODY_HTML, value);
5
+ }
6
+ export function useSsrBodyHtmlFor(docId) {
7
+ const provided = inject(ABRA_SSR_BODY_HTML, null);
8
+ return computed(() => {
9
+ const v = provided?.value;
10
+ if (!v || !v.html) return "";
11
+ const id = docId();
12
+ return id && v.docId === id ? v.html : "";
13
+ });
14
+ }
@@ -1,20 +1,28 @@
1
1
  import { shallowRef, ref, computed } from "vue";
2
2
  import { defineNuxtPlugin } from "#imports";
3
3
  import { PluginRegistry } from "./plugin-registry.js";
4
+ import { useDocTreeSnapshot } from "./composables/useDocTreeSnapshot.js";
4
5
  export default defineNuxtPlugin({
5
6
  name: "abracadabra:server-stub",
6
7
  enforce: "post",
7
- setup(nuxtApp) {
8
+ async setup(nuxtApp) {
8
9
  const registry = new PluginRegistry();
10
+ const { _collectSchemaRegistries } = await import("./composables/useAbracadabraSchema.js");
11
+ const { plugins: inlinePlugins } = await _collectSchemaRegistries(nuxtApp);
12
+ for (const plugin of inlinePlugins) {
13
+ registry.register(plugin);
14
+ }
9
15
  registry.freeze();
10
16
  const noop = () => {
11
17
  };
12
18
  const noopAsync = async () => {
13
19
  };
20
+ const snapshot = useDocTreeSnapshot();
21
+ const spaceDocId = computed(() => snapshot.value?.rootId ?? null);
14
22
  nuxtApp.provide("abracadabra", {
15
23
  // CRDT objects — null on server
16
24
  doc: shallowRef(null),
17
- spaceDocId: ref(null),
25
+ spaceDocId,
18
26
  provider: shallowRef(null),
19
27
  client: shallowRef(null),
20
28
  keystore: shallowRef(null),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/nuxt",
3
- "version": "2.86.0",
3
+ "version": "2.87.0",
4
4
  "description": "First-class Nuxt module for the Abracadabra CRDT collaboration platform",
5
5
  "repository": "abracadabra/abracadabra-nuxt",
6
6
  "license": "MIT",
@@ -173,9 +173,9 @@
173
173
  }
174
174
  },
175
175
  "devDependencies": {
176
- "@abraca/convert": "^2.85.0",
177
- "@abraca/dabra": "^2.85.0",
178
- "@abraca/plugin": "^2.85.0",
176
+ "@abraca/convert": "^2.86.0",
177
+ "@abraca/dabra": "^2.86.0",
178
+ "@abraca/plugin": "^2.86.0",
179
179
  "@codemirror/autocomplete": "^6.18.0",
180
180
  "@codemirror/commands": "^6.7.0",
181
181
  "@codemirror/lang-css": "^6.3.1",