x4js 1.4.4 → 1.4.7

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 (85) hide show
  1. package/lib/application.d.ts +96 -0
  2. package/lib/application.js +146 -0
  3. package/lib/base64.d.ts +31 -0
  4. package/lib/base64.js +139 -0
  5. package/lib/base_component.d.ts +64 -0
  6. package/lib/base_component.js +81 -0
  7. package/lib/button.d.ts +145 -0
  8. package/lib/button.js +241 -0
  9. package/lib/calendar.d.ts +77 -0
  10. package/lib/calendar.js +241 -0
  11. package/lib/canvas.d.ts +88 -0
  12. package/lib/canvas.js +358 -0
  13. package/lib/cardview.d.ts +83 -0
  14. package/lib/cardview.js +156 -0
  15. package/lib/checkbox.d.ts +72 -0
  16. package/lib/checkbox.js +130 -0
  17. package/lib/color.d.ts +144 -0
  18. package/lib/color.js +588 -0
  19. package/lib/colorpicker.js +86 -80
  20. package/lib/combobox.js +26 -22
  21. package/lib/component.d.ts +572 -0
  22. package/lib/component.js +1729 -0
  23. package/lib/datastore.js +29 -20
  24. package/lib/dialog.js +41 -36
  25. package/lib/dom_events.d.ts +284 -0
  26. package/lib/dom_events.js +14 -0
  27. package/lib/drag_manager.js +4 -1
  28. package/lib/drawtext.js +9 -5
  29. package/lib/fileupload.js +19 -12
  30. package/lib/form.js +29 -25
  31. package/lib/formatters.js +19 -10
  32. package/lib/gridview.js +40 -35
  33. package/lib/hosts/host.d.ts +44 -0
  34. package/lib/hosts/host.js +73 -0
  35. package/lib/i18n.d.ts +67 -0
  36. package/lib/i18n.js +175 -0
  37. package/lib/icon.d.ts +56 -0
  38. package/lib/icon.js +178 -0
  39. package/lib/image.js +7 -3
  40. package/lib/index.js +71 -55
  41. package/lib/input.d.ts +86 -0
  42. package/lib/input.js +176 -0
  43. package/lib/label.d.ts +54 -0
  44. package/lib/label.js +90 -0
  45. package/lib/layout.d.ts +77 -0
  46. package/lib/layout.js +271 -0
  47. package/lib/link.js +9 -5
  48. package/lib/listview.js +34 -27
  49. package/lib/md5.js +5 -1
  50. package/lib/menu.d.ts +122 -0
  51. package/lib/menu.js +284 -0
  52. package/lib/messagebox.js +22 -17
  53. package/lib/panel.js +13 -9
  54. package/lib/popup.d.ts +71 -0
  55. package/lib/popup.js +378 -0
  56. package/lib/property_editor.js +20 -16
  57. package/lib/radiobtn.js +13 -9
  58. package/lib/rating.js +13 -9
  59. package/lib/request.js +16 -9
  60. package/lib/router.js +5 -1
  61. package/lib/settings.d.ts +33 -0
  62. package/lib/settings.js +67 -0
  63. package/lib/sidebarview.js +12 -8
  64. package/lib/smartedit.js +16 -11
  65. package/lib/spreadsheet.js +35 -31
  66. package/lib/styles.d.ts +81 -0
  67. package/lib/styles.js +268 -0
  68. package/lib/svgcomponent.js +8 -3
  69. package/lib/tabbar.js +10 -6
  70. package/lib/tabview.js +10 -6
  71. package/lib/textarea.js +10 -6
  72. package/lib/textedit.js +39 -35
  73. package/lib/texthiliter.js +8 -4
  74. package/lib/toaster.js +8 -4
  75. package/lib/tools.d.ts +382 -0
  76. package/lib/tools.js +1142 -0
  77. package/lib/tooltips.js +14 -9
  78. package/lib/treeview.js +30 -26
  79. package/lib/x4_events.d.ts +253 -0
  80. package/lib/x4_events.js +375 -0
  81. package/package.json +1 -1
  82. package/src/application.ts +9 -4
  83. package/src/x4.less +143 -107
  84. package/tsconfig.json +1 -1
  85. package/x4.css +1541 -0
