@nocobase/flow-engine 2.1.0-alpha.1 → 2.1.0-alpha.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.
Files changed (252) 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/dnd/gridDragPlanner.d.ts +1 -0
  9. package/lib/components/dnd/gridDragPlanner.js +53 -1
  10. package/lib/components/settings/wrappers/component/SwitchWithTitle.js +2 -1
  11. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +76 -15
  12. package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +24 -4
  13. package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +5 -1
  14. package/lib/components/variables/VariableInput.js +9 -4
  15. package/lib/components/variables/VariableTag.js +46 -39
  16. package/lib/components/variables/utils.d.ts +7 -0
  17. package/lib/components/variables/utils.js +42 -2
  18. package/lib/data-source/index.d.ts +7 -27
  19. package/lib/data-source/index.js +84 -51
  20. package/lib/executor/FlowExecutor.d.ts +2 -1
  21. package/lib/executor/FlowExecutor.js +163 -22
  22. package/lib/flowContext.d.ts +230 -7
  23. package/lib/flowContext.js +2267 -148
  24. package/lib/flowEngine.d.ts +21 -0
  25. package/lib/flowEngine.js +55 -13
  26. package/lib/flowI18n.js +6 -4
  27. package/lib/flowSettings.js +17 -11
  28. package/lib/index.d.ts +7 -1
  29. package/lib/index.js +21 -0
  30. package/lib/locale/en-US.json +9 -2
  31. package/lib/locale/index.d.ts +14 -0
  32. package/lib/locale/zh-CN.json +8 -1
  33. package/lib/models/CollectionFieldModel.d.ts +1 -0
  34. package/lib/models/CollectionFieldModel.js +3 -2
  35. package/lib/models/flowModel.d.ts +7 -0
  36. package/lib/models/flowModel.js +66 -1
  37. package/lib/provider.js +7 -6
  38. package/lib/resources/baseRecordResource.d.ts +5 -0
  39. package/lib/resources/baseRecordResource.js +24 -0
  40. package/lib/resources/multiRecordResource.d.ts +1 -0
  41. package/lib/resources/multiRecordResource.js +11 -4
  42. package/lib/resources/singleRecordResource.js +2 -0
  43. package/lib/resources/sqlResource.d.ts +4 -3
  44. package/lib/resources/sqlResource.js +8 -3
  45. package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +12 -2
  46. package/lib/runjs-context/contexts/JSBlockRunJSContext.js +2 -2
  47. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.d.ts +16 -0
  48. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +125 -0
  49. package/lib/runjs-context/contexts/JSItemRunJSContext.js +12 -2
  50. package/lib/runjs-context/contexts/base.js +706 -41
  51. package/lib/runjs-context/contributions.d.ts +33 -0
  52. package/lib/runjs-context/contributions.js +88 -0
  53. package/lib/runjs-context/helpers.js +12 -1
  54. package/lib/runjs-context/setup.js +6 -0
  55. package/lib/runjs-context/snippets/global/api-request.snippet.js +3 -3
  56. package/lib/runjs-context/snippets/global/import-esm.snippet.js +2 -3
  57. package/lib/runjs-context/snippets/global/query-selector.snippet.js +8 -3
  58. package/lib/runjs-context/snippets/global/require-amd.snippet.js +1 -1
  59. package/lib/runjs-context/snippets/index.d.ts +11 -1
  60. package/lib/runjs-context/snippets/index.js +61 -40
  61. package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.js +10 -7
  62. package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +3 -3
  63. package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +2 -2
  64. package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.js +2 -2
  65. package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +2 -2
  66. package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +1 -1
  67. package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +1 -1
  68. package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +1 -1
  69. package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +5 -5
  70. package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +6 -6
  71. package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +3 -4
  72. package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.js +1 -1
  73. package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.js +20 -3
  74. package/lib/runjs-context/snippets/scene/detail/format-number.snippet.js +1 -1
  75. package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.js +1 -1
  76. package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +3 -3
  77. package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +3 -3
  78. package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +2 -2
  79. package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +1 -1
  80. package/lib/runjs-context/snippets/scene/form/render-basic.snippet.js +2 -2
  81. package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +6 -3
  82. package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +3 -1
  83. package/lib/runjsLibs.d.ts +28 -0
  84. package/lib/runjsLibs.js +532 -0
  85. package/lib/scheduler/ModelOperationScheduler.d.ts +2 -0
  86. package/lib/scheduler/ModelOperationScheduler.js +25 -21
  87. package/lib/types.d.ts +27 -0
  88. package/lib/utils/associationObjectVariable.d.ts +2 -2
  89. package/lib/utils/createCollectionContextMeta.js +1 -0
  90. package/lib/utils/createEphemeralContext.js +2 -2
  91. package/lib/utils/dateVariable.d.ts +16 -0
  92. package/lib/utils/dateVariable.js +380 -0
  93. package/lib/utils/exceptions.d.ts +7 -0
  94. package/lib/utils/exceptions.js +10 -0
  95. package/lib/utils/index.d.ts +8 -3
  96. package/lib/utils/index.js +45 -0
  97. package/lib/utils/params-resolvers.js +16 -9
  98. package/lib/utils/resolveModuleUrl.d.ts +58 -0
  99. package/lib/utils/resolveModuleUrl.js +65 -0
  100. package/lib/utils/resolveRunJSObjectValues.d.ts +16 -0
  101. package/lib/utils/resolveRunJSObjectValues.js +61 -0
  102. package/lib/utils/runjsModuleLoader.d.ts +58 -0
  103. package/lib/utils/runjsModuleLoader.js +422 -0
  104. package/lib/utils/runjsTemplateCompat.d.ts +35 -0
  105. package/lib/utils/runjsTemplateCompat.js +743 -0
  106. package/lib/utils/runjsValue.d.ts +29 -0
  107. package/lib/utils/runjsValue.js +275 -0
  108. package/lib/utils/safeGlobals.d.ts +18 -8
  109. package/lib/utils/safeGlobals.js +164 -17
  110. package/lib/utils/schema-utils.d.ts +10 -0
  111. package/lib/utils/schema-utils.js +61 -0
  112. package/lib/views/createViewMeta.d.ts +0 -7
  113. package/lib/views/createViewMeta.js +19 -70
  114. package/lib/views/index.d.ts +1 -2
  115. package/lib/views/index.js +4 -3
  116. package/lib/views/useDialog.js +8 -3
  117. package/lib/views/useDrawer.js +7 -2
  118. package/lib/views/usePage.d.ts +4 -0
  119. package/lib/views/usePage.js +43 -6
  120. package/lib/views/usePopover.js +4 -1
  121. package/lib/views/viewEvents.d.ts +17 -0
  122. package/lib/views/viewEvents.js +90 -0
  123. package/package.json +4 -4
  124. package/src/BlockScopedFlowEngine.ts +2 -5
  125. package/src/JSRunner.ts +44 -2
  126. package/src/ViewScopedFlowEngine.ts +4 -0
  127. package/src/__tests__/JSRunner.test.ts +64 -0
  128. package/src/__tests__/createViewMeta.popup.test.ts +62 -1
  129. package/src/__tests__/flowContext.test.ts +693 -1
  130. package/src/__tests__/flowEngine.dataSourceDirty.test.ts +63 -0
  131. package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
  132. package/src/__tests__/flowRunJSContextDefine.test.ts +63 -0
  133. package/src/__tests__/flowRuntimeContext.test.ts +2 -1
  134. package/src/__tests__/flowSettings.open.test.tsx +123 -19
  135. package/src/__tests__/provider.test.tsx +0 -5
  136. package/src/__tests__/runjsContext.test.ts +10 -7
  137. package/src/__tests__/runjsContextImplementations.test.ts +34 -3
  138. package/src/__tests__/runjsContextRuntime.test.ts +3 -3
  139. package/src/__tests__/runjsContributions.test.ts +89 -0
  140. package/src/__tests__/runjsExternalLibs.test.ts +242 -0
  141. package/src/__tests__/runjsLibsLazyLoading.test.ts +44 -0
  142. package/src/__tests__/runjsLocales.test.ts +4 -1
  143. package/src/__tests__/runjsPreprocessDefault.test.ts +49 -0
  144. package/src/__tests__/runjsRuntimeFeatures.test.ts +166 -0
  145. package/src/__tests__/runjsSnippets.test.ts +40 -3
  146. package/src/acl/Acl.tsx +3 -3
  147. package/src/components/FlowContextSelector.tsx +208 -12
  148. package/src/components/__tests__/gridDragPlanner.test.ts +141 -1
  149. package/src/components/dnd/gridDragPlanner.ts +60 -0
  150. package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +2 -1
  151. package/src/components/settings/wrappers/component/__tests__/InlineControls.test.tsx +74 -0
  152. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +109 -16
  153. package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +41 -7
  154. package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +13 -2
  155. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +157 -5
  156. package/src/components/variables/VariableInput.tsx +12 -4
  157. package/src/components/variables/VariableTag.tsx +54 -45
  158. package/src/components/variables/__tests__/FlowContextSelector.test.tsx +260 -3
  159. package/src/components/variables/__tests__/VariableTag.test.tsx +50 -0
  160. package/src/components/variables/__tests__/utils.test.ts +81 -3
  161. package/src/components/variables/utils.ts +67 -6
  162. package/src/data-source/index.ts +88 -110
  163. package/src/executor/FlowExecutor.ts +200 -23
  164. package/src/executor/__tests__/flowExecutor.test.ts +66 -0
  165. package/src/flowContext.ts +2986 -211
  166. package/src/flowEngine.ts +58 -13
  167. package/src/flowI18n.ts +7 -5
  168. package/src/flowSettings.ts +18 -12
  169. package/src/index.ts +14 -1
  170. package/src/locale/en-US.json +9 -2
  171. package/src/locale/zh-CN.json +8 -1
  172. package/src/models/CollectionFieldModel.tsx +3 -1
  173. package/src/models/__tests__/dispatchEvent.when.test.ts +554 -0
  174. package/src/models/__tests__/flowModel.clone.test.ts +416 -0
  175. package/src/models/__tests__/flowModel.test.ts +20 -4
  176. package/src/models/flowModel.tsx +94 -1
  177. package/src/provider.tsx +9 -7
  178. package/src/resources/__tests__/multiRecordResource.test.ts +44 -0
  179. package/src/resources/__tests__/sqlResource.test.ts +60 -0
  180. package/src/resources/baseRecordResource.ts +31 -0
  181. package/src/resources/multiRecordResource.ts +11 -4
  182. package/src/resources/singleRecordResource.ts +3 -0
  183. package/src/resources/sqlResource.ts +11 -6
  184. package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +10 -0
  185. package/src/runjs-context/contexts/JSBlockRunJSContext.ts +6 -2
  186. package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +106 -0
  187. package/src/runjs-context/contexts/JSItemRunJSContext.ts +10 -0
  188. package/src/runjs-context/contexts/base.ts +715 -44
  189. package/src/runjs-context/contributions.ts +88 -0
  190. package/src/runjs-context/helpers.ts +11 -1
  191. package/src/runjs-context/setup.ts +6 -0
  192. package/src/runjs-context/snippets/global/api-request.snippet.ts +3 -3
  193. package/src/runjs-context/snippets/global/import-esm.snippet.ts +2 -3
  194. package/src/runjs-context/snippets/global/query-selector.snippet.ts +8 -3
  195. package/src/runjs-context/snippets/global/require-amd.snippet.ts +1 -1
  196. package/src/runjs-context/snippets/index.ts +75 -41
  197. package/src/runjs-context/snippets/scene/block/add-event-listener.snippet.ts +11 -13
  198. package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +3 -3
  199. package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +2 -2
  200. package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +2 -2
  201. package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +2 -2
  202. package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +1 -1
  203. package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +1 -1
  204. package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +1 -1
  205. package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +6 -11
  206. package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +6 -6
  207. package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +3 -4
  208. package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +1 -1
  209. package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +20 -3
  210. package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +1 -1
  211. package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +1 -1
  212. package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +3 -3
  213. package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +3 -3
  214. package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +2 -2
  215. package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +1 -1
  216. package/src/runjs-context/snippets/scene/form/render-basic.snippet.ts +3 -8
  217. package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +6 -3
  218. package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +3 -1
  219. package/src/runjsLibs.ts +622 -0
  220. package/src/scheduler/ModelOperationScheduler.ts +27 -21
  221. package/src/types.ts +38 -1
  222. package/src/utils/__tests__/dateVariable.test.ts +101 -0
  223. package/src/utils/__tests__/params-resolvers.test.ts +40 -0
  224. package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +38 -0
  225. package/src/utils/__tests__/runjsTemplateCompat.test.ts +159 -0
  226. package/src/utils/__tests__/runjsValue.test.ts +44 -0
  227. package/src/utils/__tests__/safeGlobals.test.ts +57 -2
  228. package/src/utils/__tests__/utils.test.ts +95 -0
  229. package/src/utils/associationObjectVariable.ts +2 -2
  230. package/src/utils/createCollectionContextMeta.ts +1 -0
  231. package/src/utils/createEphemeralContext.ts +5 -4
  232. package/src/utils/dateVariable.ts +397 -0
  233. package/src/utils/exceptions.ts +11 -0
  234. package/src/utils/index.ts +37 -3
  235. package/src/utils/params-resolvers.ts +23 -9
  236. package/src/utils/resolveModuleUrl.ts +91 -0
  237. package/src/utils/resolveRunJSObjectValues.ts +46 -0
  238. package/src/utils/runjsModuleLoader.ts +553 -0
  239. package/src/utils/runjsTemplateCompat.ts +828 -0
  240. package/src/utils/runjsValue.ts +287 -0
  241. package/src/utils/safeGlobals.ts +188 -17
  242. package/src/utils/schema-utils.ts +79 -0
  243. package/src/views/__tests__/FlowView.usePage.test.tsx +54 -1
  244. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +35 -8
  245. package/src/views/__tests__/viewEvents.resolveOpenerEngine.test.ts +28 -0
  246. package/src/views/createViewMeta.ts +22 -75
  247. package/src/views/index.tsx +1 -2
  248. package/src/views/useDialog.tsx +9 -2
  249. package/src/views/useDrawer.tsx +8 -1
  250. package/src/views/usePage.tsx +51 -5
  251. package/src/views/usePopover.tsx +4 -1
  252. package/src/views/viewEvents.ts +55 -0
