@lightningjs/solid-primitives
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -28,3 +28,3 @@ import { ElementNode } from '@lightningjs/solid'; | ||
onBlur?: (currentFocusedElm: ElementNode | null, prevFocusedElm: ElementNode | null) => void; | ||
onKeyPress?: (this: ElementNode, e: KeyboardEvent, key: string, currentFocusedElm: ElementNode) => KeyHandlerReturn; | ||
onKeyPress?: (this: ElementNode, e: KeyboardEvent, mappedKeyEvent: string | undefined, currentFocusedElm: ElementNode) => KeyHandlerReturn; | ||
onSelectedChanged?: (container: ElementNode, activeElm: ElementNode, selectedIndex: number | null, lastSelectedIndex: number | null) => void; | ||
@@ -35,2 +35,8 @@ skipFocus?: boolean; | ||
} | ||
interface IntrinsicNodeStyleProps { | ||
focus?: IntrinsicNodeStyleProps; | ||
} | ||
interface IntrinsicTextNodeStyleProps { | ||
focus?: IntrinsicTextNodeStyleProps; | ||
} | ||
interface TextNode { | ||
@@ -37,0 +43,0 @@ skipFocus?: undefined; |
@@ -37,2 +37,3 @@ /* | ||
}; | ||
const keyMapEntries = Object.entries(keyMap); | ||
createEffect(on(activeElement, (currentFocusedElm, prevFocusedElm, prevFocusPath = []) => { | ||
@@ -65,14 +66,21 @@ const newFocusedElms = []; | ||
if (e) { | ||
const key = keyMap[e.key] || e.key; | ||
// Search keyMap for the value of the pressed key | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const foundKeyEntry = keyMapEntries.find(([key, value]) => { | ||
return (value === e.key); | ||
}); | ||
untrack(() => { | ||
const fp = focusPath(); | ||
for (const elm of fp) { | ||
const onKeyHandler = elm[`on${key}`]; | ||
if (isFunc(onKeyHandler)) { | ||
if (onKeyHandler.call(elm, e, elm) === true) { | ||
break; | ||
const mappedKeyEvent = foundKeyEntry ? foundKeyEntry[0] : undefined; | ||
if (mappedKeyEvent) { | ||
const onKeyHandler = elm[`on${mappedKeyEvent}`]; | ||
if (isFunc(onKeyHandler)) { | ||
if (onKeyHandler.call(elm, e, elm) === true) { | ||
break; | ||
} | ||
} | ||
} | ||
if (isFunc(elm.onKeyPress)) { | ||
if (elm.onKeyPress.call(elm, e, key, elm) === true) { | ||
if (elm.onKeyPress.call(elm, e, mappedKeyEvent, elm) === true) { | ||
break; | ||
@@ -79,0 +87,0 @@ } |
{ | ||
"name": "@lightningjs/solid-primitives", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Lightning Primitives for Solid Lightning", | ||
@@ -41,3 +41,3 @@ "type": "module", | ||
"@lightningjs/renderer": "^0.3.6", | ||
"@lightningjs/solid": "^0.6.10", | ||
"@lightningjs/solid": "^0.7.0", | ||
"@typescript-eslint/eslint-plugin": "^6.3.0", | ||
@@ -44,0 +44,0 @@ "@typescript-eslint/parser": "^6.3.0", |
@@ -56,3 +56,3 @@ /* | ||
e: KeyboardEvent, | ||
key: string, | ||
mappedKeyEvent: string | undefined, | ||
currentFocusedElm: ElementNode, | ||
@@ -71,2 +71,12 @@ ) => KeyHandlerReturn; | ||
interface IntrinsicNodeStyleProps { | ||
// TODO: Refactor states to use a $ prefix | ||
focus?: IntrinsicNodeStyleProps; | ||
} | ||
interface IntrinsicTextNodeStyleProps { | ||
// TODO: Refactor states to use a $ prefix | ||
focus?: IntrinsicTextNodeStyleProps; | ||
} | ||
interface TextNode { | ||
@@ -94,2 +104,3 @@ skipFocus?: undefined; | ||
}; | ||
const keyMapEntries = Object.entries(keyMap); | ||
createEffect( | ||
@@ -134,10 +145,17 @@ on( | ||
if (e) { | ||
const key = keyMap[e.key as keyof typeof keyMap] || e.key; | ||
// Search keyMap for the value of the pressed key | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const foundKeyEntry = keyMapEntries.find(([key, value]) => { | ||
return (value === e.key); | ||
}); | ||
untrack(() => { | ||
const fp = focusPath(); | ||
for (const elm of fp) { | ||
const onKeyHandler = elm[`on${key}` as keyof KeyMapEventHandlers]; | ||
if (isFunc(onKeyHandler)) { | ||
if (onKeyHandler.call(elm, e, elm) === true) { | ||
break; | ||
const mappedKeyEvent = foundKeyEntry ? foundKeyEntry[0] : undefined; | ||
if (mappedKeyEvent) { | ||
const onKeyHandler = elm[`on${mappedKeyEvent}` as keyof KeyMapEventHandlers]; | ||
if (isFunc(onKeyHandler)) { | ||
if (onKeyHandler.call(elm, e, elm) === true) { | ||
break; | ||
} | ||
} | ||
@@ -147,3 +165,3 @@ } | ||
if (isFunc(elm.onKeyPress)) { | ||
if (elm.onKeyPress.call(elm, e, key, elm) === true) { | ||
if (elm.onKeyPress.call(elm, e, mappedKeyEvent, elm) === true) { | ||
break; | ||
@@ -150,0 +168,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
150290
1648
0