x4js 1.5.16 → 1.5.18

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 (75) hide show
  1. package/lib/cjs/app_sockets.js +74 -0
  2. package/lib/cjs/index.js +1 -0
  3. package/lib/cjs/treeview.js +27 -12
  4. package/lib/cjs/version.js +1 -1
  5. package/lib/esm/app_sockets.js +70 -0
  6. package/lib/esm/index.mjs +1 -0
  7. package/lib/esm/treeview.js +26 -12
  8. package/lib/esm/version.js +1 -1
  9. package/lib/{src/version.ts → types/app_sockets.d.ts} +29 -30
  10. package/lib/types/index.d.ts +1 -0
  11. package/lib/types/treeview.d.ts +5 -2
  12. package/lib/types/version.d.ts +1 -1
  13. package/package.json +1 -4
  14. package/lib/src/MIT-license.md +0 -14
  15. package/lib/src/action.ts +0 -88
  16. package/lib/src/alpha.jpg +0 -0
  17. package/lib/src/application.ts +0 -251
  18. package/lib/src/autocomplete.ts +0 -197
  19. package/lib/src/base64.ts +0 -166
  20. package/lib/src/base_component.ts +0 -152
  21. package/lib/src/button.ts +0 -355
  22. package/lib/src/calendar.ts +0 -328
  23. package/lib/src/canvas.ts +0 -505
  24. package/lib/src/cardview.ts +0 -227
  25. package/lib/src/checkbox.ts +0 -188
  26. package/lib/src/color.ts +0 -752
  27. package/lib/src/colorpicker.ts +0 -1639
  28. package/lib/src/combobox.ts +0 -465
  29. package/lib/src/component.ts +0 -2329
  30. package/lib/src/datastore.ts +0 -1322
  31. package/lib/src/dialog.ts +0 -656
  32. package/lib/src/dom_events.ts +0 -315
  33. package/lib/src/drag_manager.ts +0 -199
  34. package/lib/src/drawtext.ts +0 -355
  35. package/lib/src/fileupload.ts +0 -213
  36. package/lib/src/form.ts +0 -375
  37. package/lib/src/formatters.ts +0 -105
  38. package/lib/src/gridview.ts +0 -1185
  39. package/lib/src/i18n.ts +0 -346
  40. package/lib/src/icon.ts +0 -335
  41. package/lib/src/image.ts +0 -204
  42. package/lib/src/index.ts +0 -88
  43. package/lib/src/input.ts +0 -249
  44. package/lib/src/label.ts +0 -128
  45. package/lib/src/layout.ts +0 -430
  46. package/lib/src/link.ts +0 -86
  47. package/lib/src/listview.ts +0 -765
  48. package/lib/src/md5.ts +0 -438
  49. package/lib/src/menu.ts +0 -425
  50. package/lib/src/messagebox.ts +0 -224
  51. package/lib/src/panel.ts +0 -86
  52. package/lib/src/popup.ts +0 -494
  53. package/lib/src/property_editor.ts +0 -337
  54. package/lib/src/radiobtn.ts +0 -197
  55. package/lib/src/rating.ts +0 -135
  56. package/lib/src/request.ts +0 -300
  57. package/lib/src/router.ts +0 -185
  58. package/lib/src/settings.ts +0 -77
  59. package/lib/src/sidebarview.ts +0 -103
  60. package/lib/src/spreadsheet.ts +0 -1449
  61. package/lib/src/styles.ts +0 -343
  62. package/lib/src/svgcomponent.ts +0 -577
  63. package/lib/src/tabbar.ts +0 -151
  64. package/lib/src/tabview.ts +0 -110
  65. package/lib/src/textarea.ts +0 -235
  66. package/lib/src/textedit.ts +0 -544
  67. package/lib/src/toaster.ts +0 -80
  68. package/lib/src/tools.ts +0 -1473
  69. package/lib/src/tooltips.ts +0 -191
  70. package/lib/src/treeview.ts +0 -696
  71. package/lib/src/x4.less +0 -2243
  72. package/lib/src/x4dom.ts +0 -57
  73. package/lib/src/x4events.ts +0 -585
  74. package/lib/src/x4react.ts +0 -90
  75. package/lib/x4.css +0 -1780
@@ -1,544 +0,0 @@
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
- }
@@ -1,80 +0,0 @@
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
- }