Add copy buttons to code blocks and tool input and output
This commit is contained in:
Vendored
+17
@@ -26,6 +26,23 @@ export function replace(el, ...children) {
|
||||
el.replaceChildren();
|
||||
append(el, ...children);
|
||||
}
|
||||
export function copyable(pre) {
|
||||
const button = h("button", { type: "button", class: "copy", title: "Copy to the clipboard" }, "copy");
|
||||
button.onclick = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(pre.textContent ?? "");
|
||||
}
|
||||
catch (err) {
|
||||
void showAlert(errorText(err));
|
||||
return;
|
||||
}
|
||||
button.textContent = "copied";
|
||||
setTimeout(() => {
|
||||
button.textContent = "copy";
|
||||
}, 1500);
|
||||
};
|
||||
return h("div", { class: "copyable" }, pre, button);
|
||||
}
|
||||
export function ago(iso) {
|
||||
const seconds = Math.round((Date.now() - Date.parse(iso)) / 1000);
|
||||
if (seconds < 60) {
|
||||
|
||||
Reference in New Issue
Block a user