@nocobase/flow-engine 2.1.0-alpha.4 → 2.1.0-alpha.45

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 (209) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -10
  3. package/lib/FlowContextProvider.d.ts +5 -1
  4. package/lib/FlowContextProvider.js +9 -2
  5. package/lib/JSRunner.d.ts +10 -1
  6. package/lib/JSRunner.js +50 -5
  7. package/lib/ViewScopedFlowEngine.js +5 -1
  8. package/lib/components/FieldModelRenderer.js +2 -2
  9. package/lib/components/FlowModelRenderer.d.ts +3 -1
  10. package/lib/components/FlowModelRenderer.js +12 -6
  11. package/lib/components/FormItem.d.ts +6 -0
  12. package/lib/components/FormItem.js +11 -3
  13. package/lib/components/MobilePopup.js +6 -5
  14. package/lib/components/dnd/gridDragPlanner.d.ts +59 -2
  15. package/lib/components/dnd/gridDragPlanner.js +613 -21
  16. package/lib/components/dnd/index.d.ts +31 -2
  17. package/lib/components/dnd/index.js +244 -23
  18. package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +2 -1
  19. package/lib/components/settings/wrappers/component/SelectWithTitle.js +14 -12
  20. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
  21. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +76 -11
  22. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +23 -43
  23. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +352 -295
  24. package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +16 -2
  25. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.d.ts +36 -0
  26. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +274 -0
  27. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
  28. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +315 -0
  29. package/lib/components/subModel/AddSubModelButton.js +27 -1
  30. package/lib/components/subModel/LazyDropdown.js +293 -52
  31. package/lib/components/subModel/index.d.ts +1 -0
  32. package/lib/components/subModel/index.js +19 -0
  33. package/lib/components/subModel/utils.d.ts +1 -1
  34. package/lib/components/subModel/utils.js +9 -3
  35. package/lib/components/variables/VariableHybridInput.d.ts +27 -0
  36. package/lib/components/variables/VariableHybridInput.js +499 -0
  37. package/lib/components/variables/index.d.ts +2 -0
  38. package/lib/components/variables/index.js +3 -0
  39. package/lib/data-source/index.d.ts +84 -0
  40. package/lib/data-source/index.js +259 -5
  41. package/lib/executor/FlowExecutor.js +32 -9
  42. package/lib/flow-registry/DetachedFlowRegistry.d.ts +21 -0
  43. package/lib/flow-registry/DetachedFlowRegistry.js +80 -0
  44. package/lib/flow-registry/index.d.ts +1 -0
  45. package/lib/flow-registry/index.js +3 -1
  46. package/lib/flowContext.d.ts +3 -0
  47. package/lib/flowContext.js +46 -1
  48. package/lib/flowEngine.d.ts +151 -1
  49. package/lib/flowEngine.js +392 -18
  50. package/lib/flowI18n.js +2 -1
  51. package/lib/flowSettings.d.ts +14 -6
  52. package/lib/flowSettings.js +34 -6
  53. package/lib/index.d.ts +2 -0
  54. package/lib/index.js +7 -0
  55. package/lib/lazy-helper.d.ts +14 -0
  56. package/lib/lazy-helper.js +71 -0
  57. package/lib/locale/en-US.json +1 -0
  58. package/lib/locale/index.d.ts +2 -0
  59. package/lib/locale/zh-CN.json +1 -0
  60. package/lib/models/DisplayItemModel.d.ts +1 -1
  61. package/lib/models/EditableItemModel.d.ts +1 -1
  62. package/lib/models/FilterableItemModel.d.ts +1 -1
  63. package/lib/models/flowModel.d.ts +13 -10
  64. package/lib/models/flowModel.js +81 -21
  65. package/lib/provider.js +38 -23
  66. package/lib/reactive/observer.js +46 -16
  67. package/lib/runjs-context/registry.d.ts +1 -1
  68. package/lib/runjs-context/setup.js +20 -12
  69. package/lib/runjs-context/snippets/index.js +13 -2
  70. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts +11 -0
  71. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.js +50 -0
  72. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts +11 -0
  73. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
  74. package/lib/scheduler/ModelOperationScheduler.d.ts +5 -1
  75. package/lib/scheduler/ModelOperationScheduler.js +3 -2
  76. package/lib/types.d.ts +50 -2
  77. package/lib/types.js +1 -0
  78. package/lib/utils/createCollectionContextMeta.js +6 -2
  79. package/lib/utils/index.d.ts +3 -2
  80. package/lib/utils/index.js +7 -0
  81. package/lib/utils/parsePathnameToViewParams.d.ts +5 -1
  82. package/lib/utils/parsePathnameToViewParams.js +29 -5
  83. package/lib/utils/randomId.d.ts +39 -0
  84. package/lib/utils/randomId.js +45 -0
  85. package/lib/utils/runjsTemplateCompat.js +1 -1
  86. package/lib/utils/runjsValue.js +41 -11
  87. package/lib/utils/schema-utils.d.ts +7 -1
  88. package/lib/utils/schema-utils.js +19 -0
  89. package/lib/views/FlowView.d.ts +7 -1
  90. package/lib/views/FlowView.js +11 -1
  91. package/lib/views/PageComponent.js +8 -6
  92. package/lib/views/ViewNavigation.d.ts +12 -2
  93. package/lib/views/ViewNavigation.js +28 -9
  94. package/lib/views/createViewMeta.js +114 -50
  95. package/lib/views/inheritLayoutContext.d.ts +10 -0
  96. package/lib/views/inheritLayoutContext.js +50 -0
  97. package/lib/views/runViewBeforeClose.d.ts +10 -0
  98. package/lib/views/runViewBeforeClose.js +45 -0
  99. package/lib/views/useDialog.d.ts +2 -1
  100. package/lib/views/useDialog.js +22 -3
  101. package/lib/views/useDrawer.d.ts +2 -1
  102. package/lib/views/useDrawer.js +22 -3
  103. package/lib/views/usePage.d.ts +5 -11
  104. package/lib/views/usePage.js +304 -144
  105. package/package.json +6 -5
  106. package/src/FlowContextProvider.tsx +9 -1
  107. package/src/JSRunner.ts +68 -4
  108. package/src/ViewScopedFlowEngine.ts +4 -0
  109. package/src/__tests__/JSRunner.test.ts +27 -1
  110. package/src/__tests__/createViewMeta.popup.test.ts +115 -1
  111. package/src/__tests__/flow-engine.test.ts +166 -0
  112. package/src/__tests__/flowContext.test.ts +82 -1
  113. package/src/__tests__/flowEngine.modelLoaders.test.ts +245 -0
  114. package/src/__tests__/flowEngine.removeModel.test.ts +47 -3
  115. package/src/__tests__/flowSettings.test.ts +94 -15
  116. package/src/__tests__/objectVariable.test.ts +24 -0
  117. package/src/__tests__/provider.test.tsx +24 -2
  118. package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
  119. package/src/__tests__/runjsContext.test.ts +16 -0
  120. package/src/__tests__/runjsContextRuntime.test.ts +2 -0
  121. package/src/__tests__/runjsPreprocessDefault.test.ts +23 -0
  122. package/src/__tests__/runjsSnippets.test.ts +21 -0
  123. package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
  124. package/src/components/FieldModelRenderer.tsx +2 -1
  125. package/src/components/FlowModelRenderer.tsx +18 -6
  126. package/src/components/FormItem.tsx +7 -1
  127. package/src/components/MobilePopup.tsx +4 -2
  128. package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
  129. package/src/components/__tests__/FormItem.test.tsx +25 -0
  130. package/src/components/__tests__/dnd.test.ts +44 -0
  131. package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +20 -10
  132. package/src/components/__tests__/gridDragPlanner.test.ts +558 -3
  133. package/src/components/dnd/__tests__/DndProvider.test.tsx +98 -0
  134. package/src/components/dnd/gridDragPlanner.ts +758 -19
  135. package/src/components/dnd/index.tsx +305 -28
  136. package/src/components/settings/wrappers/component/SelectWithTitle.tsx +21 -9
  137. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +99 -11
  138. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +487 -440
  139. package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +18 -2
  140. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +194 -5
  141. package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +778 -0
  142. package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +360 -0
  143. package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +361 -0
  144. package/src/components/subModel/AddSubModelButton.tsx +32 -2
  145. package/src/components/subModel/LazyDropdown.tsx +332 -56
  146. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +522 -37
  147. package/src/components/subModel/__tests__/utils.test.ts +24 -0
  148. package/src/components/subModel/index.ts +1 -0
  149. package/src/components/subModel/utils.ts +7 -1
  150. package/src/components/variables/VariableHybridInput.tsx +531 -0
  151. package/src/components/variables/index.ts +2 -0
  152. package/src/data-source/__tests__/collection.test.ts +41 -2
  153. package/src/data-source/__tests__/index.test.ts +68 -1
  154. package/src/data-source/index.ts +322 -6
  155. package/src/executor/FlowExecutor.ts +35 -10
  156. package/src/executor/__tests__/flowExecutor.test.ts +85 -0
  157. package/src/flow-registry/DetachedFlowRegistry.ts +46 -0
  158. package/src/flow-registry/__tests__/detachedFlowRegistry.test.ts +47 -0
  159. package/src/flow-registry/index.ts +1 -0
  160. package/src/flowContext.ts +50 -3
  161. package/src/flowEngine.ts +449 -14
  162. package/src/flowI18n.ts +2 -1
  163. package/src/flowSettings.ts +40 -6
  164. package/src/index.ts +2 -0
  165. package/src/lazy-helper.tsx +57 -0
  166. package/src/locale/en-US.json +1 -0
  167. package/src/locale/zh-CN.json +1 -0
  168. package/src/models/DisplayItemModel.tsx +1 -1
  169. package/src/models/EditableItemModel.tsx +1 -1
  170. package/src/models/FilterableItemModel.tsx +1 -1
  171. package/src/models/__tests__/dispatchEvent.when.test.ts +214 -0
  172. package/src/models/__tests__/flowEngine.resolveUse.test.ts +0 -15
  173. package/src/models/__tests__/flowModel.test.ts +80 -37
  174. package/src/models/flowModel.tsx +122 -36
  175. package/src/provider.tsx +41 -25
  176. package/src/reactive/__tests__/observer.test.tsx +82 -0
  177. package/src/reactive/observer.tsx +87 -25
  178. package/src/runjs-context/registry.ts +1 -1
  179. package/src/runjs-context/setup.ts +22 -12
  180. package/src/runjs-context/snippets/index.ts +12 -1
  181. package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
  182. package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
  183. package/src/scheduler/ModelOperationScheduler.ts +14 -3
  184. package/src/types.ts +62 -0
  185. package/src/utils/__tests__/createCollectionContextMeta.test.ts +48 -0
  186. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +28 -0
  187. package/src/utils/__tests__/runjsValue.test.ts +11 -0
  188. package/src/utils/__tests__/utils.test.ts +62 -0
  189. package/src/utils/createCollectionContextMeta.ts +6 -2
  190. package/src/utils/index.ts +5 -1
  191. package/src/utils/parsePathnameToViewParams.ts +47 -7
  192. package/src/utils/randomId.ts +48 -0
  193. package/src/utils/runjsTemplateCompat.ts +1 -1
  194. package/src/utils/runjsValue.ts +50 -11
  195. package/src/utils/schema-utils.ts +30 -1
  196. package/src/views/FlowView.tsx +22 -2
  197. package/src/views/PageComponent.tsx +7 -4
  198. package/src/views/ViewNavigation.ts +46 -9
  199. package/src/views/__tests__/FlowView.usePage.test.tsx +243 -3
  200. package/src/views/__tests__/ViewNavigation.test.ts +52 -0
  201. package/src/views/__tests__/inheritLayoutContext.test.ts +53 -0
  202. package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
  203. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +13 -12
  204. package/src/views/createViewMeta.ts +106 -34
  205. package/src/views/inheritLayoutContext.ts +26 -0
  206. package/src/views/runViewBeforeClose.ts +19 -0
  207. package/src/views/useDialog.tsx +27 -3
  208. package/src/views/useDrawer.tsx +27 -3
  209. package/src/views/usePage.tsx +367 -179
