fix: add extraEnv

This commit is contained in:
kangwei 2020-06-22 11:09:01 +08:00
parent b843117fc4
commit 9058ac82d5
5 changed files with 14 additions and 7 deletions

View File

@ -40,6 +40,7 @@ export interface BuiltinSimulatorProps {
device?: 'mobile' | 'iphone' | string;
deviceClassName?: string;
environment?: Asset;
extraEnvironment?: Asset;
library?: LibraryItem[];
simulatorUrl?: Asset;
theme?: Asset;
@ -187,6 +188,8 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
// required & use once
assetBundle(this.get('environment') || defaultEnvironment, AssetLevel.Environment),
// required & use once
assetBundle(this.get('extraEnvironment'), AssetLevel.Environment),
// required & use once
assetBundle(libraryAsset, AssetLevel.Library),
// required & TODO: think of update
assetBundle(this.theme, AssetLevel.Theme),

View File

@ -1,6 +1,6 @@
import lg from '@ali/vu-logger';
import { ComponentClass, ComponentType } from 'react';
import Prototype from './prototype';
import Prototype, { isPrototype } from './prototype';
import { designer } from '../editor';
function basename(name: string) {
@ -141,12 +141,12 @@ export default class Bundle {
private recursivelyRegisterPrototypes(list: any[], cp: ComponentProtoBundle) {
const propList: ComponentProtoBundle[] = list;
propList.forEach((proto: ComponentProtoBundle, index: number) => {
propList.forEach((proto: any, index: number) => {
if (Array.isArray(proto)) {
this.recursivelyRegisterPrototypes(proto, cp);
return;
}
if (proto instanceof Prototype) {
if (isPrototype(proto)) {
const componentName = proto.getComponentName()!;
if (!proto.getView() && this.viewsMap[componentName]) {
proto.setView(this.viewsMap[componentName]);

View File

@ -217,7 +217,7 @@ class Prototype {
}
readonly isPrototype = true;
private meta: ComponentMeta;
readonly meta: ComponentMeta;
readonly options: OldPrototypeConfig | ComponentMetadata;
constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta) {

View File

@ -35,7 +35,7 @@ export class Trunk {
bundle = this.trunk[i];
prototype = bundle.get(name);
if (prototype) {
return prototype;
return (prototype.meta as any).prototype;
}
}
return this.metaBundle.getFromMeta(name);

View File

@ -10,6 +10,7 @@ export interface PluginProps {
interface DesignerPluginState {
componentMetadatas?: any[] | null;
library?: any[] | null;
extraEnvironment?: any[] | null;
}
export default class DesignerPlugin extends PureComponent<PluginProps, DesignerPluginState> {
@ -18,6 +19,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
state: DesignerPluginState = {
componentMetadatas: null,
library: null,
extraEnvironment: null,
};
private _mounted = true;
@ -33,10 +35,11 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
if (!this._mounted) {
return;
}
const { components, packages } = assets;
const { components, packages, extraEnvironment } = assets;
const state = {
componentMetadatas: components || [],
library: packages || [],
extraEnvironment,
};
this.setState(state);
};
@ -56,7 +59,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
render(): React.ReactNode {
const { editor } = this.props;
const { componentMetadatas, library } = this.state;
const { componentMetadatas, library, extraEnvironment } = this.state;
if (!library || !componentMetadatas) {
// TODO: use a Loading
@ -72,6 +75,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
componentMetadatas={componentMetadatas}
simulatorProps={{
library,
extraEnvironment,
}}
/>
);