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/lib/button.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file button.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 { EvClick, EvChange } from './x4_events';
|
|
27
|
+
import { Icon } from './icon';
|
|
28
|
+
import { Label } from './label';
|
|
29
|
+
import { Menu } from './menu';
|
|
30
|
+
import { isFunction } from './tools';
|
|
31
|
+
/**
|
|
32
|
+
* Base button
|
|
33
|
+
*/
|
|
34
|
+
export class BaseButton extends Component {
|
|
35
|
+
constructor(props) {
|
|
36
|
+
super(props);
|
|
37
|
+
this.setProp('tag', 'button');
|
|
38
|
+
this.setDomEvent('click', (e) => this._handleClick(e));
|
|
39
|
+
this.setDomEvent('mousedown', () => { this._startAutoRep(true); });
|
|
40
|
+
this.setDomEvent('mouseup', () => { this._startAutoRep(false); });
|
|
41
|
+
this.setDomEvent('keydown', (e) => this._handleKeyDown(e));
|
|
42
|
+
this.mapPropEvents(props, 'click');
|
|
43
|
+
}
|
|
44
|
+
render(props) {
|
|
45
|
+
let icon = props.icon ? new Icon({ icon: props.icon, cls: 'left', ref: 'l_icon' }) : null;
|
|
46
|
+
let label = new Label({ flex: 1, text: props.text ?? '', align: props.align, ref: 'label' });
|
|
47
|
+
let ricon = props.rightIcon ? new Icon({ icon: props.rightIcon, cls: 'right', ref: 'r_icon' }) : null;
|
|
48
|
+
this.setContent([icon, label, ricon]);
|
|
49
|
+
this._setTabIndex(props.tabIndex);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* starts/stops the autorepeat
|
|
53
|
+
*/
|
|
54
|
+
_startAutoRep(start) {
|
|
55
|
+
if (!this.m_props.autoRepeat) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (start) {
|
|
59
|
+
// 1st timer 1s
|
|
60
|
+
this.startTimer('repeat', 700, false, () => {
|
|
61
|
+
// auto click
|
|
62
|
+
this.startTimer('repeat', this.m_props.autoRepeat, true, this._sendClick);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.stopTimer('repeat');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
_handleKeyDown(ev) {
|
|
73
|
+
if (!ev.ctrlKey && !ev.shiftKey && !ev.altKey) {
|
|
74
|
+
if (ev.key == 'Enter' || ev.key == ' ') {
|
|
75
|
+
this._sendClick();
|
|
76
|
+
ev.preventDefault();
|
|
77
|
+
ev.stopPropagation();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* called by the system on click event
|
|
83
|
+
*/
|
|
84
|
+
_handleClick(ev) {
|
|
85
|
+
if (this.m_props.menu) {
|
|
86
|
+
let menu = new Menu({
|
|
87
|
+
items: isFunction(this.m_props.menu) ? this.m_props.menu() : this.m_props.menu
|
|
88
|
+
});
|
|
89
|
+
let rc = this.getBoundingRect();
|
|
90
|
+
menu.displayAt(rc.left, rc.bottom, 'tl');
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this._sendClick();
|
|
94
|
+
}
|
|
95
|
+
ev.preventDefault();
|
|
96
|
+
ev.stopPropagation();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* sends a click to the observers
|
|
100
|
+
*/
|
|
101
|
+
_sendClick() {
|
|
102
|
+
if (this.m_props.menu) {
|
|
103
|
+
let menu = new Menu({
|
|
104
|
+
items: isFunction(this.m_props.menu) ? this.m_props.menu() : this.m_props.menu
|
|
105
|
+
});
|
|
106
|
+
let rc = this.getBoundingRect();
|
|
107
|
+
menu.displayAt(rc.left, rc.bottom, 'tl');
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this.emit('click', EvClick());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* change the button text
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* let btn = new Button( {
|
|
118
|
+
* text: 'hello'
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* btn.text = 'world';
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
set text(text) {
|
|
125
|
+
this.m_props.text = text;
|
|
126
|
+
let label = this.itemWithRef('label');
|
|
127
|
+
if (label) {
|
|
128
|
+
label.text = text;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
get text() {
|
|
132
|
+
let label = this.itemWithRef('label');
|
|
133
|
+
return label?.text;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* change the button icon
|
|
137
|
+
* todo: do nothing if no icon defined at startup
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* let btn = new Button( {
|
|
142
|
+
* text: 'hello',
|
|
143
|
+
* icon: 'close'
|
|
144
|
+
* });
|
|
145
|
+
* btn.setIcon( 'open' );
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
set icon(icon) {
|
|
149
|
+
this.m_props.icon = icon;
|
|
150
|
+
let ico = this.itemWithRef('l_icon');
|
|
151
|
+
if (ico) {
|
|
152
|
+
ico.icon = icon;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
this.update();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
get icon() {
|
|
159
|
+
let ico = this.itemWithRef('l_icon');
|
|
160
|
+
return ico?.icon;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* change the button right icon
|
|
164
|
+
* todo: do nothing if no icon defined at startup
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* let btn = new Button( {
|
|
169
|
+
* text: 'hello',
|
|
170
|
+
* icon: 'close'
|
|
171
|
+
* });
|
|
172
|
+
* btn.setIcon( 'open' );
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
set rightIcon(icon) {
|
|
176
|
+
this.m_props.rightIcon = icon;
|
|
177
|
+
let ico = this.itemWithRef('r_icon');
|
|
178
|
+
if (ico) {
|
|
179
|
+
ico.icon = icon;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
get rightIcon() {
|
|
183
|
+
let ico = this.itemWithRef('l_icon');
|
|
184
|
+
return ico?.icon;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
*/
|
|
189
|
+
set menu(items) {
|
|
190
|
+
this.m_props.menu = items;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// :: BUTTON ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
194
|
+
/**
|
|
195
|
+
*
|
|
196
|
+
*/
|
|
197
|
+
export class Button extends BaseButton {
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
*
|
|
201
|
+
*/
|
|
202
|
+
export class ToggleButton extends BaseButton {
|
|
203
|
+
constructor(props) {
|
|
204
|
+
super(props);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
*
|
|
208
|
+
*/
|
|
209
|
+
render(props) {
|
|
210
|
+
super.render(props);
|
|
211
|
+
if (props.checked) {
|
|
212
|
+
this.addClass('checked');
|
|
213
|
+
this._updateIcon();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
*
|
|
218
|
+
*/
|
|
219
|
+
_sendClick() {
|
|
220
|
+
super._sendClick();
|
|
221
|
+
this.m_props.checked = !this.m_props.checked;
|
|
222
|
+
this.setClass('checked', this.m_props.checked);
|
|
223
|
+
this.emit('change', EvChange(this.m_props.checked));
|
|
224
|
+
this._updateIcon();
|
|
225
|
+
}
|
|
226
|
+
_updateIcon() {
|
|
227
|
+
if (this.m_props.checkedIcon) {
|
|
228
|
+
const ic = this.m_props.checked ? this.m_props.checkedIcon : this.m_props.icon;
|
|
229
|
+
let ico = this.itemWithRef('l_icon');
|
|
230
|
+
if (ico) {
|
|
231
|
+
ico.icon = ic;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file calendar.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 { Popup } from './popup';
|
|
26
|
+
import { CProps, ContainerEventMap } from './component';
|
|
27
|
+
import { EvChange, EventCallback } from './x4_events';
|
|
28
|
+
import { VLayout } from './layout';
|
|
29
|
+
interface CalendarEventMap extends ContainerEventMap {
|
|
30
|
+
change?: EvChange;
|
|
31
|
+
}
|
|
32
|
+
interface CalendarProps extends CProps<CalendarEventMap> {
|
|
33
|
+
date?: Date;
|
|
34
|
+
minDate?: Date;
|
|
35
|
+
maxDate?: Date;
|
|
36
|
+
change?: EventCallback<EvChange>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* default calendar control
|
|
40
|
+
*
|
|
41
|
+
* fires:
|
|
42
|
+
* EventChange ( value = Date )
|
|
43
|
+
*/
|
|
44
|
+
export declare class Calendar extends VLayout<CalendarProps, CalendarEventMap> {
|
|
45
|
+
private m_date;
|
|
46
|
+
constructor(props: CalendarProps);
|
|
47
|
+
/** @ignore */
|
|
48
|
+
render(props: CalendarProps): void;
|
|
49
|
+
/**
|
|
50
|
+
* select the given date
|
|
51
|
+
* @param date
|
|
52
|
+
*/
|
|
53
|
+
private select;
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
private _next;
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
private _choose;
|
|
62
|
+
get date(): Date;
|
|
63
|
+
set date(date: Date);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* default popup calendar
|
|
67
|
+
*/
|
|
68
|
+
export declare class PopupCalendar extends Popup {
|
|
69
|
+
m_cal: Calendar;
|
|
70
|
+
constructor(props: CalendarProps);
|
|
71
|
+
private _handleClick;
|
|
72
|
+
/** @ignore */
|
|
73
|
+
show(modal?: boolean): void;
|
|
74
|
+
/** @ignore */
|
|
75
|
+
close(): void;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
package/lib/calendar.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file calendar.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 { Button } from './button';
|
|
26
|
+
import { Popup } from './popup';
|
|
27
|
+
import { Component, Flex } from './component';
|
|
28
|
+
import { EvChange } from './x4_events';
|
|
29
|
+
import { _tr } from './i18n';
|
|
30
|
+
import { Label } from './label';
|
|
31
|
+
import { HLayout, VLayout } from './layout';
|
|
32
|
+
import { date_hash, date_clone, formatIntlDate } from './tools';
|
|
33
|
+
import { Menu, MenuItem } from './menu';
|
|
34
|
+
/**
|
|
35
|
+
* default calendar control
|
|
36
|
+
*
|
|
37
|
+
* fires:
|
|
38
|
+
* EventChange ( value = Date )
|
|
39
|
+
*/
|
|
40
|
+
export class Calendar extends VLayout {
|
|
41
|
+
m_date;
|
|
42
|
+
constructor(props) {
|
|
43
|
+
super(props);
|
|
44
|
+
this.mapPropEvents(props, 'change');
|
|
45
|
+
this.m_date = props.date?.clone() ?? new Date();
|
|
46
|
+
}
|
|
47
|
+
/** @ignore */
|
|
48
|
+
render(props) {
|
|
49
|
+
let month_start = date_clone(this.m_date);
|
|
50
|
+
month_start.setDate(1);
|
|
51
|
+
let day = month_start.getDay();
|
|
52
|
+
if (day == 0) {
|
|
53
|
+
day = 7;
|
|
54
|
+
}
|
|
55
|
+
month_start.setDate(-day + 1 + 1);
|
|
56
|
+
let dte = date_clone(month_start);
|
|
57
|
+
let today = this.m_date.hash();
|
|
58
|
+
let month_end = date_clone(this.m_date);
|
|
59
|
+
month_end.setDate(1);
|
|
60
|
+
month_end.setMonth(month_end.getMonth() + 1);
|
|
61
|
+
month_end.setDate(0);
|
|
62
|
+
let end_of_month = date_hash(month_end);
|
|
63
|
+
let rows = [];
|
|
64
|
+
// month selector
|
|
65
|
+
let header = new HLayout({
|
|
66
|
+
cls: 'month-sel',
|
|
67
|
+
content: [
|
|
68
|
+
new Label({
|
|
69
|
+
cls: 'month',
|
|
70
|
+
text: formatIntlDate(this.m_date, 'O'),
|
|
71
|
+
dom_events: {
|
|
72
|
+
click: () => this._choose('month')
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
new Label({
|
|
76
|
+
cls: 'year',
|
|
77
|
+
text: formatIntlDate(this.m_date, 'Y'),
|
|
78
|
+
dom_events: {
|
|
79
|
+
click: () => this._choose('year')
|
|
80
|
+
}
|
|
81
|
+
}),
|
|
82
|
+
new Flex(),
|
|
83
|
+
new Button({ text: '<', click: () => this._next(false) }),
|
|
84
|
+
new Button({ text: '>', click: () => this._next(true) })
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
rows.push(header);
|
|
88
|
+
// calendar part
|
|
89
|
+
let day_names = [];
|
|
90
|
+
// day names
|
|
91
|
+
// empty week num
|
|
92
|
+
day_names.push(new HLayout({
|
|
93
|
+
cls: 'weeknum cell',
|
|
94
|
+
}));
|
|
95
|
+
for (let d = 0; d < 7; d++) {
|
|
96
|
+
day_names.push(new Label({
|
|
97
|
+
cls: 'cell',
|
|
98
|
+
flex: 1,
|
|
99
|
+
text: _tr.global.day_short[(d + 1) % 7]
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
rows.push(new HLayout({
|
|
103
|
+
cls: 'week header',
|
|
104
|
+
content: day_names
|
|
105
|
+
}));
|
|
106
|
+
let cmonth = this.m_date.getMonth();
|
|
107
|
+
// weeks
|
|
108
|
+
let first = true;
|
|
109
|
+
while (date_hash(dte) <= end_of_month) {
|
|
110
|
+
let days = [
|
|
111
|
+
new HLayout({ cls: 'weeknum cell', content: new Component({ tag: 'span', content: formatIntlDate(dte, 'w') }) })
|
|
112
|
+
];
|
|
113
|
+
// days
|
|
114
|
+
for (let d = 0; d < 7; d++) {
|
|
115
|
+
let cls = 'cell day';
|
|
116
|
+
if (dte.hash() == today) {
|
|
117
|
+
cls += ' today';
|
|
118
|
+
}
|
|
119
|
+
if (dte.getMonth() != cmonth) {
|
|
120
|
+
cls += ' out';
|
|
121
|
+
}
|
|
122
|
+
days.push(new HLayout({
|
|
123
|
+
cls,
|
|
124
|
+
flex: 1,
|
|
125
|
+
content: new Component({
|
|
126
|
+
tag: 'span',
|
|
127
|
+
content: formatIntlDate(dte, 'd'),
|
|
128
|
+
}),
|
|
129
|
+
dom_events: {
|
|
130
|
+
click: () => this.select(dte.clone())
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
dte.setDate(dte.getDate() + 1);
|
|
134
|
+
first = false;
|
|
135
|
+
}
|
|
136
|
+
rows.push(new HLayout({
|
|
137
|
+
cls: 'week',
|
|
138
|
+
flex: 1,
|
|
139
|
+
content: days
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
this.setContent(rows);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* select the given date
|
|
146
|
+
* @param date
|
|
147
|
+
*/
|
|
148
|
+
select(date) {
|
|
149
|
+
this.m_date = date;
|
|
150
|
+
this.emit('change', EvChange(date));
|
|
151
|
+
this.update();
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
*
|
|
155
|
+
*/
|
|
156
|
+
_next(n) {
|
|
157
|
+
this.m_date.setMonth(this.m_date.getMonth() + (n ? 1 : -1));
|
|
158
|
+
this.update();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
*/
|
|
163
|
+
_choose(type) {
|
|
164
|
+
let items = [];
|
|
165
|
+
if (type == 'month') {
|
|
166
|
+
for (let m = 0; m < 12; m++) {
|
|
167
|
+
items.push(new MenuItem({
|
|
168
|
+
text: _tr.global.month_long[m],
|
|
169
|
+
click: () => { this.m_date.setMonth(m); this.update(); }
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (type == 'year') {
|
|
174
|
+
let min = this.m_props.minDate?.getFullYear() ?? 1900;
|
|
175
|
+
let max = this.m_props.maxDate?.getFullYear() ?? 2037;
|
|
176
|
+
for (let m = min; m < max; m++) {
|
|
177
|
+
items.push(new MenuItem({
|
|
178
|
+
text: '' + m,
|
|
179
|
+
click: () => { this.m_date.setFullYear(m); this.update(); }
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
let menu = new Menu({
|
|
184
|
+
items
|
|
185
|
+
});
|
|
186
|
+
let rc = this.getBoundingRect();
|
|
187
|
+
menu.displayAt(rc.left, rc.top);
|
|
188
|
+
}
|
|
189
|
+
get date() {
|
|
190
|
+
return this.m_date;
|
|
191
|
+
}
|
|
192
|
+
set date(date) {
|
|
193
|
+
this.m_date = date;
|
|
194
|
+
this.update();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* default popup calendar
|
|
199
|
+
*/
|
|
200
|
+
export class PopupCalendar extends Popup {
|
|
201
|
+
m_cal;
|
|
202
|
+
constructor(props) {
|
|
203
|
+
super({ tabIndex: 1 });
|
|
204
|
+
this.enableMask(false);
|
|
205
|
+
this.m_cal = new Calendar(props);
|
|
206
|
+
this.m_cal.addClass('@fit');
|
|
207
|
+
this.setContent(this.m_cal);
|
|
208
|
+
}
|
|
209
|
+
// binded
|
|
210
|
+
_handleClick = (e) => {
|
|
211
|
+
if (!this.dom) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
let newfocus = e.target;
|
|
215
|
+
// child of this: ok
|
|
216
|
+
if (this.dom.contains(newfocus)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
// menu: ok
|
|
220
|
+
let dest = Component.getElement(newfocus, MenuItem);
|
|
221
|
+
if (dest) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
this.close();
|
|
225
|
+
};
|
|
226
|
+
/** @ignore */
|
|
227
|
+
show(modal) {
|
|
228
|
+
document.addEventListener('mousedown', this._handleClick);
|
|
229
|
+
super.show(modal);
|
|
230
|
+
}
|
|
231
|
+
/** @ignore */
|
|
232
|
+
close() {
|
|
233
|
+
document.removeEventListener('mousedown', this._handleClick);
|
|
234
|
+
super.close();
|
|
235
|
+
}
|
|
236
|
+
}
|
package/lib/canvas.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file canvas.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 { BasicEvent, EventCallback } from './x4_events';
|
|
27
|
+
interface EvPaint extends BasicEvent {
|
|
28
|
+
ctx: CanvasPainter;
|
|
29
|
+
}
|
|
30
|
+
declare function EvPaint(ctx: CanvasPainter): EvPaint;
|
|
31
|
+
interface CanvasEventMap extends CEventMap {
|
|
32
|
+
paint: EvPaint;
|
|
33
|
+
}
|
|
34
|
+
interface CanvasProps extends CProps<CanvasEventMap> {
|
|
35
|
+
autoClear?: boolean;
|
|
36
|
+
painter?: PaintHandler;
|
|
37
|
+
paint: EventCallback<EvPaint>;
|
|
38
|
+
}
|
|
39
|
+
export interface CanvasPainter extends CanvasRenderingContext2D {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
smoothLine(points: any[], path: CanvasPath, move: boolean): void;
|
|
43
|
+
smoothLineEx(_points: any[], tension: number, numOfSeg: number, path: CanvasPath, move?: boolean, close?: boolean): void;
|
|
44
|
+
line(x1: number, y1: number, x2: number, y2: number, color: string, lineWidth: number): void;
|
|
45
|
+
roundRect(x: number, y: number, width: number, height: number, radius: number): void;
|
|
46
|
+
calcTextSize(text: string, rounded: boolean): {
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
};
|
|
50
|
+
setFontSize(fs: number): void;
|
|
51
|
+
circle(x: number, y: number, radius: number): void;
|
|
52
|
+
}
|
|
53
|
+
declare type PaintHandler = (ctx: CanvasPainter) => any;
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Standard Canvas
|
|
59
|
+
*/
|
|
60
|
+
export declare class Canvas extends Component<CanvasProps, CanvasEventMap> {
|
|
61
|
+
private m_iwidth;
|
|
62
|
+
private m_iheight;
|
|
63
|
+
private m_scale;
|
|
64
|
+
private m_canvas;
|
|
65
|
+
constructor(props: CanvasProps);
|
|
66
|
+
/** @ignore */
|
|
67
|
+
render(): void;
|
|
68
|
+
update(delay?: number): void;
|
|
69
|
+
/**
|
|
70
|
+
* scale the whole canvas
|
|
71
|
+
*/
|
|
72
|
+
scale(scale: number): void;
|
|
73
|
+
/**
|
|
74
|
+
* return the internal canvas
|
|
75
|
+
*/
|
|
76
|
+
get canvas(): Component;
|
|
77
|
+
/**
|
|
78
|
+
* redraw the canvas (force a paint)
|
|
79
|
+
*/
|
|
80
|
+
private $update_rep;
|
|
81
|
+
redraw(wait?: number): void;
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
private _paint;
|
|
86
|
+
protected paint(ctx: CanvasPainter): void;
|
|
87
|
+
}
|
|
88
|
+
export {};
|