@univerjs/sheets-formula-ui 0.6.7 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js ADDED
@@ -0,0 +1,3716 @@
1
+ var Zo = Object.defineProperty;
2
+ var Xo = (t, e, n) => e in t ? Zo(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var B = (t, e, n) => Xo(t, typeof e != "symbol" ? e + "" : e, n);
4
+ import { CommandType as Ie, ICommandService as ae, createIdentifier as Qo, IContextService as on, IUniverInstanceService as oe, Rectangle as Gn, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as rn, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as Zn, DEFAULT_EMPTY_DOCUMENT_VALUE as Xn, isRealNum as Jo, CellValueType as En, getCellValueType as er, LocaleService as je, Tools as ft, Inject as K, Injector as mt, ThemeService as gt, toDisposable as Qn, DisposableCollection as Ve, RANGE_TYPE as ge, UniverInstanceType as ue, ColorKit as sn, getBodySlice as bn, Direction as ne, EDITOR_ACTIVATED as bt, createInternalEditorID as tr, generateRandomId as nr, BuildTextUtils as or, RichTextBuilder as rr, isFormulaString as Re, isFormulaId as Be, FOCUSING_DOC as sr, FOCUSING_UNIVER_EDITOR as ir, Disposable as pt, isICellData as cr, ObjectMatrix as tt, ILogService as lr, RxDisposable as ar, InterceptorEffectEnum as ur, DependentOn as fr, IConfigService as hr, Plugin as dr, merge as mr, registerDependencies as gr, touchDependencies as pr } from "@univerjs/core";
5
+ import { SheetPasteCommand as Sr, PREDEFINED_HOOK_NAME as Je, IEditorBridgeService as Jn, SetCellEditVisibleOperation as eo, SheetSkeletonManagerService as Lt, BaseSelectionRenderService as Cr, getCoordByOffset as yn, checkInHeaderRanges as Nn, getAllSelection as vr, genNormalSelectionStyle as to, getSheetObject as _r, attachSelectionWithCoord as Xt, SelectionControl as no, MoveSelectionCommand as Tn, JumpOver as Fn, ExpandSelectionCommand as On, EMBEDDING_FORMULA_EDITOR as Rr, IMarkSelectionService as Ir, HoverManagerService as Er, CellAlertManagerService as br, CellAlertType as yr, IAutoFillService as Nr, APPLY_TYPE as Tr, DATA_TYPE as Mn, ISheetClipboardService as Fr, COPY_TYPE as oo, SELECTION_SHAPE_DEPTH as Or, useActiveWorkbook as Mr, getCurrentRangeDisable$ as ro, PASTE_SPECIAL_MENU_ID as Ar, whenFormulaEditorActivated as St, SheetsUIPart as Pr, RANGE_SELECTOR_COMPONENT_KEY as xr, EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY as wr } from "@univerjs/sheets-ui";
6
+ import { sequenceNodeType as z, serializeRange as pe, LexerTreeBuilder as Ee, deserializeRangeWithSheetWithCache as Dr, matchRefDrawToken as Lr, isFormulaLexerToken as $r, matchToken as nt, deserializeRangeWithSheet as ot, serializeRangeWithSheet as ht, generateStringWithSequence as kr, operatorToken as so, ERROR_TYPE_SET as Hr, ErrorType as se, FormulaDataModel as $t, SetFormulaCalculationResultMutation as Wr, SetArrayFormulaDataMutation as Ur, SetFormulaCalculationStopMutation as Vr, FunctionType as Br, UniverFormulaEnginePlugin as qr } from "@univerjs/engine-formula";
7
+ import { Subject as st, BehaviorSubject as io, throttleTime as co, debounceTime as cn, filter as Qt, map as lo, distinctUntilChanged as jr, merge as Kr, combineLatestWith as Yr, switchMap as zr, of as An, Observable as Gr } from "rxjs";
8
+ import { IEditorService as be, DocSelectionRenderService as ao, ReplaceTextRunsCommand as Pn, MoveSelectionOperation as Zr, MoveCursorOperation as Xr, useKeyboardEvent as Qr, useResize as Jr, DocBackScrollRenderController as es, RichTextEditor as ts } from "@univerjs/docs-ui";
9
+ import { DeviceInputEventType as ye, ScrollTimerType as jt, SHEET_VIEWPORT_KEY as xn, Vector2 as wn, IRenderManagerService as Ne } from "@univerjs/engine-render";
10
+ import { SheetsSelectionsService as ln, getSheetCommandTarget as uo, getCellAtRowCol as ns, SetSelectionsOperation as an, IRefSelectionsService as kt, SelectionMoveType as Kt, convertSelectionDataToRange as os, setEndForRange as rs, REF_SELECTIONS_ENABLED as Dn, SetWorksheetActiveOperation as Ln, SetRangeValuesMutation as $n, SetRangeValuesUndoMutationFactory as ss, SheetInterceptorService as fo, BEFORE_CELL_EDIT as is, SetWorksheetRowAutoHeightMutation as cs, INTERCEPTOR_POINT as ls, WorksheetSetCellValuePermission as ho, WorksheetEditPermission as mo, RangeProtectionPermissionEditPoint as go, WorkbookEditablePermission as po } from "@univerjs/sheets";
11
+ import { InsertFunctionCommand as as, IDescriptionService as Ht, TriggerCalculationController as us, UniverSheetsFormulaPlugin as fs } from "@univerjs/sheets-formula";
12
+ import { ISidebarService as Wt, useDependency as O, useEvent as ee, RectPopup as So, IShortcutService as Ut, KeyCode as D, MetaKeys as U, IContextMenuService as hs, useObservable as qe, useUpdateEffect as ds, IZenZoneService as ms, ProgressBar as gs, useInjector as ps, ILayoutService as Ss, MenuItemType as un, getMenuHiddenObservable as Cs, IClipboardInterfaceService as kn, RibbonStartGroup as vs, IMenuManagerService as _s, IUIPartsService as Co, ComponentManager as vo, BuiltInUIPart as _o, connectInjector as Jt } from "@univerjs/ui";
13
+ import { jsx as b, jsxs as k, Fragment as ut } from "react/jsx-runtime";
14
+ import { clsx as Hn, Tooltip as Rs, Dialog as Is, Input as Ro, Button as et, Popup as Io, Select as Es } from "@univerjs/design";
15
+ import { forwardRef as Te, useRef as j, createElement as Le, useEffect as L, useMemo as le, useState as $, useCallback as Ft, useLayoutEffect as Ot } from "react";
16
+ import { DocSelectionManagerService as Eo } from "@univerjs/docs";
17
+ import { debounceTime as bs } from "rxjs/operators";
18
+ const fn = {
19
+ id: "sheet.command.paste-formula",
20
+ type: Ie.COMMAND,
21
+ handler: async (t) => t.get(ae).executeCommand(Sr.id, {
22
+ value: Je.SPECIAL_PASTE_FORMULA
23
+ })
24
+ }, rt = {
25
+ id: "formula-ui.operation.select-editor-formula",
26
+ type: Ie.OPERATION,
27
+ handler: (t, e) => !0
28
+ };
29
+ var ys = Object.getOwnPropertyDescriptor, Ns = (t, e, n, o) => {
30
+ for (var r = o > 1 ? void 0 : o ? ys(e, n) : e, s = t.length - 1, i; s >= 0; s--)
31
+ (i = t[s]) && (r = i(r) || r);
32
+ return r;
33
+ }, Ts = (t, e) => (n, o) => e(n, o, t);
34
+ const Fs = "FORMULA_PROMPT_ACTIVATED", Ct = Qo("formula-ui.prompt-service");
35
+ let en = class {
36
+ constructor(t) {
37
+ B(this, "_search$", new st());
38
+ B(this, "_help$", new st());
39
+ B(this, "_navigate$", new st());
40
+ B(this, "_accept$", new st());
41
+ B(this, "_acceptFormulaName$", new st());
42
+ B(this, "search$", this._search$.asObservable());
43
+ B(this, "help$", this._help$.asObservable());
44
+ B(this, "navigate$", this._navigate$.asObservable());
45
+ B(this, "accept$", this._accept$.asObservable());
46
+ B(this, "acceptFormulaName$", this._acceptFormulaName$.asObservable());
47
+ B(this, "_searching", !1);
48
+ B(this, "_helping", !1);
49
+ B(this, "_sequenceNodes", []);
50
+ B(this, "_isLockedOnSelectionChangeRefString", !1);
51
+ B(this, "_isLockedOnSelectionInsertRefString", !1);
52
+ this._contextService = t;
53
+ }
54
+ dispose() {
55
+ this._search$.complete(), this._help$.complete(), this._navigate$.complete(), this._accept$.complete(), this._acceptFormulaName$.complete(), this._sequenceNodes = [];
56
+ }
57
+ search(t) {
58
+ this._contextService.setContextValue(Fs, t.visible), this._searching = t.visible, this._search$.next(t);
59
+ }
60
+ isSearching() {
61
+ return this._searching;
62
+ }
63
+ help(t) {
64
+ this._helping = t.visible, this._help$.next(t);
65
+ }
66
+ isHelping() {
67
+ return this._helping;
68
+ }
69
+ navigate(t) {
70
+ this._navigate$.next(t);
71
+ }
72
+ accept(t) {
73
+ this._accept$.next(t);
74
+ }
75
+ acceptFormulaName(t) {
76
+ this._acceptFormulaName$.next(t);
77
+ }
78
+ getSequenceNodes() {
79
+ return [...this._sequenceNodes];
80
+ }
81
+ setSequenceNodes(t) {
82
+ this._sequenceNodes = t;
83
+ }
84
+ clearSequenceNodes() {
85
+ this._sequenceNodes = [];
86
+ }
87
+ getCurrentSequenceNode(t) {
88
+ return this._sequenceNodes[this.getCurrentSequenceNodeIndex(t)];
89
+ }
90
+ getCurrentSequenceNodeByIndex(t) {
91
+ return this._sequenceNodes[t];
92
+ }
93
+ /**
94
+ * Query the text coordinates in the sequenceNodes and determine the actual insertion index.
95
+ * @param strIndex
96
+ */
97
+ getCurrentSequenceNodeIndex(t) {
98
+ let e = 0;
99
+ const n = this._sequenceNodes[0];
100
+ for (let o = 0, r = this._sequenceNodes.length; o < r; o++) {
101
+ const s = this._sequenceNodes[o];
102
+ if (typeof s == "string")
103
+ e++;
104
+ else {
105
+ const { endIndex: i } = s;
106
+ e = i;
107
+ }
108
+ if (t <= e)
109
+ return typeof n == "string" && t !== 0 ? o + 1 : o;
110
+ }
111
+ return this._sequenceNodes.length;
112
+ }
113
+ /**
114
+ * Synchronize the reference text based on the changes of the selection.
115
+ * @param nodeIndex
116
+ * @param refString
117
+ */
118
+ updateSequenceRef(t, e) {
119
+ const n = this._sequenceNodes[t];
120
+ if (typeof n == "string" || n.nodeType !== z.REFERENCE)
121
+ return;
122
+ const o = e.length - n.token.length, r = { ...n };
123
+ r.token = e, r.endIndex += o, this._sequenceNodes[t] = r;
124
+ for (let s = t + 1, i = this._sequenceNodes.length; s < i; s++) {
125
+ const c = this._sequenceNodes[s];
126
+ if (typeof c == "string")
127
+ continue;
128
+ const l = { ...c };
129
+ l.startIndex += o, l.endIndex += o, this._sequenceNodes[s] = l;
130
+ }
131
+ }
132
+ /**
133
+ * When the cursor is on the right side of a formula token,
134
+ * you can add reference text to the formula by drawing a selection.
135
+ * @param index
136
+ * @param refString
137
+ */
138
+ insertSequenceRef(t, e) {
139
+ const n = e.length, o = this.getCurrentSequenceNodeIndex(t);
140
+ this._sequenceNodes.splice(o, 0, {
141
+ token: e,
142
+ startIndex: t,
143
+ endIndex: t + n - 1,
144
+ nodeType: z.REFERENCE
145
+ });
146
+ for (let r = o + 1, s = this._sequenceNodes.length; r < s; r++) {
147
+ const i = this._sequenceNodes[r];
148
+ if (typeof i == "string")
149
+ continue;
150
+ const c = { ...i };
151
+ c.startIndex += n, c.endIndex += n, this._sequenceNodes[r] = c;
152
+ }
153
+ }
154
+ /**
155
+ * Insert a string at the cursor position in the text corresponding to the sequenceNodes.
156
+ * @param index
157
+ * @param content
158
+ */
159
+ insertSequenceString(t, e) {
160
+ const n = this.getCurrentSequenceNodeIndex(t), o = e.split("");
161
+ this._sequenceNodes.splice(n, 0, ...o);
162
+ const r = o.length;
163
+ for (let s = n + r, i = this._sequenceNodes.length; s < i; s++) {
164
+ const c = this._sequenceNodes[s];
165
+ if (typeof c == "string")
166
+ continue;
167
+ const l = { ...c };
168
+ l.startIndex += r, l.endIndex += r, this._sequenceNodes[s] = l;
169
+ }
170
+ }
171
+ enableLockedSelectionChange() {
172
+ this._isLockedOnSelectionChangeRefString = !0;
173
+ }
174
+ disableLockedSelectionChange() {
175
+ this._isLockedOnSelectionChangeRefString = !1;
176
+ }
177
+ isLockedSelectionChange() {
178
+ return this._isLockedOnSelectionChangeRefString;
179
+ }
180
+ enableLockedSelectionInsert() {
181
+ this._isLockedOnSelectionInsertRefString = !0;
182
+ }
183
+ disableLockedSelectionInsert() {
184
+ this._isLockedOnSelectionInsertRefString = !1;
185
+ }
186
+ isLockedSelectionInsert() {
187
+ return this._isLockedOnSelectionInsertRefString;
188
+ }
189
+ };
190
+ en = Ns([
191
+ Ts(0, on)
192
+ ], en);
193
+ const Os = {
194
+ id: "formula-ui.operation.help-function",
195
+ type: Ie.OPERATION,
196
+ handler: async (t, e) => (t.get(Ct).help(e), !0)
197
+ }, hn = {
198
+ id: "formula-ui.operation.insert-function",
199
+ type: Ie.OPERATION,
200
+ // eslint-disable-next-line
201
+ handler: async (t, e) => {
202
+ var C, S;
203
+ const n = t.get(ln), o = t.get(be), r = n.getCurrentSelections();
204
+ if (!r || !r.length)
205
+ return !1;
206
+ const s = uo(t.get(oe));
207
+ if (!s) return !1;
208
+ const { worksheet: i, unitId: c, subUnitId: l } = s, h = i.getCellMatrix(), { value: f } = e, m = t.get(ae);
209
+ t.get(Jn);
210
+ const u = [], d = [];
211
+ let a = null, I = 0, g = 0, p = "";
212
+ if (r.length === 1 && (Ps(r[0].range) || xs(r[0].range) && Un(h, r[0].range))) {
213
+ const { range: v, primary: _ } = r[0], T = (C = _ == null ? void 0 : _.actualRow) != null ? C : v.startRow, w = (S = _ == null ? void 0 : _.actualColumn) != null ? S : v.startColumn;
214
+ a = v, I = T, g = w;
215
+ const A = Wn(h, T, w);
216
+ A && (p = pe(A));
217
+ } else
218
+ r.some((v) => {
219
+ var w, A;
220
+ const { range: _, primary: T } = v;
221
+ if (Un(h, _)) {
222
+ const M = (w = T == null ? void 0 : T.actualRow) != null ? w : _.startRow, R = (A = T == null ? void 0 : T.actualColumn) != null ? A : _.startColumn, y = Wn(h, M, R);
223
+ if (!y)
224
+ return a = _, I = M, g = R, !0;
225
+ const P = pe(y), N = `=${f}(${P})`;
226
+ u.push({
227
+ range: _,
228
+ primary: {
229
+ row: M,
230
+ column: R
231
+ },
232
+ formula: N
233
+ });
234
+ } else {
235
+ const { startRow: M, startColumn: R, endRow: y, endColumn: P } = _;
236
+ if (M === y) {
237
+ const N = ws(h, M, P, i.getColumnCount() - 1), E = N === P ? P - 1 : P, F = pe({
238
+ startRow: M,
239
+ endRow: y,
240
+ startColumn: R,
241
+ endColumn: E
242
+ }), x = `=${f}(${F})`;
243
+ d.push({
244
+ range: _,
245
+ primary: {
246
+ row: M,
247
+ column: N
248
+ },
249
+ formula: x
250
+ });
251
+ } else {
252
+ let N = -1;
253
+ for (let F = R; F <= P; F++) {
254
+ const x = Ds(h, F, y, i.getRowCount() - 1);
255
+ N = Math.max(N, x);
256
+ }
257
+ const E = N === y ? y - 1 : y;
258
+ for (let F = R; F <= P; F++) {
259
+ const x = pe({
260
+ startRow: M,
261
+ endRow: E,
262
+ startColumn: F,
263
+ endColumn: F
264
+ }), H = `=${f}(${x})`;
265
+ d.push({
266
+ range: _,
267
+ primary: {
268
+ row: N,
269
+ column: F
270
+ },
271
+ formula: H
272
+ });
273
+ }
274
+ }
275
+ }
276
+ return !1;
277
+ });
278
+ if (a) {
279
+ const v = ns(I, g, i), _ = {
280
+ range: Gn.clone(a),
281
+ primary: {
282
+ startRow: v.startRow,
283
+ startColumn: v.startColumn,
284
+ endRow: v.endRow,
285
+ endColumn: v.endColumn,
286
+ actualRow: I,
287
+ actualColumn: g,
288
+ isMerged: v.isMerged,
289
+ isMergedMainCell: v.startRow === I && v.startColumn === g
290
+ }
291
+ }, T = {
292
+ unitId: c,
293
+ subUnitId: l,
294
+ selections: [_]
295
+ };
296
+ await m.executeCommand(an.id, T);
297
+ const w = o.getEditor(rn), A = o.getEditor(Zn);
298
+ m.syncExecuteCommand(eo.id, {
299
+ visible: !0,
300
+ unitId: c,
301
+ eventType: ye.Dblclick
302
+ });
303
+ const M = `=${f}(${p}`;
304
+ w == null || w.replaceText(M), A == null || A.replaceText(M, !1);
305
+ }
306
+ return u.length === 0 && d.length === 0 ? !1 : m.executeCommand(as.id, {
307
+ list: u,
308
+ listOfRangeHasNumber: d
309
+ });
310
+ }
311
+ };
312
+ function Wn(t, e, n) {
313
+ const o = Ms(t, e, n);
314
+ if (o !== e)
315
+ return {
316
+ startRow: o,
317
+ endRow: e - 1,
318
+ startColumn: n,
319
+ endColumn: n
320
+ };
321
+ const r = As(t, e, n);
322
+ return r !== n ? {
323
+ startRow: e,
324
+ endRow: e,
325
+ startColumn: r,
326
+ endColumn: n - 1
327
+ } : null;
328
+ }
329
+ function Ms(t, e, n) {
330
+ let o = !1;
331
+ if (e === 0) return e;
332
+ for (let r = e - 1; r >= 0; r--) {
333
+ const s = t.getValue(r, n);
334
+ if (dt(s) && !o) {
335
+ if (r === 0) return 0;
336
+ o = !0;
337
+ } else {
338
+ if (o && !dt(s))
339
+ return r + 1;
340
+ if (o && r === 0)
341
+ return 0;
342
+ }
343
+ }
344
+ return e;
345
+ }
346
+ function As(t, e, n) {
347
+ let o = !1;
348
+ if (n === 0) return n;
349
+ for (let r = n - 1; r >= 0; r--) {
350
+ const s = t.getValue(e, r);
351
+ if (dt(s) && !o) {
352
+ if (r === 0) return 0;
353
+ o = !0;
354
+ } else {
355
+ if (o && !dt(s))
356
+ return r + 1;
357
+ if (o && r === 0)
358
+ return 0;
359
+ }
360
+ }
361
+ return n;
362
+ }
363
+ function dt(t) {
364
+ if (t != null && t.p) {
365
+ const e = t == null ? void 0 : t.p.body;
366
+ if (e == null)
367
+ return !1;
368
+ const n = e.dataStream, r = n.substring(n.length - 2, n.length) === Xn ? n.substring(0, n.length - 2) : n;
369
+ return Jo(r);
370
+ }
371
+ return t && (t.t === En.NUMBER || er(t) === En.NUMBER);
372
+ }
373
+ function Ps(t) {
374
+ return t.startRow === t.endRow && t.startColumn === t.endColumn;
375
+ }
376
+ function xs(t) {
377
+ return t.startRow !== t.endRow && t.startColumn !== t.endColumn;
378
+ }
379
+ function Un(t, e) {
380
+ for (let n = e.startRow; n <= e.endRow; n++)
381
+ for (let o = e.startColumn; o <= e.endColumn; o++)
382
+ if (dt(t.getValue(n, o)))
383
+ return !1;
384
+ return !0;
385
+ }
386
+ function ws(t, e, n, o) {
387
+ for (let r = n; r <= o; r++)
388
+ if (!t.getValue(e, r))
389
+ return r;
390
+ return o;
391
+ }
392
+ function Ds(t, e, n, o) {
393
+ for (let r = n; r <= o; r++)
394
+ if (!t.getValue(r, e))
395
+ return r;
396
+ return o;
397
+ }
398
+ const bo = "SHEET_FORMULA_UI_PLUGIN", yo = `${bo}_MORE_FUNCTIONS_COMPONENT`, dn = {
399
+ id: "formula-ui.operation.more-functions",
400
+ type: Ie.OPERATION,
401
+ handler: async (t) => (t.get(Wt).open({
402
+ header: { title: "formula.insert.tooltip" },
403
+ children: { label: yo }
404
+ }), !0)
405
+ }, No = {
406
+ id: "formula-ui.operation.change-ref-to-absolute",
407
+ type: Ie.OPERATION,
408
+ handler: async (t) => !0
409
+ }, Ls = {
410
+ id: "formula-ui.operation.search-function",
411
+ type: Ie.OPERATION,
412
+ handler: async (t, e) => (t.get(Ct).search(e), !0)
413
+ }, mn = (t, e, n = !0) => {
414
+ let o = -1;
415
+ return t.reduce((r, s, i) => {
416
+ if (r.isFinish)
417
+ return r;
418
+ const c = r.currentIndex;
419
+ if (typeof s != "string")
420
+ r.currentIndex += s.token.length;
421
+ else {
422
+ const l = s.length;
423
+ r.currentIndex += l;
424
+ }
425
+ return (n ? r.currentIndex === e : e > c && e <= r.currentIndex) && (o = i, r.isFinish = !0), r;
426
+ }, { currentIndex: 0, isFinish: !1 }), o;
427
+ }, To = (t, e) => {
428
+ const n = t[e];
429
+ let o = -1;
430
+ if (!n || typeof n == "string" || n.nodeType !== z.REFERENCE) return -1;
431
+ for (let r = 0; r <= e; r++) {
432
+ const s = t[r];
433
+ typeof s != "string" && s.nodeType === z.REFERENCE && o++;
434
+ }
435
+ return o;
436
+ };
437
+ var ce = function() {
438
+ return ce = Object.assign || function(t) {
439
+ for (var e, n = 1, o = arguments.length; n < o; n++) {
440
+ e = arguments[n];
441
+ for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
442
+ }
443
+ return t;
444
+ }, ce.apply(this, arguments);
445
+ }, $s = function(t, e) {
446
+ var n = {};
447
+ for (var o in t) Object.prototype.hasOwnProperty.call(t, o) && e.indexOf(o) < 0 && (n[o] = t[o]);
448
+ if (t != null && typeof Object.getOwnPropertySymbols == "function")
449
+ for (var r = 0, o = Object.getOwnPropertySymbols(t); r < o.length; r++)
450
+ e.indexOf(o[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, o[r]) && (n[o[r]] = t[o[r]]);
451
+ return n;
452
+ }, $e = Te(function(t, e) {
453
+ var n = t.icon, o = t.id, r = t.className, s = t.extend, i = $s(t, ["icon", "id", "className", "extend"]), c = "univerjs-icon univerjs-icon-".concat(o, " ").concat(r || "").trim(), l = j("_".concat(Ws()));
454
+ return Fo(n, "".concat(o), { defIds: n.defIds, idSuffix: l.current }, ce({ ref: e, className: c }, i), s);
455
+ });
456
+ function Fo(t, e, n, o, r) {
457
+ return Le(t.tag, ce(ce({ key: e }, ks(t, n, r)), o), (Hs(t, n).children || []).map(function(s, i) {
458
+ return Fo(s, "".concat(e, "-").concat(t.tag, "-").concat(i), n, void 0, r);
459
+ }));
460
+ }
461
+ function ks(t, e, n) {
462
+ var o = ce({}, t.attrs);
463
+ n != null && n.colorChannel1 && o.fill === "colorChannel1" && (o.fill = n.colorChannel1), t.tag === "mask" && o.id && (o.id = o.id + e.idSuffix), Object.entries(o).forEach(function(s) {
464
+ var i = s[0], c = s[1];
465
+ i === "mask" && typeof c == "string" && (o[i] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
466
+ });
467
+ var r = e.defIds;
468
+ return !r || r.length === 0 || (t.tag === "use" && o["xlink:href"] && (o["xlink:href"] = o["xlink:href"] + e.idSuffix), Object.entries(o).forEach(function(s) {
469
+ var i = s[0], c = s[1];
470
+ typeof c == "string" && (o[i] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
471
+ })), o;
472
+ }
473
+ function Hs(t, e) {
474
+ var n, o = e.defIds;
475
+ return !o || o.length === 0 ? t : t.tag === "defs" && (!((n = t.children) === null || n === void 0) && n.length) ? ce(ce({}, t), { children: t.children.map(function(r) {
476
+ return typeof r.attrs.id == "string" && o && o.indexOf(r.attrs.id) > -1 ? ce(ce({}, r), { attrs: ce(ce({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
477
+ }) }) : t;
478
+ }
479
+ function Ws() {
480
+ return Math.random().toString(36).substring(2, 8);
481
+ }
482
+ $e.displayName = "UniverIcon";
483
+ var Us = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Oo = Te(function(t, e) {
484
+ return Le($e, Object.assign({}, t, {
485
+ id: "check-mark-single",
486
+ ref: e,
487
+ icon: Us
488
+ }));
489
+ });
490
+ Oo.displayName = "CheckMarkSingle";
491
+ var Vs = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z" } }] }, Vt = Te(function(t, e) {
492
+ return Le($e, Object.assign({}, t, {
493
+ id: "close-single",
494
+ ref: e,
495
+ icon: Vs
496
+ }));
497
+ });
498
+ Vt.displayName = "CloseSingle";
499
+ var Bs = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.3313 1.4667C5.3313 1.13533 5.59993.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Mo = Te(function(t, e) {
500
+ return Le($e, Object.assign({}, t, {
501
+ id: "delete-single",
502
+ ref: e,
503
+ icon: Bs
504
+ }));
505
+ });
506
+ Mo.displayName = "DeleteSingle";
507
+ var qs = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M8.75 5.32495C8.75 5.73916 8.41421 6.07495 8 6.07495 7.58579 6.07495 7.25 5.73916 7.25 5.32495 7.25 4.91074 7.58579 4.57495 8 4.57495 8.41421 4.57495 8.75 4.91074 8.75 5.32495zM8.5999 7.52505C8.5999 7.19368 8.33127 6.92505 7.9999 6.92505 7.66853 6.92505 7.3999 7.19368 7.3999 7.52505V11.425C7.3999 11.7564 7.66853 12.025 7.9999 12.025 8.33127 12.025 8.5999 11.7564 8.5999 11.425V7.52505z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M0.899902 8.00002C0.899902 4.0788 4.07868 0.900024 7.9999 0.900024C11.9211 0.900024 15.0999 4.0788 15.0999 8.00002C15.0999 11.9212 11.9211 15.1 7.9999 15.1C4.07868 15.1 0.899902 11.9212 0.899902 8.00002ZM7.9999 2.10002C4.74142 2.10002 2.0999 4.74154 2.0999 8.00002C2.0999 11.2585 4.74142 13.9 7.9999 13.9C11.2584 13.9 13.8999 11.2585 13.8999 8.00002C13.8999 4.74154 11.2584 2.10002 7.9999 2.10002Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Ao = Te(function(t, e) {
508
+ return Le($e, Object.assign({}, t, {
509
+ id: "details-single",
510
+ ref: e,
511
+ icon: qs
512
+ }));
513
+ });
514
+ Ao.displayName = "DetailsSingle";
515
+ var js = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z" } }] }, Po = Te(function(t, e) {
516
+ return Le($e, Object.assign({}, t, {
517
+ id: "increase-single",
518
+ ref: e,
519
+ icon: js
520
+ }));
521
+ });
522
+ Po.displayName = "IncreaseSingle";
523
+ var Ks = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, gn = Te(function(t, e) {
524
+ return Le($e, Object.assign({}, t, {
525
+ id: "more-single",
526
+ ref: e,
527
+ icon: Ks
528
+ }));
529
+ });
530
+ gn.displayName = "MoreSingle";
531
+ var Ys = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M12.6185 12.4423C12.5907 12.2749 12.7773 12.15 12.9343 12.2308L15.4242 13.5126C15.6102 13.6084 15.5544 13.8745 15.3439 13.8955L14.2456 14.184L13.4521 15.1286C13.3495 15.2939 13.085 15.2463 13.0534 15.0568L12.6185 12.4423Z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M1 3.6C1 2.16406 2.16406 1 3.6 1H12.3C13.7359 1 14.9 2.16406 14.9 3.6V5.81156C14.9003 5.81881 14.9004 5.82609 14.9004 5.8334C14.9004 5.84071 14.9003 5.84799 14.9 5.85524V10.045C14.9003 10.0522 14.9004 10.0595 14.9004 10.0668C14.9004 10.3982 14.6318 10.6668 14.3004 10.6668H11.1668C10.8907 10.6668 10.6668 10.8907 10.6668 11.1668V14.3C10.6668 14.6314 10.3982 14.9 10.0668 14.9L10.05 14.8998L3.6 14.9C2.16406 14.9 1 13.7359 1 12.3V3.6ZM13.2 5.2334C13.4761 5.2334 13.7 5.00954 13.7 4.7334V3.6C13.7 2.8268 13.0732 2.2 12.3 2.2H11.1668C10.8907 2.2 10.6668 2.42386 10.6668 2.7V4.7334C10.6668 5.00954 10.8907 5.2334 11.1668 5.2334H13.2ZM10.6668 6.9334C10.6668 6.65726 10.8907 6.4334 11.1668 6.4334H13.2C13.4761 6.4334 13.7 6.65726 13.7 6.9334V8.9668C13.7 9.24294 13.4761 9.4668 13.2 9.4668H11.1668C10.8907 9.4668 10.6668 9.24294 10.6668 8.9668V6.9334ZM8.9668 5.2334C9.24294 5.2334 9.4668 5.00954 9.4668 4.7334V2.7C9.4668 2.42386 9.24294 2.2 8.9668 2.2H6.9334C6.65726 2.2 6.4334 2.42386 6.4334 2.7V4.7334C6.4334 5.00954 6.65726 5.2334 6.9334 5.2334L8.9668 5.2334ZM6.4334 6.9334C6.4334 6.65726 6.65726 6.4334 6.9334 6.4334L8.9668 6.4334C9.24294 6.4334 9.4668 6.65726 9.4668 6.9334V8.9668C9.4668 9.24294 9.24294 9.4668 8.9668 9.4668L6.9334 9.4668C6.65726 9.4668 6.4334 9.24294 6.4334 8.9668V6.9334ZM4.7334 5.2334C5.00954 5.2334 5.2334 5.00954 5.2334 4.7334V2.7C5.2334 2.42386 5.00954 2.2 4.7334 2.2H3.6C2.8268 2.2 2.2 2.8268 2.2 3.6V4.7334C2.2 5.00954 2.42386 5.2334 2.7 5.2334H4.7334ZM2.2 6.9334C2.2 6.65726 2.42386 6.4334 2.7 6.4334H4.7334C5.00954 6.4334 5.2334 6.65725 5.2334 6.9334V8.9668C5.2334 9.24294 5.00954 9.4668 4.7334 9.4668H2.7C2.42386 9.4668 2.2 9.24294 2.2 8.9668V6.9334ZM5.2334 11.1668C5.2334 10.8907 5.00954 10.6668 4.7334 10.6668H2.7C2.42386 10.6668 2.2 10.8907 2.2 11.1668V12.3C2.2 13.0732 2.8268 13.7 3.6 13.7H4.7334C5.00954 13.7 5.2334 13.4761 5.2334 13.2V11.1668ZM9.4668 11.1668C9.4668 10.8907 9.24294 10.6668 8.9668 10.6668H6.9334C6.65726 10.6668 6.4334 10.8907 6.4334 11.1668V13.2C6.4334 13.4761 6.65726 13.7 6.9334 13.7H8.9668C9.24294 13.7 9.4668 13.4761 9.4668 13.2V11.1668Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, xo = Te(function(t, e) {
532
+ return Le($e, Object.assign({}, t, {
533
+ id: "select-range-single",
534
+ ref: e,
535
+ icon: Ys
536
+ }));
537
+ });
538
+ xo.displayName = "SelectRangeSingle";
539
+ function zs(t, e) {
540
+ return Object.keys(t).filter((n) => isNaN(Number(n)) && n !== "DefinedName").map((n) => ({
541
+ label: e.t(`formula.functionType.${n.toLocaleLowerCase()}`),
542
+ value: `${t[n]}`
543
+ }));
544
+ }
545
+ function pn(t) {
546
+ if (!t.require && !t.repeat)
547
+ return `[${t.name}]`;
548
+ if (t.require && !t.repeat)
549
+ return t.name;
550
+ if (!t.require && t.repeat)
551
+ return `[${t.name},...]`;
552
+ if (t.require && t.repeat)
553
+ return `${t.name},...`;
554
+ }
555
+ const Gs = (t, e = 100) => {
556
+ L(() => {
557
+ let n = null;
558
+ const o = () => {
559
+ n === null && (n = window.setTimeout(() => {
560
+ t(), n = null;
561
+ }, e));
562
+ };
563
+ return window.addEventListener("scroll", o), window.addEventListener("resize", o), () => {
564
+ n !== null && clearTimeout(n), window.removeEventListener("scroll", o), window.removeEventListener("resize", o);
565
+ };
566
+ }, [t, e]);
567
+ };
568
+ function wo(t, e, n) {
569
+ const o = O(be), r = le(() => new io({ left: -999, top: -999, right: -999, bottom: -999 }), []), s = O(Wt), i = O(oe), c = ee(() => {
570
+ const l = o.getEditor(t);
571
+ if (!l)
572
+ return;
573
+ const h = l.getBoundingClientRect(), { left: f, top: m, right: u, bottom: d } = h, a = r.getValue();
574
+ if (!(a.left === f && a.top === m && a.right === u && a.bottom === d))
575
+ return r.next({ left: f - 1, right: u + 1, top: m - 1, bottom: d + 1 }), h;
576
+ });
577
+ return L(() => {
578
+ e && c();
579
+ }, [t, o, i.unitAdded$, c, e, ...n != null ? n : []]), Gs(c), L(() => {
580
+ const l = s.scrollEvent$.pipe(co(100)).subscribe(c);
581
+ return () => {
582
+ l.unsubscribe();
583
+ };
584
+ }, []), [r, c];
585
+ }
586
+ const Ke = (t) => {
587
+ const e = j(t);
588
+ return e.current = t, e;
589
+ }, Zs = (t, e, n) => {
590
+ const o = O(Ht), r = O(Ee), [s, i] = $(), [c, l] = $(-1), [h, f] = $(!0), m = Ke(h), u = j(e);
591
+ u.current = e;
592
+ const d = () => {
593
+ i(void 0), l(-1), f(!1);
594
+ };
595
+ return L(() => {
596
+ if (n && t) {
597
+ const a = n.selectionChange$.pipe(cn(50)).subscribe((g) => {
598
+ if (g.textRanges.length === 1) {
599
+ const [p] = g.textRanges;
600
+ if (p.collapsed && m.current) {
601
+ const C = r.getFunctionAndParameter(`${u.current}A`, p.startOffset - 1);
602
+ if (C) {
603
+ const { functionName: S, paramIndex: v } = C, _ = o.getFunctionInfo(S);
604
+ i(_), l(v);
605
+ return;
606
+ }
607
+ }
608
+ }
609
+ i(void 0), l(-1);
610
+ }), I = n.selectionChange$.pipe(
611
+ Qt((g) => g.isEditing),
612
+ Qt((g) => g.textRanges.length === 1),
613
+ lo((g) => g.textRanges[0].startOffset),
614
+ jr()
615
+ ).subscribe(() => {
616
+ f(!0);
617
+ });
618
+ return () => {
619
+ a.unsubscribe(), I.unsubscribe();
620
+ };
621
+ }
622
+ }, [n, t]), L(() => {
623
+ t || d();
624
+ }, [t]), {
625
+ functionInfo: s,
626
+ paramIndex: c,
627
+ reset: d
628
+ };
629
+ }, Xs = "univer-formula-help-function", Qs = "univer-formula-help-function-title", Js = "univer-formula-help-function-title-icons", ei = "univer-formula-help-function-title-icon", ti = "univer-formula-help-function-content", ni = "univer-formula-help-function-content-inner", oi = "univer-formula-help-function-content-params", ri = "univer-formula-help-function-content-params-title", si = "univer-formula-help-function-content-params-detail", ii = "univer-formula-help-function-active", ci = "univer-formula-help-param", li = "univer-formula-help-param-prefix", ai = "univer-formula-help-param-item", ui = "univer-formula-help-param-active", J = {
630
+ formulaHelpFunction: Xs,
631
+ formulaHelpFunctionTitle: Qs,
632
+ formulaHelpFunctionTitleIcons: Js,
633
+ formulaHelpFunctionTitleIcon: ei,
634
+ formulaHelpFunctionContent: ti,
635
+ formulaHelpFunctionContentInner: ni,
636
+ formulaHelpFunctionContentParams: oi,
637
+ formulaHelpFunctionContentParamsTitle: ri,
638
+ formulaHelpFunctionContentParamsDetail: si,
639
+ formulaHelpFunctionActive: ii,
640
+ formulaHelpParam: ci,
641
+ formulaHelpParamPrefix: li,
642
+ formulaHelpParamItem: ai,
643
+ formulaHelpParamActive: ui
644
+ }, Yt = ({ className: t, title: e, value: n }) => /* @__PURE__ */ k("div", { className: J.formulaHelpFunctionContentParams, children: [
645
+ /* @__PURE__ */ b(
646
+ "div",
647
+ {
648
+ className: `
649
+ ${J.formulaHelpFunctionContentParamsTitle}
650
+ ${t}
651
+ `,
652
+ children: e
653
+ }
654
+ ),
655
+ /* @__PURE__ */ b("div", { className: J.formulaHelpFunctionContentParamsDetail, children: n })
656
+ ] }), fi = (t) => {
657
+ const { prefix: e, value: n, active: o, onClick: r } = t;
658
+ return /* @__PURE__ */ k("div", { className: J.formulaHelpParam, children: [
659
+ /* @__PURE__ */ k("span", { className: J.formulaHelpParamPrefix, children: [
660
+ e,
661
+ "("
662
+ ] }),
663
+ n && n.map((s, i) => /* @__PURE__ */ k("span", { className: J.formulaHelpParamItem, children: [
664
+ /* @__PURE__ */ b(
665
+ "span",
666
+ {
667
+ className: o === i ? J.formulaHelpFunctionActive : J.formulaHelpParamActive,
668
+ onClick: () => r(i),
669
+ children: pn(s)
670
+ }
671
+ ),
672
+ i === n.length - 1 ? "" : ","
673
+ ] }, s.name)),
674
+ ")"
675
+ ] });
676
+ }, Vn = () => {
677
+ };
678
+ function hi(t) {
679
+ const { onParamsSwitch: e = Vn, onClose: n = Vn, isFocus: o, editor: r, formulaText: s } = t, { functionInfo: i, paramIndex: c, reset: l } = Zs(o, s, r), h = le(() => !!i && c >= 0, [i, c]), [f, m] = $(!0), u = O(je), d = u.t("formula.prompt.required"), a = u.t("formula.prompt.optional"), I = r.getEditorId(), [g] = wo(I, h, [i, c]);
680
+ function p(S) {
681
+ e && e(S);
682
+ }
683
+ const C = () => {
684
+ l(), n();
685
+ };
686
+ return h && i ? /* @__PURE__ */ b(So, { portal: !0, onClickOutside: () => l(), anchorRect$: g, direction: "vertical", children: /* @__PURE__ */ k("div", { className: J.formulaHelpFunction, children: [
687
+ /* @__PURE__ */ k("div", { className: J.formulaHelpFunctionTitle, children: [
688
+ /* @__PURE__ */ b(
689
+ fi,
690
+ {
691
+ prefix: i.functionName,
692
+ value: i.functionParameter,
693
+ active: c,
694
+ onClick: p
695
+ }
696
+ ),
697
+ /* @__PURE__ */ k("div", { className: J.formulaHelpFunctionTitleIcons, children: [
698
+ /* @__PURE__ */ b(
699
+ "div",
700
+ {
701
+ className: J.formulaHelpFunctionTitleIcon,
702
+ style: { transform: f ? "rotateZ(-90deg)" : "rotateZ(90deg)" },
703
+ onClick: () => m(!f),
704
+ children: /* @__PURE__ */ b(gn, {})
705
+ }
706
+ ),
707
+ /* @__PURE__ */ b(
708
+ "div",
709
+ {
710
+ className: J.formulaHelpFunctionTitleIcon,
711
+ onClick: C,
712
+ children: /* @__PURE__ */ b(Vt, {})
713
+ }
714
+ )
715
+ ] })
716
+ ] }),
717
+ /* @__PURE__ */ b(
718
+ "div",
719
+ {
720
+ className: J.formulaHelpFunctionContent,
721
+ style: {
722
+ height: f ? "unset" : 0,
723
+ padding: f ? "revert-layer" : 0
724
+ },
725
+ children: /* @__PURE__ */ k("div", { className: J.formulaHelpFunctionContentInner, children: [
726
+ /* @__PURE__ */ b(
727
+ Yt,
728
+ {
729
+ title: u.t("formula.prompt.helpExample"),
730
+ value: `${i.functionName}(${i.functionParameter.map((S) => S.example).join(",")})`
731
+ }
732
+ ),
733
+ /* @__PURE__ */ b(
734
+ Yt,
735
+ {
736
+ title: u.t("formula.prompt.helpAbstract"),
737
+ value: i.description
738
+ }
739
+ ),
740
+ i && i.functionParameter && i.functionParameter.map((S, v) => /* @__PURE__ */ b(
741
+ Yt,
742
+ {
743
+ className: c === v ? J.formulaHelpFunctionActive : "",
744
+ title: S.name,
745
+ value: `${S.require ? d : a} ${S.detail}`
746
+ },
747
+ v
748
+ ))
749
+ ] })
750
+ }
751
+ )
752
+ ] }) }) : null;
753
+ }
754
+ const di = (t) => {
755
+ const e = O(be);
756
+ return ee((o) => {
757
+ var r, s;
758
+ if (t) {
759
+ e.focus(t.getEditorId());
760
+ const i = [...t.getSelectionRanges()];
761
+ if (ft.isDefine(o))
762
+ t.setSelectionRanges([{ startOffset: o, endOffset: o }]);
763
+ else if (!i.length && !t.docSelectionRenderService.isOnPointerEvent) {
764
+ const c = (s = (r = t.getDocumentData().body) == null ? void 0 : r.dataStream) != null ? s : `\r
765
+ `, l = Math.max(c.length - 2, 0);
766
+ t.setSelectionRanges([{ startOffset: l, endOffset: l }]);
767
+ }
768
+ }
769
+ });
770
+ };
771
+ var mi = Object.getOwnPropertyDescriptor, gi = (t, e, n, o) => {
772
+ for (var r = o > 1 ? void 0 : o ? mi(e, n) : e, s = t.length - 1, i; s >= 0; s--)
773
+ (i = t[s]) && (r = i(r) || r);
774
+ return r;
775
+ }, Xe = (t, e) => (n, o) => e(n, o, t);
776
+ let De = class extends Cr {
777
+ constructor(e, n, o, r, s, i, c) {
778
+ super(
779
+ n,
780
+ o,
781
+ r,
782
+ s,
783
+ i
784
+ );
785
+ B(this, "_workbookSelections");
786
+ B(this, "_eventDisposables");
787
+ this._context = e, this._contextService = i, this._refSelectionsService = c, this._workbookSelections = this._refSelectionsService.getWorkbookSelections(this._context.unitId), this._initSelectionChangeListener(), this._initSkeletonChangeListener(), this._initUserActionSyncListener(), this._setSelectionStyle(pi(this._themeService)), this._remainLastEnabled = !0, this._highlightHeader = !1;
788
+ }
789
+ getLocation() {
790
+ return this._skeleton.getLocation();
791
+ }
792
+ setRemainLastEnabled(e) {
793
+ this._remainLastEnabled = e;
794
+ }
795
+ /**
796
+ * This is set to true when you need to add a new selection.
797
+ * @param {boolean} enabled
798
+ * @memberof RefSelectionsRenderService
799
+ */
800
+ setSkipLastEnabled(e) {
801
+ this._skipLastEnabled = e;
802
+ }
803
+ clearLastSelection() {
804
+ const e = this._selectionControls[this._selectionControls.length - 1];
805
+ e && (e.dispose(), this._selectionControls.pop());
806
+ }
807
+ /**
808
+ * Call this method and user will be able to select on the canvas to update selections.
809
+ */
810
+ enableSelectionChanging() {
811
+ return this._disableSelectionChanging(), this._eventDisposables = this._initCanvasEventListeners(), Qn(() => this._disableSelectionChanging());
812
+ }
813
+ _disableSelectionChanging() {
814
+ var e;
815
+ (e = this._eventDisposables) == null || e.dispose(), this._eventDisposables = null;
816
+ }
817
+ disableSelectionChanging() {
818
+ this._disableSelectionChanging();
819
+ }
820
+ _initCanvasEventListeners() {
821
+ const e = this._getSheetObject(), { spreadsheetRowHeader: n, spreadsheetColumnHeader: o, spreadsheet: r, spreadsheetLeftTopPlaceholder: s } = e, { scene: i } = this._context, c = new Ve();
822
+ return c.add(r == null ? void 0 : r.onPointerDown$.subscribeEvent((l, h) => {
823
+ this.inRefSelectionMode() && (this._onPointerDown(l, r.zIndex + 1, ge.NORMAL, this._getActiveViewport(l)), l.button !== 2 && h.stopPropagation());
824
+ })), c.add(
825
+ n == null ? void 0 : n.onPointerDown$.subscribeEvent((l, h) => {
826
+ if (!this.inRefSelectionMode()) return;
827
+ const f = this._sheetSkeletonManagerService.getCurrent().skeleton, { row: m } = yn(l.offsetX, l.offsetY, i, f);
828
+ Nn(this._workbookSelections.getCurrentSelections(), m, ge.ROW) || (this._onPointerDown(l, (r.zIndex || 1) + 1, ge.ROW, this._getActiveViewport(l), jt.Y), l.button !== 2 && h.stopPropagation());
829
+ })
830
+ ), c.add(o == null ? void 0 : o.onPointerDown$.subscribeEvent((l, h) => {
831
+ if (!this.inRefSelectionMode()) return;
832
+ const f = this._sheetSkeletonManagerService.getCurrent().skeleton, { column: m } = yn(l.offsetX, l.offsetY, i, f);
833
+ Nn(this._workbookSelections.getCurrentSelections(), m, ge.COLUMN) || (this._onPointerDown(l, (r.zIndex || 1) + 1, ge.COLUMN, this._getActiveViewport(l), jt.X), l.button !== 2 && h.stopPropagation());
834
+ })), c.add(s == null ? void 0 : s.onPointerDown$.subscribeEvent((l, h) => {
835
+ if (this._reset(), !this.inRefSelectionMode()) return;
836
+ const f = this._sheetSkeletonManagerService.getCurrent().skeleton, m = vr(f);
837
+ this._addSelectionControlByModelData(m), this._selectionMoveStart$.next(this.getSelectionDataWithStyle());
838
+ const u = i.onPointerUp$.subscribeEvent(() => {
839
+ u.unsubscribe(), this._selectionMoveEnd$.next(this.getSelectionDataWithStyle());
840
+ });
841
+ l.button !== 2 && h.stopPropagation();
842
+ })), c;
843
+ }
844
+ /**
845
+ * Add a selection in spreadsheet, create a new SelectionControl and then update this control by range derives from selection.
846
+ * For ref selection, create selectionShapeExtension to handle user action.
847
+ * @param {ISelectionWithCoord} selectionWithStyle
848
+ */
849
+ _addSelectionControlByModelData(e) {
850
+ var i;
851
+ const n = this._skeleton, o = (i = e.style) != null ? i : to(this._themeService), r = this._scene;
852
+ return e.style = o, this.newSelectionControl(r, n, e);
853
+ }
854
+ _initSelectionChangeListener() {
855
+ this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe((e) => {
856
+ this._reset(), this._skeleton && this.resetSelectionsByModelData(e || []);
857
+ }));
858
+ }
859
+ /**
860
+ * Update selectionModel in this._workbookSelections by user action in spreadsheet area.
861
+ */
862
+ _initUserActionSyncListener() {
863
+ this.disposeWithMe(this.selectionMoveStart$.subscribe((e) => {
864
+ this._updateSelections(e, Kt.MOVE_START);
865
+ })), this.disposeWithMe(this.selectionMoving$.subscribe((e) => {
866
+ this._updateSelections(e, Kt.MOVING);
867
+ })), this.disposeWithMe(this.selectionMoveEnd$.subscribe((e) => {
868
+ this._updateSelections(e, Kt.MOVE_END);
869
+ }));
870
+ }
871
+ _updateSelections(e, n) {
872
+ const r = this._context.unit.getActiveSheet().getSheetId();
873
+ e.length !== 0 && this._workbookSelections.setSelections(
874
+ r,
875
+ e.map((s) => os(s)),
876
+ n
877
+ );
878
+ }
879
+ _initSkeletonChangeListener() {
880
+ this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((e) => {
881
+ if (!e)
882
+ return;
883
+ const { skeleton: n } = e, { scene: o } = this._context, r = o.getViewport(xn.VIEW_MAIN);
884
+ this._skeleton && this._skeleton.worksheet.getSheetId() !== n.worksheet.getSheetId() && this._reset(), this._changeRuntime(n, o, r);
885
+ const s = this._workbookSelections.getCurrentSelections();
886
+ this.resetSelectionsByModelData(s);
887
+ }));
888
+ }
889
+ _getActiveViewport(e) {
890
+ const n = this._getSheetObject();
891
+ return n == null ? void 0 : n.scene.getActiveViewportByCoord(wn.FromArray([e.offsetX, e.offsetY]));
892
+ }
893
+ _getSheetObject() {
894
+ return _r(this._context.unit, this._context);
895
+ }
896
+ /**
897
+ * Handle pointer down event, bind pointermove & pointerup handler.
898
+ * then trigger selectionMoveStart$.
899
+ *
900
+ * @param evt
901
+ * @param _zIndex
902
+ * @param rangeType
903
+ * @param viewport
904
+ * @param scrollTimerType
905
+ */
906
+ // eslint-disable-next-line complexity, max-lines-per-function
907
+ _onPointerDown(e, n = 0, o = ge.NORMAL, r, s = jt.ALL) {
908
+ var R;
909
+ this._rangeType = o;
910
+ const i = this._skeleton, c = this._scene;
911
+ if (!c || !i)
912
+ return;
913
+ r && (this._activeViewport = r);
914
+ const { offsetX: l, offsetY: h } = e, f = c.getViewport(xn.VIEW_MAIN);
915
+ if (!f) return;
916
+ const m = c.getCoordRelativeToViewport(wn.FromArray([l, h])), { x: u, y: d } = m;
917
+ this._startViewportPosX = u, this._startViewportPosY = d;
918
+ const a = c.getScrollXYInfoByViewport(m), { scaleX: I, scaleY: g } = c.getAncestorScale(), p = this._skeleton.getCellByOffset(u, d, I, g, a);
919
+ if (!p) return;
920
+ switch (o) {
921
+ case ge.NORMAL:
922
+ break;
923
+ case ge.ROW:
924
+ p.startColumn = 0, p.endColumn = this._skeleton.getColumnCount() - 1;
925
+ break;
926
+ case ge.COLUMN:
927
+ p.startRow = 0, p.endRow = this._skeleton.getRowCount() - 1;
928
+ break;
929
+ case ge.ALL:
930
+ p.startRow = 0, p.startColumn = 0, p.endRow = this._skeleton.getRowCount() - 1, p.endColumn = this._skeleton.getColumnCount() - 1;
931
+ }
932
+ const C = { range: p, primary: p, style: null };
933
+ C.range.rangeType = o;
934
+ const S = Xt(C, this._skeleton);
935
+ this._startRangeWhenPointerDown = { ...S.rangeWithCoord };
936
+ const v = { ...S.rangeWithCoord, rangeType: o };
937
+ let _ = this.getActiveSelectionControl();
938
+ const T = this.getSelectionControls();
939
+ for (const y of T) {
940
+ if (e.button === 2 && Gn.contains(y.model, v)) {
941
+ _ = y;
942
+ return;
943
+ }
944
+ if (y.model.isEqual(v)) {
945
+ _ = y;
946
+ break;
947
+ }
948
+ }
949
+ this._checkClearPreviousControls(e);
950
+ const w = _ == null ? void 0 : _.model.currentCell, A = e.shiftKey && w, M = this._remainLastEnabled && !e.ctrlKey && !e.shiftKey && !this._skipLastEnabled && !this._singleSelectionEnabled;
951
+ A && w ? this._makeSelectionByTwoCells(
952
+ w,
953
+ v,
954
+ i,
955
+ o,
956
+ _
957
+ // Get updated in this method
958
+ ) : M && _ ? _.updateRangeBySelectionWithCoord(S) : _ = this.newSelectionControl(c, i, C);
959
+ for (let y = 0; y < this.getSelectionControls().length - 1; y++)
960
+ this.getSelectionControls()[y].clearHighlight();
961
+ this._selectionMoveStart$.next(this.getSelectionDataWithStyle()), c.disableObjectsEvent(), this._clearUpdatingListeners(), this._addEndingListeners(), (R = c.getTransformer()) == null || R.clearSelectedObjects(), this._setupPointerMoveListener(f, _, o, s, u, d), this._escapeShortcutDisposable = this._shortcutService.forceEscape(), this._scenePointerUpSub = c.onPointerUp$.subscribeEvent(() => {
962
+ var y;
963
+ this._clearUpdatingListeners(), this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()), (y = this._escapeShortcutDisposable) == null || y.dispose(), this._escapeShortcutDisposable = null;
964
+ });
965
+ }
966
+ /**
967
+ * Diff between normal selection, no highlightHeader for ref selections.
968
+ * @param scene
969
+ * @param skeleton
970
+ * @param selectionWithCoord
971
+ * @returns {SelectionControl} selectionControl just created
972
+ */
973
+ newSelectionControl(e, n, o) {
974
+ const r = this.getSelectionControls().length, { rowHeaderWidth: s, columnHeaderHeight: i } = n, c = new no(e, r, this._themeService, {
975
+ highlightHeader: this._highlightHeader,
976
+ enableAutoFill: !1,
977
+ rowHeaderWidth: s,
978
+ columnHeaderHeight: i
979
+ }), l = Xt(o, n);
980
+ return c.updateRangeBySelectionWithCoord(l), this._selectionControls.push(c), c.setControlExtension({
981
+ skeleton: n,
982
+ scene: e,
983
+ themeService: this._themeService,
984
+ injector: this._injector,
985
+ selectionHooks: {
986
+ selectionMoveEnd: () => {
987
+ this._selectionMoveEnd$.next(this.getSelectionDataWithStyle());
988
+ }
989
+ }
990
+ }), c;
991
+ }
992
+ };
993
+ De = gi([
994
+ Xe(1, K(mt)),
995
+ Xe(2, K(gt)),
996
+ Xe(3, Ut),
997
+ Xe(4, K(Lt)),
998
+ Xe(5, on),
999
+ Xe(6, kt)
1000
+ ], De);
1001
+ function pi(t) {
1002
+ const e = to(t);
1003
+ return e.widgets = { tl: !0, tc: !0, tr: !0, ml: !0, mr: !0, bl: !0, bc: !0, br: !0 }, e;
1004
+ }
1005
+ function Si(t) {
1006
+ var r, s;
1007
+ const n = t.get(oe).getCurrentUniverDocInstance();
1008
+ return n != null && n.getBody() ? { dataStream: (s = (r = n.getBody()) == null ? void 0 : r.dataStream) != null ? s : "", offset: 0 } : void 0;
1009
+ }
1010
+ var we = /* @__PURE__ */ ((t) => (t[t.NOT_SELECT = 0] = "NOT_SELECT", t[t.NEED_ADD = 1] = "NEED_ADD", t[t.CAN_EDIT = 2] = "CAN_EDIT", t[t.EDIT_OTHER_SHEET_REFERENCE = 3] = "EDIT_OTHER_SHEET_REFERENCE", t))(we || {});
1011
+ function Ci(t) {
1012
+ var w;
1013
+ const { editorId: e, isFocus: n, disableOnClick: o, unitId: r, subUnitId: s } = t, i = O(Ne), c = O(oe), l = i.getRenderById(r), h = i.getRenderById(e), f = h == null ? void 0 : h.with(ao), m = O(Eo), u = O(mt), [d, a] = $(
1014
+ 0
1015
+ /* NOT_SELECT */
1016
+ ), I = O(Ee), g = j(!0), p = l == null ? void 0 : l.with(De), C = Ke(d), S = c.getUnit(r, ue.UNIVER_SHEET), v = S == null ? void 0 : S.getSheetBySheetId(s), _ = ee((A) => {
1017
+ p && p.setSkipLastEnabled(
1018
+ A === 1 || A === 3
1019
+ /* EDIT_OTHER_SHEET_REFERENCE */
1020
+ ), C.current = A, a(A);
1021
+ }), T = ee(() => {
1022
+ var te, ie;
1023
+ if (!S) return;
1024
+ const A = S.getActiveSheet(), M = f == null ? void 0 : f.getActiveTextRange(), R = M != null && M.collapsed ? M.startOffset : -1, y = Si(u);
1025
+ if (!y) return;
1026
+ const P = (te = y == null ? void 0 : y.dataStream) == null ? void 0 : te.slice(0, -2), N = ((ie = I.sequenceNodesBuilder(P)) != null ? ie : []).map((q) => typeof q == "object" ? q.nodeType === z.REFERENCE ? {
1027
+ ...q,
1028
+ range: Dr(q.token)
1029
+ } : {
1030
+ ...q,
1031
+ range: void 0
1032
+ } : q), E = P[R - 1], F = P[R], x = N.find((q) => typeof q == "object" && q.nodeType === z.REFERENCE && R === q.endIndex + 2), H = E && Lr(E) && (!F || $r(F) && F !== nt.OPEN_BRACKET), V = !!x;
1033
+ if ((P == null ? void 0 : P.substring(0, 1)) === "=" && (H || V))
1034
+ if (V) {
1035
+ if (g.current)
1036
+ return;
1037
+ !x.range.sheetName && A.getSheetId() === (v == null ? void 0 : v.getSheetId()) || x.range.sheetName === A.getName() ? _(
1038
+ 2
1039
+ /* CAN_EDIT */
1040
+ ) : _(
1041
+ 3
1042
+ /* EDIT_OTHER_SHEET_REFERENCE */
1043
+ );
1044
+ } else
1045
+ g.current = !1, _(
1046
+ 1
1047
+ /* NEED_ADD */
1048
+ );
1049
+ else
1050
+ _(
1051
+ 0
1052
+ /* NOT_SELECT */
1053
+ );
1054
+ });
1055
+ return L(() => {
1056
+ const A = m.textSelection$.pipe(Qt((M) => M.unitId === e)).subscribe(() => {
1057
+ T();
1058
+ });
1059
+ return () => A.unsubscribe();
1060
+ }, [T, m.textSelection$, e]), L(() => {
1061
+ n || (_(
1062
+ 0
1063
+ /* NOT_SELECT */
1064
+ ), g.current = !0);
1065
+ }, [n, _]), L(() => {
1066
+ var M;
1067
+ if (!o) return;
1068
+ const A = (M = h == null ? void 0 : h.mainComponent) == null ? void 0 : M.onPointerDown$.subscribeEvent(() => {
1069
+ _(
1070
+ 0
1071
+ /* NOT_SELECT */
1072
+ ), g.current = !0;
1073
+ });
1074
+ return () => A == null ? void 0 : A.unsubscribe();
1075
+ }, [o, (w = h == null ? void 0 : h.mainComponent) == null ? void 0 : w.onPointerDown$, _]), L(() => {
1076
+ if (!n) return;
1077
+ const A = S == null ? void 0 : S.activeSheet$.subscribe(() => {
1078
+ T();
1079
+ });
1080
+ return () => A == null ? void 0 : A.unsubscribe();
1081
+ }, [T, n, S == null ? void 0 : S.activeSheet$]), { isSelecting: d, isSelectingRef: C };
1082
+ }
1083
+ const vi = () => {
1084
+ const t = O(Ee);
1085
+ return Ft((n) => t.sequenceNodesBuilder(n) || [], [t]);
1086
+ };
1087
+ function _i(t, e, n) {
1088
+ const o = t.getCurrentTheme(), r = new sn(e).setAlpha(0.05).toRgbString();
1089
+ return {
1090
+ id: n,
1091
+ strokeWidth: 1,
1092
+ stroke: e,
1093
+ fill: r,
1094
+ widgets: { tl: !0, tc: !0, tr: !0, ml: !0, mr: !0, bl: !0, bc: !0, br: !0 },
1095
+ widgetSize: 6,
1096
+ widgetStrokeWidth: 1,
1097
+ widgetStroke: o.colorWhite
1098
+ };
1099
+ }
1100
+ function Do(t) {
1101
+ var p, C, S;
1102
+ const {
1103
+ unitId: e,
1104
+ subUnitId: n,
1105
+ refSelections: o,
1106
+ editor: r,
1107
+ refSelectionsService: s,
1108
+ refSelectionsRenderService: i,
1109
+ sheetSkeletonManagerService: c,
1110
+ themeService: l,
1111
+ univerInstanceService: h
1112
+ } = t, f = h.getUnit(e, ue.UNIVER_SHEET), m = f == null ? void 0 : f.getActiveSheet(), u = [];
1113
+ if (!f || !m) {
1114
+ s.setSelections(u);
1115
+ return;
1116
+ }
1117
+ const d = m.getSheetId(), a = (v) => {
1118
+ var _;
1119
+ return (_ = f == null ? void 0 : f.getSheetBySheetName(v)) == null ? void 0 : _.getSheetId();
1120
+ };
1121
+ if (!((p = c == null ? void 0 : c.getWorksheetSkeleton(d)) == null ? void 0 : p.skeleton)) return;
1122
+ const g = [];
1123
+ for (let v = 0, _ = o.length; v < _; v++) {
1124
+ const T = o[v], { themeColor: w, token: A, refIndex: M, endIndex: R } = T, y = ot(A), { unitId: P, sheetName: N, range: E } = y;
1125
+ if (P && e !== P)
1126
+ continue;
1127
+ const F = a(N);
1128
+ if (F && F !== d || !F && d !== n)
1129
+ continue;
1130
+ const x = rs(E, m.getRowCount(), m.getColumnCount());
1131
+ x.unitId = e, x.sheetId = d, u.push({
1132
+ range: x,
1133
+ primary: null,
1134
+ style: _i(l, w, M.toString())
1135
+ }), g.push(R);
1136
+ }
1137
+ if (r) {
1138
+ const v = (S = (C = r.getSelectionRanges()) == null ? void 0 : C[0]) == null ? void 0 : S.startOffset, _ = g.findIndex((T) => T + 2 === v);
1139
+ _ !== -1 ? i == null || i.setActiveSelectionIndex(_) : i == null || i.resetActiveSelectionIndex();
1140
+ }
1141
+ return u;
1142
+ }
1143
+ function Ri(t, e) {
1144
+ const n = O(oe), o = O(gt), r = O(kt), i = O(Ne).getRenderById(t), c = i == null ? void 0 : i.with(De), l = i == null ? void 0 : i.with(Lt), h = ee((f, m) => {
1145
+ if (c != null && c.selectionMoving) return;
1146
+ const u = Do({
1147
+ unitId: t,
1148
+ subUnitId: e,
1149
+ refSelections: f,
1150
+ editor: m,
1151
+ refSelectionsService: r,
1152
+ refSelectionsRenderService: c,
1153
+ sheetSkeletonManagerService: l,
1154
+ themeService: o,
1155
+ univerInstanceService: n
1156
+ });
1157
+ if (!u) return;
1158
+ ((c == null ? void 0 : c.getSelectionControls()) || []).length === u.length ? c == null || c.resetSelectionsByModelData(u) : r.setSelections(u);
1159
+ });
1160
+ return L(() => () => {
1161
+ c == null || c.resetActiveSelectionIndex();
1162
+ }, [c]), h;
1163
+ }
1164
+ function Lo(t = "") {
1165
+ const e = O(Ht), n = Ii(), o = O(ae), r = le(() => t.length, [t]);
1166
+ return ee((i, c, l = !0, h) => {
1167
+ const f = i.getDocumentData(), m = i.getEditorId();
1168
+ if (!f)
1169
+ return [];
1170
+ const u = f.body;
1171
+ if (!u)
1172
+ return [];
1173
+ const d = u.dataStream.slice(0, u.dataStream.length - 2), a = { dataStream: "", ...f.body };
1174
+ if (!d.startsWith(t)) return [];
1175
+ if (c == null || c.length === 0)
1176
+ return a.textRuns = [], o.syncExecuteCommand(Pn.id, {
1177
+ unitId: m,
1178
+ body: bn(a, 0, a.dataStream.length - 2)
1179
+ }), [];
1180
+ {
1181
+ const { textRuns: I, refSelections: g } = Ei(e, n, c);
1182
+ r && I.forEach((S) => {
1183
+ S.ed = S.ed + r, S.st = S.st + r;
1184
+ }), a.textRuns = [{ st: 0, ed: 1, ts: { fs: 11 } }, ...I];
1185
+ const p = c.reduce((S, v) => typeof v == "string" ? `${S}${v}` : `${S}${v.token}`, "");
1186
+ a.dataStream = `${t}${p}\r
1187
+ `;
1188
+ let C;
1189
+ if (l) {
1190
+ C = i.getSelectionRanges();
1191
+ const S = a.dataStream.length - 2 + r;
1192
+ C.forEach((v) => {
1193
+ v.startOffset = Math.max(0, Math.min(v.startOffset, S)), v.endOffset = Math.max(0, Math.min(v.endOffset, S));
1194
+ });
1195
+ }
1196
+ return o.syncExecuteCommand(Pn.id, {
1197
+ unitId: m,
1198
+ body: bn(a, 0, a.dataStream.length - 2),
1199
+ textRanges: h != null ? h : C
1200
+ }), g;
1201
+ }
1202
+ });
1203
+ }
1204
+ function Ii() {
1205
+ const e = O(gt).getCurrentTheme();
1206
+ return le(() => {
1207
+ const o = [
1208
+ e.loopColor1,
1209
+ e.loopColor2,
1210
+ e.loopColor3,
1211
+ e.loopColor4,
1212
+ e.loopColor5,
1213
+ e.loopColor6,
1214
+ e.loopColor7,
1215
+ e.loopColor8,
1216
+ e.loopColor9,
1217
+ e.loopColor10,
1218
+ e.loopColor11,
1219
+ e.loopColor12
1220
+ ], r = e.hyacinth700, s = e.verdancy800, i = e.colorBlack;
1221
+ return { formulaRefColors: o, numberColor: r, stringColor: s, plainTextColor: i };
1222
+ }, [e]);
1223
+ }
1224
+ function Ei(t, e, n) {
1225
+ const { formulaRefColors: o, numberColor: r, stringColor: s, plainTextColor: i } = e, c = [], l = [], h = /* @__PURE__ */ new Map();
1226
+ let f = 0;
1227
+ for (let m = 0, u = n.length; m < u; m++) {
1228
+ const d = n[m];
1229
+ if (typeof d == "string") {
1230
+ const S = c[c.length - 1], v = S ? S.ed : 0, _ = v + d.length;
1231
+ c.push({
1232
+ st: v,
1233
+ ed: _,
1234
+ ts: {
1235
+ cl: {
1236
+ rgb: i
1237
+ },
1238
+ fs: 11
1239
+ }
1240
+ });
1241
+ continue;
1242
+ }
1243
+ if (t.hasDefinedNameDescription(d.token.trim())) {
1244
+ c.push({
1245
+ st: d.startIndex,
1246
+ ed: d.endIndex + 1,
1247
+ ts: {
1248
+ cl: {
1249
+ rgb: i
1250
+ },
1251
+ fs: 11
1252
+ }
1253
+ });
1254
+ continue;
1255
+ }
1256
+ const { startIndex: a, endIndex: I, nodeType: g, token: p } = d;
1257
+ let C = "";
1258
+ if (g === z.REFERENCE) {
1259
+ if (h.has(p))
1260
+ C = h.get(p);
1261
+ else {
1262
+ const S = f % o.length;
1263
+ C = o[S], h.set(p, C), f++;
1264
+ }
1265
+ l.push({
1266
+ refIndex: m,
1267
+ themeColor: C,
1268
+ token: p,
1269
+ startIndex: d.startIndex,
1270
+ endIndex: d.endIndex,
1271
+ index: l.length
1272
+ });
1273
+ } else g === z.NUMBER ? C = r : (g === z.STRING || g === z.ARRAY) && (C = s);
1274
+ C && C.length > 0 ? c.push({
1275
+ st: a,
1276
+ ed: I + 1,
1277
+ ts: {
1278
+ cl: {
1279
+ rgb: C
1280
+ },
1281
+ fs: 11
1282
+ }
1283
+ }) : c.push({
1284
+ st: a,
1285
+ ed: I + 1,
1286
+ ts: {
1287
+ cl: {
1288
+ rgb: i
1289
+ },
1290
+ fs: 11
1291
+ }
1292
+ });
1293
+ }
1294
+ return { textRuns: c, refSelections: l };
1295
+ }
1296
+ const bi = (t, e, n, o) => {
1297
+ const r = O(ae), s = O(Ut), i = j(e);
1298
+ i.current = e;
1299
+ const c = j(o);
1300
+ c.current = o, L(() => {
1301
+ if (!n || !t)
1302
+ return;
1303
+ const h = `sheet.formula-embedding-editor.${n.getEditorId()}`, f = new Ve(), m = (a, I) => {
1304
+ if (c.current) {
1305
+ c.current(a, I);
1306
+ return;
1307
+ }
1308
+ let g = ne.LEFT;
1309
+ a === D.ARROW_DOWN ? g = ne.DOWN : a === D.ARROW_UP ? g = ne.UP : a === D.ARROW_RIGHT && (g = ne.RIGHT), I === U.SHIFT ? r.executeCommand(Zr.id, {
1310
+ direction: g
1311
+ }) : r.executeCommand(Xr.id, {
1312
+ direction: g
1313
+ });
1314
+ }, u = (a, I) => {
1315
+ let g = ne.DOWN;
1316
+ a === D.ARROW_DOWN ? g = ne.DOWN : a === D.ARROW_UP ? g = ne.UP : a === D.ARROW_LEFT ? g = ne.LEFT : a === D.ARROW_RIGHT && (g = ne.RIGHT), i.current ? I === U.CTRL_COMMAND ? r.executeCommand(Tn.id, {
1317
+ direction: g,
1318
+ jumpOver: Fn.moveGap,
1319
+ extra: "formula-editor",
1320
+ fromCurrentSelection: i.current === we.NEED_ADD || i.current === we.EDIT_OTHER_SHEET_REFERENCE
1321
+ }) : I === U.SHIFT ? r.executeCommand(On.id, {
1322
+ direction: g,
1323
+ extra: "formula-editor"
1324
+ }) : I === (U.CTRL_COMMAND | U.SHIFT) ? r.executeCommand(On.id, {
1325
+ direction: g,
1326
+ jumpOver: Fn.moveGap,
1327
+ extra: "formula-editor"
1328
+ }) : r.executeCommand(Tn.id, {
1329
+ direction: g,
1330
+ extra: "formula-editor",
1331
+ fromCurrentSelection: i.current === we.NEED_ADD || i.current === we.EDIT_OTHER_SHEET_REFERENCE
1332
+ }) : m(a, I);
1333
+ };
1334
+ return f.add(r.registerCommand({
1335
+ id: h,
1336
+ type: Ie.OPERATION,
1337
+ handler(a, I) {
1338
+ const { keyCode: g, metaKey: p } = I;
1339
+ u(g, p);
1340
+ }
1341
+ })), [
1342
+ { keyCode: D.ARROW_DOWN },
1343
+ { keyCode: D.ARROW_LEFT },
1344
+ { keyCode: D.ARROW_RIGHT },
1345
+ { keyCode: D.ARROW_UP },
1346
+ { keyCode: D.ARROW_DOWN, metaKey: U.SHIFT },
1347
+ { keyCode: D.ARROW_LEFT, metaKey: U.SHIFT },
1348
+ { keyCode: D.ARROW_RIGHT, metaKey: U.SHIFT },
1349
+ { keyCode: D.ARROW_UP, metaKey: U.SHIFT },
1350
+ { keyCode: D.ARROW_DOWN, metaKey: U.CTRL_COMMAND },
1351
+ { keyCode: D.ARROW_LEFT, metaKey: U.CTRL_COMMAND },
1352
+ { keyCode: D.ARROW_RIGHT, metaKey: U.CTRL_COMMAND },
1353
+ { keyCode: D.ARROW_UP, metaKey: U.CTRL_COMMAND },
1354
+ { keyCode: D.ARROW_DOWN, metaKey: U.CTRL_COMMAND | U.SHIFT },
1355
+ { keyCode: D.ARROW_LEFT, metaKey: U.CTRL_COMMAND | U.SHIFT },
1356
+ { keyCode: D.ARROW_RIGHT, metaKey: U.CTRL_COMMAND | U.SHIFT },
1357
+ { keyCode: D.ARROW_UP, metaKey: U.CTRL_COMMAND | U.SHIFT }
1358
+ ].map(({ keyCode: a, metaKey: I }) => ({
1359
+ id: h,
1360
+ binding: I ? a | I : a,
1361
+ preconditions: () => !0,
1362
+ priority: 900,
1363
+ staticParameters: {
1364
+ eventType: ye.Keyboard,
1365
+ keyCode: a,
1366
+ metaKey: I
1367
+ }
1368
+ })).forEach((a) => {
1369
+ f.add(s.registerShortcut(a));
1370
+ }), () => {
1371
+ f.dispose();
1372
+ };
1373
+ }, [r, n, t, s]);
1374
+ }, yi = (t, e, n, o = !0) => {
1375
+ const r = O(Ne), s = O(on), i = O(hs), c = O(kt), l = r.getRenderById(n), h = l == null ? void 0 : l.with(De);
1376
+ Ot(() => {
1377
+ if (t)
1378
+ return s.setContextValue(bt, !0), () => {
1379
+ s.setContextValue(bt, !1), c.clear();
1380
+ };
1381
+ }, [s, t, c]), Ot(() => {
1382
+ if (t && e) {
1383
+ const f = h == null ? void 0 : h.enableSelectionChanging();
1384
+ return s.setContextValue(Dn, !0), () => {
1385
+ s.setContextValue(Dn, !1), f == null || f.dispose();
1386
+ };
1387
+ }
1388
+ }, [s, t, h, e]), L(() => {
1389
+ if (t)
1390
+ return s.setContextValue(bt, !0), o && i.disable(), () => {
1391
+ s.setContextValue(bt, !1), o && i.enable();
1392
+ };
1393
+ }, [i, s, t, o]), L(() => {
1394
+ t && (h == null || h.setSkipLastEnabled(!1));
1395
+ }, [t, h]);
1396
+ }, Ni = (t, e, n) => {
1397
+ const o = O(oe), r = O(ln);
1398
+ return Ft(() => {
1399
+ if (t) {
1400
+ const i = [...r.getWorkbookSelections(e).getSelectionsOfWorksheet(n)], c = o.getCurrentUnitForType(ue.UNIVER_SHEET), l = c == null ? void 0 : c.getActiveSheet();
1401
+ l && l.getSheetId() === n && r.setSelections(i);
1402
+ }
1403
+ }, [t, r, n, e, o]);
1404
+ }, Ti = (t) => t.reduce((e, n) => typeof n == "string" ? e + n.length : e + n.token.length, 0), tn = (t) => t.map((e) => typeof e == "string" ? e : e.token).join(""), yt = (t, e = !1, n = "") => e ? t.map((o) => o.sheetName !== "" && o.sheetName !== n ? ht(o.sheetName, o.range) : pe(o.range)) : t.map((o) => pe(o.range)), Fi = (t) => {
1405
+ var f, m, u;
1406
+ const { editor: e, lexerTreeBuilder: n } = t, o = e == null ? void 0 : e.getSelectionRanges();
1407
+ if ((o == null ? void 0 : o.length) !== 1)
1408
+ return;
1409
+ const s = o[0].startOffset - 1, i = ((m = (f = e == null ? void 0 : e.getDocumentData().body) == null ? void 0 : f.dataStream) != null ? m : `\r
1410
+ `).slice(0, -2), c = (u = n.sequenceNodesBuilder(i.slice(1))) != null ? u : [], l = mn(c, s, !1), h = To(c, l);
1411
+ return {
1412
+ nodeIndex: l,
1413
+ updatingRefIndex: h,
1414
+ sequenceNodes: c,
1415
+ offset: s
1416
+ };
1417
+ }, Oi = () => {
1418
+ }, Mi = (t, e, n, o, r, s, i, c, l, h = Oi) => {
1419
+ const f = O(Ne), m = O(oe), u = O(ae), d = O(Eo), a = O(gt), I = O(Ee), g = m.getUnit(o), p = ee((R) => {
1420
+ var y, P;
1421
+ return (P = (y = g == null ? void 0 : g.getSheetBySheetId(R)) == null ? void 0 : y.getName()) != null ? P : "";
1422
+ }), C = le(() => p(r), [p, r]), S = qe(g == null ? void 0 : g.activeSheet$), v = Ke({ activeSheet: S, sheetName: C }), _ = f.getRenderById(o), T = _ == null ? void 0 : _.with(De), w = _ == null ? void 0 : _.with(Lt), A = O(kt), M = ee((R, y) => {
1423
+ var H, V, te, ie, q, Ye;
1424
+ const P = Fi({ editor: l, lexerTreeBuilder: I });
1425
+ if (!P) return;
1426
+ const { nodeIndex: N, updatingRefIndex: E, sequenceNodes: F, offset: x } = P;
1427
+ if (n.current === we.NEED_ADD)
1428
+ if (x !== 0) {
1429
+ if (N === -1 && F.length)
1430
+ return;
1431
+ const W = R[R.length - 1], Z = F.splice(N + 1), fe = (H = W.sheetId) != null ? H : r, he = {
1432
+ range: W,
1433
+ unitId: (V = W.unitId) != null ? V : o,
1434
+ sheetName: p(fe)
1435
+ }, de = yt([he], i && fe !== r, C);
1436
+ F.push({ token: de[0], nodeType: z.REFERENCE });
1437
+ const Fe = [...F, ...Z], vt = tn(Fe);
1438
+ h(vt, Ti(F), y);
1439
+ } else {
1440
+ const W = R[R.length - 1], Z = (te = W.sheetId) != null ? te : r, fe = {
1441
+ range: W,
1442
+ unitId: (ie = W.unitId) != null ? ie : o,
1443
+ sheetName: p(Z)
1444
+ }, re = yt([fe], i && Z !== r);
1445
+ F.unshift({ token: re[0], nodeType: z.REFERENCE });
1446
+ const de = tn(F);
1447
+ h(de, re[0].length, y);
1448
+ }
1449
+ else if (n.current === we.EDIT_OTHER_SHEET_REFERENCE) {
1450
+ const W = R.pop();
1451
+ if (!W) return;
1452
+ const Z = F[N];
1453
+ if (typeof Z == "object" && Z.nodeType === z.REFERENCE) {
1454
+ const fe = Z.token;
1455
+ Z.token = C === (S == null ? void 0 : S.getName()) ? pe(W) : ht(S.getName(), W);
1456
+ const he = x + (Z.token.length - fe.length);
1457
+ h(kr(F), he, y);
1458
+ }
1459
+ } else {
1460
+ const W = [...R];
1461
+ if (E !== -1) {
1462
+ const Y = W.pop();
1463
+ Y && W.splice(E, 0, Y);
1464
+ }
1465
+ let Z = 0;
1466
+ const fe = F.map((Y) => {
1467
+ var me, ke, Oe;
1468
+ if (typeof Y == "string")
1469
+ return Y;
1470
+ if (Y.nodeType === z.REFERENCE) {
1471
+ const Me = ot(Y.token);
1472
+ if (Me.sheetName || (Me.sheetName = C), i && ((me = v.current.activeSheet) == null ? void 0 : me.getName()) !== Me.sheetName)
1473
+ return Y.token;
1474
+ const Se = W[Z];
1475
+ if (Z++, !Se)
1476
+ return "";
1477
+ const _t = (ke = Se.sheetId) != null ? ke : r, qt = {
1478
+ range: Se,
1479
+ unitId: (Oe = Se.unitId) != null ? Oe : o,
1480
+ sheetName: p(_t)
1481
+ };
1482
+ return yt([qt], i, C)[0];
1483
+ }
1484
+ return Y.token;
1485
+ });
1486
+ let he = "", re;
1487
+ fe.forEach((Y, me) => {
1488
+ he += Y, me === N && (re = he.length);
1489
+ });
1490
+ const de = [];
1491
+ for (let Y = Z; Y <= R.length - 1; Y++) {
1492
+ const me = R[Y], ke = (q = me.sheetId) != null ? q : r, Oe = {
1493
+ range: me,
1494
+ unitId: (Ye = me.unitId) != null ? Ye : o,
1495
+ sheetName: p(ke)
1496
+ }, Se = yt([Oe], i && ke !== r, C);
1497
+ de.push(Se[0]);
1498
+ }
1499
+ const Fe = F[F.length - 1], vt = Fe && (typeof Fe == "string" ? !1 : Fe.nodeType === z.REFERENCE), ze = `${he}${de.length && vt ? "," : ""}${de.join(",")}`;
1500
+ h(ze, !de.length && re ? re : ze.length, y);
1501
+ }
1502
+ });
1503
+ L(() => {
1504
+ if (T && t) {
1505
+ let R = !0;
1506
+ const y = (N, E) => {
1507
+ if (R) {
1508
+ R = !1;
1509
+ return;
1510
+ }
1511
+ M(N.map((F) => F.rangeWithCoord), E);
1512
+ }, P = new Ve();
1513
+ return P.add(T.selectionMoving$.subscribe((N) => {
1514
+ y(N, !1);
1515
+ })), P.add(T.selectionMoveEnd$.subscribe((N) => {
1516
+ y(N, !0);
1517
+ })), () => {
1518
+ P.dispose();
1519
+ };
1520
+ }
1521
+ }, [t, M, T]), L(() => {
1522
+ if (e && T && l) {
1523
+ const R = new Ve(), y = () => {
1524
+ R.dispose(), T.getSelectionControls().forEach((E, F) => {
1525
+ R.add(
1526
+ E.selectionScaling$.subscribe((x) => {
1527
+ const H = T.getSelectionDataWithStyle().map((te) => te.rangeWithCoord), V = H[F];
1528
+ x.sheetId = V.sheetId, x.unitId = V.unitId, H[F] = x, M(H, !1);
1529
+ })
1530
+ ), R.add(
1531
+ E.selectionMoving$.subscribe((x) => {
1532
+ const H = T.getSelectionDataWithStyle().map((te) => te.rangeWithCoord), V = H[F];
1533
+ x.sheetId = V.sheetId, x.unitId = V.unitId, H[F] = x, M(H, !0);
1534
+ })
1535
+ );
1536
+ });
1537
+ }, P = Kr(
1538
+ l.input$,
1539
+ A.selectionSet$,
1540
+ T.selectionMoveEnd$
1541
+ ).pipe(
1542
+ bs(50)
1543
+ ).subscribe(() => {
1544
+ y();
1545
+ });
1546
+ return () => {
1547
+ P.unsubscribe(), R.dispose();
1548
+ };
1549
+ }
1550
+ }, [l, e, M, T, A.selectionSet$]), T == null || T.getSelectionDataWithStyle(), L(() => {
1551
+ if (c) {
1552
+ const R = u.onCommandExecuted((y) => {
1553
+ var N;
1554
+ if (y.id !== an.id)
1555
+ return;
1556
+ const P = y.params;
1557
+ if (P.extra === "formula-editor" && P.selections.length) {
1558
+ const E = P.selections[P.selections.length - 1];
1559
+ if (E) {
1560
+ const F = n.current === we.NEED_ADD, x = ((N = T == null ? void 0 : T.getSelectionDataWithStyle()) != null ? N : []).map((H) => H.rangeWithCoord);
1561
+ F ? x.push(E.range) : x[x.length - 1] = E.range, M(x, !0);
1562
+ }
1563
+ }
1564
+ });
1565
+ return () => {
1566
+ R.dispose();
1567
+ };
1568
+ }
1569
+ }, [u, l, n, I, c, M, T]), L(() => {
1570
+ if (!l)
1571
+ return;
1572
+ const R = d.textSelection$.subscribe((y) => {
1573
+ y.unitId === l.getEditorId() && Do({
1574
+ unitId: o,
1575
+ subUnitId: r,
1576
+ refSelections: s.current,
1577
+ editor: l,
1578
+ refSelectionsService: A,
1579
+ refSelectionsRenderService: T,
1580
+ sheetSkeletonManagerService: w,
1581
+ themeService: a,
1582
+ univerInstanceService: m
1583
+ });
1584
+ });
1585
+ return () => R.unsubscribe();
1586
+ }, [d.textSelection$, l, s, T, A, w, r, a, o, m]);
1587
+ }, Ai = (t, e, n, o, r, s) => {
1588
+ const i = O(ae), c = O(be), h = O(Ne).getRenderById(e), f = h == null ? void 0 : h.with(De);
1589
+ L(() => {
1590
+ if (t && f)
1591
+ if (n) {
1592
+ const m = i.onCommandExecuted((u) => {
1593
+ if (u.id === Ln.id) {
1594
+ const d = f.getSelectionControls().length;
1595
+ for (let a = 1; a <= d; a++)
1596
+ f.clearLastSelection();
1597
+ setTimeout(() => {
1598
+ s();
1599
+ }, 30);
1600
+ }
1601
+ });
1602
+ return () => {
1603
+ m.dispose();
1604
+ };
1605
+ } else {
1606
+ const m = i.beforeCommandExecuted((u) => {
1607
+ if (u.id === Ln.id) {
1608
+ o(!1), r(), s();
1609
+ const d = c.getEditor(rn);
1610
+ d == null || d.focus();
1611
+ }
1612
+ });
1613
+ return () => {
1614
+ m.dispose();
1615
+ };
1616
+ }
1617
+ }, [t, f]);
1618
+ }, Pi = (t, e, n) => {
1619
+ const o = O(Ee), r = j(!0);
1620
+ L(() => {
1621
+ if (t) {
1622
+ const s = setTimeout(() => {
1623
+ r.current = !1;
1624
+ }, 500);
1625
+ return () => {
1626
+ clearTimeout(s);
1627
+ };
1628
+ }
1629
+ }, [t]), L(() => {
1630
+ if (!r.current && e) {
1631
+ const s = o.checkIfAddBracket(n);
1632
+ e(s === 0 && n.startsWith(so.EQUALS), `${n}`);
1633
+ }
1634
+ }, [n, e]);
1635
+ }, xi = "univer-sheet-embedding-formula-editor-active", wi = "univer-sheet-embedding-formula-editor-wrap", Di = "univer-sheet-embedding-formula-editor-text", Li = "univer-sheet-embedding-formula-editor-error", $i = "univer-sheet-embedding-formula-editor", ki = "univer-sheet-embedding-formula-editor-error-wrap", Qe = {
1636
+ sheetEmbeddingFormulaEditorActive: xi,
1637
+ sheetEmbeddingFormulaEditorWrap: wi,
1638
+ sheetEmbeddingFormulaEditorText: Di,
1639
+ sheetEmbeddingFormulaEditorError: Li,
1640
+ sheetEmbeddingFormulaEditor: $i,
1641
+ sheetEmbeddingFormulaEditorErrorWrap: ki
1642
+ }, Hi = (t, e = [], n) => {
1643
+ const o = O(Ht), [r, s] = $([]), [i, c] = $(""), l = j(-1), h = Ke({ nodes: e }), f = () => {
1644
+ s([]), c(""), l.current = -1;
1645
+ };
1646
+ return L(() => {
1647
+ if (n && t) {
1648
+ const u = n.input$.pipe(cn(300)).subscribe(() => {
1649
+ const d = n.getSelectionRanges();
1650
+ if (d.length === 1) {
1651
+ const a = h.current.nodes, I = d[0];
1652
+ if (I.collapsed) {
1653
+ const g = mn(a, I.startOffset - 1, !1);
1654
+ l.current = g;
1655
+ const p = a[g];
1656
+ if (p && typeof p != "string" && p.nodeType === z.FUNCTION) {
1657
+ l.current = g;
1658
+ const C = p.token, S = o.getSearchListByNameFirstLetter(C);
1659
+ s(S), c(C);
1660
+ return;
1661
+ }
1662
+ }
1663
+ }
1664
+ l.current = -1, c(""), s((a) => a != null && a.length ? [] : a);
1665
+ });
1666
+ return () => {
1667
+ u.unsubscribe();
1668
+ };
1669
+ }
1670
+ }, [n, t]), L(() => {
1671
+ t || f();
1672
+ }, [t]), {
1673
+ searchList: r,
1674
+ searchText: i,
1675
+ handlerFormulaReplace: (u) => {
1676
+ const d = [...h.current.nodes];
1677
+ if (l.current !== -1) {
1678
+ const a = d.splice(l.current + 1), I = d.pop() || "";
1679
+ let g = (typeof I == "string" ? I.length : I.token.length) - u.length;
1680
+ return d.push(u), a[0] !== nt.OPEN_BRACKET && (d.push(nt.OPEN_BRACKET), g--), { text: tn([...d, ...a]), offset: g };
1681
+ }
1682
+ },
1683
+ reset: f
1684
+ };
1685
+ }, Wi = "univer-formula-search-function", Ui = "univer-formula-search-function-item", Vi = "univer-formula-search-function-item-name", Bi = "univer-formula-search-function-item-name-light", qi = "univer-formula-search-function-item-desc", ji = "univer-formula-search-function-item-active", Pe = {
1686
+ formulaSearchFunction: Wi,
1687
+ formulaSearchFunctionItem: Ui,
1688
+ formulaSearchFunctionItemName: Vi,
1689
+ formulaSearchFunctionItemNameLight: Bi,
1690
+ formulaSearchFunctionItemDesc: qi,
1691
+ formulaSearchFunctionItemActive: ji
1692
+ }, Ki = () => {
1693
+ }, Yi = Te(zi);
1694
+ function zi(t, e) {
1695
+ const { isFocus: n, sequenceNodes: o, onSelect: r, editor: s, onClose: i = Ki } = t, c = s.getEditorId(), l = O(Ut), h = O(ae), { searchList: f, searchText: m, handlerFormulaReplace: u, reset: d } = Hi(n, o, s), a = le(() => !!f.length, [f]), I = j(void 0), [g, p] = $(0), C = j(!1), [S] = wo(c, a, [m, f]), v = Ke({ searchList: f, active: g }), _ = (R) => {
1696
+ const y = u(R);
1697
+ y && (d(), r(y));
1698
+ };
1699
+ function T(R) {
1700
+ C.current && p(R);
1701
+ }
1702
+ function w() {
1703
+ C.current && p(-1);
1704
+ }
1705
+ L(() => {
1706
+ if (!f.length)
1707
+ return;
1708
+ const R = `sheet.formula-embedding-editor.search_function.${c}`, y = new Ve(), P = (N) => {
1709
+ const { searchList: E, active: F } = v.current;
1710
+ switch (N) {
1711
+ case D.ARROW_UP: {
1712
+ p((x) => {
1713
+ const H = Math.max(0, x - 1);
1714
+ return A(H), H;
1715
+ });
1716
+ break;
1717
+ }
1718
+ case D.ARROW_DOWN: {
1719
+ p((x) => {
1720
+ const H = Math.min(E.length - 1, x + 1);
1721
+ return A(H), H;
1722
+ });
1723
+ break;
1724
+ }
1725
+ case D.TAB:
1726
+ case D.ENTER: {
1727
+ const x = E[F];
1728
+ _(x.name);
1729
+ break;
1730
+ }
1731
+ case D.ESC: {
1732
+ d(), i();
1733
+ break;
1734
+ }
1735
+ }
1736
+ };
1737
+ return y.add(h.registerCommand({
1738
+ id: R,
1739
+ type: Ie.OPERATION,
1740
+ handler(N, E) {
1741
+ const { keyCode: F } = E;
1742
+ P(F);
1743
+ }
1744
+ })), [D.ARROW_UP, D.ARROW_DOWN, D.ENTER, D.ESC, D.TAB].map((N) => ({
1745
+ id: R,
1746
+ binding: N,
1747
+ preconditions: () => !0,
1748
+ priority: 1e3,
1749
+ staticParameters: {
1750
+ eventType: ye.Keyboard,
1751
+ keyCode: N
1752
+ }
1753
+ })).forEach((N) => {
1754
+ y.add(l.registerShortcut(N));
1755
+ }), () => {
1756
+ y.dispose();
1757
+ };
1758
+ }, [f]);
1759
+ function A(R) {
1760
+ var ie;
1761
+ const y = (ie = I.current) == null ? void 0 : ie.querySelectorAll(`.${Pe.formulaSearchFunctionItem}`)[R];
1762
+ if (!y) return;
1763
+ const P = y.parentNode;
1764
+ if (!P) return;
1765
+ const E = P.getBoundingClientRect().top, F = P.offsetHeight, x = y.getBoundingClientRect(), H = x.top, V = x.height;
1766
+ if (H >= 0 && H > E && H - E + V <= F)
1767
+ return;
1768
+ const te = y.offsetTop - (F - V) / 2;
1769
+ P.scrollTo({
1770
+ top: te,
1771
+ behavior: "smooth"
1772
+ });
1773
+ }
1774
+ const M = le(() => {
1775
+ let R = "";
1776
+ return () => {
1777
+ clearTimeout(R), C.current = !0, R = setTimeout(() => {
1778
+ C.current = !1;
1779
+ }, 300);
1780
+ };
1781
+ }, []);
1782
+ return f.length > 0 && a && /* @__PURE__ */ b(So, { portal: !0, anchorRect$: S, direction: "vertical", children: /* @__PURE__ */ b(
1783
+ "ul",
1784
+ {
1785
+ className: Pe.formulaSearchFunction,
1786
+ ref: (R) => {
1787
+ I.current = R, e && (e.current = R);
1788
+ },
1789
+ children: f.map((R, y) => /* @__PURE__ */ k(
1790
+ "li",
1791
+ {
1792
+ className: g === y ? `
1793
+ ${Pe.formulaSearchFunctionItem}
1794
+ ${Pe.formulaSearchFunctionItemActive}
1795
+ ` : Pe.formulaSearchFunctionItem,
1796
+ onMouseEnter: () => T(y),
1797
+ onMouseLeave: w,
1798
+ onMouseMove: M,
1799
+ onClick: () => {
1800
+ _(R.name), s && s.focus();
1801
+ },
1802
+ children: [
1803
+ /* @__PURE__ */ k("span", { className: Pe.formulaSearchFunctionItemName, children: [
1804
+ /* @__PURE__ */ b("span", { className: Pe.formulaSearchFunctionItemNameLight, children: R.name.substring(0, m.length) }),
1805
+ /* @__PURE__ */ b("span", { children: R.name.slice(m.length) })
1806
+ ] }),
1807
+ /* @__PURE__ */ b("span", { className: Pe.formulaSearchFunctionItemDesc, children: R.desc })
1808
+ ]
1809
+ },
1810
+ R.name
1811
+ ))
1812
+ }
1813
+ ) });
1814
+ }
1815
+ const Gi = (t) => t.startsWith(so.EQUALS) ? t.slice(1) : "", Bn = () => {
1816
+ };
1817
+ function Zi(t) {
1818
+ var vn, _n;
1819
+ const {
1820
+ errorText: e,
1821
+ initValue: n,
1822
+ unitId: o,
1823
+ subUnitId: r,
1824
+ isFocus: s = !0,
1825
+ isSupportAcrossSheet: i = !1,
1826
+ onFocus: c = Bn,
1827
+ onBlur: l = Bn,
1828
+ onChange: h,
1829
+ onVerify: f,
1830
+ actions: m,
1831
+ className: u,
1832
+ editorId: d,
1833
+ moveCursor: a = !0,
1834
+ onFormulaSelectingChange: I,
1835
+ keyboradEventConfig: g,
1836
+ onMoveInEditor: p,
1837
+ resetSelectionOnBlur: C = !0,
1838
+ autoScrollbar: S = !0,
1839
+ isSingle: v = !0,
1840
+ disableSelectionOnClick: _ = !1,
1841
+ disableContextMenu: T,
1842
+ style: w
1843
+ } = t, A = O(be), M = j(null), R = ee(h);
1844
+ m && (m.handleOutClick = (X, Q) => {
1845
+ M.current && !M.current.contains(X.target) && Q();
1846
+ });
1847
+ const y = ee(I), P = j(null), N = j(void 0), E = N.current, [F, x] = $(s), H = j(null), V = le(() => d != null ? d : tr(`${Rr}-${nr(4)}`), []), te = le(() => e !== void 0, [e]), ie = O(oe), q = ie.getUnit(V);
1848
+ qe(q == null ? void 0 : q.change$);
1849
+ const Ye = vi(), W = or.transform.getPlainText((_n = (vn = q == null ? void 0 : q.getBody()) == null ? void 0 : vn.dataStream) != null ? _n : ""), Z = Ke(W), fe = le(() => Gi(W), [W]), he = le(() => Ye(fe), [fe, Ye]), { isSelecting: re, isSelectingRef: de } = Ci({ unitId: o, subUnitId: r, editorId: V, isFocus: F, disableOnClick: _ }), Fe = j(""), ze = O(Ne).getRenderById(V), Y = ze == null ? void 0 : ze.with(ao), me = Y == null ? void 0 : Y.isFocusing, ke = le(() => ie.getCurrentTypeOfUnit$(ue.UNIVER_DOC), [ie]), Oe = qe(ke), Me = (Oe == null ? void 0 : Oe.getUnitId()) === V, Se = j([]), _t = re;
1850
+ ds(() => {
1851
+ R(W);
1852
+ }, [W, R]);
1853
+ const qt = Lo("="), Sn = Ri(o, r), Ge = ee((X, Q = !0, Ce, ve) => {
1854
+ if (!N.current) return;
1855
+ Fe.current = X;
1856
+ const Rt = X[0] === "=" ? X.slice(1) : "", Ae = Ye(Rt), Yo = Ae.reduce((He, Et) => typeof Et == "object" ? `${He}${Et.token}` : `${He}${Et}`, ""), It = qt(
1857
+ N.current,
1858
+ Yo === Rt ? Ae : [],
1859
+ Q,
1860
+ ve
1861
+ );
1862
+ if (Se.current = It, Ce) {
1863
+ const He = ve != null ? ve : E == null ? void 0 : E.getSelectionRanges();
1864
+ if ((He == null ? void 0 : He.length) !== 1)
1865
+ return;
1866
+ const zo = He[0].startOffset - 1, Go = mn(Ae, zo, !1), Rn = To(Ae, Go);
1867
+ if (Rn >= 0) {
1868
+ const In = It.splice(Rn, 1)[0];
1869
+ In && It.push(In);
1870
+ }
1871
+ Sn(F ? It : [], N.current);
1872
+ }
1873
+ });
1874
+ L(() => {
1875
+ F && Ge(W, !1, !0);
1876
+ }, [F]), L(() => {
1877
+ if (F) {
1878
+ if (Fe.current === W) return;
1879
+ Ge(W, !1, !0);
1880
+ }
1881
+ }, [W]), Pi(F, f, W);
1882
+ const Ze = di(E), Cn = Ni(F, o, r);
1883
+ L(() => {
1884
+ y(re);
1885
+ }, [y, re]), Qr(F, g, E), Ot(() => {
1886
+ let X;
1887
+ if (H.current) {
1888
+ X = A.register({
1889
+ autofocus: !0,
1890
+ editorUnitId: V,
1891
+ initialSnapshot: {
1892
+ id: V,
1893
+ body: {
1894
+ dataStream: `${n}\r
1895
+ `,
1896
+ textRuns: [],
1897
+ customBlocks: [],
1898
+ customDecorations: [],
1899
+ customRanges: []
1900
+ },
1901
+ documentStyle: {}
1902
+ }
1903
+ }, H.current);
1904
+ const Q = A.getEditor(V);
1905
+ N.current = Q, Ge(n, !1, !0);
1906
+ }
1907
+ return () => {
1908
+ X == null || X.dispose();
1909
+ };
1910
+ }, []), Ot(() => {
1911
+ s ? (x(s), Ze()) : (C && (E == null || E.blur(), Cn()), x(s));
1912
+ }, [s, E, Ze, Cn, C]);
1913
+ const { checkScrollBar: Bo } = Jr(E, v, S);
1914
+ yi(F, !!(re && Me), o, T), bi(F && a, _t, E, p);
1915
+ const qo = ee((X, Q, Ce) => {
1916
+ if (!me)
1917
+ return;
1918
+ const ve = Q !== -1 ? [{ startOffset: Q + 1, endOffset: Q + 1, collapsed: !0 }] : void 0;
1919
+ Ge(`=${X}`, !0, Ce, ve), Ce && (Ze(), Q !== -1 && setTimeout(() => {
1920
+ const Rt = { startOffset: Q + 1, endOffset: Q + 1 }, Ae = E == null ? void 0 : E.render.with(es);
1921
+ Ae == null || Ae.scrollToRange({ ...Rt, collapsed: !0 });
1922
+ }, 50), Bo());
1923
+ });
1924
+ Mi(
1925
+ F && !!(re && Me),
1926
+ F,
1927
+ de,
1928
+ o,
1929
+ r,
1930
+ Se,
1931
+ i,
1932
+ !!_t,
1933
+ E,
1934
+ qo
1935
+ ), Ai(F && !!(re && Me), o, i, x, l, () => {
1936
+ Ge(Z.current, !1, !0);
1937
+ });
1938
+ const jo = (X) => {
1939
+ if (X) {
1940
+ const Q = E == null ? void 0 : E.getSelectionRanges();
1941
+ if (Q && Q.length === 1) {
1942
+ const Ce = Q[0];
1943
+ if (Ce.collapsed) {
1944
+ const ve = X.offset;
1945
+ setTimeout(() => {
1946
+ E == null || E.setSelectionRanges([{ startOffset: Ce.startOffset - ve, endOffset: Ce.endOffset - ve }]);
1947
+ }, 30);
1948
+ }
1949
+ }
1950
+ Ze(), Ge(`=${X.text}`);
1951
+ }
1952
+ }, Ko = () => {
1953
+ x(!0), c(), Ze();
1954
+ };
1955
+ return /* @__PURE__ */ k("div", { style: w, className: Hn(Qe.sheetEmbeddingFormulaEditor, u), children: [
1956
+ /* @__PURE__ */ b(
1957
+ "div",
1958
+ {
1959
+ className: Hn(Qe.sheetEmbeddingFormulaEditorWrap, {
1960
+ [Qe.sheetEmbeddingFormulaEditorActive]: F,
1961
+ [Qe.sheetEmbeddingFormulaEditorError]: te
1962
+ }),
1963
+ ref: M,
1964
+ children: /* @__PURE__ */ b(
1965
+ "div",
1966
+ {
1967
+ className: Qe.sheetEmbeddingFormulaEditorText,
1968
+ ref: H,
1969
+ onMouseUp: Ko
1970
+ }
1971
+ )
1972
+ }
1973
+ ),
1974
+ e !== void 0 ? /* @__PURE__ */ b("div", { className: Qe.sheetEmbeddingFormulaEditorErrorWrap, children: e }) : null,
1975
+ E ? /* @__PURE__ */ b(
1976
+ hi,
1977
+ {
1978
+ editor: E,
1979
+ isFocus: F,
1980
+ formulaText: W,
1981
+ onClose: () => Ze()
1982
+ }
1983
+ ) : null,
1984
+ E ? /* @__PURE__ */ b(
1985
+ Yi,
1986
+ {
1987
+ isFocus: F,
1988
+ sequenceNodes: he,
1989
+ onSelect: jo,
1990
+ ref: P,
1991
+ editor: E
1992
+ }
1993
+ ) : null
1994
+ ] });
1995
+ }
1996
+ function Xi(t, e, n, o) {
1997
+ const r = O(Ee), s = Lo(""), i = qe(t == null ? void 0 : t.getDocumentDataModel().change$), [c, l] = $([]), h = O(Ir), f = j(""), m = O(oe);
1998
+ return L(() => {
1999
+ if (!t) return;
2000
+ const u = t.getDocumentDataModel().getPlainText();
2001
+ if (f.current === u)
2002
+ return;
2003
+ f.current = u;
2004
+ const d = r.sequenceNodesBuilder(u);
2005
+ l(d != null ? d : []);
2006
+ }, [i, t, r]), L(() => {
2007
+ var a, I;
2008
+ if (!t) return;
2009
+ if (!e) {
2010
+ const g = t.getDocumentData();
2011
+ t.setDocumentData({
2012
+ ...g,
2013
+ body: {
2014
+ ...g.body,
2015
+ dataStream: (I = (a = g.body) == null ? void 0 : a.dataStream) != null ? I : "",
2016
+ textRuns: []
2017
+ }
2018
+ });
2019
+ return;
2020
+ }
2021
+ const u = s(t, c, !1), d = new Ve();
2022
+ return u.forEach((g) => {
2023
+ const p = ot(g.token), C = m.getCurrentUnitForType(ue.UNIVER_SHEET), S = C == null ? void 0 : C.getActiveSheet();
2024
+ if (!p.sheetName && o !== (S == null ? void 0 : S.getSheetId()) || p.sheetName && (S == null ? void 0 : S.getName()) !== p.sheetName)
2025
+ return;
2026
+ const v = new sn(g.themeColor).toRgb(), _ = h.addShape({
2027
+ range: p.range,
2028
+ style: {
2029
+ stroke: g.themeColor,
2030
+ fill: `rgba(${v.r}, ${v.g}, ${v.b}, 0.1)`,
2031
+ strokeDash: 12
2032
+ },
2033
+ primary: null
2034
+ });
2035
+ _ && d.add(() => h.removeShape(_));
2036
+ }), () => {
2037
+ d.dispose();
2038
+ };
2039
+ }, [t, e, s, h, c]), { sequenceNodes: c };
2040
+ }
2041
+ function Qi(t) {
2042
+ const e = O(ln), { supportAcrossSheet: n = !1, unitId: o, subUnitId: r, onChange: s } = t, c = O(oe).getUnit(o, ue.UNIVER_SHEET), l = ee(s), h = ee((f, m) => {
2043
+ const u = c == null ? void 0 : c.getActiveSheet();
2044
+ if (!u || !n && u.getSheetId() !== r || !(f != null && f.length)) return;
2045
+ const d = f.map((a) => ({
2046
+ range: a.range,
2047
+ unitId: o,
2048
+ sheetName: u.getSheetId() === r ? "" : u.getName()
2049
+ }));
2050
+ l(d, m);
2051
+ });
2052
+ L(() => {
2053
+ const f = new Ve();
2054
+ return f.add(e.selectionMoveStart$.subscribe((m) => {
2055
+ h(m, !0);
2056
+ })), f.add(e.selectionMoving$.subscribe((m) => {
2057
+ h(m, !1);
2058
+ })), f.add(e.selectionMoveEnd$.subscribe((m) => {
2059
+ h(m, !1);
2060
+ })), () => {
2061
+ f.dispose();
2062
+ };
2063
+ }, [h, e.selectionMoveEnd$, e.selectionMoveStart$, e.selectionMoving$]);
2064
+ }
2065
+ const Ji = "univer-sheet-range-selector-icon", ec = "univer-sheet-range-selector-dialog", tc = "univer-sheet-range-selector-dialog-item", nc = "univer-sheet-range-selector-dialog-item-delete", Tt = {
2066
+ sheetRangeSelectorIcon: Ji,
2067
+ sheetRangeSelectorDialog: ec,
2068
+ sheetRangeSelectorDialogItem: tc,
2069
+ sheetRangeSelectorDialogItemDelete: nc
2070
+ }, qn = (t) => !t.some((n) => {
2071
+ if (typeof n == "string") {
2072
+ if (n !== nt.COMMA)
2073
+ return !0;
2074
+ } else if (n.nodeType !== z.REFERENCE)
2075
+ return !0;
2076
+ return !1;
2077
+ }), oc = (t) => {
2078
+ if (t.endColumn < t.startColumn) {
2079
+ const e = t.endColumn;
2080
+ t.endColumn = t.startColumn, t.startColumn = e;
2081
+ }
2082
+ if (t.endRow < t.startRow) {
2083
+ const e = t.endRow;
2084
+ t.endRow = t.startRow, t.startRow = e;
2085
+ }
2086
+ return t;
2087
+ };
2088
+ function rc(t) {
2089
+ const { visible: e, initialValue: n, unitId: o, subUnitId: r, maxRangeCount: s = 1 / 0, supportAcrossSheet: i, onConfirm: c, onClose: l, onShowBySelection: h } = t, f = O(je), m = O(Ee), [u, d] = $([]), [a, I] = $(0), g = j(null);
2090
+ L(() => {
2091
+ if (e && n.length) {
2092
+ const v = n.map((_) => _.sheetName ? ht(_.sheetName, _.range) : pe(_.range));
2093
+ d(v), I(v.length - 1);
2094
+ } else
2095
+ d([""]), I(0);
2096
+ }, [e]);
2097
+ const p = (v, _) => {
2098
+ const T = [...u];
2099
+ T[v] = _, d(T);
2100
+ }, C = () => {
2101
+ d([...u, ""]), I(u.length);
2102
+ }, S = (v) => {
2103
+ u.splice(v, 1), d([...u]);
2104
+ };
2105
+ return Qi({
2106
+ unitId: o,
2107
+ subUnitId: r,
2108
+ supportAcrossSheet: i,
2109
+ onChange: (v, _) => {
2110
+ if (!e && h != null && h(v))
2111
+ return;
2112
+ const T = new Set(u), w = v.map((R) => R.sheetName ? ht(R.sheetName, R.range) : pe(R.range)), A = w.filter((R) => !T.has(R));
2113
+ if (!A.length) return;
2114
+ const M = [...u];
2115
+ if (w.length > 1) {
2116
+ _ || M.splice(a, 1), M.push(...A);
2117
+ const R = M.slice(0, s);
2118
+ d(R), I(R.length - 1), requestAnimationFrame(() => {
2119
+ var y;
2120
+ (y = g.current) == null || y.scrollTo({ top: g.current.scrollHeight });
2121
+ });
2122
+ } else {
2123
+ M.splice(a, 1, ...A);
2124
+ const R = M.slice(0, s);
2125
+ d(R), I(a + A.length - 1);
2126
+ }
2127
+ }
2128
+ }), /* @__PURE__ */ b(
2129
+ Is,
2130
+ {
2131
+ width: "328px",
2132
+ visible: e,
2133
+ title: f.t("rangeSelector.title"),
2134
+ draggable: !0,
2135
+ closeIcon: /* @__PURE__ */ b(Vt, {}),
2136
+ footer: /* @__PURE__ */ k("footer", { children: [
2137
+ /* @__PURE__ */ b(et, { onClick: l, children: f.t("rangeSelector.cancel") }),
2138
+ /* @__PURE__ */ b(
2139
+ et,
2140
+ {
2141
+ style: { marginLeft: 10 },
2142
+ onClick: () => {
2143
+ c(
2144
+ u.filter((v) => {
2145
+ const _ = m.sequenceNodesBuilder(v);
2146
+ return _ && _.length === 1 && typeof _[0] != "string" && _[0].nodeType === z.REFERENCE;
2147
+ }).map((v) => ot(v)).map((v) => ({ ...v, range: oc(v.range) }))
2148
+ );
2149
+ },
2150
+ type: "primary",
2151
+ children: f.t("rangeSelector.confirm")
2152
+ }
2153
+ )
2154
+ ] }),
2155
+ onClose: l,
2156
+ children: /* @__PURE__ */ k("div", { ref: g, className: Tt.sheetRangeSelectorDialog, children: [
2157
+ u.map((v, _) => /* @__PURE__ */ k("div", { className: Tt.sheetRangeSelectorDialogItem, children: [
2158
+ /* @__PURE__ */ b(
2159
+ Ro,
2160
+ {
2161
+ affixWrapperStyle: { width: "100%" },
2162
+ placeholder: f.t("rangeSelector.placeHolder"),
2163
+ onFocus: () => I(_),
2164
+ value: v,
2165
+ onChange: (T) => p(_, T),
2166
+ style: { borderColor: a === _ ? "rgb(var(--primary-color))" : void 0 }
2167
+ }
2168
+ ),
2169
+ u.length > 1 && /* @__PURE__ */ b(Mo, { className: Tt.sheetRangeSelectorDialogItemDelete, onClick: () => S(_) })
2170
+ ] }, _)),
2171
+ u.length < s && /* @__PURE__ */ b("div", { children: /* @__PURE__ */ k(et, { type: "link", size: "small", onClick: C, children: [
2172
+ /* @__PURE__ */ b(Po, {}),
2173
+ /* @__PURE__ */ b("span", { children: f.t("rangeSelector.addAnotherRange") })
2174
+ ] }) })
2175
+ ] })
2176
+ }
2177
+ );
2178
+ }
2179
+ function sc(t) {
2180
+ return t.split(nt.COMMA).filter((e) => !!e).map((e) => ot(e));
2181
+ }
2182
+ function ic(t) {
2183
+ return t.map((e) => e.sheetName ? ht(e.sheetName, e.range) : pe(e.range)).join(nt.COMMA);
2184
+ }
2185
+ function $o(t) {
2186
+ const [e, n] = $(null), {
2187
+ onVerify: o,
2188
+ selectorRef: r,
2189
+ unitId: s,
2190
+ subUnitId: i,
2191
+ maxRangeCount: c,
2192
+ supportAcrossSheet: l,
2193
+ autoFocus: h,
2194
+ onChange: f,
2195
+ onRangeSelectorDialogVisibleChange: m,
2196
+ onClickOutside: u,
2197
+ onFocusChange: d,
2198
+ forceShowDialogWhenSelectionChanged: a,
2199
+ hideEditor: I,
2200
+ resetRange: g
2201
+ } = t, [p, C] = $(h != null ? h : !1), [S, v] = $(!1), [_, T] = $([]), w = O(je), A = O(be), { sequenceNodes: M } = Xi(e, p, s, i), R = Ke(M), y = O(ae), P = ee(() => {
2202
+ e == null || e.setSelectionRanges([]), e == null || e.blur(), A.blur();
2203
+ }), N = ee(() => {
2204
+ var E;
2205
+ P(), T(sc((E = e == null ? void 0 : e.getDocumentDataModel().getPlainText()) != null ? E : "")), v(!0);
2206
+ });
2207
+ return L(() => {
2208
+ r && (r.current = {
2209
+ get editor() {
2210
+ return e;
2211
+ },
2212
+ focus() {
2213
+ A.focus(e.getEditorId());
2214
+ },
2215
+ blur: P,
2216
+ verify: () => qn(R.current),
2217
+ showDialog: (E) => {
2218
+ P(), T(E), v(!0);
2219
+ },
2220
+ hideDialog: () => {
2221
+ T([]), v(!1);
2222
+ },
2223
+ getValue: () => {
2224
+ var E;
2225
+ return (E = e == null ? void 0 : e.getDocumentDataModel().getPlainText()) != null ? E : "";
2226
+ }
2227
+ });
2228
+ }, [P, e, A, r, R]), L(() => {
2229
+ var E;
2230
+ o == null || o(qn(M), (E = e == null ? void 0 : e.getDocumentDataModel().getPlainText()) != null ? E : "");
2231
+ }, [M]), L(() => {
2232
+ m == null || m(S);
2233
+ }, [S]), L(() => {
2234
+ if (S && g)
2235
+ return () => {
2236
+ const E = {
2237
+ unitId: s,
2238
+ subUnitId: i,
2239
+ selections: g
2240
+ };
2241
+ y.executeCommand(an.id, E);
2242
+ };
2243
+ }, [S]), /* @__PURE__ */ k(ut, { children: [
2244
+ I ? null : /* @__PURE__ */ b(
2245
+ ts,
2246
+ {
2247
+ isSingle: !0,
2248
+ ...t,
2249
+ onFocusChange: (E, F) => {
2250
+ C(E), d == null || d(E, F);
2251
+ },
2252
+ editorRef: n,
2253
+ onClickOutside: () => {
2254
+ C(!1), P(), u == null || u();
2255
+ },
2256
+ icon: /* @__PURE__ */ b(Rs, { title: w.t("rangeSelector.buttonTooltip"), placement: "bottom", children: /* @__PURE__ */ b(xo, { className: Tt.sheetRangeSelectorIcon, onClick: N }) })
2257
+ }
2258
+ ),
2259
+ /* @__PURE__ */ b(
2260
+ rc,
2261
+ {
2262
+ initialValue: _,
2263
+ unitId: s,
2264
+ subUnitId: i,
2265
+ visible: S,
2266
+ maxRangeCount: c,
2267
+ onConfirm: (E) => {
2268
+ const F = ic(E), x = rr.newEmptyData();
2269
+ x.body.dataStream = F, e == null || e.replaceText(F, !1), f == null || f(x, F), v(!1), T([]), requestAnimationFrame(() => {
2270
+ P();
2271
+ });
2272
+ },
2273
+ onClose: () => {
2274
+ v(!1), T([]);
2275
+ },
2276
+ supportAcrossSheet: l,
2277
+ onShowBySelection: (E) => p || a ? (T(E), v(!0), !1) : !0
2278
+ }
2279
+ )
2280
+ ] });
2281
+ }
2282
+ class ko {
2283
+ constructor() {
2284
+ B(this, "_currentSelector$", new io(null));
2285
+ B(this, "currentSelector$", this._currentSelector$.asObservable());
2286
+ }
2287
+ showRangeSelectorDialog(e) {
2288
+ const n = e.callback, o = new Promise((r) => {
2289
+ e.callback = (s) => {
2290
+ r(s), n(s);
2291
+ };
2292
+ });
2293
+ return this._currentSelector$.next(e), o;
2294
+ }
2295
+ }
2296
+ const cc = "sheets-formula-ui.base.config", jn = {};
2297
+ function lc(t) {
2298
+ return t.getContextValue(sr) && t.getContextValue(ir);
2299
+ }
2300
+ function Ho(t, e = !1) {
2301
+ return !e && !(Re(t == null ? void 0 : t.f) || Be(t == null ? void 0 : t.si)) ? null : typeof (t == null ? void 0 : t.v) == "string" && Hr.has(t.v) ? t.v : null;
2302
+ }
2303
+ var ac = Object.getOwnPropertyDescriptor, uc = (t, e, n, o) => {
2304
+ for (var r = o > 1 ? void 0 : o ? ac(e, n) : e, s = t.length - 1, i; s >= 0; s--)
2305
+ (i = t[s]) && (r = i(r) || r);
2306
+ return r;
2307
+ }, it = (t, e) => (n, o) => e(n, o, t);
2308
+ const zt = "SHEET_FORMULA_ALERT", fc = {
2309
+ [se.DIV_BY_ZERO]: "divByZero",
2310
+ [se.NAME]: "name",
2311
+ [se.VALUE]: "value",
2312
+ [se.NUM]: "num",
2313
+ [se.NA]: "na",
2314
+ [se.CYCLE]: "cycle",
2315
+ [se.REF]: "ref",
2316
+ [se.SPILL]: "spill",
2317
+ [se.CALC]: "calc",
2318
+ [se.ERROR]: "error",
2319
+ [se.CONNECT]: "connect",
2320
+ [se.NULL]: "null"
2321
+ };
2322
+ let nn = class extends pt {
2323
+ constructor(t, e, n, o, r, s) {
2324
+ super(), this._context = t, this._hoverManagerService = e, this._cellAlertManagerService = n, this._localeService = o, this._formulaDataModel = r, this._zenZoneService = s, this._init();
2325
+ }
2326
+ _init() {
2327
+ this._initCellAlertPopup(), this._initZenService();
2328
+ }
2329
+ _initCellAlertPopup() {
2330
+ this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(cn(100)).subscribe((t) => {
2331
+ var e, n, o, r, s;
2332
+ if (t) {
2333
+ const c = this._context.unit.getActiveSheet();
2334
+ if (!c) return;
2335
+ const l = c.getCell(t.location.row, t.location.col), h = (r = (o = (n = (e = this._formulaDataModel.getArrayFormulaCellData()) == null ? void 0 : e[t.location.unitId]) == null ? void 0 : n[t.location.subUnitId]) == null ? void 0 : o[t.location.row]) == null ? void 0 : r[t.location.col];
2336
+ if (cr(l)) {
2337
+ const f = Ho(l, !!h);
2338
+ if (!f) {
2339
+ this._hideAlert();
2340
+ return;
2341
+ }
2342
+ const m = this._cellAlertManagerService.currentAlert.get(zt), u = (s = m == null ? void 0 : m.alert) == null ? void 0 : s.location;
2343
+ if (u && u.row === t.location.row && u.col === t.location.col && u.subUnitId === t.location.subUnitId && u.unitId === t.location.unitId)
2344
+ return;
2345
+ this._cellAlertManagerService.showAlert({
2346
+ type: yr.ERROR,
2347
+ title: this._localeService.t("formula.error.title"),
2348
+ message: this._localeService.t(`formula.error.${fc[f]}`),
2349
+ location: t.location,
2350
+ width: 200,
2351
+ height: 74,
2352
+ key: zt
2353
+ });
2354
+ return;
2355
+ }
2356
+ }
2357
+ this._hideAlert();
2358
+ }));
2359
+ }
2360
+ _initZenService() {
2361
+ this.disposeWithMe(this._zenZoneService.visible$.subscribe((t) => {
2362
+ t && this._hideAlert();
2363
+ }));
2364
+ }
2365
+ _hideAlert() {
2366
+ this._cellAlertManagerService.removeAlert(zt);
2367
+ }
2368
+ };
2369
+ nn = uc([
2370
+ it(1, K(Er)),
2371
+ it(2, K(br)),
2372
+ it(3, K(je)),
2373
+ it(4, K($t)),
2374
+ it(5, ms)
2375
+ ], nn);
2376
+ var hc = Object.getOwnPropertyDescriptor, dc = (t, e, n, o) => {
2377
+ for (var r = o > 1 ? void 0 : o ? hc(e, n) : e, s = t.length - 1, i; s >= 0; s--)
2378
+ (i = t[s]) && (r = i(r) || r);
2379
+ return r;
2380
+ }, Kn = (t, e) => (n, o) => e(n, o, t);
2381
+ let Mt = class extends pt {
2382
+ constructor(t, e) {
2383
+ super(), this._autoFillService = t, this._lexerTreeBuilder = e, this._registerAutoFill();
2384
+ }
2385
+ _registerAutoFill() {
2386
+ const t = {
2387
+ type: Mn.FORMULA,
2388
+ priority: 1001,
2389
+ match: (e) => Re(e == null ? void 0 : e.f) || Be(e == null ? void 0 : e.si),
2390
+ isContinue: (e, n) => e.type === Mn.FORMULA,
2391
+ applyFunctions: {
2392
+ [Tr.COPY]: (e, n, o, r, s) => {
2393
+ const { data: i, index: c } = e;
2394
+ return this._fillCopyFormula(i, n, o, c, r, s);
2395
+ }
2396
+ }
2397
+ };
2398
+ this._autoFillService.registerRule(t);
2399
+ }
2400
+ _fillCopyFormula(t, e, n, o, r, s) {
2401
+ var h, f;
2402
+ const i = gc(r), c = [], l = /* @__PURE__ */ new Map();
2403
+ for (let m = 1; m <= e; m++) {
2404
+ const u = (m - 1) % t.length, d = o[u], a = ft.deepClone(t[u]);
2405
+ if (a) {
2406
+ const I = ((h = t[u]) == null ? void 0 : h.f) || "", g = ((f = t[u]) == null ? void 0 : f.si) || "", p = Re(I);
2407
+ if (Be(g))
2408
+ a.si = g, a.f = null, a.v = null, a.p = null, a.t = null, c.push(a);
2409
+ else if (p) {
2410
+ let S = l.get(u);
2411
+ if (S)
2412
+ a.si = S, a.f = null, a.v = null, a.p = null, a.t = null;
2413
+ else {
2414
+ S = ft.generateRandomId(6), l.set(u, S);
2415
+ const { offsetX: v, offsetY: _ } = mc(i, e, n, s, d), T = this._lexerTreeBuilder.moveFormulaRefOffset(
2416
+ I,
2417
+ v,
2418
+ _
2419
+ );
2420
+ a.si = S, a.f = T, a.v = null, a.p = null, a.t = null;
2421
+ }
2422
+ c.push(a);
2423
+ }
2424
+ }
2425
+ }
2426
+ return c;
2427
+ }
2428
+ };
2429
+ Mt = dc([
2430
+ Kn(0, Nr),
2431
+ Kn(1, K(Ee))
2432
+ ], Mt);
2433
+ function mc(t, e, n, o, r) {
2434
+ const { source: s, target: i } = o, { rows: c } = i, { rows: l } = s;
2435
+ let h = 0, f = 0;
2436
+ switch (n) {
2437
+ case ne.UP:
2438
+ f = c[r] - l[r];
2439
+ break;
2440
+ case ne.RIGHT:
2441
+ h = t;
2442
+ break;
2443
+ case ne.DOWN:
2444
+ f = c[r] - l[r];
2445
+ break;
2446
+ case ne.LEFT:
2447
+ h = -t * e;
2448
+ break;
2449
+ }
2450
+ return { offsetX: h, offsetY: f };
2451
+ }
2452
+ function gc(t) {
2453
+ let e = 0;
2454
+ for (const n in t)
2455
+ t[n].forEach((o) => {
2456
+ e += o.data.length;
2457
+ });
2458
+ return e;
2459
+ }
2460
+ var pc = Object.getOwnPropertyDescriptor, Sc = (t, e, n, o) => {
2461
+ for (var r = o > 1 ? void 0 : o ? pc(e, n) : e, s = t.length - 1, i; s >= 0; s--)
2462
+ (i = t[s]) && (r = i(r) || r);
2463
+ return r;
2464
+ }, ct = (t, e) => (n, o) => e(n, o, t);
2465
+ const Cc = "default-paste-formula";
2466
+ let At = class extends pt {
2467
+ constructor(t, e, n, o, r) {
2468
+ super(), this._currentUniverSheet = t, this._lexerTreeBuilder = e, this._sheetClipboardService = n, this._injector = o, this._formulaDataModel = r, this._initialize();
2469
+ }
2470
+ _initialize() {
2471
+ this._registerClipboardHook();
2472
+ }
2473
+ _registerClipboardHook() {
2474
+ this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())), this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()));
2475
+ }
2476
+ _pasteFormulaHook() {
2477
+ return {
2478
+ id: Je.SPECIAL_PASTE_FORMULA,
2479
+ priority: 10,
2480
+ specialPasteInfo: { label: "specialPaste.formula" },
2481
+ onPasteCells: (t, e, n, o) => this._onPasteCells(t, e, n, o, !0)
2482
+ };
2483
+ }
2484
+ _pasteWithFormulaHook() {
2485
+ return {
2486
+ id: Cc,
2487
+ priority: 10,
2488
+ onPasteCells: (t, e, n, o) => this._onPasteCells(t, e, n, o, !1)
2489
+ };
2490
+ }
2491
+ _onPasteCells(t, e, n, o, r) {
2492
+ var u;
2493
+ if ([
2494
+ Je.SPECIAL_PASTE_FORMAT,
2495
+ Je.SPECIAL_PASTE_COL_WIDTH
2496
+ ].includes(o.pasteType))
2497
+ return {
2498
+ undos: [],
2499
+ redos: []
2500
+ };
2501
+ const i = this._currentUniverSheet.getCurrentUnitForType(ue.UNIVER_SHEET), c = e.unitId || i.getUnitId(), l = e.subUnitId || ((u = i.getActiveSheet()) == null ? void 0 : u.getSheetId());
2502
+ if (!c || !l)
2503
+ return {
2504
+ undos: [],
2505
+ redos: []
2506
+ };
2507
+ const h = e.range, f = n, m = {
2508
+ copyType: o.copyType || oo.COPY,
2509
+ copyRange: t == null ? void 0 : t.range,
2510
+ pasteType: o.pasteType
2511
+ };
2512
+ return this._injector.invoke((d) => vc(
2513
+ c,
2514
+ l,
2515
+ h,
2516
+ f,
2517
+ d,
2518
+ m,
2519
+ this._lexerTreeBuilder,
2520
+ this._formulaDataModel,
2521
+ r,
2522
+ t
2523
+ ));
2524
+ }
2525
+ };
2526
+ At = Sc([
2527
+ ct(0, oe),
2528
+ ct(1, K(Ee)),
2529
+ ct(2, Fr),
2530
+ ct(3, K(mt)),
2531
+ ct(4, K($t))
2532
+ ], At);
2533
+ function vc(t, e, n, o, r, s, i, c, l = !1, h) {
2534
+ const f = [], m = [], u = _c(t, e, n, o, s, i, c, h);
2535
+ if (!u.hasValue())
2536
+ return {
2537
+ undos: [],
2538
+ redos: []
2539
+ };
2540
+ const d = {
2541
+ unitId: t,
2542
+ subUnitId: e,
2543
+ cellValue: u.getData()
2544
+ };
2545
+ f.push({
2546
+ id: $n.id,
2547
+ params: d
2548
+ });
2549
+ const a = ss(
2550
+ r,
2551
+ d
2552
+ );
2553
+ return m.push({
2554
+ id: $n.id,
2555
+ params: a
2556
+ }), {
2557
+ undos: m,
2558
+ redos: f
2559
+ };
2560
+ }
2561
+ function _c(t, e, n, o, r, s, i, c) {
2562
+ return c ? r.pasteType === Je.SPECIAL_PASTE_VALUE ? Ic(t, e, n, o, i, c) : r.pasteType === Je.SPECIAL_PASTE_FORMULA ? Ec(t, e, n, o, s, i, c) : bc(t, e, n, o, r.copyType, s, i, c) : Rc(t, e, n, o, i);
2563
+ }
2564
+ function Rc(t, e, n, o, r) {
2565
+ const s = new tt(), i = r.getSheetFormulaData(t, e);
2566
+ return o.forValue((c, l, h) => {
2567
+ var d;
2568
+ const f = n.rows[c], m = n.cols[l], u = {};
2569
+ Re(h.v) ? (u.v = null, u.f = `${h.v}`, u.si = null, u.p = null, s.setValue(f, m, u)) : (d = i == null ? void 0 : i[f]) != null && d[m] && (u.v = h.v, u.f = null, u.si = null, u.p = null, s.setValue(f, m, u));
2570
+ }), s;
2571
+ }
2572
+ function Ic(t, e, n, o, r, s) {
2573
+ var h, f;
2574
+ const i = new tt(), c = (f = (h = r.getArrayFormulaCellData()) == null ? void 0 : h[s.unitId]) == null ? void 0 : f[s.subUnitId], l = r.getSheetFormulaData(t, e);
2575
+ return o.forValue((m, u, d) => {
2576
+ var S, v;
2577
+ const a = s.range.rows[m % s.range.rows.length], I = s.range.cols[u % s.range.cols.length], g = n.rows[m], p = n.cols[u], C = {};
2578
+ if (Re(d.f) || Be(d.si))
2579
+ C.v = d.v, C.f = null, C.si = null, C.p = null, i.setValue(g, p, C);
2580
+ else if ((S = c == null ? void 0 : c[a]) != null && S[I]) {
2581
+ const _ = c[a][I];
2582
+ C.v = _.v, C.f = null, C.si = null, C.p = null, i.setValue(g, p, C);
2583
+ } else if ((v = l == null ? void 0 : l[g]) != null && v[p]) {
2584
+ if (C.v = d.v, C.f = null, C.si = null, C.p = null, d.p) {
2585
+ const _ = Wo(d);
2586
+ _ && (C.v = _);
2587
+ }
2588
+ i.setValue(g, p, C);
2589
+ }
2590
+ }), i;
2591
+ }
2592
+ function Ec(t, e, n, o, r, s, i) {
2593
+ const c = new tt(), l = /* @__PURE__ */ new Map();
2594
+ return o.forValue((h, f, m) => {
2595
+ const u = n.rows[h], d = n.cols[f], a = {};
2596
+ if (Be(m.si)) {
2597
+ if (i.unitId !== t || i.subUnitId !== e) {
2598
+ const I = s.getFormulaStringByCell(
2599
+ i.range.rows[h % i.range.rows.length],
2600
+ i.range.cols[f % i.range.cols.length],
2601
+ i.subUnitId,
2602
+ i.unitId
2603
+ ), g = n.cols[f] - i.range.cols[f % i.range.cols.length], p = n.rows[h] - i.range.rows[h % i.range.rows.length], C = r.moveFormulaRefOffset(I || "", g, p);
2604
+ a.si = null, a.f = C;
2605
+ } else
2606
+ a.si = m.si, a.f = null;
2607
+ a.v = null, a.p = null, c.setValue(u, d, a);
2608
+ } else if (Re(m.f)) {
2609
+ const I = `${h % i.range.rows.length}_${f % i.range.cols.length}`;
2610
+ let g = l.get(I);
2611
+ if (g)
2612
+ a.si = g, a.f = null;
2613
+ else {
2614
+ g = ft.generateRandomId(6), l.set(I, g);
2615
+ const p = n.cols[f] - i.range.cols[f % i.range.cols.length], C = n.rows[h] - i.range.rows[h % i.range.rows.length], S = r.moveFormulaRefOffset(m.f || "", p, C);
2616
+ a.si = g, a.f = S;
2617
+ }
2618
+ a.v = null, a.p = null, c.setValue(u, d, a);
2619
+ } else {
2620
+ if (a.v = m.v, a.f = null, a.si = null, a.p = null, m.p) {
2621
+ const I = Wo(m);
2622
+ I && (a.v = I);
2623
+ }
2624
+ c.setValue(u, d, a);
2625
+ }
2626
+ }), c;
2627
+ }
2628
+ function bc(t, e, n, o, r, s, i, c) {
2629
+ const l = new tt(), h = /* @__PURE__ */ new Map(), f = i.getSheetFormulaData(t, e), m = [];
2630
+ return r === oo.CUT ? o.forValue((u, d, a) => {
2631
+ const I = n.rows[u], g = n.cols[d], p = {};
2632
+ if (Be(a.si)) {
2633
+ if (Re(a.f))
2634
+ m.push(a.si), p.f = a.f, p.si = a.si;
2635
+ else if (m.includes(a.si))
2636
+ p.f = null, p.si = a.si;
2637
+ else {
2638
+ const C = i.getFormulaStringByCell(
2639
+ c.range.rows[u % c.range.rows.length],
2640
+ c.range.cols[d % c.range.cols.length],
2641
+ c.subUnitId,
2642
+ c.unitId
2643
+ );
2644
+ p.f = C, p.si = null;
2645
+ }
2646
+ p.v = null, p.p = null, l.setValue(I, g, p);
2647
+ } else Re(a.f) && (p.f = a.f, p.si = null, p.v = null, p.p = null, l.setValue(I, g, p));
2648
+ }) : o.forValue((u, d, a) => {
2649
+ var C;
2650
+ const I = n.rows[u], g = n.cols[d], p = {};
2651
+ if (Be(a.si)) {
2652
+ if (c.unitId !== t || c.subUnitId !== e) {
2653
+ const S = i.getFormulaStringByCell(
2654
+ c.range.rows[u % c.range.rows.length],
2655
+ c.range.cols[d % c.range.cols.length],
2656
+ c.subUnitId,
2657
+ c.unitId
2658
+ ), v = n.cols[d] - c.range.cols[d % c.range.cols.length], _ = n.rows[u] - c.range.rows[u % c.range.rows.length], T = s.moveFormulaRefOffset(S || "", v, _);
2659
+ p.si = null, p.f = T;
2660
+ } else
2661
+ p.si = a.si, p.f = null;
2662
+ p.v = null, p.p = null, l.setValue(I, g, p);
2663
+ } else if (Re(a.f)) {
2664
+ const S = `${u % c.range.rows.length}_${d % c.range.cols.length}`;
2665
+ let v = h.get(S);
2666
+ if (v)
2667
+ p.si = v, p.f = null;
2668
+ else {
2669
+ v = ft.generateRandomId(6), h.set(S, v);
2670
+ const _ = n.cols[d] - c.range.cols[d % c.range.cols.length], T = n.rows[u] - c.range.rows[u % c.range.rows.length], w = s.moveFormulaRefOffset(a.f || "", _, T);
2671
+ p.si = v, p.f = w;
2672
+ }
2673
+ p.v = null, p.p = null, l.setValue(I, g, p);
2674
+ } else (C = f == null ? void 0 : f[I]) != null && C[g] && (p.v = a.v, p.f = null, p.si = null, p.p = a.p, l.setValue(I, g, p));
2675
+ }), m.length > 0 && new tt(f).forValue((u, d, a) => {
2676
+ if (!(c.range.rows.includes(u) && c.range.cols.includes(d)) && !(n.rows.includes(u) && n.cols.includes(d)) && m.includes(a == null ? void 0 : a.si)) {
2677
+ const I = i.getFormulaStringByCell(
2678
+ u,
2679
+ d,
2680
+ c.subUnitId,
2681
+ c.unitId
2682
+ );
2683
+ l.setValue(u, d, {
2684
+ f: I,
2685
+ si: null,
2686
+ v: null,
2687
+ p: null
2688
+ });
2689
+ }
2690
+ }), l;
2691
+ }
2692
+ function Wo(t) {
2693
+ if (t != null && t.p) {
2694
+ const e = t == null ? void 0 : t.p.body;
2695
+ if (e == null)
2696
+ return;
2697
+ const n = e.dataStream;
2698
+ return n.substring(n.length - 2, n.length) === Xn ? n.substring(0, n.length - 2) : n;
2699
+ }
2700
+ }
2701
+ var yc = Object.getOwnPropertyDescriptor, Nc = (t, e, n, o) => {
2702
+ for (var r = o > 1 ? void 0 : o ? yc(e, n) : e, s = t.length - 1, i; s >= 0; s--)
2703
+ (i = t[s]) && (r = i(r) || r);
2704
+ return r;
2705
+ }, We = (t, e) => (n, o) => e(n, o, t);
2706
+ let Pt = class extends pt {
2707
+ constructor(e, n, o, r, s, i, c, l) {
2708
+ super();
2709
+ B(this, "_previousShape");
2710
+ B(this, "_skeleton");
2711
+ this._context = e, this._sheetInterceptorService = n, this._formulaDataModel = o, this._themeService = r, this._renderManagerService = s, this._sheetSkeletonManagerService = i, this._commandService = c, this._logService = l, this._initSkeletonChangeListener(), this._initInterceptorEditorStart(), this._commandExecutedListener();
2712
+ }
2713
+ _initSkeletonChangeListener() {
2714
+ this.disposeWithMe(
2715
+ this._sheetSkeletonManagerService.currentSkeleton$.subscribe((e) => {
2716
+ var n, o;
2717
+ if (e == null)
2718
+ this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");
2719
+ else {
2720
+ const { skeleton: r } = e, s = (o = (n = this._skeleton) == null ? void 0 : n.worksheet) == null ? void 0 : o.getSheetId();
2721
+ if (this._changeRuntime(r), s !== r.worksheet.getSheetId())
2722
+ this._removeArrayFormulaRangeShape();
2723
+ else {
2724
+ const { unitId: i, sheetId: c } = e;
2725
+ this._updateArrayFormulaRangeShape(i, c);
2726
+ }
2727
+ }
2728
+ })
2729
+ );
2730
+ }
2731
+ _changeRuntime(e) {
2732
+ this._skeleton = e;
2733
+ }
2734
+ _initInterceptorEditorStart() {
2735
+ this.disposeWithMe(
2736
+ Qn(
2737
+ this._sheetInterceptorService.writeCellInterceptor.intercept(is, {
2738
+ handler: (e, n, o) => {
2739
+ var a, I, g, p;
2740
+ const { row: r, col: s, unitId: i, subUnitId: c, worksheet: l } = n, h = this._formulaDataModel.getArrayFormulaRange(), f = this._formulaDataModel.getArrayFormulaCellData();
2741
+ if (this._removeArrayFormulaRangeShape(), e == null)
2742
+ return o(e);
2743
+ let m = null;
2744
+ const u = this._formulaDataModel.getFormulaStringByCell(r, s, c, i);
2745
+ if (u !== null && (m = { f: u }), e.v != null && e.v !== "" && ((g = (I = (a = f[i]) == null ? void 0 : a[c]) == null ? void 0 : I[r]) == null ? void 0 : g[s]) == null)
2746
+ return m ? { ...e, ...m } : o(e);
2747
+ const d = (p = h == null ? void 0 : h[i]) == null ? void 0 : p[c];
2748
+ return d != null && (m = this._displayArrayFormulaRangeShape(d, r, s, i, c, l, m)), m ? { ...e, ...m } : o(e);
2749
+ }
2750
+ })
2751
+ )
2752
+ );
2753
+ }
2754
+ _commandExecutedListener() {
2755
+ this.disposeWithMe(this._commandService.onCommandExecuted((e, n) => {
2756
+ (e.id === Wr.id || e.id === Ur.id && n && n.remove) && this._removeArrayFormulaRangeShape();
2757
+ })), this.disposeWithMe(
2758
+ this._commandService.beforeCommandExecuted((e) => {
2759
+ cs.id === e.id && requestIdleCallback(() => {
2760
+ const n = e.params, { unitId: o, subUnitId: r, rowsAutoHeightInfo: s } = n;
2761
+ this._refreshArrayFormulaRangeShapeByRow(o, r, s);
2762
+ });
2763
+ })
2764
+ );
2765
+ }
2766
+ _displayArrayFormulaRangeShape(e, n, o, r, s, i, c) {
2767
+ const l = this._formulaDataModel.getSheetFormulaData(r, s);
2768
+ return new tt(e).forValue((h, f, m) => {
2769
+ var g;
2770
+ if (m == null)
2771
+ return !0;
2772
+ const { startRow: u, startColumn: d, endRow: a, endColumn: I } = m;
2773
+ if (h === n && f === o)
2774
+ return this._createArrayFormulaRangeShape(m, r), !1;
2775
+ if (n >= u && n <= a && o >= d && o <= I) {
2776
+ const p = i.getCell(u, d);
2777
+ if ((p == null ? void 0 : p.v) === se.SPILL)
2778
+ return;
2779
+ const C = (g = l == null ? void 0 : l[h]) == null ? void 0 : g[f];
2780
+ return C == null || C.f == null ? !0 : (c == null && (c = {
2781
+ f: C.f,
2782
+ isInArrayFormulaRange: !0
2783
+ }), this._createArrayFormulaRangeShape(m, r), !1);
2784
+ }
2785
+ }), c;
2786
+ }
2787
+ _createArrayFormulaRangeShape(e, n) {
2788
+ const o = this._renderManagerService.getRenderById(n), r = this._sheetSkeletonManagerService.getCurrentSkeleton();
2789
+ if (!o || !r) return;
2790
+ const { scene: s } = o;
2791
+ if (!s) return;
2792
+ const i = this._themeService.getCurrentTheme(), c = {
2793
+ range: e,
2794
+ primary: null,
2795
+ style: {
2796
+ strokeWidth: 1,
2797
+ stroke: i.hyacinth700,
2798
+ fill: new sn(i.colorWhite).setAlpha(0).toString(),
2799
+ widgets: {}
2800
+ }
2801
+ }, l = Xt(c, r), { rowHeaderWidth: h, columnHeaderHeight: f } = r, m = new no(s, Or.FORMULA_EDITOR_SHOW, this._themeService, {
2802
+ highlightHeader: !1,
2803
+ rowHeaderWidth: h,
2804
+ columnHeaderHeight: f
2805
+ });
2806
+ m.updateRangeBySelectionWithCoord(l), m.setEvent(!1), this._previousShape = m;
2807
+ }
2808
+ _removeArrayFormulaRangeShape() {
2809
+ this._previousShape != null && (this._previousShape.dispose(), this._previousShape = null);
2810
+ }
2811
+ _refreshArrayFormulaRangeShape(e, n) {
2812
+ if (this._previousShape) {
2813
+ const { startRow: o, endRow: r, startColumn: s, endColumn: i } = this._previousShape.getRange(), c = { startRow: o, endRow: r, startColumn: s, endColumn: i };
2814
+ this._removeArrayFormulaRangeShape(), this._createArrayFormulaRangeShape(c, e);
2815
+ }
2816
+ }
2817
+ _checkCurrentSheet(e, n) {
2818
+ const o = this._sheetSkeletonManagerService.getCurrentSkeleton();
2819
+ if (!o) return !1;
2820
+ const r = o.worksheet;
2821
+ return r ? r.unitId === e && r.getSheetId() === n : !1;
2822
+ }
2823
+ _updateArrayFormulaRangeShape(e, n) {
2824
+ this._checkCurrentSheet(e, n) && this._previousShape && this._refreshArrayFormulaRangeShape(e);
2825
+ }
2826
+ _refreshArrayFormulaRangeShapeByRow(e, n, o) {
2827
+ if (!this._checkCurrentSheet(e, n) || !this._previousShape) return;
2828
+ const { startRow: r, endRow: s, startColumn: i, endColumn: c } = this._previousShape.getRange();
2829
+ for (let l = 0; l < o.length; l++) {
2830
+ const { row: h } = o[l];
2831
+ if (r >= h) {
2832
+ const f = {
2833
+ startRow: r,
2834
+ endRow: s,
2835
+ startColumn: i,
2836
+ endColumn: c
2837
+ };
2838
+ this._refreshArrayFormulaRangeShape(e, f);
2839
+ break;
2840
+ }
2841
+ }
2842
+ }
2843
+ };
2844
+ Pt = Nc([
2845
+ We(1, K(fo)),
2846
+ We(2, K($t)),
2847
+ We(3, K(gt)),
2848
+ We(4, Ne),
2849
+ We(5, K(Lt)),
2850
+ We(6, ae),
2851
+ We(7, lr)
2852
+ ], Pt);
2853
+ var Tc = Object.getOwnPropertyDescriptor, Fc = (t, e, n, o) => {
2854
+ for (var r = o > 1 ? void 0 : o ? Tc(e, n) : e, s = t.length - 1, i; s >= 0; s--)
2855
+ (i = t[s]) && (r = i(r) || r);
2856
+ return r;
2857
+ }, Yn = (t, e) => (n, o) => e(n, o, t);
2858
+ const Oc = {
2859
+ tl: {
2860
+ size: 6,
2861
+ color: "#409f11"
2862
+ }
2863
+ };
2864
+ let xt = class extends ar {
2865
+ constructor(t, e) {
2866
+ super(), this._sheetInterceptorService = t, this._formulaDataModel = e, this.disposeWithMe(this._sheetInterceptorService.intercept(
2867
+ ls.CELL_CONTENT,
2868
+ {
2869
+ effect: ur.Style,
2870
+ handler: (n, o, r) => {
2871
+ var c, l, h, f;
2872
+ const s = (f = (h = (l = (c = this._formulaDataModel.getArrayFormulaCellData()) == null ? void 0 : c[o.unitId]) == null ? void 0 : l[o.subUnitId]) == null ? void 0 : h[o.row]) == null ? void 0 : f[o.col];
2873
+ return Ho(n, !!s) ? r({
2874
+ ...n,
2875
+ markers: {
2876
+ ...n == null ? void 0 : n.markers,
2877
+ ...Oc
2878
+ }
2879
+ }) : r(n);
2880
+ },
2881
+ priority: 10
2882
+ }
2883
+ ));
2884
+ }
2885
+ };
2886
+ xt = Fc([
2887
+ Yn(0, K(fo)),
2888
+ Yn(1, K($t))
2889
+ ], xt);
2890
+ function Mc() {
2891
+ const t = O(us), e = O(ae), n = qe(t.progress$), o = Ft(() => {
2892
+ e.executeCommand(Vr.id);
2893
+ }, [e]), r = Ft(() => {
2894
+ t.clearProgress();
2895
+ }, [t]);
2896
+ return /* @__PURE__ */ b(gs, { progress: n, onTerminate: o, onClearProgress: r });
2897
+ }
2898
+ const Ac = (t, e = 100) => {
2899
+ L(() => {
2900
+ let n = null;
2901
+ const o = () => {
2902
+ n === null && (n = window.setTimeout(() => {
2903
+ t(), n = null;
2904
+ }, e));
2905
+ };
2906
+ return window.addEventListener("scroll", o), window.addEventListener("resize", o), () => {
2907
+ n !== null && clearTimeout(n), window.removeEventListener("scroll", o), window.removeEventListener("resize", o);
2908
+ };
2909
+ }, [t, e]);
2910
+ }, Pc = "univer-formula-help-function", xc = "univer-formula-help-function-title", wc = "univer-formula-help-function-title-icons", Dc = "univer-formula-help-function-title-icon", Lc = "univer-formula-help-function-content", $c = "univer-formula-help-function-content-inner", kc = "univer-formula-help-function-content-params", Hc = "univer-formula-help-function-content-params-title", Wc = "univer-formula-help-function-content-params-detail", Uc = "univer-formula-help-function-active", Vc = "univer-formula-help-decorator", Bc = "univer-formula-help-param", qc = "univer-formula-help-param-prefix", jc = "univer-formula-help-param-item", Kc = "univer-formula-help-param-active", G = {
2911
+ formulaHelpFunction: Pc,
2912
+ formulaHelpFunctionTitle: xc,
2913
+ formulaHelpFunctionTitleIcons: wc,
2914
+ formulaHelpFunctionTitleIcon: Dc,
2915
+ formulaHelpFunctionContent: Lc,
2916
+ formulaHelpFunctionContentInner: $c,
2917
+ formulaHelpFunctionContentParams: kc,
2918
+ formulaHelpFunctionContentParamsTitle: Hc,
2919
+ formulaHelpFunctionContentParamsDetail: Wc,
2920
+ formulaHelpFunctionActive: Uc,
2921
+ formulaHelpDecorator: Vc,
2922
+ formulaHelpParam: Bc,
2923
+ formulaHelpParamPrefix: qc,
2924
+ formulaHelpParamItem: jc,
2925
+ formulaHelpParamActive: Kc
2926
+ };
2927
+ function Yc() {
2928
+ const [t, e] = $(!1), [n, o] = $(!0), [r, s] = $(!0), [i, c] = $(0), [l, h] = $([0, 0]), [f, m] = $({ left: 0, top: 0 }), [u, d] = $(null), a = O(Ct), I = O(je), g = I.t("formula.prompt.required"), p = I.t("formula.prompt.optional"), C = O(oe), S = O(be), v = O(Wt), _ = ps();
2929
+ Ac(T), L(() => {
2930
+ const R = a.help$.subscribe((P) => {
2931
+ const { visible: N, paramIndex: E, functionInfo: F } = P;
2932
+ if (!N) {
2933
+ e(N);
2934
+ return;
2935
+ }
2936
+ const x = w();
2937
+ if (x == null)
2938
+ return;
2939
+ const { left: H, top: V, height: te } = x;
2940
+ F.description === "" && F.functionParameter.length === 0 || (h([H, V + te]), c(E), d(F), m({ left: H, top: V }), e(N));
2941
+ }), y = v.scrollEvent$.pipe(co(100)).subscribe(T);
2942
+ return () => {
2943
+ R == null || R.unsubscribe(), y.unsubscribe();
2944
+ };
2945
+ }, []);
2946
+ function T() {
2947
+ if (!r)
2948
+ return;
2949
+ const R = w();
2950
+ if (R == null)
2951
+ return;
2952
+ const { left: y, top: P, height: N } = R;
2953
+ h([y, P + N]);
2954
+ }
2955
+ function w() {
2956
+ const R = C.getCurrentUniverDocInstance();
2957
+ if (!R)
2958
+ return;
2959
+ const y = R.getUnitId();
2960
+ if (!S.isEditor(y))
2961
+ return;
2962
+ const P = S.getEditor(y);
2963
+ return P == null ? void 0 : P.getBoundingClientRect();
2964
+ }
2965
+ function A(R) {
2966
+ c(R);
2967
+ }
2968
+ function M() {
2969
+ s(!r), _.get(Ss).focus();
2970
+ }
2971
+ return /* @__PURE__ */ b(ut, { children: r ? /* @__PURE__ */ b(Io, { visible: t, offset: l, children: u ? /* @__PURE__ */ k("div", { className: G.formulaHelpFunction, children: [
2972
+ /* @__PURE__ */ k("div", { className: G.formulaHelpFunctionTitle, children: [
2973
+ /* @__PURE__ */ b(
2974
+ zc,
2975
+ {
2976
+ prefix: u.functionName,
2977
+ value: u.functionParameter,
2978
+ active: i,
2979
+ onClick: A
2980
+ }
2981
+ ),
2982
+ /* @__PURE__ */ k("div", { className: G.formulaHelpFunctionTitleIcons, children: [
2983
+ /* @__PURE__ */ b(
2984
+ "div",
2985
+ {
2986
+ className: G.formulaHelpFunctionTitleIcon,
2987
+ style: { transform: n ? "rotateZ(-90deg)" : "rotateZ(90deg)" },
2988
+ onClick: () => o(!n),
2989
+ children: /* @__PURE__ */ b(gn, {})
2990
+ }
2991
+ ),
2992
+ /* @__PURE__ */ b(
2993
+ "div",
2994
+ {
2995
+ className: G.formulaHelpFunctionTitleIcon,
2996
+ onClick: M,
2997
+ children: /* @__PURE__ */ b(Vt, {})
2998
+ }
2999
+ )
3000
+ ] })
3001
+ ] }),
3002
+ /* @__PURE__ */ b(
3003
+ "div",
3004
+ {
3005
+ className: G.formulaHelpFunctionContent,
3006
+ style: {
3007
+ height: n ? "unset" : 0,
3008
+ padding: n ? "revert-layer" : 0
3009
+ },
3010
+ children: /* @__PURE__ */ k("div", { className: G.formulaHelpFunctionContentInner, children: [
3011
+ /* @__PURE__ */ b(
3012
+ Gt,
3013
+ {
3014
+ title: I.t("formula.prompt.helpExample"),
3015
+ value: `${u.functionName}(${u.functionParameter.map((R) => R.example).join(",")})`
3016
+ }
3017
+ ),
3018
+ /* @__PURE__ */ b(
3019
+ Gt,
3020
+ {
3021
+ title: I.t("formula.prompt.helpAbstract"),
3022
+ value: u.description
3023
+ }
3024
+ ),
3025
+ u && u.functionParameter && u.functionParameter.map((R, y) => /* @__PURE__ */ b(
3026
+ Gt,
3027
+ {
3028
+ className: i === y ? G.formulaHelpFunctionActive : "",
3029
+ title: R.name,
3030
+ value: `${R.require ? g : p} ${R.detail}`
3031
+ },
3032
+ y
3033
+ ))
3034
+ ] })
3035
+ }
3036
+ )
3037
+ ] }) : /* @__PURE__ */ b(ut, {}) }) : t ? /* @__PURE__ */ b(
3038
+ "div",
3039
+ {
3040
+ className: G.formulaHelpDecorator,
3041
+ onClick: () => s(!r),
3042
+ style: { left: f.left - 24, top: f.top },
3043
+ children: /* @__PURE__ */ b(Ao, {})
3044
+ }
3045
+ ) : /* @__PURE__ */ b(ut, {}) });
3046
+ }
3047
+ const Gt = (t) => /* @__PURE__ */ k("div", { className: G.formulaHelpFunctionContentParams, children: [
3048
+ /* @__PURE__ */ b(
3049
+ "div",
3050
+ {
3051
+ className: `
3052
+ ${G.formulaHelpFunctionContentParamsTitle}
3053
+ ${t.className}
3054
+ `,
3055
+ children: t.title
3056
+ }
3057
+ ),
3058
+ /* @__PURE__ */ b("div", { className: G.formulaHelpFunctionContentParamsDetail, children: t.value })
3059
+ ] }), zc = (t) => {
3060
+ const { prefix: e, value: n, active: o, onClick: r } = t;
3061
+ return /* @__PURE__ */ k("div", { className: G.formulaHelpParam, children: [
3062
+ /* @__PURE__ */ k("span", { className: G.formulaHelpParamPrefix, children: [
3063
+ e,
3064
+ "("
3065
+ ] }),
3066
+ n && n.map((s, i) => (
3067
+ // TODO@Dushusir: more params needs to be active
3068
+ /* @__PURE__ */ k("span", { className: G.formulaHelpParamItem, children: [
3069
+ /* @__PURE__ */ b(
3070
+ "span",
3071
+ {
3072
+ className: o === i ? G.formulaHelpFunctionActive : G.formulaHelpParamActive,
3073
+ onClick: () => r(i),
3074
+ children: pn(s)
3075
+ }
3076
+ ),
3077
+ i === n.length - 1 ? "" : ","
3078
+ ] }, i)
3079
+ )),
3080
+ ")"
3081
+ ] });
3082
+ }, Gc = "univer-formula-search-function", Zc = "univer-formula-search-function-item", Xc = "univer-formula-search-function-item-name", Qc = "univer-formula-search-function-item-name-light", Jc = "univer-formula-search-function-item-desc", el = "univer-formula-search-function-item-active", xe = {
3083
+ formulaSearchFunction: Gc,
3084
+ formulaSearchFunctionItem: Zc,
3085
+ formulaSearchFunctionItemName: Xc,
3086
+ formulaSearchFunctionItemNameLight: Qc,
3087
+ formulaSearchFunctionItemDesc: Jc,
3088
+ formulaSearchFunctionItemActive: el
3089
+ };
3090
+ function tl() {
3091
+ const [t, e] = $(!1), [n, o] = $(0), [r, s] = $([0, 0]), [i, c] = $([]), [l, h] = $(""), f = j(null), m = O(Ct), u = O(oe), d = O(be);
3092
+ L(() => {
3093
+ let C = [], S = 0;
3094
+ const v = m.search$.subscribe((w) => {
3095
+ const { visible: A, searchText: M, searchList: R } = w;
3096
+ if (!A) {
3097
+ e(A);
3098
+ return;
3099
+ }
3100
+ const y = a();
3101
+ if (y == null)
3102
+ return;
3103
+ const { left: P, top: N, height: E } = y;
3104
+ h(M), c(R), C = R, s([P, N + E]), e(A), o(0), S = 0;
3105
+ }), _ = m.navigate$.subscribe((w) => {
3106
+ const { direction: A } = w;
3107
+ if (A === ne.UP) {
3108
+ let M = S - 1;
3109
+ M = M < 0 ? C.length - 1 : M, o(M), S = M;
3110
+ } else if (A === ne.DOWN) {
3111
+ let M = S + 1;
3112
+ M = M >= C.length ? 0 : M, o(M), S = M;
3113
+ }
3114
+ p(S);
3115
+ }), T = m.accept$.subscribe((w) => {
3116
+ const A = C[S].name;
3117
+ m.acceptFormulaName(A);
3118
+ });
3119
+ return () => {
3120
+ v == null || v.unsubscribe(), _ == null || _.unsubscribe(), T == null || T.unsubscribe();
3121
+ };
3122
+ }, []);
3123
+ function a() {
3124
+ const S = u.getCurrentUniverDocInstance().getUnitId();
3125
+ if (!d.isEditor(S))
3126
+ return;
3127
+ const v = d.getEditor(S);
3128
+ return v == null ? void 0 : v.getBoundingClientRect();
3129
+ }
3130
+ function I(C) {
3131
+ o(C);
3132
+ }
3133
+ function g() {
3134
+ o(-1);
3135
+ }
3136
+ function p(C) {
3137
+ var P;
3138
+ const S = (P = f.current) == null ? void 0 : P.querySelectorAll(`.${xe.formulaSearchFunctionItem}`)[C];
3139
+ if (!S) return;
3140
+ const v = S.parentNode;
3141
+ if (!v) return;
3142
+ const T = v.getBoundingClientRect().top, w = v.offsetHeight, A = S.getBoundingClientRect(), M = A.top, R = A.height;
3143
+ if (M >= 0 && M > T && M - T + R <= w)
3144
+ return;
3145
+ const y = S.offsetTop - (w - R) / 2;
3146
+ v.scrollTo({
3147
+ top: y,
3148
+ behavior: "smooth"
3149
+ });
3150
+ }
3151
+ return i.length > 0 && /* @__PURE__ */ b(Io, { visible: t, offset: r, children: /* @__PURE__ */ b("ul", { className: xe.formulaSearchFunction, ref: f, children: i.map((C, S) => /* @__PURE__ */ k(
3152
+ "li",
3153
+ {
3154
+ className: n === S ? `
3155
+ ${xe.formulaSearchFunctionItem}
3156
+ ${xe.formulaSearchFunctionItemActive}
3157
+ ` : xe.formulaSearchFunctionItem,
3158
+ onMouseEnter: () => I(S),
3159
+ onMouseLeave: g,
3160
+ onClick: () => m.acceptFormulaName(C.name),
3161
+ children: [
3162
+ /* @__PURE__ */ k("span", { className: xe.formulaSearchFunctionItemName, children: [
3163
+ /* @__PURE__ */ b("span", { className: xe.formulaSearchFunctionItemNameLight, children: C.name.substring(0, l.length) }),
3164
+ /* @__PURE__ */ b("span", { children: C.name.slice(l.length) })
3165
+ ] }),
3166
+ /* @__PURE__ */ b("span", { className: xe.formulaSearchFunctionItemDesc, children: C.desc })
3167
+ ]
3168
+ },
3169
+ S
3170
+ )) }) });
3171
+ }
3172
+ function nl() {
3173
+ return /* @__PURE__ */ k(ut, { children: [
3174
+ /* @__PURE__ */ b(tl, {}),
3175
+ /* @__PURE__ */ b(Yc, {})
3176
+ ] });
3177
+ }
3178
+ const ol = "univer-formula-more-functions", rl = "univer-formula-more-functions-operation", zn = {
3179
+ formulaMoreFunctions: ol,
3180
+ formulaMoreFunctionsOperation: rl
3181
+ };
3182
+ function Uo(t) {
3183
+ const { prefix: e, value: n } = t;
3184
+ return /* @__PURE__ */ k("div", { children: [
3185
+ /* @__PURE__ */ k("span", { children: [
3186
+ e,
3187
+ "("
3188
+ ] }),
3189
+ n && n.map((o, r) => /* @__PURE__ */ k("span", { children: [
3190
+ /* @__PURE__ */ b("span", { children: pn(o) }),
3191
+ r === n.length - 1 ? "" : ","
3192
+ ] }, r)),
3193
+ ")"
3194
+ ] });
3195
+ }
3196
+ const sl = "univer-formula-function-params", il = "univer-formula-function-params-title", cl = "univer-formula-function-params-detail", Zt = {
3197
+ formulaFunctionParams: sl,
3198
+ formulaFunctionParamsTitle: il,
3199
+ formulaFunctionParamsDetail: cl
3200
+ };
3201
+ function at(t) {
3202
+ const { className: e, value: n, title: o } = t;
3203
+ return /* @__PURE__ */ k("div", { className: Zt.formulaFunctionParams, children: [
3204
+ /* @__PURE__ */ b(
3205
+ "div",
3206
+ {
3207
+ className: `
3208
+ ${Zt.formulaFunctionParamsTitle}
3209
+ ${e}
3210
+ `,
3211
+ children: o
3212
+ }
3213
+ ),
3214
+ /* @__PURE__ */ b("div", { className: Zt.formulaFunctionParamsDetail, children: n })
3215
+ ] });
3216
+ }
3217
+ const ll = "univer-formula-input-params-list", al = "univer-formula-input-params-list-item-name", ul = "univer-formula-input-params-list-item-selector", lt = {
3218
+ formulaInputParamsList: ll,
3219
+ formulaInputParamsListItemName: al,
3220
+ formulaInputParamsListItemSelector: ul
3221
+ };
3222
+ function fl(t) {
3223
+ const { functionInfo: e, onChange: n } = t;
3224
+ if (!e) return null;
3225
+ const [o, r] = $([]), [s, i] = $(e.functionParameter), [c, l] = $(-1);
3226
+ return /* @__PURE__ */ k("div", { className: lt.formulaInputParams, children: [
3227
+ /* @__PURE__ */ b("div", { className: lt.formulaInputParamsList, children: s.map((h, f) => /* @__PURE__ */ k("div", { children: [
3228
+ /* @__PURE__ */ b("div", { className: lt.formulaInputParamsListItemName, children: h.name }),
3229
+ /* @__PURE__ */ b("div", { className: lt.formulaInputParamsListItemSelector })
3230
+ ] }, f)) }),
3231
+ /* @__PURE__ */ b("div", { className: lt.formulaInputParamsInfo, children: /* @__PURE__ */ b(
3232
+ at,
3233
+ {
3234
+ title: c === -1 ? /* @__PURE__ */ b(Uo, { prefix: e.functionName, value: s }) : s[c].name,
3235
+ value: c === -1 ? e.description : s[c].detail
3236
+ }
3237
+ ) })
3238
+ ] });
3239
+ }
3240
+ const hl = "univer-formula-select-function-select", dl = "univer-formula-select-function-result", ml = "univer-formula-select-function-result-item", gl = "univer-formula-select-function-result-item-name-light", pl = "univer-formula-select-function-result-item-selected", Sl = "univer-formula-select-function-result-item-active", Cl = "univer-formula-select-function-content", _e = {
3241
+ formulaSelectFunctionSelect: hl,
3242
+ formulaSelectFunctionResult: dl,
3243
+ formulaSelectFunctionResultItem: ml,
3244
+ formulaSelectFunctionResultItemNameLight: gl,
3245
+ formulaSelectFunctionResultItemSelected: pl,
3246
+ formulaSelectFunctionResultItemActive: Sl,
3247
+ formulaSelectFunctionContent: Cl
3248
+ };
3249
+ function vl(t) {
3250
+ const { onChange: e } = t, n = "-1", [o, r] = $(""), [s, i] = $([]), [c, l] = $(0), [h, f] = $(n), [m, u] = $(0), [d, a] = $(null), I = O(Ht), g = O(je), p = O(Wt), C = qe(p.sidebarOptions$), S = zs(Br, g);
3251
+ S.unshift({
3252
+ label: g.t("formula.moreFunctions.allFunctions"),
3253
+ value: n
3254
+ });
3255
+ const v = g.t("formula.prompt.required"), _ = g.t("formula.prompt.optional");
3256
+ L(() => {
3257
+ A(n);
3258
+ }, []), L(() => {
3259
+ w(0);
3260
+ }, [s]), L(() => {
3261
+ C != null && C.visible && (r(""), i([]), l(0), f(n), u(0), a(null), A(n));
3262
+ }, [C]);
3263
+ const T = (N) => {
3264
+ if (o.trim() === "") return N;
3265
+ const E = new RegExp(`(${o.toLocaleUpperCase()})`);
3266
+ return N.split(E).filter(Boolean).map((x, H) => x.match(E) ? /* @__PURE__ */ b("span", { className: _e.formulaSelectFunctionResultItemNameLight, children: x }, H) : x);
3267
+ }, w = (N) => {
3268
+ if (s.length === 0) {
3269
+ a(null);
3270
+ return;
3271
+ }
3272
+ u(N);
3273
+ const E = I.getFunctionInfo(s[N].name);
3274
+ if (!E) {
3275
+ a(null);
3276
+ return;
3277
+ }
3278
+ a(E), e(E);
3279
+ };
3280
+ function A(N) {
3281
+ f(N);
3282
+ const E = I.getSearchListByType(+N);
3283
+ i(E);
3284
+ }
3285
+ function M(N) {
3286
+ r(N);
3287
+ const E = I.getSearchListByName(N);
3288
+ i(E);
3289
+ }
3290
+ function R(N) {
3291
+ if (N.stopPropagation(), N.key === "ArrowDown") {
3292
+ const E = c + 1;
3293
+ l(E === s.length ? 0 : E);
3294
+ } else if (N.key === "ArrowUp") {
3295
+ const E = c - 1;
3296
+ l(E === -1 ? s.length - 1 : E);
3297
+ } else N.key === "Enter" && w(c);
3298
+ }
3299
+ const y = (N) => {
3300
+ l(N);
3301
+ }, P = () => {
3302
+ l(-1);
3303
+ };
3304
+ return /* @__PURE__ */ k("div", { children: [
3305
+ /* @__PURE__ */ k("div", { className: _e.formulaSelectFunctionSelect, children: [
3306
+ /* @__PURE__ */ b(Es, { value: h, options: S, onChange: A }),
3307
+ /* @__PURE__ */ b(
3308
+ Ro,
3309
+ {
3310
+ placeholder: g.t("formula.moreFunctions.searchFunctionPlaceholder"),
3311
+ onKeyDown: R,
3312
+ value: o,
3313
+ onChange: M,
3314
+ size: "small",
3315
+ allowClear: !0
3316
+ }
3317
+ )
3318
+ ] }),
3319
+ /* @__PURE__ */ b("ul", { className: _e.formulaSelectFunctionResult, onKeyDown: R, tabIndex: -1, children: s.map(({ name: N }, E) => /* @__PURE__ */ k(
3320
+ "li",
3321
+ {
3322
+ className: c === E ? `
3323
+ ${_e.formulaSelectFunctionResultItem}
3324
+ ${_e.formulaSelectFunctionResultItemActive}
3325
+ ` : _e.formulaSelectFunctionResultItem,
3326
+ onMouseEnter: () => y(E),
3327
+ onMouseLeave: P,
3328
+ onClick: () => w(E),
3329
+ children: [
3330
+ m === E && /* @__PURE__ */ b(Oo, { className: _e.formulaSelectFunctionResultItemSelected }),
3331
+ /* @__PURE__ */ b("span", { className: _e.formulaSelectFunctionResultItemName, children: T(N) })
3332
+ ]
3333
+ },
3334
+ E
3335
+ )) }),
3336
+ d && /* @__PURE__ */ k("div", { className: _e.formulaSelectFunctionContent, children: [
3337
+ /* @__PURE__ */ b(at, { title: d.functionName, value: d.description }),
3338
+ /* @__PURE__ */ b(
3339
+ at,
3340
+ {
3341
+ title: g.t("formula.moreFunctions.syntax"),
3342
+ value: /* @__PURE__ */ b(Uo, { prefix: d.functionName, value: d.functionParameter })
3343
+ }
3344
+ ),
3345
+ /* @__PURE__ */ b(
3346
+ at,
3347
+ {
3348
+ title: g.t("formula.prompt.helpExample"),
3349
+ value: `${d.functionName}(${d.functionParameter.map((N) => N.example).join(",")})`
3350
+ }
3351
+ ),
3352
+ d.functionParameter && d.functionParameter.map((N) => /* @__PURE__ */ b(
3353
+ at,
3354
+ {
3355
+ title: N.name,
3356
+ value: `${N.require ? v : _} ${N.detail}`
3357
+ },
3358
+ N.name
3359
+ ))
3360
+ ] })
3361
+ ] });
3362
+ }
3363
+ function _l() {
3364
+ const t = Mr(), [e, n] = $(!0), [o, r] = $(!1), [s, i] = $(null);
3365
+ O(Jn);
3366
+ const c = O(je), l = O(be), h = O(oe), f = O(ae);
3367
+ function m() {
3368
+ n(!e), r(!o);
3369
+ }
3370
+ function u() {
3371
+ const d = uo(h);
3372
+ if (!d) return;
3373
+ f.executeCommand(eo.id, {
3374
+ visible: !0,
3375
+ unitId: d.unitId,
3376
+ eventType: ye.Dblclick
3377
+ });
3378
+ const a = l.getEditor(rn), I = l.getEditor(Zn), g = `=${s == null ? void 0 : s.functionName}(`;
3379
+ a == null || a.replaceText(g), I == null || I.replaceText(g, !1);
3380
+ }
3381
+ return /* @__PURE__ */ k("div", { className: zn.formulaMoreFunctions, children: [
3382
+ e && /* @__PURE__ */ b(vl, { onChange: i }),
3383
+ o && /* @__PURE__ */ b(fl, { functionInfo: s, onChange: () => {
3384
+ } }),
3385
+ /* @__PURE__ */ k("div", { className: zn.formulaMoreFunctionsOperation, children: [
3386
+ o && /* @__PURE__ */ b(et, { type: "primary", size: "small", onClick: m, children: c.t("formula.moreFunctions.next") }),
3387
+ o && /* @__PURE__ */ b(et, { size: "small", onClick: m, children: c.t("formula.moreFunctions.prev") }),
3388
+ e && !!t && /* @__PURE__ */ b(et, { type: "primary", size: "small", onClick: u, children: c.t("formula.moreFunctions.confirm") })
3389
+ ] })
3390
+ ] });
3391
+ }
3392
+ function Rl(t) {
3393
+ return {
3394
+ id: hn.id,
3395
+ icon: "FunctionSingle",
3396
+ tooltip: "formula.insert.tooltip",
3397
+ type: un.SELECTOR,
3398
+ selections: [
3399
+ {
3400
+ label: {
3401
+ name: "SUM",
3402
+ selectable: !1
3403
+ },
3404
+ value: "SUM",
3405
+ icon: "SumSingle"
3406
+ },
3407
+ {
3408
+ label: {
3409
+ name: "AVERAGE",
3410
+ selectable: !1
3411
+ },
3412
+ value: "AVERAGE",
3413
+ icon: "AvgSingle"
3414
+ },
3415
+ {
3416
+ label: {
3417
+ name: "COUNT",
3418
+ selectable: !1
3419
+ },
3420
+ value: "COUNT",
3421
+ icon: "CntSingle"
3422
+ },
3423
+ {
3424
+ label: {
3425
+ name: "MAX",
3426
+ selectable: !1
3427
+ },
3428
+ value: "MAX",
3429
+ icon: "MaxSingle"
3430
+ },
3431
+ {
3432
+ label: {
3433
+ name: "MIN",
3434
+ selectable: !1
3435
+ },
3436
+ value: "MIN",
3437
+ icon: "MinSingle"
3438
+ }
3439
+ ],
3440
+ hidden$: Cs(t, ue.UNIVER_SHEET),
3441
+ disabled$: ro(t, { workbookTypes: [po], worksheetTypes: [mo, ho], rangeTypes: [go] })
3442
+ };
3443
+ }
3444
+ function Il(t) {
3445
+ return {
3446
+ id: dn.id,
3447
+ title: "formula.insert.more",
3448
+ type: un.BUTTON
3449
+ };
3450
+ }
3451
+ function El(t) {
3452
+ return t.get(oe).getCurrentTypeOfUnit$(ue.UNIVER_SHEET).pipe(
3453
+ zr((o) => o ? t.get(kn) ? new Gr((s) => s.next(!t.get(kn).supportClipboard)) : An(!0) : An(!0))
3454
+ );
3455
+ }
3456
+ function bl(t) {
3457
+ return {
3458
+ id: fn.id,
3459
+ type: un.BUTTON,
3460
+ title: "formula.operation.pasteFormula",
3461
+ disabled$: El(t).pipe(
3462
+ Yr(ro(t, { workbookTypes: [po], rangeTypes: [go], worksheetTypes: [ho, mo] })),
3463
+ lo(([e, n]) => e || n)
3464
+ )
3465
+ };
3466
+ }
3467
+ const yl = {
3468
+ [vs.FORMULAS_INSERT]: {
3469
+ [hn.id]: {
3470
+ order: 1,
3471
+ menuItemFactory: Rl,
3472
+ [dn.id]: {
3473
+ order: 1,
3474
+ menuItemFactory: Il
3475
+ }
3476
+ }
3477
+ },
3478
+ [Ar]: {
3479
+ [fn.id]: {
3480
+ order: 4,
3481
+ menuItemFactory: bl
3482
+ }
3483
+ }
3484
+ }, Nl = "meta_key_ctrl_And_Shift", Bt = [
3485
+ D.ARROW_DOWN,
3486
+ D.ARROW_UP,
3487
+ D.ARROW_LEFT,
3488
+ D.ARROW_RIGHT
3489
+ ], Tl = [...Bt, D.ENTER, D.TAB, D.ESC];
3490
+ function Fl() {
3491
+ const t = [];
3492
+ for (const e of Tl)
3493
+ t.push({
3494
+ id: rt.id,
3495
+ binding: e,
3496
+ preconditions: (n) => St(n),
3497
+ staticParameters: {
3498
+ eventType: ye.Keyboard,
3499
+ keycode: e
3500
+ }
3501
+ });
3502
+ return t;
3503
+ }
3504
+ function Ol() {
3505
+ const t = [];
3506
+ for (const e of Bt)
3507
+ t.push({
3508
+ id: rt.id,
3509
+ binding: e | U.SHIFT,
3510
+ preconditions: (n) => St(n),
3511
+ staticParameters: {
3512
+ eventType: ye.Keyboard,
3513
+ keycode: e,
3514
+ metaKey: U.SHIFT
3515
+ }
3516
+ });
3517
+ return t;
3518
+ }
3519
+ function Ml() {
3520
+ const t = [];
3521
+ for (const e of Bt)
3522
+ t.push({
3523
+ id: rt.id,
3524
+ binding: e | U.CTRL_COMMAND,
3525
+ preconditions: (n) => St(n),
3526
+ staticParameters: {
3527
+ eventType: ye.Keyboard,
3528
+ keycode: e,
3529
+ metaKey: U.CTRL_COMMAND
3530
+ }
3531
+ });
3532
+ return t;
3533
+ }
3534
+ function Al() {
3535
+ const t = [];
3536
+ for (const e of Bt)
3537
+ t.push({
3538
+ id: rt.id,
3539
+ binding: e | U.SHIFT | U.CTRL_COMMAND,
3540
+ preconditions: (n) => St(n),
3541
+ staticParameters: {
3542
+ eventType: ye.Keyboard,
3543
+ keycode: e,
3544
+ metaKey: Nl
3545
+ }
3546
+ });
3547
+ return t;
3548
+ }
3549
+ const Pl = {
3550
+ id: No.id,
3551
+ binding: D.F4,
3552
+ preconditions: (t) => St(t)
3553
+ };
3554
+ function xl() {
3555
+ const t = [];
3556
+ for (const e of [D.ENTER, D.TAB, D.ARROW_DOWN, D.ARROW_UP])
3557
+ t.push({
3558
+ id: rt.id,
3559
+ binding: e,
3560
+ preconditions: (n) => lc(n),
3561
+ staticParameters: {
3562
+ eventType: ye.Keyboard,
3563
+ keycode: e,
3564
+ isSingleEditor: !0
3565
+ }
3566
+ });
3567
+ return t;
3568
+ }
3569
+ var wl = Object.getOwnPropertyDescriptor, Dl = (t, e, n, o) => {
3570
+ for (var r = o > 1 ? void 0 : o ? wl(e, n) : e, s = t.length - 1, i; s >= 0; s--)
3571
+ (i = t[s]) && (r = i(r) || r);
3572
+ return r;
3573
+ }, Ue = (t, e) => (n, o) => e(n, o, t);
3574
+ let wt = class extends pt {
3575
+ constructor(t, e, n, o, r, s, i) {
3576
+ super(), this._injector = t, this._menuManagerService = e, this._commandService = n, this._shortcutService = o, this._uiPartsService = r, this._renderManagerService = s, this._componentManager = i, this._initialize();
3577
+ }
3578
+ _initialize() {
3579
+ this._registerCommands(), this._registerMenus(), this._registerShortcuts(), this._registerComponents(), this._registerRenderModules();
3580
+ }
3581
+ _registerMenus() {
3582
+ this._menuManagerService.mergeMenu(yl);
3583
+ }
3584
+ _registerCommands() {
3585
+ [
3586
+ fn,
3587
+ hn,
3588
+ dn,
3589
+ Ls,
3590
+ Os,
3591
+ rt,
3592
+ No
3593
+ ].forEach((t) => this.disposeWithMe(this._commandService.registerCommand(t)));
3594
+ }
3595
+ _registerShortcuts() {
3596
+ [
3597
+ ...Fl(),
3598
+ ...Ol(),
3599
+ ...Ml(),
3600
+ ...Al(),
3601
+ ...xl(),
3602
+ Pl
3603
+ ].forEach((t) => {
3604
+ this.disposeWithMe(this._shortcutService.registerShortcut(t));
3605
+ });
3606
+ }
3607
+ _registerComponents() {
3608
+ this.disposeWithMe(this._uiPartsService.registerComponent(_o.CONTENT, () => Jt(nl, this._injector))), this.disposeWithMe(this._uiPartsService.registerComponent(Pr.FORMULA_AUX, () => Jt(Mc, this._injector))), this._componentManager.register(yo, _l);
3609
+ }
3610
+ _registerRenderModules() {
3611
+ this.disposeWithMe(this._renderManagerService.registerRenderModule(ue.UNIVER_SHEET, [Pt]));
3612
+ }
3613
+ };
3614
+ wt = Dl([
3615
+ Ue(0, K(mt)),
3616
+ Ue(1, _s),
3617
+ Ue(2, ae),
3618
+ Ue(3, Ut),
3619
+ Ue(4, Co),
3620
+ Ue(5, Ne),
3621
+ Ue(6, K(vo))
3622
+ ], wt);
3623
+ const Ll = () => {
3624
+ var o, r;
3625
+ const t = O(ko), e = qe(t.currentSelector$), n = j(null);
3626
+ return L(() => {
3627
+ var s, i;
3628
+ if (e)
3629
+ return (i = n.current) == null || i.showDialog((s = e.initialValue) != null ? s : []), () => {
3630
+ var c;
3631
+ (c = n.current) == null || c.hideDialog();
3632
+ };
3633
+ }, [e]), /* @__PURE__ */ b(
3634
+ $o,
3635
+ {
3636
+ unitId: (o = e == null ? void 0 : e.unitId) != null ? o : "",
3637
+ subUnitId: (r = e == null ? void 0 : e.subUnitId) != null ? r : "",
3638
+ hideEditor: !0,
3639
+ selectorRef: n,
3640
+ onChange: (s, i) => {
3641
+ var c;
3642
+ e == null || e.callback((c = i == null ? void 0 : i.split(",").map((l) => ot(l))) != null ? c : []);
3643
+ }
3644
+ }
3645
+ );
3646
+ };
3647
+ var $l = Object.defineProperty, kl = Object.getOwnPropertyDescriptor, Hl = (t, e, n) => e in t ? $l(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, Wl = (t, e, n, o) => {
3648
+ for (var r = o > 1 ? void 0 : o ? kl(e, n) : e, s = t.length - 1, i; s >= 0; s--)
3649
+ (i = t[s]) && (r = i(r) || r);
3650
+ return r;
3651
+ }, Nt = (t, e) => (n, o) => e(n, o, t), Vo = (t, e, n) => Hl(t, typeof e != "symbol" ? e + "" : e, n);
3652
+ let Dt = class extends dr {
3653
+ constructor(t = jn, e, n, o, r) {
3654
+ super(), this._config = t, this._injector = e, this._renderManagerService = n, this._configService = o, this._uiPartsService = r;
3655
+ const { menu: s, ...i } = mr(
3656
+ jn,
3657
+ this._config
3658
+ );
3659
+ s && this._configService.setConfig("menu", s, { merge: !0 }), this._configService.setConfig(cc, i, { merge: !0 });
3660
+ }
3661
+ onStarting() {
3662
+ gr(this._injector, [
3663
+ [Ct, { useClass: en }],
3664
+ [ko],
3665
+ [wt],
3666
+ [Mt],
3667
+ [At],
3668
+ [Pt],
3669
+ [xt]
3670
+ ]);
3671
+ }
3672
+ onRendered() {
3673
+ [
3674
+ [De],
3675
+ [nn]
3676
+ ].forEach((t) => {
3677
+ this.disposeWithMe(this._renderManagerService.registerRenderModule(ue.UNIVER_SHEET, t));
3678
+ }), pr(this._injector, [
3679
+ [wt],
3680
+ // FormulaProgressBar relies on TriggerCalculationController, but it is necessary to ensure that the formula calculation is done after rendered.
3681
+ [At],
3682
+ [xt]
3683
+ ]), this._initUIPart();
3684
+ }
3685
+ onSteady() {
3686
+ this._injector.get(Mt);
3687
+ }
3688
+ _initUIPart() {
3689
+ const t = this._injector.get(vo);
3690
+ this.disposeWithMe(t.register(xr, $o)), this.disposeWithMe(t.register(wr, Zi)), this.disposeWithMe(this._uiPartsService.registerComponent(_o.GLOBAL, () => Jt(Ll, this._injector)));
3691
+ }
3692
+ };
3693
+ Vo(Dt, "pluginName", bo);
3694
+ Vo(Dt, "type", ue.UNIVER_SHEET);
3695
+ Dt = Wl([
3696
+ fr(qr, fs),
3697
+ Nt(1, K(mt)),
3698
+ Nt(2, Ne),
3699
+ Nt(3, hr),
3700
+ Nt(4, Co)
3701
+ ], Dt);
3702
+ export {
3703
+ Fs as FORMULA_PROMPT_ACTIVATED,
3704
+ Zi as FormulaEditor,
3705
+ ko as GlobalRangeSelectorService,
3706
+ Os as HelpFunctionOperation,
3707
+ hn as InsertFunctionOperation,
3708
+ dn as MoreFunctionsOperation,
3709
+ $o as RangeSelector,
3710
+ De as RefSelectionsRenderService,
3711
+ No as ReferenceAbsoluteOperation,
3712
+ Ls as SearchFunctionOperation,
3713
+ rt as SelectEditorFormulaOperation,
3714
+ fn as SheetOnlyPasteFormulaCommand,
3715
+ Dt as UniverSheetsFormulaUIPlugin
3716
+ };