From 66c21c07be8ededb6cd13a07de299b93e5d81ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 27 Aug 2020 09:43:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E5=9C=A8=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E4=BF=AE=E6=94=B9=20prototype=20=E6=97=B6=E4=B9=9F?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E9=87=8D=E6=96=B0=E8=AE=A1=E7=AE=97=20meta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor-preset-vision/src/bundle/bundle.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); From 795a4e6a69d0f9a89c8a5b35c5a1bf7e47b05188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Mon, 31 Aug 2020 17:59:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=98=AF=E5=90=A6=E6=98=AF=20simulator=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E7=9A=84=E9=80=BB=E8=BE=91=20fix:=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20NodeChildren#find=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/builtin-simulator/host.ts | 4 ++-- packages/designer/src/document/node/node-children.ts | 8 ++++++-- packages/editor-preset-vision/src/bundle/prototype.ts | 10 ++++++++-- packages/editor-preset-vision/src/editor.ts | 2 +- packages/utils/src/env.ts | 3 +++ packages/utils/src/index.ts | 1 + 6 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 packages/utils/src/env.ts 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/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';