read lifecycle

This commit is contained in:
kangwei 2020-03-16 22:32:28 +08:00
parent 2efbe38d01
commit c817d2424a
6 changed files with 157 additions and 60 deletions

View File

@ -314,7 +314,10 @@ export interface LibraryMap {
function buildComponents(libraryMap: LibraryMap, componentsMap: { [componentName: string]: NpmInfo }) { function buildComponents(libraryMap: LibraryMap, componentsMap: { [componentName: string]: NpmInfo }) {
const components: any = {}; const components: any = {};
Object.keys(componentsMap).forEach(componentName => { Object.keys(componentsMap).forEach(componentName => {
components[componentName] = findComponent(libraryMap, componentName, componentsMap[componentName]); const component = findComponent(libraryMap, componentName, componentsMap[componentName]);
if (component) {
components[componentName] = component;
}
}); });
return components; return components;
} }

View File

@ -13,6 +13,44 @@ export default {
} }
}, },
components: { components: {
Page: {
componentName: 'Page',
title: '页面',
configure: {
events: {
supportedLifecycles: [
{
description: '初始化时',
name: 'constructor',
},
{
description: '装载后',
name: 'componentDidMount',
},
{
description: '更新时',
name: 'componentDidMount',
},
{
description: '卸载时',
name: 'componentWillUnmount',
},
]
},
component: {
isContainer: true,
}
}
},
Div: {
componentName: 'Div',
title: '容器',
configure: {
component: {
isContainer: true,
}
}
},
Button: { Button: {
componentName: 'Button', componentName: 'Button',
title: '按钮', title: '按钮',
@ -165,7 +203,15 @@ export default {
name: 'children', name: 'children',
propType: 'node' propType: 'node'
} }
] ],
configure: {
component: {
isContainer: true,
nestingRule: {
childWhitelist: 'Button'
}
}
}
}, },
Input: { Input: {
componentName: 'Input', componentName: 'Input',
@ -450,7 +496,12 @@ export default {
propType: 'bool', propType: 'bool',
description: '是否开启预览态' description: '是否开启预览态'
} }
] ],
configure: {
component: {
isContainer: true,
}
}
}, },
'Form.Item': { 'Form.Item': {
componentName: 'Form.Item', componentName: 'Form.Item',
@ -747,7 +798,15 @@ export default {
propType: 'func', propType: 'func',
description: '预览态模式下渲染的内容\n@param {any} value 根据包裹的组件的 value 类型而决定' description: '预览态模式下渲染的内容\n@param {any} value 根据包裹的组件的 value 类型而决定'
} }
] ],
configure: {
component: {
isContainer: true,
nestingRule: {
parentWhitelist: 'Form'
}
}
}
}, },
NumberPicker: { NumberPicker: {
componentName: 'NumberPicker', componentName: 'NumberPicker',
@ -1142,7 +1201,15 @@ export default {
propType: 'object', propType: 'object',
defaultValue: 'zhCN.Select' defaultValue: 'zhCN.Select'
} }
] ],
configure: {
component: {
isContainer: true,
nestingRule: {
childWhitelist: 'Select.Option'
}
}
}
}, },
'Select.Option': { 'Select.Option': {
componentName: 'Select.Option', componentName: 'Select.Option',
@ -1173,7 +1240,15 @@ export default {
name: 'children', name: 'children',
propType: 'any' propType: 'any'
} }
] ],
configure: {
component: {
isContainer: true,
nestingRule: {
parentWhitelist: 'Select'
}
}
}
} }
}, },
componentList: [ componentList: [

View File

@ -8,6 +8,7 @@ import Node from '../../designer/src/designer/document/node/node';
import ArraySetter from './builtin-setters/array-setter'; import ArraySetter from './builtin-setters/array-setter';
import ObjectSetter from './builtin-setters/object-setter'; import ObjectSetter from './builtin-setters/object-setter';
import './register-transducer'; import './register-transducer';
import { TipContainer } from './tip';
export default class SettingsMainView extends Component { export default class SettingsMainView extends Component {
private main: SettingsMain; private main: SettingsMain;
@ -101,6 +102,7 @@ export default class SettingsMainView extends Component {
return ( return (
<div className="lc-settings-main"> <div className="lc-settings-main">
<TipContainer />
<Tab <Tab
navClassName="lc-settings-tabs" navClassName="lc-settings-tabs"
animation={false} animation={false}

View File

@ -11,7 +11,13 @@ import { SetterType, FieldConfig, SettingField } from './main';
import { registerMetadataTransducer } from '../../designer/src/designer/component-meta'; import { registerMetadataTransducer } from '../../designer/src/designer/component-meta';
export function propConfigToFieldConfig(propConfig: PropConfig): FieldConfig { export function propConfigToFieldConfig(propConfig: PropConfig): FieldConfig {
const { name, description } = propConfig;
const title = {
label: description?.slice(0, 10) || name,
tip: description ? `${name} | ${description}` : undefined,
};
return { return {
title,
...propConfig, ...propConfig,
setter: propTypeToSetter(propConfig.propType), setter: propTypeToSetter(propConfig.propType),
}; };
@ -163,21 +169,23 @@ registerMetadataTransducer(metadata => {
return metadata as any; return metadata as any;
} }
} }
const { configure = {} } = metadata;
if (!metadata.props) { if (!metadata.props) {
return { return {
...metadata, ...metadata,
configure: { configure: {
props: metadata.configure && Array.isArray(metadata.configure) ? metadata.configure : [], ...configure,
props: [],
}, },
}; };
} }
const { configure = {} } = metadata;
const { props = [], component = {}, events = {}, styles = {} } = configure; const { props = [], component = {}, events = {}, styles = {} } = configure;
const supportEvents: string[] | null = (events as any).supportEvents ? null : []; const supportedEvents: any[] | null = (events as any).supportedEvents ? null : [];
metadata.props.forEach(prop => { metadata.props.forEach(prop => {
const { name, propType } = prop; const { name, propType, description } = prop;
if ( if (
name === 'children' && name === 'children' &&
(component.isContainer || propType === 'node' || propType === 'element' || propType === 'any') (component.isContainer || propType === 'node' || propType === 'element' || propType === 'any')
@ -189,9 +197,12 @@ registerMetadataTransducer(metadata => {
} }
if (EVENT_RE.test(name) && (propType === 'func' || propType === 'any')) { if (EVENT_RE.test(name) && (propType === 'func' || propType === 'any')) {
if (supportEvents) { if (supportedEvents) {
supportEvents.push(name); supportedEvents.push({
(events as any).supportEvents = supportEvents; name,
description,
});
(events as any).supportedEvents = supportedEvents;
} }
return; return;
} }
@ -304,44 +315,40 @@ registerMetadataTransducer(metadata => {
}; };
} }
const { props, events, styles } = configure as any; const { props, events = {}, styles } = configure as any;
let eventsDefinition: any; const isRoot: boolean = componentName === 'Page' || componentName === 'Component';
let isRoot: boolean = false; const eventsDefinition: any[] = [];
if (componentName === 'Page' || componentName === 'Component') { const supportedLifecycles = events.supportedLifecycles || (isRoot ? [
isRoot = true; {
// 平台配置的,一般只有根节点才会配置 description: '初始化时',
eventsDefinition = [ name: 'constructor',
{ },
type: 'lifeCycleEvent', {
title: '生命周期', description: '装载后',
list: [ name: 'componentDidMount',
{ },
description: '初始化时', {
name: 'constructor', description: '更新时',
}, name: 'componentDidMount',
{ },
description: '装载后', {
name: 'componentDidMount', description: '卸载时',
}, name: 'componentWillUnmount',
{ },
description: '更新时', ] : null);
name: 'componentDidMount', if (supportedLifecycles) {
}, eventsDefinition.push({
{ type: 'lifeCycleEvent',
description: '卸载时', title: '生命周期',
name: 'componentWillUnmount', list: supportedLifecycles.map((event: any) => (typeof event === 'string' ? { name: event } : event)),
}, });
], }
}, if (events.supportedEvents) {
]; eventsDefinition.push({
} else { type: 'events',
eventsDefinition = [ title: '事件',
{ list: (events.supportedEvents || []).map((event: any) => (typeof event === 'string' ? { name: event } : event)),
type: 'events', });
title: '事件',
list: (events?.supportEvents || []).map((event: any) => (typeof event === 'string' ? { name: event } : event)),
},
];
} }
// 通用设置 // 通用设置
const propsGroup = props || []; const propsGroup = props || [];
@ -402,7 +409,7 @@ registerMetadataTransducer(metadata => {
}); });
} }
if (eventsDefinition) { if (eventsDefinition.length > 0) {
combined.push({ combined.push({
name: '#events', name: '#events',
title: '事件', title: '事件',
@ -416,15 +423,14 @@ registerMetadataTransducer(metadata => {
definition: eventsDefinition, definition: eventsDefinition,
}, },
}, },
getValue(field: SettingField, val?: any[]) {
getValue(field: SettingField, val?:any[]) { // todo:
return val; return val;
}, },
setValue(field: SettingField, eventDataList: any[]) { setValue(field: SettingField, eventDataList: any[]) {
// todo:
return; return;
// console.info(eventDataList);
// field.parent.setPropValue('eventDataList', eventDataList);
}, },
}, },
], ],
@ -432,7 +438,6 @@ registerMetadataTransducer(metadata => {
} }
if (isRoot) { if (isRoot) {
// todo...
combined.push({ combined.push({
name: '#advanced', name: '#advanced',
title: '高级', title: '高级',

View File

@ -6,7 +6,7 @@ import './title.less';
export interface IconConfig { export interface IconConfig {
type: string; type: string;
size?: number | "small" | "xxs" | "xs" | "medium" | "large" | "xl" | "xxl" | "xxxl" | "inherit"; size?: number | 'small' | 'xxs' | 'xs' | 'medium' | 'large' | 'xl' | 'xxl' | 'xxxl' | 'inherit';
className?: string; className?: string;
} }
@ -51,7 +51,12 @@ export default class Title extends Component<{ title: TitleContent; onClick?: ()
} }
return ( return (
<div className={classNames('lc-title', title.className)} onClick={this.props.onClick}> <div
className={classNames('lc-title', title.className, {
'has-tip': !!tip,
})}
onClick={this.props.onClick}
>
{icon ? <div className="lc-title-icon">{icon}</div> : null} {icon ? <div className="lc-title-icon">{icon}</div> : null}
{title.label ? <span className="lc-title-label">{title.label}</span> : null} {title.label ? <span className="lc-title-label">{title.label}</span> : null}
{tip} {tip}

View File

@ -7,6 +7,13 @@
align-items: center; align-items: center;
margin-right: 4px; margin-right: 4px;
} }
&.has-tip {
cursor: help;
text-decoration-line: underline;
text-decoration-style: dashed;
text-decoration-color: rgba(31, 56, 88, .3);
}
padding: 2px 0;
} }
.actived .lc-title { .actived .lc-title {