fix: 合并后bugfix

This commit is contained in:
荣彬 2020-08-20 22:13:13 +08:00
parent c871eb980e
commit c3e6b4b35f
3 changed files with 83 additions and 81 deletions

View File

@ -13,7 +13,7 @@
"build": "./scripts/build.sh", "build": "./scripts/build.sh",
"clean": "rm -rf ./packages/*/lib ./packages/*/es ./packages/*/dist ./packages/*/build", "clean": "rm -rf ./packages/*/lib ./packages/*/es ./packages/*/dist ./packages/*/build",
"commit": "git-cz", "commit": "git-cz",
"pub": "lerna publish --force-publish --cd-version major", "pub": "lerna publish --force-publish --cd-version prepatch",
"setup": "./scripts/setup.sh", "setup": "./scripts/setup.sh",
"start": "./scripts/start.sh", "start": "./scripts/start.sh",
"start:server": "./scripts/start-server.sh", "start:server": "./scripts/start-server.sh",

View File

@ -53,5 +53,5 @@
"publishConfig": { "publishConfig": {
"registry": "http://registry.npm.alibaba-inc.com" "registry": "http://registry.npm.alibaba-inc.com"
}, },
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.4-0/build/index.html" "homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.5-0/build/index.html"
} }

View File

@ -34,6 +34,7 @@ let scopeIdx = 0;
export default class BaseRender extends PureComponent { export default class BaseRender extends PureComponent {
static dislayName = 'base-renderer'; static dislayName = 'base-renderer';
static propTypes = { static propTypes = {
locale: PropTypes.string, locale: PropTypes.string,
messages: PropTypes.object, messages: PropTypes.object,
@ -42,9 +43,11 @@ export default class BaseRender extends PureComponent {
__ctx: PropTypes.object, __ctx: PropTypes.object,
__schema: PropTypes.object, __schema: PropTypes.object,
}; };
static defaultProps = { static defaultProps = {
__schema: {}, __schema: {},
}; };
static contextType = AppContext; static contextType = AppContext;
constructor(props, context) { constructor(props, context) {
@ -78,8 +81,7 @@ export default class BaseRender extends PureComponent {
console.warn(e); console.warn(e);
} }
reloadDataSource = () => { reloadDataSource = () => new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
debug('reload data source'); debug('reload data source');
if (!this.__dataHelper) { if (!this.__dataHelper) {
this.__showPlaceholder = false; this.__showPlaceholder = false;
@ -103,7 +105,6 @@ export default class BaseRender extends PureComponent {
reject(err); reject(err);
}); });
}); });
};
__setLifeCycleMethods = (method, args) => { __setLifeCycleMethods = (method, args) => {
const lifeCycleMethods = getValue(this.props.__schema, 'lifeCycles', {}); const lifeCycleMethods = getValue(this.props.__schema, 'lifeCycles', {});
@ -128,8 +129,8 @@ export default class BaseRender extends PureComponent {
__bindCustomMethods = (props = this.props) => { __bindCustomMethods = (props = this.props) => {
const { __schema } = props; const { __schema } = props;
const customMethodsList = Object.keys(__schema.methods || {}) || []; const customMethodsList = Object.keys(__schema.methods || {}) || [];
this.__customMethodsList && this.__customMethodsList
this.__customMethodsList.forEach((item) => { && this.__customMethodsList.forEach((item) => {
if (!customMethodsList.includes(item)) { if (!customMethodsList.includes(item)) {
delete this[item]; delete this[item];
} }
@ -171,16 +172,16 @@ export default class BaseRender extends PureComponent {
this.__dataHelper = new DataHelper(this, dataSource, appHelper, (config) => this.__parseData(config)); this.__dataHelper = new DataHelper(this, dataSource, appHelper, (config) => this.__parseData(config));
this.dataSourceMap = this.__dataHelper.dataSourceMap; this.dataSourceMap = this.__dataHelper.dataSourceMap;
// loading // loading
this.__showPlaceholder = this.__showPlaceholder = this.__parseData(schema.props && schema.props.autoLoading) && (dataSource.list || []).some(
this.__parseData(schema.props && schema.props.autoLoading) && (item) => !!this.__parseData(item.isInit),
(dataSource.list || []).some((item) => !!this.__parseData(item.isInit)); );
}; };
__render = () => { __render = () => {
const schema = this.props.__schema; const schema = this.props.__schema;
this.__setLifeCycleMethods('render'); this.__setLifeCycleMethods('render');
const engine = this.context.engine; const { engine } = this.context;
if (engine) { if (engine) {
engine.props.onCompGetCtx(schema, this); engine.props.onCompGetCtx(schema, this);
// bind // bind
@ -201,7 +202,7 @@ export default class BaseRender extends PureComponent {
} }
if (!schema.children) return schema.props.children; if (!schema.children) return schema.props.children;
if (!schema.props.children) return schema.children; if (!schema.props.children) return schema.children;
var _children = [].concat(schema.children); let _children = [].concat(schema.children);
if (Array.isArray(schema.props.children)) { if (Array.isArray(schema.props.children)) {
_children = _children.concat(schema.props.children); _children = _children.concat(schema.props.children);
} else { } else {
@ -214,7 +215,7 @@ export default class BaseRender extends PureComponent {
const { __schema, __ctx, __components = {} } = this.props; const { __schema, __ctx, __components = {} } = this.props;
const self = {}; const self = {};
self.__proto__ = __ctx || this; self.__proto__ = __ctx || this;
let _children = this.getSchemaChildren(__schema); const _children = this.getSchemaChildren(__schema);
return this.__createVirtualDom(_children, self, { return this.__createVirtualDom(_children, self, {
schema: __schema, schema: __schema,
Comp: __components[__schema.componentName], Comp: __components[__schema.componentName],
@ -230,8 +231,7 @@ export default class BaseRender extends PureComponent {
const { engine } = this.context || {}; const { engine } = this.context || {};
try { try {
if (!schema) return null; if (!schema) return null;
const { __appHelper: appHelper, __components: components = {} } = const { __appHelper: appHelper, __components: components = {} } = this.props || {};
this.props || {};
if (isJSExpression(schema)) { if (isJSExpression(schema)) {
return parseExpression(schema, self); return parseExpression(schema, self);
@ -245,15 +245,13 @@ export default class BaseRender extends PureComponent {
} }
if (Array.isArray(schema)) { if (Array.isArray(schema)) {
if (schema.length === 1) return this.__createVirtualDom(schema[0], self, parentInfo); if (schema.length === 1) return this.__createVirtualDom(schema[0], self, parentInfo);
return schema.map((item, idx) => return schema.map((item, idx) => this.__createVirtualDom(item, self, parentInfo, item && item.__ctx && item.__ctx.lunaKey ? '' : idx),);
this.__createVirtualDom(item, self, parentInfo, item && item.__ctx && item.__ctx.lunaKey ? '' : idx),
);
} }
// FIXME // FIXME
const _children = this.getSchemaChildren(schema); const _children = this.getSchemaChildren(schema);
// //
if (schema.componentName === 'Flagment' && _children) { if (schema.componentName === 'Flagment' && _children) {
let tarChildren = isJSExpression(_children) ? parseExpression(_children, self) : _children; const tarChildren = isJSExpression(_children) ? parseExpression(_children, self) : _children;
return this.__createVirtualDom(tarChildren, self, parentInfo); return this.__createVirtualDom(tarChildren, self, parentInfo);
} }
@ -269,7 +267,7 @@ export default class BaseRender extends PureComponent {
if (schema.loop != null) { if (schema.loop != null) {
const loop = parseData(schema.loop, self); const loop = parseData(schema.loop, self);
if (Array.isArray(loop) && loop.length > 0 || isJSExpression(loop)) { if ((Array.isArray(loop) && loop.length > 0) || isJSExpression(loop)) {
return this.__createLoopVirtualDom( return this.__createLoopVirtualDom(
{ {
...schema, ...schema,
@ -324,7 +322,8 @@ export default class BaseRender extends PureComponent {
otherProps.__designMode = engine.props.designMode; otherProps.__designMode = engine.props.designMode;
} }
const componentInfo = {}; const componentInfo = {};
const props = this.__parseProps(schema.props, self, '', { const props =
this.__parseProps(schema.props, self, '', {
schema, schema,
Comp, Comp,
componentInfo: { componentInfo: {
@ -361,27 +360,19 @@ export default class BaseRender extends PureComponent {
if (!props.key) { if (!props.key) {
props.key = props.__id; props.key = props.__id;
} }
const renderComp = (props) => {
return engine.createElement( let child = null;
Comp, if (!isFileSchema(schema) && !!_children) {
props, child = this.__createVirtualDom(
<<<<<<< HEAD:packages/react-renderer/src/renderer/base.jsx
(!isFileSchema(schema) &&
!!_children &&
=======
(!!schema.children &&
>>>>>>> master:packages/react-renderer/src/engine/base.jsx
this.__createVirtualDom(
isJSExpression(_children) ? parseExpression(_children, self) : _children, isJSExpression(_children) ? parseExpression(_children, self) : _children,
self, self,
{ {
schema, schema,
Comp, Comp,
}, },
)) ||
null,
); );
}; }
const renderComp = (props) => engine.createElement(Comp, props, child);
// //
if (engine && [DESIGN_MODE.EXTEND, DESIGN_MODE.BORDER].includes(engine.props.designMode)) { if (engine && [DESIGN_MODE.EXTEND, DESIGN_MODE.BORDER].includes(engine.props.designMode)) {
// overlay,dialog使div // overlay,dialog使div
@ -397,7 +388,10 @@ export default class BaseRender extends PureComponent {
if (componentInfo && componentInfo.parentRule) { if (componentInfo && componentInfo.parentRule) {
const parentList = componentInfo.parentRule.split(','); const parentList = componentInfo.parentRule.split(',');
const { schema: parentSchema, Comp: parentComp } = parentInfo; const { schema: parentSchema, Comp: parentComp } = parentInfo;
if (!parentList.includes(parentSchema.componentName) || parentComp !== components[parentSchema.componentName]) { if (
!parentList.includes(parentSchema.componentName) ||
parentComp !== components[parentSchema.componentName]
) {
props.__componentName = schema.componentName; props.__componentName = schema.componentName;
Comp = VisualDom; Comp = VisualDom;
} else { } else {
@ -458,7 +452,7 @@ export default class BaseRender extends PureComponent {
const parseReactNode = (data, params) => { const parseReactNode = (data, params) => {
if (isEmpty(params)) { if (isEmpty(params)) {
return checkProps(this.__createVirtualDom(data, self, { schema, Comp })); return checkProps(this.__createVirtualDom(data, self, { schema, Comp }));
} else { }
return checkProps(function() { return checkProps(function() {
const args = {}; const args = {};
if (Array.isArray(params) && params.length) { if (Array.isArray(params) && params.length) {
@ -473,7 +467,6 @@ export default class BaseRender extends PureComponent {
args.__proto__ = self; args.__proto__ = self;
return self.__createVirtualDom(data, args, { schema, Comp }); return self.__createVirtualDom(data, args, { schema, Comp });
}); });
}
}; };
// //
@ -504,20 +497,20 @@ export default class BaseRender extends PureComponent {
// componentInfo // componentInfo
if (isSchema(props)) { if (isSchema(props)) {
const isReactNodeFunction = !!( const isReactNodeFunction = !!(
propInfo && propInfo
propInfo.type === 'ReactNode' && && propInfo.type === 'ReactNode'
propInfo.props && && propInfo.props
propInfo.props.type === 'function' && propInfo.props.type === 'function'
); );
const isMixinReactNodeFunction = !!( const isMixinReactNodeFunction = !!(
propInfo && propInfo
propInfo.type === 'Mixin' && && propInfo.type === 'Mixin'
propInfo.props && && propInfo.props
propInfo.props.types && && propInfo.props.types
propInfo.props.types.indexOf('ReactNode') > -1 && && propInfo.props.types.indexOf('ReactNode') > -1
propInfo.props.reactNodeProps && && propInfo.props.reactNodeProps
propInfo.props.reactNodeProps.type === 'function' && propInfo.props.reactNodeProps.type === 'function'
); );
return parseReactNode( return parseReactNode(
props, props,
@ -527,11 +520,14 @@ export default class BaseRender extends PureComponent {
? propInfo.props.reactNodeProps.params ? propInfo.props.reactNodeProps.params
: null, : null,
); );
} else if (Array.isArray(props)) { }
if (Array.isArray(props)) {
return checkProps(props.map((item, idx) => this.__parseProps(item, self, path ? `${path}.${idx}` : idx, info))); return checkProps(props.map((item, idx) => this.__parseProps(item, self, path ? `${path}.${idx}` : idx, info)));
} else if (typeof props === 'function') { }
if (typeof props === 'function') {
return checkProps(props.bind(self)); return checkProps(props.bind(self));
} else if (props && typeof props === 'object') { }
if (props && typeof props === 'object') {
if (props.$$typeof) return checkProps(props); if (props.$$typeof) return checkProps(props);
const res = {}; const res = {};
forEach(props, (val, key) => { forEach(props, (val, key) => {
@ -542,7 +538,8 @@ export default class BaseRender extends PureComponent {
res[key] = this.__parseProps(val, self, path ? `${path}.${key}` : key, info); res[key] = this.__parseProps(val, self, path ? `${path}.${key}` : key, info);
}); });
return checkProps(res); return checkProps(res);
} else if (typeof props === 'string') { }
if (typeof props === 'string') {
return checkProps(props.trim()); return checkProps(props.trim());
} }
return checkProps(props); return checkProps(props);
@ -551,18 +548,23 @@ export default class BaseRender extends PureComponent {
get utils() { get utils() {
return this.appHelper && this.appHelper.utils; return this.appHelper && this.appHelper.utils;
} }
get constants() { get constants() {
return this.appHelper && this.appHelper.constants; return this.appHelper && this.appHelper.constants;
} }
get history() { get history() {
return this.appHelper && this.appHelper.history; return this.appHelper && this.appHelper.history;
} }
get location() { get location() {
return this.appHelper && this.appHelper.location; return this.appHelper && this.appHelper.location;
} }
get match() { get match() {
return this.appHelper && this.appHelper.match; return this.appHelper && this.appHelper.match;
} }
render() { render() {
return null; return null;
} }