@nocobase/flow-engine 2.0.0-beta.9 → 2.0.1

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
@@ -0,0 +1,422 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var runjsModuleLoader_exports = {};
29
+ __export(runjsModuleLoader_exports, {
30
+ runjsImportAsync: () => runjsImportAsync,
31
+ runjsImportModule: () => runjsImportModule,
32
+ runjsRequireAsync: () => runjsRequireAsync
33
+ });
34
+ module.exports = __toCommonJS(runjsModuleLoader_exports);
35
+ var import_runjsLibs = require("../runjsLibs");
36
+ var import_resolveModuleUrl = require("./resolveModuleUrl");
37
+ var import_safeGlobals = require("./safeGlobals");
38
+ function snapshotOwnKeys(obj) {
39
+ try {
40
+ if (!obj || typeof obj !== "object" && typeof obj !== "function") return [];
41
+ return Object.getOwnPropertyNames(obj);
42
+ } catch (_) {
43
+ return [];
44
+ }
45
+ }
46
+ __name(snapshotOwnKeys, "snapshotOwnKeys");
47
+ function diffAddedKeys(afterKeys, beforeKeys) {
48
+ if (!afterKeys.length) return [];
49
+ if (!beforeKeys.length) return [...afterKeys];
50
+ const beforeSet = new Set(beforeKeys);
51
+ const added = [];
52
+ for (const k of afterKeys) {
53
+ if (!beforeSet.has(k)) added.push(k);
54
+ }
55
+ return added;
56
+ }
57
+ __name(diffAddedKeys, "diffAddedKeys");
58
+ async function withRunjsModuleLoadLock(task) {
59
+ const g = globalThis;
60
+ g.__nocobaseRunjsModuleLoadLock = (g.__nocobaseRunjsModuleLoadLock || Promise.resolve()).catch(() => {
61
+ });
62
+ const prev = g.__nocobaseRunjsModuleLoadLock;
63
+ let release;
64
+ const current = new Promise((resolve) => {
65
+ release = resolve;
66
+ });
67
+ g.__nocobaseRunjsModuleLoadLock = prev.then(() => current);
68
+ await prev;
69
+ try {
70
+ return await task();
71
+ } finally {
72
+ release == null ? void 0 : release();
73
+ }
74
+ }
75
+ __name(withRunjsModuleLoadLock, "withRunjsModuleLoadLock");
76
+ function disableAmdDefineTemporarily() {
77
+ const g = globalThis;
78
+ const def = g == null ? void 0 : g.define;
79
+ const amd = def == null ? void 0 : def.amd;
80
+ if (!def || !amd) return () => {
81
+ };
82
+ const desc = Object.getOwnPropertyDescriptor(def, "amd");
83
+ const hadOwn = !!desc;
84
+ const prev = amd;
85
+ try {
86
+ if (desc == null ? void 0 : desc.writable) {
87
+ def.amd = void 0;
88
+ } else if (desc == null ? void 0 : desc.configurable) {
89
+ delete def.amd;
90
+ } else {
91
+ def.amd = void 0;
92
+ }
93
+ } catch (_) {
94
+ }
95
+ return () => {
96
+ try {
97
+ if (hadOwn && desc) {
98
+ Object.defineProperty(def, "amd", desc);
99
+ return;
100
+ }
101
+ def.amd = prev;
102
+ } catch (_) {
103
+ }
104
+ };
105
+ }
106
+ __name(disableAmdDefineTemporarily, "disableAmdDefineTemporarily");
107
+ function hasPendingRequireJsLoads() {
108
+ var _a, _b;
109
+ const g = globalThis;
110
+ const req = (_a = g == null ? void 0 : g.requirejs) == null ? void 0 : _a.requirejs;
111
+ const contexts = (_b = req == null ? void 0 : req.s) == null ? void 0 : _b.contexts;
112
+ if (!contexts || typeof contexts !== "object") return false;
113
+ for (const ctxName of Object.keys(contexts)) {
114
+ const ctx = contexts[ctxName];
115
+ const registry = ctx == null ? void 0 : ctx.registry;
116
+ if (!registry || typeof registry !== "object") continue;
117
+ for (const id of Object.keys(registry)) {
118
+ const mod = registry[id];
119
+ if (!mod || typeof mod !== "object") continue;
120
+ if (!mod.enabled) continue;
121
+ if (mod.error) continue;
122
+ const map = mod.map;
123
+ if (!map || typeof map !== "object") continue;
124
+ if (!mod.inited && mod.fetched && map.isDefine) return true;
125
+ }
126
+ }
127
+ return false;
128
+ }
129
+ __name(hasPendingRequireJsLoads, "hasPendingRequireJsLoads");
130
+ async function waitForRequireJsIdle(options) {
131
+ const timeoutMs = Math.max(0, (options == null ? void 0 : options.timeoutMs) ?? 1500);
132
+ const pollMs = Math.max(10, (options == null ? void 0 : options.pollMs) ?? 30);
133
+ if (timeoutMs === 0) return;
134
+ const start = Date.now();
135
+ while (hasPendingRequireJsLoads()) {
136
+ if (Date.now() - start >= timeoutMs) return;
137
+ await new Promise((resolve) => setTimeout(resolve, pollMs));
138
+ }
139
+ }
140
+ __name(waitForRequireJsIdle, "waitForRequireJsIdle");
141
+ async function prefetchEsmModule(url, options) {
142
+ const u = typeof url === "string" ? url.trim() : "";
143
+ if (!u) return;
144
+ const g = globalThis;
145
+ g.__nocobaseImportAsyncPrefetchCache = g.__nocobaseImportAsyncPrefetchCache || /* @__PURE__ */ new Map();
146
+ const cache = g.__nocobaseImportAsyncPrefetchCache;
147
+ if (cache.has(u)) return await cache.get(u);
148
+ const timeoutMs = Math.max(0, (options == null ? void 0 : options.timeoutMs) ?? 5e3);
149
+ const task = (async () => {
150
+ var _a;
151
+ try {
152
+ if (typeof document !== "undefined" && (document == null ? void 0 : document.createElement)) {
153
+ const href = new URL(u, ((_a = globalThis == null ? void 0 : globalThis.location) == null ? void 0 : _a.href) || void 0).toString();
154
+ const head = document.head || document.getElementsByTagName("head")[0];
155
+ if (head) {
156
+ const selector = `link[rel="modulepreload"][href="${href}"]`;
157
+ const existing = document.querySelector(selector);
158
+ if (!existing) {
159
+ const link = document.createElement("link");
160
+ link.rel = "modulepreload";
161
+ link.href = href;
162
+ link.crossOrigin = "anonymous";
163
+ const done = await new Promise((resolve) => {
164
+ let settled = false;
165
+ const finalize = /* @__PURE__ */ __name(() => {
166
+ if (settled) return;
167
+ settled = true;
168
+ link.onload = null;
169
+ link.onerror = null;
170
+ resolve();
171
+ }, "finalize");
172
+ const timer = timeoutMs > 0 ? setTimeout(() => {
173
+ finalize();
174
+ }, timeoutMs) : void 0;
175
+ link.onload = () => {
176
+ if (timer) clearTimeout(timer);
177
+ finalize();
178
+ };
179
+ link.onerror = () => {
180
+ if (timer) clearTimeout(timer);
181
+ finalize();
182
+ };
183
+ head.appendChild(link);
184
+ });
185
+ return done;
186
+ }
187
+ }
188
+ }
189
+ } catch (_) {
190
+ }
191
+ try {
192
+ if (typeof fetch !== "function") return;
193
+ const controller = typeof AbortController === "function" ? new AbortController() : void 0;
194
+ const timer = controller && timeoutMs > 0 ? setTimeout(() => {
195
+ try {
196
+ controller.abort();
197
+ } catch (_) {
198
+ }
199
+ }, timeoutMs) : void 0;
200
+ const res = await fetch(u, {
201
+ method: "GET",
202
+ mode: "cors",
203
+ credentials: "omit",
204
+ cache: "force-cache",
205
+ signal: controller == null ? void 0 : controller.signal
206
+ });
207
+ if (timer) clearTimeout(timer);
208
+ if (res && res.ok && typeof res.arrayBuffer === "function") {
209
+ try {
210
+ await res.arrayBuffer();
211
+ } catch (_) {
212
+ }
213
+ }
214
+ } catch (_) {
215
+ }
216
+ })();
217
+ const safeTask = task.catch(() => {
218
+ });
219
+ cache.set(u, safeTask);
220
+ return await safeTask;
221
+ }
222
+ __name(prefetchEsmModule, "prefetchEsmModule");
223
+ async function runjsRequireAsync(requirejs, url) {
224
+ return await withRunjsModuleLoadLock(async () => {
225
+ const beforeWinKeys = typeof window !== "undefined" ? snapshotOwnKeys(window) : [];
226
+ const beforeDocKeys = typeof document !== "undefined" ? snapshotOwnKeys(document) : [];
227
+ let result;
228
+ let error;
229
+ try {
230
+ result = await new Promise((resolve, reject) => {
231
+ if (!requirejs) {
232
+ reject(new Error("requirejs is not available"));
233
+ return;
234
+ }
235
+ requirejs(
236
+ [url],
237
+ (...args) => {
238
+ resolve(args[0]);
239
+ },
240
+ reject
241
+ );
242
+ });
243
+ } catch (e) {
244
+ error = e;
245
+ } finally {
246
+ const afterWinKeys = typeof window !== "undefined" ? snapshotOwnKeys(window) : [];
247
+ const afterDocKeys = typeof document !== "undefined" ? snapshotOwnKeys(document) : [];
248
+ const addedWinKeys = diffAddedKeys(afterWinKeys, beforeWinKeys);
249
+ const addedDocKeys = diffAddedKeys(afterDocKeys, beforeDocKeys);
250
+ (0, import_safeGlobals.registerRunJSSafeWindowGlobals)(addedWinKeys);
251
+ (0, import_safeGlobals.registerRunJSSafeDocumentGlobals)(addedDocKeys);
252
+ }
253
+ if (error) throw error;
254
+ return result;
255
+ });
256
+ }
257
+ __name(runjsRequireAsync, "runjsRequireAsync");
258
+ async function runjsImportAsync(url) {
259
+ var _a;
260
+ if (!url || typeof url !== "string") {
261
+ throw new Error("invalid url");
262
+ }
263
+ const u = url.trim();
264
+ const shouldPatchAmd = !!((_a = globalThis == null ? void 0 : globalThis.define) == null ? void 0 : _a.amd);
265
+ if (shouldPatchAmd) await prefetchEsmModule(u);
266
+ return await withRunjsModuleLoadLock(async () => {
267
+ await waitForRequireJsIdle();
268
+ const restoreAmd = shouldPatchAmd ? disableAmdDefineTemporarily() : () => {
269
+ };
270
+ try {
271
+ const nativeImport = /* @__PURE__ */ __name(() => import(
272
+ /* @vite-ignore */
273
+ /* webpackIgnore: true */
274
+ u
275
+ ), "nativeImport");
276
+ const evalImport = /* @__PURE__ */ __name(() => {
277
+ const importer = (0, eval)("u => import(u)");
278
+ return importer(u);
279
+ }, "evalImport");
280
+ try {
281
+ return await nativeImport();
282
+ } catch (err) {
283
+ try {
284
+ return await evalImport();
285
+ } catch (err2) {
286
+ throw err2 || err;
287
+ }
288
+ }
289
+ } finally {
290
+ restoreAmd();
291
+ }
292
+ });
293
+ }
294
+ __name(runjsImportAsync, "runjsImportAsync");
295
+ function stripUrlQueryAndHash(input) {
296
+ const q = input.indexOf("?");
297
+ const h = input.indexOf("#");
298
+ const cut = q >= 0 && h >= 0 ? Math.min(q, h) : q >= 0 ? q : h;
299
+ return cut >= 0 ? input.slice(0, cut) : input;
300
+ }
301
+ __name(stripUrlQueryAndHash, "stripUrlQueryAndHash");
302
+ function parsePackageSpecifier(input) {
303
+ if (!input || typeof input !== "string") return null;
304
+ const s = stripUrlQueryAndHash(input).trim();
305
+ if (!s) return null;
306
+ if (s.startsWith("http://") || s.startsWith("https://")) return null;
307
+ const pathPart = s.replace(/^\//, "");
308
+ if (!pathPart) return null;
309
+ if (pathPart.startsWith("@")) {
310
+ const m2 = pathPart.match(/^(@[^/]+\/[^/]+?)(?:@([^/]+))?(?:\/(.*))?$/);
311
+ if (!m2) return null;
312
+ return { name: m2[1], version: m2[2], subpath: m2[3] };
313
+ }
314
+ const m = pathPart.match(/^([^/]+?)(?:@([^/]+))?(?:\/(.*))?$/);
315
+ if (!m) return null;
316
+ return { name: m[1], version: m[2], subpath: m[3] };
317
+ }
318
+ __name(parsePackageSpecifier, "parsePackageSpecifier");
319
+ function appendQueryParams(specifier, params) {
320
+ if (!specifier || typeof specifier !== "string") return specifier;
321
+ const s = specifier.trim();
322
+ const hashIndex = s.indexOf("#");
323
+ const baseAndQuery = hashIndex >= 0 ? s.slice(0, hashIndex) : s;
324
+ const hash = hashIndex >= 0 ? s.slice(hashIndex) : "";
325
+ const qIndex = baseAndQuery.indexOf("?");
326
+ const base = qIndex >= 0 ? baseAndQuery.slice(0, qIndex) : baseAndQuery;
327
+ const query = qIndex >= 0 ? baseAndQuery.slice(qIndex + 1) : "";
328
+ const search = new URLSearchParams(query);
329
+ for (const [k, v] of Object.entries(params)) {
330
+ if (!k) continue;
331
+ if (search.has(k)) continue;
332
+ search.set(k, v);
333
+ }
334
+ const nextQuery = search.toString();
335
+ return nextQuery ? `${base}?${nextQuery}${hash}` : `${base}${hash}`;
336
+ }
337
+ __name(appendQueryParams, "appendQueryParams");
338
+ function getEsmCdnBaseUrl() {
339
+ const g = globalThis;
340
+ if (typeof (g == null ? void 0 : g.__esm_cdn_base_url__) === "string") return g.__esm_cdn_base_url__;
341
+ const w = typeof window !== "undefined" ? window : g == null ? void 0 : g.window;
342
+ if (typeof (w == null ? void 0 : w.__esm_cdn_base_url__) === "string") return w.__esm_cdn_base_url__;
343
+ return "https://esm.sh";
344
+ }
345
+ __name(getEsmCdnBaseUrl, "getEsmCdnBaseUrl");
346
+ function normalizeModule(mod) {
347
+ if (mod && typeof mod === "object" && "default" in mod) {
348
+ const keys = Object.keys(mod);
349
+ if (keys.length === 1 && keys[0] === "default") {
350
+ return mod.default;
351
+ }
352
+ }
353
+ return mod;
354
+ }
355
+ __name(normalizeModule, "normalizeModule");
356
+ async function runjsImportModule(ctx, specifier, options) {
357
+ if (!specifier || typeof specifier !== "string") {
358
+ throw new Error("invalid url");
359
+ }
360
+ let finalSpecifier = specifier;
361
+ const parsedForRewrite = parsePackageSpecifier(specifier);
362
+ if ((parsedForRewrite == null ? void 0 : parsedForRewrite.name) === "antd" && !parsedForRewrite.subpath) {
363
+ const baseUrl = getEsmCdnBaseUrl();
364
+ if (typeof baseUrl === "string") {
365
+ const params = { bundle: "1" };
366
+ const reactInfo = ctx == null ? void 0 : ctx.__runjsExternalReact;
367
+ const reactVersion = reactInfo == null ? void 0 : reactInfo.version;
368
+ if (reactVersion && typeof reactVersion === "string") {
369
+ params.deps = `react@${reactVersion},react-dom@${reactVersion}`;
370
+ }
371
+ finalSpecifier = appendQueryParams(finalSpecifier, params);
372
+ }
373
+ }
374
+ const resolvedUrl = (0, import_resolveModuleUrl.resolveModuleUrl)(finalSpecifier, { addSuffix: (options == null ? void 0 : options.addSuffix) ?? true });
375
+ const importer = (options == null ? void 0 : options.importer) || runjsImportAsync;
376
+ const g = globalThis;
377
+ g.__nocobaseImportAsyncCache = g.__nocobaseImportAsyncCache || /* @__PURE__ */ new Map();
378
+ const cache = g.__nocobaseImportAsyncCache;
379
+ const loadTask = cache.get(resolvedUrl) || (async () => {
380
+ const mod2 = await importer(resolvedUrl);
381
+ return normalizeModule(mod2);
382
+ })();
383
+ cache.set(resolvedUrl, loadTask);
384
+ const mod = await loadTask;
385
+ const libs = ctx == null ? void 0 : ctx.libs;
386
+ if (!libs || typeof libs !== "object") return mod;
387
+ const parsed = parsePackageSpecifier(finalSpecifier);
388
+ if (!parsed) return mod;
389
+ const subpath = parsed.subpath || "";
390
+ if (parsed.name === "react" && !subpath) {
391
+ (0, import_runjsLibs.setRunJSLibOverride)(ctx, "React", mod);
392
+ ctx.__runjsExternalReact = { specifier, version: parsed.version, url: resolvedUrl };
393
+ const domSpecifier = parsed.version ? `react-dom@${parsed.version}/client` : "react-dom/client";
394
+ try {
395
+ await ctx.importAsync(domSpecifier);
396
+ } catch (err) {
397
+ const e = new Error(
398
+ `External React has been loaded via ctx.importAsync("${specifier}"), but auto-loading "${domSpecifier}" failed.
399
+ Please run: await ctx.importAsync("${domSpecifier}") to ensure ctx.render uses a matching ReactDOM.`
400
+ );
401
+ e.cause = err;
402
+ throw e;
403
+ }
404
+ } else if (parsed.name === "react-dom" && (subpath === "client" || subpath.startsWith("client/"))) {
405
+ (0, import_runjsLibs.setRunJSLibOverride)(ctx, "ReactDOM", mod);
406
+ ctx.__runjsExternalReactDOM = { specifier, version: parsed.version, url: resolvedUrl };
407
+ } else if (parsed.name === "antd" && !subpath) {
408
+ (0, import_runjsLibs.setRunJSLibOverride)(ctx, "antd", mod);
409
+ ctx.__runjsExternalAntd = { specifier, version: parsed.version, url: resolvedUrl };
410
+ } else if (parsed.name === "@ant-design/icons" && !subpath) {
411
+ (0, import_runjsLibs.setRunJSLibOverride)(ctx, "antdIcons", mod, { topLevelKey: false });
412
+ ctx.__runjsExternalAntdIcons = { specifier, version: parsed.version, url: resolvedUrl };
413
+ }
414
+ return mod;
415
+ }
416
+ __name(runjsImportModule, "runjsImportModule");
417
+ // Annotate the CommonJS export names for ESM import in node:
418
+ 0 && (module.exports = {
419
+ runjsImportAsync,
420
+ runjsImportModule,
421
+ runjsRequireAsync
422
+ });
@@ -0,0 +1,35 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ type PrepareRunJsCodeOptions = {
10
+ preprocessTemplates?: boolean;
11
+ };
12
+ /**
13
+ * 预处理 RunJS 源码,兼容旧版 `{{ ... }}` 占位符。
14
+ *
15
+ * 注意:这不是“变量解析”(这里不会计算任何值)。
16
+ * 它会把代码重写为合法的 JS,并在执行期间调用 `ctx.resolveJsonTemplate(...)` 来解析 {{ ... }}。
17
+ *
18
+ * 设计说明:
19
+ * - 为避免出现 “await is only valid in async functions” 之类的语法错误,会把所有模板解析提升到
20
+ * RunJS 程序的顶层,再用变量替换各处的出现位置。
21
+ * - 对于字符串/模板字面量,不在原位置直接包一层 `await ...`。而是保留原字面量表达式,并通过
22
+ * 一个小 helper 用 `.split().join()` 做替换,以匹配 `resolveJsonTemplate` 对 object/undefined
23
+ * 的字符串替换行为。
24
+ */
25
+ export declare function preprocessRunJsTemplates(code: string, options?: {
26
+ processBarePlaceholders?: boolean;
27
+ processStringLiterals?: boolean;
28
+ }): string;
29
+ /**
30
+ * 为执行准备用户的 RunJS 源码。
31
+ * - 可选:运行时模板兼容重写
32
+ * - JSX 转换(sucrase),确保 RunJS 可以安全使用 JSX
33
+ */
34
+ export declare function prepareRunJsCode(code: string, options?: PrepareRunJsCodeOptions): Promise<string>;
35
+ export {};