x4js 1.4.53 → 1.5.0
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/cjs/action.d.ts +57 -0
- package/lib/cjs/application.d.ts +104 -0
- package/lib/cjs/autocomplete.d.ts +58 -0
- package/lib/cjs/base_component.d.ts +88 -0
- package/lib/cjs/button.d.ts +151 -0
- package/lib/cjs/calendar.d.ts +81 -0
- package/lib/cjs/canvas.d.ts +92 -0
- package/lib/cjs/cardview.d.ts +87 -0
- package/lib/cjs/checkbox.d.ts +77 -0
- package/lib/cjs/color.d.ts +148 -0
- package/lib/cjs/colorpicker.d.ts +107 -0
- package/lib/cjs/combobox.d.ts +101 -0
- package/lib/cjs/component.d.ts +601 -0
- package/lib/cjs/datastore.d.ts +396 -0
- package/lib/cjs/dialog.d.ts +175 -0
- package/lib/cjs/dom_events.d.ts +302 -0
- package/lib/cjs/drag_manager.d.ts +54 -0
- package/lib/cjs/drawtext.d.ts +48 -0
- package/lib/cjs/fileupload.d.ts +64 -0
- package/lib/cjs/form.d.ts +126 -0
- package/lib/cjs/formatters.d.ts +35 -0
- package/lib/cjs/gridview.d.ts +175 -0
- package/lib/cjs/i18n.d.ts +73 -0
- package/lib/cjs/icon.d.ts +64 -0
- package/lib/cjs/image.d.ts +55 -0
- package/lib/cjs/index.d.ts +83 -0
- package/lib/cjs/input.d.ts +91 -0
- package/lib/cjs/label.d.ts +58 -0
- package/lib/cjs/layout.d.ts +87 -0
- package/lib/cjs/link.d.ts +50 -0
- package/lib/cjs/listview.d.ts +178 -0
- package/lib/cjs/md5.d.ts +61 -0
- package/lib/cjs/menu.d.ts +130 -0
- package/lib/cjs/messagebox.d.ts +68 -0
- package/lib/cjs/panel.d.ts +47 -0
- package/lib/cjs/popup.d.ts +75 -0
- package/lib/cjs/property_editor.d.ts +71 -0
- package/lib/cjs/radiobtn.d.ts +72 -0
- package/lib/cjs/rating.d.ts +53 -0
- package/lib/cjs/request.d.ts +52 -0
- package/lib/cjs/router.d.ts +42 -0
- package/lib/cjs/settings.d.ts +37 -0
- package/lib/cjs/sidebarview.d.ts +49 -0
- package/lib/cjs/spreadsheet.d.ts +218 -0
- package/lib/cjs/styles.d.ts +85 -0
- package/lib/cjs/svgcomponent.d.ts +191 -0
- package/lib/cjs/tabbar.d.ts +58 -0
- package/lib/cjs/tabview.d.ts +49 -0
- package/lib/cjs/textarea.d.ts +63 -0
- package/lib/cjs/textedit.d.ts +123 -0
- package/lib/cjs/toaster.d.ts +42 -0
- package/lib/cjs/tools.d.ts +394 -0
- package/lib/cjs/tooltips.d.ts +46 -0
- package/lib/cjs/treeview.d.ts +132 -0
- package/lib/cjs/version.d.ts +29 -0
- package/lib/cjs/x4dom.d.ts +49 -0
- package/lib/cjs/x4events.d.ts +269 -0
- package/lib/cjs/x4react.d.ts +41 -0
- package/lib/esm/action.d.ts +57 -0
- package/lib/esm/application.d.ts +104 -0
- package/lib/esm/autocomplete.d.ts +58 -0
- package/lib/esm/base_component.d.ts +88 -0
- package/lib/esm/button.d.ts +151 -0
- package/lib/esm/calendar.d.ts +81 -0
- package/lib/esm/canvas.d.ts +92 -0
- package/lib/esm/cardview.d.ts +87 -0
- package/lib/esm/checkbox.d.ts +77 -0
- package/lib/esm/color.d.ts +148 -0
- package/lib/esm/colorpicker.d.ts +107 -0
- package/lib/esm/combobox.d.ts +101 -0
- package/lib/esm/component.d.ts +601 -0
- package/lib/esm/datastore.d.ts +396 -0
- package/lib/esm/dialog.d.ts +175 -0
- package/lib/esm/dom_events.d.ts +302 -0
- package/lib/esm/drag_manager.d.ts +54 -0
- package/lib/esm/drawtext.d.ts +48 -0
- package/lib/esm/fileupload.d.ts +64 -0
- package/lib/esm/form.d.ts +126 -0
- package/lib/esm/formatters.d.ts +35 -0
- package/lib/esm/gridview.d.ts +175 -0
- package/lib/esm/i18n.d.ts +73 -0
- package/lib/esm/icon.d.ts +64 -0
- package/lib/esm/image.d.ts +55 -0
- package/lib/esm/index.d.ts +83 -0
- package/lib/esm/input.d.ts +91 -0
- package/lib/esm/label.d.ts +58 -0
- package/lib/esm/layout.d.ts +87 -0
- package/lib/esm/link.d.ts +50 -0
- package/lib/esm/listview.d.ts +178 -0
- package/lib/esm/md5.d.ts +61 -0
- package/lib/esm/menu.d.ts +130 -0
- package/lib/esm/messagebox.d.ts +68 -0
- package/lib/esm/panel.d.ts +47 -0
- package/lib/esm/popup.d.ts +75 -0
- package/lib/esm/property_editor.d.ts +71 -0
- package/lib/esm/radiobtn.d.ts +72 -0
- package/lib/esm/rating.d.ts +53 -0
- package/lib/esm/request.d.ts +52 -0
- package/lib/esm/router.d.ts +42 -0
- package/lib/esm/settings.d.ts +37 -0
- package/lib/esm/sidebarview.d.ts +49 -0
- package/lib/esm/spreadsheet.d.ts +218 -0
- package/lib/esm/styles.d.ts +85 -0
- package/lib/esm/svgcomponent.d.ts +191 -0
- package/lib/esm/tabbar.d.ts +58 -0
- package/lib/esm/tabview.d.ts +49 -0
- package/lib/esm/textarea.d.ts +63 -0
- package/lib/esm/textedit.d.ts +123 -0
- package/lib/esm/toaster.d.ts +42 -0
- package/lib/esm/tools.d.ts +394 -0
- package/lib/esm/tooltips.d.ts +46 -0
- package/lib/esm/treeview.d.ts +132 -0
- package/lib/esm/version.d.ts +29 -0
- package/lib/esm/x4dom.d.ts +49 -0
- package/lib/esm/x4events.d.ts +269 -0
- package/lib/esm/x4react.d.ts +41 -0
- package/lib/ts_src/MIT-license.md +14 -0
- package/lib/ts_src/action.ts +88 -0
- package/lib/ts_src/alpha.jpg +0 -0
- package/lib/ts_src/application.ts +251 -0
- package/lib/ts_src/autocomplete.ts +197 -0
- package/lib/ts_src/base64.ts +166 -0
- package/lib/ts_src/base_component.ts +152 -0
- package/lib/ts_src/button.ts +355 -0
- package/lib/ts_src/calendar.ts +322 -0
- package/lib/ts_src/canvas.ts +505 -0
- package/lib/ts_src/cardview.ts +227 -0
- package/lib/ts_src/checkbox.ts +187 -0
- package/lib/ts_src/color.ts +752 -0
- package/lib/ts_src/colorpicker.ts +1639 -0
- package/lib/ts_src/combobox.ts +362 -0
- package/lib/ts_src/component.ts +2329 -0
- package/lib/ts_src/datastore.ts +1322 -0
- package/lib/ts_src/dialog.ts +656 -0
- package/lib/ts_src/dom_events.ts +315 -0
- package/lib/ts_src/drag_manager.ts +199 -0
- package/lib/ts_src/drawtext.ts +355 -0
- package/lib/ts_src/fileupload.ts +213 -0
- package/lib/ts_src/form.ts +366 -0
- package/lib/ts_src/formatters.ts +105 -0
- package/lib/ts_src/gridview.ts +1185 -0
- package/lib/ts_src/i18n.ts +346 -0
- package/lib/ts_src/icon.ts +329 -0
- package/lib/ts_src/image.ts +204 -0
- package/lib/ts_src/index.ts +88 -0
- package/lib/ts_src/input.ts +249 -0
- package/lib/ts_src/label.ts +128 -0
- package/lib/ts_src/layout.ts +430 -0
- package/lib/ts_src/link.ts +86 -0
- package/lib/ts_src/listview.ts +762 -0
- package/lib/ts_src/md5.ts +438 -0
- package/lib/ts_src/menu.ts +425 -0
- package/lib/ts_src/messagebox.ts +203 -0
- package/lib/ts_src/panel.ts +86 -0
- package/lib/ts_src/popup.ts +494 -0
- package/lib/ts_src/property_editor.ts +337 -0
- package/lib/ts_src/radiobtn.ts +196 -0
- package/lib/ts_src/rating.ts +135 -0
- package/lib/ts_src/request.ts +300 -0
- package/lib/ts_src/router.ts +185 -0
- package/lib/ts_src/settings.ts +77 -0
- package/lib/ts_src/sidebarview.ts +103 -0
- package/lib/ts_src/spreadsheet.ts +1442 -0
- package/lib/ts_src/styles.ts +343 -0
- package/lib/ts_src/svgcomponent.ts +537 -0
- package/lib/ts_src/tabbar.ts +151 -0
- package/lib/ts_src/tabview.ts +110 -0
- package/lib/ts_src/textarea.ts +187 -0
- package/lib/ts_src/textedit.ts +544 -0
- package/lib/ts_src/toaster.ts +80 -0
- package/lib/ts_src/tools.ts +1468 -0
- package/lib/ts_src/tooltips.ts +191 -0
- package/lib/ts_src/treeview.ts +675 -0
- package/lib/ts_src/version.ts +30 -0
- package/lib/ts_src/x4.less +2236 -0
- package/lib/ts_src/x4dom.ts +57 -0
- package/lib/ts_src/x4events.ts +585 -0
- package/lib/ts_src/x4react.ts +90 -0
- package/package.json +3 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file autocomplete.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
|
+
|
|
30
|
+
import { ListViewItem, PopupListView } from "./listview";
|
|
31
|
+
import { TextEdit, TextEditProps } from './textedit';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
interface AutoCompleteProps extends TextEditProps {
|
|
38
|
+
enumValues: ( filter: string ) => string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
export class AutoComplete extends TextEdit<AutoCompleteProps> {
|
|
46
|
+
|
|
47
|
+
private m_popup: PopupListView;
|
|
48
|
+
private m_popvis: boolean;
|
|
49
|
+
private m_needval: boolean;
|
|
50
|
+
private m_lockpop: boolean;
|
|
51
|
+
|
|
52
|
+
constructor( props: AutoCompleteProps ) {
|
|
53
|
+
super( props );
|
|
54
|
+
|
|
55
|
+
this.setDomEvent( "input", ( ) => this._onChange( ) );
|
|
56
|
+
this.setDomEvent( "focusin", ( ) => this._onFocus( ) );
|
|
57
|
+
this.startTimer( "focus-check", 100, true, () => this._checkFocus() );
|
|
58
|
+
|
|
59
|
+
this.m_popvis = false;
|
|
60
|
+
this.m_needval = false;
|
|
61
|
+
this.m_lockpop = false;
|
|
62
|
+
|
|
63
|
+
this.setDomEvent( "keydown", e => this._onKey(e) );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_onKey( e: KeyboardEvent ) {
|
|
67
|
+
if( this.m_popvis ) {
|
|
68
|
+
if( e.key=="ArrowUp" || e.key=="ArrowDown" ) {
|
|
69
|
+
this.m_lockpop = true;
|
|
70
|
+
this.m_popup.handleKey( e );
|
|
71
|
+
this.m_lockpop = false;
|
|
72
|
+
|
|
73
|
+
e.preventDefault( );
|
|
74
|
+
e.stopPropagation( );
|
|
75
|
+
}
|
|
76
|
+
else if( e.key=="Escape" ) {
|
|
77
|
+
this._hidePopup( );
|
|
78
|
+
|
|
79
|
+
e.preventDefault( );
|
|
80
|
+
e.stopPropagation( );
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if( e.key=="ArrowDown" ) {
|
|
84
|
+
this._onChange( );
|
|
85
|
+
e.preventDefault( );
|
|
86
|
+
e.stopPropagation( );
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private _onChange( ) {
|
|
91
|
+
const items = this.m_props.enumValues( this.value );
|
|
92
|
+
this.showPopup( items );
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
componentDisposed( ) {
|
|
96
|
+
if( this.m_popup ) {
|
|
97
|
+
this._hidePopup( );
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
super.componentDisposed( );
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* display the popup
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
showPopup( items: string[] ) {
|
|
108
|
+
|
|
109
|
+
let props = this.m_props;
|
|
110
|
+
if (props.readOnly || this.hasClass("@disable") ) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// need creation ?
|
|
115
|
+
|
|
116
|
+
if( !this.m_popup ) {
|
|
117
|
+
let cstyle = this.getComputedStyle( );
|
|
118
|
+
let fontFamily = cstyle.value( 'fontFamily' );
|
|
119
|
+
let fontSize = cstyle.value( 'fontSize' );
|
|
120
|
+
|
|
121
|
+
// prepare the combo listview
|
|
122
|
+
this.m_popup = new PopupListView({
|
|
123
|
+
cls: '@combo-popup',
|
|
124
|
+
attrs: {
|
|
125
|
+
tabindex: 0
|
|
126
|
+
},
|
|
127
|
+
selectionChange: (e) => {
|
|
128
|
+
this.value = (e.selection as ListViewItem).id
|
|
129
|
+
if( !this.m_lockpop ) {
|
|
130
|
+
this._hidePopup( );
|
|
131
|
+
this.focus( );
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
style: {
|
|
135
|
+
fontFamily,
|
|
136
|
+
fontSize
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this.m_popup.items = items.map( c => ({ id: c, text: c }) );
|
|
142
|
+
|
|
143
|
+
let r1 = this.m_ui_input.getBoundingRect();
|
|
144
|
+
this.m_popup.setStyle({
|
|
145
|
+
minWidth: r1.width,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
this.m_popup.displayAt(r1.left, r1.bottom);
|
|
149
|
+
this.m_popvis = true;
|
|
150
|
+
|
|
151
|
+
//if( this.value!==undefined ) {
|
|
152
|
+
// this.m_popup.selection = this.value;
|
|
153
|
+
//}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected override _validate(value: string): boolean {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
override validate( ): boolean {
|
|
161
|
+
return super._validate( this.value );
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private _checkFocus( ) {
|
|
165
|
+
const focus = document.activeElement;
|
|
166
|
+
if( this.dom && this.dom.contains(focus) ) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if( this.m_popup && this.m_popup.dom && this.m_popup.dom.contains(focus) ) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
this._hidePopup( );
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private _hidePopup( ) {
|
|
178
|
+
|
|
179
|
+
if( this.m_popvis ) {
|
|
180
|
+
this.m_popup.close();
|
|
181
|
+
this.m_popvis = false;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if( this.m_needval ) {
|
|
185
|
+
this.validate( );
|
|
186
|
+
this.m_needval = false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private _onFocus( ) {
|
|
191
|
+
if( this.value.length==0 ) {
|
|
192
|
+
this._onChange( );
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.m_needval = true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file base64.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
|
+
|
|
30
|
+
const _alphabet: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
31
|
+
let _lookup: any = null;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export class Base64 {
|
|
35
|
+
lookup: any = null;
|
|
36
|
+
|
|
37
|
+
static encode(s: string | Uint8Array ) {
|
|
38
|
+
let buffer;
|
|
39
|
+
|
|
40
|
+
if( s instanceof Uint8Array ) {
|
|
41
|
+
buffer = []
|
|
42
|
+
s.forEach( (v) => {
|
|
43
|
+
buffer.push( v );
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
buffer = Base64._toUtf8(s);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let position = -1;
|
|
51
|
+
let len = buffer.length;
|
|
52
|
+
let nan1, nan2;
|
|
53
|
+
let enc = [, , ,];
|
|
54
|
+
|
|
55
|
+
let result = '';
|
|
56
|
+
while (++position < len) {
|
|
57
|
+
nan1 = buffer[position + 1], nan2 = buffer[position + 2];
|
|
58
|
+
enc[0] = buffer[position] >> 2;
|
|
59
|
+
enc[1] = ((buffer[position] & 3) << 4) | (buffer[++position] >> 4);
|
|
60
|
+
|
|
61
|
+
if (isNaN(nan1)) {
|
|
62
|
+
enc[2] = enc[3] = 64;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
enc[2] = ((buffer[position] & 15) << 2) | (buffer[++position] >> 6);
|
|
66
|
+
enc[3] = (isNaN(nan2)) ? 64 : buffer[position] & 63;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
result += _alphabet[enc[0]] + _alphabet[enc[1]] + _alphabet[enc[2]] + _alphabet[enc[3]];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static decode(s: string) {
|
|
76
|
+
let buffer = Base64._fromUtf8(s);
|
|
77
|
+
|
|
78
|
+
let position = 0;
|
|
79
|
+
let len = buffer.length;
|
|
80
|
+
|
|
81
|
+
let result = '';
|
|
82
|
+
while (position < len) {
|
|
83
|
+
if (buffer[position] < 128) {
|
|
84
|
+
result += String.fromCharCode(buffer[position++]);
|
|
85
|
+
}
|
|
86
|
+
else if (buffer[position] > 191 && buffer[position] < 224) {
|
|
87
|
+
result += String.fromCharCode(((buffer[position++] & 31) << 6) | (buffer[position++] & 63));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
result += String.fromCharCode(((buffer[position++] & 15) << 12) | ((buffer[position++] & 63) << 6) | (buffer[position++] & 63));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private static _toUtf8(s) {
|
|
98
|
+
let position = -1;
|
|
99
|
+
let len = s.length;
|
|
100
|
+
|
|
101
|
+
let chr;
|
|
102
|
+
let buffer = [];
|
|
103
|
+
|
|
104
|
+
if (/^[\x00-\x7f]*$/.test(s)) {
|
|
105
|
+
while (++position < len) {
|
|
106
|
+
buffer.push(s.charCodeAt(position));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
while (++position < len) {
|
|
111
|
+
chr = s.charCodeAt(position);
|
|
112
|
+
if (chr < 128) {
|
|
113
|
+
buffer.push(chr);
|
|
114
|
+
}
|
|
115
|
+
else if (chr < 2048) {
|
|
116
|
+
buffer.push((chr >> 6) | 192, (chr & 63) | 128);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
buffer.push((chr >> 12) | 224, ((chr >> 6) & 63) | 128, (chr & 63) | 128);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return buffer;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private static _fromUtf8(s) {
|
|
128
|
+
let position = -1;
|
|
129
|
+
let len;
|
|
130
|
+
let buffer = [];
|
|
131
|
+
let enc = [, , ,];
|
|
132
|
+
|
|
133
|
+
if (!_lookup) {
|
|
134
|
+
len = _alphabet.length;
|
|
135
|
+
_lookup = {};
|
|
136
|
+
while (++position < len) {
|
|
137
|
+
_lookup[_alphabet[position]] = position;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
position = -1;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
len = s.length;
|
|
144
|
+
while (position < len) {
|
|
145
|
+
enc[0] = _lookup[s.charAt(++position)];
|
|
146
|
+
enc[1] = _lookup[s.charAt(++position)];
|
|
147
|
+
buffer.push((enc[0] << 2) | (enc[1] >> 4));
|
|
148
|
+
|
|
149
|
+
enc[2] = _lookup[s.charAt(++position)];
|
|
150
|
+
if (enc[2] == 64) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
buffer.push(((enc[1] & 15) << 4) | (enc[2] >> 2));
|
|
155
|
+
enc[3] = _lookup[s.charAt(++position)];
|
|
156
|
+
|
|
157
|
+
if (enc[3] == 64) {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
buffer.push(((enc[2] & 3) << 6) | enc[3]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return buffer;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file base_component.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
|
+
**/
|
|
30
|
+
|
|
31
|
+
import { EventMap, MapEvents, EventSource, EvTimer } from './x4events';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Timer Callback
|
|
35
|
+
* @see EvTimer, startTimer, stopTimer
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
interface TimerCallback {
|
|
39
|
+
(name: string, time: number): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* BaseComponent EventMap
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
export interface BaseComponentEventMap extends EventMap {
|
|
47
|
+
timer: EvTimer,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* BaseCompoment Properties
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
export interface BaseComponentProps<T = BaseComponentEventMap> {
|
|
55
|
+
events?: MapEvents<T>; // basic component event map in base interface, should specialised in derived interfaces
|
|
56
|
+
[key: string]: any; // added index signature to solve "Type 'X' has no properties with type 'Y'"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* BaseComponent class
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
export class BaseComponent< P extends BaseComponentProps<BaseComponentEventMap>, E extends BaseComponentEventMap >
|
|
64
|
+
extends EventSource< E > {
|
|
65
|
+
|
|
66
|
+
protected m_props: P;
|
|
67
|
+
#m_timers: Map<string, Function>;
|
|
68
|
+
|
|
69
|
+
constructor(props: P) {
|
|
70
|
+
super();
|
|
71
|
+
|
|
72
|
+
//this.m_props = { ...props };
|
|
73
|
+
this.m_props = props;
|
|
74
|
+
|
|
75
|
+
if (props.events) {
|
|
76
|
+
this.listen(props.events as EventMap);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* start a new timer
|
|
82
|
+
* @param name timer name
|
|
83
|
+
* @param timeout time out in ms
|
|
84
|
+
* @param repeat if true this is an auto repeat timer
|
|
85
|
+
* @param callback if !null, the callback to call else a EvTimer is fired
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
startTimer(name: string, timeout: number, repeat = true, callback: TimerCallback = null) {
|
|
89
|
+
if (!this.#m_timers) {
|
|
90
|
+
this.#m_timers = new Map();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.stopTimer(name);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const id = (repeat ? setInterval : setTimeout)((tm: number) => {
|
|
97
|
+
if (callback) {
|
|
98
|
+
callback(name, tm);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.emit('timer', EvTimer( name, tm ));
|
|
102
|
+
}
|
|
103
|
+
}, timeout);
|
|
104
|
+
|
|
105
|
+
this.#m_timers.set(name, () => { (repeat ? clearInterval : clearTimeout)(id) });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* stop the given timer
|
|
110
|
+
* @param name
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
stopTimer(name: string) {
|
|
114
|
+
const clear = this.#m_timers.get(name);
|
|
115
|
+
if (clear) { clear(); }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* stop all timers
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
disposeTimers( ) {
|
|
123
|
+
this.#m_timers?.forEach( v => v() );
|
|
124
|
+
this.#m_timers = undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
* @param callback
|
|
130
|
+
* @param timeout
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
singleShot( callback: TimerCallback, timeout = 0 ) {
|
|
134
|
+
setTimeout( callback, timeout );
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
*
|
|
139
|
+
* @param props
|
|
140
|
+
* @param elements
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
public mapPropEvents<N extends keyof E>(props: P, ...elements: N[] ) {
|
|
144
|
+
elements.forEach( name => {
|
|
145
|
+
const n = name as string;
|
|
146
|
+
if (props[n]) {
|
|
147
|
+
this._on(n, props[n]);
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|