@univerjs/sheets-formula 1.0.0-alpha.7 → 1.0.0-beta.0
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 +5 -35
- package/lib/cjs/index.js +48 -68
- package/lib/es/facade.js +4 -34
- package/lib/es/index.js +44 -64
- package/lib/facade.js +4 -34
- package/lib/index.js +44 -64
- package/lib/types/controllers/defined-name.controller.d.ts +1 -2
- package/lib/types/controllers/sheet-formula-calculation-result-apply.controller.d.ts +1 -1
- package/lib/types/controllers/super-table.controller.d.ts +1 -2
- package/lib/types/controllers/trigger-calculation.controller.d.ts +2 -3
- package/lib/types/facade/f-formula.d.ts +1 -2
- package/lib/types/facade/index.d.ts +0 -3
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +8 -9
- package/lib/types/facade/f-univer.d.ts +0 -49
package/lib/es/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { AbsoluteRefType, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, ICommandService, IConfigService, ILogService, IUndoRedoService, IUniverInstanceService, ImageSourceType, Inject, Injector, InterceptorEffectEnum, LocaleService, ObjectMatrix, Plugin, PositionedObjectLayoutType, RANGE_TYPE, Rectangle, Tools, UniverInstanceType, WrapTextType, cellToRange, createDocumentModelWithStyle, createIdentifier, generateRandomId, getIntersectRange, isFormulaId, isFormulaString, isNodeEnv, isRealNum, merge, moveRangeByOffset, sequenceExecute, sequenceExecuteAsync, toDisposable, touchDependencies } from "@univerjs/core";
|
|
2
2
|
import { AUTO_FILL_APPLY_TYPE, AUTO_FILL_DATA_TYPE, ClearSelectionFormatCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, EffectRefRangId, IAutoFillService, INTERCEPTOR_POINT, InsertColCommand, InsertColMutation, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, InsertRowMutation, InsertSheetMutation, InterceptCellContentPriority, MoveColsCommand, MoveColsMutation, MoveRangeCommand, MoveRangeMutation, MoveRowsCommand, MoveRowsMutation, RefRangeService, RemoveColCommand, RemoveColMutation, RemoveDefinedNameCommand, RemoveRowCommand, RemoveRowMutation, RemoveSheetCommand, RemoveSheetMutation, ReorderRangeMutation, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetBorderCommand, SetDefinedNameCommand, SetRangeCustomMetadataCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetRowHiddenMutation, SetRowVisibleMutation, SetSelectionsOperation, SetStyleCommand, SetWorkbookNameCommand, SetWorksheetActiveOperation, SetWorksheetNameCommand, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, alignToMergedCellsBorders, expandToContinuousRange, findFirstNonEmptyCell, getSeparateEffectedRangesOnCommand, getSheetCommandTarget, handleCommonDefaultRangeChangeWithEffectRefCommands, handleDefaultRangeChangeWithEffectRefCommands, handleDeleteRangeMoveLeft, handleDeleteRangeMoveUp, handleIRemoveCol, handleIRemoveRow, handleInsertCol, handleInsertRangeMoveDown, handleInsertRangeMoveRight, handleInsertRow, handleMoveCols, handleMoveRange, handleMoveRows, runRefRangeMutations } from "@univerjs/sheets";
|
|
3
|
-
import { AstTreeBuilder, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ErrorType, FormulaDataModel, FormulaExecuteStageType, FormulaExecutedStateType, FunctionType, IActiveDirtyManagerService, IDefinedNamesService, IFormulaCurrentConfigService, IFunctionService, ISuperTableService, Interpreter, Lexer, LexerTreeBuilder,
|
|
3
|
+
import { AstTreeBuilder, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ErrorType, FormulaCalculationSessionService, FormulaDataModel, FormulaExecuteStageType, FormulaExecutedStateType, FormulaResultApplicationType, FunctionType, IActiveDirtyManagerService, IDefinedNamesService, IDescriptionService, IFormulaCurrentConfigService, IFunctionService, ISuperTableService, Interpreter, Lexer, LexerTreeBuilder, RemoveDefinedNameMutation, RemoveSuperTableMutation, SetArrayFormulaDataMutation, SetDefinedNameMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaStringBatchCalculationMutation, SetImageFormulaDataMutation, SetSuperTableMutation, SetTriggerFormulaCalculationStartMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheetWithCache, generateExecuteAstNodeData, generateStringWithSequence, getObjectValue, initSheetFormulaData, refactorFormulaUnitQualifier, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, splitTableStructuredRef, stripErrorMargin } from "@univerjs/engine-formula";
|
|
4
4
|
import { buildDocTransform } from "@univerjs/docs";
|
|
5
5
|
import { BehaviorSubject, map } from "rxjs";
|
|
6
|
-
import { FormulaCalculationSessionService, FormulaResultApplicationType, IDescriptionService, UniverFormulaPlugin } from "@univerjs/formula";
|
|
7
6
|
import { IRPCChannelService, fromModule, toModule } from "@univerjs/rpc";
|
|
8
7
|
|
|
9
8
|
//#region src/commands/commands/insert-function.command.ts
|
|
@@ -29,7 +28,7 @@ const InsertFunctionCommand = {
|
|
|
29
28
|
const { primary, formula } = item;
|
|
30
29
|
cellMatrix.setValue(primary.row, primary.column, { f: formula });
|
|
31
30
|
});
|
|
32
|
-
const setRangeValuesParams = { value: cellMatrix.
|
|
31
|
+
const setRangeValuesParams = { value: cellMatrix.clone() };
|
|
33
32
|
return commandService.executeCommand(SetRangeValuesCommand.id, setRangeValuesParams);
|
|
34
33
|
}
|
|
35
34
|
};
|
|
@@ -154,7 +153,7 @@ const PLUGIN_CONFIG_KEY_MOBILE = "sheets-formula.mobile.config";
|
|
|
154
153
|
const configSymbolMobile = Symbol(PLUGIN_CONFIG_KEY_MOBILE);
|
|
155
154
|
|
|
156
155
|
//#endregion
|
|
157
|
-
//#region \0@oxc-project+runtime@0.
|
|
156
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
|
|
158
157
|
function __decorateParam(paramIndex, decorator) {
|
|
159
158
|
return function(target, key) {
|
|
160
159
|
decorator(target, key, paramIndex);
|
|
@@ -162,7 +161,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
162
161
|
}
|
|
163
162
|
|
|
164
163
|
//#endregion
|
|
165
|
-
//#region \0@oxc-project+runtime@0.
|
|
164
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
|
|
166
165
|
function __decorate(decorators, target, key, desc) {
|
|
167
166
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
168
167
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -276,7 +275,7 @@ function getDataLength(copyDataPiece) {
|
|
|
276
275
|
}
|
|
277
276
|
|
|
278
277
|
//#endregion
|
|
279
|
-
//#region \0@oxc-project+runtime@0.
|
|
278
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
|
|
280
279
|
function _typeof(o) {
|
|
281
280
|
"@babel/helpers - typeof";
|
|
282
281
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -287,7 +286,7 @@ function _typeof(o) {
|
|
|
287
286
|
}
|
|
288
287
|
|
|
289
288
|
//#endregion
|
|
290
|
-
//#region \0@oxc-project+runtime@0.
|
|
289
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
|
|
291
290
|
function toPrimitive(t, r) {
|
|
292
291
|
if ("object" != _typeof(t) || !t) return t;
|
|
293
292
|
var e = t[Symbol.toPrimitive];
|
|
@@ -300,14 +299,14 @@ function toPrimitive(t, r) {
|
|
|
300
299
|
}
|
|
301
300
|
|
|
302
301
|
//#endregion
|
|
303
|
-
//#region \0@oxc-project+runtime@0.
|
|
302
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
|
|
304
303
|
function toPropertyKey(t) {
|
|
305
304
|
var i = toPrimitive(t, "string");
|
|
306
305
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
307
306
|
}
|
|
308
307
|
|
|
309
308
|
//#endregion
|
|
310
|
-
//#region \0@oxc-project+runtime@0.
|
|
309
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
|
|
311
310
|
function _defineProperty(e, r, t) {
|
|
312
311
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
313
312
|
value: t,
|
|
@@ -501,7 +500,7 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
|
|
|
501
500
|
this._totalCalculationTaskCount = 0;
|
|
502
501
|
this._emitProgress();
|
|
503
502
|
}
|
|
504
|
-
constructor(_commandService, _univerInstanceService, _logService, _configService, _formulaDataModel, _localeService
|
|
503
|
+
constructor(_commandService, _univerInstanceService, _logService, _configService, _formulaDataModel, _localeService) {
|
|
505
504
|
super();
|
|
506
505
|
this._commandService = _commandService;
|
|
507
506
|
this._univerInstanceService = _univerInstanceService;
|
|
@@ -509,7 +508,6 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
|
|
|
509
508
|
this._configService = _configService;
|
|
510
509
|
this._formulaDataModel = _formulaDataModel;
|
|
511
510
|
this._localeService = _localeService;
|
|
512
|
-
this._registerOtherFormulaService = _registerOtherFormulaService;
|
|
513
511
|
_defineProperty(this, "_startExecutionTime", 0);
|
|
514
512
|
_defineProperty(this, "_totalCalculationTaskCount", 0);
|
|
515
513
|
_defineProperty(this, "_doneCalculationTaskCount", 0);
|
|
@@ -529,9 +527,8 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
|
|
|
529
527
|
this._progress$.complete();
|
|
530
528
|
}
|
|
531
529
|
_getCalculationMode() {
|
|
532
|
-
var _config$initialFormul;
|
|
533
530
|
const config = this._configService.getConfig(PLUGIN_CONFIG_KEY_BASE);
|
|
534
|
-
return (
|
|
531
|
+
return (config === null || config === void 0 ? void 0 : config.initialFormulaComputing) ?? 1;
|
|
535
532
|
}
|
|
536
533
|
_commandExecutedListener() {
|
|
537
534
|
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
@@ -619,9 +616,10 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
|
|
|
619
616
|
}
|
|
620
617
|
_initialExecuteFormula() {
|
|
621
618
|
const calculationMode = this._getCalculationMode();
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
619
|
+
if (calculationMode !== 2) {
|
|
620
|
+
const params = this._getDirtyDataByCalculationMode(calculationMode);
|
|
621
|
+
this._commandService.executeCommand(SetTriggerFormulaCalculationStartMutation.id, params, lo);
|
|
622
|
+
}
|
|
625
623
|
}
|
|
626
624
|
_getDirtyDataByCalculationMode(calculationMode) {
|
|
627
625
|
return {
|
|
@@ -642,8 +640,7 @@ TriggerCalculationController = __decorate([
|
|
|
642
640
|
__decorateParam(2, ILogService),
|
|
643
641
|
__decorateParam(3, IConfigService),
|
|
644
642
|
__decorateParam(4, Inject(FormulaDataModel)),
|
|
645
|
-
__decorateParam(5, Inject(LocaleService))
|
|
646
|
-
__decorateParam(6, Inject(RegisterOtherFormulaService))
|
|
643
|
+
__decorateParam(5, Inject(LocaleService))
|
|
647
644
|
], TriggerCalculationController);
|
|
648
645
|
|
|
649
646
|
//#endregion
|
|
@@ -657,7 +654,7 @@ function collectUnitQualifierFormulaPatches(workbook, oldName, newName) {
|
|
|
657
654
|
const formula = refactorFormulaUnitQualifier(cell.f, oldName, newName);
|
|
658
655
|
if (formula !== cell.f) updates.setValue(row, column, { f: formula });
|
|
659
656
|
});
|
|
660
|
-
const cellValue = updates.
|
|
657
|
+
const cellValue = updates.clone();
|
|
661
658
|
return Object.keys(cellValue).length > 0 ? [{
|
|
662
659
|
unitId,
|
|
663
660
|
subUnitId: sheet.getSheetId(),
|
|
@@ -695,8 +692,7 @@ let UnitQualifierRenameController = class UnitQualifierRenameController extends
|
|
|
695
692
|
if (!sheet) continue;
|
|
696
693
|
const undoCellValue = new ObjectMatrix();
|
|
697
694
|
new ObjectMatrix(patch.cellValue).forValue((row, column) => {
|
|
698
|
-
|
|
699
|
-
undoCellValue.setValue(row, column, (_sheet$getCellRaw = sheet.getCellRaw(row, column)) !== null && _sheet$getCellRaw !== void 0 ? _sheet$getCellRaw : null);
|
|
695
|
+
undoCellValue.setValue(row, column, sheet.getCellRaw(row, column) ?? null);
|
|
700
696
|
});
|
|
701
697
|
redos.push({
|
|
702
698
|
id: SetRangeValuesMutation.id,
|
|
@@ -706,12 +702,12 @@ let UnitQualifierRenameController = class UnitQualifierRenameController extends
|
|
|
706
702
|
id: SetRangeValuesMutation.id,
|
|
707
703
|
params: {
|
|
708
704
|
...patch,
|
|
709
|
-
cellValue: undoCellValue.
|
|
705
|
+
cellValue: undoCellValue.clone()
|
|
710
706
|
}
|
|
711
707
|
});
|
|
712
708
|
}
|
|
713
709
|
const definedNames = this._definedNamesService.getDefinedNameMap(workbook.getUnitId());
|
|
714
|
-
for (const item of Object.values(definedNames
|
|
710
|
+
for (const item of Object.values(definedNames ?? {})) {
|
|
715
711
|
const formulaOrRefString = refactorFormulaUnitQualifier(item.formulaOrRefString, oldName, newName);
|
|
716
712
|
if (formulaOrRefString !== item.formulaOrRefString) {
|
|
717
713
|
redos.push({
|
|
@@ -880,12 +876,11 @@ function getFormulaReferenceRange(oldFormulaData, newFormulaData, formulaReferen
|
|
|
880
876
|
* @returns
|
|
881
877
|
*/
|
|
882
878
|
function refRangeFormula(oldFormulaData, newFormulaData, formulaReferenceMoveParam) {
|
|
883
|
-
var _formulaReferenceMove, _formulaReferenceMove2;
|
|
884
879
|
const redoFormulaData = {};
|
|
885
880
|
const undoFormulaData = {};
|
|
886
881
|
const { unitId: fromUnitId, sheetId: fromSheetId } = formulaReferenceMoveParam;
|
|
887
|
-
const targetUnitId =
|
|
888
|
-
const targetSheetId =
|
|
882
|
+
const targetUnitId = formulaReferenceMoveParam.targetUnitId ?? fromUnitId;
|
|
883
|
+
const targetSheetId = formulaReferenceMoveParam.targetSheetId ?? fromSheetId;
|
|
889
884
|
const isCrossSheet = fromUnitId !== targetUnitId || fromSheetId !== targetSheetId;
|
|
890
885
|
(/* @__PURE__ */ new Set([...Object.keys(oldFormulaData), ...Object.keys(newFormulaData)])).forEach((unitId) => {
|
|
891
886
|
if (checkFormulaDataNull(oldFormulaData, unitId, fromSheetId)) return;
|
|
@@ -1110,8 +1105,7 @@ function getRedoFormulaData(rangeList, oldFormulaMatrix, newFormulaMatrix) {
|
|
|
1110
1105
|
si: null
|
|
1111
1106
|
});
|
|
1112
1107
|
if (newCell) {
|
|
1113
|
-
|
|
1114
|
-
const newValue = formulaDataItemToCellData((_newFormulaMatrix$get = newFormulaMatrix.getValue(oldCell.startRow, oldCell.startColumn)) !== null && _newFormulaMatrix$get !== void 0 ? _newFormulaMatrix$get : oldFormulaMatrix.getValue(oldCell.startRow, oldCell.startColumn));
|
|
1108
|
+
const newValue = formulaDataItemToCellData(newFormulaMatrix.getValue(oldCell.startRow, oldCell.startColumn) ?? oldFormulaMatrix.getValue(oldCell.startRow, oldCell.startColumn));
|
|
1115
1109
|
redoFormulaData.setValue(newCell.startRow, newCell.startColumn, newValue);
|
|
1116
1110
|
}
|
|
1117
1111
|
}
|
|
@@ -1131,7 +1125,7 @@ function getUndoFormulaData(rangeList, oldFormulaMatrix) {
|
|
|
1131
1125
|
undoFormulaData.setValue(oldCell.startRow, oldCell.startColumn, oldCellOldValue);
|
|
1132
1126
|
if (newCell) {
|
|
1133
1127
|
const newCellOldValue = formulaDataItemToCellData(oldFormulaMatrix.getValue(newCell.startRow, newCell.startColumn));
|
|
1134
|
-
undoFormulaData.setValue(newCell.startRow, newCell.startColumn, newCellOldValue
|
|
1128
|
+
undoFormulaData.setValue(newCell.startRow, newCell.startColumn, newCellOldValue ?? {
|
|
1135
1129
|
f: null,
|
|
1136
1130
|
si: null
|
|
1137
1131
|
});
|
|
@@ -1574,7 +1568,7 @@ function getReferenceMoveParams(workbook, command) {
|
|
|
1574
1568
|
result = handleRefRemoveRow(command, workbook);
|
|
1575
1569
|
break;
|
|
1576
1570
|
case RemoveColCommand.id:
|
|
1577
|
-
result = handleRefRemoveCol(command
|
|
1571
|
+
result = handleRefRemoveCol(command);
|
|
1578
1572
|
break;
|
|
1579
1573
|
case DeleteRangeMoveUpCommand.id:
|
|
1580
1574
|
result = handleRefDeleteRangeMoveUp(command, workbook);
|
|
@@ -1749,24 +1743,22 @@ function handleRefInsertRangeMoveDown(command, workbook) {
|
|
|
1749
1743
|
};
|
|
1750
1744
|
}
|
|
1751
1745
|
function handleRefRemoveRow(command, workbook) {
|
|
1752
|
-
var _workbook$getSheetByS3
|
|
1746
|
+
var _workbook$getSheetByS3;
|
|
1753
1747
|
const { params } = command;
|
|
1754
1748
|
if (!params) return null;
|
|
1755
|
-
const { range } = params;
|
|
1756
|
-
const { unitId, sheetId } = getCurrentSheetInfo(workbook);
|
|
1749
|
+
const { range, unitId, subUnitId: sheetId } = params;
|
|
1757
1750
|
return {
|
|
1758
1751
|
type: 5,
|
|
1759
1752
|
range,
|
|
1760
1753
|
unitId,
|
|
1761
1754
|
sheetId,
|
|
1762
|
-
rangeFilteredRows: (_workbook$getSheetByS3 =
|
|
1755
|
+
rangeFilteredRows: ((_workbook$getSheetByS3 = workbook.getSheetBySheetId(sheetId)) === null || _workbook$getSheetByS3 === void 0 ? void 0 : _workbook$getSheetByS3.getRangeFilterRows(range)) ?? []
|
|
1763
1756
|
};
|
|
1764
1757
|
}
|
|
1765
|
-
function handleRefRemoveCol(command
|
|
1758
|
+
function handleRefRemoveCol(command) {
|
|
1766
1759
|
const { params } = command;
|
|
1767
1760
|
if (!params) return null;
|
|
1768
|
-
const { range } = params;
|
|
1769
|
-
const { unitId, sheetId } = getCurrentSheetInfo(workbook);
|
|
1761
|
+
const { range, unitId, subUnitId: sheetId } = params;
|
|
1770
1762
|
return {
|
|
1771
1763
|
type: 6,
|
|
1772
1764
|
range,
|
|
@@ -1930,7 +1922,7 @@ let UpdateDefinedNameController = class UpdateDefinedNameController extends Disp
|
|
|
1930
1922
|
};
|
|
1931
1923
|
if (result.type === 12) {
|
|
1932
1924
|
var _this$_univerInstance;
|
|
1933
|
-
result.oldUnitName = (_this$_univerInstance = this._univerInstanceService.getUnit(result.unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.
|
|
1925
|
+
result.oldUnitName = (_this$_univerInstance = this._univerInstanceService.getUnit(result.unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.name;
|
|
1934
1926
|
}
|
|
1935
1927
|
return this._getUpdateDefinedNameMutations(workbook, result);
|
|
1936
1928
|
} }));
|
|
@@ -2137,7 +2129,6 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
|
|
|
2137
2129
|
this._commandService.executeCommand(SetFormulaDataMutation.id, { formulaData: newFormulaData }, { onlyLocal: true });
|
|
2138
2130
|
}
|
|
2139
2131
|
_handleWorkbookAdded(unit) {
|
|
2140
|
-
var _config$initialFormul;
|
|
2141
2132
|
const formulaData = {};
|
|
2142
2133
|
const unitId = unit.getUnitId();
|
|
2143
2134
|
const newFormulaData = { [unitId]: {} };
|
|
@@ -2150,7 +2141,7 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
|
|
|
2150
2141
|
});
|
|
2151
2142
|
this._commandService.executeCommand(SetFormulaDataMutation.id, { formulaData: newFormulaData }, { onlyLocal: true });
|
|
2152
2143
|
const config = this._configService.getConfig(PLUGIN_CONFIG_KEY_BASE);
|
|
2153
|
-
const calculationMode = (
|
|
2144
|
+
const calculationMode = (config === null || config === void 0 ? void 0 : config.initialFormulaComputing) ?? 1;
|
|
2154
2145
|
const params = this._getDirtyDataByCalculationMode(calculationMode);
|
|
2155
2146
|
this._commandService.executeCommand(SetTriggerFormulaCalculationStartMutation.id, params, { onlyLocal: true });
|
|
2156
2147
|
}
|
|
@@ -2293,7 +2284,7 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
|
|
|
2293
2284
|
};
|
|
2294
2285
|
shouldModify = true;
|
|
2295
2286
|
refChangeIds.push(i);
|
|
2296
|
-
if (si && (x
|
|
2287
|
+
if (si && (x ?? 0) === 0 && (y ?? 0) === 0) shouldModifySi.push(si);
|
|
2297
2288
|
}
|
|
2298
2289
|
/**
|
|
2299
2290
|
* If the reference sequence range is not affected by the move, and the move is a cross-worksheet cut operation, it may be necessary to rewrite the sheet name in the ref string after move, to make sure the ref still works after move.
|
|
@@ -2334,7 +2325,7 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
|
|
|
2334
2325
|
0
|
|
2335
2326
|
].includes(type)) {
|
|
2336
2327
|
if (from && from.startRow <= row && row <= from.endRow && from.startColumn <= column && column <= from.endColumn) {
|
|
2337
|
-
if ((x
|
|
2328
|
+
if ((x ?? 0) === 0 && (y ?? 0) === 0) shouldModifySi.push(si);
|
|
2338
2329
|
} else if (!shouldModifySi.includes(si)) return true;
|
|
2339
2330
|
} else return true;
|
|
2340
2331
|
if (inCrossSheetCutRange) {
|
|
@@ -2349,17 +2340,16 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
|
|
|
2349
2340
|
const newSequenceNodes = updateRefOffset(sequenceNodes, refChangeIds, x, y);
|
|
2350
2341
|
newFormulaDataItem.setValue(row, column, { f: `=${generateStringWithSequence(newSequenceNodes)}` });
|
|
2351
2342
|
});
|
|
2352
|
-
if (newFormulaData[unitId]) newFormulaData[unitId][sheetId] = newFormulaDataItem.
|
|
2343
|
+
if (newFormulaData[unitId]) newFormulaData[unitId][sheetId] = newFormulaDataItem.clone();
|
|
2353
2344
|
}
|
|
2354
2345
|
}
|
|
2355
2346
|
if (inCrossSheetCutRangeNewFormulas.length > 0 && targetUnitId && targetSheetId) {
|
|
2356
2347
|
if (!newFormulaData[targetUnitId]) newFormulaData[targetUnitId] = {};
|
|
2357
2348
|
if (!newFormulaData[targetUnitId][targetSheetId]) newFormulaData[targetUnitId][targetSheetId] = {};
|
|
2358
2349
|
for (const newFormula of inCrossSheetCutRangeNewFormulas) {
|
|
2359
|
-
var _to$startRow, _from$startRow, _to$startColumn, _from$startColumn;
|
|
2360
2350
|
const { fromRow, fromColumn, formulaString } = newFormula;
|
|
2361
|
-
const targetRow = fromRow + (((
|
|
2362
|
-
const targetColumn = fromColumn + (((
|
|
2351
|
+
const targetRow = fromRow + (((to === null || to === void 0 ? void 0 : to.startRow) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startRow) ?? 0));
|
|
2352
|
+
const targetColumn = fromColumn + (((to === null || to === void 0 ? void 0 : to.startColumn) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startColumn) ?? 0));
|
|
2363
2353
|
if (!newFormulaData[targetUnitId][targetSheetId][targetRow]) newFormulaData[targetUnitId][targetSheetId][targetRow] = {};
|
|
2364
2354
|
newFormulaData[targetUnitId][targetSheetId][targetRow][targetColumn] = { f: formulaString };
|
|
2365
2355
|
}
|
|
@@ -2425,7 +2415,7 @@ function tableReferenceContainsColumn(columnStruct, columnNames) {
|
|
|
2425
2415
|
//#endregion
|
|
2426
2416
|
//#region package.json
|
|
2427
2417
|
var name = "@univerjs/sheets-formula";
|
|
2428
|
-
var version = "1.0.0-
|
|
2418
|
+
var version = "1.0.0-beta.0";
|
|
2429
2419
|
|
|
2430
2420
|
//#endregion
|
|
2431
2421
|
//#region src/common/plugin-name.ts
|
|
@@ -2581,12 +2571,6 @@ let ActiveDirtyController = class ActiveDirtyController extends Disposable {
|
|
|
2581
2571
|
});
|
|
2582
2572
|
}
|
|
2583
2573
|
_initialSheet() {
|
|
2584
|
-
this._activeDirtyManagerService.register(SetTriggerFormulaCalculationStartMutation.id, {
|
|
2585
|
-
commandId: SetTriggerFormulaCalculationStartMutation.id,
|
|
2586
|
-
getDirtyData: (command) => {
|
|
2587
|
-
return { ...command.params };
|
|
2588
|
-
}
|
|
2589
|
-
});
|
|
2590
2574
|
this._activeDirtyManagerService.register(RemoveSheetMutation.id, {
|
|
2591
2575
|
commandId: RemoveSheetMutation.id,
|
|
2592
2576
|
getDirtyData: (command) => {
|
|
@@ -2645,8 +2629,8 @@ let ActiveDirtyController = class ActiveDirtyController extends Disposable {
|
|
|
2645
2629
|
_getMoveRowsMutationDirtyRange(params) {
|
|
2646
2630
|
const { subUnitId: sheetId, unitId, sourceRange, targetRange } = params;
|
|
2647
2631
|
const dirtyRanges = [];
|
|
2648
|
-
const sourceMatrix = this._rangeToMatrix(sourceRange).
|
|
2649
|
-
const targetMatrix = this._rangeToMatrix(targetRange).
|
|
2632
|
+
const sourceMatrix = this._rangeToMatrix(sourceRange).clone();
|
|
2633
|
+
const targetMatrix = this._rangeToMatrix(targetRange).clone();
|
|
2650
2634
|
dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, sourceMatrix));
|
|
2651
2635
|
dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, targetMatrix));
|
|
2652
2636
|
dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, targetMatrix));
|
|
@@ -2654,7 +2638,7 @@ let ActiveDirtyController = class ActiveDirtyController extends Disposable {
|
|
|
2654
2638
|
}
|
|
2655
2639
|
_getReorderRangeMutationDirtyRange(params) {
|
|
2656
2640
|
const { unitId, subUnitId: sheetId, range } = params;
|
|
2657
|
-
const matrix = this._rangeToMatrix(range).
|
|
2641
|
+
const matrix = this._rangeToMatrix(range).clone();
|
|
2658
2642
|
const dirtyRanges = [];
|
|
2659
2643
|
dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, matrix));
|
|
2660
2644
|
dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, matrix));
|
|
@@ -2663,7 +2647,7 @@ let ActiveDirtyController = class ActiveDirtyController extends Disposable {
|
|
|
2663
2647
|
_getRemoveRowOrColumnMutation(params, isRow = true) {
|
|
2664
2648
|
const { subUnitId: sheetId, unitId, range } = params;
|
|
2665
2649
|
const dirtyRanges = [];
|
|
2666
|
-
const workbook = this._univerInstanceService.
|
|
2650
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
2667
2651
|
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(sheetId);
|
|
2668
2652
|
const rowCount = (worksheet === null || worksheet === void 0 ? void 0 : worksheet.getRowCount()) || 0;
|
|
2669
2653
|
const columnCount = (worksheet === null || worksheet === void 0 ? void 0 : worksheet.getColumnCount()) || 0;
|
|
@@ -2681,7 +2665,7 @@ let ActiveDirtyController = class ActiveDirtyController extends Disposable {
|
|
|
2681
2665
|
endRow: rowCount,
|
|
2682
2666
|
endColumn
|
|
2683
2667
|
});
|
|
2684
|
-
const matrixData = matrix.
|
|
2668
|
+
const matrixData = matrix.clone();
|
|
2685
2669
|
dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, matrixData));
|
|
2686
2670
|
dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, matrixData));
|
|
2687
2671
|
return dirtyRanges;
|
|
@@ -2993,11 +2977,7 @@ let FormulaController = class FormulaController extends Disposable {
|
|
|
2993
2977
|
constructor(_commandService) {
|
|
2994
2978
|
super();
|
|
2995
2979
|
this._commandService = _commandService;
|
|
2996
|
-
[
|
|
2997
|
-
InsertFunctionCommand,
|
|
2998
|
-
QuickSumCommand,
|
|
2999
|
-
OtherFormulaMarkDirty
|
|
3000
|
-
].forEach((c) => this._commandService.registerCommand(c));
|
|
2980
|
+
[InsertFunctionCommand, QuickSumCommand].forEach((c) => this._commandService.registerCommand(c));
|
|
3001
2981
|
}
|
|
3002
2982
|
};
|
|
3003
2983
|
FormulaController = __decorate([__decorateParam(0, ICommandService)], FormulaController);
|
|
@@ -3562,7 +3542,7 @@ _defineProperty(UniverSheetsFormulaPlugin, "packageName", name);
|
|
|
3562
3542
|
_defineProperty(UniverSheetsFormulaPlugin, "version", version);
|
|
3563
3543
|
_defineProperty(UniverSheetsFormulaPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
3564
3544
|
UniverSheetsFormulaPlugin = __decorate([
|
|
3565
|
-
DependentOn(
|
|
3545
|
+
DependentOn(UniverFormulaEnginePlugin, UniverSheetsPlugin),
|
|
3566
3546
|
__decorateParam(1, Inject(Injector)),
|
|
3567
3547
|
__decorateParam(2, IConfigService)
|
|
3568
3548
|
], UniverSheetsFormulaPlugin);
|
package/lib/facade.js
CHANGED
|
@@ -1,38 +1,10 @@
|
|
|
1
1
|
import { IConfigService, ILogService, LifecycleService, LifecycleStages, debounce } from "@univerjs/core";
|
|
2
|
-
import {
|
|
3
|
-
import { FormulaDataModel, SetTriggerFormulaCalculationStartMutation, extractFormulaError } from "@univerjs/engine-formula";
|
|
4
|
-
import { IRegisterFunctionService } from "@univerjs/formula";
|
|
5
|
-
import "@univerjs/formula/facade";
|
|
2
|
+
import { FormulaDataModel, IRegisterFunctionService, SetTriggerFormulaCalculationStartMutation, extractFormulaError } from "@univerjs/engine-formula";
|
|
6
3
|
import { FFormula } from "@univerjs/engine-formula/facade";
|
|
7
4
|
import { CalculationMode, PLUGIN_CONFIG_KEY_BASE } from "@univerjs/sheets-formula";
|
|
5
|
+
import { FEnum } from "@univerjs/core/facade";
|
|
8
6
|
import { FRange, FWorkbook } from "@univerjs/sheets/facade";
|
|
9
7
|
|
|
10
|
-
//#region src/facade/f-univer.ts
|
|
11
|
-
/**
|
|
12
|
-
* @ignore
|
|
13
|
-
*/
|
|
14
|
-
var FUniverSheetsFormulaMixin = class extends FUniver {
|
|
15
|
-
/**
|
|
16
|
-
* Initialize the FUniver instance.
|
|
17
|
-
* @ignore
|
|
18
|
-
*/
|
|
19
|
-
_initialize() {
|
|
20
|
-
this._debouncedFormulaCalculation = debounce(() => {
|
|
21
|
-
this._commandService.executeCommand(SetTriggerFormulaCalculationStartMutation.id, {
|
|
22
|
-
commands: [],
|
|
23
|
-
forceCalculation: true
|
|
24
|
-
}, { onlyLocal: true });
|
|
25
|
-
}, 10);
|
|
26
|
-
}
|
|
27
|
-
registerFunction(config) {
|
|
28
|
-
const functionsDisposable = this._injector.get(IRegisterFunctionService).registerFunctions(config);
|
|
29
|
-
this._debouncedFormulaCalculation();
|
|
30
|
-
return functionsDisposable;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
FUniver.extend(FUniverSheetsFormulaMixin);
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
8
|
//#region src/facade/f-formula.ts
|
|
37
9
|
var FFormulaSheetsMixin = class extends FFormula {
|
|
38
10
|
/**
|
|
@@ -60,12 +32,11 @@ var FFormulaSheetsMixin = class extends FFormula {
|
|
|
60
32
|
config.initialFormulaComputing = calculationMode;
|
|
61
33
|
}
|
|
62
34
|
registerFunction(name, func, options) {
|
|
63
|
-
var _options$description;
|
|
64
35
|
const registerFunctionService = this._injector.get(IRegisterFunctionService);
|
|
65
36
|
const params = {
|
|
66
37
|
name,
|
|
67
38
|
func,
|
|
68
|
-
description: typeof options === "string" ? options : (
|
|
39
|
+
description: typeof options === "string" ? options : (options === null || options === void 0 ? void 0 : options.description) ?? "",
|
|
69
40
|
locales: typeof options === "object" ? options.locales : void 0
|
|
70
41
|
};
|
|
71
42
|
const functionsDisposable = registerFunctionService.registerFunction(params);
|
|
@@ -73,12 +44,11 @@ var FFormulaSheetsMixin = class extends FFormula {
|
|
|
73
44
|
return functionsDisposable;
|
|
74
45
|
}
|
|
75
46
|
registerAsyncFunction(name, func, options) {
|
|
76
|
-
var _options$description2;
|
|
77
47
|
const registerFunctionService = this._injector.get(IRegisterFunctionService);
|
|
78
48
|
const params = {
|
|
79
49
|
name,
|
|
80
50
|
func,
|
|
81
|
-
description: typeof options === "string" ? options : (
|
|
51
|
+
description: typeof options === "string" ? options : (options === null || options === void 0 ? void 0 : options.description) ?? "",
|
|
82
52
|
locales: typeof options === "object" ? options.locales : void 0
|
|
83
53
|
};
|
|
84
54
|
const functionsDisposable = registerFunctionService.registerAsyncFunction(params);
|