@nocobase/flow-engine 2.0.28 → 2.0.29

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.
@@ -0,0 +1,36 @@
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 { CSSProperties, RefObject } from 'react';
10
+ type ToolbarPortalPositioningMode = 'fixed' | 'absolute';
11
+ export interface ToolbarPortalRenderSnapshot {
12
+ mountElement: HTMLElement;
13
+ positioningMode: ToolbarPortalPositioningMode;
14
+ }
15
+ export interface ToolbarPortalRect {
16
+ top: number;
17
+ left: number;
18
+ width: number;
19
+ height: number;
20
+ }
21
+ interface UseFloatToolbarPortalOptions {
22
+ active: boolean;
23
+ containerRef: RefObject<HTMLDivElement>;
24
+ toolbarContainerRef: RefObject<HTMLDivElement>;
25
+ toolbarStyle?: CSSProperties;
26
+ }
27
+ interface UseFloatToolbarPortalResult {
28
+ portalRect: ToolbarPortalRect;
29
+ portalRenderSnapshot: ToolbarPortalRenderSnapshot | null;
30
+ getPopupContainer: (triggerNode?: HTMLElement) => HTMLElement;
31
+ updatePortalRect: () => void;
32
+ schedulePortalRectUpdate: () => void;
33
+ }
34
+ export declare const omitToolbarPortalInsetStyle: (toolbarStyle?: CSSProperties) => CSSProperties | undefined;
35
+ export declare const useFloatToolbarPortal: ({ active, containerRef, toolbarContainerRef, toolbarStyle, }: UseFloatToolbarPortalOptions) => UseFloatToolbarPortalResult;
36
+ export {};
@@ -0,0 +1,274 @@
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 useFloatToolbarPortal_exports = {};
29
+ __export(useFloatToolbarPortal_exports, {
30
+ omitToolbarPortalInsetStyle: () => omitToolbarPortalInsetStyle,
31
+ useFloatToolbarPortal: () => useFloatToolbarPortal
32
+ });
33
+ module.exports = __toCommonJS(useFloatToolbarPortal_exports);
34
+ var import_react = require("react");
35
+ const APP_CONTAINER_SELECTOR = "#nocobase-app-container";
36
+ const DRAWER_CONTENT_WRAPPER_SELECTOR = ".ant-drawer-content-wrapper";
37
+ const DRAWER_CONTENT_SELECTOR = ".ant-drawer-content";
38
+ const DRAWER_ROOT_SELECTOR = ".ant-drawer-root";
39
+ const MODAL_CONTENT_SELECTOR = ".ant-modal-content";
40
+ const MODAL_SELECTOR = ".ant-modal";
41
+ const MODAL_WRAP_SELECTOR = ".ant-modal-wrap";
42
+ const MODAL_ROOT_SELECTOR = ".ant-modal-root";
43
+ const defaultPortalRect = {
44
+ top: 0,
45
+ left: 0,
46
+ width: 0,
47
+ height: 0
48
+ };
49
+ const getClosestElement = /* @__PURE__ */ __name((hostEl, selector) => hostEl == null ? void 0 : hostEl.closest(selector), "getClosestElement");
50
+ const createAbsolutePortalHostConfig = /* @__PURE__ */ __name((element) => ({
51
+ mountElement: element,
52
+ positioningElement: element,
53
+ positioningMode: "absolute"
54
+ }), "createAbsolutePortalHostConfig");
55
+ const popupPortalHostResolvers = [
56
+ (hostEl) => getClosestElement(hostEl, DRAWER_CONTENT_WRAPPER_SELECTOR),
57
+ (hostEl) => getClosestElement(hostEl, MODAL_CONTENT_SELECTOR),
58
+ (hostEl) => getClosestElement(hostEl, MODAL_SELECTOR),
59
+ (hostEl) => getClosestElement(hostEl, MODAL_WRAP_SELECTOR),
60
+ (hostEl) => {
61
+ const drawerContent = getClosestElement(hostEl, DRAWER_CONTENT_SELECTOR);
62
+ return drawerContent ? getClosestElement(drawerContent, DRAWER_CONTENT_WRAPPER_SELECTOR) || drawerContent : null;
63
+ },
64
+ (hostEl) => getClosestElement(hostEl, DRAWER_ROOT_SELECTOR),
65
+ (hostEl) => getClosestElement(hostEl, MODAL_ROOT_SELECTOR)
66
+ ];
67
+ const getPopupPortalHostConfig = /* @__PURE__ */ __name((hostEl) => {
68
+ for (const resolveHost of popupPortalHostResolvers) {
69
+ const popupHost = resolveHost(hostEl);
70
+ if (popupHost) {
71
+ return createAbsolutePortalHostConfig(popupHost);
72
+ }
73
+ }
74
+ return null;
75
+ }, "getPopupPortalHostConfig");
76
+ const getToolbarPortalHostConfig = /* @__PURE__ */ __name((hostEl) => {
77
+ if (typeof document === "undefined") {
78
+ return null;
79
+ }
80
+ const popupRootConfig = getPopupPortalHostConfig(hostEl);
81
+ if (popupRootConfig) {
82
+ return popupRootConfig;
83
+ }
84
+ const appContainer = document.querySelector(APP_CONTAINER_SELECTOR);
85
+ if (appContainer) {
86
+ return createAbsolutePortalHostConfig(appContainer);
87
+ }
88
+ return {
89
+ mountElement: document.body,
90
+ positioningElement: document.body,
91
+ positioningMode: "fixed"
92
+ };
93
+ }, "getToolbarPortalHostConfig");
94
+ const parseToolbarInsetValue = /* @__PURE__ */ __name((value) => {
95
+ if (typeof value === "number" && Number.isFinite(value)) {
96
+ return value;
97
+ }
98
+ if (typeof value === "string") {
99
+ const trimmedValue = value.trim();
100
+ if (/^-?\d+(\.\d+)?(px)?$/.test(trimmedValue)) {
101
+ return Number.parseFloat(trimmedValue);
102
+ }
103
+ }
104
+ return 0;
105
+ }, "parseToolbarInsetValue");
106
+ const resolveToolbarPortalInset = /* @__PURE__ */ __name((toolbarStyle) => {
107
+ return {
108
+ top: parseToolbarInsetValue(toolbarStyle == null ? void 0 : toolbarStyle.top),
109
+ left: parseToolbarInsetValue(toolbarStyle == null ? void 0 : toolbarStyle.left),
110
+ right: parseToolbarInsetValue(toolbarStyle == null ? void 0 : toolbarStyle.right),
111
+ bottom: parseToolbarInsetValue(toolbarStyle == null ? void 0 : toolbarStyle.bottom)
112
+ };
113
+ }, "resolveToolbarPortalInset");
114
+ const getAbsolutePositioningElement = /* @__PURE__ */ __name((toolbarEl, portalHostConfig) => {
115
+ if (!portalHostConfig || portalHostConfig.positioningMode !== "absolute") {
116
+ return (portalHostConfig == null ? void 0 : portalHostConfig.positioningElement) || null;
117
+ }
118
+ const offsetParent = toolbarEl == null ? void 0 : toolbarEl.offsetParent;
119
+ if (offsetParent instanceof HTMLElement && offsetParent !== document.body && offsetParent !== document.documentElement) {
120
+ return offsetParent;
121
+ }
122
+ return portalHostConfig.positioningElement;
123
+ }, "getAbsolutePositioningElement");
124
+ const calculatePortalRect = /* @__PURE__ */ __name((hostEl, portalHostConfig, toolbarStyle, toolbarEl) => {
125
+ if (!hostEl) {
126
+ return defaultPortalRect;
127
+ }
128
+ const inset = resolveToolbarPortalInset(toolbarStyle);
129
+ const hostRect = hostEl.getBoundingClientRect();
130
+ let rect;
131
+ if (!portalHostConfig || portalHostConfig.positioningMode === "fixed") {
132
+ rect = {
133
+ top: hostRect.top,
134
+ left: hostRect.left,
135
+ width: hostRect.width,
136
+ height: hostRect.height
137
+ };
138
+ } else {
139
+ const positioningElement = getAbsolutePositioningElement(toolbarEl || null, portalHostConfig);
140
+ const portalHostRect = (positioningElement == null ? void 0 : positioningElement.getBoundingClientRect()) || portalHostConfig.positioningElement.getBoundingClientRect();
141
+ const scrollTop = (positioningElement == null ? void 0 : positioningElement.scrollTop) ?? portalHostConfig.positioningElement.scrollTop;
142
+ const scrollLeft = (positioningElement == null ? void 0 : positioningElement.scrollLeft) ?? portalHostConfig.positioningElement.scrollLeft;
143
+ rect = {
144
+ top: hostRect.top - portalHostRect.top + scrollTop,
145
+ left: hostRect.left - portalHostRect.left + scrollLeft,
146
+ width: hostRect.width,
147
+ height: hostRect.height
148
+ };
149
+ }
150
+ return {
151
+ top: rect.top + inset.top,
152
+ left: rect.left + inset.left,
153
+ width: Math.max(0, rect.width - inset.left - inset.right),
154
+ height: Math.max(0, rect.height - inset.top - inset.bottom)
155
+ };
156
+ }, "calculatePortalRect");
157
+ const omitToolbarPortalInsetStyle = /* @__PURE__ */ __name((toolbarStyle) => {
158
+ if (!toolbarStyle) {
159
+ return void 0;
160
+ }
161
+ const nextStyle = { ...toolbarStyle };
162
+ delete nextStyle.top;
163
+ delete nextStyle.left;
164
+ delete nextStyle.right;
165
+ delete nextStyle.bottom;
166
+ return nextStyle;
167
+ }, "omitToolbarPortalInsetStyle");
168
+ const useFloatToolbarPortal = /* @__PURE__ */ __name(({
169
+ active,
170
+ containerRef,
171
+ toolbarContainerRef,
172
+ toolbarStyle
173
+ }) => {
174
+ const [portalRect, setPortalRect] = (0, import_react.useState)(defaultPortalRect);
175
+ const [portalRenderSnapshot, setPortalRenderSnapshot] = (0, import_react.useState)(null);
176
+ const portalHostConfigRef = (0, import_react.useRef)(null);
177
+ const portalRafIdRef = (0, import_react.useRef)(null);
178
+ const updatePortalRect = (0, import_react.useCallback)(() => {
179
+ const hostElement = containerRef.current;
180
+ if (!hostElement) {
181
+ return;
182
+ }
183
+ const nextPortalHostConfig = getToolbarPortalHostConfig(hostElement);
184
+ portalHostConfigRef.current = nextPortalHostConfig;
185
+ setPortalRenderSnapshot((prevSnapshot) => {
186
+ if (!nextPortalHostConfig) {
187
+ return prevSnapshot === null ? prevSnapshot : null;
188
+ }
189
+ if ((prevSnapshot == null ? void 0 : prevSnapshot.mountElement) === nextPortalHostConfig.mountElement && (prevSnapshot == null ? void 0 : prevSnapshot.positioningMode) === nextPortalHostConfig.positioningMode) {
190
+ return prevSnapshot;
191
+ }
192
+ return {
193
+ mountElement: nextPortalHostConfig.mountElement,
194
+ positioningMode: nextPortalHostConfig.positioningMode
195
+ };
196
+ });
197
+ const nextRect = calculatePortalRect(hostElement, nextPortalHostConfig, toolbarStyle, toolbarContainerRef.current);
198
+ setPortalRect((prevRect) => {
199
+ if (prevRect.top === nextRect.top && prevRect.left === nextRect.left && prevRect.width === nextRect.width && prevRect.height === nextRect.height) {
200
+ return prevRect;
201
+ }
202
+ return nextRect;
203
+ });
204
+ }, [containerRef, toolbarContainerRef, toolbarStyle]);
205
+ const schedulePortalRectUpdate = (0, import_react.useCallback)(() => {
206
+ if (portalRafIdRef.current !== null) {
207
+ return;
208
+ }
209
+ portalRafIdRef.current = window.requestAnimationFrame(() => {
210
+ portalRafIdRef.current = null;
211
+ updatePortalRect();
212
+ });
213
+ }, [updatePortalRect]);
214
+ const getPopupContainer = (0, import_react.useCallback)(
215
+ (triggerNode) => {
216
+ var _a, _b, _c, _d, _e;
217
+ const fallbackContainer = ((_a = triggerNode == null ? void 0 : triggerNode.ownerDocument) == null ? void 0 : _a.body) || ((_c = (_b = containerRef.current) == null ? void 0 : _b.ownerDocument) == null ? void 0 : _c.body) || (typeof document !== "undefined" ? document.body : null);
218
+ return ((_d = portalHostConfigRef.current) == null ? void 0 : _d.mountElement) || ((_e = getToolbarPortalHostConfig(triggerNode || containerRef.current)) == null ? void 0 : _e.mountElement) || fallbackContainer;
219
+ },
220
+ [containerRef]
221
+ );
222
+ (0, import_react.useEffect)(() => {
223
+ var _a, _b;
224
+ if (!active) {
225
+ return;
226
+ }
227
+ updatePortalRect();
228
+ const handleViewportChange = /* @__PURE__ */ __name(() => {
229
+ schedulePortalRectUpdate();
230
+ }, "handleViewportChange");
231
+ const container = containerRef.current;
232
+ const mountElement = (_a = portalHostConfigRef.current) == null ? void 0 : _a.mountElement;
233
+ const positioningElement = (_b = portalHostConfigRef.current) == null ? void 0 : _b.positioningElement;
234
+ const resizeObserver = typeof ResizeObserver !== "undefined" && container ? new ResizeObserver(() => {
235
+ schedulePortalRectUpdate();
236
+ }) : null;
237
+ if (container) {
238
+ resizeObserver == null ? void 0 : resizeObserver.observe(container);
239
+ }
240
+ if (mountElement && mountElement !== container) {
241
+ resizeObserver == null ? void 0 : resizeObserver.observe(mountElement);
242
+ }
243
+ if (positioningElement && positioningElement !== container && positioningElement !== mountElement) {
244
+ resizeObserver == null ? void 0 : resizeObserver.observe(positioningElement);
245
+ }
246
+ window.addEventListener("resize", handleViewportChange);
247
+ window.addEventListener("scroll", handleViewportChange, true);
248
+ return () => {
249
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
250
+ window.removeEventListener("resize", handleViewportChange);
251
+ window.removeEventListener("scroll", handleViewportChange, true);
252
+ };
253
+ }, [active, containerRef, schedulePortalRectUpdate, updatePortalRect]);
254
+ (0, import_react.useEffect)(() => {
255
+ return () => {
256
+ if (portalRafIdRef.current !== null) {
257
+ window.cancelAnimationFrame(portalRafIdRef.current);
258
+ }
259
+ portalHostConfigRef.current = null;
260
+ };
261
+ }, []);
262
+ return {
263
+ portalRect,
264
+ portalRenderSnapshot,
265
+ getPopupContainer,
266
+ updatePortalRect,
267
+ schedulePortalRectUpdate
268
+ };
269
+ }, "useFloatToolbarPortal");
270
+ // Annotate the CommonJS export names for ESM import in node:
271
+ 0 && (module.exports = {
272
+ omitToolbarPortalInsetStyle,
273
+ useFloatToolbarPortal
274
+ });
@@ -0,0 +1,30 @@
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 { MouseEvent as ReactMouseEvent, RefObject } from 'react';
10
+ interface UseFloatToolbarVisibilityOptions {
11
+ modelUid: string;
12
+ containerRef: RefObject<HTMLDivElement>;
13
+ toolbarContainerRef: RefObject<HTMLDivElement>;
14
+ updatePortalRect: () => void;
15
+ schedulePortalRectUpdate: () => void;
16
+ }
17
+ interface UseFloatToolbarVisibilityResult {
18
+ isToolbarVisible: boolean;
19
+ shouldRenderToolbar: boolean;
20
+ handleSettingsMenuOpenChange: (open: boolean) => void;
21
+ handleChildHover: (e: ReactMouseEvent) => void;
22
+ handleHostMouseEnter: () => void;
23
+ handleHostMouseLeave: (e: ReactMouseEvent<HTMLDivElement>) => void;
24
+ handleToolbarMouseEnter: () => void;
25
+ handleToolbarMouseLeave: (e: ReactMouseEvent<HTMLDivElement>) => void;
26
+ handleResizeDragStart: () => void;
27
+ handleResizeDragEnd: () => void;
28
+ }
29
+ export declare const useFloatToolbarVisibility: ({ modelUid, containerRef, toolbarContainerRef, updatePortalRect, schedulePortalRectUpdate, }: UseFloatToolbarVisibilityOptions) => UseFloatToolbarVisibilityResult;
30
+ export {};
@@ -0,0 +1,247 @@
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 useFloatToolbarVisibility_exports = {};
29
+ __export(useFloatToolbarVisibility_exports, {
30
+ useFloatToolbarVisibility: () => useFloatToolbarVisibility
31
+ });
32
+ module.exports = __toCommonJS(useFloatToolbarVisibility_exports);
33
+ var import_react = require("react");
34
+ const TOOLBAR_HIDE_DELAY = 180;
35
+ const CHILD_FLOAT_MENU_ACTIVITY_EVENT = "nb-float-menu-child-activity";
36
+ const isNodeWithin = /* @__PURE__ */ __name((target, container) => {
37
+ return target instanceof Node && !!(container == null ? void 0 : container.contains(target));
38
+ }, "isNodeWithin");
39
+ const getToolbarModelUidFromTarget = /* @__PURE__ */ __name((target) => {
40
+ var _a;
41
+ if (!(target instanceof Element)) {
42
+ return null;
43
+ }
44
+ return ((_a = target.closest(".nb-toolbar-container[data-model-uid]")) == null ? void 0 : _a.getAttribute("data-model-uid")) || null;
45
+ }, "getToolbarModelUidFromTarget");
46
+ const isNodeWithinDescendantFloatToolbar = /* @__PURE__ */ __name((target, container, currentModelUid) => {
47
+ const targetModelUid = getToolbarModelUidFromTarget(target);
48
+ if (!container || !targetModelUid || targetModelUid === currentModelUid) {
49
+ return false;
50
+ }
51
+ return Array.from(
52
+ container.querySelectorAll('[data-has-float-menu="true"][data-float-menu-model-uid]')
53
+ ).some(
54
+ (hostElement) => hostElement !== container && hostElement.getAttribute("data-float-menu-model-uid") === targetModelUid
55
+ );
56
+ }, "isNodeWithinDescendantFloatToolbar");
57
+ const useFloatToolbarVisibility = /* @__PURE__ */ __name(({
58
+ modelUid,
59
+ containerRef,
60
+ toolbarContainerRef,
61
+ updatePortalRect,
62
+ schedulePortalRectUpdate
63
+ }) => {
64
+ const [hideMenu, setHideMenu] = (0, import_react.useState)(false);
65
+ const [isHostHovered, setIsHostHovered] = (0, import_react.useState)(false);
66
+ const [isToolbarHovered, setIsToolbarHovered] = (0, import_react.useState)(false);
67
+ const [isDraggingToolbar, setIsDraggingToolbar] = (0, import_react.useState)(false);
68
+ const [isToolbarPinned, setIsToolbarPinned] = (0, import_react.useState)(false);
69
+ const [isHidePending, setIsHidePending] = (0, import_react.useState)(false);
70
+ const [activeChildToolbarIds, setActiveChildToolbarIds] = (0, import_react.useState)([]);
71
+ const hideToolbarTimerRef = (0, import_react.useRef)(null);
72
+ const reportedChildActivityToAncestorsRef = (0, import_react.useRef)(false);
73
+ const hasActiveChildToolbar = activeChildToolbarIds.length > 0;
74
+ const isToolbarVisible = !hideMenu && !hasActiveChildToolbar && (isHostHovered || isToolbarHovered || isDraggingToolbar || isToolbarPinned);
75
+ const shouldRenderToolbar = isToolbarVisible || isToolbarPinned || isDraggingToolbar;
76
+ const isToolbarInteractionActive = isHostHovered || isToolbarHovered || isDraggingToolbar || isToolbarPinned || isHidePending;
77
+ const clearHideToolbarTimer = (0, import_react.useCallback)(() => {
78
+ if (hideToolbarTimerRef.current !== null) {
79
+ window.clearTimeout(hideToolbarTimerRef.current);
80
+ hideToolbarTimerRef.current = null;
81
+ }
82
+ setIsHidePending(false);
83
+ }, []);
84
+ const scheduleHideToolbar = (0, import_react.useCallback)(() => {
85
+ clearHideToolbarTimer();
86
+ setIsHidePending(true);
87
+ hideToolbarTimerRef.current = window.setTimeout(() => {
88
+ hideToolbarTimerRef.current = null;
89
+ setIsHidePending(false);
90
+ if (isDraggingToolbar || isToolbarPinned) {
91
+ return;
92
+ }
93
+ setIsHostHovered(false);
94
+ setIsToolbarHovered(false);
95
+ }, TOOLBAR_HIDE_DELAY);
96
+ }, [clearHideToolbarTimer, isDraggingToolbar, isToolbarPinned]);
97
+ const handleSettingsMenuOpenChange = (0, import_react.useCallback)((open) => {
98
+ setIsToolbarPinned(open);
99
+ }, []);
100
+ (0, import_react.useEffect)(() => {
101
+ const hostElement = containerRef.current;
102
+ if (!hostElement) {
103
+ return;
104
+ }
105
+ const handleChildToolbarActivity = /* @__PURE__ */ __name((event) => {
106
+ var _a;
107
+ const customEvent = event;
108
+ if (!(customEvent.target instanceof HTMLElement) || customEvent.target === hostElement) {
109
+ return;
110
+ }
111
+ const childModelUid = (_a = customEvent.detail) == null ? void 0 : _a.modelUid;
112
+ if (!childModelUid) {
113
+ return;
114
+ }
115
+ setActiveChildToolbarIds((prevIds) => {
116
+ var _a2;
117
+ return ((_a2 = customEvent.detail) == null ? void 0 : _a2.active) ? prevIds.includes(childModelUid) ? prevIds : [...prevIds, childModelUid] : prevIds.filter((id) => id !== childModelUid);
118
+ });
119
+ }, "handleChildToolbarActivity");
120
+ hostElement.addEventListener(CHILD_FLOAT_MENU_ACTIVITY_EVENT, handleChildToolbarActivity);
121
+ return () => {
122
+ hostElement.removeEventListener(CHILD_FLOAT_MENU_ACTIVITY_EVENT, handleChildToolbarActivity);
123
+ };
124
+ }, [containerRef]);
125
+ (0, import_react.useEffect)(() => {
126
+ const hostElement = containerRef.current;
127
+ if (!hostElement || reportedChildActivityToAncestorsRef.current === isToolbarInteractionActive) {
128
+ return;
129
+ }
130
+ reportedChildActivityToAncestorsRef.current = isToolbarInteractionActive;
131
+ hostElement.dispatchEvent(
132
+ new CustomEvent(CHILD_FLOAT_MENU_ACTIVITY_EVENT, {
133
+ bubbles: true,
134
+ detail: { active: isToolbarInteractionActive, modelUid }
135
+ })
136
+ );
137
+ }, [containerRef, isToolbarInteractionActive, modelUid]);
138
+ (0, import_react.useEffect)(() => {
139
+ const hostElement = containerRef.current;
140
+ return () => {
141
+ if (hostElement && reportedChildActivityToAncestorsRef.current) {
142
+ hostElement.dispatchEvent(
143
+ new CustomEvent(CHILD_FLOAT_MENU_ACTIVITY_EVENT, {
144
+ bubbles: true,
145
+ detail: { active: false, modelUid }
146
+ })
147
+ );
148
+ reportedChildActivityToAncestorsRef.current = false;
149
+ }
150
+ clearHideToolbarTimer();
151
+ };
152
+ }, [clearHideToolbarTimer, containerRef, modelUid]);
153
+ (0, import_react.useEffect)(() => {
154
+ if (isToolbarPinned) {
155
+ clearHideToolbarTimer();
156
+ updatePortalRect();
157
+ }
158
+ }, [clearHideToolbarTimer, isToolbarPinned, updatePortalRect]);
159
+ const handleChildHover = (0, import_react.useCallback)(
160
+ (e) => {
161
+ const target = e.target;
162
+ const childWithMenu = target.closest("[data-has-float-menu]");
163
+ const isCurrentHostTarget = !childWithMenu || childWithMenu === containerRef.current;
164
+ if (isCurrentHostTarget) {
165
+ clearHideToolbarTimer();
166
+ setIsHostHovered(true);
167
+ }
168
+ setHideMenu(!!childWithMenu && childWithMenu !== containerRef.current);
169
+ },
170
+ [clearHideToolbarTimer, containerRef]
171
+ );
172
+ const handleHostMouseEnter = (0, import_react.useCallback)(() => {
173
+ clearHideToolbarTimer();
174
+ setHideMenu(false);
175
+ updatePortalRect();
176
+ setIsHostHovered(true);
177
+ }, [clearHideToolbarTimer, updatePortalRect]);
178
+ const handleHostMouseLeave = (0, import_react.useCallback)(
179
+ (e) => {
180
+ if (isToolbarPinned) {
181
+ setIsHostHovered(false);
182
+ return;
183
+ }
184
+ if (isNodeWithin(e.relatedTarget, toolbarContainerRef.current)) {
185
+ clearHideToolbarTimer();
186
+ setIsHostHovered(false);
187
+ setIsToolbarHovered(true);
188
+ return;
189
+ }
190
+ if (isNodeWithinDescendantFloatToolbar(e.relatedTarget, containerRef.current, modelUid)) {
191
+ clearHideToolbarTimer();
192
+ setHideMenu(false);
193
+ setIsHostHovered(true);
194
+ return;
195
+ }
196
+ scheduleHideToolbar();
197
+ },
198
+ [clearHideToolbarTimer, containerRef, isToolbarPinned, modelUid, scheduleHideToolbar, toolbarContainerRef]
199
+ );
200
+ const handleToolbarMouseEnter = (0, import_react.useCallback)(() => {
201
+ clearHideToolbarTimer();
202
+ updatePortalRect();
203
+ setIsHostHovered(false);
204
+ setIsToolbarHovered(true);
205
+ }, [clearHideToolbarTimer, updatePortalRect]);
206
+ const handleToolbarMouseLeave = (0, import_react.useCallback)(
207
+ (e) => {
208
+ if (isToolbarPinned) {
209
+ setIsToolbarHovered(false);
210
+ return;
211
+ }
212
+ setIsToolbarHovered(false);
213
+ if (isNodeWithin(e.relatedTarget, containerRef.current)) {
214
+ clearHideToolbarTimer();
215
+ setIsHostHovered(true);
216
+ return;
217
+ }
218
+ scheduleHideToolbar();
219
+ },
220
+ [clearHideToolbarTimer, containerRef, isToolbarPinned, scheduleHideToolbar]
221
+ );
222
+ const handleResizeDragStart = (0, import_react.useCallback)(() => {
223
+ updatePortalRect();
224
+ setIsDraggingToolbar(true);
225
+ schedulePortalRectUpdate();
226
+ }, [schedulePortalRectUpdate, updatePortalRect]);
227
+ const handleResizeDragEnd = (0, import_react.useCallback)(() => {
228
+ setIsDraggingToolbar(false);
229
+ schedulePortalRectUpdate();
230
+ }, [schedulePortalRectUpdate]);
231
+ return {
232
+ isToolbarVisible,
233
+ shouldRenderToolbar,
234
+ handleSettingsMenuOpenChange,
235
+ handleChildHover,
236
+ handleHostMouseEnter,
237
+ handleHostMouseLeave,
238
+ handleToolbarMouseEnter,
239
+ handleToolbarMouseLeave,
240
+ handleResizeDragStart,
241
+ handleResizeDragEnd
242
+ };
243
+ }, "useFloatToolbarVisibility");
244
+ // Annotate the CommonJS export names for ESM import in node:
245
+ 0 && (module.exports = {
246
+ useFloatToolbarVisibility
247
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.0.28",
3
+ "version": "2.0.29",
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.0.28",
12
- "@nocobase/shared": "2.0.28",
11
+ "@nocobase/sdk": "2.0.29",
12
+ "@nocobase/shared": "2.0.29",
13
13
  "ahooks": "^3.7.2",
14
14
  "dayjs": "^1.11.9",
15
15
  "dompurify": "^3.0.2",
@@ -36,5 +36,5 @@
36
36
  ],
37
37
  "author": "NocoBase Team",
38
38
  "license": "Apache-2.0",
39
- "gitHead": "7a3e96a74b05f2beaa5a87d8ef28ccf269ea90f4"
39
+ "gitHead": "c623e8be68bb2f8d730c30d2de6ab55e24d0861a"
40
40
  }
