@nocobase/flow-engine 2.1.0-beta.37 → 2.1.0-beta.40

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 (41) hide show
  1. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +8 -1
  2. package/lib/components/subModel/LazyDropdown.js +200 -16
  3. package/lib/data-source/index.d.ts +9 -0
  4. package/lib/data-source/index.js +12 -0
  5. package/lib/flowContext.js +3 -0
  6. package/lib/flowEngine.js +3 -3
  7. package/lib/models/flowModel.js +3 -3
  8. package/lib/utils/parsePathnameToViewParams.d.ts +5 -1
  9. package/lib/utils/parsePathnameToViewParams.js +28 -4
  10. package/lib/views/ViewNavigation.d.ts +12 -2
  11. package/lib/views/ViewNavigation.js +22 -7
  12. package/lib/views/createViewMeta.js +114 -50
  13. package/lib/views/inheritLayoutContext.d.ts +10 -0
  14. package/lib/views/inheritLayoutContext.js +50 -0
  15. package/lib/views/useDialog.js +2 -0
  16. package/lib/views/useDrawer.js +2 -0
  17. package/lib/views/usePage.js +2 -0
  18. package/package.json +4 -4
  19. package/src/__tests__/createViewMeta.popup.test.ts +115 -1
  20. package/src/__tests__/flowEngine.removeModel.test.ts +47 -3
  21. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +11 -1
  22. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +5 -2
  23. package/src/components/subModel/LazyDropdown.tsx +228 -16
  24. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +203 -1
  25. package/src/data-source/index.ts +18 -0
  26. package/src/executor/__tests__/flowExecutor.test.ts +28 -0
  27. package/src/flowContext.ts +3 -0
  28. package/src/flowEngine.ts +4 -3
  29. package/src/models/__tests__/flowEngine.resolveUse.test.ts +0 -15
  30. package/src/models/__tests__/flowModel.test.ts +33 -34
  31. package/src/models/flowModel.tsx +3 -3
  32. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +21 -0
  33. package/src/utils/parsePathnameToViewParams.ts +45 -5
  34. package/src/views/ViewNavigation.ts +40 -7
  35. package/src/views/__tests__/ViewNavigation.test.ts +52 -0
  36. package/src/views/__tests__/inheritLayoutContext.test.ts +53 -0
  37. package/src/views/createViewMeta.ts +106 -34
  38. package/src/views/inheritLayoutContext.ts +26 -0
  39. package/src/views/useDialog.tsx +2 -0
  40. package/src/views/useDrawer.tsx +2 -0
  41. package/src/views/usePage.tsx +2 -0
