@nocobase/flow-engine 2.0.0-alpha.9 → 2.0.0-beta.2
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/BlockScopedFlowEngine.d.ts +23 -0
- package/lib/BlockScopedFlowEngine.js +92 -0
- package/lib/FlowDefinition.d.ts +6 -4
- package/lib/JSRunner.js +3 -0
- package/lib/ViewScopedFlowEngine.js +15 -1
- package/lib/acl/Acl.d.ts +12 -12
- package/lib/acl/Acl.js +78 -30
- package/lib/components/DynamicFlowsEditor.js +2 -4
- package/lib/components/FieldModelRenderer.js +10 -8
- package/lib/components/FieldSkeleton.d.ts +10 -0
- package/lib/components/FieldSkeleton.js +64 -0
- package/lib/components/FlowContextSelector.js +19 -3
- package/lib/components/FlowModelRenderer.d.ts +2 -1
- package/lib/components/FlowModelRenderer.js +34 -12
- package/lib/components/FormItem.js +5 -1
- package/lib/components/MobilePopup.d.ts +20 -0
- package/lib/components/MobilePopup.js +102 -0
- package/lib/components/MobilePopup.style.d.ts +17 -0
- package/lib/components/MobilePopup.style.js +186 -0
- package/lib/components/common/withFlowDesignMode.d.ts +1 -1
- package/lib/components/common/withFlowDesignMode.js +5 -5
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +3 -1
- package/lib/components/settings/independents/dropdown/FlowsDropdownButton.js +71 -53
- package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +19 -0
- package/lib/components/settings/wrappers/component/SelectWithTitle.js +136 -0
- package/lib/components/settings/wrappers/component/SwitchWithTitle.d.ts +10 -0
- package/lib/components/settings/wrappers/component/SwitchWithTitle.js +110 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +221 -93
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +71 -54
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +2 -2
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +63 -23
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +11 -6
- package/lib/components/settings/wrappers/embedded/FlowSettings.js +42 -28
- package/lib/components/settings/wrappers/embedded/FlowsSettings.js +3 -3
- package/lib/components/settings/wrappers/embedded/FlowsSettingsContent.js +52 -32
- package/lib/components/subModel/AddSubModelButton.d.ts +7 -0
- package/lib/components/subModel/AddSubModelButton.js +78 -8
- package/lib/components/subModel/LazyDropdown.js +14 -15
- package/lib/components/subModel/utils.d.ts +1 -1
- package/lib/components/subModel/utils.js +21 -11
- package/lib/components/variables/VariableInput.js +5 -3
- package/lib/components/variables/types.d.ts +2 -0
- package/lib/components/variables/utils.js +4 -2
- package/lib/data-source/index.d.ts +43 -4
- package/lib/data-source/index.js +104 -11
- package/lib/data-source/jioToJoiSchema.js +1 -0
- package/lib/emitter.d.ts +6 -0
- package/lib/emitter.js +12 -0
- package/lib/executor/FlowExecutor.js +48 -7
- package/lib/flow-registry/GlobalFlowRegistry.d.ts +1 -0
- package/lib/flow-registry/GlobalFlowRegistry.js +3 -0
- package/lib/flow-registry/InstanceFlowRegistry.d.ts +1 -0
- package/lib/flow-registry/InstanceFlowRegistry.js +3 -0
- package/lib/flowContext.d.ts +6 -0
- package/lib/flowContext.js +111 -30
- package/lib/flowEngine.d.ts +49 -0
- package/lib/flowEngine.js +265 -10
- package/lib/flowSettings.d.ts +4 -3
- package/lib/flowSettings.js +33 -11
- package/lib/hooks/useApplyAutoFlows.d.ts +1 -0
- package/lib/hooks/useApplyAutoFlows.js +2 -2
- package/lib/index.d.ts +4 -2
- package/lib/index.js +11 -5
- package/lib/locale/de-DE.json +62 -0
- package/lib/locale/en-US.json +57 -45
- package/lib/locale/es-ES.json +62 -0
- package/lib/locale/fr-FR.json +62 -0
- package/lib/locale/hu-HU.json +62 -0
- package/lib/locale/id-ID.json +62 -0
- package/lib/locale/index.d.ts +114 -90
- package/lib/locale/it-IT.json +62 -0
- package/lib/locale/ja-JP.json +62 -0
- package/lib/locale/ko-KR.json +62 -0
- package/lib/locale/nl-NL.json +62 -0
- package/lib/locale/pt-BR.json +62 -0
- package/lib/locale/ru-RU.json +62 -0
- package/lib/locale/tr-TR.json +62 -0
- package/lib/locale/uk-UA.json +62 -0
- package/lib/locale/vi-VN.json +62 -0
- package/lib/locale/zh-CN.json +58 -46
- package/lib/locale/zh-TW.json +62 -0
- package/lib/models/CollectionFieldModel.d.ts +6 -2
- package/lib/models/CollectionFieldModel.js +60 -14
- package/lib/models/flowModel.d.ts +43 -4
- package/lib/models/flowModel.js +128 -26
- package/lib/models/forkFlowModel.d.ts +6 -2
- package/lib/models/forkFlowModel.js +9 -2
- package/lib/provider.d.ts +3 -1
- package/lib/provider.js +4 -3
- package/lib/reactive/index.d.ts +10 -0
- package/lib/reactive/index.js +41 -0
- package/lib/reactive/observer.d.ts +19 -0
- package/lib/reactive/observer.js +109 -0
- package/lib/resources/baseRecordResource.d.ts +1 -0
- package/lib/resources/baseRecordResource.js +14 -3
- package/lib/resources/multiRecordResource.d.ts +4 -2
- package/lib/resources/multiRecordResource.js +15 -6
- package/lib/resources/singleRecordResource.js +6 -3
- package/lib/resources/sqlResource.d.ts +1 -0
- package/lib/resources/sqlResource.js +22 -25
- package/lib/runjs-context/contexts/base.js +42 -6
- package/lib/runjs-context/snippets/global/clipboard-copy-text.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/global/clipboard-copy-text.snippet.js +61 -0
- package/lib/runjs-context/snippets/index.js +3 -0
- package/lib/runjs-context/snippets/scene/block/render-antd-icons.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-antd-icons.snippet.js +65 -0
- package/lib/runjs-context/snippets/scene/block/render-button-handler.snippet.js +6 -4
- package/lib/runjs-context/snippets/scene/block/render-info-card.snippet.js +15 -16
- package/lib/runjs-context/snippets/scene/block/render-react-jsx.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/block/render-react-jsx.snippet.js +58 -0
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +7 -7
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +24 -29
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +20 -21
- package/lib/scheduler/ModelOperationScheduler.d.ts +51 -0
- package/lib/scheduler/ModelOperationScheduler.js +262 -0
- package/lib/types.d.ts +42 -7
- package/lib/types.js +4 -3
- package/lib/utils/associationObjectVariable.d.ts +32 -0
- package/lib/utils/associationObjectVariable.js +157 -0
- package/lib/utils/createCollectionContextMeta.d.ts +1 -1
- package/lib/utils/createCollectionContextMeta.js +8 -4
- package/lib/utils/createEphemeralContext.d.ts +13 -0
- package/lib/utils/createEphemeralContext.js +140 -0
- package/lib/utils/flows.d.ts +10 -0
- package/lib/utils/flows.js +48 -0
- package/lib/utils/index.d.ts +7 -3
- package/lib/utils/index.js +20 -0
- package/lib/utils/jsxTransform.d.ts +15 -0
- package/lib/utils/jsxTransform.js +68 -0
- package/lib/utils/params-resolvers.js +3 -3
- package/lib/utils/parsePathnameToViewParams.d.ts +1 -1
- package/lib/utils/parsePathnameToViewParams.js +41 -5
- package/lib/utils/pruneFilter.d.ts +21 -0
- package/lib/utils/pruneFilter.js +52 -0
- package/lib/utils/safeGlobals.d.ts +5 -3
- package/lib/utils/safeGlobals.js +42 -1
- package/lib/utils/schema-utils.d.ts +6 -0
- package/lib/utils/schema-utils.js +71 -6
- package/lib/utils/serverContextParams.d.ts +3 -0
- package/lib/utils/serverContextParams.js +2 -0
- package/lib/utils/translation.d.ts +4 -1
- package/lib/utils/translation.js +6 -2
- package/lib/utils/variablesParams.d.ts +21 -5
- package/lib/utils/variablesParams.js +103 -34
- package/lib/views/DialogComponent.js +1 -5
- package/lib/views/DrawerComponent.js +18 -9
- package/lib/views/PageComponent.js +3 -4
- package/lib/views/ViewNavigation.d.ts +11 -15
- package/lib/views/ViewNavigation.js +37 -19
- package/lib/views/createViewMeta.d.ts +3 -2
- package/lib/views/createViewMeta.js +164 -53
- package/lib/views/useDialog.d.ts +2 -1
- package/lib/views/useDialog.js +36 -30
- package/lib/views/useDrawer.d.ts +2 -1
- package/lib/views/useDrawer.js +33 -26
- package/lib/views/usePage.d.ts +2 -1
- package/lib/views/usePage.js +40 -29
- package/package.json +6 -3
- package/src/BlockScopedFlowEngine.ts +88 -0
- package/src/JSRunner.ts +3 -0
- package/src/ViewScopedFlowEngine.ts +16 -0
- package/src/__tests__/JSRunner.test.ts +62 -53
- package/src/__tests__/blockScopedFlowEngine.test.ts +154 -0
- package/src/__tests__/createViewMeta.popup.test.ts +142 -0
- package/src/__tests__/flow-engine.test.ts +3 -0
- package/src/__tests__/flowContext.test.ts +70 -0
- package/src/__tests__/flowEngine.destroyModel.test.ts +74 -0
- package/src/__tests__/flowEngine.moveModel.test.ts +43 -0
- package/src/__tests__/flowEngine.removeModel.test.ts +72 -0
- package/src/__tests__/flowEngine.saveModel.test.ts +4 -0
- package/src/__tests__/flowModel.openView.navigation.test.ts +3 -2
- package/src/__tests__/flowSettings.open.test.tsx +2 -0
- package/src/__tests__/flowSettings.test.ts +2 -0
- package/src/__tests__/globalFlowRegistry.test.ts +1 -1
- package/src/__tests__/modelOperationScheduler.test.ts +346 -0
- package/src/__tests__/objectVariable.test.ts +464 -0
- package/src/__tests__/runjsRuntimeFeatures.test.ts +12 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +98 -0
- package/src/acl/Acl.tsx +85 -31
- package/src/acl/__tests__/Acl.test.tsx +43 -1
- package/src/components/DynamicFlowsEditor.tsx +0 -10
- package/src/components/FieldModelRenderer.tsx +15 -8
- package/src/components/FieldSkeleton.tsx +27 -0
- package/src/components/FlowContextSelector.tsx +20 -2
- package/src/components/FlowModelRenderer.tsx +46 -12
- package/src/components/FormItem.tsx +8 -1
- package/src/components/MobilePopup.style.ts +220 -0
- package/src/components/MobilePopup.tsx +86 -0
- package/src/components/__tests__/FlowModelRenderer.test.tsx +89 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +1 -1
- package/src/components/common/withFlowDesignMode.tsx +5 -5
- package/src/components/index.ts +1 -0
- package/src/components/settings/independents/dropdown/FlowsDropdownButton.tsx +34 -17
- package/src/components/settings/wrappers/component/SelectWithTitle.tsx +110 -0
- package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +82 -0
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +260 -121
- package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +34 -18
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +56 -18
- package/src/components/settings/wrappers/contextual/StepSettings.tsx +1 -2
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +12 -6
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +565 -0
- package/src/components/settings/wrappers/embedded/FlowSettings.tsx +47 -35
- package/src/components/settings/wrappers/embedded/FlowsSettings.tsx +1 -1
- package/src/components/settings/wrappers/embedded/FlowsSettingsContent.tsx +64 -42
- package/src/components/subModel/AddSubModelButton.tsx +104 -9
- package/src/components/subModel/LazyDropdown.tsx +14 -14
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +168 -7
- package/src/components/subModel/__tests__/utils.test.ts +12 -12
- package/src/components/subModel/utils.ts +25 -6
- package/src/components/variables/VariableInput.tsx +5 -3
- package/src/components/variables/types.ts +2 -0
- package/src/components/variables/utils.ts +7 -3
- package/src/data-source/index.ts +169 -11
- package/src/data-source/jioToJoiSchema.ts +1 -0
- package/src/emitter.ts +14 -0
- package/src/executor/FlowExecutor.ts +56 -8
- package/src/executor/__tests__/ctx-defs-injection.test.ts +197 -0
- package/src/flow-registry/GlobalFlowRegistry.ts +1 -0
- package/src/flow-registry/InstanceFlowRegistry.ts +1 -0
- package/src/flow-registry/__tests__/globalFlowRegistry.test.ts +54 -0
- package/src/flowContext.ts +144 -29
- package/src/flowEngine.ts +328 -8
- package/src/flowSettings.ts +47 -19
- package/src/hooks/useApplyAutoFlows.ts +3 -3
- package/src/index.ts +4 -2
- package/src/locale/de-DE.json +62 -0
- package/src/locale/en-US.json +57 -45
- package/src/locale/es-ES.json +62 -0
- package/src/locale/fr-FR.json +62 -0
- package/src/locale/hu-HU.json +62 -0
- package/src/locale/id-ID.json +62 -0
- package/src/locale/it-IT.json +62 -0
- package/src/locale/ja-JP.json +62 -0
- package/src/locale/ko-KR.json +62 -0
- package/src/locale/nl-NL.json +62 -0
- package/src/locale/pt-BR.json +62 -0
- package/src/locale/ru-RU.json +62 -0
- package/src/locale/tr-TR.json +62 -0
- package/src/locale/uk-UA.json +62 -0
- package/src/locale/vi-VN.json +62 -0
- package/src/locale/zh-CN.json +58 -46
- package/src/locale/zh-TW.json +62 -0
- package/src/models/CollectionFieldModel.tsx +79 -17
- package/src/models/__tests__/dispatchEvent.behavior.test.ts +169 -0
- package/src/models/__tests__/flowEngine.resolveUse.test.ts +170 -0
- package/src/models/__tests__/flowModel.getFlows.sort.test.ts +29 -5
- package/src/models/__tests__/flowModel.scheduleModelOperation.test.tsx +129 -0
- package/src/models/__tests__/flowModel.test.ts +65 -27
- package/src/models/__tests__/forkFlowModel.test.ts +40 -7
- package/src/models/flowModel.tsx +192 -30
- package/src/models/forkFlowModel.ts +11 -3
- package/src/provider.tsx +5 -5
- package/src/reactive/__tests__/observer.test.tsx +211 -0
- package/src/reactive/index.ts +11 -0
- package/src/reactive/observer.tsx +101 -0
- package/src/resources/baseRecordResource.ts +15 -3
- package/src/resources/multiRecordResource.ts +17 -8
- package/src/resources/singleRecordResource.ts +6 -3
- package/src/resources/sqlResource.ts +22 -26
- package/src/runjs-context/contexts/base.ts +47 -6
- package/src/runjs-context/snippets/global/clipboard-copy-text.snippet.ts +42 -0
- package/src/runjs-context/snippets/index.ts +3 -0
- package/src/runjs-context/snippets/scene/block/render-antd-icons.snippet.ts +46 -0
- package/src/runjs-context/snippets/scene/block/render-button-handler.snippet.ts +6 -4
- package/src/runjs-context/snippets/scene/block/render-info-card.snippet.ts +15 -16
- package/src/runjs-context/snippets/scene/block/render-react-jsx.snippet.ts +39 -0
- package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +7 -7
- package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +24 -29
- package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +20 -21
- package/src/scheduler/ModelOperationScheduler.ts +304 -0
- package/src/types.ts +50 -4
- package/src/utils/__tests__/createCollectionContextMeta.test.ts +51 -0
- package/src/utils/__tests__/flows.test.ts +65 -0
- package/src/utils/__tests__/jsxTransform.test.ts +38 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +25 -0
- package/src/utils/__tests__/pruneFilter.test.ts +38 -0
- package/src/utils/__tests__/safeGlobals.test.ts +23 -1
- package/src/utils/__tests__/utils.test.ts +114 -15
- package/src/utils/__tests__/variablesParams.test.ts +120 -0
- package/src/utils/associationObjectVariable.ts +180 -0
- package/src/utils/createCollectionContextMeta.ts +8 -3
- package/src/utils/createEphemeralContext.ts +142 -0
- package/src/utils/flows.ts +23 -0
- package/src/utils/index.ts +11 -2
- package/src/utils/jsxTransform.ts +39 -0
- package/src/utils/params-resolvers.ts +2 -2
- package/src/utils/parsePathnameToViewParams.ts +50 -6
- package/src/utils/pruneFilter.ts +41 -0
- package/src/utils/safeGlobals.ts +51 -4
- package/src/utils/schema-utils.ts +81 -3
- package/src/utils/serverContextParams.ts +5 -0
- package/src/utils/translation.ts +7 -2
- package/src/utils/variablesParams.ts +125 -42
- package/src/views/DialogComponent.tsx +1 -4
- package/src/views/DrawerComponent.tsx +19 -7
- package/src/views/PageComponent.tsx +2 -4
- package/src/views/ViewNavigation.ts +49 -43
- package/src/views/__tests__/FlowView.usePage.test.tsx +133 -0
- package/src/views/__tests__/ViewNavigation.test.ts +54 -34
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +132 -0
- package/src/views/createViewMeta.ts +179 -42
- package/src/views/useDialog.tsx +36 -24
- package/src/views/useDrawer.tsx +37 -24
- package/src/views/usePage.tsx +46 -27
package/lib/flowEngine.js
CHANGED
|
@@ -59,6 +59,8 @@ var import_flowSettings = require("./flowSettings");
|
|
|
59
59
|
var import_models = require("./models");
|
|
60
60
|
var import_ReactView = require("./ReactView");
|
|
61
61
|
var import_resources = require("./resources");
|
|
62
|
+
var import_emitter = require("./emitter");
|
|
63
|
+
var import_ModelOperationScheduler = __toESM(require("./scheduler/ModelOperationScheduler"));
|
|
62
64
|
var import_utils = require("./utils");
|
|
63
65
|
var _FlowEngine_instances, registerModel_fn;
|
|
64
66
|
const _FlowEngine = class _FlowEngine {
|
|
@@ -118,6 +120,13 @@ const _FlowEngine = class _FlowEngine {
|
|
|
118
120
|
__publicField(this, "_previousEngine");
|
|
119
121
|
__publicField(this, "_nextEngine");
|
|
120
122
|
__publicField(this, "_resources", /* @__PURE__ */ new Map());
|
|
123
|
+
/**
|
|
124
|
+
* 引擎事件总线(目前用于模型生命周期等事件)。
|
|
125
|
+
* ViewScopedFlowEngine 持有自己的实例,实现作用域隔离。
|
|
126
|
+
*/
|
|
127
|
+
__publicField(this, "emitter", new import_emitter.Emitter());
|
|
128
|
+
/** 调度器:仅在 View 作用域引擎本地启用;根/Block 作用域默认不持有 */
|
|
129
|
+
__publicField(this, "_modelOperationScheduler");
|
|
121
130
|
__publicField(this, "logger");
|
|
122
131
|
/**
|
|
123
132
|
* Flow settings, including components and form scopes.
|
|
@@ -161,6 +170,27 @@ const _FlowEngine = class _FlowEngine {
|
|
|
161
170
|
});
|
|
162
171
|
this.executor = new import_FlowExecutor.FlowExecutor(this);
|
|
163
172
|
}
|
|
173
|
+
/** 获取/创建当前引擎的调度器(仅在本地作用域) */
|
|
174
|
+
getScheduler() {
|
|
175
|
+
if (!this._modelOperationScheduler) {
|
|
176
|
+
this._modelOperationScheduler = new import_ModelOperationScheduler.default(this);
|
|
177
|
+
}
|
|
178
|
+
return this._modelOperationScheduler;
|
|
179
|
+
}
|
|
180
|
+
/** 释放并清理当前引擎本地调度器(若存在) */
|
|
181
|
+
disposeScheduler() {
|
|
182
|
+
if (this._modelOperationScheduler) {
|
|
183
|
+
try {
|
|
184
|
+
this._modelOperationScheduler.dispose();
|
|
185
|
+
} finally {
|
|
186
|
+
this._modelOperationScheduler = void 0;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** 在目标模型生命周期达成时执行操作(仅在 View 引擎本地存储计划) */
|
|
191
|
+
scheduleModelOperation(fromModelOrUid, toUid, fn, options) {
|
|
192
|
+
return this.getScheduler().schedule(fromModelOrUid, toUid, fn, options);
|
|
193
|
+
}
|
|
164
194
|
/** 上一个引擎(根引擎为 undefined) */
|
|
165
195
|
get previousEngine() {
|
|
166
196
|
return this._previousEngine;
|
|
@@ -361,8 +391,14 @@ const _FlowEngine = class _FlowEngine {
|
|
|
361
391
|
* @returns {T} Created model instance
|
|
362
392
|
*/
|
|
363
393
|
createModel(options, extra) {
|
|
394
|
+
var _a;
|
|
364
395
|
const { parentId, uid, use: modelClassName, subModels } = options;
|
|
365
|
-
const
|
|
396
|
+
const parentModel = parentId ? this.getModel(parentId) || ((_a = this.previousEngine) == null ? void 0 : _a.getModel(parentId)) : void 0;
|
|
397
|
+
const ModelClass = this._resolveModelClass(
|
|
398
|
+
typeof modelClassName === "string" ? this.getModelClass(modelClassName) : modelClassName,
|
|
399
|
+
options,
|
|
400
|
+
parentModel
|
|
401
|
+
);
|
|
366
402
|
if (uid && this._modelInstances.has(uid)) {
|
|
367
403
|
return this._modelInstances.get(uid);
|
|
368
404
|
}
|
|
@@ -376,20 +412,69 @@ const _FlowEngine = class _FlowEngine {
|
|
|
376
412
|
if (extra == null ? void 0 : extra.delegate) {
|
|
377
413
|
modelInstance.context.addDelegate(extra.delegate);
|
|
378
414
|
}
|
|
379
|
-
if (
|
|
380
|
-
modelInstance.setParent(
|
|
415
|
+
if (parentModel) {
|
|
416
|
+
modelInstance.setParent(parentModel);
|
|
381
417
|
if ((extra == null ? void 0 : extra.delegateToParent) === false) {
|
|
382
418
|
modelInstance.removeParentDelegate();
|
|
383
419
|
}
|
|
384
420
|
}
|
|
385
421
|
this._modelInstances.set(modelInstance.uid, modelInstance);
|
|
386
422
|
modelInstance.onInit(options);
|
|
423
|
+
void this.emitter.emitAsync("model:created", {
|
|
424
|
+
uid: modelInstance.uid,
|
|
425
|
+
model: modelInstance
|
|
426
|
+
});
|
|
387
427
|
this._applyFlowDefinitionDefaultParams(modelInstance).catch((err) => {
|
|
388
428
|
console.warn("FlowEngine: apply flow defaultParams failed:", err);
|
|
389
429
|
});
|
|
390
430
|
modelInstance._createSubModels(options.subModels);
|
|
391
431
|
return modelInstance;
|
|
392
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* 按类上的 resolveUse 链路解析最终用于实例化的模型类。
|
|
435
|
+
* 允许模型类根据上下文动态指定实际使用的类,支持多级 resolveUse。
|
|
436
|
+
*/
|
|
437
|
+
_resolveModelClass(initial, options, parent) {
|
|
438
|
+
const normalize = /* @__PURE__ */ __name((resolved) => {
|
|
439
|
+
if (!resolved) return {};
|
|
440
|
+
if (typeof resolved === "object" && "use" in resolved) {
|
|
441
|
+
return { target: resolved.use, stop: !!resolved.stop };
|
|
442
|
+
}
|
|
443
|
+
return { target: resolved, stop: false };
|
|
444
|
+
}, "normalize");
|
|
445
|
+
let current = initial;
|
|
446
|
+
const visited = /* @__PURE__ */ new Set();
|
|
447
|
+
while (current) {
|
|
448
|
+
if (visited.has(current)) {
|
|
449
|
+
console.warn(`FlowEngine: resolveUse circular reference detected on '${current.name}'.`);
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
visited.add(current);
|
|
453
|
+
const resolver = current == null ? void 0 : current.resolveUse;
|
|
454
|
+
if (typeof resolver !== "function") {
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
const { target, stop } = normalize(resolver(options, this, parent));
|
|
458
|
+
if (!target || target === current) {
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
let next;
|
|
462
|
+
if (typeof target === "string") {
|
|
463
|
+
next = this.getModelClass(target);
|
|
464
|
+
if (!next) {
|
|
465
|
+
console.warn(`FlowEngine: resolveUse returned '${target}' but no model is registered under that name.`);
|
|
466
|
+
return void 0;
|
|
467
|
+
}
|
|
468
|
+
} else {
|
|
469
|
+
next = target;
|
|
470
|
+
}
|
|
471
|
+
current = next;
|
|
472
|
+
if (stop) {
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return current;
|
|
477
|
+
}
|
|
393
478
|
/**
|
|
394
479
|
* 尝试应用当前模型可用 flow 的 defaultParams(如果存在)到 model.stepParams。
|
|
395
480
|
* 仅对尚未存在的步骤参数进行填充,不覆盖已有值。
|
|
@@ -460,12 +545,13 @@ const _FlowEngine = class _FlowEngine {
|
|
|
460
545
|
* @returns {boolean} Returns true if successfully destroyed, false otherwise (e.g. instance does not exist)
|
|
461
546
|
*/
|
|
462
547
|
removeModel(uid) {
|
|
463
|
-
var _a;
|
|
548
|
+
var _a, _b, _c;
|
|
464
549
|
if (!this._modelInstances.has(uid)) {
|
|
465
550
|
console.warn(`FlowEngine: Model with UID '${uid}' does not exist.`);
|
|
466
551
|
return false;
|
|
467
552
|
}
|
|
468
553
|
const modelInstance = this._modelInstances.get(uid);
|
|
554
|
+
modelInstance.invalidateFlowCache(void 0, true);
|
|
469
555
|
modelInstance.clearForks();
|
|
470
556
|
if ((_a = modelInstance.parent) == null ? void 0 : _a.subModels) {
|
|
471
557
|
for (const subKey in modelInstance.parent.subModels) {
|
|
@@ -475,18 +561,65 @@ const _FlowEngine = class _FlowEngine {
|
|
|
475
561
|
if (index !== -1) {
|
|
476
562
|
subModelValue.splice(index, 1);
|
|
477
563
|
modelInstance.parent.emitter.emit("onSubModelRemoved", modelInstance);
|
|
564
|
+
(_b = this.emitter) == null ? void 0 : _b.emit("model:subModel:removed", {
|
|
565
|
+
parentUid: modelInstance.parent.uid,
|
|
566
|
+
parent: modelInstance.parent,
|
|
567
|
+
model: modelInstance
|
|
568
|
+
});
|
|
478
569
|
break;
|
|
479
570
|
}
|
|
480
571
|
} else if (subModelValue && subModelValue === modelInstance) {
|
|
481
572
|
delete modelInstance.parent.subModels[subKey];
|
|
482
573
|
modelInstance.parent.emitter.emit("onSubModelRemoved", modelInstance);
|
|
574
|
+
(_c = this.emitter) == null ? void 0 : _c.emit("model:subModel:removed", {
|
|
575
|
+
parentUid: modelInstance.parent.uid,
|
|
576
|
+
parent: modelInstance.parent,
|
|
577
|
+
model: modelInstance
|
|
578
|
+
});
|
|
483
579
|
break;
|
|
484
580
|
}
|
|
485
581
|
}
|
|
486
582
|
}
|
|
487
583
|
this._modelInstances.delete(uid);
|
|
584
|
+
void this.emitter.emitAsync("model:destroyed", {
|
|
585
|
+
uid,
|
|
586
|
+
model: modelInstance
|
|
587
|
+
});
|
|
488
588
|
return true;
|
|
489
589
|
}
|
|
590
|
+
/**
|
|
591
|
+
* Remove a local model instance and all its sub-models recursively.
|
|
592
|
+
* @param {string} uid UID of the model instance to destroy
|
|
593
|
+
* @returns {boolean} Returns true if successfully destroyed, false otherwise
|
|
594
|
+
*/
|
|
595
|
+
removeModelWithSubModels(uid) {
|
|
596
|
+
const model = this.getModel(uid);
|
|
597
|
+
if (!model) {
|
|
598
|
+
return false;
|
|
599
|
+
}
|
|
600
|
+
const collectDescendants = /* @__PURE__ */ __name((m, acc) => {
|
|
601
|
+
if (m.subModels) {
|
|
602
|
+
for (const key in m.subModels) {
|
|
603
|
+
const sub = m.subModels[key];
|
|
604
|
+
if (Array.isArray(sub)) {
|
|
605
|
+
[...sub].forEach((s) => collectDescendants(s, acc));
|
|
606
|
+
} else if (sub) {
|
|
607
|
+
collectDescendants(sub, acc);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
acc.push(m);
|
|
612
|
+
}, "collectDescendants");
|
|
613
|
+
const allModels = [];
|
|
614
|
+
collectDescendants(model, allModels);
|
|
615
|
+
let success = true;
|
|
616
|
+
for (const m of allModels) {
|
|
617
|
+
if (!this.removeModel(m.uid)) {
|
|
618
|
+
success = false;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return success;
|
|
622
|
+
}
|
|
490
623
|
/**
|
|
491
624
|
* Check if the model repository is set.
|
|
492
625
|
* @returns {boolean} Returns true if set, false otherwise.
|
|
@@ -498,6 +631,91 @@ const _FlowEngine = class _FlowEngine {
|
|
|
498
631
|
}
|
|
499
632
|
return true;
|
|
500
633
|
}
|
|
634
|
+
/**
|
|
635
|
+
* Try to locate a model instance in previous engines (view stack) by uid.
|
|
636
|
+
* This is mainly used by view-scoped engines to reuse already-loaded model trees
|
|
637
|
+
* (e.g. models created from local JSON) without hitting the repository.
|
|
638
|
+
*/
|
|
639
|
+
findModelInPreviousEngines(uid) {
|
|
640
|
+
let eng = this.previousEngine;
|
|
641
|
+
while (eng) {
|
|
642
|
+
const found = eng.getModel(uid);
|
|
643
|
+
if (found) return found;
|
|
644
|
+
eng = eng.previousEngine;
|
|
645
|
+
}
|
|
646
|
+
return void 0;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Try to locate a sub-model in previous engines (view stack) by (parentId, subKey).
|
|
650
|
+
*/
|
|
651
|
+
findSubModelInPreviousEngines(parentId, subKey) {
|
|
652
|
+
var _a;
|
|
653
|
+
let eng = this.previousEngine;
|
|
654
|
+
while (eng) {
|
|
655
|
+
const parent = eng.getModel(parentId);
|
|
656
|
+
if (parent) {
|
|
657
|
+
const sub = (_a = parent.subModels) == null ? void 0 : _a[subKey];
|
|
658
|
+
if (sub) {
|
|
659
|
+
const model = Array.isArray(sub) ? sub[0] : sub;
|
|
660
|
+
if (model) return { parent, model };
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
eng = eng.previousEngine;
|
|
664
|
+
}
|
|
665
|
+
return void 0;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Hydrate a model into current engine from an already-existing model instance in previous engines.
|
|
669
|
+
* - Avoids repository requests when the model tree is already present in memory.
|
|
670
|
+
*/
|
|
671
|
+
hydrateModelFromPreviousEngines(options, extra) {
|
|
672
|
+
var _a;
|
|
673
|
+
const uid = options == null ? void 0 : options.uid;
|
|
674
|
+
const parentId = options == null ? void 0 : options.parentId;
|
|
675
|
+
const subKey = options == null ? void 0 : options.subKey;
|
|
676
|
+
if (uid && !this._modelInstances.has(uid)) {
|
|
677
|
+
const existing = this.findModelInPreviousEngines(uid);
|
|
678
|
+
if (existing == null ? void 0 : existing.context.flowSettingsEnabled) {
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
681
|
+
if (existing) {
|
|
682
|
+
const data = existing.serialize();
|
|
683
|
+
return this.createModel(data, extra);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
if (parentId && subKey) {
|
|
687
|
+
const found = this.findSubModelInPreviousEngines(parentId, subKey);
|
|
688
|
+
if (!found || found.parent.context.flowSettingsEnabled) return null;
|
|
689
|
+
const { parent: parentFromPrev, model: modelFromPrev } = found;
|
|
690
|
+
let localParent = this.getModel(parentId);
|
|
691
|
+
if (!localParent) {
|
|
692
|
+
const parentData = parentFromPrev.serialize();
|
|
693
|
+
delete parentData.subModels;
|
|
694
|
+
localParent = this.createModel(parentData, extra);
|
|
695
|
+
}
|
|
696
|
+
const modelData = modelFromPrev.serialize();
|
|
697
|
+
const localModel = this.createModel(modelData, extra);
|
|
698
|
+
const mounted = (_a = localParent.subModels) == null ? void 0 : _a[subKey];
|
|
699
|
+
if (Array.isArray(mounted)) {
|
|
700
|
+
const exists = mounted.some((m) => (m == null ? void 0 : m.uid) === (localModel == null ? void 0 : localModel.uid));
|
|
701
|
+
if (!exists) {
|
|
702
|
+
localParent.addSubModel(subKey, localModel);
|
|
703
|
+
}
|
|
704
|
+
} else if (mounted instanceof import_models.FlowModel) {
|
|
705
|
+
if (mounted.uid !== (localModel == null ? void 0 : localModel.uid)) {
|
|
706
|
+
localParent.setSubModel(subKey, localModel);
|
|
707
|
+
}
|
|
708
|
+
} else {
|
|
709
|
+
if ((localModel == null ? void 0 : localModel.subType) === "array") {
|
|
710
|
+
localParent.addSubModel(subKey, localModel);
|
|
711
|
+
} else {
|
|
712
|
+
localParent.setSubModel(subKey, localModel);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return localModel;
|
|
716
|
+
}
|
|
717
|
+
return null;
|
|
718
|
+
}
|
|
501
719
|
/**
|
|
502
720
|
* Load a model instance (prefers local, falls back to repository).
|
|
503
721
|
* @template T FlowModel subclass type, defaults to FlowModel.
|
|
@@ -510,6 +728,10 @@ const _FlowEngine = class _FlowEngine {
|
|
|
510
728
|
if (model) {
|
|
511
729
|
return model;
|
|
512
730
|
}
|
|
731
|
+
const hydrated = this.hydrateModelFromPreviousEngines(options);
|
|
732
|
+
if (hydrated) {
|
|
733
|
+
return hydrated;
|
|
734
|
+
}
|
|
513
735
|
const data = await this._modelRepository.findOne(options);
|
|
514
736
|
return (data == null ? void 0 : data.uid) ? this.createModel(data) : null;
|
|
515
737
|
}
|
|
@@ -549,6 +771,10 @@ const _FlowEngine = class _FlowEngine {
|
|
|
549
771
|
if (m) {
|
|
550
772
|
return m;
|
|
551
773
|
}
|
|
774
|
+
const hydrated = this.hydrateModelFromPreviousEngines(options, extra);
|
|
775
|
+
if (hydrated) {
|
|
776
|
+
return hydrated;
|
|
777
|
+
}
|
|
552
778
|
const data = await this._modelRepository.findOne(options);
|
|
553
779
|
let model = null;
|
|
554
780
|
if (data == null ? void 0 : data.uid) {
|
|
@@ -627,7 +853,21 @@ const _FlowEngine = class _FlowEngine {
|
|
|
627
853
|
if (this.ensureModelRepository()) {
|
|
628
854
|
await this._modelRepository.destroy(uid);
|
|
629
855
|
}
|
|
630
|
-
|
|
856
|
+
const modelInstance = this._modelInstances.get(uid);
|
|
857
|
+
const parent = modelInstance == null ? void 0 : modelInstance.parent;
|
|
858
|
+
const result = this.removeModel(uid);
|
|
859
|
+
parent && parent.emitter.emit("onSubModelDestroyed", modelInstance);
|
|
860
|
+
return result;
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Duplicate a model tree via repository API.
|
|
864
|
+
* Returns the duplicated model JSON (root with subModels) or null if not available.
|
|
865
|
+
* @param {string} uid UID of the model to duplicate
|
|
866
|
+
* @returns {Promise<any | null>} Duplicated model JSON or null
|
|
867
|
+
*/
|
|
868
|
+
async duplicateModel(uid) {
|
|
869
|
+
if (!this.ensureModelRepository()) return null;
|
|
870
|
+
return this._modelRepository.duplicate(uid);
|
|
631
871
|
}
|
|
632
872
|
/**
|
|
633
873
|
* Replace a model instance with a new instance of a class.
|
|
@@ -640,7 +880,7 @@ const _FlowEngine = class _FlowEngine {
|
|
|
640
880
|
* @returns {Promise<T | null>} Newly created model instance
|
|
641
881
|
*/
|
|
642
882
|
async replaceModel(uid, optionsOrFn) {
|
|
643
|
-
var _a;
|
|
883
|
+
var _a, _b;
|
|
644
884
|
const oldModel = this.getModel(uid);
|
|
645
885
|
if (!oldModel) {
|
|
646
886
|
console.warn(`FlowEngine: Cannot replace model. Model with UID '${uid}' not found.`);
|
|
@@ -677,6 +917,12 @@ const _FlowEngine = class _FlowEngine {
|
|
|
677
917
|
currentParent.parent.invalidateFlowCache("beforeRender", true);
|
|
678
918
|
(_a = currentParent.parent) == null ? void 0 : _a.rerender();
|
|
679
919
|
currentParent.emitter.emit("onSubModelReplaced", { oldModel, newModel });
|
|
920
|
+
(_b = this.emitter) == null ? void 0 : _b.emit("model:subModel:replaced", {
|
|
921
|
+
parentUid: currentParent.uid,
|
|
922
|
+
parent: currentParent,
|
|
923
|
+
oldModel,
|
|
924
|
+
newModel
|
|
925
|
+
});
|
|
680
926
|
}
|
|
681
927
|
await newModel.save();
|
|
682
928
|
return newModel;
|
|
@@ -688,6 +934,7 @@ const _FlowEngine = class _FlowEngine {
|
|
|
688
934
|
* @returns {Promise<void>} No return value
|
|
689
935
|
*/
|
|
690
936
|
async moveModel(sourceId, targetId, options) {
|
|
937
|
+
var _a, _b;
|
|
691
938
|
const sourceModel = this.getModel(sourceId);
|
|
692
939
|
const targetModel = this.getModel(targetId);
|
|
693
940
|
if (!sourceModel || !targetModel) {
|
|
@@ -704,7 +951,8 @@ const _FlowEngine = class _FlowEngine {
|
|
|
704
951
|
console.error("FlowModel.moveTo: Parent subModels must be an array to perform move operation.");
|
|
705
952
|
return false;
|
|
706
953
|
}
|
|
707
|
-
const
|
|
954
|
+
const subModelsCopy = [...subModels];
|
|
955
|
+
const findIndex = /* @__PURE__ */ __name((model) => subModelsCopy.findIndex((item) => item.uid === model.uid), "findIndex");
|
|
708
956
|
const currentIndex = findIndex(sourceModel2);
|
|
709
957
|
const targetIndex = findIndex(targetModel2);
|
|
710
958
|
if (currentIndex === -1 || targetIndex === -1) {
|
|
@@ -715,11 +963,12 @@ const _FlowEngine = class _FlowEngine {
|
|
|
715
963
|
console.warn("FlowModel.moveTo: Current model is already at the target position. No action taken.");
|
|
716
964
|
return false;
|
|
717
965
|
}
|
|
718
|
-
const [movedModel] =
|
|
719
|
-
|
|
720
|
-
|
|
966
|
+
const [movedModel] = subModelsCopy.splice(currentIndex, 1);
|
|
967
|
+
subModelsCopy.splice(targetIndex, 0, movedModel);
|
|
968
|
+
subModelsCopy.forEach((model, index) => {
|
|
721
969
|
model.sortIndex = index;
|
|
722
970
|
});
|
|
971
|
+
subModels.splice(0, subModels.length, ...subModelsCopy);
|
|
723
972
|
return true;
|
|
724
973
|
}, "move");
|
|
725
974
|
move(sourceModel, targetModel);
|
|
@@ -728,6 +977,12 @@ const _FlowEngine = class _FlowEngine {
|
|
|
728
977
|
await this._modelRepository.move(sourceId, targetId, position);
|
|
729
978
|
}
|
|
730
979
|
sourceModel.parent.emitter.emit("onSubModelMoved", { source: sourceModel, target: targetModel });
|
|
980
|
+
(_b = this.emitter) == null ? void 0 : _b.emit("model:subModel:moved", {
|
|
981
|
+
parentUid: (_a = sourceModel.parent) == null ? void 0 : _a.uid,
|
|
982
|
+
parent: sourceModel.parent,
|
|
983
|
+
source: sourceModel,
|
|
984
|
+
target: targetModel
|
|
985
|
+
});
|
|
731
986
|
}
|
|
732
987
|
/**
|
|
733
988
|
* Filter model classes by parent class (supports multi-level inheritance).
|
package/lib/flowSettings.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export interface FlowSettingsOpenOptions {
|
|
|
25
25
|
/** 指定打开的步骤 key(配合 flowKey 使用) */
|
|
26
26
|
stepKey?: string;
|
|
27
27
|
/** 弹窗展现形式(drawer 或 dialog) */
|
|
28
|
-
uiMode?: 'dialog' | 'drawer' | 'embed' | {
|
|
29
|
-
type?: 'dialog' | 'drawer' | 'embed';
|
|
28
|
+
uiMode?: 'select' | 'switch' | 'dialog' | 'drawer' | 'embed' | {
|
|
29
|
+
type?: 'dialog' | 'drawer' | 'embed' | 'select' | 'switch';
|
|
30
30
|
props?: {
|
|
31
31
|
title?: string;
|
|
32
32
|
width?: number;
|
|
@@ -227,12 +227,13 @@ export declare class FlowSettings {
|
|
|
227
227
|
* @param {any} form 表单实例(从外部传入以便统一管理)
|
|
228
228
|
* @returns {React.ReactElement} 渲染的表单元素
|
|
229
229
|
*/
|
|
230
|
-
renderStepForm({ uiSchema, initialValues, flowEngine, form, onFormValuesChange, }: {
|
|
230
|
+
renderStepForm({ uiSchema, initialValues, flowEngine, form, onFormValuesChange, key, }: {
|
|
231
231
|
uiSchema: any;
|
|
232
232
|
initialValues: any;
|
|
233
233
|
flowEngine: any;
|
|
234
234
|
form?: any;
|
|
235
235
|
onFormValuesChange?: (form: any) => void;
|
|
236
|
+
key?: string;
|
|
236
237
|
}): React.ReactElement;
|
|
237
238
|
/**
|
|
238
239
|
* 打开流程设置入口(聚合渲染多个 flow 的可配置步骤)
|
package/lib/flowSettings.js
CHANGED
|
@@ -152,7 +152,7 @@ const _FlowSettings = class _FlowSettings {
|
|
|
152
152
|
TreeSelect,
|
|
153
153
|
Upload
|
|
154
154
|
} = await import("@formily/antd-v5");
|
|
155
|
-
const { Button: Button2 } = await import("antd");
|
|
155
|
+
const { Button: Button2, Alert } = await import("antd");
|
|
156
156
|
this.components.Form = Form;
|
|
157
157
|
this.components.FormDialog = FormDialog;
|
|
158
158
|
this.components.FormDrawer = FormDrawer;
|
|
@@ -186,6 +186,7 @@ const _FlowSettings = class _FlowSettings {
|
|
|
186
186
|
this.components.Space = Space2;
|
|
187
187
|
this.components.Editable = Editable;
|
|
188
188
|
this.components.PreviewText = PreviewText;
|
|
189
|
+
this.components.Alert = Alert;
|
|
189
190
|
this.components.Button = Button2;
|
|
190
191
|
this.components.Submit = Submit;
|
|
191
192
|
this.components.Reset = Reset;
|
|
@@ -376,7 +377,8 @@ const _FlowSettings = class _FlowSettings {
|
|
|
376
377
|
initialValues,
|
|
377
378
|
flowEngine,
|
|
378
379
|
form,
|
|
379
|
-
onFormValuesChange: onFormValuesChange2
|
|
380
|
+
onFormValuesChange: onFormValuesChange2,
|
|
381
|
+
key
|
|
380
382
|
}) {
|
|
381
383
|
var _a, _b;
|
|
382
384
|
const scopes = {
|
|
@@ -399,7 +401,7 @@ const _FlowSettings = class _FlowSettings {
|
|
|
399
401
|
const SchemaField = (0, import_react.createSchemaField)();
|
|
400
402
|
return import_react2.default.createElement(
|
|
401
403
|
FormProviderWithForm,
|
|
402
|
-
{ form, initialValues, onFormValuesChange: onFormValuesChange2 },
|
|
404
|
+
{ form, initialValues, onFormValuesChange: onFormValuesChange2, key },
|
|
403
405
|
import_react2.default.createElement(SchemaField, {
|
|
404
406
|
schema: compiledSchema,
|
|
405
407
|
components: ((_b = flowEngine == null ? void 0 : flowEngine.flowSettings) == null ? void 0 : _b.components) || {},
|
|
@@ -436,7 +438,7 @@ const _FlowSettings = class _FlowSettings {
|
|
|
436
438
|
* @returns {Promise<boolean>} 是否成功打开弹窗
|
|
437
439
|
*/
|
|
438
440
|
async open(options) {
|
|
439
|
-
var _a, _b, _c, _d, _e, _f;
|
|
441
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
440
442
|
__privateGet(this, _emitter).emit("beforeOpen", options);
|
|
441
443
|
const { model, flowKey, flowKeys, stepKey, uiMode = "dialog", preset, onCancel, onSaved } = options;
|
|
442
444
|
if (!model) {
|
|
@@ -461,17 +463,16 @@ const _FlowSettings = class _FlowSettings {
|
|
|
461
463
|
for (const sk of Object.keys(flow.steps || {})) {
|
|
462
464
|
if (stepKey && sk !== stepKey) continue;
|
|
463
465
|
const step = flow.steps[sk];
|
|
464
|
-
if (!preset && (!step ||
|
|
466
|
+
if (!preset && (!step || await (0, import_utils.shouldHideStepInSettings)(model, flow, step))) continue;
|
|
465
467
|
if (preset && !step.preset) continue;
|
|
466
468
|
const mergedUiSchema = await (0, import_utils.resolveStepUiSchema)(model, flow, step);
|
|
467
|
-
if (!mergedUiSchema || Object.keys(mergedUiSchema).length === 0) continue;
|
|
468
469
|
let stepTitle = step.title;
|
|
469
470
|
let beforeParamsSave = step.beforeParamsSave;
|
|
470
471
|
let afterParamsSave = step.afterParamsSave;
|
|
471
472
|
let actionDefaultParams = {};
|
|
472
|
-
let uiMode2;
|
|
473
|
+
let uiMode2 = step.uiMode;
|
|
473
474
|
if (step.use) {
|
|
474
|
-
const action = (
|
|
475
|
+
const action = (_b = model.getAction) == null ? void 0 : _b.call(model, step.use);
|
|
475
476
|
if (action) {
|
|
476
477
|
actionDefaultParams = action.defaultParams || {};
|
|
477
478
|
stepTitle = stepTitle || action.title;
|
|
@@ -483,6 +484,10 @@ const _FlowSettings = class _FlowSettings {
|
|
|
483
484
|
const flowRuntimeContext = new import_flowContext.FlowRuntimeContext(model, fk, "settings");
|
|
484
485
|
(0, import_utils.setupRuntimeContextSteps)(flowRuntimeContext, flow.steps, model, fk);
|
|
485
486
|
flowRuntimeContext.defineProperty("currentStep", { value: step });
|
|
487
|
+
flowRuntimeContext.defineMethod("getStepFormValues", (flowKey2, stepKey2) => {
|
|
488
|
+
var _a2;
|
|
489
|
+
return (_a2 = forms.get(keyOf({ flowKey: flowKey2, stepKey: stepKey2 }))) == null ? void 0 : _a2.values;
|
|
490
|
+
});
|
|
486
491
|
const modelStepParams = model.getStepParams(fk, sk) || {};
|
|
487
492
|
const resolvedDefaultParams = await (0, import_utils.resolveDefaultParams)(step.defaultParams, flowRuntimeContext);
|
|
488
493
|
const resolvedActionDefaults = await (0, import_utils.resolveDefaultParams)(actionDefaultParams, flowRuntimeContext);
|
|
@@ -491,6 +496,9 @@ const _FlowSettings = class _FlowSettings {
|
|
|
491
496
|
...resolvedDefaultParams || {},
|
|
492
497
|
...modelStepParams
|
|
493
498
|
};
|
|
499
|
+
if ((!mergedUiSchema || Object.keys(mergedUiSchema).length === 0) && !["select", "switch"].includes((uiMode2 == null ? void 0 : uiMode2.type) || uiMode2)) {
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
494
502
|
entries.push({
|
|
495
503
|
flowKey: fk,
|
|
496
504
|
flowTitle: t(flow.title) || fk,
|
|
@@ -509,19 +517,22 @@ const _FlowSettings = class _FlowSettings {
|
|
|
509
517
|
}
|
|
510
518
|
if (entries.length === 0) {
|
|
511
519
|
if (!preset) {
|
|
512
|
-
(
|
|
520
|
+
(_c = message == null ? void 0 : message.info) == null ? void 0 : _c.call(message, t("This model has no configurable flow settings"));
|
|
513
521
|
}
|
|
514
522
|
return false;
|
|
515
523
|
}
|
|
516
524
|
const viewer = model.context.viewer;
|
|
517
525
|
const resolvedUiMode = entries.length === 1 ? await (0, import_utils.resolveUiMode)(entries[0].uiMode || uiMode, entries[0].ctx) : uiMode;
|
|
518
526
|
const modeType = typeof resolvedUiMode === "string" ? resolvedUiMode : resolvedUiMode.type || "dialog";
|
|
527
|
+
if (["select", "switch"].includes(modeType)) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
519
530
|
const openView = viewer[modeType || "dialog"].bind(viewer);
|
|
520
531
|
const flowEngine = model.flowEngine;
|
|
521
532
|
const scopes = {
|
|
522
533
|
// 为 schema 表达式提供上下文能力(可在表达式中使用 useFlowSettingsContext 等)
|
|
523
534
|
useFlowSettingsContext: import_useFlowSettingsContext.useFlowSettingsContext,
|
|
524
|
-
...((
|
|
535
|
+
...((_d = flowEngine == null ? void 0 : flowEngine.flowSettings) == null ? void 0 : _d.scopes) || {}
|
|
525
536
|
};
|
|
526
537
|
let modeProps = typeof resolvedUiMode === "object" && resolvedUiMode ? resolvedUiMode.props || {} : {};
|
|
527
538
|
if (modeType === "embed") {
|
|
@@ -535,7 +546,7 @@ const _FlowSettings = class _FlowSettings {
|
|
|
535
546
|
target,
|
|
536
547
|
styles: {
|
|
537
548
|
body: {
|
|
538
|
-
padding: (
|
|
549
|
+
padding: (_e = flowEngine.context.themeToken) == null ? void 0 : _e.padding
|
|
539
550
|
}
|
|
540
551
|
},
|
|
541
552
|
...modeProps,
|
|
@@ -593,6 +604,13 @@ const _FlowSettings = class _FlowSettings {
|
|
|
593
604
|
}
|
|
594
605
|
);
|
|
595
606
|
}, "autoUpdateViewProps");
|
|
607
|
+
const baseViewInputArgs = ((_f = model.context.view) == null ? void 0 : _f.inputArgs) || {};
|
|
608
|
+
const navigation = (_g = model.context.view) == null ? void 0 : _g.navigation;
|
|
609
|
+
const inputArgs = {
|
|
610
|
+
...baseViewInputArgs,
|
|
611
|
+
...navigation ? { navigation } : {},
|
|
612
|
+
...(modeProps == null ? void 0 : modeProps.inputArgs) || {}
|
|
613
|
+
};
|
|
596
614
|
openView({
|
|
597
615
|
// 默认标题与宽度可被传入的 props 覆盖
|
|
598
616
|
title: modeProps.title || getTitle(),
|
|
@@ -602,6 +620,8 @@ const _FlowSettings = class _FlowSettings {
|
|
|
602
620
|
zIndex: 5e3,
|
|
603
621
|
// 允许透传其它 props(如 maskClosable、footer 等),但确保 content 由我们接管
|
|
604
622
|
...modeProps,
|
|
623
|
+
// 统一构造 settings 弹窗的 inputArgs(集合/记录/父导航/关联)
|
|
624
|
+
inputArgs,
|
|
605
625
|
content: /* @__PURE__ */ __name((currentView, viewCtx) => {
|
|
606
626
|
viewCtx == null ? void 0 : viewCtx.defineMethod("getStepFormValues", (flowKey2, stepKey2) => {
|
|
607
627
|
var _a2;
|
|
@@ -683,6 +703,8 @@ const _FlowSettings = class _FlowSettings {
|
|
|
683
703
|
}
|
|
684
704
|
}
|
|
685
705
|
currentView.close();
|
|
706
|
+
model.invalidateFlowCache("beforeRender", true);
|
|
707
|
+
await model.rerender();
|
|
686
708
|
try {
|
|
687
709
|
await (onSaved == null ? void 0 : onSaved());
|
|
688
710
|
} catch (cbErr) {
|
|
@@ -15,6 +15,7 @@ import { FlowModel } from '../models';
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function useApplyAutoFlows(modelOrUid: FlowModel | string, inputArgs?: Record<string, any>, options?: {
|
|
17
17
|
throwOnError?: boolean;
|
|
18
|
+
useCache?: boolean;
|
|
18
19
|
}): {
|
|
19
20
|
readonly loading: boolean;
|
|
20
21
|
readonly error: Error;
|
|
@@ -45,10 +45,10 @@ function useApplyAutoFlows(modelOrUid, inputArgs, options) {
|
|
|
45
45
|
const { loading, error } = (0, import_ahooks.useRequest)(
|
|
46
46
|
async () => {
|
|
47
47
|
if (!model) return;
|
|
48
|
-
await model.dispatchEvent("beforeRender", inputArgs);
|
|
48
|
+
await model.dispatchEvent("beforeRender", inputArgs, { useCache: options == null ? void 0 : options.useCache });
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
|
-
refreshDeps: [model, inputArgs]
|
|
51
|
+
refreshDeps: [model, inputArgs, options == null ? void 0 : options.useCache]
|
|
52
52
|
}
|
|
53
53
|
);
|
|
54
54
|
if ((options == null ? void 0 : options.throwOnError) !== false && error) {
|
package/lib/index.d.ts
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export * from './types';
|
|
10
10
|
export * from './utils';
|
|
11
|
+
export { compileRunJs } from './utils/jsxTransform';
|
|
11
12
|
export * from './resources';
|
|
12
13
|
export * from './flowEngine';
|
|
13
14
|
export * from './hooks';
|
|
14
15
|
export * from './models';
|
|
15
16
|
export * from './provider';
|
|
16
|
-
export * from '
|
|
17
|
-
export { observer } from '@formily/reactive-react';
|
|
17
|
+
export * from './reactive';
|
|
18
18
|
export * from './components';
|
|
19
19
|
export * from './data-source';
|
|
20
20
|
export * from './decorators';
|
|
@@ -28,3 +28,5 @@ export { setupRunJSContexts } from './runjs-context/setup';
|
|
|
28
28
|
export { getSnippetBody, listSnippetsForContext } from './runjs-context/snippets';
|
|
29
29
|
export * from './views';
|
|
30
30
|
export * from './FlowDefinition';
|
|
31
|
+
export { createViewScopedEngine } from './ViewScopedFlowEngine';
|
|
32
|
+
export { createBlockScopedEngine } from './BlockScopedFlowEngine';
|