@nocobase/flow-engine 2.1.0-alpha.1 → 2.1.0-alpha.10

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 (283) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -10
  3. package/lib/BlockScopedFlowEngine.js +0 -1
  4. package/lib/FlowDefinition.d.ts +2 -0
  5. package/lib/JSRunner.d.ts +15 -0
  6. package/lib/JSRunner.js +82 -7
  7. package/lib/ViewScopedFlowEngine.js +8 -1
  8. package/lib/acl/Acl.js +13 -3
  9. package/lib/components/FlowContextSelector.js +155 -10
  10. package/lib/components/MobilePopup.js +6 -5
  11. package/lib/components/dnd/gridDragPlanner.d.ts +1 -0
  12. package/lib/components/dnd/gridDragPlanner.js +59 -3
  13. package/lib/components/settings/wrappers/component/SwitchWithTitle.js +2 -1
  14. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +76 -15
  15. package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +24 -4
  16. package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +21 -3
  17. package/lib/components/subModel/AddSubModelButton.js +16 -1
  18. package/lib/components/subModel/utils.js +2 -2
  19. package/lib/components/variables/VariableInput.js +9 -4
  20. package/lib/components/variables/VariableTag.js +46 -39
  21. package/lib/components/variables/utils.d.ts +7 -0
  22. package/lib/components/variables/utils.js +42 -2
  23. package/lib/data-source/index.d.ts +7 -27
  24. package/lib/data-source/index.js +84 -51
  25. package/lib/executor/FlowExecutor.d.ts +2 -1
  26. package/lib/executor/FlowExecutor.js +190 -26
  27. package/lib/flowContext.d.ts +230 -7
  28. package/lib/flowContext.js +2270 -148
  29. package/lib/flowEngine.d.ts +160 -1
  30. package/lib/flowEngine.js +383 -26
  31. package/lib/flowI18n.js +6 -4
  32. package/lib/flowSettings.d.ts +14 -6
  33. package/lib/flowSettings.js +51 -17
  34. package/lib/index.d.ts +7 -1
  35. package/lib/index.js +21 -0
  36. package/lib/lazy-helper.d.ts +14 -0
  37. package/lib/lazy-helper.js +71 -0
  38. package/lib/locale/en-US.json +9 -2
  39. package/lib/locale/index.d.ts +14 -0
  40. package/lib/locale/zh-CN.json +8 -1
  41. package/lib/models/CollectionFieldModel.d.ts +1 -0
  42. package/lib/models/CollectionFieldModel.js +3 -2
  43. package/lib/models/flowModel.d.ts +7 -0
  44. package/lib/models/flowModel.js +83 -8
  45. package/lib/provider.js +7 -6
  46. package/lib/resources/baseRecordResource.d.ts +5 -0
  47. package/lib/resources/baseRecordResource.js +24 -0
  48. package/lib/resources/multiRecordResource.d.ts +1 -0
  49. package/lib/resources/multiRecordResource.js +11 -4
  50. package/lib/resources/singleRecordResource.js +2 -0
  51. package/lib/resources/sqlResource.d.ts +4 -3
  52. package/lib/resources/sqlResource.js +8 -3
  53. package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +12 -2
  54. package/lib/runjs-context/contexts/JSBlockRunJSContext.js +2 -2
  55. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.d.ts +16 -0
  56. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +125 -0
  57. package/lib/runjs-context/contexts/JSItemRunJSContext.js +12 -2
  58. package/lib/runjs-context/contexts/base.js +706 -41
  59. package/lib/runjs-context/contributions.d.ts +33 -0
  60. package/lib/runjs-context/contributions.js +88 -0
  61. package/lib/runjs-context/helpers.js +12 -1
  62. package/lib/runjs-context/registry.d.ts +1 -1
  63. package/lib/runjs-context/setup.js +22 -9
  64. package/lib/runjs-context/snippets/global/api-request.snippet.js +3 -3
  65. package/lib/runjs-context/snippets/global/import-esm.snippet.js +2 -3
  66. package/lib/runjs-context/snippets/global/query-selector.snippet.js +8 -3
  67. package/lib/runjs-context/snippets/global/require-amd.snippet.js +1 -1
  68. package/lib/runjs-context/snippets/index.d.ts +11 -1
  69. package/lib/runjs-context/snippets/index.js +61 -40
  70. package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.js +10 -7
  71. package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +3 -3
  72. package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +2 -2
  73. package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.js +2 -2
  74. package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +2 -2
  75. package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +1 -1
  76. package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +1 -1
  77. package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +1 -1
  78. package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +5 -5
  79. package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +6 -6
  80. package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +3 -4
  81. package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.js +1 -1
  82. package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.js +20 -3
  83. package/lib/runjs-context/snippets/scene/detail/format-number.snippet.js +1 -1
  84. package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.js +1 -1
  85. package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +3 -3
  86. package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +3 -3
  87. package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +2 -2
  88. package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +1 -1
  89. package/lib/runjs-context/snippets/scene/form/render-basic.snippet.js +2 -2
  90. package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +6 -3
  91. package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +3 -1
  92. package/lib/runjsLibs.d.ts +28 -0
  93. package/lib/runjsLibs.js +532 -0
  94. package/lib/scheduler/ModelOperationScheduler.d.ts +7 -1
  95. package/lib/scheduler/ModelOperationScheduler.js +28 -23
  96. package/lib/types.d.ts +63 -1
  97. package/lib/utils/associationObjectVariable.d.ts +2 -2
  98. package/lib/utils/createCollectionContextMeta.js +1 -0
  99. package/lib/utils/createEphemeralContext.js +2 -2
  100. package/lib/utils/dateVariable.d.ts +16 -0
  101. package/lib/utils/dateVariable.js +380 -0
  102. package/lib/utils/exceptions.d.ts +7 -0
  103. package/lib/utils/exceptions.js +10 -0
  104. package/lib/utils/index.d.ts +8 -3
  105. package/lib/utils/index.js +49 -0
  106. package/lib/utils/params-resolvers.js +16 -9
  107. package/lib/utils/parsePathnameToViewParams.js +1 -1
  108. package/lib/utils/resolveModuleUrl.d.ts +58 -0
  109. package/lib/utils/resolveModuleUrl.js +65 -0
  110. package/lib/utils/resolveRunJSObjectValues.d.ts +16 -0
  111. package/lib/utils/resolveRunJSObjectValues.js +61 -0
  112. package/lib/utils/runjsModuleLoader.d.ts +58 -0
  113. package/lib/utils/runjsModuleLoader.js +422 -0
  114. package/lib/utils/runjsTemplateCompat.d.ts +35 -0
  115. package/lib/utils/runjsTemplateCompat.js +743 -0
  116. package/lib/utils/runjsValue.d.ts +29 -0
  117. package/lib/utils/runjsValue.js +275 -0
  118. package/lib/utils/safeGlobals.d.ts +18 -8
  119. package/lib/utils/safeGlobals.js +164 -17
  120. package/lib/utils/schema-utils.d.ts +17 -1
  121. package/lib/utils/schema-utils.js +80 -0
  122. package/lib/views/FlowView.d.ts +7 -1
  123. package/lib/views/createViewMeta.d.ts +0 -7
  124. package/lib/views/createViewMeta.js +19 -70
  125. package/lib/views/index.d.ts +1 -2
  126. package/lib/views/index.js +4 -3
  127. package/lib/views/runViewBeforeClose.d.ts +10 -0
  128. package/lib/views/runViewBeforeClose.js +45 -0
  129. package/lib/views/useDialog.d.ts +2 -1
  130. package/lib/views/useDialog.js +28 -6
  131. package/lib/views/useDrawer.d.ts +2 -1
  132. package/lib/views/useDrawer.js +27 -5
  133. package/lib/views/usePage.d.ts +6 -1
  134. package/lib/views/usePage.js +53 -9
  135. package/lib/views/usePopover.js +4 -1
  136. package/lib/views/viewEvents.d.ts +17 -0
  137. package/lib/views/viewEvents.js +90 -0
  138. package/package.json +5 -5
  139. package/src/BlockScopedFlowEngine.ts +2 -5
  140. package/src/JSRunner.ts +111 -5
  141. package/src/ViewScopedFlowEngine.ts +8 -0
  142. package/src/__tests__/JSRunner.test.ts +91 -1
  143. package/src/__tests__/createViewMeta.popup.test.ts +62 -1
  144. package/src/__tests__/flowContext.test.ts +693 -1
  145. package/src/__tests__/flowEngine.dataSourceDirty.test.ts +63 -0
  146. package/src/__tests__/flowEngine.modelLoaders.test.ts +245 -0
  147. package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
  148. package/src/__tests__/flowRunJSContextDefine.test.ts +63 -0
  149. package/src/__tests__/flowRuntimeContext.test.ts +2 -1
  150. package/src/__tests__/flowSettings.open.test.tsx +123 -19
  151. package/src/__tests__/flowSettings.test.ts +94 -15
  152. package/src/__tests__/provider.test.tsx +0 -5
  153. package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
  154. package/src/__tests__/runjsContext.test.ts +23 -7
  155. package/src/__tests__/runjsContextImplementations.test.ts +34 -3
  156. package/src/__tests__/runjsContextRuntime.test.ts +3 -3
  157. package/src/__tests__/runjsContributions.test.ts +89 -0
  158. package/src/__tests__/runjsExternalLibs.test.ts +242 -0
  159. package/src/__tests__/runjsLibsLazyLoading.test.ts +44 -0
  160. package/src/__tests__/runjsLocales.test.ts +4 -1
  161. package/src/__tests__/runjsPreprocessDefault.test.ts +72 -0
  162. package/src/__tests__/runjsRuntimeFeatures.test.ts +166 -0
  163. package/src/__tests__/runjsSnippets.test.ts +40 -3
  164. package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
  165. package/src/acl/Acl.tsx +3 -3
  166. package/src/components/FlowContextSelector.tsx +208 -12
  167. package/src/components/MobilePopup.tsx +4 -2
  168. package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +3 -3
  169. package/src/components/__tests__/gridDragPlanner.test.ts +229 -1
  170. package/src/components/dnd/gridDragPlanner.ts +68 -2
  171. package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +2 -1
  172. package/src/components/settings/wrappers/component/__tests__/InlineControls.test.tsx +74 -0
  173. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +109 -16
  174. package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +41 -7
  175. package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +31 -4
  176. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +157 -5
  177. package/src/components/subModel/AddSubModelButton.tsx +17 -1
  178. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +142 -32
  179. package/src/components/subModel/utils.ts +1 -1
  180. package/src/components/variables/VariableInput.tsx +12 -4
  181. package/src/components/variables/VariableTag.tsx +54 -45
  182. package/src/components/variables/__tests__/FlowContextSelector.test.tsx +260 -3
  183. package/src/components/variables/__tests__/VariableTag.test.tsx +50 -0
  184. package/src/components/variables/__tests__/utils.test.ts +81 -3
  185. package/src/components/variables/utils.ts +67 -6
  186. package/src/data-source/index.ts +88 -110
  187. package/src/executor/FlowExecutor.ts +230 -28
  188. package/src/executor/__tests__/flowExecutor.test.ts +123 -0
  189. package/src/flowContext.ts +2989 -212
  190. package/src/flowEngine.ts +427 -22
  191. package/src/flowI18n.ts +7 -5
  192. package/src/flowSettings.ts +58 -18
  193. package/src/index.ts +14 -1
  194. package/src/lazy-helper.tsx +57 -0
  195. package/src/locale/en-US.json +9 -2
  196. package/src/locale/zh-CN.json +8 -1
  197. package/src/models/CollectionFieldModel.tsx +3 -1
  198. package/src/models/__tests__/dispatchEvent.when.test.ts +768 -0
  199. package/src/models/__tests__/flowModel.clone.test.ts +416 -0
  200. package/src/models/__tests__/flowModel.test.ts +20 -4
  201. package/src/models/flowModel.tsx +112 -7
  202. package/src/provider.tsx +9 -7
  203. package/src/resources/__tests__/multiRecordResource.test.ts +44 -0
  204. package/src/resources/__tests__/sqlResource.test.ts +60 -0
  205. package/src/resources/baseRecordResource.ts +31 -0
  206. package/src/resources/multiRecordResource.ts +11 -4
  207. package/src/resources/singleRecordResource.ts +3 -0
  208. package/src/resources/sqlResource.ts +11 -6
  209. package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +10 -0
  210. package/src/runjs-context/contexts/JSBlockRunJSContext.ts +6 -2
  211. package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +106 -0
  212. package/src/runjs-context/contexts/JSItemRunJSContext.ts +10 -0
  213. package/src/runjs-context/contexts/base.ts +715 -44
  214. package/src/runjs-context/contributions.ts +88 -0
  215. package/src/runjs-context/helpers.ts +11 -1
  216. package/src/runjs-context/registry.ts +1 -1
  217. package/src/runjs-context/setup.ts +24 -9
  218. package/src/runjs-context/snippets/global/api-request.snippet.ts +3 -3
  219. package/src/runjs-context/snippets/global/import-esm.snippet.ts +2 -3
  220. package/src/runjs-context/snippets/global/query-selector.snippet.ts +8 -3
  221. package/src/runjs-context/snippets/global/require-amd.snippet.ts +1 -1
  222. package/src/runjs-context/snippets/index.ts +75 -41
  223. package/src/runjs-context/snippets/scene/block/add-event-listener.snippet.ts +11 -13
  224. package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +3 -3
  225. package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +2 -2
  226. package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +2 -2
  227. package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +2 -2
  228. package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +1 -1
  229. package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +1 -1
  230. package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +1 -1
  231. package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +6 -11
  232. package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +6 -6
  233. package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +3 -4
  234. package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +1 -1
  235. package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +20 -3
  236. package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +1 -1
  237. package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +1 -1
  238. package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +3 -3
  239. package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +3 -3
  240. package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +2 -2
  241. package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +1 -1
  242. package/src/runjs-context/snippets/scene/form/render-basic.snippet.ts +3 -8
  243. package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +6 -3
  244. package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +3 -1
  245. package/src/runjsLibs.ts +622 -0
  246. package/src/scheduler/ModelOperationScheduler.ts +41 -24
  247. package/src/types.ts +86 -1
  248. package/src/utils/__tests__/dateVariable.test.ts +101 -0
  249. package/src/utils/__tests__/params-resolvers.test.ts +40 -0
  250. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
  251. package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +38 -0
  252. package/src/utils/__tests__/runjsTemplateCompat.test.ts +159 -0
  253. package/src/utils/__tests__/runjsValue.test.ts +44 -0
  254. package/src/utils/__tests__/safeGlobals.test.ts +57 -2
  255. package/src/utils/__tests__/utils.test.ts +157 -0
  256. package/src/utils/associationObjectVariable.ts +2 -2
  257. package/src/utils/createCollectionContextMeta.ts +1 -0
  258. package/src/utils/createEphemeralContext.ts +5 -4
  259. package/src/utils/dateVariable.ts +397 -0
  260. package/src/utils/exceptions.ts +11 -0
  261. package/src/utils/index.ts +38 -3
  262. package/src/utils/params-resolvers.ts +23 -9
  263. package/src/utils/parsePathnameToViewParams.ts +2 -2
  264. package/src/utils/resolveModuleUrl.ts +91 -0
  265. package/src/utils/resolveRunJSObjectValues.ts +46 -0
  266. package/src/utils/runjsModuleLoader.ts +553 -0
  267. package/src/utils/runjsTemplateCompat.ts +828 -0
  268. package/src/utils/runjsValue.ts +287 -0
  269. package/src/utils/safeGlobals.ts +188 -17
  270. package/src/utils/schema-utils.ts +109 -1
  271. package/src/views/FlowView.tsx +11 -1
  272. package/src/views/__tests__/FlowView.usePage.test.tsx +54 -1
  273. package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
  274. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +44 -16
  275. package/src/views/__tests__/viewEvents.resolveOpenerEngine.test.ts +28 -0
  276. package/src/views/createViewMeta.ts +22 -75
  277. package/src/views/index.tsx +1 -2
  278. package/src/views/runViewBeforeClose.ts +19 -0
  279. package/src/views/useDialog.tsx +34 -5
  280. package/src/views/useDrawer.tsx +33 -4
  281. package/src/views/usePage.tsx +63 -8
  282. package/src/views/usePopover.tsx +4 -1
  283. package/src/views/viewEvents.ts +55 -0
@@ -52,12 +52,12 @@ __export(flowContext_exports, {
52
52
  FlowForkModelContext: () => FlowForkModelContext,
53
53
  FlowModelContext: () => FlowModelContext,
54
54
  FlowRunJSContext: () => FlowRunJSContext,
55
- FlowRuntimeContext: () => FlowRuntimeContext
55
+ FlowRuntimeContext: () => FlowRuntimeContext,
56
+ createRunJSDeprecationProxy: () => createRunJSDeprecationProxy
56
57
  });
57
58
  module.exports = __toCommonJS(flowContext_exports);
58
59
  var import_reactive = require("@formily/reactive");
59
60
  var antd = __toESM(require("antd"));
60
- var antdIcons = __toESM(require("@ant-design/icons"));
61
61
  var import_lodash = __toESM(require("lodash"));
62
62
  var import_qs = __toESM(require("qs"));
63
63
  var import_react = __toESM(require("react"));
@@ -74,9 +74,12 @@ var import_utils = require("./utils");
74
74
  var import_exceptions = require("./utils/exceptions");
75
75
  var import_params_resolvers = require("./utils/params-resolvers");
76
76
  var import_serverContextParams = require("./utils/serverContextParams");
77
+ var import_variablesParams = require("./utils/variablesParams");
77
78
  var import_registry = require("./runjs-context/registry");
78
79
  var import_createEphemeralContext = require("./utils/createEphemeralContext");
79
80
  var import_dayjs = __toESM(require("dayjs"));
81
+ var import_runjsLibs = require("./runjsLibs");
82
+ var import_runjsModuleLoader = require("./utils/runjsModuleLoader");
80
83
  var _proxy, _FlowContext_instances, createChildNodes_fn, findMetaByPath_fn, findMetaInDelegatesDeep_fn, findMetaInProperty_fn, resolvePathInMeta_fn, resolvePathInMetaAsync_fn, buildParentTitles_fn, toTreeNode_fn;
