@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
|
@@ -46,6 +46,52 @@ var import_react = __toESM(require("react"));
|
|
|
46
46
|
var import_models = require("../../../../models");
|
|
47
47
|
var import_utils = require("../../../../utils");
|
|
48
48
|
var import_hooks = require("../../../../hooks");
|
|
49
|
+
var import_SwitchWithTitle = require("../component/SwitchWithTitle");
|
|
50
|
+
var import_SelectWithTitle = require("../component/SelectWithTitle");
|
|
51
|
+
const walkSubModels = /* @__PURE__ */ __name((rootModel, options, cb) => {
|
|
52
|
+
const maxDepth = options.maxDepth;
|
|
53
|
+
const arrayLimit = typeof options.arrayLimit === "number" ? options.arrayLimit : Number.POSITIVE_INFINITY;
|
|
54
|
+
const mode = options.mode ?? "stack";
|
|
55
|
+
const visited = /* @__PURE__ */ new Set();
|
|
56
|
+
const stackIds = /* @__PURE__ */ new Set();
|
|
57
|
+
const walk = /* @__PURE__ */ __name((model, depth, modelKey) => {
|
|
58
|
+
if (!model || depth > maxDepth) return;
|
|
59
|
+
const run = /* @__PURE__ */ __name(() => {
|
|
60
|
+
cb(model, { depth, modelKey });
|
|
61
|
+
if (depth >= maxDepth) return;
|
|
62
|
+
Object.entries(model.subModels || {}).forEach(([subKey, subModelValue]) => {
|
|
63
|
+
if (Array.isArray(subModelValue)) {
|
|
64
|
+
const limit = Number.isFinite(arrayLimit) ? Math.min(subModelValue.length, arrayLimit) : subModelValue.length;
|
|
65
|
+
for (let index = 0; index < limit; index++) {
|
|
66
|
+
const subModel = subModelValue[index];
|
|
67
|
+
if (subModel instanceof import_models.FlowModel) {
|
|
68
|
+
walk(subModel, depth + 1, `${subKey}[${index}]`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (subModelValue instanceof import_models.FlowModel) {
|
|
74
|
+
walk(subModelValue, depth + 1, subKey);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}, "run");
|
|
78
|
+
if (mode === "visited") {
|
|
79
|
+
if (visited.has(model)) return;
|
|
80
|
+
visited.add(model);
|
|
81
|
+
run();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const modelId = model.uid || `temp-${Date.now()}`;
|
|
85
|
+
if (stackIds.has(modelId)) return;
|
|
86
|
+
stackIds.add(modelId);
|
|
87
|
+
try {
|
|
88
|
+
run();
|
|
89
|
+
} finally {
|
|
90
|
+
stackIds.delete(modelId);
|
|
91
|
+
}
|
|
92
|
+
}, "walk");
|
|
93
|
+
walk(rootModel, 1);
|
|
94
|
+
}, "walkSubModels");
|
|
49
95
|
const findSubModelByKey = /* @__PURE__ */ __name((model, subModelKey) => {
|
|
50
96
|
var _a;
|
|
51
97
|
if (!model || !subModelKey || typeof subModelKey !== "string") {
|
|
@@ -82,6 +128,18 @@ const findSubModelByKey = /* @__PURE__ */ __name((model, subModelKey) => {
|
|
|
82
128
|
return subModel instanceof import_models.FlowModel ? subModel : null;
|
|
83
129
|
}
|
|
84
130
|
}, "findSubModelByKey");
|
|
131
|
+
const componentMap = {
|
|
132
|
+
switch: import_SwitchWithTitle.SwitchWithTitle,
|
|
133
|
+
select: import_SelectWithTitle.SelectWithTitle
|
|
134
|
+
};
|
|
135
|
+
const MenuLabelItem = /* @__PURE__ */ __name(({ title, uiMode, itemProps }) => {
|
|
136
|
+
const type = (uiMode == null ? void 0 : uiMode.type) || uiMode;
|
|
137
|
+
const Component = type ? componentMap[type] : null;
|
|
138
|
+
if (!Component) {
|
|
139
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, title);
|
|
140
|
+
}
|
|
141
|
+
return /* @__PURE__ */ import_react.default.createElement(Component, { title, ...itemProps });
|
|
142
|
+
}, "MenuLabelItem");
|
|
85
143
|
const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
86
144
|
model,
|
|
87
145
|
showDeleteButton = true,
|
|
@@ -91,8 +149,10 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
91
149
|
flattenSubMenus = true
|
|
92
150
|
}) => {
|
|
93
151
|
const { message } = import_antd.App.useApp();
|
|
94
|
-
const t = (0, import_utils.getT)(model);
|
|
152
|
+
const t = (0, import_react.useMemo)(() => (0, import_utils.getT)(model), [model]);
|
|
95
153
|
const [visible, setVisible] = (0, import_react.useState)(false);
|
|
154
|
+
const [refreshTick, setRefreshTick] = (0, import_react.useState)(0);
|
|
155
|
+
const [extraMenuItems, setExtraMenuItems] = (0, import_react.useState)([]);
|
|
96
156
|
const handleOpenChange = (0, import_react.useCallback)((nextOpen, info) => {
|
|
97
157
|
if (info.source === "trigger" || nextOpen) {
|
|
98
158
|
(0, import_react.startTransition)(() => {
|
|
@@ -101,14 +161,66 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
101
161
|
}
|
|
102
162
|
}, []);
|
|
103
163
|
const dropdownMaxHeight = (0, import_hooks.useNiceDropdownMaxHeight)([visible]);
|
|
164
|
+
(0, import_react.useEffect)(() => {
|
|
165
|
+
let mounted = true;
|
|
166
|
+
const loadExtras = /* @__PURE__ */ __name(async () => {
|
|
167
|
+
var _a;
|
|
168
|
+
const allExtras = [];
|
|
169
|
+
const modelsToProcess = [];
|
|
170
|
+
walkSubModels(model, { maxDepth: menuLevels, arrayLimit: 50, mode: "stack" }, (targetModel, { modelKey }) => {
|
|
171
|
+
modelsToProcess.push({ model: targetModel, modelKey });
|
|
172
|
+
});
|
|
173
|
+
for (const { model: targetModel, modelKey } of modelsToProcess) {
|
|
174
|
+
const Cls = targetModel.constructor;
|
|
175
|
+
const extras = await ((_a = Cls.getExtraMenuItems) == null ? void 0 : _a.call(Cls, targetModel, t));
|
|
176
|
+
if (extras == null ? void 0 : extras.length) {
|
|
177
|
+
allExtras.push(
|
|
178
|
+
...extras.map((item) => ({
|
|
179
|
+
...item,
|
|
180
|
+
key: modelKey ? `${modelKey}:${item.key}` : item.key
|
|
181
|
+
}))
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (mounted) {
|
|
186
|
+
const seen = /* @__PURE__ */ new Set();
|
|
187
|
+
const dedupedExtras = allExtras.filter((item) => {
|
|
188
|
+
if (seen.has(`${item.key}`)) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
seen.add(`${item.key}`);
|
|
192
|
+
return true;
|
|
193
|
+
});
|
|
194
|
+
setExtraMenuItems(dedupedExtras);
|
|
195
|
+
}
|
|
196
|
+
}, "loadExtras");
|
|
197
|
+
if (visible) {
|
|
198
|
+
loadExtras();
|
|
199
|
+
}
|
|
200
|
+
return () => {
|
|
201
|
+
mounted = false;
|
|
202
|
+
};
|
|
203
|
+
}, [model, menuLevels, t, refreshTick, visible, message]);
|
|
104
204
|
const copyUidToClipboard = (0, import_react.useCallback)(
|
|
105
205
|
async (uid) => {
|
|
206
|
+
var _a;
|
|
106
207
|
try {
|
|
107
208
|
await navigator.clipboard.writeText(uid);
|
|
108
209
|
message.success(t("UID copied to clipboard"));
|
|
109
210
|
} catch (error) {
|
|
110
211
|
console.error(t("Copy failed"), ":", error);
|
|
111
|
-
|
|
212
|
+
const isHttps = typeof window !== "undefined" && ((_a = window.location) == null ? void 0 : _a.protocol) === "https:";
|
|
213
|
+
if (!isHttps) {
|
|
214
|
+
message.error(
|
|
215
|
+
t(
|
|
216
|
+
"Copy failed under HTTP. Clipboard API is unavailable on non-HTTPS pages. Please copy [{{uid}}] manually.",
|
|
217
|
+
{ uid }
|
|
218
|
+
)
|
|
219
|
+
);
|
|
220
|
+
return;
|
|
221
|
+
} else {
|
|
222
|
+
message.error(t("Copy failed, please copy [{{uid}}] manually.", { uid }));
|
|
223
|
+
}
|
|
112
224
|
}
|
|
113
225
|
},
|
|
114
226
|
[message, t]
|
|
@@ -194,11 +306,17 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
194
306
|
);
|
|
195
307
|
const handleMenuClick = (0, import_react.useCallback)(
|
|
196
308
|
({ key }) => {
|
|
309
|
+
const originalKey = key;
|
|
197
310
|
const cleanKey = key.includes("-") && /^(.+)-\d+$/.test(key) ? key.replace(/-\d+$/, "") : key;
|
|
198
311
|
if (cleanKey.startsWith("copy-pop-uid:")) {
|
|
199
312
|
handleCopyPopupUid(cleanKey);
|
|
200
313
|
return;
|
|
201
314
|
}
|
|
315
|
+
const extra = extraMenuItems.find((it) => (it == null ? void 0 : it.key) === originalKey || (it == null ? void 0 : it.key) === cleanKey);
|
|
316
|
+
if (extra == null ? void 0 : extra.onClick) {
|
|
317
|
+
extra.onClick();
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
202
320
|
switch (cleanKey) {
|
|
203
321
|
case "copy-uid":
|
|
204
322
|
handleCopyUid();
|
|
@@ -211,41 +329,47 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
211
329
|
break;
|
|
212
330
|
}
|
|
213
331
|
},
|
|
214
|
-
[handleCopyUid, handleDelete, handleStepConfiguration, handleCopyPopupUid]
|
|
332
|
+
[handleCopyUid, handleDelete, handleStepConfiguration, handleCopyPopupUid, extraMenuItems]
|
|
215
333
|
);
|
|
216
334
|
const getModelConfigurableFlowsAndSteps = (0, import_react.useCallback)(
|
|
217
335
|
async (targetModel, modelKey) => {
|
|
218
336
|
try {
|
|
219
|
-
const
|
|
337
|
+
const flowsMap = new Map(targetModel.constructor.globalFlowRegistry.getFlows());
|
|
338
|
+
const flows = flowsMap;
|
|
220
339
|
const flowsArray = Array.from(flows.values());
|
|
221
340
|
const flowsWithSteps = await Promise.all(
|
|
222
341
|
flowsArray.map(async (flow) => {
|
|
223
342
|
const configurableSteps = await Promise.all(
|
|
224
343
|
Object.entries(flow.steps).map(async ([stepKey, stepDefinition]) => {
|
|
225
|
-
var _a
|
|
344
|
+
var _a;
|
|
226
345
|
const actionStep = stepDefinition;
|
|
227
|
-
|
|
346
|
+
let step = actionStep;
|
|
347
|
+
if (await (0, import_utils.shouldHideStepInSettings)(targetModel, flow, actionStep)) {
|
|
228
348
|
return null;
|
|
229
349
|
}
|
|
350
|
+
let uiMode = await (0, import_utils.resolveUiMode)(actionStep.uiMode, targetModel.context);
|
|
230
351
|
const hasStepUiSchema = actionStep.uiSchema != null;
|
|
231
352
|
let hasActionUiSchema = false;
|
|
232
353
|
let stepTitle = actionStep.title;
|
|
233
354
|
if (actionStep.use) {
|
|
234
355
|
try {
|
|
235
|
-
const action = (
|
|
356
|
+
const action = (_a = targetModel.getAction) == null ? void 0 : _a.call(targetModel, actionStep.use);
|
|
357
|
+
step = { ...action || {}, ...actionStep };
|
|
358
|
+
uiMode = await (0, import_utils.resolveUiMode)((action == null ? void 0 : action.uiMode) || uiMode, targetModel.context);
|
|
236
359
|
hasActionUiSchema = action && action.uiSchema != null;
|
|
237
|
-
stepTitle = stepTitle || action.title;
|
|
360
|
+
stepTitle = stepTitle || (action == null ? void 0 : action.title);
|
|
238
361
|
} catch (error) {
|
|
239
362
|
console.warn(t("Failed to get action {{action}}", { action: actionStep.use }), ":", error);
|
|
240
363
|
}
|
|
241
364
|
}
|
|
242
|
-
|
|
365
|
+
const selectOrSwitchMode = ["select", "switch"].includes((uiMode == null ? void 0 : uiMode.type) || uiMode);
|
|
366
|
+
if (!selectOrSwitchMode && !hasStepUiSchema && !hasActionUiSchema) {
|
|
243
367
|
return null;
|
|
244
368
|
}
|
|
245
369
|
let mergedUiSchema = {};
|
|
246
370
|
try {
|
|
247
371
|
const resolvedSchema = await (0, import_utils.resolveStepUiSchema)(targetModel, flow, actionStep);
|
|
248
|
-
if (!resolvedSchema) {
|
|
372
|
+
if (!resolvedSchema && !selectOrSwitchMode) {
|
|
249
373
|
return null;
|
|
250
374
|
}
|
|
251
375
|
mergedUiSchema = resolvedSchema;
|
|
@@ -255,11 +379,12 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
255
379
|
}
|
|
256
380
|
return {
|
|
257
381
|
stepKey,
|
|
258
|
-
step
|
|
382
|
+
step,
|
|
259
383
|
uiSchema: mergedUiSchema,
|
|
260
384
|
title: t(stepTitle) || stepKey,
|
|
261
|
-
modelKey
|
|
385
|
+
modelKey,
|
|
262
386
|
// 添加模型标识
|
|
387
|
+
uiMode
|
|
263
388
|
};
|
|
264
389
|
})
|
|
265
390
|
).then((steps) => steps.filter(Boolean));
|
|
@@ -280,61 +405,41 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
280
405
|
);
|
|
281
406
|
const getConfigurableFlowsAndSteps = (0, import_react.useCallback)(async () => {
|
|
282
407
|
const result = [];
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
processedModels.add(modelId);
|
|
293
|
-
try {
|
|
294
|
-
const modelFlows = await getModelConfigurableFlowsAndSteps(targetModel, modelKey);
|
|
295
|
-
result.push(...modelFlows);
|
|
296
|
-
if (depth < menuLevels && targetModel.subModels) {
|
|
297
|
-
await Promise.all(
|
|
298
|
-
Object.entries(targetModel.subModels).map(async ([subKey, subModelValue]) => {
|
|
299
|
-
if (Array.isArray(subModelValue)) {
|
|
300
|
-
await Promise.all(
|
|
301
|
-
subModelValue.map(async (subModel, index) => {
|
|
302
|
-
if (subModel instanceof import_models.FlowModel && index < 50) {
|
|
303
|
-
await processModel(subModel, depth + 1, `${subKey}[${index}]`);
|
|
304
|
-
}
|
|
305
|
-
})
|
|
306
|
-
);
|
|
307
|
-
} else if (subModelValue instanceof import_models.FlowModel) {
|
|
308
|
-
await processModel(subModelValue, depth + 1, subKey);
|
|
309
|
-
}
|
|
310
|
-
})
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
} finally {
|
|
314
|
-
processedModels.delete(modelId);
|
|
315
|
-
}
|
|
316
|
-
}, "processModel");
|
|
317
|
-
await processModel(model, 1);
|
|
408
|
+
const modelsToProcess = [];
|
|
409
|
+
walkSubModels(model, { maxDepth: menuLevels, arrayLimit: 50, mode: "stack" }, (targetModel, { modelKey }) => {
|
|
410
|
+
modelsToProcess.push({ model: targetModel, modelKey });
|
|
411
|
+
});
|
|
412
|
+
for (const { model: targetModel, modelKey } of modelsToProcess) {
|
|
413
|
+
const modelFlows = await getModelConfigurableFlowsAndSteps(targetModel, modelKey);
|
|
414
|
+
result.push(...modelFlows);
|
|
415
|
+
}
|
|
318
416
|
return result;
|
|
319
417
|
}, [model, menuLevels, getModelConfigurableFlowsAndSteps]);
|
|
320
418
|
const [configurableFlowsAndSteps, setConfigurableFlowsAndSteps] = (0, import_react.useState)([]);
|
|
321
419
|
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
322
|
-
const [refreshTick, setRefreshTick] = (0, import_react.useState)(0);
|
|
323
420
|
(0, import_react.useEffect)(() => {
|
|
324
|
-
const triggerRebuild = /* @__PURE__ */ __name(() =>
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
model.emitter.off("onSubModelAdded", triggerRebuild);
|
|
333
|
-
model.emitter.off("onSubModelRemoved", triggerRebuild);
|
|
334
|
-
model.emitter.off("onSubModelReplaced", triggerRebuild);
|
|
421
|
+
const triggerRebuild = /* @__PURE__ */ __name(() => {
|
|
422
|
+
setRefreshTick((v) => v + 1);
|
|
423
|
+
}, "triggerRebuild");
|
|
424
|
+
const cleanups = [];
|
|
425
|
+
walkSubModels(model, { maxDepth: menuLevels, mode: "visited" }, (targetModel, { depth }) => {
|
|
426
|
+
const eventNames = ["onStepParamsChanged"];
|
|
427
|
+
if (depth === 1) {
|
|
428
|
+
eventNames.push("onSubModelAdded", "onSubModelRemoved", "onSubModelReplaced");
|
|
335
429
|
}
|
|
430
|
+
eventNames.forEach((eventName) => {
|
|
431
|
+
var _a;
|
|
432
|
+
(_a = targetModel.emitter) == null ? void 0 : _a.on(eventName, triggerRebuild);
|
|
433
|
+
cleanups.push(() => {
|
|
434
|
+
var _a2;
|
|
435
|
+
return (_a2 = targetModel.emitter) == null ? void 0 : _a2.off(eventName, triggerRebuild);
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
return () => {
|
|
440
|
+
cleanups.forEach((dispose) => dispose());
|
|
336
441
|
};
|
|
337
|
-
}, [model]);
|
|
442
|
+
}, [model, menuLevels, refreshTick]);
|
|
338
443
|
(0, import_react.useEffect)(() => {
|
|
339
444
|
const loadConfigurableFlowsAndSteps = /* @__PURE__ */ __name(async () => {
|
|
340
445
|
setIsLoading(true);
|
|
@@ -362,26 +467,60 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
362
467
|
if (flattenSubMenus) {
|
|
363
468
|
configurableFlowsAndSteps.forEach(({ flow, steps, modelKey }) => {
|
|
364
469
|
const groupKey = generateUniqueKey(`flow-group-${modelKey ? `${modelKey}-` : ""}${flow.key}`);
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
470
|
+
if (flow.options.divider === "top") {
|
|
471
|
+
items.push({
|
|
472
|
+
type: "divider"
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
if (flow.options.enableTitle) {
|
|
476
|
+
items.push({
|
|
477
|
+
key: groupKey,
|
|
478
|
+
label: t(flow.title) || flow.key,
|
|
479
|
+
type: "group"
|
|
480
|
+
});
|
|
481
|
+
}
|
|
370
482
|
steps.forEach((stepInfo) => {
|
|
371
483
|
const baseMenuKey = modelKey ? `${modelKey}:${flow.key}:${stepInfo.stepKey}` : `${flow.key}:${stepInfo.stepKey}`;
|
|
372
484
|
const uniqueKey = generateUniqueKey(baseMenuKey);
|
|
485
|
+
const uiMode = stepInfo.uiMode;
|
|
486
|
+
const subModel = stepInfo.modelKey ? findSubModelByKey(model, stepInfo.modelKey) : null;
|
|
487
|
+
const targetModel = subModel || model;
|
|
488
|
+
const stepParams = targetModel.getStepParams(flow.key, stepInfo.stepKey) || {};
|
|
489
|
+
const itemProps = {
|
|
490
|
+
getDefaultValue: /* @__PURE__ */ __name(async () => {
|
|
491
|
+
var _a;
|
|
492
|
+
let defaultParams = await (0, import_utils.resolveDefaultParams)(stepInfo.step.defaultParams, targetModel.context);
|
|
493
|
+
if (stepInfo.step.use) {
|
|
494
|
+
const action = (_a = targetModel.getAction) == null ? void 0 : _a.call(targetModel, stepInfo.step.use);
|
|
495
|
+
defaultParams = await (0, import_utils.resolveDefaultParams)(action.defaultParams, targetModel.context);
|
|
496
|
+
}
|
|
497
|
+
return { ...defaultParams, ...stepParams };
|
|
498
|
+
}, "getDefaultValue"),
|
|
499
|
+
onChange: /* @__PURE__ */ __name(async (val) => {
|
|
500
|
+
var _a;
|
|
501
|
+
targetModel.setStepParams(flow.key, stepInfo.stepKey, val);
|
|
502
|
+
if (typeof stepInfo.step.beforeParamsSave === "function") {
|
|
503
|
+
await stepInfo.step.beforeParamsSave(targetModel.context, val, stepParams);
|
|
504
|
+
}
|
|
505
|
+
await targetModel.saveStepParams();
|
|
506
|
+
(_a = message == null ? void 0 : message.success) == null ? void 0 : _a.call(message, t("Configuration saved"));
|
|
507
|
+
if (typeof stepInfo.step.afterParamsSave === "function") {
|
|
508
|
+
await stepInfo.step.afterParamsSave(targetModel.context, val, stepParams);
|
|
509
|
+
}
|
|
510
|
+
}, "onChange"),
|
|
511
|
+
...(uiMode == null ? void 0 : uiMode.props) || {},
|
|
512
|
+
itemKey: uiMode == null ? void 0 : uiMode.key
|
|
513
|
+
};
|
|
373
514
|
items.push({
|
|
374
515
|
key: uniqueKey,
|
|
375
|
-
label: t(stepInfo.title)
|
|
516
|
+
label: /* @__PURE__ */ import_react.default.createElement(MenuLabelItem, { title: t(stepInfo.title), uiMode, itemProps })
|
|
376
517
|
});
|
|
377
|
-
if (flow.key === "popupSettings") {
|
|
378
|
-
const copyKey = generateUniqueKey(`copy-pop-uid:${baseMenuKey}`);
|
|
379
|
-
items.push({
|
|
380
|
-
key: copyKey,
|
|
381
|
-
label: t("Copy popup UID")
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
518
|
});
|
|
519
|
+
if (flow.options.divider === "bottom") {
|
|
520
|
+
items.push({
|
|
521
|
+
type: "divider"
|
|
522
|
+
});
|
|
523
|
+
}
|
|
385
524
|
});
|
|
386
525
|
} else {
|
|
387
526
|
const modelGroups = /* @__PURE__ */ new Map();
|
|
@@ -410,13 +549,6 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
410
549
|
key: uniqueKey,
|
|
411
550
|
label: t(stepInfo.title)
|
|
412
551
|
});
|
|
413
|
-
if (flow.key === "popupSettings") {
|
|
414
|
-
const copyKey = generateUniqueKey(`copy-pop-uid:${flow.key}:${stepInfo.stepKey}`);
|
|
415
|
-
items.push({
|
|
416
|
-
key: copyKey,
|
|
417
|
-
label: t("Copy popup UID")
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
552
|
});
|
|
421
553
|
});
|
|
422
554
|
} else {
|
|
@@ -429,13 +561,6 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
429
561
|
key: uniqueKey,
|
|
430
562
|
label: t(stepInfo.title)
|
|
431
563
|
});
|
|
432
|
-
if (flow.key === "popupSettings") {
|
|
433
|
-
const copyKey = generateUniqueKey(`copy-pop-uid:${modelKey}:${flow.key}:${stepInfo.stepKey}`);
|
|
434
|
-
subMenuChildren.push({
|
|
435
|
-
key: copyKey,
|
|
436
|
-
label: t("Copy popup UID")
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
564
|
});
|
|
440
565
|
});
|
|
441
566
|
items.push({
|
|
@@ -451,12 +576,14 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
451
576
|
}, [configurableFlowsAndSteps, flattenSubMenus, t]);
|
|
452
577
|
const finalMenuItems = (0, import_react.useMemo)(() => {
|
|
453
578
|
const items = [...menuItems];
|
|
454
|
-
|
|
579
|
+
const commonExtras = extraMenuItems.filter((it) => it.group === "common-actions").sort((a, b) => (a.sort ?? 0) - (b.sort ?? 0));
|
|
580
|
+
if (showCopyUidButton || showDeleteButton || commonExtras.length > 0) {
|
|
455
581
|
items.push({
|
|
456
|
-
|
|
457
|
-
label: t("Common actions"),
|
|
458
|
-
type: "group"
|
|
582
|
+
type: "divider"
|
|
459
583
|
});
|
|
584
|
+
if (commonExtras.length > 0) {
|
|
585
|
+
items.push(...commonExtras);
|
|
586
|
+
}
|
|
460
587
|
if (showCopyUidButton && model.uid) {
|
|
461
588
|
items.push({
|
|
462
589
|
key: "copy-uid",
|
|
@@ -471,8 +598,9 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
|
|
|
471
598
|
}
|
|
472
599
|
}
|
|
473
600
|
return items;
|
|
474
|
-
}, [menuItems, showCopyUidButton, showDeleteButton, model.uid, model.destroy, t]);
|
|
475
|
-
|
|
601
|
+
}, [menuItems, showCopyUidButton, showDeleteButton, model.uid, model.destroy, t, extraMenuItems]);
|
|
602
|
+
const hasExtras = extraMenuItems.some((it) => it.group === "common-actions");
|
|
603
|
+
if (isLoading || configurableFlowsAndSteps.length === 0 && !showDeleteButton && !showCopyUidButton && !hasExtras) {
|
|
476
604
|
return null;
|
|
477
605
|
}
|
|
478
606
|
if (!model || !model.uid) {
|
|
@@ -41,33 +41,33 @@ __export(FlowsContextMenu_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(FlowsContextMenu_exports);
|
|
43
43
|
var import_icons = require("@ant-design/icons");
|
|
44
|
-
var import_react = require("@formily/react");
|
|
45
44
|
var import_antd = require("antd");
|
|
46
|
-
var
|
|
45
|
+
var import_react = __toESM(require("react"));
|
|
47
46
|
var import_flowContext = require("../../../../flowContext");
|
|
48
47
|
var import_hooks = require("../../../../hooks");
|
|
49
48
|
var import_utils = require("../../../../utils");
|
|
50
49
|
var import_StepSettingsDialog = require("./StepSettingsDialog");
|
|
50
|
+
var import_reactive = require("../../../../reactive");
|
|
51
51
|
const isModelByIdProps = /* @__PURE__ */ __name((props) => {
|
|
52
52
|
return "uid" in props && "modelClassName" in props && Boolean(props.uid) && Boolean(props.modelClassName);
|
|
53
53
|
}, "isModelByIdProps");
|
|
54
54
|
const FlowsContextMenu = /* @__PURE__ */ __name((props) => {
|
|
55
55
|
if (isModelByIdProps(props)) {
|
|
56
|
-
return /* @__PURE__ */
|
|
56
|
+
return /* @__PURE__ */ import_react.default.createElement(FlowsContextMenuWithModelById, { ...props });
|
|
57
57
|
} else {
|
|
58
|
-
return /* @__PURE__ */
|
|
58
|
+
return /* @__PURE__ */ import_react.default.createElement(FlowsContextMenuWithModel, { ...props });
|
|
59
59
|
}
|
|
60
60
|
}, "FlowsContextMenu");
|
|
61
|
-
const FlowsContextMenuWithModel = (0,
|
|
61
|
+
const FlowsContextMenuWithModel = (0, import_reactive.observer)(
|
|
62
62
|
({ model, children, enabled = true, position = "right", showDeleteButton = true }) => {
|
|
63
63
|
const t = (0, import_utils.getT)(model);
|
|
64
|
-
const handleMenuClick = (0,
|
|
64
|
+
const handleMenuClick = (0, import_react.useCallback)(
|
|
65
65
|
({ key }) => {
|
|
66
66
|
var _a;
|
|
67
67
|
if (key === "delete") {
|
|
68
68
|
import_antd.Modal.confirm({
|
|
69
69
|
title: t("Confirm delete"),
|
|
70
|
-
icon: /* @__PURE__ */
|
|
70
|
+
icon: /* @__PURE__ */ import_react.default.createElement(import_icons.ExclamationCircleOutlined, null),
|
|
71
71
|
content: t("Are you sure you want to delete this item? This action cannot be undone."),
|
|
72
72
|
okText: t("Confirm Delete"),
|
|
73
73
|
okType: "danger",
|
|
@@ -111,58 +111,75 @@ const FlowsContextMenuWithModel = (0, import_react.observer)(
|
|
|
111
111
|
[model]
|
|
112
112
|
);
|
|
113
113
|
if (!model) {
|
|
114
|
-
return /* @__PURE__ */
|
|
114
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd.Alert, { message: "\u63D0\u4F9B\u7684\u6A21\u578B\u65E0\u6548", type: "error" });
|
|
115
115
|
}
|
|
116
116
|
if (!enabled || !children) {
|
|
117
|
-
return /* @__PURE__ */
|
|
117
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
|
|
118
118
|
}
|
|
119
|
-
const getConfigurableFlowsAndSteps = (0,
|
|
119
|
+
const getConfigurableFlowsAndSteps = (0, import_react.useCallback)(async () => {
|
|
120
120
|
try {
|
|
121
121
|
const flows = model.getFlows();
|
|
122
122
|
const flowsArray = Array.from(flows.values());
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
123
|
+
const result = await Promise.all(
|
|
124
|
+
flowsArray.map(async (flow) => {
|
|
125
|
+
const configurableSteps = await Promise.all(
|
|
126
|
+
Object.entries(flow.steps).map(async ([stepKey, stepDefinition]) => {
|
|
127
|
+
var _a;
|
|
128
|
+
const actionStep = stepDefinition;
|
|
129
|
+
if (await (0, import_utils.shouldHideStepInSettings)(model, flow, actionStep)) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const stepUiSchema = actionStep.uiSchema || {};
|
|
133
|
+
let actionUiSchema = {};
|
|
134
|
+
if (actionStep.use) {
|
|
135
|
+
const action = (_a = model.getAction) == null ? void 0 : _a.call(model, actionStep.use);
|
|
136
|
+
if (action && action.uiSchema) {
|
|
137
|
+
actionUiSchema = action.uiSchema;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const mergedUiSchema = { ...actionUiSchema };
|
|
141
|
+
Object.entries(stepUiSchema).forEach(([fieldKey, schema]) => {
|
|
142
|
+
if (mergedUiSchema[fieldKey]) {
|
|
143
|
+
mergedUiSchema[fieldKey] = { ...mergedUiSchema[fieldKey], ...schema };
|
|
144
|
+
} else {
|
|
145
|
+
mergedUiSchema[fieldKey] = schema;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
if (Object.keys(mergedUiSchema).length === 0) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
stepKey,
|
|
153
|
+
step: actionStep,
|
|
154
|
+
uiSchema: mergedUiSchema,
|
|
155
|
+
title: actionStep.title || stepKey
|
|
156
|
+
};
|
|
157
|
+
})
|
|
158
|
+
).then((steps) => steps.filter(Boolean));
|
|
159
|
+
return configurableSteps.length > 0 ? { flow, steps: configurableSteps } : null;
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
return result.filter(Boolean);
|
|
158
163
|
} catch (error) {
|
|
159
164
|
console.warn("[FlowsContextMenu] \u83B7\u53D6\u53EF\u914D\u7F6Eflows\u5931\u8D25:", error);
|
|
160
165
|
return [];
|
|
161
166
|
}
|
|
162
167
|
}, [model]);
|
|
163
|
-
const configurableFlowsAndSteps =
|
|
168
|
+
const [configurableFlowsAndSteps, setConfigurableFlowsAndSteps] = (0, import_react.useState)([]);
|
|
169
|
+
(0, import_react.useEffect)(() => {
|
|
170
|
+
let mounted = true;
|
|
171
|
+
(async () => {
|
|
172
|
+
const flows = await getConfigurableFlowsAndSteps();
|
|
173
|
+
if (mounted) {
|
|
174
|
+
setConfigurableFlowsAndSteps(flows);
|
|
175
|
+
}
|
|
176
|
+
})();
|
|
177
|
+
return () => {
|
|
178
|
+
mounted = false;
|
|
179
|
+
};
|
|
180
|
+
}, [getConfigurableFlowsAndSteps]);
|
|
164
181
|
if (configurableFlowsAndSteps.length === 0 && !showDeleteButton) {
|
|
165
|
-
return /* @__PURE__ */
|
|
182
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
|
|
166
183
|
}
|
|
167
184
|
const menuItems = [];
|
|
168
185
|
if (configurableFlowsAndSteps.length > 0) {
|
|
@@ -175,7 +192,7 @@ const FlowsContextMenuWithModel = (0, import_react.observer)(
|
|
|
175
192
|
steps.forEach((stepInfo) => {
|
|
176
193
|
menuItems.push({
|
|
177
194
|
key: `${flow.key}:${stepInfo.stepKey}`,
|
|
178
|
-
icon: /* @__PURE__ */
|
|
195
|
+
icon: /* @__PURE__ */ import_react.default.createElement(import_icons.SettingOutlined, null),
|
|
179
196
|
label: stepInfo.title
|
|
180
197
|
});
|
|
181
198
|
});
|
|
@@ -189,11 +206,11 @@ const FlowsContextMenuWithModel = (0, import_react.observer)(
|
|
|
189
206
|
}
|
|
190
207
|
menuItems.push({
|
|
191
208
|
key: "delete",
|
|
192
|
-
icon: /* @__PURE__ */
|
|
209
|
+
icon: /* @__PURE__ */ import_react.default.createElement(import_icons.DeleteOutlined, null),
|
|
193
210
|
label: "\u5220\u9664"
|
|
194
211
|
});
|
|
195
212
|
}
|
|
196
|
-
return /* @__PURE__ */
|
|
213
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
|
|
197
214
|
import_antd.Dropdown,
|
|
198
215
|
{
|
|
199
216
|
menu: {
|
|
@@ -203,17 +220,17 @@ const FlowsContextMenuWithModel = (0, import_react.observer)(
|
|
|
203
220
|
trigger: ["contextMenu"],
|
|
204
221
|
placement: position === "left" ? "bottomLeft" : "bottomRight"
|
|
205
222
|
},
|
|
206
|
-
/* @__PURE__ */
|
|
223
|
+
/* @__PURE__ */ import_react.default.createElement("div", { style: { display: "inline-block", width: "100%" } }, children)
|
|
207
224
|
));
|
|
208
225
|
}
|
|
209
226
|
);
|
|
210
|
-
const FlowsContextMenuWithModelById = (0,
|
|
227
|
+
const FlowsContextMenuWithModelById = (0, import_reactive.observer)(
|
|
211
228
|
({ uid, modelClassName, children, enabled = true, position = "right", showDeleteButton = true }) => {
|
|
212
229
|
const model = (0, import_hooks.useFlowModelById)(uid, modelClassName);
|
|
213
230
|
if (!model) {
|
|
214
|
-
return /* @__PURE__ */
|
|
231
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd.Alert, { message: `\u672A\u627E\u5230ID\u4E3A ${uid} \u7684\u6A21\u578B`, type: "error" });
|
|
215
232
|
}
|
|
216
|
-
return /* @__PURE__ */
|
|
233
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
217
234
|
FlowsContextMenuWithModel,
|
|
218
235
|
{
|
|
219
236
|
model,
|