@nocobase/flow-engine 2.2.0-alpha.1 → 2.2.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/lib/JSRunner.d.ts +1 -0
  2. package/lib/JSRunner.js +110 -20
  3. package/lib/acl/Acl.d.ts +2 -1
  4. package/lib/acl/Acl.js +28 -0
  5. package/lib/components/FieldModelRenderer.js +44 -31
  6. package/lib/components/FlowContextSelector.js +55 -12
  7. package/lib/components/FormItem.js +11 -7
  8. package/lib/components/MobilePopup.js +39 -10
  9. package/lib/components/MobilePopup.style.js +27 -6
  10. package/lib/components/dnd/index.js +9 -2
  11. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +86 -32
  12. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +20 -0
  13. package/lib/components/subModel/LazyDropdown.js +41 -26
  14. package/lib/components/variables/VariableHybridInput.d.ts +9 -0
  15. package/lib/components/variables/VariableHybridInput.js +146 -17
  16. package/lib/components/variables/VariableInput.js +19 -7
  17. package/lib/components/variables/VariableTag.js +48 -36
  18. package/lib/components/variables/types.d.ts +21 -0
  19. package/lib/flowContext.d.ts +1 -1
  20. package/lib/flowContext.js +97 -42
  21. package/lib/flowEngine.js +6 -0
  22. package/lib/flowI18n.js +3 -3
  23. package/lib/flowSettings.d.ts +5 -1
  24. package/lib/flowSettings.js +70 -0
  25. package/lib/locale/en-US.json +3 -0
  26. package/lib/locale/index.d.ts +6 -0
  27. package/lib/locale/zh-CN.json +3 -0
  28. package/lib/resources/apiResource.js +2 -1
  29. package/lib/resources/baseRecordResource.js +6 -17
  30. package/lib/resources/multiRecordResource.js +13 -3
  31. package/lib/resources/singleRecordResource.js +7 -2
  32. package/lib/runjs-context/helpers.js +12 -5
  33. package/lib/types.d.ts +15 -1
  34. package/lib/types.js +1 -0
  35. package/lib/utils/dataSourceDirty.d.ts +20 -0
  36. package/lib/utils/dataSourceDirty.js +139 -0
  37. package/lib/utils/dirtyAwareApiClient.d.ts +11 -0
  38. package/lib/utils/dirtyAwareApiClient.js +632 -0
  39. package/lib/utils/index.d.ts +1 -1
  40. package/lib/utils/index.js +11 -11
  41. package/lib/utils/loadedPageCache.d.ts +1 -0
  42. package/lib/utils/loadedPageCache.js +6 -0
  43. package/lib/utils/openViewRouteState.d.ts +28 -0
  44. package/lib/utils/openViewRouteState.js +125 -0
  45. package/lib/utils/parsePathnameToViewParams.d.ts +3 -0
  46. package/lib/utils/parsePathnameToViewParams.js +18 -1
  47. package/lib/utils/resolveRunJSObjectValues.js +3 -2
  48. package/lib/utils/runjsModuleLoader.js +0 -30
  49. package/lib/views/ViewNavigation.js +5 -0
  50. package/package.json +4 -4
  51. package/src/JSRunner.ts +112 -25
  52. package/src/__tests__/JSRunner.test.ts +4 -5
  53. package/src/__tests__/flowContext.test.ts +154 -0
  54. package/src/__tests__/flowEngine.dataSourceDirty.test.ts +51 -0
  55. package/src/__tests__/flowI18n.test.ts +11 -0
  56. package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
  57. package/src/__tests__/flowSettings.test.ts +72 -0
  58. package/src/__tests__/runjsRuntimeFeatures.test.ts +15 -2
  59. package/src/__tests__/viewScopedFlowEngine.test.ts +72 -6
  60. package/src/acl/Acl.tsx +36 -1
  61. package/src/acl/__tests__/Acl.test.tsx +70 -0
  62. package/src/components/FieldModelRenderer.tsx +50 -36
  63. package/src/components/FlowContextSelector.tsx +66 -11
  64. package/src/components/FormItem.tsx +12 -7
  65. package/src/components/MobilePopup.style.ts +34 -7
  66. package/src/components/MobilePopup.tsx +42 -10
  67. package/src/components/__tests__/FieldModelRenderer.test.tsx +165 -0
  68. package/src/components/__tests__/FormItem.test.tsx +17 -2
  69. package/src/components/__tests__/MobilePopup.style.test.tsx +103 -0
  70. package/src/components/__tests__/MobilePopup.test.tsx +150 -0
  71. package/src/components/dnd/index.tsx +11 -2
  72. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +105 -35
  73. package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +381 -12
  74. package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +28 -0
  75. package/src/components/subModel/LazyDropdown.tsx +44 -26
  76. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +85 -2
  77. package/src/components/variables/VariableHybridInput.tsx +185 -14
  78. package/src/components/variables/VariableInput.tsx +32 -7
  79. package/src/components/variables/VariableTag.tsx +51 -37
  80. package/src/components/variables/__tests__/FlowContextSelector.test.tsx +60 -3
  81. package/src/components/variables/__tests__/VariableHybridInput.test.tsx +212 -0
  82. package/src/components/variables/__tests__/VariableInput.test.tsx +202 -6
  83. package/src/components/variables/__tests__/VariableTag.test.tsx +80 -0
  84. package/src/components/variables/types.ts +21 -0
  85. package/src/flowContext.ts +104 -36
  86. package/src/flowEngine.ts +6 -0
  87. package/src/flowI18n.ts +8 -3
  88. package/src/flowSettings.ts +85 -1
  89. package/src/locale/__tests__/index.test.ts +21 -0
  90. package/src/locale/en-US.json +3 -0
  91. package/src/locale/zh-CN.json +3 -0
  92. package/src/resources/apiResource.ts +2 -1
  93. package/src/resources/baseRecordResource.ts +6 -23
  94. package/src/resources/multiRecordResource.ts +13 -3
  95. package/src/resources/singleRecordResource.ts +6 -1
  96. package/src/runjs-context/helpers.ts +12 -6
  97. package/src/types.ts +16 -0
  98. package/src/utils/__tests__/dirtyAwareApiClient.test.ts +713 -0
  99. package/src/utils/__tests__/openViewRouteState.test.ts +40 -0
  100. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +36 -0
  101. package/src/utils/dataSourceDirty.ts +126 -0
  102. package/src/utils/dirtyAwareApiClient.ts +742 -0
  103. package/src/utils/index.ts +10 -9
  104. package/src/utils/loadedPageCache.ts +7 -0
  105. package/src/utils/openViewRouteState.ts +107 -0
  106. package/src/utils/parsePathnameToViewParams.ts +23 -1
  107. package/src/utils/resolveRunJSObjectValues.ts +5 -2
  108. package/src/utils/runjsModuleLoader.ts +0 -32
  109. package/src/views/ViewNavigation.ts +6 -1
  110. package/src/views/__tests__/ViewNavigation.test.ts +15 -0
  111. package/lib/utils/safeGlobals.d.ts +0 -28
  112. package/lib/utils/safeGlobals.js +0 -367
  113. package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +0 -38
  114. package/src/utils/__tests__/safeGlobals.test.ts +0 -106
  115. package/src/utils/safeGlobals.ts +0 -406
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.
@@ -500,6 +502,18 @@ export interface ToolbarItemConfig {
500
502
  /** 排序权重,数字越小越靠右(先添加的在右边) */
501
503
  sort?: number;
502
504
  }
