@univerjs/sheets 0.4.2 → 0.5.0-beta.0

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 (60) hide show
  1. package/lib/cjs/facade.js +1 -0
  2. package/lib/cjs/index.js +3 -3
  3. package/lib/cjs/locale/en-US.js +1 -0
  4. package/lib/cjs/locale/fa-IR.js +1 -0
  5. package/lib/cjs/locale/ru-RU.js +1 -0
  6. package/lib/cjs/locale/vi-VN.js +1 -0
  7. package/lib/cjs/locale/zh-CN.js +1 -0
  8. package/lib/cjs/locale/zh-TW.js +1 -0
  9. package/lib/es/facade.js +1806 -0
  10. package/lib/es/index.js +7694 -7605
  11. package/lib/es/locale/en-US.js +17 -0
  12. package/lib/es/locale/fa-IR.js +17 -0
  13. package/lib/es/locale/ru-RU.js +17 -0
  14. package/lib/es/locale/vi-VN.js +17 -0
  15. package/lib/es/locale/zh-CN.js +17 -0
  16. package/lib/es/locale/zh-TW.js +17 -0
  17. package/lib/types/basics/selection.d.ts +31 -20
  18. package/lib/types/commands/commands/add-worksheet-protection.command.d.ts +7 -0
  19. package/lib/types/commands/commands/delete-worksheet-protection.command.d.ts +8 -0
  20. package/lib/types/commands/commands/set-frozen.command.d.ts +13 -0
  21. package/lib/types/commands/commands/set-protection.command.d.ts +13 -0
  22. package/lib/types/commands/commands/set-worksheet-protection.command.d.ts +8 -0
  23. package/lib/types/commands/mutations/reorder-range.mutation.d.ts +1 -1
  24. package/lib/types/commands/operations/selection.operation.d.ts +4 -1
  25. package/lib/types/facade/__tests__/utils.spec.d.ts +16 -0
  26. package/lib/types/facade/f-permission.d.ts +106 -0
  27. package/lib/types/facade/f-range.d.ts +193 -0
  28. package/lib/types/facade/f-selection.d.ts +11 -0
  29. package/lib/types/facade/f-univer.d.ts +36 -0
  30. package/lib/types/facade/f-workbook.d.ts +105 -0
  31. package/lib/types/facade/f-worksheet.d.ts +408 -0
  32. package/lib/types/facade/index.d.ts +22 -0
  33. package/lib/types/facade/utils.d.ts +24 -0
  34. package/lib/types/index.d.ts +11 -9
  35. package/lib/types/model/range-protection-rule.model.d.ts +10 -1
  36. package/lib/types/services/permission/type.d.ts +3 -1
  37. package/lib/types/services/permission/worksheet-permission/worksheet-permission.service.d.ts +3 -2
  38. package/lib/types/services/ref-range/util.d.ts +12 -4
  39. package/lib/types/services/selections/index.d.ts +19 -0
  40. package/lib/types/services/selections/selection-data-model.d.ts +57 -0
  41. package/lib/types/services/selections/selection-manager.service.d.ts +15 -61
  42. package/lib/types/services/selections/type.d.ts +28 -0
  43. package/lib/types/services/sheet-interceptor/sheet-interceptor.service.d.ts +38 -7
  44. package/lib/umd/facade.js +1 -0
  45. package/lib/umd/index.js +3 -3
  46. package/lib/umd/locale/en-US.js +1 -0
  47. package/lib/umd/locale/fa-IR.js +1 -0
  48. package/lib/umd/locale/ru-RU.js +1 -0
  49. package/lib/umd/locale/vi-VN.js +1 -0
  50. package/lib/umd/locale/zh-CN.js +1 -0
  51. package/lib/umd/locale/zh-TW.js +1 -0
  52. package/package.json +36 -18
  53. package/lib/locale/en-US.json +0 -14
  54. package/lib/locale/fa-IR.json +0 -14
  55. package/lib/locale/ru-RU.json +0 -14
  56. package/lib/locale/vi-VN.json +0 -14
  57. package/lib/locale/zh-CN.json +0 -14
  58. package/lib/locale/zh-TW.json +0 -14
  59. package/lib/types/commands/commands/set-frozen-cancel.command.d.ts +0 -2
  60. package/lib/types/commands/commands/set-range-protection.command.d.ts +0 -8
