x4js 1.5.17 → 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.
Files changed (242) hide show
  1. package/lib/{README.md → README.txt} +0 -0
  2. package/lib/cjs/index.js +39 -103
  3. package/lib/cjs/index.js.map +7 -0
  4. package/lib/esm/index.mjs +39 -87
  5. package/lib/esm/index.mjs.map +7 -0
  6. package/lib/{license.md → licence.md} +0 -0
  7. package/lib/src/MIT-license.md +14 -0
  8. package/lib/{types/action.d.ts → src/action.ts} +64 -33
  9. package/lib/src/alpha.jpg +0 -0
  10. package/lib/src/app_sockets.ts +81 -0
  11. package/lib/src/application.ts +251 -0
  12. package/lib/src/autocomplete.ts +197 -0
  13. package/lib/src/base64.ts +166 -0
  14. package/lib/src/base_component.ts +152 -0
  15. package/lib/src/button.ts +355 -0
  16. package/lib/src/calendar.ts +328 -0
  17. package/lib/src/canvas.ts +505 -0
  18. package/lib/src/cardview.ts +227 -0
  19. package/lib/src/checkbox.ts +188 -0
  20. package/lib/src/color.ts +752 -0
  21. package/lib/src/colorpicker.ts +1639 -0
  22. package/lib/src/combobox.ts +465 -0
  23. package/lib/src/component.ts +2329 -0
  24. package/lib/{esm/dom_events.js → src/copyright.txt} +27 -29
  25. package/lib/src/datastore.ts +1322 -0
  26. package/lib/src/dialog.ts +656 -0
  27. package/lib/src/dom_events.ts +315 -0
  28. package/lib/src/drag_manager.ts +199 -0
  29. package/lib/src/drawtext.ts +355 -0
  30. package/lib/src/fileupload.ts +213 -0
  31. package/lib/src/form.ts +375 -0
  32. package/lib/src/formatters.ts +105 -0
  33. package/lib/src/gridview.ts +1185 -0
  34. package/lib/src/i18n.ts +346 -0
  35. package/lib/src/icon.ts +335 -0
  36. package/lib/src/image.ts +204 -0
  37. package/lib/src/index.ts +89 -0
  38. package/lib/src/input.ts +249 -0
  39. package/lib/src/label.ts +128 -0
  40. package/lib/src/layout.ts +430 -0
  41. package/lib/src/link.ts +86 -0
  42. package/lib/src/listview.ts +765 -0
  43. package/lib/{esm/md5.js → src/md5.ts} +438 -403
  44. package/lib/src/menu.ts +425 -0
  45. package/lib/src/messagebox.ts +224 -0
  46. package/lib/src/panel.ts +86 -0
  47. package/lib/src/popup.ts +494 -0
  48. package/lib/src/property_editor.ts +337 -0
  49. package/lib/src/radiobtn.ts +197 -0
  50. package/lib/src/rating.ts +135 -0
  51. package/lib/src/request.ts +300 -0
  52. package/lib/src/router.ts +185 -0
  53. package/lib/src/settings.ts +77 -0
  54. package/lib/src/sidebarview.ts +103 -0
  55. package/lib/src/spreadsheet.ts +1449 -0
  56. package/lib/src/styles.ts +343 -0
  57. package/lib/src/svgcomponent.ts +577 -0
  58. package/lib/src/tabbar.ts +151 -0
  59. package/lib/src/tabview.ts +110 -0
  60. package/lib/src/textarea.ts +235 -0
  61. package/lib/src/textedit.ts +544 -0
  62. package/lib/src/toaster.ts +80 -0
  63. package/lib/src/tools.ts +1473 -0
  64. package/lib/src/tooltips.ts +191 -0
  65. package/lib/src/treeview.ts +716 -0
  66. package/lib/{esm/version.js → src/version.ts} +30 -29
  67. package/lib/{styles → src}/x4.less +0 -0
  68. package/lib/src/x4dom.ts +57 -0
  69. package/lib/src/x4events.ts +585 -0
  70. package/lib/src/x4react.ts +90 -0
  71. package/package.json +52 -49
  72. package/lib/cjs/action.js +0 -58
  73. package/lib/cjs/app_sockets.js +0 -74
  74. package/lib/cjs/application.js +0 -182
  75. package/lib/cjs/autocomplete.js +0 -155
  76. package/lib/cjs/base_component.js +0 -124
  77. package/lib/cjs/button.js +0 -263
  78. package/lib/cjs/calendar.js +0 -254
  79. package/lib/cjs/canvas.js +0 -361
  80. package/lib/cjs/cardview.js +0 -161
  81. package/lib/cjs/checkbox.js +0 -139
  82. package/lib/cjs/color.js +0 -591
  83. package/lib/cjs/colorpicker.js +0 -1468
  84. package/lib/cjs/combobox.js +0 -349
  85. package/lib/cjs/component.js +0 -1719
  86. package/lib/cjs/datastore.js +0 -985
  87. package/lib/cjs/dialog.js +0 -478
  88. package/lib/cjs/dom_events.js +0 -30
  89. package/lib/cjs/drag_manager.js +0 -145
  90. package/lib/cjs/drawtext.js +0 -276
  91. package/lib/cjs/fileupload.js +0 -167
  92. package/lib/cjs/form.js +0 -304
  93. package/lib/cjs/formatters.js +0 -90
  94. package/lib/cjs/gridview.js +0 -881
  95. package/lib/cjs/i18n.js +0 -266
  96. package/lib/cjs/icon.js +0 -272
  97. package/lib/cjs/image.js +0 -157
  98. package/lib/cjs/input.js +0 -174
  99. package/lib/cjs/label.js +0 -95
  100. package/lib/cjs/layout.js +0 -322
  101. package/lib/cjs/link.js +0 -64
  102. package/lib/cjs/listview.js +0 -546
  103. package/lib/cjs/md5.js +0 -403
  104. package/lib/cjs/menu.js +0 -301
  105. package/lib/cjs/messagebox.js +0 -177
  106. package/lib/cjs/panel.js +0 -68
  107. package/lib/cjs/popup.js +0 -383
  108. package/lib/cjs/property_editor.js +0 -252
  109. package/lib/cjs/radiobtn.js +0 -140
  110. package/lib/cjs/rating.js +0 -102
  111. package/lib/cjs/request.js +0 -246
  112. package/lib/cjs/router.js +0 -139
  113. package/lib/cjs/settings.js +0 -69
  114. package/lib/cjs/sidebarview.js +0 -82
  115. package/lib/cjs/spreadsheet.js +0 -1084
  116. package/lib/cjs/styles.js +0 -275
  117. package/lib/cjs/svgcomponent.js +0 -447
  118. package/lib/cjs/tabbar.js +0 -111
  119. package/lib/cjs/tabview.js +0 -85
  120. package/lib/cjs/textarea.js +0 -165
  121. package/lib/cjs/textedit.js +0 -415
  122. package/lib/cjs/toaster.js +0 -64
  123. package/lib/cjs/tools.js +0 -1197
  124. package/lib/cjs/tooltips.js +0 -157
  125. package/lib/cjs/treeview.js +0 -535
  126. package/lib/cjs/version.js +0 -32
  127. package/lib/cjs/x4dom.js +0 -32
  128. package/lib/cjs/x4events.js +0 -384
  129. package/lib/cjs/x4react.js +0 -72
  130. package/lib/esm/action.js +0 -53
  131. package/lib/esm/app_sockets.js +0 -70
  132. package/lib/esm/application.js +0 -184
  133. package/lib/esm/autocomplete.js +0 -155
  134. package/lib/esm/base_component.js +0 -107
  135. package/lib/esm/button.js +0 -257
  136. package/lib/esm/calendar.js +0 -249
  137. package/lib/esm/canvas.js +0 -358
  138. package/lib/esm/cardview.js +0 -159
  139. package/lib/esm/checkbox.js +0 -134
  140. package/lib/esm/color.js +0 -588
  141. package/lib/esm/colorpicker.js +0 -1475
  142. package/lib/esm/combobox.js +0 -351
  143. package/lib/esm/component.js +0 -1711
  144. package/lib/esm/datastore.js +0 -990
  145. package/lib/esm/dialog.js +0 -490
  146. package/lib/esm/drag_manager.js +0 -147
  147. package/lib/esm/drawtext.js +0 -271
  148. package/lib/esm/fileupload.js +0 -163
  149. package/lib/esm/form.js +0 -304
  150. package/lib/esm/formatters.js +0 -81
  151. package/lib/esm/gridview.js +0 -889
  152. package/lib/esm/i18n.js +0 -257
  153. package/lib/esm/icon.js +0 -261
  154. package/lib/esm/image.js +0 -154
  155. package/lib/esm/input.js +0 -182
  156. package/lib/esm/label.js +0 -90
  157. package/lib/esm/layout.js +0 -310
  158. package/lib/esm/link.js +0 -59
  159. package/lib/esm/listview.js +0 -534
  160. package/lib/esm/menu.js +0 -300
  161. package/lib/esm/messagebox.js +0 -161
  162. package/lib/esm/panel.js +0 -65
  163. package/lib/esm/popup.js +0 -379
  164. package/lib/esm/property_editor.js +0 -251
  165. package/lib/esm/radiobtn.js +0 -136
  166. package/lib/esm/rating.js +0 -97
  167. package/lib/esm/request.js +0 -224
  168. package/lib/esm/router.js +0 -136
  169. package/lib/esm/settings.js +0 -66
  170. package/lib/esm/sidebarview.js +0 -79
  171. package/lib/esm/spreadsheet.js +0 -1097
  172. package/lib/esm/styles.js +0 -270
  173. package/lib/esm/svgcomponent.js +0 -450
  174. package/lib/esm/tabbar.js +0 -107
  175. package/lib/esm/tabview.js +0 -83
  176. package/lib/esm/textarea.js +0 -160
  177. package/lib/esm/textedit.js +0 -412
  178. package/lib/esm/toaster.js +0 -62
  179. package/lib/esm/tools.js +0 -1158
  180. package/lib/esm/tooltips.js +0 -153
  181. package/lib/esm/treeview.js +0 -527
  182. package/lib/esm/x4dom.js +0 -29
  183. package/lib/esm/x4events.js +0 -376
  184. package/lib/esm/x4react.js +0 -71
  185. package/lib/types/app_sockets.d.ts +0 -29
  186. package/lib/types/application.d.ts +0 -104
  187. package/lib/types/autocomplete.d.ts +0 -58
  188. package/lib/types/base_component.d.ts +0 -88
  189. package/lib/types/button.d.ts +0 -151
  190. package/lib/types/calendar.d.ts +0 -82
  191. package/lib/types/canvas.d.ts +0 -92
  192. package/lib/types/cardview.d.ts +0 -87
  193. package/lib/types/checkbox.d.ts +0 -77
  194. package/lib/types/color.d.ts +0 -148
  195. package/lib/types/colorpicker.d.ts +0 -107
  196. package/lib/types/combobox.d.ts +0 -107
  197. package/lib/types/component.d.ts +0 -601
  198. package/lib/types/datastore.d.ts +0 -396
  199. package/lib/types/dialog.d.ts +0 -175
  200. package/lib/types/dom_events.d.ts +0 -302
  201. package/lib/types/drag_manager.d.ts +0 -54
  202. package/lib/types/drawtext.d.ts +0 -48
  203. package/lib/types/fileupload.d.ts +0 -64
  204. package/lib/types/form.d.ts +0 -133
  205. package/lib/types/formatters.d.ts +0 -35
  206. package/lib/types/gridview.d.ts +0 -175
  207. package/lib/types/i18n.d.ts +0 -73
  208. package/lib/types/icon.d.ts +0 -64
  209. package/lib/types/image.d.ts +0 -55
  210. package/lib/types/index.d.ts +0 -84
  211. package/lib/types/input.d.ts +0 -91
  212. package/lib/types/label.d.ts +0 -58
  213. package/lib/types/layout.d.ts +0 -87
  214. package/lib/types/link.d.ts +0 -50
  215. package/lib/types/listview.d.ts +0 -178
  216. package/lib/types/md5.d.ts +0 -61
  217. package/lib/types/menu.d.ts +0 -130
  218. package/lib/types/messagebox.d.ts +0 -69
  219. package/lib/types/panel.d.ts +0 -47
  220. package/lib/types/popup.d.ts +0 -75
  221. package/lib/types/property_editor.d.ts +0 -71
  222. package/lib/types/radiobtn.d.ts +0 -73
  223. package/lib/types/rating.d.ts +0 -53
  224. package/lib/types/request.d.ts +0 -52
  225. package/lib/types/router.d.ts +0 -42
  226. package/lib/types/settings.d.ts +0 -37
  227. package/lib/types/sidebarview.d.ts +0 -49
  228. package/lib/types/spreadsheet.d.ts +0 -222
  229. package/lib/types/styles.d.ts +0 -85
  230. package/lib/types/svgcomponent.d.ts +0 -215
  231. package/lib/types/tabbar.d.ts +0 -58
  232. package/lib/types/tabview.d.ts +0 -49
  233. package/lib/types/textarea.d.ts +0 -77
  234. package/lib/types/textedit.d.ts +0 -123
  235. package/lib/types/toaster.d.ts +0 -42
  236. package/lib/types/tools.d.ts +0 -394
  237. package/lib/types/tooltips.d.ts +0 -46
  238. package/lib/types/treeview.d.ts +0 -144
  239. package/lib/types/version.d.ts +0 -29
  240. package/lib/types/x4dom.d.ts +0 -49
  241. package/lib/types/x4events.d.ts +0 -269
  242. package/lib/types/x4react.d.ts +0 -41
