@signageos/front-applet 6.5.6 → 6.5.7
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.
|
@@ -4,15 +4,21 @@ import IKeyUpEvent from './IKeyUpEvent';
|
|
|
4
4
|
import { IInput } from './IInput';
|
|
5
5
|
export default class Input implements IInput {
|
|
6
6
|
readonly window: Window;
|
|
7
|
-
private messagePrefix;
|
|
8
|
-
static MESSAGE_PREFIX: string;
|
|
9
|
-
private eventEmitter;
|
|
7
|
+
private readonly messagePrefix;
|
|
8
|
+
static readonly MESSAGE_PREFIX: string;
|
|
9
|
+
private readonly eventEmitter;
|
|
10
|
+
private readonly hasWindowEventListener;
|
|
11
|
+
private alive;
|
|
10
12
|
constructor(window: Window, messagePrefix: string);
|
|
13
|
+
destroy(): void;
|
|
11
14
|
onKeyUp(listener: IKeyUpEventListener): void;
|
|
12
15
|
handleMessageData(data: IInputKeyMessage): void;
|
|
13
16
|
removeEventListeners(): void;
|
|
14
17
|
removeEventListener(event: string, listener: (...args: any[]) => void): void;
|
|
15
18
|
emitKeyUpEvent(event: IKeyUpEvent): void;
|
|
19
|
+
private isTopLevelFrame;
|
|
20
|
+
private canAccessParentOrigin;
|
|
16
21
|
private dispatchEventToParent;
|
|
17
22
|
private getMessage;
|
|
23
|
+
private checkAlive;
|
|
18
24
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const events_1 = require("events");
|
|
13
4
|
const Validate_1 = require("../Validate/Validate");
|
|
@@ -16,9 +7,39 @@ class Input {
|
|
|
16
7
|
this.window = window;
|
|
17
8
|
this.messagePrefix = messagePrefix;
|
|
18
9
|
this.eventEmitter = new events_1.EventEmitter();
|
|
19
|
-
this.
|
|
10
|
+
this.hasWindowEventListener = false;
|
|
11
|
+
this.alive = true;
|
|
12
|
+
this.dispatchEventToParent = (event) => {
|
|
13
|
+
try {
|
|
14
|
+
this.window.parent.document.dispatchEvent(new KeyboardEvent('keyup', event));
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
if (e instanceof ReferenceError) {
|
|
18
|
+
// KeyboardEvent constructor isn't available during tests.
|
|
19
|
+
// TODO Mock KeyboardEvent constructor during tests.
|
|
20
|
+
this.window.parent.document.dispatchEvent(event);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
if (!this.isTopLevelFrame() && this.canAccessParentOrigin()) {
|
|
28
|
+
this.hasWindowEventListener = true;
|
|
29
|
+
this.window.addEventListener('keyup', this.dispatchEventToParent);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
destroy() {
|
|
33
|
+
if (this.alive) {
|
|
34
|
+
this.alive = false;
|
|
35
|
+
this.removeEventListeners();
|
|
36
|
+
if (this.hasWindowEventListener) {
|
|
37
|
+
this.window.removeEventListener('keyup', this.dispatchEventToParent);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
20
40
|
}
|
|
21
41
|
onKeyUp(listener) {
|
|
42
|
+
this.checkAlive();
|
|
22
43
|
Validate_1.default({ listener }).required().function();
|
|
23
44
|
this.eventEmitter.addListener('keyup', listener);
|
|
24
45
|
}
|
|
@@ -30,7 +51,7 @@ class Input {
|
|
|
30
51
|
keyCode: data.keyCode,
|
|
31
52
|
keyName: data.keyName,
|
|
32
53
|
};
|
|
33
|
-
this.
|
|
54
|
+
this.emitKeyUpEvent(keyupEvent);
|
|
34
55
|
break;
|
|
35
56
|
default:
|
|
36
57
|
}
|
|
@@ -42,22 +63,42 @@ class Input {
|
|
|
42
63
|
this.eventEmitter.removeListener(event, listener);
|
|
43
64
|
}
|
|
44
65
|
emitKeyUpEvent(event) {
|
|
66
|
+
this.checkAlive();
|
|
45
67
|
this.eventEmitter.emit('keyup', event);
|
|
46
68
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
isTopLevelFrame() {
|
|
70
|
+
return this.window === this.window.parent;
|
|
71
|
+
}
|
|
72
|
+
canAccessParentOrigin() {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
try {
|
|
75
|
+
const hasParent = !!((_b = (_a = this.window) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.document);
|
|
76
|
+
if (!hasParent) {
|
|
77
|
+
console.warn('Parent window or document is not defined');
|
|
78
|
+
}
|
|
79
|
+
return hasParent;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
if (e instanceof DOMException) {
|
|
83
|
+
// Blocked a frame with origin "..." from accessing a cross-origin frame.
|
|
84
|
+
// This will happen on Android when applets have https://appassets.android.signageos.io origin
|
|
85
|
+
// and top-level frame has file:// origin. Android doesn't benefit from this hack anyway.
|
|
86
|
+
console.warn('Parent document is not accessible');
|
|
87
|
+
return false;
|
|
52
88
|
}
|
|
53
89
|
else {
|
|
54
|
-
|
|
90
|
+
throw e;
|
|
55
91
|
}
|
|
56
|
-
}
|
|
92
|
+
}
|
|
57
93
|
}
|
|
58
94
|
getMessage(name) {
|
|
59
95
|
return this.messagePrefix + '.' + Input.MESSAGE_PREFIX + '.' + name;
|
|
60
96
|
}
|
|
97
|
+
checkAlive() {
|
|
98
|
+
if (!this.alive) {
|
|
99
|
+
throw new Error('destroyed');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
61
102
|
}
|
|
62
103
|
exports.default = Input;
|
|
63
104
|
Input.MESSAGE_PREFIX = 'input';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sourceRoot":"","sources":["../../../src/FrontApplet/Input/Input.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Input.js","sourceRoot":"","sources":["../../../src/FrontApplet/Input/Input.ts"],"names":[],"mappings":";;AAAA,mCAAsC;AAItC,mDAA4C;AAG5C,MAAqB,KAAK;IAQzB,YAA4B,MAAc,EAAmB,aAAqB;QAAtD,WAAM,GAAN,MAAM,CAAQ;QAAmB,kBAAa,GAAb,aAAa,CAAQ;QALjE,iBAAY,GAAiB,IAAI,qBAAY,EAAE,CAAC;QAChD,2BAAsB,GAAY,KAAK,CAAC;QAEjD,UAAK,GAAY,IAAI,CAAC;QA4EtB,0BAAqB,GAAG,CAAC,KAAoB,EAAE,EAAE;YACxD,IAAI;gBACH,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;aAC7E;YAAC,OAAO,CAAC,EAAE;gBACX,IAAI,CAAC,YAAY,cAAc,EAAE;oBAChC,0DAA0D;oBAC1D,oDAAoD;oBACpD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;iBACjD;qBAAM;oBACN,MAAM,CAAC,CAAC;iBACR;aACD;QACF,CAAC,CAAA;QArFA,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,IAAI,CAAC,qBAAqB,EAAE,EAAE;YAC5D,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO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,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAEO,eAAe;QACtB,OAAO,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM,CAAA;IAC1C,CAAC;IAEO,qBAAqB;;QAC5B,IAAI;YACH,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,MAAM,0CAAE,QAAQ,CAAC,CAAC;YACpD,IAAI,CAAC,SAAS,EAAE;gBACf,OAAO,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;aACzD;YACD,OAAO,SAAS,CAAC;SACjB;QAAC,OAAO,CAAC,EAAE;YACX,IAAI,CAAC,YAAY,YAAY,EAAE;gBAC9B,yEAAyE;gBACzE,8FAA8F;gBAC9F,yFAAyF;gBACzF,OAAO,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;gBAClD,OAAO,KAAK,CAAC;aACb;iBAAM;gBACN,MAAM,CAAC,CAAC;aACR;SACD;IACF,CAAC;IAgBO,UAAU,CAAC,IAAY;QAC9B,OAAO,IAAI,CAAC,aAAa,GAAG,GAAG,GAAG,KAAK,CAAC,cAAc,GAAG,GAAG,GAAG,IAAI,CAAC;IACrE,CAAC;IAEO,UAAU;QACjB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;SAC7B;IACF,CAAC;;AAxGF,wBAyGC;AAxGuB,oBAAc,GAAW,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signageos/front-applet",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.7",
|
|
4
4
|
"main": "dist/bundle.js",
|
|
5
5
|
"types": "es6/bundle.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lint:prettier:fix": "prettier \"**/*.+(ts|tsx|json|js)\" --write",
|
|
21
21
|
"lint:staged": "npx lint-staged",
|
|
22
22
|
"prebuild": "rm -rf dist/*",
|
|
23
|
-
"prepare": "npm run
|
|
23
|
+
"prepare": "npm run build && npm run generate-declarations && npx husky install",
|
|
24
24
|
"test": "env NODE_ENV=test ./node_modules/mocha/bin/mocha --config .mocha/default.js",
|
|
25
25
|
"test:coverage": "npm run test:coverage:runtime && npm run test:coverage:types",
|
|
26
26
|
"test:coverage:runtime": "env NODE_ENV=test c8 ./node_modules/mocha/bin/mocha --config .mocha/transpile-only.js",
|