@@ -33,6 +33,75 @@ __export(createViewMeta_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(createViewMeta_exports);
35
35
  var import_variablesParams = require("../utils/variablesParams");
36
+ function isDefined(value) {
37
+ return value !== void 0 && value !== null;
38
+ }
39
+ __name(isDefined, "isDefined");
40
+ function isSameViewParamValue(left, right) {
41
+ if (left === right) return true;
42
+ if (!isDefined(left) || !isDefined(right)) return false;
43
+ try {
44
+ return JSON.stringify(left) === JSON.stringify(right);
45
+ } catch (_) {
46
+ return String(left) === String(right);
47
+ }
48
+ }
49
+ __name(isSameViewParamValue, "isSameViewParamValue");
50
+ function getViewStack(view) {
51
+ var _a;
52
+ const stack = (_a = view == null ? void 0 : view.navigation) == null ? void 0 : _a.viewStack;
53
+ return Array.isArray(stack) ? stack : [];
54
+ }
55
+ __name(getViewStack, "getViewStack");
56
+ function getAnchoredViewStackIndex(view, stack = getViewStack(view)) {
57
+ var _a;
58
+ if (!stack.length) return -1;
59
+ const args = (view == null ? void 0 : view.inputArgs) || {};
60
+ const navParams = ((_a = view == null ? void 0 : view.navigation) == null ? void 0 : _a.viewParams) || {};
61
+ const viewUid = args.viewUid ?? navParams.viewUid;
62
+ if (!viewUid) {
63
+ return stack.length - 1;
64
+ }
65
+ const candidates = stack.map((item, index) => ({ item, index })).filter(({ item }) => (item == null ? void 0 : item.viewUid) === viewUid);
66
+ if (!candidates.length) {
67
+ return stack.length - 1;
68
+ }
69
+ const keys = ["filterByTk", "sourceId", "tabUid"];
70
+ let bestIndex = candidates[candidates.length - 1].index;
71
+ let bestScore = -1;
72
+ for (const { item, index } of candidates) {
73
+ let score = 0;
74
+ let matched = true;
75
+ for (const key of keys) {
76
+ if (!isDefined(args[key])) continue;
77
+ if (!isSameViewParamValue(item == null ? void 0 : item[key], args[key])) {
78
+ matched = false;
79
+ break;
80
+ }
81
+ score += 1;
82
+ }
83
+ if (!matched) continue;
84
+ if (score >= bestScore) {
85
+ bestIndex = index;
86
+ bestScore = score;
87
+ }
88
+ }
89
+ return bestIndex;
90
+ }
91
+ __name(getAnchoredViewStackIndex, "getAnchoredViewStackIndex");
92
+ function getPopupView(ctx, anchorView) {
93
+ return anchorView ?? ctx.view;
94
+ }
95
+ __name(getPopupView, "getPopupView");
96
+ function isPopupView(view) {
97
+ var _a;
98
+ if (!view) return false;
99
+ const stack = getViewStack(view);
100
+ const openerUids = (_a = view == null ? void 0 : view.inputArgs) == null ? void 0 : _a.openerUids;
101
+ const hasOpener = Array.isArray(openerUids) && openerUids.length > 0;
102
+ return getAnchoredViewStackIndex(view, stack) >= 1 || hasOpener;
103
+ }
104
+ __name(isPopupView, "isPopupView");
36
105
  function isPlainObject(val) {
37
106
  if (val === null || typeof val !== "object") return false;
38
107
  const proto = Object.getPrototypeOf(val);
@@ -83,17 +152,9 @@ function makeMetaFromValue(value, title, seen) {
83
152
  __name(makeMetaFromValue, "makeMetaFromValue");
84
153
  function createPopupMeta(ctx, anchorView) {
85
154
  const t = /* @__PURE__ */ __name((k) => ctx.t(k), "t");
86
- const isPopupView = /* @__PURE__ */ __name((view) => {
87
- var _a, _b;
88
- if (!view) return false;
89
- const stack = Array.isArray((_a = view.navigation) == null ? void 0 : _a.viewStack) ? view.navigation.viewStack : [];
90
- const openerUids = (_b = view == null ? void 0 : view.inputArgs) == null ? void 0 : _b.openerUids;
91
- const hasOpener = Array.isArray(openerUids) && openerUids.length > 0;
92
- return stack.length >= 2 || hasOpener;
93
- }, "isPopupView");
94
- const hasPopupNow = /* @__PURE__ */ __name(() => isPopupView(anchorView ?? ctx.view), "hasPopupNow");
155
+ const hasPopupNow = /* @__PURE__ */ __name((flowCtx = ctx) => isPopupView(getPopupView(flowCtx, anchorView)), "hasPopupNow");
95
156
  const resolveRecordRef = /* @__PURE__ */ __name(async (flowCtx) => {
96
- const view = anchorView ?? flowCtx.view;
157
+ const view = getPopupView(flowCtx, anchorView);
97
158
  if (!view || !isPopupView(view)) return void 0;
98
159
  const base = await buildPopupRuntime(flowCtx, view);
99
160
  const res = base == null ? void 0 : base.resource;
@@ -116,25 +177,26 @@ function createPopupMeta(ctx, anchorView) {
116
177
  return ((_d = (_c = ds == null ? void 0 : ds.collectionManager) == null ? void 0 : _c.getCollection) == null ? void 0 : _d.call(_c, ref.collection)) || null;
117
178
  }, "getCurrentCollection");
118
179
  const getParentRecordRef = /* @__PURE__ */ __name(async (level, flowCtx) => {
119
- var _a, _b, _c, _d, _e, _f, _g;
180
+ var _a, _b, _c, _d, _e, _f;
120
181
  try {
121
182
  const useCtx = flowCtx || ctx;
122
- const nav = (_a = useCtx.view) == null ? void 0 : _a.navigation;
123
- const stack = Array.isArray(nav == null ? void 0 : nav.viewStack) ? nav.viewStack : [];
124
- if (stack.length < 2 || level < 1) return void 0;
125
- const idx = stack.length - 1 - level;
126
- if (idx < 0) return void 0;
183
+ const view = getPopupView(useCtx, anchorView);
184
+ const stack = getViewStack(view);
185
+ const currentIndex = getAnchoredViewStackIndex(view, stack);
186
+ if (currentIndex < 1 || level < 1) return void 0;
187
+ const idx = currentIndex - level;
188
+ if (idx < 1) return void 0;
127
189
  const parent = stack[idx];
128
190
  if (!(parent == null ? void 0 : parent.viewUid)) return void 0;
129
- let model = (_b = useCtx.engine) == null ? void 0 : _b.getModel(parent.viewUid, true);
191
+ let model = (_a = useCtx.engine) == null ? void 0 : _a.getModel(parent.viewUid, true);
130
192
  if (!model) {
131
193
  try {
132
194
  model = await useCtx.engine.loadModel({ uid: parent.viewUid });
133
195
  } catch (e) {
134
- (_d = (_c = useCtx.logger || ctx.logger) == null ? void 0 : _c.warn) == null ? void 0 : _d.call(_c, { err: e }, "[FlowEngine] popup.getParentRecordRef loadModel failed");
196
+ (_c = (_b = useCtx.logger || ctx.logger) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, { err: e }, "[FlowEngine] popup.getParentRecordRef loadModel failed");
135
197
  }
136
198
  }
137
- const params = ((_e = model == null ? void 0 : model.getStepParams) == null ? void 0 : _e.call(model, "popupSettings", "openView")) || {};
199
+ const params = ((_d = model == null ? void 0 : model.getStepParams) == null ? void 0 : _d.call(model, "popupSettings", "openView")) || {};
138
200
  const collection = params == null ? void 0 : params.collectionName;
139
201
  const dataSourceKey = (params == null ? void 0 : params.dataSourceKey) || "main";
140
202
  const filterByTk = (parent == null ? void 0 : parent.filterByTk) ?? (parent == null ? void 0 : parent.sourceId);
@@ -148,16 +210,16 @@ function createPopupMeta(ctx, anchorView) {
148
210
  };
149
211
  return ref;
150
212
  } catch (e) {
151
- (_g = (_f = (flowCtx == null ? void 0 : flowCtx.logger) || ctx.logger) == null ? void 0 : _f.warn) == null ? void 0 : _g.call(_f, { err: e }, "[FlowEngine] popup.getParentRecordRef failed");
213
+ (_f = (_e = (flowCtx == null ? void 0 : flowCtx.logger) || ctx.logger) == null ? void 0 : _e.warn) == null ? void 0 : _f.call(_e, { err: e }, "[FlowEngine] popup.getParentRecordRef failed");
152
214
  return void 0;
153
215
  }
154
216
  }, "getParentRecordRef");
155
217
  const hasParentNow = /* @__PURE__ */ __name((level) => {
156
- var _a;
157
218
  try {
158
- const nav = (_a = anchorView ?? ctx.view) == null ? void 0 : _a.navigation;
159
- const stack = Array.isArray(nav == null ? void 0 : nav.viewStack) ? nav.viewStack : [];
160
- return stack.length >= level + 1;
219
+ const view = getPopupView(ctx, anchorView);
220
+ const stack = getViewStack(view);
221
+ const currentIndex = getAnchoredViewStackIndex(view, stack);
222
+ return currentIndex - level >= 1;
161
223
  } catch (_) {
162
224
  return false;
163
225
  }
@@ -220,10 +282,11 @@ function createPopupMeta(ctx, anchorView) {
220
282
  disabled: /* @__PURE__ */ __name(() => !hasPopupNow(), "disabled"),
221
283
  hidden: /* @__PURE__ */ __name(() => !hasPopupNow(), "hidden"),
222
284
  buildVariablesParams: /* @__PURE__ */ __name(async (c) => {
223
- var _a, _b, _c, _d, _e, _f;
224
- if (!hasPopupNow()) return void 0;
285
+ var _a, _b, _c, _d;
286
+ if (!hasPopupNow(c)) return void 0;
225
287
  const ref = await resolveRecordRef(c);
226
- const inputArgs = (_a = c.view) == null ? void 0 : _a.inputArgs;
288
+ const view = getPopupView(c, anchorView);
289
+ const inputArgs = view == null ? void 0 : view.inputArgs;
227
290
  const params = {};
228
291
  if (ref) {
229
292
  const merged = { ...ref };
@@ -236,9 +299,9 @@ function createPopupMeta(ctx, anchorView) {
236
299
  params.record = merged;
237
300
  }
238
301
  try {
239
- const nav = (_b = c.view) == null ? void 0 : _b.navigation;
240
- const stack = Array.isArray(nav == null ? void 0 : nav.viewStack) ? nav.viewStack : [];
241
- if (stack.length >= 2) {
302
+ const stack = getViewStack(view);
303
+ const currentIndex = getAnchoredViewStackIndex(view, stack);
304
+ if (currentIndex >= 2) {
242
305
  let cur = params;
243
306
  let level = 1;
244
307
  let parentRef = await getParentRecordRef(level, c);
@@ -251,7 +314,7 @@ function createPopupMeta(ctx, anchorView) {
251
314
  }
252
315
  }
253
316
  } catch (err) {
254
- (_d = (_c = c.logger) == null ? void 0 : _c.debug) == null ? void 0 : _d.call(_c, { err }, "[FlowEngine] buildVariablesParams: build parent-chain failed");
317
+ (_b = (_a = c.logger) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, { err }, "[FlowEngine] buildVariablesParams: build parent-chain failed");
255
318
  }
256
319
  try {
257
320
  const srcId = inputArgs == null ? void 0 : inputArgs.sourceId;
@@ -268,12 +331,12 @@ function createPopupMeta(ctx, anchorView) {
268
331
  }
269
332
  }
270
333
  } catch (err) {
271
- (_f = (_e = c.logger) == null ? void 0 : _e.debug) == null ? void 0 : _f.call(_e, { err }, "[FlowEngine] buildVariablesParams: infer sourceRecord failed");
334
+ (_d = (_c = c.logger) == null ? void 0 : _c.debug) == null ? void 0 : _d.call(_c, { err }, "[FlowEngine] buildVariablesParams: infer sourceRecord failed");
272
335
  }
273
336
  return params;
274
337
  }, "buildVariablesParams"),
275
338
  properties: /* @__PURE__ */ __name(async () => {
276
- var _a, _b, _c, _d, _e, _f;
339
+ var _a, _b, _c, _d;
277
340
  const props = {};
278
341
  props.uid = { type: "string", title: t("Popup uid") };
279
342
  const recordRef = await resolveRecordRef(ctx);
@@ -292,20 +355,21 @@ function createPopupMeta(ctx, anchorView) {
292
355
  props.record = recordFactory;
293
356
  }
294
357
  try {
295
- const inputArgs = (_a = ctx.view) == null ? void 0 : _a.inputArgs;
358
+ const view = getPopupView(ctx, anchorView);
359
+ const inputArgs = view == null ? void 0 : view.inputArgs;
296
360
  const srcId = inputArgs == null ? void 0 : inputArgs.sourceId;
297
361
  let assoc = inputArgs == null ? void 0 : inputArgs.associationName;
298
362
  let dsKey = (inputArgs == null ? void 0 : inputArgs.dataSourceKey) || "main";
299
363
  if (!assoc || typeof assoc !== "string" || !assoc.includes(".")) {
300
- const nav = (_b = ctx.view) == null ? void 0 : _b.navigation;
301
- const stack = Array.isArray(nav == null ? void 0 : nav.viewStack) ? nav.viewStack : [];
302
- const last = stack == null ? void 0 : stack[stack.length - 1];
303
- if (last == null ? void 0 : last.viewUid) {
304
- let model = (_c = ctx == null ? void 0 : ctx.engine) == null ? void 0 : _c.getModel(last.viewUid, true);
364
+ const stack = getViewStack(view);
365
+ const currentIndex = getAnchoredViewStackIndex(view, stack);
366
+ const current = currentIndex >= 0 ? stack == null ? void 0 : stack[currentIndex] : void 0;
367
+ if (current == null ? void 0 : current.viewUid) {
368
+ let model = (_a = ctx == null ? void 0 : ctx.engine) == null ? void 0 : _a.getModel(current.viewUid, true);
305
369
  if (!model) {
306
- model = await ctx.engine.loadModel({ uid: last.viewUid });
370
+ model = await ctx.engine.loadModel({ uid: current.viewUid });
307
371
  }
308
- const p = ((_d = model == null ? void 0 : model.getStepParams) == null ? void 0 : _d.call(model, "popupSettings", "openView")) || {};
372
+ const p = ((_b = model == null ? void 0 : model.getStepParams) == null ? void 0 : _b.call(model, "popupSettings", "openView")) || {};
309
373
  assoc = (p == null ? void 0 : p.associationName) || assoc;
310
374
  dsKey = (p == null ? void 0 : p.dataSourceKey) || dsKey;
311
375
  }
@@ -333,7 +397,7 @@ function createPopupMeta(ctx, anchorView) {
333
397
  }
334
398
  }
335
399
  } catch (err) {
336
- (_f = (_e = ctx.logger) == null ? void 0 : _e.debug) == null ? void 0 : _f.call(_e, { err }, "[FlowEngine] popup.properties: build sourceRecord failed");
400
+ (_d = (_c = ctx.logger) == null ? void 0 : _c.debug) == null ? void 0 : _d.call(_c, { err }, "[FlowEngine] popup.properties: build sourceRecord failed");
337
401
  }
338
402
  const resourceMeta = {
339
403
  type: "object",
@@ -362,12 +426,12 @@ function createPopupMeta(ctx, anchorView) {
362
426
  }
363
427
  __name(createPopupMeta, "createPopupMeta");
364
428
  async function buildPopupRuntime(ctx, view) {
365
- var _a, _b, _c;
366
- const nav = view == null ? void 0 : view.navigation;
367
- const stack = Array.isArray(nav == null ? void 0 : nav.viewStack) ? nav.viewStack : [];
429
+ var _a;
430
+ const stack = getViewStack(view);
431
+ const currentIndex = getAnchoredViewStackIndex(view, stack);
368
432
  const openerUids = (_a = view == null ? void 0 : view.inputArgs) == null ? void 0 : _a.openerUids;
369
433
  const hasOpener = Array.isArray(openerUids) && openerUids.length > 0;
370
- const hasStackPopup = stack.length >= 2;
434
+ const hasStackPopup = currentIndex >= 1;
371
435
  const isPopup = hasStackPopup || hasOpener;
372
436
  if (!isPopup) return void 0;
373
437
  if (!stack.length) {
@@ -386,12 +450,12 @@ async function buildPopupRuntime(ctx, view) {
386
450
  };
387
451
  }
388
452
  const buildNode = /* @__PURE__ */ __name(async (idx) => {
389
- var _a2, _b2, _c2, _d, _e, _f;
453
+ var _a2, _b, _c, _d, _e, _f;
390
454
  if (idx < 0 || !((_a2 = stack[idx]) == null ? void 0 : _a2.viewUid)) return void 0;
391
455
  const viewUid = stack[idx].viewUid;
392
- let model = (_b2 = ctx.engine) == null ? void 0 : _b2.getModel(viewUid, true);
456
+ let model = (_b = ctx.engine) == null ? void 0 : _b.getModel(viewUid, true);
393
457
  if (!model) {
394
- model = await ((_c2 = ctx.engine) == null ? void 0 : _c2.loadModel({ uid: viewUid }));
458
+ model = await ((_c = ctx.engine) == null ? void 0 : _c.loadModel({ uid: viewUid }));
395
459
  }
396
460
  const p = ((_d = model == null ? void 0 : model.getStepParams) == null ? void 0 : _d.call(model, "popupSettings", "openView")) || {};
397
461
  const collectionName = p == null ? void 0 : p.collectionName;
@@ -410,7 +474,7 @@ async function buildPopupRuntime(ctx, view) {
410
474
  if (parentNode) node.parent = parentNode;
411
475
  return node;
412
476
  }, "buildNode");
413
- const currentNode = await buildNode((((_c = (_b = view == null ? void 0 : view.navigation) == null ? void 0 : _b.viewStack) == null ? void 0 : _c.length) || 1) - 1);
477
+ const currentNode = await buildNode(currentIndex);
414
478
  return currentNode;
415
479
  }
416
480
  __name(buildPopupRuntime, "buildPopupRuntime");
@@ -0,0 +1,10 @@
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 { FlowContext } from '../flowContext';
10
+ export declare function inheritLayoutContextForDetachedView(viewContext: FlowContext, sourceContext: FlowContext): void;
@@ -0,0 +1,50 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var inheritLayoutContext_exports = {};
29
+ __export(inheritLayoutContext_exports, {
30
+ inheritLayoutContextForDetachedView: () => inheritLayoutContextForDetachedView
31
+ });
32
+ module.exports = __toCommonJS(inheritLayoutContext_exports);
33
+ var import_flowContext = require("../flowContext");
34
+ function inheritLayoutContextForDetachedView(viewContext, sourceContext) {
35
+ var _a;
36
+ const layoutContext = sourceContext == null ? void 0 : sourceContext.layoutContext;
37
+ const engineContext = (_a = sourceContext == null ? void 0 : sourceContext.engine) == null ? void 0 : _a.context;
38
+ if (!(layoutContext instanceof import_flowContext.FlowContext)) {
39
+ return;
40
+ }
41
+ if (layoutContext === sourceContext || layoutContext === engineContext) {
42
+ return;
43
+ }
44
+ viewContext.addDelegate(layoutContext);
45
+ }
46
+ __name(inheritLayoutContextForDetachedView, "inheritLayoutContextForDetachedView");
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ inheritLayoutContextForDetachedView
50
+ });
@@ -53,6 +53,7 @@ var import_provider = require("../provider");
53
53
  var import_ViewScopedFlowEngine = require("../ViewScopedFlowEngine");
54
54
  var import_variablesParams = require("../utils/variablesParams");
55
55
  var import_runViewBeforeClose = require("./runViewBeforeClose");
56
+ var import_inheritLayoutContext = require("./inheritLayoutContext");
56
57
  let uuid = 0;
57
58
  function useDialog() {
58
59
  const holderRef = React.useRef(null);
@@ -103,6 +104,7 @@ function useDialog() {
103
104
  ctx.addDelegate(flowContext);
104
105
  } else {
105
106
  ctx.addDelegate(flowContext.engine.context);
107
+ (0, import_inheritLayoutContext.inheritLayoutContextForDetachedView)(ctx, flowContext);
106
108
  }
107
109
  let destroyed = false;
108
110
  const currentDialog = {
@@ -53,6 +53,7 @@ var import_provider = require("../provider");
53
53
  var import_ViewScopedFlowEngine = require("../ViewScopedFlowEngine");
54
54
  var import_variablesParams = require("../utils/variablesParams");
55
55
  var import_runViewBeforeClose = require("./runViewBeforeClose");
56
+ var import_inheritLayoutContext = require("./inheritLayoutContext");
56
57
  function useDrawer() {
57
58
  const holderRef = React.useRef(null);
58
59
  const drawerList = React.useMemo(() => import__.observable.shallow({ value: [] }), []);
@@ -122,6 +123,7 @@ function useDrawer() {
122
123
  ctx.addDelegate(flowContext);
123
124
  } else {
124
125
  ctx.addDelegate(flowContext.engine.context);
126
+ (0, import_inheritLayoutContext.inheritLayoutContextForDetachedView)(ctx, flowContext);
125
127
  }
126
128
  let destroyed = false;
127
129
  const currentDrawer = {
@@ -55,6 +55,7 @@ var import_provider = require("../provider");
55
55
  var import_ViewScopedFlowEngine = require("../ViewScopedFlowEngine");
56
56
  var import_variablesParams = require("../utils/variablesParams");
57
57
  var import_runViewBeforeClose = require("./runViewBeforeClose");
58
+ var import_inheritLayoutContext = require("./inheritLayoutContext");
58
59
  let uuid = 0;
59
60
  const GLOBAL_EMBED_CONTAINER_ID = "nocobase-embed-container";
60
61
  const EMBED_REPLACING_DATA_KEY = "nocobaseEmbedReplacing";
@@ -217,6 +218,7 @@ function usePage() {
217
218
  ctx.addDelegate(flowContext);
218
219
  } else {
219
220
  ctx.addDelegate(flowContext.engine.context);
221
+ (0, import_inheritLayoutContext.inheritLayoutContextForDetachedView)(ctx, flowContext);
220
222
  }
221
223
  let destroyed = false;
222
224
  let closingPromise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.1.0-beta.37",
3
+ "version": "2.1.0-beta.40",
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.0-beta.37",
12
- "@nocobase/shared": "2.1.0-beta.37",
11
+ "@nocobase/sdk": "2.1.0-beta.40",
12
+ "@nocobase/shared": "2.1.0-beta.40",
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": "7132e5b83ecc0e42b54715eaf1429c72bcef34ae"
40
+ "gitHead": "36e906138f6305723abbef676a61006058feb5ea"
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 { createPopupMeta } from '../views/createViewMeta';
14
+ import { buildPopupRuntime, createPopupMeta } from '../views/createViewMeta';
15
15
 
16
16
  describe('createPopupMeta - popup variables', () => {
17
17
  function makeCtx() {
@@ -23,6 +23,62 @@ describe('createPopupMeta - popup variables', () => {
23
23
  return { engine, ctx };
24
24
  }
25
25
 
26
+ function makeNestedPopupView(viewUid: string, filterByTk: number): FlowView {
27
+ return {
28
+ type: 'drawer',
29
+ inputArgs: {
30
+ viewUid,
31
+ filterByTk,
32
+ sourceId: 13,
33
+ },
34
+ Header: null,
35
+ Footer: null,
36
+ close: () => void 0,
37
+ update: () => void 0,
38
+ navigation: {
39
+ viewStack: [
40
+ { viewUid: 'base-page-uid' },
41
+ { viewUid: 'parent-popup-uid', filterByTk: 13, sourceId: 13 },
42
+ { viewUid: 'child-popup-uid', filterByTk: 24, sourceId: 13 },
43
+ ],
44
+ } as any,
45
+ } as any;
46
+ }
47
+
48
+ function mockNestedPopupModels(engine: FlowEngine) {
49
+ vi.spyOn(engine as any, 'getModel').mockImplementation((uid: string) => {
50
+ if (uid === 'parent-popup-uid') {
51
+ return {
52
+ getStepParams: vi.fn((_fk: string, sk: string) =>
53
+ sk === 'openView'
54
+ ? {
55
+ collectionName: 'users',
56
+ dataSourceKey: 'main',
57
+ associationName: 'users.orgs',
58
+ }
59
+ : undefined,
60
+ ),
61
+ };
62
+ }
63
+ if (uid === 'child-popup-uid') {
64
+ return {
65
+ getStepParams: vi.fn((_fk: string, sk: string) =>
66
+ sk === 'openView'
67
+ ? {
68
+ collectionName: 'orgs',
69
+ dataSourceKey: 'main',
70
+ associationName: 'users.orgs',
71
+ }
72
+ : undefined,
73
+ ),
74
+ };
75
+ }
76
+ return {
77
+ getStepParams: vi.fn(() => undefined),
78
+ };
79
+ });
80
+ }
81
+
26
82
  it('buildVariablesParams(record) uses anchor view instead of ctx.view', async () => {
27
83
  const { engine, ctx } = makeCtx();
28
84
 
@@ -108,6 +164,64 @@ describe('createPopupMeta - popup variables', () => {
108
164
  expect(vars.record.collection).not.toBe('comments');
109
165
  });
110
166
 
167
+ it('buildPopupRuntime anchors current popup even when the navigation stack already has a child popup', async () => {
168
+ const { engine, ctx } = makeCtx();
169
+ const parentView = makeNestedPopupView('parent-popup-uid', 13);
170
+ mockNestedPopupModels(engine);
171
+
172
+ const popup = await buildPopupRuntime(ctx, parentView);
173
+
174
+ expect(popup?.uid).toBe('parent-popup-uid');
175
+ expect(popup?.resource).toEqual({
176
+ dataSourceKey: 'main',
177
+ collectionName: 'users',
178
+ associationName: 'users.orgs',
179
+ filterByTk: 13,
180
+ sourceId: 13,
181
+ });
182
+ });
183
+
184
+ it('buildVariablesParams(record) keeps the parent view record when a child popup is open', async () => {
185
+ const { engine, ctx } = makeCtx();
186
+ const parentView = makeNestedPopupView('parent-popup-uid', 13);
187
+ mockNestedPopupModels(engine);
188
+
189
+ const meta = (await createPopupMeta(ctx, parentView)())!;
190
+ const vars = (await meta.buildVariablesParams!(ctx)) as any;
191
+
192
+ expect(vars.record).toEqual({
193
+ collection: 'users',
194
+ dataSourceKey: 'main',
195
+ filterByTk: 13,
196
+ associationName: 'users.orgs',
197
+ sourceId: 13,
198
+ });
199
+ });
200
+
201
+ it('buildVariablesParams(parent.record) is still relative to the child popup view', async () => {
202
+ const { engine, ctx } = makeCtx();
203
+ const childView = makeNestedPopupView('child-popup-uid', 24);
204
+ mockNestedPopupModels(engine);
205
+
206
+ const meta = (await createPopupMeta(ctx, childView)())!;
207
+ const vars = (await meta.buildVariablesParams!(ctx)) as any;
208
+
209
+ expect(vars.record).toEqual({
210
+ collection: 'orgs',
211
+ dataSourceKey: 'main',
212
+ filterByTk: 24,
213
+ associationName: 'users.orgs',
214
+ sourceId: 13,
215
+ });
216
+ expect(vars.parent.record).toEqual({
217
+ collection: 'users',
218
+ dataSourceKey: 'main',
219
+ filterByTk: 13,
220
+ sourceId: 13,
221
+ associationName: 'users.orgs',
222
+ });
223
+ });
224
+
111
225
  it('properties() provides a record factory node (lazy) with title', async () => {
112
226
  const { engine, ctx } = makeCtx();
113
227
  // 只要能通过 anchorView 推断到集合名和主键即可;集合详情在懒加载时再取
@@ -7,7 +7,7 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- import { beforeEach, describe, expect, it } from 'vitest';
10
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
11
11
  import { FlowEngine } from '../flowEngine';
12
12
  import { FlowModel } from '../models';
13
13
 
@@ -20,6 +20,7 @@ describe('FlowEngine removeModel', () => {
20
20
  });
21
21
 
22
22
  it('removeModel should remove model but keep sub-models in cache (current behavior)', () => {
23
+ const loggerSpy = vi.spyOn(engine.logger, 'debug').mockImplementation(() => {});
23
24
  const parent = engine.createModel({ uid: 'parent', use: 'FlowModel' });
24
25
  const child = engine.createModel({
25
26
  uid: 'child',
@@ -32,14 +33,53 @@ describe('FlowEngine removeModel', () => {
32
33
  expect(engine.getModel('parent')).toBe(parent);
33
34
  expect(engine.getModel('child')).toBe(child);
34
35
 
35
- engine.removeModel('parent');
36
+ try {
37
+ engine.removeModel('parent');
38
+ } finally {
39
+ loggerSpy.mockRestore();
40
+ }
36
41
 
37
42
  expect(engine.getModel('parent')).toBeUndefined();
38
43
  // Current behavior: child is still in cache
39
44
  expect(engine.getModel('child')).toBeDefined();
40
45
  });
41
46
 
47
+ it('removeModel should log missing models at debug level', () => {
48
+ const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
49
+ const loggerSpy = vi.spyOn(engine.logger, 'debug').mockImplementation(() => {});
50
+
51
+ try {
52
+ expect(engine.removeModel('missing')).toBe(false);
53
+ expect(consoleWarnSpy).not.toHaveBeenCalled();
54
+ expect(loggerSpy).toHaveBeenCalledWith("FlowEngine: Model with UID 'missing' does not exist.");
55
+ } finally {
56
+ consoleWarnSpy.mockRestore();
57
+ loggerSpy.mockRestore();
58
+ }
59
+ });
60
+
61
+ it('should reduce default logger verbosity in production', () => {
62
+ const originalNodeEnv = process.env.NODE_ENV;
63
+
64
+ try {
65
+ process.env.NODE_ENV = 'production';
66
+
67
+ const productionEngine = new FlowEngine();
68
+
69
+ expect(productionEngine.logger.level).toBe('warn');
70
+ expect(productionEngine.logger.isLevelEnabled('debug')).toBe(false);
71
+ expect(productionEngine.logger.isLevelEnabled('warn')).toBe(true);
72
+ } finally {
73
+ if (originalNodeEnv === undefined) {
74
+ delete process.env.NODE_ENV;
75
+ } else {
76
+ process.env.NODE_ENV = originalNodeEnv;
77
+ }
78
+ }
79
+ });
80
+
42
81
  it('removeModelWithSubModels should remove model and all sub-models from cache', () => {
82
+ const loggerSpy = vi.spyOn(engine.logger, 'debug').mockImplementation(() => {});
43
83
  const parent = engine.createModel({ uid: 'parent', use: 'FlowModel' });
44
84
  const child = engine.createModel({
45
85
  uid: 'child',
@@ -63,7 +103,11 @@ describe('FlowEngine removeModel', () => {
63
103
  expect(engine.getModel('child')).toBe(child);
64
104
  expect(engine.getModel('grandChild')).toBe(grandChild);
65
105
 
66
- engine.removeModelWithSubModels('parent');
106
+ try {
107
+ engine.removeModelWithSubModels('parent');
108
+ } finally {
109
+ loggerSpy.mockRestore();
110
+ }
67
111
 
68
112
  expect(engine.getModel('parent')).toBeUndefined();
69
113
  expect(engine.getModel('child')).toBeUndefined();