@dooc-dev/dooc 0.0.19 → 0.0.20
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/edit.global.js +3 -3
- package/dist/frontend/figure-preview.d.ts +1 -1
- package/dist/frontend/figure-preview.js +39 -11
- package/dist/frontend/locales/eng.json +0 -1
- package/dist/frontend/locales/jpn.json +0 -1
- package/dist/frontend/locales/zho.json +0 -1
- package/dist/plugins.global.js +3 -3
- package/dist/subformats.global.js +3 -3
- package/dist/ui.global.js +3 -3
- package/dist/workspace-mcp-worker.global.js +3 -3
- package/dist/workspace-reader-mcp-worker.global.js +3 -3
- package/dist/workspace-reader-worker.global.js +3 -3
- package/dist/workspace-worker.global.js +3 -3
- package/package.json +1 -1
|
@@ -6,18 +6,16 @@ export const deferredFigureHtml = (fig, cls = "fig-frame", label) => {
|
|
|
6
6
|
if (cls.includes("figpop-frame"))
|
|
7
7
|
return escapeHtml(fig.title ?? fig.file);
|
|
8
8
|
const url = `/api/figure-preview?file=${encodeURIComponent(fig.file)}${label === undefined ? "" : `&label=${encodeURIComponent(label)}`}`;
|
|
9
|
-
return `<div class="figure-placeholder" data-figure-preview="${escapeHtml(url)}"><span>${escapeHtml(label || fig.title || fig.file)}</span><button type="button" data-i18n="
|
|
9
|
+
return `<div class="figure-placeholder" data-figure-preview="${escapeHtml(url)}"><span>${escapeHtml(label || fig.title || fig.file)}</span><button type="button" data-i18n="Retry" hidden>Retry</button><span role="status"></span></div>`;
|
|
10
10
|
};
|
|
11
|
-
/**
|
|
11
|
+
/** Load visible figures automatically, including previews inserted by navigation or HMR. */
|
|
12
12
|
export function mountFigurePreviews(request = fetch) {
|
|
13
|
-
document.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const status = host?.querySelector('[role="status"]');
|
|
20
|
-
if (!button || !host || !url || !status)
|
|
13
|
+
const root = document.querySelector("main") ?? document.body;
|
|
14
|
+
const load = async (host) => {
|
|
15
|
+
const button = host.querySelector(":scope > button");
|
|
16
|
+
const url = host.dataset.figurePreview;
|
|
17
|
+
const status = host.querySelector('[role="status"]');
|
|
18
|
+
if (!button || button.disabled || !url || !status)
|
|
21
19
|
return;
|
|
22
20
|
const translate = (key) => window.__docsTranslate?.(key) ?? key;
|
|
23
21
|
button.disabled = true;
|
|
@@ -43,12 +41,42 @@ export function mountFigurePreviews(request = fetch) {
|
|
|
43
41
|
if (!host.isConnected)
|
|
44
42
|
return;
|
|
45
43
|
status.textContent = error instanceof Error ? error.message : String(error);
|
|
44
|
+
button.hidden = false;
|
|
46
45
|
button.textContent = translate("Retry");
|
|
47
|
-
button.dataset.i18n = "Retry";
|
|
48
46
|
}
|
|
49
47
|
finally {
|
|
50
48
|
button.disabled = false;
|
|
51
49
|
host.removeAttribute("aria-busy");
|
|
52
50
|
}
|
|
51
|
+
};
|
|
52
|
+
document.addEventListener("click", (event) => {
|
|
53
|
+
const button = event.target instanceof Element
|
|
54
|
+
? event.target.closest("[data-figure-preview] > button")
|
|
55
|
+
: null;
|
|
56
|
+
if (button?.parentElement)
|
|
57
|
+
void load(button.parentElement);
|
|
53
58
|
});
|
|
59
|
+
const watched = new Set();
|
|
60
|
+
const visibility = new IntersectionObserver((entries) => {
|
|
61
|
+
for (const entry of entries) {
|
|
62
|
+
if (!entry.isIntersecting || !root.contains(entry.target))
|
|
63
|
+
continue;
|
|
64
|
+
visibility.unobserve(entry.target);
|
|
65
|
+
void load(entry.target);
|
|
66
|
+
}
|
|
67
|
+
}, { rootMargin: "200px" });
|
|
68
|
+
const watch = () => {
|
|
69
|
+
for (const host of watched)
|
|
70
|
+
if (!root.contains(host) || !host.dataset.figurePreview) {
|
|
71
|
+
visibility.unobserve(host);
|
|
72
|
+
watched.delete(host);
|
|
73
|
+
}
|
|
74
|
+
for (const host of root.querySelectorAll("[data-figure-preview]"))
|
|
75
|
+
if (!watched.has(host)) {
|
|
76
|
+
watched.add(host);
|
|
77
|
+
visibility.observe(host);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
new MutationObserver(watch).observe(root, { childList: true, subtree: true });
|
|
81
|
+
watch();
|
|
54
82
|
}
|
|
@@ -405,7 +405,6 @@
|
|
|
405
405
|
"Today": "Today",
|
|
406
406
|
"Clear": "Clear",
|
|
407
407
|
"Enter a valid date (YYYY-MM-DD).": "Enter a valid date (YYYY-MM-DD).",
|
|
408
|
-
"Load preview": "Load preview",
|
|
409
408
|
"Preview unavailable": "Preview unavailable",
|
|
410
409
|
"History": "History",
|
|
411
410
|
"Snapshot message": "Snapshot message",
|