@nocobase/flow-engine 2.2.0-beta.16 → 2.2.0-beta.18

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 (36) hide show
  1. package/lib/components/FlowContextSelector.js +7 -1
  2. package/lib/components/subModel/LazyDropdown.js +21 -7
  3. package/lib/flowContext.d.ts +5 -1
  4. package/lib/flowContext.js +23 -6
  5. package/lib/resources/flowResource.js +1 -0
  6. package/lib/utils/associationObjectVariable.d.ts +10 -0
  7. package/lib/utils/associationObjectVariable.js +10 -7
  8. package/lib/utils/dateVariable.d.ts +22 -0
  9. package/lib/utils/dateVariable.js +123 -16
  10. package/lib/utils/index.d.ts +3 -3
  11. package/lib/utils/index.js +8 -0
  12. package/lib/utils/params-resolvers.d.ts +3 -0
  13. package/lib/utils/params-resolvers.js +10 -0
  14. package/lib/utils/variablesParams.js +5 -0
  15. package/lib/views/createViewMeta.d.ts +1 -0
  16. package/lib/views/createViewMeta.js +53 -22
  17. package/package.json +4 -4
  18. package/src/__tests__/createViewMeta.popup.test.ts +84 -1
  19. package/src/__tests__/flowContext.test.ts +8 -0
  20. package/src/__tests__/objectVariable.test.ts +6 -1
  21. package/src/__tests__/runjsFormSubmit.test.ts +45 -0
  22. package/src/components/FlowContextSelector.tsx +7 -1
  23. package/src/components/subModel/LazyDropdown.tsx +28 -13
  24. package/src/components/subModel/__tests__/LazyDropdown.test.tsx +202 -0
  25. package/src/components/variables/__tests__/FlowContextSelector.test.tsx +35 -0
  26. package/src/flowContext.ts +35 -5
  27. package/src/resources/__tests__/flowResource.test.ts +3 -0
  28. package/src/resources/flowResource.ts +1 -0
  29. package/src/utils/__tests__/dateVariable.test.ts +57 -4
  30. package/src/utils/__tests__/variablesParams.test.ts +28 -1
  31. package/src/utils/associationObjectVariable.ts +9 -6
  32. package/src/utils/dateVariable.ts +145 -18
  33. package/src/utils/index.ts +17 -2
  34. package/src/utils/params-resolvers.ts +12 -0
  35. package/src/utils/variablesParams.ts +10 -0
  36. package/src/views/createViewMeta.ts +52 -18
@@ -37,6 +37,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
38
  var params_resolvers_exports = {};
