@nocobase/flow-engine 2.1.0-alpha.40 → 2.1.0-alpha.46
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 +84 -32
- package/lib/components/subModel/LazyDropdown.js +208 -16
- package/lib/components/subModel/utils.d.ts +1 -0
- package/lib/components/subModel/utils.js +6 -2
- package/lib/data-source/index.d.ts +9 -0
- package/lib/data-source/index.js +12 -0
- package/lib/executor/FlowExecutor.js +0 -3
- package/lib/flowContext.d.ts +6 -1
- package/lib/flowContext.js +38 -6
- package/lib/flowEngine.d.ts +4 -3
- package/lib/flowEngine.js +72 -40
- package/lib/models/flowModel.js +48 -16
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +4 -3
- package/lib/runjs-context/contexts/JSBlockRunJSContext.js +4 -15
- package/lib/runjs-context/contexts/JSColumnRunJSContext.js +5 -2
- package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +5 -8
- package/lib/runjs-context/contexts/JSFieldRunJSContext.js +4 -3
- package/lib/runjs-context/contexts/JSItemRunJSContext.js +4 -3
- package/lib/runjs-context/contexts/base.js +464 -29
- package/lib/runjs-context/contexts/elementDoc.d.ts +11 -0
- package/lib/runjs-context/contexts/elementDoc.js +152 -0
- package/lib/utils/loadedPageCache.d.ts +24 -0
- package/lib/utils/loadedPageCache.js +139 -0
- 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__/flowContext.test.ts +23 -0
- package/src/__tests__/flowEngine.moveModel.test.ts +81 -1
- package/src/__tests__/flowEngine.removeModel.test.ts +47 -3
- package/src/__tests__/runjsContext.test.ts +18 -0
- package/src/__tests__/runjsContextImplementations.test.ts +9 -2
- package/src/__tests__/runjsLocales.test.ts +6 -5
- package/src/__tests__/viewScopedFlowEngine.test.ts +133 -0
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +90 -38
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +155 -5
- package/src/components/subModel/LazyDropdown.tsx +237 -16
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +254 -1
- package/src/components/subModel/utils.ts +6 -1
- package/src/data-source/index.ts +18 -0
- package/src/executor/FlowExecutor.ts +0 -3
- package/src/executor/__tests__/flowExecutor.test.ts +26 -0
- package/src/flowContext.ts +43 -6
- package/src/flowEngine.ts +75 -38
- package/src/models/__tests__/flowEngine.resolveUse.test.ts +0 -15
- package/src/models/__tests__/flowModel.test.ts +46 -62
- package/src/models/flowModel.tsx +65 -32
- package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +4 -3
- package/src/runjs-context/contexts/JSBlockRunJSContext.ts +4 -15
- package/src/runjs-context/contexts/JSColumnRunJSContext.ts +4 -2
- package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +5 -9
- package/src/runjs-context/contexts/JSFieldRunJSContext.ts +4 -3
- package/src/runjs-context/contexts/JSItemRunJSContext.ts +4 -3
- package/src/runjs-context/contexts/base.ts +467 -31
- package/src/runjs-context/contexts/elementDoc.ts +130 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +21 -0
- package/src/utils/loadedPageCache.ts +147 -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
package/lib/flowContext.d.ts
CHANGED
|
@@ -222,6 +222,10 @@ export type FlowContextGetApiInfosOptions = {
|
|
|
222
222
|
* RunJS 文档版本(默认 v1)。
|
|
223
223
|
*/
|
|
224
224
|
version?: RunJSVersion;
|
|
225
|
+
/**
|
|
226
|
+
* Include editor completion metadata. Defaults to false so API-doc callers keep the compact public shape.
|
|
227
|
+
*/
|
|
228
|
+
includeCompletion?: boolean;
|
|
225
229
|
};
|
|
226
230
|
export type FlowContextGetVarInfosOptions = {
|
|
227
231
|
/**
|
|
@@ -293,7 +297,7 @@ export declare class FlowContext {
|
|
|
293
297
|
* - 输出仅来自 RunJS doc 与 defineProperty/defineMethod 的 info
|
|
294
298
|
* - 不读取/展开 PropertyMeta(变量结构)
|
|
295
299
|
* - 不自动展开深层 properties
|
|
296
|
-
* -
|
|
300
|
+
* - 默认不返回自动补全字段(例如 completion),传入 includeCompletion=true 时返回
|
|
297
301
|
*/
|
|
298
302
|
getApiInfos(options?: FlowContextGetApiInfosOptions): Promise<Record<string, FlowContextApiInfo>>;
|
|
299
303
|
/**
|
|
@@ -423,6 +427,7 @@ export declare class FlowRuntimeContext<TModel extends FlowModel = FlowModel, TM
|
|
|
423
427
|
export type FlowSettingsContext<TModel extends FlowModel = FlowModel> = FlowRuntimeContext<TModel, 'settings'>;
|
|
424
428
|
export type RunJSDocCompletionDoc = {
|
|
425
429
|
insertText?: string;
|
|
430
|
+
requires?: Array<'element'>;
|
|
426
431
|
};
|
|
427
432
|
export type RunJSDocHiddenDoc = boolean | ((ctx: any) => boolean | Promise<boolean>);
|
|
428
433
|
export type RunJSDocHiddenOrPathsDoc = boolean | string[] | ((ctx: any) => boolean | string[] | Promise<boolean | string[]>);
|
package/lib/flowContext.js
CHANGED
|
@@ -399,10 +399,11 @@ const _FlowContext = class _FlowContext {
|
|
|
399
399
|
* - 输出仅来自 RunJS doc 与 defineProperty/defineMethod 的 info
|
|
400
400
|
* - 不读取/展开 PropertyMeta(变量结构)
|
|
401
401
|
* - 不自动展开深层 properties
|
|
402
|
-
* -
|
|
402
|
+
* - 默认不返回自动补全字段(例如 completion),传入 includeCompletion=true 时返回
|
|
403
403
|
*/
|
|
404
404
|
async getApiInfos(options = {}) {
|
|
405
405
|
const version = options.version || "v1";
|
|
406
|
+
const includeCompletion = !!options.includeCompletion;
|
|
406
407
|
const evalCtx = this.createProxy();
|
|
407
408
|
const isPrivateKey = /* @__PURE__ */ __name((key) => typeof key === "string" && key.startsWith("_"), "isPrivateKey");
|
|
408
409
|
const isVarRootKey = /* @__PURE__ */ __name((key) => key === "record" || key === "formValues" || key === "popup", "isVarRootKey");
|
|
@@ -439,7 +440,14 @@ const _FlowContext = class _FlowContext {
|
|
|
439
440
|
const src = toDocObject(obj);
|
|
440
441
|
if (!src) return {};
|
|
441
442
|
const out2 = {};
|
|
442
|
-
for (const k of [
|
|
443
|
+
for (const k of [
|
|
444
|
+
"description",
|
|
445
|
+
"examples",
|
|
446
|
+
...includeCompletion ? ["completion"] : [],
|
|
447
|
+
"ref",
|
|
448
|
+
"params",
|
|
449
|
+
"returns"
|
|
450
|
+
]) {
|
|
443
451
|
const v = src[k];
|
|
444
452
|
if (typeof v !== "undefined") out2[k] = v;
|
|
445
453
|
}
|
|
@@ -452,7 +460,17 @@ const _FlowContext = class _FlowContext {
|
|
|
452
460
|
const src = toDocObject(obj);
|
|
453
461
|
if (!src) return {};
|
|
454
462
|
const out2 = {};
|
|
455
|
-
for (const k of [
|
|
463
|
+
for (const k of [
|
|
464
|
+
"title",
|
|
465
|
+
"type",
|
|
466
|
+
"interface",
|
|
467
|
+
"description",
|
|
468
|
+
"examples",
|
|
469
|
+
...includeCompletion ? ["completion"] : [],
|
|
470
|
+
"ref",
|
|
471
|
+
"params",
|
|
472
|
+
"returns"
|
|
473
|
+
]) {
|
|
456
474
|
const v = src[k];
|
|
457
475
|
if (typeof v !== "undefined") out2[k] = v;
|
|
458
476
|
}
|
|
@@ -539,7 +557,7 @@ const _FlowContext = class _FlowContext {
|
|
|
539
557
|
node = { ...node, ...pickPropertyInfo(docObj) };
|
|
540
558
|
node = { ...node, ...pickPropertyInfo(infoObj) };
|
|
541
559
|
delete node.properties;
|
|
542
|
-
delete node.completion;
|
|
560
|
+
if (!includeCompletion) delete node.completion;
|
|
543
561
|
if (!Object.keys(node).length) continue;
|
|
544
562
|
const outKey = mapDocKeyToApiKey(key, docNode);
|
|
545
563
|
out[outKey] = out[outKey] ? { ...out[outKey] || {}, ...node || {} } : node;
|
|
@@ -554,7 +572,7 @@ const _FlowContext = class _FlowContext {
|
|
|
554
572
|
node = { ...node, ...pickMethodInfo(docObj) };
|
|
555
573
|
node = { ...node, ...pickMethodInfo(info) };
|
|
556
574
|
delete node.properties;
|
|
557
|
-
delete node.completion;
|
|
575
|
+
if (!includeCompletion) delete node.completion;
|
|
558
576
|
if (!Object.keys(node).length) continue;
|
|
559
577
|
node.type = "function";
|
|
560
578
|
if (!out[key]) out[key] = node;
|
|
@@ -571,7 +589,7 @@ const _FlowContext = class _FlowContext {
|
|
|
571
589
|
let node = {};
|
|
572
590
|
node = { ...node, ...pickPropertyInfo(childObj) };
|
|
573
591
|
delete node.properties;
|
|
574
|
-
delete node.completion;
|
|
592
|
+
if (!includeCompletion) delete node.completion;
|
|
575
593
|
if (!node.description || !String(node.description).trim()) continue;
|
|
576
594
|
out[outKey] = node;
|
|
577
595
|
}
|
|
@@ -2255,6 +2273,17 @@ const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext
|
|
|
2255
2273
|
});
|
|
2256
2274
|
const jsCode = await (0, import_utils.prepareRunJsCode)(String(code ?? ""), { preprocessTemplates: shouldPreprocessTemplates });
|
|
2257
2275
|
return runner.run(jsCode);
|
|
2276
|
+
},
|
|
2277
|
+
{
|
|
2278
|
+
description: "Execute a RunJS code string in the current Flow context.",
|
|
2279
|
+
detail: "(code: string, variables?: Record<string, any>, options?: JSRunnerOptions) => Promise<RunJSResult>",
|
|
2280
|
+
params: [
|
|
2281
|
+
{ name: "code", type: "string", description: "RunJS code to execute." },
|
|
2282
|
+
{ name: "variables", type: "Record<string, any>", optional: true, description: "Additional globals." },
|
|
2283
|
+
{ name: "options", type: "JSRunnerOptions", optional: true, description: "Runner options." }
|
|
2284
|
+
],
|
|
2285
|
+
returns: { type: "Promise<{ success: boolean; value?: any; error?: any; timeout?: boolean }>" },
|
|
2286
|
+
completion: { insertText: `await ctx.runjs('return 1')` }
|
|
2258
2287
|
}
|
|
2259
2288
|
);
|
|
2260
2289
|
}
|
|
@@ -2697,6 +2726,9 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
2697
2726
|
}, "get")
|
|
2698
2727
|
});
|
|
2699
2728
|
this.defineMethod("aclCheck", function(params) {
|
|
2729
|
+
if (this.skipAclCheck) {
|
|
2730
|
+
return true;
|
|
2731
|
+
}
|
|
2700
2732
|
return this.acl.aclCheck(params);
|
|
2701
2733
|
});
|
|
2702
2734
|
this.defineMethod("createResource", function(resourceType) {
|
package/lib/flowEngine.d.ts
CHANGED
|
@@ -93,6 +93,7 @@ export declare class FlowEngine {
|
|
|
93
93
|
* @private
|
|
94
94
|
*/
|
|
95
95
|
private _savingModels;
|
|
96
|
+
private _loadedPageCache;
|
|
96
97
|
/**
|
|
97
98
|
* Flow engine context object.
|
|
98
99
|
* @private
|
|
@@ -537,11 +538,11 @@ export declare class FlowEngine {
|
|
|
537
538
|
replaceModel<T extends FlowModel = FlowModel>(uid: string, optionsOrFn?: Partial<FlowModelOptions> | ((currentOptions: FlowModelOptions) => Partial<FlowModelOptions>)): Promise<T | null>;
|
|
538
539
|
/**
|
|
539
540
|
* Move a model instance within its parent model.
|
|
540
|
-
* @param {
|
|
541
|
-
* @param {
|
|
541
|
+
* @param {string | number} sourceId Source model UID
|
|
542
|
+
* @param {string | number} targetId Target model UID
|
|
542
543
|
* @returns {Promise<void>} No return value
|
|
543
544
|
*/
|
|
544
|
-
moveModel(sourceId:
|
|
545
|
+
moveModel(sourceId: string | number, targetId: string | number, options?: PersistOptions): Promise<void>;
|
|
545
546
|
/**
|
|
546
547
|
* Filter model classes by parent class (supports multi-level inheritance).
|
|
547
548
|
* @param {string | ModelConstructor} parentClass Parent class name or constructor
|
package/lib/flowEngine.js
CHANGED
|
@@ -61,8 +61,10 @@ var import_ReactView = require("./ReactView");
|
|
|
61
61
|
var import_resources = require("./resources");
|
|
62
62
|
var import_emitter = require("./emitter");
|
|
63
63
|
var import_ModelOperationScheduler = __toESM(require("./scheduler/ModelOperationScheduler"));
|
|
64
|
+
var import_loadedPageCache = require("./utils/loadedPageCache");
|
|
64
65
|
var import_utils = require("./utils");
|
|
65
66
|
var _FlowEngine_instances, registerModel_fn;
|
|
67
|
+
const getFlowEngineLoggerLevel = /* @__PURE__ */ __name(() => process.env.NODE_ENV === "production" ? "warn" : "trace", "getFlowEngineLoggerLevel");
|
|
66
68
|
const _FlowEngine = class _FlowEngine {
|
|
67
69
|
/**
|
|
68
70
|
* Constructor. Initializes React view, registers default model and form scopes.
|
|
@@ -129,6 +131,7 @@ const _FlowEngine = class _FlowEngine {
|
|
|
129
131
|
* @private
|
|
130
132
|
*/
|
|
131
133
|
__publicField(this, "_savingModels", /* @__PURE__ */ new Map());
|
|
134
|
+
__publicField(this, "_loadedPageCache", (0, import_loadedPageCache.createLoadedPageCache)());
|
|
132
135
|
/**
|
|
133
136
|
* Flow engine context object.
|
|
134
137
|
* @private
|
|
@@ -195,7 +198,7 @@ const _FlowEngine = class _FlowEngine {
|
|
|
195
198
|
MultiRecordResource: import_resources.MultiRecordResource
|
|
196
199
|
});
|
|
197
200
|
this.logger = (0, import_pino.default)({
|
|
198
|
-
level:
|
|
201
|
+
level: getFlowEngineLoggerLevel(),
|
|
199
202
|
browser: {
|
|
200
203
|
write: {
|
|
201
204
|
fatal: /* @__PURE__ */ __name((o) => console.trace(o), "fatal"),
|
|
@@ -859,7 +862,6 @@ const _FlowEngine = class _FlowEngine {
|
|
|
859
862
|
const visited = /* @__PURE__ */ new Set();
|
|
860
863
|
while (current) {
|
|
861
864
|
if (visited.has(current)) {
|
|
862
|
-
console.warn(`FlowEngine: resolveUse circular reference detected on '${current.name}'.`);
|
|
863
865
|
break;
|
|
864
866
|
}
|
|
865
867
|
visited.add(current);
|
|
@@ -960,7 +962,7 @@ const _FlowEngine = class _FlowEngine {
|
|
|
960
962
|
removeModel(uid) {
|
|
961
963
|
var _a, _b, _c;
|
|
962
964
|
if (!this._modelInstances.has(uid)) {
|
|
963
|
-
|
|
965
|
+
this.logger.debug(`FlowEngine: Model with UID '${uid}' does not exist.`);
|
|
964
966
|
return false;
|
|
965
967
|
}
|
|
966
968
|
const modelInstance = this._modelInstances.get(uid);
|
|
@@ -1138,10 +1140,11 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1138
1140
|
async loadModel(options) {
|
|
1139
1141
|
if (!this.ensureModelRepository()) return;
|
|
1140
1142
|
const refresh = !!(options == null ? void 0 : options.refresh);
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1143
|
+
const bypassLoadedPageCache = this._loadedPageCache.shouldBypass(options, () => this.context.flowSettingsEnabled);
|
|
1144
|
+
if (!refresh && !bypassLoadedPageCache) {
|
|
1145
|
+
const model2 = this.findModelByParentId(options.parentId, options.subKey);
|
|
1146
|
+
if (model2) {
|
|
1147
|
+
return model2;
|
|
1145
1148
|
}
|
|
1146
1149
|
const hydrated = await this.hydrateModelFromPreviousEngines(options);
|
|
1147
1150
|
if (hydrated) {
|
|
@@ -1149,15 +1152,24 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1149
1152
|
}
|
|
1150
1153
|
}
|
|
1151
1154
|
const data = await this._modelRepository.findOne(options);
|
|
1152
|
-
if (!(data == null ? void 0 : data.uid))
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
+
if (!(data == null ? void 0 : data.uid)) {
|
|
1156
|
+
if (bypassLoadedPageCache) {
|
|
1157
|
+
this._loadedPageCache.clear(options);
|
|
1158
|
+
}
|
|
1159
|
+
return null;
|
|
1160
|
+
}
|
|
1161
|
+
if (refresh || bypassLoadedPageCache) {
|
|
1155
1162
|
const existing = this.getModel(data.uid);
|
|
1156
1163
|
if (existing) {
|
|
1157
1164
|
this.removeModelWithSubModels(existing.uid);
|
|
1158
1165
|
}
|
|
1159
1166
|
}
|
|
1160
|
-
|
|
1167
|
+
const model = await this.createModelAsync(data);
|
|
1168
|
+
if (bypassLoadedPageCache) {
|
|
1169
|
+
this._loadedPageCache.mountModelToParent(model, true);
|
|
1170
|
+
this._loadedPageCache.clear(options);
|
|
1171
|
+
}
|
|
1172
|
+
return model;
|
|
1161
1173
|
}
|
|
1162
1174
|
/**
|
|
1163
1175
|
* Find a sub-model by parent model ID and subKey.
|
|
@@ -1188,20 +1200,29 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1188
1200
|
async loadOrCreateModel(options, extra) {
|
|
1189
1201
|
if (!this.ensureModelRepository()) return;
|
|
1190
1202
|
const { uid, parentId, subKey } = options;
|
|
1191
|
-
|
|
1203
|
+
const bypassLoadedPageCache = this._loadedPageCache.shouldBypass(options, () => this.context.flowSettingsEnabled);
|
|
1204
|
+
if (uid && !bypassLoadedPageCache && this._modelInstances.has(uid)) {
|
|
1192
1205
|
return this._modelInstances.get(uid);
|
|
1193
1206
|
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1207
|
+
if (!bypassLoadedPageCache) {
|
|
1208
|
+
const m = this.findModelByParentId(parentId, subKey);
|
|
1209
|
+
if (m) {
|
|
1210
|
+
return m;
|
|
1211
|
+
}
|
|
1212
|
+
const hydrated = await this.hydrateModelFromPreviousEngines(options, extra);
|
|
1213
|
+
if (hydrated) {
|
|
1214
|
+
return hydrated;
|
|
1215
|
+
}
|
|
1201
1216
|
}
|
|
1202
1217
|
const data = await this._modelRepository.findOne(options);
|
|
1203
1218
|
let model = null;
|
|
1204
1219
|
if (data == null ? void 0 : data.uid) {
|
|
1220
|
+
if (bypassLoadedPageCache) {
|
|
1221
|
+
const existing = this.getModel(data.uid);
|
|
1222
|
+
if (existing) {
|
|
1223
|
+
this.removeModelWithSubModels(existing.uid);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1205
1226
|
model = await this.createModelAsync(data, extra);
|
|
1206
1227
|
} else {
|
|
1207
1228
|
model = await this.createModelAsync(options, extra);
|
|
@@ -1209,18 +1230,9 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1209
1230
|
await model.save();
|
|
1210
1231
|
}
|
|
1211
1232
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
});
|
|
1216
|
-
if (subModel) {
|
|
1217
|
-
return model;
|
|
1218
|
-
}
|
|
1219
|
-
if (model.subType === "array") {
|
|
1220
|
-
model.parent.addSubModel(model.subKey, model);
|
|
1221
|
-
} else {
|
|
1222
|
-
model.parent.setSubModel(model.subKey, model);
|
|
1223
|
-
}
|
|
1233
|
+
this._loadedPageCache.mountModelToParent(model, bypassLoadedPageCache);
|
|
1234
|
+
if (bypassLoadedPageCache) {
|
|
1235
|
+
this._loadedPageCache.clear(options);
|
|
1224
1236
|
}
|
|
1225
1237
|
return model;
|
|
1226
1238
|
}
|
|
@@ -1238,6 +1250,9 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1238
1250
|
async saveModel(model, options) {
|
|
1239
1251
|
if (!this.ensureModelRepository()) return;
|
|
1240
1252
|
const modelUid = model.uid;
|
|
1253
|
+
const dirtyLoadedPageKey = this._loadedPageCache.getDirtyKeyForModel(model, {
|
|
1254
|
+
force: !!(options == null ? void 0 : options.onlyStepParams)
|
|
1255
|
+
});
|
|
1241
1256
|
if (this._savingModels.has(modelUid)) {
|
|
1242
1257
|
this.logger.debug(`Model ${modelUid} is already being saved, waiting for existing save operation`);
|
|
1243
1258
|
return await this._savingModels.get(modelUid);
|
|
@@ -1246,6 +1261,7 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1246
1261
|
this._savingModels.set(modelUid, savePromise);
|
|
1247
1262
|
try {
|
|
1248
1263
|
const result = await savePromise;
|
|
1264
|
+
this._loadedPageCache.markDirty(dirtyLoadedPageKey);
|
|
1249
1265
|
return result;
|
|
1250
1266
|
} finally {
|
|
1251
1267
|
this._savingModels.delete(modelUid);
|
|
@@ -1276,10 +1292,15 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1276
1292
|
* @returns {Promise<boolean>} Whether destroyed successfully
|
|
1277
1293
|
*/
|
|
1278
1294
|
async destroyModel(uid) {
|
|
1279
|
-
|
|
1295
|
+
const modelInstance = this._modelInstances.get(uid);
|
|
1296
|
+
const dirtyLoadedPageKey = this._loadedPageCache.getDirtyKeyForModel(modelInstance);
|
|
1297
|
+
const hasModelRepository = this.ensureModelRepository();
|
|
1298
|
+
if (hasModelRepository) {
|
|
1280
1299
|
await this._modelRepository.destroy(uid);
|
|
1281
1300
|
}
|
|
1282
|
-
|
|
1301
|
+
if (hasModelRepository) {
|
|
1302
|
+
this._loadedPageCache.markDirty(dirtyLoadedPageKey);
|
|
1303
|
+
}
|
|
1283
1304
|
const parent = modelInstance == null ? void 0 : modelInstance.parent;
|
|
1284
1305
|
const result = this.removeModel(uid);
|
|
1285
1306
|
parent && parent.emitter.emit("onSubModelDestroyed", modelInstance);
|
|
@@ -1355,18 +1376,25 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1355
1376
|
}
|
|
1356
1377
|
/**
|
|
1357
1378
|
* Move a model instance within its parent model.
|
|
1358
|
-
* @param {
|
|
1359
|
-
* @param {
|
|
1379
|
+
* @param {string | number} sourceId Source model UID
|
|
1380
|
+
* @param {string | number} targetId Target model UID
|
|
1360
1381
|
* @returns {Promise<void>} No return value
|
|
1361
1382
|
*/
|
|
1362
1383
|
async moveModel(sourceId, targetId, options) {
|
|
1363
1384
|
var _a, _b;
|
|
1364
|
-
const
|
|
1365
|
-
const
|
|
1385
|
+
const sourceUid = String(sourceId);
|
|
1386
|
+
const targetUid = String(targetId);
|
|
1387
|
+
if (!sourceUid || !targetUid || sourceUid === targetUid) {
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
const sourceModel = this.getModel(sourceUid);
|
|
1391
|
+
const targetModel = this.getModel(targetUid);
|
|
1366
1392
|
if (!sourceModel || !targetModel) {
|
|
1367
1393
|
console.warn(`FlowEngine: Cannot move model. Source or target model not found.`);
|
|
1368
1394
|
return;
|
|
1369
1395
|
}
|
|
1396
|
+
let position = "after";
|
|
1397
|
+
const dirtyLoadedPageKey = this._loadedPageCache.getDirtyKeyForModel(sourceModel);
|
|
1370
1398
|
const move = /* @__PURE__ */ __name((sourceModel2, targetModel2) => {
|
|
1371
1399
|
if (!sourceModel2.parent || !targetModel2.parent || sourceModel2.parent !== targetModel2.parent) {
|
|
1372
1400
|
console.error("FlowModel.moveTo: Both models must have the same parent to perform move operation.");
|
|
@@ -1389,6 +1417,7 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1389
1417
|
console.warn("FlowModel.moveTo: Current model is already at the target position. No action taken.");
|
|
1390
1418
|
return false;
|
|
1391
1419
|
}
|
|
1420
|
+
position = currentIndex < targetIndex ? "after" : "before";
|
|
1392
1421
|
const [movedModel] = subModelsCopy.splice(currentIndex, 1);
|
|
1393
1422
|
subModelsCopy.splice(targetIndex, 0, movedModel);
|
|
1394
1423
|
subModelsCopy.forEach((model, index) => {
|
|
@@ -1397,10 +1426,13 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1397
1426
|
subModels.splice(0, subModels.length, ...subModelsCopy);
|
|
1398
1427
|
return true;
|
|
1399
1428
|
}, "move");
|
|
1400
|
-
move(sourceModel, targetModel);
|
|
1429
|
+
const moved = move(sourceModel, targetModel);
|
|
1430
|
+
if (!moved) {
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1401
1433
|
if ((options == null ? void 0 : options.persist) !== false && this.ensureModelRepository()) {
|
|
1402
|
-
|
|
1403
|
-
|
|
1434
|
+
await this._modelRepository.move(sourceUid, targetUid, position);
|
|
1435
|
+
this._loadedPageCache.markDirty(dirtyLoadedPageKey);
|
|
1404
1436
|
}
|
|
1405
1437
|
sourceModel.parent.emitter.emit("onSubModelMoved", { source: sourceModel, target: targetModel });
|
|
1406
1438
|
(_b = this.emitter) == null ? void 0 : _b.emit("model:subModel:moved", {
|
package/lib/models/flowModel.js
CHANGED
|
@@ -71,6 +71,18 @@ var _flowContext;
|
|
|
71
71
|
const classActionRegistries = /* @__PURE__ */ new WeakMap();
|
|
72
72
|
const classEventRegistries = /* @__PURE__ */ new WeakMap();
|
|
73
73
|
const modelMetas = /* @__PURE__ */ new WeakMap();
|
|
74
|
+
function getStableSortIndex(item, fallbackIndex) {
|
|
75
|
+
return typeof (item == null ? void 0 : item.sortIndex) === "number" && Number.isFinite(item.sortIndex) ? item.sortIndex : fallbackIndex + 1;
|
|
76
|
+
}
|
|
77
|
+
__name(getStableSortIndex, "getStableSortIndex");
|
|
78
|
+
function sortByStableSortIndex(items) {
|
|
79
|
+
return items.map((item, index) => ({
|
|
80
|
+
item,
|
|
81
|
+
index,
|
|
82
|
+
sortIndex: getStableSortIndex(item, index)
|
|
83
|
+
})).sort((a, b) => a.sortIndex - b.sortIndex || a.index - b.index).map(({ item }) => item);
|
|
84
|
+
}
|
|
85
|
+
__name(sortByStableSortIndex, "sortByStableSortIndex");
|
|
74
86
|
const modelGlobalRegistries = /* @__PURE__ */ new WeakMap();
|
|
75
87
|
const classMenuExtensions = /* @__PURE__ */ new WeakMap();
|
|
76
88
|
const sortExtraMenuItems = /* @__PURE__ */ __name((items) => {
|
|
@@ -204,7 +216,7 @@ const _FlowModel = class _FlowModel {
|
|
|
204
216
|
};
|
|
205
217
|
this.stepParams = options.stepParams || {};
|
|
206
218
|
this.subModels = {};
|
|
207
|
-
this.sortIndex = options.sortIndex
|
|
219
|
+
this.sortIndex = getStableSortIndex({ sortIndex: options.sortIndex }, -1);
|
|
208
220
|
this._options = options;
|
|
209
221
|
this._title = "";
|
|
210
222
|
this._extraTitle = "";
|
|
@@ -416,7 +428,7 @@ const _FlowModel = class _FlowModel {
|
|
|
416
428
|
}
|
|
417
429
|
Object.entries(mergedSubModels || {}).forEach(([key, value]) => {
|
|
418
430
|
if (Array.isArray(value)) {
|
|
419
|
-
value
|
|
431
|
+
sortByStableSortIndex(value).forEach((item) => {
|
|
420
432
|
this.addSubModel(key, item);
|
|
421
433
|
});
|
|
422
434
|
} else {
|
|
@@ -628,26 +640,43 @@ const _FlowModel = class _FlowModel {
|
|
|
628
640
|
return this.props;
|
|
629
641
|
}
|
|
630
642
|
setStepParams(flowKeyOrAllParams, stepKeyOrStepsParams, params) {
|
|
643
|
+
var _a;
|
|
644
|
+
let hasChanged = false;
|
|
631
645
|
if (typeof flowKeyOrAllParams === "string") {
|
|
632
646
|
const flowKey = flowKeyOrAllParams;
|
|
633
647
|
if (typeof stepKeyOrStepsParams === "string" && params !== void 0) {
|
|
634
|
-
|
|
635
|
-
|
|
648
|
+
const currentStepParams = ((_a = this.stepParams[flowKey]) == null ? void 0 : _a[stepKeyOrStepsParams]) || {};
|
|
649
|
+
const nextStepParams = { ...currentStepParams, ...params };
|
|
650
|
+
if (!import_lodash.default.isEqual(currentStepParams, nextStepParams)) {
|
|
651
|
+
if (!this.stepParams[flowKey]) {
|
|
652
|
+
this.stepParams[flowKey] = {};
|
|
653
|
+
}
|
|
654
|
+
this.stepParams[flowKey][stepKeyOrStepsParams] = nextStepParams;
|
|
655
|
+
hasChanged = true;
|
|
636
656
|
}
|
|
637
|
-
this.stepParams[flowKey][stepKeyOrStepsParams] = {
|
|
638
|
-
...this.stepParams[flowKey][stepKeyOrStepsParams],
|
|
639
|
-
...params
|
|
640
|
-
};
|
|
641
657
|
} else if (typeof stepKeyOrStepsParams === "object" && stepKeyOrStepsParams !== null) {
|
|
642
|
-
|
|
658
|
+
const currentFlowParams = this.stepParams[flowKey] || {};
|
|
659
|
+
const nextFlowParams = { ...currentFlowParams, ...stepKeyOrStepsParams };
|
|
660
|
+
if (!import_lodash.default.isEqual(currentFlowParams, nextFlowParams)) {
|
|
661
|
+
this.stepParams[flowKey] = nextFlowParams;
|
|
662
|
+
hasChanged = true;
|
|
663
|
+
}
|
|
643
664
|
}
|
|
644
665
|
} else if (typeof flowKeyOrAllParams === "object" && flowKeyOrAllParams !== null) {
|
|
645
666
|
for (const fk in flowKeyOrAllParams) {
|
|
646
667
|
if (Object.prototype.hasOwnProperty.call(flowKeyOrAllParams, fk)) {
|
|
647
|
-
|
|
668
|
+
const currentFlowParams = this.stepParams[fk] || {};
|
|
669
|
+
const nextFlowParams = { ...currentFlowParams, ...flowKeyOrAllParams[fk] };
|
|
670
|
+
if (!import_lodash.default.isEqual(currentFlowParams, nextFlowParams)) {
|
|
671
|
+
this.stepParams[fk] = nextFlowParams;
|
|
672
|
+
hasChanged = true;
|
|
673
|
+
}
|
|
648
674
|
}
|
|
649
675
|
}
|
|
650
676
|
}
|
|
677
|
+
if (!hasChanged) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
651
680
|
this.emitter.emit("onStepParamsChanged");
|
|
652
681
|
}
|
|
653
682
|
getStepParams(flowKey, stepKey) {
|
|
@@ -668,7 +697,7 @@ const _FlowModel = class _FlowModel {
|
|
|
668
697
|
}
|
|
669
698
|
const isFork = this.isFork === true;
|
|
670
699
|
const target = this;
|
|
671
|
-
|
|
700
|
+
currentFlowEngine.logger.debug(
|
|
672
701
|
`[FlowModel] applyFlow: uid=${this.uid}, flowKey=${flowKey}, isFork=${isFork}, cleanRun=${this.cleanRun}, targetIsFork=${(target == null ? void 0 : target.isFork) === true}`
|
|
673
702
|
);
|
|
674
703
|
return currentFlowEngine.executor.runFlow(target, flowKey, inputArgs, runId);
|
|
@@ -681,7 +710,7 @@ const _FlowModel = class _FlowModel {
|
|
|
681
710
|
}
|
|
682
711
|
const isFork = this.isFork === true;
|
|
683
712
|
const target = this;
|
|
684
|
-
|
|
713
|
+
currentFlowEngine.logger.debug(
|
|
685
714
|
`[FlowModel] dispatchEvent: uid=${this.uid}, event=${eventName}, isFork=${isFork}, cleanRun=${this.cleanRun}, targetIsFork=${(target == null ? void 0 : target.isFork) === true}`
|
|
686
715
|
);
|
|
687
716
|
return await currentFlowEngine.executor.dispatchEvent(target, eventName, inputArgs, options);
|
|
@@ -933,7 +962,10 @@ const _FlowModel = class _FlowModel {
|
|
|
933
962
|
if (!Array.isArray(subModels[subKey])) {
|
|
934
963
|
subModels[subKey] = import_reactive.observable.shallow([]);
|
|
935
964
|
}
|
|
936
|
-
const maxSortIndex = Math.max(
|
|
965
|
+
const maxSortIndex = Math.max(
|
|
966
|
+
...subModels[subKey].map((item, index) => getStableSortIndex(item, index)),
|
|
967
|
+
0
|
|
968
|
+
);
|
|
937
969
|
model.sortIndex = maxSortIndex + 1;
|
|
938
970
|
subModels[subKey].push(model);
|
|
939
971
|
actualParent.emitter.emit("onSubModelAdded", model);
|
|
@@ -981,7 +1013,7 @@ const _FlowModel = class _FlowModel {
|
|
|
981
1013
|
return [];
|
|
982
1014
|
}
|
|
983
1015
|
const results = [];
|
|
984
|
-
import_lodash.default.castArray(model)
|
|
1016
|
+
sortByStableSortIndex(import_lodash.default.castArray(model)).forEach((item, index) => {
|
|
985
1017
|
const result = callback(item, index);
|
|
986
1018
|
if (result) {
|
|
987
1019
|
results.push(item);
|
|
@@ -995,7 +1027,7 @@ const _FlowModel = class _FlowModel {
|
|
|
995
1027
|
return [];
|
|
996
1028
|
}
|
|
997
1029
|
const results = [];
|
|
998
|
-
import_lodash.default.castArray(model)
|
|
1030
|
+
sortByStableSortIndex(import_lodash.default.castArray(model)).forEach((item, index) => {
|
|
999
1031
|
const result = callback(item, index);
|
|
1000
1032
|
results.push(result);
|
|
1001
1033
|
});
|
|
@@ -1056,7 +1088,7 @@ const _FlowModel = class _FlowModel {
|
|
|
1056
1088
|
}
|
|
1057
1089
|
clearForks() {
|
|
1058
1090
|
var _a;
|
|
1059
|
-
|
|
1091
|
+
this.flowEngine.logger.debug(`FlowModel ${this.uid} clearing all forks.`);
|
|
1060
1092
|
if ((_a = this.forks) == null ? void 0 : _a.size) {
|
|
1061
1093
|
this.forks.forEach((fork) => fork.dispose());
|
|
1062
1094
|
this.forks.clear();
|
|
@@ -31,6 +31,7 @@ __export(FormJSFieldItemRunJSContext_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(FormJSFieldItemRunJSContext_exports);
|
|
33
33
|
var import_flowContext = require("../../flowContext");
|
|
34
|
+
var import_elementDoc = require("./elementDoc");
|
|
34
35
|
const _FormJSFieldItemRunJSContext = class _FormJSFieldItemRunJSContext extends import_flowContext.FlowRunJSContext {
|
|
35
36
|
};
|
|
36
37
|
__name(_FormJSFieldItemRunJSContext, "FormJSFieldItemRunJSContext");
|
|
@@ -38,8 +39,8 @@ let FormJSFieldItemRunJSContext = _FormJSFieldItemRunJSContext;
|
|
|
38
39
|
FormJSFieldItemRunJSContext.define({
|
|
39
40
|
label: "FormJSFieldItem RunJS context",
|
|
40
41
|
properties: {
|
|
41
|
-
element: `ElementProxy instance providing a safe DOM container for form field rendering.
|
|
42
|
-
Supports innerHTML, append, and other DOM manipulation methods
|
|
42
|
+
element: (0, import_elementDoc.createElementPropertyDoc)(`ElementProxy instance providing a safe DOM container for form field rendering.
|
|
43
|
+
Supports innerHTML, append, and other DOM manipulation methods.`),
|
|
43
44
|
value: `Current field value (read-only in display mode; in controlled scenarios, use setProps to modify).`,
|
|
44
45
|
record: `Current record data object (read-only).
|
|
45
46
|
Contains all field values of the parent record.`,
|
|
@@ -61,7 +62,7 @@ FormJSFieldItemRunJSContext.define(
|
|
|
61
62
|
{
|
|
62
63
|
label: "\u8868\u5355 JS \u5B57\u6BB5\u9879 RunJS \u4E0A\u4E0B\u6587",
|
|
63
64
|
properties: {
|
|
64
|
-
element: "ElementProxy\uFF0C\u8868\u5355\u5B57\u6BB5\u5BB9\u5668",
|
|
65
|
+
element: (0, import_elementDoc.createZhCNElementPropertyDoc)("ElementProxy\uFF0C\u8868\u5355\u5B57\u6BB5\u5BB9\u5668"),
|
|
65
66
|
value: "\u5B57\u6BB5\u503C\uFF08\u5C55\u793A\u6A21\u5F0F\u4E3A\u53EA\u8BFB\uFF1B\u53D7\u63A7\u573A\u666F\u7528 setProps \u4FEE\u6539\uFF09",
|
|
66
67
|
record: "\u5F53\u524D\u8BB0\u5F55\uFF08\u53EA\u8BFB\uFF09",
|
|
67
68
|
formValues: {
|
|
@@ -31,6 +31,7 @@ __export(JSBlockRunJSContext_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(JSBlockRunJSContext_exports);
|
|
33
33
|
var import_flowContext = require("../../flowContext");
|
|
34
|
+
var import_elementDoc = require("./elementDoc");
|
|
34
35
|
const _JSBlockRunJSContext = class _JSBlockRunJSContext extends import_flowContext.FlowRunJSContext {
|
|
35
36
|
};
|
|
36
37
|
__name(_JSBlockRunJSContext, "JSBlockRunJSContext");
|
|
@@ -38,15 +39,9 @@ let JSBlockRunJSContext = _JSBlockRunJSContext;
|
|
|
38
39
|
JSBlockRunJSContext.define({
|
|
39
40
|
label: "RunJS context",
|
|
40
41
|
properties: {
|
|
41
|
-
element:
|
|
42
|
-
description: `ElementProxy instance providing a safe DOM container.
|
|
42
|
+
element: (0, import_elementDoc.createElementPropertyDoc)(`ElementProxy instance providing a safe DOM container.
|
|
43
43
|
Supports innerHTML, append, and other DOM manipulation methods.
|
|
44
|
-
Use this to render content in the JS block
|
|
45
|
-
detail: "ElementProxy",
|
|
46
|
-
properties: {
|
|
47
|
-
innerHTML: "Set or read the HTML content of the container element."
|
|
48
|
-
}
|
|
49
|
-
},
|
|
44
|
+
Use this to render content in the JS block.`),
|
|
50
45
|
record: `Current record data object (read-only).
|
|
51
46
|
Available when the JS block is within a data block or detail view context.`,
|
|
52
47
|
value: "Current value of the field or component, if available in the current context.",
|
|
@@ -65,13 +60,7 @@ JSBlockRunJSContext.define(
|
|
|
65
60
|
{
|
|
66
61
|
label: "RunJS \u4E0A\u4E0B\u6587",
|
|
67
62
|
properties: {
|
|
68
|
-
element:
|
|
69
|
-
description: "ElementProxy\uFF0C\u5B89\u5168\u7684 DOM \u5BB9\u5668\uFF0C\u652F\u6301 innerHTML/append \u7B49",
|
|
70
|
-
detail: "ElementProxy",
|
|
71
|
-
properties: {
|
|
72
|
-
innerHTML: "\u8BFB\u53D6\u6216\u8BBE\u7F6E\u5BB9\u5668\u7684 HTML \u5185\u5BB9"
|
|
73
|
-
}
|
|
74
|
-
},
|
|
63
|
+
element: (0, import_elementDoc.createZhCNElementPropertyDoc)("ElementProxy\uFF0C\u5B89\u5168\u7684 DOM \u5BB9\u5668\uFF0C\u652F\u6301 innerHTML/append \u7B49"),
|
|
75
64
|
record: "\u5F53\u524D\u8BB0\u5F55\uFF08\u53EA\u8BFB\uFF0C\u7528\u4E8E\u6570\u636E\u533A\u5757/\u8BE6\u60C5\u7B49\u573A\u666F\uFF09",
|
|
76
65
|
value: "\u5F53\u524D\u503C\uFF08\u82E5\u5B58\u5728\uFF09",
|
|
77
66
|
React: "React \u5E93",
|
|
@@ -31,6 +31,7 @@ __export(JSColumnRunJSContext_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(JSColumnRunJSContext_exports);
|
|
33
33
|
var import_flowContext = require("../../flowContext");
|
|
34
|
+
var import_elementDoc = require("./elementDoc");
|
|
34
35
|
const _JSColumnRunJSContext = class _JSColumnRunJSContext extends import_flowContext.FlowRunJSContext {
|
|
35
36
|
};
|
|
36
37
|
__name(_JSColumnRunJSContext, "JSColumnRunJSContext");
|
|
@@ -38,7 +39,9 @@ let JSColumnRunJSContext = _JSColumnRunJSContext;
|
|
|
38
39
|
JSColumnRunJSContext.define({
|
|
39
40
|
label: "JSColumn RunJS context",
|
|
40
41
|
properties: {
|
|
41
|
-
element:
|
|
42
|
+
element: (0, import_elementDoc.createElementPropertyDoc)(
|
|
43
|
+
"ElementProxy instance providing a safe DOM container for the current table cell. Supports innerHTML/append and basic DOM APIs."
|
|
44
|
+
),
|
|
42
45
|
record: "Current row record object (read-only).",
|
|
43
46
|
recordIndex: "Index of the current row in the page (0-based).",
|
|
44
47
|
collection: "Collection definition metadata (read-only).",
|
|
@@ -56,7 +59,7 @@ JSColumnRunJSContext.define(
|
|
|
56
59
|
{
|
|
57
60
|
label: "JS \u5217 RunJS \u4E0A\u4E0B\u6587",
|
|
58
61
|
properties: {
|
|
59
|
-
element: "ElementProxy\uFF0C\u8868\u683C\u5355\u5143\u683C\u7684\u5B89\u5168 DOM \u5BB9\u5668\uFF0C\u652F\u6301 innerHTML/append \u7B49",
|
|
62
|
+
element: (0, import_elementDoc.createZhCNElementPropertyDoc)("ElementProxy\uFF0C\u8868\u683C\u5355\u5143\u683C\u7684\u5B89\u5168 DOM \u5BB9\u5668\uFF0C\u652F\u6301 innerHTML/append \u7B49"),
|
|
60
63
|
record: "\u5F53\u524D\u884C\u8BB0\u5F55\u5BF9\u8C61\uFF08\u53EA\u8BFB\uFF09",
|
|
61
64
|
recordIndex: "\u5F53\u524D\u884C\u7D22\u5F15\uFF08\u4ECE 0 \u5F00\u59CB\uFF09",
|
|
62
65
|
collection: "\u96C6\u5408\u5B9A\u4E49\u5143\u6570\u636E\uFF08\u53EA\u8BFB\uFF09",
|