@fileverse-dev/fortune-react 1.2.42 → 1.2.44

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.
@@ -30,6 +30,9 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
30
30
  context = _a.context,
31
31
  setContext = _a.setContext,
32
32
  refs = _a.refs;
33
+ var selectedColWidth = useRef(0);
34
+ var selectedSourceColRef = useRef([]);
35
+ var selectedTargetColRef = useRef([]);
33
36
  var dragRef = useRef({
34
37
  mouseDown: false,
35
38
  startX: 0,
@@ -142,6 +145,7 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
142
145
  });
143
146
  if (selectedBlock) {
144
147
  ghostWidthPx = Math.max(60, selectedBlock.col - selectedBlock.col_pre - 1);
148
+ selectedColWidth.current = ghostWidthPx;
145
149
  var count = selectedBlock.c2 - selectedBlock.c1 + 1;
146
150
  ghostLabel = count > 1 ? "".concat(count, " cols") : "Col ".concat(String.fromCharCode(65 + selectedBlock.c1));
147
151
  } else {
@@ -150,6 +154,7 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
150
154
  end = _a[1];
151
155
  var sourceColWidth = end - pre - 1;
152
156
  ghostWidthPx = Math.max(60, sourceColWidth);
157
+ selectedColWidth.current = ghostWidthPx;
153
158
  }
154
159
  el.style.width = "".concat(ghostWidthPx, "px");
155
160
  el.textContent = ghostLabel;
@@ -183,28 +188,30 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
183
188
  var dragOffset = Math.abs(ev.pageX - dragRef.current.startX);
184
189
  if (!isDragActivated(host, dragOffset)) return;
185
190
  var lineLeftPx = computeInsertionFromPageX(ev.pageX).lineLeftPx;
186
- var ghostPosOffset = dragRef.current.startX > ev.pageX ? 0 : 80;
191
+ var ghostPosOffset = 60;
192
+ var ghostFinalPos = dragRef.current.startX > ev.pageX ? lineLeftPx + ghostPosOffset : lineLeftPx - (selectedColWidth.current - ghostPosOffset);
187
193
  if (dragRef.current.lineEl) {
188
194
  dragRef.current.lineEl.style.left = "".concat(lineLeftPx, "px");
189
195
  }
190
196
  if (dragRef.current.ghostEl) {
191
- dragRef.current.ghostEl.style.left = "".concat(ev.pageX - ghostPosOffset, "px");
197
+ dragRef.current.ghostEl.style.left = "".concat(ghostFinalPos, "px");
192
198
  }
193
199
  };
