@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.
@@ -1,6 +1,5 @@
1
1
  import { IUser } from '@univerjs/protocol';
2
2
  import { Observable } from 'rxjs';
3
- import { FRange } from '../f-range';
4
3
  /**
5
4
  * ========================
6
5
  * Basic Types / Enums
@@ -165,6 +164,22 @@ export type RangePermissionSnapshot = Record<RangePermissionPoint, boolean>;
165
164
  * Unsubscribe function type
166
165
  */
167
166
  export type UnsubscribeFn = () => void;
167
+ /**
168
+ * ========================
169
+ * Worksheet Protection Configuration
170
+ * ========================
171
+ */
172
+ /**
173
+ * Worksheet protection options configuration
174
+ */
175
+ export interface IWorksheetProtectionOptions {
176
+ /** Whitelist of users allowed to edit; empty means only owner */
177
+ allowedUsers?: string[];
178
+ /** Protection name for UI display */
179
+ name?: string;
180
+ /** Custom metadata */
181
+ metadata?: Record<string, unknown>;
182
+ }
168
183
  /**
169
184
  * ========================
170
185
  * Range Protection Configuration and Rules
@@ -184,24 +199,6 @@ export interface IRangeProtectionOptions {
184
199
  /** Custom metadata (logs, tags, etc.) */
185
200
  metadata?: Record<string, unknown>;
186
201
  }
187
- /**
188
- * Range protection rule Facade
189
- * Encapsulates internal permissionId / ruleId
190
- */
191
- export interface IRangeProtectionRule {
192
- /** Internal rule id, for debugging/logging, generally not directly used by callers */
193
- readonly id: string;
194
- /** List of ranges covered by this rule */
195
- readonly ranges: FRange[];
196
- /** Current rule configuration */
197
- readonly options: IRangeProtectionOptions;
198
- /** Update protected ranges */
199
- updateRanges(ranges: FRange[]): Promise<void>;
200
- /** Partially update configuration */
201
- updateOptions(options: Partial<IRangeProtectionOptions>): Promise<void>;
202
- /** Delete current protection rule */
203
- remove(): Promise<void>;
204
- }
205
202
  /**
206
203
  * Cell permission debug rule information
207
204
  */
@@ -211,15 +208,6 @@ export interface ICellPermissionDebugRuleInfo {
211
208
  rangeRefs: string[];
212
209
  options: IRangeProtectionOptions;
213
210
  }
214
- /**
215
- * Cell permission debug information
216
- */
217
- export interface ICellPermissionDebugInfo {
218
- row: number;
219
- col: number;
220
- /** List of protection rules that apply */
221
- hitRules: ICellPermissionDebugRuleInfo[];
222
- }
223
211
  /**
224
212
  * ========================
225
213
  * Facade: WorkbookPermission
@@ -317,167 +305,12 @@ export interface IWorksheetPermissionConfig {
317
305
  options?: IRangeProtectionOptions;
318
306
  }>;
319
307
  }
320
- /**
321
- * Worksheet-level permission Facade interface
322
- */
323
- export interface IWorksheetPermission {
324
- /**
325
- * Set worksheet overall mode:
326
- * - 'readOnly' → Lock write-related points
327
- * - 'filterOnly' → Only enable Filter/Sort, close other write-related points
328
- * - 'commentOnly' → Close write, keep comment
329
- * - 'editable' → Most write-related points enabled
330
- */
331
- setMode(mode: WorksheetMode): Promise<void>;
332
- /** Shortcut: Read-only */
333
- setReadOnly(): Promise<void>;
334
- /** Shortcut: Editable */
335
- setEditable(): Promise<void>;
336
- /** Whether current user can "overall" edit this sheet (not considering local range protection) */
337
- canEdit(): boolean;
338
- /**
339
- * Cell-level high-level check (combines sheet-level & range-level rules)
340
- */
341
- canEditCell(row: number, col: number): boolean;
342
- canViewCell(row: number, col: number): boolean;
343
- /**
344
- * Debug use: View protection rule information for a specific cell
345
- */
346
- debugCellPermission(row: number, col: number): ICellPermissionDebugInfo | null;
347
- /**
348
- * Point operations (low-level)
349
- */
350
- setPoint(point: WorksheetPermissionPoint, value: boolean): Promise<void>;
351
- getPoint(point: WorksheetPermissionPoint): boolean;
352
- getSnapshot(): WorksheetPermissionSnapshot;
353
- /**
354
- * Batch apply permission configuration (for "configuration-driven" scenarios)
355
- * Internally uses Command to ensure undo/redo
356
- */
357
- applyConfig(config: IWorksheetPermissionConfig): Promise<void>;
358
- /**
359
- * Range protection management
360
- */
361
- /** Batch create multiple range protection rules (one-time operation, better performance) */
362
- protectRanges(configs: Array<{
363
- ranges: FRange[];
364
- options?: IRangeProtectionOptions;
365
- }>): Promise<IRangeProtectionRule[]>;
366
- /** Batch delete multiple protection rules */
367
- unprotectRules(ruleIds: string[]): Promise<void>;
368
- /**
369
- * List all range protection rules on current sheet
370
- */
371
- listRangeProtectionRules(): Promise<IRangeProtectionRule[]>;
372
- /**
373
- * ========================
374
- * RxJS Observable Reactive Interface
375
- * ========================
376
- */
377
- /**
378
- * Permission snapshot change stream (BehaviorSubject, immediately provides current state on subscription)
379
- * Triggers when any permission point changes
380
- */
381
- readonly permission$: Observable<WorksheetPermissionSnapshot>;
382
- /**
383
- * Single permission point change stream
384
- * For scenarios that only care about specific permission point changes
385
- */
386
- readonly pointChange$: Observable<{
387
- point: WorksheetPermissionPoint;
388
- value: boolean;
389
- oldValue: boolean;
390
- }>;
391
- /**
392
- * Range protection rule change stream (add, delete, update)
393
- */
394
- readonly rangeProtectionChange$: Observable<{
395
- type: 'add' | 'update' | 'delete';
396
- rules: IRangeProtectionRule[];
397
- }>;
398
- /**
399
- * Current all range protection rules list stream (BehaviorSubject)
400
- * Immediately provides current rule list on subscription, auto-updates when rules change
401
- */
402
- readonly rangeProtectionRules$: Observable<IRangeProtectionRule[]>;
403
- /**
404
- * Compatibility method: Simplified subscription (for users unfamiliar with RxJS)
405
- * Internally implemented based on permission$ Observable
406
- */
407
- subscribe(listener: (snapshot: WorksheetPermissionSnapshot) => void): UnsubscribeFn;
408
- }
409
308
  /**
410
309
  * ========================
411
310
  * Facade: RangePermission
412
311
  * ========================
413
312
  */
