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/textarea.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file textarea.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 { asap } from './tools';
|
|
28
|
+
export class TextArea extends Component {
|
|
29
|
+
constructor(props) {
|
|
30
|
+
super(props);
|
|
31
|
+
this.mapPropEvents(props, 'change');
|
|
32
|
+
}
|
|
33
|
+
/** @ignore */
|
|
34
|
+
render(props) {
|
|
35
|
+
props.text = props.text ?? '';
|
|
36
|
+
this.setAttribute('tabindex', props.tabIndex ?? 0);
|
|
37
|
+
if (props.spellcheck === false) {
|
|
38
|
+
this.setAttribute('spellcheck', 'false');
|
|
39
|
+
}
|
|
40
|
+
if (props.readOnly !== undefined) {
|
|
41
|
+
this.setAttribute('readonly', props.readOnly);
|
|
42
|
+
}
|
|
43
|
+
if (props.rows) {
|
|
44
|
+
this.setAttribute('rows', props.rows);
|
|
45
|
+
}
|
|
46
|
+
if (props.placeHolder) {
|
|
47
|
+
this.setAttribute('placeholder', props.placeHolder);
|
|
48
|
+
}
|
|
49
|
+
if (props.autoFocus) {
|
|
50
|
+
this.setAttribute('autofocus', props.autoFocus);
|
|
51
|
+
}
|
|
52
|
+
if (props.name) {
|
|
53
|
+
this.setAttribute('name', props.name);
|
|
54
|
+
}
|
|
55
|
+
if (props.autoGrow) {
|
|
56
|
+
this.setProp('autoGrow', true);
|
|
57
|
+
this.setAttribute('rows', this._calcHeight(props.text));
|
|
58
|
+
this.setDomEvent('keydown', () => {
|
|
59
|
+
asap(() => this._updateHeight());
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// avoid going to next element on enter
|
|
63
|
+
this.setDomEvent('keydown', (e) => {
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
});
|
|
66
|
+
this.setDomEvent('input', () => this._change());
|
|
67
|
+
this.setProp('tag', 'textarea');
|
|
68
|
+
}
|
|
69
|
+
_change() {
|
|
70
|
+
this.emit('change', EvChange(this.value));
|
|
71
|
+
}
|
|
72
|
+
componentCreated() {
|
|
73
|
+
this.value = this.m_props.text;
|
|
74
|
+
}
|
|
75
|
+
get value() {
|
|
76
|
+
if (this.dom) {
|
|
77
|
+
return this.dom.value;
|
|
78
|
+
}
|
|
79
|
+
return this.m_props.text;
|
|
80
|
+
}
|
|
81
|
+
set value(t) {
|
|
82
|
+
this.m_props.text = t ?? '';
|
|
83
|
+
if (this.dom) {
|
|
84
|
+
this.dom.value = this.m_props.text;
|
|
85
|
+
if (this.m_props.autoGrow) {
|
|
86
|
+
this.setAttribute('rows', this._calcHeight(this.m_props.text));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
_calcHeight(text) {
|
|
91
|
+
return 1 + (text.match(/\n/g) || []).length;
|
|
92
|
+
}
|
|
93
|
+
_updateHeight() {
|
|
94
|
+
const text = this.value;
|
|
95
|
+
const lines = this._calcHeight(text);
|
|
96
|
+
if (this.getData('lines') != lines) {
|
|
97
|
+
this.setAttribute('rows', lines);
|
|
98
|
+
this.setData('lines', lines);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* insert text at cursor position
|
|
103
|
+
*/
|
|
104
|
+
insertText(text) {
|
|
105
|
+
if (this.dom) {
|
|
106
|
+
let dom = this.dom;
|
|
107
|
+
let start = dom.selectionStart;
|
|
108
|
+
dom.setRangeText(text);
|
|
109
|
+
dom.selectionStart = start;
|
|
110
|
+
dom.selectionEnd = start + text.length;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
getStoreValue() {
|
|
114
|
+
return this.value;
|
|
115
|
+
}
|
|
116
|
+
setStoreValue(value) {
|
|
117
|
+
this.value = value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file textedit.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, EvFocus, HtmlString } from './component';
|
|
26
|
+
import { Input, InputProps, InputEventMap } from './input';
|
|
27
|
+
import { IconID } from './icon';
|
|
28
|
+
import { EvClick, EvChange, EventCallback } from './x4_events';
|
|
29
|
+
declare type ValidationFunction = (value: string) => string;
|
|
30
|
+
interface TextEditEventMap extends InputEventMap {
|
|
31
|
+
click: EvClick;
|
|
32
|
+
change: EvChange;
|
|
33
|
+
focus: EvFocus;
|
|
34
|
+
}
|
|
35
|
+
export interface TextEditProps extends InputProps<TextEditEventMap> {
|
|
36
|
+
label?: string | HtmlString;
|
|
37
|
+
labelWidth?: number;
|
|
38
|
+
labelAlign?: 'left' | 'right' | 'top';
|
|
39
|
+
required?: boolean;
|
|
40
|
+
spellcheck?: boolean;
|
|
41
|
+
icon?: IconID;
|
|
42
|
+
pattern?: string;
|
|
43
|
+
uppercase?: boolean;
|
|
44
|
+
format?: string | 'native';
|
|
45
|
+
gadgets?: Component[];
|
|
46
|
+
validator?: ValidationFunction;
|
|
47
|
+
change?: EventCallback<EvChange>;
|
|
48
|
+
click?: EventCallback<EvClick>;
|
|
49
|
+
focus?: EventCallback<EvFocus>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* TextEdit is a single line editor, it can have a label and an error descriptor.
|
|
53
|
+
*/
|
|
54
|
+
export declare class TextEdit<T extends TextEditProps = TextEditProps> extends Component<TextEditProps, TextEditEventMap> {
|
|
55
|
+
private m_cal_popup;
|
|
56
|
+
protected m_ui_input: Input;
|
|
57
|
+
private m_error_tip;
|
|
58
|
+
constructor(props: TextEditProps);
|
|
59
|
+
componentCreated(): void;
|
|
60
|
+
componentDisposed(): void;
|
|
61
|
+
focus(): void;
|
|
62
|
+
/** @ignore */
|
|
63
|
+
render(props: TextEditProps): void;
|
|
64
|
+
enable(ena?: boolean): void;
|
|
65
|
+
disable(): void;
|
|
66
|
+
private _btnClick;
|
|
67
|
+
/**
|
|
68
|
+
* select the value format for input/output on textedit of type date
|
|
69
|
+
* cf. formatIntlDate / parseIntlDate
|
|
70
|
+
* @param fmt
|
|
71
|
+
*/
|
|
72
|
+
setDateStoreFormat(fmt: string): void;
|
|
73
|
+
setStoreValue(value: any): void;
|
|
74
|
+
getStoreValue(): any;
|
|
75
|
+
private _date_get_hook;
|
|
76
|
+
private _date_set_hook;
|
|
77
|
+
showError(text: string): void;
|
|
78
|
+
clearError(): void;
|
|
79
|
+
get value(): string;
|
|
80
|
+
set value(value: string);
|
|
81
|
+
/**
|
|
82
|
+
* select all the text
|
|
83
|
+
*/
|
|
84
|
+
selectAll(): void;
|
|
85
|
+
select(start: number, length?: number): void;
|
|
86
|
+
getSelection(): {
|
|
87
|
+
start: number;
|
|
88
|
+
length: number;
|
|
89
|
+
};
|
|
90
|
+
set readOnly(ro: boolean);
|
|
91
|
+
get label(): string | HtmlString;
|
|
92
|
+
set label(text: string | HtmlString);
|
|
93
|
+
/**
|
|
94
|
+
* content changed
|
|
95
|
+
* todo: should move into Input
|
|
96
|
+
*/
|
|
97
|
+
private _change;
|
|
98
|
+
/**
|
|
99
|
+
* getting focus
|
|
100
|
+
*/
|
|
101
|
+
private _focus;
|
|
102
|
+
/**
|
|
103
|
+
* loosing focus
|
|
104
|
+
* @param value
|
|
105
|
+
*/
|
|
106
|
+
private _blur;
|
|
107
|
+
/**
|
|
108
|
+
* todo: should move into Input
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
111
|
+
validate(): boolean;
|
|
112
|
+
private _validate;
|
|
113
|
+
_date_validator(value: string): string;
|
|
114
|
+
private _showDatePicker;
|
|
115
|
+
get input(): Input;
|
|
116
|
+
get type(): import("./input").EditType;
|
|
117
|
+
}
|
|
118
|
+
export {};
|
package/lib/textedit.js
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file textedit.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, EvFocus } from './component';
|
|
26
|
+
import { Input } from './input';
|
|
27
|
+
import { Button } from './button';
|
|
28
|
+
import { HLayout } from './layout';
|
|
29
|
+
import { Label } from './label';
|
|
30
|
+
import { PopupCalendar } from './calendar';
|
|
31
|
+
import { sprintf, parseIntlDate, formatIntlDate } from './tools';
|
|
32
|
+
import { Tooltip } from './tooltips';
|
|
33
|
+
import { EvClick, EvChange } from './x4_events';
|
|
34
|
+
import { _tr } from './i18n';
|
|
35
|
+
/** @ignore */
|
|
36
|
+
const reEmail = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
37
|
+
/**
|
|
38
|
+
* TextEdit is a single line editor, it can have a label and an error descriptor.
|
|
39
|
+
*/
|
|
40
|
+
export class TextEdit extends Component {
|
|
41
|
+
m_cal_popup;
|
|
42
|
+
m_ui_input;
|
|
43
|
+
m_error_tip;
|
|
44
|
+
constructor(props) {
|
|
45
|
+
super(props);
|
|
46
|
+
this.addClass('@hlayout');
|
|
47
|
+
this.mapPropEvents(props, 'change', 'click', 'focus');
|
|
48
|
+
}
|
|
49
|
+
componentCreated() {
|
|
50
|
+
super.componentCreated();
|
|
51
|
+
if (this.m_props.autoFocus) {
|
|
52
|
+
this.focus();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
componentDisposed() {
|
|
56
|
+
if (this.m_error_tip) {
|
|
57
|
+
this.m_error_tip.dispose();
|
|
58
|
+
}
|
|
59
|
+
super.componentDisposed();
|
|
60
|
+
}
|
|
61
|
+
focus() {
|
|
62
|
+
this.m_ui_input.focus();
|
|
63
|
+
}
|
|
64
|
+
/** @ignore */
|
|
65
|
+
render(props) {
|
|
66
|
+
let eprops = {
|
|
67
|
+
flex: 1,
|
|
68
|
+
dom_events: {
|
|
69
|
+
focus: () => this._focus(),
|
|
70
|
+
blur: () => this._blur(),
|
|
71
|
+
input: () => this._change()
|
|
72
|
+
},
|
|
73
|
+
value: props.value,
|
|
74
|
+
name: props.name,
|
|
75
|
+
type: props.type,
|
|
76
|
+
placeHolder: props.placeHolder,
|
|
77
|
+
autoFocus: props.autoFocus,
|
|
78
|
+
readOnly: props.readOnly,
|
|
79
|
+
value_hook: props.value_hook,
|
|
80
|
+
uppercase: props.uppercase,
|
|
81
|
+
spellcheck: props.spellcheck,
|
|
82
|
+
tabIndex: props.tabIndex === undefined ? true : props.tabIndex,
|
|
83
|
+
attrs: props.attrs,
|
|
84
|
+
min: props.min,
|
|
85
|
+
max: props.max,
|
|
86
|
+
};
|
|
87
|
+
// date is handled manually with popupcalendar
|
|
88
|
+
if (props.type == 'date') {
|
|
89
|
+
props.format = props.format ?? 'Y-M-D';
|
|
90
|
+
eprops.type = 'text';
|
|
91
|
+
let def_hook = {
|
|
92
|
+
get: () => this._date_get_hook(),
|
|
93
|
+
set: (e) => this._date_set_hook(e)
|
|
94
|
+
};
|
|
95
|
+
eprops.value_hook = props.value_hook ?? def_hook;
|
|
96
|
+
}
|
|
97
|
+
this.m_ui_input = new Input(eprops);
|
|
98
|
+
// button
|
|
99
|
+
let button = undefined;
|
|
100
|
+
if (props.icon) {
|
|
101
|
+
button = new Button({
|
|
102
|
+
icon: props.icon,
|
|
103
|
+
click: () => this._btnClick(),
|
|
104
|
+
tabIndex: false
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else if (props.type == 'date') {
|
|
108
|
+
button = new Button({
|
|
109
|
+
cls: 'gadget',
|
|
110
|
+
icon: 'cls(far fa-calendar-days)',
|
|
111
|
+
tabIndex: false,
|
|
112
|
+
click: () => this._showDatePicker(button)
|
|
113
|
+
});
|
|
114
|
+
if (!props.validator) {
|
|
115
|
+
props.validator = this._date_validator;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
let ag = props.gadgets ?? [];
|
|
119
|
+
ag.forEach(b => {
|
|
120
|
+
b.addClass('gadget');
|
|
121
|
+
});
|
|
122
|
+
let gadgets = [button, ...ag];
|
|
123
|
+
this.setClass('@required', props.required);
|
|
124
|
+
if (props.gadgets && props.gadgets.length) {
|
|
125
|
+
this.addClass('with-gadgets');
|
|
126
|
+
}
|
|
127
|
+
let width = undefined, flex = undefined, labelWidth = props.labelWidth;
|
|
128
|
+
if (labelWidth > 0) {
|
|
129
|
+
width = labelWidth;
|
|
130
|
+
}
|
|
131
|
+
if (labelWidth < 0) {
|
|
132
|
+
flex = -labelWidth;
|
|
133
|
+
}
|
|
134
|
+
let label = undefined;
|
|
135
|
+
let labelAlign = props.labelAlign;
|
|
136
|
+
let top = false;
|
|
137
|
+
if (props.label) {
|
|
138
|
+
if (labelAlign == 'top') {
|
|
139
|
+
labelAlign = 'left';
|
|
140
|
+
top = true;
|
|
141
|
+
flex = 1;
|
|
142
|
+
}
|
|
143
|
+
label = new Label({
|
|
144
|
+
ref: 'label',
|
|
145
|
+
tag: 'label',
|
|
146
|
+
cls: 'label1' + (props.label ? '' : ' @hidden'),
|
|
147
|
+
text: props.label ?? '',
|
|
148
|
+
width,
|
|
149
|
+
flex,
|
|
150
|
+
align: labelAlign
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (top) {
|
|
154
|
+
this.removeClass('@hlayout');
|
|
155
|
+
this.addClass('@vlayout vertical');
|
|
156
|
+
this.setContent([
|
|
157
|
+
label,
|
|
158
|
+
new HLayout({ width, content: [this.m_ui_input, ...gadgets] })
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.addClass('@hlayout');
|
|
163
|
+
this.setContent([label, this.m_ui_input, ...gadgets]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
enable(ena) {
|
|
167
|
+
if (ena === true) {
|
|
168
|
+
this.m_ui_input.enable();
|
|
169
|
+
}
|
|
170
|
+
super.enable(ena);
|
|
171
|
+
}
|
|
172
|
+
disable() {
|
|
173
|
+
this.m_ui_input.disable();
|
|
174
|
+
super.disable();
|
|
175
|
+
}
|
|
176
|
+
_btnClick() {
|
|
177
|
+
this.emit('click', EvClick(this.value));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* select the value format for input/output on textedit of type date
|
|
181
|
+
* cf. formatIntlDate / parseIntlDate
|
|
182
|
+
* @param fmt
|
|
183
|
+
*/
|
|
184
|
+
setDateStoreFormat(fmt) {
|
|
185
|
+
this.m_props.format = fmt;
|
|
186
|
+
}
|
|
187
|
+
setStoreValue(value) {
|
|
188
|
+
this.m_ui_input.setStoreValue(value);
|
|
189
|
+
}
|
|
190
|
+
getStoreValue() {
|
|
191
|
+
return this.m_ui_input.getStoreValue();
|
|
192
|
+
}
|
|
193
|
+
_date_get_hook() {
|
|
194
|
+
let date = parseIntlDate(this.value);
|
|
195
|
+
let props = this.m_props;
|
|
196
|
+
if (props.format == 'native') {
|
|
197
|
+
return date;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return date ? formatIntlDate(date, props.format) : null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
_date_set_hook(dte) {
|
|
204
|
+
let props = this.m_props;
|
|
205
|
+
if (props.format == 'native') {
|
|
206
|
+
this.value = formatIntlDate(dte);
|
|
207
|
+
}
|
|
208
|
+
else if (dte) {
|
|
209
|
+
let date = parseIntlDate(dte, props.format);
|
|
210
|
+
this.value = formatIntlDate(date);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this.value = '';
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
showError(text) {
|
|
217
|
+
if (!this.m_error_tip) {
|
|
218
|
+
this.m_error_tip = new Tooltip({ cls: 'error' });
|
|
219
|
+
document.body.appendChild(this.m_error_tip._build());
|
|
220
|
+
}
|
|
221
|
+
let rc = this.m_ui_input.getBoundingRect();
|
|
222
|
+
this.m_error_tip.text = text;
|
|
223
|
+
this.m_error_tip.displayAt(rc.right, rc.top, 'top left');
|
|
224
|
+
this.addClass('@error');
|
|
225
|
+
}
|
|
226
|
+
clearError() {
|
|
227
|
+
if (this.m_error_tip) {
|
|
228
|
+
this.m_error_tip.hide();
|
|
229
|
+
this.removeClass('@error');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
get value() {
|
|
233
|
+
if (this.m_ui_input) {
|
|
234
|
+
return this.m_ui_input.value;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
return this.m_props.value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
set value(value) {
|
|
241
|
+
if (this.m_ui_input) {
|
|
242
|
+
this.m_ui_input.value = value;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
this.m_props.value = value;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* select all the text
|
|
250
|
+
*/
|
|
251
|
+
selectAll() {
|
|
252
|
+
this.m_ui_input.selectAll();
|
|
253
|
+
}
|
|
254
|
+
select(start, length = 9999) {
|
|
255
|
+
this.m_ui_input.select(start, length);
|
|
256
|
+
}
|
|
257
|
+
getSelection() {
|
|
258
|
+
return this.m_ui_input.getSelection();
|
|
259
|
+
}
|
|
260
|
+
set readOnly(ro) {
|
|
261
|
+
this.m_ui_input.readOnly = ro;
|
|
262
|
+
}
|
|
263
|
+
get label() {
|
|
264
|
+
return this.itemWithRef('label')?.text;
|
|
265
|
+
}
|
|
266
|
+
set label(text) {
|
|
267
|
+
this.itemWithRef('label').text = text;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* content changed
|
|
271
|
+
* todo: should move into Input
|
|
272
|
+
*/
|
|
273
|
+
_change() {
|
|
274
|
+
let value = this.m_ui_input.value;
|
|
275
|
+
this.emit('change', EvChange(value));
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* getting focus
|
|
279
|
+
*/
|
|
280
|
+
_focus() {
|
|
281
|
+
this.clearError();
|
|
282
|
+
this.emit('focus', EvFocus(true));
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* loosing focus
|
|
286
|
+
* @param value
|
|
287
|
+
*/
|
|
288
|
+
_blur() {
|
|
289
|
+
this._validate(this.m_ui_input.value);
|
|
290
|
+
this.emit('focus', EvFocus(false));
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* todo: should move into Input
|
|
294
|
+
* @returns
|
|
295
|
+
*/
|
|
296
|
+
validate() {
|
|
297
|
+
return this._validate(this.value);
|
|
298
|
+
}
|
|
299
|
+
_validate(value) {
|
|
300
|
+
let props = this.m_props;
|
|
301
|
+
let update = false;
|
|
302
|
+
if (props.required && value.length == 0) {
|
|
303
|
+
this.showError(_tr.global.required_field);
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
if (value != '') {
|
|
307
|
+
let pattern = this.getAttribute('pattern');
|
|
308
|
+
if (pattern) {
|
|
309
|
+
let re = new RegExp(pattern);
|
|
310
|
+
if (re && !re.test(value)) {
|
|
311
|
+
this.showError(_tr.global.invalid_format);
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (props.type == 'email') {
|
|
316
|
+
if (!reEmail.test(value.toLowerCase())) {
|
|
317
|
+
this.showError(_tr.global.invalid_email);
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else if (props.type == 'number') {
|
|
322
|
+
const v = parseFloat(value);
|
|
323
|
+
if (isNaN(v)) {
|
|
324
|
+
this.showError(_tr.global.invalid_number);
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
let min = parseFloat(this.m_ui_input.getAttribute('min'));
|
|
328
|
+
if (min !== undefined && v < min) {
|
|
329
|
+
value = '' + min;
|
|
330
|
+
update = true;
|
|
331
|
+
}
|
|
332
|
+
let max = parseFloat(this.m_ui_input.getAttribute('max'));
|
|
333
|
+
if (max !== undefined && v > max) {
|
|
334
|
+
value = '' + max;
|
|
335
|
+
update = true;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (props.validator) {
|
|
340
|
+
try {
|
|
341
|
+
this.value = props.validator(value);
|
|
342
|
+
}
|
|
343
|
+
catch (err) {
|
|
344
|
+
this.showError(err instanceof Error ? err.message : err);
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else if (update) {
|
|
349
|
+
this.value = value;
|
|
350
|
+
}
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
_date_validator(value) {
|
|
354
|
+
value = value.trim();
|
|
355
|
+
if (value == '') {
|
|
356
|
+
return '';
|
|
357
|
+
}
|
|
358
|
+
let date;
|
|
359
|
+
if (value == '@') {
|
|
360
|
+
date = new Date();
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
date = parseIntlDate(value);
|
|
364
|
+
if (!date) {
|
|
365
|
+
throw sprintf(_tr.global.invalid_date, _tr.global.date_format);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return formatIntlDate(date);
|
|
369
|
+
}
|
|
370
|
+
//onKeyDown( e ) {
|
|
371
|
+
// if( this.readOnly ) {
|
|
372
|
+
// if( this.type=='date' && (e.key==' ' || e.key=='Enter') ) {
|
|
373
|
+
// this.showDatePicker( );
|
|
374
|
+
// e.stopPropagation( );
|
|
375
|
+
// e.preventDefault( );
|
|
376
|
+
// }
|
|
377
|
+
// }
|
|
378
|
+
//}
|
|
379
|
+
//onClick( e ) {
|
|
380
|
+
// if( this.readOnly ) {
|
|
381
|
+
// if( this.type=='date' ) {
|
|
382
|
+
// this.showDatePicker( );
|
|
383
|
+
// e.stopPropagation( );
|
|
384
|
+
// e.preventDefault( );
|
|
385
|
+
// }
|
|
386
|
+
// }
|
|
387
|
+
//}
|
|
388
|
+
_showDatePicker(btn) {
|
|
389
|
+
if (!this.m_cal_popup) {
|
|
390
|
+
this.m_cal_popup = new PopupCalendar({
|
|
391
|
+
change: (ev) => {
|
|
392
|
+
this.value = formatIntlDate(ev.value);
|
|
393
|
+
this.m_cal_popup.close();
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
let rc = this.m_ui_input.getBoundingRect();
|
|
398
|
+
this.m_cal_popup.displayAt(rc.left, rc.bottom, 'top left');
|
|
399
|
+
}
|
|
400
|
+
get input() {
|
|
401
|
+
return this.m_ui_input;
|
|
402
|
+
}
|
|
403
|
+
get type() {
|
|
404
|
+
return this.m_props.type;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file texthiliter.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
|
+
* idea came from https://www.cdolivet.com/editarea
|
|
27
|
+
*/
|
|
28
|
+
import { Component, CProps, CEventMap } from './component';
|
|
29
|
+
import { EvChange } from './x4_events';
|
|
30
|
+
interface TextHiliterEventMap extends CEventMap {
|
|
31
|
+
change: EvChange;
|
|
32
|
+
}
|
|
33
|
+
interface TextHiliterProps extends CProps {
|
|
34
|
+
text: string;
|
|
35
|
+
kwList?: Set<string>;
|
|
36
|
+
change?: EvChange;
|
|
37
|
+
}
|
|
38
|
+
export declare class TextHiliter extends Component<TextHiliterProps, TextHiliterEventMap> {
|
|
39
|
+
private m_text;
|
|
40
|
+
private m_ed;
|
|
41
|
+
private m_hi;
|
|
42
|
+
private m_top;
|
|
43
|
+
private m_kwList;
|
|
44
|
+
constructor(props: TextHiliterProps);
|
|
45
|
+
/** @ignore */
|
|
46
|
+
render(): void;
|
|
47
|
+
componentCreated(): void;
|
|
48
|
+
get value(): string;
|
|
49
|
+
set value(t: string);
|
|
50
|
+
private _keydown;
|
|
51
|
+
private _hiliteText;
|
|
52
|
+
private _updateScroll;
|
|
53
|
+
private _escape;
|
|
54
|
+
private _tokenize;
|
|
55
|
+
}
|
|
56
|
+
export {};
|