x4js 1.4.4 → 1.4.5
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 +141 -0
- package/lib/base64.d.ts +31 -0
- package/lib/base64.js +139 -0
- package/lib/base_component.d.ts +64 -0
- package/lib/base_component.js +81 -0
- package/lib/button.d.ts +145 -0
- package/lib/button.js +241 -0
- package/lib/calendar.d.ts +77 -0
- package/lib/calendar.js +241 -0
- package/lib/canvas.d.ts +88 -0
- package/lib/canvas.js +358 -0
- package/lib/cardview.d.ts +83 -0
- package/lib/cardview.js +156 -0
- package/lib/checkbox.d.ts +72 -0
- package/lib/checkbox.js +130 -0
- package/lib/color.d.ts +144 -0
- package/lib/color.js +588 -0
- package/lib/colorpicker.js +86 -80
- package/lib/combobox.js +26 -22
- package/lib/component.d.ts +572 -0
- package/lib/component.js +1729 -0
- package/lib/datastore.js +29 -20
- package/lib/dialog.js +41 -36
- package/lib/dom_events.d.ts +284 -0
- package/lib/dom_events.js +14 -0
- package/lib/drag_manager.js +4 -1
- package/lib/drawtext.js +9 -5
- package/lib/fileupload.js +19 -12
- package/lib/form.js +29 -25
- package/lib/formatters.js +19 -10
- package/lib/gridview.js +40 -35
- package/lib/hosts/host.d.ts +44 -0
- package/lib/hosts/host.js +73 -0
- package/lib/i18n.d.ts +67 -0
- package/lib/i18n.js +175 -0
- package/lib/icon.d.ts +56 -0
- package/lib/icon.js +178 -0
- package/lib/image.js +7 -3
- package/lib/index.js +71 -55
- package/lib/input.d.ts +86 -0
- package/lib/input.js +176 -0
- package/lib/label.d.ts +54 -0
- package/lib/label.js +90 -0
- package/lib/layout.d.ts +77 -0
- package/lib/layout.js +271 -0
- package/lib/link.js +9 -5
- package/lib/listview.js +34 -27
- package/lib/md5.js +5 -1
- package/lib/menu.d.ts +122 -0
- package/lib/menu.js +284 -0
- package/lib/messagebox.js +22 -17
- package/lib/panel.js +13 -9
- package/lib/popup.d.ts +71 -0
- package/lib/popup.js +378 -0
- package/lib/property_editor.js +20 -16
- package/lib/radiobtn.js +13 -9
- package/lib/rating.js +13 -9
- package/lib/request.js +16 -9
- package/lib/router.js +5 -1
- package/lib/settings.d.ts +33 -0
- package/lib/settings.js +67 -0
- package/lib/sidebarview.js +12 -8
- package/lib/smartedit.js +16 -11
- package/lib/spreadsheet.js +35 -31
- package/lib/styles.d.ts +81 -0
- package/lib/styles.js +268 -0
- package/lib/svgcomponent.js +8 -3
- package/lib/tabbar.js +10 -6
- package/lib/tabview.js +10 -6
- package/lib/textarea.js +10 -6
- package/lib/textedit.js +39 -35
- package/lib/texthiliter.js +8 -4
- package/lib/toaster.js +8 -4
- package/lib/tools.d.ts +382 -0
- package/lib/tools.js +1142 -0
- package/lib/tooltips.js +14 -9
- package/lib/treeview.js +30 -26
- package/lib/x4_events.d.ts +253 -0
- package/lib/x4_events.js +375 -0
- package/package.json +1 -1
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file host.ts
|
|
4
|
+
* @author Etienne Cochard
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
7
|
+
*
|
|
8
|
+
* This program is free software; you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License as published by
|
|
10
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
**/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.host = exports.Host = void 0;
|
|
22
|
+
class Host {
|
|
23
|
+
constructor() {
|
|
24
|
+
exports.host = this;
|
|
25
|
+
}
|
|
26
|
+
makePath(...els) {
|
|
27
|
+
return els.join('/');
|
|
28
|
+
}
|
|
29
|
+
readBinary(path) {
|
|
30
|
+
return Promise.reject('not imp');
|
|
31
|
+
}
|
|
32
|
+
writeBinary(path, data) {
|
|
33
|
+
return Promise.reject('not imp');
|
|
34
|
+
}
|
|
35
|
+
readUtf8(path) {
|
|
36
|
+
return Promise.reject('not imp');
|
|
37
|
+
}
|
|
38
|
+
writeUtf8(path, data) {
|
|
39
|
+
return Promise.reject('not imp');
|
|
40
|
+
}
|
|
41
|
+
compress(data) {
|
|
42
|
+
return Promise.reject('not imp');
|
|
43
|
+
}
|
|
44
|
+
decompress(data) {
|
|
45
|
+
return Promise.reject('not imp');
|
|
46
|
+
}
|
|
47
|
+
readLocalStorage(name) {
|
|
48
|
+
return localStorage.getItem(name);
|
|
49
|
+
}
|
|
50
|
+
writeLocalStorage(name, data) {
|
|
51
|
+
localStorage.setItem(name, data);
|
|
52
|
+
}
|
|
53
|
+
stat(name) {
|
|
54
|
+
throw 'not imp';
|
|
55
|
+
}
|
|
56
|
+
readDir(path) {
|
|
57
|
+
throw 'not imp';
|
|
58
|
+
}
|
|
59
|
+
require(name) {
|
|
60
|
+
throw 'not imp';
|
|
61
|
+
}
|
|
62
|
+
cwd() {
|
|
63
|
+
throw 'not imp';
|
|
64
|
+
}
|
|
65
|
+
getPath(type) {
|
|
66
|
+
throw 'not imp';
|
|
67
|
+
}
|
|
68
|
+
getPathPart(path, type) {
|
|
69
|
+
throw 'not imp';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.Host = Host;
|
|
73
|
+
exports.host = null;
|
package/lib/i18n.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file i18n.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
|
+
* current language
|
|
27
|
+
* FR by default
|
|
28
|
+
* @example ```typescript
|
|
29
|
+
* console.log( _tr.global.ok );
|
|
30
|
+
*/
|
|
31
|
+
export declare let _tr: any;
|
|
32
|
+
/**
|
|
33
|
+
* check if the language is known
|
|
34
|
+
* @param name - language name to test
|
|
35
|
+
* @example ```typescript
|
|
36
|
+
* if( isLanguage('fr') ) {
|
|
37
|
+
* }
|
|
38
|
+
*/
|
|
39
|
+
export declare function isLanguage(name: any): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* select the current language
|
|
42
|
+
* @param name - language name
|
|
43
|
+
* @example ```typescript
|
|
44
|
+
* selectLanguage( 'en' );
|
|
45
|
+
*/
|
|
46
|
+
export declare function selectLanguage(name: any): void;
|
|
47
|
+
/**
|
|
48
|
+
* define a translation
|
|
49
|
+
* you can also patch 'global' elements witch are defined by x4
|
|
50
|
+
* @param name - language name
|
|
51
|
+
* @param definition - definition of the language
|
|
52
|
+
* @example ```typescript
|
|
53
|
+
* setTranslation( 'fr', {
|
|
54
|
+
* this_is_an_example: 'ceci est un exemple',
|
|
55
|
+
* this_is: {
|
|
56
|
+
* another_example: 'ceci est un autre exemple'
|
|
57
|
+
* },
|
|
58
|
+
* global: {
|
|
59
|
+
* ok: 'O.K.'
|
|
60
|
+
* }
|
|
61
|
+
* });
|
|
62
|
+
* console.log( _tr.this_is_an_example ); // defined by the previous line
|
|
63
|
+
* selectLanguage( 'en' );
|
|
64
|
+
* console.log( _tr.this_is_an_example ); // 'en' do not define this, so we get 'fr' one
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
export declare function extendTranslation(name: any, definition: any): void;
|
package/lib/i18n.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ___ ___ __
|
|
4
|
+
* \ \/ / / _
|
|
5
|
+
* \ / /_| |_
|
|
6
|
+
* / \____ _|
|
|
7
|
+
* /__/\__\ |_|
|
|
8
|
+
*
|
|
9
|
+
* @file i18n.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.extendTranslation = exports.selectLanguage = exports.isLanguage = exports._tr = void 0;
|
|
28
|
+
/**
|
|
29
|
+
* language definition
|
|
30
|
+
* x4 specific strings
|
|
31
|
+
*/
|
|
32
|
+
let fr = {
|
|
33
|
+
global: {
|
|
34
|
+
ok: 'OK',
|
|
35
|
+
cancel: 'Annuler',
|
|
36
|
+
ignore: 'Ignorer',
|
|
37
|
+
yes: 'Oui',
|
|
38
|
+
no: 'Non',
|
|
39
|
+
open: 'Ouvrir',
|
|
40
|
+
new: 'Nouveau',
|
|
41
|
+
delete: 'Supprimer',
|
|
42
|
+
close: 'Fermer',
|
|
43
|
+
save: 'Enregistrer',
|
|
44
|
+
search: 'Rechercher',
|
|
45
|
+
search_tip: 'Saisissez le texte à rechercher. <b>Enter</b> pour lancer la recherche. <b>Esc</b> pour annuler.',
|
|
46
|
+
required_field: "information requise",
|
|
47
|
+
invalid_format: "format invalide",
|
|
48
|
+
invalid_email: 'adresse mail invalide',
|
|
49
|
+
invalid_number: 'valeur numérique invalide',
|
|
50
|
+
diff_date_seconds: '{0} seconds',
|
|
51
|
+
diff_date_minutes: '{0} minutes',
|
|
52
|
+
diff_date_hours: '{0} hours',
|
|
53
|
+
invalid_date: 'Date non reconnue ({0})',
|
|
54
|
+
empty_list: 'Liste vide',
|
|
55
|
+
date_input_formats: 'd/m/y|d.m.y|d m y|d-m-y|dmy',
|
|
56
|
+
date_format: 'D/M/Y',
|
|
57
|
+
day_short: ['dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam'],
|
|
58
|
+
day_long: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
|
|
59
|
+
month_short: ['jan', 'fév', 'mar', 'avr', 'mai', 'jun', 'jui', 'aoû', 'sep', 'oct', 'nov', 'déc'],
|
|
60
|
+
month_long: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
|
|
61
|
+
property: 'Propriété',
|
|
62
|
+
value: 'Valeur',
|
|
63
|
+
err_403: `Vous n'avez pas les droits suffisants pour effectuer cette action`,
|
|
64
|
+
copy: 'Copier',
|
|
65
|
+
cut: 'Couper',
|
|
66
|
+
paste: 'Coller'
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
/** @ignore */
|
|
70
|
+
let en = {
|
|
71
|
+
global: {
|
|
72
|
+
ok: 'OK',
|
|
73
|
+
cancel: 'Cancel',
|
|
74
|
+
ignore: 'Ignore',
|
|
75
|
+
yes: 'Yes',
|
|
76
|
+
no: 'No',
|
|
77
|
+
required_field: "required field",
|
|
78
|
+
invalid_format: "invalid format",
|
|
79
|
+
diff_date_seconds: '{0} seconds',
|
|
80
|
+
diff_date_minutes: '{0} minutes',
|
|
81
|
+
diff_date_hours: '{0} hours',
|
|
82
|
+
invalid_date: 'Bad date format {0}',
|
|
83
|
+
copy: 'Copy',
|
|
84
|
+
cut: 'Cut',
|
|
85
|
+
paste: 'Paste'
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/** @ignore */
|
|
89
|
+
let all_langs = {
|
|
90
|
+
'fr': fr,
|
|
91
|
+
'en': _mk_proxy(_patch({}, en))
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* current language
|
|
95
|
+
* FR by default
|
|
96
|
+
* @example ```typescript
|
|
97
|
+
* console.log( _tr.global.ok );
|
|
98
|
+
*/
|
|
99
|
+
exports._tr = all_langs['fr'];
|
|
100
|
+
/**
|
|
101
|
+
* check if the language is known
|
|
102
|
+
* @param name - language name to test
|
|
103
|
+
* @example ```typescript
|
|
104
|
+
* if( isLanguage('fr') ) {
|
|
105
|
+
* }
|
|
106
|
+
*/
|
|
107
|
+
function isLanguage(name) {
|
|
108
|
+
return all_langs[name] !== undefined;
|
|
109
|
+
}
|
|
110
|
+
exports.isLanguage = isLanguage;
|
|
111
|
+
/**
|
|
112
|
+
* select the current language
|
|
113
|
+
* @param name - language name
|
|
114
|
+
* @example ```typescript
|
|
115
|
+
* selectLanguage( 'en' );
|
|
116
|
+
*/
|
|
117
|
+
function selectLanguage(name) {
|
|
118
|
+
if (!isLanguage(name)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
exports._tr = all_langs[name];
|
|
122
|
+
}
|
|
123
|
+
exports.selectLanguage = selectLanguage;
|
|
124
|
+
/**
|
|
125
|
+
* define a translation
|
|
126
|
+
* you can also patch 'global' elements witch are defined by x4
|
|
127
|
+
* @param name - language name
|
|
128
|
+
* @param definition - definition of the language
|
|
129
|
+
* @example ```typescript
|
|
130
|
+
* setTranslation( 'fr', {
|
|
131
|
+
* this_is_an_example: 'ceci est un exemple',
|
|
132
|
+
* this_is: {
|
|
133
|
+
* another_example: 'ceci est un autre exemple'
|
|
134
|
+
* },
|
|
135
|
+
* global: {
|
|
136
|
+
* ok: 'O.K.'
|
|
137
|
+
* }
|
|
138
|
+
* });
|
|
139
|
+
* console.log( _tr.this_is_an_example ); // defined by the previous line
|
|
140
|
+
* selectLanguage( 'en' );
|
|
141
|
+
* console.log( _tr.this_is_an_example ); // 'en' do not define this, so we get 'fr' one
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
144
|
+
function extendTranslation(name, definition) {
|
|
145
|
+
if (!isLanguage(name)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
_patch(all_langs[name], definition);
|
|
149
|
+
}
|
|
150
|
+
exports.extendTranslation = extendTranslation;
|
|
151
|
+
function _patch(obj, by) {
|
|
152
|
+
for (let n in by) {
|
|
153
|
+
if (obj[n] instanceof Object) {
|
|
154
|
+
_patch(obj[n], by[n]);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
obj[n] = by[n];
|
|
158
|
+
if (obj[n] instanceof Object) {
|
|
159
|
+
obj[n] = _mk_proxy(obj[n]);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return obj;
|
|
164
|
+
}
|
|
165
|
+
function _mk_proxy(obj) {
|
|
166
|
+
return new Proxy(obj, {
|
|
167
|
+
get: function (target, prop, receiver) {
|
|
168
|
+
let value = target[prop];
|
|
169
|
+
if (value === undefined) {
|
|
170
|
+
return fr[prop];
|
|
171
|
+
}
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
package/lib/icon.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file icon.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 } from './component';
|
|
26
|
+
import { BasicEvent } from './x4_events';
|
|
27
|
+
export declare type IconID = string | number;
|
|
28
|
+
export interface IconProps extends CProps {
|
|
29
|
+
icon: IconID;
|
|
30
|
+
size?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface EvLoaded extends BasicEvent {
|
|
33
|
+
url: string;
|
|
34
|
+
svg: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function EvLoaded(url: string, svg: string, context?: any): EvLoaded;
|
|
37
|
+
/**
|
|
38
|
+
* standard icon
|
|
39
|
+
*/
|
|
40
|
+
export declare class Icon extends Component<IconProps> {
|
|
41
|
+
private m_icon;
|
|
42
|
+
private m_iconName;
|
|
43
|
+
constructor(props: IconProps);
|
|
44
|
+
private _setIcon;
|
|
45
|
+
/**
|
|
46
|
+
* change the icon
|
|
47
|
+
* @param icon - new icon
|
|
48
|
+
*/
|
|
49
|
+
set icon(icon: IconID);
|
|
50
|
+
get icon(): IconID;
|
|
51
|
+
private _setSVG;
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
private static icon_cache;
|
|
56
|
+
}
|
package/lib/icon.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ___ ___ __
|
|
4
|
+
* \ \/ / / _
|
|
5
|
+
* \ / /_| |_
|
|
6
|
+
* / \____ _|
|
|
7
|
+
* /__/\__\ |_|
|
|
8
|
+
*
|
|
9
|
+
* @file icon.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.Icon = exports.EvLoaded = void 0;
|
|
28
|
+
const component_1 = require("./component");
|
|
29
|
+
const styles_1 = require("./styles");
|
|
30
|
+
const tools_1 = require("./tools");
|
|
31
|
+
const x4_events_1 = require("./x4_events");
|
|
32
|
+
function EvLoaded(url, svg, context = null) {
|
|
33
|
+
return (0, x4_events_1.BasicEvent)({ url, svg, context });
|
|
34
|
+
}
|
|
35
|
+
exports.EvLoaded = EvLoaded;
|
|
36
|
+
class Loader extends x4_events_1.EventSource {
|
|
37
|
+
svgs;
|
|
38
|
+
constructor() {
|
|
39
|
+
super();
|
|
40
|
+
this.svgs = new Map();
|
|
41
|
+
}
|
|
42
|
+
load(url) {
|
|
43
|
+
if (this.svgs.has(url)) {
|
|
44
|
+
const svg = this.svgs.get(url);
|
|
45
|
+
if (svg) {
|
|
46
|
+
//console.log( 'cached=', url );
|
|
47
|
+
this.signal('loaded', EvLoaded(url, svg));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// mark it as loading
|
|
52
|
+
this.svgs.set(url, null);
|
|
53
|
+
// then start loading
|
|
54
|
+
const _load = async (url) => {
|
|
55
|
+
const r = await fetch(url);
|
|
56
|
+
if (r.ok) {
|
|
57
|
+
const svg = await r.text();
|
|
58
|
+
this.svgs.set(url, svg);
|
|
59
|
+
//console.log( 'signal=', url );
|
|
60
|
+
this.signal('loaded', EvLoaded(url, svg));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
_load(url);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const svgLoader = new Loader();
|
|
68
|
+
/**
|
|
69
|
+
* standard icon
|
|
70
|
+
*/
|
|
71
|
+
class Icon extends component_1.Component {
|
|
72
|
+
m_icon;
|
|
73
|
+
m_iconName;
|
|
74
|
+
constructor(props) {
|
|
75
|
+
super(props);
|
|
76
|
+
this._setIcon(props.icon, false);
|
|
77
|
+
if (props.size) {
|
|
78
|
+
this.setStyleValue('fontSize', props.size);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
_setIcon(icon, remove_old) {
|
|
82
|
+
const reUrl = /\s*url\s*\(\s*(.+)\s*\)\s*/gi;
|
|
83
|
+
const reSvg = /\s*svg\s*\(\s*(.+)\s*\)\s*/gi;
|
|
84
|
+
const reSvg2 = /(.*\.svg)$/gi;
|
|
85
|
+
const reCls = /\s*cls\s*\(\s*(.+)\s*\)\s*/gi;
|
|
86
|
+
if (!icon) {
|
|
87
|
+
this.m_iconName = '';
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.removeClass('@svg');
|
|
91
|
+
let name, url;
|
|
92
|
+
if (typeof (icon) === 'number') {
|
|
93
|
+
icon = icon.toString(16);
|
|
94
|
+
name = icon;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
let match_svg = reSvg.exec(icon) || reSvg2.exec(icon);
|
|
98
|
+
if (match_svg) {
|
|
99
|
+
const url = match_svg[1].trim();
|
|
100
|
+
this._setSVG(url);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let match_cls = reCls.exec(icon);
|
|
104
|
+
if (match_cls) {
|
|
105
|
+
const classes = match_cls[1].trim();
|
|
106
|
+
this.addClass(classes);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
let match_url = reUrl.exec(icon);
|
|
110
|
+
if (match_url) {
|
|
111
|
+
url = match_url[1].trim();
|
|
112
|
+
name = url.replace(/[/\\\.\* ]/g, '_');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
name = icon;
|
|
116
|
+
icon = styles_1.Stylesheet.getVar('icon-' + icon);
|
|
117
|
+
if (icon == '' || icon === undefined) {
|
|
118
|
+
// name your icon 'icon-xxx'
|
|
119
|
+
// ex:
|
|
120
|
+
// :root { --icon-zoom-p: f00e; }
|
|
121
|
+
console.assert(false);
|
|
122
|
+
icon = '0';
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
this.m_iconName = name;
|
|
127
|
+
if (this.m_icon === icon) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let css = component_1.Component.getCss(), rulename;
|
|
131
|
+
if (remove_old && this.m_icon) {
|
|
132
|
+
rulename = 'icon-' + name;
|
|
133
|
+
this.removeClass(rulename);
|
|
134
|
+
}
|
|
135
|
+
// generate dynamic css icon rule
|
|
136
|
+
rulename = 'icon-' + name;
|
|
137
|
+
if (Icon.icon_cache[rulename] === undefined) {
|
|
138
|
+
Icon.icon_cache[rulename] = true;
|
|
139
|
+
let rule;
|
|
140
|
+
if (url) {
|
|
141
|
+
rule = `display: block; content: ' '; background-image: url(${url}); background-size: contain; width: 100%; height: 100%; background-repeat: no-repeat; color: white;`;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
rule = `content: "\\${icon}";`;
|
|
145
|
+
}
|
|
146
|
+
css.setRule(rulename, `.${rulename}::before {${rule}}`);
|
|
147
|
+
}
|
|
148
|
+
this.addClass(rulename);
|
|
149
|
+
this.m_icon = icon;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* change the icon
|
|
153
|
+
* @param icon - new icon
|
|
154
|
+
*/
|
|
155
|
+
set icon(icon) {
|
|
156
|
+
this._setIcon(icon, true);
|
|
157
|
+
}
|
|
158
|
+
get icon() {
|
|
159
|
+
return this.m_iconName;
|
|
160
|
+
}
|
|
161
|
+
_setSVG(url) {
|
|
162
|
+
const set = (ev) => {
|
|
163
|
+
//console.log( 'set=', ev.url, 'url=', url );
|
|
164
|
+
if (ev.url == url) {
|
|
165
|
+
this.addClass('@svg-icon');
|
|
166
|
+
this.setContent(tools_1.HtmlString.from(ev.svg), false);
|
|
167
|
+
svgLoader.off('loaded', set);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
svgLoader.on('loaded', set);
|
|
171
|
+
svgLoader.load(url);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
176
|
+
static icon_cache = [];
|
|
177
|
+
}
|
|
178
|
+
exports.Icon = Icon;
|
package/lib/image.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* ___ ___ __
|
|
3
4
|
* \ \/ / / _
|
|
@@ -22,7 +23,9 @@
|
|
|
22
23
|
*
|
|
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/>.
|
|
24
25
|
**/
|
|
25
|
-
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Image = void 0;
|
|
28
|
+
const component_1 = require("./component");
|
|
26
29
|
const emptyImageSrc = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
|
27
30
|
function _isStaticImage(src) {
|
|
28
31
|
return src.substr(0, 5) == 'data:';
|
|
@@ -30,7 +33,7 @@ function _isStaticImage(src) {
|
|
|
30
33
|
/**
|
|
31
34
|
* Standard image class
|
|
32
35
|
*/
|
|
33
|
-
|
|
36
|
+
class Image extends component_1.Component {
|
|
34
37
|
m_created;
|
|
35
38
|
m_lazysrc; // expected
|
|
36
39
|
constructor(props) {
|
|
@@ -51,7 +54,7 @@ export class Image extends Component {
|
|
|
51
54
|
/** @ignore */
|
|
52
55
|
render() {
|
|
53
56
|
let mp = this.m_props;
|
|
54
|
-
const img = new Component({
|
|
57
|
+
const img = new component_1.Component({
|
|
55
58
|
tag: 'img',
|
|
56
59
|
attrs: {
|
|
57
60
|
draggable: false,
|
|
@@ -147,3 +150,4 @@ export class Image extends Component {
|
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
152
|
}
|
|
153
|
+
exports.Image = Image;
|