fix javascript files import.

This commit is contained in:
Miroslav Šedivý 2024-03-17 14:47:53 +01:00
parent 5ebfb043f8
commit f3a49e7051
6 changed files with 100 additions and 82 deletions

View File

@ -1,73 +1,8 @@
// https://github.com/apache/guacamole-client/blob/1ca1161a68030565a37319ec6275556dfcd1a1af/guacamole-common-js/src/main/webapp/modules/Keyboard.js // https://github.com/apache/guacamole-client/blob/1ca1161a68030565a37319ec6275556dfcd1a1af/guacamole-common-js/src/main/webapp/modules/Keyboard.js
import GuacamoleKeyboard from './guacamole.js' import GuacamoleKeyboard from './guacamole/keyboard'
import type { Interface } from './guacamole/keyboard'
export interface GuacamoleKeyboardInterface { export interface GuacamoleKeyboardInterface extends Interface {
/**
* Fired whenever the user presses a key with the element associated
* with this Guacamole.Keyboard in focus.
*
* @event
* @param {Number} keysym The keysym of the key being pressed.
* @return {Boolean} true if the key event should be allowed through to the
* browser, false otherwise.
*/
onkeydown?: (keysym: number) => boolean
/**
* Fired whenever the user releases a key with the element associated
* with this Guacamole.Keyboard in focus.
*
* @event
* @param {Number} keysym The keysym of the key being released.
*/
onkeyup?: (keysym: number) => void
/**
* Marks a key as pressed, firing the keydown event if registered. Key
* repeat for the pressed key will start after a delay if that key is
* not a modifier. The return value of this function depends on the
* return value of the keydown event handler, if any.
*
* @param {Number} keysym The keysym of the key to press.
* @return {Boolean} true if event should NOT be canceled, false otherwise.
*/
press: (keysym: number) => boolean
/**
* Marks a key as released, firing the keyup event if registered.
*
* @param {Number} keysym The keysym of the key to release.
*/
release: (keysym: number) => void
/**
* Presses and releases the keys necessary to type the given string of
* text.
*
* @param {String} str
* The string to type.
*/
type: (str: string) => void
/**
* Resets the state of this keyboard, releasing all keys, and firing keyup
* events for each released key.
*/
reset: () => void
/**
* Attaches event listeners to the given Element, automatically translating
* received key, input, and composition events into simple keydown/keyup
* events signalled through this Guacamole.Keyboard's onkeydown and
* onkeyup handlers.
*
* @param {Element|Document} element
* The Element to attach event listeners to for the sake of handling
* key or input events.
*/
listenTo: (element: Element | Document) => void
// custom functions
removeListener: () => void removeListener: () => void
} }

View File

@ -0,0 +1,68 @@
declare export interface Interface {
/**
* Fired whenever the user presses a key with the element associated
* with this Guacamole.Keyboard in focus.
*
* @event
* @param {Number} keysym The keysym of the key being pressed.
* @return {Boolean} true if the key event should be allowed through to the
* browser, false otherwise.
*/
onkeydown?: (keysym: number) => boolean
/**
* Fired whenever the user releases a key with the element associated
* with this Guacamole.Keyboard in focus.
*
* @event
* @param {Number} keysym The keysym of the key being released.
*/
onkeyup?: (keysym: number) => void
/**
* Marks a key as pressed, firing the keydown event if registered. Key
* repeat for the pressed key will start after a delay if that key is
* not a modifier. The return value of this function depends on the
* return value of the keydown event handler, if any.
*
* @param {Number} keysym The keysym of the key to press.
* @return {Boolean} true if event should NOT be canceled, false otherwise.
*/
press: (keysym: number) => boolean
/**
* Marks a key as released, firing the keyup event if registered.
*
* @param {Number} keysym The keysym of the key to release.
*/
release: (keysym: number) => void
/**
* Presses and releases the keys necessary to type the given string of
* text.
*
* @param {String} str
* The string to type.
*/
type: (str: string) => void
/**
* Resets the state of this keyboard, releasing all keys, and firing keyup
* events for each released key.
*/
reset: () => void
/**
* Attaches event listeners to the given Element, automatically translating
* received key, input, and composition events into simple keydown/keyup
* events signalled through this Guacamole.Keyboard's onkeydown and
* onkeyup handlers.
*
* @param {Element|Document} element
* The Element to attach event listeners to for the sake of handling
* key or input events.
*/
listenTo: (element: Element | Document) => void
}
declare export default function (element?: Element): Interface

View File

@ -1,2 +0,0 @@
import Keyboard from './novnc/keyboard.js'
export default Keyboard

View File

@ -1,13 +1,7 @@
// https://github.com/novnc/noVNC/blob/ca6527c1bf7131adccfdcc5028964a1e67f9018c/core/input/keyboard.js // https://github.com/novnc/noVNC/blob/ca6527c1bf7131adccfdcc5028964a1e67f9018c/core/input/keyboard.js
import Keyboard from './novnc.js' import Keyboard from './novnc/keyboard'
export interface NoVncKeyboardInterface { export interface NoVncKeyboardInterface extends Keyboard {
// original functions
onkeyevent: (keysym: number | null, code: string, down: boolean) => boolean
grab: () => void
ungrab: () => void
// custom functions
onkeydown?: (keysym: number) => boolean onkeydown?: (keysym: number) => boolean
onkeyup?: (keysym: number) => void onkeyup?: (keysym: number) => void
release: (keysym: number) => void release: (keysym: number) => void
@ -16,14 +10,14 @@ export interface NoVncKeyboardInterface {
} }
export default function (element?: Element): NoVncKeyboardInterface { export default function (element?: Element): NoVncKeyboardInterface {
// @ts-ignore const keyboard = new Keyboard(element) as NoVncKeyboardInterface
const keyboard = new Keyboard(element)
// map on key event to onkeydown and onkeyup // map on key event to onkeydown and onkeyup
keyboard.onkeyevent = function (keysym: number | null, code: string, down: boolean) { keyboard.onkeyevent = function (keysym: number | null, code: string, down: boolean) {
if (keysym === null) return false if (keysym === null) return false
if (down) return this.onkeydown(keysym, code) if (down && this.onkeydown) return this.onkeydown(keysym)
this.onkeyup(keysym, code) if (!down && this.onkeyup) this.onkeyup(keysym)
return false
} }
// add release function // add release function

View File

@ -0,0 +1,23 @@
declare export default class Keyboard {
constructor (element?: Element)
_target: Element | Document | null
_keyDownList: { [key: string]: number }
_altGrArmed: boolean
_eventHandlers: {
keyup: (event: KeyboardEvent) => void
keydown: (event: KeyboardEvent) => void
blur: () => void
}
_sendKeyEvent(keysym: number, code: string, down: boolean): void
_getKeyCode(e: KeyboardEvent): string
_handleKeyDown(e: KeyboardEvent): void
_handleKeyUp(e: KeyboardEvent): void
_handleAltGrTimeout(): void
_allKeysUp(): void
onkeyevent: (keysym: number | null, code: string, down: boolean) => boolean
grab: () => void
ungrab: () => void
}