@nocobase/flow-engine 2.1.0-beta.25 → 2.1.0-beta.26

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.
@@ -851,6 +851,18 @@ const findCellByPath = /* @__PURE__ */ __name((layout, path) => {
851
851
  }
852
852
  return null;
853
853
  }, "findCellByPath");
854
+ const findCellByPathOrClosestAncestor = /* @__PURE__ */ __name((layout, path) => {
855
+ if (!(path == null ? void 0 : path.length)) {
856
+ return null;
857
+ }
858
+ for (let length = path.length; length > 0; length -= 1) {
859
+ const target = findCellByPath(layout, path.slice(0, length));
860
+ if (target) {
861
+ return target;
862
+ }
863
+ }
864
+ return null;
865
+ }, "findCellByPathOrClosestAncestor");
854
866
  const removeItemFromGridLayout = /* @__PURE__ */ __name((layout, sourceUid) => {
855
867
  const removeFromRows = /* @__PURE__ */ __name((rows) => rows.map((row) => {
856
868
  const cellsWithSizes = row.cells.map((cell, index) => {
@@ -918,7 +930,7 @@ const simulateGridLayoutForSlot = /* @__PURE__ */ __name(({
918
930
  removeItemFromGridLayout(cloned, sourceUid);
919
931
  switch (slot.type) {
920
932
  case "column": {
921
- const target = findCellByPath(cloned, targetPath);
933
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
922
934
  if (!target) {
923
935
  break;
924
936
  }
@@ -934,7 +946,7 @@ const simulateGridLayoutForSlot = /* @__PURE__ */ __name(({
934
946
  break;
935
947
  }
936
948
  case "empty-column": {
937
- const target = findCellByPath(cloned, targetPath);
949
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
938
950
  if (target) {
939
951
  delete target.cell.rows;
940
952
  target.cell.items = [sourceUid];
@@ -942,7 +954,7 @@ const simulateGridLayoutForSlot = /* @__PURE__ */ __name(({
942
954
  break;
943
955
  }
944
956
  case "column-edge": {
945
- const target = findCellByPath(cloned, targetPath);
957
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
946
958
  if (!target) {
947
959
  break;
948
960
  }
@@ -969,7 +981,7 @@ const simulateGridLayoutForSlot = /* @__PURE__ */ __name(({
969
981
  if (!targetItemUid) {
970
982
  break;
971
983
  }
972
- const target = findCellByPath(cloned, targetPath);
984
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
973
985
  if (!(target == null ? void 0 : target.cell.items)) {
974
986
  break;
975
987
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.1.0-beta.25",
3
+ "version": "2.1.0-beta.26",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@formily/antd-v5": "1.x",
10
10
  "@formily/reactive": "2.x",
11
- "@nocobase/sdk": "2.1.0-beta.25",
12
- "@nocobase/shared": "2.1.0-beta.25",
11
+ "@nocobase/sdk": "2.1.0-beta.26",
12
+ "@nocobase/shared": "2.1.0-beta.26",
13
13
  "ahooks": "^3.7.2",
14
14
  "axios": "^1.7.0",
15
15
  "dayjs": "^1.11.9",
@@ -37,5 +37,5 @@
37
37
  ],
38
38
  "author": "NocoBase Team",
39
39
  "license": "Apache-2.0",
40
- "gitHead": "824f8b8200e9fe086135768934d3ef427b212446"
40
+ "gitHead": "b17e1a72057813fa27d8435bf0f2af67ea4b059f"
41
41
  }
@@ -829,6 +829,52 @@ describe('simulateLayoutForSlot', () => {
829
829
  expect(nestedRows[1].sizes).toEqual([12, 12]);
830
830
  });
831
831
 
832
+ it('keeps nested column insertion target when removing a sibling collapses the original path', () => {
833
+ const layout = createLayout(
834
+ {
835
+ vyvfw2jw071: [['6ad3ccaabd5', 'ff8b4b57f65']],
836
+ ablhoqw51gb: [['21b422021b8']],
837
+ },
838
+ {
839
+ vyvfw2jw071: [24],
840
+ ablhoqw51gb: [24],
841
+ },
842
+ ['vyvfw2jw071', 'ablhoqw51gb'],
843
+ );
844
+ layout.layout = normalizeGridLayout({
845
+ rows: layout.rows,
846
+ sizes: layout.sizes,
847
+ rowOrder: layout.rowOrder,
848
+ itemUids: ['6ad3ccaabd5', 'ff8b4b57f65', '21b422021b8'],
849
+ });
850
+
851
+ const slot: LayoutSlot = {
852
+ type: 'column',
853
+ rowId: 'll5vo5pzj3u',
854
+ columnIndex: 0,
855
+ insertIndex: 1,
856
+ position: 'after',
857
+ path: [
858
+ { rowId: 'vyvfw2jw071', cellId: 'vyvfw2jw071:cell:0' },
859
+ { rowId: 'll5vo5pzj3u', cellId: 'ghy612j5zzg' },
860
+ ],
861
+ rect,
862
+ };
863
+
864
+ const result = simulateLayoutForSlot({ slot, sourceUid: 'ff8b4b57f65', layout });
865
+
866
+ expect(result.layout!.rows).toMatchObject([
867
+ {
868
+ id: 'vyvfw2jw071',
869
+ cells: [{ items: ['6ad3ccaabd5', 'ff8b4b57f65'] }],
870
+ },
871
+ {
872
+ id: 'ablhoqw51gb',
873
+ cells: [{ items: ['21b422021b8'] }],
874
+ },
875
+ ]);
876
+ });
877
+
832
878
  it('treats dragging an item to its own item-edge as no-op', () => {
833
879
  const layout = createLayout(
834
880
  {
@@ -1146,6 +1146,21 @@ const findCellByPath = (layout: GridLayoutV2, path?: GridLayoutPath) => {
1146
1146
  return null;
1147
1147
  };
1148
1148
 
1149
+ const findCellByPathOrClosestAncestor = (layout: GridLayoutV2, path?: GridLayoutPath) => {
1150
+ if (!path?.length) {
1151
+ return null;
1152
+ }
1153
+
1154
+ for (let length = path.length; length > 0; length -= 1) {
1155
+ const target = findCellByPath(layout, path.slice(0, length));
1156
+ if (target) {
1157
+ return target;
1158
+ }
1159
+ }
1160
+
1161
+ return null;
1162
+ };
1163
+
1149
1164
  const removeItemFromGridLayout = (layout: GridLayoutV2, sourceUid: string) => {
1150
1165
  const removeFromRows = (rows: GridRowV2[]): GridRowV2[] =>
1151
1166
  rows
@@ -1231,7 +1246,7 @@ const simulateGridLayoutForSlot = ({
1231
1246
 
1232
1247
  switch (slot.type) {
1233
1248
  case 'column': {
1234
- const target = findCellByPath(cloned, targetPath);
1249
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
1235
1250
  if (!target) {
1236
1251
  break;
1237
1252
  }
@@ -1247,7 +1262,7 @@ const simulateGridLayoutForSlot = ({
1247
1262
  break;
1248
1263
  }
1249
1264
  case 'empty-column': {
1250
- const target = findCellByPath(cloned, targetPath);
1265
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
1251
1266
  if (target) {
1252
1267
  delete target.cell.rows;
1253
1268
  target.cell.items = [sourceUid];
@@ -1255,7 +1270,7 @@ const simulateGridLayoutForSlot = ({
1255
1270
  break;
1256
1271
  }
1257
1272
  case 'column-edge': {
1258
- const target = findCellByPath(cloned, targetPath);
1273
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
1259
1274
  if (!target) {
1260
1275
  break;
1261
1276
  }
@@ -1282,7 +1297,7 @@ const simulateGridLayoutForSlot = ({
1282
1297
  if (!targetItemUid) {
1283
1298
  break;
1284
1299
  }
1285
- const target = findCellByPath(cloned, targetPath);
1300
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
1286
1301
  if (!target?.cell.items) {
1287
1302
  break;
1288
1303
  }