@nocobase/flow-engine 2.1.0-alpha.3 → 2.1.0-alpha.30
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/FieldModelRenderer.js +2 -2
- package/lib/components/FlowModelRenderer.d.ts +3 -1
- package/lib/components/FlowModelRenderer.js +12 -6
- package/lib/components/MobilePopup.js +6 -5
- package/lib/components/dnd/gridDragPlanner.d.ts +59 -2
- package/lib/components/dnd/gridDragPlanner.js +601 -21
- package/lib/components/dnd/index.d.ts +19 -1
- package/lib/components/dnd/index.js +243 -23
- package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +2 -1
- package/lib/components/settings/wrappers/component/SelectWithTitle.js +14 -12
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +68 -10
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +23 -43
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +352 -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 +274 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +315 -0
- package/lib/components/subModel/AddSubModelButton.js +27 -1
- package/lib/components/subModel/index.d.ts +1 -0
- package/lib/components/subModel/index.js +19 -0
- package/lib/components/subModel/utils.d.ts +1 -1
- package/lib/components/subModel/utils.js +2 -2
- package/lib/data-source/index.d.ts +73 -0
- package/lib/data-source/index.js +211 -1
- package/lib/executor/FlowExecutor.js +31 -8
- package/lib/flowContext.d.ts +2 -0
- package/lib/flowContext.js +31 -1
- package/lib/flowEngine.d.ts +151 -1
- package/lib/flowEngine.js +389 -15
- package/lib/flowI18n.js +2 -1
- 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/DisplayItemModel.d.ts +1 -1
- package/lib/models/EditableItemModel.d.ts +1 -1
- package/lib/models/FilterableItemModel.d.ts +1 -1
- package/lib/models/flowModel.d.ts +13 -10
- package/lib/models/flowModel.js +78 -18
- package/lib/provider.js +38 -23
- 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/createCollectionContextMeta.js +6 -2
- 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__/objectVariable.test.ts +24 -0
- package/src/__tests__/provider.test.tsx +24 -2
- 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/FieldModelRenderer.tsx +2 -1
- package/src/components/FlowModelRenderer.tsx +18 -6
- package/src/components/MobilePopup.tsx +4 -2
- package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
- package/src/components/__tests__/dnd.test.ts +44 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +20 -10
- package/src/components/__tests__/gridDragPlanner.test.ts +512 -3
- package/src/components/dnd/__tests__/DndProvider.test.tsx +98 -0
- package/src/components/dnd/gridDragPlanner.ts +743 -19
- package/src/components/dnd/index.tsx +291 -27
- package/src/components/settings/wrappers/component/SelectWithTitle.tsx +21 -9
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +88 -10
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +487 -440
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +18 -2
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +189 -3
- package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +778 -0
- package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +360 -0
- package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +361 -0
- package/src/components/subModel/AddSubModelButton.tsx +32 -2
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +142 -32
- package/src/components/subModel/index.ts +1 -0
- package/src/components/subModel/utils.ts +1 -1
- package/src/data-source/__tests__/index.test.ts +34 -1
- package/src/data-source/index.ts +258 -2
- package/src/executor/FlowExecutor.ts +34 -9
- package/src/executor/__tests__/flowExecutor.test.ts +57 -0
- package/src/flowContext.ts +37 -3
- package/src/flowEngine.ts +445 -11
- package/src/flowI18n.ts +2 -1
- 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/DisplayItemModel.tsx +1 -1
- package/src/models/EditableItemModel.tsx +1 -1
- package/src/models/FilterableItemModel.tsx +1 -1
- package/src/models/__tests__/dispatchEvent.when.test.ts +214 -0
- package/src/models/__tests__/flowModel.test.ts +19 -3
- package/src/models/flowModel.tsx +119 -33
- package/src/provider.tsx +41 -25
- 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__/createCollectionContextMeta.test.ts +48 -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/createCollectionContextMeta.ts +6 -2
- 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
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>;
|