414
- /**
415
- * Range-level permission Facade interface
416
- */
417
- export interface IRangePermission {
418
- /**
419
- * Create protection rule on current range
420
- * - Default options.allowEdit = false → Treated as "locked"
421
- */
422
- protect(options?: IRangeProtectionOptions): Promise<IRangeProtectionRule>;
423
- /**
424
- * Remove all protection rules covered by current range
425
- * (Internally can calculate range → ruleId mapping)
426
- */
427
- unprotect(): Promise<void>;
428
- /**
429
- * Whether current range is in protected state (for current user)
430
- */
431
- isProtected(): boolean;
432
- /** Whether current user can edit this range (combines Worksheet / Workbook / Range levels) */
433
- canEdit(): boolean;
434
- /** Whether current user can view this range */
435
- canView(): boolean;
436
- /**
437
- * Range-level point reading (generally for debugging / advanced scenarios)
438
- * Usually only need Edit/View two points
439
- */
440
- getPoint(point: RangePermissionPoint): boolean;
441
- getSnapshot(): RangePermissionSnapshot;
442
- /**
443
- * Set a specific permission point for the range (low-level API for local runtime control)
444
- * @param {RangePermissionPoint} point The permission point to set
445
- * @param {boolean} value The value to set (true = allowed, false = denied)
446
- * @returns {Promise<void>} A promise that resolves when the point is set
447
- * @example
448
- * ```ts
449
- * const range = univerAPI.getActiveWorkbook()?.getActiveSheet()?.getRange('A1:B2');
450
- * const permission = range?.getRangePermission();
451
- * await permission?.setPoint(RangePermissionPoint.Edit, false); // Disable edit for current user
452
- * ```
453
- */
454
- setPoint(point: RangePermissionPoint, value: boolean): Promise<void>;
455
- /**
456
- * Get snapshot of all protection rules in current worksheet (can also proxy worksheet interface)
457
- */
458
- listRules(): Promise<IRangeProtectionRule[]>;
459
- /**
460
- * ========================
461
- * RxJS Observable Reactive Interface
462
- * ========================
463
- */
464
- /**
465
- * Permission snapshot change stream (BehaviorSubject, immediately provides current state on subscription)
466
- */
467
- readonly permission$: Observable<RangePermissionSnapshot>;
468
- /**
469
- * Protection state change stream
470
- */
471
- readonly protectionChange$: Observable<{
472
- type: 'protected';
473
- rule: IRangeProtectionRule;
474
- } | {
475
- type: 'unprotected';
476
- ruleId: string;
477
- }>;
478
- /**
479
- * Compatibility method: Simplified subscription (for users unfamiliar with RxJS)
480
- * Internally implemented based on permission$ Observable
481
- */
482
- subscribe(listener: (snapshot: RangePermissionSnapshot) => void): UnsubscribeFn;
313
+ export interface ICellPermissionDebugInfo {
314
+ permissionId: string;
315
+ ruleId: string;
483
316
  }