@univerjs/sheets-formula-ui 1.0.0-alpha.6 → 1.0.0-alpha.8

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
@@ -32,7 +32,7 @@ const SheetOnlyPasteFormulaCommand = {
32
32
  };
33
33
 
34
34
  //#endregion
35
- //#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
36
36
  function _typeof(o) {
37
37
  "@babel/helpers - typeof";
38
38
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -43,7 +43,7 @@ function _typeof(o) {
43
43
  }
44
44
 
45
45
  //#endregion
46
- //#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
47
47
  function toPrimitive(t, r) {
48
48
  if ("object" != _typeof(t) || !t) return t;
49
49
  var e = t[Symbol.toPrimitive];
@@ -56,14 +56,14 @@ function toPrimitive(t, r) {
56
56
  }
57
57
 
58
58
  //#endregion
59
- //#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
60
60
  function toPropertyKey(t) {
61
61
  var i = toPrimitive(t, "string");
62
62
  return "symbol" == _typeof(i) ? i : i + "";
63
63
  }
64
64
 
65
65
  //#endregion
66
- //#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
67
67
  function _defineProperty(e, r, t) {
68
68
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
69
69
  value: t,
@@ -74,7 +74,7 @@ function _defineProperty(e, r, t) {
74
74
  }
75
75
 
76
76
  //#endregion
77
- //#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
78
78
  function __decorateParam(paramIndex, decorator) {
79
79
  return function(target, key) {
80
80
  decorator(target, key, paramIndex);
@@ -82,7 +82,7 @@ function __decorateParam(paramIndex, decorator) {
82
82
  }
83
83
 
84
84
  //#endregion
85
- //#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
86
86
  function __decorate(decorators, target, key, desc) {
87
87
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
88
88
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -328,7 +328,8 @@ const InsertFunctionOperation = {
328
328
  editColumn = column;
329
329
  return true;
330
330
  }
331
- const formulaString = `=${value}(${(0, _univerjs_engine_formula.serializeRange)(refRange)})`;
331
+ const rangeString = (0, _univerjs_engine_formula.serializeRange)(refRange);
332
+ const formulaString = `=${value}(${rangeString})`;
332
333
  list.push({
333
334
  range,
334
335
  primary: {
@@ -341,12 +342,13 @@ const InsertFunctionOperation = {
341
342
  const { startRow, startColumn, endRow, endColumn } = range;
342
343
  if (startRow === endRow) {
343
344
  const blankCellColumn = findBlankCellOfRow(cellMatrix, startRow, endColumn, worksheet.getColumnCount() - 1);
344
- const formulaString = `=${value}(${(0, _univerjs_engine_formula.serializeRange)({
345
+ const rangeString = (0, _univerjs_engine_formula.serializeRange)({
345
346
  startRow,
346
347
  endRow,
347
348
  startColumn,
348
349
  endColumn: blankCellColumn === endColumn ? endColumn - 1 : endColumn
349
- })})`;
350
+ });
351
+ const formulaString = `=${value}(${rangeString})`;
350
352
  listOfRangeHasNumber.push({
351
353
  range,
352
354
  primary: {
@@ -363,12 +365,13 @@ const InsertFunctionOperation = {
363
365
  }
364
366
  const newEndRow = maxBlankCellRow === endRow ? endRow - 1 : endRow;
365
367
  for (let c = startColumn; c <= endColumn; c++) {
366
- const formulaString = `=${value}(${(0, _univerjs_engine_formula.serializeRange)({
368
+ const rangeString = (0, _univerjs_engine_formula.serializeRange)({
367
369
  startRow,
368
370
  endRow: newEndRow,
369
371
  startColumn: c,
370
372
  endColumn: c
371
- })})`;
373
+ });
374
+ const formulaString = `=${value}(${rangeString})`;
372
375
  listOfRangeHasNumber.push({
373
376
  range,
374
377
  primary: {
@@ -696,6 +699,30 @@ const SearchFunctionOperation = {
696
699
  }
697
700
  };
698
701
 
702
+ //#endregion
703
+ //#region src/common/selection.ts
704
+ function genFormulaRefSelectionStyle(themeService, refColor, id) {
705
+ return {
706
+ id,
707
+ strokeWidth: 1,
708
+ stroke: refColor,
709
+ fill: new _univerjs_core.ColorKit(refColor).setAlpha(.05).toRgbString(),
710
+ widgets: {
711
+ tl: true,
712
+ tc: true,
713
+ tr: true,
714
+ ml: true,
715
+ mr: true,
716
+ bl: true,
717
+ bc: true,
718
+ br: true
719
+ },
720
+ widgetSize: 6,
721
+ widgetStrokeWidth: 1,
722
+ widgetStroke: themeService.getColorFromTheme("white")
723
+ };
724
+ }
725
+
699
726
  //#endregion
700
727
  //#region src/controllers/formula-reorder.controller.ts
701
728
  let FormulaReorderController = class FormulaReorderController extends _univerjs_core.Disposable {
@@ -720,7 +747,7 @@ let FormulaReorderController = class FormulaReorderController extends _univerjs_
720
747
  const redos = [];
721
748
  const undos = [];
722
749
  const { unitId, subUnitId, range, order } = params;
723
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
750
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
724
751
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
725
752
  if (!worksheet) return {
726
753
  redos,
@@ -798,7 +825,7 @@ function InsertCommonFunctionMenuItemFactory(accessor) {
798
825
  value: name
799
826
  }));
800
827
  try {
801
- const descriptionService = accessor.get(_univerjs_sheets_formula.IDescriptionService);
828
+ const descriptionService = accessor.get(_univerjs_engine_formula.IDescriptionService);
802
829
  const filtered = commonFunctions.filter((name) => Boolean(descriptionService.getFunctionInfo(name)));
803
830
  if (filtered.length > 0) selections = filtered.map((name) => ({
804
831
  label: {
@@ -823,7 +850,7 @@ function createInsertFunctionCategoryMenuItemFactory(functionType, categoryKey,
823
850
  return function insertFunctionCategoryMenuItemFactory(accessor) {
824
851
  let selections = [];
825
852
  try {
826
- selections = accessor.get(_univerjs_sheets_formula.IDescriptionService).getSearchListByType(functionType).map(({ name }) => ({
853
+ selections = accessor.get(_univerjs_engine_formula.IDescriptionService).getSearchListByType(functionType).map(({ name }) => ({
827
854
  label: {
828
855
  name,
829
856
  selectable: false
@@ -903,6 +930,12 @@ const menuSchema = {
903
930
  [_univerjs_ui.RibbonFormulasGroup.BASIC]: {
904
931
  [`${InsertFunctionOperation.id}.common`]: {
905
932
  order: 0,
933
+ gridLayout: {
934
+ row: 1,
935
+ column: 1,
936
+ rowSpan: 2,
937
+ showLabel: false
938
+ },
906
939
  menuItemFactory: InsertCommonFunctionMenuItemFactory,
907
940
  [MoreFunctionsOperation.id]: {
908
941
  order: 0,
@@ -963,7 +996,7 @@ const menuSchema = {
963
996
  //#endregion
964
997
  //#region package.json
965
998
  var name = "@univerjs/sheets-formula-ui";
966
- var version = "1.0.0-alpha.6";
999
+ var version = "1.0.0-alpha.8";
967
1000
 
968
1001
  //#endregion
969
1002
  //#region src/config/config.ts
@@ -1262,7 +1295,7 @@ const useStateRef = (value) => {
1262
1295
  //#region src/views/formula-editor/hooks/use-formula-describe.ts
1263
1296
  const useFormulaDescribe = (isNeed, formulaText, editor) => {
1264
1297
  const formulaPromptService = (0, _univerjs_ui.useDependency)(IFormulaPromptService);
1265
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_formula.IDescriptionService);
1298
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDescriptionService);
1266
1299
  const lexerTreeBuilder = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.LexerTreeBuilder);
1267
1300
  const [functionInfo, setFunctionInfo] = (0, react.useState)();
1268
1301
  const [paramIndex, setParamIndex] = (0, react.useState)(-1);
@@ -1290,14 +1323,16 @@ const useFormulaDescribe = (isNeed, formulaText, editor) => {
1290
1323
  const currentSequenceNode = formulaPromptService.getCurrentSequenceNodeByIndex(nodeIndex);
1291
1324
  const nextSequenceNode = formulaPromptService.getCurrentSequenceNodeByIndex(nodeIndex + 1);
1292
1325
  if (currentSequenceNode) if (typeof currentSequenceNode !== "string" && currentSequenceNode.nodeType === 3 && !descriptionService.hasDefinedNameDescription(currentSequenceNode.token.trim()) && nextSequenceNode === _univerjs_engine_formula.matchToken.OPEN_BRACKET) {
1293
- setFunctionInfo(descriptionService.getFunctionInfo(currentSequenceNode.token));
1326
+ const info = descriptionService.getFunctionInfo(currentSequenceNode.token);
1327
+ setFunctionInfo(info);
1294
1328
  setParamIndex(-1);
1295
1329
  return;
1296
1330
  } else {
1297
1331
  const res = lexerTreeBuilder.getFunctionAndParameter(`${formulaTextRef.current}A`, startOffset - 1);
1298
1332
  if (res) {
1299
1333
  const { functionName, paramIndex } = res;
1300
- setFunctionInfo(descriptionService.getFunctionInfo(functionName));
1334
+ const info = descriptionService.getFunctionInfo(functionName);
1335
+ setFunctionInfo(info);
1301
1336
  setParamIndex(paramIndex);
1302
1337
  return;
1303
1338
  }
@@ -1902,8 +1937,8 @@ function useFormulaSelecting(opts) {
1902
1937
  const { editor, editorId, isFocus, disableOnClick, unitId, subUnitId } = opts;
1903
1938
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
1904
1939
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1905
- const sheetRenderer = renderManagerService.getRenderById(unitId);
1906
- const renderer = renderManagerService.getRenderById(editorId);
1940
+ const sheetRenderer = renderManagerService.getRenderUnitById(unitId);
1941
+ const renderer = renderManagerService.getRenderUnitById(editorId);
1907
1942
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(_univerjs_docs_ui.DocSelectionRenderService);
1908
1943
  const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
1909
1944
  const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
@@ -2061,30 +2096,6 @@ const useFormulaToken = () => {
2061
2096
  return (0, react.useCallback)((text) => lexerTreeBuilder.sequenceNodesBuilder(text) || [], [lexerTreeBuilder]);
2062
2097
  };
2063
2098
 
2064
- //#endregion
2065
- //#region src/common/selection.ts
2066
- function genFormulaRefSelectionStyle(themeService, refColor, id) {
2067
- return {
2068
- id,
2069
- strokeWidth: 1,
2070
- stroke: refColor,
2071
- fill: new _univerjs_core.ColorKit(refColor).setAlpha(.05).toRgbString(),
2072
- widgets: {
2073
- tl: true,
2074
- tc: true,
2075
- tr: true,
2076
- ml: true,
2077
- mr: true,
2078
- bl: true,
2079
- bc: true,
2080
- br: true
2081
- },
2082
- widgetSize: 6,
2083
- widgetStrokeWidth: 1,
2084
- widgetStroke: themeService.getColorFromTheme("white")
2085
- };
2086
- }
2087
-
2088
2099
  //#endregion
2089
2100
  //#region src/views/formula-editor/hooks/use-highlight.ts
2090
2101
  function isSameSelectionRange(left, right) {
@@ -2156,7 +2167,7 @@ function useSheetHighlight(unitId, subUnitId) {
2156
2167
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
2157
2168
  const refSelectionsService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.IRefSelectionsService);
2158
2169
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2159
- const ownerRender = renderManagerService.getRenderById(unitId);
2170
+ const ownerRender = renderManagerService.getRenderUnitById(unitId);
2160
2171
  const ownerRefSelectionsRenderService = ownerRender === null || ownerRender === void 0 ? void 0 : ownerRender.with(RefSelectionsRenderService);
2161
2172
  const getHighlightWorkbook = (0, _univerjs_ui.useEvent)((refSelections) => {
2162
2173
  const ownerWorkbook = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
@@ -2168,7 +2179,7 @@ function useSheetHighlight(unitId, subUnitId) {
2168
2179
  var _currentWorkbook$getA;
2169
2180
  const currentWorkbook = getHighlightWorkbook(refSelections);
2170
2181
  if (!currentWorkbook) return;
2171
- const currentRender = renderManagerService.getRenderById(currentWorkbook.getUnitId());
2182
+ const currentRender = renderManagerService.getRenderUnitById(currentWorkbook.getUnitId());
2172
2183
  const refSelectionsRenderService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(RefSelectionsRenderService);
2173
2184
  const sheetSelectionRenderService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_sheets_ui.ISheetSelectionRenderService);
2174
2185
  const sheetSkeletonManagerService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_sheets_ui.SheetSkeletonManagerService);
@@ -2200,7 +2211,7 @@ function useSheetHighlight(unitId, subUnitId) {
2200
2211
  return highlightSheet;
2201
2212
  }
2202
2213
  function useDocHight(_leadingCharacter = "") {
2203
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_formula.IDescriptionService);
2214
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDescriptionService);
2204
2215
  const colorMap = useColor();
2205
2216
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2206
2217
  const leadingCharacterLength = (0, react.useMemo)(() => _leadingCharacter.length, [_leadingCharacter]);
@@ -2224,7 +2235,7 @@ function useDocHight(_leadingCharacter = "") {
2224
2235
  e.ed = e.ed + leadingCharacterLength;
2225
2236
  e.st = e.st + leadingCharacterLength;
2226
2237
  });
2227
- const highlightDataStream = getFormulaHighlightDataStream(_leadingCharacter, sequenceNodes, sourceText);
2238
+ const highlightDataStream = (0, _univerjs_engine_formula.getFormulaHighlightDataStream)(_leadingCharacter, sequenceNodes, sourceText);
2228
2239
  const highlightTextRuns = [{
2229
2240
  st: 0,
2230
2241
  ed: 1,
@@ -2259,12 +2270,6 @@ function createFormulaHighlightBody(dataStream, textRuns) {
2259
2270
  textRuns
2260
2271
  };
2261
2272
  }
2262
- function getFormulaHighlightDataStream(leadingCharacter, sequenceNodes, sourceText) {
2263
- return `${leadingCharacter}${sourceText !== null && sourceText !== void 0 ? sourceText : sequenceNodes.reduce((pre, cur) => {
2264
- if (typeof cur === "string") return `${pre}${cur}`;
2265
- return `${pre}${cur.token}`;
2266
- }, "")}\r\n`;
2267
- }
2268
2273
  function useColor() {
2269
2274
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
2270
2275
  return (0, react.useMemo)(() => {
@@ -2290,79 +2295,7 @@ function useColor() {
2290
2295
  }, [themeService.getCurrentTheme()]);
2291
2296
  }
2292
2297
  function buildTextRuns(descriptionService, colorMap, sequenceNodes) {
2293
- const { formulaRefColors, numberColor, stringColor, plainTextColor } = colorMap;
2294
- const textRuns = [];
2295
- const refSelections = [];
2296
- const themeColorMap = /* @__PURE__ */ new Map();
2297
- let refColorIndex = 0;
2298
- for (let i = 0, len = sequenceNodes.length; i < len; i++) {
2299
- const node = sequenceNodes[i];
2300
- if (typeof node === "string") {
2301
- const theLastItem = textRuns[textRuns.length - 1];
2302
- const start = theLastItem ? theLastItem.ed : 0;
2303
- const end = start + node.length;
2304
- textRuns.push({
2305
- st: start,
2306
- ed: end,
2307
- ts: {
2308
- cl: { rgb: plainTextColor },
2309
- fs: 11
2310
- }
2311
- });
2312
- continue;
2313
- }
2314
- if (descriptionService.hasDefinedNameDescription(node.token.trim())) {
2315
- textRuns.push({
2316
- st: node.startIndex,
2317
- ed: node.endIndex + 1,
2318
- ts: {
2319
- cl: { rgb: plainTextColor },
2320
- fs: 11
2321
- }
2322
- });
2323
- continue;
2324
- }
2325
- const { startIndex, endIndex, nodeType, token } = node;
2326
- let themeColor = "";
2327
- if (nodeType === _univerjs_engine_formula.sequenceNodeType.REFERENCE) {
2328
- if (themeColorMap.has(token)) themeColor = themeColorMap.get(token);
2329
- else {
2330
- themeColor = formulaRefColors[refColorIndex % formulaRefColors.length];
2331
- themeColorMap.set(token, themeColor);
2332
- refColorIndex++;
2333
- }
2334
- refSelections.push({
2335
- refIndex: i,
2336
- themeColor,
2337
- token,
2338
- startIndex: node.startIndex,
2339
- endIndex: node.endIndex,
2340
- index: refSelections.length
2341
- });
2342
- } else if (nodeType === _univerjs_engine_formula.sequenceNodeType.NUMBER) themeColor = numberColor;
2343
- else if (nodeType === _univerjs_engine_formula.sequenceNodeType.STRING) themeColor = stringColor;
2344
- else if (nodeType === _univerjs_engine_formula.sequenceNodeType.ARRAY) themeColor = stringColor;
2345
- if (themeColor && themeColor.length > 0) textRuns.push({
2346
- st: startIndex,
2347
- ed: endIndex + 1,
2348
- ts: {
2349
- cl: { rgb: themeColor },
2350
- fs: 11
2351
- }
2352
- });
2353
- else textRuns.push({
2354
- st: startIndex,
2355
- ed: endIndex + 1,
2356
- ts: {
2357
- cl: { rgb: plainTextColor },
2358
- fs: 11
2359
- }
2360
- });
2361
- }
2362
- return {
2363
- textRuns,
2364
- refSelections
2365
- };
2298
+ return (0, _univerjs_engine_formula.buildFormulaTextRuns)(descriptionService, colorMap, sequenceNodes);
2366
2299
  }
2367
2300
 
2368
2301
  //#endregion
@@ -2545,7 +2478,7 @@ const useRefactorEffect = (isNeed, selecting, unitId, editorId, disableContextMe
2545
2478
  const refSelectionsService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.IRefSelectionsService);
2546
2479
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
2547
2480
  const currentUnit = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), [univerInstanceService]));
2548
- const render = renderManagerService.getRenderById((_currentUnit$getUnitI = currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== null && _currentUnit$getUnitI !== void 0 ? _currentUnit$getUnitI : "");
2481
+ const render = renderManagerService.getRenderUnitById((_currentUnit$getUnitI = currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== null && _currentUnit$getUnitI !== void 0 ? _currentUnit$getUnitI : "");
2549
2482
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
2550
2483
  (0, react.useLayoutEffect)(() => {
2551
2484
  if (isNeed) {
@@ -2652,24 +2585,6 @@ const prepareSelectionChangeContext = (opts) => {
2652
2585
  offset
2653
2586
  };
2654
2587
  };
2655
- function getSequenceNodeCharAtOffset(sequenceNodes, offset) {
2656
- let currentOffset = 0;
2657
- for (const node of sequenceNodes) {
2658
- const text = typeof node === "string" ? node : node.token;
2659
- const nextOffset = currentOffset + text.length;
2660
- if (offset > currentOffset && offset <= nextOffset) return text[offset - currentOffset - 1];
2661
- currentOffset = nextOffset;
2662
- }
2663
- }
2664
- function isFormulaReferenceAddingContext(sequenceNodes, offset) {
2665
- const char = getSequenceNodeCharAtOffset(sequenceNodes, offset);
2666
- return Boolean(char && (0, _univerjs_engine_formula.matchRefDrawToken)(char));
2667
- }
2668
- function isFormulaReferenceAddingTextContext(formulaText, offset) {
2669
- const char = formulaText[offset - 1];
2670
- const nextChar = formulaText[offset];
2671
- return Boolean(char && (0, _univerjs_engine_formula.matchRefDrawToken)(char) && (!nextChar || (0, _univerjs_engine_formula.isFormulaLexerToken)(nextChar) && nextChar !== _univerjs_engine_formula.matchToken.OPEN_BRACKET));
2672
- }
2673
2588
  function insertFormulaReferenceText(formulaText, refText, offset) {
2674
2589
  return `${formulaText.slice(0, offset)}${refText}${formulaText.slice(offset)}`;
2675
2590
  }
@@ -2807,7 +2722,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2807
2722
  sheetName
2808
2723
  });
2809
2724
  const activeWorkbook = resolveFormulaSelectionWorkbook((0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), [univerInstanceService])), workbook);
2810
- const render = renderManagerService.getRenderById((_activeWorkbook$getUn = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== null && _activeWorkbook$getUn !== void 0 ? _activeWorkbook$getUn : unitId);
2725
+ const render = renderManagerService.getRenderUnitById((_activeWorkbook$getUn = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== null && _activeWorkbook$getUn !== void 0 ? _activeWorkbook$getUn : unitId);
2811
2726
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
2812
2727
  const sheetSkeletonManagerService = render === null || render === void 0 ? void 0 : render.with(_univerjs_sheets_ui.SheetSkeletonManagerService);
2813
2728
  const refSelectionsService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.IRefSelectionsService);
@@ -2820,7 +2735,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2820
2735
  });
2821
2736
  if (!ctx) return;
2822
2737
  const { nodeIndex, updatingRefIndex, formulaText, sequenceNodes, offset } = ctx;
2823
- if (isSelectingRef.current === 1 || isFormulaReferenceAddingContext(sequenceNodes, offset) || isFormulaReferenceAddingTextContext(formulaText, offset)) if (offset !== 0) {
2738
+ if (isSelectingRef.current === 1 || (0, _univerjs_engine_formula.isFormulaReferenceAddingContext)(sequenceNodes, offset) || (0, _univerjs_engine_formula.isFormulaReferenceAddingTextContext)(formulaText, offset)) if (offset !== 0) {
2824
2739
  var _range$sheetId, _range$unitId, _range$unitId2;
2825
2740
  if (nodeIndex === -1 && sequenceNodes.length) return;
2826
2741
  const range = getLastFormulaSelection(selections);
@@ -2835,7 +2750,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2835
2750
  const isAcrossSheet = rangeSheetId !== subUnitId;
2836
2751
  const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
2837
2752
  const refRanges = unitRangesToText([unitRangeName], isSupportAcrossSheet && (isAcrossSheet || isAcrossWorkbook), sheetName, isAcrossWorkbook);
2838
- if (isFormulaReferenceAddingTextContext(formulaText, offset)) {
2753
+ if ((0, _univerjs_engine_formula.isFormulaReferenceAddingTextContext)(formulaText, offset)) {
2839
2754
  handleRangeChange(insertFormulaReferenceText(formulaText, refRanges[0], offset), offset + refRanges[0].length, isEnd);
2840
2755
  return;
2841
2756
  }
@@ -3026,7 +2941,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
3026
2941
  editor,
3027
2942
  lexerTreeBuilder
3028
2943
  });
3029
- const isAdd = isSelectingRef.current === 1 || Boolean(ctx && (isFormulaReferenceAddingContext(ctx.sequenceNodes, ctx.offset) || isFormulaReferenceAddingTextContext(ctx.formulaText, ctx.offset)));
2944
+ 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)));
3030
2945
  const selections = ((_refSelectionsRenderS = refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.getSelectionDataWithStyle()) !== null && _refSelectionsRenderS !== void 0 ? _refSelectionsRenderS : []).map((i) => i.rangeWithCoord);
3031
2946
  if (isAdd) {
3032
2947
  if (selections.length > 0 && isSameFormulaSelection(selections[selections.length - 1], range)) return;
@@ -3108,7 +3023,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
3108
3023
  const useSwitchSheet = (isNeed, unitId, isSupportAcrossSheet, isFocusSet, onBlur, refresh) => {
3109
3024
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
3110
3025
  const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
3111
- const render = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderById(unitId);
3026
+ const render = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(unitId);
3112
3027
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
3113
3028
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
3114
3029
  (0, react.useEffect)(() => {
@@ -3171,28 +3086,11 @@ const useVerify = (isNeed, onVerify, formulaText) => {
3171
3086
 
3172
3087
  //#endregion
3173
3088
  //#region src/views/formula-editor/hooks/use-formula-search.ts
3174
- function shouldAppendOpenBracket(functionType) {
3175
- return functionType !== _univerjs_engine_formula.FunctionType.DefinedName && functionType !== _univerjs_engine_formula.FunctionType.Table;
3176
- }
3177
3089
  function getFormulaReplaceResult(nodes, index, formulaName, functionType) {
3178
- const cloneNodes = [...nodes];
3179
- if (index !== -1) {
3180
- const lastNodes = cloneNodes.splice(index + 1);
3181
- const oldNode = cloneNodes.pop() || "";
3182
- let offset = (typeof oldNode === "string" ? oldNode.length : oldNode.token.length) - formulaName.length;
3183
- cloneNodes.push(formulaName);
3184
- if (lastNodes[0] !== _univerjs_engine_formula.matchToken.OPEN_BRACKET && shouldAppendOpenBracket(functionType)) {
3185
- cloneNodes.push(_univerjs_engine_formula.matchToken.OPEN_BRACKET);
3186
- offset--;
3187
- }
3188
- return {
3189
- text: sequenceNodeToText([...cloneNodes, ...lastNodes]),
3190
- offset
3191
- };
3192
- }
3090
+ return (0, _univerjs_engine_formula.getFormulaReplaceResult)(nodes, index, formulaName, functionType);
3193
3091
  }
3194
3092
  const useFormulaSearch = (isNeed, nodes = [], editor) => {
3195
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_formula.IDescriptionService);
3093
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDescriptionService);
3196
3094
  const [searchList, setSearchList] = (0, react.useState)([]);
3197
3095
  const [searchText, setSearchText] = (0, react.useState)("");
3198
3096
  const indexRef = (0, react.useRef)(-1);
@@ -3216,7 +3114,8 @@ const useFormulaSearch = (isNeed, nodes = [], editor) => {
3216
3114
  if (currentNode && typeof currentNode !== "string" && currentNode.nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION) {
3217
3115
  indexRef.current = currentNodeIndex;
3218
3116
  const token = currentNode.token;
3219
- setSearchList(descriptionService.getSearchListByNameFirstLetter(token).slice(0, 10));
3117
+ const list = (0, _univerjs_engine_formula.searchFormulaFunctions)(descriptionService, token);
3118
+ setSearchList(list);
3220
3119
  setSearchText(token);
3221
3120
  return;
3222
3121
  }
@@ -3481,7 +3380,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3481
3380
  disableOnClick: disableSelectionOnClick
3482
3381
  });
3483
3382
  const highTextRef = (0, react.useRef)("");
3484
- const renderer = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderById(editorId);
3383
+ const renderer = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(editorId);
3485
3384
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(_univerjs_docs_ui.DocSelectionRenderService);
3486
3385
  const isFocusing = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing;
3487
3386
  const currentDoc = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC), [univerInstanceService]));
@@ -3863,7 +3762,7 @@ function SelectFunction(props) {
3863
3762
  const [typeSelected, setTypeSelected] = (0, react.useState)(allTypeValue);
3864
3763
  const [nameSelected, setNameSelected] = (0, react.useState)(0);
3865
3764
  const [functionInfo, setFunctionInfo] = (0, react.useState)(null);
3866
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_formula.IDescriptionService);
3765
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDescriptionService);
3867
3766
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
3868
3767
  const sidebarOptions = (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(_univerjs_ui.ISidebarService).sidebarOptions$);
3869
3768
  const options = getFunctionTypeValues(localeService, Boolean(customFunction)).filter((option) => descriptionService.getSearchListByType(Number(option.value)).length > 0);
@@ -3919,11 +3818,13 @@ function SelectFunction(props) {
3919
3818
  };
3920
3819
  function handleSelectChange(value) {
3921
3820
  setTypeSelected(value);
3922
- setSelectList(descriptionService.getSearchListByType(+value));
3821
+ const selectList = descriptionService.getSearchListByType(+value);
3822
+ setSelectList(selectList);
3923
3823
  }
3924
3824
  function handleSearchInputChange(value) {
3925
3825
  setSearchText(value);
3926
- setSelectList(descriptionService.getSearchListByName(value));
3826
+ const selectList = descriptionService.getSearchListByName(value);
3827
+ setSelectList(selectList);
3927
3828
  }
3928
3829
  function handleSelectListKeyDown(e) {
3929
3830
  e.stopPropagation();
@@ -4182,11 +4083,12 @@ function useRangeSelectorSelectionChange(opts) {
4182
4083
  if (!supportAcrossSheet && currentSheet.getSheetId() !== subUnitId) return;
4183
4084
  if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return;
4184
4085
  const sheetName = keepSheetReference ? currentSheet.getName() : currentSheet.getSheetId() === subUnitId ? "" : currentSheet.getName();
4185
- onChange(selections.map((item) => ({
4086
+ const ranges = selections.map((item) => ({
4186
4087
  range: item.range,
4187
4088
  unitId,
4188
4089
  sheetName
4189
- })), isStart);
4090
+ }));
4091
+ onChange(ranges, isStart);
4190
4092
  });
4191
4093
  (0, react.useEffect)(() => {
4192
4094
  const disposableCollection = new _univerjs_core.DisposableCollection();
@@ -4299,7 +4201,8 @@ function RangeSelectorDialog(props) {
4299
4201
  });
4300
4202
  } else {
4301
4203
  newRanges.splice(focusIndex, 1, ...addedRanges);
4302
- setRanges(newRanges.slice(0, maxRangeCount));
4204
+ const finalRanges = newRanges.slice(0, maxRangeCount);
4205
+ setRanges(finalRanges);
4303
4206
  setFocusIndex(focusIndex + addedRanges.length - 1);
4304
4207
  }
4305
4208
  }
@@ -4460,10 +4363,9 @@ function RangeSelector(props) {
4460
4363
  maxRangeCount,
4461
4364
  onConfirm: (ranges) => {
4462
4365
  const resultStr = stringifyRanges(ranges);
4463
- const empty = _univerjs_core.RichTextBuilder.newEmptyData();
4464
- empty.body.dataStream = resultStr;
4366
+ const documentData = _univerjs_core.RichTextBuilder.create().insertText(resultStr).getData();
4465
4367
  editor === null || editor === void 0 || editor.replaceText(resultStr, false);
4466
- onChange === null || onChange === void 0 || onChange(empty, resultStr);
4368
+ onChange === null || onChange === void 0 || onChange(documentData, resultStr);
4467
4369
  setPopupVisible(false);
4468
4370
  setRangeSelectorRanges([]);
4469
4371
  requestAnimationFrame(() => {
@@ -4750,7 +4652,7 @@ function getSetCellFormulaMutations(unitId, subUnitId, range, matrix, accessor,
4750
4652
  const setValuesMutation = {
4751
4653
  unitId,
4752
4654
  subUnitId,
4753
- cellValue: valueMatrix.getData()
4655
+ cellValue: valueMatrix.clone()
4754
4656
  };
4755
4657
  redoMutationsInfo.push({
4756
4658
  id: _univerjs_sheets.SetRangeValuesMutation.id,
@@ -5093,7 +4995,7 @@ let FormulaEditorShowController = class FormulaEditorShowController extends _uni
5093
4995
  return cellInfo;
5094
4996
  }
5095
4997
  _createArrayFormulaRangeShape(arrayRange, unitId, subUnitId) {
5096
- const renderUnit = this._renderManagerService.getRenderById(unitId);
4998
+ const renderUnit = this._renderManagerService.getRenderUnitById(unitId);
5097
4999
  const skeleton = this._sheetSkeletonService.getSkeleton(unitId, subUnitId);
5098
5000
  if (!renderUnit || !skeleton) return;
5099
5001
  const { scene } = renderUnit;
@@ -5230,7 +5132,7 @@ let ImageFormulaRenderController = class ImageFormulaRenderController extends _u
5230
5132
  this._imageFormulaCellInterceptorController.registerRefreshRenderFunction(() => {
5231
5133
  const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
5232
5134
  if (!workbook) return;
5233
- const render = this._renderManagerService.getRenderById(workbook.getUnitId());
5135
+ const render = this._renderManagerService.getRenderUnitById(workbook.getUnitId());
5234
5136
  if (!render) return;
5235
5137
  render.with(_univerjs_sheets_ui.SheetSkeletonManagerService).reCalculate();
5236
5138
  const mainComponent = render.mainComponent;
@@ -5456,7 +5358,7 @@ _defineProperty(UniverSheetsFormulaUIPlugin, "packageName", name);
5456
5358
  _defineProperty(UniverSheetsFormulaUIPlugin, "version", version);
5457
5359
  _defineProperty(UniverSheetsFormulaUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
5458
5360
  UniverSheetsFormulaUIPlugin = __decorate([
5459
- (0, _univerjs_core.DependentOn)(_univerjs_sheets_formula.UniverSheetsFormulaPlugin),
5361
+ (0, _univerjs_core.DependentOn)(_univerjs_engine_formula.UniverFormulaEnginePlugin, _univerjs_engine_render.UniverRenderEnginePlugin, _univerjs_sheets.UniverSheetsPlugin, _univerjs_ui.UniverUIPlugin, _univerjs_sheets_formula.UniverSheetsFormulaPlugin, _univerjs_sheets_ui.UniverSheetsUIPlugin),
5460
5362
  __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
5461
5363
  __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
5462
5364
  __decorateParam(3, _univerjs_core.IConfigService),
@@ -5493,4 +5395,5 @@ Object.defineProperty(exports, 'UniverSheetsFormulaUIPlugin', {
5493
5395
  get: function () {
5494
5396
  return UniverSheetsFormulaUIPlugin;
5495
5397
  }
5496
- });
5398
+ });
5399
+ exports.genFormulaRefSelectionStyle = genFormulaRefSelectionStyle;