@univerjs/sheets 0.20.1 → 0.21.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 (58) hide show
  1. package/lib/cjs/facade.js +8352 -1
  2. package/lib/cjs/index.js +21494 -2
  3. package/lib/cjs/locale/ca-ES.js +17 -1
  4. package/lib/cjs/locale/en-US.js +32 -1
  5. package/lib/cjs/locale/es-ES.js +17 -1
  6. package/lib/cjs/locale/fa-IR.js +17 -1
  7. package/lib/cjs/locale/fr-FR.js +17 -1
  8. package/lib/cjs/locale/ja-JP.js +17 -1
  9. package/lib/cjs/locale/ko-KR.js +17 -1
  10. package/lib/cjs/locale/ru-RU.js +17 -1
  11. package/lib/cjs/locale/sk-SK.js +17 -1
  12. package/lib/cjs/locale/vi-VN.js +17 -1
  13. package/lib/cjs/locale/zh-CN.js +17 -1
  14. package/lib/cjs/locale/zh-TW.js +17 -1
  15. package/lib/es/facade.js +8314 -1
  16. package/lib/es/index.js +20973 -2
  17. package/lib/es/locale/ca-ES.js +16 -1
  18. package/lib/es/locale/en-US.js +31 -1
  19. package/lib/es/locale/es-ES.js +16 -1
  20. package/lib/es/locale/fa-IR.js +16 -1
  21. package/lib/es/locale/fr-FR.js +16 -1
  22. package/lib/es/locale/ja-JP.js +16 -1
  23. package/lib/es/locale/ko-KR.js +16 -1
  24. package/lib/es/locale/ru-RU.js +16 -1
  25. package/lib/es/locale/sk-SK.js +16 -1
  26. package/lib/es/locale/vi-VN.js +16 -1
  27. package/lib/es/locale/zh-CN.js +16 -1
  28. package/lib/es/locale/zh-TW.js +16 -1
  29. package/lib/facade.js +8314 -1
  30. package/lib/index.js +20973 -2
  31. package/lib/locale/ca-ES.js +16 -1
  32. package/lib/locale/en-US.js +31 -1
  33. package/lib/locale/es-ES.js +16 -1
  34. package/lib/locale/fa-IR.js +16 -1
  35. package/lib/locale/fr-FR.js +16 -1
  36. package/lib/locale/ja-JP.js +16 -1
  37. package/lib/locale/ko-KR.js +16 -1
  38. package/lib/locale/ru-RU.js +16 -1
  39. package/lib/locale/sk-SK.js +16 -1
  40. package/lib/locale/vi-VN.js +16 -1
  41. package/lib/locale/zh-CN.js +16 -1
  42. package/lib/locale/zh-TW.js +16 -1
  43. package/lib/types/commands/commands/remove-row-col.command.d.ts +2 -1
  44. package/lib/types/controllers/permission/sheet-permission-check.controller.d.ts +11 -12
  45. package/lib/types/facade/f-univer.d.ts +0 -7
  46. package/lib/types/facade/f-workbook.d.ts +0 -13
  47. package/lib/types/facade/index.d.ts +2 -2
  48. package/lib/types/facade/permission/f-range-permission.d.ts +31 -228
  49. package/lib/types/facade/permission/f-range-protection-rule.d.ts +157 -46
  50. package/lib/types/facade/permission/f-workbook-permission.d.ts +51 -129
  51. package/lib/types/facade/permission/f-worksheet-permission.d.ts +111 -199
  52. package/lib/types/facade/permission/permission-types.d.ts +20 -125
  53. package/lib/types/facade/permission/util.d.ts +40 -0
  54. package/lib/types/services/permission/range-permission/util.d.ts +2 -1
  55. package/lib/umd/facade.js +1 -1
  56. package/lib/umd/index.js +2 -2
  57. package/package.json +9 -9
  58. package/lib/types/facade/f-permission.d.ts +0 -426
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "private": false,
5
5
  "description": "UniverSheet normal base-sheets",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -63,18 +63,18 @@
63
63
  "rxjs": ">=7.0.0"
