@nocobase/flow-engine 2.1.0-beta.22 → 2.1.0-beta.23

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 (45) hide show
  1. package/lib/components/FieldModelRenderer.js +2 -2
  2. package/lib/components/FlowModelRenderer.d.ts +2 -0
  3. package/lib/components/FlowModelRenderer.js +2 -0
  4. package/lib/components/dnd/index.d.ts +19 -1
  5. package/lib/components/dnd/index.js +239 -21
  6. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +20 -1
  7. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +4 -0
  8. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +21 -8
  9. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +2 -0
  10. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +100 -32
  11. package/lib/components/subModel/index.d.ts +1 -0
  12. package/lib/components/subModel/index.js +19 -0
  13. package/lib/components/subModel/utils.d.ts +1 -1
  14. package/lib/data-source/index.d.ts +73 -0
  15. package/lib/data-source/index.js +205 -1
  16. package/lib/flowContext.d.ts +2 -0
  17. package/lib/flowI18n.js +2 -1
  18. package/lib/models/DisplayItemModel.d.ts +1 -1
  19. package/lib/models/EditableItemModel.d.ts +1 -1
  20. package/lib/models/FilterableItemModel.d.ts +1 -1
  21. package/lib/models/flowModel.d.ts +11 -9
  22. package/lib/models/flowModel.js +48 -9
  23. package/lib/provider.js +38 -23
  24. package/package.json +4 -4
  25. package/src/__tests__/provider.test.tsx +24 -2
  26. package/src/components/FieldModelRenderer.tsx +2 -1
  27. package/src/components/FlowModelRenderer.tsx +6 -0
  28. package/src/components/__tests__/dnd.test.ts +44 -0
  29. package/src/components/dnd/index.tsx +286 -26
  30. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +25 -1
  31. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +24 -5
  32. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +94 -3
  33. package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +171 -2
  34. package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +2 -0
  35. package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +112 -32
  36. package/src/components/subModel/index.ts +1 -0
  37. package/src/data-source/__tests__/index.test.ts +34 -1
  38. package/src/data-source/index.ts +252 -2
  39. package/src/flowContext.ts +2 -0
  40. package/src/flowI18n.ts +2 -1
  41. package/src/models/DisplayItemModel.tsx +1 -1
  42. package/src/models/EditableItemModel.tsx +1 -1
  43. package/src/models/FilterableItemModel.tsx +1 -1
  44. package/src/models/flowModel.tsx +85 -23
  45. package/src/provider.tsx +41 -25
