@nocobase/flow-engine 2.1.0-beta.11 → 2.1.0-beta.12

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 (36) hide show
  1. package/lib/components/FlowModelRenderer.d.ts +1 -1
  2. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
  3. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +48 -9
  4. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +19 -43
  5. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +332 -296
  6. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.d.ts +36 -0
  7. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +272 -0
  8. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
  9. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +247 -0
  10. package/lib/components/subModel/AddSubModelButton.js +11 -0
  11. package/lib/flowContext.js +27 -0
  12. package/lib/runjs-context/setup.js +1 -0
  13. package/lib/runjs-context/snippets/index.js +13 -2
  14. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts +11 -0
  15. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.js +50 -0
  16. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts +11 -0
  17. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
  18. package/package.json +5 -4
  19. package/src/__tests__/flowContext.test.ts +65 -1
  20. package/src/__tests__/runjsContext.test.ts +3 -0
  21. package/src/__tests__/runjsContextRuntime.test.ts +2 -0
  22. package/src/__tests__/runjsSnippets.test.ts +21 -0
  23. package/src/components/FlowModelRenderer.tsx +3 -1
  24. package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +17 -7
  25. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +63 -9
  26. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +457 -440
  27. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +95 -0
  28. package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +547 -0
  29. package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +358 -0
  30. package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +281 -0
  31. package/src/components/subModel/AddSubModelButton.tsx +15 -1
  32. package/src/flowContext.ts +30 -0
  33. package/src/runjs-context/setup.ts +1 -0
  34. package/src/runjs-context/snippets/index.ts +12 -1
  35. package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
  36. package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
@@ -19,7 +19,7 @@ export interface FlowModelRendererProps {
19
19
  showBackground?: boolean;
20
20
  showBorder?: boolean;
21
21
  showDragHandle?: boolean;
22
- /** 自定义工具栏样式 */
22
+ /** 自定义工具栏样式,`top/left/right/bottom` 会作为 portal overlay 的 inset 使用 */
23
23
  style?: React.CSSProperties;
24
24
  /**
25
25
  * @default 'inside'
@@ -6,6 +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 type { DropdownProps } from 'antd';
9
10
  import React from 'react';
10
11
  import { FlowModel } from '../../../../models';
11
12
  /**
@@ -18,6 +19,8 @@ interface DefaultSettingsIconProps {
18
19
  showCopyUidButton?: boolean;
19
20
  menuLevels?: number;
20
21
  flattenSubMenus?: boolean;
22
+ onDropdownVisibleChange?: (open: boolean) => void;
23
+ getPopupContainer?: DropdownProps['getPopupContainer'];
21
24
  [key: string]: any;
22
25
  }
23
26
  export declare const DefaultSettingsIcon: React.FC<DefaultSettingsIconProps>;
@@ -41,6 +41,7 @@ __export(DefaultSettingsIcon_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(DefaultSettingsIcon_exports);
43
43
  var import_icons = require("@ant-design/icons");
44
+ var import_css = require("@emotion/css");
44
45
  var import_antd = require("antd");
45
46
  var import_react = __toESM(require("react"));
46
47
  var import_models = require("../../../../models");
@@ -149,13 +150,32 @@ const MenuLabelItem = /* @__PURE__ */ __name(({ title, uiMode, itemProps }) => {
149
150
  }
150
151
  return /* @__PURE__ */ import_react.default.createElement("span", { style: { display: "inline-flex", alignItems: "center", gap: 6 } }, content, /* @__PURE__ */ import_react.default.createElement(import_antd.Tooltip, { title: disabledReason, placement: "right", destroyTooltipOnHide: true }, /* @__PURE__ */ import_react.default.createElement(import_icons.QuestionCircleOutlined, { style: { color: disabledIconColor } })));
151
152
  }, "MenuLabelItem");
