@nocobase/flow-engine 2.1.0-beta.9 → 2.1.1

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 (215) hide show
  1. package/lib/FlowContextProvider.d.ts +5 -1
  2. package/lib/FlowContextProvider.js +9 -2
  3. package/lib/components/FieldModelRenderer.js +2 -2
  4. package/lib/components/FlowModelRenderer.d.ts +3 -1
  5. package/lib/components/FlowModelRenderer.js +12 -6
  6. package/lib/components/FormItem.d.ts +6 -0
  7. package/lib/components/FormItem.js +11 -3
  8. package/lib/components/MobilePopup.js +6 -5
  9. package/lib/components/dnd/gridDragPlanner.d.ts +59 -2
  10. package/lib/components/dnd/gridDragPlanner.js +607 -19
  11. package/lib/components/dnd/index.d.ts +31 -2
  12. package/lib/components/dnd/index.js +244 -23
  13. package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +2 -1
  14. package/lib/components/settings/wrappers/component/SelectWithTitle.js +14 -12
  15. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
  16. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +152 -42
  17. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +23 -43
  18. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +352 -295
  19. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.d.ts +36 -0
  20. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +274 -0
  21. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
  22. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +315 -0
  23. package/lib/components/subModel/AddSubModelButton.js +12 -1
  24. package/lib/components/subModel/LazyDropdown.js +301 -52
  25. package/lib/components/subModel/index.d.ts +1 -0
  26. package/lib/components/subModel/index.js +19 -0
  27. package/lib/components/subModel/utils.d.ts +2 -1
  28. package/lib/components/subModel/utils.js +15 -5
  29. package/lib/components/variables/VariableHybridInput.d.ts +27 -0
  30. package/lib/components/variables/VariableHybridInput.js +499 -0
  31. package/lib/components/variables/index.d.ts +2 -0
  32. package/lib/components/variables/index.js +3 -0
  33. package/lib/data-source/index.d.ts +84 -0
  34. package/lib/data-source/index.js +269 -7
  35. package/lib/executor/FlowExecutor.js +6 -3
  36. package/lib/flow-registry/DetachedFlowRegistry.d.ts +21 -0
  37. package/lib/flow-registry/DetachedFlowRegistry.js +80 -0
  38. package/lib/flow-registry/index.d.ts +1 -0
  39. package/lib/flow-registry/index.js +3 -1
  40. package/lib/flowContext.d.ts +9 -1
  41. package/lib/flowContext.js +77 -6
  42. package/lib/flowEngine.d.ts +136 -4
  43. package/lib/flowEngine.js +429 -51
  44. package/lib/flowI18n.js +2 -1
  45. package/lib/flowSettings.d.ts +14 -6
  46. package/lib/flowSettings.js +34 -6
  47. package/lib/index.d.ts +2 -0
  48. package/lib/index.js +7 -0
  49. package/lib/lazy-helper.d.ts +14 -0
  50. package/lib/lazy-helper.js +71 -0
  51. package/lib/locale/en-US.json +1 -0
  52. package/lib/locale/index.d.ts +2 -0
  53. package/lib/locale/zh-CN.json +1 -0
  54. package/lib/models/DisplayItemModel.d.ts +1 -1
  55. package/lib/models/EditableItemModel.d.ts +1 -1
  56. package/lib/models/FilterableItemModel.d.ts +1 -1
  57. package/lib/models/flowModel.d.ts +13 -10
  58. package/lib/models/flowModel.js +126 -34
  59. package/lib/provider.js +38 -23
  60. package/lib/reactive/observer.js +46 -16
  61. package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +4 -3
  62. package/lib/runjs-context/contexts/JSBlockRunJSContext.js +4 -15
  63. package/lib/runjs-context/contexts/JSColumnRunJSContext.js +5 -2
  64. package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +5 -8
  65. package/lib/runjs-context/contexts/JSFieldRunJSContext.js +4 -3
  66. package/lib/runjs-context/contexts/JSItemRunJSContext.js +4 -3
  67. package/lib/runjs-context/contexts/base.js +464 -29
  68. package/lib/runjs-context/contexts/elementDoc.d.ts +11 -0
  69. package/lib/runjs-context/contexts/elementDoc.js +152 -0
  70. package/lib/runjs-context/setup.js +1 -0
  71. package/lib/runjs-context/snippets/index.js +13 -2
  72. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts +11 -0
  73. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.js +50 -0
  74. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts +11 -0
  75. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
  76. package/lib/types.d.ts +50 -2
  77. package/lib/types.js +1 -0
  78. package/lib/utils/createCollectionContextMeta.js +6 -2
  79. package/lib/utils/index.d.ts +3 -2
  80. package/lib/utils/index.js +7 -0
  81. package/lib/utils/loadedPageCache.d.ts +24 -0
  82. package/lib/utils/loadedPageCache.js +139 -0
  83. package/lib/utils/parsePathnameToViewParams.d.ts +5 -1
  84. package/lib/utils/parsePathnameToViewParams.js +28 -4
  85. package/lib/utils/randomId.d.ts +39 -0
  86. package/lib/utils/randomId.js +45 -0
  87. package/lib/utils/runjsTemplateCompat.js +1 -1
  88. package/lib/utils/runjsValue.js +41 -11
  89. package/lib/utils/schema-utils.d.ts +7 -1
  90. package/lib/utils/schema-utils.js +19 -0
  91. package/lib/views/FlowView.d.ts +7 -1
  92. package/lib/views/FlowView.js +11 -1
  93. package/lib/views/PageComponent.js +8 -6
  94. package/lib/views/ViewNavigation.d.ts +12 -2
  95. package/lib/views/ViewNavigation.js +28 -9
  96. package/lib/views/createViewMeta.js +114 -50
  97. package/lib/views/inheritLayoutContext.d.ts +10 -0
  98. package/lib/views/inheritLayoutContext.js +50 -0
  99. package/lib/views/runViewBeforeClose.d.ts +10 -0
  100. package/lib/views/runViewBeforeClose.js +45 -0
  101. package/lib/views/useDialog.d.ts +2 -1
  102. package/lib/views/useDialog.js +12 -3
  103. package/lib/views/useDrawer.d.ts +2 -1
  104. package/lib/views/useDrawer.js +12 -3
  105. package/lib/views/usePage.d.ts +5 -11
  106. package/lib/views/usePage.js +304 -144
  107. package/package.json +5 -4
  108. package/src/FlowContextProvider.tsx +9 -1
  109. package/src/__tests__/createViewMeta.popup.test.ts +115 -1
  110. package/src/__tests__/flow-engine.test.ts +166 -0
  111. package/src/__tests__/flowContext.test.ts +105 -1
  112. package/src/__tests__/flowEngine.modelLoaders.test.ts +245 -0
  113. package/src/__tests__/flowEngine.moveModel.test.ts +81 -1
  114. package/src/__tests__/flowEngine.removeModel.test.ts +47 -3
  115. package/src/__tests__/flowSettings.test.ts +94 -15
  116. package/src/__tests__/objectVariable.test.ts +24 -0
  117. package/src/__tests__/provider.test.tsx +24 -2
  118. package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
  119. package/src/__tests__/runjsContext.test.ts +21 -0
  120. package/src/__tests__/runjsContextImplementations.test.ts +9 -2
  121. package/src/__tests__/runjsContextRuntime.test.ts +2 -0
  122. package/src/__tests__/runjsLocales.test.ts +6 -5
  123. package/src/__tests__/runjsSnippets.test.ts +21 -0
  124. package/src/__tests__/viewScopedFlowEngine.test.ts +136 -3
  125. package/src/components/FieldModelRenderer.tsx +2 -1
  126. package/src/components/FlowModelRenderer.tsx +18 -6
  127. package/src/components/FormItem.tsx +7 -1
  128. package/src/components/MobilePopup.tsx +4 -2
  129. package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
  130. package/src/components/__tests__/FormItem.test.tsx +25 -0
  131. package/src/components/__tests__/dnd.test.ts +44 -0
  132. package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +20 -10
  133. package/src/components/__tests__/gridDragPlanner.test.ts +472 -5
  134. package/src/components/dnd/__tests__/DndProvider.test.tsx +98 -0
  135. package/src/components/dnd/gridDragPlanner.ts +750 -17
  136. package/src/components/dnd/index.tsx +305 -28
  137. package/src/components/settings/wrappers/component/SelectWithTitle.tsx +21 -9
  138. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +178 -48
  139. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +487 -440
  140. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +344 -8
  141. package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +778 -0
  142. package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +360 -0
  143. package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +361 -0
  144. package/src/components/subModel/AddSubModelButton.tsx +16 -2
  145. package/src/components/subModel/LazyDropdown.tsx +341 -56
  146. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +524 -38
  147. package/src/components/subModel/__tests__/utils.test.ts +24 -0
  148. package/src/components/subModel/index.ts +1 -0
  149. package/src/components/subModel/utils.ts +13 -2
  150. package/src/components/variables/VariableHybridInput.tsx +531 -0
  151. package/src/components/variables/index.ts +2 -0
  152. package/src/data-source/__tests__/collection.test.ts +41 -2
  153. package/src/data-source/__tests__/index.test.ts +69 -2
  154. package/src/data-source/index.ts +332 -8
  155. package/src/executor/FlowExecutor.ts +6 -3
  156. package/src/executor/__tests__/flowExecutor.test.ts +57 -0
  157. package/src/flow-registry/DetachedFlowRegistry.ts +46 -0
  158. package/src/flow-registry/__tests__/detachedFlowRegistry.test.ts +47 -0
  159. package/src/flow-registry/index.ts +1 -0
  160. package/src/flowContext.ts +85 -6
  161. package/src/flowEngine.ts +484 -45
  162. package/src/flowI18n.ts +2 -1
  163. package/src/flowSettings.ts +40 -6
  164. package/src/index.ts +2 -0
  165. package/src/lazy-helper.tsx +57 -0
  166. package/src/locale/en-US.json +1 -0
  167. package/src/locale/zh-CN.json +1 -0
  168. package/src/models/DisplayItemModel.tsx +1 -1
  169. package/src/models/EditableItemModel.tsx +1 -1
  170. package/src/models/FilterableItemModel.tsx +1 -1
  171. package/src/models/__tests__/flowEngine.resolveUse.test.ts +0 -15
  172. package/src/models/__tests__/flowModel.test.ts +65 -37
  173. package/src/models/flowModel.tsx +184 -65
  174. package/src/provider.tsx +41 -25
  175. package/src/reactive/__tests__/observer.test.tsx +82 -0
  176. package/src/reactive/observer.tsx +87 -25
  177. package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +4 -3
  178. package/src/runjs-context/contexts/JSBlockRunJSContext.ts +4 -15
  179. package/src/runjs-context/contexts/JSColumnRunJSContext.ts +4 -2
  180. package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +5 -9
  181. package/src/runjs-context/contexts/JSFieldRunJSContext.ts +4 -3
  182. package/src/runjs-context/contexts/JSItemRunJSContext.ts +4 -3
  183. package/src/runjs-context/contexts/base.ts +467 -31
  184. package/src/runjs-context/contexts/elementDoc.ts +130 -0
  185. package/src/runjs-context/setup.ts +1 -0
  186. package/src/runjs-context/snippets/index.ts +12 -1
  187. package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
  188. package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
  189. package/src/types.ts +62 -0
  190. package/src/utils/__tests__/createCollectionContextMeta.test.ts +48 -0
  191. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +21 -0
  192. package/src/utils/__tests__/runjsValue.test.ts +11 -0
  193. package/src/utils/__tests__/utils.test.ts +62 -0
  194. package/src/utils/createCollectionContextMeta.ts +6 -2
  195. package/src/utils/index.ts +5 -1
  196. package/src/utils/loadedPageCache.ts +147 -0
  197. package/src/utils/parsePathnameToViewParams.ts +45 -5
  198. package/src/utils/randomId.ts +48 -0
  199. package/src/utils/runjsTemplateCompat.ts +1 -1
  200. package/src/utils/runjsValue.ts +50 -11
  201. package/src/utils/schema-utils.ts +30 -1
  202. package/src/views/FlowView.tsx +22 -2
  203. package/src/views/PageComponent.tsx +7 -4
  204. package/src/views/ViewNavigation.ts +46 -9
  205. package/src/views/__tests__/FlowView.usePage.test.tsx +243 -3
  206. package/src/views/__tests__/ViewNavigation.test.ts +52 -0
  207. package/src/views/__tests__/inheritLayoutContext.test.ts +53 -0
  208. package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
  209. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +12 -12
  210. package/src/views/createViewMeta.ts +106 -34
  211. package/src/views/inheritLayoutContext.ts +26 -0
  212. package/src/views/runViewBeforeClose.ts +19 -0
  213. package/src/views/useDialog.tsx +13 -3
  214. package/src/views/useDrawer.tsx +13 -3
  215. package/src/views/usePage.tsx +367 -180
