@univerjs/sheets 0.5.1 → 0.5.2-nightly.202412291605

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/lib/cjs/facade.js +1 -1
  2. package/lib/cjs/index.js +3 -3
  3. package/lib/es/facade.js +1962 -500
  4. package/lib/es/index.js +3640 -3263
  5. package/lib/types/basics/cell-position.d.ts +25 -0
  6. package/lib/types/basics/index.d.ts +1 -0
  7. package/lib/types/basics/selection.d.ts +1 -1
  8. package/lib/types/basics/split-range-text.d.ts +42 -0
  9. package/lib/types/commands/commands/__tests__/set-gridlines-command.spec.d.ts +16 -0
  10. package/lib/types/commands/commands/add-worksheet-merge.command.d.ts +1 -1
  11. package/lib/types/commands/commands/set-gridlines-color.command.d.ts +7 -0
  12. package/lib/types/commands/commands/set-worksheet-show.command.d.ts +0 -1
  13. package/lib/types/commands/commands/split-text-to-columns.command.d.ts +15 -0
  14. package/lib/types/commands/mutations/set-gridlines-color.mutation.d.ts +12 -0
  15. package/lib/types/controllers/defined-name-data.controller.d.ts +1 -0
  16. package/lib/types/facade/f-defined-name.d.ts +294 -0
  17. package/lib/types/facade/f-permission.d.ts +49 -1
  18. package/lib/types/facade/f-range.d.ts +99 -5
  19. package/lib/types/facade/f-selection.d.ts +71 -1
  20. package/lib/types/facade/f-univer.d.ts +17 -3
  21. package/lib/types/facade/f-workbook.d.ts +345 -7
  22. package/lib/types/facade/f-worksheet.d.ts +350 -11
  23. package/lib/types/index.d.ts +13 -2
  24. package/lib/types/services/__tests__/move-active-cell.spec.d.ts +16 -0
  25. package/lib/types/services/exclusive-range/exclusive-range-service.d.ts +12 -0
  26. package/lib/types/services/permission/permission-point/const.d.ts +82 -0
  27. package/lib/types/services/ref-range/util.d.ts +1 -1
  28. package/lib/types/services/selections/index.d.ts +1 -1
  29. package/lib/types/services/selections/move-active-cell-util.d.ts +10 -0
  30. package/lib/types/services/selections/selection-data-model.d.ts +5 -10
  31. package/lib/types/services/selections/selection.service.d.ts +21 -1
  32. package/lib/umd/facade.js +1 -1
  33. package/lib/umd/index.js +3 -3
  34. package/package.json +8 -8
  35. package/LICENSE +0 -176