153
+ const TOOLBAR_ICONS_SELECTOR = ".nb-toolbar-container-icons";
154
+ const TOOLBAR_CONTAINER_SELECTOR = ".nb-toolbar-container";
155
+ const TOOLBAR_DROPDOWN_OVERLAY_CLASS = import_css.css`
156
+ width: max-content;
157
+ min-width: max-content;
158
+
159
+ .ant-dropdown-menu {
160
+ width: max-content;
161
+ min-width: max-content;
162
+ }
163
+ `;
164
+ const getToolbarPopupContainer = /* @__PURE__ */ __name((triggerNode) => {
165
+ if (!triggerNode) {
166
+ return null;
167
+ }
168
+ return triggerNode.closest(TOOLBAR_ICONS_SELECTOR) || triggerNode.closest(TOOLBAR_CONTAINER_SELECTOR);
169
+ }, "getToolbarPopupContainer");
152
170
  const DefaultSettingsIcon = /* @__PURE__ */ __name(({
153
171
  model,
154
172
  showDeleteButton = true,
155
173
  showCopyUidButton = true,
156
174
  menuLevels = 1,
157
175
  // 默认一级菜单
158
- flattenSubMenus = true
176
+ flattenSubMenus = true,
177
+ onDropdownVisibleChange,
178
+ getPopupContainer
159
179
  }) => {
160
180
  const { message } = import_antd.App.useApp();
161
181
  const t = (0, import_react.useMemo)(() => (0, import_utils.getT)(model), [model]);
@@ -168,14 +188,30 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
168
188
  const [isLoading, setIsLoading] = (0, import_react.useState)(true);
169
189
  const closeDropdown = (0, import_react.useCallback)(() => {
170
190
  setVisible(false);
171
- }, []);
172
- const handleOpenChange = (0, import_react.useCallback)((nextOpen, info) => {
173
- if (info.source === "trigger" || nextOpen) {
174
- (0, import_react.startTransition)(() => {
175
- setVisible(nextOpen);
176
- });
177
- }
178
- }, []);
191
+ onDropdownVisibleChange == null ? void 0 : onDropdownVisibleChange(false);
192
+ }, [onDropdownVisibleChange]);
193
+ const resolvePopupContainer = (0, import_react.useCallback)(
194
+ (triggerNode) => {
195
+ return getToolbarPopupContainer(triggerNode) || (getPopupContainer == null ? void 0 : getPopupContainer(triggerNode)) || (triggerNode == null ? void 0 : triggerNode.parentElement) || document.body;
196
+ },
197
+ [getPopupContainer]
198
+ );
199
+ const handleOpenChange = (0, import_react.useCallback)(
200
+ (nextOpen, info) => {
201
+ if (info.source === "trigger" || nextOpen) {
202
+ (0, import_react.startTransition)(() => {
203
+ setVisible(nextOpen);
204
+ });
205
+ onDropdownVisibleChange == null ? void 0 : onDropdownVisibleChange(nextOpen);
206
+ }
207
+ },
208
+ [onDropdownVisibleChange]
209
+ );
210
+ (0, import_react.useEffect)(() => {
211
+ return () => {
212
+ onDropdownVisibleChange == null ? void 0 : onDropdownVisibleChange(false);
213
+ };
214
+ }, [onDropdownVisibleChange]);
179
215
  const dropdownMaxHeight = (0, import_hooks.useNiceDropdownMaxHeight)([visible]);