@@ -69,7 +69,7 @@ export interface FlowModelRendererProps {
69
69
  showBackground?: boolean;
70
70
  showBorder?: boolean;
71
71
  showDragHandle?: boolean;
72
- /** 自定义工具栏样式 */
72
+ /** 自定义工具栏样式,`top/left/right/bottom` 会作为 portal overlay 的 inset 使用 */
73
73
  style?: React.CSSProperties;
74
74
  /**
75
75
  * @default 'inside'
@@ -112,6 +112,7 @@ const FlowModelRendererWithAutoFlows: React.FC<{
112
112
  showBackground?: boolean;
113
113
  showBorder?: boolean;
114
114
  showDragHandle?: boolean;
115
+ /** `top/left/right/bottom` 会作为 portal overlay 的 inset 使用 */
115
116
  style?: React.CSSProperties;
116
117
  /**
117
118
  * @default 'inside'
@@ -182,6 +183,7 @@ const FlowModelRendererCore: React.FC<{
182
183
  showBackground?: boolean;
183
184
  showBorder?: boolean;
184
185
  showDragHandle?: boolean;
186
+ /** `top/left/right/bottom` 会作为 portal overlay 的 inset 使用 */
185
187
  style?: React.CSSProperties;
186
188
  /**
187
189
  * @default 'inside'