Skip to content

Commit

Permalink
Merge pull request #280 from lvhuichao/develop
Browse files Browse the repository at this point in the history
PR 02.23
  • Loading branch information
neon-balcony authored Feb 24, 2023
2 parents 1264a8e + 9d60c64 commit b278eb0
Show file tree
Hide file tree
Showing 286 changed files with 5,564 additions and 2,433 deletions.
2 changes: 1 addition & 1 deletion client/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.5
1.1.6
4 changes: 3 additions & 1 deletion client/config/test/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const globals = {};
buildVars.forEach(({ name, defaultValue }) => {
globals[name] = process.env[name] || defaultValue;
});
const isEE = process.env.REACT_APP_EDITION === "enterprise";
const edition = process.env.REACT_APP_EDITION;
const isEEGlobal = edition === "enterprise-global";
const isEE = edition === "enterprise" || isEEGlobal;
const dirname = currentDirName(import.meta.url);

export default {
Expand Down
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"scripts": {
"start": "yarn workspace openblocks start",
"start:ee": "REACT_APP_EDITION=enterprise yarn workspace openblocks start",
"start:ee-global": "REACT_APP_EDITION=enterprise-global yarn workspace openblocks start",
"build": "yarn node ./scripts/build.js",
"test": "jest",
"prepare": "yarn workspace openblocks prepare",
Expand Down Expand Up @@ -71,6 +72,7 @@
"react-virtualized@^9.22.3": "patch:react-virtualized@npm%3A9.22.3#./.yarn/patches/react-virtualized-npm-9.22.3-0fff3cbf64.patch"
},
"dependencies": {
"antd-mobile": "^5.28.0",
"chalk": "4",
"number-precision": "^1.6.0",
"react-player": "^2.11.0",
Expand Down
122 changes: 63 additions & 59 deletions client/packages/openblocks-core/lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,49 +106,40 @@ function __spreadArray(to, from, pack) {
return to.concat(ar || Array.prototype.slice.call(from));
}

function getCache(obj, fnName) {
function isEqualArgs(args, cacheArgs, equals) {
if (!cacheArgs) {
return false;
}
if (args.length === 0 && cacheArgs.length === 0) {
return true;
}
return (args.length === cacheArgs.length &&
cacheArgs.every(function (arg, index) { var _a, _b; return (_b = (_a = equals === null || equals === void 0 ? void 0 : equals[index]) === null || _a === void 0 ? void 0 : _a.call(equals, arg, args[index])) !== null && _b !== void 0 ? _b : arg === args[index]; }));
}
function getCacheResult(thisObj, fnName, args, equals) {
var _a;
return (_a = obj === null || obj === void 0 ? void 0 : obj.__cache) === null || _a === void 0 ? void 0 : _a[fnName];
var cache = (_a = thisObj === null || thisObj === void 0 ? void 0 : thisObj.__cache) === null || _a === void 0 ? void 0 : _a[fnName];
if (cache && isEqualArgs(args, cache.args, equals)) {
return cache.result;
}
}
function createCache(obj, fnName, args) {
if (!obj.__cache) {
obj.__cache = {};
function cache(fn, args, thisObj, fnName, equals) {
var result = getCacheResult(thisObj, fnName, args, equals);
if (result) {
return result.value;
}
obj.__cache[fnName] = {
var cache = {
id: Symbol("id"),
args: args,
isInProgress: true,
time: Date.now(),
};
return getCache(obj, fnName);
}
function genCache(fn, args, thisObj, fnName) {
var cache = createCache(thisObj, fnName, args);
var value = fn.apply(thisObj, args);
cache.isInProgress = false;
cache.value = value;
}
function read(thisObj, fnName) {
var cache = getCache(thisObj, fnName);
return cache && cache.value;
}
function hitCache(args, thisObj, fnName, equals) {
var cache = getCache(thisObj, fnName);
if (!cache || !cache.args)
return false;
if (args.length === 0 && cache.args.length === 0)
return true;
return cache.args.every(function (arg, index) { var _a, _b; return (_b = (_a = equals === null || equals === void 0 ? void 0 : equals[index]) === null || _a === void 0 ? void 0 : _a.call(equals, arg, args[index])) !== null && _b !== void 0 ? _b : arg === args[index]; });
}
function isCyclic(thisObj, fnName) {
var cache = getCache(thisObj, fnName);
return cache && cache.isInProgress;
}
function cache(fn, args, thisObj, fnName, equals) {
if (!hitCache(args, thisObj, fnName, equals) && !isCyclic(thisObj, fnName)) {
genCache(fn, args, thisObj, fnName);
if (!thisObj.__cache) {
thisObj.__cache = {};
}
return read(thisObj, fnName);
thisObj.__cache[fnName] = cache;
var value = fn.apply(thisObj, args);
cache.result = { value: value };
return value;
}
function memoized(equals) {
return function (target, fnName, descriptor) {
Expand Down Expand Up @@ -1049,23 +1040,24 @@ var loglevel = {exports: {}};

var log = loglevel.exports;

// global variables black list, forbidden to use
var blacklist = new Set([
// global variables black list, forbidden to use in for jsQuery/jsAction
var functionBlacklist = new Set([
"top",
"parent",
"document",
"location",
"chrome",
"setTimeout",
"fetch",
"setInterval",
"clearInterval",
"setImmediate",
"XMLHttpRequest",
"importScripts",
"Navigator",
"MutationObserver",
]);
var expressionBlacklist = new Set(__spreadArray(__spreadArray([], Array.from(functionBlacklist.values()), true), [
"setTimeout",
"setInterval",
"setImmediate",
], false));
var globalVarNames = new Set(["window", "globalThis", "self", "global"]);
function createBlackHole() {
return new Proxy(function () {
Expand All @@ -1087,12 +1079,14 @@ function createBlackHole() {
},
});
}
function createMockWindow() {
var win = new Proxy({}, {
function createMockWindow(base, blacklist) {
if (blacklist === void 0) { blacklist = expressionBlacklist; }
var win = new Proxy(Object.assign({}, base), {
has: function () {
return true;
},
set: function (target, p, newValue) {
console.info("set:", p, newValue);
return Reflect.set(target, p, newValue);
},
get: function (target, p) {
Expand All @@ -1102,19 +1096,11 @@ function createMockWindow() {
if (globalVarNames.has(p)) {
return win;
}
if (typeof p === "string" && blacklist.has(p)) {
if (typeof p === "string" && (blacklist === null || blacklist === void 0 ? void 0 : blacklist.has(p))) {
log.log("[Sandbox] access ".concat(String(p), " on mock window, return mock object"));
return createBlackHole();
}
var ret = Reflect.get(window, p);
if (typeof ret === "function" && !ret.prototype) {
return ret.bind(window);
}
// get DOM element by id, serializing may cause error
if (isDomElement(ret)) {
return undefined;
}
return ret;
return getPropertyFromNativeWindow(p);
},
});
return win;
Expand All @@ -1126,12 +1112,26 @@ function clearMockWindow() {
function isDomElement(obj) {
return obj instanceof Element || obj instanceof HTMLCollection;
}
function getPropertyFromNativeWindow(prop) {
var ret = Reflect.get(window, prop);
if (typeof ret === "function" && !ret.prototype) {
return ret.bind(window);
}
// get DOM element by id, serializing may cause error
if (isDomElement(ret)) {
return undefined;
}
return ret;
}
function proxySandbox(context, methods, options) {
var _a = (options || {}).disableLimit, disableLimit = _a === void 0 ? false : _a;
var _a = options || {}, _b = _a.disableLimit, disableLimit = _b === void 0 ? false : _b, _c = _a.scope, scope = _c === void 0 ? "expression" : _c;
var isProtectedVar = function (key) {
return key in context || key in (methods || {}) || globalVarNames.has(key);
};
var cache = {};
if (scope === "function") {
mockWindow = createMockWindow(mockWindow, functionBlacklist);
}
return new Proxy(mockWindow, {
has: function (target, p) {
// proxy all variables
Expand Down Expand Up @@ -1163,7 +1163,7 @@ function proxySandbox(context, methods, options) {
return value;
}
if (disableLimit) {
return Reflect.get(window, p);
return getPropertyFromNativeWindow(p);
}
return Reflect.get(target, p, receiver);
},
Expand Down Expand Up @@ -1427,6 +1427,7 @@ var DefaultParser = /** @class */ (function () {
function evalJson(unevaledValue, context) {
return new RelaxedJsonParser(unevaledValue, context).parse();
}
// this will also be used in node-service
var RelaxedJsonParser = /** @class */ (function (_super) {
__extends(RelaxedJsonParser, _super);
function RelaxedJsonParser(unevaledValue, context) {
Expand Down Expand Up @@ -1503,11 +1504,12 @@ var RelaxedJsonParser = /** @class */ (function (_super) {
}(DefaultParser));
function evalFunction(unevaledValue, context, methods, isAsync) {
try {
return new ValueAndMsg(function (args, runInHost) {
return new ValueAndMsg(function (args, runInHost, scope) {
if (runInHost === void 0) { runInHost = false; }
if (scope === void 0) { scope = "function"; }
return evalFunc(unevaledValue.startsWith("return")
? unevaledValue + "\n"
: "return ".concat(isAsync ? "async " : "", "function(){'use strict'; ").concat(unevaledValue, "\n}()"), args ? __assign(__assign({}, context), args) : context, methods, { disableLimit: runInHost }, isAsync);
: "return ".concat(isAsync ? "async " : "", "function(){'use strict'; ").concat(unevaledValue, "\n}()"), args ? __assign(__assign({}, context), args) : context, methods, { disableLimit: runInHost, scope: scope }, isAsync);
});
}
catch (err) {
Expand Down Expand Up @@ -3209,8 +3211,8 @@ function updateNodesV2Action(value) {
value: value,
};
}
function wrapActionExtraInfo(action, extraCompInfos) {
return __assign(__assign({}, action), { extraInfo: { compInfos: extraCompInfos } });
function wrapActionExtraInfo(action, extraInfos) {
return __assign(__assign({}, action), { extraInfo: __assign(__assign({}, action.extraInfo), extraInfos) });
}
function deferAction(action) {
return __assign(__assign({}, action), { priority: "defer" });
Expand Down Expand Up @@ -7537,6 +7539,7 @@ exports.FetchCheckNode = FetchCheckNode;
exports.FunctionNode = FunctionNode;
exports.MultiBaseComp = MultiBaseComp;
exports.RecordNode = RecordNode;
exports.RelaxedJsonParser = RelaxedJsonParser;
exports.SimpleAbstractComp = SimpleAbstractComp;
exports.SimpleComp = SimpleComp;
exports.SimpleNode = SimpleNode;
Expand All @@ -7558,6 +7561,7 @@ exports.evalFunc = evalFunc;
exports.evalFunctionResult = evalFunctionResult;
exports.evalNodeOrMinor = evalNodeOrMinor;
exports.evalPerfUtil = evalPerfUtil;
exports.evalScript = evalScript;
exports.evalStyle = evalStyle;
exports.executeQueryAction = executeQueryAction;
exports.fromRecord = fromRecord;
Expand Down
Loading

0 comments on commit b278eb0

Please sign in to comment.