@nocobase/flow-engine 2.1.0-alpha.3 → 2.1.0-alpha.30

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 (160) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -10
  3. package/lib/JSRunner.d.ts +10 -1
  4. package/lib/JSRunner.js +50 -5
  5. package/lib/ViewScopedFlowEngine.js +5 -1
  6. package/lib/components/FieldModelRenderer.js +2 -2
  7. package/lib/components/FlowModelRenderer.d.ts +3 -1
  8. package/lib/components/FlowModelRenderer.js +12 -6
  9. package/lib/components/MobilePopup.js +6 -5
  10. package/lib/components/dnd/gridDragPlanner.d.ts +59 -2
  11. package/lib/components/dnd/gridDragPlanner.js +601 -21
  12. package/lib/components/dnd/index.d.ts +19 -1
  13. package/lib/components/dnd/index.js +243 -23
  14. package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +2 -1
  15. package/lib/components/settings/wrappers/component/SelectWithTitle.js +14 -12
  16. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
  17. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +68 -10
  18. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +23 -43
  19. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +352 -295
  20. package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +16 -2
  21. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.d.ts +36 -0
  22. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +274 -0
  23. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
  24. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +315 -0
  25. package/lib/components/subModel/AddSubModelButton.js +27 -1
  26. package/lib/components/subModel/index.d.ts +1 -0
  27. package/lib/components/subModel/index.js +19 -0
  28. package/lib/components/subModel/utils.d.ts +1 -1
  29. package/lib/components/subModel/utils.js +2 -2
  30. package/lib/data-source/index.d.ts +73 -0
  31. package/lib/data-source/index.js +211 -1
  32. package/lib/executor/FlowExecutor.js +31 -8
  33. package/lib/flowContext.d.ts +2 -0
  34. package/lib/flowContext.js +31 -1
  35. package/lib/flowEngine.d.ts +151 -1
  36. package/lib/flowEngine.js +389 -15
  37. package/lib/flowI18n.js +2 -1
  38. package/lib/flowSettings.d.ts +14 -6
  39. package/lib/flowSettings.js +34 -6
  40. package/lib/lazy-helper.d.ts +14 -0
  41. package/lib/lazy-helper.js +71 -0
  42. package/lib/locale/en-US.json +1 -0
  43. package/lib/locale/index.d.ts +2 -0
  44. package/lib/locale/zh-CN.json +1 -0
  45. package/lib/models/DisplayItemModel.d.ts +1 -1
  46. package/lib/models/EditableItemModel.d.ts +1 -1
  47. package/lib/models/FilterableItemModel.d.ts +1 -1
  48. package/lib/models/flowModel.d.ts +13 -10
  49. package/lib/models/flowModel.js +78 -18
  50. package/lib/provider.js +38 -23
  51. package/lib/reactive/observer.js +46 -16
  52. package/lib/runjs-context/registry.d.ts +1 -1
  53. package/lib/runjs-context/setup.js +20 -12
  54. package/lib/runjs-context/snippets/index.js +13 -2
  55. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts +11 -0
  56. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.js +50 -0
  57. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts +11 -0
  58. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
  59. package/lib/scheduler/ModelOperationScheduler.d.ts +5 -1
  60. package/lib/scheduler/ModelOperationScheduler.js +3 -2
  61. package/lib/types.d.ts +47 -1
  62. package/lib/utils/createCollectionContextMeta.js +6 -2
  63. package/lib/utils/index.d.ts +2 -2
  64. package/lib/utils/index.js +4 -0
  65. package/lib/utils/parsePathnameToViewParams.js +1 -1
  66. package/lib/utils/runjsTemplateCompat.js +1 -1
  67. package/lib/utils/runjsValue.js +41 -11
  68. package/lib/utils/schema-utils.d.ts +7 -1
  69. package/lib/utils/schema-utils.js +19 -0
  70. package/lib/views/FlowView.d.ts +7 -1
  71. package/lib/views/runViewBeforeClose.d.ts +10 -0
  72. package/lib/views/runViewBeforeClose.js +45 -0
  73. package/lib/views/useDialog.d.ts +2 -1
  74. package/lib/views/useDialog.js +20 -3
  75. package/lib/views/useDrawer.d.ts +2 -1
  76. package/lib/views/useDrawer.js +20 -3
  77. package/lib/views/usePage.d.ts +2 -1
  78. package/lib/views/usePage.js +10 -3
  79. package/package.json +6 -5
  80. package/src/JSRunner.ts +68 -4
  81. package/src/ViewScopedFlowEngine.ts +4 -0
  82. package/src/__tests__/JSRunner.test.ts +27 -1
  83. package/src/__tests__/flow-engine.test.ts +166 -0
  84. package/src/__tests__/flowContext.test.ts +65 -1
  85. package/src/__tests__/flowEngine.modelLoaders.test.ts +245 -0
  86. package/src/__tests__/flowSettings.test.ts +94 -15
  87. package/src/__tests__/objectVariable.test.ts +24 -0
  88. package/src/__tests__/provider.test.tsx +24 -2
  89. package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
  90. package/src/__tests__/runjsContext.test.ts +16 -0
  91. package/src/__tests__/runjsContextRuntime.test.ts +2 -0
  92. package/src/__tests__/runjsPreprocessDefault.test.ts +23 -0
  93. package/src/__tests__/runjsSnippets.test.ts +21 -0
  94. package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
  95. package/src/components/FieldModelRenderer.tsx +2 -1
  96. package/src/components/FlowModelRenderer.tsx +18 -6
  97. package/src/components/MobilePopup.tsx +4 -2
  98. package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
  99. package/src/components/__tests__/dnd.test.ts +44 -0
  100. package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +20 -10
  101. package/src/components/__tests__/gridDragPlanner.test.ts +512 -3
  102. package/src/components/dnd/__tests__/DndProvider.test.tsx +98 -0
  103. package/src/components/dnd/gridDragPlanner.ts +743 -19
  104. package/src/components/dnd/index.tsx +291 -27
  105. package/src/components/settings/wrappers/component/SelectWithTitle.tsx +21 -9
  106. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +88 -10
  107. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +487 -440
  108. package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +18 -2
  109. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +189 -3
  110. package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +778 -0
  111. package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +360 -0
  112. package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +361 -0
  113. package/src/components/subModel/AddSubModelButton.tsx +32 -2
  114. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +142 -32
  115. package/src/components/subModel/index.ts +1 -0
  116. package/src/components/subModel/utils.ts +1 -1
  117. package/src/data-source/__tests__/index.test.ts +34 -1
  118. package/src/data-source/index.ts +258 -2
  119. package/src/executor/FlowExecutor.ts +34 -9
  120. package/src/executor/__tests__/flowExecutor.test.ts +57 -0
  121. package/src/flowContext.ts +37 -3
  122. package/src/flowEngine.ts +445 -11
  123. package/src/flowI18n.ts +2 -1
  124. package/src/flowSettings.ts +40 -6
  125. package/src/lazy-helper.tsx +57 -0
  126. package/src/locale/en-US.json +1 -0
  127. package/src/locale/zh-CN.json +1 -0
  128. package/src/models/DisplayItemModel.tsx +1 -1
  129. package/src/models/EditableItemModel.tsx +1 -1
  130. package/src/models/FilterableItemModel.tsx +1 -1
  131. package/src/models/__tests__/dispatchEvent.when.test.ts +214 -0
  132. package/src/models/__tests__/flowModel.test.ts +19 -3
  133. package/src/models/flowModel.tsx +119 -33
  134. package/src/provider.tsx +41 -25
  135. package/src/reactive/__tests__/observer.test.tsx +82 -0
  136. package/src/reactive/observer.tsx +87 -25
  137. package/src/runjs-context/registry.ts +1 -1
  138. package/src/runjs-context/setup.ts +22 -12
  139. package/src/runjs-context/snippets/index.ts +12 -1
  140. package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
  141. package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
  142. package/src/scheduler/ModelOperationScheduler.ts +14 -3
  143. package/src/types.ts +60 -0
  144. package/src/utils/__tests__/createCollectionContextMeta.test.ts +48 -0
  145. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
  146. package/src/utils/__tests__/runjsValue.test.ts +11 -0
  147. package/src/utils/__tests__/utils.test.ts +62 -0
  148. package/src/utils/createCollectionContextMeta.ts +6 -2
  149. package/src/utils/index.ts +2 -1
  150. package/src/utils/parsePathnameToViewParams.ts +2 -2
  151. package/src/utils/runjsTemplateCompat.ts +1 -1
  152. package/src/utils/runjsValue.ts +50 -11
  153. package/src/utils/schema-utils.ts +30 -1
  154. package/src/views/FlowView.tsx +11 -1
  155. package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
  156. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +13 -12
  157. package/src/views/runViewBeforeClose.ts +19 -0
  158. package/src/views/useDialog.tsx +25 -3
  159. package/src/views/useDrawer.tsx +25 -3
  160. package/src/views/usePage.tsx +12 -3
