Archived
Private
Public Access
1
0

Finished WindowAPI for the frontend

This commit is contained in:
2022-10-24 22:57:17 +02:00
parent 0fd41608b9
commit e27992ffdb
246 changed files with 1067505 additions and 39 deletions

22
WindowAPI/dist/WindowAPI.d.ts vendored Normal file
View File

@@ -0,0 +1,22 @@
import { Getters } from "./helper/functions/Getter.js";
import { Setters } from "./helper/functions/Setter.js";
import { WindowEventEmitter } from "./helper/functions/WindowEventEmitter.js";
import { Actions } from "./helper/functions/Actions.js";
export declare class WindowAPI {
private currentEventListener;
constructor();
private sendRequest;
private getMethod;
private setMethod;
get: Getters;
set: Setters;
action: Actions;
event: WindowEventEmitter;
private openWindow;
private closeWindow;
private sendDataToWindow;
private close;
private focus;
private notification;
private openPopup;
}

132
WindowAPI/dist/WindowAPI.js vendored Normal file
View File

@@ -0,0 +1,132 @@
import { WindowEventEmitter } from "./helper/functions/WindowEventEmitter.js";
export class WindowAPI {
constructor() {
this.get = {
title: this.getMethod('title'),
size: this.getMethod('size'),
position: this.getMethod('size'),
maximized: this.getMethod('maximized'),
minimized: this.getMethod('minimized'),
draggable: this.getMethod('draggable'),
resizable: this.getMethod('resizable'),
};
this.set = {
title: this.setMethod('title'),
size: this.setMethod('size'),
position: this.setMethod('position'),
maximized: this.setMethod('maximized'),
minimized: this.setMethod('minimized'),
draggable: this.setMethod('draggable'),
resizable: this.setMethod('resizable'),
};
this.action = {
openWindow: this.openWindow.bind(this),
closeWindow: this.closeWindow.bind(this),
sendDataToWindow: this.sendDataToWindow.bind(this),
close: this.close.bind(this),
focus: this.focus.bind(this),
notification: this.notification.bind(this),
openPopup: this.openPopup.bind(this)
};
this.event = new class extends WindowEventEmitter {
emit(name, data) {
if (!this._events[name]) {
throw new Error(`Can't emit an event. Event "${name}" doesn't exits.`);
}
const fire = (callback) => callback(data);
this._events[name].forEach(fire);
}
on(name, listener) {
if (!this._events[name]) {
this._events[name] = [];
}
this._events[name].push(listener);
}
removeListener(name, listenerToRemove) {
if (!this._events[name]) {
throw new Error(`Can't remove a listener. Event "${name}" doesn't exits.`);
}
const filter = (listener) => listener !== listenerToRemove;
this._events[name] = this._events[name].filter(filter);
}
};
window.addEventListener('message', (event) => {
const data = event.data;
if (this.currentEventListener !== undefined && data.method !== "event") {
this.currentEventListener(data);
delete this.currentEventListener;
}
if (data.method === 'event') {
const eventData = data.content;
this.event.emit(data.event, eventData);
}
}, false);
}
sendRequest(data) {
parent.postMessage(data, '*');
}
getMethod(variable) {
return () => new Promise(resolve => {
this.currentEventListener = (data) => {
resolve(data.content);
};
this.sendRequest({ method: 'get', variable });
});
}
setMethod(variable) {
return (content) => {
this.sendRequest({ method: "set", variable, content });
};
}
openWindow(identifier, args, asPopup) {
return new Promise(resolve => {
this.currentEventListener = (data) => {
resolve(data.content);
};
this.sendRequest({ method: 'action', action: 'openWindow', content: { identifier, args, asPopup } });
});
}
closeWindow(uuid) {
return new Promise(resolve => {
this.currentEventListener = (data) => {
resolve(data.content);
};
this.sendRequest({ method: 'action', action: 'closeWindow', content: { uuid } });
});
}
sendDataToWindow(uuid, data) {
return new Promise(resolve => {
this.currentEventListener = (data) => {
resolve(data.content);
};
this.sendRequest({ method: 'action', action: 'messageWindow', content: { uuid, data } });
});
}
close() {
return new Promise(resolve => {
this.currentEventListener = () => resolve();
this.sendRequest({ method: 'action', action: 'closeSelf' });
});
}
focus() {
return new Promise(resolve => {
this.currentEventListener = () => resolve();
this.sendRequest({ method: 'action', action: 'focus' });
});
}
notification(notification) {
return new Promise(resolve => {
this.currentEventListener = () => resolve();
this.sendRequest({ method: 'action', action: 'notification', content: notification });
});
}
openPopup(data) {
return new Promise(resolve => {
this.currentEventListener = (data) => {
resolve(data.content);
};
this.sendRequest({ method: 'action', action: 'popup', content: data });
});
}
}
//# sourceMappingURL=WindowAPI.js.map

