Merge branch 'polyfill/vision' of gitlab.alibaba-inc.com:ali-lowcode/ali-lowcode-engine into polyfill/vision

This commit is contained in:
kangwei 2020-05-07 18:15:03 +08:00
commit 8344703f3d
4 changed files with 46 additions and 44 deletions

View File

@ -127,7 +127,11 @@ export default class Panel implements IWidget {
}
active(item?: Panel | string | null) {
this.container?.active(item);
if (item) {
this.container?.active(item);
} else {
this.setActive(true);
}
}
getName() {

View File

@ -5,7 +5,6 @@ import { observer } from '@recore/obx-react';
import { SimulatorRenderer } from './renderer';
import { host } from './host';
import './renderer.less';
import { toCss } from '@ali/vu-css-style';
// patch cloneElement avoid lost keyProps
const originCloneElement = window.React.cloneElement;
@ -87,9 +86,6 @@ class Renderer extends Component<{ renderer: SimulatorRenderer }> {
viewProps.componentId = __id;
viewProps._leaf = host.document.getNode(__id);
// FIXME: 此处未来使用propsReducer方式处理
this.createNodeStyleSheet(viewProps);
return createElement(
Component,
viewProps,
@ -105,28 +101,4 @@ class Renderer extends Component<{ renderer: SimulatorRenderer }> {
/>
);
}
createNodeStyleSheet(props: any) {
if (props && props.fieldId) {
let styleProp = props.__style__;
if (isObject(styleProp)) {
styleProp = toCss(styleProp);
}
if (typeof styleProp === 'string') {
const s = document.createElement('style');
const cssId = '_style_pesudo_' + props.fieldId;
const cssClass = '_css_pesudo_' + props.fieldId;
props.className = cssClass;
s.setAttribute('type', 'text/css');
s.setAttribute('id', cssId);
document.getElementsByTagName('head')[0].appendChild(s);
s.appendChild(document.createTextNode(styleProp.replace(/:root/g, '.' + cssClass)));
return s;
}
}
}
}

View File

@ -4,6 +4,7 @@ import { globalContext, Editor } from '@ali/lowcode-editor-core';
import { Designer, TransformStage, addBuiltinComponentAction } from '@ali/lowcode-designer';
// import { registerSetters } from '@ali/lowcode-setters';
import Outline from '@ali/lowcode-plugin-outline-pane';
import { toCss } from '@ali/vu-css-style';
import DesignerPlugin from '@ali/lowcode-plugin-designer';
import { Skeleton, SettingsPrimaryPane } from '@ali/lowcode-editor-skeleton';
@ -66,6 +67,37 @@ function upgradePropsReducer(props: any) {
}
designer.addPropsReducer(upgradePropsReducer, TransformStage.Init);
// 设计器组件样式处理
function stylePropsReducer(props: any, node: any) {
if (props && typeof props === 'object' && props.__style__) {
const doc = designer.currentDocument?.simulator?.contentDocument;
if (!doc) {
return;
}
const cssId = '_style_pesudo_' + node.id.replace(/\$/g, '_');
const cssClass = '_css_pesudo_' + node.id.replace(/\$/g, '_');
const dom = doc.getElementById(cssId);
if (dom) {
dom.parentNode?.removeChild(dom);
}
let styleProp = props.__style__;
if (typeof styleProp === 'object') {
styleProp = toCss(styleProp);
}
if (typeof styleProp === 'string') {
const s = doc.createElement('style');
props.className = cssClass;
s.setAttribute('type', 'text/css');
s.setAttribute('id', cssId);
doc.getElementsByTagName('head')[0].appendChild(s);
s.appendChild(doc.createTextNode(styleProp.replace(/:root/g, '.' + cssClass)));
}
}
return props;
}
designer.addPropsReducer(stylePropsReducer, TransformStage.Render);
skeleton.add({
area: 'mainArea',
name: 'designer',

View File

@ -69,17 +69,7 @@ function upgradeConfig(config: OldPaneConfig): IWidgetBaseConfig & { area: strin
newConfig.type = 'PanelDock';
newConfig.area = 'left';
newConfig.props.description = description || title;
const {
contents,
hideTitleBar,
tip,
width,
maxWidth,
height,
maxHeight,
menu,
isAction
} = config;
const { contents, hideTitleBar, tip, width, maxWidth, height, maxHeight, menu, isAction } = config;
if (menu) {
newConfig.props.title = menu;
}
@ -97,14 +87,14 @@ function upgradeConfig(config: OldPaneConfig): IWidgetBaseConfig & { area: strin
if (contents && Array.isArray(contents)) {
newConfig.content = contents.map(({ title, content, tip }) => {
return {
type: "Panel",
type: 'Panel',
name: title,
content,
props: {
title,
help: tip,
}
}
},
};
});
}
}
@ -163,7 +153,11 @@ const dockPane = Object.assign(skeleton.leftArea, {
return;
}
const name = item.name || item;
skeleton.getPanel(name)?.active();
const pane = skeleton.getPanel(name);
if (!pane) {
console.warn(`Could not find pane with name ${name}`);
}
pane?.active();
},
/**