@nocobase/flow-engine 2.1.0-beta.2 → 2.1.0-beta.20
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/FlowModelRenderer.d.ts +1 -1
- package/lib/components/FlowModelRenderer.js +10 -6
- package/lib/components/MobilePopup.js +6 -5
- package/lib/components/dnd/gridDragPlanner.js +6 -2
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +48 -9
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +19 -43
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +339 -295
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +16 -2
- package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.d.ts +36 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +272 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +247 -0
- package/lib/components/subModel/AddSubModelButton.js +27 -1
- package/lib/components/subModel/utils.js +2 -2
- package/lib/data-source/index.js +6 -0
- package/lib/executor/FlowExecutor.js +31 -8
- package/lib/flowContext.js +31 -1
- package/lib/flowEngine.d.ts +151 -1
- package/lib/flowEngine.js +389 -15
- package/lib/flowSettings.d.ts +14 -6
- package/lib/flowSettings.js +34 -6
- package/lib/lazy-helper.d.ts +14 -0
- package/lib/lazy-helper.js +71 -0
- package/lib/locale/en-US.json +1 -0
- package/lib/locale/index.d.ts +2 -0
- package/lib/locale/zh-CN.json +1 -0
- package/lib/models/flowModel.d.ts +2 -1
- package/lib/models/flowModel.js +28 -9
- package/lib/reactive/observer.js +46 -16
- package/lib/runjs-context/registry.d.ts +1 -1
- package/lib/runjs-context/setup.js +20 -12
- package/lib/runjs-context/snippets/index.js +13 -2
- package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.js +50 -0
- package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
- package/lib/scheduler/ModelOperationScheduler.d.ts +5 -1
- package/lib/scheduler/ModelOperationScheduler.js +3 -2
- package/lib/types.d.ts +47 -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/runjsTemplateCompat.js +1 -1
- package/lib/utils/runjsValue.js +41 -11
- 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 +6 -5
- package/src/JSRunner.ts +68 -4
- package/src/ViewScopedFlowEngine.ts +4 -0
- package/src/__tests__/JSRunner.test.ts +27 -1
- package/src/__tests__/flow-engine.test.ts +166 -0
- package/src/__tests__/flowContext.test.ts +65 -1
- package/src/__tests__/flowEngine.modelLoaders.test.ts +245 -0
- package/src/__tests__/flowSettings.test.ts +94 -15
- package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
- package/src/__tests__/runjsContext.test.ts +16 -0
- package/src/__tests__/runjsContextRuntime.test.ts +2 -0
- package/src/__tests__/runjsPreprocessDefault.test.ts +23 -0
- package/src/__tests__/runjsSnippets.test.ts +21 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
- package/src/components/FlowModelRenderer.tsx +12 -6
- package/src/components/MobilePopup.tsx +4 -2
- package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +20 -10
- package/src/components/__tests__/gridDragPlanner.test.ts +88 -0
- package/src/components/dnd/gridDragPlanner.ts +8 -2
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +63 -9
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +468 -440
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +18 -2
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +95 -0
- package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +609 -0
- package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +358 -0
- package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +281 -0
- package/src/components/subModel/AddSubModelButton.tsx +32 -2
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +142 -32
- package/src/components/subModel/utils.ts +1 -1
- package/src/data-source/index.ts +6 -0
- package/src/executor/FlowExecutor.ts +34 -9
- package/src/executor/__tests__/flowExecutor.test.ts +57 -0
- package/src/flowContext.ts +35 -3
- package/src/flowEngine.ts +445 -11
- package/src/flowSettings.ts +40 -6
- package/src/lazy-helper.tsx +57 -0
- package/src/locale/en-US.json +1 -0
- package/src/locale/zh-CN.json +1 -0
- package/src/models/__tests__/dispatchEvent.when.test.ts +214 -0
- package/src/models/flowModel.tsx +31 -10
- package/src/reactive/__tests__/observer.test.tsx +82 -0
- package/src/reactive/observer.tsx +87 -25
- package/src/runjs-context/registry.ts +1 -1
- package/src/runjs-context/setup.ts +22 -12
- package/src/runjs-context/snippets/index.ts +12 -1
- package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
- package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
- package/src/scheduler/ModelOperationScheduler.ts +14 -3
- package/src/types.ts +60 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
- package/src/utils/__tests__/runjsValue.test.ts +11 -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/runjsTemplateCompat.ts +1 -1
- package/src/utils/runjsValue.ts +50 -11
- 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
|
@@ -44,7 +44,7 @@ __export(utils_exports, {
|
|
|
44
44
|
buildWrapperFieldChildren: () => buildWrapperFieldChildren
|
|
45
45
|
});
|
|
46
46
|
module.exports = __toCommonJS(utils_exports);
|
|
47
|
-
var
|
|
47
|
+
var import_lodash = __toESM(require("lodash"));
|
|
48
48
|
var import_utils = require("../../utils");
|
|
49
49
|
async function callHideFunction(hide, ctx) {
|
|
50
50
|
if (typeof hide === "function") {
|
|
@@ -107,7 +107,7 @@ function buildSubModelChildren(M, ctx) {
|
|
|
107
107
|
const extraArg = args && args.length > 0 ? args[args.length - 1] : void 0;
|
|
108
108
|
const defaultOpts = await (0, import_utils.resolveCreateModelOptions)(meta == null ? void 0 : meta.createModelOptions, ctx, extraArg);
|
|
109
109
|
const childOpts = await (0, import_utils.resolveCreateModelOptions)(src, ctx, extraArg);
|
|
110
|
-
return
|
|
110
|
+
return import_lodash.default.merge({}, import_lodash.default.cloneDeep(defaultOpts), childOpts);
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
return node;
|
package/lib/data-source/index.js
CHANGED
|
@@ -461,6 +461,12 @@ const _Collection = class _Collection {
|
|
|
461
461
|
}
|
|
462
462
|
get titleCollectionField() {
|
|
463
463
|
const titleFieldName = this.options.titleField || this.filterTargetKey;
|
|
464
|
+
if (Array.isArray(titleFieldName)) {
|
|
465
|
+
if (titleFieldName.length !== 1) {
|
|
466
|
+
return void 0;
|
|
467
|
+
}
|
|
468
|
+
return this.getField(titleFieldName[0]);
|
|
469
|
+
}
|
|
464
470
|
const titleCollectionField = this.getField(titleFieldName);
|
|
465
471
|
return titleCollectionField;
|
|
466
472
|
}
|
|
@@ -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
|
@@ -57,6 +57,7 @@ __export(flowContext_exports, {
|
|
|
57
57
|
});
|
|
58
58
|
module.exports = __toCommonJS(flowContext_exports);
|
|
59
59
|
var import_reactive = require("@formily/reactive");
|
|
60
|
+
var import_axios = __toESM(require("axios"));
|
|
60
61
|
var antd = __toESM(require("antd"));
|
|
61
62
|
var import_lodash = __toESM(require("lodash"));
|
|
62
63
|
var import_qs = __toESM(require("qs"));
|
|
@@ -81,6 +82,28 @@ var import_dayjs = __toESM(require("dayjs"));
|
|
|
81
82
|
var import_runjsLibs = require("./runjsLibs");
|
|
82
83
|
var import_runjsModuleLoader = require("./utils/runjsModuleLoader");
|
|
83
84
|
var _proxy, _FlowContext_instances, createChildNodes_fn, findMetaByPath_fn, findMetaInDelegatesDeep_fn, findMetaInProperty_fn, resolvePathInMeta_fn, resolvePathInMetaAsync_fn, buildParentTitles_fn, toTreeNode_fn;
|
|
85
|
+
function normalizePathname(pathname) {
|
|
86
|
+
return pathname.endsWith("/") ? pathname : `${pathname}/`;
|
|
87
|
+
}
|
|
88
|
+
__name(normalizePathname, "normalizePathname");
|
|
89
|
+
function shouldBypassApiClient(url, app) {
|
|
90
|
+
try {
|
|
91
|
+
const requestUrl = new URL(url);
|
|
92
|
+
if (!["http:", "https:"].includes(requestUrl.protocol)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (!(app == null ? void 0 : app.getApiUrl)) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
const apiUrl = new URL(app.getApiUrl());
|
|
99
|
+
const apiPath = normalizePathname(apiUrl.pathname);
|
|
100
|
+
const requestPath = normalizePathname(requestUrl.pathname);
|
|
101
|
+
return requestUrl.origin !== apiUrl.origin || !requestPath.startsWith(apiPath);
|
|
102
|
+
} catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
__name(shouldBypassApiClient, "shouldBypassApiClient");
|
|
84
107
|
function isRecordRefLike(val) {
|
|
85
108
|
return !!(val && typeof val === "object" && "collection" in val && "filterByTk" in val);
|
|
86
109
|
}
|
|
@@ -2211,6 +2234,10 @@ const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext
|
|
|
2211
2234
|
return this.engine.getModel(modelName, searchInPreviousEngines);
|
|
2212
2235
|
});
|
|
2213
2236
|
this.defineMethod("request", (options) => {
|
|
2237
|
+
const app = this.app;
|
|
2238
|
+
if (typeof (options == null ? void 0 : options.url) === "string" && shouldBypassApiClient(options.url, app)) {
|
|
2239
|
+
return import_axios.default.request(options);
|
|
2240
|
+
}
|
|
2214
2241
|
return this.api.request(options);
|
|
2215
2242
|
});
|
|
2216
2243
|
this.defineMethod(
|
|
@@ -2222,7 +2249,10 @@ const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext
|
|
|
2222
2249
|
...runnerOptions || {},
|
|
2223
2250
|
globals: mergedGlobals
|
|
2224
2251
|
});
|
|
2225
|
-
const shouldPreprocessTemplates =
|
|
2252
|
+
const shouldPreprocessTemplates = (0, import_JSRunner.shouldPreprocessRunJSTemplates)({
|
|
2253
|
+
version: runnerOptions == null ? void 0 : runnerOptions.version,
|
|
2254
|
+
preprocessTemplates
|
|
2255
|
+
});
|
|
2226
2256
|
const jsCode = await (0, import_utils.prepareRunJsCode)(String(code ?? ""), { preprocessTemplates: shouldPreprocessTemplates });
|
|
2227
2257
|
return runner.run(jsCode);
|
|
2228
2258
|
}
|
package/lib/flowEngine.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { FlowResource } from './resources';
|
|
|
8
8
|
import { Emitter } from './emitter';
|
|
9
9
|
import ModelOperationScheduler from './scheduler/ModelOperationScheduler';
|
|
10
10
|
import type { ScheduleOptions, ScheduledCancel } from './scheduler/ModelOperationScheduler';
|
|
11
|
-
import type { ActionDefinition, ApplyFlowCacheEntry, CreateModelOptions, EventDefinition, FlowModelOptions, IFlowModelRepository, ModelConstructor, PersistOptions, ResourceType } from './types';
|
|
11
|
+
import type { ActionDefinition, ApplyFlowCacheEntry, CreateModelOptions, EnsureBatchResult, EventDefinition, FlowModelLoaderInputMap, FlowModelOptions, IFlowModelRepository, ModelConstructor, PersistOptions, ResourceType } from './types';
|
|
12
12
|
/**
|
|
13
13
|
* FlowEngine is the core class of the flow engine, responsible for managing flow models, actions, model repository, and more.
|
|
14
14
|
* It provides capabilities for registering, creating, finding, persisting, replacing, and moving models.
|
|
@@ -47,6 +47,28 @@ export declare class FlowEngine {
|
|
|
47
47
|
* @private
|
|
48
48
|
*/
|
|
49
49
|
private _modelClasses;
|
|
50
|
+
/**
|
|
51
|
+
* Registered model entries.
|
|
52
|
+
* Key is the model class name, value is the model loader entry.
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
private _modelLoaders;
|
|
56
|
+
/**
|
|
57
|
+
* In-flight model loading promises.
|
|
58
|
+
* Key is the model class name, value is the loading promise.
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
private _loadingModelPromises;
|
|
62
|
+
/**
|
|
63
|
+
* Whether model-loader preload has completed in this session.
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
private _modelLoadersPreloaded;
|
|
67
|
+
/**
|
|
68
|
+
* In-flight model-loader preload promise.
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
private _modelLoadersPreloadPromise?;
|
|
50
72
|
/**
|
|
51
73
|
* Created model instances.
|
|
52
74
|
* Key is the model instance UID, value is the model instance object.
|
|
@@ -83,6 +105,12 @@ export declare class FlowEngine {
|
|
|
83
105
|
*/
|
|
84
106
|
private _previousEngine?;
|
|
85
107
|
private _nextEngine?;
|
|
108
|
+
/**
|
|
109
|
+
* 视图销毁回调。由 useDrawer / useDialog 在创建弹窗视图时注册,
|
|
110
|
+
* 供外部(如 afterSuccess)通过引擎栈遍历来关闭多层弹窗。
|
|
111
|
+
* embed 视图(usePage)不注册此回调,因此 destroyView() 会自然跳过。
|
|
112
|
+
*/
|
|
113
|
+
private _destroyView?;
|
|
86
114
|
private _resources;
|
|
87
115
|
/**
|
|
88
116
|
* Data change registry used to coordinate "refresh on active" across view-scoped engines.
|
|
@@ -151,6 +179,18 @@ export declare class FlowEngine {
|
|
|
151
179
|
* 将当前引擎从栈中移除并修复相邻指针(用于视图关闭时)。
|
|
152
180
|
*/
|
|
153
181
|
unlinkFromStack(): void;
|
|
182
|
+
/**
|
|
183
|
+
* 注册视图销毁回调(由 useDrawer / useDialog 调用)。
|
|
184
|
+
*/
|
|
185
|
+
setDestroyView(fn: () => void): void;
|
|
186
|
+
/**
|
|
187
|
+
* 关闭当前引擎关联的弹窗视图。
|
|
188
|
+
* 路由触发的弹窗会先 navigation.back() 清理 URL,再 destroy() 移除元素;
|
|
189
|
+
* 非路由弹窗直接 destroy()。
|
|
190
|
+
* embed 视图不注册回调,调用时返回 false 自动跳过。
|
|
191
|
+
* @returns 是否成功执行
|
|
192
|
+
*/
|
|
193
|
+
destroyView(): boolean;
|
|
154
194
|
/**
|
|
155
195
|
* Get the flow engine context object.
|
|
156
196
|
* @returns {FlowEngineContext} Flow engine context
|
|
@@ -208,6 +248,10 @@ export declare class FlowEngine {
|
|
|
208
248
|
* Get all registered global events.
|
|
209
249
|
*/
|
|
210
250
|
getEvents<TModel extends FlowModel = FlowModel>(): Map<string, EventDefinition<TModel>>;
|
|
251
|
+
/**
|
|
252
|
+
* for proxy instance, the #registerModel can't be called.
|
|
253
|
+
*/
|
|
254
|
+
private _registerModel;
|
|
211
255
|
/**
|
|
212
256
|
* Register multiple model classes.
|
|
213
257
|
* @param {Record<string, ModelConstructor>} models Model class map, key is model name, value is model constructor
|
|
@@ -216,6 +260,102 @@ export declare class FlowEngine {
|
|
|
216
260
|
* flowEngine.registerModels({ UserModel, OrderModel });
|
|
217
261
|
*/
|
|
218
262
|
registerModels(models: Record<string, ModelConstructor | typeof FlowModel<any>>): void;
|
|
263
|
+
/**
|
|
264
|
+
* Register multiple model loader entries.
|
|
265
|
+
* The `extends` field declares parent class(es) for async subclass discovery via `getSubclassesOfAsync`.
|
|
266
|
+
* It accepts `string | ModelConstructor | (string | ModelConstructor)[]` and is normalized to `string[]` internally.
|
|
267
|
+
* @param {FlowModelLoaderInputMap} loaders Model loader input map
|
|
268
|
+
* @returns {void}
|
|
269
|
+
* @example
|
|
270
|
+
* flowEngine.registerModelLoaders({
|
|
271
|
+
* DemoModel: {
|
|
272
|
+
* extends: 'BaseModel',
|
|
273
|
+
* loader: () => import('./models/DemoModel'),
|
|
274
|
+
* },
|
|
275
|
+
* });
|
|
276
|
+
*/
|
|
277
|
+
registerModelLoaders(loaders: FlowModelLoaderInputMap): void;
|
|
278
|
+
/**
|
|
279
|
+
* Get a registered model class (constructor) asynchronously.
|
|
280
|
+
* This will first ensure the model loader entry is resolved.
|
|
281
|
+
* @param {string} name Model class name
|
|
282
|
+
* @returns {Promise<ModelConstructor | undefined>} Model constructor, or undefined if not found
|
|
283
|
+
*/
|
|
284
|
+
getModelClassAsync(name: string): Promise<ModelConstructor | undefined>;
|
|
285
|
+
/**
|
|
286
|
+
* Get all registered model classes asynchronously.
|
|
287
|
+
* This will first ensure all registered model loader entries are resolved.
|
|
288
|
+
* @returns {Promise<Map<string, ModelConstructor>>} Model class map
|
|
289
|
+
*/
|
|
290
|
+
getModelClassesAsync(): Promise<Map<string, ModelConstructor>>;
|
|
291
|
+
/**
|
|
292
|
+
* Create and register a model instance asynchronously.
|
|
293
|
+
* This will first ensure all string-based model references in the model tree are resolved.
|
|
294
|
+
* @template T FlowModel subclass type, defaults to FlowModel.
|
|
295
|
+
* @param {CreateModelOptions} options Model creation options
|
|
296
|
+
* @returns {Promise<T>} Created model instance
|
|
297
|
+
*/
|
|
298
|
+
createModelAsync<T extends FlowModel = FlowModel>(options: CreateModelOptions, extra?: {
|
|
299
|
+
delegateToParent?: boolean;
|
|
300
|
+
delegate?: FlowContext;
|
|
301
|
+
}): Promise<T>;
|
|
302
|
+
/**
|
|
303
|
+
* Normalize a loader result into a model constructor.
|
|
304
|
+
* @param {string} name Model class name
|
|
305
|
+
* @param {FlowModelLoaderResult} loaded Loader result
|
|
306
|
+
* @returns {ModelConstructor | null} Normalized model constructor
|
|
307
|
+
* @private
|
|
308
|
+
*/
|
|
309
|
+
private normalizeModelLoaderResult;
|
|
310
|
+
/**
|
|
311
|
+
* Collect string-based model names from a model tree.
|
|
312
|
+
* @param {unknown} data Model tree data
|
|
313
|
+
* @param {Set<string>} names Model name set
|
|
314
|
+
* @private
|
|
315
|
+
*/
|
|
316
|
+
private collectModelNamesFromTree;
|
|
317
|
+
/**
|
|
318
|
+
* Collect additional model names from object-form meta.createModelOptions defaults.
|
|
319
|
+
* @param {ModelConstructor} modelClass Model class constructor
|
|
320
|
+
* @param {Set<string>} names Model name set
|
|
321
|
+
* @private
|
|
322
|
+
*/
|
|
323
|
+
private collectModelNamesFromMetaDefaults;
|
|
324
|
+
/**
|
|
325
|
+
* Ensure a single model class is available.
|
|
326
|
+
* @param {string} name Model class name
|
|
327
|
+
* @returns {Promise<ModelConstructor | null>} Model constructor or null when resolution fails
|
|
328
|
+
* @private
|
|
329
|
+
*/
|
|
330
|
+
private ensureModel;
|
|
331
|
+
/**
|
|
332
|
+
* Ensure multiple model classes are available.
|
|
333
|
+
* @param {string[]} names Model class names
|
|
334
|
+
* @returns {Promise<EnsureBatchResult>} Batch ensure result
|
|
335
|
+
* @private
|
|
336
|
+
*/
|
|
337
|
+
private ensureModels;
|
|
338
|
+
/**
|
|
339
|
+
* Resolve all unresolved string-based model references in a model tree before synchronous creation begins.
|
|
340
|
+
*
|
|
341
|
+
* Use this when you already have a model tree object, such as repository-returned data or resolved
|
|
342
|
+
* `createModelOptions`, and you need to ensure every string `use` in that tree has been loaded and
|
|
343
|
+
* registered into `_modelClasses` before calling `createModel()`.
|
|
344
|
+
*
|
|
345
|
+
* @param {unknown} data Model tree data
|
|
346
|
+
* @returns {Promise<EnsureBatchResult>} Batch ensure result
|
|
347
|
+
*/
|
|
348
|
+
resolveModelTree(data: unknown): Promise<EnsureBatchResult>;
|
|
349
|
+
/**
|
|
350
|
+
* Preload all currently registered unresolved model loaders.
|
|
351
|
+
*
|
|
352
|
+
* This method is intended for flow-settings/discovery style entry points that need registered model
|
|
353
|
+
* classes to exist before UI is rendered, without requiring callers to know which specific models
|
|
354
|
+
* will be touched next.
|
|
355
|
+
*
|
|
356
|
+
* @returns {Promise<EnsureBatchResult>} Batch ensure result
|
|
357
|
+
*/
|
|
358
|
+
preloadModelLoaders(): Promise<EnsureBatchResult>;
|
|
219
359
|
registerResources(resources: Record<string, any>): void;
|
|
220
360
|
createResource<T = FlowResource>(resourceType: ResourceType<T>, options?: {
|
|
221
361
|
context?: FlowContext;
|
|
@@ -244,6 +384,15 @@ export declare class FlowEngine {
|
|
|
244
384
|
* @returns {Map<string, ModelConstructor>} Model classes inherited from base class and passed the filter
|
|
245
385
|
*/
|
|
246
386
|
getSubclassesOf(baseClass: string | ModelConstructor, filter?: (ModelClass: ModelConstructor, className: string) => boolean): Map<string, ModelConstructor>;
|
|
387
|
+
/**
|
|
388
|
+
* Asynchronously get all subclasses of a base class, including those registered via model loaders.
|
|
389
|
+
* Merges results from already-loaded classes (_modelClasses) and async loader entries with matching `extends` declarations.
|
|
390
|
+
* Loader-resolved classes are validated with `isInheritedFrom`; mismatches are warned and excluded.
|
|
391
|
+
* @param {string | ModelConstructor} baseClass Base class name or constructor
|
|
392
|
+
* @param {(ModelClass: ModelConstructor, className: string) => boolean} [filter] Optional filter function
|
|
393
|
+
* @returns {Promise<Map<string, ModelConstructor>>} Model classes that are subclasses of the base class
|
|
394
|
+
*/
|
|
395
|
+
getSubclassesOfAsync(baseClass: string | ModelConstructor, filter?: (ModelClass: ModelConstructor, className: string) => boolean): Promise<Map<string, ModelConstructor>>;
|
|
247
396
|
/**
|
|
248
397
|
* Create and register a model instance.
|
|
249
398
|
* If an instance with the same UID exists, returns the existing instance.
|
|
@@ -333,6 +482,7 @@ export declare class FlowEngine {
|
|
|
333
482
|
* @returns {Promise<T | null>} Model instance or null
|
|
334
483
|
*/
|
|
335
484
|
loadOrCreateModel<T extends FlowModel = FlowModel>(options: any, extra?: {
|
|
485
|
+
skipSave?: boolean;
|
|
336
486
|
delegateToParent?: boolean;
|
|
337
487
|
delegate?: FlowContext;
|
|
338
488
|
}): Promise<T | null>;
|