@nocobase/flow-engine 2.0.0-alpha.3 → 2.0.0-alpha.5

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.
@@ -1,302 +0,0 @@
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 __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
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
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var moveBlock_exports = {};
39
- __export(moveBlock_exports, {
40
- findModelUidPosition: () => findModelUidPosition,
41
- moveBlock: () => moveBlock,
42
- positionToDirection: () => positionToDirection
43
- });
44
- module.exports = __toCommonJS(moveBlock_exports);
45
- var import_shared = require("@formily/shared");
46
- var import_lodash = __toESM(require("lodash"));
47
- var import_getMousePositionOnElement = require("./getMousePositionOnElement");
48
- const findModelUidPosition = /* @__PURE__ */ __name((uid2, rows) => {
49
- let result = null;
50
- for (const [rowId, columns] of Object.entries(rows)) {
51
- for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
52
- const column = columns[columnIndex];
53
- for (let itemIndex = 0; itemIndex < column.length; itemIndex++) {
54
- if (column[itemIndex] === uid2) {
55
- result = { rowId, columnIndex, itemIndex };
56
- }
57
- }
58
- }
59
- }
60
- return result;
61
- }, "findModelUidPosition");
62
- const moveBlock = /* @__PURE__ */ __name(({
63
- sourceUid,
64
- targetUid,
65
- direction,
66
- layoutData
67
- }) => {
68
- var _a;
69
- const { rows, sizes } = layoutData;
70
- const newSizes = import_lodash.default.cloneDeep(sizes);
71
- let newRows = import_lodash.default.cloneDeep(rows);
72
- let sourcePosition = null;
73
- let targetPosition = null;
74
- for (const [rowId, columns] of Object.entries(newRows)) {
75
- for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
76
- const column = columns[columnIndex];
77
- for (let itemIndex = 0; itemIndex < column.length; itemIndex++) {
78
- if (column[itemIndex] === sourceUid) {
79
- sourcePosition = { rowId, columnIndex, itemIndex };
80
- }
81
- if (column[itemIndex] === targetUid) {
82
- targetPosition = { rowId, columnIndex, itemIndex };
83
- }
84
- }
85
- }
86
- }
87
- if (!sourcePosition || !targetPosition) {
88
- return layoutData;
89
- }
90
- const removeOldSourceUid = /* @__PURE__ */ __name(() => {
91
- var _a2, _b;
92
- newRows[sourcePosition.rowId][sourcePosition.columnIndex].splice(sourcePosition.itemIndex, 1);
93
- if (newRows[sourcePosition.rowId][sourcePosition.columnIndex].length === 0) {
94
- (_a2 = newRows[sourcePosition.rowId]) == null ? void 0 : _a2.splice(sourcePosition.columnIndex, 1);
95
- (_b = newSizes[sourcePosition.rowId]) == null ? void 0 : _b.splice(sourcePosition.columnIndex, 1);
96
- }
97
- if (newRows[sourcePosition.rowId].length === 0) {
98
- delete newRows[sourcePosition.rowId];
99
- delete newSizes[sourcePosition.rowId];
100
- }
101
- for (const [rowId, columns] of Object.entries(newRows)) {
102
- for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
103
- const column = columns[columnIndex];
104
- for (let itemIndex = 0; itemIndex < column.length; itemIndex++) {
105
- if (column[itemIndex] === sourceUid) {
106
- sourcePosition = { rowId, columnIndex, itemIndex };
107
- }
108
- if (column[itemIndex] === targetUid) {
109
- targetPosition = { rowId, columnIndex, itemIndex };
110
- }
111
- }
112
- }
113
- }
114
- }, "removeOldSourceUid");
115
- switch (direction) {
116
- case "insert-row-above": {
117
- if (targetPosition.itemIndex > 0) {
118
- return layoutData;
119
- }
120
- removeOldSourceUid();
121
- const newRowId = (0, import_shared.uid)();
122
- newRows = insertKey({
123
- obj: newRows,
124
- newKey: newRowId,
125
- newValue: [[sourceUid]],
126
- referenceKey: targetPosition.rowId,
127
- position: "before"
128
- });
129
- newSizes[newRowId] = [24];
130
- break;
131
- }
132
- case "insert-row-below": {
133
- const nextRowKey = getNextKey(newRows, targetPosition.rowId);
134
- if (nextRowKey === sourcePosition.rowId && newRows[nextRowKey].length === 1) {
135
- return layoutData;
136
- }
137
- removeOldSourceUid();
138
- const newRowId = (0, import_shared.uid)();
139
- newRows = insertKey({
140
- obj: newRows,
141
- newKey: newRowId,
142
- newValue: [[sourceUid]],
143
- referenceKey: targetPosition.rowId,
144
- position: "after"
145
- });
146
- newSizes[newRowId] = [24];
147
- break;
148
- }
149
- case "insert-same-column-above": {
150
- removeOldSourceUid();
151
- const column = newRows[targetPosition.rowId][targetPosition.columnIndex];
152
- if (column[targetPosition.itemIndex - 1] === sourceUid) {
153
- return layoutData;
154
- }
155
- column.splice(targetPosition.itemIndex, 0, sourceUid);
156
- break;
157
- }
158
- case "insert-same-column-below": {
159
- removeOldSourceUid();
160
- const column = newRows[targetPosition.rowId][targetPosition.columnIndex];
161
- if (column[targetPosition.itemIndex + 1] === sourceUid) {
162
- return layoutData;
163
- }
164
- column.splice(targetPosition.itemIndex + 1, 0, sourceUid);
165
- break;
166
- }
167
- case "insert-column-left": {
168
- removeOldSourceUid();
169
- newRows[targetPosition.rowId].splice(targetPosition.columnIndex, 0, [sourceUid]);
170
- const currentSizes = newSizes[targetPosition.rowId] || [];
171
- const columnCount = newRows[targetPosition.rowId].length || 0;
172
- const newColumnWidth = Math.floor(24 / columnCount);
173
- const remainingWidth = 24 - newColumnWidth;
174
- const totalOldWidth = currentSizes.reduce((sum, size) => sum + size, 0);
175
- const adjustedSizes = currentSizes.map((size) => Math.floor(size / totalOldWidth * remainingWidth));
176
- adjustedSizes.splice(targetPosition.columnIndex, 0, newColumnWidth);
177
- const totalNewWidth = adjustedSizes.reduce((sum, size) => sum + size, 0);
178
- if (totalNewWidth < 24) {
179
- adjustedSizes[adjustedSizes.length - 1] += 24 - totalNewWidth;
180
- }
181
- newSizes[targetPosition.rowId] = adjustedSizes;
182
- break;
183
- }
184
- case "insert-column-right": {
185
- removeOldSourceUid();
186
- newRows[targetPosition.rowId].splice(targetPosition.columnIndex + 1, 0, [sourceUid]);
187
- const currentSizes = newSizes[targetPosition.rowId] || [];
188
- const columnCount = ((_a = newRows[targetPosition.rowId]) == null ? void 0 : _a.length) || 0;
189
- const newColumnWidth = Math.floor(24 / columnCount);
190
- const remainingWidth = 24 - newColumnWidth;
191
- const totalOldWidth = currentSizes.reduce((sum, size) => sum + size, 0);
192
- const adjustedSizes = currentSizes.map((size) => Math.floor(size / totalOldWidth * remainingWidth));
193
- adjustedSizes.splice(targetPosition.columnIndex + 1, 0, newColumnWidth);
194
- const totalNewWidth = adjustedSizes.reduce((sum, size) => sum + size, 0);
195
- if (totalNewWidth < 24) {
196
- adjustedSizes[adjustedSizes.length - 1] += 24 - totalNewWidth;
197
- }
198
- newSizes[targetPosition.rowId] = adjustedSizes;
199
- break;
200
- }
201
- }
202
- return recalculateAllRowSizesWithProportion({ rows: newRows, sizes: newSizes });
203
- }, "moveBlock");
204
- const positionToDirection = /* @__PURE__ */ __name((position) => {
205
- switch (position) {
206
- case import_getMousePositionOnElement.ElementPosition.TOP:
207
- return "insert-same-column-above";
208
- case import_getMousePositionOnElement.ElementPosition.BOTTOM:
209
- return "insert-same-column-below";
210
- case import_getMousePositionOnElement.ElementPosition.LEFT:
211
- return "insert-column-left";
212
- case import_getMousePositionOnElement.ElementPosition.RIGHT:
213
- return "insert-column-right";
214
- case import_getMousePositionOnElement.ElementPosition.TOP_EDGE:
215
- return "insert-row-above";
216
- case import_getMousePositionOnElement.ElementPosition.BOTTOM_EDGE:
217
- return "insert-row-below";
218
- case import_getMousePositionOnElement.ElementPosition.LEFT_EDGE:
219
- return "insert-column-left";
220
- case import_getMousePositionOnElement.ElementPosition.RIGHT_EDGE:
221
- return "insert-column-right";
222
- default:
223
- throw new Error(`Unsupported position: ${position}`);
224
- }
225
- }, "positionToDirection");
226
- function insertKey({
227
- obj,
228
- newKey,
229
- newValue,
230
- referenceKey,
231
- position
232
- }) {
233
- const result = {};
234
- for (const [key, value] of Object.entries(obj)) {
235
- if (position === "before" && key === referenceKey) {
236
- result[newKey] = newValue;
237
- }
238
- result[key] = value;
239
- if (position === "after" && key === referenceKey) {
240
- result[newKey] = newValue;
241
- }
242
- }
243
- return result;
244
- }
245
- __name(insertKey, "insertKey");
246
- function getNextKey(obj, currentKey) {
247
- const keys = Object.keys(obj);
248
- const index = keys.indexOf(currentKey);
249
- return index >= 0 && index < keys.length - 1 ? keys[index + 1] : null;
250
- }
251
- __name(getNextKey, "getNextKey");
252
- function recalculateAllRowSizesWithProportion(layoutData) {
253
- const { rows, sizes } = layoutData;
254
- const newSizes = import_lodash.default.cloneDeep(sizes);
255
- for (const [rowId, columns] of Object.entries(rows)) {
256
- const columnCount = columns.length;
257
- const currentSizes = sizes[rowId] || [];
258
- if (columnCount === 0) {
259
- continue;
260
- }
261
- if (currentSizes.length !== columnCount || currentSizes.every((size) => size === 0)) {
262
- const baseWidth = Math.floor(24 / columnCount);
263
- const remainder = 24 % columnCount;
264
- const newRowSizes = new Array(columnCount).fill(baseWidth);
265
- for (let i = 0; i < remainder; i++) {
266
- newRowSizes[i] += 1;
267
- }
268
- newSizes[rowId] = newRowSizes;
269
- continue;
270
- }
271
- const currentTotal = currentSizes.reduce((sum, size) => sum + size, 0);
272
- if (currentTotal === 0) {
273
- const baseWidth = Math.floor(24 / columnCount);
274
- const remainder = 24 % columnCount;
275
- const newRowSizes = new Array(columnCount).fill(baseWidth);
276
- for (let i = 0; i < remainder; i++) {
277
- newRowSizes[i] += 1;
278
- }
279
- newSizes[rowId] = newRowSizes;
280
- } else {
281
- const newRowSizes = currentSizes.map((size) => Math.floor(size / currentTotal * 24));
282
- const actualTotal = newRowSizes.reduce((sum, size) => sum + size, 0);
283
- const diff = 24 - actualTotal;
284
- for (let i = newRowSizes.length - 1; i >= 0 && diff > 0; i--) {
285
- const add = Math.min(diff, 1);
286
- newRowSizes[i] += add;
287
- }
288
- newSizes[rowId] = newRowSizes;
289
- }
290
- }
291
- return {
292
- rows,
293
- sizes: newSizes
294
- };
295
- }
296
- __name(recalculateAllRowSizesWithProportion, "recalculateAllRowSizesWithProportion");
297
- // Annotate the CommonJS export names for ESM import in node:
298
- 0 && (module.exports = {
299
- findModelUidPosition,
300
- moveBlock,
301
- positionToDirection
302
- });
@@ -1,115 +0,0 @@
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
- // 定义位置枚举
11
- export enum ElementPosition {
12
- TOP = 'top',
13
- BOTTOM = 'bottom',
14
- LEFT = 'left',
15
- RIGHT = 'right',
16
- TOP_EDGE = 'top-edge',
17
- BOTTOM_EDGE = 'bottom-edge',
18
- LEFT_EDGE = 'left-edge',
19
- RIGHT_EDGE = 'right-edge',
20
- }
21
-
22
- interface MousePosition {
23
- x: number;
24
- y: number;
25
- }
26
-
27
- interface ElementBounds {
28
- x: number; // 左上角x坐标
29
- y: number; // 左上角y坐标
30
- width: number; // 元素宽度
31
- height: number; // 元素高度
32
- }
33
-
34
- interface GetMousePositionOptions {
35
- initialMousePos: MousePosition;
36
- mouseOffset: MousePosition;
37
- elementBounds: ElementBounds;
38
- edgeThreshold?: number; // 边缘区域厚度,默认为5px
39
- topBottomHeightRatio?: number; // 上下区域高度占比,默认为0.25(四分之一)
40
- }
41
-
42
- /**
43
- * 计算鼠标指针在元素上的位置
44
- *
45
- * 区域划分逻辑:
46
- * 1. 上区域:宽度=元素宽度,高度=元素高度*topBottomHeightRatio,位于元素顶部
47
- * 2. 下区域:宽度=元素宽度,高度=元素高度*topBottomHeightRatio,位于元素底部
48
- * 3. 左区域:剩余中间部分的左侧
49
- * 4. 右区域:剩余中间部分的右侧
50
- * 5. 边缘区域:在各个区域的边缘处,厚度为edgeThreshold
51
- *
52
- * @param options 配置选项
53
- * @returns 鼠标在元素上的位置
54
- */
55
- export const getMousePositionOnElement = ({
56
- initialMousePos,
57
- mouseOffset,
58
- elementBounds,
59
- edgeThreshold = 5,
60
- topBottomHeightRatio = 0.25,
61
- }: GetMousePositionOptions): ElementPosition => {
62
- // 计算当前鼠标的实际坐标
63
- const currentMouseX = initialMousePos.x + mouseOffset.x;
64
- const currentMouseY = initialMousePos.y + mouseOffset.y;
65
-
66
- // 计算鼠标相对于元素的坐标
67
- const relativeX = currentMouseX - elementBounds.x;
68
- const relativeY = currentMouseY - elementBounds.y;
69
-
70
- // 如果鼠标不在元素范围内,返回最接近的方向
71
- if (relativeX < 0 || relativeX > elementBounds.width || relativeY < 0 || relativeY > elementBounds.height) {
72
- if (relativeY < 0) return ElementPosition.TOP;
73
- if (relativeY > elementBounds.height) return ElementPosition.BOTTOM;
74
- if (relativeX < 0) return ElementPosition.LEFT;
75
- return ElementPosition.RIGHT;
76
- }
77
-
78
- // 计算区域边界
79
- const topBottomHeight = elementBounds.height * topBottomHeightRatio;
80
- const middleAreaTop = topBottomHeight;
81
- const middleAreaBottom = elementBounds.height - topBottomHeight;
82
- const middleAreaHeight = middleAreaBottom - middleAreaTop;
83
-
84
- // 判断在哪个主要区域
85
- if (relativeY <= topBottomHeight) {
86
- // 上区域
87
- if (relativeY <= edgeThreshold) {
88
- return ElementPosition.TOP_EDGE;
89
- }
90
- return ElementPosition.TOP;
91
- } else if (relativeY >= middleAreaBottom) {
92
- // 下区域
93
- if (relativeY >= elementBounds.height - edgeThreshold) {
94
- return ElementPosition.BOTTOM_EDGE;
95
- }
96
- return ElementPosition.BOTTOM;
97
- } else {
98
- // 中间区域(左右区域)
99
- const middleAreaCenterX = elementBounds.width / 2;
100
-
101
- if (relativeX <= middleAreaCenterX) {
102
- // 左区域
103
- if (relativeX <= edgeThreshold) {
104
- return ElementPosition.LEFT_EDGE;
105
- }
106
- return ElementPosition.LEFT;
107
- } else {
108
- // 右区域
109
- if (relativeX >= elementBounds.width - edgeThreshold) {
110
- return ElementPosition.RIGHT_EDGE;
111
- }
112
- return ElementPosition.RIGHT;
113
- }
114
- }
115
- };