Skip to content

Agent Zero AI framework

Make browser annotation tray draggable

Alessandro39a96012f998
diff --git a/plugins/_browser/webui/browser-panel.html b/plugins/_browser/webui/browser-panel.html
index 1b70bf677..c25cfa167 100644
--- a/plugins/_browser/webui/browser-panel.html
+++ b/plugins/_browser/webui/browser-panel.html
@@ -220,9 +220,15 @@
</template>
<div class="browser-annotation-tray"
x-show="$store.browserPage.visibleAnnotations().length"
+ :class="{ 'is-floating': $store.browserPage.annotationTrayPosition, 'is-dragging': $store.browserPage.annotationTrayDragging }"
+ :style="$store.browserPage.annotationTrayStyle()"
x-transition style="display: none;"
- @click.stop @pointerdown.stop @keydown.stop>
- <div class="browser-annotation-tray-header">
+ @click.stop @pointerdown.stop @keydown.stop
+ @pointermove.window="$store.browserPage.moveAnnotationTrayDrag($event)"
+ @pointerup.window="$store.browserPage.finishAnnotationTrayDrag($event)"
+ @pointercancel.window="$store.browserPage.finishAnnotationTrayDrag($event)">
+ <div class="browser-annotation-tray-header"
+ @pointerdown.stop="$store.browserPage.startAnnotationTrayDrag($event)">
<span>Annotations</span>
<button type="button" class="browser-annotation-clear" title="Clear annotations"
aria-label="Clear annotations" @click="$store.browserPage.clearVisibleAnnotations()">
@@ -990,7 +996,6 @@
.browser-annotation-popover,
.browser-annotation-tray {
position: absolute;
- z-index: 18;
border: 1px solid color-mix(in srgb, var(--color-border) 76%, transparent);
border-radius: 7px;
background: color-mix(in srgb, var(--color-background) 96%, #000 4%);
@@ -999,6 +1004,7 @@
}
.browser-annotation-popover {
+ z-index: 24;
display: flex;
flex-direction: column;
gap: 8px;
@@ -1044,6 +1050,7 @@
}
.browser-annotation-tray {
+ z-index: 20;
right: 10px;
bottom: 10px;
display: flex;
@@ -1054,8 +1061,18 @@
padding: 10px;
}
+ .browser-annotation-tray.is-dragging {
+ user-select: none;
+ }
+
.browser-annotation-tray-header {
justify-content: space-between;
+ cursor: grab;
+ user-select: none;
+ }
+
+ .browser-annotation-tray.is-dragging .browser-annotation-tray-header {
+ cursor: grabbing;
}
.browser-annotation-clear,
diff --git a/plugins/_browser/webui/browser-store.js b/plugins/_browser/webui/browser-store.js
index 09f3a12b2..c20630273 100644
--- a/plugins/_browser/webui/browser-store.js
+++ b/plugins/_browser/webui/browser-store.js
@@ -23,6 +23,7 @@ const FRAME_REJECT_SYNC_COOLDOWN_MS = 600;
const ANNOTATION_DRAG_THRESHOLD = 6;
const ANNOTATION_MAX_COMMENTS = 24;
const ANNOTATION_DOM_LIMIT = 1200;
+const ANNOTATION_TRAY_MARGIN = 10;
function makeViewerToken() {
return globalThis.crypto?.randomUUID?.()
@@ -106,6 +107,8 @@ const model = {
annotationDragRect: null,
annotationBusy: false,
annotationError: "",
+ annotationTrayPosition: null,
+ annotationTrayDragging: false,
connected: false,
switchingBrowserId: null,
commandInFlight: false,
@@ -127,6 +130,7 @@ const model = {
_lastViewportKey: "",
_lastViewport: null,
_annotationPointer: null,
+ _annotationTrayDrag: null,
_annotationSequence: 0,
_mode: "",
_surfaceMounted: false,
@@ -1588,8 +1592,93 @@ const model = {
return this.visibleAnnotations().length + 1;
},
+ annotationTrayStyle() {
+ if (!this.annotationTrayPosition) return {};
+ const position = this.clampAnnotationTrayPosition(this.annotationTrayPosition);
+ return {
+ left: `${position.x}px`,
+ top: `${position.y}px`,
+ right: "auto",
+ bottom: "auto",
+ };
+ },
+
+ clampAnnotationTrayPosition(position = {}) {
+ const stageRect = this._stageElement?.getBoundingClientRect?.();
+ const stageWidth = Math.max(1, Number(stageRect?.width || 0));
+ const stageHeight = Math.max(1, Number(stageRect?.height || 0));
+ const width = Math.max(180, Number(position.width || 0));
+ const height = Math.max(90, Number(position.height || 0));
+ const maxX = Math.max(ANNOTATION_TRAY_MARGIN, stageWidth - width - ANNOTATION_TRAY_MARGIN);
+ const maxY = Math.max(ANNOTATION_TRAY_MARGIN, stageHeight - height - ANNOTATION_TRAY_MARGIN);
+ return {
+ x: Math.min(Math.max(ANNOTATION_TRAY_MARGIN, Number(position.x || 0)), maxX),
+ y: Math.min(Math.max(ANNOTATION_TRAY_MARGIN, Number(position.y || 0)), maxY),
+ width,
+ height,
+ };
+ },
+
+ startAnnotationTrayDrag(event) {
+ if (event.button !== 0) return;
+ if (event.target?.closest?.("button, input, select, textarea, a")) return;
+ const tray = event.currentTarget?.closest?.(".browser-annotation-tray");
+ const stageRect = this._stageElement?.getBoundingClientRect?.();
+ const trayRect = tray?.getBoundingClientRect?.();
+ if (!tray || !stageRect || !trayRect) return;
+
+ const position = this.clampAnnotationTrayPosition({
+ x: trayRect.left - stageRect.left,
+ y: trayRect.top - stageRect.top,
+ width: trayRect.width,
+ height: trayRect.height,
+ });
+ this.annotationTrayPosition = position;
+ this.annotationTrayDragging = true;
+ this._annotationTrayDrag = {
+ id: event.pointerId,
+ target: event.currentTarget,
+ x: event.clientX,
+ y: event.clientY,
+ startX: position.x,
+ startY: position.y,
+ width: position.width,
+ height: position.height,
+ };
+ event.currentTarget?.setPointerCapture?.(event.pointerId);
+ event.preventDefault();
+ },
+
+ moveAnnotationTrayDrag(event) {
+ const drag = this._annotationTrayDrag;
+ if (!drag || event.pointerId !== drag.id) return;
+ this.annotationTrayPosition = this.clampAnnotationTrayPosition({
+ x: drag.startX + event.clientX - drag.x,
+ y: drag.startY + event.clientY - drag.y,
+ width: drag.width,
+ height: drag.height,
+ });
+ event.preventDefault();
+ },
+
+ finishAnnotationTrayDrag(event = null) {
+ const drag = this._annotationTrayDrag;
+ if (!drag || (event?.pointerId && event.pointerId !== drag.id)) return;
+ try {
+ drag.target?.releasePointerCapture?.(drag.id);
+ } catch {}
+ this._annotationTrayDrag = null;
+ this.annotationTrayDragging = false;
+ },
+
+ resetAnnotationTrayPosition() {
+ this.finishAnnotationTrayDrag();
+ this.annotationTrayPosition = null;
+ },
+
clearVisibleAnnotations() {
this.clearAnnotationsForBrowser(this.activeBrowserId, this.activeAnnotationUrl(), this.activeBrowserContextId);
+ this.resetAnnotationTrayPosition();
},
clearAnnotationsForBrowser(browserId, url = null, contextId = "") {
@@ -1821,6 +1910,9 @@ const model = {
removeAnnotationComment(annotationId) {
this.annotationComments = this.annotationComments.filter((annotation) => annotation.id !== annotationId);
+ if (!this.visibleAnnotations().length) {
+ this.resetAnnotationTrayPosition();
+ }
},
annotationChipLabel(annotation) {
@@ -2114,6 +2206,7 @@ const model = {
this.annotationError = "";
this.cancelAnnotationDraft();
this.cancelAnnotationSelection();
+ this.resetAnnotationTrayPosition();
if (this.contextId) {
try {
await websocket.emit("browser_viewer_unsubscribe", { context_id: this.contextId });
diff --git a/tests/test_browser_agent_regressions.py b/tests/test_browser_agent_regressions.py
index a4da1cccd..6c14fd5ed 100644
--- a/tests/test_browser_agent_regressions.py
+++ b/tests/test_browser_agent_regressions.py
@@ -788,11 +788,15 @@ def test_browser_annotate_mode_ui_and_prompt_hooks():
assert "Annotating" in panel_html
assert "browser-annotation-layer" in panel_html
assert "browser-annotation-tray" in panel_html
+ assert "annotationTrayStyle()" in panel_html
+ assert "startAnnotationTrayDrag($event)" in panel_html
assert "Draft to chat" in panel_html
assert "Send now" in panel_html
assert "@pointerdown.stop.prevent=\"$store.browserPage.startAnnotationSelection($event)\"" in panel_html
assert "@keydown.window=\"$store.browserPage.handleKeydown($event)\"" in panel_html
assert "annotationComments: []" in browser_store
+ assert "annotationTrayPosition: null" in browser_store
+ assert "clampAnnotationTrayPosition" in browser_store
assert '"browser_viewer_annotation"' in browser_store
assert 'event?.key === "." && (event.metaKey || event.ctrlKey)' in browser_store
assert "Browser annotations" in browser_store