@abraca/nuxt 2.36.0 → 2.38.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.d.mts +6 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/ADocPickModal.vue +1 -1
- package/dist/runtime/components/ADocSubPageList.d.vue.ts +46 -0
- package/dist/runtime/components/ADocSubPageList.vue +1006 -0
- package/dist/runtime/components/ADocSubPageList.vue.d.ts +46 -0
- package/dist/runtime/components/ADocumentTree.vue +3 -2
- package/dist/runtime/components/AEditor.d.vue.ts +9 -0
- package/dist/runtime/components/AEditor.vue +14 -2
- package/dist/runtime/components/AEditor.vue.d.ts +9 -0
- package/dist/runtime/components/AIconPicker.vue +27 -180
- package/dist/runtime/components/ANodePanel.d.vue.ts +8 -5
- package/dist/runtime/components/ANodePanel.vue +1 -1
- package/dist/runtime/components/ANodePanel.vue.d.ts +8 -5
- package/dist/runtime/components/AWindowLayer.vue +4 -2
- package/dist/runtime/components/docs/ADocsSearch.d.vue.ts +2 -2
- package/dist/runtime/components/docs/ADocsSearch.vue.d.ts +2 -2
- package/dist/runtime/components/editor/ADocSuggestMenu.vue +1 -1
- package/dist/runtime/components/editor/ALocationPickerPopover.vue +31 -16
- package/dist/runtime/components/renderers/ACalendarRenderer.d.vue.ts +1 -0
- package/dist/runtime/components/renderers/ACalendarRenderer.vue +309 -68
- package/dist/runtime/components/renderers/ACalendarRenderer.vue.d.ts +1 -0
- package/dist/runtime/components/renderers/AChecklistRenderer.vue +259 -40
- package/dist/runtime/components/renderers/ADashboardRenderer.vue +493 -89
- package/dist/runtime/components/renderers/AGraphRenderer.d.vue.ts +2 -0
- package/dist/runtime/components/renderers/AGraphRenderer.vue +2113 -576
- package/dist/runtime/components/renderers/AGraphRenderer.vue.d.ts +2 -0
- package/dist/runtime/components/renderers/AKanbanRenderer.vue +460 -86
- package/dist/runtime/components/renderers/AMapRenderer.d.vue.ts +7 -1
- package/dist/runtime/components/renderers/AMapRenderer.vue +999 -166
- package/dist/runtime/components/renderers/AMapRenderer.vue.d.ts +7 -1
- package/dist/runtime/components/renderers/AOutlineRenderer.d.vue.ts +2 -0
- package/dist/runtime/components/renderers/AOutlineRenderer.vue +285 -81
- package/dist/runtime/components/renderers/AOutlineRenderer.vue.d.ts +2 -0
- package/dist/runtime/components/renderers/AOverviewRenderer.vue +3 -2
- package/dist/runtime/components/renderers/ASheetsRenderer.client.vue +255 -87
- package/dist/runtime/components/renderers/ATimelineRenderer.d.vue.ts +1 -0
- package/dist/runtime/components/renderers/ATimelineRenderer.vue +224 -31
- package/dist/runtime/components/renderers/ATimelineRenderer.vue.d.ts +1 -0
- package/dist/runtime/components/renderers/calendar/ACalendarDayCell.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/calendar/ACalendarDayCell.vue +12 -1
- package/dist/runtime/components/renderers/calendar/ACalendarDayCell.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/calendar/ACalendarEventChip.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/calendar/ACalendarEventChip.vue +15 -3
- package/dist/runtime/components/renderers/calendar/ACalendarEventChip.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/calendar/ACalendarMonthView.d.vue.ts +14 -0
- package/dist/runtime/components/renderers/calendar/ACalendarMonthView.vue +6 -1
- package/dist/runtime/components/renderers/calendar/ACalendarMonthView.vue.d.ts +14 -0
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.d.vue.ts +6 -6
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.vue +25 -7
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.vue.d.ts +6 -6
- package/dist/runtime/components/renderers/sheets/ASheetsMobileActionBar.d.vue.ts +2 -2
- package/dist/runtime/components/renderers/sheets/ASheetsMobileActionBar.vue.d.ts +2 -2
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.d.vue.ts +6 -0
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue +130 -23
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue.d.ts +6 -0
- package/dist/runtime/components/renderers/timeline/ATimelineAxis.vue +5 -3
- package/dist/runtime/components/renderers/timeline/ATimelineBar.vue +1 -1
- package/dist/runtime/components/renderers/timeline/ATimelineBarArea.d.vue.ts +0 -2
- package/dist/runtime/components/renderers/timeline/ATimelineBarArea.vue +16 -14
- package/dist/runtime/components/renderers/timeline/ATimelineBarArea.vue.d.ts +0 -2
- package/dist/runtime/components/renderers/timeline/ATimelineLabelPanel.vue +4 -2
- package/dist/runtime/composables/useAbracadabraAuth.d.ts +1 -0
- package/dist/runtime/composables/useAbracadabraAuth.js +1 -0
- package/dist/runtime/composables/useCalendarView.js +34 -11
- package/dist/runtime/composables/useConnectionStatus.d.ts +1 -1
- package/dist/runtime/composables/useGraphReferenceEdges.d.ts +26 -0
- package/dist/runtime/composables/useGraphReferenceEdges.js +138 -0
- package/dist/runtime/composables/useGraphSim.d.ts +79 -0
- package/dist/runtime/composables/useGraphSim.js +231 -0
- package/dist/runtime/composables/useSheetsDependencyGraph.d.ts +26 -0
- package/dist/runtime/composables/useSheetsDependencyGraph.js +76 -0
- package/dist/runtime/composables/useSheetsFormulas.d.ts +4 -3
- package/dist/runtime/composables/useSheetsFormulas.js +575 -26
- package/dist/runtime/composables/useTimelineView.d.ts +4 -0
- package/dist/runtime/composables/useTimelineView.js +45 -11
- package/dist/runtime/composables/useWindowManager.d.ts +4 -0
- package/dist/runtime/composables/useWindowManager.js +11 -0
- package/dist/runtime/composables/useWorkspace.d.ts +57 -0
- package/dist/runtime/composables/useWorkspace.js +58 -0
- package/dist/runtime/middleware/abracadabra-auth.js +11 -1
- package/dist/runtime/plugin-abracadabra.client.js +121 -12
- package/dist/runtime/utils/dateField.d.ts +17 -0
- package/dist/runtime/utils/dateField.js +19 -0
- package/dist/runtime/utils/itemLabel.d.ts +27 -0
- package/dist/runtime/utils/itemLabel.js +8 -0
- package/dist/runtime/utils/localDate.d.ts +15 -0
- package/dist/runtime/utils/localDate.js +16 -0
- package/dist/runtime/utils/lucideIcons.d.ts +16 -10
- package/dist/runtime/utils/lucideIcons.js +1391 -69
- package/dist/runtime/utils/resolveDocColor.d.ts +7 -0
- package/dist/runtime/utils/resolveDocColor.js +32 -0
- package/dist/runtime/utils/resolveDocIcon.d.ts +10 -0
- package/dist/runtime/utils/resolveDocIcon.js +44 -0
- package/dist/runtime/utils/rowEdges.d.ts +22 -0
- package/dist/runtime/utils/rowEdges.js +29 -0
- package/dist/runtime/utils/softKeystore.d.ts +55 -0
- package/dist/runtime/utils/softKeystore.js +160 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1006 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref, computed, watch, onUnmounted, onScopeDispose } from "vue";
|
|
3
|
+
import { useRouter, useRoute, useRuntimeConfig, useToast } from "#imports";
|
|
4
|
+
import * as Y from "yjs";
|
|
5
|
+
import { useAbracadabra } from "../composables/useAbracadabra";
|
|
6
|
+
import { useChildTree } from "../composables/useChildTree";
|
|
7
|
+
import { useNodePanel } from "../composables/useNodePanel";
|
|
8
|
+
import { useWindowManager } from "../composables/useWindowManager";
|
|
9
|
+
import { useItemPresence, useViewingBroadcast } from "../composables/useItemPresence";
|
|
10
|
+
import { useTreeExpansion } from "../composables/useTreeExpansion";
|
|
11
|
+
import { useTiptapDragState } from "../composables/useTiptapDragState";
|
|
12
|
+
import { useDocDragBus } from "../composables/useDocDragBus";
|
|
13
|
+
import { useFavorites } from "../composables/useFavorites";
|
|
14
|
+
import { useOfflineUploadQueue } from "../composables/useOfflineUploadQueue";
|
|
15
|
+
import { resolveDocType, getAvailableDocTypes } from "../utils/docTypes";
|
|
16
|
+
import { resolveDocIcon } from "../utils/resolveDocIcon";
|
|
17
|
+
import { resolveDocColor } from "../utils/resolveDocColor";
|
|
18
|
+
import { avatarBorderStyle } from "../utils/avatarStyle";
|
|
19
|
+
import { duplicateDocTree } from "../utils/duplicateDocContent";
|
|
20
|
+
import { populateYDocFromMarkdown, filenameToLabel, parseFrontmatter } from "../utils/markdownToYjs";
|
|
21
|
+
import { populateYDocFromHtml, appendHtmlToFragment } from "../utils/htmlToYjs";
|
|
22
|
+
import { isDocDrag, parseDocDragPayload, isDescendantInMap, DOC_DRAG_MIME } from "../utils/docDragDrop";
|
|
23
|
+
const props = defineProps({
|
|
24
|
+
docId: { type: String, required: true },
|
|
25
|
+
expanded: { type: Boolean, required: false, default: true },
|
|
26
|
+
editable: { type: Boolean, required: false, default: true },
|
|
27
|
+
labels: { type: Object, required: false, default: () => ({}) }
|
|
28
|
+
});
|
|
29
|
+
const emit = defineEmits(["open"]);
|
|
30
|
+
const config = useRuntimeConfig();
|
|
31
|
+
const moduleLocale = computed(
|
|
32
|
+
() => config.public?.abracadabra?.locale ?? {}
|
|
33
|
+
);
|
|
34
|
+
const DEFAULT_LABELS = {
|
|
35
|
+
subPages: "Sub-pages",
|
|
36
|
+
addChildPage: "Add child page",
|
|
37
|
+
open: "Open",
|
|
38
|
+
openAsSlideover: "Open as slideover",
|
|
39
|
+
openAsWindow: "Open as window",
|
|
40
|
+
rename: "Rename",
|
|
41
|
+
duplicate: "Duplicate",
|
|
42
|
+
addToFavorites: "Add to favorites",
|
|
43
|
+
removeFromFavorites: "Remove from favorites",
|
|
44
|
+
changeType: "Change type",
|
|
45
|
+
moveToTrash: "Move to trash",
|
|
46
|
+
untitled: "Untitled",
|
|
47
|
+
appendTo: "Append to",
|
|
48
|
+
toTarget: "in",
|
|
49
|
+
dropToCreateSubPage: "Drop to create a sub-page from",
|
|
50
|
+
dropInto: "Drop into",
|
|
51
|
+
dropToImport: "Drop files or folders to import",
|
|
52
|
+
notConnected: "Not connected",
|
|
53
|
+
uploadFailed: "Upload failed",
|
|
54
|
+
serverRejectedFile: "The server rejected this file.",
|
|
55
|
+
uploadQueued: "Upload queued",
|
|
56
|
+
uploadQueuedDesc: "Will upload when you reconnect."
|
|
57
|
+
};
|
|
58
|
+
const locale = computed(() => {
|
|
59
|
+
const ml = moduleLocale.value;
|
|
60
|
+
return {
|
|
61
|
+
...DEFAULT_LABELS,
|
|
62
|
+
// reuse any overlapping keys an app already set on these sections
|
|
63
|
+
...ml.documentTree ?? {},
|
|
64
|
+
...ml.renderers && ml.renderers.overview ? ml.renderers.overview : {},
|
|
65
|
+
...props.labels ?? {}
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
const { doc: rootDoc, provider, client, isReady } = useAbracadabra();
|
|
69
|
+
const docTree = useChildTree(rootDoc, props.docId);
|
|
70
|
+
const { treeMap } = docTree;
|
|
71
|
+
const canWrite = computed(() => props.editable !== false);
|
|
72
|
+
const router = useRouter();
|
|
73
|
+
const route = useRoute();
|
|
74
|
+
const toast = useToast();
|
|
75
|
+
const { enqueue: enqueueUpload } = useOfflineUploadQueue();
|
|
76
|
+
const { isFavorite, toggleFavorite } = useFavorites(rootDoc);
|
|
77
|
+
const { floatWindowsAvailable, openWindow, windows, focusWindow } = useWindowManager();
|
|
78
|
+
const {
|
|
79
|
+
openNodeId,
|
|
80
|
+
openNodeLabel,
|
|
81
|
+
openNodeProvider,
|
|
82
|
+
isLoading: nodePanelLoading,
|
|
83
|
+
openNode,
|
|
84
|
+
closePanel
|
|
85
|
+
} = useNodePanel(provider);
|
|
86
|
+
useViewingBroadcast(() => props.docId, openNodeId);
|
|
87
|
+
const { getViewers: getDocViewers } = useItemPresence();
|
|
88
|
+
function pageIcon(id, entry) {
|
|
89
|
+
return resolveDocIcon(entry.meta, entry.type, {
|
|
90
|
+
selfId: id,
|
|
91
|
+
lookup: (lid) => treeMap.data[lid]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function pageColor(id, entry) {
|
|
95
|
+
return resolveDocColor(entry.meta, entry.type, {
|
|
96
|
+
selfId: id,
|
|
97
|
+
lookup: (lid) => treeMap.data[lid]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const { expandedIds, toggle: toggleExpand, flatItems } = useTreeExpansion({
|
|
101
|
+
storageKey: `subdoc:expand:${props.docId}`,
|
|
102
|
+
childrenOf: (parentId) => docTree.childrenOf(parentId)
|
|
103
|
+
});
|
|
104
|
+
const viewersByPage = computed(() => {
|
|
105
|
+
const m = /* @__PURE__ */ new Map();
|
|
106
|
+
for (const item of flatItems.value) {
|
|
107
|
+
const v = getDocViewers(item.id);
|
|
108
|
+
if (v.length) m.set(item.id, v);
|
|
109
|
+
}
|
|
110
|
+
return m;
|
|
111
|
+
});
|
|
112
|
+
function pageViewers(pageId) {
|
|
113
|
+
return viewersByPage.value.get(pageId) ?? [];
|
|
114
|
+
}
|
|
115
|
+
function openFull(id, label) {
|
|
116
|
+
emit("open", id, label);
|
|
117
|
+
router.push(`/doc/${id}`);
|
|
118
|
+
}
|
|
119
|
+
function onItemActivate(e, id, label) {
|
|
120
|
+
if (e.metaKey || e.ctrlKey) {
|
|
121
|
+
openNode(id, label);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (e.altKey) {
|
|
125
|
+
if (floatWindowsAvailable.value) {
|
|
126
|
+
openAsWindow(id, label);
|
|
127
|
+
} else {
|
|
128
|
+
openNode(id, label);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
openFull(id, label);
|
|
133
|
+
}
|
|
134
|
+
const dragId = ref(null);
|
|
135
|
+
const dropIndicator = ref(null);
|
|
136
|
+
const tiptapDragState = useTiptapDragState();
|
|
137
|
+
const tiptapDragActive = computed(() => tiptapDragState.value !== null);
|
|
138
|
+
const docDragBus = useDocDragBus();
|
|
139
|
+
let dragOriginDocId = null;
|
|
140
|
+
watch(tiptapDragState, (state, oldState) => {
|
|
141
|
+
if (state) {
|
|
142
|
+
dragOriginDocId = state.sourceDocId;
|
|
143
|
+
} else if (oldState && dragOriginDocId) {
|
|
144
|
+
dropIndicator.value = null;
|
|
145
|
+
const currentDocId = route.params.id;
|
|
146
|
+
if (currentDocId && currentDocId !== dragOriginDocId) {
|
|
147
|
+
router.push(`/doc/${dragOriginDocId}`);
|
|
148
|
+
}
|
|
149
|
+
dragOriginDocId = null;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
function siblingParentOf(targetId) {
|
|
153
|
+
const entry = docTree.treeMap.get(targetId);
|
|
154
|
+
if (!entry) return null;
|
|
155
|
+
const pid = entry.parentId ?? null;
|
|
156
|
+
return pid === props.docId ? null : pid;
|
|
157
|
+
}
|
|
158
|
+
function computeOrder(targetId, position, parentId = null, excludeId) {
|
|
159
|
+
const exclude = excludeId ?? dragId.value;
|
|
160
|
+
const siblings = docTree.childrenOf(parentId).filter((p) => p.id !== exclude);
|
|
161
|
+
const idx = siblings.findIndex((p) => p.id === targetId);
|
|
162
|
+
if (idx < 0) return Date.now();
|
|
163
|
+
const target = siblings[idx];
|
|
164
|
+
if (position === "before") {
|
|
165
|
+
const prev = siblings[idx - 1];
|
|
166
|
+
return prev ? (prev.order + target.order) / 2 : target.order - 1e3;
|
|
167
|
+
} else {
|
|
168
|
+
const next = siblings[idx + 1];
|
|
169
|
+
return next ? (target.order + next.order) / 2 : target.order + 1e3;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function onDragStart(e, page) {
|
|
173
|
+
if (!canWrite.value) return;
|
|
174
|
+
dragId.value = page.id;
|
|
175
|
+
if (e.dataTransfer) {
|
|
176
|
+
e.dataTransfer.effectAllowed = "move";
|
|
177
|
+
e.dataTransfer.setData("text/plain", page.id);
|
|
178
|
+
e.dataTransfer.setData(DOC_DRAG_MIME, JSON.stringify({ id: page.id, label: page.label }));
|
|
179
|
+
}
|
|
180
|
+
docDragBus.startDrag({
|
|
181
|
+
docIds: [page.id],
|
|
182
|
+
labels: [page.label],
|
|
183
|
+
source: "subpagelist",
|
|
184
|
+
sourceDocId: props.docId,
|
|
185
|
+
pointer: { x: e.clientX, y: e.clientY }
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function dropPositionFromEvent(e) {
|
|
189
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
190
|
+
const y = e.clientY - rect.top;
|
|
191
|
+
const h = rect.height;
|
|
192
|
+
if (y < h * 0.25) return "before";
|
|
193
|
+
if (y > h * 0.75) return "after";
|
|
194
|
+
return "inside";
|
|
195
|
+
}
|
|
196
|
+
function onDragOver(e, page) {
|
|
197
|
+
if (dragId.value === null && tiptapDragState.value !== null) {
|
|
198
|
+
if (tiptapDragState.value.sourceDocId === page.id) {
|
|
199
|
+
if (dropIndicator.value !== null) dropIndicator.value = null;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
e.preventDefault();
|
|
203
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
|
|
204
|
+
if (dropIndicator.value?.targetId !== page.id || dropIndicator.value?.position !== "inside") {
|
|
205
|
+
dropIndicator.value = { targetId: page.id, position: "inside" };
|
|
206
|
+
}
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (dragId.value === null && isExternalFileDrag(e)) {
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = "copy";
|
|
212
|
+
if (dropIndicator.value?.targetId !== page.id || dropIndicator.value?.position !== "inside") {
|
|
213
|
+
dropIndicator.value = { targetId: page.id, position: "inside" };
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (!dragId.value && isDocDrag(e)) {
|
|
218
|
+
e.preventDefault();
|
|
219
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
|
|
220
|
+
const position2 = dropPositionFromEvent(e);
|
|
221
|
+
if (dropIndicator.value?.targetId !== page.id || dropIndicator.value?.position !== position2) {
|
|
222
|
+
dropIndicator.value = { targetId: page.id, position: position2 };
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!dragId.value || dragId.value === page.id) {
|
|
227
|
+
if (dropIndicator.value !== null) dropIndicator.value = null;
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (isDescendantInMap(treeMap.data, dragId.value, page.id)) {
|
|
231
|
+
if (dropIndicator.value !== null) dropIndicator.value = null;
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
e.preventDefault();
|
|
235
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
|
|
236
|
+
const position = dropPositionFromEvent(e);
|
|
237
|
+
if (dropIndicator.value?.targetId !== page.id || dropIndicator.value?.position !== position) {
|
|
238
|
+
dropIndicator.value = { targetId: page.id, position };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function onListDragLeave(e) {
|
|
242
|
+
const related = e.relatedTarget;
|
|
243
|
+
if (related && e.currentTarget.contains(related)) return;
|
|
244
|
+
dropIndicator.value = null;
|
|
245
|
+
}
|
|
246
|
+
async function onTiptapDrop(targetId) {
|
|
247
|
+
const state = tiptapDragState.value;
|
|
248
|
+
if (!state) return;
|
|
249
|
+
tiptapDragState.value = null;
|
|
250
|
+
dropIndicator.value = null;
|
|
251
|
+
dragOriginDocId = null;
|
|
252
|
+
if (!isReady.value || !provider.value) {
|
|
253
|
+
toast.add({ title: locale.value.notConnected, color: "warning", icon: "i-lucide-cloud-off" });
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (targetId === null) {
|
|
257
|
+
const newId = crypto.randomUUID();
|
|
258
|
+
const label = `Block from "${state.sourceDocLabel}"`;
|
|
259
|
+
treeMap.set(newId, { label, parentId: props.docId, order: Date.now(), type: "doc" });
|
|
260
|
+
const childProv = await provider.value.loadChild(newId);
|
|
261
|
+
const fragment = childProv.document.getXmlFragment("default");
|
|
262
|
+
populateYDocFromHtml(fragment, state.html, label);
|
|
263
|
+
state.deleteFromSource();
|
|
264
|
+
router.push(`/doc/${newId}`);
|
|
265
|
+
} else {
|
|
266
|
+
if (targetId === state.sourceDocId) return;
|
|
267
|
+
const childProv = await provider.value.loadChild(targetId);
|
|
268
|
+
if (!childProv.isSynced) {
|
|
269
|
+
await waitForSync(childProv);
|
|
270
|
+
}
|
|
271
|
+
const fragment = childProv.document.getXmlFragment("default");
|
|
272
|
+
appendHtmlToFragment(fragment, state.html);
|
|
273
|
+
state.deleteFromSource();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function onDrop(e) {
|
|
277
|
+
e.preventDefault();
|
|
278
|
+
if (!canWrite.value) return;
|
|
279
|
+
if (dragId.value === null && tiptapDragState.value !== null) {
|
|
280
|
+
const targetId2 = dropIndicator.value?.targetId ?? null;
|
|
281
|
+
onTiptapDrop(targetId2);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (!dragId.value) {
|
|
285
|
+
const crossPayload = parseDocDragPayload(e);
|
|
286
|
+
if (crossPayload) {
|
|
287
|
+
const { targetId: targetId3, position: position2 } = dropIndicator.value ?? { targetId: null, position: null };
|
|
288
|
+
dropIndicator.value = null;
|
|
289
|
+
externalDragActive.value = false;
|
|
290
|
+
externalDragCounter = 0;
|
|
291
|
+
if (!targetId3 || !position2) return;
|
|
292
|
+
if (!treeMap.get(crossPayload.id)) return;
|
|
293
|
+
if (crossPayload.id === targetId3) return;
|
|
294
|
+
if (isDescendantInMap(treeMap.data, crossPayload.id, targetId3)) return;
|
|
295
|
+
if (position2 === "before" || position2 === "after") {
|
|
296
|
+
const sibParent = siblingParentOf(targetId3);
|
|
297
|
+
const newOrder = computeOrder(targetId3, position2, sibParent, crossPayload.id);
|
|
298
|
+
docTree.moveEntry(crossPayload.id, sibParent, newOrder);
|
|
299
|
+
} else {
|
|
300
|
+
docTree.moveEntry(crossPayload.id, targetId3, Date.now());
|
|
301
|
+
if (!expandedIds.value.has(targetId3)) toggleExpand(targetId3);
|
|
302
|
+
}
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const targetId2 = dropIndicator.value?.targetId ?? null;
|
|
306
|
+
dropIndicator.value = null;
|
|
307
|
+
onExternalFileDrop(e, targetId2);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (!dropIndicator.value) {
|
|
311
|
+
cleanupDrag();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const id = dragId.value;
|
|
315
|
+
const { targetId, position } = dropIndicator.value;
|
|
316
|
+
if (!treeMap.get(id)) {
|
|
317
|
+
cleanupDrag();
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (position === "before" || position === "after") {
|
|
321
|
+
const sibParent = siblingParentOf(targetId);
|
|
322
|
+
const newOrder = computeOrder(targetId, position, sibParent);
|
|
323
|
+
docTree.moveEntry(id, sibParent, newOrder);
|
|
324
|
+
} else {
|
|
325
|
+
docTree.moveEntry(id, targetId, Date.now());
|
|
326
|
+
if (!expandedIds.value.has(targetId)) toggleExpand(targetId);
|
|
327
|
+
}
|
|
328
|
+
cleanupDrag();
|
|
329
|
+
}
|
|
330
|
+
function onDragEnd() {
|
|
331
|
+
cleanupDrag();
|
|
332
|
+
}
|
|
333
|
+
function cleanupDrag() {
|
|
334
|
+
dragId.value = null;
|
|
335
|
+
dropIndicator.value = null;
|
|
336
|
+
docDragBus.endDrag();
|
|
337
|
+
}
|
|
338
|
+
const busDragFromRenderer = computed(
|
|
339
|
+
() => docDragBus.isDragging.value && docDragBus.dragState.value?.source === "renderer"
|
|
340
|
+
);
|
|
341
|
+
function onBusPointerMove() {
|
|
342
|
+
if (!busDragFromRenderer.value || !docDragBus.dragState.value) return;
|
|
343
|
+
const { pointer } = docDragBus.dragState.value;
|
|
344
|
+
const el = document.elementFromPoint(pointer.x, pointer.y);
|
|
345
|
+
if (!el) {
|
|
346
|
+
dropIndicator.value = null;
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const itemEl = el.closest?.("[data-subpage-item-id]");
|
|
350
|
+
if (!itemEl) {
|
|
351
|
+
dropIndicator.value = null;
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const itemId = itemEl.getAttribute("data-subpage-item-id");
|
|
355
|
+
if (!itemId || !treeMap.get(itemId)) {
|
|
356
|
+
dropIndicator.value = null;
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const rect = itemEl.getBoundingClientRect();
|
|
360
|
+
const y = pointer.y - rect.top;
|
|
361
|
+
const h = rect.height;
|
|
362
|
+
let position;
|
|
363
|
+
if (y < h * 0.25) position = "before";
|
|
364
|
+
else if (y > h * 0.75) position = "after";
|
|
365
|
+
else position = "inside";
|
|
366
|
+
const { docIds } = docDragBus.dragState.value;
|
|
367
|
+
for (const docId of docIds) {
|
|
368
|
+
if (isDescendantInMap(treeMap.data, docId, itemId)) {
|
|
369
|
+
dropIndicator.value = null;
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (dropIndicator.value?.targetId !== itemId || dropIndicator.value?.position !== position) {
|
|
374
|
+
dropIndicator.value = { targetId: itemId, position };
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
function onBusPointerUp() {
|
|
378
|
+
if (!busDragFromRenderer.value || !docDragBus.dragState.value || !dropIndicator.value) return;
|
|
379
|
+
const { docIds } = docDragBus.dragState.value;
|
|
380
|
+
const { targetId, position } = dropIndicator.value;
|
|
381
|
+
if (!treeMap.get(targetId)) {
|
|
382
|
+
dropIndicator.value = null;
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (position === "inside") {
|
|
386
|
+
docIds.forEach((id) => {
|
|
387
|
+
docTree.moveEntry(id, targetId, Date.now());
|
|
388
|
+
});
|
|
389
|
+
if (!expandedIds.value.has(targetId)) toggleExpand(targetId);
|
|
390
|
+
} else {
|
|
391
|
+
const sibParent = siblingParentOf(targetId);
|
|
392
|
+
docIds.forEach((id, idx) => {
|
|
393
|
+
const newOrder = computeOrder(targetId, position === "before" ? "before" : "after", sibParent, id) + idx;
|
|
394
|
+
docTree.moveEntry(id, sibParent, newOrder);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
dropIndicator.value = null;
|
|
398
|
+
docDragBus.endDrag();
|
|
399
|
+
}
|
|
400
|
+
let busRafId = null;
|
|
401
|
+
watch(
|
|
402
|
+
() => docDragBus.dragState.value?.pointer,
|
|
403
|
+
() => {
|
|
404
|
+
if (!busDragFromRenderer.value) return;
|
|
405
|
+
if (busRafId !== null) cancelAnimationFrame(busRafId);
|
|
406
|
+
busRafId = requestAnimationFrame(onBusPointerMove);
|
|
407
|
+
},
|
|
408
|
+
{ flush: "sync" }
|
|
409
|
+
);
|
|
410
|
+
watch(busDragFromRenderer, (active) => {
|
|
411
|
+
if (!import.meta.client) return;
|
|
412
|
+
if (active) {
|
|
413
|
+
document.addEventListener("pointerup", onBusPointerUp);
|
|
414
|
+
} else {
|
|
415
|
+
document.removeEventListener("pointerup", onBusPointerUp);
|
|
416
|
+
dropIndicator.value = null;
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
onUnmounted(() => {
|
|
420
|
+
if (import.meta.client) document.removeEventListener("pointerup", onBusPointerUp);
|
|
421
|
+
if (busRafId !== null) cancelAnimationFrame(busRafId);
|
|
422
|
+
});
|
|
423
|
+
const externalDragActive = ref(false);
|
|
424
|
+
let externalDragCounter = 0;
|
|
425
|
+
function resetExternalDrag() {
|
|
426
|
+
externalDragCounter = 0;
|
|
427
|
+
externalDragActive.value = false;
|
|
428
|
+
}
|
|
429
|
+
if (import.meta.client) {
|
|
430
|
+
window.addEventListener("drop", resetExternalDrag, true);
|
|
431
|
+
window.addEventListener("dragend", resetExternalDrag, true);
|
|
432
|
+
onScopeDispose(() => {
|
|
433
|
+
window.removeEventListener("drop", resetExternalDrag, true);
|
|
434
|
+
window.removeEventListener("dragend", resetExternalDrag, true);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
function isExternalFileDrag(e) {
|
|
438
|
+
return !!e.dataTransfer?.types.includes("Files");
|
|
439
|
+
}
|
|
440
|
+
function onContainerDragEnter(e) {
|
|
441
|
+
if (dragId.value !== null) return;
|
|
442
|
+
if (!isExternalFileDrag(e) && !isDocDrag(e)) return;
|
|
443
|
+
externalDragCounter++;
|
|
444
|
+
externalDragActive.value = true;
|
|
445
|
+
}
|
|
446
|
+
function onContainerDragLeave(e) {
|
|
447
|
+
if (!isExternalFileDrag(e) && !isDocDrag(e)) return;
|
|
448
|
+
externalDragCounter--;
|
|
449
|
+
if (externalDragCounter <= 0) {
|
|
450
|
+
externalDragCounter = 0;
|
|
451
|
+
externalDragActive.value = false;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function onContainerDragOver(e) {
|
|
455
|
+
if (dragId.value !== null) return;
|
|
456
|
+
if (!isExternalFileDrag(e) && tiptapDragState.value === null && !isDocDrag(e)) return;
|
|
457
|
+
e.preventDefault();
|
|
458
|
+
if (e.dataTransfer)
|
|
459
|
+
e.dataTransfer.dropEffect = isExternalFileDrag(e) ? "copy" : "move";
|
|
460
|
+
}
|
|
461
|
+
function onOuterDrop(e) {
|
|
462
|
+
if (tiptapDragState.value !== null) {
|
|
463
|
+
onTiptapDrop(null);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const crossPayload = parseDocDragPayload(e);
|
|
467
|
+
if (crossPayload) {
|
|
468
|
+
externalDragActive.value = false;
|
|
469
|
+
externalDragCounter = 0;
|
|
470
|
+
if (treeMap.get(crossPayload.id)) {
|
|
471
|
+
docTree.moveEntry(crossPayload.id, props.docId, Date.now());
|
|
472
|
+
}
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
onExternalFileDrop(e, null);
|
|
476
|
+
}
|
|
477
|
+
function waitForSync(childProv) {
|
|
478
|
+
return new Promise((resolve) => {
|
|
479
|
+
const done = () => {
|
|
480
|
+
childProv.off("synced", done);
|
|
481
|
+
resolve();
|
|
482
|
+
};
|
|
483
|
+
childProv.on("synced", done);
|
|
484
|
+
setTimeout(resolve, 6e3);
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
async function onExternalFileDrop(e, parentId = null) {
|
|
488
|
+
if (dragId.value !== null) return;
|
|
489
|
+
externalDragActive.value = false;
|
|
490
|
+
externalDragCounter = 0;
|
|
491
|
+
if (!isReady.value || !provider.value) return;
|
|
492
|
+
e.preventDefault();
|
|
493
|
+
const entries = Array.from(e.dataTransfer?.items ?? []).map((item) => item.webkitGetAsEntry()).filter((entry) => entry !== null);
|
|
494
|
+
if (!entries.length) return;
|
|
495
|
+
const effectiveParentId = parentId ?? props.docId;
|
|
496
|
+
const nodes = [];
|
|
497
|
+
for (const fsEntry of entries) {
|
|
498
|
+
const node = await collectEntry(fsEntry);
|
|
499
|
+
if (node) nodes.push(node);
|
|
500
|
+
}
|
|
501
|
+
let firstId = null;
|
|
502
|
+
for (const node of nodes) {
|
|
503
|
+
const id = await materializeNode(node, effectiveParentId);
|
|
504
|
+
if (firstId === null && id !== null) firstId = id;
|
|
505
|
+
}
|
|
506
|
+
if (parentId) {
|
|
507
|
+
router.push(`/doc/${parentId}`);
|
|
508
|
+
} else if (firstId) {
|
|
509
|
+
router.push(`/doc/${firstId}`);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
const TEXT_EXTENSIONS = ["md", "mdx", "txt", "html", "htm"];
|
|
513
|
+
async function collectEntry(fsEntry) {
|
|
514
|
+
if (fsEntry.name.startsWith(".")) return null;
|
|
515
|
+
if (fsEntry.isFile) {
|
|
516
|
+
const file = await new Promise(
|
|
517
|
+
(resolve, reject) => fsEntry.file(resolve, reject)
|
|
518
|
+
);
|
|
519
|
+
return { kind: "file", file };
|
|
520
|
+
}
|
|
521
|
+
if (fsEntry.isDirectory) {
|
|
522
|
+
const children = await readDirEntries(fsEntry);
|
|
523
|
+
children.sort((a, b) => {
|
|
524
|
+
if (a.isDirectory !== b.isDirectory) return a.isDirectory ? -1 : 1;
|
|
525
|
+
return a.name.localeCompare(b.name);
|
|
526
|
+
});
|
|
527
|
+
const collected = [];
|
|
528
|
+
for (const child of children) {
|
|
529
|
+
const node = await collectEntry(child);
|
|
530
|
+
if (node) collected.push(node);
|
|
531
|
+
}
|
|
532
|
+
return { kind: "dir", name: fsEntry.name, children: collected };
|
|
533
|
+
}
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
async function materializeNode(node, parentId) {
|
|
537
|
+
if (node.kind === "file") {
|
|
538
|
+
return importFile(node.file, parentId);
|
|
539
|
+
}
|
|
540
|
+
const id = crypto.randomUUID();
|
|
541
|
+
treeMap.set(id, { label: filenameToLabel(node.name), parentId, order: Date.now(), type: "doc" });
|
|
542
|
+
for (const child of node.children) await materializeNode(child, id);
|
|
543
|
+
return id;
|
|
544
|
+
}
|
|
545
|
+
async function importFile(file, parentId) {
|
|
546
|
+
const ext = file.name.split(".").pop()?.toLowerCase() ?? "";
|
|
547
|
+
if (TEXT_EXTENSIONS.includes(ext)) return importTextFile(file, parentId);
|
|
548
|
+
return importBinaryFile(file, parentId);
|
|
549
|
+
}
|
|
550
|
+
async function importTextFile(file, parentId) {
|
|
551
|
+
const ext = file.name.split(".").pop()?.toLowerCase() ?? "";
|
|
552
|
+
const text = await file.text();
|
|
553
|
+
let label = filenameToLabel(file.name);
|
|
554
|
+
let meta = {};
|
|
555
|
+
let body = text;
|
|
556
|
+
if (ext === "md" || ext === "mdx" || ext === "txt") {
|
|
557
|
+
const fm = parseFrontmatter(text);
|
|
558
|
+
if (fm.title) label = fm.title;
|
|
559
|
+
meta = fm.meta;
|
|
560
|
+
body = fm.body;
|
|
561
|
+
}
|
|
562
|
+
const id = crypto.randomUUID();
|
|
563
|
+
treeMap.set(id, {
|
|
564
|
+
label,
|
|
565
|
+
parentId,
|
|
566
|
+
order: Date.now(),
|
|
567
|
+
type: "doc",
|
|
568
|
+
...Object.keys(meta).length ? { meta } : {}
|
|
569
|
+
});
|
|
570
|
+
const childProv = await provider.value.loadChild(id);
|
|
571
|
+
const fragment = childProv.document.getXmlFragment("default");
|
|
572
|
+
if (ext === "html" || ext === "htm") {
|
|
573
|
+
populateYDocFromHtml(fragment, text, label);
|
|
574
|
+
} else {
|
|
575
|
+
populateYDocFromMarkdown(fragment, body, label);
|
|
576
|
+
}
|
|
577
|
+
return id;
|
|
578
|
+
}
|
|
579
|
+
async function importBinaryFile(file, parentId) {
|
|
580
|
+
const id = crypto.randomUUID();
|
|
581
|
+
const label = filenameToLabel(file.name);
|
|
582
|
+
const mimeType = file.type || "application/octet-stream";
|
|
583
|
+
treeMap.set(id, { label, parentId, order: Date.now(), type: "doc" });
|
|
584
|
+
const rootDocId = provider.value?.configuration?.name;
|
|
585
|
+
if (client.value && rootDocId && rootDocId !== id) {
|
|
586
|
+
await client.value.createChild(rootDocId, { child_id: id, kind: "page" }).catch(() => {
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
let uploadId;
|
|
590
|
+
let uploadDocId;
|
|
591
|
+
try {
|
|
592
|
+
if (!client.value) throw new Error("offline");
|
|
593
|
+
const meta = await client.value.upload(id, file);
|
|
594
|
+
uploadId = meta.id;
|
|
595
|
+
uploadDocId = meta.doc_id;
|
|
596
|
+
} catch (err) {
|
|
597
|
+
const status = err?.status;
|
|
598
|
+
if (status && status >= 400 && status < 500) {
|
|
599
|
+
toast.add({
|
|
600
|
+
title: locale.value.uploadFailed,
|
|
601
|
+
description: err.message || locale.value.serverRejectedFile,
|
|
602
|
+
color: "error",
|
|
603
|
+
icon: "i-lucide-circle-x"
|
|
604
|
+
});
|
|
605
|
+
return id;
|
|
606
|
+
}
|
|
607
|
+
const meta = await enqueueUpload(id, file);
|
|
608
|
+
uploadId = meta.id;
|
|
609
|
+
uploadDocId = meta.doc_id;
|
|
610
|
+
toast.add({
|
|
611
|
+
title: locale.value.uploadQueued,
|
|
612
|
+
description: locale.value.uploadQueuedDesc,
|
|
613
|
+
color: "warning",
|
|
614
|
+
icon: "i-lucide-cloud-off"
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
const childProv = await provider.value.loadChild(id);
|
|
618
|
+
const fragment = childProv.document.getXmlFragment("default");
|
|
619
|
+
childProv.document.transact(() => {
|
|
620
|
+
const el = new Y.XmlElement("fileBlock");
|
|
621
|
+
el.setAttribute("uploadId", uploadId);
|
|
622
|
+
el.setAttribute("docId", uploadDocId);
|
|
623
|
+
el.setAttribute("filename", file.name);
|
|
624
|
+
el.setAttribute("mimeType", mimeType);
|
|
625
|
+
fragment.insert(0, [el]);
|
|
626
|
+
}, "system");
|
|
627
|
+
return id;
|
|
628
|
+
}
|
|
629
|
+
function readDirEntries(dir) {
|
|
630
|
+
return new Promise((resolve, reject) => {
|
|
631
|
+
const reader = dir.createReader();
|
|
632
|
+
const all = [];
|
|
633
|
+
function next() {
|
|
634
|
+
reader.readEntries((batch) => {
|
|
635
|
+
if (!batch.length) {
|
|
636
|
+
resolve(all);
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
all.push(...batch);
|
|
640
|
+
next();
|
|
641
|
+
}, reject);
|
|
642
|
+
}
|
|
643
|
+
next();
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
function createChildPage(parentId) {
|
|
647
|
+
if (!isReady.value || !canWrite.value) return;
|
|
648
|
+
const id = crypto.randomUUID();
|
|
649
|
+
treeMap.set(id, { label: "", parentId, order: Date.now(), type: "doc" });
|
|
650
|
+
void client.value?.createChild?.(parentId, { child_id: id, kind: "page" })?.catch?.(() => {
|
|
651
|
+
});
|
|
652
|
+
router.push(`/doc/${id}`);
|
|
653
|
+
}
|
|
654
|
+
async function duplicateDoc(id) {
|
|
655
|
+
if (!provider.value) return;
|
|
656
|
+
await duplicateDocTree(
|
|
657
|
+
provider.value,
|
|
658
|
+
id,
|
|
659
|
+
treeMap.data,
|
|
660
|
+
(newId, entry) => treeMap.set(newId, entry)
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
async function openAsWindow(id, label) {
|
|
664
|
+
if (windows.has(id)) {
|
|
665
|
+
focusWindow(id);
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
const childProv = await provider.value?.loadChild(id);
|
|
669
|
+
if (!childProv) return;
|
|
670
|
+
if (!childProv.isSynced) await waitForSync(childProv);
|
|
671
|
+
const entry = treeMap.get(id);
|
|
672
|
+
openWindow({
|
|
673
|
+
id,
|
|
674
|
+
title: label,
|
|
675
|
+
docId: id,
|
|
676
|
+
docType: entry?.type,
|
|
677
|
+
provider: childProv,
|
|
678
|
+
initialTab: "editor"
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
function changeDocType(id, type) {
|
|
682
|
+
const entry = treeMap.get(id);
|
|
683
|
+
if (entry) treeMap.set(id, { ...entry, type });
|
|
684
|
+
}
|
|
685
|
+
const renameId = ref(null);
|
|
686
|
+
const renameValue = ref("");
|
|
687
|
+
function startRename(id) {
|
|
688
|
+
if (!canWrite.value) return;
|
|
689
|
+
const entry = treeMap.get(id);
|
|
690
|
+
if (!entry) return;
|
|
691
|
+
renameId.value = id;
|
|
692
|
+
renameValue.value = entry.label;
|
|
693
|
+
}
|
|
694
|
+
function commitRename() {
|
|
695
|
+
if (!renameId.value || !renameValue.value.trim()) {
|
|
696
|
+
renameId.value = null;
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
docTree.renameEntry(renameId.value, renameValue.value.trim());
|
|
700
|
+
renameId.value = null;
|
|
701
|
+
}
|
|
702
|
+
function pageMenuItems(page) {
|
|
703
|
+
const l = locale.value;
|
|
704
|
+
return [
|
|
705
|
+
[
|
|
706
|
+
{ label: l.open, icon: "i-lucide-external-link", onSelect: () => openFull(page.id, page.label) },
|
|
707
|
+
{ label: l.openAsSlideover, icon: "i-lucide-panel-right", onSelect: () => openNode(page.id, page.label) },
|
|
708
|
+
...floatWindowsAvailable.value ? [{ label: l.openAsWindow, icon: "i-lucide-picture-in-picture-2", onSelect: () => openAsWindow(page.id, page.label) }] : [],
|
|
709
|
+
{ label: l.rename, icon: "i-lucide-pencil", onSelect: () => startRename(page.id) },
|
|
710
|
+
{ label: l.duplicate, icon: "i-lucide-copy", onSelect: () => duplicateDoc(page.id) },
|
|
711
|
+
{ label: l.addChildPage, icon: "i-lucide-file-plus", onSelect: () => createChildPage(page.id) },
|
|
712
|
+
{
|
|
713
|
+
label: isFavorite(page.id) ? l.removeFromFavorites : l.addToFavorites,
|
|
714
|
+
icon: isFavorite(page.id) ? "i-lucide-star-off" : "i-lucide-star",
|
|
715
|
+
onSelect: () => toggleFavorite(page.id)
|
|
716
|
+
}
|
|
717
|
+
],
|
|
718
|
+
[
|
|
719
|
+
{
|
|
720
|
+
label: l.changeType,
|
|
721
|
+
icon: "i-lucide-layers",
|
|
722
|
+
children: getAvailableDocTypes().map((typeDef) => ({
|
|
723
|
+
label: typeDef.label,
|
|
724
|
+
icon: typeDef.icon,
|
|
725
|
+
type: "checkbox",
|
|
726
|
+
checked: page.type === typeDef.key,
|
|
727
|
+
onSelect: (e) => {
|
|
728
|
+
e.preventDefault();
|
|
729
|
+
changeDocType(page.id, typeDef.key);
|
|
730
|
+
}
|
|
731
|
+
}))
|
|
732
|
+
}
|
|
733
|
+
],
|
|
734
|
+
[
|
|
735
|
+
{
|
|
736
|
+
label: l.moveToTrash,
|
|
737
|
+
icon: "i-lucide-trash-2",
|
|
738
|
+
color: "error",
|
|
739
|
+
onSelect: () => docTree.deleteEntry(page.id)
|
|
740
|
+
}
|
|
741
|
+
]
|
|
742
|
+
];
|
|
743
|
+
}
|
|
744
|
+
function readOnlyPageMenuItems(page) {
|
|
745
|
+
const l = locale.value;
|
|
746
|
+
return [
|
|
747
|
+
[
|
|
748
|
+
{ label: l.open, icon: "i-lucide-external-link", onSelect: () => openFull(page.id, page.label) },
|
|
749
|
+
{ label: l.openAsSlideover, icon: "i-lucide-panel-right", onSelect: () => openNode(page.id, page.label) },
|
|
750
|
+
...floatWindowsAvailable.value ? [{ label: l.openAsWindow, icon: "i-lucide-picture-in-picture-2", onSelect: () => openAsWindow(page.id, page.label) }] : [],
|
|
751
|
+
{
|
|
752
|
+
label: isFavorite(page.id) ? l.removeFromFavorites : l.addToFavorites,
|
|
753
|
+
icon: isFavorite(page.id) ? "i-lucide-star-off" : "i-lucide-star",
|
|
754
|
+
onSelect: () => toggleFavorite(page.id)
|
|
755
|
+
}
|
|
756
|
+
]
|
|
757
|
+
];
|
|
758
|
+
}
|
|
759
|
+
const isDragActive = computed(() => tiptapDragActive.value || externalDragActive.value || busDragFromRenderer.value);
|
|
760
|
+
</script>
|
|
761
|
+
|
|
762
|
+
<template>
|
|
763
|
+
<div
|
|
764
|
+
v-if="flatItems.length > 0 || canWrite || isDragActive"
|
|
765
|
+
data-doc-drop-zone="subpagelist"
|
|
766
|
+
:class="[
|
|
767
|
+
'mx-auto w-full px-4 sm:px-14 pb-12 transition-colors duration-150',
|
|
768
|
+
expanded ? '' : 'max-w-4xl',
|
|
769
|
+
isDragActive ? 'ring-2 ring-inset ring-(--ui-primary)/30 rounded-(--ui-radius) bg-(--ui-primary)/3' : ''
|
|
770
|
+
]"
|
|
771
|
+
@dragenter="onContainerDragEnter"
|
|
772
|
+
@dragleave="onContainerDragLeave"
|
|
773
|
+
@dragover="onContainerDragOver"
|
|
774
|
+
@drop.prevent.stop="onOuterDrop"
|
|
775
|
+
>
|
|
776
|
+
<div class="flex items-center justify-between mt-8 mb-2">
|
|
777
|
+
<p class="text-xs font-medium text-(--ui-text-muted) uppercase tracking-wide">
|
|
778
|
+
{{ locale.subPages }}
|
|
779
|
+
</p>
|
|
780
|
+
<UTooltip
|
|
781
|
+
v-if="canWrite"
|
|
782
|
+
:text="locale.addChildPage"
|
|
783
|
+
>
|
|
784
|
+
<UButton
|
|
785
|
+
icon="i-lucide-plus"
|
|
786
|
+
size="xs"
|
|
787
|
+
variant="ghost"
|
|
788
|
+
color="neutral"
|
|
789
|
+
@click="createChildPage(props.docId)"
|
|
790
|
+
/>
|
|
791
|
+
</UTooltip>
|
|
792
|
+
</div>
|
|
793
|
+
|
|
794
|
+
<div
|
|
795
|
+
:class="{ 'is-dragging': dragId }"
|
|
796
|
+
@dragleave="onListDragLeave"
|
|
797
|
+
>
|
|
798
|
+
<div
|
|
799
|
+
v-for="item in flatItems"
|
|
800
|
+
:key="item.id"
|
|
801
|
+
:data-subpage-item-id="item.id"
|
|
802
|
+
class="subpage-item relative"
|
|
803
|
+
:class="{ 'opacity-30': dragId === item.id }"
|
|
804
|
+
:style="{ paddingLeft: `${item.depth * 16}px` }"
|
|
805
|
+
@dragover="onDragOver($event, item.entry)"
|
|
806
|
+
@drop.stop="onDrop"
|
|
807
|
+
>
|
|
808
|
+
<!-- Drop indicator: line BEFORE -->
|
|
809
|
+
<div
|
|
810
|
+
v-if="dropIndicator?.targetId === item.id && dropIndicator.position === 'before'"
|
|
811
|
+
class="drop-line drop-line-before"
|
|
812
|
+
>
|
|
813
|
+
<div class="drop-line-dot" />
|
|
814
|
+
</div>
|
|
815
|
+
|
|
816
|
+
<!-- Drop indicator: highlight INSIDE -->
|
|
817
|
+
<div
|
|
818
|
+
v-if="dropIndicator?.targetId === item.id && dropIndicator.position === 'inside'"
|
|
819
|
+
class="drop-inside"
|
|
820
|
+
/>
|
|
821
|
+
|
|
822
|
+
<!-- Drop indicator: line AFTER -->
|
|
823
|
+
<div
|
|
824
|
+
v-if="dropIndicator?.targetId === item.id && dropIndicator.position === 'after'"
|
|
825
|
+
class="drop-line drop-line-after"
|
|
826
|
+
>
|
|
827
|
+
<div class="drop-line-dot" />
|
|
828
|
+
</div>
|
|
829
|
+
|
|
830
|
+
<ANodeContextMenu :items="canWrite ? pageMenuItems(item.entry) : readOnlyPageMenuItems(item.entry)">
|
|
831
|
+
<button
|
|
832
|
+
type="button"
|
|
833
|
+
class="flex items-center gap-1.5 pl-2 pr-3 py-2 rounded-lg hover:bg-(--ui-bg-elevated) transition-colors text-sm text-(--ui-text) w-full select-none cursor-pointer relative"
|
|
834
|
+
:style="pageViewers(item.id).length ? {
|
|
835
|
+
borderLeft: `5px solid ${pageViewers(item.id)[0].color}`,
|
|
836
|
+
backgroundColor: pageViewers(item.id)[0].color + '14'
|
|
837
|
+
} : void 0"
|
|
838
|
+
:draggable="canWrite"
|
|
839
|
+
@dragstart="onDragStart($event, item.entry)"
|
|
840
|
+
@dragend="onDragEnd"
|
|
841
|
+
@click="onItemActivate($event, item.id, item.entry.label)"
|
|
842
|
+
@dblclick.prevent="startRename(item.id)"
|
|
843
|
+
>
|
|
844
|
+
<!-- Remote viewer cluster -->
|
|
845
|
+
<div
|
|
846
|
+
v-if="pageViewers(item.id).length"
|
|
847
|
+
class="absolute right-1 top-1/2 -translate-y-1/2 flex -space-x-1 z-10 pointer-events-none"
|
|
848
|
+
>
|
|
849
|
+
<UAvatar
|
|
850
|
+
v-for="(u, i) in pageViewers(item.id).slice(0, 3)"
|
|
851
|
+
:key="`v-${i}`"
|
|
852
|
+
size="3xs"
|
|
853
|
+
:alt="u.name"
|
|
854
|
+
:title="u.name"
|
|
855
|
+
:style="avatarBorderStyle(u.color, 'zinc')"
|
|
856
|
+
/>
|
|
857
|
+
</div>
|
|
858
|
+
|
|
859
|
+
<!-- Expand/collapse chevron -->
|
|
860
|
+
<span
|
|
861
|
+
v-if="item.hasChildren"
|
|
862
|
+
class="flex items-center justify-center size-5 shrink-0 rounded hover:bg-(--ui-bg-accented)"
|
|
863
|
+
@click.stop="toggleExpand(item.id)"
|
|
864
|
+
>
|
|
865
|
+
<UIcon
|
|
866
|
+
:name="item.expanded ? 'i-lucide-chevron-down' : 'i-lucide-chevron-right'"
|
|
867
|
+
class="size-3.5 text-(--ui-text-dimmed)"
|
|
868
|
+
/>
|
|
869
|
+
</span>
|
|
870
|
+
<span
|
|
871
|
+
v-else
|
|
872
|
+
class="size-5 shrink-0"
|
|
873
|
+
/>
|
|
874
|
+
|
|
875
|
+
<UIcon
|
|
876
|
+
:name="pageIcon(item.id, item.entry)"
|
|
877
|
+
class="size-4 shrink-0"
|
|
878
|
+
:class="pageColor(item.id, item.entry) ? '' : 'text-(--ui-text-muted)'"
|
|
879
|
+
:style="pageColor(item.id, item.entry) ? { color: pageColor(item.id, item.entry) } : void 0"
|
|
880
|
+
/>
|
|
881
|
+
|
|
882
|
+
<UInput
|
|
883
|
+
v-if="renameId === item.id"
|
|
884
|
+
v-model="renameValue"
|
|
885
|
+
size="xs"
|
|
886
|
+
variant="none"
|
|
887
|
+
class="flex-1 -my-1"
|
|
888
|
+
autofocus
|
|
889
|
+
@keydown.enter="commitRename"
|
|
890
|
+
@keydown.escape="renameId = null"
|
|
891
|
+
@blur="commitRename"
|
|
892
|
+
@click.stop
|
|
893
|
+
/>
|
|
894
|
+
<span
|
|
895
|
+
v-else
|
|
896
|
+
class="truncate flex-1 text-left"
|
|
897
|
+
>{{ item.entry.label || locale.untitled }}</span>
|
|
898
|
+
|
|
899
|
+
<UBadge
|
|
900
|
+
v-if="item.entry.type && item.entry.type !== 'doc'"
|
|
901
|
+
:label="resolveDocType(item.entry.type).label"
|
|
902
|
+
size="xs"
|
|
903
|
+
variant="soft"
|
|
904
|
+
color="neutral"
|
|
905
|
+
/>
|
|
906
|
+
|
|
907
|
+
<!-- Hover actions -->
|
|
908
|
+
<div
|
|
909
|
+
v-if="renameId !== item.id && canWrite"
|
|
910
|
+
class="subpage-row-actions absolute right-1 top-1/2 -translate-y-1/2 flex items-center bg-(--ui-bg-elevated)"
|
|
911
|
+
@click.stop
|
|
912
|
+
>
|
|
913
|
+
<UTooltip :text="locale.addChildPage">
|
|
914
|
+
<UButton
|
|
915
|
+
icon="i-lucide-plus"
|
|
916
|
+
size="xs"
|
|
917
|
+
variant="ghost"
|
|
918
|
+
color="neutral"
|
|
919
|
+
@click="() => {
|
|
920
|
+
createChildPage(item.id);
|
|
921
|
+
if (!expandedIds.has(item.id)) toggleExpand(item.id);
|
|
922
|
+
}"
|
|
923
|
+
/>
|
|
924
|
+
</UTooltip>
|
|
925
|
+
<UDropdownMenu
|
|
926
|
+
:items="pageMenuItems(item.entry)"
|
|
927
|
+
:content="{ align: 'start' }"
|
|
928
|
+
>
|
|
929
|
+
<UButton
|
|
930
|
+
icon="i-lucide-ellipsis"
|
|
931
|
+
size="xs"
|
|
932
|
+
variant="ghost"
|
|
933
|
+
color="neutral"
|
|
934
|
+
/>
|
|
935
|
+
</UDropdownMenu>
|
|
936
|
+
</div>
|
|
937
|
+
</button>
|
|
938
|
+
</ANodeContextMenu>
|
|
939
|
+
</div>
|
|
940
|
+
</div>
|
|
941
|
+
|
|
942
|
+
<!-- TipTap block drag hint -->
|
|
943
|
+
<Transition name="drop-hint">
|
|
944
|
+
<div
|
|
945
|
+
v-if="tiptapDragActive"
|
|
946
|
+
class="mt-1.5 px-3 py-2 rounded-(--ui-radius) bg-(--ui-bg-elevated) ring-1 ring-(--ui-border) shadow-sm flex items-center gap-2 pointer-events-none"
|
|
947
|
+
>
|
|
948
|
+
<UIcon
|
|
949
|
+
:name="dropIndicator ? 'i-lucide-file-input' : 'i-lucide-file-plus'"
|
|
950
|
+
class="size-3.5 text-(--ui-primary) shrink-0"
|
|
951
|
+
/>
|
|
952
|
+
<span
|
|
953
|
+
v-if="dropIndicator"
|
|
954
|
+
class="text-xs text-(--ui-text-muted) truncate"
|
|
955
|
+
>
|
|
956
|
+
{{ locale.appendTo }} <span class="font-medium text-(--ui-text-highlighted)">{{ tiptapDragState?.nodeType }}</span> {{ locale.toTarget }}
|
|
957
|
+
<span class="font-medium text-(--ui-text-highlighted)">{{ treeMap.get(dropIndicator.targetId)?.label }}</span>
|
|
958
|
+
</span>
|
|
959
|
+
<span
|
|
960
|
+
v-else
|
|
961
|
+
class="text-xs text-(--ui-text-muted)"
|
|
962
|
+
>
|
|
963
|
+
{{ locale.dropToCreateSubPage }} <span class="font-medium text-(--ui-text-highlighted)">{{ tiptapDragState?.sourceDocLabel }}</span>
|
|
964
|
+
</span>
|
|
965
|
+
</div>
|
|
966
|
+
</Transition>
|
|
967
|
+
|
|
968
|
+
<!-- External file drag hint -->
|
|
969
|
+
<Transition name="drop-hint">
|
|
970
|
+
<div
|
|
971
|
+
v-if="externalDragActive"
|
|
972
|
+
class="mt-1.5 px-3 py-2 rounded-(--ui-radius) bg-(--ui-bg-elevated) ring-1 ring-(--ui-border) shadow-sm flex items-center gap-2 pointer-events-none"
|
|
973
|
+
>
|
|
974
|
+
<UIcon
|
|
975
|
+
:name="dropIndicator ? 'i-lucide-folder-input' : 'i-lucide-upload'"
|
|
976
|
+
class="size-3.5 text-(--ui-primary) shrink-0"
|
|
977
|
+
/>
|
|
978
|
+
<span
|
|
979
|
+
v-if="dropIndicator"
|
|
980
|
+
class="text-xs text-(--ui-text-muted) truncate"
|
|
981
|
+
>
|
|
982
|
+
{{ locale.dropInto }}
|
|
983
|
+
<span class="font-medium text-(--ui-text-highlighted)">{{ treeMap.get(dropIndicator.targetId)?.label }}</span>
|
|
984
|
+
</span>
|
|
985
|
+
<span
|
|
986
|
+
v-else
|
|
987
|
+
class="text-xs text-(--ui-text-muted)"
|
|
988
|
+
>
|
|
989
|
+
{{ locale.dropToImport }}
|
|
990
|
+
</span>
|
|
991
|
+
</div>
|
|
992
|
+
</Transition>
|
|
993
|
+
|
|
994
|
+
<ANodePanel
|
|
995
|
+
:node-id="openNodeId"
|
|
996
|
+
:node-label="openNodeLabel"
|
|
997
|
+
:child-provider="openNodeProvider"
|
|
998
|
+
:is-loading="nodePanelLoading"
|
|
999
|
+
@close="closePanel"
|
|
1000
|
+
/>
|
|
1001
|
+
</div>
|
|
1002
|
+
</template>
|
|
1003
|
+
|
|
1004
|
+
<style scoped>
|
|
1005
|
+
.subpage-row-actions{opacity:0;pointer-events:none;transition:opacity .1s ease}@media (hover:hover) and (pointer:fine){.subpage-item:hover .subpage-row-actions,.subpage-row-actions:has([data-state=open]){opacity:1;pointer-events:auto}}.subpage-row-actions:has([data-state=open]){opacity:1;pointer-events:auto}.drop-line{background:var(--ui-primary);border-radius:1px;height:2px;left:12px;pointer-events:none;position:absolute;right:4px;z-index:20}.drop-line-before{top:0}.drop-line-after{bottom:0}.drop-line-dot{background:var(--ui-bg);border:2px solid var(--ui-primary);border-radius:50%;height:8px;left:-3px;position:absolute;top:-3px;width:8px}.drop-inside{background:color-mix(in srgb,var(--ui-primary) 8%,transparent);border:2px solid color-mix(in srgb,var(--ui-primary) 50%,transparent);border-radius:var(--ui-radius);inset:1px 4px;pointer-events:none;position:absolute;z-index:10}.drop-hint-enter-active,.drop-hint-leave-active{transition:all .15s ease}.drop-hint-enter-from,.drop-hint-leave-to{opacity:0;transform:translateY(4px)}
|
|
1006
|
+
</style>
|