x4js 1.4.4 → 1.4.5
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 +95 -0
- package/lib/application.js +141 -0
- package/lib/base64.d.ts +31 -0
- package/lib/base64.js +139 -0
- package/lib/base_component.d.ts +64 -0
- package/lib/base_component.js +81 -0
- package/lib/button.d.ts +145 -0
- package/lib/button.js +241 -0
- package/lib/calendar.d.ts +77 -0
- package/lib/calendar.js +241 -0
- package/lib/canvas.d.ts +88 -0
- package/lib/canvas.js +358 -0
- package/lib/cardview.d.ts +83 -0
- package/lib/cardview.js +156 -0
- package/lib/checkbox.d.ts +72 -0
- package/lib/checkbox.js +130 -0
- package/lib/color.d.ts +144 -0
- package/lib/color.js +588 -0
- package/lib/colorpicker.js +86 -80
- package/lib/combobox.js +26 -22
- package/lib/component.d.ts +572 -0
- package/lib/component.js +1729 -0
- package/lib/datastore.js +29 -20
- package/lib/dialog.js +41 -36
- package/lib/dom_events.d.ts +284 -0
- package/lib/dom_events.js +14 -0
- package/lib/drag_manager.js +4 -1
- package/lib/drawtext.js +9 -5
- package/lib/fileupload.js +19 -12
- package/lib/form.js +29 -25
- package/lib/formatters.js +19 -10
- package/lib/gridview.js +40 -35
- package/lib/hosts/host.d.ts +44 -0
- package/lib/hosts/host.js +73 -0
- package/lib/i18n.d.ts +67 -0
- package/lib/i18n.js +175 -0
- package/lib/icon.d.ts +56 -0
- package/lib/icon.js +178 -0
- package/lib/image.js +7 -3
- package/lib/index.js +71 -55
- package/lib/input.d.ts +86 -0
- package/lib/input.js +176 -0
- package/lib/label.d.ts +54 -0
- package/lib/label.js +90 -0
- package/lib/layout.d.ts +77 -0
- package/lib/layout.js +271 -0
- package/lib/link.js +9 -5
- package/lib/listview.js +34 -27
- package/lib/md5.js +5 -1
- package/lib/menu.d.ts +122 -0
- package/lib/menu.js +284 -0
- package/lib/messagebox.js +22 -17
- package/lib/panel.js +13 -9
- package/lib/popup.d.ts +71 -0
- package/lib/popup.js +378 -0
- package/lib/property_editor.js +20 -16
- package/lib/radiobtn.js +13 -9
- package/lib/rating.js +13 -9
- package/lib/request.js +16 -9
- package/lib/router.js +5 -1
- package/lib/settings.d.ts +33 -0
- package/lib/settings.js +67 -0
- package/lib/sidebarview.js +12 -8
- package/lib/smartedit.js +16 -11
- package/lib/spreadsheet.js +35 -31
- package/lib/styles.d.ts +81 -0
- package/lib/styles.js +268 -0
- package/lib/svgcomponent.js +8 -3
- package/lib/tabbar.js +10 -6
- package/lib/tabview.js +10 -6
- package/lib/textarea.js +10 -6
- package/lib/textedit.js +39 -35
- package/lib/texthiliter.js +8 -4
- package/lib/toaster.js +8 -4
- package/lib/tools.d.ts +382 -0
- package/lib/tools.js +1142 -0
- package/lib/tooltips.js +14 -9
- package/lib/treeview.js +30 -26
- package/lib/x4_events.d.ts +253 -0
- package/lib/x4_events.js +375 -0
- package/package.json +1 -1
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file application.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
import { EvMessage } from './x4_events';
|
|
26
|
+
import { BaseComponent, BaseComponentEventMap, BaseComponentProps } from './base_component';
|
|
27
|
+
import { Component } from './component';
|
|
28
|
+
import { Settings } from './settings';
|
|
29
|
+
interface ApplicationEventMap extends BaseComponentEventMap {
|
|
30
|
+
message: EvMessage;
|
|
31
|
+
global: EvMessage;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export interface ApplicationProps extends BaseComponentProps<ApplicationEventMap> {
|
|
37
|
+
app_name: string;
|
|
38
|
+
app_version: string;
|
|
39
|
+
app_uid: string;
|
|
40
|
+
locale: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Represents an x4 application, which is typically a single page app.
|
|
44
|
+
* You should inherit Application to define yours.
|
|
45
|
+
* Application derives from BaseComponent so you can use that to implement a global messaging system.
|
|
46
|
+
* @example ```ts
|
|
47
|
+
*
|
|
48
|
+
* // in yout main caode
|
|
49
|
+
* let app = new Application( );
|
|
50
|
+
*
|
|
51
|
+
* app.events.close.on( ( ev ) => {
|
|
52
|
+
* ... do something
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // somewhere else in the source
|
|
56
|
+
* function xxx( ) {
|
|
57
|
+
* let app = Application.instance( );
|
|
58
|
+
* app.events.close.emit( new Events.close() );
|
|
59
|
+
* }
|
|
60
|
+
*/
|
|
61
|
+
export declare class Application<P extends ApplicationProps = ApplicationProps, E extends ApplicationEventMap = ApplicationEventMap> extends BaseComponent<P, E> {
|
|
62
|
+
private static self;
|
|
63
|
+
/**
|
|
64
|
+
* the application singleton
|
|
65
|
+
*/
|
|
66
|
+
static instance(): Application;
|
|
67
|
+
private m_mainView;
|
|
68
|
+
private m_app_name;
|
|
69
|
+
private m_app_version;
|
|
70
|
+
private m_app_uid;
|
|
71
|
+
private m_local_storage;
|
|
72
|
+
private m_user_data;
|
|
73
|
+
constructor(props: P);
|
|
74
|
+
ApplicationCreated(): void;
|
|
75
|
+
get app_name(): string;
|
|
76
|
+
get app_uid(): string;
|
|
77
|
+
get app_version(): string;
|
|
78
|
+
get local_storage(): Settings;
|
|
79
|
+
get user_data(): any;
|
|
80
|
+
get history(): any;
|
|
81
|
+
/**
|
|
82
|
+
* define the application root object (MainView)
|
|
83
|
+
* @example ```ts
|
|
84
|
+
*
|
|
85
|
+
* let myApp = new Application( ... );
|
|
86
|
+
* let mainView = new VLayout( ... );
|
|
87
|
+
* myApp.setMainView( mainView );
|
|
88
|
+
*/
|
|
89
|
+
set mainView(root: Component);
|
|
90
|
+
get mainView(): Component;
|
|
91
|
+
setTitle(title: string): void;
|
|
92
|
+
disableZoomWheel(): void;
|
|
93
|
+
enterModal(enter: boolean): void;
|
|
94
|
+
}
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ___ ___ __
|
|
4
|
+
* \ \/ / / _
|
|
5
|
+
* \ / /_| |_
|
|
6
|
+
* / \____ _|
|
|
7
|
+
* /__/\__\ |_|
|
|
8
|
+
*
|
|
9
|
+
* @file application.ts
|
|
10
|
+
* @author Etienne Cochard
|
|
11
|
+
* @license
|
|
12
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
13
|
+
*
|
|
14
|
+
* This program is free software; you can redistribute it and/or modify
|
|
15
|
+
* it under the terms of the GNU General Public License as published by
|
|
16
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
17
|
+
* (at your option) any later version.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
25
|
+
**/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Application = void 0;
|
|
28
|
+
const base_component_1 = require("./base_component");
|
|
29
|
+
const settings_1 = require("./settings");
|
|
30
|
+
const tools_1 = require("./tools");
|
|
31
|
+
/**
|
|
32
|
+
* Represents an x4 application, which is typically a single page app.
|
|
33
|
+
* You should inherit Application to define yours.
|
|
34
|
+
* Application derives from BaseComponent so you can use that to implement a global messaging system.
|
|
35
|
+
* @example ```ts
|
|
36
|
+
*
|
|
37
|
+
* // in yout main caode
|
|
38
|
+
* let app = new Application( );
|
|
39
|
+
*
|
|
40
|
+
* app.events.close.on( ( ev ) => {
|
|
41
|
+
* ... do something
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // somewhere else in the source
|
|
45
|
+
* function xxx( ) {
|
|
46
|
+
* let app = Application.instance( );
|
|
47
|
+
* app.events.close.emit( new Events.close() );
|
|
48
|
+
* }
|
|
49
|
+
*/
|
|
50
|
+
class Application extends base_component_1.BaseComponent {
|
|
51
|
+
static self = null;
|
|
52
|
+
/**
|
|
53
|
+
* the application singleton
|
|
54
|
+
*/
|
|
55
|
+
static instance() {
|
|
56
|
+
return Application.self;
|
|
57
|
+
}
|
|
58
|
+
m_mainView;
|
|
59
|
+
m_app_name;
|
|
60
|
+
m_app_version;
|
|
61
|
+
m_app_uid;
|
|
62
|
+
m_local_storage;
|
|
63
|
+
m_user_data;
|
|
64
|
+
constructor(props) {
|
|
65
|
+
console.assert(Application.self === null, 'application is a singleton');
|
|
66
|
+
super(props);
|
|
67
|
+
this.m_app_name = props.app_name ?? 'application';
|
|
68
|
+
this.m_app_version = props.app_version ?? '1.0';
|
|
69
|
+
this.m_app_uid = props.app_uid ?? 'application';
|
|
70
|
+
let settings_name = `${this.m_app_name}.${this.m_app_version}.settings`;
|
|
71
|
+
this.m_local_storage = new settings_1.Settings(settings_name);
|
|
72
|
+
this.m_user_data = {};
|
|
73
|
+
Application.self = this;
|
|
74
|
+
if ('onload' in globalThis) {
|
|
75
|
+
globalThis.addEventListener('load', () => {
|
|
76
|
+
this.ApplicationCreated();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.ApplicationCreated();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
ApplicationCreated() {
|
|
84
|
+
}
|
|
85
|
+
get app_name() {
|
|
86
|
+
return this.m_app_name;
|
|
87
|
+
}
|
|
88
|
+
get app_uid() {
|
|
89
|
+
return this.m_app_uid;
|
|
90
|
+
}
|
|
91
|
+
get app_version() {
|
|
92
|
+
return this.m_app_version;
|
|
93
|
+
}
|
|
94
|
+
get local_storage() {
|
|
95
|
+
return this.m_local_storage;
|
|
96
|
+
}
|
|
97
|
+
get user_data() {
|
|
98
|
+
return this.m_user_data;
|
|
99
|
+
}
|
|
100
|
+
get history() {
|
|
101
|
+
//if( !this.m_history ) {
|
|
102
|
+
// this.m_history = new NavigationHistory( );
|
|
103
|
+
//}
|
|
104
|
+
//
|
|
105
|
+
//return this.m_history;
|
|
106
|
+
debugger;
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* define the application root object (MainView)
|
|
111
|
+
* @example ```ts
|
|
112
|
+
*
|
|
113
|
+
* let myApp = new Application( ... );
|
|
114
|
+
* let mainView = new VLayout( ... );
|
|
115
|
+
* myApp.setMainView( mainView );
|
|
116
|
+
*/
|
|
117
|
+
set mainView(root) {
|
|
118
|
+
this.m_mainView = root;
|
|
119
|
+
(0, tools_1.deferCall)(() => {
|
|
120
|
+
document.body.appendChild(root._build());
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
get mainView() {
|
|
124
|
+
return this.m_mainView;
|
|
125
|
+
}
|
|
126
|
+
setTitle(title) {
|
|
127
|
+
document.title = this.m_app_name + ' > ' + title;
|
|
128
|
+
}
|
|
129
|
+
disableZoomWheel() {
|
|
130
|
+
window.addEventListener('wheel', function (ev) {
|
|
131
|
+
if (ev.ctrlKey) {
|
|
132
|
+
ev.preventDefault();
|
|
133
|
+
//ev.stopPropagation( );
|
|
134
|
+
}
|
|
135
|
+
}, { passive: false, capture: true });
|
|
136
|
+
}
|
|
137
|
+
enterModal(enter) {
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.Application = Application;
|
|
141
|
+
;
|
package/lib/base64.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file base64.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
export declare class Base64 {
|
|
26
|
+
lookup: any;
|
|
27
|
+
static encode(s: string | Uint8Array): string;
|
|
28
|
+
static decode(s: string): string;
|
|
29
|
+
private static _toUtf8;
|
|
30
|
+
private static _fromUtf8;
|
|
31
|
+
}
|
package/lib/base64.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ___ ___ __
|
|
4
|
+
* \ \/ / / _
|
|
5
|
+
* \ / /_| |_
|
|
6
|
+
* / \____ _|
|
|
7
|
+
* /__/\__\ |_|
|
|
8
|
+
*
|
|
9
|
+
* @file base64.ts
|
|
10
|
+
* @author Etienne Cochard
|
|
11
|
+
* @license
|
|
12
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
13
|
+
*
|
|
14
|
+
* This program is free software; you can redistribute it and/or modify
|
|
15
|
+
* it under the terms of the GNU General Public License as published by
|
|
16
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
17
|
+
* (at your option) any later version.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
25
|
+
**/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Base64 = void 0;
|
|
28
|
+
const _alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
29
|
+
let _lookup = null;
|
|
30
|
+
class Base64 {
|
|
31
|
+
lookup = null;
|
|
32
|
+
static encode(s) {
|
|
33
|
+
let buffer;
|
|
34
|
+
if (s instanceof Uint8Array) {
|
|
35
|
+
buffer = [];
|
|
36
|
+
s.forEach((v) => {
|
|
37
|
+
buffer.push(v);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
buffer = Base64._toUtf8(s);
|
|
42
|
+
}
|
|
43
|
+
let position = -1;
|
|
44
|
+
let len = buffer.length;
|
|
45
|
+
let nan1, nan2;
|
|
46
|
+
let enc = [, , ,];
|
|
47
|
+
let result = '';
|
|
48
|
+
while (++position < len) {
|
|
49
|
+
nan1 = buffer[position + 1], nan2 = buffer[position + 2];
|
|
50
|
+
enc[0] = buffer[position] >> 2;
|
|
51
|
+
enc[1] = ((buffer[position] & 3) << 4) | (buffer[++position] >> 4);
|
|
52
|
+
if (isNaN(nan1)) {
|
|
53
|
+
enc[2] = enc[3] = 64;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
enc[2] = ((buffer[position] & 15) << 2) | (buffer[++position] >> 6);
|
|
57
|
+
enc[3] = (isNaN(nan2)) ? 64 : buffer[position] & 63;
|
|
58
|
+
}
|
|
59
|
+
result += _alphabet[enc[0]] + _alphabet[enc[1]] + _alphabet[enc[2]] + _alphabet[enc[3]];
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
static decode(s) {
|
|
64
|
+
let buffer = Base64._fromUtf8(s);
|
|
65
|
+
let position = 0;
|
|
66
|
+
let len = buffer.length;
|
|
67
|
+
let result = '';
|
|
68
|
+
while (position < len) {
|
|
69
|
+
if (buffer[position] < 128) {
|
|
70
|
+
result += String.fromCharCode(buffer[position++]);
|
|
71
|
+
}
|
|
72
|
+
else if (buffer[position] > 191 && buffer[position] < 224) {
|
|
73
|
+
result += String.fromCharCode(((buffer[position++] & 31) << 6) | (buffer[position++] & 63));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
result += String.fromCharCode(((buffer[position++] & 15) << 12) | ((buffer[position++] & 63) << 6) | (buffer[position++] & 63));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
static _toUtf8(s) {
|
|
82
|
+
let position = -1;
|
|
83
|
+
let len = s.length;
|
|
84
|
+
let chr;
|
|
85
|
+
let buffer = [];
|
|
86
|
+
if (/^[\x00-\x7f]*$/.test(s)) {
|
|
87
|
+
while (++position < len) {
|
|
88
|
+
buffer.push(s.charCodeAt(position));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
while (++position < len) {
|
|
93
|
+
chr = s.charCodeAt(position);
|
|
94
|
+
if (chr < 128) {
|
|
95
|
+
buffer.push(chr);
|
|
96
|
+
}
|
|
97
|
+
else if (chr < 2048) {
|
|
98
|
+
buffer.push((chr >> 6) | 192, (chr & 63) | 128);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
buffer.push((chr >> 12) | 224, ((chr >> 6) & 63) | 128, (chr & 63) | 128);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return buffer;
|
|
106
|
+
}
|
|
107
|
+
static _fromUtf8(s) {
|
|
108
|
+
let position = -1;
|
|
109
|
+
let len;
|
|
110
|
+
let buffer = [];
|
|
111
|
+
let enc = [, , ,];
|
|
112
|
+
if (!_lookup) {
|
|
113
|
+
len = _alphabet.length;
|
|
114
|
+
_lookup = {};
|
|
115
|
+
while (++position < len) {
|
|
116
|
+
_lookup[_alphabet[position]] = position;
|
|
117
|
+
}
|
|
118
|
+
position = -1;
|
|
119
|
+
}
|
|
120
|
+
len = s.length;
|
|
121
|
+
while (position < len) {
|
|
122
|
+
enc[0] = _lookup[s.charAt(++position)];
|
|
123
|
+
enc[1] = _lookup[s.charAt(++position)];
|
|
124
|
+
buffer.push((enc[0] << 2) | (enc[1] >> 4));
|
|
125
|
+
enc[2] = _lookup[s.charAt(++position)];
|
|
126
|
+
if (enc[2] == 64) {
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
buffer.push(((enc[1] & 15) << 4) | (enc[2] >> 2));
|
|
130
|
+
enc[3] = _lookup[s.charAt(++position)];
|
|
131
|
+
if (enc[3] == 64) {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
buffer.push(((enc[2] & 3) << 6) | enc[3]);
|
|
135
|
+
}
|
|
136
|
+
return buffer;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.Base64 = Base64;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file base_component.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @copyright (c) 2022 R-libre ingenierie, all rights reserved.
|
|
11
|
+
*
|
|
12
|
+
**/
|
|
13
|
+
import { EventMap, MapEvents, EventSource, EvTimer } from './x4_events';
|
|
14
|
+
/**
|
|
15
|
+
* Timer Callback
|
|
16
|
+
* @see EvTimer, startTimer, stopTimer
|
|
17
|
+
*/
|
|
18
|
+
interface TimerCallback {
|
|
19
|
+
(name: string, time: number): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* BaseComponent EventMap
|
|
23
|
+
*/
|
|
24
|
+
export interface BaseComponentEventMap extends EventMap {
|
|
25
|
+
timer: EvTimer;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* BaseCompoment Properties
|
|
29
|
+
*/
|
|
30
|
+
export interface BaseComponentProps<T = BaseComponentEventMap> {
|
|
31
|
+
events?: MapEvents<T>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* BaseComponent class
|
|
35
|
+
*/
|
|
36
|
+
export declare class BaseComponent<P extends BaseComponentProps<BaseComponentEventMap>, E extends BaseComponentEventMap> extends EventSource<E> {
|
|
37
|
+
#private;
|
|
38
|
+
protected m_props: P;
|
|
39
|
+
constructor(props: P);
|
|
40
|
+
/**
|
|
41
|
+
* start a new timer
|
|
42
|
+
* @param name timer name
|
|
43
|
+
* @param timeout time out in ms
|
|
44
|
+
* @param repeat if true this is an auto repeat timer
|
|
45
|
+
* @param callback if !null, the callback to call else a EvTimer is fired
|
|
46
|
+
*/
|
|
47
|
+
startTimer(name: string, timeout: number, repeat?: boolean, callback?: TimerCallback): void;
|
|
48
|
+
/**
|
|
49
|
+
* stop the given timer
|
|
50
|
+
* @param name
|
|
51
|
+
*/
|
|
52
|
+
stopTimer(name: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* stop all timers
|
|
55
|
+
*/
|
|
56
|
+
disposeTimers(): void;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param callback
|
|
60
|
+
* @param timeout
|
|
61
|
+
*/
|
|
62
|
+
singleShot(callback: TimerCallback, timeout?: number): void;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ___ ___ __
|
|
4
|
+
* \ \/ / / _
|
|
5
|
+
* \ / /_| |_
|
|
6
|
+
* / \____ _|
|
|
7
|
+
* /__/\__\ |_|
|
|
8
|
+
*
|
|
9
|
+
* @file base_component.ts
|
|
10
|
+
* @author Etienne Cochard
|
|
11
|
+
* @copyright (c) 2022 R-libre ingenierie, all rights reserved.
|
|
12
|
+
*
|
|
13
|
+
**/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BaseComponent = void 0;
|
|
16
|
+
const x4_events_1 = require("./x4_events");
|
|
17
|
+
/**
|
|
18
|
+
* BaseComponent class
|
|
19
|
+
*/
|
|
20
|
+
class BaseComponent extends x4_events_1.EventSource {
|
|
21
|
+
m_props;
|
|
22
|
+
#m_timers;
|
|
23
|
+
constructor(props) {
|
|
24
|
+
super();
|
|
25
|
+
//this.m_props = { ...props };
|
|
26
|
+
this.m_props = props;
|
|
27
|
+
if (props.events) {
|
|
28
|
+
this.listen(props.events);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* start a new timer
|
|
33
|
+
* @param name timer name
|
|
34
|
+
* @param timeout time out in ms
|
|
35
|
+
* @param repeat if true this is an auto repeat timer
|
|
36
|
+
* @param callback if !null, the callback to call else a EvTimer is fired
|
|
37
|
+
*/
|
|
38
|
+
startTimer(name, timeout, repeat = true, callback = null) {
|
|
39
|
+
if (!this.#m_timers) {
|
|
40
|
+
this.#m_timers = new Map();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.stopTimer(name);
|
|
44
|
+
}
|
|
45
|
+
const id = (repeat ? setInterval : setTimeout)((tm) => {
|
|
46
|
+
if (callback) {
|
|
47
|
+
callback(name, tm);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.emit('timer', (0, x4_events_1.EvTimer)(name, tm));
|
|
51
|
+
}
|
|
52
|
+
}, timeout);
|
|
53
|
+
this.#m_timers.set(name, () => { (repeat ? clearInterval : clearTimeout)(id); });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* stop the given timer
|
|
57
|
+
* @param name
|
|
58
|
+
*/
|
|
59
|
+
stopTimer(name) {
|
|
60
|
+
const clear = this.#m_timers.get(name);
|
|
61
|
+
if (clear) {
|
|
62
|
+
clear();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* stop all timers
|
|
67
|
+
*/
|
|
68
|
+
disposeTimers() {
|
|
69
|
+
this.#m_timers?.forEach(v => v());
|
|
70
|
+
this.#m_timers = undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @param callback
|
|
75
|
+
* @param timeout
|
|
76
|
+
*/
|
|
77
|
+
singleShot(callback, timeout = 0) {
|
|
78
|
+
setTimeout(callback, timeout);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.BaseComponent = BaseComponent;
|
package/lib/button.d.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file button.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
import { Component, CProps, CEventMap, HtmlString } from './component';
|
|
26
|
+
import { EventCallback, EvClick, EvChange } from './x4_events';
|
|
27
|
+
import { IconID } from './icon';
|
|
28
|
+
import { MenuItem, MenuOrSep } from './menu';
|
|
29
|
+
/**
|
|
30
|
+
* Button events
|
|
31
|
+
*/
|
|
32
|
+
interface ButtonEventMap extends CEventMap {
|
|
33
|
+
click: EvClick;
|
|
34
|
+
}
|
|
35
|
+
declare type MenuCallBack = () => MenuOrSep[];
|
|
36
|
+
/**
|
|
37
|
+
* Button properties
|
|
38
|
+
*/
|
|
39
|
+
interface ButtonProps<E extends ButtonEventMap = ButtonEventMap> extends CProps<E> {
|
|
40
|
+
text?: string | HtmlString;
|
|
41
|
+
icon?: IconID;
|
|
42
|
+
rightIcon?: IconID;
|
|
43
|
+
align?: 'center' | 'left' | 'right';
|
|
44
|
+
autoRepeat?: number;
|
|
45
|
+
menu?: MenuOrSep[] | MenuCallBack;
|
|
46
|
+
click?: EventCallback<EvClick>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Base button
|
|
50
|
+
*/
|
|
51
|
+
export declare class BaseButton<P extends ButtonProps = ButtonProps, E extends ButtonEventMap = ButtonEventMap> extends Component<P, E> {
|
|
52
|
+
constructor(props: P);
|
|
53
|
+
render(props: ButtonProps): void;
|
|
54
|
+
/**
|
|
55
|
+
* starts/stops the autorepeat
|
|
56
|
+
*/
|
|
57
|
+
private _startAutoRep;
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
protected _handleKeyDown(ev: KeyboardEvent): void;
|
|
62
|
+
/**
|
|
63
|
+
* called by the system on click event
|
|
64
|
+
*/
|
|
65
|
+
protected _handleClick(ev: MouseEvent): void;
|
|
66
|
+
/**
|
|
67
|
+
* sends a click to the observers
|
|
68
|
+
*/
|
|
69
|
+
protected _sendClick(): void;
|
|
70
|
+
/**
|
|
71
|
+
* change the button text
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* let btn = new Button( {
|
|
75
|
+
* text: 'hello'
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* btn.text = 'world';
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
set text(text: string | HtmlString);
|
|
82
|
+
get text(): string | HtmlString;
|
|
83
|
+
/**
|
|
84
|
+
* change the button icon
|
|
85
|
+
* todo: do nothing if no icon defined at startup
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* let btn = new Button( {
|
|
90
|
+
* text: 'hello',
|
|
91
|
+
* icon: 'close'
|
|
92
|
+
* });
|
|
93
|
+
* btn.setIcon( 'open' );
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
set icon(icon: IconID);
|
|
97
|
+
get icon(): IconID;
|
|
98
|
+
/**
|
|
99
|
+
* change the button right icon
|
|
100
|
+
* todo: do nothing if no icon defined at startup
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* let btn = new Button( {
|
|
105
|
+
* text: 'hello',
|
|
106
|
+
* icon: 'close'
|
|
107
|
+
* });
|
|
108
|
+
* btn.setIcon( 'open' );
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
set rightIcon(icon: IconID);
|
|
112
|
+
get rightIcon(): IconID;
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
set menu(items: MenuItem[]);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
*
|
|
120
|
+
*/
|
|
121
|
+
export declare class Button extends BaseButton<ButtonProps> {
|
|
122
|
+
}
|
|
123
|
+
interface ToggleButtonEventMap extends ButtonEventMap {
|
|
124
|
+
change: EvChange;
|
|
125
|
+
}
|
|
126
|
+
interface ToggleButtonProps extends ButtonProps<ToggleButtonEventMap> {
|
|
127
|
+
checked: boolean;
|
|
128
|
+
checkedIcon?: IconID;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
export declare class ToggleButton extends BaseButton<ToggleButtonProps, ToggleButtonEventMap> {
|
|
134
|
+
constructor(props: ToggleButtonProps);
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
*/
|
|
138
|
+
render(props: ToggleButtonProps): void;
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
*/
|
|
142
|
+
protected _sendClick(): void;
|
|
143
|
+
private _updateIcon;
|
|
144
|
+
}
|
|
145
|
+
export {};
|