@univerjs/sheets-formula 0.21.0 → 0.21.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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AbsoluteRefType, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, ICommandService, IConfigService, ILogService, IUniverInstanceService, ImageSourceType, Inject, Injector, InterceptorEffectEnum, LocaleService, ObjectMatrix, ObjectRelativeFromH, ObjectRelativeFromV, Optional, Plugin, PositionedObjectLayoutType, RANGE_TYPE, Rectangle, Tools, UniverInstanceType, WrapTextType, cellToRange, createDocumentModelWithStyle, createIdentifier, generateRandomId, getIntersectRange, isFormulaId, isFormulaString, isNodeEnv, isRealNum, merge, moveRangeByOffset, 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, 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, AsyncCustomFunction, CustomFunction, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ErrorType, FUNCTION_NAMES_ARRAY, FUNCTION_NAMES_COMPATIBILITY, FUNCTION_NAMES_CUBE, FUNCTION_NAMES_DATABASE, FUNCTION_NAMES_DATE, FUNCTION_NAMES_ENGINEERING, FUNCTION_NAMES_FINANCIAL, FUNCTION_NAMES_INFORMATION, FUNCTION_NAMES_LOGICAL, FUNCTION_NAMES_LOOKUP, FUNCTION_NAMES_MATH, FUNCTION_NAMES_STATISTICAL, FUNCTION_NAMES_TEXT, FUNCTION_NAMES_WEB, FormulaDataModel, FormulaExecuteStageType, FormulaExecutedStateType, FunctionType, IActiveDirtyManagerService, IDefinedNamesService, IFormulaCurrentConfigService, IFunctionService, ISuperTableService, Interpreter, Lexer, LexerTreeBuilder, OtherFormulaMarkDirty, RegisterOtherFormulaService, RemoveDefinedNameMutation, RemoveSuperTableMutation, SetArrayFormulaDataMutation, SetDefinedNameMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaStringBatchCalculationMutation, SetImageFormulaDataMutation, SetSuperTableMutation, SetTriggerFormulaCalculationStartMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheetWithCache, functionArray, functionCompatibility, functionCube, functionDatabase, functionDate, functionEngineering, functionFinancial, functionInformation, functionLogical, functionLookup, functionMath, functionMeta, functionStatistical, functionText, functionUniver, functionWeb, generateExecuteAstNodeData, generateStringWithSequence, getObjectValue, initSheetFormulaData, isReferenceStrings, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, stripErrorMargin } from "@univerjs/engine-formula";
3
+ import { ALL_IMPLEMENTED_FUNCTIONS_SET, AstTreeBuilder, AsyncCustomFunction, CustomFunction, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ErrorType, FUNCTION_NAMES_ARRAY, FUNCTION_NAMES_COMPATIBILITY, FUNCTION_NAMES_CUBE, FUNCTION_NAMES_DATABASE, FUNCTION_NAMES_DATE, FUNCTION_NAMES_ENGINEERING, FUNCTION_NAMES_FINANCIAL, FUNCTION_NAMES_INFORMATION, FUNCTION_NAMES_LOGICAL, FUNCTION_NAMES_LOOKUP, FUNCTION_NAMES_MATH, FUNCTION_NAMES_STATISTICAL, FUNCTION_NAMES_TEXT, FUNCTION_NAMES_WEB, FormulaDataModel, FormulaExecuteStageType, FormulaExecutedStateType, FunctionType, IActiveDirtyManagerService, IDefinedNamesService, IFormulaCurrentConfigService, IFunctionService, ISuperTableService, Interpreter, Lexer, LexerTreeBuilder, OtherFormulaMarkDirty, RegisterOtherFormulaService, RemoveDefinedNameMutation, RemoveSuperTableMutation, SetArrayFormulaDataMutation, SetDefinedNameMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaStringBatchCalculationMutation, SetImageFormulaDataMutation, SetSuperTableMutation, SetTriggerFormulaCalculationStartMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheetWithCache, generateExecuteAstNodeData, generateStringWithSequence, getObjectValue, initSheetFormulaData, isReferenceStrings, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, stripErrorMargin } from "@univerjs/engine-formula";
4
4
  import { BehaviorSubject, map } from "rxjs";