81
84
  function isRecordRefLike(val) {
82
85
  return !!(val && typeof val === "object" && "collection" in val && "filterByTk" in val);
@@ -96,11 +99,56 @@ function filterBuilderOutputByPaths(built, neededPaths) {
96
99
  return void 0;
97
100
  }
98
101
  __name(filterBuilderOutputByPaths, "filterBuilderOutputByPaths");
102
+ function topLevelOf(subPath) {
103
+ if (!subPath) return void 0;
104
+ const m = String(subPath).match(/^([^.[]+)/);
105
+ return m == null ? void 0 : m[1];
106
+ }
107
+ __name(topLevelOf, "topLevelOf");
108
+ function inferSelectsFromUsage(paths = []) {
109
+ if (!Array.isArray(paths) || paths.length === 0) {
110
+ return { generatedAppends: void 0, generatedFields: void 0 };
111
+ }
112
+ const appendSet = /* @__PURE__ */ new Set();
113
+ const fieldSet = /* @__PURE__ */ new Set();
114
+ const normalizePath = /* @__PURE__ */ __name((raw) => {
115
+ if (!raw) return "";
116
+ let s = String(raw);
117
+ s = s.replace(/\[(?:\d+)\]/g, "");
118
+ s = s.replace(/\[(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)')\]/g, (_m, g1, g2) => `.${g1 || g2}`);
119
+ s = s.replace(/\.\.+/g, ".");
120
+ s = s.replace(/^\./, "").replace(/\.$/, "");
121
+ return s;
122
+ }, "normalizePath");
123
+ for (let path of paths) {
124
+ if (!path) continue;
125
+ while (/^\[(\d+)\](\.|$)/.test(path)) {
126
+ path = path.replace(/^\[(\d+)\]\.?/, "");
127
+ }
128
+ const norm = normalizePath(path);
129
+ if (!norm) continue;
130
+ const segments = norm.split(".").filter(Boolean);
131
+ if (segments.length === 0) continue;
132
+ if (segments.length === 1) {
133
+ fieldSet.add(segments[0]);
134
+ continue;
135
+ }
136
+ for (let i = 0; i < segments.length - 1; i++) {
137
+ appendSet.add(segments.slice(0, i + 1).join("."));
138
+ }
139
+ fieldSet.add(segments.join("."));
140
+ }
141
+ const generatedAppends = appendSet.size ? Array.from(appendSet) : void 0;
142
+ const generatedFields = fieldSet.size ? Array.from(fieldSet) : void 0;
143
+ return { generatedAppends, generatedFields };
144
+ }
145
+ __name(inferSelectsFromUsage, "inferSelectsFromUsage");
99
146
  const _FlowContext = class _FlowContext {
100
147
  constructor() {
101
148
  __privateAdd(this, _FlowContext_instances);
102
149
  __publicField(this, "_props", {});
103
150
  __publicField(this, "_methods", {});
151
+ __publicField(this, "_methodInfos", {});
104
152
  __publicField(this, "_cache", {});
105
153
  __publicField(this, "_observableCache", import_reactive.observable.shallow({}));
106
154
  __publicField(this, "_delegates", []);
@@ -163,8 +211,15 @@ const _FlowContext = class _FlowContext {
163
211
  get: /* @__PURE__ */ __name(() => this._getOwnProperty(key, this.createProxy()), "get")
164
212
  });
165
213
  }
166
- defineMethod(name, fn, des) {
214
+ defineMethod(name, fn, info) {
167
215
  this._methods[name] = fn;
216
+ if (typeof info === "string") {
217
+ this._methodInfos[name] = { description: info };
218
+ } else if (info && typeof info === "object") {
219
+ this._methodInfos[name] = info;
220
+ } else {
221
+ delete this._methodInfos[name];
222
+ }
168
223
  Object.defineProperty(this, name, {
169
224
  configurable: true,
170
225
  enumerable: false,
@@ -315,6 +370,1477 @@ const _FlowContext = class _FlowContext {
315
370
  });
316
371
  return sorted.map(([key, metaOrFactory]) => __privateMethod(this, _FlowContext_instances, toTreeNode_fn).call(this, key, metaOrFactory, [key], []));
317
372
  }
373
+ /**
374
+ * 获取静态 API 文档信息(仅顶层一层)。
375
+ *
376
+ * - 输出仅来自 RunJS doc 与 defineProperty/defineMethod 的 info
377
+ * - 不读取/展开 PropertyMeta(变量结构)
378
+ * - 不自动展开深层 properties
379
+ * - 不返回自动补全字段(例如 completion)
380
+ */
381
+ async getApiInfos(options = {}) {
382
+ const version = options.version || "v1";
383
+ const evalCtx = this.createProxy();
384
+ const isPrivateKey = /* @__PURE__ */ __name((key) => typeof key === "string" && key.startsWith("_"), "isPrivateKey");
385
+ const isVarRootKey = /* @__PURE__ */ __name((key) => key === "record" || key === "formValues" || key === "popup", "isVarRootKey");
386
+ const isPromiseLike = /* @__PURE__ */ __name((v) => !!v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function", "isPromiseLike");
387
+ const getRunJSDoc = /* @__PURE__ */ __name(() => {
388
+ var _a, _b, _c, _d, _e;
389
+ const modelClass = (0, import_registry.getModelClassName)(this);
390
+ const Ctor = import_registry.RunJSContextRegistry.resolve(version, modelClass) || import_registry.RunJSContextRegistry.resolve(version, "*");
391
+ if (!Ctor) return {};
392
+ const locale = ((_b = (_a = this == null ? void 0 : this.api) == null ? void 0 : _a.auth) == null ? void 0 : _b.locale) || ((_c = this == null ? void 0 : this.i18n) == null ? void 0 : _c.language) || (this == null ? void 0 : this.locale);
393
+ try {
394
+ if ((_d = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _d.length) {
395
+ return Ctor.getDoc(locale) || {};
396
+ }
397
+ return ((_e = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _e.call(Ctor)) || {};
398
+ } catch (_2) {
399
+ return {};
400
+ }
401
+ }, "getRunJSDoc");
402
+ const doc = getRunJSDoc();
403
+ const docMethods = __isPlainObject(doc == null ? void 0 : doc.methods) ? doc.methods : {};
404
+ const docProps = __isPlainObject(doc == null ? void 0 : doc.properties) ? doc.properties : {};
405
+ const toDocObject = /* @__PURE__ */ __name((node) => {
406
+ if (typeof node === "string") return { description: node };
407
+ if (__isPlainObject(node)) return node;
408
+ return void 0;
409
+ }, "toDocObject");
410
+ const mapDocKeyToApiKey = /* @__PURE__ */ __name((key, docNode) => {
411
+ const desc = typeof docNode === "string" ? docNode : __isPlainObject(docNode) && typeof docNode.description === "string" ? String(docNode.description) : void 0;
412
+ if (desc && desc.includes(`ctx.libs.${key}`)) return `libs.${key}`;
413
+ return key;
414
+ }, "mapDocKeyToApiKey");
415
+ const pickMethodInfo = /* @__PURE__ */ __name((obj) => {
416
+ const src = toDocObject(obj);
417
+ if (!src) return {};
418
+ const out2 = {};
419
+ for (const k of ["description", "examples", "ref", "params", "returns"]) {
420
+ const v = src[k];
421
+ if (typeof v !== "undefined") out2[k] = v;
422
+ }
423
+ if (Array.isArray(out2.examples)) {
424
+ out2.examples = out2.examples.filter((x) => typeof x === "string" && x.trim());
425
+ }
426
+ return out2;
427
+ }, "pickMethodInfo");
428
+ const pickPropertyInfo = /* @__PURE__ */ __name((obj) => {
429
+ const src = toDocObject(obj);
430
+ if (!src) return {};
431
+ const out2 = {};
432
+ for (const k of ["title", "type", "interface", "description", "examples", "ref", "params", "returns"]) {
433
+ const v = src[k];
434
+ if (typeof v !== "undefined") out2[k] = v;
435
+ }
436
+ if (Array.isArray(out2.examples)) {
437
+ out2.examples = out2.examples.filter((x) => typeof x === "string" && x.trim());
438
+ }
439
+ return out2;
440
+ }, "pickPropertyInfo");
441
+ const getMethodInfoFromChain = /* @__PURE__ */ __name((name) => {
442
+ const visited = /* @__PURE__ */ new WeakSet();
443
+ const walk = /* @__PURE__ */ __name((ctx) => {
444
+ var _a;
445
+ if (!ctx || typeof ctx !== "object") return void 0;
446
+ if (visited.has(ctx)) return void 0;
447
+ visited.add(ctx);
448
+ if (Object.prototype.hasOwnProperty.call(ctx._methodInfos || {}, name)) {
449
+ return (_a = ctx._methodInfos) == null ? void 0 : _a[name];
450
+ }
451
+ const delegates = ctx._delegates;
452
+ if (Array.isArray(delegates)) {
453
+ for (const d of delegates) {
454
+ const found = walk(d);
455
+ if (found) return found;
456
+ }
457
+ }
458
+ return void 0;
459
+ }, "walk");
460
+ return walk(this);
461
+ }, "getMethodInfoFromChain");
462
+ const resolvePropertyInfo = /* @__PURE__ */ __name(async (key) => {
463
+ const opt = this.getPropertyOptions(key);
464
+ if (!(opt == null ? void 0 : opt.info)) return void 0;
465
+ try {
466
+ const v = typeof opt.info === "function" ? opt.info.call(evalCtx, evalCtx) : opt.info;
467
+ const resolved = isPromiseLike(v) ? await v : v;
468
+ return resolved ?? void 0;
469
+ } catch (_2) {
470
+ return void 0;
471
+ }
472
+ }, "resolvePropertyInfo");
473
+ const propKeys = /* @__PURE__ */ new Set();
474
+ const methodKeys = /* @__PURE__ */ new Set();
475
+ for (const k of Object.keys(docProps)) propKeys.add(k);
476
+ for (const k of Object.keys(docMethods)) methodKeys.add(k);
477
+ const collectInfoKeysDeep = /* @__PURE__ */ __name((ctx, visited) => {
478
+ if (!ctx || typeof ctx !== "object") return;
479
+ if (visited.has(ctx)) return;
480
+ visited.add(ctx);
481
+ try {
482
+ const props = ctx._props;
483
+ if (props && typeof props === "object") {
484
+ for (const [k, v] of Object.entries(props)) {
485
+ if (v == null ? void 0 : v.info) propKeys.add(k);
486
+ }
487
+ }
488
+ } catch (_2) {
489
+ }
490
+ try {
491
+ const mi = ctx._methodInfos;
492
+ if (mi && typeof mi === "object") {
493
+ for (const k of Object.keys(mi)) methodKeys.add(k);
494
+ }
495
+ } catch (_2) {
496
+ }
497
+ try {
498
+ const delegates = ctx._delegates;
499
+ if (Array.isArray(delegates)) {
500
+ for (const d of delegates) collectInfoKeysDeep(d, visited);
501
+ }
502
+ } catch (_2) {
503
+ }
504
+ }, "collectInfoKeysDeep");
505
+ collectInfoKeysDeep(this, /* @__PURE__ */ new WeakSet());
506
+ const out = {};
507
+ for (const key of propKeys) {
508
+ if (isPrivateKey(key)) continue;
509
+ if (isVarRootKey(key)) continue;
510
+ const docNode = docProps[key];
511
+ const infoNode = await resolvePropertyInfo(key);
512
+ if (typeof docNode === "undefined" && typeof infoNode === "undefined") continue;
513
+ const docObj = toDocObject(docNode);
514
+ const infoObj = toDocObject(infoNode);
515
+ let node = {};
516
+ node = { ...node, ...pickPropertyInfo(docObj) };
517
+ node = { ...node, ...pickPropertyInfo(infoObj) };
518
+ delete node.properties;
519
+ delete node.completion;
520
+ if (!Object.keys(node).length) continue;
521
+ const outKey = mapDocKeyToApiKey(key, docNode);
522
+ out[outKey] = out[outKey] ? { ...out[outKey] || {}, ...node || {} } : node;
523
+ }
524
+ for (const key of methodKeys) {
525
+ if (isPrivateKey(key)) continue;
526
+ const docNode = docMethods[key];
527
+ const info = getMethodInfoFromChain(key);
528
+ if (typeof docNode === "undefined" && typeof info === "undefined") continue;
529
+ const docObj = toDocObject(docNode);
530
+ let node = {};
531
+ node = { ...node, ...pickMethodInfo(docObj) };
532
+ node = { ...node, ...pickMethodInfo(info) };
533
+ delete node.properties;
534
+ delete node.completion;
535
+ if (!Object.keys(node).length) continue;
536
+ node.type = "function";
537
+ if (!out[key]) out[key] = node;
538
+ else out[key] = { ...out[key] || {}, ...node || {} };
539
+ }
540
+ const libsDocObj = toDocObject(docProps.libs);
541
+ const libsChildren = __isPlainObject(libsDocObj == null ? void 0 : libsDocObj.properties) ? libsDocObj.properties : void 0;
542
+ if (libsChildren) {
543
+ for (const [k, v] of Object.entries(libsChildren)) {
544
+ if (isPrivateKey(k)) continue;
545
+ const outKey = `libs.${k}`;
546
+ if (out[outKey]) continue;
547
+ const childObj = toDocObject(v);
548
+ let node = {};
549
+ node = { ...node, ...pickPropertyInfo(childObj) };
550
+ delete node.properties;
551
+ delete node.completion;
552
+ if (!node.description || !String(node.description).trim()) continue;
553
+ out[outKey] = node;
554
+ }
555
+ }
556
+ return out;
557
+ }
558
+ /**
559
+ * 获取运行时环境快照信息(小体积、可序列化)。
560
+ */
561
+ async getEnvInfos() {
562
+ var _a, _b, _c;
563
+ const evalCtx = this.createProxy();
564
+ const isPromiseLike = /* @__PURE__ */ __name((v) => !!v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function", "isPromiseLike");
565
+ const envs = {};
566
+ const getMaybe = /* @__PURE__ */ __name((fn) => {
567
+ try {
568
+ return fn();
569
+ } catch (_2) {
570
+ return void 0;
571
+ }
572
+ }, "getMaybe");
573
+ const hasSnapshotValue = /* @__PURE__ */ __name((v) => {
574
+ if (typeof v === "undefined" || v === null) return false;
575
+ if (typeof v === "string") return v.trim().length > 0;
576
+ if (Array.isArray(v)) return v.length > 0;
577
+ return true;
578
+ }, "hasSnapshotValue");
579
+ const getResourceSnapshot = /* @__PURE__ */ __name((res) => {
580
+ var _a2, _b2, _c2, _d, _e;
581
+ const out = {};
582
+ if (!res) return out;
583
+ const r = res;
584
+ for (const k of [
585
+ "dataSourceKey",
586
+ "collectionName",
587
+ "associationName",
588
+ "filterByTk",
589
+ "sourceId"
590
+ ]) {
591
+ const v = r == null ? void 0 : r[k];
592
+ if (hasSnapshotValue(v)) out[k] = v;
593
+ }
594
+ if (!("dataSourceKey" in out)) {
595
+ const v = (_a2 = r.getDataSourceKey) == null ? void 0 : _a2.call(r);
596
+ if (hasSnapshotValue(v)) out.dataSourceKey = v;
597
+ }
598
+ if (!("filterByTk" in out)) {
599
+ const v = (_b2 = r.getFilterByTk) == null ? void 0 : _b2.call(r);
600
+ if (hasSnapshotValue(v)) out.filterByTk = v;
601
+ }
602
+ if (!("filterByTk" in out)) {
603
+ const v = (_c2 = r.getMeta) == null ? void 0 : _c2.call(r, "currentFilterByTk");
604
+ if (hasSnapshotValue(v)) out.filterByTk = v;
605
+ }
606
+ if (!("sourceId" in out)) {
607
+ const v = (_d = r.getSourceId) == null ? void 0 : _d.call(r);
608
+ if (hasSnapshotValue(v)) out.sourceId = v;
609
+ }
610
+ if (!("collectionName" in out) || !("associationName" in out)) {
611
+ const rn = (_e = r.getResourceName) == null ? void 0 : _e.call(r);
612
+ const resourceName = typeof rn === "string" ? rn.trim() : "";
613
+ if (resourceName) {
614
+ const parts = resourceName.split(".").map((x) => x.trim()).filter(Boolean);
615
+ if (parts.length === 1) {
616
+ if (!("collectionName" in out)) out.collectionName = parts[0];
617
+ } else if (parts.length >= 2) {
618
+ if (!("collectionName" in out)) out.collectionName = parts[0];
619
+ if (!("associationName" in out)) out.associationName = parts.slice(1).join(".");
620
+ }
621
+ }
622
+ }
623
+ return out;
624
+ }, "getResourceSnapshot");
625
+ const popup = await (async () => {
626
+ try {
627
+ const raw = evalCtx.popup;
628
+ return isPromiseLike(raw) ? await raw : raw;
629
+ } catch (_2) {
630
+ return void 0;
631
+ }
632
+ })();
633
+ const popupLike = popup;
634
+ const model = getMaybe(() => evalCtx.model);
635
+ const blockModel = getMaybe(() => evalCtx.blockModel);
636
+ const inputArgs = getMaybe(() => {
637
+ var _a2;
638
+ return (_a2 = evalCtx.view) == null ? void 0 : _a2.inputArgs;
639
+ });
640
+ const ctxResource = getMaybe(() => evalCtx.resource);
641
+ const popupResource = popupLike == null ? void 0 : popupLike.resource;
642
+ const popupResourceSnap = getResourceSnapshot(popupResource);
643
+ const blockOwner = blockModel;
644
+ const blockOwnerExpr = blockModel ? "ctx.blockModel" : void 0;
645
+ const blockResourceBaseExpr = blockOwnerExpr ? `${blockOwnerExpr}.resource` : void 0;
646
+ const blockResource = blockOwner == null ? void 0 : blockOwner.resource;
647
+ const blockResourceSnap = getResourceSnapshot(blockResource);
648
+ const inputArgsSnap = getResourceSnapshot(inputArgs);
649
+ const ctxResourceSnap = getResourceSnapshot(ctxResource);
650
+ const pickWithGetVar = /* @__PURE__ */ __name((pairs) => {
651
+ for (const p of pairs) {
652
+ if (hasSnapshotValue(p.value)) return { value: p.value, getVar: p.getVar };
653
+ }
654
+ return void 0;
655
+ }, "pickWithGetVar");
656
+ const hasAnyResourceValuesIn = /* @__PURE__ */ __name((snap) => hasSnapshotValue(snap.collectionName) || hasSnapshotValue(snap.dataSourceKey) || hasSnapshotValue(snap.associationName), "hasAnyResourceValuesIn");
657
+ const resourceBaseExpr = hasAnyResourceValuesIn(popupResourceSnap) ? "ctx.popup.resource" : hasAnyResourceValuesIn(blockResourceSnap) ? blockResourceBaseExpr : hasAnyResourceValuesIn(inputArgsSnap) ? "ctx.view.inputArgs" : hasAnyResourceValuesIn(ctxResourceSnap) ? "ctx.resource" : void 0;
658
+ const collectionNamePick = pickWithGetVar([
659
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.collectionName, getVar: "ctx.popup.resource.collectionName" },
660
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.collectionName, getVar: `${blockResourceBaseExpr}.collectionName` },
661
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.collectionName, getVar: "ctx.view.inputArgs.collectionName" },
662
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.collectionName, getVar: "ctx.resource.collectionName" }
663
+ ]);
664
+ const dataSourceKeyPick = pickWithGetVar([
665
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.dataSourceKey, getVar: "ctx.popup.resource.dataSourceKey" },
666
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.dataSourceKey, getVar: `${blockResourceBaseExpr}.dataSourceKey` },
667
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.dataSourceKey, getVar: "ctx.view.inputArgs.dataSourceKey" },
668
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.dataSourceKey, getVar: "ctx.resource.dataSourceKey" }
669
+ ]);
670
+ const associationNamePick = pickWithGetVar([
671
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.associationName, getVar: "ctx.popup.resource.associationName" },
672
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.associationName, getVar: `${blockResourceBaseExpr}.associationName` },
673
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.associationName, getVar: "ctx.view.inputArgs.associationName" },
674
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.associationName, getVar: "ctx.resource.associationName" }
675
+ ]);
676
+ const filterByTkPick = pickWithGetVar([
677
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.filterByTk, getVar: "ctx.popup.resource.filterByTk" },
678
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.filterByTk, getVar: `${blockResourceBaseExpr}.filterByTk` },
679
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.filterByTk, getVar: "ctx.view.inputArgs.filterByTk" },
680
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.filterByTk, getVar: "ctx.resource.filterByTk" }
681
+ ]);
682
+ const sourceIdPick = pickWithGetVar([
683
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.sourceId, getVar: "ctx.popup.resource.sourceId" },
684
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.sourceId, getVar: `${blockResourceBaseExpr}.sourceId` },
685
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.sourceId, getVar: "ctx.view.inputArgs.sourceId" },
686
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.sourceId, getVar: "ctx.resource.sourceId" }
687
+ ]);
688
+ const resourceProps = {};
689
+ let hasResourceValues = false;
690
+ const collectionNameValue = collectionNamePick == null ? void 0 : collectionNamePick.value;
691
+ if (hasSnapshotValue(collectionNameValue)) {
692
+ resourceProps.collectionName = {
693
+ description: "Collection name",
694
+ getVar: (collectionNamePick == null ? void 0 : collectionNamePick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.collectionName` : void 0),
695
+ value: collectionNameValue
696
+ };
697
+ hasResourceValues = true;
698
+ }
699
+ const dataSourceKeyValue = dataSourceKeyPick == null ? void 0 : dataSourceKeyPick.value;
700
+ if (hasSnapshotValue(dataSourceKeyValue)) {
701
+ resourceProps.dataSourceKey = {
702
+ description: "Data source key",
703
+ getVar: (dataSourceKeyPick == null ? void 0 : dataSourceKeyPick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.dataSourceKey` : void 0),
704
+ value: dataSourceKeyValue
705
+ };
706
+ hasResourceValues = true;
707
+ }
708
+ const associationNameValue = associationNamePick == null ? void 0 : associationNamePick.value;
709
+ if (hasSnapshotValue(associationNameValue)) {
710
+ resourceProps.associationName = {
711
+ description: "Association name",
712
+ getVar: (associationNamePick == null ? void 0 : associationNamePick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.associationName` : void 0),
713
+ value: associationNameValue
714
+ };
715
+ hasResourceValues = true;
716
+ }
717
+ if (hasResourceValues) {
718
+ if (hasSnapshotValue(filterByTkPick == null ? void 0 : filterByTkPick.value)) {
719
+ resourceProps.filterByTk = {
720
+ description: "Record filterByTk",
721
+ getVar: (filterByTkPick == null ? void 0 : filterByTkPick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.filterByTk` : void 0)
722
+ };
723
+ }
724
+ if (hasSnapshotValue(sourceIdPick == null ? void 0 : sourceIdPick.value)) {
725
+ resourceProps.sourceId = {
726
+ description: "Source record ID (sourceId)",
727
+ getVar: (sourceIdPick == null ? void 0 : sourceIdPick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.sourceId` : void 0)
728
+ };
729
+ }
730
+ envs.resource = {
731
+ description: "Resource information",
732
+ getVar: resourceBaseExpr,
733
+ properties: resourceProps
734
+ };
735
+ }
736
+ if (hasSnapshotValue(filterByTkPick == null ? void 0 : filterByTkPick.value)) {
737
+ envs.record = {
738
+ description: "Current record",
739
+ getVar: "ctx.record"
740
+ };
741
+ }
742
+ const pickLabel = /* @__PURE__ */ __name((obj) => {
743
+ var _a2, _b2;
744
+ try {
745
+ const t = obj == null ? void 0 : obj.title;
746
+ if (typeof t === "string" && t.trim()) return t;
747
+ } catch (_2) {
748
+ }
749
+ try {
750
+ const label = (_b2 = (_a2 = obj == null ? void 0 : obj.constructor) == null ? void 0 : _a2.meta) == null ? void 0 : _b2.label;
751
+ if (typeof label === "string" && label.trim()) return label;
752
+ } catch (_2) {
753
+ }
754
+ return void 0;
755
+ }, "pickLabel");
756
+ if (model) {
757
+ const modelLabel = pickLabel(model);
758
+ const modelUid = model.uid;
759
+ const modelClassName = (_a = model.constructor) == null ? void 0 : _a.name;
760
+ const modelResourceSnap = getResourceSnapshot(model.resource);
761
+ const modelResourceProps = {};
762
+ let hasModelResourceValues = false;
763
+ const modelCollectionName = modelResourceSnap.collectionName;
764
+ if (hasSnapshotValue(modelCollectionName)) {
765
+ modelResourceProps.collectionName = {
766
+ description: "Collection name",
767
+ getVar: "ctx.model.resource.collectionName",
768
+ value: modelCollectionName
769
+ };
770
+ hasModelResourceValues = true;
771
+ }
772
+ const modelDataSourceKey = modelResourceSnap.dataSourceKey;
773
+ if (hasSnapshotValue(modelDataSourceKey)) {
774
+ modelResourceProps.dataSourceKey = {
775
+ description: "Data source key",
776
+ getVar: "ctx.model.resource.dataSourceKey",
777
+ value: modelDataSourceKey
778
+ };
779
+ hasModelResourceValues = true;
780
+ }
781
+ const modelAssociationName = modelResourceSnap.associationName;
782
+ if (hasSnapshotValue(modelAssociationName)) {
783
+ modelResourceProps.associationName = {
784
+ description: "Association name",
785
+ getVar: "ctx.model.resource.associationName",
786
+ value: modelAssociationName
787
+ };
788
+ hasModelResourceValues = true;
789
+ }
790
+ envs.flowModel = {
791
+ description: "Current FlowModel information",
792
+ getVar: "ctx.model",
793
+ properties: {
794
+ ...hasSnapshotValue(modelLabel) ? { label: { description: "Flow model label", value: modelLabel } } : {},
795
+ ...hasSnapshotValue(modelClassName) ? {
796
+ modelClass: {
797
+ description: "Flow model class name",
798
+ value: modelClassName
799
+ }
800
+ } : {},
801
+ ...hasSnapshotValue(modelUid) ? { uid: { description: "Flow model uid", getVar: "ctx.model.uid", value: modelUid } } : {},
802
+ ...hasModelResourceValues ? {
803
+ resource: {
804
+ description: "Flow model resource",
805
+ getVar: "ctx.model.resource",
806
+ properties: modelResourceProps
807
+ }
808
+ } : {}
809
+ }
810
+ };
811
+ }
812
+ if (popupLike == null ? void 0 : popupLike.uid) {
813
+ envs.popup = {
814
+ description: "Current popup information",
815
+ getVar: "ctx.popup",
816
+ properties: {
817
+ uid: { description: "Popup uid", getVar: "ctx.popup.uid", value: popupLike.uid },
818
+ ...(popupLike == null ? void 0 : popupLike.record) ? { record: { description: "Popup record", getVar: "ctx.popup.record" } } : {},
819
+ ...(popupLike == null ? void 0 : popupLike.sourceRecord) ? { sourceRecord: { description: "Popup source record", getVar: "ctx.popup.sourceRecord" } } : {}
820
+ }
821
+ };
822
+ }
823
+ if (blockOwner) {
824
+ const blockLabel = pickLabel(blockOwner);
825
+ const blockUid = blockOwner.uid;
826
+ const blockModelClass = (_b = blockOwner.constructor) == null ? void 0 : _b.name;
827
+ const blockResourceProps = {};
828
+ let hasBlockResourceValues = false;
829
+ const blockCollectionName = blockResourceSnap.collectionName;
830
+ if (hasSnapshotValue(blockCollectionName)) {
831
+ blockResourceProps.collectionName = {
832
+ description: "Collection name",
833
+ getVar: `${blockResourceBaseExpr}.collectionName`,
834
+ value: blockCollectionName
835
+ };
836
+ hasBlockResourceValues = true;
837
+ }
838
+ const blockDataSourceKey = blockResourceSnap.dataSourceKey;
839
+ if (hasSnapshotValue(blockDataSourceKey)) {
840
+ blockResourceProps.dataSourceKey = {
841
+ description: "Data source key",
842
+ getVar: `${blockResourceBaseExpr}.dataSourceKey`,
843
+ value: blockDataSourceKey
844
+ };
845
+ hasBlockResourceValues = true;
846
+ }
847
+ const blockAssociationName = blockResourceSnap.associationName;
848
+ if (hasSnapshotValue(blockAssociationName)) {
849
+ blockResourceProps.associationName = {
850
+ description: "Association name",
851
+ getVar: `${blockResourceBaseExpr}.associationName`,
852
+ value: blockAssociationName
853
+ };
854
+ hasBlockResourceValues = true;
855
+ }
856
+ envs.block = {
857
+ description: "Current block information",
858
+ getVar: blockOwnerExpr,
859
+ properties: {
860
+ ...hasSnapshotValue(blockLabel) ? { label: { description: "Block label", value: blockLabel } } : {},
861
+ ...hasSnapshotValue(blockModelClass) ? { modelClass: { description: "Block model class name", value: blockModelClass } } : {},
862
+ ...hasSnapshotValue(blockUid) ? { uid: { description: "Block uid", getVar: `${blockOwnerExpr}.uid`, value: blockUid } } : {},
863
+ ...hasBlockResourceValues ? {
864
+ resource: {
865
+ description: "Block resource",
866
+ getVar: blockResourceBaseExpr,
867
+ properties: blockResourceProps
868
+ }
869
+ } : {}
870
+ }
871
+ };
872
+ }
873
+ const viewUid = (() => {
874
+ const popupUid = popupLike == null ? void 0 : popupLike.uid;
875
+ if (hasSnapshotValue(popupUid)) return String(popupUid).trim();
876
+ const v = inputArgs == null ? void 0 : inputArgs.viewUid;
877
+ if (hasSnapshotValue(v)) return String(v).trim();
878
+ return void 0;
879
+ })();
880
+ const engine = getMaybe(() => evalCtx.engine);
881
+ const viewModel = viewUid ? engine == null ? void 0 : engine.getModel(viewUid, true) : void 0;
882
+ const isBlockModelInstance = /* @__PURE__ */ __name((m) => {
883
+ var _a2;
884
+ return ((_a2 = m.context) == null ? void 0 : _a2.blockModel) === m;
885
+ }, "isBlockModelInstance");
886
+ if (viewModel) {
887
+ const queue = [viewModel];
888
+ const blocks = [];
889
+ for (let i = 0; i < queue.length; i++) {
890
+ const m = queue[i];
891
+ if (isBlockModelInstance(m)) {
892
+ const modelClass = ((_c = m.constructor) == null ? void 0 : _c.name) || m.uid;
893
+ const label = pickLabel(m) || modelClass || m.uid;
894
+ const resSnap = getResourceSnapshot(m.resource);
895
+ const resource = {};
896
+ if (hasSnapshotValue(resSnap.dataSourceKey)) resource.dataSourceKey = resSnap.dataSourceKey;
897
+ if (hasSnapshotValue(resSnap.collectionName)) resource.collectionName = resSnap.collectionName;
898
+ if (hasSnapshotValue(resSnap.associationName)) resource.associationName = resSnap.associationName;
899
+ const block = {
900
+ uid: m.uid,
901
+ label,
902
+ modelClass,
903
+ ...Object.keys(resource).length > 0 ? { resource } : {}
904
+ };
905
+ blocks.push(block);
906
+ }
907
+ const subModels = m.subModels;
908
+ if (subModels && typeof subModels === "object") {
909
+ for (const v of Object.values(subModels)) {
910
+ if (!v) continue;
911
+ if (Array.isArray(v)) queue.push(...v);
912
+ else queue.push(v);
913
+ }
914
+ }
915
+ }
916
+ if (blocks.length) {
917
+ envs.currentViewBlocks = {
918
+ description: "Current view blocks",
919
+ value: blocks
920
+ };
921
+ }
922
+ }
923
+ return envs;
924
+ }
925
+ /**
926
+ * 获取变量结构信息(来源于 PropertyMeta)。
927
+ *
928
+ * - 返回静态 plain object(不包含函数)
929
+ * - 支持 maxDepth(默认 3)与 path 剪裁
930
+ */
931
+ async getVarInfos(options = {}) {
932
+ const maxDepthRaw = options.maxDepth ?? 3;
933
+ const maxDepth = Number.isFinite(maxDepthRaw) ? Math.max(1, Math.floor(maxDepthRaw)) : 3;
934
+ const version = "v1";
935
+ const evalCtx = this.createProxy();
936
+ const isPrivateKey = /* @__PURE__ */ __name((key) => typeof key === "string" && key.startsWith("_"), "isPrivateKey");
937
+ const isPromiseLike = /* @__PURE__ */ __name((v) => !!v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function", "isPromiseLike");
938
+ const metaFactoryCache = /* @__PURE__ */ new WeakMap();
939
+ const resolveMetaOrFactory = /* @__PURE__ */ __name(async (meta) => {
940
+ if (!meta) return void 0;
941
+ if (typeof meta !== "function") return meta;
942
+ let pending = metaFactoryCache.get(meta);
943
+ if (!pending) {
944
+ pending = (async () => {
945
+ const v = meta.call(evalCtx, evalCtx);
946
+ const resolved2 = isPromiseLike(v) ? await v : v;
947
+ return resolved2 || null;
948
+ })();
949
+ metaFactoryCache.set(meta, pending);
950
+ }
951
+ const resolved = await pending;
952
+ return resolved || void 0;
953
+ }, "resolveMetaOrFactory");
954
+ const buildEnvs = /* @__PURE__ */ __name(async () => {
955
+ var _a, _b, _c;
956
+ const envs = {};
957
+ const getMaybe = /* @__PURE__ */ __name((fn) => {
958
+ try {
959
+ return fn();
960
+ } catch (_2) {
961
+ return void 0;
962
+ }
963
+ }, "getMaybe");
964
+ const hasSnapshotValue = /* @__PURE__ */ __name((v) => {
965
+ if (typeof v === "undefined" || v === null) return false;
966
+ if (typeof v === "string") return v.trim().length > 0;
967
+ if (Array.isArray(v)) return v.length > 0;
968
+ return true;
969
+ }, "hasSnapshotValue");
970
+ const getResourceSnapshot = /* @__PURE__ */ __name((res) => {
971
+ var _a2, _b2, _c2, _d, _e;
972
+ const out2 = {};
973
+ if (!res) return out2;
974
+ const r = res;
975
+ for (const k of [
976
+ "dataSourceKey",
977
+ "collectionName",
978
+ "associationName",
979
+ "filterByTk",
980
+ "sourceId"
981
+ ]) {
982
+ const v = r == null ? void 0 : r[k];
983
+ if (hasSnapshotValue(v)) out2[k] = v;
984
+ }
985
+ if (!("dataSourceKey" in out2)) {
986
+ const v = (_a2 = r.getDataSourceKey) == null ? void 0 : _a2.call(r);
987
+ if (hasSnapshotValue(v)) out2.dataSourceKey = v;
988
+ }
989
+ if (!("filterByTk" in out2)) {
990
+ const v = (_b2 = r.getFilterByTk) == null ? void 0 : _b2.call(r);
991
+ if (hasSnapshotValue(v)) out2.filterByTk = v;
992
+ }
993
+ if (!("filterByTk" in out2)) {
994
+ const v = (_c2 = r.getMeta) == null ? void 0 : _c2.call(r, "currentFilterByTk");
995
+ if (hasSnapshotValue(v)) out2.filterByTk = v;
996
+ }
997
+ if (!("sourceId" in out2)) {
998
+ const v = (_d = r.getSourceId) == null ? void 0 : _d.call(r);
999
+ if (hasSnapshotValue(v)) out2.sourceId = v;
1000
+ }
1001
+ if (!("collectionName" in out2) || !("associationName" in out2)) {
1002
+ const rn = (_e = r.getResourceName) == null ? void 0 : _e.call(r);
1003
+ const resourceName = typeof rn === "string" ? rn.trim() : "";
1004
+ if (resourceName) {
1005
+ const parts = resourceName.split(".").map((x) => x.trim()).filter(Boolean);
1006
+ if (parts.length === 1) {
1007
+ if (!("collectionName" in out2)) out2.collectionName = parts[0];
1008
+ } else if (parts.length >= 2) {
1009
+ if (!("collectionName" in out2)) out2.collectionName = parts[0];
1010
+ if (!("associationName" in out2)) out2.associationName = parts.slice(1).join(".");
1011
+ }
1012
+ }
1013
+ }
1014
+ return out2;
1015
+ }, "getResourceSnapshot");
1016
+ const popup = await (async () => {
1017
+ try {
1018
+ const raw = evalCtx.popup;
1019
+ return isPromiseLike(raw) ? await raw : raw;
1020
+ } catch (_2) {
1021
+ return void 0;
1022
+ }
1023
+ })();
1024
+ const popupLike = popup;
1025
+ const model = getMaybe(() => evalCtx.model);
1026
+ const blockModel = getMaybe(() => evalCtx.blockModel);
1027
+ const inputArgs = getMaybe(() => {
1028
+ var _a2;
1029
+ return (_a2 = evalCtx.view) == null ? void 0 : _a2.inputArgs;
1030
+ });
1031
+ const ctxResource = getMaybe(() => evalCtx.resource);
1032
+ const popupResource = popupLike == null ? void 0 : popupLike.resource;
1033
+ const popupResourceSnap = getResourceSnapshot(popupResource);
1034
+ const blockOwner = blockModel;
1035
+ const blockOwnerExpr = blockModel ? "ctx.blockModel" : void 0;
1036
+ const blockResourceBaseExpr = blockOwnerExpr ? `${blockOwnerExpr}.resource` : void 0;
1037
+ const blockResource = blockOwner == null ? void 0 : blockOwner.resource;
1038
+ const blockResourceSnap = getResourceSnapshot(blockResource);
1039
+ const inputArgsSnap = getResourceSnapshot(inputArgs);
1040
+ const ctxResourceSnap = getResourceSnapshot(ctxResource);
1041
+ const pickWithGetVar = /* @__PURE__ */ __name((pairs) => {
1042
+ for (const p of pairs) {
1043
+ if (hasSnapshotValue(p.value)) return { value: p.value, getVar: p.getVar };
1044
+ }
1045
+ return void 0;
1046
+ }, "pickWithGetVar");
1047
+ const hasAnyResourceValuesIn = /* @__PURE__ */ __name((snap) => hasSnapshotValue(snap.collectionName) || hasSnapshotValue(snap.dataSourceKey) || hasSnapshotValue(snap.associationName), "hasAnyResourceValuesIn");
1048
+ const resourceBaseExpr = hasAnyResourceValuesIn(popupResourceSnap) ? "ctx.popup.resource" : hasAnyResourceValuesIn(blockResourceSnap) ? blockResourceBaseExpr : hasAnyResourceValuesIn(inputArgsSnap) ? "ctx.view.inputArgs" : hasAnyResourceValuesIn(ctxResourceSnap) ? "ctx.resource" : void 0;
1049
+ const collectionNamePick = pickWithGetVar([
1050
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.collectionName, getVar: "ctx.popup.resource.collectionName" },
1051
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.collectionName, getVar: `${blockResourceBaseExpr}.collectionName` },
1052
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.collectionName, getVar: "ctx.view.inputArgs.collectionName" },
1053
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.collectionName, getVar: "ctx.resource.collectionName" }
1054
+ ]);
1055
+ const dataSourceKeyPick = pickWithGetVar([
1056
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.dataSourceKey, getVar: "ctx.popup.resource.dataSourceKey" },
1057
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.dataSourceKey, getVar: `${blockResourceBaseExpr}.dataSourceKey` },
1058
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.dataSourceKey, getVar: "ctx.view.inputArgs.dataSourceKey" },
1059
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.dataSourceKey, getVar: "ctx.resource.dataSourceKey" }
1060
+ ]);
1061
+ const associationNamePick = pickWithGetVar([
1062
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.associationName, getVar: "ctx.popup.resource.associationName" },
1063
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.associationName, getVar: `${blockResourceBaseExpr}.associationName` },
1064
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.associationName, getVar: "ctx.view.inputArgs.associationName" },
1065
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.associationName, getVar: "ctx.resource.associationName" }
1066
+ ]);
1067
+ const filterByTkPick = pickWithGetVar([
1068
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.filterByTk, getVar: "ctx.popup.resource.filterByTk" },
1069
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.filterByTk, getVar: `${blockResourceBaseExpr}.filterByTk` },
1070
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.filterByTk, getVar: "ctx.view.inputArgs.filterByTk" },
1071
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.filterByTk, getVar: "ctx.resource.filterByTk" }
1072
+ ]);
1073
+ const sourceIdPick = pickWithGetVar([
1074
+ { value: popupResourceSnap == null ? void 0 : popupResourceSnap.sourceId, getVar: "ctx.popup.resource.sourceId" },
1075
+ { value: blockResourceSnap == null ? void 0 : blockResourceSnap.sourceId, getVar: `${blockResourceBaseExpr}.sourceId` },
1076
+ { value: inputArgsSnap == null ? void 0 : inputArgsSnap.sourceId, getVar: "ctx.view.inputArgs.sourceId" },
1077
+ { value: ctxResourceSnap == null ? void 0 : ctxResourceSnap.sourceId, getVar: "ctx.resource.sourceId" }
1078
+ ]);
1079
+ const resourceProps = {};
1080
+ let hasResourceValues = false;
1081
+ const collectionNameValue = collectionNamePick == null ? void 0 : collectionNamePick.value;
1082
+ if (hasSnapshotValue(collectionNameValue)) {
1083
+ resourceProps.collectionName = {
1084
+ description: "Collection name",
1085
+ getVar: (collectionNamePick == null ? void 0 : collectionNamePick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.collectionName` : void 0),
1086
+ value: collectionNameValue
1087
+ };
1088
+ hasResourceValues = true;
1089
+ }
1090
+ const dataSourceKeyValue = dataSourceKeyPick == null ? void 0 : dataSourceKeyPick.value;
1091
+ if (hasSnapshotValue(dataSourceKeyValue)) {
1092
+ resourceProps.dataSourceKey = {
1093
+ description: "Data source key",
1094
+ getVar: (dataSourceKeyPick == null ? void 0 : dataSourceKeyPick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.dataSourceKey` : void 0),
1095
+ value: dataSourceKeyValue
1096
+ };
1097
+ hasResourceValues = true;
1098
+ }
1099
+ const associationNameValue = associationNamePick == null ? void 0 : associationNamePick.value;
1100
+ if (hasSnapshotValue(associationNameValue)) {
1101
+ resourceProps.associationName = {
1102
+ description: "Association name",
1103
+ getVar: (associationNamePick == null ? void 0 : associationNamePick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.associationName` : void 0),
1104
+ value: associationNameValue
1105
+ };
1106
+ hasResourceValues = true;
1107
+ }
1108
+ if (hasResourceValues) {
1109
+ if (hasSnapshotValue(filterByTkPick == null ? void 0 : filterByTkPick.value)) {
1110
+ resourceProps.filterByTk = {
1111
+ description: "Record filterByTk",
1112
+ getVar: (filterByTkPick == null ? void 0 : filterByTkPick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.filterByTk` : void 0)
1113
+ };
1114
+ }
1115
+ if (hasSnapshotValue(sourceIdPick == null ? void 0 : sourceIdPick.value)) {
1116
+ resourceProps.sourceId = {
1117
+ description: "Source record ID (sourceId)",
1118
+ getVar: (sourceIdPick == null ? void 0 : sourceIdPick.getVar) || (resourceBaseExpr ? `${resourceBaseExpr}.sourceId` : void 0)
1119
+ };
1120
+ }
1121
+ envs.resource = {
1122
+ description: "Resource information",
1123
+ getVar: resourceBaseExpr,
1124
+ properties: resourceProps
1125
+ };
1126
+ }
1127
+ if (hasSnapshotValue(filterByTkPick == null ? void 0 : filterByTkPick.value)) {
1128
+ envs.record = {
1129
+ description: "Current record",
1130
+ getVar: "ctx.record"
1131
+ };
1132
+ }
1133
+ const pickLabel = /* @__PURE__ */ __name((obj) => {
1134
+ var _a2, _b2;
1135
+ try {
1136
+ const t = obj == null ? void 0 : obj.title;
1137
+ if (typeof t === "string" && t.trim()) return t;
1138
+ } catch (_2) {
1139
+ }
1140
+ try {
1141
+ const label = (_b2 = (_a2 = obj == null ? void 0 : obj.constructor) == null ? void 0 : _a2.meta) == null ? void 0 : _b2.label;
1142
+ if (typeof label === "string" && label.trim()) return label;
1143
+ } catch (_2) {
1144
+ }
1145
+ return void 0;
1146
+ }, "pickLabel");
1147
+ if (model) {
1148
+ const modelLabel = pickLabel(model);
1149
+ const modelUid = model.uid;
1150
+ const modelClassName = (_a = model.constructor) == null ? void 0 : _a.name;
1151
+ const modelResourceSnap = getResourceSnapshot(model.resource);
1152
+ const modelResourceProps = {};
1153
+ let hasModelResourceValues = false;
1154
+ const modelCollectionName = modelResourceSnap.collectionName;
1155
+ if (hasSnapshotValue(modelCollectionName)) {
1156
+ modelResourceProps.collectionName = {
1157
+ description: "Collection name",
1158
+ getVar: "ctx.model.resource.collectionName",
1159
+ value: modelCollectionName
1160
+ };
1161
+ hasModelResourceValues = true;
1162
+ }
1163
+ const modelDataSourceKey = modelResourceSnap.dataSourceKey;
1164
+ if (hasSnapshotValue(modelDataSourceKey)) {
1165
+ modelResourceProps.dataSourceKey = {
1166
+ description: "Data source key",
1167
+ getVar: "ctx.model.resource.dataSourceKey",
1168
+ value: modelDataSourceKey
1169
+ };
1170
+ hasModelResourceValues = true;
1171
+ }
1172
+ const modelAssociationName = modelResourceSnap.associationName;
1173
+ if (hasSnapshotValue(modelAssociationName)) {
1174
+ modelResourceProps.associationName = {
1175
+ description: "Association name",
1176
+ getVar: "ctx.model.resource.associationName",
1177
+ value: modelAssociationName
1178
+ };
1179
+ hasModelResourceValues = true;
1180
+ }
1181
+ envs.flowModel = {
1182
+ description: "Current FlowModel information",
1183
+ getVar: "ctx.model",
1184
+ properties: {
1185
+ ...hasSnapshotValue(modelLabel) ? { label: { description: "Flow model label", value: modelLabel } } : {},
1186
+ ...hasSnapshotValue(modelClassName) ? {
1187
+ modelClass: {
1188
+ description: "Flow model class name",
1189
+ value: modelClassName
1190
+ }
1191
+ } : {},
1192
+ ...hasSnapshotValue(modelUid) ? { uid: { description: "Flow model uid", getVar: "ctx.model.uid", value: modelUid } } : {},
1193
+ ...hasModelResourceValues ? {
1194
+ resource: {
1195
+ description: "Resource information",
1196
+ getVar: "ctx.model.resource",
1197
+ properties: {
1198
+ ...modelResourceProps,
1199
+ ...hasSnapshotValue(modelResourceSnap == null ? void 0 : modelResourceSnap.filterByTk) ? {
1200
+ filterByTk: {
1201
+ description: "Record filterByTk",
1202
+ getVar: "ctx.model.resource.filterByTk"
1203
+ }
1204
+ } : {},
1205
+ ...hasSnapshotValue(modelResourceSnap == null ? void 0 : modelResourceSnap.sourceId) ? {
1206
+ sourceId: {
1207
+ description: "Source record ID (sourceId)",
1208
+ getVar: "ctx.model.resource.sourceId"
1209
+ }
1210
+ } : {}
1211
+ }
1212
+ }
1213
+ } : {}
1214
+ }
1215
+ };
1216
+ }
1217
+ if (blockOwner && blockOwnerExpr) {
1218
+ const blockLabel = pickLabel(blockOwner);
1219
+ const blockUid = blockOwner.uid;
1220
+ const blockModelClass = (_b = blockOwner.constructor) == null ? void 0 : _b.name;
1221
+ const blockResourceProps = {};
1222
+ let hasBlockResourceValues = false;
1223
+ const blockCollectionName = blockResourceSnap.collectionName;
1224
+ if (hasSnapshotValue(blockCollectionName)) {
1225
+ blockResourceProps.collectionName = {
1226
+ description: "Collection name",
1227
+ getVar: `${blockResourceBaseExpr}.collectionName`,
1228
+ value: blockCollectionName
1229
+ };
1230
+ hasBlockResourceValues = true;
1231
+ }
1232
+ const blockDataSourceKey = blockResourceSnap.dataSourceKey;
1233
+ if (hasSnapshotValue(blockDataSourceKey)) {
1234
+ blockResourceProps.dataSourceKey = {
1235
+ description: "Data source key",
1236
+ getVar: `${blockResourceBaseExpr}.dataSourceKey`,
1237
+ value: blockDataSourceKey
1238
+ };
1239
+ hasBlockResourceValues = true;
1240
+ }
1241
+ const blockAssociationName = blockResourceSnap.associationName;
1242
+ if (hasSnapshotValue(blockAssociationName)) {
1243
+ blockResourceProps.associationName = {
1244
+ description: "Association name",
1245
+ getVar: `${blockResourceBaseExpr}.associationName`,
1246
+ value: blockAssociationName
1247
+ };
1248
+ hasBlockResourceValues = true;
1249
+ }
1250
+ envs.block = {
1251
+ description: "Current block information",
1252
+ getVar: "ctx.blockModel",
1253
+ properties: {
1254
+ ...hasSnapshotValue(blockLabel) ? { label: { description: "Block label", value: blockLabel } } : {},
1255
+ ...hasSnapshotValue(blockModelClass) ? {
1256
+ modelClass: {
1257
+ description: "Block model class name",
1258
+ value: blockModelClass
1259
+ }
1260
+ } : {},
1261
+ ...hasSnapshotValue(blockUid) ? {
1262
+ uid: {
1263
+ description: "Block uid",
1264
+ getVar: "ctx.blockModel.uid",
1265
+ value: blockUid
1266
+ }
1267
+ } : {},
1268
+ ...hasBlockResourceValues ? {
1269
+ resource: {
1270
+ description: "Resource information",
1271
+ getVar: "ctx.blockModel.resource",
1272
+ properties: {
1273
+ ...blockResourceProps,
1274
+ ...hasSnapshotValue(blockResourceSnap == null ? void 0 : blockResourceSnap.filterByTk) ? {
1275
+ filterByTk: {
1276
+ description: "Record filterByTk",
1277
+ getVar: "ctx.blockModel.resource.filterByTk"
1278
+ }
1279
+ } : {},
1280
+ ...hasSnapshotValue(blockResourceSnap == null ? void 0 : blockResourceSnap.sourceId) ? {
1281
+ sourceId: {
1282
+ description: "Source record ID (sourceId)",
1283
+ getVar: "ctx.blockModel.resource.sourceId"
1284
+ }
1285
+ } : {}
1286
+ }
1287
+ }
1288
+ } : {}
1289
+ }
1290
+ };
1291
+ }
1292
+ if (popupLike == null ? void 0 : popupLike.uid) {
1293
+ const popupUid = popupLike.uid;
1294
+ const popupResourceProps = {};
1295
+ let hasPopupResourceValues = false;
1296
+ const popupCollectionName = popupResourceSnap.collectionName;
1297
+ if (hasSnapshotValue(popupCollectionName)) {
1298
+ popupResourceProps.collectionName = {
1299
+ description: "Collection name",
1300
+ getVar: "ctx.popup.resource.collectionName",
1301
+ value: popupCollectionName
1302
+ };
1303
+ hasPopupResourceValues = true;
1304
+ }
1305
+ const popupDataSourceKey = popupResourceSnap.dataSourceKey;
1306
+ if (hasSnapshotValue(popupDataSourceKey)) {
1307
+ popupResourceProps.dataSourceKey = {
1308
+ description: "Data source key",
1309
+ getVar: "ctx.popup.resource.dataSourceKey",
1310
+ value: popupDataSourceKey
1311
+ };
1312
+ hasPopupResourceValues = true;
1313
+ }
1314
+ const popupAssociationName = popupResourceSnap.associationName;
1315
+ if (hasSnapshotValue(popupAssociationName)) {
1316
+ popupResourceProps.associationName = {
1317
+ description: "Association name",
1318
+ getVar: "ctx.popup.resource.associationName",
1319
+ value: popupAssociationName
1320
+ };
1321
+ hasPopupResourceValues = true;
1322
+ }
1323
+ envs.popup = {
1324
+ description: "Current popup information",
1325
+ getVar: "ctx.popup",
1326
+ properties: {
1327
+ uid: { description: "Popup uid", getVar: "ctx.popup.uid", value: popupUid },
1328
+ record: {
1329
+ description: "Current popup record (object).",
1330
+ getVar: "ctx.popup.record"
1331
+ },
1332
+ sourceRecord: {
1333
+ description: "Current popup sourceRecord (object).",
1334
+ getVar: "ctx.popup.sourceRecord"
1335
+ },
1336
+ parent: {
1337
+ description: "Parent popup info (object).",
1338
+ getVar: "ctx.popup.parent"
1339
+ },
1340
+ ...hasPopupResourceValues ? {
1341
+ resource: {
1342
+ description: "Resource information",
1343
+ getVar: "ctx.popup.resource",
1344
+ properties: {
1345
+ ...popupResourceProps,
1346
+ ...hasSnapshotValue(popupResourceSnap == null ? void 0 : popupResourceSnap.filterByTk) ? {
1347
+ filterByTk: {
1348
+ description: "Record filterByTk",
1349
+ getVar: "ctx.popup.resource.filterByTk"
1350
+ }
1351
+ } : {},
1352
+ ...hasSnapshotValue(popupResourceSnap == null ? void 0 : popupResourceSnap.sourceId) ? {
1353
+ sourceId: {
1354
+ description: "Source record ID (sourceId)",
1355
+ getVar: "ctx.popup.resource.sourceId"
1356
+ }
1357
+ } : {}
1358
+ }
1359
+ }
1360
+ } : {}
1361
+ }
1362
+ };
1363
+ }
1364
+ const viewUid = (() => {
1365
+ const popupUid = popupLike == null ? void 0 : popupLike.uid;
1366
+ if (hasSnapshotValue(popupUid)) return popupUid.trim();
1367
+ const v = inputArgs == null ? void 0 : inputArgs.viewUid;
1368
+ if (hasSnapshotValue(v)) return v.trim();
1369
+ return void 0;
1370
+ })();
1371
+ const engine = getMaybe(() => evalCtx.engine);
1372
+ const viewModel = viewUid ? engine == null ? void 0 : engine.getModel(viewUid, true) : void 0;
1373
+ const isBlockModelInstance = /* @__PURE__ */ __name((m) => {
1374
+ var _a2;
1375
+ return ((_a2 = m.context) == null ? void 0 : _a2.blockModel) === m;
1376
+ }, "isBlockModelInstance");
1377
+ if (viewModel) {
1378
+ const queue = [viewModel];
1379
+ const blocks = [];
1380
+ for (let i = 0; i < queue.length; i++) {
1381
+ const m = queue[i];
1382
+ if (isBlockModelInstance(m)) {
1383
+ const modelClass = ((_c = m.constructor) == null ? void 0 : _c.name) || m.uid;
1384
+ const label = pickLabel(m) || modelClass || m.uid;
1385
+ const resSnap = getResourceSnapshot(m.resource);
1386
+ const resource = {};
1387
+ if (hasSnapshotValue(resSnap.dataSourceKey)) resource.dataSourceKey = resSnap.dataSourceKey;
1388
+ if (hasSnapshotValue(resSnap.collectionName)) resource.collectionName = resSnap.collectionName;
1389
+ if (hasSnapshotValue(resSnap.associationName)) resource.associationName = resSnap.associationName;
1390
+ const block = {
1391
+ uid: m.uid,
1392
+ label,
1393
+ modelClass,
1394
+ ...Object.keys(resource).length > 0 ? { resource } : {}
1395
+ };
1396
+ blocks.push(block);
1397
+ }
1398
+ const subModels = m.subModels;
1399
+ if (subModels && typeof subModels === "object") {
1400
+ for (const v of Object.values(subModels)) {
1401
+ if (!v) continue;
1402
+ if (Array.isArray(v)) queue.push(...v);
1403
+ else queue.push(v);
1404
+ }
1405
+ }
1406
+ }
1407
+ envs.currentViewBlocks = {
1408
+ description: "Current view blocks",
1409
+ value: blocks
1410
+ };
1411
+ }
1412
+ return envs;
1413
+ }, "buildEnvs");
1414
+ const normalizePath = /* @__PURE__ */ __name((raw) => {
1415
+ if (typeof raw !== "string") return void 0;
1416
+ const s = raw.trim();
1417
+ if (!s) return void 0;
1418
+ const extracted = (0, import_utils.extractPropertyPath)(s);
1419
+ if (Array.isArray(extracted) && extracted.length > 0) {
1420
+ return extracted.join(".");
1421
+ }
1422
+ if (s === "ctx") return "";
1423
+ if (s.startsWith("ctx.")) return s.slice(4).trim();
1424
+ return s;
1425
+ }, "normalizePath");
1426
+ const paths = (() => {
1427
+ const p = options.path;
1428
+ const list = typeof p === "string" ? [p] : Array.isArray(p) ? p : [];
1429
+ return list.map((x) => normalizePath(String(x))).filter((x) => typeof x === "string" && x.length > 0);
1430
+ })();
1431
+ const hasRootPath = (() => {
1432
+ const p = options.path;
1433
+ if (typeof p === "string") return normalizePath(p) === "";
1434
+ if (Array.isArray(p)) return p.some((x) => normalizePath(String(x)) === "");
1435
+ return false;
1436
+ })();
1437
+ const collectKeysDeep = /* @__PURE__ */ __name((ctx, out2, key, visited) => {
1438
+ if (!ctx || typeof ctx !== "object") return;
1439
+ if (visited.has(ctx)) return;
1440
+ visited.add(ctx);
1441
+ try {
1442
+ const bag = ctx[key];
1443
+ if (bag && typeof bag === "object") {
1444
+ for (const k of Object.keys(bag)) out2.add(k);
1445
+ }
1446
+ } catch (_2) {
1447
+ }
1448
+ try {
1449
+ const delegates = ctx._delegates;
1450
+ if (Array.isArray(delegates)) {
1451
+ for (const d of delegates) collectKeysDeep(d, out2, key, visited);
1452
+ }
1453
+ } catch (_2) {
1454
+ }
1455
+ }, "collectKeysDeep");
1456
+ const getRunJSDoc = /* @__PURE__ */ __name(() => {
1457
+ var _a, _b, _c, _d, _e;
1458
+ const modelClass = (0, import_registry.getModelClassName)(this);
1459
+ const Ctor = import_registry.RunJSContextRegistry.resolve(version, modelClass) || import_registry.RunJSContextRegistry.resolve(version, "*");
1460
+ if (!Ctor) return {};
1461
+ const locale = ((_b = (_a = this == null ? void 0 : this.api) == null ? void 0 : _a.auth) == null ? void 0 : _b.locale) || ((_c = this == null ? void 0 : this.i18n) == null ? void 0 : _c.language) || (this == null ? void 0 : this.locale);
1462
+ try {
1463
+ if ((_d = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _d.length) {
1464
+ return Ctor.getDoc(locale) || {};
1465
+ }
1466
+ return ((_e = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _e.call(Ctor)) || {};
1467
+ } catch (_2) {
1468
+ return {};
1469
+ }
1470
+ }, "getRunJSDoc");
1471
+ const doc = getRunJSDoc();
1472
+ const docMethods = __isPlainObject(doc == null ? void 0 : doc.methods) ? doc.methods : {};
1473
+ const docProps = __isPlainObject(doc == null ? void 0 : doc.properties) ? doc.properties : {};
1474
+ const toDocObject = /* @__PURE__ */ __name((node) => {
1475
+ if (typeof node === "string") return { description: node };
1476
+ if (__isPlainObject(node)) return node;
1477
+ return void 0;
1478
+ }, "toDocObject");
1479
+ const evalBool = /* @__PURE__ */ __name(async (raw, call) => {
1480
+ if (typeof raw === "undefined") return void 0;
1481
+ if (typeof raw === "boolean") return raw;
1482
+ if (typeof raw === "function") {
1483
+ try {
1484
+ const v = call(raw);
1485
+ return isPromiseLike(v) ? !!await v : !!v;
1486
+ } catch (_2) {
1487
+ return false;
1488
+ }
1489
+ }
1490
+ return !!raw;
1491
+ }, "evalBool");
1492
+ const evalString = /* @__PURE__ */ __name(async (raw, call) => {
1493
+ if (typeof raw === "undefined" || raw === null) return void 0;
1494
+ if (typeof raw === "string") return raw;
1495
+ if (typeof raw === "function") {
1496
+ try {
1497
+ const v = call(raw);
1498
+ const resolved = isPromiseLike(v) ? await v : v;
1499
+ if (typeof resolved === "string") return resolved;
1500
+ return typeof resolved === "undefined" || resolved === null ? void 0 : String(resolved);
1501
+ } catch (_2) {
1502
+ return void 0;
1503
+ }
1504
+ }
1505
+ return String(raw);
1506
+ }, "evalString");
1507
+ const evalRunJSHidden = /* @__PURE__ */ __name(async (raw) => {
1508
+ let hideSelf = false;
1509
+ let list = [];
1510
+ try {
1511
+ if (typeof raw === "boolean") hideSelf = raw;
1512
+ else if (Array.isArray(raw)) list = raw;
1513
+ else if (typeof raw === "function") {
1514
+ const v = raw(evalCtx);
1515
+ const resolved = isPromiseLike(v) ? await v : v;
1516
+ if (typeof resolved === "boolean") hideSelf = resolved;
1517
+ else if (Array.isArray(resolved)) list = resolved;
1518
+ }
1519
+ } catch (_2) {
1520
+ hideSelf = false;
1521
+ list = [];
1522
+ }
1523
+ const hideSubpaths = [];
1524
+ if (Array.isArray(list)) {
1525
+ for (const p of list) {
1526
+ if (typeof p !== "string") continue;
1527
+ const s = p.trim();
1528
+ if (!s) continue;
1529
+ if (s === "ctx" || s.startsWith("ctx.")) continue;
1530
+ if (/\s/.test(s)) continue;
1531
+ hideSubpaths.push(s);
1532
+ }
1533
+ }
1534
+ return { hideSelf: !!hideSelf, hideSubpaths };
1535
+ }, "evalRunJSHidden");
1536
+ const isHiddenByPrefixes = /* @__PURE__ */ __name((path, hiddenPrefixes) => {
1537
+ if (!path) return false;
1538
+ const parts = path.split(".").filter(Boolean);
1539
+ while (parts.length) {
1540
+ if (hiddenPrefixes.has(parts.join("."))) return true;
1541
+ parts.pop();
1542
+ }
1543
+ return false;
1544
+ }, "isHiddenByPrefixes");
1545
+ const pickMethodInfo = /* @__PURE__ */ __name((obj) => {
1546
+ const src = toDocObject(obj);
1547
+ if (!src) return {};
1548
+ const out2 = {};
1549
+ for (const k of ["description", "examples", "completion", "ref", "params", "returns"]) {
1550
+ const v = src[k];
1551
+ if (typeof v !== "undefined") out2[k] = v;
1552
+ }
1553
+ if (Array.isArray(out2.examples)) {
1554
+ out2.examples = out2.examples.filter((x) => typeof x === "string" && x.trim());
1555
+ }
1556
+ return out2;
1557
+ }, "pickMethodInfo");
1558
+ const pickPropertyInfo = /* @__PURE__ */ __name((obj) => {
1559
+ const src = toDocObject(obj);
1560
+ if (!src) return {};
1561
+ const out2 = {};
1562
+ for (const k of [
1563
+ "title",
1564
+ "type",
1565
+ "interface",
1566
+ "description",
1567
+ "examples",
1568
+ "completion",
1569
+ "ref",
1570
+ "params",
1571
+ "returns"
1572
+ ]) {
1573
+ const v = src[k];
1574
+ if (typeof v !== "undefined") out2[k] = v;
1575
+ }
1576
+ if (Array.isArray(out2.examples)) {
1577
+ out2.examples = out2.examples.filter((x) => typeof x === "string" && x.trim());
1578
+ }
1579
+ return out2;
1580
+ }, "pickPropertyInfo");
1581
+ const getMethodInfoFromChain = /* @__PURE__ */ __name((name) => {
1582
+ const visited = /* @__PURE__ */ new WeakSet();
1583
+ const walk = /* @__PURE__ */ __name((ctx) => {
1584
+ var _a;
1585
+ if (!ctx || typeof ctx !== "object") return void 0;
1586
+ if (visited.has(ctx)) return void 0;
1587
+ visited.add(ctx);
1588
+ if (Object.prototype.hasOwnProperty.call(ctx._methodInfos || {}, name)) {
1589
+ return (_a = ctx._methodInfos) == null ? void 0 : _a[name];
1590
+ }
1591
+ const delegates = ctx._delegates;
1592
+ if (Array.isArray(delegates)) {
1593
+ for (const d of delegates) {
1594
+ const found = walk(d);
1595
+ if (found) return found;
1596
+ }
1597
+ }
1598
+ return void 0;
1599
+ }, "walk");
1600
+ return walk(this);
1601
+ }, "getMethodInfoFromChain");
1602
+ const hasMethodInChain = /* @__PURE__ */ __name((name) => {
1603
+ const visited = /* @__PURE__ */ new WeakSet();
1604
+ const walk = /* @__PURE__ */ __name((ctx) => {
1605
+ if (!ctx || typeof ctx !== "object") return false;
1606
+ if (visited.has(ctx)) return false;
1607
+ visited.add(ctx);
1608
+ if (Object.prototype.hasOwnProperty.call(ctx._methods || {}, name)) return true;
1609
+ const delegates = ctx._delegates;
1610
+ if (Array.isArray(delegates)) {
1611
+ for (const d of delegates) {
1612
+ if (walk(d)) return true;
1613
+ }
1614
+ }
1615
+ return false;
1616
+ }, "walk");
1617
+ return walk(this);
1618
+ }, "hasMethodInChain");
1619
+ const buildMethodInfo = /* @__PURE__ */ __name(async (name) => {
1620
+ if (isPrivateKey(name)) return void 0;
1621
+ const docNode = docMethods[name];
1622
+ const info = getMethodInfoFromChain(name);
1623
+ const exists = typeof docNode !== "undefined" || typeof info !== "undefined" || hasMethodInChain(name);
1624
+ if (!exists) return void 0;
1625
+ const docObj = toDocObject(docNode);
1626
+ const docHidden = await evalBool(docObj == null ? void 0 : docObj.hidden, (fn) => fn(evalCtx));
1627
+ const infoHidden = await evalBool(info == null ? void 0 : info.hidden, (fn) => fn(evalCtx));
1628
+ if (!!docHidden || !!infoHidden) return void 0;
1629
+ const docDisabled = await evalBool(docObj == null ? void 0 : docObj.disabled, (fn) => fn(evalCtx));
1630
+ const docDisabledReason = await evalString(docObj == null ? void 0 : docObj.disabledReason, (fn) => fn(evalCtx));
1631
+ const infoDisabled = await evalBool(info == null ? void 0 : info.disabled, (fn) => fn(evalCtx));
1632
+ const infoDisabledReason = await evalString(info == null ? void 0 : info.disabledReason, (fn) => fn(evalCtx));
1633
+ const disabled = typeof infoDisabled !== "undefined" ? infoDisabled : docDisabled;
1634
+ const disabledReason = typeof infoDisabledReason !== "undefined" ? infoDisabledReason : docDisabledReason;
1635
+ let out2 = {};
1636
+ out2 = { ...out2, ...pickMethodInfo(docObj) };
1637
+ out2 = { ...out2, ...pickMethodInfo(info) };
1638
+ if (typeof disabled !== "undefined") out2.disabled = !!disabled;
1639
+ if (typeof disabledReason !== "undefined") out2.disabledReason = disabledReason;
1640
+ if (!Object.keys(out2).length) return void 0;
1641
+ out2.type = "function";
1642
+ return out2;
1643
+ }, "buildMethodInfo");
1644
+ const buildPropertyInfoFromNodes = /* @__PURE__ */ __name(async (args) => {
1645
+ const { docNode, metaNode, infoNode, depth, pathFromRoot, hiddenPrefixes } = args;
1646
+ const relPath = pathFromRoot.join(".");
1647
+ if (isHiddenByPrefixes(relPath, hiddenPrefixes)) return void 0;
1648
+ const docObj = toDocObject(docNode);
1649
+ const infoObj = toDocObject(infoNode);
1650
+ const docHiddenDecision = await evalRunJSHidden(docObj == null ? void 0 : docObj.hidden);
1651
+ if (docHiddenDecision.hideSelf) return void 0;
1652
+ const infoHiddenDecision = await evalRunJSHidden(infoObj == null ? void 0 : infoObj.hidden);
1653
+ if (infoHiddenDecision.hideSelf) return void 0;
1654
+ const resolvedMetaNode = await resolveMetaOrFactory(metaNode);
1655
+ const metaHidden = await evalBool(resolvedMetaNode == null ? void 0 : resolvedMetaNode.hidden, (fn) => fn.call(resolvedMetaNode, evalCtx));
1656
+ if (metaHidden) return void 0;
1657
+ const childHiddenPrefixes = new Set(hiddenPrefixes);
1658
+ for (const sub of [...docHiddenDecision.hideSubpaths, ...infoHiddenDecision.hideSubpaths]) {
1659
+ const normalized = sub.trim();
1660
+ if (!normalized) continue;
1661
+ const stripped = normalized === "ctx" ? "" : normalized.startsWith("ctx.") ? normalized.slice(4) : normalized;
1662
+ if (!stripped) continue;
1663
+ const abs = relPath ? `${relPath}.${stripped}` : stripped;
1664
+ childHiddenPrefixes.add(abs);
1665
+ }
1666
+ const docDisabled = await evalBool(docObj == null ? void 0 : docObj.disabled, (fn) => fn(evalCtx));
1667
+ const docDisabledReason = await evalString(docObj == null ? void 0 : docObj.disabledReason, (fn) => fn(evalCtx));
1668
+ const metaDisabled = await evalBool(
1669
+ resolvedMetaNode == null ? void 0 : resolvedMetaNode.disabled,
1670
+ (fn) => fn.call(resolvedMetaNode, evalCtx)
1671
+ );
1672
+ const metaDisabledReason = await evalString(
1673
+ resolvedMetaNode == null ? void 0 : resolvedMetaNode.disabledReason,
1674
+ (fn) => fn.call(resolvedMetaNode, evalCtx)
1675
+ );
1676
+ const infoDisabled = await evalBool(infoObj == null ? void 0 : infoObj.disabled, (fn) => fn(evalCtx));
1677
+ const infoDisabledReason = await evalString(infoObj == null ? void 0 : infoObj.disabledReason, (fn) => fn(evalCtx));
1678
+ const disabled = typeof infoDisabled !== "undefined" ? infoDisabled : typeof metaDisabled !== "undefined" ? metaDisabled : docDisabled;
1679
+ const disabledReason = typeof infoDisabledReason !== "undefined" ? infoDisabledReason : typeof metaDisabledReason !== "undefined" ? metaDisabledReason : docDisabledReason;
1680
+ let out2 = {};
1681
+ out2 = { ...out2, ...pickPropertyInfo(docObj) };
1682
+ out2 = { ...out2, ...pickPropertyInfo(resolvedMetaNode) };
1683
+ out2 = { ...out2, ...pickPropertyInfo(infoObj) };
1684
+ if (typeof disabled !== "undefined") out2.disabled = !!disabled;
1685
+ if (typeof disabledReason !== "undefined") out2.disabledReason = disabledReason;
1686
+ if (depth >= maxDepth) return Object.keys(out2).length ? out2 : void 0;
1687
+ const docChildren = __isPlainObject(docObj == null ? void 0 : docObj.properties) ? docObj.properties : void 0;
1688
+ let metaChildren;
1689
+ if (resolvedMetaNode == null ? void 0 : resolvedMetaNode.properties) {
1690
+ try {
1691
+ const props = resolvedMetaNode.properties;
1692
+ if (typeof props === "function") {
1693
+ const resolved = await props.call(resolvedMetaNode, evalCtx);
1694
+ resolvedMetaNode.properties = resolved;
1695
+ metaChildren = resolved;
1696
+ } else if (__isPlainObject(props)) {
1697
+ metaChildren = props;
1698
+ }
1699
+ } catch (_2) {
1700
+ metaChildren = void 0;
1701
+ }
1702
+ }
1703
+ let infoChildren;
1704
+ if (__isPlainObject(infoObj) && (infoObj == null ? void 0 : infoObj.properties)) {
1705
+ try {
1706
+ const props = infoObj.properties;
1707
+ if (typeof props === "function") {
1708
+ const resolved = await props.call(infoObj, evalCtx);
1709
+ infoObj.properties = resolved;
1710
+ infoChildren = resolved;
1711
+ } else if (__isPlainObject(props)) {
1712
+ infoChildren = props;
1713
+ }
1714
+ } catch (_2) {
1715
+ infoChildren = void 0;
1716
+ }
1717
+ }
1718
+ const keys = /* @__PURE__ */ new Set();
1719
+ if (docChildren) for (const k of Object.keys(docChildren)) keys.add(k);
1720
+ if (metaChildren) for (const k of Object.keys(metaChildren)) keys.add(k);
1721
+ if (infoChildren) for (const k of Object.keys(infoChildren)) keys.add(k);
1722
+ if (!keys.size) return Object.keys(out2).length ? out2 : void 0;
1723
+ const childrenOut = {};
1724
+ for (const k of keys) {
1725
+ if (isPrivateKey(k)) continue;
1726
+ const child = await buildPropertyInfoFromNodes({
1727
+ docNode: docChildren == null ? void 0 : docChildren[k],
1728
+ metaNode: metaChildren == null ? void 0 : metaChildren[k],
1729
+ infoNode: infoChildren == null ? void 0 : infoChildren[k],
1730
+ depth: depth + 1,
1731
+ pathFromRoot: [...pathFromRoot, k],
1732
+ hiddenPrefixes: childHiddenPrefixes
1733
+ });
1734
+ if (child) childrenOut[k] = child;
1735
+ }
1736
+ if (Object.keys(childrenOut).length) out2.properties = childrenOut;
1737
+ if (!Object.keys(out2).length) return void 0;
1738
+ return out2;
1739
+ }, "buildPropertyInfoFromNodes");
1740
+ const resolvePropertyMetaAtPath = /* @__PURE__ */ __name(async (segments) => {
1741
+ if (!segments.length) return void 0;
1742
+ const [first, ...rest] = segments;
1743
+ const opt = this.getPropertyOptions(first);
1744
+ if (!(opt == null ? void 0 : opt.meta)) return void 0;
1745
+ try {
1746
+ if (!rest.length) return opt.meta;
1747
+ let current = await resolveMetaOrFactory(opt.meta);
1748
+ if (!current) return void 0;
1749
+ for (let i = 0; i < rest.length; i++) {
1750
+ const key = rest[i];
1751
+ let props = current == null ? void 0 : current.properties;
1752
+ if (!props) return void 0;
1753
+ if (typeof props === "function") {
1754
+ const resolved = await props.call(current, evalCtx);
1755
+ current.properties = resolved;
1756
+ props = resolved;
1757
+ }
1758
+ if (!props || typeof props !== "object") return void 0;
1759
+ const next = props == null ? void 0 : props[key];
1760
+ if (!next) return void 0;
1761
+ if (i === rest.length - 1) return next;
1762
+ const resolvedNext = await resolveMetaOrFactory(next);
1763
+ if (!resolvedNext) return void 0;
1764
+ current = resolvedNext;
1765
+ }
1766
+ return void 0;
1767
+ } catch (_2) {
1768
+ return void 0;
1769
+ }
1770
+ }, "resolvePropertyMetaAtPath");
1771
+ const resolvePropertyInfoAtPath = /* @__PURE__ */ __name(async (segments) => {
1772
+ if (!segments.length) return void 0;
1773
+ const [first, ...rest] = segments;
1774
+ const opt = this.getPropertyOptions(first);
1775
+ if (!(opt == null ? void 0 : opt.info)) return void 0;
1776
+ try {
1777
+ let cur = typeof opt.info === "function" ? await opt.info.call(evalCtx, evalCtx) : opt.info;
1778
+ if (!rest.length) return cur;
1779
+ for (const key of rest) {
1780
+ const obj = toDocObject(cur);
1781
+ if (!__isPlainObject(obj)) return void 0;
1782
+ let props = obj == null ? void 0 : obj.properties;
1783
+ if (!props) return void 0;
1784
+ if (typeof props === "function") {
1785
+ const resolved = await props.call(obj, evalCtx);
1786
+ obj.properties = resolved;
1787
+ props = resolved;
1788
+ }
1789
+ if (!__isPlainObject(props)) return void 0;
1790
+ cur = props[key];
1791
+ }
1792
+ return cur;
1793
+ } catch (_2) {
1794
+ return void 0;
1795
+ }
1796
+ }, "resolvePropertyInfoAtPath");
1797
+ const resolveDocNodeAtPath = /* @__PURE__ */ __name((segments) => {
1798
+ if (!segments.length) return void 0;
1799
+ let cur = docProps[segments[0]];
1800
+ for (let i = 1; i < segments.length; i++) {
1801
+ const obj = toDocObject(cur);
1802
+ if (!__isPlainObject(obj)) return void 0;
1803
+ const props = obj.properties;
1804
+ if (!__isPlainObject(props)) return void 0;
1805
+ cur = props[segments[i]];
1806
+ }
1807
+ return cur;
1808
+ }, "resolveDocNodeAtPath");
1809
+ if (!hasRootPath && paths.length) {
1810
+ const out2 = {};
1811
+ for (const p of paths) {
1812
+ const segments = p.split(".").map((x) => x.trim()).filter(Boolean);
1813
+ if (segments.some((s) => isPrivateKey(s))) continue;
1814
+ if (!segments.length) continue;
1815
+ const metaNode = await resolvePropertyMetaAtPath(segments);
1816
+ const pi = await buildPropertyInfoFromNodes({
1817
+ docNode: void 0,
1818
+ metaNode,
1819
+ infoNode: void 0,
1820
+ depth: 1,
1821
+ pathFromRoot: [],
1822
+ hiddenPrefixes: /* @__PURE__ */ new Set()
1823
+ });
1824
+ if (pi) out2[p] = pi;
1825
+ }
1826
+ return out2;
1827
+ }
1828
+ const metaMap = this._getPropertiesMeta();
1829
+ const out = {};
1830
+ for (const [key, metaNode] of Object.entries(metaMap)) {
1831
+ if (isPrivateKey(key)) continue;
1832
+ const pi = await buildPropertyInfoFromNodes({
1833
+ docNode: void 0,
1834
+ metaNode,
1835
+ infoNode: void 0,
1836
+ depth: 1,
1837
+ pathFromRoot: [key],
1838
+ hiddenPrefixes: /* @__PURE__ */ new Set()
1839
+ });
1840
+ if (pi) out[key] = pi;
1841
+ }
1842
+ return out;
1843
+ }
318
1844
  _getPropertiesMeta() {
319
1845
  const metaMap = {};
320
1846
  for (const delegate of this._delegates) {
@@ -593,9 +2119,15 @@ toTreeNode_fn = /* @__PURE__ */ __name(function(name, metaOrFactory, paths = [na
593
2119
  const computeStateFromMeta = /* @__PURE__ */ __name((m) => {
594
2120
  if (!m) return { disabled: false, hidden: false };
595
2121
  const disabledVal = typeof m.disabled === "function" ? m.disabled() : m.disabled;
596
- const reason = typeof m.disabledReason === "function" ? m.disabledReason() : m.disabledReason;
2122
+ const reasonVal = typeof m.disabledReason === "function" ? m.disabledReason() : m.disabledReason;
597
2123
  const hiddenVal = typeof m.hidden === "function" ? m.hidden() : m.hidden;
598
- return { disabled: !!disabledVal, reason, hidden: !!hiddenVal };
2124
+ const disabledIsPromise = disabledVal && typeof disabledVal.then === "function";
2125
+ const reasonIsPromise = reasonVal && typeof reasonVal.then === "function";
2126
+ const hiddenIsPromise = hiddenVal && typeof hiddenVal.then === "function";
2127
+ const disabled = disabledIsPromise ? false : !!disabledVal;
2128
+ const reason = reasonIsPromise ? void 0 : reasonVal;
2129
+ const hidden = hiddenIsPromise ? false : !!hiddenVal;
2130
+ return { disabled, reason, hidden };
599
2131
  }, "computeStateFromMeta");
600
2132
  if (typeof metaOrFactory === "function") {
601
2133
  const initialTitle = name;
@@ -607,6 +2139,7 @@ toTreeNode_fn = /* @__PURE__ */ __name(function(name, metaOrFactory, paths = [na
607
2139
  type: "object",
608
2140
  // 初始类型
609
2141
  interface: void 0,
2142
+ options: void 0,
610
2143
  uiSchema: void 0,
611
2144
  paths,
612
2145
  parentTitles: parentTitles.length > 0 ? parentTitles : void 0,
@@ -635,6 +2168,7 @@ toTreeNode_fn = /* @__PURE__ */ __name(function(name, metaOrFactory, paths = [na
635
2168
  node.title = finalTitle;
636
2169
  node.type = meta == null ? void 0 : meta.type;
637
2170
  node.interface = meta == null ? void 0 : meta.interface;
2171
+ node.options = meta == null ? void 0 : meta.options;
638
2172
  node.uiSchema = meta == null ? void 0 : meta.uiSchema;
639
2173
  if (!(meta == null ? void 0 : meta.properties)) return [];
640
2174
  const childNodes = __privateMethod(this, _FlowContext_instances, createChildNodes_fn).call(this, meta.properties, paths, [...parentTitles, finalTitle], meta);
@@ -655,6 +2189,7 @@ toTreeNode_fn = /* @__PURE__ */ __name(function(name, metaOrFactory, paths = [na
655
2189
  title: nodeTitle,
656
2190
  type: metaOrFactory.type,
657
2191
  interface: metaOrFactory.interface,
2192
+ options: metaOrFactory.options,
658
2193
  uiSchema: metaOrFactory.uiSchema,
659
2194
  paths,
660
2195
  parentTitles: parentTitles.length > 0 ? parentTitles : void 0,
@@ -670,6 +2205,32 @@ toTreeNode_fn = /* @__PURE__ */ __name(function(name, metaOrFactory, paths = [na
670
2205
  __name(_FlowContext, "FlowContext");
671
2206
  let FlowContext = _FlowContext;
672
2207
  const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext {
2208
+ constructor() {
2209
+ super();
2210
+ this.defineMethod("getModel", (modelName, searchInPreviousEngines) => {
2211
+ return this.engine.getModel(modelName, searchInPreviousEngines);
2212
+ });
2213
+ this.defineMethod("request", (options) => {
2214
+ return this.api.request(options);
2215
+ });
2216
+ this.defineMethod(
2217
+ "runjs",
2218
+ async function(code, variables, options) {
2219
+ const { preprocessTemplates, ...runnerOptions } = options || {};
2220
+ const mergedGlobals = { ...(runnerOptions == null ? void 0 : runnerOptions.globals) || {}, ...variables || {} };
2221
+ const runner = await this.createJSRunner({
2222
+ ...runnerOptions || {},
2223
+ globals: mergedGlobals
2224
+ });
2225
+ const shouldPreprocessTemplates = (0, import_JSRunner.shouldPreprocessRunJSTemplates)({
2226
+ version: runnerOptions == null ? void 0 : runnerOptions.version,
2227
+ preprocessTemplates
2228
+ });
2229
+ const jsCode = await (0, import_utils.prepareRunJsCode)(String(code ?? ""), { preprocessTemplates: shouldPreprocessTemplates });
2230
+ return runner.run(jsCode);
2231
+ }
2232
+ );
2233
+ }
673
2234
  };
674
2235
  __name(_BaseFlowEngineContext, "BaseFlowEngineContext");
675
2236
  let BaseFlowEngineContext = _BaseFlowEngineContext;
@@ -694,26 +2255,31 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
694
2255
  });
695
2256
  dataSourceManager.addDataSource(mainDataSource);
696
2257
  this.defineProperty("engine", {
697
- value: this.engine
2258
+ value: this.engine,
2259
+ info: {
2260
+ description: "FlowEngine instance.",
2261
+ detail: "FlowEngine"
2262
+ }
698
2263
  });
699
2264
  this.defineProperty("sql", {
700
- get: /* @__PURE__ */ __name(() => new import_resources.FlowSQLRepository(this), "get")
2265
+ get: /* @__PURE__ */ __name((ctx) => new import_resources.FlowSQLRepository(ctx), "get"),
2266
+ cache: false,
2267
+ info: {
2268
+ description: "SQL helper (FlowSQLRepository).",
2269
+ detail: "FlowSQLRepository"
2270
+ }
701
2271
  });
702
2272
  this.defineProperty("dataSourceManager", {
703
- value: dataSourceManager
2273
+ value: dataSourceManager,
2274
+ info: {
2275
+ description: "DataSourceManager instance.",
2276
+ detail: "DataSourceManager"
2277
+ }
704
2278
  });
705
2279
  const i18n = new import_flowI18n.FlowI18n(this);
706
2280
  this.defineMethod("t", (keyOrTemplate, options) => {
707
2281
  return i18n.translate(keyOrTemplate, options);
708
2282
  });
709
- this.defineMethod("runjs", async (code, variables, options) => {
710
- const mergedGlobals = { ...(options == null ? void 0 : options.globals) || {}, ...variables || {} };
711
- const runner = await this.createJSRunner({
712
- ...options || {},
713
- globals: mergedGlobals
714
- });
715
- return runner.run(code);
716
- });
717
2283
  this.defineMethod("renderJson", function(template) {
718
2284
  return this.resolveJsonTemplate(template);
719
2285
  });
@@ -745,6 +2311,21 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
745
2311
  const needServer = Object.keys(serverVarPaths).length > 0;
746
2312
  let serverResolved = template;
747
2313
  if (needServer) {
2314
+ const inferRecordRefWithMeta = /* @__PURE__ */ __name((ctx) => {
2315
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2316
+ const ref = (0, import_variablesParams.inferRecordRef)(ctx);
2317
+ if (ref) return ref;
2318
+ try {
2319
+ const tk = (_b2 = (_a2 = ctx == null ? void 0 : ctx.resource) == null ? void 0 : _a2.getMeta) == null ? void 0 : _b2.call(_a2, "currentFilterByTk");
2320
+ if (typeof tk === "undefined" || tk === null) return void 0;
2321
+ const collection = ((_c = ctx == null ? void 0 : ctx.collection) == null ? void 0 : _c.name) || ((_j = (_i = (_h = (_g = (_f = (_e = (_d = ctx == null ? void 0 : ctx.resource) == null ? void 0 : _d.getResourceName) == null ? void 0 : _e.call(_d)) == null ? void 0 : _f.split) == null ? void 0 : _g.call(_f, ".")) == null ? void 0 : _h.slice) == null ? void 0 : _i.call(_h, -1)) == null ? void 0 : _j[0]);
2322
+ if (!collection) return void 0;
2323
+ const dataSourceKey = ((_k = ctx == null ? void 0 : ctx.collection) == null ? void 0 : _k.dataSourceKey) || ((_m = (_l = ctx == null ? void 0 : ctx.resource) == null ? void 0 : _l.getDataSourceKey) == null ? void 0 : _m.call(_l));
2324
+ return { collection, dataSourceKey, filterByTk: tk };
2325
+ } catch (_2) {
2326
+ return void 0;
2327
+ }
2328
+ }, "inferRecordRefWithMeta");
748
2329
  const collectFromMeta = /* @__PURE__ */ __name(async () => {
749
2330
  var _a2;
750
2331
  const out = {};
@@ -780,6 +2361,43 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
780
2361
  }, "collectFromMeta");
781
2362
  const inputFromMeta = await collectFromMeta();
782
2363
  const autoInput = { ...inputFromMeta };
2364
+ try {
2365
+ const varName = "formValues";
2366
+ const neededPaths = serverVarPaths[varName] || [];
2367
+ if (neededPaths.length) {
2368
+ const requiredTop = /* @__PURE__ */ new Set();
2369
+ for (const p of neededPaths) {
2370
+ const top = topLevelOf(p);
2371
+ if (top) requiredTop.add(top);
2372
+ }
2373
+ const metaOut = inputFromMeta == null ? void 0 : inputFromMeta[varName];
2374
+ const builtTop = /* @__PURE__ */ new Set();
2375
+ if (metaOut && typeof metaOut === "object" && !Array.isArray(metaOut) && !isRecordRefLike(metaOut)) {
2376
+ Object.keys(metaOut).forEach((k) => builtTop.add(k));
2377
+ }
2378
+ const missing = [...requiredTop].filter((k) => !builtTop.has(k));
2379
+ if (missing.length) {
2380
+ const ref = inferRecordRefWithMeta(this);
2381
+ if (ref) {
2382
+ const { generatedFields, generatedAppends } = inferSelectsFromUsage(neededPaths);
2383
+ const recordRef = {
2384
+ ...ref,
2385
+ fields: generatedFields,
2386
+ appends: generatedAppends
2387
+ };
2388
+ const existing = autoInput[varName];
2389
+ if (existing && typeof existing === "object" && !Array.isArray(existing) && !isRecordRefLike(existing)) {
2390
+ for (const [k, v] of Object.entries(existing)) {
2391
+ autoInput[`${varName}.${k}`] = v;
2392
+ }
2393
+ delete autoInput[varName];
2394
+ }
2395
+ autoInput[varName] = recordRef;
2396
+ }
2397
+ }
2398
+ }
2399
+ } catch (_2) {
2400
+ }
783
2401
  const autoContextParams = Object.keys(autoInput).length ? (0, import_serverContextParams.buildServerContextParams)(this, autoInput) : void 0;
784
2402
  if (!autoContextParams) {
785
2403
  const keys = Object.keys(serverVarPaths);
@@ -805,6 +2423,19 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
805
2423
  }
806
2424
  return (0, import_utils.resolveExpressions)(serverResolved, this);
807
2425
  });
2426
+ this.defineMethod(
2427
+ "getVar",
2428
+ async function(varPath) {
2429
+ const raw = typeof varPath === "string" ? varPath : String(varPath ?? "");
2430
+ const s = raw.trim();
2431
+ if (!s) return void 0;
2432
+ if (s !== "ctx" && !s.startsWith("ctx.")) {
2433
+ throw new Error(`ctx.getVar(path) expects an expression starting with "ctx.", got: "${s}"`);
2434
+ }
2435
+ return this.resolveJsonTemplate(`{{ ${s} }}`);
2436
+ },
2437
+ 'Resolve a ctx expression value by path (expression starts with "ctx.").'
2438
+ );
808
2439
  this.defineProperty("requirejs", {
809
2440
  get: /* @__PURE__ */ __name(() => {
810
2441
  var _a, _b;
@@ -894,69 +2525,72 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
894
2525
  user: this.user
895
2526
  }), "get")
896
2527
  });
897
- this.defineMethod("loadCSS", async (url) => {
898
- return new Promise((resolve, reject) => {
899
- const existingLink = document.querySelector(`link[href="${url}"]`);
900
- if (existingLink) {
901
- resolve(null);
902
- return;
903
- }
904
- const link = document.createElement("link");
905
- link.rel = "stylesheet";
906
- link.href = url;
907
- link.onload = () => resolve(null);
908
- link.onerror = () => reject(new Error(`Failed to load CSS: ${url}`));
909
- document.head.appendChild(link);
910
- });
2528
+ this.defineProperty("date", {
2529
+ get: /* @__PURE__ */ __name(() => {
2530
+ const createBranch = /* @__PURE__ */ __name((prefix) => {
2531
+ return new Proxy(
2532
+ {},
2533
+ {
2534
+ get: /* @__PURE__ */ __name((_target, prop) => {
2535
+ if (typeof prop !== "string") return void 0;
2536
+ const nextPath = [...prefix, prop];
2537
+ if (!(0, import_utils.isCtxDatePathPrefix)(nextPath)) {
2538
+ return void 0;
2539
+ }
2540
+ const resolved = (0, import_utils.resolveCtxDatePath)(nextPath);
2541
+ if (typeof resolved !== "undefined") {
2542
+ return resolved;
2543
+ }
2544
+ return createBranch(nextPath);
2545
+ }, "get")
2546
+ }
2547
+ );
2548
+ }, "createBranch");
2549
+ return createBranch(["date"]);
2550
+ }, "get"),
2551
+ cache: false
911
2552
  });
2553
+ this.defineMethod(
2554
+ "loadCSS",
2555
+ async (href) => {
2556
+ const url = (0, import_utils.resolveModuleUrl)(href);
2557
+ return new Promise((resolve, reject) => {
2558
+ const existingLink = document.querySelector(`link[href="${url}"]`);
2559
+ if (existingLink) {
2560
+ resolve(null);
2561
+ return;
2562
+ }
2563
+ const link = document.createElement("link");
2564
+ link.rel = "stylesheet";
2565
+ link.href = url;
2566
+ link.onload = () => resolve(null);
2567
+ link.onerror = () => reject(new Error(`Failed to load CSS: ${url}`));
2568
+ document.head.appendChild(link);
2569
+ });
2570
+ },
2571
+ {
2572
+ description: "Load a CSS file by URL (browser only).",
2573
+ params: [{ name: "href", type: "string", description: "CSS URL." }],
2574
+ returns: { type: "Promise<void>" },
2575
+ completion: { insertText: "await ctx.loadCSS('https://example.com/style.css')" },
2576
+ examples: ["await ctx.loadCSS('https://example.com/style.css');"]
2577
+ }
2578
+ );
912
2579
  this.defineMethod("requireAsync", async (url) => {
913
- return new Promise((resolve, reject) => {
914
- if (!this.requirejs) {
915
- reject(new Error("requirejs is not available"));
916
- return;
917
- }
918
- this.requirejs(
919
- [url],
920
- (...args) => {
921
- resolve(args[0]);
922
- },
923
- reject
924
- );
925
- });
2580
+ if ((0, import_utils.isCssFile)(url)) {
2581
+ return this.loadCSS(url);
2582
+ }
2583
+ const u = (0, import_utils.resolveModuleUrl)(url, { raw: true });
2584
+ return await (0, import_runjsModuleLoader.runjsRequireAsync)(this.requirejs, u);
926
2585
  });
927
- this.defineMethod("importAsync", async (url) => {
928
- if (!url || typeof url !== "string") {
929
- throw new Error("invalid url");
930
- }
931
- const u = url.trim();
932
- const g = globalThis;
933
- g.__nocobaseImportAsyncCache = g.__nocobaseImportAsyncCache || /* @__PURE__ */ new Map();
934
- const cache = g.__nocobaseImportAsyncCache;
935
- if (cache.has(u)) return cache.get(u);
936
- const nativeImport = /* @__PURE__ */ __name(() => import(
937
- /* @vite-ignore */
938
- /* webpackIgnore: true */
939
- u
940
- ), "nativeImport");
941
- const evalImport = /* @__PURE__ */ __name(() => {
942
- const importer = (0, eval)("u => import(u)");
943
- return importer(u);
944
- }, "evalImport");
945
- const p = (async () => {
946
- try {
947
- return await nativeImport();
948
- } catch (err) {
949
- try {
950
- return await evalImport();
951
- } catch (err2) {
952
- throw err2 || err;
953
- }
954
- }
955
- })();
956
- cache.set(u, p);
957
- return p;
2586
+ this.defineMethod("importAsync", async function(url) {
2587
+ if ((0, import_utils.isCssFile)(url)) {
2588
+ return this.loadCSS(url);
2589
+ }
2590
+ return await (0, import_runjsModuleLoader.runjsImportModule)(this, url, { importer: import_runjsModuleLoader.runjsImportAsync });
958
2591
  });
959
2592
  this.defineMethod("createJSRunner", async function(options) {
2593
+ var _a, _b, _c, _d, _e;
960
2594
  try {
961
2595
  const mod = await import("./runjs-context/setup");
962
2596
  if (typeof (mod == null ? void 0 : mod.setupRunJSContexts) === "function") await mod.setupRunJSContexts();
@@ -964,12 +2598,21 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
964
2598
  }
965
2599
  const version = (options == null ? void 0 : options.version) || "v1";
966
2600
  const modelClass = (0, import_registry.getModelClassName)(this);
967
- const Ctor = import_registry.RunJSContextRegistry.resolve(version, modelClass) || import_registry.RunJSContextRegistry.resolve(version, "*") || FlowRunJSContext;
968
- let runCtx;
969
- if (Ctor) {
970
- runCtx = new Ctor(this);
2601
+ const Ctor = import_registry.RunJSContextRegistry.resolve(version, modelClass) || FlowRunJSContext;
2602
+ const runCtx = new Ctor(this);
2603
+ runCtx.defineMethod("t", (key, options2) => {
2604
+ return this.t(key, { ns: "runjs", ...options2 });
2605
+ });
2606
+ let doc = {};
2607
+ try {
2608
+ const locale = ((_b = (_a = this == null ? void 0 : this.api) == null ? void 0 : _a.auth) == null ? void 0 : _b.locale) || ((_c = this == null ? void 0 : this.i18n) == null ? void 0 : _c.language) || (this == null ? void 0 : this.locale);
2609
+ if ((_d = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _d.length) doc = Ctor.getDoc(locale) || {};
2610
+ else doc = ((_e = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _e.call(Ctor)) || {};
2611
+ } catch (_2) {
2612
+ doc = {};
971
2613
  }
972
- const globals = { ctx: runCtx, ...(options == null ? void 0 : options.globals) || {} };
2614
+ const deprecatedCtx = createRunJSDeprecationProxy(runCtx, { doc });
2615
+ const globals = { ctx: deprecatedCtx, ...(options == null ? void 0 : options.globals) || {} };
973
2616
  const { timeoutMs } = options || {};
974
2617
  return new import_JSRunner.JSRunner({ globals, timeoutMs });
975
2618
  });
@@ -1022,13 +2665,26 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
1022
2665
  context: this.createProxy()
1023
2666
  });
1024
2667
  });
2668
+ this.defineMethod("makeResource", function(resourceType) {
2669
+ return this.engine.createResource(resourceType, {
2670
+ context: this.createProxy()
2671
+ });
2672
+ });
2673
+ this.defineMethod(
2674
+ "initResource",
2675
+ function(className) {
2676
+ if (!this.has("resource")) {
2677
+ this.defineProperty("resource", {
2678
+ get: /* @__PURE__ */ __name(() => this.createResource(className), "get")
2679
+ });
2680
+ }
2681
+ return this.resource;
2682
+ }
2683
+ );
1025
2684
  this.defineMethod(
1026
2685
  "useResource",
1027
2686
  function(className) {
1028
- if (this.has("resource")) return;
1029
- this.defineProperty("resource", {
1030
- get: /* @__PURE__ */ __name(() => this.createResource(className), "get")
1031
- });
2687
+ return this.initResource(className);
1032
2688
  }
1033
2689
  );
1034
2690
  }
@@ -1045,25 +2701,26 @@ const _FlowModelContext = class _FlowModelContext extends BaseFlowModelContext {
1045
2701
  this.defineMethod("onRefReady", (ref, cb, timeout) => {
1046
2702
  this.engine.reactView.onRefReady(ref, cb, timeout);
1047
2703
  });
1048
- this.defineMethod("runjs", async (code, variables, options) => {
1049
- const runner = await this.createJSRunner({
1050
- globals: variables,
1051
- version: options == null ? void 0 : options.version
1052
- });
1053
- return runner.run(code);
1054
- });
1055
2704
  this.defineProperty("model", {
1056
- value: model
2705
+ value: model,
2706
+ info: {
2707
+ description: "Current FlowModel instance.",
2708
+ detail: "FlowModel"
2709
+ }
1057
2710
  });
1058
2711
  const stableRef = (0, import_react.createRef)();
1059
2712
  this.defineProperty("ref", {
1060
2713
  get: /* @__PURE__ */ __name(() => {
1061
2714
  this.model["_refCreated"] = true;
1062
2715
  return stableRef;
1063
- }, "get")
2716
+ }, "get"),
2717
+ info: {
2718
+ description: "Stable React ref for the view container.",
2719
+ detail: "React.RefObject<HTMLDivElement>"
2720
+ }
1064
2721
  });
1065
2722
  this.defineMethod("openView", async function(uid, options) {
1066
- var _a, _b, _c, _d;
2723
+ var _a, _b, _c, _d, _e;
1067
2724
  const opts = { ...options };
1068
2725
  if (opts.defineProperties || opts.defineMethods) {
1069
2726
  opts.navigation = false;
@@ -1113,8 +2770,16 @@ const _FlowModelContext = class _FlowModelContext extends BaseFlowModelContext {
1113
2770
  engineCtx: this.engine.context
1114
2771
  };
1115
2772
  model2.context.defineProperty("view", { value: pendingView });
2773
+ const popupFlow = (_e = model2.getFlow) == null ? void 0 : _e.call(model2, "popupSettings");
2774
+ const on = popupFlow == null ? void 0 : popupFlow.on;
2775
+ let openEventName = "click";
2776
+ if (typeof on === "string" && on) {
2777
+ openEventName = on;
2778
+ } else if (on && typeof on === "object" && typeof on.eventName === "string" && on.eventName) {
2779
+ openEventName = on.eventName;
2780
+ }
1116
2781
  await model2.dispatchEvent(
1117
- "click",
2782
+ openEventName,
1118
2783
  {
1119
2784
  // navigation: false, // TODO: 路由模式有bug,不支持多层同样viewId的弹窗,因此这里默认先用false
1120
2785
  // ...this.model?.['getInputArgs']?.(), // 避免部分关系字段信息丢失, 仿照 ClickableCollectionField 做法
@@ -1174,21 +2839,22 @@ const _FlowForkModelContext = class _FlowForkModelContext extends BaseFlowModelC
1174
2839
  this.engine.reactView.onRefReady(ref, cb, timeout);
1175
2840
  });
1176
2841
  this.defineProperty("model", {
1177
- get: /* @__PURE__ */ __name(() => this.fork, "get")
2842
+ get: /* @__PURE__ */ __name(() => this.fork, "get"),
2843
+ info: {
2844
+ description: "Current ForkFlowModel instance (as model).",
2845
+ detail: "ForkFlowModel"
2846
+ }
1178
2847
  });
1179
2848
  const stableRef = (0, import_react.createRef)();
1180
2849
  this.defineProperty("ref", {
1181
2850
  get: /* @__PURE__ */ __name(() => {
1182
2851
  this.fork["_refCreated"] = true;
1183
2852
  return stableRef;
1184
- }, "get")
1185
- });
1186
- this.defineMethod("runjs", async (code, variables, options) => {
1187
- const runner = await this.createJSRunner({
1188
- globals: variables,
1189
- version: options == null ? void 0 : options.version
1190
- });
1191
- return runner.run(code);
2853
+ }, "get"),
2854
+ info: {
2855
+ description: "Stable React ref for the view container.",
2856
+ detail: "React.RefObject<HTMLDivElement>"
2857
+ }
1192
2858
  });
1193
2859
  }
1194
2860
  };
@@ -1211,15 +2877,15 @@ const _FlowRuntimeContext = class _FlowRuntimeContext extends BaseFlowModelConte
1211
2877
  return import_lodash.default.get(this.steps, [stepKey, "result"]);
1212
2878
  });
1213
2879
  this.defineMethod(
1214
- "useResource",
2880
+ "initResource",
1215
2881
  (className) => {
1216
2882
  if (model.context.has("resource")) {
1217
- console.warn(`[FlowRuntimeContext] useResource - resource already defined in context: ${className}`);
2883
+ console.log(`[FlowRuntimeContext] useResource - resource already defined in context: ${className}`);
1218
2884
  return;
1219
2885
  }
1220
2886
  model.context.defineProperty("resource", {
1221
2887
  get: /* @__PURE__ */ __name(() => {
1222
- return this.createResource(className);
2888
+ return this.makeResource(className);
1223
2889
  }, "get")
1224
2890
  });
1225
2891
  if (!model["resource"]) {
@@ -1227,6 +2893,12 @@ const _FlowRuntimeContext = class _FlowRuntimeContext extends BaseFlowModelConte
1227
2893
  }
1228
2894
  }
1229
2895
  );
2896
+ this.defineMethod(
2897
+ "useResource",
2898
+ (className) => {
2899
+ return this.initResource(className);
2900
+ }
2901
+ );
1230
2902
  this.defineProperty("resource", {
1231
2903
  get: /* @__PURE__ */ __name(() => model["resource"] || model.context["resource"], "get"),
1232
2904
  cache: false
@@ -1234,13 +2906,6 @@ const _FlowRuntimeContext = class _FlowRuntimeContext extends BaseFlowModelConte
1234
2906
  this.defineMethod("onRefReady", (ref, cb, timeout) => {
1235
2907
  this.engine.reactView.onRefReady(ref, cb, timeout);
1236
2908
  });
1237
- this.defineMethod("runjs", async (code, variables, options) => {
1238
- const runner = await this.createJSRunner({
1239
- globals: variables,
1240
- version: options == null ? void 0 : options.version
1241
- });
1242
- return runner.run(code);
1243
- });
1244
2909
  }
1245
2910
  stepResults = {};
1246
2911
  _getOwnProperty(key) {
@@ -1265,7 +2930,7 @@ const _FlowRuntimeContext = class _FlowRuntimeContext extends BaseFlowModelConte
1265
2930
  return void 0;
1266
2931
  }
1267
2932
  exit() {
1268
- throw new import_utils.FlowExitException(this.flowKey, this.model.uid);
2933
+ throw new import_exceptions.FlowExitAllException(this.flowKey, this.model.uid);
1269
2934
  }
1270
2935
  exitAll() {
1271
2936
  throw new import_exceptions.FlowExitAllException(this.flowKey, this.model.uid);
@@ -1293,13 +2958,442 @@ function __runjsDeepMerge(base, patch) {
1293
2958
  return out;
1294
2959
  }
1295
2960
  __name(__runjsDeepMerge, "__runjsDeepMerge");
2961
+ function __isPlainObject(val) {
2962
+ return !!val && typeof val === "object" && !Array.isArray(val);
2963
+ }
2964
+ __name(__isPlainObject, "__isPlainObject");
2965
+ function __isPromiseLike(v) {
2966
+ return !!v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
2967
+ }
2968
+ __name(__isPromiseLike, "__isPromiseLike");
2969
+ function __normalizeDeprecationDoc(v) {
2970
+ if (v === true) return true;
2971
+ if (!v) return void 0;
2972
+ if (__isPlainObject(v)) return v;
2973
+ return void 0;
2974
+ }
2975
+ __name(__normalizeDeprecationDoc, "__normalizeDeprecationDoc");
2976
+ function __addDeprecatedPath(root, path, deprecated) {
2977
+ if (!Array.isArray(path) || !path.length) return;
2978
+ let cur = root;
2979
+ for (const seg of path) {
2980
+ if (!seg) return;
2981
+ cur.children = cur.children || {};
2982
+ cur.children[seg] = cur.children[seg] || {};
2983
+ cur = cur.children[seg];
2984
+ }
2985
+ cur.deprecated = deprecated;
2986
+ }
2987
+ __name(__addDeprecatedPath, "__addDeprecatedPath");
2988
+ function __mergeDeprecatedTree(base, patch) {
2989
+ if (patch.deprecated !== void 0) base.deprecated = patch.deprecated;
2990
+ const pChildren = patch.children || {};
2991
+ const keys = Object.keys(pChildren);
2992
+ if (!keys.length) return;
2993
+ base.children = base.children || {};
2994
+ for (const k of keys) {
2995
+ base.children[k] = base.children[k] || {};
2996
+ __mergeDeprecatedTree(base.children[k], pChildren[k]);
2997
+ }
2998
+ }
2999
+ __name(__mergeDeprecatedTree, "__mergeDeprecatedTree");
3000
+ function __buildDeprecatedTreeFromRunJSDoc(doc) {
3001
+ const root = {};
3002
+ if (!doc) return root;
3003
+ const walkProps = /* @__PURE__ */ __name((props, parentPath) => {
3004
+ if (!__isPlainObject(props)) return;
3005
+ for (const [key, raw] of Object.entries(props)) {
3006
+ if (!key) continue;
3007
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3008
+ const node = raw;
3009
+ const dep = __normalizeDeprecationDoc(node.deprecated);
3010
+ if (dep) __addDeprecatedPath(root, [...parentPath, key], dep);
3011
+ if (__isPlainObject(node.properties)) {
3012
+ walkProps(node.properties, [...parentPath, key]);
3013
+ }
3014
+ }
3015
+ }, "walkProps");
3016
+ const walkMethods = /* @__PURE__ */ __name((methods) => {
3017
+ if (!__isPlainObject(methods)) return;
3018
+ for (const [key, raw] of Object.entries(methods)) {
3019
+ if (!key) continue;
3020
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3021
+ const node = raw;
3022
+ const dep = __normalizeDeprecationDoc(node.deprecated);
3023
+ if (dep) __addDeprecatedPath(root, [key], dep);
3024
+ }
3025
+ }, "walkMethods");
3026
+ walkProps(doc.properties, []);
3027
+ walkMethods(doc.methods);
3028
+ return root;
3029
+ }
3030
+ __name(__buildDeprecatedTreeFromRunJSDoc, "__buildDeprecatedTreeFromRunJSDoc");
3031
+ function __buildDeprecatedTreeFromFlowContextInfos(ctx) {
3032
+ const root = {};
3033
+ const visited = /* @__PURE__ */ new WeakSet();
3034
+ const collectInfoProperties = /* @__PURE__ */ __name((basePath, props) => {
3035
+ if (!__isPlainObject(props)) return;
3036
+ for (const [key, raw] of Object.entries(props)) {
3037
+ if (!key) continue;
3038
+ if (typeof raw === "string") continue;
3039
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3040
+ const node = raw;
3041
+ const dep = __normalizeDeprecationDoc(node.deprecated);
3042
+ if (dep) __addDeprecatedPath(root, [...basePath, key], dep);
3043
+ if (__isPlainObject(node.properties)) {
3044
+ collectInfoProperties([...basePath, key], node.properties);
3045
+ }
3046
+ }
3047
+ }, "collectInfoProperties");
3048
+ const walk = /* @__PURE__ */ __name((c) => {
3049
+ if (!c || typeof c !== "object" && typeof c !== "function") return;
3050
+ if (visited.has(c)) return;
3051
+ visited.add(c);
3052
+ const methodInfos = c._methodInfos;
3053
+ if (__isPlainObject(methodInfos)) {
3054
+ for (const [name, info] of Object.entries(methodInfos)) {
3055
+ if (!name) continue;
3056
+ if (!info || typeof info !== "object" || Array.isArray(info)) continue;
3057
+ const dep = __normalizeDeprecationDoc(info.deprecated);
3058
+ if (dep) __addDeprecatedPath(root, [name], dep);
3059
+ }
3060
+ }
3061
+ const props = c._props;
3062
+ if (__isPlainObject(props)) {
3063
+ for (const [name, opt] of Object.entries(props)) {
3064
+ if (!name) continue;
3065
+ const info = opt == null ? void 0 : opt.info;
3066
+ if (!info || typeof info !== "object" || Array.isArray(info)) continue;
3067
+ const dep = __normalizeDeprecationDoc(info.deprecated);
3068
+ if (dep) __addDeprecatedPath(root, [name], dep);
3069
+ if (__isPlainObject(info.properties)) {
3070
+ collectInfoProperties([name], info.properties);
3071
+ }
3072
+ }
3073
+ }
3074
+ const delegates = c._delegates;
3075
+ if (Array.isArray(delegates)) {
3076
+ for (const d of delegates) walk(d);
3077
+ }
3078
+ }, "walk");
3079
+ walk(ctx);
3080
+ return root;
3081
+ }
3082
+ __name(__buildDeprecatedTreeFromFlowContextInfos, "__buildDeprecatedTreeFromFlowContextInfos");
3083
+ function createRunJSDeprecationProxy(ctx, options = {}) {
3084
+ const fromDoc = __buildDeprecatedTreeFromRunJSDoc(options.doc);
3085
+ const fromInfo = __buildDeprecatedTreeFromFlowContextInfos(ctx);
3086
+ __mergeDeprecatedTree(fromDoc, fromInfo);
3087
+ const warned = /* @__PURE__ */ new Set();
3088
+ const proxyToTarget = /* @__PURE__ */ new WeakMap();
3089
+ const objectProxyCache = /* @__PURE__ */ new WeakMap();
3090
+ const functionProxyCache = /* @__PURE__ */ new WeakMap();
3091
+ const extractRunJSLocation = /* @__PURE__ */ __name((stack) => {
3092
+ if (!stack || typeof stack !== "string") return {};
3093
+ const WRAPPER_PREFIX_LINES = 2;
3094
+ const lines = stack.split("\n");
3095
+ for (const l of lines) {
3096
+ if (!l) continue;
3097
+ const m = l.match(/<anonymous>:(\d+):(\d+)/);
3098
+ if (!m) continue;
3099
+ const rawLine = Number(m[1]);
3100
+ const rawColumn = Number(m[2]);
3101
+ const line = Number.isFinite(rawLine) && rawLine > WRAPPER_PREFIX_LINES ? rawLine - WRAPPER_PREFIX_LINES : rawLine;
3102
+ const column = Number.isFinite(rawColumn) ? rawColumn : void 0;
3103
+ return { line, column, rawLine, rawColumn };
3104
+ }
3105
+ return {};
3106
+ }, "extractRunJSLocation");
3107
+ const collectInfoProperties = /* @__PURE__ */ __name((basePath, props) => {
3108
+ if (!__isPlainObject(props)) return;
3109
+ for (const [key, raw] of Object.entries(props)) {
3110
+ if (!key) continue;
3111
+ if (typeof raw === "string") continue;
3112
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3113
+ const node = raw;
3114
+ const dep = __normalizeDeprecationDoc(node.deprecated);
3115
+ if (dep) __addDeprecatedPath(fromDoc, [...basePath, key], dep);
3116
+ if (__isPlainObject(node.properties)) {
3117
+ collectInfoProperties([...basePath, key], node.properties);
3118
+ }
3119
+ }
3120
+ }, "collectInfoProperties");
3121
+ const updateTreeFromDefineProperty = /* @__PURE__ */ __name((name, options2) => {
3122
+ if (!name) return;
3123
+ const info = options2 == null ? void 0 : options2.info;
3124
+ if (!info || typeof info !== "object" || Array.isArray(info)) return;
3125
+ const dep = __normalizeDeprecationDoc(info.deprecated);
3126
+ if (dep) __addDeprecatedPath(fromDoc, [name], dep);
3127
+ if (__isPlainObject(info.properties)) {
3128
+ collectInfoProperties([name], info.properties);
3129
+ }
3130
+ }, "updateTreeFromDefineProperty");
3131
+ const updateTreeFromDefineMethod = /* @__PURE__ */ __name((name, info) => {
3132
+ if (!name) return;
3133
+ if (!info || typeof info !== "object" || Array.isArray(info)) return;
3134
+ const dep = __normalizeDeprecationDoc(info.deprecated);
3135
+ if (dep) __addDeprecatedPath(fromDoc, [name], dep);
3136
+ }, "updateTreeFromDefineMethod");
3137
+ const unwrapProxy = /* @__PURE__ */ __name((val) => {
3138
+ let cur = val;
3139
+ while (cur && (typeof cur === "object" || typeof cur === "function")) {
3140
+ const mapped = proxyToTarget.get(cur);
3141
+ if (!mapped) break;
3142
+ cur = mapped;
3143
+ }
3144
+ return cur;
3145
+ }, "unwrapProxy");
3146
+ const formatReplacedBy = /* @__PURE__ */ __name((replacedBy) => {
3147
+ if (!replacedBy) return void 0;
3148
+ if (typeof replacedBy === "string") return replacedBy.trim() || void 0;
3149
+ if (Array.isArray(replacedBy)) {
3150
+ const parts = replacedBy.map((x) => typeof x === "string" ? x.trim() : "").filter(Boolean);
3151
+ return parts.length ? parts.join(", ") : void 0;
3152
+ }
3153
+ return void 0;
3154
+ }, "formatReplacedBy");
3155
+ const warnOnce = /* @__PURE__ */ __name((apiPath, deprecated, stack) => {
3156
+ if (!apiPath) return;
3157
+ if (warned.has(apiPath)) return;
3158
+ warned.add(apiPath);
3159
+ const logger = ctx == null ? void 0 : ctx.logger;
3160
+ const t = typeof (ctx == null ? void 0 : ctx.t) === "function" ? (key, options2) => ctx.t(key, { ns: [import_utils.FLOW_ENGINE_NAMESPACE, "client"], nsMode: "fallback", ...options2 }) : (key, options2) => {
3161
+ const fallback = (options2 == null ? void 0 : options2.defaultValue) ?? key;
3162
+ if (typeof fallback !== "string" || !options2) return fallback;
3163
+ return fallback.replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g, (_m, k) => {
3164
+ const v = options2 == null ? void 0 : options2[k];
3165
+ return typeof v === "string" || typeof v === "number" ? String(v) : "";
3166
+ });
3167
+ };
3168
+ const meta = typeof deprecated === "object" && deprecated ? deprecated : {};
3169
+ const replacedBy = formatReplacedBy(meta.replacedBy);
3170
+ const since = typeof meta.since === "string" ? String(meta.since) : void 0;
3171
+ const removedIn = typeof meta.removedIn === "string" ? String(meta.removedIn) : void 0;
3172
+ const message = typeof meta.message === "string" ? String(meta.message) : "";
3173
+ const loc = extractRunJSLocation(stack);
3174
+ const locText = loc.line ? `\uFF08line ${loc.line}${loc.column ? `:${loc.column}` : ""}\uFF09` : "";
3175
+ const msg = message.trim();
3176
+ const mainText = msg ? t("RunJS deprecated warning with message", {
3177
+ defaultValue: "[RunJS][Deprecated] {{api}} {{message}}{{location}}",
3178
+ api: apiPath,
3179
+ message: msg,
3180
+ location: locText
3181
+ }) : t("RunJS deprecated warning", {
3182
+ defaultValue: "[RunJS][Deprecated] {{api}} is deprecated{{location}}",
3183
+ api: apiPath,
3184
+ location: locText
3185
+ });
3186
+ const separator = t("RunJS deprecated separator", { defaultValue: "; " });
3187
+ const textParts = [mainText];
3188
+ if (replacedBy)
3189
+ textParts.push(t("RunJS deprecated replacedBy", { defaultValue: "Use {{replacedBy}} instead", replacedBy }));
3190
+ if (since) textParts.push(t("RunJS deprecated since", { defaultValue: "since {{since}}", since }));
3191
+ if (removedIn)
3192
+ textParts.push(t("RunJS deprecated removedIn", { defaultValue: "will be removed in {{removedIn}}", removedIn }));
3193
+ const text = textParts.filter(Boolean).join(separator);
3194
+ try {
3195
+ if (logger && typeof logger.warn === "function") {
3196
+ logger.warn(text);
3197
+ } else {
3198
+ console.warn(text);
3199
+ }
3200
+ } catch (_2) {
3201
+ }
3202
+ }, "warnOnce");
3203
+ const createFunctionProxy = /* @__PURE__ */ __name((fn, node, path) => {
3204
+ const dep = node.deprecated;
3205
+ if (!dep) return fn;
3206
+ const cacheByPath = functionProxyCache.get(fn) || /* @__PURE__ */ new Map();
3207
+ functionProxyCache.set(fn, cacheByPath);
3208
+ if (cacheByPath.has(path)) return cacheByPath.get(path);
3209
+ const proxied = new Proxy(fn, {
3210
+ apply(target, thisArg, argArray) {
3211
+ const stack = warned.has(path) ? void 0 : new Error().stack;
3212
+ warnOnce(path, dep, stack);
3213
+ const realThis = unwrapProxy(thisArg);
3214
+ return Reflect.apply(target, realThis, argArray);
3215
+ },
3216
+ get(target, key, receiver) {
3217
+ return Reflect.get(target, key, receiver);
3218
+ }
3219
+ });
3220
+ cacheByPath.set(path, proxied);
3221
+ return proxied;
3222
+ }, "createFunctionProxy");
3223
+ const createObjectProxy = /* @__PURE__ */ __name((target, node, path) => {
3224
+ if (!target || typeof target !== "object" && typeof target !== "function") return target;
3225
+ if (__isPromiseLike(target)) return target;
3226
+ const hasChildren = !!node.children && Object.keys(node.children).length > 0;
3227
+ if (!hasChildren && path !== "ctx") return target;
3228
+ const cacheByPath = objectProxyCache.get(target) || /* @__PURE__ */ new Map();
3229
+ objectProxyCache.set(target, cacheByPath);
3230
+ if (cacheByPath.has(path)) return cacheByPath.get(path);
3231
+ const proxied = new Proxy(target, {
3232
+ get(t, key, receiver) {
3233
+ var _a;
3234
+ if (typeof key === "symbol") {
3235
+ return Reflect.get(t, key, unwrapProxy(receiver));
3236
+ }
3237
+ const prop = String(key);
3238
+ const value = Reflect.get(t, key, unwrapProxy(receiver));
3239
+ if (path === "ctx" && prop === "defineProperty" && typeof value === "function") {
3240
+ return (...args) => {
3241
+ const result = value(...args);
3242
+ try {
3243
+ updateTreeFromDefineProperty(String((args == null ? void 0 : args[0]) ?? ""), args == null ? void 0 : args[1]);
3244
+ } catch (_2) {
3245
+ }
3246
+ return result;
3247
+ };
3248
+ }
3249
+ if (path === "ctx" && prop === "defineMethod" && typeof value === "function") {
3250
+ return (...args) => {
3251
+ const result = value(...args);
3252
+ try {
3253
+ updateTreeFromDefineMethod(String((args == null ? void 0 : args[0]) ?? ""), args == null ? void 0 : args[2]);
3254
+ } catch (_2) {
3255
+ }
3256
+ return result;
3257
+ };
3258
+ }
3259
+ const child = (_a = node.children) == null ? void 0 : _a[prop];
3260
+ if (!child) return value;
3261
+ const childPath = `${path}.${prop}`;
3262
+ if (typeof value === "function" && child.deprecated) {
3263
+ return createFunctionProxy(value, child, childPath);
3264
+ }
3265
+ if (child.deprecated) {
3266
+ const stack = warned.has(childPath) ? void 0 : new Error().stack;
3267
+ warnOnce(childPath, child.deprecated, stack);
3268
+ }
3269
+ if (value && (typeof value === "object" || typeof value === "function") && child.children) {
3270
+ return createObjectProxy(value, child, childPath);
3271
+ }
3272
+ return value;
3273
+ },
3274
+ has(t, key) {
3275
+ return Reflect.has(t, key);
3276
+ }
3277
+ });
3278
+ proxyToTarget.set(proxied, target);
3279
+ cacheByPath.set(path, proxied);
3280
+ return proxied;
3281
+ }, "createObjectProxy");
3282
+ return createObjectProxy(ctx, fromDoc, "ctx");
3283
+ }
3284
+ __name(createRunJSDeprecationProxy, "createRunJSDeprecationProxy");
3285
+ function __mergeRunJSDocDocRecord(base, patch, mergeDoc) {
3286
+ if (!__isPlainObject(patch)) return base;
3287
+ if (!__isPlainObject(base)) return patch;
3288
+ const out = { ...base };
3289
+ for (const k of Object.keys(patch)) {
3290
+ const pv = patch[k];
3291
+ if (pv === null) {
3292
+ delete out[k];
3293
+ continue;
3294
+ }
3295
+ const bv = __isPlainObject(base) ? base[k] : void 0;
3296
+ const merged = mergeDoc(bv, pv);
3297
+ if (typeof merged === "undefined") delete out[k];
3298
+ else out[k] = merged;
3299
+ }
3300
+ return out;
3301
+ }
3302
+ __name(__mergeRunJSDocDocRecord, "__mergeRunJSDocDocRecord");
3303
+ function __mergeRunJSDocPropertyDoc(base, patch) {
3304
+ if (patch === null) return void 0;
3305
+ const baseIsObj = __isPlainObject(base);
3306
+ const patchIsObj = __isPlainObject(patch);
3307
+ const baseIsStr = typeof base === "string";
3308
+ const patchIsStr = typeof patch === "string";
3309
+ if (patchIsStr) {
3310
+ if (baseIsObj) {
3311
+ return __mergeRunJSDocPropertyDoc(base, { description: patch });
3312
+ }
3313
+ return patch;
3314
+ }
3315
+ if (patchIsObj) {
3316
+ const baseObj = baseIsObj ? base : baseIsStr ? { description: base } : void 0;
3317
+ const out = { ...baseObj || {} };
3318
+ for (const k of Object.keys(patch)) {
3319
+ if (k === "properties") {
3320
+ const pv = patch.properties;
3321
+ if (pv === null) {
3322
+ delete out.properties;
3323
+ continue;
3324
+ }
3325
+ const mergedProps = __mergeRunJSDocDocRecord(baseObj == null ? void 0 : baseObj.properties, pv, __mergeRunJSDocPropertyDoc);
3326
+ if (typeof mergedProps === "undefined") delete out.properties;
3327
+ else out.properties = mergedProps;
3328
+ continue;
3329
+ }
3330
+ const mergedVal = __runjsDeepMerge(baseObj == null ? void 0 : baseObj[k], patch[k]);
3331
+ if (typeof mergedVal === "undefined") delete out[k];
3332
+ else out[k] = mergedVal;
3333
+ }
3334
+ return out;
3335
+ }
3336
+ return patch ?? base;
3337
+ }
3338
+ __name(__mergeRunJSDocPropertyDoc, "__mergeRunJSDocPropertyDoc");
3339
+ function __mergeRunJSDocMethodDoc(base, patch) {
3340
+ if (patch === null) return void 0;
3341
+ const baseIsObj = __isPlainObject(base);
3342
+ const patchIsObj = __isPlainObject(patch);
3343
+ const baseIsStr = typeof base === "string";
3344
+ const patchIsStr = typeof patch === "string";
3345
+ if (patchIsStr) {
3346
+ if (baseIsObj) {
3347
+ return __mergeRunJSDocMethodDoc(base, { description: patch });
3348
+ }
3349
+ return patch;
3350
+ }
3351
+ if (patchIsObj) {
3352
+ const baseObj = baseIsObj ? base : baseIsStr ? { description: base } : void 0;
3353
+ const out = { ...baseObj || {} };
3354
+ for (const k of Object.keys(patch)) {
3355
+ const mergedVal = __runjsDeepMerge(baseObj == null ? void 0 : baseObj[k], patch[k]);
3356
+ if (typeof mergedVal === "undefined") delete out[k];
3357
+ else out[k] = mergedVal;
3358
+ }
3359
+ return out;
3360
+ }
3361
+ return patch ?? base;
3362
+ }
3363
+ __name(__mergeRunJSDocMethodDoc, "__mergeRunJSDocMethodDoc");
3364
+ function __mergeRunJSDocMeta(base, patch) {
3365
+ const baseObj = __isPlainObject(base) ? base : {};
3366
+ const patchObj = __isPlainObject(patch) ? patch : {};
3367
+ const out = { ...baseObj };
3368
+ for (const k of Object.keys(patchObj)) {
3369
+ if (k === "properties") {
3370
+ const mergedProps = __mergeRunJSDocDocRecord(baseObj.properties, patchObj.properties, __mergeRunJSDocPropertyDoc);
3371
+ if (typeof mergedProps === "undefined") delete out.properties;
3372
+ else out.properties = mergedProps;
3373
+ continue;
3374
+ }
3375
+ if (k === "methods") {
3376
+ const mergedMethods = __mergeRunJSDocDocRecord(baseObj.methods, patchObj.methods, __mergeRunJSDocMethodDoc);
3377
+ if (typeof mergedMethods === "undefined") delete out.methods;
3378
+ else out.methods = mergedMethods;
3379
+ continue;
3380
+ }
3381
+ const mergedVal = __runjsDeepMerge(baseObj[k], patchObj[k]);
3382
+ if (typeof mergedVal === "undefined") delete out[k];
3383
+ else out[k] = mergedVal;
3384
+ }
3385
+ return out;
3386
+ }
3387
+ __name(__mergeRunJSDocMeta, "__mergeRunJSDocMeta");
1296
3388
  const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
1297
3389
  constructor(delegate) {
1298
3390
  super();
1299
3391
  this.addDelegate(delegate);
1300
3392
  this.defineProperty("React", { value: import_react.default });
1301
3393
  this.defineProperty("antd", { value: antd });
1302
- this.defineProperty("dayjs", { value: import_dayjs.default });
3394
+ this.defineProperty("dayjs", {
3395
+ value: import_dayjs.default
3396
+ });
1303
3397
  const ReactDOMShim = {
1304
3398
  ...ReactDOMClient,
1305
3399
  createRoot: /* @__PURE__ */ __name((container, options) => {
@@ -1307,15 +3401,9 @@ const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
1307
3401
  return this.engine.reactView.createRoot(realContainer, options);
1308
3402
  }, "createRoot")
1309
3403
  };
3404
+ ReactDOMShim.__nbRunjsInternalShim = true;
1310
3405
  this.defineProperty("ReactDOM", { value: ReactDOMShim });
1311
- const libs = Object.freeze({
1312
- React: import_react.default,
1313
- ReactDOM: ReactDOMShim,
1314
- antd,
1315
- dayjs: import_dayjs.default,
1316
- antdIcons
1317
- });
1318
- this.defineProperty("libs", { value: libs });
3406
+ (0, import_runjsLibs.setupRunJSLibs)(this);
1319
3407
  this.defineMethod(
1320
3408
  "render",
1321
3409
  function(vnode, container) {
@@ -1325,52 +3413,85 @@ const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
1325
3413
  const globalRef = globalThis;
1326
3414
  globalRef.__nbRunjsRoots = globalRef.__nbRunjsRoots || /* @__PURE__ */ new WeakMap();
1327
3415
  const rootMap = globalRef.__nbRunjsRoots;
1328
- if (typeof vnode === "string") {
1329
- const existingRoot = rootMap.get(containerEl);
1330
- if (existingRoot && typeof existingRoot.unmount === "function") {
3416
+ const disposeEntry = /* @__PURE__ */ __name((entry2) => {
3417
+ if (!entry2) return;
3418
+ if (entry2.disposeTheme && typeof entry2.disposeTheme === "function") {
3419
+ try {
3420
+ entry2.disposeTheme();
3421
+ } catch (_2) {
3422
+ }
3423
+ entry2.disposeTheme = void 0;
3424
+ }
3425
+ const root = entry2.root || entry2;
3426
+ if (root && typeof root.unmount === "function") {
1331
3427
  try {
1332
- existingRoot.unmount();
1333
- } finally {
1334
- rootMap.delete(containerEl);
3428
+ root.unmount();
3429
+ } catch (_2) {
1335
3430
  }
1336
3431
  }
3432
+ }, "disposeEntry");
3433
+ const unmountContainerRoot = /* @__PURE__ */ __name(() => {
3434
+ const existing = rootMap.get(containerEl);
3435
+ if (existing) {
3436
+ disposeEntry(existing);
3437
+ rootMap.delete(containerEl);
3438
+ }
3439
+ }, "unmountContainerRoot");
3440
+ if (typeof vnode === "string") {
3441
+ unmountContainerRoot();
1337
3442
  const proxy = new import_ElementProxy.ElementProxy(containerEl);
1338
3443
  proxy.innerHTML = String(vnode ?? "");
1339
3444
  return null;
1340
3445
  }
1341
3446
  if (vnode && vnode.nodeType && (vnode.nodeType === 1 || vnode.nodeType === 3 || vnode.nodeType === 11)) {
1342
- const existingRoot = rootMap.get(containerEl);
1343
- if (existingRoot && typeof existingRoot.unmount === "function") {
1344
- try {
1345
- existingRoot.unmount();
1346
- } finally {
1347
- rootMap.delete(containerEl);
1348
- }
1349
- }
3447
+ unmountContainerRoot();
1350
3448
  while (containerEl.firstChild) containerEl.removeChild(containerEl.firstChild);
1351
3449
  containerEl.appendChild(vnode);
1352
3450
  return null;
1353
3451
  }
1354
- let root = rootMap.get(containerEl);
1355
- if (!root) {
1356
- root = this.ReactDOM.createRoot(containerEl);
1357
- rootMap.set(containerEl, root);
3452
+ const rendererKey = this.ReactDOM;
3453
+ const ownerKey = this;
3454
+ let entry = rootMap.get(containerEl);
3455
+ if (!entry || entry.rendererKey !== rendererKey || entry.ownerKey !== ownerKey) {
3456
+ if (entry) {
3457
+ disposeEntry(entry);
3458
+ rootMap.delete(containerEl);
3459
+ }
3460
+ const root = this.ReactDOM.createRoot(containerEl);
3461
+ entry = { rendererKey, ownerKey, root, disposeTheme: void 0, lastVnode: void 0 };
3462
+ rootMap.set(containerEl, entry);
1358
3463
  }
1359
- root.render(vnode);
1360
- return root;
3464
+ return (0, import_runjsLibs.externalReactRender)({
3465
+ ctx: this,
3466
+ entry,
3467
+ vnode,
3468
+ containerEl,
3469
+ rootMap,
3470
+ unmountContainerRoot,
3471
+ internalReact: import_react.default,
3472
+ internalAntd: antd
3473
+ });
1361
3474
  }
1362
3475
  );
1363
3476
  }
3477
+ exit() {
3478
+ var _a;
3479
+ throw new import_exceptions.FlowExitAllException(this.flowKey, ((_a = this.model) == null ? void 0 : _a.uid) || "runjs");
3480
+ }
3481
+ exitAll() {
3482
+ var _a;
3483
+ throw new import_exceptions.FlowExitAllException(this.flowKey, ((_a = this.model) == null ? void 0 : _a.uid) || "runjs");
3484
+ }
1364
3485
  static define(meta, options) {
1365
3486
  const locale = options == null ? void 0 : options.locale;
1366
3487
  if (locale) {
1367
3488
  const map = __runjsClassLocaleMeta.get(this) || /* @__PURE__ */ new Map();
1368
3489
  const prev = map.get(locale) || {};
1369
- map.set(locale, __runjsDeepMerge(prev, meta));
3490
+ map.set(locale, __mergeRunJSDocMeta(prev, meta));
1370
3491
  __runjsClassLocaleMeta.set(this, map);
1371
3492
  } else {
1372
3493
  const prev = __runjsClassDefaultMeta.get(this) || {};
1373
- __runjsClassDefaultMeta.set(this, __runjsDeepMerge(prev, meta));
3494
+ __runjsClassDefaultMeta.set(this, __mergeRunJSDocMeta(prev, meta));
1374
3495
  }
1375
3496
  __runjsDocCache.delete(this);
1376
3497
  }
@@ -1387,13 +3508,13 @@ const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
1387
3508
  }
1388
3509
  let merged = {};
1389
3510
  for (const cls of chain) {
1390
- merged = __runjsDeepMerge(merged, __runjsClassDefaultMeta.get(cls) || {});
3511
+ merged = __mergeRunJSDocMeta(merged, __runjsClassDefaultMeta.get(cls) || {});
1391
3512
  }
1392
3513
  if (locale) {
1393
3514
  for (const cls of chain) {
1394
3515
  const lmap = __runjsClassLocaleMeta.get(cls);
1395
3516
  if (lmap && lmap.has(locale)) {
1396
- merged = __runjsDeepMerge(merged, lmap.get(locale));
3517
+ merged = __mergeRunJSDocMeta(merged, lmap.get(locale));
1397
3518
  }
1398
3519
  }
1399
3520
  }
@@ -1414,5 +3535,6 @@ let FlowRunJSContext = _FlowRunJSContext;
1414
3535
  FlowForkModelContext,
1415
3536
  FlowModelContext,
1416
3537
  FlowRunJSContext,
1417
- FlowRuntimeContext
3538
+ FlowRuntimeContext,
3539
+ createRunJSDeprecationProxy
1418
3540
  });