forge
Explore
Log in

Don't you dare go Hollow

One dropdown, one ring

Browse files at this commit

dce3af045a7b5f25c07e563590378a43249c5671Ahmet Kaan GümüşParent: f19924d
  • feat
    • one dropdown, one ring
Show full message
✨ feat(web): one dropdown, one ring
crates/izlek-web/src/board.rsmodified+16 -12
@@ -378,13 +378,12 @@ async fn render_card(
378 /// open; a plain document click closes it again. Rendered once — every378 /// open; a plain document click closes it again. Rendered once — every
379 /// card's `@contextmenu` calls into this same global, by the menu's id.379 /// card's `@contextmenu` calls into this same global, by the menu's id.
380 ///380 ///
381-/// Also holds the board page's own `Escape` listener — now only the381+/// Also registers the board page's own `Escape` resolvers on
382-/// datepicker panel and the card menu: viewer, delete confirm, open edit382+/// `window.__izlekEsc`: the datepicker panel (priority 100, above the modal
383-/// popovers and the modal itself belong to `detail::escape_closes`, which383+/// chain — `detail::escape_closes` used to defer to it) and the card menu
384-/// registers first (inline in the modal markup) and stops the key. The384+/// (priority 10). Viewer, delete confirm, open edit popovers and the modal
385-/// topbar `.user-menu` is handled one script earlier, by385+/// itself stay `detail::escape_closes`'s at priority 90; the whole order
386-/// `layout::escape_script`, registered before this one so its blur wins386+/// lives in the table on `layout.rs`'s `escape_manager_script`.
387-/// over anything below.
388 async fn card_menu_script(cx: &Cx) -> Result {387 async fn card_menu_script(cx: &Cx) -> Result {
389 use topcoat::view::Unescaped;388 use topcoat::view::Unescaped;
390 const JS: &str = "\389 const JS: &str = "\
@@ -401,13 +400,18 @@ async fn card_menu_script(cx: &Cx) -> Result {
401 menu.classList.add('card-menu-open'); \400 menu.classList.add('card-menu-open'); \
402 }; \401 }; \
403 document.addEventListener('click', closeCardMenus); \402 document.addEventListener('click', closeCardMenus); \
404- document.addEventListener('keydown', function (e) { \403+ window.__izlekEsc.register(100, function () { \
405- if (e.key !== 'Escape') { return; } \
406 var datepick = document.querySelector('.datepick-pop > .edit-toggle:checked'); \404 var datepick = document.querySelector('.datepick-pop > .edit-toggle:checked'); \
407- if (datepick) { datepick.checked = false; e.stopImmediatePropagation(); return; } \405+ if (!datepick) { return false; } \
406+ datepick.checked = false; \
407+ return true; \
408+ }); \
409+ window.__izlekEsc.register(10, function () { \
408 var menu = document.querySelector('.card-menu-open'); \410 var menu = document.querySelector('.card-menu-open'); \
409- if (menu) { closeCardMenus(); e.stopImmediatePropagation(); return; } \411+ if (!menu) { return false; } \
410- }, true); \412+ closeCardMenus(); \
413+ return true; \
414+ }); \
411 document.addEventListener('contextmenu', function (e) { \415 document.addEventListener('contextmenu', function (e) { \
412 var card = e.target.closest ? e.target.closest('.card[data-menu-id]') : null; \416 var card = e.target.closest ? e.target.closest('.card[data-menu-id]') : null; \
413 if (!card) { return; } \417 if (!card) { return; } \
crates/izlek-web/src/detail.rsmodified+19 -26
@@ -675,38 +675,30 @@ async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result {
675 675
676 /// `Escape` for everything the task modal renders, topmost first: viewer →676 /// `Escape` for everything the task modal renders, topmost first: viewer →
677 /// delete confirm (`confirm=delete` in URL) → open edit popovers → modal677 /// delete confirm (`confirm=delete` in URL) → open edit popovers → modal
678-/// itself; datepick and card menu stay `board.rs`'s — this capture listener678+/// itself — one resolver at priority 90 on `window.__izlekEsc` (table on
679-/// registers first (inline in modal markup) and stops the key. Closing679+/// `layout.rs`'s `escape_manager_script`); an open datepick popover returns
680-/// never navigates: `layout.rs`'s `__izlekCloseViewer`/`__izlekCloseModal`680+/// false, leaving it to `board.rs`'s priority-100 resolver. Closing never
681-/// drop the overlay's DOM and rewrite the URL, the board underneath is681+/// navigates: `layout.rs`'s `__izlekCloseViewer`/`__izlekCloseModal` drop
682-/// already rendered. Focused native media controls swallow `Escape` before682+/// the overlay's DOM and rewrite the URL, the board underneath is already
683-/// the page ever sees the key, so focus landing on the viewer's683+/// rendered. Focused native media controls swallow `Escape` before the page
684-/// audio/video is moved straight back to the panel. Every closing branch684+/// ever sees the key, so focus landing on the viewer's audio/video is moved
685-/// still calls `preventDefault()`: a real Escape's browser default is685+/// straight back to the panel.
686-/// stop-loading (it once cancelled the navigation these branches used to
687-/// start; synthetic keys carry no default, so only a live keyboard ever
688-/// showed it).
689 async fn escape_closes(cx: &Cx) -> Result {686 async fn escape_closes(cx: &Cx) -> Result {
690 use topcoat::view::Unescaped;687 use topcoat::view::Unescaped;
691 const JS: &str = "\688 const JS: &str = "\
692 (function () { \689 (function () { \
693 if (window.__izlekEscModal) { return; } \690 if (window.__izlekEscModal) { return; } \
694 window.__izlekEscModal = true; \691 window.__izlekEscModal = true; \
695- document.addEventListener('keydown', function (e) { \692+ window.__izlekEsc.register(90, function () { \
696- if (e.key !== 'Escape') { return; } \693+ if (document.querySelector('.datepick-pop .edit-toggle:checked')) { return false; } \
697- if (document.querySelector('.datepick-pop .edit-toggle:checked')) { return; } \
698 if (document.querySelector('.viewer-scrim')) { \694 if (document.querySelector('.viewer-scrim')) { \
699- e.preventDefault(); \
700 window.__izlekCloseViewer(); \695 window.__izlekCloseViewer(); \
701- e.stopImmediatePropagation(); \696+ return true; \
702- return; \
703 } \697 } \
704 var confirm = document.querySelector('details.confirm-details[open]'); \698 var confirm = document.querySelector('details.confirm-details[open]'); \
705 if (confirm && window.location.search.indexOf('confirm=delete') !== -1) { \699 if (confirm && window.location.search.indexOf('confirm=delete') !== -1) { \
706- e.preventDefault(); \
707 window.__izlekCloseModal(); \700 window.__izlekCloseModal(); \
708- e.stopImmediatePropagation(); \701+ return true; \
709- return; \
710 } \702 } \
711 var toggled = false; \703 var toggled = false; \
712 document.querySelectorAll('.edit-toggle:checked').forEach(function (toggle) { \704 document.querySelectorAll('.edit-toggle:checked').forEach(function (toggle) { \
@@ -716,15 +708,14 @@ async fn escape_closes(cx: &Cx) -> Result {
716 }); \708 }); \
717 if (toggled || confirm) { \709 if (toggled || confirm) { \
718 if (confirm) { confirm.removeAttribute('open'); } \710 if (confirm) { confirm.removeAttribute('open'); } \
719- e.stopImmediatePropagation(); \711+ return true; \
720- return; \
721 } \712 } \
722 if (document.querySelector('.modal-scrim')) { \713 if (document.querySelector('.modal-scrim')) { \
723- e.preventDefault(); \
724 window.__izlekCloseModal(); \714 window.__izlekCloseModal(); \
725- e.stopImmediatePropagation(); \715+ return true; \
726 } \716 } \
727- }, true); \717+ return false; \
718+ }); \
728 document.addEventListener('focusin', function (e) { \719 document.addEventListener('focusin', function (e) { \
729 var media = e.target; \720 var media = e.target; \
730 if (media.tagName !== 'AUDIO' && media.tagName !== 'VIDEO') { return; } \721 if (media.tagName !== 'AUDIO' && media.tagName !== 'VIDEO') { return; } \
@@ -879,7 +870,9 @@ async fn datepicker_grid(cx: &Cx, name: &str, value: &str, lang: Lang) -> Result
879 /// nav, day pick, Clear/Today, and closes a panel on outside click —870 /// nav, day pick, Clear/Today, and closes a panel on outside click —
880 /// registered in the capture phase so a stray click never reaches871 /// registered in the capture phase so a stray click never reaches
881 /// `escape_closes`'s confirm-closing listener while a panel is open.872 /// `escape_closes`'s confirm-closing listener while a panel is open.
882-/// `Escape` itself is handled centrally by `board.rs`'s `card_menu_script`.873+/// `Escape` closes the panel through the datepick resolver `board.rs`'s
874+/// `card_menu_script` registers (priority 100 — see the table on
875+/// `layout.rs`'s `escape_manager_script`).
883 async fn datepicker_script(cx: &Cx, lang: Lang) -> Result {876 async fn datepicker_script(cx: &Cx, lang: Lang) -> Result {
884 use crate::i18n::datepicker_js_literals;877 use crate::i18n::datepicker_js_literals;
885 use topcoat::view::Unescaped;878 use topcoat::view::Unescaped;
crates/izlek-web/src/dropdown.rsmodified+8 -11
@@ -17,12 +17,10 @@ use topcoat::view::{Unescaped, view};
17 17
18 /// Emitted once per page that renders a `<select>`; the enhancement is18 /// Emitted once per page that renders a `<select>`; the enhancement is
19 /// per-element and idempotent (`data-dd-done`), re-run on `izlek:wire` so19 /// per-element and idempotent (`data-dd-done`), re-run on `izlek:wire` so
20-/// selects arriving in a soft page swap get theirs too. Owns its own `Escape`20+/// selects arriving in a soft page swap get theirs too. Owns its own
21-/// handling (capture-phase, `stopImmediatePropagation` on an open panel)21+/// `Escape` resolver on `window.__izlekEsc` (priority 50 — an open panel
22-/// rather than routing through `board.rs`'s `card_menu_script` — on any22+/// closes before the topbar and card-menu layers below it; the whole order
23-/// page carrying both, this script must be emitted *before* that one so its23+/// lives in the table on `layout.rs`'s `escape_manager_script`).
24-/// document-level capture listener, registered first, runs first and can
25-/// swallow the key before the board's own overlay chain sees it.
26 pub async fn dropdown_script(cx: &Cx) -> Result {24 pub async fn dropdown_script(cx: &Cx) -> Result {
27 const JS: &str = "\25 const JS: &str = "\
28 (function () {\26 (function () {\
@@ -119,15 +117,14 @@ pub async fn dropdown_script(cx: &Cx) -> Result {
119 if (row) { pick(select, trigger, panel, row); }\117 if (row) { pick(select, trigger, panel, row); }\
120 });\118 });\
121 }\119 }\
122- document.addEventListener('keydown', function (e) {\120+ window.__izlekEsc.register(50, function () {\
123- if (e.key !== 'Escape') { return; }\
124 var panel = document.querySelector('.dd-panel.dd-open');\121 var panel = document.querySelector('.dd-panel.dd-open');\
125- if (!panel) { return; }\122+ if (!panel) { return false; }\
126 var trigger = panel.__ddTrigger;\123 var trigger = panel.__ddTrigger;\
127 closeAll();\124 closeAll();\
128 if (trigger) { trigger.focus(); }\125 if (trigger) { trigger.focus(); }\
129- e.stopImmediatePropagation();\126+ return true;\
130- }, true);\127+ });\
131 document.addEventListener('click', closeAll);\128 document.addEventListener('click', closeAll);\
132 window.addEventListener('scroll', closeAll, true);\129 window.addEventListener('scroll', closeAll, true);\
133 function enhanceAll() { document.querySelectorAll('select.status-select, select.field-input').forEach(enhance); }\130 function enhanceAll() { document.querySelectorAll('select.status-select, select.field-input').forEach(enhance); }\
crates/izlek-web/src/layout.rsmodified+63 -19
@@ -276,40 +276,83 @@ pub async fn soft_nav_script(cx: &Cx) -> Result {
276 view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }276 view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }
277 }277 }
278 278
279-/// The one `Escape` path shared by every page that has no `board.rs`279+/// The one document-level capture `keydown` listener for `Escape`, emitted
280-/// overlay chain of its own (settings, mail rules, logs) — plus board280+/// once from `root_layout` before every page's own scripts. Owners install
281-/// itself, whose `card_menu_script` never looks at `.user-menu`. Closes,281+/// no listeners of their own; their scripts call
282-/// in order: the topbar `.user-menu` panel — hover-open included, pinned282+/// `window.__izlekEsc.register(priority, fn)` and on `Escape` the manager
283-/// shut by a `user-menu-esc` class that a `mouseenter` inside the menu283+/// runs the resolvers highest-priority first — the first to return true
284-/// clears — then a `.rule-new` composer left open on the rules page, then284+/// closes its surface and the manager stops the key. Every consuming press
285-/// a rules edit row (navigating back to `/rules`). Never touches285+/// gets `preventDefault()`: a real Escape's browser default is stop-loading
286-/// `details.confirm-details`; that flow stays `board.rs`'s alone. Must be286+/// (it once cancelled the navigation these branches used to start; synthetic
287-/// emitted *after* `dropdown_script` (an open dd-panel wins the press) and287+/// keys carry no default, so only a live keyboard ever showed it).
288-/// *before* `card_menu_script` where both are present (the user-menu blur288+///
289-/// wins over board's other popups).289+/// The table below is the whole precedence order, topmost first; a resolver
290+/// whose surface is absent returns false so lower layers get the press. It
291+/// reproduces what the four former listeners' registration order produced
292+/// per page (the modal's inline `escape_closes` registered before the board
293+/// page's trailing scripts, `dropdown_script` before `escape_script` on
294+/// settings/rules, `escape_script` before `card_menu_script` on the board):
295+///
296+/// | prio | closes | registered by |
297+/// |------|--------|---------------|
298+/// | 100 | the datepicker popover | `board.rs`'s `card_menu_script` |
299+/// | 90 | the viewer, then the delete confirm, then non-datepick edit popovers, then the task modal | `detail.rs`'s `escape_closes` |
300+/// | 50 | the open dropdown panel (refocusing its trigger) | `dropdown.rs`'s `dropdown_script` |
301+/// | 40 | the topbar `.user-menu` (pin+blur), then the rules composer, then a rules edit row (back to `/rules`) | `layout.rs`'s `escape_script` |
302+/// | 10 | the card context menu | `board.rs`'s `card_menu_script` |
303+pub async fn escape_manager_script(cx: &Cx) -> Result {
304+ use topcoat::view::Unescaped;
305+ const JS: &str = "\
306+ (function () { \
307+ if (window.__izlekEsc) { return; } \
308+ window.__izlekEsc = { \
309+ resolvers: [], \
310+ register: function (priority, fn) { \
311+ window.__izlekEsc.resolvers.push({ priority: priority, fn: fn }); \
312+ window.__izlekEsc.resolvers.sort(function (a, b) { return b.priority - a.priority; }); \
313+ } \
314+ }; \
315+ document.addEventListener('keydown', function (e) { \
316+ if (e.key !== 'Escape') { return; } \
317+ for (var i = 0; i < window.__izlekEsc.resolvers.length; i++) { \
318+ if (window.__izlekEsc.resolvers[i].fn(e)) { \
319+ e.preventDefault(); \
320+ e.stopImmediatePropagation(); \
321+ return; \
322+ } \
323+ } \
324+ }, true); \
325+ })();";
326+ view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }
327+}
328+/// Registers the topbar/rules `Escape` resolvers on `window.__izlekEsc`
329+/// (priority 40 — the table is on `escape_manager_script`): the topbar
330+/// `.user-menu` panel — hover-open included, pinned shut by a
331+/// `user-menu-esc` class that a `mouseenter` inside the menu clears — then
332+/// a `.rule-new` composer left open on the rules page, then a rules edit
333+/// row (navigating back to `/rules`). Never touches
334+/// `details.confirm-details`; that flow stays `detail.rs`'s.
290 pub async fn escape_script(cx: &Cx) -> Result {335 pub async fn escape_script(cx: &Cx) -> Result {
291 const JS: &str = "\336 const JS: &str = "\
292 (function () { \337 (function () { \
293 if (window.__izlekEscTop) { return; } \338 if (window.__izlekEscTop) { return; } \
294 window.__izlekEscTop = true; \339 window.__izlekEscTop = true; \
295- document.addEventListener('keydown', function (e) { \340+ window.__izlekEsc.register(40, function () { \
296- if (e.key !== 'Escape') { return; } \
297 var menu = document.querySelector('.user-menu'); \341 var menu = document.querySelector('.user-menu'); \
298 if (menu && (menu.matches(':hover') || menu.contains(document.activeElement))) { \342 if (menu && (menu.matches(':hover') || menu.contains(document.activeElement))) { \
299 menu.classList.add('user-menu-esc'); \343 menu.classList.add('user-menu-esc'); \
300 var focused = document.activeElement; \344 var focused = document.activeElement; \
301 if (focused && focused.closest('.user-menu')) { focused.blur(); } \345 if (focused && focused.closest('.user-menu')) { focused.blur(); } \
302- e.stopImmediatePropagation(); \346+ return true; \
303- return; \
304 } \347 } \
305 var composer = document.querySelector('details.rule-new[open]'); \348 var composer = document.querySelector('details.rule-new[open]'); \
306- if (composer) { composer.removeAttribute('open'); e.stopImmediatePropagation(); return; } \349+ if (composer) { composer.removeAttribute('open'); return true; } \
307 if (document.querySelector('.rule-new-body[action=\"/api/update_rule\"]')) { \350 if (document.querySelector('.rule-new-body[action=\"/api/update_rule\"]')) { \
308- e.preventDefault(); \
309 if (window.__izlekGo) { window.__izlekGo('/rules'); } else { window.location.href = '/rules'; } \351 if (window.__izlekGo) { window.__izlekGo('/rules'); } else { window.location.href = '/rules'; } \
310- e.stopImmediatePropagation(); \352+ return true; \
311 } \353 } \
312- }, true); \354+ return false; \
355+ }); \
313 document.addEventListener('mouseenter', function (e) { \356 document.addEventListener('mouseenter', function (e) { \
314 var menu = e.target.closest ? e.target.closest('.user-menu') : null; \357 var menu = e.target.closest ? e.target.closest('.user-menu') : null; \
315 if (menu) { menu.classList.remove('user-menu-esc'); } \358 if (menu) { menu.classList.remove('user-menu-esc'); } \
@@ -370,6 +413,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result {
370 topcoat::dev::script()413 topcoat::dev::script()
371 </head>414 </head>
372 <body>415 <body>
416+ (escape_manager_script(cx).await?)
373 (soft_nav_script(cx).await?)417 (soft_nav_script(cx).await?)
374 (content)418 (content)
375 </body>419 </body>
crates/izlek-web/tests/http.rsmodified+14 -9
@@ -739,9 +739,12 @@ async fn the_board_sort_control_keeps_its_hidden_select_and_gets_a_dropdown_trig
739 // house trigger + panel client-side; its presence is the page's only739 // house trigger + panel client-side; its presence is the page's only
740 // server-rendered proof the shell is wired in.740 // server-rendered proof the shell is wired in.
741 assert!(html.contains("dd-trigger"), "no dropdown script on the board page: {html}");741 assert!(html.contains("dd-trigger"), "no dropdown script on the board page: {html}");
742- // `layout.rs`'s shared Escape handler — proof the topbar `.user-menu`742+ // `root_layout` emits `layout.rs`'s Escape manager on every page; the
743- // gets its close path on the board page too.743+ // registration below is proof the topbar `.user-menu` gets its close
744- assert!(html.contains("closest('.user-menu')"), "no escape script on the board page: {html}");744+ // path on the board page too.
745+ assert!(html.contains("window.__izlekEsc"), "no escape manager on the board page: {html}");
746+ assert!(html.contains("__izlekEsc.register(40"), "no escape script on the board page: {html}");
747+ assert!(html.contains("closest('.user-menu')"), "no user-menu close path on the board page: {html}");
745 }748 }
746 749
747 #[tokio::test]750 #[tokio::test]
@@ -1134,7 +1137,8 @@ async fn settings_selects_keep_their_hidden_form_fields_and_get_a_dropdown_trigg
1134 let html = String::from_utf8_lossy(&page.bytes);1137 let html = String::from_utf8_lossy(&page.bytes);
1135 assert!(html.contains("select class=\"field-input\" name=\"theme\""), "{html}");1138 assert!(html.contains("select class=\"field-input\" name=\"theme\""), "{html}");
1136 assert!(html.contains("dd-trigger"), "no dropdown script on the settings page: {html}");1139 assert!(html.contains("dd-trigger"), "no dropdown script on the settings page: {html}");
1137- assert!(html.contains("closest('.user-menu')"), "no escape script on the settings page: {html}");1140+ assert!(html.contains("__izlekEsc.register(40"), "no escape script on the settings page: {html}");
1141+ assert!(html.contains("closest('.user-menu')"), "no user-menu close path on the settings page: {html}");
1138 }1142 }
1139 1143
1140 /// The rules and logs pages carry no `board.rs`, so like settings they wire1144 /// The rules and logs pages carry no `board.rs`, so like settings they wire
@@ -1147,12 +1151,12 @@ async fn the_rules_and_logs_pages_get_the_shared_escape_script() {
1147 1151
1148 let rules_page = app.get("/rules", Some(&cookie)).await;1152 let rules_page = app.get("/rules", Some(&cookie)).await;
1149 let rules_html = String::from_utf8_lossy(&rules_page.bytes);1153 let rules_html = String::from_utf8_lossy(&rules_page.bytes);
1150- assert!(rules_html.contains("closest('.user-menu')"), "no escape script on the rules page: {rules_html}");1154+ assert!(rules_html.contains("__izlekEsc.register(40"), "no escape script on the rules page: {rules_html}");
1151 assert!(rules_html.contains("details.rule-new[open]"), "escape script does not close the rule composer: {rules_html}");1155 assert!(rules_html.contains("details.rule-new[open]"), "escape script does not close the rule composer: {rules_html}");
1152 1156
1153 let logs_page = app.get("/logs", Some(&cookie)).await;1157 let logs_page = app.get("/logs", Some(&cookie)).await;
1154 let logs_html = String::from_utf8_lossy(&logs_page.bytes);1158 let logs_html = String::from_utf8_lossy(&logs_page.bytes);
1155- assert!(logs_html.contains("closest('.user-menu')"), "no escape script on the logs page: {logs_html}");1159+ assert!(logs_html.contains("__izlekEsc.register(40"), "no escape script on the logs page: {logs_html}");
1156 }1160 }
1157 1161
1158 #[tokio::test]1162 #[tokio::test]
@@ -2342,10 +2346,11 @@ async fn the_viewer_renders_in_page_for_a_renderable_file_and_ignores_a_foreign_
2342 let page = app.get(&format!("/?task={task}&file={file_id}"), Some(&admin_cookie)).await;2346 let page = app.get(&format!("/?task={task}&file={file_id}"), Some(&admin_cookie)).await;
2343 assert_eq!(page.status, StatusCode::OK);2347 assert_eq!(page.status, StatusCode::OK);
2344 let html = String::from_utf8_lossy(&page.bytes);2348 let html = String::from_utf8_lossy(&page.bytes);
2345- // "viewer-body" marks the rendered overlay; "viewer-scrim" also appears2349+ // "viewer-body" marks the rendered overlay; the viewer's Escape resolver
2346- // as a string literal inside the Escape-handler script that escape_closes2350+ // that escape_closes registers (priority 90) also appears here on task
2347- // inlines on task pages only, not every board page.2351+ // pages only, not every board page.
2348 assert!(html.contains("viewer-body"), "no viewer overlay in the page: {html}");2352 assert!(html.contains("viewer-body"), "no viewer overlay in the page: {html}");
2353+ assert!(html.contains("__izlekEsc.register(90"), "no viewer escape resolver in the page: {html}");
2349 assert!(html.contains(&format!("/files/{file_id}")), "viewer's <img> does not point at the file: {html}");2354 assert!(html.contains(&format!("/files/{file_id}")), "viewer's <img> does not point at the file: {html}");
2350 2355
2351 // A file id that exists but belongs to another task is refused the same2356 // A file id that exists but belongs to another task is refused the same