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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/lib/BlockScopedFlowEngine.js +0 -1
  2. package/lib/FlowDefinition.d.ts +2 -0
  3. package/lib/JSRunner.d.ts +6 -0
  4. package/lib/JSRunner.js +32 -2
  5. package/lib/ViewScopedFlowEngine.js +3 -0
  6. package/lib/acl/Acl.js +13 -3
  7. package/lib/components/FlowContextSelector.js +155 -10
  8. package/lib/components/settings/wrappers/component/SwitchWithTitle.js +2 -1
  9. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +76 -15
  10. package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +24 -4
  11. package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +5 -1
  12. package/lib/components/variables/VariableInput.js +9 -4
  13. package/lib/components/variables/VariableTag.js +46 -39
  14. package/lib/components/variables/utils.d.ts +7 -0
  15. package/lib/components/variables/utils.js +42 -2
  16. package/lib/data-source/index.d.ts +7 -27
  17. package/lib/data-source/index.js +81 -51
  18. package/lib/executor/FlowExecutor.d.ts +2 -1
  19. package/lib/executor/FlowExecutor.js +163 -22
  20. package/lib/flowContext.d.ts +230 -7
  21. package/lib/flowContext.js +2267 -148
  22. package/lib/flowEngine.d.ts +21 -0
  23. package/lib/flowEngine.js +56 -8
  24. package/lib/flowI18n.js +6 -4
  25. package/lib/flowSettings.js +17 -11
  26. package/lib/index.d.ts +7 -1
  27. package/lib/index.js +21 -0
  28. package/lib/locale/en-US.json +9 -2
  29. package/lib/locale/index.d.ts +14 -0
  30. package/lib/locale/zh-CN.json +8 -1
  31. package/lib/models/CollectionFieldModel.d.ts +1 -0
  32. package/lib/models/CollectionFieldModel.js +3 -2
  33. package/lib/models/flowModel.js +12 -1
  34. package/lib/provider.js +5 -5
  35. package/lib/resources/baseRecordResource.d.ts +5 -0
  36. package/lib/resources/baseRecordResource.js +24 -0
  37. package/lib/resources/multiRecordResource.d.ts +1 -0
  38. package/lib/resources/multiRecordResource.js +11 -4
  39. package/lib/resources/singleRecordResource.js +2 -0
  40. package/lib/resources/sqlResource.d.ts +4 -3
  41. package/lib/resources/sqlResource.js +8 -3
  42. package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +12 -2
  43. package/lib/runjs-context/contexts/JSBlockRunJSContext.js +2 -2
  44. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.d.ts +16 -0
  45. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +125 -0
  46. package/lib/runjs-context/contexts/JSItemRunJSContext.js +12 -2
  47. package/lib/runjs-context/contexts/base.js +706 -41
  48. package/lib/runjs-context/contributions.d.ts +33 -0
  49. package/lib/runjs-context/contributions.js +88 -0
  50. package/lib/runjs-context/helpers.js +12 -1
  51. package/lib/runjs-context/setup.js +6 -0
  52. package/lib/runjs-context/snippets/global/api-request.snippet.js +3 -3
  53. package/lib/runjs-context/snippets/global/import-esm.snippet.js +2 -3
  54. package/lib/runjs-context/snippets/global/query-selector.snippet.js +8 -3
  55. package/lib/runjs-context/snippets/global/require-amd.snippet.js +1 -1
  56. package/lib/runjs-context/snippets/index.d.ts +11 -1
  57. package/lib/runjs-context/snippets/index.js +61 -40
  58. package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.js +10 -7
  59. package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +3 -3
  60. package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +2 -2
  61. package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.js +2 -2
  62. package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +2 -2
  63. package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +1 -1
  64. package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +1 -1
  65. package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +1 -1
  66. package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +5 -5
  67. package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +6 -6
  68. package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +3 -4
  69. package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.js +1 -1
  70. package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.js +20 -3
  71. package/lib/runjs-context/snippets/scene/detail/format-number.snippet.js +1 -1
  72. package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.js +1 -1
  73. package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +3 -3
  74. package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +3 -3
  75. package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +2 -2
  76. package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +1 -1
  77. package/lib/runjs-context/snippets/scene/form/render-basic.snippet.js +2 -2
  78. package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +6 -3
  79. package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +3 -1
  80. package/lib/runjsLibs.d.ts +28 -0
  81. package/lib/runjsLibs.js +532 -0
  82. package/lib/scheduler/ModelOperationScheduler.d.ts +2 -0
  83. package/lib/scheduler/ModelOperationScheduler.js +25 -21
  84. package/lib/types.d.ts +27 -0
  85. package/lib/utils/associationObjectVariable.d.ts +2 -2
  86. package/lib/utils/createCollectionContextMeta.js +1 -0
  87. package/lib/utils/createEphemeralContext.js +2 -2
  88. package/lib/utils/dateVariable.d.ts +16 -0
  89. package/lib/utils/dateVariable.js +380 -0
  90. package/lib/utils/exceptions.d.ts +7 -0
  91. package/lib/utils/exceptions.js +10 -0
  92. package/lib/utils/index.d.ts +8 -3
  93. package/lib/utils/index.js +45 -0
  94. package/lib/utils/params-resolvers.js +16 -9
  95. package/lib/utils/resolveModuleUrl.d.ts +58 -0
  96. package/lib/utils/resolveModuleUrl.js +65 -0
  97. package/lib/utils/resolveRunJSObjectValues.d.ts +16 -0
  98. package/lib/utils/resolveRunJSObjectValues.js +61 -0
  99. package/lib/utils/runjsModuleLoader.d.ts +58 -0
  100. package/lib/utils/runjsModuleLoader.js +422 -0
  101. package/lib/utils/runjsTemplateCompat.d.ts +35 -0
  102. package/lib/utils/runjsTemplateCompat.js +743 -0
  103. package/lib/utils/runjsValue.d.ts +29 -0
  104. package/lib/utils/runjsValue.js +275 -0
  105. package/lib/utils/safeGlobals.d.ts +18 -8
  106. package/lib/utils/safeGlobals.js +164 -17
  107. package/lib/utils/schema-utils.d.ts +10 -0
  108. package/lib/utils/schema-utils.js +61 -0
  109. package/lib/views/createViewMeta.d.ts +0 -7
  110. package/lib/views/createViewMeta.js +19 -70
  111. package/lib/views/index.d.ts +1 -2
  112. package/lib/views/index.js +4 -3
  113. package/lib/views/useDialog.js +7 -2
  114. package/lib/views/useDrawer.js +7 -2
  115. package/lib/views/usePage.d.ts +4 -0
  116. package/lib/views/usePage.js +43 -6
  117. package/lib/views/usePopover.js +4 -1
  118. package/lib/views/viewEvents.d.ts +17 -0
  119. package/lib/views/viewEvents.js +90 -0
  120. package/package.json +4 -4
  121. package/src/BlockScopedFlowEngine.ts +2 -5
  122. package/src/JSRunner.ts +44 -2
  123. package/src/ViewScopedFlowEngine.ts +4 -0
  124. package/src/__tests__/JSRunner.test.ts +64 -0
  125. package/src/__tests__/createViewMeta.popup.test.ts +62 -1
  126. package/src/__tests__/flowContext.test.ts +693 -1
  127. package/src/__tests__/flowEngine.dataSourceDirty.test.ts +63 -0
  128. package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
  129. package/src/__tests__/flowRunJSContextDefine.test.ts +63 -0
  130. package/src/__tests__/flowRuntimeContext.test.ts +2 -1
  131. package/src/__tests__/flowSettings.open.test.tsx +123 -19
  132. package/src/__tests__/runjsContext.test.ts +10 -7
  133. package/src/__tests__/runjsContextImplementations.test.ts +34 -3
  134. package/src/__tests__/runjsContextRuntime.test.ts +3 -3
  135. package/src/__tests__/runjsContributions.test.ts +89 -0
  136. package/src/__tests__/runjsExternalLibs.test.ts +242 -0
  137. package/src/__tests__/runjsLibsLazyLoading.test.ts +44 -0
  138. package/src/__tests__/runjsLocales.test.ts +4 -1
  139. package/src/__tests__/runjsPreprocessDefault.test.ts +49 -0
  140. package/src/__tests__/runjsRuntimeFeatures.test.ts +166 -0
  141. package/src/__tests__/runjsSnippets.test.ts +40 -3
  142. package/src/acl/Acl.tsx +3 -3
  143. package/src/components/FlowContextSelector.tsx +208 -12
  144. package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +2 -1
  145. package/src/components/settings/wrappers/component/__tests__/InlineControls.test.tsx +74 -0
  146. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +109 -16
  147. package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +41 -7
  148. package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +13 -2
  149. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +157 -5
  150. package/src/components/variables/VariableInput.tsx +12 -4
  151. package/src/components/variables/VariableTag.tsx +54 -45
  152. package/src/components/variables/__tests__/FlowContextSelector.test.tsx +260 -3
  153. package/src/components/variables/__tests__/VariableTag.test.tsx +50 -0
  154. package/src/components/variables/__tests__/utils.test.ts +81 -3
  155. package/src/components/variables/utils.ts +67 -6
  156. package/src/data-source/index.ts +85 -110
  157. package/src/executor/FlowExecutor.ts +200 -23
  158. package/src/executor/__tests__/flowExecutor.test.ts +66 -0
  159. package/src/flowContext.ts +2986 -211
  160. package/src/flowEngine.ts +59 -8
  161. package/src/flowI18n.ts +7 -5
  162. package/src/flowSettings.ts +18 -12
  163. package/src/index.ts +14 -1
  164. package/src/locale/en-US.json +9 -2
  165. package/src/locale/zh-CN.json +8 -1
  166. package/src/models/CollectionFieldModel.tsx +3 -1
  167. package/src/models/__tests__/dispatchEvent.when.test.ts +554 -0
  168. package/src/models/__tests__/flowModel.test.ts +20 -4
  169. package/src/models/flowModel.tsx +13 -1
  170. package/src/provider.tsx +7 -6
  171. package/src/resources/__tests__/multiRecordResource.test.ts +44 -0
  172. package/src/resources/__tests__/sqlResource.test.ts +60 -0
  173. package/src/resources/baseRecordResource.ts +31 -0
  174. package/src/resources/multiRecordResource.ts +11 -4
  175. package/src/resources/singleRecordResource.ts +3 -0
  176. package/src/resources/sqlResource.ts +11 -6
  177. package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +10 -0
  178. package/src/runjs-context/contexts/JSBlockRunJSContext.ts +6 -2
  179. package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +106 -0
  180. package/src/runjs-context/contexts/JSItemRunJSContext.ts +10 -0
  181. package/src/runjs-context/contexts/base.ts +715 -44
  182. package/src/runjs-context/contributions.ts +88 -0
  183. package/src/runjs-context/helpers.ts +11 -1
  184. package/src/runjs-context/setup.ts +6 -0
  185. package/src/runjs-context/snippets/global/api-request.snippet.ts +3 -3
  186. package/src/runjs-context/snippets/global/import-esm.snippet.ts +2 -3
  187. package/src/runjs-context/snippets/global/query-selector.snippet.ts +8 -3
  188. package/src/runjs-context/snippets/global/require-amd.snippet.ts +1 -1
  189. package/src/runjs-context/snippets/index.ts +75 -41
  190. package/src/runjs-context/snippets/scene/block/add-event-listener.snippet.ts +11 -13
  191. package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +3 -3
  192. package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +2 -2
  193. package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +2 -2
  194. package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +2 -2
  195. package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +1 -1
  196. package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +1 -1
  197. package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +1 -1
  198. package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +6 -11
  199. package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +6 -6
  200. package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +3 -4
  201. package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +1 -1
  202. package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +20 -3
  203. package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +1 -1
  204. package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +1 -1
  205. package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +3 -3
  206. package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +3 -3
  207. package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +2 -2
  208. package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +1 -1
  209. package/src/runjs-context/snippets/scene/form/render-basic.snippet.ts +3 -8
  210. package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +6 -3
  211. package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +3 -1
  212. package/src/runjsLibs.ts +622 -0
  213. package/src/scheduler/ModelOperationScheduler.ts +27 -21
  214. package/src/types.ts +38 -1
  215. package/src/utils/__tests__/dateVariable.test.ts +101 -0
  216. package/src/utils/__tests__/params-resolvers.test.ts +40 -0
  217. package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +38 -0
  218. package/src/utils/__tests__/runjsTemplateCompat.test.ts +159 -0
  219. package/src/utils/__tests__/runjsValue.test.ts +44 -0
  220. package/src/utils/__tests__/safeGlobals.test.ts +57 -2
  221. package/src/utils/__tests__/utils.test.ts +95 -0
  222. package/src/utils/associationObjectVariable.ts +2 -2
  223. package/src/utils/createCollectionContextMeta.ts +1 -0
  224. package/src/utils/createEphemeralContext.ts +5 -4
  225. package/src/utils/dateVariable.ts +397 -0
  226. package/src/utils/exceptions.ts +11 -0
  227. package/src/utils/index.ts +37 -3
  228. package/src/utils/params-resolvers.ts +23 -9
  229. package/src/utils/resolveModuleUrl.ts +91 -0
  230. package/src/utils/resolveRunJSObjectValues.ts +46 -0
  231. package/src/utils/runjsModuleLoader.ts +553 -0
  232. package/src/utils/runjsTemplateCompat.ts +828 -0
  233. package/src/utils/runjsValue.ts +287 -0
  234. package/src/utils/safeGlobals.ts +188 -17
  235. package/src/utils/schema-utils.ts +79 -0
  236. package/src/views/__tests__/FlowView.usePage.test.tsx +54 -1
  237. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +35 -8
  238. package/src/views/__tests__/viewEvents.resolveOpenerEngine.test.ts +28 -0
  239. package/src/views/createViewMeta.ts +22 -75
  240. package/src/views/index.tsx +1 -2
  241. package/src/views/useDialog.tsx +8 -1
  242. package/src/views/useDrawer.tsx +8 -1
  243. package/src/views/usePage.tsx +51 -5
  244. package/src/views/usePopover.tsx +4 -1
  245. package/src/views/viewEvents.ts +55 -0
