@abraca/nuxt 0.1.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/README.md +84 -0
- package/dist/module.d.mts +201 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +170 -0
- package/dist/runtime/components/ACollaborationUsers.d.vue.ts +11 -0
- package/dist/runtime/components/ACollaborationUsers.vue +48 -0
- package/dist/runtime/components/ACollaborationUsers.vue.d.ts +11 -0
- package/dist/runtime/components/AColorPicker.d.vue.ts +13 -0
- package/dist/runtime/components/AColorPicker.vue +71 -0
- package/dist/runtime/components/AColorPicker.vue.d.ts +13 -0
- package/dist/runtime/components/ACommandPalette.d.vue.ts +13 -0
- package/dist/runtime/components/ACommandPalette.vue +31 -0
- package/dist/runtime/components/ACommandPalette.vue.d.ts +13 -0
- package/dist/runtime/components/AConnectionStatus.d.vue.ts +13 -0
- package/dist/runtime/components/AConnectionStatus.vue +50 -0
- package/dist/runtime/components/AConnectionStatus.vue.d.ts +13 -0
- package/dist/runtime/components/ADocTypeSelect.d.vue.ts +10 -0
- package/dist/runtime/components/ADocTypeSelect.vue +34 -0
- package/dist/runtime/components/ADocTypeSelect.vue.d.ts +10 -0
- package/dist/runtime/components/ADocumentTree.d.vue.ts +53 -0
- package/dist/runtime/components/ADocumentTree.vue +350 -0
- package/dist/runtime/components/ADocumentTree.vue.d.ts +53 -0
- package/dist/runtime/components/AEditor.d.vue.ts +60 -0
- package/dist/runtime/components/AEditor.vue +174 -0
- package/dist/runtime/components/AEditor.vue.d.ts +60 -0
- package/dist/runtime/components/AFloatingWindow.d.vue.ts +24 -0
- package/dist/runtime/components/AFloatingWindow.vue +232 -0
- package/dist/runtime/components/AFloatingWindow.vue.d.ts +24 -0
- package/dist/runtime/components/AIconPicker.d.vue.ts +13 -0
- package/dist/runtime/components/AIconPicker.vue +257 -0
- package/dist/runtime/components/AIconPicker.vue.d.ts +13 -0
- package/dist/runtime/components/ANodePanel.d.vue.ts +15 -0
- package/dist/runtime/components/ANodePanel.vue +541 -0
- package/dist/runtime/components/ANodePanel.vue.d.ts +15 -0
- package/dist/runtime/components/ANotifications.d.vue.ts +7 -0
- package/dist/runtime/components/ANotifications.vue +75 -0
- package/dist/runtime/components/ANotifications.vue.d.ts +7 -0
- package/dist/runtime/components/APermissionGuard.d.vue.ts +21 -0
- package/dist/runtime/components/APermissionGuard.vue +22 -0
- package/dist/runtime/components/APermissionGuard.vue.d.ts +21 -0
- package/dist/runtime/components/APresence.d.vue.ts +43 -0
- package/dist/runtime/components/APresence.vue +36 -0
- package/dist/runtime/components/APresence.vue.d.ts +43 -0
- package/dist/runtime/components/AProvider.d.vue.ts +27 -0
- package/dist/runtime/components/AProvider.vue +42 -0
- package/dist/runtime/components/AProvider.vue.d.ts +27 -0
- package/dist/runtime/components/ARoleBadge.d.vue.ts +11 -0
- package/dist/runtime/components/ARoleBadge.vue +29 -0
- package/dist/runtime/components/ARoleBadge.vue.d.ts +11 -0
- package/dist/runtime/components/AVoiceBar.d.vue.ts +13 -0
- package/dist/runtime/components/AVoiceBar.vue +379 -0
- package/dist/runtime/components/AVoiceBar.vue.d.ts +13 -0
- package/dist/runtime/components/AVoiceTile.d.vue.ts +10 -0
- package/dist/runtime/components/AVoiceTile.vue +48 -0
- package/dist/runtime/components/AVoiceTile.vue.d.ts +10 -0
- package/dist/runtime/components/AWindowLayer.d.vue.ts +3 -0
- package/dist/runtime/components/AWindowLayer.vue +17 -0
- package/dist/runtime/components/AWindowLayer.vue.d.ts +3 -0
- package/dist/runtime/components/aware/AArea.d.vue.ts +42 -0
- package/dist/runtime/components/aware/AArea.vue +45 -0
- package/dist/runtime/components/aware/AArea.vue.d.ts +42 -0
- package/dist/runtime/components/aware/AAvatar.d.vue.ts +25 -0
- package/dist/runtime/components/aware/AAvatar.vue +86 -0
- package/dist/runtime/components/aware/AAvatar.vue.d.ts +25 -0
- package/dist/runtime/components/aware/AButton.d.vue.ts +7 -0
- package/dist/runtime/components/aware/AButton.vue +39 -0
- package/dist/runtime/components/aware/AButton.vue.d.ts +7 -0
- package/dist/runtime/components/aware/ACursorLabel.d.vue.ts +12 -0
- package/dist/runtime/components/aware/ACursorLabel.vue +44 -0
- package/dist/runtime/components/aware/ACursorLabel.vue.d.ts +12 -0
- package/dist/runtime/components/aware/ADocBadge.d.vue.ts +11 -0
- package/dist/runtime/components/aware/ADocBadge.vue +27 -0
- package/dist/runtime/components/aware/ADocBadge.vue.d.ts +11 -0
- package/dist/runtime/components/aware/AFacepile.d.vue.ts +20 -0
- package/dist/runtime/components/aware/AFacepile.vue +92 -0
- package/dist/runtime/components/aware/AFacepile.vue.d.ts +20 -0
- package/dist/runtime/components/aware/AInput.d.vue.ts +7 -0
- package/dist/runtime/components/aware/AInput.vue +44 -0
- package/dist/runtime/components/aware/AInput.vue.d.ts +7 -0
- package/dist/runtime/components/aware/ASelect.d.vue.ts +7 -0
- package/dist/runtime/components/aware/ASelect.vue +51 -0
- package/dist/runtime/components/aware/ASelect.vue.d.ts +7 -0
- package/dist/runtime/components/aware/ATextarea.d.vue.ts +7 -0
- package/dist/runtime/components/aware/ATextarea.vue +44 -0
- package/dist/runtime/components/aware/ATextarea.vue.d.ts +7 -0
- package/dist/runtime/components/aware/AUserList.d.vue.ts +17 -0
- package/dist/runtime/components/aware/AUserList.vue +72 -0
- package/dist/runtime/components/aware/AUserList.vue.d.ts +17 -0
- package/dist/runtime/components/renderers/ACalendarRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/ACalendarRenderer.vue +154 -0
- package/dist/runtime/components/renderers/ACalendarRenderer.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/AGalleryRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/AGalleryRenderer.vue +88 -0
- package/dist/runtime/components/renderers/AGalleryRenderer.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/AKanbanRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/AKanbanRenderer.vue +179 -0
- package/dist/runtime/components/renderers/AKanbanRenderer.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/AOutlineRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/AOutlineRenderer.vue +180 -0
- package/dist/runtime/components/renderers/AOutlineRenderer.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/ATableRenderer.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/ATableRenderer.vue +191 -0
- package/dist/runtime/components/renderers/ATableRenderer.vue.d.ts +8 -0
- package/dist/runtime/composables/useAAField.d.ts +42 -0
- package/dist/runtime/composables/useAAField.js +62 -0
- package/dist/runtime/composables/useAbraLocale.d.ts +14 -0
- package/dist/runtime/composables/useAbraLocale.js +11 -0
- package/dist/runtime/composables/useAbracadabra.d.ts +11 -0
- package/dist/runtime/composables/useAbracadabra.js +3 -0
- package/dist/runtime/composables/useAbracadabraAuth.d.ts +23 -0
- package/dist/runtime/composables/useAbracadabraAuth.js +22 -0
- package/dist/runtime/composables/useAwareness.d.ts +22 -0
- package/dist/runtime/composables/useAwareness.js +48 -0
- package/dist/runtime/composables/useAwarenessPeers.d.ts +34 -0
- package/dist/runtime/composables/useAwarenessPeers.js +33 -0
- package/dist/runtime/composables/useBackgroundSync.d.ts +37 -0
- package/dist/runtime/composables/useBackgroundSync.js +73 -0
- package/dist/runtime/composables/useChat.d.ts +65 -0
- package/dist/runtime/composables/useChat.js +210 -0
- package/dist/runtime/composables/useChatUsers.d.ts +21 -0
- package/dist/runtime/composables/useChatUsers.js +39 -0
- package/dist/runtime/composables/useChildTree.d.ts +119 -0
- package/dist/runtime/composables/useChildTree.js +100 -0
- package/dist/runtime/composables/useCommandPalette.d.ts +58 -0
- package/dist/runtime/composables/useCommandPalette.js +94 -0
- package/dist/runtime/composables/useConnectionStatus.d.ts +17 -0
- package/dist/runtime/composables/useConnectionStatus.js +37 -0
- package/dist/runtime/composables/useDashboard.d.ts +3 -0
- package/dist/runtime/composables/useDashboard.js +23 -0
- package/dist/runtime/composables/useDocExport.d.ts +5 -0
- package/dist/runtime/composables/useDocExport.js +256 -0
- package/dist/runtime/composables/useDocImport.d.ts +10 -0
- package/dist/runtime/composables/useDocImport.js +227 -0
- package/dist/runtime/composables/useDocJump.d.ts +29 -0
- package/dist/runtime/composables/useDocJump.js +17 -0
- package/dist/runtime/composables/useDocumentPermissions.d.ts +20 -0
- package/dist/runtime/composables/useDocumentPermissions.js +33 -0
- package/dist/runtime/composables/useEditor.d.ts +45 -0
- package/dist/runtime/composables/useEditor.js +121 -0
- package/dist/runtime/composables/useEditorDragHandle.d.ts +26 -0
- package/dist/runtime/composables/useEditorDragHandle.js +219 -0
- package/dist/runtime/composables/useEditorMentions.d.ts +28 -0
- package/dist/runtime/composables/useEditorMentions.js +40 -0
- package/dist/runtime/composables/useEditorSuggestions.d.ts +18 -0
- package/dist/runtime/composables/useEditorSuggestions.js +45 -0
- package/dist/runtime/composables/useEditorToolbar.d.ts +22 -0
- package/dist/runtime/composables/useEditorToolbar.js +60 -0
- package/dist/runtime/composables/useFileBlobStore.d.ts +15 -0
- package/dist/runtime/composables/useFileBlobStore.js +22 -0
- package/dist/runtime/composables/useFileIndex.d.ts +20 -0
- package/dist/runtime/composables/useFileIndex.js +69 -0
- package/dist/runtime/composables/useFollowUser.d.ts +5 -0
- package/dist/runtime/composables/useFollowUser.js +40 -0
- package/dist/runtime/composables/useNotifications.d.ts +82 -0
- package/dist/runtime/composables/useNotifications.js +171 -0
- package/dist/runtime/composables/useOfflineUploadQueue.d.ts +90 -0
- package/dist/runtime/composables/useOfflineUploadQueue.js +33 -0
- package/dist/runtime/composables/usePasskeyAccounts.d.ts +32 -0
- package/dist/runtime/composables/usePasskeyAccounts.js +46 -0
- package/dist/runtime/composables/usePluginRegistry.d.ts +6 -0
- package/dist/runtime/composables/usePluginRegistry.js +3 -0
- package/dist/runtime/composables/useRendererBase.d.ts +186 -0
- package/dist/runtime/composables/useRendererBase.js +46 -0
- package/dist/runtime/composables/useSearchIndex.d.ts +20 -0
- package/dist/runtime/composables/useSearchIndex.js +104 -0
- package/dist/runtime/composables/useTrash.d.ts +50 -0
- package/dist/runtime/composables/useTrash.js +127 -0
- package/dist/runtime/composables/useVoice.d.ts +51 -0
- package/dist/runtime/composables/useVoice.js +220 -0
- package/dist/runtime/composables/useWindowManager.d.ts +122 -0
- package/dist/runtime/composables/useWindowManager.js +141 -0
- package/dist/runtime/composables/useYDoc.d.ts +142 -0
- package/dist/runtime/composables/useYDoc.js +172 -0
- package/dist/runtime/extensions/accordion.d.ts +3 -0
- package/dist/runtime/extensions/accordion.js +49 -0
- package/dist/runtime/extensions/badge.d.ts +2 -0
- package/dist/runtime/extensions/badge.js +39 -0
- package/dist/runtime/extensions/callout.d.ts +2 -0
- package/dist/runtime/extensions/callout.js +28 -0
- package/dist/runtime/extensions/card.d.ts +3 -0
- package/dist/runtime/extensions/card.js +53 -0
- package/dist/runtime/extensions/code-collapse.d.ts +2 -0
- package/dist/runtime/extensions/code-collapse.js +32 -0
- package/dist/runtime/extensions/code-group.d.ts +2 -0
- package/dist/runtime/extensions/code-group.js +17 -0
- package/dist/runtime/extensions/collapsible.d.ts +2 -0
- package/dist/runtime/extensions/collapsible.js +35 -0
- package/dist/runtime/extensions/document-header.d.ts +11 -0
- package/dist/runtime/extensions/document-header.js +82 -0
- package/dist/runtime/extensions/document-meta.d.ts +20 -0
- package/dist/runtime/extensions/document-meta.js +121 -0
- package/dist/runtime/extensions/document.d.ts +6 -0
- package/dist/runtime/extensions/document.js +6 -0
- package/dist/runtime/extensions/file-block.d.ts +15 -0
- package/dist/runtime/extensions/file-block.js +34 -0
- package/dist/runtime/extensions/file-drop.d.ts +6 -0
- package/dist/runtime/extensions/file-drop.js +65 -0
- package/dist/runtime/extensions/kbd.d.ts +2 -0
- package/dist/runtime/extensions/kbd.js +33 -0
- package/dist/runtime/extensions/prose-icon.d.ts +2 -0
- package/dist/runtime/extensions/prose-icon.js +33 -0
- package/dist/runtime/extensions/search-highlight.d.ts +10 -0
- package/dist/runtime/extensions/search-highlight.js +129 -0
- package/dist/runtime/extensions/steps.d.ts +2 -0
- package/dist/runtime/extensions/steps.js +32 -0
- package/dist/runtime/extensions/tabs.d.ts +3 -0
- package/dist/runtime/extensions/tabs.js +49 -0
- package/dist/runtime/extensions/views/AccordionItemView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/AccordionItemView.vue +41 -0
- package/dist/runtime/extensions/views/AccordionItemView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/AccordionView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/AccordionView.vue +22 -0
- package/dist/runtime/extensions/views/AccordionView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/BadgeView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/BadgeView.vue +23 -0
- package/dist/runtime/extensions/views/BadgeView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CalloutView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CalloutView.vue +43 -0
- package/dist/runtime/extensions/views/CalloutView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CardGroupView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CardGroupView.vue +22 -0
- package/dist/runtime/extensions/views/CardGroupView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CardView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CardView.vue +28 -0
- package/dist/runtime/extensions/views/CardView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CodeCollapseView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CodeCollapseView.vue +45 -0
- package/dist/runtime/extensions/views/CodeCollapseView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CodeGroupView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CodeGroupView.vue +53 -0
- package/dist/runtime/extensions/views/CodeGroupView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/CollapsibleView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/CollapsibleView.vue +42 -0
- package/dist/runtime/extensions/views/CollapsibleView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/FileNodeView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/FileNodeView.vue +140 -0
- package/dist/runtime/extensions/views/FileNodeView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/KbdView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/KbdView.vue +23 -0
- package/dist/runtime/extensions/views/KbdView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/ProseIconView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/ProseIconView.vue +23 -0
- package/dist/runtime/extensions/views/ProseIconView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/StepsView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/StepsView.vue +32 -0
- package/dist/runtime/extensions/views/StepsView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/TabsItemView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/TabsItemView.vue +22 -0
- package/dist/runtime/extensions/views/TabsItemView.vue.d.ts +4 -0
- package/dist/runtime/extensions/views/TabsView.d.vue.ts +4 -0
- package/dist/runtime/extensions/views/TabsView.vue +56 -0
- package/dist/runtime/extensions/views/TabsView.vue.d.ts +4 -0
- package/dist/runtime/locale.d.ts +134 -0
- package/dist/runtime/locale.js +119 -0
- package/dist/runtime/middleware/abracadabra-auth.d.ts +11 -0
- package/dist/runtime/middleware/abracadabra-auth.js +9 -0
- package/dist/runtime/plugin-abracadabra.client.d.ts +7 -0
- package/dist/runtime/plugin-abracadabra.client.js +898 -0
- package/dist/runtime/plugin-abracadabra.server.d.ts +2 -0
- package/dist/runtime/plugin-abracadabra.server.js +71 -0
- package/dist/runtime/plugin-registry.d.ts +34 -0
- package/dist/runtime/plugin-registry.js +83 -0
- package/dist/runtime/plugin-shared-globals.client.d.ts +2 -0
- package/dist/runtime/plugin-shared-globals.client.js +20 -0
- package/dist/runtime/plugins/core.plugin.d.ts +12 -0
- package/dist/runtime/plugins/core.plugin.js +179 -0
- package/dist/runtime/server/api/_abracadabra/render/[docId].get.d.ts +18 -0
- package/dist/runtime/server/api/_abracadabra/render/[docId].get.js +51 -0
- package/dist/runtime/server/api/_abracadabra/spaces.get.d.ts +11 -0
- package/dist/runtime/server/api/_abracadabra/spaces.get.js +16 -0
- package/dist/runtime/server/plugins/abracadabra-service.d.ts +2 -0
- package/dist/runtime/server/plugins/abracadabra-service.js +116 -0
- package/dist/runtime/server/runners/doc-tree-cache.d.ts +11 -0
- package/dist/runtime/server/runners/doc-tree-cache.js +65 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/docCache.d.ts +25 -0
- package/dist/runtime/server/utils/docCache.js +131 -0
- package/dist/runtime/server/utils/serverRunner.d.ts +28 -0
- package/dist/runtime/server/utils/serverRunner.js +58 -0
- package/dist/runtime/types.d.ts +444 -0
- package/dist/runtime/types.js +93 -0
- package/dist/runtime/utils/VoiceClient.d.ts +94 -0
- package/dist/runtime/utils/VoiceClient.js +599 -0
- package/dist/runtime/utils/avatarStyle.d.ts +15 -0
- package/dist/runtime/utils/avatarStyle.js +20 -0
- package/dist/runtime/utils/colorPalettes.d.ts +13 -0
- package/dist/runtime/utils/colorPalettes.js +49 -0
- package/dist/runtime/utils/docTypes.d.ts +129 -0
- package/dist/runtime/utils/docTypes.js +116 -0
- package/dist/runtime/utils/markdownToYjs.d.ts +23 -0
- package/dist/runtime/utils/markdownToYjs.js +440 -0
- package/dist/runtime/utils/metaFieldDefinitions.d.ts +7 -0
- package/dist/runtime/utils/metaFieldDefinitions.js +182 -0
- package/dist/runtime/utils/voiceErrors.d.ts +33 -0
- package/dist/runtime/utils/voiceErrors.js +54 -0
- package/dist/runtime/utils/yjsConvert.d.ts +14 -0
- package/dist/runtime/utils/yjsConvert.js +331 -0
- package/dist/types.d.mts +13 -0
- package/package.json +100 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { useSyncedMap } from "./useYDoc.js";
|
|
3
|
+
export function useChildTree(rootDoc, parentDocId) {
|
|
4
|
+
const treeMap = useSyncedMap(rootDoc, "doc-tree");
|
|
5
|
+
const trashMap = useSyncedMap(rootDoc, "doc-trash");
|
|
6
|
+
const entries = computed(
|
|
7
|
+
() => Object.entries(treeMap.data).map(([id, v]) => ({
|
|
8
|
+
id,
|
|
9
|
+
label: v.label || "Untitled",
|
|
10
|
+
parentId: v.parentId ?? null,
|
|
11
|
+
order: v.order ?? 0,
|
|
12
|
+
type: v.type,
|
|
13
|
+
meta: v.meta,
|
|
14
|
+
createdAt: v.createdAt,
|
|
15
|
+
updatedAt: v.updatedAt
|
|
16
|
+
}))
|
|
17
|
+
);
|
|
18
|
+
function childrenOf(parentId) {
|
|
19
|
+
const target = parentId === null ? parentDocId : parentId;
|
|
20
|
+
return entries.value.filter((e) => e.parentId === target).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
21
|
+
}
|
|
22
|
+
function descendantsOf(id) {
|
|
23
|
+
const result = [];
|
|
24
|
+
function collect(pid) {
|
|
25
|
+
for (const child of childrenOf(pid)) {
|
|
26
|
+
result.push(child);
|
|
27
|
+
collect(child.id);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
collect(id);
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
function createChild(parentId, label, type) {
|
|
34
|
+
const id = crypto.randomUUID();
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
treeMap.set(id, {
|
|
37
|
+
label,
|
|
38
|
+
parentId: parentId === null ? parentDocId : parentId,
|
|
39
|
+
order: now,
|
|
40
|
+
type,
|
|
41
|
+
createdAt: now,
|
|
42
|
+
updatedAt: now
|
|
43
|
+
});
|
|
44
|
+
return id;
|
|
45
|
+
}
|
|
46
|
+
function moveEntry(id, newParentId, newOrder) {
|
|
47
|
+
const entry = treeMap.get(id);
|
|
48
|
+
if (entry) {
|
|
49
|
+
treeMap.set(id, {
|
|
50
|
+
...entry,
|
|
51
|
+
parentId: newParentId === null ? parentDocId : newParentId,
|
|
52
|
+
order: newOrder,
|
|
53
|
+
updatedAt: Date.now()
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function deleteEntry(id) {
|
|
58
|
+
const doc = rootDoc.value;
|
|
59
|
+
if (!doc) return;
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
const toDelete = [id, ...descendantsOf(id).map((e) => e.id)];
|
|
62
|
+
doc.transact(() => {
|
|
63
|
+
for (const nid of toDelete) {
|
|
64
|
+
const entry = treeMap.get(nid);
|
|
65
|
+
if (!entry) continue;
|
|
66
|
+
trashMap.set(nid, { label: entry.label || "Untitled", parentId: entry.parentId ?? null, order: entry.order ?? 0, type: entry.type, meta: entry.meta, deletedAt: now });
|
|
67
|
+
treeMap.remove(nid);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function renameEntry(id, label) {
|
|
72
|
+
const entry = treeMap.get(id);
|
|
73
|
+
if (entry) treeMap.set(id, { ...entry, label, updatedAt: Date.now() });
|
|
74
|
+
}
|
|
75
|
+
function updateMeta(id, patch) {
|
|
76
|
+
const entry = treeMap.get(id);
|
|
77
|
+
if (!entry) return;
|
|
78
|
+
treeMap.set(id, { ...entry, meta: { ...entry.meta ?? {}, ...patch }, updatedAt: Date.now() });
|
|
79
|
+
}
|
|
80
|
+
function duplicateEntry(id) {
|
|
81
|
+
const entry = treeMap.get(id);
|
|
82
|
+
if (!entry) return id;
|
|
83
|
+
const newId = crypto.randomUUID();
|
|
84
|
+
treeMap.set(newId, { ...entry, label: (entry.label || "Untitled") + " (copy)", order: Date.now() });
|
|
85
|
+
return newId;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
entries,
|
|
89
|
+
childrenOf,
|
|
90
|
+
descendantsOf,
|
|
91
|
+
createChild,
|
|
92
|
+
moveEntry,
|
|
93
|
+
deleteEntry,
|
|
94
|
+
renameEntry,
|
|
95
|
+
updateMeta,
|
|
96
|
+
duplicateEntry,
|
|
97
|
+
treeMap,
|
|
98
|
+
trashMap
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useCommandPalette
|
|
3
|
+
*
|
|
4
|
+
* ⌘K command palette state and item provider.
|
|
5
|
+
* Aggregates commands from the plugin registry, the document tree, search results,
|
|
6
|
+
* and recent documents.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const { isOpen, searchTerm, toggle, groups } = useCommandPalette()
|
|
10
|
+
* <UCommandPalette v-model:open="isOpen" v-model="searchTerm" :groups="groups" />
|
|
11
|
+
*/
|
|
12
|
+
export interface CommandItem {
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
icon?: string;
|
|
16
|
+
suffix?: string;
|
|
17
|
+
shortcut?: string[];
|
|
18
|
+
onClick?: () => void;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface CommandGroup {
|
|
22
|
+
id: string;
|
|
23
|
+
label?: string;
|
|
24
|
+
items: CommandItem[];
|
|
25
|
+
}
|
|
26
|
+
export declare function useCommandPalette(): {
|
|
27
|
+
isOpen: import("vue").Ref<boolean, boolean>;
|
|
28
|
+
searchTerm: import("vue").Ref<string, string>;
|
|
29
|
+
groups: import("vue").Ref<{
|
|
30
|
+
id: string;
|
|
31
|
+
label?: string | undefined;
|
|
32
|
+
items: {
|
|
33
|
+
id: string;
|
|
34
|
+
label: string;
|
|
35
|
+
icon?: string | undefined;
|
|
36
|
+
suffix?: string | undefined;
|
|
37
|
+
shortcut?: string[] | undefined;
|
|
38
|
+
onClick?: (() => void) | undefined;
|
|
39
|
+
disabled?: boolean | undefined;
|
|
40
|
+
}[];
|
|
41
|
+
}[], CommandGroup[] | {
|
|
42
|
+
id: string;
|
|
43
|
+
label?: string | undefined;
|
|
44
|
+
items: {
|
|
45
|
+
id: string;
|
|
46
|
+
label: string;
|
|
47
|
+
icon?: string | undefined;
|
|
48
|
+
suffix?: string | undefined;
|
|
49
|
+
shortcut?: string[] | undefined;
|
|
50
|
+
onClick?: (() => void) | undefined;
|
|
51
|
+
disabled?: boolean | undefined;
|
|
52
|
+
}[];
|
|
53
|
+
}[]>;
|
|
54
|
+
open: (term?: string) => void;
|
|
55
|
+
close: () => void;
|
|
56
|
+
toggle: () => void;
|
|
57
|
+
trackRecentDoc: (docId: string) => void;
|
|
58
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ref, watch } from "vue";
|
|
2
|
+
import { useLocalStorage } from "@vueuse/core";
|
|
3
|
+
const isOpen = ref(false);
|
|
4
|
+
const searchTerm = ref("");
|
|
5
|
+
export function useCommandPalette() {
|
|
6
|
+
const { doc, isReady, provider } = useAbracadabra();
|
|
7
|
+
const registry = usePluginRegistry();
|
|
8
|
+
const recentDocIds = useLocalStorage("abra_recent_docs", []);
|
|
9
|
+
function open(term = "") {
|
|
10
|
+
searchTerm.value = term;
|
|
11
|
+
isOpen.value = true;
|
|
12
|
+
}
|
|
13
|
+
function close() {
|
|
14
|
+
isOpen.value = false;
|
|
15
|
+
searchTerm.value = "";
|
|
16
|
+
}
|
|
17
|
+
function toggle() {
|
|
18
|
+
if (isOpen.value) close();
|
|
19
|
+
else open();
|
|
20
|
+
}
|
|
21
|
+
function trackRecentDoc(docId) {
|
|
22
|
+
recentDocIds.value = [docId, ...recentDocIds.value.filter((x) => x !== docId)].slice(0, 10);
|
|
23
|
+
}
|
|
24
|
+
const groups = ref([]);
|
|
25
|
+
async function _refreshGroups() {
|
|
26
|
+
if (!isReady.value) {
|
|
27
|
+
groups.value = [];
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const q = searchTerm.value.toLowerCase().trim();
|
|
31
|
+
const result = [];
|
|
32
|
+
if (doc.value) {
|
|
33
|
+
try {
|
|
34
|
+
const treeMap = doc.value.getMap("doc-tree");
|
|
35
|
+
const entries = [];
|
|
36
|
+
treeMap.forEach((entry, id) => {
|
|
37
|
+
if (!entry.label) return;
|
|
38
|
+
if (q && !entry.label.toLowerCase().includes(q)) return;
|
|
39
|
+
entries.push({
|
|
40
|
+
id: `doc:${id}`,
|
|
41
|
+
label: entry.label,
|
|
42
|
+
icon: "i-lucide-file-text",
|
|
43
|
+
suffix: entry.type,
|
|
44
|
+
onClick: () => {
|
|
45
|
+
trackRecentDoc(id);
|
|
46
|
+
navigateTo(`${useRuntimeConfig().public.abracadabra?.docBasePath ?? "/doc"}/${id}`);
|
|
47
|
+
close();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
const sorted = q ? entries : entries.filter((e) => recentDocIds.value.includes(e.id.slice(4))).slice(0, 5);
|
|
52
|
+
if (sorted.length > 0) {
|
|
53
|
+
result.push({ id: "docs", label: q ? "Documents" : "Recent", items: sorted });
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const ctx = { doc, provider, abracadabra: useAbracadabra(), searchTerm: searchTerm.value };
|
|
60
|
+
const pluginGroups = await registry.getAllCommandPaletteItems(ctx);
|
|
61
|
+
for (const group of pluginGroups) {
|
|
62
|
+
const filtered = (group.items ?? []).filter((item) => !q || item.label?.toLowerCase().includes(q)).map((item) => ({
|
|
63
|
+
id: item.id ?? `${group.id ?? "plugin"}:${item.label}`,
|
|
64
|
+
label: item.label,
|
|
65
|
+
icon: item.icon,
|
|
66
|
+
suffix: item.suffix,
|
|
67
|
+
shortcut: item.shortcut,
|
|
68
|
+
onClick: () => {
|
|
69
|
+
item.action?.();
|
|
70
|
+
close();
|
|
71
|
+
},
|
|
72
|
+
disabled: item.disabled
|
|
73
|
+
}));
|
|
74
|
+
if (filtered.length > 0) {
|
|
75
|
+
result.push({ id: group.id ?? "plugin", label: group.label, items: filtered });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} catch {
|
|
79
|
+
}
|
|
80
|
+
groups.value = result;
|
|
81
|
+
}
|
|
82
|
+
watch([isOpen, searchTerm, isReady], () => {
|
|
83
|
+
if (isOpen.value) _refreshGroups();
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
isOpen,
|
|
87
|
+
searchTerm,
|
|
88
|
+
groups,
|
|
89
|
+
open,
|
|
90
|
+
close,
|
|
91
|
+
toggle,
|
|
92
|
+
trackRecentDoc
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
type ConnectionStatusValue = 'disconnected' | 'connecting' | 'connected' | 'offline';
|
|
3
|
+
/**
|
|
4
|
+
* Maps connection status + synced state to UI-ready label, color, and icon.
|
|
5
|
+
*
|
|
6
|
+
* If `status` and `synced` are not provided, reads from `useAbracadabra()` globals.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const { label, color, icon } = useConnectionStatus()
|
|
10
|
+
* const { label, color, icon } = useConnectionStatus(status, synced)
|
|
11
|
+
*/
|
|
12
|
+
export declare function useConnectionStatus(status?: MaybeRef<ConnectionStatusValue | string | undefined>, synced?: MaybeRef<boolean | undefined>): {
|
|
13
|
+
label: import("vue").ComputedRef<string>;
|
|
14
|
+
color: import("vue").ComputedRef<"success" | "warning" | "error">;
|
|
15
|
+
icon: import("vue").ComputedRef<"i-lucide-cloud-check" | "i-lucide-cloud-upload" | "i-lucide-cloud" | "i-lucide-cloud-off">;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { computed, toValue } from "vue";
|
|
2
|
+
import { useAbraLocale } from "./useAbraLocale.js";
|
|
3
|
+
import { useAbracadabra } from "./useAbracadabra.js";
|
|
4
|
+
export function useConnectionStatus(status, synced) {
|
|
5
|
+
const locale = useAbraLocale("connectionStatus");
|
|
6
|
+
const abra = useAbracadabra();
|
|
7
|
+
const resolvedStatus = computed(() => {
|
|
8
|
+
if (status !== void 0) return toValue(status) ?? "disconnected";
|
|
9
|
+
return abra.status?.value ?? "disconnected";
|
|
10
|
+
});
|
|
11
|
+
const resolvedSynced = computed(() => {
|
|
12
|
+
if (synced !== void 0) return toValue(synced) ?? false;
|
|
13
|
+
return abra.synced?.value ?? false;
|
|
14
|
+
});
|
|
15
|
+
const label = computed(() => {
|
|
16
|
+
const s = resolvedStatus.value;
|
|
17
|
+
if (s === "connected" && resolvedSynced.value) return locale.connected;
|
|
18
|
+
if (s === "connected") return locale.syncing;
|
|
19
|
+
if (s === "connecting") return locale.connecting;
|
|
20
|
+
return locale.offline;
|
|
21
|
+
});
|
|
22
|
+
const color = computed(() => {
|
|
23
|
+
const s = resolvedStatus.value;
|
|
24
|
+
if (s === "connected" && resolvedSynced.value) return "success";
|
|
25
|
+
if (s === "connected") return "warning";
|
|
26
|
+
if (s === "connecting") return "warning";
|
|
27
|
+
return "error";
|
|
28
|
+
});
|
|
29
|
+
const icon = computed(() => {
|
|
30
|
+
const s = resolvedStatus.value;
|
|
31
|
+
if (s === "connected" && resolvedSynced.value) return "i-lucide-cloud-check";
|
|
32
|
+
if (s === "connected") return "i-lucide-cloud-upload";
|
|
33
|
+
if (s === "connecting") return "i-lucide-cloud";
|
|
34
|
+
return "i-lucide-cloud-off";
|
|
35
|
+
});
|
|
36
|
+
return { label, color, icon };
|
|
37
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ref, watch } from "vue";
|
|
2
|
+
import { createSharedComposable } from "@vueuse/core";
|
|
3
|
+
const _useDashboard = () => {
|
|
4
|
+
const route = useRoute();
|
|
5
|
+
const { toggle } = useCommandPalette();
|
|
6
|
+
const isNotificationsOpen = ref(false);
|
|
7
|
+
defineShortcuts({
|
|
8
|
+
meta_f: () => {
|
|
9
|
+
toggle();
|
|
10
|
+
},
|
|
11
|
+
meta_n: () => {
|
|
12
|
+
toggle();
|
|
13
|
+
},
|
|
14
|
+
n: () => {
|
|
15
|
+
isNotificationsOpen.value = !isNotificationsOpen.value;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
watch(() => route.fullPath, () => {
|
|
19
|
+
isNotificationsOpen.value = false;
|
|
20
|
+
});
|
|
21
|
+
return { isNotificationsOpen };
|
|
22
|
+
};
|
|
23
|
+
export const useDashboard = createSharedComposable(_useDashboard);
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import { yjsToMarkdown, yjsToHtml } from "../utils/yjsConvert.js";
|
|
3
|
+
function labelToFilename(label) {
|
|
4
|
+
return label.toLowerCase().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "") || "untitled";
|
|
5
|
+
}
|
|
6
|
+
function triggerDownload(blob, filename) {
|
|
7
|
+
const url = URL.createObjectURL(blob);
|
|
8
|
+
const a = document.createElement("a");
|
|
9
|
+
a.href = url;
|
|
10
|
+
a.download = filename;
|
|
11
|
+
a.click();
|
|
12
|
+
URL.revokeObjectURL(url);
|
|
13
|
+
}
|
|
14
|
+
function collectFileBlocks(el, sourceDocId) {
|
|
15
|
+
const files = [];
|
|
16
|
+
for (const child of el.toArray()) {
|
|
17
|
+
if (child instanceof Y.XmlElement) {
|
|
18
|
+
if (child.nodeName === "fileBlock") {
|
|
19
|
+
const uploadId = child.getAttribute("uploadId");
|
|
20
|
+
const filename = child.getAttribute("filename") ?? "file";
|
|
21
|
+
const mimeType = child.getAttribute("mimeType") ?? "";
|
|
22
|
+
const docId = child.getAttribute("docId") ?? sourceDocId;
|
|
23
|
+
if (uploadId) files.push({ uploadId, docId, filename, mimeType });
|
|
24
|
+
}
|
|
25
|
+
files.push(...collectFileBlocks(child, sourceDocId));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return files;
|
|
29
|
+
}
|
|
30
|
+
function replaceFileMarkers(content, docZipPath, filePathMap, format) {
|
|
31
|
+
return content.replace(/<!--fileblock:([^:]+):(.+?)-->/g, (_, uploadId, filename) => {
|
|
32
|
+
const entry = filePathMap.get(uploadId);
|
|
33
|
+
if (!entry) return `<!-- file: ${filename} -->`;
|
|
34
|
+
const docDir = docZipPath.includes("/") ? docZipPath.substring(0, docZipPath.lastIndexOf("/")) : "";
|
|
35
|
+
const depth = docDir ? docDir.split("/").length : 0;
|
|
36
|
+
const relPath = "../".repeat(depth) + entry.zipPath;
|
|
37
|
+
if (format === "md") {
|
|
38
|
+
if (entry.mimeType.startsWith("image/")) return ``;
|
|
39
|
+
return `[${filename}](${relPath})`;
|
|
40
|
+
} else {
|
|
41
|
+
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
42
|
+
const escapedPath = relPath.replace(/"/g, """);
|
|
43
|
+
if (entry.mimeType.startsWith("image/")) return `<img src="${escapedPath}" alt="${esc(filename)}">`;
|
|
44
|
+
return `<a href="${escapedPath}" download>${esc(filename)}</a>`;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export function useDocExport() {
|
|
49
|
+
const toast = useToast();
|
|
50
|
+
const { provider, client } = useAbracadabra();
|
|
51
|
+
function getTreeMap() {
|
|
52
|
+
const p = provider.value;
|
|
53
|
+
if (!p?.document) return null;
|
|
54
|
+
const ymap = p.document.getMap("doc-tree");
|
|
55
|
+
const result = {};
|
|
56
|
+
ymap.forEach((v, k) => {
|
|
57
|
+
result[k] = v;
|
|
58
|
+
});
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
function getDescendants(treeMap, rootId) {
|
|
62
|
+
const result = [];
|
|
63
|
+
const queue = [rootId];
|
|
64
|
+
while (queue.length) {
|
|
65
|
+
const id = queue.shift();
|
|
66
|
+
result.push(id);
|
|
67
|
+
for (const [childId, entry] of Object.entries(treeMap)) {
|
|
68
|
+
if (entry.parentId === id) queue.push(childId);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
function buildPath(treeMap, id, ext) {
|
|
74
|
+
const segments = [];
|
|
75
|
+
let current = id;
|
|
76
|
+
while (current) {
|
|
77
|
+
const entry = treeMap[current];
|
|
78
|
+
if (!entry) break;
|
|
79
|
+
segments.unshift(labelToFilename(entry.label));
|
|
80
|
+
current = entry.parentId;
|
|
81
|
+
}
|
|
82
|
+
if (segments.length) segments[segments.length - 1] += `.${ext}`;
|
|
83
|
+
return segments.join("/");
|
|
84
|
+
}
|
|
85
|
+
async function loadDoc(id, format) {
|
|
86
|
+
const p = provider.value;
|
|
87
|
+
if (!p) throw new Error("no provider");
|
|
88
|
+
const treeMap = getTreeMap() ?? {};
|
|
89
|
+
const entry = treeMap[id];
|
|
90
|
+
if (!entry) throw new Error(`doc ${id} not in tree`);
|
|
91
|
+
const childProv = await p.loadChild(id);
|
|
92
|
+
if (!childProv.isSynced) {
|
|
93
|
+
await new Promise((resolve) => {
|
|
94
|
+
const done = () => {
|
|
95
|
+
childProv.off("synced", done);
|
|
96
|
+
resolve();
|
|
97
|
+
};
|
|
98
|
+
childProv.on("synced", done);
|
|
99
|
+
setTimeout(resolve, 6e3);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const fragment = childProv.document.getXmlFragment("default");
|
|
103
|
+
const files = collectFileBlocks(fragment, id);
|
|
104
|
+
const content = format === "html" ? yjsToHtml(fragment, entry.label) : yjsToMarkdown(fragment, entry.label, entry.meta, entry.type);
|
|
105
|
+
return { content, files };
|
|
106
|
+
}
|
|
107
|
+
async function downloadFiles(files) {
|
|
108
|
+
const c = client.value;
|
|
109
|
+
if (!c) return /* @__PURE__ */ new Map();
|
|
110
|
+
const blobs = /* @__PURE__ */ new Map();
|
|
111
|
+
const unique = files.filter((f, i, arr) => arr.findIndex((x) => x.uploadId === f.uploadId) === i);
|
|
112
|
+
await Promise.all(unique.map(async (file) => {
|
|
113
|
+
try {
|
|
114
|
+
const blob = await c.getUpload(file.docId, file.uploadId);
|
|
115
|
+
blobs.set(file.uploadId, blob);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
console.warn(`[export] Failed to download file ${file.filename}:`, e);
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
120
|
+
return blobs;
|
|
121
|
+
}
|
|
122
|
+
async function exportDoc(id, format) {
|
|
123
|
+
if (!provider.value) return;
|
|
124
|
+
const treeMap = getTreeMap() ?? {};
|
|
125
|
+
const entry = treeMap[id];
|
|
126
|
+
if (!entry) return;
|
|
127
|
+
const hasChildren = Object.values(treeMap).some((e) => e.parentId === id);
|
|
128
|
+
if (format === "zip" || hasChildren) {
|
|
129
|
+
return exportDocs([id], format === "zip" ? "md" : format);
|
|
130
|
+
}
|
|
131
|
+
const fmt = format;
|
|
132
|
+
const ext = fmt === "md" ? "md" : "html";
|
|
133
|
+
const toastRef = toast.add({ title: "Exporting\u2026", icon: "i-lucide-loader" });
|
|
134
|
+
try {
|
|
135
|
+
const { content, files } = await loadDoc(id, fmt);
|
|
136
|
+
if (files.length === 0 || !client.value) {
|
|
137
|
+
toast.remove(toastRef.id);
|
|
138
|
+
const blob = new Blob([content], { type: "text/plain;charset=utf-8" });
|
|
139
|
+
triggerDownload(blob, `${labelToFilename(entry.label)}.${ext}`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const filePathMap = /* @__PURE__ */ new Map();
|
|
143
|
+
const usedNames = /* @__PURE__ */ new Map();
|
|
144
|
+
for (const file of files) {
|
|
145
|
+
if (filePathMap.has(file.uploadId)) continue;
|
|
146
|
+
let name = file.filename;
|
|
147
|
+
const count = usedNames.get(name) ?? 0;
|
|
148
|
+
if (count > 0) {
|
|
149
|
+
const dotIdx = name.lastIndexOf(".");
|
|
150
|
+
const base = dotIdx > 0 ? name.slice(0, dotIdx) : name;
|
|
151
|
+
const extPart = dotIdx > 0 ? name.slice(dotIdx) : "";
|
|
152
|
+
name = `${base}-${count + 1}${extPart}`;
|
|
153
|
+
}
|
|
154
|
+
usedNames.set(file.filename, count + 1);
|
|
155
|
+
filePathMap.set(file.uploadId, { zipPath: `_files/${name}`, mimeType: file.mimeType });
|
|
156
|
+
}
|
|
157
|
+
const fileBlobs = await downloadFiles(files);
|
|
158
|
+
const docPath = `${labelToFilename(entry.label)}.${ext}`;
|
|
159
|
+
const processed = replaceFileMarkers(content, docPath, filePathMap, fmt);
|
|
160
|
+
const JSZip = (await import("jszip")).default;
|
|
161
|
+
const zip = new JSZip();
|
|
162
|
+
zip.file(docPath, processed);
|
|
163
|
+
for (const [uploadId, info] of filePathMap) {
|
|
164
|
+
const blob = fileBlobs.get(uploadId);
|
|
165
|
+
if (blob) zip.file(info.zipPath, blob);
|
|
166
|
+
}
|
|
167
|
+
const zipBlob = await zip.generateAsync({ type: "blob" });
|
|
168
|
+
toast.remove(toastRef.id);
|
|
169
|
+
triggerDownload(zipBlob, `${labelToFilename(entry.label)}.zip`);
|
|
170
|
+
toast.add({ title: "Export complete", icon: "i-lucide-check" });
|
|
171
|
+
} catch (e) {
|
|
172
|
+
toast.remove(toastRef.id);
|
|
173
|
+
toast.add({ title: "Export failed", color: "error", icon: "i-lucide-x" });
|
|
174
|
+
console.error("[export]", e);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function exportDocs(ids, format = "md") {
|
|
178
|
+
if (!provider.value) return;
|
|
179
|
+
const treeMap = getTreeMap() ?? {};
|
|
180
|
+
const ext = format === "md" ? "md" : "html";
|
|
181
|
+
const toastRef = toast.add({ title: "Exporting\u2026", icon: "i-lucide-loader" });
|
|
182
|
+
try {
|
|
183
|
+
const allIds = /* @__PURE__ */ new Set();
|
|
184
|
+
for (const id of ids) {
|
|
185
|
+
for (const did of getDescendants(treeMap, id)) allIds.add(did);
|
|
186
|
+
}
|
|
187
|
+
const pathMap = /* @__PURE__ */ new Map();
|
|
188
|
+
for (const id of allIds) {
|
|
189
|
+
pathMap.set(id, buildPath(treeMap, id, ext));
|
|
190
|
+
}
|
|
191
|
+
const contents = /* @__PURE__ */ new Map();
|
|
192
|
+
const allFiles = [];
|
|
193
|
+
await Promise.all([...allIds].map(async (id) => {
|
|
194
|
+
try {
|
|
195
|
+
const { content, files } = await loadDoc(id, format);
|
|
196
|
+
contents.set(id, content);
|
|
197
|
+
allFiles.push(...files);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
const entry = treeMap[id];
|
|
200
|
+
console.warn(`[export] Failed to load doc ${id}:`, e);
|
|
201
|
+
contents.set(id, format === "md" ? `# ${entry?.label ?? id}
|
|
202
|
+
|
|
203
|
+
<!-- export error -->` : `<h1>${entry?.label ?? id}</h1>`);
|
|
204
|
+
}
|
|
205
|
+
}));
|
|
206
|
+
const filePathMap = /* @__PURE__ */ new Map();
|
|
207
|
+
const usedNames = /* @__PURE__ */ new Map();
|
|
208
|
+
for (const file of allFiles) {
|
|
209
|
+
if (filePathMap.has(file.uploadId)) continue;
|
|
210
|
+
let name = file.filename;
|
|
211
|
+
const count = usedNames.get(name) ?? 0;
|
|
212
|
+
if (count > 0) {
|
|
213
|
+
const dotIdx = name.lastIndexOf(".");
|
|
214
|
+
const base = dotIdx > 0 ? name.slice(0, dotIdx) : name;
|
|
215
|
+
const extPart = dotIdx > 0 ? name.slice(dotIdx) : "";
|
|
216
|
+
name = `${base}-${count + 1}${extPart}`;
|
|
217
|
+
}
|
|
218
|
+
usedNames.set(file.filename, count + 1);
|
|
219
|
+
filePathMap.set(file.uploadId, { zipPath: `_files/${name}`, mimeType: file.mimeType });
|
|
220
|
+
}
|
|
221
|
+
const fileBlobs = client.value ? await downloadFiles(allFiles) : /* @__PURE__ */ new Map();
|
|
222
|
+
const JSZip = (await import("jszip")).default;
|
|
223
|
+
const zip = new JSZip();
|
|
224
|
+
for (const [id, path] of pathMap) {
|
|
225
|
+
let content = contents.get(id);
|
|
226
|
+
if (content) {
|
|
227
|
+
if (filePathMap.size > 0) content = replaceFileMarkers(content, path, filePathMap, format);
|
|
228
|
+
zip.file(path, content);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
for (const [uploadId, info] of filePathMap) {
|
|
232
|
+
const blob2 = fileBlobs.get(uploadId);
|
|
233
|
+
if (blob2) zip.file(info.zipPath, blob2);
|
|
234
|
+
}
|
|
235
|
+
const blob = await zip.generateAsync({ type: "blob" });
|
|
236
|
+
const zipName = ids.length === 1 ? `${labelToFilename(treeMap[ids[0]]?.label ?? "export")}.zip` : "export.zip";
|
|
237
|
+
toast.remove(toastRef.id);
|
|
238
|
+
triggerDownload(blob, zipName);
|
|
239
|
+
toast.add({ title: "Export complete", icon: "i-lucide-check" });
|
|
240
|
+
} catch (e) {
|
|
241
|
+
toast.remove(toastRef.id);
|
|
242
|
+
toast.add({ title: "Export failed", color: "error", icon: "i-lucide-x" });
|
|
243
|
+
console.error("[export]", e);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async function exportAll(format = "md") {
|
|
247
|
+
const treeMap = getTreeMap() ?? {};
|
|
248
|
+
const rootIds = Object.entries(treeMap).filter(([, e]) => !e.parentId).map(([id]) => id);
|
|
249
|
+
if (!rootIds.length) {
|
|
250
|
+
toast.add({ title: "Nothing to export", icon: "i-lucide-info" });
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
return exportDocs(rootIds, format);
|
|
254
|
+
}
|
|
255
|
+
return { exportDoc, exportDocs, exportAll };
|
|
256
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function useDocImport(): {
|
|
2
|
+
externalDragActive: import("vue").Ref<boolean, boolean>;
|
|
3
|
+
onDragEnter: (e: DragEvent) => void;
|
|
4
|
+
onDragLeave: (e: DragEvent) => void;
|
|
5
|
+
onDragOver: (e: DragEvent) => void;
|
|
6
|
+
onFileDrop: (e: DragEvent, parentId?: string | null) => Promise<void>;
|
|
7
|
+
importFiles: (parentId?: string | null) => void;
|
|
8
|
+
importFolder: (parentId?: string | null) => void;
|
|
9
|
+
importFile: (file: File, parentId: string | null) => Promise<string>;
|
|
10
|
+
};
|