@nocobase/flow-engine 2.0.0-beta.9 → 2.0.1

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.
Files changed (245) hide show
  1. package/lib/BlockScopedFlowEngine.js +0 -1
  2. package/lib/FlowDefinition.d.ts +2 -0
  3. package/lib/JSRunner.d.ts +6 -0
  4. package/lib/JSRunner.js +32 -2
  5. package/lib/ViewScopedFlowEngine.js +3 -0
  6. package/lib/acl/Acl.js +13 -3
  7. package/lib/components/FlowContextSelector.js +155 -10
  8. package/lib/components/settings/wrappers/component/SwitchWithTitle.js +2 -1
  9. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +76 -15
  10. package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +24 -4
  11. package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +5 -1
  12. package/lib/components/variables/VariableInput.js +9 -4
  13. package/lib/components/variables/VariableTag.js +46 -39
  14. package/lib/components/variables/utils.d.ts +7 -0
  15. package/lib/components/variables/utils.js +42 -2
  16. package/lib/data-source/index.d.ts +7 -27
  17. package/lib/data-source/index.js +81 -51
  18. package/lib/executor/FlowExecutor.d.ts +2 -1
  19. package/lib/executor/FlowExecutor.js +163 -22
  20. package/lib/flowContext.d.ts +230 -7
  21. package/lib/flowContext.js +2267 -148
  22. package/lib/flowEngine.d.ts +21 -0
  23. package/lib/flowEngine.js +56 -8
  24. package/lib/flowI18n.js +6 -4
  25. package/lib/flowSettings.js +17 -11
  26. package/lib/index.d.ts +7 -1
  27. package/lib/index.js +21 -0
  28. package/lib/locale/en-US.json +9 -2
  29. package/lib/locale/index.d.ts +14 -0
  30. package/lib/locale/zh-CN.json +8 -1
  31. package/lib/models/CollectionFieldModel.d.ts +1 -0
  32. package/lib/models/CollectionFieldModel.js +3 -2
  33. package/lib/models/flowModel.js +12 -1
  34. package/lib/provider.js +5 -5
  35. package/lib/resources/baseRecordResource.d.ts +5 -0
  36. package/lib/resources/baseRecordResource.js +24 -0
  37. package/lib/resources/multiRecordResource.d.ts +1 -0
  38. package/lib/resources/multiRecordResource.js +11 -4
  39. package/lib/resources/singleRecordResource.js +2 -0
  40. package/lib/resources/sqlResource.d.ts +4 -3
  41. package/lib/resources/sqlResource.js +8 -3
  42. package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +12 -2
  43. package/lib/runjs-context/contexts/JSBlockRunJSContext.js +2 -2
  44. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.d.ts +16 -0
  45. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +125 -0
  46. package/lib/runjs-context/contexts/JSItemRunJSContext.js +12 -2
  47. package/lib/runjs-context/contexts/base.js +706 -41
  48. package/lib/runjs-context/contributions.d.ts +33 -0
  49. package/lib/runjs-context/contributions.js +88 -0
  50. package/lib/runjs-context/helpers.js +12 -1
  51. package/lib/runjs-context/setup.js +6 -0
  52. package/lib/runjs-context/snippets/global/api-request.snippet.js +3 -3
  53. package/lib/runjs-context/snippets/global/import-esm.snippet.js +2 -3
  54. package/lib/runjs-context/snippets/global/query-selector.snippet.js +8 -3
  55. package/lib/runjs-context/snippets/global/require-amd.snippet.js +1 -1
  56. package/lib/runjs-context/snippets/index.d.ts +11 -1
  57. package/lib/runjs-context/snippets/index.js +61 -40
  58. package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.js +10 -7
  59. package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +3 -3
  60. package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +2 -2
  61. package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.js +2 -2
  62. package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +2 -2
  63. package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +1 -1
  64. package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +1 -1
  65. package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +1 -1
  66. package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +5 -5
  67. package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +6 -6
  68. package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +3 -4
  69. package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.js +1 -1
  70. package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.js +20 -3
  71. package/lib/runjs-context/snippets/scene/detail/format-number.snippet.js +1 -1
  72. package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.js +1 -1
  73. package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +3 -3
  74. package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +3 -3
  75. package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +2 -2
  76. package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +1 -1
  77. package/lib/runjs-context/snippets/scene/form/render-basic.snippet.js +2 -2
  78. package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +6 -3
  79. package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +3 -1
  80. package/lib/runjsLibs.d.ts +28 -0
  81. package/lib/runjsLibs.js +532 -0
  82. package/lib/scheduler/ModelOperationScheduler.d.ts +2 -0
  83. package/lib/scheduler/ModelOperationScheduler.js +25 -21
  84. package/lib/types.d.ts +27 -0
  85. package/lib/utils/associationObjectVariable.d.ts +2 -2
  86. package/lib/utils/createCollectionContextMeta.js +1 -0
  87. package/lib/utils/createEphemeralContext.js +2 -2
  88. package/lib/utils/dateVariable.d.ts +16 -0
  89. package/lib/utils/dateVariable.js +380 -0
  90. package/lib/utils/exceptions.d.ts +7 -0
  91. package/lib/utils/exceptions.js +10 -0
  92. package/lib/utils/index.d.ts +8 -3
  93. package/lib/utils/index.js +45 -0
  94. package/lib/utils/params-resolvers.js +16 -9
  95. package/lib/utils/resolveModuleUrl.d.ts +58 -0
  96. package/lib/utils/resolveModuleUrl.js +65 -0
  97. package/lib/utils/resolveRunJSObjectValues.d.ts +16 -0
  98. package/lib/utils/resolveRunJSObjectValues.js +61 -0
  99. package/lib/utils/runjsModuleLoader.d.ts +58 -0
  100. package/lib/utils/runjsModuleLoader.js +422 -0
  101. package/lib/utils/runjsTemplateCompat.d.ts +35 -0
  102. package/lib/utils/runjsTemplateCompat.js +743 -0
  103. package/lib/utils/runjsValue.d.ts +29 -0
  104. package/lib/utils/runjsValue.js +275 -0
  105. package/lib/utils/safeGlobals.d.ts +18 -8
  106. package/lib/utils/safeGlobals.js +164 -17
  107. package/lib/utils/schema-utils.d.ts +10 -0
  108. package/lib/utils/schema-utils.js +61 -0
  109. package/lib/views/createViewMeta.d.ts +0 -7
  110. package/lib/views/createViewMeta.js +19 -70
  111. package/lib/views/index.d.ts +1 -2
  112. package/lib/views/index.js +4 -3
  113. package/lib/views/useDialog.js +7 -2
  114. package/lib/views/useDrawer.js +7 -2
  115. package/lib/views/usePage.d.ts +4 -0
  116. package/lib/views/usePage.js +43 -6
  117. package/lib/views/usePopover.js +4 -1
  118. package/lib/views/viewEvents.d.ts +17 -0
  119. package/lib/views/viewEvents.js +90 -0
  120. package/package.json +4 -4
  121. package/src/BlockScopedFlowEngine.ts +2 -5
  122. package/src/JSRunner.ts +44 -2
  123. package/src/ViewScopedFlowEngine.ts +4 -0
  124. package/src/__tests__/JSRunner.test.ts +64 -0
  125. package/src/__tests__/createViewMeta.popup.test.ts +62 -1
  126. package/src/__tests__/flowContext.test.ts +693 -1
  127. package/src/__tests__/flowEngine.dataSourceDirty.test.ts +63 -0
  128. package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
  129. package/src/__tests__/flowRunJSContextDefine.test.ts +63 -0
  130. package/src/__tests__/flowRuntimeContext.test.ts +2 -1
  131. package/src/__tests__/flowSettings.open.test.tsx +123 -19
  132. package/src/__tests__/runjsContext.test.ts +10 -7
  133. package/src/__tests__/runjsContextImplementations.test.ts +34 -3
  134. package/src/__tests__/runjsContextRuntime.test.ts +3 -3
  135. package/src/__tests__/runjsContributions.test.ts +89 -0
  136. package/src/__tests__/runjsExternalLibs.test.ts +242 -0
  137. package/src/__tests__/runjsLibsLazyLoading.test.ts +44 -0
  138. package/src/__tests__/runjsLocales.test.ts +4 -1
  139. package/src/__tests__/runjsPreprocessDefault.test.ts +49 -0
  140. package/src/__tests__/runjsRuntimeFeatures.test.ts +166 -0
  141. package/src/__tests__/runjsSnippets.test.ts +40 -3
  142. package/src/acl/Acl.tsx +3 -3
  143. package/src/components/FlowContextSelector.tsx +208 -12
  144. package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +2 -1
  145. package/src/components/settings/wrappers/component/__tests__/InlineControls.test.tsx +74 -0
  146. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +109 -16
  147. package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +41 -7
  148. package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +13 -2
  149. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +157 -5
  150. package/src/components/variables/VariableInput.tsx +12 -4
  151. package/src/components/variables/VariableTag.tsx +54 -45
  152. package/src/components/variables/__tests__/FlowContextSelector.test.tsx +260 -3
  153. package/src/components/variables/__tests__/VariableTag.test.tsx +50 -0
  154. package/src/components/variables/__tests__/utils.test.ts +81 -3
  155. package/src/components/variables/utils.ts +67 -6
  156. package/src/data-source/index.ts +85 -110
  157. package/src/executor/FlowExecutor.ts +200 -23
  158. package/src/executor/__tests__/flowExecutor.test.ts +66 -0
  159. package/src/flowContext.ts +2986 -211
  160. package/src/flowEngine.ts +59 -8
  161. package/src/flowI18n.ts +7 -5
  162. package/src/flowSettings.ts +18 -12
  163. package/src/index.ts +14 -1
  164. package/src/locale/en-US.json +9 -2
  165. package/src/locale/zh-CN.json +8 -1
  166. package/src/models/CollectionFieldModel.tsx +3 -1
  167. package/src/models/__tests__/dispatchEvent.when.test.ts +554 -0
  168. package/src/models/__tests__/flowModel.test.ts +20 -4
  169. package/src/models/flowModel.tsx +13 -1
  170. package/src/provider.tsx +7 -6
  171. package/src/resources/__tests__/multiRecordResource.test.ts +44 -0
  172. package/src/resources/__tests__/sqlResource.test.ts +60 -0
  173. package/src/resources/baseRecordResource.ts +31 -0
  174. package/src/resources/multiRecordResource.ts +11 -4
  175. package/src/resources/singleRecordResource.ts +3 -0
  176. package/src/resources/sqlResource.ts +11 -6
  177. package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +10 -0
  178. package/src/runjs-context/contexts/JSBlockRunJSContext.ts +6 -2
  179. package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +106 -0
  180. package/src/runjs-context/contexts/JSItemRunJSContext.ts +10 -0
  181. package/src/runjs-context/contexts/base.ts +715 -44
  182. package/src/runjs-context/contributions.ts +88 -0
  183. package/src/runjs-context/helpers.ts +11 -1
  184. package/src/runjs-context/setup.ts +6 -0
  185. package/src/runjs-context/snippets/global/api-request.snippet.ts +3 -3
  186. package/src/runjs-context/snippets/global/import-esm.snippet.ts +2 -3
  187. package/src/runjs-context/snippets/global/query-selector.snippet.ts +8 -3
  188. package/src/runjs-context/snippets/global/require-amd.snippet.ts +1 -1
  189. package/src/runjs-context/snippets/index.ts +75 -41
  190. package/src/runjs-context/snippets/scene/block/add-event-listener.snippet.ts +11 -13
  191. package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +3 -3
  192. package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +2 -2
  193. package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +2 -2
  194. package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +2 -2
  195. package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +1 -1
  196. package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +1 -1
  197. package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +1 -1
  198. package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +6 -11
  199. package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +6 -6
  200. package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +3 -4
  201. package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +1 -1
  202. package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +20 -3
  203. package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +1 -1
  204. package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +1 -1
  205. package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +3 -3
  206. package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +3 -3
  207. package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +2 -2
  208. package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +1 -1
  209. package/src/runjs-context/snippets/scene/form/render-basic.snippet.ts +3 -8
  210. package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +6 -3
  211. package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +3 -1
  212. package/src/runjsLibs.ts +622 -0
  213. package/src/scheduler/ModelOperationScheduler.ts +27 -21
  214. package/src/types.ts +38 -1
  215. package/src/utils/__tests__/dateVariable.test.ts +101 -0
  216. package/src/utils/__tests__/params-resolvers.test.ts +40 -0
  217. package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +38 -0
  218. package/src/utils/__tests__/runjsTemplateCompat.test.ts +159 -0
  219. package/src/utils/__tests__/runjsValue.test.ts +44 -0
  220. package/src/utils/__tests__/safeGlobals.test.ts +57 -2
  221. package/src/utils/__tests__/utils.test.ts +95 -0
  222. package/src/utils/associationObjectVariable.ts +2 -2
  223. package/src/utils/createCollectionContextMeta.ts +1 -0
  224. package/src/utils/createEphemeralContext.ts +5 -4
  225. package/src/utils/dateVariable.ts +397 -0
  226. package/src/utils/exceptions.ts +11 -0
  227. package/src/utils/index.ts +37 -3
  228. package/src/utils/params-resolvers.ts +23 -9
  229. package/src/utils/resolveModuleUrl.ts +91 -0
  230. package/src/utils/resolveRunJSObjectValues.ts +46 -0
  231. package/src/utils/runjsModuleLoader.ts +553 -0
  232. package/src/utils/runjsTemplateCompat.ts +828 -0
  233. package/src/utils/runjsValue.ts +287 -0
  234. package/src/utils/safeGlobals.ts +188 -17
  235. package/src/utils/schema-utils.ts +79 -0
  236. package/src/views/__tests__/FlowView.usePage.test.tsx +54 -1
  237. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +35 -8
  238. package/src/views/__tests__/viewEvents.resolveOpenerEngine.test.ts +28 -0
  239. package/src/views/createViewMeta.ts +22 -75
  240. package/src/views/index.tsx +1 -2
  241. package/src/views/useDialog.tsx +8 -1
  242. package/src/views/useDrawer.tsx +8 -1
  243. package/src/views/usePage.tsx +51 -5
  244. package/src/views/usePopover.tsx +4 -1
  245. package/src/views/viewEvents.ts +55 -0
