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
package/src/request.ts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file request.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
|
+
|
|
27
|
+
/**
|
|
28
|
+
* TODO: use fetch api
|
|
29
|
+
*
|
|
30
|
+
|
|
31
|
+
async function xx( resp, cb ) {
|
|
32
|
+
cb( await resp.json() );
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function getToto( cb ) {
|
|
36
|
+
fetch('home/toto', { method: 'GET' }).then( (resp) => { xx(resp,cb); } );
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function dump( resp ) {
|
|
40
|
+
console.log( resp );
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getToto( dump );
|
|
44
|
+
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
import { isArray, isLiteralObject, isString, NetworkError } from './tools'
|
|
49
|
+
|
|
50
|
+
const DEFAULT_TIMEOUT = 10000;
|
|
51
|
+
|
|
52
|
+
export interface RequestProps
|
|
53
|
+
{
|
|
54
|
+
url: string;
|
|
55
|
+
method?: 'GET' | 'POST';
|
|
56
|
+
headers?: string[];
|
|
57
|
+
params?: any;
|
|
58
|
+
timeout?: number;
|
|
59
|
+
responseType?: 'text' | 'json' | 'arraybuffer';
|
|
60
|
+
userData?: any;
|
|
61
|
+
|
|
62
|
+
success: ( data: any, userData: any ) => void;
|
|
63
|
+
failure?: ( status: number, statusText: string, userData: any ) => void;
|
|
64
|
+
progress?: ( length: number, total: number, display: string ) => void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
export function ajaxRequest( cfg: RequestProps ) : Function {
|
|
69
|
+
|
|
70
|
+
let params,
|
|
71
|
+
url = cfg.url,
|
|
72
|
+
method = cfg.method || 'GET',
|
|
73
|
+
formdata = false;
|
|
74
|
+
|
|
75
|
+
if( cfg.params instanceof FormData ) {
|
|
76
|
+
params = cfg.params;
|
|
77
|
+
formdata = true;
|
|
78
|
+
}
|
|
79
|
+
else if( method=='POST' ) {
|
|
80
|
+
params = buildQuery( cfg.params, false );
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
url += buildQuery( cfg.params, true );
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
url = encodeURI( url );
|
|
87
|
+
|
|
88
|
+
let xhr = new XMLHttpRequest( );
|
|
89
|
+
xhr.open( method, url );
|
|
90
|
+
|
|
91
|
+
xhr.upload.addEventListener( 'progress', progress, false);
|
|
92
|
+
xhr.addEventListener( 'timeout', failure );
|
|
93
|
+
xhr.addEventListener( 'error', failure );
|
|
94
|
+
xhr.addEventListener( 'load', success );
|
|
95
|
+
|
|
96
|
+
if( !formdata ) {
|
|
97
|
+
xhr.setRequestHeader( "Content-type", "application/x-www-form-urlencoded; charset=UTF-8" );
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if( method!='POST' ) {
|
|
101
|
+
xhr.responseType = cfg.responseType || 'json';
|
|
102
|
+
xhr.timeout = cfg.timeout || DEFAULT_TIMEOUT;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if( cfg.headers ) {
|
|
106
|
+
for( let h in cfg.headers) {
|
|
107
|
+
this.xhr.setRequestHeader( h, cfg.headers[h] );
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function progress( ev: ProgressEvent<EventTarget> ) {
|
|
112
|
+
console.log( ev );
|
|
113
|
+
if( cfg.progress ) {
|
|
114
|
+
try {
|
|
115
|
+
if( ev.lengthComputable ) {
|
|
116
|
+
let disp = humanSize( ev.loaded ) + ' / ' + humanSize( ev.total );
|
|
117
|
+
cfg.progress( ev.loaded, ev.total, disp );
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch( e ) {
|
|
121
|
+
console.error( 'unhandled exception:', e );
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function humanSize( bytes: number ) {
|
|
127
|
+
|
|
128
|
+
let unit, value: number;
|
|
129
|
+
|
|
130
|
+
if( bytes>=1e9 ) {
|
|
131
|
+
unit = 'Gb';
|
|
132
|
+
value = bytes/1e9;
|
|
133
|
+
}
|
|
134
|
+
else if( bytes>=1e6 ) {
|
|
135
|
+
unit = 'Mb';
|
|
136
|
+
value = bytes/1e6;
|
|
137
|
+
}
|
|
138
|
+
else if( bytes>=1e3 ) {
|
|
139
|
+
unit = 'Kb';
|
|
140
|
+
value = bytes/1e3;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
unit = 'bytes';
|
|
144
|
+
value = bytes;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return value.toFixed( 2 ) + unit;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function failure( ) {
|
|
151
|
+
if( cfg.failure ) {
|
|
152
|
+
cfg.failure( xhr.status, xhr.statusText, cfg.userData );
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function success( ) {
|
|
157
|
+
if( xhr.status>=200 && xhr.status<300 ) {
|
|
158
|
+
if( cfg.success ) {
|
|
159
|
+
try {
|
|
160
|
+
cfg.success( xhr.response, cfg.userData );
|
|
161
|
+
}
|
|
162
|
+
catch( e ) {
|
|
163
|
+
console.error( 'unhandled exception:', e );
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
failure( );
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if( formdata || method=='POST' ) {
|
|
173
|
+
xhr.send( params );
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
xhr.send( );
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return function( ) {
|
|
180
|
+
xhr.abort( );
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function buildQuery( params: any, getMethod: boolean ) {
|
|
185
|
+
|
|
186
|
+
if( !params ) {
|
|
187
|
+
return '';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let query = [];
|
|
191
|
+
for( let key in params ) {
|
|
192
|
+
|
|
193
|
+
let param = params[key];
|
|
194
|
+
|
|
195
|
+
// array
|
|
196
|
+
if( isArray(param) ) {
|
|
197
|
+
for( let i=0, n=param.length; i<n; i++ ) {
|
|
198
|
+
query.push( encodeURIComponent(key) + '[]=' + encodeURIComponent( ''+param[i] ) );
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// simple string ...
|
|
202
|
+
else {
|
|
203
|
+
|
|
204
|
+
if( param===undefined ) {
|
|
205
|
+
param = '';
|
|
206
|
+
}
|
|
207
|
+
query.push( encodeURIComponent(key) + '=' + encodeURIComponent(''+param) );
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
let result = query.join( '&' );
|
|
212
|
+
if( getMethod ) {
|
|
213
|
+
return '?' + result;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
//type Identity<T> = { [P in keyof T]: T[P] }
|
|
222
|
+
//type Replace<T, K extends keyof T, TReplace> = Identity<Pick<T, Exclude<keyof T, K>> & {
|
|
223
|
+
// [P in K] : TReplace
|
|
224
|
+
//}>
|
|
225
|
+
//type AjaxRequestInit = Replace< RequestInit, 'body', BodyInit | null | object | undefined >;
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
interface AjaxRequestInit extends Omit<RequestInit,'body'> {
|
|
229
|
+
body?: BodyInit | null | object;
|
|
230
|
+
noGenX?: boolean; // donot generate exception on error
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
export async function ajaxAsJSON( url: string, init?: AjaxRequestInit ) : Promise<any> {
|
|
235
|
+
let response = await ajax( url, init, 'application/json' );
|
|
236
|
+
return response.json( );
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export async function ajaxAsText( url: string, init?: AjaxRequestInit ) : Promise<any> {
|
|
240
|
+
let response = await ajax( url, init, 'text/plain' );
|
|
241
|
+
return response.text( );
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* use encodeURIComponent for elements in url
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
export async function ajax( url: string, init?: AjaxRequestInit, type?: string ) : Promise<Response> {
|
|
249
|
+
|
|
250
|
+
let options: AjaxRequestInit = {
|
|
251
|
+
method: 'GET',
|
|
252
|
+
headers: {
|
|
253
|
+
'X-Requested-With': 'XMLHttpRequest'
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if( type ) {
|
|
258
|
+
options.headers['Content-Type'] = type;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if( init ) {
|
|
262
|
+
options = { ...options, ...init };
|
|
263
|
+
|
|
264
|
+
if( init.body && !isString(init.body) ) {
|
|
265
|
+
let cvt = false;
|
|
266
|
+
if( isLiteralObject(init.body) ) {
|
|
267
|
+
cvt = true;
|
|
268
|
+
}
|
|
269
|
+
else if( !(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer) && !(init.body instanceof FormData) &&
|
|
270
|
+
!(init.body instanceof URLSearchParams) && !(init.body instanceof ReadableStream) )
|
|
271
|
+
{
|
|
272
|
+
cvt = true;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if( cvt ) {
|
|
276
|
+
options.body = JSON.stringify( init.body );
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
options.body = init.body;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
let response = await fetch( url, options as RequestInit );
|
|
285
|
+
|
|
286
|
+
if( init && init.noGenX ) {
|
|
287
|
+
return response;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
if( !response.ok ) {
|
|
291
|
+
throw new NetworkError( response );
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return response;
|
|
295
|
+
}
|
|
296
|
+
}
|
package/src/router.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
type Callback = (request: { path: string }) => void;
|
|
3
|
+
|
|
4
|
+
interface Route {
|
|
5
|
+
uri: string;
|
|
6
|
+
callback: Callback;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class Router {
|
|
10
|
+
|
|
11
|
+
private routes: Route[];
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
this.routes = [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get(uri, callback) {
|
|
18
|
+
|
|
19
|
+
// throw an error if the route uri already exists to avoid confilicting routes
|
|
20
|
+
this.routes.forEach(route => {
|
|
21
|
+
if (route.uri === uri) {
|
|
22
|
+
throw new Error(`the uri ${route.uri} already exists`);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
this.routes.push({
|
|
27
|
+
uri,
|
|
28
|
+
callback
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
init() {
|
|
33
|
+
this.routes.some(route => {
|
|
34
|
+
|
|
35
|
+
let regEx = new RegExp(`^${route.uri}$`);
|
|
36
|
+
let path = window.location.pathname;
|
|
37
|
+
|
|
38
|
+
if (path.match(regEx)) {
|
|
39
|
+
return route.callback({ path });
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/settings.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file local_storage.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 { host } from './hosts/host';
|
|
27
|
+
|
|
28
|
+
export class Settings {
|
|
29
|
+
|
|
30
|
+
private m_data: any;
|
|
31
|
+
private m_name: string;
|
|
32
|
+
|
|
33
|
+
constructor( name?: string ) {
|
|
34
|
+
this.m_data = null;
|
|
35
|
+
this.m_name = name ?? 'settings';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
set( name: string, value: any ) {
|
|
39
|
+
this._load( );
|
|
40
|
+
this.m_data[name] = value;
|
|
41
|
+
this._save( );
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get( name: string, defValue? ) : any {
|
|
45
|
+
this._load( );
|
|
46
|
+
return this.m_data[name] ?? defValue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private _save( ) {
|
|
50
|
+
let data = JSON.stringify(this.m_data);
|
|
51
|
+
host.writeLocalStorage( this.m_name, data );
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private _load( ) {
|
|
55
|
+
if( this.m_data ) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.m_data = {};
|
|
60
|
+
|
|
61
|
+
let data = host.readLocalStorage( this.m_name );
|
|
62
|
+
if( data!==null ) {
|
|
63
|
+
data = JSON.parse( data );
|
|
64
|
+
if( data ) {
|
|
65
|
+
this.m_data = data;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.info('There was an error attempting to read your settings.');
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// console.info('There was an error attempting to read your settings.');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file sidebarview.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, Flex } from './component'
|
|
27
|
+
import { HLayout, VLayout } from './layout'
|
|
28
|
+
import { Button } from './button'
|
|
29
|
+
import { CardView, CardViewProps, ICardViewItem } from './cardview'
|
|
30
|
+
|
|
31
|
+
export interface SideBarItem extends ICardViewItem {
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface SideBarProps extends CardViewProps {
|
|
35
|
+
bar_sizable?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export class SideBarView extends CardView {
|
|
43
|
+
m_sidebar: VLayout;
|
|
44
|
+
m_content: Component;
|
|
45
|
+
|
|
46
|
+
constructor( props: SideBarProps ) {
|
|
47
|
+
|
|
48
|
+
super( props );
|
|
49
|
+
|
|
50
|
+
this.addClass( '@hlayout' );
|
|
51
|
+
|
|
52
|
+
this.m_sidebar = new VLayout( {
|
|
53
|
+
cls: '@side-bar',
|
|
54
|
+
sizable: props.bar_sizable ? 'right' : undefined,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
this.m_content = new HLayout( { flex: 1, cls: '@tab-container' } );
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** @ignore */
|
|
61
|
+
render() {
|
|
62
|
+
|
|
63
|
+
let tabs = [];
|
|
64
|
+
|
|
65
|
+
this.m_cards.forEach( (p) => {
|
|
66
|
+
tabs.push( p.selector );
|
|
67
|
+
} );
|
|
68
|
+
|
|
69
|
+
this.m_sidebar.setContent( new VLayout( {
|
|
70
|
+
flex: 1,
|
|
71
|
+
cls: 'content',
|
|
72
|
+
content: tabs
|
|
73
|
+
}) );
|
|
74
|
+
|
|
75
|
+
this.setContent( [
|
|
76
|
+
this.m_sidebar,
|
|
77
|
+
this.m_content
|
|
78
|
+
] );
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected _prepareSelector( card: ICardViewItem ): Component {
|
|
82
|
+
return new Button( {
|
|
83
|
+
text: card.title,
|
|
84
|
+
icon: card.icon,
|
|
85
|
+
tooltip: card.title,
|
|
86
|
+
click: ( ) => { this.switchTo( card.name); }
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
protected _preparePage( page: Component ) {
|
|
91
|
+
super._preparePage( page );
|
|
92
|
+
|
|
93
|
+
if( !page.dom ) {
|
|
94
|
+
this.m_content.appendChild( page );
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|