@@ -0,0 +1,71 @@
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 lazy_helper_exports = {};
39
+ __export(lazy_helper_exports, {
40
+ lazy: () => lazy
41
+ });
42
+ module.exports = __toCommonJS(lazy_helper_exports);
43
+ var import_react = __toESM(require("react"));
44
+ function lazy(factory, ...componentNames) {
45
+ if (componentNames.length === 0) {
46
+ const LazyComponent = (0, import_react.lazy)(
47
+ () => factory().then((module2) => ({
48
+ default: module2.default
49
+ }))
50
+ );
51
+ const Component = /* @__PURE__ */ __name((props) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Suspense, { fallback: null }, /* @__PURE__ */ import_react.default.createElement(LazyComponent, { ...props })), "Component");
52
+ return Component;
53
+ }
54
+ return componentNames.reduce(
55
+ (acc, name) => {
56
+ const LazyComponent = (0, import_react.lazy)(
57
+ () => factory().then((module2) => ({
58
+ default: module2[name]
59
+ }))
60
+ );
61
+ acc[name] = (props) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Suspense, { fallback: null }, /* @__PURE__ */ import_react.default.createElement(LazyComponent, { ...props }));
62
+ return acc;
63
+ },
64
+ {}
65
+ );
66
+ }
67
+ __name(lazy, "lazy");
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ lazy
71
+ });
@@ -34,6 +34,7 @@
34
34
  "Failed to destroy model after creation error": "Failed to destroy model after creation error",
