@univerjs/sheets-formula-ui 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/es/index.js CHANGED
@@ -1,19 +1,17 @@
1
1
  import { AbsoluteRefType, BuildTextUtils, CellValueType, ColorKit, CommandType, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DocumentFlavor, EDITOR_ACTIVATED, FOCUSING_FX_BAR_EDITOR, HorizontalAlign, ICommandService, IConfigService, IContextService, ILogService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, ObjectMatrix, Plugin, RANGE_TYPE, Range, Rectangle, RichTextBuilder, RxDisposable, ThemeService, Tools, UniverInstanceType, VerticalAlign, createIdentifier, createInternalEditorID, generateRandomId, getCellValueType, getEmptyCell, isFormulaId, isFormulaString, isICellData, isRealNum, merge, noop, registerDependencies, toDisposable, touchDependencies } from "@univerjs/core";
2
- import { BaseSelectionRenderService, COPY_SPECIAL_MENU_ID, COPY_TYPE, CellAlertManagerService, CellAlertType, EMBEDDING_FORMULA_EDITOR, EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY, ExpandSelectionCommand, HoverManagerService, IEditorBridgeService, IMarkSelectionService, ISheetClipboardService, ISheetSelectionRenderService, JumpOver, MoveSelectionCommand, PASTE_SPECIAL_MENU_ID, PREDEFINED_HOOK_NAME_COPY, PREDEFINED_HOOK_NAME_PASTE, RANGE_SELECTOR_COMPONENT_KEY, SELECTION_SHAPE_DEPTH, SelectionControl, SetCellEditVisibleOperation, SheetPasteCommand, SheetSkeletonManagerService, SheetsUIPart, checkInHeaderRanges, genNormalSelectionStyle, getAllSelection, getCoordByOffset, getCurrentRangeDisable$, getSheetObject, menuClipboardDisabledObservable, useActiveWorkbook, whenSheetEditorActivated, whenSheetEditorFocused } from "@univerjs/sheets-ui";
3
- import { ErrorType, FormulaDataModel, FunctionType, LexerTreeBuilder, SetArrayFormulaDataMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStopMutation, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, extractFormulaError, generateStringWithSequence, getAbsoluteRefTypeWithSingleString, handleRefStringInfo, isFormulaLexerToken, matchRefDrawToken, matchToken, operatorToken, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from "@univerjs/engine-formula";
2
+ import { BaseSelectionRenderService, COPY_SPECIAL_MENU_ID, COPY_TYPE, CellAlertManagerService, CellAlertType, EMBEDDING_FORMULA_EDITOR, EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY, ExpandSelectionCommand, HoverManagerService, IEditorBridgeService, IMarkSelectionService, ISheetClipboardService, ISheetSelectionRenderService, JumpOver, MoveSelectionCommand, PASTE_SPECIAL_MENU_ID, PREDEFINED_HOOK_NAME_COPY, PREDEFINED_HOOK_NAME_PASTE, RANGE_SELECTOR_COMPONENT_KEY, SELECTION_SHAPE_DEPTH, SelectionControl, SetCellEditVisibleOperation, SheetPasteCommand, SheetSkeletonManagerService, SheetsUIPart, UniverSheetsUIPlugin, checkInHeaderRanges, genNormalSelectionStyle, getAllSelection, getCoordByOffset, getCurrentRangeDisable$, getSheetObject, menuClipboardDisabledObservable, useActiveWorkbook, whenSheetEditorActivated, whenSheetEditorFocused } from "@univerjs/sheets-ui";
3
+ import { ErrorType, FormulaDataModel, FunctionType, IDescriptionService, LexerTreeBuilder, SetArrayFormulaDataMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStopMutation, UniverFormulaEnginePlugin, buildFormulaTextRuns, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, extractFormulaError, generateStringWithSequence, getAbsoluteRefTypeWithSingleString, getFormulaHighlightDataStream, getFormulaReplaceResult, handleRefStringInfo, isFormulaLexerToken, isFormulaReferenceAddingContext, isFormulaReferenceAddingTextContext, matchRefDrawToken, matchToken, operatorToken, searchFormulaFunctions, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from "@univerjs/engine-formula";
4
4
  import { BehaviorSubject, Subject, combineLatestWith, debounceTime, distinctUntilChanged, filter, map, merge as merge$1, throttleTime } from "rxjs";
5
5
  import { DocBackScrollRenderController, DocSelectionRenderService, IEditorService, MoveCursorOperation, MoveSelectionOperation, ReplaceTextRunsCommand, RichTextEditor, createEditorUndoRedoKeyboardConfig, useKeyboardEvent, useResize } from "@univerjs/docs-ui";
6
- import { DeviceInputEventType, IRenderManagerService, SHEET_VIEWPORT_KEY, ScrollTimerType, Vector2 } from "@univerjs/engine-render";
7
- import { BEFORE_CELL_EDIT, INTERCEPTOR_POINT, IRefSelectionsService, REF_SELECTIONS_ENABLED, RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, ReorderRangeCommand, SelectionMoveType, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetRowAutoHeightMutation, SheetInterceptorService, SheetSkeletonService, SheetsSelectionsService, WorkbookCopyPermission, WorkbookEditablePermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetSetCellValuePermission, attachSelectionWithCoord, convertSelectionDataToRange, getCellAtRowCol, getSheetCommandTarget, setEndForRange } from "@univerjs/sheets";
6
+ import { DeviceInputEventType, IRenderManagerService, SHEET_VIEWPORT_KEY, ScrollTimerType, UniverRenderEnginePlugin, Vector2 } from "@univerjs/engine-render";
7
+ import { BEFORE_CELL_EDIT, INTERCEPTOR_POINT, IRefSelectionsService, REF_SELECTIONS_ENABLED, RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, ReorderRangeCommand, SelectionMoveType, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetRowAutoHeightMutation, SheetInterceptorService, SheetSkeletonService, SheetsSelectionsService, UniverSheetsPlugin, WorkbookCopyPermission, WorkbookEditablePermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetSetCellValuePermission, attachSelectionWithCoord, convertSelectionDataToRange, getCellAtRowCol, getSheetCommandTarget, setEndForRange } from "@univerjs/sheets";
8
8
  import { ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, QuickSumCommand, TriggerCalculationController, UniverSheetsFormulaPlugin } from "@univerjs/sheets-formula";
9
9
  import { BuiltInUIPart, ComponentManager, IContextMenuService, IMenuManagerService, IShortcutService, ISidebarService, IUIPartsService, IconManager, KeyCode, MenuItemType, MetaKeys, ProgressBar, RectPopup, RibbonFormulasGroup, connectInjector, getMenuHiddenObservable, useDependency, useEvent, useObservable, useUpdateEffect } from "@univerjs/ui";
10
10
  import { DocSelectionManagerService } from "@univerjs/docs";
11
- import { IDescriptionService } from "@univerjs/formula";
12
11
  import { CheckMarkIcon, CloseIcon, DatabaseFunctionIcon, DateFunctionIcon, DeleteIcon, EngineeringFunctionIcon, FinancialFunctionIcon, FunctionIcon, IncreaseIcon, InformationFunctionIcon, LogicalFunctionIcon, LookupFunctionIcon, MathFunctionIcon, MoreRightIcon, SelectRangeIcon, StatisticalFunctionIcon, TextFunctionIcon } from "@univerjs/icons";
13
12
  import { Button, Dialog, Input, Select, Tooltip, borderClassName, borderLeftClassName, borderTopClassName, clsx, divideYClassName, scrollbarClassName } from "@univerjs/design";
14
13
  import { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
15
14
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
16
- import { buildFormulaTextRuns, getFormulaHighlightDataStream, getFormulaReplaceResult, isFormulaReferenceAddingContext, isFormulaReferenceAddingTextContext, searchFormulaFunctions } from "@univerjs/formula-ui";
17
15
  import { debounceTime as debounceTime$1 } from "rxjs/operators";
18
16
 
19
17
  //#region src/commands/commands/formula-clipboard.command.ts
@@ -33,7 +31,7 @@ const SheetOnlyPasteFormulaCommand = {
33
31
  };
34
32
 
35
33
  //#endregion
36
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
34
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
37
35
  function _typeof(o) {
38
36
  "@babel/helpers - typeof";
39
37
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -44,7 +42,7 @@ function _typeof(o) {
44
42
  }
45
43
 
46
44
  //#endregion
47
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
45
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
48
46
  function toPrimitive(t, r) {
49
47
  if ("object" != _typeof(t) || !t) return t;
50
48
  var e = t[Symbol.toPrimitive];
@@ -57,14 +55,14 @@ function toPrimitive(t, r) {
57
55
  }
58
56
 
59
57
  //#endregion
60
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
58
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
61
59
  function toPropertyKey(t) {
62
60
  var i = toPrimitive(t, "string");
63
61
  return "symbol" == _typeof(i) ? i : i + "";
64
62
  }
65
63
 
66
64
  //#endregion
67
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
65
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
68
66
  function _defineProperty(e, r, t) {
69
67
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
70
68
  value: t,
@@ -75,7 +73,7 @@ function _defineProperty(e, r, t) {
75
73
  }
76
74
 
77
75
  //#endregion
78
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
76
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
79
77
  function __decorateParam(paramIndex, decorator) {
80
78
  return function(target, key) {
81
79
  decorator(target, key, paramIndex);
@@ -83,7 +81,7 @@ function __decorateParam(paramIndex, decorator) {
83
81
  }
84
82
 
85
83
  //#endregion
86
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
84
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
87
85
  function __decorate(decorators, target, key, desc) {
88
86
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
89
87
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -307,10 +305,9 @@ const InsertFunctionOperation = {
307
305
  let editColumn = 0;
308
306
  let editFormulaRangeString = "";
309
307
  if (currentSelections.length === 1 && (isSingleCell(currentSelections[0].range) || isMultiRowsColumnsRange(currentSelections[0].range) && rangeHasNoNumber(cellMatrix, currentSelections[0].range))) {
310
- var _primary$actualRow, _primary$actualColumn;
311
308
  const { range, primary } = currentSelections[0];
312
- const row = (_primary$actualRow = primary === null || primary === void 0 ? void 0 : primary.actualRow) !== null && _primary$actualRow !== void 0 ? _primary$actualRow : range.startRow;
313
- const column = (_primary$actualColumn = primary === null || primary === void 0 ? void 0 : primary.actualColumn) !== null && _primary$actualColumn !== void 0 ? _primary$actualColumn : range.startColumn;
309
+ const row = (primary === null || primary === void 0 ? void 0 : primary.actualRow) ?? range.startRow;
310
+ const column = (primary === null || primary === void 0 ? void 0 : primary.actualColumn) ?? range.startColumn;
314
311
  editRange = range;
315
312
  editRow = row;
316
313
  editColumn = column;
@@ -319,9 +316,8 @@ const InsertFunctionOperation = {
319
316
  } else currentSelections.some((selection) => {
320
317
  const { range, primary } = selection;
321
318
  if (rangeHasNoNumber(cellMatrix, range)) {
322
- var _primary$actualRow2, _primary$actualColumn2;
323
- const row = (_primary$actualRow2 = primary === null || primary === void 0 ? void 0 : primary.actualRow) !== null && _primary$actualRow2 !== void 0 ? _primary$actualRow2 : range.startRow;
324
- const column = (_primary$actualColumn2 = primary === null || primary === void 0 ? void 0 : primary.actualColumn) !== null && _primary$actualColumn2 !== void 0 ? _primary$actualColumn2 : range.startColumn;
319
+ const row = (primary === null || primary === void 0 ? void 0 : primary.actualRow) ?? range.startRow;
320
+ const column = (primary === null || primary === void 0 ? void 0 : primary.actualColumn) ?? range.startColumn;
325
321
  const refRange = findRefRange(cellMatrix, row, column);
326
322
  if (!refRange) {
327
323
  editRange = range;
@@ -329,7 +325,8 @@ const InsertFunctionOperation = {
329
325
  editColumn = column;
330
326
  return true;
331
327
  }
332
- const formulaString = `=${value}(${serializeRange(refRange)})`;
328
+ const rangeString = serializeRange(refRange);
329
+ const formulaString = `=${value}(${rangeString})`;
333
330
  list.push({
334
331
  range,
335
332
  primary: {
@@ -342,12 +339,13 @@ const InsertFunctionOperation = {
342
339
  const { startRow, startColumn, endRow, endColumn } = range;
343
340
  if (startRow === endRow) {
344
341
  const blankCellColumn = findBlankCellOfRow(cellMatrix, startRow, endColumn, worksheet.getColumnCount() - 1);
345
- const formulaString = `=${value}(${serializeRange({
342
+ const rangeString = serializeRange({
346
343
  startRow,
347
344
  endRow,
348
345
  startColumn,
349
346
  endColumn: blankCellColumn === endColumn ? endColumn - 1 : endColumn
350
- })})`;
347
+ });
348
+ const formulaString = `=${value}(${rangeString})`;
351
349
  listOfRangeHasNumber.push({
352
350
  range,
353
351
  primary: {
@@ -364,12 +362,13 @@ const InsertFunctionOperation = {
364
362
  }
365
363
  const newEndRow = maxBlankCellRow === endRow ? endRow - 1 : endRow;
366
364
  for (let c = startColumn; c <= endColumn; c++) {
367
- const formulaString = `=${value}(${serializeRange({
365
+ const rangeString = serializeRange({
368
366
  startRow,
369
367
  endRow: newEndRow,
370
368
  startColumn: c,
371
369
  endColumn: c
372
- })})`;
370
+ });
371
+ const formulaString = `=${value}(${rangeString})`;
373
372
  listOfRangeHasNumber.push({
374
373
  range,
375
374
  primary: {
@@ -665,7 +664,7 @@ const ReferenceAbsoluteOperation = {
665
664
  id: "formula-ui.operation.change-ref-to-absolute",
666
665
  type: CommandType.OPERATION,
667
666
  handler: async (accessor) => {
668
- var _focusEditor$getDocum, _focusEditor$getDocum2;
667
+ var _focusEditor$getDocum;
669
668
  const editorService = accessor.get(IEditorService);
670
669
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
671
670
  const lexerTreeBuilder = accessor.get(LexerTreeBuilder);
@@ -675,7 +674,7 @@ const ReferenceAbsoluteOperation = {
675
674
  if (editorId !== DOCS_NORMAL_EDITOR_UNIT_ID_KEY && editorId !== DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) return false;
676
675
  const activeTextRange = docSelectionManagerService.getActiveTextRange();
677
676
  if (!activeTextRange) return false;
678
- const nextReferenceState = toggleReferenceAbsoluteAtCursor(lexerTreeBuilder, BuildTextUtils.transform.getPlainText((_focusEditor$getDocum = (_focusEditor$getDocum2 = focusEditor.getDocumentData().body) === null || _focusEditor$getDocum2 === void 0 ? void 0 : _focusEditor$getDocum2.dataStream) !== null && _focusEditor$getDocum !== void 0 ? _focusEditor$getDocum : ""), activeTextRange.endOffset);
677
+ const nextReferenceState = toggleReferenceAbsoluteAtCursor(lexerTreeBuilder, BuildTextUtils.transform.getPlainText(((_focusEditor$getDocum = focusEditor.getDocumentData().body) === null || _focusEditor$getDocum === void 0 ? void 0 : _focusEditor$getDocum.dataStream) ?? ""), activeTextRange.endOffset);
679
678
  if (!nextReferenceState) return false;
680
679
  focusEditor.replaceText(nextReferenceState.formulaText, [{
681
680
  startOffset: nextReferenceState.cursorOffset,
@@ -745,7 +744,7 @@ let FormulaReorderController = class FormulaReorderController extends Disposable
745
744
  const redos = [];
746
745
  const undos = [];
747
746
  const { unitId, subUnitId, range, order } = params;
748
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
747
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
749
748
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
750
749
  if (!worksheet) return {
751
750
  redos,
@@ -994,7 +993,7 @@ const menuSchema = {
994
993
  //#endregion
995
994
  //#region package.json
996
995
  var name = "@univerjs/sheets-formula-ui";
997
- var version = "1.0.0-alpha.7";
996
+ var version = "1.0.0-beta.0";
998
997
 
999
998
  //#endregion
1000
999
  //#region src/config/config.ts
@@ -1048,8 +1047,7 @@ const FORMULA_EMBED_CHILD_UNIT_ID_ATTRIBUTE = "data-embed-child-unit-id";
1048
1047
  const IFormulaEmbedRuntimeFocusCoordinator = createIdentifier("sheets-formula-ui.embed-runtime-focus-coordinator");
1049
1048
  const IFormulaEmbedInteractionBoundaryService = createIdentifier("sheets-formula-ui.embed-interaction-boundary.service");
1050
1049
  function registerFormulaEditorRuntimePortal(options) {
1051
- var _options$ownerDocumen;
1052
- const ownerDocument = (_options$ownerDocumen = options.ownerDocument) !== null && _options$ownerDocumen !== void 0 ? _options$ownerDocumen : typeof document === "undefined" ? void 0 : document;
1050
+ const ownerDocument = options.ownerDocument ?? (typeof document === "undefined" ? void 0 : document);
1053
1051
  if (!ownerDocument) return toDisposable(() => {});
1054
1052
  const collection = new DisposableCollection();
1055
1053
  const view = ownerDocument.defaultView;
@@ -1104,8 +1102,7 @@ function registerFormulaEditorRuntimePortal(options) {
1104
1102
  return collection;
1105
1103
  }
1106
1104
  function resolveFormulaEditorPortalRoot(editorId, ownerDocument) {
1107
- var _ref;
1108
- return (_ref = ownerDocument.getElementById(`univer-doc-selection-container-${editorId}`)) !== null && _ref !== void 0 ? _ref : ownerDocument.getElementById(`__editor_${editorId}`);
1105
+ return ownerDocument.getElementById(`univer-doc-selection-container-${editorId}`) ?? ownerDocument.getElementById(`__editor_${editorId}`);
1109
1106
  }
1110
1107
  function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
1111
1108
  const collection = new DisposableCollection();
@@ -1121,14 +1118,13 @@ function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
1121
1118
  return collection;
1122
1119
  }
1123
1120
  function resolveFormulaEmbedRuntimeDomScope(root) {
1124
- var _scopeElement$getAttr, _scopeElement$getAttr2;
1125
1121
  const scopeElement = root === null || root === void 0 ? void 0 : root.closest(`[${FORMULA_EMBED_ID_ATTRIBUTE}]`);
1126
1122
  const embedId = scopeElement === null || scopeElement === void 0 ? void 0 : scopeElement.getAttribute(FORMULA_EMBED_ID_ATTRIBUTE);
1127
1123
  if (!scopeElement || !embedId) return;
1128
1124
  return {
1129
1125
  embedId,
1130
- hostUnitId: (_scopeElement$getAttr = scopeElement.getAttribute("data-embed-host-unit-id")) !== null && _scopeElement$getAttr !== void 0 ? _scopeElement$getAttr : void 0,
1131
- childUnitId: (_scopeElement$getAttr2 = scopeElement.getAttribute("data-embed-child-unit-id")) !== null && _scopeElement$getAttr2 !== void 0 ? _scopeElement$getAttr2 : void 0
1126
+ hostUnitId: scopeElement.getAttribute("data-embed-host-unit-id") ?? void 0,
1127
+ childUnitId: scopeElement.getAttribute("data-embed-child-unit-id") ?? void 0
1132
1128
  };
1133
1129
  }
1134
1130
  function resolveActiveFormulaEmbedRuntimeDomScope(ownerDocument) {
@@ -1140,9 +1136,9 @@ function isEventTargetInSameFormulaEmbedInteractionBoundary(left, right) {
1140
1136
  return Boolean(leftOwner && leftOwner === resolveFormulaEmbedInteractionOwnerId(right));
1141
1137
  }
1142
1138
  function resolveFormulaEmbedInteractionOwnerId(target) {
1143
- var _target$closest$getAt, _target$closest;
1139
+ var _target$closest;
1144
1140
  if (!(target instanceof Element)) return;
1145
- return (_target$closest$getAt = (_target$closest = target.closest(`[${"data-embed-interaction-boundary-owner"}]`)) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute("data-embed-interaction-boundary-owner")) !== null && _target$closest$getAt !== void 0 ? _target$closest$getAt : void 0;
1141
+ return ((_target$closest = target.closest(`[${"data-embed-interaction-boundary-owner"}]`)) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute("data-embed-interaction-boundary-owner")) ?? void 0;
1146
1142
  }
1147
1143
 
1148
1144
  //#endregion
@@ -1254,7 +1250,7 @@ function useEditorPosition(editorId, ready, deps) {
1254
1250
  univerInstanceService.unitAdded$,
1255
1251
  updatePosition,
1256
1252
  ready,
1257
- ...deps !== null && deps !== void 0 ? deps : []
1253
+ ...deps ?? []
1258
1254
  ]);
1259
1255
  useResizeScrollObserver(updatePosition);
1260
1256
  useEffect(() => {
@@ -1308,7 +1304,7 @@ const useFormulaDescribe = (isNeed, formulaText, editor) => {
1308
1304
  };
1309
1305
  useEffect(() => {
1310
1306
  const nodes = lexerTreeBuilder.sequenceNodesBuilder(formulaText.slice(1));
1311
- formulaPromptService.setSequenceNodes(nodes !== null && nodes !== void 0 ? nodes : []);
1307
+ formulaPromptService.setSequenceNodes(nodes ?? []);
1312
1308
  }, [formulaText]);
1313
1309
  useEffect(() => {
1314
1310
  if (editor && isNeed) {
@@ -1321,14 +1317,16 @@ const useFormulaDescribe = (isNeed, formulaText, editor) => {
1321
1317
  const currentSequenceNode = formulaPromptService.getCurrentSequenceNodeByIndex(nodeIndex);
1322
1318
  const nextSequenceNode = formulaPromptService.getCurrentSequenceNodeByIndex(nodeIndex + 1);
1323
1319
  if (currentSequenceNode) if (typeof currentSequenceNode !== "string" && currentSequenceNode.nodeType === 3 && !descriptionService.hasDefinedNameDescription(currentSequenceNode.token.trim()) && nextSequenceNode === matchToken.OPEN_BRACKET) {
1324
- setFunctionInfo(descriptionService.getFunctionInfo(currentSequenceNode.token));
1320
+ const info = descriptionService.getFunctionInfo(currentSequenceNode.token);
1321
+ setFunctionInfo(info);
1325
1322
  setParamIndex(-1);
1326
1323
  return;
1327
1324
  } else {
1328
1325
  const res = lexerTreeBuilder.getFunctionAndParameter(`${formulaTextRef.current}A`, startOffset - 1);
1329
1326
  if (res) {
1330
1327
  const { functionName, paramIndex } = res;
1331
- setFunctionInfo(descriptionService.getFunctionInfo(functionName));
1328
+ const info = descriptionService.getFunctionInfo(functionName);
1329
+ setFunctionInfo(info);
1332
1330
  setParamIndex(paramIndex);
1333
1331
  return;
1334
1332
  }
@@ -1384,20 +1382,19 @@ const HelpHiddenTip = ({ onClick }) => {
1384
1382
 
1385
1383
  //#endregion
1386
1384
  //#region src/views/formula-editor/help-function/HelpFunction.tsx
1387
- const Params = ({ className, title, titleKey, value }) => {
1388
- const localeService = useDependency(LocaleService);
1385
+ function Params({ className, title, value }) {
1389
1386
  return /* @__PURE__ */ jsxs("div", {
1390
1387
  className: "univer-my-2",
1391
1388
  children: [/* @__PURE__ */ jsx("div", {
1392
1389
  className: clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white", className),
1393
- children: titleKey ? localeService.t(titleKey) : title
1390
+ children: title
1394
1391
  }), /* @__PURE__ */ jsx("div", {
1395
1392
  className: "univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",
1396
1393
  children: value
1397
1394
  })]
1398
1395
  });
1399
- };
1400
- const Help = (props) => {
1396
+ }
1397
+ function Help(props) {
1401
1398
  const { prefix, value, active, onClick } = props;
1402
1399
  return /* @__PURE__ */ jsxs("div", { children: [
1403
1400
  /* @__PURE__ */ jsxs("span", { children: [prefix, "("] }),
@@ -1408,7 +1405,7 @@ const Help = (props) => {
1408
1405
  }), i === value.length - 1 ? "" : ","] }, item.name)),
1409
1406
  ")"
1410
1407
  ] });
1411
- };
1408
+ }
1412
1409
  function HelpFunction(props) {
1413
1410
  const { onParamsSwitch = noop, onClose: propColose = noop, isFocus, editor, formulaText } = props;
1414
1411
  const { functionInfo, paramIndex, reset } = useFormulaDescribe(isFocus, formulaText, editor);
@@ -1472,11 +1469,11 @@ function HelpFunction(props) {
1472
1469
  className: "univer-mt-3",
1473
1470
  children: [
1474
1471
  /* @__PURE__ */ jsx(Params, {
1475
- titleKey: "sheets-formula-ui.prompt.helpExample",
1472
+ title: localeService.t("sheets-formula-ui.prompt.helpExample"),
1476
1473
  value: `${functionInfo.functionName}(${functionInfo.functionParameter.map((item) => item.example).join(",")})`
1477
1474
  }),
1478
1475
  /* @__PURE__ */ jsx(Params, {
1479
- titleKey: "sheets-formula-ui.prompt.helpAbstract",
1476
+ title: localeService.t("sheets-formula-ui.prompt.helpAbstract"),
1480
1477
  value: functionInfo.description
1481
1478
  }),
1482
1479
  functionInfo && functionInfo.functionParameter && functionInfo.functionParameter.map((item, i) => /* @__PURE__ */ jsx(Params, {
@@ -1504,8 +1501,8 @@ function focusFormulaEditor(editorService, editor, offset) {
1504
1501
  endOffset: offset
1505
1502
  }]);
1506
1503
  else if (!selections.length) {
1507
- var _editor$getDocumentDa, _editor$getDocumentDa2;
1508
- const body = (_editor$getDocumentDa = (_editor$getDocumentDa2 = editor.getDocumentData().body) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.dataStream) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : "\r\n";
1504
+ var _editor$getDocumentDa;
1505
+ const body = ((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "\r\n";
1509
1506
  const offset = Math.max(body.length - 2, 0);
1510
1507
  editor.setSelectionRanges([{
1511
1508
  startOffset: offset,
@@ -1514,8 +1511,8 @@ function focusFormulaEditor(editorService, editor, offset) {
1514
1511
  } else editor.setSelectionRanges(selections);
1515
1512
  }
1516
1513
  function focusFormulaEditorElement(editor) {
1517
- var _editor$editorDOM$own, _editor$editorDOM;
1518
- const editorElement = ((_editor$editorDOM$own = (_editor$editorDOM = editor.editorDOM) === null || _editor$editorDOM === void 0 ? void 0 : _editor$editorDOM.ownerDocument) !== null && _editor$editorDOM$own !== void 0 ? _editor$editorDOM$own : document).getElementById(`__editor_${editor.getEditorId()}`);
1514
+ var _editor$editorDOM;
1515
+ const editorElement = (((_editor$editorDOM = editor.editorDOM) === null || _editor$editorDOM === void 0 ? void 0 : _editor$editorDOM.ownerDocument) ?? document).getElementById(`__editor_${editor.getEditorId()}`);
1519
1516
  editorElement === null || editorElement === void 0 || editorElement.focus({ preventScroll: true });
1520
1517
  }
1521
1518
  function shouldSkipFormulaEditorMouseUpFocus(_target) {
@@ -1649,9 +1646,8 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends BaseSe
1649
1646
  * @param {ISelectionWithCoord} selectionWithStyle
1650
1647
  */
1651
1648
  _addSelectionControlByModelData(selectionWithStyle) {
1652
- var _selectionWithStyle$s;
1653
1649
  const skeleton = this._skeleton;
1654
- const style = (_selectionWithStyle$s = selectionWithStyle.style) !== null && _selectionWithStyle$s !== void 0 ? _selectionWithStyle$s : genNormalSelectionStyle(this._themeService);
1650
+ const style = selectionWithStyle.style ?? genNormalSelectionStyle(this._themeService);
1655
1651
  const scene = this._scene;
1656
1652
  selectionWithStyle.style = style;
1657
1653
  return this.newSelectionControl(scene, skeleton, selectionWithStyle);
@@ -1883,18 +1879,17 @@ function getDefaultRefSelectionStyle(themeService) {
1883
1879
  //#endregion
1884
1880
  //#region src/views/formula-editor/hooks/use-formula-selection.ts
1885
1881
  function resolveFormulaSelectionDataStream(accssor, editor, editorId) {
1886
- var _editor$getDocumentDa, _documentModel$getBod, _documentModel$getBod2;
1882
+ var _editor$getDocumentDa, _documentModel$getBod;
1887
1883
  const editorDataStream = editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream;
1888
1884
  if (editorDataStream != null) return {
1889
1885
  dataStream: editorDataStream,
1890
1886
  offset: 0
1891
1887
  };
1892
1888
  const univerInstanceService = accssor.get(IUniverInstanceService);
1893
- const editorDocumentModel = editorId ? univerInstanceService.getUnit(editorId, UniverInstanceType.UNIVER_DOC) : void 0;
1894
- const documentModel = editorDocumentModel !== null && editorDocumentModel !== void 0 ? editorDocumentModel : univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
1889
+ const documentModel = (editorId ? univerInstanceService.getUnit(editorId, UniverInstanceType.UNIVER_DOC) : void 0) ?? univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
1895
1890
  if (!(documentModel === null || documentModel === void 0 ? void 0 : documentModel.getBody())) return;
1896
1891
  return {
1897
- dataStream: (_documentModel$getBod = (_documentModel$getBod2 = documentModel.getBody()) === null || _documentModel$getBod2 === void 0 ? void 0 : _documentModel$getBod2.dataStream) !== null && _documentModel$getBod !== void 0 ? _documentModel$getBod : "",
1892
+ dataStream: ((_documentModel$getBod = documentModel.getBody()) === null || _documentModel$getBod === void 0 ? void 0 : _documentModel$getBod.dataStream) ?? "",
1898
1893
  offset: 0
1899
1894
  };
1900
1895
  }
@@ -1902,8 +1897,7 @@ function shouldSkipReferenceEditingByPointer(isDisabledByPointer, disableOnClick
1902
1897
  return isDisabledByPointer && !disableOnClick;
1903
1898
  }
1904
1899
  function resolveFormulaSelectionWorkbook(currentWorkbook, fallbackWorkbook) {
1905
- var _ref;
1906
- return (_ref = currentWorkbook !== null && currentWorkbook !== void 0 ? currentWorkbook : fallbackWorkbook) !== null && _ref !== void 0 ? _ref : void 0;
1900
+ return currentWorkbook ?? fallbackWorkbook ?? void 0;
1907
1901
  }
1908
1902
  function resolveFormulaSelectionCursorIndex(activeRange, dataStream) {
1909
1903
  const index = (activeRange === null || activeRange === void 0 ? void 0 : activeRange.collapsed) ? activeRange.startOffset : -1;
@@ -1933,8 +1927,8 @@ function useFormulaSelecting(opts) {
1933
1927
  const { editor, editorId, isFocus, disableOnClick, unitId, subUnitId } = opts;
1934
1928
  const renderManagerService = useDependency(IRenderManagerService);
1935
1929
  const univerInstanceService = useDependency(IUniverInstanceService);
1936
- const sheetRenderer = renderManagerService.getRenderById(unitId);
1937
- const renderer = renderManagerService.getRenderById(editorId);
1930
+ const sheetRenderer = renderManagerService.getRenderUnitById(unitId);
1931
+ const renderer = renderManagerService.getRenderUnitById(editorId);
1938
1932
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocSelectionRenderService);
1939
1933
  const docSelectionManagerService = useDependency(DocSelectionManagerService);
1940
1934
  const injector = useDependency(Injector);
@@ -1952,16 +1946,16 @@ function useFormulaSelecting(opts) {
1952
1946
  innerSetIsSelecting(v);
1953
1947
  });
1954
1948
  const calculateSelectingType = useEvent(() => {
1955
- var _editor$getSelectionR, _editor$getSelectionR2, _config$dataStream, _getSelectionAfterLag, _lexerTreeBuilder$seq;
1949
+ var _editor$getSelectionR, _config$dataStream;
1956
1950
  const currentWorkbook = resolveFormulaSelectionWorkbook(univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET), workbook);
1957
1951
  if (!currentWorkbook) return;
1958
1952
  const currentSheet = currentWorkbook.getActiveSheet();
1959
- const activeRange = (_editor$getSelectionR = editor === null || editor === void 0 || (_editor$getSelectionR2 = editor.getSelectionRanges()) === null || _editor$getSelectionR2 === void 0 ? void 0 : _editor$getSelectionR2[0]) !== null && _editor$getSelectionR !== void 0 ? _editor$getSelectionR : docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getActiveTextRange();
1953
+ const activeRange = (editor === null || editor === void 0 || (_editor$getSelectionR = editor.getSelectionRanges()) === null || _editor$getSelectionR === void 0 ? void 0 : _editor$getSelectionR[0]) ?? (docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getActiveTextRange());
1960
1954
  const config = resolveFormulaSelectionDataStream(injector, editor, editorId);
1961
1955
  if (!config) return;
1962
1956
  const dataStream = config === null || config === void 0 || (_config$dataStream = config.dataStream) === null || _config$dataStream === void 0 ? void 0 : _config$dataStream.slice(0, -2);
1963
- const index = resolveFormulaSelectionCursorIndex((_getSelectionAfterLag = getSelectionAfterLaggingFormulaInput(dataStream, activeRange, lastInputContentRef.current)) !== null && _getSelectionAfterLag !== void 0 ? _getSelectionAfterLag : activeRange, dataStream);
1964
- const nodes = ((_lexerTreeBuilder$seq = lexerTreeBuilder.sequenceNodesBuilder(dataStream)) !== null && _lexerTreeBuilder$seq !== void 0 ? _lexerTreeBuilder$seq : []).map((node) => {
1957
+ const index = resolveFormulaSelectionCursorIndex(getSelectionAfterLaggingFormulaInput(dataStream, activeRange, lastInputContentRef.current) ?? activeRange, dataStream);
1958
+ const nodes = (lexerTreeBuilder.sequenceNodesBuilder(dataStream) ?? []).map((node) => {
1965
1959
  if (typeof node === "object") {
1966
1960
  if (node.nodeType === sequenceNodeType.REFERENCE) return {
1967
1961
  ...node,
@@ -2163,19 +2157,19 @@ function useSheetHighlight(unitId, subUnitId) {
2163
2157
  const themeService = useDependency(ThemeService);
2164
2158
  const refSelectionsService = useDependency(IRefSelectionsService);
2165
2159
  const renderManagerService = useDependency(IRenderManagerService);
2166
- const ownerRender = renderManagerService.getRenderById(unitId);
2160
+ const ownerRender = renderManagerService.getRenderUnitById(unitId);
2167
2161
  const ownerRefSelectionsRenderService = ownerRender === null || ownerRender === void 0 ? void 0 : ownerRender.with(RefSelectionsRenderService);
2168
2162
  const getHighlightWorkbook = useEvent((refSelections) => {
2169
2163
  const ownerWorkbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
2170
2164
  const currentWorkbook = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
2171
2165
  const currentUnitId = currentWorkbook === null || currentWorkbook === void 0 ? void 0 : currentWorkbook.getUnitId();
2172
- return Boolean(currentUnitId) && refSelections.some((refSelection) => deserializeRangeWithSheet(refSelection.token).unitId === currentUnitId) ? currentWorkbook : ownerWorkbook !== null && ownerWorkbook !== void 0 ? ownerWorkbook : currentWorkbook;
2166
+ return Boolean(currentUnitId) && refSelections.some((refSelection) => deserializeRangeWithSheet(refSelection.token).unitId === currentUnitId) ? currentWorkbook : ownerWorkbook ?? currentWorkbook;
2173
2167
  });
2174
2168
  const highlightSheet = useEvent((refSelections, editor, isEnd = false) => {
2175
2169
  var _currentWorkbook$getA;
2176
2170
  const currentWorkbook = getHighlightWorkbook(refSelections);
2177
2171
  if (!currentWorkbook) return;
2178
- const currentRender = renderManagerService.getRenderById(currentWorkbook.getUnitId());
2172
+ const currentRender = renderManagerService.getRenderUnitById(currentWorkbook.getUnitId());
2179
2173
  const refSelectionsRenderService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(RefSelectionsRenderService);
2180
2174
  const sheetSelectionRenderService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(ISheetSelectionRenderService);
2181
2175
  const sheetSkeletonManagerService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(SheetSkeletonManagerService);
@@ -2231,7 +2225,7 @@ function useDocHight(_leadingCharacter = "") {
2231
2225
  e.ed = e.ed + leadingCharacterLength;
2232
2226
  e.st = e.st + leadingCharacterLength;
2233
2227
  });
2234
- const highlightDataStream = getFormulaHighlightDataStream$1(_leadingCharacter, sequenceNodes, sourceText);
2228
+ const highlightDataStream = getFormulaHighlightDataStream(_leadingCharacter, sequenceNodes, sourceText);
2235
2229
  const highlightTextRuns = [{
2236
2230
  st: 0,
2237
2231
  ed: 1,
@@ -2249,7 +2243,7 @@ function useDocHight(_leadingCharacter = "") {
2249
2243
  commandService.syncExecuteCommand(ReplaceTextRunsCommand.id, {
2250
2244
  unitId: editorId,
2251
2245
  body: createFormulaHighlightBody(highlightDataStream.slice(0, -2), highlightTextRuns),
2252
- textRanges: newSelections !== null && newSelections !== void 0 ? newSelections : selections
2246
+ textRanges: newSelections ?? selections
2253
2247
  });
2254
2248
  return refSelections;
2255
2249
  }
@@ -2266,9 +2260,6 @@ function createFormulaHighlightBody(dataStream, textRuns) {
2266
2260
  textRuns
2267
2261
  };
2268
2262
  }
2269
- function getFormulaHighlightDataStream$1(leadingCharacter, sequenceNodes, sourceText) {
2270
- return getFormulaHighlightDataStream(leadingCharacter, sequenceNodes, sourceText);
2271
- }
2272
2263
  function useColor() {
2273
2264
  const themeService = useDependency(ThemeService);
2274
2265
  return useMemo(() => {
@@ -2304,10 +2295,9 @@ function shouldMoveFormulaSelectionFromCurrentSelection(selectingType, refSelect
2304
2295
  return selectingType === 3;
2305
2296
  }
2306
2297
  function isFormulaEditorInteractionOwner(focusEditorId, editorId, options) {
2307
- var _options$formulaBarEd, _options$normalEditor;
2308
2298
  if (focusEditorId === editorId) return true;
2309
2299
  if (!(options === null || options === void 0 ? void 0 : options.fxBarFocused)) return false;
2310
- return editorId === ((_options$formulaBarEd = options.formulaBarEditorId) !== null && _options$formulaBarEd !== void 0 ? _options$formulaBarEd : DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && focusEditorId === ((_options$normalEditor = options.normalEditorId) !== null && _options$normalEditor !== void 0 ? _options$normalEditor : DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
2300
+ return editorId === (options.formulaBarEditorId ?? DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && focusEditorId === (options.normalEditorId ?? DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
2311
2301
  }
2312
2302
  const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEditor, getRefSelectionCount) => {
2313
2303
  const commandService = useDependency(ICommandService);
@@ -2353,8 +2343,8 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2353
2343
  else if (keycode === KeyCode.ARROW_LEFT) direction = Direction.LEFT;
2354
2344
  else if (keycode === KeyCode.ARROW_RIGHT) direction = Direction.RIGHT;
2355
2345
  if (shouldMoveSelectionRef.current) {
2356
- var _getRefSelectionCount, _getRefSelectionCount2;
2357
- const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, (_getRefSelectionCount = (_getRefSelectionCount2 = getRefSelectionCountRef.current) === null || _getRefSelectionCount2 === void 0 ? void 0 : _getRefSelectionCount2.call(getRefSelectionCountRef)) !== null && _getRefSelectionCount !== void 0 ? _getRefSelectionCount : 0);
2346
+ var _getRefSelectionCount;
2347
+ const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, ((_getRefSelectionCount = getRefSelectionCountRef.current) === null || _getRefSelectionCount === void 0 ? void 0 : _getRefSelectionCount.call(getRefSelectionCountRef)) ?? 0);
2358
2348
  if (metaKey === MetaKeys.CTRL_COMMAND) commandService.executeCommand(MoveSelectionCommand.id, {
2359
2349
  direction,
2360
2350
  jumpOver: JumpOver.moveGap,
@@ -2470,14 +2460,13 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2470
2460
  //#endregion
2471
2461
  //#region src/views/formula-editor/hooks/use-refactor-effect.ts
2472
2462
  const useRefactorEffect = (isNeed, selecting, unitId, editorId, disableContextMenu = true) => {
2473
- var _currentUnit$getUnitI;
2474
2463
  const renderManagerService = useDependency(IRenderManagerService);
2475
2464
  const contextService = useDependency(IContextService);
2476
2465
  const contextMenuService = useDependency(IContextMenuService);
2477
2466
  const refSelectionsService = useDependency(IRefSelectionsService);
2478
2467
  const univerInstanceService = useDependency(IUniverInstanceService);
2479
2468
  const currentUnit = useObservable(useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET), [univerInstanceService]));
2480
- const render = renderManagerService.getRenderById((_currentUnit$getUnitI = currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== null && _currentUnit$getUnitI !== void 0 ? _currentUnit$getUnitI : "");
2469
+ const render = renderManagerService.getRenderUnitById((currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) ?? "");
2481
2470
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
2482
2471
  useLayoutEffect(() => {
2483
2472
  if (isNeed) {
@@ -2566,11 +2555,11 @@ const unitRangesToText = (ranges, isNeedSheetName = false, originSheetName = "",
2566
2555
  //#endregion
2567
2556
  //#region src/views/formula-editor/hooks/use-sheet-selection-change.ts
2568
2557
  const prepareSelectionChangeContext = (opts) => {
2569
- var _editor$getDocumentDa, _editor$getDocumentDa2, _lexerTreeBuilder$seq;
2558
+ var _editor$getDocumentDa;
2570
2559
  const { editor, lexerTreeBuilder } = opts;
2571
2560
  const currentDocSelections = editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges();
2572
- const dataStream = ((_editor$getDocumentDa = editor === null || editor === void 0 || (_editor$getDocumentDa2 = editor.getDocumentData().body) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.dataStream) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : "\r\n").slice(0, -2);
2573
- const sequenceNodes = (_lexerTreeBuilder$seq = lexerTreeBuilder.sequenceNodesBuilder(dataStream.slice(1))) !== null && _lexerTreeBuilder$seq !== void 0 ? _lexerTreeBuilder$seq : [];
2561
+ const dataStream = ((editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "\r\n").slice(0, -2);
2562
+ const sequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(dataStream.slice(1)) ?? [];
2574
2563
  let offset;
2575
2564
  if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) offset = currentDocSelections[0].startOffset - 1;
2576
2565
  else if (dataStream.startsWith("=")) offset = Math.max(dataStream.length - 1, 0);
@@ -2605,14 +2594,13 @@ function getLastFormulaSelection(selections) {
2605
2594
  return selections[selections.length - 1];
2606
2595
  }
2607
2596
  function getFormulaSelectionIdentityKey(selection) {
2608
- var _ref, _item$rangeWithCoord, _range$startRow, _range$endRow, _range$startColumn, _range$endColumn;
2609
2597
  const item = selection;
2610
- const range = (_ref = (_item$rangeWithCoord = item.rangeWithCoord) !== null && _item$rangeWithCoord !== void 0 ? _item$rangeWithCoord : item.range) !== null && _ref !== void 0 ? _ref : item;
2598
+ const range = item.rangeWithCoord ?? item.range ?? item;
2611
2599
  return [
2612
- (_range$startRow = range.startRow) !== null && _range$startRow !== void 0 ? _range$startRow : "",
2613
- (_range$endRow = range.endRow) !== null && _range$endRow !== void 0 ? _range$endRow : "",
2614
- (_range$startColumn = range.startColumn) !== null && _range$startColumn !== void 0 ? _range$startColumn : "",
2615
- (_range$endColumn = range.endColumn) !== null && _range$endColumn !== void 0 ? _range$endColumn : ""
2600
+ range.startRow ?? "",
2601
+ range.endRow ?? "",
2602
+ range.startColumn ?? "",
2603
+ range.endColumn ?? ""
2616
2604
  ].join(":");
2617
2605
  }
2618
2606
  function isSameFormulaSelection(first, second) {
@@ -2647,10 +2635,9 @@ function createSelectionChangeDuplicateEndGuard() {
2647
2635
  };
2648
2636
  }
2649
2637
  function createSelectionChangeHandler(opts) {
2650
- var _opts$duplicateEndGua;
2651
2638
  let prevSelectionsCount = opts.initialSelectionsCount;
2652
2639
  let pendingCtrlAddCount = 0;
2653
- const duplicateEndGuard = (_opts$duplicateEndGua = opts.duplicateEndGuard) !== null && _opts$duplicateEndGua !== void 0 ? _opts$duplicateEndGua : createSelectionChangeDuplicateEndGuard();
2640
+ const duplicateEndGuard = opts.duplicateEndGuard ?? createSelectionChangeDuplicateEndGuard();
2654
2641
  return (selections, isEnd, options) => {
2655
2642
  if (options === null || options === void 0 ? void 0 : options.initial) return;
2656
2643
  if (selections.length === 0) return;
@@ -2696,7 +2683,6 @@ function getInitialFormulaReferenceSelectionCount(renderSelectionCount, formulaR
2696
2683
  return Math.max(renderSelectionCount, formulaReferenceCount);
2697
2684
  }
2698
2685
  const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUnitId, getRefSelections, isSupportAcrossSheet, listenSelectionSet, editor, handleRangeChange = noop) => {
2699
- var _activeWorkbook$getUn;
2700
2686
  const renderManagerService = useDependency(IRenderManagerService);
2701
2687
  const univerInstanceService = useDependency(IUniverInstanceService);
2702
2688
  const commandService = useDependency(ICommandService);
@@ -2707,8 +2693,8 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2707
2693
  const lexerTreeBuilder = useDependency(LexerTreeBuilder);
2708
2694
  const workbook = univerInstanceService.getUnit(unitId);
2709
2695
  const getSheetNameById = useEvent((unitId, sheetId) => {
2710
- var _univerInstanceServic, _univerInstanceServic2;
2711
- return (_univerInstanceServic = (_univerInstanceServic2 = univerInstanceService.getUnit(unitId)) === null || _univerInstanceServic2 === void 0 || (_univerInstanceServic2 = _univerInstanceServic2.getSheetBySheetId(sheetId)) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getName()) !== null && _univerInstanceServic !== void 0 ? _univerInstanceServic : "";
2696
+ var _univerInstanceServic;
2697
+ return ((_univerInstanceServic = univerInstanceService.getUnit(unitId)) === null || _univerInstanceServic === void 0 || (_univerInstanceServic = _univerInstanceServic.getSheetBySheetId(sheetId)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getName()) ?? "";
2712
2698
  });
2713
2699
  const sheetName = useMemo(() => getSheetNameById(unitId, subUnitId), [
2714
2700
  getSheetNameById,
@@ -2721,7 +2707,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2721
2707
  sheetName
2722
2708
  });
2723
2709
  const activeWorkbook = resolveFormulaSelectionWorkbook(useObservable(useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET), [univerInstanceService])), workbook);
2724
- const render = renderManagerService.getRenderById((_activeWorkbook$getUn = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== null && _activeWorkbook$getUn !== void 0 ? _activeWorkbook$getUn : unitId);
2710
+ const render = renderManagerService.getRenderUnitById((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) ?? unitId);
2725
2711
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
2726
2712
  const sheetSkeletonManagerService = render === null || render === void 0 ? void 0 : render.with(SheetSkeletonManagerService);
2727
2713
  const refSelectionsService = useDependency(IRefSelectionsService);
@@ -2735,16 +2721,15 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2735
2721
  if (!ctx) return;
2736
2722
  const { nodeIndex, updatingRefIndex, formulaText, sequenceNodes, offset } = ctx;
2737
2723
  if (isSelectingRef.current === 1 || isFormulaReferenceAddingContext(sequenceNodes, offset) || isFormulaReferenceAddingTextContext(formulaText, offset)) if (offset !== 0) {
2738
- var _range$sheetId, _range$unitId, _range$unitId2;
2739
2724
  if (nodeIndex === -1 && sequenceNodes.length) return;
2740
2725
  const range = getLastFormulaSelection(selections);
2741
2726
  if (!range) return;
2742
2727
  const lastNodes = sequenceNodes.splice(nodeIndex + 1);
2743
- const rangeSheetId = (_range$sheetId = range.sheetId) !== null && _range$sheetId !== void 0 ? _range$sheetId : subUnitId;
2728
+ const rangeSheetId = range.sheetId ?? subUnitId;
2744
2729
  const unitRangeName = {
2745
2730
  range,
2746
- unitId: (_range$unitId = range.unitId) !== null && _range$unitId !== void 0 ? _range$unitId : activeWorkbook.getUnitId(),
2747
- sheetName: getSheetNameById((_range$unitId2 = range.unitId) !== null && _range$unitId2 !== void 0 ? _range$unitId2 : activeWorkbook.getUnitId(), rangeSheetId)
2731
+ unitId: range.unitId ?? activeWorkbook.getUnitId(),
2732
+ sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
2748
2733
  };
2749
2734
  const isAcrossSheet = rangeSheetId !== subUnitId;
2750
2735
  const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
@@ -2759,14 +2744,13 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2759
2744
  });
2760
2745
  handleRangeChange(sequenceNodeToText([...sequenceNodes, ...lastNodes]), getOffsetFromSequenceNodes(sequenceNodes), isEnd);
2761
2746
  } else {
2762
- var _range$sheetId2, _range$unitId3, _range$unitId4;
2763
2747
  const range = getLastFormulaSelection(selections);
2764
2748
  if (!range) return;
2765
- const rangeSheetId = (_range$sheetId2 = range.sheetId) !== null && _range$sheetId2 !== void 0 ? _range$sheetId2 : subUnitId;
2749
+ const rangeSheetId = range.sheetId ?? subUnitId;
2766
2750
  const unitRangeName = {
2767
2751
  range,
2768
- unitId: (_range$unitId3 = range.unitId) !== null && _range$unitId3 !== void 0 ? _range$unitId3 : activeWorkbook.getUnitId(),
2769
- sheetName: getSheetNameById((_range$unitId4 = range.unitId) !== null && _range$unitId4 !== void 0 ? _range$unitId4 : activeWorkbook.getUnitId(), rangeSheetId)
2752
+ unitId: range.unitId ?? activeWorkbook.getUnitId(),
2753
+ sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
2770
2754
  };
2771
2755
  const isAcrossSheet = rangeSheetId !== subUnitId;
2772
2756
  const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
@@ -2783,22 +2767,19 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2783
2767
  const node = sequenceNodes[nodeIndex];
2784
2768
  if (typeof node === "object" && node.nodeType === sequenceNodeType.REFERENCE) {
2785
2769
  const oldToken = node.token;
2786
- if ((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId) {
2787
- var _activeWorkbook$getUn2;
2788
- node.token = serializeRangeWithSpreadsheet((_activeWorkbook$getUn2 = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== null && _activeWorkbook$getUn2 !== void 0 ? _activeWorkbook$getUn2 : "", sheetName, last);
2789
- } else node.token = sheetName === (activeSheet === null || activeSheet === void 0 ? void 0 : activeSheet.getName()) ? serializeRange(last) : serializeRangeWithSheet(activeSheet.getName(), last);
2770
+ if ((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId) node.token = serializeRangeWithSpreadsheet((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) ?? "", sheetName, last);
2771
+ else node.token = sheetName === (activeSheet === null || activeSheet === void 0 ? void 0 : activeSheet.getName()) ? serializeRange(last) : serializeRangeWithSheet(activeSheet.getName(), last);
2790
2772
  const newOffset = offset + (node.token.length - oldToken.length);
2791
2773
  handleRangeChange(generateStringWithSequence(sequenceNodes), newOffset, isEnd);
2792
2774
  }
2793
2775
  } else {
2794
2776
  const { orderedSelections, insertedSelection } = getSelectionsForFormulaRefUpdate(selections, updatingRefIndex, isCtrlAddMode);
2795
2777
  const getRefRangeText = (range) => {
2796
- var _range$sheetId3, _range$unitId5, _range$unitId6;
2797
- const rangeSheetId = (_range$sheetId3 = range.sheetId) !== null && _range$sheetId3 !== void 0 ? _range$sheetId3 : subUnitId;
2778
+ const rangeSheetId = range.sheetId ?? subUnitId;
2798
2779
  const unitRangeName = {
2799
2780
  range,
2800
- unitId: (_range$unitId5 = range.unitId) !== null && _range$unitId5 !== void 0 ? _range$unitId5 : activeWorkbook.getUnitId(),
2801
- sheetName: getSheetNameById((_range$unitId6 = range.unitId) !== null && _range$unitId6 !== void 0 ? _range$unitId6 : activeWorkbook.getUnitId(), rangeSheetId)
2781
+ unitId: range.unitId ?? activeWorkbook.getUnitId(),
2782
+ sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
2802
2783
  };
2803
2784
  const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
2804
2785
  return unitRangesToText([unitRangeName], isSupportAcrossSheet && (rangeSheetId !== subUnitId || isAcrossWorkbook), sheetName, isAcrossWorkbook)[0];
@@ -2926,7 +2907,6 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2926
2907
  if (params.selections.length) {
2927
2908
  const last = params.selections[params.selections.length - 1];
2928
2909
  if (last) {
2929
- var _refSelectionsRenderS;
2930
2910
  const { range, primary } = last;
2931
2911
  if (((primary === null || primary === void 0 ? void 0 : primary.isMergedMainCell) || (primary === null || primary === void 0 ? void 0 : primary.isMerged)) && Rectangle.contains(primary, range)) {
2932
2912
  range.startRow = primary.startRow;
@@ -2941,7 +2921,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2941
2921
  lexerTreeBuilder
2942
2922
  });
2943
2923
  const isAdd = isSelectingRef.current === 1 || Boolean(ctx && (isFormulaReferenceAddingContext(ctx.sequenceNodes, ctx.offset) || isFormulaReferenceAddingTextContext(ctx.formulaText, ctx.offset)));
2944
- const selections = ((_refSelectionsRenderS = refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.getSelectionDataWithStyle()) !== null && _refSelectionsRenderS !== void 0 ? _refSelectionsRenderS : []).map((i) => i.rangeWithCoord);
2924
+ const selections = ((refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.getSelectionDataWithStyle()) ?? []).map((i) => i.rangeWithCoord);
2945
2925
  if (isAdd) {
2946
2926
  if (selections.length > 0 && isSameFormulaSelection(selections[selections.length - 1], range)) return;
2947
2927
  selections.push(range);
@@ -3022,7 +3002,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
3022
3002
  const useSwitchSheet = (isNeed, unitId, isSupportAcrossSheet, isFocusSet, onBlur, refresh) => {
3023
3003
  const commandService = useDependency(ICommandService);
3024
3004
  const editorService = useDependency(IEditorService);
3025
- const render = useDependency(IRenderManagerService).getRenderById(unitId);
3005
+ const render = useDependency(IRenderManagerService).getRenderUnitById(unitId);
3026
3006
  const univerInstanceService = useDependency(IUniverInstanceService);
3027
3007
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
3028
3008
  useEffect(() => {
@@ -3113,7 +3093,8 @@ const useFormulaSearch = (isNeed, nodes = [], editor) => {
3113
3093
  if (currentNode && typeof currentNode !== "string" && currentNode.nodeType === sequenceNodeType.FUNCTION) {
3114
3094
  indexRef.current = currentNodeIndex;
3115
3095
  const token = currentNode.token;
3116
- setSearchList(searchFormulaFunctions(descriptionService, token));
3096
+ const list = searchFormulaFunctions(descriptionService, token);
3097
+ setSearchList(list);
3117
3098
  setSearchText(token);
3118
3099
  return;
3119
3100
  }
@@ -3340,7 +3321,7 @@ function syncCounterpartFormulaEditorSelection(editorService, editorId, selectio
3340
3321
  (_editorService$getEdi = editorService.getEditor(syncEditorId)) === null || _editorService$getEdi === void 0 || _editorService$getEdi.setSelectionRanges(selections, false);
3341
3322
  }
3342
3323
  const FormulaEditor = forwardRef((props, ref) => {
3343
- var _document$getBody$dat2, _document$getBody2, _configService$getCon, _configService$getCon2;
3324
+ var _document$getBody2, _configService$getCon;
3344
3325
  const { errorText, initValue, unitId, subUnitId, isFocus: _isFocus = true, isSupportAcrossSheet = false, onFocus = noop, onBlur = noop, onChange: propOnChange, onVerify, className, editorId: propEditorId, moveCursor = true, onFormulaSelectingChange: propOnFormulaSelectingChange, keyboardEventConfig, onMoveInEditor, resetSelectionOnBlur = true, autoScrollbar = true, isSingle = true, disableSelectionOnClick = false, autofocus = true, disableContextMenu, style, borderless = false, canvasStyle } = props;
3345
3326
  const editorService = useDependency(IEditorService);
3346
3327
  const commandService = useDependency(ICommandService);
@@ -3357,15 +3338,15 @@ const FormulaEditor = forwardRef((props, ref) => {
3357
3338
  const [editor, setEditor] = useState();
3358
3339
  const [isFocus, setIsFocus] = useState(_isFocus);
3359
3340
  const formulaEditorContainerRef = useRef(null);
3360
- const editorId = useMemo(() => propEditorId !== null && propEditorId !== void 0 ? propEditorId : createInternalEditorID(`${EMBEDDING_FORMULA_EDITOR}-${generateRandomId(4)}`), []);
3341
+ const editorId = useMemo(() => propEditorId ?? createInternalEditorID(`${EMBEDDING_FORMULA_EDITOR}-${generateRandomId(4)}`), []);
3361
3342
  const isError = errorText !== void 0;
3362
3343
  const univerInstanceService = useDependency(IUniverInstanceService);
3363
3344
  const document = univerInstanceService.getUnit(editorId);
3364
3345
  const getFormulaToken = useFormulaToken();
3365
3346
  const formulaText = useObservable(document ? () => document.change$.pipe(map(() => {
3366
- var _document$getBody$dat, _document$getBody;
3367
- return BuildTextUtils.transform.getPlainText((_document$getBody$dat = (_document$getBody = document.getBody()) === null || _document$getBody === void 0 ? void 0 : _document$getBody.dataStream) !== null && _document$getBody$dat !== void 0 ? _document$getBody$dat : "");
3368
- })) : null, BuildTextUtils.transform.getPlainText((_document$getBody$dat2 = document === null || document === void 0 || (_document$getBody2 = document.getBody()) === null || _document$getBody2 === void 0 ? void 0 : _document$getBody2.dataStream) !== null && _document$getBody$dat2 !== void 0 ? _document$getBody$dat2 : ""), false, [document]);
3347
+ var _document$getBody;
3348
+ return BuildTextUtils.transform.getPlainText(((_document$getBody = document.getBody()) === null || _document$getBody === void 0 ? void 0 : _document$getBody.dataStream) ?? "");
3349
+ })) : null, BuildTextUtils.transform.getPlainText((document === null || document === void 0 || (_document$getBody2 = document.getBody()) === null || _document$getBody2 === void 0 ? void 0 : _document$getBody2.dataStream) ?? ""), false, [document]);
3369
3350
  const formulaTextRef = useStateRef(formulaText);
3370
3351
  const formulaWithoutEqualSymbol = useMemo(() => getFormulaText(formulaText), [formulaText]);
3371
3352
  const sequenceNodes = useMemo(() => getFormulaToken(formulaWithoutEqualSymbol), [formulaWithoutEqualSymbol, getFormulaToken]);
@@ -3378,7 +3359,7 @@ const FormulaEditor = forwardRef((props, ref) => {
3378
3359
  disableOnClick: disableSelectionOnClick
3379
3360
  });
3380
3361
  const highTextRef = useRef("");
3381
- const renderer = useDependency(IRenderManagerService).getRenderById(editorId);
3362
+ const renderer = useDependency(IRenderManagerService).getRenderUnitById(editorId);
3382
3363
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocSelectionRenderService);
3383
3364
  const isFocusing = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing;
3384
3365
  const currentDoc = useObservable(useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC), [univerInstanceService]));
@@ -3387,7 +3368,7 @@ const FormulaEditor = forwardRef((props, ref) => {
3387
3368
  const getRefSelections = useEvent(() => refSelectionsRef.current);
3388
3369
  const getRefSelectionCount = useEvent(() => getRefSelections().length);
3389
3370
  const selectingMode = isSelecting;
3390
- const functionScreenTips = (_configService$getCon = (_configService$getCon2 = useDependency(IConfigService).getConfig("sheets-formula-ui.base.config")) === null || _configService$getCon2 === void 0 ? void 0 : _configService$getCon2.functionScreenTips) !== null && _configService$getCon !== void 0 ? _configService$getCon : true;
3371
+ const functionScreenTips = ((_configService$getCon = useDependency(IConfigService).getConfig("sheets-formula-ui.base.config")) === null || _configService$getCon === void 0 ? void 0 : _configService$getCon.functionScreenTips) ?? true;
3391
3372
  useUpdateEffect(() => {
3392
3373
  onChange(formulaText);
3393
3374
  }, [formulaText, onChange]);
@@ -3396,9 +3377,9 @@ const FormulaEditor = forwardRef((props, ref) => {
3396
3377
  const subscription = editor.input$.subscribe(({ content, isComposing }) => {
3397
3378
  if (isComposing) return;
3398
3379
  queueMicrotask(() => {
3399
- var _editor$getSelectionR, _editor$getDocumentDa, _editor$getDocumentDa2;
3380
+ var _editor$getSelectionR, _editor$getDocumentDa;
3400
3381
  const selection = (_editor$getSelectionR = editor.getSelectionRanges()) === null || _editor$getSelectionR === void 0 ? void 0 : _editor$getSelectionR[0];
3401
- const normalizedSelection = getSelectionAfterLaggingFormulaInput((_editor$getDocumentDa = (_editor$getDocumentDa2 = editor.getDocumentData().body) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.dataStream) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : "", selection, content);
3382
+ const normalizedSelection = getSelectionAfterLaggingFormulaInput(((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "", selection, content);
3402
3383
  if (!normalizedSelection) return;
3403
3384
  const selections = [normalizedSelection];
3404
3385
  editor.setSelectionRanges(selections, false);
@@ -3422,7 +3403,7 @@ const FormulaEditor = forwardRef((props, ref) => {
3422
3403
  const ranges = highlightDoc(editorRef.current, sequenceNodes, isNeedResetSelection, newSelections, formulaStr);
3423
3404
  refSelectionsRef.current = ranges;
3424
3405
  if (isEnd) {
3425
- const currentDocSelections = newSelections !== null && newSelections !== void 0 ? newSelections : editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges();
3406
+ const currentDocSelections = newSelections ?? (editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges());
3426
3407
  if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) {
3427
3408
  const refIndex = findRefSequenceIndex(sequenceNodes, findIndexFromSequenceNodes(sequenceNodes, currentDocSelections[0].startOffset - 1, false));
3428
3409
  if (refIndex >= 0) {
@@ -3446,8 +3427,7 @@ const FormulaEditor = forwardRef((props, ref) => {
3446
3427
  const focus = useFocus(editor);
3447
3428
  const resetSelection = useResetSelection(isFocus, unitId, subUnitId);
3448
3429
  useEffect(() => {
3449
- var _docSelectionRenderSe;
3450
- onFormulaSelectingChange(isSelecting, (_docSelectionRenderSe = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : true);
3430
+ onFormulaSelectingChange(isSelecting, (docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) ?? true);
3451
3431
  }, [onFormulaSelectingChange, isSelecting]);
3452
3432
  useKeyboardEvent(isFocus, useMemo(() => createEditorUndoRedoKeyboardConfig({
3453
3433
  commandService,
@@ -3506,11 +3486,10 @@ const FormulaEditor = forwardRef((props, ref) => {
3506
3486
  };
3507
3487
  }, []);
3508
3488
  useEffect(() => {
3509
- var _ref, _resolveFormulaEmbedR;
3510
3489
  const formulaEditorContainer = formulaEditorContainerRef.current;
3511
3490
  if (!isFocus || !formulaEditorContainer || !injector.has(IFormulaEmbedRuntimeFocusCoordinator)) return;
3512
3491
  const focusCoordinator = injector.get(IFormulaEmbedRuntimeFocusCoordinator);
3513
- const scope = (_ref = (_resolveFormulaEmbedR = resolveFormulaEmbedRuntimeDomScope(formulaEditorContainer)) !== null && _resolveFormulaEmbedR !== void 0 ? _resolveFormulaEmbedR : focusCoordinator.resolveRuntimeScopeByChildUnitId(editorId)) !== null && _ref !== void 0 ? _ref : resolveActiveFormulaEmbedRuntimeDomScope(formulaEditorContainer.ownerDocument);
3492
+ const scope = resolveFormulaEmbedRuntimeDomScope(formulaEditorContainer) ?? focusCoordinator.resolveRuntimeScopeByChildUnitId(editorId) ?? resolveActiveFormulaEmbedRuntimeDomScope(formulaEditorContainer.ownerDocument);
3514
3493
  if (!scope) return;
3515
3494
  const collection = new DisposableCollection();
3516
3495
  const interactionBoundaryService = injector.has(IFormulaEmbedInteractionBoundaryService) ? injector.get(IFormulaEmbedInteractionBoundaryService) : void 0;
@@ -3816,11 +3795,13 @@ function SelectFunction(props) {
3816
3795
  };
3817
3796
  function handleSelectChange(value) {
3818
3797
  setTypeSelected(value);
3819
- setSelectList(descriptionService.getSearchListByType(+value));
3798
+ const selectList = descriptionService.getSearchListByType(+value);
3799
+ setSelectList(selectList);
3820
3800
  }
3821
3801
  function handleSearchInputChange(value) {
3822
3802
  setSearchText(value);
3823
- setSelectList(descriptionService.getSearchListByName(value));
3803
+ const selectList = descriptionService.getSearchListByName(value);
3804
+ setSelectList(selectList);
3824
3805
  }
3825
3806
  function handleSelectListKeyDown(e) {
3826
3807
  e.stopPropagation();
@@ -4013,7 +3994,7 @@ function useRangesHighlight(editor, focusing, unitId, subUnitId) {
4013
3994
  if (last.current === text) return;
4014
3995
  last.current = text;
4015
3996
  const nodes = lexerTreeBuilder.sequenceNodesBuilder(text);
4016
- setSequenceNodes(nodes !== null && nodes !== void 0 ? nodes : []);
3997
+ setSequenceNodes(nodes ?? []);
4017
3998
  }, [
4018
3999
  change,
4019
4000
  editor,
@@ -4022,13 +4003,13 @@ function useRangesHighlight(editor, focusing, unitId, subUnitId) {
4022
4003
  useEffect(() => {
4023
4004
  if (!editor) return;
4024
4005
  if (!focusing) {
4025
- var _current$body$dataStr, _current$body;
4006
+ var _current$body;
4026
4007
  const current = editor.getDocumentData();
4027
4008
  editor.setDocumentData({
4028
4009
  ...current,
4029
4010
  body: {
4030
4011
  ...current.body,
4031
- dataStream: (_current$body$dataStr = (_current$body = current.body) === null || _current$body === void 0 ? void 0 : _current$body.dataStream) !== null && _current$body$dataStr !== void 0 ? _current$body$dataStr : "",
4012
+ dataStream: ((_current$body = current.body) === null || _current$body === void 0 ? void 0 : _current$body.dataStream) ?? "",
4032
4013
  textRuns: []
4033
4014
  }
4034
4015
  });
@@ -4079,11 +4060,12 @@ function useRangeSelectorSelectionChange(opts) {
4079
4060
  if (!supportAcrossSheet && currentSheet.getSheetId() !== subUnitId) return;
4080
4061
  if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return;
4081
4062
  const sheetName = keepSheetReference ? currentSheet.getName() : currentSheet.getSheetId() === subUnitId ? "" : currentSheet.getName();
4082
- onChange(selections.map((item) => ({
4063
+ const ranges = selections.map((item) => ({
4083
4064
  range: item.range,
4084
4065
  unitId,
4085
4066
  sheetName
4086
- })), isStart);
4067
+ }));
4068
+ onChange(ranges, isStart);
4087
4069
  });
4088
4070
  useEffect(() => {
4089
4071
  const disposableCollection = new DisposableCollection();
@@ -4196,7 +4178,8 @@ function RangeSelectorDialog(props) {
4196
4178
  });
4197
4179
  } else {
4198
4180
  newRanges.splice(focusIndex, 1, ...addedRanges);
4199
- setRanges(newRanges.slice(0, maxRangeCount));
4181
+ const finalRanges = newRanges.slice(0, maxRangeCount);
4182
+ setRanges(finalRanges);
4200
4183
  setFocusIndex(focusIndex + addedRanges.length - 1);
4201
4184
  }
4202
4185
  }
@@ -4260,7 +4243,7 @@ function stringifyRanges(ranges) {
4260
4243
  function RangeSelector(props) {
4261
4244
  const [editor, setEditor] = useState(null);
4262
4245
  const { onVerify, selectorRef, unitId, subUnitId, maxRangeCount, supportAcrossSheet, keepSheetReference, autoFocus, onChange, onRangeSelectorDialogVisibleChange, onClickOutside, onFocusChange, forceShowDialogWhenSelectionChanged, hideEditor, resetRange } = props;
4263
- const [focusing, setFocusing] = useState(autoFocus !== null && autoFocus !== void 0 ? autoFocus : false);
4246
+ const [focusing, setFocusing] = useState(autoFocus ?? false);
4264
4247
  const [popupVisible, setPopupVisible] = useState(false);
4265
4248
  const [rangeSelectorRanges, setRangeSelectorRanges] = useState([]);
4266
4249
  const localeService = useDependency(LocaleService);
@@ -4274,9 +4257,9 @@ function RangeSelector(props) {
4274
4257
  editorService.blur();
4275
4258
  });
4276
4259
  const handleOpenModal = useEvent(() => {
4277
- var _editor$getDocumentDa, _editor$getDocumentDa2;
4260
+ var _editor$getDocumentDa;
4278
4261
  blurEditor();
4279
- setRangeSelectorRanges(parseRanges((_editor$getDocumentDa = editor === null || editor === void 0 || (_editor$getDocumentDa2 = editor.getDocumentDataModel()) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.getPlainText()) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : ""));
4262
+ setRangeSelectorRanges(parseRanges((editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentDataModel()) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.getPlainText()) ?? ""));
4280
4263
  setPopupVisible(true);
4281
4264
  });
4282
4265
  useEffect(() => {
@@ -4300,8 +4283,8 @@ function RangeSelector(props) {
4300
4283
  setPopupVisible(false);
4301
4284
  },
4302
4285
  getValue: () => {
4303
- var _editor$getDocumentDa3, _editor$getDocumentDa4;
4304
- return (_editor$getDocumentDa3 = editor === null || editor === void 0 || (_editor$getDocumentDa4 = editor.getDocumentDataModel()) === null || _editor$getDocumentDa4 === void 0 ? void 0 : _editor$getDocumentDa4.getPlainText()) !== null && _editor$getDocumentDa3 !== void 0 ? _editor$getDocumentDa3 : "";
4286
+ var _editor$getDocumentDa2;
4287
+ return (editor === null || editor === void 0 || (_editor$getDocumentDa2 = editor.getDocumentDataModel()) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.getPlainText()) ?? "";
4305
4288
  }
4306
4289
  };
4307
4290
  }, [
@@ -4312,8 +4295,8 @@ function RangeSelector(props) {
4312
4295
  sequenceNodesRef
4313
4296
  ]);
4314
4297
  useEffect(() => {
4315
- var _editor$getDocumentDa5, _editor$getDocumentDa6;
4316
- onVerify === null || onVerify === void 0 || onVerify(verifyRange(sequenceNodes), (_editor$getDocumentDa5 = editor === null || editor === void 0 || (_editor$getDocumentDa6 = editor.getDocumentDataModel()) === null || _editor$getDocumentDa6 === void 0 ? void 0 : _editor$getDocumentDa6.getPlainText()) !== null && _editor$getDocumentDa5 !== void 0 ? _editor$getDocumentDa5 : "");
4298
+ var _editor$getDocumentDa3;
4299
+ onVerify === null || onVerify === void 0 || onVerify(verifyRange(sequenceNodes), (editor === null || editor === void 0 || (_editor$getDocumentDa3 = editor.getDocumentDataModel()) === null || _editor$getDocumentDa3 === void 0 ? void 0 : _editor$getDocumentDa3.getPlainText()) ?? "");
4317
4300
  }, [sequenceNodes]);
4318
4301
  useEffect(() => {
4319
4302
  onRangeSelectorDialogVisibleChange === null || onRangeSelectorDialogVisibleChange === void 0 || onRangeSelectorDialogVisibleChange(popupVisible);
@@ -4331,6 +4314,7 @@ function RangeSelector(props) {
4331
4314
  return /* @__PURE__ */ jsxs(Fragment, { children: [!hideEditor ? /* @__PURE__ */ jsx(RichTextEditor, {
4332
4315
  isSingle: true,
4333
4316
  ...props,
4317
+ preserveHostFocus: true,
4334
4318
  onFocusChange: (focusing, newValue) => {
4335
4319
  setFocusing(focusing);
4336
4320
  onFocusChange === null || onFocusChange === void 0 || onFocusChange(focusing, newValue);
@@ -4357,10 +4341,9 @@ function RangeSelector(props) {
4357
4341
  maxRangeCount,
4358
4342
  onConfirm: (ranges) => {
4359
4343
  const resultStr = stringifyRanges(ranges);
4360
- const empty = RichTextBuilder.newEmptyData();
4361
- empty.body.dataStream = resultStr;
4344
+ const documentData = RichTextBuilder.create().insertText(resultStr).getData();
4362
4345
  editor === null || editor === void 0 || editor.replaceText(resultStr, false);
4363
- onChange === null || onChange === void 0 || onChange(empty, resultStr);
4346
+ onChange === null || onChange === void 0 || onChange(documentData, resultStr);
4364
4347
  setPopupVisible(false);
4365
4348
  setRangeSelectorRanges([]);
4366
4349
  requestAnimationFrame(() => {
@@ -4647,7 +4630,7 @@ function getSetCellFormulaMutations(unitId, subUnitId, range, matrix, accessor,
4647
4630
  const setValuesMutation = {
4648
4631
  unitId,
4649
4632
  subUnitId,
4650
- cellValue: valueMatrix.getData()
4633
+ cellValue: valueMatrix.clone()
4651
4634
  };
4652
4635
  redoMutationsInfo.push({
4653
4636
  id: SetRangeValuesMutation.id,
@@ -4990,7 +4973,7 @@ let FormulaEditorShowController = class FormulaEditorShowController extends Disp
4990
4973
  return cellInfo;
4991
4974
  }
4992
4975
  _createArrayFormulaRangeShape(arrayRange, unitId, subUnitId) {
4993
- const renderUnit = this._renderManagerService.getRenderById(unitId);
4976
+ const renderUnit = this._renderManagerService.getRenderUnitById(unitId);
4994
4977
  const skeleton = this._sheetSkeletonService.getSkeleton(unitId, subUnitId);
4995
4978
  if (!renderUnit || !skeleton) return;
4996
4979
  const { scene } = renderUnit;
@@ -5127,7 +5110,7 @@ let ImageFormulaRenderController = class ImageFormulaRenderController extends Di
5127
5110
  this._imageFormulaCellInterceptorController.registerRefreshRenderFunction(() => {
5128
5111
  const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
5129
5112
  if (!workbook) return;
5130
- const render = this._renderManagerService.getRenderById(workbook.getUnitId());
5113
+ const render = this._renderManagerService.getRenderUnitById(workbook.getUnitId());
5131
5114
  if (!render) return;
5132
5115
  render.with(SheetSkeletonManagerService).reCalculate();
5133
5116
  const mainComponent = render.mainComponent;
@@ -5271,13 +5254,12 @@ var GlobalRangeSelectorService = class {
5271
5254
  //#endregion
5272
5255
  //#region src/views/range-selector/Global.tsx
5273
5256
  const GlobalRangeSelector = () => {
5274
- var _current$unitId, _current$subUnitId;
5275
5257
  const current = useObservable(useDependency(GlobalRangeSelectorService).currentSelector$);
5276
5258
  const instance = useRef(null);
5277
5259
  useEffect(() => {
5278
5260
  if (current) {
5279
- var _instance$current, _current$initialValue;
5280
- (_instance$current = instance.current) === null || _instance$current === void 0 || _instance$current.showDialog((_current$initialValue = current.initialValue) !== null && _current$initialValue !== void 0 ? _current$initialValue : []);
5261
+ var _instance$current;
5262
+ (_instance$current = instance.current) === null || _instance$current === void 0 || _instance$current.showDialog(current.initialValue ?? []);
5281
5263
  return () => {
5282
5264
  var _instance$current2;
5283
5265
  (_instance$current2 = instance.current) === null || _instance$current2 === void 0 || _instance$current2.hideDialog();
@@ -5285,13 +5267,12 @@ const GlobalRangeSelector = () => {
5285
5267
  }
5286
5268
  }, [current]);
5287
5269
  return /* @__PURE__ */ jsx(RangeSelector, {
5288
- unitId: (_current$unitId = current === null || current === void 0 ? void 0 : current.unitId) !== null && _current$unitId !== void 0 ? _current$unitId : "",
5289
- subUnitId: (_current$subUnitId = current === null || current === void 0 ? void 0 : current.subUnitId) !== null && _current$subUnitId !== void 0 ? _current$subUnitId : "",
5270
+ unitId: (current === null || current === void 0 ? void 0 : current.unitId) ?? "",
5271
+ subUnitId: (current === null || current === void 0 ? void 0 : current.subUnitId) ?? "",
5290
5272
  hideEditor: true,
5291
5273
  selectorRef: instance,
5292
5274
  onChange: (_, value) => {
5293
- var _value$split$map;
5294
- current === null || current === void 0 || current.callback((_value$split$map = value === null || value === void 0 ? void 0 : value.split(",").map((i) => deserializeRangeWithSheet(i))) !== null && _value$split$map !== void 0 ? _value$split$map : []);
5275
+ current === null || current === void 0 || current.callback((value === null || value === void 0 ? void 0 : value.split(",").map((i) => deserializeRangeWithSheet(i))) ?? []);
5295
5276
  }
5296
5277
  });
5297
5278
  };
@@ -5353,7 +5334,7 @@ _defineProperty(UniverSheetsFormulaUIPlugin, "packageName", name);
5353
5334
  _defineProperty(UniverSheetsFormulaUIPlugin, "version", version);
5354
5335
  _defineProperty(UniverSheetsFormulaUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
5355
5336
  UniverSheetsFormulaUIPlugin = __decorate([
5356
- DependentOn(UniverSheetsFormulaPlugin),
5337
+ DependentOn(UniverFormulaEnginePlugin, UniverRenderEnginePlugin, UniverSheetsPlugin, UniverSheetsFormulaPlugin, UniverSheetsUIPlugin),
5357
5338
  __decorateParam(1, Inject(Injector)),
5358
5339
  __decorateParam(2, IRenderManagerService),
5359
5340
  __decorateParam(3, IConfigService),