@univerjs/sheets-formula-ui 1.0.0-alpha.5 → 1.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -9,10 +9,12 @@ let _univerjs_sheets = require("@univerjs/sheets");
9
9
  let _univerjs_sheets_formula = require("@univerjs/sheets-formula");
10
10
  let _univerjs_ui = require("@univerjs/ui");
11
11
  let _univerjs_docs = require("@univerjs/docs");
12
+ let _univerjs_formula = require("@univerjs/formula");
12
13
  let _univerjs_icons = require("@univerjs/icons");
13
14
  let _univerjs_design = require("@univerjs/design");
14
15
  let react = require("react");
15
16
  let react_jsx_runtime = require("react/jsx-runtime");
17
+ let _univerjs_formula_ui = require("@univerjs/formula-ui");
16
18
  let rxjs_operators = require("rxjs/operators");
17
19
 
18
20
  //#region src/commands/commands/formula-clipboard.command.ts
@@ -696,6 +698,30 @@ const SearchFunctionOperation = {
696
698
  }
697
699
  };
698
700
 
701
+ //#endregion
702
+ //#region src/common/selection.ts
703
+ function genFormulaRefSelectionStyle(themeService, refColor, id) {
704
+ return {
705
+ id,
706
+ strokeWidth: 1,
707
+ stroke: refColor,
708
+ fill: new _univerjs_core.ColorKit(refColor).setAlpha(.05).toRgbString(),
709
+ widgets: {
710
+ tl: true,
711
+ tc: true,
712
+ tr: true,
713
+ ml: true,
714
+ mr: true,
715
+ bl: true,
716
+ bc: true,
717
+ br: true
718
+ },
719
+ widgetSize: 6,
720
+ widgetStrokeWidth: 1,
721
+ widgetStroke: themeService.getColorFromTheme("white")
722
+ };
723
+ }
724
+
699
725
  //#endregion
700
726
  //#region src/controllers/formula-reorder.controller.ts
701
727
  let FormulaReorderController = class FormulaReorderController extends _univerjs_core.Disposable {
@@ -798,7 +824,7 @@ function InsertCommonFunctionMenuItemFactory(accessor) {
798
824
  value: name
799
825
  }));