@@ -61,6 +61,20 @@ const FlowsContextMenu = /* @__PURE__ */ __name((props) => {
61
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 { token } = import_antd.theme.useToken();
65
+ const disabledIconColor = (token == null ? void 0 : token.colorTextTertiary) || (token == null ? void 0 : token.colorTextDescription) || (token == null ? void 0 : token.colorTextSecondary);
66
+ const [configurableFlowsAndSteps, setConfigurableFlowsAndSteps] = (0, import_react.useState)([]);
67
+ const isStepMenuItemDisabled = (0, import_react.useCallback)(
68
+ (key) => {
69
+ const [flowKey, stepKey] = key.split(":");
70
+ if (!flowKey || !stepKey) return false;
71
+ return configurableFlowsAndSteps.some(({ flow, steps }) => {
72
+ if (flow.key !== flowKey) return false;
73
+ return steps.some((stepInfo) => stepInfo.stepKey === stepKey && !!stepInfo.disabled);
74
+ });
75
+ },
76
+ [configurableFlowsAndSteps]
77
+ );
64
78
  const handleMenuClick = (0, import_react.useCallback)(
65
79
  ({ key }) => {
66
80
  var _a;
@@ -86,6 +100,9 @@ const FlowsContextMenuWithModel = (0, import_reactive.observer)(
86
100
  }
87
101
  });
88
102
  } else {
103
+ if (isStepMenuItemDisabled(key)) {
104
+ return;
105
+ }
89
106
  const [flowKey, stepKey] = key.split(":");
90
107
  try {
91
108
  const flow = model.getFlow(flowKey);
@@ -108,7 +125,7 @@ const FlowsContextMenuWithModel = (0, import_reactive.observer)(
108
125
  }
109
126
  }
110
127
  },
111
- [model]
128
+ [isStepMenuItemDisabled, model]
112
129
  );