@@ -0,0 +1,544 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file textedit.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
+ import { x4document } from './x4dom'
31
+
32
+ import { Component, EvFocus, HtmlString } from './component'
33
+ import { Input, InputProps, InputEventMap, EditType } from './input'
34
+ import { IconID } from './icon'
35
+ import { Button } from './button'
36
+ import { HLayout } from './layout'
37
+ import { Label } from './label'
38
+ import { PopupCalendar } from './calendar'
39
+ import { sprintf, parseIntlDate, formatIntlDate } from './tools';
40
+ import { Tooltip } from './tooltips'
41
+ import { EvClick, EvChange, EventCallback } from './x4events';
42
+
43
+ import { _tr } from './i18n'
44
+
45
+ // throw in case of error
46
+ // return the corrected
47
+ type ValidationFunction = (value: string) => string;
48
+
49
+ /** @ignore */
50
+ 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,}))$/;
51
+
52
+ // ============================================================================
53
+ // [TEXTEDIT]
54
+ // ============================================================================
55
+
56
+ interface TextEditEventMap extends InputEventMap {
57
+ click: EvClick;
58
+ change: EvChange;
59
+ focus: EvFocus;
60
+ }
61
+
62
+ export interface TextEditProps extends InputProps<TextEditEventMap> {
63
+ label?: string | HtmlString;
64
+ labelWidth?: number; // <0 for flex -> -3 mean flex: 3
65
+ labelAlign?: 'left' | 'right' | 'top';
66
+ required?: boolean;
67
+ spellcheck?: boolean;
68
+ icon?: IconID;
69
+ pattern?: string;
70
+ uppercase?: boolean;
71
+ format?: string | 'native'; // default store format on type date.
72
+ autosel?: boolean; // select content on focus
73
+
74
+ // by default mysql format without time 'YYYY-MM-DD'
75
+ // use 'native' to work on real Date object (get/set value)
76
+
77
+ gadgets?: Component[];
78
+
79
+ validator?: ValidationFunction;
80
+
81
+ change?: EventCallback<EvChange>; // shortcut to events: { change: ... }
82
+ click?: EventCallback<EvClick>; // shortcut to events: { click: ... }
83
+ focus?: EventCallback<EvFocus>; // shortcut to events: { focus: ... }
84
+ }
85
+
86
+
87
+
88
+ /**
89
+ * TextEdit is a single line editor, it can have a label and an error descriptor.
90
+ */
91
+
92
+ export class TextEdit<T extends TextEditProps = TextEditProps, E extends TextEditEventMap = TextEditEventMap > extends Component<T, E> {
93
+
94
+ private m_cal_popup: PopupCalendar;
95
+ protected m_ui_input: Input;
96
+ private m_error_tip: Tooltip;
97
+
98
+ constructor(props: T) {
99
+ super(props);
100
+ this.addClass( '@hlayout' );
101
+ this.mapPropEvents( props, 'change', 'click', 'focus' );
102
+ }
103
+
104
+ componentCreated() {
105
+ super.componentCreated( );
106
+
107
+ if (this.m_props.autoFocus) {
108
+ this.focus();
109
+ }
110
+ }
111
+
112
+ componentDisposed() {
113
+ if (this.m_error_tip) {
114
+ this.m_error_tip.dispose();
115
+ }
116
+
117
+ super.componentDisposed();
118
+ }
119
+
120
+ focus() {
121
+ this.m_ui_input.focus();
122
+ }
123
+
124
+ /** @ignore */
125
+ render(props: TextEditProps) {
126
+
127
+ let eprops: InputProps = {
128
+ flex: 1,
129
+ dom_events: {
130
+ focus: ( ) => this._focus( ),
131
+ focusout: ( ) => this._blur( ),
132
+ input: ( ) => this._change( )
133
+ },
134
+ value: props.value,
135
+ name: props.name,
136
+ type: props.type,
137
+ placeHolder: props.placeHolder,
138
+ autoFocus: props.autoFocus,
139
+ readOnly: props.readOnly,
140
+ value_hook: props.value_hook,
141
+ uppercase: props.uppercase,
142
+ spellcheck: props.spellcheck,
143
+ tabIndex: props.tabIndex === undefined ? true : props.tabIndex,
144
+ attrs: props.attrs,
145
+ min: props.min,
146
+ max: props.max,
147
+ autosel: props.autosel,
148
+ };
149
+
150
+ // date is handled manually with popupcalendar
151
+
152
+ if (props.type == 'date') {
153
+ props.format = props.format ?? 'Y-M-D';
154
+ eprops.type = 'text';
155
+
156
+ let def_hook = {
157
+ get: ( ) => this._date_get_hook(),
158
+ set: (e) => this._date_set_hook(e)
159
+ }
160
+
161
+ eprops.value_hook = props.value_hook ?? def_hook;
162
+ }
163
+
164
+ this.m_ui_input = new Input(eprops);
165
+
166
+ // button
167
+ let button = undefined;
168
+ if (props.icon) {
169
+ button = new Button({
170
+ icon: props.icon,
171
+ click: () => this._btnClick(),
172
+ tabIndex: false
173
+ });
174
+ }
175
+ else if (props.type == 'date') {
176
+
177
+ button = new Button({
178
+ cls: 'gadget',
179
+ icon: 'var( --x4-icon-calendar-days )',
180
+ tabIndex: false,
181
+ click: () => this._showDatePicker(button)
182
+ });
183
+
184
+ if (!props.validator) {
185
+ props.validator = this._date_validator;
186
+ }
187
+ }
188
+
189
+ let ag = props.gadgets ?? [];
190
+ ag.forEach( b => {
191
+ b.addClass( 'gadget' );
192
+ });
193
+
194
+ let gadgets = [button, ...ag];
195
+
196
+ this.setClass('@required', props.required);
197
+ if (props.gadgets && props.gadgets.length) {
198
+ this.addClass('with-gadgets');
199
+ }
200
+
201
+ let width = undefined,
202
+ flex = undefined,
203
+ labelWidth = props.labelWidth;
204
+
205
+ if (labelWidth > 0) {
206
+ width = labelWidth;
207
+ }
208
+
209
+ if (labelWidth < 0) {
210
+ flex = -labelWidth;
211
+ }
212
+
213
+ let label = undefined;
214
+ let labelAlign = props.labelAlign;
215
+ let top = false;
216
+
217
+ if (props.label) {
218
+
219
+ if (labelAlign == 'top') {
220
+ labelAlign = 'left';
221
+ top = true;
222
+ flex = 1;
223
+ }
224
+
225
+ label = new Label({
226
+ ref: 'label',
227
+ tag: 'label',
228
+ cls: 'label1' + (props.label ? '' : ' @hidden'), // todo: why 'label1' class name ?
229
+ text: props.label ?? '',
230
+ width,
231
+ flex,
232
+ align: labelAlign
233
+ });
234
+ }
235
+
236
+ if (top) {
237
+ this.removeClass('@hlayout');
238
+ this.addClass('@vlayout vertical');
239
+
240
+ this.setContent([
241
+ label,
242
+ new HLayout({ width, content: [this.m_ui_input, ...gadgets] })
243
+ ]);
244
+ }
245
+ else {
246
+ this.addClass('@hlayout');
247
+ this.setContent([label, this.m_ui_input, ...gadgets]);
248
+ }
249
+ }
250
+
251
+ enable(ena?: boolean) {
252
+ if (ena === true) {
253
+ this.m_ui_input.enable();
254
+ }
255
+
256
+ super.enable(ena);
257
+ }
258
+
259
+ disable() {
260
+ this.m_ui_input.disable();
261
+ super.disable();
262
+ }
263
+
264
+ private _btnClick() {
265
+ this.emit('click', EvClick(this.value) );
266
+ }
267
+
268
+ /**
269
+ * select the value format for input/output on textedit of type date
270
+ * cf. formatIntlDate / parseIntlDate
271
+ * @param fmt
272
+ */
273
+ public setDateStoreFormat(fmt: string) {
274
+ this.m_props.format = fmt;
275
+ }
276
+
277
+ public setStoreValue(value: any) {
278
+ this.m_ui_input.setStoreValue(value);
279
+ }
280
+
281
+ public getStoreValue(): any {
282
+ return this.m_ui_input.getStoreValue();
283
+ }
284
+
285
+ private _date_get_hook() {
286
+ let date = parseIntlDate(this.value);
287
+ let props = this.m_props;
288
+ if (props.format == 'native') {
289
+ return date;
290
+ }
291
+ else {
292
+ return date ? formatIntlDate(date, props.format) : null;
293
+ }
294
+ }
295
+
296
+ private _date_set_hook(dte) {
297
+ let props = this.m_props;
298
+
299
+ if (props.format == 'native') {
300
+ this.value = formatIntlDate(dte);
301
+ }
302
+ else if (dte) {
303
+ let date = parseIntlDate(dte, props.format);
304
+ this.value = formatIntlDate(date);
305
+ }
306
+ else {
307
+ this.value = '';
308
+ }
309
+ }
310
+
311
+ public showError(text: string) {
312
+
313
+ if (!this.m_error_tip) {
314
+ this.m_error_tip = new Tooltip({ cls: 'error' });
315
+ x4document.body.appendChild(this.m_error_tip._build());
316
+ }
317
+
318
+ let rc = this.m_ui_input.getBoundingRect();
319
+
320
+ this.m_error_tip.text = text;
321
+ this.m_error_tip.displayAt(rc.right, rc.top, 'top left');
322
+ this.addClass('@error');
323
+ }
324
+
325
+ public clearError() {
326
+
327
+ if (this.m_error_tip) {
328
+ this.m_error_tip.hide();
329
+ this.removeClass('@error');
330
+ }
331
+ }
332
+
333
+ public get value(): string {
334
+ if (this.m_ui_input) {
335
+ return this.m_ui_input.value;
336
+ }
337
+ else {
338
+ return this.m_props.value;
339
+ }
340
+ }
341
+
342
+ public set value(value: string) {
343
+ if (this.m_ui_input) {
344
+ this.m_ui_input.value = value;
345
+ }
346
+ else {
347
+ this.m_props.value = value;
348
+ }
349
+ }
350
+
351
+ /**
352
+ * select all the text
353
+ */
354
+
355
+ public selectAll() {
356
+ this.m_ui_input.selectAll();
357
+ }
358
+
359
+ public select(start: number, length: number = 9999): void {
360
+ this.m_ui_input.select(start, length);
361
+ }
362
+
363
+ public getSelection() {
364
+ return this.m_ui_input.getSelection();
365
+ }
366
+
367
+ set readOnly(ro: boolean) {
368
+ this.m_ui_input.readOnly = ro;
369
+ }
370
+
371
+ get label() {
372
+ return this.itemWithRef<Label>('label')?.text;
373
+ }
374
+
375
+ set label(text) {
376
+ this.itemWithRef<Label>('label').text = text;
377
+ }
378
+
379
+ /**
380
+ * content changed
381
+ * todo: should move into Input
382
+ */
383
+
384
+ private _change() {
385
+ let value = this.m_ui_input.value;
386
+ this.emit('change', EvChange(value));
387
+ }
388
+
389
+ /**
390
+ * getting focus
391
+ */
392
+
393
+ private _focus() {
394
+ this.clearError();
395
+ this.emit('focus', EvFocus(true));
396
+ }
397
+
398
+ /**
399
+ * loosing focus
400
+ * @param value
401
+ */
402
+
403
+ private _blur() {
404
+ this._validate(this.m_ui_input.value);
405
+ this.emit('focus', EvFocus(false));
406
+ }
407
+
408
+ /**
409
+ * todo: should move into Input
410
+ * @returns
411
+ */
412
+ public validate(): boolean {
413
+ return this._validate(this.value);
414
+ }
415
+
416
+ protected _validate(value: string): boolean {
417
+ let props = this.m_props;
418
+ let update = false;
419
+
420
+ if (props.required && value.length == 0) {
421
+ this.showError(_tr.global.required_field);
422
+ return false;
423
+ }
424
+
425
+ if (value != '') {
426
+ let pattern = this.getAttribute('pattern');
427
+ if (pattern) {
428
+ let re = new RegExp(pattern);
429
+ if (re && !re.test(value)) {
430
+ this.showError(_tr.global.invalid_format);
431
+ return false;
432
+ }
433
+ }
434
+
435
+ if (props.type == 'email') {
436
+ if (!reEmail.test(value.toLowerCase())) {
437
+ this.showError(_tr.global.invalid_email);
438
+ return false;
439
+ }
440
+ }
441
+ else if (props.type == 'number') {
442
+
443
+ const v = parseFloat(value);
444
+ if (isNaN(v)) {
445
+ this.showError(_tr.global.invalid_number);
446
+ return false;
447
+ }
448
+
449
+ let min = parseFloat(this.m_ui_input.getAttribute('min'));
450
+ if (min !== undefined && v < min) {
451
+ value = '' + min;
452
+ update = true;
453
+ }
454
+
455
+ let max = parseFloat(this.m_ui_input.getAttribute('max'));
456
+ if (max !== undefined && v > max) {
457
+ value = '' + max;
458
+ update = true;
459
+ }
460
+ }
461
+ }
462
+
463
+
464
+ if (props.validator) {
465
+ try {
466
+ this.value = props.validator(value);
467
+ }
468
+ catch (err) {
469
+ this.showError(err instanceof Error ? err.message : err as string);
470
+ return false;
471
+ }
472
+ }
473
+ else if (update) {
474
+ this.value = value;
475
+ }
476
+
477
+ return true;
478
+ }
479
+
480
+ _date_validator(value: string): string {
481
+
482
+ value = value.trim();
483
+ if (value == '') {
484
+ return '';
485
+ }
486
+
487
+ let date: Date;
488
+ if (value == '@') {
489
+ date = new Date();
490
+ }
491
+ else {
492
+ date = parseIntlDate(value);
493
+ if (!date) {
494
+ throw sprintf(_tr.global.invalid_date, _tr.global.date_format);
495
+ }
496
+ }
497
+
498
+ return formatIntlDate(date);
499
+ }
500
+
501
+
502
+ //onKeyDown( e ) {
503
+ // if( this.readOnly ) {
504
+ // if( this.type=='date' && (e.key==' ' || e.key=='Enter') ) {
505
+ // this.showDatePicker( );
506
+ // e.stopPropagation( );
507
+ // e.preventDefault( );
508
+ // }
509
+ // }
510
+ //}
511
+
512
+ //onClick( e ) {
513
+ // if( this.readOnly ) {
514
+ // if( this.type=='date' ) {
515
+ // this.showDatePicker( );
516
+ // e.stopPropagation( );
517
+ // e.preventDefault( );
518
+ // }
519
+ // }
520
+ //}
521
+
522
+ private _showDatePicker(btn: Component) {
523
+
524
+ if (!this.m_cal_popup) {
525
+ this.m_cal_popup = new PopupCalendar({
526
+ change: (ev: EvChange) => {
527
+ this.value = formatIntlDate(ev.value as Date);
528
+ this.m_cal_popup.close();
529
+ }
530
+ });
531
+ }
532
+
533
+ let rc = this.m_ui_input.getBoundingRect();
534
+ this.m_cal_popup.displayAt(rc.left, rc.bottom, 'top left');
535
+ }
536
+
537
+ get input() {
538
+ return this.m_ui_input;
539
+ }
540
+
541
+ get type(): EditType {
542
+ return this.m_props.type;
543
+ }
544
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file toaster.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
+ import { IconID } from './icon';
31
+ import { Label } from "./label";
32
+ import { Popup, PopupProps} from './popup';
33
+
34
+
35
+ export interface ToasterProps extends PopupProps {
36
+ message: string;
37
+ icon?: IconID;
38
+ }
39
+
40
+ export class Toaster extends Popup<ToasterProps> {
41
+
42
+ private m_message: string;
43
+ private m_icon: IconID;
44
+
45
+ constructor( props: ToasterProps ) {
46
+ super( props );
47
+
48
+ this.m_message = props.message;
49
+ this.m_icon = props.icon;
50
+ this.enableMask( false );
51
+ this.addClass( '@non-maskable' );
52
+ }
53
+
54
+ /** @ignore */
55
+ render( ) {
56
+ this.addClass( '@hlayout' );
57
+ this.setContent( [
58
+ new Label( { icon: this.m_icon, text: this.m_message } )
59
+ ]);
60
+ }
61
+
62
+ show( ) {
63
+ this.show = super.show;
64
+ this.displayAt( 9999, 9999, 'br', {x:0,y:-24} );
65
+
66
+ let opacity = 1.0;
67
+
68
+ this.startTimer( 'fadeout', 2000, false, ( ) => {
69
+
70
+ this.startTimer( 'opacity', 100, true, ( ) => {
71
+ this.setStyleValue( 'opacity', opacity );
72
+ opacity -= 0.1;
73
+
74
+ if( opacity<0 ) {
75
+ this.dispose( );
76
+ }
77
+ });
78
+ } );
79
+ }
80
+ }