5
5
  import { IRPCChannelService, fromModule, toModule } from "@univerjs/rpc";
6
6
 
@@ -2054,7 +2054,7 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2054
2054
  this._handleSetRangeValuesMutation(params);
2055
2055
  }
2056
2056
  }));
2057
- this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => this._handleWorkbookAdded(unit)));
2057
+ this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_SHEET).subscribe((event) => this._handleWorkbookAdded(event.unit)));
2058
2058
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_SHEET).pipe(map((unit) => unit.getUnitId())).subscribe((unitId) => this._handleWorkbookDisposed(unitId)));
2059
2059
  }
2060
2060
  _handleSetRangeValuesMutation(params) {
@@ -2321,7 +2321,7 @@ UpdateFormulaController = __decorate([
2321
2321
  //#endregion
2322
2322
  //#region package.json
2323
2323
  var name = "@univerjs/sheets-formula";
2324
- var version = "0.21.0";
2324
+ var version = "0.21.1";
2325
2325
 
2326
2326
  //#endregion
2327
2327
  //#region src/common/plugin-name.ts
@@ -15421,33 +15421,100 @@ function getFunctionName(item, localeService) {
15421
15421
  //#endregion
15422
15422
  //#region src/services/description.service.ts
15423
15423
  const IDescriptionService = createIdentifier("formula.description-service");
15424
- let DescriptionService = class DescriptionService {
15424
+ let DescriptionService = class DescriptionService extends Disposable {
15425
15425
  constructor(_functionService, _localeService, _configService) {
15426
+ super();
15426
15427
  this._functionService = _functionService;
15427
15428
  this._localeService = _localeService;
15428
15429
  this._configService = _configService;
15429
- _defineProperty(this, "_descriptions", []);
15430
+ _defineProperty(this, "_descriptions", /* @__PURE__ */ new Map());
15430
15431
  this._initialize();
15431
15432
  }
15433
+ _initialize() {
15434
+ this.disposeWithMe(toDisposable(this._localeService.localeChanged$.subscribe(() => {
15435
+ this._functionService.clearDescriptions();
15436
+ const newDescriptions = /* @__PURE__ */ new Map();
15437
+ this._descriptions.forEach((item) => {
15438
+ const functionName = getFunctionName(item, this._localeService).toUpperCase();
15439
+ newDescriptions.set(functionName, item);
15440
+ });
15441
+ this._descriptions = newDescriptions;
15442
+ this._initRegisterDescriptions();
15443
+ })));
15444
+ this._initDescriptions();
15445
+ this._initRegisterDescriptions();
15446
+ }
15447
+ _initDescriptions() {
15448
+ var _config$description;
15449
+ const localeService = this._localeService;
15450
+ FUNCTION_LIST.forEach((item) => {
15451
+ if (ALL_IMPLEMENTED_FUNCTIONS_SET.has(item.functionName)) {
15452
+ const functionName = getFunctionName(item, localeService).toUpperCase();
15453
+ this._descriptions.set(functionName, item);
15454
+ }
15455
+ });
15456
+ const config = this._configService.getConfig(PLUGIN_CONFIG_KEY_BASE);
15457
+ config === null || config === void 0 || (_config$description = config.description) === null || _config$description === void 0 || _config$description.forEach((item) => {
15458
+ const functionName = getFunctionName(item, localeService).toUpperCase();
15459
+ this._descriptions.set(functionName, item);
15460
+ });
15461
+ }
15462
+ _initRegisterDescriptions() {
15463
+ const localeService = this._localeService;
15464
+ const functionListLocale = Array.from(this._descriptions.values()).map((functionInfo) => ({
15465
+ functionName: getFunctionName(functionInfo, localeService),
15466
+ functionType: functionInfo.functionType,
15467
+ description: localeService.t(functionInfo.description),
15468
+ abstract: localeService.t(functionInfo.abstract),
15469
+ functionParameter: functionInfo.functionParameter.map((item) => ({
15470
+ name: localeService.t(item.name),
15471
+ detail: localeService.t(item.detail),
15472
+ example: item.example,
15473
+ require: item.require,
15474
+ repeat: item.repeat
15475
+ }))
15476
+ }));
15477
+ this._functionService.registerDescriptions(...functionListLocale);
15478
+ }
15479
+ _registerDescriptions(descriptions) {
15480
+ const localeService = this._localeService;
15481
+ const functionListLocale = descriptions.map((functionInfo) => ({
15482
+ functionName: getFunctionName(functionInfo, localeService),
15483
+ functionType: functionInfo.functionType,
15484
+ description: localeService.t(functionInfo.description),
15485
+ abstract: localeService.t(functionInfo.abstract),
15486
+ functionParameter: functionInfo.functionParameter.map((item) => ({
15487
+ name: localeService.t(item.name),
15488
+ detail: localeService.t(item.detail),
15489
+ example: item.example,
15490
+ require: item.require,
15491
+ repeat: item.repeat
15492
+ }))
15493
+ }));
15494
+ this._functionService.registerDescriptions(...functionListLocale);
15495
+ }
15432
15496
  dispose() {
15433
- this._localeService.localeChanged$.complete();
15497
+ super.dispose();
15498
+ this._descriptions.clear();
15434
15499
  }
15435
15500
  getDescriptions() {
15436
15501
  return this._functionService.getDescriptions();
15437
15502
  }
15438
15503
  hasFunction(searchText) {
15439
- return this._functionService.getDescriptions().get(searchText.toLocaleUpperCase()) !== void 0;
15504
+ return this._descriptions.has(searchText.toUpperCase());
15440
15505
  }
15441
15506
  getFunctionInfo(searchText) {
15442
- return this._functionService.getDescriptions().get(searchText.toLocaleUpperCase());
15507
+ const item = this._descriptions.get(searchText.toUpperCase());
15508
+ if (!item) return;
15509
+ return this._functionService.getDescription(getFunctionName(item, this._localeService));
15443
15510
  }
15444
15511
  getSearchListByName(searchText) {
15445
- const searchList = [];
15446
15512
  const functionList = this._functionService.getDescriptions();
15447
- const _searchText = searchText.toLocaleUpperCase().trim();
15513
+ const _searchText = searchText.toUpperCase().trim();
15514
+ const searchList = [];
15448
15515
  functionList.forEach((item) => {
15449
15516
  const { functionName, abstract, functionType } = item;
15450
- if (functionName.toLocaleUpperCase().indexOf(_searchText) > -1 && functionType !== FunctionType.DefinedName) searchList.push({
15517
+ if (functionName.toUpperCase().indexOf(_searchText) > -1 && functionType !== FunctionType.DefinedName) searchList.push({
15451
15518
  name: functionName,
15452
15519
  desc: abstract
15453
15520
  });
@@ -15455,12 +15522,12 @@ let DescriptionService = class DescriptionService {
15455
15522
  return searchList;
15456
15523
  }
15457
15524
  getSearchListByNameFirstLetter(searchText) {
15458
- const searchList = [];
15459
15525
  const functionList = this._functionService.getDescriptions();
15460
- const _searchText = searchText.toLocaleUpperCase().trim();
15526
+ const _searchText = searchText.toUpperCase().trim();
15527
+ const searchList = [];
15461
15528
  functionList.forEach((item) => {
15462
15529
  const { functionName, abstract, functionType } = item;
15463
- if (functionName.toLocaleUpperCase().indexOf(_searchText) === 0) searchList.push({
15530
+ if (functionName.toUpperCase().indexOf(_searchText) === 0) searchList.push({
15464
15531
  name: functionName,
15465
15532
  desc: abstract,
15466
15533
  functionType
@@ -15469,8 +15536,9 @@ let DescriptionService = class DescriptionService {
15469
15536
  return searchList;
15470
15537
  }
15471
15538
  getSearchListByType(type) {
15539
+ const functionList = this._functionService.getDescriptions();
15472
15540
  const searchList = [];
15473
- this._functionService.getDescriptions().forEach((item) => {
15541
+ functionList.forEach((item) => {
15474
15542
  const { functionName, functionType, abstract } = item;
15475
15543
  if ((functionType === type || type === -1) && functionType !== FunctionType.DefinedName) searchList.push({
15476
15544
  name: functionName,
@@ -15479,79 +15547,43 @@ let DescriptionService = class DescriptionService {
15479
15547
  });
15480
15548
  return searchList;
15481
15549
  }
15482
- registerDescriptions(description) {
15483
- this._descriptions = this._descriptions.concat(description);
15484
- this._registerDescriptions();
15550
+ registerDescriptions(descriptions) {
15551
+ const localeService = this._localeService;
15552
+ const functionNames = [];
15553
+ descriptions.forEach((item) => {
15554
+ const functionName = getFunctionName(item, localeService).toUpperCase();
15555
+ functionNames.push(functionName);
15556
+ this._descriptions.set(functionName, item);
15557
+ });
15558
+ this._registerDescriptions(descriptions);
15485
15559
  return toDisposable(() => {
15486
- const functionNames = description.map((item) => item.functionName);
15487
15560
  this.unregisterDescriptions(functionNames);
15488
15561
  });
15489
15562
  }
15490
15563
  unregisterDescriptions(functionNames) {
15491
- this._descriptions = this._descriptions.filter((item) => !functionNames.includes(item.functionName));
15492
- this._functionService.unregisterDescriptions(...functionNames);
15564
+ const removeFunctionNames = [];
15565
+ functionNames.forEach((name) => {
15566
+ const functionName = name.toUpperCase();
15567
+ const item = this._descriptions.get(functionName);
15568
+ if (!item) return;
15569
+ removeFunctionNames.push(getFunctionName(item, this._localeService));
15570
+ this._descriptions.delete(functionName);
15571
+ });
15572
+ this._functionService.unregisterDescriptions(...removeFunctionNames);
15493
15573
  }
15494
15574
  hasDescription(name) {
15495
- return this._descriptions.some((item) => item.functionName === name);
15575
+ return this._descriptions.has(name.toUpperCase());
15496
15576
  }
15497
15577
  hasDefinedNameDescription(name) {
15498
- return this._descriptions.some((item) => item.functionName === name && item.functionType === FunctionType.DefinedName);
15578
+ const item = this._descriptions.get(name.toUpperCase());
15579
+ if (!item) return false;
15580
+ return item.functionType === FunctionType.DefinedName;
15499
15581
  }
15500
15582
  isFormulaDefinedName(name) {
15501
- const items = this._descriptions.filter((item) => item.functionName === name && item.functionType === FunctionType.DefinedName);
15502
- if (items.length === 0) return false;
15503
- const token = items[0].description;
15504
- return !isReferenceStrings(token);
15505
- }
15506
- _initialize() {
15507
- this._localeService.localeChanged$.subscribe(() => {
15508
- this._registerDescriptions();
15509
- });
15510
- this._initDescription();
15511
- this._registerDescriptions();
15512
- }
15513
- _initDescription() {
15514
- var _config$description;
15515
- const functions = [
15516
- ...functionArray,
15517
- ...functionCompatibility,
15518
- ...functionCube,
15519
- ...functionDatabase,
15520
- ...functionDate,
15521
- ...functionEngineering,
15522
- ...functionFinancial,
15523
- ...functionInformation,
15524
- ...functionLogical,
15525
- ...functionLookup,
15526
- ...functionMath,
15527
- ...functionMeta,
15528
- ...functionStatistical,
15529
- ...functionText,
15530
- ...functionUniver,
15531
- ...functionWeb
15532
- ].map((item) => item[1]);
15533
- const filterFunctionList = FUNCTION_LIST.filter((item) => {
15534
- return functions.includes(item.functionName);
15535
- });
15536
- const config = this._configService.getConfig(PLUGIN_CONFIG_KEY_BASE);
15537
- this._descriptions = filterFunctionList.concat((_config$description = config === null || config === void 0 ? void 0 : config.description) !== null && _config$description !== void 0 ? _config$description : []);
15538
- }
15539
- _registerDescriptions() {
15540
- const localeService = this._localeService;
15541
- const functionListLocale = this._descriptions.map((functionInfo) => ({
15542
- functionName: getFunctionName(functionInfo, localeService),
15543
- functionType: functionInfo.functionType,
15544
- description: localeService.t(functionInfo.description),
15545
- abstract: localeService.t(functionInfo.abstract),
15546
- functionParameter: functionInfo.functionParameter.map((item) => ({
15547
- name: localeService.t(item.name),
15548
- detail: localeService.t(item.detail),
15549
- example: item.example,
15550
- require: item.require,
15551
- repeat: item.repeat
15552
- }))
15553
- }));
15554
- this._functionService.registerDescriptions(...functionListLocale);
15583
+ const item = this._descriptions.get(name.toUpperCase());
15584
+ if (!item) return false;
15585
+ if (item.functionType !== FunctionType.DefinedName) return false;
15586
+ return !isReferenceStrings(item.description);
15555
15587
  }
15556
15588
  };
15557
15589
  DescriptionService = __decorate([
@@ -15578,37 +15610,66 @@ let DefinedNameController = class DefinedNameController extends Disposable {
15578
15610
  this._changeSheetListener();
15579
15611
  }
15580
15612
  _descriptionListener() {
15581
- toDisposable(this._definedNamesService.update$.subscribe(() => {
15582
- this._registerDescriptions();
15583
- }));
15613
+ this.disposeWithMe(toDisposable(this._definedNamesService.update$.subscribe((event) => {
15614
+ this._updateDescriptions(event);
15615
+ })));
15584
15616
  }
15585
15617
  _changeUnitListener() {
15586
- toDisposable(this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
15618
+ this.disposeWithMe(toDisposable(this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
15587
15619
  this._unRegisterDescriptions();
15588
- if (workbook) this._registerDescriptions();
15589
- }));
15620
+ if (workbook) this._initRegisterDescriptions(workbook.getUnitId());
15621
+ })));
15590
15622
  }
15591
15623
  _changeSheetListener() {
15592
15624
  this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
15593
15625
  if (options === null || options === void 0 ? void 0 : options.fromCollab) return;
15594
15626
  if (command.id === SetWorksheetActiveOperation.id) {
15595
- this._unregisterDescriptionsForNotInSheetId();
15596
- this._registerDescriptions();
15627
+ const params = command.params;
15628
+ this._unregisterDescriptionsForNotInSheetId(params.unitId, params.subUnitId);
15629
+ this._initRegisterDescriptions(params.unitId, params.subUnitId);
15597
15630
  } else if (command.id === SetDefinedNameMutation.id) {
15598
- const param = command.params;
15599
- this._registerDescription(param);
15631
+ const params = command.params;
15632
+ this._registerDescription(params);
15600
15633
  } else if (command.id === RemoveDefinedNameMutation.id) {
15601
- const param = command.params;
15602
- this._unregisterDescription(param);
15634
+ const params = command.params;
15635
+ this._unregisterDescription(params);
15603
15636
  }
15604
15637
  }));
15605
15638
  }
15606
- _registerDescription(param) {
15607
- const target = this._getUnitIdAndSheetId(param);
15639
+ _updateDescriptions(event) {
15640
+ const target = getSheetCommandTarget(this._univerInstanceService);
15608
15641
  if (!target) return;
15609
- const { sheetId } = target;
15610
- const { name, comment, formulaOrRefString, localSheetId } = param;
15611
- if (!this._descriptionService.hasDescription(name) && (localSheetId == null || localSheetId === SCOPE_WORKBOOK_VALUE_DEFINED_NAME || localSheetId === sheetId)) this._descriptionService.registerDescriptions([{
15642
+ const { unitId, subUnitId } = target;
15643
+ const { type, unitId: updateUnitId, definedNames } = event;
15644
+ if (updateUnitId !== unitId) return;
15645
+ if (type === "update") {
15646
+ const functionList = [];
15647
+ definedNames.forEach((definedName) => {
15648
+ const { name, comment, formulaOrRefString, localSheetId } = definedName;
15649
+ if (localSheetId == null || localSheetId === SCOPE_WORKBOOK_VALUE_DEFINED_NAME || localSheetId === subUnitId) functionList.push({
15650
+ functionName: name,
15651
+ description: formulaOrRefString + (comment || ""),
15652
+ abstract: formulaOrRefString,
15653
+ functionType: FunctionType.DefinedName,
15654
+ functionParameter: []
15655
+ });
15656
+ });
15657
+ this._descriptionService.registerDescriptions(functionList);
15658
+ } else if (type === "remove") {
15659
+ const functionList = [];
15660
+ definedNames.forEach((definedName) => {
15661
+ functionList.push(definedName.name);
15662
+ });
15663
+ this._descriptionService.unregisterDescriptions(functionList);
15664
+ }
15665
+ }
15666
+ _registerDescription(params) {
15667
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
15668
+ if (!target) return;
15669
+ const { subUnitId } = target;
15670
+ const { name, comment, formulaOrRefString, localSheetId } = params;
15671
+ if (this._descriptionService.hasDescription(name)) return;
15672
+ if (localSheetId == null || localSheetId === SCOPE_WORKBOOK_VALUE_DEFINED_NAME || localSheetId === subUnitId) this._descriptionService.registerDescriptions([{
15612
15673
  functionName: name,
15613
15674
  description: formulaOrRefString + (comment || ""),
15614
15675
  abstract: formulaOrRefString,
@@ -15621,9 +15682,9 @@ let DefinedNameController = class DefinedNameController extends Disposable {
15621
15682
  this._descriptionService.unregisterDescriptions([name]);
15622
15683
  }
15623
15684
  _unRegisterDescriptions() {
15624
- if (this._preUnitId == null) return;
15685
+ if (this._preUnitId === null) return;
15625
15686
  const definedNames = this._definedNamesService.getDefinedNameMap(this._preUnitId);
15626
- if (definedNames == null) return;
15687
+ if (!definedNames) return;
15627
15688
  const functionList = [];
15628
15689
  Array.from(Object.values(definedNames)).forEach((value) => {
15629
15690
  const { name } = value;
@@ -15632,28 +15693,21 @@ let DefinedNameController = class DefinedNameController extends Disposable {
15632
15693
  this._descriptionService.unregisterDescriptions(functionList);
15633
15694
  this._preUnitId = null;
15634
15695
  }
15635
- _getUnitIdAndSheetId(params = {}) {
15636
- const { unitId, subUnitId } = params;
15637
- const workbook = unitId ? this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
15638
- if (!workbook) return null;
15639
- const worksheet = subUnitId ? workbook.getSheetBySheetId(subUnitId) : workbook.getActiveSheet(true);
15640
- if (!worksheet) return null;
15641
- return {
15642
- unitId: workbook.getUnitId(),
15643
- sheetId: worksheet.getSheetId()
15644
- };
15645
- }
15646
- _registerDescriptions() {
15647
- const target = this._getUnitIdAndSheetId();
15696
+ _initRegisterDescriptions(unitId, subUnitId) {
15697
+ const target = getSheetCommandTarget(this._univerInstanceService, {
15698
+ unitId,
15699
+ subUnitId
15700
+ });
15648
15701
  if (!target) return;
15649
- const { unitId, sheetId } = target;
15650
- const definedNames = this._definedNamesService.getDefinedNameMap(unitId);
15702
+ const { unitId: _unitId, subUnitId: _subUnitId } = target;
15703
+ const definedNames = this._definedNamesService.getDefinedNameMap(_unitId);
15651
15704
  if (!definedNames) return;
15652
15705
  const functionList = [];
15653
- this._preUnitId = unitId;
15706
+ this._preUnitId = _unitId;
15654
15707
  Array.from(Object.values(definedNames)).forEach((value) => {
15655
15708
  const { name, comment, formulaOrRefString, localSheetId } = value;
15656
- if (!this._descriptionService.hasDescription(name) && (localSheetId == null || localSheetId === SCOPE_WORKBOOK_VALUE_DEFINED_NAME || localSheetId === sheetId)) functionList.push({
15709
+ if (this._descriptionService.hasDescription(name)) return;
15710
+ if (localSheetId == null || localSheetId === SCOPE_WORKBOOK_VALUE_DEFINED_NAME || localSheetId === _subUnitId) functionList.push({
15657
15711
  functionName: name,
15658
15712
  description: formulaOrRefString + (comment || ""),
15659
15713
  abstract: formulaOrRefString,
@@ -15663,16 +15717,13 @@ let DefinedNameController = class DefinedNameController extends Disposable {
15663
15717
  });
15664
15718
  this._descriptionService.registerDescriptions(functionList);
15665
15719
  }
15666
- _unregisterDescriptionsForNotInSheetId() {
15667
- const target = this._getUnitIdAndSheetId();
15668
- if (!target) return;
15669
- const { unitId, sheetId } = target;
15720
+ _unregisterDescriptionsForNotInSheetId(unitId, subUnitId) {
15670
15721
  const definedNames = this._definedNamesService.getDefinedNameMap(unitId);
15671
15722
  if (!definedNames) return;
15672
15723
  const functionList = [];
15673
15724
  Array.from(Object.values(definedNames)).forEach((value) => {
15674
15725
  const { name, localSheetId } = value;
15675
- if (localSheetId !== SCOPE_WORKBOOK_VALUE_DEFINED_NAME && localSheetId !== sheetId) functionList.push(name);
15726
+ if (localSheetId !== SCOPE_WORKBOOK_VALUE_DEFINED_NAME && localSheetId !== subUnitId) functionList.push(name);
15676
15727
  });
15677
15728
  this._descriptionService.unregisterDescriptions(functionList);
15678
15729
  }
@@ -16179,19 +16230,16 @@ let RegisterFunctionService = class RegisterFunctionService extends Disposable {
16179
16230
  const { locales, description, calculate } = params;
16180
16231
  if (locales) this._localeService.load(locales);
16181
16232
  const disposables = new DisposableCollection();
16182
- if (description) disposables.add(this._descriptionService.registerDescriptions(description));
16183
- else {
16184
- const descriptionList = calculate.map(([_func, functionName, functionIntroduction]) => {
16185
- return {
16186
- functionName,
16187
- functionType: FunctionType.User,
16188
- description: "",
16189
- abstract: functionIntroduction || "",
16190
- functionParameter: []
16191
- };
16192
- });
16193
- disposables.add(this._functionService.registerDescriptions(...descriptionList));
16194
- }
16233
+ const descriptions = description !== null && description !== void 0 ? description : calculate.map(([_func, functionName, functionIntroduction]) => {
16234
+ return {
16235
+ functionName,
16236
+ functionType: FunctionType.User,
16237
+ description: "",
16238
+ abstract: functionIntroduction || "",
16239
+ functionParameter: []
16240
+ };
16241
+ });
16242
+ disposables.add(this._descriptionService.registerDescriptions(descriptions));
16195
16243
  disposables.add(this._registerLocalExecutors(calculate));
16196
16244
  if (this._remoteRegisterFunctionService) disposables.add(this._registerRemoteExecutors(calculate));
16197
16245
  return disposables;
@@ -31,10 +31,10 @@ export declare class DefinedNameController extends Disposable {
31
31
  private _descriptionListener;
32
32
  private _changeUnitListener;
33
33
  private _changeSheetListener;
34
+ private _updateDescriptions;
34
35
  private _registerDescription;
35
36
  private _unregisterDescription;
36
37
  private _unRegisterDescriptions;
37
- private _getUnitIdAndSheetId;
38
- private _registerDescriptions;
38
+ private _initRegisterDescriptions;
39
39
  private _unregisterDescriptionsForNotInSheetId;
40
40
  }
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import type { IDisposable } from '@univerjs/core';
17
17
  import type { IFunctionInfo, IFunctionNames } from '@univerjs/engine-formula';
18
- import { IConfigService, LocaleService } from '@univerjs/core';
18
+ import { Disposable, IConfigService, LocaleService } from '@univerjs/core';
19
19
  import { FunctionType, IFunctionService } from '@univerjs/engine-formula';
20
20
  export interface ISearchItem {
21
21
  name: string;
@@ -32,60 +32,52 @@ export interface IDescriptionService {
32
32
  hasFunction(searchText: string): boolean;
33
33
  /**
34
34
  * get function info by name
35
- * @param searchText
36
35
  */
37
36
  getFunctionInfo(searchText: string): IFunctionInfo | undefined;
38
37
  /**
39
38
  * get search list by name
40
- * @param searchText
41
- * @returns
42
39
  */
43
40
  getSearchListByName(searchText: string): ISearchItem[];
44
41
  /**
45
42
  * get search list by name, from first letter
46
- * @param searchText
47
- * @returns
48
43
  */
49
44
  getSearchListByNameFirstLetter(searchText: string): ISearchItemWithType[];
50
45
  /**
51
46
  * get search list by type, if type is -1, return all
52
- * @param type
53
- * @returns
54
47
  */
55
48
  getSearchListByType(type: number): ISearchItem[];
56
49
  /**
57
50
  * register descriptions
58
- * @param functionList
59
51
  */
60
52
  registerDescriptions(functionList: IFunctionInfo[]): IDisposable;
61
53
  /**
62
54
  * unregister descriptions
63
- * @param functionList
64
55
  */
65
56
  unregisterDescriptions(functionNames: string[]): void;
66
57
  /**
67
58
  * check if has description
68
- * @param name
69
59
  */
70
60
  hasDescription(name: string): boolean;
71
61
  /**
72
62
  * check if has defined name description
73
- * @param name
74
63
  */
75
64
  hasDefinedNameDescription(name: string): boolean;
76
65
  /**
77
66
  * check if is formula defined name
78
- * @param name
79
67
  */
80
68
  isFormulaDefinedName(name: string): boolean;
81
69
  }
82
70
  export declare const IDescriptionService: import("@wendellhu/redi").IdentifierDecorator<IDescriptionService>;
83
- export declare class DescriptionService implements IDescriptionService, IDisposable {
71
+ export declare class DescriptionService extends Disposable implements IDescriptionService {
84
72
  private readonly _functionService;
85
73
  private readonly _localeService;
86
74
  private readonly _configService;
87
75
  private _descriptions;
88
76
  constructor(_functionService: IFunctionService, _localeService: LocaleService, _configService: IConfigService);
77
+ private _initialize;
78
+ private _initDescriptions;
79
+ private _initRegisterDescriptions;
80
+ private _registerDescriptions;
89
81
  dispose(): void;
90
82
  getDescriptions(): Map<IFunctionNames, IFunctionInfo>;
91
83
  hasFunction(searchText: string): boolean;
@@ -93,12 +85,9 @@ export declare class DescriptionService implements IDescriptionService, IDisposa
93
85
  getSearchListByName(searchText: string): ISearchItem[];
94
86
  getSearchListByNameFirstLetter(searchText: string): ISearchItemWithType[];
95
87
  getSearchListByType(type: number): ISearchItem[];
96
- registerDescriptions(description: IFunctionInfo[]): IDisposable;
88
+ registerDescriptions(descriptions: IFunctionInfo[]): IDisposable;
97
89
  unregisterDescriptions(functionNames: string[]): void;
98
90
  hasDescription(name: string): boolean;
99
91
  hasDefinedNameDescription(name: string): boolean;
100
92
  isFormulaDefinedName(name: string): boolean;
101
- private _initialize;
102
- private _initDescription;
103
- private _registerDescriptions;
104
93
  }