@nocobase/flow-engine 2.1.0-beta.8 → 2.1.0

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 (215) hide show
  1. package/lib/FlowContextProvider.d.ts +5 -1
  2. package/lib/FlowContextProvider.js +9 -2
  3. package/lib/components/FieldModelRenderer.js +2 -2
  4. package/lib/components/FlowModelRenderer.d.ts +3 -1
  5. package/lib/components/FlowModelRenderer.js +12 -6
  6. package/lib/components/FormItem.d.ts +6 -0
  7. package/lib/components/FormItem.js +11 -3
  8. package/lib/components/MobilePopup.js +6 -5
  9. package/lib/components/dnd/gridDragPlanner.d.ts +59 -2
  10. package/lib/components/dnd/gridDragPlanner.js +607 -19
  11. package/lib/components/dnd/index.d.ts +31 -2
  12. package/lib/components/dnd/index.js +244 -23
  13. package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +2 -1
  14. package/lib/components/settings/wrappers/component/SelectWithTitle.js +14 -12
  15. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
  16. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +152 -42
  17. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +23 -43
  18. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +352 -295
  19. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.d.ts +36 -0
  20. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +274 -0
  21. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
  22. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +315 -0
  23. package/lib/components/subModel/AddSubModelButton.js +12 -1
  24. package/lib/components/subModel/LazyDropdown.js +301 -52
  25. package/lib/components/subModel/index.d.ts +1 -0
  26. package/lib/components/subModel/index.js +19 -0
  27. package/lib/components/subModel/utils.d.ts +2 -1
  28. package/lib/components/subModel/utils.js +15 -5
  29. package/lib/components/variables/VariableHybridInput.d.ts +27 -0
  30. package/lib/components/variables/VariableHybridInput.js +499 -0
  31. package/lib/components/variables/index.d.ts +2 -0
  32. package/lib/components/variables/index.js +3 -0
  33. package/lib/data-source/index.d.ts +84 -0
  34. package/lib/data-source/index.js +269 -7
  35. package/lib/executor/FlowExecutor.js +6 -3
  36. package/lib/flow-registry/DetachedFlowRegistry.d.ts +21 -0
  37. package/lib/flow-registry/DetachedFlowRegistry.js +80 -0
  38. package/lib/flow-registry/index.d.ts +1 -0
  39. package/lib/flow-registry/index.js +3 -1
  40. package/lib/flowContext.d.ts +9 -1
  41. package/lib/flowContext.js +77 -6
  42. package/lib/flowEngine.d.ts +136 -4
  43. package/lib/flowEngine.js +429 -51
  44. package/lib/flowI18n.js +2 -1
  45. package/lib/flowSettings.d.ts +14 -6
  46. package/lib/flowSettings.js +34 -6
  47. package/lib/index.d.ts +2 -0
  48. package/lib/index.js +7 -0
  49. package/lib/lazy-helper.d.ts +14 -0
  50. package/lib/lazy-helper.js +71 -0
  51. package/lib/locale/en-US.json +1 -0
  52. package/lib/locale/index.d.ts +2 -0
  53. package/lib/locale/zh-CN.json +1 -0
  54. package/lib/models/DisplayItemModel.d.ts +1 -1
  55. package/lib/models/EditableItemModel.d.ts +1 -1
  56. package/lib/models/FilterableItemModel.d.ts +1 -1
  57. package/lib/models/flowModel.d.ts +13 -10
  58. package/lib/models/flowModel.js +126 -34
  59. package/lib/provider.js +38 -23
  60. package/lib/reactive/observer.js +46 -16
  61. package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +4 -3
  62. package/lib/runjs-context/contexts/JSBlockRunJSContext.js +4 -15
  63. package/lib/runjs-context/contexts/JSColumnRunJSContext.js +5 -2
  64. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +5 -8
  65. package/lib/runjs-context/contexts/JSFieldRunJSContext.js +4 -3
  66. package/lib/runjs-context/contexts/JSItemRunJSContext.js +4 -3
  67. package/lib/runjs-context/contexts/base.js +464 -29
  68. package/lib/runjs-context/contexts/elementDoc.d.ts +11 -0
  69. package/lib/runjs-context/contexts/elementDoc.js +152 -0
  70. package/lib/runjs-context/setup.js +1 -0
  71. package/lib/runjs-context/snippets/index.js +13 -2
  72. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts +11 -0
  73. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.js +50 -0
  74. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts +11 -0
  75. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
  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/loadedPageCache.d.ts +24 -0
  82. package/lib/utils/loadedPageCache.js +139 -0
  83. package/lib/utils/parsePathnameToViewParams.d.ts +5 -1
  84. package/lib/utils/parsePathnameToViewParams.js +28 -4
  85. package/lib/utils/randomId.d.ts +39 -0
  86. package/lib/utils/randomId.js +45 -0
  87. package/lib/utils/runjsTemplateCompat.js +1 -1
  88. package/lib/utils/runjsValue.js +41 -11
  89. package/lib/utils/schema-utils.d.ts +7 -1
  90. package/lib/utils/schema-utils.js +19 -0
  91. package/lib/views/FlowView.d.ts +7 -1
  92. package/lib/views/FlowView.js +11 -1
  93. package/lib/views/PageComponent.js +8 -6
  94. package/lib/views/ViewNavigation.d.ts +12 -2
  95. package/lib/views/ViewNavigation.js +28 -9
  96. package/lib/views/createViewMeta.js +114 -50
  97. package/lib/views/inheritLayoutContext.d.ts +10 -0
  98. package/lib/views/inheritLayoutContext.js +50 -0
  99. package/lib/views/runViewBeforeClose.d.ts +10 -0
  100. package/lib/views/runViewBeforeClose.js +45 -0
  101. package/lib/views/useDialog.d.ts +2 -1
  102. package/lib/views/useDialog.js +12 -3
  103. package/lib/views/useDrawer.d.ts +2 -1
  104. package/lib/views/useDrawer.js +12 -3
  105. package/lib/views/usePage.d.ts +5 -11
  106. package/lib/views/usePage.js +304 -144
  107. package/package.json +5 -4
  108. package/src/FlowContextProvider.tsx +9 -1
  109. package/src/__tests__/createViewMeta.popup.test.ts +115 -1
  110. package/src/__tests__/flow-engine.test.ts +166 -0
  111. package/src/__tests__/flowContext.test.ts +105 -1
  112. package/src/__tests__/flowEngine.modelLoaders.test.ts +245 -0
  113. package/src/__tests__/flowEngine.moveModel.test.ts +81 -1
  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 +21 -0
  120. package/src/__tests__/runjsContextImplementations.test.ts +9 -2
  121. package/src/__tests__/runjsContextRuntime.test.ts +2 -0
  122. package/src/__tests__/runjsLocales.test.ts +6 -5
  123. package/src/__tests__/runjsSnippets.test.ts +21 -0
  124. package/src/__tests__/viewScopedFlowEngine.test.ts +136 -3
  125. package/src/components/FieldModelRenderer.tsx +2 -1
  126. package/src/components/FlowModelRenderer.tsx +18 -6
  127. package/src/components/FormItem.tsx +7 -1
  128. package/src/components/MobilePopup.tsx +4 -2
  129. package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
  130. package/src/components/__tests__/FormItem.test.tsx +25 -0
  131. package/src/components/__tests__/dnd.test.ts +44 -0
  132. package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +20 -10
  133. package/src/components/__tests__/gridDragPlanner.test.ts +472 -5
  134. package/src/components/dnd/__tests__/DndProvider.test.tsx +98 -0
  135. package/src/components/dnd/gridDragPlanner.ts +750 -17
  136. package/src/components/dnd/index.tsx +305 -28
  137. package/src/components/settings/wrappers/component/SelectWithTitle.tsx +21 -9
  138. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +178 -48
  139. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +487 -440
  140. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +344 -8
  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 +16 -2
  145. package/src/components/subModel/LazyDropdown.tsx +341 -56
  146. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +524 -38
  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 +13 -2
  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 +69 -2
  154. package/src/data-source/index.ts +332 -8
  155. package/src/executor/FlowExecutor.ts +6 -3
  156. package/src/executor/__tests__/flowExecutor.test.ts +57 -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 +85 -6
  161. package/src/flowEngine.ts +484 -45
  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__/flowEngine.resolveUse.test.ts +0 -15
  172. package/src/models/__tests__/flowModel.test.ts +65 -37
  173. package/src/models/flowModel.tsx +184 -65
  174. package/src/provider.tsx +41 -25
  175. package/src/reactive/__tests__/observer.test.tsx +82 -0
  176. package/src/reactive/observer.tsx +87 -25
  177. package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +4 -3
  178. package/src/runjs-context/contexts/JSBlockRunJSContext.ts +4 -15
  179. package/src/runjs-context/contexts/JSColumnRunJSContext.ts +4 -2
  180. package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +5 -9
  181. package/src/runjs-context/contexts/JSFieldRunJSContext.ts +4 -3
  182. package/src/runjs-context/contexts/JSItemRunJSContext.ts +4 -3
  183. package/src/runjs-context/contexts/base.ts +467 -31
  184. package/src/runjs-context/contexts/elementDoc.ts +130 -0
  185. package/src/runjs-context/setup.ts +1 -0
  186. package/src/runjs-context/snippets/index.ts +12 -1
  187. package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
  188. package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
  189. package/src/types.ts +62 -0
  190. package/src/utils/__tests__/createCollectionContextMeta.test.ts +48 -0
  191. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +21 -0
  192. package/src/utils/__tests__/runjsValue.test.ts +11 -0
  193. package/src/utils/__tests__/utils.test.ts +62 -0
  194. package/src/utils/createCollectionContextMeta.ts +6 -2
  195. package/src/utils/index.ts +5 -1
  196. package/src/utils/loadedPageCache.ts +147 -0
  197. package/src/utils/parsePathnameToViewParams.ts +45 -5
  198. package/src/utils/randomId.ts +48 -0
  199. package/src/utils/runjsTemplateCompat.ts +1 -1
  200. package/src/utils/runjsValue.ts +50 -11
  201. package/src/utils/schema-utils.ts +30 -1
  202. package/src/views/FlowView.tsx +22 -2
  203. package/src/views/PageComponent.tsx +7 -4
  204. package/src/views/ViewNavigation.ts +46 -9
  205. package/src/views/__tests__/FlowView.usePage.test.tsx +243 -3
  206. package/src/views/__tests__/ViewNavigation.test.ts +52 -0
  207. package/src/views/__tests__/inheritLayoutContext.test.ts +53 -0
  208. package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
  209. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +12 -12
  210. package/src/views/createViewMeta.ts +106 -34
  211. package/src/views/inheritLayoutContext.ts +26 -0
  212. package/src/views/runViewBeforeClose.ts +19 -0
  213. package/src/views/useDialog.tsx +13 -3
  214. package/src/views/useDrawer.tsx +13 -3
  215. package/src/views/usePage.tsx +367 -180
