@nocobase/flow-engine 2.0.0-alpha.9 → 2.0.0-beta.2

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 (305) hide show
  1. package/lib/BlockScopedFlowEngine.d.ts +23 -0
  2. package/lib/BlockScopedFlowEngine.js +92 -0
  3. package/lib/FlowDefinition.d.ts +6 -4
  4. package/lib/JSRunner.js +3 -0
  5. package/lib/ViewScopedFlowEngine.js +15 -1
  6. package/lib/acl/Acl.d.ts +12 -12
  7. package/lib/acl/Acl.js +78 -30
  8. package/lib/components/DynamicFlowsEditor.js +2 -4
  9. package/lib/components/FieldModelRenderer.js +10 -8
  10. package/lib/components/FieldSkeleton.d.ts +10 -0
  11. package/lib/components/FieldSkeleton.js +64 -0
  12. package/lib/components/FlowContextSelector.js +19 -3
  13. package/lib/components/FlowModelRenderer.d.ts +2 -1
  14. package/lib/components/FlowModelRenderer.js +34 -12
  15. package/lib/components/FormItem.js +5 -1
  16. package/lib/components/MobilePopup.d.ts +20 -0
  17. package/lib/components/MobilePopup.js +102 -0
  18. package/lib/components/MobilePopup.style.d.ts +17 -0
  19. package/lib/components/MobilePopup.style.js +186 -0
  20. package/lib/components/common/withFlowDesignMode.d.ts +1 -1
  21. package/lib/components/common/withFlowDesignMode.js +5 -5
  22. package/lib/components/index.d.ts +1 -0
  23. package/lib/components/index.js +3 -1
  24. package/lib/components/settings/independents/dropdown/FlowsDropdownButton.js +71 -53
  25. package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +19 -0
  26. package/lib/components/settings/wrappers/component/SelectWithTitle.js +136 -0
  27. package/lib/components/settings/wrappers/component/SwitchWithTitle.d.ts +10 -0
  28. package/lib/components/settings/wrappers/component/SwitchWithTitle.js +110 -0
  29. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +221 -93
  30. package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +71 -54
  31. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +2 -2
  32. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +63 -23
  33. package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +11 -6
  34. package/lib/components/settings/wrappers/embedded/FlowSettings.js +42 -28
  35. package/lib/components/settings/wrappers/embedded/FlowsSettings.js +3 -3
  36. package/lib/components/settings/wrappers/embedded/FlowsSettingsContent.js +52 -32
  37. package/lib/components/subModel/AddSubModelButton.d.ts +7 -0
  38. package/lib/components/subModel/AddSubModelButton.js +78 -8
  39. package/lib/components/subModel/LazyDropdown.js +14 -15
  40. package/lib/components/subModel/utils.d.ts +1 -1
  41. package/lib/components/subModel/utils.js +21 -11
  42. package/lib/components/variables/VariableInput.js +5 -3
  43. package/lib/components/variables/types.d.ts +2 -0
  44. package/lib/components/variables/utils.js +4 -2
  45. package/lib/data-source/index.d.ts +43 -4
  46. package/lib/data-source/index.js +104 -11
  47. package/lib/data-source/jioToJoiSchema.js +1 -0
  48. package/lib/emitter.d.ts +6 -0
  49. package/lib/emitter.js +12 -0
  50. package/lib/executor/FlowExecutor.js +48 -7
  51. package/lib/flow-registry/GlobalFlowRegistry.d.ts +1 -0
  52. package/lib/flow-registry/GlobalFlowRegistry.js +3 -0
  53. package/lib/flow-registry/InstanceFlowRegistry.d.ts +1 -0
  54. package/lib/flow-registry/InstanceFlowRegistry.js +3 -0
  55. package/lib/flowContext.d.ts +6 -0
  56. package/lib/flowContext.js +111 -30
  57. package/lib/flowEngine.d.ts +49 -0
  58. package/lib/flowEngine.js +265 -10
  59. package/lib/flowSettings.d.ts +4 -3
  60. package/lib/flowSettings.js +33 -11
  61. package/lib/hooks/useApplyAutoFlows.d.ts +1 -0
  62. package/lib/hooks/useApplyAutoFlows.js +2 -2
  63. package/lib/index.d.ts +4 -2
  64. package/lib/index.js +11 -5
  65. package/lib/locale/de-DE.json +62 -0
  66. package/lib/locale/en-US.json +57 -45
  67. package/lib/locale/es-ES.json +62 -0
  68. package/lib/locale/fr-FR.json +62 -0
  69. package/lib/locale/hu-HU.json +62 -0
  70. package/lib/locale/id-ID.json +62 -0
  71. package/lib/locale/index.d.ts +114 -90
  72. package/lib/locale/it-IT.json +62 -0
  73. package/lib/locale/ja-JP.json +62 -0
  74. package/lib/locale/ko-KR.json +62 -0
  75. package/lib/locale/nl-NL.json +62 -0
  76. package/lib/locale/pt-BR.json +62 -0
  77. package/lib/locale/ru-RU.json +62 -0
  78. package/lib/locale/tr-TR.json +62 -0
  79. package/lib/locale/uk-UA.json +62 -0
  80. package/lib/locale/vi-VN.json +62 -0
  81. package/lib/locale/zh-CN.json +58 -46
  82. package/lib/locale/zh-TW.json +62 -0
  83. package/lib/models/CollectionFieldModel.d.ts +6 -2
  84. package/lib/models/CollectionFieldModel.js +60 -14
  85. package/lib/models/flowModel.d.ts +43 -4
  86. package/lib/models/flowModel.js +128 -26
  87. package/lib/models/forkFlowModel.d.ts +6 -2
  88. package/lib/models/forkFlowModel.js +9 -2
  89. package/lib/provider.d.ts +3 -1
  90. package/lib/provider.js +4 -3
  91. package/lib/reactive/index.d.ts +10 -0
  92. package/lib/reactive/index.js +41 -0
  93. package/lib/reactive/observer.d.ts +19 -0
  94. package/lib/reactive/observer.js +109 -0
  95. package/lib/resources/baseRecordResource.d.ts +1 -0
  96. package/lib/resources/baseRecordResource.js +14 -3
  97. package/lib/resources/multiRecordResource.d.ts +4 -2
  98. package/lib/resources/multiRecordResource.js +15 -6
  99. package/lib/resources/singleRecordResource.js +6 -3
  100. package/lib/resources/sqlResource.d.ts +1 -0
  101. package/lib/resources/sqlResource.js +22 -25
  102. package/lib/runjs-context/contexts/base.js +42 -6
  103. package/lib/runjs-context/snippets/global/clipboard-copy-text.snippet.d.ts +11 -0
  104. package/lib/runjs-context/snippets/global/clipboard-copy-text.snippet.js +61 -0
  105. package/lib/runjs-context/snippets/index.js +3 -0
  106. package/lib/runjs-context/snippets/scene/block/render-antd-icons.snippet.d.ts +11 -0
  107. package/lib/runjs-context/snippets/scene/block/render-antd-icons.snippet.js +65 -0
  108. package/lib/runjs-context/snippets/scene/block/render-button-handler.snippet.js +6 -4
  109. package/lib/runjs-context/snippets/scene/block/render-info-card.snippet.js +15 -16
  110. package/lib/runjs-context/snippets/scene/block/render-react-jsx.snippet.d.ts +11 -0
  111. package/lib/runjs-context/snippets/scene/block/render-react-jsx.snippet.js +58 -0
  112. package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +7 -7
  113. package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +24 -29
  114. package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +20 -21
  115. package/lib/scheduler/ModelOperationScheduler.d.ts +51 -0
  116. package/lib/scheduler/ModelOperationScheduler.js +262 -0
  117. package/lib/types.d.ts +42 -7
  118. package/lib/types.js +4 -3
  119. package/lib/utils/associationObjectVariable.d.ts +32 -0
  120. package/lib/utils/associationObjectVariable.js +157 -0
  121. package/lib/utils/createCollectionContextMeta.d.ts +1 -1
  122. package/lib/utils/createCollectionContextMeta.js +8 -4
  123. package/lib/utils/createEphemeralContext.d.ts +13 -0
  124. package/lib/utils/createEphemeralContext.js +140 -0
  125. package/lib/utils/flows.d.ts +10 -0
  126. package/lib/utils/flows.js +48 -0
  127. package/lib/utils/index.d.ts +7 -3
  128. package/lib/utils/index.js +20 -0
  129. package/lib/utils/jsxTransform.d.ts +15 -0
  130. package/lib/utils/jsxTransform.js +68 -0
  131. package/lib/utils/params-resolvers.js +3 -3
  132. package/lib/utils/parsePathnameToViewParams.d.ts +1 -1
  133. package/lib/utils/parsePathnameToViewParams.js +41 -5
  134. package/lib/utils/pruneFilter.d.ts +21 -0
  135. package/lib/utils/pruneFilter.js +52 -0
  136. package/lib/utils/safeGlobals.d.ts +5 -3
  137. package/lib/utils/safeGlobals.js +42 -1
  138. package/lib/utils/schema-utils.d.ts +6 -0
  139. package/lib/utils/schema-utils.js +71 -6
  140. package/lib/utils/serverContextParams.d.ts +3 -0
  141. package/lib/utils/serverContextParams.js +2 -0
  142. package/lib/utils/translation.d.ts +4 -1
  143. package/lib/utils/translation.js +6 -2
  144. package/lib/utils/variablesParams.d.ts +21 -5
  145. package/lib/utils/variablesParams.js +103 -34
  146. package/lib/views/DialogComponent.js +1 -5
  147. package/lib/views/DrawerComponent.js +18 -9
  148. package/lib/views/PageComponent.js +3 -4
  149. package/lib/views/ViewNavigation.d.ts +11 -15
  150. package/lib/views/ViewNavigation.js +37 -19
  151. package/lib/views/createViewMeta.d.ts +3 -2
  152. package/lib/views/createViewMeta.js +164 -53
  153. package/lib/views/useDialog.d.ts +2 -1
  154. package/lib/views/useDialog.js +36 -30
  155. package/lib/views/useDrawer.d.ts +2 -1
  156. package/lib/views/useDrawer.js +33 -26
  157. package/lib/views/usePage.d.ts +2 -1
  158. package/lib/views/usePage.js +40 -29
  159. package/package.json +6 -3
  160. package/src/BlockScopedFlowEngine.ts +88 -0
  161. package/src/JSRunner.ts +3 -0
  162. package/src/ViewScopedFlowEngine.ts +16 -0
  163. package/src/__tests__/JSRunner.test.ts +62 -53
  164. package/src/__tests__/blockScopedFlowEngine.test.ts +154 -0
  165. package/src/__tests__/createViewMeta.popup.test.ts +142 -0
  166. package/src/__tests__/flow-engine.test.ts +3 -0
  167. package/src/__tests__/flowContext.test.ts +70 -0
  168. package/src/__tests__/flowEngine.destroyModel.test.ts +74 -0
  169. package/src/__tests__/flowEngine.moveModel.test.ts +43 -0
  170. package/src/__tests__/flowEngine.removeModel.test.ts +72 -0
  171. package/src/__tests__/flowEngine.saveModel.test.ts +4 -0
  172. package/src/__tests__/flowModel.openView.navigation.test.ts +3 -2
  173. package/src/__tests__/flowSettings.open.test.tsx +2 -0
  174. package/src/__tests__/flowSettings.test.ts +2 -0
  175. package/src/__tests__/globalFlowRegistry.test.ts +1 -1
  176. package/src/__tests__/modelOperationScheduler.test.ts +346 -0
  177. package/src/__tests__/objectVariable.test.ts +464 -0
  178. package/src/__tests__/runjsRuntimeFeatures.test.ts +12 -0
  179. package/src/__tests__/viewScopedFlowEngine.test.ts +98 -0
  180. package/src/acl/Acl.tsx +85 -31
  181. package/src/acl/__tests__/Acl.test.tsx +43 -1
  182. package/src/components/DynamicFlowsEditor.tsx +0 -10
  183. package/src/components/FieldModelRenderer.tsx +15 -8
  184. package/src/components/FieldSkeleton.tsx +27 -0
  185. package/src/components/FlowContextSelector.tsx +20 -2
  186. package/src/components/FlowModelRenderer.tsx +46 -12
  187. package/src/components/FormItem.tsx +8 -1
  188. package/src/components/MobilePopup.style.ts +220 -0
  189. package/src/components/MobilePopup.tsx +86 -0
  190. package/src/components/__tests__/FlowModelRenderer.test.tsx +89 -0
  191. package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +1 -1
  192. package/src/components/common/withFlowDesignMode.tsx +5 -5
  193. package/src/components/index.ts +1 -0
  194. package/src/components/settings/independents/dropdown/FlowsDropdownButton.tsx +34 -17
  195. package/src/components/settings/wrappers/component/SelectWithTitle.tsx +110 -0
  196. package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +82 -0
  197. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +260 -121
  198. package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +34 -18
  199. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +56 -18
  200. package/src/components/settings/wrappers/contextual/StepSettings.tsx +1 -2
  201. package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +12 -6
  202. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +565 -0
  203. package/src/components/settings/wrappers/embedded/FlowSettings.tsx +47 -35
  204. package/src/components/settings/wrappers/embedded/FlowsSettings.tsx +1 -1
  205. package/src/components/settings/wrappers/embedded/FlowsSettingsContent.tsx +64 -42
  206. package/src/components/subModel/AddSubModelButton.tsx +104 -9
  207. package/src/components/subModel/LazyDropdown.tsx +14 -14
  208. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +168 -7
  209. package/src/components/subModel/__tests__/utils.test.ts +12 -12
  210. package/src/components/subModel/utils.ts +25 -6
  211. package/src/components/variables/VariableInput.tsx +5 -3
  212. package/src/components/variables/types.ts +2 -0
  213. package/src/components/variables/utils.ts +7 -3
  214. package/src/data-source/index.ts +169 -11
  215. package/src/data-source/jioToJoiSchema.ts +1 -0
  216. package/src/emitter.ts +14 -0
  217. package/src/executor/FlowExecutor.ts +56 -8
  218. package/src/executor/__tests__/ctx-defs-injection.test.ts +197 -0
  219. package/src/flow-registry/GlobalFlowRegistry.ts +1 -0
  220. package/src/flow-registry/InstanceFlowRegistry.ts +1 -0
  221. package/src/flow-registry/__tests__/globalFlowRegistry.test.ts +54 -0
  222. package/src/flowContext.ts +144 -29
  223. package/src/flowEngine.ts +328 -8
  224. package/src/flowSettings.ts +47 -19
  225. package/src/hooks/useApplyAutoFlows.ts +3 -3
  226. package/src/index.ts +4 -2
  227. package/src/locale/de-DE.json +62 -0
  228. package/src/locale/en-US.json +57 -45
  229. package/src/locale/es-ES.json +62 -0
  230. package/src/locale/fr-FR.json +62 -0
  231. package/src/locale/hu-HU.json +62 -0
  232. package/src/locale/id-ID.json +62 -0
  233. package/src/locale/it-IT.json +62 -0
  234. package/src/locale/ja-JP.json +62 -0
  235. package/src/locale/ko-KR.json +62 -0
  236. package/src/locale/nl-NL.json +62 -0
  237. package/src/locale/pt-BR.json +62 -0
  238. package/src/locale/ru-RU.json +62 -0
  239. package/src/locale/tr-TR.json +62 -0
  240. package/src/locale/uk-UA.json +62 -0
  241. package/src/locale/vi-VN.json +62 -0
  242. package/src/locale/zh-CN.json +58 -46
  243. package/src/locale/zh-TW.json +62 -0
  244. package/src/models/CollectionFieldModel.tsx +79 -17
  245. package/src/models/__tests__/dispatchEvent.behavior.test.ts +169 -0
  246. package/src/models/__tests__/flowEngine.resolveUse.test.ts +170 -0
  247. package/src/models/__tests__/flowModel.getFlows.sort.test.ts +29 -5
  248. package/src/models/__tests__/flowModel.scheduleModelOperation.test.tsx +129 -0
  249. package/src/models/__tests__/flowModel.test.ts +65 -27
  250. package/src/models/__tests__/forkFlowModel.test.ts +40 -7
  251. package/src/models/flowModel.tsx +192 -30
  252. package/src/models/forkFlowModel.ts +11 -3
  253. package/src/provider.tsx +5 -5
  254. package/src/reactive/__tests__/observer.test.tsx +211 -0
  255. package/src/reactive/index.ts +11 -0
  256. package/src/reactive/observer.tsx +101 -0
  257. package/src/resources/baseRecordResource.ts +15 -3
  258. package/src/resources/multiRecordResource.ts +17 -8
  259. package/src/resources/singleRecordResource.ts +6 -3
  260. package/src/resources/sqlResource.ts +22 -26
  261. package/src/runjs-context/contexts/base.ts +47 -6
  262. package/src/runjs-context/snippets/global/clipboard-copy-text.snippet.ts +42 -0
  263. package/src/runjs-context/snippets/index.ts +3 -0
  264. package/src/runjs-context/snippets/scene/block/render-antd-icons.snippet.ts +46 -0
  265. package/src/runjs-context/snippets/scene/block/render-button-handler.snippet.ts +6 -4
  266. package/src/runjs-context/snippets/scene/block/render-info-card.snippet.ts +15 -16
  267. package/src/runjs-context/snippets/scene/block/render-react-jsx.snippet.ts +39 -0
  268. package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +7 -7
  269. package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +24 -29
  270. package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +20 -21
  271. package/src/scheduler/ModelOperationScheduler.ts +304 -0
  272. package/src/types.ts +50 -4
  273. package/src/utils/__tests__/createCollectionContextMeta.test.ts +51 -0
  274. package/src/utils/__tests__/flows.test.ts +65 -0
  275. package/src/utils/__tests__/jsxTransform.test.ts +38 -0
  276. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +25 -0
  277. package/src/utils/__tests__/pruneFilter.test.ts +38 -0
  278. package/src/utils/__tests__/safeGlobals.test.ts +23 -1
  279. package/src/utils/__tests__/utils.test.ts +114 -15
  280. package/src/utils/__tests__/variablesParams.test.ts +120 -0
  281. package/src/utils/associationObjectVariable.ts +180 -0
  282. package/src/utils/createCollectionContextMeta.ts +8 -3
  283. package/src/utils/createEphemeralContext.ts +142 -0
  284. package/src/utils/flows.ts +23 -0
  285. package/src/utils/index.ts +11 -2
  286. package/src/utils/jsxTransform.ts +39 -0
  287. package/src/utils/params-resolvers.ts +2 -2
  288. package/src/utils/parsePathnameToViewParams.ts +50 -6
  289. package/src/utils/pruneFilter.ts +41 -0
  290. package/src/utils/safeGlobals.ts +51 -4
  291. package/src/utils/schema-utils.ts +81 -3
  292. package/src/utils/serverContextParams.ts +5 -0
  293. package/src/utils/translation.ts +7 -2
  294. package/src/utils/variablesParams.ts +125 -42
  295. package/src/views/DialogComponent.tsx +1 -4
  296. package/src/views/DrawerComponent.tsx +19 -7
  297. package/src/views/PageComponent.tsx +2 -4
  298. package/src/views/ViewNavigation.ts +49 -43
  299. package/src/views/__tests__/FlowView.usePage.test.tsx +133 -0
  300. package/src/views/__tests__/ViewNavigation.test.ts +54 -34
  301. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +132 -0
  302. package/src/views/createViewMeta.ts +179 -42
  303. package/src/views/useDialog.tsx +36 -24
  304. package/src/views/useDrawer.tsx +37 -24
  305. package/src/views/usePage.tsx +46 -27
