@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
|
@@ -41,11 +41,12 @@ __export(MobilePopup_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(MobilePopup_exports);
|
|
43
43
|
var import_antd = require("antd");
|
|
44
|
-
var import_antd_mobile = require("antd-mobile");
|
|
45
44
|
var import_react = __toESM(require("react"));
|
|
46
|
-
var import_antd_mobile_icons = require("antd-mobile-icons");
|
|
47
45
|
var import_MobilePopup = require("./MobilePopup.style");
|
|
48
46
|
var import_react_i18next = require("react-i18next");
|
|
47
|
+
var import_lazy_helper = require("../lazy-helper");
|
|
48
|
+
const { Popup } = (0, import_lazy_helper.lazy)(() => import("antd-mobile"), "Popup");
|
|
49
|
+
const { CloseOutline } = (0, import_lazy_helper.lazy)(() => import("antd-mobile-icons"), "CloseOutline");
|
|
49
50
|
const MobilePopup = /* @__PURE__ */ __name((props) => {
|
|
50
51
|
const { title, visible, onClose: closePopup, children, minHeight, className, footer } = props;
|
|
51
52
|
const { t } = (0, import_react_i18next.useTranslation)();
|
|
@@ -67,7 +68,7 @@ const MobilePopup = /* @__PURE__ */ __name((props) => {
|
|
|
67
68
|
};
|
|
68
69
|
}, []);
|
|
69
70
|
return /* @__PURE__ */ import_react.default.createElement(import_antd.ConfigProvider, { theme }, /* @__PURE__ */ import_react.default.createElement(
|
|
70
|
-
|
|
71
|
+
Popup,
|
|
71
72
|
{
|
|
72
73
|
className: `${componentCls} ${hashId} ${className || ""}`,
|
|
73
74
|
visible,
|
|
@@ -81,7 +82,7 @@ const MobilePopup = /* @__PURE__ */ __name((props) => {
|
|
|
81
82
|
style,
|
|
82
83
|
destroyOnClose: true
|
|
83
84
|
},
|
|
84
|
-
/* @__PURE__ */ import_react.default.createElement("div", { className: "nb-mobile-action-drawer-header" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "nb-mobile-action-drawer-placeholder" }, /* @__PURE__ */ import_react.default.createElement(
|
|
85
|
+
/* @__PURE__ */ import_react.default.createElement("div", { className: "nb-mobile-action-drawer-header" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "nb-mobile-action-drawer-placeholder" }, /* @__PURE__ */ import_react.default.createElement(CloseOutline, null)), /* @__PURE__ */ import_react.default.createElement("span", null, title), /* @__PURE__ */ import_react.default.createElement(
|
|
85
86
|
"span",
|
|
86
87
|
{
|
|
87
88
|
className: "nb-mobile-action-drawer-close-icon",
|
|
@@ -90,7 +91,7 @@ const MobilePopup = /* @__PURE__ */ __name((props) => {
|
|
|
90
91
|
tabIndex: 0,
|
|
91
92
|
"aria-label": t("Close")
|
|
92
93
|
},
|
|
93
|
-
/* @__PURE__ */ import_react.default.createElement(
|
|
94
|
+
/* @__PURE__ */ import_react.default.createElement(CloseOutline, null)
|
|
94
95
|
)),
|
|
95
96
|
children,
|
|
96
97
|
footer && /* @__PURE__ */ import_react.default.createElement("div", { className: "nb-mobile-action-drawer-footer" }, footer)
|
|
@@ -430,7 +430,7 @@ const AddSubModelButtonCore = /* @__PURE__ */ __name(function AddSubModelButton(
|
|
|
430
430
|
}
|
|
431
431
|
let addedModel;
|
|
432
432
|
try {
|
|
433
|
-
addedModel = model.flowEngine.
|
|
433
|
+
addedModel = await model.flowEngine.createModelAsync({
|
|
434
434
|
...import_lodash.default.cloneDeep(createOpts),
|
|
435
435
|
parentId: model.uid,
|
|
436
436
|
subKey: subModelKey,
|
|
@@ -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/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.
|
|
@@ -226,6 +248,10 @@ export declare class FlowEngine {
|
|
|
226
248
|
* Get all registered global events.
|
|
227
249
|
*/
|
|
228
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;
|
|
229
255
|
/**
|
|
230
256
|
* Register multiple model classes.
|
|
231
257
|
* @param {Record<string, ModelConstructor>} models Model class map, key is model name, value is model constructor
|
|
@@ -234,6 +260,102 @@ export declare class FlowEngine {
|
|
|
234
260
|
* flowEngine.registerModels({ UserModel, OrderModel });
|
|
235
261
|
*/
|
|
236
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>;
|
|
237
359
|
registerResources(resources: Record<string, any>): void;
|
|
238
360
|
createResource<T = FlowResource>(resourceType: ResourceType<T>, options?: {
|
|
239
361
|
context?: FlowContext;
|
|
@@ -262,6 +384,15 @@ export declare class FlowEngine {
|
|
|
262
384
|
* @returns {Map<string, ModelConstructor>} Model classes inherited from base class and passed the filter
|
|
263
385
|
*/
|
|
264
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>>;
|
|
265
396
|
/**
|
|
266
397
|
* Create and register a model instance.
|
|
267
398
|
* If an instance with the same UID exists, returns the existing instance.
|