x4js 1.4.4 → 1.4.7

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 (85) hide show
  1. package/lib/application.d.ts +96 -0
  2. package/lib/application.js +146 -0
  3. package/lib/base64.d.ts +31 -0
  4. package/lib/base64.js +139 -0
  5. package/lib/base_component.d.ts +64 -0
  6. package/lib/base_component.js +81 -0
  7. package/lib/button.d.ts +145 -0
  8. package/lib/button.js +241 -0
  9. package/lib/calendar.d.ts +77 -0
  10. package/lib/calendar.js +241 -0
  11. package/lib/canvas.d.ts +88 -0
  12. package/lib/canvas.js +358 -0
  13. package/lib/cardview.d.ts +83 -0
  14. package/lib/cardview.js +156 -0
  15. package/lib/checkbox.d.ts +72 -0
  16. package/lib/checkbox.js +130 -0
  17. package/lib/color.d.ts +144 -0
  18. package/lib/color.js +588 -0
  19. package/lib/colorpicker.js +86 -80
  20. package/lib/combobox.js +26 -22
  21. package/lib/component.d.ts +572 -0
  22. package/lib/component.js +1729 -0
  23. package/lib/datastore.js +29 -20
  24. package/lib/dialog.js +41 -36
  25. package/lib/dom_events.d.ts +284 -0
  26. package/lib/dom_events.js +14 -0
  27. package/lib/drag_manager.js +4 -1
  28. package/lib/drawtext.js +9 -5
  29. package/lib/fileupload.js +19 -12
  30. package/lib/form.js +29 -25
  31. package/lib/formatters.js +19 -10
  32. package/lib/gridview.js +40 -35
  33. package/lib/hosts/host.d.ts +44 -0
  34. package/lib/hosts/host.js +73 -0
  35. package/lib/i18n.d.ts +67 -0
  36. package/lib/i18n.js +175 -0
  37. package/lib/icon.d.ts +56 -0
  38. package/lib/icon.js +178 -0
  39. package/lib/image.js +7 -3
  40. package/lib/index.js +71 -55
  41. package/lib/input.d.ts +86 -0
  42. package/lib/input.js +176 -0
  43. package/lib/label.d.ts +54 -0
  44. package/lib/label.js +90 -0
  45. package/lib/layout.d.ts +77 -0
  46. package/lib/layout.js +271 -0
  47. package/lib/link.js +9 -5
  48. package/lib/listview.js +34 -27
  49. package/lib/md5.js +5 -1
  50. package/lib/menu.d.ts +122 -0
  51. package/lib/menu.js +284 -0
  52. package/lib/messagebox.js +22 -17
  53. package/lib/panel.js +13 -9
  54. package/lib/popup.d.ts +71 -0
  55. package/lib/popup.js +378 -0
  56. package/lib/property_editor.js +20 -16
  57. package/lib/radiobtn.js +13 -9
  58. package/lib/rating.js +13 -9
  59. package/lib/request.js +16 -9
  60. package/lib/router.js +5 -1
  61. package/lib/settings.d.ts +33 -0
  62. package/lib/settings.js +67 -0
  63. package/lib/sidebarview.js +12 -8
  64. package/lib/smartedit.js +16 -11
  65. package/lib/spreadsheet.js +35 -31
  66. package/lib/styles.d.ts +81 -0
  67. package/lib/styles.js +268 -0
  68. package/lib/svgcomponent.js +8 -3
  69. package/lib/tabbar.js +10 -6
  70. package/lib/tabview.js +10 -6
  71. package/lib/textarea.js +10 -6
  72. package/lib/textedit.js +39 -35
  73. package/lib/texthiliter.js +8 -4
  74. package/lib/toaster.js +8 -4
  75. package/lib/tools.d.ts +382 -0
  76. package/lib/tools.js +1142 -0
  77. package/lib/tooltips.js +14 -9
  78. package/lib/treeview.js +30 -26
  79. package/lib/x4_events.d.ts +253 -0
  80. package/lib/x4_events.js +375 -0
  81. package/package.json +1 -1
  82. package/src/application.ts +9 -4
  83. package/src/x4.less +143 -107
  84. package/tsconfig.json +1 -1
  85. package/x4.css +1541 -0