@@ -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,29 @@ 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 = preprocessTemplates !== false;
2226
+ const jsCode = await (0, import_utils.prepareRunJsCode)(String(code ?? ""), { preprocessTemplates: shouldPreprocessTemplates });
2227
+ return runner.run(jsCode);
2228
+ }
2229
+ );
2230
+ }
673
2231
  };
674
2232
  __name(_BaseFlowEngineContext, "BaseFlowEngineContext");
675
2233
  let BaseFlowEngineContext = _BaseFlowEngineContext;
@@ -694,26 +2252,31 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
694
2252
  });
695
2253
  dataSourceManager.addDataSource(mainDataSource);
696
2254
  this.defineProperty("engine", {
697
- value: this.engine
2255
+ value: this.engine,
2256
+ info: {
2257
+ description: "FlowEngine instance.",
2258
+ detail: "FlowEngine"
2259
+ }
698
2260
  });
699
2261
  this.defineProperty("sql", {
700
- get: /* @__PURE__ */ __name(() => new import_resources.FlowSQLRepository(this), "get")
2262
+ get: /* @__PURE__ */ __name((ctx) => new import_resources.FlowSQLRepository(ctx), "get"),
2263
+ cache: false,
2264
+ info: {
2265
+ description: "SQL helper (FlowSQLRepository).",
2266
+ detail: "FlowSQLRepository"
2267
+ }
701
2268
  });
