x4js 1.5.18 → 1.5.20
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/{README.md → README.txt} +0 -0
- package/lib/cjs/index.js +39 -103
- package/lib/cjs/index.js.map +7 -0
- package/lib/esm/index.mjs +39 -87
- package/lib/esm/index.mjs.map +7 -0
- package/lib/{license.md → licence.md} +0 -0
- package/lib/src/MIT-license.md +14 -0
- package/lib/{types/action.d.ts → src/action.ts} +64 -33
- package/lib/src/alpha.jpg +0 -0
- package/lib/src/app_sockets.ts +81 -0
- package/lib/src/application.ts +251 -0
- package/lib/src/autocomplete.ts +197 -0
- package/lib/src/base64.ts +166 -0
- package/lib/src/base_component.ts +152 -0
- package/lib/src/button.ts +355 -0
- package/lib/src/calendar.ts +328 -0
- package/lib/src/canvas.ts +505 -0
- package/lib/src/cardview.ts +227 -0
- package/lib/src/checkbox.ts +188 -0
- package/lib/src/color.ts +752 -0
- package/lib/src/colorpicker.ts +1639 -0
- package/lib/src/combobox.ts +465 -0
- package/lib/src/component.ts +2329 -0
- package/lib/{esm/dom_events.js → src/copyright.txt} +27 -29
- package/lib/src/datastore.ts +1322 -0
- package/lib/src/dialog.ts +656 -0
- package/lib/src/dom_events.ts +315 -0
- package/lib/src/drag_manager.ts +199 -0
- package/lib/src/drawtext.ts +355 -0
- package/lib/src/fileupload.ts +213 -0
- package/lib/src/form.ts +375 -0
- package/lib/src/formatters.ts +105 -0
- package/lib/src/gridview.ts +1185 -0
- package/lib/src/i18n.ts +346 -0
- package/lib/src/icon.ts +335 -0
- package/lib/src/image.ts +204 -0
- package/lib/src/index.ts +89 -0
- package/lib/src/input.ts +249 -0
- package/lib/src/label.ts +128 -0
- package/lib/src/layout.ts +430 -0
- package/lib/src/link.ts +86 -0
- package/lib/src/listview.ts +765 -0
- package/lib/{esm/md5.js → src/md5.ts} +438 -403
- package/lib/src/menu.ts +425 -0
- package/lib/src/messagebox.ts +224 -0
- package/lib/src/panel.ts +86 -0
- package/lib/src/popup.ts +494 -0
- package/lib/src/property_editor.ts +337 -0
- package/lib/src/radiobtn.ts +197 -0
- package/lib/src/rating.ts +135 -0
- package/lib/src/request.ts +300 -0
- package/lib/src/router.ts +185 -0
- package/lib/src/settings.ts +77 -0
- package/lib/src/sidebarview.ts +103 -0
- package/lib/src/spreadsheet.ts +1449 -0
- package/lib/src/styles.ts +343 -0
- package/lib/src/svgcomponent.ts +577 -0
- package/lib/src/tabbar.ts +151 -0
- package/lib/src/tabview.ts +110 -0
- package/lib/src/textarea.ts +235 -0
- package/lib/src/textedit.ts +544 -0
- package/lib/src/toaster.ts +80 -0
- package/lib/src/tools.ts +1473 -0
- package/lib/src/tooltips.ts +191 -0
- package/lib/src/treeview.ts +716 -0
- package/lib/{esm/version.js → src/version.ts} +30 -29
- package/lib/{styles → src}/x4.less +0 -0
- package/lib/src/x4dom.ts +57 -0
- package/lib/src/x4events.ts +585 -0
- package/lib/src/x4react.ts +90 -0
- package/package.json +52 -46
- package/lib/cjs/action.js +0 -58
- package/lib/cjs/app_sockets.js +0 -74
- package/lib/cjs/application.js +0 -182
- package/lib/cjs/autocomplete.js +0 -155
- package/lib/cjs/base_component.js +0 -124
- package/lib/cjs/button.js +0 -263
- package/lib/cjs/calendar.js +0 -254
- package/lib/cjs/canvas.js +0 -361
- package/lib/cjs/cardview.js +0 -161
- package/lib/cjs/checkbox.js +0 -139
- package/lib/cjs/color.js +0 -591
- package/lib/cjs/colorpicker.js +0 -1468
- package/lib/cjs/combobox.js +0 -349
- package/lib/cjs/component.js +0 -1719
- package/lib/cjs/datastore.js +0 -985
- package/lib/cjs/dialog.js +0 -478
- package/lib/cjs/dom_events.js +0 -30
- package/lib/cjs/drag_manager.js +0 -145
- package/lib/cjs/drawtext.js +0 -276
- package/lib/cjs/fileupload.js +0 -167
- package/lib/cjs/form.js +0 -304
- package/lib/cjs/formatters.js +0 -90
- package/lib/cjs/gridview.js +0 -881
- package/lib/cjs/i18n.js +0 -266
- package/lib/cjs/icon.js +0 -272
- package/lib/cjs/image.js +0 -157
- package/lib/cjs/input.js +0 -174
- package/lib/cjs/label.js +0 -95
- package/lib/cjs/layout.js +0 -322
- package/lib/cjs/link.js +0 -64
- package/lib/cjs/listview.js +0 -546
- package/lib/cjs/md5.js +0 -403
- package/lib/cjs/menu.js +0 -301
- package/lib/cjs/messagebox.js +0 -177
- package/lib/cjs/panel.js +0 -68
- package/lib/cjs/popup.js +0 -383
- package/lib/cjs/property_editor.js +0 -252
- package/lib/cjs/radiobtn.js +0 -140
- package/lib/cjs/rating.js +0 -102
- package/lib/cjs/request.js +0 -246
- package/lib/cjs/router.js +0 -139
- package/lib/cjs/settings.js +0 -69
- package/lib/cjs/sidebarview.js +0 -82
- package/lib/cjs/spreadsheet.js +0 -1084
- package/lib/cjs/styles.js +0 -275
- package/lib/cjs/svgcomponent.js +0 -447
- package/lib/cjs/tabbar.js +0 -111
- package/lib/cjs/tabview.js +0 -85
- package/lib/cjs/textarea.js +0 -165
- package/lib/cjs/textedit.js +0 -415
- package/lib/cjs/toaster.js +0 -64
- package/lib/cjs/tools.js +0 -1197
- package/lib/cjs/tooltips.js +0 -157
- package/lib/cjs/treeview.js +0 -535
- package/lib/cjs/version.js +0 -32
- package/lib/cjs/x4dom.js +0 -32
- package/lib/cjs/x4events.js +0 -384
- package/lib/cjs/x4react.js +0 -72
- package/lib/esm/action.js +0 -53
- package/lib/esm/app_sockets.js +0 -70
- package/lib/esm/application.js +0 -184
- package/lib/esm/autocomplete.js +0 -155
- package/lib/esm/base_component.js +0 -107
- package/lib/esm/button.js +0 -257
- package/lib/esm/calendar.js +0 -249
- package/lib/esm/canvas.js +0 -358
- package/lib/esm/cardview.js +0 -159
- package/lib/esm/checkbox.js +0 -134
- package/lib/esm/color.js +0 -588
- package/lib/esm/colorpicker.js +0 -1475
- package/lib/esm/combobox.js +0 -351
- package/lib/esm/component.js +0 -1711
- package/lib/esm/datastore.js +0 -990
- package/lib/esm/dialog.js +0 -490
- package/lib/esm/drag_manager.js +0 -147
- package/lib/esm/drawtext.js +0 -271
- package/lib/esm/fileupload.js +0 -163
- package/lib/esm/form.js +0 -304
- package/lib/esm/formatters.js +0 -81
- package/lib/esm/gridview.js +0 -889
- package/lib/esm/i18n.js +0 -257
- package/lib/esm/icon.js +0 -261
- package/lib/esm/image.js +0 -154
- package/lib/esm/input.js +0 -182
- package/lib/esm/label.js +0 -90
- package/lib/esm/layout.js +0 -310
- package/lib/esm/link.js +0 -59
- package/lib/esm/listview.js +0 -534
- package/lib/esm/menu.js +0 -300
- package/lib/esm/messagebox.js +0 -161
- package/lib/esm/panel.js +0 -65
- package/lib/esm/popup.js +0 -379
- package/lib/esm/property_editor.js +0 -251
- package/lib/esm/radiobtn.js +0 -136
- package/lib/esm/rating.js +0 -97
- package/lib/esm/request.js +0 -224
- package/lib/esm/router.js +0 -136
- package/lib/esm/settings.js +0 -66
- package/lib/esm/sidebarview.js +0 -79
- package/lib/esm/spreadsheet.js +0 -1097
- package/lib/esm/styles.js +0 -270
- package/lib/esm/svgcomponent.js +0 -450
- package/lib/esm/tabbar.js +0 -107
- package/lib/esm/tabview.js +0 -83
- package/lib/esm/textarea.js +0 -160
- package/lib/esm/textedit.js +0 -412
- package/lib/esm/toaster.js +0 -62
- package/lib/esm/tools.js +0 -1158
- package/lib/esm/tooltips.js +0 -153
- package/lib/esm/treeview.js +0 -527
- package/lib/esm/x4dom.js +0 -29
- package/lib/esm/x4events.js +0 -376
- package/lib/esm/x4react.js +0 -71
- package/lib/types/app_sockets.d.ts +0 -29
- package/lib/types/application.d.ts +0 -104
- package/lib/types/autocomplete.d.ts +0 -58
- package/lib/types/base_component.d.ts +0 -88
- package/lib/types/button.d.ts +0 -151
- package/lib/types/calendar.d.ts +0 -82
- package/lib/types/canvas.d.ts +0 -92
- package/lib/types/cardview.d.ts +0 -87
- package/lib/types/checkbox.d.ts +0 -77
- package/lib/types/color.d.ts +0 -148
- package/lib/types/colorpicker.d.ts +0 -107
- package/lib/types/combobox.d.ts +0 -107
- package/lib/types/component.d.ts +0 -601
- package/lib/types/datastore.d.ts +0 -396
- package/lib/types/dialog.d.ts +0 -175
- package/lib/types/dom_events.d.ts +0 -302
- package/lib/types/drag_manager.d.ts +0 -54
- package/lib/types/drawtext.d.ts +0 -48
- package/lib/types/fileupload.d.ts +0 -64
- package/lib/types/form.d.ts +0 -133
- package/lib/types/formatters.d.ts +0 -35
- package/lib/types/gridview.d.ts +0 -175
- package/lib/types/i18n.d.ts +0 -73
- package/lib/types/icon.d.ts +0 -64
- package/lib/types/image.d.ts +0 -55
- package/lib/types/index.d.ts +0 -84
- package/lib/types/input.d.ts +0 -91
- package/lib/types/label.d.ts +0 -58
- package/lib/types/layout.d.ts +0 -87
- package/lib/types/link.d.ts +0 -50
- package/lib/types/listview.d.ts +0 -178
- package/lib/types/md5.d.ts +0 -61
- package/lib/types/menu.d.ts +0 -130
- package/lib/types/messagebox.d.ts +0 -69
- package/lib/types/panel.d.ts +0 -47
- package/lib/types/popup.d.ts +0 -75
- package/lib/types/property_editor.d.ts +0 -71
- package/lib/types/radiobtn.d.ts +0 -73
- package/lib/types/rating.d.ts +0 -53
- package/lib/types/request.d.ts +0 -52
- package/lib/types/router.d.ts +0 -42
- package/lib/types/settings.d.ts +0 -37
- package/lib/types/sidebarview.d.ts +0 -49
- package/lib/types/spreadsheet.d.ts +0 -222
- package/lib/types/styles.d.ts +0 -85
- package/lib/types/svgcomponent.d.ts +0 -215
- package/lib/types/tabbar.d.ts +0 -58
- package/lib/types/tabview.d.ts +0 -49
- package/lib/types/textarea.d.ts +0 -77
- package/lib/types/textedit.d.ts +0 -123
- package/lib/types/toaster.d.ts +0 -42
- package/lib/types/tools.d.ts +0 -394
- package/lib/types/tooltips.d.ts +0 -46
- package/lib/types/treeview.d.ts +0 -144
- package/lib/types/version.d.ts +0 -29
- package/lib/types/x4dom.d.ts +0 -49
- package/lib/types/x4events.d.ts +0 -269
- package/lib/types/x4react.d.ts +0 -41
package/lib/esm/radiobtn.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file radiobtn.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2022 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
import { x4document } from './x4dom';
|
|
30
|
-
import { Component } from './component';
|
|
31
|
-
import { EvChange } from './x4events';
|
|
32
|
-
import { Input } from './input';
|
|
33
|
-
import { Label } from './label';
|
|
34
|
-
/**
|
|
35
|
-
* Standard RadioBtn
|
|
36
|
-
*/
|
|
37
|
-
export class RadioBtn extends Component {
|
|
38
|
-
m_ui_input; // todo: remove that / use ref
|
|
39
|
-
constructor(props) {
|
|
40
|
-
super(props);
|
|
41
|
-
this.mapPropEvents(props, 'change');
|
|
42
|
-
}
|
|
43
|
-
/** @ignore */
|
|
44
|
-
render(props) {
|
|
45
|
-
let text = props.text ?? '';
|
|
46
|
-
let name = props.name ?? props.group;
|
|
47
|
-
let labelWidth = props.labelWidth ?? -1;
|
|
48
|
-
let checked = props.checked ?? false;
|
|
49
|
-
let align = props.align ?? 'left';
|
|
50
|
-
let value = props.value;
|
|
51
|
-
let icon = props.icon;
|
|
52
|
-
this.setTag('label');
|
|
53
|
-
this.addClass('@hlayout');
|
|
54
|
-
this.addClass(align);
|
|
55
|
-
this._setTabIndex(props.tabIndex);
|
|
56
|
-
if (checked) {
|
|
57
|
-
this.addClass('checked');
|
|
58
|
-
}
|
|
59
|
-
this.setContent([
|
|
60
|
-
this.m_ui_input = new Input({
|
|
61
|
-
type: 'radio',
|
|
62
|
-
name: name,
|
|
63
|
-
tabIndex: props.tabIndex,
|
|
64
|
-
value: value,
|
|
65
|
-
attrs: {
|
|
66
|
-
checked: checked ? '' : undefined
|
|
67
|
-
},
|
|
68
|
-
dom_events: {
|
|
69
|
-
change: () => this._change(),
|
|
70
|
-
focus: () => this.m_ui_input.focus(),
|
|
71
|
-
}
|
|
72
|
-
}),
|
|
73
|
-
new Label({
|
|
74
|
-
ref: 'label',
|
|
75
|
-
icon: icon,
|
|
76
|
-
text: text,
|
|
77
|
-
width: labelWidth === 'flex' ? undefined : labelWidth,
|
|
78
|
-
flex: labelWidth === 'flex' ? 1 : undefined,
|
|
79
|
-
style: {
|
|
80
|
-
order: align == 'right' ? -1 : undefined,
|
|
81
|
-
},
|
|
82
|
-
})
|
|
83
|
-
]);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* check state changed
|
|
87
|
-
*/
|
|
88
|
-
_change() {
|
|
89
|
-
let props = this.m_props;
|
|
90
|
-
let query = '.x-input[name=' + props.name + ']';
|
|
91
|
-
let nlist = x4document.querySelectorAll(query); //todo: document ?
|
|
92
|
-
nlist.forEach((dom) => {
|
|
93
|
-
let radio = Component.getElement(dom, RadioBtn);
|
|
94
|
-
radio.removeClass('checked');
|
|
95
|
-
});
|
|
96
|
-
let dom = this.m_ui_input.dom;
|
|
97
|
-
this.setClass('checked', dom.checked);
|
|
98
|
-
this.emit('change', EvChange(true));
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* @return the checked value
|
|
102
|
-
*/
|
|
103
|
-
get check() {
|
|
104
|
-
if (this.m_ui_input) {
|
|
105
|
-
return this.m_ui_input.dom.checked;
|
|
106
|
-
}
|
|
107
|
-
return this.m_props.checked;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* change the checked value
|
|
111
|
-
* @param {boolean} ck new checked value
|
|
112
|
-
*/
|
|
113
|
-
set check(ck) {
|
|
114
|
-
let dom = this.m_ui_input.dom;
|
|
115
|
-
if (ck) {
|
|
116
|
-
//this.addClass( 'checked' );
|
|
117
|
-
if (dom) {
|
|
118
|
-
dom.checked = true;
|
|
119
|
-
}
|
|
120
|
-
this.m_props.checked = true;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
//this.removeClass( 'checked' );
|
|
124
|
-
if (dom) {
|
|
125
|
-
dom.checked = false;
|
|
126
|
-
}
|
|
127
|
-
this.m_props.checked = false;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
get text() {
|
|
131
|
-
return this.itemWithRef('label').text;
|
|
132
|
-
}
|
|
133
|
-
set text(text) {
|
|
134
|
-
this.itemWithRef('label').text = text;
|
|
135
|
-
}
|
|
136
|
-
}
|
package/lib/esm/rating.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file rating.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2022 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
import { Component } from './component';
|
|
30
|
-
import { HLayout } from './layout';
|
|
31
|
-
import { Input } from './input';
|
|
32
|
-
import { EvChange } from './x4events';
|
|
33
|
-
export class Rating extends HLayout {
|
|
34
|
-
m_els;
|
|
35
|
-
m_input;
|
|
36
|
-
constructor(props) {
|
|
37
|
-
super(props);
|
|
38
|
-
props.steps = props.steps ?? 5;
|
|
39
|
-
}
|
|
40
|
-
render(props) {
|
|
41
|
-
let shape = props.shape ?? 'star';
|
|
42
|
-
let value = props.value ?? 0;
|
|
43
|
-
this.m_input = new Input({
|
|
44
|
-
cls: '@hidden',
|
|
45
|
-
name: props.name,
|
|
46
|
-
value: '' + value
|
|
47
|
-
});
|
|
48
|
-
this.addClass(shape);
|
|
49
|
-
this.setDomEvent('click', (e) => this._onclick(e));
|
|
50
|
-
this.m_els = [];
|
|
51
|
-
for (let i = 0; i < props.steps; i++) {
|
|
52
|
-
let cls = 'item';
|
|
53
|
-
if (i + 1 <= value) {
|
|
54
|
-
cls += ' checked';
|
|
55
|
-
}
|
|
56
|
-
let c = new Component({
|
|
57
|
-
tag: 'option',
|
|
58
|
-
cls,
|
|
59
|
-
data: { value: i + 1 }
|
|
60
|
-
});
|
|
61
|
-
this.m_els.push(c);
|
|
62
|
-
}
|
|
63
|
-
this.m_els.push(this.m_input);
|
|
64
|
-
this.setContent(this.m_els);
|
|
65
|
-
}
|
|
66
|
-
getValue() {
|
|
67
|
-
return this.m_props.value ?? 0;
|
|
68
|
-
}
|
|
69
|
-
set value(v) {
|
|
70
|
-
this.m_props.value = v;
|
|
71
|
-
for (let c = 0; c < this.m_props.steps; c++) {
|
|
72
|
-
this.m_els[c].setClass('checked', this.m_els[c].getData('value') <= v);
|
|
73
|
-
}
|
|
74
|
-
this.m_input.value = '' + this.m_props.value;
|
|
75
|
-
}
|
|
76
|
-
set steps(n) {
|
|
77
|
-
this.m_props.steps = n;
|
|
78
|
-
this.update();
|
|
79
|
-
}
|
|
80
|
-
set shape(shape) {
|
|
81
|
-
this.removeClass(this.m_props.shape);
|
|
82
|
-
this.m_props.shape = shape;
|
|
83
|
-
this.addClass(this.m_props.shape);
|
|
84
|
-
}
|
|
85
|
-
_onclick(ev) {
|
|
86
|
-
let on = true;
|
|
87
|
-
for (let el = this.dom.firstChild; el; el = el.nextSibling) {
|
|
88
|
-
let comp = Component.getElement(el);
|
|
89
|
-
comp.setClass('checked', on);
|
|
90
|
-
if (el == ev.target) {
|
|
91
|
-
this.m_input.value = comp.getData('value');
|
|
92
|
-
on = false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
this.emit('change', EvChange(this.m_props.value));
|
|
96
|
-
}
|
|
97
|
-
}
|
package/lib/esm/request.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file request.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2022 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
/**
|
|
30
|
-
* TODO: use fetch api
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
async function xx( resp, cb ) {
|
|
34
|
-
cb( await resp.json() );
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function getToto( cb ) {
|
|
38
|
-
fetch('home/toto', { method: 'GET' }).then( (resp) => { xx(resp,cb); } );
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function dump( resp ) {
|
|
42
|
-
console.log( resp );
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
getToto( dump );
|
|
46
|
-
|
|
47
|
-
*/
|
|
48
|
-
import { isArray, isLiteralObject, isString, NetworkError } from './tools';
|
|
49
|
-
const DEFAULT_TIMEOUT = 10000;
|
|
50
|
-
export function ajaxRequest(cfg) {
|
|
51
|
-
let params, url = cfg.url, method = cfg.method || 'GET', formdata = false;
|
|
52
|
-
if (cfg.params instanceof FormData) {
|
|
53
|
-
params = cfg.params;
|
|
54
|
-
formdata = true;
|
|
55
|
-
}
|
|
56
|
-
else if (method == 'POST') {
|
|
57
|
-
params = buildQuery(cfg.params, false);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
url += buildQuery(cfg.params, true);
|
|
61
|
-
}
|
|
62
|
-
url = encodeURI(url);
|
|
63
|
-
let xhr = new XMLHttpRequest();
|
|
64
|
-
xhr.open(method, url);
|
|
65
|
-
xhr.upload.addEventListener('progress', progress, false);
|
|
66
|
-
xhr.addEventListener('timeout', failure);
|
|
67
|
-
xhr.addEventListener('error', failure);
|
|
68
|
-
xhr.addEventListener('load', success);
|
|
69
|
-
if (!formdata) {
|
|
70
|
-
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
71
|
-
}
|
|
72
|
-
if (method != 'POST') {
|
|
73
|
-
xhr.responseType = cfg.responseType || 'json';
|
|
74
|
-
xhr.timeout = cfg.timeout || DEFAULT_TIMEOUT;
|
|
75
|
-
}
|
|
76
|
-
if (cfg.headers) {
|
|
77
|
-
for (let h in cfg.headers) {
|
|
78
|
-
xhr.setRequestHeader(h, cfg.headers[h]);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function progress(ev) {
|
|
82
|
-
console.log(ev);
|
|
83
|
-
if (cfg.progress) {
|
|
84
|
-
try {
|
|
85
|
-
if (ev.lengthComputable) {
|
|
86
|
-
let disp = humanSize(ev.loaded) + ' / ' + humanSize(ev.total);
|
|
87
|
-
cfg.progress(ev.loaded, ev.total, disp);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
console.error('unhandled exception:', e);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function humanSize(bytes) {
|
|
96
|
-
let unit, value;
|
|
97
|
-
if (bytes >= 1e9) {
|
|
98
|
-
unit = 'Gb';
|
|
99
|
-
value = bytes / 1e9;
|
|
100
|
-
}
|
|
101
|
-
else if (bytes >= 1e6) {
|
|
102
|
-
unit = 'Mb';
|
|
103
|
-
value = bytes / 1e6;
|
|
104
|
-
}
|
|
105
|
-
else if (bytes >= 1e3) {
|
|
106
|
-
unit = 'Kb';
|
|
107
|
-
value = bytes / 1e3;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
unit = 'bytes';
|
|
111
|
-
value = bytes;
|
|
112
|
-
}
|
|
113
|
-
return value.toFixed(2) + unit;
|
|
114
|
-
}
|
|
115
|
-
function failure() {
|
|
116
|
-
if (cfg.failure) {
|
|
117
|
-
cfg.failure(xhr.status, xhr.statusText, cfg.userData);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function success() {
|
|
121
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
122
|
-
if (cfg.success) {
|
|
123
|
-
try {
|
|
124
|
-
cfg.success(xhr.response, cfg.userData);
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
console.error('unhandled exception:', e);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
failure();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (formdata || method == 'POST') {
|
|
136
|
-
xhr.send(params);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
xhr.send();
|
|
140
|
-
}
|
|
141
|
-
return function () {
|
|
142
|
-
xhr.abort();
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function buildQuery(params, getMethod) {
|
|
146
|
-
if (!params) {
|
|
147
|
-
return '';
|
|
148
|
-
}
|
|
149
|
-
let query = [];
|
|
150
|
-
for (let key in params) {
|
|
151
|
-
let param = params[key];
|
|
152
|
-
// array
|
|
153
|
-
if (isArray(param)) {
|
|
154
|
-
for (let i = 0, n = param.length; i < n; i++) {
|
|
155
|
-
query.push(encodeURIComponent(key) + '[]=' + encodeURIComponent('' + param[i]));
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
// simple string ...
|
|
159
|
-
else {
|
|
160
|
-
if (param === undefined) {
|
|
161
|
-
param = '';
|
|
162
|
-
}
|
|
163
|
-
query.push(encodeURIComponent(key) + '=' + encodeURIComponent('' + param));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
let result = query.join('&');
|
|
167
|
-
if (getMethod) {
|
|
168
|
-
return '?' + result;
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
return result;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
export async function ajaxAsJSON(url, init) {
|
|
175
|
-
let response = await ajax(url, init, 'application/json');
|
|
176
|
-
return response.json();
|
|
177
|
-
}
|
|
178
|
-
export async function ajaxAsText(url, init) {
|
|
179
|
-
let response = await ajax(url, init, 'text/plain');
|
|
180
|
-
return response.text();
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* use encodeURIComponent for elements in url
|
|
184
|
-
*/
|
|
185
|
-
export async function ajax(url, init, type) {
|
|
186
|
-
let options = {
|
|
187
|
-
method: 'GET',
|
|
188
|
-
headers: {
|
|
189
|
-
'X-Requested-With': 'XMLHttpRequest'
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
if (type) {
|
|
193
|
-
options.headers['Content-Type'] = type;
|
|
194
|
-
}
|
|
195
|
-
if (init) {
|
|
196
|
-
options = { ...options, ...init };
|
|
197
|
-
if (init.body && !isString(init.body)) {
|
|
198
|
-
let cvt = false;
|
|
199
|
-
if (isLiteralObject(init.body)) {
|
|
200
|
-
cvt = true;
|
|
201
|
-
}
|
|
202
|
-
else if (!(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer) && !(init.body instanceof FormData) &&
|
|
203
|
-
!(init.body instanceof URLSearchParams) && !(init.body instanceof ReadableStream)) {
|
|
204
|
-
cvt = true;
|
|
205
|
-
}
|
|
206
|
-
if (cvt) {
|
|
207
|
-
options.body = JSON.stringify(init.body);
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
options.body = init.body;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
let response = await fetch(url, options);
|
|
215
|
-
if (init && init.noGenX) {
|
|
216
|
-
return response;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
if (!response.ok) {
|
|
220
|
-
throw new NetworkError(response);
|
|
221
|
-
}
|
|
222
|
-
return response;
|
|
223
|
-
}
|
|
224
|
-
}
|
package/lib/esm/router.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file router.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2022 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
import { x4document } from './x4dom';
|
|
30
|
-
import { EventSource, EvError } from "./x4events";
|
|
31
|
-
function parseRoute(str, loose = false) {
|
|
32
|
-
if (str instanceof RegExp) {
|
|
33
|
-
return {
|
|
34
|
-
keys: null,
|
|
35
|
-
pattern: str
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const arr = str.split('/');
|
|
39
|
-
let keys = [];
|
|
40
|
-
let pattern = '';
|
|
41
|
-
if (arr[0] == '') {
|
|
42
|
-
arr.shift();
|
|
43
|
-
}
|
|
44
|
-
for (const tmp of arr) {
|
|
45
|
-
const c = tmp[0];
|
|
46
|
-
if (c === '*') {
|
|
47
|
-
keys.push('wild');
|
|
48
|
-
pattern += '/(.*)';
|
|
49
|
-
}
|
|
50
|
-
else if (c === ':') {
|
|
51
|
-
const o = tmp.indexOf('?', 1);
|
|
52
|
-
const ext = tmp.indexOf('.', 1);
|
|
53
|
-
keys.push(tmp.substring(1, o >= 0 ? o : ext >= 0 ? ext : tmp.length));
|
|
54
|
-
pattern += o >= 0 && ext < 0 ? '(?:/([^\/]+?))?' : '/([^\/]+?)';
|
|
55
|
-
if (ext >= 0) {
|
|
56
|
-
pattern += (o >= 0 ? '?' : '') + '\\' + tmp.substring(ext);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
pattern += '/' + tmp;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
keys,
|
|
65
|
-
pattern: new RegExp(`^${pattern}${loose ? '(?=$|\/)' : '\/?$'}`, 'i')
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
export class Router extends EventSource {
|
|
69
|
-
routes;
|
|
70
|
-
constructor() {
|
|
71
|
-
super();
|
|
72
|
-
this.routes = [];
|
|
73
|
-
window.addEventListener('popstate', (event) => {
|
|
74
|
-
const url = x4document.location.pathname;
|
|
75
|
-
const found = this._find(url);
|
|
76
|
-
found.handlers.forEach(h => {
|
|
77
|
-
h(found.params, url);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
get(uri, handler) {
|
|
82
|
-
let { keys, pattern } = parseRoute(uri);
|
|
83
|
-
this.routes.push({ keys, pattern, handler });
|
|
84
|
-
}
|
|
85
|
-
init() {
|
|
86
|
-
this.navigate(window.location.pathname);
|
|
87
|
-
}
|
|
88
|
-
navigate(uri, notify = true) {
|
|
89
|
-
const found = this._find(uri);
|
|
90
|
-
if (!found || found.handlers.length == 0) {
|
|
91
|
-
//window.history.pushState({}, '', 'error')
|
|
92
|
-
console.log('route not found: ' + uri);
|
|
93
|
-
this.signal("error", EvError(404, "route not found"));
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
window.history.pushState({}, '', uri);
|
|
97
|
-
if (notify) {
|
|
98
|
-
found.handlers.forEach(h => {
|
|
99
|
-
h(found.params, uri);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
_find(url) {
|
|
104
|
-
let matches = [];
|
|
105
|
-
let params = {};
|
|
106
|
-
let handlers = [];
|
|
107
|
-
for (const tmp of this.routes) {
|
|
108
|
-
if (!tmp.keys) {
|
|
109
|
-
matches = tmp.pattern.exec(url);
|
|
110
|
-
if (!matches) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (matches['groups']) {
|
|
114
|
-
for (const k in matches['groups']) {
|
|
115
|
-
params[k] = matches['groups'][k];
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
handlers = [...handlers, tmp.handler];
|
|
119
|
-
}
|
|
120
|
-
else if (tmp.keys.length > 0) {
|
|
121
|
-
matches = tmp.pattern.exec(url);
|
|
122
|
-
if (matches === null) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
for (let j = 0; j < tmp.keys.length;) {
|
|
126
|
-
params[tmp.keys[j]] = matches[++j];
|
|
127
|
-
}
|
|
128
|
-
handlers = [...handlers, tmp.handler];
|
|
129
|
-
}
|
|
130
|
-
else if (tmp.pattern.test(url)) {
|
|
131
|
-
handlers = [...handlers, tmp.handler];
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return { params, handlers };
|
|
135
|
-
}
|
|
136
|
-
}
|
package/lib/esm/settings.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file local_storage.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2022 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
export class Settings {
|
|
30
|
-
m_data;
|
|
31
|
-
m_name;
|
|
32
|
-
constructor(name) {
|
|
33
|
-
this.m_data = null;
|
|
34
|
-
this.m_name = name ?? 'settings';
|
|
35
|
-
}
|
|
36
|
-
set(name, value) {
|
|
37
|
-
this._load();
|
|
38
|
-
this.m_data[name] = value;
|
|
39
|
-
this._save();
|
|
40
|
-
}
|
|
41
|
-
get(name, defValue) {
|
|
42
|
-
this._load();
|
|
43
|
-
return this.m_data[name] ?? defValue;
|
|
44
|
-
}
|
|
45
|
-
_save() {
|
|
46
|
-
let data = JSON.stringify(this.m_data);
|
|
47
|
-
localStorage.setItem(this.m_name, data);
|
|
48
|
-
}
|
|
49
|
-
_load() {
|
|
50
|
-
if (this.m_data) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
this.m_data = {};
|
|
54
|
-
let data = localStorage.getItem(this.m_name);
|
|
55
|
-
if (data !== null) {
|
|
56
|
-
data = JSON.parse(data);
|
|
57
|
-
if (data) {
|
|
58
|
-
this.m_data = data;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
console.info('There was an error attempting to read your settings.');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// console.info('There was an error attempting to read your settings.');
|
|
65
|
-
}
|
|
66
|
-
}
|