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,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file radiobtn.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, EventCallback } from './x4_events';
|
|
27
|
+
import { IconID } from './icon';
|
|
28
|
+
import { Input } from './input';
|
|
29
|
+
interface RadioBtnEventMap extends CEventMap {
|
|
30
|
+
change?: EvChange;
|
|
31
|
+
}
|
|
32
|
+
export interface RadioBtnProps extends CProps {
|
|
33
|
+
group: string;
|
|
34
|
+
value: string;
|
|
35
|
+
tabIndex?: number | boolean;
|
|
36
|
+
name?: string;
|
|
37
|
+
icon?: IconID;
|
|
38
|
+
text?: string;
|
|
39
|
+
checked?: boolean;
|
|
40
|
+
labelWidth?: number | 'flex';
|
|
41
|
+
align?: 'left' | 'right';
|
|
42
|
+
change?: EventCallback<EvChange>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Standard RadioBtn
|
|
46
|
+
*/
|
|
47
|
+
export declare class RadioBtn extends Component<RadioBtnProps, RadioBtnEventMap> {
|
|
48
|
+
protected m_ui_input: Input;
|
|
49
|
+
constructor(props: RadioBtnProps);
|
|
50
|
+
/** @ignore */
|
|
51
|
+
render(props: RadioBtnProps): void;
|
|
52
|
+
/**
|
|
53
|
+
* check state changed
|
|
54
|
+
*/
|
|
55
|
+
private _change;
|
|
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 | import("./tools").HtmlString;
|
|
66
|
+
set text(text: string | import("./tools").HtmlString);
|
|
67
|
+
}
|
|
68
|
+
export {};
|
package/lib/radiobtn.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file radiobtn.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
import { Component } from './component';
|
|
26
|
+
import { EvChange } from './x4_events';
|
|
27
|
+
import { Input } from './input';
|
|
28
|
+
import { Label } from './label';
|
|
29
|
+
/**
|
|
30
|
+
* Standard RadioBtn
|
|
31
|
+
*/
|
|
32
|
+
export class RadioBtn extends Component {
|
|
33
|
+
m_ui_input; // todo: remove that / use ref
|
|
34
|
+
constructor(props) {
|
|
35
|
+
super(props);
|
|
36
|
+
this.mapPropEvents(props, 'change');
|
|
37
|
+
}
|
|
38
|
+
/** @ignore */
|
|
39
|
+
render(props) {
|
|
40
|
+
let text = props.text ?? '';
|
|
41
|
+
let name = props.name ?? props.group;
|
|
42
|
+
let labelWidth = props.labelWidth ?? -1;
|
|
43
|
+
let checked = props.checked ?? false;
|
|
44
|
+
let align = props.align ?? 'left';
|
|
45
|
+
let value = props.value;
|
|
46
|
+
let icon = props.icon;
|
|
47
|
+
this.addClass('@hlayout');
|
|
48
|
+
this.setProp('tag', 'label');
|
|
49
|
+
this.addClass(align);
|
|
50
|
+
this._setTabIndex(props.tabIndex);
|
|
51
|
+
if (checked) {
|
|
52
|
+
this.addClass('checked');
|
|
53
|
+
}
|
|
54
|
+
this.setContent([
|
|
55
|
+
this.m_ui_input = new Input({
|
|
56
|
+
type: 'radio',
|
|
57
|
+
name: name,
|
|
58
|
+
tabIndex: props.tabIndex,
|
|
59
|
+
value: value,
|
|
60
|
+
attrs: {
|
|
61
|
+
checked: checked ? '' : undefined
|
|
62
|
+
},
|
|
63
|
+
dom_events: {
|
|
64
|
+
change: () => this._change(),
|
|
65
|
+
focus: () => this.m_ui_input.focus(),
|
|
66
|
+
}
|
|
67
|
+
}),
|
|
68
|
+
new Label({
|
|
69
|
+
ref: 'label',
|
|
70
|
+
icon: icon,
|
|
71
|
+
text: text,
|
|
72
|
+
width: labelWidth === 'flex' ? undefined : labelWidth,
|
|
73
|
+
flex: labelWidth === 'flex' ? 1 : undefined,
|
|
74
|
+
style: {
|
|
75
|
+
order: align == 'right' ? -1 : undefined,
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* check state changed
|
|
82
|
+
*/
|
|
83
|
+
_change() {
|
|
84
|
+
let props = this.m_props;
|
|
85
|
+
let query = '.x-input[name=' + props.name + ']';
|
|
86
|
+
let nlist = document.querySelectorAll(query); //todo: document ?
|
|
87
|
+
nlist.forEach((dom) => {
|
|
88
|
+
let radio = Component.getElement(dom, RadioBtn);
|
|
89
|
+
radio.removeClass('checked');
|
|
90
|
+
});
|
|
91
|
+
let dom = this.m_ui_input.dom;
|
|
92
|
+
this.setClass('checked', dom.checked);
|
|
93
|
+
this.emit('change', EvChange(true));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @return the checked value
|
|
97
|
+
*/
|
|
98
|
+
get check() {
|
|
99
|
+
if (this.m_ui_input) {
|
|
100
|
+
return this.m_ui_input.dom.checked;
|
|
101
|
+
}
|
|
102
|
+
return this.m_props.checked;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* change the checked value
|
|
106
|
+
* @param {boolean} ck new checked value
|
|
107
|
+
*/
|
|
108
|
+
set check(ck) {
|
|
109
|
+
let dom = this.m_ui_input.dom;
|
|
110
|
+
if (ck) {
|
|
111
|
+
//this.addClass( 'checked' );
|
|
112
|
+
if (dom) {
|
|
113
|
+
dom.checked = true;
|
|
114
|
+
}
|
|
115
|
+
this.m_props.checked = true;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
//this.removeClass( 'checked' );
|
|
119
|
+
if (dom) {
|
|
120
|
+
dom.checked = false;
|
|
121
|
+
}
|
|
122
|
+
this.m_props.checked = false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
get text() {
|
|
126
|
+
return this.itemWithRef('label').text;
|
|
127
|
+
}
|
|
128
|
+
set text(text) {
|
|
129
|
+
this.itemWithRef('label').text = text;
|
|
130
|
+
}
|
|
131
|
+
}
|
package/lib/rating.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file rating.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 { CProps, ContainerEventMap } from './component';
|
|
26
|
+
import { HLayout } from './layout';
|
|
27
|
+
import { EvChange, EventCallback } from './x4_events';
|
|
28
|
+
interface RatingEventMap extends ContainerEventMap {
|
|
29
|
+
change: EvChange;
|
|
30
|
+
}
|
|
31
|
+
export interface RatingProps extends CProps<RatingEventMap> {
|
|
32
|
+
steps?: number;
|
|
33
|
+
value?: number;
|
|
34
|
+
shape?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
change?: EventCallback<EvChange>;
|
|
37
|
+
}
|
|
38
|
+
export declare class Rating extends HLayout<RatingProps, RatingEventMap> {
|
|
39
|
+
private m_els;
|
|
40
|
+
private m_input;
|
|
41
|
+
constructor(props: RatingProps);
|
|
42
|
+
render(props: RatingProps): void;
|
|
43
|
+
getValue(): number;
|
|
44
|
+
set value(v: number);
|
|
45
|
+
set steps(n: number);
|
|
46
|
+
set shape(shape: string);
|
|
47
|
+
private _onclick;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
package/lib/rating.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file rating.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
import { Component } from './component';
|
|
26
|
+
import { HLayout } from './layout';
|
|
27
|
+
import { Input } from './input';
|
|
28
|
+
import { EvChange } from './x4_events';
|
|
29
|
+
export class Rating extends HLayout {
|
|
30
|
+
m_els;
|
|
31
|
+
m_input;
|
|
32
|
+
constructor(props) {
|
|
33
|
+
super(props);
|
|
34
|
+
props.steps = props.steps ?? 5;
|
|
35
|
+
}
|
|
36
|
+
render(props) {
|
|
37
|
+
let shape = props.shape ?? 'star';
|
|
38
|
+
let value = props.value ?? 0;
|
|
39
|
+
this.m_input = new Input({
|
|
40
|
+
cls: '@hidden',
|
|
41
|
+
name: props.name,
|
|
42
|
+
value: '' + value
|
|
43
|
+
});
|
|
44
|
+
this.addClass(shape);
|
|
45
|
+
this.setDomEvent('click', (e) => this._onclick(e));
|
|
46
|
+
this.m_els = [];
|
|
47
|
+
for (let i = 0; i < props.steps; i++) {
|
|
48
|
+
let cls = 'item';
|
|
49
|
+
if (i + 1 <= value) {
|
|
50
|
+
cls += ' checked';
|
|
51
|
+
}
|
|
52
|
+
let c = new Component({
|
|
53
|
+
tag: 'option',
|
|
54
|
+
cls,
|
|
55
|
+
data: { value: i + 1 }
|
|
56
|
+
});
|
|
57
|
+
this.m_els.push(c);
|
|
58
|
+
}
|
|
59
|
+
this.m_els.push(this.m_input);
|
|
60
|
+
this.setContent(this.m_els);
|
|
61
|
+
}
|
|
62
|
+
getValue() {
|
|
63
|
+
return this.m_props.value ?? 0;
|
|
64
|
+
}
|
|
65
|
+
set value(v) {
|
|
66
|
+
this.m_props.value = v;
|
|
67
|
+
for (let c = 0; c < this.m_props.steps; c++) {
|
|
68
|
+
this.m_els[c].setClass('checked', this.m_els[c].getData('value') <= v);
|
|
69
|
+
}
|
|
70
|
+
this.m_input.value = '' + this.m_props.value;
|
|
71
|
+
}
|
|
72
|
+
set steps(n) {
|
|
73
|
+
this.m_props.steps = n;
|
|
74
|
+
this.update();
|
|
75
|
+
}
|
|
76
|
+
set shape(shape) {
|
|
77
|
+
this.removeClass(this.m_props.shape);
|
|
78
|
+
this.m_props.shape = shape;
|
|
79
|
+
this.addClass(this.m_props.shape);
|
|
80
|
+
}
|
|
81
|
+
_onclick(ev) {
|
|
82
|
+
let on = true;
|
|
83
|
+
for (let el = this.dom.firstChild; el; el = el.nextSibling) {
|
|
84
|
+
let comp = Component.getElement(el);
|
|
85
|
+
comp.setClass('checked', on);
|
|
86
|
+
if (el == ev.target) {
|
|
87
|
+
this.m_input.value = comp.getData('value');
|
|
88
|
+
on = false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
this.emit('change', EvChange(this.m_props.value));
|
|
92
|
+
}
|
|
93
|
+
}
|
package/lib/request.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
export interface RequestProps {
|
|
26
|
+
url: string;
|
|
27
|
+
method?: 'GET' | 'POST';
|
|
28
|
+
headers?: string[];
|
|
29
|
+
params?: any;
|
|
30
|
+
timeout?: number;
|
|
31
|
+
responseType?: 'text' | 'json' | 'arraybuffer';
|
|
32
|
+
userData?: any;
|
|
33
|
+
success: (data: any, userData: any) => void;
|
|
34
|
+
failure?: (status: number, statusText: string, userData: any) => void;
|
|
35
|
+
progress?: (length: number, total: number, display: string) => void;
|
|
36
|
+
}
|
|
37
|
+
export declare function ajaxRequest(cfg: RequestProps): Function;
|
|
38
|
+
interface AjaxRequestInit extends Omit<RequestInit, 'body'> {
|
|
39
|
+
body?: BodyInit | null | object;
|
|
40
|
+
noGenX?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function ajaxAsJSON(url: string, init?: AjaxRequestInit): Promise<any>;
|
|
43
|
+
export declare function ajaxAsText(url: string, init?: AjaxRequestInit): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* use encodeURIComponent for elements in url
|
|
46
|
+
*/
|
|
47
|
+
export declare function ajax(url: string, init?: AjaxRequestInit, type?: string): Promise<Response>;
|
|
48
|
+
export {};
|
package/lib/request.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
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
|
+
* TODO: use fetch api
|
|
27
|
+
*
|
|
28
|
+
|
|
29
|
+
async function xx( resp, cb ) {
|
|
30
|
+
cb( await resp.json() );
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function getToto( cb ) {
|
|
34
|
+
fetch('home/toto', { method: 'GET' }).then( (resp) => { xx(resp,cb); } );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function dump( resp ) {
|
|
38
|
+
console.log( resp );
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getToto( dump );
|
|
42
|
+
|
|
43
|
+
*/
|
|
44
|
+
import { isArray, isLiteralObject, isString, NetworkError } from './tools';
|
|
45
|
+
const DEFAULT_TIMEOUT = 10000;
|
|
46
|
+
export function ajaxRequest(cfg) {
|
|
47
|
+
let params, url = cfg.url, method = cfg.method || 'GET', formdata = false;
|
|
48
|
+
if (cfg.params instanceof FormData) {
|
|
49
|
+
params = cfg.params;
|
|
50
|
+
formdata = true;
|
|
51
|
+
}
|
|
52
|
+
else if (method == 'POST') {
|
|
53
|
+
params = buildQuery(cfg.params, false);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
url += buildQuery(cfg.params, true);
|
|
57
|
+
}
|
|
58
|
+
url = encodeURI(url);
|
|
59
|
+
let xhr = new XMLHttpRequest();
|
|
60
|
+
xhr.open(method, url);
|
|
61
|
+
xhr.upload.addEventListener('progress', progress, false);
|
|
62
|
+
xhr.addEventListener('timeout', failure);
|
|
63
|
+
xhr.addEventListener('error', failure);
|
|
64
|
+
xhr.addEventListener('load', success);
|
|
65
|
+
if (!formdata) {
|
|
66
|
+
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
67
|
+
}
|
|
68
|
+
if (method != 'POST') {
|
|
69
|
+
xhr.responseType = cfg.responseType || 'json';
|
|
70
|
+
xhr.timeout = cfg.timeout || DEFAULT_TIMEOUT;
|
|
71
|
+
}
|
|
72
|
+
if (cfg.headers) {
|
|
73
|
+
for (let h in cfg.headers) {
|
|
74
|
+
this.xhr.setRequestHeader(h, cfg.headers[h]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function progress(ev) {
|
|
78
|
+
console.log(ev);
|
|
79
|
+
if (cfg.progress) {
|
|
80
|
+
try {
|
|
81
|
+
if (ev.lengthComputable) {
|
|
82
|
+
let disp = humanSize(ev.loaded) + ' / ' + humanSize(ev.total);
|
|
83
|
+
cfg.progress(ev.loaded, ev.total, disp);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
console.error('unhandled exception:', e);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function humanSize(bytes) {
|
|
92
|
+
let unit, value;
|
|
93
|
+
if (bytes >= 1e9) {
|
|
94
|
+
unit = 'Gb';
|
|
95
|
+
value = bytes / 1e9;
|
|
96
|
+
}
|
|
97
|
+
else if (bytes >= 1e6) {
|
|
98
|
+
unit = 'Mb';
|
|
99
|
+
value = bytes / 1e6;
|
|
100
|
+
}
|
|
101
|
+
else if (bytes >= 1e3) {
|
|
102
|
+
unit = 'Kb';
|
|
103
|
+
value = bytes / 1e3;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
unit = 'bytes';
|
|
107
|
+
value = bytes;
|
|
108
|
+
}
|
|
109
|
+
return value.toFixed(2) + unit;
|
|
110
|
+
}
|
|
111
|
+
function failure() {
|
|
112
|
+
if (cfg.failure) {
|
|
113
|
+
cfg.failure(xhr.status, xhr.statusText, cfg.userData);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function success() {
|
|
117
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
118
|
+
if (cfg.success) {
|
|
119
|
+
try {
|
|
120
|
+
cfg.success(xhr.response, cfg.userData);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
console.error('unhandled exception:', e);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
failure();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (formdata || method == 'POST') {
|
|
132
|
+
xhr.send(params);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
xhr.send();
|
|
136
|
+
}
|
|
137
|
+
return function () {
|
|
138
|
+
xhr.abort();
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function buildQuery(params, getMethod) {
|
|
142
|
+
if (!params) {
|
|
143
|
+
return '';
|
|
144
|
+
}
|
|
145
|
+
let query = [];
|
|
146
|
+
for (let key in params) {
|
|
147
|
+
let param = params[key];
|
|
148
|
+
// array
|
|
149
|
+
if (isArray(param)) {
|
|
150
|
+
for (let i = 0, n = param.length; i < n; i++) {
|
|
151
|
+
query.push(encodeURIComponent(key) + '[]=' + encodeURIComponent('' + param[i]));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// simple string ...
|
|
155
|
+
else {
|
|
156
|
+
if (param === undefined) {
|
|
157
|
+
param = '';
|
|
158
|
+
}
|
|
159
|
+
query.push(encodeURIComponent(key) + '=' + encodeURIComponent('' + param));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
let result = query.join('&');
|
|
163
|
+
if (getMethod) {
|
|
164
|
+
return '?' + result;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export async function ajaxAsJSON(url, init) {
|
|
171
|
+
let response = await ajax(url, init, 'application/json');
|
|
172
|
+
return response.json();
|
|
173
|
+
}
|
|
174
|
+
export async function ajaxAsText(url, init) {
|
|
175
|
+
let response = await ajax(url, init, 'text/plain');
|
|
176
|
+
return response.text();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* use encodeURIComponent for elements in url
|
|
180
|
+
*/
|
|
181
|
+
export async function ajax(url, init, type) {
|
|
182
|
+
let options = {
|
|
183
|
+
method: 'GET',
|
|
184
|
+
headers: {
|
|
185
|
+
'X-Requested-With': 'XMLHttpRequest'
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
if (type) {
|
|
189
|
+
options.headers['Content-Type'] = type;
|
|
190
|
+
}
|
|
191
|
+
if (init) {
|
|
192
|
+
options = { ...options, ...init };
|
|
193
|
+
if (init.body && !isString(init.body)) {
|
|
194
|
+
let cvt = false;
|
|
195
|
+
if (isLiteralObject(init.body)) {
|
|
196
|
+
cvt = true;
|
|
197
|
+
}
|
|
198
|
+
else if (!(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer) && !(init.body instanceof FormData) &&
|
|
199
|
+
!(init.body instanceof URLSearchParams) && !(init.body instanceof ReadableStream)) {
|
|
200
|
+
cvt = true;
|
|
201
|
+
}
|
|
202
|
+
if (cvt) {
|
|
203
|
+
options.body = JSON.stringify(init.body);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
options.body = init.body;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
let response = await fetch(url, options);
|
|
211
|
+
if (init && init.noGenX) {
|
|
212
|
+
return response;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
if (!response.ok) {
|
|
216
|
+
throw new NetworkError(response);
|
|
217
|
+
}
|
|
218
|
+
return response;
|
|
219
|
+
}
|
|
220
|
+
}
|
package/lib/router.d.ts
ADDED
package/lib/router.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class Router {
|
|
2
|
+
routes;
|
|
3
|
+
constructor() {
|
|
4
|
+
this.routes = [];
|
|
5
|
+
}
|
|
6
|
+
get(uri, callback) {
|
|
7
|
+
// throw an error if the route uri already exists to avoid confilicting routes
|
|
8
|
+
this.routes.forEach(route => {
|
|
9
|
+
if (route.uri === uri) {
|
|
10
|
+
throw new Error(`the uri ${route.uri} already exists`);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
this.routes.push({
|
|
14
|
+
uri,
|
|
15
|
+
callback
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
init() {
|
|
19
|
+
this.routes.some(route => {
|
|
20
|
+
let regEx = new RegExp(`^${route.uri}$`);
|
|
21
|
+
let path = window.location.pathname;
|
|
22
|
+
if (path.match(regEx)) {
|
|
23
|
+
return route.callback({ path });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
export declare class Settings {
|
|
26
|
+
private m_data;
|
|
27
|
+
private m_name;
|
|
28
|
+
constructor(name?: string);
|
|
29
|
+
set(name: string, value: any): void;
|
|
30
|
+
get(name: string, defValue?: any): any;
|
|
31
|
+
private _save;
|
|
32
|
+
private _load;
|
|
33
|
+
}
|