@univerjs/sheets-formula-ui 1.0.0-alpha.8 → 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
@@ -6,7 +6,7 @@ import { DocBackScrollRenderController, DocSelectionRenderService, IEditorServic
6
6
  import { DeviceInputEventType, IRenderManagerService, SHEET_VIEWPORT_KEY, ScrollTimerType, UniverRenderEnginePlugin, Vector2 } from "@univerjs/engine-render";
7
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
- import { BuiltInUIPart, ComponentManager, IContextMenuService, IMenuManagerService, IShortcutService, ISidebarService, IUIPartsService, IconManager, KeyCode, MenuItemType, MetaKeys, ProgressBar, RectPopup, RibbonFormulasGroup, UniverUIPlugin, connectInjector, getMenuHiddenObservable, useDependency, useEvent, useObservable, useUpdateEffect } from "@univerjs/ui";
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
11
  import { CheckMarkIcon, CloseIcon, DatabaseFunctionIcon, DateFunctionIcon, DeleteIcon, EngineeringFunctionIcon, FinancialFunctionIcon, FunctionIcon, IncreaseIcon, InformationFunctionIcon, LogicalFunctionIcon, LookupFunctionIcon, MathFunctionIcon, MoreRightIcon, SelectRangeIcon, StatisticalFunctionIcon, TextFunctionIcon } from "@univerjs/icons";
12
12
  import { Button, Dialog, Input, Select, Tooltip, borderClassName, borderLeftClassName, borderTopClassName, clsx, divideYClassName, scrollbarClassName } from "@univerjs/design";
@@ -305,10 +305,9 @@ const InsertFunctionOperation = {
305
305
  let editColumn = 0;
306
306
  let editFormulaRangeString = "";
307
307
  if (currentSelections.length === 1 && (isSingleCell(currentSelections[0].range) || isMultiRowsColumnsRange(currentSelections[0].range) && rangeHasNoNumber(cellMatrix, currentSelections[0].range))) {
308
- var _primary$actualRow, _primary$actualColumn;
309
308
  const { range, primary } = currentSelections[0];
310
- const row = (_primary$actualRow = primary === null || primary === void 0 ? void 0 : primary.actualRow) !== null && _primary$actualRow !== void 0 ? _primary$actualRow : range.startRow;
311
- 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;
312
311
  editRange = range;
313
312
  editRow = row;
314
313
  editColumn = column;
@@ -317,9 +316,8 @@ const InsertFunctionOperation = {
317
316
  } else currentSelections.some((selection) => {
318
317
  const { range, primary } = selection;
319
318
  if (rangeHasNoNumber(cellMatrix, range)) {
320
- var _primary$actualRow2, _primary$actualColumn2;
321
- const row = (_primary$actualRow2 = primary === null || primary === void 0 ? void 0 : primary.actualRow) !== null && _primary$actualRow2 !== void 0 ? _primary$actualRow2 : range.startRow;
322
- 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;
323
321
  const refRange = findRefRange(cellMatrix, row, column);
324
322
  if (!refRange) {
325
323
  editRange = range;
@@ -666,7 +664,7 @@ const ReferenceAbsoluteOperation = {
666
664
  id: "formula-ui.operation.change-ref-to-absolute",
667
665
  type: CommandType.OPERATION,
668
666
  handler: async (accessor) => {
669
- var _focusEditor$getDocum, _focusEditor$getDocum2;
667
+ var _focusEditor$getDocum;
670
668
  const editorService = accessor.get(IEditorService);
671
669
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
672
670
  const lexerTreeBuilder = accessor.get(LexerTreeBuilder);
@@ -676,7 +674,7 @@ const ReferenceAbsoluteOperation = {
676
674
  if (editorId !== DOCS_NORMAL_EDITOR_UNIT_ID_KEY && editorId !== DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) return false;
677
675
  const activeTextRange = docSelectionManagerService.getActiveTextRange();
678
676
  if (!activeTextRange) return false;
679
- 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);
680
678
  if (!nextReferenceState) return false;
681
679
  focusEditor.replaceText(nextReferenceState.formulaText, [{
682
680
  startOffset: nextReferenceState.cursorOffset,
@@ -995,7 +993,7 @@ const menuSchema = {
995
993
  //#endregion
996
994
  //#region package.json
997
995
  var name = "@univerjs/sheets-formula-ui";
998
- var version = "1.0.0-alpha.8";
996
+ var version = "1.0.0-beta.0";
999
997
 
1000
998
  //#endregion
1001
999
  //#region src/config/config.ts
@@ -1049,8 +1047,7 @@ const FORMULA_EMBED_CHILD_UNIT_ID_ATTRIBUTE = "data-embed-child-unit-id";
1049
1047
  const IFormulaEmbedRuntimeFocusCoordinator = createIdentifier("sheets-formula-ui.embed-runtime-focus-coordinator");
1050
1048
  const IFormulaEmbedInteractionBoundaryService = createIdentifier("sheets-formula-ui.embed-interaction-boundary.service");
1051
1049
  function registerFormulaEditorRuntimePortal(options) {
1052
- var _options$ownerDocumen;
1053
- 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);
1054
1051
  if (!ownerDocument) return toDisposable(() => {});
1055
1052
  const collection = new DisposableCollection();
1056
1053
  const view = ownerDocument.defaultView;
@@ -1105,8 +1102,7 @@ function registerFormulaEditorRuntimePortal(options) {
1105
1102
  return collection;
1106
1103
  }
1107
1104
  function resolveFormulaEditorPortalRoot(editorId, ownerDocument) {
1108
- var _ref;
1109
- 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}`);
1110
1106
  }
1111
1107
  function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
1112
1108
  const collection = new DisposableCollection();
@@ -1122,14 +1118,13 @@ function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
1122
1118
  return collection;
1123
1119
  }
1124
1120
  function resolveFormulaEmbedRuntimeDomScope(root) {
1125
- var _scopeElement$getAttr, _scopeElement$getAttr2;
1126
1121
  const scopeElement = root === null || root === void 0 ? void 0 : root.closest(`[${FORMULA_EMBED_ID_ATTRIBUTE}]`);
1127
1122
  const embedId = scopeElement === null || scopeElement === void 0 ? void 0 : scopeElement.getAttribute(FORMULA_EMBED_ID_ATTRIBUTE);
1128
1123
  if (!scopeElement || !embedId) return;
1129
1124
  return {
1130
1125
  embedId,
1131
- hostUnitId: (_scopeElement$getAttr = scopeElement.getAttribute("data-embed-host-unit-id")) !== null && _scopeElement$getAttr !== void 0 ? _scopeElement$getAttr : void 0,
1132
- 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
1133
1128
  };
1134
1129
  }
1135
1130
  function resolveActiveFormulaEmbedRuntimeDomScope(ownerDocument) {
@@ -1141,9 +1136,9 @@ function isEventTargetInSameFormulaEmbedInteractionBoundary(left, right) {
1141
1136
  return Boolean(leftOwner && leftOwner === resolveFormulaEmbedInteractionOwnerId(right));
1142
1137
  }
1143
1138
  function resolveFormulaEmbedInteractionOwnerId(target) {
1144
- var _target$closest$getAt, _target$closest;
1139
+ var _target$closest;
1145
1140
  if (!(target instanceof Element)) return;
1146
- 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;
1147
1142
  }
1148
1143
 
1149
1144
  //#endregion
@@ -1255,7 +1250,7 @@ function useEditorPosition(editorId, ready, deps) {
1255
1250
  univerInstanceService.unitAdded$,
1256
1251
  updatePosition,
1257
1252
  ready,
1258
- ...deps !== null && deps !== void 0 ? deps : []
1253
+ ...deps ?? []
1259
1254
  ]);
1260
1255
  useResizeScrollObserver(updatePosition);
1261
1256
  useEffect(() => {
@@ -1309,7 +1304,7 @@ const useFormulaDescribe = (isNeed, formulaText, editor) => {
1309
1304
  };
1310
1305
  useEffect(() => {
1311
1306
  const nodes = lexerTreeBuilder.sequenceNodesBuilder(formulaText.slice(1));
1312
- formulaPromptService.setSequenceNodes(nodes !== null && nodes !== void 0 ? nodes : []);
1307
+ formulaPromptService.setSequenceNodes(nodes ?? []);
1313
1308
  }, [formulaText]);
1314
1309
  useEffect(() => {
1315
1310
  if (editor && isNeed) {
@@ -1387,20 +1382,19 @@ const HelpHiddenTip = ({ onClick }) => {
1387
1382
 
1388
1383
  //#endregion
1389
1384
  //#region src/views/formula-editor/help-function/HelpFunction.tsx
1390
- const Params = ({ className, title, titleKey, value }) => {
1391
- const localeService = useDependency(LocaleService);
1385
+ function Params({ className, title, value }) {
1392
1386
  return /* @__PURE__ */ jsxs("div", {
1393
1387
  className: "univer-my-2",
1394
1388
  children: [/* @__PURE__ */ jsx("div", {
1395
1389
  className: clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white", className),
1396
- children: titleKey ? localeService.t(titleKey) : title
1390
+ children: title
1397
1391
  }), /* @__PURE__ */ jsx("div", {
1398
1392
  className: "univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",
1399
1393
  children: value
1400
1394
  })]
1401
1395
  });
1402
- };
1403
- const Help = (props) => {
1396
+ }
1397
+ function Help(props) {
1404
1398
  const { prefix, value, active, onClick } = props;
1405
1399
  return /* @__PURE__ */ jsxs("div", { children: [
1406
1400
  /* @__PURE__ */ jsxs("span", { children: [prefix, "("] }),
@@ -1411,7 +1405,7 @@ const Help = (props) => {
1411
1405
  }), i === value.length - 1 ? "" : ","] }, item.name)),
1412
1406
  ")"
1413
1407
  ] });
1414
- };
1408
+ }
1415
1409
  function HelpFunction(props) {
1416
1410
  const { onParamsSwitch = noop, onClose: propColose = noop, isFocus, editor, formulaText } = props;
1417
1411
  const { functionInfo, paramIndex, reset } = useFormulaDescribe(isFocus, formulaText, editor);
@@ -1475,11 +1469,11 @@ function HelpFunction(props) {
1475
1469
  className: "univer-mt-3",
1476
1470
  children: [
1477
1471
  /* @__PURE__ */ jsx(Params, {
1478
- titleKey: "sheets-formula-ui.prompt.helpExample",
1472
+ title: localeService.t("sheets-formula-ui.prompt.helpExample"),
1479
1473
  value: `${functionInfo.functionName}(${functionInfo.functionParameter.map((item) => item.example).join(",")})`
1480
1474
  }),
1481
1475
  /* @__PURE__ */ jsx(Params, {
1482
- titleKey: "sheets-formula-ui.prompt.helpAbstract",
1476
+ title: localeService.t("sheets-formula-ui.prompt.helpAbstract"),
1483
1477
  value: functionInfo.description
1484
1478
  }),
1485
1479
  functionInfo && functionInfo.functionParameter && functionInfo.functionParameter.map((item, i) => /* @__PURE__ */ jsx(Params, {
@@ -1507,8 +1501,8 @@ function focusFormulaEditor(editorService, editor, offset) {
1507
1501
  endOffset: offset
1508
1502
  }]);
1509
1503
  else if (!selections.length) {
1510
- var _editor$getDocumentDa, _editor$getDocumentDa2;
1511
- 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";
1512
1506
  const offset = Math.max(body.length - 2, 0);
1513
1507
  editor.setSelectionRanges([{
1514
1508
  startOffset: offset,
@@ -1517,8 +1511,8 @@ function focusFormulaEditor(editorService, editor, offset) {
1517
1511
  } else editor.setSelectionRanges(selections);
1518
1512
  }
1519
1513
  function focusFormulaEditorElement(editor) {
1520
- var _editor$editorDOM$own, _editor$editorDOM;
1521
- 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()}`);
1522
1516
  editorElement === null || editorElement === void 0 || editorElement.focus({ preventScroll: true });
1523
1517
  }
1524
1518
  function shouldSkipFormulaEditorMouseUpFocus(_target) {
@@ -1652,9 +1646,8 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends BaseSe
1652
1646
  * @param {ISelectionWithCoord} selectionWithStyle
1653
1647
  */
1654
1648
  _addSelectionControlByModelData(selectionWithStyle) {
1655
- var _selectionWithStyle$s;
1656
1649
  const skeleton = this._skeleton;
1657
- const style = (_selectionWithStyle$s = selectionWithStyle.style) !== null && _selectionWithStyle$s !== void 0 ? _selectionWithStyle$s : genNormalSelectionStyle(this._themeService);
1650
+ const style = selectionWithStyle.style ?? genNormalSelectionStyle(this._themeService);
1658
1651
  const scene = this._scene;
1659
1652
  selectionWithStyle.style = style;
1660
1653
  return this.newSelectionControl(scene, skeleton, selectionWithStyle);
@@ -1886,18 +1879,17 @@ function getDefaultRefSelectionStyle(themeService) {
1886
1879
  //#endregion
1887
1880
  //#region src/views/formula-editor/hooks/use-formula-selection.ts
1888
1881
  function resolveFormulaSelectionDataStream(accssor, editor, editorId) {
1889
- var _editor$getDocumentDa, _documentModel$getBod, _documentModel$getBod2;
1882
+ var _editor$getDocumentDa, _documentModel$getBod;
1890
1883
  const editorDataStream = editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream;
1891
1884
  if (editorDataStream != null) return {
1892
1885
  dataStream: editorDataStream,
1893
1886
  offset: 0
1894
1887
  };
1895
1888
  const univerInstanceService = accssor.get(IUniverInstanceService);
1896
- const editorDocumentModel = editorId ? univerInstanceService.getUnit(editorId, UniverInstanceType.UNIVER_DOC) : void 0;
1897
- 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);
1898
1890
  if (!(documentModel === null || documentModel === void 0 ? void 0 : documentModel.getBody())) return;
1899
1891
  return {
1900
- 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) ?? "",
1901
1893
  offset: 0
1902
1894
  };
1903
1895
  }
@@ -1905,8 +1897,7 @@ function shouldSkipReferenceEditingByPointer(isDisabledByPointer, disableOnClick
1905
1897
  return isDisabledByPointer && !disableOnClick;
1906
1898
  }
1907
1899
  function resolveFormulaSelectionWorkbook(currentWorkbook, fallbackWorkbook) {
1908
- var _ref;
1909
- return (_ref = currentWorkbook !== null && currentWorkbook !== void 0 ? currentWorkbook : fallbackWorkbook) !== null && _ref !== void 0 ? _ref : void 0;
1900
+ return currentWorkbook ?? fallbackWorkbook ?? void 0;
1910
1901
  }
1911
1902
  function resolveFormulaSelectionCursorIndex(activeRange, dataStream) {
1912
1903
  const index = (activeRange === null || activeRange === void 0 ? void 0 : activeRange.collapsed) ? activeRange.startOffset : -1;
@@ -1955,16 +1946,16 @@ function useFormulaSelecting(opts) {
1955
1946
  innerSetIsSelecting(v);
1956
1947
  });
1957
1948
  const calculateSelectingType = useEvent(() => {
1958
- var _editor$getSelectionR, _editor$getSelectionR2, _config$dataStream, _getSelectionAfterLag, _lexerTreeBuilder$seq;
1949
+ var _editor$getSelectionR, _config$dataStream;
1959
1950
  const currentWorkbook = resolveFormulaSelectionWorkbook(univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET), workbook);
1960
1951
  if (!currentWorkbook) return;
1961
1952
  const currentSheet = currentWorkbook.getActiveSheet();
1962
- 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());
1963
1954
  const config = resolveFormulaSelectionDataStream(injector, editor, editorId);
1964
1955
  if (!config) return;
1965
1956
  const dataStream = config === null || config === void 0 || (_config$dataStream = config.dataStream) === null || _config$dataStream === void 0 ? void 0 : _config$dataStream.slice(0, -2);
1966
- const index = resolveFormulaSelectionCursorIndex((_getSelectionAfterLag = getSelectionAfterLaggingFormulaInput(dataStream, activeRange, lastInputContentRef.current)) !== null && _getSelectionAfterLag !== void 0 ? _getSelectionAfterLag : activeRange, dataStream);
1967
- 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) => {
1968
1959
  if (typeof node === "object") {
1969
1960
  if (node.nodeType === sequenceNodeType.REFERENCE) return {
1970
1961
  ...node,
@@ -2172,7 +2163,7 @@ function useSheetHighlight(unitId, subUnitId) {
2172
2163
  const ownerWorkbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
2173
2164
  const currentWorkbook = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
2174
2165
  const currentUnitId = currentWorkbook === null || currentWorkbook === void 0 ? void 0 : currentWorkbook.getUnitId();
2175
- 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;
2176
2167
  });
2177
2168
  const highlightSheet = useEvent((refSelections, editor, isEnd = false) => {
2178
2169
  var _currentWorkbook$getA;
@@ -2252,7 +2243,7 @@ function useDocHight(_leadingCharacter = "") {
2252
2243
  commandService.syncExecuteCommand(ReplaceTextRunsCommand.id, {
2253
2244
  unitId: editorId,
2254
2245
  body: createFormulaHighlightBody(highlightDataStream.slice(0, -2), highlightTextRuns),
2255
- textRanges: newSelections !== null && newSelections !== void 0 ? newSelections : selections
2246
+ textRanges: newSelections ?? selections
2256
2247
  });
2257
2248
  return refSelections;
2258
2249
  }
@@ -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.getRenderUnitById((_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.getRenderUnitById((_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);
@@ -3341,7 +3321,7 @@ function syncCounterpartFormulaEditorSelection(editorService, editorId, selectio
3341
3321
  (_editorService$getEdi = editorService.getEditor(syncEditorId)) === null || _editorService$getEdi === void 0 || _editorService$getEdi.setSelectionRanges(selections, false);
3342
3322
  }
3343
3323
  const FormulaEditor = forwardRef((props, ref) => {
3344
- var _document$getBody$dat2, _document$getBody2, _configService$getCon, _configService$getCon2;
3324
+ var _document$getBody2, _configService$getCon;
3345
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;
3346
3326
  const editorService = useDependency(IEditorService);
3347
3327
  const commandService = useDependency(ICommandService);
@@ -3358,15 +3338,15 @@ const FormulaEditor = forwardRef((props, ref) => {
3358
3338
  const [editor, setEditor] = useState();
3359
3339
  const [isFocus, setIsFocus] = useState(_isFocus);
3360
3340
  const formulaEditorContainerRef = useRef(null);
3361
- 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)}`), []);
3362
3342
  const isError = errorText !== void 0;
3363
3343
  const univerInstanceService = useDependency(IUniverInstanceService);
3364
3344
  const document = univerInstanceService.getUnit(editorId);
3365
3345
  const getFormulaToken = useFormulaToken();
3366
3346
  const formulaText = useObservable(document ? () => document.change$.pipe(map(() => {
3367
- var _document$getBody$dat, _document$getBody;
3368
- 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 : "");
3369
- })) : 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]);
3370
3350
  const formulaTextRef = useStateRef(formulaText);
3371
3351
  const formulaWithoutEqualSymbol = useMemo(() => getFormulaText(formulaText), [formulaText]);
3372
3352
  const sequenceNodes = useMemo(() => getFormulaToken(formulaWithoutEqualSymbol), [formulaWithoutEqualSymbol, getFormulaToken]);
@@ -3388,7 +3368,7 @@ const FormulaEditor = forwardRef((props, ref) => {
3388
3368
  const getRefSelections = useEvent(() => refSelectionsRef.current);
3389
3369
  const getRefSelectionCount = useEvent(() => getRefSelections().length);
3390
3370
  const selectingMode = isSelecting;
3391
- 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;
3392
3372
  useUpdateEffect(() => {
3393
3373
  onChange(formulaText);
3394
3374
  }, [formulaText, onChange]);
@@ -3397,9 +3377,9 @@ const FormulaEditor = forwardRef((props, ref) => {
3397
3377
  const subscription = editor.input$.subscribe(({ content, isComposing }) => {
3398
3378
  if (isComposing) return;
3399
3379
  queueMicrotask(() => {
3400
- var _editor$getSelectionR, _editor$getDocumentDa, _editor$getDocumentDa2;
3380
+ var _editor$getSelectionR, _editor$getDocumentDa;
3401
3381
  const selection = (_editor$getSelectionR = editor.getSelectionRanges()) === null || _editor$getSelectionR === void 0 ? void 0 : _editor$getSelectionR[0];
3402
- 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);
3403
3383
  if (!normalizedSelection) return;
3404
3384
  const selections = [normalizedSelection];
3405
3385
  editor.setSelectionRanges(selections, false);
@@ -3423,7 +3403,7 @@ const FormulaEditor = forwardRef((props, ref) => {
3423
3403
  const ranges = highlightDoc(editorRef.current, sequenceNodes, isNeedResetSelection, newSelections, formulaStr);
3424
3404
  refSelectionsRef.current = ranges;
3425
3405
  if (isEnd) {
3426
- 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());
3427
3407
  if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) {
3428
3408
  const refIndex = findRefSequenceIndex(sequenceNodes, findIndexFromSequenceNodes(sequenceNodes, currentDocSelections[0].startOffset - 1, false));
3429
3409
  if (refIndex >= 0) {
@@ -3447,8 +3427,7 @@ const FormulaEditor = forwardRef((props, ref) => {
3447
3427
  const focus = useFocus(editor);
3448
3428
  const resetSelection = useResetSelection(isFocus, unitId, subUnitId);
3449
3429
  useEffect(() => {
3450
- var _docSelectionRenderSe;
3451
- 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);
3452
3431
  }, [onFormulaSelectingChange, isSelecting]);
3453
3432
  useKeyboardEvent(isFocus, useMemo(() => createEditorUndoRedoKeyboardConfig({
3454
3433
  commandService,
@@ -3507,11 +3486,10 @@ const FormulaEditor = forwardRef((props, ref) => {
3507
3486
  };
3508
3487
  }, []);
3509
3488
  useEffect(() => {
3510
- var _ref, _resolveFormulaEmbedR;
3511
3489
  const formulaEditorContainer = formulaEditorContainerRef.current;
3512
3490
  if (!isFocus || !formulaEditorContainer || !injector.has(IFormulaEmbedRuntimeFocusCoordinator)) return;
3513
3491
  const focusCoordinator = injector.get(IFormulaEmbedRuntimeFocusCoordinator);
3514
- 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);
3515
3493
  if (!scope) return;
3516
3494
  const collection = new DisposableCollection();
3517
3495
  const interactionBoundaryService = injector.has(IFormulaEmbedInteractionBoundaryService) ? injector.get(IFormulaEmbedInteractionBoundaryService) : void 0;
@@ -4016,7 +3994,7 @@ function useRangesHighlight(editor, focusing, unitId, subUnitId) {
4016
3994
  if (last.current === text) return;
4017
3995
  last.current = text;
4018
3996
  const nodes = lexerTreeBuilder.sequenceNodesBuilder(text);
4019
- setSequenceNodes(nodes !== null && nodes !== void 0 ? nodes : []);
3997
+ setSequenceNodes(nodes ?? []);
4020
3998
  }, [
4021
3999
  change,
4022
4000
  editor,
@@ -4025,13 +4003,13 @@ function useRangesHighlight(editor, focusing, unitId, subUnitId) {
4025
4003
  useEffect(() => {
4026
4004
  if (!editor) return;
4027
4005
  if (!focusing) {
4028
- var _current$body$dataStr, _current$body;
4006
+ var _current$body;
4029
4007
  const current = editor.getDocumentData();
4030
4008
  editor.setDocumentData({
4031
4009
  ...current,
4032
4010
  body: {
4033
4011
  ...current.body,
4034
- 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) ?? "",
4035
4013
  textRuns: []
4036
4014
  }
4037
4015
  });
@@ -4265,7 +4243,7 @@ function stringifyRanges(ranges) {
4265
4243
  function RangeSelector(props) {
4266
4244
  const [editor, setEditor] = useState(null);
4267
4245
  const { onVerify, selectorRef, unitId, subUnitId, maxRangeCount, supportAcrossSheet, keepSheetReference, autoFocus, onChange, onRangeSelectorDialogVisibleChange, onClickOutside, onFocusChange, forceShowDialogWhenSelectionChanged, hideEditor, resetRange } = props;
4268
- const [focusing, setFocusing] = useState(autoFocus !== null && autoFocus !== void 0 ? autoFocus : false);
4246
+ const [focusing, setFocusing] = useState(autoFocus ?? false);
4269
4247
  const [popupVisible, setPopupVisible] = useState(false);
4270
4248
  const [rangeSelectorRanges, setRangeSelectorRanges] = useState([]);
4271
4249
  const localeService = useDependency(LocaleService);
@@ -4279,9 +4257,9 @@ function RangeSelector(props) {
4279
4257
  editorService.blur();
4280
4258
  });
4281
4259
  const handleOpenModal = useEvent(() => {
4282
- var _editor$getDocumentDa, _editor$getDocumentDa2;
4260
+ var _editor$getDocumentDa;
4283
4261
  blurEditor();
4284
- 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()) ?? ""));
4285
4263
  setPopupVisible(true);
4286
4264
  });
4287
4265
  useEffect(() => {
@@ -4305,8 +4283,8 @@ function RangeSelector(props) {
4305
4283
  setPopupVisible(false);
4306
4284
  },
4307
4285
  getValue: () => {
4308
- var _editor$getDocumentDa3, _editor$getDocumentDa4;
4309
- 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()) ?? "";
4310
4288
  }
4311
4289
  };
4312
4290
  }, [
@@ -4317,8 +4295,8 @@ function RangeSelector(props) {
4317
4295
  sequenceNodesRef
4318
4296
  ]);
4319
4297
  useEffect(() => {
4320
- var _editor$getDocumentDa5, _editor$getDocumentDa6;
4321
- 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()) ?? "");
4322
4300
  }, [sequenceNodes]);
4323
4301
  useEffect(() => {
4324
4302
  onRangeSelectorDialogVisibleChange === null || onRangeSelectorDialogVisibleChange === void 0 || onRangeSelectorDialogVisibleChange(popupVisible);
@@ -4336,6 +4314,7 @@ function RangeSelector(props) {
4336
4314
  return /* @__PURE__ */ jsxs(Fragment, { children: [!hideEditor ? /* @__PURE__ */ jsx(RichTextEditor, {
4337
4315
  isSingle: true,
4338
4316
  ...props,
4317
+ preserveHostFocus: true,
4339
4318
  onFocusChange: (focusing, newValue) => {
4340
4319
  setFocusing(focusing);
4341
4320
  onFocusChange === null || onFocusChange === void 0 || onFocusChange(focusing, newValue);
@@ -5275,13 +5254,12 @@ var GlobalRangeSelectorService = class {
5275
5254
  //#endregion
5276
5255
  //#region src/views/range-selector/Global.tsx
5277
5256
  const GlobalRangeSelector = () => {
5278
- var _current$unitId, _current$subUnitId;
5279
5257
  const current = useObservable(useDependency(GlobalRangeSelectorService).currentSelector$);
5280
5258
  const instance = useRef(null);
5281
5259
  useEffect(() => {
5282
5260
  if (current) {
5283
- var _instance$current, _current$initialValue;
5284
- (_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 ?? []);
5285
5263
  return () => {
5286
5264
  var _instance$current2;
5287
5265
  (_instance$current2 = instance.current) === null || _instance$current2 === void 0 || _instance$current2.hideDialog();
@@ -5289,13 +5267,12 @@ const GlobalRangeSelector = () => {
5289
5267
  }
5290
5268
  }, [current]);
5291
5269
  return /* @__PURE__ */ jsx(RangeSelector, {
5292
- unitId: (_current$unitId = current === null || current === void 0 ? void 0 : current.unitId) !== null && _current$unitId !== void 0 ? _current$unitId : "",
5293
- 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) ?? "",
5294
5272
  hideEditor: true,
5295
5273
  selectorRef: instance,
5296
5274
  onChange: (_, value) => {
5297
- var _value$split$map;
5298
- 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))) ?? []);
5299
5276
  }
5300
5277
  });
5301
5278
  };
@@ -5357,7 +5334,7 @@ _defineProperty(UniverSheetsFormulaUIPlugin, "packageName", name);
5357
5334
  _defineProperty(UniverSheetsFormulaUIPlugin, "version", version);
5358
5335
  _defineProperty(UniverSheetsFormulaUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
5359
5336
  UniverSheetsFormulaUIPlugin = __decorate([
5360
- DependentOn(UniverFormulaEnginePlugin, UniverRenderEnginePlugin, UniverSheetsPlugin, UniverUIPlugin, UniverSheetsFormulaPlugin, UniverSheetsUIPlugin),
5337
+ DependentOn(UniverFormulaEnginePlugin, UniverRenderEnginePlugin, UniverSheetsPlugin, UniverSheetsFormulaPlugin, UniverSheetsUIPlugin),
5361
5338
  __decorateParam(1, Inject(Injector)),
5362
5339
  __decorateParam(2, IRenderManagerService),
5363
5340
  __decorateParam(3, IConfigService),