@nocobase/flow-engine 2.1.0-alpha.3 → 2.1.0-alpha.31
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.
- package/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/JSRunner.d.ts +10 -1
- package/lib/JSRunner.js +50 -5
- package/lib/ViewScopedFlowEngine.js +5 -1
- package/lib/components/FieldModelRenderer.js +2 -2
- package/lib/components/FlowModelRenderer.d.ts +3 -1
- package/lib/components/FlowModelRenderer.js +12 -6
- package/lib/components/FormItem.d.ts +6 -0
- package/lib/components/FormItem.js +11 -3
- package/lib/components/MobilePopup.js +6 -5
- package/lib/components/dnd/gridDragPlanner.d.ts +59 -2
- package/lib/components/dnd/gridDragPlanner.js +613 -21
- package/lib/components/dnd/index.d.ts +19 -1
- package/lib/components/dnd/index.js +243 -23
- package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +2 -1
- package/lib/components/settings/wrappers/component/SelectWithTitle.js +14 -12
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +68 -10
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +23 -43
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +352 -295
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +16 -2
- package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.d.ts +36 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +274 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +315 -0
- package/lib/components/subModel/AddSubModelButton.js +27 -1
- package/lib/components/subModel/index.d.ts +1 -0
- package/lib/components/subModel/index.js +19 -0
- package/lib/components/subModel/utils.d.ts +1 -1
- package/lib/components/subModel/utils.js +2 -2
- package/lib/data-source/index.d.ts +75 -0
- package/lib/data-source/index.js +246 -4
- package/lib/executor/FlowExecutor.js +31 -8
- package/lib/flowContext.d.ts +2 -0
- package/lib/flowContext.js +31 -1
- package/lib/flowEngine.d.ts +151 -1
- package/lib/flowEngine.js +389 -15
- package/lib/flowI18n.js +2 -1
- package/lib/flowSettings.d.ts +14 -6
- package/lib/flowSettings.js +34 -6
- package/lib/lazy-helper.d.ts +14 -0
- package/lib/lazy-helper.js +71 -0
- package/lib/locale/en-US.json +1 -0
- package/lib/locale/index.d.ts +2 -0
- package/lib/locale/zh-CN.json +1 -0
- package/lib/models/DisplayItemModel.d.ts +1 -1
- package/lib/models/EditableItemModel.d.ts +1 -1
- package/lib/models/FilterableItemModel.d.ts +1 -1
- package/lib/models/flowModel.d.ts +13 -10
- package/lib/models/flowModel.js +78 -18
- package/lib/provider.js +38 -23
- package/lib/reactive/observer.js +46 -16
- package/lib/runjs-context/registry.d.ts +1 -1
- package/lib/runjs-context/setup.js +20 -12
- package/lib/runjs-context/snippets/index.js +13 -2
- package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.js +50 -0
- package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
- package/lib/scheduler/ModelOperationScheduler.d.ts +5 -1
- package/lib/scheduler/ModelOperationScheduler.js +3 -2
- package/lib/types.d.ts +47 -1
- package/lib/utils/createCollectionContextMeta.js +6 -2
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.js +4 -0
- package/lib/utils/parsePathnameToViewParams.js +1 -1
- package/lib/utils/runjsTemplateCompat.js +1 -1
- package/lib/utils/runjsValue.js +41 -11
- package/lib/utils/schema-utils.d.ts +7 -1
- package/lib/utils/schema-utils.js +19 -0
- package/lib/views/FlowView.d.ts +7 -1
- package/lib/views/runViewBeforeClose.d.ts +10 -0
- package/lib/views/runViewBeforeClose.js +45 -0
- package/lib/views/useDialog.d.ts +2 -1
- package/lib/views/useDialog.js +20 -3
- package/lib/views/useDrawer.d.ts +2 -1
- package/lib/views/useDrawer.js +20 -3
- package/lib/views/usePage.d.ts +2 -1
- package/lib/views/usePage.js +10 -3
- package/package.json +6 -5
- package/src/JSRunner.ts +68 -4
- package/src/ViewScopedFlowEngine.ts +4 -0
- package/src/__tests__/JSRunner.test.ts +27 -1
- package/src/__tests__/flow-engine.test.ts +166 -0
- package/src/__tests__/flowContext.test.ts +65 -1
- package/src/__tests__/flowEngine.modelLoaders.test.ts +245 -0
- package/src/__tests__/flowSettings.test.ts +94 -15
- package/src/__tests__/objectVariable.test.ts +24 -0
- package/src/__tests__/provider.test.tsx +24 -2
- package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
- package/src/__tests__/runjsContext.test.ts +16 -0
- package/src/__tests__/runjsContextRuntime.test.ts +2 -0
- package/src/__tests__/runjsPreprocessDefault.test.ts +23 -0
- package/src/__tests__/runjsSnippets.test.ts +21 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
- package/src/components/FieldModelRenderer.tsx +2 -1
- package/src/components/FlowModelRenderer.tsx +18 -6
- package/src/components/FormItem.tsx +7 -1
- package/src/components/MobilePopup.tsx +4 -2
- package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
- package/src/components/__tests__/FormItem.test.tsx +25 -0
- package/src/components/__tests__/dnd.test.ts +44 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +20 -10
- package/src/components/__tests__/gridDragPlanner.test.ts +558 -3
- package/src/components/dnd/__tests__/DndProvider.test.tsx +98 -0
- package/src/components/dnd/gridDragPlanner.ts +758 -19
- package/src/components/dnd/index.tsx +291 -27
- package/src/components/settings/wrappers/component/SelectWithTitle.tsx +21 -9
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +88 -10
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +487 -440
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +18 -2
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +189 -3
- package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +778 -0
- package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +360 -0
- package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +361 -0
- package/src/components/subModel/AddSubModelButton.tsx +32 -2
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +142 -32
- package/src/components/subModel/index.ts +1 -0
- package/src/components/subModel/utils.ts +1 -1
- package/src/data-source/__tests__/collection.test.ts +41 -2
- package/src/data-source/__tests__/index.test.ts +68 -1
- package/src/data-source/index.ts +303 -5
- package/src/executor/FlowExecutor.ts +34 -9
- package/src/executor/__tests__/flowExecutor.test.ts +57 -0
- package/src/flowContext.ts +37 -3
- package/src/flowEngine.ts +445 -11
- package/src/flowI18n.ts +2 -1
- package/src/flowSettings.ts +40 -6
- package/src/lazy-helper.tsx +57 -0
- package/src/locale/en-US.json +1 -0
- package/src/locale/zh-CN.json +1 -0
- package/src/models/DisplayItemModel.tsx +1 -1
- package/src/models/EditableItemModel.tsx +1 -1
- package/src/models/FilterableItemModel.tsx +1 -1
- package/src/models/__tests__/dispatchEvent.when.test.ts +214 -0
- package/src/models/__tests__/flowModel.test.ts +19 -3
- package/src/models/flowModel.tsx +119 -33
- package/src/provider.tsx +41 -25
- package/src/reactive/__tests__/observer.test.tsx +82 -0
- package/src/reactive/observer.tsx +87 -25
- package/src/runjs-context/registry.ts +1 -1
- package/src/runjs-context/setup.ts +22 -12
- package/src/runjs-context/snippets/index.ts +12 -1
- package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
- package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
- package/src/scheduler/ModelOperationScheduler.ts +14 -3
- package/src/types.ts +60 -0
- package/src/utils/__tests__/createCollectionContextMeta.test.ts +48 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
- package/src/utils/__tests__/runjsValue.test.ts +11 -0
- package/src/utils/__tests__/utils.test.ts +62 -0
- package/src/utils/createCollectionContextMeta.ts +6 -2
- package/src/utils/index.ts +2 -1
- package/src/utils/parsePathnameToViewParams.ts +2 -2
- package/src/utils/runjsTemplateCompat.ts +1 -1
- package/src/utils/runjsValue.ts +50 -11
- package/src/utils/schema-utils.ts +30 -1
- package/src/views/FlowView.tsx +11 -1
- package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +13 -12
- package/src/views/runViewBeforeClose.ts +19 -0
- package/src/views/useDialog.tsx +25 -3
- package/src/views/useDrawer.tsx +25 -3
- package/src/views/usePage.tsx +12 -3
|
@@ -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
|
+
});
|
|
@@ -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.
|
|
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
|
{
|
|
@@ -7,10 +7,16 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
14
20
|
var __copyProps = (to, from, except, desc) => {
|
|
15
21
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
22
|
for (let key of __getOwnPropNames(from))
|
|
@@ -20,13 +26,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
26
|
return to;
|
|
21
27
|
};
|
|
22
28
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
23
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
38
|
var subModel_exports = {};
|
|
39
|
+
__export(subModel_exports, {
|
|
40
|
+
LazyDropdown: () => import_LazyDropdown.default
|
|
41
|
+
});
|
|
25
42
|
module.exports = __toCommonJS(subModel_exports);
|
|
26
43
|
__reExport(subModel_exports, require("./AddSubModelButton"), module.exports);
|
|
44
|
+
var import_LazyDropdown = __toESM(require("./LazyDropdown"));
|
|
27
45
|
__reExport(subModel_exports, require("./utils"), module.exports);
|
|
28
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
47
|
0 && (module.exports = {
|
|
48
|
+
LazyDropdown,
|
|
30
49
|
...require("./AddSubModelButton"),
|
|
31
50
|
...require("./utils")
|
|
32
51
|
});
|
|
@@ -44,7 +44,7 @@ __export(utils_exports, {
|
|
|
44
44
|
buildWrapperFieldChildren: () => buildWrapperFieldChildren
|
|
45
45
|
});
|
|
46
46
|
module.exports = __toCommonJS(utils_exports);
|
|
47
|
-
var
|
|
47
|
+
var import_lodash = __toESM(require("lodash"));
|
|
48
48
|
var import_utils = require("../../utils");
|
|
49
49
|
async function callHideFunction(hide, ctx) {
|
|
50
50
|
if (typeof hide === "function") {
|
|
@@ -107,7 +107,7 @@ function buildSubModelChildren(M, ctx) {
|
|
|
107
107
|
const extraArg = args && args.length > 0 ? args[args.length - 1] : void 0;
|
|
108
108
|
const defaultOpts = await (0, import_utils.resolveCreateModelOptions)(meta == null ? void 0 : meta.createModelOptions, ctx, extraArg);
|
|
109
109
|
const childOpts = await (0, import_utils.resolveCreateModelOptions)(src, ctx, extraArg);
|
|
110
|
-
return
|
|
110
|
+
return import_lodash.default.merge({}, import_lodash.default.cloneDeep(defaultOpts), childOpts);
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
return node;
|
|
@@ -15,11 +15,49 @@ export interface DataSourceOptions extends Record<string, any> {
|
|
|
15
15
|
description?: string;
|
|
16
16
|
[key: string]: any;
|
|
17
17
|
}
|
|
18
|
+
export type DataSourceRequester = (options: Record<string, any>) => Promise<any>;
|
|
19
|
+
export interface DataSourceLoadResult {
|
|
20
|
+
collections?: CollectionOptions[];
|
|
21
|
+
dataSources?: Array<DataSourceOptions & {
|
|
22
|
+
collections?: CollectionOptions[];
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export type DataSourceLoader = (context: {
|
|
26
|
+
key: string;
|
|
27
|
+
manager: DataSourceManager;
|
|
28
|
+
}) => Promise<DataSourceLoadResult>;
|
|
18
29
|
export declare class DataSourceManager {
|
|
19
30
|
dataSources: Map<string, DataSource>;
|
|
20
31
|
flowEngine: FlowEngine;
|
|
32
|
+
requester?: DataSourceRequester;
|
|
33
|
+
collectionFieldInterfaceManager?: {
|
|
34
|
+
addFieldInterfaces?: (fieldInterfaceClasses?: any[]) => void;
|
|
35
|
+
addFieldInterfaceGroups?: (groups: Record<string, {
|
|
36
|
+
label: string;
|
|
37
|
+
order?: number;
|
|
38
|
+
}>) => void;
|
|
39
|
+
addFieldInterfaceComponentOption?: (name: string, option: any) => void;
|
|
40
|
+
addFieldInterfaceOperator?: (name: string, operator: any) => void;
|
|
41
|
+
getFieldInterface?: (name: string) => any;
|
|
42
|
+
};
|
|
43
|
+
loaders: Map<string, DataSourceLoader>;
|
|
44
|
+
loadedKeys: Set<string>;
|
|
45
|
+
loadingKeys: Set<string>;
|
|
46
|
+
loadErrors: Map<string, Error>;
|
|
47
|
+
loadingPromise: Promise<void> | null;
|
|
21
48
|
constructor();
|
|
22
49
|
setFlowEngine(flowEngine: FlowEngine): void;
|
|
50
|
+
setRequester(requester?: DataSourceRequester): void;
|
|
51
|
+
setCollectionFieldInterfaceManager(manager: DataSourceManager['collectionFieldInterfaceManager']): void;
|
|
52
|
+
addFieldInterfaces(fieldInterfaceClasses?: any[]): void;
|
|
53
|
+
addFieldInterfaceGroups(groups: Record<string, {
|
|
54
|
+
label: string;
|
|
55
|
+
order?: number;
|
|
56
|
+
}>): void;
|
|
57
|
+
addFieldInterfaceComponentOption(name: string, option: any): void;
|
|
58
|
+
addFieldInterfaceOperator(name: string, operator: any): void;
|
|
59
|
+
registerLoader(key: string, loader: DataSourceLoader): void;
|
|
60
|
+
removeLoader(key: string): void;
|
|
23
61
|
addDataSource(ds: DataSource | DataSourceOptions): void;
|
|
24
62
|
upsertDataSource(ds: DataSource | DataSourceOptions): void;
|
|
25
63
|
removeDataSource(key: string): void;
|
|
@@ -28,7 +66,32 @@ export declare class DataSourceManager {
|
|
|
28
66
|
getDataSource(key: string): DataSource | undefined;
|
|
29
67
|
getCollection(dataSourceKey: string, collectionName: string): Collection | undefined;
|
|
30
68
|
getCollectionField(fieldPathWithDataSource: string): CollectionField;
|
|
69
|
+
ensureLoaded(options?: {
|
|
70
|
+
force?: boolean;
|
|
71
|
+
keys?: string[];
|
|
72
|
+
}): Promise<void>;
|
|
73
|
+
reload(options?: {
|
|
74
|
+
keys?: string[];
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
reloadDataSource(key: string): Promise<void>;
|
|
77
|
+
protected resolveLoadKeys(requestedKeys?: string[]): string[];
|
|
78
|
+
protected getApp(): {
|
|
79
|
+
eventBus?: EventTarget;
|
|
80
|
+
};
|
|
81
|
+
protected dispatchDataSourceEvent(type: 'dataSource:loaded' | 'dataSource:loadFailed', detail: {
|
|
82
|
+
dataSourceKey: string;
|
|
83
|
+
initial: boolean;
|
|
84
|
+
error?: Error;
|
|
85
|
+
}): void;
|
|
86
|
+
protected setDataSourceState(key: string, options: Partial<Pick<DataSourceOptions, 'status' | 'errorMessage'>> & Record<string, any>): void;
|
|
87
|
+
protected applyDataSourceLoadResult(key: string, result: DataSourceLoadResult): void;
|
|
88
|
+
protected loadKey(key: string, options: {
|
|
89
|
+
initial: boolean;
|
|
90
|
+
force: boolean;
|
|
91
|
+
}): Promise<void>;
|
|
31
92
|
}
|
|
93
|
+
export type CollectionFieldInterfaceDataSourceManager = Pick<DataSourceManager, 'collectionFieldInterfaceManager'>;
|
|
94
|
+
export declare function getCollectionFieldInterface(interfaceName: string | undefined, ...dataSourceManagers: Array<CollectionFieldInterfaceDataSourceManager | null | undefined>): any;
|
|
32
95
|
export declare class DataSource {
|
|
33
96
|
dataSourceManager: DataSourceManager;
|
|
34
97
|
collectionManager: CollectionManager;
|
|
@@ -38,6 +101,8 @@ export declare class DataSource {
|
|
|
38
101
|
get displayName(): any;
|
|
39
102
|
get key(): any;
|
|
40
103
|
get name(): any;
|
|
104
|
+
get status(): any;
|
|
105
|
+
get errorMessage(): any;
|
|
41
106
|
setDataSourceManager(dataSourceManager: DataSourceManager): void;
|
|
42
107
|
getCollections(): Collection[];
|
|
43
108
|
getCollection(name: string): Collection | undefined;
|
|
@@ -52,9 +117,14 @@ export declare class DataSource {
|
|
|
52
117
|
upsertCollections(collections: CollectionOptions[], options?: {
|
|
53
118
|
clearFields?: boolean;
|
|
54
119
|
}): void;
|
|
120
|
+
setCollections(collections: CollectionOptions[], options?: {
|
|
121
|
+
clearFields?: boolean;
|
|
122
|
+
}): void;
|
|
55
123
|
removeCollection(name: string): void;
|
|
56
124
|
clearCollections(): void;
|
|
57
125
|
setOptions(newOptions?: any): void;
|
|
126
|
+
patchOptions(newOptions?: any): void;
|
|
127
|
+
reload(): Promise<void>;
|
|
58
128
|
getCollectionField(fieldPath: string): CollectionField;
|
|
59
129
|
}
|
|
60
130
|
export interface CollectionOptions {
|
|
@@ -72,6 +142,7 @@ export declare class CollectionManager {
|
|
|
72
142
|
notSupportView?: string[];
|
|
73
143
|
};
|
|
74
144
|
constructor(dataSource: DataSource);
|
|
145
|
+
protected resetCaches(): void;
|
|
75
146
|
get flowEngine(): FlowEngine;
|
|
76
147
|
addCollection(collection: Collection | CollectionOptions): void;
|
|
77
148
|
removeCollection(name: string): void;
|
|
@@ -82,6 +153,9 @@ export declare class CollectionManager {
|
|
|
82
153
|
upsertCollections(collections: CollectionOptions[], options?: {
|
|
83
154
|
clearFields?: boolean;
|
|
84
155
|
}): void;
|
|
156
|
+
setCollections(collections: CollectionOptions[], options?: {
|
|
157
|
+
clearFields?: boolean;
|
|
158
|
+
}): void;
|
|
85
159
|
sortCollectionsByInherits(collections: CollectionOptions[]): CollectionOptions[];
|
|
86
160
|
getCollection(name: string): Collection | undefined;
|
|
87
161
|
getCollections(): Collection[];
|
|
@@ -116,6 +190,7 @@ export declare class Collection {
|
|
|
116
190
|
setOptions(newOptions?: any, options?: {
|
|
117
191
|
clearFields?: boolean;
|
|
118
192
|
}): void;
|
|
193
|
+
setOption(key: string, value: any): void;
|
|
119
194
|
getFields(): CollectionField[];
|
|
120
195
|
getToOneAssociationFields(): CollectionField[];
|
|
121
196
|
getAssociationFields(types?: any[]): CollectionField[];
|