39
39
  __export(params_resolvers_exports, {
40
+ buildFlowModelResolveDescriptor: () => buildFlowModelResolveDescriptor,
40
41
  enqueueVariablesResolve: () => enqueueVariablesResolve,
41
42
  preprocessExpression: () => preprocessExpression,
42
43
  resolveCreateModelOptions: () => resolveCreateModelOptions,
@@ -45,6 +46,7 @@ __export(params_resolvers_exports, {
45
46
  });
46
47
  module.exports = __toCommonJS(params_resolvers_exports);
47
48
  var import_shared = require("@nocobase/shared");
49
+ var import_client = require("@nocobase/utils/client");
48
50
  var import_lodash = __toESM(require("lodash"));
49
51
  async function resolveDefaultParams(defaultParams, ctx) {
50
52
  if (!defaultParams) {
@@ -144,6 +146,8 @@ function enqueueVariablesResolve(ctx, payload) {
144
146
  try {
145
147
  const batch = items.map((it) => ({
146
148
  id: it.id,
149
+ contractRd: it.payload.contractRd,
150
+ rd: it.payload.rd,
147
151
  template: it.payload.template,
148
152
  contextParams: it.payload.contextParams || {}
149
153
  }));
@@ -187,6 +191,11 @@ function enqueueVariablesResolve(ctx, payload) {
187
191
  return p;
188
192
  }
189
193
  __name(enqueueVariablesResolve, "enqueueVariablesResolve");
194
+ function buildFlowModelResolveDescriptor(ctx, flowModelUid) {
195
+ var _a, _b;
196
+ return (0, import_client.generateFlowModelRdFromToken)(flowModelUid, (_b = (_a = ctx == null ? void 0 : ctx.api) == null ? void 0 : _a.auth) == null ? void 0 : _b.token);
197
+ }
198
+ __name(buildFlowModelResolveDescriptor, "buildFlowModelResolveDescriptor");
190
199
  async function resolveExpressions(params, ctx) {
191
200
  const compile = /* @__PURE__ */ __name(async (source) => {
192
201
  if (typeof source === "string" && /\{\{.*?\}\}/.test(source)) {
@@ -308,6 +317,7 @@ async function compileExpression(expression, ctx) {
308
317
  __name(compileExpression, "compileExpression");
309
318
  // Annotate the CommonJS export names for ESM import in node:
310
319
  0 && (module.exports = {
320
+ buildFlowModelResolveDescriptor,
311
321
  enqueueVariablesResolve,
312
322
  preprocessExpression,
313
323
  resolveCreateModelOptions,
@@ -210,6 +210,11 @@ async function collectContextParamsForTemplate(ctx, template) {
210
210
  input[key] = built;
211
211
  }
212
212
  }
213
+ const viewPaths = usage.view || [];
214
+ if (!input.view && viewPaths.some((path) => path === "record" || path.startsWith("record.") || path.startsWith("record["))) {
215
+ const recordRef = inferViewRecordRef(ctx);
216
+ if (recordRef) input.view = { record: recordRef };
217
+ }
213
218
  return (0, import_serverContextParams.buildServerContextParams)(ctx, input);
214
219
  }
215
220
  __name(collectContextParamsForTemplate, "collectContextParamsForTemplate");
@@ -28,6 +28,7 @@ interface PopupNodeResource {
28
28
  interface PopupNode {
29
29
  uid?: string;
30
30
  resource: PopupNodeResource;
31
+ sourceRecord?: unknown;
31
32
  parent?: PopupNode;
32
33
  }
33
34
  export declare function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promise<PopupNode | undefined>;
@@ -33,6 +33,13 @@ __export(createViewMeta_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(createViewMeta_exports);
35
35
  var import_variablesParams = require("../utils/variablesParams");
36
+ function buildPopupSourceRecordRef(ref) {
37
+ if ((ref == null ? void 0 : ref.sourceId) == null || ref.sourceId === "" || typeof ref.associationName !== "string") return void 0;
38
+ const collection = ref.associationName.split(".")[0];
39
+ if (!collection) return void 0;
40
+ return { collection, dataSourceKey: ref.dataSourceKey || "main", filterByTk: ref.sourceId };
41
+ }
42
+ __name(buildPopupSourceRecordRef, "buildPopupSourceRecordRef");
36
43
  function isDefined(value) {
37
44
  return value !== void 0 && value !== null;
38
45
  }
@@ -306,9 +313,11 @@ function createPopupMeta(ctx, anchorView) {
306
313
  let level = 1;
307
314
  let parentRef = await getParentRecordRef(level, c);
308
315
  while (parentRef) {
309
- if (!cur.parent) cur.parent = {};
310
- cur.parent.record = parentRef;
311
- cur = cur.parent;
316
+ const parent = { record: parentRef };
317
+ const sourceRecord = buildPopupSourceRecordRef(parentRef);
318
+ if (sourceRecord) parent.sourceRecord = sourceRecord;
319
+ cur.parent = parent;
320
+ cur = parent;
312
321
  level += 1;
313
322
  parentRef = await getParentRecordRef(level, c);
314
323
  }
@@ -317,19 +326,12 @@ function createPopupMeta(ctx, anchorView) {
317
326
  (_b = (_a = c.logger) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, { err }, "[FlowEngine] buildVariablesParams: build parent-chain failed");
318
327
  }
319
328
  try {
320
- const srcId = inputArgs == null ? void 0 : inputArgs.sourceId;
321
- const assoc = inputArgs == null ? void 0 : inputArgs.associationName;
322
- const dsKey = (inputArgs == null ? void 0 : inputArgs.dataSourceKey) || "main";
323
- if (srcId != null && srcId !== "" && assoc && typeof assoc === "string") {
324
- const parentCollectionName = String(assoc).split(".")[0];
325
- if (parentCollectionName) {
326
- params.sourceRecord = {
327
- collection: parentCollectionName,
328
- dataSourceKey: dsKey,
329
- filterByTk: srcId
330
- };
331
- }
332
- }
329
+ const sourceRecord = buildPopupSourceRecordRef({
330
+ sourceId: inputArgs == null ? void 0 : inputArgs.sourceId,
331
+ associationName: inputArgs == null ? void 0 : inputArgs.associationName,
332
+ dataSourceKey: inputArgs == null ? void 0 : inputArgs.dataSourceKey
333
+ });
334
+ if (sourceRecord) params.sourceRecord = sourceRecord;
333
335
  } catch (err) {
334
336
  (_d = (_c = c.logger) == null ? void 0 : _c.debug) == null ? void 0 : _d.call(_c, { err }, "[FlowEngine] buildVariablesParams: infer sourceRecord failed");
335
337
  }
@@ -426,10 +428,11 @@ function createPopupMeta(ctx, anchorView) {
426
428
  }
427
429
  __name(createPopupMeta, "createPopupMeta");
428
430
  async function buildPopupRuntime(ctx, view) {
429
- var _a;
431
+ var _a, _b, _c;
430
432
  const stack = getViewStack(view);
431
433
  const currentIndex = getAnchoredViewStackIndex(view, stack);
432
- const openerUids = (_a = view == null ? void 0 : view.inputArgs) == null ? void 0 : _a.openerUids;
434
+ const sourceRecord = (_b = (_a = view == null ? void 0 : view.inputArgs) == null ? void 0 : _a.parentItem) == null ? void 0 : _b.value;
435
+ const openerUids = (_c = view == null ? void 0 : view.inputArgs) == null ? void 0 : _c.openerUids;
433
436
  const hasOpener = Array.isArray(openerUids) && openerUids.length > 0;
434
437
  const hasStackPopup = currentIndex >= 1;
435
438
  const isPopup = hasStackPopup || hasOpener;
@@ -446,16 +449,17 @@ async function buildPopupRuntime(ctx, view) {
446
449
  associationName: args.associationName,
447
450
  filterByTk: args.filterByTk,
448
451
  sourceId: args.sourceId
449
- }
452
+ },
453
+ ...typeof sourceRecord !== "undefined" ? { sourceRecord } : {}
450
454
  };
451
455
  }
452
456
  const buildNode = /* @__PURE__ */ __name(async (idx) => {
453
- var _a2, _b, _c, _d, _e, _f;
457
+ var _a2, _b2, _c2, _d, _e, _f;
454
458
  if (idx < 0 || !((_a2 = stack[idx]) == null ? void 0 : _a2.viewUid)) return void 0;
455
459
  const viewUid = stack[idx].viewUid;
456
- let model = (_b = ctx.engine) == null ? void 0 : _b.getModel(viewUid, true);
460
+ let model = (_b2 = ctx.engine) == null ? void 0 : _b2.getModel(viewUid, true);
457
461
  if (!model) {
458
- model = await ((_c = ctx.engine) == null ? void 0 : _c.loadModel({ uid: viewUid }));
462
+ model = await ((_c2 = ctx.engine) == null ? void 0 : _c2.loadModel({ uid: viewUid }));
459
463
  }
460
464
  const p = ((_d = model == null ? void 0 : model.getStepParams) == null ? void 0 : _d.call(model, "popupSettings", "openView")) || {};
461
465
  const collectionName = p == null ? void 0 : p.collectionName;
@@ -475,16 +479,43 @@ async function buildPopupRuntime(ctx, view) {
475
479
  return node;
476
480
  }, "buildNode");
477
481
  const currentNode = await buildNode(currentIndex);
482
+ if (currentNode && typeof sourceRecord !== "undefined") {
483
+ currentNode.sourceRecord = sourceRecord;
484
+ }
478
485
  return currentNode;
479
486
  }
480
487
  __name(buildPopupRuntime, "buildPopupRuntime");
481
488
  function registerPopupVariable(ctx, view) {
482
489
  const POPUP_SERVER_PATH_RE = /^(?:record|sourceRecord)(?:\.|$)|^parent(?:\.parent)*(?:\.(?:record|sourceRecord))(?:\.|$)/;
490
+ const shouldResolveSourceRecordOnServer = /* @__PURE__ */ __name((path) => {
491
+ var _a, _b;
492
+ if (path !== "sourceRecord" && !path.startsWith("sourceRecord.")) return false;
493
+ const parentItem = (_a = view == null ? void 0 : view.inputArgs) == null ? void 0 : _a.parentItem;
494
+ if (typeof (parentItem == null ? void 0 : parentItem.value) === "undefined") return true;
495
+ const sourcePath = path === "sourceRecord" ? "" : path.slice("sourceRecord.".length);
496
+ if (!sourcePath) return false;
497
+ const parentItemResolver = (_b = view == null ? void 0 : view.inputArgs) == null ? void 0 : _b.parentItemResolver;
498
+ if (typeof parentItemResolver === "function") {
499
+ return parentItemResolver(`value.${sourcePath}`);
500
+ }
501
+ const segments = sourcePath.split(".").filter(Boolean);
502
+ let current = parentItem.value;
503
+ for (const segment of segments) {
504
+ if (current === null || typeof current !== "object" || !(segment in current)) {
505
+ return true;
506
+ }
507
+ current = current[segment];
508
+ }
509
+ return false;
510
+ }, "shouldResolveSourceRecordOnServer");
483
511
  ctx.defineProperty("popup", {
484
512
  get: /* @__PURE__ */ __name(async () => buildPopupRuntime(ctx, view), "get"),
485
513
  meta: createPopupMeta(ctx, view),
486
514
  resolveOnServer: /* @__PURE__ */ __name((p) => {
487
515
  try {
516
+ if (p === "sourceRecord" || p.startsWith("sourceRecord.")) {
517
+ return shouldResolveSourceRecordOnServer(p);
518
+ }
488
519
  return !!p && POPUP_SERVER_PATH_RE.test(p);
489
520
  } catch (_) {
490
521
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.2.0-beta.16",
3
+ "version": "2.2.0-beta.18",
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.2.0-beta.16",
12
- "@nocobase/shared": "2.2.0-beta.16",
11
+ "@nocobase/sdk": "2.2.0-beta.18",
12
+ "@nocobase/shared": "2.2.0-beta.18",
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": "49d9bd2e21122eab9435f128375828b8c5bb4c07"
40
+ "gitHead": "b74c962f7d35aa12012d908d16bd74fe6ac20a3d"
41
41
  }
@@ -11,7 +11,7 @@ import { describe, it, expect, vi } from 'vitest';
11
11
  import { FlowContext } from '../flowContext';
12
12
  import { FlowEngine } from '../flowEngine';
13
13
  import type { FlowView } from '../views/FlowView';
14
- import { buildPopupRuntime, createPopupMeta } from '../views/createViewMeta';
14
+ import { buildPopupRuntime, createPopupMeta, registerPopupVariable } from '../views/createViewMeta';
15
15
 
16
16
  describe('createPopupMeta - popup variables', () => {
17
17
  function makeCtx() {
@@ -167,6 +167,7 @@ describe('createPopupMeta - popup variables', () => {
167
167
  it('buildPopupRuntime anchors current popup even when the navigation stack already has a child popup', async () => {
168
168
  const { engine, ctx } = makeCtx();
169
169
  const parentView = makeNestedPopupView('parent-popup-uid', 13);
170
+ parentView.inputArgs.parentItem = { value: { id: 13, phone: '9999' } };
170
171
  mockNestedPopupModels(engine);
171
172
 
172
173
  const popup = await buildPopupRuntime(ctx, parentView);
@@ -179,6 +180,7 @@ describe('createPopupMeta - popup variables', () => {
179
180
  filterByTk: 13,
180
181
  sourceId: 13,
181
182
  });
183
+ expect(popup?.sourceRecord).toEqual({ id: 13, phone: '9999' });
182
184
  });
183
185
 
184
186
  it('buildVariablesParams(record) keeps the parent view record when a child popup is open', async () => {
@@ -314,4 +316,85 @@ describe('createPopupMeta - popup variables', () => {
314
316
  const props = typeof meta.properties === 'function' ? await (meta.properties as any)() : meta.properties || {};
315
317
  expect(props.record).toBeUndefined();
316
318
  });
319
+
320
+ it('uses the current parent item value for popup sourceRecord fields', async () => {
321
+ const { ctx } = makeCtx();
322
+ const parentItemResolver = vi.fn(() => false);
323
+ const anchorView: FlowView = {
324
+ type: 'dialog',
325
+ inputArgs: {
326
+ openerUids: ['opener-uid-1'],
327
+ viewUid: 'popup-uid',
328
+ dataSourceKey: 'main',
329
+ collectionName: 'roles',
330
+ associationName: 'users.roles',
331
+ sourceId: 1,
332
+ parentItem: { value: { id: 1, phone: '9999' } },
333
+ parentItemResolver,
334
+ },
335
+ Header: null,
336
+ Footer: null,
337
+ close: () => void 0,
338
+ update: () => void 0,
339
+ } as any;
340
+
341
+ registerPopupVariable(ctx, anchorView);
342
+
343
+ await expect(ctx.popup).resolves.toMatchObject({
344
+ sourceRecord: { id: 1, phone: '9999' },
345
+ });
346
+ expect(ctx.getPropertyOptions('popup')?.resolveOnServer?.('sourceRecord.phone')).toBe(false);
347
+ expect(parentItemResolver).toHaveBeenCalledWith('value.phone');
348
+ });
349
+
350
+ it('resolves a popup sourceRecord field from the current parent item without a server request', async () => {
351
+ const engine = new FlowEngine();
352
+ const ctx = engine.context;
353
+ const anchorView: FlowView = {
354
+ type: 'dialog',
355
+ inputArgs: {
356
+ openerUids: ['opener-uid-1'],
357
+ viewUid: 'popup-uid',
358
+ dataSourceKey: 'main',
359
+ collectionName: 'roles',
360
+ associationName: 'users.roles',
361
+ sourceId: 1,
362
+ parentItem: { value: { id: 1, phone: '9999' } },
363
+ parentItemResolver: () => false,
364
+ },
365
+ Header: null,
366
+ Footer: null,
367
+ close: () => void 0,
368
+ update: () => void 0,
369
+ } as any;
370
+
371
+ registerPopupVariable(ctx, anchorView);
372
+
373
+ await expect(ctx.resolveJsonTemplate('{{ ctx.popup.sourceRecord.phone }}')).resolves.toBe('9999');
374
+ });
375
+
376
+ it('keeps server resolution for popup sourceRecord association subpaths', async () => {
377
+ const { ctx } = makeCtx();
378
+ const anchorView: FlowView = {
379
+ type: 'dialog',
380
+ inputArgs: {
381
+ openerUids: ['opener-uid-1'],
382
+ viewUid: 'popup-uid',
383
+ dataSourceKey: 'main',
384
+ collectionName: 'roles',
385
+ associationName: 'users.roles',
386
+ sourceId: 1,
387
+ parentItem: { value: { id: 1, departmentId: 2 } },
388
+ parentItemResolver: (path: string) => path === 'value.department.title',
389
+ },
390
+ Header: null,
391
+ Footer: null,
392
+ close: () => void 0,
393
+ update: () => void 0,
394
+ } as any;
395
+
396
+ registerPopupVariable(ctx, anchorView);
397
+
398
+ expect(ctx.getPropertyOptions('popup')?.resolveOnServer?.('sourceRecord.department.title')).toBe(true);
399
+ });
317
400
  });
@@ -16,6 +16,7 @@ import { RunJSContextRegistry } from '../runjs-context/registry';
16
16
  import { setupRunJSContexts } from '../runjs-context/setup';
17
17
  import { createViewScopedEngine } from '../ViewScopedFlowEngine';
18
18
  import { DATA_SOURCE_DIRTY_EVENT } from '../views/viewEvents';
19
+ import { serializeCtxDateExpressionConfig } from '../utils/dateVariable';
19
20
 
20
21
  describe('FlowContext properties and methods', () => {
21
22
  it('should return static property value', () => {
@@ -2068,10 +2069,16 @@ describe('getPropertyMetaTree with deep delegate meta', () => {
2068
2069
  describe('FlowContext resolveOnServer selective server resolution', () => {
2069
2070
  it('resolves ctx.date expressions on client context', async () => {
2070
2071
  const engine = new FlowEngine();
2072
+ const formattedToday = serializeCtxDateExpressionConfig({
2073
+ kind: 'preset',
2074
+ preset: 'today',
2075
+ format: 'YYYY/MM/DD',
2076
+ });
2071
2077
  const out = await (engine.context as any).resolveJsonTemplate({
2072
2078
  today: '{{ ctx.date.preset.today }}',
2073
2079
  next12: '{{ ctx.date.relative.next.day.n12 }}',
2074
2080
  now: '{{ ctx.date.preset.now }}',
2081
+ formattedToday,
2075
2082
  });
2076
2083
 
2077
2084
  expect(typeof out.today).toBe('string');
@@ -2080,6 +2087,7 @@ describe('FlowContext resolveOnServer selective server resolution', () => {
2080
2087
  expect(out.next12).toMatch(/^\d{4}-\d{2}-\d{2}$/);
2081
2088
  expect(typeof out.now).toBe('string');
2082
2089
  expect(out.now.length).toBeGreaterThan(0);
2090
+ expect(out.formattedToday).toMatch(/^\d{4}\/\d{2}\/\d{2}$/);
2083
2091
  });
2084
2092
 
2085
2093
  it('does not call server by default (no resolveOnServer set)', async () => {
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  import { describe, expect, it, vi } from 'vitest';
11
+ import { generateFlowModelRdFromToken } from '@nocobase/utils/client';
11
12
  import { FlowContext } from '../flowContext';
12
13
  import { FlowEngine } from '../flowEngine';
13
14
  import {
@@ -122,7 +123,10 @@ describe('objectVariable utilities', () => {
122
123
 
123
124
  // Provide API stub to intercept variables:resolve
124
125
  const calls: any[] = [];
126
+ const payload = Buffer.from(JSON.stringify({ userId: 1, signInTime: 'contract-owner-test' })).toString('base64url');
127
+ const token = `test.${payload}.sig`;
125
128
  (ctx as any).api = {
129
+ auth: { token },
126
130
  request: vi.fn(async ({ url, data, method }) => {
127
131
  calls.push({ url, data, method });
128
132
  const batch = (data?.values?.batch as any[]) || [];
@@ -146,13 +150,14 @@ describe('objectVariable utilities', () => {
146
150
  });
147
151
 
148
152
  const template = { x: '{{ ctx.obj.author.name }}' } as any;
149
- await (ctx as any).resolveJsonTemplate(template);
153
+ await (ctx as any).resolveJsonTemplate(template, { contractModelUid: 'form-grid' });
150
154
 
151
155
  // Assert variables:resolve was called with proper flattened contextParams
152
156
  expect((ctx as any).api.request).toHaveBeenCalled();
153
157
  const call = calls.find((c) => c.url === 'variables:resolve');
154
158
  expect(call).toBeTruthy();
155
159
  const batch0 = call.data?.values?.batch?.[0];
160
+ expect(batch0?.contractRd).toBe(generateFlowModelRdFromToken('form-grid', token));
156
161
  expect(batch0?.contextParams).toBeTruthy();
157
162
  // Flattened key should be 'obj.author'
158
163
  const cp = batch0.contextParams as Record<string, any>;
@@ -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
+ });
@@ -311,6 +311,7 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
311
311
  const path = selectedValues.map(String);
312
312
  const pathString = path.join('.');
313
313
  const isLeaf = lastOption?.isLeaf;
314
+ const isSelectable = lastOption?.meta?.selectable !== false;
314
315
  const now = Date.now();
315
316
 
316
317
  // 使用自定义格式化函数或默认函数
@@ -325,6 +326,10 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
325
326
  }
326
327
 
327
328
  if (isLeaf) {
329
+ if (!isSelectable) {
330
+ setTempSelectedPath(path);
331
+ return;
332
+ }
328
333
  onChange?.(formattedValue, lastOption?.meta);
329
334
  // 选中叶子节点后,可清空内部临时路径(外部 value 将驱动级联)
330
335
  setTempSelectedPath([]);
@@ -333,7 +338,8 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
333
338
 
334
339
  // 非叶子节点:检查双击
335
340
  const lastSelected = lastSelectedRef.current;
336
- const isDoubleClick = !onlyLeafSelectable && lastSelected?.path === pathString && now - lastSelected.time < 300;
341
+ const isDoubleClick =
342
+ isSelectable && !onlyLeafSelectable && lastSelected?.path === pathString && now - lastSelected.time < 300;
337
343
 
338
344
  if (isDoubleClick) {
339
345
  // 双击:选中非叶子节点
@@ -8,8 +8,8 @@
8
8
  */
9
9
 
10
10
  import { css } from '@emotion/css';
11
- import { ConfigProvider, Dropdown, DropdownProps, Empty, Input, InputProps, Spin } from 'antd';
12
- import React, { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';
11
+ import { ConfigProvider, Dropdown, DropdownProps, Empty, Input, InputProps, Spin, theme } from 'antd';
12
+ import React, { FC, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
13
13
  import { useFlowEngine } from '../../provider';
14
14
 
15
15
  // ==================== Types ====================
@@ -69,16 +69,6 @@ interface ExtendedMenuInfo {
69
69
 
70
70
  // ==================== Custom Hooks ====================
71
71
 
72
- /**
73
- * 计算合适的下拉菜单最大高度
74
- */
75
- const useNiceDropdownMaxHeight = () => {
76
- return useMemo(() => {
77
- const maxHeight = Math.min(window.innerHeight * 0.6, 400);
78
- return maxHeight;
79
- }, []);
80
- };
81
-
82
72
  /**
83
73
  * 处理异步菜单项加载的逻辑
84
74
  */
@@ -555,6 +545,7 @@ const KEEP_OPEN_LABEL_STYLE: React.CSSProperties = {
555
545
 
556
546
  // 短暂保持打开状态的注册表(用于跨父节点快速重建时的恢复)
557
547
  const DROPDOWN_PERSIST_TTL_MS = 350;
548
+ const DEFAULT_DROPDOWN_MAX_HEIGHT = 400;
558
549
  const MENU_CLOSE_DELAY = 0.3;
559
550
  const SUBMENU_MOTION_DISABLED = {
560
551
  motionEnter: false,
@@ -565,8 +556,11 @@ const dropdownPersistRegistry: Map<string, number> = new Map();
565
556
  const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownMenuProps }> = ({ menu, ...props }) => {
566
557
  const engine = useFlowEngine();
567
558
  const { getPrefixCls } = React.useContext(ConfigProvider.ConfigContext);
559
+ const { token } = theme.useToken();
568
560
  const triggerId = React.useId();
561
+ const showArrow = Boolean(props.arrow);
569
562
  const [menuVisible, setMenuVisible] = useState(false);
563
+ const [dropdownMaxHeight, setDropdownMaxHeight] = useState(DEFAULT_DROPDOWN_MAX_HEIGHT);
570
564
  const [openKeys, setOpenKeys] = useState<Set<string>>(new Set());
571
565
  const [rootItems, setRootItems] = useState<Item[]>([]);
572
566
  const [rootLoading, setRootLoading] = useState(false);
@@ -578,7 +572,6 @@ const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownM
578
572
  const mergedOpenClassName = [props.openClassName ?? defaultOpenClassName, triggerOpenClassName]
579
573
  .filter(Boolean)
580
574
  .join(' ');
581
- const dropdownMaxHeight = useNiceDropdownMaxHeight();
582
575
  const t = engine.translate.bind(engine);
583
576
 
584
577
  // 解构 menu,避免在 effect 中直接依赖整个对象,减少不必要的重跑并满足 exhaustive-deps
@@ -597,6 +590,28 @@ const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownM
597
590
  const { requestKeepOpen, shouldPreventClose } = useKeepDropdownOpen();
598
591
  useSubmenuStyles(menuVisible, dropdownMaxHeight);
599
592
 
593
+ useLayoutEffect(() => {
594
+ if (!menuVisible) return;
595
+
596
+ const updateDropdownMaxHeight = () => {
597
+ const trigger = document.querySelector<HTMLElement>(`.${triggerOpenClassName}`);
598
+ if (!trigger) return;
599
+
600
+ const triggerRect = trigger.getBoundingClientRect();
601
+ const placementOffset = token.marginXXS + (showArrow ? token.sizePopupArrow / 2 : 0);
602
+ const reservedSpace = placementOffset + token.marginXXS;
603
+ const availableAbove = triggerRect.top - reservedSpace;
604
+ const availableBelow = window.innerHeight - triggerRect.bottom - reservedSpace;
605
+ const nextMaxHeight = Math.min(DEFAULT_DROPDOWN_MAX_HEIGHT, Math.max(0, availableAbove, availableBelow));
606
+
607
+ setDropdownMaxHeight(nextMaxHeight);
608
+ };
609
+
610
+ updateDropdownMaxHeight();
611
+ window.addEventListener('resize', updateDropdownMaxHeight);
612
+ return () => window.removeEventListener('resize', updateDropdownMaxHeight);
613
+ }, [menuVisible, showArrow, token.marginXXS, token.sizePopupArrow, triggerOpenClassName]);
614
+
600
615
  const closeMenu = useCallback(() => {
601
616
  setMenuVisible(false);
602
617
  activeSearchKeyRef.current = null;