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.
- package/lib/application.d.ts +95 -0
- package/lib/application.js +137 -0
- package/lib/base64.d.ts +31 -0
- package/lib/base64.js +135 -0
- package/lib/base_component.d.ts +64 -0
- package/lib/base_component.js +77 -0
- package/lib/button.d.ts +145 -0
- package/lib/button.js +235 -0
- package/lib/calendar.d.ts +77 -0
- package/lib/calendar.js +236 -0
- package/lib/canvas.d.ts +88 -0
- package/lib/canvas.js +354 -0
- package/lib/cardview.d.ts +83 -0
- package/lib/cardview.js +152 -0
- package/lib/checkbox.d.ts +72 -0
- package/lib/checkbox.js +126 -0
- package/lib/color.d.ts +144 -0
- package/lib/color.js +584 -0
- package/lib/colorpicker.d.ts +98 -0
- package/lib/colorpicker.js +1457 -0
- package/lib/combobox.d.ts +97 -0
- package/lib/combobox.js +246 -0
- package/lib/component.d.ts +572 -0
- package/lib/component.js +1712 -0
- package/lib/datastore.d.ts +392 -0
- package/lib/datastore.js +986 -0
- package/lib/dialog.d.ts +171 -0
- package/lib/dialog.js +468 -0
- package/lib/dom_events.d.ts +284 -0
- package/lib/dom_events.js +13 -0
- package/lib/drag_manager.d.ts +26 -0
- package/lib/drag_manager.js +118 -0
- package/lib/drawtext.d.ts +43 -0
- package/lib/drawtext.js +261 -0
- package/lib/fileupload.d.ts +60 -0
- package/lib/fileupload.js +158 -0
- package/lib/form.d.ts +122 -0
- package/lib/form.js +293 -0
- package/lib/formatters.d.ts +31 -0
- package/lib/formatters.js +75 -0
- package/lib/gridview.d.ts +171 -0
- package/lib/gridview.js +786 -0
- package/lib/hosts/host.d.ts +44 -0
- package/lib/hosts/host.js +69 -0
- package/lib/i18n.d.ts +67 -0
- package/lib/i18n.js +169 -0
- package/lib/icon.d.ts +56 -0
- package/lib/icon.js +173 -0
- package/lib/image.d.ts +51 -0
- package/lib/image.js +149 -0
- package/lib/index.js +1 -0
- package/lib/input.d.ts +86 -0
- package/lib/input.js +172 -0
- package/lib/label.d.ts +54 -0
- package/lib/label.js +86 -0
- package/lib/layout.d.ts +77 -0
- package/lib/layout.js +261 -0
- package/lib/link.d.ts +46 -0
- package/lib/link.js +55 -0
- package/lib/listview.d.ts +173 -0
- package/lib/listview.js +532 -0
- package/lib/md5.d.ts +56 -0
- package/lib/md5.js +397 -0
- package/lib/menu.d.ts +122 -0
- package/lib/menu.js +276 -0
- package/lib/messagebox.d.ts +64 -0
- package/lib/messagebox.js +141 -0
- package/lib/panel.d.ts +42 -0
- package/lib/panel.js +61 -0
- package/lib/popup.d.ts +71 -0
- package/lib/popup.js +373 -0
- package/lib/property_editor.d.ts +67 -0
- package/lib/property_editor.js +247 -0
- package/lib/radiobtn.d.ts +68 -0
- package/lib/radiobtn.js +131 -0
- package/lib/rating.d.ts +49 -0
- package/lib/rating.js +93 -0
- package/lib/request.d.ts +48 -0
- package/lib/request.js +220 -0
- package/lib/router.d.ts +13 -0
- package/lib/router.js +27 -0
- package/lib/settings.d.ts +33 -0
- package/lib/settings.js +63 -0
- package/lib/sidebarview.d.ts +44 -0
- package/lib/sidebarview.js +73 -0
- package/lib/smartedit.d.ts +103 -0
- package/lib/smartedit.js +381 -0
- package/lib/spreadsheet.d.ts +214 -0
- package/lib/spreadsheet.js +1073 -0
- package/lib/styles.d.ts +81 -0
- package/lib/styles.js +262 -0
- package/lib/svgcomponent.d.ts +165 -0
- package/lib/svgcomponent.js +350 -0
- package/lib/tabbar.d.ts +41 -0
- package/lib/tabbar.js +66 -0
- package/lib/tabview.d.ts +45 -0
- package/lib/tabview.js +79 -0
- package/lib/textarea.d.ts +59 -0
- package/lib/textarea.js +119 -0
- package/lib/textedit.d.ts +118 -0
- package/lib/textedit.js +406 -0
- package/lib/texthiliter.d.ts +56 -0
- package/lib/texthiliter.js +219 -0
- package/lib/toaster.d.ts +38 -0
- package/lib/toaster.js +58 -0
- package/lib/tools.d.ts +382 -0
- package/lib/tools.js +1096 -0
- package/lib/tooltips.d.ts +42 -0
- package/lib/tooltips.js +148 -0
- package/lib/treeview.d.ts +128 -0
- package/lib/treeview.js +490 -0
- package/lib/x4_events.d.ts +253 -0
- package/lib/x4_events.js +363 -0
- package/package.json +21 -0
- package/src/README.md +2 -0
- package/src/application.ts +191 -0
- package/src/base64.ts +162 -0
- package/src/base_component.ts +118 -0
- package/src/button.ts +327 -0
- package/src/calendar.ts +312 -0
- package/src/canvas.ts +501 -0
- package/src/cardview.ts +220 -0
- package/src/checkbox.ts +178 -0
- package/src/color.ts +748 -0
- package/src/colorpicker.ts +1618 -0
- package/src/combobox.ts +348 -0
- package/src/component.ts +2330 -0
- package/src/datastore.ts +1318 -0
- package/src/dialog.ts +631 -0
- package/src/dom_events.ts +297 -0
- package/src/drag_manager.ts +168 -0
- package/src/drawtext.ts +342 -0
- package/src/fileupload.ts +208 -0
- package/src/form.ts +362 -0
- package/src/formatters.ts +96 -0
- package/src/gridview.ts +1051 -0
- package/src/hosts/electron.ts +161 -0
- package/src/hosts/host.ts +100 -0
- package/src/hosts/nwjs.ts +141 -0
- package/src/hosts/nwjs_types.ts +339 -0
- package/src/i18n.ts +205 -0
- package/src/icon.ts +237 -0
- package/src/image.ts +198 -0
- package/src/input.ts +236 -0
- package/src/label.ts +124 -0
- package/src/layout.ts +366 -0
- package/src/link.ts +82 -0
- package/src/listview.ts +749 -0
- package/src/md5.ts +432 -0
- package/src/menu.ts +394 -0
- package/src/messagebox.ts +199 -0
- package/src/panel.ts +81 -0
- package/src/popup.ts +488 -0
- package/src/property_editor.ts +333 -0
- package/src/radiobtn.ts +190 -0
- package/src/rating.ts +131 -0
- package/src/request.ts +296 -0
- package/src/router.ts +43 -0
- package/src/settings.ts +75 -0
- package/src/sidebarview.ts +97 -0
- package/src/smartedit.ts +532 -0
- package/src/spreadsheet.ts +1423 -0
- package/src/styles.ts +332 -0
- package/src/svgcomponent.ts +440 -0
- package/src/tabbar.ts +105 -0
- package/src/tabview.ts +106 -0
- package/src/textarea.ts +183 -0
- package/src/textedit.ts +535 -0
- package/src/texthiliter.ts +284 -0
- package/src/toaster.ts +76 -0
- package/src/tools.ts +1391 -0
- package/src/tooltips.ts +185 -0
- package/src/treeview.ts +670 -0
- package/src/x4.less +1940 -0
- package/src/x4_events.ts +558 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file svgcomponent.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 } from './component'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// degrees to radian
|
|
30
|
+
function d2r( d: number ): number {
|
|
31
|
+
return d * Math.PI / 180.0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// polar to cartesian
|
|
35
|
+
function p2c( x: number, y: number, r: number, deg: number ): {x: number,y: number} {
|
|
36
|
+
const rad = d2r( deg );
|
|
37
|
+
return {
|
|
38
|
+
x: x + r * Math.cos( rad ),
|
|
39
|
+
y: y + r * Math.sin( rad )
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function num( x: number ): number {
|
|
44
|
+
return Math.round( x * 1000 ) / 1000;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function clean( a, ...b ) {
|
|
48
|
+
|
|
49
|
+
// just round number values to 3 digits
|
|
50
|
+
b = b.map( v => {
|
|
51
|
+
if( typeof v === 'number' && isFinite(v) ) {
|
|
52
|
+
return num(v);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return v;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return String.raw( a, ...b );
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
abstract class SVGItem {
|
|
66
|
+
private m_tag: string
|
|
67
|
+
private m_attrs: Map<string,string>;
|
|
68
|
+
|
|
69
|
+
constructor( tag: string ) {
|
|
70
|
+
this.m_tag = tag;
|
|
71
|
+
this.m_attrs = new Map( );
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* render the item
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
render( ) : string {
|
|
79
|
+
return `<${this.m_tag} ${this.renderAttrs()}>${this.renderContent( )}</${this.m_tag}>`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* change the stroke color
|
|
84
|
+
* @param color
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
stroke( color: string ): this {
|
|
88
|
+
this.attr( 'stroke', color );
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* change the stroke width
|
|
94
|
+
* @param width
|
|
95
|
+
*/
|
|
96
|
+
strokeWidth( width: number ): this {
|
|
97
|
+
this.attr( 'stroke-width', width+'px' );
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* change the fill color
|
|
103
|
+
* @param color
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
fill( color: string ): this {
|
|
107
|
+
this.attr( 'fill', color );
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* define a new attribute
|
|
113
|
+
* @param name attibute name
|
|
114
|
+
* @param value attribute value
|
|
115
|
+
* @returns this
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
attr( name: string, value: string ) : this {
|
|
119
|
+
this.m_attrs.set( name, value );
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* add a class
|
|
125
|
+
* @param name class name to add
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
class( name: string ): this {
|
|
129
|
+
let c = this.m_attrs.get( 'class' );
|
|
130
|
+
this.m_attrs.set( 'class', (c??'' + ' ' + name).trim() );
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
renderAttrs( ) {
|
|
139
|
+
let result = '';
|
|
140
|
+
this.m_attrs.forEach( (v,k) => {
|
|
141
|
+
result += ` ${k} = "${v}"`
|
|
142
|
+
});
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
renderContent( ): string {
|
|
147
|
+
return '';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
*
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
class SVGPath extends SVGItem {
|
|
156
|
+
private m_path: string;
|
|
157
|
+
|
|
158
|
+
constructor( ) {
|
|
159
|
+
super( 'path' );
|
|
160
|
+
this.m_path = '';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
override renderAttrs(): string {
|
|
164
|
+
this.attr( 'd', this.m_path );
|
|
165
|
+
return super.renderAttrs( );
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* move the current pos
|
|
170
|
+
* @param x new pos x
|
|
171
|
+
* @param y new pos y
|
|
172
|
+
* @returns this
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
moveTo( x: number, y: number ) : this {
|
|
176
|
+
this.m_path += clean`M${x},${y}`;
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* draw aline to the given point
|
|
182
|
+
* @param x end x
|
|
183
|
+
* @param y end y
|
|
184
|
+
* @returns this
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
lineTo( x: number, y: number ): this {
|
|
188
|
+
this.m_path += clean`L${x},${y}`;
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* close the currentPath
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
closePath( ): this {
|
|
197
|
+
this.m_path += 'Z';
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* draw an arc
|
|
203
|
+
* @param x center x
|
|
204
|
+
* @param y center y
|
|
205
|
+
* @param r radius
|
|
206
|
+
* @param start angle start in degrees
|
|
207
|
+
* @param end angle end in degrees
|
|
208
|
+
* @returns this
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
arc( x: number, y: number, r: number, start: number, end: number ): this {
|
|
212
|
+
|
|
213
|
+
const st = p2c( x, y, r, start-90 );
|
|
214
|
+
const en = p2c( x, y, r, end-90 );
|
|
215
|
+
|
|
216
|
+
const flag = end - start <= 180 ? "0" : "1";
|
|
217
|
+
this.m_path += clean`M${st.x},${st.y}A${r},${r} 0 ${flag} 1 ${en.x},${en.y}`;
|
|
218
|
+
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
*
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
class SVGText extends SVGItem {
|
|
228
|
+
|
|
229
|
+
private m_text;
|
|
230
|
+
|
|
231
|
+
constructor( x: number, y: number, txt: string ) {
|
|
232
|
+
super( 'text' );
|
|
233
|
+
this.m_text = txt;
|
|
234
|
+
this.attr( 'x', num(x)+'' );
|
|
235
|
+
this.attr( 'y', num(y)+'' );
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
font( font: string ): this {
|
|
239
|
+
this.attr( 'font-family', font );
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
fontSize( size: number | string ): this {
|
|
244
|
+
this.attr( 'font-size', size+'' );
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
fontWeight( weight: 'light' | 'normal' | 'bold' ): this {
|
|
249
|
+
this.attr( 'font-weight', weight );
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
textAlign( align: 'left' | 'center' | 'right' ): this {
|
|
254
|
+
|
|
255
|
+
let al;
|
|
256
|
+
switch( align ) {
|
|
257
|
+
case 'left': al = 'start'; break;
|
|
258
|
+
case 'center': al = 'middle'; break;
|
|
259
|
+
case 'right': al = 'end'; break;
|
|
260
|
+
default: return this;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
this.attr( 'text-anchor', al );
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
verticalAlign( align: 'top' | 'center' | 'bottom' ): this {
|
|
268
|
+
|
|
269
|
+
let al;
|
|
270
|
+
switch( align ) {
|
|
271
|
+
case 'top': al = 'hanging'; break;
|
|
272
|
+
case 'center': al = 'middle'; break;
|
|
273
|
+
case 'bottom': al = 'baseline'; break;
|
|
274
|
+
default: return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
this.attr( 'alignment-baseline', al );
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
override renderContent( ) {
|
|
282
|
+
return this.m_text;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
*
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
class SVGShape extends SVGItem {
|
|
291
|
+
constructor( tag: string ) {
|
|
292
|
+
super( tag );
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
*
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
class SVGGradient extends SVGItem {
|
|
301
|
+
|
|
302
|
+
private static g_id = 1;
|
|
303
|
+
|
|
304
|
+
private m_id: string;
|
|
305
|
+
private m_stops: { offset: number, color: string } [];
|
|
306
|
+
|
|
307
|
+
constructor( x1: number, y1: number, x2: number, y2: number ) {
|
|
308
|
+
super( 'linearGradient')
|
|
309
|
+
|
|
310
|
+
this.m_id = 'gx-'+SVGGradient.g_id;
|
|
311
|
+
this.attr( 'id', this.m_id );
|
|
312
|
+
this.attr( 'x1', num(x1)+'' );
|
|
313
|
+
this.attr( 'x2', num(x2)+'' );
|
|
314
|
+
this.attr( 'y1', num(y1)+'' );
|
|
315
|
+
this.attr( 'y2', num(y2)+'' );
|
|
316
|
+
|
|
317
|
+
this.m_stops = [];
|
|
318
|
+
SVGGradient.g_id++;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
get id( ) {
|
|
322
|
+
return 'url(#'+this.m_id+')';
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
addStop( offset: number, color: string ): this {
|
|
326
|
+
this.m_stops.push( {offset,color} );
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
override renderContent(): string {
|
|
331
|
+
|
|
332
|
+
const result = [];
|
|
333
|
+
this.m_stops.forEach( s => {
|
|
334
|
+
result.push( `<stop offset="${s.offset}%" stop-color="${s.color}"></stop>`);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
return result.join('\n' );
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
*
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
export class SVGPathBuilder
|
|
346
|
+
{
|
|
347
|
+
private m_items: SVGItem[];
|
|
348
|
+
|
|
349
|
+
constructor( ) {
|
|
350
|
+
this.m_items = [];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
path( ) {
|
|
354
|
+
const path = new SVGPath( );
|
|
355
|
+
this.m_items.push( path );
|
|
356
|
+
return path;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
text( x, y, txt ) {
|
|
360
|
+
const text = new SVGText( x, y, txt );
|
|
361
|
+
this.m_items.push( text );
|
|
362
|
+
return text;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
ellipse( x, y, r1, r2 = r1 ) {
|
|
366
|
+
const shape = new SVGShape( 'ellipse' );
|
|
367
|
+
shape.attr( 'cx', num(x)+'' );
|
|
368
|
+
shape.attr( 'cy', num(y)+'' );
|
|
369
|
+
shape.attr( 'rx', num(r1)+'' );
|
|
370
|
+
shape.attr( 'ry', num(r2)+'' );
|
|
371
|
+
this.m_items.push( shape );
|
|
372
|
+
return shape;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
rect( x, y, w, h ) {
|
|
376
|
+
const shape = new SVGShape( 'rect' );
|
|
377
|
+
shape.attr( 'x', num(x)+'' );
|
|
378
|
+
shape.attr( 'y', num(y)+'' );
|
|
379
|
+
shape.attr( 'width', num(w)+'' );
|
|
380
|
+
shape.attr( 'height', num(h)+'' );
|
|
381
|
+
this.m_items.push( shape );
|
|
382
|
+
return shape;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
gradient( x1, y1, x2, y2 ) {
|
|
386
|
+
const grad = new SVGGradient( x1, y1, x2, y2 );
|
|
387
|
+
this.m_items.push( grad );
|
|
388
|
+
return grad;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* clear
|
|
393
|
+
*/
|
|
394
|
+
|
|
395
|
+
clear( ) {
|
|
396
|
+
this.m_items = [];
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
render( ) {
|
|
400
|
+
let result: string[] = [];
|
|
401
|
+
this.m_items.forEach( i => {
|
|
402
|
+
result.push( i.render() );
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
return result.join( '\n' );
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
*
|
|
411
|
+
*/
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
export interface SVGProps extends CProps {
|
|
415
|
+
viewBox?: string;
|
|
416
|
+
path?: string;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
export class SVGComponent<P extends SVGProps = SVGProps> extends Component<P> {
|
|
421
|
+
|
|
422
|
+
constructor( props: P ) {
|
|
423
|
+
super( props );
|
|
424
|
+
|
|
425
|
+
this.setProp('tag','svg');
|
|
426
|
+
this.setProp('ns','http://www.w3.org/2000/svg');
|
|
427
|
+
this.setAttribute('xmlns','http://www.w3.org/2000/svg');
|
|
428
|
+
|
|
429
|
+
this.setAttributes( {
|
|
430
|
+
viewBox: props.viewBox,
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
this.setContent( props.path );
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
package/src/tabbar.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file tabbar.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @copyright (c) 2021 R-libre ingenierie, all rights reserved.
|
|
11
|
+
*
|
|
12
|
+
* @description Tab
|
|
13
|
+
**/
|
|
14
|
+
|
|
15
|
+
import { Component, Container, ContainerEventMap, CProps, EventHandler } from './component';
|
|
16
|
+
import { Button } from './button';
|
|
17
|
+
import { EvChange } from './x4_events';
|
|
18
|
+
import { IconID } from './icon.js';
|
|
19
|
+
|
|
20
|
+
interface TabBarEventMap extends ContainerEventMap {
|
|
21
|
+
change: EvChange;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface TabBarProps extends CProps<TabBarEventMap> {
|
|
25
|
+
pages?: ITabPage[];
|
|
26
|
+
default?: string;
|
|
27
|
+
vertical?: boolean;
|
|
28
|
+
change: EventHandler<EvChange>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ITabPage {
|
|
32
|
+
id: string;
|
|
33
|
+
title?: string;
|
|
34
|
+
icon?: IconID;
|
|
35
|
+
page: Component;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface TabPage extends ITabPage {
|
|
39
|
+
btn?: Component;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class TabBar extends Container<TabBarProps,TabBarEventMap> {
|
|
43
|
+
|
|
44
|
+
private m_pages: TabPage[];
|
|
45
|
+
private m_curPage: TabPage;
|
|
46
|
+
|
|
47
|
+
constructor( props: TabBarProps ) {
|
|
48
|
+
super( props );
|
|
49
|
+
|
|
50
|
+
this.m_pages = [];
|
|
51
|
+
this.m_curPage = null;
|
|
52
|
+
|
|
53
|
+
this.mapPropEvents( props, 'change' );
|
|
54
|
+
|
|
55
|
+
if( props.vertical ) {
|
|
56
|
+
this.addClass( '@vlayout')
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.addClass( '@hlayout')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.m_props.pages?.forEach( p => this.addPage(p) );
|
|
63
|
+
if( this.m_props.default ) {
|
|
64
|
+
this.select( this.m_props.default );
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
addPage( page: ITabPage ) {
|
|
69
|
+
this.m_pages.push( { ...page } );
|
|
70
|
+
this._updateContent( );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
render( ) {
|
|
74
|
+
let buttons = [];
|
|
75
|
+
this.m_pages.forEach( p => {
|
|
76
|
+
p.btn = new Button( { cls: p===this.m_curPage ? 'selected' : '', text: p.title, icon: p.icon, click: () => this._select(p) } );
|
|
77
|
+
buttons.push( p.btn );
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.setContent( buttons );
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
select( id: string ) {
|
|
84
|
+
let page = this.m_pages.find( x => x.id===id );
|
|
85
|
+
if( page ) {
|
|
86
|
+
this._select( page );
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private _select( p: TabPage ) {
|
|
91
|
+
|
|
92
|
+
if( this.dom && this.m_curPage && this.m_curPage.page ) {
|
|
93
|
+
this.m_curPage.btn.removeClass( 'selected' );
|
|
94
|
+
this.m_curPage.page.hide( );
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.m_curPage = p;
|
|
98
|
+
this.signal( 'change', EvChange(p ? p.id : null) );
|
|
99
|
+
|
|
100
|
+
if( this.dom && this.m_curPage && this.m_curPage.page ) {
|
|
101
|
+
this.m_curPage.btn.addClass( 'selected' );
|
|
102
|
+
this.m_curPage.page.show( );
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/tabview.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file tabview.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 } from './component'
|
|
27
|
+
import { HLayout } from './layout'
|
|
28
|
+
import { Button } from './button'
|
|
29
|
+
import { CardView, CardViewProps, ICardViewItem } from './cardview'
|
|
30
|
+
import { MenuItem } from './menu'
|
|
31
|
+
|
|
32
|
+
interface TabProps extends CardViewProps
|
|
33
|
+
{
|
|
34
|
+
tab_selector?: boolean;
|
|
35
|
+
menu?: MenuItem;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Standard TabView class
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export class TabView extends CardView<TabProps>
|
|
43
|
+
{
|
|
44
|
+
protected m_tab_selector: boolean;
|
|
45
|
+
protected m_menu: MenuItem;
|
|
46
|
+
|
|
47
|
+
constructor( props: TabProps ) {
|
|
48
|
+
super( props );
|
|
49
|
+
|
|
50
|
+
this.m_tab_selector = props.tab_selector ? true : false;
|
|
51
|
+
this.m_menu = props.menu;
|
|
52
|
+
|
|
53
|
+
this.addClass( '@vlayout' );
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @ignore */
|
|
57
|
+
render() {
|
|
58
|
+
|
|
59
|
+
let tabs = [];
|
|
60
|
+
let pages = [];
|
|
61
|
+
|
|
62
|
+
if( this.m_menu ) {
|
|
63
|
+
this.m_menu.addClass( '@button @tab-btn' );
|
|
64
|
+
this.m_menu.removeClass( '@menu-item' );
|
|
65
|
+
tabs.push( this.m_menu );
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.m_cards.forEach( (p) => {
|
|
69
|
+
tabs.push( p.selector );
|
|
70
|
+
if( !(p.page instanceof Function) ) {
|
|
71
|
+
pages.push( p.page );
|
|
72
|
+
}
|
|
73
|
+
} );
|
|
74
|
+
|
|
75
|
+
if( this.m_tab_selector ) {
|
|
76
|
+
pages.unshift( new HLayout( {
|
|
77
|
+
cls: '@tab-switch',
|
|
78
|
+
content: tabs
|
|
79
|
+
}) );
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.setContent( pages );
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
protected _updateSelector( ) {
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
protected _prepareSelector( card: ICardViewItem ): Component {
|
|
90
|
+
|
|
91
|
+
return new Button( {
|
|
92
|
+
cls: '@tab-btn',
|
|
93
|
+
text: card.title,
|
|
94
|
+
icon: card.icon,
|
|
95
|
+
click: ( ) => { this.switchTo(card.name); }
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected _preparePage( page: Component ) {
|
|
100
|
+
super._preparePage( page );
|
|
101
|
+
|
|
102
|
+
if( !page.dom ) {
|
|
103
|
+
this.appendChild( page );
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|