@hiai-gg/docsmint 0.3.7 → 0.3.8
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/backend/src/lib/logger.ts +45 -15
- package/dist/backend/index.js +238 -150
- package/dist/frontend/CategoryDialog-DphkZqIB.js +611 -0
- package/dist/frontend/ConfirmDialog-BLF3x_hr.js +214 -0
- package/dist/frontend/CreateSnapshotDialog-D5vPvFTL.js +216 -0
- package/dist/frontend/DatePicker-CLNTdvTk.js +259 -0
- package/dist/frontend/DeleteDialog-DxYFJivN.js +174 -0
- package/dist/frontend/FolderDialog-CRVZM2Oi.js +250 -0
- package/dist/frontend/FolderNode-C2zG7uii.js +298 -0
- package/dist/frontend/FolderTreeSelector-CyB8y2Sm.js +103 -0
- package/dist/frontend/Icon-CooFj4Ee.js +64 -0
- package/dist/frontend/SettingsDialog-DCM4-N6_.js +1016 -0
- package/dist/frontend/ShareDialog-DYu3RKQu.js +165 -0
- package/dist/frontend/TagCreateDialog-DXQs2bL9.js +260 -0
- package/dist/frontend/camera-iKXDOOWT.js +29 -0
- package/dist/frontend/check-D-UuvBuh.js +25 -0
- package/dist/frontend/chevron-down-CiPtYyFh.js +25 -0
- package/dist/frontend/circle-check-tSPE1V6t.js +29 -0
- package/dist/frontend/clock-DJHbHZb8.js +29 -0
- package/dist/frontend/{bundle-mjs-CP6Owz-8.js → clsx-C7bIvsDS.js} +16 -1
- package/dist/frontend/components/category-dialog.js +1 -1
- package/dist/frontend/components/create-snapshot-dialog.js +1 -1
- package/dist/frontend/components/delete-dialog.js +1 -1
- package/dist/frontend/components/editor/document-editor.js +1364 -1353
- package/dist/frontend/components/editor/document-title.js +25 -25
- package/dist/frontend/components/editor/markdown-toggle.js +45 -45
- package/dist/frontend/components/folder-node.js +1 -1
- package/dist/frontend/components/folder-tree-selector.js +1 -1
- package/dist/frontend/components/save-as-dialog.js +169 -151
- package/dist/frontend/components/settings.js +1 -1
- package/dist/frontend/components/share-dialog.js +1 -1
- package/dist/frontend/components/sidebar.js +1161 -1153
- package/dist/frontend/components/tag-create-dialog.js +1 -1
- package/dist/frontend/components/version-history.js +188 -187
- package/dist/frontend/copy-GppwRMjX.js +32 -0
- package/dist/frontend/dashboard.js +1188 -1156
- package/dist/frontend/dialog-D6NxYVmy.js +213 -0
- package/dist/frontend/doc-tabs.js +2 -2
- package/dist/frontend/ellipsis-vertical-P9MHvCps.js +530 -0
- package/dist/frontend/extension.js +8 -8
- package/dist/frontend/{floating-layer-anchor-C51M4l6v.js → floating-layer-anchor-CPwucTfd.js} +1414 -1412
- package/dist/frontend/folder-DeWhnD7O.js +45 -0
- package/dist/frontend/folder-refresh.js +1 -1
- package/dist/frontend/input-B5Rak-5G.js +23 -0
- package/dist/frontend/keyboard.js +1 -1
- package/dist/frontend/{keyboard.svelte-D7H8DihC.js → keyboard.svelte-CApmX0vl.js} +53 -53
- package/dist/frontend/label-CW9rxoAb.js +30 -0
- package/dist/frontend/{loader-circle-Bk-WFz9g.js → loader-circle-BA6aLO71.js} +86 -85
- package/dist/frontend/rotate-ccw-B4Q7brmV.js +25 -0
- package/dist/frontend/search.js +680 -654
- package/dist/frontend/select-value-sF86Geyh.js +1446 -0
- package/dist/frontend/shared-document.js +94 -94
- package/dist/frontend/subfolders-refresh-store.svelte-B2dKVmgz.js +65 -0
- package/dist/frontend/tag-HxRazVN_.js +54 -0
- package/dist/frontend/tag-store.svelte-CqrUXo0o.js +29 -0
- package/dist/frontend/textarea-i1720bE7.js +23 -0
- package/dist/frontend/theme.js +1 -1
- package/dist/frontend/theme.svelte-DKfCy12k.js +49 -0
- package/dist/frontend/{utils-C0OW2678.js → utils-CffiyuTo.js} +2 -3
- package/dist/frontend/{utils-D8kmM3ub.js → utils-hzdMVeCv.js} +2 -3
- package/dist/frontend/utils.js +1 -1
- package/dist/frontend/x-CzBsnJ2x.js +25 -0
- package/dist/frontend-ssr/api/attachments.js +2 -0
- package/dist/frontend-ssr/api/categories.js +2 -0
- package/dist/frontend-ssr/api/documents.js +2 -0
- package/dist/frontend-ssr/api/folders.js +2 -0
- package/dist/frontend-ssr/api/settings.js +2 -0
- package/dist/frontend-ssr/api/share.js +2 -0
- package/dist/frontend-ssr/api/tags.js +2 -0
- package/dist/frontend-ssr/assets/CategoryDialog-C2xaZKHq.js +584 -0
- package/dist/frontend-ssr/assets/ConfirmDialog-DjMFKc0V.js +420 -0
- package/dist/frontend-ssr/assets/CreateSnapshotDialog-BRw1xJW1.js +214 -0
- package/dist/frontend-ssr/assets/DatePicker-DnXniwlZ.js +312 -0
- package/dist/frontend-ssr/assets/DeleteDialog-BCfZy3Zn.js +154 -0
- package/dist/frontend-ssr/assets/FolderDialog-Dq7I2cKZ.js +429 -0
- package/dist/frontend-ssr/assets/FolderNode-DRfBfpft.js +171 -0
- package/dist/frontend-ssr/assets/FolderTreeSelector-DZNZ2oI6.js +147 -0
- package/dist/frontend-ssr/assets/Icon-B0Zqppjo.js +231 -0
- package/dist/frontend-ssr/assets/SettingsDialog-CX8Noa8A.js +1107 -0
- package/dist/frontend-ssr/assets/ShareDialog-Cge49ZdJ.js +54 -0
- package/dist/frontend-ssr/assets/TagCreateDialog-EAChgBF-.js +264 -0
- package/dist/frontend-ssr/assets/api-keys-DFqX39MT.js +35 -0
- package/dist/frontend-ssr/assets/attachments-CWBxE3Vz.js +85 -0
- package/dist/frontend-ssr/assets/auth-client-x26kqY8Z.js +1286 -0
- package/dist/frontend-ssr/assets/camera-CdxscTw-.js +84 -0
- package/dist/frontend-ssr/assets/categories-AOqgcsn4.js +75 -0
- package/dist/frontend-ssr/assets/chevron-down-CSSNGNh_.js +80 -0
- package/dist/frontend-ssr/assets/chevron-right-B4p7Sk6X.js +80 -0
- package/dist/frontend-ssr/assets/circle-check-CI1v4vYh.js +84 -0
- package/dist/frontend-ssr/assets/client-DZMkDkDn.js +129 -0
- package/dist/frontend-ssr/assets/clipboard-CXOaoz2W.js +30 -0
- package/dist/frontend-ssr/assets/clock-IL-eX2di.js +84 -0
- package/dist/frontend-ssr/assets/context-jz1GGEUi.js +45 -0
- package/dist/frontend-ssr/assets/copy-CjV57nGQ.js +87 -0
- package/dist/frontend-ssr/assets/db-CnxeO66n.js +65 -0
- package/dist/frontend-ssr/assets/dialog-BOV1u6zP.js +157 -0
- package/dist/frontend-ssr/assets/dndzone-DMvTO_Jz.js +2114 -0
- package/dist/frontend-ssr/assets/document-drop-coordinator-CEaYACsC.js +109 -0
- package/dist/frontend-ssr/assets/documents-BnOTRdTY.js +108 -0
- package/dist/frontend-ssr/assets/editorExtensions-DUzwndMy.js +186 -0
- package/dist/frontend-ssr/assets/ellipsis-vertical-C-0hgkZn.js +555 -0
- package/dist/frontend-ssr/assets/floating-layer-anchor-uzw9K8qN.js +6114 -0
- package/dist/frontend-ssr/assets/folder-DChhG7qN.js +80 -0
- package/dist/frontend-ssr/assets/folders-CTfbS24J.js +127 -0
- package/dist/frontend-ssr/assets/identity-B3uHoDtf.js +99 -0
- package/dist/frontend-ssr/assets/input-DezGsU3y.js +19 -0
- package/dist/frontend-ssr/assets/keyboard.svelte-BgF47N3L.js +174 -0
- package/dist/frontend-ssr/assets/label-Bj8-TfFN.js +21 -0
- package/dist/frontend-ssr/assets/loader-circle-DZsrZ-er.js +80 -0
- package/dist/frontend-ssr/assets/markdown-CjqvGi5W.js +20 -0
- package/dist/frontend-ssr/assets/messages-DhXqlcJI.js +11125 -0
- package/dist/frontend-ssr/assets/resolve-BqHozBXl.js +32 -0
- package/dist/frontend-ssr/assets/rotate-ccw-BlgWwaiq.js +80 -0
- package/dist/frontend-ssr/assets/select-value-DngdSmLI.js +1526 -0
- package/dist/frontend-ssr/assets/settings-E6qSAWM2.js +64 -0
- package/dist/frontend-ssr/assets/share-BTBJelxA.js +30 -0
- package/dist/frontend-ssr/assets/subfolders-refresh-store.svelte-DAh4gT16.js +77 -0
- package/dist/frontend-ssr/assets/tag-GZEuGWk1.js +166 -0
- package/dist/frontend-ssr/assets/tag-store.svelte-DPodKj6Z.js +21 -0
- package/dist/frontend-ssr/assets/tags-BId2wdYd.js +49 -0
- package/dist/frontend-ssr/assets/textarea-Dev-qSEc.js +21 -0
- package/dist/frontend-ssr/assets/theme.svelte-Co0-ssaD.js +67 -0
- package/dist/frontend-ssr/assets/utils-DtlPPXpJ.js +9 -0
- package/dist/frontend-ssr/assets/utils-DvZnctjz.js +23 -0
- package/dist/frontend-ssr/collaboration.js +39 -0
- package/dist/frontend-ssr/components/category-dialog.js +2 -0
- package/dist/frontend-ssr/components/create-snapshot-dialog.js +2 -0
- package/dist/frontend-ssr/components/delete-dialog.js +2 -0
- package/dist/frontend-ssr/components/editor/document-editor.js +2499 -0
- package/dist/frontend-ssr/components/editor/document-title.js +11 -0
- package/dist/frontend-ssr/components/editor/docx-serializer.js +186 -0
- package/dist/frontend-ssr/components/editor/extensions.js +2 -0
- package/dist/frontend-ssr/components/editor/markdown-toggle.js +20 -0
- package/dist/frontend-ssr/components/editor/markdown.js +2 -0
- package/dist/frontend-ssr/components/folder-node.js +2 -0
- package/dist/frontend-ssr/components/folder-tree-selector.js +2 -0
- package/dist/frontend-ssr/components/save-as-dialog.js +280 -0
- package/dist/frontend-ssr/components/settings.js +2 -0
- package/dist/frontend-ssr/components/share-dialog.js +2 -0
- package/dist/frontend-ssr/components/sidebar.js +2033 -0
- package/dist/frontend-ssr/components/tag-create-dialog.js +2 -0
- package/dist/frontend-ssr/components/version-history.js +370 -0
- package/dist/frontend-ssr/dashboard.js +2542 -0
- package/dist/frontend-ssr/doc-tabs.js +23 -0
- package/dist/frontend-ssr/document-drop-coordinator.js +2 -0
- package/dist/frontend-ssr/extension.js +13 -0
- package/dist/frontend-ssr/folder-refresh.js +2 -0
- package/dist/frontend-ssr/i18n.js +10 -0
- package/dist/frontend-ssr/keyboard.js +2 -0
- package/dist/frontend-ssr/offline/identity.js +2 -0
- package/dist/frontend-ssr/search.js +332 -0
- package/dist/frontend-ssr/shared-document.js +273 -0
- package/dist/frontend-ssr/theme.js +9 -0
- package/dist/frontend-ssr/types.js +1 -0
- package/dist/frontend-ssr/utils/clipboard.js +2 -0
- package/dist/frontend-ssr/utils/dndzone.js +2 -0
- package/dist/frontend-ssr/utils.js +2 -0
- package/package.json +22 -1
- package/packages/cli/src/index.ts +1 -1
- package/packages/db/src/schema.ts +3 -0
- package/packages/mcp-server/src/index.ts +1 -1
- package/dist/frontend/CategoryDialog--rIE7FrH.js +0 -580
- package/dist/frontend/ConfirmDialog-Cpzyb55f.js +0 -212
- package/dist/frontend/CreateSnapshotDialog-CmkV-n2A.js +0 -216
- package/dist/frontend/DatePicker-Byynca7V.js +0 -257
- package/dist/frontend/DeleteDialog-ap6nOywZ.js +0 -174
- package/dist/frontend/FolderDialog-DmN_trV0.js +0 -247
- package/dist/frontend/FolderNode-C4B8a2fd.js +0 -317
- package/dist/frontend/FolderTreeSelector-D6ijiZTA.js +0 -100
- package/dist/frontend/Icon-DtNo0N1U.js +0 -64
- package/dist/frontend/SettingsDialog-2kTaTXAs.js +0 -992
- package/dist/frontend/ShareDialog-BBDGNF5n.js +0 -165
- package/dist/frontend/TagCreateDialog-DiLZnJo4.js +0 -258
- package/dist/frontend/camera-B7dAOd4s.js +0 -28
- package/dist/frontend/check-CDwRlG9T.js +0 -24
- package/dist/frontend/chevron-down-B7ZrjUmT.js +0 -24
- package/dist/frontend/circle-check-CDqeMB2d.js +0 -28
- package/dist/frontend/client-Bc5Fzx40.js +0 -2785
- package/dist/frontend/clock-Ck5Sn-Zl.js +0 -28
- package/dist/frontend/clsx-nmtDPO_P.js +0 -16
- package/dist/frontend/copy-CMAA6GP0.js +0 -31
- package/dist/frontend/dialog-BDkiG42a.js +0 -213
- package/dist/frontend/disclose-version-5I57E3LD.js +0 -3
- package/dist/frontend/ellipsis-vertical-BBuPldbW.js +0 -519
- package/dist/frontend/folder-TQjKY4yn.js +0 -44
- package/dist/frontend/index-client-jobkrWVL.js +0 -86
- package/dist/frontend/input-CBI6p4Xl.js +0 -23
- package/dist/frontend/label-C-GkhEp4.js +0 -30
- package/dist/frontend/rotate-ccw-CleZtJ5D.js +0 -24
- package/dist/frontend/select-value-CvrWRkXW.js +0 -1436
- package/dist/frontend/subfolders-refresh-store.svelte-BsheoQma.js +0 -65
- package/dist/frontend/tag-Dx3SmucJ.js +0 -53
- package/dist/frontend/tag-store.svelte-CIaF4sdZ.js +0 -29
- package/dist/frontend/textarea-Dfp78XlL.js +0 -23
- package/dist/frontend/theme.svelte-CROg1Hi5.js +0 -49
- package/dist/frontend/x-DaTdeDXv.js +0 -24
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//#region src/lib/components/sidebar/document-drop-coordinator.ts
|
|
2
|
+
function createDocumentPlacementWriter(options) {
|
|
3
|
+
const states = /* @__PURE__ */ new Map();
|
|
4
|
+
return function move(id, placement, initialConfirmed) {
|
|
5
|
+
let state = states.get(id);
|
|
6
|
+
if (!state) {
|
|
7
|
+
state = {
|
|
8
|
+
chain: Promise.resolve(),
|
|
9
|
+
confirmed: { ...initialConfirmed },
|
|
10
|
+
generation: 0
|
|
11
|
+
};
|
|
12
|
+
states.set(id, state);
|
|
13
|
+
}
|
|
14
|
+
const request = {
|
|
15
|
+
generation: ++state.generation,
|
|
16
|
+
placement: { ...placement },
|
|
17
|
+
token: options.optimistic(id, placement)
|
|
18
|
+
};
|
|
19
|
+
const run = state.chain.then(async () => {
|
|
20
|
+
try {
|
|
21
|
+
await options.patch(id, request.placement);
|
|
22
|
+
state.confirmed = { ...request.placement };
|
|
23
|
+
options.acknowledge(id, request.token);
|
|
24
|
+
if (options.refresh) options.refresh().catch(options.onRefreshError ?? (() => void 0));
|
|
25
|
+
} catch (error) {
|
|
26
|
+
options.acknowledge(id, request.token);
|
|
27
|
+
if (request.generation === state.generation) options.rollback(id, state.confirmed);
|
|
28
|
+
options.onError(error);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
state.chain = run.catch(() => void 0);
|
|
33
|
+
return run;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function createDocumentDropCoordinator(options) {
|
|
37
|
+
const defer = options.defer ?? ((callback) => setTimeout(callback, 0));
|
|
38
|
+
const cancel = options.cancel ?? clearTimeout;
|
|
39
|
+
const expire = options.expire ?? ((callback) => setTimeout(callback, 1e3));
|
|
40
|
+
const cancelExpire = options.cancelExpire ?? clearTimeout;
|
|
41
|
+
let active;
|
|
42
|
+
function clearActive() {
|
|
43
|
+
if (active?.pending) cancel(active.pending);
|
|
44
|
+
if (active?.expiry) cancelExpire(active.expiry);
|
|
45
|
+
active = void 0;
|
|
46
|
+
}
|
|
47
|
+
function lookup(id) {
|
|
48
|
+
return active?.id === id ? active : void 0;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
/**
|
|
52
|
+
* Returns the document whose drag transaction is still awaiting a
|
|
53
|
+
* destination. UI state may already have been cleared by the source
|
|
54
|
+
* zone's finalize event before a category-header drop is delivered.
|
|
55
|
+
*/
|
|
56
|
+
pendingId(token) {
|
|
57
|
+
return active && !active.resolved && active.token === token ? active.id : null;
|
|
58
|
+
},
|
|
59
|
+
begin(id, token) {
|
|
60
|
+
if (active?.id === id && active.token === token) return;
|
|
61
|
+
clearActive();
|
|
62
|
+
active = {
|
|
63
|
+
id,
|
|
64
|
+
token,
|
|
65
|
+
resolved: false,
|
|
66
|
+
pending: null,
|
|
67
|
+
expiry: null
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
end(id, token) {
|
|
71
|
+
const transaction = active;
|
|
72
|
+
if (!transaction || transaction.id !== id || transaction.token !== token || transaction.resolved || transaction.expiry) return;
|
|
73
|
+
transaction.expiry = expire(() => {
|
|
74
|
+
if (active === transaction && !transaction.resolved) clearActive();
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
cancel() {
|
|
78
|
+
clearActive();
|
|
79
|
+
},
|
|
80
|
+
zone(id, placement) {
|
|
81
|
+
const transaction = lookup(id);
|
|
82
|
+
if (!transaction || transaction.resolved) return;
|
|
83
|
+
if (transaction.pending) cancel(transaction.pending);
|
|
84
|
+
transaction.pending = defer(() => {
|
|
85
|
+
if (active === transaction && !transaction.resolved) {
|
|
86
|
+
transaction.pending = null;
|
|
87
|
+
if (transaction.expiry) {
|
|
88
|
+
cancelExpire(transaction.expiry);
|
|
89
|
+
transaction.expiry = null;
|
|
90
|
+
}
|
|
91
|
+
transaction.resolved = true;
|
|
92
|
+
options.persist(id, placement);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
header(id, placement) {
|
|
97
|
+
const transaction = lookup(id);
|
|
98
|
+
if (!transaction || transaction.resolved) return;
|
|
99
|
+
if (transaction.pending) cancel(transaction.pending);
|
|
100
|
+
transaction.pending = null;
|
|
101
|
+
if (transaction.expiry) cancelExpire(transaction.expiry);
|
|
102
|
+
transaction.expiry = null;
|
|
103
|
+
transaction.resolved = true;
|
|
104
|
+
options.persist(id, placement);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { createDocumentPlacementWriter as n, createDocumentDropCoordinator as t };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { n as apiFetch } from "./client-DZMkDkDn.js";
|
|
2
|
+
//#region src/lib/api/documents.ts
|
|
3
|
+
var listDocumentsInflight = /* @__PURE__ */ new Map();
|
|
4
|
+
var listDocumentsTtl = /* @__PURE__ */ new Map();
|
|
5
|
+
var LIST_CACHE_TTL_MS = 5e3;
|
|
6
|
+
function clearDocumentsCache() {
|
|
7
|
+
listDocumentsInflight.clear();
|
|
8
|
+
listDocumentsTtl.clear();
|
|
9
|
+
}
|
|
10
|
+
function listDocumentsCacheKey(params) {
|
|
11
|
+
if (!params) return "all";
|
|
12
|
+
return JSON.stringify({
|
|
13
|
+
folderId: params.folderId ?? null,
|
|
14
|
+
tag: params.tag ?? null,
|
|
15
|
+
page: params.page ?? 1,
|
|
16
|
+
limit: params.limit ?? null
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function getTtlEntry(key) {
|
|
20
|
+
const entry = listDocumentsTtl.get(key);
|
|
21
|
+
if (!entry) return void 0;
|
|
22
|
+
if (Date.now() - entry.timestamp >= LIST_CACHE_TTL_MS) {
|
|
23
|
+
listDocumentsTtl.delete(key);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return entry;
|
|
27
|
+
}
|
|
28
|
+
function setTtlEntry(key, promise) {
|
|
29
|
+
listDocumentsTtl.set(key, {
|
|
30
|
+
promise,
|
|
31
|
+
timestamp: Date.now()
|
|
32
|
+
});
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
listDocumentsTtl.delete(key);
|
|
35
|
+
}, LIST_CACHE_TTL_MS);
|
|
36
|
+
}
|
|
37
|
+
function listDocuments(params, fetcher) {
|
|
38
|
+
const key = listDocumentsCacheKey(params);
|
|
39
|
+
const inflight = listDocumentsInflight.get(key);
|
|
40
|
+
if (inflight) return inflight;
|
|
41
|
+
const ttl = getTtlEntry(key);
|
|
42
|
+
if (ttl) return ttl.promise;
|
|
43
|
+
const searchParams = new URLSearchParams();
|
|
44
|
+
if (params?.folderId) searchParams.set("folderId", params.folderId);
|
|
45
|
+
if (params?.tag) searchParams.set("tag", params.tag);
|
|
46
|
+
if (params?.page) searchParams.set("page", String(params.page));
|
|
47
|
+
if (params?.limit) searchParams.set("limit", String(params.limit));
|
|
48
|
+
const qs = searchParams.toString();
|
|
49
|
+
const promise = apiFetch(`/api/documents${qs ? `?${qs}` : ""}`, {}, fetcher).catch((err) => {
|
|
50
|
+
listDocumentsTtl.delete(key);
|
|
51
|
+
throw err;
|
|
52
|
+
});
|
|
53
|
+
listDocumentsInflight.set(key, promise);
|
|
54
|
+
setTtlEntry(key, promise);
|
|
55
|
+
promise.finally(() => {
|
|
56
|
+
listDocumentsInflight.delete(key);
|
|
57
|
+
});
|
|
58
|
+
return promise;
|
|
59
|
+
}
|
|
60
|
+
function getDocument(id, fetcher) {
|
|
61
|
+
return apiFetch(`/api/documents/${id}`, {}, fetcher);
|
|
62
|
+
}
|
|
63
|
+
function createDocument(data, fetcher) {
|
|
64
|
+
clearDocumentsCache();
|
|
65
|
+
return apiFetch("/api/documents", {
|
|
66
|
+
method: "POST",
|
|
67
|
+
body: JSON.stringify(data)
|
|
68
|
+
}, fetcher);
|
|
69
|
+
}
|
|
70
|
+
function updateDocument(id, data) {
|
|
71
|
+
clearDocumentsCache();
|
|
72
|
+
return apiFetch(`/api/documents/${id}`, {
|
|
73
|
+
method: "PATCH",
|
|
74
|
+
body: JSON.stringify(data)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function deleteDocument(id) {
|
|
78
|
+
clearDocumentsCache();
|
|
79
|
+
return apiFetch(`/api/documents/${id}`, { method: "DELETE" });
|
|
80
|
+
}
|
|
81
|
+
function importDocument(file, folderId) {
|
|
82
|
+
clearDocumentsCache();
|
|
83
|
+
const formData = new FormData();
|
|
84
|
+
formData.append("file", file);
|
|
85
|
+
if (folderId) formData.append("folderId", folderId);
|
|
86
|
+
return apiFetch("/api/documents/import", {
|
|
87
|
+
method: "POST",
|
|
88
|
+
body: formData
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Import one or more documents. Accepts any combination of supported
|
|
93
|
+
* file types (markdown, text, JSON, DOCX). The backend endpoint accepts
|
|
94
|
+
* a multipart body with multiple `file` parts and returns an
|
|
95
|
+
* `ImportResponse` describing per-file success/failure.
|
|
96
|
+
*/
|
|
97
|
+
function importDocuments(files, folderId) {
|
|
98
|
+
clearDocumentsCache();
|
|
99
|
+
const formData = new FormData();
|
|
100
|
+
for (const file of files) formData.append("file", file);
|
|
101
|
+
if (folderId) formData.append("folderId", folderId);
|
|
102
|
+
return apiFetch("/api/documents/import", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: formData
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { importDocument as a, updateDocument as c, getDocument as i, createDocument as n, importDocuments as o, deleteDocument as r, listDocuments as s, clearDocumentsCache as t };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Node, mergeAttributes, textblockTypeInputRule } from "@tiptap/core";
|
|
2
|
+
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
|
|
3
|
+
import Highlight from "@tiptap/extension-highlight";
|
|
4
|
+
import Image from "@tiptap/extension-image";
|
|
5
|
+
import Link from "@tiptap/extension-link";
|
|
6
|
+
import { TaskItem, TaskList } from "@tiptap/extension-list";
|
|
7
|
+
import { TableKit } from "@tiptap/extension-table";
|
|
8
|
+
import TextAlign from "@tiptap/extension-text-align";
|
|
9
|
+
import { Markdown } from "@tiptap/markdown";
|
|
10
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
11
|
+
import { common, createLowlight } from "lowlight";
|
|
12
|
+
//#region src/lib/components/editor/editorExtensions.ts
|
|
13
|
+
var lowlight = createLowlight(common);
|
|
14
|
+
var EMPTY_PARAGRAPH_MARKDOWN = " ";
|
|
15
|
+
var NBSP_CHAR = "\xA0";
|
|
16
|
+
var TEXT_ALIGNMENTS = [
|
|
17
|
+
"left",
|
|
18
|
+
"center",
|
|
19
|
+
"right",
|
|
20
|
+
"justify"
|
|
21
|
+
];
|
|
22
|
+
var TextAlignParagraph = Node.create({
|
|
23
|
+
name: "paragraph",
|
|
24
|
+
priority: 1e3,
|
|
25
|
+
addOptions() {
|
|
26
|
+
return { HTMLAttributes: {} };
|
|
27
|
+
},
|
|
28
|
+
group: "block",
|
|
29
|
+
content: "inline*",
|
|
30
|
+
parseHTML() {
|
|
31
|
+
return [{ tag: "p" }];
|
|
32
|
+
},
|
|
33
|
+
renderHTML({ HTMLAttributes }) {
|
|
34
|
+
return [
|
|
35
|
+
"p",
|
|
36
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
37
|
+
0
|
|
38
|
+
];
|
|
39
|
+
},
|
|
40
|
+
parseMarkdown: (token, helpers) => {
|
|
41
|
+
const tokens = token.tokens || [];
|
|
42
|
+
if (tokens.length === 1 && tokens[0].type === "image") return helpers.parseChildren([tokens[0]]);
|
|
43
|
+
const content = helpers.parseInline(tokens);
|
|
44
|
+
if (tokens.length === 1 && tokens[0].type === "text" && (tokens[0].raw === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].text === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].raw === NBSP_CHAR || tokens[0].text === NBSP_CHAR) && content.length === 1 && content[0].type === "text" && (content[0].text === EMPTY_PARAGRAPH_MARKDOWN || content[0].text === NBSP_CHAR)) return helpers.createNode("paragraph", void 0, []);
|
|
45
|
+
return helpers.createNode("paragraph", void 0, content);
|
|
46
|
+
},
|
|
47
|
+
renderMarkdown: (node, h, ctx) => {
|
|
48
|
+
if (!node) return "";
|
|
49
|
+
const content = Array.isArray(node.content) ? node.content : [];
|
|
50
|
+
const align = node.attrs?.textAlign ?? "";
|
|
51
|
+
const normalizedAlign = TEXT_ALIGNMENTS.includes(align) ? align : "";
|
|
52
|
+
if (normalizedAlign && normalizedAlign !== "left") return `<p style="text-align: ${normalizedAlign}">${content.length === 0 ? "" : h.renderChildren(content)}</p>`;
|
|
53
|
+
if (content.length === 0) {
|
|
54
|
+
const previousContent = Array.isArray(ctx?.previousNode?.content) ? ctx.previousNode.content : [];
|
|
55
|
+
return ctx?.previousNode?.type === "paragraph" && previousContent.length === 0 ? EMPTY_PARAGRAPH_MARKDOWN : "";
|
|
56
|
+
}
|
|
57
|
+
return h.renderChildren(content);
|
|
58
|
+
},
|
|
59
|
+
addCommands() {
|
|
60
|
+
return { setParagraph: () => ({ commands }) => {
|
|
61
|
+
return commands.setNode(this.name);
|
|
62
|
+
} };
|
|
63
|
+
},
|
|
64
|
+
addKeyboardShortcuts() {
|
|
65
|
+
return { "Mod-Alt-0": () => this.editor.commands.setParagraph() };
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
var HEADING_DEFAULT_LEVELS = [
|
|
69
|
+
1,
|
|
70
|
+
2,
|
|
71
|
+
3
|
|
72
|
+
];
|
|
73
|
+
var TextAlignHeading = Node.create({
|
|
74
|
+
name: "heading",
|
|
75
|
+
addOptions() {
|
|
76
|
+
return {
|
|
77
|
+
levels: [...HEADING_DEFAULT_LEVELS],
|
|
78
|
+
HTMLAttributes: {}
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
content: "inline*",
|
|
82
|
+
group: "block",
|
|
83
|
+
defining: true,
|
|
84
|
+
addAttributes() {
|
|
85
|
+
return { level: {
|
|
86
|
+
default: 1,
|
|
87
|
+
rendered: false
|
|
88
|
+
} };
|
|
89
|
+
},
|
|
90
|
+
parseHTML() {
|
|
91
|
+
return this.options.levels.map((level) => ({
|
|
92
|
+
tag: `h${level}`,
|
|
93
|
+
attrs: { level }
|
|
94
|
+
}));
|
|
95
|
+
},
|
|
96
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
97
|
+
const levels = this.options.levels;
|
|
98
|
+
return [
|
|
99
|
+
`h${levels.includes(node.attrs.level) ? node.attrs.level : levels[0]}`,
|
|
100
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
101
|
+
0
|
|
102
|
+
];
|
|
103
|
+
},
|
|
104
|
+
parseMarkdown: (token, helpers) => {
|
|
105
|
+
return helpers.createNode("heading", { level: token.depth || 1 }, helpers.parseInline(token.tokens || []));
|
|
106
|
+
},
|
|
107
|
+
renderMarkdown: (node, h) => {
|
|
108
|
+
const attrs = node.attrs ?? {};
|
|
109
|
+
const rawLevel = attrs.level;
|
|
110
|
+
const numericLevel = typeof rawLevel === "number" ? rawLevel : typeof rawLevel === "string" ? parseInt(rawLevel, 10) : 1;
|
|
111
|
+
const level = numericLevel >= 1 && numericLevel <= 6 ? Math.floor(numericLevel) : 1;
|
|
112
|
+
const headingChars = "#".repeat(level);
|
|
113
|
+
const content = Array.isArray(node.content) ? node.content : [];
|
|
114
|
+
const inner = h.renderChildren(content);
|
|
115
|
+
const align = attrs.textAlign ?? "";
|
|
116
|
+
const normalizedAlign = TEXT_ALIGNMENTS.includes(align) ? align : "";
|
|
117
|
+
if (normalizedAlign && normalizedAlign !== "left") return `<h${level} style="text-align: ${normalizedAlign}">${inner}</h${level}>`;
|
|
118
|
+
return `${headingChars} ${inner}`;
|
|
119
|
+
},
|
|
120
|
+
addCommands() {
|
|
121
|
+
return {
|
|
122
|
+
setHeading: (attributes) => ({ commands }) => {
|
|
123
|
+
if (!this.options.levels.includes(attributes.level)) return false;
|
|
124
|
+
return commands.setNode(this.name, attributes);
|
|
125
|
+
},
|
|
126
|
+
toggleHeading: (attributes) => ({ commands }) => {
|
|
127
|
+
if (!this.options.levels.includes(attributes.level)) return false;
|
|
128
|
+
return commands.toggleNode(this.name, "paragraph", attributes);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
addKeyboardShortcuts() {
|
|
133
|
+
const shortcuts = {};
|
|
134
|
+
for (const level of this.options.levels) shortcuts[`Mod-Alt-${level}`] = () => this.editor.commands.toggleHeading({ level });
|
|
135
|
+
return shortcuts;
|
|
136
|
+
},
|
|
137
|
+
addInputRules() {
|
|
138
|
+
const levels = this.options.levels;
|
|
139
|
+
const min = Math.min(...levels);
|
|
140
|
+
return levels.map((level) => textblockTypeInputRule({
|
|
141
|
+
find: new RegExp(`^(#{${min},${level}})\\s$`),
|
|
142
|
+
type: this.type,
|
|
143
|
+
getAttributes: { level }
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
var editorExtensions = [
|
|
148
|
+
StarterKit.configure({
|
|
149
|
+
heading: false,
|
|
150
|
+
paragraph: false,
|
|
151
|
+
codeBlock: false,
|
|
152
|
+
link: false
|
|
153
|
+
}),
|
|
154
|
+
Markdown.configure({}),
|
|
155
|
+
TextAlignParagraph,
|
|
156
|
+
TextAlignHeading,
|
|
157
|
+
Link.configure({
|
|
158
|
+
openOnClick: false,
|
|
159
|
+
HTMLAttributes: { class: "doc-link" }
|
|
160
|
+
}),
|
|
161
|
+
Image.configure({
|
|
162
|
+
inline: false,
|
|
163
|
+
allowBase64: false,
|
|
164
|
+
HTMLAttributes: { class: "doc-image" },
|
|
165
|
+
resize: {
|
|
166
|
+
enabled: true,
|
|
167
|
+
directions: [
|
|
168
|
+
"top-left",
|
|
169
|
+
"top-right",
|
|
170
|
+
"bottom-left",
|
|
171
|
+
"bottom-right"
|
|
172
|
+
],
|
|
173
|
+
minWidth: 96,
|
|
174
|
+
minHeight: 54,
|
|
175
|
+
alwaysPreserveAspectRatio: true
|
|
176
|
+
}
|
|
177
|
+
}),
|
|
178
|
+
Highlight.configure({ multicolor: true }),
|
|
179
|
+
CodeBlockLowlight.configure({ lowlight }),
|
|
180
|
+
TextAlign.configure({ types: ["heading", "paragraph"] }),
|
|
181
|
+
TableKit.configure({ table: { resizable: true } }),
|
|
182
|
+
TaskList,
|
|
183
|
+
TaskItem.configure({ nested: true })
|
|
184
|
+
];
|
|
185
|
+
//#endregion
|
|
186
|
+
export { TextAlignParagraph as n, editorExtensions as r, TextAlignHeading as t };
|