mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
fix:引用funcparse包
This commit is contained in:
parent
aaf9ed70a3
commit
b7ec2f0e24
@ -40,7 +40,8 @@
|
||||
"@alife/theme-lowcode-dark": "^0.1.0",
|
||||
"@alife/theme-lowcode-light": "^0.1.0",
|
||||
"react": "^16.8.1",
|
||||
"react-dom": "^16.8.1"
|
||||
"react-dom": "^16.8.1",
|
||||
"@ali/vu-function-parser": "^2.5.0-beta.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ali/iceluna-cli": "^0.0.16",
|
||||
|
||||
@ -1,114 +0,0 @@
|
||||
function getWrappedFunction(func: any, sourceCode: any) {
|
||||
const result = function (...args) {
|
||||
try {
|
||||
return func.apply(this, args);
|
||||
} catch (e) {
|
||||
const message = `项目代码执行出错(非引擎内部错误)!非生产环境可以通过在 URL 上加入 ?debug_all 来打开调试模式。更多请点击这里:https://ur.alipay.com/2JbYP
|
||||
--------------------------------------------------------
|
||||
错误信息:${e.message}
|
||||
${sourceCode ? `以下是原始函数:
|
||||
--------------------------------------------------------
|
||||
${sourceCode}
|
||||
--------------------------------------------------------` : ''}
|
||||
点击下方函数的可以进入并调试方法:
|
||||
--------------------------------------------------------
|
||||
`;
|
||||
console.error(message, func);
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
const USE_STRICT = /^(["'])use strict\1;?/i;
|
||||
|
||||
/**
|
||||
* parse a function string into Function object, isolateWindow (if any) will be used
|
||||
* as the window object instead of global window
|
||||
*
|
||||
* @param {String} func function string need parse
|
||||
* @param {Object} isolateWindow the isolateWindow used when running the action
|
||||
*/
|
||||
export default function (func: any, isolateWindow: any, ctx: any) {
|
||||
let sourceCode = func;
|
||||
|
||||
// 兼容 ES6 方案,即 funcString 为对象的情况
|
||||
// if (typeof func === 'object' && func !== null) {
|
||||
// if (func.id) {
|
||||
// let action;
|
||||
// if (window.VisualEngineUtils) {
|
||||
// action = window.VisualEngineUtils.ActionUtil.getAction(func.id, { func: true });
|
||||
// } else if (window.LeGao && window.LeGao.getContext) {
|
||||
// const _ctx = ctx || window.LeGao.getContext();
|
||||
// action = _ctx.getAction().actionsMap[func.id];
|
||||
// }
|
||||
|
||||
// if (!action) {
|
||||
// const result = () => {
|
||||
// console.error(`无法找到 ${func.id} 函数`);
|
||||
// };
|
||||
// return result;
|
||||
// }
|
||||
// return getWrappedFunction(action.func);
|
||||
// }
|
||||
// sourceCode = func.source;
|
||||
// func = func.compiled || func.source || '';
|
||||
// }
|
||||
|
||||
if (!func) {
|
||||
const result = () => {
|
||||
window.location.search.indexOf('dev') >= 0 && console.log('解析的函数为空');
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
if (typeof func === 'function') {
|
||||
// TODO: un-annotate these code after vision-render-service done
|
||||
// if (isolateWindow) {
|
||||
// return func(isolateWindow);
|
||||
// }
|
||||
return func;
|
||||
}
|
||||
|
||||
let code = '';
|
||||
if (func.indexOf('var __preParser__') >= 0 && func.indexOf('function') !== 0) {
|
||||
code = `
|
||||
${func}
|
||||
if (typeof __preParser__ === 'function') {
|
||||
return __preParser__.apply(this, Array.prototype.slice.call(arguments));
|
||||
}
|
||||
console.warn('code must be a string of function');
|
||||
`;
|
||||
} else {
|
||||
code = `
|
||||
var __preParser__ = ${func.replace(USE_STRICT, '')};
|
||||
if (typeof __preParser__ === 'function') {
|
||||
return __preParser__.apply(this, Array.prototype.slice.call(arguments));
|
||||
}
|
||||
console.warn('code must be a string of function');
|
||||
`;
|
||||
}
|
||||
|
||||
try {
|
||||
if (isolateWindow) {
|
||||
code = `
|
||||
return function() {
|
||||
${code}
|
||||
}
|
||||
`;
|
||||
func = new Function('window', code)(isolateWindow);
|
||||
} else {
|
||||
func = new Function(code);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(
|
||||
'解析 function 字符串失败,请检查字符串的合法性',
|
||||
e.message,
|
||||
`\n${sourceCode}`,
|
||||
);
|
||||
func = function () {
|
||||
console.error('代码配置有误,请检查相关配置');
|
||||
};
|
||||
}
|
||||
|
||||
return getWrappedFunction(func, sourceCode);
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable */
|
||||
import { createElement } from 'react';
|
||||
import { Button } from '@alifd/next';
|
||||
import Engine, { Panes } from '@ali/visualengine';
|
||||
import Engine, { Panes, Prototype } from '@ali/visualengine';
|
||||
import { ActionUtil as actionUtil } from '@ali/visualengine-utils';
|
||||
import getTrunkPane from '@ali/ve-trunk-pane';
|
||||
import DatapoolPane from '@ali/ve-datapool-pane';
|
||||
@ -18,10 +18,8 @@ import { upgradeAssetsBundle } from './upgrade-assets';
|
||||
import { isCSSUrl } from '@ali/lowcode-utils';
|
||||
import { I18nSetter } from '@ali/visualengine-utils';
|
||||
import VariableSetter from '@ali/vs-variable-setter';
|
||||
// import { isObject, isArray } from 'lodash';
|
||||
// import funcParser from '@ali/vu-function-parser';
|
||||
// import funcParser from './funcParser';
|
||||
// import Prototype from '../../../vision-preset/src/index';
|
||||
import { isObject, isArray } from 'lodash';
|
||||
import funcParser from '@ali/vu-function-parser';
|
||||
|
||||
|
||||
const { editor, skeleton, context, HOOKS, Trunk } = Engine;
|
||||
@ -329,31 +327,30 @@ function initActionPane() {
|
||||
props,
|
||||
});
|
||||
}
|
||||
// const replaceFuncProp = (props) => {
|
||||
// const replaceProps = {};
|
||||
function replaceFuncProp(props?: any){
|
||||
const replaceProps = {};
|
||||
for (const name in props) {
|
||||
const prop = props[name];
|
||||
if (!prop) {
|
||||
continue;
|
||||
}
|
||||
if ((prop.compiled && prop.source) || prop.type === 'actionRef' || prop.type === 'js') {
|
||||
replaceProps[name] = funcParser(prop);
|
||||
} else if (isObject(prop)) {
|
||||
replaceFuncProp(prop);
|
||||
} else if (isArray(prop)) {
|
||||
prop.map((propItem) => {
|
||||
replaceFuncProp(propItem);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// for (const name in props) {
|
||||
// const prop = props[name];
|
||||
// if (!prop) {
|
||||
// continue;
|
||||
// }
|
||||
// if ((prop.compiled && prop.source) || prop.type === 'actionRef' || prop.type === 'js') {
|
||||
// replaceProps[name] = funcParser(prop);
|
||||
// } else if (isObject(prop)) {
|
||||
// replaceFuncProp(prop);
|
||||
// } else if (isArray(prop)) {
|
||||
// prop.map((propItem) => {
|
||||
// replaceFuncProp(propItem);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
for (const name in replaceProps) {
|
||||
props[name] = replaceProps[name];
|
||||
}
|
||||
|
||||
// for (const name in replaceProps) {
|
||||
// props[name] = replaceProps[name];
|
||||
// }
|
||||
|
||||
// return props;
|
||||
// };
|
||||
return props;
|
||||
};
|
||||
|
||||
// 操作历史与页面历史面板
|
||||
function initHistoryPane() {
|
||||
@ -418,6 +415,7 @@ async function init() {
|
||||
subview: true,
|
||||
i18nPane: true,
|
||||
});
|
||||
Prototype.addGlobalPropsReducer(replaceFuncProp);
|
||||
await loadAssets();
|
||||
await loadSchema();
|
||||
await initTrunkPane();
|
||||
@ -425,10 +423,6 @@ async function init() {
|
||||
initI18nPane();
|
||||
initActionPane();
|
||||
initDemoPanes();
|
||||
// console.log(funcParser,'funcParser')
|
||||
// debugger
|
||||
// Prototype.addGlobalPropsReducer(replaceFuncProp);
|
||||
// debugger
|
||||
initHistoryPane();
|
||||
Engine.init();
|
||||
}
|
||||
|
||||
2
packages/demo/src/vision/module.d.ts
vendored
2
packages/demo/src/vision/module.d.ts
vendored
@ -9,4 +9,4 @@ declare module '@ali/ve-page-history';
|
||||
declare module '@ali/ve-i18n-manage-pane';
|
||||
declare module '@ali/ve-action-pane';
|
||||
declare module '@ali/vu-legao-design-fetch-context';
|
||||
// declare module "@ali/vu-function-parser";
|
||||
declare module "@ali/vu-function-parser";
|
||||
|
||||
@ -84,16 +84,6 @@ class Renderer extends Component<{ renderer: SimulatorRenderer }> {
|
||||
const { __id, __desingMode, ...viewProps } = props;
|
||||
viewProps.componentId = __id;
|
||||
viewProps._leaf = host.document.getNode(__id);
|
||||
if (Component.displayName === 'Calendar') {
|
||||
// debugger
|
||||
const testProps = {
|
||||
// defaultDate: undefined,
|
||||
// dateCellRender:(date: any)=>{return date.date();}
|
||||
// onSelect:(value:any)=>{console.log(value,'test')}
|
||||
// defaultMonth: undefined,
|
||||
};
|
||||
Object.assign(viewProps, testProps);
|
||||
}
|
||||
return createElement(
|
||||
Component,
|
||||
viewProps,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user