@@ -0,0 +1,1806 @@
1
+ var ue = Object.defineProperty;
2
+ var me = (n, e, t) => e in n ? ue(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var E = (n, e, t) => me(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { Inject as u, Injector as f, IAuthzIoService as le, FBase as U, generateRandomId as ge, Rectangle as j, ICommandService as R, IPermissionService as ie, HorizontalAlign as C, VerticalAlign as I, isFormulaString as _e, isCellV as we, isICellData as ke, ObjectMatrix as y, Tools as Se, RANGE_TYPE as l, BooleanNumber as m, WrapStrategy as H, Dimension as N, Direction as b, IResourceLoaderService as Ce, mergeWorksheetSnapshotWithDefault as Ie, UndoCommand as Re, RedoCommand as ve, toDisposable as fe, UniverInstanceType as O, IUniverInstanceService as ae, ILogService as be, FUniver as he } from "@univerjs/core";
5
+ import { WorksheetProtectionRuleModel as pe, RangeProtectionRuleModel as ye, WorksheetProtectionPointModel as Pe, WorkbookEditablePermission as ce, UnitObject as v, AddWorksheetProtectionMutation as Ue, DeleteWorksheetProtectionMutation as xe, getAllWorksheetPermissionPoint as Ee, getAllWorksheetPermissionPointByPointPanel as $, SetWorksheetPermissionPointsMutation as Me, AddRangeProtectionMutation as Fe, DeleteRangeProtectionMutation as We, SetRangeProtectionMutation as Ae, WorksheetEditPermission as De, WorksheetViewPermission as Te, SetStyleCommand as _, SetRangeValuesCommand as G, SetTextWrapCommand as q, SetVerticalTextAlignCommand as je, SetHorizontalTextAlignCommand as Oe, addMergeCellsUtil as M, getAddMergeMutationRangeByType as Y, RemoveWorksheetMergeCommand as Ve, SheetsSelectionsService as de, SetWorksheetDefaultStyleMutation as ze, SetColDataCommand as J, SetRowDataCommand as K, copyRangeStyles as p, InsertRowCommand as Q, RemoveRowCommand as Le, MoveRowsCommand as Be, SetRowHiddenCommand as X, SetSpecificRowsVisibleCommand as Z, SetRowHeightCommand as ee, SetWorksheetRowIsAutoHeightCommand as He, InsertColCommand as te, RemoveColCommand as Ne, MoveColsCommand as $e, SetColHiddenCommand as ne, SetSpecificColsVisibleCommand as oe, SetColWidthCommand as Ge, SetFrozenCommand as qe, CancelFrozenCommand as Ye, ToggleGridlinesCommand as Je, SetRangeValuesMutation as se, InsertSheetCommand as re, SetWorksheetActiveOperation as F, RemoveSheetCommand as Ke, getPrimaryForRange as Qe, SetSelectionsOperation as Xe } from "@univerjs/sheets";
6
+ import { FormulaDataModel as Ze, deserializeRangeWithSheet as et } from "@univerjs/engine-formula";
7
+ var tt = Object.defineProperty, nt = Object.getOwnPropertyDescriptor, ot = (n, e, t, o) => {
8
+ for (var s = o > 1 ? void 0 : o ? nt(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 && tt(e, t, s), s;
11
+ }, w = (n, e) => (t, o) => e(t, o, n);
12
+ let V = class extends U {
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;
15
+ }
16
+ /**
17
+ * Configures a specific permission point for a workbook.
18
+ *
19
+ * This function sets or updates a permission point for a workbook identified by `unitId`.
20
+ * It creates a new permission point if it does not already exist, and updates the point with the provided value.
21
+ *
22
+ * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
23
+ * @param {WorkbookPermissionPointConstructor} FPointClass - The constructor function for creating a permission point instance. Other point constructors can See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
24
+ * @param {boolean} value - The boolean value to determine whether the permission point is enabled or disabled.
25
+ *
26
+ */
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);
30
+ }
31
+ /**
32
+ * This function is used to set whether the workbook can be edited
33
+ *
34
+ * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
35
+ * @param {boolean} value - A value that controls whether the workbook can be edited
36
+ *
37
+ */
38
+ setWorkbookEditPermission(n, e) {
39
+ this.setWorkbookPermissionPoint(n, ce, e);
40
+ }
41
+ /**
42
+ * This function is used to add a base permission for a worksheet.
43
+ *
44
+ * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
45
+ * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
46
+ *
47
+ * @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
+ */
49
+ async addWorksheetBasePermission(n, e) {
50
+ if (this._rangeProtectionRuleModel.getSubunitRuleList(n, e).length > 0)
51
+ throw new Error("sheet protection cannot intersect with range protection");
52
+ const o = await this._authzIoService.create({ objectType: v.Worksheet });
53
+ if (this._commandService.syncExecuteCommand(Ue.id, {
54
+ unitId: n,
55
+ subUnitId: e,
56
+ rule: {
57
+ permissionId: o,
58
+ unitType: v.Worksheet,
59
+ unitId: n,
60
+ subUnitId: e
61
+ }
62
+ }))
63
+ return o;
64
+ }
65
+ /**
66
+ * Delete the entire table protection set for the worksheet and reset the point permissions of the worksheet to true
67
+ *
68
+ * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
69
+ * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
70
+ */
71
+ removeWorksheetPermission(n, e) {
72
+ this._commandService.syncExecuteCommand(xe.id, {
73
+ unitId: n,
74
+ subUnitId: e
75
+ }), [...Ee(), ...$()].forEach((t) => {
76
+ const o = new t(n, e);
77
+ this._permissionService.updatePermissionPoint(o.id, !0);
78
+ }), this._worksheetProtectionPointRuleModel.deleteRule(n, e);
79
+ }
80
+ /**
81
+ * Sets the worksheet permission point by updating or adding the permission point for the worksheet.
82
+ * If the worksheet doesn't have a base permission, it creates one to used render
83
+ *
84
+ * @param {string} unitId - The unique identifier of the workbook.
85
+ * @param {string} subUnitId - The unique identifier of the worksheet.
86
+ * @param {WorkSheetPermissionPointConstructor} FPointClass - The constructor for the permission point class.
87
+ * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
88
+ * @param {boolean} value - The new permission value to be set for the worksheet.
89
+ *
90
+ * @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
+ */
92
+ async setWorksheetPermissionPoint(n, e, t, o) {
93
+ const s = this._worksheetProtectionRuleModel.getRule(n, e);
94
+ let r;
95
+ if (t === De || t === Te)
96
+ if (s)
97
+ r = s.permissionId;
98
+ else {
99
+ if (this._rangeProtectionRuleModel.getSubunitRuleList(n, e).length > 0)
100
+ throw new Error("sheet protection cannot intersect with range protection");
101
+ r = await this.addWorksheetBasePermission(n, e);
102
+ }
103
+ else {
104
+ const c = this._worksheetProtectionPointRuleModel.getRule(n, e);
105
+ c ? r = c.permissionId : (r = await this._authzIoService.create({ objectType: v.Worksheet }), this._commandService.executeCommand(Me.id, { unitId: n, subUnitId: e, permissionId: r }));
106
+ }
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;
109
+ }
110
+ /**
111
+ * Adds a range protection to the worksheet.
112
+ *
113
+ * @param {string} unitId - The unique identifier of the workbook.
114
+ * @param {string} subUnitId - The unique identifier of the worksheet.
115
+ * @param {IRange[]} ranges - The ranges to be protected.
116
+ *
117
+ * @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
+ */
119
+ async addRangeBaseProtection(n, e, t) {
120
+ const o = await this._authzIoService.create({ objectType: v.SelectRange }), s = `ruleId_${ge(6)}`;
121
+ if (this._worksheetProtectionRuleModel.getRule(n, e))
122
+ 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) => j.intersects(x, d)))))
124
+ throw new Error("range protection cannot intersect");
125
+ if (this._commandService.syncExecuteCommand(Fe.id, {
126
+ unitId: n,
127
+ subUnitId: e,
128
+ rules: [{
129
+ permissionId: o,
130
+ unitType: v.SelectRange,
131
+ unitId: n,
132
+ subUnitId: e,
133
+ ranges: t,
134
+ id: s
135
+ }]
136
+ }))
137
+ return {
138
+ permissionId: o,
139
+ ruleId: s
140
+ };
141
+ }
142
+ /**
143
+ * Removes the range protection from the worksheet.
144
+ *
145
+ * @param {string} unitId - The unique identifier of the workbook.
146
+ * @param {string} subUnitId - The unique identifier of the worksheet.
147
+ * @param {string[]} ruleIds - The rule IDs of the range protection to be removed.
148
+ */
149
+ removeRangeProtection(n, e, t) {
150
+ this._commandService.syncExecuteCommand(We.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);
157
+ }));
158
+ }
159
+ /**
160
+ * Modify the permission points of a custom area
161
+ *
162
+ * @param {string} unitId - The unique identifier of the workbook.
163
+ * @param {string} subUnitId - The unique identifier of the worksheet within the workbook.
164
+ * @param {string} permissionId - The unique identifier of the permission that controls access to the range.
165
+ * @param {RangePermissionPointConstructor} FPointClass - The constructor for the range permission point class.
166
+ * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
167
+ * @param {boolean} value - The new permission value to be set for the range (e.g., true for allowing access, false for restricting access).
168
+ */
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);
172
+ }
173
+ /**
174
+ * Sets the ranges for range protection in a worksheet.
175
+ *
176
+ * This method finds the rule by unitId, subUnitId, and ruleId, and updates the rule with the provided ranges.
177
+ * It checks for overlaps with existing ranges in the same subunit and shows an error message if any overlap is detected.
178
+ * If no overlap is found, it executes the command to update the range protection with the new ranges.
179
+ *
180
+ * @param {string} unitId - The unique identifier of the workbook.
181
+ * @param {string} subUnitId - The unique identifier of the worksheet within the workbook.
182
+ * @param {string} ruleId - The ruleId of the range protection rule that is being updated.
183
+ * @param {IRange[]} ranges - The array of new ranges to be set for the range protection rule.
184
+ */
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) => j.intersects(c, h)))))
189
+ throw new Error("range protection cannot intersect");
190
+ this._commandService.syncExecuteCommand(Ae.id, {
191
+ unitId: n,
192
+ subUnitId: e,
193
+ ruleId: t,
194
+ rule: {
195
+ ...s,
196
+ ranges: o
197
+ }
198
+ });
199
+ }
200
+ }
201
+ };
202
+ V = ot([
203
+ w(0, u(f)),
204
+ w(1, R),
205
+ w(2, ie),
206
+ w(3, u(pe)),
207
+ w(4, u(ye)),
208
+ w(5, u(Pe)),
209
+ w(6, u(le))
210
+ ], V);
211
+ function st(n) {
212
+ switch (n) {
213
+ case "left":
214
+ return C.LEFT;
215
+ case "center":
216
+ return C.CENTER;
217
+ case "normal":
218
+ return C.RIGHT;
219
+ default:
220
+ throw new Error(`Invalid horizontal alignment: ${n}`);
221
+ }
222
+ }
223
+ function rt(n) {
224
+ switch (n) {
225
+ case C.LEFT:
226
+ return "left";
227
+ case C.CENTER:
228
+ return "center";
229
+ case C.RIGHT:
230
+ return "normal";
231
+ default:
232
+ throw new Error(`Invalid horizontal alignment: ${n}`);
233
+ }
234
+ }
235
+ function it(n) {
236
+ switch (n) {
237
+ case "top":
238
+ return I.TOP;
239
+ case "middle":
240
+ return I.MIDDLE;
241
+ case "bottom":
242
+ return I.BOTTOM;
243
+ default:
244
+ throw new Error(`Invalid vertical alignment: ${n}`);
245
+ }
246
+ }
247
+ function at(n) {
248
+ switch (n) {
249
+ case I.TOP:
250
+ return "top";
251
+ case I.MIDDLE:
252
+ return "middle";
253
+ case I.BOTTOM:
254
+ return "bottom";
255
+ default:
256
+ throw new Error(`Invalid vertical alignment: ${n}`);
257
+ }
258
+ }
259
+ function z(n) {
260
+ return _e(n) ? {
261
+ f: n
262
+ } : we(n) ? {
263
+ v: n
264
+ } : (ke(n), n);
265
+ }
266
+ function ht(n, e) {
267
+ const t = new y(), { startRow: o, startColumn: s, endRow: r, endColumn: i } = e;
268
+ if (Se.isArray(n))
269
+ for (let a = 0; a <= r - o; a++)
270
+ for (let h = 0; h <= i - s; h++)
271
+ t.setValue(a + o, h + s, z(n[a][h]));
272
+ else
273
+ new y(n).forValue((h, c, d) => {
274
+ t.setValue(h, c, z(d));
275
+ });
276
+ return t.getMatrix();
277
+ }
278
+ function W(n, e) {
279
+ return {
280
+ startRow: n.startRow,
281
+ endRow: n.endRow,
282
+ startColumn: 0,
283
+ endColumn: e.getColumnCount() - 1,
284
+ rangeType: l.ROW
285
+ };
286
+ }
287
+ function A(n, e) {
288
+ return {
289
+ startRow: 0,
290
+ endRow: e.getRowCount() - 1,
291
+ startColumn: n.startColumn,
292
+ endColumn: n.endColumn,
293
+ rangeType: l.COLUMN
294
+ };
295
+ }
296
+ var ct = Object.defineProperty, dt = Object.getOwnPropertyDescriptor, ut = (n, e, t, o) => {
297
+ for (var s = o > 1 ? void 0 : o ? dt(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 && ct(e, t, s), s;
300
+ }, D = (n, e) => (t, o) => e(t, o, n);
301
+ let S = class extends U {
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;
304
+ }
305
+ /**
306
+ * Get the unit ID of the current workbook
307
+ *
308
+ * @return The unit ID of the workbook
309
+ */
310
+ getUnitId() {
311
+ return this._workbook.getUnitId();
312
+ }
313
+ /**
314
+ * Gets the name of the worksheet
315
+ *
316
+ * @return The name of the worksheet
317
+ */
318
+ getSheetName() {
319
+ return this._worksheet.getName();
320
+ }
321
+ /**
322
+ * Gets the area where the statement is applied
323
+ *
324
+ * @return The area where the statement is applied
325
+ */
326
+ getRange() {
327
+ return this._range;
328
+ }
329
+ /**
330
+ * Gets the starting row number of the applied area
331
+ *
332
+ * @return The starting row number of the area
333
+ */
334
+ getRow() {
335
+ return this._range.startRow;
336
+ }
337
+ /**
338
+ * Gets the starting column number of the applied area
339
+ *
340
+ * @return The starting column number of the area
341
+ */
342
+ getColumn() {
343
+ return this._range.startColumn;
344
+ }
345
+ /**
346
+ * Gets the width of the applied area
347
+ *
348
+ * @return The width of the area
349
+ */
350
+ getWidth() {
351
+ return this._range.endColumn - this._range.startColumn + 1;
352
+ }
353
+ /**
354
+ * Gets the height of the applied area
355
+ *
356
+ * @return The height of the area
357
+ */
358
+ getHeight() {
359
+ return this._range.endRow - this._range.startRow + 1;
360
+ }
361
+ /**
362
+ * Return first cell model data in this range
363
+ * @returns The cell model data
364
+ */
365
+ getCellData() {
366
+ var n;
367
+ return (n = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) != null ? n : null;
368
+ }
369
+ /**
370
+ * Return range whether this range is merged
371
+ * @returns if true is merged
372
+ */
373
+ isMerged() {
374
+ const { startColumn: n, startRow: e, endColumn: t, endRow: o } = this._range;
375
+ return this._worksheet.getMergedCellRange(e, n, o, t).some((r) => j.equals(r, this._range));
376
+ }
377
+ /**
378
+ * Return first cell style data in this range
379
+ * @returns The cell style data
380
+ */
381
+ getCellStyleData() {
382
+ var t;
383
+ const n = this.getCellData(), e = this._workbook.getStyles();
384
+ return n && e && (t = e.getStyleByCell(n)) != null ? t : null;
385
+ }
386
+ /**
387
+ * Returns the value of the cell at the start of this range.
388
+ * @returns The value of the cell.
389
+ */
390
+ 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;
393
+ }
394
+ /**
395
+ * Returns the rectangular grid of values for this range.
396
+ * Returns a two-dimensional array of values, indexed by row, then by column.
397
+ * @returns A two-dimensional array of values.
398
+ */
399
+ getValues() {
400
+ var r, i;
401
+ const { startRow: n, endRow: e, startColumn: t, endColumn: o } = this._range, s = [];
402
+ for (let a = n; a <= e; a++) {
403
+ const h = [];
404
+ for (let c = t; c <= o; c++)
405
+ h.push((i = (r = this._worksheet.getCell(a, c)) == null ? void 0 : r.v) != null ? i : null);
406
+ s.push(h);
407
+ }
408
+ return s;
409
+ }
410
+ /**
411
+ * Returns the cell data for the cells in the range.
412
+ * @returns A two-dimensional array of cell data.
413
+ */
414
+ getCellDataGrid() {
415
+ const { startRow: n, endRow: e, startColumn: t, endColumn: o } = this._range, s = [];
416
+ for (let r = n; r <= e; r++) {
417
+ const i = [];
418
+ for (let a = t; a <= o; a++)
419
+ i.push(this._worksheet.getCellRaw(r, a));
420
+ s.push(i);
421
+ }
422
+ return s;
423
+ }
424
+ /**
425
+ * Returns the formulas (A1 notation) for the cells in the range. Entries in the 2D array are empty strings for cells with no formula.
426
+ * @returns A two-dimensional array of formulas in string format.
427
+ */
428
+ getFormulas() {
429
+ const n = [], { startRow: e, endRow: t, startColumn: o, endColumn: s } = this._range, r = this._worksheet.getSheetId(), i = this._workbook.getUnitId();
430
+ for (let a = e; a <= t; a++) {
431
+ const h = [];
432
+ for (let c = o; c <= s; c++) {
433
+ const d = this._formulaDataModel.getFormulaStringByCell(a, c, r, i);
434
+ h.push(d || "");
435
+ }
436
+ n.push(h);
437
+ }
438
+ return n;
439
+ }
440
+ getWrap() {
441
+ return this._worksheet.getRange(this._range).getWrap() === m.TRUE;
442
+ }
443
+ getWrapStrategy() {
444
+ return this._worksheet.getRange(this._range).getWrapStrategy();
445
+ }
446
+ getHorizontalAlignment() {
447
+ return rt(this._worksheet.getRange(this._range).getHorizontalAlignment());
448
+ }
449
+ getVerticalAlignment() {
450
+ return at(this._worksheet.getRange(this._range).getVerticalAlignment());
451
+ }
452
+ // #region editing
453
+ setBackgroundColor(n) {
454
+ return this._commandService.executeCommand(_.id, {
455
+ unitId: this._workbook.getUnitId(),
456
+ subUnitId: this._worksheet.getSheetId(),
457
+ range: this._range,
458
+ style: {
459
+ type: "bg",
460
+ value: {
461
+ rgb: n
462
+ }
463
+ }
464
+ });
465
+ }
466
+ /**
467
+ * 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
+ * @param value
469
+ */
470
+ setValue(n) {
471
+ const e = z(n);
472
+ if (!e)
473
+ throw new Error("Invalid value");
474
+ return this._commandService.executeCommand(G.id, {
475
+ unitId: this._workbook.getUnitId(),
476
+ subUnitId: this._worksheet.getSheetId(),
477
+ range: this._range,
478
+ value: e
479
+ });
480
+ }
481
+ /**
482
+ * Set the cell wrap of the given range.
483
+ * 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
+ */
485
+ setWrap(n) {
486
+ return this._commandService.executeCommand(q.id, {
487
+ unitId: this._workbook.getUnitId(),
488
+ subUnitId: this._worksheet.getSheetId(),
489
+ range: this._range,
490
+ value: n ? H.WRAP : H.UNSPECIFIED
491
+ });
492
+ }
493
+ /**
494
+ * Sets the text wrapping strategy for the cells in the range.
495
+ */
496
+ setWrapStrategy(n) {
497
+ return this._commandService.executeCommand(q.id, {
498
+ unitId: this._workbook.getUnitId(),
499
+ subUnitId: this._worksheet.getSheetId(),
500
+ range: this._range,
501
+ value: n
502
+ });
503
+ }
504
+ /**
505
+ * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).
506
+ */
507
+ setVerticalAlignment(n) {
508
+ return this._commandService.executeCommand(je.id, {
509
+ unitId: this._workbook.getUnitId(),
510
+ subUnitId: this._worksheet.getSheetId(),
511
+ range: this._range,
512
+ value: it(n)
513
+ });
514
+ }
515
+ /**
516
+ * Set the horizontal (left to right) alignment for the given range (left/center/right).
517
+ */
518
+ setHorizontalAlignment(n) {
519
+ return this._commandService.executeCommand(Oe.id, {
520
+ unitId: this._workbook.getUnitId(),
521
+ subUnitId: this._worksheet.getSheetId(),
522
+ range: this._range,
523
+ value: st(n)
524
+ });
525
+ }
526
+ /**
527
+ * 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
+ * @param value
529
+ */
530
+ setValues(n) {
531
+ const e = ht(n, this._range);
532
+ return this._commandService.executeCommand(G.id, {
533
+ unitId: this._workbook.getUnitId(),
534
+ subUnitId: this._worksheet.getSheetId(),
535
+ range: this._range,
536
+ value: e
537
+ });
538
+ }
539
+ /**
540
+ * Sets the font weight for the given range (normal/bold),
541
+ * @param fontWeight The font weight, either 'normal' or 'bold'; a null value resets the font weight.
542
+ */
543
+ setFontWeight(n) {
544
+ let e;
545
+ if (n === "bold")
546
+ e = m.TRUE;
547
+ else if (n === "normal")
548
+ e = m.FALSE;
549
+ else if (n === null)
550
+ e = null;
551
+ else
552
+ throw new Error("Invalid fontWeight");
553
+ const t = {
554
+ type: "bl",
555
+ value: e
556
+ }, o = {
557
+ unitId: this._workbook.getUnitId(),
558
+ subUnitId: this._worksheet.getSheetId(),
559
+ range: this._range,
560
+ style: t
561
+ };
562
+ return this._commandService.executeCommand(_.id, o), this;
563
+ }
564
+ /**
565
+ * Sets the font style for the given range ('italic' or 'normal').
566
+ * @param fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.
567
+ */
568
+ setFontStyle(n) {
569
+ let e;
570
+ if (n === "italic")
571
+ e = m.TRUE;
572
+ else if (n === "normal")
573
+ e = m.FALSE;
574
+ else if (n === null)
575
+ e = null;
576
+ else
577
+ throw new Error("Invalid fontStyle");
578
+ const t = {
579
+ type: "it",
580
+ value: e
581
+ }, o = {
582
+ unitId: this._workbook.getUnitId(),
583
+ subUnitId: this._worksheet.getSheetId(),
584
+ range: this._range,
585
+ style: t
586
+ };
587
+ return this._commandService.executeCommand(_.id, o), this;
588
+ }
589
+ /**
590
+ * Sets the font line style of the given range ('underline', 'line-through', or 'none').
591
+ * @param fontLine The font line style, either 'underline', 'line-through', or 'none'; a null value resets the font line style.
592
+ */
593
+ setFontLine(n) {
594
+ if (n === "underline")
595
+ this._setFontUnderline({
596
+ s: m.TRUE
597
+ });
598
+ else if (n === "line-through")
599
+ this._setFontStrikethrough({
600
+ s: m.TRUE
601
+ });
602
+ else if (n === "none")
603
+ this._setFontUnderline({
604
+ s: m.FALSE
605
+ }), this._setFontStrikethrough({
606
+ s: m.FALSE
607
+ });
608
+ else if (n === null)
609
+ this._setFontUnderline(null), this._setFontStrikethrough(null);
610
+ else
611
+ throw new Error("Invalid fontLine");
612
+ return this;
613
+ }
614
+ /**
615
+ * Sets the font underline style of the given ITextDecoration
616
+ */
617
+ _setFontUnderline(n) {
618
+ const e = {
619
+ type: "ul",
620
+ value: n
621
+ }, t = {
622
+ unitId: this._workbook.getUnitId(),
623
+ subUnitId: this._worksheet.getSheetId(),
624
+ range: this._range,
625
+ style: e
626
+ };
627
+ this._commandService.executeCommand(_.id, t);
628
+ }
629
+ /**
630
+ * Sets the font strikethrough style of the given ITextDecoration
631
+ */
632
+ _setFontStrikethrough(n) {
633
+ const e = {
634
+ type: "st",
635
+ value: n
636
+ }, t = {
637
+ unitId: this._workbook.getUnitId(),
638
+ subUnitId: this._worksheet.getSheetId(),
639
+ range: this._range,
640
+ style: e
641
+ };
642
+ this._commandService.executeCommand(_.id, t);
643
+ }
644
+ /**
645
+ * Sets the font family, such as "Arial" or "Helvetica".
646
+ * @param fontFamily The font family to set; a null value resets the font family.
647
+ */
648
+ setFontFamily(n) {
649
+ const e = {
650
+ type: "ff",
651
+ value: n
652
+ }, t = {
653
+ unitId: this._workbook.getUnitId(),
654
+ subUnitId: this._worksheet.getSheetId(),
655
+ range: this._range,
656
+ style: e
657
+ };
658
+ return this._commandService.executeCommand(_.id, t), this;
659
+ }
660
+ /**
661
+ * Sets the font size, with the size being the point size to use.
662
+ * @param size A font size in point size. A null value resets the font size.
663
+ */
664
+ setFontSize(n) {
665
+ const e = {
666
+ type: "fs",
667
+ value: n
668
+ }, t = {
669
+ unitId: this._workbook.getUnitId(),
670
+ subUnitId: this._worksheet.getSheetId(),
671
+ range: this._range,
672
+ style: e
673
+ };
674
+ return this._commandService.executeCommand(_.id, t), this;
675
+ }
676
+ /**
677
+ * Sets the font color in CSS notation (such as '#ffffff' or 'white').
678
+ * @param color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color.
679
+ */
680
+ setFontColor(n) {
681
+ const t = {
682
+ type: "cl",
683
+ value: n === null ? null : { rgb: n }
684
+ }, o = {
685
+ unitId: this._workbook.getUnitId(),
686
+ subUnitId: this._worksheet.getSheetId(),
687
+ range: this._range,
688
+ style: t
689
+ };
690
+ return this._commandService.executeCommand(_.id, o), this;
691
+ }
692
+ // #endregion editing
693
+ //#region Merge cell
694
+ /**
695
+ * Merge cells in a range into one merged cell
696
+ * @returns This range, for chaining
697
+ */
698
+ async merge() {
699
+ const n = this._workbook.getUnitId(), e = this._worksheet.getSheetId();
700
+ return await M(this._injector, n, e, [this._range]), this;
701
+ }
702
+ /**
703
+ * Merges cells in a range horizontally.
704
+ * @returns This range, for chaining
705
+ */
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;
709
+ }
710
+ /**
711
+ * Merges cells in a range vertically.
712
+ * @returns This range, for chaining
713
+ */
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;
717
+ }
718
+ /**
719
+ * Returns true if cells in the current range overlap a merged cell.
720
+ * @returns {boolean} is overlap with a merged cell
721
+ */
722
+ isPartOfMerge() {
723
+ const { startRow: n, startColumn: e, endRow: t, endColumn: o } = this._range;
724
+ return this._worksheet.getMergedCellRange(n, e, t, o).length > 0;
725
+ }
726
+ /**
727
+ * Unmerge cells in the range
728
+ * @returns This range, for chaining
729
+ */
730
+ breakApart() {
731
+ return this._commandService.executeCommand(Ve.id, { ranges: [this._range] }), this;
732
+ }
733
+ //#endregion
734
+ /**
735
+ * 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);
742
+ });
743
+ }
744
+ };
745
+ S = ut([
746
+ D(3, u(f)),
747
+ D(4, R),
748
+ D(5, u(Ze))
749
+ ], S);
750
+ var mt = Object.defineProperty, lt = Object.getOwnPropertyDescriptor, gt = (n, e, t, o) => {
751
+ for (var s = o > 1 ? void 0 : o ? lt(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 && mt(e, t, s), s;
754
+ }, _t = (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;
758
+ }
759
+ getActiveRange() {
760
+ const n = this._selections.find((e) => !!e.primary);
761
+ return n ? this._injector.createInstance(S, this._workbook, this._worksheet, n.range) : null;
762
+ }
763
+ };
764
+ L = gt([
765
+ _t(3, u(f))
766
+ ], L);
767
+ var wt = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, St = (n, e, t, o) => {
768
+ for (var s = o > 1 ? void 0 : o ? kt(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 && wt(e, t, s), s;
771
+ }, T = (n, e) => (t, o) => e(t, o, n);
772
+ let g = class extends U {
773
+ constructor(e, t, o, s, r, i) {
774
+ super();
775
+ /**
776
+ * Sets the active selection region for this sheet.
777
+ * @param range The range to set as the active selection.
778
+ */
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;
781
+ }
782
+ /**
783
+ * Returns the injector
784
+ * @returns The injector
785
+ */
786
+ getInject() {
787
+ return this._injector;
788
+ }
789
+ /**
790
+ * Returns the workbook
791
+ * @returns The workbook
792
+ */
793
+ getWorkbook() {
794
+ return this._workbook;
795
+ }
796
+ /**
797
+ * Returns the worksheet id
798
+ * @returns The id of the worksheet
799
+ */
800
+ getSheetId() {
801
+ return this._worksheet.getSheetId();
802
+ }
803
+ /**
804
+ * Returns the worksheet name
805
+ * @returns The name of the worksheet
806
+ */
807
+ getSheetName() {
808
+ return this._worksheet.getName();
809
+ }
810
+ getSelection() {
811
+ const e = this._selectionManagerService.getCurrentSelections();
812
+ return e ? this._injector.createInstance(L, this._workbook, this._worksheet, e) : null;
813
+ }
814
+ // #region rows
815
+ // #region default style
816
+ /**
817
+ * Get the default style of the worksheet
818
+ * @returns Default style
819
+ */
820
+ getDefaultStyle() {
821
+ return this._worksheet.getDefaultCellStyle();
822
+ }
823
+ /**
824
+ * Get the default style of the worksheet row
825
+ * @param {number} index The row index
826
+ * @param {boolean} [keepRaw] If true, return the raw style data maybe the style name or style data, otherwise return the data from row manager
827
+ * @returns {Nullable<IStyleData> | string} The default style of the worksheet row name or style data
828
+ */
829
+ getRowDefaultStyle(e, t = !1) {
830
+ return this._worksheet.getRowStyle(e, t);
831
+ }
832
+ /**
833
+ * Get the default style of the worksheet column
834
+ * @param {number} index The column index
835
+ * @param {boolean} [keepRaw] If true, return the raw style data maybe the style name or style data, otherwise return the data from col manager
836
+ * @returns {Nullable<IStyleData> | string} The default style of the worksheet column name or style data
837
+ */
838
+ getColumnDefaultStyle(e, t = !1) {
839
+ return this._worksheet.getColumnStyle(e, t);
840
+ }
841
+ /**
842
+ * Set the default style of the worksheet
843
+ * @param style default style
844
+ * @returns this worksheet
845
+ */
846
+ async setDefaultStyle(e) {
847
+ const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId();
848
+ return await this._commandService.executeCommand(ze.id, {
849
+ unitId: t,
850
+ subUnitId: o,
851
+ defaultStyle: e
852
+ }), this._worksheet.setDefaultCellStyle(e), this;
853
+ }
854
+ /**
855
+ * Set the default style of the worksheet row
856
+ * @param {number} index The row index
857
+ * @param {string | Nullable<IStyleData>} style The style name or style data
858
+ */
859
+ async setColumnDefaultStyle(e, t) {
860
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
861
+ unitId: o,
862
+ subUnitId: s,
863
+ columnData: {
864
+ [e]: {
865
+ s: t
866
+ }
867
+ }
868
+ };
869
+ return await this._commandService.executeCommand(J.id, r), this;
870
+ }
871
+ /**
872
+ * Set the default style of the worksheet column
873
+ * @param {number} index The column index
874
+ * @param {string | Nullable<IStyleData>} style The style name or style data
875
+ */
876
+ async setRowDefaultStyle(e, t) {
877
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
878
+ unitId: o,
879
+ subUnitId: s,
880
+ rowData: {
881
+ [e]: {
882
+ s: t
883
+ }
884
+ }
885
+ };
886
+ return await this._commandService.executeCommand(K.id, r), this;
887
+ }
888
+ getRange(e, t, o, s) {
889
+ let r, i;
890
+ if (typeof e == "string") {
891
+ const { range: a, sheetName: h } = et(e), c = h ? this._workbook.getSheetBySheetName(h) : this._worksheet;
892
+ if (!c)
893
+ throw new Error("Range not found");
894
+ i = c, r = {
895
+ ...a,
896
+ unitId: this._workbook.getUnitId(),
897
+ sheetId: i.getSheetId(),
898
+ // Use the current range instead of the future actual range to match Apps Script behavior.
899
+ // 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
905
+ };
906
+ } else if (typeof e == "number" && t !== void 0)
907
+ i = this._worksheet, r = {
908
+ startRow: e,
909
+ endRow: e + (o != null ? o : 1) - 1,
910
+ startColumn: t,
911
+ endColumn: t + (s != null ? s : 1) - 1,
912
+ unitId: this._workbook.getUnitId(),
913
+ sheetId: this._worksheet.getSheetId()
914
+ };
915
+ else
916
+ throw new Error("Invalid range specification");
917
+ return this._injector.createInstance(S, this._workbook, i, r);
918
+ }
919
+ /**
920
+ * Returns the current number of columns in the sheet, regardless of content.
921
+ * @return The maximum columns count of the sheet
922
+ */
923
+ getMaxColumns() {
924
+ return this._worksheet.getMaxColumns();
925
+ }
926
+ /**
927
+ * Returns the current number of rows in the sheet, regardless of content.
928
+ * @return The maximum rows count of the sheet
929
+ */
930
+ getMaxRows() {
931
+ return this._worksheet.getMaxRows();
932
+ }
933
+ /**
934
+ * Inserts a row after the given row position.
935
+ * @param afterPosition The row after which the new row should be added, starting at 0 for the first row.
936
+ * @returns This sheet, for chaining.
937
+ */
938
+ async insertRowAfter(e) {
939
+ return this.insertRowsAfter(e, 1);
940
+ }
941
+ /**
942
+ * Inserts a row before the given row position.
943
+ * @param beforePosition The row before which the new row should be added, starting at 0 for the first row.
944
+ * @returns This sheet, for chaining.
945
+ */
946
+ async insertRowBefore(e) {
947
+ return this.insertRowsBefore(e, 1);
948
+ }
949
+ /**
950
+ * Inserts one or more consecutive blank rows in a sheet starting at the specified location.
951
+ * @param rowIndex The index indicating where to insert a row, starting at 0 for the first row.
952
+ * @param numRows The number of rows to insert.
953
+ * @returns This sheet, for chaining.
954
+ */
955
+ async insertRows(e, t = 1) {
956
+ return this.insertRowsBefore(e, t);
957
+ }
958
+ /**
959
+ * Inserts a number of rows after the given row position.
960
+ * @param afterPosition The row after which the new rows should be added, starting at 0 for the first row.
961
+ * @param howMany The number of rows to insert.
962
+ * @returns This sheet, for chaining.
963
+ */
964
+ async insertRowsAfter(e, t) {
965
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = b.DOWN, i = e + 1, a = e + t, h = 0, c = this._worksheet.getColumnCount() - 1, d = p(this._worksheet, i, a, h, c, !0, e);
966
+ return await this._commandService.executeCommand(Q.id, {
967
+ unitId: o,
968
+ subUnitId: s,
969
+ direction: r,
970
+ range: {
971
+ startRow: i,
972
+ endRow: a,
973
+ startColumn: h,
974
+ endColumn: c
975
+ },
976
+ cellValue: d
977
+ }), this;
978
+ }
979
+ /**
980
+ * Inserts a number of rows before the given row position.
981
+ * @param beforePosition The row before which the new rows should be added, starting at 0 for the first row.
982
+ * @param howMany The number of rows to insert.
983
+ * @returns This sheet, for chaining.
984
+ */
985
+ async insertRowsBefore(e, t) {
986
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = b.UP, i = e, a = e + t - 1, h = 0, c = this._worksheet.getColumnCount() - 1, d = p(this._worksheet, i, a, h, c, !0, e - 1);
987
+ return await this._commandService.executeCommand(Q.id, {
988
+ unitId: o,
989
+ subUnitId: s,
990
+ direction: r,
991
+ range: {
992
+ startRow: i,
993
+ endRow: a,
994
+ startColumn: h,
995
+ endColumn: c
996
+ },
997
+ cellValue: d
998
+ }), this;
999
+ }
1000
+ /**
1001
+ * Deletes the row at the given row position.
1002
+ * @param rowPosition The position of the row, starting at 0 for the first row.
1003
+ * @returns This sheet, for chaining.
1004
+ */
1005
+ async deleteRow(e) {
1006
+ return this.deleteRows(e, 1);
1007
+ }
1008
+ /**
1009
+ * Deletes a number of rows starting at the given row position.
1010
+ * @param rowPosition The position of the first row to delete, starting at 0 for the first row.
1011
+ * @param howMany The number of rows to delete.
1012
+ * @returns This sheet, for chaining.
1013
+ */
1014
+ async deleteRows(e, t) {
1015
+ const o = {
1016
+ startRow: e,
1017
+ endRow: e + t - 1,
1018
+ startColumn: 0,
1019
+ endColumn: this._worksheet.getColumnCount() - 1
1020
+ };
1021
+ return await this._commandService.executeCommand(Le.id, {
1022
+ range: o
1023
+ }), this;
1024
+ }
1025
+ /**
1026
+ * Moves the rows selected by the given range to the position indicated by the destinationIndex. The rowSpec itself does not have to exactly represent an entire row or group of rows to move—it selects all rows that the range spans.
1027
+ * @param rowSpec A range spanning the rows that should be moved.
1028
+ * @param destinationIndex The index that the rows should be moved to. Note that this index is based on the coordinates before the rows are moved. Existing data is shifted down to make room for the moved rows while the source rows are removed from the grid. Therefore, the data may end up at a different index than originally specified. Use 0-index for this method.
1029
+ * @returns This sheet, for chaining.
1030
+ */
1031
+ async moveRows(e, t) {
1032
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = W(e.getRange(), this._worksheet), i = r, a = {
1033
+ startRow: t,
1034
+ endRow: t,
1035
+ startColumn: r.startColumn,
1036
+ endColumn: r.endColumn
1037
+ };
1038
+ return await this._commandService.executeCommand(Be.id, {
1039
+ unitId: o,
1040
+ subUnitId: s,
1041
+ range: r,
1042
+ fromRange: i,
1043
+ toRange: a
1044
+ }), this;
1045
+ }
1046
+ /**
1047
+ * Hides the rows in the given range.
1048
+ * @param row The row range to hide.
1049
+ * @returns This sheet, for chaining.
1050
+ */
1051
+ 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, {
1054
+ unitId: t,
1055
+ subUnitId: o,
1056
+ ranges: [s]
1057
+ }), this;
1058
+ }
1059
+ /**
1060
+ * Hides one or more consecutive rows starting at the given index. Use 0-index for this method.
1061
+ * @param rowIndex The starting index of the rows to hide.
1062
+ * @param numRows The number of rows to hide.
1063
+ * @returns This sheet, for chaining.
1064
+ */
1065
+ async hideRows(e, t = 1) {
1066
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1067
+ startRow: e,
1068
+ endRow: e + t - 1,
1069
+ startColumn: 0,
1070
+ endColumn: this._worksheet.getColumnCount() - 1,
1071
+ rangeType: l.ROW
1072
+ };
1073
+ return await this._commandService.executeCommand(X.id, {
1074
+ unitId: o,
1075
+ subUnitId: s,
1076
+ ranges: [r]
1077
+ }), this;
1078
+ }
1079
+ /**
1080
+ * Unhides the row in the given range.
1081
+ * @param row The range to unhide, if hidden.
1082
+ * @returns This sheet, for chaining.
1083
+ */
1084
+ 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, {
1087
+ unitId: t,
1088
+ subUnitId: o,
1089
+ ranges: [s]
1090
+ }), this;
1091
+ }
1092
+ /**
1093
+ * Unhides one or more consecutive rows starting at the given index. Use 0-index for this method.
1094
+ * @param rowIndex The starting index of the rows to unhide.
1095
+ * @param numRows The number of rows to unhide.
1096
+ * @returns This sheet, for chaining.
1097
+ */
1098
+ async showRows(e, t = 1) {
1099
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1100
+ startRow: e,
1101
+ endRow: e + t - 1,
1102
+ startColumn: 0,
1103
+ endColumn: this._worksheet.getColumnCount() - 1,
1104
+ rangeType: l.ROW
1105
+ };
1106
+ return await this._commandService.executeCommand(Z.id, {
1107
+ unitId: o,
1108
+ subUnitId: s,
1109
+ ranges: [r]
1110
+ }), this;
1111
+ }
1112
+ /**
1113
+ * Sets the row height of the given row in pixels. By default, rows grow to fit cell contents. If you want to force rows to a specified height, use setRowHeightsForced(startRow, numRows, height).
1114
+ * @param rowPosition The row position to change.
1115
+ * @param height The height in pixels to set it to.
1116
+ * @returns This sheet, for chaining.
1117
+ */
1118
+ async setRowHeight(e, t) {
1119
+ return this.setRowHeights(e, 1, t);
1120
+ }
1121
+ /**
1122
+ * Sets the height of the given rows in pixels. By default, rows grow to fit cell contents. If you want to force rows to a specified height, use setRowHeightsForced(startRow, numRows, height).
1123
+ * @param startRow The starting row position to change.
1124
+ * @param numRows The number of rows to change.
1125
+ * @param height The height in pixels to set it to.
1126
+ * @returns This sheet, for chaining.
1127
+ */
1128
+ async setRowHeights(e, t, o) {
1129
+ var c;
1130
+ const s = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = this._worksheet.getRowManager(), a = [], h = [];
1131
+ 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 = {
1133
+ startRow: d,
1134
+ endRow: d,
1135
+ startColumn: 0,
1136
+ endColumn: this._worksheet.getColumnCount() - 1
1137
+ };
1138
+ o <= x ? a.push(B) : h.push(B);
1139
+ }
1140
+ return h.length > 0 && await this._commandService.executeCommand(ee.id, {
1141
+ unitId: s,
1142
+ subUnitId: r,
1143
+ ranges: h,
1144
+ value: o
1145
+ }), a.length > 0 && await this._commandService.executeCommand(He.id, {
1146
+ unitId: s,
1147
+ subUnitId: r,
1148
+ ranges: a
1149
+ }), this;
1150
+ }
1151
+ /**
1152
+ * Sets the height of the given rows in pixels. By default, rows grow to fit cell contents. When you use setRowHeightsForced, rows are forced to the specified height even if the cell contents are taller than the row height.
1153
+ * @param startRow The starting row position to change.
1154
+ * @param numRows The number of rows to change.
1155
+ * @param height The height in pixels to set it to.
1156
+ * @returns This sheet, for chaining.
1157
+ */
1158
+ async setRowHeightsForced(e, t, o) {
1159
+ const s = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = [
1160
+ {
1161
+ startRow: e,
1162
+ endRow: e + t - 1,
1163
+ startColumn: 0,
1164
+ endColumn: this._worksheet.getColumnCount() - 1
1165
+ }
1166
+ ];
1167
+ return await this._commandService.executeCommand(ee.id, {
1168
+ unitId: s,
1169
+ subUnitId: r,
1170
+ ranges: i,
1171
+ value: o
1172
+ }), this;
1173
+ }
1174
+ // #endregion
1175
+ /**
1176
+ * Set custom properties for given rows.
1177
+ * @param custom The custom properties to set.
1178
+ * @returns This sheet, for chaining.
1179
+ */
1180
+ async setRowCustom(e) {
1181
+ const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = {};
1182
+ for (const [i, a] of Object.entries(e))
1183
+ s[Number(i)] = {
1184
+ custom: a
1185
+ };
1186
+ const r = {
1187
+ unitId: t,
1188
+ subUnitId: o,
1189
+ rowData: s
1190
+ };
1191
+ return await this._commandService.executeCommand(K.id, r), this;
1192
+ }
1193
+ // #region Column
1194
+ /**
1195
+ * Inserts a column after the given column position.
1196
+ * @param afterPosition The column after which the new column should be added, starting at 0 for the first column.
1197
+ * @returns This sheet, for chaining.
1198
+ */
1199
+ async insertColumnAfter(e) {
1200
+ return this.insertColumnsAfter(e, 1);
1201
+ }
1202
+ /**
1203
+ * Inserts a column before the given column position.
1204
+ * @param beforePosition The column before which the new column should be added, starting at 0 for the first column.
1205
+ * @returns This sheet, for chaining.
1206
+ */
1207
+ async insertColumnBefore(e) {
1208
+ return this.insertColumnsBefore(e, 1);
1209
+ }
1210
+ /**
1211
+ * Inserts one or more consecutive blank columns in a sheet starting at the specified location.
1212
+ * @param columnIndex The index indicating where to insert a column, starting at 0 for the first column.
1213
+ * @param numColumns The number of columns to insert.
1214
+ * @returns This sheet, for chaining.
1215
+ */
1216
+ async insertColumns(e, t = 1) {
1217
+ return this.insertColumnsBefore(e, t);
1218
+ }
1219
+ /**
1220
+ * Inserts a given number of columns after the given column position.
1221
+ * @param afterPosition The column after which the new column should be added, starting at 0 for the first column.
1222
+ * @param howMany The number of columns to insert.
1223
+ * @returns This sheet, for chaining.
1224
+ */
1225
+ async insertColumnsAfter(e, t) {
1226
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = b.RIGHT, i = 0, a = this._worksheet.getRowCount() - 1, h = e + 1, c = e + t, d = p(this._worksheet, i, a, h, c, !1, e);
1227
+ return await this._commandService.executeCommand(te.id, {
1228
+ unitId: o,
1229
+ subUnitId: s,
1230
+ direction: r,
1231
+ range: {
1232
+ startRow: i,
1233
+ endRow: a,
1234
+ startColumn: h,
1235
+ endColumn: c
1236
+ },
1237
+ cellValue: d
1238
+ }), this;
1239
+ }
1240
+ /**
1241
+ * Inserts a number of columns before the given column position.
1242
+ * @param beforePosition The column before which the new column should be added, starting at 0 for the first column.
1243
+ * @param howMany The number of columns to insert.
1244
+ * @returns This sheet, for chaining.
1245
+ */
1246
+ async insertColumnsBefore(e, t) {
1247
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = b.LEFT, i = 0, a = this._worksheet.getRowCount() - 1, h = e, c = e + t - 1, d = p(this._worksheet, i, a, h, c, !1, e - 1);
1248
+ return await this._commandService.executeCommand(te.id, {
1249
+ unitId: o,
1250
+ subUnitId: s,
1251
+ direction: r,
1252
+ range: {
1253
+ startRow: i,
1254
+ endRow: a,
1255
+ startColumn: h,
1256
+ endColumn: c
1257
+ },
1258
+ cellValue: d
1259
+ }), this;
1260
+ }
1261
+ /**
1262
+ * Deletes the column at the given column position.
1263
+ * @param columnPosition The position of the column, starting at 0 for the first column.
1264
+ * @returns This sheet, for chaining.
1265
+ */
1266
+ async deleteColumn(e) {
1267
+ return this.deleteColumns(e, 1);
1268
+ }
1269
+ /**
1270
+ * Deletes a number of columns starting at the given column position.
1271
+ * @param columnPosition The position of the first column to delete, starting at 0 for the first column.
1272
+ * @param howMany The number of columns to delete.
1273
+ * @returns This sheet, for chaining.
1274
+ */
1275
+ async deleteColumns(e, t) {
1276
+ const o = {
1277
+ startRow: 0,
1278
+ endRow: this._worksheet.getRowCount() - 1,
1279
+ startColumn: e,
1280
+ endColumn: e + t - 1
1281
+ };
1282
+ return await this._commandService.executeCommand(Ne.id, {
1283
+ range: o
1284
+ }), this;
1285
+ }
1286
+ /**
1287
+ * Moves the columns selected by the given range to the position indicated by the destinationIndex. The columnSpec itself does not have to exactly represent an entire column or group of columns to move—it selects all columns that the range spans.
1288
+ * @param columnSpec A range spanning the columns that should be moved.
1289
+ * @param destinationIndex The index that the columns should be moved to. Note that this index is based on the coordinates before the columns are moved. Existing data is shifted right to make room for the moved columns while the source columns are removed from the grid. Therefore, the data may end up at a different index than originally specified. Use 0-index for this method.
1290
+ * @returns This sheet, for chaining.
1291
+ */
1292
+ async moveColumns(e, t) {
1293
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = A(e.getRange(), this._worksheet), i = r, a = {
1294
+ startRow: 0,
1295
+ endRow: this._worksheet.getRowCount() - 1,
1296
+ startColumn: t,
1297
+ endColumn: t
1298
+ };
1299
+ return await this._commandService.executeCommand($e.id, {
1300
+ unitId: o,
1301
+ subUnitId: s,
1302
+ range: r,
1303
+ fromRange: i,
1304
+ toRange: a
1305
+ }), this;
1306
+ }
1307
+ /**
1308
+ * Hides the column or columns in the given range.
1309
+ * @param column The column range to hide.
1310
+ * @returns This sheet, for chaining.
1311
+ */
1312
+ 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, {
1315
+ unitId: t,
1316
+ subUnitId: o,
1317
+ ranges: [s]
1318
+ }), this;
1319
+ }
1320
+ /**
1321
+ * Hides one or more consecutive columns starting at the given index. Use 0-index for this method.
1322
+ * @param columnIndex The starting index of the columns to hide.
1323
+ * @param numColumns The number of columns to hide.
1324
+ * @returns This sheet, for chaining.
1325
+ */
1326
+ async hideColumns(e, t = 1) {
1327
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1328
+ startRow: 0,
1329
+ endRow: this._worksheet.getRowCount() - 1,
1330
+ startColumn: e,
1331
+ endColumn: e + t - 1,
1332
+ rangeType: l.COLUMN
1333
+ };
1334
+ return await this._commandService.executeCommand(ne.id, {
1335
+ unitId: o,
1336
+ subUnitId: s,
1337
+ ranges: [r]
1338
+ }), this;
1339
+ }
1340
+ /**
1341
+ * Unhides the column in the given range.
1342
+ * @param column The range to unhide, if hidden.
1343
+ * @returns This sheet, for chaining.
1344
+ */
1345
+ 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, {
1348
+ unitId: t,
1349
+ subUnitId: o,
1350
+ ranges: [s]
1351
+ }), this;
1352
+ }
1353
+ /**
1354
+ * Unhides one or more consecutive columns starting at the given index. Use 0-index for this method.
1355
+ * @param columnIndex The starting index of the columns to unhide.
1356
+ * @param numColumns The number of columns to unhide.
1357
+ * @returns This sheet, for chaining.
1358
+ */
1359
+ async showColumns(e, t = 1) {
1360
+ const o = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), r = {
1361
+ startRow: 0,
1362
+ endRow: this._worksheet.getRowCount() - 1,
1363
+ startColumn: e,
1364
+ endColumn: e + t - 1,
1365
+ rangeType: l.COLUMN
1366
+ };
1367
+ return await this._commandService.executeCommand(oe.id, {
1368
+ unitId: o,
1369
+ subUnitId: s,
1370
+ ranges: [r]
1371
+ }), this;
1372
+ }
1373
+ /**
1374
+ * Sets the width of the given column in pixels.
1375
+ * @param columnPosition The position of the given column to set.
1376
+ * @param width The width in pixels to set it to.
1377
+ * @returns This sheet, for chaining.
1378
+ */
1379
+ async setColumnWidth(e, t) {
1380
+ return this.setColumnWidths(e, 1, t);
1381
+ }
1382
+ /**
1383
+ * Sets the width of the given columns in pixels.
1384
+ * @param startColumn The starting column position to change.
1385
+ * @param numColumns The number of columns to change.
1386
+ * @param width The width in pixels to set it to.
1387
+ * @returns This sheet, for chaining.
1388
+ */
1389
+ async setColumnWidths(e, t, o) {
1390
+ const s = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = [
1391
+ {
1392
+ startColumn: e,
1393
+ endColumn: e + t - 1,
1394
+ startRow: 0,
1395
+ endRow: this._worksheet.getRowCount() - 1
1396
+ }
1397
+ ];
1398
+ return await this._commandService.executeCommand(Ge.id, {
1399
+ unitId: s,
1400
+ subUnitId: r,
1401
+ ranges: i,
1402
+ value: o
1403
+ }), this;
1404
+ }
1405
+ // #endregion
1406
+ /**
1407
+ * Set custom properties for given columns.
1408
+ * @param custom The custom properties to set.
1409
+ * @returns This sheet, for chaining.
1410
+ */
1411
+ async setColumnCustom(e) {
1412
+ const t = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), s = {};
1413
+ for (const [i, a] of Object.entries(e))
1414
+ s[Number(i)] = {
1415
+ custom: a
1416
+ };
1417
+ const r = {
1418
+ unitId: t,
1419
+ subUnitId: o,
1420
+ columnData: s
1421
+ };
1422
+ return await this._commandService.executeCommand(J.id, r), this;
1423
+ }
1424
+ // #region merge cells
1425
+ /**
1426
+ * Get all merged cells in the current sheet
1427
+ * @returns all merged cells
1428
+ */
1429
+ getMergedRanges() {
1430
+ return this._worksheet.getSnapshot().mergeData.map((t) => this._injector.createInstance(S, this._workbook, this._worksheet, t));
1431
+ }
1432
+ /**
1433
+ * Get the merged cell data of the specified row and column.
1434
+ * @param {number} row The row index.
1435
+ * @param {number} column The column index.
1436
+ * @returns {FRange|undefined} The merged cell data, or undefined if the cell is not merged.
1437
+ */
1438
+ getCellMergeData(e, t) {
1439
+ const s = this._worksheet.getMergedCell(e, t);
1440
+ if (s)
1441
+ return this._injector.createInstance(S, this._workbook, this._worksheet, s);
1442
+ }
1443
+ // #endregion
1444
+ /**
1445
+ * Returns the selected range in the active sheet, or null if there is no active range.
1446
+ * @returns the active range
1447
+ */
1448
+ getActiveRange() {
1449
+ return this._fWorkbook.getActiveRange();
1450
+ }
1451
+ /**
1452
+ * Sets the active selection region for this sheet.
1453
+ * @param range The range to set as the active selection.
1454
+ */
1455
+ setActiveRange(e) {
1456
+ const { unitId: t, sheetId: o } = e.getRange();
1457
+ if (t !== this._workbook.getUnitId() || o !== this._worksheet.getSheetId())
1458
+ throw new Error("Specified range must be part of the sheet.");
1459
+ this._fWorkbook.setActiveRange(e);
1460
+ }
1461
+ /**
1462
+ * Sets the frozen state of the current sheet.
1463
+ * @param freeze - The freeze object containing the parameters for freezing the sheet.
1464
+ * @returns True if the command was successful, false otherwise.
1465
+ */
1466
+ setFreeze(e) {
1467
+ return this._commandService.syncExecuteCommand(qe.id, {
1468
+ ...e,
1469
+ unitId: this._workbook.getUnitId(),
1470
+ subUnitId: this.getSheetId()
1471
+ });
1472
+ }
1473
+ /**
1474
+ * Cancels the frozen state of the current sheet.
1475
+ * @returns True if the command was successful, false otherwise.
1476
+ */
1477
+ cancelFreeze() {
1478
+ return this._commandService.syncExecuteCommand(Ye.id, {
1479
+ unitId: this._workbook.getUnitId(),
1480
+ subUnitId: this.getSheetId()
1481
+ });
1482
+ }
1483
+ /**
1484
+ * Get the freeze state of the current sheet.
1485
+ * @returns The freeze state of the current sheet.
1486
+ */
1487
+ getFreeze() {
1488
+ return this._worksheet.getFreeze();
1489
+ }
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) {
1496
+ const t = this.getFreeze();
1497
+ this.setFreeze({
1498
+ ...t,
1499
+ startColumn: e > 0 ? e : -1,
1500
+ xSplit: e
1501
+ });
1502
+ }
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) {
1509
+ const t = this.getFreeze();
1510
+ this.setFreeze({
1511
+ ...t,
1512
+ startRow: e > 0 ? e : -1,
1513
+ ySplit: e
1514
+ });
1515
+ }
1516
+ /**
1517
+ * Get the number of frozen columns.
1518
+ * @returns The number of frozen columns.
1519
+ * Returns 0 if no columns are frozen.
1520
+ */
1521
+ getFrozenColumns() {
1522
+ const e = this.getFreeze();
1523
+ return e.startColumn === -1 ? 0 : e.startColumn;
1524
+ }
1525
+ /**
1526
+ * Get the number of frozen rows.
1527
+ * @returns The number of frozen rows.
1528
+ * Returns 0 if no rows are frozen.
1529
+ */
1530
+ getFrozenRows() {
1531
+ const e = this.getFreeze();
1532
+ return e.startRow === -1 ? 0 : e.startRow;
1533
+ }
1534
+ /**
1535
+ * Returns true if the sheet's gridlines are hidden; otherwise returns false. Gridlines are visible by default.
1536
+ */
1537
+ hasHiddenGridLines() {
1538
+ return this._worksheet.getConfig().showGridlines === m.FALSE;
1539
+ }
1540
+ /**
1541
+ * Hides or reveals the sheet gridlines.
1542
+ * @param {boolean} hidden If `true`, hide gridlines in this sheet; otherwise show the gridlines.
1543
+ */
1544
+ setHiddenGridlines(e) {
1545
+ return this._commandService.executeCommand(Je.id, {
1546
+ unitId: this._workbook.getUnitId(),
1547
+ subUnitId: this._worksheet.getSheetId(),
1548
+ showGridlines: e ? m.FALSE : m.TRUE
1549
+ });
1550
+ }
1551
+ /**
1552
+ * Subscribe to the cell data change event.
1553
+ * @param callback - The callback function to be executed when the cell data changes.
1554
+ * @returns - A disposable object to unsubscribe from the event.
1555
+ */
1556
+ onCellDataChange(e) {
1557
+ return this._injector.get(R).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 y(s.cellValue));
1561
+ }
1562
+ });
1563
+ }
1564
+ /**
1565
+ * Subscribe to the cell data change event.
1566
+ * @param callback - The callback function to be executed before the cell data changes.
1567
+ * @returns - A disposable object to unsubscribe from the event.
1568
+ */
1569
+ onBeforeCellDataChange(e) {
1570
+ return this._injector.get(R).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 y(s.cellValue));
1574
+ }
1575
+ });
1576
+ }
1577
+ };
1578
+ g = St([
1579
+ T(3, u(f)),
1580
+ T(4, u(de)),
1581
+ T(5, R)
1582
+ ], g);
1583
+ var Ct = Object.defineProperty, It = Object.getOwnPropertyDescriptor, Rt = (n, e, t, o) => {
1584
+ for (var s = o > 1 ? void 0 : o ? It(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 && Ct(e, t, s), s;
1587
+ }, k = (n, e) => (t, o) => e(t, o, n);
1588
+ let P = class extends U {
1589
+ constructor(e, t, o, s, r, i, a, h) {
1590
+ 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();
1593
+ }
1594
+ getId() {
1595
+ return this.id;
1596
+ }
1597
+ getName() {
1598
+ return this._workbook.getName();
1599
+ }
1600
+ /**
1601
+ * save workbook snapshot data, including conditional formatting, data validation, and other plugin data.
1602
+ */
1603
+ save() {
1604
+ return this._resourceLoaderService.saveUnit(this._workbook.getUnitId());
1605
+ }
1606
+ /**
1607
+ * @deprecated use 'save' instead.
1608
+ * @return {*} {IWorkbookData}
1609
+ * @memberof FWorkbook
1610
+ */
1611
+ getSnapshot() {
1612
+ return this._logService.warn("use 'save' instead of 'getSnapshot'"), this.save();
1613
+ }
1614
+ /**
1615
+ * Get the active sheet of the workbook.
1616
+ * @returns The active sheet of the workbook
1617
+ */
1618
+ getActiveSheet() {
1619
+ const e = this._workbook.getActiveSheet();
1620
+ return this._injector.createInstance(g, this, this._workbook, e);
1621
+ }
1622
+ /**
1623
+ * Gets all the worksheets in this workbook
1624
+ * @returns An array of all the worksheets in the workbook
1625
+ */
1626
+ getSheets() {
1627
+ return this._workbook.getSheets().map((e) => this._injector.createInstance(g, this, this._workbook, e));
1628
+ }
1629
+ /**
1630
+ * Create a new worksheet and returns a handle to it.
1631
+ * @param name Name of the new sheet
1632
+ * @param rows How may rows would the new sheet have
1633
+ * @param column How many columns would the new sheet have
1634
+ * @returns The new created sheet
1635
+ */
1636
+ create(e, t, o) {
1637
+ const s = Ie({});
1638
+ s.rowCount = t, s.columnCount = o, s.name = e, s.id = e.toLowerCase().replace(/ /g, "-"), this._commandService.syncExecuteCommand(re.id, {
1639
+ unitId: this.id,
1640
+ index: this._workbook.getSheets().length,
1641
+ sheet: s
1642
+ }), this._commandService.syncExecuteCommand(F.id, {
1643
+ unitId: this.id,
1644
+ subUnitId: this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId()
1645
+ });
1646
+ const r = this._workbook.getActiveSheet();
1647
+ if (!r)
1648
+ throw new Error("No active sheet found");
1649
+ return this._injector.createInstance(g, this, this._workbook, r);
1650
+ }
1651
+ /**
1652
+ * Get a worksheet by sheet id.
1653
+ * @param sheetId The id of the sheet to get.
1654
+ * @return The worksheet with given sheet id
1655
+ */
1656
+ getSheetBySheetId(e) {
1657
+ const t = this._workbook.getSheetBySheetId(e);
1658
+ return t ? this._injector.createInstance(g, this, this._workbook, t) : null;
1659
+ }
1660
+ /**
1661
+ * Get a worksheet by sheet name.
1662
+ * @param name The name of the sheet to get.
1663
+ * @returns The worksheet with given sheet name
1664
+ */
1665
+ getSheetByName(e) {
1666
+ const t = this._workbook.getSheetBySheetName(e);
1667
+ return t ? this._injector.createInstance(g, this, this._workbook, t) : null;
1668
+ }
1669
+ /**
1670
+ * Sets the given worksheet to be the active worksheet in the workbook.
1671
+ * @param sheet The worksheet to set as the active worksheet.
1672
+ * @returns The active worksheet
1673
+ */
1674
+ setActiveSheet(e) {
1675
+ return this._commandService.syncExecuteCommand(F.id, {
1676
+ unitId: this.id,
1677
+ subUnitId: e.getSheetId()
1678
+ }), e;
1679
+ }
1680
+ /**
1681
+ * Inserts a new worksheet into the workbook.
1682
+ * Using a default sheet name. The new sheet becomes the active sheet
1683
+ * @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
1691
+ });
1692
+ const o = this._workbook.getActiveSheet();
1693
+ if (!o)
1694
+ throw new Error("No active sheet found");
1695
+ return this._injector.createInstance(g, this, this._workbook, o);
1696
+ }
1697
+ /**
1698
+ * Deletes the specified worksheet.
1699
+ * @param sheet The worksheet to delete.
1700
+ */
1701
+ deleteSheet(e) {
1702
+ const t = this.id, o = e.getSheetId();
1703
+ this._commandService.executeCommand(Ke.id, {
1704
+ unitId: t,
1705
+ subUnitId: o
1706
+ });
1707
+ }
1708
+ // #region editing
1709
+ undo() {
1710
+ return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(Re.id);
1711
+ }
1712
+ redo() {
1713
+ return this._univerInstanceService.focusUnit(this.id), this._commandService.executeCommand(ve.id);
1714
+ }
1715
+ /**
1716
+ * Register a callback that will be triggered before invoking a command targeting the Univer sheet.
1717
+ * @param callback the callback.
1718
+ * @returns A function to dispose the listening.
1719
+ */
1720
+ onBeforeCommandExecute(e) {
1721
+ return this._commandService.beforeCommandExecuted((t) => {
1722
+ var o;
1723
+ ((o = t.params) == null ? void 0 : o.unitId) === this.id && e(t);
1724
+ });
1725
+ }
1726
+ /**
1727
+ * Register a callback that will be triggered when a command is invoked targeting the Univer sheet.
1728
+ * @param callback the callback.
1729
+ * @returns A function to dispose the listening.
1730
+ */
1731
+ onCommandExecuted(e) {
1732
+ return this._commandService.onCommandExecuted((t) => {
1733
+ var o;
1734
+ ((o = t.params) == null ? void 0 : o.unitId) === this.id && e(t);
1735
+ });
1736
+ }
1737
+ onSelectionChange(e) {
1738
+ return fe(
1739
+ 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([]));
1741
+ })
1742
+ );
1743
+ }
1744
+ /**
1745
+ * Used to modify the editing permissions of the workbook. When the value is false, editing is not allowed.
1746
+ * @param {boolean} value editable value want to set
1747
+ */
1748
+ setEditable(e) {
1749
+ const t = new ce(this._workbook.getUnitId());
1750
+ this._permissionService.getPermissionPoint(t.id) || this._permissionService.addPermissionPoint(t), this._permissionService.updatePermissionPoint(t.id, e);
1751
+ }
1752
+ /**
1753
+ * Sets the active selection region for this sheet.
1754
+ * @param range The range to set as the active selection.
1755
+ */
1756
+ setActiveRange(e) {
1757
+ const t = this.getActiveSheet(), o = e.getRange().sheetId || t.getSheetId(), s = o ? this._workbook.getSheetBySheetId(o) : this._workbook.getActiveSheet(!0);
1758
+ if (!s)
1759
+ throw new Error("No active sheet found");
1760
+ s.getSheetId() !== t.getSheetId() && this.setActiveSheet(this._injector.createInstance(g, this, this._workbook, s));
1761
+ const r = {
1762
+ unitId: this.getId(),
1763
+ subUnitId: o,
1764
+ selections: [e].map((i) => ({ range: i.getRange(), primary: Qe(i.getRange(), s), style: null }))
1765
+ };
1766
+ this._commandService.syncExecuteCommand(Xe.id, r);
1767
+ }
1768
+ /**
1769
+ * Returns the selected range in the active sheet, or null if there is no active range.
1770
+ * @returns the active range
1771
+ */
1772
+ 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;
1775
+ }
1776
+ };
1777
+ P = Rt([
1778
+ k(1, u(f)),
1779
+ k(2, u(Ce)),
1780
+ k(3, u(de)),
1781
+ k(4, ae),
1782
+ k(5, R),
1783
+ k(6, ie),
1784
+ k(7, be)
1785
+ ], P);
1786
+ class vt extends he {
1787
+ createUniverSheet(e) {
1788
+ const o = this._injector.get(ae).createUnit(O.UNIVER_SHEET, e);
1789
+ return this._injector.createInstance(P, o);
1790
+ }
1791
+ getActiveWorkbook() {
1792
+ const e = this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET);
1793
+ return e ? this._injector.createInstance(P, e) : null;
1794
+ }
1795
+ getPermission() {
1796
+ return this._injector.createInstance(V);
1797
+ }
1798
+ }
1799
+ he.extend(vt);
1800
+ export {
1801
+ V as FPermission,
1802
+ S as FRange,
1803
+ L as FSelection,
1804
+ P as FWorkbook,
1805
+ g as FWorksheet
1806
+ };