@nocobase/flow-engine 2.1.38 → 2.1.39

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.
@@ -3501,8 +3501,13 @@ function __mergeRunJSDocMeta(base, patch) {
3501
3501
  __name(__mergeRunJSDocMeta, "__mergeRunJSDocMeta");
3502
3502
  const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
3503
3503
  constructor(delegate) {
3504
+ var _a, _b;
3504
3505
  super();
3505
3506
  this.addDelegate(delegate);
3507
+ const submit = (_b = (_a = delegate.blockModel) == null ? void 0 : _a.submitFromRunJs) == null ? void 0 : _b.bind(delegate.blockModel);
3508
+ if (delegate.form && submit) {
3509
+ this.defineProperty("form", { value: { ...delegate.form, submit } });
3510
+ }
3506
3511
  this.defineProperty("React", { value: import_react.default });
3507
3512
  this.defineProperty("antd", { value: antd });
3508
3513
  this.defineProperty("dayjs", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.1.38",
3
+ "version": "2.1.39",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@formily/antd-v5": "1.x",
10
10
  "@formily/reactive": "2.x",
11
- "@nocobase/sdk": "2.1.38",
12
- "@nocobase/shared": "2.1.38",
11
+ "@nocobase/sdk": "2.1.39",
12
+ "@nocobase/shared": "2.1.39",
13
13
  "ahooks": "^3.7.2",
14
14
  "axios": "^1.7.0",
15
15
  "dayjs": "^1.11.9",
@@ -37,5 +37,5 @@
37
37
  ],
38
38
  "author": "NocoBase Team",
39
39
  "license": "Apache-2.0",
40
- "gitHead": "cf73a1ede7f46029428d3ed143af2e5dc4f035e6"
40
+ "gitHead": "ddbf88ac2a5de1ad94ff4779618cdf1b81aae037"
41
41
  }
@@ -0,0 +1,45 @@
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
+ import { describe, expect, it, vi } from 'vitest';
11
+ import { FlowContext, FlowRunJSContext } from '../flowContext';
12
+ import { JSItemRunJSContext } from '../runjs-context/contexts/JSItemRunJSContext';
13
+
14
+ describe('FlowRunJSContext form submission', () => {
15
+ it('uses the form block RunJS submit capability without changing the native form', () => {
16
+ const nativeSubmit = vi.fn();
17
+ const getFieldsValue = vi.fn(() => ({ name: 'Alice' }));
18
+ const form = { submit: nativeSubmit, getFieldsValue };
19
+ const submitFromRunJs = vi.fn();
20
+ const delegate = new FlowContext();
21
+ delegate.defineProperty('form', { value: form });
22
+ delegate.defineProperty('blockModel', { value: { submitFromRunJs } });
23
+
24
+ const ctx = new JSItemRunJSContext(delegate);
25
+
26
+ expect(ctx.form.getFieldsValue()).toEqual({ name: 'Alice' });
27
+ ctx.form.submit();
28
+ expect(submitFromRunJs).toHaveBeenCalledOnce();
29
+ expect(nativeSubmit).not.toHaveBeenCalled();
30
+ expect(form.submit).toBe(nativeSubmit);
31
+ });
32
+
33
+ it('keeps the native submit method when the block has no RunJS submit capability', () => {
34
+ const nativeSubmit = vi.fn();
35
+ const form = { submit: nativeSubmit };
36
+ const delegate = new FlowContext();
37
+ delegate.defineProperty('form', { value: form });
38
+ delegate.defineProperty('blockModel', { value: {} });
39
+
40
+ const ctx = new FlowRunJSContext(delegate);
41
+
42
+ ctx.form.submit();
43
+ expect(nativeSubmit).toHaveBeenCalledOnce();
44
+ });
45
+ });
@@ -4601,6 +4601,10 @@ export class FlowRunJSContext extends FlowContext {
4601
4601
  constructor(delegate: FlowContext) {
4602
4602
  super();
4603
4603
  this.addDelegate(delegate);
4604
+ const submit = delegate.blockModel?.submitFromRunJs?.bind(delegate.blockModel);
4605
+ if (delegate.form && submit) {
4606
+ this.defineProperty('form', { value: { ...delegate.form, submit } });
4607
+ }
4604
4608
  this.defineProperty('React', { value: React });
4605
4609
  this.defineProperty('antd', { value: antd });
4606
4610
  this.defineProperty('dayjs', {