35
35
  "Failed to get action {{action}}": "Failed to get action {{action}}",
36
36
  "Failed to get configurable flows for model {{model}}": "Failed to get configurable flows for model {{model}}",
37
+ "Attributes are unavailable before selecting a record": "Attributes are unavailable before selecting a record",
37
38
  "Failed to import FormDialog": "Failed to import FormDialog",
38
39
  "Failed to import FormDialog or FormStep": "Failed to import FormDialog or FormStep",
39
40
  "Failed to import Formily components": "Failed to import Formily components",
@@ -43,6 +43,7 @@ export declare const locales: {
43
43
  "Failed to destroy model after creation error": string;
44
44
  "Failed to get action {{action}}": string;
45
45
  "Failed to get configurable flows for model {{model}}": string;
46
+ "Attributes are unavailable before selecting a record": string;
46
47
  "Failed to import FormDialog": string;
47
48
  "Failed to import FormDialog or FormStep": string;
48
49
  "Failed to import Formily components": string;
@@ -120,6 +121,7 @@ export declare const locales: {
120
121
  "Failed to destroy model after creation error": string;
121
122
  "Failed to get action {{action}}": string;
122
123
  "Failed to get configurable flows for model {{model}}": string;
124
+ "Attributes are unavailable before selecting a record": string;
123
125
  "Failed to import FormDialog": string;
124
126
  "Failed to import FormDialog or FormStep": string;
125
127
  "Failed to import Formily components": string;
@@ -31,6 +31,7 @@
31
31
  "Failed to destroy model after creation error": "创建错误后销毁模型失败",
32
32
  "Failed to get action {{action}}": "获取 action '{{action}}' 失败",
33
33
  "Failed to get configurable flows for model {{model}}": "获取模型 '{{model}}' 的可配置 flows 失败",
34
+ "Attributes are unavailable before selecting a record": "选择记录之前,当前项属性不可用",
34
35
  "Failed to import FormDialog": "导入 FormDialog 失败",
35
36
  "Failed to import FormDialog or FormStep": "导入 FormDialog 或 FormStep 失败",
36
37
  "Failed to import Formily components": "导入 Formily 组件失败",
@@ -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
  }
@@ -13,6 +13,7 @@ import { FlowContext, FlowModelContext, FlowRuntimeContext } from '../flowContex
13
13
  import { FlowEngine } from '../flowEngine';
14
14
  import type { ActionDefinition, ArrayElementType, CreateModelOptions, CreateSubModelOptions, DefaultStructure, FlowDefinitionOptions, FlowModelMeta, FlowModelOptions, ModelConstructor, ParamObject, ParentFlowModel, PersistOptions, ResolveUseResult, StepParams } from '../types';
15
15
  import { IModelComponentProps, ReadonlyModelProps } from '../types';
16
+ import type { MenuProps } from 'antd';
16
17
  import { ModelActionRegistry } from '../action-registry/ModelActionRegistry';
17
18
  import { ModelEventRegistry } from '../event-registry/ModelEventRegistry';
18
19
  import { GlobalFlowRegistry } from '../flow-registry/GlobalFlowRegistry';
@@ -21,19 +22,20 @@ import { FlowSettingsOpenOptions } from '../flowSettings';
21
22
  import type { ScheduleOptions } from '../scheduler/ModelOperationScheduler';
22
23
  import type { DispatchEventOptions, EventDefinition } from '../types';
23
24
  import { ForkFlowModel } from './forkFlowModel';
24
- import type { MenuProps } from 'antd';
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;
@@ -239,6 +241,7 @@ export declare class FlowModel<Structure extends DefaultStructure = DefaultStruc
239
241
  * 使用 lodash debounce 避免频繁调用
240
242
  */
241
243
  private _rerunLastAutoRun;
244
+ private resetAutoRunState;
242
245
  /**
243
246
  * 通用事件分发钩子:开始
244
247
  * 子类可覆盖;beforeRender 事件可通过抛出 FlowExitException 提前终止。
@@ -297,10 +300,10 @@ export declare class FlowModel<Structure extends DefaultStructure = DefaultStruc
297
300
  removeParentDelegate(): void;
298
301
  addSubModel<T extends FlowModel>(subKey: string, options: CreateModelOptions | T): T;
299
302
  setSubModel(subKey: string, options: CreateModelOptions | FlowModel): FlowModel<DefaultStructure>;
300
- filterSubModels<K extends keyof Structure['subModels'], R>(subKey: K, callback: (model: ArrayElementType<Structure['subModels'][K]>, index: number) => boolean): ArrayElementType<Structure['subModels'][K]>[];
301
- mapSubModels<K extends keyof Structure['subModels'], R>(subKey: K, callback: (model: ArrayElementType<Structure['subModels'][K]>, index: number) => R): R[];
302
- hasSubModel<K extends keyof Structure['subModels']>(subKey: K): boolean;
303
- 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;
304
307
  createRootModel(options: any): FlowModel<DefaultStructure>;
305
308
  /**
306
309
  * 对指定子模型派发 beforeRender 事件(顺序执行并使用缓存)。
@@ -56,25 +56,68 @@ var import_reactive = require("@formily/reactive");
56
56
  var import_lodash = __toESM(require("lodash"));
57
57
  var import_react = __toESM(require("react"));
58
58
  var import_secure = require("uid/secure");
59
- var import_StepRequiredSettingsDialog = require("../components/settings/wrappers/contextual/StepRequiredSettingsDialog");
60
- var import_StepSettingsDialog = require("../components/settings/wrappers/contextual/StepSettingsDialog");
61
59
  var import_emitter = require("../emitter");
62
60
  var import_InstanceFlowRegistry = require("../flow-registry/InstanceFlowRegistry");
63
61
  var import_flowContext = require("../flowContext");
64
62
  var import_utils = require("../utils");
65
- var import_lib = require("antd/lib");
63
+ var import_antd = require("antd");
64
+ var import__ = require("..");
66
65
  var import_ModelActionRegistry = require("../action-registry/ModelActionRegistry");
67
66
  var import_utils2 = require("../components/subModel/utils");
68
67
  var import_ModelEventRegistry = require("../event-registry/ModelEventRegistry");
69
68
  var import_GlobalFlowRegistry = require("../flow-registry/GlobalFlowRegistry");
70
69
  var import_forkFlowModel = require("./forkFlowModel");
71
- var import__ = require("..");
72
70
  var _flowContext;
73
71
  const classActionRegistries = /* @__PURE__ */ new WeakMap();
74
72
  const classEventRegistries = /* @__PURE__ */ new WeakMap();
75
73
  const modelMetas = /* @__PURE__ */ new WeakMap();
76
74
  const modelGlobalRegistries = /* @__PURE__ */ new WeakMap();
77
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");
111
+ async function loadOpenStepSettingsDialog() {
112
+ const mod = await import("../components/settings/wrappers/contextual/StepSettingsDialog");
113
+ return mod.openStepSettingsDialog;
114
+ }
115
+ __name(loadOpenStepSettingsDialog, "loadOpenStepSettingsDialog");
116
+ async function loadOpenRequiredParamsStepFormDialog() {
117
+ const mod = await import("../components/settings/wrappers/contextual/StepRequiredSettingsDialog");
118
+ return mod.openRequiredParamsStepFormDialog;
119
+ }
120
+ __name(loadOpenRequiredParamsStepFormDialog, "loadOpenRequiredParamsStepFormDialog");
78
121
  var ModelRenderMode = /* @__PURE__ */ ((ModelRenderMode2) => {
79
122
  ModelRenderMode2["ReactElement"] = "reactElement";
80
123
  ModelRenderMode2["RenderFunction"] = "renderFunction";
@@ -183,10 +226,13 @@ const _FlowModel = class _FlowModel {
183
226
  if (changed.type === "set" && import_lodash.default.isEqual(changed.value, changed.oldValue)) {
184
227
  return;
185
228
  }
229
+ const hasLastAutoRun = !!this._lastAutoRunParams;
186
230
  if (this.flowEngine) {
187
231
  this.invalidateFlowCache("beforeRender");
188
232
  }
189
- this._rerunLastAutoRun();
233
+ if (hasLastAutoRun) {
234
+ this._rerunLastAutoRun();
235
+ }
190
236
  this.forks.forEach((fork) => {
191
237
  fork.rerender();
192
238
  });
@@ -576,6 +622,7 @@ const _FlowModel = class _FlowModel {
576
622
  } else {
577
623
  this.props = { ...this.props, ...props };
578
624
  }
625
+ this._options.props = { ...this.props };
579
626
  }
580
627
  getProps() {
581
628
  return this.props;
@@ -674,6 +721,11 @@ const _FlowModel = class _FlowModel {
674
721
  }, "isMatch");
675
722
  return Array.from(allFlows.values()).filter(isMatch);
676
723
  }
724
+ resetAutoRunState() {
725
+ var _a, _b;
726
+ (_b = (_a = this._rerunLastAutoRun) == null ? void 0 : _a.cancel) == null ? void 0 : _b.call(_a);
727
+ this._lastAutoRunParams = null;
728
+ }
677
729
  /**
678
730
  * 通用事件分发钩子:开始
679
731
  * 子类可覆盖;beforeRender 事件可通过抛出 FlowExitException 提前终止。
@@ -763,6 +815,7 @@ const _FlowModel = class _FlowModel {
763
815
  }));
764
816
  return () => {
765
817
  var _a3, _b3;
818
+ renderTarget.resetAutoRunState();
766
819
  if (typeof renderTarget.onUnmount === "function") {
767
820
  renderTarget.onUnmount();
768
821
  }
@@ -1058,7 +1111,7 @@ const _FlowModel = class _FlowModel {
1058
1111
  * @param {string} stepKey 步骤的唯一标识符
1059
1112
  * @returns {void}
1060
1113
  */
1061
- openStepSettingsDialog(flowKey, stepKey) {
1114
+ async openStepSettingsDialog(flowKey, stepKey) {
1062
1115
  var _a;
1063
1116
  const flow = this.getFlow(flowKey);
1064
1117
  const step = (_a = flow == null ? void 0 : flow.steps) == null ? void 0 : _a[stepKey];
@@ -1069,7 +1122,8 @@ const _FlowModel = class _FlowModel {
1069
1122
  const ctx = new import_flowContext.FlowRuntimeContext(this, flowKey, "settings");
1070
1123
  (0, import_utils.setupRuntimeContextSteps)(ctx, flow.steps, this, flowKey);
1071
1124
  ctx.defineProperty("currentStep", { value: step });
1072
- return (0, import_StepSettingsDialog.openStepSettingsDialog)({
1125
+ const openStepSettingsDialog = await loadOpenStepSettingsDialog();
1126
+ return openStepSettingsDialog({
1073
1127
  model: this,
1074
1128
  flowKey,
1075
1129
  stepKey,
@@ -1084,7 +1138,8 @@ const _FlowModel = class _FlowModel {
1084
1138
  * @returns {Promise<any>} 返回表单提交的值
1085
1139
  */
1086
1140
  async configureRequiredSteps(dialogWidth, dialogTitle) {
1087
- return (0, import_StepRequiredSettingsDialog.openRequiredParamsStepFormDialog)({
1141
+ const openRequiredParamsStepFormDialog = await loadOpenRequiredParamsStepFormDialog();
1142
+ return openRequiredParamsStepFormDialog({
1088
1143
  model: this,
1089
1144
  dialogWidth,
1090
1145
  dialogTitle
@@ -1109,6 +1164,7 @@ const _FlowModel = class _FlowModel {
1109
1164
  const data = {
1110
1165
  uid: this.uid,
1111
1166
  ...import_lodash.default.omit(this._options, ["flowEngine"]),
1167
+ props: { ...this.props },
1112
1168
  stepParams: this.stepParams,
1113
1169
  sortIndex: this.sortIndex,
1114
1170
  flowRegistry: {}
@@ -1221,22 +1277,26 @@ const _FlowModel = class _FlowModel {
1221
1277
  seen.add(Cls);
1222
1278
  const reg = classMenuExtensions.get(Cls);
1223
1279
  if (reg) {
1280
+ let entryIndex = 0;
1224
1281
  for (const entry of reg) {
1225
1282
  if (entry.matcher && !entry.matcher(model)) continue;
1226
1283
  const items = typeof entry.items === "function" ? await entry.items(model, t) : await Promise.resolve(entry.items || []);
1227
1284
  const group = entry.group || "common-actions";
1228
1285
  const sort = entry.sort ?? 0;
1229
1286
  const prefix = entry.keyPrefix || Cls.name || "extra";
1230
- (items || []).forEach((it, idx) => {
1231
- if (!it) return;
1232
- const key = it.key ?? `${prefix}-${group}-${idx}-${Math.random().toString(36).slice(2, 6)}`;
1233
- collected.push({
1234
- ...it,
1235
- key,
1236
- group: it.group || group,
1237
- sort: typeof it.sort === "number" ? it.sort : sort
1238
- });
1287
+ sortExtraMenuItems(
1288
+ (items || []).map(
1289
+ (it, idx) => normalizeExtraMenuItem(it, {
1290
+ group,
1291
+ sort,
1292
+ prefix,
1293
+ path: `${entryIndex}-${idx}`
1294
+ })
1295
+ ).filter(isFlowModelExtraMenuItem)
1296
+ ).forEach((it) => {
1297
+ collected.push(it);
1239
1298
  });
1299
+ entryIndex += 1;
1240
1300
  }
1241
1301
  }
1242
1302
  const ParentClass = Object.getPrototypeOf(Cls);
@@ -1303,7 +1363,7 @@ const _ErrorFlowModel = class _ErrorFlowModel extends FlowModel {
1303
1363
  this.errorMessage = msg;
1304
1364
  }
1305
1365
  render() {
1306
- return /* @__PURE__ */ import_react.default.createElement(import_lib.Typography.Text, { type: "danger" }, this.errorMessage);
1366
+ return /* @__PURE__ */ import_react.default.createElement(import_antd.Typography.Text, { type: "danger" }, this.errorMessage);
1307
1367
  }
1308
1368
  };
1309
1369
  __name(_ErrorFlowModel, "ErrorFlowModel");
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 } = {}) => {
@@ -51,8 +51,31 @@ const observer = /* @__PURE__ */ __name((Component, options) => {
51
51
  const ctxRef = (0, import_react.useRef)(ctx);
52
52
  ctxRef.current = ctx;
53
53
  const pendingDisposerRef = (0, import_react.useRef)(null);
54
+ const pendingTimerRef = (0, import_react.useRef)(null);
55
+ const clearPendingDisposer = /* @__PURE__ */ __name(() => {
56
+ if (pendingDisposerRef.current) {
57
+ pendingDisposerRef.current();
58
+ pendingDisposerRef.current = null;
59
+ }
60
+ }, "clearPendingDisposer");
61
+ const clearPendingTimer = /* @__PURE__ */ __name(() => {
62
+ if (pendingTimerRef.current) {
63
+ clearTimeout(pendingTimerRef.current);
64
+ pendingTimerRef.current = null;
65
+ }
66
+ }, "clearPendingTimer");
67
+ const isContextActive = /* @__PURE__ */ __name(() => {
68
+ var _a, _b;
69
+ const pageActive = getPageActive(ctxRef.current);
70
+ const tabActive = (_b = (_a = ctxRef.current) == null ? void 0 : _a.tabActive) == null ? void 0 : _b.value;
71
+ return pageActive !== false && tabActive !== false;
72
+ }, "isContextActive");
54
73
  (0, import_react.useEffect)(() => {
55
74
  return () => {
75
+ if (pendingTimerRef.current) {
76
+ clearTimeout(pendingTimerRef.current);
77
+ pendingTimerRef.current = null;
78
+ }
56
79
  if (pendingDisposerRef.current) {
57
80
  pendingDisposerRef.current();
58
81
  pendingDisposerRef.current = null;
@@ -62,30 +85,37 @@ const observer = /* @__PURE__ */ __name((Component, options) => {
62
85
  const ObservedComponent = (0, import_react.useMemo)(
63
86
  () => (0, import_reactive_react.observer)(Component, {
64
87
  scheduler(updater) {
65
- var _a, _b;
66
- const pageActive = getPageActive(ctxRef.current);
67
- const tabActive = (_b = (_a = ctxRef.current) == null ? void 0 : _a.tabActive) == null ? void 0 : _b.value;
68
- if (pageActive === false || tabActive === false) {
69
- setTimeout(() => {
88
+ if (!isContextActive()) {
89
+ if (pendingTimerRef.current || pendingDisposerRef.current) {
90
+ return;
91
+ }
92
+ pendingTimerRef.current = setTimeout(() => {
93
+ pendingTimerRef.current = null;
70
94
  if (pendingDisposerRef.current) {
71
95
  return;
72
96
  }
73
- const disposer = (0, import_reactive.autorun)(() => {
74
- var _a2, _b2, _c, _d, _e, _f;
75
- if (((_b2 = (_a2 = ctxRef.current) == null ? void 0 : _a2.pageActive) == null ? void 0 : _b2.value) && (((_d = (_c = ctxRef.current) == null ? void 0 : _c.tabActive) == null ? void 0 : _d.value) === true || ((_f = (_e = ctxRef.current) == null ? void 0 : _e.tabActive) == null ? void 0 : _f.value) === void 0)) {
97
+ if (isContextActive()) {
98
+ updater();
99
+ return;
100
+ }
101
+ pendingDisposerRef.current = (0, import_reactive.reaction)(
102
+ () => isContextActive(),
103
+ (active) => {
104
+ if (!active) {
105
+ return;
106
+ }
107
+ clearPendingDisposer();
76
108
  updater();
77
- disposer == null ? void 0 : disposer();
78
- pendingDisposerRef.current = null;
109
+ },
110
+ {
111
+ name: "FlowObserverPendingUpdate"
79
112
  }
80
- });
81
- pendingDisposerRef.current = disposer;
113
+ );
82
114
  });
83
115
  return;
84
116
  }
85
- if (pendingDisposerRef.current) {
86
- pendingDisposerRef.current();
87
- pendingDisposerRef.current = null;
88
- }
117
+ clearPendingTimer();
118
+ clearPendingDisposer();
89
119
  updater();
90
120
  },
91
121
  ...options
@@ -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
- export type RunJSVersion = 'v1' | (string & {});
9
+ export type RunJSVersion = 'v1' | 'v2' | (string & {});
10
10
  export type RunJSContextCtor = new (delegate: any) => any;
11
11
  export type RunJSContextMeta = {
12
12
  scenes?: string[];
@@ -67,19 +67,27 @@ async function setupRunJSContexts() {
67
67
  import("./contexts/JSRecordActionRunJSContext"),
68
68
  import("./contexts/JSCollectionActionRunJSContext")
69
69
  ]);
70
- const v1 = "v1";
71
- import_registry.RunJSContextRegistry.register(v1, "*", import_flowContext.FlowRunJSContext);
72
- import_registry.RunJSContextRegistry.register(v1, "JSBlockModel", JSBlockRunJSContext, { scenes: ["block"] });
73
- import_registry.RunJSContextRegistry.register(v1, "JSFieldModel", JSFieldRunJSContext, { scenes: ["detail"] });
74
- import_registry.RunJSContextRegistry.register(v1, "JSEditableFieldModel", JSEditableFieldRunJSContext, { scenes: ["form"] });
75
- import_registry.RunJSContextRegistry.register(v1, "JSItemModel", JSItemRunJSContext, { scenes: ["form"] });
76
- import_registry.RunJSContextRegistry.register(v1, "JSColumnModel", JSColumnRunJSContext, { scenes: ["table"] });
77
- import_registry.RunJSContextRegistry.register(v1, "FormJSFieldItemModel", FormJSFieldItemRunJSContext, { scenes: ["form"] });
78
- import_registry.RunJSContextRegistry.register(v1, "JSRecordActionModel", JSRecordActionRunJSContext, { scenes: ["table"] });
79
- import_registry.RunJSContextRegistry.register(v1, "JSCollectionActionModel", JSCollectionActionRunJSContext, { scenes: ["table"] });
80
- await (0, import_contributions.applyRunJSContextContributions)(v1);
70
+ const registerBuiltins = /* @__PURE__ */ __name((version) => {
71
+ import_registry.RunJSContextRegistry.register(version, "*", import_flowContext.FlowRunJSContext);
72
+ import_registry.RunJSContextRegistry.register(version, "JSBlockModel", JSBlockRunJSContext, { scenes: ["block"] });
73
+ import_registry.RunJSContextRegistry.register(version, "JSFieldModel", JSFieldRunJSContext, { scenes: ["detail"] });
74
+ import_registry.RunJSContextRegistry.register(version, "JSEditableFieldModel", JSEditableFieldRunJSContext, { scenes: ["form"] });
75
+ import_registry.RunJSContextRegistry.register(version, "JSItemModel", JSItemRunJSContext, { scenes: ["form"] });
76
+ import_registry.RunJSContextRegistry.register(version, "JSItemActionModel", JSItemRunJSContext, { scenes: ["table"] });
77
+ import_registry.RunJSContextRegistry.register(version, "JSColumnModel", JSColumnRunJSContext, { scenes: ["table"] });
78
+ import_registry.RunJSContextRegistry.register(version, "FormJSFieldItemModel", FormJSFieldItemRunJSContext, { scenes: ["form"] });
79
+ import_registry.RunJSContextRegistry.register(version, "JSRecordActionModel", JSRecordActionRunJSContext, { scenes: ["table"] });
80
+ import_registry.RunJSContextRegistry.register(version, "JSCollectionActionModel", JSCollectionActionRunJSContext, {
81
+ scenes: ["table"]
82
+ });
83
+ }, "registerBuiltins");
84
+ const versions = ["v1", "v2"];
85
+ for (const version of versions) {
86
+ registerBuiltins(version);
87
+ await (0, import_contributions.applyRunJSContextContributions)(version);
88
+ (0, import_contributions.markRunJSContextsSetupDone)(version);
89
+ }
81
90
  done = true;
82
- (0, import_contributions.markRunJSContextsSetupDone)(v1);
83
91
  }
84
92
  __name(setupRunJSContexts, "setupRunJSContexts");
85
93
  // Annotate the CommonJS export names for ESM import in node:
@@ -81,6 +81,7 @@ const snippets = {
81
81
  "scene/detail/status-tag": /* @__PURE__ */ __name(() => import("./scene/detail/status-tag.snippet"), "scene/detail/status-tag"),
82
82
  "scene/detail/relative-time": /* @__PURE__ */ __name(() => import("./scene/detail/relative-time.snippet"), "scene/detail/relative-time"),
83
83
  "scene/detail/percentage-bar": /* @__PURE__ */ __name(() => import("./scene/detail/percentage-bar.snippet"), "scene/detail/percentage-bar"),
84
+ "scene/detail/set-field-style": /* @__PURE__ */ __name(() => import("./scene/detail/set-field-style.snippet"), "scene/detail/set-field-style"),
84
85
  // scene/form
85
86
  "scene/form/render-basic": /* @__PURE__ */ __name(() => import("./scene/form/render-basic.snippet"), "scene/form/render-basic"),
86
87
  "scene/form/set-field-value": /* @__PURE__ */ __name(() => import("./scene/form/set-field-value.snippet"), "scene/form/set-field-value"),
@@ -98,7 +99,8 @@ const snippets = {
98
99
  "scene/table/collection-selected-count": /* @__PURE__ */ __name(() => import("./scene/table/collection-selected-count.snippet"), "scene/table/collection-selected-count"),
99
100
  "scene/table/iterate-selected-rows": /* @__PURE__ */ __name(() => import("./scene/table/iterate-selected-rows.snippet"), "scene/table/iterate-selected-rows"),
100
101
  "scene/table/destroy-selected": /* @__PURE__ */ __name(() => import("./scene/table/destroy-selected.snippet"), "scene/table/destroy-selected"),
101
- "scene/table/export-selected-json": /* @__PURE__ */ __name(() => import("./scene/table/export-selected-json.snippet"), "scene/table/export-selected-json")
102
+ "scene/table/export-selected-json": /* @__PURE__ */ __name(() => import("./scene/table/export-selected-json.snippet"), "scene/table/export-selected-json"),
103
+ "scene/table/set-cell-style": /* @__PURE__ */ __name(() => import("./scene/table/set-cell-style.snippet"), "scene/table/set-cell-style")
102
104
  };
103
105
  var snippets_default = snippets;
104
106
  function registerRunJSSnippet(ref, loader, options) {
@@ -131,10 +133,19 @@ function normalizeScenes(def, key) {
131
133
  return [];
132
134
  }
133
135
  __name(normalizeScenes, "normalizeScenes");
136
+ function normalizeSceneGroup(scene) {
137
+ const mapping = {
138
+ detailFieldEvent: "detail",
139
+ tableFieldEvent: "table",
140
+ formFieldEvent: "form"
141
+ };
142
+ return mapping[scene] || scene;
143
+ }
144
+ __name(normalizeSceneGroup, "normalizeSceneGroup");
134
145
  function computeGroups(def, key) {
135
146
  const scenes = normalizeScenes(def, key);
136
147
  if (scenes.length) {
137
- return scenes.map((scene) => `scene/${scene}`);
148
+ return Array.from(new Set(scenes.map((scene) => `scene/${normalizeSceneGroup(scene)}`)));
138
149
  }
139
150
  const parts = key.split("/");
140
151
  if (!parts.length) return [];