505
+ export interface DynamicFlowSource {
506
+ key: string;
507
+ label: React.ReactNode;
508
+ model: FlowModel;
509
+ sort?: number;
510
+ }
511
+ export interface DynamicFlowSourceProvider {
512
+ key: string;
513
+ sort?: number;
514
+ visible?: (model: FlowModel) => boolean;
515
+ getSources: (model: FlowModel) => DynamicFlowSource[] | Promise<DynamicFlowSource[]>;
516
+ }
503
517
  export interface ApplyFlowCacheEntry {
504
518
  status: 'pending' | 'resolved' | 'rejected';
505
519
  promise: Promise<any>;
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:
@@ -0,0 +1,20 @@
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 type { FlowEngine } from '../flowEngine';
10
+ type MarkDataSourceDirtyOptions = {
11
+ engine?: FlowEngine;
12
+ dataSourceKey?: unknown;
13
+ resourceName?: unknown;
14
+ includePreviousEngines?: boolean;
15
+ };
16
+ export declare function getHeaderValue(headers: unknown, name: string): unknown;
17
+ export declare function getDataSourceKeyFromHeaders(headers: unknown): string;
18
+ export declare function getAffectedResourceNames(resourceName: unknown): string[];
19
+ export declare function markDataSourceDirty(options: MarkDataSourceDirtyOptions): string[];
20
+ export {};
@@ -0,0 +1,139 @@
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 dataSourceDirty_exports = {};
29
+ __export(dataSourceDirty_exports, {
30
+ getAffectedResourceNames: () => getAffectedResourceNames,
31
+ getDataSourceKeyFromHeaders: () => getDataSourceKeyFromHeaders,
32
+ getHeaderValue: () => getHeaderValue,
33
+ markDataSourceDirty: () => markDataSourceDirty
34
+ });
35
+ module.exports = __toCommonJS(dataSourceDirty_exports);
36
+ var import_viewEvents = require("../views/viewEvents");
37
+ function getHeaderValue(headers, name) {
38
+ if (!headers || typeof headers !== "object") {
39
+ return void 0;
40
+ }
41
+ const maybeHeaders = headers;
42
+ if (typeof maybeHeaders.get === "function") {
43
+ const value = maybeHeaders.get(name);
44
+ if (value != null && value !== "") {
45
+ return value;
46
+ }
47
+ }
48
+ const lowerName = name.toLowerCase();
49
+ for (const [key, value] of Object.entries(headers)) {
50
+ if (key.toLowerCase() === lowerName) {
51
+ return value;
52
+ }
53
+ }
54
+ return void 0;
55
+ }
56
+ __name(getHeaderValue, "getHeaderValue");
57
+ function getDataSourceKeyFromHeaders(headers) {
58
+ const value = getHeaderValue(headers, "x-data-source");
59
+ if (Array.isArray(value)) {
60
+ return String(value[0] || "main");
61
+ }
62
+ return value == null || value === "" ? "main" : String(value);
63
+ }
64
+ __name(getDataSourceKeyFromHeaders, "getDataSourceKeyFromHeaders");
65
+ function getAffectedResourceNames(resourceName) {
66
+ const name = String(resourceName || "").trim();
67
+ if (!name) {
68
+ return [];
69
+ }
70
+ const names = /* @__PURE__ */ new Set([name]);
71
+ if (name.includes(".")) {
72
+ names.add(name.split(".")[0]);
73
+ }
74
+ return Array.from(names);
75
+ }
76
+ __name(getAffectedResourceNames, "getAffectedResourceNames");
77
+ function getDirtyTargetEngines(engine, includePreviousEngines) {
78
+ if (!includePreviousEngines) {
79
+ return [engine];
80
+ }
81
+ const engines = [];
82
+ const seen = /* @__PURE__ */ new Set();
83
+ let current = engine;
84
+ let guard = 0;
85
+ while (current && guard++ < 50) {
86
+ if (!seen.has(current)) {
87
+ engines.push(current);
88
+ seen.add(current);
89
+ }
90
+ current = current.previousEngine;
91
+ }
92
+ return engines;
93
+ }
94
+ __name(getDirtyTargetEngines, "getDirtyTargetEngines");
95
+ function markDataSourceDirty(options) {
96
+ var _a, _b, _c, _d;
97
+ const { engine, resourceName, includePreviousEngines } = options;
98
+ if (!(engine == null ? void 0 : engine.markDataSourceDirty)) {
99
+ return [];
100
+ }
101
+ const resourceNames = getAffectedResourceNames(resourceName);
102
+ if (!resourceNames.length) {
103
+ return [];
104
+ }
105
+ const dataSourceKey = String(options.dataSourceKey || "main");
106
+ const targetEngines = getDirtyTargetEngines(engine, includePreviousEngines);
107
+ const beforeVersions = /* @__PURE__ */ new Map();
108
+ for (const targetEngine of targetEngines) {
109
+ const versions = /* @__PURE__ */ new Map();
110
+ beforeVersions.set(targetEngine, versions);
111
+ for (const name of resourceNames) {
112
+ versions.set(name, ((_a = targetEngine.getDataSourceDirtyVersion) == null ? void 0 : _a.call(targetEngine, dataSourceKey, name)) || 0);
113
+ }
114
+ }
115
+ for (const targetEngine of targetEngines) {
116
+ const versions = beforeVersions.get(targetEngine);
117
+ for (const name of resourceNames) {
118
+ const before = (versions == null ? void 0 : versions.get(name)) || 0;
119
+ const current = ((_b = targetEngine.getDataSourceDirtyVersion) == null ? void 0 : _b.call(targetEngine, dataSourceKey, name)) || 0;
120
+ if (current !== before) {
121
+ continue;
122
+ }
123
+ targetEngine.markDataSourceDirty(dataSourceKey, name);
124
+ }
125
+ }
126
+ (_d = (_c = engine.emitter) == null ? void 0 : _c.emit) == null ? void 0 : _d.call(_c, import_viewEvents.DATA_SOURCE_DIRTY_EVENT, {
127
+ dataSourceKey,
128
+ resourceNames
129
+ });
130
+ return resourceNames;
131
+ }
132
+ __name(markDataSourceDirty, "markDataSourceDirty");
133
+ // Annotate the CommonJS export names for ESM import in node:
134
+ 0 && (module.exports = {
135
+ getAffectedResourceNames,
136
+ getDataSourceKeyFromHeaders,
137
+ getHeaderValue,
138
+ markDataSourceDirty
139
+ });
@@ -0,0 +1,11 @@
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 type { FlowContext } from '../flowContext';
10
+ export declare const SKIP_DATA_SOURCE_DIRTY = "__nocobaseSkipDataSourceDirty";
11
+ export declare function getDirtyAwareApiClient(value: unknown, context: FlowContext): unknown;