@univerjs/sheets 0.11.0 → 0.12.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.
@@ -0,0 +1,270 @@
1
+ import { IUser } from '@univerjs/protocol';
2
+ import { Observable } from 'rxjs';
3
+ import { ICollaborator, IWorkbookPermission, UnsubscribeFn, WorkbookMode, WorkbookPermissionSnapshot, UnitRole, WorkbookPermissionPoint } from './permission-types';
4
+ import { IAuthzIoService, Injector, IPermissionService } from '@univerjs/core';
5
+ /**
6
+ * Implementation class for WorkbookPermission
7
+ * Provides workbook-level permission control
8
+ *
9
+ * @hideconstructor
10
+ */
11
+ export declare class FWorkbookPermission implements IWorkbookPermission {
12
+ private readonly _unitId;
13
+ private readonly _injector;
14
+ private readonly _permissionService;
15
+ private readonly _authzIoService;
16
+ private readonly _permissionSubject;
17
+ private readonly _collaboratorChangeSubject;
18
+ /**
19
+ * Observable stream of permission snapshot changes (BehaviorSubject)
20
+ * Emits immediately on subscription with current state, then on any permission point change
21
+ */
22
+ readonly permission$: Observable<WorkbookPermissionSnapshot>;
23
+ /**
24
+ * Observable stream of individual permission point changes
25
+ * Emits when a specific permission point value changes
26
+ */
27
+ readonly pointChange$: Observable<{
28
+ point: WorkbookPermissionPoint;
29
+ value: boolean;
30
+ oldValue: boolean;
31
+ }>;
32
+ /**
33
+ * Observable stream of collaborator changes
34
+ * Emits when collaborators are added, updated, or removed
35
+ */
36
+ readonly collaboratorChange$: Observable<{
37
+ type: 'add' | 'update' | 'delete';
38
+ collaborator: ICollaborator;
39
+ }>;
40
+ private _subscriptions;
41
+ constructor(_unitId: string, _injector: Injector, _permissionService: IPermissionService, _authzIoService: IAuthzIoService);
42
+ /**
43
+ * Create permission snapshot stream from IPermissionService
44
+ * @private
45
+ */
46
+ private _createPermissionStream;
47
+ /**
48
+ * Create point change stream from IPermissionService
49
+ * @private
50
+ */
51
+ private _createPointChangeStream;
52
+ /**
53
+ * Extract WorkbookPermissionPoint type from permission point ID
54
+ * @private
55
+ */
56
+ private _extractWorkbookPointType;
57
+ /**
58
+ * Build permission snapshot
59
+ */
60
+ private _buildSnapshot;
61
+ /**
62
+ * Listen to permission point changes
63
+ /**
64
+ * Set permission mode for the workbook.
65
+ * @param {WorkbookMode} mode The permission mode to set ('owner' | 'editor' | 'viewer' | 'commenter').
66
+ * @returns {Promise<void>} A promise that resolves when the mode is set.
67
+ * @example
68
+ * ```ts
69
+ * const workbook = univerAPI.getActiveWorkbook();
70
+ * const permission = workbook?.getWorkbookPermission();
71
+ * await permission?.setMode('editor');
72
+ * ```
73
+ */
74
+ setMode(mode: WorkbookMode): Promise<void>;
75
+ /**
76
+ * Get permission configuration for a specific mode
77
+ * @private
78
+ */
79
+ private _getModePermissions;
80
+ /**
81
+ * Batch set multiple permission points efficiently
82
+ * @private
83
+ */
84
+ private _batchSetPermissionPoints;
85
+ /**
86
+ * Set the workbook to read-only mode (viewer mode).
87
+ * @returns {Promise<void>} A promise that resolves when the mode is set.
88
+ * @example
89
+ * ```ts
90
+ * const workbook = univerAPI.getActiveWorkbook();
91
+ * const permission = workbook?.getWorkbookPermission();
92
+ * await permission?.setReadOnly();
93
+ * ```
94
+ */
95
+ setReadOnly(): Promise<void>;
96
+ /**
97
+ * Set the workbook to editable mode (editor mode).
98
+ * @returns {Promise<void>} A promise that resolves when the mode is set.
99
+ * @example
100
+ * ```ts
101
+ * const workbook = univerAPI.getActiveWorkbook();
102
+ * const permission = workbook?.getWorkbookPermission();
103
+ * await permission?.setEditable();
104
+ * ```
105
+ */
106
+ setEditable(): Promise<void>;
107
+ /**
108
+ * Check if the workbook is editable.
109
+ * @returns {boolean} true if the workbook can be edited, false otherwise.
110
+ * @example
111
+ * ```ts
112
+ * const workbook = univerAPI.getActiveWorkbook();
113
+ * const permission = workbook?.getWorkbookPermission();
114
+ * if (permission?.canEdit()) {
115
+ * console.log('Workbook is editable');
116
+ * }
117
+ * ```
118
+ */
119
+ canEdit(): boolean;
120
+ /**
121
+ * Set a specific permission point.
122
+ * @param {WorkbookPermissionPoint} point The permission point to set.
123
+ * @param {boolean} value The value to set (true = allowed, false = denied).
124
+ * @returns {Promise<void>} A promise that resolves when the point is set.
125
+ * @example
126
+ * ```ts
127
+ * const workbook = univerAPI.getActiveWorkbook();
128
+ * const permission = workbook?.getWorkbookPermission();
129
+ * await permission?.setPoint(WorkbookPermissionPoint.Print, false);
130
+ * ```
131
+ */
132
+ setPoint(point: WorkbookPermissionPoint, value: boolean): Promise<void>;
133
+ /**
134
+ * Get the value of a specific permission point.
135
+ * @param {WorkbookPermissionPoint} point The permission point to query.
136
+ * @returns {boolean} true if allowed, false if denied.
137
+ * @example
138
+ * ```ts
139
+ * const workbook = univerAPI.getActiveWorkbook();
140
+ * const permission = workbook?.getWorkbookPermission();
141
+ * const canPrint = permission?.getPoint(WorkbookPermissionPoint.Print);
142
+ * console.log(canPrint);
143
+ * ```
144
+ */
145
+ getPoint(point: WorkbookPermissionPoint): boolean;
146
+ /**
147
+ * Get a snapshot of all permission points.
148
+ * @returns {WorkbookPermissionSnapshot} An object containing all permission point values.
149
+ * @example
150
+ * ```ts
151
+ * const workbook = univerAPI.getActiveWorkbook();
152
+ * const permission = workbook?.getWorkbookPermission();
153
+ * const snapshot = permission?.getSnapshot();
154
+ * console.log(snapshot);
155
+ * ```
156
+ */
157
+ getSnapshot(): WorkbookPermissionSnapshot;
158
+ /**
159
+ * Set multiple collaborators at once (replaces existing collaborators).
160
+ * @param {Array<{ user: IUser; role: UnitRole }>} collaborators Array of collaborators with user information and role.
161
+ * @returns {Promise<void>} A promise that resolves when the collaborators are set.
162
+ * @example
163
+ * ```ts
164
+ * const workbook = univerAPI.getActiveWorkbook();
165
+ * const permission = workbook?.getWorkbookPermission();
166
+ * await permission?.setCollaborators([
167
+ * {
168
+ * user: { userID: 'user1', name: 'John Doe', avatar: 'https://...' },
169
+ * role: UnitRole.Editor
170
+ * },
171
+ * {
172
+ * user: { userID: 'user2', name: 'Jane Smith', avatar: '' },
173
+ * role: UnitRole.Reader
174
+ * }
175
+ * ]);
176
+ * ```
177
+ */
178
+ setCollaborators(collaborators: Array<{
179
+ user: IUser;
180
+ role: UnitRole;
181
+ }>): Promise<void>;
182
+ /**
183
+ * Add a single collaborator.
184
+ * @param {IUser} user The user information (userID, name, avatar).
185
+ * @param {UnitRole} role The role to assign.
186
+ * @returns {Promise<void>} A promise that resolves when the collaborator is added.
187
+ * @example
188
+ * ```ts
189
+ * const workbook = univerAPI.getActiveWorkbook();
190
+ * const permission = workbook?.getWorkbookPermission();
191
+ * await permission?.addCollaborator(
192
+ * { userID: 'user1', name: 'John Doe', avatar: 'https://...' },
193
+ * UnitRole.Editor
194
+ * );
195
+ * ```
196
+ */
197
+ addCollaborator(user: IUser, role: UnitRole): Promise<void>;
198
+ /**
199
+ * Update an existing collaborator's role and information.
200
+ * @param {IUser} user The updated user information (userID, name, avatar).
201
+ * @param {UnitRole} role The new role to assign.
202
+ * @returns {Promise<void>} A promise that resolves when the collaborator is updated.
203
+ * @example
204
+ * ```ts
205
+ * const workbook = univerAPI.getActiveWorkbook();
206
+ * const permission = workbook?.getWorkbookPermission();
207
+ * await permission?.updateCollaborator(
208
+ * { userID: 'user1', name: 'John Doe Updated', avatar: 'https://...' },
209
+ * UnitRole.Reader
210
+ * );
211
+ * ```
212
+ */
213
+ updateCollaborator(user: IUser, role: UnitRole): Promise<void>;
214
+ /**
215
+ * Remove a collaborator from the workbook.
216
+ * @param {string} userId The user ID to remove.
217
+ * @returns {Promise<void>} A promise that resolves when the collaborator is removed.
218
+ * @example
219
+ * ```ts
220
+ * const workbook = univerAPI.getActiveWorkbook();
221
+ * const permission = workbook?.getWorkbookPermission();
222
+ * await permission?.removeCollaborator('user1');
223
+ * ```
224
+ */
225
+ removeCollaborator(userId: string): Promise<void>;
226
+ /**
227
+ * Remove multiple collaborators at once.
228
+ * @param {string[]} userIds Array of user IDs to remove.
229
+ * @returns {Promise<void>} A promise that resolves when the collaborators are removed.
230
+ * @example
231
+ * ```ts
232
+ * const workbook = univerAPI.getActiveWorkbook();
233
+ * const permission = workbook?.getWorkbookPermission();
234
+ * await permission?.removeCollaborators(['user1', 'user2']);
235
+ * ```
236
+ */
237
+ removeCollaborators(userIds: string[]): Promise<void>;
238
+ /**
239
+ * List all collaborators of the workbook.
240
+ * @returns {Promise<ICollaborator[]>} Array of collaborators with their roles.
241
+ * @example
242
+ * ```ts
243
+ * const workbook = univerAPI.getActiveWorkbook();
244
+ * const permission = workbook?.getWorkbookPermission();
245
+ * const collaborators = await permission?.listCollaborators();
246
+ * console.log(collaborators);
247
+ * ```
248
+ */
249
+ listCollaborators(): Promise<ICollaborator[]>;
250
+ /**
251
+ * Subscribe to permission changes (simplified interface for users not familiar with RxJS).
252
+ * @param {Function} listener Callback function to be called when permissions change.
253
+ * @returns {UnsubscribeFn} Unsubscribe function.
254
+ * @example
255
+ * ```ts
256
+ * const workbook = univerAPI.getActiveWorkbook();
257
+ * const permission = workbook?.getWorkbookPermission();
258
+ * const unsubscribe = permission?.subscribe((snapshot) => {
259
+ * console.log('Permission changed:', snapshot);
260
+ * });
261
+ * // Later, to stop listening:
262
+ * unsubscribe?.();
263
+ * ```
264
+ */
265
+ subscribe(listener: (snapshot: WorkbookPermissionSnapshot) => void): UnsubscribeFn;
266
+ /**
267
+ * Clean up resources
268
+ */
269
+ dispose(): void;
270
+ }
@@ -0,0 +1,335 @@
1
+ import { Observable } from 'rxjs';
2
+ import { FRange } from '../f-range';
3
+ import { FWorksheet } from '../f-worksheet';
4
+ import { ICellPermissionDebugInfo, IRangeProtectionOptions, IRangeProtectionRule, IWorksheetPermission, IWorksheetPermissionConfig, UnsubscribeFn, WorksheetMode, WorksheetPermissionSnapshot, WorksheetPermissionPoint } from './permission-types';
5
+ import { IAuthzIoService, ICommandService, Injector, IPermissionService } from '@univerjs/core';
6
+ import { RangeProtectionRuleModel, WorksheetProtectionPointModel } from '@univerjs/sheets';
7
+ /**
8
+ * Implementation class for WorksheetPermission
9
+ * Provides worksheet-level permission control
10
+ *
11
+ * @hideconstructor
12
+ */
13
+ export declare class FWorksheetPermission implements IWorksheetPermission {
14
+ private readonly _worksheet;
15
+ private readonly _injector;
16
+ private readonly _permissionService;
17
+ private readonly _authzIoService;
18
+ private readonly _commandService;
19
+ private readonly _rangeProtectionRuleModel;
20
+ private readonly _worksheetProtectionPointModel;
21
+ private readonly _permissionSubject;
22
+ private readonly _rangeRulesSubject;
23
+ /**
24
+ * Observable stream of permission snapshot changes (BehaviorSubject)
25
+ * Emits immediately on subscription with current state, then on any permission point change
26
+ */
27
+ readonly permission$: Observable<WorksheetPermissionSnapshot>;
28
+ /**
29
+ * Observable stream of individual permission point changes
30
+ * Emits when a specific permission point value changes
31
+ */
32
+ readonly pointChange$: Observable<{
33
+ point: WorksheetPermissionPoint;
34
+ value: boolean;
35
+ oldValue: boolean;
36
+ }>;
37
+ /**
38
+ * Observable stream of range protection rule changes
39
+ * Emits when protection rules are added, updated, or deleted
40
+ */
41
+ readonly rangeProtectionChange$: Observable<{
42
+ type: 'add' | 'update' | 'delete';
43
+ rules: IRangeProtectionRule[];
44
+ }>;
45
+ /**
46
+ * Observable stream of current range protection rules list (BehaviorSubject)
47
+ * Emits immediately on subscription with current rules, then auto-updates when rules change
48
+ */
49
+ readonly rangeProtectionRules$: Observable<IRangeProtectionRule[]>;
50
+ private readonly _unitId;
51
+ private readonly _subUnitId;
52
+ private readonly _subscriptions;
53
+ constructor(_worksheet: FWorksheet, _injector: Injector, _permissionService: IPermissionService, _authzIoService: IAuthzIoService, _commandService: ICommandService, _rangeProtectionRuleModel: RangeProtectionRuleModel, _worksheetProtectionPointModel: WorksheetProtectionPointModel);
54
+ /**
55
+ * Create permission snapshot stream from IPermissionService
56
+ * @private
57
+ */
58
+ private _createPermissionStream;
59
+ /**
60
+ * Create point change stream from IPermissionService
61
+ * @private
62
+ */
63
+ private _createPointChangeStream;
64
+ /**
65
+ * Create range protection change stream from RangeProtectionRuleModel
66
+ * @private
67
+ */
68
+ private _createRangeProtectionChangeStream;
69
+ /**
70
+ * Create range protection rules list stream from RangeProtectionRuleModel
71
+ * @private
72
+ */
73
+ private _createRangeProtectionRulesStream;
74
+ /**
75
+ * Extract WorksheetPermissionPoint type from permission point ID
76
+ * @private
77
+ */
78
+ private _extractWorksheetPointType;
79
+ /**
80
+ * Read the actual edit permission from a rule's permissionId
81
+ */
82
+ private _getRuleEditPermission;
83
+ /**
84
+ * Build permission snapshot
85
+ */
86
+ private _buildSnapshot;
87
+ /**
88
+ * Build range protection rules list
89
+ */
90
+ private _buildRangeProtectionRules;
91
+ /**
92
+ * Set permission mode for the worksheet.
93
+ * @param {WorksheetMode} mode The permission mode to set ('editable' | 'readOnly' | 'filterOnly' | 'commentOnly').
94
+ * @returns {Promise<void>} A promise that resolves when the mode is set.
95
+ * @example
96
+ * ```ts
97
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
98
+ * const permission = worksheet?.getWorksheetPermission();
99
+ * await permission?.setMode('readOnly');
100
+ * ```
101
+ */
102
+ setMode(mode: WorksheetMode): Promise<void>;
103
+ /**
104
+ * Get permission configuration for a specific mode
105
+ * @private
106
+ */
107
+ private _getModePermissions;
108
+ /**
109
+ * Batch set multiple permission points efficiently
110
+ * @private
111
+ */
112
+ private _batchSetPermissionPoints;
113
+ /**
114
+ * Set the worksheet to read-only mode.
115
+ * @returns {Promise<void>} A promise that resolves when the mode is set.
116
+ * @example
117
+ * ```ts
118
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
119
+ * const permission = worksheet?.getWorksheetPermission();
120
+ * await permission?.setReadOnly();
121
+ * ```
122
+ */
123
+ setReadOnly(): Promise<void>;
124
+ /**
125
+ * Set the worksheet to editable mode.
126
+ * @returns {Promise<void>} A promise that resolves when the mode is set.
127
+ * @example
128
+ * ```ts
129
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
130
+ * const permission = worksheet?.getWorksheetPermission();
131
+ * await permission?.setEditable();
132
+ * ```
133
+ */
134
+ setEditable(): Promise<void>;
135
+ /**
136
+ * Check if the worksheet is editable.
137
+ * @returns {boolean} true if the worksheet can be edited, false otherwise.
138
+ * @example
139
+ * ```ts
140
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
141
+ * const permission = worksheet?.getWorksheetPermission();
142
+ * if (permission?.canEdit()) {
143
+ * console.log('Worksheet is editable');
144
+ * }
145
+ * ```
146
+ */
147
+ canEdit(): boolean;
148
+ /**
149
+ * Check if a specific cell can be edited.
150
+ * @param {number} row Row index.
151
+ * @param {number} col Column index.
152
+ * @returns {boolean} true if the cell can be edited, false otherwise.
153
+ * @example
154
+ * ```ts
155
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
156
+ * const permission = worksheet?.getWorksheetPermission();
157
+ * const canEdit = permission?.canEditCell(0, 0);
158
+ * console.log(canEdit);
159
+ * ```
160
+ */
161
+ canEditCell(row: number, col: number): boolean;
162
+ /**
163
+ * Check if a specific cell can be viewed.
164
+ * @param {number} _row Row index (unused, for API consistency).
165
+ * @param {number} _col Column index (unused, for API consistency).
166
+ * @returns {boolean} true if the cell can be viewed, false otherwise.
167
+ * @example
168
+ * ```ts
169
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
170
+ * const permission = worksheet?.getWorksheetPermission();
171
+ * const canView = permission?.canViewCell(0, 0);
172
+ * console.log(canView);
173
+ * ```
174
+ */
175
+ canViewCell(_row: number, _col: number): boolean;
176
+ /**
177
+ * Debug cell permission information.
178
+ * @param {number} row Row index.
179
+ * @param {number} col Column index.
180
+ * @returns {ICellPermissionDebugInfo | null} Debug information about which rules affect this cell, or null if no rules apply.
181
+ * @example
182
+ * ```ts
183
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
184
+ * const permission = worksheet?.getWorksheetPermission();
185
+ * const debugInfo = permission?.debugCellPermission(0, 0);
186
+ * console.log(debugInfo);
187
+ * ```
188
+ */
189
+ debugCellPermission(row: number, col: number): ICellPermissionDebugInfo | null;
190
+ /**
191
+ * Set a specific permission point for the worksheet.
192
+ * @param {WorksheetPermissionPoint} point The permission point to set.
193
+ * @param {boolean} value The value to set (true = allowed, false = denied).
194
+ * @returns {Promise<void>} A promise that resolves when the point is set.
195
+ * @example
196
+ * ```ts
197
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
198
+ * const permission = worksheet?.getWorksheetPermission();
199
+ * await permission?.setPoint(WorksheetPermissionPoint.InsertRow, false);
200
+ * ```
201
+ */
202
+ setPoint(point: WorksheetPermissionPoint, value: boolean): Promise<void>;
203
+ /**
204
+ * Get the value of a specific permission point.
205
+ * @param {WorksheetPermissionPoint} point The permission point to query.
206
+ * @returns {boolean} true if allowed, false if denied.
207
+ * @example
208
+ * ```ts
209
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
210
+ * const permission = worksheet?.getWorksheetPermission();
211
+ * const canInsertRow = permission?.getPoint(WorksheetPermissionPoint.InsertRow);
212
+ * console.log(canInsertRow);
213
+ * ```
214
+ */
215
+ getPoint(point: WorksheetPermissionPoint): boolean;
216
+ /**
217
+ * Get a snapshot of all permission points.
218
+ * @returns {WorksheetPermissionSnapshot} An object containing all permission point values.
219
+ * @example
220
+ * ```ts
221
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
222
+ * const permission = worksheet?.getWorksheetPermission();
223
+ * const snapshot = permission?.getSnapshot();
224
+ * console.log(snapshot);
225
+ * ```
226
+ */
227
+ getSnapshot(): WorksheetPermissionSnapshot;
228
+ /**
229
+ * Apply a permission configuration to the worksheet.
230
+ * @param {IWorksheetPermissionConfig} config The configuration to apply.
231
+ * @returns {Promise<void>} A promise that resolves when the configuration is applied.
232
+ * @example
233
+ * ```ts
234
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
235
+ * const permission = worksheet?.getWorksheetPermission();
236
+ * await permission?.applyConfig({
237
+ * mode: 'readOnly',
238
+ * points: {
239
+ * [WorksheetPermissionPoint.View]: true,
240
+ * [WorksheetPermissionPoint.Edit]: false
241
+ * }
242
+ * });
243
+ * ```
244
+ */
245
+ applyConfig(config: IWorksheetPermissionConfig): Promise<void>;
246
+ /**
247
+ * Protect multiple ranges at once (batch operation).
248
+ * @param {Array<{ ranges: FRange[]; options?: IRangeProtectionOptions }>} configs Array of protection configurations.
249
+ * @returns {Promise<IRangeProtectionRule[]>} Array of created protection rules.
250
+ * @example
251
+ * ```ts
252
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
253
+ * const permission = worksheet?.getWorksheetPermission();
254
+ * const rules = await permission?.protectRanges([
255
+ * {
256
+ * ranges: [worksheet.getRange('A1:B2')],
257
+ * options: { name: 'Protected Area 1', allowEdit: false, allowView: true }
258
+ * },
259
+ * {
260
+ * ranges: [worksheet.getRange('C3:D4')],
261
+ * options: { name: 'Protected Area 2', allowEdit: true, allowView: false }
262
+ * }
263
+ * ]);
264
+ * console.log(rules);
265
+ * ```
266
+ */
267
+ protectRanges(configs: Array<{
268
+ ranges: FRange[];
269
+ options?: IRangeProtectionOptions;
270
+ }>): Promise<IRangeProtectionRule[]>;
271
+ /**
272
+ * Determine view state from options
273
+ * @private
274
+ */
275
+ private _determineViewState;
276
+ /**
277
+ * Determine edit state from options
278
+ * @private
279
+ */
280
+ private _determineEditState;
281
+ /**
282
+ * Set permission points based on options (for local runtime control)
283
+ * @private
284
+ */
285
+ private _setPermissionPoints;
286
+ /**
287
+ * Set a single permission point
288
+ * @private
289
+ */
290
+ private _setPermissionPoint;
291
+ /**
292
+ * Remove multiple protection rules at once.
293
+ * @param {string[]} ruleIds Array of rule IDs to remove.
294
+ * @returns {Promise<void>} A promise that resolves when the rules are removed.
295
+ * @example
296
+ * ```ts
297
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
298
+ * const permission = worksheet?.getWorksheetPermission();
299
+ * await permission?.unprotectRules(['rule1', 'rule2']);
300
+ * ```
301
+ */
302
+ unprotectRules(ruleIds: string[]): Promise<void>;
303
+ /**
304
+ * List all range protection rules for the worksheet.
305
+ * @returns {Promise<IRangeProtectionRule[]>} Array of protection rules.
306
+ * @example
307
+ * ```ts
308
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
309
+ * const permission = worksheet?.getWorksheetPermission();
310
+ * const rules = await permission?.listRangeProtectionRules();
311
+ * console.log(rules);
312
+ * ```
313
+ */
314
+ listRangeProtectionRules(): Promise<IRangeProtectionRule[]>;
315
+ /**
316
+ * Subscribe to permission changes (simplified interface for users not familiar with RxJS).
317
+ * @param {Function} listener Callback function to be called when permissions change.
318
+ * @returns {UnsubscribeFn} Unsubscribe function.
319
+ * @example
320
+ * ```ts
321
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
322
+ * const permission = worksheet?.getWorksheetPermission();
323
+ * const unsubscribe = permission?.subscribe((snapshot) => {
324
+ * console.log('Permission changed:', snapshot);
325
+ * });
326
+ * // Later, to stop listening:
327
+ * unsubscribe?.();
328
+ * ```
329
+ */
330
+ subscribe(listener: (snapshot: WorksheetPermissionSnapshot) => void): UnsubscribeFn;
331
+ /**
332
+ * Clean up resources
333
+ */
334
+ dispose(): void;
335
+ }
@@ -0,0 +1,21 @@
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
+ export { FRangePermission } from './f-range-permission';
17
+ export { FRangeProtectionRule } from './f-range-protection-rule';
18
+ export { FWorkbookPermission } from './f-workbook-permission';
19
+ export { FWorksheetPermission } from './f-worksheet-permission';
20
+ export * from './permission-point-map';
21
+ export * from './permission-types';
@@ -0,0 +1,14 @@
1
+ import { RangePermissionPointConstructor, WorkbookPermissionPointConstructor, WorkSheetPermissionPointConstructor } from '@univerjs/core';
2
+ import { RangePermissionPoint, WorkbookPermissionPoint, WorksheetPermissionPoint } from './permission-types';
3
+ /**
4
+ * Mapping table from Workbook permission point enum to class constructors
5
+ */
6
+ export declare const WORKBOOK_PERMISSION_POINT_MAP: Record<WorkbookPermissionPoint, WorkbookPermissionPointConstructor>;
7
+ /**
8
+ * Mapping table from Worksheet permission point enum to class constructors
9
+ */
10
+ export declare const WORKSHEET_PERMISSION_POINT_MAP: Record<WorksheetPermissionPoint, WorkSheetPermissionPointConstructor>;
11
+ /**
12
+ * Mapping table from Range permission point enum to class constructors
13
+ */
14
+ export declare const RANGE_PERMISSION_POINT_MAP: Record<RangePermissionPoint, RangePermissionPointConstructor>;