@@ -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;
@@ -682,13 +706,22 @@ const _CollectionField = class _CollectionField {
682
706
  if (typeof v !== "object") {
683
707
  return v;
684
708
  }
709
+ if (v.value === null || v.value === void 0) {
710
+ return v;
711
+ }
685
712
  return {
686
713
  ...v,
714
+ label: v.label ? this.flowEngine.translate(v.label, { ns: "lm-collections" }) : v.label,
687
715
  value: Number(v.value)
688
716
  };
689
717
  });
690
718
  }
691
- return options;
719
+ return options.map((v) => {
720
+ return {
721
+ ...v,
722
+ label: this.flowEngine.translate(v.label, { ns: "lm-collections" })
723
+ };
724
+ });
692
725
  }
693
726
  get defaultValue() {
694
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
  */
@@ -51,6 +51,10 @@ const _FlowExecutor = class _FlowExecutor {
51
51
  constructor(engine) {
52
52
  this.engine = engine;
53
53
  }
54
+ async emitModelEventIf(eventName, topic, payload) {
55
+ if (!eventName) return;
56
+ await this.engine.emitter.emitAsync(`model:event:${eventName}:${topic}`, payload);
57
+ }
54
58
  /** Cache wrapper for applyFlow cache lifecycle */
55
59
  async withApplyFlowCache(cacheKey, executor) {
56
60
  if (!cacheKey || !this.engine) return await executor();
@@ -81,7 +85,7 @@ const _FlowExecutor = class _FlowExecutor {
81
85
  /**
82
86
  * Execute a single flow on model.
83
87
  */
84
- async runFlow(model, flowKey, inputArgs, runId) {
88
+ async runFlow(model, flowKey, inputArgs, runId, eventName) {
85
89
  var _a;
86
90
  const flow = model.getFlow(flowKey);
87
91
  if (!flow) {
@@ -113,6 +117,14 @@ const _FlowExecutor = class _FlowExecutor {
113
117
  const stepDefs = eventStep ? { eventStep, ...flow.steps } : flow.steps;
114
118
  (0, import_setupRuntimeContextSteps.setupRuntimeContextSteps)(flowContext, stepDefs, model, flowKey);
115
119
  const stepsRuntime = flowContext.steps;
120
+ const flowEventBasePayload = {
121
+ uid: model.uid,
122
+ model,
123
+ runId: flowContext.runId,
124
+ inputArgs,
125
+ flowKey
126
+ };
127
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:start`, flowEventBasePayload);
116
128
  for (const [stepKey, step] of Object.entries(stepDefs)) {
117
129
  let handler;
118
130
  let combinedParams = {};
@@ -163,20 +175,56 @@ const _FlowExecutor = class _FlowExecutor {
163
175
  );
164
176
  continue;
165
177
  }
178
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:start`, {
179
+ ...flowEventBasePayload,
180
+ stepKey
181
+ });
166
182
  const currentStepResult = handler(runtimeCtx, combinedParams);
167
183
  const isAwait = step.isAwait !== false;
168
184
  lastResult = isAwait ? await currentStepResult : currentStepResult;
169
185
  stepResults[stepKey] = lastResult;
170
186
  stepsRuntime[stepKey].result = stepResults[stepKey];
187
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:end`, {
188
+ ...flowEventBasePayload,
189
+ result: lastResult,
190
+ stepKey
191
+ });
171
192
  } catch (error) {
193
+ if (!(error instanceof import_utils.FlowExitException) && !(error instanceof import_exceptions.FlowExitAllException)) {
194
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:error`, {
195
+ ...flowEventBasePayload,
196
+ error,
197
+ stepKey
198
+ });
199
+ }
172
200
  if (error instanceof import_utils.FlowExitException) {
173
201
  flowContext.logger.info(`[FlowEngine] ${error.message}`);
202
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:end`, {
203
+ ...flowEventBasePayload,
204
+ stepKey
205
+ });
206
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:end`, {
207
+ ...flowEventBasePayload,
208
+ result: stepResults
209
+ });
174
210
  return Promise.resolve(stepResults);
175
211
  }
176
212
  if (error instanceof import_exceptions.FlowExitAllException) {
177
213
  flowContext.logger.info(`[FlowEngine] ${error.message}`);
214
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:end`, {
215
+ ...flowEventBasePayload,
216
+ stepKey
217
+ });
218
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:end`, {
219
+ ...flowEventBasePayload,
220
+ result: error
221
+ });
178
222
  return Promise.resolve(error);
179
223
  }
224
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:error`, {
225
+ ...flowEventBasePayload,
226
+ error
227
+ });
180
228
  flowContext.logger.error(
181
229
  { err: error },
182
230
  `BaseModel.applyFlow: Error executing step '${stepKey}' in flow '${flowKey}':`
@@ -184,9 +232,12 @@ const _FlowExecutor = class _FlowExecutor {
184
232
  return Promise.reject(error);
185
233
  }
186
234
  }
235
+ await this.emitModelEventIf(eventName, `flow:${flowKey}:end`, {
236
+ ...flowEventBasePayload,
237
+ result: stepResults
238
+ });
187
239
  return Promise.resolve(stepResults);
188
240
  }
189
- // runAutoFlows 已移除:统一通过 dispatchEvent('beforeRender') + useCache 控制
190
241
  /**
191
242
  * Dispatch an event to flows bound via flow.on and execute them.
192
243
  */
@@ -198,13 +249,14 @@ const _FlowExecutor = class _FlowExecutor {
198
249
  const throwOnError = isBeforeRender;
199
250
  const runId = `${model.uid}-${eventName}-${Date.now()}`;
200
251
  const logger = model.context.logger;
252
+ const eventBasePayload = {
253
+ uid: model.uid,
254
+ model,
255
+ runId,
256
+ inputArgs
257
+ };
201
258
  try {
202
- await this.engine.emitter.emitAsync(`model:event:${eventName}:start`, {
203
- uid: model.uid,
204
- model,
205
- runId,
206
- inputArgs
207
- });
259
+ await this.emitModelEventIf(eventName, "start", eventBasePayload);
208
260
  await ((_a = model.onDispatchEventStart) == null ? void 0 : _a.call(model, eventName, options, inputArgs));
209
261
  } catch (err) {
210
262
  if (isBeforeRender && err instanceof import_utils.FlowExitException) {
@@ -226,9 +278,17 @@ const _FlowExecutor = class _FlowExecutor {
226
278
  if (typeof on === "object") return on.eventName === eventName;
227
279
  return false;
228
280
  });
281
+ const isRouterReplayClick = eventName === "click" && (inputArgs == null ? void 0 : inputArgs.triggerByRouter) === true;
282
+ const flowsToRun = isRouterReplayClick ? flows.filter((flow) => {
283
+ var _a2;
284
+ const reg = flow["flowRegistry"];
285
+ const type = (_a2 = reg == null ? void 0 : reg.constructor) == null ? void 0 : _a2._type;
286
+ return type !== "instance";
287
+ }) : flows;
288
+ const scheduledCancels = [];
229
289
  const execute = /* @__PURE__ */ __name(async () => {
230
290
  if (sequential) {
231
- const flowsWithIndex = flows.map((f, i) => ({ f, i }));
291
+ const flowsWithIndex = flowsToRun.map((f, i) => ({ f, i }));
232
292
  const ordered = flowsWithIndex.slice().sort((a, b) => {
233
293
  var _a2, _b2;
234
294
  const regA = a.f["flowRegistry"];
@@ -244,18 +304,101 @@ const _FlowExecutor = class _FlowExecutor {
244
304
  return a.i - b.i;
245
305
  }).map((x) => x.f);
246
306
  const results2 = [];
307
+ const staticFlowsByKey = new Map(
308
+ ordered.filter((f) => {
309
+ var _a2;
310
+ const reg = f["flowRegistry"];
311
+ const type = (_a2 = reg == null ? void 0 : reg.constructor) == null ? void 0 : _a2._type;
312
+ return type !== "instance";
313
+ }).map((f) => [f.key, f])
314
+ );
315
+ const scheduled = /* @__PURE__ */ new Set();
316
+ const scheduleGroups = /* @__PURE__ */ new Map();
317
+ ordered.forEach((flow, indexInOrdered) => {
318
+ var _a2;
319
+ const on = flow.on;
320
+ const onObj = typeof on === "object" ? on : void 0;
321
+ if (!onObj) return;
322
+ const phase = onObj.phase;
323
+ const flowKey = onObj.flowKey;
324
+ const stepKey = onObj.stepKey;
325
+ if (!phase || phase === "beforeAllFlows") return;
326
+ let whenKey = null;
327
+ if (phase === "afterAllFlows") {
328
+ whenKey = `event:${eventName}:end`;
329
+ } else if (phase === "beforeFlow" || phase === "afterFlow") {
330
+ if (!flowKey) {
331
+ whenKey = `event:${eventName}:end`;
332
+ } else {
333
+ const anchorFlow = staticFlowsByKey.get(String(flowKey));
334
+ if (anchorFlow) {
335
+ const anchorPhase = phase === "beforeFlow" ? "start" : "end";
336
+ whenKey = `event:${eventName}:flow:${String(flowKey)}:${anchorPhase}`;
337
+ } else {
338
+ whenKey = `event:${eventName}:end`;
339
+ }
340
+ }
341
+ } else if (phase === "beforeStep" || phase === "afterStep") {
342
+ if (!flowKey || !stepKey) {
343
+ whenKey = `event:${eventName}:end`;
344
+ } else {
345
+ const anchorFlow = staticFlowsByKey.get(String(flowKey));
346
+ const anchorStepExists = !!((_a2 = anchorFlow == null ? void 0 : anchorFlow.hasStep) == null ? void 0 : _a2.call(anchorFlow, String(stepKey)));
347
+ if (anchorFlow && anchorStepExists) {
348
+ const anchorPhase = phase === "beforeStep" ? "start" : "end";
349
+ whenKey = `event:${eventName}:flow:${String(flowKey)}:step:${String(stepKey)}:${anchorPhase}`;
350
+ } else {
351
+ whenKey = `event:${eventName}:end`;
352
+ }
353
+ }
354
+ } else {
355
+ return;
356
+ }
357
+ if (!whenKey) return;
358
+ scheduled.add(flow.key);
359
+ const list = scheduleGroups.get(whenKey) || [];
360
+ list.push({ flow, order: indexInOrdered });
361
+ scheduleGroups.set(whenKey, list);
362
+ });
363
+ for (const [whenKey, list] of scheduleGroups.entries()) {
364
+ const sorted = list.slice().sort((a, b) => {
365
+ const sa = a.flow.sort ?? 0;
366
+ const sb = b.flow.sort ?? 0;
367
+ if (sa !== sb) return sa - sb;
368
+ return a.order - b.order;
369
+ });
370
+ for (const it of sorted) {
371
+ const cancel = model.scheduleModelOperation(
372
+ model.uid,
373
+ async (m) => {
374
+ const res = await this.runFlow(m, it.flow.key, inputArgs, runId, eventName);
375
+ if (res instanceof import_exceptions.FlowExitAllException) {
376
+ throw res;
377
+ }
378
+ results2.push(res);
379
+ },
380
+ { when: whenKey }
381
+ );
382
+ scheduledCancels.push(cancel);
383
+ }
384
+ }
247
385
  for (const flow of ordered) {
386
+ if (scheduled.has(flow.key)) continue;
248
387
  try {
249
388
  logger.debug(
250
389
  `BaseModel '${model.uid}' dispatching event '${eventName}' to flow '${flow.key}' (sequential).`
251
390
  );
252
- const result = await this.runFlow(model, flow.key, inputArgs, runId);
391
+ const result = await this.runFlow(model, flow.key, inputArgs, runId, eventName);
253
392
  if (result instanceof import_exceptions.FlowExitAllException) {
254
393
  logger.debug(`[FlowEngine.dispatchEvent] ${result.message}`);
255
394
  break;
256
395
  }
257
396
  results2.push(result);
258
397
  } catch (error) {
398
+ if (error instanceof import_exceptions.FlowExitAllException) {
399
+ logger.debug(`[FlowEngine.dispatchEvent] ${error.message}`);
400
+ break;
401
+ }
259
402
  logger.error(
260
403
  { err: error },
261
404
  `BaseModel.dispatchEvent: Error executing event-triggered flow '${flow.key}' for event '${eventName}' (sequential):`
@@ -266,10 +409,10 @@ const _FlowExecutor = class _FlowExecutor {
266
409
  return results2;
267
410
  }
268
411
  const results = await Promise.all(
269
- flows.map(async (flow) => {
412
+ flowsToRun.map(async (flow) => {
270
413
  logger.debug(`BaseModel '${model.uid}' dispatching event '${eventName}' to flow '${flow.key}'.`);
271
414
  try {
272
- return await this.runFlow(model, flow.key, inputArgs, runId);
415
+ return await this.runFlow(model, flow.key, inputArgs, runId, eventName);
273
416
  } catch (error) {
274
417
  logger.error(
275
418
  { err: error },
@@ -295,11 +438,8 @@ const _FlowExecutor = class _FlowExecutor {
295
438
  } catch (hookErr) {
296
439
  logger.error({ err: hookErr }, `BaseModel.dispatchEvent: End hook error for event '${eventName}'`);
297
440
  }
298
- await this.engine.emitter.emitAsync(`model:event:${eventName}:end`, {
299
- uid: model.uid,
300
- model,
301
- runId,
302
- inputArgs,
441
+ await this.emitModelEventIf(eventName, "end", {
442
+ ...eventBasePayload,
303
443
  result
304
444
  });
305
445
  return result;
@@ -312,14 +452,15 @@ const _FlowExecutor = class _FlowExecutor {
312
452
  { err: error },
313
453
  `BaseModel.dispatchEvent: Error executing event '${eventName}' for model '${model.uid}':`
314
454
  );
315
- await this.engine.emitter.emitAsync(`model:event:${eventName}:error`, {
316
- uid: model.uid,
317
- model,
318
- runId,
319
- inputArgs,
455
+ await this.emitModelEventIf(eventName, "error", {
456
+ ...eventBasePayload,
320
457
  error
321
458
  });
322
459
  if (throwOnError) throw error;
460
+ } finally {
461
+ for (const cancel of scheduledCancels) {
462
+ cancel();
463
+ }
323
464
  }
324
465
  }
325
466
  };