@univerjs/sheets-formula-ui 1.0.0-alpha.6 → 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/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.6";
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 };
@@ -20,6 +20,7 @@ export { InsertFunctionOperation } from './commands/operations/insert-function.o
20
20
  export { MoreFunctionsOperation } from './commands/operations/more-functions.operation';
21
21
  export { ReferenceAbsoluteOperation } from './commands/operations/reference-absolute.operation';
22
22
  export { SearchFunctionOperation } from './commands/operations/search-function.operation';
23
+ export { genFormulaRefSelectionStyle } from './common/selection';
23
24
  export type { IUniverSheetsFormulaUIConfig } from './config/config';
24
25
  export { FormulaReorderController } from './controllers/formula-reorder.controller';
25
26
  export { menuSchema as SheetsFormulaUIMenuSchema } from './menu/schema';
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import type { Direction, IDisposable } from '@univerjs/core';
17
17
  import type { IFunctionInfo, ISequenceNode } from '@univerjs/engine-formula';
18
- import type { ISearchItem } from '@univerjs/sheets-formula';
18
+ import type { ISearchItem } from '@univerjs/formula';
19
19
  import type { Observable } from 'rxjs';
20
20
  import { IContextService } from '@univerjs/core';
21
21
  /** If the formula prompt is visible. */
@@ -14,13 +14,9 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { Editor } from '@univerjs/docs-ui';
17
- import type { ISearchItemWithType } from '@univerjs/sheets-formula';
17
+ import type { FunctionType } from '@univerjs/engine-formula';
18
+ import type { ISearchItemWithType } from '@univerjs/formula';
18
19
  import type { INode } from './use-formula-token';
19
- import { FunctionType } from '@univerjs/engine-formula';
20
- export declare function getFormulaReplaceResult(nodes: INode[], index: number, formulaName: string, functionType: FunctionType): {
21
- text: string;
22
- offset: number;
23
- } | undefined;
24
20
  export declare const useFormulaSearch: (isNeed: boolean, nodes?: INode[], editor?: Editor) => {
25
21
  searchList: ISearchItemWithType[];
26
22
  searchText: string;
@@ -15,11 +15,9 @@
15
15
  */
16
16
  import type { IDocumentBody, ITextRange, ITextRun, Workbook } from '@univerjs/core';
17
17
  import type { Editor } from '@univerjs/docs-ui';
18
- import type { ISequenceNode } from '@univerjs/engine-formula';
19
18
  import type { ISelectionWithStyle, SheetsSelectionsService } from '@univerjs/sheets';
20
19
  import type { INode } from './use-formula-token';
21
20
  import { IUniverInstanceService, ThemeService } from '@univerjs/core';
22
- import { IDescriptionService } from '@univerjs/sheets-formula';
23
21
  import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';
24
22
  import { RefSelectionsRenderService } from '../../../services/render-services/ref-selections.render.service';
25
23
  export interface IRefSelection {
@@ -48,14 +46,13 @@ export declare function calcHighlightRanges(opts: {
48
46
  * @param {IRefSelection[]} refSelections
49
47
  */
50
48
  export declare function useSheetHighlight(unitId: string, subUnitId: string): (refSelections: IRefSelection[], editor?: Editor, isEnd?: any) => void;
51
- export declare function useDocHight(_leadingCharacter?: string): (editor: Editor, sequenceNodes: INode[], isNeedResetSelection?: any, newSelections?: ITextRange[], sourceText?: string) => IRefSelection[];
49
+ export declare function useDocHight(_leadingCharacter?: string): (editor: Editor, sequenceNodes: INode[], isNeedResetSelection?: any, newSelections?: ITextRange[], sourceText?: string) => import("@univerjs/formula-ui").IFormulaRefSelection[];
52
50
  /**
53
51
  * ReplaceTextRunsCommand shifts the editor's existing structural metadata when text changes.
54
52
  * Its replacement body must therefore contain only inline formula data; carrying paragraphs
55
53
  * or section breaks copied from the old snapshot would leave their indexes stale.
56
54
  */
57
55
  export declare function createFormulaHighlightBody(dataStream: string, textRuns: ITextRun[]): IDocumentBody;
58
- export declare function getFormulaHighlightDataStream(leadingCharacter: string, sequenceNodes: Array<ISequenceNode | string>, sourceText?: string): string;
59
56
  interface IColorMap {
60
57
  formulaRefColors: string[];
61
58
  numberColor: string;
@@ -63,8 +60,4 @@ interface IColorMap {
63
60
  plainTextColor: string;
64
61
  }
65
62
  export declare function useColor(): IColorMap;
66
- export declare function buildTextRuns(descriptionService: IDescriptionService, colorMap: IColorMap, sequenceNodes: Array<ISequenceNode | string>): {
67
- textRuns: ITextRun[];
68
- refSelections: IRefSelection[];
69
- };
70
63
  export {};
@@ -29,13 +29,6 @@ export declare const prepareSelectionChangeContext: (opts: {
29
29
  sequenceNodes: (string | import("@univerjs/engine-formula").ISequenceNode)[];
30
30
  offset: number;
31
31
  } | undefined;
32
- export declare function getSequenceNodeCharAtOffset(sequenceNodes: (string | {
33
- token: string;
34
- })[], offset: number): string | undefined;
35
- export declare function isFormulaReferenceAddingContext(sequenceNodes: (string | {
36
- token: string;
37
- })[], offset: number): boolean;
38
- export declare function isFormulaReferenceAddingTextContext(formulaText: string, offset: number): boolean;
39
32
  export declare function insertFormulaReferenceText(formulaText: string, refText: string, offset: number): string;
40
33
  export declare function shouldSkipFormulaReferenceUpdate(isAdd: boolean, selectionCount: number): boolean;
41
34
  export declare function getSelectionsForFormulaRefUpdate(selections: IRange[], updatingRefIndex: number, isCtrlAddMode?: boolean): {