@univerjs/sheets 0.12.2 → 0.12.3-experimental.20251205-e439e48

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,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
  };
@@ -4,3 +4,4 @@ export declare function getSuitableRangesInView(ranges: IRange[], skeleton: Null
4
4
  suitableRanges: IRange[];
5
5
  remainingRanges: IRange[];
6
6
  };
7
+ export declare function countCells(cellMatrix: ObjectMatrix<unknown>): number;
@@ -0,0 +1,10 @@
1
+ import { IMutation } from '@univerjs/core';
2
+ export interface ICopyWorksheetEndMutationParams {
3
+ unitId: string;
4
+ subUnitId: string;
5
+ }
6
+ /**
7
+ * This mutation is used to mark the end of a copy worksheet operation that was split into chunks.
8
+ * When this mutation is applied on the server, it should trigger a snapshot save.
9
+ */
10
+ export declare const CopyWorksheetEndMutation: IMutation<ICopyWorksheetEndMutationParams, boolean>;
@@ -1,6 +1,21 @@
1
1
  import { DependencyOverride } from '@univerjs/core';
2
2
  export declare const SHEETS_PLUGIN_CONFIG_KEY = "sheets.config";
3
3
  export declare const configSymbol: unique symbol;
4
+ export interface ILargeSheetOperationConfig {
5
+ /**
6
+ * The minimum number of cells that defines a "large sheet".
7
+ * When a sheet has more cells than this threshold:
8
+ * - Copy sheet: the mutation will be split into multiple batches
9
+ * - Remove sheet: undo/redo will not be supported
10
+ * @default 6000
11
+ */
12
+ largeSheetCellCountThreshold?: number;
13
+ /**
14
+ * The maximum number of cells per batch when splitting mutations for large sheets.
15
+ * @default 3000
16
+ */
17
+ batchSize?: number;
18
+ }
4
19
  export interface IUniverSheetsConfig {
5
20
  notExecuteFormula?: boolean;
6
21
  override?: DependencyOverride;
@@ -22,5 +37,13 @@ export interface IUniverSheetsConfig {
22
37
  * @default true
23
38
  */
24
39
  freezeSync?: boolean;
40
+ /**
41
+ * Configuration for large sheet operations.
42
+ * When a sheet has more cells than the threshold:
43
+ * - Copy sheet: the mutation will be split into multiple batches
44
+ * - Remove sheet: undo/redo will not be supported
45
+ */
46
+ largeSheetOperation?: ILargeSheetOperationConfig;
25
47
  }
48
+ export declare const defaultLargeSheetOperationConfig: Required<ILargeSheetOperationConfig>;
26
49
  export declare const defaultPluginConfig: IUniverSheetsConfig;
@@ -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
  */