@univerjs/engine-formula 1.0.0-alpha.2 → 1.0.0-alpha.4
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/lib/cjs/facade.js +9 -5
- package/lib/cjs/index.js +2017 -356
- package/lib/es/facade.js +9 -5
- package/lib/es/index.js +1999 -359
- package/lib/facade.js +9 -5
- package/lib/index.js +1999 -359
- package/lib/types/basics/common.d.ts +16 -1
- package/lib/types/basics/date.d.ts +2 -2
- package/lib/types/basics/regex.d.ts +4 -4
- package/lib/types/commands/mutations/set-super-table.mutation.d.ts +4 -1
- package/lib/types/controllers/formula-calculation-trigger.controller.d.ts +20 -0
- package/lib/types/controllers/super-table-active-dirty.controller.d.ts +22 -0
- package/lib/types/engine/analysis/lexer-node.d.ts +3 -3
- package/lib/types/engine/analysis/lexer-tree-builder.d.ts +2 -1
- package/lib/types/engine/analysis/lexer.d.ts +2 -1
- package/lib/types/engine/analysis/parser.d.ts +2 -1
- package/lib/types/engine/ast-node/function-node.d.ts +9 -2
- package/lib/types/engine/ast-node/operator-node.d.ts +1 -0
- package/lib/types/engine/ast-node/prefix-node.d.ts +1 -0
- package/lib/types/engine/ast-node/reference-node.d.ts +14 -4
- package/lib/types/engine/interpreter/interpreter.d.ts +11 -0
- package/lib/types/engine/reference-object/base-reference-object.d.ts +3 -0
- package/lib/types/engine/reference-object/cell-reference-object.d.ts +1 -0
- package/lib/types/engine/reference-object/table-reference-object.d.ts +2 -0
- package/lib/types/engine/utils/generate-ast-node.d.ts +1 -1
- package/lib/types/engine/utils/math-kit.d.ts +5 -0
- package/lib/types/engine/utils/reference.d.ts +3 -5
- package/lib/types/engine/utils/unit-qualifier.d.ts +32 -0
- package/lib/types/engine/value-object/array-value-object.d.ts +5 -0
- package/lib/types/engine/value-object/base-value-object.d.ts +6 -0
- package/lib/types/facade/f-formula.d.ts +9 -5
- package/lib/types/functions/base-function.d.ts +21 -1
- package/lib/types/functions/cube/cubekpimember/index.d.ts +20 -0
- package/lib/types/functions/cube/cubemember/index.d.ts +20 -0
- package/lib/types/functions/cube/cubememberproperty/index.d.ts +20 -0
- package/lib/types/functions/cube/cuberankedmember/index.d.ts +20 -0
- package/lib/types/functions/cube/cubeset/index.d.ts +20 -0
- package/lib/types/functions/cube/cubesetcount/index.d.ts +20 -0
- package/lib/types/functions/cube/cubevalue/index.d.ts +20 -0
- package/lib/types/functions/financial/amordegrc/index.d.ts +20 -0
- package/lib/types/functions/information/info/index.d.ts +20 -0
- package/lib/types/functions/information/isomitted/index.d.ts +20 -0
- package/lib/types/functions/logical/function-map.d.ts +3 -2
- package/lib/types/functions/logical/function-names.d.ts +2 -0
- package/lib/types/functions/logical/groupby/index.d.ts +46 -0
- package/lib/types/functions/logical/if/index.d.ts +5 -0
- package/lib/types/functions/logical/iferror/index.d.ts +4 -1
- package/lib/types/functions/logical/percentof/index.d.ts +27 -0
- package/lib/types/functions/lookup/anchorarray/index.d.ts +23 -0
- package/lib/types/functions/lookup/function-names.d.ts +1 -0
- package/lib/types/functions/lookup/getpivotdata/index.d.ts +20 -0
- package/lib/types/functions/lookup/hlookup/index.d.ts +1 -0
- package/lib/types/functions/lookup/indirect/index.d.ts +2 -0
- package/lib/types/functions/lookup/rtd/index.d.ts +20 -0
- package/lib/types/functions/lookup/vlookup/index.d.ts +2 -0
- package/lib/types/functions/lookup/xlookup/index.d.ts +2 -0
- package/lib/types/functions/math/iso-ceiling/index.d.ts +20 -0
- package/lib/types/functions/math/sum/index.d.ts +1 -0
- package/lib/types/functions/meta/compare/index.d.ts +1 -0
- package/lib/types/functions/not-implemented-function.d.ts +23 -0
- package/lib/types/functions/statistical/average/index.d.ts +1 -0
- package/lib/types/functions/statistical/countifs/index.d.ts +1 -0
- package/lib/types/functions/statistical/forecast-ets/index.d.ts +20 -0
- package/lib/types/functions/statistical/forecast-ets-confint/index.d.ts +20 -0
- package/lib/types/functions/statistical/forecast-ets-seasonality/index.d.ts +20 -0
- package/lib/types/functions/statistical/forecast-ets-stat/index.d.ts +20 -0
- package/lib/types/functions/statistical/linest/index.d.ts +1 -0
- package/lib/types/functions/text/call/index.d.ts +20 -0
- package/lib/types/functions/text/euroconvert/index.d.ts +20 -0
- package/lib/types/functions/text/function-names.d.ts +1 -0
- package/lib/types/functions/text/phonetic/index.d.ts +20 -0
- package/lib/types/functions/text/register-id/index.d.ts +20 -0
- package/lib/types/functions/text/textsplit/index.d.ts +1 -0
- package/lib/types/functions/web/filterxml/index.d.ts +22 -0
- package/lib/types/functions/web/function-map.d.ts +2 -2
- package/lib/types/functions/web/webservice/index.d.ts +20 -0
- package/lib/types/index.d.ts +7 -2
- package/lib/types/models/formula-data.model.d.ts +4 -2
- package/lib/types/services/active-dirty-manager.service.d.ts +2 -1
- package/lib/types/services/calculate-formula.service.d.ts +2 -2
- package/lib/types/services/current-data.service.d.ts +6 -1
- package/lib/types/services/defined-names.service.d.ts +2 -2
- package/lib/types/services/formula-calculation-trigger.service.d.ts +43 -0
- package/lib/types/services/runtime.service.d.ts +6 -0
- package/lib/types/services/unit-reference-resolver.service.d.ts +39 -0
- package/lib/umd/index.js +5 -2
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -508,12 +508,14 @@ var BaseValueObject = class extends ObjectClassType {
|
|
|
508
508
|
return ErrorValueObject.create("#NAME?");
|
|
509
509
|
}
|
|
510
510
|
concatenate(value, concatenateType = 0) {
|
|
511
|
-
let currentValue = this.getValue()
|
|
511
|
+
let currentValue = formatValueForFormulaText(this.getValue());
|
|
512
512
|
if (typeof value === "string") if (concatenateType === 0) currentValue = value + currentValue;
|
|
513
513
|
else currentValue += value;
|
|
514
|
-
else if (typeof value === "number")
|
|
515
|
-
|
|
516
|
-
|
|
514
|
+
else if (typeof value === "number") {
|
|
515
|
+
const numberString = formatNumberForFormulaText(value);
|
|
516
|
+
if (concatenateType === 0) currentValue = numberString + currentValue;
|
|
517
|
+
else currentValue += numberString;
|
|
518
|
+
} else if (typeof value === "boolean") {
|
|
517
519
|
const booleanString = value ? "TRUE" : "FALSE";
|
|
518
520
|
if (concatenateType === 0) currentValue = booleanString + currentValue;
|
|
519
521
|
else currentValue += booleanString;
|
|
@@ -679,6 +681,16 @@ var BaseValueObject = class extends ObjectClassType {
|
|
|
679
681
|
return ErrorValueObject.create("#VALUE!");
|
|
680
682
|
}
|
|
681
683
|
};
|
|
684
|
+
function formatValueForFormulaText(value) {
|
|
685
|
+
if (typeof value === "number") return formatNumberForFormulaText(value);
|
|
686
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
687
|
+
return value == null ? "" : value.toString();
|
|
688
|
+
}
|
|
689
|
+
function formatNumberForFormulaText(value) {
|
|
690
|
+
if (!Number.isFinite(value)) return value.toString();
|
|
691
|
+
const rounded = Number(value.toPrecision(15));
|
|
692
|
+
return Object.is(rounded, -0) ? "0" : rounded.toString();
|
|
693
|
+
}
|
|
682
694
|
const Error_CACHE_LRU_COUNT = 1e3;
|
|
683
695
|
const ErrorValueObjectCache = new FormulaAstLRU(Error_CACHE_LRU_COUNT);
|
|
684
696
|
var ErrorValueObject = class ErrorValueObject extends BaseValueObject {
|
|
@@ -711,6 +723,12 @@ var ErrorValueObject = class ErrorValueObject extends BaseValueObject {
|
|
|
711
723
|
isError() {
|
|
712
724
|
return true;
|
|
713
725
|
}
|
|
726
|
+
concatenateFront(_valueObject) {
|
|
727
|
+
return this;
|
|
728
|
+
}
|
|
729
|
+
concatenateBack(_valueObject) {
|
|
730
|
+
return this;
|
|
731
|
+
}
|
|
714
732
|
};
|
|
715
733
|
|
|
716
734
|
//#endregion
|
|
@@ -781,6 +799,43 @@ function parseFormattedDate(value) {
|
|
|
781
799
|
function parseFormattedTime(value) {
|
|
782
800
|
return _univerjs_core.numfmt.parseTime(value);
|
|
783
801
|
}
|
|
802
|
+
function parseEnglishMonthNameDate(value) {
|
|
803
|
+
const match = value.trim().match(/^(\d{1,2})\s*([A-Za-z]{3,9})\s*(\d{2,4})$/);
|
|
804
|
+
if (!match) return null;
|
|
805
|
+
const [, dayText, monthText, yearText] = match;
|
|
806
|
+
const month = {
|
|
807
|
+
jan: 0,
|
|
808
|
+
january: 0,
|
|
809
|
+
feb: 1,
|
|
810
|
+
february: 1,
|
|
811
|
+
mar: 2,
|
|
812
|
+
march: 2,
|
|
813
|
+
apr: 3,
|
|
814
|
+
april: 3,
|
|
815
|
+
may: 4,
|
|
816
|
+
jun: 5,
|
|
817
|
+
june: 5,
|
|
818
|
+
jul: 6,
|
|
819
|
+
july: 6,
|
|
820
|
+
aug: 7,
|
|
821
|
+
august: 7,
|
|
822
|
+
sep: 8,
|
|
823
|
+
sept: 8,
|
|
824
|
+
september: 8,
|
|
825
|
+
oct: 9,
|
|
826
|
+
october: 9,
|
|
827
|
+
nov: 10,
|
|
828
|
+
november: 10,
|
|
829
|
+
dec: 11,
|
|
830
|
+
december: 11
|
|
831
|
+
}[monthText.toLowerCase()];
|
|
832
|
+
if (month == null) return null;
|
|
833
|
+
const day = Number(dayText);
|
|
834
|
+
const year = Number(yearText.length === 2 ? `20${yearText}` : yearText);
|
|
835
|
+
const date = new Date(Date.UTC(year, month, day));
|
|
836
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return null;
|
|
837
|
+
return date;
|
|
838
|
+
}
|
|
784
839
|
function isDate(format) {
|
|
785
840
|
return _univerjs_core.numfmt.getFormatInfo(format).isDate;
|
|
786
841
|
}
|
|
@@ -859,6 +914,7 @@ function getDateSerialNumberByObject(serialNumberObject) {
|
|
|
859
914
|
let dateSerial;
|
|
860
915
|
if (parseFormattedDate(`${dateValue}`)) dateSerial = parseFormattedDate(`${dateValue}`).v;
|
|
861
916
|
else if (parseFormattedTime(`${dateValue}`)) dateSerial = parseFormattedTime(`${dateValue}`).v;
|
|
917
|
+
else if (parseEnglishMonthNameDate(`${dateValue}`)) dateSerial = parseEnglishMonthNameDate(`${dateValue}`);
|
|
862
918
|
else if ((0, _univerjs_core.isRealNum)(dateValue)) dateSerial = +dateValue;
|
|
863
919
|
else return ErrorValueObject.create("#VALUE!");
|
|
864
920
|
if (dateSerial instanceof Date) dateSerial = excelDateTimeSerial(dateSerial);
|
|
@@ -906,10 +962,11 @@ function getDaysByNASD(startDateSerialNumber, endDateSerialNumber) {
|
|
|
906
962
|
let endYear = endDateSerialNumber > 0 ? endDateDate.getUTCFullYear() : 1900;
|
|
907
963
|
let endMonth = endDateSerialNumber > 0 ? endDateDate.getUTCMonth() + 1 : 1;
|
|
908
964
|
let endDay = endDateSerialNumber > 0 ? endDateDate.getUTCDate() : 0;
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
if (endDay ===
|
|
965
|
+
const startIsLastDayOfFebruary = startMonth === 2 && startDay === getDaysInMonth(startYear, startMonth - 1);
|
|
966
|
+
if (startIsLastDayOfFebruary) startDay = 30;
|
|
967
|
+
else if (startDay === 31) startDay = 30;
|
|
968
|
+
if (endMonth === 2 && endDay === getDaysInMonth(endYear, endMonth - 1) && startIsLastDayOfFebruary) endDay = 30;
|
|
969
|
+
else if (endDay === 31) if (startDay < 30) {
|
|
913
970
|
endDateDate = excelSerialToDate(endDateSerialNumber + 1);
|
|
914
971
|
endYear = endDateDate.getUTCFullYear();
|
|
915
972
|
endMonth = endDateDate.getUTCMonth() + 1;
|
|
@@ -1196,16 +1253,19 @@ var InvertedIndexCache = class {
|
|
|
1196
1253
|
};
|
|
1197
1254
|
const _value = normalizeValue(value);
|
|
1198
1255
|
if (ERROR_TYPE_SET.has(_value)) result.errorType = _value;
|
|
1199
|
-
else if (_value === 0
|
|
1256
|
+
else if (_value === 0) {
|
|
1200
1257
|
const rows = [];
|
|
1201
1258
|
const rowsForZero = columnMap.get(0);
|
|
1202
1259
|
if (rowsForZero) rows.push(...rowsForZero);
|
|
1203
1260
|
const rowsForEmpty = columnMap.get(DEFAULT_EMPTY_CELL_KEY);
|
|
1204
1261
|
if (rowsForEmpty) rows.push(...rowsForEmpty);
|
|
1205
1262
|
result.matchingRows = rows.filter((row) => rowsInCache.some(([start, end]) => row >= start && row <= end));
|
|
1206
|
-
} else {
|
|
1263
|
+
} else if (_value === DEFAULT_EMPTY_CELL_KEY) {
|
|
1207
1264
|
var _columnMap$get;
|
|
1208
|
-
result.matchingRows = Array.from((_columnMap$get = columnMap.get(
|
|
1265
|
+
result.matchingRows = Array.from((_columnMap$get = columnMap.get(DEFAULT_EMPTY_CELL_KEY)) !== null && _columnMap$get !== void 0 ? _columnMap$get : []).filter((row) => rowsInCache.some(([start, end]) => row >= start && row <= end));
|
|
1266
|
+
} else {
|
|
1267
|
+
var _columnMap$get2;
|
|
1268
|
+
result.matchingRows = Array.from((_columnMap$get2 = columnMap.get(_value)) !== null && _columnMap$get2 !== void 0 ? _columnMap$get2 : []).filter((row) => rowsInCache.some(([start, end]) => row >= start && row <= end));
|
|
1209
1269
|
}
|
|
1210
1270
|
return result;
|
|
1211
1271
|
}
|
|
@@ -1421,12 +1481,13 @@ const REFERENCE_REGEX_SINGLE_COLUMN = `^${UNIT_NAME_SHEET_NAME_REGEX}\\s*?\\${"$
|
|
|
1421
1481
|
const REFERENCE_REGEX_SINGLE_COLUMN_PRECOMPILING = new RegExp(REFERENCE_REGEX_SINGLE_COLUMN);
|
|
1422
1482
|
const TABLE_NAME_REGEX = "((?![~!@#$%^&*()_+<>?:,./;’,。、‘:“《》?~!@#¥%……()【】\\[\\]\\/\\\\]).)+";
|
|
1423
1483
|
const TABLE_TITLE_REGEX = "\\[#.+\\]\\s*?,\\s*?";
|
|
1424
|
-
const TABLE_CONTENT_REGEX = "\\[((?<!#)
|
|
1484
|
+
const TABLE_CONTENT_REGEX = "\\[((?<!#)[\\s\\S])*\\]";
|
|
1425
1485
|
const TABLE_MULTIPLE_COLUMN_REGEX = `${TABLE_CONTENT_REGEX}${RANGE_SYMBOL}${TABLE_CONTENT_REGEX}`;
|
|
1426
|
-
const
|
|
1427
|
-
const
|
|
1428
|
-
const
|
|
1429
|
-
const
|
|
1486
|
+
const TABLE_UNIT_QUALIFIER_REGEX = `(?:(?:${UNIT_NAME_REGEX}|'(?:[^']|'')+'|[^\\s!\\[\\]]+)!)?(?:${UNIT_NAME_REGEX})?`;
|
|
1487
|
+
const REFERENCE_TABLE_ALL_COLUMN_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}$`;
|
|
1488
|
+
const REFERENCE_TABLE_SINGLE_COLUMN_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}(${TABLE_CONTENT_REGEX}|\\[${TABLE_TITLE_REGEX}${TABLE_CONTENT_REGEX}\\])+$`;
|
|
1489
|
+
const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}(\\[${TABLE_MULTIPLE_COLUMN_REGEX}\\])?$|^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}(\\[${TABLE_TITLE_REGEX}${TABLE_MULTIPLE_COLUMN_REGEX}\\])?$`;
|
|
1490
|
+
const REFERENCE_TABLE_TITLE_ONLY_ANY_HASH_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}\\[\\s*#([^\\]]+)\\s*\\]$`;
|
|
1430
1491
|
const REFERENCE_TABLE_ALL_COLUMN_REGEX_PRECOMPILING = new RegExp(REFERENCE_TABLE_ALL_COLUMN_REGEX);
|
|
1431
1492
|
const REFERENCE_TABLE_SINGLE_COLUMN_REGEX_PRECOMPILING = new RegExp(REFERENCE_TABLE_SINGLE_COLUMN_REGEX);
|
|
1432
1493
|
const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX_PRECOMPILING = new RegExp(REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX);
|
|
@@ -1677,10 +1738,10 @@ function singleReferenceToGrid(refBody) {
|
|
|
1677
1738
|
}
|
|
1678
1739
|
function handleRefStringInfo(refString) {
|
|
1679
1740
|
const unitIdMatch = UNIT_NAME_REGEX_PRECOMPILING.exec(refString);
|
|
1680
|
-
let
|
|
1741
|
+
let unitQualifier = "";
|
|
1681
1742
|
if (unitIdMatch != null) {
|
|
1682
|
-
|
|
1683
|
-
|
|
1743
|
+
unitQualifier = unitIdMatch[0].trim();
|
|
1744
|
+
unitQualifier = unquoteSheetName(unitQualifier.slice(1, unitQualifier.length - 1));
|
|
1684
1745
|
refString = refString.replace(UNIT_NAME_REGEX_PRECOMPILING, "");
|
|
1685
1746
|
}
|
|
1686
1747
|
const sheetNameIndex = refString.indexOf("!");
|
|
@@ -1695,11 +1756,13 @@ function handleRefStringInfo(refString) {
|
|
|
1695
1756
|
return {
|
|
1696
1757
|
refBody,
|
|
1697
1758
|
sheetName,
|
|
1698
|
-
|
|
1759
|
+
unitQualifier,
|
|
1760
|
+
/** @deprecated Use unitQualifier. Kept for reference-grid compatibility. */
|
|
1761
|
+
unitId: unitQualifier
|
|
1699
1762
|
};
|
|
1700
1763
|
}
|
|
1701
1764
|
function deserializeRangeWithSheet(refString) {
|
|
1702
|
-
const { refBody, sheetName,
|
|
1765
|
+
const { refBody, sheetName, unitQualifier } = handleRefStringInfo(refString);
|
|
1703
1766
|
const colonIndex = refBody.indexOf(":");
|
|
1704
1767
|
if (colonIndex === -1) {
|
|
1705
1768
|
const grid = singleReferenceToGrid(refBody);
|
|
@@ -1707,7 +1770,7 @@ function deserializeRangeWithSheet(refString) {
|
|
|
1707
1770
|
const column = grid.column;
|
|
1708
1771
|
const absoluteRefType = grid.absoluteRefType;
|
|
1709
1772
|
return {
|
|
1710
|
-
unitId,
|
|
1773
|
+
unitId: unitQualifier,
|
|
1711
1774
|
sheetName,
|
|
1712
1775
|
range: {
|
|
1713
1776
|
startRow: row,
|
|
@@ -1731,7 +1794,7 @@ function deserializeRangeWithSheet(refString) {
|
|
|
1731
1794
|
if (Number.isNaN(startRow) && Number.isNaN(endRow)) rangeType = _univerjs_core.RANGE_TYPE.COLUMN;
|
|
1732
1795
|
else if (Number.isNaN(startColumn) && Number.isNaN(endColumn)) rangeType = _univerjs_core.RANGE_TYPE.ROW;
|
|
1733
1796
|
return {
|
|
1734
|
-
unitId,
|
|
1797
|
+
unitId: unitQualifier,
|
|
1735
1798
|
sheetName,
|
|
1736
1799
|
range: {
|
|
1737
1800
|
startRow,
|
|
@@ -1865,14 +1928,49 @@ function startsWithNonAlphabetic(name) {
|
|
|
1865
1928
|
return !/^\p{Letter}/u.test(name.charAt(0));
|
|
1866
1929
|
}
|
|
1867
1930
|
function splitTableStructuredRef(ref) {
|
|
1868
|
-
|
|
1931
|
+
let unitQualifier = "";
|
|
1932
|
+
let tableRef = ref.trim();
|
|
1933
|
+
let quoteOpen = false;
|
|
1934
|
+
let bracketDepth = 0;
|
|
1935
|
+
let qualifierEnd = -1;
|
|
1936
|
+
for (let i = 0; i < tableRef.length; i++) {
|
|
1937
|
+
const char = tableRef[i];
|
|
1938
|
+
if (char === "'") {
|
|
1939
|
+
if (quoteOpen && tableRef[i + 1] === "'") {
|
|
1940
|
+
i++;
|
|
1941
|
+
continue;
|
|
1942
|
+
}
|
|
1943
|
+
quoteOpen = !quoteOpen;
|
|
1944
|
+
} else if (!quoteOpen && char === "[") bracketDepth++;
|
|
1945
|
+
else if (!quoteOpen && char === "]") bracketDepth--;
|
|
1946
|
+
else if (!quoteOpen && bracketDepth === 0 && char === "!") {
|
|
1947
|
+
qualifierEnd = i;
|
|
1948
|
+
break;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
if (qualifierEnd >= 0) {
|
|
1952
|
+
unitQualifier = tableRef.slice(0, qualifierEnd).trim();
|
|
1953
|
+
tableRef = tableRef.slice(qualifierEnd + 1);
|
|
1954
|
+
if (unitQualifier.startsWith("'") && unitQualifier.endsWith("'")) unitQualifier = unitQualifier.slice(1, -1);
|
|
1955
|
+
if (unitQualifier.startsWith("[") && unitQualifier.endsWith("]")) unitQualifier = unitQualifier.slice(1, -1);
|
|
1956
|
+
unitQualifier = unquoteSheetName(unitQualifier);
|
|
1957
|
+
} else if (tableRef.startsWith("[")) {
|
|
1958
|
+
const legacyQualifierEnd = tableRef.indexOf("]");
|
|
1959
|
+
if (legacyQualifierEnd > 0) {
|
|
1960
|
+
unitQualifier = unquoteSheetName(tableRef.slice(1, legacyQualifierEnd));
|
|
1961
|
+
tableRef = tableRef.slice(legacyQualifierEnd + 1);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
const idx = tableRef.indexOf("[");
|
|
1869
1965
|
if (idx === -1) return {
|
|
1870
|
-
|
|
1871
|
-
|
|
1966
|
+
unitQualifier,
|
|
1967
|
+
tableName: tableRef,
|
|
1968
|
+
columnStruct: ""
|
|
1872
1969
|
};
|
|
1873
1970
|
return {
|
|
1874
|
-
|
|
1875
|
-
|
|
1971
|
+
unitQualifier,
|
|
1972
|
+
tableName: tableRef.slice(0, idx),
|
|
1973
|
+
columnStruct: tableRef.slice(idx)
|
|
1876
1974
|
};
|
|
1877
1975
|
}
|
|
1878
1976
|
|
|
@@ -2000,16 +2098,38 @@ let DefinedNamesService = class DefinedNamesService extends _univerjs_core.Dispo
|
|
|
2000
2098
|
getDefinedNameMap(unitId) {
|
|
2001
2099
|
return this._definedNameMap[unitId];
|
|
2002
2100
|
}
|
|
2003
|
-
getValueByName(unitId, name) {
|
|
2004
|
-
const cachedMap = this._nameCacheMap[unitId];
|
|
2005
|
-
if (cachedMap) return cachedMap[name.toLowerCase()] || null;
|
|
2101
|
+
getValueByName(unitId, name, sheetId) {
|
|
2006
2102
|
const nameMap = this._definedNameMap[unitId];
|
|
2007
2103
|
if (nameMap === void 0) return null;
|
|
2104
|
+
if (sheetId) {
|
|
2105
|
+
var _workbookScope;
|
|
2106
|
+
const normalizedName = name.toLowerCase();
|
|
2107
|
+
let workbookScope = null;
|
|
2108
|
+
let firstMatch = null;
|
|
2109
|
+
for (const item of Object.values(nameMap)) {
|
|
2110
|
+
if (item.name.toLowerCase() !== normalizedName) continue;
|
|
2111
|
+
if (firstMatch == null) firstMatch = item;
|
|
2112
|
+
if (item.localSheetId === sheetId) return item;
|
|
2113
|
+
if (item.localSheetId === "AllDefaultWorkbook" || item.localSheetId == null) {
|
|
2114
|
+
if (workbookScope == null) workbookScope = item;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
return (_workbookScope = workbookScope) !== null && _workbookScope !== void 0 ? _workbookScope : firstMatch;
|
|
2118
|
+
}
|
|
2119
|
+
const cachedMap = this._nameCacheMap[unitId];
|
|
2120
|
+
if (cachedMap) return cachedMap[name.toLowerCase()] || null;
|
|
2008
2121
|
let result = null;
|
|
2009
|
-
|
|
2122
|
+
const normalizedName = name.toLowerCase();
|
|
2123
|
+
for (const item of Object.values(nameMap)) if (item.name.toLowerCase() === normalizedName && (item.localSheetId === "AllDefaultWorkbook" || item.localSheetId == null)) {
|
|
2010
2124
|
result = item;
|
|
2011
2125
|
break;
|
|
2012
2126
|
}
|
|
2127
|
+
if (!result) {
|
|
2128
|
+
for (const item of Object.values(nameMap)) if (item.name.toLowerCase() === normalizedName) {
|
|
2129
|
+
result = item;
|
|
2130
|
+
break;
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2013
2133
|
if (result) {
|
|
2014
2134
|
this._nameCacheMap[unitId] = this._nameCacheMap[unitId] || {};
|
|
2015
2135
|
this._nameCacheMap[unitId][name.toLowerCase()] = result;
|
|
@@ -2044,7 +2164,10 @@ let DefinedNamesService = class DefinedNamesService extends _univerjs_core.Dispo
|
|
|
2044
2164
|
return;
|
|
2045
2165
|
}
|
|
2046
2166
|
this._nameCacheMap[unitId] = {};
|
|
2047
|
-
for (const item of Object.values(nameMap))
|
|
2167
|
+
for (const item of Object.values(nameMap)) {
|
|
2168
|
+
const normalizedName = item.name.toLowerCase();
|
|
2169
|
+
if (item.localSheetId === "AllDefaultWorkbook" || item.localSheetId == null || this._nameCacheMap[unitId][normalizedName] == null) this._nameCacheMap[unitId][normalizedName] = item;
|
|
2170
|
+
}
|
|
2048
2171
|
}
|
|
2049
2172
|
_isDeepDefinedNameMapEmpty() {
|
|
2050
2173
|
for (const unitId in this._definedNameMap) if (this.hasDefinedName(unitId)) return false;
|
|
@@ -2617,6 +2740,7 @@ let FUNCTION_NAMES_LOGICAL = /* @__PURE__ */ function(FUNCTION_NAMES_LOGICAL) {
|
|
|
2617
2740
|
FUNCTION_NAMES_LOGICAL["BYCOL"] = "BYCOL";
|
|
2618
2741
|
FUNCTION_NAMES_LOGICAL["BYROW"] = "BYROW";
|
|
2619
2742
|
FUNCTION_NAMES_LOGICAL["FALSE"] = "FALSE";
|
|
2743
|
+
FUNCTION_NAMES_LOGICAL["GROUPBY"] = "GROUPBY";
|
|
2620
2744
|
FUNCTION_NAMES_LOGICAL["IF"] = "IF";
|
|
2621
2745
|
FUNCTION_NAMES_LOGICAL["IFERROR"] = "IFERROR";
|
|
2622
2746
|
FUNCTION_NAMES_LOGICAL["IFNA"] = "IFNA";
|
|
@@ -2627,6 +2751,7 @@ let FUNCTION_NAMES_LOGICAL = /* @__PURE__ */ function(FUNCTION_NAMES_LOGICAL) {
|
|
|
2627
2751
|
FUNCTION_NAMES_LOGICAL["MAP"] = "MAP";
|
|
2628
2752
|
FUNCTION_NAMES_LOGICAL["NOT"] = "NOT";
|
|
2629
2753
|
FUNCTION_NAMES_LOGICAL["OR"] = "OR";
|
|
2754
|
+
FUNCTION_NAMES_LOGICAL["PERCENTOF"] = "PERCENTOF";
|
|
2630
2755
|
FUNCTION_NAMES_LOGICAL["REDUCE"] = "REDUCE";
|
|
2631
2756
|
FUNCTION_NAMES_LOGICAL["SCAN"] = "SCAN";
|
|
2632
2757
|
FUNCTION_NAMES_LOGICAL["SWITCH"] = "SWITCH";
|
|
@@ -2654,6 +2779,7 @@ let FUNCTION_NAMES_LOGICAL = /* @__PURE__ */ function(FUNCTION_NAMES_LOGICAL) {
|
|
|
2654
2779
|
*/
|
|
2655
2780
|
let FUNCTION_NAMES_LOOKUP = /* @__PURE__ */ function(FUNCTION_NAMES_LOOKUP) {
|
|
2656
2781
|
FUNCTION_NAMES_LOOKUP["ADDRESS"] = "ADDRESS";
|
|
2782
|
+
FUNCTION_NAMES_LOOKUP["ANCHORARRAY"] = "ANCHORARRAY";
|
|
2657
2783
|
FUNCTION_NAMES_LOOKUP["AREAS"] = "AREAS";
|
|
2658
2784
|
FUNCTION_NAMES_LOOKUP["CHOOSE"] = "CHOOSE";
|
|
2659
2785
|
FUNCTION_NAMES_LOOKUP["CHOOSECOLS"] = "CHOOSECOLS";
|
|
@@ -2976,6 +3102,7 @@ let FUNCTION_NAMES_TEXT = /* @__PURE__ */ function(FUNCTION_NAMES_TEXT) {
|
|
|
2976
3102
|
FUNCTION_NAMES_TEXT["PROPER"] = "PROPER";
|
|
2977
3103
|
FUNCTION_NAMES_TEXT["REGEXEXTRACT"] = "REGEXEXTRACT";
|
|
2978
3104
|
FUNCTION_NAMES_TEXT["REGEXMATCH"] = "REGEXMATCH";
|
|
3105
|
+
FUNCTION_NAMES_TEXT["REGEXTEST"] = "REGEXTEST";
|
|
2979
3106
|
FUNCTION_NAMES_TEXT["REGEXREPLACE"] = "REGEXREPLACE";
|
|
2980
3107
|
FUNCTION_NAMES_TEXT["REPLACE"] = "REPLACE";
|
|
2981
3108
|
FUNCTION_NAMES_TEXT["REPLACEB"] = "REPLACEB";
|
|
@@ -3087,6 +3214,7 @@ const NEW_EXCEL_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
|
3087
3214
|
"SHEETS",
|
|
3088
3215
|
"IFNA",
|
|
3089
3216
|
"IFS",
|
|
3217
|
+
"GROUPBY",
|
|
3090
3218
|
"SWITCH",
|
|
3091
3219
|
"XOR",
|
|
3092
3220
|
"BETA.DIST",
|
|
@@ -3181,7 +3309,7 @@ function deserializeRangeWithSheetWithCache(refString) {
|
|
|
3181
3309
|
if (refCache) return refCache;
|
|
3182
3310
|
const result = deserializeRangeWithSheet(refString);
|
|
3183
3311
|
referenceToRangeCache.set(refString, result);
|
|
3184
|
-
return
|
|
3312
|
+
return result;
|
|
3185
3313
|
}
|
|
3186
3314
|
function clearReferenceToRangeCache() {
|
|
3187
3315
|
referenceToRangeCache.clear();
|
|
@@ -3740,7 +3868,7 @@ var LexerTreeBuilder = class extends _univerjs_core.Disposable {
|
|
|
3740
3868
|
return this._currentLexerNode;
|
|
3741
3869
|
}
|
|
3742
3870
|
_handleDefinedName(sequenceArray, param) {
|
|
3743
|
-
const { unitId, getValueByName, getSheetName } = param;
|
|
3871
|
+
const { unitId, sheetId, getValueByName, getSheetName } = param;
|
|
3744
3872
|
if (unitId == null) return {
|
|
3745
3873
|
sequenceString: "",
|
|
3746
3874
|
hasDefinedName: false,
|
|
@@ -3760,14 +3888,15 @@ var LexerTreeBuilder = class extends _univerjs_core.Disposable {
|
|
|
3760
3888
|
let token = tokenRaw;
|
|
3761
3889
|
if (nodeType === 4 || nodeType === 3) {
|
|
3762
3890
|
if (nodeType === 3) token = this._getHasSheetNameDefinedName(tokenRaw, unitId, param);
|
|
3763
|
-
const
|
|
3891
|
+
const definedNameToken = token.trim();
|
|
3892
|
+
const definedContent = getValueByName(unitId, definedNameToken, sheetId);
|
|
3764
3893
|
if (definedContent) {
|
|
3765
3894
|
const refString = definedContent.formulaOrRefString;
|
|
3766
3895
|
const nestedDefinedNameParam = this._handleNestedDefinedName(refString, param);
|
|
3767
3896
|
if (nestedDefinedNameParam == null || typeof nestedDefinedNameParam !== "object") {
|
|
3768
3897
|
sequenceString += nestedDefinedNameParam || "#NAME?";
|
|
3769
3898
|
hasDefinedName = true;
|
|
3770
|
-
definedNames.push(
|
|
3899
|
+
definedNames.push(definedNameToken);
|
|
3771
3900
|
} else if (typeof nestedDefinedNameParam === "object") {
|
|
3772
3901
|
const { sequenceString: nestedSequenceString, definedNames: nestedDefinedNames } = nestedDefinedNameParam;
|
|
3773
3902
|
sequenceString += nestedSequenceString;
|
|
@@ -3776,10 +3905,10 @@ var LexerTreeBuilder = class extends _univerjs_core.Disposable {
|
|
|
3776
3905
|
});
|
|
3777
3906
|
hasDefinedName = true;
|
|
3778
3907
|
}
|
|
3779
|
-
} else if (this._checkDefinedNameDirty(
|
|
3908
|
+
} else if (this._checkDefinedNameDirty(definedNameToken, param)) {
|
|
3780
3909
|
sequenceString += "#NAME?";
|
|
3781
3910
|
hasDefinedName = true;
|
|
3782
|
-
definedNames.push(
|
|
3911
|
+
definedNames.push(definedNameToken);
|
|
3783
3912
|
} else sequenceString += token;
|
|
3784
3913
|
} else sequenceString += token;
|
|
3785
3914
|
}
|
|
@@ -4193,7 +4322,7 @@ var LexerTreeBuilder = class extends _univerjs_core.Disposable {
|
|
|
4193
4322
|
}
|
|
4194
4323
|
}
|
|
4195
4324
|
_nodeMaker(formulaStringRaw, sequenceArray, matchCurrentNodeIndex) {
|
|
4196
|
-
let formulaString = formulaStringRaw.replace(
|
|
4325
|
+
let formulaString = formulaStringRaw.replace(/(?:\r\n|\r|\n)$/g, " ");
|
|
4197
4326
|
if (formulaString.substring(0, 1) === "=") formulaString = formulaString.substring(1);
|
|
4198
4327
|
const formulaChars = formulaString.split("");
|
|
4199
4328
|
const charsCount = formulaChars.length;
|
|
@@ -4947,7 +5076,9 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
4947
5076
|
for (let j = 0; j < worksheets.length; j++) {
|
|
4948
5077
|
const worksheet = worksheets[j];
|
|
4949
5078
|
const cellMatrix = worksheet.getCellMatrix();
|
|
4950
|
-
|
|
5079
|
+
const sheetId = worksheet.getSheetId();
|
|
5080
|
+
this._initSheetArrayFormulaData(unitId, sheetId, cellMatrix);
|
|
5081
|
+
initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix);
|
|
4951
5082
|
}
|
|
4952
5083
|
}
|
|
4953
5084
|
const allBases = this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_BASE);
|
|
@@ -4959,7 +5090,6 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
4959
5090
|
const tables = Object.values(snapshot.tables);
|
|
4960
5091
|
for (let j = 0; j < tables.length; j++) {
|
|
4961
5092
|
const table = tables[j];
|
|
4962
|
-
if (table.deleted) continue;
|
|
4963
5093
|
const tableFormulaData = {};
|
|
4964
5094
|
const recordOrder = table.recordOrder;
|
|
4965
5095
|
if (!recordOrder) {
|
|
@@ -4968,13 +5098,12 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
4968
5098
|
}
|
|
4969
5099
|
for (let row = 0; row < recordOrder.length; row++) {
|
|
4970
5100
|
const recordId = recordOrder[row];
|
|
4971
|
-
|
|
4972
|
-
if (!record || record.deleted) continue;
|
|
5101
|
+
if (!table.records[recordId]) continue;
|
|
4973
5102
|
for (let col = 0; col < table.fieldOrder.length; col++) {
|
|
4974
5103
|
var _field$config$formula, _field$config, _row, _tableFormulaData$_ro;
|
|
4975
5104
|
const fieldId = table.fieldOrder[col];
|
|
4976
5105
|
const field = table.fields[fieldId];
|
|
4977
|
-
if (!field || field.
|
|
5106
|
+
if (!field || field.type !== "formula") continue;
|
|
4978
5107
|
const formula = String((_field$config$formula = (_field$config = field.config) === null || _field$config === void 0 ? void 0 : _field$config.formula) !== null && _field$config$formula !== void 0 ? _field$config$formula : "").trim();
|
|
4979
5108
|
if (!formula) continue;
|
|
4980
5109
|
(_tableFormulaData$_ro = tableFormulaData[_row = row]) !== null && _tableFormulaData$_ro !== void 0 || (tableFormulaData[_row] = {});
|
|
@@ -4996,7 +5125,9 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
4996
5125
|
formulaData[unitId] = {};
|
|
4997
5126
|
const worksheet = workbook.getSheetBySheetId(sheetId);
|
|
4998
5127
|
if (worksheet == null) return {};
|
|
4999
|
-
|
|
5128
|
+
const cellMatrix = worksheet.getCellMatrix();
|
|
5129
|
+
this._initSheetArrayFormulaData(unitId, sheetId, cellMatrix);
|
|
5130
|
+
initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix);
|
|
5000
5131
|
return formulaData[unitId][sheetId];
|
|
5001
5132
|
}
|
|
5002
5133
|
getArrayFormulaRange() {
|
|
@@ -5067,8 +5198,13 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
5067
5198
|
const allUnitData = {};
|
|
5068
5199
|
const unitStylesData = {};
|
|
5069
5200
|
const unitSheetNameMap = {};
|
|
5201
|
+
const unitNameMap = {};
|
|
5070
5202
|
for (const workbook of unitAllSheet) {
|
|
5071
5203
|
const unitId = workbook.getUnitId();
|
|
5204
|
+
unitNameMap[unitId] = {
|
|
5205
|
+
name: workbook.name,
|
|
5206
|
+
unitType: _univerjs_core.UniverInstanceType.UNIVER_SHEET
|
|
5207
|
+
};
|
|
5072
5208
|
const sheets = workbook.getSheets();
|
|
5073
5209
|
const sheetData = {};
|
|
5074
5210
|
const sheetNameMap = {};
|
|
@@ -5094,20 +5230,18 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
5094
5230
|
for (const base of unitAllBases) {
|
|
5095
5231
|
const snapshot = base.getSnapshot();
|
|
5096
5232
|
const unitId = base.getUnitId();
|
|
5233
|
+
unitNameMap[unitId] = {
|
|
5234
|
+
name: snapshot.name,
|
|
5235
|
+
unitType: _univerjs_core.UniverInstanceType.UNIVER_BASE
|
|
5236
|
+
};
|
|
5097
5237
|
const baseData = {};
|
|
5098
5238
|
const tableNameMap = {};
|
|
5099
|
-
for (const table of Object.values(snapshot.tables)
|
|
5100
|
-
var _table$recordOrder$
|
|
5239
|
+
for (const table of Object.values(snapshot.tables)) {
|
|
5240
|
+
var _table$recordOrder$le, _table$recordOrder;
|
|
5101
5241
|
baseData[table.id] = {
|
|
5102
5242
|
cellData: new _univerjs_core.ObjectMatrix(buildBaseRuntimeCellData(table)),
|
|
5103
|
-
rowCount: (_table$recordOrder$
|
|
5104
|
-
|
|
5105
|
-
return !((_table$records$record = table.records[recordId]) === null || _table$records$record === void 0 ? void 0 : _table$records$record.deleted);
|
|
5106
|
-
}).length) !== null && _table$recordOrder$fi !== void 0 ? _table$recordOrder$fi : 0,
|
|
5107
|
-
columnCount: table.fieldOrder.filter((fieldId) => {
|
|
5108
|
-
var _table$fields$fieldId;
|
|
5109
|
-
return !((_table$fields$fieldId = table.fields[fieldId]) === null || _table$fields$fieldId === void 0 ? void 0 : _table$fields$fieldId.deleted);
|
|
5110
|
-
}).length,
|
|
5243
|
+
rowCount: (_table$recordOrder$le = (_table$recordOrder = table.recordOrder) === null || _table$recordOrder === void 0 ? void 0 : _table$recordOrder.length) !== null && _table$recordOrder$le !== void 0 ? _table$recordOrder$le : 0,
|
|
5244
|
+
columnCount: table.fieldOrder.length,
|
|
5111
5245
|
rowData: {},
|
|
5112
5246
|
columnData: {}
|
|
5113
5247
|
};
|
|
@@ -5120,7 +5254,8 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
5120
5254
|
return {
|
|
5121
5255
|
allUnitData,
|
|
5122
5256
|
unitStylesData,
|
|
5123
|
-
unitSheetNameMap
|
|
5257
|
+
unitSheetNameMap,
|
|
5258
|
+
unitNameMap
|
|
5124
5259
|
};
|
|
5125
5260
|
}
|
|
5126
5261
|
/**
|
|
@@ -5148,18 +5283,51 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
5148
5283
|
return rowData;
|
|
5149
5284
|
}
|
|
5150
5285
|
updateFormulaData(unitId, sheetId, cellValue) {
|
|
5286
|
+
var _this$_univerInstance, _formulaData$unitId$s, _formulaData$unitId;
|
|
5151
5287
|
const cellMatrix = new _univerjs_core.ObjectMatrix(cellValue);
|
|
5152
|
-
const formulaIdMap = this._getSheetFormulaIdMap(unitId, sheetId);
|
|
5153
|
-
const deleteFormulaIdMap = /* @__PURE__ */ new Map();
|
|
5154
|
-
const formulaData = this.getFormulaData();
|
|
5155
|
-
if (formulaData[unitId] == null) formulaData[unitId] = {};
|
|
5156
|
-
const workbookFormulaData = formulaData[unitId];
|
|
5157
|
-
if (workbookFormulaData[sheetId] == null) workbookFormulaData[sheetId] = {};
|
|
5158
|
-
const sheetFormulaDataMatrix = new _univerjs_core.ObjectMatrix(workbookFormulaData[sheetId] || {});
|
|
5159
5288
|
const newSheetFormulaDataMatrix = new _univerjs_core.ObjectMatrix();
|
|
5289
|
+
const worksheetCellMatrix = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getSheetBySheetId(sheetId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getCellMatrix();
|
|
5290
|
+
const affectedFormulaIds = /* @__PURE__ */ new Set();
|
|
5291
|
+
cellMatrix.forValue((r, c, cell) => {
|
|
5292
|
+
const currentCell = worksheetCellMatrix === null || worksheetCellMatrix === void 0 ? void 0 : worksheetCellMatrix.getValue(r, c);
|
|
5293
|
+
const currentFormulaId = currentCell === null || currentCell === void 0 ? void 0 : currentCell.si;
|
|
5294
|
+
const formulaId = cell === null || cell === void 0 ? void 0 : cell.si;
|
|
5295
|
+
const hasCurrentFormulaId = (0, _univerjs_core.isFormulaId)(currentFormulaId);
|
|
5296
|
+
const hasFormulaId = (0, _univerjs_core.isFormulaId)(formulaId);
|
|
5297
|
+
const formulaString = cell === null || cell === void 0 ? void 0 : cell.f;
|
|
5298
|
+
if (hasCurrentFormulaId) affectedFormulaIds.add(String(currentFormulaId));
|
|
5299
|
+
if (hasFormulaId) affectedFormulaIds.add(String(formulaId));
|
|
5300
|
+
if (!hasCurrentFormulaId && !hasFormulaId) {
|
|
5301
|
+
if (typeof formulaString === "string" && (0, _univerjs_core.isFormulaString)(formulaString)) newSheetFormulaDataMatrix.setValue(r, c, { f: formulaString });
|
|
5302
|
+
else if ((0, _univerjs_core.isFormulaString)(currentCell === null || currentCell === void 0 ? void 0 : currentCell.f)) newSheetFormulaDataMatrix.setValue(r, c, null);
|
|
5303
|
+
}
|
|
5304
|
+
});
|
|
5305
|
+
if (affectedFormulaIds.size === 0) return newSheetFormulaDataMatrix.getMatrix();
|
|
5306
|
+
const formulaIdMap = {};
|
|
5307
|
+
const sharedFormulaCellMatrix = new _univerjs_core.ObjectMatrix();
|
|
5308
|
+
worksheetCellMatrix === null || worksheetCellMatrix === void 0 || worksheetCellMatrix.forValue((r, c, cell) => {
|
|
5309
|
+
const formulaId = cell === null || cell === void 0 ? void 0 : cell.si;
|
|
5310
|
+
if (!(0, _univerjs_core.isFormulaId)(formulaId) || !affectedFormulaIds.has(String(formulaId))) return;
|
|
5311
|
+
sharedFormulaCellMatrix.setValue(r, c, cell);
|
|
5312
|
+
if (typeof (cell === null || cell === void 0 ? void 0 : cell.f) === "string" && (0, _univerjs_core.isFormulaString)(cell.f)) formulaIdMap[String(formulaId)] = {
|
|
5313
|
+
f: cell.f,
|
|
5314
|
+
r,
|
|
5315
|
+
c
|
|
5316
|
+
};
|
|
5317
|
+
});
|
|
5318
|
+
const formulaData = {};
|
|
5319
|
+
initSheetFormulaData(formulaData, unitId, sheetId, sharedFormulaCellMatrix);
|
|
5320
|
+
const deleteFormulaIdMap = /* @__PURE__ */ new Map();
|
|
5321
|
+
const sheetFormulaDataMatrix = new _univerjs_core.ObjectMatrix((_formulaData$unitId$s = (_formulaData$unitId = formulaData[unitId]) === null || _formulaData$unitId === void 0 ? void 0 : _formulaData$unitId[sheetId]) !== null && _formulaData$unitId$s !== void 0 ? _formulaData$unitId$s : {});
|
|
5160
5322
|
cellMatrix.forValue((r, c, cell) => {
|
|
5323
|
+
var _worksheetCellMatrix$;
|
|
5324
|
+
if (!(0, _univerjs_core.isFormulaId)(worksheetCellMatrix === null || worksheetCellMatrix === void 0 || (_worksheetCellMatrix$ = worksheetCellMatrix.getValue(r, c)) === null || _worksheetCellMatrix$ === void 0 ? void 0 : _worksheetCellMatrix$.si) && !(0, _univerjs_core.isFormulaId)(cell === null || cell === void 0 ? void 0 : cell.si)) return;
|
|
5161
5325
|
updateFormulaDataByCellValue(sheetFormulaDataMatrix, newSheetFormulaDataMatrix, formulaIdMap, deleteFormulaIdMap, r, c, cell);
|
|
5162
5326
|
});
|
|
5327
|
+
this._rebindSharedFormulaData(sheetFormulaDataMatrix, newSheetFormulaDataMatrix, formulaIdMap, deleteFormulaIdMap);
|
|
5328
|
+
return newSheetFormulaDataMatrix.getMatrix();
|
|
5329
|
+
}
|
|
5330
|
+
_rebindSharedFormulaData(sheetFormulaDataMatrix, newSheetFormulaDataMatrix, formulaIdMap, deleteFormulaIdMap) {
|
|
5163
5331
|
sheetFormulaDataMatrix.forValue((r, c, cell) => {
|
|
5164
5332
|
const formulaString = (cell === null || cell === void 0 ? void 0 : cell.f) || "";
|
|
5165
5333
|
const formulaId = (cell === null || cell === void 0 ? void 0 : cell.si) || "";
|
|
@@ -5217,7 +5385,6 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
5217
5385
|
}
|
|
5218
5386
|
}
|
|
5219
5387
|
});
|
|
5220
|
-
return newSheetFormulaDataMatrix.getMatrix();
|
|
5221
5388
|
}
|
|
5222
5389
|
updateArrayFormulaRange(unitId, sheetId, cellValue) {
|
|
5223
5390
|
var _this$_arrayFormulaRa5;
|
|
@@ -5293,7 +5460,7 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
5293
5460
|
for (const unitId in formulaData) {
|
|
5294
5461
|
const workbook = formulaData[unitId];
|
|
5295
5462
|
if (!workbook) continue;
|
|
5296
|
-
const workbookInstance = this._univerInstanceService.getUnit(unitId);
|
|
5463
|
+
const workbookInstance = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
5297
5464
|
if (!workbookInstance) continue;
|
|
5298
5465
|
for (const sheetId in workbook) {
|
|
5299
5466
|
const sheet = workbook[sheetId];
|
|
@@ -5307,7 +5474,7 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
5307
5474
|
const column = Number(columnStr);
|
|
5308
5475
|
const currentCell = sheetInstance.getCellRaw(row, column);
|
|
5309
5476
|
const isFormula = (0, _univerjs_core.isFormulaString)(currentCell === null || currentCell === void 0 ? void 0 : currentCell.f) || (0, _univerjs_core.isFormulaId)(currentCell === null || currentCell === void 0 ? void 0 : currentCell.si);
|
|
5310
|
-
const noValue = (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === void 0 || (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === null
|
|
5477
|
+
const noValue = (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === void 0 || (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === null;
|
|
5311
5478
|
if (!(isFormula && noValue)) continue;
|
|
5312
5479
|
if (!columnRanges[column]) columnRanges[column] = [];
|
|
5313
5480
|
const lastRange = columnRanges[column].slice(-1)[0];
|
|
@@ -5339,22 +5506,38 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
|
|
|
5339
5506
|
}
|
|
5340
5507
|
return dirtyRanges;
|
|
5341
5508
|
}
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5509
|
+
_initSheetArrayFormulaData(unitId, sheetId, cellMatrix) {
|
|
5510
|
+
let arrayFormulaRangeMatrix;
|
|
5511
|
+
let arrayFormulaCellDataMatrix;
|
|
5512
|
+
const formulaIds = /* @__PURE__ */ new Set();
|
|
5513
|
+
cellMatrix.forValue((_, __, cell) => {
|
|
5514
|
+
const formulaId = cell === null || cell === void 0 ? void 0 : cell.si;
|
|
5515
|
+
if ((0, _univerjs_core.isFormulaString)(cell === null || cell === void 0 ? void 0 : cell.f) && (0, _univerjs_core.isFormulaId)(formulaId)) formulaIds.add(String(formulaId));
|
|
5516
|
+
});
|
|
5517
|
+
cellMatrix.forValue((row, column, cell) => {
|
|
5518
|
+
var _arrayFormulaRangeMat, _this$_arrayFormulaRa7, _arrayFormulaCellData, _this$_arrayFormulaCe5;
|
|
5519
|
+
const ref = cell === null || cell === void 0 ? void 0 : cell.ref;
|
|
5520
|
+
const formula = cell === null || cell === void 0 ? void 0 : cell.f;
|
|
5521
|
+
const formulaId = cell === null || cell === void 0 ? void 0 : cell.si;
|
|
5522
|
+
const hasOwnFormula = (0, _univerjs_core.isFormulaString)(formula);
|
|
5523
|
+
const hasSharedFormula = (0, _univerjs_core.isFormulaId)(formulaId) && formulaIds.has(String(formulaId));
|
|
5524
|
+
if (!hasOwnFormula && !hasSharedFormula || typeof ref !== "string" || ref.length === 0) return true;
|
|
5525
|
+
const { range } = deserializeRangeWithSheet(ref);
|
|
5526
|
+
if (!Number.isFinite(range.startRow) || !Number.isFinite(range.startColumn) || !Number.isFinite(range.endRow) || !Number.isFinite(range.endColumn)) return true;
|
|
5527
|
+
if (range.startRow === row && range.endRow === row && range.startColumn === column && range.endColumn === column && !isArrayConstantFormula(formula)) return true;
|
|
5528
|
+
if (!this._arrayFormulaRange[unitId]) this._arrayFormulaRange[unitId] = {};
|
|
5529
|
+
if (!this._arrayFormulaCellData[unitId]) this._arrayFormulaCellData[unitId] = {};
|
|
5530
|
+
(_arrayFormulaRangeMat = arrayFormulaRangeMatrix) !== null && _arrayFormulaRangeMat !== void 0 || (arrayFormulaRangeMatrix = new _univerjs_core.ObjectMatrix((_this$_arrayFormulaRa7 = this._arrayFormulaRange[unitId]) === null || _this$_arrayFormulaRa7 === void 0 ? void 0 : _this$_arrayFormulaRa7[sheetId]));
|
|
5531
|
+
(_arrayFormulaCellData = arrayFormulaCellDataMatrix) !== null && _arrayFormulaCellData !== void 0 || (arrayFormulaCellDataMatrix = new _univerjs_core.ObjectMatrix((_this$_arrayFormulaCe5 = this._arrayFormulaCellData[unitId]) === null || _this$_arrayFormulaCe5 === void 0 ? void 0 : _this$_arrayFormulaCe5[sheetId]));
|
|
5532
|
+
if (arrayFormulaRangeMatrix.getValue(row, column) == null) arrayFormulaRangeMatrix.setValue(row, column, range);
|
|
5533
|
+
for (let r = range.startRow; r <= range.endRow; r++) for (let c = range.startColumn; c <= range.endColumn; c++) {
|
|
5534
|
+
if (arrayFormulaCellDataMatrix.getValue(r, c) != null) continue;
|
|
5535
|
+
const rangeCell = cellMatrix.getValue(r, c);
|
|
5536
|
+
if (rangeCell != null) arrayFormulaCellDataMatrix.setValue(r, c, { ...rangeCell });
|
|
5537
|
+
}
|
|
5356
5538
|
});
|
|
5357
|
-
|
|
5539
|
+
if (arrayFormulaRangeMatrix && this._arrayFormulaRange[unitId]) this._arrayFormulaRange[unitId][sheetId] = arrayFormulaRangeMatrix.getData();
|
|
5540
|
+
if (arrayFormulaCellDataMatrix && this._arrayFormulaCellData[unitId]) this._arrayFormulaCellData[unitId][sheetId] = arrayFormulaCellDataMatrix.getData();
|
|
5358
5541
|
}
|
|
5359
5542
|
};
|
|
5360
5543
|
FormulaDataModel = __decorate([__decorateParam(0, _univerjs_core.IUniverInstanceService), __decorateParam(1, (0, _univerjs_core.Inject)(LexerTreeBuilder))], FormulaDataModel);
|
|
@@ -5390,9 +5573,9 @@ function initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix) {
|
|
|
5390
5573
|
if ((0, _univerjs_core.isFormulaId)(formulaId) && !(0, _univerjs_core.isFormulaString)(formulaString)) {
|
|
5391
5574
|
const formulaInfo = formulaIdMap.get(formulaId);
|
|
5392
5575
|
if (formulaInfo) {
|
|
5393
|
-
const f = formulaInfo.f;
|
|
5394
5576
|
const x = c - formulaInfo.c;
|
|
5395
5577
|
const y = r - formulaInfo.r;
|
|
5578
|
+
const f = formulaInfo.f;
|
|
5396
5579
|
sheetFormulaDataMatrix.setValue(r, c, {
|
|
5397
5580
|
f,
|
|
5398
5581
|
si: formulaId,
|
|
@@ -5408,12 +5591,13 @@ function initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix) {
|
|
|
5408
5591
|
const BASE_LEGACY_FIELD_REF_PATTERN = /\{([^}]+)\}/g;
|
|
5409
5592
|
const BASE_TABLE_FIELD_REF_PATTERN = /\b([A-Z_]\w*)\[([^\]]+)\]/gi;
|
|
5410
5593
|
const BASE_BRACKET_FIELD_REF_PATTERN = /(^|[^A-Za-z0-9_\]\[])\[([^\]]+)\]/g;
|
|
5594
|
+
const BASE_EXTERNAL_A1_REF_PATTERN = /(?:'\[[^\]]+\](?:[^']|'')+'|\[[^\]]+\][^\s'!]+)!\$?[A-Z]{1,3}\$?\d+(?::\$?[A-Z]{1,3}\$?\d+)?/gi;
|
|
5411
5595
|
function normalizeBaseFormulaForEngine(formula, currentTable, snapshot) {
|
|
5412
5596
|
const refs = [];
|
|
5413
5597
|
const hold = (ref) => {
|
|
5414
5598
|
return `__BASE_FORMULA_REF_${refs.push(ref) - 1}__`;
|
|
5415
5599
|
};
|
|
5416
|
-
return formula.replace(BASE_LEGACY_FIELD_REF_PATTERN, (_match, fieldName) => hold(createEngineThisRowRef(currentTable, fieldName, snapshot))).replace(BASE_TABLE_FIELD_REF_PATTERN, (_match, sourceTableName, fieldName) => {
|
|
5600
|
+
return formula.replace(BASE_EXTERNAL_A1_REF_PATTERN, (reference) => hold(reference)).replace(BASE_LEGACY_FIELD_REF_PATTERN, (_match, fieldName) => hold(createEngineThisRowRef(currentTable, fieldName, snapshot))).replace(BASE_TABLE_FIELD_REF_PATTERN, (_match, sourceTableName, fieldName) => {
|
|
5417
5601
|
const targetTable = resolveBaseFormulaTable(sourceTableName, currentTable, snapshot);
|
|
5418
5602
|
return targetTable ? hold(createEngineThisRowRef(targetTable, fieldName, snapshot)) : `${sourceTableName}[${fieldName}]`;
|
|
5419
5603
|
}).replace(BASE_BRACKET_FIELD_REF_PATTERN, (_match, prefix, fieldName) => `${prefix}${hold(createEngineThisRowRef(currentTable, fieldName, snapshot))}`).replace(/__BASE_FORMULA_REF_(\d+)__/g, (_match, index) => {
|
|
@@ -5427,12 +5611,9 @@ function createEngineThisRowRef(table, fieldName, snapshot) {
|
|
|
5427
5611
|
function getEngineBaseTableName(table, snapshot) {
|
|
5428
5612
|
const tables = Object.values(snapshot.tables);
|
|
5429
5613
|
let sameNameCount = 0;
|
|
5430
|
-
for (let i = 0; i < tables.length; i++) {
|
|
5431
|
-
|
|
5432
|
-
if (
|
|
5433
|
-
sameNameCount++;
|
|
5434
|
-
if (sameNameCount > 1) break;
|
|
5435
|
-
}
|
|
5614
|
+
for (let i = 0; i < tables.length; i++) if (tables[i].name === table.name) {
|
|
5615
|
+
sameNameCount++;
|
|
5616
|
+
if (sameNameCount > 1) break;
|
|
5436
5617
|
}
|
|
5437
5618
|
return sameNameCount === 1 ? table.name : table.id;
|
|
5438
5619
|
}
|
|
@@ -5441,14 +5622,14 @@ function buildBaseRuntimeCellData(table) {
|
|
|
5441
5622
|
const fieldOrder = [];
|
|
5442
5623
|
for (let i = 0; i < table.fieldOrder.length; i++) {
|
|
5443
5624
|
const fieldId = table.fieldOrder[i];
|
|
5444
|
-
if (table.fields[fieldId]
|
|
5625
|
+
if (table.fields[fieldId]) fieldOrder.push(fieldId);
|
|
5445
5626
|
}
|
|
5446
5627
|
let recordOrder;
|
|
5447
5628
|
if (table.recordOrder) {
|
|
5448
5629
|
recordOrder = [];
|
|
5449
5630
|
for (let i = 0; i < table.recordOrder.length; i++) {
|
|
5450
5631
|
const recordId = table.recordOrder[i];
|
|
5451
|
-
if (table.records[recordId]
|
|
5632
|
+
if (table.records[recordId]) recordOrder.push(recordId);
|
|
5452
5633
|
}
|
|
5453
5634
|
} else {
|
|
5454
5635
|
var _table$records;
|
|
@@ -5456,7 +5637,7 @@ function buildBaseRuntimeCellData(table) {
|
|
|
5456
5637
|
const records = [];
|
|
5457
5638
|
for (let i = 0; i < allRecords.length; i++) {
|
|
5458
5639
|
const record = allRecords[i];
|
|
5459
|
-
|
|
5640
|
+
records.push(record);
|
|
5460
5641
|
}
|
|
5461
5642
|
records.sort((a, b) => a.orderKey.localeCompare(b.orderKey));
|
|
5462
5643
|
recordOrder = [];
|
|
@@ -5468,7 +5649,7 @@ function buildBaseRuntimeCellData(table) {
|
|
|
5468
5649
|
for (let row = 0; row < recordOrder.length; row++) {
|
|
5469
5650
|
const recordId = recordOrder[row];
|
|
5470
5651
|
const record = table.records[recordId];
|
|
5471
|
-
if (!record
|
|
5652
|
+
if (!record) continue;
|
|
5472
5653
|
cellData[row] = { ...cellData[row] };
|
|
5473
5654
|
for (let col = 0; col < fieldOrder.length; col++) {
|
|
5474
5655
|
var _record$values;
|
|
@@ -5520,14 +5701,17 @@ function inferBaseRuntimeCellType(value) {
|
|
|
5520
5701
|
if (typeof value === "string") return _univerjs_core.CellValueType.STRING;
|
|
5521
5702
|
return null;
|
|
5522
5703
|
}
|
|
5704
|
+
function isArrayConstantFormula(formula) {
|
|
5705
|
+
return typeof formula === "string" && /^=\s*\{/.test(formula);
|
|
5706
|
+
}
|
|
5523
5707
|
function isBaseCellData(value) {
|
|
5524
5708
|
return !!value && typeof value === "object" && (Object.prototype.hasOwnProperty.call(value, "v") || Object.prototype.hasOwnProperty.call(value, "t") || Object.prototype.hasOwnProperty.call(value, "p") || Object.prototype.hasOwnProperty.call(value, "f") || Object.prototype.hasOwnProperty.call(value, "si"));
|
|
5525
5709
|
}
|
|
5526
5710
|
function resolveBaseFormulaTable(tableName, currentTable, snapshot) {
|
|
5527
5711
|
if (!tableName || tableName === "table" || tableName === currentTable.id || tableName === currentTable.name) return currentTable;
|
|
5528
5712
|
const byId = snapshot.tables[tableName];
|
|
5529
|
-
if (byId
|
|
5530
|
-
const matches = Object.values(snapshot.tables).filter((table) =>
|
|
5713
|
+
if (byId) return byId;
|
|
5714
|
+
const matches = Object.values(snapshot.tables).filter((table) => table.name === tableName);
|
|
5531
5715
|
return matches.length === 1 ? matches[0] : void 0;
|
|
5532
5716
|
}
|
|
5533
5717
|
|
|
@@ -5579,6 +5763,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
|
|
|
5579
5763
|
_defineProperty(this, "_arrayFormulaRange", {});
|
|
5580
5764
|
_defineProperty(this, "_formulaData", {});
|
|
5581
5765
|
_defineProperty(this, "_sheetNameMap", {});
|
|
5766
|
+
_defineProperty(this, "_unitNameMap", {});
|
|
5582
5767
|
_defineProperty(this, "_forceCalculate", false);
|
|
5583
5768
|
_defineProperty(this, "_clearDependencyTreeCache", {});
|
|
5584
5769
|
_defineProperty(this, "_dirtyRanges", []);
|
|
@@ -5600,6 +5785,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
|
|
|
5600
5785
|
this._arrayFormulaRange = {};
|
|
5601
5786
|
this._formulaData = {};
|
|
5602
5787
|
this._sheetNameMap = {};
|
|
5788
|
+
this._unitNameMap = {};
|
|
5603
5789
|
this._clearDependencyTreeCache = {};
|
|
5604
5790
|
this._dirtyRanges = [];
|
|
5605
5791
|
this._dirtyNameMap = {};
|
|
@@ -5643,6 +5829,9 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
|
|
|
5643
5829
|
getSheetNameMap() {
|
|
5644
5830
|
return this._sheetNameMap;
|
|
5645
5831
|
}
|
|
5832
|
+
getUnitNameMap() {
|
|
5833
|
+
return this._unitNameMap;
|
|
5834
|
+
}
|
|
5646
5835
|
isForceCalculate() {
|
|
5647
5836
|
return this._forceCalculate;
|
|
5648
5837
|
}
|
|
@@ -5708,11 +5897,13 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
|
|
|
5708
5897
|
this._unitData = config.allUnitData;
|
|
5709
5898
|
this._unitStylesData = config.unitStylesData;
|
|
5710
5899
|
this._sheetNameMap = config.unitSheetNameMap;
|
|
5900
|
+
this._unitNameMap = config.unitNameMap || {};
|
|
5711
5901
|
} else {
|
|
5712
|
-
const { allUnitData, unitSheetNameMap, unitStylesData } = this._loadSheetData();
|
|
5902
|
+
const { allUnitData, unitNameMap, unitSheetNameMap, unitStylesData } = this._loadSheetData();
|
|
5713
5903
|
this._unitData = allUnitData;
|
|
5714
5904
|
this._unitStylesData = unitStylesData;
|
|
5715
5905
|
this._sheetNameMap = unitSheetNameMap;
|
|
5906
|
+
this._unitNameMap = unitNameMap;
|
|
5716
5907
|
}
|
|
5717
5908
|
if (config.rowData) this._applyUnitRowData(config.rowData);
|
|
5718
5909
|
this._formulaData = config.formulaData;
|
|
@@ -5730,10 +5921,11 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
|
|
|
5730
5921
|
this._mergeNameMap(this._sheetNameMap, this._dirtyNameMap);
|
|
5731
5922
|
}
|
|
5732
5923
|
loadDataLite(rowData) {
|
|
5733
|
-
const { allUnitData, unitSheetNameMap, unitStylesData } = this._loadSheetData();
|
|
5924
|
+
const { allUnitData, unitNameMap, unitSheetNameMap, unitStylesData } = this._loadSheetData();
|
|
5734
5925
|
this._unitData = allUnitData;
|
|
5735
5926
|
this._unitStylesData = unitStylesData;
|
|
5736
5927
|
this._sheetNameMap = unitSheetNameMap;
|
|
5928
|
+
this._unitNameMap = unitNameMap;
|
|
5737
5929
|
this._formulaData = this._formulaDataModel.getFormulaData();
|
|
5738
5930
|
this._arrayFormulaCellData = convertUnitDataToRuntime(this._formulaDataModel.getArrayFormulaCellData());
|
|
5739
5931
|
this._arrayFormulaRange = this._formulaDataModel.getArrayFormulaRange();
|
|
@@ -5768,6 +5960,9 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
|
|
|
5768
5960
|
registerSheetNameMap(sheetNameMap) {
|
|
5769
5961
|
this._sheetNameMap = sheetNameMap;
|
|
5770
5962
|
}
|
|
5963
|
+
registerUnitNameMap(unitNameMap) {
|
|
5964
|
+
this._unitNameMap = unitNameMap;
|
|
5965
|
+
}
|
|
5771
5966
|
_mergeNameMap(unitSheetNameMap, dirtyNameMap) {
|
|
5772
5967
|
Object.keys(dirtyNameMap).forEach((unitId) => {
|
|
5773
5968
|
if (dirtyNameMap[unitId]) Object.keys(dirtyNameMap[unitId]).forEach((sheetId) => {
|
|
@@ -5788,7 +5983,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
|
|
|
5788
5983
|
const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
5789
5984
|
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
|
|
5790
5985
|
const base = workbook ? null : this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_BASE);
|
|
5791
|
-
const table = base ?
|
|
5986
|
+
const table = base ? getFirstBaseTable(base.getSnapshot().tables, base.getSnapshot().tableOrder) : null;
|
|
5792
5987
|
this._executeUnitId = (_workbook$getUnitId = workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId()) !== null && _workbook$getUnitId !== void 0 ? _workbook$getUnitId : base === null || base === void 0 ? void 0 : base.getUnitId();
|
|
5793
5988
|
this._executeSubUnitId = (_worksheet$getSheetId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId()) !== null && _worksheet$getSheetId !== void 0 ? _worksheet$getSheetId : table === null || table === void 0 ? void 0 : table.id;
|
|
5794
5989
|
return this._formulaDataModel.getCalculateData();
|
|
@@ -5821,33 +6016,18 @@ FormulaCurrentConfigService = __decorate([
|
|
|
5821
6016
|
__decorateParam(2, (0, _univerjs_core.Inject)(FormulaDataModel)),
|
|
5822
6017
|
__decorateParam(3, (0, _univerjs_core.Inject)(ISheetRowFilteredService))
|
|
5823
6018
|
], FormulaCurrentConfigService);
|
|
5824
|
-
function
|
|
5825
|
-
var _Object$values
|
|
6019
|
+
function getFirstBaseTable(tables, tableOrder) {
|
|
6020
|
+
var _Object$values$;
|
|
5826
6021
|
for (const tableId of tableOrder) {
|
|
5827
6022
|
const table = tables[tableId];
|
|
5828
|
-
if (table
|
|
6023
|
+
if (table) return table;
|
|
5829
6024
|
}
|
|
5830
|
-
return (_Object$values$
|
|
6025
|
+
return (_Object$values$ = Object.values(tables)[0]) !== null && _Object$values$ !== void 0 ? _Object$values$ : null;
|
|
5831
6026
|
}
|
|
5832
6027
|
const IFormulaCurrentConfigService = (0, _univerjs_core.createIdentifier)("univer.formula.current-data.service");
|
|
5833
6028
|
|
|
5834
6029
|
//#endregion
|
|
5835
6030
|
//#region src/engine/analysis/lexer.ts
|
|
5836
|
-
/**
|
|
5837
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
5838
|
-
*
|
|
5839
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5840
|
-
* you may not use this file except in compliance with the License.
|
|
5841
|
-
* You may obtain a copy of the License at
|
|
5842
|
-
*
|
|
5843
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5844
|
-
*
|
|
5845
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
5846
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5847
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5848
|
-
* See the License for the specific language governing permissions and
|
|
5849
|
-
* limitations under the License.
|
|
5850
|
-
*/
|
|
5851
6031
|
let Lexer = class Lexer extends _univerjs_core.Disposable {
|
|
5852
6032
|
constructor(_definedNamesService, _lexerTreeBuilder, _formulaCurrentConfigService) {
|
|
5853
6033
|
super();
|
|
@@ -5855,10 +6035,11 @@ let Lexer = class Lexer extends _univerjs_core.Disposable {
|
|
|
5855
6035
|
this._lexerTreeBuilder = _lexerTreeBuilder;
|
|
5856
6036
|
this._formulaCurrentConfigService = _formulaCurrentConfigService;
|
|
5857
6037
|
}
|
|
5858
|
-
treeBuilder(formulaString, transformSuffix = true) {
|
|
6038
|
+
treeBuilder(formulaString, transformSuffix = true, unitId) {
|
|
5859
6039
|
if (this._definedNamesService.getAllDefinedNamesIsEmpty()) return this._lexerTreeBuilder.treeBuilder(formulaString, transformSuffix);
|
|
5860
6040
|
return this._lexerTreeBuilder.treeBuilder(formulaString, transformSuffix, {
|
|
5861
|
-
unitId: this._formulaCurrentConfigService.getExecuteUnitId(),
|
|
6041
|
+
unitId: unitId !== null && unitId !== void 0 ? unitId : this._formulaCurrentConfigService.getExecuteUnitId(),
|
|
6042
|
+
sheetId: this._formulaCurrentConfigService.getExecuteSubUnitId(),
|
|
5862
6043
|
getValueByName: this._definedNamesService.getValueByName.bind(this._definedNamesService),
|
|
5863
6044
|
getDirtyDefinedNameMap: this._formulaCurrentConfigService.getDirtyDefinedNameMap.bind(this._formulaCurrentConfigService),
|
|
5864
6045
|
getSheetName: this._formulaCurrentConfigService.getSheetName.bind(this._formulaCurrentConfigService)
|
|
@@ -5880,10 +6061,13 @@ function getCellValue(cell) {
|
|
|
5880
6061
|
const body = cell === null || cell === void 0 ? void 0 : cell.p.body;
|
|
5881
6062
|
if (body == null) return 0;
|
|
5882
6063
|
const data = body.dataStream;
|
|
5883
|
-
return _univerjs_core.BuildTextUtils.transform.getPlainText(data);
|
|
6064
|
+
return normalizeRichTextFormulaValue(_univerjs_core.BuildTextUtils.transform.getPlainText(data));
|
|
5884
6065
|
}
|
|
5885
6066
|
return (_cell$v = cell === null || cell === void 0 ? void 0 : cell.v) !== null && _cell$v !== void 0 ? _cell$v : 0;
|
|
5886
6067
|
}
|
|
6068
|
+
function normalizeRichTextFormulaValue(value) {
|
|
6069
|
+
return value.replace(/\r\n|\r|\n/g, "\r\n");
|
|
6070
|
+
}
|
|
5887
6071
|
/**
|
|
5888
6072
|
* Extract the formula error from the cell
|
|
5889
6073
|
* @param cell
|
|
@@ -6122,24 +6306,16 @@ function reverseCompareOperator(operator) {
|
|
|
6122
6306
|
Reference https://en.wikipedia.org/wiki/Numeric_precision_in_Microsoft_Excel
|
|
6123
6307
|
*/
|
|
6124
6308
|
function plus(a, b) {
|
|
6125
|
-
|
|
6126
|
-
if (Number.isSafeInteger(result)) return result;
|
|
6127
|
-
return new decimal_js.default(a).add(b).toNumber();
|
|
6309
|
+
return a + b;
|
|
6128
6310
|
}
|
|
6129
6311
|
function minus(a, b) {
|
|
6130
|
-
|
|
6131
|
-
if (Number.isSafeInteger(result)) return result;
|
|
6132
|
-
return new decimal_js.default(a).sub(b).toNumber();
|
|
6312
|
+
return a - b;
|
|
6133
6313
|
}
|
|
6134
6314
|
function multiply(a, b) {
|
|
6135
|
-
|
|
6136
|
-
if (Number.isSafeInteger(result)) return result;
|
|
6137
|
-
return new decimal_js.default(a).mul(b).toNumber();
|
|
6315
|
+
return a * b;
|
|
6138
6316
|
}
|
|
6139
6317
|
function divide(a, b) {
|
|
6140
|
-
|
|
6141
|
-
if (Number.isSafeInteger(result)) return result;
|
|
6142
|
-
return new decimal_js.default(a).div(b).toNumber();
|
|
6318
|
+
return a / b;
|
|
6143
6319
|
}
|
|
6144
6320
|
/**
|
|
6145
6321
|
* Rounds a number to a specified number of decimal places.
|
|
@@ -6211,7 +6387,7 @@ function sqrt(base) {
|
|
|
6211
6387
|
* @returns True if numbers are equal, false otherwise.
|
|
6212
6388
|
*/
|
|
6213
6389
|
function equals(a, b) {
|
|
6214
|
-
return a === b;
|
|
6390
|
+
return a === b || stripErrorMargin(a) === stripErrorMargin(b);
|
|
6215
6391
|
}
|
|
6216
6392
|
/**
|
|
6217
6393
|
* Checks if the first number is greater than the second number.
|
|
@@ -6220,7 +6396,7 @@ function equals(a, b) {
|
|
|
6220
6396
|
* @returns True if a is greater than b, false otherwise.
|
|
6221
6397
|
*/
|
|
6222
6398
|
function greaterThan(a, b) {
|
|
6223
|
-
return a > b;
|
|
6399
|
+
return !equals(a, b) && stripErrorMargin(a) > stripErrorMargin(b);
|
|
6224
6400
|
}
|
|
6225
6401
|
/**
|
|
6226
6402
|
* Checks if the first number is greater than or equal to the second number.
|
|
@@ -6229,7 +6405,7 @@ function greaterThan(a, b) {
|
|
|
6229
6405
|
* @returns True if a is greater than or equal to b, false otherwise.
|
|
6230
6406
|
*/
|
|
6231
6407
|
function greaterThanOrEquals(a, b) {
|
|
6232
|
-
return a
|
|
6408
|
+
return equals(a, b) || stripErrorMargin(a) > stripErrorMargin(b);
|
|
6233
6409
|
}
|
|
6234
6410
|
/**
|
|
6235
6411
|
* Checks if the first number is less than the second number.
|
|
@@ -6238,7 +6414,7 @@ function greaterThanOrEquals(a, b) {
|
|
|
6238
6414
|
* @returns True if a is less than b, false otherwise.
|
|
6239
6415
|
*/
|
|
6240
6416
|
function lessThan(a, b) {
|
|
6241
|
-
return a < b;
|
|
6417
|
+
return !equals(a, b) && stripErrorMargin(a) < stripErrorMargin(b);
|
|
6242
6418
|
}
|
|
6243
6419
|
/**
|
|
6244
6420
|
* Checks if the first number is less than or equal to the second number.
|
|
@@ -6247,7 +6423,7 @@ function lessThan(a, b) {
|
|
|
6247
6423
|
* @returns True if a is less than or equal to b, false otherwise.
|
|
6248
6424
|
*/
|
|
6249
6425
|
function lessThanOrEquals(a, b) {
|
|
6250
|
-
return a
|
|
6426
|
+
return equals(a, b) || stripErrorMargin(a) < stripErrorMargin(b);
|
|
6251
6427
|
}
|
|
6252
6428
|
/**
|
|
6253
6429
|
* Complete the number to the specified accuracy and solve the accuracy error,
|
|
@@ -6515,8 +6691,8 @@ var BooleanValueObject = class BooleanValueObject extends BaseValueObject {
|
|
|
6515
6691
|
case ">=": return true;
|
|
6516
6692
|
case "=":
|
|
6517
6693
|
case "<":
|
|
6518
|
-
case "<=":
|
|
6519
|
-
case "<>": return
|
|
6694
|
+
case "<=": return false;
|
|
6695
|
+
case "<>": return true;
|
|
6520
6696
|
}
|
|
6521
6697
|
}
|
|
6522
6698
|
concatenateFront(valueObject) {
|
|
@@ -7138,12 +7314,13 @@ var StringValueObject = class StringValueObject extends BaseValueObject {
|
|
|
7138
7314
|
return BooleanValueObject.create(result);
|
|
7139
7315
|
}
|
|
7140
7316
|
_compareString(currentValue, value, operator) {
|
|
7317
|
+
const compareResult = currentValue.localeCompare(value);
|
|
7141
7318
|
switch (operator) {
|
|
7142
7319
|
case "=": return currentValue === value;
|
|
7143
|
-
case ">": return
|
|
7144
|
-
case ">=": return currentValue
|
|
7145
|
-
case "<": return
|
|
7146
|
-
case "<=": return currentValue
|
|
7320
|
+
case ">": return compareResult > 0;
|
|
7321
|
+
case ">=": return currentValue === value || compareResult > 0;
|
|
7322
|
+
case "<": return compareResult < 0;
|
|
7323
|
+
case "<=": return currentValue === value || compareResult < 0;
|
|
7147
7324
|
case "<>": return currentValue !== value;
|
|
7148
7325
|
}
|
|
7149
7326
|
}
|
|
@@ -7169,6 +7346,7 @@ var StringValueObject = class StringValueObject extends BaseValueObject {
|
|
|
7169
7346
|
}
|
|
7170
7347
|
convertToNumberObjectValue() {
|
|
7171
7348
|
const rawValue = this.getValue();
|
|
7349
|
+
if (rawValue.trim() === "") return ErrorValueObject.create("#VALUE!");
|
|
7172
7350
|
const parseData = (0, _univerjs_core.getNumfmtParseValueFilter)(rawValue);
|
|
7173
7351
|
if (parseData && parseData.z) return createNumberValueObjectByRawValue(parseData.v, parseData.z);
|
|
7174
7352
|
return createNumberValueObjectByRawValue(rawValue);
|
|
@@ -7277,6 +7455,8 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
7277
7455
|
_defineProperty(this, "_sheetId", "");
|
|
7278
7456
|
_defineProperty(this, "_currentRow", -1);
|
|
7279
7457
|
_defineProperty(this, "_currentColumn", -1);
|
|
7458
|
+
_defineProperty(this, "_useInvertedIndexCache", false);
|
|
7459
|
+
_defineProperty(this, "_legacyImplicitForAggregate", false);
|
|
7280
7460
|
_defineProperty(this, "_sliceCache", /* @__PURE__ */ new Map());
|
|
7281
7461
|
_defineProperty(this, "_flattenCache", void 0);
|
|
7282
7462
|
_defineProperty(this, "_defaultValue", null);
|
|
@@ -7328,6 +7508,15 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
7328
7508
|
getCurrentColumn() {
|
|
7329
7509
|
return this._currentColumn;
|
|
7330
7510
|
}
|
|
7511
|
+
usesInvertedIndexCache() {
|
|
7512
|
+
return this._useInvertedIndexCache;
|
|
7513
|
+
}
|
|
7514
|
+
usesLegacyImplicitForAggregate() {
|
|
7515
|
+
return this._legacyImplicitForAggregate;
|
|
7516
|
+
}
|
|
7517
|
+
setLegacyImplicitForAggregate(value) {
|
|
7518
|
+
this._legacyImplicitForAggregate = value;
|
|
7519
|
+
}
|
|
7331
7520
|
getArrayValue() {
|
|
7332
7521
|
return this._values;
|
|
7333
7522
|
}
|
|
@@ -7594,6 +7783,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
7594
7783
|
if (itemValue == null || itemValue.isNull()) return true;
|
|
7595
7784
|
let matchObject;
|
|
7596
7785
|
if (isFuzzyMatching === true) matchObject = itemValue.compare(valueObject, "=");
|
|
7786
|
+
else if (searchType === 0 && itemValue.isNumber() && valueObject.isNumber()) matchObject = BooleanValueObject.create(Number(itemValue.getValue()) === Number(valueObject.getValue()));
|
|
7597
7787
|
else matchObject = itemValue.isEqual(valueObject);
|
|
7598
7788
|
if ((matchObject === null || matchObject === void 0 ? void 0 : matchObject.getValue()) === true) {
|
|
7599
7789
|
result = itemValue;
|
|
@@ -7716,7 +7906,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
7716
7906
|
return false;
|
|
7717
7907
|
}
|
|
7718
7908
|
if (valueObject.isString() || valueObject.isNull() || valueObject.isBoolean()) return true;
|
|
7719
|
-
if (accumulatorAll.
|
|
7909
|
+
if (Number(accumulatorAll.getValue()) < Number(valueObject.getValue())) accumulatorAll = valueObject;
|
|
7720
7910
|
});
|
|
7721
7911
|
return accumulatorAll;
|
|
7722
7912
|
}
|
|
@@ -7757,7 +7947,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
7757
7947
|
return accumulatorAll;
|
|
7758
7948
|
}
|
|
7759
7949
|
getNegative() {
|
|
7760
|
-
return
|
|
7950
|
+
return this.mapValue((valueObject) => NumberValueObject.create(0).minus(valueObject));
|
|
7761
7951
|
}
|
|
7762
7952
|
getReciprocal() {
|
|
7763
7953
|
return ArrayValueObject.create("{1}").divided(this);
|
|
@@ -7809,12 +7999,10 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
7809
7999
|
for (let c = 0; c < columnCount; c++) {
|
|
7810
8000
|
var _this$_values;
|
|
7811
8001
|
const row = (_this$_values = this._values) === null || _this$_values === void 0 ? void 0 : _this$_values[r];
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
else rowList[c] = NullValueObject.create();
|
|
7817
|
-
}
|
|
8002
|
+
const currentValue = this.getValueOrDefault(r, c);
|
|
8003
|
+
if (row == null && currentValue == null) rowList[c] = ErrorValueObject.create("#VALUE!");
|
|
8004
|
+
else if (currentValue) rowList[c] = callbackFn(currentValue, r, c);
|
|
8005
|
+
else rowList[c] = NullValueObject.create();
|
|
7818
8006
|
}
|
|
7819
8007
|
result.push(rowList);
|
|
7820
8008
|
}
|
|
@@ -8124,7 +8312,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8124
8312
|
* If comparison operations are conducted for a single numerical value,
|
|
8125
8313
|
* then retrieve the judgment from the inverted index. This enhances performance.
|
|
8126
8314
|
*/
|
|
8127
|
-
if (batchOperatorType === 5) {
|
|
8315
|
+
if (batchOperatorType === 5 && this._useInvertedIndexCache) {
|
|
8128
8316
|
const { rowsInCache, rowsNotInCache } = CELL_INVERTED_INDEX_CACHE.canUseCache(unitId, sheetId, column + startColumn, startRow, startRow + rowCount - 1);
|
|
8129
8317
|
if (rowsInCache.length > 0) {
|
|
8130
8318
|
if (operator === "=" && !(valueObject.isString() && isWildcard(valueObject.getValue()))) {
|
|
@@ -8158,13 +8346,13 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8158
8346
|
if (rowsNotInCache.length > 0) for (const interval of rowsNotInCache) {
|
|
8159
8347
|
const [start, end] = interval;
|
|
8160
8348
|
for (let r = start; r <= end; r++) this.__batchOperatorRowValue(valueObject, column, result, batchOperatorType, r - startRow, unitId, sheetId, startRow, startColumn, operator, isCaseSensitive);
|
|
8161
|
-
CELL_INVERTED_INDEX_CACHE.setContinueBuildingCache(unitId, sheetId, column + startColumn, start, end);
|
|
8349
|
+
if (this._useInvertedIndexCache) CELL_INVERTED_INDEX_CACHE.setContinueBuildingCache(unitId, sheetId, column + startColumn, start, end);
|
|
8162
8350
|
}
|
|
8163
8351
|
return;
|
|
8164
8352
|
}
|
|
8165
8353
|
}
|
|
8166
8354
|
for (let r = 0; r < rowCount; r++) this.__batchOperatorRowValue(valueObject, column, result, batchOperatorType, r, unitId, sheetId, startRow, startColumn, operator, isCaseSensitive);
|
|
8167
|
-
CELL_INVERTED_INDEX_CACHE.setContinueBuildingCache(unitId, sheetId, column + startColumn, startRow, startRow + rowCount - 1);
|
|
8355
|
+
if (this._useInvertedIndexCache) CELL_INVERTED_INDEX_CACHE.setContinueBuildingCache(unitId, sheetId, column + startColumn, startRow, startRow + rowCount - 1);
|
|
8168
8356
|
}
|
|
8169
8357
|
__batchOperatorRowValue(valueObject, column, result, batchOperatorType, r, unitId, sheetId, startRow, startColumn, operator, isCaseSensitive) {
|
|
8170
8358
|
const currentValue = this.getValueOrDefault(r, column);
|
|
@@ -8214,7 +8402,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8214
8402
|
break;
|
|
8215
8403
|
}
|
|
8216
8404
|
else result[r][column] = ErrorValueObject.create("#N/A");
|
|
8217
|
-
CELL_INVERTED_INDEX_CACHE.set(unitId, sheetId, column + startColumn, (currentValue === null || currentValue === void 0 ? void 0 : currentValue.isNull()) ? null : currentValue === null || currentValue === void 0 ? void 0 : currentValue.getValue(), r + startRow);
|
|
8405
|
+
if (this._useInvertedIndexCache) CELL_INVERTED_INDEX_CACHE.set(unitId, sheetId, column + startColumn, (currentValue === null || currentValue === void 0 ? void 0 : currentValue.isNull()) ? null : currentValue === null || currentValue === void 0 ? void 0 : currentValue.getValue(), r + startRow);
|
|
8218
8406
|
}
|
|
8219
8407
|
_batchOperatorArray(valueObject, batchOperatorType, operator, isCaseSensitive) {
|
|
8220
8408
|
let rowCount = valueObject.getRowCount();
|
|
@@ -8285,7 +8473,9 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8285
8473
|
}
|
|
8286
8474
|
result.push(rowList);
|
|
8287
8475
|
}
|
|
8288
|
-
|
|
8476
|
+
const newArray = this._createNewArray(result, rowCount, columnCount);
|
|
8477
|
+
if (batchOperatorType === 1) newArray.setLegacyImplicitForAggregate(true);
|
|
8478
|
+
return newArray;
|
|
8289
8479
|
}
|
|
8290
8480
|
_checkArrayCalculateType(valueObject) {
|
|
8291
8481
|
if (valueObject.getRowCount() === 1 && valueObject.getColumnCount() === 1) return 3;
|
|
@@ -8302,6 +8492,8 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8302
8492
|
this._sheetId = rawValue.sheetId;
|
|
8303
8493
|
this._currentRow = rawValue.row;
|
|
8304
8494
|
this._currentColumn = rawValue.column;
|
|
8495
|
+
this._useInvertedIndexCache = rawValue.useInvertedIndexCache === true;
|
|
8496
|
+
this._legacyImplicitForAggregate = rawValue.legacyImplicitForAggregate === true;
|
|
8305
8497
|
return rawValue.calculateValueList;
|
|
8306
8498
|
}
|
|
8307
8499
|
rawValue = rawValue.slice(1, -1);
|
|
@@ -8324,7 +8516,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8324
8516
|
this._columnCount = maxColumnCount;
|
|
8325
8517
|
return result;
|
|
8326
8518
|
}
|
|
8327
|
-
_createNewArray(result, rowCount, columnCount, row =
|
|
8519
|
+
_createNewArray(result, rowCount, columnCount, row = this._currentRow, column = this._currentColumn) {
|
|
8328
8520
|
if (this._currentColumn === -1 || this._currentRow === -1) {
|
|
8329
8521
|
row = -1;
|
|
8330
8522
|
column = -1;
|
|
@@ -8389,6 +8581,7 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
8389
8581
|
_defineProperty(this, "_filteredOutRows", []);
|
|
8390
8582
|
_defineProperty(this, "_defaultUnitId", "");
|
|
8391
8583
|
_defineProperty(this, "_forcedUnitId", "");
|
|
8584
|
+
_defineProperty(this, "_unitQualifier", "");
|
|
8392
8585
|
_defineProperty(this, "_runtimeData", {});
|
|
8393
8586
|
_defineProperty(this, "_arrayFormulaCellData", {});
|
|
8394
8587
|
_defineProperty(this, "_arrayFormulaRange", {});
|
|
@@ -8440,14 +8633,14 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
8440
8633
|
}
|
|
8441
8634
|
iterator(callback) {
|
|
8442
8635
|
const { startRow, endRow, startColumn, endColumn } = this.getRangePosition();
|
|
8443
|
-
if (this._checkIfWorksheetMiss()) return callback(ErrorValueObject.create("#
|
|
8636
|
+
if (this._checkIfWorksheetMiss()) return callback(ErrorValueObject.create("#REF!"), startRow, startColumn);
|
|
8444
8637
|
const unitId = this._forcedUnitId || this._defaultUnitId;
|
|
8445
8638
|
const sheetId = this._forcedSheetId || this._defaultSheetId;
|
|
8446
8639
|
for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
|
|
8447
8640
|
if (r < 0 || c < 0) return callback(ErrorValueObject.create("#REF!"), r, c);
|
|
8448
8641
|
const cell = this.getCellData(r, c);
|
|
8449
8642
|
let result = false;
|
|
8450
|
-
if ((0, _univerjs_core.isNullCell)(cell)) {
|
|
8643
|
+
if ((0, _univerjs_core.isNullCell)(cell) && !isTypedEmptyStringCell(cell)) {
|
|
8451
8644
|
result = callback(null, r, c);
|
|
8452
8645
|
continue;
|
|
8453
8646
|
}
|
|
@@ -8464,7 +8657,7 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
8464
8657
|
}
|
|
8465
8658
|
}
|
|
8466
8659
|
getFirstCell() {
|
|
8467
|
-
if (this._checkIfWorksheetMiss()) return ErrorValueObject.create("#
|
|
8660
|
+
if (this._checkIfWorksheetMiss()) return ErrorValueObject.create("#REF!");
|
|
8468
8661
|
const { startRow, startColumn } = this.getRangePosition();
|
|
8469
8662
|
const cell = this.getCellData(startRow, startColumn);
|
|
8470
8663
|
if (!cell) return NumberValueObject.create(0);
|
|
@@ -8495,6 +8688,12 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
8495
8688
|
setForcedUnitIdDirect(unitId) {
|
|
8496
8689
|
if (unitId.length > 0) this._forcedUnitId = unitId;
|
|
8497
8690
|
}
|
|
8691
|
+
setUnitQualifier(unitQualifier) {
|
|
8692
|
+
this._unitQualifier = unitQualifier;
|
|
8693
|
+
}
|
|
8694
|
+
getUnitQualifier() {
|
|
8695
|
+
return this._unitQualifier;
|
|
8696
|
+
}
|
|
8498
8697
|
getForcedUnitId() {
|
|
8499
8698
|
return this._forcedUnitId;
|
|
8500
8699
|
}
|
|
@@ -8643,14 +8842,15 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
8643
8842
|
}
|
|
8644
8843
|
getCellValueObject(cell) {
|
|
8645
8844
|
const value = getCellValue(cell);
|
|
8845
|
+
const cellValueType = Number(cell.t);
|
|
8646
8846
|
if (ERROR_TYPE_SET.has(value)) return ErrorValueObject.create(value);
|
|
8647
|
-
if (
|
|
8847
|
+
if (cellValueType === _univerjs_core.CellValueType.NUMBER) {
|
|
8648
8848
|
const pattern = this._getPatternByCell(cell);
|
|
8649
8849
|
if ((0, _univerjs_core.isTextFormat)(pattern)) return StringValueObject.create(value.toString());
|
|
8650
8850
|
return createNumberValueObjectByRawValue(value, pattern);
|
|
8651
8851
|
}
|
|
8652
|
-
if (
|
|
8653
|
-
if (
|
|
8852
|
+
if (cellValueType === _univerjs_core.CellValueType.STRING || cellValueType === _univerjs_core.CellValueType.FORCE_STRING) return StringValueObject.create(value.toString());
|
|
8853
|
+
if (cellValueType === _univerjs_core.CellValueType.BOOLEAN) return createBooleanValueObjectByRawValue(value);
|
|
8654
8854
|
return ValueObjectFactory.create(value);
|
|
8655
8855
|
}
|
|
8656
8856
|
_getPatternByCell(cell) {
|
|
@@ -8726,7 +8926,7 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
8726
8926
|
if (!row) row = rangeData.startRow;
|
|
8727
8927
|
if (!column) column = rangeData.startColumn;
|
|
8728
8928
|
const cell = this.getCellData(row, column);
|
|
8729
|
-
if (!cell) return
|
|
8929
|
+
if (!cell) return NullValueObject.create();
|
|
8730
8930
|
return this.getCellValueObject(cell);
|
|
8731
8931
|
}
|
|
8732
8932
|
setCurrentRowAndColumn(row, column) {
|
|
@@ -8780,7 +8980,8 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
8780
8980
|
unitId: this.getUnitId(),
|
|
8781
8981
|
sheetId: this.getSheetId(),
|
|
8782
8982
|
row: startRow,
|
|
8783
|
-
column: startColumn
|
|
8983
|
+
column: startColumn,
|
|
8984
|
+
useInvertedIndexCache: true
|
|
8784
8985
|
};
|
|
8785
8986
|
const arrayValueObject = ArrayValueObject.create(arrayValueObjectData);
|
|
8786
8987
|
useCache && FORMULA_REF_TO_ARRAY_CACHE.set(key, arrayValueObject);
|
|
@@ -8810,6 +9011,9 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
8810
9011
|
return ArrayValueObject.create(arrayValueObjectData);
|
|
8811
9012
|
}
|
|
8812
9013
|
};
|
|
9014
|
+
function isTypedEmptyStringCell(cell) {
|
|
9015
|
+
return (cell === null || cell === void 0 ? void 0 : cell.v) === "" && (cell.t === _univerjs_core.CellValueType.STRING || cell.t === _univerjs_core.CellValueType.FORCE_STRING);
|
|
9016
|
+
}
|
|
8813
9017
|
var AsyncObject = class extends ObjectClassType {
|
|
8814
9018
|
constructor(_promise) {
|
|
8815
9019
|
super();
|
|
@@ -8871,10 +9075,13 @@ var RangeReferenceObject = class extends BaseReferenceObject {
|
|
|
8871
9075
|
|
|
8872
9076
|
//#endregion
|
|
8873
9077
|
//#region src/engine/reference-object/cell-reference-object.ts
|
|
9078
|
+
const EXCEL_MAX_ROWS = 1048576;
|
|
9079
|
+
const EXCEL_MAX_COLUMNS = 16384;
|
|
8874
9080
|
var CellReferenceObject = class extends BaseReferenceObject {
|
|
8875
9081
|
constructor(token) {
|
|
8876
9082
|
super(token);
|
|
8877
9083
|
const grid = deserializeRangeWithSheetWithCache(token);
|
|
9084
|
+
this.setUnitQualifier(grid.unitId);
|
|
8878
9085
|
this.setForcedUnitIdDirect(grid.unitId);
|
|
8879
9086
|
this.setForcedSheetName(grid.sheetName);
|
|
8880
9087
|
this.setRangeData(grid.range);
|
|
@@ -8882,6 +9089,12 @@ var CellReferenceObject = class extends BaseReferenceObject {
|
|
|
8882
9089
|
isCell() {
|
|
8883
9090
|
return true;
|
|
8884
9091
|
}
|
|
9092
|
+
isExceedRange() {
|
|
9093
|
+
var _this$getForcedSheetI;
|
|
9094
|
+
if ((this.getForcedSheetId() == null || ((_this$getForcedSheetI = this.getForcedSheetId()) === null || _this$getForcedSheetI === void 0 ? void 0 : _this$getForcedSheetI.length) === 0) && this.getForcedSheetName().length > 0) return true;
|
|
9095
|
+
const { startRow, endRow, startColumn, endColumn } = this.getRangePosition();
|
|
9096
|
+
return startRow < 0 || startColumn < 0 || endRow >= EXCEL_MAX_ROWS || endColumn >= EXCEL_MAX_COLUMNS;
|
|
9097
|
+
}
|
|
8885
9098
|
unionBy(referenceObject) {
|
|
8886
9099
|
if (!referenceObject.isCell()) return ErrorValueObject.create("#REF!");
|
|
8887
9100
|
const cellReferenceObject = referenceObject;
|
|
@@ -8944,6 +9157,7 @@ var ColumnReferenceObject = class extends BaseReferenceObject {
|
|
|
8944
9157
|
constructor(token) {
|
|
8945
9158
|
super(token);
|
|
8946
9159
|
const grid = deserializeRangeWithSheetWithCache(token);
|
|
9160
|
+
this.setUnitQualifier(grid.unitId);
|
|
8947
9161
|
this.setForcedUnitIdDirect(grid.unitId);
|
|
8948
9162
|
this.setForcedSheetName(grid.sheetName);
|
|
8949
9163
|
const range = {
|
|
@@ -8986,6 +9200,7 @@ var RowReferenceObject = class extends BaseReferenceObject {
|
|
|
8986
9200
|
constructor(token) {
|
|
8987
9201
|
super(token);
|
|
8988
9202
|
const grid = deserializeRangeWithSheetWithCache(token);
|
|
9203
|
+
this.setUnitQualifier(grid.unitId);
|
|
8989
9204
|
this.setForcedUnitIdDirect(grid.unitId);
|
|
8990
9205
|
this.setForcedSheetName(grid.sheetName);
|
|
8991
9206
|
const range = {
|
|
@@ -9365,11 +9580,11 @@ function getPairedRangeAndCriteriaResult(variants, params) {
|
|
|
9365
9580
|
result = sum.divided(count);
|
|
9366
9581
|
} else if (formulaName === "MAXIFS") {
|
|
9367
9582
|
const picked = targetRange.pick(finalCompareResult);
|
|
9368
|
-
if (picked.getColumnCount() === 0) result =
|
|
9583
|
+
if (picked.getColumnCount() === 0) result = NumberValueObject.create(0);
|
|
9369
9584
|
else result = picked.max();
|
|
9370
9585
|
} else if (formulaName === "MINIFS") {
|
|
9371
9586
|
const picked = targetRange.pick(finalCompareResult);
|
|
9372
|
-
if (picked.getColumnCount() === 0) result =
|
|
9587
|
+
if (picked.getColumnCount() === 0) result = NumberValueObject.create(0);
|
|
9373
9588
|
else result = picked.min();
|
|
9374
9589
|
}
|
|
9375
9590
|
if (!results[rowIndex]) results[rowIndex] = [];
|
|
@@ -9381,13 +9596,25 @@ function getPairedRangeAndCriteriaResult(variants, params) {
|
|
|
9381
9596
|
* Two ArrayValueObject of the same type can be compared
|
|
9382
9597
|
*/
|
|
9383
9598
|
function filterSameValueObjectResult(array, range, criteria) {
|
|
9384
|
-
const [operator, criteriaObject] = findCompareToken(`${criteria.getValue()}`);
|
|
9599
|
+
const [operator, criteriaObject] = criteria.isString() ? findCompareToken(`${criteria.getValue()}`) : ["=", criteria];
|
|
9385
9600
|
return array.mapValue((valueObject, r, c) => {
|
|
9386
9601
|
const rangeValueObject = range.get(r, c);
|
|
9602
|
+
const isBlankStringCriteria = criteriaObject.isString() && criteriaObject.getValue() === "";
|
|
9603
|
+
if (operator === "<>" && isBlankStringCriteria && (rangeValueObject === null || rangeValueObject === void 0 ? void 0 : rangeValueObject.isString()) && rangeValueObject.getValue() === "") return BooleanValueObject.create(true);
|
|
9604
|
+
if (criteriaObject.isString() && criteriaObject.getValue() !== "" && (operator === "<" || operator === "<=") && (rangeValueObject == null || rangeValueObject.isNull() || rangeValueObject.isString() && rangeValueObject.getValue() === "")) return BooleanValueObject.create(false);
|
|
9605
|
+
if (criteriaObject.isString() && (rangeValueObject === null || rangeValueObject === void 0 ? void 0 : rangeValueObject.isString()) && (operator === "<" || operator === "<=") && isSameLowerBoundBucket(rangeValueObject.getValue(), criteriaObject.getValue())) return BooleanValueObject.create(false);
|
|
9606
|
+
if ((rangeValueObject === null || rangeValueObject === void 0 ? void 0 : rangeValueObject.isNumber()) && criteriaObject.isString()) {
|
|
9607
|
+
const criteriaNumber = criteriaObject.convertToNumberObjectValue();
|
|
9608
|
+
if (criteriaNumber.isNumber()) return rangeValueObject.compare(criteriaNumber, operator);
|
|
9609
|
+
}
|
|
9610
|
+
if (criteriaObject.isNumber() && criteriaObject.isDateFormat() && (rangeValueObject === null || rangeValueObject === void 0 ? void 0 : rangeValueObject.isString())) {
|
|
9611
|
+
const rangeNumber = rangeValueObject.convertToNumberObjectValue();
|
|
9612
|
+
if (rangeNumber.isNumber()) return rangeNumber.compare(criteriaObject, operator);
|
|
9613
|
+
}
|
|
9387
9614
|
if (rangeValueObject && isSameValueObjectType(rangeValueObject, criteriaObject)) return valueObject;
|
|
9388
9615
|
if ((rangeValueObject === null || rangeValueObject === void 0 ? void 0 : rangeValueObject.isError()) && criteriaObject.isError() && rangeValueObject.getValue() === criteriaObject.getValue()) return BooleanValueObject.create(true);
|
|
9389
9616
|
/**
|
|
9390
|
-
* If the operator is '=' or '<>', we can compare numbers
|
|
9617
|
+
* If the operator is '=' or '<>', we can compare string numbers against numeric criteria directly in COUNTIF, COUNTIFS, SUMIF, SUMIFS, etc.
|
|
9391
9618
|
* Other operators require both valueObjects to be of the same type.
|
|
9392
9619
|
* For example:
|
|
9393
9620
|
* | A1 | B1 |
|
|
@@ -9399,10 +9626,6 @@ function filterSameValueObjectResult(array, range, criteria) {
|
|
|
9399
9626
|
* =COUNTIF(A1:B1, '<=123') will return 1
|
|
9400
9627
|
*/
|
|
9401
9628
|
if (operator === "=" || operator === "<>") {
|
|
9402
|
-
if ((rangeValueObject === null || rangeValueObject === void 0 ? void 0 : rangeValueObject.isNumber()) && criteriaObject.isString()) {
|
|
9403
|
-
const criteriaNumber = criteriaObject.convertToNumberObjectValue();
|
|
9404
|
-
if (criteriaNumber.isNumber()) return rangeValueObject.compare(criteriaNumber, operator);
|
|
9405
|
-
}
|
|
9406
9629
|
if (criteriaObject.isNumber() && (rangeValueObject === null || rangeValueObject === void 0 ? void 0 : rangeValueObject.isString())) {
|
|
9407
9630
|
const rangeNumber = rangeValueObject.convertToNumberObjectValue();
|
|
9408
9631
|
if (rangeNumber.isNumber()) return rangeNumber.compare(criteriaObject, operator);
|
|
@@ -9413,6 +9636,11 @@ function filterSameValueObjectResult(array, range, criteria) {
|
|
|
9413
9636
|
return BooleanValueObject.create(false);
|
|
9414
9637
|
});
|
|
9415
9638
|
}
|
|
9639
|
+
function isSameLowerBoundBucket(rangeValue, criteriaValue) {
|
|
9640
|
+
const criteriaMatch = criteriaValue.match(/^(\d+)\|/);
|
|
9641
|
+
const rangeMatch = rangeValue.match(/^(\d+)-/);
|
|
9642
|
+
return criteriaMatch != null && rangeMatch != null && criteriaMatch[1] === rangeMatch[1];
|
|
9643
|
+
}
|
|
9416
9644
|
/**
|
|
9417
9645
|
* Check if the two valueObjects are of the same type
|
|
9418
9646
|
* @param left
|
|
@@ -9513,6 +9741,7 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
|
|
|
9513
9741
|
_defineProperty(this, "_currentColumn", -1);
|
|
9514
9742
|
_defineProperty(this, "_currentRowCount", Number.NEGATIVE_INFINITY);
|
|
9515
9743
|
_defineProperty(this, "_currentColumnCount", Number.NEGATIVE_INFINITY);
|
|
9744
|
+
_defineProperty(this, "_functionRefInfoOverrideStack", []);
|
|
9516
9745
|
_defineProperty(this, "_currentSubUnitId", "");
|
|
9517
9746
|
_defineProperty(this, "_currentUnitId", "");
|
|
9518
9747
|
_defineProperty(this, "_runtimeData", {});
|
|
@@ -9541,10 +9770,12 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
|
|
|
9541
9770
|
return this._currentColumn;
|
|
9542
9771
|
}
|
|
9543
9772
|
get currentRowCount() {
|
|
9544
|
-
|
|
9773
|
+
var _this$_functionRefInf, _this$_functionRefInf2;
|
|
9774
|
+
return (_this$_functionRefInf = (_this$_functionRefInf2 = this._functionRefInfoOverrideStack[this._functionRefInfoOverrideStack.length - 1]) === null || _this$_functionRefInf2 === void 0 ? void 0 : _this$_functionRefInf2.rowCount) !== null && _this$_functionRefInf !== void 0 ? _this$_functionRefInf : this._currentRowCount;
|
|
9545
9775
|
}
|
|
9546
9776
|
get currentColumnCount() {
|
|
9547
|
-
|
|
9777
|
+
var _this$_functionRefInf3, _this$_functionRefInf4;
|
|
9778
|
+
return (_this$_functionRefInf3 = (_this$_functionRefInf4 = this._functionRefInfoOverrideStack[this._functionRefInfoOverrideStack.length - 1]) === null || _this$_functionRefInf4 === void 0 ? void 0 : _this$_functionRefInf4.columnCount) !== null && _this$_functionRefInf3 !== void 0 ? _this$_functionRefInf3 : this._currentColumnCount;
|
|
9548
9779
|
}
|
|
9549
9780
|
get currentSubUnitId() {
|
|
9550
9781
|
return this._currentSubUnitId;
|
|
@@ -9638,6 +9869,7 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
|
|
|
9638
9869
|
this._isCycleDependency = false;
|
|
9639
9870
|
this._totalFormulasToCalculate = 0;
|
|
9640
9871
|
this._completedFormulasCount = 0;
|
|
9872
|
+
this._functionRefInfoOverrideStack = [];
|
|
9641
9873
|
this.clearReferenceAndNumberformatCache();
|
|
9642
9874
|
}
|
|
9643
9875
|
clearReferenceAndNumberformatCache() {
|
|
@@ -9653,6 +9885,15 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
|
|
|
9653
9885
|
this._currentSubUnitId = sheetId;
|
|
9654
9886
|
this._currentUnitId = unitId;
|
|
9655
9887
|
}
|
|
9888
|
+
setFunctionRefInfoOverride(rowCount, columnCount) {
|
|
9889
|
+
this._functionRefInfoOverrideStack.push({
|
|
9890
|
+
rowCount,
|
|
9891
|
+
columnCount
|
|
9892
|
+
});
|
|
9893
|
+
return () => {
|
|
9894
|
+
this._functionRefInfoOverrideStack.pop();
|
|
9895
|
+
};
|
|
9896
|
+
}
|
|
9656
9897
|
clearFunctionDefinitionPrivacyVar() {
|
|
9657
9898
|
this._functionDefinitionPrivacyVar.clear();
|
|
9658
9899
|
}
|
|
@@ -9716,13 +9957,22 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
|
|
|
9716
9957
|
* then it is not treated as an array range and is directly assigned.
|
|
9717
9958
|
*/
|
|
9718
9959
|
if (startRow === endRow && startColumn === endColumn) {
|
|
9719
|
-
const
|
|
9960
|
+
const firstCellRaw = objectValueRefOrArray.getFirstCell();
|
|
9961
|
+
const firstCell = firstCellRaw.isNull() ? NumberValueObject.create(0) : firstCellRaw;
|
|
9720
9962
|
const valueObject = this._getValueObjectOfRuntimeData(firstCell);
|
|
9721
9963
|
sheetData.setValue(row, column, valueObject);
|
|
9722
9964
|
clearArrayUnitData.setValue(row, column, valueObject);
|
|
9723
9965
|
CELL_INVERTED_INDEX_CACHE.set(unitId, sheetId, column, firstCell.getValue(), row, true);
|
|
9724
9966
|
return;
|
|
9725
9967
|
}
|
|
9968
|
+
if (this._isCurrentSingleCellArrayFormulaRange(unitId, sheetId, row, column)) {
|
|
9969
|
+
const errorObject = this._getValueObjectOfRuntimeData(ErrorValueObject.create("#VALUE!"));
|
|
9970
|
+
sheetData.setValue(row, column, errorObject);
|
|
9971
|
+
clearArrayUnitData.setValue(row, column, errorObject);
|
|
9972
|
+
runtimeArrayUnitData.setValue(row, column, errorObject);
|
|
9973
|
+
CELL_INVERTED_INDEX_CACHE.set(unitId, sheetId, column, "#VALUE!", row, true);
|
|
9974
|
+
return;
|
|
9975
|
+
}
|
|
9726
9976
|
const arrayRange = {
|
|
9727
9977
|
startRow: row,
|
|
9728
9978
|
startColumn: column,
|
|
@@ -9934,6 +10184,11 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
|
|
|
9934
10184
|
});
|
|
9935
10185
|
return isCellOverlapping;
|
|
9936
10186
|
}
|
|
10187
|
+
_isCurrentSingleCellArrayFormulaRange(unitId, sheetId, row, column) {
|
|
10188
|
+
var _this$_currentConfigS4;
|
|
10189
|
+
const range = (_this$_currentConfigS4 = this._currentConfigService.getArrayFormulaRange()[unitId]) === null || _this$_currentConfigS4 === void 0 || (_this$_currentConfigS4 = _this$_currentConfigS4[sheetId]) === null || _this$_currentConfigS4 === void 0 || (_this$_currentConfigS4 = _this$_currentConfigS4[row]) === null || _this$_currentConfigS4 === void 0 ? void 0 : _this$_currentConfigS4[column];
|
|
10190
|
+
return range != null && range.startRow === range.endRow && range.startColumn === range.endColumn;
|
|
10191
|
+
}
|
|
9937
10192
|
_isInArrayFormulaRange(range, r, c) {
|
|
9938
10193
|
if (range == null) return false;
|
|
9939
10194
|
const { startRow, startColumn, endRow, endColumn } = range;
|
|
@@ -10172,18 +10427,23 @@ const FORMULA_CACHE_LRU_COUNT = 5e3;
|
|
|
10172
10427
|
const FORMULA_AST_CACHE = new FormulaAstLRU(FORMULA_CACHE_LRU_COUNT);
|
|
10173
10428
|
const DIRTY_DEFINED_NAME_SET_CACHE = /* @__PURE__ */ new WeakMap();
|
|
10174
10429
|
const DIRTY_SUPER_TABLE_PATTERN_CACHE = /* @__PURE__ */ new WeakMap();
|
|
10175
|
-
function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentConfigService) {
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10430
|
+
function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentConfigService, subUnitId) {
|
|
10431
|
+
var _ref;
|
|
10432
|
+
if (subUnitId) {
|
|
10433
|
+
currentConfigService.setExecuteUnitId(unitId);
|
|
10434
|
+
currentConfigService.setExecuteSubUnitId(subUnitId);
|
|
10435
|
+
}
|
|
10436
|
+
const cacheKey = `${unitId}:${(_ref = subUnitId !== null && subUnitId !== void 0 ? subUnitId : currentConfigService.getExecuteSubUnitId()) !== null && _ref !== void 0 ? _ref : ""}:${formulaString}`;
|
|
10437
|
+
let astNode = FORMULA_AST_CACHE.get(cacheKey);
|
|
10438
|
+
if (!(checkIsChangedByDefinedName(unitId, formulaString, currentConfigService) || checkIsChangedBySuperTable(unitId, formulaString, currentConfigService)) && astNode && !isDirtyDefinedForNode(astNode, currentConfigService, unitId)) return astNode;
|
|
10439
|
+
const lexerNode = lexer.treeBuilder(formulaString, true, unitId);
|
|
10180
10440
|
if (ERROR_TYPE_SET.has(lexerNode)) return ErrorNode.create(lexerNode);
|
|
10181
10441
|
astNode = astTreeBuilder.parse(lexerNode);
|
|
10182
10442
|
if (astNode == null) {
|
|
10183
10443
|
console.error("generateAstNode astNode is null");
|
|
10184
10444
|
return ErrorNode.create(lexerNode);
|
|
10185
10445
|
}
|
|
10186
|
-
|
|
10446
|
+
FORMULA_AST_CACHE.set(cacheKey, astNode);
|
|
10187
10447
|
return astNode;
|
|
10188
10448
|
}
|
|
10189
10449
|
function checkIsChangedByDefinedName(unitId, formula, currentConfigService) {
|
|
@@ -10214,15 +10474,15 @@ function getNormalizedDirtyDefinedNameSet(unitDefinedNameMap) {
|
|
|
10214
10474
|
function getDirtySuperTableReferencePattern(unitSuperTableMap) {
|
|
10215
10475
|
let tableReferencePattern = DIRTY_SUPER_TABLE_PATTERN_CACHE.get(unitSuperTableMap);
|
|
10216
10476
|
if (tableReferencePattern === void 0) {
|
|
10217
|
-
const
|
|
10218
|
-
tableReferencePattern =
|
|
10477
|
+
const tableNames = Object.keys(unitSuperTableMap).filter((tableName) => tableName.length > 0);
|
|
10478
|
+
tableReferencePattern = tableNames.length > 0 ? _univerjs_core.regexp.createRegExpFromSafeFragment(`(^|[^A-Za-z0-9_])${_univerjs_core.regexp.or(...tableNames)}(\\s*\\[|$|[^A-Za-z0-9_])`, "i") : null;
|
|
10219
10479
|
DIRTY_SUPER_TABLE_PATTERN_CACHE.set(unitSuperTableMap, tableReferencePattern);
|
|
10220
10480
|
}
|
|
10221
10481
|
return tableReferencePattern;
|
|
10222
10482
|
}
|
|
10223
|
-
function isDirtyDefinedForNode(node, currentConfigService) {
|
|
10483
|
+
function isDirtyDefinedForNode(node, currentConfigService, unitId) {
|
|
10224
10484
|
const definedNameMap = currentConfigService.getDirtyDefinedNameMap();
|
|
10225
|
-
const executeUnitId =
|
|
10485
|
+
const executeUnitId = unitId;
|
|
10226
10486
|
if (executeUnitId != null && definedNameMap[executeUnitId] != null) {
|
|
10227
10487
|
const names = Object.keys(definedNameMap[executeUnitId]);
|
|
10228
10488
|
for (let i = 0, len = names.length; i < len; i++) {
|
|
@@ -10237,7 +10497,7 @@ function includeDefinedName(tree, node, currentConfigService) {
|
|
|
10237
10497
|
* Detect whether the dirty map contains a defined name.
|
|
10238
10498
|
*/
|
|
10239
10499
|
if (node != null) {
|
|
10240
|
-
if (isDirtyDefinedForNode(node, currentConfigService)) return true;
|
|
10500
|
+
if (isDirtyDefinedForNode(node, currentConfigService, tree.unitId)) return true;
|
|
10241
10501
|
}
|
|
10242
10502
|
return false;
|
|
10243
10503
|
}
|
|
@@ -10316,6 +10576,49 @@ var FunctionService = class extends _univerjs_core.Disposable {
|
|
|
10316
10576
|
}
|
|
10317
10577
|
};
|
|
10318
10578
|
|
|
10579
|
+
//#endregion
|
|
10580
|
+
//#region src/services/unit-reference-resolver.service.ts
|
|
10581
|
+
const IFormulaUnitReferenceResolver = (0, _univerjs_core.createIdentifier)("univer.formula.unit-reference-resolver");
|
|
10582
|
+
const EXCEL_WORKBOOK_EXTENSION = /\.(?:xlsx|xlsm|xlsb|xltx|xltm|xls)$/i;
|
|
10583
|
+
function normalizeFormulaUnitName(name) {
|
|
10584
|
+
return name.replace(EXCEL_WORKBOOK_EXTENSION, "").toLowerCase();
|
|
10585
|
+
}
|
|
10586
|
+
let FormulaUnitReferenceResolver = class FormulaUnitReferenceResolver {
|
|
10587
|
+
constructor(_currentConfigService) {
|
|
10588
|
+
this._currentConfigService = _currentConfigService;
|
|
10589
|
+
}
|
|
10590
|
+
resolve({ hostUnitId, qualifier, referenceKind }) {
|
|
10591
|
+
const unitNameMap = this._currentConfigService.getUnitNameMap();
|
|
10592
|
+
const unitData = this._currentConfigService.getUnitData();
|
|
10593
|
+
const address = qualifier || hostUnitId;
|
|
10594
|
+
const direct = unitNameMap[address];
|
|
10595
|
+
if (direct || unitData[address]) return this._validateReferenceKind(hostUnitId, referenceKind, {
|
|
10596
|
+
unitId: address,
|
|
10597
|
+
unitType: direct === null || direct === void 0 ? void 0 : direct.unitType
|
|
10598
|
+
}, unitNameMap);
|
|
10599
|
+
if (!qualifier) return "#REF!";
|
|
10600
|
+
const namedUnits = Object.entries(unitNameMap).filter(([, item]) => item.name.length > 0);
|
|
10601
|
+
const normalizedQualifier = qualifier.toLowerCase();
|
|
10602
|
+
const exactMatches = namedUnits.filter(([, item]) => item.name.toLowerCase() === normalizedQualifier);
|
|
10603
|
+
const matches = exactMatches.length > 0 ? exactMatches : namedUnits.filter(([, item]) => normalizeFormulaUnitName(item.name) === normalizeFormulaUnitName(qualifier));
|
|
10604
|
+
if (matches.length !== 1) return "#REF!";
|
|
10605
|
+
const [unitId, item] = matches[0];
|
|
10606
|
+
return this._validateReferenceKind(hostUnitId, referenceKind, {
|
|
10607
|
+
unitId,
|
|
10608
|
+
unitType: item.unitType
|
|
10609
|
+
}, unitNameMap);
|
|
10610
|
+
}
|
|
10611
|
+
_validateReferenceKind(hostUnitId, referenceKind, resolution, unitNameMap) {
|
|
10612
|
+
var _unitNameMap$hostUnit;
|
|
10613
|
+
if (referenceKind !== "a1" || resolution.unitId === hostUnitId) return resolution;
|
|
10614
|
+
const hostType = (_unitNameMap$hostUnit = unitNameMap[hostUnitId]) === null || _unitNameMap$hostUnit === void 0 ? void 0 : _unitNameMap$hostUnit.unitType;
|
|
10615
|
+
if (resolution.unitType === _univerjs_core.UniverInstanceType.UNIVER_BASE) return "#REF!";
|
|
10616
|
+
if (hostType === _univerjs_core.UniverInstanceType.UNIVER_BASE && resolution.unitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return "#REF!";
|
|
10617
|
+
return resolution;
|
|
10618
|
+
}
|
|
10619
|
+
};
|
|
10620
|
+
FormulaUnitReferenceResolver = __decorate([__decorateParam(0, IFormulaCurrentConfigService)], FormulaUnitReferenceResolver);
|
|
10621
|
+
|
|
10319
10622
|
//#endregion
|
|
10320
10623
|
//#region src/engine/ast-node/prefix-node.ts
|
|
10321
10624
|
var PrefixNode = class extends BaseAstNode {
|
|
@@ -10347,6 +10650,7 @@ var PrefixNode = class extends BaseAstNode {
|
|
|
10347
10650
|
if (!value.isReferenceObject()) return ErrorValueObject.create("#VALUE!");
|
|
10348
10651
|
const currentValue = value;
|
|
10349
10652
|
if (currentValue.isCell()) return ErrorValueObject.create("#VALUE!");
|
|
10653
|
+
if (this._preserveAtRangeForFormula2LookupArray()) return currentValue;
|
|
10350
10654
|
const runtimeService = this._runtimeService;
|
|
10351
10655
|
const currentRow = runtimeService.currentRow || 0;
|
|
10352
10656
|
const currentColumn = runtimeService.currentColumn || 0;
|
|
@@ -10358,6 +10662,22 @@ var PrefixNode = class extends BaseAstNode {
|
|
|
10358
10662
|
if (currentValue.isTable()) return currentValue.getCellByPosition(currentRow);
|
|
10359
10663
|
return ErrorValueObject.create("#VALUE!");
|
|
10360
10664
|
}
|
|
10665
|
+
_preserveAtRangeForFormula2LookupArray() {
|
|
10666
|
+
let node = this;
|
|
10667
|
+
let parent = node.getParent();
|
|
10668
|
+
let sawCompareOperator = false;
|
|
10669
|
+
while (parent != null) {
|
|
10670
|
+
if (parent.nodeType === 3) sawCompareOperator || (sawCompareOperator = OPERATOR_TOKEN_COMPARE_SET.has(parent.getToken()));
|
|
10671
|
+
if (parent.nodeType === 4) {
|
|
10672
|
+
const functionName = parent.getToken().toUpperCase();
|
|
10673
|
+
if (sawCompareOperator && functionName === "XMATCH") return parent.getChildren().indexOf(node) === 1;
|
|
10674
|
+
return false;
|
|
10675
|
+
}
|
|
10676
|
+
node = parent;
|
|
10677
|
+
parent = parent.getParent();
|
|
10678
|
+
}
|
|
10679
|
+
return false;
|
|
10680
|
+
}
|
|
10361
10681
|
};
|
|
10362
10682
|
let PrefixNodeFactory = class PrefixNodeFactory extends BaseAstNodeFactory {
|
|
10363
10683
|
constructor(_functionService, _runtimeService) {
|
|
@@ -10415,58 +10735,62 @@ function prefixHandler(tokenTrimParam, functionService, runtimeService) {
|
|
|
10415
10735
|
//#endregion
|
|
10416
10736
|
//#region src/engine/ast-node/function-node.ts
|
|
10417
10737
|
var FunctionNode = class extends BaseAstNode {
|
|
10418
|
-
constructor(token, _functionExecutor, _currentConfigService, _runtimeService, _definedNamesService, _formulaDataModel) {
|
|
10738
|
+
constructor(token, _functionExecutor, _currentConfigService, _runtimeService, _definedNamesService, _formulaDataModel, _unitReferenceResolver) {
|
|
10419
10739
|
super(token);
|
|
10420
10740
|
this._functionExecutor = _functionExecutor;
|
|
10421
10741
|
this._currentConfigService = _currentConfigService;
|
|
10422
10742
|
this._runtimeService = _runtimeService;
|
|
10423
10743
|
this._definedNamesService = _definedNamesService;
|
|
10424
10744
|
this._formulaDataModel = _formulaDataModel;
|
|
10745
|
+
this._unitReferenceResolver = _unitReferenceResolver;
|
|
10425
10746
|
if (this._functionExecutor.isAsync()) this.setAsync();
|
|
10426
10747
|
if (this._functionExecutor.isAddress()) this.setAddress();
|
|
10427
10748
|
if (this._functionExecutor.needsLocale) this._setLocale();
|
|
10428
10749
|
if (this._functionExecutor.needsSheetsInfo) this._setSheetsInfo();
|
|
10429
10750
|
if (this._functionExecutor.needsFormulaDataModel) this._functionExecutor.setFormulaDataModel(this._formulaDataModel);
|
|
10751
|
+
if (this._functionExecutor.needsUnitReferenceResolver) this._functionExecutor.setUnitReferenceResolver(this._unitReferenceResolver);
|
|
10430
10752
|
}
|
|
10431
10753
|
get nodeType() {
|
|
10432
10754
|
return 4;
|
|
10433
10755
|
}
|
|
10434
10756
|
async executeAsync() {
|
|
10435
|
-
const variants = [];
|
|
10436
10757
|
const children = this.getChildren();
|
|
10437
|
-
const childrenCount = children.length;
|
|
10438
10758
|
this._compatibility();
|
|
10439
|
-
|
|
10440
|
-
const object = children[i].getValue();
|
|
10441
|
-
if (object == null) continue;
|
|
10442
|
-
if (object.isReferenceObject() && !this._functionExecutor.needsReferenceObject) variants.push(object.toArrayValueObject());
|
|
10443
|
-
else variants.push(object);
|
|
10444
|
-
}
|
|
10445
|
-
const resultVariant = await this._calculateAsync(variants);
|
|
10759
|
+
const resultVariant = this._functionExecutor.needsAstChildren ? this._calculateAst(children) : await this._calculateAsync(this._collectVariants(children));
|
|
10446
10760
|
let result;
|
|
10447
10761
|
if (resultVariant.isAsyncObject() || resultVariant.isAsyncArrayObject()) result = await resultVariant.getValue();
|
|
10448
10762
|
else result = resultVariant;
|
|
10763
|
+
result = this._normalizeTopLevelLegacyArrayResult(result);
|
|
10449
10764
|
this._setEmbeddedArrayFormulaToResult(result);
|
|
10450
10765
|
this._setRefData(result);
|
|
10451
10766
|
this.setValue(result);
|
|
10452
10767
|
return Promise.resolve(0);
|
|
10453
10768
|
}
|
|
10454
10769
|
execute() {
|
|
10455
|
-
const variants = [];
|
|
10456
10770
|
const children = this.getChildren();
|
|
10457
|
-
const childrenCount = children.length;
|
|
10458
10771
|
this._compatibility();
|
|
10772
|
+
const resultVariant = this._functionExecutor.needsAstChildren ? this._calculateAst(children) : this._calculate(this._collectVariants(children));
|
|
10773
|
+
const result = this._normalizeTopLevelLegacyArrayResult(resultVariant);
|
|
10774
|
+
this._setEmbeddedArrayFormulaToResult(result);
|
|
10775
|
+
this._setRefData(result);
|
|
10776
|
+
this.setValue(result);
|
|
10777
|
+
}
|
|
10778
|
+
_collectVariants(children) {
|
|
10779
|
+
const variants = [];
|
|
10780
|
+
const childrenCount = children.length;
|
|
10459
10781
|
for (let i = 0; i < childrenCount; i++) {
|
|
10460
|
-
const object = children[i]
|
|
10782
|
+
const object = this._getChildVariant(children[i]);
|
|
10461
10783
|
if (object == null) continue;
|
|
10462
|
-
|
|
10463
|
-
if (object.isReferenceObject() && !this._functionExecutor.needsReferenceObject) variants.push(object.toArrayValueObject());
|
|
10464
|
-
else variants.push(object);
|
|
10784
|
+
variants.push(object);
|
|
10465
10785
|
}
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10786
|
+
return variants;
|
|
10787
|
+
}
|
|
10788
|
+
_getChildVariant(child) {
|
|
10789
|
+
const object = child.getValue();
|
|
10790
|
+
if (object == null) return;
|
|
10791
|
+
if (object.isReferenceObject() && this._functionExecutor.needsFilteredOutRows) this._setFilteredOutRows(object);
|
|
10792
|
+
if (object.isReferenceObject() && !this._functionExecutor.needsReferenceObject) return object.toArrayValueObject();
|
|
10793
|
+
return object;
|
|
10470
10794
|
}
|
|
10471
10795
|
isFunctionExecutorArgumentsIgnoreNumberPattern() {
|
|
10472
10796
|
return this._functionExecutor.isArgumentsIgnoreNumberPattern();
|
|
@@ -10481,6 +10805,14 @@ var FunctionNode = class extends BaseAstNode {
|
|
|
10481
10805
|
if (rowCount <= 1 && colCount <= 1) return;
|
|
10482
10806
|
this._runtimeService.setUnitArrayFormulaEmbeddedMap();
|
|
10483
10807
|
}
|
|
10808
|
+
_normalizeTopLevelLegacyArrayResult(result) {
|
|
10809
|
+
const parent = this.getParent();
|
|
10810
|
+
const isTopLevel = parent == null || parent.nodeType === 9;
|
|
10811
|
+
if (!this._functionExecutor.returnsLegacyArrayAsScalar || !isTopLevel || !result.isArray()) return result;
|
|
10812
|
+
const array = result;
|
|
10813
|
+
if (array.getRowCount() <= 1 && array.getColumnCount() <= 1) return result;
|
|
10814
|
+
return array.getFirstCell();
|
|
10815
|
+
}
|
|
10484
10816
|
/**
|
|
10485
10817
|
* Compatibility handling for special functions.
|
|
10486
10818
|
*/
|
|
@@ -10565,6 +10897,16 @@ var FunctionNode = class extends BaseAstNode {
|
|
|
10565
10897
|
}
|
|
10566
10898
|
return resultVariant;
|
|
10567
10899
|
}
|
|
10900
|
+
_calculateAst(children) {
|
|
10901
|
+
const { minParams, maxParams } = this._functionExecutor;
|
|
10902
|
+
if (minParams !== -1 && maxParams !== -1 && (children.length < minParams || children.length > maxParams)) return ErrorValueObject.create("#N/A");
|
|
10903
|
+
this._setRefInfo();
|
|
10904
|
+
this._handleAddressFunction();
|
|
10905
|
+
return this._functionExecutor.calculateAst(children, (node) => {
|
|
10906
|
+
var _this$_getChildVarian;
|
|
10907
|
+
return (_this$_getChildVarian = this._getChildVariant(node)) !== null && _this$_getChildVarian !== void 0 ? _this$_getChildVarian : null;
|
|
10908
|
+
});
|
|
10909
|
+
}
|
|
10568
10910
|
async _calculateAsync(variants) {
|
|
10569
10911
|
const { minParams, maxParams } = this._functionExecutor;
|
|
10570
10912
|
if (minParams !== -1 && maxParams !== -1 && (variants.length < minParams || variants.length > maxParams)) return ErrorValueObject.create("#N/A");
|
|
@@ -10580,15 +10922,15 @@ var FunctionNode = class extends BaseAstNode {
|
|
|
10580
10922
|
return resultVariant;
|
|
10581
10923
|
}
|
|
10582
10924
|
_setDefinedNamesForFunction() {
|
|
10583
|
-
const editorUnitId = this.
|
|
10925
|
+
const editorUnitId = this._runtimeService.currentUnitId;
|
|
10584
10926
|
if (editorUnitId == null) return;
|
|
10585
10927
|
const definedNames = this._definedNamesService.getDefinedNameMap(editorUnitId);
|
|
10586
10928
|
if (definedNames == null) return;
|
|
10587
10929
|
this._functionExecutor.setDefinedNames(definedNames);
|
|
10588
10930
|
}
|
|
10589
10931
|
_setRefInfo() {
|
|
10590
|
-
const { currentUnitId, currentSubUnitId, currentRow, currentColumn } = this._runtimeService;
|
|
10591
|
-
this._functionExecutor.setRefInfo(currentUnitId, currentSubUnitId, currentRow, currentColumn);
|
|
10932
|
+
const { currentUnitId, currentSubUnitId, currentRow, currentColumn, currentRowCount, currentColumnCount } = this._runtimeService;
|
|
10933
|
+
this._functionExecutor.setRefInfo(currentUnitId, currentSubUnitId, currentRow, currentColumn, currentRowCount, currentColumnCount);
|
|
10592
10934
|
if (this._functionExecutor.needsSheetRowColumnCount) {
|
|
10593
10935
|
const { rowCount, columnCount } = this._currentConfigService.getSheetRowColumnCount(currentUnitId, currentSubUnitId);
|
|
10594
10936
|
this._functionExecutor.setSheetRowColumnCount(rowCount, columnCount);
|
|
@@ -10634,7 +10976,7 @@ var ErrorFunctionNode = class extends BaseAstNode {
|
|
|
10634
10976
|
}
|
|
10635
10977
|
};
|
|
10636
10978
|
let FunctionNodeFactory = class FunctionNodeFactory extends BaseAstNodeFactory {
|
|
10637
|
-
constructor(_functionService, _currentConfigService, _runtimeService, _definedNamesService, _injector, _formulaDataModel) {
|
|
10979
|
+
constructor(_functionService, _currentConfigService, _runtimeService, _definedNamesService, _injector, _formulaDataModel, _unitReferenceResolver) {
|
|
10638
10980
|
super();
|
|
10639
10981
|
this._functionService = _functionService;
|
|
10640
10982
|
this._currentConfigService = _currentConfigService;
|
|
@@ -10642,6 +10984,7 @@ let FunctionNodeFactory = class FunctionNodeFactory extends BaseAstNodeFactory {
|
|
|
10642
10984
|
this._definedNamesService = _definedNamesService;
|
|
10643
10985
|
this._injector = _injector;
|
|
10644
10986
|
this._formulaDataModel = _formulaDataModel;
|
|
10987
|
+
this._unitReferenceResolver = _unitReferenceResolver;
|
|
10645
10988
|
}
|
|
10646
10989
|
get zIndex() {
|
|
10647
10990
|
return NODE_ORDER_MAP.get(4) || 100;
|
|
@@ -10652,14 +10995,14 @@ let FunctionNodeFactory = class FunctionNodeFactory extends BaseAstNodeFactory {
|
|
|
10652
10995
|
console.error(`No function ${token}`);
|
|
10653
10996
|
return ErrorNode.create("#NAME?");
|
|
10654
10997
|
}
|
|
10655
|
-
return new FunctionNode(token, functionExecutor, this._currentConfigService, this._runtimeService, this._definedNamesService, this._formulaDataModel);
|
|
10998
|
+
return new FunctionNode(token, functionExecutor, this._currentConfigService, this._runtimeService, this._definedNamesService, this._formulaDataModel, this._unitReferenceResolver);
|
|
10656
10999
|
}
|
|
10657
11000
|
checkAndCreateNodeType(param) {
|
|
10658
11001
|
if (typeof param === "string") return;
|
|
10659
11002
|
const { tokenTrim, minusPrefixNode, atPrefixNode } = prefixHandler(param.getToken().trim(), this._functionService, this._runtimeService);
|
|
10660
11003
|
const isColon = this._isParentUnionNode(param);
|
|
10661
11004
|
if (!Number.isNaN(Number(tokenTrim)) && !isColon) return ErrorNode.create("#VALUE!");
|
|
10662
|
-
const tokenTrimUpper = tokenTrim.toUpperCase();
|
|
11005
|
+
const tokenTrimUpper = normalizeFunctionToken(tokenTrim.toUpperCase());
|
|
10663
11006
|
if (isColon && COLUMN_LIKE_FUNCTION_NAMES.has(tokenTrimUpper)) return;
|
|
10664
11007
|
if (this._functionService.hasExecutor(tokenTrimUpper)) {
|
|
10665
11008
|
const functionNode = this.create(tokenTrimUpper);
|
|
@@ -10679,8 +11022,18 @@ FunctionNodeFactory = __decorate([
|
|
|
10679
11022
|
__decorateParam(2, IFormulaRuntimeService),
|
|
10680
11023
|
__decorateParam(3, IDefinedNamesService),
|
|
10681
11024
|
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
10682
|
-
__decorateParam(5, (0, _univerjs_core.Inject)(FormulaDataModel))
|
|
11025
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(FormulaDataModel)),
|
|
11026
|
+
__decorateParam(6, IFormulaUnitReferenceResolver)
|
|
10683
11027
|
], FunctionNodeFactory);
|
|
11028
|
+
function normalizeFunctionToken(token) {
|
|
11029
|
+
if (token === "REGEXTEST" || token === "_XLFN.REGEXTEST") return "REGEXMATCH";
|
|
11030
|
+
for (const prefix of [
|
|
11031
|
+
"_XLFN.",
|
|
11032
|
+
"_XLWS.",
|
|
11033
|
+
"_XLETA."
|
|
11034
|
+
]) if (token.startsWith(prefix)) return token.slice(prefix.length);
|
|
11035
|
+
return token;
|
|
11036
|
+
}
|
|
10684
11037
|
|
|
10685
11038
|
//#endregion
|
|
10686
11039
|
//#region src/engine/interpreter/interpreter.ts
|
|
@@ -10731,6 +11084,7 @@ let Interpreter = class Interpreter extends _univerjs_core.Disposable {
|
|
|
10731
11084
|
}
|
|
10732
11085
|
async _executeAsync(node, refOffsetX = 0, refOffsetY = 0) {
|
|
10733
11086
|
if (this._runtimeService.isStopExecution()) return Promise.resolve(1);
|
|
11087
|
+
if (await this._executeLazyFunctionAsync(node, refOffsetX, refOffsetY)) return Promise.resolve(0);
|
|
10734
11088
|
const children = node.getChildren();
|
|
10735
11089
|
const childrenCount = children.length;
|
|
10736
11090
|
for (let i = 0; i < childrenCount; i++) {
|
|
@@ -10751,6 +11105,7 @@ let Interpreter = class Interpreter extends _univerjs_core.Disposable {
|
|
|
10751
11105
|
}
|
|
10752
11106
|
_execute(node, refOffsetX = 0, refOffsetY = 0) {
|
|
10753
11107
|
if (this._runtimeService.isStopExecution()) return 1;
|
|
11108
|
+
if (this._executeLazyFunction(node, refOffsetX, refOffsetY)) return 0;
|
|
10754
11109
|
const children = node.getChildren();
|
|
10755
11110
|
const childrenCount = children.length;
|
|
10756
11111
|
for (let i = 0; i < childrenCount; i++) {
|
|
@@ -10768,6 +11123,161 @@ let Interpreter = class Interpreter extends _univerjs_core.Disposable {
|
|
|
10768
11123
|
node.execute();
|
|
10769
11124
|
return 0;
|
|
10770
11125
|
}
|
|
11126
|
+
async _executeLazyFunctionAsync(node, refOffsetX, refOffsetY) {
|
|
11127
|
+
if (node.nodeType !== 4) return false;
|
|
11128
|
+
const token = node.getToken().toUpperCase();
|
|
11129
|
+
if (token === "IF") return await this._executeLazyIfAsync(node, refOffsetX, refOffsetY);
|
|
11130
|
+
if (token === "IFERROR") return await this._executeLazyIfErrorAsync(node, refOffsetX, refOffsetY);
|
|
11131
|
+
return false;
|
|
11132
|
+
}
|
|
11133
|
+
_executeLazyFunction(node, refOffsetX, refOffsetY) {
|
|
11134
|
+
if (node.nodeType !== 4) return false;
|
|
11135
|
+
const token = node.getToken().toUpperCase();
|
|
11136
|
+
if (token === "IF") return this._executeLazyIf(node, refOffsetX, refOffsetY);
|
|
11137
|
+
if (token === "IFERROR") return this._executeLazyIfError(node, refOffsetX, refOffsetY);
|
|
11138
|
+
return false;
|
|
11139
|
+
}
|
|
11140
|
+
async _executeLazyIfAsync(node, refOffsetX, refOffsetY) {
|
|
11141
|
+
const children = node.getChildren();
|
|
11142
|
+
if (children.length < 2 || children.length > 3) return false;
|
|
11143
|
+
await this._executeAsync(children[0], refOffsetX, refOffsetY);
|
|
11144
|
+
const condition = children[0].getValue();
|
|
11145
|
+
if (condition == null || condition.isReferenceObject() || condition.isArray()) return false;
|
|
11146
|
+
if (condition.isError()) {
|
|
11147
|
+
node.setValue(condition);
|
|
11148
|
+
return true;
|
|
11149
|
+
}
|
|
11150
|
+
const selected = condition.getValue() ? children[1] : children[2];
|
|
11151
|
+
if (selected == null) {
|
|
11152
|
+
node.setValue(BooleanValueObject.create(false));
|
|
11153
|
+
return true;
|
|
11154
|
+
}
|
|
11155
|
+
await this._executeAsync(selected, refOffsetX, refOffsetY);
|
|
11156
|
+
node.setValue(this._toLazyIfSelectedValue(selected.getValue(), node));
|
|
11157
|
+
return true;
|
|
11158
|
+
}
|
|
11159
|
+
_executeLazyIf(node, refOffsetX, refOffsetY) {
|
|
11160
|
+
const children = node.getChildren();
|
|
11161
|
+
if (children.length < 2 || children.length > 3) return false;
|
|
11162
|
+
this._execute(children[0], refOffsetX, refOffsetY);
|
|
11163
|
+
const condition = children[0].getValue();
|
|
11164
|
+
if (condition == null || condition.isReferenceObject() || condition.isArray()) return false;
|
|
11165
|
+
if (condition.isError()) {
|
|
11166
|
+
node.setValue(condition);
|
|
11167
|
+
return true;
|
|
11168
|
+
}
|
|
11169
|
+
const selected = condition.getValue() ? children[1] : children[2];
|
|
11170
|
+
if (selected == null) {
|
|
11171
|
+
node.setValue(BooleanValueObject.create(false));
|
|
11172
|
+
return true;
|
|
11173
|
+
}
|
|
11174
|
+
this._execute(selected, refOffsetX, refOffsetY);
|
|
11175
|
+
node.setValue(this._toLazyIfSelectedValue(selected.getValue(), node));
|
|
11176
|
+
return true;
|
|
11177
|
+
}
|
|
11178
|
+
async _executeLazyIfErrorAsync(node, refOffsetX, refOffsetY) {
|
|
11179
|
+
var _children$1$getValue;
|
|
11180
|
+
const children = node.getChildren();
|
|
11181
|
+
if (children.length !== 2) return false;
|
|
11182
|
+
await this._executeAsync(children[0], refOffsetX, refOffsetY);
|
|
11183
|
+
const rawValue = children[0].getValue();
|
|
11184
|
+
const value = this._toLazyIfErrorValue(rawValue);
|
|
11185
|
+
if (value == null || value.isArray()) return false;
|
|
11186
|
+
if (!value.isError()) {
|
|
11187
|
+
node.setValue(value);
|
|
11188
|
+
return true;
|
|
11189
|
+
}
|
|
11190
|
+
await this._executeAsync(children[1], refOffsetX, refOffsetY);
|
|
11191
|
+
node.setValue((_children$1$getValue = children[1].getValue()) !== null && _children$1$getValue !== void 0 ? _children$1$getValue : ErrorValueObject.create("#VALUE!"));
|
|
11192
|
+
return true;
|
|
11193
|
+
}
|
|
11194
|
+
_executeLazyIfError(node, refOffsetX, refOffsetY) {
|
|
11195
|
+
var _children$1$getValue2;
|
|
11196
|
+
const children = node.getChildren();
|
|
11197
|
+
if (children.length !== 2) return false;
|
|
11198
|
+
this._execute(children[0], refOffsetX, refOffsetY);
|
|
11199
|
+
const rawValue = children[0].getValue();
|
|
11200
|
+
const value = this._toLazyIfErrorValue(rawValue);
|
|
11201
|
+
if (value == null || value.isArray()) return false;
|
|
11202
|
+
if (!value.isError()) {
|
|
11203
|
+
node.setValue(value);
|
|
11204
|
+
return true;
|
|
11205
|
+
}
|
|
11206
|
+
this._execute(children[1], refOffsetX, refOffsetY);
|
|
11207
|
+
node.setValue((_children$1$getValue2 = children[1].getValue()) !== null && _children$1$getValue2 !== void 0 ? _children$1$getValue2 : ErrorValueObject.create("#VALUE!"));
|
|
11208
|
+
return true;
|
|
11209
|
+
}
|
|
11210
|
+
_toLazyIfErrorValue(value) {
|
|
11211
|
+
if (value == null) return null;
|
|
11212
|
+
if (!value.isReferenceObject()) {
|
|
11213
|
+
const baseValue = value;
|
|
11214
|
+
return baseValue.isNull() ? NumberValueObject.create(0) : baseValue;
|
|
11215
|
+
}
|
|
11216
|
+
const reference = value;
|
|
11217
|
+
if (reference.getRowCount() !== 1 || reference.getColumnCount() !== 1) return reference.toArrayValueObject();
|
|
11218
|
+
const cellValue = reference.getCellByPosition();
|
|
11219
|
+
return cellValue.isNull() ? NumberValueObject.create(0) : cellValue;
|
|
11220
|
+
}
|
|
11221
|
+
_toLazyIfSelectedValue(value, node) {
|
|
11222
|
+
if (value == null) return ErrorValueObject.create("#VALUE!");
|
|
11223
|
+
if (value.isReferenceObject()) {
|
|
11224
|
+
const reference = value;
|
|
11225
|
+
if (this._preserveLazyIfSelectedReferenceArray(node)) return reference.toArrayValueObject();
|
|
11226
|
+
value = this._implicitLazyIfReferenceValue(reference);
|
|
11227
|
+
}
|
|
11228
|
+
if (value.isArray()) value = this._implicitLazyIfArrayValue(value);
|
|
11229
|
+
if (!value.isArray()) {
|
|
11230
|
+
const baseValue = value;
|
|
11231
|
+
return baseValue.isNull() ? NumberValueObject.create(0) : baseValue;
|
|
11232
|
+
}
|
|
11233
|
+
return value;
|
|
11234
|
+
}
|
|
11235
|
+
_implicitLazyIfReferenceValue(reference) {
|
|
11236
|
+
const range = reference.getRangePosition();
|
|
11237
|
+
const currentRow = this._runtimeService.currentRow || 0;
|
|
11238
|
+
const currentColumn = this._runtimeService.currentColumn || 0;
|
|
11239
|
+
const { startRow, startColumn, endRow, endColumn } = range;
|
|
11240
|
+
if (startRow === endRow && startColumn === endColumn) return reference.getCellByPosition();
|
|
11241
|
+
if (endRow === startRow && currentColumn >= startColumn && currentColumn <= endColumn) return reference.getCellByColumn(currentColumn);
|
|
11242
|
+
if (startColumn === endColumn && currentRow >= startRow && currentRow <= endRow) return reference.getCellByRow(currentRow);
|
|
11243
|
+
return ErrorValueObject.create("#VALUE!");
|
|
11244
|
+
}
|
|
11245
|
+
_preserveLazyIfSelectedReferenceArray(node) {
|
|
11246
|
+
let child = node;
|
|
11247
|
+
let parent = child.getParent();
|
|
11248
|
+
while (parent != null) {
|
|
11249
|
+
if (parent.nodeType === 4) return parent.getToken().toUpperCase() === "MATCH" && parent.getChildren().indexOf(child) === 1;
|
|
11250
|
+
child = parent;
|
|
11251
|
+
parent = parent.getParent();
|
|
11252
|
+
}
|
|
11253
|
+
return false;
|
|
11254
|
+
}
|
|
11255
|
+
_implicitLazyIfArrayValue(array) {
|
|
11256
|
+
if (array.getUnitId() === "" || array.getSheetId() === "" || array.getCurrentRow() < 0 || array.getCurrentColumn() < 0) return array;
|
|
11257
|
+
const startRow = array.getCurrentRow();
|
|
11258
|
+
const startColumn = array.getCurrentColumn();
|
|
11259
|
+
const rowCount = array.getRowCount();
|
|
11260
|
+
const columnCount = array.getColumnCount();
|
|
11261
|
+
const currentRow = this._runtimeService.currentRow || 0;
|
|
11262
|
+
const currentColumn = this._runtimeService.currentColumn || 0;
|
|
11263
|
+
let rowIndex = -1;
|
|
11264
|
+
let columnIndex = -1;
|
|
11265
|
+
if (rowCount === 1 && columnCount === 1) {
|
|
11266
|
+
rowIndex = 0;
|
|
11267
|
+
columnIndex = 0;
|
|
11268
|
+
} else if (rowCount === 1) {
|
|
11269
|
+
rowIndex = 0;
|
|
11270
|
+
columnIndex = currentColumn - startColumn;
|
|
11271
|
+
} else if (columnCount === 1) {
|
|
11272
|
+
rowIndex = currentRow - startRow;
|
|
11273
|
+
columnIndex = 0;
|
|
11274
|
+
} else {
|
|
11275
|
+
rowIndex = currentRow - startRow;
|
|
11276
|
+
columnIndex = currentColumn - startColumn;
|
|
11277
|
+
}
|
|
11278
|
+
if (rowIndex < 0 || rowIndex >= rowCount || columnIndex < 0 || columnIndex >= columnCount) return ErrorValueObject.create("#VALUE!");
|
|
11279
|
+
return array.get(rowIndex, columnIndex) || ErrorValueObject.create("#VALUE!");
|
|
11280
|
+
}
|
|
10771
11281
|
};
|
|
10772
11282
|
Interpreter = __decorate([__decorateParam(0, IFormulaRuntimeService)], Interpreter);
|
|
10773
11283
|
|
|
@@ -10986,9 +11496,10 @@ let LambdaNodeFactory = class LambdaNodeFactory extends BaseAstNodeFactory {
|
|
|
10986
11496
|
for (let i = 0; i < parameterArray.length; i++) {
|
|
10987
11497
|
const parameter = parameterArray[i];
|
|
10988
11498
|
if (parameter instanceof LexerNode) {
|
|
10989
|
-
const variant = parameter
|
|
11499
|
+
const variant = getLambdaParameterName(parameter);
|
|
11500
|
+
if (variant == null) return ErrorNode.create("#VALUE!");
|
|
10990
11501
|
parameter.setToken(DEFAULT_TOKEN_TYPE_LAMBDA_OMIT_PARAMETER);
|
|
10991
|
-
currentLambdaPrivacyVar.set(variant
|
|
11502
|
+
currentLambdaPrivacyVar.set(variant, void 0);
|
|
10992
11503
|
} else return ErrorNode.create("#VALUE!");
|
|
10993
11504
|
}
|
|
10994
11505
|
this._runtimeService.registerFunctionDefinitionPrivacyVar(lambdaId, currentLambdaPrivacyVar);
|
|
@@ -11005,6 +11516,20 @@ let LambdaNodeFactory = class LambdaNodeFactory extends BaseAstNodeFactory {
|
|
|
11005
11516
|
}
|
|
11006
11517
|
};
|
|
11007
11518
|
LambdaNodeFactory = __decorate([__decorateParam(0, IFormulaRuntimeService), __decorateParam(1, (0, _univerjs_core.Inject)(Interpreter))], LambdaNodeFactory);
|
|
11519
|
+
function getLambdaParameterName(parameter) {
|
|
11520
|
+
const children = parameter.getChildren();
|
|
11521
|
+
for (let i = 0; i < children.length; i++) {
|
|
11522
|
+
const child = children[i];
|
|
11523
|
+
if (typeof child === "string") {
|
|
11524
|
+
const token = child.trim();
|
|
11525
|
+
if (token.length > 0) return token;
|
|
11526
|
+
} else {
|
|
11527
|
+
const token = getLambdaParameterName(child);
|
|
11528
|
+
if (token != null) return token;
|
|
11529
|
+
}
|
|
11530
|
+
}
|
|
11531
|
+
return null;
|
|
11532
|
+
}
|
|
11008
11533
|
|
|
11009
11534
|
//#endregion
|
|
11010
11535
|
//#region src/engine/ast-node/lambda-parameter-node.ts
|
|
@@ -11115,12 +11640,17 @@ var OperatorNode = class extends BaseAstNode {
|
|
|
11115
11640
|
}
|
|
11116
11641
|
if (object1 == null) object1 = NullValueObject.create();
|
|
11117
11642
|
if (object2 == null) object2 = NullValueObject.create();
|
|
11118
|
-
if (object1.isReferenceObject()) object1 =
|
|
11119
|
-
if (object2.isReferenceObject()) object2 =
|
|
11643
|
+
if (object1.isReferenceObject()) object1 = this._referenceToOperatorValue(object1);
|
|
11644
|
+
if (object2.isReferenceObject()) object2 = this._referenceToOperatorValue(object2);
|
|
11120
11645
|
const result = this._functionExecutor.calculate(object1, object2);
|
|
11121
11646
|
this._setEmbeddedArrayFormulaToResult(result);
|
|
11122
11647
|
this.setValue(result);
|
|
11123
11648
|
}
|
|
11649
|
+
_referenceToOperatorValue(reference) {
|
|
11650
|
+
const array = reference.toArrayValueObject();
|
|
11651
|
+
if (array.getRowCount() === 1 && array.getColumnCount() === 1) return array.get(0, 0);
|
|
11652
|
+
return array;
|
|
11653
|
+
}
|
|
11124
11654
|
/**
|
|
11125
11655
|
* If it contains an array formula, set the current cell to the cache and send itself as a ref outward
|
|
11126
11656
|
*/
|
|
@@ -11197,6 +11727,7 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11197
11727
|
const { startColumn, endColumn, type } = this._parseStructuredRef(this._columnDataString, titleMap);
|
|
11198
11728
|
const tableStartRow = range.startRow;
|
|
11199
11729
|
const tableEndRow = range.endRow;
|
|
11730
|
+
const dataStartRow = tableStartRow + (this._tableData.showHeader === false ? 0 : 1);
|
|
11200
11731
|
let startRow = -1;
|
|
11201
11732
|
let endRow = -1;
|
|
11202
11733
|
switch (type) {
|
|
@@ -11205,10 +11736,15 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11205
11736
|
endRow = tableEndRow;
|
|
11206
11737
|
break;
|
|
11207
11738
|
case "#Data":
|
|
11208
|
-
startRow =
|
|
11739
|
+
startRow = dataStartRow;
|
|
11209
11740
|
endRow = tableEndRow;
|
|
11210
11741
|
break;
|
|
11211
11742
|
case "#Headers":
|
|
11743
|
+
if (this._tableData.showHeader === false) {
|
|
11744
|
+
startRow = -1;
|
|
11745
|
+
endRow = -1;
|
|
11746
|
+
break;
|
|
11747
|
+
}
|
|
11212
11748
|
startRow = tableStartRow;
|
|
11213
11749
|
endRow = tableStartRow;
|
|
11214
11750
|
break;
|
|
@@ -11223,7 +11759,7 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11223
11759
|
break;
|
|
11224
11760
|
}
|
|
11225
11761
|
default:
|
|
11226
|
-
startRow =
|
|
11762
|
+
startRow = dataStartRow;
|
|
11227
11763
|
endRow = tableEndRow;
|
|
11228
11764
|
break;
|
|
11229
11765
|
}
|
|
@@ -11248,6 +11784,13 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11248
11784
|
}
|
|
11249
11785
|
return rangeData;
|
|
11250
11786
|
}
|
|
11787
|
+
getCellData(row, column) {
|
|
11788
|
+
if (this._isCurrentRowForRange) {
|
|
11789
|
+
const { startRow, endRow } = this._tableData.range;
|
|
11790
|
+
if (row < startRow || row > endRow) return { v: "#N/A" };
|
|
11791
|
+
}
|
|
11792
|
+
return super.getCellData(row, column);
|
|
11793
|
+
}
|
|
11251
11794
|
getRefOffset() {
|
|
11252
11795
|
return {
|
|
11253
11796
|
x: 0,
|
|
@@ -11424,12 +11967,15 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11424
11967
|
}
|
|
11425
11968
|
/** Column title → column index; returns -1 if not found (caller should handle as parse error) */
|
|
11426
11969
|
_titleToIndex(name, titleMap) {
|
|
11427
|
-
var _titleMap$get;
|
|
11428
11970
|
const key = name.trim();
|
|
11429
11971
|
const hit = titleMap.get(key);
|
|
11430
11972
|
if (hit !== void 0) return hit;
|
|
11431
11973
|
const keyNorm = key.replace(/\u3000/g, " ").trim();
|
|
11432
|
-
|
|
11974
|
+
const normalizedHit = titleMap.get(keyNorm);
|
|
11975
|
+
if (normalizedHit !== void 0) return normalizedHit;
|
|
11976
|
+
const lineBreakNorm = keyNorm.replace(/\r\n?/g, "\n");
|
|
11977
|
+
for (const [title, index] of titleMap.entries()) if (title.replace(/\u3000/g, " ").trim().replace(/\r\n?/g, "\n") === lineBreakNorm) return index;
|
|
11978
|
+
return -1;
|
|
11433
11979
|
}
|
|
11434
11980
|
/** Resolve #This Row's row number; takes first data row (tableStartRow+1) when no context available */
|
|
11435
11981
|
_resolveThisRow(tableStartRow, tableEndRow) {
|
|
@@ -11441,13 +11987,15 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11441
11987
|
//#endregion
|
|
11442
11988
|
//#region src/engine/ast-node/reference-node.ts
|
|
11443
11989
|
var ReferenceNode = class extends BaseAstNode {
|
|
11444
|
-
constructor(_currentConfigService, _runtimeService, operatorString, _referenceObjectType, _isPrepareMerge = false,
|
|
11990
|
+
constructor(_currentConfigService, _runtimeService, operatorString, _referenceObjectType, _unitReferenceResolver, _superTableService, _isPrepareMerge = false, _tableReference) {
|
|
11445
11991
|
super(operatorString);
|
|
11446
11992
|
this._currentConfigService = _currentConfigService;
|
|
11447
11993
|
this._runtimeService = _runtimeService;
|
|
11448
11994
|
this._referenceObjectType = _referenceObjectType;
|
|
11995
|
+
this._unitReferenceResolver = _unitReferenceResolver;
|
|
11996
|
+
this._superTableService = _superTableService;
|
|
11449
11997
|
this._isPrepareMerge = _isPrepareMerge;
|
|
11450
|
-
this.
|
|
11998
|
+
this._tableReference = _tableReference;
|
|
11451
11999
|
_defineProperty(this, "_refOffsetX", 0);
|
|
11452
12000
|
_defineProperty(this, "_refOffsetY", 0);
|
|
11453
12001
|
}
|
|
@@ -11457,7 +12005,49 @@ var ReferenceNode = class extends BaseAstNode {
|
|
|
11457
12005
|
execute() {
|
|
11458
12006
|
const currentConfigService = this._currentConfigService;
|
|
11459
12007
|
const runtimeService = this._runtimeService;
|
|
11460
|
-
|
|
12008
|
+
let referenceObject;
|
|
12009
|
+
if (this._tableReference) {
|
|
12010
|
+
var _Array$from$find;
|
|
12011
|
+
const { unitQualifier, tableName, columnStruct } = this._tableReference;
|
|
12012
|
+
const resolution = this._unitReferenceResolver.resolve({
|
|
12013
|
+
hostUnitId: runtimeService.currentUnitId,
|
|
12014
|
+
qualifier: unitQualifier,
|
|
12015
|
+
referenceKind: "table"
|
|
12016
|
+
});
|
|
12017
|
+
if (typeof resolution === "string") {
|
|
12018
|
+
this.setValue(ErrorValueObject.create(resolution));
|
|
12019
|
+
return;
|
|
12020
|
+
}
|
|
12021
|
+
const tableMap = this._superTableService.getTableMap(resolution.unitId);
|
|
12022
|
+
const tableData = (_Array$from$find = Array.from((tableMap === null || tableMap === void 0 ? void 0 : tableMap.entries()) || []).find(([name]) => name.toLocaleLowerCase() === tableName.toLocaleLowerCase())) === null || _Array$from$find === void 0 ? void 0 : _Array$from$find[1];
|
|
12023
|
+
if (!tableData) {
|
|
12024
|
+
this.setValue(ErrorValueObject.create("#REF!"));
|
|
12025
|
+
return;
|
|
12026
|
+
}
|
|
12027
|
+
referenceObject = new TableReferenceObject(this.getToken(), tableData, columnStruct, this._superTableService.getTableOptionMap());
|
|
12028
|
+
referenceObject.setUnitQualifier(unitQualifier);
|
|
12029
|
+
referenceObject.setForcedUnitIdDirect(resolution.unitId);
|
|
12030
|
+
} else {
|
|
12031
|
+
referenceObject = getReferenceObjectFromCache(this.getToken(), this._referenceObjectType);
|
|
12032
|
+
const unitQualifier = referenceObject.getUnitQualifier();
|
|
12033
|
+
if (unitQualifier) {
|
|
12034
|
+
const resolution = this._unitReferenceResolver.resolve({
|
|
12035
|
+
hostUnitId: runtimeService.currentUnitId,
|
|
12036
|
+
qualifier: unitQualifier,
|
|
12037
|
+
referenceKind: "a1"
|
|
12038
|
+
});
|
|
12039
|
+
if (typeof resolution === "string") {
|
|
12040
|
+
this.setValue(ErrorValueObject.create(resolution));
|
|
12041
|
+
return;
|
|
12042
|
+
}
|
|
12043
|
+
referenceObject.setForcedUnitIdDirect(resolution.unitId);
|
|
12044
|
+
}
|
|
12045
|
+
}
|
|
12046
|
+
this._configureReferenceObject(referenceObject, currentConfigService, runtimeService);
|
|
12047
|
+
if (!this._isPrepareMerge && referenceObject.isExceedRange()) this.setValue(ErrorValueObject.create("#NAME?"));
|
|
12048
|
+
else this.setValue(referenceObject);
|
|
12049
|
+
}
|
|
12050
|
+
_configureReferenceObject(referenceObject, currentConfigService, runtimeService) {
|
|
11461
12051
|
referenceObject.setDefaultUnitId(runtimeService.currentUnitId);
|
|
11462
12052
|
referenceObject.setDefaultSheetId(runtimeService.currentSubUnitId);
|
|
11463
12053
|
referenceObject.setForcedSheetId(currentConfigService.getSheetNameMap());
|
|
@@ -11469,13 +12059,9 @@ var ReferenceNode = class extends BaseAstNode {
|
|
|
11469
12059
|
referenceObject.setRuntimeArrayFormulaCellData(runtimeService.getRuntimeArrayFormulaCellData());
|
|
11470
12060
|
referenceObject.setRuntimeArrayFormulaRange(runtimeService.getUnitArrayFormula());
|
|
11471
12061
|
referenceObject.setRuntimeFeatureCellData(runtimeService.getRuntimeFeatureCellData());
|
|
11472
|
-
|
|
11473
|
-
const currentCol = runtimeService.currentColumn;
|
|
11474
|
-
referenceObject.setCurrentRowAndColumn(currentRow, currentCol);
|
|
12062
|
+
referenceObject.setCurrentRowAndColumn(runtimeService.currentRow, runtimeService.currentColumn);
|
|
11475
12063
|
const { x, y } = this.getRefOffset();
|
|
11476
12064
|
referenceObject.setRefOffset(x, y);
|
|
11477
|
-
if (!this._isPrepareMerge && referenceObject.isExceedRange()) this.setValue(ErrorValueObject.create("#NAME?"));
|
|
11478
|
-
else this.setValue(referenceObject);
|
|
11479
12065
|
}
|
|
11480
12066
|
setRefOffset(x = 0, y = 0) {
|
|
11481
12067
|
this._refOffsetX = x;
|
|
@@ -11489,12 +12075,13 @@ var ReferenceNode = class extends BaseAstNode {
|
|
|
11489
12075
|
}
|
|
11490
12076
|
};
|
|
11491
12077
|
let ReferenceNodeFactory = class ReferenceNodeFactory extends BaseAstNodeFactory {
|
|
11492
|
-
constructor(_currentConfigService, _formulaRuntimeService, _functionService, _superTableService) {
|
|
12078
|
+
constructor(_currentConfigService, _formulaRuntimeService, _functionService, _superTableService, _unitReferenceResolver) {
|
|
11493
12079
|
super();
|
|
11494
12080
|
this._currentConfigService = _currentConfigService;
|
|
11495
12081
|
this._formulaRuntimeService = _formulaRuntimeService;
|
|
11496
12082
|
this._functionService = _functionService;
|
|
11497
12083
|
this._superTableService = _superTableService;
|
|
12084
|
+
this._unitReferenceResolver = _unitReferenceResolver;
|
|
11498
12085
|
}
|
|
11499
12086
|
get zIndex() {
|
|
11500
12087
|
return NODE_ORDER_MAP.get(1) || 100;
|
|
@@ -11523,7 +12110,7 @@ let ReferenceNodeFactory = class ReferenceNodeFactory extends BaseAstNodeFactory
|
|
|
11523
12110
|
}
|
|
11524
12111
|
}
|
|
11525
12112
|
_getTableMap() {
|
|
11526
|
-
const unitId = this.
|
|
12113
|
+
const unitId = this._formulaRuntimeService.currentUnitId;
|
|
11527
12114
|
if (!unitId) return;
|
|
11528
12115
|
return this._superTableService.getTableMap(unitId);
|
|
11529
12116
|
}
|
|
@@ -11531,25 +12118,25 @@ let ReferenceNodeFactory = class ReferenceNodeFactory extends BaseAstNodeFactory
|
|
|
11531
12118
|
var _tableMap$has;
|
|
11532
12119
|
const currentConfigService = this._currentConfigService;
|
|
11533
12120
|
const runtimeService = this._formulaRuntimeService;
|
|
11534
|
-
const makeRef = (type) => new ReferenceNode(currentConfigService, runtimeService, tokenTrim, type, isPrepareMerge);
|
|
12121
|
+
const makeRef = (type) => new ReferenceNode(currentConfigService, runtimeService, tokenTrim, type, this._unitReferenceResolver, this._superTableService, isPrepareMerge);
|
|
11535
12122
|
const tableMap = this._getTableMap();
|
|
11536
|
-
if ((_tableMap$has = tableMap === null || tableMap === void 0 ? void 0 : tableMap.has(tokenTrim)) !== null && _tableMap$has !== void 0 ? _tableMap$has : false) return this._getTableReferenceNode(tokenTrim,
|
|
12123
|
+
if ((_tableMap$has = tableMap === null || tableMap === void 0 ? void 0 : tableMap.has(tokenTrim)) !== null && _tableMap$has !== void 0 ? _tableMap$has : false) return this._getTableReferenceNode(tokenTrim, isPrepareMerge, true);
|
|
11537
12124
|
if (regexTestSingeRange(tokenTrim)) return makeRef(0);
|
|
11538
12125
|
const parentIsUnion = isLexerNode && this._checkParentIsUnionOperator(param);
|
|
11539
12126
|
if (parentIsUnion && regexTestSingleRow(tokenTrim)) return makeRef(2);
|
|
11540
12127
|
if (parentIsUnion && regexTestSingleColumn(tokenTrim)) return makeRef(1);
|
|
11541
|
-
return this._getTableReferenceNode(tokenTrim,
|
|
12128
|
+
return this._getTableReferenceNode(tokenTrim, isPrepareMerge, false);
|
|
11542
12129
|
}
|
|
11543
|
-
_getTableReferenceNode(tokenTrim,
|
|
12130
|
+
_getTableReferenceNode(tokenTrim, isPrepareMerge, isSuperTableDirectly = false) {
|
|
11544
12131
|
if (!this._checkTokenIsTableReference(tokenTrim) && !isSuperTableDirectly) return;
|
|
11545
|
-
const { tableName, columnStruct } = splitTableStructuredRef(tokenTrim);
|
|
12132
|
+
const { unitQualifier, tableName, columnStruct } = splitTableStructuredRef(tokenTrim);
|
|
11546
12133
|
const tableMap = this._getTableMap();
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11552
|
-
}
|
|
12134
|
+
const hasLocalTable = Array.from((tableMap === null || tableMap === void 0 ? void 0 : tableMap.keys()) || []).some((name) => name.toLocaleLowerCase() === tableName.toLocaleLowerCase());
|
|
12135
|
+
if (unitQualifier || hasLocalTable) return new ReferenceNode(this._currentConfigService, this._formulaRuntimeService, tokenTrim, 1, this._unitReferenceResolver, this._superTableService, isPrepareMerge, {
|
|
12136
|
+
unitQualifier,
|
|
12137
|
+
tableName,
|
|
12138
|
+
columnStruct
|
|
12139
|
+
});
|
|
11553
12140
|
}
|
|
11554
12141
|
_checkTokenIsTableReference(token) {
|
|
11555
12142
|
return regexTestReferenceTableAllColumn(token) || regexTestReferenceTableSingleColumn(token) || regexTestReferenceTableMultipleColumn(token) || regexTestReferenceTableTitleOnlyAnyHash(token);
|
|
@@ -11563,7 +12150,8 @@ ReferenceNodeFactory = __decorate([
|
|
|
11563
12150
|
__decorateParam(0, IFormulaCurrentConfigService),
|
|
11564
12151
|
__decorateParam(1, IFormulaRuntimeService),
|
|
11565
12152
|
__decorateParam(2, IFunctionService),
|
|
11566
|
-
__decorateParam(3, ISuperTableService)
|
|
12153
|
+
__decorateParam(3, ISuperTableService),
|
|
12154
|
+
__decorateParam(4, IFormulaUnitReferenceResolver)
|
|
11567
12155
|
], ReferenceNodeFactory);
|
|
11568
12156
|
|
|
11569
12157
|
//#endregion
|
|
@@ -11609,7 +12197,7 @@ var SuffixNode = class extends BaseAstNode {
|
|
|
11609
12197
|
const formulaData = this._currentConfigService.getFormulaData();
|
|
11610
12198
|
const formulaString = formulaData === null || formulaData === void 0 || (_formulaData$unitId = formulaData[unitId]) === null || _formulaData$unitId === void 0 || (_formulaData$unitId = _formulaData$unitId[sheetId]) === null || _formulaData$unitId === void 0 || (_formulaData$unitId = _formulaData$unitId[range.startRow]) === null || _formulaData$unitId === void 0 || (_formulaData$unitId = _formulaData$unitId[range.startColumn]) === null || _formulaData$unitId === void 0 ? void 0 : _formulaData$unitId.f;
|
|
11611
12199
|
if (!formulaString) return ErrorValueObject.create("#VALUE!");
|
|
11612
|
-
this._lexer.treeBuilder(formulaString);
|
|
12200
|
+
this._lexer.treeBuilder(formulaString, true, unitId);
|
|
11613
12201
|
return ErrorValueObject.create("#VALUE!");
|
|
11614
12202
|
/** todo */
|
|
11615
12203
|
}
|
|
@@ -11710,13 +12298,19 @@ var ValueNode = class extends BaseAstNode {
|
|
|
11710
12298
|
return 2;
|
|
11711
12299
|
}
|
|
11712
12300
|
execute() {
|
|
12301
|
+
const token = this.getToken();
|
|
12302
|
+
const tokenTrim = token.trim();
|
|
12303
|
+
if (tokenTrim.startsWith("\"") && tokenTrim.endsWith("\"")) {
|
|
12304
|
+
this.setValue(StringValueObject.create(tokenTrim.slice(1, -1).replace(/""/g, "\"")));
|
|
12305
|
+
return;
|
|
12306
|
+
}
|
|
11713
12307
|
const parent = this.getParent();
|
|
11714
12308
|
let isIgnoreNumberPattern = true;
|
|
11715
12309
|
if ((parent === null || parent === void 0 ? void 0 : parent.nodeType) === 4) {
|
|
11716
12310
|
var _isFunctionExecutorAr, _isFunctionExecutorAr2;
|
|
11717
12311
|
isIgnoreNumberPattern = (_isFunctionExecutorAr = (_isFunctionExecutorAr2 = parent.isFunctionExecutorArgumentsIgnoreNumberPattern) === null || _isFunctionExecutorAr2 === void 0 ? void 0 : _isFunctionExecutorAr2.call(parent)) !== null && _isFunctionExecutorAr !== void 0 ? _isFunctionExecutorAr : true;
|
|
11718
12312
|
}
|
|
11719
|
-
this.setValue(ValueObjectFactory.create(
|
|
12313
|
+
this.setValue(ValueObjectFactory.create(token, isIgnoreNumberPattern));
|
|
11720
12314
|
}
|
|
11721
12315
|
};
|
|
11722
12316
|
var ValueNodeFactory = class extends BaseAstNodeFactory {
|
|
@@ -11882,6 +12476,9 @@ let AstTreeBuilder = class AstTreeBuilder extends _univerjs_core.Disposable {
|
|
|
11882
12476
|
astNode = getAstNodeTopParent(astNode);
|
|
11883
12477
|
if (astNode == null || (astNode === null || astNode === void 0 ? void 0 : astNode.nodeType) === 7) return astNode;
|
|
11884
12478
|
switch (astNode.nodeType) {
|
|
12479
|
+
case 8:
|
|
12480
|
+
calculateStack.push(astNode);
|
|
12481
|
+
break;
|
|
11885
12482
|
case 4: {
|
|
11886
12483
|
const token = astNode.getToken().trim().toUpperCase();
|
|
11887
12484
|
if (FORCED_RECALCULATION_FUNCTION_NAME.has(token)) astNode.setForcedCalculateFunction();
|
|
@@ -11933,9 +12530,20 @@ let AstTreeBuilder = class AstTreeBuilder extends _univerjs_core.Disposable {
|
|
|
11933
12530
|
astNode = this._astNodeFactoryList[x].checkAndCreateNodeType(item);
|
|
11934
12531
|
if (astNode != null) break;
|
|
11935
12532
|
}
|
|
11936
|
-
if (astNode == null)
|
|
12533
|
+
if (astNode == null) {
|
|
12534
|
+
const aggregatorNode = this._createGroupByAggregatorTokenNode(item);
|
|
12535
|
+
if (aggregatorNode != null) return aggregatorNode;
|
|
12536
|
+
return new ErrorFunctionNode();
|
|
12537
|
+
}
|
|
11937
12538
|
return astNode;
|
|
11938
12539
|
}
|
|
12540
|
+
_createGroupByAggregatorTokenNode(param) {
|
|
12541
|
+
const token = (typeof param === "string" ? param : param.getToken()).trim().toUpperCase();
|
|
12542
|
+
if (!token.startsWith("_XLETA.")) return null;
|
|
12543
|
+
const name = token.slice(7);
|
|
12544
|
+
if (name !== "SUM" && name !== "COUNT" && name !== "COUNTA" && name !== "PERCENTOF" && name !== "MIN" && name !== "MAX" && name !== "ARRAYTOTEXT") return null;
|
|
12545
|
+
return new BaseAstNode(name);
|
|
12546
|
+
}
|
|
11939
12547
|
_initializeAstNode() {
|
|
11940
12548
|
this._astNodeFactoryList = [
|
|
11941
12549
|
this._astRootNodeFactory,
|
|
@@ -13152,7 +13760,7 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
|
|
|
13152
13760
|
return this._dependencyTreeCache.get(treeId);
|
|
13153
13761
|
}
|
|
13154
13762
|
_getTreeNode(tree) {
|
|
13155
|
-
return generateAstNode(tree.unitId, tree.formula, this._lexer, this._astTreeBuilder, this._currentConfigService);
|
|
13763
|
+
return generateAstNode(tree.unitId, tree.formula, this._lexer, this._astTreeBuilder, this._currentConfigService, tree.subUnitId);
|
|
13156
13764
|
}
|
|
13157
13765
|
*_traverse(treeList, skippedTreeIds) {
|
|
13158
13766
|
const stack = treeList;
|
|
@@ -13278,12 +13886,12 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
|
|
|
13278
13886
|
for (let i = 0, len = treeList.length; i < len; i++) {
|
|
13279
13887
|
const tree = treeList[i];
|
|
13280
13888
|
if (!tree.formula) continue;
|
|
13889
|
+
this._runtimeService.setCurrent(tree.row, tree.column, tree.rowCount, tree.columnCount, tree.subUnitId, tree.unitId);
|
|
13281
13890
|
const node = this._getTreeNode(tree);
|
|
13282
13891
|
tree.isDirty = this._includeTree(tree, node);
|
|
13283
13892
|
const addressFunctionNodes = this._getAddressFunctionNodeList(node);
|
|
13284
13893
|
if (addressFunctionNodes.length > 0) tree.addressFunctionNodes = addressFunctionNodes;
|
|
13285
13894
|
if (tree.isVirtual) continue;
|
|
13286
|
-
this._runtimeService.setCurrent(tree.row, tree.column, tree.rowCount, tree.columnCount, tree.subUnitId, tree.unitId);
|
|
13287
13895
|
const rangeList = await this._getRangeListByNode({
|
|
13288
13896
|
node,
|
|
13289
13897
|
refOffsetX: tree.refOffsetX,
|
|
@@ -13488,13 +14096,13 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
|
|
|
13488
14096
|
async _calculateAddressFunctionRuntimeData(treeDependencyCache, preCalculateTreeList) {
|
|
13489
14097
|
while (preCalculateTreeList.length > 0) {
|
|
13490
14098
|
const tree = preCalculateTreeList.pop();
|
|
14099
|
+
this._runtimeService.setCurrent(tree.row, tree.column, tree.rowCount, tree.columnCount, tree.subUnitId, tree.unitId);
|
|
13491
14100
|
const nodeData = {
|
|
13492
14101
|
node: this._getTreeNode(tree),
|
|
13493
14102
|
refOffsetX: tree.refOffsetX,
|
|
13494
14103
|
refOffsetY: tree.refOffsetY
|
|
13495
14104
|
};
|
|
13496
14105
|
await this._calculateAddressFunction(treeDependencyCache, tree);
|
|
13497
|
-
this._runtimeService.setCurrent(tree.row, tree.column, tree.rowCount, tree.columnCount, tree.subUnitId, tree.unitId);
|
|
13498
14106
|
let value;
|
|
13499
14107
|
if (this._interpreter.checkAsyncNode(nodeData.node)) value = await this._interpreter.executeAsync(nodeData);
|
|
13500
14108
|
else value = this._interpreter.execute(nodeData);
|
|
@@ -13835,9 +14443,10 @@ let CalculateFormulaService = class CalculateFormulaService extends _univerjs_co
|
|
|
13835
14443
|
this._executeLock.acquire("FORMULA_EXECUTION_LOCK", async () => {
|
|
13836
14444
|
for (let i = 0; i < cycleReferenceCount; i++) {
|
|
13837
14445
|
this._runtimeService.setFormulaCycleIndex(i);
|
|
13838
|
-
await this._executeStep();
|
|
14446
|
+
const executed = await this._executeStep();
|
|
13839
14447
|
FORMULA_REF_TO_ARRAY_CACHE.clear();
|
|
13840
|
-
|
|
14448
|
+
const isCycleDependency = this._runtimeService.isCycleDependency();
|
|
14449
|
+
if (!executed || !isCycleDependency) break;
|
|
13841
14450
|
}
|
|
13842
14451
|
this._runtimeService.setFormulaExecuteStage(8);
|
|
13843
14452
|
this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());
|
|
@@ -13921,7 +14530,8 @@ let CalculateFormulaService = class CalculateFormulaService extends _univerjs_co
|
|
|
13921
14530
|
const treeCount = treeList.length;
|
|
13922
14531
|
while (treeList.length > 0) {
|
|
13923
14532
|
const tree = treeList.pop();
|
|
13924
|
-
|
|
14533
|
+
this._runtimeService.setCurrent(tree.row, tree.column, tree.rowCount, tree.columnCount, tree.subUnitId, tree.unitId);
|
|
14534
|
+
const node = generateAstNode(tree.unitId, tree.formula, this._lexer, this._astTreeBuilder, this._currentConfigService, tree.subUnitId);
|
|
13925
14535
|
const nodeData = {
|
|
13926
14536
|
node,
|
|
13927
14537
|
refOffsetX: tree.refOffsetX,
|
|
@@ -13947,11 +14557,9 @@ let CalculateFormulaService = class CalculateFormulaService extends _univerjs_co
|
|
|
13947
14557
|
if (this._runtimeService.isStopExecution() || nodeData == null && getDirtyData == null) {
|
|
13948
14558
|
this._runtimeService.setFormulaExecuteStage(0);
|
|
13949
14559
|
this._runtimeService.markedAsStopFunctionsExecuted();
|
|
13950
|
-
this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());
|
|
13951
14560
|
return;
|
|
13952
14561
|
}
|
|
13953
14562
|
}
|
|
13954
|
-
this._runtimeService.setCurrent(tree.row, tree.column, tree.rowCount, tree.columnCount, tree.subUnitId, tree.unitId);
|
|
13955
14563
|
let value;
|
|
13956
14564
|
if (getDirtyData != null && tree.featureId != null) {
|
|
13957
14565
|
/**
|
|
@@ -14044,8 +14652,9 @@ let CalculateFormulaService = class CalculateFormulaService extends _univerjs_co
|
|
|
14044
14652
|
}
|
|
14045
14653
|
return result;
|
|
14046
14654
|
}
|
|
14047
|
-
async calculate(formulaString) {
|
|
14048
|
-
const
|
|
14655
|
+
async calculate(formulaString, transformSuffix = true, unitId) {
|
|
14656
|
+
const executeUnitId = unitId || this._runtimeService.currentUnitId || this._currentConfigService.getExecuteUnitId();
|
|
14657
|
+
const lexerNode = this._lexer.treeBuilder(formulaString, transformSuffix, executeUnitId);
|
|
14049
14658
|
if (Object.values(ErrorType).includes(lexerNode)) return;
|
|
14050
14659
|
const astNode = this._astTreeBuilder.parse(lexerNode);
|
|
14051
14660
|
const interpreter = this._interpreter;
|
|
@@ -14233,6 +14842,86 @@ CalculateController = __decorate([
|
|
|
14233
14842
|
__decorateParam(2, (0, _univerjs_core.Inject)(FormulaDataModel))
|
|
14234
14843
|
], CalculateController);
|
|
14235
14844
|
|
|
14845
|
+
//#endregion
|
|
14846
|
+
//#region src/services/active-dirty-manager.service.ts
|
|
14847
|
+
/**
|
|
14848
|
+
* Actively mark as dirty, calculate the dirty area based on the command,
|
|
14849
|
+
* and plugins can register the ref range they affect into the formula engine.
|
|
14850
|
+
*/
|
|
14851
|
+
var ActiveDirtyManagerService = class extends _univerjs_core.Disposable {
|
|
14852
|
+
constructor(..._args) {
|
|
14853
|
+
super(..._args);
|
|
14854
|
+
_defineProperty(this, "_dirtyConversionMap", /* @__PURE__ */ new Map());
|
|
14855
|
+
}
|
|
14856
|
+
dispose() {
|
|
14857
|
+
this._dirtyConversionMap.clear();
|
|
14858
|
+
}
|
|
14859
|
+
remove(commandId) {
|
|
14860
|
+
this._dirtyConversionMap.delete(commandId);
|
|
14861
|
+
}
|
|
14862
|
+
get(commandId) {
|
|
14863
|
+
return this._dirtyConversionMap.get(commandId);
|
|
14864
|
+
}
|
|
14865
|
+
has(commandId) {
|
|
14866
|
+
return this._dirtyConversionMap.has(commandId);
|
|
14867
|
+
}
|
|
14868
|
+
register(commandId, dirtyConversion) {
|
|
14869
|
+
this._dirtyConversionMap.set(commandId, dirtyConversion);
|
|
14870
|
+
}
|
|
14871
|
+
getDirtyConversionMap() {
|
|
14872
|
+
return this._dirtyConversionMap;
|
|
14873
|
+
}
|
|
14874
|
+
};
|
|
14875
|
+
const IActiveDirtyManagerService = (0, _univerjs_core.createIdentifier)("univer.formula.active-dirty-manager.service");
|
|
14876
|
+
|
|
14877
|
+
//#endregion
|
|
14878
|
+
//#region src/controllers/super-table-active-dirty.controller.ts
|
|
14879
|
+
let SuperTableActiveDirtyController = class SuperTableActiveDirtyController extends _univerjs_core.Disposable {
|
|
14880
|
+
constructor(_activeDirtyManagerService) {
|
|
14881
|
+
super();
|
|
14882
|
+
this._activeDirtyManagerService = _activeDirtyManagerService;
|
|
14883
|
+
this._initialize();
|
|
14884
|
+
}
|
|
14885
|
+
_initialize() {
|
|
14886
|
+
this._activeDirtyManagerService.register(SetSuperTableMutation.id, {
|
|
14887
|
+
commandId: SetSuperTableMutation.id,
|
|
14888
|
+
getDirtyData: (command) => {
|
|
14889
|
+
const params = command.params;
|
|
14890
|
+
const tableNames = [params.tableName, params.oldTableName].filter((name) => Boolean(name));
|
|
14891
|
+
return {
|
|
14892
|
+
dirtyRanges: [{
|
|
14893
|
+
unitId: params.unitId,
|
|
14894
|
+
sheetId: params.reference.sheetId,
|
|
14895
|
+
range: params.reference.range
|
|
14896
|
+
}],
|
|
14897
|
+
dirtySuperTableMap: { [params.unitId]: Object.fromEntries(tableNames.map((name) => [name, "1"])) },
|
|
14898
|
+
clearDependencyTreeCache: { [params.unitId]: { [params.reference.sheetId]: "1" } }
|
|
14899
|
+
};
|
|
14900
|
+
}
|
|
14901
|
+
});
|
|
14902
|
+
this._activeDirtyManagerService.register(RemoveSuperTableMutation.id, {
|
|
14903
|
+
commandId: RemoveSuperTableMutation.id,
|
|
14904
|
+
getDirtyData: (command) => {
|
|
14905
|
+
const params = command.params;
|
|
14906
|
+
return {
|
|
14907
|
+
dirtyRanges: params.reference ? [{
|
|
14908
|
+
unitId: params.unitId,
|
|
14909
|
+
sheetId: params.reference.sheetId,
|
|
14910
|
+
range: params.reference.range
|
|
14911
|
+
}] : void 0,
|
|
14912
|
+
dirtySuperTableMap: { [params.unitId]: { [params.tableName]: "1" } },
|
|
14913
|
+
clearDependencyTreeCache: params.reference ? { [params.unitId]: { [params.reference.sheetId]: "1" } } : void 0
|
|
14914
|
+
};
|
|
14915
|
+
}
|
|
14916
|
+
});
|
|
14917
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(() => {
|
|
14918
|
+
this._activeDirtyManagerService.remove(SetSuperTableMutation.id);
|
|
14919
|
+
this._activeDirtyManagerService.remove(RemoveSuperTableMutation.id);
|
|
14920
|
+
}));
|
|
14921
|
+
}
|
|
14922
|
+
};
|
|
14923
|
+
SuperTableActiveDirtyController = __decorate([__decorateParam(0, IActiveDirtyManagerService)], SuperTableActiveDirtyController);
|
|
14924
|
+
|
|
14236
14925
|
//#endregion
|
|
14237
14926
|
//#region src/engine/utils/r1c1-reference.ts
|
|
14238
14927
|
const $relativeRegex = /[\[\]]/g;
|
|
@@ -14252,7 +14941,7 @@ function singleReference(refBody, currentRow = 0, currentColumn = 0) {
|
|
|
14252
14941
|
};
|
|
14253
14942
|
}
|
|
14254
14943
|
function deserializeRangeForR1C1(refString, currentRow = 0, currentColumn = 0) {
|
|
14255
|
-
const { refBody, sheetName,
|
|
14944
|
+
const { refBody, sheetName, unitQualifier } = handleRefStringInfo(refString);
|
|
14256
14945
|
const colonIndex = refBody.indexOf(":");
|
|
14257
14946
|
if (colonIndex === -1) {
|
|
14258
14947
|
const grid = singleReference(refBody, currentRow, currentColumn);
|
|
@@ -14260,7 +14949,7 @@ function deserializeRangeForR1C1(refString, currentRow = 0, currentColumn = 0) {
|
|
|
14260
14949
|
const column = grid.column;
|
|
14261
14950
|
const absoluteRefType = grid.absoluteRefType;
|
|
14262
14951
|
return {
|
|
14263
|
-
unitId,
|
|
14952
|
+
unitId: unitQualifier,
|
|
14264
14953
|
sheetName,
|
|
14265
14954
|
range: {
|
|
14266
14955
|
startRow: row,
|
|
@@ -14277,7 +14966,7 @@ function deserializeRangeForR1C1(refString, currentRow = 0, currentColumn = 0) {
|
|
|
14277
14966
|
const startGrid = singleReference(refStartString, currentRow, currentColumn);
|
|
14278
14967
|
const endGrid = singleReference(refEndString, currentRow, currentColumn);
|
|
14279
14968
|
return {
|
|
14280
|
-
unitId,
|
|
14969
|
+
unitId: unitQualifier,
|
|
14281
14970
|
sheetName,
|
|
14282
14971
|
range: {
|
|
14283
14972
|
startRow: startGrid.row,
|
|
@@ -14307,6 +14996,91 @@ function getR1C1Ref(index, absoluteRefType = _univerjs_core.AbsoluteRefType.ALL,
|
|
|
14307
14996
|
}
|
|
14308
14997
|
}
|
|
14309
14998
|
|
|
14999
|
+
//#endregion
|
|
15000
|
+
//#region src/engine/utils/unit-qualifier.ts
|
|
15001
|
+
/**
|
|
15002
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
15003
|
+
*
|
|
15004
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
15005
|
+
* you may not use this file except in compliance with the License.
|
|
15006
|
+
* You may obtain a copy of the License at
|
|
15007
|
+
*
|
|
15008
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15009
|
+
*
|
|
15010
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15011
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15012
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15013
|
+
* See the License for the specific language governing permissions and
|
|
15014
|
+
* limitations under the License.
|
|
15015
|
+
*/
|
|
15016
|
+
const A1_UNIT_QUALIFIER = /('?)\[([^\]]+)\]((?:[^']|'')+)\1!(?=\$?[A-Z]{1,3}\$?\d+)/gi;
|
|
15017
|
+
const TABLE_UNIT_QUALIFIER = /(^|[^\w.])(?:'((?:[^']|'')+)'|\[([^\]]+)\]|([A-Za-z0-9_.-]+))!(?=[^\s!\[\]]+\[)/g;
|
|
15018
|
+
const INDIRECT_LITERAL = /\bINDIRECT\s*\(\s*"((?:[^"]|"")*)"/gi;
|
|
15019
|
+
function equalsQualifier(actual, expected) {
|
|
15020
|
+
return actual.replace(/''/g, "'").toLocaleLowerCase() === expected.toLocaleLowerCase();
|
|
15021
|
+
}
|
|
15022
|
+
function quoteQualifier(name) {
|
|
15023
|
+
return /^[A-Za-z0-9_.-]+$/.test(name) ? name : `'${name.replace(/'/g, "''")}'`;
|
|
15024
|
+
}
|
|
15025
|
+
function refactorReferenceSegment(segment, oldName, newName) {
|
|
15026
|
+
return segment.replace(A1_UNIT_QUALIFIER, (token, quote, qualifier, sheetName) => {
|
|
15027
|
+
if (!equalsQualifier(qualifier, oldName)) return token;
|
|
15028
|
+
const escapedName = newName.replace(/'/g, "''");
|
|
15029
|
+
return quote ? `'[${escapedName}]${sheetName}'!` : `[${newName}]${sheetName}!`;
|
|
15030
|
+
}).replace(TABLE_UNIT_QUALIFIER, (token, boundary, quoted, bracketed, plain) => {
|
|
15031
|
+
var _ref, _ref2;
|
|
15032
|
+
if (!equalsQualifier((_ref = (_ref2 = quoted !== null && quoted !== void 0 ? quoted : bracketed) !== null && _ref2 !== void 0 ? _ref2 : plain) !== null && _ref !== void 0 ? _ref : "", oldName)) return token;
|
|
15033
|
+
if (quoted != null) return `${boundary}'${newName.replace(/'/g, "''")}'!`;
|
|
15034
|
+
if (bracketed != null) return `${boundary}[${newName}]!`;
|
|
15035
|
+
return `${boundary}${quoteQualifier(newName)}!`;
|
|
15036
|
+
});
|
|
15037
|
+
}
|
|
15038
|
+
function refactorOutsideStrings(formula, oldName, newName) {
|
|
15039
|
+
let result = "";
|
|
15040
|
+
let chunk = "";
|
|
15041
|
+
let inString = false;
|
|
15042
|
+
for (let index = 0; index < formula.length; index++) {
|
|
15043
|
+
const character = formula[index];
|
|
15044
|
+
if (character !== "\"") {
|
|
15045
|
+
chunk += character;
|
|
15046
|
+
continue;
|
|
15047
|
+
}
|
|
15048
|
+
if (inString && formula[index + 1] === "\"") {
|
|
15049
|
+
chunk += "\"\"";
|
|
15050
|
+
index++;
|
|
15051
|
+
continue;
|
|
15052
|
+
}
|
|
15053
|
+
result += inString ? chunk : refactorReferenceSegment(chunk, oldName, newName);
|
|
15054
|
+
result += "\"";
|
|
15055
|
+
chunk = "";
|
|
15056
|
+
inString = !inString;
|
|
15057
|
+
}
|
|
15058
|
+
return result + (inString ? chunk : refactorReferenceSegment(chunk, oldName, newName));
|
|
15059
|
+
}
|
|
15060
|
+
/** Refactors only parsed reference qualifiers and INDIRECT literal references, never arbitrary text. */
|
|
15061
|
+
function refactorFormulaUnitQualifier(formula, oldName, newName) {
|
|
15062
|
+
if (!oldName || oldName === newName) return formula;
|
|
15063
|
+
return refactorOutsideStrings(formula.replace(INDIRECT_LITERAL, (token, literal) => {
|
|
15064
|
+
const next = refactorReferenceSegment(literal.replace(/""/g, "\""), oldName, newName).replace(/"/g, "\"\"");
|
|
15065
|
+
return token.replace(literal, next);
|
|
15066
|
+
}), oldName, newName);
|
|
15067
|
+
}
|
|
15068
|
+
/**
|
|
15069
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
15070
|
+
*
|
|
15071
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
15072
|
+
* you may not use this file except in compliance with the License.
|
|
15073
|
+
* You may obtain a copy of the License at
|
|
15074
|
+
*
|
|
15075
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15076
|
+
*
|
|
15077
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15078
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15079
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15080
|
+
* See the License for the specific language governing permissions and
|
|
15081
|
+
* limitations under the License.
|
|
15082
|
+
*/
|
|
15083
|
+
|
|
14310
15084
|
//#endregion
|
|
14311
15085
|
//#region src/engine/utils/check-variant-error.ts
|
|
14312
15086
|
function checkVariantErrorIsArray(variant) {
|
|
@@ -14404,11 +15178,14 @@ var BaseFunction = class {
|
|
|
14404
15178
|
_defineProperty(this, "_subUnitId", void 0);
|
|
14405
15179
|
_defineProperty(this, "_row", -1);
|
|
14406
15180
|
_defineProperty(this, "_column", -1);
|
|
15181
|
+
_defineProperty(this, "_currentFormulaRowCount", 1);
|
|
15182
|
+
_defineProperty(this, "_currentFormulaColumnCount", 1);
|
|
14407
15183
|
_defineProperty(this, "_definedNames", void 0);
|
|
14408
15184
|
_defineProperty(this, "_locale", void 0);
|
|
14409
15185
|
_defineProperty(this, "_sheetOrder", void 0);
|
|
14410
15186
|
_defineProperty(this, "_sheetNameMap", void 0);
|
|
14411
15187
|
_defineProperty(this, "_formulaDataModel", void 0);
|
|
15188
|
+
_defineProperty(this, "_unitReferenceResolver", void 0);
|
|
14412
15189
|
_defineProperty(this, "_rowCount", -1);
|
|
14413
15190
|
_defineProperty(this, "_columnCount", -1);
|
|
14414
15191
|
_defineProperty(
|
|
@@ -14451,6 +15228,12 @@ var BaseFunction = class {
|
|
|
14451
15228
|
"needsFormulaDataModel",
|
|
14452
15229
|
false
|
|
14453
15230
|
);
|
|
15231
|
+
_defineProperty(
|
|
15232
|
+
this,
|
|
15233
|
+
/** Whether the function resolves external Unit qualifiers. */
|
|
15234
|
+
"needsUnitReferenceResolver",
|
|
15235
|
+
false
|
|
15236
|
+
);
|
|
14454
15237
|
_defineProperty(
|
|
14455
15238
|
this,
|
|
14456
15239
|
/**
|
|
@@ -14467,6 +15250,23 @@ var BaseFunction = class {
|
|
|
14467
15250
|
"needsFilteredOutRows",
|
|
14468
15251
|
false
|
|
14469
15252
|
);
|
|
15253
|
+
_defineProperty(
|
|
15254
|
+
this,
|
|
15255
|
+
/**
|
|
15256
|
+
* Whether the function needs unevaluated AST children.
|
|
15257
|
+
*/
|
|
15258
|
+
"needsAstChildren",
|
|
15259
|
+
false
|
|
15260
|
+
);
|
|
15261
|
+
_defineProperty(
|
|
15262
|
+
this,
|
|
15263
|
+
/**
|
|
15264
|
+
* Legacy CSE-style array functions should write only the first result cell
|
|
15265
|
+
* when they are used as a top-level normal formula.
|
|
15266
|
+
*/
|
|
15267
|
+
"returnsLegacyArrayAsScalar",
|
|
15268
|
+
false
|
|
15269
|
+
);
|
|
14470
15270
|
_defineProperty(
|
|
14471
15271
|
this,
|
|
14472
15272
|
/**
|
|
@@ -14499,6 +15299,12 @@ var BaseFunction = class {
|
|
|
14499
15299
|
get column() {
|
|
14500
15300
|
return this._column;
|
|
14501
15301
|
}
|
|
15302
|
+
get currentFormulaRowCount() {
|
|
15303
|
+
return this._currentFormulaRowCount;
|
|
15304
|
+
}
|
|
15305
|
+
get currentFormulaColumnCount() {
|
|
15306
|
+
return this._currentFormulaColumnCount;
|
|
15307
|
+
}
|
|
14502
15308
|
dispose() {}
|
|
14503
15309
|
/**
|
|
14504
15310
|
* In Excel, to inject a defined name into a function that has positioning capabilities,
|
|
@@ -14509,8 +15315,9 @@ var BaseFunction = class {
|
|
|
14509
15315
|
getDefinedName(name) {
|
|
14510
15316
|
const nameMap = this._definedNames;
|
|
14511
15317
|
if (nameMap == null) return null;
|
|
15318
|
+
const normalizedName = name.toLowerCase();
|
|
14512
15319
|
return Object.values(nameMap).find((value) => {
|
|
14513
|
-
return value.name ===
|
|
15320
|
+
return value.name.toLowerCase() === normalizedName;
|
|
14514
15321
|
});
|
|
14515
15322
|
}
|
|
14516
15323
|
setDefinedNames(definedNames) {
|
|
@@ -14535,6 +15342,9 @@ var BaseFunction = class {
|
|
|
14535
15342
|
setFormulaDataModel(_formulaDataModel) {
|
|
14536
15343
|
this._formulaDataModel = _formulaDataModel;
|
|
14537
15344
|
}
|
|
15345
|
+
setUnitReferenceResolver(unitReferenceResolver) {
|
|
15346
|
+
this._unitReferenceResolver = unitReferenceResolver;
|
|
15347
|
+
}
|
|
14538
15348
|
setSheetRowColumnCount(rowCount, columnCount) {
|
|
14539
15349
|
this._rowCount = rowCount;
|
|
14540
15350
|
this._columnCount = columnCount;
|
|
@@ -14551,11 +15361,13 @@ var BaseFunction = class {
|
|
|
14551
15361
|
isArgumentsIgnoreNumberPattern() {
|
|
14552
15362
|
return false;
|
|
14553
15363
|
}
|
|
14554
|
-
setRefInfo(unitId, subUnitId, row, column) {
|
|
15364
|
+
setRefInfo(unitId, subUnitId, row, column, rowCount = 1, columnCount = 1) {
|
|
14555
15365
|
this._unitId = unitId;
|
|
14556
15366
|
this._subUnitId = subUnitId;
|
|
14557
15367
|
this._row = row;
|
|
14558
15368
|
this._column = column;
|
|
15369
|
+
this._currentFormulaRowCount = rowCount;
|
|
15370
|
+
this._currentFormulaColumnCount = columnCount;
|
|
14559
15371
|
}
|
|
14560
15372
|
calculateCustom(...arg) {
|
|
14561
15373
|
return null;
|
|
@@ -14563,6 +15375,9 @@ var BaseFunction = class {
|
|
|
14563
15375
|
calculate(...arg) {
|
|
14564
15376
|
return ErrorValueObject.create("#VALUE!");
|
|
14565
15377
|
}
|
|
15378
|
+
calculateAst(_children, _getVariant) {
|
|
15379
|
+
return ErrorValueObject.create("#VALUE!");
|
|
15380
|
+
}
|
|
14566
15381
|
checkArrayType(variant) {
|
|
14567
15382
|
return variant.isReferenceObject() || variant.isValueObject() && variant.isArray();
|
|
14568
15383
|
}
|
|
@@ -16660,7 +17475,12 @@ function getArrayValuesByAggregateIgnoreOptions(array, options, formulaDataModel
|
|
|
16660
17475
|
if (ignoreErrorValues) continue;
|
|
16661
17476
|
return valueObject;
|
|
16662
17477
|
}
|
|
16663
|
-
if (!valueObject || valueObject.isNull() || valueObject.
|
|
17478
|
+
if (!valueObject || valueObject.isNull() || valueObject.isString()) continue;
|
|
17479
|
+
if (!array.isArray() && valueObject.isBoolean()) {
|
|
17480
|
+
values.push(valueObject.getValue() ? 1 : 0);
|
|
17481
|
+
continue;
|
|
17482
|
+
}
|
|
17483
|
+
if (valueObject.isBoolean()) continue;
|
|
16664
17484
|
const value = valueObject.getValue();
|
|
16665
17485
|
if (!(0, _univerjs_core.isRealNum)(value)) continue;
|
|
16666
17486
|
values.push(+value);
|
|
@@ -18388,6 +19208,11 @@ var Normsdist = class extends BaseFunction {
|
|
|
18388
19208
|
|
|
18389
19209
|
//#endregion
|
|
18390
19210
|
//#region src/functions/compatibility/rank/index.ts
|
|
19211
|
+
function isSameRankNumber$2(left, right) {
|
|
19212
|
+
if (left === right || Number.isInteger(left) || Number.isInteger(right)) return left === right;
|
|
19213
|
+
const scale = Math.max(1, Math.abs(left), Math.abs(right));
|
|
19214
|
+
return Math.abs(left - right) <= Number.EPSILON * scale * 2;
|
|
19215
|
+
}
|
|
18391
19216
|
var Rank = class extends BaseFunction {
|
|
18392
19217
|
constructor(..._args) {
|
|
18393
19218
|
super(..._args);
|
|
@@ -18413,7 +19238,7 @@ var Rank = class extends BaseFunction {
|
|
|
18413
19238
|
const numberValue = +numberObject.getValue();
|
|
18414
19239
|
const orderValue = +orderObject.getValue();
|
|
18415
19240
|
if (Number.isNaN(numberValue) || Number.isNaN(orderValue)) return ErrorValueObject.create("#VALUE!");
|
|
18416
|
-
const result = refNumbers.sort((a, b) => !orderValue ? b - a : a - b).
|
|
19241
|
+
const result = [...refNumbers].sort((a, b) => !orderValue ? b - a : a - b).findIndex((refNumber) => isSameRankNumber$2(refNumber, numberValue));
|
|
18417
19242
|
if (result === -1) return ErrorValueObject.create("#N/A");
|
|
18418
19243
|
return NumberValueObject.create(result + 1);
|
|
18419
19244
|
});
|
|
@@ -18424,12 +19249,12 @@ var Rank = class extends BaseFunction {
|
|
|
18424
19249
|
let refHasError = false;
|
|
18425
19250
|
let refErrorObject = ErrorValueObject.create("#N/A");
|
|
18426
19251
|
const refNumbers = [];
|
|
18427
|
-
if (!ref.isReferenceObject()) return {
|
|
19252
|
+
if (!ref.isReferenceObject() && !ref.isArray()) return {
|
|
18428
19253
|
refHasError: true,
|
|
18429
19254
|
refErrorObject,
|
|
18430
19255
|
refNumbers
|
|
18431
19256
|
};
|
|
18432
|
-
ref.toArrayValueObject().iterator((refObject) => {
|
|
19257
|
+
(ref.isReferenceObject() ? ref.toArrayValueObject() : ref).iterator((refObject) => {
|
|
18433
19258
|
const _refObject = refObject;
|
|
18434
19259
|
if (_refObject.isError()) {
|
|
18435
19260
|
refHasError = true;
|
|
@@ -19495,7 +20320,8 @@ var Edate = class extends BaseFunction {
|
|
|
19495
20320
|
const year = _startDate.getUTCFullYear();
|
|
19496
20321
|
const month = _startDate.getUTCMonth() + monthsValue;
|
|
19497
20322
|
const day = _startDate.getUTCDate();
|
|
19498
|
-
const
|
|
20323
|
+
const lastDayOfTargetMonth = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
|
20324
|
+
const currentSerial = excelDateSerial(new Date(Date.UTC(year, month, Math.min(day, lastDayOfTargetMonth))));
|
|
19499
20325
|
return NumberValueObject.create(currentSerial, DEFAULT_DATE_FORMAT);
|
|
19500
20326
|
});
|
|
19501
20327
|
}
|
|
@@ -19779,8 +20605,12 @@ var Networkdays = class extends BaseFunction {
|
|
|
19779
20605
|
for (let r = 0; r < rowCount; r++) for (let c = 0; c < columnCount; c++) {
|
|
19780
20606
|
const cell = holidays.get(r, c);
|
|
19781
20607
|
if (cell.isBoolean()) return ErrorValueObject.create("#VALUE!");
|
|
20608
|
+
if (cell.isNull()) continue;
|
|
19782
20609
|
const holidaySerialNumber = getDateSerialNumberByObject(cell);
|
|
19783
|
-
if (typeof holidaySerialNumber !== "number")
|
|
20610
|
+
if (typeof holidaySerialNumber !== "number") {
|
|
20611
|
+
if (cell.isString()) continue;
|
|
20612
|
+
return holidaySerialNumber;
|
|
20613
|
+
}
|
|
19784
20614
|
holidaysValueArray.push(holidaySerialNumber);
|
|
19785
20615
|
}
|
|
19786
20616
|
} else {
|
|
@@ -19851,8 +20681,12 @@ var NetworkdaysIntl = class extends BaseFunction {
|
|
|
19851
20681
|
for (let r = 0; r < rowCount; r++) for (let c = 0; c < columnCount; c++) {
|
|
19852
20682
|
const cell = holidays.get(r, c);
|
|
19853
20683
|
if (cell.isBoolean()) return ErrorValueObject.create("#VALUE!");
|
|
20684
|
+
if (cell.isNull()) continue;
|
|
19854
20685
|
const holidaySerialNumber = getDateSerialNumberByObject(cell);
|
|
19855
|
-
if (typeof holidaySerialNumber !== "number")
|
|
20686
|
+
if (typeof holidaySerialNumber !== "number") {
|
|
20687
|
+
if (cell.isString()) continue;
|
|
20688
|
+
return holidaySerialNumber;
|
|
20689
|
+
}
|
|
19856
20690
|
holidaysValueArray.push(holidaySerialNumber);
|
|
19857
20691
|
}
|
|
19858
20692
|
} else {
|
|
@@ -20305,8 +21139,12 @@ var Workday = class extends BaseFunction {
|
|
|
20305
21139
|
for (let r = 0; r < rowCount; r++) for (let c = 0; c < columnCount; c++) {
|
|
20306
21140
|
const cell = holidays.get(r, c);
|
|
20307
21141
|
if (cell.isBoolean()) return ErrorValueObject.create("#VALUE!");
|
|
21142
|
+
if (cell.isNull()) continue;
|
|
20308
21143
|
const holidaySerialNumber = getDateSerialNumberByObject(cell);
|
|
20309
|
-
if (typeof holidaySerialNumber !== "number")
|
|
21144
|
+
if (typeof holidaySerialNumber !== "number") {
|
|
21145
|
+
if (cell.isString()) continue;
|
|
21146
|
+
return holidaySerialNumber;
|
|
21147
|
+
}
|
|
20310
21148
|
holidaysValueArray.push(holidaySerialNumber);
|
|
20311
21149
|
}
|
|
20312
21150
|
} else {
|
|
@@ -20376,8 +21214,12 @@ var WorkdayIntl = class extends BaseFunction {
|
|
|
20376
21214
|
for (let r = 0; r < rowCount; r++) for (let c = 0; c < columnCount; c++) {
|
|
20377
21215
|
const cell = holidays.get(r, c);
|
|
20378
21216
|
if (cell.isBoolean()) return ErrorValueObject.create("#VALUE!");
|
|
21217
|
+
if (cell.isNull()) continue;
|
|
20379
21218
|
const holidaySerialNumber = getDateSerialNumberByObject(cell);
|
|
20380
|
-
if (typeof holidaySerialNumber !== "number")
|
|
21219
|
+
if (typeof holidaySerialNumber !== "number") {
|
|
21220
|
+
if (cell.isString()) continue;
|
|
21221
|
+
return holidaySerialNumber;
|
|
21222
|
+
}
|
|
20381
21223
|
holidaysValueArray.push(holidaySerialNumber);
|
|
20382
21224
|
}
|
|
20383
21225
|
} else {
|
|
@@ -27840,6 +28682,232 @@ var False = class extends BaseFunction {
|
|
|
27840
28682
|
}
|
|
27841
28683
|
};
|
|
27842
28684
|
|
|
28685
|
+
//#endregion
|
|
28686
|
+
//#region src/functions/logical/groupby/index.ts
|
|
28687
|
+
var Groupby = class extends BaseFunction {
|
|
28688
|
+
constructor(..._args) {
|
|
28689
|
+
super(..._args);
|
|
28690
|
+
_defineProperty(this, "minParams", 3);
|
|
28691
|
+
_defineProperty(this, "maxParams", 7);
|
|
28692
|
+
_defineProperty(this, "needsReferenceObject", true);
|
|
28693
|
+
_defineProperty(this, "needsAstChildren", true);
|
|
28694
|
+
}
|
|
28695
|
+
calculateAst(children, getVariant) {
|
|
28696
|
+
const rowFields = this._arrayInput(getVariant(children[0]));
|
|
28697
|
+
if (rowFields instanceof ErrorValueObject) return rowFields;
|
|
28698
|
+
const values = this._arrayInput(getVariant(children[1]));
|
|
28699
|
+
if (values instanceof ErrorValueObject) return values;
|
|
28700
|
+
const aggregators = this._aggregators(children[2]);
|
|
28701
|
+
if (aggregators.length === 0) return ErrorValueObject.create("#VALUE!");
|
|
28702
|
+
if (values.rowCount !== rowFields.rowCount) return ErrorValueObject.create("#VALUE!");
|
|
28703
|
+
const includeTotal = children[4] == null ? true : this._numberValue(getVariant(children[4])) !== 0;
|
|
28704
|
+
const sortColumnValue = children[5] == null ? 0 : this._numberValue(getVariant(children[5]));
|
|
28705
|
+
const sortColumn = sortColumnValue === 0 ? void 0 : Math.trunc(sortColumnValue);
|
|
28706
|
+
const filter = children[6] == null ? void 0 : this._arrayInput(getVariant(children[6]));
|
|
28707
|
+
if (filter instanceof ErrorValueObject) return filter;
|
|
28708
|
+
const groupColumnCount = rowFields.columnCount;
|
|
28709
|
+
const valueColumnCount = values.columnCount;
|
|
28710
|
+
const outputValueColumnCount = this._outputValueColumnCount(valueColumnCount, aggregators.length);
|
|
28711
|
+
const groups = [];
|
|
28712
|
+
const allValues = Array.from({ length: valueColumnCount }, () => []);
|
|
28713
|
+
for (let row = 0; row < rowFields.rowCount; row++) {
|
|
28714
|
+
if (filter != null && !this._truthy(filter.valueAt(row, 0))) continue;
|
|
28715
|
+
const key = [];
|
|
28716
|
+
for (let column = 0; column < groupColumnCount; column++) key.push(rowFields.valueAt(row, column));
|
|
28717
|
+
let group = groups.find((item) => this._keysEqual(item.key, key));
|
|
28718
|
+
if (group == null) {
|
|
28719
|
+
group = {
|
|
28720
|
+
key,
|
|
28721
|
+
values: Array.from({ length: valueColumnCount }, () => [])
|
|
28722
|
+
};
|
|
28723
|
+
groups.push(group);
|
|
28724
|
+
}
|
|
28725
|
+
for (let column = 0; column < valueColumnCount; column++) {
|
|
28726
|
+
const value = values.valueAt(row, column);
|
|
28727
|
+
group.values[column].push(value);
|
|
28728
|
+
allValues[column].push(value);
|
|
28729
|
+
}
|
|
28730
|
+
}
|
|
28731
|
+
this._sortGroups(groups, sortColumn);
|
|
28732
|
+
const includeHeader = aggregators.length > 1;
|
|
28733
|
+
const rowCount = groups.length + (includeHeader ? 1 : 0) + (includeTotal ? 1 : 0);
|
|
28734
|
+
const columnCount = groupColumnCount + outputValueColumnCount;
|
|
28735
|
+
const result = [];
|
|
28736
|
+
if (includeHeader) {
|
|
28737
|
+
const header = [];
|
|
28738
|
+
for (let column = 0; column < groupColumnCount; column++) header.push(StringValueObject.create(""));
|
|
28739
|
+
for (let column = 0; column < outputValueColumnCount; column++) header.push(StringValueObject.create(this._aggregatorHeader(this._aggregatorForOutput(aggregators, valueColumnCount, column))));
|
|
28740
|
+
result.push(header);
|
|
28741
|
+
}
|
|
28742
|
+
for (const group of groups) {
|
|
28743
|
+
const row = [...group.key];
|
|
28744
|
+
for (let column = 0; column < outputValueColumnCount; column++) {
|
|
28745
|
+
const valueColumn = this._valueColumnForOutput(valueColumnCount, aggregators.length, column);
|
|
28746
|
+
const aggregator = this._aggregatorForOutput(aggregators, valueColumnCount, column);
|
|
28747
|
+
row.push(this._applyAggregator(aggregator, group.values[valueColumn], allValues[valueColumn]));
|
|
28748
|
+
}
|
|
28749
|
+
result.push(row);
|
|
28750
|
+
}
|
|
28751
|
+
if (includeTotal) {
|
|
28752
|
+
const row = [];
|
|
28753
|
+
for (let column = 0; column < groupColumnCount; column++) row.push(StringValueObject.create(column === 0 ? "Total" : ""));
|
|
28754
|
+
for (let column = 0; column < outputValueColumnCount; column++) {
|
|
28755
|
+
const valueColumn = this._valueColumnForOutput(valueColumnCount, aggregators.length, column);
|
|
28756
|
+
const aggregator = this._aggregatorForOutput(aggregators, valueColumnCount, column);
|
|
28757
|
+
row.push(this._applyAggregator(aggregator, allValues[valueColumn], allValues[valueColumn]));
|
|
28758
|
+
}
|
|
28759
|
+
result.push(row);
|
|
28760
|
+
}
|
|
28761
|
+
return ArrayValueObject.create({
|
|
28762
|
+
calculateValueList: result,
|
|
28763
|
+
rowCount,
|
|
28764
|
+
columnCount,
|
|
28765
|
+
unitId: this.unitId,
|
|
28766
|
+
sheetId: this.subUnitId,
|
|
28767
|
+
row: this.row,
|
|
28768
|
+
column: this.column
|
|
28769
|
+
});
|
|
28770
|
+
}
|
|
28771
|
+
_arrayInput(variant) {
|
|
28772
|
+
if (variant == null) return ErrorValueObject.create("#VALUE!");
|
|
28773
|
+
let value = variant;
|
|
28774
|
+
if (value.isReferenceObject()) value = value.toArrayValueObject();
|
|
28775
|
+
if (value.isError()) return value;
|
|
28776
|
+
if (value.isArray()) {
|
|
28777
|
+
const array = value;
|
|
28778
|
+
return {
|
|
28779
|
+
rowCount: array.getRowCount(),
|
|
28780
|
+
columnCount: array.getColumnCount(),
|
|
28781
|
+
valueAt: (row, column) => {
|
|
28782
|
+
var _array$get;
|
|
28783
|
+
return (_array$get = array.get(row, column)) !== null && _array$get !== void 0 ? _array$get : NullValueObject.create();
|
|
28784
|
+
}
|
|
28785
|
+
};
|
|
28786
|
+
}
|
|
28787
|
+
return {
|
|
28788
|
+
rowCount: 1,
|
|
28789
|
+
columnCount: 1,
|
|
28790
|
+
valueAt: (row, column) => row === 0 && column === 0 ? value : NullValueObject.create()
|
|
28791
|
+
};
|
|
28792
|
+
}
|
|
28793
|
+
_aggregators(node) {
|
|
28794
|
+
const name = this._normalizedFunctionName(node.getToken());
|
|
28795
|
+
if (name === "GROUPBY") return [];
|
|
28796
|
+
if (name === "HSTACK") return node.getChildren().flatMap((child) => this._aggregators(child));
|
|
28797
|
+
if (this._isAggregatorName(name)) return [name];
|
|
28798
|
+
return [];
|
|
28799
|
+
}
|
|
28800
|
+
_normalizedFunctionName(token) {
|
|
28801
|
+
let normalized = token.toUpperCase();
|
|
28802
|
+
for (;;) {
|
|
28803
|
+
const prefix = [
|
|
28804
|
+
"_XLFN.",
|
|
28805
|
+
"_XLWS.",
|
|
28806
|
+
"_XLETA."
|
|
28807
|
+
].find((item) => normalized.startsWith(item));
|
|
28808
|
+
if (prefix == null) return normalized;
|
|
28809
|
+
normalized = normalized.slice(prefix.length);
|
|
28810
|
+
}
|
|
28811
|
+
}
|
|
28812
|
+
_isAggregatorName(name) {
|
|
28813
|
+
return name === "SUM" || name === "COUNT" || name === "COUNTA" || name === "PERCENTOF" || name === "MIN" || name === "MAX" || name === "ARRAYTOTEXT";
|
|
28814
|
+
}
|
|
28815
|
+
_outputValueColumnCount(valueColumnCount, aggregatorCount) {
|
|
28816
|
+
if (valueColumnCount === 1) return aggregatorCount;
|
|
28817
|
+
if (aggregatorCount === 1 || valueColumnCount === aggregatorCount) return valueColumnCount;
|
|
28818
|
+
return Math.min(valueColumnCount, aggregatorCount);
|
|
28819
|
+
}
|
|
28820
|
+
_valueColumnForOutput(valueColumnCount, aggregatorCount, outputColumn) {
|
|
28821
|
+
if (valueColumnCount === 1) return 0;
|
|
28822
|
+
if (aggregatorCount === 1 || valueColumnCount === aggregatorCount) return Math.min(outputColumn, valueColumnCount - 1);
|
|
28823
|
+
return Math.min(outputColumn, valueColumnCount - 1);
|
|
28824
|
+
}
|
|
28825
|
+
_aggregatorForOutput(aggregators, valueColumnCount, outputColumn) {
|
|
28826
|
+
if (aggregators.length === 1 || valueColumnCount === aggregators.length) return aggregators[Math.min(outputColumn, aggregators.length - 1)];
|
|
28827
|
+
return aggregators[Math.min(outputColumn, aggregators.length - 1)];
|
|
28828
|
+
}
|
|
28829
|
+
_aggregatorHeader(aggregator) {
|
|
28830
|
+
return aggregator === "PERCENTOF" ? "%" : aggregator;
|
|
28831
|
+
}
|
|
28832
|
+
_applyAggregator(aggregator, groupValues, allValues) {
|
|
28833
|
+
switch (aggregator) {
|
|
28834
|
+
case "SUM": return NumberValueObject.create(this._sum(groupValues));
|
|
28835
|
+
case "COUNT": return NumberValueObject.create(groupValues.filter((value) => value.isNumber()).length);
|
|
28836
|
+
case "COUNTA": return NumberValueObject.create(groupValues.filter((value) => !value.isNull() && !(value.isString() && value.getValue() === "")).length);
|
|
28837
|
+
case "PERCENTOF": {
|
|
28838
|
+
const allTotal = this._sum(allValues);
|
|
28839
|
+
if (allTotal === 0) return ErrorValueObject.create("#DIV/0!");
|
|
28840
|
+
return NumberValueObject.create(this._sum(groupValues) / allTotal);
|
|
28841
|
+
}
|
|
28842
|
+
case "MIN": {
|
|
28843
|
+
const values = groupValues.map((value) => this._numericValue(value)).filter((value) => value != null);
|
|
28844
|
+
return NumberValueObject.create(values.length === 0 ? 0 : Math.min(...values));
|
|
28845
|
+
}
|
|
28846
|
+
case "MAX": {
|
|
28847
|
+
const values = groupValues.map((value) => this._numericValue(value)).filter((value) => value != null);
|
|
28848
|
+
return NumberValueObject.create(values.length === 0 ? 0 : Math.max(...values));
|
|
28849
|
+
}
|
|
28850
|
+
case "ARRAYTOTEXT": return StringValueObject.create(groupValues.map((value) => this._textValue(value)).filter(Boolean).join(", "));
|
|
28851
|
+
}
|
|
28852
|
+
}
|
|
28853
|
+
_sum(values) {
|
|
28854
|
+
return values.reduce((sum, value) => {
|
|
28855
|
+
var _this$_numericValue;
|
|
28856
|
+
return sum + ((_this$_numericValue = this._numericValue(value)) !== null && _this$_numericValue !== void 0 ? _this$_numericValue : 0);
|
|
28857
|
+
}, 0);
|
|
28858
|
+
}
|
|
28859
|
+
_numericValue(value) {
|
|
28860
|
+
return value.isNumber() ? Number(value.getValue()) : void 0;
|
|
28861
|
+
}
|
|
28862
|
+
_numberValue(variant) {
|
|
28863
|
+
if (variant == null || variant.isError()) return 0;
|
|
28864
|
+
if (variant.isReferenceObject()) variant = variant.getFirstCell();
|
|
28865
|
+
if (variant.isArray()) {
|
|
28866
|
+
var _get;
|
|
28867
|
+
variant = (_get = variant.get(0, 0)) !== null && _get !== void 0 ? _get : NullValueObject.create();
|
|
28868
|
+
}
|
|
28869
|
+
const value = variant.getValue();
|
|
28870
|
+
return typeof value === "number" ? Math.trunc(value) : Math.trunc(Number(value) || 0);
|
|
28871
|
+
}
|
|
28872
|
+
_truthy(value) {
|
|
28873
|
+
if (value.isError() || value.isNull()) return false;
|
|
28874
|
+
return Boolean(value.getValue());
|
|
28875
|
+
}
|
|
28876
|
+
_keysEqual(left, right) {
|
|
28877
|
+
return left.length === right.length && left.every((value, index) => this._keyValue(value) === this._keyValue(right[index]));
|
|
28878
|
+
}
|
|
28879
|
+
_keyValue(value) {
|
|
28880
|
+
if (value.isError()) return `error:${value.getErrorType()}`;
|
|
28881
|
+
if (value.isNull()) return "null:";
|
|
28882
|
+
return `${typeof value.getValue()}:${String(value.getValue())}`;
|
|
28883
|
+
}
|
|
28884
|
+
_sortGroups(groups, sortColumn) {
|
|
28885
|
+
const descending = sortColumn != null && sortColumn < 0;
|
|
28886
|
+
const sortIndex = sortColumn == null ? void 0 : Math.abs(sortColumn) - 1;
|
|
28887
|
+
groups.sort((left, right) => {
|
|
28888
|
+
const compare = sortIndex != null && sortIndex < left.key.length ? this._compareValue(left.key[sortIndex], right.key[sortIndex]) : this._compareKey(left.key, right.key);
|
|
28889
|
+
return descending ? -compare : compare;
|
|
28890
|
+
});
|
|
28891
|
+
}
|
|
28892
|
+
_compareKey(left, right) {
|
|
28893
|
+
for (let index = 0; index < Math.min(left.length, right.length); index++) {
|
|
28894
|
+
const compare = this._compareValue(left[index], right[index]);
|
|
28895
|
+
if (compare !== 0) return compare;
|
|
28896
|
+
}
|
|
28897
|
+
return left.length - right.length;
|
|
28898
|
+
}
|
|
28899
|
+
_compareValue(left, right) {
|
|
28900
|
+
const leftNumber = this._numericValue(left);
|
|
28901
|
+
const rightNumber = this._numericValue(right);
|
|
28902
|
+
if (leftNumber != null && rightNumber != null) return leftNumber - rightNumber;
|
|
28903
|
+
return this._textValue(left).toUpperCase().localeCompare(this._textValue(right).toUpperCase());
|
|
28904
|
+
}
|
|
28905
|
+
_textValue(value) {
|
|
28906
|
+
if (value.isNull()) return "";
|
|
28907
|
+
return String(value.getValue());
|
|
28908
|
+
}
|
|
28909
|
+
};
|
|
28910
|
+
|
|
27843
28911
|
//#endregion
|
|
27844
28912
|
//#region src/functions/logical/if/index.ts
|
|
27845
28913
|
var If = class extends BaseFunction {
|
|
@@ -27850,12 +28918,18 @@ var If = class extends BaseFunction {
|
|
|
27850
28918
|
}
|
|
27851
28919
|
calculate(logicalTest, valueIfTrue, valueIfFalse = BooleanValueObject.create(false)) {
|
|
27852
28920
|
let _logicalTest = logicalTest;
|
|
28921
|
+
let useLegacyImplicitSelectedValue = false;
|
|
27853
28922
|
if (logicalTest.isArray()) {
|
|
27854
|
-
const
|
|
27855
|
-
const
|
|
27856
|
-
|
|
28923
|
+
const logicalTestArray = logicalTest;
|
|
28924
|
+
const rowCount = logicalTestArray.getRowCount();
|
|
28925
|
+
const columnCount = logicalTestArray.getColumnCount();
|
|
28926
|
+
if (rowCount === 1 && columnCount === 1) _logicalTest = logicalTestArray.get(0, 0);
|
|
28927
|
+
else if (!this._isCurrentArrayFormula() && logicalTestArray.getUnitId() !== "" && logicalTestArray.getSheetId() !== "" && logicalTestArray.getCurrentRow() >= 0 && logicalTestArray.getCurrentColumn() >= 0) {
|
|
28928
|
+
_logicalTest = this._legacyImplicitArrayValue(logicalTestArray);
|
|
28929
|
+
useLegacyImplicitSelectedValue = true;
|
|
28930
|
+
}
|
|
27857
28931
|
}
|
|
27858
|
-
if (!_logicalTest.isArray()) return this._handleSingleObject(_logicalTest, valueIfTrue, valueIfFalse);
|
|
28932
|
+
if (!_logicalTest.isArray()) return this._handleSingleObject(_logicalTest, valueIfTrue, valueIfFalse, useLegacyImplicitSelectedValue);
|
|
27859
28933
|
const maxRowLength = Math.max(_logicalTest.isArray() ? _logicalTest.getRowCount() : 1, valueIfTrue.isArray() ? valueIfTrue.getRowCount() : 1, valueIfFalse.isArray() ? valueIfFalse.getRowCount() : 1);
|
|
27860
28934
|
const maxColumnLength = Math.max(_logicalTest.isArray() ? _logicalTest.getColumnCount() : 1, valueIfTrue.isArray() ? valueIfTrue.getColumnCount() : 1, valueIfFalse.isArray() ? valueIfFalse.getColumnCount() : 1);
|
|
27861
28935
|
const logicalTestArray = expandArrayValueObject(maxRowLength, maxColumnLength, _logicalTest, ErrorValueObject.create("#N/A"));
|
|
@@ -27864,12 +28938,63 @@ var If = class extends BaseFunction {
|
|
|
27864
28938
|
return logicalTestArray.mapValue((logicalTestValue, rowIndex, columnIndex) => {
|
|
27865
28939
|
const valueIfTrueValue = valueIfTrueArray.get(rowIndex, columnIndex);
|
|
27866
28940
|
const valueIfFalseValue = valueIfFalseArray.get(rowIndex, columnIndex);
|
|
27867
|
-
return this._handleSingleObject(logicalTestValue, valueIfTrueValue, valueIfFalseValue);
|
|
28941
|
+
return this._handleSingleObject(logicalTestValue, valueIfTrueValue, valueIfFalseValue, false);
|
|
27868
28942
|
});
|
|
27869
28943
|
}
|
|
27870
|
-
_handleSingleObject(logicalTest, valueIfTrue, valueIfFalse) {
|
|
28944
|
+
_handleSingleObject(logicalTest, valueIfTrue, valueIfFalse, useLegacyImplicitSelectedValue) {
|
|
27871
28945
|
if (logicalTest.isError()) return logicalTest;
|
|
27872
|
-
|
|
28946
|
+
const logicalTestValue = this._coerceLogicalTest(logicalTest);
|
|
28947
|
+
if (logicalTestValue.isError()) return logicalTestValue;
|
|
28948
|
+
let selectedValue = logicalTestValue.getValue() ? valueIfTrue : valueIfFalse;
|
|
28949
|
+
if (useLegacyImplicitSelectedValue) selectedValue = this._legacyImplicitSelectedValue(selectedValue);
|
|
28950
|
+
return this._coerceSelectedValue(selectedValue);
|
|
28951
|
+
}
|
|
28952
|
+
_coerceSelectedValue(value) {
|
|
28953
|
+
return value.isNull() ? NumberValueObject.create(0) : value;
|
|
28954
|
+
}
|
|
28955
|
+
_coerceLogicalTest(logicalTest) {
|
|
28956
|
+
if (logicalTest.isNull()) return BooleanValueObject.create(false);
|
|
28957
|
+
if (logicalTest.isBoolean()) return logicalTest;
|
|
28958
|
+
if (logicalTest.isNumber()) return BooleanValueObject.create(Number(logicalTest.getValue()) !== 0);
|
|
28959
|
+
if (logicalTest.isString()) {
|
|
28960
|
+
const value = `${logicalTest.getValue()}`.trim().toUpperCase();
|
|
28961
|
+
if (value === "TRUE") return BooleanValueObject.create(true);
|
|
28962
|
+
if (value === "FALSE") return BooleanValueObject.create(false);
|
|
28963
|
+
}
|
|
28964
|
+
return ErrorValueObject.create("#VALUE!");
|
|
28965
|
+
}
|
|
28966
|
+
_legacyImplicitSelectedValue(value) {
|
|
28967
|
+
if (!value.isArray()) return value;
|
|
28968
|
+
const array = value;
|
|
28969
|
+
if (array.getUnitId() === "" || array.getSheetId() === "" || array.getCurrentRow() < 0 || array.getCurrentColumn() < 0) return value;
|
|
28970
|
+
return this._legacyImplicitArrayValue(array);
|
|
28971
|
+
}
|
|
28972
|
+
_legacyImplicitArrayValue(logicalTest) {
|
|
28973
|
+
const startRow = logicalTest.getCurrentRow();
|
|
28974
|
+
const startColumn = logicalTest.getCurrentColumn();
|
|
28975
|
+
const rowCount = logicalTest.getRowCount();
|
|
28976
|
+
const columnCount = logicalTest.getColumnCount();
|
|
28977
|
+
if (startRow < 0 || startColumn < 0) return ErrorValueObject.create("#VALUE!");
|
|
28978
|
+
let rowIndex = -1;
|
|
28979
|
+
let columnIndex = -1;
|
|
28980
|
+
if (rowCount === 1 && columnCount === 1) {
|
|
28981
|
+
rowIndex = 0;
|
|
28982
|
+
columnIndex = 0;
|
|
28983
|
+
} else if (rowCount === 1) {
|
|
28984
|
+
rowIndex = 0;
|
|
28985
|
+
columnIndex = this.column - startColumn;
|
|
28986
|
+
} else if (columnCount === 1) {
|
|
28987
|
+
rowIndex = this.row - startRow;
|
|
28988
|
+
columnIndex = 0;
|
|
28989
|
+
} else {
|
|
28990
|
+
rowIndex = this.row - startRow;
|
|
28991
|
+
columnIndex = this.column - startColumn;
|
|
28992
|
+
}
|
|
28993
|
+
if (rowIndex < 0 || rowIndex >= rowCount || columnIndex < 0 || columnIndex >= columnCount) return ErrorValueObject.create("#VALUE!");
|
|
28994
|
+
return logicalTest.get(rowIndex, columnIndex) || ErrorValueObject.create("#VALUE!");
|
|
28995
|
+
}
|
|
28996
|
+
_isCurrentArrayFormula() {
|
|
28997
|
+
return this.currentFormulaRowCount > 1 || this.currentFormulaColumnCount > 1;
|
|
27873
28998
|
}
|
|
27874
28999
|
};
|
|
27875
29000
|
|
|
@@ -27880,8 +29005,11 @@ var Iferror = class extends BaseFunction {
|
|
|
27880
29005
|
super(..._args);
|
|
27881
29006
|
_defineProperty(this, "minParams", 2);
|
|
27882
29007
|
_defineProperty(this, "maxParams", 2);
|
|
29008
|
+
_defineProperty(this, "needsReferenceObject", true);
|
|
27883
29009
|
}
|
|
27884
29010
|
calculate(value, valueIfError) {
|
|
29011
|
+
value = this._toValueObject(value);
|
|
29012
|
+
valueIfError = this._toValueObject(valueIfError);
|
|
27885
29013
|
if (!value.isArray()) return value.isError() ? valueIfError : value;
|
|
27886
29014
|
const maxRowLength = Math.max(value.isArray() ? value.getRowCount() : 1, valueIfError.isArray() ? valueIfError.getRowCount() : 1);
|
|
27887
29015
|
const maxColumnLength = Math.max(value.isArray() ? value.getColumnCount() : 1, valueIfError.isArray() ? valueIfError.getColumnCount() : 1);
|
|
@@ -27892,6 +29020,12 @@ var Iferror = class extends BaseFunction {
|
|
|
27892
29020
|
});
|
|
27893
29021
|
return valueArray;
|
|
27894
29022
|
}
|
|
29023
|
+
_toValueObject(value) {
|
|
29024
|
+
if (!value.isReferenceObject()) return value;
|
|
29025
|
+
const reference = value;
|
|
29026
|
+
if (reference.getRowCount() === 1 && reference.getColumnCount() === 1) return reference.getCellByPosition();
|
|
29027
|
+
return reference.toArrayValueObject();
|
|
29028
|
+
}
|
|
27895
29029
|
};
|
|
27896
29030
|
|
|
27897
29031
|
//#endregion
|
|
@@ -28168,6 +29302,23 @@ var Or = class extends BaseFunction {
|
|
|
28168
29302
|
}
|
|
28169
29303
|
};
|
|
28170
29304
|
|
|
29305
|
+
//#endregion
|
|
29306
|
+
//#region src/functions/logical/percentof/index.ts
|
|
29307
|
+
/**
|
|
29308
|
+
* PERCENTOF is an Excel GROUPBY aggregator token. It is evaluated by GROUPBY's
|
|
29309
|
+
* AST path, not as a standalone scalar function.
|
|
29310
|
+
*/
|
|
29311
|
+
var Percentof = class extends BaseFunction {
|
|
29312
|
+
constructor(..._args) {
|
|
29313
|
+
super(..._args);
|
|
29314
|
+
_defineProperty(this, "minParams", 0);
|
|
29315
|
+
_defineProperty(this, "maxParams", 0);
|
|
29316
|
+
}
|
|
29317
|
+
calculate(..._variants) {
|
|
29318
|
+
return ErrorValueObject.create("#VALUE!");
|
|
29319
|
+
}
|
|
29320
|
+
};
|
|
29321
|
+
|
|
28171
29322
|
//#endregion
|
|
28172
29323
|
//#region src/functions/logical/reduce/index.ts
|
|
28173
29324
|
var Reduce = class extends BaseFunction {
|
|
@@ -28451,6 +29602,7 @@ const functionLogical = [
|
|
|
28451
29602
|
[Bycol, "BYCOL"],
|
|
28452
29603
|
[Byrow, "BYROW"],
|
|
28453
29604
|
[False, "FALSE"],
|
|
29605
|
+
[Groupby, "GROUPBY"],
|
|
28454
29606
|
[If, "IF"],
|
|
28455
29607
|
[Iferror, "IFERROR"],
|
|
28456
29608
|
[Ifna, "IFNA"],
|
|
@@ -28461,6 +29613,7 @@ const functionLogical = [
|
|
|
28461
29613
|
[Map$1, "MAP"],
|
|
28462
29614
|
[Not, "NOT"],
|
|
28463
29615
|
[Or, "OR"],
|
|
29616
|
+
[Percentof, "PERCENTOF"],
|
|
28464
29617
|
[Reduce, "REDUCE"],
|
|
28465
29618
|
[Scan, "SCAN"],
|
|
28466
29619
|
[Switch, "SWITCH"],
|
|
@@ -28482,9 +29635,9 @@ var Address = class extends BaseFunction {
|
|
|
28482
29635
|
if (absNumber === null || absNumber === void 0 ? void 0 : absNumber.isError()) return absNumber;
|
|
28483
29636
|
if (a1 === null || a1 === void 0 ? void 0 : a1.isError()) return a1;
|
|
28484
29637
|
if (sheetText === null || sheetText === void 0 ? void 0 : sheetText.isError()) return sheetText;
|
|
28485
|
-
const _absNumber = absNumber
|
|
28486
|
-
const _a1 = a1
|
|
28487
|
-
const _sheetText = sheetText
|
|
29638
|
+
const _absNumber = absNumber == null || absNumber.isNull() ? NumberValueObject.create(1) : absNumber;
|
|
29639
|
+
const _a1 = a1 == null || a1.isNull() ? BooleanValueObject.create(true) : a1;
|
|
29640
|
+
const _sheetText = sheetText == null || sheetText.isNull() ? StringValueObject.create("") : sheetText;
|
|
28488
29641
|
const maxRowLength = Math.max(rowNumber.isArray() ? rowNumber.getRowCount() : 1, columnNumber.isArray() ? columnNumber.getRowCount() : 1, _absNumber.isArray() ? _absNumber.getRowCount() : 1, _a1.isArray() ? _a1.getRowCount() : 1, _sheetText.isArray() ? _sheetText.getRowCount() : 1);
|
|
28489
29642
|
const maxColumnLength = Math.max(rowNumber.isArray() ? rowNumber.getColumnCount() : 1, columnNumber.isArray() ? columnNumber.getColumnCount() : 1, _absNumber.isArray() ? _absNumber.getColumnCount() : 1, _a1.isArray() ? _a1.getColumnCount() : 1, _sheetText.isArray() ? _sheetText.getColumnCount() : 1);
|
|
28490
29643
|
const rowNumArray = expandArrayValueObject(maxRowLength, maxColumnLength, rowNumber, ErrorValueObject.create("#N/A"));
|
|
@@ -28535,6 +29688,20 @@ function transformAbsoluteRefType(number) {
|
|
|
28535
29688
|
}
|
|
28536
29689
|
}
|
|
28537
29690
|
|
|
29691
|
+
//#endregion
|
|
29692
|
+
//#region src/functions/lookup/anchorarray/index.ts
|
|
29693
|
+
var Anchorarray = class extends BaseFunction {
|
|
29694
|
+
constructor(..._args) {
|
|
29695
|
+
super(..._args);
|
|
29696
|
+
_defineProperty(this, "minParams", 1);
|
|
29697
|
+
_defineProperty(this, "maxParams", 1);
|
|
29698
|
+
_defineProperty(this, "needsReferenceObject", true);
|
|
29699
|
+
}
|
|
29700
|
+
calculate(reference) {
|
|
29701
|
+
return reference;
|
|
29702
|
+
}
|
|
29703
|
+
};
|
|
29704
|
+
|
|
28538
29705
|
//#endregion
|
|
28539
29706
|
//#region src/functions/lookup/areas/index.ts
|
|
28540
29707
|
var Areas = class extends BaseFunction {
|
|
@@ -29045,9 +30212,13 @@ var Hlookup = class extends BaseFunction {
|
|
|
29045
30212
|
return this._handleSingleObject(lookupValue, searchArray, resultArray, rangeLookupValue);
|
|
29046
30213
|
}
|
|
29047
30214
|
_handleSingleObject(value, searchArray, resultArray, rangeLookupValue) {
|
|
29048
|
-
if (rangeLookupValue === 0) return this.equalSearch(value, searchArray, resultArray);
|
|
30215
|
+
if (rangeLookupValue === 0) return this._blankResultAsZero(this.equalSearch(value, searchArray, resultArray));
|
|
29049
30216
|
return this.binarySearch(value, searchArray, resultArray);
|
|
29050
30217
|
}
|
|
30218
|
+
_blankResultAsZero(value) {
|
|
30219
|
+
if (value.isNull()) return NumberValueObject.create(0);
|
|
30220
|
+
return value;
|
|
30221
|
+
}
|
|
29051
30222
|
};
|
|
29052
30223
|
|
|
29053
30224
|
//#endregion
|
|
@@ -29319,11 +30490,23 @@ var Index = class extends BaseFunction {
|
|
|
29319
30490
|
|
|
29320
30491
|
//#endregion
|
|
29321
30492
|
//#region src/functions/lookup/indirect/index.ts
|
|
30493
|
+
const INDIRECT_ERROR_LITERALS = [
|
|
30494
|
+
"#NULL!",
|
|
30495
|
+
"#DIV/0!",
|
|
30496
|
+
"#VALUE!",
|
|
30497
|
+
"#REF!",
|
|
30498
|
+
"#NAME?",
|
|
30499
|
+
"#NUM!",
|
|
30500
|
+
"#N/A",
|
|
30501
|
+
"#CYCLE!",
|
|
30502
|
+
"#CALC!"
|
|
30503
|
+
];
|
|
29322
30504
|
var Indirect = class extends BaseFunction {
|
|
29323
30505
|
constructor(..._args) {
|
|
29324
30506
|
super(..._args);
|
|
29325
30507
|
_defineProperty(this, "minParams", 1);
|
|
29326
30508
|
_defineProperty(this, "maxParams", 2);
|
|
30509
|
+
_defineProperty(this, "needsUnitReferenceResolver", true);
|
|
29327
30510
|
}
|
|
29328
30511
|
isAddress() {
|
|
29329
30512
|
return true;
|
|
@@ -29347,10 +30530,13 @@ var Indirect = class extends BaseFunction {
|
|
|
29347
30530
|
_handleSingleObject(refTextObject, a1Value) {
|
|
29348
30531
|
const refTextValue = `${refTextObject.getValue()}`;
|
|
29349
30532
|
if (refTextValue.trim() === "") return ErrorValueObject.create("#REF!");
|
|
30533
|
+
const embeddedError = this._matchErrorLiteral(refTextValue);
|
|
30534
|
+
if (embeddedError != null) return ErrorValueObject.create(embeddedError);
|
|
29350
30535
|
const refTextV = this._convertToDefinedName(refTextValue);
|
|
29351
30536
|
if (a1Value === 0) {
|
|
29352
30537
|
const { range, sheetName, unitId } = deserializeRangeForR1C1(refTextV);
|
|
29353
30538
|
const rangeReferenceObject = new RangeReferenceObject(range);
|
|
30539
|
+
rangeReferenceObject.setUnitQualifier(unitId);
|
|
29354
30540
|
rangeReferenceObject.setForcedUnitIdDirect(unitId);
|
|
29355
30541
|
rangeReferenceObject.setForcedSheetName(sheetName);
|
|
29356
30542
|
return this._setDefault(rangeReferenceObject);
|
|
@@ -29361,12 +30547,23 @@ var Indirect = class extends BaseFunction {
|
|
|
29361
30547
|
const { range, sheetName, unitId } = deserializeRangeWithSheetWithCache(refTextV);
|
|
29362
30548
|
if (Number.isNaN(range.startRow) || range.endRow + 1 > _univerjs_core.MAX_ROW_COUNT || Number.isNaN(range.startColumn) || range.endColumn + 1 > _univerjs_core.MAX_COLUMN_COUNT) return ErrorValueObject.create("#REF!");
|
|
29363
30549
|
const rangeReferenceObject = new RangeReferenceObject(range);
|
|
30550
|
+
rangeReferenceObject.setUnitQualifier(unitId);
|
|
29364
30551
|
rangeReferenceObject.setForcedUnitIdDirect(unitId);
|
|
29365
30552
|
rangeReferenceObject.setForcedSheetName(sheetName);
|
|
29366
30553
|
return this._setDefault(rangeReferenceObject);
|
|
29367
30554
|
}
|
|
29368
30555
|
_setDefault(object) {
|
|
29369
30556
|
if (this.unitId == null || this.subUnitId == null) return ErrorValueObject.create("#REF!");
|
|
30557
|
+
const unitQualifier = object.getUnitQualifier();
|
|
30558
|
+
if (unitQualifier && this._unitReferenceResolver) {
|
|
30559
|
+
const resolution = this._unitReferenceResolver.resolve({
|
|
30560
|
+
hostUnitId: this.unitId,
|
|
30561
|
+
qualifier: unitQualifier,
|
|
30562
|
+
referenceKind: "a1"
|
|
30563
|
+
});
|
|
30564
|
+
if (typeof resolution === "string") return ErrorValueObject.create(resolution);
|
|
30565
|
+
object.setForcedUnitIdDirect(resolution.unitId);
|
|
30566
|
+
}
|
|
29370
30567
|
object.setDefaultUnitId(this.unitId);
|
|
29371
30568
|
object.setDefaultSheetId(this.subUnitId);
|
|
29372
30569
|
return object;
|
|
@@ -29385,6 +30582,10 @@ var Indirect = class extends BaseFunction {
|
|
|
29385
30582
|
if (formulaOrRefString.startsWith("=")) return formulaOrRefString.slice(1);
|
|
29386
30583
|
return formulaOrRefString;
|
|
29387
30584
|
}
|
|
30585
|
+
_matchErrorLiteral(refText) {
|
|
30586
|
+
const normalizedRefText = refText.toUpperCase();
|
|
30587
|
+
return INDIRECT_ERROR_LITERALS.find((errorType) => normalizedRefText.includes(errorType));
|
|
30588
|
+
}
|
|
29388
30589
|
};
|
|
29389
30590
|
|
|
29390
30591
|
//#endregion
|
|
@@ -29452,7 +30653,7 @@ var Match = class extends BaseFunction {
|
|
|
29452
30653
|
const columnCountLookup = lookupArray.getColumnCount();
|
|
29453
30654
|
if (rowCountLookup !== 1 && columnCountLookup !== 1) return ErrorValueObject.create("#N/A");
|
|
29454
30655
|
if (matchType === null || matchType === void 0 ? void 0 : matchType.isError()) return ErrorValueObject.create("#N/A");
|
|
29455
|
-
const matchTypeValue = this.getMatchTypeValue(matchType);
|
|
30656
|
+
const matchTypeValue = (matchType === null || matchType === void 0 ? void 0 : matchType.isNull()) ? 0 : this.getMatchTypeValue(matchType);
|
|
29456
30657
|
if (matchTypeValue == null) return ErrorValueObject.create("#VALUE!");
|
|
29457
30658
|
if (lookupValue.isArray()) return lookupValue.map((value) => this._handleSingleObject(value, lookupArray, matchTypeValue));
|
|
29458
30659
|
return this._handleSingleObject(lookupValue, lookupArray, matchTypeValue);
|
|
@@ -29871,9 +31072,10 @@ var Sort = class extends BaseFunction {
|
|
|
29871
31072
|
}
|
|
29872
31073
|
calculate(array, sortIndex, sortOrder, byCol) {
|
|
29873
31074
|
let _sortIndex = sortIndex !== null && sortIndex !== void 0 ? sortIndex : NumberValueObject.create(1);
|
|
29874
|
-
|
|
31075
|
+
let _sortOrder = sortOrder !== null && sortOrder !== void 0 ? sortOrder : NumberValueObject.create(1);
|
|
29875
31076
|
const _byCol = byCol !== null && byCol !== void 0 ? byCol : BooleanValueObject.create(false);
|
|
29876
31077
|
if (_sortIndex.isNull()) _sortIndex = NumberValueObject.create(1);
|
|
31078
|
+
if (_sortOrder.isNull()) _sortOrder = NumberValueObject.create(1);
|
|
29877
31079
|
if (_byCol.isArray()) {
|
|
29878
31080
|
const byColRowCount = _byCol.getRowCount();
|
|
29879
31081
|
const byColColumnCount = _byCol.getColumnCount();
|
|
@@ -30638,9 +31840,26 @@ var Vlookup = class extends BaseFunction {
|
|
|
30638
31840
|
return this._handleSingleObject(lookupValue, searchArray, resultArray, rangeLookupValue);
|
|
30639
31841
|
}
|
|
30640
31842
|
_handleSingleObject(value, searchArray, resultArray, rangeLookupValue) {
|
|
30641
|
-
if (rangeLookupValue === 0)
|
|
31843
|
+
if (rangeLookupValue === 0) {
|
|
31844
|
+
if (value.isNull()) return this._equalSearchBlankLookupValue(searchArray, resultArray);
|
|
31845
|
+
return this._blankResultAsZero(this.equalSearch(value, searchArray, resultArray));
|
|
31846
|
+
}
|
|
30642
31847
|
return this.binarySearch(value, searchArray, resultArray);
|
|
30643
31848
|
}
|
|
31849
|
+
_equalSearchBlankLookupValue(searchArray, resultArray) {
|
|
31850
|
+
var _resultArrayValue$;
|
|
31851
|
+
const zero = NumberValueObject.create(0);
|
|
31852
|
+
const matched = searchArray.mapValue((value) => {
|
|
31853
|
+
if (value.isNull()) return BooleanValueObject.create(false);
|
|
31854
|
+
return value.isEqual(zero);
|
|
31855
|
+
});
|
|
31856
|
+
const resultArrayValue = resultArray.pickRaw(matched);
|
|
31857
|
+
return this._blankResultAsZero(((_resultArrayValue$ = resultArrayValue[0]) === null || _resultArrayValue$ === void 0 ? void 0 : _resultArrayValue$[0]) || ErrorValueObject.create("#N/A"));
|
|
31858
|
+
}
|
|
31859
|
+
_blankResultAsZero(value) {
|
|
31860
|
+
if (value.isNull()) return NumberValueObject.create(0);
|
|
31861
|
+
return value;
|
|
31862
|
+
}
|
|
30644
31863
|
};
|
|
30645
31864
|
|
|
30646
31865
|
//#endregion
|
|
@@ -30810,7 +32029,8 @@ var Xlookup = class extends BaseFunction {
|
|
|
30810
32029
|
if (matchMode === null || matchMode === void 0 ? void 0 : matchMode.isNull()) _matchMode = NumberValueObject.create(0);
|
|
30811
32030
|
let _searchMode = searchMode !== null && searchMode !== void 0 ? searchMode : NumberValueObject.create(1);
|
|
30812
32031
|
if (searchMode === null || searchMode === void 0 ? void 0 : searchMode.isNull()) _searchMode = NumberValueObject.create(1);
|
|
30813
|
-
|
|
32032
|
+
const _lookupValue = this._legacyImplicitLookupValue(lookupValue);
|
|
32033
|
+
if (_lookupValue.isError()) return _lookupValue;
|
|
30814
32034
|
const rowCountLookup = lookupArray.isArray() ? lookupArray.getRowCount() : 1;
|
|
30815
32035
|
const columnCountLookup = lookupArray.isArray() ? lookupArray.getColumnCount() : 1;
|
|
30816
32036
|
const rowCountReturn = returnArray.isArray() ? returnArray.getRowCount() : 1;
|
|
@@ -30822,7 +32042,7 @@ var Xlookup = class extends BaseFunction {
|
|
|
30822
32042
|
if (matchModeValue instanceof ErrorValueObject) return matchModeValue;
|
|
30823
32043
|
const searchModeValue = this.getIndexNumValue(_searchMode);
|
|
30824
32044
|
if (searchModeValue instanceof ErrorValueObject) return searchModeValue;
|
|
30825
|
-
return this._getResult(
|
|
32045
|
+
return this._getResult(_lookupValue, baseValueObjectToArrayValueObject(lookupArray), baseValueObjectToArrayValueObject(returnArray), _ifNotFound, matchModeValue, searchModeValue, rowCountLookup, columnCountLookup, rowCountReturn, columnCountReturn);
|
|
30826
32046
|
}
|
|
30827
32047
|
_getResult(lookupValue, lookupArray, returnArray, ifNotFound, matchModeValue, searchModeValue, rowCountLookup, columnCountLookup, rowCountReturn, columnCountReturn) {
|
|
30828
32048
|
const lookupValueRowCount = lookupValue.isArray() ? lookupValue.getRowCount() : 1;
|
|
@@ -30837,7 +32057,7 @@ var Xlookup = class extends BaseFunction {
|
|
|
30837
32057
|
if (checkErrorCombination) return checkErrorCombination;
|
|
30838
32058
|
const result = this._handleSingleObject(value, lookupArray, resultArray, matchModeValue, searchModeValue);
|
|
30839
32059
|
if (result.isError()) return ifNotFound;
|
|
30840
|
-
return result;
|
|
32060
|
+
return this._blankResultAsZero(result);
|
|
30841
32061
|
});
|
|
30842
32062
|
}
|
|
30843
32063
|
const _lookupValue = lookupValue.isArray() ? lookupValue.get(0, 0) : lookupValue;
|
|
@@ -30846,7 +32066,7 @@ var Xlookup = class extends BaseFunction {
|
|
|
30846
32066
|
if (checkErrorCombination) return checkErrorCombination;
|
|
30847
32067
|
const result = this._handleSingleObject(_lookupValue, lookupArray, returnArray, matchModeValue, searchModeValue);
|
|
30848
32068
|
if (result.isError()) return ifNotFound;
|
|
30849
|
-
return result;
|
|
32069
|
+
return this._blankResultAsZero(result);
|
|
30850
32070
|
}
|
|
30851
32071
|
let axis = 0;
|
|
30852
32072
|
/**
|
|
@@ -30858,6 +32078,32 @@ var Xlookup = class extends BaseFunction {
|
|
|
30858
32078
|
if (resultArray == null) return ErrorValueObject.create("#N/A");
|
|
30859
32079
|
return resultArray;
|
|
30860
32080
|
}
|
|
32081
|
+
_legacyImplicitLookupValue(lookupValue) {
|
|
32082
|
+
if (!lookupValue.isArray()) return lookupValue;
|
|
32083
|
+
const array = lookupValue;
|
|
32084
|
+
if (array.getUnitId() === "" || array.getSheetId() === "" || array.getCurrentRow() < 0 || array.getCurrentColumn() < 0) return lookupValue;
|
|
32085
|
+
const startRow = array.getCurrentRow();
|
|
32086
|
+
const startColumn = array.getCurrentColumn();
|
|
32087
|
+
const rowCount = array.getRowCount();
|
|
32088
|
+
const columnCount = array.getColumnCount();
|
|
32089
|
+
let rowIndex = -1;
|
|
32090
|
+
let columnIndex = -1;
|
|
32091
|
+
if (rowCount === 1 && columnCount === 1) {
|
|
32092
|
+
rowIndex = 0;
|
|
32093
|
+
columnIndex = 0;
|
|
32094
|
+
} else if (rowCount === 1) {
|
|
32095
|
+
rowIndex = 0;
|
|
32096
|
+
columnIndex = this.column - startColumn;
|
|
32097
|
+
} else if (columnCount === 1) {
|
|
32098
|
+
rowIndex = this.row - startRow;
|
|
32099
|
+
columnIndex = 0;
|
|
32100
|
+
} else {
|
|
32101
|
+
rowIndex = this.row - startRow;
|
|
32102
|
+
columnIndex = this.column - startColumn;
|
|
32103
|
+
}
|
|
32104
|
+
if (rowIndex < 0 || rowIndex >= rowCount || columnIndex < 0 || columnIndex >= columnCount) return ErrorValueObject.create("#VALUE!");
|
|
32105
|
+
return array.get(rowIndex, columnIndex) || ErrorValueObject.create("#VALUE!");
|
|
32106
|
+
}
|
|
30861
32107
|
_handleExpandObject(value, searchArray, resultArray, matchModeValue, searchModeValue, axis = 0) {
|
|
30862
32108
|
if ((searchModeValue === 2 || searchModeValue === -2) && matchModeValue !== 2) {
|
|
30863
32109
|
const searchType = getSearchModeValue(searchModeValue);
|
|
@@ -30878,6 +32124,10 @@ var Xlookup = class extends BaseFunction {
|
|
|
30878
32124
|
if (matchModeValue === -1 || matchModeValue === 1) return this.orderSearch(value, searchArray, resultArray, matchModeValue === 1 ? 2 : 1, searchModeValue === -1);
|
|
30879
32125
|
return this.equalSearch(value, searchArray, resultArray, searchModeValue !== -1);
|
|
30880
32126
|
}
|
|
32127
|
+
_blankResultAsZero(value) {
|
|
32128
|
+
if (value.isNull()) return NumberValueObject.create(0);
|
|
32129
|
+
return value;
|
|
32130
|
+
}
|
|
30881
32131
|
/**
|
|
30882
32132
|
* Wildcard matching and binary search cannot appear at the same time
|
|
30883
32133
|
* @param matchModeValue
|
|
@@ -30994,6 +32244,7 @@ var Xmatch = class extends BaseFunction {
|
|
|
30994
32244
|
*/
|
|
30995
32245
|
const functionLookup = [
|
|
30996
32246
|
[Address, "ADDRESS"],
|
|
32247
|
+
[Anchorarray, "ANCHORARRAY"],
|
|
30997
32248
|
[Areas, "AREAS"],
|
|
30998
32249
|
[Choose, "CHOOSE"],
|
|
30999
32250
|
[Choosecols, "CHOOSECOLS"],
|
|
@@ -32099,7 +33350,7 @@ var Int = class extends BaseFunction {
|
|
|
32099
33350
|
let _number = number;
|
|
32100
33351
|
if (_number.isString()) _number = _number.convertToNumberObjectValue();
|
|
32101
33352
|
if (_number.isError()) return _number;
|
|
32102
|
-
const numberValue = Math.floor(+_number.getValue());
|
|
33353
|
+
const numberValue = Math.floor(stripErrorMargin(+_number.getValue()));
|
|
32103
33354
|
return NumberValueObject.create(numberValue);
|
|
32104
33355
|
}
|
|
32105
33356
|
};
|
|
@@ -33451,6 +34702,7 @@ var Sum = class extends BaseFunction {
|
|
|
33451
34702
|
let accumulatorAll = NumberValueObject.create(0);
|
|
33452
34703
|
for (let i = 0; i < variants.length; i++) {
|
|
33453
34704
|
let variant = variants[i];
|
|
34705
|
+
variant = this._legacyImplicitDerivedArray(variant);
|
|
33454
34706
|
if (variant.isString()) variant = variant.convertToNumberObjectValue();
|
|
33455
34707
|
if (variant.isError()) return variant;
|
|
33456
34708
|
if (variant.isArray()) variant = variant.sum();
|
|
@@ -33460,6 +34712,30 @@ var Sum = class extends BaseFunction {
|
|
|
33460
34712
|
}
|
|
33461
34713
|
return accumulatorAll;
|
|
33462
34714
|
}
|
|
34715
|
+
_legacyImplicitDerivedArray(variant) {
|
|
34716
|
+
if (!variant.isArray()) return variant;
|
|
34717
|
+
const array = variant;
|
|
34718
|
+
if (array.usesInvertedIndexCache() || !array.usesLegacyImplicitForAggregate()) return variant;
|
|
34719
|
+
const startRow = array.getCurrentRow();
|
|
34720
|
+
const startColumn = array.getCurrentColumn();
|
|
34721
|
+
if (startRow < 0 || startColumn < 0) return variant;
|
|
34722
|
+
const rowCount = array.getRowCount();
|
|
34723
|
+
const columnCount = array.getColumnCount();
|
|
34724
|
+
let rowIndex = -1;
|
|
34725
|
+
let columnIndex = -1;
|
|
34726
|
+
if (rowCount === 1) {
|
|
34727
|
+
rowIndex = 0;
|
|
34728
|
+
columnIndex = this.column - startColumn;
|
|
34729
|
+
} else if (columnCount === 1) {
|
|
34730
|
+
rowIndex = this.row - startRow;
|
|
34731
|
+
columnIndex = 0;
|
|
34732
|
+
} else {
|
|
34733
|
+
rowIndex = this.row - startRow;
|
|
34734
|
+
columnIndex = this.column - startColumn;
|
|
34735
|
+
}
|
|
34736
|
+
if (rowIndex < 0 || rowIndex >= rowCount || columnIndex < 0 || columnIndex >= columnCount) return variant;
|
|
34737
|
+
return array.get(rowIndex, columnIndex) || variant;
|
|
34738
|
+
}
|
|
33463
34739
|
};
|
|
33464
34740
|
|
|
33465
34741
|
//#endregion
|
|
@@ -34033,8 +35309,17 @@ var Compare = class extends BaseFunction {
|
|
|
34033
35309
|
calculate(variant1, variant2) {
|
|
34034
35310
|
if (variant1.isError()) return variant1;
|
|
34035
35311
|
if (variant2.isError()) return variant2;
|
|
35312
|
+
const variant1Error = this._coerceErrorLiteral(variant1);
|
|
35313
|
+
if (variant1Error) return variant1Error;
|
|
35314
|
+
const variant2Error = this._coerceErrorLiteral(variant2);
|
|
35315
|
+
if (variant2Error) return variant2Error;
|
|
34036
35316
|
return variant1.compare(variant2, this._compareType);
|
|
34037
35317
|
}
|
|
35318
|
+
_coerceErrorLiteral(variant) {
|
|
35319
|
+
const value = variant.getValue();
|
|
35320
|
+
if (typeof value === "string" && ERROR_TYPE_SET.has(value)) return ErrorValueObject.create(value);
|
|
35321
|
+
return null;
|
|
35322
|
+
}
|
|
34038
35323
|
};
|
|
34039
35324
|
|
|
34040
35325
|
//#endregion
|
|
@@ -34292,6 +35577,7 @@ var Average = class extends BaseFunction {
|
|
|
34292
35577
|
let accumulatorCount = NumberValueObject.create(0);
|
|
34293
35578
|
for (let i = 0; i < variants.length; i++) {
|
|
34294
35579
|
let variant = variants[i];
|
|
35580
|
+
variant = this._legacyImplicitDerivedArray(variant);
|
|
34295
35581
|
if (variant.isString() || variant.isBoolean()) variant = variant.convertToNumberObjectValue();
|
|
34296
35582
|
if (variant.isError()) return variant;
|
|
34297
35583
|
if (variant.isArray()) {
|
|
@@ -34305,6 +35591,30 @@ var Average = class extends BaseFunction {
|
|
|
34305
35591
|
}
|
|
34306
35592
|
return accumulatorSum.divided(accumulatorCount);
|
|
34307
35593
|
}
|
|
35594
|
+
_legacyImplicitDerivedArray(variant) {
|
|
35595
|
+
if (!variant.isArray()) return variant;
|
|
35596
|
+
const array = variant;
|
|
35597
|
+
if (array.usesInvertedIndexCache()) return variant;
|
|
35598
|
+
const startRow = array.getCurrentRow();
|
|
35599
|
+
const startColumn = array.getCurrentColumn();
|
|
35600
|
+
if (startRow < 0 || startColumn < 0) return variant;
|
|
35601
|
+
const rowCount = array.getRowCount();
|
|
35602
|
+
const columnCount = array.getColumnCount();
|
|
35603
|
+
let rowIndex = -1;
|
|
35604
|
+
let columnIndex = -1;
|
|
35605
|
+
if (rowCount === 1) {
|
|
35606
|
+
rowIndex = 0;
|
|
35607
|
+
columnIndex = this.column - startColumn;
|
|
35608
|
+
} else if (columnCount === 1) {
|
|
35609
|
+
rowIndex = this.row - startRow;
|
|
35610
|
+
columnIndex = 0;
|
|
35611
|
+
} else {
|
|
35612
|
+
rowIndex = this.row - startRow;
|
|
35613
|
+
columnIndex = this.column - startColumn;
|
|
35614
|
+
}
|
|
35615
|
+
if (rowIndex < 0 || rowIndex >= rowCount || columnIndex < 0 || columnIndex >= columnCount) return variant;
|
|
35616
|
+
return array.get(rowIndex, columnIndex) || variant;
|
|
35617
|
+
}
|
|
34308
35618
|
};
|
|
34309
35619
|
|
|
34310
35620
|
//#endregion
|
|
@@ -34837,7 +36147,13 @@ var Countif = class extends BaseFunction {
|
|
|
34837
36147
|
calculate(range, criteria) {
|
|
34838
36148
|
if (!range.isReferenceObject()) return ErrorValueObject.create("#VALUE!");
|
|
34839
36149
|
let _criteria = criteria;
|
|
34840
|
-
if (criteria.isReferenceObject())
|
|
36150
|
+
if (criteria.isReferenceObject()) {
|
|
36151
|
+
_criteria = criteria.toArrayValueObject();
|
|
36152
|
+
if (_criteria.getRowCount() === 1 && _criteria.getColumnCount() === 1) {
|
|
36153
|
+
const firstCriteria = _criteria.get(0, 0);
|
|
36154
|
+
_criteria = firstCriteria.isNull() ? NumberValueObject.create(0) : firstCriteria;
|
|
36155
|
+
}
|
|
36156
|
+
}
|
|
34841
36157
|
if (_criteria.isArray()) {
|
|
34842
36158
|
const resultArray = _criteria.mapValue((criteriaObject) => this._handleSingleObject(range, criteriaObject));
|
|
34843
36159
|
if (resultArray.getRowCount() === 1 && resultArray.getColumnCount() === 1) return resultArray.get(0, 0);
|
|
@@ -34872,7 +36188,7 @@ var Countifs = class extends BaseFunction {
|
|
|
34872
36188
|
_defineProperty(this, "needsReferenceObject", true);
|
|
34873
36189
|
}
|
|
34874
36190
|
calculate(...variants) {
|
|
34875
|
-
const { isError, errorObject, rangeIsDifferentSize, criteriaMaxRowLength, criteriaMaxColumnLength, variants: _variants } = parsePairedRangeAndCriteria(variants);
|
|
36191
|
+
const { isError, errorObject, rangeIsDifferentSize, criteriaMaxRowLength, criteriaMaxColumnLength, variants: _variants } = parsePairedRangeAndCriteria(this._legacyImplicitDerivedCriteria(variants));
|
|
34876
36192
|
if (isError) return errorObject;
|
|
34877
36193
|
if (rangeIsDifferentSize) {
|
|
34878
36194
|
if (criteriaMaxRowLength === 1 && criteriaMaxColumnLength === 1) return ErrorValueObject.create("#VALUE!");
|
|
@@ -34895,6 +36211,32 @@ var Countifs = class extends BaseFunction {
|
|
|
34895
36211
|
column: this.column
|
|
34896
36212
|
});
|
|
34897
36213
|
}
|
|
36214
|
+
_legacyImplicitDerivedCriteria(variants) {
|
|
36215
|
+
return variants.map((variant, index) => {
|
|
36216
|
+
if (index % 2 === 0 || !variant.isArray()) return variant;
|
|
36217
|
+
const array = variant;
|
|
36218
|
+
if (array.usesInvertedIndexCache()) return variant;
|
|
36219
|
+
const startRow = array.getCurrentRow();
|
|
36220
|
+
const startColumn = array.getCurrentColumn();
|
|
36221
|
+
if (startRow < 0 || startColumn < 0) return variant;
|
|
36222
|
+
const rowCount = array.getRowCount();
|
|
36223
|
+
const columnCount = array.getColumnCount();
|
|
36224
|
+
let rowIndex = -1;
|
|
36225
|
+
let columnIndex = -1;
|
|
36226
|
+
if (rowCount === 1) {
|
|
36227
|
+
rowIndex = 0;
|
|
36228
|
+
columnIndex = this.column - startColumn;
|
|
36229
|
+
} else if (columnCount === 1) {
|
|
36230
|
+
rowIndex = this.row - startRow;
|
|
36231
|
+
columnIndex = 0;
|
|
36232
|
+
} else {
|
|
36233
|
+
rowIndex = this.row - startRow;
|
|
36234
|
+
columnIndex = this.column - startColumn;
|
|
36235
|
+
}
|
|
36236
|
+
if (rowIndex < 0 || rowIndex >= rowCount || columnIndex < 0 || columnIndex >= columnCount) return variant;
|
|
36237
|
+
return array.get(rowIndex, columnIndex) || variant;
|
|
36238
|
+
});
|
|
36239
|
+
}
|
|
34898
36240
|
};
|
|
34899
36241
|
|
|
34900
36242
|
//#endregion
|
|
@@ -35672,6 +37014,7 @@ var Linest = class extends BaseFunction {
|
|
|
35672
37014
|
super(..._args);
|
|
35673
37015
|
_defineProperty(this, "minParams", 1);
|
|
35674
37016
|
_defineProperty(this, "maxParams", 4);
|
|
37017
|
+
_defineProperty(this, "returnsLegacyArrayAsScalar", true);
|
|
35675
37018
|
}
|
|
35676
37019
|
calculate(knownYs, knownXs, constb, stats) {
|
|
35677
37020
|
const { isError, errorObject } = checkKnownsArrayDimensions(knownYs, knownXs);
|
|
@@ -36201,7 +37544,11 @@ var Median = class extends BaseFunction {
|
|
|
36201
37544
|
if (isError) return errorObject;
|
|
36202
37545
|
} else {
|
|
36203
37546
|
if (variant.isError()) return variant;
|
|
36204
|
-
if (variant.isNull()
|
|
37547
|
+
if (variant.isNull()) continue;
|
|
37548
|
+
if (variant.isBoolean()) {
|
|
37549
|
+
values.push(variant.getValue() ? 1 : 0);
|
|
37550
|
+
continue;
|
|
37551
|
+
}
|
|
36205
37552
|
if (variant.isString()) {
|
|
36206
37553
|
const _variant = variant.convertToNumberObjectValue();
|
|
36207
37554
|
if (_variant.isError()) return _variant;
|
|
@@ -36811,6 +38158,11 @@ var QuartileExc = class extends BaseFunction {
|
|
|
36811
38158
|
|
|
36812
38159
|
//#endregion
|
|
36813
38160
|
//#region src/functions/statistical/rank-avg/index.ts
|
|
38161
|
+
function isSameRankNumber$1(left, right) {
|
|
38162
|
+
if (left === right || Number.isInteger(left) || Number.isInteger(right)) return left === right;
|
|
38163
|
+
const scale = Math.max(1, Math.abs(left), Math.abs(right));
|
|
38164
|
+
return Math.abs(left - right) <= Number.EPSILON * scale * 2;
|
|
38165
|
+
}
|
|
36814
38166
|
var RankAvg = class extends BaseFunction {
|
|
36815
38167
|
constructor(..._args) {
|
|
36816
38168
|
super(..._args);
|
|
@@ -36842,14 +38194,9 @@ var RankAvg = class extends BaseFunction {
|
|
|
36842
38194
|
return resultArray;
|
|
36843
38195
|
}
|
|
36844
38196
|
_getResult(numberValue, orderValue, refNumbers) {
|
|
36845
|
-
const refOrderNumbers = refNumbers.sort((a, b) => !orderValue ? b - a : a - b);
|
|
36846
|
-
let index = refOrderNumbers.indexOf(numberValue);
|
|
38197
|
+
const refOrderNumbers = [...refNumbers].sort((a, b) => !orderValue ? b - a : a - b);
|
|
36847
38198
|
const results = [];
|
|
36848
|
-
|
|
36849
|
-
const start = index + 1;
|
|
36850
|
-
results.push(start);
|
|
36851
|
-
index = refOrderNumbers.indexOf(numberValue, start);
|
|
36852
|
-
}
|
|
38199
|
+
for (let index = 0; index < refOrderNumbers.length; index++) if (isSameRankNumber$1(refOrderNumbers[index], numberValue)) results.push(index + 1);
|
|
36853
38200
|
if (results.length === 0) return ErrorValueObject.create("#N/A");
|
|
36854
38201
|
const result = results.reduce((acc, cur) => acc + cur, 0) / results.length;
|
|
36855
38202
|
return NumberValueObject.create(result);
|
|
@@ -36858,12 +38205,12 @@ var RankAvg = class extends BaseFunction {
|
|
|
36858
38205
|
let refHasError = false;
|
|
36859
38206
|
let refErrorObject = ErrorValueObject.create("#N/A");
|
|
36860
38207
|
const refNumbers = [];
|
|
36861
|
-
if (!ref.isReferenceObject()) return {
|
|
38208
|
+
if (!ref.isReferenceObject() && !ref.isArray()) return {
|
|
36862
38209
|
refHasError: true,
|
|
36863
38210
|
refErrorObject,
|
|
36864
38211
|
refNumbers
|
|
36865
38212
|
};
|
|
36866
|
-
ref.toArrayValueObject().iterator((refObject) => {
|
|
38213
|
+
(ref.isReferenceObject() ? ref.toArrayValueObject() : ref).iterator((refObject) => {
|
|
36867
38214
|
const _refObject = refObject;
|
|
36868
38215
|
if (_refObject.isError()) {
|
|
36869
38216
|
refHasError = true;
|
|
@@ -36885,6 +38232,11 @@ var RankAvg = class extends BaseFunction {
|
|
|
36885
38232
|
|
|
36886
38233
|
//#endregion
|
|
36887
38234
|
//#region src/functions/statistical/rank-eq/index.ts
|
|
38235
|
+
function isSameRankNumber(left, right) {
|
|
38236
|
+
if (left === right || Number.isInteger(left) || Number.isInteger(right)) return left === right;
|
|
38237
|
+
const scale = Math.max(1, Math.abs(left), Math.abs(right));
|
|
38238
|
+
return Math.abs(left - right) <= Number.EPSILON * scale * 2;
|
|
38239
|
+
}
|
|
36888
38240
|
var RankEq = class extends BaseFunction {
|
|
36889
38241
|
constructor(..._args) {
|
|
36890
38242
|
super(..._args);
|
|
@@ -36910,7 +38262,7 @@ var RankEq = class extends BaseFunction {
|
|
|
36910
38262
|
const numberValue = +numberObject.getValue();
|
|
36911
38263
|
const orderValue = +orderObject.getValue();
|
|
36912
38264
|
if (Number.isNaN(numberValue) || Number.isNaN(orderValue)) return ErrorValueObject.create("#VALUE!");
|
|
36913
|
-
const result = refNumbers.sort((a, b) => !orderValue ? b - a : a - b).
|
|
38265
|
+
const result = [...refNumbers].sort((a, b) => !orderValue ? b - a : a - b).findIndex((refNumber) => isSameRankNumber(refNumber, numberValue));
|
|
36914
38266
|
if (result === -1) return ErrorValueObject.create("#N/A");
|
|
36915
38267
|
return NumberValueObject.create(result + 1);
|
|
36916
38268
|
});
|
|
@@ -36921,12 +38273,12 @@ var RankEq = class extends BaseFunction {
|
|
|
36921
38273
|
let refHasError = false;
|
|
36922
38274
|
let refErrorObject = ErrorValueObject.create("#N/A");
|
|
36923
38275
|
const refNumbers = [];
|
|
36924
|
-
if (!ref.isReferenceObject()) return {
|
|
38276
|
+
if (!ref.isReferenceObject() && !ref.isArray()) return {
|
|
36925
38277
|
refHasError: true,
|
|
36926
38278
|
refErrorObject,
|
|
36927
38279
|
refNumbers
|
|
36928
38280
|
};
|
|
36929
|
-
ref.toArrayValueObject().iterator((refObject) => {
|
|
38281
|
+
(ref.isReferenceObject() ? ref.toArrayValueObject() : ref).iterator((refObject) => {
|
|
36930
38282
|
const _refObject = refObject;
|
|
36931
38283
|
if (_refObject.isError()) {
|
|
36932
38284
|
refHasError = true;
|
|
@@ -37998,11 +39350,10 @@ var Concat = class extends BaseFunction {
|
|
|
37998
39350
|
isError = valueObject;
|
|
37999
39351
|
return false;
|
|
38000
39352
|
}
|
|
38001
|
-
|
|
38002
|
-
else if (valueObject.isString() || valueObject.isNumber()) concatenatedString += valueObject.getValue();
|
|
39353
|
+
concatenatedString += formatValueForFormulaText(valueObject.getValue());
|
|
38003
39354
|
});
|
|
38004
39355
|
if (isError) return isError;
|
|
38005
|
-
} else if (!textValue.isError() && !textValue.isNull()) concatenatedString += textValue.getValue();
|
|
39356
|
+
} else if (!textValue.isError() && !textValue.isNull()) concatenatedString += formatValueForFormulaText(textValue.getValue());
|
|
38006
39357
|
return StringValueObject.create(concatenatedString);
|
|
38007
39358
|
}
|
|
38008
39359
|
};
|
|
@@ -38029,20 +39380,27 @@ var Concatenate = class extends BaseFunction {
|
|
|
38029
39380
|
}
|
|
38030
39381
|
});
|
|
38031
39382
|
let result = null;
|
|
39383
|
+
const referenceSource = textValues.find((textValue) => {
|
|
39384
|
+
if (!textValue.isArray()) return false;
|
|
39385
|
+
const arrayValue = textValue;
|
|
39386
|
+
return arrayValue.getUnitId() !== "" && arrayValue.getSheetId() !== "" && arrayValue.getCurrentRow() >= 0 && arrayValue.getCurrentColumn() >= 0;
|
|
39387
|
+
});
|
|
38032
39388
|
for (const textValue of textValues) result = expandArrayValueObject(maxRowLength, maxColumnLength, textValue, ErrorValueObject.create("#N/A")).mapValue((textValueObject, rowIndex, columnIndex) => {
|
|
38033
|
-
var
|
|
39389
|
+
var _resultValueObject$ge, _textValueObject$getV;
|
|
38034
39390
|
const resultValueObject = result && result.get(rowIndex, columnIndex);
|
|
38035
39391
|
if (resultValueObject === null || resultValueObject === void 0 ? void 0 : resultValueObject.isError()) return resultValueObject;
|
|
38036
39392
|
if (textValueObject.isError()) return textValueObject;
|
|
38037
|
-
|
|
38038
|
-
|
|
38039
|
-
if (resultValueObject === null || resultValueObject === void 0 ? void 0 : resultValueObject.isBoolean()) resultValue = `${resultValue}`.toLocaleUpperCase();
|
|
38040
|
-
if (textValueObject === null || textValueObject === void 0 ? void 0 : textValueObject.isBoolean()) textValue = `${textValue}`.toLocaleUpperCase();
|
|
38041
|
-
const resultValueObjectString = (resultValueObject === null || resultValueObject === void 0 ? void 0 : resultValueObject.isNull()) ? "" : (_resultValue = resultValue) !== null && _resultValue !== void 0 ? _resultValue : "";
|
|
38042
|
-
const textValueObjectString = (textValueObject === null || textValueObject === void 0 ? void 0 : textValueObject.isNull()) ? "" : (_textValue = textValue) !== null && _textValue !== void 0 ? _textValue : "";
|
|
39393
|
+
const resultValueObjectString = (resultValueObject === null || resultValueObject === void 0 ? void 0 : resultValueObject.isNull()) ? "" : formatValueForFormulaText((_resultValueObject$ge = resultValueObject === null || resultValueObject === void 0 ? void 0 : resultValueObject.getValue()) !== null && _resultValueObject$ge !== void 0 ? _resultValueObject$ge : null);
|
|
39394
|
+
const textValueObjectString = (textValueObject === null || textValueObject === void 0 ? void 0 : textValueObject.isNull()) ? "" : formatValueForFormulaText((_textValueObject$getV = textValueObject === null || textValueObject === void 0 ? void 0 : textValueObject.getValue()) !== null && _textValueObject$getV !== void 0 ? _textValueObject$getV : null);
|
|
38043
39395
|
return StringValueObject.create(`${resultValueObjectString}${textValueObjectString}`);
|
|
38044
39396
|
});
|
|
38045
39397
|
if (!result) return ErrorValueObject.create("#VALUE!");
|
|
39398
|
+
if (referenceSource && result.isArray()) {
|
|
39399
|
+
const resultArray = result;
|
|
39400
|
+
resultArray.setUnitId(referenceSource.getUnitId());
|
|
39401
|
+
resultArray.setSheetId(referenceSource.getSheetId());
|
|
39402
|
+
resultArray.setCurrent(referenceSource.getCurrentRow(), referenceSource.getCurrentColumn());
|
|
39403
|
+
}
|
|
38046
39404
|
return result;
|
|
38047
39405
|
}
|
|
38048
39406
|
};
|
|
@@ -39809,13 +41167,17 @@ var Text = class extends BaseFunction {
|
|
|
39809
41167
|
}
|
|
39810
41168
|
if (formatTextValue.isNull()) formatTextValue = StringValueObject.create(" ");
|
|
39811
41169
|
const formatTextValueString = `${formatTextValue.getValue()}`;
|
|
39812
|
-
const previewText = getFormatPreview(formatTextValueString, textValueNumber);
|
|
41170
|
+
const previewText = getFormatPreview(normalizeExcelWeekdayFormat(formatTextValueString), textValueNumber);
|
|
39813
41171
|
return StringValueObject.create(formatTextValueString === " " ? previewText.trimEnd() : previewText);
|
|
39814
41172
|
});
|
|
39815
41173
|
if (resultArray.getRowCount() === 1 && resultArray.getColumnCount() === 1) return resultArray.get(0, 0);
|
|
39816
41174
|
return resultArray;
|
|
39817
41175
|
}
|
|
39818
41176
|
};
|
|
41177
|
+
function normalizeExcelWeekdayFormat(formatText) {
|
|
41178
|
+
if (!formatText.includes("Å")) return formatText;
|
|
41179
|
+
return formatText.replace(/\u00C5{4,}/g, "dddd").replace(/\u00C5{1,3}/g, "ddd");
|
|
41180
|
+
}
|
|
39819
41181
|
|
|
39820
41182
|
//#endregion
|
|
39821
41183
|
//#region src/functions/text/textafter/index.ts
|
|
@@ -40190,9 +41552,19 @@ var Textsplit = class extends BaseFunction {
|
|
|
40190
41552
|
const _ignoreEmpty = ignoreEmpty !== null && ignoreEmpty !== void 0 ? ignoreEmpty : NumberValueObject.create(0);
|
|
40191
41553
|
const _matchMode = matchMode !== null && matchMode !== void 0 ? matchMode : NumberValueObject.create(0);
|
|
40192
41554
|
const _padWith = padWith !== null && padWith !== void 0 ? padWith : StringValueObject.create("#N/A");
|
|
40193
|
-
const { _variant: _colDelimiter, values: colDelimiterValue } = this._getStringValues(colDelimiter);
|
|
40194
41555
|
const { _variant, values: rowDelimiterValue } = this._getStringValues(_rowDelimiter, false);
|
|
40195
41556
|
_rowDelimiter = _variant;
|
|
41557
|
+
const allowBlankColDelimiter = rowDelimiter != null && !rowDelimiter.isNull() && !_rowDelimiter.isError() && rowDelimiterValue.length > 0;
|
|
41558
|
+
let _colDelimiter;
|
|
41559
|
+
let colDelimiterValue;
|
|
41560
|
+
if (allowBlankColDelimiter && this._isBlankScalarDelimiter(colDelimiter)) {
|
|
41561
|
+
_colDelimiter = colDelimiter;
|
|
41562
|
+
colDelimiterValue = [];
|
|
41563
|
+
} else {
|
|
41564
|
+
const { _variant: colDelimiterVariant, values } = this._getStringValues(colDelimiter);
|
|
41565
|
+
_colDelimiter = colDelimiterVariant;
|
|
41566
|
+
colDelimiterValue = values;
|
|
41567
|
+
}
|
|
40196
41568
|
const maxRowLength = Math.max(text.isArray() ? text.getRowCount() : 1, _ignoreEmpty.isArray() ? _ignoreEmpty.getRowCount() : 1, _matchMode.isArray() ? _matchMode.getRowCount() : 1);
|
|
40197
41569
|
const maxColumnLength = Math.max(text.isArray() ? text.getColumnCount() : 1, _ignoreEmpty.isArray() ? _ignoreEmpty.getColumnCount() : 1, _matchMode.isArray() ? _matchMode.getColumnCount() : 1);
|
|
40198
41570
|
const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, ErrorValueObject.create("#N/A"));
|
|
@@ -40270,7 +41642,7 @@ var Textsplit = class extends BaseFunction {
|
|
|
40270
41642
|
const resultRows = textValue.split(rowDelimiterRegExp);
|
|
40271
41643
|
let resultColsMaxCount = 1;
|
|
40272
41644
|
let result = resultRows.map((row) => {
|
|
40273
|
-
let cols = row.split(colDelimiterRegExp);
|
|
41645
|
+
let cols = colDelimiterValue.length > 0 ? row.split(colDelimiterRegExp) : [row];
|
|
40274
41646
|
if (ignoreEmptyValue) cols = cols.filter((col) => col !== "");
|
|
40275
41647
|
resultColsMaxCount = Math.max(resultColsMaxCount, cols.length);
|
|
40276
41648
|
return cols;
|
|
@@ -40294,7 +41666,10 @@ var Textsplit = class extends BaseFunction {
|
|
|
40294
41666
|
if (valueObject.isNull()) value = "\\s";
|
|
40295
41667
|
if (valueObject.isBoolean()) value = value ? "TRUE" : "FALSE";
|
|
40296
41668
|
value += "";
|
|
40297
|
-
return
|
|
41669
|
+
return _univerjs_core.regexp.escapeRegExp(value);
|
|
41670
|
+
}
|
|
41671
|
+
_isBlankScalarDelimiter(valueObject) {
|
|
41672
|
+
return !valueObject.isArray() && (valueObject.isNull() || `${valueObject.getValue()}` === "");
|
|
40298
41673
|
}
|
|
40299
41674
|
};
|
|
40300
41675
|
|
|
@@ -40523,6 +41898,7 @@ const functionText = [
|
|
|
40523
41898
|
[Numbervalue, "NUMBERVALUE"],
|
|
40524
41899
|
[Regexextract, "REGEXEXTRACT"],
|
|
40525
41900
|
[Regexmatch, "REGEXMATCH"],
|
|
41901
|
+
[Regexmatch, "REGEXTEST"],
|
|
40526
41902
|
[Regexreplace, "REGEXREPLACE"],
|
|
40527
41903
|
[Proper, "PROPER"],
|
|
40528
41904
|
[Replace, "REPLACE"],
|
|
@@ -40590,6 +41966,58 @@ var Encodeurl = class extends BaseFunction {
|
|
|
40590
41966
|
}
|
|
40591
41967
|
};
|
|
40592
41968
|
|
|
41969
|
+
//#endregion
|
|
41970
|
+
//#region src/functions/web/filterxml/index.ts
|
|
41971
|
+
var Filterxml = class extends BaseFunction {
|
|
41972
|
+
constructor(..._args) {
|
|
41973
|
+
super(..._args);
|
|
41974
|
+
_defineProperty(this, "minParams", 2);
|
|
41975
|
+
_defineProperty(this, "maxParams", 2);
|
|
41976
|
+
}
|
|
41977
|
+
calculate(xml, xpath) {
|
|
41978
|
+
if (xml.isError()) return xml;
|
|
41979
|
+
if (xpath.isError()) return xpath;
|
|
41980
|
+
const tagName = getDescendantTagName(`${xpath.getValue()}`);
|
|
41981
|
+
if (tagName == null) return ErrorValueObject.create("#VALUE!");
|
|
41982
|
+
const values = extractTagTexts(`${xml.getValue()}`, tagName);
|
|
41983
|
+
if (values.length === 0) return ErrorValueObject.create("#VALUE!");
|
|
41984
|
+
return ArrayValueObject.create({
|
|
41985
|
+
calculateValueList: transformToValueObject(values.map((value) => [value])),
|
|
41986
|
+
rowCount: values.length,
|
|
41987
|
+
columnCount: 1,
|
|
41988
|
+
unitId: "",
|
|
41989
|
+
sheetId: "",
|
|
41990
|
+
row: 0,
|
|
41991
|
+
column: 0
|
|
41992
|
+
});
|
|
41993
|
+
}
|
|
41994
|
+
};
|
|
41995
|
+
function getDescendantTagName(xpath) {
|
|
41996
|
+
const text = xpath.trim();
|
|
41997
|
+
if (!text.startsWith("//")) return null;
|
|
41998
|
+
const tagName = text.slice(2).replace(/\/text\(\)$/, "").trim();
|
|
41999
|
+
return /^[A-Za-z0-9_.-]+$/.test(tagName) ? tagName : null;
|
|
42000
|
+
}
|
|
42001
|
+
function extractTagTexts(xml, tagName) {
|
|
42002
|
+
const open = `<${tagName}>`;
|
|
42003
|
+
const close = `</${tagName}>`;
|
|
42004
|
+
const values = [];
|
|
42005
|
+
let offset = 0;
|
|
42006
|
+
while (offset < xml.length) {
|
|
42007
|
+
const openIndex = xml.indexOf(open, offset);
|
|
42008
|
+
if (openIndex < 0) break;
|
|
42009
|
+
const valueStart = openIndex + open.length;
|
|
42010
|
+
const closeIndex = xml.indexOf(close, valueStart);
|
|
42011
|
+
if (closeIndex < 0) break;
|
|
42012
|
+
values.push(decodeXmlEntities(xml.slice(valueStart, closeIndex)));
|
|
42013
|
+
offset = closeIndex + close.length;
|
|
42014
|
+
}
|
|
42015
|
+
return values;
|
|
42016
|
+
}
|
|
42017
|
+
function decodeXmlEntities(value) {
|
|
42018
|
+
return value.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/"/g, "\"").replace(/'/g, "'");
|
|
42019
|
+
}
|
|
42020
|
+
|
|
40593
42021
|
//#endregion
|
|
40594
42022
|
//#region src/functions/web/function-map.ts
|
|
40595
42023
|
/**
|
|
@@ -40607,7 +42035,7 @@ var Encodeurl = class extends BaseFunction {
|
|
|
40607
42035
|
* See the License for the specific language governing permissions and
|
|
40608
42036
|
* limitations under the License.
|
|
40609
42037
|
*/
|
|
40610
|
-
const functionWeb = [[Encodeurl, "ENCODEURL"]];
|
|
42038
|
+
const functionWeb = [[Encodeurl, "ENCODEURL"], [Filterxml, "FILTERXML"]];
|
|
40611
42039
|
|
|
40612
42040
|
//#endregion
|
|
40613
42041
|
//#region src/functions/index.ts
|
|
@@ -40677,7 +42105,7 @@ function getObjectValue(result, isUseStrip = false) {
|
|
|
40677
42105
|
//#endregion
|
|
40678
42106
|
//#region package.json
|
|
40679
42107
|
var name = "@univerjs/engine-formula";
|
|
40680
|
-
var version = "1.0.0-alpha.
|
|
42108
|
+
var version = "1.0.0-alpha.4";
|
|
40681
42109
|
|
|
40682
42110
|
//#endregion
|
|
40683
42111
|
//#region src/services/global-computing-status.service.ts
|
|
@@ -40746,6 +42174,242 @@ let ComputingStatusReporterController = class ComputingStatusReporterController
|
|
|
40746
42174
|
};
|
|
40747
42175
|
ComputingStatusReporterController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, (0, _univerjs_core.Inject)(GlobalComputingStatusService))], ComputingStatusReporterController);
|
|
40748
42176
|
|
|
42177
|
+
//#endregion
|
|
42178
|
+
//#region src/services/formula-calculation-trigger.service.ts
|
|
42179
|
+
const LOCAL_ONLY = { onlyLocal: true };
|
|
42180
|
+
const CALCULATION_DEBOUNCE_TIME = 10;
|
|
42181
|
+
let FormulaCalculationTriggerService = class FormulaCalculationTriggerService extends _univerjs_core.Disposable {
|
|
42182
|
+
constructor(_commandService, _activeDirtyManagerService) {
|
|
42183
|
+
super();
|
|
42184
|
+
this._commandService = _commandService;
|
|
42185
|
+
this._activeDirtyManagerService = _activeDirtyManagerService;
|
|
42186
|
+
_defineProperty(this, "_waitingCommandQueue", []);
|
|
42187
|
+
_defineProperty(this, "_pendingDirtyData", createEmptyDirtyData());
|
|
42188
|
+
_defineProperty(this, "_runningDirtyData", createEmptyDirtyData());
|
|
42189
|
+
_defineProperty(this, "_timer", void 0);
|
|
42190
|
+
_defineProperty(this, "_started", false);
|
|
42191
|
+
_defineProperty(this, "_executionInProgress", false);
|
|
42192
|
+
_defineProperty(this, "_hasPendingCalculation", false);
|
|
42193
|
+
_defineProperty(this, "_stopRequested", false);
|
|
42194
|
+
this._initialize();
|
|
42195
|
+
}
|
|
42196
|
+
start() {
|
|
42197
|
+
if (this._started) return;
|
|
42198
|
+
this._started = true;
|
|
42199
|
+
this._scheduleFlush();
|
|
42200
|
+
}
|
|
42201
|
+
dispose() {
|
|
42202
|
+
clearTimeout(this._timer);
|
|
42203
|
+
this._waitingCommandQueue = [];
|
|
42204
|
+
this._pendingDirtyData = createEmptyDirtyData();
|
|
42205
|
+
this._runningDirtyData = createEmptyDirtyData();
|
|
42206
|
+
super.dispose();
|
|
42207
|
+
}
|
|
42208
|
+
_initialize() {
|
|
42209
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
|
|
42210
|
+
var _conversion$shouldTri;
|
|
42211
|
+
if (command.id === SetFormulaCalculationStartMutation.id) {
|
|
42212
|
+
this._executionInProgress = true;
|
|
42213
|
+
return;
|
|
42214
|
+
}
|
|
42215
|
+
if (command.id === SetFormulaCalculationNotificationMutation.id) {
|
|
42216
|
+
this._handleCalculationNotification(command.params);
|
|
42217
|
+
return;
|
|
42218
|
+
}
|
|
42219
|
+
const conversion = this._activeDirtyManagerService.get(command.id);
|
|
42220
|
+
if (!conversion) return;
|
|
42221
|
+
if (((_conversion$shouldTri = conversion.shouldTrigger) === null || _conversion$shouldTri === void 0 ? void 0 : _conversion$shouldTri.call(conversion, command, options)) === false) return;
|
|
42222
|
+
this._waitingCommandQueue.push(command);
|
|
42223
|
+
this._scheduleFlush();
|
|
42224
|
+
}));
|
|
42225
|
+
}
|
|
42226
|
+
_scheduleFlush() {
|
|
42227
|
+
if (!this._started || this._waitingCommandQueue.length === 0 && !this._hasPendingCalculation) return;
|
|
42228
|
+
clearTimeout(this._timer);
|
|
42229
|
+
this._timer = setTimeout(() => this._flush(), CALCULATION_DEBOUNCE_TIME);
|
|
42230
|
+
}
|
|
42231
|
+
_flush() {
|
|
42232
|
+
const commands = this._waitingCommandQueue;
|
|
42233
|
+
const dirtyData = this._generateDirty(commands);
|
|
42234
|
+
this._waitingCommandQueue = [];
|
|
42235
|
+
this._timer = void 0;
|
|
42236
|
+
if (hasDirtyData(dirtyData) || commands.some(({ id }) => id === SetTriggerFormulaCalculationStartMutation.id)) {
|
|
42237
|
+
this._pendingDirtyData = mergeDirtyData(this._pendingDirtyData, dirtyData);
|
|
42238
|
+
this._hasPendingCalculation = true;
|
|
42239
|
+
}
|
|
42240
|
+
if (!this._hasPendingCalculation) return;
|
|
42241
|
+
if (this._executionInProgress) {
|
|
42242
|
+
if (!this._stopRequested && dirtyDataIntersects(this._runningDirtyData, this._pendingDirtyData)) {
|
|
42243
|
+
this._stopRequested = true;
|
|
42244
|
+
this._commandService.executeCommand(SetFormulaCalculationStopMutation.id, {}, LOCAL_ONLY);
|
|
42245
|
+
}
|
|
42246
|
+
return;
|
|
42247
|
+
}
|
|
42248
|
+
this._startCalculation();
|
|
42249
|
+
}
|
|
42250
|
+
_startCalculation() {
|
|
42251
|
+
this._runningDirtyData = this._pendingDirtyData;
|
|
42252
|
+
this._pendingDirtyData = createEmptyDirtyData();
|
|
42253
|
+
this._hasPendingCalculation = false;
|
|
42254
|
+
this._executionInProgress = true;
|
|
42255
|
+
this._stopRequested = false;
|
|
42256
|
+
this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, { ...this._runningDirtyData }, LOCAL_ONLY);
|
|
42257
|
+
}
|
|
42258
|
+
_handleCalculationNotification(params) {
|
|
42259
|
+
if (params.stageInfo != null) {
|
|
42260
|
+
this._executionInProgress = true;
|
|
42261
|
+
return;
|
|
42262
|
+
}
|
|
42263
|
+
const state = params.functionsExecutedState;
|
|
42264
|
+
if (state == null) return;
|
|
42265
|
+
if (!(state === 1 || state === 3 || state === 2) || !this._executionInProgress) return;
|
|
42266
|
+
this._executionInProgress = false;
|
|
42267
|
+
this._stopRequested = false;
|
|
42268
|
+
if (state === 1) this._pendingDirtyData = mergeDirtyData(this._runningDirtyData, this._pendingDirtyData);
|
|
42269
|
+
this._runningDirtyData = createEmptyDirtyData();
|
|
42270
|
+
if (this._hasPendingCalculation || this._waitingCommandQueue.length > 0) this._scheduleFlush();
|
|
42271
|
+
}
|
|
42272
|
+
_generateDirty(commands) {
|
|
42273
|
+
return commands.reduce((result, command) => {
|
|
42274
|
+
const conversion = this._activeDirtyManagerService.get(command.id);
|
|
42275
|
+
return conversion ? mergeDirtyData(result, conversion.getDirtyData(command)) : result;
|
|
42276
|
+
}, createEmptyDirtyData());
|
|
42277
|
+
}
|
|
42278
|
+
};
|
|
42279
|
+
FormulaCalculationTriggerService = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, IActiveDirtyManagerService)], FormulaCalculationTriggerService);
|
|
42280
|
+
function createEmptyDirtyData() {
|
|
42281
|
+
return {
|
|
42282
|
+
forceCalculation: false,
|
|
42283
|
+
dirtyRanges: [],
|
|
42284
|
+
dirtyNameMap: {},
|
|
42285
|
+
dirtyDefinedNameMap: {},
|
|
42286
|
+
dirtySuperTableMap: {},
|
|
42287
|
+
dirtyUnitFeatureMap: {},
|
|
42288
|
+
dirtyUnitOtherFormulaMap: {},
|
|
42289
|
+
clearDependencyTreeCache: {}
|
|
42290
|
+
};
|
|
42291
|
+
}
|
|
42292
|
+
function mergeDirtyData(left, right) {
|
|
42293
|
+
var _right$dirtyRanges, _left$dirtySuperTable;
|
|
42294
|
+
const dirtyRanges = [...left.dirtyRanges];
|
|
42295
|
+
mergeDirtyRanges(dirtyRanges, (_right$dirtyRanges = right.dirtyRanges) !== null && _right$dirtyRanges !== void 0 ? _right$dirtyRanges : []);
|
|
42296
|
+
return {
|
|
42297
|
+
dirtyRanges,
|
|
42298
|
+
dirtyNameMap: mergeDirtyUnitStringMap(left.dirtyNameMap, right.dirtyNameMap),
|
|
42299
|
+
dirtyDefinedNameMap: mergeDirtyUnitStringMap(left.dirtyDefinedNameMap, right.dirtyDefinedNameMap),
|
|
42300
|
+
dirtySuperTableMap: mergeDirtyUnitStringMap((_left$dirtySuperTable = left.dirtySuperTableMap) !== null && _left$dirtySuperTable !== void 0 ? _left$dirtySuperTable : {}, right.dirtySuperTableMap),
|
|
42301
|
+
dirtyUnitFeatureMap: mergeDirtyUnitNestedMap(left.dirtyUnitFeatureMap, right.dirtyUnitFeatureMap),
|
|
42302
|
+
dirtyUnitOtherFormulaMap: mergeDirtyUnitNestedMap(left.dirtyUnitOtherFormulaMap, right.dirtyUnitOtherFormulaMap),
|
|
42303
|
+
clearDependencyTreeCache: mergeDirtyUnitStringMap(left.clearDependencyTreeCache, right.clearDependencyTreeCache),
|
|
42304
|
+
forceCalculation: left.forceCalculation || Boolean(right.forceCalculation)
|
|
42305
|
+
};
|
|
42306
|
+
}
|
|
42307
|
+
function mergeDirtyRanges(target, source) {
|
|
42308
|
+
const keys = new Set(target.map(getDirtyRangeKey));
|
|
42309
|
+
source.forEach((range) => {
|
|
42310
|
+
const key = getDirtyRangeKey(range);
|
|
42311
|
+
if (!keys.has(key)) {
|
|
42312
|
+
keys.add(key);
|
|
42313
|
+
target.push(range);
|
|
42314
|
+
}
|
|
42315
|
+
});
|
|
42316
|
+
}
|
|
42317
|
+
function getDirtyRangeKey({ unitId, sheetId, range }) {
|
|
42318
|
+
return JSON.stringify([
|
|
42319
|
+
unitId,
|
|
42320
|
+
sheetId,
|
|
42321
|
+
range.startRow,
|
|
42322
|
+
range.startColumn,
|
|
42323
|
+
range.endRow,
|
|
42324
|
+
range.endColumn,
|
|
42325
|
+
range.rangeType
|
|
42326
|
+
]);
|
|
42327
|
+
}
|
|
42328
|
+
function mergeDirtyUnitStringMap(left, right) {
|
|
42329
|
+
const result = { ...left };
|
|
42330
|
+
Object.entries(right !== null && right !== void 0 ? right : {}).forEach(([unitId, values]) => {
|
|
42331
|
+
result[unitId] = {
|
|
42332
|
+
...result[unitId],
|
|
42333
|
+
...values
|
|
42334
|
+
};
|
|
42335
|
+
});
|
|
42336
|
+
return result;
|
|
42337
|
+
}
|
|
42338
|
+
function mergeDirtyUnitNestedMap(left, right) {
|
|
42339
|
+
const result = { ...left };
|
|
42340
|
+
Object.entries(right !== null && right !== void 0 ? right : {}).forEach(([unitId, sheets]) => {
|
|
42341
|
+
const unitResult = { ...result[unitId] };
|
|
42342
|
+
Object.entries(sheets !== null && sheets !== void 0 ? sheets : {}).forEach(([sheetId, values]) => {
|
|
42343
|
+
unitResult[sheetId] = {
|
|
42344
|
+
...unitResult[sheetId],
|
|
42345
|
+
...values
|
|
42346
|
+
};
|
|
42347
|
+
});
|
|
42348
|
+
result[unitId] = unitResult;
|
|
42349
|
+
});
|
|
42350
|
+
return result;
|
|
42351
|
+
}
|
|
42352
|
+
function hasDirtyData(dirtyData) {
|
|
42353
|
+
return dirtyData.forceCalculation || dirtyData.dirtyRanges.length > 0 || hasNestedValue(dirtyData.dirtyNameMap) || hasNestedValue(dirtyData.dirtyDefinedNameMap) || hasNestedValue(dirtyData.dirtySuperTableMap) || hasNestedValue(dirtyData.dirtyUnitFeatureMap) || hasNestedValue(dirtyData.dirtyUnitOtherFormulaMap) || hasNestedValue(dirtyData.clearDependencyTreeCache);
|
|
42354
|
+
}
|
|
42355
|
+
function hasNestedValue(value) {
|
|
42356
|
+
if (value == null) return false;
|
|
42357
|
+
if (typeof value !== "object") return true;
|
|
42358
|
+
return Object.values(value).some(hasNestedValue);
|
|
42359
|
+
}
|
|
42360
|
+
function dirtyDataIntersects(left, right) {
|
|
42361
|
+
if (left.forceCalculation || right.forceCalculation) return true;
|
|
42362
|
+
if (left.dirtyRanges.some((leftRange) => right.dirtyRanges.some((rightRange) => leftRange.unitId === rightRange.unitId && leftRange.sheetId === rightRange.sheetId && _univerjs_core.Rectangle.intersects(leftRange.range, rightRange.range))) || clearedSheetIntersects(left, right) || clearedSheetIntersects(right, left)) return true;
|
|
42363
|
+
return [
|
|
42364
|
+
[left.dirtyNameMap, right.dirtyNameMap],
|
|
42365
|
+
[left.dirtyDefinedNameMap, right.dirtyDefinedNameMap],
|
|
42366
|
+
[left.dirtySuperTableMap, right.dirtySuperTableMap],
|
|
42367
|
+
[left.dirtyUnitFeatureMap, right.dirtyUnitFeatureMap],
|
|
42368
|
+
[left.dirtyUnitOtherFormulaMap, right.dirtyUnitOtherFormulaMap],
|
|
42369
|
+
[left.clearDependencyTreeCache, right.clearDependencyTreeCache]
|
|
42370
|
+
].some(([leftMap, rightMap]) => hasSameNestedKey(leftMap, rightMap));
|
|
42371
|
+
}
|
|
42372
|
+
function clearedSheetIntersects(cleared, dirty) {
|
|
42373
|
+
return Object.entries(cleared.clearDependencyTreeCache).some(([unitId, sheets]) => Object.keys(sheets !== null && sheets !== void 0 ? sheets : {}).some((sheetId) => {
|
|
42374
|
+
var _dirty$dirtyNameMap$u, _dirty$dirtyUnitFeatu, _dirty$dirtyUnitOther;
|
|
42375
|
+
return dirty.dirtyRanges.some((range) => range.unitId === unitId && range.sheetId === sheetId) || ((_dirty$dirtyNameMap$u = dirty.dirtyNameMap[unitId]) === null || _dirty$dirtyNameMap$u === void 0 ? void 0 : _dirty$dirtyNameMap$u[sheetId]) != null || ((_dirty$dirtyUnitFeatu = dirty.dirtyUnitFeatureMap[unitId]) === null || _dirty$dirtyUnitFeatu === void 0 ? void 0 : _dirty$dirtyUnitFeatu[sheetId]) != null || ((_dirty$dirtyUnitOther = dirty.dirtyUnitOtherFormulaMap[unitId]) === null || _dirty$dirtyUnitOther === void 0 ? void 0 : _dirty$dirtyUnitOther[sheetId]) != null;
|
|
42376
|
+
}));
|
|
42377
|
+
}
|
|
42378
|
+
function hasSameNestedKey(left, right) {
|
|
42379
|
+
if (left == null || right == null || typeof left !== "object" || typeof right !== "object") return left != null && right != null;
|
|
42380
|
+
const rightRecord = right;
|
|
42381
|
+
return Object.entries(left).some(([key, value]) => Object.prototype.hasOwnProperty.call(rightRecord, key) && hasSameNestedKey(value, rightRecord[key]));
|
|
42382
|
+
}
|
|
42383
|
+
|
|
42384
|
+
//#endregion
|
|
42385
|
+
//#region src/controllers/formula-calculation-trigger.controller.ts
|
|
42386
|
+
/**
|
|
42387
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
42388
|
+
*
|
|
42389
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
42390
|
+
* you may not use this file except in compliance with the License.
|
|
42391
|
+
* You may obtain a copy of the License at
|
|
42392
|
+
*
|
|
42393
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
42394
|
+
*
|
|
42395
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
42396
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
42397
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42398
|
+
* See the License for the specific language governing permissions and
|
|
42399
|
+
* limitations under the License.
|
|
42400
|
+
*/
|
|
42401
|
+
let FormulaCalculationTriggerController = class FormulaCalculationTriggerController extends _univerjs_core.Disposable {
|
|
42402
|
+
constructor(formulaCalculationTriggerService, lifecycleService) {
|
|
42403
|
+
super();
|
|
42404
|
+
if ((0, _univerjs_core.isNodeEnv)()) {
|
|
42405
|
+
formulaCalculationTriggerService.start();
|
|
42406
|
+
return;
|
|
42407
|
+
}
|
|
42408
|
+
this.disposeWithMe(lifecycleService.lifecycle$.pipe((0, rxjs.filter)((stage) => stage >= _univerjs_core.LifecycleStages.Rendered), (0, rxjs.take)(1)).subscribe(() => formulaCalculationTriggerService.start()));
|
|
42409
|
+
}
|
|
42410
|
+
};
|
|
42411
|
+
FormulaCalculationTriggerController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(FormulaCalculationTriggerService)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.LifecycleService))], FormulaCalculationTriggerController);
|
|
42412
|
+
|
|
40749
42413
|
//#endregion
|
|
40750
42414
|
//#region src/controllers/formula.controller.ts
|
|
40751
42415
|
let FormulaController = class FormulaController extends _univerjs_core.Disposable {
|
|
@@ -40967,38 +42631,6 @@ SetOtherFormulaController = __decorate([
|
|
|
40967
42631
|
__decorateParam(2, IDependencyManagerService)
|
|
40968
42632
|
], SetOtherFormulaController);
|
|
40969
42633
|
|
|
40970
|
-
//#endregion
|
|
40971
|
-
//#region src/services/active-dirty-manager.service.ts
|
|
40972
|
-
/**
|
|
40973
|
-
* Actively mark as dirty, calculate the dirty area based on the command,
|
|
40974
|
-
* and plugins can register the ref range they affect into the formula engine.
|
|
40975
|
-
*/
|
|
40976
|
-
var ActiveDirtyManagerService = class extends _univerjs_core.Disposable {
|
|
40977
|
-
constructor(..._args) {
|
|
40978
|
-
super(..._args);
|
|
40979
|
-
_defineProperty(this, "_dirtyConversionMap", /* @__PURE__ */ new Map());
|
|
40980
|
-
}
|
|
40981
|
-
dispose() {
|
|
40982
|
-
this._dirtyConversionMap.clear();
|
|
40983
|
-
}
|
|
40984
|
-
remove(commandId) {
|
|
40985
|
-
this._dirtyConversionMap.delete(commandId);
|
|
40986
|
-
}
|
|
40987
|
-
get(commandId) {
|
|
40988
|
-
return this._dirtyConversionMap.get(commandId);
|
|
40989
|
-
}
|
|
40990
|
-
has(commandId) {
|
|
40991
|
-
return this._dirtyConversionMap.has(commandId);
|
|
40992
|
-
}
|
|
40993
|
-
register(commandId, dirtyConversion) {
|
|
40994
|
-
this._dirtyConversionMap.set(commandId, dirtyConversion);
|
|
40995
|
-
}
|
|
40996
|
-
getDirtyConversionMap() {
|
|
40997
|
-
return this._dirtyConversionMap;
|
|
40998
|
-
}
|
|
40999
|
-
};
|
|
41000
|
-
const IActiveDirtyManagerService = (0, _univerjs_core.createIdentifier)("univer.formula.active-dirty-manager.service");
|
|
41001
|
-
|
|
41002
42634
|
//#endregion
|
|
41003
42635
|
//#region src/services/formula-common.ts
|
|
41004
42636
|
let FormulaResultStatus = /* @__PURE__ */ function(FormulaResultStatus) {
|
|
@@ -41199,7 +42831,11 @@ let UniverFormulaEnginePlugin = class UniverFormulaEnginePlugin extends _univerj
|
|
|
41199
42831
|
}
|
|
41200
42832
|
onReady() {
|
|
41201
42833
|
var _this$_config;
|
|
41202
|
-
(0, _univerjs_core.touchDependencies)(this._injector, [
|
|
42834
|
+
(0, _univerjs_core.touchDependencies)(this._injector, [
|
|
42835
|
+
[FormulaController],
|
|
42836
|
+
[FormulaCalculationTriggerController],
|
|
42837
|
+
[SuperTableActiveDirtyController]
|
|
42838
|
+
]);
|
|
41203
42839
|
if (!((_this$_config = this._config) === null || _this$_config === void 0 ? void 0 : _this$_config.notExecuteFormula)) (0, _univerjs_core.touchDependencies)(this._injector, [
|
|
41204
42840
|
[SetOtherFormulaController],
|
|
41205
42841
|
[SetFeatureCalculationController],
|
|
@@ -41217,6 +42853,7 @@ let UniverFormulaEnginePlugin = class UniverFormulaEnginePlugin extends _univerj
|
|
|
41217
42853
|
[IFunctionService, { useClass: FunctionService }],
|
|
41218
42854
|
[IDefinedNamesService, { useClass: DefinedNamesService }],
|
|
41219
42855
|
[IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }],
|
|
42856
|
+
[FormulaCalculationTriggerService],
|
|
41220
42857
|
[RegisterOtherFormulaService],
|
|
41221
42858
|
[IHyperlinkEngineFormulaService, { useClass: HyperlinkEngineFormulaService }],
|
|
41222
42859
|
[ISheetRowFilteredService, { useClass: SheetRowFilteredService }],
|
|
@@ -41224,6 +42861,8 @@ let UniverFormulaEnginePlugin = class UniverFormulaEnginePlugin extends _univerj
|
|
|
41224
42861
|
[GlobalComputingStatusService],
|
|
41225
42862
|
[FormulaDataModel],
|
|
41226
42863
|
[FormulaController],
|
|
42864
|
+
[FormulaCalculationTriggerController],
|
|
42865
|
+
[SuperTableActiveDirtyController],
|
|
41227
42866
|
[ComputingStatusReporterController]
|
|
41228
42867
|
];
|
|
41229
42868
|
if (shouldPerformComputing) dependencies.push([IOtherFormulaManagerService, { useClass: OtherFormulaManagerService }], [IFormulaRuntimeService, { useClass: FormulaRuntimeService }], [IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }], [IFeatureCalculationManagerService, { useClass: FeatureCalculationManagerService }], [CalculateController], [SetOtherFormulaController], [SetDependencyController], [SetFeatureCalculationController], [Interpreter], [AstTreeBuilder], [Lexer], [AstRootNodeFactory], [FunctionNodeFactory], [LambdaNodeFactory], [LambdaParameterNodeFactory], [OperatorNodeFactory], [PrefixNodeFactory], [ReferenceNodeFactory], [SuffixNodeFactory], [UnionNodeFactory], [ValueNodeFactory]);
|
|
@@ -41235,7 +42874,8 @@ let UniverFormulaEnginePlugin = class UniverFormulaEnginePlugin extends _univerj
|
|
|
41235
42874
|
if (!((_this$_config3 = this._config) === null || _this$_config3 === void 0 ? void 0 : _this$_config3.notExecuteFormula)) [
|
|
41236
42875
|
[ICalculateFormulaService, { useClass: CalculateFormulaService }],
|
|
41237
42876
|
[IDependencyManagerService, { useClass: DependencyManagerService }],
|
|
41238
|
-
[IFormulaDependencyGenerator, { useClass: FormulaDependencyGenerator }]
|
|
42877
|
+
[IFormulaDependencyGenerator, { useClass: FormulaDependencyGenerator }],
|
|
42878
|
+
[IFormulaUnitReferenceResolver, { useClass: FormulaUnitReferenceResolver }]
|
|
41239
42879
|
].forEach((dependency) => this._injector.add(dependency));
|
|
41240
42880
|
}
|
|
41241
42881
|
};
|
|
@@ -41316,6 +42956,12 @@ exports.FUNCTION_NAMES_TEXT = FUNCTION_NAMES_TEXT;
|
|
|
41316
42956
|
exports.FUNCTION_NAMES_UNIVER = FUNCTION_NAMES_UNIVER;
|
|
41317
42957
|
exports.FUNCTION_NAMES_WEB = FUNCTION_NAMES_WEB;
|
|
41318
42958
|
exports.FeatureCalculationManagerService = FeatureCalculationManagerService;
|
|
42959
|
+
Object.defineProperty(exports, 'FormulaCalculationTriggerService', {
|
|
42960
|
+
enumerable: true,
|
|
42961
|
+
get: function () {
|
|
42962
|
+
return FormulaCalculationTriggerService;
|
|
42963
|
+
}
|
|
42964
|
+
});
|
|
41319
42965
|
Object.defineProperty(exports, 'FormulaCurrentConfigService', {
|
|
41320
42966
|
enumerable: true,
|
|
41321
42967
|
get: function () {
|
|
@@ -41347,6 +42993,12 @@ Object.defineProperty(exports, 'FormulaRuntimeService', {
|
|
|
41347
42993
|
return FormulaRuntimeService;
|
|
41348
42994
|
}
|
|
41349
42995
|
});
|
|
42996
|
+
Object.defineProperty(exports, 'FormulaUnitReferenceResolver', {
|
|
42997
|
+
enumerable: true,
|
|
42998
|
+
get: function () {
|
|
42999
|
+
return FormulaUnitReferenceResolver;
|
|
43000
|
+
}
|
|
43001
|
+
});
|
|
41350
43002
|
Object.defineProperty(exports, 'FunctionNodeFactory', {
|
|
41351
43003
|
enumerable: true,
|
|
41352
43004
|
get: function () {
|
|
@@ -41370,6 +43022,7 @@ exports.IFeatureCalculationManagerService = IFeatureCalculationManagerService;
|
|
|
41370
43022
|
exports.IFormulaCurrentConfigService = IFormulaCurrentConfigService;
|
|
41371
43023
|
exports.IFormulaDependencyGenerator = IFormulaDependencyGenerator;
|
|
41372
43024
|
exports.IFormulaRuntimeService = IFormulaRuntimeService;
|
|
43025
|
+
exports.IFormulaUnitReferenceResolver = IFormulaUnitReferenceResolver;
|
|
41373
43026
|
exports.IFunctionService = IFunctionService;
|
|
41374
43027
|
exports.IHyperlinkEngineFormulaService = IHyperlinkEngineFormulaService;
|
|
41375
43028
|
exports.IOtherFormulaManagerService = IOtherFormulaManagerService;
|
|
@@ -41467,6 +43120,12 @@ Object.defineProperty(exports, 'SuffixNodeFactory', {
|
|
|
41467
43120
|
return SuffixNodeFactory;
|
|
41468
43121
|
}
|
|
41469
43122
|
});
|
|
43123
|
+
Object.defineProperty(exports, 'SuperTableActiveDirtyController', {
|
|
43124
|
+
enumerable: true,
|
|
43125
|
+
get: function () {
|
|
43126
|
+
return SuperTableActiveDirtyController;
|
|
43127
|
+
}
|
|
43128
|
+
});
|
|
41470
43129
|
exports.SuperTableService = SuperTableService;
|
|
41471
43130
|
Object.defineProperty(exports, 'UnionNodeFactory', {
|
|
41472
43131
|
enumerable: true,
|
|
@@ -41525,10 +43184,12 @@ exports.isReferenceStrings = isReferenceStrings;
|
|
|
41525
43184
|
exports.matchRefDrawToken = matchRefDrawToken;
|
|
41526
43185
|
exports.matchToken = matchToken;
|
|
41527
43186
|
exports.needsQuoting = needsQuoting;
|
|
43187
|
+
exports.normalizeFormulaUnitName = normalizeFormulaUnitName;
|
|
41528
43188
|
exports.normalizeSheetName = normalizeSheetName;
|
|
41529
43189
|
exports.operatorToken = operatorToken;
|
|
41530
43190
|
exports.prefixToken = prefixToken;
|
|
41531
43191
|
exports.quoteSheetName = quoteSheetName;
|
|
43192
|
+
exports.refactorFormulaUnitQualifier = refactorFormulaUnitQualifier;
|
|
41532
43193
|
exports.sequenceNodeType = sequenceNodeType;
|
|
41533
43194
|
exports.serializeRange = serializeRange;
|
|
41534
43195
|
exports.serializeRangeToRefString = serializeRangeToRefString;
|