@nocobase/flow-engine 2.2.0-beta.9 → 2.2.0
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/acl/Acl.d.ts +2 -1
- package/lib/acl/Acl.js +28 -0
- package/lib/components/FlowContextSelector.js +62 -13
- package/lib/components/FormItem.js +11 -7
- package/lib/components/MobilePopup.js +39 -10
- package/lib/components/MobilePopup.style.js +11 -1
- package/lib/components/subModel/LazyDropdown.js +62 -33
- package/lib/components/variables/VariableHybridInput.d.ts +9 -0
- package/lib/components/variables/VariableHybridInput.js +146 -17
- package/lib/components/variables/VariableInput.js +19 -7
- package/lib/components/variables/VariableTag.js +48 -36
- package/lib/components/variables/types.d.ts +21 -0
- package/lib/flowContext.d.ts +12 -1
- package/lib/flowContext.js +47 -6
- package/lib/flowEngine.js +6 -0
- package/lib/flowI18n.js +3 -3
- package/lib/locale/en-US.json +2 -0
- package/lib/locale/index.d.ts +4 -0
- package/lib/locale/zh-CN.json +2 -0
- package/lib/resources/flowResource.js +1 -0
- package/lib/types.d.ts +3 -1
- package/lib/types.js +1 -0
- package/lib/utils/associationObjectVariable.d.ts +10 -0
- package/lib/utils/associationObjectVariable.js +10 -7
- package/lib/utils/dateVariable.d.ts +22 -0
- package/lib/utils/dateVariable.js +123 -16
- package/lib/utils/dirtyAwareApiClient.d.ts +1 -0
- package/lib/utils/dirtyAwareApiClient.js +280 -13
- package/lib/utils/index.d.ts +3 -3
- package/lib/utils/index.js +8 -0
- package/lib/utils/loadedPageCache.d.ts +1 -0
- package/lib/utils/loadedPageCache.js +6 -0
- package/lib/utils/params-resolvers.d.ts +3 -0
- package/lib/utils/params-resolvers.js +10 -0
- package/lib/utils/variablesParams.js +5 -0
- package/lib/views/createViewMeta.d.ts +1 -0
- package/lib/views/createViewMeta.js +53 -22
- package/package.json +4 -4
- package/src/__tests__/createViewMeta.popup.test.ts +84 -1
- package/src/__tests__/flowContext.test.ts +8 -0
- package/src/__tests__/flowI18n.test.ts +11 -0
- package/src/__tests__/objectVariable.test.ts +6 -1
- package/src/__tests__/runjsFormSubmit.test.ts +138 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +72 -6
- package/src/acl/Acl.tsx +36 -1
- package/src/acl/__tests__/Acl.test.tsx +70 -0
- package/src/components/FlowContextSelector.tsx +73 -12
- package/src/components/FormItem.tsx +12 -7
- package/src/components/MobilePopup.style.ts +12 -1
- package/src/components/MobilePopup.tsx +42 -10
- package/src/components/__tests__/FormItem.test.tsx +17 -2
- package/src/components/__tests__/MobilePopup.test.tsx +150 -0
- package/src/components/subModel/LazyDropdown.tsx +71 -38
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +85 -2
- package/src/components/subModel/__tests__/LazyDropdown.test.tsx +202 -0
- package/src/components/variables/VariableHybridInput.tsx +185 -14
- package/src/components/variables/VariableInput.tsx +32 -7
- package/src/components/variables/VariableTag.tsx +51 -37
- package/src/components/variables/__tests__/FlowContextSelector.test.tsx +95 -3
- package/src/components/variables/__tests__/VariableHybridInput.test.tsx +212 -0
- package/src/components/variables/__tests__/VariableInput.test.tsx +202 -6
- package/src/components/variables/__tests__/VariableTag.test.tsx +80 -0
- package/src/components/variables/types.ts +21 -0
- package/src/flowContext.ts +79 -6
- package/src/flowEngine.ts +6 -0
- package/src/flowI18n.ts +8 -3
- package/src/locale/__tests__/index.test.ts +21 -0
- package/src/locale/en-US.json +2 -0
- package/src/locale/zh-CN.json +2 -0
- package/src/resources/__tests__/flowResource.test.ts +3 -0
- package/src/resources/flowResource.ts +1 -0
- package/src/types.ts +2 -0
- package/src/utils/__tests__/dateVariable.test.ts +57 -4
- package/src/utils/__tests__/dirtyAwareApiClient.test.ts +321 -0
- package/src/utils/__tests__/variablesParams.test.ts +28 -1
- package/src/utils/associationObjectVariable.ts +9 -6
- package/src/utils/dateVariable.ts +145 -18
- package/src/utils/dirtyAwareApiClient.ts +348 -13
- package/src/utils/index.ts +17 -2
- package/src/utils/loadedPageCache.ts +7 -0
- package/src/utils/params-resolvers.ts +12 -0
- package/src/utils/variablesParams.ts +10 -0
- package/src/views/createViewMeta.ts +52 -18
package/lib/flowContext.js
CHANGED
|
@@ -2383,8 +2383,8 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
2383
2383
|
this.defineMethod("renderJson", function(template) {
|
|
2384
2384
|
return this.resolveJsonTemplate(template);
|
|
2385
2385
|
});
|
|
2386
|
-
|
|
2387
|
-
var _a, _b;
|
|
2386
|
+
const resolveJsonTemplate = /* @__PURE__ */ __name(async function(template, options) {
|
|
2387
|
+
var _a, _b, _c;
|
|
2388
2388
|
const used = (0, import_utils.extractUsedVariablePaths)(template);
|
|
2389
2389
|
const usedVarNames = Object.keys(used || {});
|
|
2390
2390
|
if (!usedVarNames.length) {
|
|
@@ -2412,13 +2412,13 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
2412
2412
|
let serverResolved = template;
|
|
2413
2413
|
if (needServer) {
|
|
2414
2414
|
const inferRecordRefWithMeta = /* @__PURE__ */ __name((ctx) => {
|
|
2415
|
-
var _a2, _b2,
|
|
2415
|
+
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2416
2416
|
const ref = (0, import_variablesParams.inferRecordRef)(ctx);
|
|
2417
2417
|
if (ref) return ref;
|
|
2418
2418
|
try {
|
|
2419
2419
|
const tk = (_b2 = (_a2 = ctx == null ? void 0 : ctx.resource) == null ? void 0 : _a2.getMeta) == null ? void 0 : _b2.call(_a2, "currentFilterByTk");
|
|
2420
2420
|
if (typeof tk === "undefined" || tk === null) return void 0;
|
|
2421
|
-
const collection = ((
|
|
2421
|
+
const collection = ((_c2 = ctx == null ? void 0 : ctx.collection) == null ? void 0 : _c2.name) || ((_j = (_i = (_h = (_g = (_f = (_e = (_d = ctx == null ? void 0 : ctx.resource) == null ? void 0 : _d.getResourceName) == null ? void 0 : _e.call(_d)) == null ? void 0 : _f.split) == null ? void 0 : _g.call(_f, ".")) == null ? void 0 : _h.slice) == null ? void 0 : _i.call(_h, -1)) == null ? void 0 : _j[0]);
|
|
2422
2422
|
if (!collection) return void 0;
|
|
2423
2423
|
const dataSourceKey = ((_k = ctx == null ? void 0 : ctx.collection) == null ? void 0 : _k.dataSourceKey) || ((_m = (_l = ctx == null ? void 0 : ctx.resource) == null ? void 0 : _l.getDataSourceKey) == null ? void 0 : _m.call(_l));
|
|
2424
2424
|
return { collection, dataSourceKey, filterByTk: tk };
|
|
@@ -2461,6 +2461,11 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
2461
2461
|
}, "collectFromMeta");
|
|
2462
2462
|
const inputFromMeta = await collectFromMeta();
|
|
2463
2463
|
const autoInput = { ...inputFromMeta };
|
|
2464
|
+
const viewPaths = serverVarPaths.view || [];
|
|
2465
|
+
if (!autoInput.view && viewPaths.some((path) => path === "record" || path.startsWith("record.") || path.startsWith("record["))) {
|
|
2466
|
+
const recordRef = (0, import_variablesParams.inferViewRecordRef)(this);
|
|
2467
|
+
if (recordRef) autoInput.view = { record: recordRef };
|
|
2468
|
+
}
|
|
2464
2469
|
try {
|
|
2465
2470
|
const varName = "formValues";
|
|
2466
2471
|
const neededPaths = serverVarPaths[varName] || [];
|
|
@@ -2511,18 +2516,25 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
2511
2516
|
}
|
|
2512
2517
|
if (this.api) {
|
|
2513
2518
|
try {
|
|
2519
|
+
const contractRd = (0, import_params_resolvers.buildFlowModelResolveDescriptor)(
|
|
2520
|
+
this,
|
|
2521
|
+
options == null ? void 0 : options.contractModelUid
|
|
2522
|
+
);
|
|
2514
2523
|
serverResolved = await (0, import_params_resolvers.enqueueVariablesResolve)(this, {
|
|
2524
|
+
...contractRd ? { contractRd } : {},
|
|
2525
|
+
rd: (0, import_params_resolvers.buildFlowModelResolveDescriptor)(this, (_a = this.model) == null ? void 0 : _a.uid),
|
|
2515
2526
|
template,
|
|
2516
2527
|
contextParams: autoContextParams || {}
|
|
2517
2528
|
});
|
|
2518
2529
|
} catch (e) {
|
|
2519
|
-
(
|
|
2530
|
+
(_c = (_b = this.logger) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, { err: e }, "variables:resolve failed, fallback to client-only");
|
|
2520
2531
|
serverResolved = template;
|
|
2521
2532
|
}
|
|
2522
2533
|
}
|
|
2523
2534
|
}
|
|
2524
2535
|
return (0, import_utils.resolveExpressions)(serverResolved, this);
|
|
2525
|
-
});
|
|
2536
|
+
}, "resolveJsonTemplate");
|
|
2537
|
+
this.defineMethod("resolveJsonTemplate", resolveJsonTemplate);
|
|
2526
2538
|
this.defineMethod(
|
|
2527
2539
|
"getVar",
|
|
2528
2540
|
async function(varPath) {
|
|
@@ -3498,9 +3510,38 @@ function __mergeRunJSDocMeta(base, patch) {
|
|
|
3498
3510
|
}
|
|
3499
3511
|
__name(__mergeRunJSDocMeta, "__mergeRunJSDocMeta");
|
|
3500
3512
|
const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
|
|
3513
|
+
[import_dirtyAwareApiClient.PREPARE_CONTEXT_RESOURCE_ACTION_PARAMS](action, params) {
|
|
3514
|
+
var _a, _b, _c, _d, _e;
|
|
3515
|
+
if (action.actionName.toLowerCase() !== "create" || !params || Array.isArray(params) || Object.prototype.hasOwnProperty.call(params, "updateAssociationValues") || !this.form || typeof ((_a = this.blockModel) == null ? void 0 : _a.submitFromRunJs) !== "function") {
|
|
3516
|
+
return params;
|
|
3517
|
+
}
|
|
3518
|
+
const resource = this.resource;
|
|
3519
|
+
const currentResourceName = (_b = resource == null ? void 0 : resource.getResourceName) == null ? void 0 : _b.call(resource);
|
|
3520
|
+
const currentDataSourceKey = ((_c = resource == null ? void 0 : resource.getDataSourceKey) == null ? void 0 : _c.call(resource)) || "main";
|
|
3521
|
+
if (action.resourceName !== currentResourceName || (action.dataSourceKey || "main") !== currentDataSourceKey) {
|
|
3522
|
+
return params;
|
|
3523
|
+
}
|
|
3524
|
+
const currentSourceId = (_d = resource == null ? void 0 : resource.getSourceId) == null ? void 0 : _d.call(resource);
|
|
3525
|
+
if ((currentResourceName == null ? void 0 : currentResourceName.includes(".")) && currentSourceId !== null && typeof currentSourceId !== "undefined" && String(action.resourceOf ?? "") !== String(currentSourceId)) {
|
|
3526
|
+
return params;
|
|
3527
|
+
}
|
|
3528
|
+
const updateAssociationValues = (_e = resource == null ? void 0 : resource.getUpdateAssociationValues) == null ? void 0 : _e.call(resource);
|
|
3529
|
+
if (!Array.isArray(updateAssociationValues) || updateAssociationValues.length === 0) {
|
|
3530
|
+
return params;
|
|
3531
|
+
}
|
|
3532
|
+
return {
|
|
3533
|
+
...params,
|
|
3534
|
+
updateAssociationValues: [...updateAssociationValues]
|
|
3535
|
+
};
|
|
3536
|
+
}
|
|
3501
3537
|
constructor(delegate) {
|
|
3538
|
+
var _a, _b;
|
|
3502
3539
|
super();
|
|
3503
3540
|
this.addDelegate(delegate);
|
|
3541
|
+
const submit = (_b = (_a = delegate.blockModel) == null ? void 0 : _a.submitFromRunJs) == null ? void 0 : _b.bind(delegate.blockModel);
|
|
3542
|
+
if (delegate.form && submit) {
|
|
3543
|
+
this.defineProperty("form", { value: { ...delegate.form, submit } });
|
|
3544
|
+
}
|
|
3504
3545
|
this.defineProperty("React", { value: import_react.default });
|
|
3505
3546
|
this.defineProperty("antd", { value: antd });
|
|
3506
3547
|
this.defineProperty("dayjs", {
|
package/lib/flowEngine.js
CHANGED
|
@@ -1141,6 +1141,9 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1141
1141
|
if (!this.ensureModelRepository()) return;
|
|
1142
1142
|
const refresh = !!(options == null ? void 0 : options.refresh);
|
|
1143
1143
|
const bypassLoadedPageCache = this._loadedPageCache.shouldBypass(options, () => this.context.flowSettingsEnabled);
|
|
1144
|
+
if (this.context.flowSettingsEnabled) {
|
|
1145
|
+
this._loadedPageCache.markDirtyForOptions(options);
|
|
1146
|
+
}
|
|
1144
1147
|
if (!refresh && !bypassLoadedPageCache) {
|
|
1145
1148
|
const model2 = this.findModelByParentId(options.parentId, options.subKey);
|
|
1146
1149
|
if (model2) {
|
|
@@ -1201,6 +1204,9 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1201
1204
|
if (!this.ensureModelRepository()) return;
|
|
1202
1205
|
const { uid, parentId, subKey } = options;
|
|
1203
1206
|
const bypassLoadedPageCache = this._loadedPageCache.shouldBypass(options, () => this.context.flowSettingsEnabled);
|
|
1207
|
+
if (this.context.flowSettingsEnabled) {
|
|
1208
|
+
this._loadedPageCache.markDirtyForOptions(options);
|
|
1209
|
+
}
|
|
1204
1210
|
if (uid && !bypassLoadedPageCache && this._modelInstances.has(uid)) {
|
|
1205
1211
|
return this._modelInstances.get(uid);
|
|
1206
1212
|
}
|
package/lib/flowI18n.js
CHANGED
|
@@ -81,7 +81,7 @@ const _FlowI18n = class _FlowI18n {
|
|
|
81
81
|
* @private
|
|
82
82
|
*/
|
|
83
83
|
isTemplate(str) {
|
|
84
|
-
return /\{\{\s*t\s*\(\s*["'`]
|
|
84
|
+
return /\{\{\s*t\s*\(\s*(["'`])(?:\\.|(?!\1).)*?\1\s*(?:,\s*.*?)?\s*\)\s*\}\}/.test(str);
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* 编译模板字符串
|
|
@@ -89,8 +89,8 @@ const _FlowI18n = class _FlowI18n {
|
|
|
89
89
|
*/
|
|
90
90
|
compileTemplate(template) {
|
|
91
91
|
return template.replace(
|
|
92
|
-
/\{\{\s*t\s*\(\s*["'`](
|
|
93
|
-
(match, key, optionsStr) => {
|
|
92
|
+
/\{\{\s*t\s*\(\s*(["'`])((?:\\.|(?!\1).)*?)\1\s*(?:,\s*((?:[^{}]|\{[^}]*\})*?))?\s*\)\s*\}\}/g,
|
|
93
|
+
(match, _quote, key, optionsStr) => {
|
|
94
94
|
try {
|
|
95
95
|
let templateOptions = {};
|
|
96
96
|
if (optionsStr) {
|
package/lib/locale/en-US.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"Add": "Add",
|
|
3
|
+
"Are you sure you want to perform the action?": "Are you sure you want to perform the action?",
|
|
3
4
|
"Are you sure you want to delete this item? This action cannot be undone.": "Are you sure you want to delete this item? This action cannot be undone.",
|
|
4
5
|
"Are you sure to convert this template block to copy mode?": "Are you sure you want to convert this template block to copy mode?",
|
|
5
6
|
"Array index out of bounds": "Array index {{index}} out of bounds for '{{subKey}}'",
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
"Other blocks": "Other blocks",
|
|
54
55
|
"Parent not found, cannot replace block": "Parent not found, cannot replace block",
|
|
55
56
|
"Previous step": "Previous step",
|
|
57
|
+
"Please Confirm": "Please Confirm",
|
|
56
58
|
"Replace current block with template?": "Replace current block with template?",
|
|
57
59
|
"Replaced with template block": "Replaced with template block",
|
|
58
60
|
"Render failed": "Render failed",
|
package/lib/locale/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
export declare const locales: {
|
|
10
10
|
'en-US': {
|
|
11
11
|
Add: string;
|
|
12
|
+
"Are you sure you want to perform the action?": string;
|
|
12
13
|
"Are you sure you want to delete this item? This action cannot be undone.": string;
|
|
13
14
|
"Are you sure to convert this template block to copy mode?": string;
|
|
14
15
|
"Array index out of bounds": string;
|
|
@@ -62,6 +63,7 @@ export declare const locales: {
|
|
|
62
63
|
"Other blocks": string;
|
|
63
64
|
"Parent not found, cannot replace block": string;
|
|
64
65
|
"Previous step": string;
|
|
66
|
+
"Please Confirm": string;
|
|
65
67
|
"Replace current block with template?": string;
|
|
66
68
|
"Replaced with template block": string;
|
|
67
69
|
"Render failed": string;
|
|
@@ -91,6 +93,7 @@ export declare const locales: {
|
|
|
91
93
|
};
|
|
92
94
|
'zh-CN': {
|
|
93
95
|
Add: string;
|
|
96
|
+
"Are you sure you want to perform the action?": string;
|
|
94
97
|
"Are you sure you want to delete this item? This action cannot be undone.": string;
|
|
95
98
|
"Are you sure to convert this template block to copy mode?": string;
|
|
96
99
|
"Array index out of bounds": string;
|
|
@@ -150,6 +153,7 @@ export declare const locales: {
|
|
|
150
153
|
OK: string;
|
|
151
154
|
"Other blocks": string;
|
|
152
155
|
"Previous step": string;
|
|
156
|
+
"Please Confirm": string;
|
|
153
157
|
"Render failed": string;
|
|
154
158
|
"Response record": string;
|
|
155
159
|
"Step configuration": string;
|
package/lib/locale/zh-CN.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"Add": "添加",
|
|
3
|
+
"Are you sure you want to perform the action?": "确定要执行此操作吗?",
|
|
3
4
|
"Are you sure you want to delete this item? This action cannot be undone.": "确定要删除此项吗?此操作不可撤销。",
|
|
4
5
|
"Are you sure to convert this template block to copy mode?": "确定将该模板区块转换为复制模式吗?",
|
|
5
6
|
"Array index out of bounds": "数组索引 {{index}} 超出 '{{subKey}}' 的边界",
|
|
@@ -59,6 +60,7 @@
|
|
|
59
60
|
"OK": "确定",
|
|
60
61
|
"Other blocks": "其他区块",
|
|
61
62
|
"Previous step": "上一步",
|
|
63
|
+
"Please Confirm": "请确认",
|
|
62
64
|
"Render failed": "渲染失败",
|
|
63
65
|
"Response record": "响应结果记录",
|
|
64
66
|
"Step configuration": "步骤配置",
|
package/lib/types.d.ts
CHANGED
|
@@ -122,7 +122,9 @@ export declare enum ActionScene {
|
|
|
122
122
|
/** 动态事件流可用 */
|
|
123
123
|
DYNAMIC_EVENT_FLOW = 6,
|
|
124
124
|
/** 菜单项联动规则可用 */
|
|
125
|
-
MENU_LINKAGE_RULES = 7
|
|
125
|
+
MENU_LINKAGE_RULES = 7,
|
|
126
|
+
/** 标签页联动规则可用 */
|
|
127
|
+
TAB_LINKAGE_RULES = 8
|
|
126
128
|
}
|
|
127
129
|
/**
|
|
128
130
|
* Defines a reusable action with generic model type support.
|
package/lib/types.js
CHANGED
|
@@ -37,6 +37,7 @@ var ActionScene = /* @__PURE__ */ ((ActionScene2) => {
|
|
|
37
37
|
ActionScene2[ActionScene2["ACTION_LINKAGE_RULES"] = 5] = "ACTION_LINKAGE_RULES";
|
|
38
38
|
ActionScene2[ActionScene2["DYNAMIC_EVENT_FLOW"] = 6] = "DYNAMIC_EVENT_FLOW";
|
|
39
39
|
ActionScene2[ActionScene2["MENU_LINKAGE_RULES"] = 7] = "MENU_LINKAGE_RULES";
|
|
40
|
+
ActionScene2[ActionScene2["TAB_LINKAGE_RULES"] = 8] = "TAB_LINKAGE_RULES";
|
|
40
41
|
return ActionScene2;
|
|
41
42
|
})(ActionScene || {});
|
|
42
43
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { Collection } from '../data-source';
|
|
10
10
|
import type { FlowContext, PropertyMetaFactory } from '../flowContext';
|
|
11
|
+
/**
|
|
12
|
+
* 从值中提取主键:
|
|
13
|
+
* - 支持主键原始值(string/number)
|
|
14
|
+
* - 支持对象(按主键名取值)
|
|
15
|
+
*
|
|
16
|
+
* @param value 字段当前值
|
|
17
|
+
* @param primaryKey 主键字段名
|
|
18
|
+
* @returns 解析出的主键值,无法解析时返回 undefined
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAssociationFilterByTk(value: unknown, primaryKey: string | string[]): unknown;
|
|
11
21
|
/**
|
|
12
22
|
* 创建一个用于“对象类变量”(如 formValues / item)的 `resolveOnServer` 判定函数。
|
|
13
23
|
* 仅当访问路径以“关联字段名”开头(且继续访问其子属性)时,返回 true 交由服务端解析;
|
|
@@ -38,7 +38,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
38
38
|
var associationObjectVariable_exports = {};
|
|
39
39
|
__export(associationObjectVariable_exports, {
|
|
40
40
|
createAssociationAwareObjectMetaFactory: () => createAssociationAwareObjectMetaFactory,
|
|
41
|
-
createAssociationSubpathResolver: () => createAssociationSubpathResolver
|
|
41
|
+
createAssociationSubpathResolver: () => createAssociationSubpathResolver,
|
|
42
|
+
getAssociationFilterByTk: () => getAssociationFilterByTk
|
|
42
43
|
});
|
|
43
44
|
module.exports = __toCommonJS(associationObjectVariable_exports);
|
|
44
45
|
var import_lodash = __toESM(require("lodash"));
|
|
@@ -58,13 +59,14 @@ function findFieldByName(collection, name) {
|
|
|
58
59
|
return fields.find((f) => f.name === name);
|
|
59
60
|
}
|
|
60
61
|
__name(findFieldByName, "findFieldByName");
|
|
61
|
-
function
|
|
62
|
+
function getAssociationFilterByTk(value, primaryKey) {
|
|
62
63
|
if (value == null) return void 0;
|
|
63
64
|
if (Array.isArray(primaryKey)) {
|
|
64
65
|
if (typeof value !== "object" || !value) return void 0;
|
|
66
|
+
const record = value;
|
|
65
67
|
const out = {};
|
|
66
68
|
for (const k of primaryKey) {
|
|
67
|
-
const v =
|
|
69
|
+
const v = record[k];
|
|
68
70
|
if (typeof v === "undefined" || v === null) return void 0;
|
|
69
71
|
out[k] = v;
|
|
70
72
|
}
|
|
@@ -76,7 +78,7 @@ function toFilterByTk(value, primaryKey) {
|
|
|
76
78
|
}
|
|
77
79
|
return void 0;
|
|
78
80
|
}
|
|
79
|
-
__name(
|
|
81
|
+
__name(getAssociationFilterByTk, "getAssociationFilterByTk");
|
|
80
82
|
function createAssociationSubpathResolver(collectionAccessor, valueAccessor) {
|
|
81
83
|
return (p) => {
|
|
82
84
|
if (!p || !p.includes(".")) return false;
|
|
@@ -122,7 +124,7 @@ function createAssociationAwareObjectMetaFactory(collectionAccessor, title, valu
|
|
|
122
124
|
const associationValue = obj[name];
|
|
123
125
|
if (associationValue == null) continue;
|
|
124
126
|
if (Array.isArray(associationValue)) {
|
|
125
|
-
const ids = associationValue.map((item) =>
|
|
127
|
+
const ids = associationValue.map((item) => getAssociationFilterByTk(item, primaryKey)).filter((v) => v != null);
|
|
126
128
|
if (ids.length) {
|
|
127
129
|
params[name] = {
|
|
128
130
|
collection: target,
|
|
@@ -131,7 +133,7 @@ function createAssociationAwareObjectMetaFactory(collectionAccessor, title, valu
|
|
|
131
133
|
};
|
|
132
134
|
}
|
|
133
135
|
} else {
|
|
134
|
-
const id =
|
|
136
|
+
const id = getAssociationFilterByTk(associationValue, primaryKey);
|
|
135
137
|
if (id != null) {
|
|
136
138
|
params[name] = {
|
|
137
139
|
collection: target,
|
|
@@ -153,5 +155,6 @@ __name(createAssociationAwareObjectMetaFactory, "createAssociationAwareObjectMet
|
|
|
153
155
|
// Annotate the CommonJS export names for ESM import in node:
|
|
154
156
|
0 && (module.exports = {
|
|
155
157
|
createAssociationAwareObjectMetaFactory,
|
|
156
|
-
createAssociationSubpathResolver
|
|
158
|
+
createAssociationSubpathResolver,
|
|
159
|
+
getAssociationFilterByTk
|
|
157
160
|
});
|
|
@@ -6,11 +6,33 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
declare const PRESET_KEY_LIST: readonly ["today", "now", "yesterday", "tomorrow", "thisWeek", "lastWeek", "nextWeek", "thisMonth", "lastMonth", "nextMonth", "thisQuarter", "lastQuarter", "nextQuarter", "thisYear", "lastYear", "nextYear"];
|
|
10
|
+
export type CtxDatePreset = (typeof PRESET_KEY_LIST)[number];
|
|
11
|
+
export type CtxDateRelativeDirection = 'next' | 'past';
|
|
12
|
+
export type CtxDateRelativeUnit = 'day' | 'week' | 'month' | 'year';
|
|
13
|
+
export type CtxDateExpressionConfig = {
|
|
14
|
+
kind: 'exact';
|
|
15
|
+
value: string | [string, string];
|
|
16
|
+
format?: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'relative';
|
|
19
|
+
direction: CtxDateRelativeDirection;
|
|
20
|
+
amount: number;
|
|
21
|
+
unit: CtxDateRelativeUnit;
|
|
22
|
+
format?: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'preset';
|
|
25
|
+
preset: CtxDatePreset;
|
|
26
|
+
format?: string;
|
|
27
|
+
};
|
|
9
28
|
export declare function isCtxDatePathPrefix(pathSegments: string[]): boolean;
|
|
10
29
|
export declare function encodeBase64Url(input: string): string;
|
|
11
30
|
export declare function decodeBase64Url(input: string): string | undefined;
|
|
12
31
|
export declare function isCtxDateExpression(value: unknown): value is string;
|
|
13
32
|
export declare function isCompleteCtxDatePath(pathSegments: string[]): boolean;
|
|
14
33
|
export declare function parseCtxDateExpression(value: unknown): any;
|
|
34
|
+
export declare function parseCtxDateExpressionConfig(value: unknown): CtxDateExpressionConfig | undefined;
|
|
35
|
+
export declare function serializeCtxDateExpressionConfig(config: CtxDateExpressionConfig): string | undefined;
|
|
15
36
|
export declare function serializeCtxDateValue(value: unknown): string | undefined;
|
|
16
37
|
export declare function resolveCtxDatePath(pathSegments: string[]): any;
|
|
38
|
+
export {};
|
|
@@ -43,13 +43,15 @@ __export(dateVariable_exports, {
|
|
|
43
43
|
isCtxDateExpression: () => isCtxDateExpression,
|
|
44
44
|
isCtxDatePathPrefix: () => isCtxDatePathPrefix,
|
|
45
45
|
parseCtxDateExpression: () => parseCtxDateExpression,
|
|
46
|
+
parseCtxDateExpressionConfig: () => parseCtxDateExpressionConfig,
|
|
46
47
|
resolveCtxDatePath: () => resolveCtxDatePath,
|
|
48
|
+
serializeCtxDateExpressionConfig: () => serializeCtxDateExpressionConfig,
|
|
47
49
|
serializeCtxDateValue: () => serializeCtxDateValue
|
|
48
50
|
});
|
|
49
51
|
module.exports = __toCommonJS(dateVariable_exports);
|
|
50
52
|
var import_dayjs = __toESM(require("dayjs"));
|
|
51
53
|
const CTX_DATE_REGEX = /^\{\{\s*ctx\.date(?:\.(.+?))?\s*\}\}$/;
|
|
52
|
-
const
|
|
54
|
+
const PRESET_KEY_LIST = [
|
|
53
55
|
"today",
|
|
54
56
|
"now",
|
|
55
57
|
"yesterday",
|
|
@@ -66,9 +68,11 @@ const PRESET_KEYS = /* @__PURE__ */ new Set([
|
|
|
66
68
|
"thisYear",
|
|
67
69
|
"lastYear",
|
|
68
70
|
"nextYear"
|
|
69
|
-
]
|
|
71
|
+
];
|
|
72
|
+
const PRESET_KEYS = new Set(PRESET_KEY_LIST);
|
|
70
73
|
const RELATIVE_DIRECTIONS = /* @__PURE__ */ new Set(["next", "past"]);
|
|
71
74
|
const RELATIVE_UNITS = /* @__PURE__ */ new Set(["day", "week", "month", "year"]);
|
|
75
|
+
const MAX_DATE_FORMAT_LENGTH = 128;
|
|
72
76
|
function parseCtxDateSegments(value) {
|
|
73
77
|
if (typeof value !== "string") return null;
|
|
74
78
|
const trimmed = value.trim();
|
|
@@ -79,8 +83,7 @@ function parseCtxDateSegments(value) {
|
|
|
79
83
|
return rawPath.split(".").map((seg) => seg.trim()).filter(Boolean);
|
|
80
84
|
}
|
|
81
85
|
__name(parseCtxDateSegments, "parseCtxDateSegments");
|
|
82
|
-
function
|
|
83
|
-
const segments = withDatePrefix((pathSegments || []).map((seg) => String(seg)));
|
|
86
|
+
function isBaseCtxDatePathPrefix(segments) {
|
|
84
87
|
if (segments[0] !== "date") return false;
|
|
85
88
|
if (segments.length === 1) return true;
|
|
86
89
|
if (segments[1] === "preset") {
|
|
@@ -117,6 +120,34 @@ function isCtxDatePathPrefix(pathSegments) {
|
|
|
117
120
|
}
|
|
118
121
|
return false;
|
|
119
122
|
}
|
|
123
|
+
__name(isBaseCtxDatePathPrefix, "isBaseCtxDatePathPrefix");
|
|
124
|
+
function decodeFormatToken(token) {
|
|
125
|
+
const raw = String(token || "");
|
|
126
|
+
if (!raw.startsWith("v")) return void 0;
|
|
127
|
+
const decoded = decodeBase64Url(raw.slice(1));
|
|
128
|
+
if (!decoded || decoded.length > MAX_DATE_FORMAT_LENGTH) return void 0;
|
|
129
|
+
return decoded;
|
|
130
|
+
}
|
|
131
|
+
__name(decodeFormatToken, "decodeFormatToken");
|
|
132
|
+
function splitFormattedDateSegments(segments) {
|
|
133
|
+
if (segments[0] !== "date") return null;
|
|
134
|
+
if (segments[1] !== "format") return { baseSegments: segments };
|
|
135
|
+
if (segments.length < 4) return null;
|
|
136
|
+
const format = decodeFormatToken(segments[2]);
|
|
137
|
+
if (!format) return null;
|
|
138
|
+
return { baseSegments: ["date", ...segments.slice(3)], format };
|
|
139
|
+
}
|
|
140
|
+
__name(splitFormattedDateSegments, "splitFormattedDateSegments");
|
|
141
|
+
function isCtxDatePathPrefix(pathSegments) {
|
|
142
|
+
const segments = withDatePrefix((pathSegments || []).map((seg) => String(seg)));
|
|
143
|
+
if (segments[0] !== "date") return false;
|
|
144
|
+
if (segments.length === 1) return true;
|
|
145
|
+
if (segments[1] !== "format") return isBaseCtxDatePathPrefix(segments);
|
|
146
|
+
if (segments.length === 2) return true;
|
|
147
|
+
if (segments.length === 3) return typeof decodeFormatToken(segments[2]) === "string";
|
|
148
|
+
const formatted = splitFormattedDateSegments(segments);
|
|
149
|
+
return formatted ? isBaseCtxDatePathPrefix(formatted.baseSegments) : false;
|
|
150
|
+
}
|
|
120
151
|
__name(isCtxDatePathPrefix, "isCtxDatePathPrefix");
|
|
121
152
|
function withDatePrefix(pathSegments) {
|
|
122
153
|
if (pathSegments[0] === "date") {
|
|
@@ -225,26 +256,31 @@ __name(isCtxDateExpression, "isCtxDateExpression");
|
|
|
225
256
|
function isCompleteCtxDatePath(pathSegments) {
|
|
226
257
|
if (!isCtxDatePathPrefix(pathSegments)) return false;
|
|
227
258
|
const segments = withDatePrefix((pathSegments || []).map((seg) => String(seg)));
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
259
|
+
const formatted = splitFormattedDateSegments(segments);
|
|
260
|
+
if (!formatted) return false;
|
|
261
|
+
const baseSegments = formatted.baseSegments;
|
|
262
|
+
if (baseSegments[1] === "preset") {
|
|
263
|
+
return baseSegments.length === 3 && PRESET_KEYS.has(baseSegments[2]);
|
|
231
264
|
}
|
|
232
|
-
if (
|
|
233
|
-
if (
|
|
234
|
-
return RELATIVE_DIRECTIONS.has(
|
|
265
|
+
if (baseSegments[1] === "relative") {
|
|
266
|
+
if (baseSegments.length !== 5) return false;
|
|
267
|
+
return RELATIVE_DIRECTIONS.has(baseSegments[2]) && RELATIVE_UNITS.has(baseSegments[3]) && typeof parseNumberToken(baseSegments[4]) === "number";
|
|
235
268
|
}
|
|
236
|
-
if (
|
|
237
|
-
return
|
|
269
|
+
if (baseSegments[1] === "exact" && baseSegments[2] === "single" && baseSegments[3] === "date") {
|
|
270
|
+
return baseSegments.length === 5 && /^v.+/.test(baseSegments[4]);
|
|
238
271
|
}
|
|
239
|
-
if (
|
|
240
|
-
return
|
|
272
|
+
if (baseSegments[1] === "exact" && baseSegments[2] === "range" && baseSegments[3] === "date") {
|
|
273
|
+
return baseSegments.length === 6 && /^v.+/.test(baseSegments[4]) && /^v.+/.test(baseSegments[5]);
|
|
241
274
|
}
|
|
242
275
|
return false;
|
|
243
276
|
}
|
|
244
277
|
__name(isCompleteCtxDatePath, "isCompleteCtxDatePath");
|
|
245
278
|
function parseCtxDateExpression(value) {
|
|
246
279
|
if (!isCtxDateExpression(value)) return void 0;
|
|
247
|
-
const
|
|
280
|
+
const rawSegments = withDatePrefix(parseCtxDateSegments(value) || []);
|
|
281
|
+
const formatted = splitFormattedDateSegments(rawSegments);
|
|
282
|
+
if (!formatted) return void 0;
|
|
283
|
+
const segments = formatted.baseSegments;
|
|
248
284
|
if (segments[1] === "preset" && segments.length === 3 && PRESET_KEYS.has(segments[2])) {
|
|
249
285
|
return { type: segments[2] };
|
|
250
286
|
}
|
|
@@ -272,6 +308,60 @@ function parseCtxDateExpression(value) {
|
|
|
272
308
|
return void 0;
|
|
273
309
|
}
|
|
274
310
|
__name(parseCtxDateExpression, "parseCtxDateExpression");
|
|
311
|
+
function parseCtxDateExpressionConfig(value) {
|
|
312
|
+
if (!isCtxDateExpression(value)) return void 0;
|
|
313
|
+
const segments = withDatePrefix(parseCtxDateSegments(value) || []);
|
|
314
|
+
const formatted = splitFormattedDateSegments(segments);
|
|
315
|
+
if (!formatted) return void 0;
|
|
316
|
+
const parsed = parseCtxDateExpression(value);
|
|
317
|
+
const formatConfig = formatted.format ? { format: formatted.format } : {};
|
|
318
|
+
if (typeof parsed === "string") {
|
|
319
|
+
return { kind: "exact", value: parsed, ...formatConfig };
|
|
320
|
+
}
|
|
321
|
+
if (Array.isArray(parsed) && parsed.length === 2 && typeof parsed[0] === "string" && typeof parsed[1] === "string") {
|
|
322
|
+
return { kind: "exact", value: [parsed[0], parsed[1]], ...formatConfig };
|
|
323
|
+
}
|
|
324
|
+
if (!parsed || typeof parsed !== "object") return void 0;
|
|
325
|
+
const typed = parsed;
|
|
326
|
+
if (typed.type === "past" || typed.type === "next") {
|
|
327
|
+
if (typeof typed.unit !== "string" || !RELATIVE_UNITS.has(typed.unit) || typeof typed.number !== "number") {
|
|
328
|
+
return void 0;
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
kind: "relative",
|
|
332
|
+
direction: typed.type,
|
|
333
|
+
amount: typed.number,
|
|
334
|
+
unit: typed.unit,
|
|
335
|
+
...formatConfig
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if (typeof typed.type === "string" && PRESET_KEYS.has(typed.type)) {
|
|
339
|
+
return { kind: "preset", preset: typed.type, ...formatConfig };
|
|
340
|
+
}
|
|
341
|
+
return void 0;
|
|
342
|
+
}
|
|
343
|
+
__name(parseCtxDateExpressionConfig, "parseCtxDateExpressionConfig");
|
|
344
|
+
function serializeCtxDateExpressionConfig(config) {
|
|
345
|
+
let legacyValue;
|
|
346
|
+
if (config.kind === "preset") {
|
|
347
|
+
if (!PRESET_KEYS.has(config.preset)) return void 0;
|
|
348
|
+
legacyValue = { type: config.preset };
|
|
349
|
+
} else if (config.kind === "relative") {
|
|
350
|
+
if (!RELATIVE_DIRECTIONS.has(config.direction) || !RELATIVE_UNITS.has(config.unit)) return void 0;
|
|
351
|
+
const amount = Math.floor(Number(config.amount));
|
|
352
|
+
if (!Number.isFinite(amount) || amount <= 0) return void 0;
|
|
353
|
+
legacyValue = { type: config.direction, unit: config.unit, number: amount };
|
|
354
|
+
} else {
|
|
355
|
+
legacyValue = config.value;
|
|
356
|
+
}
|
|
357
|
+
const expression = serializeCtxDateValue(legacyValue);
|
|
358
|
+
if (!expression || !config.format) return expression;
|
|
359
|
+
const format = String(config.format);
|
|
360
|
+
if (!format.trim() || format.length > MAX_DATE_FORMAT_LENGTH) return void 0;
|
|
361
|
+
const segments = withDatePrefix(parseCtxDateSegments(expression) || []);
|
|
362
|
+
return toCtxDateExpression(["date", "format", `v${encodeBase64Url(format)}`, ...segments.slice(1)]);
|
|
363
|
+
}
|
|
364
|
+
__name(serializeCtxDateExpressionConfig, "serializeCtxDateExpressionConfig");
|
|
275
365
|
function serializeCtxDateValue(value) {
|
|
276
366
|
if (isCtxDateExpression(value)) {
|
|
277
367
|
return String(value).trim();
|
|
@@ -317,8 +407,23 @@ function serializeCtxDateValue(value) {
|
|
|
317
407
|
return void 0;
|
|
318
408
|
}
|
|
319
409
|
__name(serializeCtxDateValue, "serializeCtxDateValue");
|
|
410
|
+
function formatResolvedDateValue(value, format) {
|
|
411
|
+
const formatValue = /* @__PURE__ */ __name((item) => {
|
|
412
|
+
if (typeof item !== "string") return item;
|
|
413
|
+
const parsed = (0, import_dayjs.default)(item);
|
|
414
|
+
return parsed.isValid() ? parsed.format(format) : item;
|
|
415
|
+
}, "formatValue");
|
|
416
|
+
return Array.isArray(value) ? value.map(formatValue) : formatValue(value);
|
|
417
|
+
}
|
|
418
|
+
__name(formatResolvedDateValue, "formatResolvedDateValue");
|
|
320
419
|
function resolveCtxDatePath(pathSegments) {
|
|
321
|
-
const
|
|
420
|
+
const rawSegments = withDatePrefix((pathSegments || []).map((seg) => String(seg)));
|
|
421
|
+
const formatted = splitFormattedDateSegments(rawSegments);
|
|
422
|
+
if (!formatted) return void 0;
|
|
423
|
+
if (formatted.format) {
|
|
424
|
+
return formatResolvedDateValue(resolveCtxDatePath(formatted.baseSegments), formatted.format);
|
|
425
|
+
}
|
|
426
|
+
const segments = formatted.baseSegments;
|
|
322
427
|
if (segments[0] !== "date") return void 0;
|
|
323
428
|
if (segments[1] === "preset" && segments.length === 3) {
|
|
324
429
|
const key = segments[2];
|
|
@@ -375,6 +480,8 @@ __name(resolveCtxDatePath, "resolveCtxDatePath");
|
|
|
375
480
|
isCtxDateExpression,
|
|
376
481
|
isCtxDatePathPrefix,
|
|
377
482
|
parseCtxDateExpression,
|
|
483
|
+
parseCtxDateExpressionConfig,
|
|
378
484
|
resolveCtxDatePath,
|
|
485
|
+
serializeCtxDateExpressionConfig,
|
|
379
486
|
serializeCtxDateValue
|
|
380
487
|
});
|
|
@@ -8,4 +8,5 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { FlowContext } from '../flowContext';
|
|
10
10
|
export declare const SKIP_DATA_SOURCE_DIRTY = "__nocobaseSkipDataSourceDirty";
|
|
11
|
+
export declare const PREPARE_CONTEXT_RESOURCE_ACTION_PARAMS: unique symbol;
|
|
11
12
|
export declare function getDirtyAwareApiClient(value: unknown, context: FlowContext): unknown;
|