@@ -0,0 +1,109 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var observer_exports = {};
39
+ __export(observer_exports, {
40
+ getPageActive: () => getPageActive,
41
+ observer: () => observer
42
+ });
43
+ module.exports = __toCommonJS(observer_exports);
44
+ var import_reactive_react = require("@formily/reactive-react");
45
+ var import_react = __toESM(require("react"));
46
+ var import_FlowContextProvider = require("../FlowContextProvider");
47
+ var import_reactive = require("@formily/reactive");
48
+ const observer = /* @__PURE__ */ __name((Component, options) => {
49
+ const ComponentWithDefaultScheduler = import_react.default.memo((props) => {
50
+ const ctx = (0, import_FlowContextProvider.useFlowContext)();
51
+ const ctxRef = (0, import_react.useRef)(ctx);
52
+ ctxRef.current = ctx;
53
+ const pendingDisposerRef = (0, import_react.useRef)(null);
54
+ (0, import_react.useEffect)(() => {
55
+ return () => {
56
+ if (pendingDisposerRef.current) {
57
+ pendingDisposerRef.current();
58
+ pendingDisposerRef.current = null;
59
+ }
60
+ };
61
+ }, []);
62
+ const ObservedComponent = (0, import_react.useMemo)(
63
+ () => (0, import_reactive_react.observer)(Component, {
64
+ scheduler(updater) {
65
+ var _a, _b;
66
+ const pageActive = getPageActive(ctxRef.current);
67
+ const tabActive = (_b = (_a = ctxRef.current) == null ? void 0 : _a.tabActive) == null ? void 0 : _b.value;
68
+ if (pageActive === false || tabActive === false) {
69
+ setTimeout(() => {
70
+ if (pendingDisposerRef.current) {
71
+ return;
72
+ }
73
+ const disposer = (0, import_reactive.autorun)(() => {
74
+ var _a2, _b2, _c, _d, _e, _f;
75
+ if (((_b2 = (_a2 = ctxRef.current) == null ? void 0 : _a2.pageActive) == null ? void 0 : _b2.value) && (((_d = (_c = ctxRef.current) == null ? void 0 : _c.tabActive) == null ? void 0 : _d.value) === true || ((_f = (_e = ctxRef.current) == null ? void 0 : _e.tabActive) == null ? void 0 : _f.value) === void 0)) {
76
+ updater();
77
+ disposer == null ? void 0 : disposer();
78
+ pendingDisposerRef.current = null;
79
+ }
80
+ });
81
+ pendingDisposerRef.current = disposer;
82
+ });
83
+ return;
84
+ }
85
+ if (pendingDisposerRef.current) {
86
+ pendingDisposerRef.current();
87
+ pendingDisposerRef.current = null;
88
+ }
89
+ updater();
90
+ },
91
+ ...options
92
+ }),
93
+ []
94
+ );
95
+ return /* @__PURE__ */ import_react.default.createElement(ObservedComponent, { ...props });
96
+ });
97
+ ComponentWithDefaultScheduler.displayName = `ComponentWithDefaultScheduler`;
98
+ return ComponentWithDefaultScheduler;
99
+ }, "observer");
100
+ function getPageActive(context) {
101
+ var _a, _b, _c;
102
+ return typeof ((_a = context == null ? void 0 : context.pageActive) == null ? void 0 : _a.value) === "boolean" ? (_b = context == null ? void 0 : context.pageActive) == null ? void 0 : _b.value : (_c = context == null ? void 0 : context.view) == null ? void 0 : _c.inputArgs.pageActive;
103
+ }
104
+ __name(getPageActive, "getPageActive");
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ getPageActive,
108
+ observer
109
+ });
@@ -45,6 +45,7 @@ export declare abstract class BaseRecordResource<TData = any> extends APIResourc
45
45
  removeAppends(appends: string | string[]): this;
