feat:complete the implement of JSX

This commit is contained in:
pengfei.zhou
2021-09-03 13:42:25 +08:00
committed by osborn
parent 266d20782a
commit bec0d44af0
23 changed files with 322 additions and 150 deletions

View File

@@ -700,6 +700,25 @@ var Group = /** @class */ (function (_super) {
this.children.push(view);
this.dirtyProps.children = this.children.map(function (e) { return e.viewId; });
};
Group.prototype.addInnerElement = function (e) {
var _this = this;
if (e instanceof Array) {
e.forEach(function (e) { return _this.addInnerElement(e); });
}
else if (e instanceof View) {
this.addChild(e);
}
else {
loge("Not allowed to add " + typeof e);
}
};
Object.defineProperty(Group.prototype, "innerElement", {
set: function (e) {
this.addInnerElement(e);
},
enumerable: false,
configurable: true
});
return Group;
}(Superview));
@@ -1887,6 +1906,13 @@ var Text = /** @class */ (function (_super) {
function Text() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(Text.prototype, "innerElement", {
set: function (e) {
this.text = e;
},
enumerable: false,
configurable: true
});
__decorate$a([
Property,
__metadata$a("design:type", String)
@@ -2500,6 +2526,13 @@ var Scroller = /** @class */ (function (_super) {
Scroller.prototype.scrollBy = function (context, offset, animated) {
return this.nativeChannel(context, "scrollBy")({ offset: offset, animated: animated });
};
Object.defineProperty(Scroller.prototype, "innerElement", {
set: function (e) {
this.content = e;
},
enumerable: false,
configurable: true
});
__decorate$6([
Property,
__metadata$6("design:type", Object)
@@ -2576,6 +2609,19 @@ var Refreshable = /** @class */ (function (_super) {
this.dirtyProps.header = (this.header || {}).viewId;
return _super.prototype.toModel.call(this);
};
Object.defineProperty(Refreshable.prototype, "innerElement", {
set: function (e) {
if (e instanceof View) {
this.content = e;
}
else {
this.header = e[0];
this.content = e[1];
}
},
enumerable: false,
configurable: true
});
__decorate$5([
Property,
__metadata$5("design:type", Function)
@@ -2699,20 +2745,6 @@ var __extends$7 = (undefined && undefined.__extends) || (function () {
})();
exports.jsx = void 0;
(function (jsx) {
function addElement(group, v) {
if (v instanceof Array) {
v.forEach(function (e) { return addElement(group, e); });
}
else if (v instanceof Fragment) {
v.children.forEach(function (e) { return addElement(group, e); });
}
else if (v instanceof View) {
group.addChild(v);
}
else {
throw new Error("Can only use view as child");
}
}
function createElement(constructor, config) {
var arguments$1 = arguments;
@@ -2721,18 +2753,22 @@ exports.jsx = void 0;
children[_i - 2] = arguments$1[_i];
}
var e = new constructor();
if (e instanceof Fragment) {
return children;
}
e.layoutConfig = layoutConfig().fit();
if (config) {
e.apply(config);
}
if (children && children.length > 0) {
if (e instanceof Group) {
children.forEach(function (child) {
addElement(e, child);
});
if (children.length === 1) {
children = children[0];
}
if (Reflect.has(e, "innerElement")) {
Reflect.set(e, "innerElement", children, e);
}
else {
throw new Error("Can only add child to group view, do not support " + constructor.name);
throw new Error("Do not support " + constructor.name + " for " + children);
}
}
return e;

View File

@@ -561,6 +561,20 @@ class Group extends Superview {
removeAllChildren() {
this.children.length = 0;
}
addInnerElement(e) {
if (e instanceof Array) {
e.forEach(e => this.addInnerElement(e));
}
else if (e instanceof View) {
this.addChild(e);
}
else {
loge(`Not allowed to add ${typeof e}`);
}
}
set innerElement(e) {
this.addInnerElement(e);
}
}
const SPECIFIED = 1;
@@ -1399,6 +1413,9 @@ exports.TruncateAt = void 0;
TruncateAt[TruncateAt["Clip"] = 3] = "Clip";
})(exports.TruncateAt || (exports.TruncateAt = {}));
class Text extends View {
set innerElement(e) {
this.text = e;
}
}
__decorate$a([
Property,
@@ -1900,6 +1917,9 @@ class Scroller extends Superview {
scrollBy(context, offset, animated) {
return this.nativeChannel(context, "scrollBy")({ offset, animated });
}
set innerElement(e) {
this.content = e;
}
}
__decorate$6([
Property,
@@ -1956,6 +1976,15 @@ class Refreshable extends Superview {
this.dirtyProps.header = (this.header || {}).viewId;
return super.toModel();
}
set innerElement(e) {
if (e instanceof View) {
this.content = e;
}
else {
this.header = e[0];
this.content = e[1];
}
}
}
__decorate$5([
Property,
@@ -2062,34 +2091,24 @@ exports.Display = void 0;
exports.jsx = void 0;
(function (jsx) {
function addElement(group, v) {
if (v instanceof Array) {
v.forEach(e => addElement(group, e));
}
else if (v instanceof Fragment) {
v.children.forEach(e => addElement(group, e));
}
else if (v instanceof View) {
group.addChild(v);
}
else {
throw new Error(`Can only use view as child`);
}
}
function createElement(constructor, config, ...children) {
const e = new constructor();
if (e instanceof Fragment) {
return children;
}
e.layoutConfig = layoutConfig().fit();
if (config) {
e.apply(config);
}
if (children && children.length > 0) {
if (e instanceof Group) {
children.forEach((child) => {
addElement(e, child);
});
if (children.length === 1) {
children = children[0];
}
if (Reflect.has(e, "innerElement")) {
Reflect.set(e, "innerElement", children, e);
}
else {
throw new Error(`Can only add child to group view, do not support ${constructor.name}`);
throw new Error(`Do not support ${constructor.name} for ${children}`);
}
}
return e;

View File

@@ -2085,6 +2085,20 @@ class Group extends Superview {
removeAllChildren() {
this.children.length = 0;
}
addInnerElement(e) {
if (e instanceof Array) {
e.forEach(e => this.addInnerElement(e));
}
else if (e instanceof View) {
this.addChild(e);
}
else {
loge(`Not allowed to add ${typeof e}`);
}
}
set innerElement(e) {
this.addInnerElement(e);
}
}
const SPECIFIED = 1;
@@ -2923,6 +2937,9 @@ exports.TruncateAt = void 0;
TruncateAt[TruncateAt["Clip"] = 3] = "Clip";
})(exports.TruncateAt || (exports.TruncateAt = {}));
class Text extends View {
set innerElement(e) {
this.text = e;
}
}
__decorate$a([
Property,
@@ -3424,6 +3441,9 @@ class Scroller extends Superview {
scrollBy(context, offset, animated) {
return this.nativeChannel(context, "scrollBy")({ offset, animated });
}
set innerElement(e) {
this.content = e;
}
}
__decorate$6([
Property,
@@ -3480,6 +3500,15 @@ class Refreshable extends Superview {
this.dirtyProps.header = (this.header || {}).viewId;
return super.toModel();
}
set innerElement(e) {
if (e instanceof View) {
this.content = e;
}
else {
this.header = e[0];
this.content = e[1];
}
}
}
__decorate$5([
Property,
@@ -3586,34 +3615,24 @@ exports.Display = void 0;
exports.jsx = void 0;
(function (jsx) {
function addElement(group, v) {
if (v instanceof Array) {
v.forEach(e => addElement(group, e));
}
else if (v instanceof Fragment) {
v.children.forEach(e => addElement(group, e));
}
else if (v instanceof View) {
group.addChild(v);
}
else {
throw new Error(`Can only use view as child`);
}
}
function createElement(constructor, config, ...children) {
const e = new constructor();
if (e instanceof Fragment) {
return children;
}
e.layoutConfig = layoutConfig().fit();
if (config) {
e.apply(config);
}
if (children && children.length > 0) {
if (e instanceof Group) {
children.forEach((child) => {
addElement(e, child);
});
if (children.length === 1) {
children = children[0];
}
if (Reflect.has(e, "innerElement")) {
Reflect.set(e, "innerElement", children, e);
}
else {
throw new Error(`Can only add child to group view, do not support ${constructor.name}`);
throw new Error(`Do not support ${constructor.name} for ${children}`);
}
}
return e;