From 2871b5ba4c3dbf1ed76bf4d6359fb457190a9b22 Mon Sep 17 00:00:00 2001 From: twinkle77 <2153165927@qq.com> Date: Thu, 19 May 2022 14:23:15 +0800 Subject: [PATCH] feat: sync utils/constants (#506) --- packages/designer/src/builtin-simulator/host.ts | 1 + packages/editor-core/src/config.ts | 9 +++++++++ packages/react-simulator-renderer/src/renderer.ts | 2 ++ 3 files changed, 12 insertions(+) diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index 8befb0433..e4cfc4c96 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -190,6 +190,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost(() => this.componentsAsset); this.injectionConsumer = new ResourceConsumer(() => { return { + appHelper: engineConfig.get('appHelper'), i18n: this.project.i18n, }; }); diff --git a/packages/editor-core/src/config.ts b/packages/editor-core/src/config.ts index f18e21575..ecb76afb4 100644 --- a/packages/editor-core/src/config.ts +++ b/packages/editor-core/src/config.ts @@ -208,6 +208,15 @@ export interface EngineOptions { // 是否开启在 render 阶段开启 filter reducer,默认值:false enableFilterReducerInRenderStage?: boolean; }; + /** + * 与 react-renderer 的 appHelper 一致, https://lowcode-engine.cn/docV2/nhilce#appHelper + */ + appHelper?: { + /** 全局公共函数 */ + utils?: Record; + /** 全局常量 */ + constants?: Record; + }; requestHandlersMap: RequestHandlersMap; } diff --git a/packages/react-simulator-renderer/src/renderer.ts b/packages/react-simulator-renderer/src/renderer.ts index 4c34f25d0..6c246e094 100644 --- a/packages/react-simulator-renderer/src/renderer.ts +++ b/packages/react-simulator-renderer/src/renderer.ts @@ -25,6 +25,7 @@ import { createMemoryHistory, MemoryHistory } from 'history'; import Slot from './builtin-components/slot'; import Leaf from './builtin-components/leaf'; import { withQueryParams, parseQuery } from './utils/url'; +import { merge } from 'lodash'; const loader = new AssetLoader(); configure({ enforceActions: 'never' }); @@ -308,6 +309,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer { ...this._appContext, }; newCtx.utils.i18n.messages = data.i18n || {}; + merge(newCtx, data.appHelper || {}); this._appContext = newCtx; }); }