@nocobase/flow-engine 2.1.0-beta.2 → 2.1.0-beta.21

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 (126) 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/FlowModelRenderer.d.ts +1 -1
  7. package/lib/components/FlowModelRenderer.js +10 -6
  8. package/lib/components/MobilePopup.js +6 -5
  9. package/lib/components/dnd/gridDragPlanner.js +6 -2
  10. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
  11. package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +48 -9
  12. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +19 -43
  13. package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +339 -295
  14. package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +16 -2
  15. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.d.ts +36 -0
  16. package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +272 -0
  17. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
  18. package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +247 -0
  19. package/lib/components/subModel/AddSubModelButton.js +27 -1
  20. package/lib/components/subModel/utils.js +2 -2
  21. package/lib/data-source/index.js +6 -0
  22. package/lib/executor/FlowExecutor.js +31 -8
  23. package/lib/flowContext.js +31 -1
  24. package/lib/flowEngine.d.ts +151 -1
  25. package/lib/flowEngine.js +389 -15
  26. package/lib/flowSettings.d.ts +14 -6
  27. package/lib/flowSettings.js +34 -6
  28. package/lib/lazy-helper.d.ts +14 -0
  29. package/lib/lazy-helper.js +71 -0
  30. package/lib/locale/en-US.json +1 -0
  31. package/lib/locale/index.d.ts +2 -0
  32. package/lib/locale/zh-CN.json +1 -0
  33. package/lib/models/flowModel.d.ts +2 -1
  34. package/lib/models/flowModel.js +28 -9
  35. package/lib/reactive/observer.js +46 -16
  36. package/lib/runjs-context/registry.d.ts +1 -1
  37. package/lib/runjs-context/setup.js +20 -12
  38. package/lib/runjs-context/snippets/index.js +13 -2
  39. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts +11 -0
  40. package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.js +50 -0
  41. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts +11 -0
  42. package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
  43. package/lib/scheduler/ModelOperationScheduler.d.ts +5 -1
  44. package/lib/scheduler/ModelOperationScheduler.js +3 -2
  45. package/lib/types.d.ts +47 -1
  46. package/lib/utils/index.d.ts +2 -2
  47. package/lib/utils/index.js +4 -0
  48. package/lib/utils/parsePathnameToViewParams.js +1 -1
  49. package/lib/utils/runjsTemplateCompat.js +1 -1
  50. package/lib/utils/runjsValue.js +41 -11
  51. package/lib/utils/schema-utils.d.ts +7 -1
  52. package/lib/utils/schema-utils.js +19 -0
  53. package/lib/views/FlowView.d.ts +7 -1
  54. package/lib/views/runViewBeforeClose.d.ts +10 -0
  55. package/lib/views/runViewBeforeClose.js +45 -0
  56. package/lib/views/useDialog.d.ts +2 -1
  57. package/lib/views/useDialog.js +20 -3
  58. package/lib/views/useDrawer.d.ts +2 -1
  59. package/lib/views/useDrawer.js +20 -3
  60. package/lib/views/usePage.d.ts +2 -1
  61. package/lib/views/usePage.js +10 -3
  62. package/package.json +6 -5
  63. package/src/JSRunner.ts +68 -4
  64. package/src/ViewScopedFlowEngine.ts +4 -0
  65. package/src/__tests__/JSRunner.test.ts +27 -1
  66. package/src/__tests__/flow-engine.test.ts +166 -0
  67. package/src/__tests__/flowContext.test.ts +65 -1
  68. package/src/__tests__/flowEngine.modelLoaders.test.ts +245 -0
  69. package/src/__tests__/flowSettings.test.ts +94 -15
  70. package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
  71. package/src/__tests__/runjsContext.test.ts +16 -0
  72. package/src/__tests__/runjsContextRuntime.test.ts +2 -0
  73. package/src/__tests__/runjsPreprocessDefault.test.ts +23 -0
  74. package/src/__tests__/runjsSnippets.test.ts +21 -0
  75. package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
  76. package/src/components/FlowModelRenderer.tsx +12 -6
  77. package/src/components/MobilePopup.tsx +4 -2
  78. package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
  79. package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +20 -10
  80. package/src/components/__tests__/gridDragPlanner.test.ts +88 -0
  81. package/src/components/dnd/gridDragPlanner.ts +8 -2
  82. package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +63 -9
  83. package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +468 -440
  84. package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +18 -2
  85. package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +95 -0
  86. package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +609 -0
  87. package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +358 -0
  88. package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +281 -0
  89. package/src/components/subModel/AddSubModelButton.tsx +32 -2
  90. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +142 -32
  91. package/src/components/subModel/utils.ts +1 -1
  92. package/src/data-source/index.ts +6 -0
  93. package/src/executor/FlowExecutor.ts +34 -9
  94. package/src/executor/__tests__/flowExecutor.test.ts +57 -0
  95. package/src/flowContext.ts +35 -3
  96. package/src/flowEngine.ts +445 -11
  97. package/src/flowSettings.ts +40 -6
  98. package/src/lazy-helper.tsx +57 -0
  99. package/src/locale/en-US.json +1 -0
  100. package/src/locale/zh-CN.json +1 -0
  101. package/src/models/__tests__/dispatchEvent.when.test.ts +214 -0
  102. package/src/models/flowModel.tsx +31 -10
  103. package/src/reactive/__tests__/observer.test.tsx +82 -0
  104. package/src/reactive/observer.tsx +87 -25
  105. package/src/runjs-context/registry.ts +1 -1
  106. package/src/runjs-context/setup.ts +22 -12
  107. package/src/runjs-context/snippets/index.ts +12 -1
  108. package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
  109. package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
  110. package/src/scheduler/ModelOperationScheduler.ts +14 -3
  111. package/src/types.ts +60 -0
  112. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
  113. package/src/utils/__tests__/runjsValue.test.ts +11 -0
  114. package/src/utils/__tests__/utils.test.ts +62 -0
  115. package/src/utils/index.ts +2 -1
  116. package/src/utils/parsePathnameToViewParams.ts +2 -2
  117. package/src/utils/runjsTemplateCompat.ts +1 -1
  118. package/src/utils/runjsValue.ts +50 -11
  119. package/src/utils/schema-utils.ts +30 -1
  120. package/src/views/FlowView.tsx +11 -1
  121. package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
  122. package/src/views/__tests__/useDialog.closeDestroy.test.tsx +13 -12
  123. package/src/views/runViewBeforeClose.ts +19 -0
  124. package/src/views/useDialog.tsx +25 -3
  125. package/src/views/useDrawer.tsx +25 -3
  126. package/src/views/usePage.tsx +12 -3