@@ -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 MENU_SUBMENU_POPUP_SELECTOR = ".ant-menu-submenu-popup";
37
+ const DRAWER_CONTENT_WRAPPER_SELECTOR = ".ant-drawer-content-wrapper";
38
+ const DRAWER_CONTENT_SELECTOR = ".ant-drawer-content";
39
+ const DRAWER_ROOT_SELECTOR = ".ant-drawer-root";
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, MENU_SUBMENU_POPUP_SELECTOR),
57
+ (hostEl) => getClosestElement(hostEl, DRAWER_CONTENT_WRAPPER_SELECTOR),
58
+ (hostEl) => getClosestElement(hostEl, MODAL_WRAP_SELECTOR),
59
+ (hostEl) => getClosestElement(hostEl, MODAL_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,315 @@
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
+ var import_dnd = require("../../../dnd");
35
+ const TOOLBAR_HIDE_DELAY = 180;
36
+ const CHILD_FLOAT_MENU_ACTIVITY_EVENT = "nb-float-menu-child-activity";
37
+ const isNodeWithin = /* @__PURE__ */ __name((target, container) => {
38
+ return target instanceof Node && !!(container == null ? void 0 : container.contains(target));
39
+ }, "isNodeWithin");
40
+ const getToolbarModelUidFromTarget = /* @__PURE__ */ __name((target) => {
41
+ var _a;
42
+ if (!(target instanceof Element)) {
43
+ return null;
44
+ }
45
+ return ((_a = target.closest(".nb-toolbar-container[data-model-uid]")) == null ? void 0 : _a.getAttribute("data-model-uid")) || null;
46
+ }, "getToolbarModelUidFromTarget");
47
+ const isNodeWithinDescendantFloatToolbar = /* @__PURE__ */ __name((target, container, currentModelUid) => {
48
+ const targetModelUid = getToolbarModelUidFromTarget(target);
49
+ if (!container || !targetModelUid || targetModelUid === currentModelUid) {
50
+ return false;
51
+ }
52
+ return Array.from(
53
+ container.querySelectorAll('[data-has-float-menu="true"][data-float-menu-model-uid]')
54
+ ).some(
55
+ (hostElement) => hostElement !== container && hostElement.getAttribute("data-float-menu-model-uid") === targetModelUid
56
+ );
57
+ }, "isNodeWithinDescendantFloatToolbar");
58
+ const useFloatToolbarVisibility = /* @__PURE__ */ __name(({
59
+ modelUid,
60
+ containerRef,
61
+ toolbarContainerRef,
62
+ updatePortalRect,
63
+ schedulePortalRectUpdate
64
+ }) => {
65
+ const [hideMenu, setHideMenu] = (0, import_react.useState)(false);
66
+ const [isHostHovered, setIsHostHovered] = (0, import_react.useState)(false);
67
+ const [isToolbarHovered, setIsToolbarHovered] = (0, import_react.useState)(false);
68
+ const [isDraggingToolbar, setIsDraggingToolbar] = (0, import_react.useState)(false);
69
+ const [isDraggingToolbarItem, setIsDraggingToolbarItem] = (0, import_react.useState)(false);
70
+ const [isToolbarPinned, setIsToolbarPinned] = (0, import_react.useState)(false);
71
+ const [isHidePending, setIsHidePending] = (0, import_react.useState)(false);
72
+ const [activeChildToolbarIds, setActiveChildToolbarIds] = (0, import_react.useState)([]);
73
+ const hideToolbarTimerRef = (0, import_react.useRef)(null);
74
+ const reportedChildActivityToAncestorsRef = (0, import_react.useRef)(false);
75
+ const isHostHoveredRef = (0, import_react.useRef)(false);
76
+ const isToolbarHoveredRef = (0, import_react.useRef)(false);
77
+ const isDraggingToolbarRef = (0, import_react.useRef)(false);
78
+ const isDraggingToolbarItemRef = (0, import_react.useRef)(false);
79
+ const isToolbarPinnedRef = (0, import_react.useRef)(false);
80
+ const setHostHovered = (0, import_react.useCallback)((value) => {
81
+ isHostHoveredRef.current = value;
82
+ setIsHostHovered(value);
83
+ }, []);
84
+ const setToolbarHovered = (0, import_react.useCallback)((value) => {
85
+ isToolbarHoveredRef.current = value;
86
+ setIsToolbarHovered(value);
87
+ }, []);
88
+ const setDraggingToolbar = (0, import_react.useCallback)((value) => {
89
+ isDraggingToolbarRef.current = value;
90
+ setIsDraggingToolbar(value);
91
+ }, []);
92
+ const setDraggingToolbarItem = (0, import_react.useCallback)((value) => {
93
+ isDraggingToolbarItemRef.current = value;
94
+ setIsDraggingToolbarItem(value);
95
+ }, []);
96
+ const setToolbarPinned = (0, import_react.useCallback)((value) => {
97
+ isToolbarPinnedRef.current = value;
98
+ setIsToolbarPinned(value);
99
+ }, []);
100
+ const hasActiveChildToolbar = activeChildToolbarIds.length > 0;
101
+ const isToolbarVisible = !hideMenu && !hasActiveChildToolbar && (isHostHovered || isToolbarHovered || isDraggingToolbar || isDraggingToolbarItem || isToolbarPinned);
102
+ const shouldRenderToolbar = isToolbarVisible || isToolbarPinned || isDraggingToolbar || isDraggingToolbarItem;
103
+ const isToolbarInteractionActive = isHostHovered || isToolbarHovered || isDraggingToolbar || isDraggingToolbarItem || isToolbarPinned || isHidePending;
104
+ const clearHideToolbarTimer = (0, import_react.useCallback)(() => {
105
+ if (hideToolbarTimerRef.current !== null) {
106
+ window.clearTimeout(hideToolbarTimerRef.current);
107
+ hideToolbarTimerRef.current = null;
108
+ }
109
+ setIsHidePending(false);
110
+ }, []);
111
+ const scheduleHideToolbar = (0, import_react.useCallback)(() => {
112
+ clearHideToolbarTimer();
113
+ setIsHidePending(true);
114
+ hideToolbarTimerRef.current = window.setTimeout(() => {
115
+ hideToolbarTimerRef.current = null;
116
+ setIsHidePending(false);
117
+ if (isDraggingToolbarRef.current || isDraggingToolbarItemRef.current || isToolbarPinnedRef.current) {
118
+ return;
119
+ }
120
+ setHostHovered(false);
121
+ setToolbarHovered(false);
122
+ }, TOOLBAR_HIDE_DELAY);
123
+ }, [clearHideToolbarTimer, setHostHovered, setToolbarHovered]);
124
+ const handleSettingsMenuOpenChange = (0, import_react.useCallback)(
125
+ (open) => {
126
+ setToolbarPinned(open);
127
+ },
128
+ [setToolbarPinned]
129
+ );
130
+ (0, import_react.useEffect)(() => {
131
+ const hostElement = containerRef.current;
132
+ if (!hostElement) {
133
+ return;
134
+ }
135
+ const handleChildToolbarActivity = /* @__PURE__ */ __name((event) => {
136
+ var _a;
137
+ const customEvent = event;
138
+ if (!(customEvent.target instanceof HTMLElement) || customEvent.target === hostElement) {
139
+ return;
140
+ }
141
+ const childModelUid = (_a = customEvent.detail) == null ? void 0 : _a.modelUid;
142
+ if (!childModelUid) {
143
+ return;
144
+ }
145
+ setActiveChildToolbarIds((prevIds) => {
146
+ var _a2;
147
+ return ((_a2 = customEvent.detail) == null ? void 0 : _a2.active) ? prevIds.includes(childModelUid) ? prevIds : [...prevIds, childModelUid] : prevIds.filter((id) => id !== childModelUid);
148
+ });
149
+ }, "handleChildToolbarActivity");
150
+ hostElement.addEventListener(CHILD_FLOAT_MENU_ACTIVITY_EVENT, handleChildToolbarActivity);
151
+ return () => {
152
+ hostElement.removeEventListener(CHILD_FLOAT_MENU_ACTIVITY_EVENT, handleChildToolbarActivity);
153
+ };
154
+ }, [containerRef]);
155
+ (0, import_react.useEffect)(() => {
156
+ const hostElement = containerRef.current;
157
+ const ownerDocument = hostElement == null ? void 0 : hostElement.ownerDocument;
158
+ if (!ownerDocument) {
159
+ return;
160
+ }
161
+ const handleToolbarDragActivity = /* @__PURE__ */ __name((event) => {
162
+ var _a, _b;
163
+ const customEvent = event;
164
+ if (((_a = customEvent.detail) == null ? void 0 : _a.modelUid) !== modelUid) {
165
+ return;
166
+ }
167
+ if ((_b = customEvent.detail) == null ? void 0 : _b.active) {
168
+ clearHideToolbarTimer();
169
+ setDraggingToolbarItem(true);
170
+ return;
171
+ }
172
+ setDraggingToolbarItem(false);
173
+ if (isHostHoveredRef.current || isToolbarHoveredRef.current || isToolbarPinnedRef.current) {
174
+ clearHideToolbarTimer();
175
+ return;
176
+ }
177
+ scheduleHideToolbar();
178
+ }, "handleToolbarDragActivity");
179
+ ownerDocument.addEventListener(import_dnd.TOOLBAR_DRAG_ACTIVITY_EVENT, handleToolbarDragActivity);
180
+ return () => {
181
+ ownerDocument.removeEventListener(import_dnd.TOOLBAR_DRAG_ACTIVITY_EVENT, handleToolbarDragActivity);
182
+ };
183
+ }, [clearHideToolbarTimer, containerRef, modelUid, scheduleHideToolbar, setDraggingToolbarItem]);
184
+ (0, import_react.useEffect)(() => {
185
+ const hostElement = containerRef.current;
186
+ if (!hostElement || reportedChildActivityToAncestorsRef.current === isToolbarInteractionActive) {
187
+ return;
188
+ }
189
+ reportedChildActivityToAncestorsRef.current = isToolbarInteractionActive;
190
+ hostElement.dispatchEvent(
191
+ new CustomEvent(CHILD_FLOAT_MENU_ACTIVITY_EVENT, {
192
+ bubbles: true,
193
+ detail: { active: isToolbarInteractionActive, modelUid }
194
+ })
195
+ );
196
+ }, [containerRef, isToolbarInteractionActive, modelUid]);
197
+ (0, import_react.useEffect)(() => {
198
+ const hostElement = containerRef.current;
199
+ return () => {
200
+ if (hostElement && reportedChildActivityToAncestorsRef.current) {
201
+ hostElement.dispatchEvent(
202
+ new CustomEvent(CHILD_FLOAT_MENU_ACTIVITY_EVENT, {
203
+ bubbles: true,
204
+ detail: { active: false, modelUid }
205
+ })
206
+ );
207
+ reportedChildActivityToAncestorsRef.current = false;
208
+ }
209
+ clearHideToolbarTimer();
210
+ };
211
+ }, [clearHideToolbarTimer, containerRef, modelUid]);
212
+ (0, import_react.useEffect)(() => {
213
+ if (isToolbarPinned) {
214
+ clearHideToolbarTimer();
215
+ updatePortalRect();
216
+ }
217
+ }, [clearHideToolbarTimer, isToolbarPinned, updatePortalRect]);
218
+ const handleChildHover = (0, import_react.useCallback)(
219
+ (e) => {
220
+ const target = e.target;
221
+ const childWithMenu = target.closest("[data-has-float-menu]");
222
+ const isCurrentHostTarget = !childWithMenu || childWithMenu === containerRef.current;
223
+ if (isCurrentHostTarget) {
224
+ clearHideToolbarTimer();
225
+ setHostHovered(true);
226
+ }
227
+ setHideMenu(!!childWithMenu && childWithMenu !== containerRef.current);
228
+ },
229
+ [clearHideToolbarTimer, containerRef, setHostHovered]
230
+ );
231
+ const handleHostMouseEnter = (0, import_react.useCallback)(() => {
232
+ clearHideToolbarTimer();
233
+ setHideMenu(false);
234
+ updatePortalRect();
235
+ setHostHovered(true);
236
+ }, [clearHideToolbarTimer, setHostHovered, updatePortalRect]);
237
+ const handleHostMouseLeave = (0, import_react.useCallback)(
238
+ (e) => {
239
+ if (isToolbarPinnedRef.current) {
240
+ setHostHovered(false);
241
+ return;
242
+ }
243
+ if (isNodeWithin(e.relatedTarget, toolbarContainerRef.current)) {
244
+ clearHideToolbarTimer();
245
+ setHostHovered(false);
246
+ setToolbarHovered(true);
247
+ return;
248
+ }
249
+ if (isNodeWithinDescendantFloatToolbar(e.relatedTarget, containerRef.current, modelUid)) {
250
+ clearHideToolbarTimer();
251
+ setHideMenu(false);
252
+ setHostHovered(true);
253
+ return;
254
+ }
255
+ scheduleHideToolbar();
256
+ },
257
+ [
258
+ clearHideToolbarTimer,
259
+ containerRef,
260
+ modelUid,
261
+ scheduleHideToolbar,
262
+ setHostHovered,
263
+ setToolbarHovered,
264
+ toolbarContainerRef
265
+ ]
266
+ );
267
+ const handleToolbarMouseEnter = (0, import_react.useCallback)(() => {
268
+ clearHideToolbarTimer();
269
+ updatePortalRect();
270
+ setHostHovered(false);
271
+ setToolbarHovered(true);
272
+ }, [clearHideToolbarTimer, setHostHovered, setToolbarHovered, updatePortalRect]);
273
+ const handleToolbarMouseLeave = (0, import_react.useCallback)(
274
+ (e) => {
275
+ if (isToolbarPinnedRef.current || isDraggingToolbarItemRef.current) {
276
+ clearHideToolbarTimer();
277
+ setToolbarHovered(false);
278
+ return;
279
+ }
280
+ setToolbarHovered(false);
281
+ if (isNodeWithin(e.relatedTarget, containerRef.current)) {
282
+ clearHideToolbarTimer();
283
+ setHostHovered(true);
284
+ return;
285
+ }
286
+ scheduleHideToolbar();
287
+ },
288
+ [clearHideToolbarTimer, containerRef, scheduleHideToolbar, setHostHovered, setToolbarHovered]
289
+ );
290
+ const handleResizeDragStart = (0, import_react.useCallback)(() => {
291
+ updatePortalRect();
292
+ setDraggingToolbar(true);
293
+ schedulePortalRectUpdate();
294
+ }, [schedulePortalRectUpdate, setDraggingToolbar, updatePortalRect]);
295
+ const handleResizeDragEnd = (0, import_react.useCallback)(() => {
296
+ setDraggingToolbar(false);
297
+ schedulePortalRectUpdate();
298
+ }, [schedulePortalRectUpdate, setDraggingToolbar]);
299
+ return {
300
+ isToolbarVisible,
301
+ shouldRenderToolbar,
302
+ handleSettingsMenuOpenChange,
303
+ handleChildHover,
304
+ handleHostMouseEnter,
305
+ handleHostMouseLeave,
306
+ handleToolbarMouseEnter,
307
+ handleToolbarMouseLeave,
308
+ handleResizeDragStart,
309
+ handleResizeDragEnd
310
+ };
311
+ }, "useFloatToolbarVisibility");
312
+ // Annotate the CommonJS export names for ESM import in node:
313
+ 0 && (module.exports = {
314
+ useFloatToolbarVisibility
315
+ });
@@ -430,7 +430,7 @@ const AddSubModelButtonCore = /* @__PURE__ */ __name(function AddSubModelButton(
430
430
  }
431
431
  let addedModel;
432
432
  try {
433
- addedModel = model.flowEngine.createModel({
433
+ addedModel = await model.flowEngine.createModelAsync({
434
434
  ...import_lodash.default.cloneDeep(createOpts),
435
435
  parentId: model.uid,
436
436
  subKey: subModelKey,
@@ -476,6 +476,17 @@ const AddSubModelButtonCore = /* @__PURE__ */ __name(function AddSubModelButton(
476
476
  () => transformItems(finalItems, model, subModelKey, subModelType),
477
477
  [finalItems, model, subModelKey, subModelType]
478
478
  );
479
+ (0, import_react.useEffect)(() => {
480
+ const handleSubModelChange = /* @__PURE__ */ __name(() => {
481
+ setRefreshTick((x) => x + 1);
482
+ }, "handleSubModelChange");
483
+ model.emitter.on("onSubModelAdded", handleSubModelChange);
484
+ model.emitter.on("onSubModelRemoved", handleSubModelChange);
485
+ return () => {
486
+ model.emitter.off("onSubModelAdded", handleSubModelChange);
487
+ model.emitter.off("onSubModelRemoved", handleSubModelChange);
488
+ };
489
+ }, [model]);
479
490
  return /* @__PURE__ */ import_react.default.createElement(
480
491
  import_LazyDropdown.default,
481
492
  {