@univerjs/sheets 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/lib/cjs/facade.js +1 -1
  2. package/lib/cjs/index.js +3 -3
  3. package/lib/es/facade.js +1959 -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 +96 -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
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,68 @@ 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
+ * @example
871
+ * ```
872
+ * univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackgroundColor('red')
873
+ * ```
874
+ * @param color {string}
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
+ * e.g. `univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackground('red')`
892
+ * @param color {string}
893
+ */
894
+ setBackground(o) {
895
+ return this.setBackgroundColor(o);
896
+ }
466
897
  /**
467
898
  * 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
899
  * @param value
469
900
  */
470
- setValue(n) {
471
- const e = z(n);
901
+ setValue(o) {
902
+ const e = J(o);
472
903
  if (!e)
473
904
  throw new Error("Invalid value");
474
- return this._commandService.executeCommand(G.id, {
905
+ return this._commandService.executeCommand(ne.id, {
475
906
  unitId: this._workbook.getUnitId(),
476
907
  subUnitId: this._worksheet.getSheetId(),
477
908
  range: this._range,
@@ -482,54 +913,54 @@ let S = class extends b {
482
913
  * Set the cell wrap of the given range.
483
914
  * 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
915
  */
485
- setWrap(n) {
486
- return this._commandService.executeCommand(q.id, {
916
+ setWrap(o) {
917
+ return this._commandService.executeCommand(se.id, {
487
918
  unitId: this._workbook.getUnitId(),
488
919
  subUnitId: this._worksheet.getSheetId(),
489
920
  range: this._range,
490
- value: n ? H.WRAP : H.UNSPECIFIED
921
+ value: o ? Z.WRAP : Z.UNSPECIFIED
491
922
  });
492
923
  }
493
924
  /**
494
925
  * Sets the text wrapping strategy for the cells in the range.
495
926
  */
496
- setWrapStrategy(n) {
497
- return this._commandService.executeCommand(q.id, {
927
+ setWrapStrategy(o) {
928
+ return this._commandService.executeCommand(se.id, {
498
929
  unitId: this._workbook.getUnitId(),
499
930
  subUnitId: this._worksheet.getSheetId(),
500
931
  range: this._range,
501
- value: n
932
+ value: o
502
933
  });
503
934
  }
504
935
  /**
505
936
  * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).
506
937
  */
507
- setVerticalAlignment(n) {
508
- return this._commandService.executeCommand(Oe.id, {
938
+ setVerticalAlignment(o) {
939
+ return this._commandService.executeCommand(et.id, {
509
940
  unitId: this._workbook.getUnitId(),
510
941
  subUnitId: this._worksheet.getSheetId(),
511
942
  range: this._range,
512
- value: at(n)
943
+ value: jt(o)
513
944
  });
514
945
  }
515
946
  /**
516
947
  * Set the horizontal (left to right) alignment for the given range (left/center/right).
517
948
  */
518
- setHorizontalAlignment(n) {
519
- return this._commandService.executeCommand(Ve.id, {
949
+ setHorizontalAlignment(o) {
950
+ return this._commandService.executeCommand(tt.id, {
520
951
  unitId: this._workbook.getUnitId(),
521
952
  subUnitId: this._worksheet.getSheetId(),
522
953
  range: this._range,
523
- value: rt(n)
954
+ value: Dt(o)
524
955
  });
525
956
  }
526
957
  /**
527
958
  * 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
959
  * @param value
529
960
  */
530
- setValues(n) {
531
- const e = ct(n, this._range);
532
- return this._commandService.executeCommand(G.id, {
961
+ setValues(o) {
962
+ const e = Ot(o, this._range);
963
+ return this._commandService.executeCommand(ne.id, {
533
964
  unitId: this._workbook.getUnitId(),
534
965
  subUnitId: this._worksheet.getSheetId(),
535
966
  range: this._range,
@@ -540,72 +971,72 @@ let S = class extends b {
540
971
  * Sets the font weight for the given range (normal/bold),
541
972
  * @param fontWeight The font weight, either 'normal' or 'bold'; a null value resets the font weight.
542
973
  */
543
- setFontWeight(n) {
974
+ setFontWeight(o) {
544
975
  let e;
545
- if (n === "bold")
546
- e = m.TRUE;
547
- else if (n === "normal")
548
- e = m.FALSE;
549
- else if (n === null)
976
+ if (o === "bold")
977
+ e = u.TRUE;
978
+ else if (o === "normal")
979
+ e = u.FALSE;
980
+ else if (o === null)
550
981
  e = null;
551
982
  else
552
983
  throw new Error("Invalid fontWeight");
553
984
  const t = {
554
985
  type: "bl",
555
986
  value: e
556
- }, o = {
987
+ }, n = {
557
988
  unitId: this._workbook.getUnitId(),
558
989
  subUnitId: this._worksheet.getSheetId(),
559
990
  range: this._range,
560
991
  style: t
561
992
  };
562
- return this._commandService.executeCommand(_.id, o), this;
993
+ return this._commandService.executeCommand(C.id, n), this;
563
994
  }
564
995
  /**
565
996
  * Sets the font style for the given range ('italic' or 'normal').
566
997
  * @param fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.
567
998
  */
568
- setFontStyle(n) {
999
+ setFontStyle(o) {
569
1000
  let e;
570
- if (n === "italic")
571
- e = m.TRUE;
572
- else if (n === "normal")
573
- e = m.FALSE;
574
- else if (n === null)
1001
+ if (o === "italic")
1002
+ e = u.TRUE;
1003
+ else if (o === "normal")
1004
+ e = u.FALSE;
1005
+ else if (o === null)
575
1006
  e = null;
576
1007
  else
577
1008
  throw new Error("Invalid fontStyle");
578
1009
  const t = {
579
1010
  type: "it",
580
1011
  value: e
581
- }, o = {
1012
+ }, n = {
582
1013
  unitId: this._workbook.getUnitId(),
583
1014
  subUnitId: this._worksheet.getSheetId(),
584
1015
  range: this._range,
585
1016
  style: t
586
1017
  };
587
- return this._commandService.executeCommand(_.id, o), this;
1018
+ return this._commandService.executeCommand(C.id, n), this;
588
1019
  }
589
1020
  /**
590
1021
  * Sets the font line style of the given range ('underline', 'line-through', or 'none').
591
1022
  * @param fontLine The font line style, either 'underline', 'line-through', or 'none'; a null value resets the font line style.
592
1023
  */
593
- setFontLine(n) {
594
- if (n === "underline")
1024
+ setFontLine(o) {
1025
+ if (o === "underline")
595
1026
  this._setFontUnderline({
596
- s: m.TRUE
1027
+ s: u.TRUE
597
1028
  });
598
- else if (n === "line-through")
1029
+ else if (o === "line-through")
599
1030
  this._setFontStrikethrough({
600
- s: m.TRUE
1031
+ s: u.TRUE
601
1032
  });
602
- else if (n === "none")
1033
+ else if (o === "none")
603
1034
  this._setFontUnderline({
604
- s: m.FALSE
1035
+ s: u.FALSE
605
1036
  }), this._setFontStrikethrough({
606
- s: m.FALSE
1037
+ s: u.FALSE
607
1038
  });
608
- else if (n === null)
1039
+ else if (o === null)
609
1040
  this._setFontUnderline(null), this._setFontStrikethrough(null);
610
1041
  else
611
1042
  throw new Error("Invalid fontLine");
@@ -614,170 +1045,368 @@ let S = class extends b {
614
1045
  /**
615
1046
  * Sets the font underline style of the given ITextDecoration
616
1047
  */
617
- _setFontUnderline(n) {
1048
+ _setFontUnderline(o) {
618
1049
  const e = {
619
1050
  type: "ul",
620
- value: n
1051
+ value: o
621
1052
  }, t = {
622
1053
  unitId: this._workbook.getUnitId(),
623
1054
  subUnitId: this._worksheet.getSheetId(),
624
1055
  range: this._range,
625
1056
  style: e
626
1057
  };
627
- this._commandService.executeCommand(_.id, t);
1058
+ this._commandService.executeCommand(C.id, t);
628
1059
  }
629
1060
  /**
630
1061
  * Sets the font strikethrough style of the given ITextDecoration
631
1062
  */
632
- _setFontStrikethrough(n) {
1063
+ _setFontStrikethrough(o) {
633
1064
  const e = {
634
1065
  type: "st",
635
- value: n
1066
+ value: o
636
1067
  }, t = {
637
1068
  unitId: this._workbook.getUnitId(),
638
1069
  subUnitId: this._worksheet.getSheetId(),
639
1070
  range: this._range,
640
1071
  style: e
641
1072
  };
642
- this._commandService.executeCommand(_.id, t);
1073
+ this._commandService.executeCommand(C.id, t);
643
1074
  }
644
1075
  /**
645
1076
  * Sets the font family, such as "Arial" or "Helvetica".
646
1077
  * @param fontFamily The font family to set; a null value resets the font family.
647
1078
  */
648
- setFontFamily(n) {
1079
+ setFontFamily(o) {
649
1080
  const e = {
650
1081
  type: "ff",
651
- value: n
1082
+ value: o
652
1083
  }, t = {
653
1084
  unitId: this._workbook.getUnitId(),
654
1085
  subUnitId: this._worksheet.getSheetId(),
655
1086
  range: this._range,
656
1087
  style: e
657
1088
  };
658
- return this._commandService.executeCommand(_.id, t), this;
1089
+ return this._commandService.executeCommand(C.id, t), this;
659
1090
  }
660
1091
  /**
661
1092
  * Sets the font size, with the size being the point size to use.
662
1093
  * @param size A font size in point size. A null value resets the font size.
663
1094
  */
664
- setFontSize(n) {
1095
+ setFontSize(o) {
665
1096
  const e = {
666
1097
  type: "fs",
667
- value: n
1098
+ value: o
668
1099
  }, t = {
669
1100
  unitId: this._workbook.getUnitId(),
670
1101
  subUnitId: this._worksheet.getSheetId(),
671
1102
  range: this._range,
672
1103
  style: e
673
1104
  };
674
- return this._commandService.executeCommand(_.id, t), this;
1105
+ return this._commandService.executeCommand(C.id, t), this;
675
1106
  }
676
1107
  /**
677
1108
  * Sets the font color in CSS notation (such as '#ffffff' or 'white').
678
1109
  * @param color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color.
679
1110
  */
680
- setFontColor(n) {
1111
+ setFontColor(o) {
681
1112
  const t = {
682
1113
  type: "cl",
683
- value: n === null ? null : { rgb: n }
684
- }, o = {
1114
+ value: o === null ? null : { rgb: o }
1115
+ }, n = {
685
1116
  unitId: this._workbook.getUnitId(),
686
1117
  subUnitId: this._worksheet.getSheetId(),
687
1118
  range: this._range,
688
1119
  style: t
689
1120
  };
690
- return this._commandService.executeCommand(_.id, o), this;
1121
+ return this._commandService.executeCommand(C.id, n), this;
691
1122
  }
692
1123
  // #endregion editing
693
1124
  //#region Merge cell
694
1125
  /**
695
1126
  * Merge cells in a range into one merged cell
1127
+ *
1128
+ * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
1129
+ *
696
1130
  * @returns This range, for chaining
697
1131
  */
698
- async merge() {
699
- const n = this._workbook.getUnitId(), e = this._worksheet.getSheetId();
700
- return await M(this._injector, n, e, [this._range]), this;
1132
+ async merge(o = !0) {
1133
+ const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId();
1134
+ return await L(this._injector, e, t, [this._range], o), this;
701
1135
  }
702
1136
  /**
703
1137
  * Merges cells in a range horizontally.
1138
+ *
1139
+ * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
1140
+ *
704
1141
  * @returns This range, for chaining
705
1142
  */
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;
1143
+ async mergeAcross(o = !0) {
1144
+ const e = oe([this._range], ee.ROWS), t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
1145
+ return await L(this._injector, t, n, e, o), this;
709
1146
  }
710
1147
  /**
711
1148
  * Merges cells in a range vertically.
1149
+ *
1150
+ * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
1151
+ *
712
1152
  * @returns This range, for chaining
713
1153
  */
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;
1154
+ async mergeVertically(o = !0) {
1155
+ const e = oe([this._range], ee.COLUMNS), t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
1156
+ return await L(this._injector, t, n, e, o), this;
717
1157
  }
718
1158
  /**
719
1159
  * Returns true if cells in the current range overlap a merged cell.
720
1160
  * @returns {boolean} is overlap with a merged cell
721
1161
  */
722
1162
  isPartOfMerge() {
723
- const { startRow: n, startColumn: e, endRow: t, endColumn: o } = this._range;
724
- return this._worksheet.getMergedCellRange(n, e, t, o).length > 0;
1163
+ const { startRow: o, startColumn: e, endRow: t, endColumn: n } = this._range;
1164
+ return this._worksheet.getMergedCellRange(o, e, t, n).length > 0;
725
1165
  }
726
1166
  /**
727
- * Unmerge cells in the range
1167
+ * Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.
728
1168
  * @returns This range, for chaining
729
1169
  */
730
1170
  breakApart() {
731
- return this._commandService.executeCommand(ze.id, { ranges: [this._range] }), this;
1171
+ return this._commandService.executeCommand(nt.id, { ranges: [this._range] }), this;
732
1172
  }
733
1173
  //#endregion
734
1174
  /**
735
1175
  * 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);
1176
+ * @param callback the callback function to be called for each cell in the range
1177
+ * @param {number} callback.row the row number of the cell
1178
+ * @param {number} callback.col the column number of the cell
1179
+ * @param {ICellData} callback.cell the cell data
1180
+ * ```ts
1181
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1182
+ * const fWorksheet = fWorkbook.getActiveSheet();
1183
+ * const fRange = fWorksheet.getRange('A1:B2');
1184
+ * fRange.forEach((row, col, cell) => {
1185
+ * console.log(row, col, cell);
1186
+ * });
1187
+ * ```
1188
+ */
1189
+ forEach(o) {
1190
+ const { startColumn: e, startRow: t, endColumn: n, endRow: s } = this._range;
1191
+ this._worksheet.getMatrixWithMergedCells(t, e, s, n).forValue((r, i, a) => {
1192
+ o(r, i, a);
1193
+ });
1194
+ }
1195
+ /**
1196
+ * Returns a string description of the range, in A1 notation.
1197
+ * @returns {string} The A1 notation of the range.
1198
+ * ```ts
1199
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1200
+ * const fWorksheet = fWorkbook.getActiveSheet();
1201
+ * const fRange = fWorksheet.getRange('A1:B2');
1202
+ * console.log(fRange.getA1Notation()); // A1:B2
1203
+ * ```
1204
+ */
1205
+ getA1Notation(o) {
1206
+ return o ? Be(this._worksheet.getName(), this._range) : X(this._range);
1207
+ }
1208
+ /**
1209
+ * Sets the specified range as the active range, with the top left cell in the range as the current cell.
1210
+ * @returns {FRange} This range, for chaining.
1211
+ * @example
1212
+ * ```ts
1213
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1214
+ * const fWorksheet = fWorkbook.getActiveSheet();
1215
+ * const fRange = fWorksheet.getRange('A1:B2');
1216
+ * fRange.activate(); // the active cell will be A1
1217
+ * ```
1218
+ */
1219
+ activate() {
1220
+ return this._injector.createInstance(I, this._workbook).setActiveRange(this), this;
1221
+ }
1222
+ /**
1223
+ * Sets the specified cell as the current cell.
1224
+ * If the specified cell is present in an existing range, then that range becomes the active range with the cell as the current cell.
1225
+ * 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.
1226
+ * @returns {FRange} This range, for chaining.
1227
+ * @description If the range is not a single cell, an error will be thrown.
1228
+ */
1229
+ activateAsCurrentCell() {
1230
+ const o = this._worksheet.getMergedCell(this._range.startRow, this._range.startColumn);
1231
+ if (o && N.equals(o, this._range) || !o && this._range.startRow === this._range.endRow && this._range.startColumn === this._range.endColumn)
1232
+ return this.activate();
1233
+ throw new Error("The range is not a single cell");
1234
+ }
1235
+ /**
1236
+ * Splits a column of text into multiple columns based on a custom specified delimiter.
1237
+ * @param {boolean} [treatMultipleDelimitersAsOne] Whether to treat multiple continuous delimiters as one. The default value is false.
1238
+ * @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.
1239
+ * @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.
1240
+ * @example Show how to split text to columns with combined delimiter. The bit operations are used to combine the delimiters.
1241
+ * // A1:A3 has following values:
1242
+ * // A | B | C
1243
+ * // 1;;2;3 | |
1244
+ * // 1;,2;3 | |
1245
+ * // After calling splitTextToColumns(false, SplitDelimiterEnum.Semicolon|SplitDelimiterEnum.Comma), the range will be:
1246
+ * // A | B | C | D
1247
+ * // 1 | | 2 | 3
1248
+ * // 1 | | 2 | 3
1249
+ * // After calling splitTextToColumns(true, SplitDelimiterEnum.Semicolon|SplitDelimiterEnum.Comma), the range will be:
1250
+ * // A | B | C
1251
+ * // 1 | 2 | 3
1252
+ * // 1 | 2 | 3
1253
+ * @example Show how to split text to columns with custom delimiter
1254
+ * // A1:A3 has following values:
1255
+ * // A | B | C
1256
+ * // 1#2#3 | |
1257
+ * // 4##5#6 | |
1258
+ * // After calling splitTextToColumns(false, SplitDelimiterEnum.Custom, '#'), the range will be:
1259
+ * // A | B | C | D
1260
+ * // 1 | 2 | 3 |
1261
+ * // 4 | | 5 | 6
1262
+ * // After calling splitTextToColumns(true, SplitDelimiterEnum.Custom, '#'), the range will be:
1263
+ * // A | B | C
1264
+ * // 1 | 2 | 3
1265
+ * // 4 | 5 | 6
1266
+ */
1267
+ splitTextToColumns(o, e, t) {
1268
+ this._commandService.executeCommand(st.id, {
1269
+ unitId: this._workbook.getUnitId(),
1270
+ subUnitId: this._worksheet.getSheetId(),
1271
+ range: this._range,
1272
+ delimiter: e,
1273
+ customDelimiter: t,
1274
+ treatMultipleDelimitersAsOne: o
742
1275
  });
743
1276
  }
744
1277
  };
745
- S = mt([
746
- D(3, u(R)),
747
- D(4, v),
748
- D(5, u(et))
1278
+ S = Tt([
1279
+ G(3, m(v)),
1280
+ G(4, l),
1281
+ G(5, m(Le))
749
1282
  ], 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;
1283
+ var Lt = Object.defineProperty, Bt = Object.getOwnPropertyDescriptor, zt = (o, e, t, n) => {
1284
+ for (var s = n > 1 ? void 0 : n ? Bt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
1285
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
1286
+ return n && s && Lt(e, t, s), s;
1287
+ }, Vt = (o, e) => (t, n) => e(t, n, o);
1288
+ let F = class {
1289
+ constructor(o, e, t, n) {
1290
+ this._workbook = o, this._worksheet = e, this._selections = t, this._injector = n;
758
1291
  }
1292
+ /**
1293
+ * Represents the active selection in the sheet. Which means the selection contains the active cell.
1294
+ * @returns {FRange | null} The active selection.
1295
+ */
759
1296
  getActiveRange() {
760
- const n = this._selections.find((e) => !!e.primary);
761
- return n ? this._injector.createInstance(S, this._workbook, this._worksheet, n.range) : null;
1297
+ const o = this._selections.find((e) => !!e.primary);
1298
+ return o ? this._injector.createInstance(S, this._workbook, this._worksheet, o.range) : null;
1299
+ }
1300
+ /**
1301
+ * Represents the active selection list in the sheet.
1302
+ * @returns {FRange[]} The active selection list.
1303
+ */
1304
+ getActiveRangeList() {
1305
+ return this._selections.map((o) => this._injector.createInstance(S, this._workbook, this._worksheet, o.range));
1306
+ }
1307
+ /**
1308
+ * Represents the current select cell in the sheet.
1309
+ * @returns {ISelectionCell} The current select cell info.Pay attention to the type of the return value.
1310
+ */
1311
+ getCurrentCell() {
1312
+ const o = this._selections.find((e) => !!e.primary);
1313
+ return o ? o.primary : null;
1314
+ }
1315
+ /**
1316
+ * Returns the active sheet in the spreadsheet.
1317
+ * @returns {FWorksheet} The active sheet in the spreadsheet.
1318
+ * @example
1319
+ * ```ts
1320
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1321
+ * const fWorksheet = fWorkbook.getActiveSheet();
1322
+ * const fSelection = fWorksheet.getSelection();
1323
+ * const activeSheet = fSelection.getActiveSheet();
1324
+ * console.log(activeSheet.equalTo(fWorksheet)); // true
1325
+ * ```
1326
+ */
1327
+ getActiveSheet() {
1328
+ const o = this._injector.createInstance(I, this._workbook);
1329
+ return this._injector.createInstance(_, o, this._workbook, this._worksheet);
1330
+ }
1331
+ /**
1332
+ * 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.
1333
+ * @param {FRange} cell The new primary cell to update.
1334
+ * @returns {FSelection} The new selection after updating the primary cell.Because the selection is immutable, the return value is a new selection.
1335
+ * @example
1336
+ * ```ts
1337
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1338
+ * const fWorksheet = fWorkbook.getActiveSheet();
1339
+ * const fSelection = fWorksheet.getSelection();
1340
+ * const cell = fWorksheet.getCell('A1');
1341
+ * const newSelection = fSelection.updatePrimaryCell(cell);
1342
+ * console.log(newSelection.getActiveRange().getA1Notation()); // A1
1343
+ * ```
1344
+ */
1345
+ async updatePrimaryCell(o) {
1346
+ const e = this._injector.get(l);
1347
+ let t = [], n = !1;
1348
+ for (const { range: r, style: i } of this._selections)
1349
+ N.contains(r, o.getRange()) ? (t.push({
1350
+ range: r,
1351
+ primary: Y(o.getRange(), this._worksheet),
1352
+ style: i
1353
+ }), n = !0) : t.push({
1354
+ range: r,
1355
+ primary: null,
1356
+ style: i
1357
+ });
1358
+ n || (t = [
1359
+ {
1360
+ range: o.getRange(),
1361
+ primary: Y(o.getRange(), this._worksheet)
1362
+ }
1363
+ ]);
1364
+ const s = {
1365
+ unitId: this._workbook.getUnitId(),
1366
+ subUnitId: this._worksheet.getSheetId(),
1367
+ selections: t
1368
+ };
1369
+ return await e.syncExecuteCommand(Ue.id, s), new F(this._workbook, this._worksheet, t, this._injector);
1370
+ }
1371
+ /**
1372
+ *Get the next primary cell in the specified direction. If the primary cell not exists in selections, return null.
1373
+ * @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).
1374
+ * @returns {FRange | null} The next primary cell in the specified direction.
1375
+ * @example
1376
+ * ```ts
1377
+ * // import { Direction } from '@univerjs/core';
1378
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1379
+ * const fWorksheet = fWorkbook.getActiveSheet();
1380
+ * // make sure the active cell is A1 and selection is A1:C3
1381
+ * const fSelection = fWorksheet.getSelection();
1382
+ * const nextCell = fSelection.getNextDataRange(Direction.RIGHT);
1383
+ * console.log(nextCell?.getA1Notation()); // B1
1384
+ * ```
1385
+ */
1386
+ getNextDataRange(o) {
1387
+ if (!this._selections.find((n) => !!n.primary))
1388
+ return null;
1389
+ const t = ot(this._selections.concat(), o, this._worksheet);
1390
+ return t ? this._injector.createInstance(S, this._workbook, this._worksheet, t) : null;
762
1391
  }
763
1392
  };
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) {
1393
+ F = zt([
1394
+ Vt(3, m(v))
1395
+ ], F);
1396
+ var Ht = Object.defineProperty, $t = Object.getOwnPropertyDescriptor, Gt = (o, e, t, n) => {
1397
+ for (var s = n > 1 ? void 0 : n ? $t(e, t) : e, r = o.length - 1, i; r >= 0; r--)
1398
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
1399
+ return n && s && Ht(e, t, s), s;
1400
+ }, M = (o, e) => (t, n) => e(t, n, o);
1401
+ let _ = class extends p {
1402
+ constructor(e, t, n, s, r, i, a) {
774
1403
  super();
775
1404
  /**
776
1405
  * Sets the active selection region for this sheet.
777
1406
  * @param range The range to set as the active selection.
778
1407
  */
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;
1408
+ P(this, "setActiveSelection", this.setActiveRange);
1409
+ this._fWorkbook = e, this._workbook = t, this._worksheet = n, this._injector = s, this._selectionManagerService = r, this._logService = i, this._commandService = a;
781
1410
  }
782
1411
  /**
783
1412
  * Returns the injector
@@ -788,34 +1417,38 @@ let g = class extends b {
788
1417
  }
789
1418
  /**
790
1419
  * Returns the workbook
791
- * @returns The workbook
1420
+ * @returns {Workbook} The workbook instance.
792
1421
  */
793
1422
  getWorkbook() {
794
1423
  return this._workbook;
795
1424
  }
796
1425
  /**
797
- * Returns the worksheet id
798
- * @returns The id of the worksheet
1426
+ * Returns the worksheet id.
1427
+ * @returns {string} The id of the worksheet.
799
1428
  */
800
1429
  getSheetId() {
801
1430
  return this._worksheet.getSheetId();
802
1431
  }
803
1432
  /**
804
- * Returns the worksheet name
805
- * @returns The name of the worksheet
1433
+ * Returns the worksheet name.
1434
+ * @returns {string} The name of the worksheet.
806
1435
  */
807
1436
  getSheetName() {
808
1437
  return this._worksheet.getName();
809
1438
  }
1439
+ /**
1440
+ * Represents the selection ranges info of the worksheet.
1441
+ * @returns {FSelection} return the current selections of the worksheet or null if there is no selection.
1442
+ */
810
1443
  getSelection() {
811
1444
  const e = this._selectionManagerService.getCurrentSelections();
812
- return e ? this._injector.createInstance(L, this._workbook, this._worksheet, e) : null;
1445
+ return e ? this._injector.createInstance(F, this._workbook, this._worksheet, e) : null;
813
1446
  }
814
1447
  // #region rows
815
1448
  // #region default style
816
1449
  /**
817
1450
  * Get the default style of the worksheet
818
- * @returns Default style
1451
+ * @returns {IStyleData} Default style of the worksheet.
819
1452
  */
820
1453
  getDefaultStyle() {
821
1454
  return this._worksheet.getDefaultCellStyle();
@@ -840,14 +1473,14 @@ let g = class extends b {
840
1473
  }
841
1474
  /**
842
1475
  * Set the default style of the worksheet
843
- * @param style default style
844
- * @returns this worksheet
1476
+ * @param {StyleDataInfo} style default style
1477
+ * @returns {Promise<FWorksheet>} This sheet, for chaining.
845
1478
  */
846
1479
  async setDefaultStyle(e) {
847
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId();
848
- return await this._commandService.executeCommand(Le.id, {
1480
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
1481
+ return await this._commandService.executeCommand(rt.id, {
849
1482
  unitId: t,
850
- subUnitId: o,
1483
+ subUnitId: n,
851
1484
  defaultStyle: e
852
1485
  }), this._worksheet.setDefaultCellStyle(e), this;
853
1486
  }
@@ -855,10 +1488,11 @@ let g = class extends b {
855
1488
  * Set the default style of the worksheet row
856
1489
  * @param {number} index The row index
857
1490
  * @param {string | Nullable<IStyleData>} style The style name or style data
1491
+ * @returns {Promise<FWorksheet>} This sheet, for chaining.
858
1492
  */
859
1493
  async setColumnDefaultStyle(e, t) {
860
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
861
- unitId: o,
1494
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1495
+ unitId: n,
862
1496
  subUnitId: s,
863
1497
  columnData: {
864
1498
  [e]: {
@@ -866,16 +1500,17 @@ let g = class extends b {
866
1500
  }
867
1501
  }
868
1502
  };
869
- return await this._commandService.executeCommand(J.id, r), this;
1503
+ return await this._commandService.executeCommand(re.id, r), this;
870
1504
  }
871
1505
  /**
872
1506
  * Set the default style of the worksheet column
873
1507
  * @param {number} index The column index
874
1508
  * @param {string | Nullable<IStyleData>} style The style name or style data
1509
+ * @returns {Promise<FWorksheet>} This sheet, for chaining.
875
1510
  */
876
1511
  async setRowDefaultStyle(e, t) {
877
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
878
- unitId: o,
1512
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1513
+ unitId: n,
879
1514
  subUnitId: s,
880
1515
  rowData: {
881
1516
  [e]: {
@@ -883,12 +1518,12 @@ let g = class extends b {
883
1518
  }
884
1519
  }
885
1520
  };
886
- return await this._commandService.executeCommand(K.id, r), this;
1521
+ return await this._commandService.executeCommand(ie.id, r), this;
887
1522
  }
888
- getRange(e, t, o, s) {
1523
+ getRange(e, t, n, s) {
889
1524
  let r, i;
890
1525
  if (typeof e == "string") {
891
- const { range: a, sheetName: h } = tt(e), c = h ? this._workbook.getSheetBySheetName(h) : this._worksheet;
1526
+ const { range: a, sheetName: h } = ze(e), c = h ? this._workbook.getSheetBySheetName(h) : this._worksheet;
892
1527
  if (!c)
893
1528
  throw new Error("Range not found");
894
1529
  i = c, r = {
@@ -897,16 +1532,16 @@ let g = class extends b {
897
1532
  sheetId: i.getSheetId(),
898
1533
  // Use the current range instead of the future actual range to match Apps Script behavior.
899
1534
  // 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
1535
+ rangeType: g.NORMAL,
1536
+ startRow: a.rangeType === g.COLUMN ? 0 : a.startRow,
1537
+ endRow: a.rangeType === g.COLUMN ? i.getMaxRows() - 1 : a.endRow,
1538
+ startColumn: a.rangeType === g.ROW ? 0 : a.startColumn,
1539
+ endColumn: a.rangeType === g.ROW ? i.getMaxColumns() - 1 : a.endColumn
905
1540
  };
906
1541
  } else if (typeof e == "number" && t !== void 0)
907
1542
  i = this._worksheet, r = {
908
1543
  startRow: e,
909
- endRow: e + (o != null ? o : 1) - 1,
1544
+ endRow: e + (n != null ? n : 1) - 1,
910
1545
  startColumn: t,
911
1546
  endColumn: t + (s != null ? s : 1) - 1,
912
1547
  unitId: this._workbook.getUnitId(),
@@ -962,9 +1597,9 @@ let g = class extends b {
962
1597
  * @returns This sheet, for chaining.
963
1598
  */
964
1599
  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,
1600
+ 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);
1601
+ return await this._commandService.executeCommand(ae.id, {
1602
+ unitId: n,
968
1603
  subUnitId: s,
969
1604
  direction: r,
970
1605
  range: {
@@ -983,9 +1618,9 @@ let g = class extends b {
983
1618
  * @returns This sheet, for chaining.
984
1619
  */
985
1620
  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,
1621
+ 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);
1622
+ return await this._commandService.executeCommand(ae.id, {
1623
+ unitId: n,
989
1624
  subUnitId: s,
990
1625
  direction: r,
991
1626
  range: {
@@ -1012,14 +1647,14 @@ let g = class extends b {
1012
1647
  * @returns This sheet, for chaining.
1013
1648
  */
1014
1649
  async deleteRows(e, t) {
1015
- const o = {
1650
+ const n = {
1016
1651
  startRow: e,
1017
1652
  endRow: e + t - 1,
1018
1653
  startColumn: 0,
1019
1654
  endColumn: this._worksheet.getColumnCount() - 1
1020
1655
  };
1021
- return await this._commandService.executeCommand(Be.id, {
1022
- range: o
1656
+ return await this._commandService.executeCommand(it.id, {
1657
+ range: n
1023
1658
  }), this;
1024
1659
  }
1025
1660
  /**
@@ -1029,14 +1664,14 @@ let g = class extends b {
1029
1664
  * @returns This sheet, for chaining.
1030
1665
  */
1031
1666
  async moveRows(e, t) {
1032
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = W(e.getRange(), this._worksheet), i = r, a = {
1667
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = H(e.getRange(), this._worksheet), i = r, a = {
1033
1668
  startRow: t,
1034
1669
  endRow: t,
1035
1670
  startColumn: r.startColumn,
1036
1671
  endColumn: r.endColumn
1037
1672
  };
1038
- return await this._commandService.executeCommand(He.id, {
1039
- unitId: o,
1673
+ return await this._commandService.executeCommand(at.id, {
1674
+ unitId: n,
1040
1675
  subUnitId: s,
1041
1676
  range: r,
1042
1677
  fromRange: i,
@@ -1049,10 +1684,10 @@ let g = class extends b {
1049
1684
  * @returns This sheet, for chaining.
1050
1685
  */
1051
1686
  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, {
1687
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = H(e.getRange(), this._worksheet);
1688
+ return await this._commandService.executeCommand(he.id, {
1054
1689
  unitId: t,
1055
- subUnitId: o,
1690
+ subUnitId: n,
1056
1691
  ranges: [s]
1057
1692
  }), this;
1058
1693
  }
@@ -1063,15 +1698,15 @@ let g = class extends b {
1063
1698
  * @returns This sheet, for chaining.
1064
1699
  */
1065
1700
  async hideRows(e, t = 1) {
1066
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1701
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1067
1702
  startRow: e,
1068
1703
  endRow: e + t - 1,
1069
1704
  startColumn: 0,
1070
1705
  endColumn: this._worksheet.getColumnCount() - 1,
1071
- rangeType: l.ROW
1706
+ rangeType: g.ROW
1072
1707
  };
1073
- return await this._commandService.executeCommand(X.id, {
1074
- unitId: o,
1708
+ return await this._commandService.executeCommand(he.id, {
1709
+ unitId: n,
1075
1710
  subUnitId: s,
1076
1711
  ranges: [r]
1077
1712
  }), this;
@@ -1082,10 +1717,10 @@ let g = class extends b {
1082
1717
  * @returns This sheet, for chaining.
1083
1718
  */
1084
1719
  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, {
1720
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = H(e.getRange(), this._worksheet);
1721
+ return await this._commandService.executeCommand(ce.id, {
1087
1722
  unitId: t,
1088
- subUnitId: o,
1723
+ subUnitId: n,
1089
1724
  ranges: [s]
1090
1725
  }), this;
1091
1726
  }
@@ -1096,15 +1731,15 @@ let g = class extends b {
1096
1731
  * @returns This sheet, for chaining.
1097
1732
  */
1098
1733
  async showRows(e, t = 1) {
1099
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1734
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1100
1735
  startRow: e,
1101
1736
  endRow: e + t - 1,
1102
1737
  startColumn: 0,
1103
1738
  endColumn: this._worksheet.getColumnCount() - 1,
1104
- rangeType: l.ROW
1739
+ rangeType: g.ROW
1105
1740
  };
1106
- return await this._commandService.executeCommand(Z.id, {
1107
- unitId: o,
1741
+ return await this._commandService.executeCommand(ce.id, {
1742
+ unitId: n,
1108
1743
  subUnitId: s,
1109
1744
  ranges: [r]
1110
1745
  }), this;
@@ -1125,24 +1760,24 @@ let g = class extends b {
1125
1760
  * @param height The height in pixels to set it to.
1126
1761
  * @returns This sheet, for chaining.
1127
1762
  */
1128
- async setRowHeights(e, t, o) {
1763
+ async setRowHeights(e, t, n) {
1129
1764
  var c;
1130
1765
  const s = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = this._worksheet.getRowManager(), a = [], h = [];
1131
1766
  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 = {
1767
+ const T = ((c = i.getRow(d)) == null ? void 0 : c.ah) || this._worksheet.getConfig().defaultRowHeight, x = {
1133
1768
  startRow: d,
1134
1769
  endRow: d,
1135
1770
  startColumn: 0,
1136
1771
  endColumn: this._worksheet.getColumnCount() - 1
1137
1772
  };
1138
- o <= x ? a.push(B) : h.push(B);
1773
+ n <= T ? a.push(x) : h.push(x);
1139
1774
  }
1140
- return h.length > 0 && await this._commandService.executeCommand(ee.id, {
1775
+ return h.length > 0 && await this._commandService.executeCommand(de.id, {
1141
1776
  unitId: s,
1142
1777
  subUnitId: r,
1143
1778
  ranges: h,
1144
- value: o
1145
- }), a.length > 0 && await this._commandService.executeCommand(Ne.id, {
1779
+ value: n
1780
+ }), a.length > 0 && await this._commandService.executeCommand(ht.id, {
1146
1781
  unitId: s,
1147
1782
  subUnitId: r,
1148
1783
  ranges: a
@@ -1155,7 +1790,7 @@ let g = class extends b {
1155
1790
  * @param height The height in pixels to set it to.
1156
1791
  * @returns This sheet, for chaining.
1157
1792
  */
1158
- async setRowHeightsForced(e, t, o) {
1793
+ async setRowHeightsForced(e, t, n) {
1159
1794
  const s = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = [
1160
1795
  {
1161
1796
  startRow: e,
@@ -1164,11 +1799,11 @@ let g = class extends b {
1164
1799
  endColumn: this._worksheet.getColumnCount() - 1
1165
1800
  }
1166
1801
  ];
1167
- return await this._commandService.executeCommand(ee.id, {
1802
+ return await this._commandService.executeCommand(de.id, {
1168
1803
  unitId: s,
1169
1804
  subUnitId: r,
1170
1805
  ranges: i,
1171
- value: o
1806
+ value: n
1172
1807
  }), this;
1173
1808
  }
1174
1809
  // #endregion
@@ -1178,17 +1813,17 @@ let g = class extends b {
1178
1813
  * @returns This sheet, for chaining.
1179
1814
  */
1180
1815
  async setRowCustom(e) {
1181
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = {};
1816
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = {};
1182
1817
  for (const [i, a] of Object.entries(e))
1183
1818
  s[Number(i)] = {
1184
1819
  custom: a
1185
1820
  };
1186
1821
  const r = {
1187
1822
  unitId: t,
1188
- subUnitId: o,
1823
+ subUnitId: n,
1189
1824
  rowData: s
1190
1825
  };
1191
- return await this._commandService.executeCommand(K.id, r), this;
1826
+ return await this._commandService.executeCommand(ie.id, r), this;
1192
1827
  }
1193
1828
  // #region Column
1194
1829
  /**
@@ -1223,9 +1858,9 @@ let g = class extends b {
1223
1858
  * @returns This sheet, for chaining.
1224
1859
  */
1225
1860
  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,
1861
+ 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);
1862
+ return await this._commandService.executeCommand(me.id, {
1863
+ unitId: n,
1229
1864
  subUnitId: s,
1230
1865
  direction: r,
1231
1866
  range: {
@@ -1244,9 +1879,9 @@ let g = class extends b {
1244
1879
  * @returns This sheet, for chaining.
1245
1880
  */
1246
1881
  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,
1882
+ 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);
1883
+ return await this._commandService.executeCommand(me.id, {
1884
+ unitId: n,
1250
1885
  subUnitId: s,
1251
1886
  direction: r,
1252
1887
  range: {
@@ -1273,14 +1908,14 @@ let g = class extends b {
1273
1908
  * @returns This sheet, for chaining.
1274
1909
  */
1275
1910
  async deleteColumns(e, t) {
1276
- const o = {
1911
+ const n = {
1277
1912
  startRow: 0,
1278
1913
  endRow: this._worksheet.getRowCount() - 1,
1279
1914
  startColumn: e,
1280
1915
  endColumn: e + t - 1
1281
1916
  };
1282
- return await this._commandService.executeCommand($e.id, {
1283
- range: o
1917
+ return await this._commandService.executeCommand(ct.id, {
1918
+ range: n
1284
1919
  }), this;
1285
1920
  }
1286
1921
  /**
@@ -1290,14 +1925,14 @@ let g = class extends b {
1290
1925
  * @returns This sheet, for chaining.
1291
1926
  */
1292
1927
  async moveColumns(e, t) {
1293
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = A(e.getRange(), this._worksheet), i = r, a = {
1928
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = $(e.getRange(), this._worksheet), i = r, a = {
1294
1929
  startRow: 0,
1295
1930
  endRow: this._worksheet.getRowCount() - 1,
1296
1931
  startColumn: t,
1297
1932
  endColumn: t
1298
1933
  };
1299
- return await this._commandService.executeCommand(Ge.id, {
1300
- unitId: o,
1934
+ return await this._commandService.executeCommand(dt.id, {
1935
+ unitId: n,
1301
1936
  subUnitId: s,
1302
1937
  range: r,
1303
1938
  fromRange: i,
@@ -1310,10 +1945,10 @@ let g = class extends b {
1310
1945
  * @returns This sheet, for chaining.
1311
1946
  */
1312
1947
  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, {
1948
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = $(e.getRange(), this._worksheet);
1949
+ return await this._commandService.executeCommand(ue.id, {
1315
1950
  unitId: t,
1316
- subUnitId: o,
1951
+ subUnitId: n,
1317
1952
  ranges: [s]
1318
1953
  }), this;
1319
1954
  }
@@ -1324,15 +1959,15 @@ let g = class extends b {
1324
1959
  * @returns This sheet, for chaining.
1325
1960
  */
1326
1961
  async hideColumns(e, t = 1) {
1327
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1962
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1328
1963
  startRow: 0,
1329
1964
  endRow: this._worksheet.getRowCount() - 1,
1330
1965
  startColumn: e,
1331
1966
  endColumn: e + t - 1,
1332
- rangeType: l.COLUMN
1967
+ rangeType: g.COLUMN
1333
1968
  };
1334
- return await this._commandService.executeCommand(ne.id, {
1335
- unitId: o,
1969
+ return await this._commandService.executeCommand(ue.id, {
1970
+ unitId: n,
1336
1971
  subUnitId: s,
1337
1972
  ranges: [r]
1338
1973
  }), this;
@@ -1343,10 +1978,10 @@ let g = class extends b {
1343
1978
  * @returns This sheet, for chaining.
1344
1979
  */
1345
1980
  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, {
1981
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = $(e.getRange(), this._worksheet);
1982
+ return await this._commandService.executeCommand(le.id, {
1348
1983
  unitId: t,
1349
- subUnitId: o,
1984
+ subUnitId: n,
1350
1985
  ranges: [s]
1351
1986
  }), this;
1352
1987
  }
@@ -1357,15 +1992,15 @@ let g = class extends b {
1357
1992
  * @returns This sheet, for chaining.
1358
1993
  */
1359
1994
  async showColumns(e, t = 1) {
1360
- const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1995
+ const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1361
1996
  startRow: 0,
1362
1997
  endRow: this._worksheet.getRowCount() - 1,
1363
1998
  startColumn: e,
1364
1999
  endColumn: e + t - 1,
1365
- rangeType: l.COLUMN
2000
+ rangeType: g.COLUMN
1366
2001
  };
1367
- return await this._commandService.executeCommand(oe.id, {
1368
- unitId: o,
2002
+ return await this._commandService.executeCommand(le.id, {
2003
+ unitId: n,
1369
2004
  subUnitId: s,
1370
2005
  ranges: [r]
1371
2006
  }), this;
@@ -1386,7 +2021,7 @@ let g = class extends b {
1386
2021
  * @param width The width in pixels to set it to.
1387
2022
  * @returns This sheet, for chaining.
1388
2023
  */
1389
- async setColumnWidths(e, t, o) {
2024
+ async setColumnWidths(e, t, n) {
1390
2025
  const s = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = [
1391
2026
  {
1392
2027
  startColumn: e,
@@ -1395,11 +2030,11 @@ let g = class extends b {
1395
2030
  endRow: this._worksheet.getRowCount() - 1
1396
2031
  }
1397
2032
  ];
1398
- return await this._commandService.executeCommand(qe.id, {
2033
+ return await this._commandService.executeCommand(mt.id, {
1399
2034
  unitId: s,
1400
2035
  subUnitId: r,
1401
2036
  ranges: i,
1402
- value: o
2037
+ value: n
1403
2038
  }), this;
1404
2039
  }
1405
2040
  // #endregion
@@ -1409,17 +2044,17 @@ let g = class extends b {
1409
2044
  * @returns This sheet, for chaining.
1410
2045
  */
1411
2046
  async setColumnCustom(e) {
1412
- const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = {};
2047
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = {};
1413
2048
  for (const [i, a] of Object.entries(e))
1414
2049
  s[Number(i)] = {
1415
2050
  custom: a
1416
2051
  };
1417
2052
  const r = {
1418
2053
  unitId: t,
1419
- subUnitId: o,
2054
+ subUnitId: n,
1420
2055
  columnData: s
1421
2056
  };
1422
- return await this._commandService.executeCommand(J.id, r), this;
2057
+ return await this._commandService.executeCommand(re.id, r), this;
1423
2058
  }
1424
2059
  // #region merge cells
1425
2060
  /**
@@ -1453,18 +2088,21 @@ let g = class extends b {
1453
2088
  * @param range The range to set as the active selection.
1454
2089
  */
1455
2090
  setActiveRange(e) {
1456
- const { unitId: t, sheetId: o } = e.getRange();
1457
- if (t !== this._workbook.getUnitId() || o !== this._worksheet.getSheetId())
2091
+ const { unitId: t, sheetId: n } = e.getRange();
2092
+ if (t !== this._workbook.getUnitId() || n !== this._worksheet.getSheetId())
1458
2093
  throw new Error("Specified range must be part of the sheet.");
1459
2094
  this._fWorkbook.setActiveRange(e);
1460
2095
  }
1461
2096
  /**
1462
2097
  * Sets the frozen state of the current sheet.
1463
- * @param freeze - The freeze object containing the parameters for freezing the sheet.
2098
+ * @param freeze - the scrolling viewport start range and count of freezed rows and columns.
2099
+ * 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 }
2100
+ *
2101
+ * @deprecated use `setFrozenRows` and `setFrozenColumns` instead.
1464
2102
  * @returns True if the command was successful, false otherwise.
1465
2103
  */
1466
2104
  setFreeze(e) {
1467
- return this._commandService.syncExecuteCommand(Ye.id, {
2105
+ return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"), this._commandService.syncExecuteCommand(B.id, {
1468
2106
  ...e,
1469
2107
  unitId: this._workbook.getUnitId(),
1470
2108
  subUnitId: this.getSheetId()
@@ -1475,7 +2113,7 @@ let g = class extends b {
1475
2113
  * @returns True if the command was successful, false otherwise.
1476
2114
  */
1477
2115
  cancelFreeze() {
1478
- return this._commandService.syncExecuteCommand(Je.id, {
2116
+ return this._commandService.syncExecuteCommand(ut.id, {
1479
2117
  unitId: this._workbook.getUnitId(),
1480
2118
  subUnitId: this.getSheetId()
1481
2119
  });
@@ -1483,35 +2121,53 @@ let g = class extends b {
1483
2121
  /**
1484
2122
  * Get the freeze state of the current sheet.
1485
2123
  * @returns The freeze state of the current sheet.
2124
+ *
2125
+ * @deprecated use `getRowFreezeStatus` and `getColumnFreezeStatus` instead.
1486
2126
  */
1487
2127
  getFreeze() {
1488
2128
  return this._worksheet.getFreeze();
1489
2129
  }
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) {
2130
+ setFrozenColumns(...e) {
1496
2131
  const t = this.getFreeze();
1497
- this.setFreeze({
1498
- ...t,
1499
- startColumn: e > 0 ? e : -1,
1500
- xSplit: e
1501
- });
2132
+ if (arguments.length === 1) {
2133
+ const n = e[0];
2134
+ this.setFreeze({
2135
+ ...t,
2136
+ startColumn: n > 0 ? n : -1,
2137
+ xSplit: n
2138
+ });
2139
+ } else if (arguments.length === 2) {
2140
+ let [n = 0, s = 0] = e;
2141
+ n > s && ([n, s] = [s, n]), this._commandService.syncExecuteCommand(B.id, {
2142
+ startColumn: s + 1,
2143
+ xSplit: s - n + 1,
2144
+ startRow: t.startRow,
2145
+ ySplit: t.ySplit,
2146
+ unitId: this._workbook.getUnitId(),
2147
+ subUnitId: this.getSheetId()
2148
+ });
2149
+ }
1502
2150
  }
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) {
2151
+ setFrozenRows(...e) {
1509
2152
  const t = this.getFreeze();
1510
- this.setFreeze({
1511
- ...t,
1512
- startRow: e > 0 ? e : -1,
1513
- ySplit: e
1514
- });
2153
+ if (arguments.length === 1) {
2154
+ const n = e[0];
2155
+ this.setFreeze({
2156
+ ...t,
2157
+ startRow: n > 0 ? n : -1,
2158
+ ySplit: n
2159
+ });
2160
+ } else if (arguments.length === 2) {
2161
+ let [n = 0, s = 0] = e;
2162
+ n > s && ([n, s] = [s, n]), this._commandService.syncExecuteCommand, this._commandService.syncExecuteCommand(B.id, {
2163
+ startRow: s + 1,
2164
+ ySplit: s - n + 1,
2165
+ startColumn: t.startColumn,
2166
+ xSplit: t.xSplit,
2167
+ unitId: this._workbook.getUnitId(),
2168
+ subUnitId: this.getSheetId()
2169
+ });
2170
+ }
1515
2171
  }
1516
2172
  /**
1517
2173
  * Get the number of frozen columns.
@@ -1531,33 +2187,141 @@ let g = class extends b {
1531
2187
  const e = this.getFreeze();
1532
2188
  return e.startRow === -1 ? 0 : e.startRow;
1533
2189
  }
2190
+ /**
2191
+ * Get freezed rows.
2192
+ */
2193
+ getFrozenRowRange() {
2194
+ const e = this._worksheet.getFreeze();
2195
+ return {
2196
+ startRow: e.startRow - e.ySplit,
2197
+ endRow: e.startRow - 1
2198
+ };
2199
+ }
2200
+ /**
2201
+ * Get freezed columns
2202
+ */
2203
+ getFrozenColumnRange() {
2204
+ const e = this._worksheet.getFreeze();
2205
+ return {
2206
+ startColumn: e.startColumn - e.xSplit,
2207
+ endColumn: e.startColumn - 1
2208
+ };
2209
+ }
1534
2210
  /**
1535
2211
  * Returns true if the sheet's gridlines are hidden; otherwise returns false. Gridlines are visible by default.
2212
+ * @returns {boolean} True if the sheet's gridlines are hidden; otherwise false.
2213
+ * @example
2214
+ * ```ts
2215
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2216
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2217
+ * // check if the gridlines are hidden
2218
+ * if (fWorkSheet.hasHiddenGridLines()) {
2219
+ * console.log('Gridlines are hidden');
2220
+ * }
2221
+ * ```
1536
2222
  */
1537
2223
  hasHiddenGridLines() {
1538
- return this._worksheet.getConfig().showGridlines === m.FALSE;
2224
+ return this._worksheet.getConfig().showGridlines === u.FALSE;
1539
2225
  }
1540
2226
  /**
1541
2227
  * Hides or reveals the sheet gridlines.
1542
2228
  * @param {boolean} hidden If `true`, hide gridlines in this sheet; otherwise show the gridlines.
2229
+ * @example
2230
+ * ``` ts
2231
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2232
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2233
+ * // hide the gridlines
2234
+ * fWorkSheet.setHiddenGridlines(true);
2235
+ * ```
1543
2236
  */
1544
2237
  setHiddenGridlines(e) {
1545
- return this._commandService.executeCommand(Ke.id, {
2238
+ return this._commandService.executeCommand(lt.id, {
2239
+ unitId: this._workbook.getUnitId(),
2240
+ subUnitId: this._worksheet.getSheetId(),
2241
+ showGridlines: e ? u.FALSE : u.TRUE
2242
+ });
2243
+ }
2244
+ /**
2245
+ * Set the color of the gridlines in the sheet.
2246
+ * @param {string|undefined} color The color to set for the gridlines.Undefined or null to reset to the default color.
2247
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2248
+ * @example
2249
+ * ```ts
2250
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2251
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2252
+ * // set the gridlines color to red
2253
+ * fWorkSheet.setGridLinesColor('#ff0000');
2254
+ * ```
2255
+ */
2256
+ setGridLinesColor(e) {
2257
+ return this._commandService.executeCommand(gt.id, {
1546
2258
  unitId: this._workbook.getUnitId(),
1547
2259
  subUnitId: this._worksheet.getSheetId(),
1548
- showGridlines: e ? m.FALSE : m.TRUE
2260
+ color: e
1549
2261
  });
1550
2262
  }
2263
+ /**
2264
+ * Get the color of the gridlines in the sheet.
2265
+ * @returns {string | undefined} The color of the gridlines in the sheet or undefined. The default color is 'rgb(214, 216, 219)'.
2266
+ */
2267
+ getGridLinesColor() {
2268
+ return this._worksheet.getGridlinesColor();
2269
+ }
2270
+ /**
2271
+ * Sets the sheet tab color.
2272
+ * @param {string|null|undefined} color A color code in CSS notation (like '#ffffff' or 'white'), or null to reset the tab color.
2273
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2274
+ * @example
2275
+ * ```ts
2276
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2277
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2278
+ * // set the tab color to red
2279
+ * fWorkSheet.setTabColor('#ff0000');
2280
+ * ```
2281
+ */
2282
+ setTabColor(e) {
2283
+ return this._commandService.executeCommand(_t.id, {
2284
+ unitId: this._workbook.getUnitId(),
2285
+ subUnitId: this._worksheet.getSheetId(),
2286
+ color: e
2287
+ });
2288
+ }
2289
+ /**
2290
+ * Get the tab color of the sheet.
2291
+ * @returns {string} The tab color of the sheet or undefined.
2292
+ * The default color is css style property 'unset'.
2293
+ * @example
2294
+ * ```ts
2295
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2296
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2297
+ * // get the tab color of the sheet
2298
+ * console.log(fWorkSheet.getTabColor());
2299
+ * ```
2300
+ */
2301
+ getTabColor() {
2302
+ return this._worksheet.getTabColor();
2303
+ }
1551
2304
  /**
1552
2305
  * Subscribe to the cell data change event.
1553
2306
  * @param callback - The callback function to be executed when the cell data changes.
1554
2307
  * @returns - A disposable object to unsubscribe from the event.
2308
+ * @example
2309
+ * ```ts
2310
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2311
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2312
+ * // subscribe to the cell data change event
2313
+ * const disposable = fWorkSheet.onCellDataChange((cellValue) => {
2314
+ * console.log(cellValue.toArray());
2315
+ * });
2316
+ * // unsubscribe from the event
2317
+ * disposable.dispose();
2318
+ * ```
1555
2319
  */
1556
2320
  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));
2321
+ return this._injector.get(l).onCommandExecuted((n) => {
2322
+ if (n.id === ge.id) {
2323
+ const s = n.params;
2324
+ s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new j(s.cellValue));
1561
2325
  }
1562
2326
  });
1563
2327
  }
@@ -1565,47 +2329,384 @@ let g = class extends b {
1565
2329
  * Subscribe to the cell data change event.
1566
2330
  * @param callback - The callback function to be executed before the cell data changes.
1567
2331
  * @returns - A disposable object to unsubscribe from the event.
2332
+ * @example
2333
+ * ```ts
2334
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2335
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2336
+ * // subscribe to the cell data change event
2337
+ * const disposable = fWorkSheet.onBeforeCellDataChange((cellValue) => {
2338
+ * console.log(cellValue.toArray());
2339
+ * });
2340
+ * // unsubscribe from the event
2341
+ * disposable.dispose();
2342
+ * ```
1568
2343
  */
1569
2344
  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));
2345
+ return this._injector.get(l).beforeCommandExecuted((n) => {
2346
+ if (n.id === ge.id) {
2347
+ const s = n.params;
2348
+ s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new j(s.cellValue));
1574
2349
  }
1575
2350
  });
1576
2351
  }
2352
+ /**
2353
+ * 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.
2354
+ * @example
2355
+ * ```ts
2356
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2357
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2358
+ * // hide the active sheet
2359
+ * fWorkSheet.hideSheet();
2360
+ * ``
2361
+ */
2362
+ hideSheet() {
2363
+ const e = this._injector.get(l);
2364
+ if (this._workbook.getSheets().filter((r) => r.isSheetHidden() !== u.TRUE).length <= 1)
2365
+ throw new Error("Cannot hide the only visible sheet");
2366
+ e.executeCommand(wt.id, {
2367
+ unitId: this._workbook.getUnitId(),
2368
+ subUnitId: this._worksheet.getSheetId()
2369
+ });
2370
+ }
2371
+ /**
2372
+ * Shows this sheet. Has no effect if the sheet is already visible.
2373
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2374
+ * @example
2375
+ * ```ts
2376
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2377
+ * const fWorkSheets = fWorkbook.getSheets();
2378
+ * // show the last sheet
2379
+ * fWorkSheets[fWorkSheets.length - 1].showSheet();
2380
+ * ```
2381
+ */
2382
+ showSheet() {
2383
+ return this._injector.get(l).executeCommand(kt.id, {
2384
+ unitId: this._workbook.getUnitId(),
2385
+ subUnitId: this._worksheet.getSheetId()
2386
+ });
2387
+ }
2388
+ /**
2389
+ * Returns true if the sheet is currently hidden.
2390
+ * @returns {boolean} True if the sheet is hidden; otherwise, false.
2391
+ */
2392
+ isSheetHidden() {
2393
+ return this._worksheet.isSheetHidden() === u.TRUE;
2394
+ }
2395
+ /**
2396
+ * Sets the sheet name.
2397
+ * @param {string} name The new name for the sheet.
2398
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2399
+ * @example
2400
+ * ```ts
2401
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2402
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2403
+ * // set the sheet name to 'Sheet1'
2404
+ * fWorkSheet.setName('Sheet1');
2405
+ * ```
2406
+ */
2407
+ setName(e) {
2408
+ return this._commandService.executeCommand(St.id, {
2409
+ unitId: this._workbook.getUnitId(),
2410
+ subUnitId: this._worksheet.getSheetId(),
2411
+ name: e
2412
+ });
2413
+ }
2414
+ /**
2415
+ * Activates this sheet. Does not alter the sheet itself, only the parent's notion of the active sheet.
2416
+ * @returns Current sheet, for chaining.
2417
+ */
2418
+ activate() {
2419
+ return this._fWorkbook.setActiveSheet(this), this;
2420
+ }
2421
+ /**
2422
+ * Gets the position of the sheet in its parent spreadsheet. Starts at 0.
2423
+ * @returns {number} The position of the sheet in its parent spreadsheet.
2424
+ * @example
2425
+ * ```ts
2426
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2427
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2428
+ * // get the position of the active sheet
2429
+ * const position = fWorkSheet.getIndex();
2430
+ * console.log(position); // 0
2431
+ * ```
2432
+ */
2433
+ getIndex() {
2434
+ return this._workbook.getSheetIndex(this._worksheet);
2435
+ }
2436
+ /**
2437
+ * Clears the sheet of content and formatting information.Or Optionally clears only the contents or only the formatting.
2438
+ * @param {IFacadeClearOptions} [options] Options for clearing the sheet. If not provided, the contents and formatting are cleared both.
2439
+ * @param {boolean} [options.contentsOnly] If true, the contents of the sheet are cleared. If false, the contents and formatting are cleared. Default is false.
2440
+ * @param {boolean} [options.formatOnly] If true, the formatting of the sheet is cleared. If false, the contents and formatting are cleared. Default is false.
2441
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2442
+ * @example
2443
+ * ```ts
2444
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2445
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2446
+ * // clear the sheet of content and formatting information
2447
+ * fWorkSheet.clear();
2448
+ * // clear the sheet of content only
2449
+ * fWorkSheet.clear({ contentsOnly: true });
2450
+ * ```
2451
+ */
2452
+ clear(e) {
2453
+ if (e && e.contentsOnly && !e.formatOnly)
2454
+ return this.clearContents();
2455
+ if (e && e.formatOnly && !e.contentsOnly)
2456
+ return this.clearFormats();
2457
+ const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = this._injector.get(l), r = {
2458
+ startRow: 0,
2459
+ endRow: this._worksheet.getRowCount() - 1,
2460
+ startColumn: 0,
2461
+ endColumn: this._worksheet.getColumnCount() - 1
2462
+ };
2463
+ return s.executeCommand(Ct.id, {
2464
+ unitId: t,
2465
+ subUnitId: n,
2466
+ ranges: [r],
2467
+ options: e
2468
+ });
2469
+ }
2470
+ /**
2471
+ * Clears the sheet of contents, while preserving formatting information.
2472
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2473
+ * @example
2474
+ * ```ts
2475
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2476
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2477
+ * // clear the sheet of content only
2478
+ * fWorkSheet.clearContents();
2479
+ * ```
2480
+ */
2481
+ clearContents() {
2482
+ const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId(), n = this._injector.get(l), s = {
2483
+ startRow: 0,
2484
+ endRow: this._worksheet.getRowCount() - 1,
2485
+ startColumn: 0,
2486
+ endColumn: this._worksheet.getColumnCount() - 1
2487
+ };
2488
+ return n.executeCommand(It.id, {
2489
+ unitId: e,
2490
+ subUnitId: t,
2491
+ ranges: [s]
2492
+ });
2493
+ }
2494
+ /**
2495
+ * Clears the sheet of formatting, while preserving contents.
2496
+ * @returns {Promise<boolean>} True if the command was successful, false otherwise.
2497
+ * @example
2498
+ * ```ts
2499
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2500
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2501
+ * // clear the sheet of formatting only
2502
+ * fWorkSheet.clearFormats();
2503
+ * ```
2504
+ */
2505
+ clearFormats() {
2506
+ const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId(), n = this._injector.get(l), s = {
2507
+ startRow: 0,
2508
+ endRow: this._worksheet.getRowCount() - 1,
2509
+ startColumn: 0,
2510
+ endColumn: this._worksheet.getColumnCount() - 1
2511
+ };
2512
+ return n.executeCommand(ft.id, {
2513
+ unitId: e,
2514
+ subUnitId: t,
2515
+ ranges: [s]
2516
+ });
2517
+ }
2518
+ /**
2519
+ * Returns a Range corresponding to the dimensions in which data is present.
2520
+ * This is functionally equivalent to creating a Range bounded by A1 and (Sheet.getLastColumns(), Sheet.getLastRows()).
2521
+ * @returns {FRange} The range of the data in the sheet.
2522
+ * @example
2523
+ * ```ts
2524
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2525
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2526
+ * // the sheet is a empty sheet
2527
+ * const cellRange = fWorkSheet.getRange(200, 10, 1, 1);
2528
+ * cellRange.setValue('Hello World');
2529
+ * console.log(fWorkSheet.getDataRange().getA1Notation()); // A1:J200
2530
+ * ```
2531
+ */
2532
+ getDataRange() {
2533
+ const e = this.getLastRows(), t = this.getLastColumns();
2534
+ return this.getRange(0, 0, e + 1, t + 1);
2535
+ }
2536
+ /**
2537
+ * Returns the position of the last column that has content.
2538
+ * @returns {number} the last column of the sheet that contains content.
2539
+ * @example
2540
+ * ```ts
2541
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2542
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2543
+ * const fRange = fWorkSheet.getRange(100, 20, 1, 1);
2544
+ * console.log(fWorkSheet.getLastColumns()); // 20
2545
+ * ```
2546
+ */
2547
+ getLastColumns() {
2548
+ return this._worksheet.getLastColumnWithContent();
2549
+ }
2550
+ /**
2551
+ * Returns the position of the last column that has content. Same as getLastColumns.
2552
+ * @returns {number} the last column of the sheet that contains content.
2553
+ * @example
2554
+ * ```ts
2555
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2556
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2557
+ * const fRange = fWorkSheet.getRange(100, 20, 1, 1);
2558
+ * console.log(fWorkSheet.getLastColumn());
2559
+ * ```
2560
+ */
2561
+ getLastColumn() {
2562
+ return this._worksheet.getLastColumnWithContent();
2563
+ }
2564
+ /**
2565
+ * Returns the position of the last row that has content.
2566
+ * @returns {number} the last row of the sheet that contains content.
2567
+ * @example
2568
+ * ```ts
2569
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2570
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2571
+ * const fRange = fWorkSheet.getRange(100,1,1,1);
2572
+ * fRange.setValue('Hello World');
2573
+ * console.log(fWorkSheet.getLastRows()); // 100
2574
+ */
2575
+ getLastRows() {
2576
+ return this._worksheet.getLastRowWithContent();
2577
+ }
2578
+ /**
2579
+ * Returns the position of the last row that has content, same as getLastRows().
2580
+ * @returns {number} the last row of the sheet that contains content.
2581
+ * @example
2582
+ * ```ts
2583
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2584
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2585
+ * const fRange = fWorkSheet.getRange(100,1,1,1);
2586
+ * fRange.setValue('Hello World');
2587
+ * console.log(fWorkSheet.getLastRow());
2588
+ */
2589
+ getLastRow() {
2590
+ return this._worksheet.getLastRowWithContent();
2591
+ }
2592
+ /**
2593
+ * Judge whether provided FWorksheet is equal to current.
2594
+ * @param {FWorksheet} other the FWorksheet to compare with.
2595
+ * @returns {boolean} true if the FWorksheet is equal to the current FWorksheet, false otherwise.
2596
+ * @example
2597
+ * ```ts
2598
+ * const fWorkbook = univerAPI.getActiveWorkbook();
2599
+ * const fWorkSheet = fWorkbook.getActiveSheet();
2600
+ * const fWorkSheet2 = fWorkbook.getSheetByName('Sheet1');
2601
+ * console.log(fWorkSheet.equals(fWorkSheet2)); // true, if the active sheet is 'Sheet1'
2602
+ * ```
2603
+ */
2604
+ equalTo(e) {
2605
+ return e instanceof _ ? this._worksheet.getSheetId() === e.getSheetId() && this._workbook.getUnitId() === e.getWorkbook().getUnitId() : !1;
2606
+ }
2607
+ /*
2608
+ * Insert a defined name for worksheet.
2609
+ * @param {string} name The name of the defined name to insert
2610
+ * @param {string} formulaOrRefString The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
2611
+ * @example
2612
+ * ```ts
2613
+ * // The code below inserts a defined name
2614
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2615
+ * const sheet1 = activeSpreadsheet.getSheetByName('Sheet1');
2616
+ * sheet1.insertDefinedName('MyDefinedName', 'Sheet1!A1');
2617
+ * ```
2618
+ */
2619
+ insertDefinedName(e, t) {
2620
+ const s = this._injector.createInstance(A).setName(e).setRef(t).build();
2621
+ s.localSheetId = this.getSheetId(), this._fWorkbook.insertDefinedNameBuilder(s);
2622
+ }
2623
+ /**
2624
+ * Get all the defined names in the worksheet.
2625
+ * @returns {FDefinedName[]} All the defined names in the worksheet
2626
+ * @example
2627
+ * ```ts
2628
+ * // The code below gets all the defined names in the worksheet
2629
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2630
+ * const sheet1 = activeSpreadsheet.getSheetByName('Sheet1');
2631
+ * const definedNames = sheet1.getDefinedNames();
2632
+ * ```
2633
+ */
2634
+ getDefinedNames() {
2635
+ return this._fWorkbook.getDefinedNames().filter((t) => t.getLocalSheetId() === this.getSheetId());
2636
+ }
1577
2637
  };
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) {
2638
+ _ = Gt([
2639
+ M(3, m(v)),
2640
+ M(4, m(Ne)),
2641
+ M(5, m(Ce)),
2642
+ M(6, l)
2643
+ ], _);
2644
+ var qt = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, Yt = (o, e, t, n) => {
2645
+ for (var s = n > 1 ? void 0 : n ? Kt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
2646
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
2647
+ return n && s && qt(e, t, s), s;
2648
+ }, k = (o, e) => (t, n) => e(t, n, o);
2649
+ let I = class extends p {
2650
+ constructor(e, t, n, s, r, i, a, h, c, d) {
1590
2651
  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();
2652
+ P(this, "id");
2653
+ 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
2654
  }
2655
+ /**
2656
+ * Get the id of the workbook.
2657
+ * @returns {string} The id of the workbook.
2658
+ * @example
2659
+ * ```ts
2660
+ * // The code below gets the id of the workbook
2661
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2662
+ * const id = activeSpreadsheet.getId();
2663
+ * ```
2664
+ */
1594
2665
  getId() {
1595
2666
  return this.id;
1596
2667
  }
2668
+ /**
2669
+ * Get the name of the workbook.
2670
+ * @returns {string} The name of the workbook.
2671
+ * @example
2672
+ * ```ts
2673
+ * // The code below gets the name of the workbook
2674
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2675
+ * const name = activeSpreadsheet.getName();
2676
+ * ```
2677
+ */
1597
2678
  getName() {
1598
- return this._workbook.getName();
2679
+ return this._workbook.name;
2680
+ }
2681
+ /**
2682
+ * Set the name of the workbook.
2683
+ * @param {string} name The new name of the workbook.
2684
+ * @example
2685
+ * ```ts
2686
+ * // The code below sets the name of the workbook
2687
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2688
+ * activeSpreadsheet.setName('MyWorkbook');
2689
+ * ```
2690
+ */
2691
+ setName(e) {
2692
+ this._workbook.setName(e);
1599
2693
  }
1600
2694
  /**
1601
2695
  * save workbook snapshot data, including conditional formatting, data validation, and other plugin data.
2696
+ * @return Workbook snapshot data
2697
+ * @example
2698
+ * ```ts
2699
+ * // The code below saves the workbook snapshot data
2700
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2701
+ * const snapshot = activeSpreadsheet.save();
2702
+ * ```
1602
2703
  */
1603
2704
  save() {
1604
2705
  return this._resourceLoaderService.saveUnit(this._workbook.getUnitId());
1605
2706
  }
1606
2707
  /**
1607
2708
  * @deprecated use 'save' instead.
1608
- * @return {*} {IWorkbookData}
2709
+ * @return {*} {IWorkbookData} Workbook snapshot data
1609
2710
  * @memberof FWorkbook
1610
2711
  */
1611
2712
  getSnapshot() {
@@ -1614,17 +2715,29 @@ let U = class extends b {
1614
2715
  /**
1615
2716
  * Get the active sheet of the workbook.
1616
2717
  * @returns The active sheet of the workbook
2718
+ * @example
2719
+ * ```ts
2720
+ * // The code below gets the active sheet of the workbook
2721
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2722
+ * const activeSheet = activeSpreadsheet.getActiveSheet();
2723
+ * ```
1617
2724
  */
1618
2725
  getActiveSheet() {
1619
2726
  const e = this._workbook.getActiveSheet();
1620
- return this._injector.createInstance(g, this, this._workbook, e);
2727
+ return this._injector.createInstance(_, this, this._workbook, e);
1621
2728
  }
1622
2729
  /**
1623
2730
  * Gets all the worksheets in this workbook
1624
2731
  * @returns An array of all the worksheets in the workbook
2732
+ * @example
2733
+ * ```ts
2734
+ * // The code below gets all the worksheets in the workbook
2735
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2736
+ * const sheets = activeSpreadsheet.getSheets();
2737
+ * ```
1625
2738
  */
1626
2739
  getSheets() {
1627
- return this._workbook.getSheets().map((e) => this._injector.createInstance(g, this, this._workbook, e));
2740
+ return this._workbook.getSheets().map((e) => this._injector.createInstance(_, this, this._workbook, e));
1628
2741
  }
1629
2742
  /**
1630
2743
  * Create a new worksheet and returns a handle to it.
@@ -1632,47 +2745,72 @@ let U = class extends b {
1632
2745
  * @param rows How may rows would the new sheet have
1633
2746
  * @param column How many columns would the new sheet have
1634
2747
  * @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, {
2748
+ * @example
2749
+ * ```ts
2750
+ * // The code below creates a new sheet
2751
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2752
+ * const newSheet = activeSpreadsheet.create('MyNewSheet', 10, 10);
2753
+ * ```
2754
+ */
2755
+ create(e, t, n) {
2756
+ const s = Fe({});
2757
+ s.rowCount = t, s.columnCount = n, s.name = e, s.id = e.toLowerCase().replace(/ /g, "-"), this._commandService.syncExecuteCommand(z.id, {
1639
2758
  unitId: this.id,
1640
2759
  index: this._workbook.getSheets().length,
1641
2760
  sheet: s
1642
- }), this._commandService.syncExecuteCommand(F.id, {
2761
+ }), this._commandService.syncExecuteCommand(V.id, {
1643
2762
  unitId: this.id,
1644
2763
  subUnitId: this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId()
1645
2764
  });
1646
2765
  const r = this._workbook.getActiveSheet();
1647
2766
  if (!r)
1648
2767
  throw new Error("No active sheet found");
1649
- return this._injector.createInstance(g, this, this._workbook, r);
2768
+ return this._injector.createInstance(_, this, this._workbook, r);
1650
2769
  }
1651
2770
  /**
1652
2771
  * Get a worksheet by sheet id.
1653
2772
  * @param sheetId The id of the sheet to get.
1654
2773
  * @return The worksheet with given sheet id
2774
+ * @example
2775
+ * ```ts
2776
+ * // The code below gets a worksheet by sheet id
2777
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2778
+ * const sheet = activeSpreadsheet.getSheetBySheetId('sheetId');
2779
+ * ```
1655
2780
  */
1656
2781
  getSheetBySheetId(e) {
1657
2782
  const t = this._workbook.getSheetBySheetId(e);
1658
- return t ? this._injector.createInstance(g, this, this._workbook, t) : null;
2783
+ return t ? this._injector.createInstance(_, this, this._workbook, t) : null;
1659
2784
  }
1660
2785
  /**
1661
2786
  * Get a worksheet by sheet name.
1662
2787
  * @param name The name of the sheet to get.
1663
2788
  * @returns The worksheet with given sheet name
2789
+ * @example
2790
+ * ```ts
2791
+ * // The code below gets a worksheet by sheet name
2792
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2793
+ * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
2794
+ * ```
1664
2795
  */
1665
2796
  getSheetByName(e) {
1666
2797
  const t = this._workbook.getSheetBySheetName(e);
1667
- return t ? this._injector.createInstance(g, this, this._workbook, t) : null;
2798
+ return t ? this._injector.createInstance(_, this, this._workbook, t) : null;
1668
2799
  }
1669
2800
  /**
1670
2801
  * Sets the given worksheet to be the active worksheet in the workbook.
1671
2802
  * @param sheet The worksheet to set as the active worksheet.
1672
2803
  * @returns The active worksheet
2804
+ * @example
2805
+ * ```ts
2806
+ * // The code below sets the given worksheet to be the active worksheet
2807
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2808
+ * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
2809
+ * activeSpreadsheet.setActiveSheet(sheet);
2810
+ * ```
1673
2811
  */
1674
2812
  setActiveSheet(e) {
1675
- return this._commandService.syncExecuteCommand(F.id, {
2813
+ return this._commandService.syncExecuteCommand(V.id, {
1676
2814
  unitId: this.id,
1677
2815
  subUnitId: e.getSheetId()
1678
2816
  }), e;
@@ -1680,64 +2818,138 @@ let U = class extends b {
1680
2818
  /**
1681
2819
  * Inserts a new worksheet into the workbook.
1682
2820
  * Using a default sheet name. The new sheet becomes the active sheet
2821
+ * @param sheetName - (optional) The name of the new sheet
1683
2822
  * @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
2823
+ * @example
2824
+ * ```ts
2825
+ * // The code below inserts a new sheet into the workbook
2826
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2827
+ * activeSpreadsheet.insertSheet();
2828
+ *
2829
+ * // The code below inserts a new sheet into the workbook, using a custom name
2830
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2831
+ * activeSpreadsheet.insertSheet('MyNewSheet');
2832
+ * ```
2833
+ */
2834
+ insertSheet(e) {
2835
+ e != null ? this._commandService.syncExecuteCommand(z.id, { sheet: { name: e } }) : this._commandService.syncExecuteCommand(z.id);
2836
+ const t = this.id, n = this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId();
2837
+ this._commandService.syncExecuteCommand(V.id, {
2838
+ unitId: t,
2839
+ subUnitId: n
1691
2840
  });
1692
- const o = this._workbook.getActiveSheet();
1693
- if (!o)
2841
+ const s = this._workbook.getActiveSheet();
2842
+ if (!s)
1694
2843
  throw new Error("No active sheet found");
1695
- return this._injector.createInstance(g, this, this._workbook, o);
2844
+ return this._injector.createInstance(_, this, this._workbook, s);
1696
2845
  }
1697
2846
  /**
1698
2847
  * Deletes the specified worksheet.
1699
2848
  * @param sheet The worksheet to delete.
2849
+ * @example
2850
+ * ```ts
2851
+ * // The code below deletes the specified worksheet
2852
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2853
+ * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
2854
+ * activeSpreadsheet.deleteSheet(sheet);
2855
+ * ```
1700
2856
  */
1701
2857
  deleteSheet(e) {
1702
- const t = this.id, o = e.getSheetId();
1703
- this._commandService.executeCommand(Qe.id, {
2858
+ const t = this.id, n = e.getSheetId();
2859
+ return this._commandService.executeCommand(vt.id, {
1704
2860
  unitId: t,
1705
- subUnitId: o
2861
+ subUnitId: n
1706
2862
  });
1707
2863
  }
1708
2864
  // #region editing
2865
+ /**
2866
+ * Undo the last action.
2867
+ * @returns A promise that resolves to true if the undo was successful, false otherwise.
2868
+ * @example
2869
+ * ```ts
2870
+ * // The code below undoes the last action
2871
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2872
+ * activeSpreadsheet.undo();
2873
+ * ```
2874
+ */
1709
2875
  undo() {
1710
- return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(Re.id);
2876
+ return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(Ae.id);
1711
2877
  }
2878
+ /**
2879
+ * Redo the last undone action.
2880
+ * @returns A promise that resolves to true if the redo was successful, false otherwise.
2881
+ * @example
2882
+ * ```ts
2883
+ * // The code below redoes the last undone action
2884
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2885
+ * activeSpreadsheet.redo();
2886
+ * ```
2887
+ */
1712
2888
  redo() {
1713
- return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(fe.id);
2889
+ return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(Te.id);
1714
2890
  }
2891
+ /**
2892
+ * Callback for command execution.
2893
+ * @callback onBeforeCommandExecuteCallback
2894
+ * @param {ICommandInfo<ISheetCommandSharedParams>} command The command that was executed.
2895
+ */
1715
2896
  /**
1716
2897
  * Register a callback that will be triggered before invoking a command targeting the Univer sheet.
1717
- * @param callback the callback.
2898
+ * @param {onBeforeCommandExecuteCallback} callback the callback.
1718
2899
  * @returns A function to dispose the listening.
2900
+ * @example
2901
+ * ```ts
2902
+ * // The code below registers a callback that will be triggered before invoking a command targeting the Univer sheet
2903
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2904
+ * activeSpreadsheet.onBeforeCommandExecute((command) => {
2905
+ * console.log('Command executed:', command);
2906
+ * });
2907
+ * ```
1719
2908
  */
1720
2909
  onBeforeCommandExecute(e) {
1721
2910
  return this._commandService.beforeCommandExecuted((t) => {
1722
- var o;
1723
- ((o = t.params) == null ? void 0 : o.unitId) === this.id && e(t);
2911
+ var n;
2912
+ ((n = t.params) == null ? void 0 : n.unitId) === this.id && e(t);
1724
2913
  });
1725
2914
  }
2915
+ /**
2916
+ * Callback for command execution.
2917
+ * @callback onCommandExecutedCallback
2918
+ * @param {ICommandInfo<ISheetCommandSharedParams>} command The command that was executed
2919
+ */
1726
2920
  /**
1727
2921
  * Register a callback that will be triggered when a command is invoked targeting the Univer sheet.
1728
- * @param callback the callback.
2922
+ * @param {onCommandExecutedCallback} callback the callback.
1729
2923
  * @returns A function to dispose the listening.
2924
+ * @example
2925
+ * ```ts
2926
+ * // The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheet
2927
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
2928
+ * activeSpreadsheet.onCommandExecuted((command) => {
2929
+ * console.log('Command executed:', command);
2930
+ * });
1730
2931
  */
1731
2932
  onCommandExecuted(e) {
1732
2933
  return this._commandService.onCommandExecuted((t) => {
1733
- var o;
1734
- ((o = t.params) == null ? void 0 : o.unitId) === this.id && e(t);
2934
+ var n;
2935
+ ((n = t.params) == null ? void 0 : n.unitId) === this.id && e(t);
1735
2936
  });
1736
2937
  }
2938
+ /**
2939
+ * Callback for selection changes.
2940
+ *
2941
+ * @callback onSelectionChangeCallback
2942
+ * @param {IRange[]} selections The new selection.
2943
+ */
2944
+ /**
2945
+ * Register a callback that will be triggered when the selection changes.
2946
+ * @param {onSelectionChangeCallback} callback The callback.
2947
+ * @returns A function to dispose the listening
2948
+ */
1737
2949
  onSelectionChange(e) {
1738
- return be(
2950
+ return Ie(
1739
2951
  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([]));
2952
+ this._univerInstanceService.getCurrentUnitForType(U.UNIVER_SHEET).getUnitId() === this.id && (t != null && t.length ? e(t.map((n) => n.range)) : e([]));
1741
2953
  })
1742
2954
  );
1743
2955
  }
@@ -1746,7 +2958,7 @@ let U = class extends b {
1746
2958
  * @param {boolean} value editable value want to set
1747
2959
  */
1748
2960
  setEditable(e) {
1749
- const t = new de(this._workbook.getUnitId());
2961
+ const t = new ye(this._workbook.getUnitId());
1750
2962
  this._permissionService.getPermissionPoint(t.id) || this._permissionService.addPermissionPoint(t), this._permissionService.updatePermissionPoint(t.id, e);
1751
2963
  }
1752
2964
  /**
@@ -1754,67 +2966,314 @@ let U = class extends b {
1754
2966
  * @param range The range to set as the active selection.
1755
2967
  */
1756
2968
  setActiveRange(e) {
1757
- const t = this.getActiveSheet(), o = e.getRange().sheetId || t.getSheetId(), s = o ? this._workbook.getSheetBySheetId(o) : this._workbook.getActiveSheet(!0);
2969
+ const t = this.getActiveSheet(), n = e.getRange().sheetId || t.getSheetId(), s = n ? this._workbook.getSheetBySheetId(n) : this._workbook.getActiveSheet(!0);
1758
2970
  if (!s)
1759
2971
  throw new Error("No active sheet found");
1760
- s.getSheetId() !== t.getSheetId() && this.setActiveSheet(this._injector.createInstance(g, this, this._workbook, s));
2972
+ s.getSheetId() !== t.getSheetId() && this.setActiveSheet(this._injector.createInstance(_, this, this._workbook, s));
1761
2973
  const r = {
1762
2974
  unitId: this.getId(),
1763
- subUnitId: o,
1764
- selections: [e].map((i) => ({ range: i.getRange(), primary: Xe(i.getRange(), s), style: null }))
2975
+ subUnitId: n,
2976
+ selections: [e].map((i) => ({ range: i.getRange(), primary: Y(i.getRange(), s), style: null }))
1765
2977
  };
1766
- this._commandService.syncExecuteCommand(Ze.id, r);
2978
+ this._commandService.syncExecuteCommand(Ue.id, r);
1767
2979
  }
1768
2980
  /**
1769
2981
  * Returns the selected range in the active sheet, or null if there is no active range.
1770
2982
  * @returns the active range
1771
2983
  */
1772
2984
  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;
2985
+ const e = this._workbook.getActiveSheet(), n = this._selectionManagerService.getCurrentSelections().find((s) => !!s.primary);
2986
+ return n ? this._injector.createInstance(S, this._workbook, e, n.range) : null;
2987
+ }
2988
+ /**
2989
+ * Deletes the currently active sheet.
2990
+ * @example
2991
+ * ```ts
2992
+ * // The code below deletes the currently active sheet and stores the new active
2993
+ * // sheet in a variable
2994
+ * const sheet = univerAPI.getActiveWorkbook().deleteActiveSheet();
2995
+ * ```
2996
+ */
2997
+ deleteActiveSheet() {
2998
+ const e = this.getActiveSheet();
2999
+ return this.deleteSheet(e);
3000
+ }
3001
+ /**
3002
+ * Duplicates the given worksheet.
3003
+ * @param {FWorksheet} sheet The worksheet to duplicate.
3004
+ * @returns {Promise<boolean>} true if the sheet was duplicated, false otherwise
3005
+ * @example
3006
+ * ```ts
3007
+ * // The code below duplicates the given worksheet
3008
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3009
+ * const activeSheet = activeSpreadsheet.getActiveSheet();
3010
+ * activeSpreadsheet.duplicateSheet(activeSheet);
3011
+ * ```
3012
+ */
3013
+ duplicateSheet(e) {
3014
+ return this._commandService.executeCommand(Rt.id, {
3015
+ unitId: e.getWorkbook().getUnitId(),
3016
+ subUnitId: e.getSheetId()
3017
+ });
3018
+ }
3019
+ /**
3020
+ * Duplicates the active sheet.
3021
+ * @returns {Promise<boolean>} true if the sheet was duplicated, false otherwise
3022
+ * @example
3023
+ * ```ts
3024
+ * // The code below duplicates the active sheet
3025
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3026
+ * activeSpreadsheet.duplicateActiveSheet();
3027
+ * ```
3028
+ */
3029
+ duplicateActiveSheet() {
3030
+ const e = this.getActiveSheet();
3031
+ return this.duplicateSheet(e);
3032
+ }
3033
+ /**
3034
+ * Get the number of sheets in the workbook.
3035
+ * @returns The number of sheets in the workbook
3036
+ * @example
3037
+ * ```ts
3038
+ * // The code below gets the number of sheets in the workbook
3039
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3040
+ * const numSheets = activeSpreadsheet.getNumSheets();
3041
+ * ```
3042
+ */
3043
+ getNumSheets() {
3044
+ return this._workbook.getSheets().length;
3045
+ }
3046
+ /**
3047
+ * Get the locale of the workbook.
3048
+ * @returns {LocaleType} The locale of the workbook
3049
+ * @example
3050
+ * ```ts
3051
+ * // The code below gets the locale of the workbook
3052
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3053
+ * const locale = activeSpreadsheet.getLocale();
3054
+ * ```
3055
+ */
3056
+ getLocale() {
3057
+ return this._localeService.getCurrentLocale();
3058
+ }
3059
+ /**
3060
+ * Set the locale of the workbook.
3061
+ * @param {LocaleType} locale The locale to set
3062
+ * @example
3063
+ * ```ts
3064
+ * // The code below sets the locale of the workbook
3065
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3066
+ * activeSpreadsheet.setLocale(LocaleType.EN_US);
3067
+ * ```
3068
+ */
3069
+ setLocale(e) {
3070
+ this._localeService.setLocale(e);
3071
+ }
3072
+ /**
3073
+ * Get the URL of the workbook.
3074
+ * @returns {string} The URL of the workbook
3075
+ * @example
3076
+ * ```ts
3077
+ * // The code below gets the URL of the workbook
3078
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3079
+ * const url = activeSpreadsheet.getUrl();
3080
+ * ```
3081
+ */
3082
+ getUrl() {
3083
+ return location.href;
3084
+ }
3085
+ /**
3086
+ * Move the sheet to the specified index.
3087
+ * @param {FWorksheet} sheet The sheet to move
3088
+ * @param {number} index The index to move the sheet to
3089
+ * @returns {Promise<boolean>} true if the sheet was moved, false otherwise
3090
+ * @example
3091
+ * ```ts
3092
+ * // The code below moves the sheet to the specified index
3093
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3094
+ * const sheet = activeSpreadsheet.getActiveSheet();
3095
+ * activeSpreadsheet.moveSheet(sheet, 1);
3096
+ * ```
3097
+ */
3098
+ moveSheet(e, t) {
3099
+ let n = t;
3100
+ return n < 0 ? n = 0 : n > this._workbook.getSheets().length - 1 && (n = this._workbook.getSheets().length - 1), this._commandService.executeCommand(bt.id, {
3101
+ unitId: e.getWorkbook().getUnitId(),
3102
+ order: n,
3103
+ subUnitId: e.getSheetId()
3104
+ });
3105
+ }
3106
+ /**
3107
+ * Move the active sheet to the specified index.
3108
+ * @param {number} index The index to move the active sheet to
3109
+ * @returns {Promise<boolean>} true if the sheet was moved, false otherwise
3110
+ * @example
3111
+ * ```ts
3112
+ * // The code below moves the active sheet to the specified index
3113
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3114
+ * activeSpreadsheet.moveActiveSheet(1);
3115
+ * ```
3116
+ */
3117
+ moveActiveSheet(e) {
3118
+ const t = this.getActiveSheet();
3119
+ return this.moveSheet(t, e);
3120
+ }
3121
+ /**
3122
+ * Get the PermissionInstance.
3123
+ *
3124
+ * @returns {FPermission} - The PermissionInstance.
3125
+ */
3126
+ getPermission() {
3127
+ return this._injector.createInstance(O);
3128
+ }
3129
+ /**
3130
+ * Get the defined name by name.
3131
+ * @param {string} name The name of the defined name to get
3132
+ * @returns {FDefinedName | null} The defined name with the given name
3133
+ * @example
3134
+ * ```ts
3135
+ * // The code below gets the defined name by name
3136
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3137
+ * const definedName = activeSpreadsheet.getDefinedName('MyDefinedName');
3138
+ * ```
3139
+ */
3140
+ getDefinedName(e) {
3141
+ const t = this._definedNamesService.getValueByName(this.id, e);
3142
+ return t ? this._injector.createInstance(W, { ...t, unitId: this.id }) : null;
3143
+ }
3144
+ /**
3145
+ * Get all the defined names in the workbook.
3146
+ * @returns {FDefinedName[]} All the defined names in the workbook
3147
+ * @example
3148
+ * ```ts
3149
+ * // The code below gets all the defined names in the workbook
3150
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3151
+ * const definedNames = activeSpreadsheet.getDefinedNames();
3152
+ * ```
3153
+ */
3154
+ getDefinedNames() {
3155
+ const e = this._definedNamesService.getDefinedNameMap(this.id);
3156
+ return e ? Object.values(e).map((t) => this._injector.createInstance(W, { ...t, unitId: this.id })) : [];
3157
+ }
3158
+ /**
3159
+ * Insert a defined name.
3160
+ * @param {string} name The name of the defined name to insert
3161
+ * @param {string} formulaOrRefString The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
3162
+ * @example
3163
+ * ```ts
3164
+ * // The code below inserts a defined name
3165
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3166
+ * activeSpreadsheet.insertDefinedName('MyDefinedName', 'Sheet1!A1');
3167
+ * ```
3168
+ */
3169
+ insertDefinedName(e, t) {
3170
+ const s = this._injector.createInstance(A).setName(e).setRef(t).build();
3171
+ s.localSheetId = K, this.insertDefinedNameBuilder(s);
3172
+ }
3173
+ /**
3174
+ * Delete the defined name with the given name.
3175
+ * @param {string} name The name of the defined name to delete
3176
+ * @returns {boolean} true if the defined name was deleted, false otherwise
3177
+ * @example
3178
+ * ```ts
3179
+ * // The code below deletes the defined name with the given name
3180
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3181
+ * const deleted = activeSpreadsheet.deleteDefinedName('MyDefinedName');
3182
+ * ```
3183
+ */
3184
+ deleteDefinedName(e) {
3185
+ const t = this.getDefinedName(e);
3186
+ return t ? (t.delete(), !0) : !1;
3187
+ }
3188
+ /**
3189
+ * insert a defined name by builder param
3190
+ * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
3191
+ * @example
3192
+ * ```ts
3193
+ * // The code below inserts a defined name by builder param
3194
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3195
+ * const builder = univerAPI.newDefinedName();
3196
+ * const param = builder.setName('MyDefinedName').setRef('Sheet1!A1').build();
3197
+ * activeSpreadsheet.insertDefinedNameBuilder(param);
3198
+ * ```
3199
+ */
3200
+ insertDefinedNameBuilder(e) {
3201
+ e.unitId = this.getId(), this._commandService.syncExecuteCommand(q.id, e);
3202
+ }
3203
+ /**
3204
+ * Update the defined name with the given name.
3205
+ * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
3206
+ * @example
3207
+ * ```ts
3208
+ * // The code below updates the defined name with the given name
3209
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
3210
+ * const builder = activeSpreadsheet.getDefinedName('MyDefinedName').toBuilder();
3211
+ * builder.setRef('Sheet1!A2').setName('MyDefinedName1').build();
3212
+ * activeSpreadsheet.updateDefinedNameBuilder(param);
3213
+ *
3214
+ * ```
3215
+ */
3216
+ updateDefinedNameBuilder(e) {
3217
+ this._commandService.syncExecuteCommand(q.id, e);
1775
3218
  }
1776
3219
  };
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 {
3220
+ I = Yt([
3221
+ k(1, m(v)),
3222
+ k(2, m(Oe)),
3223
+ k(3, m(Ne)),
3224
+ k(4, fe),
3225
+ k(5, l),
3226
+ k(6, Q),
3227
+ k(7, Ce),
3228
+ k(8, m(ke)),
3229
+ k(9, Re)
3230
+ ], I);
3231
+ class Jt extends ve {
1787
3232
  createUniverSheet(e) {
1788
- const o = this._injector.get(he).createUnit(O.UNIVER_SHEET, e);
1789
- return this._injector.createInstance(U, o);
3233
+ const n = this._injector.get(fe).createUnit(U.UNIVER_SHEET, e);
3234
+ return this._injector.createInstance(I, n);
1790
3235
  }
1791
3236
  getActiveWorkbook() {
1792
- const e = this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET);
1793
- return e ? this._injector.createInstance(U, e) : null;
3237
+ const e = this._univerInstanceService.getCurrentUnitForType(U.UNIVER_SHEET);
3238
+ return e ? this._injector.createInstance(I, e) : null;
3239
+ }
3240
+ getUniverSheet(e) {
3241
+ const t = this._univerInstanceService.getUnit(e, U.UNIVER_SHEET);
3242
+ return t ? this._injector.createInstance(I, t) : null;
1794
3243
  }
1795
3244
  getPermission() {
1796
- return this._injector.createInstance(V);
3245
+ return this._injector.createInstance(O);
3246
+ }
3247
+ onUniverSheetCreated(e) {
3248
+ const t = this._univerInstanceService.getTypeOfUnitAdded$(U.UNIVER_SHEET).subscribe((n) => {
3249
+ const s = this._injector.createInstance(I, n);
3250
+ e(s);
3251
+ });
3252
+ return Ie(t);
3253
+ }
3254
+ newDefinedName() {
3255
+ return this._injector.createInstance(A);
1797
3256
  }
1798
3257
  }
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;
3258
+ ve.extend(Jt);
3259
+ var Qt = Object.defineProperty, Xt = Object.getOwnPropertyDescriptor, Zt = (o, e, t, n) => {
3260
+ for (var s = n > 1 ? void 0 : n ? Xt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
3261
+ (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
3262
+ return n && s && Qt(e, t, s), s;
3263
+ }, en = (o, e) => (t, n) => e(t, n, o);
3264
+ let _e = class extends p {
3265
+ constructor(o) {
3266
+ super(), this._injector = o;
1808
3267
  }
1809
3268
  };
1810
- ie = yt([
1811
- Pt(0, u(R))
1812
- ], ie);
3269
+ _e = Zt([
3270
+ en(0, m(v))
3271
+ ], _e);
1813
3272
  export {
1814
- V as FPermission,
3273
+ O as FPermission,
1815
3274
  S as FRange,
1816
- L as FSelection,
1817
- ie as FSheetHooks,
1818
- U as FWorkbook,
1819
- g as FWorksheet
3275
+ F as FSelection,
3276
+ _e as FSheetHooks,
3277
+ I as FWorkbook,
3278
+ _ as FWorksheet
1820
3279
  };