46
46
  getUpdateAssociationValues(): string[];
47
47
  addUpdateAssociationValues(updateAssociationValues: string | string[]): this;
48
+ jsonStringify(value: any): string;
48
49
  setFilterByTk(filterByTk: any): this;
49
50
  getFilterByTk(): any;
50
51
  setFields(fields: string[] | string): this;
@@ -110,6 +110,7 @@ const _BaseRecordResource = class _BaseRecordResource extends import_apiResource
110
110
  }
111
111
  async runAction(action, options) {
112
112
  var _a;
113
+ const { rawResponse, ...rest } = options;
113
114
  const config = this.mergeRequestConfig(
114
115
  import_lodash.default.omit(this.request, ["params", "data", "method"]),
115
116
  {
@@ -117,14 +118,18 @@ const _BaseRecordResource = class _BaseRecordResource extends import_apiResource
117
118
  url: this.buildURL(action)
118
119
  },
119
120
  (_a = this.runActionOptions) == null ? void 0 : _a[action],
120
- options
121
+ rest
121
122
  );
122
123
  if (["create", "update", "firstOrCreate", "updateOrCreate"].includes(action)) {
123
124
  config.params = config.params || {};
124
125
  config.params.updateAssociationValues = this.getUpdateAssociationValues();
125
126
  }
126
127
  try {
127
- const { data } = await this.api.request(config);
128
+ const response = await this.api.request(config);
129
+ if (rawResponse) {
130
+ return response;
131
+ }
132
+ const { data } = response;
128
133
  if (!(data == null ? void 0 : data.data)) {
129
134
  return data;
130
135
  }
@@ -219,8 +224,14 @@ const _BaseRecordResource = class _BaseRecordResource extends import_apiResource
219
224
  this.updateAssociationValues = currentUpdateAssociationValues;
220
225
  return this;
221
226
  }
227
+ jsonStringify(value) {
228
+ if (value !== null && typeof value === "object") {
229
+ return JSON.stringify(value);
230
+ }
231
+ return value;
232
+ }
222
233
  setFilterByTk(filterByTk) {
223
- return this.addRequestParameter("filterByTk", filterByTk);
234
+ return this.addRequestParameter("filterByTk", this.jsonStringify(filterByTk));
224
235
  }
225
236
  getFilterByTk() {
226
237
  return this.request.params.filterByTk;
@@ -39,11 +39,13 @@ export declare class MultiRecordResource<TDataItem = any> extends BaseRecordReso
39
39
  next(): Promise<void>;
40
40
  previous(): Promise<void>;
41
41
  goto(page: number): Promise<void>;
42
- create(data: TDataItem, options?: AxiosRequestConfig): Promise<void>;
42
+ create(data: TDataItem, options?: AxiosRequestConfig & {
43
+ refresh?: boolean;
44
+ }): Promise<void>;
43
45
  get(filterByTk: any): Promise<TDataItem | undefined>;
44
46
  update(filterByTk: string | number, data: Partial<TDataItem>, options?: AxiosRequestConfig): Promise<void>;
45
47
  destroySelectedRows(): Promise<void>;
46
- destroy(filterByTk: string | number | string[] | number[] | TDataItem | TDataItem[], options?: AxiosRequestConfig): Promise<void>;
48
+ destroy(filterByTk: string | number | string[] | number[] | TDataItem | TDataItem[] | object, options?: AxiosRequestConfig): Promise<void>;
47
49
  setItem(index: number, newDataItem: TDataItem): void;
48
50
  /**
49
51
  * 在同一个事件循环内多次调用 refresh 方法时,只有最后一次调用会生效。避免触发多次相同的接口请求。
@@ -129,8 +129,12 @@ const _MultiRecordResource = class _MultiRecordResource extends import_baseRecor
129
129
  }
130
130
  async create(data, options) {
131
131
  const config = this.mergeRequestConfig({ data }, this.createActionOptions, options);
132
- await this.runAction("create", config);
133
- await this.refresh();
132
+ const res = await this.runAction("create", config);
133
+ this.emit("saved", data);
134
+ if ((options == null ? void 0 : options.refresh) !== false) {
135
+ await this.refresh();
136
+ }
137
+ return res;
134
138
  }
135
139
  async get(filterByTk) {
136
140
  const options = {
@@ -144,17 +148,19 @@ const _MultiRecordResource = class _MultiRecordResource extends import_baseRecor
144
148
  return data;
145
149
  }
146
150
  async update(filterByTk, data, options) {
151
+ const result = data;
147
152
  const config = this.mergeRequestConfig(
148
153
  {
149
154
  params: {
150
155
  filterByTk
151
156
  },
152
- data
157
+ data: result
153
158
  },
154
159
  this.updateActionOptions,
155
160
  options
156
161
  );
157
162
  await this.runAction("update", config);
163
+ this.emit("saved", data);
158
164
  await this.refresh();
159
165
  }
160
166
  async destroySelectedRows() {
@@ -168,14 +174,17 @@ const _MultiRecordResource = class _MultiRecordResource extends import_baseRecor
168
174
  const config = this.mergeRequestConfig(
169
175
  {
170
176
  params: {
171
- filterByTk: import_lodash.default.castArray(filterByTk).map((item) => {
172
- return typeof item === "object" ? item["id"] : item;
173
- })
177
+ filterByTk: this.jsonStringify(filterByTk)
174
178
  }
175
179
  },
176
180
  options
177
181
  );
178
182
  await this.runAction("destroy", config);
183
+ const currentPage = this.getPage();
184
+ const lastPage = Math.ceil((this.getCount() - import_lodash.default.castArray(filterByTk).length) / this.getPageSize());
185
+ if (currentPage > lastPage) {
186
+ this.setPage(lastPage || 1);
187
+ }
179
188
  await this.refresh();
180
189
  }
181
190
  setItem(index, newDataItem) {
@@ -60,24 +60,27 @@ const _SingleRecordResource = class _SingleRecordResource extends import_baseRec
60
60
  async save(data, options) {
61
61
  const config = this.mergeRequestConfig(this.saveActionOptions, import_lodash.default.omit(options, ["refresh"]));
62
62
  let actionName = "create";
63
+ const result = data;
63
64
  if (!this.isNewRecord) {
64
65
  config.params = config.params || {};
65
66
  config.params.filterByTk = this.getFilterByTk();
66
67
  actionName = "update";
67
68
  }
68
- await this.runAction(actionName, {
69
+ const res = await this.runAction(actionName, {
69
70
  ...config,
70
- data
71
+ data: result
71
72
  });
73
+ this.emit("saved", data);
72
74
  if ((options == null ? void 0 : options.refresh) !== false) {
73
75
  await this.refresh();
74
76
  }
77
+ return res;
75
78
  }
76
79
  async destroy(options) {
77
80
  const config = this.mergeRequestConfig(
78
81
  {
79
82
  params: {
80
- filterByTk: this.request.params.filterByTk
83
+ filterByTk: this.jsonStringify(this.request.params.filterByTk)
81
84
  }
82
85
  },
83
86
  options
@@ -61,6 +61,7 @@ export declare class SQLResource<TData = any> extends BaseRecordResource<TData>
61
61
  setFilterByTk(filterByTk: any): this;
62
62
  setFilter(filter: Record<string, any>): this;
63
63
  setBind(bind: Record<string, any> | Array<any>): this;
64
+ setLiquidContext(liquidContext: Record<string, any>): this;
64
65
  run(): Promise<any>;
65
66
  runBySQL(): Promise<any>;
66
67
  runById(): Promise<any>;
@@ -45,18 +45,7 @@ var import_reactive = require("@formily/reactive");
45
45
  var import_lodash = __toESM(require("lodash"));
46
46
  var import_flowContext = require("../flowContext");
47
47
  var import_baseRecordResource = require("./baseRecordResource");
48
- function transformSQL(template) {
49
- let index = 1;
50
- const bind = {};
51
- const sql = template.replace(/{{\s*([^}]+)\s*}}/g, (_2, expr) => {
52
- const key = `__var${index}`;
53
- bind[key] = `{{${expr.trim()}}}`;
54
- index++;
55
- return `$${key}`;
56
- });
57
- return { sql, bind };
58
- }
59
- __name(transformSQL, "transformSQL");
48
+ var import_client = require("@nocobase/utils/client");
60
49
  const _FlowSQLRepository = class _FlowSQLRepository {
61
50
  ctx;
62
51
  constructor(ctx) {
@@ -72,16 +61,17 @@ const _FlowSQLRepository = class _FlowSQLRepository {
72
61
  });
73
62
  }
74
63
  async run(sql, options = {}) {
75
- const result = transformSQL(sql);
76
- const bind = await this.ctx.resolveJsonTemplate(result.bind);
64
+ const { sql: transformedSQL, bind, liquidContext } = await (0, import_client.transformSQL)(sql);
65
+ const resolved = await this.ctx.resolveJsonTemplate({ bind, liquidContext });
66
+ const parsedSQL = await (0, import_client.parseLiquidContext)(transformedSQL, resolved.liquidContext);
77
67
  const { data } = await this.ctx.api.request({
78
68
  method: "POST",
79
69
  url: "flowSql:run",
80
70
  data: {
81
- sql: result.sql,
71
+ sql: parsedSQL,
82
72
  ...options,
83
73
  bind: {
84
- ...bind,
74
+ ...resolved.bind,
85
75
  ...options.bind
86
76
  }
87
77
  }
@@ -105,7 +95,7 @@ const _FlowSQLRepository = class _FlowSQLRepository {
105
95
  uid
106
96
  }
107
97
  });
108
- const bind = await this.ctx.resolveJsonTemplate(response.data.data || {});
98
+ const { bind, liquidContext } = await this.ctx.resolveJsonTemplate(response.data.data || {});
109
99
  const { data } = await this.ctx.api.request({
110
100
  method: "POST",
111
101
  url: "flowSql:runById",
@@ -114,8 +104,9 @@ const _FlowSQLRepository = class _FlowSQLRepository {
114
104
  ...options,
115
105
  bind: {
116
106
  ...bind,
117
- ...options.bind
118
- }
107
+ ...options == null ? void 0 : options.bind
108
+ },
109
+ liquidContext
119
110
  }
120
111
  });
121
112
  return data == null ? void 0 : data.data;
@@ -227,19 +218,23 @@ const _SQLResource = class _SQLResource extends import_baseRecordResource.BaseRe
227
218
  this.request.data.bind = bind;
228
219
  return this;
229
220
  }
221
+ setLiquidContext(liquidContext) {
222
+ this.request.data.liquidContext = liquidContext;
223
+ return this;
224
+ }
230
225
  async run() {
231
226
  return this._debugEnabled ? await this.runBySQL() : await this.runById();
232
227
  }
233
228
  async runBySQL() {
234
229
  const sql = this._sql;
235
- const result = transformSQL(sql);
236
- const bind = await this.context.resolveJsonTemplate(result.bind);
230
+ const { sql: transformedSQL, bind, liquidContext } = await (0, import_client.transformSQL)(sql);
231
+ const resolved = await this.context.resolveJsonTemplate({ bind, liquidContext });
237
232
  const options = import_lodash.default.cloneDeep({
238
233
  method: "post",
239
234
  ...this.getRefreshRequestOptions()
240
235
  });
241
- options.data.bind = bind;
242
- options.data.sql = result.sql;
236
+ options.data.sql = await (0, import_client.parseLiquidContext)(transformedSQL, resolved.liquidContext);
237
+ options.data.bind = resolved.bind;
243
238
  return await this.runAction("run", options);
244
239
  }
245
240
  async runById() {
@@ -249,8 +244,9 @@ const _SQLResource = class _SQLResource extends import_baseRecordResource.BaseRe
249
244
  uid: this.request.data.uid
250
245
  }
251
246
  });
252
- const bind = await this.context.resolveJsonTemplate(data);
247
+ const { bind, liquidContext } = await this.context.resolveJsonTemplate(data);
253
248
  this.setBind(bind);
249
+ this.setLiquidContext(liquidContext);
254
250
  return await this.runAction("runById", {
255
251
  method: "post",
256
252
  ...this.getRefreshRequestOptions()
@@ -269,10 +265,11 @@ const _SQLResource = class _SQLResource extends import_baseRecordResource.BaseRe
269
265
  try {
270
266
  this.clearError();
271
267
  this.loading = true;
268
+ this.emit("loading");
272
269
  const { data, meta } = await this.run();
273
270
  this.setData(data).setMeta(meta);
274
- this.emit("refresh");
275
271
  this.loading = false;
272
+ this.emit("refresh");
276
273
  resolve();
277
274
  } catch (error) {
278
275
  this.setError(error);
@@ -63,12 +63,30 @@ function defineBaseContextMeta() {
63
63
  language: "Current active language code."
64
64
  }
65
65
  },
66
- React: "React namespace providing React library functions and hooks (available in RunJS environment)",
67
- ReactDOM: "ReactDOM client API including createRoot for rendering React components",
68
- antd: "Ant Design component library"
66
+ React: "React namespace providing React library functions and hooks (available in RunJS environment). Recommended access path: `ctx.libs.React`.",
67
+ ReactDOM: "ReactDOM client API including createRoot for rendering React components. Also available via `ctx.libs.ReactDOM`.",
68
+ antd: "Ant Design component library. Recommended access path: `ctx.libs.antd`.",
69
+ libs: {
70
+ description: "Namespace for third-party and shared libraries. Includes React, ReactDOM, Ant Design, and dayjs.",
71
+ detail: "Libraries namespace",
72
+ properties: {
73
+ React: "React namespace (same as ctx.React).",
74
+ ReactDOM: "ReactDOM client API (same as ctx.ReactDOM).",
75
+ antd: "Ant Design component library (same as ctx.antd).",
76
+ dayjs: "dayjs date-time utility library.",
77
+ antdIcons: "Ant Design icons library. Example: `ctx.libs.antdIcons.PlusOutlined`."
78
+ }
79
+ }
69
80
  },
70
81
  methods: {
71
82
  t: 'Internationalization function for translating text. Parameters: (key: string, variables?: object) => string. Example: `ctx.t("Hello {name}", { name: "World" })`',
83
+ render: {
84
+ description: 'Render into container. Accepts ReactElement, DOM Node/Fragment, or HTML string. Parameters: (vnode: ReactElement | Node | DocumentFragment | string, container?: HTMLElement|ElementProxy) => Root|null. Example: `ctx.render(<div>Hello</div>)` or `ctx.render("<b>hi</b>")`',
85
+ detail: "ReactDOM Root",
86
+ completion: {
87
+ insertText: `ctx.render(<div />)`
88
+ }
89
+ },
72
90
  requireAsync: 'Asynchronously load external libraries from URL. Parameters: (url: string) => Promise<any>. Example: `const lodash = await ctx.requireAsync("https://cdn.jsdelivr.net/npm/lodash")`',
73
91
  importAsync: 'Dynamically import ESM module by URL. Parameters: (url: string) => Promise<Module>. Example: `const mod = await ctx.importAsync("https://cdn.jsdelivr.net/npm/lit-html@2/+esm")`',
74
92
  resolveJsonTemplate: "Resolve JSON templates containing variable expressions with {{ }} syntax. Parameters: (template: any, context?: object) => any",
@@ -134,12 +152,30 @@ function defineBaseContextMeta() {
134
152
  language: "\u5F53\u524D\u6FC0\u6D3B\u7684\u8BED\u8A00\u4EE3\u7801"
135
153
  }
136
154
  },
137
- React: "React \u547D\u540D\u7A7A\u95F4\uFF0C\u63D0\u4F9B React \u51FD\u6570\u4E0E hooks\uFF08RunJS \u73AF\u5883\u4E2D\u53EF\u7528\uFF09",
138
- ReactDOM: "ReactDOM \u5BA2\u6237\u7AEF API\uFF0C\u542B createRoot \u7B49\u6E32\u67D3\u65B9\u6CD5",
139
- antd: "Ant Design \u7EC4\u4EF6\u5E93\uFF08RunJS \u73AF\u5883\u4E2D\u53EF\u7528\uFF09"
155
+ React: "React \u547D\u540D\u7A7A\u95F4\uFF0C\u63D0\u4F9B React \u51FD\u6570\u4E0E hooks\uFF08RunJS \u73AF\u5883\u4E2D\u53EF\u7528\uFF09\u3002\u63A8\u8350\u4F7F\u7528 `ctx.libs.React` \u8BBF\u95EE\u3002",
156
+ ReactDOM: "ReactDOM \u5BA2\u6237\u7AEF API\uFF0C\u542B createRoot \u7B49\u6E32\u67D3\u65B9\u6CD5\u3002\u63A8\u8350\u901A\u8FC7 `ctx.libs.ReactDOM` \u8BBF\u95EE\u3002",
157
+ antd: "Ant Design \u7EC4\u4EF6\u5E93\uFF08RunJS \u73AF\u5883\u4E2D\u53EF\u7528\uFF09\u3002\u63A8\u8350\u4F7F\u7528 `ctx.libs.antd` \u8BBF\u95EE\u3002",
158
+ libs: {
159
+ description: "\u7B2C\u4E09\u65B9/\u901A\u7528\u5E93\u7684\u7EDF\u4E00\u547D\u540D\u7A7A\u95F4\uFF0C\u5305\u542B React\u3001ReactDOM\u3001Ant Design\u3001dayjs \u7B49\u3002\u540E\u7EED\u65B0\u589E\u5E93\u4F1A\u4F18\u5148\u6302\u5728\u6B64\u5904\u3002",
160
+ detail: "\u901A\u7528\u5E93\u547D\u540D\u7A7A\u95F4",
161
+ properties: {
162
+ React: "React \u547D\u540D\u7A7A\u95F4\uFF08\u7B49\u4EF7\u4E8E ctx.React\uFF09\u3002",
163
+ ReactDOM: "ReactDOM \u5BA2\u6237\u7AEF API\uFF08\u7B49\u4EF7\u4E8E ctx.ReactDOM\uFF09\u3002",
164
+ antd: "Ant Design \u7EC4\u4EF6\u5E93\uFF08\u7B49\u4EF7\u4E8E ctx.antd\uFF09\u3002",
165
+ dayjs: "dayjs \u65E5\u671F\u65F6\u95F4\u5DE5\u5177\u5E93\u3002",
166
+ antdIcons: "Ant Design \u56FE\u6807\u5E93\u3002 \u4F8B\u5982\uFF1A`ctx.libs.antdIcons.PlusOutlined`\u3002"
167
+ }
168
+ }
140
169
  },
141
170
  methods: {
142
171
  t: '\u56FD\u9645\u5316\u51FD\u6570\uFF0C\u7528\u4E8E\u7FFB\u8BD1\u6587\u6848\u3002\u53C2\u6570\uFF1A(key: string, variables?: object) => string\u3002\u793A\u4F8B\uFF1A`ctx.t("\u4F60\u597D {name}", { name: "\u4E16\u754C" })`',
172
+ render: {
173
+ description: '\u6E32\u67D3\u5230\u5BB9\u5668\u3002vnode \u652F\u6301 ReactElement\u3001DOM \u8282\u70B9/\u7247\u6BB5\u3001\u6216 HTML \u5B57\u7B26\u4E32\u3002\u53C2\u6570\uFF1A(vnode: ReactElement | Node | DocumentFragment | string, container?: HTMLElement|ElementProxy) => Root|null\u3002\u793A\u4F8B\uFF1A`ctx.render(<div />)` \u6216 `ctx.render("<b>hi</b>")`',
174
+ detail: "ReactDOM Root",
175
+ completion: {
176
+ insertText: `ctx.render(<div />)`
177
+ }
178
+ },
143
179
  requireAsync: '\u6309 URL \u5F02\u6B65\u52A0\u8F7D\u5916\u90E8\u5E93\u3002\u53C2\u6570\uFF1A(url: string) => Promise<any>\u3002\u793A\u4F8B\uFF1A`const lodash = await ctx.requireAsync("https://cdn.jsdelivr.net/npm/lodash")`',
144
180
  importAsync: '\u6309 URL \u52A8\u6001\u5BFC\u5165 ESM \u6A21\u5757\uFF08\u5F00\u53D1/\u751F\u4EA7\u5747\u53EF\u7528\uFF09\u3002\u53C2\u6570\uFF1A(url: string) => Promise<Module>\u3002\u793A\u4F8B\uFF1A`const mod = await ctx.importAsync("https://cdn.jsdelivr.net/npm/lit-html@2/+esm")`',
145
181
  resolveJsonTemplate: "\u89E3\u6790\u542B {{ }} \u53D8\u91CF\u8868\u8FBE\u5F0F\u7684 JSON \u6A21\u677F\u3002\u53C2\u6570\uFF1A(template: any, context?: object) => any",
@@ -0,0 +1,11 @@
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 type { SnippetModule } from '../types';
10
+ declare const snippet: SnippetModule;
11
+ export default snippet;
@@ -0,0 +1,61 @@
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 __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var clipboard_copy_text_snippet_exports = {};
28
+ __export(clipboard_copy_text_snippet_exports, {
29
+ default: () => clipboard_copy_text_snippet_default
30
+ });
31
+ module.exports = __toCommonJS(clipboard_copy_text_snippet_exports);
32
+ const snippet = {
33
+ contexts: ["*"],
34
+ prefix: "sn-clipboard-copy",
35
+ label: "Copy text to clipboard (function)",
36
+ description: "A reusable function that copies a given string to the clipboard.",
37
+ locales: {
38
+ "zh-CN": {
39
+ label: "\u590D\u5236\u6587\u672C\u5230\u526A\u8D34\u677F\uFF08\u51FD\u6570\uFF09",
40
+ description: "\u901A\u7528\u51FD\u6570\uFF1A\u63A5\u53D7\u4E00\u4E2A\u5B57\u7B26\u4E32\u53C2\u6570\u5E76\u590D\u5236\u5230\u526A\u8D34\u677F\u3002"
41
+ }
42
+ },
43
+ content: `
44
+ // A general utility function that copies text to clipboard.
45
+ // Usage:
46
+ // const ok = await copyTextToClipboard('Hello');
47
+ // if (ok) { /* success */ } else { /* handle failure */ }
48
+ async function copyTextToClipboard(text) {
49
+ const s = String(text ?? '');
50
+ try {
51
+ if (navigator?.clipboard?.writeText) {
52
+ await navigator.clipboard.writeText(s);
53
+ return true;
54
+ }
55
+ } catch (_) {
56
+ // Fallback below
57
+ }
58
+ }
59
+ `
60
+ };
61
+ var clipboard_copy_text_snippet_default = snippet;
@@ -55,10 +55,13 @@ const snippets = {
55
55
  "global/open-view-drawer": /* @__PURE__ */ __name(() => import("./global/open-view-drawer.snippet"), "global/open-view-drawer"),
56
56
  "global/open-view-dialog": /* @__PURE__ */ __name(() => import("./global/open-view-dialog.snippet"), "global/open-view-dialog"),
57
57
  "global/query-selector": /* @__PURE__ */ __name(() => import("./global/query-selector.snippet"), "global/query-selector"),
58
+ "global/clipboard-copy-text": /* @__PURE__ */ __name(() => import("./global/clipboard-copy-text.snippet"), "global/clipboard-copy-text"),
58
59
  // libs
59
60
  "scene/block/echarts-init": /* @__PURE__ */ __name(() => import("./scene/block/echarts-init.snippet"), "scene/block/echarts-init"),
60
61
  // scene/block
61
62
  "scene/block/render-react": /* @__PURE__ */ __name(() => import("./scene/block/render-react.snippet"), "scene/block/render-react"),
63
+ "scene/block/render-react-jsx": /* @__PURE__ */ __name(() => import("./scene/block/render-react-jsx.snippet"), "scene/block/render-react-jsx"),
64
+ "scene/block/render-antd-icons": /* @__PURE__ */ __name(() => import("./scene/block/render-antd-icons.snippet"), "scene/block/render-antd-icons"),
62
65
  "scene/block/render-button-handler": /* @__PURE__ */ __name(() => import("./scene/block/render-button-handler.snippet"), "scene/block/render-button-handler"),
63
66
  "scene/block/add-event-listener": /* @__PURE__ */ __name(() => import("./scene/block/add-event-listener.snippet"), "scene/block/add-event-listener"),
64
67
  "scene/block/chartjs-bar": /* @__PURE__ */ __name(() => import("./scene/block/chartjs-bar.snippet"), "scene/block/chartjs-bar"),
@@ -0,0 +1,11 @@
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 type { SnippetModule } from '../../types';
10
+ declare const snippet: SnippetModule;
11
+ export default snippet;
@@ -0,0 +1,65 @@
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 __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var render_antd_icons_snippet_exports = {};
28
+ __export(render_antd_icons_snippet_exports, {
29
+ default: () => render_antd_icons_snippet_default
30
+ });
31
+ module.exports = __toCommonJS(render_antd_icons_snippet_exports);
32
+ var import_JSBlockRunJSContext = require("../../../contexts/JSBlockRunJSContext");
33
+ const snippet = {
34
+ contexts: [import_JSBlockRunJSContext.JSBlockRunJSContext],
35
+ prefix: "sn-jsb-antd-icons",
36
+ label: "Render Ant Design icons",
37
+ description: "Render Ant Design icons with buttons inside the block container",
38
+ locales: {
39
+ "zh-CN": {
40
+ label: "\u6E32\u67D3 Ant Design \u56FE\u6807",
41
+ description: "\u5728\u533A\u5757\u5BB9\u5668\u4E2D\u4F7F\u7528 Ant Design \u56FE\u6807\u4E0E\u6309\u94AE\u8FDB\u884C\u6E32\u67D3"
42
+ }
43
+ },
44
+ content: `
45
+ // Render Ant Design icons with buttons via ctx.libs
46
+ const { React, antd, antdIcons } = ctx.libs;
47
+ const { Button, Space } = antd;
48
+ const { PlusOutlined, EditOutlined, DeleteOutlined } = antdIcons;
49
+
50
+ const IconButtons = () => (
51
+ <Space style={{ padding: 12 }}>
52
+ <Button type="primary" icon={<PlusOutlined />}>
53
+ {ctx.t('Add')}
54
+ </Button>
55
+ <Button icon={<EditOutlined />}>{ctx.t('Edit')}</Button>
56
+ <Button danger icon={<DeleteOutlined />}>
57
+ {ctx.t('Delete')}
58
+ </Button>
59
+ </Space>
60
+ );
61
+
62
+ ctx.render(<IconButtons />);
63
+ `
64
+ };
65
+ var render_antd_icons_snippet_default = snippet;
@@ -42,11 +42,13 @@ const snippet = {
42
42
  }
43
43
  },
44
44
  content: `
45
- const { React, ReactDOM, antd } = ctx;
46
- const { Button } = antd;
45
+ const { Button } = ctx.libs.antd;
47
46
 
48
- const node = React.createElement(Button, { type: 'primary', onClick: () => ctx.message.success(ctx.t('Clicked!')) }, ctx.t('Button'));
49
- ReactDOM.createRoot(ctx.element).render(node);
47
+ ctx.render(
48
+ <Button type="primary" onClick={() => ctx.message.success(ctx.t('Clicked!'))}>
49
+ {ctx.t('Button')}
50
+ </Button>
51
+ );
50
52
  `
51
53
  };
52
54
  var render_button_handler_snippet_default = snippet;