180
216
  (0, import_react.useEffect)(() => {
181
217
  let mounted = true;
@@ -671,6 +707,9 @@ const DefaultSettingsIcon = /* @__PURE__ */ __name(({
671
707
  return /* @__PURE__ */ import_react.default.createElement(
672
708
  import_antd.Dropdown,
673
709
  {
710
+ getPopupContainer: resolvePopupContainer,
711
+ overlayClassName: TOOLBAR_DROPDOWN_OVERLAY_CLASS,
712
+ overlayStyle: { width: "max-content", minWidth: "max-content" },
674
713
  onOpenChange: handleOpenChange,
675
714
  open: visible,
676
715
  menu: {
@@ -9,13 +9,14 @@
9
9
  import React from 'react';
10
10
  import { FlowModel } from '../../../../models';
11
11
  import { ToolbarItemConfig } from '../../../../types';
12
- interface ModelProvidedProps {
13
- model: FlowModel<any>;
12
+ type ToolbarPosition = 'inside' | 'above' | 'below';
13
+ interface BaseFloatContextMenuProps {
14
14
  children?: React.ReactNode;
15
15
  enabled?: boolean;
16
16
  showDeleteButton?: boolean;
17
17
  showCopyUidButton?: boolean;
18
18
  containerStyle?: React.CSSProperties;
19
+ /** 自定义工具栏样式,`top/left/right/bottom` 会作为 portal overlay 的 inset 使用。 */
19
20
  toolbarStyle?: React.CSSProperties;
20
21
  className?: string;
21
22
  /**
@@ -45,65 +46,40 @@ interface ModelProvidedProps {
45
46
  /**
46
47
  * @default 'inside'
47
48
  */
48
- toolbarPosition?: 'inside' | 'above' | 'below';
49
+ toolbarPosition?: ToolbarPosition;
50
+ }
51
+ interface ModelProvidedProps extends BaseFloatContextMenuProps {
52
+ model: FlowModel<any>;
49
53
  }
50
- interface ModelByIdProps {
54
+ interface ModelByIdProps extends BaseFloatContextMenuProps {
51
55
  uid: string;
52
56
  modelClassName: string;
53
- children?: React.ReactNode;
54
- enabled?: boolean;
55
- showDeleteButton?: boolean;
56
- showCopyUidButton?: boolean;
57
- containerStyle?: React.CSSProperties;
58
- className?: string;
59
- /**
60
- * @default true
61
- */
62
- showBorder?: boolean;
63
- /**
64
- * @default true
65
- */
66
- showBackground?: boolean;
67
- /**
68
- * @default false
69
- */
70
- showTitle?: boolean;
71
- /**
72
- * Settings menu levels: 1=current model only (default), 2=include sub-models
73
- */
74
- settingsMenuLevel?: number;
75
- /**
76
- * Extra toolbar items to add to this context menu instance
77
- */
78
- extraToolbarItems?: ToolbarItemConfig[];
79
- /**
80
- * @default 'inside'
81
- */
82
- toolbarPosition?: 'inside' | 'above' | 'below';
83
57
  }
84
58
  type FlowsFloatContextMenuProps = ModelProvidedProps | ModelByIdProps;
85
59
  /**
86
- * FlowsFloatContextMenu组件 - 悬浮配置图标组件
60
+ * FlowsFloatContextMenu组件 - 悬浮配置工具栏组件
87
61
  *
88
62
  * 功能特性:
89
63
  * - 鼠标悬浮显示右上角配置图标
90
64
  * - 点击图标显示配置菜单
91
65
  * - 支持删除功能
92
66
  * - Wrapper 模式支持
93
- * - 使用与 NocoBase x-settings 一致的样式
94
- * - 按flow分组显示steps
67
+ * - 使用 portal overlay 避免被宿主或祖先裁剪
68
+ * - 设置菜单与工具栏共享同一个 popup 容器
95
69
  *
96
70
  * 支持两种使用方式:
97
- * 1. 直接提供model: <FlowsFloatContextMenu model={myModel}>{children}</FlowsFloatContextMenu>
98
- * 2. 通过uid和modelClassName获取model: <FlowsFloatContextMenu uid="model1" modelClassName="MyModel">{children}</FlowsFloatContextMenu>
71
+ * 1. 直接提供 model: `<FlowsFloatContextMenu model={myModel}>{children}</FlowsFloatContextMenu>`
72
+ * 2. 通过 uid modelClassName 获取 model:
73
+ * `<FlowsFloatContextMenu uid="model1" modelClassName="MyModel">{children}</FlowsFloatContextMenu>`
99
74
  *
100
75
  * @param props.children 子组件,必须提供
101
- * @param props.enabled 是否启用悬浮菜单,默认为true
102
- * @param props.showDeleteButton 是否显示删除按钮,默认为true
103
- * @param props.showCopyUidButton 是否显示复制UID按钮,默认为true
76
+ * @param props.enabled 是否启用悬浮菜单,默认为 true
77
+ * @param props.showDeleteButton 是否显示删除按钮,默认为 true
78
+ * @param props.showCopyUidButton 是否显示复制 UID 按钮,默认为 true
104
79
  * @param props.containerStyle 容器自定义样式
80
+ * @param props.toolbarStyle 工具栏自定义样式;`top/left/right/bottom` 会作为 portal overlay 的 inset 使用
105
81
  * @param props.className 容器自定义类名
106
- * @param props.showTitle 是否在边框左上角显示模型title,默认为false
82
+ * @param props.showTitle 是否在边框左上角显示模型 title,默认为 false
107
83
  * @param props.settingsMenuLevel 设置菜单层级:1=仅当前模型(默认),2=包含子模型
108
84
  * @param props.extraToolbarItems 额外的工具栏项目,仅应用于此实例
109
85
  */