tsx:add fragment support
This commit is contained in:
10
doric-js/lib/src/util/jsx.d.ts
vendored
10
doric-js/lib/src/util/jsx.d.ts
vendored
@@ -1,8 +1,10 @@
|
||||
import { View } from "../ui/view";
|
||||
import { Group, View } from "../ui/view";
|
||||
import { ClassType } from "./types";
|
||||
export declare const jsx: {
|
||||
createElement: <T extends View>(constructor: ClassType<T>, config: Partial<T> | null, ...children: View[]) => T;
|
||||
};
|
||||
export declare namespace jsx {
|
||||
function createElement<T extends View>(constructor: ClassType<T>, config: Partial<T> | null, ...children: View[]): T;
|
||||
class Fragment extends Group {
|
||||
}
|
||||
}
|
||||
declare global {
|
||||
namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import { Group } from "../ui/view";
|
||||
import { layoutConfig } from "./layoutconfig";
|
||||
export const jsx = {
|
||||
createElement: function (constructor, config, ...children) {
|
||||
export var jsx;
|
||||
(function (jsx) {
|
||||
function createElement(constructor, config, ...children) {
|
||||
const e = new constructor();
|
||||
e.layoutConfig = layoutConfig().fit();
|
||||
if (config) {
|
||||
@@ -9,12 +10,23 @@ export const jsx = {
|
||||
}
|
||||
if (children && children.length > 0) {
|
||||
if (e instanceof Group) {
|
||||
children.forEach((child) => e.addChild(child));
|
||||
children.forEach((child) => {
|
||||
if (child instanceof Fragment) {
|
||||
child.children.forEach(c => e.addChild(c));
|
||||
}
|
||||
else {
|
||||
e.addChild(child);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
throw new Error(`Can only add child to group view, do not support ${constructor.name}`);
|
||||
}
|
||||
}
|
||||
return e;
|
||||
},
|
||||
};
|
||||
}
|
||||
jsx.createElement = createElement;
|
||||
class Fragment extends Group {
|
||||
}
|
||||
jsx.Fragment = Fragment;
|
||||
})(jsx || (jsx = {}));
|
||||
|
Reference in New Issue
Block a user