@nocobase/flow-engine 2.1.0-beta.6 → 2.1.0-beta.8
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 +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 +25 -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/utils/parsePathnameToViewParams.js +1 -1
- package/lib/views/useDialog.js +10 -0
- package/lib/views/useDrawer.js +10 -0
- package/package.json +4 -4
- 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 +28 -9
- package/src/executor/__tests__/flowExecutor.test.ts +26 -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/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
- package/src/utils/parsePathnameToViewParams.ts +2 -2
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +1 -0
- package/src/views/useDialog.tsx +14 -0
- package/src/views/useDrawer.tsx +14 -0
- package/src/views/usePage.tsx +1 -0
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,7 +456,8 @@ 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
|
});
|
|
445
462
|
return result;
|
|
446
463
|
} catch (error) {
|
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;
|
|
@@ -92,7 +92,7 @@ const parsePathnameToViewParams = /* @__PURE__ */ __name((pathname) => {
|
|
|
92
92
|
} catch (_) {
|
|
93
93
|
parsed = decoded;
|
|
94
94
|
}
|
|
95
|
-
} else if (decoded &&
|
|
95
|
+
} else if (decoded && /^[^=&]+=[^=&]*(?:&[^=&]+=[^=&]*)*$/.test(decoded)) {
|
|
96
96
|
parsed = parseKeyValuePairs(decoded);
|
|
97
97
|
}
|
|
98
98
|
currentView.filterByTk = parsed;
|
package/lib/views/useDialog.js
CHANGED
|
@@ -103,12 +103,15 @@ function useDialog() {
|
|
|
103
103
|
} else {
|
|
104
104
|
ctx.addDelegate(flowContext.engine.context);
|
|
105
105
|
}
|
|
106
|
+
let destroyed = false;
|
|
106
107
|
const currentDialog = {
|
|
107
108
|
type: "dialog",
|
|
108
109
|
inputArgs: config.inputArgs || {},
|
|
109
110
|
preventClose: !!config.preventClose,
|
|
110
111
|
destroy: /* @__PURE__ */ __name((result) => {
|
|
111
112
|
var _a2, _b2, _c2, _d;
|
|
113
|
+
if (destroyed) return;
|
|
114
|
+
destroyed = true;
|
|
112
115
|
(_a2 = config.onClose) == null ? void 0 : _a2.call(config);
|
|
113
116
|
(_b2 = dialogRef.current) == null ? void 0 : _b2.destroy();
|
|
114
117
|
closeFunc == null ? void 0 : closeFunc();
|
|
@@ -154,6 +157,13 @@ function useDialog() {
|
|
|
154
157
|
get: /* @__PURE__ */ __name(() => currentDialog, "get"),
|
|
155
158
|
resolveOnServer: (0, import_variablesParams.createViewRecordResolveOnServer)(ctx, () => (0, import_variablesParams.getViewRecordFromParent)(flowContext, ctx))
|
|
156
159
|
});
|
|
160
|
+
scopedEngine.setDestroyView(() => {
|
|
161
|
+
var _a2, _b2;
|
|
162
|
+
if (config.triggerByRouter && ((_b2 = (_a2 = config.inputArgs) == null ? void 0 : _a2.navigation) == null ? void 0 : _b2.back)) {
|
|
163
|
+
config.inputArgs.navigation.back();
|
|
164
|
+
}
|
|
165
|
+
currentDialog.destroy();
|
|
166
|
+
});
|
|
157
167
|
(0, import_createViewMeta.registerPopupVariable)(ctx, currentDialog);
|
|
158
168
|
const DialogWithContext = (0, import__.observer)(
|
|
159
169
|
() => {
|
package/lib/views/useDrawer.js
CHANGED
|
@@ -122,12 +122,15 @@ function useDrawer() {
|
|
|
122
122
|
} else {
|
|
123
123
|
ctx.addDelegate(flowContext.engine.context);
|
|
124
124
|
}
|
|
125
|
+
let destroyed = false;
|
|
125
126
|
const currentDrawer = {
|
|
126
127
|
type: "drawer",
|
|
127
128
|
inputArgs: config.inputArgs || {},
|
|
128
129
|
preventClose: !!config.preventClose,
|
|
129
130
|
destroy: /* @__PURE__ */ __name((result) => {
|
|
130
131
|
var _a2, _b2, _c, _d;
|
|
132
|
+
if (destroyed) return;
|
|
133
|
+
destroyed = true;
|
|
131
134
|
(_a2 = config.onClose) == null ? void 0 : _a2.call(config);
|
|
132
135
|
(_b2 = drawerRef.current) == null ? void 0 : _b2.destroy();
|
|
133
136
|
closeFunc == null ? void 0 : closeFunc();
|
|
@@ -173,6 +176,13 @@ function useDrawer() {
|
|
|
173
176
|
get: /* @__PURE__ */ __name(() => currentDrawer, "get"),
|
|
174
177
|
resolveOnServer: (0, import_variablesParams.createViewRecordResolveOnServer)(ctx, () => (0, import_variablesParams.getViewRecordFromParent)(flowContext, ctx))
|
|
175
178
|
});
|
|
179
|
+
scopedEngine.setDestroyView(() => {
|
|
180
|
+
var _a2, _b2;
|
|
181
|
+
if (config.triggerByRouter && ((_b2 = (_a2 = config.inputArgs) == null ? void 0 : _a2.navigation) == null ? void 0 : _b2.back)) {
|
|
182
|
+
config.inputArgs.navigation.back();
|
|
183
|
+
}
|
|
184
|
+
currentDrawer.destroy();
|
|
185
|
+
});
|
|
176
186
|
(0, import_createViewMeta.registerPopupVariable)(ctx, currentDrawer);
|
|
177
187
|
const DrawerWithContext = React.memo(
|
|
178
188
|
(0, import__.observer)((props) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/flow-engine",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@formily/antd-v5": "1.x",
|
|
10
10
|
"@formily/reactive": "2.x",
|
|
11
|
-
"@nocobase/sdk": "2.1.0-beta.
|
|
12
|
-
"@nocobase/shared": "2.1.0-beta.
|
|
11
|
+
"@nocobase/sdk": "2.1.0-beta.8",
|
|
12
|
+
"@nocobase/shared": "2.1.0-beta.8",
|
|
13
13
|
"ahooks": "^3.7.2",
|
|
14
14
|
"dayjs": "^1.11.9",
|
|
15
15
|
"dompurify": "^3.0.2",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
],
|
|
37
37
|
"author": "NocoBase Team",
|
|
38
38
|
"license": "Apache-2.0",
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "5099d561c5467292414c1e77ad6bad3730d97344"
|
|
40
40
|
}
|