Compare commits

...

4 Commits

Author SHA1 Message Date
d776843494 2.0.15 2022-04-21 23:52:45 +02:00
79e64c4cc2 fix(core): update 2022-04-21 23:52:45 +02:00
7192d3fbf7 2.0.14 2022-04-21 23:10:14 +02:00
42bcb8243d fix(core): update 2022-04-21 23:10:14 +02:00
4 changed files with 14 additions and 35 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@designestate/dees-domtools", "name": "@designestate/dees-domtools",
"version": "2.0.13", "version": "2.0.15",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@designestate/dees-domtools", "name": "@designestate/dees-domtools",
"version": "2.0.13", "version": "2.0.15",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@apiglobal/typedrequest": "^2.0.3", "@apiglobal/typedrequest": "^2.0.3",

View File

@ -1,6 +1,6 @@
{ {
"name": "@designestate/dees-domtools", "name": "@designestate/dees-domtools",
"version": "2.0.13", "version": "2.0.15",
"private": false, "private": false,
"description": "tools to simplify complex css structures", "description": "tools to simplify complex css structures",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -140,12 +140,9 @@ export class Keyboard {
public keyEnum = Key; public keyEnum = Key;
public on(keys: Key[] | KeyCombo[]) { public on(keys: Key[]) {
const combos = this.toCombos(keys);
const subject = new plugins.smartrx.rxjs.Subject<KeyboardEvent>(); const subject = new plugins.smartrx.rxjs.Subject<KeyboardEvent>();
combos.forEach((combo) => { this.registerKeys(keys, subject);
this.registerComboCallback(combo, subject);
});
return subject; return subject;
} }
@ -168,8 +165,8 @@ export class Keyboard {
private handleKeyDown = (event: KeyboardEvent) => { private handleKeyDown = (event: KeyboardEvent) => {
this.pressedKeys.add(event.keyCode); this.pressedKeys.add(event.keyCode);
this.mapCombosToHandlers.forEach((subjectArg, comboArg) => { this.mapCombosToHandlers.forEach((subjectArg, keysArg) => {
if (this.isComboPressed(comboArg)) { if (this.areAllKeysPressed(keysArg)) {
subjectArg.next(event); subjectArg.next(event);
} }
}); });
@ -179,7 +176,7 @@ export class Keyboard {
this.pressedKeys.delete(event.keyCode); this.pressedKeys.delete(event.keyCode);
}; };
private isComboPressed(combo: number[]) { private areAllKeysPressed(combo: number[]) {
let result = true; let result = true;
combo.forEach((key) => { combo.forEach((key) => {
@ -191,33 +188,15 @@ export class Keyboard {
return result; return result;
} }
private registerComboCallback( private registerKeys(
comboArg: Array<Key>, keysArg: Array<Key>,
subjectArg: plugins.smartrx.rxjs.Subject<KeyboardEvent> subjectArg: plugins.smartrx.rxjs.Subject<KeyboardEvent>
) { ) {
if (!this.mapCombosToHandlers.has(comboArg)) { if (!this.mapCombosToHandlers.has(keysArg)) {
this.mapCombosToHandlers.set(comboArg, subjectArg); this.mapCombosToHandlers.set(keysArg, subjectArg);
} else { } else {
const subject = this.mapCombosToHandlers.get(comboArg); const subject = this.mapCombosToHandlers.get(keysArg);
return subject; return subject;
} }
} }
private toCombos(keys: KeyCombo[] | Key[]) {
if (keys.length === 0) {
return [];
}
const isKeys = !Array.isArray(keys[0]);
let combos: KeyCombo[] = [];
if (isKeys) {
combos = (keys as Key[]).map((key) => [key]);
} else {
combos = keys as KeyCombo[];
combos = combos.filter((combo) => combo.length > 0);
}
return combos;
}
} }

View File

@ -5,7 +5,7 @@ import * as breakpoints from './domtools.css.breakpoints.js';
import * as css from './domtools.css.js'; import * as css from './domtools.css.js';
export { css, breakpoints, elementBasic }; export { css, breakpoints, elementBasic };
export { DomTools } from './domtools.classes.domtools.js'; export { DomTools, IDomToolsContructorOptions } from './domtools.classes.domtools.js';
export { TypedRequest } from '@apiglobal/typedrequest'; export { TypedRequest } from '@apiglobal/typedrequest';
export { IWebSetupConstructorOptions } from '@pushrocks/websetup'; export { IWebSetupConstructorOptions } from '@pushrocks/websetup';
export { rxjs } from '@pushrocks/smartrx'; export { rxjs } from '@pushrocks/smartrx';