x4js 1.5.15 → 1.5.17

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 +19 -0
  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 +19 -0
  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 +8 -0
  12. package/lib/types/version.d.ts +1 -1
  13. package/package.json +1 -1
  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 -693
  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
package/lib/src/x4dom.ts DELETED
@@ -1,57 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file x4events.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
- /**
31
- * SSR preparation
32
- */
33
-
34
- interface IX4Document {
35
- createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K];
36
- createElementNS(namespace: string | null, qualifiedName: string, options?: string | ElementCreationOptions): Element;
37
- createTextNode(data: string): Text;
38
-
39
- addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
40
- removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
41
-
42
- querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
43
- querySelector<E extends Element = Element>(selectors: string): E | null;
44
-
45
- get body( ) : HTMLElement;
46
- get activeElement( ): Element;
47
- get location( ): Location;
48
- get styleSheets( ): StyleSheetList;
49
- get head( ): HTMLHeadElement;
50
- get documentElement( ): HTMLElement;
51
-
52
- set title( title: string );
53
- }
54
-
55
-
56
- export let x4document: IX4Document = document;
57
-
@@ -1,585 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file x4events.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
- // default stopPropagation implementation for Events
31
- const stopPropagation = function ( this: any ) {
32
- this.propagationStopped = true;
33
- }
34
-
35
- // default preventDefault implementation for Events
36
- const preventDefault = function ( this: any ) {
37
- this.defaultPrevented = true;
38
- }
39
-
40
- // default callback type for events
41
- export type EventCallback<T extends BasicEvent = BasicEvent> = (event: T) => any;
42
- export interface EventDisposer {
43
- dispose( ) : void;
44
- };
45
-
46
-
47
- /**
48
- * Basic event
49
- * name like that to avoid conflict with Browsers Event class.
50
- */
51
-
52
- export interface BasicEvent {
53
- readonly type?: string; // type of the event 'click', 'change', ...
54
- readonly source?: unknown; // object that fires the event
55
- readonly context?: any; // contextual data, left to the user
56
-
57
- propagationStopped?: boolean; // if true, do not propagate the event
58
- defaultPrevented?: boolean; // if true, do not call default handler (if any)
59
-
60
- stopPropagation?(): void; // stop the propagation
61
- preventDefault?(): void; // prevent the default handler
62
- }
63
-
64
- /**
65
- * BasicEvent Builder
66
- * this function is responsable of BasicEvent creation
67
- * ie. is equivalent of new BasicEvent( xxx );
68
- * @param params
69
- * @returns BasicEvent
70
- */
71
-
72
- export function BasicEvent<T extends BasicEvent = BasicEvent>(params: any): T {
73
- return {
74
- stopPropagation,
75
- preventDefault,
76
- ...params,
77
- } as T;
78
- }
79
-
80
- /**
81
- * Click Event
82
- * click event do not have any additional parameters
83
- */
84
-
85
- export interface EvClick extends BasicEvent {
86
- }
87
-
88
- export function EvClick( context = null ) {
89
- return BasicEvent<EvClick>({ context });
90
- }
91
-
92
-
93
- /**
94
- * Change Event
95
- * value is the the element value
96
- */
97
-
98
- export interface EvChange extends BasicEvent {
99
- readonly value: any;
100
- }
101
-
102
- export function EvChange(value: unknown, context = null ) {
103
- return BasicEvent<EvChange>({ value, context });
104
- }
105
-
106
- /**
107
- * Selection Event
108
- * value is the new selection or null
109
- */
110
-
111
- interface X4Selection {
112
- }
113
-
114
- export interface EvSelectionChange extends BasicEvent {
115
- readonly selection: X4Selection;
116
- }
117
-
118
- export function EvSelectionChange( selection: X4Selection, context = null ) {
119
- return BasicEvent<EvSelectionChange>( { selection, context } );
120
- }
121
-
122
- /**
123
- * ContextMenu Event
124
- */
125
-
126
- export interface EvContextMenu extends BasicEvent {
127
- uievent: UIEvent; // UI event that fire this event
128
- }
129
-
130
- export function EvContextMenu( uievent: UIEvent, context = null ) {
131
- return BasicEvent<EvContextMenu>( { uievent, context } );
132
- }
133
-
134
- /**
135
- * Timer Event
136
- * @see startTimer, stopTimer
137
- */
138
-
139
- export interface EvTimer extends BasicEvent {
140
- timer: string;
141
- time: number;
142
- }
143
-
144
- export function EvTimer( timer: string, time = 0, context = null ) {
145
- return BasicEvent<EvTimer>( { timer, time, context });
146
- }
147
-
148
- /**
149
- * Simple message
150
- */
151
-
152
- export interface EvMessage extends BasicEvent {
153
- readonly msg: string;
154
- readonly params?: any;
155
- }
156
-
157
- export function EvMessage( msg: string, params?: unknown, source?: unknown ) {
158
- return BasicEvent<EvMessage>({msg,params,source});
159
- }
160
-
161
- /**
162
- * Drag/Drop event
163
- */
164
-
165
- export interface EvDrag extends BasicEvent {
166
- element: unknown;
167
- data: any;
168
- }
169
-
170
- export function EvDrag(element: unknown, data: any, ctx: any ) {
171
- return BasicEvent<EvDrag>({ element, data, context: ctx });
172
- }
173
-
174
- /**
175
- * Errors
176
- */
177
-
178
- export interface EvError extends BasicEvent {
179
- code: number;
180
- message: string;
181
- }
182
-
183
- export function EvError( code: number, message: string ) : EvError {
184
- return BasicEvent<EvError>( {code, message} );
185
- }
186
-
187
-
188
- /**
189
- * this Base interface is used to describe available events & their types
190
- *
191
- * you can implement your own event mapping:
192
- * @example
193
- * ```ts
194
- * interface MyEventMap extends EventMap {
195
- * click: EvClick,
196
- * 'custom-message': Event,
197
- * [key: string]: Event,
198
- * }
199
- * ```
200
- */
201
-
202
- export interface EventMap {
203
- }
204
-
205
- /**
206
- * basic event types, in general the type is builded from the eventMap
207
- * this is very usefull for editor completion
208
- * @example
209
- * ```ts
210
- * type MyEventType = MapEvents<MyEventMap>;
211
- * ```
212
- */
213
- export interface EventTypes {
214
- }
215
-
216
- /**
217
- * convert an EventMap to a EventType
218
- */
219
-
220
- export type MapEvents<Type> = {
221
- [Property in keyof Type]?: (ev: Type[Property]) => any;
222
- };
223
-
224
-
225
- /**
226
- * Event emitter class
227
- * this class allow you to emit and handle events
228
- *
229
- * @example:
230
- * ```ts
231
- *
232
- * interface EvDoIt extends BasicEvent {
233
- * param: unknown;
234
- * }
235
- *
236
- * function EvDoIt( e: EvDoIt ) : EvDoIt {
237
- * return BasicEvent<EvDoIt>( e );
238
- * }
239
- *
240
- * interface TestEventMap extends EventMap {
241
- * doit: EvDoIt;
242
- * }
243
- *
244
- * let ee = new EventSource<TestEventMap>(null);
245
- * ee.listen({
246
- * doit: (e) => {
247
- * console.log(e);
248
- * e.preventDefault();
249
- * },
250
- * });
251
- *
252
- * ee.defaults({
253
- * doit: (e) => {
254
- * console.log('default handler for ', e.type, e.selection);
255
- * },
256
- * })
257
- *
258
- * ee.on('doit', (e) => {
259
- * debugger;
260
- * })
261
- *
262
- * const ev = EvDoIt({ param: 10 });
263
- * ee.emit('change', ev);
264
- * if (ev.defaultPrevented) {
265
- * console.log('prevented');
266
- * }
267
- * ```
268
- */
269
-
270
- export class EventSource<Q extends EventMap, T extends EventTypes = MapEvents<Q>> {
271
-
272
- private m_source: unknown;
273
- private m_eventRegistry: Map<string, EventCallback[]>;
274
- private m_defaultHandlers: Map<string, EventCallback[]>;
275
-
276
- constructor(source: unknown = null) {
277
- this.m_source = source ?? this;
278
- }
279
-
280
- /**
281
- * emit an event
282
- * you can stop propagation of event or prevent default
283
- * @param eventName - name of event to emit
284
- * @param event - event data
285
- */
286
-
287
- emit<K extends keyof Q>(type: K, event?: Q[K]) {
288
- this._emit(type as string, event);
289
- }
290
-
291
- _emit(eventName: string, e: BasicEvent): void {
292
- let listeners = this.m_eventRegistry?.get(eventName);
293
- const defaultHandler = this.m_defaultHandlers?.get(eventName);
294
-
295
- if (!e) {
296
- e = {};
297
- }
298
-
299
- if (!e.source) {
300
- (e as any).source = this.m_source;
301
- }
302
-
303
- if (!e.type) {
304
- (e as any).type = eventName;
305
- }
306
-
307
- if (listeners && listeners.length) {
308
-
309
- if (!e.preventDefault) {
310
- e.preventDefault = preventDefault;
311
- }
312
-
313
- if (!e.stopPropagation) {
314
- e.stopPropagation = stopPropagation;
315
- }
316
-
317
- // small optimisation
318
- if (listeners.length == 1) {
319
- listeners[0](e);
320
- }
321
- else {
322
- const temp = listeners.slice();
323
- for (let i = 0, n = temp.length; i < n; i++) {
324
- temp[i](e);
325
- if (e.propagationStopped) {
326
- break;
327
- }
328
- }
329
- }
330
- }
331
-
332
- if (defaultHandler && defaultHandler.length && !e.defaultPrevented) {
333
- return defaultHandler[0](e);
334
- }
335
- }
336
-
337
- /**
338
- * signal en event
339
- * signaled event are notification : no way to prevent default not stop propagation
340
- * @param eventName name of event to signal
341
- * @param event event data
342
- */
343
-
344
- signal<K extends keyof Q>(type: K, event: Q[K], delay=-1) {
345
- this._signal(type as string, event,delay);
346
- }
347
-
348
- _signal(eventName: string, e: BasicEvent,delay=-1): void {
349
-
350
- if (!this.m_eventRegistry) {
351
- return;
352
- }
353
-
354
- const listeners = this.m_eventRegistry.get(eventName);
355
- if (!listeners || !listeners.length ) {
356
- return;
357
- }
358
-
359
- if (!e) {
360
- e = {};
361
- }
362
-
363
- if (!e.type) {
364
- (e as any).type = eventName;
365
- }
366
-
367
- if (!e.source) {
368
- (e as any).source = this.m_source;
369
- }
370
-
371
- e.preventDefault = e.stopPropagation = () => {
372
- console.error('this event cannot be stopped not default prevented');
373
- }
374
-
375
- // small optimisation
376
- if (listeners.length == 1 && delay==-1 ) {
377
- listeners[0](e);
378
- }
379
- else {
380
- const temp = listeners.slice();
381
-
382
- const call = ( ) => {
383
- for (let i = 0, n = temp.length; i < n; i++) {
384
- temp[i](e);
385
- }
386
- }
387
-
388
- if( delay==-1 ) {
389
- call( );
390
- }
391
- else {
392
- setTimeout( call, delay );
393
- }
394
- }
395
- }
396
-
397
- /**
398
- * handle an event one time
399
- * @param eventName - event name to handle
400
- * @param callback - callback to call when event is signaled
401
- * @returns Promise if callback is null
402
- *
403
- * take care with that because if the event is never fired and you await it,
404
- * the system may overflow
405
- */
406
-
407
- once<K extends keyof Q>(type: K, callback: (ev: Q[K]) => any) {
408
- //@ts-ignore
409
- this._once(type as string, callback);
410
- }
411
-
412
- _once(eventName: string, callback: EventCallback) {
413
-
414
- const newCallback = ( ev ) => {
415
- this._off(eventName, newCallback);
416
- callback( ev );
417
- }
418
-
419
- this._on(eventName, newCallback);
420
-
421
- if (!callback) {
422
- return new Promise(function (resolve) {
423
- callback = resolve;
424
- });
425
- }
426
- }
427
-
428
- /**
429
- * set the event default handler
430
- * @param eventName - name of the event
431
- * @param callback - callback to call when the event is not handled (and preventDeault has not been called)
432
- */
433
-
434
- setDefaultHandler(eventName: string, callback: EventCallback): void {
435
-
436
- let handlers = this.m_defaultHandlers;
437
- if (!handlers) {
438
- handlers = this.m_defaultHandlers = new Map()
439
- }
440
-
441
- let stack = handlers.get(eventName);
442
- if (stack) {
443
-
444
- // if already in the stack, remove it
445
- const idx = stack.indexOf(callback);
446
- if (idx != -1) {
447
- stack.splice(idx, 1);
448
- }
449
-
450
- // then make it first
451
- stack.unshift(callback);
452
- }
453
- else {
454
- handlers.set(eventName, [callback]);
455
- }
456
- }
457
-
458
- /**
459
- * remove the previous default handler installed for an event
460
- * @param eventName - event name
461
- * @param callback - callback handler to remove (must be the same as in setDefaultHandler)
462
- */
463
-
464
- removeDefaultHandler(eventName: string, callback: EventCallback): void {
465
- const handlers = this.m_defaultHandlers;
466
- if (!handlers) {
467
- return;
468
- }
469
-
470
- const stack = handlers.get(eventName);
471
- if (stack) {
472
- const idx = stack.indexOf(callback);
473
- if (idx != -1) {
474
- stack.splice(idx, 1);
475
- }
476
- }
477
- }
478
-
479
- /**
480
- * define a set of listeners in one call
481
- * @param events
482
- */
483
-
484
- listen(events: T) {
485
- for (let n in events) {
486
- this._on(n, events[n] as unknown as EventCallback);
487
- }
488
- }
489
-
490
- /**
491
- * define a set of default handlers in one call
492
- * @param events
493
- */
494
-
495
- defaults(events: T) {
496
- for (let n in events) {
497
- this.setDefaultHandler(n, events[n] as unknown as EventCallback);
498
- }
499
- }
500
-
501
- /**
502
- * listen for an event
503
- * @param eventName - event name to listen on
504
- * @param callback - callback to call
505
- * @param capturing - if true, capture event before other registred event handlers
506
- */
507
-
508
- on<K extends keyof Q>(type: K, callback: (ev: Q[K]) => any) : EventDisposer {
509
- //@ts-ignore
510
- return this._on(type as string, callback);
511
- }
512
-
513
- _on(eventName: string, callback: EventCallback, capturing = false): EventDisposer {
514
-
515
- if (!this.m_eventRegistry) {
516
- this.m_eventRegistry = new Map();
517
- }
518
-
519
- let listeners = this.m_eventRegistry.get(eventName);
520
- if (!listeners) {
521
- listeners = [];
522
- this.m_eventRegistry.set(eventName, listeners);
523
- }
524
-
525
- if (listeners.indexOf(callback) == -1) {
526
- if (capturing) {
527
- listeners.unshift(callback);
528
- }
529
- else {
530
- listeners.push(callback);
531
- }
532
- }
533
-
534
- return {
535
- dispose: ( ) => { this._off( eventName, callback ); }
536
- }
537
- }
538
-
539
- /**
540
- * stop listening to an event
541
- * @param eventName - event name
542
- * @param callback - callback to remove (must be the same as in on )
543
- */
544
-
545
- off<K extends keyof Q>(type: K, callback: (ev: Q[K]) => any) {
546
- //@ts-ignore
547
- return this._off(type as string, callback);
548
- }
549
-
550
- _off(eventName: string, callback: EventCallback ): void {
551
- if (!this.m_eventRegistry) {
552
- return;
553
- }
554
-
555
- let listeners = this.m_eventRegistry.get(eventName);
556
- if (!listeners) {
557
- return;
558
- }
559
-
560
- const idx = listeners.indexOf(callback);
561
- if (idx !== -1) {
562
- listeners.splice(idx, 1);
563
- }
564
- }
565
-
566
- /**
567
- * remove all listeners for an event
568
- * @param eventName - event name
569
- */
570
-
571
- removeAllListeners(eventName: string | null): void {
572
- if (!eventName) {
573
- this.m_eventRegistry = this.m_defaultHandlers = undefined;
574
- }
575
- else {
576
- if (this.m_eventRegistry) {
577
- this.m_eventRegistry[eventName] = undefined;
578
- }
579
-
580
- if (this.m_defaultHandlers) {
581
- this.m_defaultHandlers[eventName] = undefined;
582
- }
583
- }
584
- }
585
- }
@@ -1,90 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file x4react.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 { Component, ComponentContent, CProps, CEventMap } from './component';
31
-
32
-
33
- const createElement = ( clsOrTag, attrs, ...children ): ComponentContent => {
34
-
35
- let comp: Component;
36
-
37
- // fragment
38
- if( clsOrTag==createFragment || clsOrTag==Fragment ) {
39
- return children;
40
- }
41
- // class constructor, yes : dirty
42
- else if( clsOrTag instanceof Function ) {
43
- comp = new (clsOrTag as any)( attrs );
44
- }
45
- // basic tag
46
- else {
47
- comp = new Component( {
48
- tag: clsOrTag,
49
- ...attrs,
50
- });
51
- }
52
-
53
- if( children && children.length ) {
54
- comp.setContent( children );
55
- }
56
-
57
- return comp;
58
- }
59
-
60
- const Fragment = Symbol( "fragment" );
61
-
62
- const createFragment = ( ): ComponentContent => {
63
- return null;
64
- }
65
-
66
- export let React = {
67
- createElement,
68
- createFragment,
69
- Fragment,
70
- }
71
-
72
-
73
-
74
-
75
-
76
- /**
77
- *
78
- */
79
-
80
- export abstract class TSXComponent<P extends CProps<CEventMap> = CProps<CEventMap>, E extends CEventMap = CEventMap> extends Component<P,E> {
81
- public render(props: P) {
82
- const tsx = this.renderTSX( props );
83
- if( tsx ) {
84
- this.setContent( tsx );
85
- }
86
- }
87
-
88
- public abstract renderTSX( props: P ): Component | Component[];
89
- }
90
-