x4js 1.4.2

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.
Files changed (176) hide show
  1. package/lib/application.d.ts +95 -0
  2. package/lib/application.js +137 -0
  3. package/lib/base64.d.ts +31 -0
  4. package/lib/base64.js +135 -0
  5. package/lib/base_component.d.ts +64 -0
  6. package/lib/base_component.js +77 -0
  7. package/lib/button.d.ts +145 -0
  8. package/lib/button.js +235 -0
  9. package/lib/calendar.d.ts +77 -0
  10. package/lib/calendar.js +236 -0
  11. package/lib/canvas.d.ts +88 -0
  12. package/lib/canvas.js +354 -0
  13. package/lib/cardview.d.ts +83 -0
  14. package/lib/cardview.js +152 -0
  15. package/lib/checkbox.d.ts +72 -0
  16. package/lib/checkbox.js +126 -0
  17. package/lib/color.d.ts +144 -0
  18. package/lib/color.js +584 -0
  19. package/lib/colorpicker.d.ts +98 -0
  20. package/lib/colorpicker.js +1457 -0
  21. package/lib/combobox.d.ts +97 -0
  22. package/lib/combobox.js +246 -0
  23. package/lib/component.d.ts +572 -0
  24. package/lib/component.js +1712 -0
  25. package/lib/datastore.d.ts +392 -0
  26. package/lib/datastore.js +986 -0
  27. package/lib/dialog.d.ts +171 -0
  28. package/lib/dialog.js +468 -0
  29. package/lib/dom_events.d.ts +284 -0
  30. package/lib/dom_events.js +13 -0
  31. package/lib/drag_manager.d.ts +26 -0
  32. package/lib/drag_manager.js +118 -0
  33. package/lib/drawtext.d.ts +43 -0
  34. package/lib/drawtext.js +261 -0
  35. package/lib/fileupload.d.ts +60 -0
  36. package/lib/fileupload.js +158 -0
  37. package/lib/form.d.ts +122 -0
  38. package/lib/form.js +293 -0
  39. package/lib/formatters.d.ts +31 -0
  40. package/lib/formatters.js +75 -0
  41. package/lib/gridview.d.ts +171 -0
  42. package/lib/gridview.js +786 -0
  43. package/lib/hosts/host.d.ts +44 -0
  44. package/lib/hosts/host.js +69 -0
  45. package/lib/i18n.d.ts +67 -0
  46. package/lib/i18n.js +169 -0
  47. package/lib/icon.d.ts +56 -0
  48. package/lib/icon.js +173 -0
  49. package/lib/image.d.ts +51 -0
  50. package/lib/image.js +149 -0
  51. package/lib/index.js +1 -0
  52. package/lib/input.d.ts +86 -0
  53. package/lib/input.js +172 -0
  54. package/lib/label.d.ts +54 -0
  55. package/lib/label.js +86 -0
  56. package/lib/layout.d.ts +77 -0
  57. package/lib/layout.js +261 -0
  58. package/lib/link.d.ts +46 -0
  59. package/lib/link.js +55 -0
  60. package/lib/listview.d.ts +173 -0
  61. package/lib/listview.js +532 -0
  62. package/lib/md5.d.ts +56 -0
  63. package/lib/md5.js +397 -0
  64. package/lib/menu.d.ts +122 -0
  65. package/lib/menu.js +276 -0
  66. package/lib/messagebox.d.ts +64 -0
  67. package/lib/messagebox.js +141 -0
  68. package/lib/panel.d.ts +42 -0
  69. package/lib/panel.js +61 -0
  70. package/lib/popup.d.ts +71 -0
  71. package/lib/popup.js +373 -0
  72. package/lib/property_editor.d.ts +67 -0
  73. package/lib/property_editor.js +247 -0
  74. package/lib/radiobtn.d.ts +68 -0
  75. package/lib/radiobtn.js +131 -0
  76. package/lib/rating.d.ts +49 -0
  77. package/lib/rating.js +93 -0
  78. package/lib/request.d.ts +48 -0
  79. package/lib/request.js +220 -0
  80. package/lib/router.d.ts +13 -0
  81. package/lib/router.js +27 -0
  82. package/lib/settings.d.ts +33 -0
  83. package/lib/settings.js +63 -0
  84. package/lib/sidebarview.d.ts +44 -0
  85. package/lib/sidebarview.js +73 -0
  86. package/lib/smartedit.d.ts +103 -0
  87. package/lib/smartedit.js +381 -0
  88. package/lib/spreadsheet.d.ts +214 -0
  89. package/lib/spreadsheet.js +1073 -0
  90. package/lib/styles.d.ts +81 -0
  91. package/lib/styles.js +262 -0
  92. package/lib/svgcomponent.d.ts +165 -0
  93. package/lib/svgcomponent.js +350 -0
  94. package/lib/tabbar.d.ts +41 -0
  95. package/lib/tabbar.js +66 -0
  96. package/lib/tabview.d.ts +45 -0
  97. package/lib/tabview.js +79 -0
  98. package/lib/textarea.d.ts +59 -0
  99. package/lib/textarea.js +119 -0
  100. package/lib/textedit.d.ts +118 -0
  101. package/lib/textedit.js +406 -0
  102. package/lib/texthiliter.d.ts +56 -0
  103. package/lib/texthiliter.js +219 -0
  104. package/lib/toaster.d.ts +38 -0
  105. package/lib/toaster.js +58 -0
  106. package/lib/tools.d.ts +382 -0
  107. package/lib/tools.js +1096 -0
  108. package/lib/tooltips.d.ts +42 -0
  109. package/lib/tooltips.js +148 -0
  110. package/lib/treeview.d.ts +128 -0
  111. package/lib/treeview.js +490 -0
  112. package/lib/x4_events.d.ts +253 -0
  113. package/lib/x4_events.js +363 -0
  114. package/package.json +21 -0
  115. package/src/README.md +2 -0
  116. package/src/application.ts +191 -0
  117. package/src/base64.ts +162 -0
  118. package/src/base_component.ts +118 -0
  119. package/src/button.ts +327 -0
  120. package/src/calendar.ts +312 -0
  121. package/src/canvas.ts +501 -0
  122. package/src/cardview.ts +220 -0
  123. package/src/checkbox.ts +178 -0
  124. package/src/color.ts +748 -0
  125. package/src/colorpicker.ts +1618 -0
  126. package/src/combobox.ts +348 -0
  127. package/src/component.ts +2330 -0
  128. package/src/datastore.ts +1318 -0
  129. package/src/dialog.ts +631 -0
  130. package/src/dom_events.ts +297 -0
  131. package/src/drag_manager.ts +168 -0
  132. package/src/drawtext.ts +342 -0
  133. package/src/fileupload.ts +208 -0
  134. package/src/form.ts +362 -0
  135. package/src/formatters.ts +96 -0
  136. package/src/gridview.ts +1051 -0
  137. package/src/hosts/electron.ts +161 -0
  138. package/src/hosts/host.ts +100 -0
  139. package/src/hosts/nwjs.ts +141 -0
  140. package/src/hosts/nwjs_types.ts +339 -0
  141. package/src/i18n.ts +205 -0
  142. package/src/icon.ts +237 -0
  143. package/src/image.ts +198 -0
  144. package/src/input.ts +236 -0
  145. package/src/label.ts +124 -0
  146. package/src/layout.ts +366 -0
  147. package/src/link.ts +82 -0
  148. package/src/listview.ts +749 -0
  149. package/src/md5.ts +432 -0
  150. package/src/menu.ts +394 -0
  151. package/src/messagebox.ts +199 -0
  152. package/src/panel.ts +81 -0
  153. package/src/popup.ts +488 -0
  154. package/src/property_editor.ts +333 -0
  155. package/src/radiobtn.ts +190 -0
  156. package/src/rating.ts +131 -0
  157. package/src/request.ts +296 -0
  158. package/src/router.ts +43 -0
  159. package/src/settings.ts +75 -0
  160. package/src/sidebarview.ts +97 -0
  161. package/src/smartedit.ts +532 -0
  162. package/src/spreadsheet.ts +1423 -0
  163. package/src/styles.ts +332 -0
  164. package/src/svgcomponent.ts +440 -0
  165. package/src/tabbar.ts +105 -0
  166. package/src/tabview.ts +106 -0
  167. package/src/textarea.ts +183 -0
  168. package/src/textedit.ts +535 -0
  169. package/src/texthiliter.ts +284 -0
  170. package/src/toaster.ts +76 -0
  171. package/src/tools.ts +1391 -0
  172. package/src/tooltips.ts +185 -0
  173. package/src/treeview.ts +670 -0
  174. package/src/x4.less +1940 -0
  175. package/src/x4_events.ts +558 -0
  176. package/tsconfig.json +14 -0
