@nocobase/flow-engine 2.1.0-alpha.40 → 2.1.0-alpha.45
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.
- package/lib/FlowContextProvider.d.ts +5 -1
- package/lib/FlowContextProvider.js +9 -2
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +8 -1
- package/lib/components/subModel/LazyDropdown.js +200 -16
- package/lib/data-source/index.d.ts +9 -0
- package/lib/data-source/index.js +12 -0
- package/lib/flowContext.js +3 -0
- package/lib/flowEngine.js +3 -3
- package/lib/models/flowModel.js +3 -3
- package/lib/utils/parsePathnameToViewParams.d.ts +5 -1
- package/lib/utils/parsePathnameToViewParams.js +28 -4
- package/lib/views/ViewNavigation.d.ts +12 -2
- package/lib/views/ViewNavigation.js +22 -7
- package/lib/views/createViewMeta.js +114 -50
- package/lib/views/inheritLayoutContext.d.ts +10 -0
- package/lib/views/inheritLayoutContext.js +50 -0
- package/lib/views/useDialog.js +2 -0
- package/lib/views/useDrawer.js +2 -0
- package/lib/views/usePage.js +2 -0
- package/package.json +4 -4
- package/src/FlowContextProvider.tsx +9 -1
- package/src/__tests__/createViewMeta.popup.test.ts +115 -1
- package/src/__tests__/flowEngine.removeModel.test.ts +47 -3
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +11 -1
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +5 -2
- package/src/components/subModel/LazyDropdown.tsx +228 -16
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +203 -1
- package/src/data-source/index.ts +18 -0
- package/src/executor/__tests__/flowExecutor.test.ts +28 -0
- package/src/flowContext.ts +3 -0
- package/src/flowEngine.ts +4 -3
- package/src/models/__tests__/flowEngine.resolveUse.test.ts +0 -15
- package/src/models/__tests__/flowModel.test.ts +33 -34
- package/src/models/flowModel.tsx +3 -3
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +21 -0
- package/src/utils/parsePathnameToViewParams.ts +45 -5
- package/src/views/ViewNavigation.ts +40 -7
- package/src/views/__tests__/ViewNavigation.test.ts +52 -0
- package/src/views/__tests__/inheritLayoutContext.test.ts +53 -0
- package/src/views/createViewMeta.ts +106 -34
- package/src/views/inheritLayoutContext.ts +26 -0
- package/src/views/useDialog.tsx +2 -0
- package/src/views/useDrawer.tsx +2 -0
- package/src/views/usePage.tsx +2 -0
|
@@ -47,11 +47,17 @@ function hasUsableSourceId(sourceId) {
|
|
|
47
47
|
return sourceId !== void 0 && sourceId !== null && String(sourceId) !== "";
|
|
48
48
|
}
|
|
49
49
|
__name(hasUsableSourceId, "hasUsableSourceId");
|
|
50
|
-
function
|
|
50
|
+
function normalizeBasePath(basePath) {
|
|
51
|
+
const value = basePath || "/admin";
|
|
52
|
+
return `/${value.replace(/^\/+/, "").replace(/\/+$/, "")}`;
|
|
53
|
+
}
|
|
54
|
+
__name(normalizeBasePath, "normalizeBasePath");
|
|
55
|
+
function generatePathnameFromViewParams(viewParams, options = {}) {
|
|
56
|
+
const basePath = normalizeBasePath(options.basePath || options.prefix);
|
|
51
57
|
if (!viewParams || viewParams.length === 0) {
|
|
52
|
-
return
|
|
58
|
+
return basePath;
|
|
53
59
|
}
|
|
54
|
-
const segments =
|
|
60
|
+
const segments = basePath.replace(/^\/+/, "").split("/").filter(Boolean);
|
|
55
61
|
viewParams.forEach((viewParam, index) => {
|
|
56
62
|
if (index > 0) {
|
|
57
63
|
segments.push("view");
|
|
@@ -78,9 +84,11 @@ const _ViewNavigation = class _ViewNavigation {
|
|
|
78
84
|
// 只能通过 setViewStack 修改
|
|
79
85
|
ctx;
|
|
80
86
|
viewParams;
|
|
81
|
-
|
|
87
|
+
basePath;
|
|
88
|
+
constructor(ctx, viewParams, options = {}) {
|
|
82
89
|
this.setViewStack(viewParams);
|
|
83
90
|
this.ctx = ctx;
|
|
91
|
+
this.basePath = options.basePath || options.layoutBasePath;
|
|
84
92
|
(0, import_reactive.define)(this, {
|
|
85
93
|
viewParams: import_reactive.observable
|
|
86
94
|
});
|
|
@@ -96,19 +104,26 @@ const _ViewNavigation = class _ViewNavigation {
|
|
|
96
104
|
}
|
|
97
105
|
return { ...item };
|
|
98
106
|
});
|
|
99
|
-
const newPathname = generatePathnameFromViewParams(newViewStack);
|
|
107
|
+
const newPathname = generatePathnameFromViewParams(newViewStack, { basePath: this.getLayoutBasePath() });
|
|
100
108
|
this.ctx.router.navigate(newPathname, { replace: true });
|
|
101
109
|
}
|
|
102
110
|
navigateTo(viewParam, opts) {
|
|
103
|
-
const newViewPathname = generatePathnameFromViewParams([...this.viewStack, viewParam]
|
|
111
|
+
const newViewPathname = generatePathnameFromViewParams([...this.viewStack, viewParam], {
|
|
112
|
+
basePath: this.getLayoutBasePath()
|
|
113
|
+
});
|
|
104
114
|
const newPathname = newViewPathname;
|
|
105
115
|
this.ctx.router.navigate(newPathname, opts);
|
|
106
116
|
}
|
|
107
117
|
back() {
|
|
108
118
|
const prevStack = this.viewStack.slice(0, -1);
|
|
109
|
-
const prevPath = generatePathnameFromViewParams(prevStack);
|
|
119
|
+
const prevPath = generatePathnameFromViewParams(prevStack, { basePath: this.getLayoutBasePath() });
|
|
110
120
|
this.ctx.router.navigate(prevPath, { replace: true });
|
|
111
121
|
}
|
|
122
|
+
getLayoutBasePath() {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
const routePath = (_a = this.ctx.layout) == null ? void 0 : _a.routePath;
|
|
125
|
+
return this.basePath || ((_b = this.ctx.layoutRoute) == null ? void 0 : _b.basePathname) || ((routePath == null ? void 0 : routePath.startsWith("/")) ? routePath : "/admin");
|
|
126
|
+
}
|
|
112
127
|
};
|
|
113
128
|
__name(_ViewNavigation, "ViewNavigation");
|
|
114
129
|
let ViewNavigation = _ViewNavigation;
|
|
@@ -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
|
|
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
|
|
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
|
|
180
|
+
var _a, _b, _c, _d, _e, _f;
|
|
120
181
|
try {
|
|
121
182
|
const useCtx = flowCtx || ctx;
|
|
122
|
-
const
|
|
123
|
-
const stack =
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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 = (
|
|
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
|
-
(
|
|
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 = ((
|
|
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
|
-
(
|
|
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
|
|
159
|
-
const stack =
|
|
160
|
-
|
|
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
|
|
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
|
|
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
|
|
240
|
-
const
|
|
241
|
-
if (
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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
|
|
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
|
|
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
|
|
301
|
-
const
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
304
|
-
let model = (
|
|
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:
|
|
370
|
+
model = await ctx.engine.loadModel({ uid: current.viewUid });
|
|
307
371
|
}
|
|
308
|
-
const p = ((
|
|
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
|
-
(
|
|
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
|
|
366
|
-
const
|
|
367
|
-
const
|
|
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 =
|
|
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,
|
|
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 = (
|
|
456
|
+
let model = (_b = ctx.engine) == null ? void 0 : _b.getModel(viewUid, true);
|
|
393
457
|
if (!model) {
|
|
394
|
-
model = await ((
|
|
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(
|
|
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
|
+
});
|
package/lib/views/useDialog.js
CHANGED
|
@@ -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 = {
|
package/lib/views/useDrawer.js
CHANGED
|
@@ -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 = {
|
package/lib/views/usePage.js
CHANGED
|
@@ -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-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.45",
|
|
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-alpha.
|
|
12
|
-
"@nocobase/shared": "2.1.0-alpha.
|
|
11
|
+
"@nocobase/sdk": "2.1.0-alpha.45",
|
|
12
|
+
"@nocobase/shared": "2.1.0-alpha.45",
|
|
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": "
|
|
40
|
+
"gitHead": "e9e24987e12d0ad10a5db8815b1e1b7b447f1938"
|
|
41
41
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import React, { createContext, useContext } from 'react';
|
|
11
11
|
import { FlowContext, FlowEngineContext } from './flowContext';
|
|
12
|
-
import { FlowView } from './views/FlowView';
|
|
12
|
+
import { FlowView, FlowViewer } from './views/FlowView';
|
|
13
13
|
|
|
14
14
|
export const FlowReactContext = createContext<FlowContext>(null);
|
|
15
15
|
export const FlowViewContext = createContext<FlowContext>(null);
|
|
@@ -40,3 +40,11 @@ export function useFlowView() {
|
|
|
40
40
|
const ctx = useFlowContext();
|
|
41
41
|
return ctx.view as FlowView;
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Access the `FlowViewer` that opens new drawers / modals / pages (`viewer.drawer({...})`, `viewer.modal({...})`, etc.). This is the counterpart to `useFlowView()`: `useFlowView()` returns the *current* mounted view (use it to close yourself, render Header/Footer slots, etc.), while `useFlowViewer()` returns the surface that lets you open a *new* view from inside any flow-context subtree.
|
|
46
|
+
*/
|
|
47
|
+
export function useFlowViewer() {
|
|
48
|
+
const ctx = useFlowContext();
|
|
49
|
+
return ctx.viewer as FlowViewer;
|
|
50
|
+
}
|
|
@@ -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 推断到集合名和主键即可;集合详情在懒加载时再取
|