@nocobase/flow-engine 2.1.0-beta.1 → 2.1.0-beta.10
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/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/JSRunner.d.ts +10 -1
- package/lib/JSRunner.js +50 -5
- package/lib/ViewScopedFlowEngine.js +5 -1
- package/lib/components/dnd/gridDragPlanner.js +6 -2
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +16 -2
- package/lib/components/subModel/AddSubModelButton.js +15 -0
- package/lib/executor/FlowExecutor.js +31 -8
- package/lib/flowContext.js +4 -1
- package/lib/flowEngine.d.ts +19 -0
- package/lib/flowEngine.js +29 -1
- package/lib/runjs-context/registry.d.ts +1 -1
- package/lib/runjs-context/setup.js +19 -12
- package/lib/scheduler/ModelOperationScheduler.d.ts +5 -1
- package/lib/scheduler/ModelOperationScheduler.js +3 -2
- package/lib/types.d.ts +1 -1
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.js +4 -0
- package/lib/utils/parsePathnameToViewParams.js +1 -1
- package/lib/utils/schema-utils.d.ts +7 -1
- package/lib/utils/schema-utils.js +19 -0
- package/lib/views/FlowView.d.ts +7 -1
- package/lib/views/runViewBeforeClose.d.ts +10 -0
- package/lib/views/runViewBeforeClose.js +45 -0
- package/lib/views/useDialog.d.ts +2 -1
- package/lib/views/useDialog.js +20 -3
- package/lib/views/useDrawer.d.ts +2 -1
- package/lib/views/useDrawer.js +20 -3
- package/lib/views/usePage.d.ts +2 -1
- package/lib/views/usePage.js +10 -3
- package/package.json +5 -5
- package/src/JSRunner.ts +68 -4
- package/src/ViewScopedFlowEngine.ts +4 -0
- package/src/__tests__/JSRunner.test.ts +27 -1
- package/src/__tests__/runjsContext.test.ts +13 -0
- package/src/__tests__/runjsPreprocessDefault.test.ts +23 -0
- package/src/components/__tests__/gridDragPlanner.test.ts +88 -0
- package/src/components/dnd/gridDragPlanner.ts +8 -2
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +18 -2
- package/src/components/subModel/AddSubModelButton.tsx +16 -0
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +50 -0
- package/src/executor/FlowExecutor.ts +34 -9
- package/src/executor/__tests__/flowExecutor.test.ts +57 -0
- package/src/flowContext.ts +5 -3
- package/src/flowEngine.ts +33 -1
- package/src/models/__tests__/dispatchEvent.when.test.ts +214 -0
- package/src/runjs-context/registry.ts +1 -1
- package/src/runjs-context/setup.ts +21 -12
- package/src/scheduler/ModelOperationScheduler.ts +14 -3
- package/src/types.ts +1 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
- package/src/utils/__tests__/utils.test.ts +62 -0
- package/src/utils/index.ts +2 -1
- package/src/utils/parsePathnameToViewParams.ts +2 -2
- package/src/utils/schema-utils.ts +30 -1
- package/src/views/FlowView.tsx +11 -1
- package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +13 -12
- package/src/views/runViewBeforeClose.ts +19 -0
- package/src/views/useDialog.tsx +25 -3
- package/src/views/useDrawer.tsx +25 -3
- package/src/views/usePage.tsx +12 -3
package/README.md
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
# NocoBase
|
|
2
2
|
|
|
3
3
|
<video width="100%" controls>
|
|
4
|
-
|
|
4
|
+
<source src="https://github.com/user-attachments/assets/4d11a87b-00e2-48f3-9bf7-389d21072d13" type="video/mp4">
|
|
5
5
|
</video>
|
|
6
6
|
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://trendshift.io/repositories/4112" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4112" alt="nocobase%2Fnocobase | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
|
9
|
+
<a href="https://www.producthunt.com/posts/nocobase?embed=true&utm_source=badge-top-post-topic-badge&utm_medium=badge&utm_souce=badge-nocobase" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-topic-badge.svg?post_id=456520&theme=light&period=weekly&topic_id=267" alt="NocoBase - Scalability-first, open-source no-code platform | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
|
10
|
+
</p>
|
|
7
11
|
|
|
8
12
|
## What is NocoBase
|
|
9
13
|
|
|
10
|
-
NocoBase is
|
|
11
|
-
|
|
14
|
+
NocoBase is the most extensible AI-powered no-code platform.
|
|
15
|
+
Total control. Infinite extensibility. AI collaboration.
|
|
16
|
+
Enable your team to adapt quickly and cut costs dramatically.
|
|
17
|
+
No years of development. No millions wasted.
|
|
18
|
+
Deploy NocoBase in minutes — and take control of everything.
|
|
12
19
|
|
|
13
20
|
Homepage:
|
|
14
|
-
https://www.nocobase.com/
|
|
21
|
+
https://www.nocobase.com/
|
|
15
22
|
|
|
16
23
|
Online Demo:
|
|
17
24
|
https://demo.nocobase.com/new
|
|
@@ -19,12 +26,74 @@ https://demo.nocobase.com/new
|
|
|
19
26
|
Documents:
|
|
20
27
|
https://docs.nocobase.com/
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
https://
|
|
29
|
+
Forum:
|
|
30
|
+
https://forum.nocobase.com/
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
https://www.nocobase.com/en/
|
|
32
|
+
Use Cases:
|
|
33
|
+
https://www.nocobase.com/en/blog/tags/customer-stories
|
|
27
34
|
|
|
35
|
+
## Release Notes
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
Our [blog](https://www.nocobase.com/en/blog/timeline) is regularly updated with release notes and provides a weekly summary.
|
|
38
|
+
|
|
39
|
+
## Distinctive features
|
|
40
|
+
|
|
41
|
+
### 1. Data model-driven, not form/table–driven
|
|
42
|
+
|
|
43
|
+
Instead of being constrained by forms or tables, NocoBase adopts a data model–driven approach, separating data structure from user interface to unlock unlimited possibilities.
|
|
44
|
+
|
|
45
|
+
- UI and data structure are fully decoupled
|
|
46
|
+
- Multiple blocks and actions can be created for the same table or record in any quantity or form
|
|
47
|
+
- Supports the main database, external databases, and third-party APIs as data sources
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
### 2. AI employees, integrated into your business systems
|
|
52
|
+
Unlike standalone AI demos, NocoBase allows you to embed AI capabilities seamlessly into your interfaces, workflows, and data context, making AI truly useful in real business scenarios.
|
|
53
|
+
|
|
54
|
+
- Define AI employees for roles such as translator, analyst, researcher, or assistant
|
|
55
|
+
- Seamless AI–human collaboration in interfaces and workflows
|
|
56
|
+
- Ensure AI usage is secure, transparent, and customizable for your business needs
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
### 3. What you see is what you get, incredibly easy to use
|
|
61
|
+
|
|
62
|
+
While enabling the development of complex business systems, NocoBase keeps the experience simple and intuitive.
|
|
63
|
+
|
|
64
|
+
- One-click switch between usage mode and configuration mode
|
|
65
|
+
- Pages serve as a canvas to arrange blocks and actions, similar to Notion
|
|
66
|
+
- Configuration mode is designed for ordinary users, not just programmers
|
|
67
|
+
|
|
68
|
+

|
|
69
|
+
|
|
70
|
+
### 4. Everything is a plugin, designed for extension
|
|
71
|
+
Adding more no-code features will never cover every business case. NocoBase is built for extension through its plugin-based microkernel architecture.
|
|
72
|
+
|
|
73
|
+
- All functionalities are plugins, similar to WordPress
|
|
74
|
+
- Plugins are ready to use upon installation
|
|
75
|
+
- Pages, blocks, actions, APIs, and data sources can all be extended through custom plugins
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
NocoBase supports three installation methods:
|
|
82
|
+
|
|
83
|
+
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/docker-compose">Installing With Docker (👍Recommended)</a>
|
|
84
|
+
|
|
85
|
+
Suitable for no-code scenarios, no code to write. When upgrading, just download the latest image and reboot.
|
|
86
|
+
|
|
87
|
+
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/create-nocobase-app">Installing from create-nocobase-app CLI</a>
|
|
88
|
+
|
|
89
|
+
The business code of the project is completely independent and supports low-code development.
|
|
90
|
+
|
|
91
|
+
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/git-clone">Installing from Git source code</a>
|
|
92
|
+
|
|
93
|
+
If you want to experience the latest unreleased version, or want to participate in the contribution, you need to make changes and debug on the source code, it is recommended to choose this installation method, which requires a high level of development skills, and if the code has been updated, you can git pull the latest code.
|
|
94
|
+
|
|
95
|
+
## How NocoBase works
|
|
96
|
+
|
|
97
|
+
<video width="100%" controls>
|
|
98
|
+
<source src="https://github.com/user-attachments/assets/8d183b44-9bb5-4792-b08f-bc08fe8dfaaf" type="video/mp4">
|
|
99
|
+
</video>
|
package/lib/JSRunner.d.ts
CHANGED
|
@@ -13,11 +13,20 @@ export interface JSRunnerOptions {
|
|
|
13
13
|
version?: string;
|
|
14
14
|
/**
|
|
15
15
|
* Enable RunJS template compatibility preprocessing for `{{ ... }}`.
|
|
16
|
-
* When enabled
|
|
16
|
+
* When enabled (or falling back to version default),
|
|
17
17
|
* the code will be rewritten to call `ctx.resolveJsonTemplate(...)` at runtime.
|
|
18
18
|
*/
|
|
19
19
|
preprocessTemplates?: boolean;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Decide whether RunJS `{{ ... }}` compatibility preprocessing should run.
|
|
23
|
+
*
|
|
24
|
+
* Priority:
|
|
25
|
+
* 1. Explicit `preprocessTemplates` option always wins.
|
|
26
|
+
* 2. Otherwise, `version === 'v2'` disables preprocessing.
|
|
27
|
+
* 3. Fallback keeps v1-compatible behavior (enabled).
|
|
28
|
+
*/
|
|
29
|
+
export declare function shouldPreprocessRunJSTemplates(options?: Pick<JSRunnerOptions, 'preprocessTemplates' | 'version'>): boolean;
|
|
21
30
|
export declare class JSRunner {
|
|
22
31
|
private globals;
|
|
23
32
|
private timeoutMs;
|
package/lib/JSRunner.js
CHANGED
|
@@ -27,11 +27,53 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
28
|
var JSRunner_exports = {};
|
|
29
29
|
__export(JSRunner_exports, {
|
|
30
|
-
JSRunner: () => JSRunner
|
|
30
|
+
JSRunner: () => JSRunner,
|
|
31
|
+
shouldPreprocessRunJSTemplates: () => shouldPreprocessRunJSTemplates
|
|
31
32
|
});
|
|
32
33
|
module.exports = __toCommonJS(JSRunner_exports);
|
|
33
34
|
var import_ses = require("ses");
|
|
34
35
|
var import_exceptions = require("./utils/exceptions");
|
|
36
|
+
function shouldPreprocessRunJSTemplates(options) {
|
|
37
|
+
if (typeof (options == null ? void 0 : options.preprocessTemplates) === "boolean") {
|
|
38
|
+
return options.preprocessTemplates;
|
|
39
|
+
}
|
|
40
|
+
return (options == null ? void 0 : options.version) !== "v2";
|
|
41
|
+
}
|
|
42
|
+
__name(shouldPreprocessRunJSTemplates, "shouldPreprocessRunJSTemplates");
|
|
43
|
+
const BARE_CTX_TEMPLATE_RE = /(^|[=(:,[\s)])(\{\{\s*(ctx(?:\.|\[|\?\.)[^}]*)\s*\}\})/m;
|
|
44
|
+
function extractDeprecatedCtxTemplateUsage(code) {
|
|
45
|
+
const src = String(code || "");
|
|
46
|
+
const m = src.match(BARE_CTX_TEMPLATE_RE);
|
|
47
|
+
if (!m) return null;
|
|
48
|
+
const placeholder = String(m[2] || "").trim();
|
|
49
|
+
const expression = String(m[3] || "").trim();
|
|
50
|
+
if (!placeholder || !expression) return null;
|
|
51
|
+
return { placeholder, expression };
|
|
52
|
+
}
|
|
53
|
+
__name(extractDeprecatedCtxTemplateUsage, "extractDeprecatedCtxTemplateUsage");
|
|
54
|
+
function shouldHintCtxTemplateSyntax(err, usage) {
|
|
55
|
+
const isSyntaxError = err instanceof SyntaxError || String((err == null ? void 0 : err.name) || "") === "SyntaxError";
|
|
56
|
+
if (!isSyntaxError) return false;
|
|
57
|
+
if (!usage) return false;
|
|
58
|
+
const msg = String((err == null ? void 0 : err.message) || err || "");
|
|
59
|
+
return /unexpected token/i.test(msg);
|
|
60
|
+
}
|
|
61
|
+
__name(shouldHintCtxTemplateSyntax, "shouldHintCtxTemplateSyntax");
|
|
62
|
+
function toCtxTemplateSyntaxHintError(err, usage) {
|
|
63
|
+
const hint = `"${usage.placeholder}" has been deprecated and cannot be used as executable RunJS syntax. Use await ctx.getVar("${usage.expression}") instead, or keep "${usage.placeholder}" as a plain string.`;
|
|
64
|
+
const out = new SyntaxError(hint);
|
|
65
|
+
try {
|
|
66
|
+
out.cause = err;
|
|
67
|
+
} catch (_) {
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
out.__runjsHideLocation = true;
|
|
71
|
+
out.stack = `${out.name}: ${out.message}`;
|
|
72
|
+
} catch (_) {
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
__name(toCtxTemplateSyntaxHintError, "toCtxTemplateSyntaxHintError");
|
|
35
77
|
const _JSRunner = class _JSRunner {
|
|
36
78
|
globals;
|
|
37
79
|
timeoutMs;
|
|
@@ -111,11 +153,13 @@ const _JSRunner = class _JSRunner {
|
|
|
111
153
|
if (err instanceof import_exceptions.FlowExitAllException) {
|
|
112
154
|
throw err;
|
|
113
155
|
}
|
|
114
|
-
|
|
156
|
+
const usage = extractDeprecatedCtxTemplateUsage(code);
|
|
157
|
+
const outErr = shouldHintCtxTemplateSyntax(err, usage) && usage ? toCtxTemplateSyntaxHintError(err, usage) : err;
|
|
158
|
+
console.error(outErr);
|
|
115
159
|
return {
|
|
116
160
|
success: false,
|
|
117
|
-
error:
|
|
118
|
-
timeout:
|
|
161
|
+
error: outErr,
|
|
162
|
+
timeout: (outErr == null ? void 0 : outErr.message) === "Execution timed out"
|
|
119
163
|
};
|
|
120
164
|
}
|
|
121
165
|
}
|
|
@@ -124,5 +168,6 @@ __name(_JSRunner, "JSRunner");
|
|
|
124
168
|
let JSRunner = _JSRunner;
|
|
125
169
|
// Annotate the CommonJS export names for ESM import in node:
|
|
126
170
|
0 && (module.exports = {
|
|
127
|
-
JSRunner
|
|
171
|
+
JSRunner,
|
|
172
|
+
shouldPreprocessRunJSTemplates
|
|
128
173
|
});
|
|
@@ -65,7 +65,11 @@ function createViewScopedEngine(parent) {
|
|
|
65
65
|
"_previousEngine",
|
|
66
66
|
"_nextEngine",
|
|
67
67
|
// getModel 需要在本地执行以确保全局查找时正确遍历整个引擎栈
|
|
68
|
-
"getModel"
|
|
68
|
+
"getModel",
|
|
69
|
+
// 视图销毁回调需要在本地存储,每个视图引擎有自己的销毁逻辑
|
|
70
|
+
"_destroyView",
|
|
71
|
+
"setDestroyView",
|
|
72
|
+
"destroyView"
|
|
69
73
|
]);
|
|
70
74
|
const handler = {
|
|
71
75
|
get(target, prop, receiver) {
|
|
@@ -220,7 +220,9 @@ const buildLayoutSnapshot = /* @__PURE__ */ __name(({ container }) => {
|
|
|
220
220
|
}
|
|
221
221
|
const columnElements = Array.from(
|
|
222
222
|
container.querySelectorAll(`[data-grid-column-row-id="${rowId}"][data-grid-column-index]`)
|
|
223
|
-
)
|
|
223
|
+
).filter((el) => {
|
|
224
|
+
return el.closest("[data-grid-row-id]") === rowElement;
|
|
225
|
+
});
|
|
224
226
|
const sortedColumns = columnElements.sort((a, b) => {
|
|
225
227
|
const indexA = Number(a.dataset.gridColumnIndex || 0);
|
|
226
228
|
const indexB = Number(b.dataset.gridColumnIndex || 0);
|
|
@@ -245,7 +247,9 @@ const buildLayoutSnapshot = /* @__PURE__ */ __name(({ container }) => {
|
|
|
245
247
|
});
|
|
246
248
|
const itemElements = Array.from(
|
|
247
249
|
columnElement.querySelectorAll(`[data-grid-item-row-id="${rowId}"][data-grid-column-index="${columnIndex}"]`)
|
|
248
|
-
)
|
|
250
|
+
).filter((el) => {
|
|
251
|
+
return el.closest("[data-grid-column-row-id][data-grid-column-index]") === columnElement;
|
|
252
|
+
});
|
|
249
253
|
const sortedItems = itemElements.sort((a, b) => {
|
|
250
254
|
const indexA = Number(a.dataset.gridItemIndex || 0);
|
|
251
255
|
const indexB = Number(b.dataset.gridItemIndex || 0);
|
|
@@ -126,6 +126,15 @@ const openStepSettingsDialog = /* @__PURE__ */ __name(async ({
|
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
128
|
const openView = model.context.viewer[mode].bind(model.context.viewer);
|
|
129
|
+
const resolvedUiModeProps = (0, import_reactive.toJS)(uiModeProps) || {};
|
|
130
|
+
const { zIndex: uiModeZIndex, ...restUiModeProps } = resolvedUiModeProps;
|
|
131
|
+
const resolveDialogZIndex = /* @__PURE__ */ __name((rawZIndex) => {
|
|
132
|
+
var _a2, _b2;
|
|
133
|
+
const nextZIndex = typeof ((_a2 = model.context.viewer) == null ? void 0 : _a2.getNextZIndex) === "function" ? model.context.viewer.getNextZIndex() : (((_b2 = model.context.themeToken) == null ? void 0 : _b2.zIndexPopupBase) || 1e3) + 1;
|
|
134
|
+
const inputZIndex = Number(rawZIndex) || 0;
|
|
135
|
+
return Math.max(nextZIndex, inputZIndex);
|
|
136
|
+
}, "resolveDialogZIndex");
|
|
137
|
+
const mergedZIndex = resolveDialogZIndex(uiModeZIndex);
|
|
129
138
|
const form = (0, import_core.createForm)({
|
|
130
139
|
initialValues: (0, import_utils.compileUiSchema)(scopes, initialValues)
|
|
131
140
|
});
|
|
@@ -141,7 +150,8 @@ const openStepSettingsDialog = /* @__PURE__ */ __name(async ({
|
|
|
141
150
|
title: dialogTitle || t(title),
|
|
142
151
|
width: dialogWidth,
|
|
143
152
|
destroyOnClose: true,
|
|
144
|
-
...
|
|
153
|
+
...restUiModeProps,
|
|
154
|
+
zIndex: mergedZIndex,
|
|
145
155
|
// 透传 navigation,便于变量元信息根据真实视图栈推断父级弹窗
|
|
146
156
|
inputArgs,
|
|
147
157
|
onClose: /* @__PURE__ */ __name(() => {
|
|
@@ -155,7 +165,11 @@ const openStepSettingsDialog = /* @__PURE__ */ __name(async ({
|
|
|
155
165
|
(0, import_react2.useEffect)(() => {
|
|
156
166
|
return (0, import_reactive.autorun)(() => {
|
|
157
167
|
const dynamicProps = (0, import_reactive.toJS)(uiModeProps);
|
|
158
|
-
|
|
168
|
+
const { zIndex, ...restDynamicProps } = dynamicProps || {};
|
|
169
|
+
currentDialog.update({
|
|
170
|
+
...restDynamicProps,
|
|
171
|
+
zIndex: resolveDialogZIndex(zIndex)
|
|
172
|
+
});
|
|
159
173
|
});
|
|
160
174
|
}, []);
|
|
161
175
|
const compiledFormSchema = (0, import_utils.compileUiSchema)(scopes, formSchema);
|
|
@@ -376,6 +376,21 @@ const AddSubModelButtonCore = /* @__PURE__ */ __name(function AddSubModelButton(
|
|
|
376
376
|
}),
|
|
377
377
|
[model, subModelKey, subModelType]
|
|
378
378
|
);
|
|
379
|
+
import_react.default.useEffect(() => {
|
|
380
|
+
var _a, _b, _c;
|
|
381
|
+
const handleSubModelChanged = /* @__PURE__ */ __name(() => {
|
|
382
|
+
setRefreshTick((x) => x + 1);
|
|
383
|
+
}, "handleSubModelChanged");
|
|
384
|
+
(_a = model.emitter) == null ? void 0 : _a.on("onSubModelAdded", handleSubModelChanged);
|
|
385
|
+
(_b = model.emitter) == null ? void 0 : _b.on("onSubModelRemoved", handleSubModelChanged);
|
|
386
|
+
(_c = model.emitter) == null ? void 0 : _c.on("onSubModelReplaced", handleSubModelChanged);
|
|
387
|
+
return () => {
|
|
388
|
+
var _a2, _b2, _c2;
|
|
389
|
+
(_a2 = model.emitter) == null ? void 0 : _a2.off("onSubModelAdded", handleSubModelChanged);
|
|
390
|
+
(_b2 = model.emitter) == null ? void 0 : _b2.off("onSubModelRemoved", handleSubModelChanged);
|
|
391
|
+
(_c2 = model.emitter) == null ? void 0 : _c2.off("onSubModelReplaced", handleSubModelChanged);
|
|
392
|
+
};
|
|
393
|
+
}, [model]);
|
|
379
394
|
const onClick = /* @__PURE__ */ __name(async (info) => {
|
|
380
395
|
const clickedItem = info.originalItem || info;
|
|
381
396
|
const item = clickedItem.originalItem || clickedItem;
|
|
@@ -213,11 +213,13 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
213
213
|
flowContext.logger.info(`[FlowEngine] ${error.message}`);
|
|
214
214
|
await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:end`, {
|
|
215
215
|
...flowEventBasePayload,
|
|
216
|
-
stepKey
|
|
216
|
+
stepKey,
|
|
217
|
+
aborted: true
|
|
217
218
|
});
|
|
218
219
|
await this.emitModelEventIf(eventName, `flow:${flowKey}:end`, {
|
|
219
220
|
...flowEventBasePayload,
|
|
220
|
-
result: error
|
|
221
|
+
result: error,
|
|
222
|
+
aborted: true
|
|
221
223
|
});
|
|
222
224
|
return Promise.resolve(error);
|
|
223
225
|
}
|
|
@@ -287,6 +289,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
287
289
|
}) : flows;
|
|
288
290
|
const scheduledCancels = [];
|
|
289
291
|
const execute = /* @__PURE__ */ __name(async () => {
|
|
292
|
+
let abortedByExitAll = false;
|
|
290
293
|
if (sequential) {
|
|
291
294
|
const flowsWithIndex = flowsToRun.map((f, i) => ({ f, i }));
|
|
292
295
|
const ordered = flowsWithIndex.slice().sort((a, b) => {
|
|
@@ -355,9 +358,10 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
355
358
|
return;
|
|
356
359
|
}
|
|
357
360
|
if (!whenKey) return;
|
|
361
|
+
const shouldSkipOnAborted = whenKey === `event:${eventName}:end` || phase === "afterFlow" || phase === "afterStep";
|
|
358
362
|
scheduled.add(flow.key);
|
|
359
363
|
const list = scheduleGroups.get(whenKey) || [];
|
|
360
|
-
list.push({ flow, order: indexInOrdered });
|
|
364
|
+
list.push({ flow, order: indexInOrdered, shouldSkipOnAborted });
|
|
361
365
|
scheduleGroups.set(whenKey, list);
|
|
362
366
|
});
|
|
363
367
|
for (const [whenKey, list] of scheduleGroups.entries()) {
|
|
@@ -368,6 +372,12 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
368
372
|
return a.order - b.order;
|
|
369
373
|
});
|
|
370
374
|
for (const it of sorted) {
|
|
375
|
+
const when = it.shouldSkipOnAborted ? Object.assign(
|
|
376
|
+
(event) => event.type === whenKey && event.aborted !== true,
|
|
377
|
+
{
|
|
378
|
+
__eventType: whenKey
|
|
379
|
+
}
|
|
380
|
+
) : whenKey;
|
|
371
381
|
const cancel = model.scheduleModelOperation(
|
|
372
382
|
model.uid,
|
|
373
383
|
async (m) => {
|
|
@@ -377,7 +387,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
377
387
|
}
|
|
378
388
|
results2.push(res);
|
|
379
389
|
},
|
|
380
|
-
{ when
|
|
390
|
+
{ when }
|
|
381
391
|
);
|
|
382
392
|
scheduledCancels.push(cancel);
|
|
383
393
|
}
|
|
@@ -391,12 +401,14 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
391
401
|
const result = await this.runFlow(model, flow.key, inputArgs, runId, eventName);
|
|
392
402
|
if (result instanceof import_exceptions.FlowExitAllException) {
|
|
393
403
|
logger.debug(`[FlowEngine.dispatchEvent] ${result.message}`);
|
|
404
|
+
abortedByExitAll = true;
|
|
394
405
|
break;
|
|
395
406
|
}
|
|
396
407
|
results2.push(result);
|
|
397
408
|
} catch (error) {
|
|
398
409
|
if (error instanceof import_exceptions.FlowExitAllException) {
|
|
399
410
|
logger.debug(`[FlowEngine.dispatchEvent] ${error.message}`);
|
|
411
|
+
abortedByExitAll = true;
|
|
400
412
|
break;
|
|
401
413
|
}
|
|
402
414
|
logger.error(
|
|
@@ -406,7 +418,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
406
418
|
throw error;
|
|
407
419
|
}
|
|
408
420
|
}
|
|
409
|
-
return results2;
|
|
421
|
+
return { result: results2, abortedByExitAll };
|
|
410
422
|
}
|
|
411
423
|
const results = await Promise.all(
|
|
412
424
|
flowsToRun.map(async (flow) => {
|
|
@@ -423,7 +435,11 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
423
435
|
}
|
|
424
436
|
})
|
|
425
437
|
);
|
|
426
|
-
|
|
438
|
+
const filteredResults = results.filter((x) => x !== void 0);
|
|
439
|
+
if (filteredResults.some((x) => x instanceof import_exceptions.FlowExitAllException)) {
|
|
440
|
+
abortedByExitAll = true;
|
|
441
|
+
}
|
|
442
|
+
return { result: filteredResults, abortedByExitAll };
|
|
427
443
|
}, "execute");
|
|
428
444
|
const argsKey = useCache ? JSON.stringify(inputArgs ?? {}) : "";
|
|
429
445
|
const cacheKey = useCache ? import_flowEngine.FlowEngine.generateApplyFlowCacheKey(
|
|
@@ -432,7 +448,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
432
448
|
model.uid
|
|
433
449
|
) : null;
|
|
434
450
|
try {
|
|
435
|
-
const result = await this.withApplyFlowCache(cacheKey, execute);
|
|
451
|
+
const { result, abortedByExitAll } = await this.withApplyFlowCache(cacheKey, execute);
|
|
436
452
|
try {
|
|
437
453
|
await ((_c = model.onDispatchEventEnd) == null ? void 0 : _c.call(model, eventName, options, inputArgs, result));
|
|
438
454
|
} catch (hookErr) {
|
|
@@ -440,8 +456,15 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
440
456
|
}
|
|
441
457
|
await this.emitModelEventIf(eventName, "end", {
|
|
442
458
|
...eventBasePayload,
|
|
443
|
-
result
|
|
459
|
+
result,
|
|
460
|
+
...abortedByExitAll ? { aborted: true } : {}
|
|
444
461
|
});
|
|
462
|
+
if (result && typeof result === "object") {
|
|
463
|
+
Object.defineProperty(result, "__abortedByExitAll", {
|
|
464
|
+
value: abortedByExitAll,
|
|
465
|
+
configurable: true
|
|
466
|
+
});
|
|
467
|
+
}
|
|
445
468
|
return result;
|
|
446
469
|
} catch (error) {
|
|
447
470
|
try {
|
package/lib/flowContext.js
CHANGED
|
@@ -2222,7 +2222,10 @@ const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext
|
|
|
2222
2222
|
...runnerOptions || {},
|
|
2223
2223
|
globals: mergedGlobals
|
|
2224
2224
|
});
|
|
2225
|
-
const shouldPreprocessTemplates =
|
|
2225
|
+
const shouldPreprocessTemplates = (0, import_JSRunner.shouldPreprocessRunJSTemplates)({
|
|
2226
|
+
version: runnerOptions == null ? void 0 : runnerOptions.version,
|
|
2227
|
+
preprocessTemplates
|
|
2228
|
+
});
|
|
2226
2229
|
const jsCode = await (0, import_utils.prepareRunJsCode)(String(code ?? ""), { preprocessTemplates: shouldPreprocessTemplates });
|
|
2227
2230
|
return runner.run(jsCode);
|
|
2228
2231
|
}
|
package/lib/flowEngine.d.ts
CHANGED
|
@@ -83,6 +83,12 @@ export declare class FlowEngine {
|
|
|
83
83
|
*/
|
|
84
84
|
private _previousEngine?;
|
|
85
85
|
private _nextEngine?;
|
|
86
|
+
/**
|
|
87
|
+
* 视图销毁回调。由 useDrawer / useDialog 在创建弹窗视图时注册,
|
|
88
|
+
* 供外部(如 afterSuccess)通过引擎栈遍历来关闭多层弹窗。
|
|
89
|
+
* embed 视图(usePage)不注册此回调,因此 destroyView() 会自然跳过。
|
|
90
|
+
*/
|
|
91
|
+
private _destroyView?;
|
|
86
92
|
private _resources;
|
|
87
93
|
/**
|
|
88
94
|
* Data change registry used to coordinate "refresh on active" across view-scoped engines.
|
|
@@ -151,6 +157,18 @@ export declare class FlowEngine {
|
|
|
151
157
|
* 将当前引擎从栈中移除并修复相邻指针(用于视图关闭时)。
|
|
152
158
|
*/
|
|
153
159
|
unlinkFromStack(): void;
|
|
160
|
+
/**
|
|
161
|
+
* 注册视图销毁回调(由 useDrawer / useDialog 调用)。
|
|
162
|
+
*/
|
|
163
|
+
setDestroyView(fn: () => void): void;
|
|
164
|
+
/**
|
|
165
|
+
* 关闭当前引擎关联的弹窗视图。
|
|
166
|
+
* 路由触发的弹窗会先 navigation.back() 清理 URL,再 destroy() 移除元素;
|
|
167
|
+
* 非路由弹窗直接 destroy()。
|
|
168
|
+
* embed 视图不注册回调,调用时返回 false 自动跳过。
|
|
169
|
+
* @returns 是否成功执行
|
|
170
|
+
*/
|
|
171
|
+
destroyView(): boolean;
|
|
154
172
|
/**
|
|
155
173
|
* Get the flow engine context object.
|
|
156
174
|
* @returns {FlowEngineContext} Flow engine context
|
|
@@ -333,6 +351,7 @@ export declare class FlowEngine {
|
|
|
333
351
|
* @returns {Promise<T | null>} Model instance or null
|
|
334
352
|
*/
|
|
335
353
|
loadOrCreateModel<T extends FlowModel = FlowModel>(options: any, extra?: {
|
|
354
|
+
skipSave?: boolean;
|
|
336
355
|
delegateToParent?: boolean;
|
|
337
356
|
delegate?: FlowContext;
|
|
338
357
|
}): Promise<T | null>;
|
package/lib/flowEngine.js
CHANGED
|
@@ -119,6 +119,12 @@ const _FlowEngine = class _FlowEngine {
|
|
|
119
119
|
*/
|
|
120
120
|
__publicField(this, "_previousEngine");
|
|
121
121
|
__publicField(this, "_nextEngine");
|
|
122
|
+
/**
|
|
123
|
+
* 视图销毁回调。由 useDrawer / useDialog 在创建弹窗视图时注册,
|
|
124
|
+
* 供外部(如 afterSuccess)通过引擎栈遍历来关闭多层弹窗。
|
|
125
|
+
* embed 视图(usePage)不注册此回调,因此 destroyView() 会自然跳过。
|
|
126
|
+
*/
|
|
127
|
+
__publicField(this, "_destroyView");
|
|
122
128
|
__publicField(this, "_resources", /* @__PURE__ */ new Map());
|
|
123
129
|
/**
|
|
124
130
|
* Data change registry used to coordinate "refresh on active" across view-scoped engines.
|
|
@@ -258,6 +264,26 @@ const _FlowEngine = class _FlowEngine {
|
|
|
258
264
|
prev._nextEngine = void 0;
|
|
259
265
|
}
|
|
260
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* 注册视图销毁回调(由 useDrawer / useDialog 调用)。
|
|
269
|
+
*/
|
|
270
|
+
setDestroyView(fn) {
|
|
271
|
+
this._destroyView = fn;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* 关闭当前引擎关联的弹窗视图。
|
|
275
|
+
* 路由触发的弹窗会先 navigation.back() 清理 URL,再 destroy() 移除元素;
|
|
276
|
+
* 非路由弹窗直接 destroy()。
|
|
277
|
+
* embed 视图不注册回调,调用时返回 false 自动跳过。
|
|
278
|
+
* @returns 是否成功执行
|
|
279
|
+
*/
|
|
280
|
+
destroyView() {
|
|
281
|
+
if (this._destroyView) {
|
|
282
|
+
this._destroyView();
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
261
287
|
// (已移除)getModelGlobal/forEachModelGlobal/getAllModelsGlobal:不再维护冗余全局遍历 API
|
|
262
288
|
/**
|
|
263
289
|
* Get the flow engine context object.
|
|
@@ -829,7 +855,9 @@ const _FlowEngine = class _FlowEngine {
|
|
|
829
855
|
model = this.createModel(data, extra);
|
|
830
856
|
} else {
|
|
831
857
|
model = this.createModel(options, extra);
|
|
832
|
-
|
|
858
|
+
if (!(extra == null ? void 0 : extra.skipSave)) {
|
|
859
|
+
await model.save();
|
|
860
|
+
}
|
|
833
861
|
}
|
|
834
862
|
if (model.parent) {
|
|
835
863
|
const subModel = model.parent.findSubModel(model.subKey, (m2) => {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
export type RunJSVersion = 'v1' | (string & {});
|
|
9
|
+
export type RunJSVersion = 'v1' | 'v2' | (string & {});
|
|
10
10
|
export type RunJSContextCtor = new (delegate: any) => any;
|
|
11
11
|
export type RunJSContextMeta = {
|
|
12
12
|
scenes?: string[];
|
|
@@ -67,19 +67,26 @@ async function setupRunJSContexts() {
|
|
|
67
67
|
import("./contexts/JSRecordActionRunJSContext"),
|
|
68
68
|
import("./contexts/JSCollectionActionRunJSContext")
|
|
69
69
|
]);
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
const registerBuiltins = /* @__PURE__ */ __name((version) => {
|
|
71
|
+
import_registry.RunJSContextRegistry.register(version, "*", import_flowContext.FlowRunJSContext);
|
|
72
|
+
import_registry.RunJSContextRegistry.register(version, "JSBlockModel", JSBlockRunJSContext, { scenes: ["block"] });
|
|
73
|
+
import_registry.RunJSContextRegistry.register(version, "JSFieldModel", JSFieldRunJSContext, { scenes: ["detail"] });
|
|
74
|
+
import_registry.RunJSContextRegistry.register(version, "JSEditableFieldModel", JSEditableFieldRunJSContext, { scenes: ["form"] });
|
|
75
|
+
import_registry.RunJSContextRegistry.register(version, "JSItemModel", JSItemRunJSContext, { scenes: ["form"] });
|
|
76
|
+
import_registry.RunJSContextRegistry.register(version, "JSColumnModel", JSColumnRunJSContext, { scenes: ["table"] });
|
|
77
|
+
import_registry.RunJSContextRegistry.register(version, "FormJSFieldItemModel", FormJSFieldItemRunJSContext, { scenes: ["form"] });
|
|
78
|
+
import_registry.RunJSContextRegistry.register(version, "JSRecordActionModel", JSRecordActionRunJSContext, { scenes: ["table"] });
|
|
79
|
+
import_registry.RunJSContextRegistry.register(version, "JSCollectionActionModel", JSCollectionActionRunJSContext, {
|
|
80
|
+
scenes: ["table"]
|
|
81
|
+
});
|
|
82
|
+
}, "registerBuiltins");
|
|
83
|
+
const versions = ["v1", "v2"];
|
|
84
|
+
for (const version of versions) {
|
|
85
|
+
registerBuiltins(version);
|
|
86
|
+
await (0, import_contributions.applyRunJSContextContributions)(version);
|
|
87
|
+
(0, import_contributions.markRunJSContextsSetupDone)(version);
|
|
88
|
+
}
|
|
81
89
|
done = true;
|
|
82
|
-
(0, import_contributions.markRunJSContextsSetupDone)(v1);
|
|
83
90
|
}
|
|
84
91
|
__name(setupRunJSContexts, "setupRunJSContexts");
|
|
85
92
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
import type { FlowEngine } from '../flowEngine';
|
|
10
10
|
import type { FlowModel } from '../models/flowModel';
|
|
11
11
|
type LifecycleType = 'created' | 'mounted' | 'unmounted' | 'destroyed' | `event:${string}:start` | `event:${string}:end` | `event:${string}:error`;
|
|
12
|
-
|
|
12
|
+
type EventPredicateWhen = ((e: LifecycleEvent) => boolean) & {
|
|
13
|
+
__eventType?: string;
|
|
14
|
+
};
|
|
15
|
+
export type ScheduleWhen = LifecycleType | EventPredicateWhen;
|
|
13
16
|
export interface ScheduleOptions {
|
|
14
17
|
when?: ScheduleWhen;
|
|
15
18
|
}
|
|
@@ -22,6 +25,7 @@ export interface LifecycleEvent {
|
|
|
22
25
|
error?: any;
|
|
23
26
|
inputArgs?: Record<string, any>;
|
|
24
27
|
result?: any;
|
|
28
|
+
aborted?: boolean;
|
|
25
29
|
flowKey?: string;
|
|
26
30
|
stepKey?: string;
|
|
27
31
|
}
|
|
@@ -171,8 +171,9 @@ const _ModelOperationScheduler = class _ModelOperationScheduler {
|
|
|
171
171
|
this.unbindHandlers.push(() => emitter.off("model:destroyed", onDestroyed));
|
|
172
172
|
}
|
|
173
173
|
ensureEventSubscriptionIfNeeded(when) {
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
const eventType = typeof when === "string" ? when : typeof when === "function" ? when.__eventType : void 0;
|
|
175
|
+
if (!eventType) return;
|
|
176
|
+
const parsed = this.parseEventWhen(eventType);
|
|
176
177
|
if (!parsed) return;
|
|
177
178
|
const { name } = parsed;
|
|
178
179
|
if (this.subscribedEventNames.has(name)) return;
|
package/lib/types.d.ts
CHANGED
|
@@ -177,7 +177,7 @@ export interface ActionDefinition<TModel extends FlowModel = FlowModel, TCtx ext
|
|
|
177
177
|
* - 收录内置常用事件,便于智能提示;
|
|
178
178
|
* - 允许扩展字符串以保持向后兼容。
|
|
179
179
|
*/
|
|
180
|
-
export type FlowEventName = 'click' | 'submit' | 'reset' | 'remove' | 'openView' | 'dropdownOpen' | 'popupScroll' | 'search' | 'customRequest' | 'collapseToggle' | (string & {});
|
|
180
|
+
export type FlowEventName = 'click' | 'close' | 'submit' | 'reset' | 'remove' | 'openView' | 'dropdownOpen' | 'popupScroll' | 'search' | 'customRequest' | 'collapseToggle' | (string & {});
|
|
181
181
|
/**
|
|
182
182
|
* 事件流的执行时机(phase)。
|
|
183
183
|
*
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export { BLOCK_GROUP_CONFIGS, BLOCK_TYPES, FLOW_ENGINE_NAMESPACE, MENU_KEYS, type BlockBuilderConfig, } from './constants';
|
|
10
10
|
export { escapeT, getT, tExpr } from './translation';
|
|
11
|
-
export { FlowCancelSaveException, FlowExitException } from './exceptions';
|
|
11
|
+
export { FlowCancelSaveException, FlowExitAllException, FlowExitException } from './exceptions';
|
|
12
12
|
export { defineAction } from './flow-definitions';
|
|
13
13
|
export { isInheritedFrom } from './inheritance';
|
|
14
14
|
export { resolveCreateModelOptions, resolveDefaultParams, resolveExpressions } from './params-resolvers';
|
|
15
|
-
export { compileUiSchema, resolveStepUiSchema, resolveStepDisabledInSettings, resolveUiMode, shouldHideStepInSettings, } from './schema-utils';
|
|
15
|
+
export { compileUiSchema, resolveStepUiSchema, resolveStepDisabledInSettings, resolveUiMode, shouldHideEventInSettings, shouldHideStepInSettings, } from './schema-utils';
|
|
16
16
|
export { setupRuntimeContextSteps } from './setupRuntimeContextSteps';
|
|
17
17
|
export { createCollectionContextMeta } from './createCollectionContextMeta';
|
|
18
18
|
export { createAssociationAwareObjectMetaFactory, createAssociationSubpathResolver } from './associationObjectVariable';
|