@@ -53,12 +53,47 @@ var import_sortCollectionsByInherits = require("./sortCollectionsByInherits");
53
53
  const _DataSourceManager = class _DataSourceManager {
54
54
  dataSources;
55
55
  flowEngine;
56
+ requester;
57
+ collectionFieldInterfaceManager;
58
+ loaders = /* @__PURE__ */ new Map();
59
+ loadedKeys = /* @__PURE__ */ new Set();
60
+ loadingKeys = /* @__PURE__ */ new Set();
61
+ loadErrors = /* @__PURE__ */ new Map();
62
+ loadingPromise = null;
56
63
  constructor() {
57
64
  this.dataSources = import_reactive.observable.shallow(/* @__PURE__ */ new Map());
58
65
  }
59
66
  setFlowEngine(flowEngine) {
60
67
  this.flowEngine = flowEngine;
61
68
  }
69
+ setRequester(requester) {
70
+ this.requester = requester;
71
+ }
72
+ setCollectionFieldInterfaceManager(manager) {
73
+ this.collectionFieldInterfaceManager = manager;
74
+ }
75
+ addFieldInterfaces(fieldInterfaceClasses = []) {
76
+ var _a, _b;
77
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaces) == null ? void 0 : _b.call(_a, fieldInterfaceClasses);
78
+ }
79
+ addFieldInterfaceGroups(groups) {
80
+ var _a, _b;
81
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceGroups) == null ? void 0 : _b.call(_a, groups);
82
+ }
83
+ addFieldInterfaceComponentOption(name, option) {
84
+ var _a, _b;
85
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceComponentOption) == null ? void 0 : _b.call(_a, name, option);
86
+ }
87
+ addFieldInterfaceOperator(name, operator) {
88
+ var _a, _b;
89
+ (_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceOperator) == null ? void 0 : _b.call(_a, name, operator);
90
+ }
91
+ registerLoader(key, loader) {
92
+ this.loaders.set(key, loader);
93
+ }
94
+ removeLoader(key) {
95
+ this.loaders.delete(key);
96
+ }
62
97
  addDataSource(ds) {
63
98
  if (this.dataSources.has(ds.key)) {
64
99
  throw new Error(`DataSource with name ${ds.key} already exists`);
@@ -75,7 +110,7 @@ const _DataSourceManager = class _DataSourceManager {
75
110
  upsertDataSource(ds) {
76
111
  var _a;
77
112
  if (this.dataSources.has(ds.key)) {
78
- (_a = this.dataSources.get(ds.key)) == null ? void 0 : _a.setOptions(ds);
113
+ (_a = this.dataSources.get(ds.key)) == null ? void 0 : _a.patchOptions(ds);
79
114
  } else {
80
115
  this.addDataSource(ds);
81
116
  }
@@ -103,6 +138,144 @@ const _DataSourceManager = class _DataSourceManager {
103
138
  if (!ds) return void 0;
104
139
  return ds.getCollectionField(otherKeys.join("."));
105
140
  }
141
+ async ensureLoaded(options = {}) {
142
+ const { force = false } = options;
143
+ const keys = this.resolveLoadKeys(options.keys);
144
+ const pendingKeys = force ? keys : keys.filter((key) => !this.loadedKeys.has(key));
145
+ if (!pendingKeys.length) {
146
+ return;
147
+ }
148
+ if (this.loadingPromise) {
149
+ return this.loadingPromise;
150
+ }
151
+ this.loadingPromise = (async () => {
152
+ try {
153
+ for (const key of pendingKeys) {
154
+ await this.loadKey(key, { initial: !this.loadedKeys.has(key), force });
155
+ }
156
+ } finally {
157
+ this.loadingPromise = null;
158
+ }
159
+ })();
160
+ return this.loadingPromise;
161
+ }
162
+ async reload(options = {}) {
163
+ const keys = this.resolveLoadKeys(options.keys);
164
+ if (!keys.length) {
165
+ return;
166
+ }
167
+ if (this.loadingPromise) {
168
+ return this.loadingPromise;
169
+ }
170
+ this.loadingPromise = (async () => {
171
+ try {
172
+ for (const key of keys) {
173
+ await this.loadKey(key, { initial: false, force: true });
174
+ }
175
+ } finally {
176
+ this.loadingPromise = null;
177
+ }
178
+ })();
179
+ return this.loadingPromise;
180
+ }
181
+ async reloadDataSource(key) {
182
+ if (this.loadingKeys.has(key) && this.loadingPromise) {
183
+ return this.loadingPromise;
184
+ }
185
+ if (!this.loaders.has(key) && this.loaders.has("*")) {
186
+ return this.reload({ keys: ["*"] });
187
+ }
188
+ return this.reload({ keys: [key] });
189
+ }
190
+ resolveLoadKeys(requestedKeys) {
191
+ const normalizedKeys = (requestedKeys == null ? void 0 : requestedKeys.length) ? requestedKeys : ["main"];
192
+ const explicitKeys = normalizedKeys.filter((key) => this.loaders.has(key));
193
+ if (this.loaders.has("*")) {
194
+ return import_lodash.default.uniq(["*", ...explicitKeys]);
195
+ }
196
+ return explicitKeys.length ? explicitKeys : normalizedKeys;
197
+ }
198
+ getApp() {
199
+ var _a, _b;
200
+ return (_b = (_a = this.flowEngine) == null ? void 0 : _a.context) == null ? void 0 : _b.app;
201
+ }
202
+ dispatchDataSourceEvent(type, detail) {
203
+ var _a, _b;
204
+ (_b = (_a = this.getApp()) == null ? void 0 : _a.eventBus) == null ? void 0 : _b.dispatchEvent(new CustomEvent(type, { detail }));
205
+ }
206
+ setDataSourceState(key, options) {
207
+ const dataSource = this.getDataSource(key);
208
+ if (!dataSource) {
209
+ return;
210
+ }
211
+ dataSource.patchOptions(options);
212
+ }
213
+ applyDataSourceLoadResult(key, result) {
214
+ if (key === "*") {
215
+ const dataSources = (result == null ? void 0 : result.dataSources) || [];
216
+ dataSources.forEach((dataSourceOptions) => {
217
+ var _a;
218
+ const { collections, ...dataSource2 } = dataSourceOptions;
219
+ this.upsertDataSource(dataSource2);
220
+ if (collections) {
221
+ (_a = this.getDataSource(dataSource2.key)) == null ? void 0 : _a.setCollections(collections, { clearFields: true });
222
+ }
223
+ });
224
+ return;
225
+ }
226
+ const dataSource = this.getDataSource(key);
227
+ if (!dataSource) {
228
+ return;
229
+ }
230
+ dataSource.setCollections((result == null ? void 0 : result.collections) || [], { clearFields: true });
231
+ }
232
+ async loadKey(key, options) {
233
+ const loader = this.loaders.get(key);
234
+ if (!loader) {
235
+ return;
236
+ }
237
+ if (!this.getDataSource(key) && key !== "*") {
238
+ this.addDataSource({ key });
239
+ }
240
+ const { initial } = options;
241
+ this.loadingKeys.add(key);
242
+ if (key !== "*") {
243
+ this.setDataSourceState(key, {
244
+ status: initial ? "loading" : "reloading",
245
+ errorMessage: void 0
246
+ });
247
+ }
248
+ this.loadErrors.set(key, null);
249
+ try {
250
+ const result = await loader({ key, manager: this }) || {};
251
+ this.applyDataSourceLoadResult(key, result);
252
+ this.loadedKeys.add(key);
253
+ if (key !== "*") {
254
+ this.setDataSourceState(key, {
255
+ status: "loaded",
256
+ errorMessage: void 0
257
+ });
258
+ }
259
+ this.dispatchDataSourceEvent("dataSource:loaded", { dataSourceKey: key, initial });
260
+ } catch (error) {
261
+ const normalizedError = error instanceof Error ? error : new Error(String(error));
262
+ this.loadErrors.set(key, normalizedError);
263
+ if (key !== "*") {
264
+ this.setDataSourceState(key, {
265
+ status: initial ? "loading-failed" : "reloading-failed",
266
+ errorMessage: normalizedError.message
267
+ });
268
+ }
269
+ this.dispatchDataSourceEvent("dataSource:loadFailed", {
270
+ dataSourceKey: key,
271
+ initial,
272
+ error: normalizedError
273
+ });
274
+ throw normalizedError;
275
+ } finally {
276
+ this.loadingKeys.delete(key);
277
+ }
278
+ }
106
279
  };
107
280
  __name(_DataSourceManager, "DataSourceManager");
108
281
  let DataSourceManager = _DataSourceManager;
@@ -126,6 +299,12 @@ const _DataSource = class _DataSource {
126
299
  get name() {
127
300
  return this.options.key;
128
301
  }
302
+ get status() {
303
+ return this.options.status;
304
+ }
305
+ get errorMessage() {
306
+ return this.options.errorMessage;
307
+ }
129
308
  setDataSourceManager(dataSourceManager) {
130
309
  this.dataSourceManager = dataSourceManager;
131
310
  }
@@ -156,6 +335,9 @@ const _DataSource = class _DataSource {
156
335
  upsertCollections(collections, options = {}) {
157
336
  return this.collectionManager.upsertCollections(collections, options);
158
337
  }
338
+ setCollections(collections, options = {}) {
339
+ return this.collectionManager.setCollections(collections, options);
340
+ }
159
341
  removeCollection(name) {
160
342
  return this.collectionManager.removeCollection(name);
161
343
  }
@@ -166,6 +348,12 @@ const _DataSource = class _DataSource {
166
348
  Object.keys(this.options).forEach((key) => delete this.options[key]);
167
349
  Object.assign(this.options, newOptions);
168
350
  }
351
+ patchOptions(newOptions = {}) {
352
+ Object.assign(this.options, newOptions);
353
+ }
354
+ reload() {
355
+ return this.dataSourceManager.reloadDataSource(this.key);
356
+ }
169
357
  getCollectionField(fieldPath) {
170
358
  const [collectionName, ...otherKeys] = fieldPath.split(".");
171
359
  const fieldName = otherKeys.join(".");
@@ -190,6 +378,10 @@ const _CollectionManager = class _CollectionManager {
190
378
  collections;
191
379
  allCollectionsInheritChain;
192
380
  childrenCollectionsName = {};
381
+ resetCaches() {
382
+ this.childrenCollectionsName = {};
383
+ this.allCollectionsInheritChain = void 0;
384
+ }
193
385
  get flowEngine() {
194
386
  return this.dataSource.flowEngine;
195
387
  }
@@ -203,9 +395,11 @@ const _CollectionManager = class _CollectionManager {
203
395
  col.setDataSource(this.dataSource);
204
396
  col.initInherits();
205
397
  this.collections.set(col.name, col);
398
+ this.resetCaches();
206
399
  }
207
400
  removeCollection(name) {
208
401
  this.collections.delete(name);
402
+ this.resetCaches();
209
403
  }
210
404
  updateCollection(newOptions, options = {}) {
211
405
  const collection = this.getCollection(newOptions.name);
@@ -213,6 +407,7 @@ const _CollectionManager = class _CollectionManager {
213
407
  throw new Error(`Collection ${newOptions.name} not found`);
214
408
  }
215
409
  collection.setOptions(newOptions, options);
410
+ this.resetCaches();
216
411
  }
217
412
  upsertCollection(options) {
218
413
  if (this.collections.has(options.name)) {
@@ -230,6 +425,11 @@ const _CollectionManager = class _CollectionManager {
230
425
  this.addCollection(collection);
231
426
  }
232
427
  }
428
+ this.resetCaches();
429
+ }
430
+ setCollections(collections, options = {}) {
431
+ this.clearCollections();
432
+ this.upsertCollections(collections, options);
233
433
  }
234
434
  sortCollectionsByInherits(collections) {
235
435
  const map = /* @__PURE__ */ new Map();
@@ -293,6 +493,7 @@ const _CollectionManager = class _CollectionManager {
293
493
  }
294
494
  clearCollections() {
295
495
  this.collections.clear();
496
+ this.resetCaches();
296
497
  }
297
498
  getAssociation(associationName) {
298
499
  const [collectionName, fieldName] = associationName.split(".");
@@ -493,6 +694,9 @@ const _Collection = class _Collection {
493
694
  }
494
695
  this.upsertFields(this.options.fields || []);
495
696
  }
697
+ setOption(key, value) {
698
+ this.options[key] = value;
699
+ }
496
700
  getFields() {
497
701
  const fieldMap = /* @__PURE__ */ new Map();
498
702
  for (const inherit of this.inherits.values()) {
@@ -325,8 +325,10 @@ export declare class FlowContext {
325
325
  getPropertyOptions(key: string): PropertyOptions | undefined;
326
326
  }
327
327
  declare class BaseFlowEngineContext extends FlowContext {
328
+ t: (key: any, options?: any) => string;
328
329
  router: Router;
329
330
  dataSourceManager: DataSourceManager;
331
+ isDarkTheme: boolean;
330
332
  requireAsync: (url: string) => Promise<any>;
331
333
  importAsync: (url: string) => Promise<any>;
332
334
  createJSRunner: (options?: JSRunnerOptions) => Promise<JSRunner>;
package/lib/flowI18n.js CHANGED
@@ -71,7 +71,8 @@ const _FlowI18n = class _FlowI18n {
71
71
  translateKey(key, options) {
72
72
  var _a, _b;
73
73
  if ((_b = (_a = this.context) == null ? void 0 : _a.i18n) == null ? void 0 : _b.t) {
74
- return this.context.i18n.t(key, options);
74
+ const translated = this.context.i18n.t(key, options);
75
+ return translated == null || translated === "" ? key : translated;
75
76
  }
76
77
  return key;
77
78
  }
@@ -6,7 +6,7 @@
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
- import { DefaultStructure } from '@nocobase/flow-engine';
9
+ import type { DefaultStructure } from '../types';
10
10
  import { CollectionFieldModel } from './CollectionFieldModel';
11
11
  export declare class DisplayItemModel<T extends DefaultStructure = DefaultStructure> extends CollectionFieldModel<T> {
12
12
  }
@@ -6,7 +6,7 @@
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
- import { DefaultStructure } from '@nocobase/flow-engine';
9
+ import type { DefaultStructure } from '../types';
10
10
  import { CollectionFieldModel } from './CollectionFieldModel';
11
11
  export declare class EditableItemModel<T extends DefaultStructure = DefaultStructure> extends CollectionFieldModel<T> {
12
12
  }
@@ -6,7 +6,7 @@
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
- import { DefaultStructure } from '@nocobase/flow-engine';
9
+ import type { DefaultStructure } from '../types';
10
10
  import { CollectionFieldModel } from './CollectionFieldModel';
11
11
  export declare class FilterableItemModel<T extends DefaultStructure = DefaultStructure> extends CollectionFieldModel<T> {
12
12
  }
@@ -23,17 +23,19 @@ import type { ScheduleOptions } from '../scheduler/ModelOperationScheduler';
23
23
  import type { DispatchEventOptions, EventDefinition } from '../types';
24
24
  import { ForkFlowModel } from './forkFlowModel';
25
25
  type BaseMenuItem = NonNullable<MenuProps['items']>[number];
26
- type MenuLeafItem = Exclude<BaseMenuItem, {
27
- children: MenuProps['items'];
28
- }>;
29
- export type FlowModelExtraMenuItem = Omit<MenuLeafItem, 'key'> & {
26
+ type MenuBaseItem = Omit<Exclude<BaseMenuItem, null>, 'key' | 'children'>;
27
+ export type FlowModelExtraMenuItem = MenuBaseItem & {
30
28
  key: React.Key;
31
29
  group?: string;
32
30
  sort?: number;
31
+ label?: React.ReactNode;
32
+ disabled?: boolean;
33
33
  onClick?: () => void;
34
+ children?: FlowModelExtraMenuItem[];
34
35
  };
35
- type FlowModelExtraMenuItemInput = Omit<FlowModelExtraMenuItem, 'key'> & {
36
+ type FlowModelExtraMenuItemInput = Omit<FlowModelExtraMenuItem, 'key' | 'children'> & {
36
37
  key?: React.Key;
38
+ children?: FlowModelExtraMenuItemInput[];
37
39
  };
38
40
  type ExtraMenuItemEntry = {
39
41
  group?: string;
@@ -298,10 +300,10 @@ export declare class FlowModel<Structure extends DefaultStructure = DefaultStruc
298
300
  removeParentDelegate(): void;
299
301
  addSubModel<T extends FlowModel>(subKey: string, options: CreateModelOptions | T): T;
300
302
  setSubModel(subKey: string, options: CreateModelOptions | FlowModel): FlowModel<DefaultStructure>;
301
- filterSubModels<K extends keyof Structure['subModels'], R>(subKey: K, callback: (model: ArrayElementType<Structure['subModels'][K]>, index: number) => boolean): ArrayElementType<Structure['subModels'][K]>[];
302
- mapSubModels<K extends keyof Structure['subModels'], R>(subKey: K, callback: (model: ArrayElementType<Structure['subModels'][K]>, index: number) => R): R[];
303
- hasSubModel<K extends keyof Structure['subModels']>(subKey: K): boolean;
304
- findSubModel<K extends keyof Structure['subModels'], R>(subKey: K, callback: (model: ArrayElementType<Structure['subModels'][K]>) => R): ArrayElementType<Structure['subModels'][K]> | null;
303
+ filterSubModels<K extends keyof NonNullable<Structure['subModels']>, R>(subKey: K, callback: (model: ArrayElementType<NonNullable<Structure['subModels']>[K]>, index: number) => boolean): ArrayElementType<NonNullable<Structure['subModels']>[K]>[];
304
+ mapSubModels<K extends keyof NonNullable<Structure['subModels']>, R>(subKey: K, callback: (model: ArrayElementType<NonNullable<Structure['subModels']>[K]>, index: number) => R): R[];
305
+ hasSubModel<K extends keyof NonNullable<Structure['subModels']>>(subKey: K): boolean;
306
+ findSubModel<K extends keyof NonNullable<Structure['subModels']>, R>(subKey: K, callback: (model: ArrayElementType<NonNullable<Structure['subModels']>[K]>) => R): ArrayElementType<NonNullable<Structure['subModels']>[K]> | null;
305
307
  createRootModel(options: any): FlowModel<DefaultStructure>;
306
308
  /**
307
309
  * 对指定子模型派发 beforeRender 事件(顺序执行并使用缓存)。
@@ -73,6 +73,41 @@ const classEventRegistries = /* @__PURE__ */ new WeakMap();
73
73
  const modelMetas = /* @__PURE__ */ new WeakMap();
74
74
  const modelGlobalRegistries = /* @__PURE__ */ new WeakMap();
75
75
  const classMenuExtensions = /* @__PURE__ */ new WeakMap();
76
+ const sortExtraMenuItems = /* @__PURE__ */ __name((items) => {
77
+ return [...items].sort((a, b) => (a.sort ?? 0) - (b.sort ?? 0));
78
+ }, "sortExtraMenuItems");
79
+ const isFlowModelExtraMenuItem = /* @__PURE__ */ __name((item) => {
80
+ return item !== null;
81
+ }, "isFlowModelExtraMenuItem");
82
+ const normalizeExtraMenuItem = /* @__PURE__ */ __name((item, {
83
+ group,
84
+ sort,
85
+ prefix,
86
+ path
87
+ }) => {
88
+ if (!item) {
89
+ return null;
90
+ }
91
+ const normalizedGroup = item.group || group;
92
+ const normalizedSort = typeof item.sort === "number" ? item.sort : sort;
93
+ const normalizedChildren = sortExtraMenuItems(
94
+ (item.children || []).map(
95
+ (child, index) => normalizeExtraMenuItem(child, {
96
+ group: normalizedGroup,
97
+ sort: normalizedSort,
98
+ prefix,
99
+ path: `${path}-${index}`
100
+ })
101
+ ).filter(isFlowModelExtraMenuItem)
102
+ );
103
+ return {
104
+ ...item,
105
+ key: item.key ?? `${prefix}-${normalizedGroup}-${path}`,
106
+ group: normalizedGroup,
107
+ sort: normalizedSort,
108
+ children: normalizedChildren.length ? normalizedChildren : void 0
109
+ };
110
+ }, "normalizeExtraMenuItem");
76
111
  async function loadOpenStepSettingsDialog() {
77
112
  const mod = await import("../components/settings/wrappers/contextual/StepSettingsDialog");
78
113
  return mod.openStepSettingsDialog;
@@ -1240,22 +1275,26 @@ const _FlowModel = class _FlowModel {
1240
1275
  seen.add(Cls);
1241
1276
  const reg = classMenuExtensions.get(Cls);
1242
1277
  if (reg) {
1278
+ let entryIndex = 0;
1243
1279
  for (const entry of reg) {
1244
1280
  if (entry.matcher && !entry.matcher(model)) continue;
1245
1281
  const items = typeof entry.items === "function" ? await entry.items(model, t) : await Promise.resolve(entry.items || []);
1246
1282
  const group = entry.group || "common-actions";
1247
1283
  const sort = entry.sort ?? 0;
1248
1284
  const prefix = entry.keyPrefix || Cls.name || "extra";
1249
- (items || []).forEach((it, idx) => {
1250
- if (!it) return;
1251
- const key = it.key ?? `${prefix}-${group}-${idx}-${Math.random().toString(36).slice(2, 6)}`;
1252
- collected.push({
1253
- ...it,
1254
- key,
1255
- group: it.group || group,
1256
- sort: typeof it.sort === "number" ? it.sort : sort
1257
- });
1285
+ sortExtraMenuItems(
1286
+ (items || []).map(
1287
+ (it, idx) => normalizeExtraMenuItem(it, {
1288
+ group,
1289
+ sort,
1290
+ prefix,
1291
+ path: `${entryIndex}-${idx}`
1292
+ })
1293
+ ).filter(isFlowModelExtraMenuItem)
1294
+ ).forEach((it) => {
1295
+ collected.push(it);
1258
1296
  });
1297
+ entryIndex += 1;
1259
1298
  }
1260
1299
  }
1261
1300
  const ParentClass = Object.getPrototypeOf(Cls);
package/lib/provider.js CHANGED
@@ -67,31 +67,46 @@ const FlowEngineGlobalsContextProvider = /* @__PURE__ */ __name(({ children }) =
67
67
  const engine = useFlowEngine();
68
68
  const config = (0, import_react.useContext)(import_antd.ConfigProvider.ConfigContext);
69
69
  const { token } = import_antd.theme.useToken();
70
- (0, import_react.useEffect)(() => {
71
- const context = {
72
- antdConfig: config,
73
- // themeToken 改为可观察的 getter,在下方单独 define
74
- modal,
75
- message,
76
- notification
77
- };
78
- engine.context.defineProperty("viewer", {
79
- cache: false,
80
- get: /* @__PURE__ */ __name((ctx) => new import_FlowView.FlowViewer(ctx, { drawer, embed, popover, dialog }), "get")
81
- });
82
- for (const item of Object.entries(context)) {
83
- const [key, value] = item;
84
- if (value) {
85
- engine.context.defineProperty(key, { value });
86
- }
70
+ const isDarkTheme = import_react.default.useMemo(() => {
71
+ var _a2;
72
+ const algorithm = (_a2 = config == null ? void 0 : config.theme) == null ? void 0 : _a2.algorithm;
73
+ if (Array.isArray(algorithm)) {
74
+ return algorithm.includes(import_antd.theme.darkAlgorithm);
75
+ }
76
+ return algorithm === import_antd.theme.darkAlgorithm;
77
+ }, [config]);
78
+ engine.context.defineProperty("viewer", {
79
+ cache: false,
80
+ get: /* @__PURE__ */ __name((ctx) => new import_FlowView.FlowViewer(ctx, { drawer, embed, popover, dialog }), "get")
81
+ });
82
+ for (const item of Object.entries({
83
+ antdConfig: config,
84
+ modal,
85
+ message,
86
+ notification
87
+ })) {
88
+ const [key, value] = item;
89
+ if (value) {
90
+ engine.context.defineProperty(key, { value });
87
91
  }
88
- engine.context.defineProperty("themeToken", {
89
- get: /* @__PURE__ */ __name(() => token, "get"),
90
- observable: true,
91
- cache: true
92
- });
92
+ }
93
+ engine.context.defineProperty("themeToken", {
94
+ get: /* @__PURE__ */ __name(() => token, "get"),
95
+ observable: true,
96
+ cache: true
97
+ });
98
+ engine.context.defineProperty("isDarkTheme", {
99
+ get: /* @__PURE__ */ __name(() => isDarkTheme, "get"),
100
+ observable: true,
101
+ cache: true,
102
+ info: {
103
+ description: "Whether current theme algorithm is dark mode.",
104
+ detail: "boolean"
105
+ }
106
+ });
107
+ (0, import_react.useEffect)(() => {
93
108
  engine.reactView.refresh();
94
- }, [engine, drawer, modal, message, notification, config, popover, token, dialog, embed]);
109
+ }, [engine, drawer, modal, message, notification, config, popover, token, dialog, embed, isDarkTheme]);
95
110
  return /* @__PURE__ */ import_react.default.createElement(import_antd.ConfigProvider, { ...config, locale: (_a = engine.context.locales) == null ? void 0 : _a.antd, popupMatchSelectWidth: false }, children, contextHolder, popoverContextHolder, pageContextHolder, dialogContextHolder);
96
111
  }, "FlowEngineGlobalsContextProvider");
97
112
  const useFlowEngine = /* @__PURE__ */ __name(({ throwError = true } = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.1.0-beta.22",
3
+ "version": "2.1.0-beta.23",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@formily/antd-v5": "1.x",
10
10
  "@formily/reactive": "2.x",
11
- "@nocobase/sdk": "2.1.0-beta.22",
12
- "@nocobase/shared": "2.1.0-beta.22",
11
+ "@nocobase/sdk": "2.1.0-beta.23",
12
+ "@nocobase/shared": "2.1.0-beta.23",
13
13
  "ahooks": "^3.7.2",
14
14
  "axios": "^1.7.0",
15
15
  "dayjs": "^1.11.9",
@@ -37,5 +37,5 @@
37
37
  ],
38
38
  "author": "NocoBase Team",
39
39
  "license": "Apache-2.0",
40
- "gitHead": "53ad02861ed8e813103f59659804417118c85b4c"
40
+ "gitHead": "bb4c0d3551bf9eff505b63756dd24a0813231f16"
41
41
  }
@@ -9,9 +9,10 @@
9
9
 
10
10
  import React from 'react';
11
11
  import { describe, expect, it } from 'vitest';
12
- import { renderHook } from '@testing-library/react';
12
+ import { render, renderHook } from '@testing-library/react';
13
+ import { App, ConfigProvider, theme } from 'antd';
13
14
  import { FlowEngine } from '../flowEngine';
14
- import { FlowEngineProvider, useFlowEngine } from '../provider';
15
+ import { FlowEngineGlobalsContextProvider, FlowEngineProvider, useFlowEngine } from '../provider';
15
16
 
16
17
  describe('FlowEngineProvider/useFlowEngine', () => {
17
18
  it('returns engine within provider', () => {
@@ -20,4 +21,25 @@ describe('FlowEngineProvider/useFlowEngine', () => {
20
21
  const { result } = renderHook(() => useFlowEngine(), { wrapper });
21
22
  expect(result.current).toBe(engine);
22
23
  });
24
+
25
+ it('registers isDarkTheme within globals provider before first child render', () => {
26
+ const engine = new FlowEngine();
27
+ const reads: boolean[] = [];
28
+ const Reader = () => {
29
+ reads.push(engine.context.isDarkTheme);
30
+ return null;
31
+ };
32
+ const wrapper = ({ children }: any) => (
33
+ <ConfigProvider theme={{ algorithm: theme.darkAlgorithm }}>
34
+ <App>
35
+ <FlowEngineProvider engine={engine}>
36
+ <FlowEngineGlobalsContextProvider>{children}</FlowEngineGlobalsContextProvider>
37
+ </FlowEngineProvider>
38
+ </App>
39
+ </ConfigProvider>
40
+ );
41
+ render(<Reader />, { wrapper });
42
+ expect(reads[0]).toBe(true);
43
+ expect(engine.context.isDarkTheme).toBe(true);
44
+ });
23
45
  });
@@ -7,7 +7,8 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- import { FlowModelRenderer, FlowModelRendererProps } from '@nocobase/flow-engine';
10
+ import type { FlowModelRendererProps } from './FlowModelRenderer';
11
+ import { FlowModelRenderer } from './FlowModelRenderer';
11
12
  import _ from 'lodash';
12
13
  import React, { useEffect, useMemo, useRef } from 'react';
13
14
 
@@ -69,6 +69,8 @@ export interface FlowModelRendererProps {
69
69
  showBackground?: boolean;
70
70
  showBorder?: boolean;
71
71
  showDragHandle?: boolean;
72
+ /** 是否显示事件流入口,默认 true */
73
+ showDynamicFlowsEditor?: boolean;
72
74
  /** 自定义工具栏样式,`top/left/right/bottom` 会作为 portal overlay 的 inset 使用 */
73
75
  style?: React.CSSProperties;
74
76
  /**
@@ -112,6 +114,7 @@ const FlowModelRendererWithAutoFlows: React.FC<{
112
114
  showBackground?: boolean;
113
115
  showBorder?: boolean;
114
116
  showDragHandle?: boolean;
117
+ showDynamicFlowsEditor?: boolean;
115
118
  /** `top/left/right/bottom` 会作为 portal overlay 的 inset 使用 */
116
119
  style?: React.CSSProperties;
117
120
  /**
@@ -184,6 +187,7 @@ const FlowModelRendererCore: React.FC<{
184
187
  showBackground?: boolean;
185
188
  showBorder?: boolean;
186
189
  showDragHandle?: boolean;
190
+ showDynamicFlowsEditor?: boolean;
187
191
  /** `top/left/right/bottom` 会作为 portal overlay 的 inset 使用 */
188
192
  style?: React.CSSProperties;
189
193
  /**
@@ -254,6 +258,7 @@ const FlowModelRendererCore: React.FC<{
254
258
  showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
255
259
  showBorder={_.isObject(showFlowSettings) ? showFlowSettings.showBorder : undefined}
256
260
  showDragHandle={_.isObject(showFlowSettings) ? showFlowSettings.showDragHandle : undefined}
261
+ showDynamicFlowsEditor={_.isObject(showFlowSettings) ? showFlowSettings.showDynamicFlowsEditor : undefined}
257
262
  settingsMenuLevel={settingsMenuLevel}
258
263
  extraToolbarItems={extraToolbarItems}
259
264
  toolbarStyle={_.isObject(showFlowSettings) ? showFlowSettings.style : undefined}
@@ -300,6 +305,7 @@ const FlowModelRendererCore: React.FC<{
300
305
  showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
301
306
  showBorder={_.isObject(showFlowSettings) ? showFlowSettings.showBorder : undefined}
302
307
  showDragHandle={_.isObject(showFlowSettings) ? showFlowSettings.showDragHandle : undefined}
308
+ showDynamicFlowsEditor={_.isObject(showFlowSettings) ? showFlowSettings.showDynamicFlowsEditor : undefined}
303
309
  settingsMenuLevel={settingsMenuLevel}
304
310
  extraToolbarItems={extraToolbarItems}
305
311
  toolbarStyle={_.isObject(showFlowSettings) ? showFlowSettings.style : undefined}