@nocobase/flow-engine 2.2.0-beta.1 → 2.2.0-beta.11

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 (85) hide show
  1. package/lib/JSRunner.d.ts +1 -0
  2. package/lib/JSRunner.js +110 -20
  3. package/lib/components/FieldModelRenderer.js +44 -31
  4. package/lib/components/MobilePopup.js +28 -10
  5. package/lib/components/MobilePopup.style.js +27 -6
  6. package/lib/components/dnd/index.js +9 -2
  7. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +86 -32
  8. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +20 -0
  9. package/lib/flowContext.d.ts +1 -1
  10. package/lib/flowContext.js +97 -42
  11. package/lib/flowEngine.js +6 -0
  12. package/lib/flowSettings.d.ts +5 -1
  13. package/lib/flowSettings.js +70 -0
  14. package/lib/locale/en-US.json +1 -0
  15. package/lib/locale/index.d.ts +2 -0
  16. package/lib/locale/zh-CN.json +1 -0
  17. package/lib/resources/apiResource.js +2 -1
  18. package/lib/resources/baseRecordResource.js +6 -17
  19. package/lib/resources/multiRecordResource.js +13 -3
  20. package/lib/resources/singleRecordResource.js +7 -2
  21. package/lib/runjs-context/helpers.js +12 -5
  22. package/lib/types.d.ts +12 -0
  23. package/lib/utils/dataSourceDirty.d.ts +20 -0
  24. package/lib/utils/dataSourceDirty.js +139 -0
  25. package/lib/utils/dirtyAwareApiClient.d.ts +11 -0
  26. package/lib/utils/dirtyAwareApiClient.js +632 -0
  27. package/lib/utils/index.d.ts +1 -1
  28. package/lib/utils/index.js +11 -11
  29. package/lib/utils/loadedPageCache.d.ts +1 -0
  30. package/lib/utils/loadedPageCache.js +6 -0
  31. package/lib/utils/openViewRouteState.d.ts +28 -0
  32. package/lib/utils/openViewRouteState.js +125 -0
  33. package/lib/utils/parsePathnameToViewParams.d.ts +3 -0
  34. package/lib/utils/parsePathnameToViewParams.js +18 -1
  35. package/lib/utils/resolveRunJSObjectValues.js +3 -2
  36. package/lib/utils/runjsModuleLoader.js +0 -30
  37. package/lib/views/ViewNavigation.js +5 -0
  38. package/package.json +4 -4
  39. package/src/JSRunner.ts +112 -25
  40. package/src/__tests__/JSRunner.test.ts +4 -5
  41. package/src/__tests__/flowContext.test.ts +154 -0
  42. package/src/__tests__/flowEngine.dataSourceDirty.test.ts +51 -0
  43. package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
  44. package/src/__tests__/flowSettings.test.ts +72 -0
  45. package/src/__tests__/runjsRuntimeFeatures.test.ts +15 -2
  46. package/src/__tests__/viewScopedFlowEngine.test.ts +72 -6
  47. package/src/components/FieldModelRenderer.tsx +50 -36
  48. package/src/components/MobilePopup.style.ts +34 -7
  49. package/src/components/MobilePopup.tsx +30 -10
  50. package/src/components/__tests__/FieldModelRenderer.test.tsx +165 -0
  51. package/src/components/__tests__/MobilePopup.style.test.tsx +103 -0
  52. package/src/components/__tests__/MobilePopup.test.tsx +109 -0
  53. package/src/components/dnd/index.tsx +11 -2
  54. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +105 -35
  55. package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +381 -12
  56. package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +28 -0
  57. package/src/flowContext.ts +104 -36
  58. package/src/flowEngine.ts +6 -0
  59. package/src/flowSettings.ts +85 -1
  60. package/src/locale/en-US.json +1 -0
  61. package/src/locale/zh-CN.json +1 -0
  62. package/src/resources/apiResource.ts +2 -1
  63. package/src/resources/baseRecordResource.ts +6 -23
  64. package/src/resources/multiRecordResource.ts +13 -3
  65. package/src/resources/singleRecordResource.ts +6 -1
  66. package/src/runjs-context/helpers.ts +12 -6
  67. package/src/types.ts +14 -0
  68. package/src/utils/__tests__/dirtyAwareApiClient.test.ts +713 -0
  69. package/src/utils/__tests__/openViewRouteState.test.ts +40 -0
  70. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +36 -0
  71. package/src/utils/dataSourceDirty.ts +126 -0
  72. package/src/utils/dirtyAwareApiClient.ts +742 -0
  73. package/src/utils/index.ts +10 -9
  74. package/src/utils/loadedPageCache.ts +7 -0
  75. package/src/utils/openViewRouteState.ts +107 -0
  76. package/src/utils/parsePathnameToViewParams.ts +23 -1
  77. package/src/utils/resolveRunJSObjectValues.ts +5 -2
  78. package/src/utils/runjsModuleLoader.ts +0 -32
  79. package/src/views/ViewNavigation.ts +6 -1
  80. package/src/views/__tests__/ViewNavigation.test.ts +15 -0
  81. package/lib/utils/safeGlobals.d.ts +0 -28
  82. package/lib/utils/safeGlobals.js +0 -367
  83. package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +0 -38
  84. package/src/utils/__tests__/safeGlobals.test.ts +0 -106
  85. package/src/utils/safeGlobals.ts +0 -406
@@ -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;