64
64
  },
65
65
  "dependencies": {
66
- "@univerjs/protocol": "0.1.48",
67
- "@univerjs/core": "0.20.1",
68
- "@univerjs/engine-render": "0.20.1",
69
- "@univerjs/engine-formula": "0.20.1",
70
- "@univerjs/rpc": "0.20.1"
66
+ "@univerjs/core": "0.21.0",
67
+ "@univerjs/engine-formula": "0.21.0",
68
+ "@univerjs/protocol": "0.21.0",
69
+ "@univerjs/engine-render": "0.21.0",
70
+ "@univerjs/rpc": "0.21.0"
71
71
  },
72
72
  "devDependencies": {
73
73
  "rxjs": "^7.8.2",
74
74
  "typescript": "^6.0.2",
75
- "vitest": "^4.1.1",
76
- "@univerjs/network": "0.20.1",
77
- "@univerjs-infra/shared": "0.20.1"
75
+ "vitest": "^4.1.4",
76
+ "@univerjs-infra/shared": "0.21.0",
77
+ "@univerjs/network": "0.21.0"
78
78
  },
79
79
  "scripts": {
80
80
  "test": "vitest run",
@@ -1,426 +0,0 @@
1
- /**
2
- * Copyright 2023-present DreamNum Co., Ltd.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import type { RangePermissionPointConstructor, WorkbookPermissionPointConstructor, WorkSheetPermissionPointConstructor } from '@univerjs/core';
17
- import type { Observable } from 'rxjs';
18
- import type { FRange } from './f-range';
19
- import type { IRangeProtectionOptions, IWorksheetProtectionOptions } from './permission/permission-types';
20
- import { IAuthzIoService, ICommandService, Injector, IPermissionService } from '@univerjs/core';
21
- import { FBase } from '@univerjs/core/facade';
22
- import { RangeProtectionRuleModel, WorkbookEditablePermission, WorkbookPermissionService, WorksheetEditPermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetViewPermission } from '@univerjs/sheets';
23
- /**
24
- * @description Used to generate permission instances to control permissions for the entire workbook
25
- * @deprecated This class is deprecated. Use the new permission API instead:
26
- * - For workbook-level permissions, use `workbook.getWorkbookPermission()`
27
- * - For worksheet-level permissions, use `worksheet.getWorksheetPermission()`
28
- * - For range-level permissions, use `range.getRangePermission()`
29
- *
30
- * The new API provides:
31
- * - More intuitive and type-safe interfaces
32
- * - Better support for RxJS Observable streams
33
- * - Enum-based permission points instead of class constructors
34
- * - Simplified collaborator management
35
- * - Mode-based permission settings (viewer, editor, owner, etc.)
36
- *
37
- * Migration examples:
38
- * ```ts
39
- * // Old API
40
- * const permission = workbook.getPermission();
41
- * await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
42
- *
43
- * // New API
44
- * const worksheet = workbook.getSheetBySheetId(subUnitId);
45
- * const permission = worksheet.getWorksheetPermission();
46
- * await permission.protectRanges([{ ranges, options: { name: 'Protected', allowEdit: false } }]);
47
- * ```
48
- * @hideconstructor
49
- */
50
- export declare class FPermission extends FBase {
51
- protected readonly _injector: Injector;
52
- protected readonly _commandService: ICommandService;
53
- protected readonly _permissionService: IPermissionService;
54
- protected readonly _worksheetProtectionRuleModel: WorksheetProtectionRuleModel;
55
- protected readonly _rangeProtectionRuleModel: RangeProtectionRuleModel;
56
- protected readonly _worksheetProtectionPointRuleModel: WorksheetProtectionPointModel;
57
- protected readonly _workbookPermissionService: WorkbookPermissionService;
58
- protected readonly _authzIoService: IAuthzIoService;
59
- /**
60
- * Permission point definition, can read the point constructor want to modify from here
61
- */
62
- permissionPointsDefinition: {
63
- WorkbookCommentPermission: typeof import("@univerjs/sheets").WorkbookCommentPermission;
64
- WorkbookCopyPermission: typeof import("@univerjs/sheets").WorkbookCopyPermission;
65
- WorkbookCreateProtectPermission: typeof import("@univerjs/sheets").WorkbookCreateProtectPermission;
66
- WorkbookCreateSheetPermission: typeof import("@univerjs/sheets").WorkbookCreateSheetPermission;
67
- WorkbookDeleteSheetPermission: typeof import("@univerjs/sheets").WorkbookDeleteSheetPermission;
68
- WorkbookDuplicatePermission: typeof import("@univerjs/sheets").WorkbookDuplicatePermission;
69
- WorkbookEditablePermission: typeof WorkbookEditablePermission;
70
- WorkbookExportPermission: typeof import("@univerjs/sheets").WorkbookExportPermission;
71
- WorkbookHideSheetPermission: typeof import("@univerjs/sheets").WorkbookHideSheetPermission;
72
- WorkbookManageCollaboratorPermission: typeof import("@univerjs/sheets").WorkbookManageCollaboratorPermission;
73
- WorkbookMoveSheetPermission: typeof import("@univerjs/sheets").WorkbookMoveSheetPermission;
74
- WorkbookPrintPermission: typeof import("@univerjs/sheets").WorkbookPrintPermission;
75
- WorkbookRecoverHistoryPermission: typeof import("@univerjs/sheets").WorkbookRecoverHistoryPermission;
76
- WorkbookRenameSheetPermission: typeof import("@univerjs/sheets").WorkbookRenameSheetPermission;
77
- WorkbookSharePermission: typeof import("@univerjs/sheets").WorkbookSharePermission;
78
- WorkbookViewHistoryPermission: typeof import("@univerjs/sheets").WorkbookViewHistoryPermission;
79
- WorkbookViewPermission: typeof import("@univerjs/sheets").WorkbookViewPermission;
80
- WorksheetCopyPermission: typeof import("@univerjs/sheets").WorksheetCopyPermission;
81
- WorksheetDeleteColumnPermission: typeof import("@univerjs/sheets").WorksheetDeleteColumnPermission;
82
- WorksheetDeleteProtectionPermission: typeof import("@univerjs/sheets").WorksheetDeleteProtectionPermission;
83
- WorksheetDeleteRowPermission: typeof import("@univerjs/sheets").WorksheetDeleteRowPermission;
84
- WorksheetEditExtraObjectPermission: typeof import("@univerjs/sheets").WorksheetEditExtraObjectPermission;
85
- WorksheetEditPermission: typeof WorksheetEditPermission;
86
- WorksheetFilterPermission: typeof import("@univerjs/sheets").WorksheetFilterPermission;
87
- WorksheetInsertColumnPermission: typeof import("@univerjs/sheets").WorksheetInsertColumnPermission;
88
- WorksheetInsertHyperlinkPermission: typeof import("@univerjs/sheets").WorksheetInsertHyperlinkPermission;
89
- WorksheetInsertRowPermission: typeof import("@univerjs/sheets").WorksheetInsertRowPermission;
90
- WorksheetManageCollaboratorPermission: typeof import("@univerjs/sheets").WorksheetManageCollaboratorPermission;
91
- WorksheetPivotTablePermission: typeof import("@univerjs/sheets").WorksheetPivotTablePermission;
92
- WorksheetSetCellStylePermission: typeof import("@univerjs/sheets").WorksheetSetCellStylePermission;
93
- WorksheetSetCellValuePermission: typeof import("@univerjs/sheets").WorksheetSetCellValuePermission;
94
- WorksheetSetColumnStylePermission: typeof import("@univerjs/sheets").WorksheetSetColumnStylePermission;
95
- WorksheetSetRowStylePermission: typeof import("@univerjs/sheets").WorksheetSetRowStylePermission;
96
- WorksheetSortPermission: typeof import("@univerjs/sheets").WorksheetSortPermission;
97
- WorksheetViewPermission: typeof WorksheetViewPermission;
98
- RangeProtectionPermissionEditPoint: typeof import("@univerjs/sheets").RangeProtectionPermissionEditPoint;
99
- RangeProtectionPermissionViewPoint: typeof import("@univerjs/sheets").RangeProtectionPermissionViewPoint;
100
- };
101
- /**
102
- * An observable object used to monitor permission change events within a range, thereby triggering corresponding subsequent processing.
103
- */
104
- rangeRuleChangedAfterAuth$: Observable<string>;
105
- /**
106
- * An observable object used to monitor permission change events within a worksheet, thereby triggering corresponding subsequent processing.
107
- */
108
- sheetRuleChangedAfterAuth$: Observable<string>;
109
- /**
110
- * An observable object used to monitor the initialization state changes of unit permissions.
111
- */
112
- unitPermissionInitStateChange$: Observable<boolean>;
113
- constructor(_injector: Injector, _commandService: ICommandService, _permissionService: IPermissionService, _worksheetProtectionRuleModel: WorksheetProtectionRuleModel, _rangeProtectionRuleModel: RangeProtectionRuleModel, _worksheetProtectionPointRuleModel: WorksheetProtectionPointModel, _workbookPermissionService: WorkbookPermissionService, _authzIoService: IAuthzIoService);
114
- /**
115
- * Configures a specific permission point for a workbook.
116
- * This function sets or updates a permission point for a workbook identified by `unitId`.
117
- * It creates a new permission point if it does not already exist, and updates the point with the provided value.
118
- * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
119
- * @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.
120
- * @param {boolean} value - The boolean value to determine whether the permission point is enabled or disabled.
121
- *
122
- * @example
123
- * ```typescript
124
- * const workbook = univerAPI.getActiveWorkbook();
125
- * const permission = workbook.getPermission();
126
- * const unitId = workbook.getId();
127
- * permission.setWorkbookPermissionPoint(unitId, permission.permissionPointsDefinition.WorkbookEditablePermission, false)
128
- * ```
129
- */
130
- setWorkbookPermissionPoint(unitId: string, FPointClass: WorkbookPermissionPointConstructor, value: boolean): void;
131
- /**
132
- * Check if a specific permission point is enabled for a workbook.
133
- * @param unitId - The unique identifier of the workbook.
134
- * @param FPointClass - The constructor for the permission point class.
135
- * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
136
- * @example
137
- * ```typescript
138
- * const workbook = univerAPI.getActiveWorkbook();
139
- * const permission = workbook.getPermission();
140
- * const unitId = workbook.getId();
141
- * // Check if the workbook is editable
142
- * const isEditable = permission.checkWorkbookPermissionPoint(unitId, permission.permissionPointsDefinition.WorkbookEditablePermission);
143
- * console.log('Workbook is editable:', isEditable);
144
- * ```
145
- */
146
- checkWorkbookPermissionPoint(unitId: string, FPointClass: WorkbookPermissionPointConstructor): boolean | undefined;
147
- /**
148
- * This function is used to set whether the workbook can be edited
149
- * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
150
- * @param {boolean} value - A value that controls whether the workbook can be edited
151
- *
152
- * @example
153
- * ```typescript
154
- * const workbook = univerAPI.getActiveWorkbook();
155
- * const permission = workbook.getPermission();
156
- * const unitId = workbook.getId();
157
- * permission.setWorkbookEditPermission(unitId, false);
158
- * ```
159
- */
160
- setWorkbookEditPermission(unitId: string, value: boolean): void;
161
- /**
162
- * This function is used to add a base permission for a worksheet.
163
- * Note that after adding, only the background mask of the permission module will be rendered. If you want to modify the function permissions,
164
- * you need to modify the permission points with the permissionId returned by this function.
165
- * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
166
- * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
167
- * @param {IWorksheetProtectionOptions} options - Optional protection options including allowed users and name.
168
- * @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`.
169
- *
170
- * @example
171
- * ```typescript
172
- * const workbook = univerAPI.getActiveWorkbook();
173
- * const permission = workbook.getPermission();
174
- * const unitId = workbook.getId();
175
- * const worksheet = workbook.getActiveSheet();
176
- * const subUnitId = worksheet.getSheetId();
177
- * // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes.
178
- * // For details, please see the example of the **`setWorksheetPermissionPoint`** API.
179
- * const permissionId = await permission.addWorksheetBasePermission(unitId, subUnitId, {
180
- * allowedUsers: ['user1', 'user2'],
181
- * name: 'My Protection'
182
- * })
183
- * // Can still edit and read it.
184
- * console.log('debugger', permissionId)
185
- * ```
186
- */
187
- addWorksheetBasePermission(unitId: string, subUnitId: string, options?: IWorksheetProtectionOptions): Promise<string | undefined>;
188
- /**
189
- * Delete the entire table protection set for the worksheet and reset the point permissions of the worksheet to true
190
- * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
191
- * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
192
- *
193
- * @example
194
- * ```typescript
195
- * const workbook = univerAPI.getActiveWorkbook();
196
- * const permission = workbook.getPermission();
197
- * const unitId = workbook.getId();
198
- * const worksheet = workbook.getActiveSheet();
199
- * const subUnitId = worksheet.getSheetId();
200
- * permission.removeWorksheetPermission(unitId, subUnitId);
201
- * ```
202
- */
203
- removeWorksheetPermission(unitId: string, subUnitId: string): void;
204
- /**
205
- * Sets the worksheet permission point by updating or adding the permission point for the worksheet.
206
- * If the worksheet doesn't have a base permission, it creates one to used render
207
- * @param {string} unitId - The unique identifier of the workbook.
208
- * @param {string} subUnitId - The unique identifier of the worksheet.
209
- * @param {WorkSheetPermissionPointConstructor} FPointClass - The constructor for the permission point class.
210
- * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
211
- * @param {boolean} value - The new permission value to be set for the worksheet.
212
- * @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`.
213
- *
214
- * @example
215
- * ```typescript
216
- * const workbook = univerAPI.getActiveWorkbook();
217
- * const permission = workbook.getPermission();
218
- * const unitId = workbook.getId();
219
- * const worksheet = workbook.getActiveSheet();
220
- * const subUnitId = worksheet.getSheetId();
221
- * const permissionId = await permission.addWorksheetBasePermission(unitId, subUnitId)
222
- * // After this line of code , the worksheet will no longer be editable
223
- * permission.setWorksheetPermissionPoint(unitId, subUnitId, permission.permissionPointsDefinition.WorksheetEditPermission, false);
224
- * ```
225
- */
226
- setWorksheetPermissionPoint(unitId: string, subUnitId: string, FPointClass: WorkSheetPermissionPointConstructor, value: boolean): Promise<string | undefined>;
227
- /**
228
- * Check if a specific permission point is enabled for a worksheet.
229
- * @param unitId - The unique identifier of the workbook.
230
- * @param subUnitId - The unique identifier of the worksheet.
231
- * @param FPointClass - The constructor for the permission point class.
232
- * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
233
- * @returns {boolean | undefined} - Returns true if the permission point is enabled, false if it is disabled, or undefined if the permission point does not exist.
234
- * @example
235
- * ```typescript
236
- * const workbook = univerAPI.getActiveWorkbook();
237
- * const permission = workbook.getPermission();
238
- * const unitId = workbook.getId();
239
- * const worksheet = workbook.getActiveSheet();
240
- * const subUnitId = worksheet.getSheetId();
241
- * // Check if the worksheet is editable
242
- * const isEditable = permission.checkWorksheetPermissionPoint(unitId, subUnitId, permission.permissionPointsDefinition.WorksheetEditPermission);
243
- * console.log('Worksheet is editable:', isEditable);
244
- * ```
245
- */
246
- checkWorksheetPermissionPoint(unitId: string, subUnitId: string, FPointClass: WorkSheetPermissionPointConstructor): boolean | undefined;
247
- /**
248
- * Adds a range protection to the worksheet.
249
- * Note that after adding, only the background mask of the permission module will be rendered. If you want to modify the function permissions,
250
- * you need to modify the permission points with the permissionId returned by this function.
251
- * @deprecated Use `worksheet.getWorksheetPermission().protectRanges()` instead
252
- * @param {string} unitId - The unique identifier of the workbook.
253
- * @param {string} subUnitId - The unique identifier of the worksheet.
254
- * @param {FRange[]} ranges - The ranges to be protected.
255
- * @param {IRangeProtectionOptions} options - Optional protection options including allowed users and name.
256
- * @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
257
- *
258
- * @example
259
- * ```typescript
260
- * // Old API
261
- * const workbook = univerAPI.getActiveWorkbook();
262
- * const permission = workbook.getPermission();
263
- * const unitId = workbook.getId();
264
- * const worksheet = workbook.getActiveSheet();
265
- * const subUnitId = worksheet.getSheetId();
266
- * const range = worksheet.getRange('A1:B2');
267
- * const ranges = [];
268
- * ranges.push(range);
269
- * const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges, {
270
- * name: 'Protected Area',
271
- * allowEdit: false
272
- * });
273
- * const {permissionId, ruleId} = res;
274
- * console.log('debugger', permissionId, ruleId);
275
- *
276
- * // New API (recommended)
277
- * const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
278
- * const permission = worksheet.getWorksheetPermission();
279
- * const range = worksheet.getRange('A1:B2');
280
- * await permission.protectRanges([{
281
- * ranges: [range],
282
- * options: { name: 'Protected Area', allowEdit: false }
283
- * }]);
284
- * ```
285
- */
286
- addRangeBaseProtection(unitId: string, subUnitId: string, ranges: FRange[], options?: IRangeProtectionOptions): Promise<{
287
- permissionId: string;
288
- ruleId: string;
289
- } | undefined>;
290
- /**
291
- * Determine view state from range protection options
292
- * @private
293
- */
294
- private _determineRangeViewState;
295
- /**
296
- * Determine edit state from range protection options
297
- * @private
298
- */
299
- private _determineRangeEditState;
300
- /**
301
- * Removes the range protection from the worksheet.
302
- * @deprecated Use `worksheet.getWorksheetPermission().unprotectRules()` instead
303
- * @param {string} unitId - The unique identifier of the workbook.
304
- * @param {string} subUnitId - The unique identifier of the worksheet.
305
- * @param {string[]} ruleIds - The rule IDs of the range protection to be removed.
306
- *
307
- * @example
308
- * ```typescript
309
- * // Old API
310
- * const workbook = univerAPI.getActiveWorkbook();
311
- * const permission = workbook.getPermission();
312
- * const unitId = workbook.getId();
313
- * const worksheet = workbook.getActiveSheet();
314
- * const subUnitId = worksheet.getSheetId();
315
- * const range = worksheet.getRange('A1:B2');
316
- * const ranges = [];
317
- * ranges.push(range);
318
- * const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
319
- * const ruleId = res.ruleId;
320
- * permission.removeRangeProtection(unitId, subUnitId, [ruleId]);
321
- *
322
- * // New API (recommended)
323
- * const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
324
- * const permission = worksheet.getWorksheetPermission();
325
- * await permission.unprotectRules([ruleId]);
326
- * ```
327
- */
328
- removeRangeProtection(unitId: string, subUnitId: string, ruleIds: string[]): void;
329
- /**
330
- * Modify the permission points of a custom area
331
- * @param {string} unitId - The unique identifier of the workbook.
332
- * @param {string} subUnitId - The unique identifier of the worksheet within the workbook.
333
- * @param {string} permissionId - The unique identifier of the permission that controls access to the range.
334
- * @param {RangePermissionPointConstructor} FPointClass - The constructor for the range permission point class.
335
- * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
336
- * @param {boolean} value - The new permission value to be set for the range (e.g., true for allowing access, false for restricting access).
337
- *
338
- * @example
339
- * ```typescript
340
- * const workbook = univerAPI.getActiveWorkbook();
341
- * const permission = workbook.getPermission();
342
- * const unitId = workbook.getId();
343
- * const worksheet = workbook.getActiveSheet();
344
- * const subUnitId = worksheet.getSheetId();
345
- * const range = worksheet.getRange('A1:B2');
346
- * const ranges = [];
347
- * ranges.push(range);
348
- * // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes.
349
- * // For details, please see the example of the **`setRangeProtectionPermissionPoint`** API.
350
- * const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
351
- * const {permissionId, ruleId} = res;
352
- * // After passing the following line of code, the range set above will become uneditable
353
- * permission.setRangeProtectionPermissionPoint(unitId,subUnitId,permissionId, permission.permissionPointsDefinition.RangeProtectionPermissionEditPoint, false);
354
- * ```
355
- */
356
- setRangeProtectionPermissionPoint(unitId: string, subUnitId: string, permissionId: string, FPointClass: RangePermissionPointConstructor, value: boolean): void;
357
- /**
358
- * Sets the ranges for range protection in a worksheet.
359
- *
360
- * This method finds the rule by unitId, subUnitId, and ruleId, and updates the rule with the provided ranges.
361
- * It checks for overlaps with existing ranges in the same subunit and shows an error message if any overlap is detected.
362
- * If no overlap is found, it executes the command to update the range protection with the new ranges.
363
- * @param {string} unitId - The unique identifier of the workbook.
364
- * @param {string} subUnitId - The unique identifier of the worksheet within the workbook.
365
- * @param {string} ruleId - The ruleId of the range protection rule that is being updated.
366
- * @param {FRange[]} ranges - The array of new ranges to be set for the range protection rule.
367
- *
368
- * @example
369
- * ```typescript
370
- * const workbook = univerAPI.getActiveWorkbook();
371
- * const permission = workbook.getPermission();
372
- * const unitId = workbook.getId();
373
- * const worksheet = workbook.getActiveSheet();
374
- * const subUnitId = worksheet.getSheetId();
375
- * const range = worksheet.getRange('A1:B2');
376
- * const ranges = [];
377
- * ranges.push(range);
378
- * const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
379
- * const {permissionId, ruleId} = res;
380
- * const newRange = worksheet.getRange('C1:D2');
381
- * permission.setRangeProtectionRanges(unitId, subUnitId, ruleId, [newRange]);
382
- * ```
383
- */
384
- setRangeProtectionRanges(unitId: string, subUnitId: string, ruleId: string, ranges: FRange[]): void;
385
- /**
386
- * Get the permission information for a specific cell in a worksheet.
387
- * @param {string} unitId - The unique identifier of the workbook.
388
- * @param {string} subUnitId - The unique identifier of the worksheet within the workbook.
389
- * @param {number} row - The row index of the cell.
390
- * @param {number} column - The column index of the cell.
391
- * @returns {{ permissionId: string, ruleId: string } | undefined} - Returns an object containing the `permissionId` and `ruleId` if the cell is protected by a range protection rule. If no protection is found, it returns `undefined`.
392
- *
393
- * @example
394
- * ```typescript
395
- * const fWorkbook = univerAPI.getActiveWorkbook();
396
- * const fWorksheet = fWorkbook.getActiveSheet();
397
- * const permission = fWorkbook.getPermission();
398
- * const unitId = fWorkbook.getId();
399
- * const subUnitId = fWorksheet.getSheetId();
400
- *
401
- * // Get the permission information for cell C3
402
- * const cell = fWorksheet.getRange('C3');
403
- * const permissionInfo = permission.getPermissionInfoWithCell(
404
- * unitId,
405
- * subUnitId,
406
- * cell.getRow(),
407
- * cell.getColumn()
408
- * );
409
- * console.log(permissionInfo);
410
- *
411
- * // If the cell is protected, you can remove the protection like this:
412
- * if (permissionInfo) {
413
- * const { ruleId } = permissionInfo;
414
- *
415
- * // After 2 seconds, remove the protection for the cell
416
- * setTimeout(() => {
417
- * permission.removeRangeProtection(unitId, subUnitId, [ruleId]);
418
- * }, 2000);
419
- * }
420
- * ```
421
- */
422
- getPermissionInfoWithCell(unitId: string, subUnitId: string, row: number, column: number): {
423
- permissionId: string;
424
- ruleId: string;
425
- } | undefined;
426
- }