@univerjs/sheets-formula 1.4.0 → 1.5.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.
@@ -1,7 +1,5 @@
1
1
  let _univerjs_core = require("@univerjs/core");
2
2
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
3
- let _univerjs_rpc = require("@univerjs/rpc");
4
- let _univerjs_engine_formula_worker = require("@univerjs/engine-formula/worker");
5
3
 
6
4
  // src/config/config.ts
7
5
  /**
@@ -37,14 +35,14 @@ const defaultPluginRemoteConfig = {};
37
35
  const PLUGIN_CONFIG_KEY_MOBILE = "sheets-formula.mobile.config";
38
36
  const configSymbolMobile = Symbol(PLUGIN_CONFIG_KEY_MOBILE);
39
37
 
40
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorateParam.js
38
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
41
39
  function __decorateParam(paramIndex, decorator) {
42
40
  return function(target, key) {
43
41
  decorator(target, key, paramIndex);
44
42
  };
45
43
  }
46
44
 
47
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorate.js
45
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
48
46
  function __decorate(decorators, target, key, desc) {
49
47
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
50
48
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -52,7 +50,7 @@ function __decorate(decorators, target, key, desc) {
52
50
  return c > 3 && r && Object.defineProperty(target, key, r), r;
53
51
  }
54
52
 
55
- // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
53
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
56
54
  function _typeof(o) {
57
55
  "@babel/helpers - typeof";
58
56
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -62,25 +60,25 @@ function _typeof(o) {
62
60
  }, _typeof(o);
63
61
  }
64
62
 
65
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
66
- function toPrimitive(t, r) {
63
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
64
+ function toPrimitive(t, e) {
67
65
  if ("object" != _typeof(t) || !t) return t;
68
- var e = t[Symbol.toPrimitive];
69
- if (void 0 !== e) {
70
- var i = e.call(t, r || "default");
66
+ var r;
67
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
68
+ var i = r.call(t, e || "default");
71
69
  if ("object" != _typeof(i)) return i;
72
70
  throw new TypeError("@@toPrimitive must return a primitive value.");
73
71
  }
74
- return ("string" === r ? String : Number)(t);
72
+ return ("string" === e ? String : Number)(t);
75
73
  }
76
74
 
77
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
75
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
78
76
  function toPropertyKey(t) {
79
77
  var i = toPrimitive(t, "string");
80
78
  return "symbol" == _typeof(i) ? i : i + "";
81
79
  }
82
80
 
83
- // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
81
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
84
82
  function _defineProperty(e, r, t) {
85
83
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
86
84
  value: t,
@@ -92,7 +90,7 @@ function _defineProperty(e, r, t) {
92
90
 
93
91
  // package.json
94
92
  var name = "@univerjs/sheets-formula";
95
- var version = "1.4.0";
93
+ var version = "1.5.1";
96
94
 
97
95
  // src/services/remote/remote-register-function.service.ts
98
96
  /**
@@ -134,46 +132,6 @@ function rejectRemoteCustomFunctionRegistration(serializedFuncs) {
134
132
  throw new Error("Remote custom function registration is disabled because function deserialization over RPC is unsafe.");
135
133
  }
136
134
 
137
- // src/worker.ts
138
- /**
139
- * Copyright 2023-present DreamNum Co., Ltd.
140
- *
141
- * Licensed under the Apache License, Version 2.0 (the "License");
142
- * you may not use this file except in compliance with the License.
143
- * You may obtain a copy of the License at
144
- *
145
- * http://www.apache.org/licenses/LICENSE-2.0
146
- *
147
- * Unless required by applicable law or agreed to in writing, software
148
- * distributed under the License is distributed on an "AS IS" BASIS,
149
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
150
- * See the License for the specific language governing permissions and
151
- * limitations under the License.
152
- */
153
- let UniverRemoteSheetsFormulaPlugin = class UniverRemoteSheetsFormulaPlugin extends _univerjs_core.Plugin {
154
- constructor(_config = defaultPluginRemoteConfig, _injector, _configService) {
155
- super();
156
- this._config = _config;
157
- this._injector = _injector;
158
- this._configService = _configService;
159
- const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginRemoteConfig, this._config);
160
- this._configService.setConfig(PLUGIN_CONFIG_KEY_REMOTE, rest);
161
- }
162
- onStarting() {
163
- this._injector.add([RemoteRegisterFunctionService]);
164
- this._injector.get(_univerjs_rpc.IRPCChannelService).registerChannel(RemoteRegisterFunctionServiceName, (0, _univerjs_rpc.fromModule)(this._injector.get(RemoteRegisterFunctionService)));
165
- }
166
- };
167
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "pluginName", "SHEET_FORMULA_REMOTE_PLUGIN");
168
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "packageName", name);
169
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "version", version);
170
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
171
- UniverRemoteSheetsFormulaPlugin = __decorate([
172
- (0, _univerjs_core.DependentOn)(_univerjs_engine_formula_worker.UniverFormulaEnginePlugin),
173
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
174
- __decorateParam(2, _univerjs_core.IConfigService)
175
- ], UniverRemoteSheetsFormulaPlugin);
176
-
177
135
  Object.defineProperty(exports, "CalculationMode", {
178
136
  enumerable: true,
179
137
  get: function () {
@@ -192,22 +150,22 @@ Object.defineProperty(exports, "PLUGIN_CONFIG_KEY_BASE", {
192
150
  return PLUGIN_CONFIG_KEY_BASE;
193
151
  }
194
152
  });
195
- Object.defineProperty(exports, "RemoteRegisterFunctionService", {
153
+ Object.defineProperty(exports, "PLUGIN_CONFIG_KEY_REMOTE", {
196
154
  enumerable: true,
197
155
  get: function () {
198
- return RemoteRegisterFunctionService;
156
+ return PLUGIN_CONFIG_KEY_REMOTE;
199
157
  }
200
158
  });
201
- Object.defineProperty(exports, "RemoteRegisterFunctionServiceName", {
159
+ Object.defineProperty(exports, "RemoteRegisterFunctionService", {
202
160
  enumerable: true,
203
161
  get: function () {
204
- return RemoteRegisterFunctionServiceName;
162
+ return RemoteRegisterFunctionService;
205
163
  }
206
164
  });
207
- Object.defineProperty(exports, "UniverRemoteSheetsFormulaPlugin", {
165
+ Object.defineProperty(exports, "RemoteRegisterFunctionServiceName", {
208
166
  enumerable: true,
209
167
  get: function () {
210
- return UniverRemoteSheetsFormulaPlugin;
168
+ return RemoteRegisterFunctionServiceName;
211
169
  }
212
170
  });
213
171
  Object.defineProperty(exports, "__decorate", {
@@ -234,6 +192,12 @@ Object.defineProperty(exports, "defaultPluginBaseConfig", {
234
192
  return defaultPluginBaseConfig;
235
193
  }
236
194
  });
195
+ Object.defineProperty(exports, "defaultPluginRemoteConfig", {
196
+ enumerable: true,
197
+ get: function () {
198
+ return defaultPluginRemoteConfig;
199
+ }
200
+ });
237
201
  Object.defineProperty(exports, "name", {
238
202
  enumerable: true,
239
203
  get: function () {
package/lib/cjs/worker.js CHANGED
@@ -1,9 +1,52 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_worker = require("./worker-Ds9TzMsD.js");
2
+ const require_remote_register_function_service = require("./remote-register-function.service-DiergAxp.js");
3
+ let _univerjs_core = require("@univerjs/core");
4
+ let _univerjs_rpc = require("@univerjs/rpc");
5
+ let _univerjs_engine_formula_worker = require("@univerjs/engine-formula/worker");
6
+
7
+ // src/worker.ts
8
+ /**
9
+ * Copyright 2023-present DreamNum Co., Ltd.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ let UniverRemoteSheetsFormulaPlugin = class UniverRemoteSheetsFormulaPlugin extends _univerjs_core.Plugin {
24
+ constructor(_config = require_remote_register_function_service.defaultPluginRemoteConfig, _injector, _configService) {
25
+ super();
26
+ this._config = _config;
27
+ this._injector = _injector;
28
+ this._configService = _configService;
29
+ const { ...rest } = (0, _univerjs_core.merge)({}, require_remote_register_function_service.defaultPluginRemoteConfig, this._config);
30
+ this._configService.setConfig(require_remote_register_function_service.PLUGIN_CONFIG_KEY_REMOTE, rest);
31
+ }
32
+ onStarting() {
33
+ this._injector.add([require_remote_register_function_service.RemoteRegisterFunctionService]);
34
+ this._injector.get(_univerjs_rpc.IRPCChannelService).registerChannel(require_remote_register_function_service.RemoteRegisterFunctionServiceName, (0, _univerjs_rpc.fromModule)(this._injector.get(require_remote_register_function_service.RemoteRegisterFunctionService)));
35
+ }
36
+ };
37
+ require_remote_register_function_service._defineProperty(UniverRemoteSheetsFormulaPlugin, "pluginName", "SHEET_FORMULA_REMOTE_PLUGIN");
38
+ require_remote_register_function_service._defineProperty(UniverRemoteSheetsFormulaPlugin, "packageName", require_remote_register_function_service.name);
39
+ require_remote_register_function_service._defineProperty(UniverRemoteSheetsFormulaPlugin, "version", require_remote_register_function_service.version);
40
+ require_remote_register_function_service._defineProperty(UniverRemoteSheetsFormulaPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
41
+ UniverRemoteSheetsFormulaPlugin = require_remote_register_function_service.__decorate([
42
+ (0, _univerjs_core.DependentOn)(_univerjs_engine_formula_worker.UniverFormulaEnginePlugin),
43
+ require_remote_register_function_service.__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
44
+ require_remote_register_function_service.__decorateParam(2, _univerjs_core.IConfigService)
45
+ ], UniverRemoteSheetsFormulaPlugin);
3
46
 
4
47
  Object.defineProperty(exports, "UniverRemoteSheetsFormulaPlugin", {
5
48
  enumerable: true,
6
49
  get: function () {
7
- return require_worker.UniverRemoteSheetsFormulaPlugin;
50
+ return UniverRemoteSheetsFormulaPlugin;
8
51
  }
9
52
  });
package/lib/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as name, c as __decorate, d as PLUGIN_CONFIG_KEY_BASE, f as defaultPluginBaseConfig, i as RemoteRegisterFunctionServiceName, l as __decorateParam, n as IRemoteRegisterFunctionService, o as version, r as RemoteRegisterFunctionService, s as _defineProperty, t as UniverRemoteSheetsFormulaPlugin, u as CalculationMode } from "./worker-m5XIUFq5.js";
1
+ import { a as version, c as __decorateParam, f as defaultPluginBaseConfig, i as name, l as CalculationMode, n as RemoteRegisterFunctionService, o as _defineProperty, r as RemoteRegisterFunctionServiceName, s as __decorate, t as IRemoteRegisterFunctionService, u as PLUGIN_CONFIG_KEY_BASE } from "./remote-register-function.service-B8XiggYJ.js";
2
2
  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, Range, Rectangle, Tools, UniverInstanceType, WrapTextType, cellToRange, createDocumentModelWithStyle, generateRandomId, getIntersectRange, isFormulaId, isFormulaString, isNodeEnv, isRealNum, merge, moveRangeByOffset, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
3
3
  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, ReorderRangeCommand, ReorderRangeMutation, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetBorderCommand, SetDefinedNameCommand, SetRangeCustomMetadataCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetRowHiddenMutation, SetRowVisibleMutation, SetStyleCommand, SetWorkbookCalculationSettingsMutation, SetWorkbookNameCommand, SetWorksheetActiveOperation, SetWorksheetColumnCountMutation, SetWorksheetNameCommand, SetWorksheetOrderMutation, SetWorksheetRowCountMutation, SheetInterceptorService, UniverSheetsPlugin, getSeparateEffectedRangesOnCommand, getSheetCommandTarget, handleCommonDefaultRangeChangeWithEffectRefCommands, handleDefaultRangeChangeWithEffectRefCommands, handleDeleteRangeMoveLeft, handleDeleteRangeMoveUp, handleIRemoveCol, handleIRemoveRow, handleInsertCol, handleInsertRangeMoveDown, handleInsertRangeMoveRight, handleInsertRow, handleMoveCols, handleMoveRange, handleMoveRows, runRefRangeMutations } from "@univerjs/sheets";
4
4
  import { AstTreeBuilder, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ErrorType, FormulaCalculationSessionService, FormulaDataModel, FormulaExecuteStageType, FormulaExecutedStateType, FormulaResultApplicationType, FunctionType, IActiveDirtyManagerService, IDefinedNamesService, IDescriptionService, IFormulaCurrentConfigService, ISuperTableService, Interpreter, Lexer, LexerTreeBuilder, RemoveDefinedNameMutation, RemoveSuperTableMutation, SetArrayFormulaDataMutation, SetDefinedNameMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaStringBatchCalculationMutation, SetImageFormulaDataMutation, SetSuperTableMutation, SetTriggerFormulaCalculationStartMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheetWithCache, generateExecuteAstNodeData, generateStringWithSequence, getObjectValue, refactorFormulaUnitQualifier, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, splitTableStructuredRef, stripErrorMargin } from "@univerjs/engine-formula";
@@ -442,6 +442,12 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
442
442
  _initialExecuteFormulaProcessListener() {
443
443
  let startDependencyTimer = null;
444
444
  let calculationProcessCount = 0;
445
+ this.disposeWithMe(() => {
446
+ if (startDependencyTimer !== null) {
447
+ clearTimeout(startDependencyTimer);
448
+ startDependencyTimer = null;
449
+ }
450
+ });
445
451
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
446
452
  if (command.id === SetFormulaCalculationStopMutation.id) this.clearProgress();
447
453
  if (command.id !== SetFormulaCalculationNotificationMutation.id) return;
@@ -460,43 +466,11 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
460
466
  startDependencyTimer = null;
461
467
  this._startProgress();
462
468
  }, 1e3);
463
- } else if (stage === FormulaExecuteStageType.CURRENTLY_CALCULATING) {
464
- this._executionInProgressParams = params.stageInfo;
465
- if (startDependencyTimer === null) {
466
- const calculating = this._localeService.t("sheets-formula.progress.calculating");
467
- this._calculateProgress(calculating);
468
- }
469
- } else if (stage === FormulaExecuteStageType.START_DEPENDENCY_ARRAY_FORMULA) {
470
- this._executionInProgressParams = params.stageInfo;
471
- if (startDependencyTimer === null) {
472
- const arrayAnalysis = this._localeService.t("sheets-formula.progress.array-analysis");
473
- this._calculateProgress(arrayAnalysis);
474
- }
475
- } else if (stage === FormulaExecuteStageType.CURRENTLY_CALCULATING_ARRAY_FORMULA) {
476
- this._executionInProgressParams = params.stageInfo;
477
- if (startDependencyTimer === null) {
478
- const arrayCalculation = this._localeService.t("sheets-formula.progress.array-calculation");
479
- this._calculateProgress(arrayCalculation);
480
- }
481
- }
469
+ } else this._updateCalculationProgress(params.stageInfo, startDependencyTimer === null);
482
470
  } else {
483
471
  const state = params.functionsExecutedState;
484
- let result = "";
485
- calculationProcessCount--;
486
- switch (state) {
487
- case FormulaExecutedStateType.NOT_EXECUTED:
488
- result = "No tasks are being executed anymore";
489
- break;
490
- case FormulaExecutedStateType.STOP_EXECUTION:
491
- result = "The execution of the formula has been stopped";
492
- calculationProcessCount = 0;
493
- break;
494
- case FormulaExecutedStateType.SUCCESS:
495
- result = "Formula calculation succeeded";
496
- if (calculationProcessCount === 0 || calculationProcessCount === -1) result += `. Total time consumed: ${performance.now() - this._startExecutionTime} ms`;
497
- break;
498
- case FormulaExecutedStateType.INITIAL: result = "Waiting for calculation";
499
- }
472
+ calculationProcessCount = state === FormulaExecutedStateType.STOP_EXECUTION ? 0 : calculationProcessCount - 1;
473
+ const result = this._getCalculationResultMessage(state, calculationProcessCount);
500
474
  if (calculationProcessCount === 0 || calculationProcessCount === -1) {
501
475
  if (startDependencyTimer) {
502
476
  clearTimeout(startDependencyTimer);
@@ -512,6 +486,34 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
512
486
  }
513
487
  }));
514
488
  }
489
+ _updateCalculationProgress(stageInfo, showProgress) {
490
+ let label;
491
+ switch (stageInfo.stage) {
492
+ case FormulaExecuteStageType.CURRENTLY_CALCULATING:
493
+ label = "sheets-formula.progress.calculating";
494
+ break;
495
+ case FormulaExecuteStageType.START_DEPENDENCY_ARRAY_FORMULA:
496
+ label = "sheets-formula.progress.array-analysis";
497
+ break;
498
+ case FormulaExecuteStageType.CURRENTLY_CALCULATING_ARRAY_FORMULA:
499
+ label = "sheets-formula.progress.array-calculation";
500
+ break;
501
+ default: return;
502
+ }
503
+ this._executionInProgressParams = stageInfo;
504
+ if (showProgress) this._calculateProgress(this._localeService.t(label));
505
+ }
506
+ _getCalculationResultMessage(state, calculationProcessCount) {
507
+ switch (state) {
508
+ case FormulaExecutedStateType.NOT_EXECUTED: return "No tasks are being executed anymore";
509
+ case FormulaExecutedStateType.STOP_EXECUTION: return "The execution of the formula has been stopped";
510
+ case FormulaExecutedStateType.SUCCESS:
511
+ if (calculationProcessCount === 0 || calculationProcessCount === -1) return `Formula calculation succeeded. Total time consumed: ${performance.now() - this._startExecutionTime} ms`;
512
+ return "Formula calculation succeeded";
513
+ case FormulaExecutedStateType.INITIAL: return "Waiting for calculation";
514
+ default: return "";
515
+ }
516
+ }
515
517
  _initialExecuteFormula() {
516
518
  const calculationMode = this._getCalculationMode();
517
519
  if (calculationMode !== 2) {
@@ -2127,12 +2129,15 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2127
2129
  if (formulaDataKeys.length === 0) return { newFormulaData: {} };
2128
2130
  const newFormulaData = Object.create(null);
2129
2131
  const inCrossSheetCutRangeNewFormulas = [];
2132
+ const { type, unitId: affectedUnitId, sheetId: affectedSheetId } = formulaReferenceMoveParam;
2133
+ const isRemovingSheet = type === 13;
2130
2134
  for (const unitId of formulaDataKeys) {
2131
2135
  const sheetData = formulaData[unitId];
2132
2136
  if (sheetData == null) continue;
2133
2137
  const sheetDataKeys = Object.keys(sheetData);
2134
2138
  if (!Tools.isDefine(newFormulaData[unitId])) newFormulaData[unitId] = Object.create(null);
2135
2139
  for (const sheetId of sheetDataKeys) {
2140
+ if (isRemovingSheet && unitId === affectedUnitId && sheetId === affectedSheetId) continue;
2136
2141
  const matrixData = new ObjectMatrix(sheetData[sheetId] || {});
2137
2142
  const newFormulaDataItem = new ObjectMatrix();
2138
2143
  const context = {
@@ -3119,6 +3124,38 @@ SuperTableController = __decorate([
3119
3124
  ], SuperTableController);
3120
3125
 
3121
3126
  // src/services/formula-ref-range.service.ts
3127
+ /**
3128
+ * An inserted row or column that lands inside a registered range stays part of that range, the
3129
+ * same way {@link handleCommonDefaultRangeChangeWithEffectRefCommands} expands a range when the
3130
+ * insertion happens inside it. `registerRangeFormula` splits a range into the segments that are
3131
+ * affected by a command, and an inserted block is not part of any segment, so it has to be
3132
+ * collected separately, otherwise the inserted cells would silently drop out of the range.
3133
+ */
3134
+ function getInsertedBlocks(command, ranges) {
3135
+ const params = command.params;
3136
+ if (!(params === null || params === void 0 ? void 0 : params.range)) return [];
3137
+ switch (command.id) {
3138
+ case EffectRefRangId.InsertRowCommandId: {
3139
+ const { startRow, endRow } = params.range;
3140
+ return ranges.filter((range) => startRow > range.startRow && startRow <= range.endRow).map((range) => ({
3141
+ startRow,
3142
+ endRow,
3143
+ startColumn: range.startColumn,
3144
+ endColumn: range.endColumn
3145
+ }));
3146
+ }
3147
+ case EffectRefRangId.InsertColCommandId: {
3148
+ const { startColumn, endColumn } = params.range;
3149
+ return ranges.filter((range) => startColumn > range.startColumn && startColumn <= range.endColumn).map((range) => ({
3150
+ startRow: range.startRow,
3151
+ endRow: range.endRow,
3152
+ startColumn,
3153
+ endColumn
3154
+ }));
3155
+ }
3156
+ default: return [];
3157
+ }
3158
+ }
3122
3159
  function getFormulaKeyOffset(lexerTreeBuilder, formulaString, refOffsetX, refOffsetY) {
3123
3160
  const sequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(formulaString);
3124
3161
  if (sequenceNodes == null) return formulaString;
@@ -3267,6 +3304,8 @@ let FormulaRefRangeService = class FormulaRefRangeService extends Disposable {
3267
3304
  const disposableCollection = new DisposableCollection();
3268
3305
  const formulaDeps = formulas.map((formula) => this._getFormulaDependcy(unitId, subUnitId, formula, oldRanges));
3269
3306
  const handleRangeChange = (commandInfo) => {
3307
+ const wholeRangeResult = this._transformWholeRangeFormulas(unitId, subUnitId, oldRanges, formulas, commandInfo);
3308
+ if (wholeRangeResult) return callback(wholeRangeResult);
3270
3309
  const effectedRanges = getSeparateEffectedRangesOnCommand(this._injector, commandInfo);
3271
3310
  if (!effectedRanges) return {
3272
3311
  undos: [],
@@ -3358,6 +3397,7 @@ let FormulaRefRangeService = class FormulaRefRangeService extends Disposable {
3358
3397
  if (keyMap.has(item.key)) keyMap.get(item.key).push(item);
3359
3398
  else keyMap.set(item.key, [item]);
3360
3399
  }
3400
+ this._appendInsertedBlockItems(keyMap, commandInfo, oldRanges, formulas, oldRanges[0], originKey);
3361
3401
  const res = [];
3362
3402
  const keys = Array.from(keyMap.keys());
3363
3403
  for (let i = keys.length - 1; i >= 0; i--) {
@@ -3391,6 +3431,40 @@ let FormulaRefRangeService = class FormulaRefRangeService extends Disposable {
3391
3431
  });
3392
3432
  return disposableCollection;
3393
3433
  }
3434
+ /**
3435
+ * A whole column/row/sheet range keeps its anchor, so it is adjusted as a single range:
3436
+ * segmenting it would both split the rule and drop the range type.
3437
+ *
3438
+ * @returns the single rule range to apply, or `undefined` when the regular segmentation applies
3439
+ */
3440
+ _transformWholeRangeFormulas(unitId, subUnitId, oldRanges, formulas, commandInfo) {
3441
+ var _oldRanges$;
3442
+ const ruleRangeType = ((_oldRanges$ = oldRanges[0]) === null || _oldRanges$ === void 0 ? void 0 : _oldRanges$.rangeType) ?? RANGE_TYPE.NORMAL;
3443
+ if (ruleRangeType === RANGE_TYPE.NORMAL || !oldRanges.every((range) => range.rangeType === ruleRangeType)) return;
3444
+ const ranges = handleCommonDefaultRangeChangeWithEffectRefCommands(oldRanges[0], commandInfo);
3445
+ if (!ranges.length) return [];
3446
+ return [{
3447
+ formulas: formulas.map((formula) => isFormulaString(formula) ? this.transformFormulaByEffectCommand(unitId, subUnitId, formula, commandInfo) : formula),
3448
+ ranges
3449
+ }];
3450
+ }
3451
+ _appendInsertedBlockItems(keyMap, commandInfo, oldRanges, formulas, origin, originKey) {
3452
+ for (const block of getInsertedBlocks(commandInfo, oldRanges)) {
3453
+ const offsetRow = block.startRow - origin.startRow;
3454
+ const offsetColumn = block.startColumn - origin.startColumn;
3455
+ const item = {
3456
+ formulas: formulas.map((formula) => ({
3457
+ newFormula: isFormulaString(formula) ? this._lexerTreeBuilder.moveFormulaRefOffset(formula, offsetColumn, offsetRow) : formula,
3458
+ orginFormula: formula
3459
+ })),
3460
+ ranges: [block],
3461
+ key: originKey
3462
+ };
3463
+ const items = keyMap.get(item.key);
3464
+ if (items) items.push(item);
3465
+ else keyMap.set(item.key, [item]);
3466
+ }
3467
+ }
3394
3468
  };
3395
3469
  FormulaRefRangeService = __decorate([
3396
3470
  __decorateParam(0, Inject(RefRangeService)),
@@ -3492,4 +3566,4 @@ function calculateFormula(inject, formulaString, unitId, sheetData) {
3492
3566
  return getObjectValue(result);
3493
3567
  }
3494
3568
 
3495
- export { CalculationMode, FormulaAutoFillController, FormulaRefRangeService, FormulaReorderController, IRemoteRegisterFunctionService, ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, RemoteRegisterFunctionService, TriggerCalculationController, UnitQualifierRenameController, UniverRemoteSheetsFormulaPlugin, UniverSheetsFormulaPlugin, UpdateDefinedNameController, UpdateFormulaController, calculateFormula, collectUnitQualifierFormulaPatches };
3569
+ export { CalculationMode, FormulaAutoFillController, FormulaRefRangeService, FormulaReorderController, IRemoteRegisterFunctionService, ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, RemoteRegisterFunctionService, TriggerCalculationController, UnitQualifierRenameController, UniverSheetsFormulaPlugin, UpdateDefinedNameController, UpdateFormulaController, calculateFormula, collectUnitQualifierFormulaPatches };
@@ -1,7 +1,5 @@
1
- import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType, createIdentifier, merge } from "@univerjs/core";
1
+ import { createIdentifier } from "@univerjs/core";
2
2
  import { IFunctionService } from "@univerjs/engine-formula";
3
- import { IRPCChannelService, fromModule } from "@univerjs/rpc";
4
- import { UniverFormulaEnginePlugin as UniverFormulaEnginePlugin$1 } from "@univerjs/engine-formula/worker";
5
3
 
6
4
  // src/config/config.ts
7
5
  /**
@@ -37,14 +35,14 @@ const defaultPluginRemoteConfig = {};
37
35
  const PLUGIN_CONFIG_KEY_MOBILE = "sheets-formula.mobile.config";
38
36
  const configSymbolMobile = Symbol(PLUGIN_CONFIG_KEY_MOBILE);
39
37
 
40
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorateParam.js
38
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
41
39
  function __decorateParam(paramIndex, decorator) {
42
40
  return function(target, key) {
43
41
  decorator(target, key, paramIndex);
44
42
  };
45
43
  }
46
44
 
47
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorate.js
45
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
48
46
  function __decorate(decorators, target, key, desc) {
49
47
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
50
48
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -52,7 +50,7 @@ function __decorate(decorators, target, key, desc) {
52
50
  return c > 3 && r && Object.defineProperty(target, key, r), r;
53
51
  }
54
52
 
55
- // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
53
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
56
54
  function _typeof(o) {
57
55
  "@babel/helpers - typeof";
58
56
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -62,25 +60,25 @@ function _typeof(o) {
62
60
  }, _typeof(o);
63
61
  }
64
62
 
65
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
66
- function toPrimitive(t, r) {
63
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
64
+ function toPrimitive(t, e) {
67
65
  if ("object" != _typeof(t) || !t) return t;
68
- var e = t[Symbol.toPrimitive];
69
- if (void 0 !== e) {
70
- var i = e.call(t, r || "default");
66
+ var r;
67
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
68
+ var i = r.call(t, e || "default");
71
69
  if ("object" != _typeof(i)) return i;
72
70
  throw new TypeError("@@toPrimitive must return a primitive value.");
73
71
  }
74
- return ("string" === r ? String : Number)(t);
72
+ return ("string" === e ? String : Number)(t);
75
73
  }
76
74
 
77
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
75
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
78
76
  function toPropertyKey(t) {
79
77
  var i = toPrimitive(t, "string");
80
78
  return "symbol" == _typeof(i) ? i : i + "";
81
79
  }
82
80
 
83
- // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
81
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
84
82
  function _defineProperty(e, r, t) {
85
83
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
86
84
  value: t,
@@ -92,7 +90,7 @@ function _defineProperty(e, r, t) {
92
90
 
93
91
  // package.json
94
92
  var name = "@univerjs/sheets-formula";
95
- var version = "1.4.0";
93
+ var version = "1.5.1";
96
94
 
97
95
  // src/services/remote/remote-register-function.service.ts
98
96
  /**
@@ -134,44 +132,4 @@ function rejectRemoteCustomFunctionRegistration(serializedFuncs) {
134
132
  throw new Error("Remote custom function registration is disabled because function deserialization over RPC is unsafe.");
135
133
  }
136
134
 
137
- // src/worker.ts
138
- /**
139
- * Copyright 2023-present DreamNum Co., Ltd.
140
- *
141
- * Licensed under the Apache License, Version 2.0 (the "License");
142
- * you may not use this file except in compliance with the License.
143
- * You may obtain a copy of the License at
144
- *
145
- * http://www.apache.org/licenses/LICENSE-2.0
146
- *
147
- * Unless required by applicable law or agreed to in writing, software
148
- * distributed under the License is distributed on an "AS IS" BASIS,
149
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
150
- * See the License for the specific language governing permissions and
151
- * limitations under the License.
152
- */
153
- let UniverRemoteSheetsFormulaPlugin = class UniverRemoteSheetsFormulaPlugin extends Plugin {
154
- constructor(_config = defaultPluginRemoteConfig, _injector, _configService) {
155
- super();
156
- this._config = _config;
157
- this._injector = _injector;
158
- this._configService = _configService;
159
- const { ...rest } = merge({}, defaultPluginRemoteConfig, this._config);
160
- this._configService.setConfig(PLUGIN_CONFIG_KEY_REMOTE, rest);
161
- }
162
- onStarting() {
163
- this._injector.add([RemoteRegisterFunctionService]);
164
- this._injector.get(IRPCChannelService).registerChannel(RemoteRegisterFunctionServiceName, fromModule(this._injector.get(RemoteRegisterFunctionService)));
165
- }
166
- };
167
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "pluginName", "SHEET_FORMULA_REMOTE_PLUGIN");
168
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "packageName", name);
169
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "version", version);
170
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "type", UniverInstanceType.UNIVER_SHEET);
171
- UniverRemoteSheetsFormulaPlugin = __decorate([
172
- DependentOn(UniverFormulaEnginePlugin$1),
173
- __decorateParam(1, Inject(Injector)),
174
- __decorateParam(2, IConfigService)
175
- ], UniverRemoteSheetsFormulaPlugin);
176
-
177
- export { name as a, __decorate as c, PLUGIN_CONFIG_KEY_BASE as d, defaultPluginBaseConfig as f, RemoteRegisterFunctionServiceName as i, __decorateParam as l, IRemoteRegisterFunctionService as n, version as o, RemoteRegisterFunctionService as r, _defineProperty as s, UniverRemoteSheetsFormulaPlugin as t, CalculationMode as u };
135
+ export { version as a, __decorateParam as c, PLUGIN_CONFIG_KEY_REMOTE as d, defaultPluginBaseConfig as f, name as i, CalculationMode as l, RemoteRegisterFunctionService as n, _defineProperty as o, defaultPluginRemoteConfig as p, RemoteRegisterFunctionServiceName as r, __decorate as s, IRemoteRegisterFunctionService as t, PLUGIN_CONFIG_KEY_BASE as u };
package/lib/es/worker.js CHANGED
@@ -1,3 +1,46 @@
1
- import { t as UniverRemoteSheetsFormulaPlugin } from "./worker-m5XIUFq5.js";
1
+ import { a as version, c as __decorateParam, d as PLUGIN_CONFIG_KEY_REMOTE, i as name, n as RemoteRegisterFunctionService, o as _defineProperty, p as defaultPluginRemoteConfig, r as RemoteRegisterFunctionServiceName, s as __decorate } from "./remote-register-function.service-B8XiggYJ.js";
2
+ import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType, merge } from "@univerjs/core";
3
+ import { IRPCChannelService, fromModule } from "@univerjs/rpc";
4
+ import { UniverFormulaEnginePlugin } from "@univerjs/engine-formula/worker";
5
+
6
+ // src/worker.ts
7
+ /**
8
+ * Copyright 2023-present DreamNum Co., Ltd.
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ let UniverRemoteSheetsFormulaPlugin = class UniverRemoteSheetsFormulaPlugin extends Plugin {
23
+ constructor(_config = defaultPluginRemoteConfig, _injector, _configService) {
24
+ super();
25
+ this._config = _config;
26
+ this._injector = _injector;
27
+ this._configService = _configService;
28
+ const { ...rest } = merge({}, defaultPluginRemoteConfig, this._config);
29
+ this._configService.setConfig(PLUGIN_CONFIG_KEY_REMOTE, rest);
30
+ }
31
+ onStarting() {
32
+ this._injector.add([RemoteRegisterFunctionService]);
33
+ this._injector.get(IRPCChannelService).registerChannel(RemoteRegisterFunctionServiceName, fromModule(this._injector.get(RemoteRegisterFunctionService)));
34
+ }
35
+ };
36
+ _defineProperty(UniverRemoteSheetsFormulaPlugin, "pluginName", "SHEET_FORMULA_REMOTE_PLUGIN");
37
+ _defineProperty(UniverRemoteSheetsFormulaPlugin, "packageName", name);
38
+ _defineProperty(UniverRemoteSheetsFormulaPlugin, "version", version);
39
+ _defineProperty(UniverRemoteSheetsFormulaPlugin, "type", UniverInstanceType.UNIVER_SHEET);
40
+ UniverRemoteSheetsFormulaPlugin = __decorate([
41
+ DependentOn(UniverFormulaEnginePlugin),
42
+ __decorateParam(1, Inject(Injector)),
43
+ __decorateParam(2, IConfigService)
44
+ ], UniverRemoteSheetsFormulaPlugin);
2
45
 
3
46
  export { UniverRemoteSheetsFormulaPlugin };