package/lib/canvas.js ADDED
@@ -0,0 +1,358 @@
1
+ "use strict";
2
+ /**
3
+ * ___ ___ __
4
+ * \ \/ / / _
5
+ * \ / /_| |_
6
+ * / \____ _|
7
+ * /__/\__\ |_|
8
+ *
9
+ * @file canvas.ts
10
+ * @author Etienne Cochard
11
+ * @license
12
+ * Copyright (c) 2019-2021 R-libre ingenierie
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License as published by
16
+ * the Free Software Foundation; either version 3 of the License, or
17
+ * (at your option) any later version.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
25
+ **/
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.Canvas = void 0;
28
+ const component_1 = require("./component");
29
+ const x4_events_1 = require("./x4_events");
30
+ function EvPaint(ctx) {
31
+ return (0, x4_events_1.BasicEvent)({ ctx });
32
+ }
33
+ function mkPainter(c2d, w, h) {
34
+ let cp = c2d;
35
+ cp.width = w;
36
+ cp.height = h;
37
+ cp.smoothLine = smoothLine;
38
+ cp.smoothLineEx = smoothLineEx;
39
+ cp.line = line;
40
+ cp.roundRect = roundRect;
41
+ cp.calcTextSize = calcTextSize;
42
+ cp.setFontSize = setFontSize;
43
+ cp.circle = circle;
44
+ return cp;
45
+ }
46
+ function smoothLine(points, path = null, move = true) {
47
+ if (points.length < 2) {
48
+ return;
49
+ }
50
+ if (!path) {
51
+ path = this;
52
+ }
53
+ if (points.length == 2) {
54
+ if (move !== false) {
55
+ path.moveTo(points[0].x, points[0].y);
56
+ }
57
+ else {
58
+ path.lineTo(points[0].x, points[0].y);
59
+ }
60
+ path.lineTo(points[1].x, points[1].y);
61
+ return;
62
+ }
63
+ function midPointBtw(p1, p2) {
64
+ return {
65
+ x: p1.x + (p2.x - p1.x) / 2,
66
+ y: p1.y + (p2.y - p1.y) / 2
67
+ };
68
+ }
69
+ function getQuadraticXY(t, sx, sy, cp1x, cp1y, ex, ey) {
70
+ return {
71
+ x: (1 - t) * (1 - t) * sx + 2 * (1 - t) * t * cp1x + t * t * ex,
72
+ y: (1 - t) * (1 - t) * sy + 2 * (1 - t) * t * cp1y + t * t * ey
73
+ };
74
+ }
75
+ let p1 = points[0], p2 = points[1], p3 = p1;
76
+ path.moveTo(p1.x, p1.y);
77
+ for (let i = 1, len = points.length; i < len; i++) {
78
+ // we pick the point between pi+1 & pi+2 as the
79
+ // end point and p1 as our control point
80
+ let midPoint = midPointBtw(p1, p2);
81
+ //this.quadraticCurveTo(p1.x, p1.y, midPoint.x, midPoint.y);
82
+ for (let i = 0; i < 8; i++) {
83
+ let { x, y } = getQuadraticXY(i / 8, p3.x, p3.y, p1.x, p1.y, midPoint.x, midPoint.y);
84
+ path.lineTo(x, y);
85
+ }
86
+ p1 = points[i];
87
+ p2 = points[i + 1];
88
+ p3 = midPoint;
89
+ }
90
+ // Draw last line as a straight line while
91
+ // we wait for the next point to be able to calculate
92
+ // the bezier control point
93
+ path.lineTo(p1.x, p1.y);
94
+ }
95
+ function smoothLineEx(_points, tension = 0.5, numOfSeg = 10, path = null, move = true, close = false) {
96
+ let points = [];
97
+ //pts = points.slice(0);
98
+ for (let p = 0, pc = _points.length; p < pc; p++) {
99
+ points.push(_points[p].x);
100
+ points.push(_points[p].y);
101
+ }
102
+ 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;
103
+ pts = points.slice(0);
104
+ if (close) {
105
+ pts.unshift(points[l - 1]); // insert end point as first point
106
+ pts.unshift(points[l - 2]);
107
+ pts.push(points[0], points[1]); // first point as last point
108
+ }
109
+ else {
110
+ pts.unshift(points[1]); // copy 1. point and insert at beginning
111
+ pts.unshift(points[0]);
112
+ pts.push(points[l - 2], points[l - 1]); // duplicate end-points
113
+ }
114
+ // cache inner-loop calculations as they are based on t alone
115
+ cache[0] = 1; // 1,0,0,0
116
+ for (; i < numOfSeg; i++) {
117
+ var st = i / numOfSeg, st2 = st * st, st3 = st2 * st, st23 = st3 * 2, st32 = st2 * 3;
118
+ cache[cachePtr++] = st23 - st32 + 1; // c1
119
+ cache[cachePtr++] = st32 - st23; // c2
120
+ cache[cachePtr++] = st3 - 2 * st2 + st; // c3
121
+ cache[cachePtr++] = st3 - st2; // c4
122
+ }
123
+ cache[cachePtr] = 1; // 0,1,0,0
124
+ // calc. points
125
+ parse(pts, cache, l);
126
+ if (close) {
127
+ //l = points.length;
128
+ pts = [];
129
+ pts.push(points[l - 4], points[l - 3], points[l - 2], points[l - 1]); // second last and last
130
+ pts.push(points[0], points[1], points[2], points[3]); // first and second
131
+ parse(pts, cache, 4);
132
+ }
133
+ function parse(pts, cache, l) {
134
+ for (var i = 2, t; i < l; i += 2) {
135
+ 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;
136
+ for (t = 0; t < numOfSeg; t++) {
137
+ var c = t << 2, //t * 4;
138
+ c1 = cache[c], c2 = cache[c + 1], c3 = cache[c + 2], c4 = cache[c + 3];
139
+ res[rPos++] = c1 * pt1 + c2 * pt3 + c3 * t1x + c4 * t2x;
140
+ res[rPos++] = c1 * pt2 + c2 * pt4 + c3 * t1y + c4 * t2y;
141
+ }
142
+ }
143
+ }
144
+ // add last point
145
+ l = close ? 0 : points.length - 2;
146
+ res[rPos++] = points[l];
147
+ res[rPos] = points[l + 1];
148
+ if (!path) {
149
+ path = this;
150
+ }
151
+ // add lines to path
152
+ for (let i = 0, l = res.length; i < l; i += 2) {
153
+ if (i == 0 && move !== false) {
154
+ path.moveTo(res[i], res[i + 1]);
155
+ }
156
+ else {
157
+ path.lineTo(res[i], res[i + 1]);
158
+ }
159
+ }
160
+ }
161
+ function line(x1, y1, x2, y2, color, lineWidth = 1) {
162
+ this.save();
163
+ this.beginPath();
164
+ this.moveTo(x1, y1);
165
+ this.lineTo(x2, y2);
166
+ this.lineWidth = lineWidth;
167
+ this.strokeStyle = color;
168
+ this.stroke();
169
+ this.restore();
170
+ }
171
+ function roundRect(x, y, width, height, radius) {
172
+ //this.beginPath( );
173
+ this.moveTo(x + radius, y);
174
+ this.lineTo(x + width - radius, y);
175
+ this.quadraticCurveTo(x + width, y, x + width, y + radius);
176
+ this.lineTo(x + width, y + height - radius);
177
+ this.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
178
+ this.lineTo(x + radius, y + height);
179
+ this.quadraticCurveTo(x, y + height, x, y + height - radius);
180
+ this.lineTo(x, y + radius);
181
+ this.quadraticCurveTo(x, y, x + radius, y);
182
+ this.closePath();
183
+ }
184
+ function calcTextSize(text, rounded = false) {
185
+ let fh = this.measureText(text);
186
+ let lh = fh.fontBoundingBoxAscent + fh.fontBoundingBoxDescent;
187
+ if (rounded) {
188
+ return { width: Math.round(fh.width), height: Math.round(lh) };
189
+ }
190
+ else {
191
+ return { width: fh.width, height: lh };
192
+ }
193
+ }
194
+ function setFontSize(fs) {
195
+ let fsize = Math.round(fs) + 'px';
196
+ this.font = this.font.replace(/\d+px/, fsize);
197
+ }
198
+ function circle(x, y, radius) {
199
+ this.moveTo(x + radius, y);
200
+ this.arc(x, y, radius, 0, Math.PI * 2);
201
+ }
202
+ /**
203
+ *
204
+ */
205
+ //export class CanvasProps extends CProps
206
+ //{
207
+ // low level handlers
208
+ //mousedown?: (ev: MouseEvent) => any;
209
+ //mousemove?: (ev: MouseEvent) => any;
210
+ //mouseup?: (ev: MouseEvent) => any;
211
+ //mouseleave?: (ev: MouseEvent) => any;
212
+ //mousewheel?: (ev: WheelEvent) => any;
213
+ //click?: (ev: MouseEvent) => any;
214
+ //dblclick?: (ev: MouseEvent) => any;
215
+ //touchstart?: (ev: TouchEvent) => any;
216
+ //touchmove?: (ev: TouchEvent) => any;
217
+ //touchend?: (ev: TouchEvent) => any;
218
+ //keydown?: (ev: KeyboardEvent) => any;
219
+ //keyup?: (ev: KeyboardEvent) => any;
220
+ //}
221
+ /**
222
+ * Standard Canvas
223
+ */
224
+ class Canvas extends component_1.Component {
225
+ m_iwidth = -1;
226
+ m_iheight = -1;
227
+ m_scale = 1.0;
228
+ m_canvas;
229
+ constructor(props) {
230
+ super(props);
231
+ //if( props.mousedown ) { this.setDomEvent( 'mousedown', props.mousedown ); }
232
+ //if( props.mousemove ) { this.setDomEvent( 'mousemove', props.mousemove ); }
233
+ //if( props.mouseup ) { this.setDomEvent( 'mouseup', props.mouseup ); }
234
+ //if( props.mousewheel ) { this.setDomEvent( 'wheel', props.mousewheel ); }
235
+ //if( props.mouseleave ) { this.setDomEvent( 'mouseleave', props.mouseleave ); }
236
+ //if( props.click ) { this.setDomEvent( 'click', props.click ); }
237
+ //if( props.dblclick ) { this.setDomEvent( 'dblclick', props.dblclick ); }
238
+ //if( props.touchstart ) { this.setDomEvent( 'touchstart', props.touchstart ); }
239
+ //if( props.touchmove ) { this.setDomEvent( 'touchmove', props.touchmove ); }
240
+ //if( props.touchend ) { this.setDomEvent( 'touchend', props.touchend ); }
241
+ //if( props.keydown ) { this.setDomEvent( 'keydown', props.keydown ); this.setAttribute( 'tabindex', 0 ); }
242
+ //if( props.keyup ) { this.setDomEvent( 'keyup', props.keyup ); this.setAttribute( 'tabindex', 0 ); }
243
+ //if( props.paint ) { this.onPaint( props.paint ); }
244
+ this.setDomEvent('sizechange', () => { this._paint(); });
245
+ this.mapPropEvents(props, 'paint');
246
+ }
247
+ /** @ignore */
248
+ render() {
249
+ this.m_iwidth = -1;
250
+ this.m_iheight = -1;
251
+ this.m_canvas = new component_1.Component({
252
+ tag: 'canvas'
253
+ });
254
+ this.setContent(this.m_canvas);
255
+ // this.redraw(10);
256
+ }
257
+ update(delay = 0) {
258
+ this.m_iheight = this.m_iwidth = -1;
259
+ super.update(delay);
260
+ }
261
+ /**
262
+ * scale the whole canvas
263
+ */
264
+ scale(scale) {
265
+ this.m_scale = scale;
266
+ this.m_iwidth = -1; // force recalc
267
+ this.redraw();
268
+ }
269
+ /**
270
+ * return the internal canvas
271
+ */
272
+ get canvas() {
273
+ return this.m_canvas;
274
+ }
275
+ /**
276
+ * redraw the canvas (force a paint)
277
+ */
278
+ $update_rep = 0;
279
+ redraw(wait) {
280
+ if (wait !== undefined) {
281
+ if (++this.$update_rep >= 20) {
282
+ this.stopTimer('update');
283
+ this._paint();
284
+ }
285
+ else {
286
+ this.startTimer('update', wait, false, () => this._paint());
287
+ }
288
+ }
289
+ else {
290
+ this.stopTimer('update');
291
+ this._paint();
292
+ }
293
+ }
294
+ /**
295
+ *
296
+ */
297
+ _paint() {
298
+ this.$update_rep = 0;
299
+ let dom = this.dom;
300
+ if (!this.isUserVisible()) {
301
+ return;
302
+ }
303
+ let canvas = this.m_canvas.dom, w = dom.clientWidth, h = dom.clientHeight;
304
+ let ctx = canvas.getContext('2d');
305
+ if (w != this.m_iwidth || h != this.m_iheight) {
306
+ // adjustment for HDPI
307
+ let devicePixelRatio = window.devicePixelRatio || 1;
308
+ let backingStoreRatio = ctx.webkitBackingStorePixelRatio ||
309
+ ctx.mozBackingStorePixelRatio ||
310
+ ctx.msBackingStorePixelRatio ||
311
+ ctx.oBackingStorePixelRatio ||
312
+ ctx.backingStorePixelRatio || 1;
313
+ let canvas = this.canvas;
314
+ if (devicePixelRatio !== backingStoreRatio || this.m_scale != 1.0) {
315
+ let ratio = devicePixelRatio / backingStoreRatio, rw = w * ratio, rh = h * ratio;
316
+ canvas.setAttribute('width', '' + rw);
317
+ canvas.setAttribute('height', '' + rh);
318
+ canvas.setStyleValue('width', w);
319
+ canvas.setStyleValue('height', h);
320
+ ratio *= this.m_scale;
321
+ ctx.scale(ratio, ratio);
322
+ }
323
+ else {
324
+ canvas.setAttribute('width', '' + w);
325
+ canvas.setAttribute('height', '' + h);
326
+ canvas.setStyleValue('width', w);
327
+ canvas.setStyleValue('height', h);
328
+ ctx.scale(1, 1);
329
+ }
330
+ this.m_iwidth = w;
331
+ this.m_iheight = h;
332
+ }
333
+ if (w && h) {
334
+ let cc = mkPainter(ctx, w, h);
335
+ if (this.m_props.autoClear) {
336
+ cc.clearRect(0, 0, w, h);
337
+ }
338
+ cc.save();
339
+ cc.translate(-0.5, -0.5);
340
+ this.paint(cc);
341
+ cc.restore();
342
+ }
343
+ }
344
+ paint(ctx) {
345
+ try {
346
+ if (this.m_props.painter) {
347
+ this.m_props.painter(ctx);
348
+ }
349
+ else {
350
+ this.emit('paint', EvPaint(ctx));
351
+ }
352
+ }
353
+ catch (x) {
354
+ console.assert(false, x);
355
+ }
356
+ }
357
+ }
358
+ exports.Canvas = Canvas;
@@ -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,156 @@
1
+ "use strict";
2
+ /**
3
+ * ___ ___ __
4
+ * \ \/ / / _
5
+ * \ / /_| |_
6
+ * / \____ _|
7
+ * /__/\__\ |_|
8
+ *
9
+ * @file cardview.ts
10
+ * @author Etienne Cochard
11
+ * @license
12
+ * Copyright (c) 2019-2021 R-libre ingenierie
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License as published by
16
+ * the Free Software Foundation; either version 3 of the License, or
17
+ * (at your option) any later version.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
25
+ **/
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.CardView = void 0;
28
+ const component_1 = require("./component");
29
+ const x4_events_1 = require("./x4_events");
30
+ const tools_1 = require("./tools");
31
+ /**
32
+ * Standard CardView class
33
+ * a card view is composed of multiples pages with only one visible at a time.
34
+ * pages can be selected by a component (like tabs ou sidebar).
35
+ * or by code.
36
+ */
37
+ class CardView extends component_1.Component {
38
+ m_cards;
39
+ m_ipage; // initialy selected page
40
+ m_cpage; // currently selected page
41
+ constructor(props) {
42
+ super(props);
43
+ this.m_cards = [];
44
+ this.m_ipage = props.active;
45
+ this.m_cpage = null;
46
+ this.singleShot(() => {
47
+ this.setPages(props.pages);
48
+ });
49
+ }
50
+ /** @ignore */
51
+ render() {
52
+ let pages = [];
53
+ this.m_cards.forEach((p) => {
54
+ if (p.page) {
55
+ pages.push(p.page);
56
+ }
57
+ });
58
+ this.setContent(pages);
59
+ }
60
+ /**
61
+ * switch to a specific card
62
+ * @param name - card name as define in constructor
63
+ */
64
+ switchTo(name) {
65
+ if (this.m_cards.length == 0) {
66
+ return;
67
+ }
68
+ if (name === undefined) {
69
+ name = this.m_cards[0].name;
70
+ }
71
+ if (name === this.m_cpage?.name) {
72
+ return;
73
+ }
74
+ // hide old one
75
+ if (this.m_cpage) {
76
+ if (this.m_cpage.selector) {
77
+ this.m_cpage.selector.removeClass('@active');
78
+ }
79
+ if (this.m_cpage.page && !(this.m_cpage.page instanceof Function)) {
80
+ let page = this.m_cpage.page;
81
+ page.removeClass('@active');
82
+ page.addClass('@hidden');
83
+ }
84
+ }
85
+ this.m_cpage = this.m_cards.find((card) => card.name == name);
86
+ if (this.m_cpage) {
87
+ if (this.m_cpage.page) {
88
+ if ((0, tools_1.isFunction)(this.m_cpage.page)) {
89
+ this.m_cpage.page = this.m_cpage.page();
90
+ console.assert(this.m_cpage.page != null, 'You must return a valid component');
91
+ }
92
+ let page = this.m_cpage.page;
93
+ page.addClass('@active');
94
+ page.removeClass('@hidden');
95
+ if (!page.dom) {
96
+ this._preparePage(page);
97
+ }
98
+ }
99
+ this.emit('change', (0, x4_events_1.EvChange)(this.m_cpage.name));
100
+ }
101
+ }
102
+ /**
103
+ *
104
+ */
105
+ setPages(pages) {
106
+ let active = this._initTabs(pages);
107
+ if (active) {
108
+ (0, tools_1.asap)(() => {
109
+ this.switchTo(active);
110
+ this.update();
111
+ });
112
+ }
113
+ }
114
+ /**
115
+ *
116
+ */
117
+ _initTabs(pages) {
118
+ if (!pages) {
119
+ return;
120
+ }
121
+ let active = this.m_ipage;
122
+ pages.forEach((p) => {
123
+ if (!p) {
124
+ return;
125
+ }
126
+ let card = { ...p };
127
+ card.selector = this._prepareSelector(p);
128
+ card.active = false;
129
+ this.m_cards.push(card);
130
+ if (!active) {
131
+ active = p.name;
132
+ }
133
+ if (p.active) {
134
+ active = p.name;
135
+ }
136
+ });
137
+ return active;
138
+ }
139
+ _updateSelector() {
140
+ }
141
+ /**
142
+ * prepare the cardinfo
143
+ * can be used by derivations to create & set selectors
144
+ */
145
+ _prepareSelector(card) {
146
+ return null;
147
+ }
148
+ /**
149
+ *
150
+ */
151
+ _preparePage(page) {
152
+ page.setStyleValue('flex', 1);
153
+ page.addClass('@tab-page');
154
+ }
155
+ }
156
+ exports.CardView = CardView;
@@ -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 {};