lenix 1.7.22 → 1.7.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/nui/focus.ts +10 -21
- package/nui/index.ts +1 -0
- package/nui/keydown.ts +22 -0
- package/package.json +1 -1
package/nui/focus.ts
CHANGED
|
@@ -2,26 +2,15 @@ import { Request } from '../shared/types.ts'
|
|
|
2
2
|
import { fetchNui } from './fetch.ts'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Sets the keyboard and cursor focus state for the NUI browser.
|
|
6
6
|
*/
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export const setFocus = (
|
|
8
|
+
keyboard: boolean,
|
|
9
|
+
cursor: boolean
|
|
10
|
+
) => fetchNui<Request<true, '__nuiFocus', {
|
|
11
|
+
keyboard: boolean,
|
|
12
|
+
cursor: boolean
|
|
13
|
+
}>>('__nuiFocus', { keyboard, cursor })
|
|
13
14
|
|
|
14
|
-
export const
|
|
15
|
-
|
|
16
|
-
onEvent: () => void
|
|
17
|
-
) => {
|
|
18
|
-
|
|
19
|
-
const handler = (e: KeyboardEvent) => {
|
|
20
|
-
if (e.key !== key) return
|
|
21
|
-
|
|
22
|
-
onEvent()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
window.addEventListener('keydown', handler)
|
|
26
|
-
return () => window.removeEventListener('keydown', handler)
|
|
27
|
-
}
|
|
15
|
+
export const focus = () => setFocus(true, true);
|
|
16
|
+
export const unFocus = () => setFocus(false, false);
|
package/nui/index.ts
CHANGED
package/nui/keydown.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const keyHandlers = new Map<string, Set<() => void>>()
|
|
2
|
+
|
|
3
|
+
window.addEventListener("keydown", (event) => {
|
|
4
|
+
keyHandlers.get(event.key)?.forEach((handler) => handler())
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
export const onKeyDown = (
|
|
8
|
+
key: KeyboardEvent["key"],
|
|
9
|
+
handler: () => void
|
|
10
|
+
) => {
|
|
11
|
+
const handlers = keyHandlers.get(key) ?? new Set()
|
|
12
|
+
handlers.add(handler)
|
|
13
|
+
keyHandlers.set(key, handlers)
|
|
14
|
+
|
|
15
|
+
return () => {
|
|
16
|
+
handlers.delete(handler)
|
|
17
|
+
|
|
18
|
+
if (handlers.size === 0) {
|
|
19
|
+
keyHandlers.delete(key)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|