x4js 1.4.18 → 1.4.20
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/lib/application.d.ts +1 -1
- package/lib/application.js +4 -3
- package/lib/base_component.d.ts +1 -1
- package/lib/base_component.js +3 -3
- package/lib/button.d.ts +1 -1
- package/lib/button.js +3 -3
- package/lib/calendar.d.ts +1 -1
- package/lib/calendar.js +5 -4
- package/lib/canvas.d.ts +1 -1
- package/lib/canvas.js +2 -2
- package/lib/cardview.d.ts +1 -1
- package/lib/cardview.js +2 -2
- package/lib/checkbox.d.ts +1 -1
- package/lib/checkbox.js +2 -2
- package/lib/colorpicker.d.ts +1 -1
- package/lib/colorpicker.js +5 -5
- package/lib/combobox.d.ts +1 -1
- package/lib/combobox.js +3 -3
- package/lib/component.d.ts +1 -5
- package/lib/component.js +35 -39
- package/lib/datastore.d.ts +1 -1
- package/lib/datastore.js +5 -5
- package/lib/dialog.d.ts +1 -1
- package/lib/dialog.js +4 -3
- package/lib/drag_manager.js +30 -1
- package/lib/fileupload.js +2 -1
- package/lib/form.d.ts +1 -1
- package/lib/gridview.d.ts +1 -5
- package/lib/gridview.js +8 -7
- package/lib/i18n.d.ts +35 -33
- package/lib/i18n.js +180 -93
- package/lib/icon.d.ts +1 -1
- package/lib/icon.js +10 -13
- package/lib/image.js +4 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/input.js +1 -1
- package/lib/link.d.ts +1 -1
- package/lib/link.js +2 -2
- package/lib/listview.d.ts +1 -1
- package/lib/listview.js +10 -9
- package/lib/menu.d.ts +1 -1
- package/lib/menu.js +5 -4
- package/lib/popup.d.ts +1 -1
- package/lib/popup.js +13 -12
- package/lib/property_editor.d.ts +1 -1
- package/lib/property_editor.js +2 -2
- package/lib/radiobtn.d.ts +1 -1
- package/lib/radiobtn.js +4 -3
- package/lib/rating.d.ts +1 -1
- package/lib/rating.js +2 -2
- package/lib/router.d.ts +1 -1
- package/lib/router.js +5 -4
- package/lib/spreadsheet.d.ts +1 -1
- package/lib/spreadsheet.js +9 -8
- package/lib/styles.js +6 -5
- package/lib/svgcomponent.d.ts +1 -1
- package/lib/svgcomponent.js +4 -1
- package/lib/tabbar.d.ts +1 -1
- package/lib/tabbar.js +2 -2
- package/lib/textarea.d.ts +1 -1
- package/lib/textarea.js +2 -2
- package/lib/textedit.d.ts +1 -1
- package/lib/textedit.js +5 -4
- package/lib/tools.d.ts +1 -0
- package/lib/tools.js +15 -6
- package/lib/tooltips.js +6 -5
- package/lib/treeview.d.ts +1 -1
- package/lib/treeview.js +8 -8
- package/lib/x4dom.d.ts +21 -0
- package/lib/x4dom.js +7 -0
- package/lib/x4events.d.ts +266 -0
- package/lib/x4events.js +389 -0
- package/package.json +4 -3
- package/src/application.ts +5 -4
- package/src/base_component.ts +1 -1
- package/src/button.ts +1 -1
- package/src/calendar.ts +5 -3
- package/src/canvas.ts +1 -1
- package/src/cardview.ts +1 -1
- package/src/checkbox.ts +1 -1
- package/src/colorpicker.ts +1 -1
- package/src/combobox.ts +1 -1
- package/src/component.ts +34 -39
- package/src/datastore.ts +1 -1
- package/src/dialog.ts +4 -2
- package/src/drag_manager.ts +4 -1
- package/src/fileupload.ts +2 -1
- package/src/form.ts +1 -1
- package/src/gridview.ts +4 -3
- package/src/hosts/electron.ts +4 -1
- package/src/i18n.ts +234 -97
- package/src/icon.ts +9 -12
- package/src/image.ts +5 -3
- package/src/index.ts +1 -1
- package/src/input.ts +1 -1
- package/src/layout.ts +1 -1
- package/src/link.ts +1 -1
- package/src/listview.ts +6 -4
- package/src/menu.ts +5 -3
- package/src/popup.ts +14 -12
- package/src/property_editor.ts +1 -1
- package/src/radiobtn.ts +4 -2
- package/src/rating.ts +1 -1
- package/src/router.ts +4 -2
- package/src/smartedit.ts +3 -2
- package/src/spreadsheet.ts +8 -6
- package/src/styles.ts +7 -5
- package/src/svgcomponent.ts +4 -1
- package/src/tabbar.ts +1 -1
- package/src/textarea.ts +1 -1
- package/src/textedit.ts +4 -2
- package/src/tools.ts +15 -5
- package/src/tooltips.ts +7 -5
- package/src/treeview.ts +1 -1
- package/src/x4dom.ts +57 -0
- package/src/{x4_events.ts → x4events.ts} +1 -1
- package/tsconfig.json +5 -1
package/lib/tools.js
CHANGED
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
29
29
|
**/
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.generatePassword = exports.classNames = exports.mix = exports.crc32 = exports.Clipboard = exports.isHtmlString = exports.html = exports.HtmlString = exports.clamp = exports.getMousePos = exports.NetworkError = exports.markdownToHtml = exports.asap = exports.deferCall = exports.waitFontLoading = exports.isNumber = exports.pad = exports.isLiteralObject = exports.isFunction = exports.isArray = exports.isString = exports.downloadData = exports.calcAge = exports.formatIntlDate = exports.parseIntlDate = exports.date_calc_weeknum = exports.date_clone = exports.date_hash = exports.date_sql_utc = exports.date_to_sql = exports.date_diff = exports.date_format = exports._date_set_locale = exports.removeHtmlTags = exports.escapeHtml = exports.sprintf = exports.Rect = exports.Size = exports.Point = exports.pascalCase = exports.parseIntlFloat = exports.roundTo = exports.isTouchDevice = void 0;
|
|
31
|
+
exports.generatePassword = exports.classNames = exports.mix = exports.crc32 = exports.Clipboard = exports.isHtmlString = exports.html = exports.HtmlString = exports.clamp = exports.getMousePos = exports.NetworkError = exports.markdownToHtml = exports.asap = exports.deferCall = exports.waitFontLoading = exports.isNumber = exports.pad = exports.isLiteralObject = exports.isFunction = exports.isArray = exports.isString = exports.downloadData = exports.calcAge = exports.formatIntlDate = exports.parseIntlDate = exports.date_calc_weeknum = exports.date_clone = exports.date_hash = exports.date_sql_utc = exports.date_to_sql = exports.date_diff = exports.date_format = exports._date_set_locale = exports.removeHtmlTags = exports.escapeHtml = exports.sprintf = exports.Rect = exports.Size = exports.Point = exports.camelCase = exports.pascalCase = exports.parseIntlFloat = exports.roundTo = exports.isTouchDevice = void 0;
|
|
32
|
+
const x4dom_1 = require("./x4dom");
|
|
32
33
|
const i18n_1 = require("./i18n"); // you MUST create a file named translation.js
|
|
33
34
|
// :: ENVIRONMENT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
34
35
|
/**
|
|
@@ -90,6 +91,14 @@ function pascalCase(string) {
|
|
|
90
91
|
return result.replace(/ /g, '-');
|
|
91
92
|
}
|
|
92
93
|
exports.pascalCase = pascalCase;
|
|
94
|
+
function camelCase(text) {
|
|
95
|
+
let result = text.toLowerCase();
|
|
96
|
+
result = result.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => {
|
|
97
|
+
return chr.toUpperCase();
|
|
98
|
+
});
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
exports.camelCase = camelCase;
|
|
93
102
|
class Point {
|
|
94
103
|
x;
|
|
95
104
|
y;
|
|
@@ -652,11 +661,11 @@ function downloadData(data, mimetype, filename) {
|
|
|
652
661
|
//}
|
|
653
662
|
let blob = new Blob([data], { type: mimetype });
|
|
654
663
|
let url = window.URL.createObjectURL(blob);
|
|
655
|
-
let a =
|
|
664
|
+
let a = x4dom_1.x4document.createElement("a");
|
|
656
665
|
a.style['display'] = "none";
|
|
657
666
|
a.href = url;
|
|
658
667
|
a.download = filename;
|
|
659
|
-
|
|
668
|
+
x4dom_1.x4document.body.appendChild(a);
|
|
660
669
|
a.click();
|
|
661
670
|
window.URL.revokeObjectURL(url);
|
|
662
671
|
}
|
|
@@ -733,20 +742,20 @@ function waitFontLoading(name) {
|
|
|
733
742
|
// we can remove the div.
|
|
734
743
|
// pitfall: if the font is already loaded, ne never end.
|
|
735
744
|
// @review that
|
|
736
|
-
let ct =
|
|
745
|
+
let ct = x4dom_1.x4document.createElement('div');
|
|
737
746
|
ct.style.position = 'absolute';
|
|
738
747
|
ct.style.fontFamily = name;
|
|
739
748
|
ct.style.fontSize = '44px';
|
|
740
749
|
ct.style.opacity = '0.001';
|
|
741
750
|
ct.innerText = 'X';
|
|
742
|
-
|
|
751
|
+
x4dom_1.x4document.body.appendChild(ct);
|
|
743
752
|
return new Promise((resolve) => {
|
|
744
753
|
let irc = ct.getBoundingClientRect();
|
|
745
754
|
let tm = setInterval(() => {
|
|
746
755
|
let nrc = ct.getBoundingClientRect();
|
|
747
756
|
if (nrc.height != irc.height) {
|
|
748
757
|
clearInterval(tm);
|
|
749
|
-
|
|
758
|
+
x4dom_1.x4document.body.removeChild(ct);
|
|
750
759
|
resolve();
|
|
751
760
|
}
|
|
752
761
|
}, 0);
|
package/lib/tooltips.js
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
**/
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
31
|
exports.initTooltips = exports.Tooltip = void 0;
|
|
32
|
+
const x4dom_1 = require("./x4dom");
|
|
32
33
|
const component_1 = require("./component");
|
|
33
34
|
const label_1 = require("./label");
|
|
34
35
|
const icon_1 = require("./icon");
|
|
@@ -66,7 +67,7 @@ class Tooltip extends component_1.Component {
|
|
|
66
67
|
valign = 'b';
|
|
67
68
|
}
|
|
68
69
|
// @TODO: this is a minimal overflow problem solution
|
|
69
|
-
let rc =
|
|
70
|
+
let rc = x4dom_1.x4document.body.getBoundingClientRect(), rm = this.getBoundingRect();
|
|
70
71
|
if (halign == 'r') {
|
|
71
72
|
x -= rm.width;
|
|
72
73
|
}
|
|
@@ -135,7 +136,7 @@ function initTooltips(cb) {
|
|
|
135
136
|
tipTmo = setTimeout(() => {
|
|
136
137
|
if (tooltip === undefined) {
|
|
137
138
|
tooltip = new Tooltip({});
|
|
138
|
-
|
|
139
|
+
x4dom_1.x4document.body.appendChild(tooltip._build());
|
|
139
140
|
}
|
|
140
141
|
tooltip.text = tip;
|
|
141
142
|
tooltip.displayAt(tipTarget.x + 17, tipTarget.y + 17, 'top left');
|
|
@@ -150,8 +151,8 @@ function initTooltips(cb) {
|
|
|
150
151
|
tooltip.hide();
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
x4dom_1.x4document.body.addEventListener('mouseover', handle_mouse);
|
|
155
|
+
x4dom_1.x4document.body.addEventListener('mouseout', handle_mouse);
|
|
156
|
+
x4dom_1.x4document.body.addEventListener('mousemove', handle_mpos);
|
|
156
157
|
}
|
|
157
158
|
exports.initTooltips = initTooltips;
|
package/lib/treeview.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ import { Component, Container, ContainerEventMap, ContainerProps, EvDblClick, Ev
|
|
|
30
30
|
import { HtmlString } from './tools';
|
|
31
31
|
import { IconID } from './icon';
|
|
32
32
|
import { VLayout } from './layout';
|
|
33
|
-
import { EvClick, BasicEvent, EvDrag, EvSelectionChange, EvContextMenu } from './
|
|
33
|
+
import { EvClick, BasicEvent, EvDrag, EvSelectionChange, EvContextMenu } from './x4events';
|
|
34
34
|
export interface EvExpand extends BasicEvent {
|
|
35
35
|
node: TreeNode;
|
|
36
36
|
}
|
package/lib/treeview.js
CHANGED
|
@@ -33,9 +33,9 @@ const component_1 = require("./component");
|
|
|
33
33
|
const icon_1 = require("./icon");
|
|
34
34
|
const label_1 = require("./label");
|
|
35
35
|
const layout_1 = require("./layout");
|
|
36
|
-
const
|
|
36
|
+
const x4events_1 = require("./x4events");
|
|
37
37
|
function EvExpand(node) {
|
|
38
|
-
return (0,
|
|
38
|
+
return (0, x4events_1.BasicEvent)({ node });
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
*
|
|
@@ -127,7 +127,7 @@ class TreeView extends layout_1.VLayout {
|
|
|
127
127
|
for (let i = 0; i < ev.dataTransfer.items.length; i++) {
|
|
128
128
|
ev.dataTransfer.items[0].getAsString((value) => {
|
|
129
129
|
let data = JSON.parse(value);
|
|
130
|
-
this.emit('drag', (0,
|
|
130
|
+
this.emit('drag', (0, x4events_1.EvDrag)(node, data, parent));
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -346,14 +346,14 @@ class TreeView extends layout_1.VLayout {
|
|
|
346
346
|
this.selection = nd.id;
|
|
347
347
|
if (!onsub) {
|
|
348
348
|
if (ev.type == 'click') {
|
|
349
|
-
this.emit('click', (0,
|
|
349
|
+
this.emit('click', (0, x4events_1.EvClick)(nd));
|
|
350
350
|
}
|
|
351
351
|
else {
|
|
352
352
|
this.emit('dblclick', (0, component_1.EvDblClick)(nd));
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
|
-
this.emit('selectionchange', (0,
|
|
356
|
+
this.emit('selectionchange', (0, x4events_1.EvSelectionChange)(nd));
|
|
357
357
|
return;
|
|
358
358
|
}
|
|
359
359
|
dom = dom.parentElement;
|
|
@@ -361,7 +361,7 @@ class TreeView extends layout_1.VLayout {
|
|
|
361
361
|
if (ev.type == 'click') {
|
|
362
362
|
this.m_selection = null;
|
|
363
363
|
this.update();
|
|
364
|
-
this.emit('selectionchange', (0,
|
|
364
|
+
this.emit('selectionchange', (0, x4events_1.EvSelectionChange)(null));
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
_handleCtxMenu(ev) {
|
|
@@ -380,14 +380,14 @@ class TreeView extends layout_1.VLayout {
|
|
|
380
380
|
}
|
|
381
381
|
this.m_selection = { id: nd.id, el: null };
|
|
382
382
|
this.update();
|
|
383
|
-
this.emit('contextMenu', (0,
|
|
383
|
+
this.emit('contextMenu', (0, x4events_1.EvContextMenu)(ev, nd));
|
|
384
384
|
return;
|
|
385
385
|
}
|
|
386
386
|
dom = dom.parentElement;
|
|
387
387
|
}
|
|
388
388
|
this.m_selection = null;
|
|
389
389
|
this.update();
|
|
390
|
-
this.emit('contextMenu', (0,
|
|
390
|
+
this.emit('contextMenu', (0, x4events_1.EvContextMenu)(ev, null));
|
|
391
391
|
}
|
|
392
392
|
/**
|
|
393
393
|
* constructs a tree node from an array of strings
|
package/lib/x4dom.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*/
|
|
4
|
+
interface IX4Document {
|
|
5
|
+
createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K];
|
|
6
|
+
createElementNS(namespace: string | null, qualifiedName: string, options?: string | ElementCreationOptions): Element;
|
|
7
|
+
createTextNode(data: string): Text;
|
|
8
|
+
addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
9
|
+
removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
10
|
+
querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
|
|
11
|
+
querySelector<E extends Element = Element>(selectors: string): E | null;
|
|
12
|
+
get body(): HTMLElement;
|
|
13
|
+
get activeElement(): Element;
|
|
14
|
+
get location(): Location;
|
|
15
|
+
get styleSheets(): StyleSheetList;
|
|
16
|
+
get head(): HTMLHeadElement;
|
|
17
|
+
get documentElement(): HTMLElement;
|
|
18
|
+
set title(title: string);
|
|
19
|
+
}
|
|
20
|
+
export declare let x4document: IX4Document;
|
|
21
|
+
export {};
|
package/lib/x4dom.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file observable.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2019-2022 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
+
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
+
* subject to the following conditions:
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
+
* or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
+
**/
|
|
29
|
+
export declare type EventCallback<T extends BasicEvent = BasicEvent> = (event: T) => any;
|
|
30
|
+
export interface EventDisposer {
|
|
31
|
+
dispose(): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Basic event
|
|
35
|
+
* name like that to avoid conflict with Browsers Event class.
|
|
36
|
+
*/
|
|
37
|
+
export interface BasicEvent {
|
|
38
|
+
readonly type?: string;
|
|
39
|
+
readonly source?: unknown;
|
|
40
|
+
readonly context?: any;
|
|
41
|
+
propagationStopped?: boolean;
|
|
42
|
+
defaultPrevented?: boolean;
|
|
43
|
+
stopPropagation?(): void;
|
|
44
|
+
preventDefault?(): void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* BasicEvent Builder
|
|
48
|
+
* this function is responsable of BasicEvent creation
|
|
49
|
+
* ie. is equivalent of new BasicEvent( xxx );
|
|
50
|
+
* @param params
|
|
51
|
+
* @returns BasicEvent
|
|
52
|
+
*/
|
|
53
|
+
export declare function BasicEvent<T extends BasicEvent = BasicEvent>(params: any): T;
|
|
54
|
+
/**
|
|
55
|
+
* Click Event
|
|
56
|
+
* click event do not have any additional parameters
|
|
57
|
+
*/
|
|
58
|
+
export interface EvClick extends BasicEvent {
|
|
59
|
+
}
|
|
60
|
+
export declare function EvClick(context?: any): EvClick;
|
|
61
|
+
/**
|
|
62
|
+
* Change Event
|
|
63
|
+
* value is the the element value
|
|
64
|
+
*/
|
|
65
|
+
export interface EvChange extends BasicEvent {
|
|
66
|
+
readonly value: any;
|
|
67
|
+
}
|
|
68
|
+
export declare function EvChange(value: unknown, context?: any): EvChange;
|
|
69
|
+
/**
|
|
70
|
+
* Selection Event
|
|
71
|
+
* value is the new selection or null
|
|
72
|
+
*/
|
|
73
|
+
export interface EvSelectionChange extends BasicEvent {
|
|
74
|
+
readonly selection: unknown;
|
|
75
|
+
}
|
|
76
|
+
export declare function EvSelectionChange(selection: unknown, context?: any): EvSelectionChange;
|
|
77
|
+
/**
|
|
78
|
+
* ContextMenu Event
|
|
79
|
+
*/
|
|
80
|
+
export interface EvContextMenu extends BasicEvent {
|
|
81
|
+
uievent: UIEvent;
|
|
82
|
+
}
|
|
83
|
+
export declare function EvContextMenu(uievent: UIEvent, context?: any): EvContextMenu;
|
|
84
|
+
/**
|
|
85
|
+
* Timer Event
|
|
86
|
+
* @see startTimer, stopTimer
|
|
87
|
+
*/
|
|
88
|
+
export interface EvTimer extends BasicEvent {
|
|
89
|
+
timer: string;
|
|
90
|
+
time: number;
|
|
91
|
+
}
|
|
92
|
+
export declare function EvTimer(timer: string, time?: number, context?: any): EvTimer;
|
|
93
|
+
/**
|
|
94
|
+
* Simple message
|
|
95
|
+
*/
|
|
96
|
+
export interface EvMessage extends BasicEvent {
|
|
97
|
+
readonly msg: string;
|
|
98
|
+
readonly params?: any;
|
|
99
|
+
}
|
|
100
|
+
export declare function EvMessage(msg: string, params?: unknown, source?: unknown): EvMessage;
|
|
101
|
+
/**
|
|
102
|
+
* Drag/Drop event
|
|
103
|
+
*/
|
|
104
|
+
export interface EvDrag extends BasicEvent {
|
|
105
|
+
element: unknown;
|
|
106
|
+
data: any;
|
|
107
|
+
}
|
|
108
|
+
export declare function EvDrag(element: unknown, data: any, ctx: any): EvDrag;
|
|
109
|
+
/**
|
|
110
|
+
* Errors
|
|
111
|
+
*/
|
|
112
|
+
export interface EvError extends BasicEvent {
|
|
113
|
+
code: number;
|
|
114
|
+
message: string;
|
|
115
|
+
}
|
|
116
|
+
export declare function EvError(code: number, message: string): EvError;
|
|
117
|
+
/**
|
|
118
|
+
* this Base interface is used to describe available events & their types
|
|
119
|
+
*
|
|
120
|
+
* you can implement your own event mapping:
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* interface MyEventMap extends EventMap {
|
|
124
|
+
* click: EvClick,
|
|
125
|
+
* 'custom-message': Event,
|
|
126
|
+
* [key: string]: Event,
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export interface EventMap {
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* basic event types, in general the type is builded from the eventMap
|
|
134
|
+
* this is very usefull for editor completion
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* type MyEventType = MapEvents<MyEventMap>;
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export interface EventTypes {
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* convert an EventMap to a EventType
|
|
144
|
+
*/
|
|
145
|
+
export declare type MapEvents<Type> = {
|
|
146
|
+
[Property in keyof Type]?: (ev: Type[Property]) => any;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Event emitter class
|
|
150
|
+
* this class allow you to emit and handle events
|
|
151
|
+
*
|
|
152
|
+
* @example:
|
|
153
|
+
* ```ts
|
|
154
|
+
*
|
|
155
|
+
* interface EvDoIt extends BasicEvent {
|
|
156
|
+
* param: unknown;
|
|
157
|
+
* }
|
|
158
|
+
*
|
|
159
|
+
* function EvDoIt( e: EvDoIt ) : EvDoIt {
|
|
160
|
+
* return BasicEvent<EvDoIt>( e );
|
|
161
|
+
* }
|
|
162
|
+
*
|
|
163
|
+
* interface TestEventMap extends EventMap {
|
|
164
|
+
* doit: EvDoIt;
|
|
165
|
+
* }
|
|
166
|
+
*
|
|
167
|
+
* let ee = new EventSource<TestEventMap>(null);
|
|
168
|
+
* ee.listen({
|
|
169
|
+
* doit: (e) => {
|
|
170
|
+
* console.log(e);
|
|
171
|
+
* e.preventDefault();
|
|
172
|
+
* },
|
|
173
|
+
* });
|
|
174
|
+
*
|
|
175
|
+
* ee.defaults({
|
|
176
|
+
* doit: (e) => {
|
|
177
|
+
* console.log('default handler for ', e.type, e.selection);
|
|
178
|
+
* },
|
|
179
|
+
* })
|
|
180
|
+
*
|
|
181
|
+
* ee.on('doit', (e) => {
|
|
182
|
+
* debugger;
|
|
183
|
+
* })
|
|
184
|
+
*
|
|
185
|
+
* const ev = EvDoIt({ param: 10 });
|
|
186
|
+
* ee.emit('change', ev);
|
|
187
|
+
* if (ev.defaultPrevented) {
|
|
188
|
+
* console.log('prevented');
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare class EventSource<Q extends EventMap, T extends EventTypes = MapEvents<Q>> {
|
|
193
|
+
private m_source;
|
|
194
|
+
private m_eventRegistry;
|
|
195
|
+
private m_defaultHandlers;
|
|
196
|
+
constructor(source?: unknown);
|
|
197
|
+
/**
|
|
198
|
+
* emit an event
|
|
199
|
+
* you can stop propagation of event or prevent default
|
|
200
|
+
* @param eventName - name of event to emit
|
|
201
|
+
* @param event - event data
|
|
202
|
+
*/
|
|
203
|
+
emit<K extends keyof Q>(type: K, event?: Q[K]): void;
|
|
204
|
+
_emit(eventName: string, e: BasicEvent): void;
|
|
205
|
+
/**
|
|
206
|
+
* signal en event
|
|
207
|
+
* signaled event are notification : no way to prevent default not stop propagation
|
|
208
|
+
* @param eventName name of event to signal
|
|
209
|
+
* @param event event data
|
|
210
|
+
*/
|
|
211
|
+
signal<K extends keyof Q>(type: K, event: Q[K], delay?: number): void;
|
|
212
|
+
_signal(eventName: string, e: BasicEvent, delay?: number): void;
|
|
213
|
+
/**
|
|
214
|
+
* handle an event one time
|
|
215
|
+
* @param eventName - event name to handle
|
|
216
|
+
* @param callback - callback to call when event is signaled
|
|
217
|
+
* @returns Promise if callback is null
|
|
218
|
+
*
|
|
219
|
+
* take care with that because if the event is never fired and you await it,
|
|
220
|
+
* the system may overflow
|
|
221
|
+
*/
|
|
222
|
+
once<K extends keyof Q>(type: K, callback: (ev: Q[K]) => any): void;
|
|
223
|
+
_once(eventName: string, callback: EventCallback): Promise<unknown>;
|
|
224
|
+
/**
|
|
225
|
+
* set the event default handler
|
|
226
|
+
* @param eventName - name of the event
|
|
227
|
+
* @param callback - callback to call when the event is not handled (and preventDeault has not been called)
|
|
228
|
+
*/
|
|
229
|
+
setDefaultHandler(eventName: string, callback: EventCallback): void;
|
|
230
|
+
/**
|
|
231
|
+
* remove the previous default handler installed for an event
|
|
232
|
+
* @param eventName - event name
|
|
233
|
+
* @param callback - callback handler to remove (must be the same as in setDefaultHandler)
|
|
234
|
+
*/
|
|
235
|
+
removeDefaultHandler(eventName: string, callback: EventCallback): void;
|
|
236
|
+
/**
|
|
237
|
+
* define a set of listeners in one call
|
|
238
|
+
* @param events
|
|
239
|
+
*/
|
|
240
|
+
listen(events: T): void;
|
|
241
|
+
/**
|
|
242
|
+
* define a set of default handlers in one call
|
|
243
|
+
* @param events
|
|
244
|
+
*/
|
|
245
|
+
defaults(events: T): void;
|
|
246
|
+
/**
|
|
247
|
+
* listen for an event
|
|
248
|
+
* @param eventName - event name to listen on
|
|
249
|
+
* @param callback - callback to call
|
|
250
|
+
* @param capturing - if true, capture event before other registred event handlers
|
|
251
|
+
*/
|
|
252
|
+
on<K extends keyof Q>(type: K, callback: (ev: Q[K]) => any): EventDisposer;
|
|
253
|
+
_on(eventName: string, callback: EventCallback, capturing?: boolean): EventDisposer;
|
|
254
|
+
/**
|
|
255
|
+
* stop listening to an event
|
|
256
|
+
* @param eventName - event name
|
|
257
|
+
* @param callback - callback to remove (must be the same as in on )
|
|
258
|
+
*/
|
|
259
|
+
off<K extends keyof Q>(type: K, callback: (ev: Q[K]) => any): void;
|
|
260
|
+
_off(eventName: string, callback: EventCallback): void;
|
|
261
|
+
/**
|
|
262
|
+
* remove all listeners for an event
|
|
263
|
+
* @param eventName - event name
|
|
264
|
+
*/
|
|
265
|
+
removeAllListeners(eventName: string | null): void;
|
|
266
|
+
}
|