@abraca/nuxt 2.43.0 → 2.47.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 +12 -0
- package/dist/runtime/components/ADocRenderer.vue +20 -19
- package/dist/runtime/components/ADocRenderer.vue.d.ts +12 -0
- package/dist/runtime/components/ADocumentTree.d.vue.ts +10 -0
- package/dist/runtime/components/ADocumentTree.vue +33 -8
- package/dist/runtime/components/ADocumentTree.vue.d.ts +10 -0
- package/dist/runtime/components/AEditor.d.vue.ts +2 -2
- package/dist/runtime/components/AEditor.vue +12 -5
- package/dist/runtime/components/AEditor.vue.d.ts +2 -2
- package/dist/runtime/components/AEmailVerifyConfirmModal.d.vue.ts +1 -1
- package/dist/runtime/components/AEmailVerifyConfirmModal.vue.d.ts +1 -1
- package/dist/runtime/components/ANodePanel.vue +11 -3
- package/dist/runtime/components/ASetPasswordCard.d.vue.ts +1 -1
- package/dist/runtime/components/ASetPasswordCard.vue.d.ts +1 -1
- package/dist/runtime/components/renderers/AProseRenderer.d.vue.ts +2 -2
- package/dist/runtime/components/renderers/AProseRenderer.vue.d.ts +2 -2
- package/dist/runtime/composables/useConnectionStatus.d.ts +1 -1
- package/dist/runtime/composables/useDocTree.d.ts +8 -1
- package/dist/runtime/composables/useDocTree.js +24 -4
- package/dist/runtime/composables/useEditor.js +8 -51
- package/dist/runtime/composables/useSpaceConnections.d.ts +75 -18
- package/dist/runtime/composables/useSpaceConnections.js +244 -61
- package/dist/runtime/middleware/abracadabra-auth.d.ts +1 -1
- package/dist/runtime/plugin-abracadabra.client.d.ts +1 -1
- package/dist/runtime/plugin-abracadabra.client.js +19 -0
- package/dist/runtime/plugin-abracadabra.server.d.ts +1 -1
- package/dist/runtime/plugin-shared-globals.client.d.ts +1 -1
- package/dist/runtime/utils/enforceDocumentShape.d.ts +30 -0
- package/dist/runtime/utils/enforceDocumentShape.js +228 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -13,6 +13,18 @@ type __VLS_Props = {
|
|
|
13
13
|
editorClass?: string;
|
|
14
14
|
/** CSS class applied to structured renderers (kanban, table, etc.) */
|
|
15
15
|
rendererClass?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Override the doc-tree lookup with an explicit entry (`type`/`label`/`meta`).
|
|
18
|
+
* Use this when rendering a doc that is NOT in the active provider's root
|
|
19
|
+
* doc-tree — e.g. an admin browsing another space's documents, where the
|
|
20
|
+
* type lives in that space's own tree. When unset, falls back to the root
|
|
21
|
+
* tree as before, so this is purely additive.
|
|
22
|
+
*/
|
|
23
|
+
entry?: {
|
|
24
|
+
type?: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
meta?: Record<string, unknown>;
|
|
27
|
+
} | null;
|
|
16
28
|
};
|
|
17
29
|
declare var __VLS_1: {}, __VLS_23: {
|
|
18
30
|
error: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { computed, watch, shallowRef } from "vue";
|
|
3
3
|
import { useFetch } from "#imports";
|
|
4
4
|
import { useAbracadabra } from "../composables/useAbracadabra";
|
|
5
|
-
import {
|
|
5
|
+
import { useSpaceConnections } from "../composables/useSpaceConnections";
|
|
6
6
|
import { usePluginRegistry } from "../composables/usePluginRegistry";
|
|
7
7
|
import { resolveDocType } from "../utils/docTypes";
|
|
8
8
|
const props = defineProps({
|
|
@@ -10,32 +10,33 @@ const props = defineProps({
|
|
|
10
10
|
editable: { type: Boolean, required: false, default: true },
|
|
11
11
|
breadcrumbMenu: { type: Boolean, required: false, default: true },
|
|
12
12
|
editorClass: { type: String, required: false },
|
|
13
|
-
rendererClass: { type: String, required: false }
|
|
13
|
+
rendererClass: { type: String, required: false },
|
|
14
|
+
entry: { type: [Object, null], required: false }
|
|
14
15
|
});
|
|
15
16
|
const abra = useAbracadabra();
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const docTitle = computed(() =>
|
|
19
|
-
const docType = computed(() =>
|
|
20
|
-
const docMeta = computed(() =>
|
|
17
|
+
const { resolveEntry, findDocSpaceId, getProviderForDoc, connectSpace, connections } = useSpaceConnections();
|
|
18
|
+
const resolvedEntry = computed(() => resolveEntry(props.docId));
|
|
19
|
+
const docTitle = computed(() => props.entry?.label ?? resolvedEntry.value?.label ?? "Untitled");
|
|
20
|
+
const docType = computed(() => props.entry?.type ?? resolvedEntry.value?.type ?? "doc");
|
|
21
|
+
const docMeta = computed(() => props.entry?.meta ?? resolvedEntry.value?.meta ?? {});
|
|
21
22
|
const registry = usePluginRegistry();
|
|
22
23
|
const docTypeDef = computed(() => resolveDocType(docType.value, registry));
|
|
23
24
|
const childProvider = shallowRef(null);
|
|
24
25
|
async function loadChildProvider(id) {
|
|
25
26
|
childProvider.value = null;
|
|
26
|
-
if (!
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
await
|
|
31
|
-
|
|
32
|
-
prov.off("synced", done);
|
|
33
|
-
resolve();
|
|
34
|
-
};
|
|
35
|
-
prov.on("synced", done);
|
|
36
|
-
setTimeout(resolve, 6e3);
|
|
37
|
-
});
|
|
27
|
+
if (!id) return;
|
|
28
|
+
const spaceId = findDocSpaceId(id);
|
|
29
|
+
if (spaceId && !connections.get(spaceId)) {
|
|
30
|
+
try {
|
|
31
|
+
await connectSpace(spaceId);
|
|
32
|
+
} catch {
|
|
38
33
|
}
|
|
34
|
+
}
|
|
35
|
+
const provider = getProviderForDoc(id);
|
|
36
|
+
if (!provider) return;
|
|
37
|
+
try {
|
|
38
|
+
const prov = await provider.loadChild(id);
|
|
39
|
+
if (prov?.ready) await prov.ready;
|
|
39
40
|
childProvider.value = prov;
|
|
40
41
|
} catch (e) {
|
|
41
42
|
console.error("[ADocRenderer] Failed to load child provider:", e);
|
|
@@ -13,6 +13,18 @@ type __VLS_Props = {
|
|
|
13
13
|
editorClass?: string;
|
|
14
14
|
/** CSS class applied to structured renderers (kanban, table, etc.) */
|
|
15
15
|
rendererClass?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Override the doc-tree lookup with an explicit entry (`type`/`label`/`meta`).
|
|
18
|
+
* Use this when rendering a doc that is NOT in the active provider's root
|
|
19
|
+
* doc-tree — e.g. an admin browsing another space's documents, where the
|
|
20
|
+
* type lives in that space's own tree. When unset, falls back to the root
|
|
21
|
+
* tree as before, so this is purely additive.
|
|
22
|
+
*/
|
|
23
|
+
entry?: {
|
|
24
|
+
type?: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
meta?: Record<string, unknown>;
|
|
27
|
+
} | null;
|
|
16
28
|
};
|
|
17
29
|
declare var __VLS_1: {}, __VLS_23: {
|
|
18
30
|
error: string;
|
|
@@ -20,6 +20,15 @@ type __VLS_Props = {
|
|
|
20
20
|
* before, so this is purely additive.
|
|
21
21
|
*/
|
|
22
22
|
sourceDoc?: Y.Doc | null;
|
|
23
|
+
/**
|
|
24
|
+
* Bind the tree to a space by id (= its root doc id). The owning space is
|
|
25
|
+
* connected on demand via `useSpaceConnections`, and the tree reads/writes
|
|
26
|
+
* its `doc-tree` natively — no need to hand in a `sourceDoc`. Precedence:
|
|
27
|
+
* explicit `sourceDoc` > `spaceId` connection doc > active entry doc.
|
|
28
|
+
* When the space is the active one this is a no-op (resolves to the
|
|
29
|
+
* singleton). Purely additive.
|
|
30
|
+
*/
|
|
31
|
+
spaceId?: string | null;
|
|
23
32
|
};
|
|
24
33
|
declare var __VLS_39: {};
|
|
25
34
|
type __VLS_Slots = {} & {
|
|
@@ -34,6 +43,7 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
|
34
43
|
onCreate?: ((parentId: string | null) => any) | undefined;
|
|
35
44
|
onNavigate?: ((id: string) => any) | undefined;
|
|
36
45
|
}>, {
|
|
46
|
+
spaceId: string | null;
|
|
37
47
|
editable: boolean;
|
|
38
48
|
rootId: string | null;
|
|
39
49
|
sourceDoc: Y.Doc | null;
|
|
@@ -6,13 +6,15 @@ import { resolveDocType, getAvailableDocTypes } from "../utils/docTypes";
|
|
|
6
6
|
import { avatarBorderStyle } from "../utils/avatarStyle";
|
|
7
7
|
import { DOC_DRAG_MIME, isDocDrag, parseDocDragPayload, isDescendantInMap } from "../utils/docDragDrop";
|
|
8
8
|
import { useDocDragBus } from "../composables/useDocDragBus";
|
|
9
|
+
import { useSpaceConnections } from "../composables/useSpaceConnections";
|
|
9
10
|
const dragBus = useDocDragBus();
|
|
10
11
|
const props = defineProps({
|
|
11
12
|
collapsed: { type: Boolean, required: false },
|
|
12
13
|
editable: { type: Boolean, required: false, default: true },
|
|
13
14
|
selectedId: { type: [String, null], required: false },
|
|
14
15
|
rootId: { type: [String, null], required: false, default: null },
|
|
15
|
-
sourceDoc: { type: null, required: false, default: null }
|
|
16
|
+
sourceDoc: { type: null, required: false, default: null },
|
|
17
|
+
spaceId: { type: [String, null], required: false, default: null }
|
|
16
18
|
});
|
|
17
19
|
const emit = defineEmits(["navigate", "create"]);
|
|
18
20
|
const { doc, spaceDocId, isReady, provider, client, userName } = useAbracadabra();
|
|
@@ -31,9 +33,26 @@ function leaveRoom() {
|
|
|
31
33
|
const toast = useToast();
|
|
32
34
|
const appConfig = useAppConfig();
|
|
33
35
|
const presenceNeutral = computed(() => appConfig.ui?.colors?.neutral ?? "zinc");
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const { connections, connectSpace } = useSpaceConnections();
|
|
37
|
+
const spaceConnDoc = shallowRef(null);
|
|
38
|
+
watch(() => props.spaceId, (sid) => {
|
|
39
|
+
spaceConnDoc.value = null;
|
|
40
|
+
if (!sid) return;
|
|
41
|
+
const existing = connections.get(sid);
|
|
42
|
+
if (existing) {
|
|
43
|
+
spaceConnDoc.value = existing.doc;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
void connectSpace(sid).then((conn) => {
|
|
47
|
+
if (props.spaceId === sid) spaceConnDoc.value = conn.doc;
|
|
48
|
+
}).catch(() => {
|
|
49
|
+
});
|
|
50
|
+
}, { immediate: true });
|
|
51
|
+
const treeSourceDoc = shallowRef(
|
|
52
|
+
props.sourceDoc ?? spaceConnDoc.value ?? doc.value
|
|
53
|
+
);
|
|
54
|
+
watch([() => props.sourceDoc, spaceConnDoc, doc], ([src, sconn, d]) => {
|
|
55
|
+
treeSourceDoc.value = src ?? sconn ?? d;
|
|
37
56
|
}, { immediate: true });
|
|
38
57
|
const treeMap = useSyncedMap(treeSourceDoc, "doc-tree");
|
|
39
58
|
const structureHash = computed(() => {
|
|
@@ -59,11 +78,17 @@ const treeItems = computed(() => {
|
|
|
59
78
|
const raw = toRaw(treeMap.data);
|
|
60
79
|
const ROOT = "@root";
|
|
61
80
|
const scopeRoot = props.rootId ?? null;
|
|
62
|
-
const
|
|
63
|
-
const
|
|
81
|
+
const boundSpaceId = props.spaceId && treeSourceDoc.value && treeSourceDoc.value !== doc.value ? props.spaceId : null;
|
|
82
|
+
const usingExplicitSource = props.sourceDoc != null;
|
|
83
|
+
const isTopLevel = (p) => {
|
|
84
|
+
if (scopeRoot != null) return p === scopeRoot;
|
|
85
|
+
if (boundSpaceId) return p == null || p === boundSpaceId;
|
|
86
|
+
if (usingExplicitSource) return p == null;
|
|
87
|
+
return p == null || p === sid;
|
|
88
|
+
};
|
|
64
89
|
const childrenByParent = /* @__PURE__ */ new Map();
|
|
65
90
|
for (const id in raw) {
|
|
66
|
-
if (id === sid || id === scopeRoot) continue;
|
|
91
|
+
if (id === sid || id === scopeRoot || id === boundSpaceId) continue;
|
|
67
92
|
const v = raw[id];
|
|
68
93
|
const rawPid = v.parentId ?? null;
|
|
69
94
|
const pid = isTopLevel(rawPid) ? ROOT : rawPid;
|
|
@@ -1198,7 +1223,7 @@ defineExpose({
|
|
|
1198
1223
|
<template v-if="isReady">
|
|
1199
1224
|
<div
|
|
1200
1225
|
ref="scrollParent"
|
|
1201
|
-
class="flex-1 min-h-0 overflow-y-auto px-1"
|
|
1226
|
+
class="flex-1 min-h-0 overflow-y-auto px-1 pb-4"
|
|
1202
1227
|
:class="{ 'is-dragging': dragId }"
|
|
1203
1228
|
@dragover.prevent
|
|
1204
1229
|
@dragleave="onListDragLeave"
|
|
@@ -20,6 +20,15 @@ type __VLS_Props = {
|
|
|
20
20
|
* before, so this is purely additive.
|
|
21
21
|
*/
|
|
22
22
|
sourceDoc?: Y.Doc | null;
|
|
23
|
+
/**
|
|
24
|
+
* Bind the tree to a space by id (= its root doc id). The owning space is
|
|
25
|
+
* connected on demand via `useSpaceConnections`, and the tree reads/writes
|
|
26
|
+
* its `doc-tree` natively — no need to hand in a `sourceDoc`. Precedence:
|
|
27
|
+
* explicit `sourceDoc` > `spaceId` connection doc > active entry doc.
|
|
28
|
+
* When the space is the active one this is a no-op (resolves to the
|
|
29
|
+
* singleton). Purely additive.
|
|
30
|
+
*/
|
|
31
|
+
spaceId?: string | null;
|
|
23
32
|
};
|
|
24
33
|
declare var __VLS_39: {};
|
|
25
34
|
type __VLS_Slots = {} & {
|
|
@@ -34,6 +43,7 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
|
34
43
|
onCreate?: ((parentId: string | null) => any) | undefined;
|
|
35
44
|
onNavigate?: ((id: string) => any) | undefined;
|
|
36
45
|
}>, {
|
|
46
|
+
spaceId: string | null;
|
|
37
47
|
editable: boolean;
|
|
38
48
|
rootId: string | null;
|
|
39
49
|
sourceDoc: Y.Doc | null;
|
|
@@ -94,16 +94,16 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
|
94
94
|
editor: import("vue").ComputedRef<any>;
|
|
95
95
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
96
96
|
rename: (label: string) => any;
|
|
97
|
+
ready: () => any;
|
|
97
98
|
"update:modelValue": (value: any) => any;
|
|
98
99
|
updateMeta: (patch: Partial<DocPageMeta>) => any;
|
|
99
100
|
update: (content: any) => any;
|
|
100
|
-
ready: () => any;
|
|
101
101
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
102
102
|
onRename?: ((label: string) => any) | undefined;
|
|
103
|
+
onReady?: (() => any) | undefined;
|
|
103
104
|
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
104
105
|
onUpdateMeta?: ((patch: Partial<DocPageMeta>) => any) | undefined;
|
|
105
106
|
onUpdate?: ((content: any) => any) | undefined;
|
|
106
|
-
onReady?: (() => any) | undefined;
|
|
107
107
|
}>, {
|
|
108
108
|
contentType: "json" | "html" | "markdown";
|
|
109
109
|
editable: boolean;
|
|
@@ -11,6 +11,7 @@ import { useDocTree } from "../composables/useDocTree";
|
|
|
11
11
|
import { useDocBreadcrumb } from "../composables/useDocBreadcrumb";
|
|
12
12
|
import { useDocSlugs } from "../composables/useDocSlugs";
|
|
13
13
|
import { useChildTree } from "../composables/useChildTree";
|
|
14
|
+
import { useSpaceConnections } from "../composables/useSpaceConnections";
|
|
14
15
|
import { useFavorites } from "../composables/useFavorites";
|
|
15
16
|
import { useWindowManager } from "../composables/useWindowManager";
|
|
16
17
|
import { useDocDragBus } from "../composables/useDocDragBus";
|
|
@@ -51,9 +52,15 @@ const viewMode = ref("rich");
|
|
|
51
52
|
const emit = defineEmits(["ready", "update", "rename", "updateMeta"]);
|
|
52
53
|
const model = defineModel({ type: null });
|
|
53
54
|
const { doc, provider, registry } = useNuxtApp().$abracadabra;
|
|
54
|
-
const
|
|
55
|
+
const { connections, getProviderForDoc, getDocForDoc } = useSpaceConnections();
|
|
56
|
+
const ownerProvider = computed(() => getProviderForDoc(props.docId) ?? provider.value);
|
|
57
|
+
const ownerDoc = shallowRef(getDocForDoc(props.docId) ?? doc.value);
|
|
58
|
+
watch(() => [doc.value, connections.size], () => {
|
|
59
|
+
ownerDoc.value = getDocForDoc(props.docId) ?? doc.value;
|
|
60
|
+
}, { immediate: true });
|
|
61
|
+
const _treeMap = useSyncedMap(ownerDoc, "doc-tree");
|
|
55
62
|
const childProvider = shallowRef(null);
|
|
56
|
-
watch(
|
|
63
|
+
watch(ownerProvider, async (prov) => {
|
|
57
64
|
if (!prov || !props.docId) return;
|
|
58
65
|
try {
|
|
59
66
|
childProvider.value = await prov.loadChild(props.docId);
|
|
@@ -63,10 +70,10 @@ watch(provider, async (prov) => {
|
|
|
63
70
|
}
|
|
64
71
|
}, { immediate: true });
|
|
65
72
|
onBeforeUnmount(() => {
|
|
66
|
-
|
|
73
|
+
ownerProvider.value?.unpinChild?.(props.docId);
|
|
67
74
|
});
|
|
68
75
|
const docSuggestEnabled = (useRuntimeConfig().public?.abracadabra?.docPicker ?? "inline") === "inline";
|
|
69
|
-
const _suggestTree = useChildTree(
|
|
76
|
+
const _suggestTree = useChildTree(ownerDoc, props.docId);
|
|
70
77
|
const docSuggestExt = DocSuggest.configure({
|
|
71
78
|
search: makeDocSearch(_suggestTree, props.docId),
|
|
72
79
|
onCommit: (item, mode, range, query) => {
|
|
@@ -93,7 +100,7 @@ const editorRef = ref(null);
|
|
|
93
100
|
const tiptapEditor = computed(() => editorRef.value?.editor ?? null);
|
|
94
101
|
defineExpose({ editor: tiptapEditor });
|
|
95
102
|
const { bubbleItems: toolbarItems } = useEditorToolbar({ docId: props.docId });
|
|
96
|
-
const docTree = useDocTree();
|
|
103
|
+
const docTree = useDocTree(props.docId);
|
|
97
104
|
const resolvedMetaSchema = computed(() => {
|
|
98
105
|
if (props.metaSchema) return props.metaSchema;
|
|
99
106
|
const geoType = props.docMeta?.geoType;
|
|
@@ -94,16 +94,16 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
|
94
94
|
editor: import("vue").ComputedRef<any>;
|
|
95
95
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
96
96
|
rename: (label: string) => any;
|
|
97
|
+
ready: () => any;
|
|
97
98
|
"update:modelValue": (value: any) => any;
|
|
98
99
|
updateMeta: (patch: Partial<DocPageMeta>) => any;
|
|
99
100
|
update: (content: any) => any;
|
|
100
|
-
ready: () => any;
|
|
101
101
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
102
102
|
onRename?: ((label: string) => any) | undefined;
|
|
103
|
+
onReady?: (() => any) | undefined;
|
|
103
104
|
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
104
105
|
onUpdateMeta?: ((patch: Partial<DocPageMeta>) => any) | undefined;
|
|
105
106
|
onUpdate?: ((content: any) => any) | undefined;
|
|
106
|
-
onReady?: (() => any) | undefined;
|
|
107
107
|
}>, {
|
|
108
108
|
contentType: "json" | "html" | "markdown";
|
|
109
109
|
editable: boolean;
|
|
@@ -22,8 +22,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
22
22
|
}>, {
|
|
23
23
|
subtitle: string;
|
|
24
24
|
title: string;
|
|
25
|
-
loading: boolean;
|
|
26
25
|
success: boolean;
|
|
26
|
+
loading: boolean;
|
|
27
27
|
initialToken: string;
|
|
28
28
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
29
29
|
declare const _default: typeof __VLS_export;
|
|
@@ -22,8 +22,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
22
22
|
}>, {
|
|
23
23
|
subtitle: string;
|
|
24
24
|
title: string;
|
|
25
|
-
loading: boolean;
|
|
26
25
|
success: boolean;
|
|
26
|
+
loading: boolean;
|
|
27
27
|
initialToken: string;
|
|
28
28
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
29
29
|
declare const _default: typeof __VLS_export;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { ref, computed, watch, defineAsyncComponent } from "vue";
|
|
2
|
+
import { ref, shallowRef, computed, watch, defineAsyncComponent } from "vue";
|
|
3
3
|
import { useAbracadabra } from "../composables/useAbracadabra";
|
|
4
4
|
import { useSyncedMap } from "../composables/useYDoc";
|
|
5
5
|
import { navigateTo, useRuntimeConfig } from "#imports";
|
|
6
6
|
import { useChildTree } from "../composables/useChildTree";
|
|
7
|
+
import { useSpaceConnections } from "../composables/useSpaceConnections";
|
|
7
8
|
import { useAbraLocale } from "../composables/useAbraLocale";
|
|
8
9
|
import { useDocSlugs } from "../composables/useDocSlugs";
|
|
9
10
|
import { useResizableWidth } from "../composables/useResizableWidth";
|
|
@@ -35,11 +36,18 @@ const open = computed({
|
|
|
35
36
|
});
|
|
36
37
|
const locale = computed(() => useAbraLocale("nodePanel", props.labels));
|
|
37
38
|
const { doc: rootDoc, registry } = useAbracadabra();
|
|
39
|
+
const { connections, getDocForDoc } = useSpaceConnections();
|
|
40
|
+
const ownerDoc = shallowRef(
|
|
41
|
+
props.nodeId ? getDocForDoc(props.nodeId) ?? rootDoc.value : rootDoc.value
|
|
42
|
+
);
|
|
43
|
+
watch(() => [props.nodeId, rootDoc.value, connections.size], () => {
|
|
44
|
+
ownerDoc.value = props.nodeId ? getDocForDoc(props.nodeId) ?? rootDoc.value : rootDoc.value;
|
|
45
|
+
}, { immediate: true });
|
|
38
46
|
const tree = computed(() => {
|
|
39
47
|
if (!props.nodeId) return null;
|
|
40
|
-
return useChildTree(
|
|
48
|
+
return useChildTree(ownerDoc, props.nodeId);
|
|
41
49
|
});
|
|
42
|
-
const treeMap = useSyncedMap(
|
|
50
|
+
const treeMap = useSyncedMap(ownerDoc, "doc-tree");
|
|
43
51
|
const entry = computed(() => {
|
|
44
52
|
if (!props.nodeId) return null;
|
|
45
53
|
return treeMap.data[props.nodeId] ?? null;
|
|
@@ -18,9 +18,9 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
18
18
|
}>, {
|
|
19
19
|
subtitle: string;
|
|
20
20
|
title: string;
|
|
21
|
+
success: boolean;
|
|
21
22
|
minLength: number;
|
|
22
23
|
loading: boolean;
|
|
23
|
-
success: boolean;
|
|
24
24
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
25
25
|
declare const _default: typeof __VLS_export;
|
|
26
26
|
export default _default;
|
|
@@ -18,9 +18,9 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
18
18
|
}>, {
|
|
19
19
|
subtitle: string;
|
|
20
20
|
title: string;
|
|
21
|
+
success: boolean;
|
|
21
22
|
minLength: number;
|
|
22
23
|
loading: boolean;
|
|
23
|
-
success: boolean;
|
|
24
24
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
25
25
|
declare const _default: typeof __VLS_export;
|
|
26
26
|
export default _default;
|
|
@@ -10,14 +10,14 @@ type __VLS_Props = {
|
|
|
10
10
|
};
|
|
11
11
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, Record<PropertyKey, unknown>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
12
12
|
rename: (label: string) => any;
|
|
13
|
+
ready: () => any;
|
|
13
14
|
updateMeta: (patch: Partial<DocPageMeta>) => any;
|
|
14
15
|
update: (content: any) => any;
|
|
15
|
-
ready: () => any;
|
|
16
16
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
17
17
|
onRename?: ((label: string) => any) | undefined;
|
|
18
|
+
onReady?: (() => any) | undefined;
|
|
18
19
|
onUpdateMeta?: ((patch: Partial<DocPageMeta>) => any) | undefined;
|
|
19
20
|
onUpdate?: ((content: any) => any) | undefined;
|
|
20
|
-
onReady?: (() => any) | undefined;
|
|
21
21
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
22
22
|
declare const _default: typeof __VLS_export;
|
|
23
23
|
export default _default;
|
|
@@ -10,14 +10,14 @@ type __VLS_Props = {
|
|
|
10
10
|
};
|
|
11
11
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, Record<PropertyKey, unknown>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
12
12
|
rename: (label: string) => any;
|
|
13
|
+
ready: () => any;
|
|
13
14
|
updateMeta: (patch: Partial<DocPageMeta>) => any;
|
|
14
15
|
update: (content: any) => any;
|
|
15
|
-
ready: () => any;
|
|
16
16
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
17
17
|
onRename?: ((label: string) => any) | undefined;
|
|
18
|
+
onReady?: (() => any) | undefined;
|
|
18
19
|
onUpdateMeta?: ((patch: Partial<DocPageMeta>) => any) | undefined;
|
|
19
20
|
onUpdate?: ((content: any) => any) | undefined;
|
|
20
|
-
onReady?: (() => any) | undefined;
|
|
21
21
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
22
22
|
declare const _default: typeof __VLS_export;
|
|
23
23
|
export default _default;
|
|
@@ -15,7 +15,7 @@ type ConnectionStatusValue = 'disconnected' | 'connecting' | 'connected' | 'offl
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function useConnectionStatus(status?: MaybeRef<ConnectionStatusValue | string | undefined>, synced?: MaybeRef<boolean | undefined>): {
|
|
17
17
|
label: import("vue").ComputedRef<string>;
|
|
18
|
-
color: import("vue").ComputedRef<"error" | "
|
|
18
|
+
color: import("vue").ComputedRef<"error" | "success" | "warning">;
|
|
19
19
|
icon: import("vue").ComputedRef<"i-lucide-cloud-off" | "i-lucide-cloud-check" | "i-lucide-cloud">;
|
|
20
20
|
};
|
|
21
21
|
export {};
|
|
@@ -32,4 +32,11 @@ export interface DocTreeReturn {
|
|
|
32
32
|
/** Raw useSyncedMap return for advanced usage */
|
|
33
33
|
raw: ReturnType<typeof useSyncedMap>;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* @param docId When provided, the tree is read from the space that OWNS this
|
|
37
|
+
* doc (its label/type/meta + children live in that space's root `doc-tree`),
|
|
38
|
+
* not the active root — so the editor/slideover mutate the correct tree for a
|
|
39
|
+
* cross-space doc. Omitted (default) keeps the active-root behaviour, so every
|
|
40
|
+
* existing caller is unaffected.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useDocTree(docId?: string | null): DocTreeReturn;
|
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
import { computed } from "vue";
|
|
1
|
+
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
5
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
6
|
+
import { useSpaceConnections } from "./useSpaceConnections.js";
|
|
6
7
|
import { useSyncedMap } from "./useYDoc.js";
|
|
7
|
-
export function useDocTree() {
|
|
8
|
+
export function useDocTree(docId) {
|
|
8
9
|
const abra = useAbracadabra();
|
|
10
|
+
const { connections, getDocForDoc, findDocSpaceId } = useSpaceConnections();
|
|
9
11
|
const config = useRuntimeConfig();
|
|
10
12
|
const docBasePath = config.public?.abracadabra?.docBasePath ?? "/doc";
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
+
const boundDoc = shallowRef(
|
|
14
|
+
docId ? getDocForDoc(docId) ?? abra.doc.value : abra.doc.value
|
|
15
|
+
);
|
|
16
|
+
if (docId) {
|
|
17
|
+
watch(
|
|
18
|
+
() => [abra.doc.value, abra.spaceDocId.value, connections.size],
|
|
19
|
+
() => {
|
|
20
|
+
boundDoc.value = getDocForDoc(docId) ?? abra.doc.value;
|
|
21
|
+
},
|
|
22
|
+
{ immediate: true }
|
|
23
|
+
);
|
|
24
|
+
} else {
|
|
25
|
+
watch(abra.doc, (d) => {
|
|
26
|
+
boundDoc.value = d;
|
|
27
|
+
}, { immediate: true });
|
|
28
|
+
}
|
|
29
|
+
const treeMap = useSyncedMap(boundDoc, "doc-tree");
|
|
30
|
+
const spaceDocId = computed(
|
|
31
|
+
() => docId ? findDocSpaceId(docId) ?? abra.spaceDocId.value : abra.spaceDocId.value
|
|
32
|
+
);
|
|
13
33
|
const entries = computed(
|
|
14
34
|
() => Object.entries(treeMap.data).filter(([id]) => id !== spaceDocId.value).map(([id, entry]) => ({ id, ...entry }))
|
|
15
35
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ref, shallowRef, watch, onUnmounted } from "vue";
|
|
2
2
|
import { Extension } from "@tiptap/core";
|
|
3
|
-
import {
|
|
3
|
+
import { enforceDocumentShape } from "../utils/enforceDocumentShape.js";
|
|
4
4
|
import { useNuxtApp } from "#imports";
|
|
5
5
|
export function useEditor(options) {
|
|
6
6
|
const { childProvider, extraExtensions = [] } = options;
|
|
@@ -90,56 +90,14 @@ export function useEditor(options) {
|
|
|
90
90
|
];
|
|
91
91
|
const ydoc = prov.document;
|
|
92
92
|
const fragment = ydoc?.getXmlFragment?.("default");
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
const indices = [];
|
|
97
|
-
children.forEach((child, idx) => {
|
|
98
|
-
if (child.nodeName === nodeName) indices.push(idx);
|
|
99
|
-
});
|
|
100
|
-
if (indices.length <= 1) return;
|
|
101
|
-
const toRemove = /* @__PURE__ */ new Set();
|
|
102
|
-
for (let i = 1; i < indices.length; i++) {
|
|
103
|
-
const hi = indices[i];
|
|
104
|
-
toRemove.add(hi);
|
|
105
|
-
const afterIdx = hi + 1;
|
|
106
|
-
const beforeIdx = hi - 1;
|
|
107
|
-
if (afterIdx < children.length && !toRemove.has(afterIdx) && children[afterIdx]?.nodeName === "paragraph" && children[afterIdx].length === 0) {
|
|
108
|
-
toRemove.add(afterIdx);
|
|
109
|
-
} else if (beforeIdx >= 0 && !toRemove.has(beforeIdx) && children[beforeIdx]?.nodeName === "paragraph" && children[beforeIdx].length === 0) {
|
|
110
|
-
toRemove.add(beforeIdx);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const sortedDesc = [...toRemove].sort((a, b) => b - a);
|
|
114
|
-
ydoc.transact(() => {
|
|
115
|
-
for (const idx of sortedDesc) fragment.delete(idx, 1);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
const dedupeHeaders = () => dedupeByName("documentHeader");
|
|
119
|
-
const dedupeDocumentMeta = () => dedupeByName("documentMeta");
|
|
120
|
-
function ensureDocumentMeta() {
|
|
121
|
-
if (!fragment) return;
|
|
122
|
-
const children = fragment.toArray();
|
|
123
|
-
if (children.some((c) => c.nodeName === "documentMeta")) return;
|
|
124
|
-
const headerIdx = children.findIndex((c) => c.nodeName === "documentHeader");
|
|
125
|
-
const insertIdx = headerIdx >= 0 ? headerIdx + 1 : 0;
|
|
126
|
-
const metaEl = new XmlElement("documentMeta");
|
|
127
|
-
ydoc.transact(() => {
|
|
128
|
-
fragment.insert(insertIdx, [metaEl]);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
93
|
+
const healShape = () => {
|
|
94
|
+
if (fragment && ydoc) enforceDocumentShape(fragment, ydoc);
|
|
95
|
+
};
|
|
131
96
|
if (fragment) {
|
|
132
|
-
fragment.observe(
|
|
133
|
-
|
|
134
|
-
dedupeHeaders();
|
|
135
|
-
dedupeDocumentMeta();
|
|
136
|
-
ensureDocumentMeta();
|
|
97
|
+
fragment.observe(healShape);
|
|
98
|
+
healShape();
|
|
137
99
|
}
|
|
138
|
-
const onProviderSynced = () =>
|
|
139
|
-
dedupeHeaders();
|
|
140
|
-
dedupeDocumentMeta();
|
|
141
|
-
ensureDocumentMeta();
|
|
142
|
-
};
|
|
100
|
+
const onProviderSynced = () => healShape();
|
|
143
101
|
prov.on?.("synced", onProviderSynced);
|
|
144
102
|
if (prov.isSynced) Promise.resolve().then(onProviderSynced);
|
|
145
103
|
ready.value = true;
|
|
@@ -224,8 +182,7 @@ export function useEditor(options) {
|
|
|
224
182
|
fadeOutTimeouts.forEach((t) => clearTimeout(t));
|
|
225
183
|
fadeOutTimeouts.clear();
|
|
226
184
|
if (fragment) {
|
|
227
|
-
fragment.unobserve(
|
|
228
|
-
fragment.unobserve(dedupeDocumentMeta);
|
|
185
|
+
fragment.unobserve(healShape);
|
|
229
186
|
}
|
|
230
187
|
if (cursorBroadcastTimer) {
|
|
231
188
|
clearTimeout(cursorBroadcastTimer);
|