@@ -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,137 @@
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 { BaseComponent } from './base_component';
26
+ import { Settings } from './settings';
27
+ import { deferCall } from './tools';
28
+ /**
29
+ * Represents an x4 application, which is typically a single page app.
30
+ * You should inherit Application to define yours.
31
+ * Application derives from BaseComponent so you can use that to implement a global messaging system.
32
+ * @example ```ts
33
+ *
34
+ * // in yout main caode
35
+ * let app = new Application( );
36
+ *
37
+ * app.events.close.on( ( ev ) => {
38
+ * ... do something
39
+ * });
40
+ *
41
+ * // somewhere else in the source
42
+ * function xxx( ) {
43
+ * let app = Application.instance( );
44
+ * app.events.close.emit( new Events.close() );
45
+ * }
46
+ */
47
+ export class Application extends BaseComponent {
48
+ static self = null;
49
+ /**
50
+ * the application singleton
51
+ */
52
+ static instance() {
53
+ return Application.self;
54
+ }
55
+ m_mainView;
56
+ m_app_name;
57
+ m_app_version;
58
+ m_app_uid;
59
+ m_local_storage;
60
+ m_user_data;
61
+ constructor(props) {
62
+ console.assert(Application.self === null, 'application is a singleton');
63
+ super(props);
64
+ this.m_app_name = props.app_name ?? 'application';
65
+ this.m_app_version = props.app_version ?? '1.0';
66
+ this.m_app_uid = props.app_uid ?? 'application';
67
+ let settings_name = `${this.m_app_name}.${this.m_app_version}.settings`;
68
+ this.m_local_storage = new Settings(settings_name);
69
+ this.m_user_data = {};
70
+ Application.self = this;
71
+ if ('onload' in globalThis) {
72
+ globalThis.addEventListener('load', () => {
73
+ this.ApplicationCreated();
74
+ });
75
+ }
76
+ else {
77
+ this.ApplicationCreated();
78
+ }
79
+ }
80
+ ApplicationCreated() {
81
+ }
82
+ get app_name() {
83
+ return this.m_app_name;
84
+ }
85
+ get app_uid() {
86
+ return this.m_app_uid;
87
+ }
88
+ get app_version() {
89
+ return this.m_app_version;
90
+ }
91
+ get local_storage() {
92
+ return this.m_local_storage;
93
+ }
94
+ get user_data() {
95
+ return this.m_user_data;
96
+ }
97
+ get history() {
98
+ //if( !this.m_history ) {
99
+ // this.m_history = new NavigationHistory( );
100
+ //}
101
+ //
102
+ //return this.m_history;
103
+ debugger;
104
+ return null;
105
+ }
106
+ /**
107
+ * define the application root object (MainView)
108
+ * @example ```ts
109
+ *
110
+ * let myApp = new Application( ... );
111
+ * let mainView = new VLayout( ... );
112
+ * myApp.setMainView( mainView );
113
+ */
114
+ set mainView(root) {
115
+ this.m_mainView = root;
116
+ deferCall(() => {
117
+ document.body.appendChild(root._build());
118
+ });
119
+ }
120
+ get mainView() {
121
+ return this.m_mainView;
122
+ }
123
+ setTitle(title) {
124
+ document.title = this.m_app_name + ' > ' + title;
125
+ }
126
+ disableZoomWheel() {
127
+ window.addEventListener('wheel', function (ev) {
128
+ if (ev.ctrlKey) {
129
+ ev.preventDefault();
130
+ //ev.stopPropagation( );
131
+ }
132
+ }, { passive: false, capture: true });
133
+ }
134
+ enterModal(enter) {
135
+ }
136
+ }
137
+ ;
@@ -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,135 @@
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
+ const _alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
26
+ let _lookup = null;
27
+ export class Base64 {
28
+ lookup = null;
29
+ static encode(s) {
30
+ let buffer;
31
+ if (s instanceof Uint8Array) {
32
+ buffer = [];
33
+ s.forEach((v) => {
34
+ buffer.push(v);
35
+ });
36
+ }
37
+ else {
38
+ buffer = Base64._toUtf8(s);
39
+ }
40
+ let position = -1;
41
+ let len = buffer.length;
42
+ let nan1, nan2;
43
+ let enc = [, , ,];
44
+ let result = '';
45
+ while (++position < len) {
46
+ nan1 = buffer[position + 1], nan2 = buffer[position + 2];
47
+ enc[0] = buffer[position] >> 2;
48
+ enc[1] = ((buffer[position] & 3) << 4) | (buffer[++position] >> 4);
49
+ if (isNaN(nan1)) {
50
+ enc[2] = enc[3] = 64;
51
+ }
52
+ else {
53
+ enc[2] = ((buffer[position] & 15) << 2) | (buffer[++position] >> 6);
54
+ enc[3] = (isNaN(nan2)) ? 64 : buffer[position] & 63;
55
+ }
56
+ result += _alphabet[enc[0]] + _alphabet[enc[1]] + _alphabet[enc[2]] + _alphabet[enc[3]];
57
+ }
58
+ return result;
59
+ }
60
+ static decode(s) {
61
+ let buffer = Base64._fromUtf8(s);
62
+ let position = 0;
63
+ let len = buffer.length;
64
+ let result = '';
65
+ while (position < len) {
66
+ if (buffer[position] < 128) {
67
+ result += String.fromCharCode(buffer[position++]);
68
+ }
69
+ else if (buffer[position] > 191 && buffer[position] < 224) {
70
+ result += String.fromCharCode(((buffer[position++] & 31) << 6) | (buffer[position++] & 63));
71
+ }
72
+ else {
73
+ result += String.fromCharCode(((buffer[position++] & 15) << 12) | ((buffer[position++] & 63) << 6) | (buffer[position++] & 63));
74
+ }
75
+ }
76
+ return result;
77
+ }
78
+ static _toUtf8(s) {
79
+ let position = -1;
80
+ let len = s.length;
81
+ let chr;
82
+ let buffer = [];
83
+ if (/^[\x00-\x7f]*$/.test(s)) {
84
+ while (++position < len) {
85
+ buffer.push(s.charCodeAt(position));
86
+ }
87
+ }
88
+ else {
89
+ while (++position < len) {
90
+ chr = s.charCodeAt(position);
91
+ if (chr < 128) {
92
+ buffer.push(chr);
93
+ }
94
+ else if (chr < 2048) {
95
+ buffer.push((chr >> 6) | 192, (chr & 63) | 128);
96
+ }
97
+ else {
98
+ buffer.push((chr >> 12) | 224, ((chr >> 6) & 63) | 128, (chr & 63) | 128);
99
+ }
100
+ }
101
+ }
102
+ return buffer;
103
+ }
104
+ static _fromUtf8(s) {
105
+ let position = -1;
106
+ let len;
107
+ let buffer = [];
108
+ let enc = [, , ,];
109
+ if (!_lookup) {
110
+ len = _alphabet.length;
111
+ _lookup = {};
112
+ while (++position < len) {
113
+ _lookup[_alphabet[position]] = position;
114
+ }
115
+ position = -1;
116
+ }
117
+ len = s.length;
118
+ while (position < len) {
119
+ enc[0] = _lookup[s.charAt(++position)];
120
+ enc[1] = _lookup[s.charAt(++position)];
121
+ buffer.push((enc[0] << 2) | (enc[1] >> 4));
122
+ enc[2] = _lookup[s.charAt(++position)];
123
+ if (enc[2] == 64) {
124
+ break;
125
+ }
126
+ buffer.push(((enc[1] & 15) << 4) | (enc[2] >> 2));
127
+ enc[3] = _lookup[s.charAt(++position)];
128
+ if (enc[3] == 64) {
129
+ break;
130
+ }
131
+ buffer.push(((enc[2] & 3) << 6) | enc[3]);
132
+ }
133
+ return buffer;
134
+ }
135
+ }
@@ -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,77 @@
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 { EventSource, EvTimer } from './x4_events';
14
+ /**
15
+ * BaseComponent class
16
+ */
17
+ export class BaseComponent extends EventSource {
18
+ m_props;
19
+ #m_timers;
20
+ constructor(props) {
21
+ super();
22
+ //this.m_props = { ...props };
23
+ this.m_props = props;
24
+ if (props.events) {
25
+ this.listen(props.events);
26
+ }
27
+ }
28
+ /**
29
+ * start a new timer
30
+ * @param name timer name
31
+ * @param timeout time out in ms
32
+ * @param repeat if true this is an auto repeat timer
33
+ * @param callback if !null, the callback to call else a EvTimer is fired
34
+ */
35
+ startTimer(name, timeout, repeat = true, callback = null) {
36
+ if (!this.#m_timers) {
37
+ this.#m_timers = new Map();
38
+ }
39
+ else {
40
+ this.stopTimer(name);
41
+ }
42
+ const id = (repeat ? setInterval : setTimeout)((tm) => {
43
+ if (callback) {
44
+ callback(name, tm);
45
+ }
46
+ else {
47
+ this.emit('timer', EvTimer(name, tm));
48
+ }
49
+ }, timeout);
50
+ this.#m_timers.set(name, () => { (repeat ? clearInterval : clearTimeout)(id); });
51
+ }
52
+ /**
53
+ * stop the given timer
54
+ * @param name
55
+ */
56
+ stopTimer(name) {
57
+ const clear = this.#m_timers.get(name);
58
+ if (clear) {
59
+ clear();
60
+ }
61
+ }
62
+ /**
63
+ * stop all timers
64
+ */
65
+ disposeTimers() {
66
+ this.#m_timers?.forEach(v => v());
67
+ this.#m_timers = undefined;
68
+ }
69
+ /**
70
+ *
71
+ * @param callback
72
+ * @param timeout
73
+ */
74
+ singleShot(callback, timeout = 0) {
75
+ setTimeout(callback, timeout);
76
+ }
77
+ }
@@ -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 {};