@univerjs/sheets-formula 0.1.0-alpha.1 → 0.1.0-alpha.2

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.
Files changed (194) hide show
  1. package/LICENSE.txt +178 -0
  2. package/lib/cjs/index.js +11 -4215
  3. package/lib/es/index.js +4346 -0
  4. package/lib/index.css +1 -214
  5. package/lib/types/commands/commands/formula-clipboard.command.d.ts +18 -0
  6. package/lib/types/commands/commands/insert-function.command.d.ts +15 -1
  7. package/lib/types/commands/operations/__tests__/create-command-test-bed.d.ts +15 -1
  8. package/lib/types/commands/operations/__tests__/insert-function.operation.spec.d.ts +15 -1
  9. package/lib/types/commands/operations/editor-formula.operation.d.ts +15 -1
  10. package/lib/types/commands/operations/help-function.operation.d.ts +15 -1
  11. package/lib/types/commands/operations/insert-function.operation.d.ts +15 -1
  12. package/lib/types/commands/operations/more-functions.operation.d.ts +15 -1
  13. package/lib/types/commands/operations/reference-absolute.operation.d.ts +15 -1
  14. package/lib/types/commands/operations/search-function.operation.d.ts +15 -1
  15. package/lib/types/common/plugin-name.d.ts +15 -1
  16. package/lib/types/common/prompt.d.ts +15 -1
  17. package/lib/types/common/selection.d.ts +15 -1
  18. package/lib/types/controllers/__tests__/create-command-test-bed.d.ts +15 -1
  19. package/lib/types/controllers/__tests__/formula-auto-fill.controller.spec.d.ts +15 -1
  20. package/lib/types/controllers/__tests__/formula-clipboard.controller.spec.d.ts +16 -0
  21. package/lib/types/controllers/__tests__/update-formula.controller.spec.d.ts +16 -0
  22. package/lib/types/controllers/__tests__/utils.spec.d.ts +16 -0
  23. package/lib/types/controllers/active-dirty.controller.d.ts +40 -0
  24. package/lib/types/controllers/array-formula-display.controller.d.ts +27 -0
  25. package/lib/types/controllers/formula-auto-fill.controller.d.ts +18 -4
  26. package/lib/types/controllers/formula-clipboard.controller.d.ts +41 -0
  27. package/lib/types/controllers/formula-editor-show.controller.d.ts +35 -0
  28. package/lib/types/controllers/formula-input.controller.d.ts +18 -4
  29. package/lib/types/controllers/formula-ui.controller.d.ts +15 -1
  30. package/lib/types/controllers/menu.d.ts +16 -1
  31. package/lib/types/controllers/prompt.controller.d.ts +18 -4
  32. package/lib/types/controllers/shortcuts/prompt.shortcut.d.ts +15 -1
  33. package/lib/types/controllers/trigger-calculation.controller.d.ts +32 -0
  34. package/lib/types/controllers/update-formula.controller.d.ts +75 -0
  35. package/lib/types/controllers/utils.d.ts +26 -0
  36. package/lib/types/formula-ui-plugin.d.ts +16 -2
  37. package/lib/types/index.d.ts +17 -2
  38. package/lib/types/locale/en-US.d.ts +18 -1
  39. package/lib/types/locale/function-list/array/en-US.d.ts +15 -1
  40. package/lib/types/locale/function-list/array/zh-CN.d.ts +15 -1
  41. package/lib/types/locale/function-list/compatibility/en-US.d.ts +15 -1
  42. package/lib/types/locale/function-list/compatibility/zh-CN.d.ts +15 -1
  43. package/lib/types/locale/function-list/cube/en-US.d.ts +15 -1
  44. package/lib/types/locale/function-list/cube/zh-CN.d.ts +15 -1
  45. package/lib/types/locale/function-list/database/en-US.d.ts +15 -1
  46. package/lib/types/locale/function-list/database/zh-CN.d.ts +15 -1
  47. package/lib/types/locale/function-list/date/en-US.d.ts +15 -1
  48. package/lib/types/locale/function-list/date/zh-CN.d.ts +15 -1
  49. package/lib/types/locale/function-list/engineering/en-US.d.ts +15 -1
  50. package/lib/types/locale/function-list/engineering/zh-CN.d.ts +15 -1
  51. package/lib/types/locale/function-list/financial/en-US.d.ts +15 -1
  52. package/lib/types/locale/function-list/financial/zh-CN.d.ts +15 -1
  53. package/lib/types/locale/function-list/information/en-US.d.ts +15 -1
  54. package/lib/types/locale/function-list/information/zh-CN.d.ts +15 -1
  55. package/lib/types/locale/function-list/logical/en-US.d.ts +15 -1
  56. package/lib/types/locale/function-list/logical/zh-CN.d.ts +15 -1
  57. package/lib/types/locale/function-list/lookup/en-US.d.ts +15 -1
  58. package/lib/types/locale/function-list/lookup/zh-CN.d.ts +15 -1
  59. package/lib/types/locale/function-list/math/en-US.d.ts +15 -1
  60. package/lib/types/locale/function-list/math/zh-CN.d.ts +15 -1
  61. package/lib/types/locale/function-list/statistical/en-US.d.ts +15 -1
  62. package/lib/types/locale/function-list/statistical/zh-CN.d.ts +15 -1
  63. package/lib/types/locale/function-list/text/en-US.d.ts +15 -1
  64. package/lib/types/locale/function-list/text/zh-CN.d.ts +15 -1
  65. package/lib/types/locale/function-list/univer/en-US.d.ts +15 -1
  66. package/lib/types/locale/function-list/univer/zh-CN.d.ts +15 -1
  67. package/lib/types/locale/function-list/web/en-US.d.ts +15 -1
  68. package/lib/types/locale/function-list/web/zh-CN.d.ts +15 -1
  69. package/lib/types/locale/index.d.ts +15 -1
  70. package/lib/types/locale/zh-CN.d.ts +18 -1
  71. package/lib/types/services/active-dirty-manager.service.d.ts +48 -0
  72. package/lib/types/services/description.service.d.ts +21 -7
  73. package/lib/types/services/formula-input.service.d.ts +15 -4
  74. package/lib/types/services/function-list/array.d.ts +15 -1
  75. package/lib/types/services/function-list/compatibility.d.ts +15 -1
  76. package/lib/types/services/function-list/cube.d.ts +15 -1
  77. package/lib/types/services/function-list/database.d.ts +15 -1
  78. package/lib/types/services/function-list/date.d.ts +15 -1
  79. package/lib/types/services/function-list/engineering.d.ts +15 -1
  80. package/lib/types/services/function-list/financial.d.ts +15 -1
  81. package/lib/types/services/function-list/function-list.d.ts +15 -1
  82. package/lib/types/services/function-list/information.d.ts +15 -1
  83. package/lib/types/services/function-list/logical.d.ts +15 -1
  84. package/lib/types/services/function-list/lookup.d.ts +15 -1
  85. package/lib/types/services/function-list/math.d.ts +15 -1
  86. package/lib/types/services/function-list/statistical.d.ts +15 -1
  87. package/lib/types/services/function-list/text.d.ts +15 -1
  88. package/lib/types/services/function-list/univer.d.ts +15 -1
  89. package/lib/types/services/function-list/web.d.ts +15 -1
  90. package/lib/types/services/prompt.service.d.ts +15 -1
  91. package/lib/types/services/utils.d.ts +15 -1
  92. package/lib/types/views/FormulaPromptContainer.d.ts +15 -1
  93. package/lib/types/views/more-functions/MoreFunctions.d.ts +15 -1
  94. package/lib/types/views/more-functions/function-help/FunctionHelp.d.ts +15 -1
  95. package/lib/types/views/more-functions/function-params/FunctionParams.d.ts +15 -1
  96. package/lib/types/views/more-functions/input-params/InputParams.d.ts +15 -1
  97. package/lib/types/views/more-functions/interface.d.ts +15 -1
  98. package/lib/types/views/more-functions/select-function/SelectFunction.d.ts +15 -1
  99. package/lib/types/views/prompt/error-function/error-function.d.ts +15 -1
  100. package/lib/types/views/prompt/help-function/HelpFunction.d.ts +15 -1
  101. package/lib/types/views/prompt/search-function/SearchFunction.d.ts +15 -1
  102. package/lib/umd/index.js +11 -0
  103. package/package.json +42 -31
  104. package/LICENSE +0 -21
  105. package/lib/cjs/locale/en-US.js +0 -223
  106. package/lib/cjs/locale/zh-CN.js +0 -223
  107. package/lib/esm/index.js +0 -4205
  108. package/lib/esm/locale/en-US.js +0 -200
  109. package/lib/esm/locale/zh-CN.js +0 -200
  110. package/lib/types/commands/commands/insert-function.command.d.ts.map +0 -1
  111. package/lib/types/commands/operations/__tests__/create-command-test-bed.d.ts.map +0 -1
  112. package/lib/types/commands/operations/__tests__/insert-function.operation.spec.d.ts.map +0 -1
  113. package/lib/types/commands/operations/editor-formula.operation.d.ts.map +0 -1
  114. package/lib/types/commands/operations/help-function.operation.d.ts.map +0 -1
  115. package/lib/types/commands/operations/insert-function.operation.d.ts.map +0 -1
  116. package/lib/types/commands/operations/more-functions.operation.d.ts.map +0 -1
  117. package/lib/types/commands/operations/reference-absolute.operation.d.ts.map +0 -1
  118. package/lib/types/commands/operations/search-function.operation.d.ts.map +0 -1
  119. package/lib/types/common/plugin-name.d.ts.map +0 -1
  120. package/lib/types/common/prompt.d.ts.map +0 -1
  121. package/lib/types/common/selection.d.ts.map +0 -1
  122. package/lib/types/controllers/__tests__/create-command-test-bed.d.ts.map +0 -1
  123. package/lib/types/controllers/__tests__/formula-auto-fill.controller.spec.d.ts.map +0 -1
  124. package/lib/types/controllers/formula-auto-fill.controller.d.ts.map +0 -1
  125. package/lib/types/controllers/formula-input.controller.d.ts.map +0 -1
  126. package/lib/types/controllers/formula-ui.controller.d.ts.map +0 -1
  127. package/lib/types/controllers/menu.d.ts.map +0 -1
  128. package/lib/types/controllers/prompt.controller.d.ts.map +0 -1
  129. package/lib/types/controllers/shortcuts/prompt.shortcut.d.ts.map +0 -1
  130. package/lib/types/formula-ui-plugin.d.ts.map +0 -1
  131. package/lib/types/index.d.ts.map +0 -1
  132. package/lib/types/locale/en-US.d.ts.map +0 -1
  133. package/lib/types/locale/function-list/array/en-US.d.ts.map +0 -1
  134. package/lib/types/locale/function-list/array/zh-CN.d.ts.map +0 -1
  135. package/lib/types/locale/function-list/compatibility/en-US.d.ts.map +0 -1
  136. package/lib/types/locale/function-list/compatibility/zh-CN.d.ts.map +0 -1
  137. package/lib/types/locale/function-list/cube/en-US.d.ts.map +0 -1
  138. package/lib/types/locale/function-list/cube/zh-CN.d.ts.map +0 -1
  139. package/lib/types/locale/function-list/database/en-US.d.ts.map +0 -1
  140. package/lib/types/locale/function-list/database/zh-CN.d.ts.map +0 -1
  141. package/lib/types/locale/function-list/date/en-US.d.ts.map +0 -1
  142. package/lib/types/locale/function-list/date/zh-CN.d.ts.map +0 -1
  143. package/lib/types/locale/function-list/engineering/en-US.d.ts.map +0 -1
  144. package/lib/types/locale/function-list/engineering/zh-CN.d.ts.map +0 -1
  145. package/lib/types/locale/function-list/financial/en-US.d.ts.map +0 -1
  146. package/lib/types/locale/function-list/financial/zh-CN.d.ts.map +0 -1
  147. package/lib/types/locale/function-list/information/en-US.d.ts.map +0 -1
  148. package/lib/types/locale/function-list/information/zh-CN.d.ts.map +0 -1
  149. package/lib/types/locale/function-list/logical/en-US.d.ts.map +0 -1
  150. package/lib/types/locale/function-list/logical/zh-CN.d.ts.map +0 -1
  151. package/lib/types/locale/function-list/lookup/en-US.d.ts.map +0 -1
  152. package/lib/types/locale/function-list/lookup/zh-CN.d.ts.map +0 -1
  153. package/lib/types/locale/function-list/math/en-US.d.ts.map +0 -1
  154. package/lib/types/locale/function-list/math/zh-CN.d.ts.map +0 -1
  155. package/lib/types/locale/function-list/statistical/en-US.d.ts.map +0 -1
  156. package/lib/types/locale/function-list/statistical/zh-CN.d.ts.map +0 -1
  157. package/lib/types/locale/function-list/text/en-US.d.ts.map +0 -1
  158. package/lib/types/locale/function-list/text/zh-CN.d.ts.map +0 -1
  159. package/lib/types/locale/function-list/univer/en-US.d.ts.map +0 -1
  160. package/lib/types/locale/function-list/univer/zh-CN.d.ts.map +0 -1
  161. package/lib/types/locale/function-list/web/en-US.d.ts.map +0 -1
  162. package/lib/types/locale/function-list/web/zh-CN.d.ts.map +0 -1
  163. package/lib/types/locale/index.d.ts.map +0 -1
  164. package/lib/types/locale/zh-CN.d.ts.map +0 -1
  165. package/lib/types/services/description.service.d.ts.map +0 -1
  166. package/lib/types/services/formula-input.service.d.ts.map +0 -1
  167. package/lib/types/services/function-list/array.d.ts.map +0 -1
  168. package/lib/types/services/function-list/compatibility.d.ts.map +0 -1
  169. package/lib/types/services/function-list/cube.d.ts.map +0 -1
  170. package/lib/types/services/function-list/database.d.ts.map +0 -1
  171. package/lib/types/services/function-list/date.d.ts.map +0 -1
  172. package/lib/types/services/function-list/engineering.d.ts.map +0 -1
  173. package/lib/types/services/function-list/financial.d.ts.map +0 -1
  174. package/lib/types/services/function-list/function-list.d.ts.map +0 -1
  175. package/lib/types/services/function-list/information.d.ts.map +0 -1
  176. package/lib/types/services/function-list/logical.d.ts.map +0 -1
  177. package/lib/types/services/function-list/lookup.d.ts.map +0 -1
  178. package/lib/types/services/function-list/math.d.ts.map +0 -1
  179. package/lib/types/services/function-list/statistical.d.ts.map +0 -1
  180. package/lib/types/services/function-list/text.d.ts.map +0 -1
  181. package/lib/types/services/function-list/univer.d.ts.map +0 -1
  182. package/lib/types/services/function-list/web.d.ts.map +0 -1
  183. package/lib/types/services/prompt.service.d.ts.map +0 -1
  184. package/lib/types/services/utils.d.ts.map +0 -1
  185. package/lib/types/views/FormulaPromptContainer.d.ts.map +0 -1
  186. package/lib/types/views/more-functions/MoreFunctions.d.ts.map +0 -1
  187. package/lib/types/views/more-functions/function-help/FunctionHelp.d.ts.map +0 -1
  188. package/lib/types/views/more-functions/function-params/FunctionParams.d.ts.map +0 -1
  189. package/lib/types/views/more-functions/input-params/InputParams.d.ts.map +0 -1
  190. package/lib/types/views/more-functions/interface.d.ts.map +0 -1
  191. package/lib/types/views/more-functions/select-function/SelectFunction.d.ts.map +0 -1
  192. package/lib/types/views/prompt/error-function/error-function.d.ts.map +0 -1
  193. package/lib/types/views/prompt/help-function/HelpFunction.d.ts.map +0 -1
  194. package/lib/types/views/prompt/search-function/SearchFunction.d.ts.map +0 -1
