diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index b8e168883..6b64c0a40 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -87,7 +87,7 @@ const defaultRaxSimulatorUrl = (() => { const defaultEnvironment = [ // https://g.alicdn.com/mylib/??react/16.11.0/umd/react.production.min.js,react-dom/16.8.6/umd/react-dom.production.min.js,prop-types/15.7.2/prop-types.min.js - assetItem(AssetType.JSText, 'window.React=parent.React;window.ReactDOM=parent.ReactDOM;', undefined, 'react'), + assetItem(AssetType.JSText, 'window.React=parent.React;window.ReactDOM=parent.ReactDOM;window.__is_simulator_env__=true;', undefined, 'react'), assetItem( AssetType.JSText, 'window.PropTypes=parent.PropTypes;React.PropTypes=parent.PropTypes; window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;', @@ -877,7 +877,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost { return this.owner.document.createNode(child); }); + } interalInitParent() { @@ -63,7 +64,7 @@ export class NodeChildren { /** * @deprecated - * @param nodes + * @param nodes */ concat(nodes: Node[]) { return this.children.concat(nodes); @@ -235,7 +236,6 @@ export class NodeChildren { return fn(child, index); }); } - every(fn: (item: Node, index: number) => any): boolean { return this.children.every((child, index) => fn(child, index)); } @@ -248,6 +248,10 @@ export class NodeChildren { return this.children.filter(fn); } + find(fn: (item: Node, index: number) => Node) { + return this.children.find(fn); + } + mergeChildren(remover: () => any, adder: (children: Node[]) => NodeData[] | null, sorter: () => any) { let changed = false; if (remover) { diff --git a/packages/editor-preset-vision/src/bundle/bundle.ts b/packages/editor-preset-vision/src/bundle/bundle.ts index d22b14af3..0c49bc098 100644 --- a/packages/editor-preset-vision/src/bundle/bundle.ts +++ b/packages/editor-preset-vision/src/bundle/bundle.ts @@ -126,8 +126,8 @@ export default class Bundle { */ if (bundles.length >= 2) { const prototype = bundles[0]; - // const metadata = upgradeMetadata(prototype.options); - // prototype.meta = designer.createComponentMeta(metadata); + const metadata = upgradeMetadata(prototype.options); + prototype.meta = designer.createComponentMeta(metadata); const prototypeView = bundles[1]; prototype.setView(prototypeView); this.registerPrototype(prototype); diff --git a/packages/editor-preset-vision/src/bundle/prototype.ts b/packages/editor-preset-vision/src/bundle/prototype.ts index a031cb9db..c1de2e6f1 100644 --- a/packages/editor-preset-vision/src/bundle/prototype.ts +++ b/packages/editor-preset-vision/src/bundle/prototype.ts @@ -1,5 +1,5 @@ import { ComponentType, ReactElement, Component, FunctionComponent } from 'react'; -import { ComponentMetadata, FieldConfig, InitialItem, FilterItem, AutorunItem, isI18nData } from '@ali/lowcode-types'; +import { ComponentMetadata, FieldConfig, InitialItem, FilterItem, AutorunItem } from '@ali/lowcode-types'; import { ComponentMeta, addBuiltinComponentAction, @@ -7,6 +7,8 @@ import { registerMetadataTransducer, TransformStage, } from '@ali/lowcode-designer'; +import { intl } from '@ali/lowcode-editor-core'; +import { isInSimulator } from '@ali/lowcode-utils'; import { OldPropConfig, OldPrototypeConfig, @@ -15,7 +17,7 @@ import { upgradePropConfig, upgradeConfigure, } from './upgrade-metadata'; -import { intl } from '@ali/lowcode-editor-core'; + import { designer } from '../editor'; const GlobalPropsConfigure: Array<{ @@ -213,6 +215,10 @@ class Prototype { static removeGlobalPropsConfigure = removeGlobalPropsConfigure; static overridePropsConfigure = overridePropsConfigure; static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, extraConfigs: any = null, lookup: boolean = false) { + // 目前 vc-xxx 会在设计器和渲染 simulator iframe 中执行两遍,在 simulator 中不需要重新创建,直接复用外层的 + if (isInSimulator()) { + lookup = true; + } return new Prototype(config, extraConfigs, lookup); } diff --git a/packages/editor-preset-vision/src/editor.ts b/packages/editor-preset-vision/src/editor.ts index d9e8b767f..a45b2f30b 100644 --- a/packages/editor-preset-vision/src/editor.ts +++ b/packages/editor-preset-vision/src/editor.ts @@ -107,7 +107,7 @@ designer.addPropsReducer((props, node) => { } }); // 全局的关闭 uniqueIdChecker 信号,在 ve-utils 中实现 - if (fieldIds.indexOf(props.fieldId) >= 0 && !window.__disable_unique_id_checker__) { + if (fieldIds.indexOf(props.fieldId) >= 0 && !(window as any).__disable_unique_id_checker__) { newProps.fieldId = undefined; } } diff --git a/packages/utils/src/env.ts b/packages/utils/src/env.ts new file mode 100644 index 000000000..4770bd46f --- /dev/null +++ b/packages/utils/src/env.ts @@ -0,0 +1,3 @@ +export function isInSimulator() { + return Boolean((window as any).__is_simulator_env__); +} \ No newline at end of file diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 3df01d928..3863eeb6b 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -18,3 +18,4 @@ export * from './set-prototype-of'; export * from './shallow-equal'; export * from './svg-icon'; export * from './unique-id'; +export * from './env';