Skip to content
This repository has been archived by the owner on Mar 14, 2021. It is now read-only.

Commit

Permalink
changed exUi.js to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
baetz-daniel committed Feb 9, 2020
1 parent 88cd366 commit 1eafec6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 47 deletions.
46 changes: 0 additions & 46 deletions src/exUi/exUi.js

This file was deleted.

59 changes: 59 additions & 0 deletions src/exUi/exUi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { InputFlags } from '@/exUi/InputFlags';
import Vue from 'vue';

Vue.directive('ui-focusable', {
bind: (el, binding) => {
const modifiers = Object.keys(binding.modifiers);
let flags = InputFlags.ALL;
if (!binding.value && modifiers.length !== 0) {
flags = 0;
for (const key of modifiers) {
flags |= InputFlags[key as keyof typeof InputFlags];
}
} else {
for (const key of modifiers) {
flags &= ~InputFlags[key as keyof typeof InputFlags];
}
}
el._exUiFocusIn = async () => {
el._hasFocus = true;
window.exUiInput.removeFlag(flags);
};
el.addEventListener('focusin', el._exUiFocusIn);

if (!binding.arg) {
el._exUiFocusOut = async () => window.exUiInput.setFlag(flags);
} else {
el._exUiFocusOut = () => {
if (el._hasFocus) {
el.focus();
}
};
el._exUikeyUp = async (e: KeyboardEvent) => {
if (binding.arg === e.key) {
el._hasFocus = false;
el.blur();
await window.exUiInput.setFlag(flags);
}
};
el.addEventListener('keyup', el._exUikeyUp);
}
el.addEventListener('focusout', el._exUiFocusOut);
},
unbind: (el, binding) => {
if (el._exUiFocusIn != null) {
el.removeEventListener('focusin', el._exUiFocusIn);
el._exUiFocusIn = null;
}
if (binding.arg) {
if (el._exUikeyUp != null) {
el.removeEventListener('keyup', el._exUikeyUp);
el._exUikeyUp = null;
}
}
if (el._exUiFocusOut != null) {
el.removeEventListener('focusout', el._exUiFocusOut);
el._exUiFocusOut = null;
}
},
});
7 changes: 7 additions & 0 deletions src/shims/exui.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { InputFlags } from '@/exUi/InputFlags';

declare global {
// tslint:disable-next-line
interface HTMLElement {
_exUiFocusIn: (() => Promise<void>) | null;
_exUiFocusOut: (() => Promise<void>) | (() => void) | null;
_exUikeyUp: ((event: KeyboardEvent) => Promise<void>) | null;
_hasFocus: boolean;
}
// tslint:disable-next-line
interface Window {
cefSharp: {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
},
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx", "src/exUi/exUi.js"],
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx", "src/exUi/exUi.ts"],
"exclude": ["node_modules"]
}

0 comments on commit 1eafec6

Please sign in to comment.