113
130
  if (!model) {
114
131
  return /* @__PURE__ */ import_react.default.createElement(import_antd.Alert, { message: "\u63D0\u4F9B\u7684\u6A21\u578B\u65E0\u6548", type: "error" });
@@ -129,6 +146,7 @@ const FlowsContextMenuWithModel = (0, import_reactive.observer)(
129
146
  if (await (0, import_utils.shouldHideStepInSettings)(model, flow, actionStep)) {
130
147
  return null;
131
148
  }
149
+ const disabledState = await (0, import_utils.resolveStepDisabledInSettings)(model, flow, actionStep);
132
150
  const stepUiSchema = actionStep.uiSchema || {};
133
151
  let actionUiSchema = {};
134
152
  if (actionStep.use) {
@@ -152,7 +170,9 @@ const FlowsContextMenuWithModel = (0, import_reactive.observer)(
152
170
  stepKey,
153
171
  step: actionStep,
154
172
  uiSchema: mergedUiSchema,
155
- title: actionStep.title || stepKey
173
+ title: actionStep.title || stepKey,
174
+ disabled: disabledState.disabled,
175
+ disabledReason: disabledState.reason
156
176
  };
157
177
  })
158
178
  ).then((steps) => steps.filter(Boolean));
@@ -165,7 +185,6 @@ const FlowsContextMenuWithModel = (0, import_reactive.observer)(
165
185
  return [];
166
186
  }
