From e2be4e39120ce9891069bfa169130e59089b2ac2 Mon Sep 17 00:00:00 2001 From: webbeef Date: Tue, 3 Nov 2026 21:28:08 -0800 Subject: [PATCH] system: update color picker Signed-off-by: webbeef --- ui/shared/context_menu.js | 16 ++--- ui/system/color_picker.css | 20 +++---- ui/system/color_picker.js | 15 +++++ ui/system/desktop/index.html | 1 + ui/system/desktop/index.js | 7 ++- ...ine_context_menu.js => engine_controls.js} | 58 ++++++++++++++----- ui/system/mobile/index.html | 1 + ui/system/mobile/index.js | 7 ++- ui/system/web_view.js | 56 +++++++++--------- 9 files changed, 114 insertions(+), 67 deletions(-) rename ui/system/{engine_context_menu.js => engine_controls.js} (55%) diff --git a/ui/shared/context_menu.js b/ui/shared/context_menu.js index af3a844..d0e7872 100644 --- a/ui/shared/context_menu.js +++ b/ui/shared/context_menu.js @@ -131,17 +131,17 @@ export class ContextMenu extends MenuBase { > ${ - item.icon - ? html`` - : "" - } + item.icon + ? html`` + : "" + } ${item.label} ${ - item.checked - ? html`` - : "" - } + item.checked + ? html`` + : "" + } `, )} diff --git a/ui/system/color_picker.css b/ui/system/color_picker.css index 4c62fa4..fdaee60 100644 --- a/ui/system/color_picker.css +++ b/ui/system/color_picker.css @@ -2,12 +2,9 @@ :host { display: none; - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - z-index: var(--z-modal); + position: fixed; + inset: 0; + z-index: var(--z-modal, 40); } :host([open]) { @@ -15,21 +12,20 @@ } .backdrop { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; + position: fixed; + inset: 0; background: var(--color-backdrop); } .picker { - position: absolute; + position: fixed; background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: 0 8px 32px var(--color-shadow); padding: var(--spacing-2xl); min-width: 280px; + max-height: calc(100vh - 16px); + overflow-y: auto; font-family: var(--font-family-base); font-size: var(--font-size-base); } diff --git a/ui/system/color_picker.js b/ui/system/color_picker.js index 526235c..8f4e460 100644 --- a/ui/system/color_picker.js +++ b/ui/system/color_picker.js @@ -63,6 +63,21 @@ export class ColorPicker extends LitElement { if (changedProperties.has("currentColor") && this.currentColor) { this.parseInitialColor(); } + if (this.open) this._clamp(); + } + + /** Keep the picker fully onscreen (the menu does the same thing). */ + _clamp() { + const picker = this.renderRoot.querySelector(".picker"); + if (!picker) return; + picker.style.left = `${Math.max( + 8, + Math.min(this.x, window.innerWidth - picker.offsetWidth - 8), + )}px`; + picker.style.top = `${Math.max( + 8, + Math.min(this.y, window.innerHeight - picker.offsetHeight - 8), + )}px`; } disconnectedCallback() { diff --git a/ui/system/desktop/index.html b/ui/system/desktop/index.html index f4cdcae..35621f6 100644 --- a/ui/system/desktop/index.html +++ b/ui/system/desktop/index.html @@ -488,5 +488,6 @@ + diff --git a/ui/system/desktop/index.js b/ui/system/desktop/index.js index dc306fe..3dbcc50 100644 --- a/ui/system/desktop/index.js +++ b/ui/system/desktop/index.js @@ -10,7 +10,7 @@ import { WebView } from "../web_view.js"; import { initApp, createNewView, openView } from "../app.js"; -import { initEngineContextMenu } from "../engine_context_menu.js"; +import { initEngineControls } from "../engine_controls.js"; import { registerPanel, handleClick as handleNotificationClick, @@ -1133,7 +1133,10 @@ initShortcuts({ closeOverview, persist, }); -initEngineContextMenu(document.getElementById("engine-menu")); +initEngineControls( + document.getElementById("engine-menu"), + document.getElementById("engine-color-picker"), +); const params = new URLSearchParams(window.location.search); // Open the start URL only when there's nothing else to show. Restored // snapshot or `?open=URL` both suppress the default tab. diff --git a/ui/system/engine_context_menu.js b/ui/system/engine_controls.js similarity index 55% rename from ui/system/engine_context_menu.js rename to ui/system/engine_controls.js index 055dc10..3a93f3e 100644 --- a/ui/system/engine_context_menu.js +++ b/ui/system/engine_controls.js @@ -1,22 +1,24 @@ // SPDX-License-Identifier: AGPL-3.0-or-later -// The engine's menus (context menus and dropdowns, color +// pickers), hosted at the shell's chrome layer. // -// A menu inside a webview tile stacks below the dock (desk layers sit at -// z 1-2, the dock at 10), so one shared lives at the shell -// root. A web_view asks with "show-context-menu" or "show-select-menu" and +// A control inside a webview tile stacks below the dock (desk layers sit at +// z 1-2, the dock at 10), so one shared and one +// live at the shell root. A web_view asks with +// "show-context-menu" / "show-select-menu" / "show-color-picker" and // retracts with the matching hide event; this module remembers the -// requester and its kind, and hands picks back to it directly (the -// component's menu-action / menu-cancel / menu-closed come only from this -// one element, so nothing fans out to other webviews or menu kinds). +// requester and its kind, and hands answers back to it directly (the +// components' events come only from these two elements, so nothing fans +// out to other webviews or control kinds). import "beaver://shared/context_menu.js"; +import "./color_picker.js"; -// The web_view whose menu is open, if any, and which kind. The menu is a -// singleton, so one owner at a time is the whole story. +// The web_view whose control is open, if any, and which kind. One open +// control at a time is the whole story. let owner = null; -let ownerKind = null; // "context" | "select" +let ownerKind = null; // "context" | "select" | "color" /**