@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/cjs/index.js CHANGED
@@ -9,12 +9,10 @@ let _univerjs_sheets = require("@univerjs/sheets");
9
9
  let _univerjs_sheets_formula = require("@univerjs/sheets-formula");
10
10
  let _univerjs_ui = require("@univerjs/ui");
11
11
  let _univerjs_docs = require("@univerjs/docs");
12
- let _univerjs_formula = require("@univerjs/formula");
13
12
  let _univerjs_icons = require("@univerjs/icons");
14
13
  let _univerjs_design = require("@univerjs/design");
15
14
  let react = require("react");
16
15
  let react_jsx_runtime = require("react/jsx-runtime");
17
- let _univerjs_formula_ui = require("@univerjs/formula-ui");
18
16
  let rxjs_operators = require("rxjs/operators");
19
17
 
20
18
  //#region src/commands/commands/formula-clipboard.command.ts
@@ -34,7 +32,7 @@ const SheetOnlyPasteFormulaCommand = {
34
32
  };
35
33
 
36
34
  //#endregion
37
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
35
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
38
36
  function _typeof(o) {
39
37
  "@babel/helpers - typeof";
40
38
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -45,7 +43,7 @@ function _typeof(o) {
45
43
  }
46
44
 
47
45
  //#endregion
48
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
46
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
49
47
  function toPrimitive(t, r) {
50
48
  if ("object" != _typeof(t) || !t) return t;
51
49
  var e = t[Symbol.toPrimitive];
@@ -58,14 +56,14 @@ function toPrimitive(t, r) {
58
56
  }
59
57
 
60
58
  //#endregion
61
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
59
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
62
60
  function toPropertyKey(t) {
63
61
  var i = toPrimitive(t, "string");
64
62
  return "symbol" == _typeof(i) ? i : i + "";
65
63
  }
66
64
 
67
65
  //#endregion
68
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
66
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
69
67
  function _defineProperty(e, r, t) {
70
68
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
71
69
  value: t,
@@ -76,7 +74,7 @@ function _defineProperty(e, r, t) {
76
74
  }
77
75
 
78
76
  //#endregion
79
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
77
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
80
78
  function __decorateParam(paramIndex, decorator) {
81
79
  return function(target, key) {
82
80
  decorator(target, key, paramIndex);
@@ -84,7 +82,7 @@ function __decorateParam(paramIndex, decorator) {
84
82
  }
85
83
 
86
84
  //#endregion
87
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
85
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
88
86
  function __decorate(decorators, target, key, desc) {
89
87
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
90
88
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -308,10 +306,9 @@ const InsertFunctionOperation = {
308
306
  let editColumn = 0;
309
307
  let editFormulaRangeString = "";
310
308
  if (currentSelections.length === 1 && (isSingleCell(currentSelections[0].range) || isMultiRowsColumnsRange(currentSelections[0].range) && rangeHasNoNumber(cellMatrix, currentSelections[0].range))) {
311
- var _primary$actualRow, _primary$actualColumn;
312
309
  const { range, primary } = currentSelections[0];
313
- const row = (_primary$actualRow = primary === null || primary === void 0 ? void 0 : primary.actualRow) !== null && _primary$actualRow !== void 0 ? _primary$actualRow : range.startRow;
314
- const column = (_primary$actualColumn = primary === null || primary === void 0 ? void 0 : primary.actualColumn) !== null && _primary$actualColumn !== void 0 ? _primary$actualColumn : range.startColumn;
310
+ const row = (primary === null || primary === void 0 ? void 0 : primary.actualRow) ?? range.startRow;
311
+ const column = (primary === null || primary === void 0 ? void 0 : primary.actualColumn) ?? range.startColumn;
315
312
  editRange = range;
316
313
  editRow = row;
317
314
  editColumn = column;
@@ -320,9 +317,8 @@ const InsertFunctionOperation = {
320
317
  } else currentSelections.some((selection) => {
321
318
  const { range, primary } = selection;
322
319
  if (rangeHasNoNumber(cellMatrix, range)) {
323
- var _primary$actualRow2, _primary$actualColumn2;
324
- const row = (_primary$actualRow2 = primary === null || primary === void 0 ? void 0 : primary.actualRow) !== null && _primary$actualRow2 !== void 0 ? _primary$actualRow2 : range.startRow;
325
- const column = (_primary$actualColumn2 = primary === null || primary === void 0 ? void 0 : primary.actualColumn) !== null && _primary$actualColumn2 !== void 0 ? _primary$actualColumn2 : range.startColumn;
320
+ const row = (primary === null || primary === void 0 ? void 0 : primary.actualRow) ?? range.startRow;
321
+ const column = (primary === null || primary === void 0 ? void 0 : primary.actualColumn) ?? range.startColumn;
326
322
  const refRange = findRefRange(cellMatrix, row, column);
327
323
  if (!refRange) {
328
324
  editRange = range;
@@ -330,7 +326,8 @@ const InsertFunctionOperation = {
330
326
  editColumn = column;
331
327
  return true;
332
328
  }
333
- const formulaString = `=${value}(${(0, _univerjs_engine_formula.serializeRange)(refRange)})`;
329
+ const rangeString = (0, _univerjs_engine_formula.serializeRange)(refRange);
330
+ const formulaString = `=${value}(${rangeString})`;
334
331
  list.push({
335
332
  range,
336
333
  primary: {
@@ -343,12 +340,13 @@ const InsertFunctionOperation = {
343
340
  const { startRow, startColumn, endRow, endColumn } = range;
344
341
  if (startRow === endRow) {
345
342
  const blankCellColumn = findBlankCellOfRow(cellMatrix, startRow, endColumn, worksheet.getColumnCount() - 1);
346
- const formulaString = `=${value}(${(0, _univerjs_engine_formula.serializeRange)({
343
+ const rangeString = (0, _univerjs_engine_formula.serializeRange)({
347
344
  startRow,
348
345
  endRow,
349
346
  startColumn,
350
347
  endColumn: blankCellColumn === endColumn ? endColumn - 1 : endColumn
351
- })})`;
348
+ });
349
+ const formulaString = `=${value}(${rangeString})`;
352
350
  listOfRangeHasNumber.push({
353
351
  range,
354
352
  primary: {
@@ -365,12 +363,13 @@ const InsertFunctionOperation = {
365
363
  }
366
364
  const newEndRow = maxBlankCellRow === endRow ? endRow - 1 : endRow;
367
365
  for (let c = startColumn; c <= endColumn; c++) {
368
- const formulaString = `=${value}(${(0, _univerjs_engine_formula.serializeRange)({
366
+ const rangeString = (0, _univerjs_engine_formula.serializeRange)({
369
367
  startRow,
370
368
  endRow: newEndRow,
371
369
  startColumn: c,
372
370
  endColumn: c
373
- })})`;
371
+ });
372
+ const formulaString = `=${value}(${rangeString})`;
374
373
  listOfRangeHasNumber.push({
375
374
  range,
376
375
  primary: {
@@ -666,7 +665,7 @@ const ReferenceAbsoluteOperation = {
666
665
  id: "formula-ui.operation.change-ref-to-absolute",
667
666
  type: _univerjs_core.CommandType.OPERATION,
668
667
  handler: async (accessor) => {
669
- var _focusEditor$getDocum, _focusEditor$getDocum2;
668
+ var _focusEditor$getDocum;
670
669
  const editorService = accessor.get(_univerjs_docs_ui.IEditorService);
671
670
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
672
671
  const lexerTreeBuilder = accessor.get(_univerjs_engine_formula.LexerTreeBuilder);
@@ -676,7 +675,7 @@ const ReferenceAbsoluteOperation = {
676
675
  if (editorId !== _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY && editorId !== _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) return false;
677
676
  const activeTextRange = docSelectionManagerService.getActiveTextRange();
678
677
  if (!activeTextRange) return false;
679
- const nextReferenceState = toggleReferenceAbsoluteAtCursor(lexerTreeBuilder, _univerjs_core.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);
678
+ const nextReferenceState = toggleReferenceAbsoluteAtCursor(lexerTreeBuilder, _univerjs_core.BuildTextUtils.transform.getPlainText(((_focusEditor$getDocum = focusEditor.getDocumentData().body) === null || _focusEditor$getDocum === void 0 ? void 0 : _focusEditor$getDocum.dataStream) ?? ""), activeTextRange.endOffset);
680
679
  if (!nextReferenceState) return false;
681
680
  focusEditor.replaceText(nextReferenceState.formulaText, [{
682
681
  startOffset: nextReferenceState.cursorOffset,
@@ -746,7 +745,7 @@ let FormulaReorderController = class FormulaReorderController extends _univerjs_
746
745
  const redos = [];
747
746
  const undos = [];
748
747
  const { unitId, subUnitId, range, order } = params;
749
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
748
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
750
749
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
751
750
  if (!worksheet) return {
752
751
  redos,
@@ -824,7 +823,7 @@ function InsertCommonFunctionMenuItemFactory(accessor) {
824
823
  value: name
825
824
  }));
826
825
  try {
827
- const descriptionService = accessor.get(_univerjs_formula.IDescriptionService);
826
+ const descriptionService = accessor.get(_univerjs_engine_formula.IDescriptionService);
828
827
  const filtered = commonFunctions.filter((name) => Boolean(descriptionService.getFunctionInfo(name)));
829
828
  if (filtered.length > 0) selections = filtered.map((name) => ({
830
829
  label: {
@@ -849,7 +848,7 @@ function createInsertFunctionCategoryMenuItemFactory(functionType, categoryKey,
849
848
  return function insertFunctionCategoryMenuItemFactory(accessor) {
850
849
  let selections = [];
851
850
  try {
852
- selections = accessor.get(_univerjs_formula.IDescriptionService).getSearchListByType(functionType).map(({ name }) => ({
851
+ selections = accessor.get(_univerjs_engine_formula.IDescriptionService).getSearchListByType(functionType).map(({ name }) => ({
853
852
  label: {
854
853
  name,
855
854
  selectable: false
@@ -995,7 +994,7 @@ const menuSchema = {
995
994
  //#endregion
996
995
  //#region package.json
997
996
  var name = "@univerjs/sheets-formula-ui";
998
- var version = "1.0.0-alpha.7";
997
+ var version = "1.0.0-beta.0";
999
998
 
1000
999
  //#endregion
1001
1000
  //#region src/config/config.ts
@@ -1049,8 +1048,7 @@ const FORMULA_EMBED_CHILD_UNIT_ID_ATTRIBUTE = "data-embed-child-unit-id";
1049
1048
  const IFormulaEmbedRuntimeFocusCoordinator = (0, _univerjs_core.createIdentifier)("sheets-formula-ui.embed-runtime-focus-coordinator");
1050
1049
  const IFormulaEmbedInteractionBoundaryService = (0, _univerjs_core.createIdentifier)("sheets-formula-ui.embed-interaction-boundary.service");
1051
1050
  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;
1051
+ const ownerDocument = options.ownerDocument ?? (typeof document === "undefined" ? void 0 : document);
1054
1052
  if (!ownerDocument) return (0, _univerjs_core.toDisposable)(() => {});
1055
1053
  const collection = new _univerjs_core.DisposableCollection();
1056
1054
  const view = ownerDocument.defaultView;
@@ -1105,8 +1103,7 @@ function registerFormulaEditorRuntimePortal(options) {
1105
1103
  return collection;
1106
1104
  }
1107
1105
  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}`);
1106
+ return ownerDocument.getElementById(`univer-doc-selection-container-${editorId}`) ?? ownerDocument.getElementById(`__editor_${editorId}`);
1110
1107
  }
1111
1108
  function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
1112
1109
  const collection = new _univerjs_core.DisposableCollection();
@@ -1122,14 +1119,13 @@ function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
1122
1119
  return collection;
1123
1120
  }
1124
1121
  function resolveFormulaEmbedRuntimeDomScope(root) {
1125
- var _scopeElement$getAttr, _scopeElement$getAttr2;
1126
1122
  const scopeElement = root === null || root === void 0 ? void 0 : root.closest(`[${FORMULA_EMBED_ID_ATTRIBUTE}]`);
1127
1123
  const embedId = scopeElement === null || scopeElement === void 0 ? void 0 : scopeElement.getAttribute(FORMULA_EMBED_ID_ATTRIBUTE);
1128
1124
  if (!scopeElement || !embedId) return;
1129
1125
  return {
1130
1126
  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
1127
+ hostUnitId: scopeElement.getAttribute("data-embed-host-unit-id") ?? void 0,
1128
+ childUnitId: scopeElement.getAttribute("data-embed-child-unit-id") ?? void 0
1133
1129
  };
1134
1130
  }
1135
1131
  function resolveActiveFormulaEmbedRuntimeDomScope(ownerDocument) {
@@ -1141,9 +1137,9 @@ function isEventTargetInSameFormulaEmbedInteractionBoundary(left, right) {
1141
1137
  return Boolean(leftOwner && leftOwner === resolveFormulaEmbedInteractionOwnerId(right));
1142
1138
  }
1143
1139
  function resolveFormulaEmbedInteractionOwnerId(target) {
1144
- var _target$closest$getAt, _target$closest;
1140
+ var _target$closest;
1145
1141
  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;
1142
+ 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
1143
  }
1148
1144
 
1149
1145
  //#endregion
@@ -1255,7 +1251,7 @@ function useEditorPosition(editorId, ready, deps) {
1255
1251
  univerInstanceService.unitAdded$,
1256
1252
  updatePosition,
1257
1253
  ready,
1258
- ...deps !== null && deps !== void 0 ? deps : []
1254
+ ...deps ?? []
1259
1255
  ]);
1260
1256
  useResizeScrollObserver(updatePosition);
1261
1257
  (0, react.useEffect)(() => {
@@ -1294,7 +1290,7 @@ const useStateRef = (value) => {
1294
1290
  //#region src/views/formula-editor/hooks/use-formula-describe.ts
1295
1291
  const useFormulaDescribe = (isNeed, formulaText, editor) => {
1296
1292
  const formulaPromptService = (0, _univerjs_ui.useDependency)(IFormulaPromptService);
1297
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_formula.IDescriptionService);
1293
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDescriptionService);
1298
1294
  const lexerTreeBuilder = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.LexerTreeBuilder);
1299
1295
  const [functionInfo, setFunctionInfo] = (0, react.useState)();
1300
1296
  const [paramIndex, setParamIndex] = (0, react.useState)(-1);
@@ -1309,7 +1305,7 @@ const useFormulaDescribe = (isNeed, formulaText, editor) => {
1309
1305
  };
1310
1306
  (0, react.useEffect)(() => {
1311
1307
  const nodes = lexerTreeBuilder.sequenceNodesBuilder(formulaText.slice(1));
1312
- formulaPromptService.setSequenceNodes(nodes !== null && nodes !== void 0 ? nodes : []);
1308
+ formulaPromptService.setSequenceNodes(nodes ?? []);
1313
1309
  }, [formulaText]);
1314
1310
  (0, react.useEffect)(() => {
1315
1311
  if (editor && isNeed) {
@@ -1322,14 +1318,16 @@ const useFormulaDescribe = (isNeed, formulaText, editor) => {
1322
1318
  const currentSequenceNode = formulaPromptService.getCurrentSequenceNodeByIndex(nodeIndex);
1323
1319
  const nextSequenceNode = formulaPromptService.getCurrentSequenceNodeByIndex(nodeIndex + 1);
1324
1320
  if (currentSequenceNode) if (typeof currentSequenceNode !== "string" && currentSequenceNode.nodeType === 3 && !descriptionService.hasDefinedNameDescription(currentSequenceNode.token.trim()) && nextSequenceNode === _univerjs_engine_formula.matchToken.OPEN_BRACKET) {
1325
- setFunctionInfo(descriptionService.getFunctionInfo(currentSequenceNode.token));
1321
+ const info = descriptionService.getFunctionInfo(currentSequenceNode.token);
1322
+ setFunctionInfo(info);
1326
1323
  setParamIndex(-1);
1327
1324
  return;
1328
1325
  } else {
1329
1326
  const res = lexerTreeBuilder.getFunctionAndParameter(`${formulaTextRef.current}A`, startOffset - 1);
1330
1327
  if (res) {
1331
1328
  const { functionName, paramIndex } = res;
1332
- setFunctionInfo(descriptionService.getFunctionInfo(functionName));
1329
+ const info = descriptionService.getFunctionInfo(functionName);
1330
+ setFunctionInfo(info);
1333
1331
  setParamIndex(paramIndex);
1334
1332
  return;
1335
1333
  }
@@ -1385,20 +1383,19 @@ const HelpHiddenTip = ({ onClick }) => {
1385
1383
 
1386
1384
  //#endregion
1387
1385
  //#region src/views/formula-editor/help-function/HelpFunction.tsx
1388
- const Params = ({ className, title, titleKey, value }) => {
1389
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1386
+ function Params({ className, title, value }) {
1390
1387
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1391
1388
  className: "univer-my-2",
1392
1389
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1393
1390
  className: (0, _univerjs_design.clsx)("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white", className),
1394
- children: titleKey ? localeService.t(titleKey) : title
1391
+ children: title
1395
1392
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1396
1393
  className: "univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",
1397
1394
  children: value
1398
1395
  })]
1399
1396
  });
1400
- };
1401
- const Help = (props) => {
1397
+ }
1398
+ function Help(props) {
1402
1399
  const { prefix, value, active, onClick } = props;
1403
1400
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
1404
1401
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [prefix, "("] }),
@@ -1409,7 +1406,7 @@ const Help = (props) => {
1409
1406
  }), i === value.length - 1 ? "" : ","] }, item.name)),
1410
1407
  ")"
1411
1408
  ] });
1412
- };
1409
+ }
1413
1410
  function HelpFunction(props) {
1414
1411
  const { onParamsSwitch = _univerjs_core.noop, onClose: propColose = _univerjs_core.noop, isFocus, editor, formulaText } = props;
1415
1412
  const { functionInfo, paramIndex, reset } = useFormulaDescribe(isFocus, formulaText, editor);
@@ -1473,11 +1470,11 @@ function HelpFunction(props) {
1473
1470
  className: "univer-mt-3",
1474
1471
  children: [
1475
1472
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Params, {
1476
- titleKey: "sheets-formula-ui.prompt.helpExample",
1473
+ title: localeService.t("sheets-formula-ui.prompt.helpExample"),
1477
1474
  value: `${functionInfo.functionName}(${functionInfo.functionParameter.map((item) => item.example).join(",")})`
1478
1475
  }),
1479
1476
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Params, {
1480
- titleKey: "sheets-formula-ui.prompt.helpAbstract",
1477
+ title: localeService.t("sheets-formula-ui.prompt.helpAbstract"),
1481
1478
  value: functionInfo.description
1482
1479
  }),
1483
1480
  functionInfo && functionInfo.functionParameter && functionInfo.functionParameter.map((item, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Params, {
@@ -1505,8 +1502,8 @@ function focusFormulaEditor(editorService, editor, offset) {
1505
1502
  endOffset: offset
1506
1503
  }]);
1507
1504
  else if (!selections.length) {
1508
- var _editor$getDocumentDa, _editor$getDocumentDa2;
1509
- 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";
1505
+ var _editor$getDocumentDa;
1506
+ const body = ((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "\r\n";
1510
1507
  const offset = Math.max(body.length - 2, 0);
1511
1508
  editor.setSelectionRanges([{
1512
1509
  startOffset: offset,
@@ -1515,8 +1512,8 @@ function focusFormulaEditor(editorService, editor, offset) {
1515
1512
  } else editor.setSelectionRanges(selections);
1516
1513
  }
1517
1514
  function focusFormulaEditorElement(editor) {
1518
- var _editor$editorDOM$own, _editor$editorDOM;
1519
- 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()}`);
1515
+ var _editor$editorDOM;
1516
+ const editorElement = (((_editor$editorDOM = editor.editorDOM) === null || _editor$editorDOM === void 0 ? void 0 : _editor$editorDOM.ownerDocument) ?? document).getElementById(`__editor_${editor.getEditorId()}`);
1520
1517
  editorElement === null || editorElement === void 0 || editorElement.focus({ preventScroll: true });
1521
1518
  }
1522
1519
  function shouldSkipFormulaEditorMouseUpFocus(_target) {
@@ -1650,9 +1647,8 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends _unive
1650
1647
  * @param {ISelectionWithCoord} selectionWithStyle
1651
1648
  */
1652
1649
  _addSelectionControlByModelData(selectionWithStyle) {
1653
- var _selectionWithStyle$s;
1654
1650
  const skeleton = this._skeleton;
1655
- const style = (_selectionWithStyle$s = selectionWithStyle.style) !== null && _selectionWithStyle$s !== void 0 ? _selectionWithStyle$s : (0, _univerjs_sheets_ui.genNormalSelectionStyle)(this._themeService);
1651
+ const style = selectionWithStyle.style ?? (0, _univerjs_sheets_ui.genNormalSelectionStyle)(this._themeService);
1656
1652
  const scene = this._scene;
1657
1653
  selectionWithStyle.style = style;
1658
1654
  return this.newSelectionControl(scene, skeleton, selectionWithStyle);
@@ -1884,18 +1880,17 @@ function getDefaultRefSelectionStyle(themeService) {
1884
1880
  //#endregion
1885
1881
  //#region src/views/formula-editor/hooks/use-formula-selection.ts
1886
1882
  function resolveFormulaSelectionDataStream(accssor, editor, editorId) {
1887
- var _editor$getDocumentDa, _documentModel$getBod, _documentModel$getBod2;
1883
+ var _editor$getDocumentDa, _documentModel$getBod;
1888
1884
  const editorDataStream = editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream;
1889
1885
  if (editorDataStream != null) return {
1890
1886
  dataStream: editorDataStream,
1891
1887
  offset: 0
1892
1888
  };
1893
1889
  const univerInstanceService = accssor.get(_univerjs_core.IUniverInstanceService);
1894
- const editorDocumentModel = editorId ? univerInstanceService.getUnit(editorId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : void 0;
1895
- const documentModel = editorDocumentModel !== null && editorDocumentModel !== void 0 ? editorDocumentModel : univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1890
+ const documentModel = (editorId ? univerInstanceService.getUnit(editorId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : void 0) ?? univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1896
1891
  if (!(documentModel === null || documentModel === void 0 ? void 0 : documentModel.getBody())) return;
1897
1892
  return {
1898
- dataStream: (_documentModel$getBod = (_documentModel$getBod2 = documentModel.getBody()) === null || _documentModel$getBod2 === void 0 ? void 0 : _documentModel$getBod2.dataStream) !== null && _documentModel$getBod !== void 0 ? _documentModel$getBod : "",
1893
+ dataStream: ((_documentModel$getBod = documentModel.getBody()) === null || _documentModel$getBod === void 0 ? void 0 : _documentModel$getBod.dataStream) ?? "",
1899
1894
  offset: 0
1900
1895
  };
1901
1896
  }
@@ -1903,8 +1898,7 @@ function shouldSkipReferenceEditingByPointer(isDisabledByPointer, disableOnClick
1903
1898
  return isDisabledByPointer && !disableOnClick;
1904
1899
  }
1905
1900
  function resolveFormulaSelectionWorkbook(currentWorkbook, fallbackWorkbook) {
1906
- var _ref;
1907
- return (_ref = currentWorkbook !== null && currentWorkbook !== void 0 ? currentWorkbook : fallbackWorkbook) !== null && _ref !== void 0 ? _ref : void 0;
1901
+ return currentWorkbook ?? fallbackWorkbook ?? void 0;
1908
1902
  }
1909
1903
  function resolveFormulaSelectionCursorIndex(activeRange, dataStream) {
1910
1904
  const index = (activeRange === null || activeRange === void 0 ? void 0 : activeRange.collapsed) ? activeRange.startOffset : -1;
@@ -1934,8 +1928,8 @@ function useFormulaSelecting(opts) {
1934
1928
  const { editor, editorId, isFocus, disableOnClick, unitId, subUnitId } = opts;
1935
1929
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
1936
1930
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1937
- const sheetRenderer = renderManagerService.getRenderById(unitId);
1938
- const renderer = renderManagerService.getRenderById(editorId);
1931
+ const sheetRenderer = renderManagerService.getRenderUnitById(unitId);
1932
+ const renderer = renderManagerService.getRenderUnitById(editorId);
1939
1933
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(_univerjs_docs_ui.DocSelectionRenderService);
1940
1934
  const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
1941
1935
  const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
@@ -1953,16 +1947,16 @@ function useFormulaSelecting(opts) {
1953
1947
  innerSetIsSelecting(v);
1954
1948
  });
1955
1949
  const calculateSelectingType = (0, _univerjs_ui.useEvent)(() => {
1956
- var _editor$getSelectionR, _editor$getSelectionR2, _config$dataStream, _getSelectionAfterLag, _lexerTreeBuilder$seq;
1950
+ var _editor$getSelectionR, _config$dataStream;
1957
1951
  const currentWorkbook = resolveFormulaSelectionWorkbook(univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET), workbook);
1958
1952
  if (!currentWorkbook) return;
1959
1953
  const currentSheet = currentWorkbook.getActiveSheet();
1960
- 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();
1954
+ 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());
1961
1955
  const config = resolveFormulaSelectionDataStream(injector, editor, editorId);
1962
1956
  if (!config) return;
1963
1957
  const dataStream = config === null || config === void 0 || (_config$dataStream = config.dataStream) === null || _config$dataStream === void 0 ? void 0 : _config$dataStream.slice(0, -2);
1964
- const index = resolveFormulaSelectionCursorIndex((_getSelectionAfterLag = getSelectionAfterLaggingFormulaInput(dataStream, activeRange, lastInputContentRef.current)) !== null && _getSelectionAfterLag !== void 0 ? _getSelectionAfterLag : activeRange, dataStream);
1965
- const nodes = ((_lexerTreeBuilder$seq = lexerTreeBuilder.sequenceNodesBuilder(dataStream)) !== null && _lexerTreeBuilder$seq !== void 0 ? _lexerTreeBuilder$seq : []).map((node) => {
1958
+ const index = resolveFormulaSelectionCursorIndex(getSelectionAfterLaggingFormulaInput(dataStream, activeRange, lastInputContentRef.current) ?? activeRange, dataStream);
1959
+ const nodes = (lexerTreeBuilder.sequenceNodesBuilder(dataStream) ?? []).map((node) => {
1966
1960
  if (typeof node === "object") {
1967
1961
  if (node.nodeType === _univerjs_engine_formula.sequenceNodeType.REFERENCE) return {
1968
1962
  ...node,
@@ -2164,19 +2158,19 @@ function useSheetHighlight(unitId, subUnitId) {
2164
2158
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
2165
2159
  const refSelectionsService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.IRefSelectionsService);
2166
2160
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2167
- const ownerRender = renderManagerService.getRenderById(unitId);
2161
+ const ownerRender = renderManagerService.getRenderUnitById(unitId);
2168
2162
  const ownerRefSelectionsRenderService = ownerRender === null || ownerRender === void 0 ? void 0 : ownerRender.with(RefSelectionsRenderService);
2169
2163
  const getHighlightWorkbook = (0, _univerjs_ui.useEvent)((refSelections) => {
2170
2164
  const ownerWorkbook = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
2171
2165
  const currentWorkbook = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
2172
2166
  const currentUnitId = currentWorkbook === null || currentWorkbook === void 0 ? void 0 : currentWorkbook.getUnitId();
2173
- return Boolean(currentUnitId) && refSelections.some((refSelection) => (0, _univerjs_engine_formula.deserializeRangeWithSheet)(refSelection.token).unitId === currentUnitId) ? currentWorkbook : ownerWorkbook !== null && ownerWorkbook !== void 0 ? ownerWorkbook : currentWorkbook;
2167
+ return Boolean(currentUnitId) && refSelections.some((refSelection) => (0, _univerjs_engine_formula.deserializeRangeWithSheet)(refSelection.token).unitId === currentUnitId) ? currentWorkbook : ownerWorkbook ?? currentWorkbook;
2174
2168
  });
2175
2169
  const highlightSheet = (0, _univerjs_ui.useEvent)((refSelections, editor, isEnd = false) => {
2176
2170
  var _currentWorkbook$getA;
2177
2171
  const currentWorkbook = getHighlightWorkbook(refSelections);
2178
2172
  if (!currentWorkbook) return;
2179
- const currentRender = renderManagerService.getRenderById(currentWorkbook.getUnitId());
2173
+ const currentRender = renderManagerService.getRenderUnitById(currentWorkbook.getUnitId());
2180
2174
  const refSelectionsRenderService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(RefSelectionsRenderService);
2181
2175
  const sheetSelectionRenderService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_sheets_ui.ISheetSelectionRenderService);
2182
2176
  const sheetSkeletonManagerService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_sheets_ui.SheetSkeletonManagerService);
@@ -2208,7 +2202,7 @@ function useSheetHighlight(unitId, subUnitId) {
2208
2202
  return highlightSheet;
2209
2203
  }
2210
2204
  function useDocHight(_leadingCharacter = "") {
2211
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_formula.IDescriptionService);
2205
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDescriptionService);
2212
2206
  const colorMap = useColor();
2213
2207
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2214
2208
  const leadingCharacterLength = (0, react.useMemo)(() => _leadingCharacter.length, [_leadingCharacter]);
@@ -2232,7 +2226,7 @@ function useDocHight(_leadingCharacter = "") {
2232
2226
  e.ed = e.ed + leadingCharacterLength;
2233
2227
  e.st = e.st + leadingCharacterLength;
2234
2228
  });
2235
- const highlightDataStream = getFormulaHighlightDataStream(_leadingCharacter, sequenceNodes, sourceText);
2229
+ const highlightDataStream = (0, _univerjs_engine_formula.getFormulaHighlightDataStream)(_leadingCharacter, sequenceNodes, sourceText);
2236
2230
  const highlightTextRuns = [{
2237
2231
  st: 0,
2238
2232
  ed: 1,
@@ -2250,7 +2244,7 @@ function useDocHight(_leadingCharacter = "") {
2250
2244
  commandService.syncExecuteCommand(_univerjs_docs_ui.ReplaceTextRunsCommand.id, {
2251
2245
  unitId: editorId,
2252
2246
  body: createFormulaHighlightBody(highlightDataStream.slice(0, -2), highlightTextRuns),
2253
- textRanges: newSelections !== null && newSelections !== void 0 ? newSelections : selections
2247
+ textRanges: newSelections ?? selections
2254
2248
  });
2255
2249
  return refSelections;
2256
2250
  }
@@ -2267,9 +2261,6 @@ function createFormulaHighlightBody(dataStream, textRuns) {
2267
2261
  textRuns
2268
2262
  };
2269
2263
  }
2270
- function getFormulaHighlightDataStream(leadingCharacter, sequenceNodes, sourceText) {
2271
- return (0, _univerjs_formula_ui.getFormulaHighlightDataStream)(leadingCharacter, sequenceNodes, sourceText);
2272
- }
2273
2264
  function useColor() {
2274
2265
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
2275
2266
  return (0, react.useMemo)(() => {
@@ -2295,7 +2286,7 @@ function useColor() {
2295
2286
  }, [themeService.getCurrentTheme()]);
2296
2287
  }
2297
2288
  function buildTextRuns(descriptionService, colorMap, sequenceNodes) {
2298
- return (0, _univerjs_formula_ui.buildFormulaTextRuns)(descriptionService, colorMap, sequenceNodes);
2289
+ return (0, _univerjs_engine_formula.buildFormulaTextRuns)(descriptionService, colorMap, sequenceNodes);
2299
2290
  }
2300
2291
 
2301
2292
  //#endregion
@@ -2305,10 +2296,9 @@ function shouldMoveFormulaSelectionFromCurrentSelection(selectingType, refSelect
2305
2296
  return selectingType === 3;
2306
2297
  }
2307
2298
  function isFormulaEditorInteractionOwner(focusEditorId, editorId, options) {
2308
- var _options$formulaBarEd, _options$normalEditor;
2309
2299
  if (focusEditorId === editorId) return true;
2310
2300
  if (!(options === null || options === void 0 ? void 0 : options.fxBarFocused)) return false;
2311
- return editorId === ((_options$formulaBarEd = options.formulaBarEditorId) !== null && _options$formulaBarEd !== void 0 ? _options$formulaBarEd : _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && focusEditorId === ((_options$normalEditor = options.normalEditorId) !== null && _options$normalEditor !== void 0 ? _options$normalEditor : _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
2301
+ return editorId === (options.formulaBarEditorId ?? _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && focusEditorId === (options.normalEditorId ?? _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
2312
2302
  }
2313
2303
  const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEditor, getRefSelectionCount) => {
2314
2304
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
@@ -2354,8 +2344,8 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2354
2344
  else if (keycode === _univerjs_ui.KeyCode.ARROW_LEFT) direction = _univerjs_core.Direction.LEFT;
2355
2345
  else if (keycode === _univerjs_ui.KeyCode.ARROW_RIGHT) direction = _univerjs_core.Direction.RIGHT;
2356
2346
  if (shouldMoveSelectionRef.current) {
2357
- var _getRefSelectionCount, _getRefSelectionCount2;
2358
- const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, (_getRefSelectionCount = (_getRefSelectionCount2 = getRefSelectionCountRef.current) === null || _getRefSelectionCount2 === void 0 ? void 0 : _getRefSelectionCount2.call(getRefSelectionCountRef)) !== null && _getRefSelectionCount !== void 0 ? _getRefSelectionCount : 0);
2347
+ var _getRefSelectionCount;
2348
+ const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, ((_getRefSelectionCount = getRefSelectionCountRef.current) === null || _getRefSelectionCount === void 0 ? void 0 : _getRefSelectionCount.call(getRefSelectionCountRef)) ?? 0);
2359
2349
  if (metaKey === _univerjs_ui.MetaKeys.CTRL_COMMAND) commandService.executeCommand(_univerjs_sheets_ui.MoveSelectionCommand.id, {
2360
2350
  direction,
2361
2351
  jumpOver: _univerjs_sheets_ui.JumpOver.moveGap,
@@ -2471,14 +2461,13 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2471
2461
  //#endregion
2472
2462
  //#region src/views/formula-editor/hooks/use-refactor-effect.ts
2473
2463
  const useRefactorEffect = (isNeed, selecting, unitId, editorId, disableContextMenu = true) => {
2474
- var _currentUnit$getUnitI;
2475
2464
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2476
2465
  const contextService = (0, _univerjs_ui.useDependency)(_univerjs_core.IContextService);
2477
2466
  const contextMenuService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IContextMenuService);
2478
2467
  const refSelectionsService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.IRefSelectionsService);
2479
2468
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
2480
2469
  const currentUnit = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), [univerInstanceService]));
2481
- const render = renderManagerService.getRenderById((_currentUnit$getUnitI = currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== null && _currentUnit$getUnitI !== void 0 ? _currentUnit$getUnitI : "");
2470
+ const render = renderManagerService.getRenderUnitById((currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) ?? "");
2482
2471
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
2483
2472
  (0, react.useLayoutEffect)(() => {
2484
2473
  if (isNeed) {
@@ -2567,11 +2556,11 @@ const unitRangesToText = (ranges, isNeedSheetName = false, originSheetName = "",
2567
2556
  //#endregion
2568
2557
  //#region src/views/formula-editor/hooks/use-sheet-selection-change.ts
2569
2558
  const prepareSelectionChangeContext = (opts) => {
2570
- var _editor$getDocumentDa, _editor$getDocumentDa2, _lexerTreeBuilder$seq;
2559
+ var _editor$getDocumentDa;
2571
2560
  const { editor, lexerTreeBuilder } = opts;
2572
2561
  const currentDocSelections = editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges();
2573
- 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);
2574
- const sequenceNodes = (_lexerTreeBuilder$seq = lexerTreeBuilder.sequenceNodesBuilder(dataStream.slice(1))) !== null && _lexerTreeBuilder$seq !== void 0 ? _lexerTreeBuilder$seq : [];
2562
+ 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);
2563
+ const sequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(dataStream.slice(1)) ?? [];
2575
2564
  let offset;
2576
2565
  if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) offset = currentDocSelections[0].startOffset - 1;
2577
2566
  else if (dataStream.startsWith("=")) offset = Math.max(dataStream.length - 1, 0);
@@ -2606,14 +2595,13 @@ function getLastFormulaSelection(selections) {
2606
2595
  return selections[selections.length - 1];
2607
2596
  }
2608
2597
  function getFormulaSelectionIdentityKey(selection) {
2609
- var _ref, _item$rangeWithCoord, _range$startRow, _range$endRow, _range$startColumn, _range$endColumn;
2610
2598
  const item = selection;
2611
- const range = (_ref = (_item$rangeWithCoord = item.rangeWithCoord) !== null && _item$rangeWithCoord !== void 0 ? _item$rangeWithCoord : item.range) !== null && _ref !== void 0 ? _ref : item;
2599
+ const range = item.rangeWithCoord ?? item.range ?? item;
2612
2600
  return [
2613
- (_range$startRow = range.startRow) !== null && _range$startRow !== void 0 ? _range$startRow : "",
2614
- (_range$endRow = range.endRow) !== null && _range$endRow !== void 0 ? _range$endRow : "",
2615
- (_range$startColumn = range.startColumn) !== null && _range$startColumn !== void 0 ? _range$startColumn : "",
2616
- (_range$endColumn = range.endColumn) !== null && _range$endColumn !== void 0 ? _range$endColumn : ""
2601
+ range.startRow ?? "",
2602
+ range.endRow ?? "",
2603
+ range.startColumn ?? "",
2604
+ range.endColumn ?? ""
2617
2605
  ].join(":");
2618
2606
  }
2619
2607
  function isSameFormulaSelection(first, second) {
@@ -2648,10 +2636,9 @@ function createSelectionChangeDuplicateEndGuard() {
2648
2636
  };
2649
2637
  }
2650
2638
  function createSelectionChangeHandler(opts) {
2651
- var _opts$duplicateEndGua;
2652
2639
  let prevSelectionsCount = opts.initialSelectionsCount;
2653
2640
  let pendingCtrlAddCount = 0;
2654
- const duplicateEndGuard = (_opts$duplicateEndGua = opts.duplicateEndGuard) !== null && _opts$duplicateEndGua !== void 0 ? _opts$duplicateEndGua : createSelectionChangeDuplicateEndGuard();
2641
+ const duplicateEndGuard = opts.duplicateEndGuard ?? createSelectionChangeDuplicateEndGuard();
2655
2642
  return (selections, isEnd, options) => {
2656
2643
  if (options === null || options === void 0 ? void 0 : options.initial) return;
2657
2644
  if (selections.length === 0) return;
@@ -2697,7 +2684,6 @@ function getInitialFormulaReferenceSelectionCount(renderSelectionCount, formulaR
2697
2684
  return Math.max(renderSelectionCount, formulaReferenceCount);
2698
2685
  }
2699
2686
  const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUnitId, getRefSelections, isSupportAcrossSheet, listenSelectionSet, editor, handleRangeChange = _univerjs_core.noop) => {
2700
- var _activeWorkbook$getUn;
2701
2687
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2702
2688
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
2703
2689
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
@@ -2708,8 +2694,8 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2708
2694
  const lexerTreeBuilder = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.LexerTreeBuilder);
2709
2695
  const workbook = univerInstanceService.getUnit(unitId);
2710
2696
  const getSheetNameById = (0, _univerjs_ui.useEvent)((unitId, sheetId) => {
2711
- var _univerInstanceServic, _univerInstanceServic2;
2712
- 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 : "";
2697
+ var _univerInstanceServic;
2698
+ return ((_univerInstanceServic = univerInstanceService.getUnit(unitId)) === null || _univerInstanceServic === void 0 || (_univerInstanceServic = _univerInstanceServic.getSheetBySheetId(sheetId)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getName()) ?? "";
2713
2699
  });
2714
2700
  const sheetName = (0, react.useMemo)(() => getSheetNameById(unitId, subUnitId), [
2715
2701
  getSheetNameById,
@@ -2722,7 +2708,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2722
2708
  sheetName
2723
2709
  });
2724
2710
  const activeWorkbook = resolveFormulaSelectionWorkbook((0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), [univerInstanceService])), workbook);
2725
- const render = renderManagerService.getRenderById((_activeWorkbook$getUn = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== null && _activeWorkbook$getUn !== void 0 ? _activeWorkbook$getUn : unitId);
2711
+ const render = renderManagerService.getRenderUnitById((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) ?? unitId);
2726
2712
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
2727
2713
  const sheetSkeletonManagerService = render === null || render === void 0 ? void 0 : render.with(_univerjs_sheets_ui.SheetSkeletonManagerService);
2728
2714
  const refSelectionsService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.IRefSelectionsService);
@@ -2735,22 +2721,21 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2735
2721
  });
2736
2722
  if (!ctx) return;
2737
2723
  const { nodeIndex, updatingRefIndex, formulaText, sequenceNodes, offset } = ctx;
2738
- if (isSelectingRef.current === 1 || (0, _univerjs_formula_ui.isFormulaReferenceAddingContext)(sequenceNodes, offset) || (0, _univerjs_formula_ui.isFormulaReferenceAddingTextContext)(formulaText, offset)) if (offset !== 0) {
2739
- var _range$sheetId, _range$unitId, _range$unitId2;
2724
+ if (isSelectingRef.current === 1 || (0, _univerjs_engine_formula.isFormulaReferenceAddingContext)(sequenceNodes, offset) || (0, _univerjs_engine_formula.isFormulaReferenceAddingTextContext)(formulaText, offset)) if (offset !== 0) {
2740
2725
  if (nodeIndex === -1 && sequenceNodes.length) return;
2741
2726
  const range = getLastFormulaSelection(selections);
2742
2727
  if (!range) return;
2743
2728
  const lastNodes = sequenceNodes.splice(nodeIndex + 1);
2744
- const rangeSheetId = (_range$sheetId = range.sheetId) !== null && _range$sheetId !== void 0 ? _range$sheetId : subUnitId;
2729
+ const rangeSheetId = range.sheetId ?? subUnitId;
2745
2730
  const unitRangeName = {
2746
2731
  range,
2747
- unitId: (_range$unitId = range.unitId) !== null && _range$unitId !== void 0 ? _range$unitId : activeWorkbook.getUnitId(),
2748
- sheetName: getSheetNameById((_range$unitId2 = range.unitId) !== null && _range$unitId2 !== void 0 ? _range$unitId2 : activeWorkbook.getUnitId(), rangeSheetId)
2732
+ unitId: range.unitId ?? activeWorkbook.getUnitId(),
2733
+ sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
2749
2734
  };
2750
2735
  const isAcrossSheet = rangeSheetId !== subUnitId;
2751
2736
  const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
2752
2737
  const refRanges = unitRangesToText([unitRangeName], isSupportAcrossSheet && (isAcrossSheet || isAcrossWorkbook), sheetName, isAcrossWorkbook);
2753
- if ((0, _univerjs_formula_ui.isFormulaReferenceAddingTextContext)(formulaText, offset)) {
2738
+ if ((0, _univerjs_engine_formula.isFormulaReferenceAddingTextContext)(formulaText, offset)) {
2754
2739
  handleRangeChange(insertFormulaReferenceText(formulaText, refRanges[0], offset), offset + refRanges[0].length, isEnd);
2755
2740
  return;
2756
2741
  }
@@ -2760,14 +2745,13 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2760
2745
  });
2761
2746
  handleRangeChange(sequenceNodeToText([...sequenceNodes, ...lastNodes]), getOffsetFromSequenceNodes(sequenceNodes), isEnd);
2762
2747
  } else {
2763
- var _range$sheetId2, _range$unitId3, _range$unitId4;
2764
2748
  const range = getLastFormulaSelection(selections);
2765
2749
  if (!range) return;
2766
- const rangeSheetId = (_range$sheetId2 = range.sheetId) !== null && _range$sheetId2 !== void 0 ? _range$sheetId2 : subUnitId;
2750
+ const rangeSheetId = range.sheetId ?? subUnitId;
2767
2751
  const unitRangeName = {
2768
2752
  range,
2769
- unitId: (_range$unitId3 = range.unitId) !== null && _range$unitId3 !== void 0 ? _range$unitId3 : activeWorkbook.getUnitId(),
2770
- sheetName: getSheetNameById((_range$unitId4 = range.unitId) !== null && _range$unitId4 !== void 0 ? _range$unitId4 : activeWorkbook.getUnitId(), rangeSheetId)
2753
+ unitId: range.unitId ?? activeWorkbook.getUnitId(),
2754
+ sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
2771
2755
  };
2772
2756
  const isAcrossSheet = rangeSheetId !== subUnitId;
2773
2757
  const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
@@ -2784,22 +2768,19 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2784
2768
  const node = sequenceNodes[nodeIndex];
2785
2769
  if (typeof node === "object" && node.nodeType === _univerjs_engine_formula.sequenceNodeType.REFERENCE) {
2786
2770
  const oldToken = node.token;
2787
- if ((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId) {
2788
- var _activeWorkbook$getUn2;
2789
- node.token = (0, _univerjs_engine_formula.serializeRangeWithSpreadsheet)((_activeWorkbook$getUn2 = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== null && _activeWorkbook$getUn2 !== void 0 ? _activeWorkbook$getUn2 : "", sheetName, last);
2790
- } else node.token = sheetName === (activeSheet === null || activeSheet === void 0 ? void 0 : activeSheet.getName()) ? (0, _univerjs_engine_formula.serializeRange)(last) : (0, _univerjs_engine_formula.serializeRangeWithSheet)(activeSheet.getName(), last);
2771
+ if ((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId) node.token = (0, _univerjs_engine_formula.serializeRangeWithSpreadsheet)((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) ?? "", sheetName, last);
2772
+ else node.token = sheetName === (activeSheet === null || activeSheet === void 0 ? void 0 : activeSheet.getName()) ? (0, _univerjs_engine_formula.serializeRange)(last) : (0, _univerjs_engine_formula.serializeRangeWithSheet)(activeSheet.getName(), last);
2791
2773
  const newOffset = offset + (node.token.length - oldToken.length);
2792
2774
  handleRangeChange((0, _univerjs_engine_formula.generateStringWithSequence)(sequenceNodes), newOffset, isEnd);
2793
2775
  }
2794
2776
  } else {
2795
2777
  const { orderedSelections, insertedSelection } = getSelectionsForFormulaRefUpdate(selections, updatingRefIndex, isCtrlAddMode);
2796
2778
  const getRefRangeText = (range) => {
2797
- var _range$sheetId3, _range$unitId5, _range$unitId6;
2798
- const rangeSheetId = (_range$sheetId3 = range.sheetId) !== null && _range$sheetId3 !== void 0 ? _range$sheetId3 : subUnitId;
2779
+ const rangeSheetId = range.sheetId ?? subUnitId;
2799
2780
  const unitRangeName = {
2800
2781
  range,
2801
- unitId: (_range$unitId5 = range.unitId) !== null && _range$unitId5 !== void 0 ? _range$unitId5 : activeWorkbook.getUnitId(),
2802
- sheetName: getSheetNameById((_range$unitId6 = range.unitId) !== null && _range$unitId6 !== void 0 ? _range$unitId6 : activeWorkbook.getUnitId(), rangeSheetId)
2782
+ unitId: range.unitId ?? activeWorkbook.getUnitId(),
2783
+ sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
2803
2784
  };
2804
2785
  const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
2805
2786
  return unitRangesToText([unitRangeName], isSupportAcrossSheet && (rangeSheetId !== subUnitId || isAcrossWorkbook), sheetName, isAcrossWorkbook)[0];
@@ -2927,7 +2908,6 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2927
2908
  if (params.selections.length) {
2928
2909
  const last = params.selections[params.selections.length - 1];
2929
2910
  if (last) {
2930
- var _refSelectionsRenderS;
2931
2911
  const { range, primary } = last;
2932
2912
  if (((primary === null || primary === void 0 ? void 0 : primary.isMergedMainCell) || (primary === null || primary === void 0 ? void 0 : primary.isMerged)) && _univerjs_core.Rectangle.contains(primary, range)) {
2933
2913
  range.startRow = primary.startRow;
@@ -2941,8 +2921,8 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2941
2921
  editor,
2942
2922
  lexerTreeBuilder
2943
2923
  });
2944
- const isAdd = isSelectingRef.current === 1 || Boolean(ctx && ((0, _univerjs_formula_ui.isFormulaReferenceAddingContext)(ctx.sequenceNodes, ctx.offset) || (0, _univerjs_formula_ui.isFormulaReferenceAddingTextContext)(ctx.formulaText, ctx.offset)));
2945
- const selections = ((_refSelectionsRenderS = refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.getSelectionDataWithStyle()) !== null && _refSelectionsRenderS !== void 0 ? _refSelectionsRenderS : []).map((i) => i.rangeWithCoord);
2924
+ const isAdd = isSelectingRef.current === 1 || Boolean(ctx && ((0, _univerjs_engine_formula.isFormulaReferenceAddingContext)(ctx.sequenceNodes, ctx.offset) || (0, _univerjs_engine_formula.isFormulaReferenceAddingTextContext)(ctx.formulaText, ctx.offset)));
2925
+ const selections = ((refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.getSelectionDataWithStyle()) ?? []).map((i) => i.rangeWithCoord);
2946
2926
  if (isAdd) {
2947
2927
  if (selections.length > 0 && isSameFormulaSelection(selections[selections.length - 1], range)) return;
2948
2928
  selections.push(range);
@@ -3023,7 +3003,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
3023
3003
  const useSwitchSheet = (isNeed, unitId, isSupportAcrossSheet, isFocusSet, onBlur, refresh) => {
3024
3004
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
3025
3005
  const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
3026
- const render = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderById(unitId);
3006
+ const render = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(unitId);
3027
3007
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
3028
3008
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
3029
3009
  (0, react.useEffect)(() => {
@@ -3087,10 +3067,10 @@ const useVerify = (isNeed, onVerify, formulaText) => {
3087
3067
  //#endregion
3088
3068
  //#region src/views/formula-editor/hooks/use-formula-search.ts
3089
3069
  function getFormulaReplaceResult(nodes, index, formulaName, functionType) {
3090
- return (0, _univerjs_formula_ui.getFormulaReplaceResult)(nodes, index, formulaName, functionType);
3070
+ return (0, _univerjs_engine_formula.getFormulaReplaceResult)(nodes, index, formulaName, functionType);
3091
3071
  }
3092
3072
  const useFormulaSearch = (isNeed, nodes = [], editor) => {
3093
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_formula.IDescriptionService);
3073
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDescriptionService);
3094
3074
  const [searchList, setSearchList] = (0, react.useState)([]);
3095
3075
  const [searchText, setSearchText] = (0, react.useState)("");
3096
3076
  const indexRef = (0, react.useRef)(-1);
@@ -3114,7 +3094,8 @@ const useFormulaSearch = (isNeed, nodes = [], editor) => {
3114
3094
  if (currentNode && typeof currentNode !== "string" && currentNode.nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION) {
3115
3095
  indexRef.current = currentNodeIndex;
3116
3096
  const token = currentNode.token;
3117
- setSearchList((0, _univerjs_formula_ui.searchFormulaFunctions)(descriptionService, token));
3097
+ const list = (0, _univerjs_engine_formula.searchFormulaFunctions)(descriptionService, token);
3098
+ setSearchList(list);
3118
3099
  setSearchText(token);
3119
3100
  return;
3120
3101
  }
@@ -3341,7 +3322,7 @@ function syncCounterpartFormulaEditorSelection(editorService, editorId, selectio
3341
3322
  (_editorService$getEdi = editorService.getEditor(syncEditorId)) === null || _editorService$getEdi === void 0 || _editorService$getEdi.setSelectionRanges(selections, false);
3342
3323
  }
3343
3324
  const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3344
- var _document$getBody$dat2, _document$getBody2, _configService$getCon, _configService$getCon2;
3325
+ var _document$getBody2, _configService$getCon;
3345
3326
  const { errorText, initValue, unitId, subUnitId, isFocus: _isFocus = true, isSupportAcrossSheet = false, onFocus = _univerjs_core.noop, onBlur = _univerjs_core.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
3327
  const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
3347
3328
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
@@ -3358,15 +3339,15 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3358
3339
  const [editor, setEditor] = (0, react.useState)();
3359
3340
  const [isFocus, setIsFocus] = (0, react.useState)(_isFocus);
3360
3341
  const formulaEditorContainerRef = (0, react.useRef)(null);
3361
- const editorId = (0, react.useMemo)(() => propEditorId !== null && propEditorId !== void 0 ? propEditorId : (0, _univerjs_core.createInternalEditorID)(`${_univerjs_sheets_ui.EMBEDDING_FORMULA_EDITOR}-${(0, _univerjs_core.generateRandomId)(4)}`), []);
3342
+ const editorId = (0, react.useMemo)(() => propEditorId ?? (0, _univerjs_core.createInternalEditorID)(`${_univerjs_sheets_ui.EMBEDDING_FORMULA_EDITOR}-${(0, _univerjs_core.generateRandomId)(4)}`), []);
3362
3343
  const isError = errorText !== void 0;
3363
3344
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
3364
3345
  const document = univerInstanceService.getUnit(editorId);
3365
3346
  const getFormulaToken = useFormulaToken();
3366
3347
  const formulaText = (0, _univerjs_ui.useObservable)(document ? () => document.change$.pipe((0, rxjs.map)(() => {
3367
- var _document$getBody$dat, _document$getBody;
3368
- return _univerjs_core.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, _univerjs_core.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]);
3348
+ var _document$getBody;
3349
+ return _univerjs_core.BuildTextUtils.transform.getPlainText(((_document$getBody = document.getBody()) === null || _document$getBody === void 0 ? void 0 : _document$getBody.dataStream) ?? "");
3350
+ })) : null, _univerjs_core.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
3351
  const formulaTextRef = useStateRef(formulaText);
3371
3352
  const formulaWithoutEqualSymbol = (0, react.useMemo)(() => getFormulaText(formulaText), [formulaText]);
3372
3353
  const sequenceNodes = (0, react.useMemo)(() => getFormulaToken(formulaWithoutEqualSymbol), [formulaWithoutEqualSymbol, getFormulaToken]);
@@ -3379,7 +3360,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3379
3360
  disableOnClick: disableSelectionOnClick
3380
3361
  });
3381
3362
  const highTextRef = (0, react.useRef)("");
3382
- const renderer = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderById(editorId);
3363
+ const renderer = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(editorId);
3383
3364
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(_univerjs_docs_ui.DocSelectionRenderService);
3384
3365
  const isFocusing = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing;
3385
3366
  const currentDoc = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC), [univerInstanceService]));
@@ -3388,7 +3369,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3388
3369
  const getRefSelections = (0, _univerjs_ui.useEvent)(() => refSelectionsRef.current);
3389
3370
  const getRefSelectionCount = (0, _univerjs_ui.useEvent)(() => getRefSelections().length);
3390
3371
  const selectingMode = isSelecting;
3391
- const functionScreenTips = (_configService$getCon = (_configService$getCon2 = (0, _univerjs_ui.useDependency)(_univerjs_core.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;
3372
+ const functionScreenTips = ((_configService$getCon = (0, _univerjs_ui.useDependency)(_univerjs_core.IConfigService).getConfig("sheets-formula-ui.base.config")) === null || _configService$getCon === void 0 ? void 0 : _configService$getCon.functionScreenTips) ?? true;
3392
3373
  (0, _univerjs_ui.useUpdateEffect)(() => {
3393
3374
  onChange(formulaText);
3394
3375
  }, [formulaText, onChange]);
@@ -3397,9 +3378,9 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3397
3378
  const subscription = editor.input$.subscribe(({ content, isComposing }) => {
3398
3379
  if (isComposing) return;
3399
3380
  queueMicrotask(() => {
3400
- var _editor$getSelectionR, _editor$getDocumentDa, _editor$getDocumentDa2;
3381
+ var _editor$getSelectionR, _editor$getDocumentDa;
3401
3382
  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);
3383
+ const normalizedSelection = getSelectionAfterLaggingFormulaInput(((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "", selection, content);
3403
3384
  if (!normalizedSelection) return;
3404
3385
  const selections = [normalizedSelection];
3405
3386
  editor.setSelectionRanges(selections, false);
@@ -3423,7 +3404,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3423
3404
  const ranges = highlightDoc(editorRef.current, sequenceNodes, isNeedResetSelection, newSelections, formulaStr);
3424
3405
  refSelectionsRef.current = ranges;
3425
3406
  if (isEnd) {
3426
- const currentDocSelections = newSelections !== null && newSelections !== void 0 ? newSelections : editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges();
3407
+ const currentDocSelections = newSelections ?? (editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges());
3427
3408
  if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) {
3428
3409
  const refIndex = findRefSequenceIndex(sequenceNodes, findIndexFromSequenceNodes(sequenceNodes, currentDocSelections[0].startOffset - 1, false));
3429
3410
  if (refIndex >= 0) {
@@ -3447,8 +3428,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3447
3428
  const focus = useFocus(editor);
3448
3429
  const resetSelection = useResetSelection(isFocus, unitId, subUnitId);
3449
3430
  (0, react.useEffect)(() => {
3450
- var _docSelectionRenderSe;
3451
- onFormulaSelectingChange(isSelecting, (_docSelectionRenderSe = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : true);
3431
+ onFormulaSelectingChange(isSelecting, (docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) ?? true);
3452
3432
  }, [onFormulaSelectingChange, isSelecting]);
3453
3433
  (0, _univerjs_docs_ui.useKeyboardEvent)(isFocus, (0, react.useMemo)(() => (0, _univerjs_docs_ui.createEditorUndoRedoKeyboardConfig)({
3454
3434
  commandService,
@@ -3507,11 +3487,10 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3507
3487
  };
3508
3488
  }, []);
3509
3489
  (0, react.useEffect)(() => {
3510
- var _ref, _resolveFormulaEmbedR;
3511
3490
  const formulaEditorContainer = formulaEditorContainerRef.current;
3512
3491
  if (!isFocus || !formulaEditorContainer || !injector.has(IFormulaEmbedRuntimeFocusCoordinator)) return;
3513
3492
  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);
3493
+ const scope = resolveFormulaEmbedRuntimeDomScope(formulaEditorContainer) ?? focusCoordinator.resolveRuntimeScopeByChildUnitId(editorId) ?? resolveActiveFormulaEmbedRuntimeDomScope(formulaEditorContainer.ownerDocument);
3515
3494
  if (!scope) return;
3516
3495
  const collection = new _univerjs_core.DisposableCollection();
3517
3496
  const interactionBoundaryService = injector.has(IFormulaEmbedInteractionBoundaryService) ? injector.get(IFormulaEmbedInteractionBoundaryService) : void 0;
@@ -3761,7 +3740,7 @@ function SelectFunction(props) {
3761
3740
  const [typeSelected, setTypeSelected] = (0, react.useState)(allTypeValue);
3762
3741
  const [nameSelected, setNameSelected] = (0, react.useState)(0);
3763
3742
  const [functionInfo, setFunctionInfo] = (0, react.useState)(null);
3764
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_formula.IDescriptionService);
3743
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDescriptionService);
3765
3744
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
3766
3745
  const sidebarOptions = (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(_univerjs_ui.ISidebarService).sidebarOptions$);
3767
3746
  const options = getFunctionTypeValues(localeService, Boolean(customFunction)).filter((option) => descriptionService.getSearchListByType(Number(option.value)).length > 0);
@@ -3817,11 +3796,13 @@ function SelectFunction(props) {
3817
3796
  };
3818
3797
  function handleSelectChange(value) {
3819
3798
  setTypeSelected(value);
3820
- setSelectList(descriptionService.getSearchListByType(+value));
3799
+ const selectList = descriptionService.getSearchListByType(+value);
3800
+ setSelectList(selectList);
3821
3801
  }
3822
3802
  function handleSearchInputChange(value) {
3823
3803
  setSearchText(value);
3824
- setSelectList(descriptionService.getSearchListByName(value));
3804
+ const selectList = descriptionService.getSearchListByName(value);
3805
+ setSelectList(selectList);
3825
3806
  }
3826
3807
  function handleSelectListKeyDown(e) {
3827
3808
  e.stopPropagation();
@@ -4014,7 +3995,7 @@ function useRangesHighlight(editor, focusing, unitId, subUnitId) {
4014
3995
  if (last.current === text) return;
4015
3996
  last.current = text;
4016
3997
  const nodes = lexerTreeBuilder.sequenceNodesBuilder(text);
4017
- setSequenceNodes(nodes !== null && nodes !== void 0 ? nodes : []);
3998
+ setSequenceNodes(nodes ?? []);
4018
3999
  }, [
4019
4000
  change,
4020
4001
  editor,
@@ -4023,13 +4004,13 @@ function useRangesHighlight(editor, focusing, unitId, subUnitId) {
4023
4004
  (0, react.useEffect)(() => {
4024
4005
  if (!editor) return;
4025
4006
  if (!focusing) {
4026
- var _current$body$dataStr, _current$body;
4007
+ var _current$body;
4027
4008
  const current = editor.getDocumentData();
4028
4009
  editor.setDocumentData({
4029
4010
  ...current,
4030
4011
  body: {
4031
4012
  ...current.body,
4032
- 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 : "",
4013
+ dataStream: ((_current$body = current.body) === null || _current$body === void 0 ? void 0 : _current$body.dataStream) ?? "",
4033
4014
  textRuns: []
4034
4015
  }
4035
4016
  });
@@ -4080,11 +4061,12 @@ function useRangeSelectorSelectionChange(opts) {
4080
4061
  if (!supportAcrossSheet && currentSheet.getSheetId() !== subUnitId) return;
4081
4062
  if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return;
4082
4063
  const sheetName = keepSheetReference ? currentSheet.getName() : currentSheet.getSheetId() === subUnitId ? "" : currentSheet.getName();
4083
- onChange(selections.map((item) => ({
4064
+ const ranges = selections.map((item) => ({
4084
4065
  range: item.range,
4085
4066
  unitId,
4086
4067
  sheetName
4087
- })), isStart);
4068
+ }));
4069
+ onChange(ranges, isStart);
4088
4070
  });
4089
4071
  (0, react.useEffect)(() => {
4090
4072
  const disposableCollection = new _univerjs_core.DisposableCollection();
@@ -4197,7 +4179,8 @@ function RangeSelectorDialog(props) {
4197
4179
  });
4198
4180
  } else {
4199
4181
  newRanges.splice(focusIndex, 1, ...addedRanges);
4200
- setRanges(newRanges.slice(0, maxRangeCount));
4182
+ const finalRanges = newRanges.slice(0, maxRangeCount);
4183
+ setRanges(finalRanges);
4201
4184
  setFocusIndex(focusIndex + addedRanges.length - 1);
4202
4185
  }
4203
4186
  }
@@ -4261,7 +4244,7 @@ function stringifyRanges(ranges) {
4261
4244
  function RangeSelector(props) {
4262
4245
  const [editor, setEditor] = (0, react.useState)(null);
4263
4246
  const { onVerify, selectorRef, unitId, subUnitId, maxRangeCount, supportAcrossSheet, keepSheetReference, autoFocus, onChange, onRangeSelectorDialogVisibleChange, onClickOutside, onFocusChange, forceShowDialogWhenSelectionChanged, hideEditor, resetRange } = props;
4264
- const [focusing, setFocusing] = (0, react.useState)(autoFocus !== null && autoFocus !== void 0 ? autoFocus : false);
4247
+ const [focusing, setFocusing] = (0, react.useState)(autoFocus ?? false);
4265
4248
  const [popupVisible, setPopupVisible] = (0, react.useState)(false);
4266
4249
  const [rangeSelectorRanges, setRangeSelectorRanges] = (0, react.useState)([]);
4267
4250
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
@@ -4275,9 +4258,9 @@ function RangeSelector(props) {
4275
4258
  editorService.blur();
4276
4259
  });
4277
4260
  const handleOpenModal = (0, _univerjs_ui.useEvent)(() => {
4278
- var _editor$getDocumentDa, _editor$getDocumentDa2;
4261
+ var _editor$getDocumentDa;
4279
4262
  blurEditor();
4280
- 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 : ""));
4263
+ setRangeSelectorRanges(parseRanges((editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentDataModel()) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.getPlainText()) ?? ""));
4281
4264
  setPopupVisible(true);
4282
4265
  });
4283
4266
  (0, react.useEffect)(() => {
@@ -4301,8 +4284,8 @@ function RangeSelector(props) {
4301
4284
  setPopupVisible(false);
4302
4285
  },
4303
4286
  getValue: () => {
4304
- var _editor$getDocumentDa3, _editor$getDocumentDa4;
4305
- 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 : "";
4287
+ var _editor$getDocumentDa2;
4288
+ return (editor === null || editor === void 0 || (_editor$getDocumentDa2 = editor.getDocumentDataModel()) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.getPlainText()) ?? "";
4306
4289
  }
4307
4290
  };
4308
4291
  }, [
@@ -4313,8 +4296,8 @@ function RangeSelector(props) {
4313
4296
  sequenceNodesRef
4314
4297
  ]);
4315
4298
  (0, react.useEffect)(() => {
4316
- var _editor$getDocumentDa5, _editor$getDocumentDa6;
4317
- 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 : "");
4299
+ var _editor$getDocumentDa3;
4300
+ 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()) ?? "");
4318
4301
  }, [sequenceNodes]);
4319
4302
  (0, react.useEffect)(() => {
4320
4303
  onRangeSelectorDialogVisibleChange === null || onRangeSelectorDialogVisibleChange === void 0 || onRangeSelectorDialogVisibleChange(popupVisible);
@@ -4332,6 +4315,7 @@ function RangeSelector(props) {
4332
4315
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [!hideEditor ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_docs_ui.RichTextEditor, {
4333
4316
  isSingle: true,
4334
4317
  ...props,
4318
+ preserveHostFocus: true,
4335
4319
  onFocusChange: (focusing, newValue) => {
4336
4320
  setFocusing(focusing);
4337
4321
  onFocusChange === null || onFocusChange === void 0 || onFocusChange(focusing, newValue);
@@ -4358,10 +4342,9 @@ function RangeSelector(props) {
4358
4342
  maxRangeCount,
4359
4343
  onConfirm: (ranges) => {
4360
4344
  const resultStr = stringifyRanges(ranges);
4361
- const empty = _univerjs_core.RichTextBuilder.newEmptyData();
4362
- empty.body.dataStream = resultStr;
4345
+ const documentData = _univerjs_core.RichTextBuilder.create().insertText(resultStr).getData();
4363
4346
  editor === null || editor === void 0 || editor.replaceText(resultStr, false);
4364
- onChange === null || onChange === void 0 || onChange(empty, resultStr);
4347
+ onChange === null || onChange === void 0 || onChange(documentData, resultStr);
4365
4348
  setPopupVisible(false);
4366
4349
  setRangeSelectorRanges([]);
4367
4350
  requestAnimationFrame(() => {
@@ -4648,7 +4631,7 @@ function getSetCellFormulaMutations(unitId, subUnitId, range, matrix, accessor,
4648
4631
  const setValuesMutation = {
4649
4632
  unitId,
4650
4633
  subUnitId,
4651
- cellValue: valueMatrix.getData()
4634
+ cellValue: valueMatrix.clone()
4652
4635
  };
4653
4636
  redoMutationsInfo.push({
4654
4637
  id: _univerjs_sheets.SetRangeValuesMutation.id,
@@ -4991,7 +4974,7 @@ let FormulaEditorShowController = class FormulaEditorShowController extends _uni
4991
4974
  return cellInfo;
4992
4975
  }
4993
4976
  _createArrayFormulaRangeShape(arrayRange, unitId, subUnitId) {
4994
- const renderUnit = this._renderManagerService.getRenderById(unitId);
4977
+ const renderUnit = this._renderManagerService.getRenderUnitById(unitId);
4995
4978
  const skeleton = this._sheetSkeletonService.getSkeleton(unitId, subUnitId);
4996
4979
  if (!renderUnit || !skeleton) return;
4997
4980
  const { scene } = renderUnit;
@@ -5128,7 +5111,7 @@ let ImageFormulaRenderController = class ImageFormulaRenderController extends _u
5128
5111
  this._imageFormulaCellInterceptorController.registerRefreshRenderFunction(() => {
5129
5112
  const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
5130
5113
  if (!workbook) return;
5131
- const render = this._renderManagerService.getRenderById(workbook.getUnitId());
5114
+ const render = this._renderManagerService.getRenderUnitById(workbook.getUnitId());
5132
5115
  if (!render) return;
5133
5116
  render.with(_univerjs_sheets_ui.SheetSkeletonManagerService).reCalculate();
5134
5117
  const mainComponent = render.mainComponent;
@@ -5272,13 +5255,12 @@ var GlobalRangeSelectorService = class {
5272
5255
  //#endregion
5273
5256
  //#region src/views/range-selector/Global.tsx
5274
5257
  const GlobalRangeSelector = () => {
5275
- var _current$unitId, _current$subUnitId;
5276
5258
  const current = (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(GlobalRangeSelectorService).currentSelector$);
5277
5259
  const instance = (0, react.useRef)(null);
5278
5260
  (0, react.useEffect)(() => {
5279
5261
  if (current) {
5280
- var _instance$current, _current$initialValue;
5281
- (_instance$current = instance.current) === null || _instance$current === void 0 || _instance$current.showDialog((_current$initialValue = current.initialValue) !== null && _current$initialValue !== void 0 ? _current$initialValue : []);
5262
+ var _instance$current;
5263
+ (_instance$current = instance.current) === null || _instance$current === void 0 || _instance$current.showDialog(current.initialValue ?? []);
5282
5264
  return () => {
5283
5265
  var _instance$current2;
5284
5266
  (_instance$current2 = instance.current) === null || _instance$current2 === void 0 || _instance$current2.hideDialog();
@@ -5286,13 +5268,12 @@ const GlobalRangeSelector = () => {
5286
5268
  }
5287
5269
  }, [current]);
5288
5270
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RangeSelector, {
5289
- unitId: (_current$unitId = current === null || current === void 0 ? void 0 : current.unitId) !== null && _current$unitId !== void 0 ? _current$unitId : "",
5290
- subUnitId: (_current$subUnitId = current === null || current === void 0 ? void 0 : current.subUnitId) !== null && _current$subUnitId !== void 0 ? _current$subUnitId : "",
5271
+ unitId: (current === null || current === void 0 ? void 0 : current.unitId) ?? "",
5272
+ subUnitId: (current === null || current === void 0 ? void 0 : current.subUnitId) ?? "",
5291
5273
  hideEditor: true,
5292
5274
  selectorRef: instance,
5293
5275
  onChange: (_, value) => {
5294
- var _value$split$map;
5295
- current === null || current === void 0 || current.callback((_value$split$map = value === null || value === void 0 ? void 0 : value.split(",").map((i) => (0, _univerjs_engine_formula.deserializeRangeWithSheet)(i))) !== null && _value$split$map !== void 0 ? _value$split$map : []);
5276
+ current === null || current === void 0 || current.callback((value === null || value === void 0 ? void 0 : value.split(",").map((i) => (0, _univerjs_engine_formula.deserializeRangeWithSheet)(i))) ?? []);
5296
5277
  }
5297
5278
  });
5298
5279
  };
@@ -5354,7 +5335,7 @@ _defineProperty(UniverSheetsFormulaUIPlugin, "packageName", name);
5354
5335
  _defineProperty(UniverSheetsFormulaUIPlugin, "version", version);
5355
5336
  _defineProperty(UniverSheetsFormulaUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
5356
5337
  UniverSheetsFormulaUIPlugin = __decorate([
5357
- (0, _univerjs_core.DependentOn)(_univerjs_sheets_formula.UniverSheetsFormulaPlugin),
5338
+ (0, _univerjs_core.DependentOn)(_univerjs_engine_formula.UniverFormulaEnginePlugin, _univerjs_engine_render.UniverRenderEnginePlugin, _univerjs_sheets.UniverSheetsPlugin, _univerjs_sheets_formula.UniverSheetsFormulaPlugin, _univerjs_sheets_ui.UniverSheetsUIPlugin),
5358
5339
  __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
5359
5340
  __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
5360
5341
  __decorateParam(3, _univerjs_core.IConfigService),