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
package/src/menu.ts ADDED
@@ -0,0 +1,394 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file menu.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
+
26
+ import { CEventMap, Component, CProps } from './component'
27
+ import { EvClick, EventCallback } from './x4_events'
28
+
29
+ import { Popup, PopupProps } from './popup'
30
+ import { Icon, IconID } from './icon'
31
+ import { Label } from './label'
32
+ import { HLayout } from './layout'
33
+ import { isString, getMousePos } from './tools'
34
+
35
+ // ============================================================================
36
+ // [MENU]
37
+ // ============================================================================
38
+
39
+ export class MenuSeparator extends Component {
40
+ }
41
+
42
+ export class MenuTitle extends Label {
43
+ }
44
+
45
+
46
+ /**
47
+ * Standard Menu
48
+ */
49
+
50
+ export type MenuOrSep = MenuItem | MenuSeparator | MenuTitle;
51
+
52
+ export interface MenuProps extends PopupProps {
53
+ items?: MenuOrSep[];
54
+ }
55
+
56
+ export class Menu extends Popup<MenuProps>
57
+ {
58
+ private static watchCount: number = 0;
59
+ private static rootMenu: Menu = null;
60
+
61
+ protected m_subMenu: Menu;
62
+ protected m_opener: MenuItem;
63
+ protected m_virtual: boolean;
64
+ protected m_lock: number;
65
+
66
+ constructor(props: MenuProps, opener?: MenuItem) {
67
+ super(props);
68
+
69
+ this.addClass('@shadow');
70
+
71
+ this.m_opener = opener;
72
+ this.m_virtual = false;
73
+ this.m_lock = 0;
74
+
75
+ this.enableMask(false);
76
+ }
77
+
78
+ lock(yes: boolean) {
79
+ this.m_lock += yes ? 1 : -1;
80
+ }
81
+
82
+ setVirtual() {
83
+ this.m_virtual = true;
84
+ }
85
+
86
+ setSubMenu(menu: Menu) {
87
+ this.m_subMenu = menu;
88
+ }
89
+
90
+ hideSubMenu() {
91
+ if (this.m_subMenu) {
92
+ this.m_subMenu.m_opener._close();
93
+ this.m_subMenu.hide();
94
+ this.m_subMenu = null;
95
+ }
96
+ }
97
+
98
+ /** @ignore */
99
+ render(props: MenuProps) {
100
+ this.setContent(props.items);
101
+ }
102
+
103
+ /**
104
+ *
105
+ */
106
+
107
+ public show() {
108
+ if (!this.m_virtual) {
109
+ Menu._addMenu(this);
110
+ }
111
+
112
+ super.show();
113
+ }
114
+
115
+ /**
116
+ *
117
+ */
118
+
119
+ public close() {
120
+
121
+ if (!this.dom && !this.m_virtual) {
122
+ return;
123
+ }
124
+
125
+ if (this.m_opener) {
126
+ this.m_opener._close();
127
+ }
128
+
129
+ if (this.m_subMenu) {
130
+ this.m_subMenu.close();
131
+ this.m_subMenu = null;
132
+ }
133
+
134
+ super.close();
135
+ Menu._removeMenu();
136
+ }
137
+
138
+ /**
139
+ *
140
+ */
141
+
142
+ public clear() {
143
+ this.m_props.items = [];
144
+ }
145
+
146
+ /**
147
+ * @internal
148
+ */
149
+
150
+ public static _addMenu(menu) {
151
+ //console.log( 'addmenu' );
152
+ if (Menu.watchCount == 0) {
153
+ Menu.rootMenu = menu;
154
+ document.addEventListener('mousedown', Menu._mouseWatcher);
155
+ }
156
+
157
+ Menu.watchCount++;
158
+ }
159
+
160
+ public static _removeMenu() {
161
+ //console.log( 'removemenu' );
162
+ console.assert(Menu.watchCount > 0);
163
+ Menu.watchCount--;
164
+
165
+ if (Menu.watchCount == 0) {
166
+ document.removeEventListener('mousedown', Menu._mouseWatcher);
167
+ }
168
+ }
169
+
170
+ private static _mouseWatcher(ev: MouseEvent) {
171
+ if (ev.defaultPrevented) {
172
+ return;
173
+ }
174
+
175
+ let elOn = <HTMLElement>ev.target;
176
+
177
+ while (elOn) {
178
+ // is mouse on a menu
179
+ let mouseon = Component.getElement(elOn);
180
+ if (mouseon && (mouseon instanceof Menu /*|| elOn.$el instanceof Menubar*/)) {
181
+ return;
182
+ }
183
+
184
+ elOn = elOn.parentElement;
185
+ }
186
+
187
+ Menu._discardAll();
188
+ }
189
+
190
+ /**
191
+ * hide all the visible menus
192
+ */
193
+
194
+ public static _discardAll() {
195
+ if (Menu.rootMenu) {
196
+ Menu.rootMenu.close();
197
+ Menu.rootMenu = null;
198
+ }
199
+ }
200
+
201
+ public displayAt(ev: UIEvent ): void;
202
+ public displayAt(x: number, y?: number, align?: string, offset?: { x, y } ): void;
203
+ public displayAt( ...args ) {
204
+
205
+ if (!this.m_lock) {
206
+ Menu._discardAll();
207
+ }
208
+
209
+ let x, y, align, offset;
210
+
211
+ if( args.length==1 ) {
212
+ ({x,y} = getMousePos( args[0], true ));
213
+ }
214
+ else {
215
+ [x,y,align,offset] = args;
216
+ }
217
+
218
+ if( !align ) {
219
+ align = 'top left';
220
+ }
221
+
222
+ super.displayAt(x, y, align, offset);
223
+ }
224
+ }
225
+
226
+ /**
227
+ * MENU ITEM
228
+ */
229
+
230
+ interface MenuItemEventMap extends CEventMap {
231
+ click: EvClick;
232
+ }
233
+
234
+ export interface MenuItemProps extends CProps {
235
+ itemId?: any;
236
+ text?: string;
237
+ icon?: IconID; // pass -1 to avoid space for icon
238
+ items?: MenuOrSep[];
239
+ checked?: boolean;
240
+ cls?: string;
241
+
242
+ click?: EventCallback<EvClick>; // shortcut to events: { click ... }
243
+ }
244
+
245
+
246
+
247
+ export class MenuItem extends Component<MenuItemProps, MenuItemEventMap> {
248
+
249
+ private m_menu: Menu;
250
+ private m_isOpen: boolean;
251
+
252
+ constructor( text: string, click: EventCallback<EvClick> );
253
+ constructor( props: MenuItemProps);
254
+ constructor( a, b? ) {
255
+
256
+ if( isString(a) ) {
257
+ super( {
258
+ text: a,
259
+ click: b
260
+ });
261
+ }
262
+ else {
263
+ super(a);
264
+ }
265
+
266
+ this.mapPropEvents( this.m_props, 'click');
267
+
268
+ this.m_menu = null;
269
+ this.m_isOpen = false;
270
+
271
+ this.setDomEvent('mousedown', (e) => this._mousedown(e));
272
+ this.setDomEvent('click', (e) => this._click(e));
273
+ }
274
+
275
+ /** @ignore */
276
+ render(props: MenuItemProps) {
277
+
278
+ let icon = props.icon ?? 0x20;
279
+ let text = props.text;
280
+
281
+ if (props.checked !== undefined) {
282
+ icon = props.checked ? 'cls(far fa-check)' : 0; //todo: use stylesheet
283
+ }
284
+
285
+ if (this.isPopup) {
286
+ this.addClass('@popup-menu-item');
287
+ }
288
+
289
+ if (!text && !icon) {
290
+ this.addClass('@separator');
291
+ }
292
+
293
+ if (props.cls) {
294
+ this.addClass(props.cls);
295
+ }
296
+
297
+ this.setProp('tag', 'a');
298
+ //@bug: do not kill focus on click
299
+ // this.setAttribute( 'tabindex', '0' );
300
+
301
+ this.setContent([
302
+ icon < 0 ? null : new Icon({ icon }),
303
+ new Label({ flex: 1, text })
304
+ ]);
305
+ }
306
+
307
+ get id(): any {
308
+ return this.m_props.itemId;
309
+ }
310
+
311
+ get text(): string {
312
+ return this.m_props.text;
313
+ }
314
+
315
+ get isPopup(): boolean {
316
+ return !!this.m_props.items;
317
+ }
318
+
319
+ public _close() {
320
+ this.removeClass('@opened');
321
+ this.m_isOpen = false;
322
+ }
323
+
324
+ protected _click(ev: MouseEvent) {
325
+ if (!this.isPopup) {
326
+ this.emit('click', EvClick());
327
+ Menu._discardAll();
328
+ }
329
+ }
330
+
331
+ protected _mousedown(ev: MouseEvent) {
332
+
333
+ if (this.isPopup) {
334
+ if (!this.m_menu) {
335
+ this.m_menu = new Menu({ items: this.m_props.items }, this);
336
+ }
337
+
338
+ let doClose = this.m_isOpen;
339
+
340
+ // if parent menu has an opened sub menu, close it
341
+ let parent_menu = Component.getElement(this.dom, Menu);
342
+
343
+ if (parent_menu) {
344
+ parent_menu.hideSubMenu();
345
+ }
346
+
347
+ if (!doClose) {
348
+ if (parent_menu) {
349
+ parent_menu.setSubMenu(this.m_menu);
350
+ }
351
+
352
+ this.m_isOpen = true;
353
+
354
+ let rc = this.getBoundingRect();
355
+
356
+ this.m_menu.lock(true);
357
+ if (parent_menu) {
358
+ // standard menu
359
+ this.m_menu.displayAt(rc.right, rc.top);
360
+ }
361
+ else {
362
+ // menubar / menubutton
363
+ this.m_menu.displayAt(rc.left, rc.bottom);
364
+ }
365
+ this.m_menu.lock(false);
366
+ this.addClass('@opened');
367
+ }
368
+
369
+ ev.preventDefault();
370
+ }
371
+ }
372
+ }
373
+
374
+ /**
375
+ *
376
+ */
377
+
378
+ export class MenuBar extends HLayout {
379
+ protected m_items: MenuOrSep[];
380
+
381
+ constructor(props: MenuProps, opener?: MenuItem) {
382
+ super(props);
383
+
384
+ console.assert(false, 'not imp');
385
+
386
+ this.addClass('@shadow');
387
+ this.m_items = props.items;
388
+ }
389
+
390
+ /** @ignore */
391
+ render() {
392
+ this.setContent(this.m_items);
393
+ }
394
+ }
@@ -0,0 +1,199 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file messagebox.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
+
26
+ import { Dialog, DialogProps, EvBtnClick } from './dialog'
27
+ import { FormButtons } from './form'
28
+ import { asap, HtmlString, isHtmlString, isString } from './tools'
29
+ import { HLayout } from './layout'
30
+ import { Icon, IconID } from './icon'
31
+ import { Label } from './label'
32
+ import { TextEdit } from './textedit'
33
+
34
+ /**
35
+ * [ MESSAGEBOX ] -----------------------------------------------------------------
36
+ */
37
+
38
+ export interface MessageBoxProps extends DialogProps {
39
+ message: string | HtmlString; // always allow html
40
+ click: (button: string) => void;
41
+ }
42
+
43
+ export class MessageBox extends Dialog<MessageBoxProps>
44
+ {
45
+ m_label: Label;
46
+
47
+ constructor(props: MessageBoxProps) {
48
+
49
+ // remove overloaded elements from DialogBoxProps
50
+ let icon = props.icon ?? 'cls(far fa-circle-exclamation)'; // todo: resolve that
51
+ props.icon = undefined;
52
+
53
+ let buttons: FormButtons = props.buttons === undefined ? ['ok'] : props.buttons;
54
+ props.buttons = undefined;
55
+
56
+ super(props);
57
+
58
+ let msg = props.message;
59
+
60
+ this.form.updateContent(new HLayout({
61
+ style: { padding: 8 },
62
+ content: [
63
+ new Icon({ cls: 'icon', icon }),
64
+ this.m_label = new Label({ cls: 'text', text: msg, multiline: true })
65
+ ]
66
+ }), buttons);
67
+
68
+ this.on('btnClick', (ev: EvBtnClick) => {
69
+ // no prevent default -> always close the messagebox
70
+ if (!this.m_props.click) {
71
+ return;
72
+ }
73
+
74
+ asap(() => {
75
+ this.m_props.click( ev.button );
76
+ });
77
+ });
78
+ }
79
+
80
+ set text(txt: string | HtmlString) {
81
+ this.m_label.text = txt;
82
+ }
83
+
84
+
85
+ /**
86
+ * display a messagebox
87
+ */
88
+
89
+ static show(props: string | HtmlString | MessageBoxProps): MessageBox {
90
+
91
+ let msg;
92
+
93
+ if (isString(props) || isHtmlString(props)) {
94
+ msg = new MessageBox({ message: props, click: () => { } });
95
+ }
96
+ else {
97
+ msg = new MessageBox(props);
98
+ }
99
+
100
+ msg.show();
101
+ return msg;
102
+ }
103
+
104
+ /**
105
+ * display an alert message
106
+ */
107
+
108
+ static alert(text: string | HtmlString, title: string = null) {
109
+ new MessageBox({
110
+ cls: 'warning',
111
+ title,
112
+ message: text,
113
+ buttons: ['ok'],
114
+ click: () => { },
115
+ }).show();
116
+ }
117
+ }
118
+
119
+
120
+ // :: PrompDialogBox ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
121
+
122
+ export interface PromptBoxProps extends DialogProps {
123
+ message: string | HtmlString;
124
+ value?: string; // default input value
125
+ icon?: IconID;
126
+
127
+ click: (value: string) => void;
128
+ }
129
+
130
+ export class PromptDialogBox extends Dialog<PromptBoxProps> {
131
+
132
+ m_edit: TextEdit;
133
+
134
+ constructor(props: PromptBoxProps) {
135
+
136
+ // remove overloaded elements from DialogBoxProps
137
+ //let icon = props.icon; // ?? 'cls(far fa-comment-check)'; // todo: resolve that
138
+ //props.icon = undefined;
139
+ props.buttons = undefined;
140
+
141
+ props.width = props.width ?? 500;
142
+ super(props);
143
+
144
+ this.form.updateContent(
145
+ new HLayout({
146
+ cls: 'panel',
147
+ content: [
148
+ //icon ? new Icon({
149
+ // cls: 'icon',
150
+ // icon: icon
151
+ //}) : null,
152
+ this.m_edit = new TextEdit({
153
+ flex: 1,
154
+ autoFocus: true,
155
+ label: props.message,
156
+ value: props.value
157
+ }),
158
+ ]
159
+ }),
160
+ ['ok', 'cancel']
161
+ );
162
+
163
+ if (props.click) {
164
+ this.on('btnClick', (ev: EvBtnClick) => {
165
+
166
+ if (ev.button === 'ok') {
167
+ // no prevent default -> always close the messagebox
168
+ // asap to allow
169
+ asap(() => {
170
+ this.m_props.click(this.m_edit.value);
171
+ });
172
+ }
173
+ });
174
+ }
175
+ }
176
+
177
+ set text(txt: string | HtmlString) {
178
+ this.m_edit.label = txt;
179
+ }
180
+
181
+ /**
182
+ * display a messagebox
183
+ */
184
+
185
+ static show(props: string | HtmlString | PromptBoxProps, inputCallback?: (input: string) => void): PromptBoxProps {
186
+
187
+ let msg;
188
+
189
+ if (isString(props) || isHtmlString(props)) {
190
+ msg = new PromptDialogBox({ message: props, click: inputCallback });
191
+ }
192
+ else {
193
+ msg = new PromptDialogBox(props);
194
+ }
195
+
196
+ msg.show();
197
+ return msg;
198
+ }
199
+ }
package/src/panel.ts ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file panel.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
+
26
+ import { Component, CProps, ComponentContent, ContainerProps, ContainerEventMap } from './component'
27
+ import { VLayout, HLayout } from './layout'
28
+ import { Label } from './label'
29
+ import { Icon, IconID } from './icon';
30
+
31
+ // ============================================================================
32
+ // [PANEL]
33
+ // ============================================================================
34
+
35
+ export interface PanelProps<E extends ContainerEventMap = ContainerEventMap> extends ContainerProps<E> {
36
+ icon?: IconID;
37
+ title: string;
38
+ gadgets?: Component[];
39
+ sens?: 'horizontal' | 'vertical'; // vertical by default
40
+ }
41
+
42
+ export class Panel<T extends PanelProps = PanelProps, E extends ContainerEventMap = ContainerEventMap> extends VLayout<T,E> {
43
+ private m_ui_title: Label;
44
+ private m_ui_body: Component;
45
+
46
+ constructor( props: T ) {
47
+ super( props );
48
+
49
+ const sens = props?.sens=='horizontal' ? '@hlayout' : '@vlayout';
50
+
51
+ //todo: cannot be called twice do to content overload
52
+ this.m_ui_title = new Label({cls: 'title', text: this.m_props.title});
53
+ this.m_ui_body = new Component( { cls: 'body '+sens, content: this.m_props.content } );
54
+ }
55
+
56
+ /** @ignore */
57
+ render( ) {
58
+ const gadgets = this.m_props.gadgets ?? [];
59
+ const icon = this.m_props.icon ? new Icon( { icon: this.m_props.icon}) : null;
60
+
61
+ super.setContent( [
62
+ new HLayout( {
63
+ cls: 'title',
64
+ content: [
65
+ icon,
66
+ this.m_ui_title,
67
+ ...gadgets
68
+ ]
69
+ }),
70
+ this.m_ui_body
71
+ ] );
72
+ }
73
+
74
+ setContent( els: ComponentContent ) {
75
+ this.m_ui_body.setContent( els );
76
+ }
77
+
78
+ set title( text: string ) {
79
+ this.m_ui_title.text = text;
80
+ }
81
+ }