702
2269
  this.defineProperty("dataSourceManager", {
703
- value: dataSourceManager
2270
+ value: dataSourceManager,
2271
+ info: {
2272
+ description: "DataSourceManager instance.",
2273
+ detail: "DataSourceManager"
2274
+ }
704
2275
  });
705
2276
  const i18n = new import_flowI18n.FlowI18n(this);
706
2277
  this.defineMethod("t", (keyOrTemplate, options) => {
707
2278
  return i18n.translate(keyOrTemplate, options);
708
2279
  });
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
2280
  this.defineMethod("renderJson", function(template) {
718
2281
  return this.resolveJsonTemplate(template);
719
2282
  });
@@ -745,6 +2308,21 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
745
2308
  const needServer = Object.keys(serverVarPaths).length > 0;
746
2309
  let serverResolved = template;
747
2310
  if (needServer) {
2311
+ const inferRecordRefWithMeta = /* @__PURE__ */ __name((ctx) => {
2312
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2313
+ const ref = (0, import_variablesParams.inferRecordRef)(ctx);
2314
+ if (ref) return ref;
2315
+ try {
2316
+ const tk = (_b2 = (_a2 = ctx == null ? void 0 : ctx.resource) == null ? void 0 : _a2.getMeta) == null ? void 0 : _b2.call(_a2, "currentFilterByTk");
2317
+ if (typeof tk === "undefined" || tk === null) return void 0;
2318
+ 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]);
2319
+ if (!collection) return void 0;
2320
+ 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));
2321
+ return { collection, dataSourceKey, filterByTk: tk };
2322
+ } catch (_2) {
2323
+ return void 0;
2324
+ }
2325
+ }, "inferRecordRefWithMeta");
748
2326
  const collectFromMeta = /* @__PURE__ */ __name(async () => {
749
2327
  var _a2;
750
2328
  const out = {};
@@ -780,6 +2358,43 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
780
2358
  }, "collectFromMeta");
781
2359
  const inputFromMeta = await collectFromMeta();
782
2360
  const autoInput = { ...inputFromMeta };
2361
+ try {
2362
+ const varName = "formValues";
2363
+ const neededPaths = serverVarPaths[varName] || [];
2364
+ if (neededPaths.length) {
2365
+ const requiredTop = /* @__PURE__ */ new Set();
2366
+ for (const p of neededPaths) {
2367
+ const top = topLevelOf(p);
2368
+ if (top) requiredTop.add(top);
2369
+ }
2370
+ const metaOut = inputFromMeta == null ? void 0 : inputFromMeta[varName];
2371
+ const builtTop = /* @__PURE__ */ new Set();
2372
+ if (metaOut && typeof metaOut === "object" && !Array.isArray(metaOut) && !isRecordRefLike(metaOut)) {
2373
+ Object.keys(metaOut).forEach((k) => builtTop.add(k));
2374
+ }
2375
+ const missing = [...requiredTop].filter((k) => !builtTop.has(k));
2376
+ if (missing.length) {
2377
+ const ref = inferRecordRefWithMeta(this);
2378
+ if (ref) {
2379
+ const { generatedFields, generatedAppends } = inferSelectsFromUsage(neededPaths);
2380
+ const recordRef = {
2381
+ ...ref,
2382
+ fields: generatedFields,
2383
+ appends: generatedAppends
2384
+ };
2385
+ const existing = autoInput[varName];
2386
+ if (existing && typeof existing === "object" && !Array.isArray(existing) && !isRecordRefLike(existing)) {
2387
+ for (const [k, v] of Object.entries(existing)) {
2388
+ autoInput[`${varName}.${k}`] = v;
2389
+ }
2390
+ delete autoInput[varName];
2391
+ }
2392
+ autoInput[varName] = recordRef;
2393
+ }
2394
+ }
2395
+ }
2396
+ } catch (_2) {
2397
+ }
783
2398
  const autoContextParams = Object.keys(autoInput).length ? (0, import_serverContextParams.buildServerContextParams)(this, autoInput) : void 0;
784
2399
  if (!autoContextParams) {
785
2400
  const keys = Object.keys(serverVarPaths);
@@ -805,6 +2420,19 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
805
2420
  }
806
2421
  return (0, import_utils.resolveExpressions)(serverResolved, this);
807
2422
  });
2423
+ this.defineMethod(
2424
+ "getVar",
2425
+ async function(varPath) {
2426
+ const raw = typeof varPath === "string" ? varPath : String(varPath ?? "");
2427
+ const s = raw.trim();
2428
+ if (!s) return void 0;
2429
+ if (s !== "ctx" && !s.startsWith("ctx.")) {
2430
+ throw new Error(`ctx.getVar(path) expects an expression starting with "ctx.", got: "${s}"`);
2431
+ }
2432
+ return this.resolveJsonTemplate(`{{ ${s} }}`);
2433
+ },
2434
+ 'Resolve a ctx expression value by path (expression starts with "ctx.").'
2435
+ );
808
2436
  this.defineProperty("requirejs", {
809
2437
  get: /* @__PURE__ */ __name(() => {
810
2438
  var _a, _b;
@@ -894,69 +2522,72 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
894
2522
  user: this.user
895
2523
  }), "get")
896
2524
  });
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
- });
2525
+ this.defineProperty("date", {
2526
+ get: /* @__PURE__ */ __name(() => {
2527
+ const createBranch = /* @__PURE__ */ __name((prefix) => {
2528
+ return new Proxy(
2529
+ {},
2530
+ {
2531
+ get: /* @__PURE__ */ __name((_target, prop) => {
2532
+ if (typeof prop !== "string") return void 0;
2533
+ const nextPath = [...prefix, prop];
2534
+ if (!(0, import_utils.isCtxDatePathPrefix)(nextPath)) {
2535
+ return void 0;
2536
+ }
2537
+ const resolved = (0, import_utils.resolveCtxDatePath)(nextPath);
2538
+ if (typeof resolved !== "undefined") {
2539
+ return resolved;
2540
+ }
2541
+ return createBranch(nextPath);
2542
+ }, "get")
2543
+ }
2544
+ );
2545
+ }, "createBranch");
2546
+ return createBranch(["date"]);
2547
+ }, "get"),
2548
+ cache: false
911
2549
  });
2550
+ this.defineMethod(
2551
+ "loadCSS",
2552
+ async (href) => {
2553
+ const url = (0, import_utils.resolveModuleUrl)(href);
2554
+ return new Promise((resolve, reject) => {
2555
+ const existingLink = document.querySelector(`link[href="${url}"]`);
2556
+ if (existingLink) {
2557
+ resolve(null);
2558
+ return;
2559
+ }
2560
+ const link = document.createElement("link");
2561
+ link.rel = "stylesheet";
2562
+ link.href = url;
2563
+ link.onload = () => resolve(null);
2564
+ link.onerror = () => reject(new Error(`Failed to load CSS: ${url}`));
2565
+ document.head.appendChild(link);
2566
+ });
2567
+ },
2568
+ {
2569
+ description: "Load a CSS file by URL (browser only).",
2570
+ params: [{ name: "href", type: "string", description: "CSS URL." }],
2571
+ returns: { type: "Promise<void>" },
2572
+ completion: { insertText: "await ctx.loadCSS('https://example.com/style.css')" },
2573
+ examples: ["await ctx.loadCSS('https://example.com/style.css');"]
2574
+ }
2575
+ );
912
2576
  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
- });
2577
+ if ((0, import_utils.isCssFile)(url)) {
2578
+ return this.loadCSS(url);
2579
+ }
2580
+ const u = (0, import_utils.resolveModuleUrl)(url, { raw: true });
2581
+ return await (0, import_runjsModuleLoader.runjsRequireAsync)(this.requirejs, u);
926
2582
  });
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;
2583
+ this.defineMethod("importAsync", async function(url) {
2584
+ if ((0, import_utils.isCssFile)(url)) {
2585
+ return this.loadCSS(url);
2586
+ }
2587
+ return await (0, import_runjsModuleLoader.runjsImportModule)(this, url, { importer: import_runjsModuleLoader.runjsImportAsync });
958
2588
  });
