diff --git a/packages/rax-simulator-renderer/src/renderer-view.tsx b/packages/rax-simulator-renderer/src/renderer-view.tsx index b80e26ca4..883c4a437 100644 --- a/packages/rax-simulator-renderer/src/renderer-view.tsx +++ b/packages/rax-simulator-renderer/src/renderer-view.tsx @@ -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, ); }} /> diff --git a/packages/renderer-core/src/renderer/addon.tsx b/packages/renderer-core/src/renderer/addon.tsx index 4e2a7ca25..cedb3e065 100644 --- a/packages/renderer-core/src/renderer/addon.tsx +++ b/packages/renderer-core/src/renderer/addon.tsx @@ -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; } diff --git a/packages/renderer-core/src/renderer/base.tsx b/packages/renderer-core/src/renderer/base.tsx index 02b0b61b3..1d81ac6d8 100644 --- a/packages/renderer-core/src/renderer/base.tsx +++ b/packages/renderer-core/src/renderer/base.tsx @@ -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) { diff --git a/packages/renderer-core/src/utils/common.ts b/packages/renderer-core/src/utils/common.ts index adb09080d..928ddbfd8 100644 --- a/packages/renderer-core/src/utils/common.ts +++ b/packages/renderer-core/src/utils/common.ts @@ -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('-');