@nocobase/flow-engine 3.0.0-alpha.7 → 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.
@@ -475,12 +475,14 @@ interface PopupNodeResource {
475
475
  interface PopupNode {
476
476
  uid?: string;
477
477
  resource: PopupNodeResource;
478
+ sourceRecord?: unknown;
478
479
  parent?: PopupNode;
479
480
  }
480
481
 
481
482
  export async function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promise<PopupNode | undefined> {
482
483
  const stack = getViewStack(view);
483
484
  const currentIndex = getAnchoredViewStackIndex(view, stack);
485
+ const sourceRecord = view?.inputArgs?.parentItem?.value;
484
486
 
485
487
  const openerUids = view?.inputArgs?.openerUids;
486
488
  const hasOpener = Array.isArray(openerUids) && openerUids.length > 0;
@@ -503,6 +505,7 @@ export async function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promi
503
505
  filterByTk: args.filterByTk,
504
506
  sourceId: args.sourceId,
505
507
  },
508
+ ...(typeof sourceRecord !== 'undefined' ? { sourceRecord } : {}),
506
509
  };
507
510
  }
508
511
 
@@ -531,6 +534,9 @@ export async function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promi
531
534
  return node;
532
535
  };
533
536
  const currentNode = await buildNode(currentIndex);
537
+ if (currentNode && typeof sourceRecord !== 'undefined') {
538
+ currentNode.sourceRecord = sourceRecord;
539
+ }
534
540
  return currentNode;
535
541
  }
536
542
 
@@ -542,6 +548,30 @@ export function registerPopupVariable(ctx: FlowContext, view: FlowView) {
542
548
  // - 任意层级 parent.parent... 下的 record / sourceRecord 及其子字段
543
549
  const POPUP_SERVER_PATH_RE =
544
550
  /^(?:record|sourceRecord)(?:\.|$)|^parent(?:\.parent)*(?:\.(?:record|sourceRecord))(?:\.|$)/;
551
+ const shouldResolveSourceRecordOnServer = (path: string): boolean => {
552
+ if (path !== 'sourceRecord' && !path.startsWith('sourceRecord.')) return false;
553
+
554
+ const parentItem = view?.inputArgs?.parentItem;
555
+ if (typeof parentItem?.value === 'undefined') return true;
556
+
557
+ const sourcePath = path === 'sourceRecord' ? '' : path.slice('sourceRecord.'.length);
558
+ if (!sourcePath) return false;
559
+
560
+ const parentItemResolver = view?.inputArgs?.parentItemResolver;
561
+ if (typeof parentItemResolver === 'function') {
562
+ return parentItemResolver(`value.${sourcePath}`);
563
+ }
564
+
565
+ const segments = sourcePath.split('.').filter(Boolean);
566
+ let current = parentItem.value;
567
+ for (const segment of segments) {
568
+ if (current === null || typeof current !== 'object' || !(segment in current)) {
569
+ return true;
570
+ }
571
+ current = current[segment];
572
+ }
573
+ return false;
574
+ };
545
575
  // 始终注册 popup 变量:
546
576
  // - 若当前视图无可推断记录,仅在元信息中不呈现 record 字段;
547
577
  // - 但仍可依据 navigation 推断并展示上级弹窗信息。
@@ -550,6 +580,9 @@ export function registerPopupVariable(ctx: FlowContext, view: FlowView) {
550
580
  meta: createPopupMeta(ctx, view),
551
581
  resolveOnServer: (p: string) => {
552
582
  try {
583
+ if (p === 'sourceRecord' || p.startsWith('sourceRecord.')) {
584
+ return shouldResolveSourceRecordOnServer(p);
585
+ }
553
586
  return !!p && POPUP_SERVER_PATH_RE.test(p);
554
587
  } catch (_) {
555
588
  return false;