959
2589
  this.defineMethod("createJSRunner", async function(options) {
2590
+ var _a, _b, _c, _d, _e;
960
2591
  try {
961
2592
  const mod = await import("./runjs-context/setup");
962
2593
  if (typeof (mod == null ? void 0 : mod.setupRunJSContexts) === "function") await mod.setupRunJSContexts();
@@ -964,12 +2595,21 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
964
2595
  }
965
2596
  const version = (options == null ? void 0 : options.version) || "v1";
966
2597
  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);
2598
+ const Ctor = import_registry.RunJSContextRegistry.resolve(version, modelClass) || FlowRunJSContext;
2599
+ const runCtx = new Ctor(this);
2600
+ runCtx.defineMethod("t", (key, options2) => {
2601
+ return this.t(key, { ns: "runjs", ...options2 });
2602
+ });
2603
+ let doc = {};
2604
+ try {
2605
+ 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);
2606
+ if ((_d = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _d.length) doc = Ctor.getDoc(locale) || {};
2607
+ else doc = ((_e = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _e.call(Ctor)) || {};
2608
+ } catch (_2) {
2609
+ doc = {};
971
2610
  }
972
- const globals = { ctx: runCtx, ...(options == null ? void 0 : options.globals) || {} };
2611
+ const deprecatedCtx = createRunJSDeprecationProxy(runCtx, { doc });
2612
+ const globals = { ctx: deprecatedCtx, ...(options == null ? void 0 : options.globals) || {} };
973
2613
  const { timeoutMs } = options || {};
974
2614
  return new import_JSRunner.JSRunner({ globals, timeoutMs });
975
2615
  });
@@ -1022,13 +2662,26 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
1022
2662
  context: this.createProxy()
1023
2663
  });
1024
2664
  });
2665
+ this.defineMethod("makeResource", function(resourceType) {
2666
+ return this.engine.createResource(resourceType, {
2667
+ context: this.createProxy()
2668
+ });
2669
+ });
2670
+ this.defineMethod(
2671
+ "initResource",
2672
+ function(className) {
2673
+ if (!this.has("resource")) {
2674
+ this.defineProperty("resource", {
2675
+ get: /* @__PURE__ */ __name(() => this.createResource(className), "get")
2676
+ });
2677
+ }
2678
+ return this.resource;
2679
+ }
2680
+ );
1025
2681
  this.defineMethod(
1026
2682
  "useResource",
1027
2683
  function(className) {
1028
- if (this.has("resource")) return;
1029
- this.defineProperty("resource", {
1030
- get: /* @__PURE__ */ __name(() => this.createResource(className), "get")
1031
- });
2684
+ return this.initResource(className);
1032
2685
  }
1033
2686
  );
1034
2687
  }
@@ -1045,25 +2698,26 @@ const _FlowModelContext = class _FlowModelContext extends BaseFlowModelContext {
1045
2698
  this.defineMethod("onRefReady", (ref, cb, timeout) => {
1046
2699
  this.engine.reactView.onRefReady(ref, cb, timeout);
1047
2700
  });
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
2701
  this.defineProperty("model", {
1056
- value: model
2702
+ value: model,
2703
+ info: {
2704
+ description: "Current FlowModel instance.",
2705
+ detail: "FlowModel"
2706
+ }
1057
2707
  });
1058
2708
  const stableRef = (0, import_react.createRef)();
1059
2709
  this.defineProperty("ref", {
1060
2710
  get: /* @__PURE__ */ __name(() => {
1061
2711
  this.model["_refCreated"] = true;
1062
2712
  return stableRef;
1063
- }, "get")
2713
+ }, "get"),
2714
+ info: {
2715
+ description: "Stable React ref for the view container.",
2716
+ detail: "React.RefObject<HTMLDivElement>"
2717
+ }
1064
2718
  });
1065
2719
  this.defineMethod("openView", async function(uid, options) {
1066
- var _a, _b, _c, _d;
2720
+ var _a, _b, _c, _d, _e;
1067
2721
  const opts = { ...options };
1068
2722
  if (opts.defineProperties || opts.defineMethods) {
1069
2723
  opts.navigation = false;
@@ -1113,8 +2767,16 @@ const _FlowModelContext = class _FlowModelContext extends BaseFlowModelContext {
1113
2767
  engineCtx: this.engine.context
1114
2768
  };
1115
2769
  model2.context.defineProperty("view", { value: pendingView });
2770
+ const popupFlow = (_e = model2.getFlow) == null ? void 0 : _e.call(model2, "popupSettings");
2771
+ const on = popupFlow == null ? void 0 : popupFlow.on;
2772
+ let openEventName = "click";
2773
+ if (typeof on === "string" && on) {
2774
+ openEventName = on;
2775
+ } else if (on && typeof on === "object" && typeof on.eventName === "string" && on.eventName) {
2776
+ openEventName = on.eventName;
2777
+ }
1116
2778
  await model2.dispatchEvent(
1117
- "click",
2779
+ openEventName,
1118
2780
  {
1119
2781
  // navigation: false, // TODO: 路由模式有bug,不支持多层同样viewId的弹窗,因此这里默认先用false
1120
2782
  // ...this.model?.['getInputArgs']?.(), // 避免部分关系字段信息丢失, 仿照 ClickableCollectionField 做法
@@ -1174,21 +2836,22 @@ const _FlowForkModelContext = class _FlowForkModelContext extends BaseFlowModelC
1174
2836
  this.engine.reactView.onRefReady(ref, cb, timeout);
1175
2837
  });
1176
2838
  this.defineProperty("model", {
1177
- get: /* @__PURE__ */ __name(() => this.fork, "get")
2839
+ get: /* @__PURE__ */ __name(() => this.fork, "get"),
2840
+ info: {
2841
+ description: "Current ForkFlowModel instance (as model).",
2842
+ detail: "ForkFlowModel"
2843
+ }
1178
2844
  });
1179
2845
  const stableRef = (0, import_react.createRef)();
1180
2846
  this.defineProperty("ref", {
1181
2847
  get: /* @__PURE__ */ __name(() => {
1182
2848
  this.fork["_refCreated"] = true;
1183
2849
  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);
2850
+ }, "get"),
2851
+ info: {
2852
+ description: "Stable React ref for the view container.",
2853
+ detail: "React.RefObject<HTMLDivElement>"
2854
+ }
1192
2855
  });
1193
2856
  }
1194
2857
  };
@@ -1211,15 +2874,15 @@ const _FlowRuntimeContext = class _FlowRuntimeContext extends BaseFlowModelConte
1211
2874
  return import_lodash.default.get(this.steps, [stepKey, "result"]);
1212
2875
  });
1213
2876
  this.defineMethod(
1214
- "useResource",
2877
+ "initResource",
1215
2878
  (className) => {
1216
2879
  if (model.context.has("resource")) {
1217
- console.warn(`[FlowRuntimeContext] useResource - resource already defined in context: ${className}`);
2880
+ console.log(`[FlowRuntimeContext] useResource - resource already defined in context: ${className}`);
1218
2881
  return;
1219
2882
  }
1220
2883
  model.context.defineProperty("resource", {
1221
2884
  get: /* @__PURE__ */ __name(() => {
1222
- return this.createResource(className);
2885
+ return this.makeResource(className);
1223
2886
  }, "get")
1224
2887
  });
1225
2888
  if (!model["resource"]) {
@@ -1227,6 +2890,12 @@ const _FlowRuntimeContext = class _FlowRuntimeContext extends BaseFlowModelConte
1227
2890
  }
1228
2891
  }
1229
2892
  );
