@chamn/engine 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { CNode, CPage, CProp, CRootNode, CSlot, isNodeModel } from '@chamn/model';
2
2
 
3
- export const getCloseNodeList = (node: CNode | CRootNode, level = 5) => {
3
+ export const getClosestNodeList = (node: CNode | CRootNode, level = 5) => {
4
4
  const res = [];
5
5
  let count = 0;
6
6
  let currentNode: CNode | CRootNode | CSlot | CProp | CPage | null = node;
@@ -5,7 +5,7 @@ import { CPluginCtx } from '../../core/pluginManager';
5
5
  import localize from './localize';
6
6
  import { PLUGIN_NAME } from './config';
7
7
  import { DefaultSelectToolBar } from './components/DefaultSelectToolBar';
8
- import { getCloseNodeList } from './util';
8
+ import { getClosestNodeList } from './util';
9
9
  import { GhostView } from './components/GhostView';
10
10
 
11
11
  import styles from './style.module.scss';
@@ -128,7 +128,7 @@ export class Designer extends React.Component<DesignerPropsType, DesignerStateTy
128
128
  const { pluginCtx } = this.props;
129
129
  pluginCtx.engine.updateCurrentSelectNode(node);
130
130
  const pageModel = this.props.pluginCtx.pageModel;
131
- const list = getCloseNodeList(node, 5);
131
+ const list = getClosestNodeList(node, 5);
132
132
  const { layoutRef } = this;
133
133
  this.setState({
134
134
  selectToolBar: (
@@ -200,13 +200,15 @@ export class Designer extends React.Component<DesignerPropsType, DesignerStateTy
200
200
  render() {
201
201
  const { layoutRef, props, onSelectNode, onDragStart, onHoverNode } = this;
202
202
  const { pageModel, hoverToolBar, selectToolBar, ghostView, assets } = this.state;
203
+ const { pluginCtx } = props;
204
+ const renderJSUrl = pluginCtx.engine.props.renderJSUrl || './render.umd.js';
203
205
  return (
204
206
  <Layout
205
207
  beforeInitRender={props.pluginCtx.config.beforeInitRender}
206
208
  customRender={props.pluginCtx.config.customRender}
207
209
  ref={layoutRef}
208
210
  pageModel={pageModel}
209
- renderScriptPath={'./render.umd.js'}
211
+ renderJSUrl={renderJSUrl}
210
212
  {...props}
211
213
  hoverToolBar={hoverToolBar}
212
214
  selectToolBar={selectToolBar}
@@ -0,0 +1,55 @@
1
+ import { LayoutPropsType, collectVariable, flatObject } from '@chamn/layout';
2
+
3
+ /** 默认使用 react 18 模式渲染 */
4
+ export const beforeInitRender: LayoutPropsType['beforeInitRender'] = async ({ iframe }) => {
5
+ const subWin = iframe.getWindow();
6
+ if (!subWin) {
7
+ return;
8
+ }
9
+ (subWin as any).React = window.React;
10
+ (subWin as any).ReactDOM = window.ReactDOM;
11
+ (subWin as any).ReactDOMClient = (window as any).ReactDOMClient;
12
+ };
13
+
14
+ /** 默认使用 react 18 模式渲染 */
15
+ export const defaultRender: LayoutPropsType['customRender'] = async ({
16
+ iframe: iframeContainer,
17
+ assets,
18
+ page,
19
+ pageModel,
20
+ ready,
21
+ renderJSUrl,
22
+ }) => {
23
+ await iframeContainer.injectJS(renderJSUrl || '');
24
+ const iframeWindow = iframeContainer.getWindow()!;
25
+ const iframeDoc = iframeContainer.getDocument()!;
26
+ const IframeReact = iframeWindow.React!;
27
+ const IframeReactDOM = iframeWindow.ReactDOMClient!;
28
+ const CRender = iframeWindow.CRender!;
29
+
30
+ // 注入组件物料资源
31
+ const assetLoader = new CRender.AssetLoader(assets, {
32
+ window: iframeContainer.getWindow()!,
33
+ });
34
+ assetLoader
35
+ .onSuccess(() => {
36
+ // 从子窗口获取物料对象
37
+ const componentCollection = collectVariable(assets, iframeWindow);
38
+ const components = flatObject(componentCollection);
39
+
40
+ const App = IframeReact?.createElement(CRender.DesignRender, {
41
+ adapter: CRender?.ReactAdapter,
42
+ page: page,
43
+ pageModel: pageModel,
44
+ components,
45
+ onMount: (designRenderInstance) => {
46
+ ready(designRenderInstance);
47
+ },
48
+ });
49
+ IframeReactDOM.createRoot(iframeDoc.getElementById('app')!).render(App);
50
+ })
51
+ .onError(() => {
52
+ console.log('资源加载出粗');
53
+ })
54
+ .load();
55
+ };