@fileverse-dev/fortune-core 1.3.13-create-3 → 1.3.13-create-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.
- package/es/events/paste.js +0 -1
- package/es/modules/cell.js +1 -0
- package/es/modules/formula.d.ts +4 -0
- package/es/modules/formula.js +26 -0
- package/es/modules/rowcol.js +22 -0
- package/es/modules/searchReplace.js +13 -0
- package/es/modules/sort.d.ts +1 -1
- package/es/modules/sort.js +50 -13
- package/lib/events/paste.js +0 -1
- package/lib/modules/cell.js +1 -0
- package/lib/modules/formula.d.ts +4 -0
- package/lib/modules/formula.js +27 -0
- package/lib/modules/rowcol.js +22 -0
- package/lib/modules/searchReplace.js +13 -0
- package/lib/modules/sort.d.ts +1 -1
- package/lib/modules/sort.js +49 -12
- package/package.json +1 -1
package/es/events/paste.js
CHANGED
|
@@ -81,7 +81,6 @@ export function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow)
|
|
|
81
81
|
var stringOrCellRef = /"(?:\\.|[^"])*"|(\$?[A-Z]+\$?\d+)(?!\s*!)\b/g;
|
|
82
82
|
var result = formula.replace(stringOrCellRef, function (m, cellRef) {
|
|
83
83
|
if (!cellRef) return m;
|
|
84
|
-
if (cellRef.startsWith("$")) return m;
|
|
85
84
|
return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
|
|
86
85
|
var colIndex = columnLabelIndex(colLetters);
|
|
87
86
|
var rowIndex = parseInt(rowNum, 10);
|
package/es/modules/cell.js
CHANGED
|
@@ -569,6 +569,7 @@ export function cancelNormalSelected(ctx) {
|
|
|
569
569
|
ctx.formulaCache.rangedrag_column_start = false;
|
|
570
570
|
ctx.formulaCache.rangedrag_row_start = false;
|
|
571
571
|
ctx.formulaCache.rangeSelectionActive = null;
|
|
572
|
+
ctx.formulaCache.keyboardRangeSelectionLock = false;
|
|
572
573
|
ctx.formulaCache.formulaEditorOwner = null;
|
|
573
574
|
}
|
|
574
575
|
export function updateCell(ctx, r, c, $input, value, canvas) {
|
package/es/modules/formula.d.ts
CHANGED
|
@@ -74,5 +74,9 @@ type MoveReferenceRect = {
|
|
|
74
74
|
colStart: number;
|
|
75
75
|
colEnd: number;
|
|
76
76
|
};
|
|
77
|
+
export declare function remapFormulaReferencesByMap(formula: string, formulaSheetName: string, movedSheetName: string, maps: {
|
|
78
|
+
rowMap?: Record<number, number>;
|
|
79
|
+
colMap?: Record<number, number>;
|
|
80
|
+
}): string;
|
|
77
81
|
export declare function functionMoveReference(txt: string, formulaSheetName: string, movedSheetName: string, sourceRect: MoveReferenceRect, targetRowStart: number, targetColStart: number): string;
|
|
78
82
|
export {};
|
package/es/modules/formula.js
CHANGED
|
@@ -2842,6 +2842,32 @@ function normalizeSheetName(ref) {
|
|
|
2842
2842
|
var unquoted = ref.startsWith("'") && ref.endsWith("'") ? ref.slice(1, -1).replace(/''/g, "'") : ref;
|
|
2843
2843
|
return unquoted;
|
|
2844
2844
|
}
|
|
2845
|
+
var MAP_REMAP_REF_REGEX = /((?:'(?:[^']|'')+'|[A-Za-z_][A-Za-z0-9_.]*)!)?(\$?)([A-Za-z]+)(\$?)(\d+)(?::(\$?)([A-Za-z]+)(\$?)(\d+))?/g;
|
|
2846
|
+
export function remapFormulaReferencesByMap(formula, formulaSheetName, movedSheetName, maps) {
|
|
2847
|
+
var rowMap = maps.rowMap,
|
|
2848
|
+
colMap = maps.colMap;
|
|
2849
|
+
if (!formula) return formula;
|
|
2850
|
+
return formula.replace(MAP_REMAP_REF_REGEX, function (token, sheetPrefix, colAbs0, col0, rowAbs0, row0, colAbs1, col1, rowAbs1, row1) {
|
|
2851
|
+
var refSheetName = sheetPrefix ? normalizeSheetName(sheetPrefix.slice(0, -1)) : formulaSheetName;
|
|
2852
|
+
if (refSheetName !== movedSheetName) return token;
|
|
2853
|
+
var remapOne = function remapOne(colText, rowText) {
|
|
2854
|
+
var colIndex = columnCharToIndex(colText);
|
|
2855
|
+
var rowIndex = parseInt(rowText, 10) - 1;
|
|
2856
|
+
var nextCol = !Number.isNaN(colIndex) && !_.isNil(colMap === null || colMap === void 0 ? void 0 : colMap[colIndex]) ? indexToColumnChar(colMap[colIndex]) : colText;
|
|
2857
|
+
var nextRow = !Number.isNaN(rowIndex) && !_.isNil(rowMap === null || rowMap === void 0 ? void 0 : rowMap[rowIndex]) ? String(rowMap[rowIndex] + 1) : rowText;
|
|
2858
|
+
return {
|
|
2859
|
+
nextCol: nextCol,
|
|
2860
|
+
nextRow: nextRow
|
|
2861
|
+
};
|
|
2862
|
+
};
|
|
2863
|
+
var head = remapOne(col0, row0);
|
|
2864
|
+
if (_.isNil(col1) || _.isNil(row1)) {
|
|
2865
|
+
return "".concat(sheetPrefix || "").concat(colAbs0).concat(head.nextCol).concat(rowAbs0).concat(head.nextRow);
|
|
2866
|
+
}
|
|
2867
|
+
var tail = remapOne(col1, row1);
|
|
2868
|
+
return "".concat(sheetPrefix || "").concat(colAbs0).concat(head.nextCol).concat(rowAbs0).concat(head.nextRow, ":").concat(colAbs1).concat(tail.nextCol).concat(rowAbs1).concat(tail.nextRow);
|
|
2869
|
+
});
|
|
2870
|
+
}
|
|
2845
2871
|
function parseRefToken(token) {
|
|
2846
2872
|
var m = token.match(/^(\$?)([A-Za-z]+)(\$?)(\d+)$/);
|
|
2847
2873
|
if (!m) return null;
|
package/es/modules/rowcol.js
CHANGED
|
@@ -109,6 +109,26 @@ var emitCellRangeToYdoc = function emitCellRangeToYdoc(ctx, sheetId, d, r1, r2,
|
|
|
109
109
|
}
|
|
110
110
|
if (changes.length > 0) ctx.hooks.updateCellYdoc(changes);
|
|
111
111
|
};
|
|
112
|
+
var rewriteFormulasByScanningSheet = function rewriteFormulasByScanningSheet(sheet, calcChain, mode, rc, orient, stindex, step) {
|
|
113
|
+
var sheetData = sheet.data;
|
|
114
|
+
if (!sheetData) return;
|
|
115
|
+
var calcChainSet = new Set();
|
|
116
|
+
(calcChain || []).forEach(function (item) {
|
|
117
|
+
if (item && Number.isFinite(item.r) && Number.isFinite(item.c)) {
|
|
118
|
+
calcChainSet.add("".concat(item.r, "_").concat(item.c));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
for (var r = 0; r < sheetData.length; r += 1) {
|
|
122
|
+
var row = sheetData[r];
|
|
123
|
+
if (!row) continue;
|
|
124
|
+
for (var c = 0; c < row.length; c += 1) {
|
|
125
|
+
var cell = row[c];
|
|
126
|
+
if (!(cell === null || cell === void 0 ? void 0 : cell.f)) continue;
|
|
127
|
+
if (calcChainSet.has("".concat(r, "_").concat(c))) continue;
|
|
128
|
+
cell.f = "=".concat(functionStrChange(cell.f, mode, rc, orient, stindex, step));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
112
132
|
export function insertRowCol(ctx, op, changeSelection) {
|
|
113
133
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
114
134
|
if (changeSelection === void 0) {
|
|
@@ -322,6 +342,7 @@ export function insertRowCol(ctx, op, changeSelection) {
|
|
|
322
342
|
}
|
|
323
343
|
}
|
|
324
344
|
}
|
|
345
|
+
rewriteFormulasByScanningSheet(ctx.luckysheetfile[SheetIndex], calcChain, "add", type === "row" ? "row" : "col", direction, index, count);
|
|
325
346
|
}
|
|
326
347
|
var filter_select = file.filter_select;
|
|
327
348
|
var filter = file.filter;
|
|
@@ -1279,6 +1300,7 @@ export function deleteRowCol(ctx, op) {
|
|
|
1279
1300
|
}
|
|
1280
1301
|
}
|
|
1281
1302
|
}
|
|
1303
|
+
rewriteFormulasByScanningSheet(ctx.luckysheetfile[SheetIndex], calcChain, "del", type === "row" ? "row" : "col", null, start, slen);
|
|
1282
1304
|
}
|
|
1283
1305
|
var filter_select = file.filter_select;
|
|
1284
1306
|
var filter = file.filter;
|
|
@@ -5,6 +5,11 @@ import { chatatABC, getRegExpStr, getSheetIndex, isAllowEdit, replaceHtml } from
|
|
|
5
5
|
import { setCellValue } from "./cell";
|
|
6
6
|
import { valueShowEs } from "./format";
|
|
7
7
|
import { normalizeSelection, scrollToHighlightCell } from "./selection";
|
|
8
|
+
function isFormulaCell(flowdata, r, c) {
|
|
9
|
+
var _a;
|
|
10
|
+
var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[r]) === null || _a === void 0 ? void 0 : _a[c];
|
|
11
|
+
return !!(cell === null || cell === void 0 ? void 0 : cell.f);
|
|
12
|
+
}
|
|
8
13
|
export function getSearchIndexArr(searchText, range, flowdata, _a) {
|
|
9
14
|
var _b = _a === void 0 ? {
|
|
10
15
|
regCheck: false,
|
|
@@ -302,6 +307,9 @@ export function replace(ctx, searchText, replaceText, checkModes) {
|
|
|
302
307
|
if (checkModes.wordCheck) {
|
|
303
308
|
r = searchIndexArr[count].r;
|
|
304
309
|
c = searchIndexArr[count].c;
|
|
310
|
+
if (isFormulaCell(d, r, c)) {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
305
313
|
var v = replaceText;
|
|
306
314
|
setCellValue(ctx, r, c, d, v);
|
|
307
315
|
if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
|
|
@@ -326,6 +334,9 @@ export function replace(ctx, searchText, replaceText, checkModes) {
|
|
|
326
334
|
}
|
|
327
335
|
r = searchIndexArr[count].r;
|
|
328
336
|
c = searchIndexArr[count].c;
|
|
337
|
+
if (isFormulaCell(d, r, c)) {
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
329
340
|
var v = valueShowEs(r, c, d).toString().replace(reg, replaceText);
|
|
330
341
|
setCellValue(ctx, r, c, d, v);
|
|
331
342
|
if ((_f = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _f === void 0 ? void 0 : _f.updateCellYdoc) {
|
|
@@ -380,6 +391,7 @@ export function replaceAll(ctx, searchText, replaceText, checkModes) {
|
|
|
380
391
|
for (var i = 0; i < searchIndexArr.length; i += 1) {
|
|
381
392
|
var r = searchIndexArr[i].r;
|
|
382
393
|
var c = searchIndexArr[i].c;
|
|
394
|
+
if (isFormulaCell(d, r, c)) continue;
|
|
383
395
|
var v = replaceText;
|
|
384
396
|
setCellValue(ctx, r, c, d, v);
|
|
385
397
|
if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
|
|
@@ -411,6 +423,7 @@ export function replaceAll(ctx, searchText, replaceText, checkModes) {
|
|
|
411
423
|
for (var i = 0; i < searchIndexArr.length; i += 1) {
|
|
412
424
|
var r = searchIndexArr[i].r;
|
|
413
425
|
var c = searchIndexArr[i].c;
|
|
426
|
+
if (isFormulaCell(d, r, c)) continue;
|
|
414
427
|
var v = valueShowEs(r, c, d).toString().replace(reg, replaceText);
|
|
415
428
|
setCellValue(ctx, r, c, d, v);
|
|
416
429
|
if ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _e === void 0 ? void 0 : _e.updateCellYdoc) {
|
package/es/modules/sort.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Cell, CellMatrix, Context } from "..";
|
|
2
2
|
export declare function orderbydata(isAsc: boolean, index: number, data: (Cell | null)[][]): {
|
|
3
3
|
sortedData: (Cell | null)[][];
|
|
4
|
-
|
|
4
|
+
rowMap: Record<number, number>;
|
|
5
5
|
};
|
|
6
6
|
export declare function sortDataRange(ctx: Context, sheetData: CellMatrix, dataRange: CellMatrix, index: number, isAsc: boolean, str: number, edr: number, stc: number, edc: number): void;
|
|
7
7
|
export declare function sortSelection(ctx: Context, isAsc: boolean, colIndex?: number): void;
|
package/es/modules/sort.js
CHANGED
|
@@ -10,7 +10,7 @@ var __assign = this && this.__assign || function () {
|
|
|
10
10
|
};
|
|
11
11
|
import numeral from "numeral";
|
|
12
12
|
import _ from "lodash";
|
|
13
|
-
import { diff, getFlowdata, getSheetIndex, isdatetime, isRealNull, isRealNum, setCellValue } from "..";
|
|
13
|
+
import { diff, getFlowdata, getSheetIndex, isdatetime, isRealNull, isRealNum, remapFormulaReferencesByMap, setCellValue } from "..";
|
|
14
14
|
import { jfrefreshgrid } from "./refresh";
|
|
15
15
|
export function orderbydata(isAsc, index, data) {
|
|
16
16
|
if (isAsc == null) {
|
|
@@ -54,33 +54,70 @@ export function orderbydata(isAsc, index, data) {
|
|
|
54
54
|
var d = function d(x, y) {
|
|
55
55
|
return a(y, x);
|
|
56
56
|
};
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
var sortedWithIndex = data.map(function (row, i) {
|
|
58
|
+
return {
|
|
59
|
+
row: row,
|
|
60
|
+
originalIndex: i
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
sortedWithIndex.sort(function (x, y) {
|
|
64
|
+
return isAsc ? a(x.row, y.row) : d(x.row, y.row);
|
|
65
|
+
});
|
|
66
|
+
var sortedData = sortedWithIndex.map(function (item) {
|
|
67
|
+
return item.row;
|
|
68
|
+
});
|
|
69
|
+
var rowMap = {};
|
|
70
|
+
sortedWithIndex.forEach(function (item, newIndex) {
|
|
71
|
+
rowMap[item.originalIndex] = newIndex;
|
|
64
72
|
});
|
|
65
73
|
return {
|
|
66
74
|
sortedData: sortedData,
|
|
67
|
-
|
|
75
|
+
rowMap: rowMap
|
|
68
76
|
};
|
|
69
77
|
}
|
|
70
78
|
export function sortDataRange(ctx, sheetData, dataRange, index, isAsc, str, edr, stc, edc) {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
var
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
var _d = orderbydata(isAsc, index, dataRange),
|
|
81
|
+
sortedData = _d.sortedData,
|
|
82
|
+
rowMap = _d.rowMap;
|
|
73
83
|
for (var r = str; r <= edr; r += 1) {
|
|
74
84
|
for (var c = stc; c <= edc; c += 1) {
|
|
75
85
|
var cell = sortedData[r - str][c - stc];
|
|
76
86
|
sheetData[r][c] = cell;
|
|
77
87
|
}
|
|
78
88
|
}
|
|
89
|
+
var absoluteRowMap = {};
|
|
90
|
+
Object.keys(rowMap).forEach(function (k) {
|
|
91
|
+
var oldLocal = parseInt(k, 10);
|
|
92
|
+
absoluteRowMap[str + oldLocal] = str + rowMap[oldLocal];
|
|
93
|
+
});
|
|
94
|
+
var sheetIdx = getSheetIndex(ctx, ctx.currentSheetId);
|
|
95
|
+
var sheet = sheetIdx == null ? null : ctx.luckysheetfile[sheetIdx];
|
|
96
|
+
var sheetName = (sheet === null || sheet === void 0 ? void 0 : sheet.name) || "";
|
|
97
|
+
if (sheetData && sheetName) {
|
|
98
|
+
for (var r = 0; r < sheetData.length; r += 1) {
|
|
99
|
+
var row = sheetData[r];
|
|
100
|
+
if (!row) continue;
|
|
101
|
+
for (var c = 0; c < row.length; c += 1) {
|
|
102
|
+
var cell = row[c];
|
|
103
|
+
if (!(cell === null || cell === void 0 ? void 0 : cell.f)) continue;
|
|
104
|
+
cell.f = remapFormulaReferencesByMap(cell.f, sheetName, sheetName, {
|
|
105
|
+
rowMap: absoluteRowMap
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
(_a = sheet === null || sheet === void 0 ? void 0 : sheet.calcChain) === null || _a === void 0 ? void 0 : _a.forEach(function (item) {
|
|
111
|
+
var mapped = absoluteRowMap[item.r];
|
|
112
|
+
if (!_.isNil(mapped)) {
|
|
113
|
+
item.r = mapped;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
79
116
|
jfrefreshgrid(ctx, sheetData, [{
|
|
80
117
|
row: [str, edr],
|
|
81
118
|
column: [stc, edc]
|
|
82
119
|
}]);
|
|
83
|
-
if ((
|
|
120
|
+
if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
|
|
84
121
|
var changes = [];
|
|
85
122
|
for (var r = str; r <= edr; r += 1) {
|
|
86
123
|
var row = sheetData[r] || [];
|
|
@@ -91,7 +128,7 @@ export function sortDataRange(ctx, sheetData, dataRange, index, isAsc, str, edr,
|
|
|
91
128
|
value: {
|
|
92
129
|
r: r,
|
|
93
130
|
c: c,
|
|
94
|
-
v: (
|
|
131
|
+
v: (_c = row === null || row === void 0 ? void 0 : row[c]) !== null && _c !== void 0 ? _c : null
|
|
95
132
|
},
|
|
96
133
|
key: "".concat(r, "_").concat(c),
|
|
97
134
|
type: "update"
|
package/lib/events/paste.js
CHANGED
|
@@ -94,7 +94,6 @@ function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow) {
|
|
|
94
94
|
var stringOrCellRef = /"(?:\\.|[^"])*"|(\$?[A-Z]+\$?\d+)(?!\s*!)\b/g;
|
|
95
95
|
var result = formula.replace(stringOrCellRef, function (m, cellRef) {
|
|
96
96
|
if (!cellRef) return m;
|
|
97
|
-
if (cellRef.startsWith("$")) return m;
|
|
98
97
|
return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
|
|
99
98
|
var colIndex = columnLabelIndex(colLetters);
|
|
100
99
|
var rowIndex = parseInt(rowNum, 10);
|
package/lib/modules/cell.js
CHANGED
|
@@ -602,6 +602,7 @@ function cancelNormalSelected(ctx) {
|
|
|
602
602
|
ctx.formulaCache.rangedrag_column_start = false;
|
|
603
603
|
ctx.formulaCache.rangedrag_row_start = false;
|
|
604
604
|
ctx.formulaCache.rangeSelectionActive = null;
|
|
605
|
+
ctx.formulaCache.keyboardRangeSelectionLock = false;
|
|
605
606
|
ctx.formulaCache.formulaEditorOwner = null;
|
|
606
607
|
}
|
|
607
608
|
function updateCell(ctx, r, c, $input, value, canvas) {
|
package/lib/modules/formula.d.ts
CHANGED
|
@@ -74,5 +74,9 @@ type MoveReferenceRect = {
|
|
|
74
74
|
colStart: number;
|
|
75
75
|
colEnd: number;
|
|
76
76
|
};
|
|
77
|
+
export declare function remapFormulaReferencesByMap(formula: string, formulaSheetName: string, movedSheetName: string, maps: {
|
|
78
|
+
rowMap?: Record<number, number>;
|
|
79
|
+
colMap?: Record<number, number>;
|
|
80
|
+
}): string;
|
|
77
81
|
export declare function functionMoveReference(txt: string, formulaSheetName: string, movedSheetName: string, sourceRect: MoveReferenceRect, targetRowStart: number, targetColStart: number): string;
|
|
78
82
|
export {};
|
package/lib/modules/formula.js
CHANGED
|
@@ -38,6 +38,7 @@ exports.rangeDragColumn = rangeDragColumn;
|
|
|
38
38
|
exports.rangeDragRow = rangeDragRow;
|
|
39
39
|
exports.rangeHightlightselected = rangeHightlightselected;
|
|
40
40
|
exports.rangeSetValue = rangeSetValue;
|
|
41
|
+
exports.remapFormulaReferencesByMap = remapFormulaReferencesByMap;
|
|
41
42
|
exports.setCaretPosition = setCaretPosition;
|
|
42
43
|
exports.setFormulaEditorOwner = setFormulaEditorOwner;
|
|
43
44
|
exports.suppressFormulaRangeSelectionForInitialEdit = suppressFormulaRangeSelectionForInitialEdit;
|
|
@@ -2885,6 +2886,32 @@ function normalizeSheetName(ref) {
|
|
|
2885
2886
|
var unquoted = ref.startsWith("'") && ref.endsWith("'") ? ref.slice(1, -1).replace(/''/g, "'") : ref;
|
|
2886
2887
|
return unquoted;
|
|
2887
2888
|
}
|
|
2889
|
+
var MAP_REMAP_REF_REGEX = /((?:'(?:[^']|'')+'|[A-Za-z_][A-Za-z0-9_.]*)!)?(\$?)([A-Za-z]+)(\$?)(\d+)(?::(\$?)([A-Za-z]+)(\$?)(\d+))?/g;
|
|
2890
|
+
function remapFormulaReferencesByMap(formula, formulaSheetName, movedSheetName, maps) {
|
|
2891
|
+
var rowMap = maps.rowMap,
|
|
2892
|
+
colMap = maps.colMap;
|
|
2893
|
+
if (!formula) return formula;
|
|
2894
|
+
return formula.replace(MAP_REMAP_REF_REGEX, function (token, sheetPrefix, colAbs0, col0, rowAbs0, row0, colAbs1, col1, rowAbs1, row1) {
|
|
2895
|
+
var refSheetName = sheetPrefix ? normalizeSheetName(sheetPrefix.slice(0, -1)) : formulaSheetName;
|
|
2896
|
+
if (refSheetName !== movedSheetName) return token;
|
|
2897
|
+
var remapOne = function remapOne(colText, rowText) {
|
|
2898
|
+
var colIndex = (0, _utils.columnCharToIndex)(colText);
|
|
2899
|
+
var rowIndex = parseInt(rowText, 10) - 1;
|
|
2900
|
+
var nextCol = !Number.isNaN(colIndex) && !_lodash.default.isNil(colMap === null || colMap === void 0 ? void 0 : colMap[colIndex]) ? (0, _utils.indexToColumnChar)(colMap[colIndex]) : colText;
|
|
2901
|
+
var nextRow = !Number.isNaN(rowIndex) && !_lodash.default.isNil(rowMap === null || rowMap === void 0 ? void 0 : rowMap[rowIndex]) ? String(rowMap[rowIndex] + 1) : rowText;
|
|
2902
|
+
return {
|
|
2903
|
+
nextCol: nextCol,
|
|
2904
|
+
nextRow: nextRow
|
|
2905
|
+
};
|
|
2906
|
+
};
|
|
2907
|
+
var head = remapOne(col0, row0);
|
|
2908
|
+
if (_lodash.default.isNil(col1) || _lodash.default.isNil(row1)) {
|
|
2909
|
+
return "".concat(sheetPrefix || "").concat(colAbs0).concat(head.nextCol).concat(rowAbs0).concat(head.nextRow);
|
|
2910
|
+
}
|
|
2911
|
+
var tail = remapOne(col1, row1);
|
|
2912
|
+
return "".concat(sheetPrefix || "").concat(colAbs0).concat(head.nextCol).concat(rowAbs0).concat(head.nextRow, ":").concat(colAbs1).concat(tail.nextCol).concat(rowAbs1).concat(tail.nextRow);
|
|
2913
|
+
});
|
|
2914
|
+
}
|
|
2888
2915
|
function parseRefToken(token) {
|
|
2889
2916
|
var m = token.match(/^(\$?)([A-Za-z]+)(\$?)(\d+)$/);
|
|
2890
2917
|
if (!m) return null;
|
package/lib/modules/rowcol.js
CHANGED
|
@@ -122,6 +122,26 @@ var emitCellRangeToYdoc = function emitCellRangeToYdoc(ctx, sheetId, d, r1, r2,
|
|
|
122
122
|
}
|
|
123
123
|
if (changes.length > 0) ctx.hooks.updateCellYdoc(changes);
|
|
124
124
|
};
|
|
125
|
+
var rewriteFormulasByScanningSheet = function rewriteFormulasByScanningSheet(sheet, calcChain, mode, rc, orient, stindex, step) {
|
|
126
|
+
var sheetData = sheet.data;
|
|
127
|
+
if (!sheetData) return;
|
|
128
|
+
var calcChainSet = new Set();
|
|
129
|
+
(calcChain || []).forEach(function (item) {
|
|
130
|
+
if (item && Number.isFinite(item.r) && Number.isFinite(item.c)) {
|
|
131
|
+
calcChainSet.add("".concat(item.r, "_").concat(item.c));
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
for (var r = 0; r < sheetData.length; r += 1) {
|
|
135
|
+
var row = sheetData[r];
|
|
136
|
+
if (!row) continue;
|
|
137
|
+
for (var c = 0; c < row.length; c += 1) {
|
|
138
|
+
var cell = row[c];
|
|
139
|
+
if (!(cell === null || cell === void 0 ? void 0 : cell.f)) continue;
|
|
140
|
+
if (calcChainSet.has("".concat(r, "_").concat(c))) continue;
|
|
141
|
+
cell.f = "=".concat((0, _formula.functionStrChange)(cell.f, mode, rc, orient, stindex, step));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
125
145
|
function insertRowCol(ctx, op, changeSelection) {
|
|
126
146
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
127
147
|
if (changeSelection === void 0) {
|
|
@@ -335,6 +355,7 @@ function insertRowCol(ctx, op, changeSelection) {
|
|
|
335
355
|
}
|
|
336
356
|
}
|
|
337
357
|
}
|
|
358
|
+
rewriteFormulasByScanningSheet(ctx.luckysheetfile[SheetIndex], calcChain, "add", type === "row" ? "row" : "col", direction, index, count);
|
|
338
359
|
}
|
|
339
360
|
var filter_select = file.filter_select;
|
|
340
361
|
var filter = file.filter;
|
|
@@ -1292,6 +1313,7 @@ function deleteRowCol(ctx, op) {
|
|
|
1292
1313
|
}
|
|
1293
1314
|
}
|
|
1294
1315
|
}
|
|
1316
|
+
rewriteFormulasByScanningSheet(ctx.luckysheetfile[SheetIndex], calcChain, "del", type === "row" ? "row" : "col", null, start, slen);
|
|
1295
1317
|
}
|
|
1296
1318
|
var filter_select = file.filter_select;
|
|
1297
1319
|
var filter = file.filter;
|
|
@@ -19,6 +19,11 @@ var _cell = require("./cell");
|
|
|
19
19
|
var _format = require("./format");
|
|
20
20
|
var _selection = require("./selection");
|
|
21
21
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
+
function isFormulaCell(flowdata, r, c) {
|
|
23
|
+
var _a;
|
|
24
|
+
var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[r]) === null || _a === void 0 ? void 0 : _a[c];
|
|
25
|
+
return !!(cell === null || cell === void 0 ? void 0 : cell.f);
|
|
26
|
+
}
|
|
22
27
|
function getSearchIndexArr(searchText, range, flowdata, _a) {
|
|
23
28
|
var _b = _a === void 0 ? {
|
|
24
29
|
regCheck: false,
|
|
@@ -316,6 +321,9 @@ function replace(ctx, searchText, replaceText, checkModes) {
|
|
|
316
321
|
if (checkModes.wordCheck) {
|
|
317
322
|
r = searchIndexArr[count].r;
|
|
318
323
|
c = searchIndexArr[count].c;
|
|
324
|
+
if (isFormulaCell(d, r, c)) {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
319
327
|
var v = replaceText;
|
|
320
328
|
(0, _cell.setCellValue)(ctx, r, c, d, v);
|
|
321
329
|
if ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _c === void 0 ? void 0 : _c.updateCellYdoc) {
|
|
@@ -340,6 +348,9 @@ function replace(ctx, searchText, replaceText, checkModes) {
|
|
|
340
348
|
}
|
|
341
349
|
r = searchIndexArr[count].r;
|
|
342
350
|
c = searchIndexArr[count].c;
|
|
351
|
+
if (isFormulaCell(d, r, c)) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
343
354
|
var v = (0, _format.valueShowEs)(r, c, d).toString().replace(reg, replaceText);
|
|
344
355
|
(0, _cell.setCellValue)(ctx, r, c, d, v);
|
|
345
356
|
if ((_f = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _f === void 0 ? void 0 : _f.updateCellYdoc) {
|
|
@@ -394,6 +405,7 @@ function replaceAll(ctx, searchText, replaceText, checkModes) {
|
|
|
394
405
|
for (var i = 0; i < searchIndexArr.length; i += 1) {
|
|
395
406
|
var r = searchIndexArr[i].r;
|
|
396
407
|
var c = searchIndexArr[i].c;
|
|
408
|
+
if (isFormulaCell(d, r, c)) continue;
|
|
397
409
|
var v = replaceText;
|
|
398
410
|
(0, _cell.setCellValue)(ctx, r, c, d, v);
|
|
399
411
|
if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
|
|
@@ -425,6 +437,7 @@ function replaceAll(ctx, searchText, replaceText, checkModes) {
|
|
|
425
437
|
for (var i = 0; i < searchIndexArr.length; i += 1) {
|
|
426
438
|
var r = searchIndexArr[i].r;
|
|
427
439
|
var c = searchIndexArr[i].c;
|
|
440
|
+
if (isFormulaCell(d, r, c)) continue;
|
|
428
441
|
var v = (0, _format.valueShowEs)(r, c, d).toString().replace(reg, replaceText);
|
|
429
442
|
(0, _cell.setCellValue)(ctx, r, c, d, v);
|
|
430
443
|
if ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _e === void 0 ? void 0 : _e.updateCellYdoc) {
|
package/lib/modules/sort.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Cell, CellMatrix, Context } from "..";
|
|
2
2
|
export declare function orderbydata(isAsc: boolean, index: number, data: (Cell | null)[][]): {
|
|
3
3
|
sortedData: (Cell | null)[][];
|
|
4
|
-
|
|
4
|
+
rowMap: Record<number, number>;
|
|
5
5
|
};
|
|
6
6
|
export declare function sortDataRange(ctx: Context, sheetData: CellMatrix, dataRange: CellMatrix, index: number, isAsc: boolean, str: number, edr: number, stc: number, edc: number): void;
|
|
7
7
|
export declare function sortSelection(ctx: Context, isAsc: boolean, colIndex?: number): void;
|
package/lib/modules/sort.js
CHANGED
|
@@ -64,33 +64,70 @@ function orderbydata(isAsc, index, data) {
|
|
|
64
64
|
var d = function d(x, y) {
|
|
65
65
|
return a(y, x);
|
|
66
66
|
};
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
var sortedWithIndex = data.map(function (row, i) {
|
|
68
|
+
return {
|
|
69
|
+
row: row,
|
|
70
|
+
originalIndex: i
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
sortedWithIndex.sort(function (x, y) {
|
|
74
|
+
return isAsc ? a(x.row, y.row) : d(x.row, y.row);
|
|
75
|
+
});
|
|
76
|
+
var sortedData = sortedWithIndex.map(function (item) {
|
|
77
|
+
return item.row;
|
|
78
|
+
});
|
|
79
|
+
var rowMap = {};
|
|
80
|
+
sortedWithIndex.forEach(function (item, newIndex) {
|
|
81
|
+
rowMap[item.originalIndex] = newIndex;
|
|
74
82
|
});
|
|
75
83
|
return {
|
|
76
84
|
sortedData: sortedData,
|
|
77
|
-
|
|
85
|
+
rowMap: rowMap
|
|
78
86
|
};
|
|
79
87
|
}
|
|
80
88
|
function sortDataRange(ctx, sheetData, dataRange, index, isAsc, str, edr, stc, edc) {
|
|
81
|
-
var _a, _b;
|
|
82
|
-
var
|
|
89
|
+
var _a, _b, _c;
|
|
90
|
+
var _d = orderbydata(isAsc, index, dataRange),
|
|
91
|
+
sortedData = _d.sortedData,
|
|
92
|
+
rowMap = _d.rowMap;
|
|
83
93
|
for (var r = str; r <= edr; r += 1) {
|
|
84
94
|
for (var c = stc; c <= edc; c += 1) {
|
|
85
95
|
var cell = sortedData[r - str][c - stc];
|
|
86
96
|
sheetData[r][c] = cell;
|
|
87
97
|
}
|
|
88
98
|
}
|
|
99
|
+
var absoluteRowMap = {};
|
|
100
|
+
Object.keys(rowMap).forEach(function (k) {
|
|
101
|
+
var oldLocal = parseInt(k, 10);
|
|
102
|
+
absoluteRowMap[str + oldLocal] = str + rowMap[oldLocal];
|
|
103
|
+
});
|
|
104
|
+
var sheetIdx = (0, _2.getSheetIndex)(ctx, ctx.currentSheetId);
|
|
105
|
+
var sheet = sheetIdx == null ? null : ctx.luckysheetfile[sheetIdx];
|
|
106
|
+
var sheetName = (sheet === null || sheet === void 0 ? void 0 : sheet.name) || "";
|
|
107
|
+
if (sheetData && sheetName) {
|
|
108
|
+
for (var r = 0; r < sheetData.length; r += 1) {
|
|
109
|
+
var row = sheetData[r];
|
|
110
|
+
if (!row) continue;
|
|
111
|
+
for (var c = 0; c < row.length; c += 1) {
|
|
112
|
+
var cell = row[c];
|
|
113
|
+
if (!(cell === null || cell === void 0 ? void 0 : cell.f)) continue;
|
|
114
|
+
cell.f = (0, _2.remapFormulaReferencesByMap)(cell.f, sheetName, sheetName, {
|
|
115
|
+
rowMap: absoluteRowMap
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
(_a = sheet === null || sheet === void 0 ? void 0 : sheet.calcChain) === null || _a === void 0 ? void 0 : _a.forEach(function (item) {
|
|
121
|
+
var mapped = absoluteRowMap[item.r];
|
|
122
|
+
if (!_lodash.default.isNil(mapped)) {
|
|
123
|
+
item.r = mapped;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
89
126
|
(0, _refresh.jfrefreshgrid)(ctx, sheetData, [{
|
|
90
127
|
row: [str, edr],
|
|
91
128
|
column: [stc, edc]
|
|
92
129
|
}]);
|
|
93
|
-
if ((
|
|
130
|
+
if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _b === void 0 ? void 0 : _b.updateCellYdoc) {
|
|
94
131
|
var changes = [];
|
|
95
132
|
for (var r = str; r <= edr; r += 1) {
|
|
96
133
|
var row = sheetData[r] || [];
|
|
@@ -101,7 +138,7 @@ function sortDataRange(ctx, sheetData, dataRange, index, isAsc, str, edr, stc, e
|
|
|
101
138
|
value: {
|
|
102
139
|
r: r,
|
|
103
140
|
c: c,
|
|
104
|
-
v: (
|
|
141
|
+
v: (_c = row === null || row === void 0 ? void 0 : row[c]) !== null && _c !== void 0 ? _c : null
|
|
105
142
|
},
|
|
106
143
|
key: "".concat(r, "_").concat(c),
|
|
107
144
|
type: "update"
|