Agent Zero AI framework
add copy btn to code blocks and tables
3clyp50d189156a1658
diff --git a/webui/components/messages/action-buttons/simple-action-buttons.css b/webui/components/messages/action-buttons/simple-action-buttons.cssindex b9d3279f1..83450cc5a 100644--- a/webui/components/messages/action-buttons/simple-action-buttons.css+++ b/webui/components/messages/action-buttons/simple-action-buttons.css@@ -14,7 +14,8 @@pointer-events: none;}-.step-action-buttons .action-button {+.step-action-buttons .action-button,+.action-button {display: flex;align-items: center;justify-content: center;@@ -24,7 +25,8 @@cursor: pointer;}-.step-action-buttons .action-button .material-symbols-outlined {+.step-action-buttons .action-button .material-symbols-outlined,+.action-button .material-symbols-outlined {font-size: 0.85rem;line-height: 1;color: var(--color-message-text);@@ -32,18 +34,21 @@transition: color 0.15s ease;}-.step-action-buttons .action-button:hover .material-symbols-outlined {+.step-action-buttons .action-button:hover .material-symbols-outlined,+.action-button:hover .material-symbols-outlined {color: var(--color-text);}/* Success state */-.step-action-buttons .action-button.success .material-symbols-outlined {+.step-action-buttons .action-button.success .material-symbols-outlined,+.action-button.success .material-symbols-outlined {color: #4CAF50;font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 20;}/* Error state */-.step-action-buttons .action-button.error .material-symbols-outlined {+.step-action-buttons .action-button.error .material-symbols-outlined,+.action-button.error .material-symbols-outlined {color: var(--color-accent);font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 20;}@@ -65,6 +70,13 @@pointer-events: auto;}+/* Code blocks and tables: show copy button on hover */+.device-pointer .code-block-wrapper:hover .step-action-buttons,+.device-pointer .message-markdown-table-wrap:hover .step-action-buttons {+ opacity: 1;+ pointer-events: auto;+}+/* ===========================================Touch devices - Always visible=========================================== */diff --git a/webui/css/messages.css b/webui/css/messages.cssindex 176ae987d..30a9fffc6 100644--- a/webui/css/messages.css+++ b/webui/css/messages.css@@ -732,6 +732,23 @@border-radius: 0.3em;}+/* Code block and table copy buttons */+.code-block-wrapper,+.message-markdown-table-wrap {+ position: relative;+}++.overlay-actions {+ position: absolute;+ top: 0;+ right: 0;+ background: var(--color-panel);+ border-radius: var(--border-radius-sm);+ z-index: 1;+ padding: 2px !important;+ gap: 0 !important;+}+.msg-content hr {border: 0;border-top: 1px solid var(--color-border);diff --git a/webui/js/messages.js b/webui/js/messages.jsindex 3337b5f09..e96f96bb8 100644--- a/webui/js/messages.js+++ b/webui/js/messages.js@@ -1883,16 +1883,57 @@ function convertPathsToLinks(str) {.join("");}+// markdown render helpers //++// wraps an element with a container div+const wrapElement = (el, className) => {+ const wrapper = document.createElement("div");+ wrapper.className = className;+ el.parentNode.insertBefore(wrapper, el);+ wrapper.appendChild(el);+ return wrapper;+};++// data extractors+const extractTableTSV = (table) =>+ [...table.rows]+ .map((row) =>+ [...row.cells]+ .map((cell) => cell.textContent.replace(/\t/g, " ").replace(/\n/g, " "))+ .join("\t"),+ )+ .join("\n");+function adjustMarkdownRender(element) {// find all tables in the element- const elements = element.querySelectorAll("table");-- // wrap each with a div with class message-markdown-table-wrap- elements.forEach((el) => {- const wrapper = document.createElement("div");- wrapper.className = "message-markdown-table-wrap";- el.parentNode.insertBefore(wrapper, el);- wrapper.appendChild(el);+ const tables = element.querySelectorAll("table");+ tables.forEach((el) => {+ if (el.parentNode.classList.contains("message-markdown-table-wrap"))+ return;+ const wrapper = wrapElement(el, "message-markdown-table-wrap");++ // create copy button directly+ const copyBtn = createActionButton("copy", "", () =>+ copyToClipboard(extractTableTSV(el))+ );+ copyBtn.classList.add("step-action-buttons", "overlay-actions");+ wrapper.appendChild(copyBtn);+ });++ // find all code blocks+ // we select the code element to ensure valid targets, then wrap the parent pre+ const codeElements = element.querySelectorAll("pre > code");+ codeElements.forEach((code) => {+ const pre = code.parentNode;+ if (pre.parentNode.classList.contains("code-block-wrapper")) return;+ const wrapper = wrapElement(pre, "code-block-wrapper");++ // create copy button directly+ const copyBtn = createActionButton("copy", "", () =>+ copyToClipboard(code.textContent)+ );+ copyBtn.classList.add("step-action-buttons", "overlay-actions");+ wrapper.appendChild(copyBtn);});// find all images