@lemoncat7/dsh-knowledge 2.7.0 → 2.8.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 +22 -0
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +13 -2
- package/lib/api.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/local-provider.d.ts +2 -2
- package/lib/local-provider.d.ts.map +1 -1
- package/lib/local-provider.js +12 -5
- package/lib/local-provider.js.map +1 -1
- package/lib/note-recording.d.ts +21 -0
- package/lib/note-recording.d.ts.map +1 -0
- package/lib/note-recording.js +32 -0
- package/lib/note-recording.js.map +1 -0
- package/lib/note-reference-tools.js +3 -2
- package/lib/note-reference-tools.js.map +1 -1
- package/lib/note-tools.d.ts +3 -2
- package/lib/note-tools.d.ts.map +1 -1
- package/lib/note-tools.js +35 -12
- package/lib/note-tools.js.map +1 -1
- package/lib/notes/store.d.ts +5 -1
- package/lib/notes/store.d.ts.map +1 -1
- package/lib/notes/store.js +11 -2
- package/lib/notes/store.js.map +1 -1
- package/lib/provider.d.ts +2 -2
- package/lib/provider.d.ts.map +1 -1
- package/lib/remote-provider.d.ts +2 -2
- package/lib/remote-provider.d.ts.map +1 -1
- package/lib/remote-provider.js +6 -5
- package/lib/remote-provider.js.map +1 -1
- package/lib/tools.js +1 -1
- package/lib/tools.js.map +1 -1
- package/lib/web.js +1 -1
- package/lib/web.js.map +1 -1
- package/package.json +1 -1
- package/web/app.js +174 -23
- package/web/document-sync-ui.js +23 -0
- package/web/document-sync.js +43 -0
- package/web/styles.css +14 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** One bounded metadata poll for the active document; no full-library reloads. */
|
|
2
|
+
export function createDocumentSync({ current, check, refresh, notify, visible = () => !document.hidden, interval = 5000 }) {
|
|
3
|
+
let timer, controller, stopped = false, failures = 0
|
|
4
|
+
const same = target => {
|
|
5
|
+
const active = current()
|
|
6
|
+
return active && active.identity === target.identity && active.version === target.version && active.key === target.key
|
|
7
|
+
}
|
|
8
|
+
async function tick() {
|
|
9
|
+
clearTimeout(timer)
|
|
10
|
+
if (stopped || controller) return
|
|
11
|
+
const target = visible() ? current() : null
|
|
12
|
+
if (!target) return schedule()
|
|
13
|
+
controller = new AbortController()
|
|
14
|
+
const timeout = setTimeout(() => controller?.abort(), 10000)
|
|
15
|
+
try {
|
|
16
|
+
const remote = await check(target, controller.signal)
|
|
17
|
+
if (stopped || !visible() || !same(target)) return
|
|
18
|
+
failures = 0
|
|
19
|
+
if (remote.version !== target.version || remote.updatedAt !== target.updatedAt) {
|
|
20
|
+
if (current().busy()) notify(target, 'changed')
|
|
21
|
+
else await refresh(target, controller.signal, () => !stopped && visible() && same(target) && !current().busy())
|
|
22
|
+
} else notify(target, 'current')
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (!stopped && same(target)) {
|
|
25
|
+
failures++
|
|
26
|
+
notify(target, error.status === 404 ? 'missing' : 'offline')
|
|
27
|
+
}
|
|
28
|
+
} finally {
|
|
29
|
+
clearTimeout(timeout)
|
|
30
|
+
controller = null
|
|
31
|
+
schedule()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function schedule() {
|
|
35
|
+
clearTimeout(timer)
|
|
36
|
+
if (!stopped && visible()) timer = setTimeout(tick, Math.min(30000, interval * 2 ** Math.min(failures, 3)))
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
wake() { if (!stopped) void tick() },
|
|
40
|
+
pause() { clearTimeout(timer); controller?.abort() },
|
|
41
|
+
stop() { stopped = true; clearTimeout(timer); controller?.abort() },
|
|
42
|
+
}
|
|
43
|
+
}
|
package/web/styles.css
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
.document-sync-notice {
|
|
2
|
+
flex: 1 0 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
|
|
3
|
+
padding: 8px 0 0; color: var(--text); font-size: 12px;
|
|
4
|
+
border-top: 1px solid var(--separator); overflow-wrap: anywhere;
|
|
5
|
+
}
|
|
6
|
+
.note-editor-toolbar:has(.document-sync-notice), .notes-document-toolbar:has(.document-sync-notice) { flex-wrap: wrap; }
|
|
7
|
+
.sync-conflict-dialog { width: min(980px, calc(100vw - 32px)); max-width: 980px; }
|
|
8
|
+
.sync-conflict-body { display: grid; gap: 16px; }
|
|
9
|
+
.sync-merge-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
|
|
10
|
+
.sync-merge-columns section { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
|
|
11
|
+
.sync-merge-columns h3, .sync-merge-columns p { margin: 0; overflow-wrap: anywhere; }
|
|
12
|
+
.sync-conflict-dialog .sync-merge-content { width: 100%; height: 260px; min-height: 200px; resize: vertical; line-height: 1.6; }
|
|
13
|
+
@media (max-width: 640px) { .sync-merge-columns { grid-template-columns: minmax(0, 1fr); } }
|
|
14
|
+
|
|
1
15
|
:root {
|
|
2
16
|
color-scheme: light dark;
|
|
3
17
|
font-family: var(--font-ui);
|