x4js 2.0.20 → 2.0.22

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 (173) hide show
  1. package/lib/cjs/x4.css +1 -1
  2. package/lib/cjs/x4.js +2 -2
  3. package/lib/esm/x4.css +1 -1
  4. package/lib/esm/x4.mjs +2 -2
  5. package/lib/styles/x4.css +1 -1
  6. package/lib/types/x4js.d.ts +93 -77
  7. package/package.json +1 -1
  8. package/src/components/boxes/boxes.ts +33 -1
  9. package/src/components/canvas/canvas.ts +9 -3
  10. package/src/components/combobox/combobox.module.scss +13 -0
  11. package/src/components/combobox/combobox.ts +7 -0
  12. package/src/components/form/form.ts +4 -4
  13. package/src/components/gridview/gridview.ts +12 -9
  14. package/src/components/header/header.module.scss +2 -1
  15. package/src/components/header/header.ts +17 -5
  16. package/src/components/icon/icon.module.scss +1 -0
  17. package/src/components/label/label.module.scss +6 -1
  18. package/src/components/listbox/listbox.module.scss +35 -31
  19. package/src/components/listbox/listbox.ts +50 -12
  20. package/src/components/messages/messages.ts +14 -0
  21. package/src/components/notification/notification.ts +1 -1
  22. package/src/components/popup/popup.ts +13 -2
  23. package/src/components/propgrid/propgrid.ts +4 -2
  24. package/src/components/sizers/sizer.ts +4 -4
  25. package/src/components/tabs/tabs.module.scss +2 -2
  26. package/src/components/tabs/tabs.ts +28 -4
  27. package/src/components/textedit/textedit.ts +1 -1
  28. package/src/components/treeview/treeview.module.scss +9 -1
  29. package/src/components/treeview/treeview.ts +52 -13
  30. package/src/core/component.ts +46 -9
  31. package/src/core/core_data.ts +8 -8
  32. package/src/core/core_state.ts +1 -1
  33. package/src/core/core_tools.ts +2 -0
  34. package/lib/src/components/base.scss +0 -25
  35. package/lib/src/components/boxes/boxes.module.scss +0 -54
  36. package/lib/src/components/boxes/boxes.ts +0 -370
  37. package/lib/src/components/breadcrumb/breadcrumb.scss +0 -56
  38. package/lib/src/components/breadcrumb/breadcrumb.ts +0 -93
  39. package/lib/src/components/breadcrumb/chevron-right.svg +0 -1
  40. package/lib/src/components/btngroup/btngroup.module.scss +0 -41
  41. package/lib/src/components/btngroup/btngroup.ts +0 -153
  42. package/lib/src/components/button/button.module.scss +0 -173
  43. package/lib/src/components/button/button.ts +0 -185
  44. package/lib/src/components/calendar/calendar-check-sharp-light.svg +0 -1
  45. package/lib/src/components/calendar/calendar.module.scss +0 -163
  46. package/lib/src/components/calendar/calendar.ts +0 -327
  47. package/lib/src/components/calendar/chevron-left-sharp-light.svg +0 -1
  48. package/lib/src/components/calendar/chevron-right-sharp-light.svg +0 -1
  49. package/lib/src/components/canvas/canvas.module.scss +0 -25
  50. package/lib/src/components/canvas/canvas.ts +0 -189
  51. package/lib/src/components/canvas/canvas_ex.ts +0 -276
  52. package/lib/src/components/checkbox/check.svg +0 -4
  53. package/lib/src/components/checkbox/checkbox.module.scss +0 -142
  54. package/lib/src/components/checkbox/checkbox.ts +0 -140
  55. package/lib/src/components/colorinput/colorinput.module.scss +0 -65
  56. package/lib/src/components/colorinput/colorinput.ts +0 -91
  57. package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +0 -1
  58. package/lib/src/components/colorpicker/colorpicker.module.scss +0 -133
  59. package/lib/src/components/colorpicker/colorpicker.ts +0 -482
  60. package/lib/src/components/combobox/combobox.module.scss +0 -133
  61. package/lib/src/components/combobox/combobox.ts +0 -275
  62. package/lib/src/components/combobox/updown.svg +0 -4
  63. package/lib/src/components/components.ts +0 -42
  64. package/lib/src/components/dialog/dialog.module.scss +0 -104
  65. package/lib/src/components/dialog/dialog.ts +0 -229
  66. package/lib/src/components/dialog/xmark-sharp-light.svg +0 -1
  67. package/lib/src/components/filedrop/cloud-arrow-up.svg +0 -1
  68. package/lib/src/components/filedrop/filedrop.module.scss +0 -70
  69. package/lib/src/components/filedrop/filedrop.ts +0 -131
  70. package/lib/src/components/form/form.module.scss +0 -38
  71. package/lib/src/components/form/form.ts +0 -172
  72. package/lib/src/components/gridview/arrow-down-light.svg +0 -1
  73. package/lib/src/components/gridview/arrow-up-light.svg +0 -1
  74. package/lib/src/components/gridview/gridview.module.scss +0 -324
  75. package/lib/src/components/gridview/gridview.ts +0 -1175
  76. package/lib/src/components/header/header.module.scss +0 -40
  77. package/lib/src/components/header/header.ts +0 -130
  78. package/lib/src/components/icon/icon.module.scss +0 -31
  79. package/lib/src/components/icon/icon.ts +0 -137
  80. package/lib/src/components/image/image.module.scss +0 -28
  81. package/lib/src/components/image/image.ts +0 -168
  82. package/lib/src/components/input/input.module.scss +0 -74
  83. package/lib/src/components/input/input.ts +0 -422
  84. package/lib/src/components/keyboard/arrow-up.svg +0 -1
  85. package/lib/src/components/keyboard/delete-left.svg +0 -1
  86. package/lib/src/components/keyboard/eye-slash.svg +0 -1
  87. package/lib/src/components/keyboard/keyboard.module.scss +0 -134
  88. package/lib/src/components/keyboard/keyboard.ts +0 -526
  89. package/lib/src/components/label/label.module.scss +0 -76
  90. package/lib/src/components/label/label.ts +0 -97
  91. package/lib/src/components/link/link.ts +0 -81
  92. package/lib/src/components/listbox/listbox.module.scss +0 -161
  93. package/lib/src/components/listbox/listbox.ts +0 -539
  94. package/lib/src/components/menu/caret-right-solid.svg +0 -1
  95. package/lib/src/components/menu/menu.module.scss +0 -117
  96. package/lib/src/components/menu/menu.ts +0 -174
  97. package/lib/src/components/messages/circle-exclamation.svg +0 -1
  98. package/lib/src/components/messages/messages.module.scss +0 -92
  99. package/lib/src/components/messages/messages.ts +0 -215
  100. package/lib/src/components/messages/pen-field.svg +0 -1
  101. package/lib/src/components/normalize.scss +0 -391
  102. package/lib/src/components/notification/circle-check-solid.svg +0 -1
  103. package/lib/src/components/notification/circle-exclamation-solid.svg +0 -1
  104. package/lib/src/components/notification/circle-notch-light.svg +0 -1
  105. package/lib/src/components/notification/notification.module.scss +0 -84
  106. package/lib/src/components/notification/notification.ts +0 -107
  107. package/lib/src/components/notification/xmark-sharp-light.svg +0 -1
  108. package/lib/src/components/panel/panel.module.scss +0 -60
  109. package/lib/src/components/panel/panel.ts +0 -58
  110. package/lib/src/components/popup/popup.module.scss +0 -51
  111. package/lib/src/components/popup/popup.ts +0 -442
  112. package/lib/src/components/progress/progress.module.scss +0 -57
  113. package/lib/src/components/progress/progress.ts +0 -44
  114. package/lib/src/components/propgrid/folder-closed.svg +0 -1
  115. package/lib/src/components/propgrid/folder-open.svg +0 -1
  116. package/lib/src/components/propgrid/progrid.module.scss +0 -112
  117. package/lib/src/components/propgrid/propgrid.ts +0 -288
  118. package/lib/src/components/propgrid/updown.svg +0 -4
  119. package/lib/src/components/radio/radio.module.scss +0 -147
  120. package/lib/src/components/radio/radio.svg +0 -4
  121. package/lib/src/components/radio/radio.ts +0 -142
  122. package/lib/src/components/rating/rating.module.scss +0 -23
  123. package/lib/src/components/rating/rating.ts +0 -131
  124. package/lib/src/components/rating/star-sharp-light.svg +0 -1
  125. package/lib/src/components/rating/star-sharp-solid.svg +0 -1
  126. package/lib/src/components/select/select.module.scss +0 -9
  127. package/lib/src/components/select/select.ts +0 -134
  128. package/lib/src/components/shared.scss +0 -137
  129. package/lib/src/components/sizers/sizer.module.scss +0 -90
  130. package/lib/src/components/sizers/sizer.ts +0 -132
  131. package/lib/src/components/slider/slider.module.scss +0 -118
  132. package/lib/src/components/slider/slider.ts +0 -198
  133. package/lib/src/components/switch/switch.module.scss +0 -127
  134. package/lib/src/components/switch/switch.ts +0 -62
  135. package/lib/src/components/tabs/tabs.module.scss +0 -45
  136. package/lib/src/components/tabs/tabs.ts +0 -205
  137. package/lib/src/components/textarea/textarea.module.scss +0 -63
  138. package/lib/src/components/textarea/textarea.ts +0 -125
  139. package/lib/src/components/textedit/textedit.module.scss +0 -116
  140. package/lib/src/components/textedit/textedit.ts +0 -115
  141. package/lib/src/components/themes.scss +0 -88
  142. package/lib/src/components/tickline/tickline.module.scss +0 -26
  143. package/lib/src/components/tickline/tickline.ts +0 -82
  144. package/lib/src/components/tooltips/circle-info-sharp-light.svg +0 -1
  145. package/lib/src/components/tooltips/comments-question.svg +0 -1
  146. package/lib/src/components/tooltips/tooltips.scss +0 -72
  147. package/lib/src/components/tooltips/tooltips.ts +0 -109
  148. package/lib/src/components/treeview/chevron-down-light.svg +0 -1
  149. package/lib/src/components/treeview/treeview.module.scss +0 -185
  150. package/lib/src/components/treeview/treeview.ts +0 -445
  151. package/lib/src/components/viewport/viewport.module.scss +0 -32
  152. package/lib/src/components/viewport/viewport.ts +0 -41
  153. package/lib/src/core/component.ts +0 -1066
  154. package/lib/src/core/core_application.ts +0 -265
  155. package/lib/src/core/core_colors.ts +0 -250
  156. package/lib/src/core/core_data.ts +0 -1310
  157. package/lib/src/core/core_dom.ts +0 -471
  158. package/lib/src/core/core_dragdrop.ts +0 -201
  159. package/lib/src/core/core_element.ts +0 -115
  160. package/lib/src/core/core_events.ts +0 -177
  161. package/lib/src/core/core_i18n.ts +0 -393
  162. package/lib/src/core/core_react.ts +0 -79
  163. package/lib/src/core/core_router.ts +0 -237
  164. package/lib/src/core/core_state.ts +0 -62
  165. package/lib/src/core/core_styles.ts +0 -214
  166. package/lib/src/core/core_svg.ts +0 -712
  167. package/lib/src/core/core_tools.ts +0 -906
  168. package/lib/src/types/scss.d.ts +0 -4
  169. package/lib/src/types/svg.d.ts +0 -1
  170. package/lib/src/types/x4react.d.ts +0 -9
  171. package/lib/src/x4.scss +0 -19
  172. package/lib/src/x4.ts +0 -35
  173. package/lib/src/x4tsx.d.ts +0 -25
