@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,33 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { FlowRunJSContext } from '../flowContext';
10
+ import { RunJSContextRegistry, type RunJSVersion } from './registry';
11
+ export type RunJSContextContributionApi = {
12
+ version: RunJSVersion;
13
+ RunJSContextRegistry: typeof RunJSContextRegistry;
14
+ FlowRunJSContext: typeof FlowRunJSContext;
15
+ };
16
+ export type RunJSContextContribution = (api: RunJSContextContributionApi) => void | Promise<void>;
17
+ /**
18
+ * Register a RunJS context/doc contribution.
19
+ *
20
+ * - If RunJS contexts have already been set up for a version, the contribution is applied immediately once.
21
+ * - Each contribution is executed at most once per version.
22
+ */
23
+ export declare function registerRunJSContextContribution(contribution: RunJSContextContribution): void;
24
+ /**
25
+ * Apply all registered contributions for a given version.
26
+ * Intended to be called by setupRunJSContexts().
27
+ */
28
+ export declare function applyRunJSContextContributions(version: RunJSVersion): Promise<void>;
29
+ /**
30
+ * Mark setupRunJSContexts() as completed for a given version.
31
+ * Used to support late contributions that should take effect without re-running setup.
32
+ */
33
+ export declare function markRunJSContextsSetupDone(version: RunJSVersion): void;
@@ -0,0 +1,88 @@
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 contributions_exports = {};
29
+ __export(contributions_exports, {
30
+ applyRunJSContextContributions: () => applyRunJSContextContributions,
31
+ markRunJSContextsSetupDone: () => markRunJSContextsSetupDone,
32
+ registerRunJSContextContribution: () => registerRunJSContextContribution
33
+ });
34
+ module.exports = __toCommonJS(contributions_exports);
35
+ var import_flowContext = require("../flowContext");
36
+ var import_registry = require("./registry");
37
+ const contributions = /* @__PURE__ */ new Set();
38
+ const appliedByVersion = /* @__PURE__ */ new Map();
39
+ const setupDoneVersions = /* @__PURE__ */ new Set();
40
+ async function applyContributionOnce(version, contribution) {
41
+ const applied = appliedByVersion.get(version) || /* @__PURE__ */ new Set();
42
+ appliedByVersion.set(version, applied);
43
+ if (applied.has(contribution)) return;
44
+ applied.add(contribution);
45
+ try {
46
+ await contribution({
47
+ version,
48
+ RunJSContextRegistry: import_registry.RunJSContextRegistry,
49
+ FlowRunJSContext: import_flowContext.FlowRunJSContext
50
+ });
51
+ } catch (error) {
52
+ applied.delete(contribution);
53
+ throw error;
54
+ }
55
+ }
56
+ __name(applyContributionOnce, "applyContributionOnce");
57
+ function registerRunJSContextContribution(contribution) {
58
+ if (typeof contribution !== "function") {
59
+ throw new Error("[flow-engine] registerRunJSContextContribution: contribution must be a function");
60
+ }
61
+ if (contributions.has(contribution)) return;
62
+ contributions.add(contribution);
63
+ for (const version of setupDoneVersions) {
64
+ void applyContributionOnce(version, contribution).catch((error) => {
65
+ try {
66
+ console.error("[flow-engine] RunJS context contribution failed:", error);
67
+ } catch (_) {
68
+ }
69
+ });
70
+ }
71
+ }
72
+ __name(registerRunJSContextContribution, "registerRunJSContextContribution");
73
+ async function applyRunJSContextContributions(version) {
74
+ for (const contribution of contributions) {
75
+ await applyContributionOnce(version, contribution);
76
+ }
77
+ }
78
+ __name(applyRunJSContextContributions, "applyRunJSContextContributions");
79
+ function markRunJSContextsSetupDone(version) {
80
+ setupDoneVersions.add(version);
81
+ }
82
+ __name(markRunJSContextsSetupDone, "markRunJSContextsSetupDone");
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ applyRunJSContextContributions,
86
+ markRunJSContextsSetupDone,
87
+ registerRunJSContextContribution
88
+ });
@@ -33,6 +33,7 @@ __export(helpers_exports, {
33
33
  getRunJSScenesForModel: () => getRunJSScenesForModel
34
34
  });