@@ -57,6 +57,7 @@ __export(flowContext_exports, {
57
57
  });
58
58
  module.exports = __toCommonJS(flowContext_exports);
59
59
  var import_reactive = require("@formily/reactive");
60
+ var import_axios = __toESM(require("axios"));
60
61
  var antd = __toESM(require("antd"));
61
62
  var import_lodash = __toESM(require("lodash"));
62
63
  var import_qs = __toESM(require("qs"));
@@ -81,6 +82,28 @@ var import_dayjs = __toESM(require("dayjs"));
81
82
  var import_runjsLibs = require("./runjsLibs");
82
83
  var import_runjsModuleLoader = require("./utils/runjsModuleLoader");
83
84
  var _proxy, _FlowContext_instances, createChildNodes_fn, findMetaByPath_fn, findMetaInDelegatesDeep_fn, findMetaInProperty_fn, resolvePathInMeta_fn, resolvePathInMetaAsync_fn, buildParentTitles_fn, toTreeNode_fn;
85
+ function normalizePathname(pathname) {
86
+ return pathname.endsWith("/") ? pathname : `${pathname}/`;
87
+ }
88
+ __name(normalizePathname, "normalizePathname");
89
+ function shouldBypassApiClient(url, app) {
90
+ try {
91
+ const requestUrl = new URL(url);
92
+ if (!["http:", "https:"].includes(requestUrl.protocol)) {
93
+ return false;
94
+ }
95
+ if (!(app == null ? void 0 : app.getApiUrl)) {
96
+ return true;
97
+ }
98
+ const apiUrl = new URL(app.getApiUrl());
99
+ const apiPath = normalizePathname(apiUrl.pathname);
100
+ const requestPath = normalizePathname(requestUrl.pathname);
101
+ return requestUrl.origin !== apiUrl.origin || !requestPath.startsWith(apiPath);
102
+ } catch {
103
+ return false;
104
+ }
105
+ }
106
+ __name(shouldBypassApiClient, "shouldBypassApiClient");
84
107
  function isRecordRefLike(val) {
85
108
  return !!(val && typeof val === "object" && "collection" in val && "filterByTk" in val);
86
109
  }
