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,261 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file drawtext.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 { Point, roundTo } from './tools';
26
+ // adapted & modified from Canvas-txt:
27
+ // https://github.com/geongeorge/Canvas-Txt/blob/master/src/index.js
28
+ // Hair space character for precise justification
29
+ const SPACE = '\u200a';
30
+ const defStyle = {
31
+ align: 'center',
32
+ vAlign: 'middle',
33
+ fontSize: 14,
34
+ fontWeight: null,
35
+ fontStyle: '',
36
+ fontVariant: '',
37
+ fontFamily: 'Arial',
38
+ lineHeight: 0,
39
+ clip: true,
40
+ columns: 1,
41
+ columnGap: 0,
42
+ lineBreak: true,
43
+ };
44
+ export function drawText(ctx, input_Text, rc, drawStyle) {
45
+ if (rc.width <= 0 || rc.height <= 0) {
46
+ //width or height or font size cannot be 0
47
+ return;
48
+ }
49
+ //console.time( 'drawtext' );
50
+ drawStyle = { ...defStyle, ...drawStyle };
51
+ ctx.save();
52
+ if (drawStyle.clip) {
53
+ ctx.beginPath();
54
+ ctx.rect(rc.left, rc.top, rc.width, rc.height);
55
+ ctx.clip();
56
+ }
57
+ if (drawStyle.rotation) {
58
+ const center = new Point(rc.left + rc.width / 2, rc.top + rc.height / 2);
59
+ const rad = drawStyle.rotation / 180 * Math.PI;
60
+ ctx.translate(center.x, center.y);
61
+ ctx.rotate(rad);
62
+ ctx.translate(-center.x, -center.y);
63
+ //ctx.beginPath();
64
+ //ctx.rect( rc.left, rc.top, rc.width, rc.height );
65
+ //ctx.stroke( );
66
+ }
67
+ ctx.textBaseline = 'bottom';
68
+ // End points
69
+ let fontSize = roundTo(drawStyle.fontSize, 2) ?? 12;
70
+ //let style = `${drawStyle.fontStyle ?? ''} ${drawStyle.fontVariant ?? ''} ${drawStyle.fontWeight ?? ''} ${fontSize}px ${drawStyle.fontFamily ?? 'arial'}`;
71
+ let style = '';
72
+ if (drawStyle.fontStyle) {
73
+ style += drawStyle.fontStyle + ' ';
74
+ }
75
+ if (drawStyle.fontVariant) {
76
+ style += drawStyle.fontVariant + ' ';
77
+ }
78
+ if (drawStyle.fontWeight) {
79
+ style += drawStyle.fontWeight + ' ';
80
+ }
81
+ style += fontSize + 'px ';
82
+ let family = drawStyle.fontFamily ?? 'sans-serif';
83
+ if (family.indexOf('.') > 0) {
84
+ family = '"' + family + '"';
85
+ }
86
+ style += family;
87
+ ctx.font = style.trim();
88
+ let textarray = [];
89
+ let lines = input_Text.split('\n');
90
+ const columns = drawStyle.columns < 1 ? 1 : drawStyle.columns;
91
+ const gap = drawStyle.columnGap;
92
+ let col_width = (rc.width - gap * (columns - 1)) / columns;
93
+ let col_left = rc.left;
94
+ let hlimit = col_width;
95
+ if (!drawStyle.lineBreak) {
96
+ hlimit = 99999999;
97
+ }
98
+ const spaceW = _measureText(ctx, ' ');
99
+ lines.forEach((text) => {
100
+ let line = { width: 0, words: [], space: 0 };
101
+ // fit in width ?
102
+ let lwidth = _measureText(ctx, text);
103
+ if (lwidth < hlimit) {
104
+ line.width = lwidth;
105
+ line.words.push({ width: lwidth, text });
106
+ textarray.push(line);
107
+ }
108
+ // break line to fit in width
109
+ else {
110
+ // make word list & measure them
111
+ let twords = text.split(/\s/).filter(w => w !== '');
112
+ let words = twords.map(w => {
113
+ const wwidth = _measureText(ctx, w);
114
+ const word = {
115
+ width: wwidth,
116
+ text: w
117
+ };
118
+ return word;
119
+ });
120
+ // then compute lines
121
+ let n = 0;
122
+ let e = 0;
123
+ while (n < words.length) {
124
+ const word = words[n];
125
+ let test = line.width;
126
+ if (test) {
127
+ test += spaceW;
128
+ }
129
+ test += word.width;
130
+ //console.log( word, test, col_width );
131
+ if (test > col_width && e > 0) {
132
+ textarray.push(line);
133
+ // restart
134
+ e = 0;
135
+ lwidth = 0;
136
+ line = { width: 0, words: [], space: 0 };
137
+ }
138
+ else {
139
+ line.words.push(word);
140
+ line.width = test;
141
+ n++;
142
+ e++;
143
+ }
144
+ }
145
+ if (e) {
146
+ textarray.push(line);
147
+ line.last = true;
148
+ }
149
+ }
150
+ });
151
+ const textSize = _calcTextHeight(ctx, "Ag");
152
+ let lineHeight = (drawStyle.lineHeight ?? 1.3) * textSize; // * 1.2 = map to pdf
153
+ const nlines = textarray.length;
154
+ // calc vertical Align
155
+ let col_top = rc.top;
156
+ if (columns == 1) {
157
+ let fullHeight = lineHeight * nlines;
158
+ if (nlines == 1) {
159
+ lineHeight = textSize;
160
+ fullHeight = textSize;
161
+ }
162
+ if (drawStyle.vAlign === 'middle') {
163
+ col_top = rc.top + rc.height / 2 - fullHeight / 2;
164
+ col_top += lineHeight / 2;
165
+ ctx.textBaseline = 'middle';
166
+ }
167
+ else if (drawStyle.vAlign === 'bottom') {
168
+ if (fullHeight < rc.height) {
169
+ col_top = rc.top + rc.height - fullHeight + lineHeight;
170
+ }
171
+ }
172
+ else {
173
+ col_top = rc.top;
174
+ ctx.textBaseline = 'top';
175
+ }
176
+ }
177
+ else {
178
+ // always top, cannot justify multi-columns vertically
179
+ // todo: for now
180
+ col_top += textSize;
181
+ }
182
+ const justify = drawStyle.align == 'justify';
183
+ let column = columns;
184
+ let y = col_top;
185
+ let align = 0;
186
+ // faster test..
187
+ switch (drawStyle.align) {
188
+ case 'right':
189
+ align = 1;
190
+ break;
191
+ case 'center':
192
+ align = 2;
193
+ break;
194
+ }
195
+ //print all lines of text
196
+ let idx = 1, yy = 0;
197
+ textarray.some(line => {
198
+ //console.log( idx++, yy );
199
+ line.space = spaceW;
200
+ if (justify && !line.last) {
201
+ _justify(line, col_width, spaceW);
202
+ }
203
+ let x = col_left;
204
+ if (align == 1) {
205
+ x += col_width - line.width;
206
+ }
207
+ else if (align == 2) {
208
+ x += col_width / 2 - line.width / 2;
209
+ }
210
+ // ...debug
211
+ /*ctx.lineWidth = 1;
212
+ ctx.beginPath( );
213
+ ctx.moveTo( rc.left, y );
214
+ ctx.lineTo( rc.right, y );
215
+ ctx.strokeStyle = 'white';
216
+ ctx.stroke( );*/
217
+ line.words.forEach(w => {
218
+ /*ctx.beginPath( );
219
+ ctx.moveTo( x, y );
220
+ ctx.lineTo( x, y-40 );
221
+ ctx.strokeStyle = 'red';
222
+ ctx.stroke( );*/
223
+ /*ctx.beginPath( );
224
+ ctx.moveTo( x+w.width, y );
225
+ ctx.lineTo( x+w.width, y-40 );
226
+ ctx.strokeStyle = 'green';
227
+ ctx.stroke( );*/
228
+ ctx.fillText(w.text, x, y);
229
+ x += w.width + line.space;
230
+ });
231
+ y += lineHeight;
232
+ yy += lineHeight;
233
+ if (y > (rc.bottom + lineHeight)) {
234
+ y = col_top;
235
+ col_left += col_width + gap;
236
+ if (--column == 0) {
237
+ return true;
238
+ }
239
+ }
240
+ });
241
+ ctx.restore();
242
+ //console.timeEnd( 'drawtext' );
243
+ // todo autogrow + multi-columns
244
+ return { height: (textarray.length + 0.3) * lineHeight };
245
+ }
246
+ // Calculate Height of the font
247
+ function _calcTextHeight(ctx, text) {
248
+ const size = ctx.measureText(text);
249
+ return size.actualBoundingBoxAscent + size.actualBoundingBoxDescent;
250
+ }
251
+ function _measureText(ctx, text) {
252
+ return roundTo(ctx.measureText(text).width, 2);
253
+ }
254
+ function _justify(line, width, spaceW) {
255
+ let delta = (width - line.width) / (line.words.length - 1) + spaceW;
256
+ if (delta <= 0) {
257
+ return;
258
+ }
259
+ line.width = width;
260
+ line.space = delta;
261
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file fileupload.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 { CProps } from './component';
26
+ import { HLayout } from './layout';
27
+ export interface FileUploadProps extends CProps {
28
+ name: string;
29
+ value: string;
30
+ }
31
+ export declare class FileUpload extends HLayout<FileUploadProps> {
32
+ constructor(props: FileUploadProps);
33
+ clear(): void;
34
+ }
35
+ /**
36
+ *
37
+ */
38
+ export declare class ImageUpload extends FileUpload {
39
+ private m_path;
40
+ private m_ui_img;
41
+ private m_ui_input;
42
+ /** @ignore */
43
+ render(props: FileUploadProps): void;
44
+ clear(): void;
45
+ private _get_value;
46
+ private _set_value;
47
+ private _handleChange;
48
+ }
49
+ /**
50
+ * show openfile dialog
51
+ * @param extensions - string - ex: '.doc,.docx'
52
+ * @param cb - callback to call when user select a file
53
+ */
54
+ export declare function openFile(extensions: string, cb: (filename: FileList) => void, multiple?: boolean): void;
55
+ /**
56
+ * open saveas dialog
57
+ * @param defFileName - string - proposed filename
58
+ * @param cb - callback to call when user choose the destination
59
+ */
60
+ export declare function saveFile(defFileName: string, extensions: string, cb: (filename: File) => void): void;
@@ -0,0 +1,158 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file fileupload.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 } from './component';
26
+ import { HLayout } from './layout';
27
+ import { Input } from './input';
28
+ import { Image } from './image';
29
+ export class FileUpload extends HLayout {
30
+ constructor(props) {
31
+ super(props);
32
+ }
33
+ clear() {
34
+ this.m_props.value = '';
35
+ }
36
+ }
37
+ /**
38
+ *
39
+ */
40
+ export class ImageUpload extends FileUpload {
41
+ m_path;
42
+ m_ui_img;
43
+ m_ui_input;
44
+ /** @ignore */
45
+ render(props) {
46
+ let ename = "up" + this.uid;
47
+ this.setContent([
48
+ new Component({
49
+ tag: 'label', attrs: { for: ename }, content: [
50
+ this.m_ui_img = new Image({ src: this.m_props.value }),
51
+ ]
52
+ }),
53
+ this.m_ui_input = new Input({
54
+ cls: '@hidden',
55
+ id: ename,
56
+ type: 'file',
57
+ name: this.m_props.name,
58
+ value_hook: {
59
+ get: () => { return this._get_value(); },
60
+ set: (v) => { this._set_value(v); }
61
+ },
62
+ attrs: {
63
+ accept: 'image/*'
64
+ },
65
+ dom_events: {
66
+ change: (e) => { this._handleChange(e); }
67
+ }
68
+ }),
69
+ ]);
70
+ }
71
+ clear() {
72
+ super.clear();
73
+ this.m_ui_input.dom.value = '';
74
+ this.m_ui_img.setImage(null, false);
75
+ }
76
+ _get_value() {
77
+ return this.m_path;
78
+ }
79
+ _set_value(v) {
80
+ debugger;
81
+ }
82
+ _handleChange(e) {
83
+ let self = this;
84
+ function createThumbnail(file) {
85
+ let reader = new FileReader();
86
+ reader.addEventListener('load', (e) => {
87
+ self.m_ui_img.setImage(reader.result.toString());
88
+ });
89
+ reader.readAsDataURL(file);
90
+ }
91
+ const allowedTypes = ['png', 'jpg', 'jpeg', 'gif'];
92
+ let files = e.target.files, filesLen = files.length;
93
+ for (let i = 0; i < filesLen; i++) {
94
+ let imgType = files[i].name.split('.');
95
+ imgType = imgType[imgType.length - 1];
96
+ imgType = imgType.toLowerCase();
97
+ if (allowedTypes.indexOf(imgType) != -1) {
98
+ createThumbnail(files[i]);
99
+ this.m_path = files[i];
100
+ break;
101
+ }
102
+ }
103
+ }
104
+ }
105
+ let g_file_input = null;
106
+ function _createFileInput() {
107
+ if (!g_file_input) {
108
+ g_file_input = new Component({
109
+ tag: 'input',
110
+ style: {
111
+ display: 'none',
112
+ id: 'fileDialog',
113
+ },
114
+ attrs: {
115
+ type: 'file'
116
+ }
117
+ });
118
+ // ajoute un input type:file caché pour pouvoir choir un fichier a ouvrir
119
+ document.body.appendChild(g_file_input._build());
120
+ }
121
+ g_file_input.clearDomEvent('change');
122
+ return g_file_input;
123
+ }
124
+ /**
125
+ * show openfile dialog
126
+ * @param extensions - string - ex: '.doc,.docx'
127
+ * @param cb - callback to call when user select a file
128
+ */
129
+ export function openFile(extensions, cb, multiple = false) {
130
+ let fi = _createFileInput();
131
+ fi.removeAttribute('nwsaveas');
132
+ fi.setAttribute('accept', extensions);
133
+ fi.setAttribute('multiple', multiple);
134
+ // Set up the file chooser for the on change event
135
+ fi.setDomEvent("change", (evt) => {
136
+ // When we reach this point, it means the user has selected a file,
137
+ let files = fi.dom.files;
138
+ cb(files);
139
+ });
140
+ fi.dom.click();
141
+ }
142
+ /**
143
+ * open saveas dialog
144
+ * @param defFileName - string - proposed filename
145
+ * @param cb - callback to call when user choose the destination
146
+ */
147
+ export function saveFile(defFileName, extensions, cb) {
148
+ let fi = _createFileInput();
149
+ fi.setAttribute('nwsaveas', defFileName);
150
+ fi.setAttribute('accept', extensions);
151
+ // Set up the file chooser for the on change event
152
+ fi.setDomEvent("change", (evt) => {
153
+ // When we reach this point, it means the user has selected a file,
154
+ let files = fi.dom.files;
155
+ cb(files[0]);
156
+ });
157
+ fi.dom.click();
158
+ }
package/lib/form.d.ts ADDED
@@ -0,0 +1,122 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file form.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, Container, CProps, ContainerEventMap, ComponentContent } from './component';
26
+ import { HLayout, VLayout } from './layout';
27
+ import { Button } from './button';
28
+ import { RequestProps } from './request';
29
+ import { EventCallback } from './x4_events';
30
+ import { EvBtnClick } from './dialog';
31
+ export declare type FormBtn = 'ok' | 'cancel' | 'ignore' | 'yes' | 'no' | 'close' | 'save' | 'dontsave';
32
+ export declare type FormButtons = (FormBtn | Button | Component)[];
33
+ export interface FormEventMap extends ContainerEventMap {
34
+ btnClick?: EvBtnClick;
35
+ }
36
+ export interface FormProps extends CProps<FormEventMap> {
37
+ disableSuggestions?: boolean;
38
+ buttons?: FormButtons;
39
+ btnClick?: EventCallback<EvBtnClick>;
40
+ }
41
+ /**
42
+ *
43
+ */
44
+ export declare class Form extends VLayout<FormProps, FormEventMap> {
45
+ protected m_height: string | number;
46
+ protected m_container: Container;
47
+ protected m_buttons: HLayout;
48
+ protected m_dirty: boolean;
49
+ protected m_watchChanges: boolean;
50
+ constructor(props: FormProps);
51
+ /**
52
+ * returns the container object
53
+ */
54
+ get container(): Container;
55
+ /**
56
+ *
57
+ */
58
+ componentCreated(): void;
59
+ /**
60
+ *
61
+ */
62
+ updateContent(items: ComponentContent, buttons: FormButtons, height?: string | number): void;
63
+ /**
64
+ *
65
+ * @param els
66
+ * @param refreshAll
67
+ */
68
+ setContent(els: ComponentContent, refreshAll?: boolean): void;
69
+ /**
70
+ *
71
+ * @param buttons
72
+ */
73
+ setButtons(buttons: FormButtons): void;
74
+ /**
75
+ * enable a button by it's name
76
+ */
77
+ enableButton(name: string, enable?: boolean): void;
78
+ /**
79
+ * return a button by it's name
80
+ * @param name
81
+ */
82
+ getButton(name: string): Button;
83
+ /**
84
+ *
85
+ */
86
+ private _makeButtons;
87
+ /**
88
+ *
89
+ */
90
+ validate(): boolean;
91
+ /**
92
+ *
93
+ */
94
+ private _click;
95
+ /**
96
+ * replacement for HTMLFormElement.elements
97
+ * as chrome shows suggestions on form elements even if we ask him (not to do that)
98
+ * we removed <form> element.
99
+ * so we have to get children by hand
100
+ */
101
+ private _getElements;
102
+ /**
103
+ *
104
+ */
105
+ setValues(values: any): void;
106
+ /**
107
+ * values are not escaped
108
+ * checkbox set true when checked
109
+ * radio set value when checked
110
+ */
111
+ getValues(): any;
112
+ /**
113
+ * send the query to the desired handler
114
+ */
115
+ submit(cfg: RequestProps, cbvalidation: Function): false | Function;
116
+ /**
117
+ *
118
+ */
119
+ watchChanges(): void;
120
+ setDirty(set?: boolean): void;
121
+ isDirty(): boolean;
122
+ }