2893
+ this.defineMethod(
2894
+ "useResource",
2895
+ (className) => {
2896
+ return this.initResource(className);
2897
+ }
2898
+ );
1230
2899
  this.defineProperty("resource", {
1231
2900
  get: /* @__PURE__ */ __name(() => model["resource"] || model.context["resource"], "get"),
1232
2901
  cache: false
@@ -1234,13 +2903,6 @@ const _FlowRuntimeContext = class _FlowRuntimeContext extends BaseFlowModelConte
1234
2903
  this.defineMethod("onRefReady", (ref, cb, timeout) => {
1235
2904
  this.engine.reactView.onRefReady(ref, cb, timeout);
1236
2905
  });
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
2906
  }
1245
2907
  stepResults = {};
1246
2908
  _getOwnProperty(key) {
@@ -1265,7 +2927,7 @@ const _FlowRuntimeContext = class _FlowRuntimeContext extends BaseFlowModelConte
1265
2927
  return void 0;
1266
2928
  }
1267
2929
  exit() {
1268
- throw new import_utils.FlowExitException(this.flowKey, this.model.uid);
2930
+ throw new import_exceptions.FlowExitAllException(this.flowKey, this.model.uid);
1269
2931
  }
1270
2932
  exitAll() {
1271
2933
  throw new import_exceptions.FlowExitAllException(this.flowKey, this.model.uid);
@@ -1293,13 +2955,442 @@ function __runjsDeepMerge(base, patch) {
1293
2955
  return out;
1294
2956
  }
1295
2957
  __name(__runjsDeepMerge, "__runjsDeepMerge");
2958
+ function __isPlainObject(val) {
2959
+ return !!val && typeof val === "object" && !Array.isArray(val);
2960
+ }
2961
+ __name(__isPlainObject, "__isPlainObject");
2962
+ function __isPromiseLike(v) {
2963
+ return !!v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
2964
+ }
2965
+ __name(__isPromiseLike, "__isPromiseLike");
2966
+ function __normalizeDeprecationDoc(v) {
2967
+ if (v === true) return true;
2968
+ if (!v) return void 0;
2969
+ if (__isPlainObject(v)) return v;
2970
+ return void 0;
2971
+ }
2972
+ __name(__normalizeDeprecationDoc, "__normalizeDeprecationDoc");
2973
+ function __addDeprecatedPath(root, path, deprecated) {
2974
+ if (!Array.isArray(path) || !path.length) return;
2975
+ let cur = root;
2976
+ for (const seg of path) {
2977
+ if (!seg) return;
2978
+ cur.children = cur.children || {};
2979
+ cur.children[seg] = cur.children[seg] || {};
2980
+ cur = cur.children[seg];
2981
+ }
2982
+ cur.deprecated = deprecated;
2983
+ }
2984
+ __name(__addDeprecatedPath, "__addDeprecatedPath");
2985
+ function __mergeDeprecatedTree(base, patch) {
2986
+ if (patch.deprecated !== void 0) base.deprecated = patch.deprecated;
2987
+ const pChildren = patch.children || {};
2988
+ const keys = Object.keys(pChildren);
2989
+ if (!keys.length) return;
2990
+ base.children = base.children || {};
2991
+ for (const k of keys) {
2992
+ base.children[k] = base.children[k] || {};
2993
+ __mergeDeprecatedTree(base.children[k], pChildren[k]);
2994
+ }
2995
+ }
2996
+ __name(__mergeDeprecatedTree, "__mergeDeprecatedTree");
2997
+ function __buildDeprecatedTreeFromRunJSDoc(doc) {
2998
+ const root = {};
2999
+ if (!doc) return root;
3000
+ const walkProps = /* @__PURE__ */ __name((props, parentPath) => {
3001
+ if (!__isPlainObject(props)) return;
3002
+ for (const [key, raw] of Object.entries(props)) {
3003
+ if (!key) continue;
3004
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3005
+ const node = raw;
3006
+ const dep = __normalizeDeprecationDoc(node.deprecated);
3007
+ if (dep) __addDeprecatedPath(root, [...parentPath, key], dep);
3008
+ if (__isPlainObject(node.properties)) {
3009
+ walkProps(node.properties, [...parentPath, key]);
3010
+ }
3011
+ }
3012
+ }, "walkProps");
3013
+ const walkMethods = /* @__PURE__ */ __name((methods) => {
3014
+ if (!__isPlainObject(methods)) return;
3015
+ for (const [key, raw] of Object.entries(methods)) {
3016
+ if (!key) continue;
3017
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3018
+ const node = raw;
3019
+ const dep = __normalizeDeprecationDoc(node.deprecated);
3020
+ if (dep) __addDeprecatedPath(root, [key], dep);
3021
+ }
3022
+ }, "walkMethods");
3023
+ walkProps(doc.properties, []);
3024
+ walkMethods(doc.methods);
3025
+ return root;
3026
+ }
3027
+ __name(__buildDeprecatedTreeFromRunJSDoc, "__buildDeprecatedTreeFromRunJSDoc");
3028
+ function __buildDeprecatedTreeFromFlowContextInfos(ctx) {
3029
+ const root = {};
3030
+ const visited = /* @__PURE__ */ new WeakSet();
3031
+ const collectInfoProperties = /* @__PURE__ */ __name((basePath, props) => {
3032
+ if (!__isPlainObject(props)) return;
3033
+ for (const [key, raw] of Object.entries(props)) {
3034
+ if (!key) continue;
3035
+ if (typeof raw === "string") continue;
3036
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3037
+ const node = raw;
3038
+ const dep = __normalizeDeprecationDoc(node.deprecated);
3039
+ if (dep) __addDeprecatedPath(root, [...basePath, key], dep);
3040
+ if (__isPlainObject(node.properties)) {
3041
+ collectInfoProperties([...basePath, key], node.properties);
3042
+ }
3043
+ }
3044
+ }, "collectInfoProperties");
3045
+ const walk = /* @__PURE__ */ __name((c) => {
3046
+ if (!c || typeof c !== "object" && typeof c !== "function") return;
3047
+ if (visited.has(c)) return;
3048
+ visited.add(c);
3049
+ const methodInfos = c._methodInfos;
3050
+ if (__isPlainObject(methodInfos)) {
3051
+ for (const [name, info] of Object.entries(methodInfos)) {
3052
+ if (!name) continue;
3053
+ if (!info || typeof info !== "object" || Array.isArray(info)) continue;
3054
+ const dep = __normalizeDeprecationDoc(info.deprecated);
3055
+ if (dep) __addDeprecatedPath(root, [name], dep);
3056
+ }
3057
+ }
3058
+ const props = c._props;
3059
+ if (__isPlainObject(props)) {
3060
+ for (const [name, opt] of Object.entries(props)) {
3061
+ if (!name) continue;
3062
+ const info = opt == null ? void 0 : opt.info;
3063
+ if (!info || typeof info !== "object" || Array.isArray(info)) continue;
3064
+ const dep = __normalizeDeprecationDoc(info.deprecated);
3065
+ if (dep) __addDeprecatedPath(root, [name], dep);
3066
+ if (__isPlainObject(info.properties)) {
3067
+ collectInfoProperties([name], info.properties);
3068
+ }
3069
+ }
3070
+ }
3071
+ const delegates = c._delegates;
3072
+ if (Array.isArray(delegates)) {
3073
+ for (const d of delegates) walk(d);
3074
+ }
3075
+ }, "walk");
3076
+ walk(ctx);
3077
+ return root;
3078
+ }
3079
+ __name(__buildDeprecatedTreeFromFlowContextInfos, "__buildDeprecatedTreeFromFlowContextInfos");
3080
+ function createRunJSDeprecationProxy(ctx, options = {}) {
3081
+ const fromDoc = __buildDeprecatedTreeFromRunJSDoc(options.doc);
3082
+ const fromInfo = __buildDeprecatedTreeFromFlowContextInfos(ctx);
3083
+ __mergeDeprecatedTree(fromDoc, fromInfo);
3084
+ const warned = /* @__PURE__ */ new Set();
3085
+ const proxyToTarget = /* @__PURE__ */ new WeakMap();
3086
+ const objectProxyCache = /* @__PURE__ */ new WeakMap();
3087
+ const functionProxyCache = /* @__PURE__ */ new WeakMap();
3088
+ const extractRunJSLocation = /* @__PURE__ */ __name((stack) => {
3089
+ if (!stack || typeof stack !== "string") return {};
3090
+ const WRAPPER_PREFIX_LINES = 2;
3091
+ const lines = stack.split("\n");
3092
+ for (const l of lines) {
3093
+ if (!l) continue;
3094
+ const m = l.match(/<anonymous>:(\d+):(\d+)/);
3095
+ if (!m) continue;
3096
+ const rawLine = Number(m[1]);
3097
+ const rawColumn = Number(m[2]);
3098
+ const line = Number.isFinite(rawLine) && rawLine > WRAPPER_PREFIX_LINES ? rawLine - WRAPPER_PREFIX_LINES : rawLine;
3099
+ const column = Number.isFinite(rawColumn) ? rawColumn : void 0;
3100
+ return { line, column, rawLine, rawColumn };
3101
+ }
3102
+ return {};
3103
+ }, "extractRunJSLocation");
3104
+ const collectInfoProperties = /* @__PURE__ */ __name((basePath, props) => {
3105
+ if (!__isPlainObject(props)) return;
3106
+ for (const [key, raw] of Object.entries(props)) {
3107
+ if (!key) continue;
3108
+ if (typeof raw === "string") continue;
3109
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3110
+ const node = raw;
3111
+ const dep = __normalizeDeprecationDoc(node.deprecated);
3112
+ if (dep) __addDeprecatedPath(fromDoc, [...basePath, key], dep);
3113
+ if (__isPlainObject(node.properties)) {
3114
+ collectInfoProperties([...basePath, key], node.properties);
3115
+ }
3116
+ }
3117
+ }, "collectInfoProperties");
3118
+ const updateTreeFromDefineProperty = /* @__PURE__ */ __name((name, options2) => {
3119
+ if (!name) return;
3120
+ const info = options2 == null ? void 0 : options2.info;
3121
+ if (!info || typeof info !== "object" || Array.isArray(info)) return;
3122
+ const dep = __normalizeDeprecationDoc(info.deprecated);
3123
+ if (dep) __addDeprecatedPath(fromDoc, [name], dep);
3124
+ if (__isPlainObject(info.properties)) {
3125
+ collectInfoProperties([name], info.properties);
3126
+ }
3127
+ }, "updateTreeFromDefineProperty");
3128
+ const updateTreeFromDefineMethod = /* @__PURE__ */ __name((name, info) => {
3129
+ if (!name) return;
3130
+ if (!info || typeof info !== "object" || Array.isArray(info)) return;
3131
+ const dep = __normalizeDeprecationDoc(info.deprecated);
3132
+ if (dep) __addDeprecatedPath(fromDoc, [name], dep);
3133
+ }, "updateTreeFromDefineMethod");
3134
+ const unwrapProxy = /* @__PURE__ */ __name((val) => {
3135
+ let cur = val;
3136
+ while (cur && (typeof cur === "object" || typeof cur === "function")) {
3137
+ const mapped = proxyToTarget.get(cur);
3138
+ if (!mapped) break;
3139
+ cur = mapped;
3140
+ }
3141
+ return cur;
3142
+ }, "unwrapProxy");
3143
+ const formatReplacedBy = /* @__PURE__ */ __name((replacedBy) => {
3144
+ if (!replacedBy) return void 0;
3145
+ if (typeof replacedBy === "string") return replacedBy.trim() || void 0;
3146
+ if (Array.isArray(replacedBy)) {
3147
+ const parts = replacedBy.map((x) => typeof x === "string" ? x.trim() : "").filter(Boolean);
3148
+ return parts.length ? parts.join(", ") : void 0;
3149
+ }
3150
+ return void 0;
3151
+ }, "formatReplacedBy");
3152
+ const warnOnce = /* @__PURE__ */ __name((apiPath, deprecated, stack) => {
3153
+ if (!apiPath) return;
3154
+ if (warned.has(apiPath)) return;
3155
+ warned.add(apiPath);
3156
+ const logger = ctx == null ? void 0 : ctx.logger;
3157
+ 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) => {
3158
+ const fallback = (options2 == null ? void 0 : options2.defaultValue) ?? key;
3159
+ if (typeof fallback !== "string" || !options2) return fallback;
3160
+ return fallback.replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g, (_m, k) => {
3161
+ const v = options2 == null ? void 0 : options2[k];
3162
+ return typeof v === "string" || typeof v === "number" ? String(v) : "";
3163
+ });
3164
+ };
3165
+ const meta = typeof deprecated === "object" && deprecated ? deprecated : {};
3166
+ const replacedBy = formatReplacedBy(meta.replacedBy);
3167
+ const since = typeof meta.since === "string" ? String(meta.since) : void 0;
3168
+ const removedIn = typeof meta.removedIn === "string" ? String(meta.removedIn) : void 0;
3169
+ const message = typeof meta.message === "string" ? String(meta.message) : "";
3170
+ const loc = extractRunJSLocation(stack);
3171
+ const locText = loc.line ? `\uFF08line ${loc.line}${loc.column ? `:${loc.column}` : ""}\uFF09` : "";
3172
+ const msg = message.trim();
3173
+ const mainText = msg ? t("RunJS deprecated warning with message", {
3174
+ defaultValue: "[RunJS][Deprecated] {{api}} {{message}}{{location}}",
3175
+ api: apiPath,
3176
+ message: msg,
3177
+ location: locText
3178
+ }) : t("RunJS deprecated warning", {
3179
+ defaultValue: "[RunJS][Deprecated] {{api}} is deprecated{{location}}",
3180
+ api: apiPath,
3181
+ location: locText
3182
+ });
3183
+ const separator = t("RunJS deprecated separator", { defaultValue: "; " });
3184
+ const textParts = [mainText];
3185
+ if (replacedBy)
3186
+ textParts.push(t("RunJS deprecated replacedBy", { defaultValue: "Use {{replacedBy}} instead", replacedBy }));
3187
+ if (since) textParts.push(t("RunJS deprecated since", { defaultValue: "since {{since}}", since }));
3188
+ if (removedIn)
3189
+ textParts.push(t("RunJS deprecated removedIn", { defaultValue: "will be removed in {{removedIn}}", removedIn }));
3190
+ const text = textParts.filter(Boolean).join(separator);
3191
+ try {
3192
+ if (logger && typeof logger.warn === "function") {
3193
+ logger.warn(text);
3194
+ } else {
3195
+ console.warn(text);
3196
+ }
3197
+ } catch (_2) {
3198
+ }
3199
+ }, "warnOnce");
3200
+ const createFunctionProxy = /* @__PURE__ */ __name((fn, node, path) => {
3201
+ const dep = node.deprecated;
3202
+ if (!dep) return fn;
3203
+ const cacheByPath = functionProxyCache.get(fn) || /* @__PURE__ */ new Map();
3204
+ functionProxyCache.set(fn, cacheByPath);
3205
+ if (cacheByPath.has(path)) return cacheByPath.get(path);
3206
+ const proxied = new Proxy(fn, {
3207
+ apply(target, thisArg, argArray) {
3208
+ const stack = warned.has(path) ? void 0 : new Error().stack;
3209
+ warnOnce(path, dep, stack);
3210
+ const realThis = unwrapProxy(thisArg);
3211
+ return Reflect.apply(target, realThis, argArray);
3212
+ },
3213
+ get(target, key, receiver) {
3214
+ return Reflect.get(target, key, receiver);
3215
+ }
3216
+ });
3217
+ cacheByPath.set(path, proxied);
3218
+ return proxied;
3219
+ }, "createFunctionProxy");
3220
+ const createObjectProxy = /* @__PURE__ */ __name((target, node, path) => {
3221
+ if (!target || typeof target !== "object" && typeof target !== "function") return target;
3222
+ if (__isPromiseLike(target)) return target;
3223
+ const hasChildren = !!node.children && Object.keys(node.children).length > 0;
3224
+ if (!hasChildren && path !== "ctx") return target;
3225
+ const cacheByPath = objectProxyCache.get(target) || /* @__PURE__ */ new Map();
3226
+ objectProxyCache.set(target, cacheByPath);
3227
+ if (cacheByPath.has(path)) return cacheByPath.get(path);
3228
+ const proxied = new Proxy(target, {
3229
+ get(t, key, receiver) {
3230
+ var _a;
3231
+ if (typeof key === "symbol") {
3232
+ return Reflect.get(t, key, unwrapProxy(receiver));
3233
+ }
3234
+ const prop = String(key);
3235
+ const value = Reflect.get(t, key, unwrapProxy(receiver));
3236
+ if (path === "ctx" && prop === "defineProperty" && typeof value === "function") {
3237
+ return (...args) => {
3238
+ const result = value(...args);
3239
+ try {
3240
+ updateTreeFromDefineProperty(String((args == null ? void 0 : args[0]) ?? ""), args == null ? void 0 : args[1]);
3241
+ } catch (_2) {
3242
+ }
3243
+ return result;
3244
+ };
3245
+ }
3246
+ if (path === "ctx" && prop === "defineMethod" && typeof value === "function") {
3247
+ return (...args) => {
3248
+ const result = value(...args);
3249
+ try {
3250
+ updateTreeFromDefineMethod(String((args == null ? void 0 : args[0]) ?? ""), args == null ? void 0 : args[2]);
3251
+ } catch (_2) {
3252
+ }
3253
+ return result;
3254
+ };
3255
+ }
3256
+ const child = (_a = node.children) == null ? void 0 : _a[prop];
3257
+ if (!child) return value;
3258
+ const childPath = `${path}.${prop}`;
3259
+ if (typeof value === "function" && child.deprecated) {
3260
+ return createFunctionProxy(value, child, childPath);
3261
+ }
3262
+ if (child.deprecated) {
3263
+ const stack = warned.has(childPath) ? void 0 : new Error().stack;
3264
+ warnOnce(childPath, child.deprecated, stack);
3265
+ }
3266
+ if (value && (typeof value === "object" || typeof value === "function") && child.children) {
3267
+ return createObjectProxy(value, child, childPath);
3268
+ }
3269
+ return value;
3270
+ },
3271
+ has(t, key) {
3272
+ return Reflect.has(t, key);
3273
+ }
3274
+ });
3275
+ proxyToTarget.set(proxied, target);
3276
+ cacheByPath.set(path, proxied);
3277
+ return proxied;
3278
+ }, "createObjectProxy");
3279
+ return createObjectProxy(ctx, fromDoc, "ctx");
3280
+ }
3281
+ __name(createRunJSDeprecationProxy, "createRunJSDeprecationProxy");
3282
+ function __mergeRunJSDocDocRecord(base, patch, mergeDoc) {
3283
+ if (!__isPlainObject(patch)) return base;
3284
+ if (!__isPlainObject(base)) return patch;
3285
+ const out = { ...base };
3286
+ for (const k of Object.keys(patch)) {
3287
+ const pv = patch[k];
3288
+ if (pv === null) {
3289
+ delete out[k];
3290
+ continue;
3291
+ }
3292
+ const bv = __isPlainObject(base) ? base[k] : void 0;
3293
+ const merged = mergeDoc(bv, pv);
3294
+ if (typeof merged === "undefined") delete out[k];
3295
+ else out[k] = merged;
3296
+ }
3297
+ return out;
3298
+ }
3299
+ __name(__mergeRunJSDocDocRecord, "__mergeRunJSDocDocRecord");
3300
+ function __mergeRunJSDocPropertyDoc(base, patch) {
3301
+ if (patch === null) return void 0;
3302
+ const baseIsObj = __isPlainObject(base);
3303
+ const patchIsObj = __isPlainObject(patch);
3304
+ const baseIsStr = typeof base === "string";
3305
+ const patchIsStr = typeof patch === "string";
3306
+ if (patchIsStr) {
3307
+ if (baseIsObj) {
3308
+ return __mergeRunJSDocPropertyDoc(base, { description: patch });
3309
+ }
3310
+ return patch;
3311
+ }
3312
+ if (patchIsObj) {
3313
+ const baseObj = baseIsObj ? base : baseIsStr ? { description: base } : void 0;
3314
+ const out = { ...baseObj || {} };
3315
+ for (const k of Object.keys(patch)) {
3316
+ if (k === "properties") {
3317
+ const pv = patch.properties;
3318
+ if (pv === null) {
3319
+ delete out.properties;
3320
+ continue;
3321
+ }
3322
+ const mergedProps = __mergeRunJSDocDocRecord(baseObj == null ? void 0 : baseObj.properties, pv, __mergeRunJSDocPropertyDoc);
3323
+ if (typeof mergedProps === "undefined") delete out.properties;
3324
+ else out.properties = mergedProps;
3325
+ continue;
3326
+ }
3327
+ const mergedVal = __runjsDeepMerge(baseObj == null ? void 0 : baseObj[k], patch[k]);
3328
+ if (typeof mergedVal === "undefined") delete out[k];
3329
+ else out[k] = mergedVal;
3330
+ }
3331
+ return out;
3332
+ }
3333
+ return patch ?? base;
3334
+ }
3335
+ __name(__mergeRunJSDocPropertyDoc, "__mergeRunJSDocPropertyDoc");
3336
+ function __mergeRunJSDocMethodDoc(base, patch) {
3337
+ if (patch === null) return void 0;
3338
+ const baseIsObj = __isPlainObject(base);
3339
+ const patchIsObj = __isPlainObject(patch);
3340
+ const baseIsStr = typeof base === "string";
3341
+ const patchIsStr = typeof patch === "string";
3342
+ if (patchIsStr) {
3343
+ if (baseIsObj) {
3344
+ return __mergeRunJSDocMethodDoc(base, { description: patch });
3345
+ }
3346
+ return patch;
3347
+ }
3348
+ if (patchIsObj) {
3349
+ const baseObj = baseIsObj ? base : baseIsStr ? { description: base } : void 0;
3350
+ const out = { ...baseObj || {} };
3351
+ for (const k of Object.keys(patch)) {
3352
+ const mergedVal = __runjsDeepMerge(baseObj == null ? void 0 : baseObj[k], patch[k]);
3353
+ if (typeof mergedVal === "undefined") delete out[k];
3354
+ else out[k] = mergedVal;
3355
+ }
3356
+ return out;
3357
+ }
3358
+ return patch ?? base;
3359
+ }
3360
+ __name(__mergeRunJSDocMethodDoc, "__mergeRunJSDocMethodDoc");
3361
+ function __mergeRunJSDocMeta(base, patch) {
3362
+ const baseObj = __isPlainObject(base) ? base : {};
3363
+ const patchObj = __isPlainObject(patch) ? patch : {};
3364
+ const out = { ...baseObj };
3365
+ for (const k of Object.keys(patchObj)) {
3366
+ if (k === "properties") {
3367
+ const mergedProps = __mergeRunJSDocDocRecord(baseObj.properties, patchObj.properties, __mergeRunJSDocPropertyDoc);
3368
+ if (typeof mergedProps === "undefined") delete out.properties;
3369
+ else out.properties = mergedProps;
3370
+ continue;
3371
+ }
3372
+ if (k === "methods") {
3373
+ const mergedMethods = __mergeRunJSDocDocRecord(baseObj.methods, patchObj.methods, __mergeRunJSDocMethodDoc);
3374
+ if (typeof mergedMethods === "undefined") delete out.methods;
3375
+ else out.methods = mergedMethods;
3376
+ continue;
3377
+ }
3378
+ const mergedVal = __runjsDeepMerge(baseObj[k], patchObj[k]);
3379
+ if (typeof mergedVal === "undefined") delete out[k];
3380
+ else out[k] = mergedVal;
3381
+ }
3382
+ return out;
3383
+ }
3384
+ __name(__mergeRunJSDocMeta, "__mergeRunJSDocMeta");
1296
3385
  const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