194
200
  var handleColumnDragEnd = function handleColumnDragEnd(ev) {
201
+ var _a, _b, _c;
195
202
  if (!dragRef.current.mouseDown) return;
196
203
  dragRef.current.mouseDown = false;
197
204
  try {
198
205
  document.body.style.userSelect = dragRef.current.prevUserSelect || "";
199
206
  document.body.style.webkitUserSelect = dragRef.current.prevWebkitUserSelect || "";
200
- } catch (_a) {}
207
+ } catch (_d) {}
201
208
  if (dragRef.current.active) {
202
209
  var finalInsertionIndex_1 = computeInsertionFromPageX(ev.pageX).insertionIndex;
203
- var sourceIndex_1 = dragRef.current.source;
210
+ var sourceIndex_1 = ((_c = (_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.column) === null || _c === void 0 ? void 0 : _c[0]) || 0;
204
211
  var sheetIdx_1 = getSheetIndex(context, context.currentSheetId);
205
212
  if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
206
213
  setContext(function (draft) {
207
- var _a, _b, _c, _d;
214
+ var _a, _b, _c, _d, _e, _f, _g;
208
215
  var _sheet = draft.luckysheetfile[sheetIdx_1];
209
216
  if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
210
217
  var rows = _sheet.data;
@@ -213,50 +220,80 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
213
220
  if (sourceIndex_1 < 0 || sourceIndex_1 >= numCols) return;
214
221
  var targetIndex = finalInsertionIndex_1;
215
222
  if (targetIndex > sourceIndex_1) targetIndex -= 1;
216
- for (var i = 0; i < rows.length; i += 1) {
217
- var row = rows[i];
218
- if (!row || sourceIndex_1 >= row.length) continue;
219
- var cellData = row.splice(sourceIndex_1, 1)[0];
220
- if (targetIndex < 0) targetIndex = 0;
221
- if (targetIndex > row.length) targetIndex = row.length;
222
- row.splice(targetIndex, 0, cellData);
223
+ var selectedColRange = ((_d = (_c = context.luckysheet_select_save) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.column) || [];
224
+ var selectedSourceCol = [];
225
+ for (var i = selectedColRange === null || selectedColRange === void 0 ? void 0 : selectedColRange[0]; i <= (selectedColRange === null || selectedColRange === void 0 ? void 0 : selectedColRange[1]); i += 1) {
226
+ selectedSourceCol.push(i);
223
227
  }
228
+ var tempSelectedTargetCol = [];
229
+ selectedSourceCol.forEach(function (_, index) {
230
+ if (sourceIndex_1 < targetIndex) {
231
+ tempSelectedTargetCol.push(targetIndex - index);
232
+ } else {
233
+ tempSelectedTargetCol.push(targetIndex + index);
234
+ }
235
+ });
236
+ var selectedTargetCol = (_e = __spreadArray([], tempSelectedTargetCol, true)) === null || _e === void 0 ? void 0 : _e.sort(function (a, b) {
237
+ return a - b;
238
+ });
239
+ selectedSourceColRef.current = selectedSourceCol;
240
+ selectedTargetColRef.current = selectedTargetCol;
241
+ selectedSourceCol.forEach(function () {
242
+ var adjustedSourceIndex = sourceIndex_1;
243
+ if (targetIndex < sourceIndex_1) {
244
+ adjustedSourceIndex = sourceIndex_1 + (selectedSourceCol.length - 1);
245
+ }
246
+ for (var j = 0; j < rows.length; j += 1) {
247
+ var row = rows[j];
248
+ if (!row || adjustedSourceIndex >= row.length) continue;
249
+ var cellData = row.splice(adjustedSourceIndex, 1)[0];
250
+ if (targetIndex < 0) targetIndex = 0;
251
+ if (targetIndex > row.length) targetIndex = row.length;
252
+ row.splice(targetIndex, 0, cellData);
253
+ }
254
+ });
224
255
  _sheet.data = rows;
225
256
  updateContextWithSheetData(draft, _sheet.data);
226
257
  var d = getFlowdata(draft);
227
258
  d === null || d === void 0 ? void 0 : d.forEach(function (row) {
228
259
  row.forEach(function (cell) {
229
260
  if (cell) {
230
- var sourceColName = numberToColumnName(sourceIndex_1);
231
- var targetColName_1 = numberToColumnName(targetIndex);
232
- if (cell.f) {
233
- cell.f = cell.f.replace(new RegExp("\\b".concat(sourceColName, "(\\d+)\\b"), "g"), function (match, p1) {
234
- if (/^\d+$/.test(p1)) {
235
- return "".concat(targetColName_1).concat(p1);
236
- }
237
- return match;
238
- });
239
- }
240
- var otherAffectedCols = [];
261
+ var otherAffectedCols_1 = [];
241
262
  if (sourceIndex_1 < targetIndex) {
242
- for (var c = sourceIndex_1 + 1; c < targetIndex; c += 1) {
243
- otherAffectedCols.push({
263
+ var start = selectedSourceCol === null || selectedSourceCol === void 0 ? void 0 : selectedSourceCol[selectedSourceCol.length - 1];
264
+ var last = selectedTargetCol === null || selectedTargetCol === void 0 ? void 0 : selectedTargetCol[selectedTargetCol.length - 1];
265
+ for (var c = start + 1; c <= last; c += 1) {
266
+ otherAffectedCols_1.push({
244
267
  source: numberToColumnName(c),
245
- target: numberToColumnName(c - 1)
268
+ target: numberToColumnName(c - selectedSourceCol.length)
246
269
  });
247
270
  }
271
+ selectedSourceCol.forEach(function (c, index) {
272
+ otherAffectedCols_1.push({
273
+ source: numberToColumnName(c),
274
+ target: numberToColumnName(selectedTargetCol[index])
275
+ });
276
+ });
248
277
  } else if (sourceIndex_1 > targetIndex) {
249
- for (var c = targetIndex; c < sourceIndex_1; c += 1) {
250
- otherAffectedCols.push({
278
+ var start = selectedTargetCol === null || selectedTargetCol === void 0 ? void 0 : selectedTargetCol[0];
279
+ var last = selectedSourceCol === null || selectedSourceCol === void 0 ? void 0 : selectedSourceCol[0];
280
+ for (var c = start; c < last; c += 1) {
281
+ otherAffectedCols_1.push({
251
282
  source: numberToColumnName(c),
252
- target: numberToColumnName(c + 1)
283
+ target: numberToColumnName(c + selectedSourceCol.length)
253
284
  });
254
285
  }
286
+ selectedSourceCol.forEach(function (c, index) {
287
+ otherAffectedCols_1.push({
288
+ source: numberToColumnName(c),
289
+ target: numberToColumnName(selectedTargetCol[index])
290
+ });
291
+ });
255
292
  }
256
293
  if (cell.f) {
257
294
  var formula_1 = cell.f;
258
295
  var replacements_1 = [];
259
- otherAffectedCols.forEach(function (col) {
296
+ otherAffectedCols_1.forEach(function (col) {
260
297
  var regex = new RegExp("\\b".concat(col.source, "(\\d+)\\b"), "g");
261
298
  var match;
262
299
  while ((match = regex.exec(formula_1)) !== null) {
@@ -290,38 +327,38 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
290
327
  if (colRow.length !== 2) return;
291
328
  var presentcol = parseInt(colRow[1], 10);
292
329
  var updatedCol = presentcol;
293
- if (presentcol === sourceIndex_1) {
294
- updatedCol = targetIndex;
330
+ if (selectedSourceCol.includes(presentcol)) {
331
+ var index = selectedSourceCol.indexOf(presentcol);
332
+ var target = selectedTargetCol[index];
333
+ updatedCol = target;
295
334
  } else if (presentcol > sourceIndex_1 && presentcol < targetIndex) {
296
- updatedCol -= 1;
335
+ updatedCol -= selectedSourceCol.length;
297
336
  } else if (presentcol < sourceIndex_1 && presentcol >= targetIndex) {
298
- updatedCol += 1;
337
+ updatedCol += selectedSourceCol.length;
299
338
  }
300
339
  newDataVerification_1["".concat(colRow[0], "_").concat(updatedCol)] = itemData;
301
340
  });
302
341
  _sheet.dataVerification = newDataVerification_1;
303
342
  }
304
- (_c = _sheet.calcChain) === null || _c === void 0 ? void 0 : _c.forEach(function (item) {
305
- if (item.c === sourceIndex_1) {
306
- item.c = targetIndex;
343
+ (_f = _sheet.calcChain) === null || _f === void 0 ? void 0 : _f.forEach(function (item) {
344
+ if (selectedSourceCol.includes(item.c)) {
345
+ var index = selectedSourceCol.indexOf(item.c);
346
+ item.c = selectedTargetCol[index];
307
347
  } else if (item.c > sourceIndex_1 && item.c < targetIndex) {
308
- item.c -= 1;
348
+ item.c -= selectedSourceCol.length;
309
349
  } else if (item.c < sourceIndex_1 && item.c >= targetIndex) {
310
- item.c += 1;
350
+ item.c += selectedSourceCol.length;
311
351
  }
312
352
  });
313
- (_d = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _d === void 0 ? void 0 : _d.call(window, sourceIndex_1, targetIndex, "column", context.currentSheetId);
353
+ (_g = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _g === void 0 ? void 0 : _g.call(window, selectedSourceCol, selectedTargetCol, "column", context.currentSheetId, sourceIndex_1, targetIndex);
314
354
  });
315
- var targetIndex = finalInsertionIndex_1;
316
- if (targetIndex > sourceIndex_1) targetIndex -= 1;
317
- var selData = api.getSelection(context) || [];
318
- var sel_1 = __spreadArray([], selData, true);
319
- if (sel_1 && sel_1[0]) {
320
- sel_1[0].column = [targetIndex, targetIndex];
321
- }
355
+ var d = getFlowdata(context);
356
+ var rowLen_1 = (d === null || d === void 0 ? void 0 : d.length) || 0;
322
357
  setContext(function (draftCtx) {
323
- console.log("after update", sel_1);
324
- api.setSelection(draftCtx, sel_1, {
358
+ api.setSelection(draftCtx, [{
359
+ row: [0, rowLen_1],
360
+ column: selectedTargetColRef.current
361
+ }], {
325
362
  id: context.currentSheetId
326
363
  });
327
364
  });
@@ -21,6 +21,9 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
21
21
  context = _a.context,
22
22
  setContext = _a.setContext,
23
23
  refs = _a.refs;
24
+ var selectedRowHeight = useRef(0);
25
+ var selectedSourceRowRef = useRef([]);
26
+ var selectedTargetRowRef = useRef([]);
24
27
  var dragRef = useRef({
25
28
  mouseDown: false,
26
29
  startY: 0,
@@ -132,6 +135,7 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
132
135
  });
133
136
  if (selectedBlock) {
134
137
  ghostHeightPx = Math.max(24, selectedBlock.row - selectedBlock.row_pre - 1);
138
+ selectedRowHeight.current = ghostHeightPx;
135
139
  var count = selectedBlock.r2 - selectedBlock.r1 + 1;
136
140
  ghostLabel = count > 1 ? "".concat(count, " rows") : "".concat(selectedBlock.r1 + 1, " row");
137
141
  } else {
@@ -140,6 +144,7 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
140
144
  end = _a[1];
141
145
  var sourceRowHeight = end - pre - 1;
142
146
  ghostHeightPx = Math.max(24, sourceRowHeight);
147
+ selectedRowHeight.current = ghostHeightPx;
143
148
  }
144
149
  el.style.height = "".concat(ghostHeightPx, "px");
145
150
  el.textContent = ghostLabel;
@@ -166,6 +171,7 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
166
171
  return true;
167
172
  };
168
173
  var handleRowDrag = function handleRowDrag(ev) {
174
+ var _a, _b;
169
175
  if (!dragRef.current.mouseDown) return;
170
176
  dragRef.current.lastNativeEvent = ev;
171
177
  var host = containerRef.current;
@@ -173,72 +179,111 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
173
179
  var dragOffset = Math.abs(ev.pageY - dragRef.current.startY);
174
180
  if (!isDragActivated(host, dragOffset)) return;
175
181
  var lineTopPx = computeInsertionFromPageY(ev.pageY).lineTopPx;
176
- var ghostPosOffset = dragRef.current.startY > ev.pageY ? 0 : 25;
182
+ var rows = (_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.row;
183
+ var selectedRowLength = rows && rows[1] != null && rows[0] != null ? rows[1] - rows[0] + 1 : 0;
184
+ var off = 3 - selectedRowLength;
185
+ var bottomOff = (off + 1) * 25;
186
+ var topRowOff = selectedRowLength - 4;
187
+ var topOff = topRowOff * 25;
188
+ var ghostFinalPos = dragRef.current.startY > ev.pageY ? lineTopPx - topOff : lineTopPx + bottomOff;
177
189
  if (dragRef.current.lineEl) {
178
190
  dragRef.current.lineEl.style.top = "".concat(lineTopPx, "px");
179
191
  }
180
192
  if (dragRef.current.ghostEl) {
181
- dragRef.current.ghostEl.style.top = "".concat(ev.pageY - ghostPosOffset, "px");
193
+ dragRef.current.ghostEl.style.top = "".concat(ghostFinalPos, "px");
182
194
  }
183
195
  };
184
196
  var handleRowDragEnd = function handleRowDragEnd(ev) {
185
- var _a;
197
+ var _a, _b, _c, _d;
186
198
  if (!dragRef.current.mouseDown) return;
187
199
  dragRef.current.mouseDown = false;
188
200
  try {
189
201
  document.body.style.userSelect = dragRef.current.prevUserSelect || "";
190
202
  document.body.style.webkitUserSelect = dragRef.current.prevWebkitUserSelect || "";
191
- } catch (_b) {}
203
+ } catch (_e) {}
192
204
  if (dragRef.current.active) {
193
205
  var finalInsertionIndex_1 = computeInsertionFromPageY(ev.pageY).insertionIndex;
194
- var sourceIndex_1 = dragRef.current.source;
206
+ var sourceIndex_1 = ((_c = (_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.row) === null || _c === void 0 ? void 0 : _c[0]) || 0;
195
207
  var sheetIdx_1 = getSheetIndex(context, context.currentSheetId);
196
208
  if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
197
209
  setContext(function (draft) {
198
- var _a, _b;
210
+ var _a, _b, _c, _d, _e;
199
211
  var _sheet = draft.luckysheetfile[sheetIdx_1];
200
212
  if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
201
213
  var rows = _sheet.data;
202
214
  if (sourceIndex_1 < 0 || sourceIndex_1 >= rows.length) return;
203
215
  var targetIndex = finalInsertionIndex_1;
204
216
  if (targetIndex > sourceIndex_1) targetIndex -= 1;
205
- var rowData = rows.splice(sourceIndex_1, 1)[0];
206
- if (targetIndex < 0) targetIndex = 0;
207
- if (targetIndex > rows.length) targetIndex = rows.length;
208
- rows.splice(targetIndex, 0, rowData);
217
+ var selectedRowRange = ((_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.row) || [];
218
+ var selectedSourceRow = [];
219
+ for (var i = selectedRowRange === null || selectedRowRange === void 0 ? void 0 : selectedRowRange[0]; i <= (selectedRowRange === null || selectedRowRange === void 0 ? void 0 : selectedRowRange[1]); i += 1) {
220
+ selectedSourceRow.push(i);
221
+ }
222
+ var tempSelectedTargetRow = [];
223
+ selectedSourceRow.forEach(function (_, index) {
224
+ if (sourceIndex_1 < targetIndex) {
225
+ tempSelectedTargetRow.push(targetIndex - index);
226
+ } else {
227
+ tempSelectedTargetRow.push(targetIndex + index);
228
+ }
229
+ });
230
+ var selectedTargetRow = (_c = __spreadArray([], tempSelectedTargetRow, true)) === null || _c === void 0 ? void 0 : _c.sort(function (a, b) {
231
+ return a - b;
232
+ });
233
+ selectedSourceRowRef.current = selectedSourceRow;
234
+ selectedTargetRowRef.current = selectedTargetRow;
235
+ selectedSourceRow.forEach(function () {
236
+ var adjustedSourceIndex = sourceIndex_1;
237
+ if (targetIndex < sourceIndex_1) {
238
+ adjustedSourceIndex = sourceIndex_1 + (selectedSourceRow.length - 1);
239
+ }
240
+ var rowData = rows.splice(adjustedSourceIndex, 1)[0];
241
+ if (targetIndex < 0) targetIndex = 0;
242
+ if (targetIndex > rows.length) targetIndex = rows.length;
243
+ rows.splice(targetIndex, 0, rowData);
244
+ });
209
245
  _sheet.data = rows;
210
246
  updateContextWithSheetData(draft, _sheet.data);
211
247
  var d = getFlowdata(draft);
212
248
  d === null || d === void 0 ? void 0 : d.forEach(function (row) {
213
249
  row.forEach(function (cell) {
214
250
  if (cell) {
215
- var startingIndex = sourceIndex_1 + 1;
216
- var targetingIndex_1 = targetIndex + 1;
217
- if (cell.f) {
218
- cell.f = cell.f.replace(new RegExp("\\b([A-Z]+)".concat(startingIndex, "\\b"), "g"), function (match, p1) {
219
- return "".concat(p1).concat(targetingIndex_1);
220
- });
221
- }
222
- var otherAffectedRows = [];
251
+ var otherAffectedRows_1 = [];
223
252
  if (sourceIndex_1 < targetIndex) {
224
- for (var c = startingIndex + 1; c < targetingIndex_1; c += 1) {
225
- otherAffectedRows.push({
253
+ var start = selectedSourceRow === null || selectedSourceRow === void 0 ? void 0 : selectedSourceRow[selectedSourceRow.length - 1];
254
+ var last = selectedTargetRow === null || selectedTargetRow === void 0 ? void 0 : selectedTargetRow[selectedTargetRow.length - 1];
255
+ for (var c = start + 1; c < last; c += 1) {
256
+ otherAffectedRows_1.push({
226
257
  source: c,
227
- target: c - 1
258
+ target: c - selectedSourceRow.length
228
259
  });
229
260
  }
261
+ selectedSourceRow.forEach(function (c, index) {
262
+ otherAffectedRows_1.push({
263
+ source: c,
264
+ target: selectedTargetRow[index]
265
+ });
266
+ });
230
267
  } else {
231
- for (var c = targetingIndex_1; c < startingIndex; c += 1) {
232
- otherAffectedRows.push({
268
+ var start = selectedTargetRow === null || selectedTargetRow === void 0 ? void 0 : selectedTargetRow[0];
269
+ var last = selectedSourceRow === null || selectedSourceRow === void 0 ? void 0 : selectedSourceRow[0];
270
+ for (var c = start; c < last; c += 1) {
271
+ otherAffectedRows_1.push({
233
272
  source: c,
234
- target: c + 1
273
+ target: c + +selectedSourceRow.length
235
274
  });
236
275
  }
276
+ selectedSourceRow.forEach(function (c, index) {
277
+ otherAffectedRows_1.push({
278
+ source: c,
279
+ target: selectedTargetRow[index]
280
+ });
281
+ });
237
282
  }
238
283
  if (cell.f) {
239
284
  var formula_1 = cell.f;
240
285
  var replacements_1 = [];
241
- otherAffectedRows.forEach(function (_a) {
286
+ otherAffectedRows_1.forEach(function (_a) {
242
287
  var source = _a.source,
243
288
  target = _a.target;
244
289
  var regex = new RegExp("\\b([A-Z]+)".concat(source, "\\b"), "g");
@@ -272,30 +317,33 @@ export var useRowDragAndDrop = function useRowDragAndDrop(containerRef, selected
272
317
  if (colRow.length !== 2) return;
273
318
  var presentRow = parseInt(colRow[0], 10);
274
319
  var updatedRow = presentRow;
275
- if (presentRow === sourceIndex_1) {
276
- updatedRow = targetIndex;
320
+ if (selectedSourceRow.includes(presentRow)) {
321
+ var index = selectedSourceRow.indexOf(presentRow);
322
+ var target = selectedTargetRow[index];
323
+ updatedRow = target;
277
324
  } else if (presentRow > sourceIndex_1 && presentRow < targetIndex) {
278
- updatedRow -= 1;
325
+ updatedRow -= selectedSourceRow.length;
279
326
  } else if (presentRow < sourceIndex_1 && presentRow >= targetIndex) {
280
- updatedRow += 1;
327
+ updatedRow += selectedSourceRow.length;
281
328
  }
282
329
  newDataVerification_1["".concat(updatedRow, "_").concat(colRow[1])] = itemData;
283
330
  });
284
331
  _sheet.dataVerification = newDataVerification_1;
285
332
  }
286
- (_a = _sheet.calcChain) === null || _a === void 0 ? void 0 : _a.forEach(function (item) {
287
- if (item.r === sourceIndex_1) {
288
- item.r = targetIndex;
333
+ (_d = _sheet.calcChain) === null || _d === void 0 ? void 0 : _d.forEach(function (item) {
334
+ if (selectedSourceRow.includes(item.r)) {
335
+ var index = selectedSourceRow.indexOf(item.c);
336
+ item.r = selectedTargetRow[index];
289
337
  } else if (item.r > sourceIndex_1 && item.r < targetIndex) {
290
- item.r -= 1;
338
+ item.r -= selectedSourceRow.length;
291
339
  } else if (item.r < sourceIndex_1 && item.r >= targetIndex) {
292
- item.r += 1;
340
+ item.r += selectedSourceRow.length;
293
341
  }
294
342
  });
295
- (_b = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _b === void 0 ? void 0 : _b.call(window, sourceIndex_1, targetIndex, "row", context.currentSheetId);
343
+ (_e = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _e === void 0 ? void 0 : _e.call(window, sourceIndex_1, targetIndex, "row", context.currentSheetId);
296
344
  });
297
345
  var d = getFlowdata(context);
298
- var colLen_1 = ((_a = d === null || d === void 0 ? void 0 : d[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
346
+ var colLen_1 = ((_d = d === null || d === void 0 ? void 0 : d[0]) === null || _d === void 0 ? void 0 : _d.length) || 0;
299
347
  var targetIndex_1 = finalInsertionIndex_1;
300
348
  if (targetIndex_1 > sourceIndex_1) targetIndex_1 -= 1;
301
349
  var selData = api.getSelection(context) || [];
@@ -38,6 +38,9 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
38
38
  context = _a.context,
39
39
  setContext = _a.setContext,
40
40
  refs = _a.refs;
41
+ var selectedColWidth = (0, _react.useRef)(0);
42
+ var selectedSourceColRef = (0, _react.useRef)([]);
43
+ var selectedTargetColRef = (0, _react.useRef)([]);
41
44
  var dragRef = (0, _react.useRef)({
42
45
  mouseDown: false,
43
46
  startX: 0,
@@ -150,6 +153,7 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
150
153
  });
151
154
  if (selectedBlock) {
152
155
  ghostWidthPx = Math.max(60, selectedBlock.col - selectedBlock.col_pre - 1);
156
+ selectedColWidth.current = ghostWidthPx;
153
157
  var count = selectedBlock.c2 - selectedBlock.c1 + 1;
154
158
  ghostLabel = count > 1 ? "".concat(count, " cols") : "Col ".concat(String.fromCharCode(65 + selectedBlock.c1));
155
159
  } else {
@@ -158,6 +162,7 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
158
162
  end = _a[1];
159
163
  var sourceColWidth = end - pre - 1;
160
164
  ghostWidthPx = Math.max(60, sourceColWidth);
165
+ selectedColWidth.current = ghostWidthPx;
161
166
  }
162
167
  el.style.width = "".concat(ghostWidthPx, "px");
163
168
  el.textContent = ghostLabel;
@@ -191,28 +196,30 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
191
196
  var dragOffset = Math.abs(ev.pageX - dragRef.current.startX);
192
197
  if (!isDragActivated(host, dragOffset)) return;
193
198
  var lineLeftPx = computeInsertionFromPageX(ev.pageX).lineLeftPx;
194
- var ghostPosOffset = dragRef.current.startX > ev.pageX ? 0 : 80;
199
+ var ghostPosOffset = 60;
200
+ var ghostFinalPos = dragRef.current.startX > ev.pageX ? lineLeftPx + ghostPosOffset : lineLeftPx - (selectedColWidth.current - ghostPosOffset);
195
201
  if (dragRef.current.lineEl) {
196
202
  dragRef.current.lineEl.style.left = "".concat(lineLeftPx, "px");
197
203
  }
198
204
  if (dragRef.current.ghostEl) {
199
- dragRef.current.ghostEl.style.left = "".concat(ev.pageX - ghostPosOffset, "px");
205
+ dragRef.current.ghostEl.style.left = "".concat(ghostFinalPos, "px");
200
206
  }
201
207
  };
202
208
  var handleColumnDragEnd = function handleColumnDragEnd(ev) {
209
+ var _a, _b, _c;
203
210
  if (!dragRef.current.mouseDown) return;
204
211
  dragRef.current.mouseDown = false;
205
212
  try {
206
213
  document.body.style.userSelect = dragRef.current.prevUserSelect || "";
207
214
  document.body.style.webkitUserSelect = dragRef.current.prevWebkitUserSelect || "";
208
- } catch (_a) {}
215
+ } catch (_d) {}
209
216
  if (dragRef.current.active) {
210
217
  var finalInsertionIndex_1 = computeInsertionFromPageX(ev.pageX).insertionIndex;
211
- var sourceIndex_1 = dragRef.current.source;
218
+ var sourceIndex_1 = ((_c = (_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.column) === null || _c === void 0 ? void 0 : _c[0]) || 0;
212
219
  var sheetIdx_1 = (0, _fortuneCore.getSheetIndex)(context, context.currentSheetId);
213
220
  if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
214
221
  setContext(function (draft) {
215
- var _a, _b, _c, _d;
222
+ var _a, _b, _c, _d, _e, _f, _g;
216
223
  var _sheet = draft.luckysheetfile[sheetIdx_1];
217
224
  if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
218
225
  var rows = _sheet.data;
@@ -221,50 +228,80 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
221
228
  if (sourceIndex_1 < 0 || sourceIndex_1 >= numCols) return;
222
229
  var targetIndex = finalInsertionIndex_1;
223
230
  if (targetIndex > sourceIndex_1) targetIndex -= 1;
224
- for (var i = 0; i < rows.length; i += 1) {
225
- var row = rows[i];
226
- if (!row || sourceIndex_1 >= row.length) continue;
227
- var cellData = row.splice(sourceIndex_1, 1)[0];
228
- if (targetIndex < 0) targetIndex = 0;
229
- if (targetIndex > row.length) targetIndex = row.length;
230
- row.splice(targetIndex, 0, cellData);
231
+ var selectedColRange = ((_d = (_c = context.luckysheet_select_save) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.column) || [];
232
+ var selectedSourceCol = [];
233
+ for (var i = selectedColRange === null || selectedColRange === void 0 ? void 0 : selectedColRange[0]; i <= (selectedColRange === null || selectedColRange === void 0 ? void 0 : selectedColRange[1]); i += 1) {
234
+ selectedSourceCol.push(i);
231
235
  }
236
+ var tempSelectedTargetCol = [];
237
+ selectedSourceCol.forEach(function (_, index) {
238
+ if (sourceIndex_1 < targetIndex) {
239
+ tempSelectedTargetCol.push(targetIndex - index);
240
+ } else {
241
+ tempSelectedTargetCol.push(targetIndex + index);
242
+ }
243
+ });
244
+ var selectedTargetCol = (_e = __spreadArray([], tempSelectedTargetCol, true)) === null || _e === void 0 ? void 0 : _e.sort(function (a, b) {
245
+ return a - b;
246
+ });
247
+ selectedSourceColRef.current = selectedSourceCol;
248
+ selectedTargetColRef.current = selectedTargetCol;
249
+ selectedSourceCol.forEach(function () {
250
+ var adjustedSourceIndex = sourceIndex_1;
251
+ if (targetIndex < sourceIndex_1) {
252
+ adjustedSourceIndex = sourceIndex_1 + (selectedSourceCol.length - 1);
253
+ }
254
+ for (var j = 0; j < rows.length; j += 1) {
255
+ var row = rows[j];
256
+ if (!row || adjustedSourceIndex >= row.length) continue;
257
+ var cellData = row.splice(adjustedSourceIndex, 1)[0];
258
+ if (targetIndex < 0) targetIndex = 0;
259
+ if (targetIndex > row.length) targetIndex = row.length;
260
+ row.splice(targetIndex, 0, cellData);
261
+ }
262
+ });
232
263
  _sheet.data = rows;
233
264
  (0, _fortuneCore.updateContextWithSheetData)(draft, _sheet.data);
234
265
  var d = (0, _fortuneCore.getFlowdata)(draft);
235
266
  d === null || d === void 0 ? void 0 : d.forEach(function (row) {
236
267
  row.forEach(function (cell) {
237
268
  if (cell) {
238
- var sourceColName = numberToColumnName(sourceIndex_1);
239
- var targetColName_1 = numberToColumnName(targetIndex);
240
- if (cell.f) {
241
- cell.f = cell.f.replace(new RegExp("\\b".concat(sourceColName, "(\\d+)\\b"), "g"), function (match, p1) {
242
- if (/^\d+$/.test(p1)) {
243
- return "".concat(targetColName_1).concat(p1);
244
- }
245
- return match;
246
- });
247
- }
248
- var otherAffectedCols = [];
269
+ var otherAffectedCols_1 = [];
249
270
  if (sourceIndex_1 < targetIndex) {
250
- for (var c = sourceIndex_1 + 1; c < targetIndex; c += 1) {
251
- otherAffectedCols.push({
271
+ var start = selectedSourceCol === null || selectedSourceCol === void 0 ? void 0 : selectedSourceCol[selectedSourceCol.length - 1];
272
+ var last = selectedTargetCol === null || selectedTargetCol === void 0 ? void 0 : selectedTargetCol[selectedTargetCol.length - 1];
273
+ for (var c = start + 1; c <= last; c += 1) {
274
+ otherAffectedCols_1.push({
252
275
  source: numberToColumnName(c),
253
- target: numberToColumnName(c - 1)
276
+ target: numberToColumnName(c - selectedSourceCol.length)
254
277
  });
255
278
  }
279
+ selectedSourceCol.forEach(function (c, index) {
280
+ otherAffectedCols_1.push({
281
+ source: numberToColumnName(c),
282
+ target: numberToColumnName(selectedTargetCol[index])
283
+ });
284
+ });
256
285
  } else if (sourceIndex_1 > targetIndex) {
257
- for (var c = targetIndex; c < sourceIndex_1; c += 1) {
258
- otherAffectedCols.push({
286
+ var start = selectedTargetCol === null || selectedTargetCol === void 0 ? void 0 : selectedTargetCol[0];
287
+ var last = selectedSourceCol === null || selectedSourceCol === void 0 ? void 0 : selectedSourceCol[0];
288
+ for (var c = start; c < last; c += 1) {
289
+ otherAffectedCols_1.push({
259
290
  source: numberToColumnName(c),
260
- target: numberToColumnName(c + 1)
291
+ target: numberToColumnName(c + selectedSourceCol.length)
261
292
  });
262
293
  }
294
+ selectedSourceCol.forEach(function (c, index) {
295
+ otherAffectedCols_1.push({
296
+ source: numberToColumnName(c),
297
+ target: numberToColumnName(selectedTargetCol[index])
298
+ });
299
+ });
263
300
  }
264
301
  if (cell.f) {
265
302
  var formula_1 = cell.f;
266
303
  var replacements_1 = [];
267
- otherAffectedCols.forEach(function (col) {
304
+ otherAffectedCols_1.forEach(function (col) {
268
305
  var regex = new RegExp("\\b".concat(col.source, "(\\d+)\\b"), "g");
269
306
  var match;
270
307
  while ((match = regex.exec(formula_1)) !== null) {
@@ -298,38 +335,38 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
298
335
  if (colRow.length !== 2) return;
299
336
  var presentcol = parseInt(colRow[1], 10);
300
337
  var updatedCol = presentcol;
301
- if (presentcol === sourceIndex_1) {
302
- updatedCol = targetIndex;
338
+ if (selectedSourceCol.includes(presentcol)) {
339
+ var index = selectedSourceCol.indexOf(presentcol);
340
+ var target = selectedTargetCol[index];
341
+ updatedCol = target;
303
342
  } else if (presentcol > sourceIndex_1 && presentcol < targetIndex) {
304
- updatedCol -= 1;
343
+ updatedCol -= selectedSourceCol.length;
305
344
  } else if (presentcol < sourceIndex_1 && presentcol >= targetIndex) {
306
- updatedCol += 1;
345
+ updatedCol += selectedSourceCol.length;
307
346
  }
308
347
  newDataVerification_1["".concat(colRow[0], "_").concat(updatedCol)] = itemData;
309
348
  });
310
349
  _sheet.dataVerification = newDataVerification_1;
311
350
  }
312
- (_c = _sheet.calcChain) === null || _c === void 0 ? void 0 : _c.forEach(function (item) {
313
- if (item.c === sourceIndex_1) {
314
- item.c = targetIndex;
351
+ (_f = _sheet.calcChain) === null || _f === void 0 ? void 0 : _f.forEach(function (item) {
352
+ if (selectedSourceCol.includes(item.c)) {
353
+ var index = selectedSourceCol.indexOf(item.c);
354
+ item.c = selectedTargetCol[index];
315
355
  } else if (item.c > sourceIndex_1 && item.c < targetIndex) {
316
- item.c -= 1;
356
+ item.c -= selectedSourceCol.length;
317
357
  } else if (item.c < sourceIndex_1 && item.c >= targetIndex) {
318
- item.c += 1;
358
+ item.c += selectedSourceCol.length;
319
359
  }
320
360
  });
321
- (_d = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _d === void 0 ? void 0 : _d.call(window, sourceIndex_1, targetIndex, "column", context.currentSheetId);
361
+ (_g = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _g === void 0 ? void 0 : _g.call(window, selectedSourceCol, selectedTargetCol, "column", context.currentSheetId, sourceIndex_1, targetIndex);
322
362
  });
323
- var targetIndex = finalInsertionIndex_1;
324
- if (targetIndex > sourceIndex_1) targetIndex -= 1;
325
- var selData = _fortuneCore.api.getSelection(context) || [];
326
- var sel_1 = __spreadArray([], selData, true);
327
- if (sel_1 && sel_1[0]) {
328
- sel_1[0].column = [targetIndex, targetIndex];
329
- }
363
+ var d = (0, _fortuneCore.getFlowdata)(context);
364
+ var rowLen_1 = (d === null || d === void 0 ? void 0 : d.length) || 0;
330
365
  setContext(function (draftCtx) {
331
- console.log("after update", sel_1);
332
- _fortuneCore.api.setSelection(draftCtx, sel_1, {
366
+ _fortuneCore.api.setSelection(draftCtx, [{
367
+ row: [0, rowLen_1],
368
+ column: selectedTargetColRef.current
369
+ }], {
333
370
  id: context.currentSheetId
334
371
  });
335
372
  });
@@ -28,6 +28,9 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
28
28
  context = _a.context,
29
29
  setContext = _a.setContext,
30
30
  refs = _a.refs;
31
+ var selectedRowHeight = (0, _react.useRef)(0);
32
+ var selectedSourceRowRef = (0, _react.useRef)([]);
33
+ var selectedTargetRowRef = (0, _react.useRef)([]);
31
34
  var dragRef = (0, _react.useRef)({
32
35
  mouseDown: false,
33
36
  startY: 0,
@@ -139,6 +142,7 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
139
142
  });
140
143
  if (selectedBlock) {
141
144
  ghostHeightPx = Math.max(24, selectedBlock.row - selectedBlock.row_pre - 1);
145
+ selectedRowHeight.current = ghostHeightPx;
142
146
  var count = selectedBlock.r2 - selectedBlock.r1 + 1;
143
147
  ghostLabel = count > 1 ? "".concat(count, " rows") : "".concat(selectedBlock.r1 + 1, " row");
144
148
  } else {
@@ -147,6 +151,7 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
147
151
  end = _a[1];
148
152
  var sourceRowHeight = end - pre - 1;
149
153
  ghostHeightPx = Math.max(24, sourceRowHeight);
154
+ selectedRowHeight.current = ghostHeightPx;
150
155
  }
151
156
  el.style.height = "".concat(ghostHeightPx, "px");
152
157
  el.textContent = ghostLabel;
@@ -173,6 +178,7 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
173
178
  return true;
174
179
  };
175
180
  var handleRowDrag = function handleRowDrag(ev) {
181
+ var _a, _b;
176
182
  if (!dragRef.current.mouseDown) return;
177
183
  dragRef.current.lastNativeEvent = ev;
178
184
  var host = containerRef.current;
@@ -180,72 +186,111 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
180
186
  var dragOffset = Math.abs(ev.pageY - dragRef.current.startY);
181
187
  if (!isDragActivated(host, dragOffset)) return;
182
188
  var lineTopPx = computeInsertionFromPageY(ev.pageY).lineTopPx;
183
- var ghostPosOffset = dragRef.current.startY > ev.pageY ? 0 : 25;
189
+ var rows = (_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.row;
190
+ var selectedRowLength = rows && rows[1] != null && rows[0] != null ? rows[1] - rows[0] + 1 : 0;
191
+ var off = 3 - selectedRowLength;
192
+ var bottomOff = (off + 1) * 25;
193
+ var topRowOff = selectedRowLength - 4;
194
+ var topOff = topRowOff * 25;
195
+ var ghostFinalPos = dragRef.current.startY > ev.pageY ? lineTopPx - topOff : lineTopPx + bottomOff;
184
196
  if (dragRef.current.lineEl) {
185
197
  dragRef.current.lineEl.style.top = "".concat(lineTopPx, "px");
186
198
  }
187
199
  if (dragRef.current.ghostEl) {
188
- dragRef.current.ghostEl.style.top = "".concat(ev.pageY - ghostPosOffset, "px");
200
+ dragRef.current.ghostEl.style.top = "".concat(ghostFinalPos, "px");
189
201
  }
190
202
  };
191
203
  var handleRowDragEnd = function handleRowDragEnd(ev) {
192
- var _a;
204
+ var _a, _b, _c, _d;
193
205
  if (!dragRef.current.mouseDown) return;
194
206
  dragRef.current.mouseDown = false;
195
207
  try {
196
208
  document.body.style.userSelect = dragRef.current.prevUserSelect || "";
197
209
  document.body.style.webkitUserSelect = dragRef.current.prevWebkitUserSelect || "";
198
- } catch (_b) {}
210
+ } catch (_e) {}
199
211
  if (dragRef.current.active) {
200
212
  var finalInsertionIndex_1 = computeInsertionFromPageY(ev.pageY).insertionIndex;
201
- var sourceIndex_1 = dragRef.current.source;
213
+ var sourceIndex_1 = ((_c = (_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.row) === null || _c === void 0 ? void 0 : _c[0]) || 0;
202
214
  var sheetIdx_1 = (0, _fortuneCore.getSheetIndex)(context, context.currentSheetId);
203
215
  if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
204
216
  setContext(function (draft) {
205
- var _a, _b;
217
+ var _a, _b, _c, _d, _e;
206
218
  var _sheet = draft.luckysheetfile[sheetIdx_1];
207
219
  if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
208
220
  var rows = _sheet.data;
209
221
  if (sourceIndex_1 < 0 || sourceIndex_1 >= rows.length) return;
210
222
  var targetIndex = finalInsertionIndex_1;
211
223
  if (targetIndex > sourceIndex_1) targetIndex -= 1;
212
- var rowData = rows.splice(sourceIndex_1, 1)[0];
213
- if (targetIndex < 0) targetIndex = 0;
214
- if (targetIndex > rows.length) targetIndex = rows.length;
215
- rows.splice(targetIndex, 0, rowData);
224
+ var selectedRowRange = ((_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.row) || [];
225
+ var selectedSourceRow = [];
226
+ for (var i = selectedRowRange === null || selectedRowRange === void 0 ? void 0 : selectedRowRange[0]; i <= (selectedRowRange === null || selectedRowRange === void 0 ? void 0 : selectedRowRange[1]); i += 1) {
227
+ selectedSourceRow.push(i);
228
+ }
229
+ var tempSelectedTargetRow = [];
230
+ selectedSourceRow.forEach(function (_, index) {
231
+ if (sourceIndex_1 < targetIndex) {
232
+ tempSelectedTargetRow.push(targetIndex - index);
233
+ } else {
234
+ tempSelectedTargetRow.push(targetIndex + index);
235
+ }
236
+ });
237
+ var selectedTargetRow = (_c = __spreadArray([], tempSelectedTargetRow, true)) === null || _c === void 0 ? void 0 : _c.sort(function (a, b) {
238
+ return a - b;
239
+ });
240
+ selectedSourceRowRef.current = selectedSourceRow;
241
+ selectedTargetRowRef.current = selectedTargetRow;
242
+ selectedSourceRow.forEach(function () {
243
+ var adjustedSourceIndex = sourceIndex_1;
244
+ if (targetIndex < sourceIndex_1) {
245
+ adjustedSourceIndex = sourceIndex_1 + (selectedSourceRow.length - 1);
246
+ }
247
+ var rowData = rows.splice(adjustedSourceIndex, 1)[0];
248
+ if (targetIndex < 0) targetIndex = 0;
249
+ if (targetIndex > rows.length) targetIndex = rows.length;
250
+ rows.splice(targetIndex, 0, rowData);
251
+ });
216
252
  _sheet.data = rows;
217
253
  (0, _fortuneCore.updateContextWithSheetData)(draft, _sheet.data);
218
254
  var d = (0, _fortuneCore.getFlowdata)(draft);
219
255
  d === null || d === void 0 ? void 0 : d.forEach(function (row) {
220
256
  row.forEach(function (cell) {
221
257
  if (cell) {
222
- var startingIndex = sourceIndex_1 + 1;
223
- var targetingIndex_1 = targetIndex + 1;
224
- if (cell.f) {
225
- cell.f = cell.f.replace(new RegExp("\\b([A-Z]+)".concat(startingIndex, "\\b"), "g"), function (match, p1) {
226
- return "".concat(p1).concat(targetingIndex_1);
227
- });
228
- }
229
- var otherAffectedRows = [];
258
+ var otherAffectedRows_1 = [];
230
259
  if (sourceIndex_1 < targetIndex) {
231
- for (var c = startingIndex + 1; c < targetingIndex_1; c += 1) {
232
- otherAffectedRows.push({
260
+ var start = selectedSourceRow === null || selectedSourceRow === void 0 ? void 0 : selectedSourceRow[selectedSourceRow.length - 1];
261
+ var last = selectedTargetRow === null || selectedTargetRow === void 0 ? void 0 : selectedTargetRow[selectedTargetRow.length - 1];
262
+ for (var c = start + 1; c < last; c += 1) {
263
+ otherAffectedRows_1.push({
233
264
  source: c,
234
- target: c - 1
265
+ target: c - selectedSourceRow.length
235
266
  });
236
267
  }
268
+ selectedSourceRow.forEach(function (c, index) {
269
+ otherAffectedRows_1.push({
270
+ source: c,
271
+ target: selectedTargetRow[index]
272
+ });
273
+ });
237
274
  } else {
238
- for (var c = targetingIndex_1; c < startingIndex; c += 1) {
239
- otherAffectedRows.push({
275
+ var start = selectedTargetRow === null || selectedTargetRow === void 0 ? void 0 : selectedTargetRow[0];
276
+ var last = selectedSourceRow === null || selectedSourceRow === void 0 ? void 0 : selectedSourceRow[0];
277
+ for (var c = start; c < last; c += 1) {
278
+ otherAffectedRows_1.push({
240
279
  source: c,
241
- target: c + 1
280
+ target: c + +selectedSourceRow.length
242
281
  });
243
282
  }
283
+ selectedSourceRow.forEach(function (c, index) {
284
+ otherAffectedRows_1.push({
285
+ source: c,
286
+ target: selectedTargetRow[index]
287
+ });
288
+ });
244
289
  }
245
290
  if (cell.f) {
246
291
  var formula_1 = cell.f;
247
292
  var replacements_1 = [];
248
- otherAffectedRows.forEach(function (_a) {
293
+ otherAffectedRows_1.forEach(function (_a) {
249
294
  var source = _a.source,
250
295
  target = _a.target;
251
296
  var regex = new RegExp("\\b([A-Z]+)".concat(source, "\\b"), "g");
@@ -279,30 +324,33 @@ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(c
279
324
  if (colRow.length !== 2) return;
280
325
  var presentRow = parseInt(colRow[0], 10);
281
326
  var updatedRow = presentRow;
282
- if (presentRow === sourceIndex_1) {
283
- updatedRow = targetIndex;
327
+ if (selectedSourceRow.includes(presentRow)) {
328
+ var index = selectedSourceRow.indexOf(presentRow);
329
+ var target = selectedTargetRow[index];
330
+ updatedRow = target;
284
331
  } else if (presentRow > sourceIndex_1 && presentRow < targetIndex) {
285
- updatedRow -= 1;
332
+ updatedRow -= selectedSourceRow.length;
286
333
  } else if (presentRow < sourceIndex_1 && presentRow >= targetIndex) {
287
- updatedRow += 1;
334
+ updatedRow += selectedSourceRow.length;
288
335
  }
289
336
  newDataVerification_1["".concat(updatedRow, "_").concat(colRow[1])] = itemData;
290
337
  });
291
338
  _sheet.dataVerification = newDataVerification_1;
292
339
  }
293
- (_a = _sheet.calcChain) === null || _a === void 0 ? void 0 : _a.forEach(function (item) {
294
- if (item.r === sourceIndex_1) {
295
- item.r = targetIndex;
340
+ (_d = _sheet.calcChain) === null || _d === void 0 ? void 0 : _d.forEach(function (item) {
341
+ if (selectedSourceRow.includes(item.r)) {
342
+ var index = selectedSourceRow.indexOf(item.c);
343
+ item.r = selectedTargetRow[index];
296
344
  } else if (item.r > sourceIndex_1 && item.r < targetIndex) {
297
- item.r -= 1;
345
+ item.r -= selectedSourceRow.length;
298
346
  } else if (item.r < sourceIndex_1 && item.r >= targetIndex) {
299
- item.r += 1;
347
+ item.r += selectedSourceRow.length;
300
348
  }
301
349
  });
302
- (_b = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _b === void 0 ? void 0 : _b.call(window, sourceIndex_1, targetIndex, "row", context.currentSheetId);
350
+ (_e = window === null || window === void 0 ? void 0 : window.updateDataBlockCalcFunctionAfterRowDrag) === null || _e === void 0 ? void 0 : _e.call(window, sourceIndex_1, targetIndex, "row", context.currentSheetId);
303
351
  });
304
352
  var d = (0, _fortuneCore.getFlowdata)(context);
305
- var colLen_1 = ((_a = d === null || d === void 0 ? void 0 : d[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
353
+ var colLen_1 = ((_d = d === null || d === void 0 ? void 0 : d[0]) === null || _d === void 0 ? void 0 : _d.length) || 0;
306
354
  var targetIndex_1 = finalInsertionIndex_1;
307
355
  if (targetIndex_1 > sourceIndex_1) targetIndex_1 -= 1;
308
356
  var selData = _fortuneCore.api.getSelection(context) || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.2.42",
3
+ "version": "1.2.44",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "module": "es/index.js",
@@ -16,7 +16,7 @@
16
16
  "tsc": "tsc"
17
17
  },
18
18
  "dependencies": {
19
- "@fileverse-dev/fortune-core": "1.2.42",
19
+ "@fileverse-dev/fortune-core": "1.2.44",
20
20
  "@fileverse/ui": "^4.1.7-patch-40",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",