@@ -0,0 +1,4346 @@
1
+ var Wn = Object.defineProperty;
2
+ var Hn = (i, e, t) => e in i ? Wn(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var F = (i, e, t) => (Hn(i, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { Disposable as V, ObjectMatrix as D, Dimension as z, OnLifecycle as Y, LifecycleStages as X, IUniverInstanceService as ve, ICommandService as Z, isFormulaString as _e, isFormulaId as At, Tools as G, Direction as L, CommandType as se, toDisposable as U, ThemeService as nn, deserializeRangeWithSheet as Se, AbsoluteRefType as k, serializeRange as gt, Rectangle as je, getCellValueType as Kn, CellValueType as Gn, LocaleService as Ce, IContextService as yt, FOCUSING_FORMULA_EDITOR as rn, FOCUSING_EDITOR_INPUT_FORMULA as Le, DisposableCollection as zn, serializeRangeToRefString as Be, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as Dt, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Pt, RANGE_TYPE as pe, Plugin as Yn, PluginType as Xn } from "@univerjs/core";
5
+ import { createIdentifier as Je, Inject as x, Injector as et } from "@wendellhu/redi";
6
+ import { FormulaDataModel as tt, SetArrayFormulaDataMutation as pt, LexerTreeBuilder as Re, SetFormulaCalculationResultMutation as Zn, sequenceNodeType as K, matchToken as H, FUNCTION_NAMES_MATH as Ut, FunctionType as me, FUNCTION_NAMES_STATISTICAL as Ae, IFunctionService as Qn, isFormulaLexerToken as Jn, normalizeSheetName as er, includeFormulaLexerToken as tr, generateStringWithSequence as on, SetFormulaCalculationStartMutation as kt, SetFormulaCalculationNotificationMutation as nr, FormulaExecutedStateType as De, SetFormulaDataMutation as Pe, initSheetFormulaData as rr } from "@univerjs/engine-formula";
7
+ import { SetRangeValuesMutation as re, SetStyleCommand as sn, MoveRangeMutation as $t, MoveRowsMutation as jt, MoveColsMutation as Bt, DeleteRangeMutation as qt, InsertRangeMutation as Vt, RemoveRowMutation as Wt, RemoveColMutation as Ht, RemoveSheetMutation as _t, InsertSheetMutation as St, INTERCEPTOR_POINT as ir, SheetInterceptorService as an, SetRangeValuesUndoMutationFactory as cn, SetRangeValuesCommand as or, SelectionManagerService as Mt, getCellAtRowCol as sr, SetSelectionsOperation as ar, NORMAL_SELECTION_PLUGIN_NAME as Me, convertSelectionDataToRange as st, getNormalSelectionStyle as cr, DeleteRangeMoveLeftCommand as ln, DeleteRangeMoveUpCommand as un, RemoveColCommand as mn, RemoveRowCommand as dn, InsertRangeMoveDownCommand as hn, InsertRangeMoveRightCommand as fn, InsertColCommand as gn, InsertRowCommand as pn, MoveColsCommand as _n, MoveRowsCommand as Sn, MoveRangeCommand as vn, handleInsertRangeMutation as nt, handleDeleteRangeMutation as rt, SetWorksheetNameCommand as lr, handleMoveRange as ur, EffectRefRangId as Q, runRefRangeMutations as J, handleInsertRow as mr, handleInsertCol as dr, handleIRemoveRow as hr, handleIRemoveCol as fr, handleDeleteRangeMoveLeft as gr, handleDeleteRangeMoveUp as pr, handleInsertRangeMoveDown as _r, handleInsertRangeMoveRight as Sr } from "@univerjs/sheets";
8
+ import { DATA_TYPE as Kt, APPLY_TYPE as vr, IAutoFillService as Cr, SheetPasteCommand as Rr, ISheetClipboardService as Ir, COPY_TYPE as yr, SelectionShape as Mr, IEditorBridgeService as bt, SheetSkeletonManagerService as Cn, ISelectionRenderService as Rn, getEditorObject as vt, ICellEditorManagerService as Ft, IFormulaEditorManagerService as In, RangeSelector as br, PASTE_SPECIAL_MENU_ID as Fr, whenEditorInputFormulaActivated as Ne, SetEditorResizeOperation as Nr, MoveSelectionCommand as Ue, JumpOver as Gt, ExpandSelectionCommand as zt } from "@univerjs/sheets-ui";
9
+ import { TinyColor as yn } from "@ctrl/tinycolor";
10
+ import { IRenderManagerService as Nt, DeviceInputEventType as ie, ITextSelectionRenderManager as Mn, getCellInfoInMergeData as wr } from "@univerjs/engine-render";
11
+ import { KeyCode as A, ISidebarService as bn, MenuGroup as xr, MenuItemType as wt, MenuPosition as Tr, MetaKeys as oe, ComponentManager as Or, IMenuService as Er, IShortcutService as Lr, IUIController as Ar } from "@univerjs/ui";
12
+ import { Subject as ne } from "rxjs";
13
+ import { useDependency as $, connectInjector as Dr } from "@wendellhu/redi/react-bindings";
14
+ import Pr, { useState as O, useEffect as Fe, forwardRef as we, useRef as Ur, createElement as xe } from "react";
15
+ import { Popup as Fn, Select as kr, Input as $r, Button as at } from "@univerjs/design";
16
+ import { ReplaceContentCommand as jr, MoveCursorOperation as Br, TextSelectionManagerService as qr, DocViewModelManagerService as Vr } from "@univerjs/docs";
17
+ const Nn = "formula-ui";
18
+ class Wr extends V {
19
+ constructor() {
20
+ super(...arguments);
21
+ F(this, "_dirtyConversionMap", /* @__PURE__ */ new Map());
22
+ }
23
+ dispose() {
24
+ this._dirtyConversionMap.clear();
25
+ }
26
+ remove(t) {
27
+ this._dirtyConversionMap.delete(t);
28
+ }
29
+ get(t) {
30
+ return this._dirtyConversionMap.get(t);
31
+ }
32
+ has(t) {
33
+ return this._dirtyConversionMap.has(t);
34
+ }
35
+ register(t, n) {
36
+ this._dirtyConversionMap.set(t, n);
37
+ }
38
+ getDirtyConversionMap() {
39
+ return this._dirtyConversionMap;
40
+ }
41
+ }
42
+ const xt = Je(
43
+ "univer.formula.active-dirty-manager.service"
44
+ );
45
+ var Hr = Object.defineProperty, Kr = Object.getOwnPropertyDescriptor, Gr = (i, e, t, n) => {
46
+ for (var r = n > 1 ? void 0 : n ? Kr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
47
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
48
+ return n && r && Hr(e, t, r), r;
49
+ }, ct = (i, e) => (t, n) => e(t, n, i);
50
+ let qe = class extends V {
51
+ constructor(i, e, t) {
52
+ super(), this._activeDirtyManagerService = i, this._currentUniverService = e, this._formulaDataModel = t, this._initialize();
53
+ }
54
+ _initialize() {
55
+ this._initialConversion();
56
+ }
57
+ _initialConversion() {
58
+ this._activeDirtyManagerService.register(re.id, {
59
+ commandId: re.id,
60
+ getDirtyData: (i) => {
61
+ const e = i.params;
62
+ return e.trigger === sn.id ? {} : {
63
+ dirtyRanges: this._getSetRangeValuesMutationDirtyRange(e)
64
+ };
65
+ }
66
+ }), this._activeDirtyManagerService.register($t.id, {
67
+ commandId: $t.id,
68
+ getDirtyData: (i) => {
69
+ const e = i.params;
70
+ return {
71
+ dirtyRanges: this._getMoveRangeMutationDirtyRange(e)
72
+ };
73
+ }
74
+ }), this._activeDirtyManagerService.register(jt.id, {
75
+ commandId: jt.id,
76
+ getDirtyData: (i) => {
77
+ const e = i.params;
78
+ return {
79
+ dirtyRanges: this._getMoveRowsMutationDirtyRange(e)
80
+ };
81
+ }
82
+ }), this._activeDirtyManagerService.register(Bt.id, {
83
+ commandId: Bt.id,
84
+ getDirtyData: (i) => {
85
+ const e = i.params;
86
+ return {
87
+ dirtyRanges: this._getMoveRowsMutationDirtyRange(e)
88
+ };
89
+ }
90
+ }), this._activeDirtyManagerService.register(qt.id, {
91
+ commandId: qt.id,
92
+ getDirtyData: (i) => {
93
+ const e = i.params;
94
+ return {
95
+ dirtyRanges: this._getDeleteRangeMutationDirtyRange(e)
96
+ };
97
+ }
98
+ }), this._activeDirtyManagerService.register(Vt.id, {
99
+ commandId: Vt.id,
100
+ getDirtyData: (i) => {
101
+ const e = i.params;
102
+ return {
103
+ dirtyRanges: this._getDeleteRangeMutationDirtyRange(e)
104
+ };
105
+ }
106
+ }), this._activeDirtyManagerService.register(Wt.id, {
107
+ commandId: Wt.id,
108
+ getDirtyData: (i) => {
109
+ const e = i.params;
110
+ return {
111
+ dirtyRanges: this._getRemoveRowOrColumnMutation(e, !0)
112
+ };
113
+ }
114
+ }), this._activeDirtyManagerService.register(Ht.id, {
115
+ commandId: Ht.id,
116
+ getDirtyData: (i) => {
117
+ const e = i.params;
118
+ return {
119
+ dirtyRanges: this._getRemoveRowOrColumnMutation(e, !1)
120
+ };
121
+ }
122
+ }), this._activeDirtyManagerService.register(_t.id, {
123
+ commandId: _t.id,
124
+ getDirtyData: (i) => {
125
+ const e = i.params;
126
+ return { dirtyNameMap: this._getRemoveSheetMutation(e) };
127
+ }
128
+ }), this._activeDirtyManagerService.register(St.id, {
129
+ commandId: St.id,
130
+ getDirtyData: (i) => {
131
+ const e = i.params;
132
+ return { dirtyNameMap: this._getInsertSheetMutation(e) };
133
+ }
134
+ });
135
+ }
136
+ _getSetRangeValuesMutationDirtyRange(i) {
137
+ const { worksheetId: e, workbookId: t, cellValue: n } = i, r = [];
138
+ return n == null || (r.push(...this._getDirtyRangesByCellValue(t, e, n)), r.push(...this._getDirtyRangesForArrayFormula(t, e, n))), r;
139
+ }
140
+ _getMoveRangeMutationDirtyRange(i) {
141
+ const { worksheetId: e, workbookId: t, from: n, to: r } = i, o = [];
142
+ return o.push(...this._getDirtyRangesByCellValue(t, e, n)), o.push(...this._getDirtyRangesByCellValue(t, e, r)), o.push(...this._getDirtyRangesForArrayFormula(t, e, r)), o;
143
+ }
144
+ _getMoveRowsMutationDirtyRange(i) {
145
+ const { worksheetId: e, workbookId: t, sourceRange: n, targetRange: r } = i, o = [], s = this._rangeToMatrix(n).getData(), a = this._rangeToMatrix(r).getData();
146
+ return o.push(...this._getDirtyRangesByCellValue(t, e, s)), o.push(...this._getDirtyRangesByCellValue(t, e, a)), o.push(...this._getDirtyRangesForArrayFormula(t, e, a)), o;
147
+ }
148
+ _getDeleteRangeMutationDirtyRange(i) {
149
+ const { worksheetId: e, workbookId: t, ranges: n, shiftDimension: r } = i, o = [], s = this._currentUniverService.getUniverSheetInstance(t), a = s == null ? void 0 : s.getSheetBySheetId(e), c = (a == null ? void 0 : a.getLastRowWithContent()) || 0, l = (a == null ? void 0 : a.getLastColumnWithContent()) || 0, d = new D();
150
+ for (const m of n) {
151
+ let f = null;
152
+ const { startRow: p, startColumn: v, endRow: u, endColumn: _ } = m;
153
+ r === z.ROWS ? f = this._rangeToMatrix({
154
+ startRow: p,
155
+ startColumn: v,
156
+ endRow: c,
157
+ endColumn: _
158
+ }) : r === z.COLUMNS && (f = this._rangeToMatrix({
159
+ startRow: p,
160
+ startColumn: v,
161
+ endRow: u,
162
+ endColumn: l
163
+ })), f != null && d.merge(f);
164
+ }
165
+ const h = d.getData();
166
+ return o.push(...this._getDirtyRangesByCellValue(t, e, h)), o.push(...this._getDirtyRangesForArrayFormula(t, e, h)), o;
167
+ }
168
+ _getRemoveRowOrColumnMutation(i, e = !0) {
169
+ const { worksheetId: t, workbookId: n, ranges: r } = i, o = [], s = this._currentUniverService.getUniverSheetInstance(n), a = s == null ? void 0 : s.getSheetBySheetId(t), c = (a == null ? void 0 : a.getRowCount()) || 0, l = (a == null ? void 0 : a.getColumnCount()) || 0, d = new D();
170
+ for (const m of r) {
171
+ let f = null;
172
+ const { startRow: p, endRow: v, startColumn: u, endColumn: _ } = m;
173
+ e === !0 ? f = this._rangeToMatrix({
174
+ startRow: p,
175
+ startColumn: 0,
176
+ endRow: v,
177
+ endColumn: l - 1
178
+ }) : f = this._rangeToMatrix({
179
+ startRow: 0,
180
+ startColumn: u,
181
+ endRow: c,
182
+ endColumn: _
183
+ }), f != null && d.merge(f);
184
+ }
185
+ const h = d.getData();
186
+ return o.push(...this._getDirtyRangesByCellValue(n, t, h)), o.push(...this._getDirtyRangesForArrayFormula(n, t, h)), o;
187
+ }
188
+ _getRemoveSheetMutation(i, e) {
189
+ const t = {}, { worksheetId: n, workbookId: r } = i;
190
+ return t[r] == null && (t[r] = {}), t[r][n] = e, t;
191
+ }
192
+ _getInsertSheetMutation(i, e) {
193
+ const t = {}, { sheet: n, workbookId: r } = i;
194
+ return t[r] == null && (t[r] = {}), t[r][n.id] = e, t;
195
+ }
196
+ _rangeToMatrix(i) {
197
+ const e = new D(), { startRow: t, startColumn: n, endRow: r, endColumn: o } = i;
198
+ for (let s = t; s <= r; s++)
199
+ for (let a = n; a <= o; a++)
200
+ e.setValue(s, a, {});
201
+ return e;
202
+ }
203
+ _getDirtyRangesByCellValue(i, e, t) {
204
+ const n = [];
205
+ return t == null || new D(t).getDiscreteRanges().forEach((s) => {
206
+ n.push({ unitId: i, sheetId: e, range: s });
207
+ }), n;
208
+ }
209
+ /**
210
+ * The array formula is a range where only the top-left corner contains the formula value.
211
+ * All other positions, apart from the top-left corner, need to be marked as dirty.
212
+ */
213
+ _getDirtyRangesForArrayFormula(i, e, t) {
214
+ var s, a;
215
+ const n = [];
216
+ if (t == null)
217
+ return n;
218
+ const r = new D(t), o = this._formulaDataModel.getArrayFormulaRange();
219
+ if ((s = o == null ? void 0 : o[i]) != null && s[e]) {
220
+ const c = new D((a = o == null ? void 0 : o[i]) == null ? void 0 : a[e]);
221
+ r.forValue((l, d) => {
222
+ c.forValue((h, m, f) => {
223
+ const { startRow: p, startColumn: v, endRow: u, endColumn: _ } = f;
224
+ l >= p && l <= u && d >= v && d <= _ && n.push({
225
+ unitId: i,
226
+ sheetId: e,
227
+ range: {
228
+ startRow: p,
229
+ startColumn: v,
230
+ endRow: p,
231
+ endColumn: v
232
+ }
233
+ });
234
+ });
235
+ });
236
+ }
237
+ return n;
238
+ }
239
+ };
240
+ qe = Gr([
241
+ Y(X.Ready, qe),
242
+ ct(0, xt),
243
+ ct(1, ve),
244
+ ct(2, x(tt))
245
+ ], qe);
246
+ var zr = Object.defineProperty, Yr = Object.getOwnPropertyDescriptor, Xr = (i, e, t, n) => {
247
+ for (var r = n > 1 ? void 0 : n ? Yr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
248
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
249
+ return n && r && zr(e, t, r), r;
250
+ }, lt = (i, e) => (t, n) => e(t, n, i);
251
+ let Ve = class extends V {
252
+ constructor(i, e, t) {
253
+ super(), this._commandService = i, this._sheetInterceptorService = e, this._formulaDataModel = t, this._initialize();
254
+ }
255
+ _initialize() {
256
+ this._commandExecutedListener(), this._initInterceptorCellContent();
257
+ }
258
+ _commandExecutedListener() {
259
+ this.disposeWithMe(
260
+ this._commandService.onCommandExecuted((i) => {
261
+ if (i.id !== pt.id)
262
+ return;
263
+ const e = i.params;
264
+ if (e == null)
265
+ return;
266
+ const { arrayFormulaRange: t, arrayFormulaCellData: n } = e;
267
+ this._formulaDataModel.setArrayFormulaRange(t), this._formulaDataModel.setArrayFormulaCellData(n);
268
+ })
269
+ );
270
+ }
271
+ _initInterceptorCellContent() {
272
+ this.disposeWithMe(
273
+ this._sheetInterceptorService.intercept(ir.CELL_CONTENT, {
274
+ priority: 100,
275
+ handler: (i, e, t) => {
276
+ var h, m, f, p, v, u;
277
+ const { workbookId: n, worksheetId: r, row: o, col: s } = e, a = this._formulaDataModel.getArrayFormulaCellData(), c = this._formulaDataModel.getArrayFormulaRange(), l = (f = (m = (h = a == null ? void 0 : a[n]) == null ? void 0 : h[r]) == null ? void 0 : m[o]) == null ? void 0 : f[s], d = (u = (v = (p = c == null ? void 0 : c[n]) == null ? void 0 : p[r]) == null ? void 0 : v[o]) == null ? void 0 : u[s];
278
+ return l == null || d != null && d.startRow === o && d.startColumn === s ? t(i) : t({ ...i, ...l });
279
+ }
280
+ })
281
+ );
282
+ }
283
+ };
284
+ Ve = Xr([
285
+ Y(X.Ready, Ve),
286
+ lt(0, Z),
287
+ lt(1, x(an)),
288
+ lt(2, x(tt))
289
+ ], Ve);
290
+ var Zr = Object.defineProperty, Qr = Object.getOwnPropertyDescriptor, Jr = (i, e, t, n) => {
291
+ for (var r = n > 1 ? void 0 : n ? Qr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
292
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
293
+ return n && r && Zr(e, t, r), r;
294
+ }, Yt = (i, e) => (t, n) => e(t, n, i);
295
+ let We = class extends V {
296
+ constructor(i, e) {
297
+ super(), this._autoFillService = i, this._lexerTreeBuilder = e, this._initialize();
298
+ }
299
+ _initialize() {
300
+ this._registerAutoFill();
301
+ }
302
+ _registerAutoFill() {
303
+ const i = {
304
+ type: Kt.FORMULA,
305
+ priority: 1001,
306
+ match: (e) => _e(e == null ? void 0 : e.f) || At(e == null ? void 0 : e.si),
307
+ isContinue: (e, t) => e.type === Kt.FORMULA,
308
+ applyFunctions: {
309
+ [vr.COPY]: (e, t, n, r) => {
310
+ const { data: o, index: s } = e;
311
+ return this._fillCopyFormula(o, t, n, s, r);
312
+ }
313
+ }
314
+ };
315
+ this._autoFillService.registerRule(i);
316
+ }
317
+ _fillCopyFormula(i, e, t, n, r) {
318
+ var c, l;
319
+ const o = ti(r), s = [], a = /* @__PURE__ */ new Map();
320
+ for (let d = 1; d <= e; d++) {
321
+ const h = (d - 1) % i.length, m = G.deepClone(i[h]);
322
+ if (m) {
323
+ const f = ((c = i[h]) == null ? void 0 : c.f) || "", p = ((l = i[h]) == null ? void 0 : l.si) || "", v = _e(f);
324
+ if (At(p))
325
+ m.si = p, m.f = null, m.v = null, m.p = null, t === L.DOWN || t === L.RIGHT ? s.push(m) : s.unshift(m);
326
+ else if (v) {
327
+ let _ = a.get(h);
328
+ if (_)
329
+ m.si = _, m.f = null, m.v = null, m.p = null;
330
+ else {
331
+ _ = G.generateRandomId(6), a.set(h, _);
332
+ const { offsetX: g, offsetY: C } = ei(o, t), b = this._lexerTreeBuilder.moveFormulaRefOffset(
333
+ f,
334
+ g,
335
+ C
336
+ );
337
+ m.si = _, m.f = b, m.v = null, m.p = null;
338
+ }
339
+ t === L.DOWN || t === L.RIGHT ? s.push(m) : s.unshift(m);
340
+ }
341
+ }
342
+ }
343
+ return s;
344
+ }
345
+ };
346
+ We = Jr([
347
+ Y(X.Ready, We),
348
+ Yt(0, Cr),
349
+ Yt(1, x(Re))
350
+ ], We);
351
+ function ei(i, e) {
352
+ let t = 0, n = 0;
353
+ switch (e) {
354
+ case L.UP:
355
+ n = -i;
356
+ break;
357
+ case L.RIGHT:
358
+ t = i;
359
+ break;
360
+ case L.DOWN:
361
+ n = i;
362
+ break;
363
+ case L.LEFT:
364
+ t = -i;
365
+ break;
366
+ }
367
+ return { offsetX: t, offsetY: n };
368
+ }
369
+ function ti(i) {
370
+ let e = 0;
371
+ for (const t in i)
372
+ i[t].forEach((n) => {
373
+ e += n.data.length;
374
+ });
375
+ return e;
376
+ }
377
+ const wn = "special-paste-formula", xn = {
378
+ id: "sheet.command.paste-formula",
379
+ type: se.COMMAND,
380
+ handler: async (i) => i.get(Z).executeCommand(Rr.id, {
381
+ value: wn
382
+ })
383
+ };
384
+ var ni = Object.defineProperty, ri = Object.getOwnPropertyDescriptor, ii = (i, e, t, n) => {
385
+ for (var r = n > 1 ? void 0 : n ? ri(e, t) : e, o = i.length - 1, s; o >= 0; o--)
386
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
387
+ return n && r && ni(e, t, r), r;
388
+ }, ke = (i, e) => (t, n) => e(t, n, i);
389
+ const oi = "default-paste-formula";
390
+ let He = class extends V {
391
+ constructor(i, e, t, n) {
392
+ super(), this._currentUniverSheet = i, this._lexerTreeBuilder = e, this._sheetClipboardService = t, this._injector = n, this._initialize();
393
+ }
394
+ _initialize() {
395
+ this._registerClipboardHook();
396
+ }
397
+ _registerClipboardHook() {
398
+ this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())), this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()));
399
+ }
400
+ _pasteFormulaHook() {
401
+ return {
402
+ hookName: wn,
403
+ specialPasteInfo: {
404
+ label: "specialPaste.formula"
405
+ },
406
+ onPasteCells: (e, t, n, r) => {
407
+ const o = this._currentUniverSheet.getCurrentUniverSheetInstance(), s = o.getUnitId(), a = o.getActiveSheet().getSheetId();
408
+ return this._injector.invoke(
409
+ (c) => Xt(
410
+ s,
411
+ a,
412
+ e,
413
+ t,
414
+ c,
415
+ r,
416
+ this._lexerTreeBuilder,
417
+ !0
418
+ )
419
+ );
420
+ }
421
+ };
422
+ }
423
+ _pasteWithFormulaHook() {
424
+ return {
425
+ hookName: oi,
426
+ onPasteCells: (e, t, n, r) => {
427
+ const o = this._currentUniverSheet.getCurrentUniverSheetInstance(), s = o.getUnitId(), a = o.getActiveSheet().getSheetId();
428
+ return this._injector.invoke(
429
+ (c) => Xt(
430
+ s,
431
+ a,
432
+ e,
433
+ t,
434
+ c,
435
+ r,
436
+ this._lexerTreeBuilder
437
+ )
438
+ );
439
+ }
440
+ };
441
+ }
442
+ };
443
+ He = ii([
444
+ Y(X.Ready, He),
445
+ ke(0, ve),
446
+ ke(1, x(Re)),
447
+ ke(2, Ir),
448
+ ke(3, x(et))
449
+ ], He);
450
+ function Xt(i, e, t, n, r, o, s, a = !1) {
451
+ const c = [], l = [], { startColumn: d, startRow: h } = t, m = new D(), f = /* @__PURE__ */ new Map();
452
+ let p = 0, v = 0, u = 0, _ = 0;
453
+ if (o) {
454
+ const { copyType: b, copyRange: y } = o;
455
+ b === yr.COPY && y && (u = y.startRow, _ = y.startColumn, p = y.endRow - u + 1, v = y.endColumn - _ + 1);
456
+ }
457
+ n.forValue((b, y, R) => {
458
+ const I = R.f || "", N = {};
459
+ if (a && (N.v = R.v), _e(I) && p && v) {
460
+ const E = b % p, M = y % v, T = `${E}_${M}`;
461
+ let w = f.get(T);
462
+ if (w)
463
+ N.si = w, N.f = null, N.v = null, N.p = null;
464
+ else {
465
+ w = G.generateRandomId(6), f.set(T, w);
466
+ const W = y + d - (_ + M), j = b + h - (u + E), ae = s.moveFormulaRefOffset(I, W, j);
467
+ N.si = w, N.f = ae, N.v = null, N.p = null;
468
+ }
469
+ }
470
+ m.setValue(b + h, y + d, N);
471
+ });
472
+ const g = {
473
+ workbookId: i,
474
+ worksheetId: e,
475
+ cellValue: m.getData()
476
+ };
477
+ c.push({
478
+ id: re.id,
479
+ params: g
480
+ });
481
+ const C = cn(
482
+ r,
483
+ g
484
+ );
485
+ return l.push({
486
+ id: re.id,
487
+ params: C
488
+ }), {
489
+ undos: l,
490
+ redos: c
491
+ };
492
+ }
493
+ var si = Object.defineProperty, ai = Object.getOwnPropertyDescriptor, ci = (i, e, t, n) => {
494
+ for (var r = n > 1 ? void 0 : n ? ai(e, t) : e, o = i.length - 1, s; o >= 0; o--)
495
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
496
+ return n && r && si(e, t, r), r;
497
+ }, te = (i, e) => (t, n) => e(t, n, i);
498
+ let Ke = class extends V {
499
+ constructor(e, t, n, r, o, s, a, c) {
500
+ super();
501
+ F(this, "_previousShape");
502
+ this._editorBridgeService = e, this._formulaDataModel = t, this._lexerTreeBuilder = n, this._themeService = r, this._renderManagerService = o, this._selectionRenderService = s, this._sheetSkeletonManagerService = a, this._commandService = c, this._initInterceptorEditorStart(), this._commandExecutedListener();
503
+ }
504
+ _initInterceptorEditorStart() {
505
+ this.disposeWithMe(
506
+ U(
507
+ this._editorBridgeService.interceptor.intercept(
508
+ this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,
509
+ {
510
+ handler: (e, t, n) => {
511
+ var f, p, v, u;
512
+ const { row: r, col: o, workbookId: s, worksheetId: a } = t, c = this._formulaDataModel.getArrayFormulaRange(), l = this._formulaDataModel.getArrayFormulaCellData();
513
+ if (this._removeArrayFormulaRangeShape(), e == null)
514
+ return n(e);
515
+ let d = null;
516
+ const h = this._formulaDataModel.getFormulaDataItem(
517
+ r,
518
+ o,
519
+ a,
520
+ s
521
+ );
522
+ if (h != null) {
523
+ const { f: _, si: g, x: C = 0, y: b = 0 } = h;
524
+ if (g != null && (C > 0 || b > 0)) {
525
+ let y = "";
526
+ if (_.length > 0)
527
+ y = _;
528
+ else {
529
+ const I = this._formulaDataModel.getFormulaItemBySId(
530
+ g,
531
+ a,
532
+ s
533
+ );
534
+ if (I == null || I.f.length === 0)
535
+ return n(e);
536
+ y = I.f;
537
+ }
538
+ d = { f: this._lexerTreeBuilder.moveFormulaRefOffset(
539
+ y,
540
+ C,
541
+ b
542
+ ) };
543
+ }
544
+ }
545
+ if (e.v != null && e.v !== "" && ((v = (p = (f = l[s]) == null ? void 0 : f[a]) == null ? void 0 : p[r]) == null ? void 0 : v[o]) == null)
546
+ return d || n(e);
547
+ const m = (u = c == null ? void 0 : c[s]) == null ? void 0 : u[a];
548
+ return m != null && new D(m).forValue((_, g, C) => {
549
+ if (C == null)
550
+ return !0;
551
+ const { startRow: b, startColumn: y, endRow: R, endColumn: I } = C;
552
+ if (_ === r && g === o)
553
+ return this._createArrayFormulaRangeShape(C, s), !1;
554
+ if (r >= b && r <= R && o >= y && o <= I) {
555
+ const N = this._formulaDataModel.getFormulaDataItem(
556
+ _,
557
+ g,
558
+ a,
559
+ s
560
+ );
561
+ return N == null || N.f == null ? !0 : (d == null && (d = {
562
+ f: N.f,
563
+ isInArrayFormulaRange: !0
564
+ }), this._createArrayFormulaRangeShape(C, s), !1);
565
+ }
566
+ }), d || n(e);
567
+ }
568
+ }
569
+ )
570
+ )
571
+ );
572
+ }
573
+ _commandExecutedListener() {
574
+ this.disposeWithMe(
575
+ this._commandService.onCommandExecuted((e) => {
576
+ e.id === Zn.id && this._removeArrayFormulaRangeShape();
577
+ })
578
+ );
579
+ }
580
+ _createArrayFormulaRangeShape(e, t) {
581
+ var f;
582
+ const n = this._themeService.getCurrentTheme(), r = new yn(n.colorWhite).setAlpha(0).toString(), o = {
583
+ strokeWidth: 1,
584
+ stroke: n.hyacinth700,
585
+ fill: r,
586
+ widgets: {},
587
+ hasAutoFill: !1,
588
+ hasRowHeader: !1,
589
+ hasColumnHeader: !1
590
+ }, { scene: s } = this._renderManagerService.getRenderById(t) || {}, { rangeWithCoord: a, primaryWithCoord: c } = this._selectionRenderService.convertSelectionRangeToData({
591
+ range: e,
592
+ primary: null,
593
+ style: o
594
+ }), l = (f = this._sheetSkeletonManagerService.getCurrent()) == null ? void 0 : f.skeleton;
595
+ if (!s || !l)
596
+ return;
597
+ const { rowHeaderWidth: d, columnHeaderHeight: h } = l, m = new Mr(s, 100, !1, this._themeService);
598
+ m.update(a, d, h, o, c), this._previousShape = m;
599
+ }
600
+ _removeArrayFormulaRangeShape() {
601
+ this._previousShape != null && (this._previousShape.dispose(), this._previousShape = null);
602
+ }
603
+ };
604
+ Ke = ci([
605
+ Y(X.Rendered, Ke),
606
+ te(0, x(bt)),
607
+ te(1, x(tt)),
608
+ te(2, x(Re)),
609
+ te(3, x(nn)),
610
+ te(4, Nt),
611
+ te(5, Rn),
612
+ te(6, x(Cn)),
613
+ te(7, Z)
614
+ ], Ke);
615
+ const Tt = {
616
+ id: "formula-ui.operation.change-ref-to-absolute",
617
+ type: se.OPERATION,
618
+ handler: async (i) => !0
619
+ };
620
+ class li {
621
+ constructor() {
622
+ F(this, "_sequenceNodes", []);
623
+ F(this, "_isSelectionMoving", !1);
624
+ F(this, "_isLockedOnSelectionChangeRefString", !1);
625
+ F(this, "_isLockedOnSelectionInsertRefString", !1);
626
+ F(this, "_syncToEditor$", new ne());
627
+ F(this, "syncToEditor$", this._syncToEditor$.asObservable());
628
+ F(this, "_changeRef$", new ne());
629
+ F(this, "changeRef$", this._changeRef$.asObservable());
630
+ F(this, "_inputFormula$", new ne());
631
+ F(this, "inputFormula$", this._inputFormula$.asObservable());
632
+ }
633
+ dispose() {
634
+ this._sequenceNodes = [];
635
+ }
636
+ inputFormula(e) {
637
+ this._inputFormula$.next(e);
638
+ }
639
+ syncToEditor(e) {
640
+ this._syncToEditor$.next({ sequences: this.getSequenceNodes(), textSelectionOffset: e });
641
+ }
642
+ getSequenceNodes() {
643
+ return [...this._sequenceNodes];
644
+ }
645
+ setSequenceNodes(e) {
646
+ this._sequenceNodes = e;
647
+ }
648
+ clearSequenceNodes() {
649
+ this._sequenceNodes = [];
650
+ }
651
+ getCurrentSequenceNode(e) {
652
+ return this._sequenceNodes[this.getCurrentSequenceNodeIndex(e)];
653
+ }
654
+ getCurrentSequenceNodeByIndex(e) {
655
+ return this._sequenceNodes[e];
656
+ }
657
+ /**
658
+ * Query the text coordinates in the sequenceNodes and determine the actual insertion index.
659
+ * @param sequenceNodes
660
+ * @param strIndex
661
+ * @returns
662
+ */
663
+ getCurrentSequenceNodeIndex(e) {
664
+ let t = 0;
665
+ for (let n = 0, r = this._sequenceNodes.length; n < r; n++) {
666
+ const o = this._sequenceNodes[n];
667
+ if (typeof o == "string")
668
+ t++;
669
+ else {
670
+ const { endIndex: s } = o;
671
+ t = s;
672
+ }
673
+ if (e <= t)
674
+ return n;
675
+ }
676
+ return this._sequenceNodes.length;
677
+ }
678
+ /**
679
+ * Synchronize the reference text based on the changes of the selection.
680
+ * @param refIndex
681
+ * @param rangeWithCoord
682
+ * @returns
683
+ */
684
+ updateSequenceRef(e, t) {
685
+ const n = this._sequenceNodes[e];
686
+ if (typeof n == "string" || n.nodeType !== K.REFERENCE)
687
+ return;
688
+ const r = t.length - n.token.length, o = { ...n };
689
+ o.token = t, o.endIndex += r, this._sequenceNodes[e] = o;
690
+ for (let s = e + 1, a = this._sequenceNodes.length; s < a; s++) {
691
+ const c = this._sequenceNodes[s];
692
+ if (typeof c == "string")
693
+ continue;
694
+ const l = { ...c };
695
+ l.startIndex += r, l.endIndex += r, this._sequenceNodes[s] = l;
696
+ }
697
+ this._changeRef$.next(!0);
698
+ }
699
+ /**
700
+ * When the cursor is on the right side of a formula token,
701
+ * you can add reference text to the formula by drawing a selection.
702
+ * @param index
703
+ * @param range
704
+ */
705
+ insertSequenceRef(e, t) {
706
+ const n = t.length, r = this.getCurrentSequenceNodeIndex(e);
707
+ this._sequenceNodes.splice(r, 0, {
708
+ token: t,
709
+ startIndex: e,
710
+ endIndex: e + n - 1,
711
+ nodeType: K.REFERENCE
712
+ });
713
+ for (let o = r + 1, s = this._sequenceNodes.length; o < s; o++) {
714
+ const a = this._sequenceNodes[o];
715
+ if (typeof a == "string")
716
+ continue;
717
+ const c = { ...a };
718
+ c.startIndex += n, c.endIndex += n, this._sequenceNodes[o] = c;
719
+ }
720
+ this._changeRef$.next(!0);
721
+ }
722
+ /**
723
+ * Insert a string at the cursor position in the text corresponding to the sequenceNodes.
724
+ * @param sequenceNodes
725
+ * @param index
726
+ * @param content
727
+ */
728
+ insertSequenceString(e, t) {
729
+ const n = this.getCurrentSequenceNodeIndex(e), r = t.split("");
730
+ this._sequenceNodes.splice(n, 0, ...r);
731
+ const o = r.length;
732
+ for (let s = n + o, a = this._sequenceNodes.length; s < a; s++) {
733
+ const c = this._sequenceNodes[s];
734
+ if (typeof c == "string")
735
+ continue;
736
+ const l = { ...c };
737
+ l.startIndex += o, l.endIndex += o, this._sequenceNodes[s] = l;
738
+ }
739
+ this._changeRef$.next(!0);
740
+ }
741
+ enableSelectionMoving() {
742
+ this._isSelectionMoving = !0;
743
+ }
744
+ disableSelectionMoving() {
745
+ this._isSelectionMoving = !1;
746
+ }
747
+ isSelectionMoving() {
748
+ return this._isSelectionMoving;
749
+ }
750
+ enableLockedSelectionChange() {
751
+ this._isLockedOnSelectionChangeRefString = !0;
752
+ }
753
+ disableLockedSelectionChange() {
754
+ this._isLockedOnSelectionChangeRefString = !1;
755
+ }
756
+ isLockedSelectionChange() {
757
+ return this._isLockedOnSelectionChangeRefString;
758
+ }
759
+ enableLockedSelectionInsert() {
760
+ this._isLockedOnSelectionInsertRefString = !0;
761
+ }
762
+ disableLockedSelectionInsert() {
763
+ this._isLockedOnSelectionInsertRefString = !1;
764
+ }
765
+ isLockedSelectionInsert() {
766
+ return this._isLockedOnSelectionInsertRefString;
767
+ }
768
+ }
769
+ const Te = Je("formula-ui.input-service");
770
+ var ui = Object.defineProperty, mi = Object.getOwnPropertyDescriptor, di = (i, e, t, n) => {
771
+ for (var r = n > 1 ? void 0 : n ? mi(e, t) : e, o = i.length - 1, s; o >= 0; o--)
772
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
773
+ return n && r && ui(e, t, r), r;
774
+ }, fe = (i, e) => (t, n) => e(t, n, i);
775
+ let Ge = class extends V {
776
+ constructor(e, t, n, r, o, s) {
777
+ super();
778
+ F(this, "_userCursorMove", !1);
779
+ this._commandService = e, this._textSelectionRenderManager = t, this._editorBridgeService = n, this._lexerTreeBuilder = r, this._renderManagerService = o, this._formulaInputService = s, this._initialize();
780
+ }
781
+ _initialize() {
782
+ this._commandExecutedListener(), this._initialEditorInputChange(), this._userMouseListener(), this._inputFormulaListener();
783
+ }
784
+ _initialEditorInputChange() {
785
+ this.disposeWithMe(
786
+ U(
787
+ this._textSelectionRenderManager.onInputBefore$.subscribe((e) => {
788
+ const t = e == null ? void 0 : e.event;
789
+ t != null && t.which !== A.F4 && (this._userCursorMove = !1);
790
+ })
791
+ )
792
+ );
793
+ }
794
+ _userMouseListener() {
795
+ const e = this._getEditorObject();
796
+ if (e == null)
797
+ return;
798
+ const { document: t } = e;
799
+ this.disposeWithMe(
800
+ U(
801
+ t.onPointerDownObserver.add(() => {
802
+ this._userCursorMove = !0;
803
+ })
804
+ )
805
+ );
806
+ }
807
+ _inputFormulaListener() {
808
+ this.disposeWithMe(
809
+ U(
810
+ this._formulaInputService.inputFormula$.subscribe((e) => {
811
+ this._editorBridgeService.isVisible().visible === !1 && this._editorBridgeService.changeVisible({
812
+ visible: !0,
813
+ eventType: ie.Dblclick
814
+ });
815
+ const n = this._lexerTreeBuilder.sequenceNodesBuilder(e) || [];
816
+ this._formulaInputService.setSequenceNodes(n), this._formulaInputService.syncToEditor(e.length - 1);
817
+ })
818
+ )
819
+ );
820
+ }
821
+ _changeRefString() {
822
+ const e = this._textSelectionRenderManager.getActiveRange();
823
+ if (e == null)
824
+ return;
825
+ const { startOffset: t } = e, n = t - 2, r = this._formulaInputService.getCurrentSequenceNodeIndex(n), o = this._formulaInputService.getCurrentSequenceNodeByIndex(r);
826
+ if (o == null || typeof o == "string" || o.nodeType !== K.REFERENCE)
827
+ return;
828
+ const s = o.token.split("!");
829
+ let a = o.token;
830
+ s.length > 1 && (a = s[s.length - 1]);
831
+ let c = "";
832
+ for (let h = 0, m = s.length; h < m - 1; h++)
833
+ c += s[h];
834
+ let l = a;
835
+ if (a.indexOf(H.COLON) > -1)
836
+ if (!this._userCursorMove)
837
+ l = this._changeRangeRef(a);
838
+ else {
839
+ const h = a.split(H.COLON), m = h[0], f = h[1];
840
+ n - o.startIndex <= m.length ? l = this._changeSingleRef(m) + H.COLON + f : l = m + H.COLON + this._changeSingleRef(f);
841
+ }
842
+ else
843
+ l = this._changeSingleRef(a);
844
+ l = c + l;
845
+ const d = l.length - o.token.length;
846
+ this._formulaInputService.updateSequenceRef(r, l), this._formulaInputService.syncToEditor(n + d + 1);
847
+ }
848
+ _changeRangeRef(e) {
849
+ const t = Se(e).range;
850
+ let n = "";
851
+ return t.startAbsoluteRefType === k.NONE || t.startAbsoluteRefType == null ? (t.startAbsoluteRefType = k.ALL, t.endAbsoluteRefType = k.ALL) : (t.startAbsoluteRefType = k.NONE, t.endAbsoluteRefType = k.NONE), n = gt(t), n;
852
+ }
853
+ _changeSingleRef(e) {
854
+ const t = Se(e).range, n = t.startAbsoluteRefType;
855
+ let r = "";
856
+ return n === k.NONE || n == null ? (t.startAbsoluteRefType = k.ALL, t.endAbsoluteRefType = k.ALL) : n === k.ALL ? (t.startAbsoluteRefType = k.ROW, t.endAbsoluteRefType = k.ROW) : n === k.ROW ? (t.startAbsoluteRefType = k.COLUMN, t.endAbsoluteRefType = k.COLUMN) : (t.startAbsoluteRefType = k.NONE, t.endAbsoluteRefType = k.NONE), r = gt(t), r;
857
+ }
858
+ _commandExecutedListener() {
859
+ const e = [Tt.id];
860
+ this.disposeWithMe(
861
+ this._commandService.onCommandExecuted((t) => {
862
+ e.includes(t.id) && this._changeRefString();
863
+ })
864
+ );
865
+ }
866
+ _getEditorObject() {
867
+ return vt(this._editorBridgeService.getCurrentEditorId(), this._renderManagerService);
868
+ }
869
+ };
870
+ Ge = di([
871
+ Y(X.Steady, Ge),
872
+ fe(0, Z),
873
+ fe(1, Mn),
874
+ fe(2, x(bt)),
875
+ fe(3, x(Re)),
876
+ fe(4, Nt),
877
+ fe(5, Te)
878
+ ], Ge);
879
+ const Tn = {
880
+ id: "formula-ui.command.insert-function",
881
+ type: se.COMMAND,
882
+ handler: async (i, e) => {
883
+ const { list: t } = e, n = i.get(Z), r = new D();
884
+ t.forEach((s) => {
885
+ const { range: a, primary: c, formula: l } = s, { row: d, column: h } = c, m = G.generateRandomId(6);
886
+ r.setValue(d, h, {
887
+ f: l,
888
+ si: m
889
+ });
890
+ const { startRow: f, startColumn: p, endRow: v, endColumn: u } = a;
891
+ for (let _ = f; _ <= v; _++)
892
+ for (let g = p; g <= u; g++)
893
+ (_ !== d || g !== h) && r.setValue(_, g, {
894
+ si: m
895
+ });
896
+ });
897
+ const o = {
898
+ value: r.getData()
899
+ };
900
+ return n.executeCommand(or.id, o);
901
+ }
902
+ }, Ie = {
903
+ id: "formula-ui.operation.select-editor-formula",
904
+ type: se.OPERATION,
905
+ handler: (i, e) => (
906
+ // const { eventType, keycode } = params;
907
+ // const formulaPromptService = accessor.get(IFormulaPromptService);
908
+ // const editorBridgeService = accessor.get(IEditorBridgeService);
909
+ // switch (keycode) {
910
+ // case KeyCode.ARROW_DOWN:
911
+ // formulaPromptService.navigate({ direction: Direction.DOWN });
912
+ // break;
913
+ // case KeyCode.ARROW_UP:
914
+ // formulaPromptService.navigate({ direction: Direction.UP });
915
+ // break;
916
+ // // case KeyCode.ENTER:
917
+ // // case KeyCode.TAB:
918
+ // // if (formulaPromptService.isSearching()) {
919
+ // // formulaPromptService.accept(true);
920
+ // // } else {
921
+ // // const editorBridgeParameters = {
922
+ // // visible: false,
923
+ // // eventType,
924
+ // // keycode,
925
+ // // };
926
+ // // editorBridgeService.changeVisible(editorBridgeParameters);
927
+ // // }
928
+ // // break;
929
+ // default:
930
+ // break;
931
+ // }
932
+ !0
933
+ )
934
+ }, de = Je("formula-ui.prompt-service");
935
+ class hi {
936
+ constructor() {
937
+ F(this, "_search$", new ne());
938
+ F(this, "_help$", new ne());
939
+ F(this, "_navigate$", new ne());
940
+ F(this, "_accept$", new ne());
941
+ F(this, "_acceptFormulaName$", new ne());
942
+ F(this, "search$", this._search$.asObservable());
943
+ F(this, "help$", this._help$.asObservable());
944
+ F(this, "navigate$", this._navigate$.asObservable());
945
+ F(this, "accept$", this._accept$.asObservable());
946
+ F(this, "acceptFormulaName$", this._acceptFormulaName$.asObservable());
947
+ F(this, "_searching", !1);
948
+ F(this, "_helping", !1);
949
+ F(this, "_isInsertRefString", !1);
950
+ }
951
+ dispose() {
952
+ this._search$.complete(), this._help$.complete(), this._navigate$.complete(), this._accept$.complete(), this._acceptFormulaName$.complete();
953
+ }
954
+ search(e) {
955
+ this._searching = e.visible, this._search$.next(e);
956
+ }
957
+ isSearching() {
958
+ return this._searching;
959
+ }
960
+ help(e) {
961
+ this._helping = e.visible, this._help$.next(e);
962
+ }
963
+ isHelping() {
964
+ return this._helping;
965
+ }
966
+ navigate(e) {
967
+ this._navigate$.next(e);
968
+ }
969
+ accept(e) {
970
+ this._accept$.next(e);
971
+ }
972
+ acceptFormulaName(e) {
973
+ this._acceptFormulaName$.next(e);
974
+ }
975
+ }
976
+ const Ct = {
977
+ id: "formula-ui.operation.help-function",
978
+ type: se.OPERATION,
979
+ handler: async (i, e) => (i.get(de).help(e), !0)
980
+ }, Ot = {
981
+ id: "formula-ui.operation.insert-function",
982
+ type: se.OPERATION,
983
+ handler: async (i, e) => {
984
+ const t = i.get(Mt), n = i.get(Te), r = t.getSelections();
985
+ if (!r || !r.length)
986
+ return !1;
987
+ const o = i.get(ve).getCurrentUniverSheetInstance(), s = o.getActiveSheet(), a = o.getUnitId(), c = s.getSheetId(), l = s.getCellMatrix(), { value: d } = e, h = i.get(Z), m = [];
988
+ let f = null, p = 0, v = 0;
989
+ if (r.some((u) => {
990
+ const { range: _, primary: g } = u, C = (g == null ? void 0 : g.actualRow) ?? _.startRow, b = (g == null ? void 0 : g.actualColumn) ?? _.startColumn, y = fi(l, C, b);
991
+ if (!y)
992
+ return f = _, p = C, v = b, !0;
993
+ const R = gt(y), I = `=${d}(${R})`;
994
+ return m.push({
995
+ range: _,
996
+ primary: {
997
+ row: C,
998
+ column: b
999
+ },
1000
+ formula: I
1001
+ }), !1;
1002
+ }), f) {
1003
+ const u = sr(p, v, s), _ = {
1004
+ range: je.clone(f),
1005
+ primary: {
1006
+ startRow: u.startRow,
1007
+ startColumn: u.startColumn,
1008
+ endRow: u.endRow,
1009
+ endColumn: u.endColumn,
1010
+ actualRow: p,
1011
+ actualColumn: v,
1012
+ isMerged: u.isMerged,
1013
+ isMergedMainCell: u.startRow === p && u.startColumn === v
1014
+ }
1015
+ }, g = {
1016
+ unitId: a,
1017
+ sheetId: c,
1018
+ pluginName: Me,
1019
+ selections: [_]
1020
+ };
1021
+ await h.executeCommand(ar.id, g), setTimeout(() => {
1022
+ n.inputFormula(`=${d}(`);
1023
+ }, 0);
1024
+ }
1025
+ return m.length === 0 ? !1 : h.executeCommand(Tn.id, {
1026
+ list: m
1027
+ });
1028
+ }
1029
+ };
1030
+ function fi(i, e, t) {
1031
+ const n = gi(i, e, t);
1032
+ if (n !== e)
1033
+ return {
1034
+ startRow: n,
1035
+ endRow: e - 1,
1036
+ startColumn: t,
1037
+ endColumn: t
1038
+ };
1039
+ const r = pi(i, e, t);
1040
+ return r !== t ? {
1041
+ startRow: e,
1042
+ endRow: e,
1043
+ startColumn: r,
1044
+ endColumn: t - 1
1045
+ } : null;
1046
+ }
1047
+ function gi(i, e, t) {
1048
+ let n = !1;
1049
+ if (e === 0)
1050
+ return e;
1051
+ for (let r = e - 1; r >= 0; r--) {
1052
+ const o = i.getValue(r, t);
1053
+ if (Qe(o) && !n) {
1054
+ if (r === 0)
1055
+ return 0;
1056
+ n = !0;
1057
+ } else {
1058
+ if (n && !Qe(o))
1059
+ return r + 1;
1060
+ if (n && r === 0)
1061
+ return 0;
1062
+ }
1063
+ }
1064
+ return e;
1065
+ }
1066
+ function pi(i, e, t) {
1067
+ let n = !1;
1068
+ if (t === 0)
1069
+ return t;
1070
+ for (let r = t - 1; r >= 0; r--) {
1071
+ const o = i.getValue(e, r);
1072
+ if (Qe(o) && !n) {
1073
+ if (r === 0)
1074
+ return 0;
1075
+ n = !0;
1076
+ } else {
1077
+ if (n && !Qe(o))
1078
+ return r + 1;
1079
+ if (n && r === 0)
1080
+ return 0;
1081
+ }
1082
+ }
1083
+ return t;
1084
+ }
1085
+ function Qe(i) {
1086
+ return i && (G.isStringNumber(i.v) || Kn(i) === Gn.NUMBER);
1087
+ }
1088
+ const On = `${Nn}_MORE_FUNCTIONS_COMPONENT`, En = {
1089
+ id: "formula-ui.operation.more-functions",
1090
+ type: se.OPERATION,
1091
+ handler: async (i) => (i.get(bn).open({
1092
+ header: { title: "formula.insert.tooltip" },
1093
+ children: { label: On }
1094
+ }), !0)
1095
+ }, Rt = {
1096
+ id: "formula-ui.operation.search-function",
1097
+ type: se.OPERATION,
1098
+ handler: async (i, e) => (i.get(de).search(e), !0)
1099
+ };
1100
+ var Ln = { exports: {} }, it = {};
1101
+ /**
1102
+ * @license React
1103
+ * react-jsx-runtime.production.min.js
1104
+ *
1105
+ * Copyright (c) Facebook, Inc. and its affiliates.
1106
+ *
1107
+ * This source code is licensed under the MIT license found in the
1108
+ * LICENSE file in the root directory of this source tree.
1109
+ */
1110
+ var _i = Pr, Si = Symbol.for("react.element"), vi = Symbol.for("react.fragment"), Ci = Object.prototype.hasOwnProperty, Ri = _i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, Ii = { key: !0, ref: !0, __self: !0, __source: !0 };
1111
+ function An(i, e, t) {
1112
+ var n, r = {}, o = null, s = null;
1113
+ t !== void 0 && (o = "" + t), e.key !== void 0 && (o = "" + e.key), e.ref !== void 0 && (s = e.ref);
1114
+ for (n in e)
1115
+ Ci.call(e, n) && !Ii.hasOwnProperty(n) && (r[n] = e[n]);
1116
+ if (i && i.defaultProps)
1117
+ for (n in e = i.defaultProps, e)
1118
+ r[n] === void 0 && (r[n] = e[n]);
1119
+ return { $$typeof: Si, type: i, key: o, ref: s, props: r, _owner: Ri.current };
1120
+ }
1121
+ it.Fragment = vi;
1122
+ it.jsx = An;
1123
+ it.jsxs = An;
1124
+ Ln.exports = it;
1125
+ var S = Ln.exports;
1126
+ const yi = "univer-formula-error-function", Mi = {
1127
+ formulaErrorFunction: yi
1128
+ };
1129
+ function bi() {
1130
+ const [i, e] = O(!1), [t, n] = O({ left: 0, top: 0 }), r = $(de), o = $(Ft);
1131
+ return Fe(() => {
1132
+ const s = r.help$.subscribe((a) => {
1133
+ const c = o.getState();
1134
+ if (!c)
1135
+ return;
1136
+ const { visible: l } = a;
1137
+ if (!l) {
1138
+ e(l);
1139
+ return;
1140
+ }
1141
+ const { endX: d = 0, startY: h = 0 } = c;
1142
+ n({ left: d, top: h }), e(l);
1143
+ });
1144
+ return () => {
1145
+ s == null || s.unsubscribe();
1146
+ };
1147
+ }, []), i ? /* @__PURE__ */ S.jsx("div", { className: Mi.formulaErrorFunction, style: { left: t.left, top: t.top } }) : null;
1148
+ }
1149
+ var q = function() {
1150
+ return q = Object.assign || function(i) {
1151
+ for (var e, t = 1, n = arguments.length; t < n; t++) {
1152
+ e = arguments[t];
1153
+ for (var r in e)
1154
+ Object.prototype.hasOwnProperty.call(e, r) && (i[r] = e[r]);
1155
+ }
1156
+ return i;
1157
+ }, q.apply(this, arguments);
1158
+ }, Fi = function(i, e) {
1159
+ var t = {};
1160
+ for (var n in i)
1161
+ Object.prototype.hasOwnProperty.call(i, n) && e.indexOf(n) < 0 && (t[n] = i[n]);
1162
+ if (i != null && typeof Object.getOwnPropertySymbols == "function")
1163
+ for (var r = 0, n = Object.getOwnPropertySymbols(i); r < n.length; r++)
1164
+ e.indexOf(n[r]) < 0 && Object.prototype.propertyIsEnumerable.call(i, n[r]) && (t[n[r]] = i[n[r]]);
1165
+ return t;
1166
+ }, Oe = we(function(i, e) {
1167
+ var t = i.icon, n = i.id, r = i.className, o = i.extend, s = Fi(i, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(n, " ").concat(r || "").trim(), c = Ur("_".concat(xi()));
1168
+ return Dn(t, "".concat(n), { defIds: t.defIds, idSuffix: c.current }, q({ ref: e, className: a }, s), o);
1169
+ });
1170
+ function Dn(i, e, t, n, r) {
1171
+ return xe(i.tag, q(q({ key: e }, Ni(i, t, r)), n), (wi(i, t).children || []).map(function(o, s) {
1172
+ return Dn(o, "".concat(e, "-").concat(i.tag, "-").concat(s), t, void 0, r);
1173
+ }));
1174
+ }
1175
+ function Ni(i, e, t) {
1176
+ var n = q({}, i.attrs);
1177
+ t != null && t.colorChannel1 && n.fill === "colorChannel1" && (n.fill = t.colorChannel1);
1178
+ var r = e.defIds;
1179
+ return !r || r.length === 0 || (i.tag === "use" && n["xlink:href"] && (n["xlink:href"] = n["xlink:href"] + e.idSuffix), Object.entries(n).forEach(function(o) {
1180
+ var s = o[0], a = o[1];
1181
+ typeof a == "string" && (n[s] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
1182
+ })), n;
1183
+ }
1184
+ function wi(i, e) {
1185
+ var t, n = e.defIds;
1186
+ return !n || n.length === 0 ? i : i.tag === "defs" && (!((t = i.children) === null || t === void 0) && t.length) ? q(q({}, i), { children: i.children.map(function(r) {
1187
+ return typeof r.attrs.id == "string" && n && n.indexOf(r.attrs.id) > -1 ? q(q({}, r), { attrs: q(q({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
1188
+ }) }) : i;
1189
+ }
1190
+ function xi() {
1191
+ return Math.random().toString(36).substring(2, 8);
1192
+ }
1193
+ Oe.displayName = "UniverIcon";
1194
+ var Ti = {
1195
+ tag: "svg",
1196
+ attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" },
1197
+ children: [
1198
+ {
1199
+ tag: "path",
1200
+ attrs: {
1201
+ fill: "currentColor",
1202
+ d: "M14.6152 4.52067C14.8732 4.77869 14.8732 5.19703 14.6152 5.45505L6.61862 13.4514C6.46241 13.6077 6.20915 13.6077 6.05294 13.4514L1.73512 9.13354C1.4771 8.87551 1.4771 8.45718 1.73513 8.19915C1.99315 7.94113 2.41149 7.94114 2.66951 8.19916L6.19436 11.7241C6.27247 11.8022 6.3991 11.8022 6.47721 11.7241L13.6808 4.52067C13.9388 4.26264 14.3571 4.26264 14.6152 4.52067Z",
1203
+ fillRule: "evenodd",
1204
+ clipRule: "evenodd"
1205
+ }
1206
+ }
1207
+ ]
1208
+ }, Pn = we(function(i, e) {
1209
+ return xe(Oe, Object.assign({}, i, {
1210
+ id: "check-mark-single",
1211
+ ref: e,
1212
+ icon: Ti
1213
+ }));
1214
+ });
1215
+ Pn.displayName = "CheckMarkSingle";
1216
+ const Oi = Pn;
1217
+ var Ei = {
1218
+ tag: "svg",
1219
+ attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" },
1220
+ children: [
1221
+ {
1222
+ tag: "path",
1223
+ attrs: {
1224
+ fill: "currentColor",
1225
+ d: "M5.48712 4.59907C5.23328 4.34523 4.82172 4.34523 4.56788 4.59907C4.31404 4.85291 4.31404 5.26447 4.56788 5.51831L7.9973 8.94773L4.56773 12.3773C4.31389 12.6311 4.31389 13.0427 4.56773 13.2965C4.82157 13.5504 5.23313 13.5504 5.48697 13.2965L8.91654 9.86697L12.3461 13.2965C12.5999 13.5503 13.0114 13.5503 13.2653 13.2965C13.5191 13.0426 13.5191 12.6311 13.2653 12.3772L9.83577 8.94773L13.2651 5.51836C13.519 5.26452 13.519 4.85296 13.2651 4.59912C13.0113 4.34528 12.5997 4.34528 12.3459 4.59912L8.91654 8.02849L5.48712 4.59907Z"
1226
+ }
1227
+ }
1228
+ ]
1229
+ }, Un = we(function(i, e) {
1230
+ return xe(Oe, Object.assign({}, i, {
1231
+ id: "close-single",
1232
+ ref: e,
1233
+ icon: Ei
1234
+ }));
1235
+ });
1236
+ Un.displayName = "CloseSingle";
1237
+ const Li = Un;
1238
+ var Ai = {
1239
+ tag: "svg",
1240
+ attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" },
1241
+ children: [
1242
+ {
1243
+ tag: "mask",
1244
+ attrs: {
1245
+ id: "mask0_102_891",
1246
+ style: { maskType: "alpha" },
1247
+ width: 17,
1248
+ height: 17,
1249
+ x: 0,
1250
+ y: 0,
1251
+ maskUnits: "userSpaceOnUse"
1252
+ },
1253
+ children: [
1254
+ {
1255
+ tag: "path",
1256
+ attrs: { fill: "#DCDCDC", d: "M0.51 0.5H16.51V16.5H0.51z" }
1257
+ }
1258
+ ]
1259
+ },
1260
+ {
1261
+ tag: "g",
1262
+ attrs: { fill: "currentColor", mask: "url(#mask0_102_891)" },
1263
+ children: [
1264
+ {
1265
+ tag: "path",
1266
+ attrs: {
1267
+ d: "M9.30291 5.78907C9.30291 6.22898 8.94629 6.5856 8.50637 6.5856 8.06646 6.5856 7.70984 6.22898 7.70984 5.78907 7.70984 5.34916 8.06646 4.99254 8.50637 4.99254 8.94629 4.99254 9.30291 5.34916 9.30291 5.78907zM9.1436 8.17867C9.1436 7.82674 8.8583 7.54144 8.50637 7.54144 8.15444 7.54144 7.86915 7.82674 7.86915 8.17867V12.002C7.86915 12.354 8.15444 12.6392 8.50637 12.6392 8.8583 12.6392 9.1436 12.354 9.1436 12.002V8.17867z"
1268
+ }
1269
+ },
1270
+ {
1271
+ tag: "path",
1272
+ attrs: {
1273
+ d: "M1.49689 8.49728C1.49689 4.62605 4.63514 1.48779 8.50637 1.48779C12.3776 1.48779 15.5159 4.62605 15.5159 8.49728C15.5159 12.3685 12.3776 15.5068 8.50637 15.5068C4.63514 15.5068 1.49689 12.3685 1.49689 8.49728ZM8.50637 2.76224C5.339 2.76224 2.77134 5.32991 2.77134 8.49728C2.77134 11.6646 5.339 14.2323 8.50637 14.2323C11.6737 14.2323 14.2414 11.6646 14.2414 8.49728C14.2414 5.32991 11.6737 2.76224 8.50637 2.76224Z",
1274
+ fillRule: "evenodd",
1275
+ clipRule: "evenodd"
1276
+ }
1277
+ }
1278
+ ]
1279
+ }
1280
+ ]
1281
+ }, kn = we(function(i, e) {
1282
+ return xe(Oe, Object.assign({}, i, {
1283
+ id: "details-single",
1284
+ ref: e,
1285
+ icon: Ai
1286
+ }));
1287
+ });
1288
+ kn.displayName = "DetailsSingle";
1289
+ const Di = kn;
1290
+ var Pi = {
1291
+ tag: "svg",
1292
+ attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" },
1293
+ children: [
1294
+ {
1295
+ tag: "path",
1296
+ attrs: {
1297
+ fill: "currentColor",
1298
+ d: "M5.52628 3.57095C5.81918 3.26411 6.29405 3.26411 6.58695 3.57095L11.0869 8.28525C11.3798 8.59209 11.3798 9.08958 11.0869 9.39642L6.51623 14.04C6.22334 14.3468 5.74846 14.3468 5.45557 14.04C5.16268 13.7331 5.16268 13.2357 5.45557 12.9288L9.35939 8.979C9.43544 8.90205 9.43652 8.77857 9.36182 8.70031L5.52628 4.68212C5.23339 4.37528 5.23339 3.87779 5.52628 3.57095Z",
1299
+ fillRule: "evenodd",
1300
+ clipRule: "evenodd"
1301
+ }
1302
+ }
1303
+ ]
1304
+ }, $n = we(function(i, e) {
1305
+ return xe(Oe, Object.assign({}, i, {
1306
+ id: "more-single",
1307
+ ref: e,
1308
+ icon: Pi
1309
+ }));
1310
+ });
1311
+ $n.displayName = "MoreSingle";
1312
+ const Ui = $n, ki = "univer-formula-help-function", $i = "univer-formula-help-function-title", ji = "univer-formula-help-function-title-icons", Bi = "univer-formula-help-function-title-icon", qi = "univer-formula-help-function-content", Vi = "univer-formula-help-function-content-inner", Wi = "univer-formula-help-function-content-params", Hi = "univer-formula-help-function-content-params-title", Ki = "univer-formula-help-function-content-params-detail", Gi = "univer-formula-help-function-active", zi = "univer-formula-help-decorator", B = {
1313
+ formulaHelpFunction: ki,
1314
+ formulaHelpFunctionTitle: $i,
1315
+ formulaHelpFunctionTitleIcons: ji,
1316
+ formulaHelpFunctionTitleIcon: Bi,
1317
+ formulaHelpFunctionContent: qi,
1318
+ formulaHelpFunctionContentInner: Vi,
1319
+ formulaHelpFunctionContentParams: Wi,
1320
+ formulaHelpFunctionContentParamsTitle: Hi,
1321
+ formulaHelpFunctionContentParamsDetail: Ki,
1322
+ formulaHelpFunctionActive: Gi,
1323
+ formulaHelpDecorator: zi
1324
+ };
1325
+ function Yi() {
1326
+ const [i, e] = O(!1), [t, n] = O(!0), [r, o] = O(!0), [s, a] = O(0), [c, l] = O([0, 0]), [d, h] = O({ left: 0, top: 0 }), [m, f] = O(null), p = $(de), v = $(Ft), u = $(Ce), _ = $(In), g = $(yt), C = u.t("formula.prompt.required"), b = u.t("formula.prompt.optional");
1327
+ Fe(() => {
1328
+ const R = p.help$.subscribe((I) => {
1329
+ const { visible: N, paramIndex: E, functionInfo: M } = I;
1330
+ if (!N) {
1331
+ e(N);
1332
+ return;
1333
+ }
1334
+ const w = g.getContextValue(rn) ? _.getPosition() : v.getRect();
1335
+ if (w == null)
1336
+ return;
1337
+ const { left: W, top: j, height: ae } = w, he = {
1338
+ functionName: M.functionName,
1339
+ functionType: M.functionType,
1340
+ description: u.t(M.description),
1341
+ abstract: u.t(M.abstract),
1342
+ functionParameter: M.functionParameter.map((ce) => ({
1343
+ name: u.t(ce.name),
1344
+ detail: u.t(ce.detail),
1345
+ example: ce.example,
1346
+ require: ce.require,
1347
+ repeat: ce.repeat
1348
+ }))
1349
+ };
1350
+ l([W, j + ae]), a(E), f(he), h({ left: W, top: j }), e(N);
1351
+ });
1352
+ return () => {
1353
+ R == null || R.unsubscribe();
1354
+ };
1355
+ }, []);
1356
+ function y(R) {
1357
+ a(R);
1358
+ }
1359
+ return /* @__PURE__ */ S.jsx(S.Fragment, { children: r ? /* @__PURE__ */ S.jsx(Fn, { visible: i, offset: c, children: m ? /* @__PURE__ */ S.jsxs("div", { className: B.formulaHelpFunction, children: [
1360
+ /* @__PURE__ */ S.jsxs("div", { className: B.formulaHelpFunctionTitle, children: [
1361
+ /* @__PURE__ */ S.jsx(
1362
+ Xi,
1363
+ {
1364
+ prefix: m.functionName,
1365
+ value: m.functionParameter,
1366
+ active: s,
1367
+ onClick: y
1368
+ }
1369
+ ),
1370
+ /* @__PURE__ */ S.jsxs("div", { className: B.formulaHelpFunctionTitleIcons, children: [
1371
+ /* @__PURE__ */ S.jsx(
1372
+ "div",
1373
+ {
1374
+ className: B.formulaHelpFunctionTitleIcon,
1375
+ style: { transform: t ? "rotateZ(-90deg)" : "rotateZ(90deg)" },
1376
+ onClick: () => n(!t),
1377
+ children: /* @__PURE__ */ S.jsx(Ui, {})
1378
+ }
1379
+ ),
1380
+ /* @__PURE__ */ S.jsx(
1381
+ "div",
1382
+ {
1383
+ className: B.formulaHelpFunctionTitleIcon,
1384
+ onClick: () => o(!r),
1385
+ children: /* @__PURE__ */ S.jsx(Li, {})
1386
+ }
1387
+ )
1388
+ ] })
1389
+ ] }),
1390
+ /* @__PURE__ */ S.jsx(
1391
+ "div",
1392
+ {
1393
+ className: B.formulaHelpFunctionContent,
1394
+ style: {
1395
+ height: t ? "unset" : 0,
1396
+ padding: t ? "revert-layer" : 0
1397
+ },
1398
+ children: /* @__PURE__ */ S.jsxs("div", { className: B.formulaHelpFunctionContentInner, children: [
1399
+ /* @__PURE__ */ S.jsx(
1400
+ ut,
1401
+ {
1402
+ title: u.t("formula.prompt.helpExample"),
1403
+ value: `${m.functionName}(${m.functionParameter.map((R) => R.example).join(",")})`
1404
+ }
1405
+ ),
1406
+ /* @__PURE__ */ S.jsx(
1407
+ ut,
1408
+ {
1409
+ title: u.t("formula.prompt.helpAbstract"),
1410
+ value: m.description
1411
+ }
1412
+ ),
1413
+ m && m.functionParameter && m.functionParameter.map((R, I) => /* @__PURE__ */ S.jsx(
1414
+ ut,
1415
+ {
1416
+ className: s === I ? B.formulaHelpFunctionActive : "",
1417
+ title: R.name,
1418
+ value: `${R.require ? C : b} ${R.detail}`
1419
+ },
1420
+ I
1421
+ ))
1422
+ ] })
1423
+ }
1424
+ )
1425
+ ] }) : /* @__PURE__ */ S.jsx(S.Fragment, {}) }) : i ? /* @__PURE__ */ S.jsx(
1426
+ "div",
1427
+ {
1428
+ className: B.formulaHelpDecorator,
1429
+ onClick: () => o(!r),
1430
+ style: { left: d.left - 24, top: d.top },
1431
+ children: /* @__PURE__ */ S.jsx(Di, {})
1432
+ }
1433
+ ) : /* @__PURE__ */ S.jsx(S.Fragment, {}) });
1434
+ }
1435
+ const ut = (i) => /* @__PURE__ */ S.jsxs("div", { className: B.formulaHelpFunctionContentParams, children: [
1436
+ /* @__PURE__ */ S.jsx("div", { className: `${B.formulaHelpFunctionContentParamsTitle} ${i.className}`, children: i.title }),
1437
+ /* @__PURE__ */ S.jsx("div", { className: B.formulaHelpFunctionContentParamsDetail, children: i.value })
1438
+ ] }), Xi = (i) => {
1439
+ const { prefix: e, value: t, active: n, onClick: r } = i;
1440
+ return /* @__PURE__ */ S.jsxs("div", { children: [
1441
+ /* @__PURE__ */ S.jsxs("span", { children: [
1442
+ e,
1443
+ "("
1444
+ ] }),
1445
+ t && t.map((o, s) => (
1446
+ // TODO@Dushusir: more params needs to be active
1447
+ /* @__PURE__ */ S.jsxs("span", { children: [
1448
+ /* @__PURE__ */ S.jsx(
1449
+ "span",
1450
+ {
1451
+ className: n === s ? B.formulaHelpFunctionActive : "",
1452
+ onClick: () => r(s),
1453
+ children: o.repeat ? `[${o.name},...]` : o.name
1454
+ }
1455
+ ),
1456
+ s === t.length - 1 ? "" : ","
1457
+ ] }, s)
1458
+ )),
1459
+ ")"
1460
+ ] });
1461
+ }, Zi = "univer-formula-search-function", Qi = "univer-formula-search-function-item", Ji = "univer-formula-search-function-item-name", eo = "univer-formula-search-function-item-name-light", to = "univer-formula-search-function-item-desc", no = "univer-formula-search-function-item-active", le = {
1462
+ formulaSearchFunction: Zi,
1463
+ formulaSearchFunctionItem: Qi,
1464
+ formulaSearchFunctionItemName: Ji,
1465
+ formulaSearchFunctionItemNameLight: eo,
1466
+ formulaSearchFunctionItemDesc: to,
1467
+ formulaSearchFunctionItemActive: no
1468
+ };
1469
+ function ro() {
1470
+ const [i, e] = O(!1), [t, n] = O(0), [r, o] = O([0, 0]), [s, a] = O([]), [c, l] = O(""), d = $(de), h = $(Ft), m = $(In), f = $(yt);
1471
+ Fe(() => {
1472
+ let u = [], _ = 0;
1473
+ const g = d.search$.subscribe((y) => {
1474
+ const { visible: R, searchText: I, searchList: N } = y;
1475
+ if (!R) {
1476
+ e(R);
1477
+ return;
1478
+ }
1479
+ const M = f.getContextValue(rn) ? m.getPosition() : h.getRect();
1480
+ if (M == null)
1481
+ return;
1482
+ const { left: T, top: w, height: W } = M;
1483
+ l(I), a(N), u = N, o([T, w + W]), e(R), n(0), _ = 0;
1484
+ }), C = d.navigate$.subscribe((y) => {
1485
+ const { direction: R } = y;
1486
+ if (R === L.UP) {
1487
+ let I = _ - 1;
1488
+ I = I < 0 ? u.length - 1 : I, n(I), _ = I;
1489
+ } else if (R === L.DOWN) {
1490
+ let I = _ + 1;
1491
+ I = I >= u.length ? 0 : I, n(I), _ = I;
1492
+ }
1493
+ }), b = d.accept$.subscribe((y) => {
1494
+ const R = u[_].name;
1495
+ d.acceptFormulaName(R);
1496
+ });
1497
+ return () => {
1498
+ g == null || g.unsubscribe(), C == null || C.unsubscribe(), b == null || b.unsubscribe();
1499
+ };
1500
+ }, []);
1501
+ function p(u) {
1502
+ n(u);
1503
+ }
1504
+ function v() {
1505
+ n(-1);
1506
+ }
1507
+ return /* @__PURE__ */ S.jsx(Fn, { visible: i, offset: r, children: /* @__PURE__ */ S.jsx("ul", { className: le.formulaSearchFunction, children: s.map((u, _) => /* @__PURE__ */ S.jsxs(
1508
+ "li",
1509
+ {
1510
+ className: t === _ ? `${le.formulaSearchFunctionItem} ${le.formulaSearchFunctionItemActive}` : le.formulaSearchFunctionItem,
1511
+ onMouseEnter: () => p(_),
1512
+ onMouseLeave: v,
1513
+ onClick: () => d.acceptFormulaName(u.name),
1514
+ children: [
1515
+ /* @__PURE__ */ S.jsxs("span", { className: le.formulaSearchFunctionItemName, children: [
1516
+ /* @__PURE__ */ S.jsx("span", { className: le.formulaSearchFunctionItemNameLight, children: c }),
1517
+ /* @__PURE__ */ S.jsx("span", { children: u.name.slice(c.length) })
1518
+ ] }),
1519
+ /* @__PURE__ */ S.jsx("span", { className: le.formulaSearchFunctionItemDesc, children: u.desc })
1520
+ ]
1521
+ },
1522
+ _
1523
+ )) }) });
1524
+ }
1525
+ function io() {
1526
+ return /* @__PURE__ */ S.jsxs(S.Fragment, { children: [
1527
+ /* @__PURE__ */ S.jsx(ro, {}),
1528
+ /* @__PURE__ */ S.jsx(Yi, {}),
1529
+ /* @__PURE__ */ S.jsx(bi, {})
1530
+ ] });
1531
+ }
1532
+ const oo = "univer-formula-more-functions", so = "univer-formula-more-functions-operation", Zt = {
1533
+ formulaMoreFunctions: oo,
1534
+ formulaMoreFunctionsOperation: so
1535
+ };
1536
+ function jn(i) {
1537
+ const { prefix: e, value: t } = i;
1538
+ return /* @__PURE__ */ S.jsxs("div", { children: [
1539
+ /* @__PURE__ */ S.jsxs("span", { children: [
1540
+ e,
1541
+ "("
1542
+ ] }),
1543
+ t && t.map((n, r) => /* @__PURE__ */ S.jsxs("span", { children: [
1544
+ /* @__PURE__ */ S.jsx("span", { children: n.repeat ? `[${n.name},...]` : n.name }),
1545
+ r === t.length - 1 ? "" : ","
1546
+ ] }, r)),
1547
+ ")"
1548
+ ] });
1549
+ }
1550
+ const ao = "univer-formula-function-params", co = "univer-formula-function-params-title", lo = "univer-formula-function-params-detail", mt = {
1551
+ formulaFunctionParams: ao,
1552
+ formulaFunctionParamsTitle: co,
1553
+ formulaFunctionParamsDetail: lo
1554
+ };
1555
+ function be(i) {
1556
+ const { className: e, value: t, title: n } = i;
1557
+ return /* @__PURE__ */ S.jsxs("div", { className: mt.formulaFunctionParams, children: [
1558
+ /* @__PURE__ */ S.jsx("div", { className: `${mt.formulaFunctionParamsTitle} ${e}`, children: n }),
1559
+ /* @__PURE__ */ S.jsx("div", { className: mt.formulaFunctionParamsDetail, children: t })
1560
+ ] });
1561
+ }
1562
+ const uo = "univer-formula-input-params-list", mo = "univer-formula-input-params-list-item-name", ho = "univer-formula-input-params-list-item-selector", ye = {
1563
+ formulaInputParamsList: uo,
1564
+ formulaInputParamsListItemName: mo,
1565
+ formulaInputParamsListItemSelector: ho
1566
+ };
1567
+ function fo(i) {
1568
+ const { functionInfo: e, onChange: t } = i;
1569
+ if (!e)
1570
+ return null;
1571
+ const [n, r] = O([]), [o, s] = O(e.functionParameter), [a, c] = O(-1);
1572
+ function l(h, m) {
1573
+ const f = [...n];
1574
+ f[m] = h, r(f), t(f);
1575
+ }
1576
+ function d(h) {
1577
+ if (h === o.length - 1 && o[h].repeat) {
1578
+ const m = [...o];
1579
+ m.push(o[h]), s(m);
1580
+ }
1581
+ c(h);
1582
+ }
1583
+ return /* @__PURE__ */ S.jsxs("div", { className: ye.formulaInputParams, children: [
1584
+ /* @__PURE__ */ S.jsx("div", { className: ye.formulaInputParamsList, children: o.map((h, m) => /* @__PURE__ */ S.jsxs("div", { children: [
1585
+ /* @__PURE__ */ S.jsx("div", { className: ye.formulaInputParamsListItemName, children: h.name }),
1586
+ /* @__PURE__ */ S.jsx("div", { className: ye.formulaInputParamsListItemSelector, children: /* @__PURE__ */ S.jsx(
1587
+ br,
1588
+ {
1589
+ onChange: (f) => l(f, m),
1590
+ onActive: () => d(m)
1591
+ }
1592
+ ) })
1593
+ ] }, m)) }),
1594
+ /* @__PURE__ */ S.jsx("div", { className: ye.formulaInputParamsInfo, children: /* @__PURE__ */ S.jsx(
1595
+ be,
1596
+ {
1597
+ title: a === -1 ? /* @__PURE__ */ S.jsx(jn, { prefix: e.functionName, value: o }) : o[a].name,
1598
+ value: a === -1 ? e.description : o[a].detail
1599
+ }
1600
+ ) })
1601
+ ] });
1602
+ }
1603
+ const go = [], po = [], _o = [], So = [], vo = [], Co = [], Ro = [], Io = [], yo = [], Mo = [], bo = [
1604
+ {
1605
+ functionName: Ut.SUM,
1606
+ aliasFunctionName: "formula.functionList.SUM.aliasFunctionName",
1607
+ functionType: me.Math,
1608
+ description: "formula.functionList.SUM.description",
1609
+ abstract: "formula.functionList.SUM.abstract",
1610
+ functionParameter: [
1611
+ {
1612
+ name: "formula.functionList.SUM.functionParameter.number1.name",
1613
+ detail: "formula.functionList.SUM.functionParameter.number1.detail",
1614
+ example: "A1:A20",
1615
+ require: 1,
1616
+ repeat: 0
1617
+ },
1618
+ {
1619
+ name: "formula.functionList.SUM.functionParameter.number2.name",
1620
+ detail: "formula.functionList.SUM.functionParameter.number2.detail",
1621
+ example: "B2:B10",
1622
+ require: 0,
1623
+ repeat: 1
1624
+ }
1625
+ ]
1626
+ },
1627
+ {
1628
+ functionName: Ut.SUMIF,
1629
+ aliasFunctionName: "formula.functionList.SUMIF.aliasFunctionName",
1630
+ functionType: me.Math,
1631
+ description: "formula.functionList.SUMIF.description",
1632
+ abstract: "formula.functionList.SUMIF.abstract",
1633
+ functionParameter: [
1634
+ {
1635
+ name: "formula.functionList.SUMIF.functionParameter.range.name",
1636
+ detail: "formula.functionList.SUMIF.functionParameter.range.detail",
1637
+ example: "A1:A20",
1638
+ require: 1,
1639
+ repeat: 0
1640
+ },
1641
+ {
1642
+ name: "formula.functionList.SUMIF.functionParameter.criteria.name",
1643
+ detail: "formula.functionList.SUMIF.functionParameter.criteria.detail",
1644
+ example: ">5",
1645
+ require: 1,
1646
+ repeat: 0
1647
+ },
1648
+ {
1649
+ name: "formula.functionList.SUMIF.functionParameter.sum_range.name",
1650
+ detail: "formula.functionList.SUMIF.functionParameter.sum_range.detail",
1651
+ example: "B1:B20",
1652
+ require: 0,
1653
+ repeat: 0
1654
+ }
1655
+ ]
1656
+ }
1657
+ ], Fo = [
1658
+ {
1659
+ functionName: Ae.AVERAGE,
1660
+ aliasFunctionName: "formula.functionList.AVERAGE.aliasFunctionName",
1661
+ functionType: me.Statistical,
1662
+ description: "formula.functionList.AVERAGE.description",
1663
+ abstract: "formula.functionList.AVERAGE.abstract",
1664
+ functionParameter: [
1665
+ {
1666
+ name: "formula.functionList.AVERAGE.functionParameter.number1.name",
1667
+ detail: "formula.functionList.AVERAGE.functionParameter.number1.detail",
1668
+ example: "A1:A20",
1669
+ require: 1,
1670
+ repeat: 0
1671
+ },
1672
+ {
1673
+ name: "formula.functionList.AVERAGE.functionParameter.number2.name",
1674
+ detail: "formula.functionList.AVERAGE.functionParameter.number2.detail",
1675
+ example: "B2:B10",
1676
+ require: 0,
1677
+ repeat: 1
1678
+ }
1679
+ ]
1680
+ },
1681
+ {
1682
+ functionName: Ae.MAX,
1683
+ aliasFunctionName: "formula.functionList.MAX.aliasFunctionName",
1684
+ functionType: me.Statistical,
1685
+ description: "formula.functionList.MAX.description",
1686
+ abstract: "formula.functionList.MAX.abstract",
1687
+ functionParameter: [
1688
+ {
1689
+ name: "formula.functionList.MAX.functionParameter.number1.name",
1690
+ detail: "formula.functionList.MAX.functionParameter.number1.detail",
1691
+ example: "A1:A20",
1692
+ require: 1,
1693
+ repeat: 0
1694
+ },
1695
+ {
1696
+ name: "formula.functionList.MAX.functionParameter.number2.name",
1697
+ detail: "formula.functionList.MAX.functionParameter.number2.detail",
1698
+ example: "B2:B10",
1699
+ require: 0,
1700
+ repeat: 1
1701
+ }
1702
+ ]
1703
+ },
1704
+ {
1705
+ functionName: Ae.COUNT,
1706
+ aliasFunctionName: "formula.functionList.COUNT.aliasFunctionName",
1707
+ functionType: me.Statistical,
1708
+ description: "formula.functionList.COUNT.description",
1709
+ abstract: "formula.functionList.COUNT.abstract",
1710
+ functionParameter: [
1711
+ {
1712
+ name: "formula.functionList.COUNT.functionParameter.value1.name",
1713
+ detail: "formula.functionList.COUNT.functionParameter.value1.detail",
1714
+ example: "A1:A20",
1715
+ require: 1,
1716
+ repeat: 0
1717
+ },
1718
+ {
1719
+ name: "formula.functionList.COUNT.functionParameter.value2.name",
1720
+ detail: "formula.functionList.COUNT.functionParameter.value2.detail",
1721
+ example: "B2:B10",
1722
+ require: 0,
1723
+ repeat: 1
1724
+ }
1725
+ ]
1726
+ },
1727
+ {
1728
+ functionName: Ae.MIN,
1729
+ aliasFunctionName: "formula.functionList.MIN.aliasFunctionName",
1730
+ functionType: me.Statistical,
1731
+ description: "formula.functionList.MIN.description",
1732
+ abstract: "formula.functionList.MIN.abstract",
1733
+ functionParameter: [
1734
+ {
1735
+ name: "formula.functionList.MIN.functionParameter.number1.name",
1736
+ detail: "formula.functionList.MIN.functionParameter.number1.detail",
1737
+ example: "A1:A20",
1738
+ require: 1,
1739
+ repeat: 0
1740
+ },
1741
+ {
1742
+ name: "formula.functionList.MIN.functionParameter.number2.name",
1743
+ detail: "formula.functionList.MIN.functionParameter.number2.detail",
1744
+ example: "B2:B10",
1745
+ require: 0,
1746
+ repeat: 1
1747
+ }
1748
+ ]
1749
+ }
1750
+ ], No = [], wo = [], xo = [], To = [
1751
+ ...Ro,
1752
+ ...vo,
1753
+ ...bo,
1754
+ ...Fo,
1755
+ ...Mo,
1756
+ ...So,
1757
+ ...No,
1758
+ ...yo,
1759
+ ...Io,
1760
+ ...Co,
1761
+ ..._o,
1762
+ ...po,
1763
+ ...xo,
1764
+ ...go,
1765
+ ...wo
1766
+ ];
1767
+ function Oo(i, e) {
1768
+ return Object.keys(i).filter((t) => isNaN(Number(t))).map((t) => ({
1769
+ label: e.t(`formula.functionType.${t.toLocaleLowerCase()}`),
1770
+ value: `${i[t]}`
1771
+ }));
1772
+ }
1773
+ function Eo(i, e) {
1774
+ let t = "";
1775
+ return i.aliasFunctionName ? (t = e.t(i.aliasFunctionName), t === i.aliasFunctionName && (t = i.functionName)) : t = i.functionName, t;
1776
+ }
1777
+ var Lo = Object.defineProperty, Ao = Object.getOwnPropertyDescriptor, Do = (i, e, t, n) => {
1778
+ for (var r = n > 1 ? void 0 : n ? Ao(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1779
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1780
+ return n && r && Lo(e, t, r), r;
1781
+ }, Qt = (i, e) => (t, n) => e(t, n, i);
1782
+ const Et = Je("formula-ui.description-service");
1783
+ let It = class {
1784
+ constructor(i, e, t) {
1785
+ this._description = i, this._functionService = e, this._localeService = t, this._initialize(), this._registerDescription();
1786
+ }
1787
+ dispose() {
1788
+ this._localeService.localeChanged$.complete();
1789
+ }
1790
+ getDescriptions() {
1791
+ return this._functionService.getDescriptions();
1792
+ }
1793
+ hasFunction(i) {
1794
+ return this._functionService.getDescriptions().get(i.toLocaleUpperCase()) !== void 0;
1795
+ }
1796
+ getFunctionInfo(i) {
1797
+ return this._functionService.getDescriptions().get(i.toLocaleUpperCase());
1798
+ }
1799
+ getSearchListByName(i) {
1800
+ const e = [], t = this._functionService.getDescriptions();
1801
+ return i = i.toLocaleUpperCase(), t.forEach((n) => {
1802
+ const { functionName: r, abstract: o } = n;
1803
+ r.indexOf(i) > -1 && e.push({ name: r, desc: o });
1804
+ }), e;
1805
+ }
1806
+ getSearchListByType(i) {
1807
+ const e = [];
1808
+ return this._functionService.getDescriptions().forEach((n) => {
1809
+ const { functionName: r, functionType: o, abstract: s } = n;
1810
+ (o === i || i === -1) && e.push({ name: r, desc: s });
1811
+ }), e;
1812
+ }
1813
+ _initialize() {
1814
+ this._localeService.localeChanged$.subscribe(() => {
1815
+ this._registerDescription();
1816
+ });
1817
+ }
1818
+ _registerDescription() {
1819
+ const i = this._localeService, t = To.concat(this._description || []).map((n) => ({
1820
+ functionName: Eo(n, i),
1821
+ functionType: n.functionType,
1822
+ description: i.t(n.description),
1823
+ abstract: i.t(n.abstract),
1824
+ functionParameter: n.functionParameter.map((r) => ({
1825
+ name: i.t(r.name),
1826
+ detail: i.t(r.detail),
1827
+ example: r.example,
1828
+ require: r.require,
1829
+ repeat: r.repeat
1830
+ }))
1831
+ }));
1832
+ this._functionService.registerDescriptions(...t);
1833
+ }
1834
+ };
1835
+ It = Do([
1836
+ Qt(1, Qn),
1837
+ Qt(2, x(Ce))
1838
+ ], It);
1839
+ const Po = "univer-formula-select-function-select", Uo = "univer-formula-select-function-result", ko = "univer-formula-select-function-result-item", $o = "univer-formula-select-function-result-item-name-light", jo = "univer-formula-select-function-result-item-selected", Bo = "univer-formula-select-function-result-item-active", qo = "univer-formula-select-function-content", ee = {
1840
+ formulaSelectFunctionSelect: Po,
1841
+ formulaSelectFunctionResult: Uo,
1842
+ formulaSelectFunctionResultItem: ko,
1843
+ formulaSelectFunctionResultItemNameLight: $o,
1844
+ formulaSelectFunctionResultItemSelected: jo,
1845
+ formulaSelectFunctionResultItemActive: Bo,
1846
+ formulaSelectFunctionContent: qo
1847
+ };
1848
+ function Vo(i) {
1849
+ const { onChange: e } = i, t = "-1", [n, r] = O(""), [o, s] = O([]), [a, c] = O(0), [l, d] = O(t), [h, m] = O(0), [f, p] = O(null), v = $(Et), u = $(Ce), _ = Oo(me, u);
1850
+ _.unshift({
1851
+ label: u.t("formula.moreFunctions.allFunctions"),
1852
+ value: t
1853
+ });
1854
+ const g = u.t("formula.prompt.required"), C = u.t("formula.prompt.optional");
1855
+ Fe(() => {
1856
+ R(t);
1857
+ }, []), Fe(() => {
1858
+ y(0);
1859
+ }, [o]);
1860
+ const b = (T) => {
1861
+ const w = new RegExp(`(${n.toLocaleUpperCase()})`);
1862
+ return T.split(w).filter(Boolean).map((j, ae) => j.match(w) ? /* @__PURE__ */ S.jsx("span", { className: ee.formulaSelectFunctionResultItemNameLight, children: j }, ae) : j);
1863
+ }, y = (T) => {
1864
+ if (o.length === 0) {
1865
+ p(null);
1866
+ return;
1867
+ }
1868
+ m(T);
1869
+ const w = v.getFunctionInfo(o[T].name);
1870
+ if (!w) {
1871
+ p(null);
1872
+ return;
1873
+ }
1874
+ p(w), e(w);
1875
+ };
1876
+ function R(T) {
1877
+ d(T);
1878
+ const w = v.getSearchListByType(+T);
1879
+ s(w);
1880
+ }
1881
+ function I(T) {
1882
+ r(T);
1883
+ const w = v.getSearchListByName(T);
1884
+ s(w);
1885
+ }
1886
+ function N(T) {
1887
+ if (T.stopPropagation(), T.key === "ArrowDown") {
1888
+ const w = a + 1;
1889
+ c(w === o.length ? 0 : w);
1890
+ } else if (T.key === "ArrowUp") {
1891
+ const w = a - 1;
1892
+ c(w === -1 ? o.length - 1 : w);
1893
+ } else
1894
+ T.key === "Enter" && y(a);
1895
+ }
1896
+ const E = (T) => {
1897
+ c(T);
1898
+ }, M = () => {
1899
+ c(-1);
1900
+ };
1901
+ return /* @__PURE__ */ S.jsxs("div", { children: [
1902
+ /* @__PURE__ */ S.jsxs("div", { className: ee.formulaSelectFunctionSelect, children: [
1903
+ /* @__PURE__ */ S.jsx(kr, { value: l, options: _, onChange: R }),
1904
+ /* @__PURE__ */ S.jsx(
1905
+ $r,
1906
+ {
1907
+ placeholder: u.t("formula.moreFunctions.searchFunctionPlaceholder"),
1908
+ onKeyDown: N,
1909
+ value: n,
1910
+ onChange: I,
1911
+ size: "large",
1912
+ allowClear: !0
1913
+ }
1914
+ )
1915
+ ] }),
1916
+ /* @__PURE__ */ S.jsx("ul", { className: ee.formulaSelectFunctionResult, onKeyDown: N, tabIndex: -1, children: o.map(({ name: T }, w) => /* @__PURE__ */ S.jsxs(
1917
+ "li",
1918
+ {
1919
+ className: a === w ? `${ee.formulaSelectFunctionResultItem} ${ee.formulaSelectFunctionResultItemActive}` : ee.formulaSelectFunctionResultItem,
1920
+ onMouseEnter: () => E(w),
1921
+ onMouseLeave: M,
1922
+ onClick: () => y(w),
1923
+ children: [
1924
+ h === w && /* @__PURE__ */ S.jsx(Oi, { className: ee.formulaSelectFunctionResultItemSelected }),
1925
+ /* @__PURE__ */ S.jsx("span", { className: ee.formulaSelectFunctionResultItemName, children: b(T) })
1926
+ ]
1927
+ },
1928
+ w
1929
+ )) }),
1930
+ f && /* @__PURE__ */ S.jsxs("div", { className: ee.formulaSelectFunctionContent, children: [
1931
+ /* @__PURE__ */ S.jsx(be, { title: f.functionName, value: f.description }),
1932
+ /* @__PURE__ */ S.jsx(
1933
+ be,
1934
+ {
1935
+ title: u.t("formula.moreFunctions.syntax"),
1936
+ value: /* @__PURE__ */ S.jsx(jn, { prefix: f.functionName, value: f.functionParameter })
1937
+ }
1938
+ ),
1939
+ /* @__PURE__ */ S.jsx(
1940
+ be,
1941
+ {
1942
+ title: u.t("formula.prompt.helpExample"),
1943
+ value: `${f.functionName}(${f.functionParameter.map((T) => T.example).join(",")})`
1944
+ }
1945
+ ),
1946
+ f.functionParameter && f.functionParameter.map((T, w) => /* @__PURE__ */ S.jsx(
1947
+ be,
1948
+ {
1949
+ title: T.name,
1950
+ value: `${T.require ? g : C} ${T.detail}`
1951
+ },
1952
+ w
1953
+ ))
1954
+ ] })
1955
+ ] });
1956
+ }
1957
+ function Wo() {
1958
+ const [i, e] = O(!0), [t, n] = O(!1), [r, o] = O([]), [s, a] = O(null), c = $(Ce);
1959
+ $(bn);
1960
+ const l = $(Te);
1961
+ function d() {
1962
+ e(!i), n(!t);
1963
+ }
1964
+ function h() {
1965
+ l.inputFormula(`=${s == null ? void 0 : s.functionName}(`);
1966
+ }
1967
+ return /* @__PURE__ */ S.jsxs("div", { className: Zt.formulaMoreFunctions, children: [
1968
+ i && /* @__PURE__ */ S.jsx(Vo, { onChange: a }),
1969
+ t && /* @__PURE__ */ S.jsx(fo, { functionInfo: s, onChange: o }),
1970
+ /* @__PURE__ */ S.jsxs("div", { className: Zt.formulaMoreFunctionsOperation, children: [
1971
+ t && /* @__PURE__ */ S.jsx(at, { type: "primary", onClick: d, children: c.t("formula.moreFunctions.next") }),
1972
+ t && /* @__PURE__ */ S.jsx(at, { onClick: d, children: c.t("formula.moreFunctions.prev") }),
1973
+ i && /* @__PURE__ */ S.jsx(at, { type: "primary", onClick: h, children: c.t("formula.moreFunctions.confirm") })
1974
+ ] })
1975
+ ] });
1976
+ }
1977
+ function Ho(i) {
1978
+ return {
1979
+ id: Ot.id,
1980
+ icon: "FunctionSingle",
1981
+ tooltip: "formula.insert.tooltip",
1982
+ group: xr.TOOLBAR_FORMULAS_INSERT,
1983
+ type: wt.SELECTOR,
1984
+ positions: [Tr.TOOLBAR_START],
1985
+ selections: [
1986
+ {
1987
+ label: "SUM",
1988
+ value: "SUM",
1989
+ icon: "SumSingle"
1990
+ },
1991
+ {
1992
+ label: "AVERAGE",
1993
+ value: "AVERAGE",
1994
+ icon: "AvgSingle"
1995
+ },
1996
+ {
1997
+ label: "COUNT",
1998
+ value: "COUNT",
1999
+ icon: "CntSingle"
2000
+ },
2001
+ {
2002
+ label: "MAX",
2003
+ value: "MAX",
2004
+ icon: "MaxSingle"
2005
+ },
2006
+ {
2007
+ label: "MIN",
2008
+ value: "MIN",
2009
+ icon: "MinSingle"
2010
+ }
2011
+ ]
2012
+ };
2013
+ }
2014
+ function Ko(i) {
2015
+ return {
2016
+ id: En.id,
2017
+ title: "formula.insert.more",
2018
+ positions: Ot.id,
2019
+ type: wt.BUTTON
2020
+ };
2021
+ }
2022
+ function Go(i) {
2023
+ return {
2024
+ id: xn.id,
2025
+ type: wt.BUTTON,
2026
+ title: "formula.operation.pasteFormula",
2027
+ positions: [Fr]
2028
+ };
2029
+ }
2030
+ const Bn = "meta_key_ctrl_And_Shift", ot = [
2031
+ A.ARROW_DOWN,
2032
+ A.ARROW_UP,
2033
+ A.ARROW_LEFT,
2034
+ A.ARROW_RIGHT
2035
+ ], zo = [...ot, A.ENTER, A.TAB];
2036
+ function Yo() {
2037
+ const i = [];
2038
+ for (const e of zo)
2039
+ i.push({
2040
+ id: Ie.id,
2041
+ binding: e,
2042
+ preconditions: (t) => Ne(t),
2043
+ staticParameters: {
2044
+ eventType: ie.Keyboard,
2045
+ keycode: e
2046
+ }
2047
+ });
2048
+ return i;
2049
+ }
2050
+ function Xo() {
2051
+ const i = [];
2052
+ for (const e of ot)
2053
+ i.push({
2054
+ id: Ie.id,
2055
+ binding: e | oe.SHIFT,
2056
+ preconditions: (t) => Ne(t),
2057
+ staticParameters: {
2058
+ eventType: ie.Keyboard,
2059
+ keycode: e,
2060
+ metaKey: oe.SHIFT
2061
+ }
2062
+ });
2063
+ return i;
2064
+ }
2065
+ function Zo() {
2066
+ const i = [];
2067
+ for (const e of ot)
2068
+ i.push({
2069
+ id: Ie.id,
2070
+ binding: e | oe.CTRL_COMMAND,
2071
+ preconditions: (t) => Ne(t),
2072
+ staticParameters: {
2073
+ eventType: ie.Keyboard,
2074
+ keycode: e,
2075
+ metaKey: oe.CTRL_COMMAND
2076
+ }
2077
+ });
2078
+ return i;
2079
+ }
2080
+ function Qo() {
2081
+ const i = [];
2082
+ for (const e of ot)
2083
+ i.push({
2084
+ id: Ie.id,
2085
+ binding: e | oe.SHIFT | oe.CTRL_COMMAND,
2086
+ preconditions: (t) => Ne(t),
2087
+ staticParameters: {
2088
+ eventType: ie.Keyboard,
2089
+ keycode: e,
2090
+ metaKey: Bn
2091
+ }
2092
+ });
2093
+ return i;
2094
+ }
2095
+ const Jo = {
2096
+ id: Tt.id,
2097
+ binding: A.F4,
2098
+ preconditions: (i) => Ne(i)
2099
+ };
2100
+ var es = Object.defineProperty, ts = Object.getOwnPropertyDescriptor, ns = (i, e, t, n) => {
2101
+ for (var r = n > 1 ? void 0 : n ? ts(e, t) : e, o = i.length - 1, s; o >= 0; o--)
2102
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
2103
+ return n && r && es(e, t, r), r;
2104
+ }, ge = (i, e) => (t, n) => e(t, n, i);
2105
+ let ze = class extends V {
2106
+ constructor(i, e, t, n, r, o) {
2107
+ super(), this._injector = i, this._menuService = e, this._commandService = t, this._shortcutService = n, this._uiController = r, this._componentManager = o, this._initialize();
2108
+ }
2109
+ _initialize() {
2110
+ this._registerCommands(), this._registerMenus(), this._registerShortcuts(), this._registerComponents();
2111
+ }
2112
+ _registerMenus() {
2113
+ [Ho, Ko, Go].forEach(
2114
+ (i) => {
2115
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)));
2116
+ }
2117
+ );
2118
+ }
2119
+ _registerCommands() {
2120
+ [
2121
+ Tn,
2122
+ xn,
2123
+ Ot,
2124
+ En,
2125
+ Rt,
2126
+ Ct,
2127
+ Ie,
2128
+ Tt
2129
+ ].forEach((i) => this.disposeWithMe(this._commandService.registerCommand(i)));
2130
+ }
2131
+ _registerShortcuts() {
2132
+ [
2133
+ ...Yo(),
2134
+ ...Xo(),
2135
+ ...Zo(),
2136
+ ...Qo(),
2137
+ Jo
2138
+ ].forEach((i) => {
2139
+ this.disposeWithMe(this._shortcutService.registerShortcut(i));
2140
+ });
2141
+ }
2142
+ _registerComponents() {
2143
+ this.disposeWithMe(
2144
+ this._uiController.registerContentComponent(
2145
+ () => Dr(io, this._injector)
2146
+ )
2147
+ ), this._componentManager.register(On, Wo);
2148
+ }
2149
+ };
2150
+ ze = ns([
2151
+ Y(X.Ready, ze),
2152
+ ge(0, x(et)),
2153
+ ge(1, Er),
2154
+ ge(2, Z),
2155
+ ge(3, Lr),
2156
+ ge(4, Ar),
2157
+ ge(5, x(Or))
2158
+ ], ze);
2159
+ const Jt = "formula_reference_selection_plugin_name";
2160
+ function dt(i, e, t) {
2161
+ const n = i.getCurrentTheme(), r = new yn(e).setAlpha(0.05).toString();
2162
+ return {
2163
+ id: t,
2164
+ strokeWidth: 2,
2165
+ stroke: e,
2166
+ // strokeDash: 10,
2167
+ fill: r,
2168
+ widgets: { tl: !0, tc: !0, tr: !0, ml: !0, mr: !0, bl: !0, bc: !0, br: !0 },
2169
+ widgetSize: 6,
2170
+ widgetStrokeWidth: 1,
2171
+ widgetStroke: n.colorWhite,
2172
+ hasAutoFill: !1,
2173
+ hasRowHeader: !1,
2174
+ hasColumnHeader: !1
2175
+ };
2176
+ }
2177
+ var rs = Object.defineProperty, is = Object.getOwnPropertyDescriptor, os = (i, e, t, n) => {
2178
+ for (var r = n > 1 ? void 0 : n ? is(e, t) : e, o = i.length - 1, s; o >= 0; o--)
2179
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
2180
+ return n && r && rs(e, t, r), r;
2181
+ }, P = (i, e) => (t, n) => e(t, n, i);
2182
+ let Ye = class extends V {
2183
+ constructor(e, t, n, r, o, s, a, c, l, d, h, m, f, p, v, u, _) {
2184
+ super();
2185
+ F(this, "_formulaRefColors", []);
2186
+ F(this, "_previousSequenceNodes");
2187
+ F(this, "_previousRangesCount", 0);
2188
+ F(this, "_previousInsertRefStringIndex");
2189
+ F(this, "_currentInsertRefStringIndex", -1);
2190
+ F(this, "_currentUnitId");
2191
+ F(this, "_currentSheetId");
2192
+ F(this, "_arrowMoveActionState", 0);
2193
+ F(this, "_isSelectionMovingRefSelections", []);
2194
+ F(this, "_stringColor", "");
2195
+ F(this, "_numberColor", "");
2196
+ F(this, "_insertSelections", []);
2197
+ F(this, "_inputPanelState", 0);
2198
+ this._commandService = e, this._localeService = t, this._contextService = n, this._textSelectionRenderManager = r, this._editorBridgeService = o, this._formulaPromptService = s, this._lexerTreeBuilder = a, this._renderManagerService = c, this._themeService = l, this._selectionManagerService = d, this._sheetSkeletonManagerService = h, this._currentUniverService = m, this._selectionRenderService = f, this._descriptionService = p, this._textSelectionManagerService = v, this._formulaInputService = u, this._docViewModelManagerService = _, this._initialize();
2199
+ }
2200
+ dispose() {
2201
+ this._formulaRefColors = [], this._resetTemp();
2202
+ }
2203
+ _resetTemp() {
2204
+ this._previousSequenceNodes = null, this._previousInsertRefStringIndex = null, this._currentUnitId = null, this._currentSheetId = null, this._isSelectionMovingRefSelections = [], this._previousRangesCount = 0, this._currentInsertRefStringIndex = -1;
2205
+ }
2206
+ _initialize() {
2207
+ this._initialCursorSync(), this._initAcceptFormula(), this._initialFormulaTheme(), this._initialRefSelectionUpdateEvent(), this._initialRefSelectionInsertEvent(), this._initialExitEditor(), this._initialEditorInputChange(), this._commandExecutedListener(), this._cursorStateListener(), this._syncEditorListener();
2208
+ }
2209
+ _initialFormulaTheme() {
2210
+ const e = this._themeService.getCurrentTheme();
2211
+ this._formulaRefColors = [
2212
+ e.loopColor1,
2213
+ e.loopColor2,
2214
+ e.loopColor3,
2215
+ e.loopColor4,
2216
+ e.loopColor5,
2217
+ e.loopColor6,
2218
+ e.loopColor7,
2219
+ e.loopColor8,
2220
+ e.loopColor9,
2221
+ e.loopColor10,
2222
+ e.loopColor11,
2223
+ e.loopColor12
2224
+ ], this._numberColor = e.hyacinth700, this._stringColor = e.verdancy800;
2225
+ }
2226
+ _initialCursorSync() {
2227
+ this.disposeWithMe(
2228
+ U(
2229
+ this._textSelectionRenderManager.textSelection$.subscribe(() => {
2230
+ if (this._editorBridgeService.isVisible().visible === !1 || this._formulaInputService.isSelectionMoving())
2231
+ return;
2232
+ const e = this._getCurrentBody(), t = (e == null ? void 0 : e.dataStream) || "";
2233
+ this._contextSwitch(t), this._changeKeepVisibleHideState(), this._switchSelectionPlugin(), !this._formulaInputService.isLockedSelectionChange() && (this._highlightFormula(), this._changeFunctionPanelState());
2234
+ })
2235
+ )
2236
+ );
2237
+ }
2238
+ _initialEditorInputChange() {
2239
+ this.disposeWithMe(
2240
+ U(
2241
+ this._textSelectionRenderManager.onInputBefore$.subscribe((e) => {
2242
+ this._previousSequenceNodes = null, this._previousInsertRefStringIndex = null, this._selectionRenderService.enableSkipRemainLast();
2243
+ const t = e == null ? void 0 : e.event;
2244
+ t != null && ([A.ARROW_DOWN, A.ARROW_UP, A.ARROW_LEFT, A.ARROW_RIGHT].includes(
2245
+ t.which
2246
+ ) ? this._inputPanelState = 2 : (this._arrowMoveActionState !== 1 && (this._arrowMoveActionState = 2), this._inputPanelState = 1));
2247
+ })
2248
+ )
2249
+ );
2250
+ }
2251
+ _initialExitEditor() {
2252
+ this.disposeWithMe(
2253
+ U(
2254
+ this._editorBridgeService.afterVisible$.subscribe((e) => {
2255
+ if (e.visible === !0) {
2256
+ const { unitId: n, sheetId: r } = this._getCurrentUnitIdAndSheetId();
2257
+ this._currentUnitId == null && (this._currentUnitId = n), this._currentSheetId == null && (this._currentSheetId = r);
2258
+ return;
2259
+ }
2260
+ const t = this._selectionManagerService.getCurrent();
2261
+ if ((t == null ? void 0 : t.pluginName) === Me) {
2262
+ this._disableForceKeepVisible();
2263
+ return;
2264
+ }
2265
+ this._selectionManagerService.clear(), this._selectionManagerService.changePlugin(Me), this._updateEditorModel(`\r
2266
+ `, []), this._contextService.setContextValue(Le, !1), this._disableForceKeepVisible(), this._selectionRenderService.resetStyle(), this._resetTemp(), this._hideFunctionPanel();
2267
+ })
2268
+ )
2269
+ );
2270
+ }
2271
+ _initialRefSelectionUpdateEvent() {
2272
+ const e = new zn();
2273
+ this.disposeWithMe(
2274
+ U(
2275
+ this._selectionManagerService.selectionMoveEnd$.subscribe(() => {
2276
+ e.dispose();
2277
+ const t = this._selectionManagerService.getCurrent();
2278
+ if (this._formulaInputService.disableSelectionMoving(), (t == null ? void 0 : t.pluginName) !== Jt)
2279
+ return;
2280
+ this._updateRefSelectionStyle(this._isSelectionMovingRefSelections), this._selectionRenderService.getCurrentControls().forEach((r) => {
2281
+ r.disableHelperSelection(), e.add(
2282
+ U(
2283
+ r.selectionMoving$.subscribe((o) => {
2284
+ this._changeControlSelection(o, r);
2285
+ })
2286
+ )
2287
+ ), e.add(
2288
+ U(
2289
+ r.selectionScaling$.subscribe((o) => {
2290
+ this._changeControlSelection(o, r);
2291
+ })
2292
+ )
2293
+ ), e.add(
2294
+ U(
2295
+ r.selectionMoved$.subscribe(() => {
2296
+ this._formulaInputService.disableLockedSelectionChange();
2297
+ })
2298
+ )
2299
+ ), e.add(
2300
+ U(
2301
+ r.selectionScaled$.subscribe(() => {
2302
+ this._formulaInputService.disableLockedSelectionChange();
2303
+ })
2304
+ )
2305
+ );
2306
+ });
2307
+ })
2308
+ )
2309
+ );
2310
+ }
2311
+ _syncEditorListener() {
2312
+ this.disposeWithMe(
2313
+ U(
2314
+ this._formulaInputService.syncToEditor$.subscribe((e) => {
2315
+ const { sequences: t, textSelectionOffset: n } = e;
2316
+ this._syncToEditor(t, n);
2317
+ })
2318
+ )
2319
+ );
2320
+ }
2321
+ _selectionChanging(e, t = !1) {
2322
+ if (e.length === 0 || !this._formulaInputService.isLockedSelectionInsert() || (this._formulaInputService.enableSelectionMoving(), this._inertControlSelection(e), t === !1))
2323
+ return;
2324
+ const n = e[e.length - 1];
2325
+ this._inertControlSelectionReplace(n);
2326
+ }
2327
+ _initialRefSelectionInsertEvent() {
2328
+ this.disposeWithMe(
2329
+ U(
2330
+ this._selectionRenderService.selectionMoving$.subscribe((e) => {
2331
+ this._selectionChanging(
2332
+ e.map(
2333
+ (t) => st(t)
2334
+ )
2335
+ );
2336
+ })
2337
+ )
2338
+ ), this.disposeWithMe(
2339
+ U(
2340
+ this._selectionRenderService.selectionMoveStart$.subscribe((e) => {
2341
+ this._selectionChanging(
2342
+ e.map(
2343
+ (t) => st(t)
2344
+ ),
2345
+ !0
2346
+ );
2347
+ })
2348
+ )
2349
+ );
2350
+ }
2351
+ _initAcceptFormula() {
2352
+ this.disposeWithMe(
2353
+ U(
2354
+ this._formulaPromptService.acceptFormulaName$.subscribe((e) => {
2355
+ const t = this._textSelectionRenderManager.getActiveRange();
2356
+ if (t == null) {
2357
+ this._hideFunctionPanel();
2358
+ return;
2359
+ }
2360
+ const { startOffset: n } = t, r = this._formulaInputService.getSequenceNodes(), o = this._formulaInputService.getCurrentSequenceNodeIndex(n - 2), s = r[o];
2361
+ if (s == null || typeof s == "string") {
2362
+ this._hideFunctionPanel();
2363
+ return;
2364
+ }
2365
+ const a = e.length - s.token.length, c = { ...s };
2366
+ c.token = e, c.endIndex += a, r[o] = c, r.splice(o + 1, 0, H.OPEN_BRACKET);
2367
+ const l = e.length + 1;
2368
+ for (let d = o + 2, h = r.length; d < h; d++) {
2369
+ const m = r[d];
2370
+ if (typeof m == "string")
2371
+ continue;
2372
+ const f = { ...m };
2373
+ f.startIndex += l, f.endIndex += l, r[d] = f;
2374
+ }
2375
+ this._syncToEditor(r, c.endIndex + 2);
2376
+ })
2377
+ )
2378
+ );
2379
+ }
2380
+ _changeFunctionPanelState() {
2381
+ const e = this._textSelectionRenderManager.getActiveRange();
2382
+ if (e == null) {
2383
+ this._hideFunctionPanel();
2384
+ return;
2385
+ }
2386
+ const { startOffset: t } = e, n = this._formulaInputService.getCurrentSequenceNode(t - 2);
2387
+ if (n == null) {
2388
+ this._hideFunctionPanel();
2389
+ return;
2390
+ }
2391
+ if (typeof n != "string" && n.nodeType === K.FUNCTION) {
2392
+ const l = n.token.toUpperCase();
2393
+ if (this._inputPanelState === 1) {
2394
+ const d = this._descriptionService.getSearchListByName(l);
2395
+ if (this._hideFunctionPanel(), d == null || d.length === 0)
2396
+ return;
2397
+ this._commandService.executeCommand(Rt.id, {
2398
+ visible: !0,
2399
+ searchText: l,
2400
+ searchList: d
2401
+ });
2402
+ } else
2403
+ this._descriptionService.hasFunction(l) && this._changeHelpFunctionPanelState(l, -1);
2404
+ return;
2405
+ }
2406
+ const r = this._getCurrentBody(), o = (r == null ? void 0 : r.dataStream) || "", s = this._lexerTreeBuilder.getFunctionAndParameter(o, t - 1);
2407
+ if (s == null) {
2408
+ this._hideFunctionPanel();
2409
+ return;
2410
+ }
2411
+ const { functionName: a, paramIndex: c } = s;
2412
+ this._changeHelpFunctionPanelState(a.toUpperCase(), c);
2413
+ }
2414
+ _changeHelpFunctionPanelState(e, t) {
2415
+ const n = this._descriptionService.getFunctionInfo(e);
2416
+ this._hideFunctionPanel(), n != null && this._commandService.executeCommand(Ct.id, {
2417
+ visible: !0,
2418
+ paramIndex: t,
2419
+ functionInfo: n
2420
+ });
2421
+ }
2422
+ _hideFunctionPanel() {
2423
+ this._commandService.executeCommand(Rt.id, {
2424
+ visible: !1,
2425
+ searchText: ""
2426
+ }), this._commandService.executeCommand(Ct.id, {
2427
+ visible: !1,
2428
+ paramIndex: -1
2429
+ });
2430
+ }
2431
+ /**
2432
+ * If the cursor is located at a formula token,
2433
+ * it is necessary to prohibit the behavior of closing the editor by clicking on the canvas,
2434
+ * in order to generate reference text for the formula.
2435
+ */
2436
+ _changeKeepVisibleHideState() {
2437
+ if (this._getContextState() === !1) {
2438
+ this._disableForceKeepVisible();
2439
+ return;
2440
+ }
2441
+ const e = this._getCurrentChar();
2442
+ if (e == null) {
2443
+ this._disableForceKeepVisible();
2444
+ return;
2445
+ }
2446
+ this._matchRefDrawToken(e) ? (this._editorBridgeService.enableForceKeepVisible(), this._formulaInputService.enableLockedSelectionInsert(), this._selectionRenderService.enableRemainLast(), this._arrowMoveActionState !== 1 && (this._arrowMoveActionState = 2)) : this._disableForceKeepVisible();
2447
+ }
2448
+ /**
2449
+ * Determine whether the character is a token keyword for the formula engine.
2450
+ * @param char
2451
+ * @returns
2452
+ */
2453
+ _matchRefDrawToken(e) {
2454
+ return Jn(e) && e !== H.CLOSE_BRACES && e !== H.CLOSE_BRACKET && e !== H.SINGLE_QUOTATION && e !== H.DOUBLE_QUOTATION || e === " ";
2455
+ }
2456
+ /**
2457
+ *
2458
+ * @returns Return the character under the current cursor in the editor.
2459
+ */
2460
+ _getCurrentChar() {
2461
+ const e = this._textSelectionRenderManager.getActiveRange();
2462
+ if (e == null)
2463
+ return;
2464
+ const { startOffset: t } = e, n = this._getCurrentBody();
2465
+ return n == null || t == null ? void 0 : n.dataStream[t - 1];
2466
+ }
2467
+ /**
2468
+ * Disable the ref string generation mode. In the ref string generation mode,
2469
+ * users can select a certain area using the mouse and arrow keys, and convert the area into a ref string.
2470
+ */
2471
+ _disableForceKeepVisible() {
2472
+ this._editorBridgeService.disableForceKeepVisible(), this._formulaInputService.disableLockedSelectionInsert(), this._currentInsertRefStringIndex = -1, this._selectionRenderService.disableRemainLast(), this._arrowMoveActionState === 2 && (this._arrowMoveActionState = 4);
2473
+ }
2474
+ _getCurrentBody() {
2475
+ var n;
2476
+ const e = this._editorBridgeService.getCurrentEditorId();
2477
+ if (e == null)
2478
+ return;
2479
+ const t = this._currentUniverService.getUniverDocInstance(e);
2480
+ return (n = t == null ? void 0 : t.snapshot) == null ? void 0 : n.body;
2481
+ }
2482
+ _getFormulaAndCellEditorBody() {
2483
+ return [Dt, Pt].map((t) => {
2484
+ const n = this._currentUniverService.getUniverDocInstance(t);
2485
+ return n == null ? void 0 : n.getBody();
2486
+ });
2487
+ }
2488
+ /**
2489
+ * Detect whether the user's input content is a formula. If it is a formula,
2490
+ * serialize the current input content into a sequenceNode;
2491
+ * otherwise, close the formula panel.
2492
+ * @param currentInputValue The text content entered by the user in the editor.
2493
+ * @returns
2494
+ */
2495
+ _contextSwitch(e) {
2496
+ if (_e(e)) {
2497
+ this._contextService.setContextValue(Le, !0);
2498
+ const t = this._lexerTreeBuilder.sequenceNodesBuilder(e.replace(/\r/g, "").replace(/\n/g, "")) || [];
2499
+ this._formulaInputService.setSequenceNodes(t);
2500
+ const n = this._textSelectionRenderManager.getActiveRange();
2501
+ if (n == null)
2502
+ return;
2503
+ const { startOffset: r } = n;
2504
+ this._currentInsertRefStringIndex = r - 1;
2505
+ } else
2506
+ this._contextService.setContextValue(Le, !1), this._formulaInputService.disableLockedSelectionChange(), this._formulaInputService.disableLockedSelectionInsert(), this._formulaInputService.clearSequenceNodes(), this._hideFunctionPanel();
2507
+ }
2508
+ _getContextState() {
2509
+ return this._contextService.getContextValue(Le);
2510
+ }
2511
+ /**
2512
+ * Switch from formula selection state to regular selection state.
2513
+ */
2514
+ _switchSelectionPlugin() {
2515
+ if (this._getContextState() === !0) {
2516
+ this._selectionManagerService.changePluginNoRefresh(Jt);
2517
+ const e = cr(this._themeService);
2518
+ e.strokeDash = 8, e.hasAutoFill = !1, e.hasRowHeader = !1, e.hasColumnHeader = !1, this._selectionRenderService.setStyle(e);
2519
+ } else
2520
+ this._selectionManagerService.changePluginNoRefresh(Me), this._selectionRenderService.resetStyle();
2521
+ }
2522
+ /**
2523
+ * Highlight cell editor and formula bar editor.
2524
+ */
2525
+ _highlightFormula() {
2526
+ if (this._getContextState() === !1)
2527
+ return;
2528
+ const e = this._formulaInputService.getSequenceNodes(), t = this._getFormulaAndCellEditorBody().filter((n) => !!n);
2529
+ if (this._selectionManagerService.clear(), e == null || e.length === 0)
2530
+ t.forEach((n) => n.textRuns = []);
2531
+ else {
2532
+ const { textRuns: n, refSelections: r } = this._buildTextRuns(e);
2533
+ t.forEach((o) => o.textRuns = n), this._refreshSelectionForReference(r);
2534
+ }
2535
+ this._refreshFormulaAndCellEditor();
2536
+ }
2537
+ /**
2538
+ * :
2539
+ * #
2540
+ * Generate styles for formula text, highlighting references, text, numbers, and arrays.
2541
+ * @returns
2542
+ */
2543
+ _buildTextRuns(e) {
2544
+ const t = [], n = [];
2545
+ let r = 0;
2546
+ for (let o = 0, s = e.length; o < s; o++) {
2547
+ const a = e[o];
2548
+ if (typeof a == "string")
2549
+ continue;
2550
+ const { startIndex: c, endIndex: l, nodeType: d, token: h } = a;
2551
+ let m = "";
2552
+ if (d === K.REFERENCE) {
2553
+ const f = r % this._formulaRefColors.length;
2554
+ m = this._formulaRefColors[f], n.push({
2555
+ refIndex: o,
2556
+ themeColor: m,
2557
+ token: h
2558
+ }), r++;
2559
+ } else
2560
+ d === K.NUMBER ? m = this._numberColor : d === K.STRING ? m = this._stringColor : d === K.ARRAY && (m = this._stringColor);
2561
+ m && m.length > 0 && t.push({
2562
+ st: c + 1,
2563
+ ed: l + 2,
2564
+ ts: {
2565
+ cl: {
2566
+ rgb: m
2567
+ }
2568
+ }
2569
+ });
2570
+ }
2571
+ return { textRuns: t, refSelections: n };
2572
+ }
2573
+ /**
2574
+ * Draw the referenced selection text based on the style and token.
2575
+ * @param refSelections
2576
+ * @returns
2577
+ */
2578
+ _refreshSelectionForReference(e) {
2579
+ var c;
2580
+ const { unitId: t, sheetId: n } = this._getCurrentUnitIdAndSheetId(), r = [], o = this._currentUniverService.getUniverSheetInstance(t);
2581
+ if ((o == null ? void 0 : o.getSheetBySheetId(n)) == null)
2582
+ return;
2583
+ let a = null;
2584
+ for (let l = 0, d = e.length; l < d; l++) {
2585
+ const h = e[l], { themeColor: m, token: f, refIndex: p } = h, v = Se(f), { unitId: u, sheetName: _, range: g } = v;
2586
+ if (u != null && u.length > 0 && t !== u)
2587
+ continue;
2588
+ const C = this._getSheetIdByName(t, _.trim());
2589
+ if (_.length !== 0 && C !== n)
2590
+ continue;
2591
+ const b = (c = this._insertSelections.find((y) => {
2592
+ const { startRow: R, startColumn: I, endRow: N, endColumn: E } = y.range;
2593
+ return R === g.startRow && I === g.startColumn && N === g.endRow && E === g.endColumn || R === g.startRow && I === g.startColumn && g.startRow === g.endRow && g.startColumn === g.endColumn;
2594
+ })) == null ? void 0 : c.primary;
2595
+ if (b != null) {
2596
+ const {
2597
+ isMerged: y,
2598
+ isMergedMainCell: R,
2599
+ startRow: I,
2600
+ endRow: N,
2601
+ startColumn: E,
2602
+ endColumn: M
2603
+ } = b;
2604
+ (y || R) && I === g.startRow && E === g.startColumn && g.startRow === g.endRow && g.startColumn === g.endColumn && (g.endRow = N, g.endColumn = M), a = {
2605
+ range: g,
2606
+ primary: b,
2607
+ style: dt(this._themeService, m, p.toString())
2608
+ };
2609
+ continue;
2610
+ }
2611
+ r.push({
2612
+ range: g,
2613
+ primary: b,
2614
+ style: dt(this._themeService, m, p.toString())
2615
+ });
2616
+ }
2617
+ a && r.push(a), r.length !== 0 && this._selectionManagerService.add(r);
2618
+ }
2619
+ _getSheetIdByName(e, t) {
2620
+ var r;
2621
+ const n = this._currentUniverService.getUniverSheetInstance(e);
2622
+ return (r = n == null ? void 0 : n.getSheetBySheetName(er(t))) == null ? void 0 : r.getSheetId();
2623
+ }
2624
+ _getSheetNameById(e, t) {
2625
+ var o;
2626
+ const n = this._currentUniverService.getUniverSheetInstance(e);
2627
+ let r = ((o = n == null ? void 0 : n.getSheetBySheetId(t)) == null ? void 0 : o.getName()) || "";
2628
+ return r.length > 0 && tr(r) && (r = `'${r}'`), r;
2629
+ }
2630
+ _getCurrentUnitIdAndSheetId() {
2631
+ const e = this._sheetSkeletonManagerService.getCurrent();
2632
+ if (e == null) {
2633
+ const o = this._currentUniverService.getCurrentUniverSheetInstance(), s = o.getActiveSheet();
2634
+ return {
2635
+ unitId: o.getUnitId(),
2636
+ sheetId: s.getSheetId()
2637
+ };
2638
+ }
2639
+ const { unitId: t, sheetId: n, skeleton: r } = e;
2640
+ return {
2641
+ unitId: t,
2642
+ sheetId: n,
2643
+ skeleton: r
2644
+ };
2645
+ }
2646
+ /**
2647
+ * Convert the selection range to a ref string for the formula engine, such as A1:B1
2648
+ * @param range
2649
+ * @returns
2650
+ */
2651
+ _getRefString(e) {
2652
+ const { unitId: t, sheetId: n } = this._getCurrentUnitIdAndSheetId();
2653
+ let r = "", o = "";
2654
+ t === this._currentUnitId ? r = "" : r = t, n === this._currentSheetId ? o = "" : o = this._getSheetNameById(t, n);
2655
+ const { range: s, primary: a } = e;
2656
+ let { startRow: c, endRow: l, startColumn: d, endColumn: h } = s;
2657
+ if (a) {
2658
+ const {
2659
+ isMerged: m,
2660
+ isMergedMainCell: f,
2661
+ startRow: p,
2662
+ endRow: v,
2663
+ startColumn: u,
2664
+ endColumn: _
2665
+ } = a;
2666
+ (m || f) && p === c && u === d && v === l && _ === h && (c = p, d = u, l = p, h = u);
2667
+ }
2668
+ return Be({
2669
+ sheetName: o,
2670
+ unitId: r,
2671
+ range: {
2672
+ startRow: c,
2673
+ endRow: l,
2674
+ startColumn: d,
2675
+ endColumn: h
2676
+ }
2677
+ });
2678
+ }
2679
+ /**
2680
+ * Restore the sequenceNode generated by the lexer to the text in the editor, and set the cursor position.
2681
+ * @param sequenceNodes
2682
+ * @param textSelectionOffset
2683
+ * @returns
2684
+ */
2685
+ async _syncToEditor(e, t, n = !0) {
2686
+ const r = on(e), { textRuns: o, refSelections: s } = this._buildTextRuns(e);
2687
+ this._isSelectionMovingRefSelections = s;
2688
+ const a = this._textSelectionManagerService.getLast();
2689
+ if (a == null)
2690
+ return;
2691
+ const { collapsed: c, style: l } = a;
2692
+ this._currentInsertRefStringIndex = t, await this._fitEditorSize(), n ? this._commandService.executeCommand(jr.id, {
2693
+ unitId: this._editorBridgeService.getCurrentEditorId(),
2694
+ body: {
2695
+ dataStream: `=${r}`,
2696
+ textRuns: o
2697
+ },
2698
+ textRanges: [
2699
+ {
2700
+ startOffset: t + 1,
2701
+ endOffset: t + 1,
2702
+ collapsed: c,
2703
+ style: l
2704
+ }
2705
+ ],
2706
+ segmentId: null
2707
+ }) : (this._updateEditorModel(`=${r}\r
2708
+ `, o), this._textSelectionManagerService.replaceTextRanges([
2709
+ {
2710
+ startOffset: t + 1,
2711
+ endOffset: t + 1,
2712
+ collapsed: c,
2713
+ style: l
2714
+ }
2715
+ ]));
2716
+ }
2717
+ async _fitEditorSize() {
2718
+ const e = this._editorBridgeService.getCurrentEditorId();
2719
+ e != null && await this._commandService.syncExecuteCommand(Nr.id, {
2720
+ unitId: e
2721
+ });
2722
+ }
2723
+ /**
2724
+ * Update the editor's model value to facilitate formula updates.
2725
+ * @param dataStream
2726
+ * @param textRuns
2727
+ * @returns
2728
+ */
2729
+ _updateEditorModel(e, t) {
2730
+ const n = this._editorBridgeService.getCurrentEditorId();
2731
+ if (n == null)
2732
+ return;
2733
+ const r = this._currentUniverService.getUniverDocInstance(n), o = this._docViewModelManagerService.getViewModel(n);
2734
+ if (o == null || r == null)
2735
+ return;
2736
+ const s = r == null ? void 0 : r.getSnapshot();
2737
+ if (s == null)
2738
+ return;
2739
+ const a = {
2740
+ dataStream: e,
2741
+ textRuns: t
2742
+ };
2743
+ s.body = a, o.reset(r);
2744
+ }
2745
+ _inertControlSelectionReplace(e) {
2746
+ this._previousSequenceNodes == null && (this._previousSequenceNodes = this._formulaInputService.getSequenceNodes()), this._previousInsertRefStringIndex == null && (this._previousInsertRefStringIndex = this._currentInsertRefStringIndex);
2747
+ const t = G.deepClone(this._previousSequenceNodes);
2748
+ if (t == null)
2749
+ return;
2750
+ const n = this._getRefString(e);
2751
+ this._formulaInputService.setSequenceNodes(t), this._formulaInputService.insertSequenceRef(this._previousInsertRefStringIndex, n), this._syncToEditor(t, this._previousInsertRefStringIndex + n.length);
2752
+ const r = this._selectionRenderService.getSelectionDataWithStyle();
2753
+ this._insertSelections = [], r.forEach((o) => {
2754
+ const s = st(o);
2755
+ this._insertSelections.push(s);
2756
+ });
2757
+ }
2758
+ _inertControlSelection(e) {
2759
+ const t = e[e.length - 1];
2760
+ if ((e.length === this._previousRangesCount || this._previousRangesCount === 0) && this._previousSequenceNodes != null)
2761
+ this._inertControlSelectionReplace(t);
2762
+ else {
2763
+ let n = this._formulaInputService.getSequenceNodes();
2764
+ if (n == null)
2765
+ return;
2766
+ const r = this._getCurrentChar();
2767
+ if (r == null)
2768
+ return;
2769
+ this._previousInsertRefStringIndex = this._currentInsertRefStringIndex, this._matchRefDrawToken(r) || (this._formulaInputService.insertSequenceString(this._currentInsertRefStringIndex, H.COMMA), n = this._formulaInputService.getSequenceNodes(), this._previousInsertRefStringIndex += 1), this._previousSequenceNodes = G.deepClone(n);
2770
+ const o = this._getRefString(t);
2771
+ this._formulaInputService.setSequenceNodes(n), this._formulaInputService.insertSequenceRef(this._previousInsertRefStringIndex, o), this._selectionRenderService.disableSkipRemainLast();
2772
+ }
2773
+ this._arrowMoveActionState = 2, this._previousRangesCount = e.length;
2774
+ }
2775
+ _updateRefSelectionStyle(e) {
2776
+ const t = this._selectionRenderService.getCurrentControls(), { unitId: n, sheetId: r } = this._getCurrentUnitIdAndSheetId();
2777
+ for (let o = 0, s = e.length; o < s; o++) {
2778
+ const a = e[o], { refIndex: c, themeColor: l, token: d } = a, h = Se(d), { unitId: m, sheetName: f, range: p } = h;
2779
+ if (m != null && m.length > 0 && n !== m)
2780
+ continue;
2781
+ const v = this._getSheetIdByName(n, f.trim());
2782
+ if (v != null && v !== r)
2783
+ continue;
2784
+ const u = t.find((g) => {
2785
+ const { startRow: C, startColumn: b, endRow: y, endColumn: R } = g.getRange();
2786
+ return C === p.startRow && b === p.startColumn && y === p.endRow && R === p.endColumn || C === p.startRow && b === p.startColumn && p.startRow === p.endRow && p.startColumn === p.endColumn;
2787
+ });
2788
+ if (u == null)
2789
+ continue;
2790
+ const _ = dt(this._themeService, l, c.toString());
2791
+ u.updateStyle(_);
2792
+ }
2793
+ }
2794
+ _changeControlSelection(e, t) {
2795
+ var u;
2796
+ if (!e)
2797
+ return;
2798
+ const { unitId: n, sheetId: r, skeleton: o } = this._getCurrentUnitIdAndSheetId();
2799
+ this._formulaInputService.enableLockedSelectionChange();
2800
+ const s = (u = t.selectionStyle) == null ? void 0 : u.id;
2801
+ if (s == null || !G.isStringNumber(s))
2802
+ return;
2803
+ let { startRow: a, endRow: c, startColumn: l, endColumn: d } = e;
2804
+ const h = wr(a, l, o == null ? void 0 : o.mergeData);
2805
+ if (h) {
2806
+ const {
2807
+ isMerged: _,
2808
+ isMergedMainCell: g,
2809
+ startRow: C,
2810
+ endRow: b,
2811
+ startColumn: y,
2812
+ endColumn: R
2813
+ } = h;
2814
+ (_ || g) && C === a && y === l && b === c && R === d && (a = C, l = y, c = C, d = y);
2815
+ }
2816
+ const m = this._getRefString({
2817
+ range: {
2818
+ startRow: a,
2819
+ endRow: c,
2820
+ startColumn: l,
2821
+ endColumn: d
2822
+ },
2823
+ primary: h,
2824
+ style: null
2825
+ }), f = Number(s);
2826
+ this._formulaInputService.updateSequenceRef(f, m);
2827
+ const p = this._formulaInputService.getSequenceNodes(), v = p[f];
2828
+ typeof v != "string" && (this._syncToEditor(p, v.endIndex + 1), t.update(e));
2829
+ }
2830
+ _refreshFormulaAndCellEditor() {
2831
+ var t;
2832
+ const e = [Dt, Pt];
2833
+ for (const n of e) {
2834
+ const r = vt(n, this._renderManagerService), o = r == null ? void 0 : r.document;
2835
+ o != null && ((t = o.getSkeleton()) == null || t.calculate(), o.makeDirty());
2836
+ }
2837
+ }
2838
+ _cursorStateListener() {
2839
+ const e = this._getEditorObject();
2840
+ if (e == null)
2841
+ return;
2842
+ const { document: t } = e;
2843
+ this.disposeWithMe(
2844
+ U(
2845
+ t.onPointerDownObserver.add(() => {
2846
+ this._arrowMoveActionState = 1, this._inputPanelState = 3;
2847
+ })
2848
+ )
2849
+ );
2850
+ }
2851
+ _commandExecutedListener() {
2852
+ const e = [Ie.id];
2853
+ this.disposeWithMe(
2854
+ this._commandService.onCommandExecuted((t) => {
2855
+ if (e.includes(t.id)) {
2856
+ const n = t.params, { keycode: r, metaKey: o } = n;
2857
+ if (r === A.ENTER) {
2858
+ if (this._formulaPromptService.isSearching()) {
2859
+ this._formulaPromptService.accept(!0);
2860
+ return;
2861
+ }
2862
+ this._editorBridgeService.changeVisible({
2863
+ visible: !1,
2864
+ eventType: ie.Keyboard,
2865
+ keycode: r
2866
+ }), this._commandService.executeCommand(Ue.id, {
2867
+ direction: L.DOWN
2868
+ });
2869
+ return;
2870
+ }
2871
+ if (r === A.TAB) {
2872
+ if (this._formulaPromptService.isSearching()) {
2873
+ this._formulaPromptService.accept(!0);
2874
+ return;
2875
+ }
2876
+ this._editorBridgeService.changeVisible({
2877
+ visible: !1,
2878
+ eventType: ie.Keyboard,
2879
+ keycode: r
2880
+ }), this._commandService.executeCommand(Ue.id, {
2881
+ direction: L.RIGHT
2882
+ });
2883
+ return;
2884
+ }
2885
+ if (this._formulaPromptService.isSearching()) {
2886
+ if (r === A.ARROW_DOWN) {
2887
+ this._formulaPromptService.navigate({ direction: L.DOWN });
2888
+ return;
2889
+ }
2890
+ if (r === A.ARROW_UP) {
2891
+ this._formulaPromptService.navigate({ direction: L.UP });
2892
+ return;
2893
+ }
2894
+ }
2895
+ if (this._arrowMoveActionState === 1) {
2896
+ this._moveInEditor(r);
2897
+ return;
2898
+ }
2899
+ if (this._arrowMoveActionState === 4) {
2900
+ this._editorBridgeService.changeVisible({
2901
+ visible: !1,
2902
+ eventType: ie.Keyboard,
2903
+ keycode: r
2904
+ });
2905
+ return;
2906
+ }
2907
+ if (this._arrowMoveActionState === 2 && (this._arrowMoveActionState = 3), (this._selectionManagerService.getSelectionRanges() || []).length === 0) {
2908
+ const d = this._selectionManagerService.getLastByPlugin(Me);
2909
+ if (d != null) {
2910
+ const h = G.deepClone(d);
2911
+ this._selectionManagerService.add([h]);
2912
+ }
2913
+ }
2914
+ let a = L.DOWN;
2915
+ r === A.ARROW_DOWN ? a = L.DOWN : r === A.ARROW_UP ? a = L.UP : r === A.ARROW_LEFT ? a = L.LEFT : r === A.ARROW_RIGHT && (a = L.RIGHT), o === oe.CTRL_COMMAND ? this._commandService.executeCommand(Ue.id, {
2916
+ direction: a,
2917
+ jumpOver: Gt.moveGap
2918
+ }) : o === oe.SHIFT ? this._commandService.executeCommand(zt.id, {
2919
+ direction: a
2920
+ }) : o === Bn ? this._commandService.executeCommand(zt.id, {
2921
+ direction: a,
2922
+ jumpOver: Gt.moveGap
2923
+ }) : this._commandService.executeCommand(Ue.id, {
2924
+ direction: a
2925
+ });
2926
+ const c = this._selectionManagerService.getSelections() || [], l = c[c.length - 1];
2927
+ this._inertControlSelectionReplace(l);
2928
+ }
2929
+ })
2930
+ );
2931
+ }
2932
+ _moveInEditor(e) {
2933
+ if (e == null)
2934
+ return;
2935
+ let t = L.LEFT;
2936
+ e === A.ARROW_DOWN ? t = L.DOWN : e === A.ARROW_UP ? t = L.UP : e === A.ARROW_RIGHT && (t = L.RIGHT), this._commandService.executeCommand(Br.id, {
2937
+ direction: t
2938
+ });
2939
+ }
2940
+ _getEditorObject() {
2941
+ return vt(this._editorBridgeService.getCurrentEditorId(), this._renderManagerService);
2942
+ }
2943
+ };
2944
+ Ye = os([
2945
+ Y(X.Steady, Ye),
2946
+ P(0, Z),
2947
+ P(1, x(Ce)),
2948
+ P(2, yt),
2949
+ P(3, Mn),
2950
+ P(4, x(bt)),
2951
+ P(5, x(de)),
2952
+ P(6, x(Re)),
2953
+ P(7, Nt),
2954
+ P(8, x(nn)),
2955
+ P(9, x(Mt)),
2956
+ P(10, x(Cn)),
2957
+ P(11, ve),
2958
+ P(12, x(Rn)),
2959
+ P(13, x(Et)),
2960
+ P(14, x(qr)),
2961
+ P(15, Te),
2962
+ P(16, x(Vr))
2963
+ ], Ye);
2964
+ var ss = Object.defineProperty, as = Object.getOwnPropertyDescriptor, cs = (i, e, t, n) => {
2965
+ for (var r = n > 1 ? void 0 : n ? as(e, t) : e, o = i.length - 1, s; o >= 0; o--)
2966
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
2967
+ return n && r && ss(e, t, r), r;
2968
+ }, en = (i, e) => (t, n) => e(t, n, i);
2969
+ let Xe = class extends V {
2970
+ constructor(e, t) {
2971
+ super();
2972
+ F(this, "_waitingCommandQueue", []);
2973
+ F(this, "_setTimeoutKey", -1);
2974
+ F(this, "_startExecutionTime", 0);
2975
+ this._commandService = e, this._activeDirtyManagerService = t, this._initialize();
2976
+ }
2977
+ _initialize() {
2978
+ this._commandExecutedListener(), this._initialExecuteFormulaProcessListener(), this._initialExecuteFormula();
2979
+ }
2980
+ _commandExecutedListener() {
2981
+ this.disposeWithMe(
2982
+ this._commandService.onCommandExecuted((e, t) => {
2983
+ if (this._activeDirtyManagerService.get(e.id)) {
2984
+ if (e.id === re.id) {
2985
+ const n = e.params;
2986
+ if (t && t.local === !0 || n.trigger === sn.id)
2987
+ return;
2988
+ }
2989
+ this._waitingCommandQueue.push(e), clearTimeout(this._setTimeoutKey), this._setTimeoutKey = setTimeout(() => {
2990
+ this._commandService.executeCommand(
2991
+ kt.id,
2992
+ {
2993
+ ...this._generateDirty(this._waitingCommandQueue)
2994
+ },
2995
+ {
2996
+ local: !0
2997
+ }
2998
+ ), this._startExecutionTime = performance.now();
2999
+ }, 100);
3000
+ }
3001
+ })
3002
+ );
3003
+ }
3004
+ _generateDirty(e) {
3005
+ const t = [], n = {}, r = {};
3006
+ for (const o of e) {
3007
+ const s = this._activeDirtyManagerService.get(o.id);
3008
+ if (s == null)
3009
+ continue;
3010
+ const a = s.getDirtyData(o), { dirtyRanges: c, dirtyNameMap: l, dirtyUnitFeatureMap: d } = a;
3011
+ c != null && t.push(...c), l != null && this._mergeDirtyNameMap(n, l), d != null && this._mergeDirtyUnitFeatureMap(r, d);
3012
+ }
3013
+ return {
3014
+ dirtyRanges: t,
3015
+ dirtyNameMap: n,
3016
+ dirtyUnitFeatureMap: r
3017
+ };
3018
+ }
3019
+ _mergeDirtyNameMap(e, t) {
3020
+ Object.keys(t).forEach((n) => {
3021
+ e[n] == null && (e[n] = {}), Object.keys(t[n]).forEach((r) => {
3022
+ e[n][r] = t[n][r];
3023
+ });
3024
+ });
3025
+ }
3026
+ _mergeDirtyUnitFeatureMap(e, t) {
3027
+ Object.keys(t).forEach((n) => {
3028
+ e[n] == null && (e[n] = {}), Object.keys(t[n]).forEach((r) => {
3029
+ e[n][r] == null && (e[n][r] = {}), Object.keys(t[n][r]).forEach((o) => {
3030
+ e[n][r][o] = t[n][r][o];
3031
+ });
3032
+ });
3033
+ });
3034
+ }
3035
+ _initialExecuteFormulaProcessListener() {
3036
+ this.disposeWithMe(
3037
+ this._commandService.onCommandExecuted((e) => {
3038
+ if (e.id !== nr.id)
3039
+ return;
3040
+ const t = e.params;
3041
+ if (t.stageInfo != null) {
3042
+ const {
3043
+ totalFormulasToCalculate: n,
3044
+ completedFormulasCount: r,
3045
+ totalArrayFormulasToCalculate: o,
3046
+ completedArrayFormulasCount: s,
3047
+ stage: a
3048
+ } = t.stageInfo;
3049
+ o > 0 ? console.log(
3050
+ `Stage ${a} Array formula.There are ${o} functions to be executed, ${s} complete.`
3051
+ ) : console.log(
3052
+ `Stage ${a} .There are ${n} functions to be executed, ${r} complete.`
3053
+ );
3054
+ } else {
3055
+ const n = t.functionsExecutedState;
3056
+ let r = "";
3057
+ switch (n) {
3058
+ case De.NOT_EXECUTED:
3059
+ r = "No tasks are being executed anymore";
3060
+ break;
3061
+ case De.STOP_EXECUTION:
3062
+ r = "The execution of the formula has been stopped";
3063
+ break;
3064
+ case De.SUCCESS:
3065
+ r = `Formula calculation succeeded, Total time consumed: ${performance.now() - this._startExecutionTime} ms`;
3066
+ break;
3067
+ case De.INITIAL:
3068
+ r = "Waiting for calculation";
3069
+ break;
3070
+ }
3071
+ console.log(`execution result${r}`);
3072
+ }
3073
+ })
3074
+ );
3075
+ }
3076
+ _initialExecuteFormula() {
3077
+ this._commandService.executeCommand(
3078
+ kt.id,
3079
+ {
3080
+ commands: [],
3081
+ forceCalculation: !0
3082
+ },
3083
+ {
3084
+ local: !0
3085
+ }
3086
+ );
3087
+ }
3088
+ };
3089
+ Xe = cs([
3090
+ Y(X.Ready, Xe),
3091
+ en(0, Z),
3092
+ en(1, xt)
3093
+ ], Xe);
3094
+ function $e(i, e, t, n, r) {
3095
+ const { id: o } = e;
3096
+ if (qn(i, t, n))
3097
+ return i;
3098
+ const s = new D(i[t][n]);
3099
+ switch (o) {
3100
+ case vn.id:
3101
+ ls(s, e);
3102
+ break;
3103
+ case Sn.id:
3104
+ us(s, e, r);
3105
+ break;
3106
+ case _n.id:
3107
+ ms(s, e, r);
3108
+ break;
3109
+ case pn.id:
3110
+ ds(s, e);
3111
+ break;
3112
+ case gn.id:
3113
+ hs(s, e);
3114
+ break;
3115
+ case fn.id:
3116
+ fs(s, e);
3117
+ break;
3118
+ case hn.id:
3119
+ gs(s, e);
3120
+ break;
3121
+ case dn.id:
3122
+ ps(s, e);
3123
+ break;
3124
+ case mn.id:
3125
+ _s(s, e);
3126
+ break;
3127
+ case un.id:
3128
+ Ss(s, e);
3129
+ break;
3130
+ case ln.id:
3131
+ vs(s, e);
3132
+ break;
3133
+ }
3134
+ return i;
3135
+ }
3136
+ function ls(i, e) {
3137
+ const { params: t } = e;
3138
+ if (!t)
3139
+ return;
3140
+ const { fromRange: n, toRange: r } = t, {
3141
+ startRow: o,
3142
+ endRow: s,
3143
+ startColumn: a,
3144
+ endColumn: c
3145
+ } = n, { startRow: l, endRow: d, startColumn: h, endColumn: m } = r, f = new D();
3146
+ for (let p = o; p <= s; p++)
3147
+ for (let v = a; v <= c; v++) {
3148
+ const u = i.getValue(p, v);
3149
+ f.setValue(p - o, v - a, u), i.setValue(p, v, null);
3150
+ }
3151
+ for (let p = l; p <= d; p++)
3152
+ for (let v = h; v <= m; v++) {
3153
+ const u = f.getValue(p - l, v - h);
3154
+ i.setValue(p, v, u);
3155
+ }
3156
+ }
3157
+ function us(i, e, t) {
3158
+ const { params: n } = e;
3159
+ if (!n)
3160
+ return;
3161
+ const { fromRow: r, toRow: o } = n, s = t == null ? void 0 : t.filter(
3162
+ (d) => d.range.rangeType === pe.ROW && d.range.startRow <= r && r <= d.range.endRow
3163
+ );
3164
+ if ((s == null ? void 0 : s.length) !== 1)
3165
+ return;
3166
+ const a = s[0].range, c = a.startRow, l = a.endRow - a.startRow + 1;
3167
+ i.moveRows(c, l, o);
3168
+ }
3169
+ function ms(i, e, t) {
3170
+ const { params: n } = e;
3171
+ if (!n)
3172
+ return;
3173
+ const { fromCol: r, toCol: o } = n, s = t == null ? void 0 : t.filter(
3174
+ (d) => d.range.rangeType === pe.COLUMN && d.range.startColumn <= r && r <= d.range.endColumn
3175
+ );
3176
+ if ((s == null ? void 0 : s.length) !== 1)
3177
+ return;
3178
+ const a = s[0].range, c = a.startColumn, l = a.endColumn - a.startColumn + 1;
3179
+ i.moveColumns(c, l, o);
3180
+ }
3181
+ function ds(i, e) {
3182
+ const { params: t } = e;
3183
+ if (!t)
3184
+ return;
3185
+ const { range: n } = t, r = i.getLength() - 1, o = i.getRange().endColumn;
3186
+ nt(i, [n], r, o, z.ROWS);
3187
+ }
3188
+ function hs(i, e) {
3189
+ const { params: t } = e;
3190
+ if (!t)
3191
+ return;
3192
+ const { range: n } = t, r = i.getLength() - 1, o = i.getRange().endColumn;
3193
+ nt(i, [n], r, o, z.COLUMNS);
3194
+ }
3195
+ function fs(i, e) {
3196
+ const { params: t } = e;
3197
+ if (!t)
3198
+ return;
3199
+ const { ranges: n } = t, r = i.getLength() - 1, o = i.getRange().endColumn;
3200
+ nt(i, n, r, o, z.COLUMNS);
3201
+ }
3202
+ function gs(i, e) {
3203
+ const { params: t } = e;
3204
+ if (!t)
3205
+ return;
3206
+ const { ranges: n } = t, r = i.getLength() - 1, o = i.getRange().endColumn;
3207
+ nt(i, n, r, o, z.ROWS);
3208
+ }
3209
+ function ps(i, e) {
3210
+ const { params: t } = e;
3211
+ if (!t)
3212
+ return;
3213
+ const { ranges: n } = t, r = i.getLength() - 1, o = i.getRange().endColumn;
3214
+ rt(i, n, r, o, z.ROWS);
3215
+ }
3216
+ function _s(i, e) {
3217
+ const { params: t } = e;
3218
+ if (!t)
3219
+ return;
3220
+ const { ranges: n } = t, r = i.getLength() - 1, o = i.getRange().endColumn;
3221
+ rt(i, n, r, o, z.COLUMNS);
3222
+ }
3223
+ function Ss(i, e) {
3224
+ const { params: t } = e;
3225
+ if (!t)
3226
+ return;
3227
+ const { ranges: n } = t, r = i.getLength() - 1, o = i.getRange().endColumn;
3228
+ rt(i, n, r, o, z.ROWS);
3229
+ }
3230
+ function vs(i, e) {
3231
+ const { params: t } = e;
3232
+ if (!t)
3233
+ return;
3234
+ const { ranges: n } = t, r = i.getLength() - 1, o = i.getRange().endColumn;
3235
+ rt(i, n, r, o, z.COLUMNS);
3236
+ }
3237
+ function Cs(i, e, t) {
3238
+ if (qn(i, e, t))
3239
+ return i;
3240
+ const n = new D(i[e][t]);
3241
+ return n.forValue((r, o, s) => {
3242
+ const { startRow: a, startColumn: c, endRow: l, endColumn: d } = s;
3243
+ if (r === a && o === c)
3244
+ return;
3245
+ const h = l - a, m = d - c, f = {
3246
+ startRow: r,
3247
+ startColumn: o,
3248
+ endRow: r + h,
3249
+ endColumn: o + m
3250
+ };
3251
+ n.setValue(r, o, f);
3252
+ }), i;
3253
+ }
3254
+ function qn(i, e, t) {
3255
+ return i == null || i[e] == null || i[e][t] == null;
3256
+ }
3257
+ var Rs = Object.defineProperty, Is = Object.getOwnPropertyDescriptor, ys = (i, e, t, n) => {
3258
+ for (var r = n > 1 ? void 0 : n ? Is(e, t) : e, o = i.length - 1, s; o >= 0; o--)
3259
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
3260
+ return n && r && Rs(e, t, r), r;
3261
+ }, ue = (i, e) => (t, n) => e(t, n, i);
3262
+ let Ze = class extends V {
3263
+ constructor(i, e, t, n, r, o, s) {
3264
+ super(), this._currentUniverService = i, this._commandService = e, this._lexerTreeBuilder = t, this._formulaDataModel = n, this._sheetInterceptorService = r, this._selectionManagerService = o, this._injector = s, this._initialize();
3265
+ }
3266
+ _initialize() {
3267
+ this._commandExecutedListener();
3268
+ }
3269
+ _commandExecutedListener() {
3270
+ this.disposeWithMe(
3271
+ this._sheetInterceptorService.interceptCommand({
3272
+ getMutations: (i) => this._getUpdateFormula(i)
3273
+ })
3274
+ ), this.disposeWithMe(
3275
+ this._commandService.onCommandExecuted((i, e) => {
3276
+ const { id: t, params: n } = i;
3277
+ if (n)
3278
+ switch (t) {
3279
+ case re.id:
3280
+ this._handleSetRangeValuesMutation(n, e);
3281
+ break;
3282
+ case _t.id:
3283
+ this._handleRemoveSheetMutation(n);
3284
+ break;
3285
+ case St.id:
3286
+ this._handleInsertSheetMutation(n);
3287
+ break;
3288
+ }
3289
+ })
3290
+ );
3291
+ }
3292
+ _handleSetRangeValuesMutation(i, e) {
3293
+ const { worksheetId: t, workbookId: n, cellValue: r } = i;
3294
+ e && e.local === !0 || r == null || (this._formulaDataModel.updateFormulaData(n, t, r), this._commandService.executeCommand(
3295
+ Pe.id,
3296
+ {
3297
+ formulaData: this._formulaDataModel.getFormulaData()
3298
+ },
3299
+ {
3300
+ local: !0
3301
+ }
3302
+ ));
3303
+ }
3304
+ _handleRemoveSheetMutation(i) {
3305
+ const { worksheetId: e, workbookId: t } = i, n = this._formulaDataModel.getFormulaData();
3306
+ delete n[t][e];
3307
+ const r = this._formulaDataModel.getArrayFormulaRange();
3308
+ delete r[t][e];
3309
+ const o = this._formulaDataModel.getArrayFormulaCellData();
3310
+ delete o[t][e], this._commandService.executeCommand(Pe.id, {
3311
+ formulaData: n
3312
+ }), this._commandService.executeCommand(pt.id, {
3313
+ arrayFormulaRange: r,
3314
+ arrayFormulaCellData: o
3315
+ });
3316
+ }
3317
+ _handleInsertSheetMutation(i) {
3318
+ const { sheet: e, workbookId: t } = i, n = this._formulaDataModel.getFormulaData(), { id: r, cellData: o } = e, s = new D(o);
3319
+ rr(n, t, r, s), this._commandService.executeCommand(Pe.id, {
3320
+ formulaData: n
3321
+ });
3322
+ }
3323
+ _getUpdateFormula(i) {
3324
+ const { id: e } = i;
3325
+ let t = null;
3326
+ switch (e) {
3327
+ case vn.id:
3328
+ t = this._handleMoveRange(i);
3329
+ break;
3330
+ case Sn.id:
3331
+ t = this._handleMoveRows(i);
3332
+ break;
3333
+ case _n.id:
3334
+ t = this._handleMoveCols(i);
3335
+ break;
3336
+ case pn.id:
3337
+ t = this._handleInsertRow(i);
3338
+ break;
3339
+ case gn.id:
3340
+ t = this._handleInsertCol(i);
3341
+ break;
3342
+ case fn.id:
3343
+ t = this._handleInsertRangeMoveRight(i);
3344
+ break;
3345
+ case hn.id:
3346
+ t = this._handleInsertRangeMoveDown(i);
3347
+ break;
3348
+ case dn.id:
3349
+ t = this._handleRemoveRow(i);
3350
+ break;
3351
+ case mn.id:
3352
+ t = this._handleRemoveCol(i);
3353
+ break;
3354
+ case un.id:
3355
+ t = this._handleDeleteRangeMoveUp(i);
3356
+ break;
3357
+ case ln.id:
3358
+ t = this._handleDeleteRangeMoveLeft(i);
3359
+ break;
3360
+ case lr.id:
3361
+ t = this._handleSetWorksheetName(i);
3362
+ break;
3363
+ }
3364
+ if (t) {
3365
+ const { unitSheetNameMap: n } = this._formulaDataModel.getCalculateData();
3366
+ let r = this._formulaDataModel.getFormulaData();
3367
+ const o = this._getFormulaReferenceMoveInfo(r, n, t), s = this._currentUniverService.getCurrentUniverSheetInstance(), a = s.getUnitId(), c = s.getActiveSheet().getSheetId(), l = this._selectionManagerService.getSelections(), d = this._formulaDataModel.getArrayFormulaRange(), h = this._formulaDataModel.getArrayFormulaCellData();
3368
+ let m = $e(d, i, a, c, l);
3369
+ m = Cs(m, a, c);
3370
+ const f = $e(
3371
+ h,
3372
+ i,
3373
+ a,
3374
+ c,
3375
+ l
3376
+ );
3377
+ this._commandService.executeCommand(
3378
+ pt.id,
3379
+ {
3380
+ arrayFormulaRange: m,
3381
+ arrayFormulaCellData: f
3382
+ },
3383
+ {
3384
+ local: !0
3385
+ }
3386
+ ), r = $e(r, i, a, c, l);
3387
+ const p = $e(o, i, a, c, l);
3388
+ return this._commandService.executeCommand(Pe.id, {
3389
+ formulaData: this._formulaDataModel.getFormulaData()
3390
+ }), this._getUpdateFormulaMutations(r, p);
3391
+ }
3392
+ return {
3393
+ undos: [],
3394
+ redos: []
3395
+ };
3396
+ }
3397
+ _handleMoveRange(i) {
3398
+ const { params: e } = i;
3399
+ if (!e)
3400
+ return null;
3401
+ const { fromRange: t, toRange: n } = e;
3402
+ if (!t || !n)
3403
+ return null;
3404
+ const { unitId: r, sheetId: o } = this._getCurrentSheetInfo();
3405
+ return {
3406
+ type: 0,
3407
+ from: t,
3408
+ to: n,
3409
+ unitId: r,
3410
+ sheetId: o
3411
+ };
3412
+ }
3413
+ _handleMoveRows(i) {
3414
+ const { params: e } = i;
3415
+ if (!e)
3416
+ return null;
3417
+ const { fromRow: t, toRow: n } = e, r = this._currentUniverService.getCurrentUniverSheetInstance(), o = r.getUnitId(), s = r.getActiveSheet(), a = s.getSheetId(), c = {
3418
+ startRow: t,
3419
+ startColumn: 0,
3420
+ endRow: t,
3421
+ endColumn: s.getColumnCount() - 1,
3422
+ rangeType: pe.ROW
3423
+ }, l = {
3424
+ startRow: n,
3425
+ startColumn: 0,
3426
+ endRow: n,
3427
+ endColumn: s.getColumnCount() - 1,
3428
+ rangeType: pe.ROW
3429
+ };
3430
+ return {
3431
+ type: 0,
3432
+ from: c,
3433
+ to: l,
3434
+ unitId: o,
3435
+ sheetId: a
3436
+ };
3437
+ }
3438
+ _handleMoveCols(i) {
3439
+ const { params: e } = i;
3440
+ if (!e)
3441
+ return null;
3442
+ const { fromCol: t, toCol: n } = e, r = this._currentUniverService.getCurrentUniverSheetInstance(), o = r.getUnitId(), s = r.getActiveSheet(), a = s.getSheetId(), c = {
3443
+ startRow: 0,
3444
+ startColumn: t,
3445
+ endRow: s.getRowCount() - 1,
3446
+ endColumn: t,
3447
+ rangeType: pe.COLUMN
3448
+ }, l = {
3449
+ startRow: 0,
3450
+ startColumn: n,
3451
+ endRow: s.getRowCount() - 1,
3452
+ endColumn: n,
3453
+ rangeType: pe.COLUMN
3454
+ };
3455
+ return {
3456
+ type: 0,
3457
+ from: c,
3458
+ to: l,
3459
+ unitId: o,
3460
+ sheetId: a
3461
+ };
3462
+ }
3463
+ _handleInsertRow(i) {
3464
+ const { params: e } = i;
3465
+ if (!e)
3466
+ return null;
3467
+ const { range: t, workbookId: n, worksheetId: r } = e;
3468
+ return {
3469
+ type: 1,
3470
+ ranges: [t],
3471
+ unitId: n,
3472
+ sheetId: r
3473
+ };
3474
+ }
3475
+ _handleInsertCol(i) {
3476
+ const { params: e } = i;
3477
+ if (!e)
3478
+ return null;
3479
+ const { range: t, workbookId: n, worksheetId: r } = e;
3480
+ return {
3481
+ type: 2,
3482
+ ranges: [t],
3483
+ unitId: n,
3484
+ sheetId: r
3485
+ };
3486
+ }
3487
+ _handleInsertRangeMoveRight(i) {
3488
+ const { params: e } = i;
3489
+ if (!e)
3490
+ return null;
3491
+ const { ranges: t } = e, { unitId: n, sheetId: r } = this._getCurrentSheetInfo();
3492
+ return {
3493
+ type: 8,
3494
+ ranges: t,
3495
+ unitId: n,
3496
+ sheetId: r
3497
+ };
3498
+ }
3499
+ _handleInsertRangeMoveDown(i) {
3500
+ const { params: e } = i;
3501
+ if (!e)
3502
+ return null;
3503
+ const { ranges: t } = e, { unitId: n, sheetId: r } = this._getCurrentSheetInfo();
3504
+ return {
3505
+ type: 7,
3506
+ ranges: t,
3507
+ unitId: n,
3508
+ sheetId: r
3509
+ };
3510
+ }
3511
+ _handleRemoveRow(i) {
3512
+ const { params: e } = i;
3513
+ if (!e)
3514
+ return null;
3515
+ const { ranges: t } = e, { unitId: n, sheetId: r } = this._getCurrentSheetInfo();
3516
+ return {
3517
+ type: 3,
3518
+ ranges: t,
3519
+ unitId: n,
3520
+ sheetId: r
3521
+ };
3522
+ }
3523
+ _handleRemoveCol(i) {
3524
+ const { params: e } = i;
3525
+ if (!e)
3526
+ return null;
3527
+ const { ranges: t } = e, { unitId: n, sheetId: r } = this._getCurrentSheetInfo();
3528
+ return {
3529
+ type: 4,
3530
+ ranges: t,
3531
+ unitId: n,
3532
+ sheetId: r
3533
+ };
3534
+ }
3535
+ _handleDeleteRangeMoveUp(i) {
3536
+ const { params: e } = i;
3537
+ if (!e)
3538
+ return null;
3539
+ const { ranges: t } = e, { unitId: n, sheetId: r } = this._getCurrentSheetInfo();
3540
+ return {
3541
+ type: 6,
3542
+ ranges: t,
3543
+ unitId: n,
3544
+ sheetId: r
3545
+ };
3546
+ }
3547
+ _handleDeleteRangeMoveLeft(i) {
3548
+ const { params: e } = i;
3549
+ if (!e)
3550
+ return null;
3551
+ const { ranges: t } = e, { unitId: n, sheetId: r } = this._getCurrentSheetInfo();
3552
+ return {
3553
+ type: 5,
3554
+ ranges: t,
3555
+ unitId: n,
3556
+ sheetId: r
3557
+ };
3558
+ }
3559
+ _handleSetWorksheetName(i) {
3560
+ const { params: e } = i;
3561
+ if (!e)
3562
+ return null;
3563
+ const { workbookId: t, worksheetId: n, name: r } = e, { unitId: o, sheetId: s } = this._getCurrentSheetInfo();
3564
+ return {
3565
+ type: 9,
3566
+ unitId: t || o,
3567
+ sheetId: n || s,
3568
+ sheetName: r
3569
+ };
3570
+ }
3571
+ _getUpdateFormulaMutations(i, e) {
3572
+ const t = [], n = [], r = {
3573
+ get: this._injector.get.bind(this._injector)
3574
+ }, o = Object.keys(e);
3575
+ for (const s of o) {
3576
+ const a = e[s], c = Object.keys(a);
3577
+ for (const l of c) {
3578
+ const d = new D(i[s][l]), h = new D(a[l]), m = new D();
3579
+ h.forValue((u, _, g) => {
3580
+ var y, R;
3581
+ const C = (g == null ? void 0 : g.f) || "", b = ((R = (y = d.getRow(u)) == null ? void 0 : y.get(_)) == null ? void 0 : R.f) || "";
3582
+ _e(C) && (_e(b) && C !== b ? m.setValue(u, _, { f: C }) : m.setValue(u, _, { f: C, si: null }));
3583
+ });
3584
+ const f = m.getData();
3585
+ if (G.isEmptyObject(f))
3586
+ continue;
3587
+ const p = {
3588
+ worksheetId: l,
3589
+ workbookId: s,
3590
+ cellValue: f
3591
+ };
3592
+ t.push({
3593
+ id: re.id,
3594
+ params: p
3595
+ });
3596
+ const v = cn(r, p);
3597
+ n.push({
3598
+ id: re.id,
3599
+ params: v
3600
+ });
3601
+ }
3602
+ }
3603
+ return {
3604
+ redos: t,
3605
+ undos: n
3606
+ };
3607
+ }
3608
+ _getFormulaReferenceMoveInfo(i, e, t) {
3609
+ const n = Object.keys(i), r = {};
3610
+ for (const o of n) {
3611
+ const s = i[o], a = Object.keys(s);
3612
+ r[o] == null && (r[o] = {});
3613
+ for (const c of a) {
3614
+ const l = new D(s[c]), d = new D();
3615
+ l.forValue((h, m, f) => {
3616
+ var R;
3617
+ if (!f)
3618
+ return !0;
3619
+ const { f: p, x: v, y: u, si: _ } = f, g = this._lexerTreeBuilder.sequenceNodesBuilder(p);
3620
+ if (g == null)
3621
+ return !0;
3622
+ let C = !1;
3623
+ const b = [];
3624
+ for (let I = 0, N = g.length; I < N; I++) {
3625
+ const E = g[I];
3626
+ if (typeof E == "string" || E.nodeType !== K.REFERENCE)
3627
+ continue;
3628
+ const { token: M } = E, T = Se(M), { range: w, sheetName: W, unitId: j } = T, ae = j == null || j.length === 0 ? o : j, he = (R = e == null ? void 0 : e[ae]) == null ? void 0 : R[W], ce = {
3629
+ range: w,
3630
+ sheetId: he,
3631
+ unitId: j,
3632
+ sheetName: W,
3633
+ refOffsetX: v || 0,
3634
+ refOffsetY: u || 0
3635
+ };
3636
+ let Ee = null;
3637
+ if (t.type === 9) {
3638
+ const {
3639
+ unitId: ia,
3640
+ sheetId: Vn,
3641
+ sheetName: Lt
3642
+ } = t;
3643
+ if (Lt == null || he == null || he.length === 0 || Vn !== he)
3644
+ continue;
3645
+ Ee = Be({
3646
+ range: w,
3647
+ sheetName: Lt,
3648
+ unitId: j
3649
+ });
3650
+ } else
3651
+ Ee = this._getNewRangeByMoveParam(
3652
+ ce,
3653
+ t,
3654
+ o,
3655
+ c
3656
+ );
3657
+ Ee != null && (g[I] = {
3658
+ ...E,
3659
+ token: Ee
3660
+ }, C = !0, b.push(I));
3661
+ }
3662
+ if (!C)
3663
+ return !0;
3664
+ const y = this._updateRefOffset(g, b, v, u);
3665
+ d.setValue(h, m, {
3666
+ f: `=${on(y)}`,
3667
+ x: v,
3668
+ y: u,
3669
+ si: _
3670
+ });
3671
+ }), r[o][c] = d.getData();
3672
+ }
3673
+ }
3674
+ return r;
3675
+ }
3676
+ _getNewRangeByMoveParam(i, e, t, n) {
3677
+ const { type: r, unitId: o, sheetId: s, ranges: a, from: c, to: l } = e, {
3678
+ range: d,
3679
+ sheetId: h,
3680
+ unitId: m,
3681
+ sheetName: f,
3682
+ refOffsetX: p,
3683
+ refOffsetY: v
3684
+ } = i;
3685
+ if (!this._checkIsSameUnitAndSheet(
3686
+ o,
3687
+ s,
3688
+ t,
3689
+ n,
3690
+ m,
3691
+ h
3692
+ ))
3693
+ return;
3694
+ const u = je.moveOffset(d, p, v);
3695
+ let _ = null;
3696
+ if (r === 0) {
3697
+ if (c == null || l == null)
3698
+ return;
3699
+ const g = this._checkMoveEdge(u, c), C = je.getIntersects(u, c);
3700
+ if (C == null)
3701
+ return;
3702
+ const b = ur(
3703
+ { id: Q.MoveRangeCommandId, params: { toRange: l, fromRange: c } },
3704
+ C
3705
+ ), y = J(b, C);
3706
+ if (y == null)
3707
+ return;
3708
+ _ = this._getMoveNewRange(g, y, c, l, u, C);
3709
+ }
3710
+ if (a != null) {
3711
+ if (r === 1) {
3712
+ const g = mr(
3713
+ {
3714
+ id: Q.InsertRowCommandId,
3715
+ params: { range: a[0], workbookId: "", worksheetId: "", direction: L.DOWN }
3716
+ },
3717
+ u
3718
+ ), C = J(g, u);
3719
+ if (C == null)
3720
+ return;
3721
+ _ = {
3722
+ ...u,
3723
+ ...C
3724
+ };
3725
+ } else if (r === 2) {
3726
+ const g = dr(
3727
+ {
3728
+ id: Q.InsertColCommandId,
3729
+ params: { range: a[0], workbookId: "", worksheetId: "", direction: L.RIGHT }
3730
+ },
3731
+ u
3732
+ ), C = J(g, u);
3733
+ if (C == null)
3734
+ return;
3735
+ _ = {
3736
+ ...u,
3737
+ ...C
3738
+ };
3739
+ } else if (r === 3) {
3740
+ const g = hr(
3741
+ {
3742
+ id: Q.RemoveRowCommandId,
3743
+ params: { ranges: a }
3744
+ },
3745
+ u
3746
+ ), C = J(g, u);
3747
+ if (C == null)
3748
+ return;
3749
+ _ = {
3750
+ ...u,
3751
+ ...C
3752
+ };
3753
+ } else if (r === 4) {
3754
+ const g = fr(
3755
+ {
3756
+ id: Q.RemoveColCommandId,
3757
+ params: { ranges: a }
3758
+ },
3759
+ u
3760
+ ), C = J(g, u);
3761
+ if (C == null)
3762
+ return;
3763
+ _ = {
3764
+ ...u,
3765
+ ...C
3766
+ };
3767
+ } else if (r === 5) {
3768
+ const g = gr(
3769
+ {
3770
+ id: Q.DeleteRangeMoveLeftCommandId,
3771
+ params: { ranges: a }
3772
+ },
3773
+ u
3774
+ ), C = J(g, u);
3775
+ if (C == null)
3776
+ return;
3777
+ _ = {
3778
+ ...u,
3779
+ ...C
3780
+ };
3781
+ } else if (r === 6) {
3782
+ const g = pr(
3783
+ {
3784
+ id: Q.DeleteRangeMoveUpCommandId,
3785
+ params: { ranges: a }
3786
+ },
3787
+ u
3788
+ ), C = J(g, u);
3789
+ if (C == null)
3790
+ return;
3791
+ _ = {
3792
+ ...u,
3793
+ ...C
3794
+ };
3795
+ } else if (r === 7) {
3796
+ const g = _r(
3797
+ {
3798
+ id: Q.InsertRangeMoveDownCommandId,
3799
+ params: { ranges: a }
3800
+ },
3801
+ u
3802
+ ), C = J(g, u);
3803
+ if (C == null)
3804
+ return;
3805
+ _ = {
3806
+ ...u,
3807
+ ...C
3808
+ };
3809
+ } else if (r === 8) {
3810
+ const g = Sr(
3811
+ {
3812
+ id: Q.InsertRangeMoveRightCommandId,
3813
+ params: { ranges: a }
3814
+ },
3815
+ u
3816
+ ), C = J(g, u);
3817
+ if (C == null)
3818
+ return;
3819
+ _ = {
3820
+ ...u,
3821
+ ...C
3822
+ };
3823
+ }
3824
+ }
3825
+ if (_ != null)
3826
+ return Be({
3827
+ range: _,
3828
+ sheetName: f,
3829
+ unitId: m
3830
+ });
3831
+ }
3832
+ _checkIsSameUnitAndSheet(i, e, t, n, r, o) {
3833
+ if ((r == null || r.length === 0) && (o == null || o.length === 0)) {
3834
+ if (i === t && e === n)
3835
+ return !0;
3836
+ } else if ((i === r || r == null || r.length === 0) && e === o)
3837
+ return !0;
3838
+ return !1;
3839
+ }
3840
+ /**
3841
+ * Update all ref nodes to the latest offset state.
3842
+ */
3843
+ _updateRefOffset(i, e, t = 0, n = 0) {
3844
+ const r = [];
3845
+ for (let o = 0, s = i.length; o < s; o++) {
3846
+ const a = i[o];
3847
+ if (typeof a == "string" || a.nodeType !== K.REFERENCE || e.includes(o)) {
3848
+ r.push(a);
3849
+ continue;
3850
+ }
3851
+ const { token: c } = a, l = Se(c), { range: d, sheetName: h, unitId: m } = l, f = je.moveOffset(d, t, n);
3852
+ r.push({
3853
+ ...a,
3854
+ token: Be({
3855
+ range: f,
3856
+ unitId: m,
3857
+ sheetName: h
3858
+ })
3859
+ });
3860
+ }
3861
+ return r;
3862
+ }
3863
+ /**
3864
+ * Determine the range of the moving selection,
3865
+ * and check if it is at the edge of the reference range of the formula.
3866
+ * @param originRange
3867
+ * @param fromRange
3868
+ */
3869
+ _checkMoveEdge(i, e) {
3870
+ const { startRow: t, startColumn: n, endRow: r, endColumn: o } = i, {
3871
+ startRow: s,
3872
+ startColumn: a,
3873
+ endRow: c,
3874
+ endColumn: l
3875
+ } = e;
3876
+ if (t >= s && r <= c && n >= a && o <= l)
3877
+ return 4;
3878
+ if (n >= a && o <= l && t >= s && t <= c && r > c)
3879
+ return 0;
3880
+ if (n >= a && o <= l && r >= s && r <= c && t < s)
3881
+ return 1;
3882
+ if (t >= s && r <= c && n >= a && n <= l && o > l)
3883
+ return 2;
3884
+ if (t >= s && r <= c && o >= a && o <= l && n < a)
3885
+ return 3;
3886
+ }
3887
+ /**
3888
+ * Calculate the new ref information for the moving selection.
3889
+ * @param moveEdge the 'from' range lie on the edge of the original range, or does it completely cover the original range
3890
+ * @param result The original range is divided by 'from' and moved to a new position range.
3891
+ * @param from The initial range of the moving selection.
3892
+ * @param to The result range after moving the initial range.
3893
+ * @param origin The original target range.
3894
+ * @param remain "The range subtracted from the initial range by 'from'.
3895
+ * @returns
3896
+ */
3897
+ _getMoveNewRange(i, e, t, n, r, o) {
3898
+ const { startRow: s, endRow: a, startColumn: c, endColumn: l } = e, {
3899
+ startRow: d,
3900
+ startColumn: h,
3901
+ endRow: m,
3902
+ endColumn: f
3903
+ } = t, { startRow: p, startColumn: v, endRow: u, endColumn: _ } = n, {
3904
+ startRow: g,
3905
+ endRow: C,
3906
+ startColumn: b,
3907
+ endColumn: y
3908
+ } = o, {
3909
+ startRow: R,
3910
+ endRow: I,
3911
+ startColumn: N,
3912
+ endColumn: E
3913
+ } = r, M = { ...r };
3914
+ if (i === 0)
3915
+ if (c === N && l === E)
3916
+ if (s < R)
3917
+ M.startRow = s;
3918
+ else if (a < I)
3919
+ M.startRow = s;
3920
+ else if (a >= I && p <= I)
3921
+ M.startRow = m + 1, M.endRow = a;
3922
+ else
3923
+ return;
3924
+ else
3925
+ return;
3926
+ else if (i === 1)
3927
+ if (c === N && l === E)
3928
+ if (a > I)
3929
+ M.endRow = a;
3930
+ else if (s > R)
3931
+ M.endRow = a;
3932
+ else if (s <= R && u >= R)
3933
+ M.endRow = d + 1, M.startRow = s;
3934
+ else
3935
+ return;
3936
+ else
3937
+ return;
3938
+ else if (i === 2)
3939
+ if (s === R && a === I)
3940
+ if (c < N)
3941
+ M.startColumn = c;
3942
+ else if (l < E)
3943
+ M.startColumn = c;
3944
+ else if (l >= E && v <= E)
3945
+ M.startColumn = f + 1, M.endColumn = l;
3946
+ else
3947
+ return;
3948
+ else
3949
+ return;
3950
+ else if (i === 3)
3951
+ if (s === R && a === I)
3952
+ if (l > E)
3953
+ M.endColumn = l;
3954
+ else if (c > N)
3955
+ M.endColumn = l;
3956
+ else if (c <= N && _ >= N)
3957
+ M.endColumn = h + 1, M.startColumn = c;
3958
+ else
3959
+ return;
3960
+ else
3961
+ return;
3962
+ else
3963
+ (i === 4 || (v <= y + 1 && _ >= E || v <= N && _ >= b - 1) && p <= R && u >= I || (p <= C + 1 && u >= I || p <= R && u >= g - 1) && v <= N && _ >= E) && (M.startRow = s, M.startColumn = c, M.endRow = a, M.endColumn = l);
3964
+ return M;
3965
+ }
3966
+ _getInsertNewRange() {
3967
+ }
3968
+ _getCurrentSheetInfo() {
3969
+ const i = this._currentUniverService.getCurrentUniverSheetInstance(), e = i.getUnitId(), t = i.getActiveSheet().getSheetId();
3970
+ return {
3971
+ unitId: e,
3972
+ sheetId: t
3973
+ };
3974
+ }
3975
+ };
3976
+ Ze = ys([
3977
+ Y(X.Ready, Ze),
3978
+ ue(0, ve),
3979
+ ue(1, Z),
3980
+ ue(2, x(Re)),
3981
+ ue(3, x(tt)),
3982
+ ue(4, x(an)),
3983
+ ue(5, x(Mt)),
3984
+ ue(6, x(et))
3985
+ ], Ze);
3986
+ const Ms = {}, bs = {}, Fs = {}, Ns = {}, ws = {}, xs = {}, Ts = {}, Os = {}, Es = {}, Ls = {}, As = {
3987
+ SUM: {
3988
+ description: "You can add individual values, cell references or ranges or a mix of all three.",
3989
+ abstract: "Adds its arguments",
3990
+ functionParameter: {
3991
+ number1: {
3992
+ name: "number1",
3993
+ detail: "The first number you want to add. The number can be like 4, a cell reference like B6, or a cell range like B2:B8."
3994
+ },
3995
+ number2: {
3996
+ name: "number2",
3997
+ detail: "This is the second number you want to add. You can specify up to 255 numbers in this way."
3998
+ }
3999
+ }
4000
+ },
4001
+ SUMIF: {
4002
+ description: "Sum the values in a range that meet criteria that you specify.",
4003
+ abstract: "Adds the cells specified by a given criteria",
4004
+ functionParameter: {
4005
+ range: {
4006
+ name: "range",
4007
+ detail: "The range of cells that you want evaluated by criteria."
4008
+ },
4009
+ criteria: {
4010
+ name: "criteria",
4011
+ detail: "The criteria in the form of a number, expression, a cell reference, text, or a function that defines which cells will be added. Wildcard characters can be included - a question mark (?) to match any single character, an asterisk (*) to match any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) preceding the character."
4012
+ },
4013
+ sum_range: {
4014
+ name: "sum_range",
4015
+ detail: "The actual cells to add, if you want to add cells other than those specified in the range argument. If the sum_range argument is omitted, Excel adds the cells that are specified in the range argument (the same cells to which the criteria is applied)."
4016
+ }
4017
+ }
4018
+ }
4019
+ }, Ds = {
4020
+ AVERAGE: {
4021
+ description: "Returns the average (arithmetic mean) of the arguments.",
4022
+ abstract: "Returns the average of its arguments",
4023
+ functionParameter: {
4024
+ number1: {
4025
+ name: "number1",
4026
+ detail: "The first number, cell reference, or range for which you want the average."
4027
+ },
4028
+ number2: {
4029
+ name: "number2",
4030
+ detail: "Additional numbers, cell references or ranges for which you want the average, up to a maximum of 255."
4031
+ }
4032
+ }
4033
+ },
4034
+ COUNT: {
4035
+ description: "Counts the number of cells that contain numbers, and counts numbers within the list of arguments.",
4036
+ abstract: "Counts how many numbers are in the list of arguments",
4037
+ functionParameter: {
4038
+ value1: {
4039
+ name: "value1",
4040
+ detail: "The first item, cell reference, or range within which you want to count numbers."
4041
+ },
4042
+ value2: {
4043
+ name: "value2",
4044
+ detail: "Up to 255 additional items, cell references, or ranges within which you want to count numbers."
4045
+ }
4046
+ }
4047
+ },
4048
+ MAX: {
4049
+ description: "Returns the largest value in a set of values.",
4050
+ abstract: "Returns the maximum value in a list of arguments",
4051
+ functionParameter: {
4052
+ number1: {
4053
+ name: "number1",
4054
+ detail: "The first number, cell reference, or range to calculate the maximum value from."
4055
+ },
4056
+ number2: {
4057
+ name: "number2",
4058
+ detail: "Additional numbers, cell references or ranges to calculate the maximum value from, up to a maximum of 255."
4059
+ }
4060
+ }
4061
+ },
4062
+ MIN: {
4063
+ description: "Returns the smallest number in a set of values.",
4064
+ abstract: "Returns the minimum value in a list of arguments",
4065
+ functionParameter: {
4066
+ number1: {
4067
+ name: "number1",
4068
+ detail: "The first number, cell reference, or range to calculate the minimum value from."
4069
+ },
4070
+ number2: {
4071
+ name: "number2",
4072
+ detail: "Additional numbers, cell references or ranges to calculate the minimum value from, up to a maximum of 255."
4073
+ }
4074
+ }
4075
+ }
4076
+ }, Ps = {}, Us = {}, ks = {}, va = {
4077
+ formula: {
4078
+ insert: {
4079
+ tooltip: "Functions",
4080
+ sum: "SUM",
4081
+ average: "AVERAGE",
4082
+ count: "COUNT",
4083
+ max: "MAX",
4084
+ min: "MIN",
4085
+ more: "More Functions..."
4086
+ },
4087
+ functionList: {
4088
+ ...Ts,
4089
+ ...ws,
4090
+ ...As,
4091
+ ...Ds,
4092
+ ...Ls,
4093
+ ...Ns,
4094
+ ...Ps,
4095
+ ...Es,
4096
+ ...Os,
4097
+ ...xs,
4098
+ ...Fs,
4099
+ ...bs,
4100
+ ...ks,
4101
+ ...Ms,
4102
+ ...Us
4103
+ },
4104
+ prompt: {
4105
+ helpExample: "EXAMPLE",
4106
+ helpAbstract: "ABOUT",
4107
+ required: "Required.",
4108
+ optional: "Optional."
4109
+ },
4110
+ functionType: {
4111
+ financial: "Financial",
4112
+ date: "Date & Time",
4113
+ math: "Math & Trig",
4114
+ statistical: "Statistical",
4115
+ lookup: "Lookup & Reference",
4116
+ database: "Database",
4117
+ text: "Text",
4118
+ logical: "Logical",
4119
+ information: "Information",
4120
+ engineering: "Engineering",
4121
+ cube: "Cube",
4122
+ compatibility: "Compatibility",
4123
+ web: "Web",
4124
+ array: "Array",
4125
+ univer: "Univer"
4126
+ },
4127
+ moreFunctions: {
4128
+ confirm: "Confirm",
4129
+ prev: "Previous",
4130
+ next: "Next",
4131
+ searchFunctionPlaceholder: "Search function",
4132
+ allFunctions: "All Functions",
4133
+ syntax: "SYNTAX"
4134
+ },
4135
+ operation: {
4136
+ pasteFormula: "Paste Formula"
4137
+ }
4138
+ }
4139
+ }, $s = {}, js = {}, Bs = {}, qs = {}, Vs = {}, Ws = {}, Hs = {}, Ks = {}, Gs = {}, zs = {}, Ys = {
4140
+ SUM: {
4141
+ description: "将单个值、单元格引用或是区域相加,或者将三者的组合相加。",
4142
+ abstract: "求参数的和",
4143
+ functionParameter: {
4144
+ number1: {
4145
+ name: "数值1",
4146
+ detail: "要相加的第一个数字。 该数字可以是 4 之类的数字,B6 之类的单元格引用或 B2:B8 之类的单元格范围。"
4147
+ },
4148
+ number2: {
4149
+ name: "数值2",
4150
+ detail: "这是要相加的第二个数字。 可以按照这种方式最多指定 255 个数字。"
4151
+ }
4152
+ }
4153
+ },
4154
+ SUMIF: {
4155
+ description: "对范围中符合指定条件的值求和。",
4156
+ abstract: "按给定条件对指定单元格求和",
4157
+ functionParameter: {
4158
+ range: {
4159
+ name: "范围",
4160
+ detail: "要根据条件进行检测的范围。"
4161
+ },
4162
+ criteria: {
4163
+ name: "条件",
4164
+ detail: "以数字、表达式、单元格引用、文本或函数的形式来定义将添加哪些单元格。可包括的通配符字符 - 问号(?)以匹配任意单个字符,星号(*)以匹配任意字符序列。 如果要查找实际的问号或星号,请在该字符前键入波形符(~)。"
4165
+ },
4166
+ sum_range: {
4167
+ name: "求和范围",
4168
+ detail: "要添加的实际单元格,如果要添加在范围参数指定以外的其他单元格。 如果省略sum_range参数,Excel就会添加范围参数中指定的单元格(与应用标准的单元格相同)。"
4169
+ }
4170
+ }
4171
+ }
4172
+ }, Xs = {
4173
+ AVERAGE: {
4174
+ description: "返回参数的平均值(算术平均值)。",
4175
+ abstract: "返回参数平均值",
4176
+ functionParameter: {
4177
+ number1: {
4178
+ name: "数值1",
4179
+ detail: "要计算平均值的第一个数字、单元格引用或单元格区域。"
4180
+ },
4181
+ number2: {
4182
+ name: "数值2",
4183
+ detail: "要计算平均值的其他数字、单元格引用或单元格区域,最多可包含 255 个。"
4184
+ }
4185
+ }
4186
+ },
4187
+ COUNT: {
4188
+ description: "计算包含数字的单元格个数以及参数列表中数字的个数。",
4189
+ abstract: "计算参数列表中数字的个数",
4190
+ functionParameter: {
4191
+ value1: {
4192
+ name: "值1",
4193
+ detail: "要计算其中数字的个数的第一项、单元格引用或区域。"
4194
+ },
4195
+ value2: {
4196
+ name: "值2",
4197
+ detail: "要计算其中数字的个数的其他项、单元格引用或区域,最多可包含 255 个。"
4198
+ }
4199
+ }
4200
+ },
4201
+ MAX: {
4202
+ description: "返回一组值中的最大值。",
4203
+ abstract: "返回参数列表中的最大值",
4204
+ functionParameter: {
4205
+ number1: {
4206
+ name: "数值1",
4207
+ detail: "要计算最大值的第一个数字、单元格引用或单元格区域。"
4208
+ },
4209
+ number2: {
4210
+ name: "数值2",
4211
+ detail: "要计算最大值的其他数字、单元格引用或单元格区域,最多可包含 255 个。"
4212
+ }
4213
+ }
4214
+ },
4215
+ MIN: {
4216
+ description: "返回一组值中的最小值。",
4217
+ abstract: "返回参数列表中的最小值",
4218
+ functionParameter: {
4219
+ number1: {
4220
+ name: "数值1",
4221
+ detail: "要计算最小值的第一个数字、单元格引用或单元格区域。"
4222
+ },
4223
+ number2: {
4224
+ name: "数值2",
4225
+ detail: "要计算最小值的其他数字、单元格引用或单元格区域,最多可包含 255 个。"
4226
+ }
4227
+ }
4228
+ }
4229
+ }, Zs = {}, Qs = {}, Js = {}, ea = {
4230
+ formula: {
4231
+ insert: {
4232
+ tooltip: "函数",
4233
+ sum: "求和",
4234
+ average: "平均值",
4235
+ count: "计数",
4236
+ max: "最大值",
4237
+ min: "最小值",
4238
+ more: "更多函数..."
4239
+ },
4240
+ functionList: {
4241
+ ...Hs,
4242
+ ...Vs,
4243
+ ...Ys,
4244
+ ...Xs,
4245
+ ...zs,
4246
+ ...qs,
4247
+ ...Zs,
4248
+ ...Gs,
4249
+ ...Ks,
4250
+ ...Ws,
4251
+ ...Bs,
4252
+ ...js,
4253
+ ...Js,
4254
+ ...$s,
4255
+ ...Qs
4256
+ },
4257
+ prompt: {
4258
+ helpExample: "示例",
4259
+ helpAbstract: "简介",
4260
+ required: "必需。",
4261
+ optional: "可选。"
4262
+ },
4263
+ functionType: {
4264
+ financial: "财务",
4265
+ date: "日期与时间",
4266
+ math: "数学与三角函数",
4267
+ statistical: "统计",
4268
+ lookup: "查找与引用",
4269
+ database: "数据库",
4270
+ text: "文本",
4271
+ logical: "逻辑",
4272
+ information: "信息",
4273
+ engineering: "工程",
4274
+ cube: "多维数据集",
4275
+ compatibility: "兼容性",
4276
+ web: "Web",
4277
+ array: "数组",
4278
+ univer: "Univer"
4279
+ },
4280
+ moreFunctions: {
4281
+ confirm: "应用",
4282
+ prev: "上一步",
4283
+ next: "下一步",
4284
+ searchFunctionPlaceholder: "搜索函数",
4285
+ allFunctions: "全部函数",
4286
+ syntax: "语法"
4287
+ },
4288
+ operation: {
4289
+ pasteFormula: "仅粘贴公式"
4290
+ }
4291
+ }
4292
+ };
4293
+ var ta = Object.defineProperty, na = Object.getOwnPropertyDescriptor, ra = (i, e, t, n) => {
4294
+ for (var r = n > 1 ? void 0 : n ? na(e, t) : e, o = i.length - 1, s; o >= 0; o--)
4295
+ (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
4296
+ return n && r && ta(e, t, r), r;
4297
+ }, ht = (i, e) => (t, n) => e(t, n, i), ft;
4298
+ let tn = (ft = class extends Yn {
4299
+ constructor(i, e, t, n) {
4300
+ super(Nn), this._config = i, this._injector = e, this._localeService = t, this._currentUniverService = n;
4301
+ }
4302
+ initialize() {
4303
+ this._localeService.load({
4304
+ zhCN: ea
4305
+ }), [
4306
+ // services
4307
+ [de, { useClass: hi }],
4308
+ [Te, { useClass: li }],
4309
+ [
4310
+ Et,
4311
+ {
4312
+ useFactory: () => {
4313
+ var e;
4314
+ return this._injector.createInstance(It, ((e = this._config) == null ? void 0 : e.description) || []);
4315
+ }
4316
+ // TODO@Dusuhir: initialize config with asynchronous method?
4317
+ }
4318
+ ],
4319
+ [xt, { useClass: Wr }],
4320
+ // controllers
4321
+ [ze],
4322
+ [Ye],
4323
+ [Ge],
4324
+ [We],
4325
+ [He],
4326
+ [Ve],
4327
+ [Xe],
4328
+ [Ze],
4329
+ [Ke],
4330
+ [qe]
4331
+ ].forEach((e) => this._injector.add(e));
4332
+ }
4333
+ onReady() {
4334
+ this.initialize();
4335
+ }
4336
+ }, F(ft, "type", Xn.Sheet), ft);
4337
+ tn = ra([
4338
+ ht(1, x(et)),
4339
+ ht(2, x(Ce)),
4340
+ ht(3, ve)
4341
+ ], tn);
4342
+ export {
4343
+ tn as UniverSheetsFormulaPlugin,
4344
+ va as enUS,
4345
+ ea as zhCN
4346
+ };