@nocobase/flow-engine 2.1.0-beta.15 → 2.1.0-beta.17
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/components/MobilePopup.js +6 -5
- package/lib/components/subModel/AddSubModelButton.js +1 -1
- package/lib/components/subModel/utils.js +2 -2
- package/lib/flowEngine.d.ts +132 -1
- package/lib/flowEngine.js +360 -14
- 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/models/flowModel.js +17 -7
- package/lib/types.d.ts +46 -0
- package/lib/utils/runjsTemplateCompat.js +1 -1
- package/package.json +4 -4
- package/src/__tests__/flow-engine.test.ts +166 -0
- 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__/viewScopedFlowEngine.test.ts +3 -3
- package/src/components/MobilePopup.tsx +4 -2
- package/src/components/__tests__/FlowModelRenderer.test.tsx +22 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +3 -3
- package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +6 -6
- package/src/components/subModel/AddSubModelButton.tsx +1 -1
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +93 -33
- package/src/components/subModel/utils.ts +1 -1
- package/src/flowEngine.ts +412 -10
- package/src/flowSettings.ts +40 -6
- package/src/lazy-helper.tsx +57 -0
- package/src/models/flowModel.tsx +18 -6
- package/src/types.ts +59 -0
- package/src/utils/runjsTemplateCompat.ts +1 -1
package/src/models/flowModel.tsx
CHANGED
|
@@ -11,8 +11,6 @@ import { batch, define, observable, observe } from '@formily/reactive';
|
|
|
11
11
|
import _ from 'lodash';
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import { uid } from 'uid/secure';
|
|
14
|
-
import { openRequiredParamsStepFormDialog as openRequiredParamsStepFormDialogFn } from '../components/settings/wrappers/contextual/StepRequiredSettingsDialog';
|
|
15
|
-
import { openStepSettingsDialog as openStepSettingsDialogFn } from '../components/settings/wrappers/contextual/StepSettingsDialog';
|
|
16
14
|
import { Emitter } from '../emitter';
|
|
17
15
|
import { InstanceFlowRegistry } from '../flow-registry/InstanceFlowRegistry';
|
|
18
16
|
import { FlowContext, FlowModelContext, FlowRuntimeContext } from '../flowContext';
|
|
@@ -36,8 +34,8 @@ import type {
|
|
|
36
34
|
import { IModelComponentProps, ReadonlyModelProps } from '../types';
|
|
37
35
|
import { isInheritedFrom, setupRuntimeContextSteps } from '../utils';
|
|
38
36
|
// import { FlowExitAllException } from '../utils/exceptions';
|
|
37
|
+
import { Typography } from 'antd';
|
|
39
38
|
import type { MenuProps } from 'antd';
|
|
40
|
-
import { Typography } from 'antd/lib';
|
|
41
39
|
import { observer } from '..';
|
|
42
40
|
import { ModelActionRegistry } from '../action-registry/ModelActionRegistry';
|
|
43
41
|
import { buildSubModelItem } from '../components/subModel/utils';
|
|
@@ -88,6 +86,16 @@ type ExtraMenuItemEntry = {
|
|
|
88
86
|
|
|
89
87
|
const classMenuExtensions = new WeakMap<typeof FlowModel, Set<ExtraMenuItemEntry>>();
|
|
90
88
|
|
|
89
|
+
async function loadOpenStepSettingsDialog() {
|
|
90
|
+
const mod = await import('../components/settings/wrappers/contextual/StepSettingsDialog');
|
|
91
|
+
return mod.openStepSettingsDialog;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function loadOpenRequiredParamsStepFormDialog() {
|
|
95
|
+
const mod = await import('../components/settings/wrappers/contextual/StepRequiredSettingsDialog');
|
|
96
|
+
return mod.openRequiredParamsStepFormDialog;
|
|
97
|
+
}
|
|
98
|
+
|
|
91
99
|
export enum ModelRenderMode {
|
|
92
100
|
ReactElement = 'reactElement',
|
|
93
101
|
RenderFunction = 'renderFunction',
|
|
@@ -1378,7 +1386,7 @@ export class FlowModel<Structure extends DefaultStructure = DefaultStructure> {
|
|
|
1378
1386
|
* @param {string} stepKey 步骤的唯一标识符
|
|
1379
1387
|
* @returns {void}
|
|
1380
1388
|
*/
|
|
1381
|
-
openStepSettingsDialog(flowKey: string, stepKey: string) {
|
|
1389
|
+
async openStepSettingsDialog(flowKey: string, stepKey: string) {
|
|
1382
1390
|
// 创建流程运行时上下文
|
|
1383
1391
|
const flow = this.getFlow(flowKey);
|
|
1384
1392
|
const step = flow?.steps?.[stepKey];
|
|
@@ -1392,7 +1400,9 @@ export class FlowModel<Structure extends DefaultStructure = DefaultStructure> {
|
|
|
1392
1400
|
setupRuntimeContextSteps(ctx, flow.steps, this, flowKey);
|
|
1393
1401
|
ctx.defineProperty('currentStep', { value: step });
|
|
1394
1402
|
|
|
1395
|
-
|
|
1403
|
+
const openStepSettingsDialog = await loadOpenStepSettingsDialog();
|
|
1404
|
+
|
|
1405
|
+
return openStepSettingsDialog({
|
|
1396
1406
|
model: this,
|
|
1397
1407
|
flowKey,
|
|
1398
1408
|
stepKey,
|
|
@@ -1408,7 +1418,9 @@ export class FlowModel<Structure extends DefaultStructure = DefaultStructure> {
|
|
|
1408
1418
|
* @returns {Promise<any>} 返回表单提交的值
|
|
1409
1419
|
*/
|
|
1410
1420
|
async configureRequiredSteps(dialogWidth?: number | string, dialogTitle?: string) {
|
|
1411
|
-
|
|
1421
|
+
const openRequiredParamsStepFormDialog = await loadOpenRequiredParamsStepFormDialog();
|
|
1422
|
+
|
|
1423
|
+
return openRequiredParamsStepFormDialog({
|
|
1412
1424
|
model: this,
|
|
1413
1425
|
dialogWidth,
|
|
1414
1426
|
dialogTitle,
|
package/src/types.ts
CHANGED
|
@@ -388,6 +388,65 @@ export interface CreateModelOptions {
|
|
|
388
388
|
delegateToParent?: boolean;
|
|
389
389
|
[key: string]: any; // 允许额外的自定义选项
|
|
390
390
|
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* FlowModel loader result.
|
|
394
|
+
* Supports returning the model constructor directly, a default export, or a module object containing the named export.
|
|
395
|
+
*/
|
|
396
|
+
export type FlowModelLoaderResult =
|
|
397
|
+
| ModelConstructor
|
|
398
|
+
| {
|
|
399
|
+
default?: ModelConstructor;
|
|
400
|
+
[key: string]: unknown;
|
|
401
|
+
}
|
|
402
|
+
| Record<string, unknown>;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* FlowModel loader function.
|
|
406
|
+
*/
|
|
407
|
+
export type FlowModelLoader = () => Promise<FlowModelLoaderResult>;
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* FlowModel loader entry (normalized internal form).
|
|
411
|
+
*/
|
|
412
|
+
export interface FlowModelLoaderEntry {
|
|
413
|
+
loader: FlowModelLoader;
|
|
414
|
+
extends?: string[];
|
|
415
|
+
// meta?: Partial<FlowModelMeta>;
|
|
416
|
+
// scenes?: string[];
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* FlowModel loader input (user-facing form for registerModelLoaders).
|
|
421
|
+
* The `extends` field accepts flexible formats that will be normalized to `string[]` at registration time.
|
|
422
|
+
*/
|
|
423
|
+
export interface FlowModelLoaderInput {
|
|
424
|
+
loader: FlowModelLoader;
|
|
425
|
+
extends?: string | ModelConstructor | (string | ModelConstructor)[];
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* FlowModel loader entry map (normalized internal form).
|
|
430
|
+
*/
|
|
431
|
+
export type FlowModelLoaderMap = Record<string, FlowModelLoaderEntry>;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* FlowModel loader input map (user-facing form for registerModelLoaders).
|
|
435
|
+
*/
|
|
436
|
+
export type FlowModelLoaderInputMap = Record<string, FlowModelLoaderInput>;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Batch ensure result.
|
|
440
|
+
*/
|
|
441
|
+
export interface EnsureBatchResult {
|
|
442
|
+
requested: string[];
|
|
443
|
+
loaded: string[];
|
|
444
|
+
failed: Array<{
|
|
445
|
+
name: string;
|
|
446
|
+
error?: unknown;
|
|
447
|
+
}>;
|
|
448
|
+
}
|
|
449
|
+
|
|
391
450
|
export interface IFlowModelRepository<T extends FlowModel = FlowModel> {
|
|
392
451
|
findOne(query: Record<string, any>): Promise<Record<string, any> | null>;
|
|
393
452
|
save(model: T, options?: { onlyStepParams?: boolean }): Promise<Record<string, any>>;
|
|
@@ -553,8 +553,8 @@ function extractUsedCtxLibKeys(code: string): string[] {
|
|
|
553
553
|
}
|
|
554
554
|
|
|
555
555
|
function injectEnsureLibsPreamble(code: string): string {
|
|
556
|
-
if (!CTX_LIBS_MARKER_RE.test(code)) return code;
|
|
557
556
|
if (ENSURE_LIBS_MARKER_RE.test(code)) return code;
|
|
557
|
+
if (!CTX_LIBS_MARKER_RE.test(code)) return code;
|
|
558
558
|
const keys = extractUsedCtxLibKeys(code);
|
|
559
559
|
if (!keys.length) return code;
|
|
560
560
|
return `/* __runjs_ensure_libs */\nawait ctx.__ensureLibs(${JSON.stringify(keys)});\n${code}`;
|