@univerjs/engine-formula 1.0.0-beta.0 → 1.0.0-beta.1
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/index.js +225 -130
- package/lib/es/index.js +227 -132
- package/lib/index.js +227 -132
- package/lib/types/basics/common.d.ts +2 -0
- package/lib/types/basics/regex.d.ts +4 -4
- package/lib/types/controllers/formula-calculation-trigger.controller.d.ts +1 -2
- package/lib/types/controllers/formula.controller.d.ts +1 -1
- package/lib/types/engine/value-object/array-value-object.d.ts +1 -1
- package/lib/types/functions/base-function.d.ts +2 -2
- package/lib/types/functions/logical/percentof/index.d.ts +5 -6
- package/lib/types/functions/lookup/xlookup/index.d.ts +4 -0
- package/lib/types/services/register-other-formula.service.d.ts +3 -3
- package/lib/types/services/runtime.service.d.ts +2 -0
- package/lib/umd/index.js +4 -4
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AbsoluteRefType, AsyncLock, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DataStreamTreeTokenType, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LRUMap, LifecycleService, LifecycleStages, LocaleService, LocaleType, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, Plugin, RANGE_TYPE, RTree, Rectangle, RichTextBuilder, Styles, Tools, UniverInstanceType, cellToRange, columnLabelToNumber, createIdentifier, generateRandomId, getNumfmtParseValueFilter, hashAlgorithm, isFormulaId, isFormulaString, isNodeEnv, isNullCell, isRealNum, isTextFormat, isValidRange, merge, moveRangeByOffset, numfmt, regexp, requestImmediateMacroTask, sortRules, toDisposable, touchDependencies } from "@univerjs/core";
|
|
1
|
+
import { AbsoluteRefType, AsyncLock, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DataStreamTreeTokenType, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LRUMap, LifecycleService, LifecycleStages, LocaleService, LocaleType, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, Plugin, RANGE_TYPE, RTree, Rectangle, RichTextBuilder, Styles, Tools, UniverInstanceType, cellToRange, columnLabelToNumber, createBaseFormulaTableNameMap, createIdentifier, generateRandomId, getBaseFormulaTableName, getNumfmtParseValueFilter, hashAlgorithm, isFormulaId, isFormulaString, isNodeEnv, isNullCell, isRealNum, isTextFormat, isValidRange, merge, moveRangeByOffset, numfmt, regexp, requestImmediateMacroTask, sortRules, toDisposable, touchDependencies } from "@univerjs/core";
|
|
2
2
|
import IntervalTree from "@flatten-js/interval-tree";
|
|
3
|
-
import { BehaviorSubject, Observable, Subject,
|
|
3
|
+
import { BehaviorSubject, Observable, Subject, combineLatest, distinctUntilChanged, filter, map, shareReplay, take } from "rxjs";
|
|
4
4
|
import Decimal from "decimal.js";
|
|
5
5
|
import { DataSyncPrimaryController } from "@univerjs/rpc";
|
|
6
6
|
|
|
@@ -1447,7 +1447,8 @@ const TABLE_NAME_REGEX = "((?![~!@#$%^&*()+<>?:,./;’,。、‘:“《》
|
|
|
1447
1447
|
const TABLE_TITLE_REGEX = "\\[#.+\\]\\s*?,\\s*?";
|
|
1448
1448
|
const TABLE_CONTENT_REGEX = "\\[[^#]*#?\\]";
|
|
1449
1449
|
const TABLE_MULTIPLE_COLUMN_REGEX = `${TABLE_CONTENT_REGEX}${RANGE_SYMBOL}${TABLE_CONTENT_REGEX}`;
|
|
1450
|
-
const
|
|
1450
|
+
const TABLE_BRACKETED_UNIT_QUALIFIER_REGEX = "\\[(?:[^\\]]|\\]\\])+\\]";
|
|
1451
|
+
const TABLE_UNIT_QUALIFIER_REGEX = `(?:(?:${TABLE_BRACKETED_UNIT_QUALIFIER_REGEX}|'(?:[^']|'')+'|[^\\s!\\[\\]]+)!)?(?:${TABLE_BRACKETED_UNIT_QUALIFIER_REGEX})?`;
|
|
1451
1452
|
const REFERENCE_TABLE_ALL_COLUMN_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}$`;
|
|
1452
1453
|
const REFERENCE_TABLE_SINGLE_COLUMN_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}(${TABLE_CONTENT_REGEX}|\\[${TABLE_TITLE_REGEX}${TABLE_CONTENT_REGEX}\\])+$`;
|
|
1453
1454
|
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}\\])?$`;
|
|
@@ -1904,8 +1905,13 @@ function splitTableStructuredRef(ref) {
|
|
|
1904
1905
|
}
|
|
1905
1906
|
quoteOpen = !quoteOpen;
|
|
1906
1907
|
} else if (!quoteOpen && char === "[") bracketDepth++;
|
|
1907
|
-
else if (!quoteOpen && char === "]")
|
|
1908
|
-
|
|
1908
|
+
else if (!quoteOpen && char === "]") {
|
|
1909
|
+
if (bracketDepth > 0 && tableRef[i + 1] === "]") {
|
|
1910
|
+
i++;
|
|
1911
|
+
continue;
|
|
1912
|
+
}
|
|
1913
|
+
bracketDepth--;
|
|
1914
|
+
} else if (!quoteOpen && bracketDepth === 0 && char === "!") {
|
|
1909
1915
|
qualifierEnd = i;
|
|
1910
1916
|
break;
|
|
1911
1917
|
}
|
|
@@ -1913,8 +1919,10 @@ function splitTableStructuredRef(ref) {
|
|
|
1913
1919
|
if (qualifierEnd >= 0) {
|
|
1914
1920
|
unitQualifier = tableRef.slice(0, qualifierEnd).trim();
|
|
1915
1921
|
tableRef = tableRef.slice(qualifierEnd + 1);
|
|
1916
|
-
|
|
1917
|
-
|
|
1922
|
+
const isQuotedQualifier = unitQualifier.startsWith("'") && unitQualifier.endsWith("'");
|
|
1923
|
+
const isBracketedQualifier = !isQuotedQualifier && unitQualifier.startsWith("[") && unitQualifier.endsWith("]");
|
|
1924
|
+
if (isQuotedQualifier) unitQualifier = unitQualifier.slice(1, -1);
|
|
1925
|
+
else if (isBracketedQualifier) unitQualifier = unitQualifier.slice(1, -1).replaceAll("]]", "]");
|
|
1918
1926
|
unitQualifier = unquoteSheetName(unitQualifier);
|
|
1919
1927
|
} else if (tableRef.startsWith("[")) {
|
|
1920
1928
|
const legacyQualifierEnd = tableRef.indexOf("]");
|
|
@@ -5079,9 +5087,11 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
|
|
|
5079
5087
|
const unitId = base.getUnitId();
|
|
5080
5088
|
formulaData[unitId] = {};
|
|
5081
5089
|
const tables = Object.values(snapshot.tables);
|
|
5090
|
+
const formulaTableNames = createBaseFormulaTableNameMap(snapshot);
|
|
5082
5091
|
for (let j = 0; j < tables.length; j++) {
|
|
5083
5092
|
const table = tables[j];
|
|
5084
5093
|
const tableFormulaData = {};
|
|
5094
|
+
const normalizedFormulaByFieldId = /* @__PURE__ */ new Map();
|
|
5085
5095
|
const recordOrder = table.recordOrder;
|
|
5086
5096
|
if (!recordOrder) {
|
|
5087
5097
|
formulaData[unitId][table.id] = tableFormulaData;
|
|
@@ -5097,9 +5107,14 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
|
|
|
5097
5107
|
if (!field || field.type !== "formula") continue;
|
|
5098
5108
|
const formula = String(((_field$config = field.config) === null || _field$config === void 0 ? void 0 : _field$config.formula) ?? "").trim();
|
|
5099
5109
|
if (!formula) continue;
|
|
5110
|
+
let normalizedFormula = normalizedFormulaByFieldId.get(field.id);
|
|
5111
|
+
if (normalizedFormula == null) {
|
|
5112
|
+
normalizedFormula = normalizeBaseFormulaForEngine(formula, table, snapshot, formulaTableNames);
|
|
5113
|
+
normalizedFormulaByFieldId.set(field.id, normalizedFormula);
|
|
5114
|
+
}
|
|
5100
5115
|
tableFormulaData[row] ??= {};
|
|
5101
5116
|
tableFormulaData[row][col] = {
|
|
5102
|
-
f:
|
|
5117
|
+
f: normalizedFormula,
|
|
5103
5118
|
si: field.id
|
|
5104
5119
|
};
|
|
5105
5120
|
}
|
|
@@ -5227,6 +5242,7 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
|
|
|
5227
5242
|
};
|
|
5228
5243
|
const baseData = {};
|
|
5229
5244
|
const tableNameMap = {};
|
|
5245
|
+
const formulaTableNames = createBaseFormulaTableNameMap(snapshot);
|
|
5230
5246
|
for (const table of Object.values(snapshot.tables)) {
|
|
5231
5247
|
var _table$recordOrder;
|
|
5232
5248
|
baseData[table.id] = {
|
|
@@ -5236,7 +5252,7 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
|
|
|
5236
5252
|
rowData: {},
|
|
5237
5253
|
columnData: {}
|
|
5238
5254
|
};
|
|
5239
|
-
tableNameMap
|
|
5255
|
+
addEngineBaseTableNameMappings(tableNameMap, table, formulaTableNames);
|
|
5240
5256
|
}
|
|
5241
5257
|
allUnitData[unitId] = baseData;
|
|
5242
5258
|
unitStylesData[unitId] = new Styles();
|
|
@@ -5580,28 +5596,47 @@ function initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix) {
|
|
|
5580
5596
|
return { [unitId]: { [sheetId]: newSheetFormulaData } };
|
|
5581
5597
|
}
|
|
5582
5598
|
const BASE_LEGACY_FIELD_REF_PATTERN = /\{([^}]+)\}/g;
|
|
5583
|
-
const
|
|
5584
|
-
const
|
|
5599
|
+
const BASE_TABLE_SCOPED_FIELD_REF_PATTERN = /\b([A-Z_][\w.]*)\[\[\s*#(This Row|Data)\s*\],\s*\[([^\]]+)\]\]/gi;
|
|
5600
|
+
const BASE_TABLE_CURRENT_ROW_FIELD_REF_PATTERN = /\b([A-Z_][\w.]*)\[@\[([^\]]+)\]\]/gi;
|
|
5601
|
+
const BASE_TABLE_FIELD_REF_PATTERN = /\b([A-Z_][\w.]*)\[([^\[\]#]+)\]/gi;
|
|
5602
|
+
const BASE_SCOPED_FIELD_REF_PATTERN = /(^|[^\w\[])\[\[\s*#(This Row|Data)\s*\],\s*\[([^\]]+)\]\]/gi;
|
|
5603
|
+
const BASE_CURRENT_ROW_FIELD_REF_PATTERN = /(^|[^\w\[])\[@\[([^\]]+)\]\](?!\])/g;
|
|
5604
|
+
const BASE_BRACKET_FIELD_REF_PATTERN = /(^|[^\w\[])\[@?([^\[\]#]+)\](?!\])/g;
|
|
5585
5605
|
const BASE_EXTERNAL_A1_REF_PATTERN = /(?:'\[[^\]]+\](?:[^']|'')+'|\[[^\]]+\][^\s'!]+)!\$?[A-Z]{1,3}\$?\d+(?::\$?[A-Z]{1,3}\$?\d+)?/gi;
|
|
5586
5606
|
const BASE_EXTERNAL_STRUCTURED_REFERENCE_PREFIX = /(?:'((?:[^']|'')+)'|\[[^\]]+\]|[A-Za-z0-9_.-]+)![^\s!\[\]]+\[/g;
|
|
5587
|
-
function normalizeBaseFormulaForEngine(formula, currentTable, snapshot) {
|
|
5607
|
+
function normalizeBaseFormulaForEngine(formula, currentTable, snapshot, formulaTableNames) {
|
|
5588
5608
|
const refs = [];
|
|
5589
5609
|
const hold = (ref) => {
|
|
5590
5610
|
return `__BASE_FORMULA_REF_${refs.push(ref) - 1}__`;
|
|
5591
5611
|
};
|
|
5592
|
-
return
|
|
5593
|
-
const targetTable = resolveBaseFormulaTable(sourceTableName, currentTable, snapshot);
|
|
5594
|
-
|
|
5595
|
-
|
|
5612
|
+
return protectBaseFormulaParts(formula, hold).replace(BASE_LEGACY_FIELD_REF_PATTERN, (_match, fieldName) => hold(createEngineThisRowRef(currentTable, fieldName, formulaTableNames))).replace(BASE_TABLE_SCOPED_FIELD_REF_PATTERN, (_match, sourceTableName, scope, fieldName) => {
|
|
5613
|
+
const targetTable = resolveBaseFormulaTable(sourceTableName, currentTable, snapshot, formulaTableNames);
|
|
5614
|
+
if (!targetTable) return `${sourceTableName}[[#${scope}],[${fieldName}]]`;
|
|
5615
|
+
return hold(scope.toLowerCase() === "data" ? createEngineColumnRef(targetTable, fieldName, formulaTableNames) : createEngineThisRowRef(targetTable, fieldName, formulaTableNames));
|
|
5616
|
+
}).replace(BASE_TABLE_CURRENT_ROW_FIELD_REF_PATTERN, (_match, sourceTableName, fieldName) => {
|
|
5617
|
+
const targetTable = resolveBaseFormulaTable(sourceTableName, currentTable, snapshot, formulaTableNames);
|
|
5618
|
+
return targetTable ? hold(createEngineThisRowRef(targetTable, fieldName, formulaTableNames)) : `${sourceTableName}[@[${fieldName}]]`;
|
|
5619
|
+
}).replace(BASE_SCOPED_FIELD_REF_PATTERN, (_match, prefix, scope, fieldName) => `${prefix}${hold(scope.toLowerCase() === "data" ? createEngineColumnRef(currentTable, fieldName, formulaTableNames) : createEngineThisRowRef(currentTable, fieldName, formulaTableNames))}`).replace(BASE_CURRENT_ROW_FIELD_REF_PATTERN, (_match, prefix, fieldName) => `${prefix}${hold(createEngineThisRowRef(currentTable, fieldName, formulaTableNames))}`).replace(BASE_TABLE_FIELD_REF_PATTERN, (_match, sourceTableName, fieldName) => {
|
|
5620
|
+
const targetTable = resolveBaseFormulaTable(sourceTableName, currentTable, snapshot, formulaTableNames);
|
|
5621
|
+
if (targetTable) return hold(createEngineColumnRef(targetTable, fieldName, formulaTableNames));
|
|
5622
|
+
return `${sourceTableName}[${fieldName}]`;
|
|
5623
|
+
}).replace(BASE_BRACKET_FIELD_REF_PATTERN, (_match, prefix, fieldName) => `${prefix}${hold(createEngineThisRowRef(currentTable, fieldName, formulaTableNames))}`).replace(/__BASE_FORMULA_REF_(\d+)__/g, (_match, index) => refs[Number(index)] ?? "");
|
|
5596
5624
|
}
|
|
5597
5625
|
function protectBaseExternalReferences(formula, replace) {
|
|
5598
5626
|
return protectBaseExternalStructuredReferences(formula.replace(BASE_EXTERNAL_A1_REF_PATTERN, (reference, offset) => isInsideBaseFormulaString(formula, offset) ? reference : replace(reference)), replace);
|
|
5599
5627
|
}
|
|
5628
|
+
function protectBaseFormulaParts(formula, replace) {
|
|
5629
|
+
return protectBaseFormulaStrings(protectBaseExternalReferences(formula, replace), replace);
|
|
5630
|
+
}
|
|
5631
|
+
function protectBaseFormulaStrings(formula, replace) {
|
|
5632
|
+
return formula.replace(/"(?:""|[^"])*"/g, replace);
|
|
5633
|
+
}
|
|
5600
5634
|
function protectBaseExternalStructuredReferences(formula, replace) {
|
|
5601
5635
|
const spans = [];
|
|
5602
5636
|
BASE_EXTERNAL_STRUCTURED_REFERENCE_PREFIX.lastIndex = 0;
|
|
5603
|
-
|
|
5604
|
-
|
|
5637
|
+
while (true) {
|
|
5638
|
+
const match = BASE_EXTERNAL_STRUCTURED_REFERENCE_PREFIX.exec(formula);
|
|
5639
|
+
if (match == null) break;
|
|
5605
5640
|
if (isInsideBaseFormulaString(formula, match.index)) continue;
|
|
5606
5641
|
const openBracket = BASE_EXTERNAL_STRUCTURED_REFERENCE_PREFIX.lastIndex - 1;
|
|
5607
5642
|
let depth = 0;
|
|
@@ -5641,20 +5676,20 @@ function isInsideBaseFormulaString(formula, position) {
|
|
|
5641
5676
|
}
|
|
5642
5677
|
return inString;
|
|
5643
5678
|
}
|
|
5644
|
-
function createEngineThisRowRef(table, fieldName,
|
|
5645
|
-
return `${
|
|
5679
|
+
function createEngineThisRowRef(table, fieldName, formulaTableNames) {
|
|
5680
|
+
return `${formulaTableNames.get(table.id) ?? getBaseFormulaTableName(table, { tables: { [table.id]: table } })}[[#This Row],[${fieldName}]]`;
|
|
5646
5681
|
}
|
|
5647
|
-
function createEngineColumnRef(table, fieldName,
|
|
5648
|
-
return `${
|
|
5682
|
+
function createEngineColumnRef(table, fieldName, formulaTableNames) {
|
|
5683
|
+
return `${formulaTableNames.get(table.id) ?? getBaseFormulaTableName(table, { tables: { [table.id]: table } })}[[#Data],[${fieldName}]]`;
|
|
5649
5684
|
}
|
|
5650
|
-
function
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5685
|
+
function addEngineBaseTableNameMappings(tableNameMap, table, formulaTableNames) {
|
|
5686
|
+
tableNameMap[formulaTableNames.get(table.id) ?? table.name] = table.id;
|
|
5687
|
+
}
|
|
5688
|
+
function createStableExcelTableName(tableId) {
|
|
5689
|
+
return `_T_${Array.from(tableId, (character) => {
|
|
5690
|
+
var _character$codePointA;
|
|
5691
|
+
return /[A-Za-z0-9]/.test(character) ? character : `_x${((_character$codePointA = character.codePointAt(0)) === null || _character$codePointA === void 0 ? void 0 : _character$codePointA.toString(16)) ?? "0"}_`;
|
|
5692
|
+
}).join("")}`;
|
|
5658
5693
|
}
|
|
5659
5694
|
function buildBaseRuntimeCellData(table) {
|
|
5660
5695
|
const cellData = { ...table.cellData };
|
|
@@ -5742,11 +5777,13 @@ function isArrayConstantFormula(formula) {
|
|
|
5742
5777
|
function isBaseCellData(value) {
|
|
5743
5778
|
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"));
|
|
5744
5779
|
}
|
|
5745
|
-
function resolveBaseFormulaTable(tableName, currentTable, snapshot) {
|
|
5746
|
-
if (!tableName
|
|
5747
|
-
const
|
|
5748
|
-
|
|
5749
|
-
|
|
5780
|
+
function resolveBaseFormulaTable(tableName, currentTable, snapshot, formulaTableNames) {
|
|
5781
|
+
if (!tableName) return currentTable;
|
|
5782
|
+
const normalizedName = tableName.toLowerCase();
|
|
5783
|
+
const matches = Object.values(snapshot.tables).filter((table) => {
|
|
5784
|
+
var _formulaTableNames$ge;
|
|
5785
|
+
return table.id.toLowerCase() === normalizedName || table.name.toLowerCase() === normalizedName || ((_formulaTableNames$ge = formulaTableNames.get(table.id)) === null || _formulaTableNames$ge === void 0 ? void 0 : _formulaTableNames$ge.toLowerCase()) === normalizedName || createStableExcelTableName(table.id).toLowerCase() === normalizedName;
|
|
5786
|
+
});
|
|
5750
5787
|
return matches.length === 1 ? matches[0] : void 0;
|
|
5751
5788
|
}
|
|
5752
5789
|
|
|
@@ -8130,11 +8167,16 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8130
8167
|
* the sequential matching approach is only used for special matches in XLOOKUP and XMATCH.
|
|
8131
8168
|
* For example, when match_mode is set to 1 and -1 for an exact match. If not found, it returns the next smaller item.
|
|
8132
8169
|
*/
|
|
8133
|
-
orderSearch(valueObject, searchType = 1, isDesc = false, isFuzzyMatching = false) {
|
|
8170
|
+
orderSearch(valueObject, searchType = 1, isDesc = false, isFuzzyMatching = false, keepFirstNearest = false) {
|
|
8134
8171
|
let result;
|
|
8135
8172
|
let maxOrMin;
|
|
8136
8173
|
let resultPosition;
|
|
8137
8174
|
let maxOrMinPosition;
|
|
8175
|
+
const _isNearer = (itemValue, currentValue) => {
|
|
8176
|
+
const distance = itemValue.minus(valueObject).abs();
|
|
8177
|
+
const currentDistance = currentValue.minus(valueObject).abs();
|
|
8178
|
+
return keepFirstNearest ? distance.isLessThan(currentDistance).getValue() === true : distance.isLessThanOrEqual(currentDistance).getValue() === true;
|
|
8179
|
+
};
|
|
8138
8180
|
const _handleMatch = (itemValue, row, column) => {
|
|
8139
8181
|
if (itemValue == null || itemValue.isNull()) return true;
|
|
8140
8182
|
let matchObject;
|
|
@@ -8151,7 +8193,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8151
8193
|
}
|
|
8152
8194
|
if (searchType === 2) {
|
|
8153
8195
|
if (itemValue.isGreaterThan(valueObject).getValue() === true) {
|
|
8154
|
-
if (maxOrMin == null || itemValue
|
|
8196
|
+
if (maxOrMin == null || _isNearer(itemValue, maxOrMin)) {
|
|
8155
8197
|
maxOrMin = itemValue;
|
|
8156
8198
|
maxOrMinPosition = {
|
|
8157
8199
|
row,
|
|
@@ -8161,7 +8203,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8161
8203
|
}
|
|
8162
8204
|
} else if (searchType === 1) {
|
|
8163
8205
|
if (itemValue.isLessThan(valueObject).getValue() === true) {
|
|
8164
|
-
if (maxOrMin == null || itemValue
|
|
8206
|
+
if (maxOrMin == null || _isNearer(itemValue, maxOrMin)) {
|
|
8165
8207
|
maxOrMin = itemValue;
|
|
8166
8208
|
maxOrMinPosition = {
|
|
8167
8209
|
row,
|
|
@@ -8664,11 +8706,12 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8664
8706
|
const sheetId = this.getSheetId();
|
|
8665
8707
|
const startRow = this.getCurrentRow();
|
|
8666
8708
|
const startColumn = this.getCurrentColumn();
|
|
8709
|
+
const isWildcardComparison = batchOperatorType === 5 && valueObject.isString() && isWildcard(String(valueObject.getValue()));
|
|
8667
8710
|
/**
|
|
8668
8711
|
* If comparison operations are conducted for a single numerical value,
|
|
8669
8712
|
* then retrieve the judgment from the inverted index. This enhances performance.
|
|
8670
8713
|
*/
|
|
8671
|
-
if (batchOperatorType === 5 && this._useInvertedIndexCache) {
|
|
8714
|
+
if (batchOperatorType === 5 && this._useInvertedIndexCache && !isWildcardComparison) {
|
|
8672
8715
|
const { rowsInCache, rowsNotInCache } = CELL_INVERTED_INDEX_CACHE.canUseCache(unitId, sheetId, column + startColumn, startRow, startRow + rowCount - 1);
|
|
8673
8716
|
if (rowsInCache.length > 0) {
|
|
8674
8717
|
if (operator === "=" && !(valueObject.isString() && isWildcard(valueObject.getValue()))) {
|
|
@@ -9056,6 +9099,7 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
9056
9099
|
}
|
|
9057
9100
|
setForcedSheetId(sheetNameMap) {
|
|
9058
9101
|
var _sheetNameMap$this$ge;
|
|
9102
|
+
if (!this._forcedSheetName) return;
|
|
9059
9103
|
this._forcedSheetId = (_sheetNameMap$this$ge = sheetNameMap[this.getUnitId()]) === null || _sheetNameMap$this$ge === void 0 ? void 0 : _sheetNameMap$this$ge[this._forcedSheetName];
|
|
9060
9104
|
}
|
|
9061
9105
|
setForcedSheetIdDirect(sheetId) {
|
|
@@ -9456,7 +9500,7 @@ var CellReferenceObject = class extends BaseReferenceObject {
|
|
|
9456
9500
|
unionBy(referenceObject) {
|
|
9457
9501
|
if (!referenceObject.isCell()) return ErrorValueObject.create("#REF!");
|
|
9458
9502
|
const cellReferenceObject = referenceObject;
|
|
9459
|
-
const newRangeData = this.unionRange(this.
|
|
9503
|
+
const newRangeData = this.unionRange(this.getRangePosition(), cellReferenceObject.getRangePosition());
|
|
9460
9504
|
return this._createRange(newRangeData);
|
|
9461
9505
|
}
|
|
9462
9506
|
unionRange(rangeData1, rangeData2) {
|
|
@@ -9498,8 +9542,6 @@ var CellReferenceObject = class extends BaseReferenceObject {
|
|
|
9498
9542
|
rangeReferenceObject.setArrayFormulaCellData(this.getArrayFormulaCellData());
|
|
9499
9543
|
rangeReferenceObject.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData());
|
|
9500
9544
|
rangeReferenceObject.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());
|
|
9501
|
-
const { x, y } = this.getRefOffset();
|
|
9502
|
-
rangeReferenceObject.setRefOffset(x, y);
|
|
9503
9545
|
const forceSheetId = this.getForcedSheetId();
|
|
9504
9546
|
rangeReferenceObject.setForcedSheetName(this.getForcedSheetName());
|
|
9505
9547
|
if (forceSheetId != null) rangeReferenceObject.setForcedSheetIdDirect(forceSheetId);
|
|
@@ -10255,6 +10297,9 @@ let FormulaRuntimeService = class FormulaRuntimeService extends Disposable {
|
|
|
10255
10297
|
this._functionRefInfoOverrideStack.pop();
|
|
10256
10298
|
};
|
|
10257
10299
|
}
|
|
10300
|
+
hasFunctionRefInfoOverride() {
|
|
10301
|
+
return this._functionRefInfoOverrideStack.length > 0;
|
|
10302
|
+
}
|
|
10258
10303
|
clearFunctionDefinitionPrivacyVar() {
|
|
10259
10304
|
this._functionDefinitionPrivacyVar.clear();
|
|
10260
10305
|
}
|
|
@@ -10711,7 +10756,7 @@ var PrefixNode = class extends BaseAstNode {
|
|
|
10711
10756
|
if (value instanceof ArrayValueObject) return value.get(0, 0) ?? ErrorValueObject.create("#VALUE!");
|
|
10712
10757
|
if (!value.isReferenceObject()) return value;
|
|
10713
10758
|
const currentValue = value;
|
|
10714
|
-
if (currentValue.isCell()) return
|
|
10759
|
+
if (currentValue.isCell()) return currentValue.getCellByPosition();
|
|
10715
10760
|
if (this._preserveAtRangeForFormula2LookupArray()) return currentValue;
|
|
10716
10761
|
const runtimeService = this._runtimeService;
|
|
10717
10762
|
const currentRow = runtimeService.currentRow || 0;
|
|
@@ -10876,6 +10921,7 @@ var FunctionNode = class extends BaseAstNode {
|
|
|
10876
10921
|
if (!this._functionExecutor.returnsLegacyArrayAsScalar || !isTopLevel || !result.isArray()) return result;
|
|
10877
10922
|
const array = result;
|
|
10878
10923
|
if (array.getRowCount() <= 1 && array.getColumnCount() <= 1) return result;
|
|
10924
|
+
if (this._runtimeService.hasFunctionRefInfoOverride() && (this._runtimeService.currentRowCount > 1 || this._runtimeService.currentColumnCount > 1)) return result;
|
|
10879
10925
|
return array.getFirstCell();
|
|
10880
10926
|
}
|
|
10881
10927
|
/**
|
|
@@ -11797,6 +11843,7 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11797
11843
|
const tableStartRow = range.startRow;
|
|
11798
11844
|
const tableEndRow = range.endRow;
|
|
11799
11845
|
const dataStartRow = tableStartRow + (this._tableData.showHeader === false ? 0 : 1);
|
|
11846
|
+
const dataEndRow = tableEndRow - (this._tableData.showFooter === true ? 1 : 0);
|
|
11800
11847
|
let startRow = -1;
|
|
11801
11848
|
let endRow = -1;
|
|
11802
11849
|
switch (type) {
|
|
@@ -11806,7 +11853,7 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11806
11853
|
break;
|
|
11807
11854
|
case "#Data":
|
|
11808
11855
|
startRow = dataStartRow;
|
|
11809
|
-
endRow =
|
|
11856
|
+
endRow = dataEndRow;
|
|
11810
11857
|
break;
|
|
11811
11858
|
case "#Headers":
|
|
11812
11859
|
if (this._tableData.showHeader === false) {
|
|
@@ -11822,14 +11869,14 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11822
11869
|
endRow = tableEndRow;
|
|
11823
11870
|
break;
|
|
11824
11871
|
case "#This Row": {
|
|
11825
|
-
const r = this._resolveThisRow(
|
|
11872
|
+
const r = this._resolveThisRow(dataStartRow, dataEndRow);
|
|
11826
11873
|
startRow = r;
|
|
11827
11874
|
endRow = r;
|
|
11828
11875
|
break;
|
|
11829
11876
|
}
|
|
11830
11877
|
default:
|
|
11831
11878
|
startRow = dataStartRow;
|
|
11832
|
-
endRow =
|
|
11879
|
+
endRow = dataEndRow;
|
|
11833
11880
|
break;
|
|
11834
11881
|
}
|
|
11835
11882
|
this.setRangeData({
|
|
@@ -11856,7 +11903,8 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
11856
11903
|
getCellData(row, column) {
|
|
11857
11904
|
if (this._isCurrentRowForRange) {
|
|
11858
11905
|
const { startRow, endRow } = this._tableData.range;
|
|
11859
|
-
|
|
11906
|
+
const lastCurrentRow = endRow - (this._tableData.showFooter === true ? 1 : 0);
|
|
11907
|
+
if (row < startRow || row > lastCurrentRow) return { v: "#N/A" };
|
|
11860
11908
|
}
|
|
11861
11909
|
return super.getCellData(row, column);
|
|
11862
11910
|
}
|
|
@@ -12061,9 +12109,9 @@ var TableReferenceObject = class extends BaseReferenceObject {
|
|
|
12061
12109
|
return -1;
|
|
12062
12110
|
}
|
|
12063
12111
|
/** Resolve #This Row's row number; takes first data row (tableStartRow+1) when no context available */
|
|
12064
|
-
_resolveThisRow(
|
|
12112
|
+
_resolveThisRow(dataStartRow, dataEndRow) {
|
|
12065
12113
|
this._isCurrentRowForRange = true;
|
|
12066
|
-
return Math.min(
|
|
12114
|
+
return Math.min(dataStartRow, dataEndRow);
|
|
12067
12115
|
}
|
|
12068
12116
|
};
|
|
12069
12117
|
|
|
@@ -15546,13 +15594,13 @@ let RegisterOtherFormulaService = class RegisterOtherFormulaService extends Disp
|
|
|
15546
15594
|
this._activeDirtyManagerService = _activeDirtyManagerService;
|
|
15547
15595
|
this._lifecycleService = _lifecycleService;
|
|
15548
15596
|
_defineProperty(this, "_formulaCacheMap", /* @__PURE__ */ new Map());
|
|
15597
|
+
_defineProperty(this, "_mutationSyncHandler", void 0);
|
|
15549
15598
|
_defineProperty(this, "_formulaChangeWithRange$", new Subject());
|
|
15550
15599
|
_defineProperty(this, "formulaChangeWithRange$", this._formulaChangeWithRange$.asObservable());
|
|
15551
15600
|
_defineProperty(this, "_formulaResult$", new Subject());
|
|
15552
15601
|
_defineProperty(this, "formulaResult$", this._formulaResult$.asObservable());
|
|
15553
15602
|
_defineProperty(this, "_otherFormulaResultApplied$", new Subject());
|
|
15554
15603
|
_defineProperty(this, "otherFormulaResultApplied$", this._otherFormulaResultApplied$.asObservable());
|
|
15555
|
-
_defineProperty(this, "calculateStarted$", new BehaviorSubject(false));
|
|
15556
15604
|
this._initFormulaRegister();
|
|
15557
15605
|
this._initFormulaCalculationResultChange();
|
|
15558
15606
|
}
|
|
@@ -15561,7 +15609,6 @@ let RegisterOtherFormulaService = class RegisterOtherFormulaService extends Disp
|
|
|
15561
15609
|
this._formulaChangeWithRange$.complete();
|
|
15562
15610
|
this._formulaResult$.complete();
|
|
15563
15611
|
this._otherFormulaResultApplied$.complete();
|
|
15564
|
-
this.calculateStarted$.complete();
|
|
15565
15612
|
}
|
|
15566
15613
|
_ensureCacheMap(unitId, subUnitId) {
|
|
15567
15614
|
let unitMap = this._formulaCacheMap.get(unitId);
|
|
@@ -15587,6 +15634,7 @@ let RegisterOtherFormulaService = class RegisterOtherFormulaService extends Disp
|
|
|
15587
15634
|
}
|
|
15588
15635
|
});
|
|
15589
15636
|
const handleRegister = (option) => {
|
|
15637
|
+
var _this$_mutationSyncHa;
|
|
15590
15638
|
const { unitId, subUnitId, formulaText, formulaId, ranges } = option;
|
|
15591
15639
|
if (!this._ensureCacheMap(unitId, subUnitId).has(formulaId)) return;
|
|
15592
15640
|
const params = {
|
|
@@ -15597,13 +15645,29 @@ let RegisterOtherFormulaService = class RegisterOtherFormulaService extends Disp
|
|
|
15597
15645
|
ranges
|
|
15598
15646
|
} }
|
|
15599
15647
|
};
|
|
15600
|
-
this.
|
|
15648
|
+
const waitForMutationSync = (_this$_mutationSyncHa = this._mutationSyncHandler) === null || _this$_mutationSyncHa === void 0 ? void 0 : _this$_mutationSyncHa.call(this, unitId);
|
|
15649
|
+
this._commandService.executeCommand(SetOtherFormulaMutation.id, params, { onlyLocal: true }).then(async () => {
|
|
15650
|
+
if (this._disposed) return;
|
|
15651
|
+
await (waitForMutationSync === null || waitForMutationSync === void 0 ? void 0 : waitForMutationSync());
|
|
15601
15652
|
if (this._disposed) return;
|
|
15602
15653
|
this._commandService.executeCommand(OtherFormulaMarkDirty.id, { [unitId]: { [subUnitId]: { [formulaId]: true } } }, { onlyLocal: true });
|
|
15603
15654
|
});
|
|
15604
15655
|
};
|
|
15605
|
-
this.disposeWithMe(this._formulaChangeWithRange$.
|
|
15606
|
-
|
|
15656
|
+
this.disposeWithMe(this._formulaChangeWithRange$.subscribe((option) => {
|
|
15657
|
+
if (this._commandService.hasCommand(SetOtherFormulaMutation.id) && this._commandService.hasCommand(OtherFormulaMarkDirty.id)) {
|
|
15658
|
+
handleRegister(option);
|
|
15659
|
+
return;
|
|
15660
|
+
}
|
|
15661
|
+
this._lifecycleService.onStage(LifecycleStages.Ready).then(() => {
|
|
15662
|
+
if (!this._disposed) handleRegister(option);
|
|
15663
|
+
});
|
|
15664
|
+
}));
|
|
15665
|
+
}
|
|
15666
|
+
setMutationSyncHandler(handler) {
|
|
15667
|
+
this._mutationSyncHandler = handler;
|
|
15668
|
+
return toDisposable(() => {
|
|
15669
|
+
if (this._mutationSyncHandler === handler) this._mutationSyncHandler = void 0;
|
|
15670
|
+
});
|
|
15607
15671
|
}
|
|
15608
15672
|
_initFormulaCalculationResultChange() {
|
|
15609
15673
|
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
@@ -15675,11 +15739,13 @@ let RegisterOtherFormulaService = class RegisterOtherFormulaService extends Disp
|
|
|
15675
15739
|
return Object.fromEntries(Array.from(unitMap.entries(), ([subUnitId, formulas]) => [subUnitId, Object.fromEntries(Array.from(formulas.keys(), (formulaId) => [formulaId, true]))]));
|
|
15676
15740
|
}
|
|
15677
15741
|
deleteFormula(unitId, subUnitId, formulaIdList) {
|
|
15742
|
+
var _this$_mutationSyncHa2;
|
|
15678
15743
|
const params = {
|
|
15679
15744
|
unitId,
|
|
15680
15745
|
subUnitId,
|
|
15681
15746
|
formulaIdList
|
|
15682
15747
|
};
|
|
15748
|
+
(_this$_mutationSyncHa2 = this._mutationSyncHandler) === null || _this$_mutationSyncHa2 === void 0 || _this$_mutationSyncHa2.call(this, unitId);
|
|
15683
15749
|
this._commandService.executeCommand(RemoveOtherFormulaMutation.id, params, { onlyLocal: true });
|
|
15684
15750
|
const cacheMap = this._ensureCacheMap(unitId, subUnitId);
|
|
15685
15751
|
formulaIdList.forEach((id) => cacheMap.delete(id));
|
|
@@ -16568,8 +16634,8 @@ var BaseFunction = class {
|
|
|
16568
16634
|
if (isFirst) return this._getOneFirstByRaw(resultArrayValue);
|
|
16569
16635
|
return this._getOneLastByRaw(resultArrayValue);
|
|
16570
16636
|
}
|
|
16571
|
-
orderSearch(value, searchArray, resultArray, searchType = 1, isDesc = false) {
|
|
16572
|
-
const position = searchArray.orderSearch(value, searchType, isDesc);
|
|
16637
|
+
orderSearch(value, searchArray, resultArray, searchType = 1, isDesc = false, keepFirstNearest = false) {
|
|
16638
|
+
const position = searchArray.orderSearch(value, searchType, isDesc, false, keepFirstNearest);
|
|
16573
16639
|
if (position == null) return ErrorValueObject.create("#N/A");
|
|
16574
16640
|
const resultValue = resultArray.get(position.row, position.column) || NullValueObject.create();
|
|
16575
16641
|
if (resultValue.isNull()) return ErrorValueObject.create("#N/A");
|
|
@@ -16599,8 +16665,8 @@ var BaseFunction = class {
|
|
|
16599
16665
|
if (axis === 0) return resultArray.slice([position.row, position.row + 1]);
|
|
16600
16666
|
return resultArray.slice(void 0, [position.column, position.column + 1]);
|
|
16601
16667
|
}
|
|
16602
|
-
orderSearchExpand(value, searchArray, resultArray, searchType = 1, isDesc = false, axis = 0) {
|
|
16603
|
-
const position = searchArray.orderSearch(value, searchType, isDesc);
|
|
16668
|
+
orderSearchExpand(value, searchArray, resultArray, searchType = 1, isDesc = false, axis = 0, keepFirstNearest = false) {
|
|
16669
|
+
const position = searchArray.orderSearch(value, searchType, isDesc, false, keepFirstNearest);
|
|
16604
16670
|
if (position == null) return ErrorValueObject.create("#N/A");
|
|
16605
16671
|
if (axis === 0) return resultArray.slice([position.row, position.row + 1]);
|
|
16606
16672
|
return resultArray.slice(void 0, [position.column, position.column + 1]);
|
|
@@ -30400,20 +30466,72 @@ var Or = class extends BaseFunction {
|
|
|
30400
30466
|
}
|
|
30401
30467
|
};
|
|
30402
30468
|
|
|
30469
|
+
//#endregion
|
|
30470
|
+
//#region src/functions/math/sum/index.ts
|
|
30471
|
+
var Sum = class extends BaseFunction {
|
|
30472
|
+
constructor(..._args) {
|
|
30473
|
+
super(..._args);
|
|
30474
|
+
_defineProperty(this, "minParams", 1);
|
|
30475
|
+
_defineProperty(this, "maxParams", 255);
|
|
30476
|
+
}
|
|
30477
|
+
calculate(...variants) {
|
|
30478
|
+
let accumulatorAll = NumberValueObject.create(0);
|
|
30479
|
+
for (let i = 0; i < variants.length; i++) {
|
|
30480
|
+
let variant = variants[i];
|
|
30481
|
+
variant = this._legacyImplicitDerivedArray(variant);
|
|
30482
|
+
if (variant.isString()) variant = variant.convertToNumberObjectValue();
|
|
30483
|
+
if (variant.isError()) return variant;
|
|
30484
|
+
if (variant.isArray()) variant = variant.sum();
|
|
30485
|
+
if (variant.isError()) return variant;
|
|
30486
|
+
accumulatorAll = accumulatorAll.plus(variant);
|
|
30487
|
+
if (accumulatorAll.isError()) return accumulatorAll;
|
|
30488
|
+
}
|
|
30489
|
+
return accumulatorAll;
|
|
30490
|
+
}
|
|
30491
|
+
_legacyImplicitDerivedArray(variant) {
|
|
30492
|
+
if (!variant.isArray()) return variant;
|
|
30493
|
+
const array = variant;
|
|
30494
|
+
if (array.usesInvertedIndexCache() || !array.usesLegacyImplicitForAggregate()) return variant;
|
|
30495
|
+
const startRow = array.getCurrentRow();
|
|
30496
|
+
const startColumn = array.getCurrentColumn();
|
|
30497
|
+
if (startRow < 0 || startColumn < 0) return variant;
|
|
30498
|
+
const rowCount = array.getRowCount();
|
|
30499
|
+
const columnCount = array.getColumnCount();
|
|
30500
|
+
let rowIndex = -1;
|
|
30501
|
+
let columnIndex = -1;
|
|
30502
|
+
if (rowCount === 1) {
|
|
30503
|
+
rowIndex = 0;
|
|
30504
|
+
columnIndex = this.column - startColumn;
|
|
30505
|
+
} else if (columnCount === 1) {
|
|
30506
|
+
rowIndex = this.row - startRow;
|
|
30507
|
+
columnIndex = 0;
|
|
30508
|
+
} else {
|
|
30509
|
+
rowIndex = this.row - startRow;
|
|
30510
|
+
columnIndex = this.column - startColumn;
|
|
30511
|
+
}
|
|
30512
|
+
if (rowIndex < 0 || rowIndex >= rowCount || columnIndex < 0 || columnIndex >= columnCount) return variant;
|
|
30513
|
+
return array.get(rowIndex, columnIndex) || variant;
|
|
30514
|
+
}
|
|
30515
|
+
};
|
|
30516
|
+
|
|
30403
30517
|
//#endregion
|
|
30404
30518
|
//#region src/functions/logical/percentof/index.ts
|
|
30405
30519
|
/**
|
|
30406
|
-
* PERCENTOF is
|
|
30407
|
-
*
|
|
30520
|
+
* PERCENTOF is logically equivalent to SUM(dataSubset) / SUM(dataAll).
|
|
30521
|
+
* GROUPBY also consumes the function name as an aggregator token through its AST path.
|
|
30408
30522
|
*/
|
|
30409
|
-
var Percentof = class extends
|
|
30523
|
+
var Percentof = class extends Sum {
|
|
30410
30524
|
constructor(..._args) {
|
|
30411
30525
|
super(..._args);
|
|
30412
|
-
_defineProperty(this, "minParams",
|
|
30413
|
-
_defineProperty(this, "maxParams",
|
|
30526
|
+
_defineProperty(this, "minParams", 2);
|
|
30527
|
+
_defineProperty(this, "maxParams", 2);
|
|
30414
30528
|
}
|
|
30415
|
-
calculate(
|
|
30416
|
-
|
|
30529
|
+
calculate(dataSubset, dataAll) {
|
|
30530
|
+
const subsetTotal = super.calculate(dataSubset);
|
|
30531
|
+
if (subsetTotal.isError()) return subsetTotal;
|
|
30532
|
+
const allTotal = super.calculate(dataAll);
|
|
30533
|
+
if (allTotal.isError()) return allTotal;
|
|
30534
|
+
return subsetTotal.divided(allTotal);
|
|
30417
30535
|
}
|
|
30418
30536
|
};
|
|
30419
30537
|
|
|
@@ -32981,8 +33099,8 @@ var Xlookup = class extends BaseFunction {
|
|
|
32981
33099
|
return this.binarySearchExpand(value, searchArray, resultArray, axis, searchType, matchType);
|
|
32982
33100
|
}
|
|
32983
33101
|
if (matchModeValue === 2) return this.fuzzySearchExpand(value, searchArray, resultArray, searchModeValue !== -1, axis);
|
|
32984
|
-
if (matchModeValue === -1 || matchModeValue === 1) return this.orderSearchExpand(value, searchArray, resultArray, matchModeValue === 1 ? 2 : 1, searchModeValue === -1, axis);
|
|
32985
|
-
return this.
|
|
33102
|
+
if (matchModeValue === -1 || matchModeValue === 1) return this.orderSearchExpand(value, searchArray, resultArray, matchModeValue === 1 ? 2 : 1, searchModeValue === -1, axis, true);
|
|
33103
|
+
return this._exactSearchExpand(value, searchArray, resultArray, searchModeValue !== -1, axis);
|
|
32986
33104
|
}
|
|
32987
33105
|
_handleSingleObject(value, searchArray, resultArray, matchModeValue, searchModeValue) {
|
|
32988
33106
|
if ((searchModeValue === 2 || searchModeValue === -2) && matchModeValue !== 2) {
|
|
@@ -32991,8 +33109,38 @@ var Xlookup = class extends BaseFunction {
|
|
|
32991
33109
|
return this.binarySearch(value, searchArray, resultArray, searchType, matchType);
|
|
32992
33110
|
}
|
|
32993
33111
|
if (matchModeValue === 2) return this.fuzzySearch(value, searchArray, resultArray, searchModeValue !== -1);
|
|
32994
|
-
if (matchModeValue === -1 || matchModeValue === 1) return this.orderSearch(value, searchArray, resultArray, matchModeValue === 1 ? 2 : 1, searchModeValue === -1);
|
|
32995
|
-
return this.
|
|
33112
|
+
if (matchModeValue === -1 || matchModeValue === 1) return this.orderSearch(value, searchArray, resultArray, matchModeValue === 1 ? 2 : 1, searchModeValue === -1, true);
|
|
33113
|
+
return this._exactSearch(value, searchArray, resultArray, searchModeValue !== -1);
|
|
33114
|
+
}
|
|
33115
|
+
_exactSearch(value, searchArray, resultArray, isFirst) {
|
|
33116
|
+
const position = this._findExactPosition(value, searchArray, isFirst);
|
|
33117
|
+
if (position == null) return ErrorValueObject.create("#N/A");
|
|
33118
|
+
return resultArray.get(position.row, position.column) ?? ErrorValueObject.create("#N/A");
|
|
33119
|
+
}
|
|
33120
|
+
_exactSearchExpand(value, searchArray, resultArray, isFirst, axis) {
|
|
33121
|
+
const position = this._findExactPosition(value, searchArray, isFirst);
|
|
33122
|
+
if (position == null) return ErrorValueObject.create("#N/A");
|
|
33123
|
+
return axis === 0 ? resultArray.slice([position.row, position.row + 1]) ?? ErrorValueObject.create("#N/A") : resultArray.slice(void 0, [position.column, position.column + 1]) ?? ErrorValueObject.create("#N/A");
|
|
33124
|
+
}
|
|
33125
|
+
_findExactPosition(value, searchArray, isFirst) {
|
|
33126
|
+
let position;
|
|
33127
|
+
const find = (candidate, row, column) => {
|
|
33128
|
+
if (candidate != null && this._isExactMatch(candidate, value)) {
|
|
33129
|
+
position = {
|
|
33130
|
+
row,
|
|
33131
|
+
column
|
|
33132
|
+
};
|
|
33133
|
+
return false;
|
|
33134
|
+
}
|
|
33135
|
+
};
|
|
33136
|
+
if (isFirst) searchArray.iterator(find);
|
|
33137
|
+
else searchArray.iteratorReverse(find);
|
|
33138
|
+
return position;
|
|
33139
|
+
}
|
|
33140
|
+
_isExactMatch(candidate, value) {
|
|
33141
|
+
if (candidate.isError() || value.isError()) return candidate.isError() && value.isError() && candidate.getValue() === value.getValue();
|
|
33142
|
+
if (candidate.isNull() !== value.isNull() || candidate.isNumber() !== value.isNumber() || candidate.isString() !== value.isString() || candidate.isBoolean() !== value.isBoolean()) return false;
|
|
33143
|
+
return candidate.isEqual(value).getValue() === true;
|
|
32996
33144
|
}
|
|
32997
33145
|
_blankResultAsZero(value) {
|
|
32998
33146
|
if (value.isNull()) return NumberValueObject.create(0);
|
|
@@ -35559,54 +35707,6 @@ var Subtotal = class extends BaseFunction {
|
|
|
35559
35707
|
}
|
|
35560
35708
|
};
|
|
35561
35709
|
|
|
35562
|
-
//#endregion
|
|
35563
|
-
//#region src/functions/math/sum/index.ts
|
|
35564
|
-
var Sum = class extends BaseFunction {
|
|
35565
|
-
constructor(..._args) {
|
|
35566
|
-
super(..._args);
|
|
35567
|
-
_defineProperty(this, "minParams", 1);
|
|
35568
|
-
_defineProperty(this, "maxParams", 255);
|
|
35569
|
-
}
|
|
35570
|
-
calculate(...variants) {
|
|
35571
|
-
let accumulatorAll = NumberValueObject.create(0);
|
|
35572
|
-
for (let i = 0; i < variants.length; i++) {
|
|
35573
|
-
let variant = variants[i];
|
|
35574
|
-
variant = this._legacyImplicitDerivedArray(variant);
|
|
35575
|
-
if (variant.isString()) variant = variant.convertToNumberObjectValue();
|
|
35576
|
-
if (variant.isError()) return variant;
|
|
35577
|
-
if (variant.isArray()) variant = variant.sum();
|
|
35578
|
-
if (variant.isError()) return variant;
|
|
35579
|
-
accumulatorAll = accumulatorAll.plus(variant);
|
|
35580
|
-
if (accumulatorAll.isError()) return accumulatorAll;
|
|
35581
|
-
}
|
|
35582
|
-
return accumulatorAll;
|
|
35583
|
-
}
|
|
35584
|
-
_legacyImplicitDerivedArray(variant) {
|
|
35585
|
-
if (!variant.isArray()) return variant;
|
|
35586
|
-
const array = variant;
|
|
35587
|
-
if (array.usesInvertedIndexCache() || !array.usesLegacyImplicitForAggregate()) return variant;
|
|
35588
|
-
const startRow = array.getCurrentRow();
|
|
35589
|
-
const startColumn = array.getCurrentColumn();
|
|
35590
|
-
if (startRow < 0 || startColumn < 0) return variant;
|
|
35591
|
-
const rowCount = array.getRowCount();
|
|
35592
|
-
const columnCount = array.getColumnCount();
|
|
35593
|
-
let rowIndex = -1;
|
|
35594
|
-
let columnIndex = -1;
|
|
35595
|
-
if (rowCount === 1) {
|
|
35596
|
-
rowIndex = 0;
|
|
35597
|
-
columnIndex = this.column - startColumn;
|
|
35598
|
-
} else if (columnCount === 1) {
|
|
35599
|
-
rowIndex = this.row - startRow;
|
|
35600
|
-
columnIndex = 0;
|
|
35601
|
-
} else {
|
|
35602
|
-
rowIndex = this.row - startRow;
|
|
35603
|
-
columnIndex = this.column - startColumn;
|
|
35604
|
-
}
|
|
35605
|
-
if (rowIndex < 0 || rowIndex >= rowCount || columnIndex < 0 || columnIndex >= columnCount) return variant;
|
|
35606
|
-
return array.get(rowIndex, columnIndex) || variant;
|
|
35607
|
-
}
|
|
35608
|
-
};
|
|
35609
|
-
|
|
35610
35710
|
//#endregion
|
|
35611
35711
|
//#region src/functions/math/sumif/index.ts
|
|
35612
35712
|
var Sumif = class extends BaseFunction {
|
|
@@ -42977,7 +43077,7 @@ function getObjectValue(result, isUseStrip = false) {
|
|
|
42977
43077
|
//#endregion
|
|
42978
43078
|
//#region package.json
|
|
42979
43079
|
var name = "@univerjs/engine-formula";
|
|
42980
|
-
var version = "1.0.0-beta.
|
|
43080
|
+
var version = "1.0.0-beta.1";
|
|
42981
43081
|
|
|
42982
43082
|
//#endregion
|
|
42983
43083
|
//#region src/services/global-computing-status.service.ts
|
|
@@ -43277,12 +43377,9 @@ function hasSameNestedKey(left, right) {
|
|
|
43277
43377
|
* limitations under the License.
|
|
43278
43378
|
*/
|
|
43279
43379
|
let FormulaCalculationTriggerController = class FormulaCalculationTriggerController extends Disposable {
|
|
43280
|
-
constructor(formulaCalculationTriggerService,
|
|
43380
|
+
constructor(formulaCalculationTriggerService, lifecycleService) {
|
|
43281
43381
|
super();
|
|
43282
|
-
const start = () =>
|
|
43283
|
-
formulaCalculationTriggerService.start();
|
|
43284
|
-
registerOtherFormulaService.calculateStarted$.next(true);
|
|
43285
|
-
};
|
|
43382
|
+
const start = () => formulaCalculationTriggerService.start();
|
|
43286
43383
|
if (isNodeEnv()) {
|
|
43287
43384
|
start();
|
|
43288
43385
|
return;
|
|
@@ -43290,11 +43387,7 @@ let FormulaCalculationTriggerController = class FormulaCalculationTriggerControl
|
|
|
43290
43387
|
this.disposeWithMe(lifecycleService.lifecycle$.pipe(filter((stage) => stage >= LifecycleStages.Rendered), take(1)).subscribe(start));
|
|
43291
43388
|
}
|
|
43292
43389
|
};
|
|
43293
|
-
FormulaCalculationTriggerController = __decorate([
|
|
43294
|
-
__decorateParam(0, Inject(FormulaCalculationTriggerService)),
|
|
43295
|
-
__decorateParam(1, Inject(RegisterOtherFormulaService)),
|
|
43296
|
-
__decorateParam(2, Inject(LifecycleService))
|
|
43297
|
-
], FormulaCalculationTriggerController);
|
|
43390
|
+
FormulaCalculationTriggerController = __decorate([__decorateParam(0, Inject(FormulaCalculationTriggerService)), __decorateParam(1, Inject(LifecycleService))], FormulaCalculationTriggerController);
|
|
43298
43391
|
|
|
43299
43392
|
//#endregion
|
|
43300
43393
|
//#region src/controllers/formula.controller.ts
|
|
@@ -43317,10 +43410,12 @@ let FormulaController = class FormulaController extends Disposable {
|
|
|
43317
43410
|
_syncOtherFormulaUnits() {
|
|
43318
43411
|
const dataSyncPrimaryController = this._dataSyncPrimaryController;
|
|
43319
43412
|
if (!dataSyncPrimaryController) return;
|
|
43320
|
-
this.disposeWithMe(this._registerOtherFormulaService.
|
|
43321
|
-
if (this._syncedOtherFormulaUnits.has(unitId))
|
|
43322
|
-
|
|
43323
|
-
|
|
43413
|
+
this.disposeWithMe(this._registerOtherFormulaService.setMutationSyncHandler((unitId) => {
|
|
43414
|
+
if (!this._syncedOtherFormulaUnits.has(unitId)) {
|
|
43415
|
+
this._syncedOtherFormulaUnits.add(unitId);
|
|
43416
|
+
this.disposeWithMe(dataSyncPrimaryController.syncUnitMutations(unitId));
|
|
43417
|
+
}
|
|
43418
|
+
return () => dataSyncPrimaryController.waitForPendingMutations();
|
|
43324
43419
|
}));
|
|
43325
43420
|
}
|
|
43326
43421
|
_registerCommands() {
|