@nocobase/flow-engine 3.0.0-alpha.8 → 3.0.0-alpha.9

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.
@@ -3511,8 +3511,13 @@ function __mergeRunJSDocMeta(base, patch) {
3511
3511
  __name(__mergeRunJSDocMeta, "__mergeRunJSDocMeta");
3512
3512
  const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
3513
3513
  constructor(delegate) {
3514
+ var _a, _b;
3514
3515
  super();
3515
3516
  this.addDelegate(delegate);
3517
+ const submit = (_b = (_a = delegate.blockModel) == null ? void 0 : _a.submitFromRunJs) == null ? void 0 : _b.bind(delegate.blockModel);
3518
+ if (delegate.form && submit) {
3519
+ this.defineProperty("form", { value: { ...delegate.form, submit } });
3520
+ }
3516
3521
  this.defineProperty("React", { value: import_react.default });
3517
3522
  this.defineProperty("antd", { value: antd });
3518
3523
  this.defineProperty("dayjs", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "3.0.0-alpha.8",
3
+ "version": "3.0.0-alpha.9",
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": "3.0.0-alpha.8",
12
- "@nocobase/shared": "3.0.0-alpha.8",
11
+ "@nocobase/sdk": "3.0.0-alpha.9",
12
+ "@nocobase/shared": "3.0.0-alpha.9",
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": "ce017f3deb8b2414c6b13818042c4187270d1d8a"
40
+ "gitHead": "82aaad40c5be1120839a11301a48e7fe690f48c3"
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
+ });
@@ -4611,6 +4611,10 @@ export class FlowRunJSContext extends FlowContext {
4611
4611
  constructor(delegate: FlowContext) {
4612
4612
  super();
4613
4613
  this.addDelegate(delegate);
4614
+ const submit = delegate.blockModel?.submitFromRunJs?.bind(delegate.blockModel);
4615
+ if (delegate.form && submit) {
4616
+ this.defineProperty('form', { value: { ...delegate.form, submit } });
4617
+ }
4614
4618
  this.defineProperty('React', { value: React });
4615
4619
  this.defineProperty('antd', { value: antd });
4616
4620
  this.defineProperty('dayjs', {