35
35
  module.exports = __toCommonJS(helpers_exports);
36
+ var import_flowContext = require("../flowContext");
36
37
  var import_JSRunner = require("../JSRunner");
37
38
  var import_registry = require("./registry");
38
39
  function getLocale(ctx) {
@@ -52,6 +53,7 @@ function getRunJSDocFor(ctx, { version = "v1" } = {}) {
52
53
  }
53
54
  __name(getRunJSDocFor, "getRunJSDocFor");
54
55
  function createJSRunnerWithVersion(options) {
56
+ var _a, _b;
55
57
  const version = (options == null ? void 0 : options.version) || "v1";
56
58
  const modelClass = (0, import_registry.getModelClassName)(this);
57
59
  const ensureFlowContext = /* @__PURE__ */ __name((obj) => obj, "ensureFlowContext");
@@ -60,7 +62,16 @@ function createJSRunnerWithVersion(options) {
60
62
  throw new Error("[RunJS] No RunJSContext registered for version/model.");
61
63
  }
62
64
  const runCtx = new Ctor(ensureFlowContext(this));
63
- const globals = { ctx: runCtx, ...(options == null ? void 0 : options.globals) || {} };
65
+ let doc = {};
66
+ try {
67
+ const locale = getLocale(this);
68
+ if ((_a = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _a.length) doc = Ctor.getDoc(locale) || {};
69
+ else doc = ((_b = Ctor == null ? void 0 : Ctor.getDoc) == null ? void 0 : _b.call(Ctor)) || {};
70
+ } catch (_) {
71
+ doc = {};
72
+ }
73
+ const deprecatedCtx = (0, import_flowContext.createRunJSDeprecationProxy)(runCtx, { doc });
74
+ const globals = { ctx: deprecatedCtx, ...(options == null ? void 0 : options.globals) || {} };
64
75
  if (modelClass === "JSFieldModel" || modelClass === "JSBlockModel") {
65
76
  if (typeof window !== "undefined") globals.window = window;
66
77
  if (typeof document !== "undefined") globals.document = document;
@@ -43,6 +43,7 @@ module.exports = __toCommonJS(setup_exports);
43
43
  var import_registry = require("./registry");
44
44
  var import_flowContext = require("../flowContext");
45
45
  var import_base = require("./contexts/base");
46
+ var import_contributions = require("./contributions");
46
47
  let done = false;
47
48
  async function setupRunJSContexts() {
48
49
  if (done) return;
@@ -50,6 +51,7 @@ async function setupRunJSContexts() {
50
51
  const [
51
52
  { JSBlockRunJSContext },
52
53
  { JSFieldRunJSContext },
54
+ { JSEditableFieldRunJSContext },
53
55
  { JSItemRunJSContext },
54
56
  { JSColumnRunJSContext },
55
57
  { FormJSFieldItemRunJSContext },
@@ -58,6 +60,7 @@ async function setupRunJSContexts() {
58
60
  ] = await Promise.all([
59
61
  import("./contexts/JSBlockRunJSContext"),
60
62
  import("./contexts/JSFieldRunJSContext"),
63
+ import("./contexts/JSEditableFieldRunJSContext"),
61
64
  import("./contexts/JSItemRunJSContext"),
62
65
  import("./contexts/JSColumnRunJSContext"),
63
66
  import("./contexts/FormJSFieldItemRunJSContext"),
@@ -68,12 +71,15 @@ async function setupRunJSContexts() {
68
71
  import_registry.RunJSContextRegistry.register(v1, "*", import_flowContext.FlowRunJSContext);
69
72
  import_registry.RunJSContextRegistry.register(v1, "JSBlockModel", JSBlockRunJSContext, { scenes: ["block"] });
70
73
  import_registry.RunJSContextRegistry.register(v1, "JSFieldModel", JSFieldRunJSContext, { scenes: ["detail"] });
74
+ import_registry.RunJSContextRegistry.register(v1, "JSEditableFieldModel", JSEditableFieldRunJSContext, { scenes: ["form"] });
71
75
  import_registry.RunJSContextRegistry.register(v1, "JSItemModel", JSItemRunJSContext, { scenes: ["form"] });
72
76
  import_registry.RunJSContextRegistry.register(v1, "JSColumnModel", JSColumnRunJSContext, { scenes: ["table"] });
73
77
  import_registry.RunJSContextRegistry.register(v1, "FormJSFieldItemModel", FormJSFieldItemRunJSContext, { scenes: ["form"] });
74
78
  import_registry.RunJSContextRegistry.register(v1, "JSRecordActionModel", JSRecordActionRunJSContext, { scenes: ["table"] });
75
79
  import_registry.RunJSContextRegistry.register(v1, "JSCollectionActionModel", JSCollectionActionRunJSContext, { scenes: ["table"] });
80
+ await (0, import_contributions.applyRunJSContextContributions)(v1);
76
81
  done = true;
82
+ (0, import_contributions.markRunJSContextsSetupDone)(v1);
77
83
  }
78
84
  __name(setupRunJSContexts, "setupRunJSContexts");
79
85
  // Annotate the CommonJS export names for ESM import in node:
@@ -33,16 +33,16 @@ const snippet = {
33
33
  contexts: ["*"],
34
34
  prefix: "sn-api-request",
35
35
  label: "API request template",
36
- description: "Basic template to send HTTP requests via ctx.api.request",
36
+ description: "Basic template to send HTTP requests via ctx.request",
37
37
  locales: {
38
38
  "zh-CN": {
39
39
  label: "API \u8BF7\u6C42\u6A21\u677F",
40
- description: "\u4F7F\u7528 ctx.api.request \u53D1\u9001 HTTP \u8BF7\u6C42\u7684\u57FA\u7840\u6A21\u677F"
40
+ description: "\u4F7F\u7528 ctx.request \u53D1\u9001 HTTP \u8BF7\u6C42\u7684\u57FA\u7840\u6A21\u677F"
41
41
  }
42
42
  },
43
43
  content: `
44
44
  // Replace url/method/params/data as needed
45
- const response = await ctx.api.request({
45
+ const response = await ctx.request({
46
46
  url: 'users:list',
47
47
  method: 'get',
48
48
  params: {
@@ -43,14 +43,13 @@ const snippet = {
43
43
  content: `
44
44
  // Import an ESM module by URL
45
45
  // Works in yarn dev and yarn start
46
- const mod = await ctx.importAsync('https://cdn.jsdelivr.net/npm/lit-html@2/+esm');
46
+ const mod = await ctx.importAsync('lit-html@2');
47
47
  const { html, render } = mod;
48
48
 
49
- ctx.element.innerHTML = '';
50
49
  const container = document.createElement('div');
51
50
  container.style.padding = '8px';
52
51
  container.style.border = '1px dashed #999';
53
- ctx.element.append(container);
52
+ ctx.render(container);
54
53
 
55
54
  render(html\`<span style="color:#52c41a;">lit-html loaded and rendered</span>\`, container);
56
55
  `
@@ -36,15 +36,20 @@ const snippet = {
36
36
  contexts: [import_JSBlockRunJSContext.JSBlockRunJSContext, import_JSFieldRunJSContext.JSFieldRunJSContext, import_FormJSFieldItemRunJSContext.FormJSFieldItemRunJSContext],
37
37
  prefix: "sn-query-selector",
38
38
  label: "Query selector",
39
- description: "Find a child element inside ctx.element using querySelector",
39
+ description: "Find a child element inside rendered DOM using querySelector",
40
40
  locales: {
41
41
  "zh-CN": {
42
42
  label: "\u67E5\u8BE2\u5B50\u5143\u7D20",
43
- description: "\u4F7F\u7528 querySelector \u5728 ctx.element \u5185\u67E5\u627E\u5B50\u5143\u7D20"
43
+ description: "\u4F7F\u7528 querySelector \u5728\u6E32\u67D3\u7684 DOM \u5185\u67E5\u627E\u5B50\u5143\u7D20"
44
44
  }
45
45
  },
46
46
  content: `
47
- const child = ctx.element.querySelector('.child-class');
47
+ const wrapper = document.createElement('div');
48
+ wrapper.innerHTML = '<div class="child-class"></div>';
49
+
50
+ ctx.render(wrapper);
51
+
52
+ const child = wrapper.querySelector('.child-class');
48
53
  if (child) {
49
54
  child.textContent = ctx.t('Hello from querySelector');
50
55
  }
@@ -42,7 +42,7 @@ const snippet = {
42
42
  },
43
43
  content: `
44
44
  // Load an external library (AMD/RequireJS)
45
- const dayjs = await ctx.requireAsync('https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js');
45
+ const dayjs = await ctx.requireAsync('dayjs@1/dayjs.min.js');
46
46
  console.log('dayjs loaded:', dayjs?.default || dayjs);
47
47
  `
48
48
  };
@@ -6,8 +6,18 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- declare const snippets: Record<string, () => Promise<any>>;
9
+ export type RunJSSnippetLoader = () => Promise<any>;
10
+ declare const snippets: Record<string, RunJSSnippetLoader | undefined>;
10
11
  export default snippets;
12
+ /**
13
+ * Register a RunJS snippet loader for editors/AI coding.
14
+ *
15
+ * - By default, an existing ref will NOT be overwritten (returns false).
16
+ * - Use { override: true } to overwrite an existing ref (returns true).
17
+ */
18
+ export declare function registerRunJSSnippet(ref: string, loader: RunJSSnippetLoader, options?: {
19
+ override?: boolean;
20
+ }): boolean;
11
21
  type EngineSnippetEntry = {
12
22
  name: string;
13
23
  prefix?: string;
@@ -39,7 +39,8 @@ var snippets_exports = {};
39
39
  __export(snippets_exports, {
40
40
  default: () => snippets_default,
41
41
  getSnippetBody: () => getSnippetBody,
42
- listSnippetsForContext: () => listSnippetsForContext
42
+ listSnippetsForContext: () => listSnippetsForContext,
43
+ registerRunJSSnippet: () => registerRunJSSnippet
43
44
  });
44
45
  module.exports = __toCommonJS(snippets_exports);
45
46
  var import_registry = require("../registry");
@@ -100,6 +101,20 @@ const snippets = {
100
101
  "scene/table/export-selected-json": /* @__PURE__ */ __name(() => import("./scene/table/export-selected-json.snippet"), "scene/table/export-selected-json")
101
102
  };
102
103
  var snippets_default = snippets;
104
+ function registerRunJSSnippet(ref, loader, options) {
105
+ if (typeof ref !== "string" || !ref.trim()) {
106
+ throw new Error("[flow-engine] registerRunJSSnippet: ref must be a non-empty string");
107
+ }
108
+ if (typeof loader !== "function") {
109
+ throw new Error("[flow-engine] registerRunJSSnippet: loader must be a function returning a Promise");
110
+ }
111
+ const key = ref.trim();
112
+ const existed = typeof snippets[key] === "function";
113
+ if (existed && !(options == null ? void 0 : options.override)) return false;
114
+ snippets[key] = loader;
115
+ return true;
116
+ }
117
+ __name(registerRunJSSnippet, "registerRunJSSnippet");
103
118
  function deriveNameFromKey(key) {
104
119
  const parts = key.split("/");
105
120
  return parts[parts.length - 1] || key;
@@ -147,7 +162,7 @@ function resolveLocaleMeta(def, locale) {
147
162
  __name(resolveLocaleMeta, "resolveLocaleMeta");
148
163
  async function getSnippetBody(ref) {
149
164
  const loader = snippets[ref];
150
- if (!loader) throw new Error(`[flow-engine] snippet not found: ${ref}`);
165
+ if (typeof loader !== "function") throw new Error(`[flow-engine] snippet not found: ${ref}`);
151
166
  const mod = await loader();
152
167
  const def = mod == null ? void 0 : mod.default;
153
168
  const content = (def == null ? void 0 : def.content) ?? (mod == null ? void 0 : mod.content) ?? (mod == null ? void 0 : mod.body) ?? "";
@@ -165,45 +180,50 @@ async function listSnippetsForContext(ctxClassName, version = "v1", locale) {
165
180
  }
166
181
  await Promise.all(
167
182
  Object.entries(snippets).map(async ([key, loader]) => {
168
- const mod = await loader();
169
- const def = (mod == null ? void 0 : mod.default) || {};
170
- const body = (def == null ? void 0 : def.content) ?? (mod == null ? void 0 : mod.content);
171
- if (typeof body !== "string") return;
172
- let ok = true;
173
- if (Array.isArray(def == null ? void 0 : def.contexts) && def.contexts.length) {
174
- const ctxNames = def.contexts.map((item) => {
175
- if (item === "*") return "*";
176
- if (typeof item === "string") return item;
177
- if (typeof item === "function") return item.name || "*";
178
- if (item && typeof item === "object" && typeof item.name === "string") return item.name;
179
- return String(item ?? "");
180
- });
181
- if (ctxClassName === "*") {
182
- ok = true;
183
- } else {
184
- ok = ctxNames.includes("*") || ctxNames.some((name2) => allowedContextNames.has(name2));
183
+ if (typeof loader !== "function") return;
184
+ try {
185
+ const mod = await loader();
186
+ const def = (mod == null ? void 0 : mod.default) || {};
187
+ const body = (def == null ? void 0 : def.content) ?? (mod == null ? void 0 : mod.content);
188
+ if (typeof body !== "string") return;
189
+ let ok = true;
190
+ if (Array.isArray(def == null ? void 0 : def.contexts) && def.contexts.length) {
191
+ const ctxNames = def.contexts.map((item) => {
192
+ if (item === "*") return "*";
193
+ if (typeof item === "string") return item;
194
+ if (typeof item === "function") return item.name || "*";
195
+ if (item && typeof item === "object" && typeof item.name === "string") return item.name;
196
+ return String(item ?? "");
197
+ });
198
+ if (ctxClassName === "*") {
199
+ ok = true;
200
+ } else {
201
+ ok = ctxNames.includes("*") || ctxNames.some((name2) => allowedContextNames.has(name2));
202
+ }
185
203
  }
204
+ if (ok && Array.isArray(def == null ? void 0 : def.versions) && def.versions.length) {
205
+ ok = def.versions.includes("*") || def.versions.includes(version);
206
+ }
207
+ if (!ok) return;
208
+ const localeMeta = resolveLocaleMeta(def, locale);
209
+ const name = localeMeta.label || (def == null ? void 0 : def.label) || deriveNameFromKey(key);
210
+ const description = localeMeta.description ?? (def == null ? void 0 : def.description);
211
+ const prefix = (def == null ? void 0 : def.prefix) || name;
212
+ const groups = computeGroups(def, key);
213
+ const scenes = normalizeScenes(def, key);
214
+ entries.push({
215
+ name,
216
+ prefix,
217
+ description,
218
+ body,
219
+ ref: key,
220
+ group: groups[0],
221
+ groups,
222
+ scenes
223
+ });
224
+ } catch (_) {
225
+ return;
186
226
  }
187
- if (ok && Array.isArray(def == null ? void 0 : def.versions) && def.versions.length) {
188
- ok = def.versions.includes("*") || def.versions.includes(version);
189
- }
190
- if (!ok) return;
191
- const localeMeta = resolveLocaleMeta(def, locale);
192
- const name = localeMeta.label || (def == null ? void 0 : def.label) || deriveNameFromKey(key);
193
- const description = localeMeta.description ?? (def == null ? void 0 : def.description);
194
- const prefix = (def == null ? void 0 : def.prefix) || name;
195
- const groups = computeGroups(def, key);
196
- const scenes = normalizeScenes(def, key);
197
- entries.push({
198
- name,
199
- prefix,
200
- description,
201
- body,
202
- ref: key,
203
- group: groups[0],
204
- groups,
205
- scenes
206
- });
207
227
  })
208
228
  );
209
229
  return entries;
@@ -212,5 +232,6 @@ __name(listSnippetsForContext, "listSnippetsForContext");
212
232
  // Annotate the CommonJS export names for ESM import in node:
213
233
  0 && (module.exports = {
214
234
  getSnippetBody,
215
- listSnippetsForContext
235
+ listSnippetsForContext,
236
+ registerRunJSSnippet
216
237
  });
@@ -43,13 +43,16 @@ const snippet = {
43
43
  },
44
44
  content: `
45
45
  // Render a button and bind a click handler
46
- ctx.element.innerHTML = \`
47
- <button id="nb-jsb-btn" style="padding:6px 12px">\${ctx.t('Click me')}</button>
48
- \`;
49
- const btn = document.getElementById('nb-jsb-btn');
50
- if (btn) {
51
- btn.addEventListener('click', () => ctx.message.success(ctx.t('Clicked!')));
52
- }
46
+ const button = document.createElement('button');
47
+ button.textContent = ctx.t('Click me');
48
+ button.style.padding = '6px 12px';
49
+ button.addEventListener('click', () => ctx.message.success(ctx.t('Clicked!')));
50
+
51
+ const wrapper = document.createElement('div');
52
+ wrapper.style.padding = '12px';
53
+ wrapper.appendChild(button);
54
+
55
+ ctx.render(wrapper);
53
56
  `
54
57
  };
55
58
  var add_event_listener_snippet_default = snippet;
@@ -43,7 +43,7 @@ const snippet = {
43
43
  },
44
44
  content: `
45
45
  // Fetch users
46
- const { data } = await ctx.api.request({
46
+ const { data } = await ctx.request({
47
47
  url: 'users:list',
48
48
  method: 'get',
49
49
  params: { pageSize: 5 },
@@ -51,14 +51,14 @@ const { data } = await ctx.api.request({
51
51
  const rows = Array.isArray(data?.data) ? data.data : (Array.isArray(data) ? data : []);
52
52
 
53
53
  // Render as a simple HTML list
54
- ctx.element.innerHTML = [
54
+ ctx.render([
55
55
  '<div style="padding:12px">',
56
56
  '<h4 style="margin:0 0 8px">' + ctx.t('Users') + '</h4>',
57
57
  '<ul style="margin:0; padding-left:20px">',
58
58
  ...rows.map((r, i) => '<li>#' + (i + 1) + ': ' + String((r && (r.nickname ?? r.username ?? r.id)) ?? '') + '</li>'),
59
59
  '</ul>',
60
60
  '</div>'
61
- ].join('');
61
+ ].join(''));
62
62
  `
63
63
  };
64
64
  var api_fetch_render_list_snippet_default = snippet;
@@ -52,10 +52,10 @@ const canvas = document.createElement('canvas');
52
52
  canvas.width = 480;
53
53
  canvas.height = 320;
54
54
  wrapper.appendChild(canvas);
55
- ctx.element.replaceChildren(wrapper);
55
+ ctx.render(wrapper);
56
56
 
57
57
  async function renderChart() {
58
- const loaded = await ctx.requireAsync('https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js');
58
+ const loaded = await ctx.requireAsync('chart.js@4.4.0/dist/chart.umd.min.js');
59
59
  const Chart = loaded?.Chart || loaded?.default?.Chart || loaded?.default;
60
60
  if (!Chart) {
61
61
  throw new Error('Chart.js is not available');
@@ -45,8 +45,8 @@ const snippet = {
45
45
  const container = document.createElement('div');
46
46
  container.style.height = '400px';
47
47
  container.style.width = '100%';
48
- ctx.element.replaceChildren(container);
49
- const echarts = await ctx.requireAsync('https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js');
48
+ ctx.render(container);
49
+ const echarts = await ctx.requireAsync('echarts@5/dist/echarts.min.js');
50
50
  if (!echarts) {
51
51
  throw new Error('ECharts library not loaded');
52
52
  }
@@ -50,8 +50,8 @@ iframe.style.width = '100%';
50
50
  iframe.style.height = '100%';
51
51
  iframe.style.border = 'none';
52
52
 
53
- // Replace existing children so the iframe is the only content
54
- ctx.element.replaceChildren(iframe);
53
+ // Render the iframe as the only content
54
+ ctx.render(iframe);
55
55
  `
56
56
  };
57
57
  var render_iframe_snippet_default = snippet;
@@ -42,7 +42,7 @@ const snippet = {
42
42
  }
43
43
  },
44
44
  content: `
45
- // Render a React element into ctx.element via ReactDOM
45
+ // Render a React element into the current container
46
46
  const { Button } = ctx.libs.antd;
47
47
 
48
48
  ctx.render(
@@ -44,7 +44,7 @@ const snippet = {
44
44
  content: `
45
45
  const { Card, Statistic, Row, Col } = ctx.libs.antd;
46
46
 
47
- const res = await ctx.api.request({
47
+ const res = await ctx.request({
48
48
  url: 'users:list',
49
49
  method: 'get',
50
50
  params: {
@@ -44,7 +44,7 @@ const snippet = {
44
44
  content: `
45
45
  const { Timeline, Card } = ctx.libs.antd;
46
46
 
47
- const res = await ctx.api.request({
47
+ const res = await ctx.request({
48
48
  url: 'users:list',
49
49
  method: 'get',
50
50
  params: {
@@ -34,27 +34,27 @@ const snippet = {
34
34
  contexts: [import_JSBlockRunJSContext.JSBlockRunJSContext],
35
35
  prefix: "sn-resource-example",
36
36
  label: "Resource example",
37
- description: "Create a resource via ctx.createResource and render JSON output",
37
+ description: "Create a resource via ctx.makeResource and render JSON output",
38
38
  locales: {
39
39
  "zh-CN": {
40
40
  label: "\u8D44\u6E90\u793A\u4F8B",
41
- description: "\u4F7F\u7528 ctx.useResource \u52A0\u8F7D\u6570\u636E\u5E76\u6E32\u67D3 JSON \u8F93\u51FA"
41
+ description: "\u4F7F\u7528 ctx.initResource \u52A0\u8F7D\u6570\u636E\u5E76\u6E32\u67D3 JSON \u8F93\u51FA"
42
42
  }
43
43
  },
44
44
  content: `
45
45
  // Create a resource and load a single record
46
- const resource = ctx.createResource('SingleRecordResource');
46
+ const resource = ctx.makeResource('SingleRecordResource');
47
47
  resource.setDataSourceKey('main');
48
48
  resource.setResourceName('users');
49
49
  // Optionally set filterByTk to target a specific record:
50
50
  // resource.setRequestOptions('params', { filterByTk: 1 });
51
51
  await resource.refresh();
52
52
 
53
- ctx.element.innerHTML = \`
53
+ ctx.render(\`
54
54
  <pre style="padding: 12px; background: #f5f5f5; border-radius: 6px;">
55
55
  \${JSON.stringify(resource.getData(), null, 2)}
56
56
  </pre>
57
- \`;
57
+ \`);
58
58
  `
59
59
  };
60
60
  var resource_example_snippet_default = snippet;
@@ -50,12 +50,12 @@ container.style.position = 'relative';
50
50
  container.style.borderRadius = '10px';
51
51
  container.style.overflow = 'hidden';
52
52
  container.style.background = 'radial-gradient(700px 300px at 20% 25%, #172036, #0b0f19 60%), radial-gradient(600px 240px at 80% 70%, rgba(56,189,248,0.12), transparent 60%)';
53
- ctx.element.replaceChildren(container);
53
+ ctx.render(container);
54
54
 
55
55
  // \u4E0D\u505A\u663E\u5F0F\u6E05\u7406\u903B\u8F91\uFF1B\u5982\u9700\u5B58\u50A8\u4FE1\u606F\uFF0C\u7EDF\u4E00\u6302\u5728 ctx.model \u4E0A
56
56
 
57
- // \u4F7F\u7528 ctx.useResource \u52A0\u8F7D users:list\uFF08\u771F\u5B9E\u6570\u636E\uFF09
58
- ctx.useResource('MultiRecordResource');
57
+ // \u4F7F\u7528 ctx.initResource \u52A0\u8F7D users:list\uFF08\u771F\u5B9E\u6570\u636E\uFF09
58
+ ctx.initResource('MultiRecordResource');
59
59
  const resource = ctx.resource;
60
60
  resource.setDataSourceKey && resource.setDataSourceKey('main');
61
61
  resource.setResourceName && resource.setResourceName('users');
@@ -64,7 +64,7 @@ try {
64
64
  await resource.refresh();
65
65
  } catch (err) {
66
66
  var msg = (err && err.message) ? err.message : 'users:list \u8BF7\u6C42\u5931\u8D25';
67
- ctx.element.innerHTML = '<div style="color:#cbd5e1; padding: 12px; text-align:center;">' + msg + '</div>';
67
+ container.innerHTML = '<div style="color:#cbd5e1; padding: 12px; text-align:center;">' + msg + '</div>';
68
68
  throw err;
69
69
  }
70
70
 
@@ -100,7 +100,7 @@ function makeAvatarTexture(user, idx) {
100
100
  return tex;
101
101
  }
102
102
 
103
- const THREE = await ctx.importAsync('https://esm.sh/three@0.160.0');
103
+ const THREE = await ctx.importAsync('three@0.160.0');
104
104
  const { Scene, PerspectiveCamera, WebGLRenderer, Color, AmbientLight, DirectionalLight, Group, Mesh, MeshStandardMaterial, SphereGeometry, Raycaster, Vector2 } = THREE;
105
105
 
106
106
  const scene = new Scene();
@@ -206,7 +206,7 @@ async function getPrimaryKeyField() {
206
206
  if (__pkField) return __pkField;
207
207
  const name = (resource && resource.getResourceName) ? resource.getResourceName() : 'users';
208
208
  try {
209
- const meta = await ctx.api.request({ url: 'collections:get', method: 'get', params: { filterByTk: name } });
209
+ const meta = await ctx.request({ url: 'collections:get', method: 'get', params: { filterByTk: name } });
210
210
  const data = (meta && meta.data) ? meta.data : {};
211
211
  // prefer filterTargetKey, fallback to fields.primaryKey
212
212
  const ft = (data && data.filterTargetKey) ? data.filterTargetKey : (data && data.options && data.options.filterTargetKey);
@@ -49,10 +49,10 @@ mountNode.style.borderRadius = '8px';
49
49
  const target = document.createElement('div');
50
50
  target.className = 'nb-vue-counter';
51
51
  mountNode.appendChild(target);
52
- ctx.element.replaceChildren(mountNode);
52
+ ctx.render(mountNode);
53
53
 
54
54
  async function bootstrap() {
55
- const mod = await ctx.importAsync('https://esm.sh/vue@3.4.27/dist/vue.runtime.esm-browser.js');
55
+ const mod = await ctx.importAsync('vue@3.4.27/dist/vue.runtime.esm-browser.js');
56
56
  const createApp = mod?.createApp;
57
57
  const ref = mod?.ref;
58
58
  const h = mod?.h;
@@ -111,8 +111,7 @@ async function bootstrap() {
111
111
  };
112
112
 
113
113
  const app = createApp(Counter);
114
- const mountTarget = ctx.element.querySelector('.nb-vue-counter');
115
- app.mount(mountTarget || ctx.element);
114
+ app.mount(target);
116
115
  }
117
116
 
118
117
  bootstrap().catch((error) => {