@@ -42,6 +42,7 @@ __export(data_source_exports, {
42
42
  CollectionManager: () => CollectionManager,
43
43
  DataSource: () => DataSource,
44
44
  DataSourceManager: () => DataSourceManager,
45
+ getCollectionFieldInterface: () => getCollectionFieldInterface,
45
46
  isFieldInterfaceMatch: () => isFieldInterfaceMatch,
46
47
  jioToJoiSchema: () => import_jioToJoiSchema.jioToJoiSchema
47
48
  });
@@ -53,12 +54,59 @@ var import_sortCollectionsByInherits = require("./sortCollectionsByInherits");
53
54
  const _DataSourceManager = class _DataSourceManager {
54
55
  dataSources;
55
56
  flowEngine;
57
+ requester;
58
+ collectionFieldInterfaceManager;
59
+ loaders = /* @__PURE__ */ new Map();
60
+ loadedKeys = /* @__PURE__ */ new Set();
61
+ loadingKeys = /* @__PURE__ */ new Set();
62
+ loadErrors = /* @__PURE__ */ new Map();
63
+ loadingPromise = null;
56
64
  constructor() {
57
65
  this.dataSources = import_reactive.observable.shallow(/* @__PURE__ */ new Map());
58
66
  }
59
67
  setFlowEngine(flowEngine) {
60
68
  this.flowEngine = flowEngine;
61
69
  }
70
+ setRequester(requester) {
71
+ this.requester = requester;
72
+ }
73
+ setCollectionFieldInterfaceManager(manager) {
74
+ this.collectionFieldInterfaceManager = manager;
75
+ }
76
+ addFieldInterfaces(fieldInterfaceClasses = []) {
77
+ var _a, _b;
78
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaces) == null ? void 0 : _b.call(_a, fieldInterfaceClasses);
79
+ }
80
+ addFieldInterfaceGroups(groups) {
81
+ var _a, _b;
82
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceGroups) == null ? void 0 : _b.call(_a, groups);
83
+ }
84
+ addFieldInterfaceComponentOption(name, option) {
85
+ var _a, _b;
86
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceComponentOption) == null ? void 0 : _b.call(_a, name, option);
87
+ }
88
+ addFieldInterfaceOperator(name, operator) {
89
+ var _a, _b;
90
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceOperator) == null ? void 0 : _b.call(_a, name, operator);
91
+ }
92
+ registerFieldFilterOperator(operator) {
93
+ var _a, _b;
94
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.registerFieldFilterOperator) == null ? void 0 : _b.call(_a, operator);
95
+ }
96
+ registerFieldFilterOperatorGroup(name, operators = []) {
97
+ var _a, _b;
98
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.registerFieldFilterOperatorGroup) == null ? void 0 : _b.call(_a, name, operators);
99
+ }
100
+ addFieldFilterOperatorsToGroup(name, operators = []) {
101
+ var _a, _b;
102
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldFilterOperatorsToGroup) == null ? void 0 : _b.call(_a, name, operators);
103
+ }
104
+ registerLoader(key, loader) {
105
+ this.loaders.set(key, loader);
106
+ }
107
+ removeLoader(key) {
108
+ this.loaders.delete(key);
109
+ }
62
110
  addDataSource(ds) {
63
111
  if (this.dataSources.has(ds.key)) {
64
112
  throw new Error(`DataSource with name ${ds.key} already exists`);
@@ -75,7 +123,7 @@ const _DataSourceManager = class _DataSourceManager {
75
123
  upsertDataSource(ds) {
76
124
  var _a;
77
125
  if (this.dataSources.has(ds.key)) {
78
- (_a = this.dataSources.get(ds.key)) == null ? void 0 : _a.setOptions(ds);
126
+ (_a = this.dataSources.get(ds.key)) == null ? void 0 : _a.patchOptions(ds);
79
127
  } else {
80
128
  this.addDataSource(ds);
81
129
  }
@@ -103,9 +151,161 @@ const _DataSourceManager = class _DataSourceManager {
103
151
  if (!ds) return void 0;
104
152
  return ds.getCollectionField(otherKeys.join("."));
105
153
  }
154
+ async ensureLoaded(options = {}) {
155
+ const { force = false } = options;
156
+ const keys = this.resolveLoadKeys(options.keys);
157
+ const pendingKeys = force ? keys : keys.filter((key) => !this.loadedKeys.has(key));
158
+ if (!pendingKeys.length) {
159
+ return;
160
+ }
161
+ if (this.loadingPromise) {
162
+ return this.loadingPromise;
163
+ }
164
+ this.loadingPromise = (async () => {
165
+ try {
166
+ for (const key of pendingKeys) {
167
+ await this.loadKey(key, { initial: !this.loadedKeys.has(key), force });
168
+ }
169
+ } finally {
170
+ this.loadingPromise = null;
171
+ }
172
+ })();
173
+ return this.loadingPromise;
174
+ }
175
+ async reload(options = {}) {
176
+ const keys = this.resolveLoadKeys(options.keys);
177
+ if (!keys.length) {
178
+ return;
179
+ }
180
+ if (this.loadingPromise) {
181
+ return this.loadingPromise;
182
+ }
183
+ this.loadingPromise = (async () => {
184
+ try {
185
+ for (const key of keys) {
186
+ await this.loadKey(key, { initial: false, force: true });
187
+ }
188
+ } finally {
189
+ this.loadingPromise = null;
190
+ }
191
+ })();
192
+ return this.loadingPromise;
193
+ }
194
+ async reloadDataSource(key) {
195
+ if (this.loadingKeys.has(key) && this.loadingPromise) {
196
+ return this.loadingPromise;
197
+ }
198
+ if (!this.loaders.has(key) && this.loaders.has("*")) {
199
+ return this.reload({ keys: ["*"] });
200
+ }
201
+ return this.reload({ keys: [key] });
202
+ }
203
+ resolveLoadKeys(requestedKeys) {
204
+ const normalizedKeys = (requestedKeys == null ? void 0 : requestedKeys.length) ? requestedKeys : ["main"];
205
+ const explicitKeys = normalizedKeys.filter((key) => this.loaders.has(key));
206
+ if (this.loaders.has("*")) {
207
+ return import_lodash.default.uniq(["*", ...explicitKeys]);
208
+ }
209
+ return explicitKeys.length ? explicitKeys : normalizedKeys;
210
+ }
211
+ getApp() {
212
+ var _a, _b;
213
+ return (_b = (_a = this.flowEngine) == null ? void 0 : _a.context) == null ? void 0 : _b.app;
214
+ }
215
+ dispatchDataSourceEvent(type, detail) {
216
+ var _a, _b;
217
+ (_b = (_a = this.getApp()) == null ? void 0 : _a.eventBus) == null ? void 0 : _b.dispatchEvent(new CustomEvent(type, { detail }));
218
+ }
219
+ setDataSourceState(key, options) {
220
+ const dataSource = this.getDataSource(key);
221
+ if (!dataSource) {
222
+ return;
223
+ }
224
+ dataSource.patchOptions(options);
225
+ }
226
+ applyDataSourceLoadResult(key, result) {
227
+ if (key === "*") {
228
+ const dataSources = (result == null ? void 0 : result.dataSources) || [];
229
+ dataSources.forEach((dataSourceOptions) => {
230
+ var _a;
231
+ const { collections, ...dataSource2 } = dataSourceOptions;
232
+ this.upsertDataSource(dataSource2);
233
+ if (collections) {
234
+ (_a = this.getDataSource(dataSource2.key)) == null ? void 0 : _a.setCollections(collections, { clearFields: true });
235
+ }
236
+ });
237
+ return;
238
+ }
239
+ const dataSource = this.getDataSource(key);
240
+ if (!dataSource) {
241
+ return;
242
+ }
243
+ dataSource.setCollections((result == null ? void 0 : result.collections) || [], { clearFields: true });
244
+ }
245
+ async loadKey(key, options) {
246
+ const loader = this.loaders.get(key);
247
+ if (!loader) {
248
+ return;
249
+ }
250
+ if (!this.getDataSource(key) && key !== "*") {
251
+ this.addDataSource({ key });
252
+ }
253
+ const { initial } = options;
254
+ this.loadingKeys.add(key);
255
+ if (key !== "*") {
256
+ this.setDataSourceState(key, {
257
+ status: initial ? "loading" : "reloading",
258
+ errorMessage: void 0
259
+ });
260
+ }
261
+ this.loadErrors.set(key, null);
262
+ try {
263
+ const result = await loader({ key, manager: this }) || {};
264
+ this.applyDataSourceLoadResult(key, result);
265
+ this.loadedKeys.add(key);
266
+ if (key !== "*") {
267
+ this.setDataSourceState(key, {
268
+ status: "loaded",
269
+ errorMessage: void 0
270
+ });
271
+ }
272
+ this.dispatchDataSourceEvent("dataSource:loaded", { dataSourceKey: key, initial });
273
+ } catch (error) {
274
+ const normalizedError = error instanceof Error ? error : new Error(String(error));
275
+ this.loadErrors.set(key, normalizedError);
276
+ if (key !== "*") {
277
+ this.setDataSourceState(key, {
278
+ status: initial ? "loading-failed" : "reloading-failed",
279
+ errorMessage: normalizedError.message
280
+ });
281
+ }
282
+ this.dispatchDataSourceEvent("dataSource:loadFailed", {
283
+ dataSourceKey: key,
284
+ initial,
285
+ error: normalizedError
286
+ });
287
+ throw normalizedError;
288
+ } finally {
289
+ this.loadingKeys.delete(key);
290
+ }
291
+ }
106
292
  };
107
293
  __name(_DataSourceManager, "DataSourceManager");
108
294
  let DataSourceManager = _DataSourceManager;
295
+ function getCollectionFieldInterface(interfaceName, ...dataSourceManagers) {
296
+ if (!interfaceName) {
297
+ return void 0;
298
+ }
299
+ for (const dataSourceManager of dataSourceManagers) {
300
+ const collectionFieldInterfaceManager = dataSourceManager == null ? void 0 : dataSourceManager.collectionFieldInterfaceManager;
301
+ const getFieldInterface = collectionFieldInterfaceManager == null ? void 0 : collectionFieldInterfaceManager.getFieldInterface;
302
+ if (typeof getFieldInterface === "function") {
303
+ return getFieldInterface.call(collectionFieldInterfaceManager, interfaceName);
304
+ }
305
+ }
306
+ return void 0;
307
+ }
308
+ __name(getCollectionFieldInterface, "getCollectionFieldInterface");
109
309
  const _DataSource = class _DataSource {
110
310
  dataSourceManager;
111
311
  collectionManager;
@@ -126,6 +326,12 @@ const _DataSource = class _DataSource {
126
326
  get name() {
127
327
  return this.options.key;
128
328
  }
329
+ get status() {
330
+ return this.options.status;
331
+ }
332
+ get errorMessage() {
333
+ return this.options.errorMessage;
334
+ }
129
335
  setDataSourceManager(dataSourceManager) {
130
336
  this.dataSourceManager = dataSourceManager;
131
337
  }
@@ -156,6 +362,9 @@ const _DataSource = class _DataSource {
156
362
  upsertCollections(collections, options = {}) {
157
363
  return this.collectionManager.upsertCollections(collections, options);
158
364
  }
365
+ setCollections(collections, options = {}) {
366
+ return this.collectionManager.setCollections(collections, options);
367
+ }
159
368
  removeCollection(name) {
160
369
  return this.collectionManager.removeCollection(name);
161
370
  }
@@ -166,6 +375,12 @@ const _DataSource = class _DataSource {
166
375
  Object.keys(this.options).forEach((key) => delete this.options[key]);
167
376
  Object.assign(this.options, newOptions);
168
377
  }
378
+ patchOptions(newOptions = {}) {
379
+ Object.assign(this.options, newOptions);
380
+ }
381
+ reload() {
382
+ return this.dataSourceManager.reloadDataSource(this.key);
383
+ }
169
384
  getCollectionField(fieldPath) {
170
385
  const [collectionName, ...otherKeys] = fieldPath.split(".");
171
386
  const fieldName = otherKeys.join(".");
@@ -190,6 +405,10 @@ const _CollectionManager = class _CollectionManager {
190
405
  collections;
191
406
  allCollectionsInheritChain;
192
407
  childrenCollectionsName = {};
408
+ resetCaches() {
409
+ this.childrenCollectionsName = {};
410
+ this.allCollectionsInheritChain = void 0;
411
+ }
193
412
  get flowEngine() {
194
413
  return this.dataSource.flowEngine;
195
414
  }
@@ -203,9 +422,11 @@ const _CollectionManager = class _CollectionManager {
203
422
  col.setDataSource(this.dataSource);
204
423
  col.initInherits();
205
424
  this.collections.set(col.name, col);
425
+ this.resetCaches();
206
426
  }
207
427
  removeCollection(name) {
208
428
  this.collections.delete(name);
429
+ this.resetCaches();
209
430
  }
210
431
  updateCollection(newOptions, options = {}) {
211
432
  const collection = this.getCollection(newOptions.name);
@@ -213,6 +434,7 @@ const _CollectionManager = class _CollectionManager {
213
434
  throw new Error(`Collection ${newOptions.name} not found`);
214
435
  }
215
436
  collection.setOptions(newOptions, options);
437
+ this.resetCaches();
216
438
  }
217
439
  upsertCollection(options) {
218
440
  if (this.collections.has(options.name)) {
@@ -230,6 +452,11 @@ const _CollectionManager = class _CollectionManager {
230
452
  this.addCollection(collection);
231
453
  }
232
454
  }
455
+ this.resetCaches();
456
+ }
457
+ setCollections(collections, options = {}) {
458
+ this.clearCollections();
459
+ this.upsertCollections(collections, options);
233
460
  }
234
461
  sortCollectionsByInherits(collections) {
235
462
  const map = /* @__PURE__ */ new Map();
@@ -293,6 +520,7 @@ const _CollectionManager = class _CollectionManager {
293
520
  }
294
521
  clearCollections() {
295
522
  this.collections.clear();
523
+ this.resetCaches();
296
524
  }
297
525
  getAssociation(associationName) {
298
526
  const [collectionName, fieldName] = associationName.split(".");
@@ -461,6 +689,12 @@ const _Collection = class _Collection {
461
689
  }
462
690
  get titleCollectionField() {
463
691
  const titleFieldName = this.options.titleField || this.filterTargetKey;
692
+ if (Array.isArray(titleFieldName)) {
693
+ if (titleFieldName.length !== 1) {
694
+ return void 0;
695
+ }
696
+ return this.getField(titleFieldName[0]);
697
+ }
464
698
  const titleCollectionField = this.getField(titleFieldName);
465
699
  return titleCollectionField;
466
700
  }
@@ -487,6 +721,9 @@ const _Collection = class _Collection {
487
721
  }
488
722
  this.upsertFields(this.options.fields || []);
489
723
  }
724
+ setOption(key, value) {
725
+ this.options[key] = value;
726
+ }
490
727
  getFields() {
491
728
  const fieldMap = /* @__PURE__ */ new Map();
492
729
  for (const inherit of this.inherits.values()) {
@@ -753,7 +990,7 @@ const _CollectionField = class _CollectionField {
753
990
  {
754
991
  ...import_lodash.default.omit(((_a = this.options.uiSchema) == null ? void 0 : _a["x-component-props"]) || {}, "fieldNames"),
755
992
  options: this.enum.length ? this.enum : void 0,
756
- mode: this.type === "array" ? "multiple" : void 0,
993
+ mode: this.interface === "multipleSelect" ? "multiple" : void 0,
757
994
  multiple: target ? ["belongsToMany", "hasMany", "belongsToArray"].includes(type) : void 0,
758
995
  maxCount: target && !["belongsToMany", "hasMany", "belongsToArray"].includes(type) ? 1 : void 0,
759
996
  target,
@@ -772,7 +1009,17 @@ const _CollectionField = class _CollectionField {
772
1009
  abortEarly: false
773
1010
  });
774
1011
  if (error) {
775
- const message = error.details.map((d) => d.message.replace(/"value"/g, `"${label}"`)).join(", ");
1012
+ const message = error.details.map((d) => {
1013
+ const translated = this.flowEngine.translate(d.type, {
1014
+ ...d.context,
1015
+ ns: "data-source-main",
1016
+ label
1017
+ });
1018
+ if (translated && translated !== d.type) {
1019
+ return translated;
1020
+ }
1021
+ return d.message.replace(/"value"/g, `"${label}"`);
1022
+ }).join(", ");
776
1023
  return Promise.reject(message);
777
1024
  }
778
1025
  return Promise.resolve();
@@ -792,8 +1039,14 @@ const _CollectionField = class _CollectionField {
792
1039
  return this.targetCollection.getFields();
793
1040
  }
794
1041
  getInterfaceOptions() {
795
- const app = this.flowEngine.context.app;
796
- return app.dataSourceManager.collectionFieldInterfaceManager.getFieldInterface(this.interface);
1042
+ var _a, _b, _c;
1043
+ const ctx = this.flowEngine.context;
1044
+ return getCollectionFieldInterface(
1045
+ this.interface,
1046
+ (_b = (_a = this.collection) == null ? void 0 : _a.dataSource) == null ? void 0 : _b.dataSourceManager,
1047
+ ctx.dataSourceManager,
1048
+ (_c = ctx.app) == null ? void 0 : _c.dataSourceManager
1049
+ );
797
1050
  }
798
1051
  getFilterOperators() {
799
1052
  var _a;
@@ -858,6 +1111,7 @@ __name(isFieldInterfaceMatch, "isFieldInterfaceMatch");
858
1111
  CollectionManager,
859
1112
  DataSource,
860
1113
  DataSourceManager,
1114
+ getCollectionFieldInterface,
861
1115
  isFieldInterfaceMatch,
862
1116
  jioToJoiSchema
863
1117
  });
@@ -153,7 +153,7 @@ const _FlowExecutor = class _FlowExecutor {
153
153
  const stepDefaultParams = await (0, import_utils.resolveDefaultParams)(step.defaultParams, runtimeCtx);
154
154
  combinedParams = { ...stepDefaultParams };
155
155
  } else {
156
- flowContext.logger.error(
156
+ flowContext.logger.warn(
157
157
  `BaseModel.applyFlow: Step '${stepKey}' in flow '${flowKey}' has neither 'use' nor 'handler'. Skipping.`
158
158
  );
159
159
  continue;
@@ -213,11 +213,13 @@ const _FlowExecutor = class _FlowExecutor {
213
213
  flowContext.logger.info(`[FlowEngine] ${error.message}`);
214
214
  await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:end`, {
215
215
  ...flowEventBasePayload,
216
- stepKey
216
+ stepKey,
217
+ aborted: true
217
218
  });
218
219
  await this.emitModelEventIf(eventName, `flow:${flowKey}:end`, {
219
220
  ...flowEventBasePayload,
220
- result: error
221
+ result: error,
222
+ aborted: true
221
223
  });
222
224
  return Promise.resolve(error);
223
225
  }
@@ -287,6 +289,7 @@ const _FlowExecutor = class _FlowExecutor {
287
289
  }) : flows;
288
290
  const scheduledCancels = [];
289
291
  const execute = /* @__PURE__ */ __name(async () => {
292
+ let abortedByExitAll = false;
290
293
  if (sequential) {
291
294
  const flowsWithIndex = flowsToRun.map((f, i) => ({ f, i }));
292
295
  const ordered = flowsWithIndex.slice().sort((a, b) => {
@@ -355,9 +358,10 @@ const _FlowExecutor = class _FlowExecutor {
355
358
  return;
356
359
  }
357
360
  if (!whenKey) return;
361
+ const shouldSkipOnAborted = whenKey === `event:${eventName}:end` || phase === "afterFlow" || phase === "afterStep";
358
362
  scheduled.add(flow.key);
359
363
  const list = scheduleGroups.get(whenKey) || [];
360
- list.push({ flow, order: indexInOrdered });
364
+ list.push({ flow, order: indexInOrdered, shouldSkipOnAborted });
361
365
  scheduleGroups.set(whenKey, list);
362
366
  });
363
367
  for (const [whenKey, list] of scheduleGroups.entries()) {
@@ -368,6 +372,12 @@ const _FlowExecutor = class _FlowExecutor {
368
372
  return a.order - b.order;
369
373
  });
370
374
  for (const it of sorted) {
375
+ const when = it.shouldSkipOnAborted ? Object.assign(
376
+ (event) => event.type === whenKey && event.aborted !== true,
377
+ {
378
+ __eventType: whenKey
379
+ }
380
+ ) : whenKey;
371
381
  const cancel = model.scheduleModelOperation(
372
382
  model.uid,
373
383
  async (m) => {
@@ -377,7 +387,7 @@ const _FlowExecutor = class _FlowExecutor {
377
387
  }
378
388
  results2.push(res);
379
389
  },
380
- { when: whenKey }
390
+ { when }
381
391
  );
382
392
  scheduledCancels.push(cancel);
383
393
  }
@@ -391,12 +401,14 @@ const _FlowExecutor = class _FlowExecutor {
391
401
  const result = await this.runFlow(model, flow.key, inputArgs, runId, eventName);
392
402
  if (result instanceof import_exceptions.FlowExitAllException) {
393
403
  logger.debug(`[FlowEngine.dispatchEvent] ${result.message}`);
404
+ abortedByExitAll = true;
394
405
  break;
395
406
  }
396
407
  results2.push(result);
397
408
  } catch (error) {
398
409
  if (error instanceof import_exceptions.FlowExitAllException) {
399
410
  logger.debug(`[FlowEngine.dispatchEvent] ${error.message}`);
411
+ abortedByExitAll = true;
400
412
  break;
401
413
  }
402
414
  logger.error(
@@ -406,7 +418,7 @@ const _FlowExecutor = class _FlowExecutor {
406
418
  throw error;
407
419
  }
408
420
  }
409
- return results2;
421
+ return { result: results2, abortedByExitAll };
410
422
  }
411
423
  const results = await Promise.all(
412
424
  flowsToRun.map(async (flow) => {
@@ -423,7 +435,11 @@ const _FlowExecutor = class _FlowExecutor {
423
435
  }
424
436
  })
425
437
  );
426
- return results.filter((x) => x !== void 0);
438
+ const filteredResults = results.filter((x) => x !== void 0);
439
+ if (filteredResults.some((x) => x instanceof import_exceptions.FlowExitAllException)) {
440
+ abortedByExitAll = true;
441
+ }
442
+ return { result: filteredResults, abortedByExitAll };
427
443
  }, "execute");
428
444
  const argsKey = useCache ? JSON.stringify(inputArgs ?? {}) : "";
429
445
  const cacheKey = useCache ? import_flowEngine.FlowEngine.generateApplyFlowCacheKey(
@@ -432,7 +448,7 @@ const _FlowExecutor = class _FlowExecutor {
432
448
  model.uid
433
449
  ) : null;
434
450
  try {
435
- const result = await this.withApplyFlowCache(cacheKey, execute);
451
+ const { result, abortedByExitAll } = await this.withApplyFlowCache(cacheKey, execute);
436
452
  try {
437
453
  await ((_c = model.onDispatchEventEnd) == null ? void 0 : _c.call(model, eventName, options, inputArgs, result));
438
454
  } catch (hookErr) {
@@ -440,8 +456,15 @@ const _FlowExecutor = class _FlowExecutor {
440
456
  }
441
457
  await this.emitModelEventIf(eventName, "end", {
442
458
  ...eventBasePayload,
443
- result
459
+ result,
460
+ ...abortedByExitAll ? { aborted: true } : {}
444
461
  });
462
+ if (result && typeof result === "object") {
463
+ Object.defineProperty(result, "__abortedByExitAll", {
464
+ value: abortedByExitAll,
465
+ configurable: true
466
+ });
467
+ }
445
468
  return result;
446
469
  } catch (error) {
447
470
  try {
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { FlowDefinition } from '../FlowDefinition';
10
+ import { FlowDefinitionOptions } from '../types';
11
+ import { BaseFlowRegistry, IFlowRepository } from './BaseFlowRegistry';
12
+ export type FlowRegistryData = Record<string, Omit<FlowDefinitionOptions, 'key'> & {
13
+ key?: string;
14
+ }>;
15
+ export declare class DetachedFlowRegistry extends BaseFlowRegistry {
16
+ constructor(flows?: FlowRegistryData);
17
+ saveFlow(_flow: FlowDefinition): void;
18
+ destroyFlow(flowKey: string): void;
19
+ }
20
+ export declare function serializeFlowRegistry(registry: Pick<IFlowRepository, 'getFlows'>): FlowRegistryData;
21
+ export declare function replaceFlowRegistry(registry: Pick<IFlowRepository, 'getFlows' | 'removeFlow' | 'addFlows'>, flows: FlowRegistryData): void;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var DetachedFlowRegistry_exports = {};
39
+ __export(DetachedFlowRegistry_exports, {
40
+ DetachedFlowRegistry: () => DetachedFlowRegistry,
41
+ replaceFlowRegistry: () => replaceFlowRegistry,
42
+ serializeFlowRegistry: () => serializeFlowRegistry
43
+ });
44
+ module.exports = __toCommonJS(DetachedFlowRegistry_exports);
45
+ var import_lodash = __toESM(require("lodash"));
46
+ var import_BaseFlowRegistry = require("./BaseFlowRegistry");
47
+ const _DetachedFlowRegistry = class _DetachedFlowRegistry extends import_BaseFlowRegistry.BaseFlowRegistry {
48
+ constructor(flows = {}) {
49
+ super();
50
+ this.addFlows(import_lodash.default.cloneDeep(flows));
51
+ }
52
+ saveFlow(_flow) {
53
+ }
54
+ destroyFlow(flowKey) {
55
+ this.removeFlow(flowKey);
56
+ }
57
+ };
58
+ __name(_DetachedFlowRegistry, "DetachedFlowRegistry");
59
+ let DetachedFlowRegistry = _DetachedFlowRegistry;
60
+ function serializeFlowRegistry(registry) {
61
+ const flows = {};
62
+ for (const [key, flow] of registry.getFlows()) {
63
+ flows[key] = import_lodash.default.cloneDeep(flow.toData());
64
+ }
65
+ return flows;
66
+ }
67
+ __name(serializeFlowRegistry, "serializeFlowRegistry");
68
+ function replaceFlowRegistry(registry, flows) {
69
+ for (const key of Array.from(registry.getFlows().keys())) {
70
+ registry.removeFlow(key);
71
+ }
72
+ registry.addFlows(import_lodash.default.cloneDeep(flows));
73
+ }
74
+ __name(replaceFlowRegistry, "replaceFlowRegistry");
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ DetachedFlowRegistry,
78
+ replaceFlowRegistry,
79
+ serializeFlowRegistry
80
+ });
@@ -9,3 +9,4 @@
9
9
  export * from './BaseFlowRegistry';
10
10
  export * from './InstanceFlowRegistry';
11
11
  export * from './GlobalFlowRegistry';
12
+ export * from './DetachedFlowRegistry';
@@ -26,9 +26,11 @@ module.exports = __toCommonJS(flow_registry_exports);
26
26
  __reExport(flow_registry_exports, require("./BaseFlowRegistry"), module.exports);
27
27
  __reExport(flow_registry_exports, require("./InstanceFlowRegistry"), module.exports);
28
28
  __reExport(flow_registry_exports, require("./GlobalFlowRegistry"), module.exports);
29
+ __reExport(flow_registry_exports, require("./DetachedFlowRegistry"), module.exports);
29
30
  // Annotate the CommonJS export names for ESM import in node:
30
31
  0 && (module.exports = {
31
32
  ...require("./BaseFlowRegistry"),
32
33
  ...require("./InstanceFlowRegistry"),
33
- ...require("./GlobalFlowRegistry")
34
+ ...require("./GlobalFlowRegistry"),
35
+ ...require("./DetachedFlowRegistry")
34
36
  });
@@ -325,8 +325,10 @@ export declare class FlowContext {
325
325
  getPropertyOptions(key: string): PropertyOptions | undefined;
326
326
  }
327
327
  declare class BaseFlowEngineContext extends FlowContext {
328
+ t: (key: any, options?: any) => string;
328
329
  router: Router;
329
330
  dataSourceManager: DataSourceManager;
331
+ isDarkTheme: boolean;
330
332
  requireAsync: (url: string) => Promise<any>;
331
333
  importAsync: (url: string) => Promise<any>;
332
334
  createJSRunner: (options?: JSRunnerOptions) => Promise<JSRunner>;
@@ -347,6 +349,7 @@ declare class BaseFlowEngineContext extends FlowContext {
347
349
  runAction: (actionName: string, params?: Record<string, any>) => Promise<any> | any;
348
350
  engine: FlowEngine;
349
351
  api: APIClient;
352
+ locale: string;
350
353
  viewer: FlowViewer;
351
354
  view: FlowView;
352
355
  modal: HookAPI;