From 186f715e9275934515ed535eccac98fa11a76c2a Mon Sep 17 00:00:00 2001 From: kangwei Date: Thu, 16 Apr 2020 01:27:55 +0800 Subject: [PATCH] start work trunk --- .../src/bundle/upgrade-metadata.ts | 193 ++++++++++++------ 1 file changed, 131 insertions(+), 62 deletions(-) diff --git a/packages/vision-polyfill/src/bundle/upgrade-metadata.ts b/packages/vision-polyfill/src/bundle/upgrade-metadata.ts index 4828f31b3..55221cd7a 100644 --- a/packages/vision-polyfill/src/bundle/upgrade-metadata.ts +++ b/packages/vision-polyfill/src/bundle/upgrade-metadata.ts @@ -1,28 +1,39 @@ +export enum DISPLAY_TYPE { + NONE = 'none', + PLAIN = 'plain', + INLINE = 'inline', + BLOCK = 'block', + ACCORDION = 'accordion', + TAB = 'tab', + ENTRY = 'entry', +} + export interface IPropConfig { /** * composite share the namespace * group just be tie up together */ - type?: 'composite' | 'group'; + type?: 'composite' | 'group'; // => composite as objectSetter /** * when type is composite or group */ - items?: IPropConfig[]; + items?: IPropConfig[]; // => items /** * property name: the field key in props of schema */ - name: string; - title?: string; + name: string; // => + title?: string; // => tip?: { + // => title?: string; content?: string; url?: string; }; - initialValue?: any; - defaultValue?: any; - display?: DISPLAY_TYPE; - fieldStyle?: DISPLAY_TYPE; - setter?: ComponentClass | ISetterConfig[] | string | SetterGetter; + initialValue?: any; // => ? + defaultValue?: any; // => + display?: DISPLAY_TYPE; // => fieldExtraProps + fieldStyle?: DISPLAY_TYPE; // => fieldExtraProps + setter?: ComponentClass | ISetterConfig[] | string | SetterGetter; // => /** * if a prop is dynamicProp, every-time while rendering setting field * - getValue() will not include value of getHotValue() @@ -31,61 +42,61 @@ export interface IPropConfig { * from node of current page */ isDynamicProp?: boolean; - supportVariable?: boolean; + supportVariable?: boolean; // => use MixinSetter /** * the prop should be collapsed while display value is accordion */ - collapse?: boolean; + collapse?: boolean; // => extraProps.defaultCollapsed /** * alias to collapse */ - collapsed?: boolean; - fieldCollapsed?: boolean; + collapsed?: boolean; // => extraProps.defaultCollapsed + fieldCollapsed?: boolean; // => extraProps.defaultCollapsed /** * if a prop is declared as disabled, it will not be saved into * schema */ - disabled?: boolean | ReturnBooleanFunction; + disabled?: boolean | ReturnBooleanFunction; // => hide & virtual ? thinkof global transform /** * will not export data to schema */ - ignore?: boolean | ReturnBooleanFunction; + ignore?: boolean | ReturnBooleanFunction; // => ?virtualProp ? thinkof global transform /** * if a prop is declared as virtual, it will not be saved in * schema props, instead it will be saved into context field */ - virtual?: boolean | ReturnBooleanFunction; - hidden?: boolean | ReturnBooleanFunction; + virtual?: boolean | ReturnBooleanFunction; // =>?virtualProp + hidden?: boolean | ReturnBooleanFunction; // => condition /** * if a prop is a lifeCycle function */ - lifeCycle?: boolean; - destroy?: () => any; + lifeCycle?: boolean; // =>? + destroy?: () => any; // => x initial?(this: Prop, value: any, initialValue: any): any; /** * when use getValue(), accessor shall be called as initializer */ - accessor?(this: Prop): any; + accessor?(this: Prop): any; // => getValue /** * when current prop value mutate, the mutator function shall be called */ - mutator?( + mutator?( // => setValue this: Prop, value: any, - hotValue: any, - preValue: any, - preHotValue: any, + hotValue: any, // => x + preValue: any, // => x + preHotValue: any, // => x ): void; /** * other values' change will trigger sync function here */ - sync?(this: Prop, value: any): void; + sync?(this: Prop, value: any): void; // => ? autorun /** * transform runtime data between view and setter * @param toHotValue hot value for the setter * @param toViewValue static value for the view */ - transformer?( + transformer?( // =>? toHotValue: (data: any) => any, toViewValue: (str: string) => any, ): any; @@ -93,10 +104,9 @@ export interface IPropConfig { * user click var to change current field to * variable setting field */ - useVariableChange?(data: { isUseVariable: boolean }): any; + useVariableChange?(data: { isUseVariable: boolean }): any; // => ? } - export interface SettingFieldConfig { type?: 'field'; title?: string; @@ -116,16 +126,98 @@ export interface SettingGroupConfig { }; } +/** + * 升级 + */ +function upgradeMetadata(oldConfig: OldPrototypeConfig) { + const { + componentName, + docUrl, + title, + icon, + packageName, + category, + defaultProps, + extraActions, + view, + initialChildren, + configure, + snippets, + transducers, + reducers, + isContainer, + rectSelector, + isModal, + isFloating, + descriptor, + context, + hasSlot, + canOperating, + canDraging, + canDragging, + canSelecting, + canContain, + canDropTo, + canDropto, + canDropIn, + canDroping, + didDropOut, + didDropIn, + canResizing, + onResizeStart, + onResize, + onResizeEnd, + subtreeModified, + } = oldConfig; -export declare interface IComponentPrototypeConfigure { + + const meta: any = { + componentName, + title, + icon, + docUrl, + devMode: 'procode', + } + + if (category) { + meta.tags = [category]; + } + if (packageName) { + meta.npm = { + componentName, + package: packageName, + }; + } + + const component: any = { + isContainer, + rectSelector, + isModal, + isFloating, + descriptor, + }; + + if (canOperating === false) { + component.disableBehaviors = '*'; + } + nestingRule + disableBehaviors + actions + const props = {}; + const styles = {}; + const events = {}; + meta.configure = { props, component, styles, events }; + +} + +export interface OldPrototypeConfig { packageName: string; // => npm.package - uri?: string; /** * category display in the component pane * component will be hidden while the value is: null */ category: string; // => tags - componentName: string;// => + componentName: string; // => docUrl?: string; // => defaultProps?: any; // => ? /** @@ -150,12 +242,12 @@ export declare interface IComponentPrototypeConfigure { * @example '.classname > div' */ rectSelector?: string; // => configure.component.rectSelector - context?: { // => ? + context?: { + // => ? [contextInfoName: string]: any; }; isContainer?: boolean; // => configure.component.isContainer - isInline?: boolean; // x isModal?: boolean; // => configure.component.isModal isFloating?: boolean; // => configure.component.isFloating descriptor?: string; // => configure.component.descriptor @@ -167,14 +259,11 @@ export declare interface IComponentPrototypeConfigure { hasSlot?: boolean; // => ? // alias to canDragging - canDraging?: boolean; // => ? + canDraging?: boolean; // => onDrag canDragging?: boolean; // => ? canOperating?: boolean; // => disabledActions - canHovering?: boolean; // x canSelecting?: boolean; - canUseCondition?: boolean; // x - canLoop?: boolean; // x canContain?: (dragment: Node) => boolean; // => nestingRule canDropTo?: ((container: Node) => boolean) | string | string[]; // => nestingRule @@ -187,34 +276,14 @@ export declare interface IComponentPrototypeConfigure { didDropIn?: (container: any | Prototype, dragment: any) => boolean; // => hooks // => ? - canResizing?: - | ((dragment: Node, triggerDirection: string) => boolean) - | boolean; - onResizeStart?: ( - e: MouseEvent, - triggerDirection: string, - dragment: Node, - ) => void; - onResize?: ( - e: MouseEvent, - triggerDirection: string, - dragment: Node, - moveX: number, - moveY: number, - ) => void; - onResizeEnd?: ( - e: MouseEvent, - triggerDirection: string, - dragment: Node, - ) => void; + canResizing?: ((dragment: Node, triggerDirection: string) => boolean) | boolean; + onResizeStart?: (e: MouseEvent, triggerDirection: string, dragment: Node) => void; + onResize?: (e: MouseEvent, triggerDirection: string, dragment: Node, moveX: number, moveY: number) => void; + onResizeEnd?: (e: MouseEvent, triggerDirection: string, dragment: Node) => void; /** * when sub-node of the current node changed * including: sub-node insert / remove */ - subtreeModified?(this: Node): any; // => ? -} - -export interface IComponentPrototypeExtraConfigs { - autoGenerated?: boolean; + subtreeModified?(this: Node): any; // => ? hooks }