@@ -376,10 +399,11 @@ const _FlowContext = class _FlowContext {
376
399
  * - 输出仅来自 RunJS doc 与 defineProperty/defineMethod 的 info
377
400
  * - 不读取/展开 PropertyMeta(变量结构)
378
401
  * - 不自动展开深层 properties
379
- * - 不返回自动补全字段(例如 completion
402
+ * - 默认不返回自动补全字段(例如 completion),传入 includeCompletion=true 时返回
380
403
  */
381
404
  async getApiInfos(options = {}) {
382
405
  const version = options.version || "v1";
406
+ const includeCompletion = !!options.includeCompletion;
383
407
  const evalCtx = this.createProxy();
384
408
  const isPrivateKey = /* @__PURE__ */ __name((key) => typeof key === "string" && key.startsWith("_"), "isPrivateKey");
385
409
  const isVarRootKey = /* @__PURE__ */ __name((key) => key === "record" || key === "formValues" || key === "popup", "isVarRootKey");
@@ -416,7 +440,14 @@ const _FlowContext = class _FlowContext {
416
440
  const src = toDocObject(obj);
417
441
  if (!src) return {};
418
442
  const out2 = {};
419
- for (const k of ["description", "examples", "ref", "params", "returns"]) {
443
+ for (const k of [
444
+ "description",
445
+ "examples",
446
+ ...includeCompletion ? ["completion"] : [],
447
+ "ref",
448
+ "params",
449
+ "returns"
450
+ ]) {
420
451
  const v = src[k];
421
452
  if (typeof v !== "undefined") out2[k] = v;
422
453
  }
@@ -429,7 +460,17 @@ const _FlowContext = class _FlowContext {
429
460
  const src = toDocObject(obj);
430
461
  if (!src) return {};
431
462
  const out2 = {};
432
- for (const k of ["title", "type", "interface", "description", "examples", "ref", "params", "returns"]) {
463
+ for (const k of [
464
+ "title",
465
+ "type",
466
+ "interface",
467
+ "description",
468
+ "examples",
469
+ ...includeCompletion ? ["completion"] : [],
470
+ "ref",
471
+ "params",
472
+ "returns"
473
+ ]) {
433
474
  const v = src[k];
434
475
  if (typeof v !== "undefined") out2[k] = v;
435
476
  }
@@ -516,7 +557,7 @@ const _FlowContext = class _FlowContext {
516
557
  node = { ...node, ...pickPropertyInfo(docObj) };
517
558
  node = { ...node, ...pickPropertyInfo(infoObj) };
518
559
  delete node.properties;
519
- delete node.completion;
560
+ if (!includeCompletion) delete node.completion;
520
561
  if (!Object.keys(node).length) continue;
521
562
  const outKey = mapDocKeyToApiKey(key, docNode);
522
563
  out[outKey] = out[outKey] ? { ...out[outKey] || {}, ...node || {} } : node;
@@ -531,7 +572,7 @@ const _FlowContext = class _FlowContext {
531
572
  node = { ...node, ...pickMethodInfo(docObj) };
532
573
  node = { ...node, ...pickMethodInfo(info) };
533
574
  delete node.properties;
534
- delete node.completion;
575
+ if (!includeCompletion) delete node.completion;
535
576
  if (!Object.keys(node).length) continue;
536
577
  node.type = "function";
537
578
  if (!out[key]) out[key] = node;
@@ -548,7 +589,7 @@ const _FlowContext = class _FlowContext {
548
589
  let node = {};
549
590
  node = { ...node, ...pickPropertyInfo(childObj) };
550
591
  delete node.properties;
551
- delete node.completion;
592
+ if (!includeCompletion) delete node.completion;
552
593
  if (!node.description || !String(node.description).trim()) continue;
553
594
  out[outKey] = node;
554
595
  }
@@ -2211,6 +2252,10 @@ const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext
2211
2252
  return this.engine.getModel(modelName, searchInPreviousEngines);
2212
2253
  });
2213
2254
  this.defineMethod("request", (options) => {
2255
+ const app = this.app;
2256
+ if (typeof (options == null ? void 0 : options.url) === "string" && shouldBypassApiClient(options.url, app)) {
2257
+ return import_axios.default.request(options);
2258
+ }
2214
2259
  return this.api.request(options);
2215
2260
  });
2216
2261
  this.defineMethod(
@@ -2228,6 +2273,17 @@ const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext
2228
2273
  });
2229
2274
  const jsCode = await (0, import_utils.prepareRunJsCode)(String(code ?? ""), { preprocessTemplates: shouldPreprocessTemplates });
2230
2275
  return runner.run(jsCode);
2276
+ },
2277
+ {
2278
+ description: "Execute a RunJS code string in the current Flow context.",
2279
+ detail: "(code: string, variables?: Record<string, any>, options?: JSRunnerOptions) => Promise<RunJSResult>",
2280
+ params: [
2281
+ { name: "code", type: "string", description: "RunJS code to execute." },
2282
+ { name: "variables", type: "Record<string, any>", optional: true, description: "Additional globals." },
2283
+ { name: "options", type: "JSRunnerOptions", optional: true, description: "Runner options." }
2284
+ ],
2285
+ returns: { type: "Promise<{ success: boolean; value?: any; error?: any; timeout?: boolean }>" },
2286
+ completion: { insertText: `await ctx.runjs('return 1')` }
2231
2287
  }
2232
2288
  );
2233
2289
  }
@@ -2280,6 +2336,18 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
2280
2336
  this.defineMethod("t", (keyOrTemplate, options) => {
2281
2337
  return i18n.translate(keyOrTemplate, options);
2282
2338
  });
2339
+ this.defineProperty("locale", {
2340
+ get: /* @__PURE__ */ __name(() => {
2341
+ var _a, _b, _c;
2342
+ return ((_b = (_a = this.api) == null ? void 0 : _a.auth) == null ? void 0 : _b.locale) || ((_c = this.i18n) == null ? void 0 : _c.language);
2343
+ }, "get"),
2344
+ cache: false,
2345
+ meta: Object.assign(() => ({ type: "string", title: this.t("Current language"), sort: 970 }), {
2346
+ title: (0, import_utils.escapeT)("Current language"),
2347
+ sort: 970,
2348
+ hasChildren: false
2349
+ })
2350
+ });
2283
2351
  this.defineMethod("renderJson", function(template) {
2284
2352
  return this.resolveJsonTemplate(template);
2285
2353
  });
@@ -2658,6 +2726,9 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
2658
2726
  }, "get")
2659
2727
  });
