@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.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +3 -3
- package/lib/cjs/locale/ja-JP.js +1 -0
- package/lib/es/facade.js +5551 -3674
- package/lib/es/index.js +3854 -3852
- package/lib/es/locale/ja-JP.js +17 -0
- package/lib/facade.js +5551 -3674
- package/lib/index.js +3854 -3852
- package/lib/locale/ja-JP.js +17 -0
- package/lib/types/commands/commands/clear-selection-content.command.d.ts +6 -1
- package/lib/types/controllers/permission/sheet-permission-init.controller.d.ts +0 -13
- package/lib/types/facade/f-permission.d.ts +41 -2
- package/lib/types/facade/f-range.d.ts +30 -0
- package/lib/types/facade/f-workbook.d.ts +28 -0
- package/lib/types/facade/f-worksheet.d.ts +31 -0
- package/lib/types/facade/permission/f-range-permission.d.ts +270 -0
- package/lib/types/facade/permission/f-range-protection-rule.d.ts +108 -0
- package/lib/types/facade/permission/f-workbook-permission.d.ts +270 -0
- package/lib/types/facade/permission/f-worksheet-permission.d.ts +335 -0
- package/lib/types/facade/permission/index.d.ts +21 -0
- package/lib/types/facade/permission/permission-point-map.d.ts +14 -0
- package/lib/types/facade/permission/permission-types.d.ts +483 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/locale/ja-JP.d.ts +3 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +3 -3
- package/lib/umd/locale/ja-JP.js +1 -0
- package/package.json +8 -8
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const e = {
|
|
2
|
+
sheets: {
|
|
3
|
+
tabs: {
|
|
4
|
+
sheetCopy: "(복사본{0})",
|
|
5
|
+
sheet: "시트"
|
|
6
|
+
},
|
|
7
|
+
info: {
|
|
8
|
+
overlappingSelections: "겹치는 영역에서는 해당 명령을 사용할 수 없습니다.",
|
|
9
|
+
acrossMergedCell: "병합된 셀을 가로지름",
|
|
10
|
+
partOfCell: "병합된 셀의 일부만 선택됨",
|
|
11
|
+
hideSheet: "이 시트를 숨기면 표시되는 시트가 없습니다."
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
e as default
|
|
17
|
+
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { ICommand } from '@univerjs/core';
|
|
1
|
+
import { ICommand, IRange } from '@univerjs/core';
|
|
2
|
+
export interface IClearSelectionContentCommandParams {
|
|
3
|
+
unitId?: string;
|
|
4
|
+
subUnitId?: string;
|
|
5
|
+
ranges?: IRange[];
|
|
6
|
+
}
|
|
2
7
|
/**
|
|
3
8
|
* The command to clear content in current selected ranges.
|
|
4
9
|
*/
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { IDeleteWorksheetProtectionParams } from '../../commands/mutations/delete-worksheet-protection.mutation';
|
|
2
1
|
import { Disposable, IAuthzIoService, ICommandService, IPermissionService, IUndoRedoService, IUniverInstanceService, UserManagerService } from '@univerjs/core';
|
|
3
2
|
import { RangeProtectionRuleModel } from '../../model/range-protection-rule.model';
|
|
4
3
|
import { WorkbookPermissionService } from '../../services/permission/workbook-permission/workbook-permission.service';
|
|
5
4
|
import { WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '../../services/permission/worksheet-permission';
|
|
6
|
-
interface ISheetPermissionCmdBufferListItemType {
|
|
7
|
-
id: string;
|
|
8
|
-
params: IDeleteWorksheetProtectionParams;
|
|
9
|
-
}
|
|
10
5
|
export declare class SheetPermissionInitController extends Disposable {
|
|
11
6
|
private readonly _univerInstanceService;
|
|
12
7
|
private _permissionService;
|
|
@@ -18,16 +13,9 @@ export declare class SheetPermissionInitController extends Disposable {
|
|
|
18
13
|
private _workbookPermissionService;
|
|
19
14
|
private _undoRedoService;
|
|
20
15
|
private _commandService;
|
|
21
|
-
private _cmdBufferList;
|
|
22
|
-
private _isRangePermissionInitFinish;
|
|
23
|
-
private _isWorksheetPermissionInitFinish;
|
|
24
|
-
private _isWorkbookPermissionInitFinish;
|
|
25
16
|
constructor(_univerInstanceService: IUniverInstanceService, _permissionService: IPermissionService, _authzIoService: IAuthzIoService, _rangeProtectionRuleModel: RangeProtectionRuleModel, _worksheetProtectionRuleModel: WorksheetProtectionRuleModel, _userManagerService: UserManagerService, _worksheetProtectionPointRuleModel: WorksheetProtectionPointModel, _workbookPermissionService: WorkbookPermissionService, _undoRedoService: IUndoRedoService, _commandService: ICommandService);
|
|
26
17
|
initPermission(): void;
|
|
27
18
|
refreshRangeProtectPermission(): void;
|
|
28
|
-
getIsPermissionInitFinish(): boolean;
|
|
29
|
-
addCmdToBufferList(item: ISheetPermissionCmdBufferListItemType): void;
|
|
30
|
-
private _processCmdBufferList;
|
|
31
19
|
private _initRangePermissionFromSnapshot;
|
|
32
20
|
private _initRangePermissionChange;
|
|
33
21
|
initWorkbookPermissionChange(_unitId?: string): Promise<void>;
|
|
@@ -39,4 +27,3 @@ export declare class SheetPermissionInitController extends Disposable {
|
|
|
39
27
|
refreshPermission(unitId: string, permissionId: string): void;
|
|
40
28
|
private _refreshPermissionByCollaCreate;
|
|
41
29
|
}
|
|
42
|
-
export {};
|
|
@@ -5,6 +5,29 @@ import { FBase } from '@univerjs/core/facade';
|
|
|
5
5
|
import { RangeProtectionRuleModel, WorkbookEditablePermission, WorkbookPermissionService, WorksheetEditPermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetViewPermission } from '@univerjs/sheets';
|
|
6
6
|
/**
|
|
7
7
|
* @description Used to generate permission instances to control permissions for the entire workbook
|
|
8
|
+
* @deprecated This class is deprecated. Use the new permission API instead:
|
|
9
|
+
* - For workbook-level permissions, use `workbook.getWorkbookPermission()`
|
|
10
|
+
* - For worksheet-level permissions, use `worksheet.getWorksheetPermission()`
|
|
11
|
+
* - For range-level permissions, use `range.getRangePermission()`
|
|
12
|
+
*
|
|
13
|
+
* The new API provides:
|
|
14
|
+
* - More intuitive and type-safe interfaces
|
|
15
|
+
* - Better support for RxJS Observable streams
|
|
16
|
+
* - Enum-based permission points instead of class constructors
|
|
17
|
+
* - Simplified collaborator management
|
|
18
|
+
* - Mode-based permission settings (viewer, editor, owner, etc.)
|
|
19
|
+
*
|
|
20
|
+
* Migration examples:
|
|
21
|
+
* ```ts
|
|
22
|
+
* // Old API
|
|
23
|
+
* const permission = workbook.getPermission();
|
|
24
|
+
* await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
|
|
25
|
+
*
|
|
26
|
+
* // New API
|
|
27
|
+
* const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
28
|
+
* const permission = worksheet.getWorksheetPermission();
|
|
29
|
+
* await permission.protectRanges([{ ranges, options: { name: 'Protected', allowEdit: false } }]);
|
|
30
|
+
* ```
|
|
8
31
|
* @hideconstructor
|
|
9
32
|
*/
|
|
10
33
|
export declare class FPermission extends FBase {
|
|
@@ -205,6 +228,7 @@ export declare class FPermission extends FBase {
|
|
|
205
228
|
* Adds a range protection to the worksheet.
|
|
206
229
|
* Note that after adding, only the background mask of the permission module will be rendered. If you want to modify the function permissions,
|
|
207
230
|
* you need to modify the permission points with the permissionId returned by this function.
|
|
231
|
+
* @deprecated Use `worksheet.getWorksheetPermission().protectRanges()` instead
|
|
208
232
|
* @param {string} unitId - The unique identifier of the workbook.
|
|
209
233
|
* @param {string} subUnitId - The unique identifier of the worksheet.
|
|
210
234
|
* @param {FRange[]} ranges - The ranges to be protected.
|
|
@@ -212,6 +236,7 @@ export declare class FPermission extends FBase {
|
|
|
212
236
|
*
|
|
213
237
|
* @example
|
|
214
238
|
* ```typescript
|
|
239
|
+
* // Old API
|
|
215
240
|
* const workbook = univerAPI.getActiveWorkbook();
|
|
216
241
|
* const permission = workbook.getPermission();
|
|
217
242
|
* const unitId = workbook.getId();
|
|
@@ -220,11 +245,18 @@ export declare class FPermission extends FBase {
|
|
|
220
245
|
* const range = worksheet.getRange('A1:B2');
|
|
221
246
|
* const ranges = [];
|
|
222
247
|
* ranges.push(range);
|
|
223
|
-
* // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes.
|
|
224
|
-
* // For details, please see the example of the **`setRangeProtectionPermissionPoint`** API.
|
|
225
248
|
* const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
|
|
226
249
|
* const {permissionId, ruleId} = res;
|
|
227
250
|
* console.log('debugger', permissionId, ruleId);
|
|
251
|
+
*
|
|
252
|
+
* // New API (recommended)
|
|
253
|
+
* const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
|
|
254
|
+
* const permission = worksheet.getWorksheetPermission();
|
|
255
|
+
* const range = worksheet.getRange('A1:B2');
|
|
256
|
+
* await permission.protectRanges([{
|
|
257
|
+
* ranges: [range],
|
|
258
|
+
* options: { name: 'Protected Area', allowEdit: false }
|
|
259
|
+
* }]);
|
|
228
260
|
* ```
|
|
229
261
|
*/
|
|
230
262
|
addRangeBaseProtection(unitId: string, subUnitId: string, ranges: FRange[]): Promise<{
|
|
@@ -233,12 +265,14 @@ export declare class FPermission extends FBase {
|
|
|
233
265
|
} | undefined>;
|
|
234
266
|
/**
|
|
235
267
|
* Removes the range protection from the worksheet.
|
|
268
|
+
* @deprecated Use `worksheet.getWorksheetPermission().unprotectRules()` instead
|
|
236
269
|
* @param {string} unitId - The unique identifier of the workbook.
|
|
237
270
|
* @param {string} subUnitId - The unique identifier of the worksheet.
|
|
238
271
|
* @param {string[]} ruleIds - The rule IDs of the range protection to be removed.
|
|
239
272
|
*
|
|
240
273
|
* @example
|
|
241
274
|
* ```typescript
|
|
275
|
+
* // Old API
|
|
242
276
|
* const workbook = univerAPI.getActiveWorkbook();
|
|
243
277
|
* const permission = workbook.getPermission();
|
|
244
278
|
* const unitId = workbook.getId();
|
|
@@ -250,6 +284,11 @@ export declare class FPermission extends FBase {
|
|
|
250
284
|
* const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
|
|
251
285
|
* const ruleId = res.ruleId;
|
|
252
286
|
* permission.removeRangeProtection(unitId, subUnitId, [ruleId]);
|
|
287
|
+
*
|
|
288
|
+
* // New API (recommended)
|
|
289
|
+
* const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
|
|
290
|
+
* const permission = worksheet.getWorksheetPermission();
|
|
291
|
+
* await permission.unprotectRules([ruleId]);
|
|
253
292
|
* ```
|
|
254
293
|
*/
|
|
255
294
|
removeRangeProtection(unitId: string, subUnitId: string, ruleIds: string[]): void;
|
|
@@ -4,6 +4,7 @@ import { IFacadeClearOptions } from './f-worksheet';
|
|
|
4
4
|
import { FHorizontalAlignment, FVerticalAlignment } from './utils';
|
|
5
5
|
import { FBaseInitialable } from '@univerjs/core/facade';
|
|
6
6
|
import { FormulaDataModel } from '@univerjs/engine-formula';
|
|
7
|
+
import { FRangePermission } from './permission/f-range-permission';
|
|
7
8
|
export type FontLine = 'none' | 'underline' | 'line-through';
|
|
8
9
|
export type FontStyle = 'normal' | 'italic';
|
|
9
10
|
export type FontWeight = 'normal' | 'bold';
|
|
@@ -1531,4 +1532,33 @@ export declare class FRange extends FBaseInitialable {
|
|
|
1531
1532
|
* ```
|
|
1532
1533
|
*/
|
|
1533
1534
|
setFormulas(formulas: string[][]): FRange;
|
|
1535
|
+
/**
|
|
1536
|
+
* Get the RangePermission instance for managing range-level permissions.
|
|
1537
|
+
* This is the new permission API that provides range-specific permission control.
|
|
1538
|
+
* @returns {FRangePermission} - The RangePermission instance.
|
|
1539
|
+
* @example
|
|
1540
|
+
* ```ts
|
|
1541
|
+
* const fWorksheet = univerAPI.getActiveWorkbook().getActiveSheet();
|
|
1542
|
+
* const fRange = fWorksheet.getRange('A1:B10');
|
|
1543
|
+
* const permission = fRange.getRangePermission();
|
|
1544
|
+
*
|
|
1545
|
+
* // Protect the range
|
|
1546
|
+
* await permission.protect({ name: 'Protected Area', allowEdit: false });
|
|
1547
|
+
*
|
|
1548
|
+
* // Check if range is protected
|
|
1549
|
+
* const isProtected = permission.isProtected();
|
|
1550
|
+
*
|
|
1551
|
+
* // Check if current user can edit
|
|
1552
|
+
* const canEdit = permission.canEdit();
|
|
1553
|
+
*
|
|
1554
|
+
* // Unprotect the range
|
|
1555
|
+
* await permission.unprotect();
|
|
1556
|
+
*
|
|
1557
|
+
* // Subscribe to protection changes
|
|
1558
|
+
* permission.protectionChange$.subscribe(change => {
|
|
1559
|
+
* console.log('Protection changed:', change);
|
|
1560
|
+
* });
|
|
1561
|
+
* ```
|
|
1562
|
+
*/
|
|
1563
|
+
getRangePermission(): FRangePermission;
|
|
1534
1564
|
}
|
|
@@ -6,6 +6,7 @@ import { FBaseInitialable } from '@univerjs/core/facade';
|
|
|
6
6
|
import { FDefinedName } from './f-defined-name';
|
|
7
7
|
import { FPermission } from './f-permission';
|
|
8
8
|
import { FWorksheet } from './f-worksheet';
|
|
9
|
+
import { FWorkbookPermission } from './permission/f-workbook-permission';
|
|
9
10
|
/**
|
|
10
11
|
* Facade API object bounded to a workbook. It provides a set of methods to interact with the workbook.
|
|
11
12
|
* @hideconstructor
|
|
@@ -491,6 +492,7 @@ export declare class FWorkbook extends FBaseInitialable {
|
|
|
491
492
|
/**
|
|
492
493
|
* Get the PermissionInstance.
|
|
493
494
|
* @returns {FPermission} - The PermissionInstance.
|
|
495
|
+
* @deprecated Use `getWorkbookPermission()` instead for the new permission API
|
|
494
496
|
* @example
|
|
495
497
|
* ```ts
|
|
496
498
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
@@ -499,6 +501,32 @@ export declare class FWorkbook extends FBaseInitialable {
|
|
|
499
501
|
* ```
|
|
500
502
|
*/
|
|
501
503
|
getPermission(): FPermission;
|
|
504
|
+
/**
|
|
505
|
+
* Get the WorkbookPermission instance for managing workbook-level permissions.
|
|
506
|
+
* This is the new permission API that provides a more intuitive and type-safe interface.
|
|
507
|
+
* @returns {FWorkbookPermission} - The WorkbookPermission instance.
|
|
508
|
+
* @example
|
|
509
|
+
* ```ts
|
|
510
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
511
|
+
* const permission = fWorkbook.getWorkbookPermission();
|
|
512
|
+
*
|
|
513
|
+
* // Set workbook to read-only mode
|
|
514
|
+
* await permission.setMode('viewer');
|
|
515
|
+
*
|
|
516
|
+
* // Add a collaborator
|
|
517
|
+
* await permission.addCollaborator({
|
|
518
|
+
* userId: 'user123',
|
|
519
|
+
* name: 'John Doe',
|
|
520
|
+
* role: 'editor'
|
|
521
|
+
* });
|
|
522
|
+
*
|
|
523
|
+
* // Subscribe to permission changes
|
|
524
|
+
* permission.permission$.subscribe(snapshot => {
|
|
525
|
+
* console.log('Permissions changed:', snapshot);
|
|
526
|
+
* });
|
|
527
|
+
* ```
|
|
528
|
+
*/
|
|
529
|
+
getWorkbookPermission(): FWorkbookPermission;
|
|
502
530
|
/**
|
|
503
531
|
* Get the defined name by name.
|
|
504
532
|
* @param {string} name The name of the defined name to get
|
|
@@ -5,6 +5,7 @@ import { FBaseInitialable } from '@univerjs/core/facade';
|
|
|
5
5
|
import { SheetsSelectionsService } from '@univerjs/sheets';
|
|
6
6
|
import { FRange } from './f-range';
|
|
7
7
|
import { FSelection } from './f-selection';
|
|
8
|
+
import { FWorksheetPermission } from './permission/f-worksheet-permission';
|
|
8
9
|
export interface IFacadeClearOptions {
|
|
9
10
|
contentsOnly?: boolean;
|
|
10
11
|
formatOnly?: boolean;
|
|
@@ -1449,4 +1450,34 @@ export declare class FWorksheet extends FBaseInitialable {
|
|
|
1449
1450
|
* ```
|
|
1450
1451
|
*/
|
|
1451
1452
|
setColumnCount(columnCount: number): FWorksheet;
|
|
1453
|
+
/**
|
|
1454
|
+
* Get the WorksheetPermission instance for managing worksheet-level permissions.
|
|
1455
|
+
* This is the new permission API that provides worksheet-specific permission control.
|
|
1456
|
+
* @returns {FWorksheetPermission} - The WorksheetPermission instance.
|
|
1457
|
+
* @example
|
|
1458
|
+
* ```ts
|
|
1459
|
+
* const fWorksheet = univerAPI.getActiveWorkbook().getActiveSheet();
|
|
1460
|
+
* const permission = fWorksheet.getWorksheetPermission();
|
|
1461
|
+
*
|
|
1462
|
+
* // Set worksheet to read-only mode
|
|
1463
|
+
* await permission.setMode('readOnly');
|
|
1464
|
+
*
|
|
1465
|
+
* // Check if a specific cell can be edited
|
|
1466
|
+
* const canEdit = permission.canEditCell(0, 0);
|
|
1467
|
+
*
|
|
1468
|
+
* // Protect multiple ranges at once
|
|
1469
|
+
* const range1 = fWorksheet.getRange('A1:B10');
|
|
1470
|
+
* const range2 = fWorksheet.getRange('D1:E10');
|
|
1471
|
+
* await permission.protectRanges([
|
|
1472
|
+
* { ranges: [range1], options: { name: 'Range 1', allowEdit: false } },
|
|
1473
|
+
* { ranges: [range2], options: { name: 'Range 2', allowEdit: false } }
|
|
1474
|
+
* ]);
|
|
1475
|
+
*
|
|
1476
|
+
* // Subscribe to permission changes
|
|
1477
|
+
* permission.permission$.subscribe(snapshot => {
|
|
1478
|
+
* console.log('Worksheet permissions changed:', snapshot);
|
|
1479
|
+
* });
|
|
1480
|
+
* ```
|
|
1481
|
+
*/
|
|
1482
|
+
getWorksheetPermission(): FWorksheetPermission;
|
|
1452
1483
|
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { FRange } from '../f-range';
|
|
3
|
+
import { FWorksheet } from '../f-worksheet';
|
|
4
|
+
import { IRangeProtectionRule as IFRangeProtectionRule, IRangePermission, IRangeProtectionOptions, RangePermissionSnapshot, RangePermissionPoint } from './permission-types';
|
|
5
|
+
import { IAuthzIoService, ICommandService, Injector, IPermissionService } from '@univerjs/core';
|
|
6
|
+
import { RangeProtectionRuleModel } from '@univerjs/sheets';
|
|
7
|
+
/**
|
|
8
|
+
* Implementation class for RangePermission
|
|
9
|
+
* Manages range-level permissions
|
|
10
|
+
*
|
|
11
|
+
* @hideconstructor
|
|
12
|
+
*/
|
|
13
|
+
export declare class FRangePermission implements IRangePermission {
|
|
14
|
+
private readonly _unitId;
|
|
15
|
+
private readonly _subUnitId;
|
|
16
|
+
private readonly _range;
|
|
17
|
+
private readonly _worksheet;
|
|
18
|
+
private readonly _injector;
|
|
19
|
+
private readonly _permissionService;
|
|
20
|
+
private readonly _authzIoService;
|
|
21
|
+
private readonly _commandService;
|
|
22
|
+
private readonly _rangeProtectionRuleModel;
|
|
23
|
+
private readonly _permissionSubject;
|
|
24
|
+
private readonly _subscriptions;
|
|
25
|
+
/**
|
|
26
|
+
* Observable stream of permission snapshot changes
|
|
27
|
+
* @returns Observable that emits when permission snapshot changes
|
|
28
|
+
*/
|
|
29
|
+
readonly permission$: Observable<RangePermissionSnapshot>;
|
|
30
|
+
/**
|
|
31
|
+
* Observable stream of protection state changes
|
|
32
|
+
* @returns Observable that emits when protection state changes
|
|
33
|
+
*/
|
|
34
|
+
readonly protectionChange$: Observable<{
|
|
35
|
+
type: 'protected';
|
|
36
|
+
rule: IFRangeProtectionRule;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'unprotected';
|
|
39
|
+
ruleId: string;
|
|
40
|
+
}>;
|
|
41
|
+
constructor(_unitId: string, _subUnitId: string, _range: FRange, _worksheet: FWorksheet, _injector: Injector, _permissionService: IPermissionService, _authzIoService: IAuthzIoService, _commandService: ICommandService, _rangeProtectionRuleModel: RangeProtectionRuleModel);
|
|
42
|
+
/**
|
|
43
|
+
* Create permission snapshot stream from IPermissionService
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
private _createPermissionStream;
|
|
47
|
+
/**
|
|
48
|
+
* Create protection change stream from RangeProtectionRuleModel
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
private _createProtectionChangeStream;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a protection rule matches this range
|
|
54
|
+
*/
|
|
55
|
+
private _rangeMatches;
|
|
56
|
+
/**
|
|
57
|
+
* Create a Facade rule from internal rule
|
|
58
|
+
*/
|
|
59
|
+
private _createFacadeRule;
|
|
60
|
+
/**
|
|
61
|
+
* Get the value of a specific permission point.
|
|
62
|
+
* @param {RangePermissionPoint} point The permission point to query.
|
|
63
|
+
* @returns {boolean} true if allowed, false if denied.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
67
|
+
* const permission = range?.getRangePermission();
|
|
68
|
+
* const canEdit = permission?.getPoint(RangePermissionPoint.Edit);
|
|
69
|
+
* console.log(canEdit);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
getPoint(point: RangePermissionPoint): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current permission snapshot.
|
|
75
|
+
* @returns {RangePermissionSnapshot} Snapshot of all permission points.
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
79
|
+
* const permission = range?.getRangePermission();
|
|
80
|
+
* const snapshot = permission?.getSnapshot();
|
|
81
|
+
* console.log(snapshot);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
getSnapshot(): RangePermissionSnapshot;
|
|
85
|
+
/**
|
|
86
|
+
* Check if the current range is protected.
|
|
87
|
+
* @returns {boolean} true if protected, false otherwise.
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
91
|
+
* const permission = range?.getRangePermission();
|
|
92
|
+
* const isProtected = permission?.isProtected();
|
|
93
|
+
* console.log(isProtected);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
isProtected(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Check if the current user can edit this range.
|
|
99
|
+
* @returns {boolean} true if editable, false otherwise.
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
103
|
+
* const permission = range?.getRangePermission();
|
|
104
|
+
* if (permission?.canEdit()) {
|
|
105
|
+
* console.log('You can edit this range');
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
canEdit(): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Check if the current user can view this range.
|
|
112
|
+
* @returns {boolean} true if viewable, false otherwise.
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
116
|
+
* const permission = range?.getRangePermission();
|
|
117
|
+
* if (permission?.canView()) {
|
|
118
|
+
* console.log('You can view this range');
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
canView(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Check if the current user can manage collaborators for this range.
|
|
125
|
+
* @returns {boolean} true if can manage collaborators, false otherwise.
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
129
|
+
* const permission = range?.getRangePermission();
|
|
130
|
+
* if (permission?.canManageCollaborator()) {
|
|
131
|
+
* console.log('You can manage collaborators for this range');
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
canManageCollaborator(): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Check if the current user can delete this protection rule.
|
|
138
|
+
* @returns {boolean} true if can delete rule, false otherwise.
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
142
|
+
* const permission = range?.getRangePermission();
|
|
143
|
+
* if (permission?.canDelete()) {
|
|
144
|
+
* console.log('You can delete this protection rule');
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
canDelete(): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Set a specific permission point for the range (low-level API for local runtime control).
|
|
151
|
+
* This method directly sets the permission point value for the current range protection rule.
|
|
152
|
+
* If no protection rule exists, it will create permission points without a rule (local-only mode).
|
|
153
|
+
* @param {RangePermissionPoint} point The permission point to set.
|
|
154
|
+
* @param {boolean} value The value to set (true = allowed, false = denied).
|
|
155
|
+
* @returns {Promise<void>} A promise that resolves when the point is set.
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
159
|
+
* const permission = range?.getRangePermission();
|
|
160
|
+
* // Can set permission points without calling protect() first (local-only mode)
|
|
161
|
+
* await permission?.setPoint(RangePermissionPoint.Edit, false); // Disable edit
|
|
162
|
+
* await permission?.setPoint(RangePermissionPoint.View, true); // Enable view
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
setPoint(point: RangePermissionPoint, value: boolean): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Get a local-only permission ID for this range (used when no protection rule exists)
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
170
|
+
private _getLocalPermissionId;
|
|
171
|
+
/**
|
|
172
|
+
* Protect the current range.
|
|
173
|
+
* @param {IRangeProtectionOptions} options Protection options.
|
|
174
|
+
* @returns {Promise<IFRangeProtectionRule>} The created protection rule.
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
178
|
+
* const permission = range?.getRangePermission();
|
|
179
|
+
* const rule = await permission?.protect({
|
|
180
|
+
* name: 'My protected range',
|
|
181
|
+
* allowEdit: false,
|
|
182
|
+
* allowView: true,
|
|
183
|
+
* allowManageCollaborator: false,
|
|
184
|
+
* allowDeleteRule: false
|
|
185
|
+
* });
|
|
186
|
+
* console.log(rule);
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
protect(options?: IRangeProtectionOptions): Promise<IFRangeProtectionRule>;
|
|
190
|
+
/**
|
|
191
|
+
* Determine view state from options
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
private _determineViewState;
|
|
195
|
+
/**
|
|
196
|
+
* Determine edit state from options
|
|
197
|
+
* @private
|
|
198
|
+
*/
|
|
199
|
+
private _determineEditState;
|
|
200
|
+
/**
|
|
201
|
+
* Set permission points based on options (for local runtime control)
|
|
202
|
+
* @private
|
|
203
|
+
*/
|
|
204
|
+
private _setPermissionPoints;
|
|
205
|
+
/**
|
|
206
|
+
* Set a single permission point
|
|
207
|
+
* @private
|
|
208
|
+
*/
|
|
209
|
+
private _setPermissionPoint;
|
|
210
|
+
/**
|
|
211
|
+
* Unprotect the current range.
|
|
212
|
+
* @returns {Promise<void>} A promise that resolves when the range is unprotected.
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
216
|
+
* const permission = range?.getRangePermission();
|
|
217
|
+
* await permission?.unprotect();
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
unprotect(): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* List all protection rules.
|
|
223
|
+
* @returns {Promise<IFRangeProtectionRule[]>} Array of protection rules.
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
227
|
+
* const permission = range?.getRangePermission();
|
|
228
|
+
* const rules = await permission?.listRules();
|
|
229
|
+
* console.log(rules);
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
listRules(): Promise<IFRangeProtectionRule[]>;
|
|
233
|
+
/**
|
|
234
|
+
* Subscribe to permission changes (simplified interface).
|
|
235
|
+
* @param {Function} listener Callback function to be called when permissions change.
|
|
236
|
+
* @returns {Function} Unsubscribe function.
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
|
|
240
|
+
* const permission = range?.getRangePermission();
|
|
241
|
+
* const unsubscribe = permission?.subscribe((snapshot) => {
|
|
242
|
+
* console.log('Permission changed:', snapshot);
|
|
243
|
+
* });
|
|
244
|
+
* // Later, to stop listening:
|
|
245
|
+
* unsubscribe?.();
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
subscribe(listener: (snapshot: RangePermissionSnapshot) => void): (() => void);
|
|
249
|
+
/**
|
|
250
|
+
* Get the protection rule for the current range
|
|
251
|
+
*/
|
|
252
|
+
private _getProtectionRule;
|
|
253
|
+
/**
|
|
254
|
+
* Build Facade objects for all protection rules
|
|
255
|
+
*/
|
|
256
|
+
private _buildProtectionRules;
|
|
257
|
+
/**
|
|
258
|
+
* Build Facade objects for all protection rules (async version with collaborator data)
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
private _buildProtectionRulesAsync;
|
|
262
|
+
/**
|
|
263
|
+
* Build permission snapshot
|
|
264
|
+
*/
|
|
265
|
+
private _buildSnapshot;
|
|
266
|
+
/**
|
|
267
|
+
* Clean up resources
|
|
268
|
+
*/
|
|
269
|
+
dispose(): void;
|
|
270
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { FRange } from '../f-range';
|
|
2
|
+
import { IRangeProtectionOptions, IRangeProtectionRule } from './permission-types';
|
|
3
|
+
import { ICommandService, Injector } from '@univerjs/core';
|
|
4
|
+
import { RangeProtectionRuleModel } from '@univerjs/sheets';
|
|
5
|
+
/**
|
|
6
|
+
* Implementation class for range protection rules
|
|
7
|
+
* Encapsulates operations on a single protection rule
|
|
8
|
+
*
|
|
9
|
+
* @hideconstructor
|
|
10
|
+
*/
|
|
11
|
+
export declare class FRangeProtectionRule implements IRangeProtectionRule {
|
|
12
|
+
private readonly _unitId;
|
|
13
|
+
private readonly _subUnitId;
|
|
14
|
+
private readonly _ruleId;
|
|
15
|
+
private readonly _permissionId;
|
|
16
|
+
private readonly _ranges;
|
|
17
|
+
private readonly _options;
|
|
18
|
+
private readonly _injector;
|
|
19
|
+
private readonly _commandService;
|
|
20
|
+
private readonly _rangeProtectionRuleModel;
|
|
21
|
+
constructor(_unitId: string, _subUnitId: string, _ruleId: string, _permissionId: string, _ranges: FRange[], _options: IRangeProtectionOptions, _injector: Injector, _commandService: ICommandService, _rangeProtectionRuleModel: RangeProtectionRuleModel);
|
|
22
|
+
/**
|
|
23
|
+
* Get the rule ID.
|
|
24
|
+
* @returns {string} The unique identifier of this protection rule.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
|
|
28
|
+
* const permission = worksheet?.permission();
|
|
29
|
+
* const rules = await permission?.listRangeProtectionRules();
|
|
30
|
+
* const ruleId = rules?.[0]?.id;
|
|
31
|
+
* console.log(ruleId);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
get id(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Get the protected ranges.
|
|
37
|
+
* @returns {FRange[]} Array of protected ranges.
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
|
|
41
|
+
* const permission = worksheet?.permission();
|
|
42
|
+
* const rules = await permission?.listRangeProtectionRules();
|
|
43
|
+
* const ranges = rules?.[0]?.ranges;
|
|
44
|
+
* console.log(ranges);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
get ranges(): FRange[];
|
|
48
|
+
/**
|
|
49
|
+
* Get the protection options.
|
|
50
|
+
* @returns {IRangeProtectionOptions} Copy of the protection options.
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
|
|
54
|
+
* const permission = worksheet?.permission();
|
|
55
|
+
* const rules = await permission?.listRangeProtectionRules();
|
|
56
|
+
* const options = rules?.[0]?.options;
|
|
57
|
+
* console.log(options);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
get options(): IRangeProtectionOptions;
|
|
61
|
+
/**
|
|
62
|
+
* Update the protected ranges.
|
|
63
|
+
* @param {FRange[]} ranges New ranges to protect.
|
|
64
|
+
* @returns {Promise<void>} A promise that resolves when the ranges are updated.
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
|
|
68
|
+
* const permission = worksheet?.permission();
|
|
69
|
+
* const rules = await permission?.listRangeProtectionRules();
|
|
70
|
+
* const rule = rules?.[0];
|
|
71
|
+
* await rule?.updateRanges([worksheet.getRange('A1:C3')]);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
updateRanges(ranges: FRange[]): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Update protection options.
|
|
77
|
+
* @param {Partial<IRangeProtectionOptions>} options Partial options to update (will be merged with existing options).
|
|
78
|
+
* @returns {Promise<void>} A promise that resolves when the options are updated.
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
|
|
82
|
+
* const permission = worksheet?.permission();
|
|
83
|
+
* const rules = await permission?.listRangeProtectionRules();
|
|
84
|
+
* const rule = rules?.[0];
|
|
85
|
+
* await rule?.updateOptions({ name: 'New Protection Name', allowEdit: true });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
updateOptions(options: Partial<IRangeProtectionOptions>): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Delete the current protection rule.
|
|
91
|
+
* @returns {Promise<void>} A promise that resolves when the rule is removed.
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
|
|
95
|
+
* const permission = worksheet?.permission();
|
|
96
|
+
* const rules = await permission?.listRangeProtectionRules();
|
|
97
|
+
* const rule = rules?.[0];
|
|
98
|
+
* await rule?.remove();
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
remove(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Check if two ranges intersect
|
|
104
|
+
* @returns true if ranges intersect, false otherwise
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
private _rangesIntersect;
|
|
108
|
+
}
|