From a8418c06d9e6824e93f894537f0aee8dc0d1e411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=85=E8=86=80?= Date: Sat, 17 Oct 2026 08:12:55 +0800 Subject: [PATCH] fix(editors): ignore accidental backdrop dismissal Do not discard unsaved route or group edits when the user clicks outside the dialog. Preserve Escape, Cancel and explicit close, including popovers and confirmation dialogs stacked above the editor. --- AGENTS.md | 3 +- app/components/GroupEditor.vue | 5 +++- app/components/RouteEditor.vue | 5 +++- app/composables/useBackdropGuard.ts | 46 +++++++++++++++++++++++++++++ docs/guide/configuration.md | 2 +- docs/zh/guide/configuration.md | 2 +- 6 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 app/composables/useBackdropGuard.ts diff --git a/AGENTS.md b/AGENTS.md index 68d7089..3dde009 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -41,7 +41,8 @@ app/ # Vue 3 UI (Nuxt app dir) │ # AST builder + FilterCombobox searchable inputs), GroupEditor, MembersPanel, WebhookPanel, │ # ConfirmDialog (app-wide destructive-action confirm), SendLogs, AuditLog, MetricsPanel, │ # AppToasts, LegalLayout -├── composables/ # useI18n, useToasts, useConfirm (promise-based confirm), useGroups, useGroupRoutes, useFilterNode (AST helpers), useFragments, useLogs, +├── composables/ # useI18n, useToasts, useConfirm (promise-based confirm), useBackdropGuard (editor dialogs ignore +│ # backdrop clicks), 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, diff --git a/app/components/GroupEditor.vue b/app/components/GroupEditor.vue index 71dc35d..8799d7f 100644 --- a/app/components/GroupEditor.vue +++ b/app/components/GroupEditor.vue @@ -343,8 +343,11 @@ function close(): void { emit("close"); } +// A click on the backdrop must not discard what has been typed so far. +const { isBackdropClose } = useBackdropGuard(() => props.open, ".editor-dialog"); + function onOpenChange(open: boolean): void { - if (!open) close(); + if (!open && !isBackdropClose()) close(); } function save(): void { diff --git a/app/components/RouteEditor.vue b/app/components/RouteEditor.vue index 5c2c1f0..84aa6a5 100644 --- a/app/components/RouteEditor.vue +++ b/app/components/RouteEditor.vue @@ -258,8 +258,11 @@ function close(): void { emit("close"); } +// A click on the backdrop must not discard what has been typed so far. +const { isBackdropClose } = useBackdropGuard(() => props.open, ".editor-dialog"); + function onOpenChange(open: boolean): void { - if (!open) close(); + if (!open && !isBackdropClose()) close(); } async function runTest(): Promise { diff --git a/app/composables/useBackdropGuard.ts b/app/composables/useBackdropGuard.ts new file mode 100644 index 0000000..85fab89 --- /dev/null +++ b/app/composables/useBackdropGuard.ts @@ -0,0 +1,46 @@ +/** + * Keeps an editor dialog open when the user clicks outside it, so a stray click + * on the backdrop never throws away unsaved input. RcDialog exposes no hook for + * reka's `interactOutside`, so this watches pointer-downs while the dialog is + * open: a press outside the dialog (and outside any popover or dialog stacked + * above it) marks the close request it triggers as one to ignore. Escape, the + * close button and Cancel keep closing the dialog. + */ +export function useBackdropGuard(isOpen: () => boolean, dialogSelector: string) { + let pressedOutside = false; + + function onPointerDown(event: PointerEvent): void { + const target = event.target as Element | null; + pressedOutside = !target?.closest?.( + `${dialogSelector}, [data-dismissable-layer], [data-reka-popper-content-wrapper]`, + ); + } + + function onKeyDown(): void { + pressedOutside = false; + } + + function listen(on: boolean): void { + if (typeof document === "undefined") return; + if (on) { + document.addEventListener("pointerdown", onPointerDown, true); + document.addEventListener("keydown", onKeyDown, true); + return; + } + document.removeEventListener("pointerdown", onPointerDown, true); + document.removeEventListener("keydown", onKeyDown, true); + pressedOutside = false; + } + + watch(isOpen, listen, { immediate: true }); + onBeforeUnmount(() => listen(false)); + + /** Whether the pending close request came from a press outside the dialog. */ + function isBackdropClose(): boolean { + const outside = pressedOutside; + pressedOutside = false; + return outside; + } + + return { isBackdropClose }; +} diff --git a/docs/guide/configuration.md b/docs/guide/configuration.md index 599125e..e43e28b 100644 --- a/docs/guide/configuration.md +++ b/docs/guide/configuration.md @@ -65,7 +65,7 @@ For local debugging only, set `DEBUG_MODE=true` to bypass GitHub OAuth and grant The console is served as an SPA at `/admin`; its tabs are deep-linkable via the URL path (`/admin/groups`, `/admin/logs`, `/admin/audit`). URLs outside `/admin` that do not match an endpoint return a plain `404` instead of the console. -Destructive actions — deleting routes, groups, filter conditions, fragments, targets or forge hosts, removing members, revoking invites, disabling a group's webhook — ask for confirmation in an in-app dialog (empty, never-filled rows are removed directly). +Destructive actions — deleting routes, groups, filter conditions, fragments, targets or forge hosts, removing members, revoking invites, disabling a group's webhook — ask for confirmation in an in-app dialog (empty, never-filled rows are removed directly). The route and group editors ignore clicks on the backdrop so unsaved input is never lost; close them with Cancel, ✕ or Esc. All management endpoints (`/admin/api/*`) are documented in the [Admin API](../api/admin). Saved routes and groups are persisted to D1 (`d1_routes` / `d1_groups`) immediately, the KV cache is invalidated and the config cache is refreshed so the webhook pipeline picks them up on the next run. diff --git a/docs/zh/guide/configuration.md b/docs/zh/guide/configuration.md index caf47d9..0ccf04d 100644 --- a/docs/zh/guide/configuration.md +++ b/docs/zh/guide/configuration.md @@ -64,7 +64,7 @@ WebHooker 在 `/admin` 提供内置配置控制台,可在浏览器中管理路 控制台以 SPA 形式在 `/admin` 提供;其标签页可通过 URL 路径直达(`/admin/groups`、`/admin/logs`、`/admin/audit`)。`/admin` 之外未匹配到端点的 URL 直接返回 `404`,而不会展示控制台。 -删除类操作——删除路由、分组、过滤条件、片段、目标或来源主机,移除成员,撤销邀请,停用分组 webhook——都会先弹出应用内确认框(从未填写过的空行直接删除)。 +删除类操作——删除路由、分组、过滤条件、片段、目标或来源主机,移除成员,撤销邀请,停用分组 webhook——都会先弹出应用内确认框(从未填写过的空行直接删除)。路由与分组编辑弹窗点击遮罩不会关闭,避免丢失未保存的内容;请用「取消」、✕ 或 Esc 关闭。 所有管理端点(`/admin/api/*`)见 [Admin API](../api/admin)。保存的路由和分组会立即持久化到 D1(`d1_routes` / `d1_groups`),并使 KV 缓存失效、刷新配置缓存,下一次 webhook 处理即会生效。