1
WindowAPI/dist/WindowAPI.js.map vendored Normal file

File diff suppressed because one or more lines are too long

5
WindowAPI/dist/helper/EventData.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
import { WindowEventName } from "./PackageTypes.js";
export interface WindowEvent {
type: WindowEventName;
data: any;
}

2
WindowAPI/dist/helper/EventData.js vendored Normal file
View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=EventData.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"EventData.js","sourceRoot":"","sources":["../../src/helper/EventData.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,2 @@
export declare class Notification {
}

3
WindowAPI/dist/helper/Notification.js vendored Normal file
View File

@@ -0,0 +1,3 @@
export class Notification {
}
//# sourceMappingURL=Notification.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Notification.js","sourceRoot":"","sources":["../../src/helper/Notification.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAY;CAExB"}

8
WindowAPI/dist/helper/Package.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
import { PackageActionType, PackageMethod, PackageVariable, WindowEventName } from "./PackageTypes.js";
export interface Package {
method: PackageMethod;
variable?: PackageVariable;
action?: PackageActionType;
event?: WindowEventName;
content?: any;
}

2
WindowAPI/dist/helper/Package.js vendored Normal file
View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=Package.js.map

1
WindowAPI/dist/helper/Package.js.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Package.js","sourceRoot":"","sources":["../../src/helper/Package.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,4 @@
export declare type PackageMethod = "get" | "set" | "event" | "action";
export declare type PackageVariable = "title" | "size" | "position" | "maximized" | "minimized" | "draggable" | "resizable";
export declare type PackageActionType = "openWindow" | "closeWindow" | "closeSelf" | "focus" | "messageWindow" | "notification" | "popup";
export declare type WindowEventName = "resize" | "move" | "openAsPopup" | "open" | "close";

2
WindowAPI/dist/helper/PackageTypes.js vendored Normal file
View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=PackageTypes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"PackageTypes.js","sourceRoot":"","sources":["../../src/helper/PackageTypes.ts"],"names":[],"mappings":""}

2
WindowAPI/dist/helper/PopupData.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export declare class PopupData {
}

3
WindowAPI/dist/helper/PopupData.js vendored Normal file
View File

@@ -0,0 +1,3 @@
export class PopupData {
}
//# sourceMappingURL=PopupData.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"PopupData.js","sourceRoot":"","sources":["../../src/helper/PopupData.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAS;CAErB"}

View File

@@ -0,0 +1,11 @@
import { Notification } from "../Notification.js";
import { PopupData } from "../PopupData.js";
export interface Actions {
openWindow(identifier: string, args?: string[], asPopup?: boolean): Promise<number>;
closeWindow(uuid: number): Promise<boolean>;
sendDataToWindow(uuid: number, data: any): Promise<boolean>;
close(): Promise<void>;
focus(): Promise<void>;
notification(notification: Notification): Promise<void>;
openPopup<T>(data: PopupData): Promise<T>;
}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=Actions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Actions.js","sourceRoot":"","sources":["../../../src/helper/functions/Actions.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,15 @@
export interface Getters {
title(): Promise<string>;
size(): Promise<{
width: number;
height: number;
}>;
position(): Promise<{
x: number;
y: number;
}>;
maximized(): Promise<boolean>;
minimized(): Promise<boolean>;
draggable(): Promise<boolean>;
resizable(): Promise<boolean>;
}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=Getter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Getter.js","sourceRoot":"","sources":["../../../src/helper/functions/Getter.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,15 @@
export interface Setters {
title(value: string): void;
size(value: {
width: number;
height: number;
}): void;
position(value: {
x: number;
y: number;
}): void;
maximized(value: boolean): void;
minimized(value: boolean): void;
draggable(value: boolean): void;
resizable(value: boolean): void;
}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=Setter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Setter.js","sourceRoot":"","sources":["../../../src/helper/functions/Setter.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,11 @@
import { WindowEventName } from "../PackageTypes.js";
import { WindowEvent } from "../EventData.js";
export declare type WindowEventListener = (event: WindowEvent) => void;
export declare abstract class WindowEventEmitter {
protected _events: {
[name: string]: WindowEventListener[];
};
abstract on(name: WindowEventName, listener: WindowEventListener): void;
abstract removeListener(name: WindowEventName, listenerToRemove: WindowEventListener): void;
abstract emit(name: WindowEventName, data: WindowEvent): void;
}

View File

@@ -0,0 +1,6 @@
export class WindowEventEmitter {
constructor() {
this._events = {};
}
}
//# sourceMappingURL=WindowEventEmitter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"WindowEventEmitter.js","sourceRoot":"","sources":["../../../src/helper/functions/WindowEventEmitter.ts"],"names":[],"mappings":"AAKA,MAAM,OAAgB,kBAAkB;IAAxC;QAEc,YAAO,GAA4C,EAAE,CAAC;IAMpE,CAAC;CAAA"}