@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.
- package/lib/cjs/facade.js +8352 -1
- package/lib/cjs/index.js +21494 -2
- package/lib/cjs/locale/ca-ES.js +17 -1
- package/lib/cjs/locale/en-US.js +32 -1
- package/lib/cjs/locale/es-ES.js +17 -1
- package/lib/cjs/locale/fa-IR.js +17 -1
- package/lib/cjs/locale/fr-FR.js +17 -1
- package/lib/cjs/locale/ja-JP.js +17 -1
- package/lib/cjs/locale/ko-KR.js +17 -1
- package/lib/cjs/locale/ru-RU.js +17 -1
- package/lib/cjs/locale/sk-SK.js +17 -1
- package/lib/cjs/locale/vi-VN.js +17 -1
- package/lib/cjs/locale/zh-CN.js +17 -1
- package/lib/cjs/locale/zh-TW.js +17 -1
- package/lib/es/facade.js +8314 -1
- package/lib/es/index.js +20973 -2
- package/lib/es/locale/ca-ES.js +16 -1
- package/lib/es/locale/en-US.js +31 -1
- package/lib/es/locale/es-ES.js +16 -1
- package/lib/es/locale/fa-IR.js +16 -1
- package/lib/es/locale/fr-FR.js +16 -1
- package/lib/es/locale/ja-JP.js +16 -1
- package/lib/es/locale/ko-KR.js +16 -1
- package/lib/es/locale/ru-RU.js +16 -1
- package/lib/es/locale/sk-SK.js +16 -1
- package/lib/es/locale/vi-VN.js +16 -1
- package/lib/es/locale/zh-CN.js +16 -1
- package/lib/es/locale/zh-TW.js +16 -1
- package/lib/facade.js +8314 -1
- package/lib/index.js +20973 -2
- package/lib/locale/ca-ES.js +16 -1
- package/lib/locale/en-US.js +31 -1
- package/lib/locale/es-ES.js +16 -1
- package/lib/locale/fa-IR.js +16 -1
- package/lib/locale/fr-FR.js +16 -1
- package/lib/locale/ja-JP.js +16 -1
- package/lib/locale/ko-KR.js +16 -1
- package/lib/locale/ru-RU.js +16 -1
- package/lib/locale/sk-SK.js +16 -1
- package/lib/locale/vi-VN.js +16 -1
- package/lib/locale/zh-CN.js +16 -1
- package/lib/locale/zh-TW.js +16 -1
- package/lib/types/commands/commands/remove-row-col.command.d.ts +2 -1
- package/lib/types/controllers/permission/sheet-permission-check.controller.d.ts +11 -12
- package/lib/types/facade/f-univer.d.ts +0 -7
- package/lib/types/facade/f-workbook.d.ts +0 -13
- package/lib/types/facade/index.d.ts +2 -2
- package/lib/types/facade/permission/f-range-permission.d.ts +31 -228
- package/lib/types/facade/permission/f-range-protection-rule.d.ts +157 -46
- package/lib/types/facade/permission/f-workbook-permission.d.ts +51 -129
- package/lib/types/facade/permission/f-worksheet-permission.d.ts +111 -199
- package/lib/types/facade/permission/permission-types.d.ts +20 -125
- package/lib/types/facade/permission/util.d.ts +40 -0
- package/lib/types/services/permission/range-permission/util.d.ts +2 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +9 -9
- package/lib/types/facade/f-permission.d.ts +0 -426
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { Observable } from 'rxjs';
|
|
17
16
|
import type { FRange } from '../f-range';
|
|
18
17
|
import type { FWorksheet } from '../f-worksheet';
|
|
19
|
-
import type { IRangeProtectionOptions, IWorksheetPermissionConfig, IWorksheetProtectionOptions,
|
|
18
|
+
import type { IRangeProtectionOptions, IWorksheetPermissionConfig, IWorksheetProtectionOptions, WorksheetMode, WorksheetPermissionSnapshot } from './permission-types';
|
|
20
19
|
import { IAuthzIoService, ICommandService, Injector, IPermissionService } from '@univerjs/core';
|
|
20
|
+
import { FBase } from '@univerjs/core/facade';
|
|
21
21
|
import { RangeProtectionRuleModel, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets';
|
|
22
22
|
import { FRangeProtectionRule } from './f-range-protection-rule';
|
|
23
23
|
import { WorksheetPermissionPoint } from './permission-types';
|
|
@@ -27,7 +27,7 @@ import { WorksheetPermissionPoint } from './permission-types';
|
|
|
27
27
|
*
|
|
28
28
|
* @hideconstructor
|
|
29
29
|
*/
|
|
30
|
-
export declare class FWorksheetPermission {
|
|
30
|
+
export declare class FWorksheetPermission extends FBase {
|
|
31
31
|
private readonly _worksheet;
|
|
32
32
|
private readonly _injector;
|
|
33
33
|
private readonly _permissionService;
|
|
@@ -36,95 +36,22 @@ export declare class FWorksheetPermission {
|
|
|
36
36
|
private readonly _rangeProtectionRuleModel;
|
|
37
37
|
private readonly _worksheetProtectionPointModel;
|
|
38
38
|
private readonly _worksheetProtectionRuleModel;
|
|
39
|
-
private readonly _permissionSubject;
|
|
40
|
-
private readonly _rangeRulesSubject;
|
|
41
|
-
/**
|
|
42
|
-
* Observable stream of permission snapshot changes (BehaviorSubject)
|
|
43
|
-
* Emits immediately on subscription with current state, then on any permission point change
|
|
44
|
-
*/
|
|
45
|
-
readonly permission$: Observable<WorksheetPermissionSnapshot>;
|
|
46
|
-
/**
|
|
47
|
-
* Observable stream of individual permission point changes
|
|
48
|
-
* Emits when a specific permission point value changes
|
|
49
|
-
*/
|
|
50
|
-
readonly pointChange$: Observable<{
|
|
51
|
-
point: WorksheetPermissionPoint;
|
|
52
|
-
value: boolean;
|
|
53
|
-
oldValue: boolean;
|
|
54
|
-
}>;
|
|
55
|
-
/**
|
|
56
|
-
* Observable stream of range protection rule changes
|
|
57
|
-
* Emits when protection rules are added, updated, or deleted
|
|
58
|
-
*/
|
|
59
|
-
readonly rangeProtectionChange$: Observable<{
|
|
60
|
-
type: 'add' | 'update' | 'delete';
|
|
61
|
-
rules: FRangeProtectionRule[];
|
|
62
|
-
}>;
|
|
63
|
-
/**
|
|
64
|
-
* Observable stream of current range protection rules list (BehaviorSubject)
|
|
65
|
-
* Emits immediately on subscription with current rules, then auto-updates when rules change
|
|
66
|
-
*/
|
|
67
|
-
readonly rangeProtectionRules$: Observable<FRangeProtectionRule[]>;
|
|
68
39
|
private readonly _unitId;
|
|
69
40
|
private readonly _subUnitId;
|
|
70
|
-
private readonly _subscriptions;
|
|
71
|
-
private readonly _fPermission;
|
|
72
41
|
constructor(_worksheet: FWorksheet, _injector: Injector, _permissionService: IPermissionService, _authzIoService: IAuthzIoService, _commandService: ICommandService, _rangeProtectionRuleModel: RangeProtectionRuleModel, _worksheetProtectionPointModel: WorksheetProtectionPointModel, _worksheetProtectionRuleModel: WorksheetProtectionRuleModel);
|
|
73
42
|
/**
|
|
74
|
-
*
|
|
75
|
-
* @
|
|
76
|
-
*/
|
|
77
|
-
private _createPermissionStream;
|
|
78
|
-
/**
|
|
79
|
-
* Create point change stream from IPermissionService
|
|
80
|
-
* @private
|
|
81
|
-
*/
|
|
82
|
-
private _createPointChangeStream;
|
|
83
|
-
/**
|
|
84
|
-
* Create range protection change stream from RangeProtectionRuleModel
|
|
85
|
-
* @private
|
|
86
|
-
*/
|
|
87
|
-
private _createRangeProtectionChangeStream;
|
|
88
|
-
/**
|
|
89
|
-
* Create range protection rules list stream from RangeProtectionRuleModel
|
|
90
|
-
* @private
|
|
91
|
-
*/
|
|
92
|
-
private _createRangeProtectionRulesStream;
|
|
93
|
-
/**
|
|
94
|
-
* Extract WorksheetPermissionPoint type from permission point ID
|
|
95
|
-
* @private
|
|
96
|
-
*/
|
|
97
|
-
private _extractWorksheetPointType;
|
|
98
|
-
/**
|
|
99
|
-
* Read the actual edit permission from a rule's permissionId
|
|
100
|
-
*/
|
|
101
|
-
private _getRuleEditPermission;
|
|
102
|
-
/**
|
|
103
|
-
* Build permission snapshot
|
|
104
|
-
*/
|
|
105
|
-
private _buildSnapshot;
|
|
106
|
-
/**
|
|
107
|
-
* Build range protection rules list
|
|
108
|
-
*/
|
|
109
|
-
private _buildRangeProtectionRules;
|
|
110
|
-
/**
|
|
111
|
-
* Build Facade objects for all protection rules
|
|
112
|
-
*/
|
|
113
|
-
private _buildProtectionRule;
|
|
114
|
-
/**
|
|
115
|
-
* Debug cell permission information.
|
|
116
|
-
* @param {number} row Row index.
|
|
117
|
-
* @param {number} col Column index.
|
|
118
|
-
* @returns {ICellPermissionDebugInfo | null} Debug information about which rules affect this cell, or null if no rules apply.
|
|
43
|
+
* Check if worksheet is currently protected.
|
|
44
|
+
* @returns {boolean} true if protected, false otherwise.
|
|
119
45
|
* @example
|
|
120
46
|
* ```ts
|
|
121
|
-
* const
|
|
122
|
-
* const
|
|
123
|
-
*
|
|
124
|
-
*
|
|
47
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
48
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
49
|
+
* if (fWorksheet.getWorksheetPermission().isProtected()) {
|
|
50
|
+
* console.log('Worksheet is protected');
|
|
51
|
+
* }
|
|
125
52
|
* ```
|
|
126
53
|
*/
|
|
127
|
-
|
|
54
|
+
isProtected(): boolean;
|
|
128
55
|
/**
|
|
129
56
|
* Create worksheet protection with collaborators support.
|
|
130
57
|
* This must be called before setting permission points for collaboration to work.
|
|
@@ -132,11 +59,12 @@ export declare class FWorksheetPermission {
|
|
|
132
59
|
* @returns {Promise<string>} The permissionId for the created protection.
|
|
133
60
|
* @example
|
|
134
61
|
* ```ts
|
|
135
|
-
* const
|
|
136
|
-
* const
|
|
62
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
63
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
64
|
+
* const permission = fWorksheet.getWorksheetPermission();
|
|
137
65
|
*
|
|
138
66
|
* // Create worksheet protection with collaborators
|
|
139
|
-
* const permissionId = await permission
|
|
67
|
+
* const permissionId = await permission.protect({
|
|
140
68
|
* allowedUsers: ['user1', 'user2'],
|
|
141
69
|
* name: 'My Worksheet Protection'
|
|
142
70
|
* });
|
|
@@ -152,25 +80,12 @@ export declare class FWorksheetPermission {
|
|
|
152
80
|
* @returns {Promise<void>} A promise that resolves when protection is removed.
|
|
153
81
|
* @example
|
|
154
82
|
* ```ts
|
|
155
|
-
* const
|
|
156
|
-
* const
|
|
157
|
-
* await
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
unprotect(): Promise<void>;
|
|
161
|
-
/**
|
|
162
|
-
* Check if worksheet is currently protected.
|
|
163
|
-
* @returns {boolean} true if protected, false otherwise.
|
|
164
|
-
* @example
|
|
165
|
-
* ```ts
|
|
166
|
-
* const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
|
|
167
|
-
* const permission = worksheet?.getWorksheetPermission();
|
|
168
|
-
* if (permission?.isProtected()) {
|
|
169
|
-
* console.log('Worksheet is protected');
|
|
170
|
-
* }
|
|
83
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
84
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
85
|
+
* await fWorksheet.getWorksheetPermission().unprotect();
|
|
171
86
|
* ```
|
|
172
87
|
*/
|
|
173
|
-
|
|
88
|
+
unprotect(): Promise<boolean>;
|
|
174
89
|
/**
|
|
175
90
|
* Set permission mode for the worksheet.
|
|
176
91
|
* Automatically creates worksheet protection if not already protected.
|
|
@@ -178,9 +93,9 @@ export declare class FWorksheetPermission {
|
|
|
178
93
|
* @returns {Promise<void>} A promise that resolves when the mode is set.
|
|
179
94
|
* @example
|
|
180
95
|
* ```ts
|
|
181
|
-
* const
|
|
182
|
-
* const
|
|
183
|
-
* await
|
|
96
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
97
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
98
|
+
* await fWorksheet.getWorksheetPermission().setMode('readOnly');
|
|
184
99
|
* ```
|
|
185
100
|
*/
|
|
186
101
|
setMode(mode: WorksheetMode): Promise<void>;
|
|
@@ -189,19 +104,14 @@ export declare class FWorksheetPermission {
|
|
|
189
104
|
* @private
|
|
190
105
|
*/
|
|
191
106
|
private _getModePermissions;
|
|
192
|
-
/**
|
|
193
|
-
* Batch set multiple permission points efficiently
|
|
194
|
-
* @private
|
|
195
|
-
*/
|
|
196
|
-
private _batchSetPermissionPoints;
|
|
197
107
|
/**
|
|
198
108
|
* Set the worksheet to read-only mode.
|
|
199
109
|
* @returns {Promise<void>} A promise that resolves when the mode is set.
|
|
200
110
|
* @example
|
|
201
111
|
* ```ts
|
|
202
|
-
* const
|
|
203
|
-
* const
|
|
204
|
-
* await
|
|
112
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
113
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
114
|
+
* await fWorksheet.getWorksheetPermission().setReadOnly();
|
|
205
115
|
* ```
|
|
206
116
|
*/
|
|
207
117
|
setReadOnly(): Promise<void>;
|
|
@@ -210,20 +120,35 @@ export declare class FWorksheetPermission {
|
|
|
210
120
|
* @returns {Promise<void>} A promise that resolves when the mode is set.
|
|
211
121
|
* @example
|
|
212
122
|
* ```ts
|
|
213
|
-
* const
|
|
214
|
-
* const
|
|
215
|
-
* await
|
|
123
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
124
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
125
|
+
* await fWorksheet.getWorksheetPermission().setEditable();
|
|
216
126
|
* ```
|
|
217
127
|
*/
|
|
218
128
|
setEditable(): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Set a specific permission point for the worksheet.
|
|
131
|
+
* Automatically creates worksheet protection if not already protected.
|
|
132
|
+
* @param {WorksheetPermissionPoint} point The permission point to set.
|
|
133
|
+
* @param {boolean} value The value to set (true = allowed, false = denied).
|
|
134
|
+
* @returns {Promise<void>} A promise that resolves when the point is set.
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
138
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
139
|
+
* const permission = fWorksheet.getWorksheetPermission();
|
|
140
|
+
* await permission.setPoint(univerAPI.Enum.WorksheetPermissionPoint.InsertRow, false);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
setPoint(point: WorksheetPermissionPoint, value: boolean): Promise<void>;
|
|
219
144
|
/**
|
|
220
145
|
* Check if the worksheet is editable.
|
|
221
146
|
* @returns {boolean} true if the worksheet can be edited, false otherwise.
|
|
222
147
|
* @example
|
|
223
148
|
* ```ts
|
|
224
|
-
* const
|
|
225
|
-
* const
|
|
226
|
-
* if (
|
|
149
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
150
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
151
|
+
* if (fWorksheet.getWorksheetPermission().canEdit()) {
|
|
227
152
|
* console.log('Worksheet is editable');
|
|
228
153
|
* }
|
|
229
154
|
* ```
|
|
@@ -236,50 +161,53 @@ export declare class FWorksheetPermission {
|
|
|
236
161
|
* @returns {boolean} true if the cell can be edited, false otherwise.
|
|
237
162
|
* @example
|
|
238
163
|
* ```ts
|
|
239
|
-
* const
|
|
240
|
-
* const
|
|
241
|
-
*
|
|
164
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
165
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
166
|
+
* // Check if cell C3 can be edited
|
|
167
|
+
* const fRange = fWorksheet.getRange('C3');
|
|
168
|
+
* const canEdit = fWorksheet.getWorksheetPermission().canEditCell(fRange.getRow(), fRange.getColumn());
|
|
242
169
|
* console.log(canEdit);
|
|
243
170
|
* ```
|
|
244
171
|
*/
|
|
245
172
|
canEditCell(row: number, col: number): boolean;
|
|
246
173
|
/**
|
|
247
|
-
* Check if
|
|
248
|
-
* @
|
|
249
|
-
* @param {number} _col Column index (unused, for API consistency).
|
|
250
|
-
* @returns {boolean} true if the cell can be viewed, false otherwise.
|
|
174
|
+
* Check if the worksheet is viewable.
|
|
175
|
+
* @returns {boolean} true if the worksheet can be viewed, false otherwise.
|
|
251
176
|
* @example
|
|
252
177
|
* ```ts
|
|
253
|
-
* const
|
|
254
|
-
* const
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
178
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
179
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
180
|
+
* if (fWorksheet.getWorksheetPermission().canView()) {
|
|
181
|
+
* console.log('Worksheet is viewable');
|
|
182
|
+
* }
|
|
258
183
|
*/
|
|
259
|
-
|
|
184
|
+
canView(): boolean;
|
|
260
185
|
/**
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* @param {
|
|
264
|
-
* @
|
|
265
|
-
* @returns {Promise<void>} A promise that resolves when the point is set.
|
|
186
|
+
* Check if a specific cell can be viewed.
|
|
187
|
+
* @param {number} row Row index.
|
|
188
|
+
* @param {number} col Column index.
|
|
189
|
+
* @returns {boolean} true if the cell can be viewed, false otherwise.
|
|
266
190
|
* @example
|
|
267
191
|
* ```ts
|
|
268
|
-
* const
|
|
269
|
-
* const
|
|
270
|
-
*
|
|
192
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
193
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
194
|
+
* // Check if cell C3 can be viewed
|
|
195
|
+
* const fRange = fWorksheet.getRange('C3');
|
|
196
|
+
* const canView = fWorksheet.getWorksheetPermission().canViewCell(fRange.getRow(), fRange.getColumn());
|
|
197
|
+
* console.log(canView);
|
|
271
198
|
* ```
|
|
272
199
|
*/
|
|
273
|
-
|
|
200
|
+
canViewCell(row: number, col: number): boolean;
|
|
274
201
|
/**
|
|
275
202
|
* Get the value of a specific permission point.
|
|
276
203
|
* @param {WorksheetPermissionPoint} point The permission point to query.
|
|
277
204
|
* @returns {boolean} true if allowed, false if denied.
|
|
278
205
|
* @example
|
|
279
206
|
* ```ts
|
|
280
|
-
* const
|
|
281
|
-
* const
|
|
282
|
-
* const
|
|
207
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
208
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
209
|
+
* const permission = fWorksheet.getWorksheetPermission();
|
|
210
|
+
* const canInsertRow = permission.getPoint(univerAPI.Enum.WorksheetPermissionPoint.InsertRow);
|
|
283
211
|
* console.log(canInsertRow);
|
|
284
212
|
* ```
|
|
285
213
|
*/
|
|
@@ -289,9 +217,9 @@ export declare class FWorksheetPermission {
|
|
|
289
217
|
* @returns {WorksheetPermissionSnapshot} An object containing all permission point values.
|
|
290
218
|
* @example
|
|
291
219
|
* ```ts
|
|
292
|
-
* const
|
|
293
|
-
* const
|
|
294
|
-
* const snapshot =
|
|
220
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
221
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
222
|
+
* const snapshot = fWorksheet.getWorksheetPermission().getSnapshot();
|
|
295
223
|
* console.log(snapshot);
|
|
296
224
|
* ```
|
|
297
225
|
*/
|
|
@@ -320,16 +248,16 @@ export declare class FWorksheetPermission {
|
|
|
320
248
|
* @returns {Promise<FRangeProtectionRule[]>} Array of created protection rules.
|
|
321
249
|
* @example
|
|
322
250
|
* ```ts
|
|
323
|
-
* const
|
|
324
|
-
* const
|
|
325
|
-
* const rules = await
|
|
251
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
252
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
253
|
+
* const rules = await fWorksheet.getWorksheetPermission().protectRanges([
|
|
326
254
|
* {
|
|
327
|
-
* ranges: [
|
|
328
|
-
* options: { name: 'Protected Area 1',
|
|
255
|
+
* ranges: [fWorksheet.getRange('A1:B2')],
|
|
256
|
+
* options: { name: 'Protected Area 1', allowedUsers: ['user1', 'user2'], allowViewByOthers: true }
|
|
329
257
|
* },
|
|
330
258
|
* {
|
|
331
|
-
* ranges: [
|
|
332
|
-
* options: { name: 'Protected Area 2',
|
|
259
|
+
* ranges: [fWorksheet.getRange('C3:D4')],
|
|
260
|
+
* options: { name: 'Protected Area 2', allowViewByOthers: false }
|
|
333
261
|
* }
|
|
334
262
|
* ]);
|
|
335
263
|
* console.log(rules);
|
|
@@ -339,68 +267,52 @@ export declare class FWorksheetPermission {
|
|
|
339
267
|
ranges: FRange[];
|
|
340
268
|
options?: IRangeProtectionOptions;
|
|
341
269
|
}>): Promise<FRangeProtectionRule[]>;
|
|
342
|
-
/**
|
|
343
|
-
* Determine view state from options
|
|
344
|
-
* @private
|
|
345
|
-
*/
|
|
346
|
-
private _determineViewState;
|
|
347
|
-
/**
|
|
348
|
-
* Determine edit state from options
|
|
349
|
-
* @private
|
|
350
|
-
*/
|
|
351
|
-
private _determineEditState;
|
|
352
|
-
/**
|
|
353
|
-
* Set permission points based on options (for local runtime control)
|
|
354
|
-
* @private
|
|
355
|
-
*/
|
|
356
|
-
private _setPermissionPoints;
|
|
357
|
-
/**
|
|
358
|
-
* Set a single permission point
|
|
359
|
-
* @private
|
|
360
|
-
*/
|
|
361
|
-
private _setPermissionPoint;
|
|
362
270
|
/**
|
|
363
271
|
* Remove multiple protection rules at once.
|
|
364
272
|
* @param {string[]} ruleIds Array of rule IDs to remove.
|
|
365
273
|
* @returns {Promise<void>} A promise that resolves when the rules are removed.
|
|
366
274
|
* @example
|
|
367
275
|
* ```ts
|
|
368
|
-
* const
|
|
369
|
-
* const
|
|
370
|
-
*
|
|
276
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
277
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
278
|
+
* const worksheetPermission = fWorksheet.getWorksheetPermission();
|
|
279
|
+
* const rules = await worksheetPermission.listRangeProtectionRules();
|
|
280
|
+
* // Unprotect the first rule as an example
|
|
281
|
+
* if (rules.length > 0) {
|
|
282
|
+
* const result = await worksheetPermission.unprotectRules([rules[0].id]);
|
|
283
|
+
* console.log(result);
|
|
284
|
+
* }
|
|
371
285
|
* ```
|
|
372
286
|
*/
|
|
373
|
-
unprotectRules(ruleIds: string[]): Promise<
|
|
287
|
+
unprotectRules(ruleIds: string[]): Promise<boolean>;
|
|
374
288
|
/**
|
|
375
289
|
* List all range protection rules for the worksheet.
|
|
376
290
|
* @returns {Promise<FRangeProtectionRule[]>} Array of protection rules.
|
|
377
291
|
* @example
|
|
378
292
|
* ```ts
|
|
379
|
-
* const
|
|
380
|
-
* const
|
|
381
|
-
* const rules = await
|
|
293
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
294
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
295
|
+
* const rules = await fWorksheet.getWorksheetPermission().listRangeProtectionRules();
|
|
382
296
|
* console.log(rules);
|
|
383
297
|
* ```
|
|
384
298
|
*/
|
|
385
|
-
listRangeProtectionRules(
|
|
299
|
+
listRangeProtectionRules(options?: {
|
|
300
|
+
ignoreCollaborators?: boolean;
|
|
301
|
+
}): Promise<FRangeProtectionRule[]>;
|
|
386
302
|
/**
|
|
387
|
-
*
|
|
388
|
-
* @param {
|
|
389
|
-
* @
|
|
303
|
+
* Debug cell permission information.
|
|
304
|
+
* @param {number} row Row index.
|
|
305
|
+
* @param {number} col Column index.
|
|
306
|
+
* @returns {FRangeProtectionRule | undefined} Debug information about which rules affect this cell, or null if no rules apply.
|
|
390
307
|
* @example
|
|
391
308
|
* ```ts
|
|
392
|
-
* const
|
|
393
|
-
* const
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
* unsubscribe?.();
|
|
309
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
310
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
311
|
+
* // Get debug info for cell C3
|
|
312
|
+
* const fRange = fWorksheet.getRange('C3');
|
|
313
|
+
* const debugInfo = await fWorksheet.getWorksheetPermission().debugCellPermission(fRange.getRow(), fRange.getColumn());
|
|
314
|
+
* console.log(debugInfo);
|
|
399
315
|
* ```
|
|
400
316
|
*/
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Clean up resources
|
|
404
|
-
*/
|
|
405
|
-
dispose(): void;
|
|
317
|
+
debugCellPermission(row: number, col: number): Promise<FRangeProtectionRule | undefined>;
|
|
406
318
|
}
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IUser } from '@univerjs/protocol';
|
|
17
|
-
import type { Observable } from 'rxjs';
|
|
18
16
|
/**
|
|
19
17
|
* ========================
|
|
20
18
|
* Basic Types / Enums
|
|
@@ -28,23 +26,14 @@ export declare enum UnitRole {
|
|
|
28
26
|
Editor = 1,
|
|
29
27
|
Owner = 2
|
|
30
28
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/** User ID (defined by host system) */
|
|
36
|
-
id: string;
|
|
37
|
-
/** Display name */
|
|
38
|
-
displayName?: string;
|
|
39
|
-
/** Email address */
|
|
40
|
-
email?: string;
|
|
29
|
+
export interface ICollaboratorUser {
|
|
30
|
+
userID: string;
|
|
31
|
+
name: string;
|
|
32
|
+
avatar: string;
|
|
41
33
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Collaborator information
|
|
44
|
-
*/
|
|
45
34
|
export interface ICollaborator {
|
|
46
35
|
/** User information */
|
|
47
|
-
user:
|
|
36
|
+
user: ICollaboratorUser;
|
|
48
37
|
/** Role */
|
|
49
38
|
role: UnitRole;
|
|
50
39
|
}
|
|
@@ -173,10 +162,6 @@ export type WorksheetPermissionSnapshot = Record<WorksheetPermissionPoint, boole
|
|
|
173
162
|
* Range permission snapshot (state of all permission points)
|
|
174
163
|
*/
|
|
175
164
|
export type RangePermissionSnapshot = Record<RangePermissionPoint, boolean>;
|
|
176
|
-
/**
|
|
177
|
-
* Unsubscribe function type
|
|
178
|
-
*/
|
|
179
|
-
export type UnsubscribeFn = () => void;
|
|
180
165
|
/**
|
|
181
166
|
* ========================
|
|
182
167
|
* Worksheet Protection Configuration
|
|
@@ -186,8 +171,15 @@ export type UnsubscribeFn = () => void;
|
|
|
186
171
|
* Worksheet protection options configuration
|
|
187
172
|
*/
|
|
188
173
|
export interface IWorksheetProtectionOptions {
|
|
189
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* Specifies users allowed to edit this worksheet; if not specified, defaults to only the owner having edit permission.
|
|
176
|
+
*/
|
|
190
177
|
allowedUsers?: string[];
|
|
178
|
+
/**
|
|
179
|
+
* Whether to allow others to view this range.
|
|
180
|
+
* @default true
|
|
181
|
+
*/
|
|
182
|
+
allowViewByOthers?: boolean;
|
|
191
183
|
/** Protection name for UI display */
|
|
192
184
|
name?: string;
|
|
193
185
|
/** Custom metadata */
|
|
@@ -202,108 +194,20 @@ export interface IWorksheetProtectionOptions {
|
|
|
202
194
|
* Range protection options configuration
|
|
203
195
|
*/
|
|
204
196
|
export interface IRangeProtectionOptions {
|
|
205
|
-
/**
|
|
206
|
-
|
|
207
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Specifies users allowed to edit this range; if not specified, defaults to only the owner having edit permission.
|
|
199
|
+
*/
|
|
208
200
|
allowedUsers?: string[];
|
|
201
|
+
/**
|
|
202
|
+
* Whether to allow others to view this range.
|
|
203
|
+
* @default true
|
|
204
|
+
*/
|
|
209
205
|
allowViewByOthers?: boolean;
|
|
210
206
|
/** Rule name for UI display and management */
|
|
211
207
|
name?: string;
|
|
212
208
|
/** Custom metadata (logs, tags, etc.) */
|
|
213
209
|
metadata?: Record<string, unknown>;
|
|
214
210
|
}
|
|
215
|
-
/**
|
|
216
|
-
* Cell permission debug rule information
|
|
217
|
-
*/
|
|
218
|
-
export interface ICellPermissionDebugRuleInfo {
|
|
219
|
-
ruleId: string;
|
|
220
|
-
/** Range reference string list, e.g., ['A1:B10', 'D1:D5'] */
|
|
221
|
-
rangeRefs: string[];
|
|
222
|
-
options: IRangeProtectionOptions;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* ========================
|
|
226
|
-
* Facade: WorkbookPermission
|
|
227
|
-
* ========================
|
|
228
|
-
*/
|
|
229
|
-
/**
|
|
230
|
-
* Workbook-level permission Facade interface
|
|
231
|
-
*/
|
|
232
|
-
export interface IWorkbookPermission {
|
|
233
|
-
/**
|
|
234
|
-
* High-level mode setting: By Owner / Editor / Viewer / Commenter semantics
|
|
235
|
-
* Internally automatically combines multiple WorkbookPermissionPoints
|
|
236
|
-
*/
|
|
237
|
-
setMode(mode: WorkbookMode): Promise<void>;
|
|
238
|
-
/** Shortcut: Set workbook to read-only (equivalent to setMode('viewer')) */
|
|
239
|
-
setReadOnly(): Promise<void>;
|
|
240
|
-
/** Shortcut: Set workbook to editable (equivalent to setMode('editor') or owner subset) */
|
|
241
|
-
setEditable(): Promise<void>;
|
|
242
|
-
/** Whether current user can edit this workbook (calculated from combined permissions) */
|
|
243
|
-
canEdit(): boolean;
|
|
244
|
-
/**
|
|
245
|
-
* Collaborator management (wraps IAuthzIoService)
|
|
246
|
-
*/
|
|
247
|
-
/** Batch set collaborators (replace mode, overwrites existing collaborator list) */
|
|
248
|
-
setCollaborators(collaborators: Array<{
|
|
249
|
-
user: IUser;
|
|
250
|
-
role: UnitRole;
|
|
251
|
-
}>): Promise<void>;
|
|
252
|
-
/** Add a single collaborator */
|
|
253
|
-
addCollaborator(user: IUser, role: UnitRole): Promise<void>;
|
|
254
|
-
/** Update collaborator role and information */
|
|
255
|
-
updateCollaborator(user: IUser, role: UnitRole): Promise<void>;
|
|
256
|
-
/** Remove collaborator */
|
|
257
|
-
removeCollaborator(userId: string): Promise<void>;
|
|
258
|
-
/** Batch remove collaborators */
|
|
259
|
-
removeCollaborators(userIds: string[]): Promise<void>;
|
|
260
|
-
/** List all collaborators */
|
|
261
|
-
listCollaborators(): Promise<ICollaborator[]>;
|
|
262
|
-
/**
|
|
263
|
-
* Low-level point operations: Directly set boolean value of a WorkbookPermissionPoint
|
|
264
|
-
*/
|
|
265
|
-
setPoint(point: WorkbookPermissionPoint, value: boolean): Promise<void>;
|
|
266
|
-
/** Read current value of a point (synchronous, reads from local state) */
|
|
267
|
-
getPoint(point: WorkbookPermissionPoint): boolean;
|
|
268
|
-
/** Get snapshot of all current points */
|
|
269
|
-
getSnapshot(): WorkbookPermissionSnapshot;
|
|
270
|
-
/**
|
|
271
|
-
* ========================
|
|
272
|
-
* RxJS Observable Reactive Interface
|
|
273
|
-
* ========================
|
|
274
|
-
*/
|
|
275
|
-
/**
|
|
276
|
-
* Permission snapshot change stream (BehaviorSubject, immediately provides current state on subscription)
|
|
277
|
-
* Triggers when any permission point changes
|
|
278
|
-
*/
|
|
279
|
-
readonly permission$: Observable<WorkbookPermissionSnapshot>;
|
|
280
|
-
/**
|
|
281
|
-
* Single permission point change stream
|
|
282
|
-
* For scenarios that only care about specific permission point changes
|
|
283
|
-
*/
|
|
284
|
-
readonly pointChange$: Observable<{
|
|
285
|
-
point: WorkbookPermissionPoint;
|
|
286
|
-
value: boolean;
|
|
287
|
-
oldValue: boolean;
|
|
288
|
-
}>;
|
|
289
|
-
/**
|
|
290
|
-
* Collaborator change stream
|
|
291
|
-
*/
|
|
292
|
-
readonly collaboratorChange$: Observable<{
|
|
293
|
-
type: 'add' | 'update' | 'delete';
|
|
294
|
-
collaborator: ICollaborator;
|
|
295
|
-
}>;
|
|
296
|
-
/**
|
|
297
|
-
* Compatibility method: Simplified subscription (for users unfamiliar with RxJS)
|
|
298
|
-
* Internally implemented based on permission$ Observable
|
|
299
|
-
*/
|
|
300
|
-
subscribe(listener: (snapshot: WorkbookPermissionSnapshot) => void): UnsubscribeFn;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* ========================
|
|
304
|
-
* Facade: WorksheetPermission
|
|
305
|
-
* ========================
|
|
306
|
-
*/
|
|
307
211
|
/**
|
|
308
212
|
* Worksheet permission configuration
|
|
309
213
|
*/
|
|
@@ -318,12 +222,3 @@ export interface IWorksheetPermissionConfig {
|
|
|
318
222
|
options?: IRangeProtectionOptions;
|
|
319
223
|
}>;
|
|
320
224
|
}
|
|
321
|
-
/**
|
|
322
|
-
* ========================
|
|
323
|
-
* Facade: RangePermission
|
|
324
|
-
* ========================
|
|
325
|
-
*/
|
|
326
|
-
export interface ICellPermissionDebugInfo {
|
|
327
|
-
permissionId: string;
|
|
328
|
-
ruleId: string;
|
|
329
|
-
}
|