refactor(core): [CORE-23] complete keyboard controls and focus lifecycle

This commit is contained in:
Harvey Zhao committed 2026-09-11 21:06:33 +08:00
1 parent faaa3e8c2d
commit 8ed0a5228c
190 files changed
+53981 -489

No files matched your search

@@ -0,0 +1,22 @@
import type { ComponentHost } from '../component/types'
import { getScope, isClosing } from '../lifecycle/instance'
const owned = new WeakSet<HTMLElement>()
export function focusPlayer(art: Pick<ComponentHost, 'template'>): void {
const player = art.template.$player
if (isClosing(art) || !player.isConnected)
return
if (!player.hasAttribute('tabindex')) {
player.setAttribute('tabindex', '-1')
if (!owned.has(player)) {
owned.add(player)
getScope(art).add(() => {
owned.delete(player)
if (player.getAttribute('tabindex') === '-1')
player.removeAttribute('tabindex')
})
}
}
player.focus({ preventScroll: true })
}