2660
2728
  this.defineMethod("aclCheck", function(params) {
2729
+ if (this.skipAclCheck) {
2730
+ return true;
2731
+ }
2661
2732
  return this.acl.aclCheck(params);
2662
2733
  });
2663
2734
  this.defineMethod("createResource", function(resourceType) {
@@ -8,7 +8,7 @@ import { FlowResource } from './resources';
8
8
  import { Emitter } from './emitter';
9
9
  import ModelOperationScheduler from './scheduler/ModelOperationScheduler';
10
10
  import type { ScheduleOptions, ScheduledCancel } from './scheduler/ModelOperationScheduler';
11
- import type { ActionDefinition, ApplyFlowCacheEntry, CreateModelOptions, EventDefinition, FlowModelOptions, IFlowModelRepository, ModelConstructor, PersistOptions, ResourceType } from './types';
11
+ import type { ActionDefinition, ApplyFlowCacheEntry, CreateModelOptions, EnsureBatchResult, EventDefinition, FlowModelLoaderInputMap, FlowModelOptions, IFlowModelRepository, ModelConstructor, PersistOptions, ResourceType } from './types';
12
12
  /**
13
13
  * FlowEngine is the core class of the flow engine, responsible for managing flow models, actions, model repository, and more.
14
14
  * It provides capabilities for registering, creating, finding, persisting, replacing, and moving models.
@@ -47,6 +47,28 @@ export declare class FlowEngine {
47
47
  * @private
48
48
  */
49
49
  private _modelClasses;
50
+ /**
51
+ * Registered model entries.
52
+ * Key is the model class name, value is the model loader entry.
53
+ * @private
54
+ */
55
+ private _modelLoaders;
56
+ /**
57
+ * In-flight model loading promises.
58
+ * Key is the model class name, value is the loading promise.
59
+ * @private
60
+ */
61
+ private _loadingModelPromises;
62
+ /**
63
+ * Whether model-loader preload has completed in this session.
64
+ * @private
65
+ */
66
+ private _modelLoadersPreloaded;
67
+ /**
68
+ * In-flight model-loader preload promise.
69
+ * @private
70
+ */
71
+ private _modelLoadersPreloadPromise?;
50
72
  /**
51
73
  * Created model instances.
52
74
  * Key is the model instance UID, value is the model instance object.
@@ -71,6 +93,7 @@ export declare class FlowEngine {
71
93
  * @private
72
94
  */
73
95
  private _savingModels;
96
+ private _loadedPageCache;
74
97
  /**
75
98
  * Flow engine context object.
76
99
  * @private
@@ -226,6 +249,10 @@ export declare class FlowEngine {
226
249
  * Get all registered global events.
227
250
  */
228
251
  getEvents<TModel extends FlowModel = FlowModel>(): Map<string, EventDefinition<TModel>>;
252
+ /**
253
+ * for proxy instance, the #registerModel can't be called.
254
+ */
255
+ private _registerModel;
229
256
  /**
230
257
  * Register multiple model classes.
231
258
  * @param {Record<string, ModelConstructor>} models Model class map, key is model name, value is model constructor
@@ -234,6 +261,102 @@ export declare class FlowEngine {
234
261
  * flowEngine.registerModels({ UserModel, OrderModel });
235
262
  */
236
263
  registerModels(models: Record<string, ModelConstructor | typeof FlowModel<any>>): void;
264
+ /**
265
+ * Register multiple model loader entries.
266
+ * The `extends` field declares parent class(es) for async subclass discovery via `getSubclassesOfAsync`.
267
+ * It accepts `string | ModelConstructor | (string | ModelConstructor)[]` and is normalized to `string[]` internally.
268
+ * @param {FlowModelLoaderInputMap} loaders Model loader input map
269
+ * @returns {void}
270
+ * @example
271
+ * flowEngine.registerModelLoaders({
272
+ * DemoModel: {
273
+ * extends: 'BaseModel',
274
+ * loader: () => import('./models/DemoModel'),
275
+ * },
276
+ * });
277
+ */
278
+ registerModelLoaders(loaders: FlowModelLoaderInputMap): void;
279
+ /**
280
+ * Get a registered model class (constructor) asynchronously.
281
+ * This will first ensure the model loader entry is resolved.
282
+ * @param {string} name Model class name
283
+ * @returns {Promise<ModelConstructor | undefined>} Model constructor, or undefined if not found
284
+ */
285
+ getModelClassAsync(name: string): Promise<ModelConstructor | undefined>;
286
+ /**
287
+ * Get all registered model classes asynchronously.
288
+ * This will first ensure all registered model loader entries are resolved.
289
+ * @returns {Promise<Map<string, ModelConstructor>>} Model class map
290
+ */
291
+ getModelClassesAsync(): Promise<Map<string, ModelConstructor>>;
292
+ /**
293
+ * Create and register a model instance asynchronously.
294
+ * This will first ensure all string-based model references in the model tree are resolved.
295
+ * @template T FlowModel subclass type, defaults to FlowModel.
296
+ * @param {CreateModelOptions} options Model creation options
297
+ * @returns {Promise<T>} Created model instance
298
+ */
299
+ createModelAsync<T extends FlowModel = FlowModel>(options: CreateModelOptions, extra?: {
300
+ delegateToParent?: boolean;
301
+ delegate?: FlowContext;
302
+ }): Promise<T>;
303
+ /**
304
+ * Normalize a loader result into a model constructor.
305
+ * @param {string} name Model class name
306
+ * @param {FlowModelLoaderResult} loaded Loader result
307
+ * @returns {ModelConstructor | null} Normalized model constructor
308
+ * @private
309
+ */
310
+ private normalizeModelLoaderResult;
311
+ /**
312
+ * Collect string-based model names from a model tree.
313
+ * @param {unknown} data Model tree data
314
+ * @param {Set<string>} names Model name set
315
+ * @private
316
+ */
317
+ private collectModelNamesFromTree;
318
+ /**
319
+ * Collect additional model names from object-form meta.createModelOptions defaults.
320
+ * @param {ModelConstructor} modelClass Model class constructor
321
+ * @param {Set<string>} names Model name set
322
+ * @private
323
+ */
324
+ private collectModelNamesFromMetaDefaults;
325
+ /**
326
+ * Ensure a single model class is available.
327
+ * @param {string} name Model class name
328
+ * @returns {Promise<ModelConstructor | null>} Model constructor or null when resolution fails
329
+ * @private
330
+ */
331
+ private ensureModel;
332
+ /**
333
+ * Ensure multiple model classes are available.
334
+ * @param {string[]} names Model class names
335
+ * @returns {Promise<EnsureBatchResult>} Batch ensure result
336
+ * @private
337
+ */
338
+ private ensureModels;
339
+ /**
340
+ * Resolve all unresolved string-based model references in a model tree before synchronous creation begins.
341
+ *
342
+ * Use this when you already have a model tree object, such as repository-returned data or resolved
343
+ * `createModelOptions`, and you need to ensure every string `use` in that tree has been loaded and
344
+ * registered into `_modelClasses` before calling `createModel()`.
345
+ *
346
+ * @param {unknown} data Model tree data
347
+ * @returns {Promise<EnsureBatchResult>} Batch ensure result
348
+ */
349
+ resolveModelTree(data: unknown): Promise<EnsureBatchResult>;
350
+ /**
351
+ * Preload all currently registered unresolved model loaders.
352
+ *
353
+ * This method is intended for flow-settings/discovery style entry points that need registered model
354
+ * classes to exist before UI is rendered, without requiring callers to know which specific models
355
+ * will be touched next.
356
+ *
357
+ * @returns {Promise<EnsureBatchResult>} Batch ensure result
358
+ */
359
+ preloadModelLoaders(): Promise<EnsureBatchResult>;
237
360
  registerResources(resources: Record<string, any>): void;
238
361
  createResource<T = FlowResource>(resourceType: ResourceType<T>, options?: {
239
362
  context?: FlowContext;
@@ -262,6 +385,15 @@ export declare class FlowEngine {
262
385
  * @returns {Map<string, ModelConstructor>} Model classes inherited from base class and passed the filter
263
386
  */
264
387
  getSubclassesOf(baseClass: string | ModelConstructor, filter?: (ModelClass: ModelConstructor, className: string) => boolean): Map<string, ModelConstructor>;
388
+ /**
389
+ * Asynchronously get all subclasses of a base class, including those registered via model loaders.
390
+ * Merges results from already-loaded classes (_modelClasses) and async loader entries with matching `extends` declarations.
391
+ * Loader-resolved classes are validated with `isInheritedFrom`; mismatches are warned and excluded.
392
+ * @param {string | ModelConstructor} baseClass Base class name or constructor
393
+ * @param {(ModelClass: ModelConstructor, className: string) => boolean} [filter] Optional filter function
394
+ * @returns {Promise<Map<string, ModelConstructor>>} Model classes that are subclasses of the base class
395
+ */
396
+ getSubclassesOfAsync(baseClass: string | ModelConstructor, filter?: (ModelClass: ModelConstructor, className: string) => boolean): Promise<Map<string, ModelConstructor>>;
265
397
  /**
266
398
  * Create and register a model instance.
267
399
  * If an instance with the same UID exists, returns the existing instance.
@@ -406,11 +538,11 @@ export declare class FlowEngine {
406
538
  replaceModel<T extends FlowModel = FlowModel>(uid: string, optionsOrFn?: Partial<FlowModelOptions> | ((currentOptions: FlowModelOptions) => Partial<FlowModelOptions>)): Promise<T | null>;
407
539
  /**
408
540
  * Move a model instance within its parent model.
409
- * @param {any} sourceId Source model UID
410
- * @param {any} targetId Target model UID
541
+ * @param {string | number} sourceId Source model UID
542
+ * @param {string | number} targetId Target model UID
411
543
  * @returns {Promise<void>} No return value
412
544
  */
413
- moveModel(sourceId: any, targetId: any, options?: PersistOptions): Promise<void>;
545
+ moveModel(sourceId: string | number, targetId: string | number, options?: PersistOptions): Promise<void>;
414
546
  /**
415
547
  * Filter model classes by parent class (supports multi-level inheritance).
416
548
  * @param {string | ModelConstructor} parentClass Parent class name or constructor