package/lib/es/facade.js CHANGED
@@ -1,17 +1,398 @@
1
- var me = Object.defineProperty;
2
- var le = (n, e, t) => e in n ? me(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var E = (n, e, t) => le(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { Inject as u, Injector as R, IAuthzIoService as ge, FBase as b, generateRandomId as _e, Rectangle as T, ICommandService as v, IPermissionService as ae, HorizontalAlign as C, VerticalAlign as I, isFormulaString as we, isCellV as ke, isICellData as Se, ObjectMatrix as P, Tools as Ce, RANGE_TYPE as l, BooleanNumber as m, WrapStrategy as H, Dimension as N, Direction as p, IResourceLoaderService as Ie, mergeWorksheetSnapshotWithDefault as ve, UndoCommand as Re, RedoCommand as fe, toDisposable as be, UniverInstanceType as O, IUniverInstanceService as he, ILogService as pe, FUniver as ce } from "@univerjs/core";
5
- import { WorksheetProtectionRuleModel as ye, RangeProtectionRuleModel as Pe, WorksheetProtectionPointModel as Ue, WorkbookEditablePermission as de, UnitObject as f, AddWorksheetProtectionMutation as xe, DeleteWorksheetProtectionMutation as Ee, getAllWorksheetPermissionPoint as Me, getAllWorksheetPermissionPointByPointPanel as $, SetWorksheetPermissionPointsMutation as Fe, AddRangeProtectionMutation as We, DeleteRangeProtectionMutation as Ae, SetRangeProtectionMutation as De, WorksheetEditPermission as je, WorksheetViewPermission as Te, SetStyleCommand as _, SetRangeValuesCommand as G, SetTextWrapCommand as q, SetVerticalTextAlignCommand as Oe, SetHorizontalTextAlignCommand as Ve, addMergeCellsUtil as M, getAddMergeMutationRangeByType as Y, RemoveWorksheetMergeCommand as ze, SheetsSelectionsService as ue, SetWorksheetDefaultStyleMutation as Le, SetColDataCommand as J, SetRowDataCommand as K, copyRangeStyles as y, InsertRowCommand as Q, RemoveRowCommand as Be, MoveRowsCommand as He, SetRowHiddenCommand as X, SetSpecificRowsVisibleCommand as Z, SetRowHeightCommand as ee, SetWorksheetRowIsAutoHeightCommand as Ne, InsertColCommand as te, RemoveColCommand as $e, MoveColsCommand as Ge, SetColHiddenCommand as ne, SetSpecificColsVisibleCommand as oe, SetColWidthCommand as qe, SetFrozenCommand as Ye, CancelFrozenCommand as Je, ToggleGridlinesCommand as Ke, SetRangeValuesMutation as se, InsertSheetCommand as re, SetWorksheetActiveOperation as F, RemoveSheetCommand as Qe, getPrimaryForRange as Xe, SetSelectionsOperation as Ze } from "@univerjs/sheets";
6
- import { FormulaDataModel as et, deserializeRangeWithSheet as tt } from "@univerjs/engine-formula";
7
- var nt = Object.defineProperty, ot = Object.getOwnPropertyDescriptor, st = (n, e, t, o) => {
8
- for (var s = o > 1 ? void 0 : o ? ot(e, t) : e, r = n.length - 1, i; r >= 0; r--)
9
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
10
- return o && s && nt(e, t, s), s;
11
- }, w = (n, e) => (t, o) => e(t, o, n);
12
- let V = class extends b {
13
- constructor(n, e, t, o, s, r, i) {
14
- super(), this._injector = n, this._commandService = e, this._permissionService = t, this._worksheetProtectionRuleModel = o, this._rangeProtectionRuleModel = s, this._worksheetProtectionPointRuleModel = r, this._authzIoService = i;
1
+ var xe = Object.defineProperty;
2
+ var Ee = (o, e, t) => e in o ? xe(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var P = (o, e, t) => Ee(o, typeof e != "symbol" ? e + "" : e, t);
4
+ import { Inject as m, Injector as v, IAuthzIoService as we, LocaleService as ke, ICommandService as l, IPermissionService as Q, generateRandomId as Se, FBase as p, Rectangle as N, HorizontalAlign as R, VerticalAlign as b, isFormulaString as De, isCellV as Me, isICellData as je, ObjectMatrix as j, Tools as We, RANGE_TYPE as g, BooleanNumber as u, WrapStrategy as Z, Dimension as ee, ILogService as Ce, Direction as E, IResourceLoaderService as Oe, mergeWorksheetSnapshotWithDefault as Fe, UndoCommand as Ae, RedoCommand as Te, toDisposable as Ie, UniverInstanceType as U, IUniverInstanceService as fe, FUniver as ve } from "@univerjs/core";
5
+ import { IDefinedNamesService as Re, serializeRange as X, FormulaDataModel as Le, serializeRangeWithSheet as Be, deserializeRangeWithSheet as ze } from "@univerjs/engine-formula";
6
+ import { WorksheetProtectionRuleModel as be, RangeProtectionRuleModel as pe, WorksheetProtectionPointModel as Pe, SetDefinedNameCommand as q, SCOPE_WORKBOOK_VALUE_DEFINED_NAME as K, RemoveDefinedNameCommand as Ve, PermissionPointsDefinitions as He, WorkbookEditablePermission as ye, UnitObject as y, AddWorksheetProtectionMutation as $e, DeleteWorksheetProtectionMutation as Ge, getAllWorksheetPermissionPoint as qe, getAllWorksheetPermissionPointByPointPanel as te, SetWorksheetPermissionPointsMutation as Ke, AddRangeProtectionMutation as Ye, DeleteRangeProtectionMutation as Je, SetRangeProtectionMutation as Qe, WorksheetEditPermission as Xe, WorksheetViewPermission as Ze, SetStyleCommand as C, SetRangeValuesCommand as ne, SetTextWrapCommand as se, SetVerticalTextAlignCommand as et, SetHorizontalTextAlignCommand as tt, addMergeCellsUtil as L, getAddMergeMutationRangeByType as oe, RemoveWorksheetMergeCommand as nt, SplitTextToColumnsCommand as st, getPrimaryForRange as Y, SetSelectionsOperation as Ue, getNextPrimaryCell as ot, SheetsSelectionsService as Ne, SetWorksheetDefaultStyleMutation as rt, SetColDataCommand as re, SetRowDataCommand as ie, copyRangeStyles as D, InsertRowCommand as ae, RemoveRowCommand as it, MoveRowsCommand as at, SetRowHiddenCommand as he, SetSpecificRowsVisibleCommand as ce, SetRowHeightCommand as de, SetWorksheetRowIsAutoHeightCommand as ht, InsertColCommand as me, RemoveColCommand as ct, MoveColsCommand as dt, SetColHiddenCommand as ue, SetSpecificColsVisibleCommand as le, SetColWidthCommand as mt, SetFrozenCommand as B, CancelFrozenCommand as ut, ToggleGridlinesCommand as lt, SetGridlinesColorCommand as gt, SetTabColorCommand as _t, SetRangeValuesMutation as ge, SetWorksheetHideCommand as wt, SetWorksheetShowCommand as kt, SetWorksheetNameCommand as St, ClearSelectionAllCommand as Ct, ClearSelectionContentCommand as It, ClearSelectionFormatCommand as ft, InsertSheetCommand as z, SetWorksheetActiveOperation as V, RemoveSheetCommand as vt, CopySheetCommand as Rt, SetWorksheetOrderCommand as bt } from "@univerjs/sheets";
7
+ var pt = Object.defineProperty, Pt = Object.getOwnPropertyDescriptor, yt = (o, e, t, n) => {
8
+ for (var s = n > 1 ? void 0 : n ? Pt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
9
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
10
+ return n && s && pt(e, t, s), s;
11
+ }, w = (o, e) => (t, n) => e(t, n, o);
12
+ function Ut(o, e, t) {
13
+ const n = t.getDefinedNameMap(o);
14
+ if (n == null)
15
+ return e.t("definedName.defaultName") + 1;
16
+ const r = Array.from(Object.values(n)).length + 1, i = e.t("definedName.defaultName") + r;
17
+ if (t.getValueByName(o, i) == null)
18
+ return i;
19
+ let a = r + 1;
20
+ for (; ; ) {
21
+ const h = e.t("definedName.defaultName") + a;
22
+ if (t.getValueByName(o, h) == null)
23
+ return h;
24
+ a++;
25
+ }
26
+ }
27
+ class A {
28
+ constructor() {
29
+ P(this, "_definedNameParam");
30
+ this._definedNameParam = {
31
+ id: Se(10),
32
+ unitId: "",
33
+ name: "",
34
+ formulaOrRefString: ""
35
+ };
36
+ }
37
+ /**
38
+ * Sets the name of the defined name builder.
39
+ * @param name The name of the defined name.
40
+ * @returns The defined name builder.
41
+ * @example
42
+ * ```ts
43
+ * const workbook = UniverAPI.getActiveWorkbook();
44
+ * const definedNameBuilder = UniverAPI.newDefinedName()
45
+ * .setName('MyDefinedName')
46
+ * .build();
47
+ * workbook.insertDefinedNameBuilder(definedNameBuilder);
48
+ * ```
49
+ */
50
+ setName(e) {
51
+ return this._definedNameParam.name = e, this;
52
+ }
53
+ /**
54
+ * Sets the formula of the defined name builder.
55
+ * @param formula The formula of the defined name.
56
+ * @returns The defined name builder.
57
+ * @example
58
+ * ```ts
59
+ * const workbook = UniverAPI.getActiveWorkbook();
60
+ * const definedNameBuilder = UniverAPI.newDefinedName()
61
+ * .setFormula('SUM(Sheet1!$A$1)')
62
+ * .setName('MyDefinedName')
63
+ * .build();
64
+ * workbook.insertDefinedNameBuilder(definedNameBuilder);
65
+ * ```
66
+ */
67
+ setFormula(e) {
68
+ return this._definedNameParam.formulaOrRefString = `=${e}`, this;
69
+ }
70
+ /**
71
+ * Sets the reference of the defined name builder.
72
+ * @param refString The reference of the defined name.
73
+ * @returns The defined name builder.
74
+ * @example
75
+ * ```ts
76
+ * const workbook = UniverAPI.getActiveWorkbook();
77
+ * const definedNameBuilder = UniverAPI.newDefinedName()
78
+ * .setRef('Sheet1!$A$1')
79
+ * .build();
80
+ * workbook.insertDefinedNameBuilder(definedNameBuilder);
81
+ * ```
82
+ */
83
+ setRef(e) {
84
+ return this._definedNameParam.formulaOrRefString = e, this;
85
+ }
86
+ /**
87
+ * Sets the reference of the defined name builder by range .
88
+ * @param row The start row of the range.
89
+ * @param column The start column of the range.
90
+ * @param numRows The number of rows in the range.
91
+ * @param numColumns The number of columns in the range.
92
+ * @returns The defined name builder.
93
+ * @example
94
+ * ```ts
95
+ * const workbook = UniverAPI.getActiveWorkbook();
96
+ * const definedNameBuilder = UniverAPI.newDefinedName()
97
+ * .setRefByRange(1, 3, 2, 5)
98
+ * .build();
99
+ * workbook.insertDefinedNameBuilder(definedNameBuilder);
100
+ * ```
101
+ */
102
+ setRefByRange(e, t, n, s) {
103
+ return this._definedNameParam.formulaOrRefString = X({
104
+ startRow: e,
105
+ endRow: e + (n != null ? n : 1) - 1,
106
+ startColumn: t,
107
+ endColumn: t + (s != null ? s : 1) - 1
108
+ }), this;
109
+ }
110
+ /**
111
+ * Sets the comment of the defined name builder.
112
+ * @param comment The comment of the defined name.
113
+ * @returns The defined name builder.
114
+ * @example
115
+ * ```ts
116
+ * const workbook = UniverAPI.getActiveWorkbook();
117
+ * const definedNameBuilder = UniverAPI.newDefinedName()
118
+ * .setComment('This is a comment')
119
+ * .build();
120
+ * workbook.insertDefinedNameBuilder(definedNameBuilder);
121
+ * ```
122
+ */
123
+ setComment(e) {
124
+ return this._definedNameParam.comment = e, this;
125
+ }
126
+ /**
127
+ * Sets the hidden status of the defined name builder.
128
+ * @param hidden The hidden status of the defined name.
129
+ * @returns The defined name builder.
130
+ * @example
131
+ * ```ts
132
+ * const workbook = UniverAPI.getActiveWorkbook();
133
+ * const definedNameBuilder = UniverAPI.newDefinedName()
134
+ * .setHidden(true)
135
+ * .build();
136
+ * workbook.insertDefinedNameBuilder(definedNameBuilder);
137
+ * ```
138
+ */
139
+ setHidden(e) {
140
+ return this._definedNameParam.hidden = e, this;
141
+ }
142
+ /**
143
+ * Builds the defined name.
144
+ * @returns The defined name mutation parameter.
145
+ * @example
146
+ * ```ts
147
+ * const workbook = UniverAPI.getActiveWorkbook();
148
+ * const definedNameBuilder = UniverAPI.newDefinedName()
149
+ * .setRef('Sheet1!$A$1')
150
+ * .setName('MyDefinedName')
151
+ * .build();
152
+ * workbook.insertDefinedNameBuilder(definedNameBuilder);
153
+ * ```
154
+ */
155
+ build() {
156
+ return this._definedNameParam;
157
+ }
158
+ load(e) {
159
+ return this._definedNameParam = e, this;
160
+ }
161
+ }
162
+ let W = class extends p {
163
+ constructor(o, e, t, n, s, r, i, a, h, c) {
164
+ super(), this._definedNameParam = o, this._injector = e, this._commandService = t, this._permissionService = n, this._worksheetProtectionRuleModel = s, this._rangeProtectionRuleModel = r, this._worksheetProtectionPointRuleModel = i, this._authzIoService = a, this._localeService = h, this._definedNamesService = c;
165
+ }
166
+ _apply() {
167
+ this._definedNameParam.name === "" && (this._definedNameParam.name = Ut(this._definedNameParam.unitId, this._localeService, this._definedNamesService)), this._commandService.syncExecuteCommand(q.id, this._definedNameParam);
168
+ }
169
+ /**
170
+ * Gets the name of the defined name.
171
+ * @returns The name of the defined name.
172
+ * @example
173
+ * ```ts
174
+ * const workbook = UniverAPI.getActiveWorkbook();
175
+ * const definedName = workbook.getDefinedNames[0];
176
+ * console.log(definedName.getName());
177
+ * ```
178
+ */
179
+ getName() {
180
+ return this._definedNameParam.name;
181
+ }
182
+ /**
183
+ * Sets the name of the defined name.
184
+ * @param name The name of the defined name.
185
+ * @example
186
+ * ```ts
187
+ * const workbook = UniverAPI.getActiveWorkbook();
188
+ * const definedName = workbook.getDefinedName('MyDefinedName');
189
+ * definedName.setName('NewDefinedName');
190
+ * ```
191
+ */
192
+ setName(o) {
193
+ this._definedNameParam.name = o, this._apply();
194
+ }
195
+ /**
196
+ * Sets the formula of the defined name.
197
+ * @param formula The formula of the defined name.
198
+ * @example
199
+ * ```ts
200
+ * const workbook = UniverAPI.getActiveWorkbook();
201
+ * const definedName = workbook.getDefinedName('MyDefinedName');
202
+ * definedName.setFormula('SUM(Sheet1!$A$1)');
203
+ * ```
204
+ */
205
+ setFormula(o) {
206
+ this._definedNameParam.formulaOrRefString = `=${o}`, this._apply();
207
+ }
208
+ /**
209
+ * Sets the reference of the defined name.
210
+ * @param refString The reference of the defined name.
211
+ * @example
212
+ * ```ts
213
+ * const workbook = UniverAPI.getActiveWorkbook();
214
+ * const definedName = workbook.getDefinedNames[0];
215
+ * definedName.setRef('Sheet1!$A$1');
216
+ * ```
217
+ */
218
+ setRef(o) {
219
+ this._definedNameParam.formulaOrRefString = o, this._apply();
220
+ }
221
+ /**
222
+ * Gets the reference of the defined name.
223
+ * @returns The reference of the defined name.
224
+ * @example
225
+ * ```ts
226
+ * const workbook = UniverAPI.getActiveWorkbook();
227
+ * const definedName = workbook.getDefinedNames[0];
228
+ * console.log(definedName.getFormulaOrRefString());
229
+ * ```
230
+ */
231
+ getFormulaOrRefString() {
232
+ return this._definedNameParam.formulaOrRefString;
233
+ }
234
+ /**
235
+ * Sets the reference of the defined name by range.
236
+ * @param row The start row of the range.
237
+ * @param column The start column of the range.
238
+ * @param numRows The number of rows in the range.
239
+ * @param numColumns The number of columns in the range.
240
+ * @example
241
+ * ```ts
242
+ * const workbook = UniverAPI.getActiveWorkbook();
243
+ * const definedName = workbook.getDefinedNames[0];
244
+ * definedName.setRefByRange(1, 3, 2, 5);
245
+ * ```
246
+ */
247
+ setRefByRange(o, e, t, n) {
248
+ this._definedNameParam.formulaOrRefString = X({
249
+ startRow: o,
250
+ endRow: o + (t != null ? t : 1) - 1,
251
+ startColumn: e,
252
+ endColumn: e + (n != null ? n : 1) - 1
253
+ }), this._apply();
254
+ }
255
+ /**
256
+ * Gets the comment of the defined name.
257
+ * @returns The comment of the defined name.
258
+ * @example
259
+ * ```ts
260
+ * const workbook = UniverAPI.getActiveWorkbook();
261
+ * const definedName = workbook.getDefinedNames[0];
262
+ * console.log(definedName.getComment());
263
+ * ```
264
+ */
265
+ getComment() {
266
+ return this._definedNameParam.comment;
267
+ }
268
+ /**
269
+ * Sets the comment of the defined name.
270
+ * @param comment The comment of the defined name.
271
+ * @example
272
+ * ```ts
273
+ * const workbook = UniverAPI.getActiveWorkbook();
274
+ * const definedName = workbook.getDefinedNames[0];
275
+ * definedName.setComment('This is a comment');
276
+ * ```
277
+ */
278
+ setComment(o) {
279
+ this._definedNameParam.comment = o, this._apply();
280
+ }
281
+ /**
282
+ * Sets the scope of the defined name to the worksheet.
283
+ * @param worksheet The worksheet to set the scope to.
284
+ * @example
285
+ * ```ts
286
+ * const workbook = UniverAPI.getActiveWorkbook();
287
+ * const worksheet = workbook.getWorksheets[0];
288
+ * const definedName = workbook.getDefinedNames[0];
289
+ * definedName.setScopeToWorksheet(worksheet);
290
+ * ```
291
+ */
292
+ setScopeToWorksheet(o) {
293
+ this._definedNameParam.localSheetId = o.getSheetId(), this._apply();
294
+ }
295
+ /**
296
+ * Sets the scope of the defined name to the workbook.
297
+ * @example
298
+ * ```ts
299
+ * const workbook = UniverAPI.getActiveWorkbook();
300
+ * const definedName = workbook.getDefinedNames[0];
301
+ * definedName.setScopeToWorkbook();
302
+ * ```
303
+ */
304
+ setScopeToWorkbook() {
305
+ this._definedNameParam.localSheetId = K, this._apply();
306
+ }
307
+ /**
308
+ * Sets the hidden status of the defined name.
309
+ * @param hidden The hidden status of the defined name.
310
+ * @example
311
+ * ```ts
312
+ * const workbook = UniverAPI.getActiveWorkbook();
313
+ * const definedName = workbook.getDefinedNames[0];
314
+ * definedName.setHidden(true);
315
+ * ```
316
+ */
317
+ setHidden(o) {
318
+ this._definedNameParam.hidden = o, this._apply();
319
+ }
320
+ /**
321
+ * Deletes the defined name.
322
+ * @example
323
+ * ```ts
324
+ * const workbook = UniverAPI.getActiveWorkbook();
325
+ * const definedName = workbook.getDefinedNames[0];
326
+ * definedName.delete();
327
+ * ```
328
+ */
329
+ delete() {
330
+ this._commandService.syncExecuteCommand(Ve.id, this._definedNameParam);
331
+ }
332
+ /**
333
+ * Gets the local sheet id of the defined name.
334
+ * @returns The local sheet id of the defined name.
335
+ * @example
336
+ * ```ts
337
+ * const workbook = UniverAPI.getActiveWorkbook();
338
+ * const definedName = workbook.getDefinedNames[0];
339
+ * console.log(definedName.getLocalSheetId());
340
+ * ```
341
+ */
342
+ getLocalSheetId() {
343
+ return this._definedNameParam.localSheetId;
344
+ }
345
+ /**
346
+ * Checks if the defined name is in the workbook scope.
347
+ * @returns True if the defined name is in the workbook scope, false otherwise.
348
+ * @example
349
+ * ```ts
350
+ * const workbook = UniverAPI.getActiveWorkbook();
351
+ * const definedName = workbook.getDefinedNames[0];
352
+ * console.log(definedName.isWorkbookScope());
353
+ * ```
354
+ */
355
+ isWorkbookScope() {
356
+ return this._definedNameParam.localSheetId === K;
357
+ }
358
+ /**
359
+ * Converts the defined name to a defined name builder.
360
+ * @returns The defined name builder.
361
+ * @example
362
+ * ```ts
363
+ * const workbook = UniverAPI.getActiveWorkbook();
364
+ * const definedName = workbook.getDefinedNames[0];
365
+ * const definedNameBuilder = definedName.toBuilder();
366
+ * const param definedNameBuilder.setName('NewDefinedName').setFormula('SUM(Sheet1!$A$1)').build();
367
+ * workbook.updateDefinedNameBuilder(param);
368
+ * ```
369
+ */
370
+ toBuilder() {
371
+ const o = this._injector.createInstance(A);
372
+ return o.load(this._definedNameParam), o;
373
+ }
374
+ };
375
+ W = yt([
376
+ w(1, m(v)),
377
+ w(2, l),
378
+ w(3, Q),
379
+ w(4, m(be)),
380
+ w(5, m(pe)),
381
+ w(6, m(Pe)),
382
+ w(7, m(we)),
383
+ w(8, m(ke)),
384
+ w(9, Re)
385
+ ], W);
386
+ var Nt = Object.defineProperty, xt = Object.getOwnPropertyDescriptor, Et = (o, e, t, n) => {
387
+ for (var s = n > 1 ? void 0 : n ? xt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
388
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
389
+ return n && s && Nt(e, t, s), s;
390
+ }, f = (o, e) => (t, n) => e(t, n, o);
391
+ let O = class extends p {
392
+ constructor(e, t, n, s, r, i, a) {
393
+ super();
394
+ P(this, "permissionPointsDefinition", He);
395
+ this._injector = e, this._commandService = t, this._permissionService = n, this._worksheetProtectionRuleModel = s, this._rangeProtectionRuleModel = r, this._worksheetProtectionPointRuleModel = i, this._authzIoService = a;
15
396
  }
16
397
  /**
17
398
  * Configures a specific permission point for a workbook.
@@ -24,9 +405,9 @@ let V = class extends b {
24
405
  * @param {boolean} value - The boolean value to determine whether the permission point is enabled or disabled.
25
406
  *
26
407
  */
27
- setWorkbookPermissionPoint(n, e, t) {
28
- const o = new e(n);
29
- this._permissionService.getPermissionPoint(o.id) || this._permissionService.addPermissionPoint(o), this._permissionService.updatePermissionPoint(o.id, t);
408
+ setWorkbookPermissionPoint(e, t, n) {
409
+ const s = new t(e);
410
+ this._permissionService.getPermissionPoint(s.id) || this._permissionService.addPermissionPoint(s), this._permissionService.updatePermissionPoint(s.id, n);
30
411
  }
31
412
  /**
32
413
  * This function is used to set whether the workbook can be edited
@@ -35,8 +416,8 @@ let V = class extends b {
35
416
  * @param {boolean} value - A value that controls whether the workbook can be edited
36
417
  *
37
418
  */
38
- setWorkbookEditPermission(n, e) {
39
- this.setWorkbookPermissionPoint(n, de, e);
419
+ setWorkbookEditPermission(e, t) {
420
+ this.setWorkbookPermissionPoint(e, ye, t);
40
421
  }
41
422
  /**
42
423
  * This function is used to add a base permission for a worksheet.
@@ -46,21 +427,30 @@ let V = class extends b {
46
427
  *
47
428
  * @returns {Promise<string | undefined>} - Returns the `permissionId` if the permission is successfully added. If the operation fails or no result is returned, it resolves to `undefined`.
48
429
  */
49
- async addWorksheetBasePermission(n, e) {
50
- if (this._rangeProtectionRuleModel.getSubunitRuleList(n, e).length > 0)
430
+ async addWorksheetBasePermission(e, t) {
431
+ if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).length > 0)
51
432
  throw new Error("sheet protection cannot intersect with range protection");
52
- const o = await this._authzIoService.create({ objectType: f.Worksheet });
53
- if (this._commandService.syncExecuteCommand(xe.id, {
54
- unitId: n,
55
- subUnitId: e,
433
+ const s = await this._authzIoService.create({
434
+ objectType: y.Worksheet,
435
+ worksheetObject: {
436
+ collaborators: [],
437
+ unitID: e,
438
+ strategies: [],
439
+ name: "",
440
+ scope: void 0
441
+ }
442
+ });
443
+ if (this._commandService.syncExecuteCommand($e.id, {
444
+ unitId: e,
445
+ subUnitId: t,
56
446
  rule: {
57
- permissionId: o,
58
- unitType: f.Worksheet,
59
- unitId: n,
60
- subUnitId: e
447
+ permissionId: s,
448
+ unitType: y.Worksheet,
449
+ unitId: e,
450
+ subUnitId: t
61
451
  }
62
452
  }))
63
- return o;
453
+ return s;
64
454
  }
65
455
  /**
66
456
  * Delete the entire table protection set for the worksheet and reset the point permissions of the worksheet to true
@@ -68,14 +458,14 @@ let V = class extends b {
68
458
  * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
69
459
  * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
70
460
  */
71
- removeWorksheetPermission(n, e) {
72
- this._commandService.syncExecuteCommand(Ee.id, {
73
- unitId: n,
74
- subUnitId: e
75
- }), [...Me(), ...$()].forEach((t) => {
76
- const o = new t(n, e);
77
- this._permissionService.updatePermissionPoint(o.id, !0);
78
- }), this._worksheetProtectionPointRuleModel.deleteRule(n, e);
461
+ removeWorksheetPermission(e, t) {
462
+ this._commandService.syncExecuteCommand(Ge.id, {
463
+ unitId: e,
464
+ subUnitId: t
465
+ }), [...qe(), ...te()].forEach((n) => {
466
+ const s = new n(e, t);
467
+ this._permissionService.updatePermissionPoint(s.id, !0);
468
+ }), this._worksheetProtectionPointRuleModel.deleteRule(e, t);
79
469
  }
80
470
  /**
81
471
  * Sets the worksheet permission point by updating or adding the permission point for the worksheet.
@@ -89,23 +479,32 @@ let V = class extends b {
89
479
  *
90
480
  * @returns {Promise<string | undefined>} - Returns the `permissionId` if the permission point is successfully set or created. If no permission is set, it resolves to `undefined`.
91
481
  */
92
- async setWorksheetPermissionPoint(n, e, t, o) {
93
- const s = this._worksheetProtectionRuleModel.getRule(n, e);
94
- let r;
95
- if (t === je || t === Te)
96
- if (s)
97
- r = s.permissionId;
482
+ async setWorksheetPermissionPoint(e, t, n, s) {
483
+ const r = this._worksheetProtectionRuleModel.getRule(e, t);
484
+ let i;
485
+ if (n === Xe || n === Ze)
486
+ if (r)
487
+ i = r.permissionId;
98
488
  else {
99
- if (this._rangeProtectionRuleModel.getSubunitRuleList(n, e).length > 0)
489
+ if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).length > 0)
100
490
  throw new Error("sheet protection cannot intersect with range protection");
101
- r = await this.addWorksheetBasePermission(n, e);
491
+ i = await this.addWorksheetBasePermission(e, t);
102
492
  }
103
493
  else {
104
- const c = this._worksheetProtectionPointRuleModel.getRule(n, e);
105
- c ? r = c.permissionId : (r = await this._authzIoService.create({ objectType: f.Worksheet }), this._commandService.executeCommand(Fe.id, { unitId: n, subUnitId: e, permissionId: r }));
494
+ const d = this._worksheetProtectionPointRuleModel.getRule(e, t);
495
+ d ? i = d.permissionId : (i = await this._authzIoService.create({
496
+ objectType: y.Worksheet,
497
+ worksheetObject: {
498
+ collaborators: [],
499
+ unitID: e,
500
+ strategies: [],
501
+ name: "",
502
+ scope: void 0
503
+ }
504
+ }), this._commandService.executeCommand(Ke.id, { unitId: e, subUnitId: t, permissionId: i }));
106
505
  }
107
- const a = new t(n, e);
108
- return this._permissionService.getPermissionPoint(a.id) || this._permissionService.addPermissionPoint(a), this._permissionService.updatePermissionPoint(a.id, o), r;
506
+ const h = new n(e, t);
507
+ return this._permissionService.getPermissionPoint(h.id) || this._permissionService.addPermissionPoint(h), this._permissionService.updatePermissionPoint(h.id, s), i;
109
508
  }
110
509
  /**
111
510
  * Adds a range protection to the worksheet.
@@ -116,27 +515,35 @@ let V = class extends b {
116
515
  *
117
516
  * @returns {Promise<{ permissionId: string, ruleId: string } | undefined>} - Returns an object containing the `permissionId` and `ruleId` if the range protection is successfully added. If the operation fails or no result is returned, it resolves to `undefined`. permissionId is used to stitch permission point ID,ruleId is used to store permission rules
118
517
  */
119
- async addRangeBaseProtection(n, e, t) {
120
- const o = await this._authzIoService.create({ objectType: f.SelectRange }), s = `ruleId_${_e(6)}`;
121
- if (this._worksheetProtectionRuleModel.getRule(n, e))
518
+ async addRangeBaseProtection(e, t, n) {
519
+ const s = await this._authzIoService.create({
520
+ objectType: y.SelectRange,
521
+ selectRangeObject: {
522
+ collaborators: [],
523
+ unitID: e,
524
+ name: "",
525
+ scope: void 0
526
+ }
527
+ }), r = `ruleId_${Se(6)}`;
528
+ if (this._worksheetProtectionRuleModel.getRule(e, t))
122
529
  throw new Error("sheet protection cannot intersect with range protection");
123
- if (this._rangeProtectionRuleModel.getSubunitRuleList(n, e).some((c) => c.ranges.some((d) => t.some((x) => T.intersects(x, d)))))
530
+ if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).some((d) => d.ranges.some((T) => n.some((x) => N.intersects(x, T)))))
124
531
  throw new Error("range protection cannot intersect");
125
- if (this._commandService.syncExecuteCommand(We.id, {
126
- unitId: n,
127
- subUnitId: e,
532
+ if (this._commandService.syncExecuteCommand(Ye.id, {
533
+ unitId: e,
534
+ subUnitId: t,
128
535
  rules: [{
129
- permissionId: o,
130
- unitType: f.SelectRange,
131
- unitId: n,
132
- subUnitId: e,
133
- ranges: t,
134
- id: s
536
+ permissionId: s,
537
+ unitType: y.SelectRange,
538
+ unitId: e,
539
+ subUnitId: t,
540
+ ranges: n,
541
+ id: r
135
542
  }]
136
543
  }))
137
544
  return {
138
- permissionId: o,
139
- ruleId: s
545
+ permissionId: s,
546
+ ruleId: r
140
547
  };
141
548
  }
142
549
  /**
@@ -146,14 +553,14 @@ let V = class extends b {
146
553
  * @param {string} subUnitId - The unique identifier of the worksheet.
147
554
  * @param {string[]} ruleIds - The rule IDs of the range protection to be removed.
148
555
  */
149
- removeRangeProtection(n, e, t) {
150
- this._commandService.syncExecuteCommand(Ae.id, {
151
- unitId: n,
152
- subUnitId: e,
153
- ruleIds: t
154
- }) && this._rangeProtectionRuleModel.getSubunitRuleList(n, e).length === 0 && (this._worksheetProtectionPointRuleModel.deleteRule(n, e), [...$()].forEach((r) => {
155
- const i = new r(n, e);
156
- this._permissionService.updatePermissionPoint(i.id, i.value);
556
+ removeRangeProtection(e, t, n) {
557
+ this._commandService.syncExecuteCommand(Je.id, {
558
+ unitId: e,
559
+ subUnitId: t,
560
+ ruleIds: n
561
+ }) && this._rangeProtectionRuleModel.getSubunitRuleList(e, t).length === 0 && (this._worksheetProtectionPointRuleModel.deleteRule(e, t), [...te()].forEach((i) => {
562
+ const a = new i(e, t);
563
+ this._permissionService.updatePermissionPoint(a.id, a.value);
157
564
  }));
158
565
  }
159
566
  /**
@@ -166,9 +573,9 @@ let V = class extends b {
166
573
  * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
167
574
  * @param {boolean} value - The new permission value to be set for the range (e.g., true for allowing access, false for restricting access).
168
575
  */
169
- setRangeProtectionPermissionPoint(n, e, t, o, s) {
170
- const r = new o(n, e, t);
171
- this._permissionService.getPermissionPoint(r.id) || this._permissionService.addPermissionPoint(r), this._permissionService.updatePermissionPoint(r.id, s);
576
+ setRangeProtectionPermissionPoint(e, t, n, s, r) {
577
+ const i = new s(e, t, n);
578
+ this._permissionService.getPermissionPoint(i.id) || this._permissionService.addPermissionPoint(i), this._permissionService.updatePermissionPoint(i.id, r);
172
579
  }
173
580
  /**
174
581
  * Sets the ranges for range protection in a worksheet.
@@ -182,125 +589,133 @@ let V = class extends b {
182
589
  * @param {string} ruleId - The ruleId of the range protection rule that is being updated.
183
590
  * @param {IRange[]} ranges - The array of new ranges to be set for the range protection rule.
184
591
  */
185
- setRangeProtectionRanges(n, e, t, o) {
186
- const s = this._rangeProtectionRuleModel.getRule(n, e, t);
187
- if (s) {
188
- if (this._rangeProtectionRuleModel.getSubunitRuleList(n, e).filter((a) => a.id !== t).some((a) => a.ranges.some((h) => o.some((c) => T.intersects(c, h)))))
592
+ setRangeProtectionRanges(e, t, n, s) {
593
+ const r = this._rangeProtectionRuleModel.getRule(e, t, n);
594
+ if (r) {
595
+ if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).filter((h) => h.id !== n).some((h) => h.ranges.some((c) => s.some((d) => N.intersects(d, c)))))
189
596
  throw new Error("range protection cannot intersect");
190
- this._commandService.syncExecuteCommand(De.id, {
191
- unitId: n,
192
- subUnitId: e,
193
- ruleId: t,
597
+ this._commandService.syncExecuteCommand(Qe.id, {
598
+ unitId: e,
599
+ subUnitId: t,
600
+ ruleId: n,
194
601
  rule: {
195
- ...s,
196
- ranges: o
602
+ ...r,
603
+ ranges: s
197
604
  }
198
605
  });
199
606
  }
200
607
  }
608
+ /**
609
+ * Set visibility of unauthorized pop-up window
610
+ *
611
+ * @param {boolean} visible
612
+ */
613
+ setPermissionDialogVisible(e) {
614
+ this._permissionService.setShowComponents(e);
615
+ }
201
616
  };
202
- V = st([
203
- w(0, u(R)),
204
- w(1, v),
205
- w(2, ae),
206
- w(3, u(ye)),
207
- w(4, u(Pe)),
208
- w(5, u(Ue)),
209
- w(6, u(ge))
210
- ], V);
211
- function rt(n) {
212
- switch (n) {
617
+ O = Et([
618
+ f(0, m(v)),
619
+ f(1, l),
620
+ f(2, Q),
621
+ f(3, m(be)),
622
+ f(4, m(pe)),
623
+ f(5, m(Pe)),
624
+ f(6, m(we))
625
+ ], O);
626
+ function Dt(o) {
627
+ switch (o) {
213
628
  case "left":
214
- return C.LEFT;
629
+ return R.LEFT;
215
630
  case "center":
216
- return C.CENTER;
631
+ return R.CENTER;
217
632
  case "normal":
218
- return C.RIGHT;
633
+ return R.RIGHT;
219
634
  default:
220
- throw new Error(`Invalid horizontal alignment: ${n}`);
635
+ throw new Error(`Invalid horizontal alignment: ${o}`);
221
636
  }
222
637
  }
223
- function it(n) {
224
- switch (n) {
225
- case C.LEFT:
638
+ function Mt(o) {
639
+ switch (o) {
640
+ case R.LEFT:
226
641
  return "left";
227
- case C.CENTER:
642
+ case R.CENTER:
228
643
  return "center";
229
- case C.RIGHT:
644
+ case R.RIGHT:
230
645
  return "normal";
231
646
  default:
232
- throw new Error(`Invalid horizontal alignment: ${n}`);
647
+ throw new Error(`Invalid horizontal alignment: ${o}`);
233
648
  }
234
649
  }
235
- function at(n) {
236
- switch (n) {
650
+ function jt(o) {
651
+ switch (o) {
237
652
  case "top":
238
- return I.TOP;
653
+ return b.TOP;
239
654
  case "middle":
240
- return I.MIDDLE;
655
+ return b.MIDDLE;
241
656
  case "bottom":
242
- return I.BOTTOM;
657
+ return b.BOTTOM;
243
658
  default:
244
- throw new Error(`Invalid vertical alignment: ${n}`);
659
+ throw new Error(`Invalid vertical alignment: ${o}`);
245
660
  }
246
661
  }
247
- function ht(n) {
248
- switch (n) {
249
- case I.TOP:
662
+ function Wt(o) {
663
+ switch (o) {
664
+ case b.TOP:
250
665
  return "top";
251
- case I.MIDDLE:
666
+ case b.MIDDLE:
252
667
  return "middle";
253
- case I.BOTTOM:
668
+ case b.BOTTOM:
254
669
  return "bottom";
255
670
  default:
256
- throw new Error(`Invalid vertical alignment: ${n}`);
671
+ throw new Error(`Invalid vertical alignment: ${o}`);
257
672
  }
258
673
  }
259
- function z(n) {
260
- return we(n) ? {
261
- f: n
262
- } : ke(n) ? {
263
- v: n
264
- } : (Se(n), n);
674
+ function J(o) {
675
+ return De(o) ? {
676
+ f: o
677
+ } : Me(o) ? {
678
+ v: o
679
+ } : (je(o), o);
265
680
  }
266
- function ct(n, e) {
267
- const t = new P(), { startRow: o, startColumn: s, endRow: r, endColumn: i } = e;
268
- if (Ce.isArray(n))
269
- for (let a = 0; a <= r - o; a++)
681
+ function Ot(o, e) {
682
+ const t = new j(), { startRow: n, startColumn: s, endRow: r, endColumn: i } = e;
683
+ if (We.isArray(o))
684
+ for (let a = 0; a <= r - n; a++)
270
685
  for (let h = 0; h <= i - s; h++)
271
- t.setValue(a + o, h + s, z(n[a][h]));
686
+ t.setValue(a + n, h + s, J(o[a][h]));
272
687
  else
273
- new P(n).forValue((h, c, d) => {
274
- t.setValue(h, c, z(d));
688
+ new j(o).forValue((h, c, d) => {
689
+ t.setValue(h, c, J(d));
275
690
  });
276
691
  return t.getMatrix();
277
692
  }
278
- function W(n, e) {
693
+ function H(o, e) {
279
694
  return {
280
- startRow: n.startRow,
281
- endRow: n.endRow,
695
+ startRow: o.startRow,
696
+ endRow: o.endRow,
282
697
  startColumn: 0,
283
698
  endColumn: e.getColumnCount() - 1,
284
- rangeType: l.ROW
699
+ rangeType: g.ROW
285
700
  };
286
701
  }
287
- function A(n, e) {
702
+ function $(o, e) {
288
703
  return {
289
704
  startRow: 0,
290
705
  endRow: e.getRowCount() - 1,
291
- startColumn: n.startColumn,
292
- endColumn: n.endColumn,
293
- rangeType: l.COLUMN
706
+ startColumn: o.startColumn,
707
+ endColumn: o.endColumn,
708
+ rangeType: g.COLUMN
294
709
  };
295
710
  }
296
- var dt = Object.defineProperty, ut = Object.getOwnPropertyDescriptor, mt = (n, e, t, o) => {
297
- for (var s = o > 1 ? void 0 : o ? ut(e, t) : e, r = n.length - 1, i; r >= 0; r--)
298
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
299
- return o && s && dt(e, t, s), s;
300
- }, D = (n, e) => (t, o) => e(t, o, n);
301
- let S = class extends b {
302
- constructor(n, e, t, o, s, r) {
303
- super(), this._workbook = n, this._worksheet = e, this._range = t, this._injector = o, this._commandService = s, this._formulaDataModel = r;
711
+ var Ft = Object.defineProperty, At = Object.getOwnPropertyDescriptor, Tt = (o, e, t, n) => {
712
+ for (var s = n > 1 ? void 0 : n ? At(e, t) : e, r = o.length - 1, i; r >= 0; r--)
713
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
714
+ return n && s && Ft(e, t, s), s;
715
+ }, G = (o, e) => (t, n) => e(t, n, o);
716
+ let S = class extends p {
717
+ constructor(o, e, t, n, s, r) {
718
+ super(), this._workbook = o, this._worksheet = e, this._range = t, this._injector = n, this._commandService = s, this._formulaDataModel = r;
304
719
  }
305
720
  /**
306
721
  * Get the unit ID of the current workbook
@@ -363,16 +778,16 @@ let S = class extends b {
363
778
  * @returns The cell model data
364
779
  */
365
780
  getCellData() {
366
- var n;
367
- return (n = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) != null ? n : null;
781
+ var o;
782
+ return (o = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) != null ? o : null;
368
783
  }
369
784
  /**
370
785
  * Return range whether this range is merged
371
786
  * @returns if true is merged
372
787
  */
373
788
  isMerged() {
374
- const { startColumn: n, startRow: e, endColumn: t, endRow: o } = this._range;
375
- return this._worksheet.getMergedCellRange(e, n, o, t).some((r) => T.equals(r, this._range));
789
+ const { startColumn: o, startRow: e, endColumn: t, endRow: n } = this._range;
790
+ return this._worksheet.getMergedCellRange(e, o, n, t).some((r) => N.equals(r, this._range));
376
791
  }
377
792
  /**
378
793
  * Return first cell style data in this range
@@ -380,16 +795,16 @@ let S = class extends b {
380
795
  */
381
796
  getCellStyleData() {
382
797
  var t;
383
- const n = this.getCellData(), e = this._workbook.getStyles();
384
- return n && e && (t = e.getStyleByCell(n)) != null ? t : null;
798
+ const o = this.getCellData(), e = this._workbook.getStyles();
799
+ return o && e && (t = e.getStyleByCell(o)) != null ? t : null;
385
800
  }
386
801
  /**
387
802
  * Returns the value of the cell at the start of this range.
388
803
  * @returns The value of the cell.
389
804
  */
390
805
  getValue() {
391
- var n, e;
392
- return (e = (n = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) == null ? void 0 : n.v) != null ? e : null;
806
+ var o, e;
807
+ return (e = (o = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) == null ? void 0 : o.v) != null ? e : null;
393
808
  }
394
809
  /**
395
810
  * Returns the rectangular grid of values for this range.
@@ -398,10 +813,10 @@ let S = class extends b {
398
813
  */
399
814
  getValues() {
400
815
  var r, i;
401
- const { startRow: n, endRow: e, startColumn: t, endColumn: o } = this._range, s = [];
402
- for (let a = n; a <= e; a++) {
816
+ const { startRow: o, endRow: e, startColumn: t, endColumn: n } = this._range, s = [];
817
+ for (let a = o; a <= e; a++) {
403
818
  const h = [];
404
- for (let c = t; c <= o; c++)
819
+ for (let c = t; c <= n; c++)
405
820
  h.push((i = (r = this._worksheet.getCell(a, c)) == null ? void 0 : r.v) != null ? i : null);
406
821
  s.push(h);
407
822
  }
@@ -412,10 +827,10 @@ let S = class extends b {
412
827
  * @returns A two-dimensional array of cell data.
413
828
  */
414
829
  getCellDataGrid() {
415
- const { startRow: n, endRow: e, startColumn: t, endColumn: o } = this._range, s = [];
416
- for (let r = n; r <= e; r++) {
830
+ const { startRow: o, endRow: e, startColumn: t, endColumn: n } = this._range, s = [];
831
+ for (let r = o; r <= e; r++) {
417
832
  const i = [];
418
- for (let a = t; a <= o; a++)
833
+ for (let a = t; a <= n; a++)
419
834
  i.push(this._worksheet.getCellRaw(r, a));
420
835
  s.push(i);
421
836
  }
@@ -426,52 +841,71 @@ let S = class extends b {
426
841
  * @returns A two-dimensional array of formulas in string format.
427
842
  */
428
843
  getFormulas() {
429
- const n = [], { startRow: e, endRow: t, startColumn: o, endColumn: s } = this._range, r = this._worksheet.getSheetId(), i = this._workbook.getUnitId();
844
+ const o = [], { startRow: e, endRow: t, startColumn: n, endColumn: s } = this._range, r = this._worksheet.getSheetId(), i = this._workbook.getUnitId();
430
845
  for (let a = e; a <= t; a++) {
431
846
  const h = [];
432
- for (let c = o; c <= s; c++) {
847
+ for (let c = n; c <= s; c++) {
433
848
  const d = this._formulaDataModel.getFormulaStringByCell(a, c, r, i);
434
849
  h.push(d || "");
435
850
  }
436
- n.push(h);
851
+ o.push(h);
437
852
  }
438
- return n;
853
+ return o;
439
854
  }
440
855
  getWrap() {
441
- return this._worksheet.getRange(this._range).getWrap() === m.TRUE;
856
+ return this._worksheet.getRange(this._range).getWrap() === u.TRUE;
442
857
  }
443
858
  getWrapStrategy() {
444
859
  return this._worksheet.getRange(this._range).getWrapStrategy();
445
860
  }
446
861
  getHorizontalAlignment() {
447
- return it(this._worksheet.getRange(this._range).getHorizontalAlignment());
862
+ return Mt(this._worksheet.getRange(this._range).getHorizontalAlignment());
448
863
  }
449
864
  getVerticalAlignment() {
450
- return ht(this._worksheet.getRange(this._range).getVerticalAlignment());
865
+ return Wt(this._worksheet.getRange(this._range).getVerticalAlignment());
451
866
  }
452
867
  // #region editing
453
- setBackgroundColor(n) {
454
- return this._commandService.executeCommand(_.id, {
868
+ /**
869
+ * Set background color for current range.
870
+ * @param color {string}
871
+ * @example
872
+ * ```
873
+ * univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackgroundColor('red')
874
+ * ```
875
+ */
876
+ setBackgroundColor(o) {
877
+ return this._commandService.executeCommand(C.id, {
455
878
  unitId: this._workbook.getUnitId(),
456
879
  subUnitId: this._worksheet.getSheetId(),
457
880
  range: this._range,
458
881
  style: {
459
882
  type: "bg",
460
883
  value: {
461
- rgb: n
884
+ rgb: o
462
885
  }
463
886
  }
464
887
  });
465
888
  }
889
+ /**
890
+ * Set background color for current range.
891
+ * @example
892
+ * ```
893
+ * univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackground('red')
894
+ * ```
895
+ * @param color {string}
896
+ */
897
+ setBackground(o) {
898
+ return this.setBackgroundColor(o);
899
+ }
466
900
  /**
467
901
  * The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.
468
902
  * @param value
469
903
  */
470
- setValue(n) {
471
- const e = z(n);
904
+ setValue(o) {
905
+ const e = J(o);
472
906
  if (!e)
473
907
  throw new Error("Invalid value");
474
- return this._commandService.executeCommand(G.id, {
908
+ return this._commandService.executeCommand(ne.id, {
475
909
  unitId: this._workbook.getUnitId(),
476
910
  subUnitId: this._worksheet.getSheetId(),
477
911
  range: this._range,
@@ -482,54 +916,54 @@ let S = class extends b {
482
916
  * Set the cell wrap of the given range.
483
917
  * Cells with wrap enabled (the default) resize to display their full content. Cells with wrap disabled display as much as possible in the cell without resizing or running to multiple lines.
484
918
  */
485
- setWrap(n) {
486
- return this._commandService.executeCommand(q.id, {
919
+ setWrap(o) {
920
+ return this._commandService.executeCommand(se.id, {
487
921
  unitId: this._workbook.getUnitId(),
488
922
  subUnitId: this._worksheet.getSheetId(),
489
923
  range: this._range,
490
- value: n ? H.WRAP : H.UNSPECIFIED
924
+ value: o ? Z.WRAP : Z.UNSPECIFIED
491
925
  });
492
926
  }
493
927
  /**
494
928
  * Sets the text wrapping strategy for the cells in the range.
495
929
  */
496
- setWrapStrategy(n) {
497
- return this._commandService.executeCommand(q.id, {
930
+ setWrapStrategy(o) {
931
+ return this._commandService.executeCommand(se.id, {
498
932
  unitId: this._workbook.getUnitId(),
499
933
  subUnitId: this._worksheet.getSheetId(),
500
934
  range: this._range,
501
- value: n
935
+ value: o
502
936
  });
503
937
  }
504
938
  /**
505
939
  * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).
506
940
  */
507
- setVerticalAlignment(n) {
508
- return this._commandService.executeCommand(Oe.id, {
941
+ setVerticalAlignment(o) {
942
+ return this._commandService.executeCommand(et.id, {
509
943
  unitId: this._workbook.getUnitId(),
510
944
  subUnitId: this._worksheet.getSheetId(),
511
945
  range: this._range,
512
- value: at(n)
946
+ value: jt(o)
513
947
  });
514
948
  }
515
949
  /**
516
950
  * Set the horizontal (left to right) alignment for the given range (left/center/right).
517
951
  */
518
- setHorizontalAlignment(n) {
519
- return this._commandService.executeCommand(Ve.id, {
952
+ setHorizontalAlignment(o) {
953
+ return this._commandService.executeCommand(tt.id, {
520
954
  unitId: this._workbook.getUnitId(),
521
955
  subUnitId: this._worksheet.getSheetId(),
522
956
  range: this._range,
523
- value: rt(n)
957
+ value: Dt(o)
524
958
  });
525
959
  }
526
960
  /**
527
961
  * Sets a different value for each cell in the range. The value can be a two-dimensional array or a standard range matrix (must match the dimensions of this range), consisting of numbers, strings, Boolean values or Composed of standard cell formats. If a value begins with `=`, it is interpreted as a formula.
528
962
  * @param value
529
963
  */
530
- setValues(n) {
531
- const e = ct(n, this._range);
532
- return this._commandService.executeCommand(G.id, {
964
+ setValues(o) {
965
+ const e = Ot(o, this._range);
966
+ return this._commandService.executeCommand(ne.id, {
533
967
  unitId: this._workbook.getUnitId(),
534
968
  subUnitId: this._worksheet.getSheetId(),
535
969
  range: this._range,
@@ -540,72 +974,72 @@ let S = class extends b {
540
974
  * Sets the font weight for the given range (normal/bold),
541
975
  * @param fontWeight The font weight, either 'normal' or 'bold'; a null value resets the font weight.
542
976
  */
543
- setFontWeight(n) {
977
+ setFontWeight(o) {
544
978
  let e;
545
- if (n === "bold")
546
- e = m.TRUE;
547
- else if (n === "normal")
548
- e = m.FALSE;
549
- else if (n === null)
979
+ if (o === "bold")
980
+ e = u.TRUE;
981
+ else if (o === "normal")
982
+ e = u.FALSE;
983
+ else if (o === null)
550
984
  e = null;
551
985
  else
552
986
  throw new Error("Invalid fontWeight");
553
987
  const t = {
554
988
  type: "bl",
555
989
  value: e
556
- }, o = {
990
+ }, n = {
557
991
  unitId: this._workbook.getUnitId(),
558
992
  subUnitId: this._worksheet.getSheetId(),
559
993
  range: this._range,
560
994
  style: t
561
995
  };
562
- return this._commandService.executeCommand(_.id, o), this;
996
+ return this._commandService.executeCommand(C.id, n), this;
563
997
  }
564
998
  /**
565
999
  * Sets the font style for the given range ('italic' or 'normal').
566
1000
  * @param fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.
567
1001
  */
568
- setFontStyle(n) {
1002
+ setFontStyle(o) {
569
1003
  let e;
570
- if (n === "italic")
571
- e = m.TRUE;
572
- else if (n === "normal")
573
- e = m.FALSE;
574
- else if (n === null)
1004
+ if (o === "italic")
1005
+ e = u.TRUE;
1006
+ else if (o === "normal")
1007
+ e = u.FALSE;
1008
+ else if (o === null)
575
1009
  e = null;
576
1010
  else
577
1011
  throw new Error("Invalid fontStyle");
578
1012
  const t = {
579
1013
  type: "it",
580
1014
  value: e
581
- }, o = {
1015
+ }, n = {
582
1016
  unitId: this._workbook.getUnitId(),
583
1017
  subUnitId: this._worksheet.getSheetId(),
584
1018
  range: this._range,
585
1019
  style: t
586
1020
  };
587
- return this._commandService.executeCommand(_.id, o), this;
1021
+ return this._commandService.executeCommand(C.id, n), this;
588
1022
  }
589
1023
  /**
590
1024
  * Sets the font line style of the given range ('underline', 'line-through', or 'none').
591
1025
  * @param fontLine The font line style, either 'underline', 'line-through', or 'none'; a null value resets the font line style.
592
1026
  */
593
- setFontLine(n) {
594
- if (n === "underline")
1027
+ setFontLine(o) {
1028
+ if (o === "underline")
595
1029
  this._setFontUnderline({
596
- s: m.TRUE
1030
+ s: u.TRUE
597
1031
  });
598
- else if (n === "line-through")
1032
+ else if (o === "line-through")
599
1033
  this._setFontStrikethrough({
600
- s: m.TRUE
1034
+ s: u.TRUE
601
1035
  });
602
- else if (n === "none")
1036
+ else if (o === "none")
603
1037
  this._setFontUnderline({
604
- s: m.FALSE
1038
+ s: u.FALSE
605
1039
  }), this._setFontStrikethrough({
606
- s: m.FALSE
1040
+ s: u.FALSE
607
1041
  });
608
- else if (n === null)
1042
+ else if (o === null)
609
1043
  this._setFontUnderline(null), this._setFontStrikethrough(null);
610
1044
  else
611
1045
  throw new Error("Invalid fontLine");
@@ -614,170 +1048,368 @@ let S = class extends b {
614
1048
  /**
615
1049
  * Sets the font underline style of the given ITextDecoration
616
1050
  */
617
- _setFontUnderline(n) {
1051
+ _setFontUnderline(o) {
618
1052
  const e = {
619
1053
  type: "ul",
620
- value: n
1054
+ value: o
621
1055
  }, t = {
622
1056
  unitId: this._workbook.getUnitId(),
623
1057
  subUnitId: this._worksheet.getSheetId(),
624
1058
  range: this._range,
625
1059
  style: e
626
1060
  };
627
- this._commandService.executeCommand(_.id, t);
1061
+ this._commandService.executeCommand(C.id, t);
628
1062
  }
629
1063
  /**
630
1064
  * Sets the font strikethrough style of the given ITextDecoration
631
1065
  */
632
- _setFontStrikethrough(n) {
1066
+ _setFontStrikethrough(o) {
633
1067
  const e = {
634
1068
  type: "st",
635
- value: n
1069
+ value: o
636
1070
  }, t = {
637
1071
  unitId: this._workbook.getUnitId(),
638
1072
  subUnitId: this._worksheet.getSheetId(),
639
1073
  range: this._range,
640
1074
  style: e
641
1075
  };
642
- this._commandService.executeCommand(_.id, t);
1076
+ this._commandService.executeCommand(C.id, t);
643
1077
  }
644
1078
  /**
645
1079
  * Sets the font family, such as "Arial" or "Helvetica".
646
1080
  * @param fontFamily The font family to set; a null value resets the font family.
647
1081
  */
648
- setFontFamily(n) {
1082
+ setFontFamily(o) {
649
1083
  const e = {
650
1084
  type: "ff",
651
- value: n
1085
+ value: o
652
1086
  }, t = {
653
1087
  unitId: this._workbook.getUnitId(),
654
1088
  subUnitId: this._worksheet.getSheetId(),
655
1089
  range: this._range,
656
1090
  style: e
657
1091
  };
658
- return this._commandService.executeCommand(_.id, t), this;
1092
+ return this._commandService.executeCommand(C.id, t), this;
659
1093
  }
660
1094
  /**
661
1095
  * Sets the font size, with the size being the point size to use.
662
1096
  * @param size A font size in point size. A null value resets the font size.
663
1097
  */
664
- setFontSize(n) {
1098
+ setFontSize(o) {
665
1099
  const e = {
666
1100
  type: "fs",
667
- value: n
1101
+ value: o
668
1102
  }, t = {
669
1103
  unitId: this._workbook.getUnitId(),
670
1104
  subUnitId: this._worksheet.getSheetId(),
671
1105
  range: this._range,
672
1106
  style: e
673
1107
  };
674
- return this._commandService.executeCommand(_.id, t), this;
1108
+ return this._commandService.executeCommand(C.id, t), this;
675
1109
  }
676
1110
  /**
677
1111
  * Sets the font color in CSS notation (such as '#ffffff' or 'white').
678
1112
  * @param color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color.
679
1113
  */
680
- setFontColor(n) {
1114
+ setFontColor(o) {
681
1115
  const t = {
682
1116
  type: "cl",
683
- value: n === null ? null : { rgb: n }
684
- }, o = {
1117
+ value: o === null ? null : { rgb: o }
1118
+ }, n = {
685
1119
  unitId: this._workbook.getUnitId(),
686
1120
  subUnitId: this._worksheet.getSheetId(),
687
1121
  range: this._range,
688
1122
  style: t
689
1123
  };
690
- return this._commandService.executeCommand(_.id, o), this;
1124
+ return this._commandService.executeCommand(C.id, n), this;
691
1125
  }
692
1126
  // #endregion editing
693
1127
  //#region Merge cell
694
1128
  /**
695
1129
  * Merge cells in a range into one merged cell
1130
+ *
1131
+ * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
1132
+ *
696
1133
  * @returns This range, for chaining
697
1134
  */
698
- async merge() {
699
- const n = this._workbook.getUnitId(), e = this._worksheet.getSheetId();
700
- return await M(this._injector, n, e, [this._range]), this;
1135
+ async merge(o = !0) {
1136
+ const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId();
1137
+ return await L(this._injector, e, t, [this._range], o), this;
701
1138
  }
702
1139
  /**
703
1140
  * Merges cells in a range horizontally.
1141
+ *
1142
+ * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
1143
+ *
704
1144
  * @returns This range, for chaining
705
1145
  */
706
- async mergeAcross() {
707
- const n = Y([this._range], N.ROWS), e = this._workbook.getUnitId(), t = this._worksheet.getSheetId();
708
- return await M(this._injector, e, t, n), this;
1146
+ async mergeAcross(o = !0) {
1147
+ const e = oe([this._range], ee.ROWS), t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
1148
+ return await L(this._injector, t, n, e, o), this;
709
1149
  }
710
1150
  /**
711
1151
  * Merges cells in a range vertically.
1152
+ *
1153
+ * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
1154
+ *
712
1155
  * @returns This range, for chaining
713
1156
  */
714
- async mergeVertically() {
715
- const n = Y([this._range], N.COLUMNS), e = this._workbook.getUnitId(), t = this._worksheet.getSheetId();
716
- return await M(this._injector, e, t, n), this;
1157
+ async mergeVertically(o = !0) {
1158
+ const e = oe([this._range], ee.COLUMNS), t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
1159
+ return await L(this._injector, t, n, e, o), this;
717
1160
  }
718
1161
  /**
719
1162
  * Returns true if cells in the current range overlap a merged cell.
720
1163
  * @returns {boolean} is overlap with a merged cell
721
1164
  */
722
1165
  isPartOfMerge() {
723
- const { startRow: n, startColumn: e, endRow: t, endColumn: o } = this._range;
724
- return this._worksheet.getMergedCellRange(n, e, t, o).length > 0;
1166
+ const { startRow: o, startColumn: e, endRow: t, endColumn: n } = this._range;
1167
+ return this._worksheet.getMergedCellRange(o, e, t, n).length > 0;
725
1168
  }
726
1169
  /**
727
- * Unmerge cells in the range
1170
+ * Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.
728
1171
  * @returns This range, for chaining
729
1172
  */
730
1173
  breakApart() {
731
- return this._commandService.executeCommand(ze.id, { ranges: [this._range] }), this;
1174
+ return this._commandService.executeCommand(nt.id, { ranges: [this._range] }), this;
732
1175
  }
733
1176
  //#endregion
734
1177
  /**
735
1178
  * Iterate cells in this range. Merged cells will be respected.
736
- * @param callback
737
- */
738
- forEach(n) {
739
- const { startColumn: e, startRow: t, endColumn: o, endRow: s } = this._range;
740
- this._worksheet.getMatrixWithMergedCells(t, e, s, o).forValue((r, i, a) => {
741
- n(r, i, a);
1179
+ * @param callback the callback function to be called for each cell in the range
1180
+ * @param {number} callback.row the row number of the cell
1181
+ * @param {number} callback.col the column number of the cell
1182
+ * @param {ICellData} callback.cell the cell data
1183
+ * ```ts
1184
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1185
+ * const fWorksheet = fWorkbook.getActiveSheet();
1186
+ * const fRange = fWorksheet.getRange('A1:B2');
1187
+ * fRange.forEach((row, col, cell) => {
1188
+ * console.log(row, col, cell);
1189
+ * });
1190
+ * ```
1191
+ */
1192
+ forEach(o) {
1193
+ const { startColumn: e, startRow: t, endColumn: n, endRow: s } = this._range;
1194
+ this._worksheet.getMatrixWithMergedCells(t, e, s, n).forValue((r, i, a) => {
1195
+ o(r, i, a);
1196
+ });
1197
+ }
1198
+ /**
1199
+ * Returns a string description of the range, in A1 notation.
1200
+ * @returns {string} The A1 notation of the range.
1201
+ * ```ts
1202
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1203
+ * const fWorksheet = fWorkbook.getActiveSheet();
1204
+ * const fRange = fWorksheet.getRange('A1:B2');
1205
+ * console.log(fRange.getA1Notation()); // A1:B2
1206
+ * ```
1207
+ */
1208
+ getA1Notation(o) {
1209
+ return o ? Be(this._worksheet.getName(), this._range) : X(this._range);
1210
+ }
1211
+ /**
1212
+ * Sets the specified range as the active range, with the top left cell in the range as the current cell.
1213
+ * @returns {FRange} This range, for chaining.
1214
+ * @example
1215
+ * ```ts
1216
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1217
+ * const fWorksheet = fWorkbook.getActiveSheet();
1218
+ * const fRange = fWorksheet.getRange('A1:B2');
1219
+ * fRange.activate(); // the active cell will be A1
1220
+ * ```
1221
+ */
1222
+ activate() {
1223
+ return this._injector.createInstance(I, this._workbook).setActiveRange(this), this;
1224
+ }
1225
+ /**
1226
+ * Sets the specified cell as the current cell.
1227
+ * If the specified cell is present in an existing range, then that range becomes the active range with the cell as the current cell.
1228
+ * If the specified cell is not part of an existing range, then a new range is created with the cell as the active range and the current cell.
1229
+ * @returns {FRange} This range, for chaining.
1230
+ * @description If the range is not a single cell, an error will be thrown.
1231
+ */
1232
+ activateAsCurrentCell() {
1233
+ const o = this._worksheet.getMergedCell(this._range.startRow, this._range.startColumn);
1234
+ if (o && N.equals(o, this._range) || !o && this._range.startRow === this._range.endRow && this._range.startColumn === this._range.endColumn)
1235
+ return this.activate();
1236
+ throw new Error("The range is not a single cell");
1237
+ }
1238
+ /**
1239
+ * Splits a column of text into multiple columns based on a custom specified delimiter.
1240
+ * @param {boolean} [treatMultipleDelimitersAsOne] Whether to treat multiple continuous delimiters as one. The default value is false.
1241
+ * @param {SplitDelimiterEnum} [delimiter] The delimiter to use to split the text. The default delimiter is Tab(1)、Comma(2)、Semicolon(4)、Space(8)、Custom(16).A delimiter like 6 (SplitDelimiterEnum.Comma|SplitDelimiterEnum.Semicolon) means using Comma and Semicolon to split the text.
1242
+ * @param {string} [customDelimiter] The custom delimiter to split the text. An error will be thrown if custom delimiter is set but the customDelimiter is not a character.
1243
+ * @example Show how to split text to columns with combined delimiter. The bit operations are used to combine the delimiters.
1244
+ * // A1:A3 has following values:
1245
+ * // A | B | C
1246
+ * // 1;;2;3 | |
1247
+ * // 1;,2;3 | |
1248
+ * // After calling splitTextToColumns(false, SplitDelimiterEnum.Semicolon|SplitDelimiterEnum.Comma), the range will be:
1249
+ * // A | B | C | D
1250
+ * // 1 | | 2 | 3
1251
+ * // 1 | | 2 | 3
1252
+ * // After calling splitTextToColumns(true, SplitDelimiterEnum.Semicolon|SplitDelimiterEnum.Comma), the range will be:
1253
+ * // A | B | C
1254
+ * // 1 | 2 | 3
1255
+ * // 1 | 2 | 3
1256
+ * @example Show how to split text to columns with custom delimiter
1257
+ * // A1:A3 has following values:
1258
+ * // A | B | C
1259
+ * // 1#2#3 | |
1260
+ * // 4##5#6 | |
1261
+ * // After calling splitTextToColumns(false, SplitDelimiterEnum.Custom, '#'), the range will be:
1262
+ * // A | B | C | D
1263
+ * // 1 | 2 | 3 |
1264
+ * // 4 | | 5 | 6
1265
+ * // After calling splitTextToColumns(true, SplitDelimiterEnum.Custom, '#'), the range will be:
1266
+ * // A | B | C
1267
+ * // 1 | 2 | 3
1268
+ * // 4 | 5 | 6
1269
+ */
1270
+ splitTextToColumns(o, e, t) {
1271
+ this._commandService.executeCommand(st.id, {
1272
+ unitId: this._workbook.getUnitId(),
1273
+ subUnitId: this._worksheet.getSheetId(),
1274
+ range: this._range,
1275
+ delimiter: e,
1276
+ customDelimiter: t,
1277
+ treatMultipleDelimitersAsOne: o
742
1278
  });
743
1279
  }
744
1280
  };
745
- S = mt([
746
- D(3, u(R)),
747
- D(4, v),
748
- D(5, u(et))
1281
+ S = Tt([
1282
+ G(3, m(v)),
1283
+ G(4, l),
1284
+ G(5, m(Le))
749
1285
  ], S);
750
- var lt = Object.defineProperty, gt = Object.getOwnPropertyDescriptor, _t = (n, e, t, o) => {
751
- for (var s = o > 1 ? void 0 : o ? gt(e, t) : e, r = n.length - 1, i; r >= 0; r--)
752
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
753
- return o && s && lt(e, t, s), s;
754
- }, wt = (n, e) => (t, o) => e(t, o, n);
755
- let L = class {
756
- constructor(n, e, t, o) {
757
- this._workbook = n, this._worksheet = e, this._selections = t, this._injector = o;
1286
+ var Lt = Object.defineProperty, Bt = Object.getOwnPropertyDescriptor, zt = (o, e, t, n) => {
1287
+ for (var s = n > 1 ? void 0 : n ? Bt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
1288
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
1289
+ return n && s && Lt(e, t, s), s;
1290
+ }, Vt = (o, e) => (t, n) => e(t, n, o);
1291
+ let F = class {
1292
+ constructor(o, e, t, n) {
1293
+ this._workbook = o, this._worksheet = e, this._selections = t, this._injector = n;
758
1294
  }
1295
+ /**
1296
+ * Represents the active selection in the sheet. Which means the selection contains the active cell.
1297
+ * @returns {FRange | null} The active selection.
1298
+ */
759
1299
  getActiveRange() {
760
- const n = this._selections.find((e) => !!e.primary);
761
- return n ? this._injector.createInstance(S, this._workbook, this._worksheet, n.range) : null;
1300
+ const o = this._selections.find((e) => !!e.primary);
1301
+ return o ? this._injector.createInstance(S, this._workbook, this._worksheet, o.range) : null;
1302
+ }
1303
+ /**
1304
+ * Represents the active selection list in the sheet.
1305
+ * @returns {FRange[]} The active selection list.
1306
+ */
1307
+ getActiveRangeList() {
1308
+ return this._selections.map((o) => this._injector.createInstance(S, this._workbook, this._worksheet, o.range));
1309
+ }
1310
+ /**
1311
+ * Represents the current select cell in the sheet.
1312
+ * @returns {ISelectionCell} The current select cell info.Pay attention to the type of the return value.
1313
+ */
1314
+ getCurrentCell() {
1315
+ const o = this._selections.find((e) => !!e.primary);
1316
+ return o ? o.primary : null;
1317
+ }
1318
+ /**
1319
+ * Returns the active sheet in the spreadsheet.
1320
+ * @returns {FWorksheet} The active sheet in the spreadsheet.
1321
+ * @example
1322
+ * ```ts
1323
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1324
+ * const fWorksheet = fWorkbook.getActiveSheet();
1325
+ * const fSelection = fWorksheet.getSelection();
1326
+ * const activeSheet = fSelection.getActiveSheet();
1327
+ * console.log(activeSheet.equalTo(fWorksheet)); // true
1328
+ * ```
1329
+ */
1330
+ getActiveSheet() {
1331
+ const o = this._injector.createInstance(I, this._workbook);
1332
+ return this._injector.createInstance(_, o, this._workbook, this._worksheet);
1333
+ }
1334
+ /**
1335
+ * Update the primary cell in the selection. if the primary cell not exists in selections, add it to the selections and clear the old selections.
1336
+ * @param {FRange} cell The new primary cell to update.
1337
+ * @returns {FSelection} The new selection after updating the primary cell.Because the selection is immutable, the return value is a new selection.
1338
+ * @example
1339
+ * ```ts
1340
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1341
+ * const fWorksheet = fWorkbook.getActiveSheet();
1342
+ * const fSelection = fWorksheet.getSelection();
1343
+ * const cell = fWorksheet.getCell('A1');
1344
+ * const newSelection = fSelection.updatePrimaryCell(cell);
1345
+ * console.log(newSelection.getActiveRange().getA1Notation()); // A1
1346
+ * ```
1347
+ */
1348
+ async updatePrimaryCell(o) {
1349
+ const e = this._injector.get(l);
1350
+ let t = [], n = !1;
1351
+ for (const { range: r, style: i } of this._selections)
1352
+ N.contains(r, o.getRange()) ? (t.push({
1353
+ range: r,
1354
+ primary: Y(o.getRange(), this._worksheet),
1355
+ style: i
1356
+ }), n = !0) : t.push({
1357
+ range: r,
1358
+ primary: null,
1359
+ style: i
1360
+ });
1361
+ n || (t = [
1362
+ {
1363
+ range: o.getRange(),
1364
+ primary: Y(o.getRange(), this._worksheet)
1365
+ }
1366
+ ]);
1367
+ const s = {
1368
+ unitId: this._workbook.getUnitId(),
1369
+ subUnitId: this._worksheet.getSheetId(),
1370
+ selections: t
1371
+ };
1372
+ return await e.syncExecuteCommand(Ue.id, s), new F(this._workbook, this._worksheet, t, this._injector);
1373
+ }
1374
+ /**
1375
+ *Get the next primary cell in the specified direction. If the primary cell not exists in selections, return null.
1376
+ * @param {Direction} direction The direction to move the primary cell.The enum value is maybe one of the following: UP(0),RIGHT(1), DOWN(2), LEFT(3).
1377
+ * @returns {FRange | null} The next primary cell in the specified direction.
1378
+ * @example
1379
+ * ```ts
1380
+ * // import { Direction } from '@univerjs/core';
1381
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1382
+ * const fWorksheet = fWorkbook.getActiveSheet();
1383
+ * // make sure the active cell is A1 and selection is A1:C3
1384
+ * const fSelection = fWorksheet.getSelection();
1385
+ * const nextCell = fSelection.getNextDataRange(Direction.RIGHT);
1386
+ * console.log(nextCell?.getA1Notation()); // B1
1387
+ * ```
1388
+ */
1389
+ getNextDataRange(o) {
1390
+ if (!this._selections.find((n) => !!n.primary))
1391
+ return null;
1392
+ const t = ot(this._selections.concat(), o, this._worksheet);
1393
+ return t ? this._injector.createInstance(S, this._workbook, this._worksheet, t) : null;
762
1394
  }
763
1395
  };
764
- L = _t([
765
- wt(3, u(R))
766
- ], L);
767
- var kt = Object.defineProperty, St = Object.getOwnPropertyDescriptor, Ct = (n, e, t, o) => {
768
- for (var s = o > 1 ? void 0 : o ? St(e, t) : e, r = n.length - 1, i; r >= 0; r--)
769
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
770
- return o && s && kt(e, t, s), s;
771
- }, j = (n, e) => (t, o) => e(t, o, n);
772
- let g = class extends b {
773
- constructor(e, t, o, s, r, i) {
1396
+ F = zt([
1397
+ Vt(3, m(v))
1398
+ ], F);
1399
+ var Ht = Object.defineProperty, $t = Object.getOwnPropertyDescriptor, Gt = (o, e, t, n) => {
1400
+ for (var s = n > 1 ? void 0 : n ? $t(e, t) : e, r = o.length - 1, i; r >= 0; r--)
1401
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
1402
+ return n && s && Ht(e, t, s), s;
1403
+ }, M = (o, e) => (t, n) => e(t, n, o);
1404
+ let _ = class extends p {
1405
+ constructor(e, t, n, s, r, i, a) {
774
1406
  super();
775
1407
  /**
776
1408
  * Sets the active selection region for this sheet.
777
1409
  * @param range The range to set as the active selection.
778
1410
  */
779
- E(this, "setActiveSelection", this.setActiveRange);
780
- this._fWorkbook = e, this._workbook = t, this._worksheet = o, this._injector = s, this._selectionManagerService = r, this._commandService = i;
1411
+ P(this, "setActiveSelection", this.setActiveRange);
1412
+ this._fWorkbook = e, this._workbook = t, this._worksheet = n, this._injector = s, this._selectionManagerService = r, this._logService = i, this._commandService = a;
781
1413
  }
782
1414
  /**
783
1415
  * Returns the injector
@@ -788,34 +1420,38 @@ let g = class extends b {
788
1420
  }
789
1421
  /**
790
1422
  * Returns the workbook
791
- * @returns The workbook
1423
+ * @returns {Workbook} The workbook instance.
792
1424
  */
793
1425
  getWorkbook() {
794
1426
  return this._workbook;
795
1427
  }
796
1428
  /**
797
- * Returns the worksheet id
798
- * @returns The id of the worksheet
1429
+ * Returns the worksheet id.
1430
+ * @returns {string} The id of the worksheet.
799
1431
  */
800
1432
  getSheetId() {
801
1433
  return this._worksheet.getSheetId();
802
1434
  }
803
1435
  /**
804
- * Returns the worksheet name
805
- * @returns The name of the worksheet
1436
+ * Returns the worksheet name.
1437
+ * @returns {string} The name of the worksheet.
806
1438
  */
807
1439
  getSheetName() {
808
1440
  return this._worksheet.getName();
809
1441
  }
1442
+ /**
1443
+ * Represents the selection ranges info of the worksheet.
1444
+ * @returns {FSelection} return the current selections of the worksheet or null if there is no selection.
1445
+ */
810
1446
  getSelection() {
811
1447
  const e = this._selectionManagerService.getCurrentSelections();
812
- return e ? this._injector.createInstance(L, this._workbook, this._worksheet, e) : null;
1448
+ return e ? this._injector.createInstance(F, this._workbook, this._worksheet, e) : null;
813
1449
  }
814
1450
  // #region rows
815
1451
  // #region default style
816
1452
  /**
817
1453
  * Get the default style of the worksheet
818
- * @returns Default style
1454
+ * @returns {IStyleData} Default style of the worksheet.
819
1455
  */
820
1456
  getDefaultStyle() {
821
1457
  return this._worksheet.getDefaultCellStyle();
@@ -840,14 +1476,14 @@ let g = class extends b {
840
1476
  }
841
1477
  /**
842
1478
  * Set the default style of the worksheet
843
- * @param style default style
844
- * @returns this worksheet
1479
+ * @param {StyleDataInfo} style default style
1480
+ * @returns {Promise<FWorksheet>} This sheet, for chaining.
845
1481
  */
846
1482
  async setDefaultStyle(e) {
847
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId();
848
- return await this._commandService.executeCommand(Le.id, {
1483
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
1484
+ return await this._commandService.executeCommand(rt.id, {
849
1485
  unitId: t,
850
- subUnitId: o,
1486
+ subUnitId: n,
851
1487
  defaultStyle: e
852
1488
  }), this._worksheet.setDefaultCellStyle(e), this;
853
1489
  }
@@ -855,10 +1491,11 @@ let g = class extends b {
855
1491
  * Set the default style of the worksheet row
856
1492
  * @param {number} index The row index
857
1493
  * @param {string | Nullable<IStyleData>} style The style name or style data
1494
+ * @returns {Promise<FWorksheet>} This sheet, for chaining.
858
1495
  */
859
1496
  async setColumnDefaultStyle(e, t) {
860
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
861
- unitId: o,
1497
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1498
+ unitId: n,
862
1499
  subUnitId: s,
863
1500
  columnData: {
864
1501
  [e]: {
@@ -866,16 +1503,17 @@ let g = class extends b {
866
1503
  }
867
1504
  }
868
1505
  };
869
- return await this._commandService.executeCommand(J.id, r), this;
1506
+ return await this._commandService.executeCommand(re.id, r), this;
870
1507
  }
871
1508
  /**
872
1509
  * Set the default style of the worksheet column
873
1510
  * @param {number} index The column index
874
1511
  * @param {string | Nullable<IStyleData>} style The style name or style data
1512
+ * @returns {Promise<FWorksheet>} This sheet, for chaining.
875
1513
  */
876
1514
  async setRowDefaultStyle(e, t) {
877
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
878
- unitId: o,
1515
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1516
+ unitId: n,
879
1517
  subUnitId: s,
880
1518
  rowData: {
881
1519
  [e]: {
@@ -883,12 +1521,12 @@ let g = class extends b {
883
1521
  }
884
1522
  }
885
1523
  };
886
- return await this._commandService.executeCommand(K.id, r), this;
1524
+ return await this._commandService.executeCommand(ie.id, r), this;
887
1525
  }
888
- getRange(e, t, o, s) {
1526
+ getRange(e, t, n, s) {
889
1527
  let r, i;
890
1528
  if (typeof e == "string") {
891
- const { range: a, sheetName: h } = tt(e), c = h ? this._workbook.getSheetBySheetName(h) : this._worksheet;
1529
+ const { range: a, sheetName: h } = ze(e), c = h ? this._workbook.getSheetBySheetName(h) : this._worksheet;
892
1530
  if (!c)
893
1531
  throw new Error("Range not found");
894
1532
  i = c, r = {
@@ -897,16 +1535,16 @@ let g = class extends b {
897
1535
  sheetId: i.getSheetId(),
898
1536
  // Use the current range instead of the future actual range to match Apps Script behavior.
899
1537
  // Users can create the latest range in real time when needed.
900
- rangeType: l.NORMAL,
901
- startRow: a.rangeType === l.COLUMN ? 0 : a.startRow,
902
- endRow: a.rangeType === l.COLUMN ? i.getMaxRows() - 1 : a.endRow,
903
- startColumn: a.rangeType === l.ROW ? 0 : a.startColumn,
904
- endColumn: a.rangeType === l.ROW ? i.getMaxColumns() - 1 : a.endColumn
1538
+ rangeType: g.NORMAL,
1539
+ startRow: a.rangeType === g.COLUMN ? 0 : a.startRow,
1540
+ endRow: a.rangeType === g.COLUMN ? i.getMaxRows() - 1 : a.endRow,
1541
+ startColumn: a.rangeType === g.ROW ? 0 : a.startColumn,
1542
+ endColumn: a.rangeType === g.ROW ? i.getMaxColumns() - 1 : a.endColumn
905
1543
  };
906
1544
  } else if (typeof e == "number" && t !== void 0)
907
1545
  i = this._worksheet, r = {
908
1546
  startRow: e,
909
- endRow: e + (o != null ? o : 1) - 1,
1547
+ endRow: e + (n != null ? n : 1) - 1,
910
1548
  startColumn: t,
911
1549
  endColumn: t + (s != null ? s : 1) - 1,
912
1550
  unitId: this._workbook.getUnitId(),
@@ -962,9 +1600,9 @@ let g = class extends b {
962
1600
  * @returns This sheet, for chaining.
963
1601
  */
964
1602
  async insertRowsAfter(e, t) {
965
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = p.DOWN, i = e + 1, a = e + t, h = 0, c = this._worksheet.getColumnCount() - 1, d = y(this._worksheet, i, a, h, c, !0, e);
966
- return await this._commandService.executeCommand(Q.id, {
967
- unitId: o,
1603
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = E.DOWN, i = e + 1, a = e + t, h = 0, c = this._worksheet.getColumnCount() - 1, d = D(this._worksheet, i, a, h, c, !0, e);
1604
+ return await this._commandService.executeCommand(ae.id, {
1605
+ unitId: n,
968
1606
  subUnitId: s,
969
1607
  direction: r,
970
1608
  range: {
@@ -983,9 +1621,9 @@ let g = class extends b {
983
1621
  * @returns This sheet, for chaining.
984
1622
  */
985
1623
  async insertRowsBefore(e, t) {
986
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = p.UP, i = e, a = e + t - 1, h = 0, c = this._worksheet.getColumnCount() - 1, d = y(this._worksheet, i, a, h, c, !0, e - 1);
987
- return await this._commandService.executeCommand(Q.id, {
988
- unitId: o,
1624
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = E.UP, i = e, a = e + t - 1, h = 0, c = this._worksheet.getColumnCount() - 1, d = D(this._worksheet, i, a, h, c, !0, e - 1);
1625
+ return await this._commandService.executeCommand(ae.id, {
1626
+ unitId: n,
989
1627
  subUnitId: s,
990
1628
  direction: r,
991
1629
  range: {
@@ -1012,14 +1650,14 @@ let g = class extends b {
1012
1650
  * @returns This sheet, for chaining.
1013
1651
  */
1014
1652
  async deleteRows(e, t) {
1015
- const o = {
1653
+ const n = {
1016
1654
  startRow: e,
1017
1655
  endRow: e + t - 1,
1018
1656
  startColumn: 0,
1019
1657
  endColumn: this._worksheet.getColumnCount() - 1
1020
1658
  };
1021
- return await this._commandService.executeCommand(Be.id, {
1022
- range: o
1659
+ return await this._commandService.executeCommand(it.id, {
1660
+ range: n
1023
1661
  }), this;
1024
1662
  }
1025
1663
  /**
@@ -1029,14 +1667,14 @@ let g = class extends b {
1029
1667
  * @returns This sheet, for chaining.
1030
1668
  */
1031
1669
  async moveRows(e, t) {
1032
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = W(e.getRange(), this._worksheet), i = r, a = {
1670
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = H(e.getRange(), this._worksheet), i = r, a = {
1033
1671
  startRow: t,
1034
1672
  endRow: t,
1035
1673
  startColumn: r.startColumn,
1036
1674
  endColumn: r.endColumn
1037
1675
  };
1038
- return await this._commandService.executeCommand(He.id, {
1039
- unitId: o,
1676
+ return await this._commandService.executeCommand(at.id, {
1677
+ unitId: n,
1040
1678
  subUnitId: s,
1041
1679
  range: r,
1042
1680
  fromRange: i,
@@ -1049,10 +1687,10 @@ let g = class extends b {
1049
1687
  * @returns This sheet, for chaining.
1050
1688
  */
1051
1689
  async hideRow(e) {
1052
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = W(e.getRange(), this._worksheet);
1053
- return await this._commandService.executeCommand(X.id, {
1690
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = H(e.getRange(), this._worksheet);
1691
+ return await this._commandService.executeCommand(he.id, {
1054
1692
  unitId: t,
1055
- subUnitId: o,
1693
+ subUnitId: n,
1056
1694
  ranges: [s]
1057
1695
  }), this;
1058
1696
  }
@@ -1063,15 +1701,15 @@ let g = class extends b {
1063
1701
  * @returns This sheet, for chaining.
1064
1702
  */
1065
1703
  async hideRows(e, t = 1) {
1066
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1704
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1067
1705
  startRow: e,
1068
1706
  endRow: e + t - 1,
1069
1707
  startColumn: 0,
1070
1708
  endColumn: this._worksheet.getColumnCount() - 1,
1071
- rangeType: l.ROW
1709
+ rangeType: g.ROW
1072
1710
  };
1073
- return await this._commandService.executeCommand(X.id, {
1074
- unitId: o,
1711
+ return await this._commandService.executeCommand(he.id, {
1712
+ unitId: n,
1075
1713
  subUnitId: s,
1076
1714
  ranges: [r]
1077
1715
  }), this;
@@ -1082,10 +1720,10 @@ let g = class extends b {
1082
1720
  * @returns This sheet, for chaining.
1083
1721
  */
1084
1722
  async unhideRow(e) {
1085
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = W(e.getRange(), this._worksheet);
1086
- return await this._commandService.executeCommand(Z.id, {
1723
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = H(e.getRange(), this._worksheet);
1724
+ return await this._commandService.executeCommand(ce.id, {
1087
1725
  unitId: t,
1088
- subUnitId: o,
1726
+ subUnitId: n,
1089
1727
  ranges: [s]
1090
1728
  }), this;
1091
1729
  }
@@ -1096,15 +1734,15 @@ let g = class extends b {
1096
1734
  * @returns This sheet, for chaining.
1097
1735
  */
1098
1736
  async showRows(e, t = 1) {
1099
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1737
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1100
1738
  startRow: e,
1101
1739
  endRow: e + t - 1,
1102
1740
  startColumn: 0,
1103
1741
  endColumn: this._worksheet.getColumnCount() - 1,
1104
- rangeType: l.ROW
1742
+ rangeType: g.ROW
1105
1743
  };
1106
- return await this._commandService.executeCommand(Z.id, {
1107
- unitId: o,
1744
+ return await this._commandService.executeCommand(ce.id, {
1745
+ unitId: n,
1108
1746
  subUnitId: s,
1109
1747
  ranges: [r]
1110
1748
  }), this;
@@ -1125,24 +1763,24 @@ let g = class extends b {
1125
1763
  * @param height The height in pixels to set it to.
1126
1764
  * @returns This sheet, for chaining.
1127
1765
  */
1128
- async setRowHeights(e, t, o) {
1766
+ async setRowHeights(e, t, n) {
1129
1767
  var c;
1130
1768
  const s = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = this._worksheet.getRowManager(), a = [], h = [];
1131
1769
  for (let d = e; d < e + t; d++) {
1132
- const x = ((c = i.getRow(d)) == null ? void 0 : c.ah) || this._worksheet.getConfig().defaultRowHeight, B = {
1770
+ const T = ((c = i.getRow(d)) == null ? void 0 : c.ah) || this._worksheet.getConfig().defaultRowHeight, x = {
1133
1771
  startRow: d,
1134
1772
  endRow: d,
1135
1773
  startColumn: 0,
1136
1774
  endColumn: this._worksheet.getColumnCount() - 1
1137
1775
  };
1138
- o <= x ? a.push(B) : h.push(B);
1776
+ n <= T ? a.push(x) : h.push(x);
1139
1777
  }
1140
- return h.length > 0 && await this._commandService.executeCommand(ee.id, {
1778
+ return h.length > 0 && await this._commandService.executeCommand(de.id, {
1141
1779
  unitId: s,
1142
1780
  subUnitId: r,
1143
1781
  ranges: h,
1144
- value: o
1145
- }), a.length > 0 && await this._commandService.executeCommand(Ne.id, {
1782
+ value: n
1783
+ }), a.length > 0 && await this._commandService.executeCommand(ht.id, {
1146
1784
  unitId: s,
1147
1785
  subUnitId: r,
1148
1786
  ranges: a
@@ -1155,7 +1793,7 @@ let g = class extends b {
1155
1793
  * @param height The height in pixels to set it to.
1156
1794
  * @returns This sheet, for chaining.
1157
1795
  */
1158
- async setRowHeightsForced(e, t, o) {
1796
+ async setRowHeightsForced(e, t, n) {
1159
1797
  const s = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = [
1160
1798
  {
1161
1799
  startRow: e,
@@ -1164,11 +1802,11 @@ let g = class extends b {
1164
1802
  endColumn: this._worksheet.getColumnCount() - 1
1165
1803
  }
1166
1804
  ];
1167
- return await this._commandService.executeCommand(ee.id, {
1805
+ return await this._commandService.executeCommand(de.id, {
1168
1806
  unitId: s,
1169
1807
  subUnitId: r,
1170
1808
  ranges: i,
1171
- value: o
1809
+ value: n
1172
1810
  }), this;
1173
1811
  }
1174
1812
  // #endregion
@@ -1178,17 +1816,17 @@ let g = class extends b {
1178
1816
  * @returns This sheet, for chaining.
1179
1817
  */
1180
1818
  async setRowCustom(e) {
1181
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = {};
1819
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = {};
1182
1820
  for (const [i, a] of Object.entries(e))
1183
1821
  s[Number(i)] = {
1184
1822
  custom: a
1185
1823
  };
1186
1824
  const r = {
1187
1825
  unitId: t,
1188
- subUnitId: o,
1826
+ subUnitId: n,
1189
1827
  rowData: s
1190
1828
  };
1191
- return await this._commandService.executeCommand(K.id, r), this;
1829
+ return await this._commandService.executeCommand(ie.id, r), this;
1192
1830
  }
1193
1831
  // #region Column
1194
1832
  /**
@@ -1223,9 +1861,9 @@ let g = class extends b {
1223
1861
  * @returns This sheet, for chaining.
1224
1862
  */
1225
1863
  async insertColumnsAfter(e, t) {
1226
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = p.RIGHT, i = 0, a = this._worksheet.getRowCount() - 1, h = e + 1, c = e + t, d = y(this._worksheet, i, a, h, c, !1, e);
1227
- return await this._commandService.executeCommand(te.id, {
1228
- unitId: o,
1864
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = E.RIGHT, i = 0, a = this._worksheet.getRowCount() - 1, h = e + 1, c = e + t, d = D(this._worksheet, i, a, h, c, !1, e);
1865
+ return await this._commandService.executeCommand(me.id, {
1866
+ unitId: n,
1229
1867
  subUnitId: s,
1230
1868
  direction: r,
1231
1869
  range: {
@@ -1244,9 +1882,9 @@ let g = class extends b {
1244
1882
  * @returns This sheet, for chaining.
1245
1883
  */
1246
1884
  async insertColumnsBefore(e, t) {
1247
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = p.LEFT, i = 0, a = this._worksheet.getRowCount() - 1, h = e, c = e + t - 1, d = y(this._worksheet, i, a, h, c, !1, e - 1);
1248
- return await this._commandService.executeCommand(te.id, {
1249
- unitId: o,
1885
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = E.LEFT, i = 0, a = this._worksheet.getRowCount() - 1, h = e, c = e + t - 1, d = D(this._worksheet, i, a, h, c, !1, e - 1);
1886
+ return await this._commandService.executeCommand(me.id, {
1887
+ unitId: n,
1250
1888
  subUnitId: s,
1251
1889
  direction: r,
1252
1890
  range: {
@@ -1273,14 +1911,14 @@ let g = class extends b {
1273
1911
  * @returns This sheet, for chaining.
1274
1912
  */
1275
1913
  async deleteColumns(e, t) {
1276
- const o = {
1914
+ const n = {
1277
1915
  startRow: 0,
1278
1916
  endRow: this._worksheet.getRowCount() - 1,
1279
1917
  startColumn: e,
1280
1918
  endColumn: e + t - 1
1281
1919
  };
1282
- return await this._commandService.executeCommand($e.id, {
1283
- range: o
1920
+ return await this._commandService.executeCommand(ct.id, {
1921
+ range: n
1284
1922
  }), this;
1285
1923
  }
1286
1924
  /**
@@ -1290,14 +1928,14 @@ let g = class extends b {
1290
1928
  * @returns This sheet, for chaining.
1291
1929
  */
1292
1930
  async moveColumns(e, t) {
1293
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = A(e.getRange(), this._worksheet), i = r, a = {
1931
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = $(e.getRange(), this._worksheet), i = r, a = {
1294
1932
  startRow: 0,
1295
1933
  endRow: this._worksheet.getRowCount() - 1,
1296
1934
  startColumn: t,
1297
1935
  endColumn: t
1298
1936
  };
1299
- return await this._commandService.executeCommand(Ge.id, {
1300
- unitId: o,
1937
+ return await this._commandService.executeCommand(dt.id, {
1938
+ unitId: n,
1301
1939
  subUnitId: s,
1302
1940
  range: r,
1303
1941
  fromRange: i,
@@ -1310,10 +1948,10 @@ let g = class extends b {
1310
1948
  * @returns This sheet, for chaining.
1311
1949
  */
1312
1950
  async hideColumn(e) {
1313
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = A(e.getRange(), this._worksheet);
1314
- return await this._commandService.executeCommand(ne.id, {
1951
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = $(e.getRange(), this._worksheet);
1952
+ return await this._commandService.executeCommand(ue.id, {
1315
1953
  unitId: t,
1316
- subUnitId: o,
1954
+ subUnitId: n,
1317
1955
  ranges: [s]
1318
1956
  }), this;
1319
1957
  }
@@ -1324,15 +1962,15 @@ let g = class extends b {
1324
1962
  * @returns This sheet, for chaining.
1325
1963
  */
1326
1964
  async hideColumns(e, t = 1) {
1327
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1965
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1328
1966
  startRow: 0,
1329
1967
  endRow: this._worksheet.getRowCount() - 1,
1330
1968
  startColumn: e,
1331
1969
  endColumn: e + t - 1,
1332
- rangeType: l.COLUMN
1970
+ rangeType: g.COLUMN
1333
1971
  };
1334
- return await this._commandService.executeCommand(ne.id, {
1335
- unitId: o,
1972
+ return await this._commandService.executeCommand(ue.id, {
1973
+ unitId: n,
1336
1974
  subUnitId: s,
1337
1975
  ranges: [r]
1338
1976
  }), this;
@@ -1343,10 +1981,10 @@ let g = class extends b {
1343
1981
  * @returns This sheet, for chaining.
1344
1982
  */
1345
1983
  async unhideColumn(e) {
1346
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = A(e.getRange(), this._worksheet);
1347
- return await this._commandService.executeCommand(oe.id, {
1984
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = $(e.getRange(), this._worksheet);
1985
+ return await this._commandService.executeCommand(le.id, {
1348
1986
  unitId: t,
1349
- subUnitId: o,
1987
+ subUnitId: n,
1350
1988
  ranges: [s]
1351
1989
  }), this;
1352
1990
  }
@@ -1357,15 +1995,15 @@ let g = class extends b {
1357
1995
  * @returns This sheet, for chaining.
1358
1996
  */
1359
1997
  async showColumns(e, t = 1) {
1360
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1998
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1361
1999
  startRow: 0,
1362
2000
  endRow: this._worksheet.getRowCount() - 1,
1363
2001
  startColumn: e,
1364
2002
  endColumn: e + t - 1,
1365
- rangeType: l.COLUMN
2003
+ rangeType: g.COLUMN
1366
2004
  };
1367
- return await this._commandService.executeCommand(oe.id, {
1368
- unitId: o,
2005
+ return await this._commandService.executeCommand(le.id, {
2006
+ unitId: n,
1369
2007
  subUnitId: s,
1370
2008
  ranges: [r]
1371
2009
  }), this;
@@ -1386,7 +2024,7 @@ let g = class extends b {
1386
2024
  * @param width The width in pixels to set it to.
1387
2025
  * @returns This sheet, for chaining.
1388
2026
  */
1389
- async setColumnWidths(e, t, o) {
2027
+ async setColumnWidths(e, t, n) {
1390
2028
  const s = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = [
1391
2029
  {
1392
2030
  startColumn: e,
@@ -1395,11 +2033,11 @@ let g = class extends b {
1395
2033
  endRow: this._worksheet.getRowCount() - 1
1396
2034
  }
1397
2035
  ];
1398
- return await this._commandService.executeCommand(qe.id, {
2036
+ return await this._commandService.executeCommand(mt.id, {
1399
2037
  unitId: s,
1400
2038
  subUnitId: r,
1401
2039
  ranges: i,
1402
- value: o
2040
+ value: n
1403
2041
  }), this;
1404
2042
  }
1405
2043
  // #endregion
@@ -1409,17 +2047,17 @@ let g = class extends b {
1409
2047
  * @returns This sheet, for chaining.
1410
2048
  */
1411
2049
  async setColumnCustom(e) {
1412
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = {};
2050
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = {};
1413
2051
  for (const [i, a] of Object.entries(e))
1414
2052
  s[Number(i)] = {
1415
2053
  custom: a
1416
2054
  };
1417
2055
  const r = {
1418
2056
  unitId: t,
1419
- subUnitId: o,
2057
+ subUnitId: n,
1420
2058
  columnData: s
1421
2059
  };
1422
- return await this._commandService.executeCommand(J.id, r), this;
2060
+ return await this._commandService.executeCommand(re.id, r), this;
1423
2061
  }
1424
2062
  // #region merge cells
1425
2063
  /**
@@ -1453,18 +2091,21 @@ let g = class extends b {
1453
2091
  * @param range The range to set as the active selection.
1454
2092
  */
1455
2093
  setActiveRange(e) {
1456
- const { unitId: t, sheetId: o } = e.getRange();
1457
- if (t !== this._workbook.getUnitId() || o !== this._worksheet.getSheetId())
2094
+ const { unitId: t, sheetId: n } = e.getRange();
2095
+ if (t !== this._workbook.getUnitId() || n !== this._worksheet.getSheetId())
1458
2096
  throw new Error("Specified range must be part of the sheet.");
1459
2097
  this._fWorkbook.setActiveRange(e);
1460
2098
  }
1461
2099
  /**
1462
2100
  * Sets the frozen state of the current sheet.
1463
- * @param freeze - The freeze object containing the parameters for freezing the sheet.
2101
+ * @param freeze - the scrolling viewport start range and count of freezed rows and columns.
2102
+ * that means if you want to freeze the first 3 rows and 2 columns, you should set freeze as { startRow: 3, startColumn: 2, xSplit: 2, ySplit: 3 }
2103
+ *
2104
+ * @deprecated use `setFrozenRows` and `setFrozenColumns` instead.
1464
2105
  * @returns True if the command was successful, false otherwise.
1465
2106
  */
1466
2107
  setFreeze(e) {
1467
- return this._commandService.syncExecuteCommand(Ye.id, {
2108
+ return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"), this._commandService.syncExecuteCommand(B.id, {
1468
2109
  ...e,
1469
2110
  unitId: this._workbook.getUnitId(),
1470
2111
  subUnitId: this.getSheetId()
@@ -1475,7 +2116,7 @@ let g = class extends b {
1475
2116
  * @returns True if the command was successful, false otherwise.
1476
2117
  */
1477
2118
  cancelFreeze() {
1478
- return this._commandService.syncExecuteCommand(Je.id, {
2119
+ return this._commandService.syncExecuteCommand(ut.id, {
1479
2120
  unitId: this._workbook.getUnitId(),
1480
2121
  subUnitId: this.getSheetId()
1481
2122
  });
@@ -1483,35 +2124,53 @@ let g = class extends b {
1483
2124
  /**
1484
2125
  * Get the freeze state of the current sheet.
1485
2126
  * @returns The freeze state of the current sheet.
2127
+ *
2128
+ * @deprecated use `getRowFreezeStatus` and `getColumnFreezeStatus` instead.
1486
2129
  */
1487
2130
  getFreeze() {
1488
2131
  return this._worksheet.getFreeze();
1489
2132
  }
1490
- /**
1491
- * Set the number of frozen columns.
1492
- * @param columns The number of columns to freeze.
1493
- * To unfreeze all columns, set this value to 0.
1494
- */
1495
- setFrozenColumns(e) {
2133
+ setFrozenColumns(...e) {
1496
2134
  const t = this.getFreeze();
1497
- this.setFreeze({
1498
- ...t,
1499
- startColumn: e > 0 ? e : -1,
1500
- xSplit: e
1501
- });
2135
+ if (arguments.length === 1) {
2136
+ const n = e[0];
2137
+ this.setFreeze({
2138
+ ...t,
2139
+ startColumn: n > 0 ? n : -1,
2140
+ xSplit: n
2141
+ });
2142
+ } else if (arguments.length === 2) {
2143
+ let [n = 0, s = 0] = e;
2144
+ n > s && ([n, s] = [s, n]), this._commandService.syncExecuteCommand(B.id, {
2145
+ startColumn: s + 1,
2146
+ xSplit: s - n + 1,
2147
+ startRow: t.startRow,
2148
+ ySplit: t.ySplit,
2149
+ unitId: this._workbook.getUnitId(),
2150
+ subUnitId: this.getSheetId()
2151
+ });
2152
+ }
1502
2153
  }
1503
- /**
1504
- * Set the number of frozen rows.
1505
- * @param rows The number of rows to freeze.
1506
- * To unfreeze all rows, set this value to 0.
1507
- */
1508
- setFrozenRows(e) {
2154
+ setFrozenRows(...e) {
1509
2155
  const t = this.getFreeze();
1510
- this.setFreeze({
1511
- ...t,
1512
- startRow: e > 0 ? e : -1,
1513
- ySplit: e
1514
- });
2156
+ if (arguments.length === 1) {
2157
+ const n = e[0];
2158
+ this.setFreeze({
2159
+ ...t,
2160
+ startRow: n > 0 ? n : -1,
2161
+ ySplit: n
2162
+ });
2163
+ } else if (arguments.length === 2) {
2164
+ let [n = 0, s = 0] = e;
2165
+ n > s && ([n, s] = [s, n]), this._commandService.syncExecuteCommand, this._commandService.syncExecuteCommand(B.id, {
2166
+ startRow: s + 1,
2167
+ ySplit: s - n + 1,
2168
+ startColumn: t.startColumn,
2169
+ xSplit: t.xSplit,
2170
+ unitId: this._workbook.getUnitId(),
2171
+ subUnitId: this.getSheetId()
2172
+ });
2173
+ }
1515
2174
  }
1516
2175
  /**
1517
2176
  * Get the number of frozen columns.
@@ -1531,33 +2190,141 @@ let g = class extends b {
1531
2190
  const e = this.getFreeze();
1532
2191
  return e.startRow === -1 ? 0 : e.startRow;
1533
2192
  }
2193
+ /**
2194
+ * Get freezed rows.
2195
+ */
2196
+ getFrozenRowRange() {
2197
+ const e = this._worksheet.getFreeze();
2198
+ return {
2199
+ startRow: e.startRow - e.ySplit,
2200
+ endRow: e.startRow - 1
2201
+ };
2202
+ }
2203
+ /**
2204
+ * Get freezed columns
2205
+ */
2206
+ getFrozenColumnRange() {
2207
+ const e = this._worksheet.getFreeze();
2208
+ return {
2209
+ startColumn: e.startColumn - e.xSplit,
2210
+ endColumn: e.startColumn - 1
2211
+ };
2212
+ }
1534
2213
  /**
1535
2214
  * Returns true if the sheet's gridlines are hidden; otherwise returns false. Gridlines are visible by default.
2215
+ * @returns {boolean} True if the sheet's gridlines are hidden; otherwise false.
2216
+ * @example
2217
+ * ```ts
2218
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2219
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2220
+ * // check if the gridlines are hidden
2221
+ * if (fWorkSheet.hasHiddenGridLines()) {
2222
+ * console.log('Gridlines are hidden');
2223
+ * }
2224
+ * ```
1536
2225
  */
1537
2226
  hasHiddenGridLines() {
1538
- return this._worksheet.getConfig().showGridlines === m.FALSE;
2227
+ return this._worksheet.getConfig().showGridlines === u.FALSE;
1539
2228
  }
1540
2229
  /**
1541
2230
  * Hides or reveals the sheet gridlines.
1542
2231
  * @param {boolean} hidden If `true`, hide gridlines in this sheet; otherwise show the gridlines.
2232
+ * @example
2233
+ * ``` ts
2234
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2235
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2236
+ * // hide the gridlines
2237
+ * fWorkSheet.setHiddenGridlines(true);
2238
+ * ```
1543
2239
  */
1544
2240
  setHiddenGridlines(e) {
1545
- return this._commandService.executeCommand(Ke.id, {
2241
+ return this._commandService.executeCommand(lt.id, {
2242
+ unitId: this._workbook.getUnitId(),
2243
+ subUnitId: this._worksheet.getSheetId(),
2244
+ showGridlines: e ? u.FALSE : u.TRUE
2245
+ });
2246
+ }
2247
+ /**
2248
+ * Set the color of the gridlines in the sheet.
2249
+ * @param {string|undefined} color The color to set for the gridlines.Undefined or null to reset to the default color.
2250
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2251
+ * @example
2252
+ * ```ts
2253
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2254
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2255
+ * // set the gridlines color to red
2256
+ * fWorkSheet.setGridLinesColor('#ff0000');
2257
+ * ```
2258
+ */
2259
+ setGridLinesColor(e) {
2260
+ return this._commandService.executeCommand(gt.id, {
1546
2261
  unitId: this._workbook.getUnitId(),
1547
2262
  subUnitId: this._worksheet.getSheetId(),
1548
- showGridlines: e ? m.FALSE : m.TRUE
2263
+ color: e
1549
2264
  });
1550
2265
  }
2266
+ /**
2267
+ * Get the color of the gridlines in the sheet.
2268
+ * @returns {string | undefined} The color of the gridlines in the sheet or undefined. The default color is 'rgb(214, 216, 219)'.
2269
+ */
2270
+ getGridLinesColor() {
2271
+ return this._worksheet.getGridlinesColor();
2272
+ }
2273
+ /**
2274
+ * Sets the sheet tab color.
2275
+ * @param {string|null|undefined} color A color code in CSS notation (like '#ffffff' or 'white'), or null to reset the tab color.
2276
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2277
+ * @example
2278
+ * ```ts
2279
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2280
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2281
+ * // set the tab color to red
2282
+ * fWorkSheet.setTabColor('#ff0000');
2283
+ * ```
2284
+ */
2285
+ setTabColor(e) {
2286
+ return this._commandService.executeCommand(_t.id, {
2287
+ unitId: this._workbook.getUnitId(),
2288
+ subUnitId: this._worksheet.getSheetId(),
2289
+ color: e
2290
+ });
2291
+ }
2292
+ /**
2293
+ * Get the tab color of the sheet.
2294
+ * @returns {string} The tab color of the sheet or undefined.
2295
+ * The default color is css style property 'unset'.
2296
+ * @example
2297
+ * ```ts
2298
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2299
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2300
+ * // get the tab color of the sheet
2301
+ * console.log(fWorkSheet.getTabColor());
2302
+ * ```
2303
+ */
2304
+ getTabColor() {
2305
+ return this._worksheet.getTabColor();
2306
+ }
1551
2307
  /**
1552
2308
  * Subscribe to the cell data change event.
1553
2309
  * @param callback - The callback function to be executed when the cell data changes.
1554
2310
  * @returns - A disposable object to unsubscribe from the event.
2311
+ * @example
2312
+ * ```ts
2313
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2314
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2315
+ * // subscribe to the cell data change event
2316
+ * const disposable = fWorkSheet.onCellDataChange((cellValue) => {
2317
+ * console.log(cellValue.toArray());
2318
+ * });
2319
+ * // unsubscribe from the event
2320
+ * disposable.dispose();
2321
+ * ```
1555
2322
  */
1556
2323
  onCellDataChange(e) {
1557
- return this._injector.get(v).onCommandExecuted((o) => {
1558
- if (o.id === se.id) {
1559
- const s = o.params;
1560
- s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new P(s.cellValue));
2324
+ return this._injector.get(l).onCommandExecuted((n) => {
2325
+ if (n.id === ge.id) {
2326
+ const s = n.params;
2327
+ s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new j(s.cellValue));
1561
2328
  }
1562
2329
  });
1563
2330
  }
@@ -1565,47 +2332,384 @@ let g = class extends b {
1565
2332
  * Subscribe to the cell data change event.
1566
2333
  * @param callback - The callback function to be executed before the cell data changes.
1567
2334
  * @returns - A disposable object to unsubscribe from the event.
2335
+ * @example
2336
+ * ```ts
2337
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2338
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2339
+ * // subscribe to the cell data change event
2340
+ * const disposable = fWorkSheet.onBeforeCellDataChange((cellValue) => {
2341
+ * console.log(cellValue.toArray());
2342
+ * });
2343
+ * // unsubscribe from the event
2344
+ * disposable.dispose();
2345
+ * ```
1568
2346
  */
1569
2347
  onBeforeCellDataChange(e) {
1570
- return this._injector.get(v).beforeCommandExecuted((o) => {
1571
- if (o.id === se.id) {
1572
- const s = o.params;
1573
- s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new P(s.cellValue));
2348
+ return this._injector.get(l).beforeCommandExecuted((n) => {
2349
+ if (n.id === ge.id) {
2350
+ const s = n.params;
2351
+ s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new j(s.cellValue));
1574
2352
  }
1575
2353
  });
1576
2354
  }
2355
+ /**
2356
+ * Hides this sheet. Has no effect if the sheet is already hidden. If this method is called on the only visible sheet, it throws an exception.
2357
+ * @example
2358
+ * ```ts
2359
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2360
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2361
+ * // hide the active sheet
2362
+ * fWorkSheet.hideSheet();
2363
+ * ``
2364
+ */
2365
+ hideSheet() {
2366
+ const e = this._injector.get(l);
2367
+ if (this._workbook.getSheets().filter((r) => r.isSheetHidden() !== u.TRUE).length <= 1)
2368
+ throw new Error("Cannot hide the only visible sheet");
2369
+ e.executeCommand(wt.id, {
2370
+ unitId: this._workbook.getUnitId(),
2371
+ subUnitId: this._worksheet.getSheetId()
2372
+ });
2373
+ }
2374
+ /**
2375
+ * Shows this sheet. Has no effect if the sheet is already visible.
2376
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2377
+ * @example
2378
+ * ```ts
2379
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2380
+ * const fWorkSheets = fWorkbook.getSheets();
2381
+ * // show the last sheet
2382
+ * fWorkSheets[fWorkSheets.length - 1].showSheet();
2383
+ * ```
2384
+ */
2385
+ showSheet() {
2386
+ return this._injector.get(l).executeCommand(kt.id, {
2387
+ unitId: this._workbook.getUnitId(),
2388
+ subUnitId: this._worksheet.getSheetId()
2389
+ });
2390
+ }
2391
+ /**
2392
+ * Returns true if the sheet is currently hidden.
2393
+ * @returns {boolean} True if the sheet is hidden; otherwise, false.
2394
+ */
2395
+ isSheetHidden() {
2396
+ return this._worksheet.isSheetHidden() === u.TRUE;
2397
+ }
2398
+ /**
2399
+ * Sets the sheet name.
2400
+ * @param {string} name The new name for the sheet.
2401
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2402
+ * @example
2403
+ * ```ts
2404
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2405
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2406
+ * // set the sheet name to 'Sheet1'
2407
+ * fWorkSheet.setName('Sheet1');
2408
+ * ```
2409
+ */
2410
+ setName(e) {
2411
+ return this._commandService.executeCommand(St.id, {
2412
+ unitId: this._workbook.getUnitId(),
2413
+ subUnitId: this._worksheet.getSheetId(),
2414
+ name: e
2415
+ });
2416
+ }
2417
+ /**
2418
+ * Activates this sheet. Does not alter the sheet itself, only the parent's notion of the active sheet.
2419
+ * @returns Current sheet, for chaining.
2420
+ */
2421
+ activate() {
2422
+ return this._fWorkbook.setActiveSheet(this), this;
2423
+ }
2424
+ /**
2425
+ * Gets the position of the sheet in its parent spreadsheet. Starts at 0.
2426
+ * @returns {number} The position of the sheet in its parent spreadsheet.
2427
+ * @example
2428
+ * ```ts
2429
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2430
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2431
+ * // get the position of the active sheet
2432
+ * const position = fWorkSheet.getIndex();
2433
+ * console.log(position); // 0
2434
+ * ```
2435
+ */
2436
+ getIndex() {
2437
+ return this._workbook.getSheetIndex(this._worksheet);
2438
+ }
2439
+ /**
2440
+ * Clears the sheet of content and formatting information.Or Optionally clears only the contents or only the formatting.
2441
+ * @param {IFacadeClearOptions} [options] Options for clearing the sheet. If not provided, the contents and formatting are cleared both.
2442
+ * @param {boolean} [options.contentsOnly] If true, the contents of the sheet are cleared. If false, the contents and formatting are cleared. Default is false.
2443
+ * @param {boolean} [options.formatOnly] If true, the formatting of the sheet is cleared. If false, the contents and formatting are cleared. Default is false.
2444
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2445
+ * @example
2446
+ * ```ts
2447
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2448
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2449
+ * // clear the sheet of content and formatting information
2450
+ * fWorkSheet.clear();
2451
+ * // clear the sheet of content only
2452
+ * fWorkSheet.clear({ contentsOnly: true });
2453
+ * ```
2454
+ */
2455
+ clear(e) {
2456
+ if (e && e.contentsOnly && !e.formatOnly)
2457
+ return this.clearContents();
2458
+ if (e && e.formatOnly && !e.contentsOnly)
2459
+ return this.clearFormats();
2460
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = this._injector.get(l), r = {
2461
+ startRow: 0,
2462
+ endRow: this._worksheet.getRowCount() - 1,
2463
+ startColumn: 0,
2464
+ endColumn: this._worksheet.getColumnCount() - 1
2465
+ };
2466
+ return s.executeCommand(Ct.id, {
2467
+ unitId: t,
2468
+ subUnitId: n,
2469
+ ranges: [r],
2470
+ options: e
2471
+ });
2472
+ }
2473
+ /**
2474
+ * Clears the sheet of contents, while preserving formatting information.
2475
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2476
+ * @example
2477
+ * ```ts
2478
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2479
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2480
+ * // clear the sheet of content only
2481
+ * fWorkSheet.clearContents();
2482
+ * ```
2483
+ */
2484
+ clearContents() {
2485
+ const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId(), n = this._injector.get(l), s = {
2486
+ startRow: 0,
2487
+ endRow: this._worksheet.getRowCount() - 1,
2488
+ startColumn: 0,
2489
+ endColumn: this._worksheet.getColumnCount() - 1
2490
+ };
2491
+ return n.executeCommand(It.id, {
2492
+ unitId: e,
2493
+ subUnitId: t,
2494
+ ranges: [s]
2495
+ });
2496
+ }
2497
+ /**
2498
+ * Clears the sheet of formatting, while preserving contents.
2499
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2500
+ * @example
2501
+ * ```ts
2502
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2503
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2504
+ * // clear the sheet of formatting only
2505
+ * fWorkSheet.clearFormats();
2506
+ * ```
2507
+ */
2508
+ clearFormats() {
2509
+ const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId(), n = this._injector.get(l), s = {
2510
+ startRow: 0,
2511
+ endRow: this._worksheet.getRowCount() - 1,
2512
+ startColumn: 0,
2513
+ endColumn: this._worksheet.getColumnCount() - 1
2514
+ };
2515
+ return n.executeCommand(ft.id, {
2516
+ unitId: e,
2517
+ subUnitId: t,
2518
+ ranges: [s]
2519
+ });
2520
+ }
2521
+ /**
2522
+ * Returns a Range corresponding to the dimensions in which data is present.
2523
+ * This is functionally equivalent to creating a Range bounded by A1 and (Sheet.getLastColumns(), Sheet.getLastRows()).
2524
+ * @returns {FRange} The range of the data in the sheet.
2525
+ * @example
2526
+ * ```ts
2527
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2528
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2529
+ * // the sheet is a empty sheet
2530
+ * const cellRange = fWorkSheet.getRange(200, 10, 1, 1);
2531
+ * cellRange.setValue('Hello World');
2532
+ * console.log(fWorkSheet.getDataRange().getA1Notation()); // A1:J200
2533
+ * ```
2534
+ */
2535
+ getDataRange() {
2536
+ const e = this.getLastRows(), t = this.getLastColumns();
2537
+ return this.getRange(0, 0, e + 1, t + 1);
2538
+ }
2539
+ /**
2540
+ * Returns the position of the last column that has content.
2541
+ * @returns {number} the last column of the sheet that contains content.
2542
+ * @example
2543
+ * ```ts
2544
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2545
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2546
+ * const fRange = fWorkSheet.getRange(100, 20, 1, 1);
2547
+ * console.log(fWorkSheet.getLastColumns()); // 20
2548
+ * ```
2549
+ */
2550
+ getLastColumns() {
2551
+ return this._worksheet.getLastColumnWithContent();
2552
+ }
2553
+ /**
2554
+ * Returns the position of the last column that has content. Same as getLastColumns.
2555
+ * @returns {number} the last column of the sheet that contains content.
2556
+ * @example
2557
+ * ```ts
2558
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2559
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2560
+ * const fRange = fWorkSheet.getRange(100, 20, 1, 1);
2561
+ * console.log(fWorkSheet.getLastColumn());
2562
+ * ```
2563
+ */
2564
+ getLastColumn() {
2565
+ return this._worksheet.getLastColumnWithContent();
2566
+ }
2567
+ /**
2568
+ * Returns the position of the last row that has content.
2569
+ * @returns {number} the last row of the sheet that contains content.
2570
+ * @example
2571
+ * ```ts
2572
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2573
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2574
+ * const fRange = fWorkSheet.getRange(100,1,1,1);
2575
+ * fRange.setValue('Hello World');
2576
+ * console.log(fWorkSheet.getLastRows()); // 100
2577
+ */
2578
+ getLastRows() {
2579
+ return this._worksheet.getLastRowWithContent();
2580
+ }
2581
+ /**
2582
+ * Returns the position of the last row that has content, same as getLastRows().
2583
+ * @returns {number} the last row of the sheet that contains content.
2584
+ * @example
2585
+ * ```ts
2586
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2587
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2588
+ * const fRange = fWorkSheet.getRange(100,1,1,1);
2589
+ * fRange.setValue('Hello World');
2590
+ * console.log(fWorkSheet.getLastRow());
2591
+ */
2592
+ getLastRow() {
2593
+ return this._worksheet.getLastRowWithContent();
2594
+ }
2595
+ /**
2596
+ * Judge whether provided FWorksheet is equal to current.
2597
+ * @param {FWorksheet} other the FWorksheet to compare with.
2598
+ * @returns {boolean} true if the FWorksheet is equal to the current FWorksheet, false otherwise.
2599
+ * @example
2600
+ * ```ts
2601
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2602
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2603
+ * const fWorkSheet2 = fWorkbook.getSheetByName('Sheet1');
2604
+ * console.log(fWorkSheet.equals(fWorkSheet2)); // true, if the active sheet is 'Sheet1'
2605
+ * ```
2606
+ */
2607
+ equalTo(e) {
2608
+ return e instanceof _ ? this._worksheet.getSheetId() === e.getSheetId() && this._workbook.getUnitId() === e.getWorkbook().getUnitId() : !1;
2609
+ }
2610
+ /*
2611
+ * Insert a defined name for worksheet.
2612
+ * @param {string} name The name of the defined name to insert
2613
+ * @param {string} formulaOrRefString The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
2614
+ * @example
2615
+ * ```ts
2616
+ * // The code below inserts a defined name
2617
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2618
+ * const sheet1 = activeSpreadsheet.getSheetByName('Sheet1');
2619
+ * sheet1.insertDefinedName('MyDefinedName', 'Sheet1!A1');
2620
+ * ```
2621
+ */
2622
+ insertDefinedName(e, t) {
2623
+ const s = this._injector.createInstance(A).setName(e).setRef(t).build();
2624
+ s.localSheetId = this.getSheetId(), this._fWorkbook.insertDefinedNameBuilder(s);
2625
+ }
2626
+ /**
2627
+ * Get all the defined names in the worksheet.
2628
+ * @returns {FDefinedName[]} All the defined names in the worksheet
2629
+ * @example
2630
+ * ```ts
2631
+ * // The code below gets all the defined names in the worksheet
2632
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2633
+ * const sheet1 = activeSpreadsheet.getSheetByName('Sheet1');
2634
+ * const definedNames = sheet1.getDefinedNames();
2635
+ * ```
2636
+ */
2637
+ getDefinedNames() {
2638
+ return this._fWorkbook.getDefinedNames().filter((t) => t.getLocalSheetId() === this.getSheetId());
2639
+ }
1577
2640
  };
1578
- g = Ct([
1579
- j(3, u(R)),
1580
- j(4, u(ue)),
1581
- j(5, v)
1582
- ], g);
1583
- var It = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, Rt = (n, e, t, o) => {
1584
- for (var s = o > 1 ? void 0 : o ? vt(e, t) : e, r = n.length - 1, i; r >= 0; r--)
1585
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
1586
- return o && s && It(e, t, s), s;
1587
- }, k = (n, e) => (t, o) => e(t, o, n);
1588
- let U = class extends b {
1589
- constructor(e, t, o, s, r, i, a, h) {
2641
+ _ = Gt([
2642
+ M(3, m(v)),
2643
+ M(4, m(Ne)),
2644
+ M(5, m(Ce)),
2645
+ M(6, l)
2646
+ ], _);
2647
+ var qt = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, Yt = (o, e, t, n) => {
2648
+ for (var s = n > 1 ? void 0 : n ? Kt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
2649
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
2650
+ return n && s && qt(e, t, s), s;
2651
+ }, k = (o, e) => (t, n) => e(t, n, o);
2652
+ let I = class extends p {
2653
+ constructor(e, t, n, s, r, i, a, h, c, d) {
1590
2654
  super();
1591
- E(this, "id");
1592
- this._workbook = e, this._injector = t, this._resourceLoaderService = o, this._selectionManagerService = s, this._univerInstanceService = r, this._commandService = i, this._permissionService = a, this._logService = h, this.id = this._workbook.getUnitId();
2655
+ P(this, "id");
2656
+ this._workbook = e, this._injector = t, this._resourceLoaderService = n, this._selectionManagerService = s, this._univerInstanceService = r, this._commandService = i, this._permissionService = a, this._logService = h, this._localeService = c, this._definedNamesService = d, this.id = this._workbook.getUnitId();
1593
2657
  }
2658
+ /**
2659
+ * Get the id of the workbook.
2660
+ * @returns {string} The id of the workbook.
2661
+ * @example
2662
+ * ```ts
2663
+ * // The code below gets the id of the workbook
2664
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2665
+ * const id = activeSpreadsheet.getId();
2666
+ * ```
2667
+ */
1594
2668
  getId() {
1595
2669
  return this.id;
1596
2670
  }
2671
+ /**
2672
+ * Get the name of the workbook.
2673
+ * @returns {string} The name of the workbook.
2674
+ * @example
2675
+ * ```ts
2676
+ * // The code below gets the name of the workbook
2677
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2678
+ * const name = activeSpreadsheet.getName();
2679
+ * ```
2680
+ */
1597
2681
  getName() {
1598
- return this._workbook.getName();
2682
+ return this._workbook.name;
2683
+ }
2684
+ /**
2685
+ * Set the name of the workbook.
2686
+ * @param {string} name The new name of the workbook.
2687
+ * @example
2688
+ * ```ts
2689
+ * // The code below sets the name of the workbook
2690
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2691
+ * activeSpreadsheet.setName('MyWorkbook');
2692
+ * ```
2693
+ */
2694
+ setName(e) {
2695
+ this._workbook.setName(e);
1599
2696
  }
1600
2697
  /**
1601
2698
  * save workbook snapshot data, including conditional formatting, data validation, and other plugin data.
2699
+ * @return Workbook snapshot data
2700
+ * @example
2701
+ * ```ts
2702
+ * // The code below saves the workbook snapshot data
2703
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2704
+ * const snapshot = activeSpreadsheet.save();
2705
+ * ```
1602
2706
  */
1603
2707
  save() {
1604
2708
  return this._resourceLoaderService.saveUnit(this._workbook.getUnitId());
1605
2709
  }
1606
2710
  /**
1607
2711
  * @deprecated use 'save' instead.
1608
- * @return {*} {IWorkbookData}
2712
+ * @return {*} {IWorkbookData} Workbook snapshot data
1609
2713
  * @memberof FWorkbook
1610
2714
  */
1611
2715
  getSnapshot() {
@@ -1614,17 +2718,29 @@ let U = class extends b {
1614
2718
  /**
1615
2719
  * Get the active sheet of the workbook.
1616
2720
  * @returns The active sheet of the workbook
2721
+ * @example
2722
+ * ```ts
2723
+ * // The code below gets the active sheet of the workbook
2724
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2725
+ * const activeSheet = activeSpreadsheet.getActiveSheet();
2726
+ * ```
1617
2727
  */
1618
2728
  getActiveSheet() {
1619
2729
  const e = this._workbook.getActiveSheet();
1620
- return this._injector.createInstance(g, this, this._workbook, e);
2730
+ return this._injector.createInstance(_, this, this._workbook, e);
1621
2731
  }
1622
2732
  /**
1623
2733
  * Gets all the worksheets in this workbook
1624
2734
  * @returns An array of all the worksheets in the workbook
2735
+ * @example
2736
+ * ```ts
2737
+ * // The code below gets all the worksheets in the workbook
2738
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2739
+ * const sheets = activeSpreadsheet.getSheets();
2740
+ * ```
1625
2741
  */
1626
2742
  getSheets() {
1627
- return this._workbook.getSheets().map((e) => this._injector.createInstance(g, this, this._workbook, e));
2743
+ return this._workbook.getSheets().map((e) => this._injector.createInstance(_, this, this._workbook, e));
1628
2744
  }
1629
2745
  /**
1630
2746
  * Create a new worksheet and returns a handle to it.
@@ -1632,47 +2748,72 @@ let U = class extends b {
1632
2748
  * @param rows How may rows would the new sheet have
1633
2749
  * @param column How many columns would the new sheet have
1634
2750
  * @returns The new created sheet
1635
- */
1636
- create(e, t, o) {
1637
- const s = ve({});
1638
- s.rowCount = t, s.columnCount = o, s.name = e, s.id = e.toLowerCase().replace(/ /g, "-"), this._commandService.syncExecuteCommand(re.id, {
2751
+ * @example
2752
+ * ```ts
2753
+ * // The code below creates a new sheet
2754
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2755
+ * const newSheet = activeSpreadsheet.create('MyNewSheet', 10, 10);
2756
+ * ```
2757
+ */
2758
+ create(e, t, n) {
2759
+ const s = Fe({});
2760
+ s.rowCount = t, s.columnCount = n, s.name = e, s.id = e.toLowerCase().replace(/ /g, "-"), this._commandService.syncExecuteCommand(z.id, {
1639
2761
  unitId: this.id,
1640
2762
  index: this._workbook.getSheets().length,
1641
2763
  sheet: s
1642
- }), this._commandService.syncExecuteCommand(F.id, {
2764
+ }), this._commandService.syncExecuteCommand(V.id, {
1643
2765
  unitId: this.id,
1644
2766
  subUnitId: this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId()
1645
2767
  });
1646
2768
  const r = this._workbook.getActiveSheet();
1647
2769
  if (!r)
1648
2770
  throw new Error("No active sheet found");
1649
- return this._injector.createInstance(g, this, this._workbook, r);
2771
+ return this._injector.createInstance(_, this, this._workbook, r);
1650
2772
  }
1651
2773
  /**
1652
2774
  * Get a worksheet by sheet id.
1653
2775
  * @param sheetId The id of the sheet to get.
1654
2776
  * @return The worksheet with given sheet id
2777
+ * @example
2778
+ * ```ts
2779
+ * // The code below gets a worksheet by sheet id
2780
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2781
+ * const sheet = activeSpreadsheet.getSheetBySheetId('sheetId');
2782
+ * ```
1655
2783
  */
1656
2784
  getSheetBySheetId(e) {
1657
2785
  const t = this._workbook.getSheetBySheetId(e);
1658
- return t ? this._injector.createInstance(g, this, this._workbook, t) : null;
2786
+ return t ? this._injector.createInstance(_, this, this._workbook, t) : null;
1659
2787
  }
1660
2788
  /**
1661
2789
  * Get a worksheet by sheet name.
1662
2790
  * @param name The name of the sheet to get.
1663
2791
  * @returns The worksheet with given sheet name
2792
+ * @example
2793
+ * ```ts
2794
+ * // The code below gets a worksheet by sheet name
2795
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2796
+ * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
2797
+ * ```
1664
2798
  */
1665
2799
  getSheetByName(e) {
1666
2800
  const t = this._workbook.getSheetBySheetName(e);
1667
- return t ? this._injector.createInstance(g, this, this._workbook, t) : null;
2801
+ return t ? this._injector.createInstance(_, this, this._workbook, t) : null;
1668
2802
  }
1669
2803
  /**
1670
2804
  * Sets the given worksheet to be the active worksheet in the workbook.
1671
2805
  * @param sheet The worksheet to set as the active worksheet.
1672
2806
  * @returns The active worksheet
2807
+ * @example
2808
+ * ```ts
2809
+ * // The code below sets the given worksheet to be the active worksheet
2810
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2811
+ * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
2812
+ * activeSpreadsheet.setActiveSheet(sheet);
2813
+ * ```
1673
2814
  */
1674
2815
  setActiveSheet(e) {
1675
- return this._commandService.syncExecuteCommand(F.id, {
2816
+ return this._commandService.syncExecuteCommand(V.id, {
1676
2817
  unitId: this.id,
1677
2818
  subUnitId: e.getSheetId()
1678
2819
  }), e;
@@ -1680,64 +2821,138 @@ let U = class extends b {
1680
2821
  /**
1681
2822
  * Inserts a new worksheet into the workbook.
1682
2823
  * Using a default sheet name. The new sheet becomes the active sheet
2824
+ * @param sheetName - (optional) The name of the new sheet
1683
2825
  * @returns The new sheet
1684
- */
1685
- insertSheet() {
1686
- this._commandService.syncExecuteCommand(re.id);
1687
- const e = this.id, t = this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId();
1688
- this._commandService.syncExecuteCommand(F.id, {
1689
- unitId: e,
1690
- subUnitId: t
2826
+ * @example
2827
+ * ```ts
2828
+ * // The code below inserts a new sheet into the workbook
2829
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2830
+ * activeSpreadsheet.insertSheet();
2831
+ *
2832
+ * // The code below inserts a new sheet into the workbook, using a custom name
2833
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2834
+ * activeSpreadsheet.insertSheet('MyNewSheet');
2835
+ * ```
2836
+ */
2837
+ insertSheet(e) {
2838
+ e != null ? this._commandService.syncExecuteCommand(z.id, { sheet: { name: e } }) : this._commandService.syncExecuteCommand(z.id);
2839
+ const t = this.id, n = this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId();
2840
+ this._commandService.syncExecuteCommand(V.id, {
2841
+ unitId: t,
2842
+ subUnitId: n
1691
2843
  });
1692
- const o = this._workbook.getActiveSheet();
1693
- if (!o)
2844
+ const s = this._workbook.getActiveSheet();
2845
+ if (!s)
1694
2846
  throw new Error("No active sheet found");
1695
- return this._injector.createInstance(g, this, this._workbook, o);
2847
+ return this._injector.createInstance(_, this, this._workbook, s);
1696
2848
  }
1697
2849
  /**
1698
2850
  * Deletes the specified worksheet.
1699
2851
  * @param sheet The worksheet to delete.
2852
+ * @example
2853
+ * ```ts
2854
+ * // The code below deletes the specified worksheet
2855
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2856
+ * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
2857
+ * activeSpreadsheet.deleteSheet(sheet);
2858
+ * ```
1700
2859
  */
1701
2860
  deleteSheet(e) {
1702
- const t = this.id, o = e.getSheetId();
1703
- this._commandService.executeCommand(Qe.id, {
2861
+ const t = this.id, n = e.getSheetId();
2862
+ return this._commandService.executeCommand(vt.id, {
1704
2863
  unitId: t,
1705
- subUnitId: o
2864
+ subUnitId: n
1706
2865
  });
1707
2866
  }
1708
2867
  // #region editing
2868
+ /**
2869
+ * Undo the last action.
2870
+ * @returns A promise that resolves to true if the undo was successful, false otherwise.
2871
+ * @example
2872
+ * ```ts
2873
+ * // The code below undoes the last action
2874
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2875
+ * activeSpreadsheet.undo();
2876
+ * ```
2877
+ */
1709
2878
  undo() {
1710
- return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(Re.id);
2879
+ return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(Ae.id);
1711
2880
  }
2881
+ /**
2882
+ * Redo the last undone action.
2883
+ * @returns A promise that resolves to true if the redo was successful, false otherwise.
2884
+ * @example
2885
+ * ```ts
2886
+ * // The code below redoes the last undone action
2887
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2888
+ * activeSpreadsheet.redo();
2889
+ * ```
2890
+ */
1712
2891
  redo() {
1713
- return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(fe.id);
2892
+ return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(Te.id);
1714
2893
  }
2894
+ /**
2895
+ * Callback for command execution.
2896
+ * @callback onBeforeCommandExecuteCallback
2897
+ * @param {ICommandInfo<ISheetCommandSharedParams>} command The command that was executed.
2898
+ */
1715
2899
  /**
1716
2900
  * Register a callback that will be triggered before invoking a command targeting the Univer sheet.
1717
- * @param callback the callback.
2901
+ * @param {onBeforeCommandExecuteCallback} callback the callback.
1718
2902
  * @returns A function to dispose the listening.
2903
+ * @example
2904
+ * ```ts
2905
+ * // The code below registers a callback that will be triggered before invoking a command targeting the Univer sheet
2906
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2907
+ * activeSpreadsheet.onBeforeCommandExecute((command) => {
2908
+ * console.log('Command executed:', command);
2909
+ * });
2910
+ * ```
1719
2911
  */
1720
2912
  onBeforeCommandExecute(e) {
1721
2913
  return this._commandService.beforeCommandExecuted((t) => {
1722
- var o;
1723
- ((o = t.params) == null ? void 0 : o.unitId) === this.id && e(t);
2914
+ var n;
2915
+ ((n = t.params) == null ? void 0 : n.unitId) === this.id && e(t);
1724
2916
  });
1725
2917
  }
2918
+ /**
2919
+ * Callback for command execution.
2920
+ * @callback onCommandExecutedCallback
2921
+ * @param {ICommandInfo<ISheetCommandSharedParams>} command The command that was executed
2922
+ */
1726
2923
  /**
1727
2924
  * Register a callback that will be triggered when a command is invoked targeting the Univer sheet.
1728
- * @param callback the callback.
2925
+ * @param {onCommandExecutedCallback} callback the callback.
1729
2926
  * @returns A function to dispose the listening.
2927
+ * @example
2928
+ * ```ts
2929
+ * // The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheet
2930
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2931
+ * activeSpreadsheet.onCommandExecuted((command) => {
2932
+ * console.log('Command executed:', command);
2933
+ * });
1730
2934
  */
1731
2935
  onCommandExecuted(e) {
1732
2936
  return this._commandService.onCommandExecuted((t) => {
1733
- var o;
1734
- ((o = t.params) == null ? void 0 : o.unitId) === this.id && e(t);
2937
+ var n;
2938
+ ((n = t.params) == null ? void 0 : n.unitId) === this.id && e(t);
1735
2939
  });
1736
2940
  }
2941
+ /**
2942
+ * Callback for selection changes.
2943
+ *
2944
+ * @callback onSelectionChangeCallback
2945
+ * @param {IRange[]} selections The new selection.
2946
+ */
2947
+ /**
2948
+ * Register a callback that will be triggered when the selection changes.
2949
+ * @param {onSelectionChangeCallback} callback The callback.
2950
+ * @returns A function to dispose the listening
2951
+ */
1737
2952
  onSelectionChange(e) {
1738
- return be(
2953
+ return Ie(
1739
2954
  this._selectionManagerService.selectionMoveEnd$.subscribe((t) => {
1740
- this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET).getUnitId() === this.id && (t != null && t.length ? e(t.map((o) => o.range)) : e([]));
2955
+ this._univerInstanceService.getCurrentUnitForType(U.UNIVER_SHEET).getUnitId() === this.id && (t != null && t.length ? e(t.map((n) => n.range)) : e([]));
1741
2956
  })
1742
2957
  );
1743
2958
  }
@@ -1746,7 +2961,7 @@ let U = class extends b {
1746
2961
  * @param {boolean} value editable value want to set
1747
2962
  */
1748
2963
  setEditable(e) {
1749
- const t = new de(this._workbook.getUnitId());
2964
+ const t = new ye(this._workbook.getUnitId());
1750
2965
  this._permissionService.getPermissionPoint(t.id) || this._permissionService.addPermissionPoint(t), this._permissionService.updatePermissionPoint(t.id, e);
1751
2966
  }
1752
2967
  /**
@@ -1754,67 +2969,314 @@ let U = class extends b {
1754
2969
  * @param range The range to set as the active selection.
1755
2970
  */
1756
2971
  setActiveRange(e) {
1757
- const t = this.getActiveSheet(), o = e.getRange().sheetId || t.getSheetId(), s = o ? this._workbook.getSheetBySheetId(o) : this._workbook.getActiveSheet(!0);
2972
+ const t = this.getActiveSheet(), n = e.getRange().sheetId || t.getSheetId(), s = n ? this._workbook.getSheetBySheetId(n) : this._workbook.getActiveSheet(!0);
1758
2973
  if (!s)
1759
2974
  throw new Error("No active sheet found");
1760
- s.getSheetId() !== t.getSheetId() && this.setActiveSheet(this._injector.createInstance(g, this, this._workbook, s));
2975
+ s.getSheetId() !== t.getSheetId() && this.setActiveSheet(this._injector.createInstance(_, this, this._workbook, s));
1761
2976
  const r = {
1762
2977
  unitId: this.getId(),
1763
- subUnitId: o,
1764
- selections: [e].map((i) => ({ range: i.getRange(), primary: Xe(i.getRange(), s), style: null }))
2978
+ subUnitId: n,
2979
+ selections: [e].map((i) => ({ range: i.getRange(), primary: Y(i.getRange(), s), style: null }))
1765
2980
  };
1766
- this._commandService.syncExecuteCommand(Ze.id, r);
2981
+ this._commandService.syncExecuteCommand(Ue.id, r);
1767
2982
  }
1768
2983
  /**
1769
2984
  * Returns the selected range in the active sheet, or null if there is no active range.
1770
2985
  * @returns the active range
1771
2986
  */
1772
2987
  getActiveRange() {
1773
- const e = this._workbook.getActiveSheet(), o = this._selectionManagerService.getCurrentSelections().find((s) => !!s.primary);
1774
- return o ? this._injector.createInstance(S, this._workbook, e, o.range) : null;
2988
+ const e = this._workbook.getActiveSheet(), n = this._selectionManagerService.getCurrentSelections().find((s) => !!s.primary);
2989
+ return n ? this._injector.createInstance(S, this._workbook, e, n.range) : null;
2990
+ }
2991
+ /**
2992
+ * Deletes the currently active sheet.
2993
+ * @example
2994
+ * ```ts
2995
+ * // The code below deletes the currently active sheet and stores the new active
2996
+ * // sheet in a variable
2997
+ * const sheet = univerAPI.getActiveWorkbook().deleteActiveSheet();
2998
+ * ```
2999
+ */
3000
+ deleteActiveSheet() {
3001
+ const e = this.getActiveSheet();
3002
+ return this.deleteSheet(e);
3003
+ }
3004
+ /**
3005
+ * Duplicates the given worksheet.
3006
+ * @param {FWorksheet} sheet The worksheet to duplicate.
3007
+ * @returns {Promise<boolean>} true if the sheet was duplicated, false otherwise
3008
+ * @example
3009
+ * ```ts
3010
+ * // The code below duplicates the given worksheet
3011
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3012
+ * const activeSheet = activeSpreadsheet.getActiveSheet();
3013
+ * activeSpreadsheet.duplicateSheet(activeSheet);
3014
+ * ```
3015
+ */
3016
+ duplicateSheet(e) {
3017
+ return this._commandService.executeCommand(Rt.id, {
3018
+ unitId: e.getWorkbook().getUnitId(),
3019
+ subUnitId: e.getSheetId()
3020
+ });
3021
+ }
3022
+ /**
3023
+ * Duplicates the active sheet.
3024
+ * @returns {Promise<boolean>} true if the sheet was duplicated, false otherwise
3025
+ * @example
3026
+ * ```ts
3027
+ * // The code below duplicates the active sheet
3028
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3029
+ * activeSpreadsheet.duplicateActiveSheet();
3030
+ * ```
3031
+ */
3032
+ duplicateActiveSheet() {
3033
+ const e = this.getActiveSheet();
3034
+ return this.duplicateSheet(e);
3035
+ }
3036
+ /**
3037
+ * Get the number of sheets in the workbook.
3038
+ * @returns The number of sheets in the workbook
3039
+ * @example
3040
+ * ```ts
3041
+ * // The code below gets the number of sheets in the workbook
3042
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3043
+ * const numSheets = activeSpreadsheet.getNumSheets();
3044
+ * ```
3045
+ */
3046
+ getNumSheets() {
3047
+ return this._workbook.getSheets().length;
3048
+ }
3049
+ /**
3050
+ * Get the locale of the workbook.
3051
+ * @returns {LocaleType} The locale of the workbook
3052
+ * @example
3053
+ * ```ts
3054
+ * // The code below gets the locale of the workbook
3055
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3056
+ * const locale = activeSpreadsheet.getLocale();
3057
+ * ```
3058
+ */
3059
+ getLocale() {
3060
+ return this._localeService.getCurrentLocale();
3061
+ }
3062
+ /**
3063
+ * Set the locale of the workbook.
3064
+ * @param {LocaleType} locale The locale to set
3065
+ * @example
3066
+ * ```ts
3067
+ * // The code below sets the locale of the workbook
3068
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3069
+ * activeSpreadsheet.setLocale(LocaleType.EN_US);
3070
+ * ```
3071
+ */
3072
+ setLocale(e) {
3073
+ this._localeService.setLocale(e);
3074
+ }
3075
+ /**
3076
+ * Get the URL of the workbook.
3077
+ * @returns {string} The URL of the workbook
3078
+ * @example
3079
+ * ```ts
3080
+ * // The code below gets the URL of the workbook
3081
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3082
+ * const url = activeSpreadsheet.getUrl();
3083
+ * ```
3084
+ */
3085
+ getUrl() {
3086
+ return location.href;
3087
+ }
3088
+ /**
3089
+ * Move the sheet to the specified index.
3090
+ * @param {FWorksheet} sheet The sheet to move
3091
+ * @param {number} index The index to move the sheet to
3092
+ * @returns {Promise<boolean>} true if the sheet was moved, false otherwise
3093
+ * @example
3094
+ * ```ts
3095
+ * // The code below moves the sheet to the specified index
3096
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3097
+ * const sheet = activeSpreadsheet.getActiveSheet();
3098
+ * activeSpreadsheet.moveSheet(sheet, 1);
3099
+ * ```
3100
+ */
3101
+ moveSheet(e, t) {
3102
+ let n = t;
3103
+ return n < 0 ? n = 0 : n > this._workbook.getSheets().length - 1 && (n = this._workbook.getSheets().length - 1), this._commandService.executeCommand(bt.id, {
3104
+ unitId: e.getWorkbook().getUnitId(),
3105
+ order: n,
3106
+ subUnitId: e.getSheetId()
3107
+ });
3108
+ }
3109
+ /**
3110
+ * Move the active sheet to the specified index.
3111
+ * @param {number} index The index to move the active sheet to
3112
+ * @returns {Promise<boolean>} true if the sheet was moved, false otherwise
3113
+ * @example
3114
+ * ```ts
3115
+ * // The code below moves the active sheet to the specified index
3116
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3117
+ * activeSpreadsheet.moveActiveSheet(1);
3118
+ * ```
3119
+ */
3120
+ moveActiveSheet(e) {
3121
+ const t = this.getActiveSheet();
3122
+ return this.moveSheet(t, e);
3123
+ }
3124
+ /**
3125
+ * Get the PermissionInstance.
3126
+ *
3127
+ * @returns {FPermission} - The PermissionInstance.
3128
+ */
3129
+ getPermission() {
3130
+ return this._injector.createInstance(O);
3131
+ }
3132
+ /**
3133
+ * Get the defined name by name.
3134
+ * @param {string} name The name of the defined name to get
3135
+ * @returns {FDefinedName | null} The defined name with the given name
3136
+ * @example
3137
+ * ```ts
3138
+ * // The code below gets the defined name by name
3139
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3140
+ * const definedName = activeSpreadsheet.getDefinedName('MyDefinedName');
3141
+ * ```
3142
+ */
3143
+ getDefinedName(e) {
3144
+ const t = this._definedNamesService.getValueByName(this.id, e);
3145
+ return t ? this._injector.createInstance(W, { ...t, unitId: this.id }) : null;
3146
+ }
3147
+ /**
3148
+ * Get all the defined names in the workbook.
3149
+ * @returns {FDefinedName[]} All the defined names in the workbook
3150
+ * @example
3151
+ * ```ts
3152
+ * // The code below gets all the defined names in the workbook
3153
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3154
+ * const definedNames = activeSpreadsheet.getDefinedNames();
3155
+ * ```
3156
+ */
3157
+ getDefinedNames() {
3158
+ const e = this._definedNamesService.getDefinedNameMap(this.id);
3159
+ return e ? Object.values(e).map((t) => this._injector.createInstance(W, { ...t, unitId: this.id })) : [];
3160
+ }
3161
+ /**
3162
+ * Insert a defined name.
3163
+ * @param {string} name The name of the defined name to insert
3164
+ * @param {string} formulaOrRefString The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
3165
+ * @example
3166
+ * ```ts
3167
+ * // The code below inserts a defined name
3168
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3169
+ * activeSpreadsheet.insertDefinedName('MyDefinedName', 'Sheet1!A1');
3170
+ * ```
3171
+ */
3172
+ insertDefinedName(e, t) {
3173
+ const s = this._injector.createInstance(A).setName(e).setRef(t).build();
3174
+ s.localSheetId = K, this.insertDefinedNameBuilder(s);
3175
+ }
3176
+ /**
3177
+ * Delete the defined name with the given name.
3178
+ * @param {string} name The name of the defined name to delete
3179
+ * @returns {boolean} true if the defined name was deleted, false otherwise
3180
+ * @example
3181
+ * ```ts
3182
+ * // The code below deletes the defined name with the given name
3183
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3184
+ * const deleted = activeSpreadsheet.deleteDefinedName('MyDefinedName');
3185
+ * ```
3186
+ */
3187
+ deleteDefinedName(e) {
3188
+ const t = this.getDefinedName(e);
3189
+ return t ? (t.delete(), !0) : !1;
3190
+ }
3191
+ /**
3192
+ * insert a defined name by builder param
3193
+ * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
3194
+ * @example
3195
+ * ```ts
3196
+ * // The code below inserts a defined name by builder param
3197
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3198
+ * const builder = univerAPI.newDefinedName();
3199
+ * const param = builder.setName('MyDefinedName').setRef('Sheet1!A1').build();
3200
+ * activeSpreadsheet.insertDefinedNameBuilder(param);
3201
+ * ```
3202
+ */
3203
+ insertDefinedNameBuilder(e) {
3204
+ e.unitId = this.getId(), this._commandService.syncExecuteCommand(q.id, e);
3205
+ }
3206
+ /**
3207
+ * Update the defined name with the given name.
3208
+ * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
3209
+ * @example
3210
+ * ```ts
3211
+ * // The code below updates the defined name with the given name
3212
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3213
+ * const builder = activeSpreadsheet.getDefinedName('MyDefinedName').toBuilder();
3214
+ * builder.setRef('Sheet1!A2').setName('MyDefinedName1').build();
3215
+ * activeSpreadsheet.updateDefinedNameBuilder(param);
3216
+ *
3217
+ * ```
3218
+ */
3219
+ updateDefinedNameBuilder(e) {
3220
+ this._commandService.syncExecuteCommand(q.id, e);
1775
3221
  }
1776
3222
  };
1777
- U = Rt([
1778
- k(1, u(R)),
1779
- k(2, u(Ie)),
1780
- k(3, u(ue)),
1781
- k(4, he),
1782
- k(5, v),
1783
- k(6, ae),
1784
- k(7, pe)
1785
- ], U);
1786
- class ft extends ce {
3223
+ I = Yt([
3224
+ k(1, m(v)),
3225
+ k(2, m(Oe)),
3226
+ k(3, m(Ne)),
3227
+ k(4, fe),
3228
+ k(5, l),
3229
+ k(6, Q),
3230
+ k(7, Ce),
3231
+ k(8, m(ke)),
3232
+ k(9, Re)
3233
+ ], I);
3234
+ class Jt extends ve {
1787
3235
  createUniverSheet(e) {
1788
- const o = this._injector.get(he).createUnit(O.UNIVER_SHEET, e);
1789
- return this._injector.createInstance(U, o);
3236
+ const n = this._injector.get(fe).createUnit(U.UNIVER_SHEET, e);
3237
+ return this._injector.createInstance(I, n);
1790
3238
  }
1791
3239
  getActiveWorkbook() {
1792
- const e = this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET);
1793
- return e ? this._injector.createInstance(U, e) : null;
3240
+ const e = this._univerInstanceService.getCurrentUnitForType(U.UNIVER_SHEET);
3241
+ return e ? this._injector.createInstance(I, e) : null;
3242
+ }
3243
+ getUniverSheet(e) {
3244
+ const t = this._univerInstanceService.getUnit(e, U.UNIVER_SHEET);
3245
+ return t ? this._injector.createInstance(I, t) : null;
1794
3246
  }
1795
3247
  getPermission() {
1796
- return this._injector.createInstance(V);
3248
+ return this._injector.createInstance(O);
3249
+ }
3250
+ onUniverSheetCreated(e) {
3251
+ const t = this._univerInstanceService.getTypeOfUnitAdded$(U.UNIVER_SHEET).subscribe((n) => {
3252
+ const s = this._injector.createInstance(I, n);
3253
+ e(s);
3254
+ });
3255
+ return Ie(t);
3256
+ }
3257
+ newDefinedName() {
3258
+ return this._injector.createInstance(A);
1797
3259
  }
1798
3260
  }
1799
- ce.extend(ft);
1800
- var bt = Object.defineProperty, pt = Object.getOwnPropertyDescriptor, yt = (n, e, t, o) => {
1801
- for (var s = o > 1 ? void 0 : o ? pt(e, t) : e, r = n.length - 1, i; r >= 0; r--)
1802
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
1803
- return o && s && bt(e, t, s), s;
1804
- }, Pt = (n, e) => (t, o) => e(t, o, n);
1805
- let ie = class extends b {
1806
- constructor(n) {
1807
- super(), this._injector = n;
3261
+ ve.extend(Jt);
3262
+ var Qt = Object.defineProperty, Xt = Object.getOwnPropertyDescriptor, Zt = (o, e, t, n) => {
3263
+ for (var s = n > 1 ? void 0 : n ? Xt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
3264
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
3265
+ return n && s && Qt(e, t, s), s;
3266
+ }, en = (o, e) => (t, n) => e(t, n, o);
3267
+ let _e = class extends p {
3268
+ constructor(o) {
3269
+ super(), this._injector = o;
1808
3270
  }
1809
3271
  };
1810
- ie = yt([
1811
- Pt(0, u(R))
1812
- ], ie);
3272
+ _e = Zt([
3273
+ en(0, m(v))
3274
+ ], _e);
1813
3275
  export {
1814
- V as FPermission,
3276
+ O as FPermission,
1815
3277
  S as FRange,
1816
- L as FSelection,
1817
- ie as FSheetHooks,
1818
- U as FWorkbook,
1819
- g as FWorksheet
3278
+ F as FSelection,
3279
+ _e as FSheetHooks,
3280
+ I as FWorkbook,
3281
+ _ as FWorksheet
1820
3282
  };