From 462f1db833609b0216fac0f725370efb9d15f00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=85=E8=86=80?= Date: Sat, 17 Oct 2026 13:23:17 +0800 Subject: [PATCH] fix(editors): focus the dialog without selecting its name field Cancel the non-bubbling FocusScope mount event in the capture phase and focus the dialog itself. Keep keyboard navigation working without highlighting the name or opening the touch keyboard automatically. --- AGENTS.md | 4 ++-- app/assets/css/main.css | 5 +++++ app/components/GroupEditor.vue | 1 + app/components/RouteEditor.vue | 1 + app/composables/useDialogFocus.ts | 26 ++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 app/composables/useDialogFocus.ts diff --git a/AGENTS.md b/AGENTS.md index dc4817a..9ae1251 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,7 +18,7 @@ Core pipeline: GitHub Webhook → Worker (verify + filter + format) → Discord - Per-group webhook ingress: optional `POST /webhook/{groupId}` with a per-group secret in KV (`tenant:{groupId}`) — Gitea/classic-GitHub/custom webhooks are verified against the group's secret instead of the operator's global ones; only that group's routes fire. The legacy `POST /webhook` (global secrets, all routes) stays untouched - GitHub App tenant isolation: `Group.installationId` binds a group to one GitHub App installation; events whose `payload.installation.id` differs are rejected at dispatch (hard isolation on top of the optional `owners` list). The App's Setup URL points at `GET /auth/github/install`, which renders a choice page (create `inst-{installationId}` or bind to a group the signed-in user owns, verified by role); `POST /auth/github/install/bind` performs the provisioning. `installation.created` webhook events auto-provision as a fallback (create `inst-{installationId}` or bind existing groups whose `owners` match the installing account) - GitHub OAuth: octokit (token is stored hashed for reverse lookup) -- Admin WebUI: `/admin` config console, OAuth-session protected via `ADMIN_USER_IDS` whitelist (local-only `DEBUG_MODE=true` bypasses authentication); left sidebar navigation (Overview / Groups / Send Logs / Audit / Stats) + topbar, deep-linkable routes (`/admin` overview · `/admin/groups` · `/admin/groups/{groupId}` a group's routes, members and webhook · `/admin/logs` · `/admin/audit` · `/admin/metrics`, parsed by `app/utils/admin-path.ts`; the admin page's `validate` 404s any other path); every page is a history entry, so the browser's back button returns from a group to the list (no in-page back button) and leaving with an open editor or an unsaved route order asks first; sign-out asks for confirmation (sidebar, or a top-right button on narrow screens); the overview dashboard (`AdminHome.vue`) aggregates delivery KPIs, a routes table and recent send logs; the stats page (`MetricsPanel.vue`) renders KPI cards plus per-platform/per-event ok/failed bar legends and a per-status breakdown, and filters by group (`?groupId=`); the route/group editors (`RouteEditor.vue` / `GroupEditor.vue`) are centered, scrollable `RcDialog` forms with an eyebrow header and sectioned bodies +- Admin WebUI: `/admin` config console, OAuth-session protected via `ADMIN_USER_IDS` whitelist (local-only `DEBUG_MODE=true` bypasses authentication); left sidebar navigation (Overview / Groups / Send Logs / Audit / Stats) + topbar, deep-linkable routes (`/admin` overview · `/admin/groups` · `/admin/groups/{groupId}` a group's routes, members and webhook · `/admin/logs` · `/admin/audit` · `/admin/metrics`, parsed by `app/utils/admin-path.ts`; the admin page's `validate` 404s any other path); every page is a history entry, so the browser's back button returns from a group to the list (no in-page back button) and leaving with an open editor or an unsaved route order asks first; sign-out asks for confirmation (sidebar, or a top-right button on narrow screens); editor dialogs open without focusing a field (`useDialogFocus`); the overview dashboard (`AdminHome.vue`) aggregates delivery KPIs, a routes table and recent send logs; the stats page (`MetricsPanel.vue`) renders KPI cards plus per-platform/per-event ok/failed bar legends and a per-status breakdown, and filters by group (`?groupId=`); the route/group editors (`RouteEditor.vue` / `GroupEditor.vue`) are centered, scrollable `RcDialog` forms with an eyebrow header and sectioned bodies - Access control: every group has role-based members (`owner` / `admin` / `viewer`); super admins bypass; legacy `adminIds` are read as owners (backward compatible); owners manage members + invites; `owners` field stays super-only - Invites: single-use 7-day links (`invite:{token}`) for joining a group as admin/viewer; `ALLOW_SELF_SIGNUP=1` gives access-less users a personal group on first login (self-service SaaS entry) - Audit log: every admin operation (logins, group/route/member/invite changes) recorded in D1 `audit_logs`; pruned by the scheduled trigger after `AUDIT_RETENTION_DAYS` (default 90) @@ -42,7 +42,7 @@ app/ # Vue 3 UI (Nuxt app dir) │ # ConfirmDialog (app-wide destructive-action confirm), SendLogs, AuditLog, MetricsPanel, │ # AppToasts, LegalLayout ├── composables/ # useI18n, useToasts, useConfirm (promise-based confirm), useBackdropGuard (editor dialogs ignore -│ # backdrop clicks), useGroups, useGroupRoutes, useFilterNode (AST helpers), useFragments, useLogs, +│ # backdrop clicks), useDialogFocus (editor dialogs open without focusing a field), useGroups, useGroupRoutes, useFilterNode (AST helpers), useFragments, useLogs, │ # useAudit, useInvites, useWebhook ├── types.ts # shared client types (Route, Group, Filter, ...) └── utils/ # legal.ts (terms/privacy HTML bodies, zh/en), format.ts, admin-path.ts (console URL parsing), diff --git a/app/assets/css/main.css b/app/assets/css/main.css index d4e287f..9dbdc54 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -553,6 +553,11 @@ padding: 0 !important; } + /* The dialog itself takes focus on open (useDialogFocus); its fields show the ring. */ + .editor-dialog:focus { + outline: none; + } + .editor-dialog > div:first-child { margin-bottom: 0 !important; flex-shrink: 0 !important; diff --git a/app/components/GroupEditor.vue b/app/components/GroupEditor.vue index 8799d7f..c2c9468 100644 --- a/app/components/GroupEditor.vue +++ b/app/components/GroupEditor.vue @@ -345,6 +345,7 @@ function close(): void { // A click on the backdrop must not discard what has been typed so far. const { isBackdropClose } = useBackdropGuard(() => props.open, ".editor-dialog"); +useDialogFocus(() => props.open, ".editor-dialog"); function onOpenChange(open: boolean): void { if (!open && !isBackdropClose()) close(); diff --git a/app/components/RouteEditor.vue b/app/components/RouteEditor.vue index 84aa6a5..3b36cc0 100644 --- a/app/components/RouteEditor.vue +++ b/app/components/RouteEditor.vue @@ -260,6 +260,7 @@ function close(): void { // A click on the backdrop must not discard what has been typed so far. const { isBackdropClose } = useBackdropGuard(() => props.open, ".editor-dialog"); +useDialogFocus(() => props.open, ".editor-dialog"); function onOpenChange(open: boolean): void { if (!open && !isBackdropClose()) close(); diff --git a/app/composables/useDialogFocus.ts b/app/composables/useDialogFocus.ts new file mode 100644 index 0000000..5e54903 --- /dev/null +++ b/app/composables/useDialogFocus.ts @@ -0,0 +1,26 @@ +/** + * Opens an editor dialog without jumping into its first field. reka-ui's + * FocusScope focuses and *selects* the first input on open, which highlights + * the name as if about to overwrite it and pops up the keyboard on touch + * screens. Its mount auto-focus is announced with a non-bubbling, cancelable + * event — RcDialog exposes no `openAutoFocus` hook — so it is caught here in + * the capture phase and focus goes to the dialog itself instead: Escape and + * Tab keep working, the fields stay untouched until the user picks one. + */ +export function useDialogFocus(isOpen: () => boolean, dialogSelector: string) { + function onMountAutoFocus(event: Event): void { + const dialog = event.target; + if (!(dialog instanceof HTMLElement) || !dialog.matches(dialogSelector)) return; + event.preventDefault(); + dialog.focus({ preventScroll: true }); + } + + function listen(on: boolean): void { + if (typeof document === "undefined") return; + if (on) document.addEventListener("focusScope.autoFocusOnMount", onMountAutoFocus, true); + else document.removeEventListener("focusScope.autoFocusOnMount", onMountAutoFocus, true); + } + + watch(isOpen, listen, { immediate: true }); + onBeforeUnmount(() => listen(false)); +}