@@ -126,6 +126,15 @@ const openStepSettingsDialog = /* @__PURE__ */ __name(async ({
126
126
  }
127
127
  };
128
128
  const openView = model.context.viewer[mode].bind(model.context.viewer);
129
+ const resolvedUiModeProps = (0, import_reactive.toJS)(uiModeProps) || {};
130
+ const { zIndex: uiModeZIndex, ...restUiModeProps } = resolvedUiModeProps;
131
+ const resolveDialogZIndex = /* @__PURE__ */ __name((rawZIndex) => {
132
+ var _a2, _b2;
133
+ const nextZIndex = typeof ((_a2 = model.context.viewer) == null ? void 0 : _a2.getNextZIndex) === "function" ? model.context.viewer.getNextZIndex() : (((_b2 = model.context.themeToken) == null ? void 0 : _b2.zIndexPopupBase) || 1e3) + 1;
134
+ const inputZIndex = Number(rawZIndex) || 0;
135
+ return Math.max(nextZIndex, inputZIndex);
136
+ }, "resolveDialogZIndex");
137
+ const mergedZIndex = resolveDialogZIndex(uiModeZIndex);
129
138
  const form = (0, import_core.createForm)({
130
139
  initialValues: (0, import_utils.compileUiSchema)(scopes, initialValues)
131
140
  });
@@ -141,7 +150,8 @@ const openStepSettingsDialog = /* @__PURE__ */ __name(async ({
141
150
  title: dialogTitle || t(title),
142
151
  width: dialogWidth,
143
152
  destroyOnClose: true,
144
- ...(0, import_reactive.toJS)(uiModeProps),
153
+ ...restUiModeProps,
154
+ zIndex: mergedZIndex,
145
155
  // 透传 navigation,便于变量元信息根据真实视图栈推断父级弹窗
146
156
  inputArgs,
147
157
  onClose: /* @__PURE__ */ __name(() => {
@@ -155,7 +165,11 @@ const openStepSettingsDialog = /* @__PURE__ */ __name(async ({
155
165
  (0, import_react2.useEffect)(() => {
156
166
  return (0, import_reactive.autorun)(() => {
157
167
  const dynamicProps = (0, import_reactive.toJS)(uiModeProps);
158
- currentDialog.update(dynamicProps);
168
+ const { zIndex, ...restDynamicProps } = dynamicProps || {};
169
+ currentDialog.update({
170
+ ...restDynamicProps,
171
+ zIndex: resolveDialogZIndex(zIndex)
172
+ });
159
173
  });
160
174
  }, []);
161
175
  const compiledFormSchema = (0, import_utils.compileUiSchema)(scopes, formSchema);
@@ -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,272 @@
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_SELECTOR = ".ant-modal";
40
+ const MODAL_WRAP_SELECTOR = ".ant-modal-wrap";
41
+ const MODAL_ROOT_SELECTOR = ".ant-modal-root";
42
+ const defaultPortalRect = {
43
+ top: 0,
44
+ left: 0,
45
+ width: 0,
46
+ height: 0
47
+ };
48
+ const getClosestElement = /* @__PURE__ */ __name((hostEl, selector) => hostEl == null ? void 0 : hostEl.closest(selector), "getClosestElement");
49
+ const createAbsolutePortalHostConfig = /* @__PURE__ */ __name((element) => ({
50
+ mountElement: element,
51
+ positioningElement: element,
52
+ positioningMode: "absolute"
53
+ }), "createAbsolutePortalHostConfig");
54
+ const popupPortalHostResolvers = [
55
+ (hostEl) => getClosestElement(hostEl, DRAWER_CONTENT_WRAPPER_SELECTOR),
56
+ (hostEl) => getClosestElement(hostEl, MODAL_WRAP_SELECTOR),
57
+ (hostEl) => getClosestElement(hostEl, MODAL_SELECTOR),
58
+ (hostEl) => {
59
+ const drawerContent = getClosestElement(hostEl, DRAWER_CONTENT_SELECTOR);
60
+ return drawerContent ? getClosestElement(drawerContent, DRAWER_CONTENT_WRAPPER_SELECTOR) || drawerContent : null;
61
+ },
62
+ (hostEl) => getClosestElement(hostEl, DRAWER_ROOT_SELECTOR),
63
+ (hostEl) => getClosestElement(hostEl, MODAL_ROOT_SELECTOR)
64
+ ];
65
+ const getPopupPortalHostConfig = /* @__PURE__ */ __name((hostEl) => {
66
+ for (const resolveHost of popupPortalHostResolvers) {
67
+ const popupHost = resolveHost(hostEl);
68
+ if (popupHost) {
69
+ return createAbsolutePortalHostConfig(popupHost);
70
+ }
71
+ }
72
+ return null;
73
+ }, "getPopupPortalHostConfig");
74
+ const getToolbarPortalHostConfig = /* @__PURE__ */ __name((hostEl) => {
75
+ if (typeof document === "undefined") {
76
+ return null;
77
+ }
78
+ const popupRootConfig = getPopupPortalHostConfig(hostEl);
79
+ if (popupRootConfig) {
80
+ return popupRootConfig;
81
+ }
82
+ const appContainer = document.querySelector(APP_CONTAINER_SELECTOR);
83
+ if (appContainer) {
84
+ return createAbsolutePortalHostConfig(appContainer);
85
+ }
86
+ return {
87
+ mountElement: document.body,
88
+ positioningElement: document.body,
89
+ positioningMode: "fixed"
90
+ };
91
+ }, "getToolbarPortalHostConfig");
92
+ const parseToolbarInsetValue = /* @__PURE__ */ __name((value) => {
93
+ if (typeof value === "number" && Number.isFinite(value)) {
94
+ return value;
95
+ }
96
+ if (typeof value === "string") {
97
+ const trimmedValue = value.trim();
98
+ if (/^-?\d+(\.\d+)?(px)?$/.test(trimmedValue)) {
99
+ return Number.parseFloat(trimmedValue);
100
+ }
101
+ }
102
+ return 0;
103
+ }, "parseToolbarInsetValue");
104
+ const resolveToolbarPortalInset = /* @__PURE__ */ __name((toolbarStyle) => {
105
+ return {
106
+ top: parseToolbarInsetValue(toolbarStyle == null ? void 0 : toolbarStyle.top),
107
+ left: parseToolbarInsetValue(toolbarStyle == null ? void 0 : toolbarStyle.left),
108
+ right: parseToolbarInsetValue(toolbarStyle == null ? void 0 : toolbarStyle.right),
109
+ bottom: parseToolbarInsetValue(toolbarStyle == null ? void 0 : toolbarStyle.bottom)
110
+ };
111
+ }, "resolveToolbarPortalInset");
112
+ const getAbsolutePositioningElement = /* @__PURE__ */ __name((toolbarEl, portalHostConfig) => {
113
+ if (!portalHostConfig || portalHostConfig.positioningMode !== "absolute") {
114
+ return (portalHostConfig == null ? void 0 : portalHostConfig.positioningElement) || null;
115
+ }
116
+ const offsetParent = toolbarEl == null ? void 0 : toolbarEl.offsetParent;
117
+ if (offsetParent instanceof HTMLElement && offsetParent !== document.body && offsetParent !== document.documentElement) {
118
+ return offsetParent;
119
+ }
120
+ return portalHostConfig.positioningElement;
121
+ }, "getAbsolutePositioningElement");
122
+ const calculatePortalRect = /* @__PURE__ */ __name((hostEl, portalHostConfig, toolbarStyle, toolbarEl) => {
123
+ if (!hostEl) {
124
+ return defaultPortalRect;
125
+ }
126
+ const inset = resolveToolbarPortalInset(toolbarStyle);
127
+ const hostRect = hostEl.getBoundingClientRect();
128
+ let rect;
129
+ if (!portalHostConfig || portalHostConfig.positioningMode === "fixed") {
130
+ rect = {
131
+ top: hostRect.top,
132
+ left: hostRect.left,
133
+ width: hostRect.width,
134
+ height: hostRect.height
135
+ };
136
+ } else {
137
+ const positioningElement = getAbsolutePositioningElement(toolbarEl || null, portalHostConfig);
138
+ const portalHostRect = (positioningElement == null ? void 0 : positioningElement.getBoundingClientRect()) || portalHostConfig.positioningElement.getBoundingClientRect();
139
+ const scrollTop = (positioningElement == null ? void 0 : positioningElement.scrollTop) ?? portalHostConfig.positioningElement.scrollTop;
140
+ const scrollLeft = (positioningElement == null ? void 0 : positioningElement.scrollLeft) ?? portalHostConfig.positioningElement.scrollLeft;
141
+ rect = {
142
+ top: hostRect.top - portalHostRect.top + scrollTop,
143
+ left: hostRect.left - portalHostRect.left + scrollLeft,
144
+ width: hostRect.width,
145
+ height: hostRect.height
146
+ };
147
+ }
148
+ return {
149
+ top: rect.top + inset.top,
150
+ left: rect.left + inset.left,
151
+ width: Math.max(0, rect.width - inset.left - inset.right),
152
+ height: Math.max(0, rect.height - inset.top - inset.bottom)
153
+ };
154
+ }, "calculatePortalRect");
155
+ const omitToolbarPortalInsetStyle = /* @__PURE__ */ __name((toolbarStyle) => {
156
+ if (!toolbarStyle) {
157
+ return void 0;
158
+ }
159
+ const nextStyle = { ...toolbarStyle };
160
+ delete nextStyle.top;
161
+ delete nextStyle.left;
162
+ delete nextStyle.right;
163
+ delete nextStyle.bottom;
164
+ return nextStyle;
165
+ }, "omitToolbarPortalInsetStyle");
166
+ const useFloatToolbarPortal = /* @__PURE__ */ __name(({
167
+ active,
168
+ containerRef,
169
+ toolbarContainerRef,
170
+ toolbarStyle
171
+ }) => {
172
+ const [portalRect, setPortalRect] = (0, import_react.useState)(defaultPortalRect);
173
+ const [portalRenderSnapshot, setPortalRenderSnapshot] = (0, import_react.useState)(null);
174
+ const portalHostConfigRef = (0, import_react.useRef)(null);
175
+ const portalRafIdRef = (0, import_react.useRef)(null);
176
+ const updatePortalRect = (0, import_react.useCallback)(() => {
177
+ const hostElement = containerRef.current;
178
+ if (!hostElement) {
179
+ return;
180
+ }
181
+ const nextPortalHostConfig = getToolbarPortalHostConfig(hostElement);
182
+ portalHostConfigRef.current = nextPortalHostConfig;
183
+ setPortalRenderSnapshot((prevSnapshot) => {
184
+ if (!nextPortalHostConfig) {
185
+ return prevSnapshot === null ? prevSnapshot : null;
186
+ }
187
+ if ((prevSnapshot == null ? void 0 : prevSnapshot.mountElement) === nextPortalHostConfig.mountElement && (prevSnapshot == null ? void 0 : prevSnapshot.positioningMode) === nextPortalHostConfig.positioningMode) {
188
+ return prevSnapshot;
189
+ }
190
+ return {
191
+ mountElement: nextPortalHostConfig.mountElement,
192
+ positioningMode: nextPortalHostConfig.positioningMode
193
+ };
194
+ });
195
+ const nextRect = calculatePortalRect(hostElement, nextPortalHostConfig, toolbarStyle, toolbarContainerRef.current);
196
+ setPortalRect((prevRect) => {
197
+ if (prevRect.top === nextRect.top && prevRect.left === nextRect.left && prevRect.width === nextRect.width && prevRect.height === nextRect.height) {
198
+ return prevRect;
199
+ }
200
+ return nextRect;
201
+ });
202
+ }, [containerRef, toolbarContainerRef, toolbarStyle]);
203
+ const schedulePortalRectUpdate = (0, import_react.useCallback)(() => {
204
+ if (portalRafIdRef.current !== null) {
205
+ return;
206
+ }
207
+ portalRafIdRef.current = window.requestAnimationFrame(() => {
208
+ portalRafIdRef.current = null;
209
+ updatePortalRect();
210
+ });
211
+ }, [updatePortalRect]);
212
+ const getPopupContainer = (0, import_react.useCallback)(
213
+ (triggerNode) => {
214
+ var _a, _b, _c, _d, _e;
215
+ 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);
216
+ return ((_d = portalHostConfigRef.current) == null ? void 0 : _d.mountElement) || ((_e = getToolbarPortalHostConfig(triggerNode || containerRef.current)) == null ? void 0 : _e.mountElement) || fallbackContainer;
217
+ },
218
+ [containerRef]
219
+ );
220
+ (0, import_react.useEffect)(() => {
221
+ var _a, _b;
222
+ if (!active) {
223
+ return;
224
+ }
225
+ updatePortalRect();
226
+ const handleViewportChange = /* @__PURE__ */ __name(() => {
227
+ schedulePortalRectUpdate();
228
+ }, "handleViewportChange");
229
+ const container = containerRef.current;
230
+ const mountElement = (_a = portalHostConfigRef.current) == null ? void 0 : _a.mountElement;
231
+ const positioningElement = (_b = portalHostConfigRef.current) == null ? void 0 : _b.positioningElement;
232
+ const resizeObserver = typeof ResizeObserver !== "undefined" && container ? new ResizeObserver(() => {
233
+ schedulePortalRectUpdate();
234
+ }) : null;
235
+ if (container) {
236
+ resizeObserver == null ? void 0 : resizeObserver.observe(container);
237
+ }
238
+ if (mountElement && mountElement !== container) {
239
+ resizeObserver == null ? void 0 : resizeObserver.observe(mountElement);
240
+ }
241
+ if (positioningElement && positioningElement !== container && positioningElement !== mountElement) {
242
+ resizeObserver == null ? void 0 : resizeObserver.observe(positioningElement);
243
+ }
244
+ window.addEventListener("resize", handleViewportChange);
245
+ window.addEventListener("scroll", handleViewportChange, true);
246
+ return () => {
247
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
248
+ window.removeEventListener("resize", handleViewportChange);
249
+ window.removeEventListener("scroll", handleViewportChange, true);
250
+ };
251
+ }, [active, containerRef, schedulePortalRectUpdate, updatePortalRect]);
252
+ (0, import_react.useEffect)(() => {
253
+ return () => {
254
+ if (portalRafIdRef.current !== null) {
255
+ window.cancelAnimationFrame(portalRafIdRef.current);
256
+ }
257
+ portalHostConfigRef.current = null;
258
+ };
259
+ }, []);
260
+ return {
261
+ portalRect,
262
+ portalRenderSnapshot,
263
+ getPopupContainer,
264
+ updatePortalRect,
265
+ schedulePortalRectUpdate
266
+ };
267
+ }, "useFloatToolbarPortal");
268
+ // Annotate the CommonJS export names for ESM import in node:
269
+ 0 && (module.exports = {
270
+ omitToolbarPortalInsetStyle,
271
+ useFloatToolbarPortal
272
+ });
@@ -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
+ });
@@ -376,6 +376,21 @@ const AddSubModelButtonCore = /* @__PURE__ */ __name(function AddSubModelButton(
376
376
  }),
377
377
  [model, subModelKey, subModelType]
378
378
  );
379
+ import_react.default.useEffect(() => {
380
+ var _a, _b, _c;
381
+ const handleSubModelChanged = /* @__PURE__ */ __name(() => {
382
+ setRefreshTick((x) => x + 1);
383
+ }, "handleSubModelChanged");
384
+ (_a = model.emitter) == null ? void 0 : _a.on("onSubModelAdded", handleSubModelChanged);
385
+ (_b = model.emitter) == null ? void 0 : _b.on("onSubModelRemoved", handleSubModelChanged);
386
+ (_c = model.emitter) == null ? void 0 : _c.on("onSubModelReplaced", handleSubModelChanged);
387
+ return () => {
388
+ var _a2, _b2, _c2;
389
+ (_a2 = model.emitter) == null ? void 0 : _a2.off("onSubModelAdded", handleSubModelChanged);
390
+ (_b2 = model.emitter) == null ? void 0 : _b2.off("onSubModelRemoved", handleSubModelChanged);
391
+ (_c2 = model.emitter) == null ? void 0 : _c2.off("onSubModelReplaced", handleSubModelChanged);
392
+ };
393
+ }, [model]);
379
394
  const onClick = /* @__PURE__ */ __name(async (info) => {
380
395
  const clickedItem = info.originalItem || info;
381
396
  const item = clickedItem.originalItem || clickedItem;
@@ -415,7 +430,7 @@ const AddSubModelButtonCore = /* @__PURE__ */ __name(function AddSubModelButton(
415
430
  }
416
431
  let addedModel;
417
432
  try {
418
- addedModel = model.flowEngine.createModel({
433
+ addedModel = await model.flowEngine.createModelAsync({
419
434
  ...import_lodash.default.cloneDeep(createOpts),
420
435
  parentId: model.uid,
421
436
  subKey: subModelKey,
@@ -461,6 +476,17 @@ const AddSubModelButtonCore = /* @__PURE__ */ __name(function AddSubModelButton(
461
476
  () => transformItems(finalItems, model, subModelKey, subModelType),
462
477
  [finalItems, model, subModelKey, subModelType]
463
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]);
464
490
  return /* @__PURE__ */ import_react.default.createElement(
465
491
  import_LazyDropdown.default,
466
492
  {