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