chore(editor): rev 5 review nits
Deterministic scroll-settle wait for the bubble e2e, useDismissal split, precondition for the add-button focus test, CSS comment wrap.
This commit is contained in:
1 parent
a9252375e1
commit
b5dcb766b1
4 files changed
+65
-26
No files matched your search
@@ -67,6 +67,27 @@ interface Box {
|
||||
height: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves once the page's scroll position has held for three animation frames: a scroll
|
||||
* event of the move before is then past, which a bubble (closed by any scroll) must not meet.
|
||||
*/
|
||||
async function settleScroll(page: Page) {
|
||||
await page.evaluate(
|
||||
() =>
|
||||
new Promise<void>((resolve) => {
|
||||
let last = window.scrollY
|
||||
let still = 0
|
||||
const frame = () => {
|
||||
still = window.scrollY === last ? still + 1 : 0
|
||||
last = window.scrollY
|
||||
if (still >= 3) resolve()
|
||||
else requestAnimationFrame(frame)
|
||||
}
|
||||
requestAnimationFrame(frame)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The bubble sits in the window, under the top bar, right under its button (within 8 px
|
||||
* unless the bar pushes it down), and over neither « Défaire » nor the strip's commands.
|
||||
@@ -311,7 +332,7 @@ test.describe('editor annotations (A3)', () => {
|
||||
await page.waitForTimeout(300)
|
||||
await redo.evaluate((el) => el.scrollIntoView({ block: 'center' }))
|
||||
// Its scroll event lands before the press, which a scroll would close.
|
||||
await page.waitForTimeout(150)
|
||||
await settleScroll(page)
|
||||
const widthBefore = await scrollWidth(page)
|
||||
await expectNoShift(page, async () => {
|
||||
await pressAtBox(page, redo)
|
||||
@@ -325,14 +346,14 @@ test.describe('editor annotations (A3)', () => {
|
||||
// Scrolled, the strip stuck under the bar: the keyboard press keeps the same rules.
|
||||
await page.evaluate(() => window.scrollTo(0, 150))
|
||||
await redo.focus()
|
||||
await page.waitForTimeout(150)
|
||||
await settleScroll(page)
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(bubble).toHaveText(reason)
|
||||
await expectBubbleBeside(page, bubble, redo, undo)
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(bubble).toHaveCount(0)
|
||||
await page.evaluate(() => window.scrollTo(0, 0))
|
||||
await page.waitForTimeout(150)
|
||||
await settleScroll(page)
|
||||
}
|
||||
await expect(page.getByTestId('gesture-message')).toHaveCount(0)
|
||||
// Escape order: the bubble first, alone; the next Escape asks about the creation.
|
||||
|
||||
@@ -902,6 +902,11 @@ for (const viewport of VIEWPORTS) {
|
||||
// scroll, never onto the bar or the strip, and the column stays below the strip.
|
||||
await page.evaluate(() => window.scrollTo(0, 0))
|
||||
const add = page.locator('[data-add-kind="point"]')
|
||||
const unrevealed = (await add.boundingBox())!
|
||||
expect(
|
||||
unrevealed.y,
|
||||
'precondition: the add button is below the fold',
|
||||
).toBeGreaterThan(await page.evaluate(() => window.innerHeight))
|
||||
await add.focus()
|
||||
const revealed = await stripGeometry(page)
|
||||
const addBox = (await add.boundingBox())!
|
||||
|
||||
@@ -26,6 +26,33 @@ export function useHeldBubble(
|
||||
return { open, serial, show, close }
|
||||
}
|
||||
|
||||
const PAGE_MOVES = ['scroll', 'wheel', 'touchmove']
|
||||
|
||||
/** Escape closes the bubble first; in a text field it is not taken, a modal keeps its own. */
|
||||
function escapeHandler(close: () => void) {
|
||||
return (event: KeyboardEvent) => {
|
||||
if (event.key !== 'Escape' || event.isComposing) return
|
||||
if (document.querySelector('dialog[open]')) return
|
||||
close()
|
||||
if (isTextField(event.target)) return
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
}
|
||||
}
|
||||
|
||||
/** A dialog gaining `open` anywhere in the page closes the bubble. */
|
||||
function watchDialogs(close: () => void) {
|
||||
const watch = new MutationObserver(() => {
|
||||
if (document.querySelector('dialog[open]')) close()
|
||||
})
|
||||
watch.observe(document.body, {
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
attributeFilter: ['open'],
|
||||
})
|
||||
return watch
|
||||
}
|
||||
|
||||
function useDismissal(
|
||||
open: boolean,
|
||||
close: () => void,
|
||||
@@ -33,37 +60,22 @@ function useDismissal(
|
||||
) {
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
const onKey = (event: KeyboardEvent) => {
|
||||
if (event.key !== 'Escape' || event.isComposing) return
|
||||
if (document.querySelector('dialog[open]')) return
|
||||
close()
|
||||
if (isTextField(event.target)) return
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
}
|
||||
const onKey = escapeHandler(close)
|
||||
const onPress = (event: Event) => {
|
||||
if (!button.current?.contains(event.target as Node)) close()
|
||||
}
|
||||
const onDialog = () => {
|
||||
if (document.querySelector('dialog[open]')) close()
|
||||
}
|
||||
const watch = new MutationObserver(onDialog)
|
||||
watch.observe(document.body, {
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
attributeFilter: ['open'],
|
||||
})
|
||||
const watch = watchDialogs(close)
|
||||
const passive = { capture: true, passive: true }
|
||||
document.addEventListener('keydown', onKey, true)
|
||||
document.addEventListener('pointerdown', onPress, true)
|
||||
for (const type of ['scroll', 'wheel', 'touchmove']) {
|
||||
for (const type of PAGE_MOVES) {
|
||||
document.addEventListener(type, close, passive)
|
||||
}
|
||||
return () => {
|
||||
watch.disconnect()
|
||||
document.removeEventListener('keydown', onKey, true)
|
||||
document.removeEventListener('pointerdown', onPress, true)
|
||||
for (const type of ['scroll', 'wheel', 'touchmove']) {
|
||||
for (const type of PAGE_MOVES) {
|
||||
document.removeEventListener(type, close, passive)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,11 @@ body,
|
||||
}
|
||||
/* The drawing column (chips, tools, canvas, add row, message line) is pinned under the
|
||||
strip, so no part of the drawing is ever under it while the side panel scrolls (U2 Task
|
||||
17). Only where the column fits: below 40.25rem (644 px) of window height the 365 px tool
|
||||
column beside a capped canvas does not, nothing here applies and nothing is pinned. The negative bottom margin lets the
|
||||
pinned travel run into the page's bottom space (workspace gap + main padding): without
|
||||
it, the page's end pushed the column's top under the strip at 1 180 x 820. */
|
||||
17). Only where the column fits: below 40.25rem (644 px) of window height the 365 px
|
||||
tool column beside a capped canvas does not, nothing here applies and nothing is
|
||||
pinned. The negative bottom margin lets the pinned travel run into the page's bottom
|
||||
space (workspace gap + main padding): without it, the page's end pushed the column's
|
||||
top under the strip at 1 180 x 820. */
|
||||
@media (min-width: 1024px) and (min-height: 40.25rem) {
|
||||
[data-drawing-column] {
|
||||
position: sticky;
|
||||
|
||||
Reference in new issue
Block a user