@fileverse-dev/fortune-core 1.1.32 → 1.1.34

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.
@@ -1119,7 +1119,7 @@ export function handlePaste(ctx, e) {
1119
1119
  }
1120
1120
  var data_1 = new Array(trList.length);
1121
1121
  var colLen_1 = 0;
1122
- _.forEach(trList[0].querySelectorAll("td"), function (td) {
1122
+ _.forEach(trList[0].querySelectorAll("td, th"), function (td) {
1123
1123
  var colspan = td.colSpan;
1124
1124
  if (Number.isNaN(colspan)) {
1125
1125
  colspan = 1;
@@ -1153,7 +1153,8 @@ export function handlePaste(ctx, e) {
1153
1153
  if (_.has(ctx.luckysheetfile[index_1].config.rowlen, targetR) && ctx.luckysheetfile[index_1].config.rowlen[targetR] !== targetRowHeight || !_.has(ctx.luckysheetfile[index_1].config.rowlen, targetR) && ctx.luckysheetfile[index_1].defaultRowHeight !== targetRowHeight) {
1154
1154
  rowHeightList_1[targetR] = targetRowHeight;
1155
1155
  }
1156
- _.forEach(tr.querySelectorAll("td"), function (td) {
1156
+ _.forEach(tr.querySelectorAll("td, th"), function (element) {
1157
+ var td = element;
1157
1158
  var className = td.className;
1158
1159
  var cell = {};
1159
1160
  var txt = td.innerText || td.innerHTML;
package/es/locale/en.js CHANGED
@@ -8689,14 +8689,14 @@ export default {
8689
8689
  m: [1, 4],
8690
8690
  p: [{
8691
8691
  name: "range",
8692
- detail: "The data to be sorted.",
8692
+ detail: "the cell range to sort.",
8693
8693
  example: "A2:A17",
8694
8694
  require: "m",
8695
8695
  repeat: "n",
8696
8696
  type: "rangenumber"
8697
8697
  }, {
8698
8698
  name: "sort_column",
8699
- detail: "The index of the column in `range` or a range outside of `range` containing the values by which to sort.",
8699
+ detail: "The index of the column in `range` to sort by. The first column in `range` is 1, the second column is 2, and so on.",
8700
8700
  example: "1",
8701
8701
  require: "o",
8702
8702
  repeat: "n",
@@ -8704,17 +8704,10 @@ export default {
8704
8704
  }, {
8705
8705
  name: "is_ascending",
8706
8706
  detail: "`TRUE` or `FALSE` indicating whether to sort `sort_column` in ascending order. `FALSE` sorts in descending order.",
8707
- example: "-1",
8707
+ example: "\"TRUE\"",
8708
8708
  require: "o",
8709
8709
  repeat: "n",
8710
- type: "rangenumber"
8711
- }, {
8712
- name: "sort_column2",
8713
- detail: "Additional columns.",
8714
- example: "TRUE()",
8715
- require: "o",
8716
- repeat: "n",
8717
- type: "rangeall"
8710
+ type: "string"
8718
8711
  }]
8719
8712
  }, {
8720
8713
  n: "FILTER",
@@ -10,6 +10,7 @@ import { delFunctionGroup, execfunction, execFunctionGroup, functionHTMLGenerate
10
10
  import { attrToCssName, convertSpanToShareString, isInlineStringCell, isInlineStringCT } from "./inline-string";
11
11
  import { isRealNull, isRealNum, valueIsError } from "./validation";
12
12
  import { getCellTextInfo } from "./text";
13
+ import { spillSortResult } from "./sort";
13
14
  export function normalizedCellAttr(cell, attr, defaultFontSize) {
14
15
  if (defaultFontSize === void 0) {
15
16
  defaultFontSize = 10;
@@ -476,7 +477,7 @@ export function cancelNormalSelected(ctx) {
476
477
  ctx.formulaCache.rangedrag_row_start = false;
477
478
  }
478
479
  export function updateCell(ctx, r, c, $input, value, canvas) {
479
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
480
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
480
481
  var inputText = $input === null || $input === void 0 ? void 0 : $input.innerText;
481
482
  var inputHtml = $input === null || $input === void 0 ? void 0 : $input.innerHTML;
482
483
  var flowdata = getFlowdata(ctx);
@@ -698,13 +699,32 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
698
699
  } else if (_typeof(value) === "object" && !value.tb) {
699
700
  value.tb = "1";
700
701
  }
702
+ var isValueArray = Array.isArray((_p = value === null || value === void 0 ? void 0 : value.v) === null || _p === void 0 ? void 0 : _p[0]);
703
+ try {
704
+ if (isValueArray) {
705
+ if (spillSortResult(ctx, r, c, value, d)) {
706
+ cancelNormalSelected(ctx);
707
+ if (ctx.hooks.afterUpdateCell) {
708
+ var newValue_1 = _.cloneDeep(d[r][c]);
709
+ setTimeout(function () {
710
+ var _a, _b;
711
+ return (_b = (_a = ctx.hooks).afterUpdateCell) === null || _b === void 0 ? void 0 : _b.call(_a, r, c, null, newValue_1);
712
+ });
713
+ }
714
+ ctx.formulaCache.execFunctionGlobalData = null;
715
+ return;
716
+ }
717
+ }
718
+ } catch (e) {
719
+ console.log("[updateCell] spill failed; falling back", e);
720
+ }
701
721
  setCellValue(ctx, r, c, d, value);
702
722
  cancelNormalSelected(ctx);
703
723
  if ((curv === null || curv === void 0 ? void 0 : curv.tb) === "2" && curv.v || isInlineStringCell(d[r][c])) {
704
724
  var defaultrowlen = ctx.defaultrowlen;
705
725
  var cfg = ctx.luckysheetfile[getSheetIndex(ctx, ctx.currentSheetId)].config || {};
706
- if (!(((_p = cfg.columnlen) === null || _p === void 0 ? void 0 : _p[c]) && ((_q = cfg.rowlen) === null || _q === void 0 ? void 0 : _q[r]))) {
707
- var cellWidth = ((_r = cfg.columnlen) === null || _r === void 0 ? void 0 : _r[c]) || ctx.defaultcollen;
726
+ if (!(((_q = cfg.columnlen) === null || _q === void 0 ? void 0 : _q[c]) && ((_r = cfg.rowlen) === null || _r === void 0 ? void 0 : _r[r]))) {
727
+ var cellWidth = ((_s = cfg.columnlen) === null || _s === void 0 ? void 0 : _s[c]) || ctx.defaultcollen;
708
728
  var textInfo = canvas ? getCellTextInfo(d[r][c], canvas, ctx, {
709
729
  r: r,
710
730
  c: c,
@@ -715,17 +735,17 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
715
735
  currentRowLen = textInfo.textHeightAll + 2;
716
736
  }
717
737
  var previousRowHeight = getRowHeight(ctx, [r])[r];
718
- if (currentRowLen > defaultrowlen && !((_s = cfg.customHeight) === null || _s === void 0 ? void 0 : _s[r]) && previousRowHeight < currentRowLen) {
738
+ if (currentRowLen > defaultrowlen && !((_t = cfg.customHeight) === null || _t === void 0 ? void 0 : _t[r]) && previousRowHeight < currentRowLen) {
719
739
  if (_.isNil(cfg.rowlen)) cfg.rowlen = {};
720
740
  cfg.rowlen[r] = currentRowLen;
721
741
  }
722
742
  }
723
743
  }
724
744
  if (ctx.hooks.afterUpdateCell) {
725
- var newValue_1 = _.cloneDeep(flowdata[r][c]);
745
+ var newValue_2 = _.cloneDeep(flowdata[r][c]);
726
746
  var afterUpdateCell_1 = ctx.hooks.afterUpdateCell;
727
747
  setTimeout(function () {
728
- afterUpdateCell_1 === null || afterUpdateCell_1 === void 0 ? void 0 : afterUpdateCell_1(r, c, oldValue, newValue_1);
748
+ afterUpdateCell_1 === null || afterUpdateCell_1 === void 0 ? void 0 : afterUpdateCell_1(r, c, oldValue, newValue_2);
729
749
  });
730
750
  }
731
751
  ctx.formulaCache.execFunctionGlobalData = null;
@@ -28,7 +28,7 @@ import { moveToEnd } from "./cursor";
28
28
  import { locale } from "../locale";
29
29
  import { colors } from "./color";
30
30
  import { colLocation, mousePosition, rowLocation } from "./location";
31
- import { cancelFunctionrangeSelected, seletedHighlistByindex } from ".";
31
+ import { cancelFunctionrangeSelected, seletedHighlistByindex, spillSortResult } from ".";
32
32
  var functionHTMLIndex = 0;
33
33
  var rangeIndexes = [];
34
34
  var operatorPriority = {
@@ -1018,6 +1018,30 @@ export function execFunctionGroup(ctx, origin_r, origin_c, value, id, data, isFo
1018
1018
  }
1019
1019
  var calc_funcStr = formulaCell.calc_funcStr;
1020
1020
  var v = execfunction(ctx, calc_funcStr, formulaCell.r, formulaCell.c, formulaCell.id, calcChainSet);
1021
+ var valueData = v === null || v === void 0 ? void 0 : v[1];
1022
+ var valueFunction = v === null || v === void 0 ? void 0 : v[2];
1023
+ if (Array.isArray(valueData)) {
1024
+ var spilled = spillSortResult(ctx, formulaCell.r, formulaCell.c, {
1025
+ v: valueData,
1026
+ f: valueFunction
1027
+ }, data);
1028
+ if (spilled) {
1029
+ var matrixTopLeftValue = Array.isArray(valueData[0]) ? valueData[0][0] : valueData[0];
1030
+ ctx.groupValuesRefreshData.push({
1031
+ r: formulaCell.r,
1032
+ c: formulaCell.c,
1033
+ v: matrixTopLeftValue,
1034
+ f: valueFunction,
1035
+ spe: v[3],
1036
+ id: formulaCell.id
1037
+ });
1038
+ ctx.formulaCache.execFunctionGlobalData["".concat(formulaCell.r, "_").concat(formulaCell.c, "_").concat(formulaCell.id)] = {
1039
+ v: matrixTopLeftValue,
1040
+ f: valueFunction
1041
+ };
1042
+ continue;
1043
+ }
1044
+ }
1021
1045
  ctx.groupValuesRefreshData.push({
1022
1046
  r: formulaCell.r,
1023
1047
  c: formulaCell.c,
@@ -5,3 +5,4 @@ export declare function orderbydata(isAsc: boolean, index: number, data: (Cell |
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;
8
+ export declare function spillSortResult(ctx: Context, startRow: number, startCol: number, formulaResult: any, flowdata?: CellMatrix): boolean;
@@ -1,6 +1,16 @@
1
+ var __assign = this && this.__assign || function () {
2
+ __assign = Object.assign || function (t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
+ }
7
+ return t;
8
+ };
9
+ return __assign.apply(this, arguments);
10
+ };
1
11
  import numeral from "numeral";
2
12
  import _ from "lodash";
3
- import { diff, getFlowdata, isdatetime, isRealNull, isRealNum } from "..";
13
+ import { diff, getFlowdata, getSheetIndex, isdatetime, isRealNull, isRealNum, setCellValue } from "..";
4
14
  import { jfrefreshgrid } from "./refresh";
5
15
  export function orderbydata(isAsc, index, data) {
6
16
  if (isAsc == null) {
@@ -131,4 +141,67 @@ export function sortSelection(ctx, isAsc, colIndex) {
131
141
  return;
132
142
  }
133
143
  sortDataRange(ctx, d, data, colIndex, isAsc, str, edr, c1, c2);
144
+ }
145
+ function createRowsOrColumnsForSpilledValues(ctx, startRow, startColumn, spillRows, spillCols) {
146
+ var flowdata = getFlowdata(ctx);
147
+ if (!flowdata) return;
148
+ try {
149
+ var sheetIndex = getSheetIndex(ctx, ctx.currentSheetId);
150
+ var sheet = ctx.luckysheetfile[sheetIndex];
151
+ var requiredRowCount = startRow + spillRows;
152
+ var requiredColCount = startColumn + spillCols;
153
+ if (sheet.row && sheet.row < requiredRowCount) {
154
+ sheet.row = requiredRowCount;
155
+ }
156
+ if (sheet.column && sheet.column < requiredColCount) {
157
+ sheet.column = requiredColCount;
158
+ }
159
+ } catch (error) {
160
+ console.error("Failed to update sheet metadata for spill operation", error);
161
+ }
162
+ while (flowdata.length < startRow + spillRows) {
163
+ flowdata.push([]);
164
+ }
165
+ for (var rowIndex = startRow; rowIndex < startRow + spillRows; rowIndex++) {
166
+ if (!Array.isArray(flowdata[rowIndex])) {
167
+ flowdata[rowIndex] = [];
168
+ }
169
+ while (flowdata[rowIndex].length < startColumn + spillCols) {
170
+ flowdata[rowIndex].push(null);
171
+ }
172
+ }
173
+ }
174
+ export function spillSortResult(ctx, startRow, startCol, formulaResult, flowdata) {
175
+ var formulaString = formulaResult === null || formulaResult === void 0 ? void 0 : formulaResult.f;
176
+ var formulaValue = formulaResult === null || formulaResult === void 0 ? void 0 : formulaResult.v;
177
+ if (typeof formulaString !== "string" || !/= *SORT\s*\(/i.test(formulaString)) return false;
178
+ if (!Array.isArray(formulaValue)) return false;
179
+ var valueMatrix = Array.isArray(formulaValue[0]) ? formulaValue : formulaValue.map(function (x) {
180
+ return [x];
181
+ });
182
+ var rowCount = valueMatrix.length;
183
+ var colCount = rowCount && Array.isArray(valueMatrix[0]) ? valueMatrix[0].length : 0;
184
+ if (!rowCount || !colCount) return false;
185
+ createRowsOrColumnsForSpilledValues(ctx, startRow, startCol, rowCount, colCount);
186
+ var sheetData = flowdata || getFlowdata(ctx);
187
+ if (!sheetData) return false;
188
+ setCellValue(ctx, startRow, startCol, sheetData, __assign(__assign({}, formulaResult), {
189
+ v: valueMatrix[0][0],
190
+ tb: "1"
191
+ }));
192
+ for (var r = 0; r < rowCount; r++) {
193
+ for (var c = 0; c < colCount; c++) {
194
+ if (r === 0 && c === 0) continue;
195
+ var cellValue = valueMatrix[r][c];
196
+ setCellValue(ctx, startRow + r, startCol + c, sheetData, {
197
+ v: cellValue,
198
+ ct: {
199
+ fa: "General",
200
+ t: typeof cellValue === "number" ? "n" : "g"
201
+ },
202
+ tb: "1"
203
+ });
204
+ }
205
+ }
206
+ return true;
134
207
  }
@@ -1128,7 +1128,7 @@ function handlePaste(ctx, e) {
1128
1128
  }
1129
1129
  var data_1 = new Array(trList.length);
1130
1130
  var colLen_1 = 0;
1131
- _lodash.default.forEach(trList[0].querySelectorAll("td"), function (td) {
1131
+ _lodash.default.forEach(trList[0].querySelectorAll("td, th"), function (td) {
1132
1132
  var colspan = td.colSpan;
1133
1133
  if (Number.isNaN(colspan)) {
1134
1134
  colspan = 1;
@@ -1162,7 +1162,8 @@ function handlePaste(ctx, e) {
1162
1162
  if (_lodash.default.has(ctx.luckysheetfile[index_1].config.rowlen, targetR) && ctx.luckysheetfile[index_1].config.rowlen[targetR] !== targetRowHeight || !_lodash.default.has(ctx.luckysheetfile[index_1].config.rowlen, targetR) && ctx.luckysheetfile[index_1].defaultRowHeight !== targetRowHeight) {
1163
1163
  rowHeightList_1[targetR] = targetRowHeight;
1164
1164
  }
1165
- _lodash.default.forEach(tr.querySelectorAll("td"), function (td) {
1165
+ _lodash.default.forEach(tr.querySelectorAll("td, th"), function (element) {
1166
+ var td = element;
1166
1167
  var className = td.className;
1167
1168
  var cell = {};
1168
1169
  var txt = td.innerText || td.innerHTML;
package/lib/locale/en.js CHANGED
@@ -8695,14 +8695,14 @@ var _default = exports.default = {
8695
8695
  m: [1, 4],
8696
8696
  p: [{
8697
8697
  name: "range",
8698
- detail: "The data to be sorted.",
8698
+ detail: "the cell range to sort.",
8699
8699
  example: "A2:A17",
8700
8700
  require: "m",
8701
8701
  repeat: "n",
8702
8702
  type: "rangenumber"
8703
8703
  }, {
8704
8704
  name: "sort_column",
8705
- detail: "The index of the column in `range` or a range outside of `range` containing the values by which to sort.",
8705
+ detail: "The index of the column in `range` to sort by. The first column in `range` is 1, the second column is 2, and so on.",
8706
8706
  example: "1",
8707
8707
  require: "o",
8708
8708
  repeat: "n",
@@ -8710,17 +8710,10 @@ var _default = exports.default = {
8710
8710
  }, {
8711
8711
  name: "is_ascending",
8712
8712
  detail: "`TRUE` or `FALSE` indicating whether to sort `sort_column` in ascending order. `FALSE` sorts in descending order.",
8713
- example: "-1",
8713
+ example: "\"TRUE\"",
8714
8714
  require: "o",
8715
8715
  repeat: "n",
8716
- type: "rangenumber"
8717
- }, {
8718
- name: "sort_column2",
8719
- detail: "Additional columns.",
8720
- example: "TRUE()",
8721
- require: "o",
8722
- repeat: "n",
8723
- type: "rangeall"
8716
+ type: "string"
8724
8717
  }]
8725
8718
  }, {
8726
8719
  n: "FILTER",
@@ -38,6 +38,7 @@ var _formula = require("./formula");
38
38
  var _inlineString = require("./inline-string");
39
39
  var _validation = require("./validation");
40
40
  var _text = require("./text");
41
+ var _sort = require("./sort");
41
42
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
42
43
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
43
44
  function normalizedCellAttr(cell, attr, defaultFontSize) {
@@ -506,7 +507,7 @@ function cancelNormalSelected(ctx) {
506
507
  ctx.formulaCache.rangedrag_row_start = false;
507
508
  }
508
509
  function updateCell(ctx, r, c, $input, value, canvas) {
509
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
510
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
510
511
  var inputText = $input === null || $input === void 0 ? void 0 : $input.innerText;
511
512
  var inputHtml = $input === null || $input === void 0 ? void 0 : $input.innerHTML;
512
513
  var flowdata = (0, _context.getFlowdata)(ctx);
@@ -728,13 +729,32 @@ function updateCell(ctx, r, c, $input, value, canvas) {
728
729
  } else if (_typeof(value) === "object" && !value.tb) {
729
730
  value.tb = "1";
730
731
  }
732
+ var isValueArray = Array.isArray((_p = value === null || value === void 0 ? void 0 : value.v) === null || _p === void 0 ? void 0 : _p[0]);
733
+ try {
734
+ if (isValueArray) {
735
+ if ((0, _sort.spillSortResult)(ctx, r, c, value, d)) {
736
+ cancelNormalSelected(ctx);
737
+ if (ctx.hooks.afterUpdateCell) {
738
+ var newValue_1 = _lodash.default.cloneDeep(d[r][c]);
739
+ setTimeout(function () {
740
+ var _a, _b;
741
+ return (_b = (_a = ctx.hooks).afterUpdateCell) === null || _b === void 0 ? void 0 : _b.call(_a, r, c, null, newValue_1);
742
+ });
743
+ }
744
+ ctx.formulaCache.execFunctionGlobalData = null;
745
+ return;
746
+ }
747
+ }
748
+ } catch (e) {
749
+ console.log("[updateCell] spill failed; falling back", e);
750
+ }
731
751
  setCellValue(ctx, r, c, d, value);
732
752
  cancelNormalSelected(ctx);
733
753
  if ((curv === null || curv === void 0 ? void 0 : curv.tb) === "2" && curv.v || (0, _inlineString.isInlineStringCell)(d[r][c])) {
734
754
  var defaultrowlen = ctx.defaultrowlen;
735
755
  var cfg = ctx.luckysheetfile[(0, _utils.getSheetIndex)(ctx, ctx.currentSheetId)].config || {};
736
- if (!(((_p = cfg.columnlen) === null || _p === void 0 ? void 0 : _p[c]) && ((_q = cfg.rowlen) === null || _q === void 0 ? void 0 : _q[r]))) {
737
- var cellWidth = ((_r = cfg.columnlen) === null || _r === void 0 ? void 0 : _r[c]) || ctx.defaultcollen;
756
+ if (!(((_q = cfg.columnlen) === null || _q === void 0 ? void 0 : _q[c]) && ((_r = cfg.rowlen) === null || _r === void 0 ? void 0 : _r[r]))) {
757
+ var cellWidth = ((_s = cfg.columnlen) === null || _s === void 0 ? void 0 : _s[c]) || ctx.defaultcollen;
738
758
  var textInfo = canvas ? (0, _text.getCellTextInfo)(d[r][c], canvas, ctx, {
739
759
  r: r,
740
760
  c: c,
@@ -745,17 +765,17 @@ function updateCell(ctx, r, c, $input, value, canvas) {
745
765
  currentRowLen = textInfo.textHeightAll + 2;
746
766
  }
747
767
  var previousRowHeight = (0, _api.getRowHeight)(ctx, [r])[r];
748
- if (currentRowLen > defaultrowlen && !((_s = cfg.customHeight) === null || _s === void 0 ? void 0 : _s[r]) && previousRowHeight < currentRowLen) {
768
+ if (currentRowLen > defaultrowlen && !((_t = cfg.customHeight) === null || _t === void 0 ? void 0 : _t[r]) && previousRowHeight < currentRowLen) {
749
769
  if (_lodash.default.isNil(cfg.rowlen)) cfg.rowlen = {};
750
770
  cfg.rowlen[r] = currentRowLen;
751
771
  }
752
772
  }
753
773
  }
754
774
  if (ctx.hooks.afterUpdateCell) {
755
- var newValue_1 = _lodash.default.cloneDeep(flowdata[r][c]);
775
+ var newValue_2 = _lodash.default.cloneDeep(flowdata[r][c]);
756
776
  var afterUpdateCell_1 = ctx.hooks.afterUpdateCell;
757
777
  setTimeout(function () {
758
- afterUpdateCell_1 === null || afterUpdateCell_1 === void 0 ? void 0 : afterUpdateCell_1(r, c, oldValue, newValue_1);
778
+ afterUpdateCell_1 === null || afterUpdateCell_1 === void 0 ? void 0 : afterUpdateCell_1(r, c, oldValue, newValue_2);
759
779
  });
760
780
  }
761
781
  ctx.formulaCache.execFunctionGlobalData = null;
@@ -1047,6 +1047,30 @@ function execFunctionGroup(ctx, origin_r, origin_c, value, id, data, isForce) {
1047
1047
  }
1048
1048
  var calc_funcStr = formulaCell.calc_funcStr;
1049
1049
  var v = execfunction(ctx, calc_funcStr, formulaCell.r, formulaCell.c, formulaCell.id, calcChainSet);
1050
+ var valueData = v === null || v === void 0 ? void 0 : v[1];
1051
+ var valueFunction = v === null || v === void 0 ? void 0 : v[2];
1052
+ if (Array.isArray(valueData)) {
1053
+ var spilled = (0, _2.spillSortResult)(ctx, formulaCell.r, formulaCell.c, {
1054
+ v: valueData,
1055
+ f: valueFunction
1056
+ }, data);
1057
+ if (spilled) {
1058
+ var matrixTopLeftValue = Array.isArray(valueData[0]) ? valueData[0][0] : valueData[0];
1059
+ ctx.groupValuesRefreshData.push({
1060
+ r: formulaCell.r,
1061
+ c: formulaCell.c,
1062
+ v: matrixTopLeftValue,
1063
+ f: valueFunction,
1064
+ spe: v[3],
1065
+ id: formulaCell.id
1066
+ });
1067
+ ctx.formulaCache.execFunctionGlobalData["".concat(formulaCell.r, "_").concat(formulaCell.c, "_").concat(formulaCell.id)] = {
1068
+ v: matrixTopLeftValue,
1069
+ f: valueFunction
1070
+ };
1071
+ continue;
1072
+ }
1073
+ }
1050
1074
  ctx.groupValuesRefreshData.push({
1051
1075
  r: formulaCell.r,
1052
1076
  c: formulaCell.c,
@@ -5,3 +5,4 @@ export declare function orderbydata(isAsc: boolean, index: number, data: (Cell |
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;
8
+ export declare function spillSortResult(ctx: Context, startRow: number, startCol: number, formulaResult: any, flowdata?: CellMatrix): boolean;
@@ -6,11 +6,22 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.orderbydata = orderbydata;
7
7
  exports.sortDataRange = sortDataRange;
8
8
  exports.sortSelection = sortSelection;
9
+ exports.spillSortResult = spillSortResult;
9
10
  var _numeral = _interopRequireDefault(require("numeral"));
10
11
  var _lodash = _interopRequireDefault(require("lodash"));
11
12
  var _2 = require("..");
12
13
  var _refresh = require("./refresh");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ var __assign = void 0 && (void 0).__assign || function () {
16
+ __assign = Object.assign || function (t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
20
+ }
21
+ return t;
22
+ };
23
+ return __assign.apply(this, arguments);
24
+ };
14
25
  function orderbydata(isAsc, index, data) {
15
26
  if (isAsc == null) {
16
27
  isAsc = true;
@@ -140,4 +151,67 @@ function sortSelection(ctx, isAsc, colIndex) {
140
151
  return;
141
152
  }
142
153
  sortDataRange(ctx, d, data, colIndex, isAsc, str, edr, c1, c2);
154
+ }
155
+ function createRowsOrColumnsForSpilledValues(ctx, startRow, startColumn, spillRows, spillCols) {
156
+ var flowdata = (0, _2.getFlowdata)(ctx);
157
+ if (!flowdata) return;
158
+ try {
159
+ var sheetIndex = (0, _2.getSheetIndex)(ctx, ctx.currentSheetId);
160
+ var sheet = ctx.luckysheetfile[sheetIndex];
161
+ var requiredRowCount = startRow + spillRows;
162
+ var requiredColCount = startColumn + spillCols;
163
+ if (sheet.row && sheet.row < requiredRowCount) {
164
+ sheet.row = requiredRowCount;
165
+ }
166
+ if (sheet.column && sheet.column < requiredColCount) {
167
+ sheet.column = requiredColCount;
168
+ }
169
+ } catch (error) {
170
+ console.error("Failed to update sheet metadata for spill operation", error);
171
+ }
172
+ while (flowdata.length < startRow + spillRows) {
173
+ flowdata.push([]);
174
+ }
175
+ for (var rowIndex = startRow; rowIndex < startRow + spillRows; rowIndex++) {
176
+ if (!Array.isArray(flowdata[rowIndex])) {
177
+ flowdata[rowIndex] = [];
178
+ }
179
+ while (flowdata[rowIndex].length < startColumn + spillCols) {
180
+ flowdata[rowIndex].push(null);
181
+ }
182
+ }
183
+ }
184
+ function spillSortResult(ctx, startRow, startCol, formulaResult, flowdata) {
185
+ var formulaString = formulaResult === null || formulaResult === void 0 ? void 0 : formulaResult.f;
186
+ var formulaValue = formulaResult === null || formulaResult === void 0 ? void 0 : formulaResult.v;
187
+ if (typeof formulaString !== "string" || !/= *SORT\s*\(/i.test(formulaString)) return false;
188
+ if (!Array.isArray(formulaValue)) return false;
189
+ var valueMatrix = Array.isArray(formulaValue[0]) ? formulaValue : formulaValue.map(function (x) {
190
+ return [x];
191
+ });
192
+ var rowCount = valueMatrix.length;
193
+ var colCount = rowCount && Array.isArray(valueMatrix[0]) ? valueMatrix[0].length : 0;
194
+ if (!rowCount || !colCount) return false;
195
+ createRowsOrColumnsForSpilledValues(ctx, startRow, startCol, rowCount, colCount);
196
+ var sheetData = flowdata || (0, _2.getFlowdata)(ctx);
197
+ if (!sheetData) return false;
198
+ (0, _2.setCellValue)(ctx, startRow, startCol, sheetData, __assign(__assign({}, formulaResult), {
199
+ v: valueMatrix[0][0],
200
+ tb: "1"
201
+ }));
202
+ for (var r = 0; r < rowCount; r++) {
203
+ for (var c = 0; c < colCount; c++) {
204
+ if (r === 0 && c === 0) continue;
205
+ var cellValue = valueMatrix[r][c];
206
+ (0, _2.setCellValue)(ctx, startRow + r, startCol + c, sheetData, {
207
+ v: cellValue,
208
+ ct: {
209
+ fa: "General",
210
+ t: typeof cellValue === "number" ? "n" : "g"
211
+ },
212
+ tb: "1"
213
+ });
214
+ }
215
+ }
216
+ return true;
143
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.1.32",
3
+ "version": "1.1.34",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "dev": "father-build --watch"
16
16
  },
17
17
  "dependencies": {
18
- "@fileverse-dev/formula-parser": "0.2.68",
18
+ "@fileverse-dev/formula-parser": "0.2.69",
19
19
  "dayjs": "^1.11.0",
20
20
  "immer": "^9.0.12",
21
21
  "lodash": "^4.17.21",