This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.

53 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-09-03 13:42:25 +08:00
import { Group } from "../ui/view";
2021-09-02 11:39:51 +08:00
import { layoutConfig } from "./layoutconfig";
2021-09-02 12:03:19 +08:00
export var jsx;
(function (jsx) {
function createElement(constructor, config, ...children) {
2022-07-04 14:13:41 +08:00
if (!!constructor.isViewClass) {
const e = new constructor();
if (e instanceof Fragment) {
return children;
}
e.layoutConfig = layoutConfig().fit();
if (config) {
e.apply(config);
2021-09-03 13:42:25 +08:00
}
2022-07-04 14:13:41 +08:00
if (children && children.length > 0) {
if (children.length === 1) {
children = children[0];
}
if (Reflect.has(e, "innerElement")) {
Reflect.set(e, "innerElement", children, e);
}
else {
throw new Error(`Do not support ${constructor.name} for ${children}`);
}
}
return e;
}
else {
const f = constructor;
const e = Reflect.apply(f, undefined, [config]);
if (e instanceof Fragment) {
return children;
2021-09-01 10:47:40 +08:00
}
2022-07-04 14:13:41 +08:00
if (children && children.length > 0) {
if (children.length === 1) {
children = children[0];
}
if (Reflect.has(e, "innerElement")) {
Reflect.set(e, "innerElement", children, e);
}
else {
throw new Error(`Do not support add child for ${e.viewType()}`);
}
2021-09-01 10:47:40 +08:00
}
2022-07-04 14:13:41 +08:00
return e;
2021-09-01 10:47:40 +08:00
}
2021-09-02 12:03:19 +08:00
}
jsx.createElement = createElement;
class Fragment extends Group {
}
jsx.Fragment = Fragment;
})(jsx || (jsx = {}));