@univerjs/sheets-formula-ui 1.0.0-rc.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AbsoluteRefType, BuildTextUtils, CellValueType, ColorKit, CommandType, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DocumentFlavor, EDITOR_ACTIVATED, FOCUSING_FX_BAR_EDITOR, HorizontalAlign, ICommandService, IConfigService, IContextService, ILogService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, ObjectMatrix, Plugin, RANGE_TYPE, Range, Rectangle, RichTextBuilder, RxDisposable, ThemeService, Tools, UniverInstanceType, VerticalAlign, createIdentifier, createInternalEditorID, generateRandomId, getCellValueType, getEmptyCell, isFormulaId, isFormulaString, isICellData, isRealNum, merge, noop, registerDependencies, toDisposable, touchDependencies } from "@univerjs/core";
1
+ import { AbsoluteRefType, BuildTextUtils, CellValueType, ColorKit, CommandType, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DocumentFlavor, EDITOR_ACTIVATED, FOCUSING_FX_BAR_EDITOR, HorizontalAlign, ICommandService, IConfigService, IContextService, ILogService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, ObjectMatrix, Plugin, RANGE_TYPE, Range, Rectangle, RichTextBuilder, RxDisposable, ThemeService, Tools, UniverInstanceType, VerticalAlign, createIdentifier, createInternalEditorID, generateRandomId, getCellValueType, getEmptyCell, isFormulaId, isFormulaString, isICellData, isRealNum, merge, noop, regexp, registerDependencies, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { BaseSelectionRenderService, COPY_SPECIAL_MENU_ID, COPY_TYPE, CellAlertManagerService, CellAlertType, EMBEDDING_FORMULA_EDITOR, EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY, ExpandSelectionCommand, HoverManagerService, IEditorBridgeService, IMarkSelectionService, ISheetClipboardService, ISheetSelectionRenderService, JumpOver, MOBILE_EXPANDING_SELECTION, MOBILE_FORMULA_FUNCTION_PANEL_OPEN, MOBILE_PINCH_ZOOMING, MobileSelectionControl, MoveSelectionCommand, PASTE_SPECIAL_MENU_ID, PREDEFINED_HOOK_NAME_COPY, PREDEFINED_HOOK_NAME_PASTE, RANGE_SELECTOR_COMPONENT_KEY, SELECTION_SHAPE_DEPTH, SelectionControl, SetCellEditVisibleOperation, SheetPasteCommand, SheetSkeletonManagerService, SheetsUIPart, UniverSheetsMobileUIPlugin, UniverSheetsUIPlugin, checkInHeaderRanges, genNormalSelectionStyle, getAllSelection, getCoordByOffset, getCurrentRangeDisable$, getSheetObject, menuClipboardDisabledObservable, useActiveWorkbook, whenSheetEditorActivated, whenSheetEditorFocused } from "@univerjs/sheets-ui";
3
3
  import { ErrorType, FormulaDataModel, FunctionType, IDescriptionService, LexerTreeBuilder, SetArrayFormulaDataMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStopMutation, UniverFormulaEnginePlugin, buildFormulaTextRuns, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, extractFormulaError, generateStringWithSequence, getAbsoluteRefTypeWithSingleString, getFormulaHighlightDataStream, getFormulaReplaceResult, handleRefStringInfo, isFormulaLexerToken, isFormulaReferenceAddingContext, isFormulaReferenceAddingTextContext, matchRefDrawToken, matchToken, operatorToken, searchFormulaFunctions, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from "@univerjs/engine-formula";
4
4
  import { BehaviorSubject, Subject, combineLatestWith, debounceTime, distinctUntilChanged, filter, map, merge as merge$1, throttleTime } from "rxjs";
@@ -32,7 +32,7 @@ const SheetOnlyPasteFormulaCommand = {
32
32
  };
33
33
 
34
34
  //#endregion
35
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
35
+ //#region \0@oxc-project+runtime@0.149.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.140.0/helpers/esm/toPrimitive.js
46
+ //#region \0@oxc-project+runtime@0.149.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.140.0/helpers/esm/toPropertyKey.js
59
+ //#region \0@oxc-project+runtime@0.149.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.140.0/helpers/esm/defineProperty.js
66
+ //#region \0@oxc-project+runtime@0.149.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.140.0/helpers/esm/decorateParam.js
77
+ //#region \0@oxc-project+runtime@0.149.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.140.0/helpers/esm/decorate.js
85
+ //#region \0@oxc-project+runtime@0.149.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);
@@ -340,11 +340,12 @@ const InsertFunctionOperation = {
340
340
  const { startRow, startColumn, endRow, endColumn } = range;
341
341
  if (startRow === endRow) {
342
342
  const blankCellColumn = findBlankCellOfRow(cellMatrix, startRow, endColumn, worksheet.getColumnCount() - 1);
343
+ const newEndColumn = blankCellColumn === endColumn ? endColumn - 1 : endColumn;
343
344
  const rangeString = serializeRange({
344
345
  startRow,
345
346
  endRow,
346
347
  startColumn,
347
- endColumn: blankCellColumn === endColumn ? endColumn - 1 : endColumn
348
+ endColumn: newEndColumn
348
349
  });
349
350
  const formulaString = `=${value}(${rangeString})`;
350
351
  listOfRangeHasNumber.push({
@@ -473,7 +474,8 @@ function isNumberCell(cell) {
473
474
  const body = cell === null || cell === void 0 ? void 0 : cell.p.body;
474
475
  if (body == null) return false;
475
476
  const data = body.dataStream;
476
- return isRealNum(data.substring(data.length - 2, data.length) === DEFAULT_EMPTY_DOCUMENT_VALUE ? data.substring(0, data.length - 2) : data);
477
+ const newDataStream = data.substring(data.length - 2, data.length) === DEFAULT_EMPTY_DOCUMENT_VALUE ? data.substring(0, data.length - 2) : data;
478
+ return isRealNum(newDataStream);
477
479
  }
478
480
  return cell && (cell.t === CellValueType.NUMBER || getCellValueType(cell) === CellValueType.NUMBER);
479
481
  }
@@ -578,15 +580,16 @@ function toggleReferenceAbsoluteAtCursor(lexerTreeBuilder, formulaText, cursorOf
578
580
  if (!matchedReference || typeof matchedReference === "string") return null;
579
581
  const nextReferenceState = _toggleReferenceToken(matchedReference, relativeCursorOffset - matchedReference.startIndex);
580
582
  if (nextReferenceState == null || nextReferenceState.token === matchedReference.token) return null;
583
+ const nextSequenceNodes = sequenceNodes.map((node) => {
584
+ if (node !== matchedReference) return node;
585
+ return {
586
+ ...node,
587
+ token: nextReferenceState.token,
588
+ endIndex: node.startIndex + nextReferenceState.token.length - 1
589
+ };
590
+ });
581
591
  return {
582
- formulaText: `=${generateStringWithSequence(sequenceNodes.map((node) => {
583
- if (node !== matchedReference) return node;
584
- return {
585
- ...node,
586
- token: nextReferenceState.token,
587
- endIndex: node.startIndex + nextReferenceState.token.length - 1
588
- };
589
- }))}`,
592
+ formulaText: `=${generateStringWithSequence(nextSequenceNodes)}`,
590
593
  cursorOffset: _translateCursorOffset(normalizedCursorOffset, matchedReference.startIndex + 1, matchedReference.endIndex + 2, nextReferenceState.token.length, nextReferenceState)
591
594
  };
592
595
  }
@@ -675,7 +678,8 @@ const ReferenceAbsoluteOperation = {
675
678
  if (editorId !== DOCS_NORMAL_EDITOR_UNIT_ID_KEY && editorId !== DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) return false;
676
679
  const activeTextRange = docSelectionManagerService.getActiveTextRange();
677
680
  if (!activeTextRange) return false;
678
- const nextReferenceState = toggleReferenceAbsoluteAtCursor(lexerTreeBuilder, BuildTextUtils.transform.getPlainText(((_focusEditor$getDocum = focusEditor.getDocumentData().body) === null || _focusEditor$getDocum === void 0 ? void 0 : _focusEditor$getDocum.dataStream) ?? ""), activeTextRange.endOffset);
681
+ const formulaText = BuildTextUtils.transform.getPlainText(((_focusEditor$getDocum = focusEditor.getDocumentData().body) === null || _focusEditor$getDocum === void 0 ? void 0 : _focusEditor$getDocum.dataStream) ?? "");
682
+ const nextReferenceState = toggleReferenceAbsoluteAtCursor(lexerTreeBuilder, formulaText, activeTextRange.endOffset);
679
683
  if (!nextReferenceState) return false;
680
684
  focusEditor.replaceText(nextReferenceState.formulaText, [{
681
685
  startOffset: nextReferenceState.cursorOffset,
@@ -994,7 +998,7 @@ const menuSchema = {
994
998
  //#endregion
995
999
  //#region package.json
996
1000
  var name = "@univerjs/sheets-formula-ui";
997
- var version = "1.0.0-rc.0";
1001
+ var version = "1.0.1";
998
1002
 
999
1003
  //#endregion
1000
1004
  //#region src/config/config.ts
@@ -1137,11 +1141,15 @@ let FormulaClipboardController = class FormulaClipboardController extends Dispos
1137
1141
  const formulaString = isFormulaString(cellData.f) ? cellData.f : self._formulaDataModel.getFormulaStringByCell(row, column, currentSheet.getSheetId(), currentSheet.getUnitId());
1138
1142
  matrixFragment.setValue(rowIndexInMatrix, columnIndexInMatrix, {
1139
1143
  ...getEmptyCell(),
1140
- f: formulaString
1144
+ f: formulaString,
1145
+ ft: cellData.ft,
1146
+ fd: cellData.fd
1141
1147
  });
1142
1148
  plainMatrix.setValue(rowIndexInMatrix, columnIndexInMatrix, {
1143
1149
  ...getEmptyCell(),
1144
1150
  f: formulaString,
1151
+ ft: cellData.ft,
1152
+ fd: cellData.fd,
1145
1153
  displayV: formulaString
1146
1154
  });
1147
1155
  } else {
@@ -1211,6 +1219,7 @@ FormulaClipboardController = __decorate([
1211
1219
  __decorateParam(4, Inject(FormulaDataModel))
1212
1220
  ], FormulaClipboardController);
1213
1221
  function getSetCellFormulaMutations(unitId, subUnitId, range, matrix, accessor, copyInfo, lexerTreeBuilder, formulaDataModel, _isSpecialPaste = false, pasteFrom) {
1222
+ var _accessor$get$getUnit;
1214
1223
  const redoMutationsInfo = [];
1215
1224
  const undoMutationsInfo = [];
1216
1225
  const valueMatrix = getValueMatrix(unitId, subUnitId, range, matrix, copyInfo, lexerTreeBuilder, formulaDataModel, pasteFrom);
@@ -1218,6 +1227,19 @@ function getSetCellFormulaMutations(unitId, subUnitId, range, matrix, accessor,
1218
1227
  undos: [],
1219
1228
  redos: []
1220
1229
  };
1230
+ const worksheet = (_accessor$get$getUnit = accessor.get(IUniverInstanceService).getUnit(unitId)) === null || _accessor$get$getUnit === void 0 ? void 0 : _accessor$get$getUnit.getSheetBySheetId(subUnitId);
1231
+ matrix.forValue((row, col, source) => {
1232
+ const targetRow = range.rows[row];
1233
+ const targetCol = range.cols[col];
1234
+ const value = valueMatrix.getValue(targetRow, targetCol);
1235
+ if (!value) return;
1236
+ const target = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCellRaw(targetRow, targetCol);
1237
+ const keepsFormula = pasteFrom && copyInfo.pasteType !== PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE && (isFormulaString(value.f) || isFormulaId(value.si));
1238
+ if (source.ft != null || source.fd != null || (target === null || target === void 0 ? void 0 : target.ft) != null || (target === null || target === void 0 ? void 0 : target.fd) != null) {
1239
+ value.ft = keepsFormula ? source.ft ?? null : null;
1240
+ value.fd = keepsFormula ? source.fd ?? null : null;
1241
+ }
1242
+ });
1221
1243
  const setValuesMutation = {
1222
1244
  unitId,
1223
1245
  subUnitId,
@@ -1581,7 +1603,7 @@ let FormulaEditorShowController = class FormulaEditorShowController extends Disp
1581
1603
  if (!renderUnit || !skeleton) return;
1582
1604
  const { scene } = renderUnit;
1583
1605
  if (!scene) return;
1584
- const selectionWithCoord = attachSelectionWithCoord({
1606
+ const selectionWithStyle = {
1585
1607
  range: arrayRange,
1586
1608
  primary: null,
1587
1609
  style: {
@@ -1590,7 +1612,8 @@ let FormulaEditorShowController = class FormulaEditorShowController extends Disp
1590
1612
  fill: new ColorKit(this._themeService.getColorFromTheme("gray.0")).setAlpha(0).toString(),
1591
1613
  widgets: {}
1592
1614
  }
1593
- }, skeleton);
1615
+ };
1616
+ const selectionWithCoord = attachSelectionWithCoord(selectionWithStyle, skeleton);
1594
1617
  const { rowHeaderWidth, columnHeaderHeight } = skeleton;
1595
1618
  const control = new SelectionControl(scene, SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW, this._themeService, {
1596
1619
  highlightHeader: false,
@@ -2639,6 +2662,7 @@ function createHighlightTextRuns(textRuns, leadingCharacterLength) {
2639
2662
  }
2640
2663
  function useColor() {
2641
2664
  const themeService = useDependency(ThemeService);
2665
+ const theme = themeService.getCurrentTheme();
2642
2666
  return useMemo(() => {
2643
2667
  return {
2644
2668
  formulaRefColors: [
@@ -2659,7 +2683,7 @@ function useColor() {
2659
2683
  stringColor: themeService.getColorFromTheme("jiqing.800"),
2660
2684
  plainTextColor: themeService.getColorFromTheme("gray.1000")
2661
2685
  };
2662
- }, [themeService.getCurrentTheme()]);
2686
+ }, [theme]);
2663
2687
  }
2664
2688
  function buildTextRuns(descriptionService, colorMap, sequenceNodes) {
2665
2689
  return buildFormulaTextRuns(descriptionService, colorMap, sequenceNodes);
@@ -3127,7 +3151,8 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
3127
3151
  activeSheet,
3128
3152
  sheetName
3129
3153
  });
3130
- const activeWorkbook = resolveFormulaSelectionWorkbook(useObservable(useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET), [univerInstanceService])), workbook);
3154
+ const currentUnit = useObservable(useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET), [univerInstanceService]));
3155
+ const activeWorkbook = resolveFormulaSelectionWorkbook(currentUnit, workbook);
3131
3156
  const render = renderManagerService.getRenderUnitById((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) ?? unitId);
3132
3157
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
3133
3158
  const sheetSkeletonManagerService = render === null || render === void 0 ? void 0 : render.with(SheetSkeletonManagerService);
@@ -3144,48 +3169,50 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
3144
3169
  });
3145
3170
  if (!ctx) return;
3146
3171
  const { nodeIndex, updatingRefIndex, formulaText, sequenceNodes, offset } = ctx;
3147
- if (isSelectingRef.current === 1 || isFormulaReferenceAddingContext(sequenceNodes, offset) || isFormulaReferenceAddingTextContext(formulaText, offset)) if (offset !== 0) {
3148
- if (nodeIndex === -1 && sequenceNodes.length) return;
3149
- const range = getLastFormulaSelection(selections);
3150
- if (!range) return;
3151
- const lastNodes = sequenceNodes.splice(nodeIndex + 1);
3152
- const rangeSheetId = range.sheetId ?? subUnitId;
3153
- const unitRangeName = {
3154
- range,
3155
- unitId: range.unitId ?? activeWorkbook.getUnitId(),
3156
- sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
3157
- };
3158
- const isAcrossSheet = rangeSheetId !== subUnitId;
3159
- const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
3160
- const refRanges = unitRangesToText([unitRangeName], isSupportAcrossSheet && (isAcrossSheet || isAcrossWorkbook), sheetName, isAcrossWorkbook);
3161
- if (isFormulaReferenceAddingTextContext(formulaText, offset)) {
3162
- handleRangeChange(insertFormulaReferenceText(formulaText, refRanges[0], offset), offset + refRanges[0].length, isEnd);
3163
- return;
3172
+ if (isSelectingRef.current === 1 || isFormulaReferenceAddingContext(sequenceNodes, offset) || isFormulaReferenceAddingTextContext(formulaText, offset)) {
3173
+ if (offset !== 0) {
3174
+ if (nodeIndex === -1 && sequenceNodes.length) return;
3175
+ const range = getLastFormulaSelection(selections);
3176
+ if (!range) return;
3177
+ const lastNodes = sequenceNodes.splice(nodeIndex + 1);
3178
+ const rangeSheetId = range.sheetId ?? subUnitId;
3179
+ const unitRangeName = {
3180
+ range,
3181
+ unitId: range.unitId ?? activeWorkbook.getUnitId(),
3182
+ sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
3183
+ };
3184
+ const isAcrossSheet = rangeSheetId !== subUnitId;
3185
+ const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
3186
+ const refRanges = unitRangesToText([unitRangeName], isSupportAcrossSheet && (isAcrossSheet || isAcrossWorkbook), sheetName, isAcrossWorkbook);
3187
+ if (isFormulaReferenceAddingTextContext(formulaText, offset)) {
3188
+ handleRangeChange(insertFormulaReferenceText(formulaText, refRanges[0], offset), offset + refRanges[0].length, isEnd);
3189
+ return;
3190
+ }
3191
+ sequenceNodes.push({
3192
+ token: refRanges[0],
3193
+ nodeType: sequenceNodeType.REFERENCE
3194
+ });
3195
+ const newSequenceNodes = [...sequenceNodes, ...lastNodes];
3196
+ handleRangeChange(sequenceNodeToText(newSequenceNodes), getOffsetFromSequenceNodes(sequenceNodes), isEnd);
3197
+ } else {
3198
+ const range = getLastFormulaSelection(selections);
3199
+ if (!range) return;
3200
+ const rangeSheetId = range.sheetId ?? subUnitId;
3201
+ const unitRangeName = {
3202
+ range,
3203
+ unitId: range.unitId ?? activeWorkbook.getUnitId(),
3204
+ sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
3205
+ };
3206
+ const isAcrossSheet = rangeSheetId !== subUnitId;
3207
+ const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
3208
+ const refRanges = unitRangesToText([unitRangeName], isSupportAcrossSheet && (isAcrossSheet || isAcrossWorkbook), sheetName, isAcrossWorkbook);
3209
+ sequenceNodes.unshift({
3210
+ token: refRanges[0],
3211
+ nodeType: sequenceNodeType.REFERENCE
3212
+ });
3213
+ handleRangeChange(sequenceNodeToText(sequenceNodes), refRanges[0].length, isEnd);
3164
3214
  }
3165
- sequenceNodes.push({
3166
- token: refRanges[0],
3167
- nodeType: sequenceNodeType.REFERENCE
3168
- });
3169
- handleRangeChange(sequenceNodeToText([...sequenceNodes, ...lastNodes]), getOffsetFromSequenceNodes(sequenceNodes), isEnd);
3170
- } else {
3171
- const range = getLastFormulaSelection(selections);
3172
- if (!range) return;
3173
- const rangeSheetId = range.sheetId ?? subUnitId;
3174
- const unitRangeName = {
3175
- range,
3176
- unitId: range.unitId ?? activeWorkbook.getUnitId(),
3177
- sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
3178
- };
3179
- const isAcrossSheet = rangeSheetId !== subUnitId;
3180
- const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
3181
- const refRanges = unitRangesToText([unitRangeName], isSupportAcrossSheet && (isAcrossSheet || isAcrossWorkbook), sheetName, isAcrossWorkbook);
3182
- sequenceNodes.unshift({
3183
- token: refRanges[0],
3184
- nodeType: sequenceNodeType.REFERENCE
3185
- });
3186
- handleRangeChange(sequenceNodeToText(sequenceNodes), refRanges[0].length, isEnd);
3187
- }
3188
- else if (isSelectingRef.current === 3 || isSelectingRef.current === 4) {
3215
+ } else if (isSelectingRef.current === 3 || isSelectingRef.current === 4) {
3189
3216
  const last = selections.pop();
3190
3217
  if (!last) return;
3191
3218
  const node = sequenceNodes[nodeIndex];
@@ -3444,37 +3471,39 @@ const useSwitchSheet = (isNeed, unitId, isSupportAcrossSheet, isFocusSet, onBlur
3444
3471
  const univerInstanceService = useDependency(IUniverInstanceService);
3445
3472
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
3446
3473
  useEffect(() => {
3447
- if (isNeed && refSelectionsRenderService) if (isSupportAcrossSheet) {
3448
- const handleRefresh = () => {
3449
- const length = refSelectionsRenderService.getSelectionControls().length;
3450
- for (let index = 1; index <= length; index++) refSelectionsRenderService.clearLastSelection();
3451
- return setTimeout(() => {
3452
- refresh();
3453
- }, 30);
3454
- };
3455
- const d = commandService.onCommandExecuted((info) => {
3456
- if (info.id === SetWorksheetActiveOperation.id) handleRefresh();
3457
- });
3458
- const d2 = univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
3459
- handleRefresh();
3460
- });
3461
- return () => {
3462
- d.dispose();
3463
- d2.unsubscribe();
3464
- };
3465
- } else {
3466
- const d = commandService.beforeCommandExecuted((info) => {
3467
- if (info.id === SetWorksheetActiveOperation.id) {
3468
- isFocusSet(false);
3469
- onBlur();
3470
- refresh();
3471
- const editor = editorService.getEditor(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
3472
- editor === null || editor === void 0 || editor.focus();
3473
- }
3474
- });
3475
- return () => {
3476
- d.dispose();
3477
- };
3474
+ if (isNeed && refSelectionsRenderService) {
3475
+ if (isSupportAcrossSheet) {
3476
+ const handleRefresh = () => {
3477
+ const length = refSelectionsRenderService.getSelectionControls().length;
3478
+ for (let index = 1; index <= length; index++) refSelectionsRenderService.clearLastSelection();
3479
+ return setTimeout(() => {
3480
+ refresh();
3481
+ }, 30);
3482
+ };
3483
+ const d = commandService.onCommandExecuted((info) => {
3484
+ if (info.id === SetWorksheetActiveOperation.id) handleRefresh();
3485
+ });
3486
+ const d2 = univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
3487
+ handleRefresh();
3488
+ });
3489
+ return () => {
3490
+ d.dispose();
3491
+ d2.unsubscribe();
3492
+ };
3493
+ } else {
3494
+ const d = commandService.beforeCommandExecuted((info) => {
3495
+ if (info.id === SetWorksheetActiveOperation.id) {
3496
+ isFocusSet(false);
3497
+ onBlur();
3498
+ refresh();
3499
+ const editor = editorService.getEditor(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
3500
+ editor === null || editor === void 0 || editor.focus();
3501
+ }
3502
+ });
3503
+ return () => {
3504
+ d.dispose();
3505
+ };
3506
+ }
3478
3507
  }
3479
3508
  }, [isNeed, refSelectionsRenderService]);
3480
3509
  };
@@ -3587,12 +3616,23 @@ function MobileFunctionPanel(props) {
3587
3616
  const [category, setCategory] = useState("recommended");
3588
3617
  const [details, setDetails] = useState(null);
3589
3618
  const [recentVersion, setRecentVersion] = useState(0);
3619
+ const panelRef = useRef(null);
3590
3620
  useEffect(() => {
3591
3621
  if (!open) return;
3592
3622
  setQuery("");
3593
3623
  setCategory("recommended");
3594
3624
  setDetails(null);
3595
3625
  }, [open]);
3626
+ useLayoutEffect(() => {
3627
+ if (!open) return void 0;
3628
+ const focusPanel = () => {
3629
+ var _panelRef$current;
3630
+ return (_panelRef$current = panelRef.current) === null || _panelRef$current === void 0 ? void 0 : _panelRef$current.focus({ preventScroll: true });
3631
+ };
3632
+ focusPanel();
3633
+ const focusFrame = requestAnimationFrame(focusPanel);
3634
+ return () => cancelAnimationFrame(focusFrame);
3635
+ }, [open]);
3596
3636
  const categories = useMemo(() => {
3597
3637
  if (!open) return [];
3598
3638
  return [
@@ -3651,8 +3691,10 @@ function MobileFunctionPanel(props) {
3651
3691
  className: "univer-fixed univer-inset-0 univer-z-[1200] univer-bg-black/20",
3652
3692
  onPointerDown: (event) => event.stopPropagation(),
3653
3693
  children: /* @__PURE__ */ jsxs("section", {
3694
+ ref: panelRef,
3654
3695
  role: "dialog",
3655
3696
  "aria-label": copy.title,
3697
+ tabIndex: -1,
3656
3698
  className: "univer-absolute univer-inset-x-0 univer-bottom-0 univer-flex univer-h-[80vh] univer-flex-col univer-overflow-hidden univer-rounded-t-2xl univer-bg-gray-0 univer-shadow-lg dark:!univer-bg-gray-900",
3657
3699
  children: [
3658
3700
  /* @__PURE__ */ jsx("div", {
@@ -3994,7 +4036,6 @@ function MobileSearchFunctionFactory(props, ref) {
3994
4036
  case KeyCode.ESC:
3995
4037
  resetFormulaSearch();
3996
4038
  onClose();
3997
- break;
3998
4039
  }
3999
4040
  };
4000
4041
  d.add(commandService.registerCommand({
@@ -4179,7 +4220,8 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4179
4220
  const renderer = useDependency(IRenderManagerService).getRenderUnitById(editorId);
4180
4221
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocSelectionRenderService);
4181
4222
  const isFocusing = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing;
4182
- const currentDoc = useObservable(useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC), [univerInstanceService]));
4223
+ const currentDoc$ = useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC), [univerInstanceService]);
4224
+ const currentDoc = useObservable(currentDoc$);
4183
4225
  const docFocusing = (currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId()) === editorId;
4184
4226
  const refSelectionsRef = useRef([]);
4185
4227
  const getRefSelections = useEvent(() => refSelectionsRef.current);
@@ -4199,7 +4241,8 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4199
4241
  queueMicrotask(() => {
4200
4242
  var _editor$getSelectionR, _editor$getDocumentDa;
4201
4243
  const selection = (_editor$getSelectionR = editor.getSelectionRanges()) === null || _editor$getSelectionR === void 0 ? void 0 : _editor$getSelectionR[0];
4202
- const normalizedSelection = getSelectionAfterLaggingFormulaInput(((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "", selection, content);
4244
+ const dataStream = ((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "";
4245
+ const normalizedSelection = getSelectionAfterLaggingFormulaInput(dataStream, selection, content);
4203
4246
  if (!normalizedSelection) return;
4204
4247
  const selections = [normalizedSelection];
4205
4248
  editor.setSelectionRanges(selections, false);
@@ -4219,10 +4262,10 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4219
4262
  handledMobileFunctionPanelRequestRef.current = mobileFunctionPanelRequest;
4220
4263
  contextService.setContextValue(MOBILE_FORMULA_FUNCTION_PANEL_OPEN, true);
4221
4264
  setMobileFunctionPanelOpen(true);
4222
- editor === null || editor === void 0 || editor.blur();
4265
+ editorService.blur();
4223
4266
  }, [
4224
4267
  contextService,
4225
- editor,
4268
+ editorService,
4226
4269
  mobileFunctionPanelRequest
4227
4270
  ]);
4228
4271
  useEffect(() => () => {
@@ -4240,7 +4283,9 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4240
4283
  if (isEnd) {
4241
4284
  const currentDocSelections = newSelections ?? (editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges());
4242
4285
  if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) {
4243
- const refIndex = findRefSequenceIndex(sequenceNodes, findIndexFromSequenceNodes(sequenceNodes, currentDocSelections[0].startOffset - 1, false));
4286
+ const offset = currentDocSelections[0].startOffset - 1;
4287
+ const nodeIndex = findIndexFromSequenceNodes(sequenceNodes, offset, false);
4288
+ const refIndex = findRefSequenceIndex(sequenceNodes, nodeIndex);
4244
4289
  if (refIndex >= 0) {
4245
4290
  const target = ranges.splice(refIndex, 1)[0];
4246
4291
  target && ranges.push(target);
@@ -4264,7 +4309,7 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4264
4309
  useEffect(() => {
4265
4310
  onFormulaSelectingChange(isSelecting, (docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) ?? true);
4266
4311
  }, [onFormulaSelectingChange, isSelecting]);
4267
- useKeyboardEvent(isFocus, useMemo(() => createEditorUndoRedoKeyboardConfig({
4312
+ const resolvedKeyboardEventConfig = useMemo(() => createEditorUndoRedoKeyboardConfig({
4268
4313
  commandService,
4269
4314
  univerInstanceService,
4270
4315
  editorUnitId: editorId,
@@ -4275,7 +4320,8 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4275
4320
  editorId,
4276
4321
  keyboardEventConfig,
4277
4322
  univerInstanceService
4278
- ]), editor);
4323
+ ]);
4324
+ useKeyboardEvent(isFocus, resolvedKeyboardEventConfig, editor);
4279
4325
  useLayoutEffect(() => {
4280
4326
  let dispose;
4281
4327
  if (formulaEditorContainerRef.current) {
@@ -4360,6 +4406,10 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4360
4406
  useLayoutEffect(() => {
4361
4407
  let focusRetryFrame = 0;
4362
4408
  let finalFocusRetryFrame = 0;
4409
+ if (mobileFunctionPanelOpen) {
4410
+ editor === null || editor === void 0 || editor.blur();
4411
+ return;
4412
+ }
4363
4413
  const retryFocus = () => {
4364
4414
  if (_isFocus && !(docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing)) focus();
4365
4415
  };
@@ -4386,6 +4436,7 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4386
4436
  docSelectionRenderService,
4387
4437
  editor,
4388
4438
  focus,
4439
+ mobileFunctionPanelOpen,
4389
4440
  resetSelection,
4390
4441
  resetSelectionOnBlur
4391
4442
  ]);
@@ -4446,6 +4497,7 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4446
4497
  const closeMobileFunctionPanel = () => {
4447
4498
  setMobileFunctionPanelOpen(false);
4448
4499
  requestAnimationFrame(() => {
4500
+ setIsFocus(true);
4449
4501
  focus();
4450
4502
  contextService.setContextValue(MOBILE_FORMULA_FUNCTION_PANEL_OPEN, false);
4451
4503
  });
@@ -4484,6 +4536,7 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4484
4536
  var _editor$getDocumentDa3, _editor$getSelectionR3;
4485
4537
  if (!editor) return;
4486
4538
  const result = buildFormulaFunctionInsertion(BuildTextUtils.transform.getPlainText(((_editor$getDocumentDa3 = editor.getDocumentData().body) === null || _editor$getDocumentDa3 === void 0 ? void 0 : _editor$getDocumentDa3.dataStream) ?? ""), (_editor$getSelectionR3 = editor.getSelectionRanges()) === null || _editor$getSelectionR3 === void 0 ? void 0 : _editor$getSelectionR3[0], functionName);
4539
+ setIsFocus(true);
4487
4540
  applyMobileInsertion(result);
4488
4541
  setMobileFunctionPanelOpen(false);
4489
4542
  requestAnimationFrame(() => {
@@ -4620,14 +4673,22 @@ function SelectFunction(props) {
4620
4673
  const { onChange, SelectComponent = Select } = props;
4621
4674
  const allTypeValue = "-1";
4622
4675
  const [searchText, setSearchText] = useState("");
4623
- const [selectList, setSelectList] = useState([]);
4624
4676
  const [active, setActive] = useState(0);
4625
4677
  const [typeSelected, setTypeSelected] = useState(allTypeValue);
4626
4678
  const [nameSelected, setNameSelected] = useState(0);
4627
- const [functionInfo, setFunctionInfo] = useState(null);
4628
4679
  const descriptionService = useDependency(IDescriptionService);
4629
4680
  const localeService = useDependency(LocaleService);
4630
- const sidebarOptions = useObservable(useDependency(ISidebarService).sidebarOptions$);
4681
+ const sidebarService = useDependency(ISidebarService);
4682
+ const selectList = useMemo(() => {
4683
+ const query = searchText.trim().toUpperCase();
4684
+ return descriptionService.getSearchListByType(Number(typeSelected)).filter(({ name }) => name.toUpperCase().includes(query));
4685
+ }, [
4686
+ descriptionService,
4687
+ searchText,
4688
+ typeSelected
4689
+ ]);
4690
+ const selectedItem = selectList[nameSelected];
4691
+ const functionInfo = selectedItem ? descriptionService.getFunctionInfo(selectedItem.name) ?? null : null;
4631
4692
  const options = getFunctionTypeValues(localeService, Boolean(customFunction)).filter((option) => descriptionService.getSearchListByType(Number(option.value)).length > 0);
4632
4693
  options.unshift({
4633
4694
  label: localeService.t("sheets-formula-ui.moreFunctions.allFunctions"),
@@ -4636,25 +4697,23 @@ function SelectFunction(props) {
4636
4697
  const required = localeService.t("sheets-formula-ui.prompt.required");
4637
4698
  const optional = localeService.t("sheets-formula-ui.prompt.optional");
4638
4699
  useEffect(() => {
4639
- handleSelectChange(allTypeValue);
4640
- }, []);
4641
- useEffect(() => {
4642
- setCurrentFunctionInfo(0);
4643
- }, [selectList]);
4700
+ onChange(functionInfo);
4701
+ }, [functionInfo, onChange]);
4644
4702
  useEffect(() => {
4645
- if (sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.visible) {
4646
- setSearchText("");
4647
- setSelectList([]);
4648
- setActive(0);
4649
- setTypeSelected(allTypeValue);
4650
- setNameSelected(0);
4651
- setFunctionInfo(null);
4652
- handleSelectChange(allTypeValue);
4653
- }
4654
- }, [sidebarOptions]);
4703
+ const subscription = sidebarService.sidebarOptions$.subscribe((options) => {
4704
+ if (options.visible) {
4705
+ setSearchText("");
4706
+ setTypeSelected(allTypeValue);
4707
+ setActive(0);
4708
+ setNameSelected(0);
4709
+ }
4710
+ });
4711
+ return () => subscription.unsubscribe();
4712
+ }, [sidebarService]);
4655
4713
  const highlightSearchText = (text) => {
4656
- if (searchText.trim() === "") return text;
4657
- const regex = new RegExp(`(${searchText.toLocaleUpperCase()})`);
4714
+ const query = searchText.trim().toUpperCase();
4715
+ if (query === "") return text;
4716
+ const regex = new RegExp(`(${regexp.escapeRegExp(query)})`, "i");
4658
4717
  return text.split(regex).filter(Boolean).map((part, index) => {
4659
4718
  if (part.match(regex)) return /* @__PURE__ */ jsx("span", {
4660
4719
  className: "univer-text-red-500",
@@ -4663,34 +4722,22 @@ function SelectFunction(props) {
4663
4722
  return part;
4664
4723
  });
4665
4724
  };
4666
- const setCurrentFunctionInfo = (selectedIndex) => {
4667
- if (selectList.length === 0) {
4668
- setFunctionInfo(null);
4669
- onChange(null);
4670
- return;
4671
- }
4672
- setNameSelected(selectedIndex);
4673
- const functionInfo = descriptionService.getFunctionInfo(selectList[selectedIndex].name);
4674
- if (!functionInfo) {
4675
- setFunctionInfo(null);
4676
- onChange(null);
4677
- return;
4678
- }
4679
- setFunctionInfo(functionInfo);
4680
- onChange(functionInfo);
4681
- };
4725
+ function setCurrentFunctionInfo(selectedIndex) {
4726
+ if (selectList[selectedIndex]) setNameSelected(selectedIndex);
4727
+ }
4682
4728
  function handleSelectChange(value) {
4683
4729
  setTypeSelected(value);
4684
- const selectList = descriptionService.getSearchListByType(+value);
4685
- setSelectList(selectList);
4730
+ setActive(0);
4731
+ setNameSelected(0);
4686
4732
  }
4687
4733
  function handleSearchInputChange(value) {
4688
4734
  setSearchText(value);
4689
- const selectList = descriptionService.getSearchListByName(value);
4690
- setSelectList(selectList);
4735
+ setActive(0);
4736
+ setNameSelected(0);
4691
4737
  }
4692
4738
  function handleSelectListKeyDown(e) {
4693
4739
  e.stopPropagation();
4740
+ if (selectList.length === 0) return;
4694
4741
  if (e.key === "ArrowDown") {
4695
4742
  const nextActive = active + 1;
4696
4743
  setActive(nextActive === selectList.length ? 0 : nextActive);
@@ -4734,7 +4781,7 @@ function SelectFunction(props) {
4734
4781
  className: "univer-block",
4735
4782
  children: highlightSearchText(name)
4736
4783
  })]
4737
- }, index))
4784
+ }, name))
4738
4785
  }),
4739
4786
  functionInfo && /* @__PURE__ */ jsxs("div", {
4740
4787
  "data-u-comp": "formula-function-details",
@@ -5634,14 +5681,17 @@ MobileComponentsController = __decorate([__decorateParam(0, Inject(ComponentMana
5634
5681
  function FormulaProgressBar() {
5635
5682
  const triggerCalculationController = useDependency(TriggerCalculationController);
5636
5683
  const commandService = useDependency(ICommandService);
5684
+ const progress = useObservable(triggerCalculationController.progress$);
5685
+ const terminateCalculation = useCallback(() => {
5686
+ commandService.executeCommand(SetFormulaCalculationStopMutation.id);
5687
+ }, [commandService]);
5688
+ const clearProgress = useCallback(() => {
5689
+ triggerCalculationController.clearProgress();
5690
+ }, [triggerCalculationController]);
5637
5691
  return /* @__PURE__ */ jsx(ProgressBar, {
5638
- progress: useObservable(triggerCalculationController.progress$),
5639
- onTerminate: useCallback(() => {
5640
- commandService.executeCommand(SetFormulaCalculationStopMutation.id);
5641
- }, [commandService]),
5642
- onClearProgress: useCallback(() => {
5643
- triggerCalculationController.clearProgress();
5644
- }, [triggerCalculationController])
5692
+ progress,
5693
+ onTerminate: terminateCalculation,
5694
+ onClearProgress: clearProgress
5645
5695
  });
5646
5696
  }
5647
5697
 
@@ -5669,10 +5719,9 @@ const QuickSumShortcut = {
5669
5719
  //#endregion
5670
5720
  //#region src/controllers/ui.controller.ts
5671
5721
  let FormulaUIController = class FormulaUIController extends Disposable {
5672
- constructor(_injector, _menuManagerService, _commandService, _shortcutService, _uiPartsService, _renderManagerService) {
5722
+ constructor(_injector, _commandService, _shortcutService, _uiPartsService, _renderManagerService) {
5673
5723
  super();
5674
5724
  this._injector = _injector;
5675
- this._menuManagerService = _menuManagerService;
5676
5725
  this._commandService = _commandService;
5677
5726
  this._shortcutService = _shortcutService;
5678
5727
  this._uiPartsService = _uiPartsService;
@@ -5681,14 +5730,10 @@ let FormulaUIController = class FormulaUIController extends Disposable {
5681
5730
  }
5682
5731
  _initialize() {
5683
5732
  this._registerCommands();
5684
- this._registerMenus();
5685
5733
  this._registerShortcuts();
5686
5734
  this._registerComponents();
5687
5735
  this._registerRenderModules();
5688
5736
  }
5689
- _registerMenus() {
5690
- this._menuManagerService.mergeMenu(menuSchema);
5691
- }
5692
5737
  _registerCommands() {
5693
5738
  [
5694
5739
  SheetCopyFormulaOnlyCommand,
@@ -5714,13 +5759,100 @@ let FormulaUIController = class FormulaUIController extends Disposable {
5714
5759
  };
5715
5760
  FormulaUIController = __decorate([
5716
5761
  __decorateParam(0, Inject(Injector)),
5717
- __decorateParam(1, IMenuManagerService),
5718
- __decorateParam(2, ICommandService),
5719
- __decorateParam(3, IShortcutService),
5720
- __decorateParam(4, IUIPartsService),
5721
- __decorateParam(5, IRenderManagerService)
5762
+ __decorateParam(1, ICommandService),
5763
+ __decorateParam(2, IShortcutService),
5764
+ __decorateParam(3, IUIPartsService),
5765
+ __decorateParam(4, IRenderManagerService)
5722
5766
  ], FormulaUIController);
5723
5767
 
5768
+ //#endregion
5769
+ //#region src/menu/mobile-schema.ts
5770
+ const mobileMenuSchema = {
5771
+ [RibbonFormulasGroup.BASIC]: {
5772
+ [`${InsertFunctionOperation.id}.common`]: {
5773
+ order: 0,
5774
+ menuItemFactory: InsertCommonFunctionMenuItemFactory,
5775
+ [MoreFunctionsOperation.id]: {
5776
+ order: 0,
5777
+ menuItemFactory: AllFunctionsMenuItemFactory
5778
+ }
5779
+ },
5780
+ [`${InsertFunctionOperation.id}.financial`]: {
5781
+ order: 1,
5782
+ menuItemFactory: InsertFinancialFunctionMenuItemFactory
5783
+ },
5784
+ [`${InsertFunctionOperation.id}.logical`]: {
5785
+ order: 2,
5786
+ menuItemFactory: InsertLogicalFunctionMenuItemFactory
5787
+ },
5788
+ [`${InsertFunctionOperation.id}.text`]: {
5789
+ order: 3,
5790
+ menuItemFactory: InsertTextFunctionMenuItemFactory
5791
+ },
5792
+ [`${InsertFunctionOperation.id}.date`]: {
5793
+ order: 4,
5794
+ menuItemFactory: InsertDateFunctionMenuItemFactory
5795
+ },
5796
+ [`${InsertFunctionOperation.id}.lookup`]: {
5797
+ order: 5,
5798
+ menuItemFactory: InsertLookupFunctionMenuItemFactory
5799
+ },
5800
+ [`${InsertFunctionOperation.id}.math`]: {
5801
+ order: 6,
5802
+ menuItemFactory: InsertMathFunctionMenuItemFactory
5803
+ },
5804
+ [`${InsertFunctionOperation.id}.statistical`]: {
5805
+ order: 7,
5806
+ menuItemFactory: InsertStatisticalFunctionMenuItemFactory
5807
+ },
5808
+ [`${InsertFunctionOperation.id}.engineering`]: {
5809
+ order: 8,
5810
+ menuItemFactory: InsertEngineeringFunctionMenuItemFactory
5811
+ },
5812
+ [`${InsertFunctionOperation.id}.information`]: {
5813
+ order: 9,
5814
+ menuItemFactory: InsertInformationFunctionMenuItemFactory
5815
+ },
5816
+ [`${InsertFunctionOperation.id}.database`]: {
5817
+ order: 10,
5818
+ menuItemFactory: InsertDatabaseFunctionMenuItemFactory
5819
+ }
5820
+ },
5821
+ [COPY_SPECIAL_MENU_ID]: { [SheetCopyFormulaOnlyCommand.id]: {
5822
+ order: 0,
5823
+ menuItemFactory: CopyFormulaOnlyMenuItemFactory
5824
+ } },
5825
+ [PASTE_SPECIAL_MENU_ID]: { [SheetOnlyPasteFormulaCommand.id]: {
5826
+ order: 4,
5827
+ menuItemFactory: PasteFormulaMenuItemFactory
5828
+ } }
5829
+ };
5830
+
5831
+ //#endregion
5832
+ //#region src/menu/mobile-formula-menu.controller.ts
5833
+ /**
5834
+ * Copyright 2023-present DreamNum Co., Ltd.
5835
+ *
5836
+ * Licensed under the Apache License, Version 2.0 (the "License");
5837
+ * you may not use this file except in compliance with the License.
5838
+ * You may obtain a copy of the License at
5839
+ *
5840
+ * http://www.apache.org/licenses/LICENSE-2.0
5841
+ *
5842
+ * Unless required by applicable law or agreed to in writing, software
5843
+ * distributed under the License is distributed on an "AS IS" BASIS,
5844
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5845
+ * See the License for the specific language governing permissions and
5846
+ * limitations under the License.
5847
+ */
5848
+ let MobileFormulaMenuController = class MobileFormulaMenuController extends Disposable {
5849
+ constructor(menuManagerService) {
5850
+ super();
5851
+ menuManagerService.mergeMenu(mobileMenuSchema);
5852
+ }
5853
+ };
5854
+ MobileFormulaMenuController = __decorate([__decorateParam(0, IMenuManagerService)], MobileFormulaMenuController);
5855
+
5724
5856
  //#endregion
5725
5857
  //#region src/services/range-selector.service.ts
5726
5858
  var GlobalRangeSelectorService = class {
@@ -5843,7 +5975,8 @@ let MobileRefSelectionsRenderService = class MobileRefSelectionsRenderService ex
5843
5975
  columnHeaderOffsetY: Math.max(0, columnHeaderHeightAndMarginTop - columnHeaderHeight),
5844
5976
  rangeType
5845
5977
  });
5846
- const selectionWithCoord = attachSelectionWithCoord(this._withMobileSelectionStyle(selection), skeleton);
5978
+ const selectionWithMobileStyle = this._withMobileSelectionStyle(selection);
5979
+ const selectionWithCoord = attachSelectionWithCoord(selectionWithMobileStyle, skeleton);
5847
5980
  control.updateRangeBySelectionWithCoord(selectionWithCoord, skeleton);
5848
5981
  control.setEvent(false);
5849
5982
  [
@@ -5963,7 +6096,8 @@ MobileRefSelectionsRenderService = __decorate([
5963
6096
  //#endregion
5964
6097
  //#region src/views/range-selector/MobileGlobal.tsx
5965
6098
  function MobileGlobalRangeSelector() {
5966
- const current = useObservable(useDependency(GlobalRangeSelectorService).currentSelector$);
6099
+ const rangeSelectorService = useDependency(GlobalRangeSelectorService);
6100
+ const current = useObservable(rangeSelectorService.currentSelector$);
5967
6101
  const instanceRef = useRef(null);
5968
6102
  useEffect(() => {
5969
6103
  if (current) {
@@ -6008,6 +6142,7 @@ let UniverSheetsFormulaMobileUIPlugin = class UniverSheetsFormulaMobileUIPlugin
6008
6142
  [IFormulaPromptService, { useClass: FormulaPromptService }],
6009
6143
  [GlobalRangeSelectorService],
6010
6144
  [FormulaUIController],
6145
+ [MobileFormulaMenuController],
6011
6146
  [FormulaClipboardController],
6012
6147
  [FormulaEditorShowController],
6013
6148
  [FormulaRenderManagerController],
@@ -6027,6 +6162,7 @@ let UniverSheetsFormulaMobileUIPlugin = class UniverSheetsFormulaMobileUIPlugin
6027
6162
  });
6028
6163
  touchDependencies(this._injector, [
6029
6164
  [FormulaUIController],
6165
+ [MobileFormulaMenuController],
6030
6166
  [FormulaClipboardController],
6031
6167
  [FormulaRenderManagerController],
6032
6168
  [ImageFormulaRenderController]
@@ -6082,19 +6218,21 @@ const useFormulaDescribe = (isNeed, formulaText, editor) => {
6082
6218
  const nodeIndex = formulaPromptService.getCurrentSequenceNodeIndex(startOffset - 2);
6083
6219
  const currentSequenceNode = formulaPromptService.getCurrentSequenceNodeByIndex(nodeIndex);
6084
6220
  const nextSequenceNode = formulaPromptService.getCurrentSequenceNodeByIndex(nodeIndex + 1);
6085
- if (currentSequenceNode) if (typeof currentSequenceNode !== "string" && currentSequenceNode.nodeType === 3 && !descriptionService.hasDefinedNameDescription(currentSequenceNode.token.trim()) && nextSequenceNode === matchToken.OPEN_BRACKET) {
6086
- const info = descriptionService.getFunctionInfo(currentSequenceNode.token);
6087
- setFunctionInfo(info);
6088
- setParamIndex(-1);
6089
- return;
6090
- } else {
6091
- const res = lexerTreeBuilder.getFunctionAndParameter(`${formulaTextRef.current}A`, startOffset - 1);
6092
- if (res) {
6093
- const { functionName, paramIndex } = res;
6094
- const info = descriptionService.getFunctionInfo(functionName);
6221
+ if (currentSequenceNode) {
6222
+ if (typeof currentSequenceNode !== "string" && currentSequenceNode.nodeType === 3 && !descriptionService.hasDefinedNameDescription(currentSequenceNode.token.trim()) && nextSequenceNode === matchToken.OPEN_BRACKET) {
6223
+ const info = descriptionService.getFunctionInfo(currentSequenceNode.token);
6095
6224
  setFunctionInfo(info);
6096
- setParamIndex(paramIndex);
6225
+ setParamIndex(-1);
6097
6226
  return;
6227
+ } else {
6228
+ const res = lexerTreeBuilder.getFunctionAndParameter(`${formulaTextRef.current}A`, startOffset - 1);
6229
+ if (res) {
6230
+ const { functionName, paramIndex } = res;
6231
+ const info = descriptionService.getFunctionInfo(functionName);
6232
+ setFunctionInfo(info);
6233
+ setParamIndex(paramIndex);
6234
+ return;
6235
+ }
6098
6236
  }
6099
6237
  }
6100
6238
  }
@@ -6181,7 +6319,8 @@ function HelpFunction(props) {
6181
6319
  const localeService = useDependency(LocaleService);
6182
6320
  const required = localeService.t("sheets-formula-ui.prompt.required");
6183
6321
  const optional = localeService.t("sheets-formula-ui.prompt.optional");
6184
- const [position$] = useEditorPosition(editor.getEditorId(), !!functionInfo, [functionInfo, paramIndex]);
6322
+ const editorId = editor.getEditorId();
6323
+ const [position$] = useEditorPosition(editorId, !!functionInfo, [functionInfo, paramIndex]);
6185
6324
  function handleSwitchActive(paramIndex) {
6186
6325
  onParamsSwitch && onParamsSwitch(paramIndex);
6187
6326
  }
@@ -6317,7 +6456,6 @@ function SearchFunctionFactory(props, ref) {
6317
6456
  case KeyCode.ESC:
6318
6457
  resetFormulaSearch();
6319
6458
  onClose();
6320
- break;
6321
6459
  }
6322
6460
  };
6323
6461
  d.add(commandService.registerCommand({
@@ -6469,7 +6607,8 @@ const FormulaEditor = forwardRef((props, ref) => {
6469
6607
  const renderer = useDependency(IRenderManagerService).getRenderUnitById(editorId);
6470
6608
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocSelectionRenderService);
6471
6609
  const isFocusing = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing;
6472
- const currentDoc = useObservable(useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC), [univerInstanceService]));
6610
+ const currentDoc$ = useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC), [univerInstanceService]);
6611
+ const currentDoc = useObservable(currentDoc$);
6473
6612
  const docFocusing = (currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId()) === editorId;
6474
6613
  const refSelectionsRef = useRef([]);
6475
6614
  const getRefSelections = useEvent(() => refSelectionsRef.current);
@@ -6486,7 +6625,8 @@ const FormulaEditor = forwardRef((props, ref) => {
6486
6625
  queueMicrotask(() => {
6487
6626
  var _editor$getSelectionR, _editor$getDocumentDa;
6488
6627
  const selection = (_editor$getSelectionR = editor.getSelectionRanges()) === null || _editor$getSelectionR === void 0 ? void 0 : _editor$getSelectionR[0];
6489
- const normalizedSelection = getSelectionAfterLaggingFormulaInput(((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "", selection, content);
6628
+ const dataStream = ((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "";
6629
+ const normalizedSelection = getSelectionAfterLaggingFormulaInput(dataStream, selection, content);
6490
6630
  if (!normalizedSelection) return;
6491
6631
  const selections = [normalizedSelection];
6492
6632
  editor.setSelectionRanges(selections, false);
@@ -6512,7 +6652,9 @@ const FormulaEditor = forwardRef((props, ref) => {
6512
6652
  if (isEnd) {
6513
6653
  const currentDocSelections = newSelections ?? (editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges());
6514
6654
  if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) {
6515
- const refIndex = findRefSequenceIndex(sequenceNodes, findIndexFromSequenceNodes(sequenceNodes, currentDocSelections[0].startOffset - 1, false));
6655
+ const offset = currentDocSelections[0].startOffset - 1;
6656
+ const nodeIndex = findIndexFromSequenceNodes(sequenceNodes, offset, false);
6657
+ const refIndex = findRefSequenceIndex(sequenceNodes, nodeIndex);
6516
6658
  if (refIndex >= 0) {
6517
6659
  const target = ranges.splice(refIndex, 1)[0];
6518
6660
  target && ranges.push(target);
@@ -6536,7 +6678,7 @@ const FormulaEditor = forwardRef((props, ref) => {
6536
6678
  useEffect(() => {
6537
6679
  onFormulaSelectingChange(isSelecting, (docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) ?? true);
6538
6680
  }, [onFormulaSelectingChange, isSelecting]);
6539
- useKeyboardEvent(isFocus, useMemo(() => createEditorUndoRedoKeyboardConfig({
6681
+ const resolvedKeyboardEventConfig = useMemo(() => createEditorUndoRedoKeyboardConfig({
6540
6682
  commandService,
6541
6683
  univerInstanceService,
6542
6684
  editorUnitId: editorId,
@@ -6547,7 +6689,8 @@ const FormulaEditor = forwardRef((props, ref) => {
6547
6689
  editorId,
6548
6690
  keyboardEventConfig,
6549
6691
  univerInstanceService
6550
- ]), editor);
6692
+ ]);
6693
+ useKeyboardEvent(isFocus, resolvedKeyboardEventConfig, editor);
6551
6694
  useLayoutEffect(() => {
6552
6695
  let dispose;
6553
6696
  if (formulaEditorContainerRef.current) {
@@ -6815,10 +6958,36 @@ let ComponentsController = class ComponentsController extends Disposable {
6815
6958
  };
6816
6959
  ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
6817
6960
 
6961
+ //#endregion
6962
+ //#region src/menu/formula-menu.controller.ts
6963
+ /**
6964
+ * Copyright 2023-present DreamNum Co., Ltd.
6965
+ *
6966
+ * Licensed under the Apache License, Version 2.0 (the "License");
6967
+ * you may not use this file except in compliance with the License.
6968
+ * You may obtain a copy of the License at
6969
+ *
6970
+ * http://www.apache.org/licenses/LICENSE-2.0
6971
+ *
6972
+ * Unless required by applicable law or agreed to in writing, software
6973
+ * distributed under the License is distributed on an "AS IS" BASIS,
6974
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6975
+ * See the License for the specific language governing permissions and
6976
+ * limitations under the License.
6977
+ */
6978
+ let FormulaMenuController = class FormulaMenuController extends Disposable {
6979
+ constructor(menuManagerService) {
6980
+ super();
6981
+ menuManagerService.mergeMenu(menuSchema);
6982
+ }
6983
+ };
6984
+ FormulaMenuController = __decorate([__decorateParam(0, IMenuManagerService)], FormulaMenuController);
6985
+
6818
6986
  //#endregion
6819
6987
  //#region src/views/range-selector/Global.tsx
6820
6988
  const GlobalRangeSelector = () => {
6821
- const current = useObservable(useDependency(GlobalRangeSelectorService).currentSelector$);
6989
+ const rangeSelectorService = useDependency(GlobalRangeSelectorService);
6990
+ const current = useObservable(rangeSelectorService.currentSelector$);
6822
6991
  const instance = useRef(null);
6823
6992
  useEffect(() => {
6824
6993
  if (current) {
@@ -6864,6 +7033,7 @@ let UniverSheetsFormulaUIPlugin = class UniverSheetsFormulaUIPlugin extends Plug
6864
7033
  [IFormulaPromptService, { useClass: FormulaPromptService }],
6865
7034
  [GlobalRangeSelectorService],
6866
7035
  [FormulaUIController],
7036
+ [FormulaMenuController],
6867
7037
  [FormulaClipboardController],
6868
7038
  [FormulaEditorShowController],
6869
7039
  [FormulaRenderManagerController],
@@ -6883,6 +7053,7 @@ let UniverSheetsFormulaUIPlugin = class UniverSheetsFormulaUIPlugin extends Plug
6883
7053
  });
6884
7054
  touchDependencies(this._injector, [
6885
7055
  [FormulaUIController],
7056
+ [FormulaMenuController],
6886
7057
  [FormulaClipboardController],
6887
7058
  [FormulaRenderManagerController],
6888
7059
  [ImageFormulaRenderController]