167
187
  }, [model]);
168
- const [configurableFlowsAndSteps, setConfigurableFlowsAndSteps] = (0, import_react.useState)([]);
169
188
  (0, import_react.useEffect)(() => {
170
189
  let mounted = true;
171
190
  (async () => {
@@ -193,7 +212,8 @@ const FlowsContextMenuWithModel = (0, import_reactive.observer)(
193
212
  menuItems.push({
194
213
  key: `${flow.key}:${stepInfo.stepKey}`,
195
214
  icon: /* @__PURE__ */ import_react.default.createElement(import_icons.SettingOutlined, null),
196
- label: stepInfo.title
215
+ label: stepInfo.disabled ? /* @__PURE__ */ import_react.default.createElement("span", { style: { display: "inline-flex", alignItems: "center", gap: 6 } }, stepInfo.title, /* @__PURE__ */ import_react.default.createElement(import_antd.Tooltip, { title: stepInfo.disabledReason, placement: "right", destroyTooltipOnHide: true }, /* @__PURE__ */ import_react.default.createElement(import_icons.QuestionCircleOutlined, { style: { color: disabledIconColor } }))) : stepInfo.title,
216
+ disabled: !!stepInfo.disabled
197
217
  });
198
218
  });
199
219
  });
@@ -47,6 +47,7 @@ var import_antd = require("antd");
47
47
  var import_react2 = __toESM(require("react"));
48
48
  var import_useFlowSettingsContext = require("../../../../hooks/useFlowSettingsContext");
49
49
  var import_utils = require("../../../../utils");
50
+ var import_exceptions = require("../../../../utils/exceptions");
50
51
  var import_reactive2 = require("../../../../reactive");
51
52
  const SchemaField = (0, import_react.createSchemaField)();
52
53
  const openStepSettingsDialog = /* @__PURE__ */ __name(async ({
@@ -195,7 +196,10 @@ const openStepSettingsDialog = /* @__PURE__ */ __name(async ({
195
196
  await afterParamsSave(flowRuntimeContext, currentValues, previousParams);
196
197
  }
197
198
  } catch (error) {
198
- if (error instanceof import_utils.FlowExitException) {
199
+ if (error instanceof import_utils.FlowCancelSaveException) {
200
+ return;
201
+ }
202
+ if (error instanceof import_utils.FlowExitException || error instanceof import_exceptions.FlowExitAllException) {
199
203
  currentDialog.close();
200
204
  return;
201
205
  }
@@ -198,8 +198,7 @@ const VariableInputComponent = /* @__PURE__ */ __name(({
198
198
  (0, import_react.useEffect)(() => {
199
199
  if (!resolvedMetaTreeNode) return;
200
200
  if (!Array.isArray(resolvedMetaTree) || innerValue == null) return;
201
- const finalValue = (resolveValueFromPath == null ? void 0 : resolveValueFromPath(resolvedMetaTreeNode)) || innerValue;
202
- emitChange(finalValue, resolvedMetaTreeNode);
201
+ emitChange(innerValue, resolvedMetaTreeNode);
203
202
  setCurrentMetaTreeNode(resolvedMetaTreeNode);
204
203
  }, [resolvedMetaTreeNode]);
205
204
  const composingRef = (0, import_react.useRef)(false);
@@ -230,12 +229,18 @@ const VariableInputComponent = /* @__PURE__ */ __name(({
230
229
  );
231
230
  const handleVariableSelect = (0, import_react.useCallback)(
232
231
  (variableValue, metaTreeNode) => {
232
+ if (!metaTreeNode && variableValue === "") {
233
+ const cleared = clearValue !== void 0 ? clearValue : null;
234
+ setInnerValue(cleared);
235
+ emitChange(cleared);
236
+ return;
237
+ }
233
238
  setCurrentMetaTreeNode(metaTreeNode);
234
239
  const finalValue = (resolveValueFromPath == null ? void 0 : resolveValueFromPath(metaTreeNode)) || variableValue;
235
240
  setInnerValue(finalValue);
236
241
  emitChange(finalValue, metaTreeNode);
237
242
  },
238
- [emitChange, resolveValueFromPath]
243
+ [emitChange, resolveValueFromPath, clearValue]
239
244
  );
240
245
  const { disabled } = restProps;
241
246
  const handleClear = (0, import_react.useCallback)(() => {
@@ -265,7 +270,7 @@ const VariableInputComponent = /* @__PURE__ */ __name(({
265
270
  }, [restProps]);
266
271
  const inputProps = (0, import_react.useMemo)(() => {
267
272
  const baseProps = {
268
- value: innerValue ?? "",
273
+ value: ValueComponent === import_antd.Input ? innerValue ?? "" : innerValue,
269
274
  onChange: handleInputChange,
270
275
  disabled
271
276
  };
@@ -59,53 +59,60 @@ const VariableTagComponent = /* @__PURE__ */ __name(({
59
59
  const ctx = (0, import_FlowContextProvider.useFlowContext)();
60
60
  const { data: displayedValue } = (0, import_ahooks.useRequest)(
61
61
  async () => {
62
- if (metaTreeNode) {
63
- return metaTreeNode.parentTitles ? [...metaTreeNode.parentTitles, metaTreeNode.title].map(ctx.t).join("/") : ctx.t(metaTreeNode.title) || "";
64
- }
65
- if (!value) return String(value);
66
- const rawPath = (0, import_utils.parseValueToPath)(value);
67
- if (!rawPath || !Array.isArray(resolvedMetaTree)) {
68
- return Array.isArray(rawPath) ? rawPath.join("/") : String(value);
69
- }
70
- const topNames = new Set((resolvedMetaTree || []).map((n) => String(n == null ? void 0 : n.name)));
71
- const path = !topNames.has(String(rawPath[0])) ? rawPath.slice(1) : rawPath;
72
- if (!path.length) return "";
73
- let nodes = resolvedMetaTree;
74
- let deepest = null;
75
- let matchedCount = 0;
76
- for (let i = 0; i < path.length; i++) {
77
- if (!nodes) break;
78
- const seg = String(path[i]);
79
- const node = nodes.find((n) => String(n == null ? void 0 : n.name) === seg);
80
- if (!node) break;
81
- deepest = node;
82
- matchedCount = i + 1;
83
- if (i < path.length - 1) {
84
- if (Array.isArray(node.children)) {
85
- nodes = node.children;
86
- } else if (typeof node.children === "function") {
87
- try {
88
- const childNodes = await node.children();
89
- node.children = childNodes;
90
- nodes = childNodes;
91
- } catch {
62
+ const resolveLabelFromPath = /* @__PURE__ */ __name(async (rawPath2) => {
63
+ if (!rawPath2) return null;
64
+ if (!Array.isArray(rawPath2)) return null;
65
+ if (!Array.isArray(resolvedMetaTree)) return null;
66
+ const topNames = new Set((resolvedMetaTree || []).map((n) => String(n == null ? void 0 : n.name)));
67
+ const path = !topNames.has(String(rawPath2[0])) ? rawPath2.slice(1) : rawPath2;
68
+ if (!path.length) return "";
69
+ let nodes = resolvedMetaTree;
70
+ const titleChain = [];
71
+ let matchedCount = 0;
72
+ for (let i = 0; i < path.length; i++) {
73
+ if (!nodes) break;
74
+ const seg = String(path[i]);
75
+ const node = nodes.find((n) => String(n == null ? void 0 : n.name) === seg);
76
+ if (!node) break;
77
+ titleChain.push(String(node.title ?? node.name ?? seg));
78
+ matchedCount = i + 1;
79
+ if (i < path.length - 1) {
80
+ if (Array.isArray(node.children)) {
81
+ nodes = node.children;
82
+ } else if (typeof node.children === "function") {
83
+ try {
84
+ const childNodes = await node.children();
85
+ node.children = childNodes;
86
+ nodes = childNodes;
87
+ } catch {
88
+ nodes = void 0;
89
+ }
90
+ } else {
92
91
  nodes = void 0;
93
92
  }
94
- } else {
95
- nodes = void 0;
96
93
  }
97
94
  }
98
- }
99
- if (deepest) {
100
- const titles = deepest.parentTitles ? [...deepest.parentTitles, deepest.title] : [deepest.title];
101
- let label = titles.map(ctx.t).join("/");
95
+ if (matchedCount === 0) return null;
96
+ let label2 = titleChain.map(ctx.t).join("/");
102
97
  if (matchedCount < path.length) {
103
98
  const tail = path.slice(matchedCount).join("/");
104
- label = tail ? `${label}/${tail}` : label;
99
+ label2 = tail ? `${label2}/${tail}` : label2;
105
100
  }
106
- return label;
101
+ return label2;
102
+ }, "resolveLabelFromPath");
103
+ if (metaTreeNode == null ? void 0 : metaTreeNode.parentTitles) {
104
+ return [...metaTreeNode.parentTitles, metaTreeNode.title].map(ctx.t).join("/");
105
+ }
106
+ if (metaTreeNode) {
107
+ const rawPath2 = (0, import_utils.parseValueToPath)(value) || metaTreeNode.paths;
108
+ const label2 = await resolveLabelFromPath(rawPath2);
109
+ return label2 ?? ctx.t(metaTreeNode.title) ?? "";
107
110
  }
108
- return path.join("/");
111
+ if (!value) return String(value);
112
+ const rawPath = (0, import_utils.parseValueToPath)(value);
113
+ const label = await resolveLabelFromPath(rawPath);
114
+ if (label != null) return label;
115
+ return Array.isArray(rawPath) ? rawPath.join("/") : String(value);
109
116
  },
110
117
  { refreshDeps: [resolvedMetaTree, value, metaTreeNode] }
111
118
  );
@@ -12,6 +12,13 @@ export declare const parseValueToPath: (value: string) => string[] | undefined;
12
12
  export declare const formatPathToValue: (item: MetaTreeNode) => string;
13
13
  export declare const loadMetaTreeChildren: (metaNode: MetaTreeNode) => Promise<MetaTreeNode[]>;
14
14
  export declare const searchInLoadedNodes: (options: ContextSelectorItem[], searchText: string, parentPaths?: string[]) => ContextSelectorItem[];
15
+ /**
16
+ * 仅在“已加载节点”范围内按关键字过滤 options(保留树结构)。
17
+ * - 匹配父节点:保留原节点引用(含原 children),避免不必要的实体重建。
18
+ * - 匹配子节点:返回裁剪后的父节点副本,children 仅包含命中分支。
19
+ * - 未加载 children(即 children 不为数组)不会递归搜索。
20
+ */
21
+ export declare const filterLoadedContextSelectorItems: (options: ContextSelectorItem[] | undefined, keyword: string) => ContextSelectorItem[];
15
22
  export declare const buildContextSelectorItems: (metaTree: MetaTreeNode[]) => ContextSelectorItem[];
16
23
  /**
17
24
  * 预加载:根据路径逐级加载 ContextSelectorItem 的 children,保证打开时已展开对应层级。
@@ -30,6 +30,7 @@ __export(utils_exports, {
30
30
  buildContextSelectorItems: () => buildContextSelectorItems,
31
31
  createDefaultConverters: () => createDefaultConverters,
32
32
  createFinalConverters: () => createFinalConverters,
33
+ filterLoadedContextSelectorItems: () => filterLoadedContextSelectorItems,
33
34
  formatPathToValue: () => formatPathToValue,
34
35
  isVariableValue: () => isVariableValue,
35
36
  loadMetaTreeChildren: () => loadMetaTreeChildren,
@@ -39,6 +40,16 @@ __export(utils_exports, {
39
40
  });
40
41
  module.exports = __toCommonJS(utils_exports);
41
42
  var import_utils = require("../../utils");
43
+ const getContextSelectorLabelText = /* @__PURE__ */ __name((node) => {
44
+ var _a;
45
+ if (typeof node.label === "string") {
46
+ return node.label;
47
+ }
48
+ if (typeof ((_a = node.meta) == null ? void 0 : _a.title) === "string") {
49
+ return node.meta.title;
50
+ }
51
+ return node.value;
52
+ }, "getContextSelectorLabelText");
42
53
  const parseValueToPath = /* @__PURE__ */ __name((value) => {
43
54
  if (typeof value !== "string") return void 0;
44
55
  const trimmed = value.trim();
@@ -71,10 +82,9 @@ const searchInLoadedNodes = /* @__PURE__ */ __name((options, searchText, parentP
71
82
  const lowerSearchText = searchText.toLowerCase().trim();
72
83
  const results = [];
73
84
  const searchRecursive = /* @__PURE__ */ __name((nodes, currentPath = []) => {
74
- var _a;
75
85
  for (const node of nodes) {
76
86
  const nodePath = [...currentPath, node.value];
77
- const labelText = typeof node.label === "string" ? node.label : typeof ((_a = node.meta) == null ? void 0 : _a.title) === "string" ? node.meta.title : String(node.value);
87
+ const labelText = getContextSelectorLabelText(node);
78
88
  if (labelText.toLowerCase().includes(lowerSearchText)) {
79
89
  results.push(node);
80
90
  }
@@ -86,6 +96,35 @@ const searchInLoadedNodes = /* @__PURE__ */ __name((options, searchText, parentP
86
96
  searchRecursive(options, []);
87
97
  return results;
88
98
  }, "searchInLoadedNodes");
99
+ const filterLoadedContextSelectorItems = /* @__PURE__ */ __name((options, keyword) => {
100
+ if (!Array.isArray(options) || options.length === 0) return [];
101
+ const normalizedKeyword = keyword.trim().toLowerCase();
102
+ if (!normalizedKeyword) {
103
+ return options;
104
+ }
105
+ const filterNode = /* @__PURE__ */ __name((node) => {
106
+ const labelText = getContextSelectorLabelText(node).toLowerCase();
107
+ const selfMatched = labelText.includes(normalizedKeyword);
108
+ if (selfMatched) {
109
+ return node;
110
+ }
111
+ if (!Array.isArray(node.children) || node.children.length === 0) {
112
+ return null;
113
+ }
114
+ const filteredChildren = node.children.map((child) => filterNode(child)).filter((item) => item !== null);
115
+ if (filteredChildren.length === 0) {
116
+ return null;
117
+ }
118
+ if (filteredChildren.length === node.children.length && filteredChildren.every((child, idx) => child === node.children[idx])) {
119
+ return node;
120
+ }
121
+ return {
122
+ ...node,
123
+ children: filteredChildren
124
+ };
125
+ }, "filterNode");
126
+ return options.map((node) => filterNode(node)).filter((item) => item !== null);
127
+ }, "filterLoadedContextSelectorItems");
89
128
  const buildContextSelectorItems = /* @__PURE__ */ __name((metaTree) => {
90
129
  if (!metaTree || !Array.isArray(metaTree)) {
91
130
  console.warn("buildContextSelectorItems received invalid metaTree:", metaTree);
@@ -170,6 +209,7 @@ const createFinalConverters = /* @__PURE__ */ __name((propConverters) => {
170
209
  buildContextSelectorItems,
171
210
  createDefaultConverters,
172
211
  createFinalConverters,
212
+ filterLoadedContextSelectorItems,
173
213
  formatPathToValue,
174
214
  isVariableValue,
175
215
  loadMetaTreeChildren,
@@ -66,6 +66,11 @@ export interface CollectionOptions {
66
66
  export declare class CollectionManager {
67
67
  dataSource: DataSource;
68
68
  collections: Map<string, Collection>;
69
+ allCollectionsInheritChain: string[];
70
+ protected childrenCollectionsName: {
71
+ supportView?: string[];
72
+ notSupportView?: string[];
73
+ };
69
74
  constructor(dataSource: DataSource);
70
75
  get flowEngine(): FlowEngine;
71
76
  addCollection(collection: Collection | CollectionOptions): void;
@@ -83,33 +88,8 @@ export declare class CollectionManager {
83
88
  clearCollections(): void;
84
89
  getAssociation(associationName: string): CollectionField | undefined;
85
90
  getChildrenCollections(name: any): any[];
86
- getCollectionFieldsOptions(collectionName: string, type?: string | string[], interfaces?: string | string[], opts?: {
87
- dataSource?: string;
88
- cached?: Record<string, any>;
89
- collectionNames?: string[];
90
- /**
91
- * 为 true 时允许查询所有关联字段
92
- * 为 Array<string> 时仅允许查询指定的关联字段
93
- */
94
- association?: boolean | string[];
95
- /**
96
- * Max depth of recursion
97
- */
98
- maxDepth?: number;
99
- allowAllTypes?: boolean;
100
- /**
101
- * 排除这些接口的字段
102
- */
103
- exceptInterfaces?: string[];
104
- /**
105
- * field value 的前缀,用 . 连接,比如 a.b.c
106
- */
107
- prefixFieldValue?: string;
108
- /**
109
- * 是否使用 prefixFieldValue 作为 field value
110
- */
111
- usePrefix?: boolean;
112
- }): any;
91
+ getChildrenCollectionsName(name: any, isSupportView?: boolean): string[];
92
+ getAllCollectionsInheritChain(name: any): string[];
113
93
  }
114
94
  export declare class Collection {
115
95
  fields: Map<string, CollectionField>;
@@ -118,7 +118,7 @@ const _DataSource = class _DataSource {
118
118
  return this.dataSourceManager.flowEngine;
119
119
  }
120
120
  get displayName() {
121
- return this.options.displayName ? this.flowEngine.translate(this.options.displayName) : this.key;
121
+ return this.flowEngine.translate(this.options.displayName, { ns: "lm-collections" }) || this.key;
122
122
  }
123
123
  get key() {
124
124
  return this.options.key;
@@ -188,6 +188,8 @@ const _CollectionManager = class _CollectionManager {
188
188
  this.collections = import_reactive.observable.shallow(/* @__PURE__ */ new Map());
189
189
  }
190
190
  collections;
191
+ allCollectionsInheritChain;
192
+ childrenCollectionsName = {};
191
193
  get flowEngine() {
192
194
  return this.dataSource.flowEngine;
193
195
  }
@@ -317,56 +319,75 @@ const _CollectionManager = class _CollectionManager {
317
319
  }, "getChildrens");
318
320
  return getChildrens(name);
319
321
  }
320
- getCollectionFieldsOptions(collectionName, type, interfaces, opts) {
321
- var _a;
322
- const {
323
- association = false,
324
- cached = {},
325
- collectionNames = [collectionName],
326
- maxDepth = 1,
327
- allowAllTypes = false,
328
- exceptInterfaces = [],
329
- prefixFieldValue = "",
330
- usePrefix = false,
331
- dataSource: customDataSourceNameValue
332
- } = opts || {};
333
- if (collectionNames.length - 1 > maxDepth) {
334
- return;
335
- }
336
- if (cached[collectionName]) {
337
- return import_lodash.default.cloneDeep(cached[collectionName]);
322
+ getChildrenCollectionsName(name, isSupportView = false) {
323
+ const cacheKey = isSupportView ? "supportView" : "notSupportView";
324
+ if (this.childrenCollectionsName[cacheKey]) {
325
+ return this.childrenCollectionsName[cacheKey].slice();
338
326
  }
339
- const collection = this.getCollection(collectionName);
340
- if (!collection) {
341
- throw new Error(`Collection ${collectionName} not found`);
342
- }
343
- const fields = collection.getFields();
344
- const options = (_a = fields == null ? void 0 : fields.filter(
345
- (field) => field.interface && !exceptInterfaces.includes(field.interface) && (allowAllTypes || type && type.includes(field.type) || interfaces && interfaces.includes(field.interface) || (association && field.target && field.target !== collectionName && Array.isArray(association) ? association.includes(field.interface) : false))
346
- )) == null ? void 0 : _a.map((field) => {
347
- var _a2, _b;
348
- const result = {
349
- value: usePrefix && prefixFieldValue ? `${prefixFieldValue}.${field.name}` : field.name,
350
- label: ((_a2 = field == null ? void 0 : field.uiSchema) == null ? void 0 : _a2.title) || field.name,
351
- ...field
352
- };
353
- if (association && field.target) {
354
- result.children = collectionNames.includes(field.target) ? [] : this.getCollectionFieldsOptions(field.target, type, interfaces, {
355
- ...opts,
356
- cached,
357
- dataSource: customDataSourceNameValue,
358
- collectionNames: [...collectionNames, field.target],
359
- prefixFieldValue: usePrefix ? prefixFieldValue ? `${prefixFieldValue}.${field.name}` : field.name : "",
360
- usePrefix
327
+ const children = [];
328
+ const collections = [...this.getCollections()];
329
+ const getChildrenCollectionsInner = /* @__PURE__ */ __name((collectionName) => {
330
+ const inheritCollections = collections.filter((v) => {
331
+ var _a;
332
+ return (_a = [...v.inherits]) == null ? void 0 : _a.includes(collectionName);
333
+ });
334
+ inheritCollections.forEach((v) => {
335
+ const collectionKey = v.name;
336
+ children.push(collectionKey);
337
+ return getChildrenCollectionsInner(collectionKey);
338
+ });
339
+ if (isSupportView) {
340
+ const sourceCollections = collections.filter((v) => {
341
+ var _a;
342
+ return ((_a = [...v.sources]) == null ? void 0 : _a.length) === 1 && (v == null ? void 0 : v.sources[0]) === collectionName;
343
+ });
344
+ sourceCollections.forEach((v) => {
345
+ const collectionKey = v.name;
346
+ children.push(v.name);
347
+ return getChildrenCollectionsInner(collectionKey);
361
348
  });
362
- if (!((_b = result.children) == null ? void 0 : _b.length)) {
363
- return null;
349
+ }
350
+ return import_lodash.default.uniq(children);
351
+ }, "getChildrenCollectionsInner");
352
+ this.childrenCollectionsName[cacheKey] = getChildrenCollectionsInner(name);
353
+ return this.childrenCollectionsName[cacheKey];
354
+ }
355
+ getAllCollectionsInheritChain(name) {
356
+ if (this.allCollectionsInheritChain) {
357
+ return this.allCollectionsInheritChain.slice();
358
+ }
359
+ const collectionsInheritChain = [name];
360
+ const getInheritChain = /* @__PURE__ */ __name((name2) => {
361
+ const collection = this.getCollection(name2);
362
+ if (collection) {
363
+ const { inherits } = collection;
364
+ const children = this.getChildrenCollectionsName(name2);
365
+ if (inherits) {
366
+ for (let index = 0; index < inherits.length; index++) {
367
+ const collectionKey = inherits[index];
368
+ if (collectionsInheritChain.includes(collectionKey)) {
369
+ continue;
370
+ }
371
+ collectionsInheritChain.push(collectionKey);
372
+ getInheritChain(collectionKey);
373
+ }
374
+ }
375
+ if (children) {
376
+ for (let index = 0; index < children.length; index++) {
377
+ const collection2 = this.getCollection(children[index]);
378
+ const collectionKey = collection2.name;
379
+ if (collectionsInheritChain.includes(collectionKey)) {
380
+ continue;
381
+ }
382
+ collectionsInheritChain.push(collectionKey);
383
+ getInheritChain(collectionKey);
384
+ }
364
385
  }
365
386
  }
366
- return result;
367
- }).filter(Boolean);
368
- cached[collectionName] = options;
369
- return options;
387
+ return collectionsInheritChain;
388
+ }, "getInheritChain");
389
+ this.allCollectionsInheritChain = getInheritChain(name);
390
+ return this.allCollectionsInheritChain || [];
370
391
  }
371
392
  };
372
393
  __name(_CollectionManager, "CollectionManager");
@@ -400,6 +421,9 @@ const _Collection = class _Collection {
400
421
  if (typeof this.filterTargetKey === "string") {
401
422
  return record[this.filterTargetKey];
402
423
  }
424
+ if (Array.isArray(this.filterTargetKey) && this.filterTargetKey.length === 1) {
425
+ return record[this.filterTargetKey[0]];
426
+ }
403
427
  return import_lodash.default.pick(record, this.filterTargetKey);
404
428
  }
405
429
  get titleableFields() {
@@ -433,7 +457,7 @@ const _Collection = class _Collection {
433
457
  return this.options.storage || "local";
434
458
  }
435
459
  get title() {
436
- return this.options.title ? this.flowEngine.translate(this.options.title) : this.name;
460
+ return this.flowEngine.translate(this.options.title, { ns: "lm-collections" }) || this.name;
437
461
  }
438
462
  get titleCollectionField() {
439
463
  const titleFieldName = this.options.titleField || this.filterTargetKey;
@@ -668,8 +692,8 @@ const _CollectionField = class _CollectionField {
668
692
  }
669
693
  get title() {
670
694
  var _a, _b, _c;
671
- const titleValue = ((_b = (_a = this.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b.title) || ((_c = this.options) == null ? void 0 : _c.title) || this.options.name;
672
- return this.flowEngine.translate(titleValue);
695
+ const titleValue = ((_b = (_a = this.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b.title) || ((_c = this.options) == null ? void 0 : _c.title);
696
+ return this.flowEngine.translate(titleValue, { ns: "lm-collections" }) || this.options.name;
673
697
  }
674
698
  set title(value) {
675
699
  this.options.title = value;
@@ -687,11 +711,17 @@ const _CollectionField = class _CollectionField {
687
711
  }
688
712
  return {
689
713
  ...v,
714
+ label: v.label ? this.flowEngine.translate(v.label, { ns: "lm-collections" }) : v.label,
690
715
  value: Number(v.value)
691
716
  };
692
717
  });
693
718
  }
694
- return options;
719
+ return options.map((v) => {
720
+ return {
721
+ ...v,
722
+ label: this.flowEngine.translate(v.label, { ns: "lm-collections" })
723
+ };
724
+ });
695
725
  }
696
726
  get defaultValue() {
697
727
  return this.options.defaultValue == null ? void 0 : this.options.defaultValue;
@@ -12,12 +12,13 @@ import type { DispatchEventOptions } from '../types';
12
12
  export declare class FlowExecutor {
13
13
  private readonly engine;
14
14
  constructor(engine: FlowEngine);
15
+ private emitModelEventIf;
15
16
  /** Cache wrapper for applyFlow cache lifecycle */
16
17
  private withApplyFlowCache;
17
18
  /**
18
19
  * Execute a single flow on model.
19
20
  */
20
- runFlow(model: FlowModel, flowKey: string, inputArgs?: Record<string, any>, runId?: string): Promise<any>;
21
+ runFlow(model: FlowModel, flowKey: string, inputArgs?: Record<string, any>, runId?: string, eventName?: string): Promise<any>;
21
22
  /**
22
23
  * Dispatch an event to flows bound via flow.on and execute them.
23
24
  */