@univerjs/sheets 0.4.1 → 0.4.2-nightly.202410301606

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