@nocobase/flow-engine 2.0.0-alpha.65 → 2.0.0-alpha.67
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.
- package/lib/JSRunner.d.ts +6 -0
- package/lib/JSRunner.js +2 -1
- package/lib/components/settings/wrappers/component/SwitchWithTitle.js +2 -1
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +11 -3
- package/lib/flowContext.d.ts +2 -1
- package/lib/flowContext.js +21 -43
- package/lib/flowSettings.js +12 -10
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -0
- package/lib/models/CollectionFieldModel.d.ts +1 -0
- package/lib/models/CollectionFieldModel.js +3 -2
- package/lib/runjs-context/contexts/base.js +10 -4
- package/lib/runjsLibs.d.ts +15 -0
- package/lib/runjsLibs.js +223 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +5 -0
- package/lib/utils/params-resolvers.js +16 -9
- package/lib/utils/runjsTemplateCompat.d.ts +35 -0
- package/lib/utils/runjsTemplateCompat.js +743 -0
- package/lib/views/createViewMeta.d.ts +0 -7
- package/lib/views/createViewMeta.js +19 -70
- package/lib/views/index.d.ts +1 -2
- package/lib/views/index.js +4 -3
- package/lib/views/useDialog.js +0 -1
- package/lib/views/useDrawer.js +0 -1
- package/lib/views/usePage.d.ts +4 -0
- package/lib/views/usePage.js +33 -5
- package/lib/views/usePopover.js +4 -1
- package/package.json +4 -4
- package/src/JSRunner.ts +8 -1
- package/src/__tests__/createViewMeta.popup.test.ts +62 -1
- package/src/__tests__/flowSettings.open.test.tsx +69 -15
- package/src/__tests__/runjsLibsLazyLoading.test.ts +44 -0
- package/src/__tests__/runjsPreprocessDefault.test.ts +49 -0
- package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +2 -1
- package/src/components/settings/wrappers/component/__tests__/InlineControls.test.tsx +74 -0
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +11 -3
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +63 -4
- package/src/flowContext.ts +30 -54
- package/src/flowSettings.ts +12 -11
- package/src/index.ts +2 -0
- package/src/models/CollectionFieldModel.tsx +3 -1
- package/src/runjs-context/contexts/base.ts +9 -2
- package/src/runjsLibs.ts +218 -0
- package/src/utils/__tests__/params-resolvers.test.ts +40 -0
- package/src/utils/__tests__/runjsTemplateCompat.test.ts +159 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/params-resolvers.ts +23 -9
- package/src/utils/runjsTemplateCompat.ts +828 -0
- package/src/views/__tests__/FlowView.usePage.test.tsx +54 -1
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +0 -4
- package/src/views/createViewMeta.ts +22 -75
- package/src/views/index.tsx +1 -2
- package/src/views/useDialog.tsx +0 -1
- package/src/views/useDrawer.tsx +0 -1
- package/src/views/usePage.tsx +38 -5
- package/src/views/usePopover.tsx +4 -1
package/lib/JSRunner.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export interface JSRunnerOptions {
|
|
|
11
11
|
timeoutMs?: number;
|
|
12
12
|
globals?: Record<string, any>;
|
|
13
13
|
version?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Enable RunJS template compatibility preprocessing for `{{ ... }}`.
|
|
16
|
+
* When enabled via `ctx.runjs(code, vars, { preprocessTemplates: true })` (default),
|
|
17
|
+
* the code will be rewritten to call `ctx.resolveJsonTemplate(...)` at runtime.
|
|
18
|
+
*/
|
|
19
|
+
preprocessTemplates?: boolean;
|
|
14
20
|
}
|
|
15
21
|
export declare class JSRunner {
|
|
16
22
|
private globals;
|
package/lib/JSRunner.js
CHANGED
|
@@ -62,7 +62,8 @@ const _JSRunner = class _JSRunner {
|
|
|
62
62
|
* 异步运行代码,带错误处理和超时机制
|
|
63
63
|
*/
|
|
64
64
|
async run(code) {
|
|
65
|
-
|
|
65
|
+
const search = typeof location !== "undefined" ? location.search : void 0;
|
|
66
|
+
if (typeof search === "string" && search.includes("skipRunJs=true")) {
|
|
66
67
|
return { success: true, value: null };
|
|
67
68
|
}
|
|
68
69
|
const wrapped = `(async () => {
|
|
@@ -73,7 +73,8 @@ const SwitchWithTitle = (0, import_reactive.observer)(
|
|
|
73
73
|
setChecked(val);
|
|
74
74
|
onChange == null ? void 0 : onChange({ [itemKey]: val });
|
|
75
75
|
}, "handleChange");
|
|
76
|
-
const handleWrapperClick = /* @__PURE__ */ __name(() => {
|
|
76
|
+
const handleWrapperClick = /* @__PURE__ */ __name((e) => {
|
|
77
|
+
e.stopPropagation();
|
|
77
78
|
if (disabled) return;
|
|
78
79
|
handleChange(!checked);
|
|
79
80
|
}, "handleWrapperClick");
|
|
@@ -153,6 +153,9 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
153
153
|
const [visible, setVisible] = (0, import_react.useState)(false);
|
|
154
154
|
const [refreshTick, setRefreshTick] = (0, import_react.useState)(0);
|
|
155
155
|
const [extraMenuItems, setExtraMenuItems] = (0, import_react.useState)([]);
|
|
156
|
+
const closeDropdown = (0, import_react.useCallback)(() => {
|
|
157
|
+
setVisible(false);
|
|
158
|
+
}, []);
|
|
156
159
|
const handleOpenChange = (0, import_react.useCallback)((nextOpen, info) => {
|
|
157
160
|
if (info.source === "trigger" || nextOpen) {
|
|
158
161
|
(0, import_react.startTransition)(() => {
|
|
@@ -249,6 +252,7 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
249
252
|
[model, copyUidToClipboard]
|
|
250
253
|
);
|
|
251
254
|
const handleDelete = (0, import_react.useCallback)(() => {
|
|
255
|
+
closeDropdown();
|
|
252
256
|
import_antd.Modal.confirm({
|
|
253
257
|
title: t("Confirm delete"),
|
|
254
258
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons.ExclamationCircleOutlined, null),
|
|
@@ -269,7 +273,7 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
269
273
|
}
|
|
270
274
|
}
|
|
271
275
|
});
|
|
272
|
-
}, [model]);
|
|
276
|
+
}, [closeDropdown, model, t]);
|
|
273
277
|
const handleStepConfiguration = (0, import_react.useCallback)(
|
|
274
278
|
(key) => {
|
|
275
279
|
const keyParts = key.split(":");
|
|
@@ -294,6 +298,7 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
294
298
|
[flowKey, stepKey] = keyParts;
|
|
295
299
|
}
|
|
296
300
|
try {
|
|
301
|
+
closeDropdown();
|
|
297
302
|
targetModel.openFlowSettings({
|
|
298
303
|
flowKey,
|
|
299
304
|
stepKey
|
|
@@ -302,23 +307,26 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
302
307
|
console.log(t("Configuration popup cancelled or error"), ":", error);
|
|
303
308
|
}
|
|
304
309
|
},
|
|
305
|
-
[model]
|
|
310
|
+
[closeDropdown, model, t]
|
|
306
311
|
);
|
|
307
312
|
const handleMenuClick = (0, import_react.useCallback)(
|
|
308
313
|
({ key }) => {
|
|
309
314
|
const originalKey = key;
|
|
310
315
|
const cleanKey = key.includes("-") && /^(.+)-\d+$/.test(key) ? key.replace(/-\d+$/, "") : key;
|
|
311
316
|
if (cleanKey.startsWith("copy-pop-uid:")) {
|
|
317
|
+
closeDropdown();
|
|
312
318
|
handleCopyPopupUid(cleanKey);
|
|
313
319
|
return;
|
|
314
320
|
}
|
|
315
321
|
const extra = extraMenuItems.find((it) => (it == null ? void 0 : it.key) === originalKey || (it == null ? void 0 : it.key) === cleanKey);
|
|
316
322
|
if (extra == null ? void 0 : extra.onClick) {
|
|
323
|
+
closeDropdown();
|
|
317
324
|
extra.onClick();
|
|
318
325
|
return;
|
|
319
326
|
}
|
|
320
327
|
switch (cleanKey) {
|
|
321
328
|
case "copy-uid":
|
|
329
|
+
closeDropdown();
|
|
322
330
|
handleCopyUid();
|
|
323
331
|
break;
|
|
324
332
|
case "delete":
|
|
@@ -329,7 +337,7 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
329
337
|
break;
|
|
330
338
|
}
|
|
331
339
|
},
|
|
332
|
-
[handleCopyUid, handleDelete, handleStepConfiguration, handleCopyPopupUid, extraMenuItems]
|
|
340
|
+
[closeDropdown, handleCopyUid, handleDelete, handleStepConfiguration, handleCopyPopupUid, extraMenuItems]
|
|
333
341
|
);
|
|
334
342
|
const getModelConfigurableFlowsAndSteps = (0, import_react.useCallback)(
|
|
335
343
|
async (targetModel, modelKey) => {
|
package/lib/flowContext.d.ts
CHANGED
|
@@ -147,7 +147,7 @@ declare class BaseFlowEngineContext extends FlowContext {
|
|
|
147
147
|
dataSourceManager: DataSourceManager;
|
|
148
148
|
requireAsync: (url: string) => Promise<any>;
|
|
149
149
|
importAsync: (url: string) => Promise<any>;
|
|
150
|
-
createJSRunner: (options?: JSRunnerOptions) => JSRunner
|
|
150
|
+
createJSRunner: (options?: JSRunnerOptions) => Promise<JSRunner>;
|
|
151
151
|
pageInfo: {
|
|
152
152
|
version?: 'v1' | 'v2';
|
|
153
153
|
};
|
|
@@ -172,6 +172,7 @@ declare class BaseFlowEngineContext extends FlowContext {
|
|
|
172
172
|
location: Location;
|
|
173
173
|
sql: FlowSQLRepository;
|
|
174
174
|
logger: pino.Logger;
|
|
175
|
+
constructor();
|
|
175
176
|
}
|
|
176
177
|
declare class BaseFlowModelContext extends BaseFlowEngineContext {
|
|
177
178
|
model: FlowModel;
|
package/lib/flowContext.js
CHANGED
|
@@ -57,7 +57,6 @@ __export(flowContext_exports, {
|
|
|
57
57
|
module.exports = __toCommonJS(flowContext_exports);
|
|
58
58
|
var import_reactive = require("@formily/reactive");
|
|
59
59
|
var antd = __toESM(require("antd"));
|
|
60
|
-
var antdIcons = __toESM(require("@ant-design/icons"));
|
|
61
60
|
var import_lodash = __toESM(require("lodash"));
|
|
62
61
|
var import_qs = __toESM(require("qs"));
|
|
63
62
|
var import_react = __toESM(require("react"));
|
|
@@ -78,6 +77,7 @@ var import_variablesParams = require("./utils/variablesParams");
|
|
|
78
77
|
var import_registry = require("./runjs-context/registry");
|
|
79
78
|
var import_createEphemeralContext = require("./utils/createEphemeralContext");
|
|
80
79
|
var import_dayjs = __toESM(require("dayjs"));
|
|
80
|
+
var import_runjsLibs = require("./runjsLibs");
|
|
81
81
|
var _proxy, _FlowContext_instances, createChildNodes_fn, findMetaByPath_fn, findMetaInDelegatesDeep_fn, findMetaInProperty_fn, resolvePathInMeta_fn, resolvePathInMetaAsync_fn, buildParentTitles_fn, toTreeNode_fn;
|
|
82
82
|
function isRecordRefLike(val) {
|
|
83
83
|
return !!(val && typeof val === "object" && "collection" in val && "filterByTk" in val);
|
|
@@ -715,6 +715,23 @@ toTreeNode_fn = /* @__PURE__ */ __name(function(name, metaOrFactory, paths = [na
|
|
|
715
715
|
__name(_FlowContext, "FlowContext");
|
|
716
716
|
let FlowContext = _FlowContext;
|
|
717
717
|
const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext {
|
|
718
|
+
constructor() {
|
|
719
|
+
super();
|
|
720
|
+
this.defineMethod(
|
|
721
|
+
"runjs",
|
|
722
|
+
async function(code, variables, options) {
|
|
723
|
+
const { preprocessTemplates, ...runnerOptions } = options || {};
|
|
724
|
+
const mergedGlobals = { ...(runnerOptions == null ? void 0 : runnerOptions.globals) || {}, ...variables || {} };
|
|
725
|
+
const runner = await this.createJSRunner({
|
|
726
|
+
...runnerOptions || {},
|
|
727
|
+
globals: mergedGlobals
|
|
728
|
+
});
|
|
729
|
+
const shouldPreprocessTemplates = preprocessTemplates !== false;
|
|
730
|
+
const jsCode = await (0, import_utils.prepareRunJsCode)(String(code ?? ""), { preprocessTemplates: shouldPreprocessTemplates });
|
|
731
|
+
return runner.run(jsCode);
|
|
732
|
+
}
|
|
733
|
+
);
|
|
734
|
+
}
|
|
718
735
|
};
|
|
719
736
|
__name(_BaseFlowEngineContext, "BaseFlowEngineContext");
|
|
720
737
|
let BaseFlowEngineContext = _BaseFlowEngineContext;
|
|
@@ -751,14 +768,6 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
751
768
|
this.defineMethod("t", (keyOrTemplate, options) => {
|
|
752
769
|
return i18n.translate(keyOrTemplate, options);
|
|
753
770
|
});
|
|
754
|
-
this.defineMethod("runjs", async (code, variables, options) => {
|
|
755
|
-
const mergedGlobals = { ...(options == null ? void 0 : options.globals) || {}, ...variables || {} };
|
|
756
|
-
const runner = await this.createJSRunner({
|
|
757
|
-
...options || {},
|
|
758
|
-
globals: mergedGlobals
|
|
759
|
-
});
|
|
760
|
-
return runner.run(code);
|
|
761
|
-
});
|
|
762
771
|
this.defineMethod("renderJson", function(template) {
|
|
763
772
|
return this.resolveJsonTemplate(template);
|
|
764
773
|
});
|
|
@@ -1061,11 +1070,8 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
1061
1070
|
}
|
|
1062
1071
|
const version = (options == null ? void 0 : options.version) || "v1";
|
|
1063
1072
|
const modelClass = (0, import_registry.getModelClassName)(this);
|
|
1064
|
-
const Ctor = import_registry.RunJSContextRegistry.resolve(version, modelClass) ||
|
|
1065
|
-
|
|
1066
|
-
if (Ctor) {
|
|
1067
|
-
runCtx = new Ctor(this);
|
|
1068
|
-
}
|
|
1073
|
+
const Ctor = import_registry.RunJSContextRegistry.resolve(version, modelClass) || FlowRunJSContext;
|
|
1074
|
+
const runCtx = new Ctor(this);
|
|
1069
1075
|
const globals = { ctx: runCtx, ...(options == null ? void 0 : options.globals) || {} };
|
|
1070
1076
|
const { timeoutMs } = options || {};
|
|
1071
1077
|
return new import_JSRunner.JSRunner({ globals, timeoutMs });
|
|
@@ -1142,13 +1148,6 @@ const _FlowModelContext = class _FlowModelContext extends BaseFlowModelContext {
|
|
|
1142
1148
|
this.defineMethod("onRefReady", (ref, cb, timeout) => {
|
|
1143
1149
|
this.engine.reactView.onRefReady(ref, cb, timeout);
|
|
1144
1150
|
});
|
|
1145
|
-
this.defineMethod("runjs", async (code, variables, options) => {
|
|
1146
|
-
const runner = await this.createJSRunner({
|
|
1147
|
-
globals: variables,
|
|
1148
|
-
version: options == null ? void 0 : options.version
|
|
1149
|
-
});
|
|
1150
|
-
return runner.run(code);
|
|
1151
|
-
});
|
|
1152
1151
|
this.defineProperty("model", {
|
|
1153
1152
|
value: model
|
|
1154
1153
|
});
|
|
@@ -1280,13 +1279,6 @@ const _FlowForkModelContext = class _FlowForkModelContext extends BaseFlowModelC
|
|
|
1280
1279
|
return stableRef;
|
|
1281
1280
|
}, "get")
|
|
1282
1281
|
});
|
|
1283
|
-
this.defineMethod("runjs", async (code, variables, options) => {
|
|
1284
|
-
const runner = await this.createJSRunner({
|
|
1285
|
-
globals: variables,
|
|
1286
|
-
version: options == null ? void 0 : options.version
|
|
1287
|
-
});
|
|
1288
|
-
return runner.run(code);
|
|
1289
|
-
});
|
|
1290
1282
|
}
|
|
1291
1283
|
};
|
|
1292
1284
|
__name(_FlowForkModelContext, "FlowForkModelContext");
|
|
@@ -1331,13 +1323,6 @@ const _FlowRuntimeContext = class _FlowRuntimeContext extends BaseFlowModelConte
|
|
|
1331
1323
|
this.defineMethod("onRefReady", (ref, cb, timeout) => {
|
|
1332
1324
|
this.engine.reactView.onRefReady(ref, cb, timeout);
|
|
1333
1325
|
});
|
|
1334
|
-
this.defineMethod("runjs", async (code, variables, options) => {
|
|
1335
|
-
const runner = await this.createJSRunner({
|
|
1336
|
-
globals: variables,
|
|
1337
|
-
version: options == null ? void 0 : options.version
|
|
1338
|
-
});
|
|
1339
|
-
return runner.run(code);
|
|
1340
|
-
});
|
|
1341
1326
|
}
|
|
1342
1327
|
stepResults = {};
|
|
1343
1328
|
_getOwnProperty(key) {
|
|
@@ -1405,14 +1390,7 @@ const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
|
|
|
1405
1390
|
}, "createRoot")
|
|
1406
1391
|
};
|
|
1407
1392
|
this.defineProperty("ReactDOM", { value: ReactDOMShim });
|
|
1408
|
-
|
|
1409
|
-
React: import_react.default,
|
|
1410
|
-
ReactDOM: ReactDOMShim,
|
|
1411
|
-
antd,
|
|
1412
|
-
dayjs: import_dayjs.default,
|
|
1413
|
-
antdIcons
|
|
1414
|
-
});
|
|
1415
|
-
this.defineProperty("libs", { value: libs });
|
|
1393
|
+
(0, import_runjsLibs.setupRunJSLibs)(this);
|
|
1416
1394
|
this.defineMethod(
|
|
1417
1395
|
"render",
|
|
1418
1396
|
function(vnode, container) {
|
package/lib/flowSettings.js
CHANGED
|
@@ -63,6 +63,7 @@ var import__ = require(".");
|
|
|
63
63
|
var import_useFlowSettingsContext = require("./hooks/useFlowSettingsContext");
|
|
64
64
|
var import_utils = require("./utils");
|
|
65
65
|
var import_useFlowStep = require("./hooks/useFlowStep");
|
|
66
|
+
var import_views = require("./views");
|
|
66
67
|
var _forceEnabled, _emitter;
|
|
67
68
|
const Panel = import_antd.Collapse.Panel;
|
|
68
69
|
const _FlowSettings = class _FlowSettings {
|
|
@@ -536,12 +537,9 @@ const _FlowSettings = class _FlowSettings {
|
|
|
536
537
|
};
|
|
537
538
|
let modeProps = typeof resolvedUiMode === "object" && resolvedUiMode ? resolvedUiMode.props || {} : {};
|
|
538
539
|
if (modeType === "embed") {
|
|
539
|
-
const target = document.querySelector(
|
|
540
|
+
const target = document.querySelector(`#${import_views.GLOBAL_EMBED_CONTAINER_ID}`);
|
|
540
541
|
const onOpen = modeProps.onOpen;
|
|
541
542
|
const onClose = modeProps.onClose;
|
|
542
|
-
if (target) {
|
|
543
|
-
target.innerHTML = "";
|
|
544
|
-
}
|
|
545
543
|
modeProps = {
|
|
546
544
|
target,
|
|
547
545
|
styles: {
|
|
@@ -551,15 +549,19 @@ const _FlowSettings = class _FlowSettings {
|
|
|
551
549
|
},
|
|
552
550
|
...modeProps,
|
|
553
551
|
onOpen() {
|
|
554
|
-
target
|
|
555
|
-
|
|
556
|
-
|
|
552
|
+
if (target) {
|
|
553
|
+
target.style.width = modeProps.width || "33.3%";
|
|
554
|
+
target.style.maxWidth = modeProps.maxWidth || "800px";
|
|
555
|
+
target.style.minWidth = modeProps.minWidth || "0px";
|
|
556
|
+
}
|
|
557
557
|
onOpen == null ? void 0 : onOpen();
|
|
558
558
|
},
|
|
559
559
|
onClose() {
|
|
560
|
-
target.
|
|
561
|
-
|
|
562
|
-
|
|
560
|
+
if (target && target.dataset[import_views.EMBED_REPLACING_DATA_KEY] !== "1") {
|
|
561
|
+
target.style.width = "auto";
|
|
562
|
+
target.style.maxWidth = "none";
|
|
563
|
+
target.style.minWidth = "auto";
|
|
564
|
+
}
|
|
563
565
|
onClose == null ? void 0 : onClose();
|
|
564
566
|
}
|
|
565
567
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
export * from './types';
|
|
10
10
|
export * from './utils';
|
|
11
11
|
export { compileRunJs } from './utils/jsxTransform';
|
|
12
|
+
export { registerRunJSLib } from './runjsLibs';
|
|
13
|
+
export type { RunJSLibCache, RunJSLibLoader } from './runjsLibs';
|
|
12
14
|
export * from './resources';
|
|
13
15
|
export * from './flowEngine';
|
|
14
16
|
export * from './hooks';
|
package/lib/index.js
CHANGED
|
@@ -38,12 +38,14 @@ __export(src_exports, {
|
|
|
38
38
|
getRunJSScenesForModel: () => import_helpers.getRunJSScenesForModel,
|
|
39
39
|
getSnippetBody: () => import_snippets.getSnippetBody,
|
|
40
40
|
listSnippetsForContext: () => import_snippets.listSnippetsForContext,
|
|
41
|
+
registerRunJSLib: () => import_runjsLibs.registerRunJSLib,
|
|
41
42
|
setupRunJSContexts: () => import_setup.setupRunJSContexts
|
|
42
43
|
});
|
|
43
44
|
module.exports = __toCommonJS(src_exports);
|
|
44
45
|
__reExport(src_exports, require("./types"), module.exports);
|
|
45
46
|
__reExport(src_exports, require("./utils"), module.exports);
|
|
46
47
|
var import_jsxTransform = require("./utils/jsxTransform");
|
|
48
|
+
var import_runjsLibs = require("./runjsLibs");
|
|
47
49
|
__reExport(src_exports, require("./resources"), module.exports);
|
|
48
50
|
__reExport(src_exports, require("./flowEngine"), module.exports);
|
|
49
51
|
__reExport(src_exports, require("./hooks"), module.exports);
|
|
@@ -78,6 +80,7 @@ var import_BlockScopedFlowEngine = require("./BlockScopedFlowEngine");
|
|
|
78
80
|
getRunJSScenesForModel,
|
|
79
81
|
getSnippetBody,
|
|
80
82
|
listSnippetsForContext,
|
|
83
|
+
registerRunJSLib,
|
|
81
84
|
setupRunJSContexts,
|
|
82
85
|
...require("./types"),
|
|
83
86
|
...require("./utils"),
|
|
@@ -45,6 +45,7 @@ export declare class CollectionFieldModel<T extends DefaultStructure = DefaultSt
|
|
|
45
45
|
}): BindingOptions | null;
|
|
46
46
|
static bindModelToInterface(modelName: string, interfaceName: string | string[], options?: {
|
|
47
47
|
isDefault?: boolean;
|
|
48
|
+
order?: number;
|
|
48
49
|
defaultProps?: object | ((ctx: FlowEngineContext, fieldInstance: CollectionField) => object);
|
|
49
50
|
when?: (ctx: FlowEngineContext, fieldInstance: CollectionField) => boolean;
|
|
50
51
|
}): void;
|
|
@@ -182,7 +182,7 @@ const _CollectionFieldModel = class _CollectionFieldModel extends import_flowMod
|
|
|
182
182
|
if (!this.bindings.has(interfaceName)) {
|
|
183
183
|
return [];
|
|
184
184
|
}
|
|
185
|
-
const bindings = this.bindings.get(interfaceName);
|
|
185
|
+
const bindings = this.bindings.get(interfaceName).sort((a, b) => a.order - b.order);
|
|
186
186
|
return bindings.filter(
|
|
187
187
|
(binding) => ctx.engine.getModelClass(binding.modelName) && binding.when(ctx, collectionField)
|
|
188
188
|
);
|
|
@@ -245,7 +245,8 @@ const _CollectionFieldModel = class _CollectionFieldModel extends import_flowMod
|
|
|
245
245
|
modelName,
|
|
246
246
|
isDefault: options.isDefault || false,
|
|
247
247
|
defaultProps: options.defaultProps || null,
|
|
248
|
-
when: options.when || defaultWhen
|
|
248
|
+
when: options.when || defaultWhen,
|
|
249
|
+
order: options.order
|
|
249
250
|
});
|
|
250
251
|
this.currentBindings.set(interfaceName, bindings);
|
|
251
252
|
}
|
|
@@ -67,14 +67,17 @@ function defineBaseContextMeta() {
|
|
|
67
67
|
ReactDOM: "ReactDOM client API including createRoot for rendering React components. Also available via `ctx.libs.ReactDOM`.",
|
|
68
68
|
antd: "Ant Design component library. Recommended access path: `ctx.libs.antd`.",
|
|
69
69
|
libs: {
|
|
70
|
-
description: "Namespace for third-party and shared libraries. Includes React, ReactDOM, Ant Design, and
|
|
70
|
+
description: "Namespace for third-party and shared libraries. Includes React, ReactDOM, Ant Design, dayjs, lodash, math.js, and formula.js.",
|
|
71
71
|
detail: "Libraries namespace",
|
|
72
72
|
properties: {
|
|
73
73
|
React: "React namespace (same as ctx.React).",
|
|
74
74
|
ReactDOM: "ReactDOM client API (same as ctx.ReactDOM).",
|
|
75
75
|
antd: "Ant Design component library (same as ctx.antd).",
|
|
76
76
|
dayjs: "dayjs date-time utility library.",
|
|
77
|
-
antdIcons: "Ant Design icons library. Example: `ctx.libs.antdIcons.PlusOutlined`."
|
|
77
|
+
antdIcons: "Ant Design icons library. Example: `ctx.libs.antdIcons.PlusOutlined`.",
|
|
78
|
+
lodash: 'Lodash utility library. Example: `ctx.libs.lodash.get(obj, "a.b.c")`.',
|
|
79
|
+
math: 'Math.js library for mathematical operations. Example: `ctx.libs.math.evaluate("2 + 3 * 4")`.',
|
|
80
|
+
formula: "Formula.js library for spreadsheet-like formulas. Example: `ctx.libs.formula.SUM([1, 2, 3])`."
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
},
|
|
@@ -156,14 +159,17 @@ function defineBaseContextMeta() {
|
|
|
156
159
|
ReactDOM: "ReactDOM \u5BA2\u6237\u7AEF API\uFF0C\u542B createRoot \u7B49\u6E32\u67D3\u65B9\u6CD5\u3002\u63A8\u8350\u901A\u8FC7 `ctx.libs.ReactDOM` \u8BBF\u95EE\u3002",
|
|
157
160
|
antd: "Ant Design \u7EC4\u4EF6\u5E93\uFF08RunJS \u73AF\u5883\u4E2D\u53EF\u7528\uFF09\u3002\u63A8\u8350\u4F7F\u7528 `ctx.libs.antd` \u8BBF\u95EE\u3002",
|
|
158
161
|
libs: {
|
|
159
|
-
description: "\u7B2C\u4E09\u65B9/\u901A\u7528\u5E93\u7684\u7EDF\u4E00\u547D\u540D\u7A7A\u95F4\uFF0C\u5305\u542B React\u3001ReactDOM\u3001Ant Design\u3001dayjs \u7B49\u3002\u540E\u7EED\u65B0\u589E\u5E93\u4F1A\u4F18\u5148\u6302\u5728\u6B64\u5904\u3002",
|
|
162
|
+
description: "\u7B2C\u4E09\u65B9/\u901A\u7528\u5E93\u7684\u7EDF\u4E00\u547D\u540D\u7A7A\u95F4\uFF0C\u5305\u542B React\u3001ReactDOM\u3001Ant Design\u3001dayjs\u3001lodash\u3001math.js\u3001formula.js \u7B49\u3002\u540E\u7EED\u65B0\u589E\u5E93\u4F1A\u4F18\u5148\u6302\u5728\u6B64\u5904\u3002",
|
|
160
163
|
detail: "\u901A\u7528\u5E93\u547D\u540D\u7A7A\u95F4",
|
|
161
164
|
properties: {
|
|
162
165
|
React: "React \u547D\u540D\u7A7A\u95F4\uFF08\u7B49\u4EF7\u4E8E ctx.React\uFF09\u3002",
|
|
163
166
|
ReactDOM: "ReactDOM \u5BA2\u6237\u7AEF API\uFF08\u7B49\u4EF7\u4E8E ctx.ReactDOM\uFF09\u3002",
|
|
164
167
|
antd: "Ant Design \u7EC4\u4EF6\u5E93\uFF08\u7B49\u4EF7\u4E8E ctx.antd\uFF09\u3002",
|
|
165
168
|
dayjs: "dayjs \u65E5\u671F\u65F6\u95F4\u5DE5\u5177\u5E93\u3002",
|
|
166
|
-
antdIcons: "Ant Design \u56FE\u6807\u5E93\u3002 \u4F8B\u5982\uFF1A`ctx.libs.antdIcons.PlusOutlined`\u3002"
|
|
169
|
+
antdIcons: "Ant Design \u56FE\u6807\u5E93\u3002 \u4F8B\u5982\uFF1A`ctx.libs.antdIcons.PlusOutlined`\u3002",
|
|
170
|
+
lodash: 'Lodash \u5DE5\u5177\u5E93\u3002\u4F8B\u5982\uFF1A`ctx.libs.lodash.get(obj, "a.b.c")`\u3002',
|
|
171
|
+
math: 'Math.js \u6570\u5B66\u8FD0\u7B97\u5E93\u3002\u4F8B\u5982\uFF1A`ctx.libs.math.evaluate("2 + 3 * 4")`\u3002',
|
|
172
|
+
formula: "Formula.js \u7535\u5B50\u8868\u683C\u516C\u5F0F\u5E93\u3002\u4F8B\u5982\uFF1A`ctx.libs.formula.SUM([1, 2, 3])`\u3002"
|
|
167
173
|
}
|
|
168
174
|
}
|
|
169
175
|
},
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import type { FlowContext } from './flowContext';
|
|
10
|
+
export type RunJSLibCache = 'global' | 'context';
|
|
11
|
+
export type RunJSLibLoader<T = any> = (ctx: FlowContext) => T | Promise<T>;
|
|
12
|
+
export declare function registerRunJSLib(name: string, loader: RunJSLibLoader, options?: {
|
|
13
|
+
cache?: RunJSLibCache;
|
|
14
|
+
}): void;
|
|
15
|
+
export declare function setupRunJSLibs(ctx: FlowContext): void;
|
package/lib/runjsLibs.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var runjsLibs_exports = {};
|
|
39
|
+
__export(runjsLibs_exports, {
|
|
40
|
+
registerRunJSLib: () => registerRunJSLib,
|
|
41
|
+
setupRunJSLibs: () => setupRunJSLibs
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(runjsLibs_exports);
|
|
44
|
+
var antdIcons = __toESM(require("@ant-design/icons"));
|
|
45
|
+
const __runjsLibRegistry = /* @__PURE__ */ new Map();
|
|
46
|
+
const __runjsLibResolvedCache = /* @__PURE__ */ new Map();
|
|
47
|
+
const __runjsLibPendingCache = /* @__PURE__ */ new Map();
|
|
48
|
+
const __runjsLibPendingByCtx = /* @__PURE__ */ new WeakMap();
|
|
49
|
+
function __runjsGetPendingMapForCtx(ctx) {
|
|
50
|
+
let m = __runjsLibPendingByCtx.get(ctx);
|
|
51
|
+
if (!m) {
|
|
52
|
+
m = /* @__PURE__ */ new Map();
|
|
53
|
+
__runjsLibPendingByCtx.set(ctx, m);
|
|
54
|
+
}
|
|
55
|
+
return m;
|
|
56
|
+
}
|
|
57
|
+
__name(__runjsGetPendingMapForCtx, "__runjsGetPendingMapForCtx");
|
|
58
|
+
function registerRunJSLib(name, loader, options) {
|
|
59
|
+
if (typeof name !== "string" || !name) return;
|
|
60
|
+
if (typeof loader !== "function") return;
|
|
61
|
+
__runjsLibRegistry.set(name, { loader, cache: (options == null ? void 0 : options.cache) || "global" });
|
|
62
|
+
__runjsLibResolvedCache.delete(name);
|
|
63
|
+
__runjsLibPendingCache.delete(name);
|
|
64
|
+
}
|
|
65
|
+
__name(registerRunJSLib, "registerRunJSLib");
|
|
66
|
+
function __runjsIsObject(val) {
|
|
67
|
+
return !!val && typeof val === "object";
|
|
68
|
+
}
|
|
69
|
+
__name(__runjsIsObject, "__runjsIsObject");
|
|
70
|
+
function __runjsHasOwn(obj, key) {
|
|
71
|
+
return __runjsIsObject(obj) && Object.prototype.hasOwnProperty.call(obj, key);
|
|
72
|
+
}
|
|
73
|
+
__name(__runjsHasOwn, "__runjsHasOwn");
|
|
74
|
+
function __runjsIsPromiseLike(val) {
|
|
75
|
+
if (!__runjsIsObject(val)) return false;
|
|
76
|
+
const then = val.then;
|
|
77
|
+
return typeof then === "function";
|
|
78
|
+
}
|
|
79
|
+
__name(__runjsIsPromiseLike, "__runjsIsPromiseLike");
|
|
80
|
+
function __runjsGetCtxValue(ctx, key) {
|
|
81
|
+
return ctx[key];
|
|
82
|
+
}
|
|
83
|
+
__name(__runjsGetCtxValue, "__runjsGetCtxValue");
|
|
84
|
+
async function __runjsEnsureLib(ctx, name) {
|
|
85
|
+
const libs = ctx == null ? void 0 : ctx.libs;
|
|
86
|
+
if (__runjsHasOwn(libs, name)) {
|
|
87
|
+
const existing = libs[name];
|
|
88
|
+
if (typeof existing !== "undefined") return existing;
|
|
89
|
+
}
|
|
90
|
+
const entry = __runjsLibRegistry.get(name);
|
|
91
|
+
if (!entry) return __runjsIsObject(libs) ? libs[name] : void 0;
|
|
92
|
+
const setLib = /* @__PURE__ */ __name((v2) => {
|
|
93
|
+
if (__runjsIsObject(libs)) libs[name] = v2;
|
|
94
|
+
}, "setLib");
|
|
95
|
+
if (entry.cache === "context") {
|
|
96
|
+
const pendingMap = __runjsGetPendingMapForCtx(ctx);
|
|
97
|
+
const existingPending2 = pendingMap.get(name);
|
|
98
|
+
if (existingPending2) {
|
|
99
|
+
const v3 = await existingPending2;
|
|
100
|
+
setLib(v3);
|
|
101
|
+
return v3;
|
|
102
|
+
}
|
|
103
|
+
const task2 = Promise.resolve().then(() => entry.loader(ctx)).then(
|
|
104
|
+
(v3) => {
|
|
105
|
+
pendingMap.delete(name);
|
|
106
|
+
return v3;
|
|
107
|
+
},
|
|
108
|
+
(err) => {
|
|
109
|
+
pendingMap.delete(name);
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
pendingMap.set(name, task2);
|
|
114
|
+
const v2 = await task2;
|
|
115
|
+
setLib(v2);
|
|
116
|
+
return v2;
|
|
117
|
+
}
|
|
118
|
+
if (__runjsLibResolvedCache.has(name)) {
|
|
119
|
+
const v2 = __runjsLibResolvedCache.get(name);
|
|
120
|
+
setLib(v2);
|
|
121
|
+
return v2;
|
|
122
|
+
}
|
|
123
|
+
const existingPending = __runjsLibPendingCache.get(name);
|
|
124
|
+
if (existingPending) {
|
|
125
|
+
const v2 = await existingPending;
|
|
126
|
+
setLib(v2);
|
|
127
|
+
return v2;
|
|
128
|
+
}
|
|
129
|
+
const task = Promise.resolve().then(() => entry.loader(ctx)).then(
|
|
130
|
+
(v2) => {
|
|
131
|
+
__runjsLibResolvedCache.set(name, v2);
|
|
132
|
+
__runjsLibPendingCache.delete(name);
|
|
133
|
+
return v2;
|
|
134
|
+
},
|
|
135
|
+
(err) => {
|
|
136
|
+
__runjsLibPendingCache.delete(name);
|
|
137
|
+
throw err;
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
__runjsLibPendingCache.set(name, task);
|
|
141
|
+
const v = await task;
|
|
142
|
+
setLib(v);
|
|
143
|
+
return v;
|
|
144
|
+
}
|
|
145
|
+
__name(__runjsEnsureLib, "__runjsEnsureLib");
|
|
146
|
+
function setupRunJSLibAPIs(ctx) {
|
|
147
|
+
if (!ctx || typeof ctx !== "object") return;
|
|
148
|
+
if (typeof ctx.defineMethod !== "function") return;
|
|
149
|
+
ctx.defineMethod("__ensureLib", async function(name) {
|
|
150
|
+
if (typeof name !== "string" || !name) return void 0;
|
|
151
|
+
return await __runjsEnsureLib(this, name);
|
|
152
|
+
});
|
|
153
|
+
ctx.defineMethod("__ensureLibs", async function(names) {
|
|
154
|
+
if (!Array.isArray(names)) return;
|
|
155
|
+
for (const n of names) {
|
|
156
|
+
if (typeof n !== "string" || !n) continue;
|
|
157
|
+
await __runjsEnsureLib(this, n);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
__name(setupRunJSLibAPIs, "setupRunJSLibAPIs");
|
|
162
|
+
const DEFAULT_RUNJS_LIBS = [
|
|
163
|
+
{ name: "React", cache: "context", loader: /* @__PURE__ */ __name((ctx) => __runjsGetCtxValue(ctx, "React"), "loader") },
|
|
164
|
+
{ name: "ReactDOM", cache: "context", loader: /* @__PURE__ */ __name((ctx) => __runjsGetCtxValue(ctx, "ReactDOM"), "loader") },
|
|
165
|
+
{ name: "antd", cache: "context", loader: /* @__PURE__ */ __name((ctx) => __runjsGetCtxValue(ctx, "antd"), "loader") },
|
|
166
|
+
{ name: "dayjs", cache: "context", loader: /* @__PURE__ */ __name((ctx) => __runjsGetCtxValue(ctx, "dayjs"), "loader") },
|
|
167
|
+
{ name: "antdIcons", cache: "global", loader: /* @__PURE__ */ __name(() => antdIcons, "loader") },
|
|
168
|
+
{ name: "lodash", cache: "global", loader: /* @__PURE__ */ __name(() => import("lodash").then((m) => m.default || m), "loader") },
|
|
169
|
+
{ name: "formula", cache: "global", loader: /* @__PURE__ */ __name(() => import("@formulajs/formulajs").then((m) => m.default || m), "loader") },
|
|
170
|
+
{ name: "math", cache: "global", loader: /* @__PURE__ */ __name(() => import("mathjs").then((m) => m), "loader") }
|
|
171
|
+
];
|
|
172
|
+
let __defaultRunJSLibsRegistered = false;
|
|
173
|
+
function ensureDefaultRunJSLibsRegistered() {
|
|
174
|
+
if (__defaultRunJSLibsRegistered) return;
|
|
175
|
+
__defaultRunJSLibsRegistered = true;
|
|
176
|
+
for (const { name, loader, cache } of DEFAULT_RUNJS_LIBS) {
|
|
177
|
+
if (__runjsLibRegistry.has(name)) continue;
|
|
178
|
+
registerRunJSLib(name, loader, { cache });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
__name(ensureDefaultRunJSLibsRegistered, "ensureDefaultRunJSLibsRegistered");
|
|
182
|
+
function resolveRegisteredLibSync(ctx, name) {
|
|
183
|
+
const entry = __runjsLibRegistry.get(name);
|
|
184
|
+
if (!entry) return void 0;
|
|
185
|
+
if (entry.cache === "global" && __runjsLibResolvedCache.has(name)) {
|
|
186
|
+
return __runjsLibResolvedCache.get(name);
|
|
187
|
+
}
|
|
188
|
+
const v = entry.loader(ctx);
|
|
189
|
+
if (__runjsIsPromiseLike(v)) return void 0;
|
|
190
|
+
if (entry.cache === "global") __runjsLibResolvedCache.set(name, v);
|
|
191
|
+
return v;
|
|
192
|
+
}
|
|
193
|
+
__name(resolveRegisteredLibSync, "resolveRegisteredLibSync");
|
|
194
|
+
function setupRunJSLibs(ctx) {
|
|
195
|
+
if (!ctx || typeof ctx !== "object") return;
|
|
196
|
+
if (typeof ctx.defineProperty !== "function") return;
|
|
197
|
+
ensureDefaultRunJSLibsRegistered();
|
|
198
|
+
const libs = {};
|
|
199
|
+
for (const { name } of DEFAULT_RUNJS_LIBS) {
|
|
200
|
+
Object.defineProperty(libs, name, {
|
|
201
|
+
configurable: true,
|
|
202
|
+
enumerable: true,
|
|
203
|
+
get() {
|
|
204
|
+
const v = resolveRegisteredLibSync(ctx, name);
|
|
205
|
+
Object.defineProperty(libs, name, {
|
|
206
|
+
configurable: true,
|
|
207
|
+
enumerable: true,
|
|
208
|
+
writable: true,
|
|
209
|
+
value: v
|
|
210
|
+
});
|
|
211
|
+
return v;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
ctx.defineProperty("libs", { value: libs });
|
|
216
|
+
setupRunJSLibAPIs(ctx);
|
|
217
|
+
}
|
|
218
|
+
__name(setupRunJSLibs, "setupRunJSLibs");
|
|
219
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
220
|
+
0 && (module.exports = {
|
|
221
|
+
registerRunJSLib,
|
|
222
|
+
setupRunJSLibs
|
|
223
|
+
});
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { extractPropertyPath, formatPathToVariable, isVariableExpression } from
|
|
|
21
21
|
export { clearAutoFlowError, getAutoFlowError, setAutoFlowError, type AutoFlowError } from './autoFlowError';
|
|
22
22
|
export { parsePathnameToViewParams, type ViewParam } from './parsePathnameToViewParams';
|
|
23
23
|
export { createSafeDocument, createSafeWindow, createSafeNavigator } from './safeGlobals';
|
|
24
|
+
export { prepareRunJsCode, preprocessRunJsTemplates } from './runjsTemplateCompat';
|
|
24
25
|
export { createEphemeralContext } from './createEphemeralContext';
|
|
25
26
|
export { pruneFilter } from './pruneFilter';
|
|
26
27
|
export { isBeforeRenderFlow } from './flows';
|