Compare commits

...

10 Commits

Author SHA1 Message Date
ca52d06c60 2.0.18 2022-04-22 09:37:50 +02:00
d33366c487 fix(core): update 2022-04-22 09:37:50 +02:00
3bc5e1d0e2 2.0.17 2022-04-22 09:25:10 +02:00
96a88112dc fix(core): update 2022-04-22 09:25:10 +02:00
6c0c1e165f 2.0.16 2022-04-21 23:53:02 +02:00
653a4138a9 fix(core): update 2022-04-21 23:53:02 +02:00
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
5 changed files with 32 additions and 38 deletions

4
package-lock.json generated
View File

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

View File

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

View File

@ -146,6 +146,23 @@ export class DomTools {
this.elements.headElement.appendChild(styleElement);
}
/**
* allows to set global styles
* @param stylesText the css text you want to set
*/
public async setExternalScript(scriptLinkArg: string) {
await this.domReady.promise;
const done = plugins.smartpromise.defer();
const script = document.createElement('script')
script.src = scriptLinkArg;
script.addEventListener('load', function() {
done.resolve();
});
const parentNode = document.head || document.body;
parentNode.append(script);
await done.promise;
}
/**
* allows setting external css files
* @param cssLinkArg a url to an external stylesheet

View File

@ -128,8 +128,6 @@ export enum Key {
Quote = 222,
}
type KeyCombo = Array<Key>;
export class Keyboard {
private mapCombosToHandlers = new Map<number[], plugins.smartrx.rxjs.Subject<KeyboardEvent>>();
private pressedKeys = new Set<Key>();
@ -140,12 +138,9 @@ export class Keyboard {
public keyEnum = Key;
public on(keys: Key[] | KeyCombo[]) {
const combos = this.toCombos(keys);
public on(keys: Key[]) {
const subject = new plugins.smartrx.rxjs.Subject<KeyboardEvent>();
combos.forEach((combo) => {
this.registerComboCallback(combo, subject);
});
this.registerKeys(keys, subject);
return subject;
}
@ -168,8 +163,8 @@ export class Keyboard {
private handleKeyDown = (event: KeyboardEvent) => {
this.pressedKeys.add(event.keyCode);
this.mapCombosToHandlers.forEach((subjectArg, comboArg) => {
if (this.isComboPressed(comboArg)) {
this.mapCombosToHandlers.forEach((subjectArg, keysArg) => {
if (this.areAllKeysPressed(keysArg)) {
subjectArg.next(event);
}
});
@ -179,10 +174,10 @@ export class Keyboard {
this.pressedKeys.delete(event.keyCode);
};
private isComboPressed(combo: number[]) {
private areAllKeysPressed(keysArg: Key[]) {
let result = true;
combo.forEach((key) => {
keysArg.forEach((key) => {
if (!this.pressedKeys.has(key)) {
result = false;
}
@ -191,33 +186,15 @@ export class Keyboard {
return result;
}
private registerComboCallback(
comboArg: Array<Key>,
private registerKeys(
keysArg: Array<Key>,
subjectArg: plugins.smartrx.rxjs.Subject<KeyboardEvent>
) {
if (!this.mapCombosToHandlers.has(comboArg)) {
this.mapCombosToHandlers.set(comboArg, subjectArg);
if (!this.mapCombosToHandlers.has(keysArg)) {
this.mapCombosToHandlers.set(keysArg, subjectArg);
} else {
const subject = this.mapCombosToHandlers.get(comboArg);
const subject = this.mapCombosToHandlers.get(keysArg);
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';
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 { IWebSetupConstructorOptions } from '@pushrocks/websetup';
export { rxjs } from '@pushrocks/smartrx';