jpf-mobx 1.0.6
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.
- package/LICENSE.md +21 -0
- package/README.md +21 -0
- package/dist/controls/codeMirror/HtmlEditor/HtmlEditor.d.ts +0 -0
- package/dist/controls/codeMirror/HtmlEditor/HtmlEditor.js +1 -0
- package/dist/controls/codeMirror/HtmlEditor/HtmlEditor.js.map +1 -0
- package/dist/controls/codeMirror/JsonEditor/JsonEditor.d.ts +0 -0
- package/dist/controls/codeMirror/JsonEditor/JsonEditor.js +1 -0
- package/dist/controls/codeMirror/JsonEditor/JsonEditor.js.map +1 -0
- package/dist/controls/codeMirror/index.d.ts +0 -0
- package/dist/controls/codeMirror/index.js +1 -0
- package/dist/controls/codeMirror/index.js.map +1 -0
- package/dist/controls/custom/FileSelector/FileSelector.d.ts +0 -0
- package/dist/controls/custom/FileSelector/FileSelector.js +1 -0
- package/dist/controls/custom/FileSelector/FileSelector.js.map +1 -0
- package/dist/controls/custom/LabeledControl/LabeledControl.d.ts +15 -0
- package/dist/controls/custom/LabeledControl/LabeledControl.js +37 -0
- package/dist/controls/custom/LabeledControl/LabeledControl.js.map +1 -0
- package/dist/controls/custom/ListItem/ListItem.d.ts +0 -0
- package/dist/controls/custom/ListItem/ListItem.js +1 -0
- package/dist/controls/custom/ListItem/ListItem.js.map +1 -0
- package/dist/controls/custom/index.d.ts +1 -0
- package/dist/controls/custom/index.js +2 -0
- package/dist/controls/custom/index.js.map +1 -0
- package/dist/controls/html/Button/Button.d.ts +0 -0
- package/dist/controls/html/Button/Button.js +1 -0
- package/dist/controls/html/Button/Button.js.map +1 -0
- package/dist/controls/html/Div/Div.d.ts +14 -0
- package/dist/controls/html/Div/Div.js +25 -0
- package/dist/controls/html/Div/Div.js.map +1 -0
- package/dist/controls/html/Image/Image.d.ts +16 -0
- package/dist/controls/html/Image/Image.js +29 -0
- package/dist/controls/html/Image/Image.js.map +1 -0
- package/dist/controls/html/Input/Input.d.ts +0 -0
- package/dist/controls/html/Input/Input.js +1 -0
- package/dist/controls/html/Input/Input.js.map +1 -0
- package/dist/controls/html/Select/Select.d.ts +0 -0
- package/dist/controls/html/Select/Select.js +1 -0
- package/dist/controls/html/Select/Select.js.map +1 -0
- package/dist/controls/html/Span/Span.d.ts +11 -0
- package/dist/controls/html/Span/Span.js +23 -0
- package/dist/controls/html/Span/Span.js.map +1 -0
- package/dist/controls/html/index.d.ts +3 -0
- package/dist/controls/html/index.js +4 -0
- package/dist/controls/html/index.js.map +1 -0
- package/dist/controls/index.d.ts +6 -0
- package/dist/controls/index.js +7 -0
- package/dist/controls/index.js.map +1 -0
- package/dist/controls/jsonViewAwesome/index.d.ts +0 -0
- package/dist/controls/jsonViewAwesome/index.js +1 -0
- package/dist/controls/jsonViewAwesome/index.js.map +1 -0
- package/dist/controls/jsonViewAwesome/jsonFormatter/JsonFormatter.d.ts +0 -0
- package/dist/controls/jsonViewAwesome/jsonFormatter/JsonFormatter.js +1 -0
- package/dist/controls/jsonViewAwesome/jsonFormatter/JsonFormatter.js.map +1 -0
- package/dist/controls/kendo/Chart/Chart.d.ts +0 -0
- package/dist/controls/kendo/Chart/Chart.js +1 -0
- package/dist/controls/kendo/Chart/Chart.js.map +1 -0
- package/dist/controls/kendo/Culture/Culture.d.ts +1 -0
- package/dist/controls/kendo/Culture/Culture.js +26 -0
- package/dist/controls/kendo/Culture/Culture.js.map +1 -0
- package/dist/controls/kendo/DataSource/DataSource.d.ts +4 -0
- package/dist/controls/kendo/DataSource/DataSource.js +2 -0
- package/dist/controls/kendo/DataSource/DataSource.js.map +1 -0
- package/dist/controls/kendo/Dialog/Dialog.d.ts +0 -0
- package/dist/controls/kendo/Dialog/Dialog.js +1 -0
- package/dist/controls/kendo/Dialog/Dialog.js.map +1 -0
- package/dist/controls/kendo/Editor/Editor.d.ts +0 -0
- package/dist/controls/kendo/Editor/Editor.js +1 -0
- package/dist/controls/kendo/Editor/Editor.js.map +1 -0
- package/dist/controls/kendo/Grid/Grid.d.ts +0 -0
- package/dist/controls/kendo/Grid/Grid.js +1 -0
- package/dist/controls/kendo/Grid/Grid.js.map +1 -0
- package/dist/controls/kendo/Menu/Menu.d.ts +0 -0
- package/dist/controls/kendo/Menu/Menu.js +1 -0
- package/dist/controls/kendo/Menu/Menu.js.map +1 -0
- package/dist/controls/kendo/ObservableObject/ObservableObject.d.ts +0 -0
- package/dist/controls/kendo/ObservableObject/ObservableObject.js +1 -0
- package/dist/controls/kendo/ObservableObject/ObservableObject.js.map +1 -0
- package/dist/controls/kendo/Tree/Tree.d.ts +0 -0
- package/dist/controls/kendo/Tree/Tree.js +1 -0
- package/dist/controls/kendo/Tree/Tree.js.map +1 -0
- package/dist/controls/kendo/index.d.ts +0 -0
- package/dist/controls/kendo/index.js +1 -0
- package/dist/controls/kendo/index.js.map +1 -0
- package/dist/controls/leaflet/LabelControl/LabelControl.d.ts +12 -0
- package/dist/controls/leaflet/LabelControl/LabelControl.js +34 -0
- package/dist/controls/leaflet/LabelControl/LabelControl.js.map +1 -0
- package/dist/controls/leaflet/Map/Map.d.ts +0 -0
- package/dist/controls/leaflet/Map/Map.js +1 -0
- package/dist/controls/leaflet/Map/Map.js.map +1 -0
- package/dist/controls/leaflet/OpenStreetMapTileLayer/OpenStreetMapTileLayer.d.ts +8 -0
- package/dist/controls/leaflet/OpenStreetMapTileLayer/OpenStreetMapTileLayer.js +14 -0
- package/dist/controls/leaflet/OpenStreetMapTileLayer/OpenStreetMapTileLayer.js.map +1 -0
- package/dist/controls/leaflet/PointerEvent/PointerEvent.d.ts +2 -0
- package/dist/controls/leaflet/PointerEvent/PointerEvent.js +8 -0
- package/dist/controls/leaflet/PointerEvent/PointerEvent.js.map +1 -0
- package/dist/controls/leaflet/index.d.ts +3 -0
- package/dist/controls/leaflet/index.js +4 -0
- package/dist/controls/leaflet/index.js.map +1 -0
- package/dist/controls/svg/Circle/Circle.d.ts +0 -0
- package/dist/controls/svg/Circle/Circle.js +1 -0
- package/dist/controls/svg/Circle/Circle.js.map +1 -0
- package/dist/controls/svg/Ellipse/Ellipse.d.ts +0 -0
- package/dist/controls/svg/Ellipse/Ellipse.js +1 -0
- package/dist/controls/svg/Ellipse/Ellipse.js.map +1 -0
- package/dist/controls/svg/ForeignObject/ForeignObject.d.ts +0 -0
- package/dist/controls/svg/ForeignObject/ForeignObject.js +1 -0
- package/dist/controls/svg/ForeignObject/ForeignObject.js.map +1 -0
- package/dist/controls/svg/Group/Group.d.ts +0 -0
- package/dist/controls/svg/Group/Group.js +1 -0
- package/dist/controls/svg/Group/Group.js.map +1 -0
- package/dist/controls/svg/Line/Line.d.ts +0 -0
- package/dist/controls/svg/Line/Line.js +1 -0
- package/dist/controls/svg/Line/Line.js.map +1 -0
- package/dist/controls/svg/Pattern/Pattern.d.ts +0 -0
- package/dist/controls/svg/Pattern/Pattern.js +1 -0
- package/dist/controls/svg/Pattern/Pattern.js.map +1 -0
- package/dist/controls/svg/Polygon/Polygon.d.ts +0 -0
- package/dist/controls/svg/Polygon/Polygon.js +1 -0
- package/dist/controls/svg/Polygon/Polygon.js.map +1 -0
- package/dist/controls/svg/Polyline/Polyline.d.ts +0 -0
- package/dist/controls/svg/Polyline/Polyline.js +1 -0
- package/dist/controls/svg/Polyline/Polyline.js.map +1 -0
- package/dist/controls/svg/Rectangle/Rectangle.d.ts +0 -0
- package/dist/controls/svg/Rectangle/Rectangle.js +1 -0
- package/dist/controls/svg/Rectangle/Rectangle.js.map +1 -0
- package/dist/controls/svg/Svg/Svg.d.ts +0 -0
- package/dist/controls/svg/Svg/Svg.js +1 -0
- package/dist/controls/svg/Svg/Svg.js.map +1 -0
- package/dist/controls/svg/Text/Text.d.ts +0 -0
- package/dist/controls/svg/Text/Text.js +1 -0
- package/dist/controls/svg/Text/Text.js.map +1 -0
- package/dist/controls/svg/Title/Title.d.ts +0 -0
- package/dist/controls/svg/Title/Title.js +1 -0
- package/dist/controls/svg/Title/Title.js.map +1 -0
- package/dist/controls/svg/index.d.ts +0 -0
- package/dist/controls/svg/index.js +1 -0
- package/dist/controls/svg/index.js.map +1 -0
- package/dist/controls/svg/svg.d.ts +0 -0
- package/dist/controls/svg/svg.js +1 -0
- package/dist/controls/svg/svg.js.map +1 -0
- package/dist/framework/View.d.ts +62 -0
- package/dist/framework/View.js +148 -0
- package/dist/framework/View.js.map +1 -0
- package/dist/framework/ViewModel.d.ts +42 -0
- package/dist/framework/ViewModel.js +287 -0
- package/dist/framework/ViewModel.js.map +1 -0
- package/dist/framework/attributes.d.ts +90 -0
- package/dist/framework/attributes.js +2 -0
- package/dist/framework/attributes.js.map +1 -0
- package/dist/framework/event.d.ts +80 -0
- package/dist/framework/event.js +26 -0
- package/dist/framework/event.js.map +1 -0
- package/dist/framework/observable.d.ts +9 -0
- package/dist/framework/observable.js +24 -0
- package/dist/framework/observable.js.map +1 -0
- package/dist/framework/style.d.ts +658 -0
- package/dist/framework/style.js +154 -0
- package/dist/framework/style.js.map +1 -0
- package/dist/framework/types.d.ts +87 -0
- package/dist/framework/types.js +2 -0
- package/dist/framework/types.js.map +1 -0
- package/dist/framework/userAgent.d.ts +31 -0
- package/dist/framework/userAgent.js +47 -0
- package/dist/framework/userAgent.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/utilities/blob/blob.d.ts +1 -0
- package/dist/utilities/blob/blob.js +18 -0
- package/dist/utilities/blob/blob.js.map +1 -0
- package/dist/utilities/cookie/cookie.d.ts +3 -0
- package/dist/utilities/cookie/cookie.js +27 -0
- package/dist/utilities/cookie/cookie.js.map +1 -0
- package/dist/utilities/dataReaderTable/dataReaderTable.d.ts +9 -0
- package/dist/utilities/dataReaderTable/dataReaderTable.js +24 -0
- package/dist/utilities/dataReaderTable/dataReaderTable.js.map +1 -0
- package/dist/utilities/fetch/fetch.d.ts +8 -0
- package/dist/utilities/fetch/fetch.js +138 -0
- package/dist/utilities/fetch/fetch.js.map +1 -0
- package/dist/utilities/float/float.d.ts +1 -0
- package/dist/utilities/float/float.js +4 -0
- package/dist/utilities/float/float.js.map +1 -0
- package/dist/utilities/formData/formData.d.ts +1 -0
- package/dist/utilities/formData/formData.js +12 -0
- package/dist/utilities/formData/formData.js.map +1 -0
- package/dist/utilities/html/html.d.ts +1 -0
- package/dist/utilities/html/html.js +8 -0
- package/dist/utilities/html/html.js.map +1 -0
- package/dist/utilities/htmlElement/htmlElement.d.ts +1 -0
- package/dist/utilities/htmlElement/htmlElement.js +17 -0
- package/dist/utilities/htmlElement/htmlElement.js.map +1 -0
- package/dist/utilities/image/image.d.ts +1 -0
- package/dist/utilities/image/image.js +2 -0
- package/dist/utilities/image/image.js.map +1 -0
- package/dist/utilities/index.d.ts +36 -0
- package/dist/utilities/index.js +37 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/integer/integer.d.ts +3 -0
- package/dist/utilities/integer/integer.js +28 -0
- package/dist/utilities/integer/integer.js.map +1 -0
- package/dist/utilities/key/key.d.ts +2 -0
- package/dist/utilities/key/key.js +7 -0
- package/dist/utilities/key/key.js.map +1 -0
- package/dist/utilities/navigator/navigator.d.ts +1 -0
- package/dist/utilities/navigator/navigator.js +9 -0
- package/dist/utilities/navigator/navigator.js.map +1 -0
- package/dist/utilities/notification/notification.d.ts +5 -0
- package/dist/utilities/notification/notification.js +67 -0
- package/dist/utilities/notification/notification.js.map +1 -0
- package/dist/utilities/querystring/querystring.d.ts +6 -0
- package/dist/utilities/querystring/querystring.js +54 -0
- package/dist/utilities/querystring/querystring.js.map +1 -0
- package/dist/utilities/router/router.d.ts +19 -0
- package/dist/utilities/router/router.js +81 -0
- package/dist/utilities/router/router.js.map +1 -0
- package/dist/utilities/stylesheet/stylesheet.d.ts +2 -0
- package/dist/utilities/stylesheet/stylesheet.js +48 -0
- package/dist/utilities/stylesheet/stylesheet.js.map +1 -0
- package/dist/utilities/uniqueId/uniqueId.d.ts +1 -0
- package/dist/utilities/uniqueId/uniqueId.js +5 -0
- package/dist/utilities/uniqueId/uniqueId.js.map +1 -0
- package/dist/utilities/webSocket/webSocket.d.ts +1 -0
- package/dist/utilities/webSocket/webSocket.js +55 -0
- package/dist/utilities/webSocket/webSocket.js.map +1 -0
- package/package.json +62 -0
- package/src/controls/codeMirror/HtmlEditor/HtmlEditor.ts +153 -0
- package/src/controls/codeMirror/JsonEditor/JsonEditor.ts +136 -0
- package/src/controls/codeMirror/index.ts +2 -0
- package/src/controls/custom/FileSelector/FileSelector.ts +74 -0
- package/src/controls/custom/LabeledControl/LabeledControl.ts +58 -0
- package/src/controls/custom/ListItem/ListItem.ts +99 -0
- package/src/controls/custom/index.ts +3 -0
- package/src/controls/html/Button/Button.ts +70 -0
- package/src/controls/html/Div/Div.ts +41 -0
- package/src/controls/html/Image/Image.ts +46 -0
- package/src/controls/html/Input/Input.ts +228 -0
- package/src/controls/html/Select/Select.ts +146 -0
- package/src/controls/html/Span/Span.ts +38 -0
- package/src/controls/html/index.ts +6 -0
- package/src/controls/index.ts +15 -0
- package/src/controls/jsonViewAwesome/index.ts +1 -0
- package/src/controls/jsonViewAwesome/jsonFormatter/JsonFormatter.ts +91 -0
- package/src/controls/kendo/Chart/Chart.ts +97 -0
- package/src/controls/kendo/Culture/Culture.ts +32 -0
- package/src/controls/kendo/DataSource/DataSource.ts +4 -0
- package/src/controls/kendo/Dialog/Dialog.ts +64 -0
- package/src/controls/kendo/Editor/Editor.ts +142 -0
- package/src/controls/kendo/Grid/Grid.ts +291 -0
- package/src/controls/kendo/Menu/Menu.ts +125 -0
- package/src/controls/kendo/ObservableObject/ObservableObject.ts +45 -0
- package/src/controls/kendo/Tree/Tree.ts +147 -0
- package/src/controls/kendo/index.ts +9 -0
- package/src/controls/leaflet/LabelControl/LabelControl.ts +42 -0
- package/src/controls/leaflet/Map/Map.ts +180 -0
- package/src/controls/leaflet/OpenStreetMapTileLayer/OpenStreetMapTileLayer.ts +19 -0
- package/src/controls/leaflet/PointerEvent/PointerEvent.ts +9 -0
- package/src/controls/leaflet/index.ts +4 -0
- package/src/controls/svg/Circle/Circle.ts +34 -0
- package/src/controls/svg/Ellipse/Ellipse.ts +36 -0
- package/src/controls/svg/ForeignObject/ForeignObject.ts +38 -0
- package/src/controls/svg/Group/Group.ts +38 -0
- package/src/controls/svg/Line/Line.ts +36 -0
- package/src/controls/svg/Pattern/Pattern.ts +49 -0
- package/src/controls/svg/Polygon/Polygon.ts +31 -0
- package/src/controls/svg/Polyline/Polyline.ts +31 -0
- package/src/controls/svg/Rectangle/Rectangle.ts +36 -0
- package/src/controls/svg/Svg/Svg.ts +43 -0
- package/src/controls/svg/Text/Text.ts +38 -0
- package/src/controls/svg/Title/Title.ts +28 -0
- package/src/controls/svg/index.ts +13 -0
- package/src/controls/svg/svg.ts +20 -0
- package/src/framework/View.ts +226 -0
- package/src/framework/ViewModel.ts +478 -0
- package/src/framework/attributes.ts +92 -0
- package/src/framework/event.ts +98 -0
- package/src/framework/observable.ts +40 -0
- package/src/framework/style.ts +3271 -0
- package/src/framework/types.ts +277 -0
- package/src/framework/userAgent.ts +51 -0
- package/src/index.ts +14 -0
- package/src/utilities/blob/blob.ts +19 -0
- package/src/utilities/cookie/cookie.ts +28 -0
- package/src/utilities/dataReaderTable/dataReaderTable.ts +34 -0
- package/src/utilities/fetch/fetch.ts +179 -0
- package/src/utilities/float/float.ts +3 -0
- package/src/utilities/formData/formData.ts +12 -0
- package/src/utilities/html/html.ts +8 -0
- package/src/utilities/htmlElement/htmlElement.ts +15 -0
- package/src/utilities/image/image.ts +1 -0
- package/src/utilities/index.ts +37 -0
- package/src/utilities/integer/integer.ts +31 -0
- package/src/utilities/key/key.ts +7 -0
- package/src/utilities/navigator/navigator.ts +7 -0
- package/src/utilities/notification/notification.ts +88 -0
- package/src/utilities/querystring/querystring.ts +61 -0
- package/src/utilities/router/router.ts +124 -0
- package/src/utilities/stylesheet/stylesheet.ts +58 -0
- package/src/utilities/uniqueId/uniqueId.ts +5 -0
- package/src/utilities/webSocket/webSocket.ts +72 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { userAgent } from "./userAgent";
|
|
2
|
+
import { EventListeners, UiElementEventMap, IEventListenerOptions, IGenericEventListener, mouseEvents, touchEvents, isGlobalEvent } from "./event";
|
|
3
|
+
import { Attributes, AttributesSubscribable } from "./attributes";
|
|
4
|
+
import { extend } from "jquery";
|
|
5
|
+
import { Style, StyleSubscribable } from "./style";
|
|
6
|
+
import { isSubscribable, unwrap, Subscribable } from "./observable";
|
|
7
|
+
import { autorun, IReactionDisposer } from "mobx";
|
|
8
|
+
|
|
9
|
+
export interface WebSocketMessageHandler {
|
|
10
|
+
handleWebSocketMessage: (message: any) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function handleWebSocketMessage(object: object, message: any) {
|
|
14
|
+
bubbleDownObjectTreeAndExecuteHandler(
|
|
15
|
+
object,
|
|
16
|
+
(object) => {
|
|
17
|
+
const webSocketMessageHandler = object as WebSocketMessageHandler;
|
|
18
|
+
if (webSocketMessageHandler.handleWebSocketMessage && typeof webSocketMessageHandler.handleWebSocketMessage === "function") {
|
|
19
|
+
//Call the handleWebSocketMessage method
|
|
20
|
+
webSocketMessageHandler.handleWebSocketMessage(message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//This function bubbles down an object tree
|
|
27
|
+
//The given handler is executed on the given object and all its child properties of type object
|
|
28
|
+
export function bubbleDownObjectTreeAndExecuteHandler(object: object, handler: (object) => void) {
|
|
29
|
+
//Find out if the object is an array
|
|
30
|
+
if (object.constructor === Array) {
|
|
31
|
+
for (const arrayEntry of object as Array<any>) {
|
|
32
|
+
if (typeof arrayEntry === "object") {
|
|
33
|
+
bubbleDownObjectTreeAndExecuteHandler(arrayEntry, handler);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
//Find out if the object implements the WebSocketMessageHandler interface
|
|
38
|
+
if (isSubscribable(object)) {
|
|
39
|
+
var unwrapped = unwrap(object);
|
|
40
|
+
if (typeof unwrapped === "object") {
|
|
41
|
+
bubbleDownObjectTreeAndExecuteHandler(unwrapped, handler);
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
handler(object);
|
|
45
|
+
//Find out if the object has properties of type object
|
|
46
|
+
for (const key in Object.keys(object)) {
|
|
47
|
+
const property = object[key];
|
|
48
|
+
if (property && typeof property === "object") {
|
|
49
|
+
//Call handleWebSocketMessage method on the property to bubble down the object tree.
|
|
50
|
+
bubbleDownObjectTreeAndExecuteHandler(property, handler);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#region Null check
|
|
58
|
+
export function isNullOrUndefined(value): boolean {
|
|
59
|
+
return value === null || typeof value === "undefined";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface Properties {
|
|
63
|
+
attributes?: Attributes | AttributesSubscribable;
|
|
64
|
+
classNames?: Array<string> | Subscribable<Array<string>>;
|
|
65
|
+
style?: Style | StyleSubscribable;
|
|
66
|
+
visible?: boolean | Subscribable<boolean>;
|
|
67
|
+
disabled?: boolean | Subscribable<boolean>;
|
|
68
|
+
innerHtml?: any | Subscribable<any>;
|
|
69
|
+
textContent?: string | Subscribable<string>;
|
|
70
|
+
addViewModelToDataObject?: boolean;
|
|
71
|
+
userSelectable?: boolean;
|
|
72
|
+
eventListeners?: EventListeners;
|
|
73
|
+
viewType?: string;
|
|
74
|
+
focused?: boolean | Subscribable<boolean>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export abstract class ViewModel implements Properties {
|
|
78
|
+
//protected constructor(properties?: Properties) {
|
|
79
|
+
// this.setProperties(this, properties);
|
|
80
|
+
//}
|
|
81
|
+
protected setProperties<TProperties>(object: object, properties?: TProperties) {
|
|
82
|
+
if (properties) {
|
|
83
|
+
Object.keys(properties).forEach((property) => {
|
|
84
|
+
object[property] = properties[property];
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
attributes?: Attributes | AttributesSubscribable;
|
|
90
|
+
classNames?: Array<string> | Subscribable<Array<string>>;
|
|
91
|
+
style?: Style | StyleSubscribable;
|
|
92
|
+
visible?: boolean | Subscribable<boolean>;
|
|
93
|
+
disabled?: boolean | Subscribable<boolean>;
|
|
94
|
+
innerHtml?: any | Subscribable<any>;
|
|
95
|
+
textContent?: string | Subscribable<string>;
|
|
96
|
+
addViewModelToDataObject?: boolean;
|
|
97
|
+
userSelectable?: boolean;
|
|
98
|
+
eventListeners?: EventListeners;
|
|
99
|
+
viewType?: string;
|
|
100
|
+
focused?: boolean | Subscribable<boolean>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#region ViewModel helper functions
|
|
104
|
+
|
|
105
|
+
//Function to merge two viewModels. The source is applied to the target. Corresponding properties are overwritten in the target.
|
|
106
|
+
export function extendProperties<TResult = Properties, TTarget = Properties, TSource = Properties>(target: TTarget, source: TSource): TResult {
|
|
107
|
+
return extend(true, target, source) as any as TResult;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//Functions to bind the viewModel to a html element
|
|
111
|
+
export function applyBindings(properties: Properties, element: HTMLElement, subscriptions: Array<IReactionDisposer>) {
|
|
112
|
+
element.setAttribute("viewtype", properties.viewType || "View");
|
|
113
|
+
|
|
114
|
+
if (properties.classNames) {
|
|
115
|
+
|
|
116
|
+
const subscription = autorun(() => {
|
|
117
|
+
applyClassesToElement(unwrap(properties.classNames), true, element);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (subscriptions) {
|
|
121
|
+
subscriptions.push(subscription);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//applyClassesToElement(unwrap<string[]>(properties.classNames), true, element);
|
|
125
|
+
|
|
126
|
+
//if (isSubscribable(properties.classNames)) {
|
|
127
|
+
// const subscription = properties.classNames.subscribe((classNames: Array<string>) => {
|
|
128
|
+
// applyClassesToElement(classNames, true, element);
|
|
129
|
+
// });
|
|
130
|
+
|
|
131
|
+
// if (subscriptions) {
|
|
132
|
+
// subscriptions.push(subscription);
|
|
133
|
+
// }
|
|
134
|
+
//}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (properties.attributes) {
|
|
138
|
+
Object.keys(properties.attributes).forEach((key) => {
|
|
139
|
+
var value = properties.attributes[key];
|
|
140
|
+
|
|
141
|
+
const subscription = autorun(() => {
|
|
142
|
+
applyAttributeToElement(key as keyof Attributes, unwrap(value), element);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (subscriptions) {
|
|
146
|
+
subscriptions.push(subscription);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//applyAttributeToElement(key as keyof Attributes, unwrap(value), element);
|
|
150
|
+
//if (isSubscribable(value)) {
|
|
151
|
+
// const subscription = value.subscribe((newValue: string) => {
|
|
152
|
+
// applyAttributeToElement(key as keyof Attributes, newValue, element);
|
|
153
|
+
// });
|
|
154
|
+
|
|
155
|
+
// if (subscriptions) {
|
|
156
|
+
// subscriptions.push(subscription);
|
|
157
|
+
// }
|
|
158
|
+
//}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (properties.style) {
|
|
163
|
+
Object.keys(properties.style).forEach((key) => {
|
|
164
|
+
const style = properties.style[key];
|
|
165
|
+
|
|
166
|
+
const subscription = autorun(() => {
|
|
167
|
+
element.style[key] = unwrap(style);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (subscriptions) {
|
|
171
|
+
subscriptions.push(subscription);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//element.style[key] = unwrap(style);
|
|
175
|
+
//if (isSubscribable(style)) {
|
|
176
|
+
// const subscription = style.subscribe((newStyle) => {
|
|
177
|
+
// element.style[key] = newStyle;
|
|
178
|
+
// });
|
|
179
|
+
|
|
180
|
+
// if (subscriptions) {
|
|
181
|
+
// subscriptions.push(subscription);
|
|
182
|
+
// }
|
|
183
|
+
//}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!isNullOrUndefined(properties.innerHtml)) {
|
|
188
|
+
|
|
189
|
+
const subscription = autorun(() => {
|
|
190
|
+
element.innerHTML = unwrap(properties.innerHtml);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
if (subscriptions) {
|
|
194
|
+
subscriptions.push(subscription);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
//element.innerHTML = unwrap(properties.innerHtml);
|
|
198
|
+
//if (isSubscribable(properties.innerHtml)) {
|
|
199
|
+
// const subscription = properties.innerHtml.subscribe((innerHtml: string) => {
|
|
200
|
+
// element.innerHTML = innerHtml;
|
|
201
|
+
// });
|
|
202
|
+
|
|
203
|
+
// if (subscriptions) {
|
|
204
|
+
// subscriptions.push(subscription);
|
|
205
|
+
// }
|
|
206
|
+
//}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!isNullOrUndefined(properties.textContent)) {
|
|
210
|
+
const subscription = autorun(() => {
|
|
211
|
+
var textContent = unwrap<string>(properties.textContent);
|
|
212
|
+
|
|
213
|
+
if (element.hasChildNodes() && element.childNodes.length === 1 && element.childNodes[0].nodeType === 3) {
|
|
214
|
+
element.firstChild.nodeValue = textContent;
|
|
215
|
+
} else {
|
|
216
|
+
element.textContent = unwrap(properties.textContent);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
if (subscriptions) {
|
|
221
|
+
subscriptions.push(subscription);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
//element.textContent = unwrap(properties.textContent);
|
|
225
|
+
//if (isSubscribable(properties.textContent)) {
|
|
226
|
+
// const subscription = properties.textContent.subscribe((textContent: string) => {
|
|
227
|
+
// if (element.hasChildNodes() && element.childNodes.length === 1 && element.childNodes[0].nodeType === 3) {
|
|
228
|
+
// //The first child is a text node so the most efficient way is to use the nodeValue property
|
|
229
|
+
// element.firstChild.nodeValue = textContent;
|
|
230
|
+
// } else {
|
|
231
|
+
// element.textContent = textContent;
|
|
232
|
+
// }
|
|
233
|
+
// });
|
|
234
|
+
|
|
235
|
+
// if (subscriptions) {
|
|
236
|
+
// subscriptions.push(subscription);
|
|
237
|
+
// }
|
|
238
|
+
//}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//Find out if the element is none selectable
|
|
242
|
+
if (properties.userSelectable === false) {
|
|
243
|
+
applyEventListenerToElement("selectstart", () => { return false; }, { passive: true }, element);
|
|
244
|
+
element.style.userSelect = "none";
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (properties.addViewModelToDataObject) {
|
|
248
|
+
if (!element["data"]) {
|
|
249
|
+
element["data"] = {};
|
|
250
|
+
}
|
|
251
|
+
element["data"].viewModel = properties;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (properties.eventListeners) {
|
|
255
|
+
applyEventListenersToElement(properties, element);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
const subscriptionVisible = autorun(() => {
|
|
260
|
+
applyVisibilityToElement(unwrap(properties.visible), element);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
if (subscriptions) {
|
|
264
|
+
subscriptions.push(subscriptionVisible);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
//applyVisibilityToElement(unwrap(properties.visible), element);
|
|
268
|
+
//if (isSubscribable(properties.visible)) {
|
|
269
|
+
// const subscription = properties.visible.subscribe((visible) => {
|
|
270
|
+
// applyVisibilityToElement(visible, element);
|
|
271
|
+
// });
|
|
272
|
+
|
|
273
|
+
// if (subscriptions) {
|
|
274
|
+
// subscriptions.push(subscription);
|
|
275
|
+
// }
|
|
276
|
+
//}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
const subscriptionDisabled = autorun(() => {
|
|
280
|
+
applyDisabledToElement(unwrap(properties.disabled), element);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
if (subscriptions) {
|
|
284
|
+
subscriptions.push(subscriptionDisabled);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
//applyDisabledToElement(unwrap(properties.disabled), element);
|
|
288
|
+
//if (isSubscribable(properties.disabled)) {
|
|
289
|
+
// const subscription = properties.disabled.subscribe((disabled) => {
|
|
290
|
+
// applyDisabledToElement(disabled, element);
|
|
291
|
+
// });
|
|
292
|
+
|
|
293
|
+
// if (subscriptions) {
|
|
294
|
+
// subscriptions.push(subscription);
|
|
295
|
+
// }
|
|
296
|
+
//}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
const subscriptionFocus = autorun(() => {
|
|
300
|
+
applyFocusToElement(unwrap(properties.focused), element);
|
|
301
|
+
});
|
|
302
|
+
if (subscriptions) {
|
|
303
|
+
subscriptions.push(subscriptionFocus);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
//applyFocusToElement(unwrap(properties.focused), element);
|
|
307
|
+
//if (isSubscribable(properties.focused)) {
|
|
308
|
+
// const subscription = properties.focused.subscribe((focused) => {
|
|
309
|
+
// applyFocusToElement(focused, element);
|
|
310
|
+
// });
|
|
311
|
+
|
|
312
|
+
// if (subscriptions) {
|
|
313
|
+
// subscriptions.push(subscription);
|
|
314
|
+
// }
|
|
315
|
+
//}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function applyVisibilityToElement(visible: boolean, element: HTMLElement) {
|
|
319
|
+
if (visible === false) {
|
|
320
|
+
element.classList.add("hidden");
|
|
321
|
+
} else {
|
|
322
|
+
element.classList.remove("hidden");
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function applyDisabledToElement(disabled: boolean, element: HTMLElement) {
|
|
327
|
+
if (disabled) {
|
|
328
|
+
element.setAttribute("disabled", "disabled");
|
|
329
|
+
} else {
|
|
330
|
+
element.removeAttribute("disabled");
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function applyEventListenersToElement(viewModel: Properties, element: HTMLElement) {
|
|
335
|
+
//Add the eventListeners to the element
|
|
336
|
+
const clickEventListeners = new Array<IGenericEventListener>();
|
|
337
|
+
const doubleClickEventListeners = new Array<IGenericEventListener>();
|
|
338
|
+
|
|
339
|
+
Object.entries(viewModel.eventListeners).forEach((entry) => {
|
|
340
|
+
var eventName = entry[0] as keyof UiElementEventMap;
|
|
341
|
+
var eventListener = entry[1] as IGenericEventListener;
|
|
342
|
+
|
|
343
|
+
if (eventName === "click") {
|
|
344
|
+
clickEventListeners.push(eventListener);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (eventName === "dblclick") {
|
|
348
|
+
doubleClickEventListeners.push(eventListener);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (eventName === "dragstart") {
|
|
353
|
+
element.setAttribute("draggable", "true");
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (isGlobalEvent(eventName)) {
|
|
357
|
+
applyEventListenerToElement(
|
|
358
|
+
eventName,
|
|
359
|
+
(event: Event) => {
|
|
360
|
+
if (eventListener.options) {
|
|
361
|
+
const options = eventListener.options as IEventListenerOptions;
|
|
362
|
+
const keyEvent = event as KeyboardEvent;
|
|
363
|
+
if (options.altKey && !keyEvent.altKey) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (options.shiftKey && !keyEvent.shiftKey) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (options.ctrlKey && !keyEvent.ctrlKey) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (options.eventKey && options.eventKey !== keyEvent.key) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
eventListener.listener.call(viewModel, event);
|
|
378
|
+
},
|
|
379
|
+
eventListener.options,
|
|
380
|
+
element
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
else if (mouseEvents[eventName] && userAgent.device.supportsMouseEvents) {
|
|
384
|
+
applyEventListenerToElement(eventName, eventListener.listener, eventListener.options, element);
|
|
385
|
+
}
|
|
386
|
+
else if (touchEvents[eventName] && userAgent.device.supportsTouchEvents) {
|
|
387
|
+
applyEventListenerToElement(eventName, eventListener.listener, eventListener.options, element);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
clickEventListeners.forEach((clickEventListener) => {
|
|
392
|
+
if (userAgent.device.supportsTouchEvents) {
|
|
393
|
+
// ReSharper disable once Html.EventNotResolved
|
|
394
|
+
applyEventListenerToElement("tap", clickEventListener.listener, clickEventListener.options, element);
|
|
395
|
+
}
|
|
396
|
+
if (userAgent.device.supportsMouseEvents) {
|
|
397
|
+
applyEventListenerToElement("click", clickEventListener.listener, clickEventListener.options, element);
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
doubleClickEventListeners.forEach((doubleClickEventListener) => {
|
|
402
|
+
if (userAgent.device.supportsTouchEvents) {
|
|
403
|
+
// ReSharper disable once Html.EventNotResolved
|
|
404
|
+
applyEventListenerToElement("dbltap", doubleClickEventListener.listener, doubleClickEventListener.options, element);
|
|
405
|
+
}
|
|
406
|
+
if (userAgent.device.supportsMouseEvents) {
|
|
407
|
+
applyEventListenerToElement("dblclick", doubleClickEventListener.listener, doubleClickEventListener.options, element);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function applyEventListenerToElement(type: keyof UiElementEventMap, listener: (event: any) => any, options: IEventListenerOptions, element: HTMLElement) {
|
|
413
|
+
if (!type) {
|
|
414
|
+
throw new Error("type is mandatory");
|
|
415
|
+
}
|
|
416
|
+
if (!listener) {
|
|
417
|
+
throw new Error("listener is mandatory");
|
|
418
|
+
}
|
|
419
|
+
if (!options) {
|
|
420
|
+
options = {};
|
|
421
|
+
}
|
|
422
|
+
if (!options.passive) {
|
|
423
|
+
options.passive = false;
|
|
424
|
+
}
|
|
425
|
+
if (!options.once) {
|
|
426
|
+
options.once = false;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (element.addEventListener) {
|
|
430
|
+
element.addEventListener(
|
|
431
|
+
type,
|
|
432
|
+
(event) => {
|
|
433
|
+
listener.call(event);
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
passive: options.passive,
|
|
437
|
+
once: options.once
|
|
438
|
+
});
|
|
439
|
+
} else if (element["attachEvent"]) {
|
|
440
|
+
element["attachEvent"](
|
|
441
|
+
type,
|
|
442
|
+
(event) => {
|
|
443
|
+
listener(event);
|
|
444
|
+
}
|
|
445
|
+
);
|
|
446
|
+
} else {
|
|
447
|
+
throw "Your browser does not support 'addEventListener'";
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function applyClassesToElement(classNames: string[], replace: boolean, element: HTMLElement) {
|
|
452
|
+
//If all existing classes need to be replace we reset the classes object to an empty object
|
|
453
|
+
if (replace) {
|
|
454
|
+
element.className = "";
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
//Add all the classNames to the classes object
|
|
458
|
+
if (classNames) {
|
|
459
|
+
classNames.forEach((className) => {
|
|
460
|
+
element.classList.add(className);
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function applyAttributeToElement(name: keyof Attributes, value: string, element: HTMLElement) {
|
|
466
|
+
if (isNullOrUndefined(value)) {
|
|
467
|
+
element.removeAttribute(name);
|
|
468
|
+
} else {
|
|
469
|
+
element.setAttribute(name, value);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function applyFocusToElement(focused: boolean, element: HTMLElement) {
|
|
474
|
+
if (focused) {
|
|
475
|
+
element.focus();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
//#endregion
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Subscribable } from "./observable";
|
|
2
|
+
import { PreserveAspectRatio } from "./types";
|
|
3
|
+
|
|
4
|
+
export interface Attributes {
|
|
5
|
+
alt?: string,
|
|
6
|
+
disabled?: string,
|
|
7
|
+
href?: string,
|
|
8
|
+
target?: string,
|
|
9
|
+
id?: string,
|
|
10
|
+
src?: string,
|
|
11
|
+
title?: string,
|
|
12
|
+
class?: string,
|
|
13
|
+
tabindex?: number,
|
|
14
|
+
draggable?: string,
|
|
15
|
+
placeholder?: string,
|
|
16
|
+
for?: string,
|
|
17
|
+
type?: string,
|
|
18
|
+
value?: string,
|
|
19
|
+
view?: string,
|
|
20
|
+
checked?: string;
|
|
21
|
+
enctype?: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
multiple?: boolean;
|
|
24
|
+
["aria-label"]?: string;
|
|
25
|
+
cx?: number | string;
|
|
26
|
+
cy?: number | string;
|
|
27
|
+
r?: number | string;
|
|
28
|
+
rx?: number | string;
|
|
29
|
+
ry?: number | string;
|
|
30
|
+
x?: number | string;
|
|
31
|
+
x1?: number | string;
|
|
32
|
+
x2?: number | string;
|
|
33
|
+
y?: number | string;
|
|
34
|
+
y1?: number | string;
|
|
35
|
+
y2?: number | string;
|
|
36
|
+
width?: number | string;
|
|
37
|
+
height?: number | string;
|
|
38
|
+
patternUnits?: string;
|
|
39
|
+
patternTransform?: string;
|
|
40
|
+
points?: string;
|
|
41
|
+
viewBox?: string;
|
|
42
|
+
dx?: number | string;
|
|
43
|
+
dy?: number | string;
|
|
44
|
+
rotate?: string;
|
|
45
|
+
preserveAspectRatio?: PreserveAspectRatio;
|
|
46
|
+
xmlns?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface AttributesSubscribable {
|
|
50
|
+
alt?: string | Subscribable<string>,
|
|
51
|
+
disabled?: string | Subscribable<string>,
|
|
52
|
+
href?: string | Subscribable<string>,
|
|
53
|
+
target?: string | Subscribable<string>,
|
|
54
|
+
id?: string | Subscribable<string>,
|
|
55
|
+
src?: string | Subscribable<string>,
|
|
56
|
+
title?: string | Subscribable<string>,
|
|
57
|
+
class?: string | Subscribable<string>,
|
|
58
|
+
tabindex?: number | Subscribable<number>,
|
|
59
|
+
draggable?: string | Subscribable<string>,
|
|
60
|
+
placeholder?: string | Subscribable<string>,
|
|
61
|
+
for?: string | Subscribable<string>,
|
|
62
|
+
type?: string | Subscribable<string>,
|
|
63
|
+
value?: string | Subscribable<string>,
|
|
64
|
+
view?: string | Subscribable<string>,
|
|
65
|
+
checked?: string | Subscribable<string>;
|
|
66
|
+
enctype?: string | Subscribable<string>;
|
|
67
|
+
name?: string | Subscribable<string>;
|
|
68
|
+
multiple?: boolean | Subscribable<boolean>;
|
|
69
|
+
["aria-label"]?: string | Subscribable<string>;
|
|
70
|
+
cx?: number | string | Subscribable<number | string>;
|
|
71
|
+
cy?: number | string | Subscribable<number | string>;
|
|
72
|
+
r?: number | string | Subscribable<number | string>;
|
|
73
|
+
rx?: number | string | Subscribable<number | string>;
|
|
74
|
+
ry?: number | string | Subscribable<number | string>;
|
|
75
|
+
x?: number | string | Subscribable<number | string>;
|
|
76
|
+
x1?: number | string | Subscribable<number | string>;
|
|
77
|
+
x2?: number | string | Subscribable<number | string>;
|
|
78
|
+
y?: number | string | Subscribable<number | string>;
|
|
79
|
+
y1?: number | string | Subscribable<number | string>;
|
|
80
|
+
y2?: number | string | Subscribable<number | string>;
|
|
81
|
+
width?: number | string | Subscribable<number | string>;
|
|
82
|
+
height?: number | string | Subscribable<number | string>;
|
|
83
|
+
patternUnits?: string | Subscribable<string>;
|
|
84
|
+
patternTransform?: string | Subscribable<string>;
|
|
85
|
+
points?: string | Subscribable<string>;
|
|
86
|
+
viewBox?: string | Subscribable<string>;
|
|
87
|
+
dx?: number | string | Subscribable<number | string>;
|
|
88
|
+
dy?: number | string | Subscribable<number | string>;
|
|
89
|
+
rotate?: string | Subscribable<string>;
|
|
90
|
+
preserveAspectRatio?: PreserveAspectRatio | Subscribable<PreserveAspectRatio>;
|
|
91
|
+
xmlns?: string| Subscribable<string>;
|
|
92
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as leaflet from "leaflet";
|
|
2
|
+
|
|
3
|
+
export const mouseEvents = {
|
|
4
|
+
click: true,
|
|
5
|
+
contextmenu: true,
|
|
6
|
+
mousedown: true,
|
|
7
|
+
mouseenter: true,
|
|
8
|
+
mouseleave: true,
|
|
9
|
+
mousemove: true,
|
|
10
|
+
mouseout: true,
|
|
11
|
+
mouseover: true,
|
|
12
|
+
mouseup: true
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const touchEvents = {
|
|
16
|
+
touchcancel: true,
|
|
17
|
+
touchend: true,
|
|
18
|
+
touchmove: true,
|
|
19
|
+
touchstart: true,
|
|
20
|
+
longtap: true,
|
|
21
|
+
swipeleft: true,
|
|
22
|
+
swiperight: true,
|
|
23
|
+
swipeup: true,
|
|
24
|
+
swipedown: true
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export function isGlobalEvent(event: keyof UiElementEventMap): boolean {
|
|
28
|
+
return !(mouseEvents[event] || touchEvents[event]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface UiElementEventMap extends HTMLElementEventMap {
|
|
32
|
+
"tap": Event;
|
|
33
|
+
"dbltap": Event;
|
|
34
|
+
"longtap": Event;
|
|
35
|
+
"swipeleft": Event;
|
|
36
|
+
"swiperight": Event;
|
|
37
|
+
"swipeup": Event;
|
|
38
|
+
"swipedown": Event;
|
|
39
|
+
"textInput": Event;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IMouseEventListener extends IEventListener {
|
|
43
|
+
listener: (event: MouseEvent) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface IFocusEventListener extends IEventListener {
|
|
47
|
+
listener: (event: FocusEvent) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface IContextMenuEventListener extends IEventListener {
|
|
51
|
+
listener: (event: PointerEvent) => void
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ILeafletEventListener extends IEventListener {
|
|
55
|
+
listener: (event: leaflet.LeafletEvent) => void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface IGenericEventListener extends IEventListener {
|
|
59
|
+
listener: (event: Event) => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface IEventListener {
|
|
63
|
+
options?: IEventListenerOptions
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface MouseEventListeners {
|
|
67
|
+
click?: IMouseEventListener;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface FocusEventListeners {
|
|
71
|
+
focusout?: IFocusEventListener;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface ContextMenuEventListeners {
|
|
75
|
+
contextMenu?: IContextMenuEventListener;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface LeafletEventListeners {
|
|
79
|
+
zoomend?: ILeafletEventListener;
|
|
80
|
+
moveend?: ILeafletEventListener;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface EventListeners extends MouseEventListeners, FocusEventListeners, ContextMenuEventListeners, LeafletEventListeners {
|
|
84
|
+
change?: IGenericEventListener;
|
|
85
|
+
load?: IGenericEventListener;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type EventKey = "Enter" | "ArrowDown" | "ArrowUp" | "ArrowLeft" | "ArrowRight";
|
|
89
|
+
|
|
90
|
+
export interface IEventListenerOptions extends AddEventListenerOptions {
|
|
91
|
+
eventKey?: EventKey;
|
|
92
|
+
altKey?: boolean;
|
|
93
|
+
shiftKey?: boolean;
|
|
94
|
+
ctrlKey?: boolean;
|
|
95
|
+
mouseLeft?: boolean;
|
|
96
|
+
mouseMiddle?: boolean;
|
|
97
|
+
mouseRight?: boolean;
|
|
98
|
+
}
|