Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd08918

Browse files
committed
feat: id source list
feat: datasource plugin support sql input feat: sync manual feat(listView): allow listView stay inside listView feat: mv file comp
1 parent 92f83e9 commit bd08918

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+555
-319
lines changed

client/packages/openblocks-core/lib/index.cjs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,23 +1049,24 @@ var loglevel = {exports: {}};
10491049

10501050
var log = loglevel.exports;
10511051

1052-
// global variables black list, forbidden to use
1053-
var blacklist = new Set([
1052+
// global variables black list, forbidden to use in for jsQuery/jsAction
1053+
var functionBlacklist = new Set([
10541054
"top",
10551055
"parent",
10561056
"document",
10571057
"location",
10581058
"chrome",
1059-
"setTimeout",
10601059
"fetch",
1061-
"setInterval",
1062-
"clearInterval",
1063-
"setImmediate",
10641060
"XMLHttpRequest",
10651061
"importScripts",
10661062
"Navigator",
10671063
"MutationObserver",
10681064
]);
1065+
var expressionBlacklist = new Set(__spreadArray(__spreadArray([], Array.from(functionBlacklist.values()), true), [
1066+
"setTimeout",
1067+
"setInterval",
1068+
"setImmediate",
1069+
], false));
10691070
var globalVarNames = new Set(["window", "globalThis", "self", "global"]);
10701071
function createBlackHole() {
10711072
return new Proxy(function () {
@@ -1087,12 +1088,14 @@ function createBlackHole() {
10871088
},
10881089
});
10891090
}
1090-
function createMockWindow() {
1091-
var win = new Proxy({}, {
1091+
function createMockWindow(base, blacklist) {
1092+
if (blacklist === void 0) { blacklist = expressionBlacklist; }
1093+
var win = new Proxy(Object.assign({}, base), {
10921094
has: function () {
10931095
return true;
10941096
},
10951097
set: function (target, p, newValue) {
1098+
console.info("set:", p, newValue);
10961099
return Reflect.set(target, p, newValue);
10971100
},
10981101
get: function (target, p) {
@@ -1102,19 +1105,11 @@ function createMockWindow() {
11021105
if (globalVarNames.has(p)) {
11031106
return win;
11041107
}
1105-
if (typeof p === "string" && blacklist.has(p)) {
1108+
if (typeof p === "string" && (blacklist === null || blacklist === void 0 ? void 0 : blacklist.has(p))) {
11061109
log.log("[Sandbox] access ".concat(String(p), " on mock window, return mock object"));
11071110
return createBlackHole();
11081111
}
1109-
var ret = Reflect.get(window, p);
1110-
if (typeof ret === "function" && !ret.prototype) {
1111-
return ret.bind(window);
1112-
}
1113-
// get DOM element by id, serializing may cause error
1114-
if (isDomElement(ret)) {
1115-
return undefined;
1116-
}
1117-
return ret;
1112+
return getPropertyFromNativeWindow(p);
11181113
},
11191114
});
11201115
return win;
@@ -1126,12 +1121,26 @@ function clearMockWindow() {
11261121
function isDomElement(obj) {
11271122
return obj instanceof Element || obj instanceof HTMLCollection;
11281123
}
1124+
function getPropertyFromNativeWindow(prop) {
1125+
var ret = Reflect.get(window, prop);
1126+
if (typeof ret === "function" && !ret.prototype) {
1127+
return ret.bind(window);
1128+
}
1129+
// get DOM element by id, serializing may cause error
1130+
if (isDomElement(ret)) {
1131+
return undefined;
1132+
}
1133+
return ret;
1134+
}
11291135
function proxySandbox(context, methods, options) {
1130-
var _a = (options || {}).disableLimit, disableLimit = _a === void 0 ? false : _a;
1136+
var _a = options || {}, _b = _a.disableLimit, disableLimit = _b === void 0 ? false : _b, _c = _a.scope, scope = _c === void 0 ? "expression" : _c;
11311137
var isProtectedVar = function (key) {
11321138
return key in context || key in (methods || {}) || globalVarNames.has(key);
11331139
};
11341140
var cache = {};
1141+
if (scope === "function") {
1142+
mockWindow = createMockWindow(mockWindow, functionBlacklist);
1143+
}
11351144
return new Proxy(mockWindow, {
11361145
has: function (target, p) {
11371146
// proxy all variables
@@ -1163,7 +1172,7 @@ function proxySandbox(context, methods, options) {
11631172
return value;
11641173
}
11651174
if (disableLimit) {
1166-
return Reflect.get(window, p);
1175+
return getPropertyFromNativeWindow(p);
11671176
}
11681177
return Reflect.get(target, p, receiver);
11691178
},
@@ -1503,11 +1512,12 @@ var RelaxedJsonParser = /** @class */ (function (_super) {
15031512
}(DefaultParser));
15041513
function evalFunction(unevaledValue, context, methods, isAsync) {
15051514
try {
1506-
return new ValueAndMsg(function (args, runInHost) {
1515+
return new ValueAndMsg(function (args, runInHost, scope) {
15071516
if (runInHost === void 0) { runInHost = false; }
1517+
if (scope === void 0) { scope = "function"; }
15081518
return evalFunc(unevaledValue.startsWith("return")
15091519
? unevaledValue + "\n"
1510-
: "return ".concat(isAsync ? "async " : "", "function(){'use strict'; ").concat(unevaledValue, "\n}()"), args ? __assign(__assign({}, context), args) : context, methods, { disableLimit: runInHost }, isAsync);
1520+
: "return ".concat(isAsync ? "async " : "", "function(){'use strict'; ").concat(unevaledValue, "\n}()"), args ? __assign(__assign({}, context), args) : context, methods, { disableLimit: runInHost, scope: scope }, isAsync);
15111521
});
15121522
}
15131523
catch (err) {
@@ -7558,6 +7568,7 @@ exports.evalFunc = evalFunc;
75587568
exports.evalFunctionResult = evalFunctionResult;
75597569
exports.evalNodeOrMinor = evalNodeOrMinor;
75607570
exports.evalPerfUtil = evalPerfUtil;
7571+
exports.evalScript = evalScript;
75617572
exports.evalStyle = evalStyle;
75627573
exports.executeQueryAction = executeQueryAction;
75637574
exports.fromRecord = fromRecord;

client/packages/openblocks-core/lib/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,18 @@ declare function isDynamicSegment(segment: string): boolean;
347347
declare function getDynamicStringSegments(input: string): string[];
348348

349349
declare function clearMockWindow(): void;
350+
declare type SandboxScope = "function" | "expression";
350351
interface SandBoxOption {
351352
/**
352353
* disable all limit, like running in host
353354
*/
354355
disableLimit?: boolean;
356+
/**
357+
* the scope this sandbox works in, which will use different blacklist
358+
*/
359+
scope?: SandboxScope;
355360
}
361+
declare function evalScript(script: string, context: any, methods?: EvalMethods): any;
356362
declare function evalFunc(
357363
functionBody: string,
358364
context: any,
@@ -851,6 +857,7 @@ export {
851857
evalFunctionResult,
852858
evalNodeOrMinor,
853859
evalPerfUtil,
860+
evalScript,
854861
evalStyle,
855862
executeQueryAction,
856863
fromRecord,

client/packages/openblocks-core/lib/index.js

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,23 +1041,24 @@ var loglevel = {exports: {}};
10411041

10421042
var log = loglevel.exports;
10431043

1044-
// global variables black list, forbidden to use
1045-
var blacklist = new Set([
1044+
// global variables black list, forbidden to use in for jsQuery/jsAction
1045+
var functionBlacklist = new Set([
10461046
"top",
10471047
"parent",
10481048
"document",
10491049
"location",
10501050
"chrome",
1051-
"setTimeout",
10521051
"fetch",
1053-
"setInterval",
1054-
"clearInterval",
1055-
"setImmediate",
10561052
"XMLHttpRequest",
10571053
"importScripts",
10581054
"Navigator",
10591055
"MutationObserver",
10601056
]);
1057+
var expressionBlacklist = new Set(__spreadArray(__spreadArray([], Array.from(functionBlacklist.values()), true), [
1058+
"setTimeout",
1059+
"setInterval",
1060+
"setImmediate",
1061+
], false));
10611062
var globalVarNames = new Set(["window", "globalThis", "self", "global"]);
10621063
function createBlackHole() {
10631064
return new Proxy(function () {
@@ -1079,12 +1080,14 @@ function createBlackHole() {
10791080
},
10801081
});
10811082
}
1082-
function createMockWindow() {
1083-
var win = new Proxy({}, {
1083+
function createMockWindow(base, blacklist) {
1084+
if (blacklist === void 0) { blacklist = expressionBlacklist; }
1085+
var win = new Proxy(Object.assign({}, base), {
10841086
has: function () {
10851087
return true;
10861088
},
10871089
set: function (target, p, newValue) {
1090+
console.info("set:", p, newValue);
10881091
return Reflect.set(target, p, newValue);
10891092
},
10901093
get: function (target, p) {
@@ -1094,19 +1097,11 @@ function createMockWindow() {
10941097
if (globalVarNames.has(p)) {
10951098
return win;
10961099
}
1097-
if (typeof p === "string" && blacklist.has(p)) {
1100+
if (typeof p === "string" && (blacklist === null || blacklist === void 0 ? void 0 : blacklist.has(p))) {
10981101
log.log("[Sandbox] access ".concat(String(p), " on mock window, return mock object"));
10991102
return createBlackHole();
11001103
}
1101-
var ret = Reflect.get(window, p);
1102-
if (typeof ret === "function" && !ret.prototype) {
1103-
return ret.bind(window);
1104-
}
1105-
// get DOM element by id, serializing may cause error
1106-
if (isDomElement(ret)) {
1107-
return undefined;
1108-
}
1109-
return ret;
1104+
return getPropertyFromNativeWindow(p);
11101105
},
11111106
});
11121107
return win;
@@ -1118,12 +1113,26 @@ function clearMockWindow() {
11181113
function isDomElement(obj) {
11191114
return obj instanceof Element || obj instanceof HTMLCollection;
11201115
}
1116+
function getPropertyFromNativeWindow(prop) {
1117+
var ret = Reflect.get(window, prop);
1118+
if (typeof ret === "function" && !ret.prototype) {
1119+
return ret.bind(window);
1120+
}
1121+
// get DOM element by id, serializing may cause error
1122+
if (isDomElement(ret)) {
1123+
return undefined;
1124+
}
1125+
return ret;
1126+
}
11211127
function proxySandbox(context, methods, options) {
1122-
var _a = (options || {}).disableLimit, disableLimit = _a === void 0 ? false : _a;
1128+
var _a = options || {}, _b = _a.disableLimit, disableLimit = _b === void 0 ? false : _b, _c = _a.scope, scope = _c === void 0 ? "expression" : _c;
11231129
var isProtectedVar = function (key) {
11241130
return key in context || key in (methods || {}) || globalVarNames.has(key);
11251131
};
11261132
var cache = {};
1133+
if (scope === "function") {
1134+
mockWindow = createMockWindow(mockWindow, functionBlacklist);
1135+
}
11271136
return new Proxy(mockWindow, {
11281137
has: function (target, p) {
11291138
// proxy all variables
@@ -1155,7 +1164,7 @@ function proxySandbox(context, methods, options) {
11551164
return value;
11561165
}
11571166
if (disableLimit) {
1158-
return Reflect.get(window, p);
1167+
return getPropertyFromNativeWindow(p);
11591168
}
11601169
return Reflect.get(target, p, receiver);
11611170
},
@@ -1495,11 +1504,12 @@ var RelaxedJsonParser = /** @class */ (function (_super) {
14951504
}(DefaultParser));
14961505
function evalFunction(unevaledValue, context, methods, isAsync) {
14971506
try {
1498-
return new ValueAndMsg(function (args, runInHost) {
1507+
return new ValueAndMsg(function (args, runInHost, scope) {
14991508
if (runInHost === void 0) { runInHost = false; }
1509+
if (scope === void 0) { scope = "function"; }
15001510
return evalFunc(unevaledValue.startsWith("return")
15011511
? unevaledValue + "\n"
1502-
: "return ".concat(isAsync ? "async " : "", "function(){'use strict'; ").concat(unevaledValue, "\n}()"), args ? __assign(__assign({}, context), args) : context, methods, { disableLimit: runInHost }, isAsync);
1512+
: "return ".concat(isAsync ? "async " : "", "function(){'use strict'; ").concat(unevaledValue, "\n}()"), args ? __assign(__assign({}, context), args) : context, methods, { disableLimit: runInHost, scope: scope }, isAsync);
15031513
});
15041514
}
15051515
catch (err) {
@@ -7521,4 +7531,4 @@ function getI18nObjects(fileData, filterLocales) {
75217531
return getDataByLocale(fileData, "Obj", filterLocales).data;
75227532
}
75237533

7524-
export { AbstractComp, AbstractNode, CachedNode, CodeNode, CompActionTypes, FetchCheckNode, FunctionNode, MultiBaseComp, RecordNode, SimpleAbstractComp, SimpleComp, SimpleNode, Translator, ValueAndMsg, WrapContextNodeV2, WrapNode, addChildAction, changeChildAction, changeDependName, changeValueAction, clearMockWindow, clearStyleEval, customAction, deferAction, deleteCompAction, dependingNodeMapEquals, evalFunc, evalFunctionResult, evalNodeOrMinor, evalPerfUtil, evalStyle, executeQueryAction, fromRecord, fromUnevaledValue, fromValue, fromValueWithCache, getDynamicStringSegments, getI18nObjects, getValueByLocale, i18n, isBroadcastAction, isChildAction, isCustomAction, isDynamicSegment, isFetching, isMyCustomAction, mergeExtra, multiChangeAction, nodeIsRecord, onlyEvalAction, relaxedJSONToJSON, renameAction, replaceCompAction, routeByNameAction, transformWrapper, triggerModuleEventAction, unwrapChildAction, updateActionContextAction, updateNodesV2Action, withFunction, wrapActionExtraInfo, wrapChildAction, wrapContext, wrapDispatch };
7534+
export { AbstractComp, AbstractNode, CachedNode, CodeNode, CompActionTypes, FetchCheckNode, FunctionNode, MultiBaseComp, RecordNode, SimpleAbstractComp, SimpleComp, SimpleNode, Translator, ValueAndMsg, WrapContextNodeV2, WrapNode, addChildAction, changeChildAction, changeDependName, changeValueAction, clearMockWindow, clearStyleEval, customAction, deferAction, deleteCompAction, dependingNodeMapEquals, evalFunc, evalFunctionResult, evalNodeOrMinor, evalPerfUtil, evalScript, evalStyle, executeQueryAction, fromRecord, fromUnevaledValue, fromValue, fromValueWithCache, getDynamicStringSegments, getI18nObjects, getValueByLocale, i18n, isBroadcastAction, isChildAction, isCustomAction, isDynamicSegment, isFetching, isMyCustomAction, mergeExtra, multiChangeAction, nodeIsRecord, onlyEvalAction, relaxedJSONToJSON, renameAction, replaceCompAction, routeByNameAction, transformWrapper, triggerModuleEventAction, unwrapChildAction, updateActionContextAction, updateNodesV2Action, withFunction, wrapActionExtraInfo, wrapChildAction, wrapContext, wrapDispatch };

client/packages/openblocks-core/src/eval/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type { EvalMethods, CodeType, CodeFunction } from "./types/evalTypes";
1515
export { ValueAndMsg } from "./types/valueAndMsg";
1616
export { relaxedJSONToJSON } from "./utils/relaxedJson";
1717
export { getDynamicStringSegments, isDynamicSegment } from "./utils/segmentUtils";
18-
export { clearMockWindow, evalFunc } from "./utils/evalScript";
18+
export { clearMockWindow, evalFunc, evalScript } from "./utils/evalScript";
1919
export { clearStyleEval, evalStyle } from "./utils/evalStyle";
2020
export { evalFunctionResult } from "./utils/string2Fn";
2121
export { nodeIsRecord } from "./utils/nodeUtils";

client/packages/openblocks-core/src/eval/utils/evalScript.test.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ test("evalFunc", () => {
66
expect(() =>
77
evalFunc("setTimeout(() => {});", {}, undefined, { disableLimit: true })
88
).not.toThrow();
9-
expect(evalFunc("return window.setTimeout", {}, {})).not.toBe(window.setTimeout);
10-
expect(evalFunc("return window.setTimeout", {}, {}, { disableLimit: true })).toBe(
9+
expect(evalFunc("console.info(window.fetch);return window.fetch;", {}, {})).not.toBe(
10+
window.fetch
11+
);
12+
expect(evalFunc("return window.fetch", {}, {}, { disableLimit: true })).toBe(window.fetch);
13+
expect(evalFunc("return window.seTimeout", {}, {}, { scope: "expression" })).not.toBe(
14+
window.setTimeout
15+
);
16+
expect(evalFunc("return window.setTimeout", {}, {}, { scope: "function" })).toBe(
1117
window.setTimeout
1218
);
1319
});
@@ -112,10 +118,6 @@ describe("evalScript", () => {
112118
});
113119

114120
it("setPrototypeOf", () => {
115-
// expect(() => evalScript("Object.setPrototypeOf(this, {})", {})).toThrow();
116-
// expect(() => evalScript("Object.setPrototypeOf(window, {})", {})).toThrow();
117-
expect(() => evalScript("Object.setPrototypeOf(setTimeout, {})", {})).toThrow();
118-
119121
let context = { input1: { value: { test: 7 } } };
120122
expect(() => evalScript("Object.setPrototypeOf(input1, {})", context)).toThrow();
121123
expect(() => evalScript("Object.setPrototypeOf(input1.value, {})", context)).toThrow();
@@ -127,6 +129,9 @@ describe("evalScript", () => {
127129
expect(evalScript("window.crypto", {})).not.toBeUndefined();
128130
expect(evalScript("this.crypto", {})).not.toBeUndefined();
129131
expect(evalScript("crypto", {})).not.toBeUndefined();
132+
133+
evalFunc("window.a = 1;", {});
134+
expect(evalScript("window.a", {})).toBe(1);
130135
});
131136

132137
it("black hole is everything", () => {

0 commit comments

Comments
 (0)