Merge branch feat/renderer-1.0.45 into release/1.0.45

Title: 渲染模块3个需求 

Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/5273568
This commit is contained in:
lihao.ylh 2021-04-22 19:23:38 +08:00
commit ecfbe24e50
4 changed files with 28 additions and 5 deletions

View File

@ -231,7 +231,7 @@ class Renderer extends Component<{
return createElement(
getDeviceView(Component, device, designMode),
viewProps,
leaf?.isContainer() ? (children == null ? [] : Array.isArray(children) ? children : [children]) : null,
leaf?.isContainer() ? (children == null ? [] : Array.isArray(children) ? children : [children]) : children,
);
}}
/>

View File

@ -27,7 +27,7 @@ export default function addonRendererFactory() {
const schema = props.__schema || {};
this.state = this.__parseData(schema.state || {});
if (isEmpty(props.config) || !props.config.addonKey) {
console.warn('luna addon has wrong config');
console.warn('lce addon has wrong config');
this.state.__hasError = true;
return;
}

View File

@ -268,9 +268,32 @@ export default function baseRenererFactory() {
this.setLocale = (loc: string) => this.appHelper?.utils?.i18n?.setLocale && this.appHelper?.utils?.i18n?.setLocale(loc);
};
__writeCss = () => {
const css = getValue(this.props.__schema, 'css', '');
let style = this.styleElement;
if (!this.styleElement) {
style = document.createElement('style');
style.type = 'text/css';
style.setAttribute('from', 'style-sheet');
if (style.firstChild) {
style.removeChild(style.firstChild);
}
const head = document.head || document.getElementsByTagName('head')[0];
head.appendChild(style);
this.styleElement = style;
}
if (style.innerHTML === css) {
return;
}
style.innerHTML = css;
};
__render = () => {
const schema = this.props.__schema;
this.__setLifeCycleMethods('render');
this.__writeCss();
const { engine } = this.context;
if (engine) {
@ -441,7 +464,7 @@ export default function baseRenererFactory() {
Comp = compWrapper(Comp);
}
otherProps.ref = (ref: any) => {
this.$(props.fieldId, ref); // 收集ref
this.$(props.fieldId || props.ref, ref); // 收集ref
const refProps = props.ref;
if (refProps && typeof refProps === 'string') {
this[refProps] = ref;
@ -668,7 +691,7 @@ export default function baseRenererFactory() {
$(filedId: string, instance?: any) {
this.__instanceMap = this.__instanceMap || {};
if (!filedId) {
if (!filedId || typeof filedId !== 'string') {
return this.__instanceMap;
}
if (instance) {

View File

@ -90,7 +90,7 @@ export function inSameDomain() {
export function getFileCssName(fileName: string) {
if (!fileName) return;
const name = fileName.replace(/([A-Z])/g, '-$1').toLowerCase();
return (`luna-${name}`)
return (`lce-${name}`)
.split('-')
.filter((p) => !!p)
.join('-');