@@ -0,0 +1,572 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file components.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
+ * @todo
27
+ * create Container class
28
+ */
29
+ import { Rect, Size, HtmlString, Constructor } from './tools';
30
+ import { Stylesheet, ComputedStyle } from './styles';
31
+ import { BasicEvent, EventCallback } from './x4_events';
32
+ import { BaseComponent, BaseComponentProps, BaseComponentEventMap } from './base_component';
33
+ import { IDOMEvents, X4ElementEventMap } from './dom_events';
34
+ export { HtmlString, isHtmlString, html } from './tools';
35
+ export interface EventHandler<T> {
36
+ (ev: T): any;
37
+ }
38
+ export interface ICaptureInfo {
39
+ initiator: Component;
40
+ handler: EventHandler<UIEvent>;
41
+ iframes: NodeListOf<HTMLIFrameElement>;
42
+ }
43
+ /**
44
+ *
45
+ */
46
+ export declare type VoidCallback = () => void;
47
+ export declare type ComponentOrString = Component | string | HtmlString;
48
+ export declare type ComponentContent = ComponentOrString | ComponentOrString[];
49
+ interface IMap<T> {
50
+ [key: string]: T;
51
+ }
52
+ /**
53
+ * DblClick Event
54
+ * double click event
55
+ */
56
+ export interface EvDblClick extends BasicEvent {
57
+ }
58
+ export declare function EvDblClick(context?: any): EvDblClick;
59
+ /**
60
+ * DblFocus Event
61
+ * double click event
62
+ */
63
+ export interface EvFocus extends BasicEvent {
64
+ readonly focus: boolean;
65
+ }
66
+ export declare function EvFocus(focus?: boolean, context?: any): EvFocus;
67
+ /**
68
+ * basic event map of Component
69
+ */
70
+ export interface CEventMap extends BaseComponentEventMap {
71
+ }
72
+ /**
73
+ * Basic properties of every Component
74
+ */
75
+ export interface CProps<T extends CEventMap = CEventMap> extends BaseComponentProps<T> {
76
+ tag?: string;
77
+ ns?: string;
78
+ cls?: string;
79
+ id?: string;
80
+ style?: IMap<string | number>;
81
+ attrs?: object;
82
+ dom_events?: IDOMEvents;
83
+ data?: any;
84
+ content?: ComponentContent;
85
+ tooltip?: string;
86
+ ref?: string;
87
+ left?: number;
88
+ top?: number;
89
+ width?: number | string;
90
+ height?: number | string;
91
+ tabIndex?: number | boolean;
92
+ flex?: number | string;
93
+ enabled?: boolean;
94
+ }
95
+ /**
96
+ *
97
+ */
98
+ export declare class Component<P extends CProps<BaseComponentEventMap> = CProps<BaseComponentEventMap>, E extends BaseComponentEventMap = BaseComponentEventMap> extends BaseComponent<P, E> {
99
+ private m_dom;
100
+ private m_iprops;
101
+ private static __sb_width;
102
+ private static __comp_guid;
103
+ private static __privateEvents;
104
+ private static __sizeObserver;
105
+ private static __createObserver;
106
+ private static __intersectionObserver;
107
+ private static __capture;
108
+ private static __capture_mask;
109
+ private static __css;
110
+ constructor(props?: P);
111
+ /**
112
+ *
113
+ */
114
+ get uid(): number;
115
+ /**
116
+ * change the component content
117
+ * @param content new content or null
118
+ */
119
+ setContent(content: ComponentContent, refreshAll?: boolean): void;
120
+ /**
121
+ * add a new child to the component content
122
+ * @param content
123
+ */
124
+ appendChild(content: ComponentContent): void;
125
+ /**
126
+ * get the Component value
127
+ * @param name name to get
128
+ */
129
+ getProp(name: string): any;
130
+ /**
131
+ * change a Component value
132
+ * @param name name to set
133
+ * @param value new value
134
+ */
135
+ setProp(name: string, value?: any): void;
136
+ /**
137
+ * get the Component data value
138
+ * @param name name to get
139
+ */
140
+ getData(name: string | Symbol): any;
141
+ /**
142
+ * set the Component data value
143
+ * @param name name to get
144
+ * @param value
145
+ */
146
+ setData(name: string | Symbol, value: any): void;
147
+ /**
148
+ * return the DOM associated with the Component (if any)
149
+ */
150
+ get dom(): HTMLElement;
151
+ /**
152
+ * shows the element
153
+ * @param show
154
+ */
155
+ show(show?: boolean): void;
156
+ /**
157
+ * hides the element
158
+ */
159
+ hide(): void;
160
+ /**
161
+ * enable or disable the element
162
+ * @param enable
163
+ */
164
+ enable(enable?: boolean): void;
165
+ /**
166
+ * disable the element
167
+ */
168
+ disable(): void;
169
+ /**
170
+ * set the focus on the element
171
+ */
172
+ focus(): void;
173
+ /**
174
+ * change the object style
175
+ * @param style - style to add
176
+ * @example ```typescript
177
+ * el.setStyle( {left:100} );
178
+ */
179
+ setStyle(style: object): void;
180
+ /**
181
+ * change a style value
182
+ * @param name string style nale
183
+ * @param value any style value or null to remove style
184
+ */
185
+ setStyleValue(name: string, value: any): void;
186
+ private _setDomStyleValue;
187
+ /**
188
+ * compute the element style
189
+ * @return all styles computed
190
+ */
191
+ getComputedStyle(pseudoElt?: string): ComputedStyle;
192
+ /**
193
+ * return a single stype value
194
+ * @param name - value to get
195
+ */
196
+ getStyleValue(name: string): any;
197
+ /**
198
+ * define the elements attributes
199
+ * @param attrs
200
+ */
201
+ setAttributes(attrs: any): void;
202
+ /**
203
+ * change a single attribute
204
+ * @param name attribute name
205
+ * @param value new value
206
+ */
207
+ setAttribute(name: string, value: any): void;
208
+ private _setDomAttribute;
209
+ /**
210
+ * remove an atrribute
211
+ * @param name name of the attribute
212
+ */
213
+ removeAttribute(name: string): void;
214
+ /**
215
+ * get an attribute value
216
+ * @param {string} name - attribute name
217
+ * @return {string} attribute value
218
+ * @example ```typescript
219
+ * let chk = el.getAttribute( 'checked' );
220
+ * @review double cache
221
+ */
222
+ getAttribute(name: string): string;
223
+ /**
224
+ * check if the element has an attribute
225
+ * @param name attribute name
226
+ * @return true is attribute is present
227
+ * @example ```typescript
228
+ * if( el.hasAttribute('checked') ) {
229
+ * }
230
+ */
231
+ hasAttribute(name: string): boolean;
232
+ /**
233
+ * a some classnames to the component
234
+ * classes can be separated by a space
235
+ * @param cls class to add
236
+ * @example ```typescript
237
+ * addClass( 'my class name @flex' );
238
+ */
239
+ addClass(name: string): void;
240
+ /**
241
+ * Remove a class from the element
242
+ * @param {string|array} name - classes in string form can be space separated
243
+ *
244
+ * @example ```typescript
245
+ * el.removeClass( 'myclass' );
246
+ * el.removeClass( 'myclass1 myclass2' );
247
+ */
248
+ removeClass(name: string): void;
249
+ /**
250
+ *
251
+ * @param cls
252
+ * @param set
253
+ */
254
+ setClass(cls: string, set: boolean): this;
255
+ /**
256
+ * Toggle a class from the element (if present remove, if absent add)
257
+ * @param {string|string[]} name - classes in string form can be space separated
258
+ * @example ```typescript
259
+ * el.toggleClass( 'myclass' );
260
+ * el.toggleClass( 'myclass1 myclass2');
261
+ * el.toggleClass( ['myclass1','myclass2']);
262
+ */
263
+ toggleClass(name: string): void;
264
+ /**
265
+ * check if the object has the class
266
+ * @param cls
267
+ */
268
+ hasClass(cls: string): boolean;
269
+ /**
270
+ * remove all classes from the object
271
+ * this is usefull for component recycling & reusing
272
+ */
273
+ clearClasses(): string;
274
+ /**
275
+ * @deprecated
276
+ */
277
+ private Build;
278
+ _build(): HTMLElement;
279
+ render(props: P): void;
280
+ _createDOM(): HTMLElement;
281
+ protected _setTabIndex(tabIndex: number | boolean, defValue?: number): void;
282
+ private static _observeCreation;
283
+ dispose(): void;
284
+ protected _dispose(with_dom: boolean, timers: boolean): void;
285
+ componentDisposed(): void;
286
+ componentCreated(): void;
287
+ /**
288
+ *
289
+ */
290
+ update(delay?: number): void;
291
+ /**
292
+ * empty the node
293
+ */
294
+ _empty(): void;
295
+ _updateContent(): void;
296
+ /**
297
+ * @return the bounding rectangle
298
+ * @example ```typescript
299
+ * let rc = el.getBoundingRect( );
300
+ * console.log( rc.left, rc.top, rc.right, rc.bottom );
301
+ */
302
+ getBoundingRect(withMargins?: boolean): Rect;
303
+ /**
304
+ * append a new dom event handler
305
+ * @param name - you can specify multiple names separated by a space
306
+ * @param handler
307
+ * @example
308
+ *
309
+ * this.setDomEvent( 'drag drop', this._handleDrag, this );
310
+ * this.setDomEvent( 'dblclick', this._handleDblClick, this );
311
+ */
312
+ setDomEvent<K extends keyof X4ElementEventMap>(type: K, listener: (this: HTMLDivElement, ev: X4ElementEventMap[K]) => void): void;
313
+ private _setDomEvent;
314
+ /**
315
+ *
316
+ */
317
+ clearDomEvent<K extends keyof X4ElementEventMap>(type: K): void;
318
+ mapPropEvents<N extends keyof E>(props: P, ...elements: N[]): void;
319
+ /**
320
+ *
321
+ * @param name
322
+ * @param handler
323
+ */
324
+ createEvent(name: string, handler: Function): void;
325
+ /**
326
+ * dispatch a dom event to the appropriated component
327
+ * called by the system
328
+ */
329
+ private static _dispatchEvent;
330
+ /**
331
+ * dispatch a dom event to the appropriated component
332
+ * called by the system
333
+ */
334
+ private static _dispatchUnbubbleEvent;
335
+ /**
336
+ * called when a size change on an observed component
337
+ */
338
+ private static _observeSize;
339
+ /**
340
+ * enum all children recursively
341
+ * @param recursive - if true do a full sub-child search
342
+ * @param cb - callback
343
+ * return true to stop enumeration
344
+ */
345
+ enumChilds(cb: (child: Component) => boolean | void, recursive?: boolean): boolean;
346
+ /**
347
+ * apprend a child to the DOM
348
+ * @param props child to append (or string)
349
+ */
350
+ private _appendChild;
351
+ /**
352
+ * generate classes from the component inheritance
353
+ * @example
354
+ * Button extends Component will give
355
+ * x-comp x-button
356
+ */
357
+ private _genClassName;
358
+ /**
359
+ * prepend the system class name prefix on a name if needed (if class starts with @)
360
+ */
361
+ private _makeCls;
362
+ /**
363
+ *
364
+ */
365
+ private static dispatchCaptures;
366
+ /**
367
+ * capture mouse events
368
+ * @param capture name of the current capture
369
+ * @param callback funciton to call on captured mouse events
370
+ *
371
+ * @example
372
+ * Component.setCapture( this, ( ev: MouseEvent, initiator: Component ) => {
373
+ * if( ev.type=='mousemove' ) {
374
+ * this.setStyle( {
375
+ * left: ev.clientX,
376
+ * top: ev.clientY
377
+ * } );
378
+ * }
379
+ * else if( ev.type=='mouseup' ) {
380
+ * Component.releaseCapture( );
381
+ * }
382
+ * } );
383
+ */
384
+ protected static setCapture(initiator: Component, listener: EventHandler<UIEvent>): void;
385
+ protected static releaseCapture(): void;
386
+ /**
387
+ * ensure the component is visible
388
+ * @param: alignToTop
389
+ */
390
+ scrollIntoView(arg?: boolean | ScrollIntoViewOptions): void;
391
+ /**
392
+ * search for a given css selector
393
+ * @param selector
394
+ * @returns child or null
395
+ */
396
+ queryItem<T extends Component>(selector: string): T;
397
+ queryAll(selector: string, cb?: (el: Component) => void): NodeListOf<Element>;
398
+ /**
399
+ * find a child with the given ID
400
+ * @param id id (without '#')
401
+ * @returns child or null
402
+ *
403
+ * @example
404
+ * let btn = this.childWithId<Button>( 'myButtonId' );
405
+ */
406
+ itemWithId<T extends Component>(id: string): T;
407
+ /**
408
+ * find a child with given ref
409
+ * @param ref
410
+ * @return found child or null
411
+ */
412
+ itemWithRef<T = Component>(ref: string): T;
413
+ /**
414
+ *
415
+ */
416
+ get ref(): string;
417
+ /**
418
+ *
419
+ */
420
+ static getCss(): Stylesheet;
421
+ /**
422
+ * return the parent element
423
+ * care, object must have been created (dom!=null)
424
+ */
425
+ getParent(): Component;
426
+ /**
427
+ * get a component from a DOM element
428
+ * move up to the hierarchy to find the request class type.
429
+ * @param dom
430
+ * @param classname
431
+ * @returns
432
+ *
433
+ * @example
434
+ *
435
+ * with a DOM like that:
436
+ * Button
437
+ * Label
438
+ * Icon <- the DOM you have (dom-icon)
439
+ *
440
+ * let btn = Component.getElement( dom-icon, Button );
441
+ */
442
+ static getElement<T extends Component>(dom: HTMLElement | Element, classname?: Constructor<T> | string): T;
443
+ /**
444
+ * compute the scrollbar size ( width = height)
445
+ */
446
+ static getScrollbarSize(): any;
447
+ /**
448
+ * check if the Component is visible to the user
449
+ */
450
+ isUserVisible(): boolean;
451
+ }
452
+ /**
453
+ * warp <b>temporarily</b> a DOM element to be able to acces to exact API
454
+ * @param dom dom element to wrap
455
+ * @review qui libere le fly_element ? -> timeout
456
+ */
457
+ export declare function flyWrap<T extends Component>(dom: HTMLElement | EventTarget): T;
458
+ /**
459
+ * simple flex spacer
460
+ */
461
+ export declare class Flex extends Component {
462
+ constructor(props?: CProps);
463
+ }
464
+ /**
465
+ * simple space between 2 elements
466
+ */
467
+ export declare class Space extends Component {
468
+ m_size: number | string;
469
+ constructor(size: number | string);
470
+ componentCreated(): void;
471
+ }
472
+ /**
473
+ * sizable separator
474
+ */
475
+ declare type SizeMode = null | 'minimize' | 'maximize' | 'restore';
476
+ export interface EvSize extends BasicEvent {
477
+ readonly size: Size;
478
+ readonly mode: SizeMode;
479
+ }
480
+ export declare function EvSize(size: Size, mode?: SizeMode, context?: any): EvSize;
481
+ interface SeparatorEventMap extends CEventMap {
482
+ resize?: EvSize;
483
+ }
484
+ interface SeparatorProps extends CProps<SeparatorEventMap> {
485
+ readonly orientation: 'vertical' | 'horizontal';
486
+ readonly sizing: 'before' | 'after';
487
+ readonly collapsible?: boolean;
488
+ }
489
+ export declare class Separator extends Component<SeparatorProps, SeparatorEventMap> {
490
+ m_irect: Rect;
491
+ m_delta: number;
492
+ m_target: Component;
493
+ constructor(props: SeparatorProps);
494
+ render(): void;
495
+ private _collapse;
496
+ private _mousedown;
497
+ _startMoving(x: number, y: number, ev: UIEvent): void;
498
+ private _pointerMoved;
499
+ private _findTarget;
500
+ }
501
+ /**
502
+ * properties
503
+ */
504
+ declare type SizerOverlaySens = 'left' | 'top' | 'right' | 'bottom' | 'topleft' | 'topright' | 'bottomleft' | 'bottomright';
505
+ export interface EvOverlayResize extends BasicEvent {
506
+ ui_event: UIEvent;
507
+ sens: SizerOverlaySens;
508
+ }
509
+ export declare function EvOverlayResize(ui_event: UIEvent, sens: SizerOverlaySens, context?: any): EvOverlayResize;
510
+ interface SizerOverlayEventMap extends CEventMap {
511
+ resize: EvSize;
512
+ rawresize: EvOverlayResize;
513
+ }
514
+ export interface SizerOverlayProps extends CProps<SizerOverlayEventMap> {
515
+ sens: SizerOverlaySens;
516
+ target: Component;
517
+ resize?: EventCallback<EvSize>;
518
+ }
519
+ export declare class SizerOverlay extends Component<SizerOverlayProps, SizerOverlayEventMap> {
520
+ private m_delta;
521
+ private m_irect;
522
+ constructor(props: SizerOverlayProps);
523
+ resetflex(event: UIEvent): void;
524
+ _mousedown(ev: UIEvent): void;
525
+ private _is_horz;
526
+ get sens(): SizerOverlaySens;
527
+ private _handle_mouse;
528
+ }
529
+ /**
530
+ * sequence: Shift+Ctrl+Alt+A
531
+ */
532
+ export interface Shortcut {
533
+ sequence: string;
534
+ name: string;
535
+ immediate: boolean;
536
+ callback?: (domTarget: any) => void;
537
+ }
538
+ interface EvShortcut extends BasicEvent {
539
+ name: string;
540
+ }
541
+ declare function EvShortcut(name: string): EvShortcut;
542
+ export interface ContainerEventMap extends CEventMap {
543
+ shortcut: EvShortcut;
544
+ }
545
+ export interface ContainerProps<E extends ContainerEventMap = ContainerEventMap> extends CProps<E> {
546
+ }
547
+ /**
548
+ * you can construct a Container as usual with it's properties but also directly with it's children array
549
+ *
550
+ * @example
551
+ * new Container( [
552
+ * child1,
553
+ * child2
554
+ * ])
555
+ */
556
+ export declare class Container<P extends ContainerProps = ContainerProps, E extends ContainerEventMap = ContainerEventMap> extends Component<P, E> {
557
+ private m_shortcuts;
558
+ constructor(props: P | ComponentOrString[]);
559
+ /**
560
+ * add an application shortcut
561
+ * @param sequence key sequence Shift+Ctrl+Alt+K
562
+ * @param callback callback to call
563
+ */
564
+ addShortcut(sequence: string | string[], name: string, callback?: EventHandler<KeyboardEvent>, immediate?: boolean): void;
565
+ /**
566
+ * remove all shortcuts for a target
567
+ */
568
+ removeShortcuts(): void;
569
+ /** @ignore this function is binded */
570
+ private _handleKeydown;
571
+ }
572
+ export declare type ComponentConstructor<T> = new (props: CProps) => T;