style(web): apply prettier formatting and drop an unused import

Run prettier over the assistant files and the new dock unit test so the
web lint job passes, and remove the unused ASSISTANT_BUTTON_SIZE import
flagged by code quality review.
This commit is contained in:
TyperBody
2026-09-25 13:38:23 +08:00
parent 6283d21311
commit 03f50d1afc
2 changed files with 46 additions and 29 deletions
@@ -20,7 +20,6 @@ import {
PopoverTrigger,
} from '@/components/ui/popover';
import {
ASSISTANT_BUTTON_SIZE,
ASSISTANT_RAIL_WIDTH,
clampAssistantPosition as clampInViewport,
resolveAssistantEdge,
@@ -81,9 +80,8 @@ function AssistantPanel({ storageKey }: { storageKey: string }) {
const controller = useRef(new AbortController());
const end = useRef<HTMLDivElement>(null);
const [dragPosition, setDragPosition] = useState<AssistantDragPosition | null>(
null,
);
const [dragPosition, setDragPosition] =
useState<AssistantDragPosition | null>(null);
const [dragging, setDragging] = useState(false);
const [dockedEdge, setDockedEdge] = useState<AssistantEdge>(null);
// The rail collapses only while the pointer is away. Hovering any part of the
@@ -193,10 +191,7 @@ function AssistantPanel({ storageKey }: { storageKey: string }) {
if (edge) lockHoverUntilPointerExit();
try {
if (edge) {
window.localStorage.setItem(
`${storageKey}:button-docked-edge`,
edge,
);
window.localStorage.setItem(`${storageKey}:button-docked-edge`, edge);
} else {
window.localStorage.removeItem(`${storageKey}:button-docked-edge`);
}
@@ -324,7 +319,9 @@ function AssistantPanel({ storageKey }: { storageKey: string }) {
window.addEventListener('pointercancel', onWindowUp);
// Release outside a drag still needs to reconcile the rail.
window.addEventListener('pointerup', settleRailAfterRelease, { once: true });
window.addEventListener('pointerup', settleRailAfterRelease, {
once: true,
});
longPressTimer.current = window.setTimeout(() => {
if (dragState.current !== state) return;
@@ -491,11 +488,7 @@ function AssistantPanel({ storageKey }: { storageKey: string }) {
return (
<div
ref={containerRef}
className={
dragPosition
? 'fixed z-50'
: 'fixed bottom-20 right-5 z-50'
}
className={dragPosition ? 'fixed z-50' : 'fixed bottom-20 right-5 z-50'}
style={inlinePosition}
onPointerEnter={handlePointerEnter}
onPointerLeave={handlePointerLeave}
+39 -15
View File
@@ -50,15 +50,18 @@ test('clamping keeps the button fully inside the viewport', () => {
});
test('a narrow viewport never produces a negative travel range', () => {
assert.deepEqual(
clampAssistantPosition(10, 10, { width: 20, height: 20 }),
{ x: 0, y: 0 },
);
assert.deepEqual(clampAssistantPosition(10, 10, { width: 20, height: 20 }), {
x: 0,
y: 0,
});
});
test('positions within the snap threshold dock to the nearest edge', () => {
assert.equal(resolveAssistantEdge(0, viewport), 'left');
assert.equal(resolveAssistantEdge(ASSISTANT_SNAP_THRESHOLD, viewport), 'left');
assert.equal(
resolveAssistantEdge(ASSISTANT_SNAP_THRESHOLD, viewport),
'left',
);
assert.equal(resolveAssistantEdge(maxX, viewport), 'right');
assert.equal(
resolveAssistantEdge(maxX - ASSISTANT_SNAP_THRESHOLD, viewport),
@@ -82,16 +85,28 @@ test('the left edge wins ties so a centred drop is deterministic', () => {
test('hovering a docked rail expands it, hovering a free button does not', () => {
assert.equal(
shouldExpandRail({ dockedEdge: 'right', railExpanded: false, dragging: false }),
shouldExpandRail({
dockedEdge: 'right',
railExpanded: false,
dragging: false,
}),
true,
);
assert.equal(
shouldExpandRail({ dockedEdge: null, railExpanded: false, dragging: false }),
shouldExpandRail({
dockedEdge: null,
railExpanded: false,
dragging: false,
}),
false,
);
// Already expanded: nothing to do, so no redundant state churn on every move.
assert.equal(
shouldExpandRail({ dockedEdge: 'left', railExpanded: true, dragging: false }),
shouldExpandRail({
dockedEdge: 'left',
railExpanded: true,
dragging: false,
}),
false,
);
});
@@ -106,15 +121,27 @@ test('only an *expanded* docked button collapses when the pointer leaves', () =>
// Regression: keying this on `!railExpanded` made a revealed button
// impossible to collapse again, so it stayed open forever after one hover.
assert.equal(
shouldCollapseRail({ dockedEdge: 'left', railExpanded: true, dragging: false }),
shouldCollapseRail({
dockedEdge: 'left',
railExpanded: true,
dragging: false,
}),
true,
);
assert.equal(
shouldCollapseRail({ dockedEdge: 'left', railExpanded: false, dragging: false }),
shouldCollapseRail({
dockedEdge: 'left',
railExpanded: false,
dragging: false,
}),
false,
);
assert.equal(
shouldCollapseRail({ dockedEdge: null, railExpanded: true, dragging: false }),
shouldCollapseRail({
dockedEdge: null,
railExpanded: true,
dragging: false,
}),
false,
);
});
@@ -124,10 +151,7 @@ test('expand then leave round-trips back to the collapsed rail', () => {
// Hover: reveal the button.
assert.equal(shouldExpandRail(docked), true);
// Pointer leaves: the revealed button must collapse again.
assert.equal(
shouldCollapseRail({ ...docked, railExpanded: true }),
true,
);
assert.equal(shouldCollapseRail({ ...docked, railExpanded: true }), true);
// A second hover re-reveals it, so the cycle is repeatable.
assert.equal(shouldExpandRail(docked), true);
});