x4js 1.4.49 → 1.4.52
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.
- package/lib/autocomplete.js +2 -1
- package/lib/base_component.d.ts +1 -0
- package/lib/button.js +1 -1
- package/lib/checkbox.js +1 -1
- package/lib/component.d.ts +4 -10
- package/lib/component.js +9 -15
- package/lib/dom_events.d.ts +2 -0
- package/lib/form.js +1 -1
- package/lib/gridview.js +3 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/input.js +1 -1
- package/lib/label.js +1 -1
- package/lib/layout.js +1 -1
- package/lib/link.js +1 -1
- package/lib/menu.js +1 -1
- package/lib/property_editor.d.ts +1 -1
- package/lib/radiobtn.js +1 -1
- package/lib/smartedit.js +1 -1
- package/lib/svgcomponent.js +1 -2
- package/lib/tabbar.d.ts +1 -1
- package/lib/textarea.js +2 -2
- package/lib/textedit.js +1 -1
- package/lib/x4.css +15 -2
- package/lib/x4react.d.ts +41 -0
- package/lib/x4react.js +75 -0
- package/license.md +21 -0
- package/package.json +1 -1
- package/src/autocomplete.ts +2 -1
- package/src/base_component.ts +3 -1
- package/src/button.ts +1 -1
- package/src/checkbox.ts +2 -2
- package/src/component.ts +2329 -2339
- package/src/dom_events.ts +2 -0
- package/src/form.ts +1 -1
- package/src/gridview.ts +3 -3
- package/src/index.ts +1 -0
- package/src/input.ts +1 -1
- package/src/label.ts +1 -1
- package/src/layout.ts +1 -1
- package/src/link.ts +1 -1
- package/src/menu.ts +24 -24
- package/src/radiobtn.ts +2 -2
- package/src/svgcomponent.ts +1 -2
- package/src/textarea.ts +2 -2
- package/src/textedit.ts +1 -1
- package/src/x4.less +19 -2
- package/src/x4react.ts +90 -0
- package/tsconfig.json +3 -1
package/src/dom_events.ts
CHANGED
|
@@ -137,6 +137,8 @@ export interface IDOMEvents {
|
|
|
137
137
|
* Fires when the object receives focus.
|
|
138
138
|
* @param ev The event.
|
|
139
139
|
*/
|
|
140
|
+
focusin?: (ev: FocusEvent) => any;
|
|
141
|
+
focusout?: (ev: FocusEvent) => any;
|
|
140
142
|
focus?: (ev: FocusEvent) => any;
|
|
141
143
|
gotpointercapture?: (ev: PointerEvent) => any;
|
|
142
144
|
input?: (ev: Event) => any;
|
package/src/form.ts
CHANGED
|
@@ -78,7 +78,7 @@ export class Form<T extends FormProps = FormProps, E extends FormEventMap = Form
|
|
|
78
78
|
|
|
79
79
|
super(props);
|
|
80
80
|
|
|
81
|
-
this.
|
|
81
|
+
this.setTag( props.disableSuggestions ? 'section' : 'form');
|
|
82
82
|
this.mapPropEvents(props, 'btnClick');
|
|
83
83
|
this.updateContent(content, props.buttons, height);
|
|
84
84
|
|
package/src/gridview.ts
CHANGED
|
@@ -1109,12 +1109,12 @@ export class GridView extends VLayout<GridViewProps, GridViewEventMap> {
|
|
|
1109
1109
|
}
|
|
1110
1110
|
|
|
1111
1111
|
private _renderCheck(rec: Record) {
|
|
1112
|
-
let
|
|
1112
|
+
let icon = '--x4-icon-square';
|
|
1113
1113
|
if (this.m_marks.has(rec.getID())) {
|
|
1114
|
-
|
|
1114
|
+
icon = '--x4-icon-square-check';
|
|
1115
1115
|
}
|
|
1116
1116
|
|
|
1117
|
-
return new
|
|
1117
|
+
return new Icon({ icon: `var(${icon})` });
|
|
1118
1118
|
}
|
|
1119
1119
|
|
|
1120
1120
|
private _toggleMark(rec: Record) {
|
package/src/index.ts
CHANGED
package/src/input.ts
CHANGED
package/src/label.ts
CHANGED
package/src/layout.ts
CHANGED
package/src/link.ts
CHANGED
|
@@ -69,8 +69,8 @@ export class Link extends Component<LinkProps, LinkEventMap>
|
|
|
69
69
|
let text = props.text ?? '';
|
|
70
70
|
let href = props.href ?? '#';
|
|
71
71
|
|
|
72
|
+
this.setTag( 'a');
|
|
72
73
|
this.setAttribute('tabindex', 0);
|
|
73
|
-
this.setProp('tag', 'a');
|
|
74
74
|
this.setAttribute('href', href);
|
|
75
75
|
this.setAttribute('target', props.target);
|
|
76
76
|
|
package/src/menu.ts
CHANGED
|
@@ -206,24 +206,24 @@ export class Menu extends Popup<MenuProps>
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
public displayAt(ev: UIEvent
|
|
210
|
-
public displayAt(x: number, y?: number, align?: string, offset?: { x, y }
|
|
211
|
-
public displayAt(
|
|
212
|
-
|
|
209
|
+
public displayAt(ev: UIEvent): void;
|
|
210
|
+
public displayAt(x: number, y?: number, align?: string, offset?: { x, y }): void;
|
|
211
|
+
public displayAt(...args) {
|
|
212
|
+
|
|
213
213
|
if (!this.m_lock) {
|
|
214
214
|
Menu._discardAll();
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
let x, y, align, offset;
|
|
218
218
|
|
|
219
|
-
if(
|
|
220
|
-
({x,y} = getMousePos(
|
|
219
|
+
if (args.length == 1) {
|
|
220
|
+
({ x, y } = getMousePos(args[0], true));
|
|
221
221
|
}
|
|
222
222
|
else {
|
|
223
|
-
[x,y,align,offset] = args;
|
|
223
|
+
[x, y, align, offset] = args;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
if(
|
|
226
|
+
if (!align) {
|
|
227
227
|
align = 'top left';
|
|
228
228
|
}
|
|
229
229
|
|
|
@@ -247,7 +247,7 @@ export interface MenuItemProps extends CProps {
|
|
|
247
247
|
checked?: boolean;
|
|
248
248
|
cls?: string;
|
|
249
249
|
click?: EventCallback<EvClick>; // shortcut to events: { click ... }
|
|
250
|
-
|
|
250
|
+
|
|
251
251
|
action?: Action;
|
|
252
252
|
}
|
|
253
253
|
|
|
@@ -259,20 +259,20 @@ export class MenuItem extends Component<MenuItemProps, MenuItemEventMap> {
|
|
|
259
259
|
private m_isOpen: boolean;
|
|
260
260
|
private m_action: Action;
|
|
261
261
|
|
|
262
|
-
constructor(
|
|
263
|
-
constructor(
|
|
264
|
-
constructor(
|
|
265
|
-
constructor(
|
|
262
|
+
constructor(action: Action);
|
|
263
|
+
constructor(text: string, click: EventCallback<EvClick>);
|
|
264
|
+
constructor(props: MenuItemProps);
|
|
265
|
+
constructor(a, b?) {
|
|
266
266
|
|
|
267
|
-
if(
|
|
268
|
-
super(
|
|
269
|
-
click: (
|
|
267
|
+
if (a instanceof Action) {
|
|
268
|
+
super({
|
|
269
|
+
click: () => { a.fire(); }
|
|
270
270
|
});
|
|
271
271
|
|
|
272
272
|
this.m_action = a;
|
|
273
273
|
}
|
|
274
|
-
else if(
|
|
275
|
-
super(
|
|
274
|
+
else if (isString(a)) {
|
|
275
|
+
super({
|
|
276
276
|
text: a,
|
|
277
277
|
click: b
|
|
278
278
|
});
|
|
@@ -281,7 +281,7 @@ export class MenuItem extends Component<MenuItemProps, MenuItemEventMap> {
|
|
|
281
281
|
super(a);
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
this.mapPropEvents(
|
|
284
|
+
this.mapPropEvents(this.m_props, 'click');
|
|
285
285
|
|
|
286
286
|
this.m_menu = null;
|
|
287
287
|
this.m_isOpen = false;
|
|
@@ -300,12 +300,12 @@ export class MenuItem extends Component<MenuItemProps, MenuItemEventMap> {
|
|
|
300
300
|
icon = props.checked ? 'var( --x4-icon-check )' : 0;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
if(
|
|
304
|
-
if(
|
|
303
|
+
if (this.m_action) {
|
|
304
|
+
if (!icon) {
|
|
305
305
|
icon = this.m_action.props.icon;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
if(
|
|
308
|
+
if (text === undefined) {
|
|
309
309
|
text = this.m_action.props.text;
|
|
310
310
|
}
|
|
311
311
|
}
|
|
@@ -313,7 +313,7 @@ export class MenuItem extends Component<MenuItemProps, MenuItemEventMap> {
|
|
|
313
313
|
let popIco = null;
|
|
314
314
|
if (this.isPopup) {
|
|
315
315
|
this.addClass('@popup-menu-item');
|
|
316
|
-
popIco = new Icon(
|
|
316
|
+
popIco = new Icon({ icon: "var( --x4-icon-chevron-right )", cls: "pop-mark" });
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
if (!text && !icon) {
|
|
@@ -324,7 +324,7 @@ export class MenuItem extends Component<MenuItemProps, MenuItemEventMap> {
|
|
|
324
324
|
this.addClass(props.cls);
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
this.
|
|
327
|
+
this.setTag('a');
|
|
328
328
|
//@bug: do not kill focus on click
|
|
329
329
|
// this.setAttribute( 'tabindex', '0' );
|
|
330
330
|
|
package/src/radiobtn.ts
CHANGED
|
@@ -87,9 +87,9 @@ export class RadioBtn extends Component<RadioBtnProps,RadioBtnEventMap> {
|
|
|
87
87
|
let value = props.value;
|
|
88
88
|
let icon = props.icon;
|
|
89
89
|
|
|
90
|
+
this.setTag( 'label' );
|
|
90
91
|
this.addClass( '@hlayout' );
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
this.addClass( align );
|
|
94
94
|
this._setTabIndex( props.tabIndex );
|
|
95
95
|
|
package/src/svgcomponent.ts
CHANGED
|
@@ -520,8 +520,7 @@ export class SVGComponent<P extends SVGProps = SVGProps> extends Component<P> {
|
|
|
520
520
|
constructor( props: P ) {
|
|
521
521
|
super( props );
|
|
522
522
|
|
|
523
|
-
this.
|
|
524
|
-
this.setProp('ns','http://www.w3.org/2000/svg');
|
|
523
|
+
this.setTag('svg','http://www.w3.org/2000/svg');
|
|
525
524
|
this.setAttribute('xmlns','http://www.w3.org/2000/svg');
|
|
526
525
|
|
|
527
526
|
this.setAttributes( {
|
package/src/textarea.ts
CHANGED
|
@@ -89,7 +89,7 @@ export class TextArea extends Component<TextAreaProps, TextAreaEventMap> {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
if (props.autoGrow) {
|
|
92
|
-
this.
|
|
92
|
+
this.m_props.autoGrow = true;
|
|
93
93
|
this.setAttribute('rows', this._calcHeight(props.text));
|
|
94
94
|
this.setDomEvent('keydown', () => {
|
|
95
95
|
asap( ()=>this._updateHeight());
|
|
@@ -101,8 +101,8 @@ export class TextArea extends Component<TextAreaProps, TextAreaEventMap> {
|
|
|
101
101
|
e.stopPropagation();
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
+
this.setTag( 'textarea');
|
|
104
105
|
this.setDomEvent('input', () => this._change());
|
|
105
|
-
this.setProp('tag', 'textarea');
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
private _change() {
|
package/src/textedit.ts
CHANGED
|
@@ -128,7 +128,7 @@ export class TextEdit<T extends TextEditProps = TextEditProps, E extends TextEdi
|
|
|
128
128
|
flex: 1,
|
|
129
129
|
dom_events: {
|
|
130
130
|
focus: ( ) => this._focus( ),
|
|
131
|
-
|
|
131
|
+
focusout: ( ) => this._blur( ),
|
|
132
132
|
input: ( ) => this._change( )
|
|
133
133
|
},
|
|
134
134
|
value: props.value,
|
package/src/x4.less
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
**/
|
|
31
31
|
|
|
32
32
|
:root {
|
|
33
|
-
--x4-font:
|
|
33
|
+
--x4-font: Helvetica, Arial, Sans-Serif;
|
|
34
34
|
--x4-font-size: 13px;
|
|
35
35
|
|
|
36
36
|
--x4-base-color: #266888;
|
|
@@ -77,12 +77,15 @@
|
|
|
77
77
|
--x4-icon-tip: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor"><path d="M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256s256-114.6 256-256S397.4 0 256 0zM256 464c-114.7 0-208-93.31-208-208S141.3 48 256 48s208 93.31 208 208S370.7 464 256 464zM296 336h-16V248C280 234.8 269.3 224 256 224H224C210.8 224 200 234.8 200 248S210.8 272 224 272h8v64h-16C202.8 336 192 346.8 192 360S202.8 384 216 384h80c13.25 0 24-10.75 24-24S309.3 336 296 336zM256 192c17.67 0 32-14.33 32-32c0-17.67-14.33-32-32-32S224 142.3 224 160C224 177.7 238.3 192 256 192z"/></svg>';
|
|
78
78
|
--x4-icon-check: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" fill="currentColor"><path d="M440.1 103C450.3 112.4 450.3 127.6 440.1 136.1L176.1 400.1C167.6 410.3 152.4 410.3 143 400.1L7.029 264.1C-2.343 255.6-2.343 240.4 7.029 231C16.4 221.7 31.6 221.7 40.97 231L160 350.1L407 103C416.4 93.66 431.6 93.66 440.1 103V103z"/></svg>';
|
|
79
79
|
--x4-icon-folder-closed: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor"><path d="M448 96h-172.1L226.7 50.75C214.7 38.74 198.5 32 181.5 32H64C28.65 32 0 60.66 0 96v320c0 35.34 28.65 64 64 64h384c35.35 0 64-28.66 64-64V160C512 124.7 483.3 96 448 96zM64 80h117.5c4.273 0 8.293 1.664 11.31 4.688L256 144h192c8.822 0 16 7.176 16 16v32h-416V96C48 87.18 55.18 80 64 80zM448 432H64c-8.822 0-16-7.176-16-16V240h416V416C464 424.8 456.8 432 448 432z"/></svg>';
|
|
80
|
-
--x4-icon-folder-opened: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" fill="currentColor"
|
|
80
|
+
--x4-icon-folder-opened: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" fill="currentColor"><path d="M572.6 270.3l-96 192C471.2 473.2 460.1 480 447.1 480H64c-35.35 0-64-28.66-64-64V96c0-35.34 28.65-64 64-64h117.5c16.97 0 33.25 6.742 45.26 18.75L275.9 96H416c35.35 0 64 28.66 64 64v32h-48V160c0-8.824-7.178-16-16-16H256L192.8 84.69C189.8 81.66 185.8 80 181.5 80H64C55.18 80 48 87.18 48 96v288l71.16-142.3C124.6 230.8 135.7 224 147.8 224h396.2C567.7 224 583.2 249 572.6 270.3z"/></svg>';
|
|
81
81
|
|
|
82
82
|
--x4-icon-chevron-down: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" fill="currentColor"><path d="M432.6 209.3l-191.1 183.1C235.1 397.8 229.1 400 224 400s-11.97-2.219-16.59-6.688L15.41 209.3C5.814 200.2 5.502 184.1 14.69 175.4c9.125-9.625 24.38-9.938 33.91-.7187L224 342.8l175.4-168c9.5-9.219 24.78-8.906 33.91 .7187C442.5 184.1 442.2 200.2 432.6 209.3z"/></svg>';
|
|
83
83
|
--x4-icon-chevron-right: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" fill="currentColor"><path d="M96 480c-8.188 0-16.38-3.125-22.62-9.375c-12.5-12.5-12.5-32.75 0-45.25L242.8 256L73.38 86.63c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0l192 192c12.5 12.5 12.5 32.75 0 45.25l-192 192C112.4 476.9 104.2 480 96 480z"/></svg>';
|
|
84
84
|
--x4-icon-chevron-left: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" fill="currentColor"><path d="M206.7 464.6l-183.1-191.1C18.22 267.1 16 261.1 16 256s2.219-11.97 6.688-16.59l183.1-191.1c9.152-9.594 24.34-9.906 33.9-.7187c9.625 9.125 9.938 24.37 .7187 33.91L73.24 256l168 175.4c9.219 9.5 8.906 24.78-.7187 33.91C231 474.5 215.8 474.2 206.7 464.6z"/></svg>';
|
|
85
85
|
--x4-icon-chevron-up: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" fill="currentColor"><path d="M15.41 302.7l191.1-183.1C212 114.2 218 111.1 224 111.1s11.97 2.219 16.59 6.688l191.1 183.1c9.594 9.152 9.906 24.34 .7187 33.9c-9.125 9.625-24.38 9.938-33.91 .7187L224 169.2l-175.4 168c-9.5 9.219-24.78 8.906-33.91-.7187C5.502 327 5.814 311.8 15.41 302.7z"/></svg>';
|
|
86
|
+
|
|
87
|
+
--x4-icon-square-check: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" fill="currentColor"><path d="M211.8 339.8C200.9 350.7 183.1 350.7 172.2 339.8L108.2 275.8C97.27 264.9 97.27 247.1 108.2 236.2C119.1 225.3 136.9 225.3 147.8 236.2L192 280.4L300.2 172.2C311.1 161.3 328.9 161.3 339.8 172.2C350.7 183.1 350.7 200.9 339.8 211.8L211.8 339.8zM0 96C0 60.65 28.65 32 64 32H384C419.3 32 448 60.65 448 96V416C448 451.3 419.3 480 384 480H64C28.65 480 0 451.3 0 416V96zM48 96V416C48 424.8 55.16 432 64 432H384C392.8 432 400 424.8 400 416V96C400 87.16 392.8 80 384 80H64C55.16 80 48 87.16 48 96z"/></svg>';
|
|
88
|
+
--x4-icon-square: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" fill="currentColor"><path d="M384 32C419.3 32 448 60.65 448 96V416C448 451.3 419.3 480 384 480H64C28.65 480 0 451.3 0 416V96C0 60.65 28.65 32 64 32H384zM384 64H64C46.33 64 32 78.33 32 96V416C32 433.7 46.33 448 64 448H384C401.7 448 416 433.7 416 416V96C416 78.33 401.7 64 384 64z"/></svg>';
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
@BLACK10: rgba(0,0,0,0.1);
|
|
@@ -280,6 +283,14 @@ textarea {
|
|
|
280
283
|
flex-basis: 0;
|
|
281
284
|
}
|
|
282
285
|
|
|
286
|
+
.x-hlayout > .x-min-content {
|
|
287
|
+
min-width: min-content;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.x-vlayout > .x-min-content {
|
|
291
|
+
min-height: min-content;
|
|
292
|
+
}
|
|
293
|
+
|
|
283
294
|
.x-fit {
|
|
284
295
|
position: absolute;
|
|
285
296
|
left: 0;
|
|
@@ -414,6 +425,12 @@ textarea {
|
|
|
414
425
|
color: inherit;
|
|
415
426
|
}
|
|
416
427
|
|
|
428
|
+
.x-svg-icon {
|
|
429
|
+
width: 100%;
|
|
430
|
+
height: 100%;
|
|
431
|
+
margin: 0;
|
|
432
|
+
}
|
|
433
|
+
|
|
417
434
|
&:focus {
|
|
418
435
|
border-color: var( --x4-focus-color );
|
|
419
436
|
background-color: var( --x4-focus-color );
|
package/src/x4react.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
|
package/tsconfig.json
CHANGED