@lightningtv/core
Advanced tools
Comparing version 2.6.1 to 2.6.2-0
@@ -106,11 +106,18 @@ import { Config } from './config.js'; | ||
}; | ||
const propagateKeyPress = (e, mappedEvent, isHold) => { | ||
const propagateKeyPress = (e, mappedEvent, isHold, propagatedUpKeys = []) => { | ||
let finalFocusElm = undefined; | ||
const isUp = e.type === 'keyup'; | ||
for (const elm of focusPath) { | ||
finalFocusElm = finalFocusElm || elm; | ||
if (mappedEvent) { | ||
const onKeyHandler = isUp | ||
? elm[`on${mappedEvent}Up`] | ||
: elm[`on${mappedEvent}`] || elm[`on${mappedEvent}Down`]; | ||
const propagateKeyUp = Boolean(mappedEvent && propagatedUpKeys.includes(mappedEvent)); | ||
if (mappedEvent) { | ||
for (const elm of focusPath) { | ||
finalFocusElm = finalFocusElm || elm; | ||
const keyEvent = elm[`on${mappedEvent}`]; | ||
const keyUpEvent = elm[`on${mappedEvent}Up`]; | ||
const keyDownEvent = elm[`on${mappedEvent}Down`]; | ||
const skipDown = !isUp && propagateKeyUp && !keyDownEvent; | ||
const skipUp = isUp && !isHold && !propagateKeyUp && !keyUpEvent; | ||
if (skipDown || skipUp) { | ||
continue; | ||
} | ||
const onKeyHandler = (isUp ? keyUpEvent : keyDownEvent) || keyEvent; | ||
if (isFunction(onKeyHandler) && | ||
@@ -120,15 +127,15 @@ onKeyHandler.call(elm, e, elm, finalFocusElm) === true) { | ||
} | ||
if (isUp && !isHold) { | ||
continue; | ||
} | ||
const fallbackFunction = isHold ? elm.onKeyHold : elm.onKeyPress; | ||
if (isFunction(fallbackFunction) && | ||
fallbackFunction.call(elm, e, mappedEvent, elm, finalFocusElm) === true) { | ||
break; | ||
} | ||
} | ||
else { | ||
console.log(`Unhandled key event: ${e.key || e.keyCode}`); | ||
} | ||
if (isUp && !isHold) { | ||
continue; | ||
} | ||
const fallbackFunction = isHold ? elm.onKeyHold : elm.onKeyPress; | ||
if (isFunction(fallbackFunction) && | ||
fallbackFunction.call(elm, e, mappedEvent, elm, finalFocusElm) === true) { | ||
break; | ||
} | ||
} | ||
else { | ||
console.log(`Unhandled key event: ${e.key || e.keyCode}`); | ||
} | ||
return false; | ||
@@ -139,3 +146,2 @@ }; | ||
const keyHoldCallback = (e, mappedKeyHoldEvent) => { | ||
delete keyHoldTimeouts[e.key || e.keyCode]; | ||
propagateKeyPress(e, mappedKeyHoldEvent, true); | ||
@@ -149,10 +155,7 @@ }; | ||
if (mappedKeyHoldEvent) { | ||
if (keyHoldTimeouts[key]) { | ||
clearTimeout(keyHoldTimeouts[key]); | ||
if (!keyHoldTimeouts[key]) { | ||
keyHoldTimeouts[key] = window.setTimeout(() => keyHoldCallback(keydown, mappedKeyHoldEvent), delay); | ||
} | ||
keyHoldTimeouts[key] = window.setTimeout(() => keyHoldCallback(keydown, mappedKeyHoldEvent), delay); | ||
} | ||
else { | ||
propagateKeyPress(keydown, mappedKeyEvent, false); | ||
} | ||
propagateKeyPress(keydown, mappedKeyEvent, false, propagatedUpKeys); | ||
} | ||
@@ -162,8 +165,7 @@ else if (keyup) { | ||
const mappedKeyEvent = keyMapEntries[keyup.key] || keyMapEntries[keyup.keyCode]; | ||
if (keyHoldTimeouts[key] || | ||
(mappedKeyEvent && propagatedUpKeys.includes(mappedKeyEvent))) { | ||
if (keyHoldTimeouts[key]) { | ||
clearTimeout(keyHoldTimeouts[key]); | ||
delete keyHoldTimeouts[key]; | ||
propagateKeyPress(keyup, mappedKeyEvent, false); | ||
} | ||
propagateKeyPress(keyup, mappedKeyEvent, false, propagatedUpKeys); | ||
} | ||
@@ -170,0 +172,0 @@ }; |
{ | ||
"name": "@lightningtv/core", | ||
"version": "2.6.1", | ||
"version": "2.6.2-0", | ||
"description": "Lightning TV Core for Universal Renderers", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -146,11 +146,26 @@ import { Config } from './config.js'; | ||
isHold: boolean, | ||
propagatedUpKeys: string[] = [], | ||
) => { | ||
let finalFocusElm: ElementNode | undefined = undefined; | ||
const isUp = e.type === 'keyup'; | ||
for (const elm of focusPath) { | ||
finalFocusElm = finalFocusElm || elm; | ||
if (mappedEvent) { | ||
const onKeyHandler = isUp | ||
? elm[`on${mappedEvent}Up`] | ||
: elm[`on${mappedEvent}`] || elm[`on${mappedEvent}Down`]; | ||
const propagateKeyUp = Boolean( | ||
mappedEvent && propagatedUpKeys.includes(mappedEvent), | ||
); | ||
if (mappedEvent) { | ||
for (const elm of focusPath) { | ||
finalFocusElm = finalFocusElm || elm; | ||
const keyEvent = elm[`on${mappedEvent}`] as unknown; | ||
const keyUpEvent = elm[`on${mappedEvent}Up`] as unknown; | ||
const keyDownEvent = elm[`on${mappedEvent}Down`] as unknown; | ||
const skipDown = !isUp && propagateKeyUp && !keyDownEvent; | ||
const skipUp = isUp && !isHold && !propagateKeyUp && !keyUpEvent; | ||
if (skipDown || skipUp) { | ||
continue; | ||
} | ||
const onKeyHandler = (isUp ? keyUpEvent : keyDownEvent) || keyEvent; | ||
if ( | ||
@@ -162,18 +177,19 @@ isFunction(onKeyHandler) && | ||
} | ||
} else { | ||
console.log(`Unhandled key event: ${e.key || e.keyCode}`); | ||
} | ||
if (isUp && !isHold) { | ||
continue; | ||
} | ||
if (isUp && !isHold) { | ||
continue; | ||
} | ||
const fallbackFunction = isHold ? elm.onKeyHold : elm.onKeyPress; | ||
if ( | ||
isFunction(fallbackFunction) && | ||
fallbackFunction.call(elm, e, mappedEvent, elm, finalFocusElm) === true | ||
) { | ||
break; | ||
const fallbackFunction = isHold ? elm.onKeyHold : elm.onKeyPress; | ||
if ( | ||
isFunction(fallbackFunction) && | ||
fallbackFunction.call(elm, e, mappedEvent, elm, finalFocusElm) === true | ||
) { | ||
break; | ||
} | ||
} | ||
} else { | ||
console.log(`Unhandled key event: ${e.key || e.keyCode}`); | ||
} | ||
return false; | ||
@@ -189,3 +205,2 @@ }; | ||
) => { | ||
delete keyHoldTimeouts[e.key || e.keyCode]; | ||
propagateKeyPress(e, mappedKeyHoldEvent, true); | ||
@@ -207,12 +222,11 @@ }; | ||
if (mappedKeyHoldEvent) { | ||
if (keyHoldTimeouts[key]) { | ||
clearTimeout(keyHoldTimeouts[key]); | ||
if (!keyHoldTimeouts[key]) { | ||
keyHoldTimeouts[key] = window.setTimeout( | ||
() => keyHoldCallback(keydown, mappedKeyHoldEvent), | ||
delay, | ||
); | ||
} | ||
keyHoldTimeouts[key] = window.setTimeout( | ||
() => keyHoldCallback(keydown, mappedKeyHoldEvent), | ||
delay, | ||
); | ||
} else { | ||
propagateKeyPress(keydown, mappedKeyEvent, false); | ||
} | ||
propagateKeyPress(keydown, mappedKeyEvent, false, propagatedUpKeys); | ||
} else if (keyup) { | ||
@@ -222,10 +236,8 @@ const key: KeyNameOrKeyCode = keyup.key || keyup.keyCode; | ||
keyMapEntries[keyup.key] || keyMapEntries[keyup.keyCode]; | ||
if ( | ||
keyHoldTimeouts[key] || | ||
(mappedKeyEvent && propagatedUpKeys.includes(mappedKeyEvent)) | ||
) { | ||
if (keyHoldTimeouts[key]) { | ||
clearTimeout(keyHoldTimeouts[key]); | ||
delete keyHoldTimeouts[key]; | ||
propagateKeyPress(keyup, mappedKeyEvent, false); | ||
} | ||
propagateKeyPress(keyup, mappedKeyEvent, false, propagatedUpKeys); | ||
} | ||
@@ -232,0 +244,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
232194
3600
3