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.
Files changed (176) hide show
  1. package/lib/application.d.ts +95 -0
  2. package/lib/application.js +137 -0
  3. package/lib/base64.d.ts +31 -0
  4. package/lib/base64.js +135 -0
  5. package/lib/base_component.d.ts +64 -0
  6. package/lib/base_component.js +77 -0
  7. package/lib/button.d.ts +145 -0
  8. package/lib/button.js +235 -0
  9. package/lib/calendar.d.ts +77 -0
  10. package/lib/calendar.js +236 -0
  11. package/lib/canvas.d.ts +88 -0
  12. package/lib/canvas.js +354 -0
  13. package/lib/cardview.d.ts +83 -0
  14. package/lib/cardview.js +152 -0
  15. package/lib/checkbox.d.ts +72 -0
  16. package/lib/checkbox.js +126 -0
  17. package/lib/color.d.ts +144 -0
  18. package/lib/color.js +584 -0
  19. package/lib/colorpicker.d.ts +98 -0
  20. package/lib/colorpicker.js +1457 -0
  21. package/lib/combobox.d.ts +97 -0
  22. package/lib/combobox.js +246 -0
  23. package/lib/component.d.ts +572 -0
  24. package/lib/component.js +1712 -0
  25. package/lib/datastore.d.ts +392 -0
  26. package/lib/datastore.js +986 -0
  27. package/lib/dialog.d.ts +171 -0
  28. package/lib/dialog.js +468 -0
  29. package/lib/dom_events.d.ts +284 -0
  30. package/lib/dom_events.js +13 -0
  31. package/lib/drag_manager.d.ts +26 -0
  32. package/lib/drag_manager.js +118 -0
  33. package/lib/drawtext.d.ts +43 -0
  34. package/lib/drawtext.js +261 -0
  35. package/lib/fileupload.d.ts +60 -0
  36. package/lib/fileupload.js +158 -0
  37. package/lib/form.d.ts +122 -0
  38. package/lib/form.js +293 -0
  39. package/lib/formatters.d.ts +31 -0
  40. package/lib/formatters.js +75 -0
  41. package/lib/gridview.d.ts +171 -0
  42. package/lib/gridview.js +786 -0
  43. package/lib/hosts/host.d.ts +44 -0
  44. package/lib/hosts/host.js +69 -0
  45. package/lib/i18n.d.ts +67 -0
  46. package/lib/i18n.js +169 -0
  47. package/lib/icon.d.ts +56 -0
  48. package/lib/icon.js +173 -0
  49. package/lib/image.d.ts +51 -0
  50. package/lib/image.js +149 -0
  51. package/lib/index.js +1 -0
  52. package/lib/input.d.ts +86 -0
  53. package/lib/input.js +172 -0
  54. package/lib/label.d.ts +54 -0
  55. package/lib/label.js +86 -0
  56. package/lib/layout.d.ts +77 -0
  57. package/lib/layout.js +261 -0
  58. package/lib/link.d.ts +46 -0
  59. package/lib/link.js +55 -0
  60. package/lib/listview.d.ts +173 -0
  61. package/lib/listview.js +532 -0
  62. package/lib/md5.d.ts +56 -0
  63. package/lib/md5.js +397 -0
  64. package/lib/menu.d.ts +122 -0
  65. package/lib/menu.js +276 -0
  66. package/lib/messagebox.d.ts +64 -0
  67. package/lib/messagebox.js +141 -0
  68. package/lib/panel.d.ts +42 -0
  69. package/lib/panel.js +61 -0
  70. package/lib/popup.d.ts +71 -0
  71. package/lib/popup.js +373 -0
  72. package/lib/property_editor.d.ts +67 -0
  73. package/lib/property_editor.js +247 -0
  74. package/lib/radiobtn.d.ts +68 -0
  75. package/lib/radiobtn.js +131 -0
  76. package/lib/rating.d.ts +49 -0
  77. package/lib/rating.js +93 -0
  78. package/lib/request.d.ts +48 -0
  79. package/lib/request.js +220 -0
  80. package/lib/router.d.ts +13 -0
  81. package/lib/router.js +27 -0
  82. package/lib/settings.d.ts +33 -0
  83. package/lib/settings.js +63 -0
  84. package/lib/sidebarview.d.ts +44 -0
  85. package/lib/sidebarview.js +73 -0
  86. package/lib/smartedit.d.ts +103 -0
  87. package/lib/smartedit.js +381 -0
  88. package/lib/spreadsheet.d.ts +214 -0
  89. package/lib/spreadsheet.js +1073 -0
  90. package/lib/styles.d.ts +81 -0
  91. package/lib/styles.js +262 -0
  92. package/lib/svgcomponent.d.ts +165 -0
  93. package/lib/svgcomponent.js +350 -0
  94. package/lib/tabbar.d.ts +41 -0
  95. package/lib/tabbar.js +66 -0
  96. package/lib/tabview.d.ts +45 -0
  97. package/lib/tabview.js +79 -0
  98. package/lib/textarea.d.ts +59 -0
  99. package/lib/textarea.js +119 -0
  100. package/lib/textedit.d.ts +118 -0
  101. package/lib/textedit.js +406 -0
  102. package/lib/texthiliter.d.ts +56 -0
  103. package/lib/texthiliter.js +219 -0
  104. package/lib/toaster.d.ts +38 -0
  105. package/lib/toaster.js +58 -0
  106. package/lib/tools.d.ts +382 -0
  107. package/lib/tools.js +1096 -0
  108. package/lib/tooltips.d.ts +42 -0
  109. package/lib/tooltips.js +148 -0
  110. package/lib/treeview.d.ts +128 -0
  111. package/lib/treeview.js +490 -0
  112. package/lib/x4_events.d.ts +253 -0
  113. package/lib/x4_events.js +363 -0
  114. package/package.json +21 -0
  115. package/src/README.md +2 -0
  116. package/src/application.ts +191 -0
  117. package/src/base64.ts +162 -0
  118. package/src/base_component.ts +118 -0
  119. package/src/button.ts +327 -0
  120. package/src/calendar.ts +312 -0
  121. package/src/canvas.ts +501 -0
  122. package/src/cardview.ts +220 -0
  123. package/src/checkbox.ts +178 -0
  124. package/src/color.ts +748 -0
  125. package/src/colorpicker.ts +1618 -0
  126. package/src/combobox.ts +348 -0
  127. package/src/component.ts +2330 -0
  128. package/src/datastore.ts +1318 -0
  129. package/src/dialog.ts +631 -0
  130. package/src/dom_events.ts +297 -0
  131. package/src/drag_manager.ts +168 -0
  132. package/src/drawtext.ts +342 -0
  133. package/src/fileupload.ts +208 -0
  134. package/src/form.ts +362 -0
  135. package/src/formatters.ts +96 -0
  136. package/src/gridview.ts +1051 -0
  137. package/src/hosts/electron.ts +161 -0
  138. package/src/hosts/host.ts +100 -0
  139. package/src/hosts/nwjs.ts +141 -0
  140. package/src/hosts/nwjs_types.ts +339 -0
  141. package/src/i18n.ts +205 -0
  142. package/src/icon.ts +237 -0
  143. package/src/image.ts +198 -0
  144. package/src/input.ts +236 -0
  145. package/src/label.ts +124 -0
  146. package/src/layout.ts +366 -0
  147. package/src/link.ts +82 -0
  148. package/src/listview.ts +749 -0
  149. package/src/md5.ts +432 -0
  150. package/src/menu.ts +394 -0
  151. package/src/messagebox.ts +199 -0
  152. package/src/panel.ts +81 -0
  153. package/src/popup.ts +488 -0
  154. package/src/property_editor.ts +333 -0
  155. package/src/radiobtn.ts +190 -0
  156. package/src/rating.ts +131 -0
  157. package/src/request.ts +296 -0
  158. package/src/router.ts +43 -0
  159. package/src/settings.ts +75 -0
  160. package/src/sidebarview.ts +97 -0
  161. package/src/smartedit.ts +532 -0
  162. package/src/spreadsheet.ts +1423 -0
  163. package/src/styles.ts +332 -0
  164. package/src/svgcomponent.ts +440 -0
  165. package/src/tabbar.ts +105 -0
  166. package/src/tabview.ts +106 -0
  167. package/src/textarea.ts +183 -0
  168. package/src/textedit.ts +535 -0
  169. package/src/texthiliter.ts +284 -0
  170. package/src/toaster.ts +76 -0
  171. package/src/tools.ts +1391 -0
  172. package/src/tooltips.ts +185 -0
  173. package/src/treeview.ts +670 -0
  174. package/src/x4.less +1940 -0
  175. package/src/x4_events.ts +558 -0
  176. package/tsconfig.json +14 -0
@@ -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 {};
@@ -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 {};