1297
3386
  constructor(delegate) {
1298
3387
  super();
1299
3388
  this.addDelegate(delegate);
1300
3389
  this.defineProperty("React", { value: import_react.default });
1301
3390
  this.defineProperty("antd", { value: antd });
1302
- this.defineProperty("dayjs", { value: import_dayjs.default });
3391
+ this.defineProperty("dayjs", {
3392
+ value: import_dayjs.default
3393
+ });
1303
3394
  const ReactDOMShim = {
1304
3395
  ...ReactDOMClient,
1305
3396
  createRoot: /* @__PURE__ */ __name((container, options) => {
@@ -1307,15 +3398,9 @@ const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
1307
3398
  return this.engine.reactView.createRoot(realContainer, options);
1308
3399
  }, "createRoot")
1309
3400
  };
3401
+ ReactDOMShim.__nbRunjsInternalShim = true;
1310
3402
  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 });
3403
+ (0, import_runjsLibs.setupRunJSLibs)(this);
1319
3404
  this.defineMethod(
1320
3405
  "render",
1321
3406
  function(vnode, container) {
@@ -1325,52 +3410,85 @@ const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
1325
3410
  const globalRef = globalThis;
1326
3411
  globalRef.__nbRunjsRoots = globalRef.__nbRunjsRoots || /* @__PURE__ */ new WeakMap();
1327
3412
  const rootMap = globalRef.__nbRunjsRoots;
1328
- if (typeof vnode === "string") {
1329
- const existingRoot = rootMap.get(containerEl);
1330
- if (existingRoot && typeof existingRoot.unmount === "function") {
3413
+ const disposeEntry = /* @__PURE__ */ __name((entry2) => {
3414
+ if (!entry2) return;
3415
+ if (entry2.disposeTheme && typeof entry2.disposeTheme === "function") {
3416
+ try {
3417
+ entry2.disposeTheme();
3418
+ } catch (_2) {
3419
+ }
3420
+ entry2.disposeTheme = void 0;
3421
+ }
3422
+ const root = entry2.root || entry2;
3423
+ if (root && typeof root.unmount === "function") {
1331
3424
  try {
1332
- existingRoot.unmount();
1333
- } finally {
1334
- rootMap.delete(containerEl);
3425
+ root.unmount();
3426
+ } catch (_2) {
1335
3427
  }
1336
3428
  }
3429
+ }, "disposeEntry");
3430
+ const unmountContainerRoot = /* @__PURE__ */ __name(() => {
3431
+ const existing = rootMap.get(containerEl);
3432
+ if (existing) {
3433
+ disposeEntry(existing);
3434
+ rootMap.delete(containerEl);
3435
+ }
3436
+ }, "unmountContainerRoot");
3437
+ if (typeof vnode === "string") {
3438
+ unmountContainerRoot();
1337
3439
  const proxy = new import_ElementProxy.ElementProxy(containerEl);
1338
3440
  proxy.innerHTML = String(vnode ?? "");
1339
3441
  return null;
1340
3442
  }
1341
3443
  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
- }
3444
+ unmountContainerRoot();
1350
3445
  while (containerEl.firstChild) containerEl.removeChild(containerEl.firstChild);
1351
3446
  containerEl.appendChild(vnode);
1352
3447
  return null;
1353
3448
  }
1354
- let root = rootMap.get(containerEl);
1355
- if (!root) {
1356
- root = this.ReactDOM.createRoot(containerEl);
1357
- rootMap.set(containerEl, root);
3449
+ const rendererKey = this.ReactDOM;
3450
+ const ownerKey = this;
3451
+ let entry = rootMap.get(containerEl);
3452
+ if (!entry || entry.rendererKey !== rendererKey || entry.ownerKey !== ownerKey) {
3453
+ if (entry) {
3454
+ disposeEntry(entry);
3455
+ rootMap.delete(containerEl);
3456
+ }
3457
+ const root = this.ReactDOM.createRoot(containerEl);
3458
+ entry = { rendererKey, ownerKey, root, disposeTheme: void 0, lastVnode: void 0 };
3459
+ rootMap.set(containerEl, entry);
1358
3460
  }
1359
- root.render(vnode);
1360
- return root;
3461
+ return (0, import_runjsLibs.externalReactRender)({
3462
+ ctx: this,
3463
+ entry,
3464
+ vnode,
3465
+ containerEl,
3466
+ rootMap,
3467
+ unmountContainerRoot,
3468
+ internalReact: import_react.default,
3469
+ internalAntd: antd
3470
+ });
1361
3471
  }
1362
3472
  );
1363
3473
  }
