@univerjs/sheets 0.12.2 → 0.12.3

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/index.js CHANGED
@@ -3231,6 +3231,13 @@ function Ct(n, e, t, o, s, r, i) {
3231
3231
  const c = r ? n.getCellWithFilteredInterceptors(i, l, us, ms) : n.getCellWithFilteredInterceptors(u, i, us, ms);
3232
3232
  !c || !c.s || (a[u] || (a[u] = {}), a[u][l] = { s: c.s });
3233
3233
  }
3234
+ for (const u in a) {
3235
+ for (const l in a[u]) {
3236
+ const c = a[u][l];
3237
+ c.s && typeof c.s == "object" && A.isEmptyObject(c.s) && delete c.s, A.isEmptyObject(c) && delete a[u][l];
3238
+ }
3239
+ A.isEmptyObject(a[u]) && delete a[u];
3240
+ }
3234
3241
  return a;
3235
3242
  }
3236
3243
  var Vu = Object.getOwnPropertyDescriptor, Lu = (n, e, t, o) => {
@@ -3439,7 +3446,7 @@ class Fo {
3439
3446
  R(this, "type", x.SelectRange);
3440
3447
  R(this, "subType", _.View);
3441
3448
  R(this, "status", q.INIT);
3442
- R(this, "value", !0);
3449
+ R(this, "value", !1);
3443
3450
  R(this, "id");
3444
3451
  R(this, "unitId");
3445
3452
  R(this, "subUnitId");
@@ -11458,7 +11465,7 @@ let Wt = class extends ue {
11458
11465
  }
11459
11466
  _getSelectionActions(e, t, o) {
11460
11467
  var l, c, d, h, g, m, f, C, p, w, I, S;
11461
- const s = (d = (c = this._permissionService.getPermissionPoint((l = new Ve(e, t, o.permissionId)) == null ? void 0 : l.id)) == null ? void 0 : c.value) != null ? d : !0, r = (m = (g = this._permissionService.getPermissionPoint((h = new Fo(e, t, o.permissionId)) == null ? void 0 : h.id)) == null ? void 0 : g.value) != null ? m : !0, i = (p = (C = this._permissionService.getPermissionPoint((f = new ai(e, t, o.permissionId)) == null ? void 0 : f.id)) == null ? void 0 : C.value) != null ? p : !1, a = (S = (I = this._permissionService.getPermissionPoint((w = new ii(e, t, o.permissionId)) == null ? void 0 : w.id)) == null ? void 0 : I.value) != null ? S : !1;
11468
+ const s = (d = (c = this._permissionService.getPermissionPoint((l = new Ve(e, t, o.permissionId)) == null ? void 0 : l.id)) == null ? void 0 : c.value) != null ? d : !1, r = (m = (g = this._permissionService.getPermissionPoint((h = new Fo(e, t, o.permissionId)) == null ? void 0 : h.id)) == null ? void 0 : g.value) != null ? m : !1, i = (p = (C = this._permissionService.getPermissionPoint((f = new ai(e, t, o.permissionId)) == null ? void 0 : f.id)) == null ? void 0 : C.value) != null ? p : !1, a = (S = (I = this._permissionService.getPermissionPoint((w = new ii(e, t, o.permissionId)) == null ? void 0 : w.id)) == null ? void 0 : I.value) != null ? S : !1;
11462
11469
  return {
11463
11470
  [_.Edit]: s,
11464
11471
  [_.View]: r,
@@ -1,14 +1,14 @@
1
1
  const e = {
2
2
  sheets: {
3
3
  tabs: {
4
- sheetCopy: "(복사본{0})",
5
- sheet: "시트"
4
+ sheetCopy: "(コピー{0})",
5
+ sheet: "シート"
6
6
  },
7
7
  info: {
8
- overlappingSelections: "겹치는 영역에서는 해당 명령을 사용할 수 없습니다.",
9
- acrossMergedCell: "병합된 셀을 가로지름",
10
- partOfCell: "병합된 셀의 일부만 선택됨",
11
- hideSheet: "이 시트를 숨기면 표시되는 시트가 없습니다."
8
+ overlappingSelections: "そのコマンドは、重なり合う選択範囲に対しては使用できません。",
9
+ acrossMergedCell: "結合セルをまたいでいます",
10
+ partOfCell: "結合セルの一部が選択されています",
11
+ hideSheet: "表示されるシートがなくなるため、このシートを非表示にできません。"
12
12
  }
13
13
  }
14
14
  };
@@ -1,4 +1,5 @@
1
1
  import { SheetSkeletonChangeType, SheetValueChangeType, SplitDelimiterEnum } from '@univerjs/sheets';
2
+ import { RangePermissionPoint, UnitRole, WorkbookPermissionPoint, WorksheetPermissionPoint } from './permission';
2
3
  /**
3
4
  * @ignore
4
5
  */
@@ -17,11 +18,31 @@ export interface IFSheetsEnum {
17
18
  * Split delimiter types.
18
19
  */
19
20
  SplitDelimiterType: typeof SplitDelimiterEnum;
21
+ /**
22
+ * Unit roles.
23
+ */
24
+ UnitRole: typeof UnitRole;
25
+ /**
26
+ * Workbook permission points.
27
+ */
28
+ WorkbookPermissionPoint: typeof WorkbookPermissionPoint;
29
+ /**
30
+ * Worksheet permission points.
31
+ */
32
+ WorksheetPermissionPoint: typeof WorksheetPermissionPoint;
33
+ /**
34
+ * Range permission points.
35
+ */
36
+ RangePermissionPoint: typeof RangePermissionPoint;
20
37
  }
21
38
  export declare class FSheetsEnum implements IFSheetsEnum {
22
39
  get SheetValueChangeType(): typeof SheetValueChangeType;
23
40
  get SheetSkeletonChangeType(): typeof SheetSkeletonChangeType;
24
41
  get SplitDelimiterType(): typeof SplitDelimiterEnum;
42
+ get UnitRole(): typeof UnitRole;
43
+ get WorkbookPermissionPoint(): typeof WorkbookPermissionPoint;
44
+ get WorksheetPermissionPoint(): typeof WorksheetPermissionPoint;
45
+ get RangePermissionPoint(): typeof RangePermissionPoint;
25
46
  }
26
47
  declare module '@univerjs/core/facade' {
27
48
  interface FEnum extends IFSheetsEnum {
@@ -1,6 +1,7 @@
1
1
  import { RangePermissionPointConstructor, WorkbookPermissionPointConstructor, WorkSheetPermissionPointConstructor, IAuthzIoService, ICommandService, Injector, IPermissionService } from '@univerjs/core';
2
2
  import { Observable } from 'rxjs';
3
3
  import { FRange } from './f-range';
4
+ import { IRangeProtectionOptions, IWorksheetProtectionOptions } from './permission/permission-types';
4
5
  import { FBase } from '@univerjs/core/facade';
5
6
  import { RangeProtectionRuleModel, WorkbookEditablePermission, WorkbookPermissionService, WorksheetEditPermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetViewPermission } from '@univerjs/sheets';
6
7
  /**
@@ -148,6 +149,7 @@ export declare class FPermission extends FBase {
148
149
  * you need to modify the permission points with the permissionId returned by this function.
149
150
  * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
150
151
  * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
152
+ * @param {IWorksheetProtectionOptions} options - Optional protection options including allowed users and name.
151
153
  * @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`.
152
154
  *
153
155
  * @example
@@ -159,12 +161,15 @@ export declare class FPermission extends FBase {
159
161
  * const subUnitId = worksheet.getSheetId();
160
162
  * // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes.
161
163
  * // For details, please see the example of the **`setWorksheetPermissionPoint`** API.
162
- * const permissionId = await permission.addWorksheetBasePermission(unitId, subUnitId)
164
+ * const permissionId = await permission.addWorksheetBasePermission(unitId, subUnitId, {
165
+ * allowedUsers: ['user1', 'user2'],
166
+ * name: 'My Protection'
167
+ * })
163
168
  * // Can still edit and read it.
164
169
  * console.log('debugger', permissionId)
165
170
  * ```
166
171
  */
167
- addWorksheetBasePermission(unitId: string, subUnitId: string): Promise<string | undefined>;
172
+ addWorksheetBasePermission(unitId: string, subUnitId: string, options?: IWorksheetProtectionOptions): Promise<string | undefined>;
168
173
  /**
169
174
  * Delete the entire table protection set for the worksheet and reset the point permissions of the worksheet to true
170
175
  * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
@@ -232,6 +237,7 @@ export declare class FPermission extends FBase {
232
237
  * @param {string} unitId - The unique identifier of the workbook.
233
238
  * @param {string} subUnitId - The unique identifier of the worksheet.
234
239
  * @param {FRange[]} ranges - The ranges to be protected.
240
+ * @param {IRangeProtectionOptions} options - Optional protection options including allowed users and name.
235
241
  * @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
236
242
  *
237
243
  * @example
@@ -245,7 +251,10 @@ export declare class FPermission extends FBase {
245
251
  * const range = worksheet.getRange('A1:B2');
246
252
  * const ranges = [];
247
253
  * ranges.push(range);
248
- * const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
254
+ * const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges, {
255
+ * name: 'Protected Area',
256
+ * allowEdit: false
257
+ * });
249
258
  * const {permissionId, ruleId} = res;
250
259
  * console.log('debugger', permissionId, ruleId);
251
260
  *
@@ -259,10 +268,20 @@ export declare class FPermission extends FBase {
259
268
  * }]);
260
269
  * ```
261
270
  */
262
- addRangeBaseProtection(unitId: string, subUnitId: string, ranges: FRange[]): Promise<{
271
+ addRangeBaseProtection(unitId: string, subUnitId: string, ranges: FRange[], options?: IRangeProtectionOptions): Promise<{
263
272
  permissionId: string;
264
273
  ruleId: string;
265
274
  } | undefined>;
275
+ /**
276
+ * Determine view state from range protection options
277
+ * @private
278
+ */
279
+ private _determineRangeViewState;
280
+ /**
281
+ * Determine edit state from range protection options
282
+ * @private
283
+ */
284
+ private _determineRangeEditState;
266
285
  /**
267
286
  * Removes the range protection from the worksheet.
268
287
  * @deprecated Use `worksheet.getWorksheetPermission().unprotectRules()` instead
@@ -1,16 +1,17 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { FRange } from '../f-range';
3
3
  import { FWorksheet } from '../f-worksheet';
4
- import { IRangeProtectionRule as IFRangeProtectionRule, IRangePermission, IRangeProtectionOptions, RangePermissionSnapshot, RangePermissionPoint } from './permission-types';
4
+ import { IRangeProtectionOptions, RangePermissionSnapshot, RangePermissionPoint } from './permission-types';
5
5
  import { IAuthzIoService, ICommandService, Injector, IPermissionService } from '@univerjs/core';
6
6
  import { RangeProtectionRuleModel } from '@univerjs/sheets';
7
+ import { FRangeProtectionRule } from './f-range-protection-rule';
7
8
  /**
8
9
  * Implementation class for RangePermission
9
10
  * Manages range-level permissions
10
11
  *
11
12
  * @hideconstructor
12
13
  */
13
- export declare class FRangePermission implements IRangePermission {
14
+ export declare class FRangePermission {
14
15
  private readonly _unitId;
15
16
  private readonly _subUnitId;
16
17
  private readonly _range;
@@ -22,6 +23,7 @@ export declare class FRangePermission implements IRangePermission {
22
23
  private readonly _rangeProtectionRuleModel;
23
24
  private readonly _permissionSubject;
24
25
  private readonly _subscriptions;
26
+ private readonly _fPermission;
25
27
  /**
26
28
  * Observable stream of permission snapshot changes
27
29
  * @returns Observable that emits when permission snapshot changes
@@ -33,7 +35,7 @@ export declare class FRangePermission implements IRangePermission {
33
35
  */
34
36
  readonly protectionChange$: Observable<{
35
37
  type: 'protected';
36
- rule: IFRangeProtectionRule;
38
+ rule: FRangeProtectionRule;
37
39
  } | {
38
40
  type: 'unprotected';
39
41
  ruleId: string;
@@ -65,7 +67,7 @@ export declare class FRangePermission implements IRangePermission {
65
67
  * ```ts
66
68
  * const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
67
69
  * const permission = range?.getRangePermission();
68
- * const canEdit = permission?.getPoint(RangePermissionPoint.Edit);
70
+ * const canEdit = permission?.getPoint(univerAPI.Enum.RangePermissionPoint.Edit);
69
71
  * console.log(canEdit);
70
72
  * ```
71
73
  */
@@ -147,46 +149,54 @@ export declare class FRangePermission implements IRangePermission {
147
149
  */
148
150
  canDelete(): boolean;
149
151
  /**
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).
152
+ * Set a specific permission point for the range (low-level API).
153
+ *
154
+ * **Important:** This method only updates the permission point value for an existing protection rule.
155
+ * It does NOT create permission checks that will block actual editing operations.
156
+ * You must call `protect()` first to create a protection rule before using this method.
157
+ *
158
+ * This method is useful for:
159
+ * - Fine-tuning permissions after creating a protection rule with `protect()`
160
+ * - Dynamically adjusting permissions based on runtime conditions
161
+ * - Advanced permission management scenarios
162
+ *
153
163
  * @param {RangePermissionPoint} point The permission point to set.
154
164
  * @param {boolean} value The value to set (true = allowed, false = denied).
155
165
  * @returns {Promise<void>} A promise that resolves when the point is set.
166
+ * @throws {Error} If no protection rule exists for this range.
167
+ *
156
168
  * @example
157
169
  * ```ts
158
170
  * const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
159
171
  * 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
172
+ *
173
+ * // First, create a protection rule
174
+ * await permission?.protect({ name: 'My Range', allowEdit: true });
175
+ *
176
+ * // Then you can dynamically update permission points
177
+ * await permission?.setPoint(univerAPI.Enum.RangePermissionPoint.Edit, false); // Now disable edit
178
+ * await permission?.setPoint(univerAPI.Enum.RangePermissionPoint.View, true); // Ensure view is enabled
163
179
  * ```
164
180
  */
165
181
  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
182
  /**
172
183
  * Protect the current range.
173
184
  * @param {IRangeProtectionOptions} options Protection options.
174
- * @returns {Promise<IFRangeProtectionRule>} The created protection rule.
185
+ * @returns {Promise<FRangeProtectionRule>} The created protection rule.
175
186
  * @example
176
187
  * ```ts
177
188
  * const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
178
189
  * const permission = range?.getRangePermission();
179
190
  * const rule = await permission?.protect({
180
191
  * name: 'My protected range',
181
- * allowEdit: false,
182
- * allowView: true,
183
- * allowManageCollaborator: false,
184
- * allowDeleteRule: false
192
+ * allowEdit: true,
193
+ * allowedUsers: ['user1', 'user2'],
194
+ * allowViewByOthers: false,
185
195
  * });
186
196
  * console.log(rule);
187
197
  * ```
188
198
  */
189
- protect(options?: IRangeProtectionOptions): Promise<IFRangeProtectionRule>;
199
+ protect(options?: IRangeProtectionOptions): Promise<FRangeProtectionRule>;
190
200
  /**
191
201
  * Determine view state from options
192
202
  * @private
@@ -220,7 +230,7 @@ export declare class FRangePermission implements IRangePermission {
220
230
  unprotect(): Promise<void>;
221
231
  /**
222
232
  * List all protection rules.
223
- * @returns {Promise<IFRangeProtectionRule[]>} Array of protection rules.
233
+ * @returns {Promise<FRangeProtectionRule[]>} Array of protection rules.
224
234
  * @example
225
235
  * ```ts
226
236
  * const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
@@ -229,7 +239,7 @@ export declare class FRangePermission implements IRangePermission {
229
239
  * console.log(rules);
230
240
  * ```
231
241
  */
232
- listRules(): Promise<IFRangeProtectionRule[]>;
242
+ listRules(): Promise<FRangeProtectionRule[]>;
233
243
  /**
234
244
  * Subscribe to permission changes (simplified interface).
235
245
  * @param {Function} listener Callback function to be called when permissions change.
@@ -1,5 +1,5 @@
1
1
  import { FRange } from '../f-range';
2
- import { IRangeProtectionOptions, IRangeProtectionRule } from './permission-types';
2
+ import { IRangeProtectionOptions } from './permission-types';
3
3
  import { ICommandService, Injector } from '@univerjs/core';
4
4
  import { RangeProtectionRuleModel } from '@univerjs/sheets';
5
5
  /**
@@ -8,7 +8,7 @@ import { RangeProtectionRuleModel } from '@univerjs/sheets';
8
8
  *
9
9
  * @hideconstructor
10
10
  */
11
- export declare class FRangeProtectionRule implements IRangeProtectionRule {
11
+ export declare class FRangeProtectionRule {
12
12
  private readonly _unitId;
13
13
  private readonly _subUnitId;
14
14
  private readonly _ruleId;
@@ -25,7 +25,7 @@ export declare class FRangeProtectionRule implements IRangeProtectionRule {
25
25
  * @example
26
26
  * ```ts
27
27
  * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
28
- * const permission = worksheet?.permission();
28
+ * const permission = worksheet?.getWorksheetPermission();
29
29
  * const rules = await permission?.listRangeProtectionRules();
30
30
  * const ruleId = rules?.[0]?.id;
31
31
  * console.log(ruleId);
@@ -38,7 +38,7 @@ export declare class FRangeProtectionRule implements IRangeProtectionRule {
38
38
  * @example
39
39
  * ```ts
40
40
  * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
41
- * const permission = worksheet?.permission();
41
+ * const permission = worksheet?.getWorksheetPermission();
42
42
  * const rules = await permission?.listRangeProtectionRules();
43
43
  * const ranges = rules?.[0]?.ranges;
44
44
  * console.log(ranges);
@@ -51,7 +51,7 @@ export declare class FRangeProtectionRule implements IRangeProtectionRule {
51
51
  * @example
52
52
  * ```ts
53
53
  * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
54
- * const permission = worksheet?.permission();
54
+ * const permission = worksheet?.getWorksheetPermission();
55
55
  * const rules = await permission?.listRangeProtectionRules();
56
56
  * const options = rules?.[0]?.options;
57
57
  * console.log(options);
@@ -65,34 +65,20 @@ export declare class FRangeProtectionRule implements IRangeProtectionRule {
65
65
  * @example
66
66
  * ```ts
67
67
  * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
68
- * const permission = worksheet?.permission();
68
+ * const permission = worksheet?.getWorksheetPermission();
69
69
  * const rules = await permission?.listRangeProtectionRules();
70
70
  * const rule = rules?.[0];
71
71
  * await rule?.updateRanges([worksheet.getRange('A1:C3')]);
72
72
  * ```
73
73
  */
74
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
75
  /**
90
76
  * Delete the current protection rule.
91
77
  * @returns {Promise<void>} A promise that resolves when the rule is removed.
92
78
  * @example
93
79
  * ```ts
94
80
  * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
95
- * const permission = worksheet?.permission();
81
+ * const permission = worksheet?.getWorksheetPermission();
96
82
  * const rules = await permission?.listRangeProtectionRules();
97
83
  * const rule = rules?.[0];
98
84
  * await rule?.remove();
@@ -38,6 +38,7 @@ export declare class FWorkbookPermission implements IWorkbookPermission {
38
38
  collaborator: ICollaborator;
39
39
  }>;
40
40
  private _subscriptions;
41
+ private readonly _fPermission;
41
42
  constructor(_unitId: string, _injector: Injector, _permissionService: IPermissionService, _authzIoService: IAuthzIoService);
42
43
  /**
43
44
  * Create permission snapshot stream from IPermissionService
@@ -126,7 +127,7 @@ export declare class FWorkbookPermission implements IWorkbookPermission {
126
127
  * ```ts
127
128
  * const workbook = univerAPI.getActiveWorkbook();
128
129
  * const permission = workbook?.getWorkbookPermission();
129
- * await permission?.setPoint(WorkbookPermissionPoint.Print, false);
130
+ * await permission?.setPoint(univerAPI.Enum.WorkbookPermissionPoint.Print, false);
130
131
  * ```
131
132
  */
132
133
  setPoint(point: WorkbookPermissionPoint, value: boolean): Promise<void>;
@@ -138,7 +139,7 @@ export declare class FWorkbookPermission implements IWorkbookPermission {
138
139
  * ```ts
139
140
  * const workbook = univerAPI.getActiveWorkbook();
140
141
  * const permission = workbook?.getWorkbookPermission();
141
- * const canPrint = permission?.getPoint(WorkbookPermissionPoint.Print);
142
+ * const canPrint = permission?.getPoint(univerAPI.Enum.WorkbookPermissionPoint.Print);
142
143
  * console.log(canPrint);
143
144
  * ```
144
145
  */
@@ -166,11 +167,11 @@ export declare class FWorkbookPermission implements IWorkbookPermission {
166
167
  * await permission?.setCollaborators([
167
168
  * {
168
169
  * user: { userID: 'user1', name: 'John Doe', avatar: 'https://...' },
169
- * role: UnitRole.Editor
170
+ * role: univerAPI.Enum.UnitRole.Editor
170
171
  * },
171
172
  * {
172
173
  * user: { userID: 'user2', name: 'Jane Smith', avatar: '' },
173
- * role: UnitRole.Reader
174
+ * role: univerAPI.Enum.UnitRole.Reader
174
175
  * }
175
176
  * ]);
176
177
  * ```
@@ -190,7 +191,7 @@ export declare class FWorkbookPermission implements IWorkbookPermission {
190
191
  * const permission = workbook?.getWorkbookPermission();
191
192
  * await permission?.addCollaborator(
192
193
  * { userID: 'user1', name: 'John Doe', avatar: 'https://...' },
193
- * UnitRole.Editor
194
+ * univerAPI.Enum.UnitRole.Editor
194
195
  * );
195
196
  * ```
196
197
  */
@@ -206,7 +207,7 @@ export declare class FWorkbookPermission implements IWorkbookPermission {
206
207
  * const permission = workbook?.getWorkbookPermission();
207
208
  * await permission?.updateCollaborator(
208
209
  * { userID: 'user1', name: 'John Doe Updated', avatar: 'https://...' },
209
- * UnitRole.Reader
210
+ * univerAPI.Enum.UnitRole.Reader
210
211
  * );
211
212
  * ```
212
213
  */
@@ -1,16 +1,17 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { FRange } from '../f-range';
3
3
  import { FWorksheet } from '../f-worksheet';
4
- import { ICellPermissionDebugInfo, IRangeProtectionOptions, IRangeProtectionRule, IWorksheetPermission, IWorksheetPermissionConfig, UnsubscribeFn, WorksheetMode, WorksheetPermissionSnapshot, WorksheetPermissionPoint } from './permission-types';
4
+ import { IRangeProtectionOptions, IWorksheetPermissionConfig, IWorksheetProtectionOptions, UnsubscribeFn, WorksheetMode, WorksheetPermissionSnapshot, WorksheetPermissionPoint } from './permission-types';
5
5
  import { IAuthzIoService, ICommandService, Injector, IPermissionService } from '@univerjs/core';
6
- import { RangeProtectionRuleModel, WorksheetProtectionPointModel } from '@univerjs/sheets';
6
+ import { RangeProtectionRuleModel, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets';
7
+ import { FRangeProtectionRule } from './f-range-protection-rule';
7
8
  /**
8
9
  * Implementation class for WorksheetPermission
9
10
  * Provides worksheet-level permission control
10
11
  *
11
12
  * @hideconstructor
12
13
  */
13
- export declare class FWorksheetPermission implements IWorksheetPermission {
14
+ export declare class FWorksheetPermission {
14
15
  private readonly _worksheet;
15
16
  private readonly _injector;
16
17
  private readonly _permissionService;
@@ -18,6 +19,7 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
18
19
  private readonly _commandService;
19
20
  private readonly _rangeProtectionRuleModel;
20
21
  private readonly _worksheetProtectionPointModel;
22
+ private readonly _worksheetProtectionRuleModel;
21
23
  private readonly _permissionSubject;
22
24
  private readonly _rangeRulesSubject;
23
25
  /**
@@ -40,17 +42,18 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
40
42
  */
41
43
  readonly rangeProtectionChange$: Observable<{
42
44
  type: 'add' | 'update' | 'delete';
43
- rules: IRangeProtectionRule[];
45
+ rules: FRangeProtectionRule[];
44
46
  }>;
45
47
  /**
46
48
  * Observable stream of current range protection rules list (BehaviorSubject)
47
49
  * Emits immediately on subscription with current rules, then auto-updates when rules change
48
50
  */
49
- readonly rangeProtectionRules$: Observable<IRangeProtectionRule[]>;
51
+ readonly rangeProtectionRules$: Observable<FRangeProtectionRule[]>;
50
52
  private readonly _unitId;
51
53
  private readonly _subUnitId;
52
54
  private readonly _subscriptions;
53
- constructor(_worksheet: FWorksheet, _injector: Injector, _permissionService: IPermissionService, _authzIoService: IAuthzIoService, _commandService: ICommandService, _rangeProtectionRuleModel: RangeProtectionRuleModel, _worksheetProtectionPointModel: WorksheetProtectionPointModel);
55
+ private readonly _fPermission;
56
+ constructor(_worksheet: FWorksheet, _injector: Injector, _permissionService: IPermissionService, _authzIoService: IAuthzIoService, _commandService: ICommandService, _rangeProtectionRuleModel: RangeProtectionRuleModel, _worksheetProtectionPointModel: WorksheetProtectionPointModel, _worksheetProtectionRuleModel: WorksheetProtectionRuleModel);
54
57
  /**
55
58
  * Create permission snapshot stream from IPermissionService
56
59
  * @private
@@ -88,8 +91,73 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
88
91
  * Build range protection rules list
89
92
  */
90
93
  private _buildRangeProtectionRules;
94
+ /**
95
+ * Build Facade objects for all protection rules
96
+ */
97
+ private _buildProtectionRule;
98
+ /**
99
+ * Debug cell permission information.
100
+ * @param {number} row Row index.
101
+ * @param {number} col Column index.
102
+ * @returns {ICellPermissionDebugInfo | null} Debug information about which rules affect this cell, or null if no rules apply.
103
+ * @example
104
+ * ```ts
105
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
106
+ * const permission = worksheet?.getWorksheetPermission();
107
+ * const debugInfo = permission?.debugCellPermission(0, 0);
108
+ * console.log(debugInfo);
109
+ * ```
110
+ */
111
+ debugCellPermission(row: number, col: number): FRangeProtectionRule | undefined;
112
+ /**
113
+ * Create worksheet protection with collaborators support.
114
+ * This must be called before setting permission points for collaboration to work.
115
+ * @param {IWorksheetProtectionOptions} options Protection options including allowed users.
116
+ * @returns {Promise<string>} The permissionId for the created protection.
117
+ * @example
118
+ * ```ts
119
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
120
+ * const permission = worksheet?.getWorksheetPermission();
121
+ *
122
+ * // Create worksheet protection with collaborators
123
+ * const permissionId = await permission?.protect({
124
+ * allowedUsers: ['user1', 'user2'],
125
+ * name: 'My Worksheet Protection'
126
+ * });
127
+ *
128
+ * // Now set permission points
129
+ * await permission?.setMode('readOnly');
130
+ * ```
131
+ */
132
+ protect(options?: IWorksheetProtectionOptions): Promise<string>;
133
+ /**
134
+ * Remove worksheet protection.
135
+ * This deletes the protection rule and resets all permission points to allowed.
136
+ * @returns {Promise<void>} A promise that resolves when protection is removed.
137
+ * @example
138
+ * ```ts
139
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
140
+ * const permission = worksheet?.getWorksheetPermission();
141
+ * await permission?.unprotect();
142
+ * ```
143
+ */
144
+ unprotect(): Promise<void>;
145
+ /**
146
+ * Check if worksheet is currently protected.
147
+ * @returns {boolean} true if protected, false otherwise.
148
+ * @example
149
+ * ```ts
150
+ * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
151
+ * const permission = worksheet?.getWorksheetPermission();
152
+ * if (permission?.isProtected()) {
153
+ * console.log('Worksheet is protected');
154
+ * }
155
+ * ```
156
+ */
157
+ isProtected(): boolean;
91
158
  /**
92
159
  * Set permission mode for the worksheet.
160
+ * Automatically creates worksheet protection if not already protected.
93
161
  * @param {WorksheetMode} mode The permission mode to set ('editable' | 'readOnly' | 'filterOnly' | 'commentOnly').
94
162
  * @returns {Promise<void>} A promise that resolves when the mode is set.
95
163
  * @example
@@ -173,22 +241,9 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
173
241
  * ```
174
242
  */
175
243
  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
244
  /**
191
245
  * Set a specific permission point for the worksheet.
246
+ * Automatically creates worksheet protection if not already protected.
192
247
  * @param {WorksheetPermissionPoint} point The permission point to set.
193
248
  * @param {boolean} value The value to set (true = allowed, false = denied).
194
249
  * @returns {Promise<void>} A promise that resolves when the point is set.
@@ -196,7 +251,7 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
196
251
  * ```ts
197
252
  * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
198
253
  * const permission = worksheet?.getWorksheetPermission();
199
- * await permission?.setPoint(WorksheetPermissionPoint.InsertRow, false);
254
+ * await permission?.setPoint(univerAPI.Enum.WorksheetPermissionPoint.InsertRow, false);
200
255
  * ```
201
256
  */
202
257
  setPoint(point: WorksheetPermissionPoint, value: boolean): Promise<void>;
@@ -208,7 +263,7 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
208
263
  * ```ts
209
264
  * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
210
265
  * const permission = worksheet?.getWorksheetPermission();
211
- * const canInsertRow = permission?.getPoint(WorksheetPermissionPoint.InsertRow);
266
+ * const canInsertRow = permission?.getPoint(univerAPI.Enum.WorksheetPermissionPoint.InsertRow);
212
267
  * console.log(canInsertRow);
213
268
  * ```
214
269
  */
@@ -236,8 +291,8 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
236
291
  * await permission?.applyConfig({
237
292
  * mode: 'readOnly',
238
293
  * points: {
239
- * [WorksheetPermissionPoint.View]: true,
240
- * [WorksheetPermissionPoint.Edit]: false
294
+ * [univerAPI.Enum.WorksheetPermissionPoint.View]: true,
295
+ * [univerAPI.Enum.WorksheetPermissionPoint.Edit]: false
241
296
  * }
242
297
  * });
243
298
  * ```
@@ -246,7 +301,7 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
246
301
  /**
247
302
  * Protect multiple ranges at once (batch operation).
248
303
  * @param {Array<{ ranges: FRange[]; options?: IRangeProtectionOptions }>} configs Array of protection configurations.
249
- * @returns {Promise<IRangeProtectionRule[]>} Array of created protection rules.
304
+ * @returns {Promise<FRangeProtectionRule[]>} Array of created protection rules.
250
305
  * @example
251
306
  * ```ts
252
307
  * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
@@ -254,11 +309,11 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
254
309
  * const rules = await permission?.protectRanges([
255
310
  * {
256
311
  * ranges: [worksheet.getRange('A1:B2')],
257
- * options: { name: 'Protected Area 1', allowEdit: false, allowView: true }
312
+ * options: { name: 'Protected Area 1', allowEdit: false, allowViewByOthers: true }
258
313
  * },
259
314
  * {
260
315
  * ranges: [worksheet.getRange('C3:D4')],
261
- * options: { name: 'Protected Area 2', allowEdit: true, allowView: false }
316
+ * options: { name: 'Protected Area 2', allowEdit: true, allowViewByOthers: false }
262
317
  * }
263
318
  * ]);
264
319
  * console.log(rules);
@@ -267,7 +322,7 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
267
322
  protectRanges(configs: Array<{
268
323
  ranges: FRange[];
269
324
  options?: IRangeProtectionOptions;
270
- }>): Promise<IRangeProtectionRule[]>;
325
+ }>): Promise<FRangeProtectionRule[]>;
271
326
  /**
272
327
  * Determine view state from options
273
328
  * @private
@@ -302,7 +357,7 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
302
357
  unprotectRules(ruleIds: string[]): Promise<void>;
303
358
  /**
304
359
  * List all range protection rules for the worksheet.
305
- * @returns {Promise<IRangeProtectionRule[]>} Array of protection rules.
360
+ * @returns {Promise<FRangeProtectionRule[]>} Array of protection rules.
306
361
  * @example
307
362
  * ```ts
308
363
  * const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
@@ -311,7 +366,7 @@ export declare class FWorksheetPermission implements IWorksheetPermission {
311
366
  * console.log(rules);
312
367
  * ```
313
368
  */
314
- listRangeProtectionRules(): Promise<IRangeProtectionRule[]>;
369
+ listRangeProtectionRules(): Promise<FRangeProtectionRule[]>;
315
370
  /**
316
371
  * Subscribe to permission changes (simplified interface for users not familiar with RxJS).
317
372
  * @param {Function} listener Callback function to be called when permissions change.