Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion design-system/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Use a pre-change reference commit when testing an already committed change.
The native fixture runs outside performance windows. Geometry equivalence does
not establish pixel-identical rasterization or coverage on other WebView engines.

For shared queue pointer/keyboard interaction, cancellation and focus retention:
For shared queue dragging, arrow-key pass-through, cancellation and focus retention:

```bash
pnpm --dir src/web-ui exec vitest run src/flow_chat/components/useQueueReorder.test.tsx
Expand Down
8 changes: 5 additions & 3 deletions design-system/packages/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1041,11 +1041,13 @@ consume those references through intervening wrappers. A control's explicit name
or own label takes precedence; descriptions are combined. Give each child in a
composite field its own name. Nested `Field` controls retain their own labels.

`ChatComposerQueue` has no outer border. Each row starts with an inset hairline;
`ChatComposerQueue` has no outer border. Each row has equal block padding and starts with an inset hairline;
the final row has no bottom hairline and meets the composer without an extra
gap. `ChatComposerQueueItem.leadingControl` accepts an accessible interactive
control; `leadingIcon` remains decorative. `useQueueReorder` supplies pointer
capture, keyboard moves, edge scrolling and cancellation when the authoritative
capture, edge scrolling and cancellation when the authoritative
revision changes. Pass only reorderable IDs and keep the actual order in the
product owner until its mutation succeeds. Disabled or legacy hosts must expose
product owner until its mutation succeeds. Arrow keys do not reorder the queue;
product action menus provide explicit move-up/down commands. Drag handles carry
an accessible label without a hover tooltip. Disabled or legacy hosts must expose
a clear reason in their product surface.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
var(--openbitfun-control-height-sm) +
var(--openbitfun-control-height-sm) +
var(--openbitfun-control-height-sm) +
var(--openbitfun-control-height-sm)
var(--openbitfun-control-height-sm) +
var(--openbitfun-space-1) * 8
);
flex-direction: column;
gap: 0;
Expand Down Expand Up @@ -99,6 +100,9 @@
min-block-size: var(--openbitfun-control-height-sm);
align-items: flex-start;
gap: var(--openbitfun-space-2);
/* Own both sides of the divider; document li margins must not leak in. */
margin: 0;
padding-block: var(--openbitfun-space-1);
padding-inline: var(--openbitfun-space-2) var(--openbitfun-space-1);
border-radius: var(--openbitfun-radius-md);
color: var(--openbitfun-color-content-primary);
Expand Down Expand Up @@ -190,7 +194,6 @@
font-size: var(--openbitfun-type-meta-font-size);
line-height: var(--openbitfun-type-body-sm-line-height);
overflow-wrap: anywhere;
padding-block-end: var(--openbitfun-space-1);
}

.status[data-openbitfun-tone="warning"] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent as ReactPointerEvent } from 'react';
import { useEffect, useRef, useState, type CSSProperties, type PointerEvent as ReactPointerEvent } from 'react';

type Drag = {
id: string;
Expand All @@ -14,7 +14,7 @@ type Drag = {
moved: boolean;
};

/** Pointer/keyboard presentation only. The caller owns authoritative ordering. */
/** Pointer drag presentation only. The caller owns authoritative ordering. */
export function useQueueReorder(ids: string[], enabled: boolean, revision: string | number,
onMove: (id: string, beforeId: string | null) => void) {
const rows = useRef(new Map<string, HTMLLIElement>());
Expand Down Expand Up @@ -131,15 +131,8 @@ export function useQueueReorder(ids: string[], enabled: boolean, revision: strin
},
onPointerMove: update,
onPointerUp: (event: ReactPointerEvent<HTMLButtonElement>) => { if (drag.current?.pointerId === event.pointerId) finish(true); },
onPointerCancel: () => finish(false),
onLostPointerCapture: () => finish(false),
onKeyDown(event: ReactKeyboardEvent<HTMLButtonElement>) {
if (!enabled || drag.current || !['ArrowUp', 'ArrowDown'].includes(event.key)) return;
event.preventDefault();
const index = ids.indexOf(id);
if (event.key === 'ArrowUp' && index > 0) requestMove(id, ids[index - 1]!);
if (event.key === 'ArrowDown' && index >= 0 && index < ids.length - 1) requestMove(id, ids[index + 2] ?? null);
},
onPointerCancel: (event: ReactPointerEvent<HTMLButtonElement>) => { if (drag.current?.pointerId === event.pointerId) finish(false); },
onLostPointerCapture: (event: ReactPointerEvent<HTMLButtonElement>) => { if (drag.current?.pointerId === event.pointerId) finish(false); },
};
},
};
Expand Down
3 changes: 3 additions & 0 deletions design-system/packages/ui/tests/chat-composer.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,11 @@ test("ChatComposer queue keeps four message rows visible before scrolling", asyn
(maxBlockSize.match(/--openbitfun-control-height-sm/g) ?? []).length,
4,
);
assert.match(maxBlockSize, /var\(--openbitfun-space-1\)\s*\*\s*8/);
assert.match(listRule, /gap:\s*0;/);
assert.match(styles, /\.item\s*\{[^}]*min-block-size:\s*var\(--openbitfun-control-height-sm\)/s);
assert.match(styles, /\.item\s*\{[^}]*margin:\s*0;[^}]*padding-block:\s*var\(--openbitfun-space-1\);/s);
assert.doesNotMatch(styles, /\.status\s*\{[^}]*padding-block-end:/s);
assert.match(listRule, /overflow-y:\s*auto/);
assert.match(listRule, /overscroll-behavior-y:\s*contain/);
});
Expand Down
4 changes: 2 additions & 2 deletions src/mobile-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ the phone, or leaving the session does not stop host-side dispatch.
still render steering inline within the active turn. The turn-scoped SDK
steering API used by CLI/Dispatch retains its inline contract; this handoff
belongs to host queue promotion.
- **Reorder** uses the drag handle, Up/Down while the handle is focused, or
Move up/down in **More**. The host confirms the new execution order before
- **Reorder** uses the drag handle or Move up/down in **More**.
Arrow keys do not change the queue order. The host confirms the new execution order before
the list changes. A concurrent update cancels a drag and asks you to retry
against the refreshed list. Older queue hosts without `supportsReorder`
retain Send now and Remove, with a clear sorting-unavailable message.
Expand Down
2 changes: 1 addition & 1 deletion src/mobile-web/src/components/MobileHostQueue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function MobileHostQueue({ queue, onRestore }: { queue: HostDialogQueue;
<ul id={listId} hidden={!expanded && !items.some(item => item.status === 'blocked') && !view.pending.length} className="host-message-queue__list">
{items.filter(item => expanded || item.status === 'blocked').map(item => <li key={item.turnId} className="host-message-queue__row" {...reorder.rowProps(item.turnId)}>
{item.status === 'queued' && view.snapshot?.supportsReorder && <MobileIconButton appearance="plain" size="sm" className="host-message-queue__handle"
aria-label={t('queue.reorder')} title={t('queue.reorder')} icon={<GripVertical size={16} aria-hidden="true" />} {...reorder.handleProps(item.turnId)} />}
aria-label={t('queue.reorder')} icon={<GripVertical size={16} aria-hidden="true" />} {...reorder.handleProps(item.turnId)} />}
<div className="host-message-queue__message">
<div className="host-message-queue__line"><p className="host-message-queue__preview">{item.displayContent}</p>
{item.attachmentCount > 0 && <span className="host-message-queue__attachments" aria-label={t('queue.attachments', { count: item.attachmentCount })}>
Expand Down
6 changes: 3 additions & 3 deletions src/mobile-web/src/i18n/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const messages: Record<MobileLanguage, MessageTree> = {
'en-US': {
backgroundDelivery: { quiet: 'Background task completed · No report needed', running: 'Background task running' },
queue: {
"reorder": "Drag to reorder, or use Up and Down arrow keys",
"reorder": "Drag to reorder",
"moveUp": "Move up",
"moveDown": "Move down",
"orderChanged": "The queue changed. Refresh it before reordering.",
Expand Down Expand Up @@ -388,7 +388,7 @@ export const messages: Record<MobileLanguage, MessageTree> = {
'zh-CN': {
backgroundDelivery: { quiet: '后台任务已完成 · 无需汇报', running: '后台任务执行中' },
queue: {
"reorder": "拖动排序,也可使用上下方向键",
"reorder": "拖动排序",
"moveUp": "上移",
"moveDown": "下移",
"orderChanged": "队列已变化,请刷新后重新调整顺序。",
Expand Down Expand Up @@ -766,7 +766,7 @@ export const messages: Record<MobileLanguage, MessageTree> = {
'zh-TW': {
backgroundDelivery: { quiet: '背景任務已完成 · 無需回報', running: '背景任務執行中' },
queue: {
"reorder": "拖曳排序,也可使用上下方向鍵",
"reorder": "拖曳排序",
"moveUp": "上移",
"moveDown": "下移",
"orderChanged": "佇列已變更,請重新整理後再調整順序。",
Expand Down
13 changes: 8 additions & 5 deletions src/mobile-web/tests/host-dialog-queue-browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ test('queue stays above the measured composer across phone, keyboard-height and
const composer=box('.chat-page__composer'),stop=box('.chat-page__send-btn.is-stop');
const plus=box('.chat-page__composer-leading');
const text=box('.chat-msg__assistant-content');
const icon=box('.chat-thinking [data-openbitfun-part="leading"]');
const message=box('.chat-msg--assistant');
return {top:stop.top-composer.top,bottom:composer.bottom-stop.bottom,right:composer.right-stop.right,
left:plus.left-composer.left,width:stop.width,plusWidth:plus.width,
textLeft:text.left+parseFloat(getComputedStyle(document.querySelector('.chat-msg__assistant-content')).paddingLeft),iconLeft:icon.left};
textLeft:text.left+parseFloat(getComputedStyle(document.querySelector('.chat-msg__assistant-content')).paddingLeft),messageLeft:message.left};
});
assert.equal(geometry.width,44);
assert.equal(geometry.plusWidth,44);
for(const edge of ['top','bottom','left']) assert.ok(Math.abs(geometry[edge]-geometry.right)<1,JSON.stringify(geometry));
assert.ok(Math.abs(geometry.textLeft-geometry.iconLeft)<1,JSON.stringify(geometry));
// The transcript gutter owns assistant text alignment; thinking/tool controls
// keep their own inset icon column.
assert.ok(Math.abs(geometry.textLeft-geometry.messageLeft)<1,JSON.stringify(geometry));
await page.screenshot({path:path.join(tmpdir(),'mobile-queue-aligned.png'),fullPage:true});
await page.click('[aria-label="排队消息说明"]');
await page.waitForSelector('.host-message-queue__help');
Expand Down Expand Up @@ -171,10 +173,11 @@ test('touch-sized queue handles reorder real component rows and overflow removes
assert.deepEqual(geometry, {gap: 0, firstLine: '1px', lastBottom: 'none', outerBorder: '0px'});
const handles = await page.$$('.host-message-queue__handle');
assert.ok((await handles[0].boundingBox()).width >= 44);
assert.equal(await handles[0].evaluate(el => el.hasAttribute('title')), false);
const before = await page.$$eval('.host-message-queue__preview', nodes => nodes.map(n => n.textContent));
await handles[2].focus(); await page.keyboard.press('ArrowUp');
await page.waitForFunction(first => document.querySelectorAll('.host-message-queue__preview')[1].textContent === first, {}, before[2]);
assert.deepEqual(await page.$$eval('.host-message-queue__preview', nodes => nodes.map(n => n.textContent)), [before[0], before[2], before[1]]);
await handles[0].focus(); await page.keyboard.press('ArrowDown');
assert.deepEqual(await page.$$eval('.host-message-queue__preview', nodes => nodes.map(n => n.textContent)), before);
const first = await page.$('.host-message-queue__handle'); const box = await first.boundingBox();
const last = await page.$eval('.host-message-queue__row:last-child', el => { const r=el.getBoundingClientRect();return {y:r.bottom-3}; });
await page.mouse.move(box.x+box.width/2,box.y+box.height/2); await page.mouse.down();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ it('keeps four queued messages compact, exposes actions, and toggles help indepe
requests.push(request.action);
if (request.action === 'cancel' || request.action === 'promote') items = items.filter(item => item.turnId !== request.turnId);
return { sessionId: 'session', queueEpoch: 'epoch', revision: requests.length, activeTurnId: 'active',
items, capacity: 20, used: items.length, receipt: null };
items, capacity: 20, used: items.length, receipt: null, supportsReorder: true };
}, { list: async () => [], put: async () => {}, remove: async () => {} });
const container = document.createElement('div');
document.body.append(container);
const root = createRoot(container);
try {
await act(async () => root.render(<HostPendingQueuePanel queue={queue} onRestore={() => true} />));
expect(container.querySelectorAll('li')).toHaveLength(4);
const handle = container.querySelector<HTMLButtonElement>('[data-queue-handle]')!;
expect(handle.getAttribute('title')).toBeNull();
await act(async () => handle.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true })));
expect(requests).not.toContain('reorder');
const badge = container.querySelector('[data-openbitfun-part="attachmentCount"]')!;
expect(badge.closest('[data-openbitfun-part="message"]')?.querySelector('[data-openbitfun-product-part="preview"]')?.textContent).toBe('1');
expect(badge.previousElementSibling?.getAttribute('data-openbitfun-product-part')).toBe('preview');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function HostPendingQueuePanel({ queue, onRestore }: { queue: HostDialogQ
const blocked = item.status === 'blocked';
return <ChatComposerQueueItem data-openbitfun-product-component="pending-queue-panel" data-openbitfun-product-part="item" key={item.turnId} {...reorder.rowProps(item.turnId)}
leadingControl={item.status === 'queued' && view.snapshot?.supportsReorder ? <IconButton variant="annotation" size="xs"
aria-label={t('pendingQueue.reorder')} title={t('pendingQueue.reorder')} icon={<Icon glyph={GripVertical} size="sm" />} {...reorder.handleProps(item.turnId)} /> : undefined}
aria-label={t('pendingQueue.reorder')} icon={<Icon glyph={GripVertical} size="sm" />} {...reorder.handleProps(item.turnId)} /> : undefined}
leadingIcon={<Icon glyph={ListEnd} size="sm" />} state={blocked ? 'failed' : steering ? 'sending' : 'default'}>
<ChatComposerQueueItemContent data-openbitfun-product-component="pending-queue-panel" data-openbitfun-product-part="content">
<ChatComposerQueueItemMessage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ describe('PendingQueuePanel', () => {
});

expect(container.querySelector('[data-openbitfun-part="header"]')).toBeNull();
expect(container.querySelector('[data-queue-handle]')?.getAttribute('title')).toBeNull();
const attachmentBadge = container.querySelector('[data-openbitfun-part="attachmentCount"]');

expect(attachmentBadge?.textContent).toBe('3');
Expand Down
2 changes: 1 addition & 1 deletion src/web-ui/src/flow_chat/components/PendingQueuePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function LegacyPendingQueuePanel({
key={item.id}
{...reorder.rowProps(item.id)}
leadingControl={<IconButton variant="annotation" size="xs"
aria-label={t('pendingQueue.reorder')} title={t('pendingQueue.reorder')} icon={<Icon glyph={GripVertical} size="sm" />} {...reorder.handleProps(item.id)} />}
aria-label={t('pendingQueue.reorder')} icon={<Icon glyph={GripVertical} size="sm" />} {...reorder.handleProps(item.id)} />}
state={itemState}
leadingIcon={<Icon glyph={ListEnd} size="sm" />}
>
Expand Down
27 changes: 21 additions & 6 deletions src/web-ui/src/flow_chat/components/useQueueReorder.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function pointer(type: string, y: number, target = container.querySelector('butt
act(() => target.dispatchEvent(event));
}
beforeEach(() => {
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
move.mockClear();
vi.stubGlobal('requestAnimationFrame', vi.fn(() => 1));
vi.stubGlobal('cancelAnimationFrame', vi.fn());
Expand Down Expand Up @@ -52,22 +53,36 @@ it.each(['Escape', 'blur', 'pointercancel', 'lostpointercapture'])('cancels with
pointer('pointerup', 110);
expect(move).not.toHaveBeenCalled();
});
it.each(['pointercancel', 'lostpointercapture'])('ignores %s from another pointer', event => {
pointer('pointerdown', 20); pointer('pointermove', 85);
pointer(event, 85, container.querySelector('button')!, 2);
expect(container.querySelector('[data-queue-dragging]')).not.toBeNull();
pointer('pointerup', 85);
expect(move).toHaveBeenCalledExactlyOnceWith('a', 'c');
});
it('host revision changes invalidate the entire gesture', () => {
pointer('pointerdown', 20); pointer('pointermove', 110); render(2); pointer('pointerup', 110);
expect(move).not.toHaveBeenCalled();
});
it('arrow keys expose reorder without dragging and unsupported hosts disable the handles', () => {
act(() => container.querySelector('button')!.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true })));
expect(move).toHaveBeenCalledExactlyOnceWith('a', 'c');
move.mockClear(); render(1, false);
it.each(['ArrowUp', 'ArrowDown'])('passes %s through without changing the queue', key => {
const handle = container.querySelectorAll('button')[1];
const event = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true });
act(() => { handle.focus(); handle.dispatchEvent(event); });
expect(move).not.toHaveBeenCalled();
expect(event.defaultPrevented).toBe(false);
expect(document.activeElement).toBe(handle);
});
it('unsupported hosts disable the handles', () => {
render(1, false);
expect(container.querySelector('button')!.disabled).toBe(true);
pointer('pointerdown', 20); pointer('pointermove', 110); pointer('pointerup', 110);
expect(move).not.toHaveBeenCalled();
});

it('restores keyboard focus after a host mutation disables and then re-enables the grip', () => {
it('restores focus after a drag mutation disables and then re-enables the grip', () => {
const handle = container.querySelector('button')!;
act(() => { handle.focus(); handle.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true })); });
pointer('pointerdown', 20); pointer('pointermove', 85); pointer('pointerup', 85);
expect(move).toHaveBeenCalledExactlyOnceWith('a', 'c');
render(1, false);
act(() => handle.blur());
render(2, true);
Expand Down
2 changes: 1 addition & 1 deletion src/web-ui/src/locales/en-US/flow-chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -3866,7 +3866,7 @@
"composerNotEmpty": "Send or clear the current input and attachments before editing this queued message",
"sendNowFailed": "Send now failed; please try again"
},
"reorder": "Drag to reorder, or use Up and Down arrow keys",
"reorder": "Drag to reorder",
"moveUp": "Move up",
"moveDown": "Move down",
"orderChanged": "The queue changed. Refresh it and try moving the message again.",
Expand Down
2 changes: 1 addition & 1 deletion src/web-ui/src/locales/zh-CN/flow-chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -3866,7 +3866,7 @@
"composerNotEmpty": "请先发送或清空当前输入和附件,再编辑这条等待发送的消息",
"sendNowFailed": "立即发送失败,请稍后重试"
},
"reorder": "拖动排序,也可使用上下方向键",
"reorder": "拖动排序",
"moveUp": "上移",
"moveDown": "下移",
"orderChanged": "队列已变化,请刷新后重新调整顺序。",
Expand Down
2 changes: 1 addition & 1 deletion src/web-ui/src/locales/zh-TW/flow-chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -3866,7 +3866,7 @@
"composerNotEmpty": "請先發送或清空目前輸入與附件,再編輯這則等待發送的訊息",
"sendNowFailed": "立即發送失敗,請稍後重試"
},
"reorder": "拖曳排序,也可使用上下方向鍵",
"reorder": "拖曳排序",
"moveUp": "上移",
"moveDown": "下移",
"orderChanged": "佇列已變更,請重新整理後再調整順序。",
Expand Down
Loading