@nocobase/flow-engine 2.0.51 → 2.0.53
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/flow-registry/DetachedFlowRegistry.d.ts +21 -0
- package/lib/flow-registry/DetachedFlowRegistry.js +80 -0
- package/lib/flow-registry/index.d.ts +1 -0
- package/lib/flow-registry/index.js +3 -1
- package/lib/flowContext.d.ts +1 -0
- package/lib/flowContext.js +12 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +7 -0
- package/lib/views/FlowView.js +11 -1
- package/lib/views/PageComponent.js +8 -6
- package/lib/views/usePage.d.ts +4 -11
- package/lib/views/usePage.js +301 -150
- package/package.json +4 -4
- package/src/__tests__/flowContext.test.ts +17 -0
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +2 -0
- package/src/flow-registry/DetachedFlowRegistry.ts +46 -0
- package/src/flow-registry/__tests__/detachedFlowRegistry.test.ts +47 -0
- package/src/flow-registry/index.ts +1 -0
- package/src/flowContext.ts +10 -0
- package/src/index.ts +2 -0
- package/src/views/FlowView.tsx +11 -1
- package/src/views/PageComponent.tsx +7 -4
- package/src/views/__tests__/FlowView.usePage.test.tsx +243 -3
- package/src/views/usePage.tsx +364 -187
|
@@ -0,0 +1,21 @@
|
|
|
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 { FlowDefinition } from '../FlowDefinition';
|
|
10
|
+
import { FlowDefinitionOptions } from '../types';
|
|
11
|
+
import { BaseFlowRegistry, IFlowRepository } from './BaseFlowRegistry';
|
|
12
|
+
export type FlowRegistryData = Record<string, Omit<FlowDefinitionOptions, 'key'> & {
|
|
13
|
+
key?: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare class DetachedFlowRegistry extends BaseFlowRegistry {
|
|
16
|
+
constructor(flows?: FlowRegistryData);
|
|
17
|
+
saveFlow(_flow: FlowDefinition): void;
|
|
18
|
+
destroyFlow(flowKey: string): void;
|
|
19
|
+
}
|
|
20
|
+
export declare function serializeFlowRegistry(registry: Pick<IFlowRepository, 'getFlows'>): FlowRegistryData;
|
|
21
|
+
export declare function replaceFlowRegistry(registry: Pick<IFlowRepository, 'getFlows' | 'removeFlow' | 'addFlows'>, flows: FlowRegistryData): void;
|
|
@@ -0,0 +1,80 @@
|
|
|
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 __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var DetachedFlowRegistry_exports = {};
|
|
39
|
+
__export(DetachedFlowRegistry_exports, {
|
|
40
|
+
DetachedFlowRegistry: () => DetachedFlowRegistry,
|
|
41
|
+
replaceFlowRegistry: () => replaceFlowRegistry,
|
|
42
|
+
serializeFlowRegistry: () => serializeFlowRegistry
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(DetachedFlowRegistry_exports);
|
|
45
|
+
var import_lodash = __toESM(require("lodash"));
|
|
46
|
+
var import_BaseFlowRegistry = require("./BaseFlowRegistry");
|
|
47
|
+
const _DetachedFlowRegistry = class _DetachedFlowRegistry extends import_BaseFlowRegistry.BaseFlowRegistry {
|
|
48
|
+
constructor(flows = {}) {
|
|
49
|
+
super();
|
|
50
|
+
this.addFlows(import_lodash.default.cloneDeep(flows));
|
|
51
|
+
}
|
|
52
|
+
saveFlow(_flow) {
|
|
53
|
+
}
|
|
54
|
+
destroyFlow(flowKey) {
|
|
55
|
+
this.removeFlow(flowKey);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
__name(_DetachedFlowRegistry, "DetachedFlowRegistry");
|
|
59
|
+
let DetachedFlowRegistry = _DetachedFlowRegistry;
|
|
60
|
+
function serializeFlowRegistry(registry) {
|
|
61
|
+
const flows = {};
|
|
62
|
+
for (const [key, flow] of registry.getFlows()) {
|
|
63
|
+
flows[key] = import_lodash.default.cloneDeep(flow.toData());
|
|
64
|
+
}
|
|
65
|
+
return flows;
|
|
66
|
+
}
|
|
67
|
+
__name(serializeFlowRegistry, "serializeFlowRegistry");
|
|
68
|
+
function replaceFlowRegistry(registry, flows) {
|
|
69
|
+
for (const key of Array.from(registry.getFlows().keys())) {
|
|
70
|
+
registry.removeFlow(key);
|
|
71
|
+
}
|
|
72
|
+
registry.addFlows(import_lodash.default.cloneDeep(flows));
|
|
73
|
+
}
|
|
74
|
+
__name(replaceFlowRegistry, "replaceFlowRegistry");
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
DetachedFlowRegistry,
|
|
78
|
+
replaceFlowRegistry,
|
|
79
|
+
serializeFlowRegistry
|
|
80
|
+
});
|
|
@@ -26,9 +26,11 @@ module.exports = __toCommonJS(flow_registry_exports);
|
|
|
26
26
|
__reExport(flow_registry_exports, require("./BaseFlowRegistry"), module.exports);
|
|
27
27
|
__reExport(flow_registry_exports, require("./InstanceFlowRegistry"), module.exports);
|
|
28
28
|
__reExport(flow_registry_exports, require("./GlobalFlowRegistry"), module.exports);
|
|
29
|
+
__reExport(flow_registry_exports, require("./DetachedFlowRegistry"), module.exports);
|
|
29
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
31
|
0 && (module.exports = {
|
|
31
32
|
...require("./BaseFlowRegistry"),
|
|
32
33
|
...require("./InstanceFlowRegistry"),
|
|
33
|
-
...require("./GlobalFlowRegistry")
|
|
34
|
+
...require("./GlobalFlowRegistry"),
|
|
35
|
+
...require("./DetachedFlowRegistry")
|
|
34
36
|
});
|
package/lib/flowContext.d.ts
CHANGED
|
@@ -347,6 +347,7 @@ declare class BaseFlowEngineContext extends FlowContext {
|
|
|
347
347
|
runAction: (actionName: string, params?: Record<string, any>) => Promise<any> | any;
|
|
348
348
|
engine: FlowEngine;
|
|
349
349
|
api: APIClient;
|
|
350
|
+
locale: string;
|
|
350
351
|
viewer: FlowViewer;
|
|
351
352
|
view: FlowView;
|
|
352
353
|
modal: HookAPI;
|
package/lib/flowContext.js
CHANGED
|
@@ -2307,6 +2307,18 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
2307
2307
|
this.defineMethod("t", (keyOrTemplate, options) => {
|
|
2308
2308
|
return i18n.translate(keyOrTemplate, options);
|
|
2309
2309
|
});
|
|
2310
|
+
this.defineProperty("locale", {
|
|
2311
|
+
get: /* @__PURE__ */ __name(() => {
|
|
2312
|
+
var _a, _b, _c;
|
|
2313
|
+
return ((_b = (_a = this.api) == null ? void 0 : _a.auth) == null ? void 0 : _b.locale) || ((_c = this.i18n) == null ? void 0 : _c.language);
|
|
2314
|
+
}, "get"),
|
|
2315
|
+
cache: false,
|
|
2316
|
+
meta: Object.assign(() => ({ type: "string", title: this.t("Current language"), sort: 970 }), {
|
|
2317
|
+
title: (0, import_utils.escapeT)("Current language"),
|
|
2318
|
+
sort: 970,
|
|
2319
|
+
hasChildren: false
|
|
2320
|
+
})
|
|
2321
|
+
});
|
|
2310
2322
|
this.defineMethod("renderJson", function(template) {
|
|
2311
2323
|
return this.resolveJsonTemplate(template);
|
|
2312
2324
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -34,5 +34,7 @@ export { getSnippetBody, listSnippetsForContext, registerRunJSSnippet } from './
|
|
|
34
34
|
export * from './views';
|
|
35
35
|
export { DATA_SOURCE_DIRTY_EVENT, ENGINE_SCOPE_KEY, getEmitterViewActivatedVersion, VIEW_ACTIVATED_EVENT, VIEW_ACTIVATED_VERSION, VIEW_ENGINE_SCOPE, } from './views/viewEvents';
|
|
36
36
|
export * from './FlowDefinition';
|
|
37
|
+
export { DetachedFlowRegistry, replaceFlowRegistry, serializeFlowRegistry } from './flow-registry';
|
|
38
|
+
export type { FlowRegistryData } from './flow-registry';
|
|
37
39
|
export { createViewScopedEngine } from './ViewScopedFlowEngine';
|
|
38
40
|
export { createBlockScopedEngine } from './BlockScopedFlowEngine';
|
package/lib/index.js
CHANGED
|
@@ -28,6 +28,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
28
28
|
var src_exports = {};
|
|
29
29
|
__export(src_exports, {
|
|
30
30
|
DATA_SOURCE_DIRTY_EVENT: () => import_viewEvents.DATA_SOURCE_DIRTY_EVENT,
|
|
31
|
+
DetachedFlowRegistry: () => import_flow_registry.DetachedFlowRegistry,
|
|
31
32
|
ENGINE_SCOPE_KEY: () => import_viewEvents.ENGINE_SCOPE_KEY,
|
|
32
33
|
RunJSContextRegistry: () => import_registry.RunJSContextRegistry,
|
|
33
34
|
VIEW_ACTIVATED_EVENT: () => import_viewEvents.VIEW_ACTIVATED_EVENT,
|
|
@@ -47,6 +48,8 @@ __export(src_exports, {
|
|
|
47
48
|
registerRunJSContextContribution: () => import_contributions.registerRunJSContextContribution,
|
|
48
49
|
registerRunJSLib: () => import_runjsLibs.registerRunJSLib,
|
|
49
50
|
registerRunJSSnippet: () => import_snippets.registerRunJSSnippet,
|
|
51
|
+
replaceFlowRegistry: () => import_flow_registry.replaceFlowRegistry,
|
|
52
|
+
serializeFlowRegistry: () => import_flow_registry.serializeFlowRegistry,
|
|
50
53
|
setupRunJSContexts: () => import_setup.setupRunJSContexts
|
|
51
54
|
});
|
|
52
55
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -75,11 +78,13 @@ var import_snippets = require("./runjs-context/snippets");
|
|
|
75
78
|
__reExport(src_exports, require("./views"), module.exports);
|
|
76
79
|
var import_viewEvents = require("./views/viewEvents");
|
|
77
80
|
__reExport(src_exports, require("./FlowDefinition"), module.exports);
|
|
81
|
+
var import_flow_registry = require("./flow-registry");
|
|
78
82
|
var import_ViewScopedFlowEngine = require("./ViewScopedFlowEngine");
|
|
79
83
|
var import_BlockScopedFlowEngine = require("./BlockScopedFlowEngine");
|
|
80
84
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
85
|
0 && (module.exports = {
|
|
82
86
|
DATA_SOURCE_DIRTY_EVENT,
|
|
87
|
+
DetachedFlowRegistry,
|
|
83
88
|
ENGINE_SCOPE_KEY,
|
|
84
89
|
RunJSContextRegistry,
|
|
85
90
|
VIEW_ACTIVATED_EVENT,
|
|
@@ -99,6 +104,8 @@ var import_BlockScopedFlowEngine = require("./BlockScopedFlowEngine");
|
|
|
99
104
|
registerRunJSContextContribution,
|
|
100
105
|
registerRunJSLib,
|
|
101
106
|
registerRunJSSnippet,
|
|
107
|
+
replaceFlowRegistry,
|
|
108
|
+
serializeFlowRegistry,
|
|
102
109
|
setupRunJSContexts,
|
|
103
110
|
...require("./types"),
|
|
104
111
|
...require("./utils"),
|
package/lib/views/FlowView.js
CHANGED
|
@@ -47,11 +47,21 @@ const _FlowViewer = class _FlowViewer {
|
|
|
47
47
|
if (this.types[type]) {
|
|
48
48
|
zIndex += 1;
|
|
49
49
|
const onClose = others.onClose;
|
|
50
|
+
let zIndexReleased = false;
|
|
51
|
+
const releaseZIndex = /* @__PURE__ */ __name(() => {
|
|
52
|
+
if (!zIndexReleased) {
|
|
53
|
+
zIndexReleased = true;
|
|
54
|
+
zIndex -= 1;
|
|
55
|
+
}
|
|
56
|
+
}, "releaseZIndex");
|
|
50
57
|
const _zIndex = others.zIndex;
|
|
51
58
|
others.onClose = (...args) => {
|
|
52
59
|
onClose == null ? void 0 : onClose(...args);
|
|
53
|
-
|
|
60
|
+
releaseZIndex();
|
|
54
61
|
};
|
|
62
|
+
if (type === "embed") {
|
|
63
|
+
others.onOpenCancelled = releaseZIndex;
|
|
64
|
+
}
|
|
55
65
|
if (type !== "embed") {
|
|
56
66
|
others.zIndex = _zIndex ?? this.getNextZIndex();
|
|
57
67
|
}
|
|
@@ -55,8 +55,9 @@ const PageComponent = (0, import_react.forwardRef)((props, ref) => {
|
|
|
55
55
|
hidden,
|
|
56
56
|
title: _title,
|
|
57
57
|
styles = {},
|
|
58
|
-
zIndex = 4
|
|
58
|
+
zIndex = 4,
|
|
59
59
|
// 这个默认值是为了防止表格的阴影显示到子页面上面
|
|
60
|
+
onClose
|
|
60
61
|
} = mergedProps;
|
|
61
62
|
const closedRef = (0, import_react.useRef)(false);
|
|
62
63
|
const flowEngine = (0, import_provider.useFlowEngine)();
|
|
@@ -114,11 +115,12 @@ const PageComponent = (0, import_react.forwardRef)((props, ref) => {
|
|
|
114
115
|
type: "text",
|
|
115
116
|
size: "small",
|
|
116
117
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons.CloseOutlined, null),
|
|
117
|
-
onClick: () => {
|
|
118
|
-
var _a;
|
|
118
|
+
onClick: async () => {
|
|
119
119
|
if (!closedRef.current) {
|
|
120
|
-
|
|
121
|
-
(
|
|
120
|
+
const closed = await (onClose == null ? void 0 : onClose());
|
|
121
|
+
if (closed !== false) {
|
|
122
|
+
closedRef.current = true;
|
|
123
|
+
}
|
|
122
124
|
}
|
|
123
125
|
},
|
|
124
126
|
style: {
|
|
@@ -138,7 +140,7 @@ const PageComponent = (0, import_react.forwardRef)((props, ref) => {
|
|
|
138
140
|
)),
|
|
139
141
|
extra && /* @__PURE__ */ import_react.default.createElement("div", null, extra)
|
|
140
142
|
);
|
|
141
|
-
}, [header, _title, flowEngine.context.themeToken, styles.header,
|
|
143
|
+
}, [header, _title, flowEngine.context.themeToken, styles.header, onClose]);
|
|
142
144
|
const FooterComponent = (0, import_react.useMemo)(() => {
|
|
143
145
|
if (!footer) return null;
|
|
144
146
|
const token = flowEngine.context.themeToken;
|
package/lib/views/usePage.d.ts
CHANGED
|
@@ -12,27 +12,20 @@ export declare const GLOBAL_EMBED_CONTAINER_ID = "nocobase-embed-container";
|
|
|
12
12
|
/** Dataset key used to signal embed replacement in progress (skip style reset on close) */
|
|
13
13
|
export declare const EMBED_REPLACING_DATA_KEY = "nocobaseEmbedReplacing";
|
|
14
14
|
export declare function usePage(): (React.JSX.Element | {
|
|
15
|
-
open: (config: any, flowContext: any) => Promise<
|
|
15
|
+
open: (config: any, flowContext: any) => Promise<any> & {
|
|
16
16
|
type: "embed";
|
|
17
17
|
inputArgs: any;
|
|
18
18
|
preventClose: boolean;
|
|
19
|
+
Header: any;
|
|
20
|
+
Footer: any;
|
|
19
21
|
beforeClose: any;
|
|
22
|
+
close: (result?: any, force?: boolean) => Promise<any>;
|
|
20
23
|
destroy: (result?: any) => void;
|
|
21
24
|
update: (newConfig: any) => void;
|
|
22
|
-
close: (result?: any, force?: boolean) => Promise<boolean>;
|
|
23
|
-
Header: React.FC<{
|
|
24
|
-
title?: React.ReactNode;
|
|
25
|
-
extra?: React.ReactNode;
|
|
26
|
-
}>;
|
|
27
|
-
Footer: React.FC<{
|
|
28
|
-
children?: React.ReactNode;
|
|
29
|
-
}>;
|
|
30
25
|
setFooter: (footer: React.ReactNode) => void;
|
|
31
26
|
setHeader: (header: {
|
|
32
27
|
title?: React.ReactNode;
|
|
33
28
|
extra?: React.ReactNode;
|
|
34
29
|
}) => void;
|
|
35
|
-
navigation: any;
|
|
36
|
-
readonly record: unknown;
|
|
37
30
|
};
|
|
38
31
|
})[];
|