800
826
  try {
801
- const descriptionService = accessor.get(_univerjs_sheets_formula.IDescriptionService);
827
+ const descriptionService = accessor.get(_univerjs_formula.IDescriptionService);
802
828
  const filtered = commonFunctions.filter((name) => Boolean(descriptionService.getFunctionInfo(name)));
803
829
  if (filtered.length > 0) selections = filtered.map((name) => ({
804
830
  label: {
@@ -823,7 +849,7 @@ function createInsertFunctionCategoryMenuItemFactory(functionType, categoryKey,
823
849
  return function insertFunctionCategoryMenuItemFactory(accessor) {
824
850
  let selections = [];
825
851
  try {
826
- selections = accessor.get(_univerjs_sheets_formula.IDescriptionService).getSearchListByType(functionType).map(({ name }) => ({
852
+ selections = accessor.get(_univerjs_formula.IDescriptionService).getSearchListByType(functionType).map(({ name }) => ({
827
853
  label: {
828
854
  name,
829
855
  selectable: false
@@ -903,6 +929,12 @@ const menuSchema = {
903
929
  [_univerjs_ui.RibbonFormulasGroup.BASIC]: {
904
930
  [`${InsertFunctionOperation.id}.common`]: {
905
931
  order: 0,
932
+ gridLayout: {
933
+ row: 1,
934
+ column: 1,
935
+ rowSpan: 2,
936
+ showLabel: false
937
+ },
906
938
  menuItemFactory: InsertCommonFunctionMenuItemFactory,
907
939
  [MoreFunctionsOperation.id]: {
908
940
  order: 0,
@@ -963,7 +995,7 @@ const menuSchema = {
963
995
  //#endregion
964
996
  //#region package.json
965
997
  var name = "@univerjs/sheets-formula-ui";
966
- var version = "1.0.0-alpha.5";
998
+ var version = "1.0.0-alpha.7";
967
999
 
968
1000
  //#endregion
969
1001
  //#region src/config/config.ts
@@ -1262,7 +1294,7 @@ const useStateRef = (value) => {
1262
1294
  //#region src/views/formula-editor/hooks/use-formula-describe.ts
1263
1295
  const useFormulaDescribe = (isNeed, formulaText, editor) => {
1264
1296
  const formulaPromptService = (0, _univerjs_ui.useDependency)(IFormulaPromptService);
1265
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_formula.IDescriptionService);
1297
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_formula.IDescriptionService);
1266
1298
  const lexerTreeBuilder = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.LexerTreeBuilder);
1267
1299
  const [functionInfo, setFunctionInfo] = (0, react.useState)();
1268
1300
  const [paramIndex, setParamIndex] = (0, react.useState)(-1);
@@ -2061,30 +2093,6 @@ const useFormulaToken = () => {
2061
2093
  return (0, react.useCallback)((text) => lexerTreeBuilder.sequenceNodesBuilder(text) || [], [lexerTreeBuilder]);
2062
2094
  };
2063
2095
 
2064
- //#endregion
2065
- //#region src/common/selection.ts
2066
- function genFormulaRefSelectionStyle(themeService, refColor, id) {
2067
- return {
2068
- id,
2069
- strokeWidth: 1,
2070
- stroke: refColor,
2071
- fill: new _univerjs_core.ColorKit(refColor).setAlpha(.05).toRgbString(),
2072
- widgets: {
2073
- tl: true,
2074
- tc: true,
2075
- tr: true,
2076
- ml: true,
2077
- mr: true,
2078
- bl: true,
2079
- bc: true,
2080
- br: true
2081
- },
2082
- widgetSize: 6,
2083
- widgetStrokeWidth: 1,
2084
- widgetStroke: themeService.getColorFromTheme("white")
2085
- };
2086
- }
2087
-
2088
2096
  //#endregion
2089
2097
  //#region src/views/formula-editor/hooks/use-highlight.ts
2090
2098
  function isSameSelectionRange(left, right) {
@@ -2200,7 +2208,7 @@ function useSheetHighlight(unitId, subUnitId) {
2200
2208
  return highlightSheet;
2201
2209
  }
2202
2210
  function useDocHight(_leadingCharacter = "") {
2203
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_formula.IDescriptionService);
2211
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_formula.IDescriptionService);
2204
2212
  const colorMap = useColor();
2205
2213
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2206
2214
  const leadingCharacterLength = (0, react.useMemo)(() => _leadingCharacter.length, [_leadingCharacter]);
@@ -2260,10 +2268,7 @@ function createFormulaHighlightBody(dataStream, textRuns) {
2260
2268
  };
2261
2269
  }
2262
2270
  function getFormulaHighlightDataStream(leadingCharacter, sequenceNodes, sourceText) {
2263
- return `${leadingCharacter}${sourceText !== null && sourceText !== void 0 ? sourceText : sequenceNodes.reduce((pre, cur) => {
2264
- if (typeof cur === "string") return `${pre}${cur}`;
2265
- return `${pre}${cur.token}`;
2266
- }, "")}\r\n`;
2271
+ return (0, _univerjs_formula_ui.getFormulaHighlightDataStream)(leadingCharacter, sequenceNodes, sourceText);
2267
2272
  }
2268
2273
  function useColor() {
2269
2274
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
@@ -2290,79 +2295,7 @@ function useColor() {
2290
2295
  }, [themeService.getCurrentTheme()]);
2291
2296
  }
2292
2297
  function buildTextRuns(descriptionService, colorMap, sequenceNodes) {
2293
- const { formulaRefColors, numberColor, stringColor, plainTextColor } = colorMap;
2294
- const textRuns = [];
2295
- const refSelections = [];
2296
- const themeColorMap = /* @__PURE__ */ new Map();
2297
- let refColorIndex = 0;
2298
- for (let i = 0, len = sequenceNodes.length; i < len; i++) {
2299
- const node = sequenceNodes[i];
2300
- if (typeof node === "string") {
2301
- const theLastItem = textRuns[textRuns.length - 1];
2302
- const start = theLastItem ? theLastItem.ed : 0;
2303
- const end = start + node.length;
2304
- textRuns.push({
2305
- st: start,
2306
- ed: end,
2307
- ts: {
2308
- cl: { rgb: plainTextColor },
2309
- fs: 11
2310
- }
2311
- });
2312
- continue;
2313
- }
2314
- if (descriptionService.hasDefinedNameDescription(node.token.trim())) {
2315
- textRuns.push({
2316
- st: node.startIndex,
2317
- ed: node.endIndex + 1,
2318
- ts: {
2319
- cl: { rgb: plainTextColor },
2320
- fs: 11
2321
- }
2322
- });
2323
- continue;
2324
- }
2325
- const { startIndex, endIndex, nodeType, token } = node;
2326
- let themeColor = "";
2327
- if (nodeType === _univerjs_engine_formula.sequenceNodeType.REFERENCE) {
2328
- if (themeColorMap.has(token)) themeColor = themeColorMap.get(token);
2329
- else {
2330
- themeColor = formulaRefColors[refColorIndex % formulaRefColors.length];
2331
- themeColorMap.set(token, themeColor);
2332
- refColorIndex++;
2333
- }
2334
- refSelections.push({
2335
- refIndex: i,
2336
- themeColor,
2337
- token,
2338
- startIndex: node.startIndex,
2339
- endIndex: node.endIndex,
2340
- index: refSelections.length
2341
- });
2342
- } else if (nodeType === _univerjs_engine_formula.sequenceNodeType.NUMBER) themeColor = numberColor;
2343
- else if (nodeType === _univerjs_engine_formula.sequenceNodeType.STRING) themeColor = stringColor;
2344
- else if (nodeType === _univerjs_engine_formula.sequenceNodeType.ARRAY) themeColor = stringColor;
2345
- if (themeColor && themeColor.length > 0) textRuns.push({
2346
- st: startIndex,
2347
- ed: endIndex + 1,
2348
- ts: {
2349
- cl: { rgb: themeColor },
2350
- fs: 11
2351
- }
2352
- });
2353
- else textRuns.push({
2354
- st: startIndex,
2355
- ed: endIndex + 1,
2356
- ts: {
2357
- cl: { rgb: plainTextColor },
2358
- fs: 11
2359
- }
2360
- });
2361
- }
2362
- return {
2363
- textRuns,
2364
- refSelections
2365
- };
2298
+ return (0, _univerjs_formula_ui.buildFormulaTextRuns)(descriptionService, colorMap, sequenceNodes);
2366
2299
  }
2367
2300
 
2368
2301
  //#endregion
@@ -2652,24 +2585,6 @@ const prepareSelectionChangeContext = (opts) => {
2652
2585
  offset
2653
2586
  };
2654
2587
  };
2655
- function getSequenceNodeCharAtOffset(sequenceNodes, offset) {
2656
- let currentOffset = 0;
2657
- for (const node of sequenceNodes) {
2658
- const text = typeof node === "string" ? node : node.token;
2659
- const nextOffset = currentOffset + text.length;
2660
- if (offset > currentOffset && offset <= nextOffset) return text[offset - currentOffset - 1];
2661
- currentOffset = nextOffset;
2662
- }
2663
- }
2664
- function isFormulaReferenceAddingContext(sequenceNodes, offset) {
2665
- const char = getSequenceNodeCharAtOffset(sequenceNodes, offset);
2666
- return Boolean(char && (0, _univerjs_engine_formula.matchRefDrawToken)(char));
2667
- }
2668
- function isFormulaReferenceAddingTextContext(formulaText, offset) {
2669
- const char = formulaText[offset - 1];
2670
- const nextChar = formulaText[offset];
2671
- return Boolean(char && (0, _univerjs_engine_formula.matchRefDrawToken)(char) && (!nextChar || (0, _univerjs_engine_formula.isFormulaLexerToken)(nextChar) && nextChar !== _univerjs_engine_formula.matchToken.OPEN_BRACKET));
2672
- }
2673
2588
  function insertFormulaReferenceText(formulaText, refText, offset) {
2674
2589
  return `${formulaText.slice(0, offset)}${refText}${formulaText.slice(offset)}`;
2675
2590
  }
@@ -2820,7 +2735,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2820
2735
  });
2821
2736
  if (!ctx) return;
2822
2737
  const { nodeIndex, updatingRefIndex, formulaText, sequenceNodes, offset } = ctx;
2823
- if (isSelectingRef.current === 1 || isFormulaReferenceAddingContext(sequenceNodes, offset) || isFormulaReferenceAddingTextContext(formulaText, offset)) if (offset !== 0) {
2738
+ if (isSelectingRef.current === 1 || (0, _univerjs_formula_ui.isFormulaReferenceAddingContext)(sequenceNodes, offset) || (0, _univerjs_formula_ui.isFormulaReferenceAddingTextContext)(formulaText, offset)) if (offset !== 0) {
2824
2739
  var _range$sheetId, _range$unitId, _range$unitId2;
2825
2740
  if (nodeIndex === -1 && sequenceNodes.length) return;
2826
2741
  const range = getLastFormulaSelection(selections);
@@ -2835,7 +2750,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2835
2750
  const isAcrossSheet = rangeSheetId !== subUnitId;
2836
2751
  const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
2837
2752
  const refRanges = unitRangesToText([unitRangeName], isSupportAcrossSheet && (isAcrossSheet || isAcrossWorkbook), sheetName, isAcrossWorkbook);
2838
- if (isFormulaReferenceAddingTextContext(formulaText, offset)) {
2753
+ if ((0, _univerjs_formula_ui.isFormulaReferenceAddingTextContext)(formulaText, offset)) {
2839
2754
  handleRangeChange(insertFormulaReferenceText(formulaText, refRanges[0], offset), offset + refRanges[0].length, isEnd);
2840
2755
  return;
2841
2756
  }
@@ -3026,7 +2941,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
3026
2941
  editor,
3027
2942
  lexerTreeBuilder
3028
2943
  });
3029
- const isAdd = isSelectingRef.current === 1 || Boolean(ctx && (isFormulaReferenceAddingContext(ctx.sequenceNodes, ctx.offset) || isFormulaReferenceAddingTextContext(ctx.formulaText, ctx.offset)));
2944
+ const isAdd = isSelectingRef.current === 1 || Boolean(ctx && ((0, _univerjs_formula_ui.isFormulaReferenceAddingContext)(ctx.sequenceNodes, ctx.offset) || (0, _univerjs_formula_ui.isFormulaReferenceAddingTextContext)(ctx.formulaText, ctx.offset)));
3030
2945
  const selections = ((_refSelectionsRenderS = refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.getSelectionDataWithStyle()) !== null && _refSelectionsRenderS !== void 0 ? _refSelectionsRenderS : []).map((i) => i.rangeWithCoord);
3031
2946
  if (isAdd) {
3032
2947
  if (selections.length > 0 && isSameFormulaSelection(selections[selections.length - 1], range)) return;
@@ -3171,28 +3086,11 @@ const useVerify = (isNeed, onVerify, formulaText) => {
3171
3086
 
3172
3087
  //#endregion
3173
3088
  //#region src/views/formula-editor/hooks/use-formula-search.ts
3174
- function shouldAppendOpenBracket(functionType) {
3175
- return functionType !== _univerjs_engine_formula.FunctionType.DefinedName && functionType !== _univerjs_engine_formula.FunctionType.Table;
3176
- }
3177
3089
  function getFormulaReplaceResult(nodes, index, formulaName, functionType) {
3178
- const cloneNodes = [...nodes];
3179
- if (index !== -1) {
3180
- const lastNodes = cloneNodes.splice(index + 1);
3181
- const oldNode = cloneNodes.pop() || "";
3182
- let offset = (typeof oldNode === "string" ? oldNode.length : oldNode.token.length) - formulaName.length;
3183
- cloneNodes.push(formulaName);
3184
- if (lastNodes[0] !== _univerjs_engine_formula.matchToken.OPEN_BRACKET && shouldAppendOpenBracket(functionType)) {
3185
- cloneNodes.push(_univerjs_engine_formula.matchToken.OPEN_BRACKET);
3186
- offset--;
3187
- }
3188
- return {
3189
- text: sequenceNodeToText([...cloneNodes, ...lastNodes]),
3190
- offset
3191
- };
3192
- }
3090
+ return (0, _univerjs_formula_ui.getFormulaReplaceResult)(nodes, index, formulaName, functionType);
3193
3091
  }
3194
3092
  const useFormulaSearch = (isNeed, nodes = [], editor) => {
3195
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_formula.IDescriptionService);
3093
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_formula.IDescriptionService);
3196
3094
  const [searchList, setSearchList] = (0, react.useState)([]);
3197
3095
  const [searchText, setSearchText] = (0, react.useState)("");
3198
3096
  const indexRef = (0, react.useRef)(-1);
@@ -3216,7 +3114,7 @@ const useFormulaSearch = (isNeed, nodes = [], editor) => {
3216
3114
  if (currentNode && typeof currentNode !== "string" && currentNode.nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION) {
3217
3115
  indexRef.current = currentNodeIndex;
3218
3116
  const token = currentNode.token;
3219
- setSearchList(descriptionService.getSearchListByNameFirstLetter(token).slice(0, 10));
3117
+ setSearchList((0, _univerjs_formula_ui.searchFormulaFunctions)(descriptionService, token));
3220
3118
  setSearchText(token);
3221
3119
  return;
3222
3120
  }
@@ -3863,7 +3761,7 @@ function SelectFunction(props) {
3863
3761
  const [typeSelected, setTypeSelected] = (0, react.useState)(allTypeValue);
3864
3762
  const [nameSelected, setNameSelected] = (0, react.useState)(0);
3865
3763
  const [functionInfo, setFunctionInfo] = (0, react.useState)(null);
3866
- const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_formula.IDescriptionService);
3764
+ const descriptionService = (0, _univerjs_ui.useDependency)(_univerjs_formula.IDescriptionService);
3867
3765
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
3868
3766
  const sidebarOptions = (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(_univerjs_ui.ISidebarService).sidebarOptions$);
3869
3767
  const options = getFunctionTypeValues(localeService, Boolean(customFunction)).filter((option) => descriptionService.getSearchListByType(Number(option.value)).length > 0);
@@ -5493,4 +5391,5 @@ Object.defineProperty(exports, 'UniverSheetsFormulaUIPlugin', {
5493
5391
  get: function () {
5494
5392
  return UniverSheetsFormulaUIPlugin;
5495
5393
  }
5496
- });
5394
+ });
5395
+ exports.genFormulaRefSelectionStyle = genFormulaRefSelectionStyle;
package/lib/es/index.js CHANGED
@@ -5,13 +5,15 @@ import { BehaviorSubject, Subject, combineLatestWith, debounceTime, distinctUnti
5
5
  import { DocBackScrollRenderController, DocSelectionRenderService, IEditorService, MoveCursorOperation, MoveSelectionOperation, ReplaceTextRunsCommand, RichTextEditor, createEditorUndoRedoKeyboardConfig, useKeyboardEvent, useResize } from "@univerjs/docs-ui";
6
6
  import { DeviceInputEventType, IRenderManagerService, SHEET_VIEWPORT_KEY, ScrollTimerType, Vector2 } from "@univerjs/engine-render";
7
7
  import { BEFORE_CELL_EDIT, INTERCEPTOR_POINT, IRefSelectionsService, REF_SELECTIONS_ENABLED, RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, ReorderRangeCommand, SelectionMoveType, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetRowAutoHeightMutation, SheetInterceptorService, SheetSkeletonService, SheetsSelectionsService, WorkbookCopyPermission, WorkbookEditablePermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetSetCellValuePermission, attachSelectionWithCoord, convertSelectionDataToRange, getCellAtRowCol, getSheetCommandTarget, setEndForRange } from "@univerjs/sheets";
8
- import { IDescriptionService, ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, QuickSumCommand, TriggerCalculationController, UniverSheetsFormulaPlugin } from "@univerjs/sheets-formula";
8
+ import { ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, QuickSumCommand, TriggerCalculationController, UniverSheetsFormulaPlugin } from "@univerjs/sheets-formula";
9
9
  import { BuiltInUIPart, ComponentManager, IContextMenuService, IMenuManagerService, IShortcutService, ISidebarService, IUIPartsService, IconManager, KeyCode, MenuItemType, MetaKeys, ProgressBar, RectPopup, RibbonFormulasGroup, connectInjector, getMenuHiddenObservable, useDependency, useEvent, useObservable, useUpdateEffect } from "@univerjs/ui";
10
10
  import { DocSelectionManagerService } from "@univerjs/docs";
11
+ import { IDescriptionService } from "@univerjs/formula";
11
12
  import { CheckMarkIcon, CloseIcon, DatabaseFunctionIcon, DateFunctionIcon, DeleteIcon, EngineeringFunctionIcon, FinancialFunctionIcon, FunctionIcon, IncreaseIcon, InformationFunctionIcon, LogicalFunctionIcon, LookupFunctionIcon, MathFunctionIcon, MoreRightIcon, SelectRangeIcon, StatisticalFunctionIcon, TextFunctionIcon } from "@univerjs/icons";
12
13
  import { Button, Dialog, Input, Select, Tooltip, borderClassName, borderLeftClassName, borderTopClassName, clsx, divideYClassName, scrollbarClassName } from "@univerjs/design";
13
14
  import { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
14
15
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
16
+ import { buildFormulaTextRuns, getFormulaHighlightDataStream, getFormulaReplaceResult, isFormulaReferenceAddingContext, isFormulaReferenceAddingTextContext, searchFormulaFunctions } from "@univerjs/formula-ui";
15
17
  import { debounceTime as debounceTime$1 } from "rxjs/operators";
16
18
 
17
19
  //#region src/commands/commands/formula-clipboard.command.ts
@@ -695,6 +697,30 @@ const SearchFunctionOperation = {
695
697
  }
696
698
  };
697
699
 
700
+ //#endregion
701
+ //#region src/common/selection.ts
702
+ function genFormulaRefSelectionStyle(themeService, refColor, id) {
703
+ return {
704
+ id,
705
+ strokeWidth: 1,
706
+ stroke: refColor,
707
+ fill: new ColorKit(refColor).setAlpha(.05).toRgbString(),
708
+ widgets: {
709
+ tl: true,
710
+ tc: true,
711
+ tr: true,
712
+ ml: true,
713
+ mr: true,
714
+ bl: true,
715
+ bc: true,
716
+ br: true
717
+ },
718
+ widgetSize: 6,
719
+ widgetStrokeWidth: 1,
720
+ widgetStroke: themeService.getColorFromTheme("white")
721
+ };
722
+ }
723
+
698
724
  //#endregion
699
725
  //#region src/controllers/formula-reorder.controller.ts
700
726
  let FormulaReorderController = class FormulaReorderController extends Disposable {
@@ -902,6 +928,12 @@ const menuSchema = {
902
928
  [RibbonFormulasGroup.BASIC]: {
903
929
  [`${InsertFunctionOperation.id}.common`]: {
904
930
  order: 0,
931
+ gridLayout: {
932
+ row: 1,
933
+ column: 1,
934
+ rowSpan: 2,
935
+ showLabel: false
936
+ },
905
937
  menuItemFactory: InsertCommonFunctionMenuItemFactory,
906
938
  [MoreFunctionsOperation.id]: {
907
939
  order: 0,
@@ -962,7 +994,7 @@ const menuSchema = {
962
994
  //#endregion
963
995
  //#region package.json
964
996
  var name = "@univerjs/sheets-formula-ui";
965
- var version = "1.0.0-alpha.5";
997
+ var version = "1.0.0-alpha.7";
966
998
 
967
999
  //#endregion
968
1000
  //#region src/config/config.ts
@@ -2060,30 +2092,6 @@ const useFormulaToken = () => {
2060
2092
  return useCallback((text) => lexerTreeBuilder.sequenceNodesBuilder(text) || [], [lexerTreeBuilder]);
2061
2093
  };
2062
2094
 
2063
- //#endregion
2064
- //#region src/common/selection.ts
2065
- function genFormulaRefSelectionStyle(themeService, refColor, id) {
2066
- return {
2067
- id,
2068
- strokeWidth: 1,
2069
- stroke: refColor,
2070
- fill: new ColorKit(refColor).setAlpha(.05).toRgbString(),
2071
- widgets: {
2072
- tl: true,
2073
- tc: true,
2074
- tr: true,
2075
- ml: true,
2076
- mr: true,
2077
- bl: true,
2078
- bc: true,
2079
- br: true
2080
- },
2081
- widgetSize: 6,
2082
- widgetStrokeWidth: 1,
2083
- widgetStroke: themeService.getColorFromTheme("white")
2084
- };
2085
- }
2086
-
2087
2095
  //#endregion
2088
2096
  //#region src/views/formula-editor/hooks/use-highlight.ts
2089
2097
  function isSameSelectionRange(left, right) {
@@ -2223,7 +2231,7 @@ function useDocHight(_leadingCharacter = "") {
2223
2231
  e.ed = e.ed + leadingCharacterLength;
2224
2232
  e.st = e.st + leadingCharacterLength;
2225
2233
  });
2226
- const highlightDataStream = getFormulaHighlightDataStream(_leadingCharacter, sequenceNodes, sourceText);
2234
+ const highlightDataStream = getFormulaHighlightDataStream$1(_leadingCharacter, sequenceNodes, sourceText);
2227
2235
  const highlightTextRuns = [{
2228
2236
  st: 0,
2229
2237
  ed: 1,
@@ -2258,11 +2266,8 @@ function createFormulaHighlightBody(dataStream, textRuns) {
2258
2266
  textRuns
2259
2267
  };
2260
2268
  }
2261
- function getFormulaHighlightDataStream(leadingCharacter, sequenceNodes, sourceText) {
2262
- return `${leadingCharacter}${sourceText !== null && sourceText !== void 0 ? sourceText : sequenceNodes.reduce((pre, cur) => {
2263
- if (typeof cur === "string") return `${pre}${cur}`;
2264
- return `${pre}${cur.token}`;
2265
- }, "")}\r\n`;
2269
+ function getFormulaHighlightDataStream$1(leadingCharacter, sequenceNodes, sourceText) {
2270
+ return getFormulaHighlightDataStream(leadingCharacter, sequenceNodes, sourceText);
2266
2271
  }
2267
2272
  function useColor() {
2268
2273
  const themeService = useDependency(ThemeService);
@@ -2289,79 +2294,7 @@ function useColor() {
2289
2294
  }, [themeService.getCurrentTheme()]);
2290
2295
  }
2291
2296
  function buildTextRuns(descriptionService, colorMap, sequenceNodes) {
2292
- const { formulaRefColors, numberColor, stringColor, plainTextColor } = colorMap;
2293
- const textRuns = [];
2294
- const refSelections = [];
2295
- const themeColorMap = /* @__PURE__ */ new Map();
2296
- let refColorIndex = 0;
2297
- for (let i = 0, len = sequenceNodes.length; i < len; i++) {
2298
- const node = sequenceNodes[i];
2299
- if (typeof node === "string") {
2300
- const theLastItem = textRuns[textRuns.length - 1];
2301
- const start = theLastItem ? theLastItem.ed : 0;
2302
- const end = start + node.length;
2303
- textRuns.push({
2304
- st: start,
2305
- ed: end,
2306
- ts: {
2307
- cl: { rgb: plainTextColor },
2308
- fs: 11
2309
- }
2310
- });
2311
- continue;
2312
- }
2313
- if (descriptionService.hasDefinedNameDescription(node.token.trim())) {
2314
- textRuns.push({
2315
- st: node.startIndex,
2316
- ed: node.endIndex + 1,
2317
- ts: {
2318
- cl: { rgb: plainTextColor },
2319
- fs: 11
2320
- }
2321
- });
2322
- continue;
2323
- }
2324
- const { startIndex, endIndex, nodeType, token } = node;
2325
- let themeColor = "";
2326
- if (nodeType === sequenceNodeType.REFERENCE) {
2327
- if (themeColorMap.has(token)) themeColor = themeColorMap.get(token);
2328
- else {
2329
- themeColor = formulaRefColors[refColorIndex % formulaRefColors.length];
2330
- themeColorMap.set(token, themeColor);
2331
- refColorIndex++;
2332
- }
2333
- refSelections.push({
2334
- refIndex: i,
2335
- themeColor,
2336
- token,
2337
- startIndex: node.startIndex,
2338
- endIndex: node.endIndex,
2339
- index: refSelections.length
2340
- });
2341
- } else if (nodeType === sequenceNodeType.NUMBER) themeColor = numberColor;
2342
- else if (nodeType === sequenceNodeType.STRING) themeColor = stringColor;
2343
- else if (nodeType === sequenceNodeType.ARRAY) themeColor = stringColor;
2344
- if (themeColor && themeColor.length > 0) textRuns.push({
2345
- st: startIndex,
2346
- ed: endIndex + 1,
2347
- ts: {
2348
- cl: { rgb: themeColor },
2349
- fs: 11
2350
- }
2351
- });
2352
- else textRuns.push({
2353
- st: startIndex,
2354
- ed: endIndex + 1,
2355
- ts: {
2356
- cl: { rgb: plainTextColor },
2357
- fs: 11
2358
- }
2359
- });
2360
- }
2361
- return {
2362
- textRuns,
2363
- refSelections
2364
- };
2297
+ return buildFormulaTextRuns(descriptionService, colorMap, sequenceNodes);
2365
2298
  }
2366
2299
 
2367
2300
  //#endregion
@@ -2651,24 +2584,6 @@ const prepareSelectionChangeContext = (opts) => {
2651
2584
  offset
2652
2585
  };
2653
2586
  };
2654
- function getSequenceNodeCharAtOffset(sequenceNodes, offset) {
2655
- let currentOffset = 0;
2656
- for (const node of sequenceNodes) {
2657
- const text = typeof node === "string" ? node : node.token;
2658
- const nextOffset = currentOffset + text.length;
2659
- if (offset > currentOffset && offset <= nextOffset) return text[offset - currentOffset - 1];
2660
- currentOffset = nextOffset;
2661
- }
2662
- }
2663
- function isFormulaReferenceAddingContext(sequenceNodes, offset) {
2664
- const char = getSequenceNodeCharAtOffset(sequenceNodes, offset);
2665
- return Boolean(char && matchRefDrawToken(char));
2666
- }
2667
- function isFormulaReferenceAddingTextContext(formulaText, offset) {
2668
- const char = formulaText[offset - 1];
2669
- const nextChar = formulaText[offset];
2670
- return Boolean(char && matchRefDrawToken(char) && (!nextChar || isFormulaLexerToken(nextChar) && nextChar !== matchToken.OPEN_BRACKET));
2671
- }
2672
2587
  function insertFormulaReferenceText(formulaText, refText, offset) {
2673
2588
  return `${formulaText.slice(0, offset)}${refText}${formulaText.slice(offset)}`;
2674
2589
  }
@@ -3170,25 +3085,8 @@ const useVerify = (isNeed, onVerify, formulaText) => {
3170
3085
 
3171
3086
  //#endregion
3172
3087
  //#region src/views/formula-editor/hooks/use-formula-search.ts
3173
- function shouldAppendOpenBracket(functionType) {
3174
- return functionType !== FunctionType.DefinedName && functionType !== FunctionType.Table;
3175
- }
3176
- function getFormulaReplaceResult(nodes, index, formulaName, functionType) {
3177
- const cloneNodes = [...nodes];
3178
- if (index !== -1) {
3179
- const lastNodes = cloneNodes.splice(index + 1);
3180
- const oldNode = cloneNodes.pop() || "";
3181
- let offset = (typeof oldNode === "string" ? oldNode.length : oldNode.token.length) - formulaName.length;
3182
- cloneNodes.push(formulaName);
3183
- if (lastNodes[0] !== matchToken.OPEN_BRACKET && shouldAppendOpenBracket(functionType)) {
3184
- cloneNodes.push(matchToken.OPEN_BRACKET);
3185
- offset--;
3186
- }
3187
- return {
3188
- text: sequenceNodeToText([...cloneNodes, ...lastNodes]),
3189
- offset
3190
- };
3191
- }
3088
+ function getFormulaReplaceResult$1(nodes, index, formulaName, functionType) {
3089
+ return getFormulaReplaceResult(nodes, index, formulaName, functionType);
3192
3090
  }
3193
3091
  const useFormulaSearch = (isNeed, nodes = [], editor) => {
3194
3092
  const descriptionService = useDependency(IDescriptionService);
@@ -3215,7 +3113,7 @@ const useFormulaSearch = (isNeed, nodes = [], editor) => {
3215
3113
  if (currentNode && typeof currentNode !== "string" && currentNode.nodeType === sequenceNodeType.FUNCTION) {
3216
3114
  indexRef.current = currentNodeIndex;
3217
3115
  const token = currentNode.token;
3218
- setSearchList(descriptionService.getSearchListByNameFirstLetter(token).slice(0, 10));
3116
+ setSearchList(searchFormulaFunctions(descriptionService, token));
3219
3117
  setSearchText(token);
3220
3118
  return;
3221
3119
  }
@@ -3237,7 +3135,7 @@ const useFormulaSearch = (isNeed, nodes = [], editor) => {
3237
3135
  if (!isNeed) reset();
3238
3136
  }, [isNeed]);
3239
3137
  const handlerFormulaReplace = (formulaName, functionType) => {
3240
- return getFormulaReplaceResult(stateRef.current.nodes, indexRef.current, formulaName, functionType);
3138
+ return getFormulaReplaceResult$1(stateRef.current.nodes, indexRef.current, formulaName, functionType);
3241
3139
  };
3242
3140
  return {
3243
3141
  searchList,
@@ -5463,4 +5361,4 @@ UniverSheetsFormulaUIPlugin = __decorate([
5463
5361
  ], UniverSheetsFormulaUIPlugin);
5464
5362
 
5465
5363
  //#endregion
5466
- export { FORMULA_PROMPT_ACTIVATED, FormulaEditor, FormulaReorderController, GlobalRangeSelectorService, HelpFunctionOperation, InsertFunctionOperation, MoreFunctionsOperation, RangeSelector, RefSelectionsRenderService, ReferenceAbsoluteOperation, SearchFunctionOperation, SheetCopyFormulaOnlyCommand, SheetOnlyPasteFormulaCommand, menuSchema as SheetsFormulaUIMenuSchema, UniverSheetsFormulaUIPlugin };
5364
+ export { FORMULA_PROMPT_ACTIVATED, FormulaEditor, FormulaReorderController, GlobalRangeSelectorService, HelpFunctionOperation, InsertFunctionOperation, MoreFunctionsOperation, RangeSelector, RefSelectionsRenderService, ReferenceAbsoluteOperation, SearchFunctionOperation, SheetCopyFormulaOnlyCommand, SheetOnlyPasteFormulaCommand, menuSchema as SheetsFormulaUIMenuSchema, UniverSheetsFormulaUIPlugin, genFormulaRefSelectionStyle };