chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)

This commit is contained in:
runny committed 2026-11-13 17:54:56 +08:00
commit 9097ee699d
5769 files changed
+1446466

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
/** Letter shown beside the i-th option of a docked prompt: A, B, C… */
export function optionKey(index: number): string {
return index >= 0 && index < 26 ? String.fromCharCode(65 + index) : ''
}
/** Index of the option a key press picks, or -1. */
export function optionIndexForKey(key: string): number {
if (key.length !== 1) return -1
const code = key.toUpperCase().charCodeAt(0)
return code >= 65 && code <= 90 ? code - 65 : -1
}
/** Whether key presses on el are typing rather than shortcuts. */
export function isTextEntry(el: EventTarget | null): boolean {
if (!(el instanceof HTMLElement)) return false
return el.isContentEditable || el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.tagName === 'SELECT'
}
/** Enter that submits: not composing an IME candidate, not a soft line break. */
export function isSubmitKey(e: KeyboardEvent): boolean {
// Let focused controls perform their own action (especially Reject/Skip).
// The dock receives bubbled keydowns from both its cards and its header.
// A picked option keeps focus after the click, and Enter then submits it.
const target = e.target as Element | null
const control = target?.closest?.('button, a, [role="button"]')
if (control && (control.getAttribute?.('role') !== 'option'
|| control.getAttribute?.('aria-selected') !== 'true')) return false
return e.key === 'Enter' && !e.shiftKey && !e.isComposing && e.keyCode !== 229
}