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/lib/canvas.js ADDED
@@ -0,0 +1,354 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file canvas.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 { BasicEvent } from './x4_events';
27
+ function EvPaint(ctx) {
28
+ return BasicEvent({ ctx });
29
+ }
30
+ function mkPainter(c2d, w, h) {
31
+ let cp = c2d;
32
+ cp.width = w;
33
+ cp.height = h;
34
+ cp.smoothLine = smoothLine;
35
+ cp.smoothLineEx = smoothLineEx;
36
+ cp.line = line;
37
+ cp.roundRect = roundRect;
38
+ cp.calcTextSize = calcTextSize;
39
+ cp.setFontSize = setFontSize;
40
+ cp.circle = circle;
41
+ return cp;
42
+ }
43
+ function smoothLine(points, path = null, move = true) {
44
+ if (points.length < 2) {
45
+ return;
46
+ }
47
+ if (!path) {
48
+ path = this;
49
+ }
50
+ if (points.length == 2) {
51
+ if (move !== false) {
52
+ path.moveTo(points[0].x, points[0].y);
53
+ }
54
+ else {
55
+ path.lineTo(points[0].x, points[0].y);
56
+ }
57
+ path.lineTo(points[1].x, points[1].y);
58
+ return;
59
+ }
60
+ function midPointBtw(p1, p2) {
61
+ return {
62
+ x: p1.x + (p2.x - p1.x) / 2,
63
+ y: p1.y + (p2.y - p1.y) / 2
64
+ };
65
+ }
66
+ function getQuadraticXY(t, sx, sy, cp1x, cp1y, ex, ey) {
67
+ return {
68
+ x: (1 - t) * (1 - t) * sx + 2 * (1 - t) * t * cp1x + t * t * ex,
69
+ y: (1 - t) * (1 - t) * sy + 2 * (1 - t) * t * cp1y + t * t * ey
70
+ };
71
+ }
72
+ let p1 = points[0], p2 = points[1], p3 = p1;
73
+ path.moveTo(p1.x, p1.y);
74
+ for (let i = 1, len = points.length; i < len; i++) {
75
+ // we pick the point between pi+1 & pi+2 as the
76
+ // end point and p1 as our control point
77
+ let midPoint = midPointBtw(p1, p2);
78
+ //this.quadraticCurveTo(p1.x, p1.y, midPoint.x, midPoint.y);
79
+ for (let i = 0; i < 8; i++) {
80
+ let { x, y } = getQuadraticXY(i / 8, p3.x, p3.y, p1.x, p1.y, midPoint.x, midPoint.y);
81
+ path.lineTo(x, y);
82
+ }
83
+ p1 = points[i];
84
+ p2 = points[i + 1];
85
+ p3 = midPoint;
86
+ }
87
+ // Draw last line as a straight line while
88
+ // we wait for the next point to be able to calculate
89
+ // the bezier control point
90
+ path.lineTo(p1.x, p1.y);
91
+ }
92
+ function smoothLineEx(_points, tension = 0.5, numOfSeg = 10, path = null, move = true, close = false) {
93
+ let points = [];
94
+ //pts = points.slice(0);
95
+ for (let p = 0, pc = _points.length; p < pc; p++) {
96
+ points.push(_points[p].x);
97
+ points.push(_points[p].y);
98
+ }
99
+ let pts, i = 1, l = points.length, rPos = 0, rLen = (l - 2) * numOfSeg + 2 + (close ? 2 * numOfSeg : 0), res = new Float32Array(rLen), cache = new Float32Array((numOfSeg + 2) * 4), cachePtr = 4;
100
+ pts = points.slice(0);
101
+ if (close) {
102
+ pts.unshift(points[l - 1]); // insert end point as first point
103
+ pts.unshift(points[l - 2]);
104
+ pts.push(points[0], points[1]); // first point as last point
105
+ }
106
+ else {
107
+ pts.unshift(points[1]); // copy 1. point and insert at beginning
108
+ pts.unshift(points[0]);
109
+ pts.push(points[l - 2], points[l - 1]); // duplicate end-points
110
+ }
111
+ // cache inner-loop calculations as they are based on t alone
112
+ cache[0] = 1; // 1,0,0,0
113
+ for (; i < numOfSeg; i++) {
114
+ var st = i / numOfSeg, st2 = st * st, st3 = st2 * st, st23 = st3 * 2, st32 = st2 * 3;
115
+ cache[cachePtr++] = st23 - st32 + 1; // c1
116
+ cache[cachePtr++] = st32 - st23; // c2
117
+ cache[cachePtr++] = st3 - 2 * st2 + st; // c3
118
+ cache[cachePtr++] = st3 - st2; // c4
119
+ }
120
+ cache[cachePtr] = 1; // 0,1,0,0
121
+ // calc. points
122
+ parse(pts, cache, l);
123
+ if (close) {
124
+ //l = points.length;
125
+ pts = [];
126
+ pts.push(points[l - 4], points[l - 3], points[l - 2], points[l - 1]); // second last and last
127
+ pts.push(points[0], points[1], points[2], points[3]); // first and second
128
+ parse(pts, cache, 4);
129
+ }
130
+ function parse(pts, cache, l) {
131
+ for (var i = 2, t; i < l; i += 2) {
132
+ var pt1 = pts[i], pt2 = pts[i + 1], pt3 = pts[i + 2], pt4 = pts[i + 3], t1x = (pt3 - pts[i - 2]) * tension, t1y = (pt4 - pts[i - 1]) * tension, t2x = (pts[i + 4] - pt1) * tension, t2y = (pts[i + 5] - pt2) * tension;
133
+ for (t = 0; t < numOfSeg; t++) {
134
+ var c = t << 2, //t * 4;
135
+ c1 = cache[c], c2 = cache[c + 1], c3 = cache[c + 2], c4 = cache[c + 3];
136
+ res[rPos++] = c1 * pt1 + c2 * pt3 + c3 * t1x + c4 * t2x;
137
+ res[rPos++] = c1 * pt2 + c2 * pt4 + c3 * t1y + c4 * t2y;
138
+ }
139
+ }
140
+ }
141
+ // add last point
142
+ l = close ? 0 : points.length - 2;
143
+ res[rPos++] = points[l];
144
+ res[rPos] = points[l + 1];
145
+ if (!path) {
146
+ path = this;
147
+ }
148
+ // add lines to path
149
+ for (let i = 0, l = res.length; i < l; i += 2) {
150
+ if (i == 0 && move !== false) {
151
+ path.moveTo(res[i], res[i + 1]);
152
+ }
153
+ else {
154
+ path.lineTo(res[i], res[i + 1]);
155
+ }
156
+ }
157
+ }
158
+ function line(x1, y1, x2, y2, color, lineWidth = 1) {
159
+ this.save();
160
+ this.beginPath();
161
+ this.moveTo(x1, y1);
162
+ this.lineTo(x2, y2);
163
+ this.lineWidth = lineWidth;
164
+ this.strokeStyle = color;
165
+ this.stroke();
166
+ this.restore();
167
+ }
168
+ function roundRect(x, y, width, height, radius) {
169
+ //this.beginPath( );
170
+ this.moveTo(x + radius, y);
171
+ this.lineTo(x + width - radius, y);
172
+ this.quadraticCurveTo(x + width, y, x + width, y + radius);
173
+ this.lineTo(x + width, y + height - radius);
174
+ this.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
175
+ this.lineTo(x + radius, y + height);
176
+ this.quadraticCurveTo(x, y + height, x, y + height - radius);
177
+ this.lineTo(x, y + radius);
178
+ this.quadraticCurveTo(x, y, x + radius, y);
179
+ this.closePath();
180
+ }
181
+ function calcTextSize(text, rounded = false) {
182
+ let fh = this.measureText(text);
183
+ let lh = fh.fontBoundingBoxAscent + fh.fontBoundingBoxDescent;
184
+ if (rounded) {
185
+ return { width: Math.round(fh.width), height: Math.round(lh) };
186
+ }
187
+ else {
188
+ return { width: fh.width, height: lh };
189
+ }
190
+ }
191
+ function setFontSize(fs) {
192
+ let fsize = Math.round(fs) + 'px';
193
+ this.font = this.font.replace(/\d+px/, fsize);
194
+ }
195
+ function circle(x, y, radius) {
196
+ this.moveTo(x + radius, y);
197
+ this.arc(x, y, radius, 0, Math.PI * 2);
198
+ }
199
+ /**
200
+ *
201
+ */
202
+ //export class CanvasProps extends CProps
203
+ //{
204
+ // low level handlers
205
+ //mousedown?: (ev: MouseEvent) => any;
206
+ //mousemove?: (ev: MouseEvent) => any;
207
+ //mouseup?: (ev: MouseEvent) => any;
208
+ //mouseleave?: (ev: MouseEvent) => any;
209
+ //mousewheel?: (ev: WheelEvent) => any;
210
+ //click?: (ev: MouseEvent) => any;
211
+ //dblclick?: (ev: MouseEvent) => any;
212
+ //touchstart?: (ev: TouchEvent) => any;
213
+ //touchmove?: (ev: TouchEvent) => any;
214
+ //touchend?: (ev: TouchEvent) => any;
215
+ //keydown?: (ev: KeyboardEvent) => any;
216
+ //keyup?: (ev: KeyboardEvent) => any;
217
+ //}
218
+ /**
219
+ * Standard Canvas
220
+ */
221
+ export class Canvas extends Component {
222
+ m_iwidth = -1;
223
+ m_iheight = -1;
224
+ m_scale = 1.0;
225
+ m_canvas;
226
+ constructor(props) {
227
+ super(props);
228
+ //if( props.mousedown ) { this.setDomEvent( 'mousedown', props.mousedown ); }
229
+ //if( props.mousemove ) { this.setDomEvent( 'mousemove', props.mousemove ); }
230
+ //if( props.mouseup ) { this.setDomEvent( 'mouseup', props.mouseup ); }
231
+ //if( props.mousewheel ) { this.setDomEvent( 'wheel', props.mousewheel ); }
232
+ //if( props.mouseleave ) { this.setDomEvent( 'mouseleave', props.mouseleave ); }
233
+ //if( props.click ) { this.setDomEvent( 'click', props.click ); }
234
+ //if( props.dblclick ) { this.setDomEvent( 'dblclick', props.dblclick ); }
235
+ //if( props.touchstart ) { this.setDomEvent( 'touchstart', props.touchstart ); }
236
+ //if( props.touchmove ) { this.setDomEvent( 'touchmove', props.touchmove ); }
237
+ //if( props.touchend ) { this.setDomEvent( 'touchend', props.touchend ); }
238
+ //if( props.keydown ) { this.setDomEvent( 'keydown', props.keydown ); this.setAttribute( 'tabindex', 0 ); }
239
+ //if( props.keyup ) { this.setDomEvent( 'keyup', props.keyup ); this.setAttribute( 'tabindex', 0 ); }
240
+ //if( props.paint ) { this.onPaint( props.paint ); }
241
+ this.setDomEvent('sizechange', () => { this._paint(); });
242
+ this.mapPropEvents(props, 'paint');
243
+ }
244
+ /** @ignore */
245
+ render() {
246
+ this.m_iwidth = -1;
247
+ this.m_iheight = -1;
248
+ this.m_canvas = new Component({
249
+ tag: 'canvas'
250
+ });
251
+ this.setContent(this.m_canvas);
252
+ // this.redraw(10);
253
+ }
254
+ update(delay = 0) {
255
+ this.m_iheight = this.m_iwidth = -1;
256
+ super.update(delay);
257
+ }
258
+ /**
259
+ * scale the whole canvas
260
+ */
261
+ scale(scale) {
262
+ this.m_scale = scale;
263
+ this.m_iwidth = -1; // force recalc
264
+ this.redraw();
265
+ }
266
+ /**
267
+ * return the internal canvas
268
+ */
269
+ get canvas() {
270
+ return this.m_canvas;
271
+ }
272
+ /**
273
+ * redraw the canvas (force a paint)
274
+ */
275
+ $update_rep = 0;
276
+ redraw(wait) {
277
+ if (wait !== undefined) {
278
+ if (++this.$update_rep >= 20) {
279
+ this.stopTimer('update');
280
+ this._paint();
281
+ }
282
+ else {
283
+ this.startTimer('update', wait, false, () => this._paint());
284
+ }
285
+ }
286
+ else {
287
+ this.stopTimer('update');
288
+ this._paint();
289
+ }
290
+ }
291
+ /**
292
+ *
293
+ */
294
+ _paint() {
295
+ this.$update_rep = 0;
296
+ let dom = this.dom;
297
+ if (!this.isUserVisible()) {
298
+ return;
299
+ }
300
+ let canvas = this.m_canvas.dom, w = dom.clientWidth, h = dom.clientHeight;
301
+ let ctx = canvas.getContext('2d');
302
+ if (w != this.m_iwidth || h != this.m_iheight) {
303
+ // adjustment for HDPI
304
+ let devicePixelRatio = window.devicePixelRatio || 1;
305
+ let backingStoreRatio = ctx.webkitBackingStorePixelRatio ||
306
+ ctx.mozBackingStorePixelRatio ||
307
+ ctx.msBackingStorePixelRatio ||
308
+ ctx.oBackingStorePixelRatio ||
309
+ ctx.backingStorePixelRatio || 1;
310
+ let canvas = this.canvas;
311
+ if (devicePixelRatio !== backingStoreRatio || this.m_scale != 1.0) {
312
+ let ratio = devicePixelRatio / backingStoreRatio, rw = w * ratio, rh = h * ratio;
313
+ canvas.setAttribute('width', '' + rw);
314
+ canvas.setAttribute('height', '' + rh);
315
+ canvas.setStyleValue('width', w);
316
+ canvas.setStyleValue('height', h);
317
+ ratio *= this.m_scale;
318
+ ctx.scale(ratio, ratio);
319
+ }
320
+ else {
321
+ canvas.setAttribute('width', '' + w);
322
+ canvas.setAttribute('height', '' + h);
323
+ canvas.setStyleValue('width', w);
324
+ canvas.setStyleValue('height', h);
325
+ ctx.scale(1, 1);
326
+ }
327
+ this.m_iwidth = w;
328
+ this.m_iheight = h;
329
+ }
330
+ if (w && h) {
331
+ let cc = mkPainter(ctx, w, h);
332
+ if (this.m_props.autoClear) {
333
+ cc.clearRect(0, 0, w, h);
334
+ }
335
+ cc.save();
336
+ cc.translate(-0.5, -0.5);
337
+ this.paint(cc);
338
+ cc.restore();
339
+ }
340
+ }
341
+ paint(ctx) {
342
+ try {
343
+ if (this.m_props.painter) {
344
+ this.m_props.painter(ctx);
345
+ }
346
+ else {
347
+ this.emit('paint', EvPaint(ctx));
348
+ }
349
+ }
350
+ catch (x) {
351
+ console.assert(false, x);
352
+ }
353
+ }
354
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file cardview.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 } from './component';
26
+ import { EvChange } from './x4_events';
27
+ import { IconID } from './icon';
28
+ export declare type PageOrCallback = Component | (() => Component);
29
+ export interface ICardViewItem {
30
+ icon?: IconID;
31
+ name: string;
32
+ title: string;
33
+ page: PageOrCallback;
34
+ }
35
+ interface CardViewEventMap extends CEventMap {
36
+ change?: EvChange;
37
+ }
38
+ export interface CardViewProps extends CProps<CardViewEventMap> {
39
+ pages: ICardViewItem[];
40
+ active?: string;
41
+ }
42
+ interface ICardItemEx extends ICardViewItem {
43
+ selector: Component;
44
+ active: boolean;
45
+ }
46
+ /**
47
+ * Standard CardView class
48
+ * a card view is composed of multiples pages with only one visible at a time.
49
+ * pages can be selected by a component (like tabs ou sidebar).
50
+ * or by code.
51
+ */
52
+ export declare class CardView<P extends CardViewProps = CardViewProps, E extends CardViewEventMap = CardViewEventMap> extends Component<P, E> {
53
+ protected m_cards: ICardItemEx[];
54
+ protected m_ipage: string;
55
+ protected m_cpage: ICardItemEx;
56
+ constructor(props: P);
57
+ /** @ignore */
58
+ render(): void;
59
+ /**
60
+ * switch to a specific card
61
+ * @param name - card name as define in constructor
62
+ */
63
+ switchTo(name?: string): void;
64
+ /**
65
+ *
66
+ */
67
+ setPages(pages: ICardViewItem[]): void;
68
+ /**
69
+ *
70
+ */
71
+ private _initTabs;
72
+ protected _updateSelector(): void;
73
+ /**
74
+ * prepare the cardinfo
75
+ * can be used by derivations to create & set selectors
76
+ */
77
+ protected _prepareSelector(card: ICardViewItem): Component;
78
+ /**
79
+ *
80
+ */
81
+ protected _preparePage(page: Component): void;
82
+ }
83
+ export {};
@@ -0,0 +1,152 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file cardview.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 { EvChange } from './x4_events';
27
+ import { asap, isFunction } from './tools';
28
+ /**
29
+ * Standard CardView class
30
+ * a card view is composed of multiples pages with only one visible at a time.
31
+ * pages can be selected by a component (like tabs ou sidebar).
32
+ * or by code.
33
+ */
34
+ export class CardView extends Component {
35
+ m_cards;
36
+ m_ipage; // initialy selected page
37
+ m_cpage; // currently selected page
38
+ constructor(props) {
39
+ super(props);
40
+ this.m_cards = [];
41
+ this.m_ipage = props.active;
42
+ this.m_cpage = null;
43
+ this.singleShot(() => {
44
+ this.setPages(props.pages);
45
+ });
46
+ }
47
+ /** @ignore */
48
+ render() {
49
+ let pages = [];
50
+ this.m_cards.forEach((p) => {
51
+ if (p.page) {
52
+ pages.push(p.page);
53
+ }
54
+ });
55
+ this.setContent(pages);
56
+ }
57
+ /**
58
+ * switch to a specific card
59
+ * @param name - card name as define in constructor
60
+ */
61
+ switchTo(name) {
62
+ if (this.m_cards.length == 0) {
63
+ return;
64
+ }
65
+ if (name === undefined) {
66
+ name = this.m_cards[0].name;
67
+ }
68
+ if (name === this.m_cpage?.name) {
69
+ return;
70
+ }
71
+ // hide old one
72
+ if (this.m_cpage) {
73
+ if (this.m_cpage.selector) {
74
+ this.m_cpage.selector.removeClass('@active');
75
+ }
76
+ if (this.m_cpage.page && !(this.m_cpage.page instanceof Function)) {
77
+ let page = this.m_cpage.page;
78
+ page.removeClass('@active');
79
+ page.addClass('@hidden');
80
+ }
81
+ }
82
+ this.m_cpage = this.m_cards.find((card) => card.name == name);
83
+ if (this.m_cpage) {
84
+ if (this.m_cpage.page) {
85
+ if (isFunction(this.m_cpage.page)) {
86
+ this.m_cpage.page = this.m_cpage.page();
87
+ console.assert(this.m_cpage.page != null, 'You must return a valid component');
88
+ }
89
+ let page = this.m_cpage.page;
90
+ page.addClass('@active');
91
+ page.removeClass('@hidden');
92
+ if (!page.dom) {
93
+ this._preparePage(page);
94
+ }
95
+ }
96
+ this.emit('change', EvChange(this.m_cpage.name));
97
+ }
98
+ }
99
+ /**
100
+ *
101
+ */
102
+ setPages(pages) {
103
+ let active = this._initTabs(pages);
104
+ if (active) {
105
+ asap(() => {
106
+ this.switchTo(active);
107
+ this.update();
108
+ });
109
+ }
110
+ }
111
+ /**
112
+ *
113
+ */
114
+ _initTabs(pages) {
115
+ if (!pages) {
116
+ return;
117
+ }
118
+ let active = this.m_ipage;
119
+ pages.forEach((p) => {
120
+ if (!p) {
121
+ return;
122
+ }
123
+ let card = { ...p };
124
+ card.selector = this._prepareSelector(p);
125
+ card.active = false;
126
+ this.m_cards.push(card);
127
+ if (!active) {
128
+ active = p.name;
129
+ }
130
+ if (p.active) {
131
+ active = p.name;
132
+ }
133
+ });
134
+ return active;
135
+ }
136
+ _updateSelector() {
137
+ }
138
+ /**
139
+ * prepare the cardinfo
140
+ * can be used by derivations to create & set selectors
141
+ */
142
+ _prepareSelector(card) {
143
+ return null;
144
+ }
145
+ /**
146
+ *
147
+ */
148
+ _preparePage(page) {
149
+ page.setStyleValue('flex', 1);
150
+ page.addClass('@tab-page');
151
+ }
152
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file checkbox.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 { CEventMap, Component, CProps } from './component';
26
+ import { EvChange, EventCallback } from './x4_events';
27
+ import { HtmlString } from './tools';
28
+ interface CheckBoxEventMap extends CEventMap {
29
+ change?: EvChange;
30
+ }
31
+ interface CheckBoxProps extends CProps<CheckBoxEventMap> {
32
+ name?: string;
33
+ text?: string | HtmlString;
34
+ checked?: boolean;
35
+ value?: string;
36
+ labelWidth?: number;
37
+ labelAlign?: 'left' | 'right';
38
+ align?: 'left' | 'right';
39
+ change: EventCallback<EvChange>;
40
+ }
41
+ /**
42
+ * Standard CheckBox
43
+ */
44
+ export declare class CheckBox extends Component<CheckBoxProps, CheckBoxEventMap> {
45
+ constructor(props: CheckBoxProps);
46
+ /** @ignore */
47
+ render(props: CheckBoxProps): void;
48
+ /**
49
+ * check state changed
50
+ */
51
+ private _change;
52
+ /**
53
+ * focus gained/loosed
54
+ */
55
+ private _setFocus;
56
+ /**
57
+ * @return the checked value
58
+ */
59
+ get check(): boolean;
60
+ /**
61
+ * change the checked value
62
+ * @param {boolean} ck new checked value
63
+ */
64
+ set check(ck: boolean);
65
+ get text(): string | HtmlString;
66
+ set text(text: string | HtmlString);
67
+ /**
68
+ * toggle the checkbox
69
+ */
70
+ toggle(): void;
71
+ }
72
+ export {};