@abraca/nuxt 2.86.0 → 2.88.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/runtime/components/ADocRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/ADocRenderer.vue +26 -7
- package/dist/runtime/components/ADocRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/AEditor.vue +22 -0
- package/dist/runtime/components/shell/AUserMenu.d.vue.ts +2 -2
- package/dist/runtime/components/shell/AUserMenu.vue.d.ts +2 -2
- package/dist/runtime/composables/useChildTree.js +8 -1
- package/dist/runtime/composables/useDocSlugs.js +9 -2
- package/dist/runtime/composables/useDocTree.d.ts +1 -0
- package/dist/runtime/composables/useDocTree.js +11 -3
- package/dist/runtime/composables/useDocTreeSnapshot.d.ts +8 -0
- package/dist/runtime/composables/useDocTreeSnapshot.js +5 -0
- package/dist/runtime/composables/useEdgeSwipe.d.ts +58 -0
- package/dist/runtime/composables/useEdgeSwipe.js +82 -0
- package/dist/runtime/composables/useSsrBodyHtml.d.ts +43 -0
- package/dist/runtime/composables/useSsrBodyHtml.js +14 -0
- package/dist/runtime/composables/useSwipeGesture.d.ts +32 -1
- package/dist/runtime/composables/useSwipeGesture.js +18 -2
- package/dist/runtime/plugin-abracadabra.server.js +10 -2
- package/package.json +4 -4
package/dist/module.json
CHANGED
|
@@ -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
|
|
24
|
-
const
|
|
25
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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 =
|
|
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,58 @@
|
|
|
1
|
+
import { type MaybeRefOrGetter } from 'vue';
|
|
2
|
+
export interface EdgeSwipeOptions {
|
|
3
|
+
/** A swipe that began at the left edge and travelled inward. */
|
|
4
|
+
onFromLeft?: () => void;
|
|
5
|
+
/** A swipe that began at the right edge and travelled inward. */
|
|
6
|
+
onFromRight?: () => void;
|
|
7
|
+
/** Turn the whole thing off without unmounting the caller. */
|
|
8
|
+
disabled?: MaybeRefOrGetter<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* How far from an edge a touch counts as an edge touch.
|
|
11
|
+
*
|
|
12
|
+
* 50px by default, which is deliberately WIDER than iOS's own back-swipe
|
|
13
|
+
* zone (~30–40px): a gesture that competes with the browser's has to be
|
|
14
|
+
* recognised before the browser recognises its own.
|
|
15
|
+
*/
|
|
16
|
+
edge?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The narrower band where an edge swipe wins even inside something that
|
|
19
|
+
* scrolls horizontally.
|
|
20
|
+
*
|
|
21
|
+
* A renderer that owns its horizontal axis — a kanban, a map, a timeline —
|
|
22
|
+
* would otherwise trap the reader: every swipe belongs to the renderer and
|
|
23
|
+
* nothing can be opened from inside it. 20px is enough to reach and small
|
|
24
|
+
* enough not to steal the renderer's own gestures.
|
|
25
|
+
*/
|
|
26
|
+
forceEdge?: number;
|
|
27
|
+
/** Minimum inward travel before it counts. */
|
|
28
|
+
threshold?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Also stop the BROWSER acting on the gesture.
|
|
31
|
+
*
|
|
32
|
+
* This is the whole reason edge handling is separate from an ordinary swipe:
|
|
33
|
+
* without `preventDefault` on an edge touch, iOS runs its own back-navigation
|
|
34
|
+
* and the app's gesture and the browser's fight over the same finger. Costs a
|
|
35
|
+
* non-passive `touchmove`, which is why it is a choice.
|
|
36
|
+
*/
|
|
37
|
+
preventBrowserGesture?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A swipe that starts at the screen's edge — the gesture that opens things.
|
|
41
|
+
*
|
|
42
|
+
* Distinct from `useSwipeGesture`, which watches an ELEMENT and tells you which
|
|
43
|
+
* way a finger travelled across it. This watches the WINDOW, cares where the
|
|
44
|
+
* finger started, and exists mostly to win an argument with the browser.
|
|
45
|
+
*
|
|
46
|
+
* Two zones and a scroll check, all three earned in cou-sh:
|
|
47
|
+
*
|
|
48
|
+
* - anything inside `data-swipe-ignore`, or inside a container that actually
|
|
49
|
+
* scrolls horizontally, keeps its own gesture — unless the touch began in
|
|
50
|
+
* the narrow `forceEdge` band;
|
|
51
|
+
* - a touch that starts on a control (a button, a link, an input) is not a
|
|
52
|
+
* swipe, so the control still works at the edge of the screen;
|
|
53
|
+
* - a gesture that travels mostly VERTICALLY is a scroll, not an edge swipe.
|
|
54
|
+
*
|
|
55
|
+
* Client-only by construction: it binds in `onMounted`-free fashion via a guard
|
|
56
|
+
* on `window`, and disposes with the calling scope.
|
|
57
|
+
*/
|
|
58
|
+
export declare function useEdgeSwipe(options?: EdgeSwipeOptions): void;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { onScopeDispose, toValue } from "vue";
|
|
2
|
+
export function useEdgeSwipe(options = {}) {
|
|
3
|
+
if (typeof window === "undefined") return;
|
|
4
|
+
const EDGE = options.edge ?? 50;
|
|
5
|
+
const FORCE_EDGE = options.forceEdge ?? 20;
|
|
6
|
+
const THRESHOLD = options.threshold ?? 60;
|
|
7
|
+
const VERTICAL_SLOP = 40;
|
|
8
|
+
let startX = 0;
|
|
9
|
+
let startY = 0;
|
|
10
|
+
let fromLeft = false;
|
|
11
|
+
let fromRight = false;
|
|
12
|
+
let tracking = false;
|
|
13
|
+
let fired = false;
|
|
14
|
+
function scrollsHorizontally(target) {
|
|
15
|
+
let el = target;
|
|
16
|
+
let depth = 0;
|
|
17
|
+
while (el && el !== document.documentElement && depth < 15) {
|
|
18
|
+
if (el.hasAttribute("data-swipe-ignore")) return true;
|
|
19
|
+
const style = getComputedStyle(el);
|
|
20
|
+
if (style.overflowX === "auto" || style.overflowX === "scroll") {
|
|
21
|
+
const box = el;
|
|
22
|
+
if (box.scrollWidth > box.clientWidth) return true;
|
|
23
|
+
}
|
|
24
|
+
el = el.parentElement;
|
|
25
|
+
depth++;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function onTouchStart(e) {
|
|
30
|
+
tracking = false;
|
|
31
|
+
fired = false;
|
|
32
|
+
if (toValue(options.disabled)) return;
|
|
33
|
+
if (e.touches.length !== 1) return;
|
|
34
|
+
const touch = e.touches[0];
|
|
35
|
+
startX = touch.clientX;
|
|
36
|
+
startY = touch.clientY;
|
|
37
|
+
const atLeft = startX < EDGE;
|
|
38
|
+
const atRight = window.innerWidth - startX < EDGE;
|
|
39
|
+
if (!atLeft && !atRight) return;
|
|
40
|
+
const target = e.target;
|
|
41
|
+
if (target?.closest?.('button, a, input, textarea, select, label, [role="button"]')) return;
|
|
42
|
+
const forced = startX < FORCE_EDGE || window.innerWidth - startX < FORCE_EDGE;
|
|
43
|
+
if (scrollsHorizontally(target) && !forced) return;
|
|
44
|
+
fromLeft = atLeft;
|
|
45
|
+
fromRight = atRight && !atLeft;
|
|
46
|
+
tracking = true;
|
|
47
|
+
}
|
|
48
|
+
function onTouchMove(e) {
|
|
49
|
+
if (!tracking || fired) return;
|
|
50
|
+
const touch = e.touches[0];
|
|
51
|
+
if (!touch) return;
|
|
52
|
+
const dx = touch.clientX - startX;
|
|
53
|
+
const dy = touch.clientY - startY;
|
|
54
|
+
if (Math.abs(dy) > VERTICAL_SLOP && Math.abs(dy) > Math.abs(dx)) {
|
|
55
|
+
tracking = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (options.preventBrowserGesture && e.cancelable) e.preventDefault();
|
|
59
|
+
if (fromLeft && dx > THRESHOLD) {
|
|
60
|
+
fired = true;
|
|
61
|
+
options.onFromLeft?.();
|
|
62
|
+
} else if (fromRight && dx < -THRESHOLD) {
|
|
63
|
+
fired = true;
|
|
64
|
+
options.onFromRight?.();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function onTouchEnd() {
|
|
68
|
+
tracking = false;
|
|
69
|
+
fired = false;
|
|
70
|
+
}
|
|
71
|
+
const moveOptions = { passive: !options.preventBrowserGesture };
|
|
72
|
+
window.addEventListener("touchstart", onTouchStart, { passive: true });
|
|
73
|
+
window.addEventListener("touchmove", onTouchMove, moveOptions);
|
|
74
|
+
window.addEventListener("touchend", onTouchEnd, { passive: true });
|
|
75
|
+
window.addEventListener("touchcancel", onTouchEnd, { passive: true });
|
|
76
|
+
onScopeDispose(() => {
|
|
77
|
+
window.removeEventListener("touchstart", onTouchStart);
|
|
78
|
+
window.removeEventListener("touchmove", onTouchMove);
|
|
79
|
+
window.removeEventListener("touchend", onTouchEnd);
|
|
80
|
+
window.removeEventListener("touchcancel", onTouchEnd);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -22,6 +22,28 @@ export interface SwipeGestureOptions {
|
|
|
22
22
|
disabled?: MaybeRefOrGetter<boolean>;
|
|
23
23
|
/** Restrict to a single axis. Gestures on the other axis pass through. */
|
|
24
24
|
axis?: 'x' | 'y';
|
|
25
|
+
/**
|
|
26
|
+
* Which input may fire this gesture.
|
|
27
|
+
*
|
|
28
|
+
* `any` (the default) keeps the trackpad: a deck, a slideover and a window
|
|
29
|
+
* manager are PAGERS, and paging them with a two-finger flick is the whole
|
|
30
|
+
* point of the wheel half.
|
|
31
|
+
*
|
|
32
|
+
* `touch` is for surfaces where a horizontal wheel is not a gesture but an
|
|
33
|
+
* accident. A reading page is the example: on a Mac, brushing sideways past a
|
|
34
|
+
* wide code block emits exactly the deltas this composable counts, and the
|
|
35
|
+
* reader is navigated away from the page they were reading. Measured, not
|
|
36
|
+
* theorised — eight `deltaX: 25` events took a documentation page to its
|
|
37
|
+
* neighbour.
|
|
38
|
+
*/
|
|
39
|
+
pointer?: 'any' | 'touch';
|
|
40
|
+
/**
|
|
41
|
+
* Damping multiplier for a valid direction. `0` follows the finger with no
|
|
42
|
+
* visible offset at all — which is what a caller passes for a reader who has
|
|
43
|
+
* asked their system for less motion: the gesture still fires, the rubber
|
|
44
|
+
* band is simply not drawn.
|
|
45
|
+
*/
|
|
46
|
+
damp?: MaybeRefOrGetter<number>;
|
|
25
47
|
}
|
|
26
48
|
/**
|
|
27
49
|
* Swipe gesture detection for both touch (mobile) and trackpad/wheel (desktop).
|
|
@@ -31,7 +53,16 @@ export interface SwipeGestureOptions {
|
|
|
31
53
|
*
|
|
32
54
|
* A child with `data-swipe-ignore` lets its own touch-scroll pass through.
|
|
33
55
|
*
|
|
34
|
-
*
|
|
56
|
+
* Shared with cou-sh, which is where this shape was proven. Two things beyond
|
|
57
|
+
* that port, both of which a SITE needs and a dashboard did not:
|
|
58
|
+
*
|
|
59
|
+
* - `disabled` is re-checked on move and on end. It can flip true AFTER
|
|
60
|
+
* `touchstart` — a drag taking over the pointer mid-gesture is the usual
|
|
61
|
+
* way — and an in-flight swipe must then abort and snap back rather than
|
|
62
|
+
* finish and navigate.
|
|
63
|
+
* - `damp` is a caller's, so `prefers-reduced-motion` can be honoured by the
|
|
64
|
+
* thing that knows about it. `damp: 0` still fires the gesture and simply
|
|
65
|
+
* does not draw the rubber band.
|
|
35
66
|
*/
|
|
36
67
|
export declare function useSwipeGesture(options: SwipeGestureOptions): {
|
|
37
68
|
swipeOffset: Ref<{
|
|
@@ -10,6 +10,8 @@ export function useSwipeGesture(options) {
|
|
|
10
10
|
const SWIPE_TRIGGER = 24;
|
|
11
11
|
const DAMP_VALID = 0.4;
|
|
12
12
|
const DAMP_INVALID = 0.1;
|
|
13
|
+
const dampValid = () => toValue(options.damp) ?? DAMP_VALID;
|
|
14
|
+
const dampInvalid = () => toValue(options.damp) == null ? DAMP_INVALID : dampValid() * 0.25;
|
|
13
15
|
function isInsideSwipeIgnore(target, boundary) {
|
|
14
16
|
let el = target;
|
|
15
17
|
while (el && el !== boundary) {
|
|
@@ -35,8 +37,17 @@ export function useSwipeGesture(options) {
|
|
|
35
37
|
isSwiping.value = false;
|
|
36
38
|
swipeOffset.value = { x: 0, y: 0 };
|
|
37
39
|
}
|
|
40
|
+
function resetSwipe() {
|
|
41
|
+
swipeOffset.value = { x: 0, y: 0 };
|
|
42
|
+
isSwiping.value = false;
|
|
43
|
+
touchLockedAxis = null;
|
|
44
|
+
}
|
|
38
45
|
function onTouchMove(e) {
|
|
39
46
|
if (touchIgnored) return;
|
|
47
|
+
if (toValue(options.disabled)) {
|
|
48
|
+
resetSwipe();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
40
51
|
const touch = e.touches[0];
|
|
41
52
|
const dx = touch.clientX - touchStartX;
|
|
42
53
|
const dy = touch.clientY - touchStartY;
|
|
@@ -51,17 +62,21 @@ export function useSwipeGesture(options) {
|
|
|
51
62
|
const canL = toValue(options.canSwipeLeft) ?? !!options.onSwipeLeft;
|
|
52
63
|
const canR = toValue(options.canSwipeRight) ?? !!options.onSwipeRight;
|
|
53
64
|
const valid = dx < 0 && canL || dx > 0 && canR;
|
|
54
|
-
swipeOffset.value = { x: dx * (valid ?
|
|
65
|
+
swipeOffset.value = { x: dx * (valid ? dampValid() : dampInvalid()), y: 0 };
|
|
55
66
|
} else {
|
|
56
67
|
const canU = toValue(options.canSwipeUp) ?? !!options.onSwipeUp;
|
|
57
68
|
const canD = toValue(options.canSwipeDown) ?? !!options.onSwipeDown;
|
|
58
69
|
const valid = dy < 0 && canU || dy > 0 && canD;
|
|
59
|
-
swipeOffset.value = { x: 0, y: dy * (valid ?
|
|
70
|
+
swipeOffset.value = { x: 0, y: dy * (valid ? dampValid() : dampInvalid()) };
|
|
60
71
|
}
|
|
61
72
|
e.preventDefault();
|
|
62
73
|
}
|
|
63
74
|
function onTouchEnd() {
|
|
64
75
|
if (touchIgnored) return;
|
|
76
|
+
if (toValue(options.disabled)) {
|
|
77
|
+
resetSwipe();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
65
80
|
if (touchLockedAxis === "x" && Math.abs(swipeOffset.value.x) > SWIPE_TRIGGER) {
|
|
66
81
|
if (swipeOffset.value.x < 0) options.onSwipeLeft?.();
|
|
67
82
|
else options.onSwipeRight?.();
|
|
@@ -85,6 +100,7 @@ export function useSwipeGesture(options) {
|
|
|
85
100
|
wheelTimer = null;
|
|
86
101
|
}
|
|
87
102
|
function onWheel(e) {
|
|
103
|
+
if (options.pointer === "touch") return;
|
|
88
104
|
if (toValue(options.disabled)) return;
|
|
89
105
|
if (e.ctrlKey) return;
|
|
90
106
|
wheelAccumX += e.deltaX;
|
|
@@ -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
|
|
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.
|
|
3
|
+
"version": "2.88.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.
|
|
177
|
-
"@abraca/dabra": "^2.
|
|
178
|
-
"@abraca/plugin": "^2.
|
|
176
|
+
"@abraca/convert": "^2.87.0",
|
|
177
|
+
"@abraca/dabra": "^2.87.0",
|
|
178
|
+
"@abraca/plugin": "^2.87.0",
|
|
179
179
|
"@codemirror/autocomplete": "^6.18.0",
|
|
180
180
|
"@codemirror/commands": "^6.7.0",
|
|
181
181
|
"@codemirror/lang-css": "^6.3.1",
|