@@ -1,1066 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \/ / / _
4
- * \ / /_| |_
5
- * / \____ _|
6
- * /__/\__\ |_|
7
- *
8
- * @file component.ts
9
- * @author Etienne Cochard
10
- *
11
- * @copyright (c) 2024 R-libre ingenierie
12
- *
13
- * Use of this source code is governed by an MIT-style license
14
- * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
- **/
16
-
17
- import { isArray, UnsafeHtml, isNumber, Rect, Constructor, class_ns, x4_class_ns_sym, IRect } from './core_tools';
18
- import { CoreElement } from './core_element';
19
- import { ariaValues, unitless } from './core_styles';
20
- import { CoreEvent, EventMap } from './core_events';
21
- import { addEvent, DOMEventHandler, GlobalDOMEvents } from './core_dom';
22
-
23
- interface RefType<T extends Component> {
24
- dom: T;
25
- }
26
-
27
- type ComponentAttributes = Record<string,string|number|boolean>;
28
- type CreateComponentCallBack = ( attrs: Record<string,string> ) => ComponentContent;
29
-
30
- const FRAGMENT = Symbol( "fragment" );
31
- const COMPONENT = Symbol( "component" );
32
-
33
- const RE_NUMBER = /^-?\d+(\.\d*)?$/;
34
-
35
- /**
36
- * you can change css classname prefix by adding
37
- *
38
- * ```
39
- * static "$cls-ns" = "<your prefix>";
40
- * ```
41
- *
42
- * to your class to avoid autogenerated css class names conflicts
43
- */
44
-
45
- function genClassNames( x: any ): string[] {
46
-
47
- const classes = [];
48
- let self = Object.getPrototypeOf(x);
49
-
50
- if( self.constructor==Component ) {
51
- return ["x4-comp"];
52
- }
53
-
54
- while (self && self.constructor !== Component ) {
55
- const clsname:string = self.constructor.name;
56
- const clsns: string = Object.prototype.hasOwnProperty.call(self.constructor,x4_class_ns_sym) ? self.constructor[x4_class_ns_sym] : "";
57
- classes.push( clsns+clsname.toLowerCase() );
58
- self = Object.getPrototypeOf(self);
59
- }
60
-
61
- return classes;
62
- }
63
-
64
- /**
65
- *
66
- */
67
-
68
- export type ComponentContent = Component | Component[] | string | string[] | UnsafeHtml| UnsafeHtml[] | number | boolean;
69
-
70
- let gen_id = 1000;
71
-
72
- export const makeUniqueComponentId = ( ) => {
73
- return `x4-${gen_id++}`;
74
- }
75
-
76
- /**
77
- *
78
- */
79
-
80
- export interface ComponentProps {
81
- tag?: string;
82
- ns?: string;
83
-
84
- style?: Partial<CSSStyleDeclaration>;
85
- attrs?: Record<string,string|number|boolean>;
86
- content?: ComponentContent;
87
- dom_events?: GlobalDOMEvents;
88
- cls?: string;
89
- id?: string;
90
- ref?: RefType<any>;
91
-
92
- // shortcuts
93
- width?: string | number;
94
- height?: string | number;
95
- disabled?: true,
96
- hidden?: true,
97
- flex?: boolean | number;
98
-
99
- tooltip?: string;
100
-
101
- // wrapper
102
- existingDOM?: HTMLElement;
103
-
104
- // index signature
105
- // to avoid errors: Type 'X' has no properties in common with type 'Y'
106
- // because all memebers here are optional.
107
- // this allow TS to recongnize derived props as ComponentProps
108
- //[key: string]: any;
109
- };
110
-
111
-
112
- /**
113
- *
114
- */
115
-
116
- export interface ComponentEvent extends CoreEvent {
117
- }
118
-
119
- /**
120
- *
121
- */
122
-
123
- export interface ComponentEvents extends EventMap {
124
- }
125
-
126
- /**
127
- *
128
- */
129
-
130
- @class_ns( "x4" )
131
- export class Component<P extends ComponentProps = ComponentProps, E extends ComponentEvents = ComponentEvents>
132
- extends CoreElement<E> {
133
-
134
- readonly dom: Element;
135
- readonly props: P;
136
- protected readonly clsprefix: string; // internal class name prefix (x4 internal)
137
-
138
- #store: Map<string|symbol,any>;
139
-
140
- constructor( props: P ) {
141
- super( );
142
-
143
- this.props = props; // copy ?
144
-
145
- if( props.existingDOM ) {
146
- this.dom = props.existingDOM;
147
- }
148
- else {
149
- if( props.ns ) {
150
- this.dom = document.createElementNS( props.ns, props.tag ?? "div" );
151
- }
152
- else {
153
- this.dom = document.createElement( props.tag ?? "div" );
154
- }
155
-
156
- if (props.attrs) {
157
- this.setAttributes( props.attrs );
158
- }
159
-
160
- if( props.cls ) {
161
- this.addClass( props.cls );
162
- }
163
-
164
- if( props.hidden ) {
165
- this.show( false );
166
- }
167
-
168
- if( props.flex===true ) {
169
- this.addClass( "x4flex" );
170
- }
171
- else if( props.flex!==undefined ) {
172
- this.setStyle( {
173
- "flexGrow": props.flex+""
174
- });
175
- }
176
-
177
- if( props.id!==undefined ) {
178
- this.setAttribute( "id", props.id );
179
- }
180
-
181
- // small shortcut
182
- if( props.width!==undefined ) {
183
- this.setStyleValue( "width", props.width );
184
- }
185
-
186
- if( props.height!==undefined ) {
187
- this.setStyleValue( "height", props.height );
188
- }
189
-
190
- if( props.tooltip ) {
191
- this.setAttribute( "tooltip", props.tooltip );
192
- }
193
-
194
- if( props.style ) {
195
- this.setStyle( props.style );
196
- }
197
-
198
- if( props.content ) {
199
- this.setContent( props.content );
200
- }
201
-
202
- if( props.dom_events ) {
203
- this.setDOMEvents( props.dom_events );
204
- }
205
-
206
- const classes = genClassNames( this );
207
- this.dom.classList.add( ...classes );
208
-
209
- // need to have children for next statements
210
- // and children way be created in caller
211
- if( props.disabled ) {
212
- this.addDOMEvent( "created", ( ) => {
213
- this.enable( false );
214
- } );
215
- }
216
- }
217
-
218
- (this.dom as any)[COMPONENT] = this;
219
- }
220
-
221
-
222
- // :: CLASSES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
223
-
224
- /**
225
- *
226
- */
227
-
228
- hasClass( cls: string ) {
229
- return this.dom.classList.contains( cls );
230
- }
231
-
232
- /**
233
- *
234
- */
235
-
236
- addClass( cls: string ) {
237
- if( !cls ) return;
238
-
239
- if( cls.indexOf(' ')>=0 ) {
240
- cls = cls.trim( );
241
- const ccs = cls.split( " " );
242
- this.dom.classList.add(...ccs);
243
- }
244
- else {
245
- this.dom.classList.add(cls);
246
- }
247
- }
248
-
249
- /**
250
- * special case: '*' mean clear class list
251
- */
252
-
253
- removeClass( cls: string ) {
254
- if( !cls ) return;
255
-
256
- if( cls=='*' ) {
257
- this.dom.classList.value = "";
258
- return;
259
- }
260
-
261
- if( cls.indexOf(' ')>=0 ) {
262
- const ccs = cls.split( " " );
263
- this.dom.classList.remove(...ccs);
264
- }
265
- else {
266
- this.dom.classList.remove(cls);
267
- }
268
- }
269
-
270
- /**
271
- *
272
- */
273
-
274
- removeClassEx( re: RegExp ) {
275
- const all = Array.from( this.dom.classList );
276
- all.forEach( x => {
277
- if( x.match(re) ) {
278
- this.dom.classList.remove( x );
279
- }
280
- });
281
- }
282
-
283
- /**
284
- *
285
- */
286
-
287
- toggleClass( cls: string ) {
288
- if( !cls ) return;
289
-
290
- const toggle = ( x: string ) => {
291
- this.dom.classList.toggle(x);
292
- }
293
-
294
- if( cls.indexOf(' ')>=0 ) {
295
- const ccs = cls.split( " " );
296
- ccs.forEach( toggle );
297
- }
298
- else {
299
- toggle( cls );
300
- }
301
- }
302
-
303
- /**
304
- *
305
- */
306
-
307
- setClass( cls: string, set: boolean = true ) : this {
308
- if( set ) this.addClass(cls);
309
- else this.removeClass( cls );
310
- return this;
311
- }
312
-
313
- // :: ATTRIBUTES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
314
-
315
- /**
316
- * attributes
317
- */
318
-
319
- setAttributes( attrs: ComponentAttributes ): this {
320
- for( const name in attrs ) {
321
- this.setAttribute( name, attrs[name] );
322
- }
323
- return this;
324
- }
325
-
326
- /**
327
- *
328
- */
329
-
330
- setAttribute( name: string, value: string | number | boolean ) {
331
- if( value===null || value===undefined ) {
332
- this.dom.removeAttribute( name );
333
- }
334
- else {
335
- this.dom.setAttribute( name, ""+value );
336
- }
337
- }
338
-
339
- /**
340
- *
341
- */
342
-
343
- getAttribute( name: string ): string {
344
- return this.dom.getAttribute( name );
345
- }
346
-
347
- /**
348
- *
349
- */
350
-
351
- getData( name: string ) : string {
352
- return this.getAttribute( "data-"+name );
353
- }
354
-
355
- /**
356
- * @returns undefined if not a number
357
- */
358
- getIntData( name: string ) : number {
359
- const v = parseInt( this.getAttribute( "data-"+name ) );
360
- if( Number.isFinite(v) ) {
361
- return v;
362
- }
363
-
364
- return undefined;
365
- }
366
-
367
- /**
368
- *
369
- */
370
-
371
- setData( name: string, value: string ) {
372
- return this.setAttribute( "data-"+name, value );
373
- }
374
-
375
- /**
376
- * idem as setData but onot on dom, you can store anything
377
- */
378
-
379
- setInternalData( name: string|symbol, value: any ): this {
380
- if( !this.#store ) {
381
- this.#store = new Map( );
382
- }
383
-
384
- this.#store.set( name, value );
385
- return this;
386
- }
387
-
388
- getInternalData( name: string|symbol ): any {
389
- return this.#store?.get(name);
390
- }
391
-
392
-
393
- // :: DOM EVENTS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
394
-
395
- /**
396
- *
397
- */
398
-
399
- addDOMEvent<K extends keyof GlobalDOMEvents>( name: K, listener: GlobalDOMEvents[K], prepend = false ) {
400
- addEvent( this.dom, name, listener as DOMEventHandler, prepend );
401
- }
402
-
403
- /**
404
- *
405
- */
406
-
407
- setDOMEvents( events: GlobalDOMEvents ) {
408
- for( const name in events ) {
409
- this.addDOMEvent( name as any, (events as any)[name] );
410
- }
411
- }
412
-
413
- // :: HILEVEL EVENTS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
414
-
415
- /**
416
- * tool to move named events to internal event map
417
- * @internal
418
- */
419
-
420
- protected mapPropEvents<N extends keyof E>(props: P, ...elements: N[] ) {
421
- const p = props as any;
422
- elements.forEach( n => {
423
- if (Object.prototype.hasOwnProperty.call(p,n) && p[n]) {
424
- this.on( n, p[n] );
425
- }
426
- });
427
- }
428
-
429
- // :: CONTENT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
430
-
431
- /**
432
- * remove all content from component
433
- */
434
-
435
- clearContent( ) {
436
- const d = this.dom;
437
- while( d.firstChild ) {
438
- d.removeChild( d.firstChild );
439
- }
440
- }
441
-
442
- /**
443
- * change the whole content of the component
444
- * clear the content before
445
- * @param content new content
446
- */
447
-
448
- setContent( content: ComponentContent ) {
449
- this.clearContent( );
450
- this.appendContent( content );
451
- }
452
-
453
- /**
454
- * cf. appendContent
455
- * @param content content to append
456
- */
457
-
458
- appendContent( content: ComponentContent ) {
459
- const set = ( d: any, c: Component | string | UnsafeHtml | number | boolean ) => {
460
-
461
- if (c instanceof Component ) {
462
- d.appendChild( c.dom );
463
- }
464
- else if( c instanceof UnsafeHtml) {
465
- d.insertAdjacentHTML( 'beforeend' , c.toString() );
466
- }
467
- else if (typeof c === "string" || typeof c === "number") {
468
- const tnode = document.createTextNode(c.toString());
469
- d.appendChild( tnode );
470
- }
471
- else if( c ) {
472
- console.warn("Unknown type to append: ", c);
473
- }
474
- }
475
-
476
- if( !isArray(content) ) {
477
- set( this.dom, content );
478
- }
479
- else if( content.length<=8 ) {
480
- for( const c of content ) {
481
- set( this.dom, c );
482
- }
483
- }
484
- else {
485
- const fragment = document.createDocumentFragment( );
486
- for (const child of content ) {
487
- set( fragment, child );
488
- }
489
-
490
- this.dom.appendChild( fragment );
491
- }
492
- }
493
-
494
- /**
495
- * cf. appendContent
496
- * @param content content to append
497
- */
498
-
499
- prependContent( content: ComponentContent ) {
500
- const d = this.dom;
501
- const set = ( c: Component | string | UnsafeHtml | number | boolean ) => {
502
- if (c instanceof Component ) {
503
- d.insertAdjacentElement( 'afterbegin', c.dom );
504
- }
505
- else if( c instanceof UnsafeHtml) {
506
- d.insertAdjacentHTML( 'afterbegin', c.toString() );
507
- }
508
- else if (typeof c === "string" || typeof c === "number") {
509
- d.insertAdjacentText( 'afterbegin', c.toString() );
510
- }
511
- else {
512
- console.warn("Unknown type to append: ", c);
513
- }
514
- }
515
-
516
- if( !isArray(content) ) {
517
- set( content );
518
- }
519
- else {
520
- const fragment = document.createDocumentFragment( );
521
- for (const child of content ) {
522
- set( child );
523
- }
524
-
525
- d.insertBefore( d.firstChild, fragment );
526
- }
527
- }
528
-
529
- /**
530
- * remove a single child
531
- * @see clearContent
532
- */
533
-
534
- removeChild( child: Component ) {
535
- this.dom.removeChild( child.dom );
536
- }
537
-
538
-
539
- /**
540
- * query all elements by selector
541
- */
542
-
543
- queryAll( selector: string ): Component[] {
544
- const all = this.dom.querySelectorAll( selector );
545
- const rc = new Array( all.length );
546
- all.forEach( (x,i) => rc[i]=wrapDOM(x as HTMLElement) );
547
- return rc;
548
- }
549
-
550
- /**
551
- *
552
- */
553
-
554
- query<T extends Component = Component>( selector: string ): T {
555
- const r = this.dom.querySelector( selector );
556
- return componentFromDOM<T>(r);
557
- }
558
-
559
-
560
- // :: STYLES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
561
-
562
-
563
- /**
564
- *
565
- */
566
-
567
- setAria( name: keyof ariaValues, value: string | number | boolean ): this {
568
- this.setAttribute( name, value );
569
- return this;
570
- }
571
-
572
-
573
- /**
574
- *
575
- */
576
-
577
- setStyle( style: Partial<CSSStyleDeclaration> ): this {
578
- const _style = (this.dom as HTMLElement).style;
579
-
580
- for( const name in style ) {
581
-
582
- let value = style[name];
583
- if( !unitless[name] && (isNumber(value) || RE_NUMBER.test(value)) ) {
584
- value += "px";
585
- }
586
-
587
- _style[name] = value;
588
- }
589
-
590
- return this;
591
- }
592
-
593
- /**
594
- *
595
- */
596
-
597
- setStyleValue<K extends keyof CSSStyleDeclaration>( name: K, value: CSSStyleDeclaration[K] | number ): this {
598
-
599
- const _style = (this.dom as HTMLElement).style;
600
-
601
- if( isNumber(value) ) {
602
- let v = value+"";
603
- if( !unitless[name as string] ) {
604
- v += "px";
605
- }
606
-
607
- (_style as any)[name] = v;
608
- }
609
- else {
610
- _style[name] = value;
611
- }
612
-
613
- return this;
614
- }
615
-
616
- /**
617
- *
618
- * @param name
619
- * @returns
620
- */
621
-
622
- getStyleValue<K extends keyof CSSStyleDeclaration>( name: K ) {
623
- const _style = (this.dom as HTMLElement).style;
624
- return _style[name];
625
- }
626
-
627
- setWidth( w: number | string ) {
628
- this.setStyleValue( "width", isNumber(w) ? w+"px" : w );
629
- }
630
-
631
- setHeight( h: number | string ) {
632
- this.setStyleValue( "height", isNumber(h) ? h+"px" : h );
633
- }
634
-
635
- /**
636
- *
637
- */
638
-
639
- setStyleVariable( name: string, value: string ) {
640
- (this.dom as HTMLElement).style.setProperty( name, value );
641
- }
642
-
643
- /**
644
- *
645
- */
646
-
647
- getStyleVariable( name: string ) {
648
- const style = this.getComputedStyle( );
649
- return style.getPropertyValue( name );
650
- }
651
-
652
- /**
653
- *
654
- * @returns
655
- */
656
-
657
- getComputedStyle( ) {
658
- return getComputedStyle( this.dom );
659
- }
660
-
661
- /**
662
- *
663
- */
664
-
665
- setCapture( pointerId: number ) {
666
- this.dom.setPointerCapture( pointerId );
667
- }
668
-
669
- /**
670
- *
671
- */
672
-
673
- releaseCapture( pointerId: number ) {
674
- this.dom.releasePointerCapture( pointerId );
675
- }
676
-
677
- /**
678
- *
679
- */
680
-
681
- getBoundingRect( ): Rect {
682
- const rc = this.dom.getBoundingClientRect( );
683
- return new Rect( rc.x, rc.y, rc.width, rc.height );
684
- }
685
-
686
- // :: MISC ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
687
-
688
- /**
689
- *
690
- */
691
-
692
- focus( ): this {
693
- (this.dom as HTMLElement).focus( );
694
- return this;
695
- }
696
-
697
- hasFocus( ) {
698
- return document.activeElement==this.dom;
699
- }
700
-
701
- /**
702
- *
703
- */
704
-
705
- scrollIntoView(arg?: boolean | ScrollIntoViewOptions) {
706
- this.dom.scrollIntoView(arg);
707
- }
708
-
709
- /**
710
- *
711
- */
712
-
713
- isVisible( ) {
714
- return (this.dom as HTMLElement).offsetParent !== null;
715
- }
716
-
717
- /**
718
- *
719
- */
720
-
721
- show( vis = true ): this {
722
- this.setClass( 'x4hidden', !vis );
723
- return this;
724
- }
725
-
726
- /**
727
- *
728
- */
729
-
730
- hide( ): this {
731
- this.show( false );
732
- return this;
733
- }
734
-
735
- /**
736
- * enable or disable a component (all sub HTMLElement will be also disabled)
737
- */
738
-
739
- enable( ena = true ): this {
740
- this.setAttribute( "disabled", !ena ? 'true' : null );
741
-
742
- if( this.dom instanceof HTMLInputElement || this.dom instanceof HTMLButtonElement ) {
743
- this.dom.disabled = !ena;
744
- }
745
-
746
- // propagate diable state to all input children
747
- const nodes = this.enumChildNodes( true );
748
- nodes.forEach( x => {
749
- if( x instanceof HTMLInputElement || x instanceof HTMLButtonElement ) {
750
- x.disabled = !ena;
751
- }
752
- });
753
-
754
- return this;
755
- }
756
-
757
- /**
758
- *
759
- */
760
-
761
- disable( ): this {
762
- this.enable( false );
763
- return this;
764
- }
765
-
766
- /**
767
- * check if element is marked disabled
768
- */
769
-
770
- isDisabled( ) {
771
- return this.getAttribute('disabled');
772
- }
773
-
774
- /**
775
- *
776
- */
777
-
778
- nextElement<T extends Component = Component>( ): T {
779
- const nxt = this.dom.nextElementSibling;
780
- return componentFromDOM<T>( nxt );
781
- }
782
-
783
- /**
784
- *
785
- * @returns
786
- */
787
-
788
- prevElement<T extends Component = Component>( ): T {
789
- const nxt = this.dom.previousElementSibling;
790
- return componentFromDOM<T>( nxt );
791
- }
792
-
793
- /**
794
- * search for parent that match the given contructor
795
- */
796
-
797
- parentElement<T extends Component>( cls?: Constructor<T> ): T {
798
- return Component.parentElement<T>( this.dom, cls );
799
- }
800
-
801
- /**
802
- * search for parent that match the given contructor
803
- */
804
-
805
- static parentElement<T extends Component>( dom: Node, cls?: Constructor<T> ): T {
806
-
807
- while( dom.parentElement ) {
808
- const cp = componentFromDOM( dom.parentElement );
809
- if( !cls ) {
810
- return cp as T;
811
- }
812
-
813
- if( cp && cp instanceof cls ) {
814
- return cp;
815
- }
816
-
817
- dom = dom.parentElement;
818
- }
819
-
820
- return null;
821
- }
822
-
823
- /**
824
- *
825
- * @returns
826
- */
827
-
828
- firstChild<T extends Component = Component>( ) : T {
829
- const nxt = this.dom.firstElementChild;
830
- return componentFromDOM<T>( nxt );
831
- }
832
-
833
- /**
834
- *
835
- * @returns
836
- */
837
-
838
- lastChild<T extends Component = Component>( ) : T {
839
- const nxt = this.dom.lastElementChild;
840
- return componentFromDOM( nxt );
841
- }
842
-
843
- /**
844
- * renvoie la liste des Composants enfants
845
- */
846
-
847
- enumChildComponents( recursive: boolean ) {
848
-
849
- const children: Component[] = [];
850
-
851
- const nodes = this.enumChildNodes( recursive );
852
- nodes.forEach( ( c: Node ) => {
853
- const cc = componentFromDOM( c as HTMLElement );
854
- if( cc ) {
855
- children.push(cc);
856
- }
857
- } );
858
-
859
- return children;
860
- }
861
-
862
- /**
863
- * return children list of node (not all should be components)
864
- */
865
-
866
- enumChildNodes( recursive: boolean ) {
867
- const children: Node[] = Array.from( recursive ? this.dom.querySelectorAll( '*' ) : this.dom.children );
868
- return children;
869
- }
870
-
871
- /**
872
- *
873
- */
874
-
875
- animate( keyframes: Keyframe[], duration: number ) {
876
- this.dom.animate(keyframes,duration);
877
- }
878
-
879
-
880
- // :: TSX/REACT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
881
-
882
- /**
883
- * called by the compiler when a jsx element is seen
884
- */
885
-
886
- static createElement( clsOrTag: string | ComponentConstructor | symbol | CreateComponentCallBack, attrs: any, ...children: Component[] ): Component | Component[] {
887
-
888
- let comp: Component;
889
-
890
- // fragment
891
- if( clsOrTag==this.createFragment || clsOrTag===FRAGMENT ) {
892
- return children;
893
- }
894
-
895
- // class constructor, yes : dirty
896
- if( clsOrTag instanceof Function ) {
897
- attrs = attrs ?? {};
898
- if( !attrs.children && children && children.length ) {
899
- attrs.content = children;
900
- }
901
-
902
- comp = new (clsOrTag as any)( attrs ?? {} );
903
- }
904
- // basic tag
905
- else {
906
- comp = new Component( {
907
- tag: clsOrTag,
908
- content: children,
909
- ...attrs,
910
- });
911
- }
912
-
913
- if( children && children.length ) {
914
- //comp.setContent( children );
915
- }
916
-
917
- return comp;
918
- }
919
-
920
- /**
921
- *
922
- */
923
-
924
- static createFragment( ): Component[] {
925
- return this.createElement( FRAGMENT, null ) as Component[];
926
- }
927
-
928
- // :: SPECIALS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
929
-
930
- /**
931
- * system interfaces:
932
- * "form-element"
933
- * "tab-handler"
934
- *
935
- * each app can create it's own interface
936
- */
937
-
938
- queryInterface<T>( name: string ): T {
939
- return null;
940
- }
941
- }
942
-
943
-
944
- /**
945
- *
946
- */
947
-
948
- type ComponentConstructor = {
949
- new(...params: any[]): Component;
950
- };
951
-
952
- /**
953
- * get a component element from it's DOM counterpart
954
- */
955
-
956
- export function componentFromDOM<T extends Component = Component>( node: Element ) {
957
- return node ? (node as any)[COMPONENT] as T : null;
958
- }
959
-
960
- /**
961
- * create a component from an existing DOM
962
- */
963
-
964
- export function wrapDOM( el: HTMLElement ): Component {
965
- const com = componentFromDOM(el);
966
- if( com ) {
967
- return com;
968
- }
969
-
970
- return new Component( { existingDOM: el } );
971
- }
972
-
973
-
974
- // :: Special components ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
975
-
976
- // just a flexible element that push other
977
- export class Flex extends Component {
978
- constructor( ) {
979
- super({})
980
- }
981
- }
982
-
983
- // just a spacer element that push other
984
- export class Space extends Component {
985
- constructor( width?: number|string, cls?: string ) {
986
- super( { width, cls } )
987
- }
988
- }
989
-
990
-
991
- // :: HIGH LEVEL BASIC EVENTS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
992
-
993
-
994
-
995
- /**
996
- * Click Event
997
- * click event do not have any additional parameters
998
- */
999
-
1000
- export interface EvClick extends ComponentEvent {
1001
- }
1002
-
1003
- /**
1004
- * Change Event
1005
- * value is the the element value
1006
- */
1007
-
1008
- export interface EvChange extends ComponentEvent {
1009
- readonly value: any;
1010
- }
1011
-
1012
- /**
1013
- * Focus event
1014
- */
1015
-
1016
- export interface EvFocus extends ComponentEvent {
1017
- readonly focus_out: boolean;
1018
- }
1019
-
1020
- /**
1021
- * Selection Event
1022
- * value is the new selection or null
1023
- */
1024
-
1025
- interface ISelection {
1026
- }
1027
-
1028
- export interface EvSelectionChange extends ComponentEvent {
1029
- readonly selection: ISelection;
1030
- readonly empty: boolean;
1031
- }
1032
-
1033
-
1034
- /**
1035
- * ContextMenu Event
1036
- */
1037
-
1038
- export interface EvContextMenu extends ComponentEvent {
1039
- uievent: UIEvent; // UI event that fire this event
1040
- }
1041
-
1042
- /**
1043
- * Drag/Drop event
1044
- */
1045
-
1046
- export interface EvDrag extends ComponentEvent {
1047
- element: unknown;
1048
- data: any;
1049
- }
1050
-
1051
- /**
1052
- * Errors
1053
- */
1054
-
1055
- export interface EvError extends ComponentEvent {
1056
- code: number;
1057
- message: string;
1058
- }
1059
-
1060
- /**
1061
- * DblClick Event
1062
- */
1063
-
1064
- export interface EvDblClick extends ComponentEvent {
1065
- }
1066
-