3474
+ exit() {
3475
+ var _a;
3476
+ throw new import_exceptions.FlowExitAllException(this.flowKey, ((_a = this.model) == null ? void 0 : _a.uid) || "runjs");
3477
+ }
3478
+ exitAll() {
3479
+ var _a;
3480
+ throw new import_exceptions.FlowExitAllException(this.flowKey, ((_a = this.model) == null ? void 0 : _a.uid) || "runjs");
3481
+ }
1364
3482
  static define(meta, options) {
1365
3483
  const locale = options == null ? void 0 : options.locale;
1366
3484
  if (locale) {
1367
3485
  const map = __runjsClassLocaleMeta.get(this) || /* @__PURE__ */ new Map();
1368
3486
  const prev = map.get(locale) || {};
1369
- map.set(locale, __runjsDeepMerge(prev, meta));
3487
+ map.set(locale, __mergeRunJSDocMeta(prev, meta));
1370
3488
  __runjsClassLocaleMeta.set(this, map);
1371
3489
  } else {
1372
3490
  const prev = __runjsClassDefaultMeta.get(this) || {};
1373
- __runjsClassDefaultMeta.set(this, __runjsDeepMerge(prev, meta));
3491
+ __runjsClassDefaultMeta.set(this, __mergeRunJSDocMeta(prev, meta));
1374
3492
  }
1375
3493
  __runjsDocCache.delete(this);
1376
3494
  }
@@ -1387,13 +3505,13 @@ const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
1387
3505
  }
1388
3506
  let merged = {};
1389
3507
  for (const cls of chain) {
1390
- merged = __runjsDeepMerge(merged, __runjsClassDefaultMeta.get(cls) || {});
3508
+ merged = __mergeRunJSDocMeta(merged, __runjsClassDefaultMeta.get(cls) || {});
1391
3509
  }
1392
3510
  if (locale) {
1393
3511
  for (const cls of chain) {
1394
3512
  const lmap = __runjsClassLocaleMeta.get(cls);
1395
3513
  if (lmap && lmap.has(locale)) {
1396
- merged = __runjsDeepMerge(merged, lmap.get(locale));
3514
+ merged = __mergeRunJSDocMeta(merged, lmap.get(locale));
1397
3515
  }
1398
3516
  }
1399
3517
  }
@@ -1414,5 +3532,6 @@ let FlowRunJSContext = _FlowRunJSContext;
1414
3532
  FlowForkModelContext,
1415
3533
  FlowModelContext,
1416
3534
  FlowRunJSContext,
1417
- FlowRuntimeContext
3535
+ FlowRuntimeContext,
3536
+ createRunJSDeprecationProxy
1418
3537
  });