@univerjs/sheets 0.5.4 → 0.5.5-nightly.202501201336

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.
@@ -87,6 +87,20 @@ export interface IFUniverSheetsMixin {
87
87
  workbook: FWorkbook;
88
88
  worksheet: FWorksheet;
89
89
  }>;
90
+ /**
91
+ * Get the active sheet.
92
+ * @returns {Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>} The active sheet.
93
+ * @example
94
+ * ```ts
95
+ * const target = univerAPI.getActiveSheet();
96
+ * if (!target) return;
97
+ * const { workbook, worksheet } = target;
98
+ * ```
99
+ */
100
+ getActiveSheet(): Nullable<{
101
+ workbook: FWorkbook;
102
+ worksheet: FWorksheet;
103
+ }>;
90
104
  }
91
105
  export declare class FUniverSheetsMixin extends FUniver implements IFUniverSheetsMixin {
92
106
  getCommandSheetTarget(commandInfo: ICommandInfo<object>): Nullable<{
@@ -108,6 +122,22 @@ export declare class FUniverSheetsMixin extends FUniver implements IFUniverSheet
108
122
  getPermission(): FPermission;
109
123
  onUniverSheetCreated(callback: (workbook: FWorkbook) => void): IDisposable;
110
124
  newDefinedName(): FDefinedNameBuilder;
125
+ getActiveSheet(): Nullable<{
126
+ workbook: FWorkbook;
127
+ worksheet: FWorksheet;
128
+ }>;
129
+ private _fireBeforeActiveSheetChange;
130
+ private _fireActiveSheetChanged;
131
+ private _fireBeforeSheetDelete;
132
+ private _fireSheetDeleted;
133
+ private _fireBeforeSheetMove;
134
+ private _fireSheetMoved;
135
+ private _fireBeforeSheetNameChange;
136
+ private _fireSheetNameChanged;
137
+ private _fireBeforeSheetTabColorChange;
138
+ private _fireSheetTabColorChanged;
139
+ private _fireBeforeSheetHideChange;
140
+ private _fireSheetHideChanged;
111
141
  }
112
142
  declare module '@univerjs/core' {
113
143
  interface FUniver extends IFUniverSheetsMixin {
@@ -1,4 +1,4 @@
1
- import { CommandListener, CustomData, IDisposable, IEventParamConfig, IRange, IWorkbookData, LocaleType, Workbook, FBaseInitialable, FEnum, FEventName, ICommandService, ILogService, Injector, IPermissionService, IResourceLoaderService, IUniverInstanceService, LocaleService } from '@univerjs/core';
1
+ import { CommandListener, CustomData, IDisposable, IRange, IWorkbookData, LocaleType, Workbook, FBaseInitialable, ICommandService, ILogService, Injector, IPermissionService, IResourceLoaderService, IUniverInstanceService, LocaleService } from '@univerjs/core';
2
2
  import { ISetDefinedNameMutationParam, IDefinedNamesService } from '@univerjs/engine-formula';
3
3
  import { RangeThemeStyle, SheetsSelectionsService } from '@univerjs/sheets';
4
4
  import { FontLine as _FontLine, FRange } from './f-range';
@@ -18,39 +18,17 @@ export declare class FWorkbook extends FBaseInitialable {
18
18
  protected readonly _definedNamesService: IDefinedNamesService;
19
19
  readonly id: string;
20
20
  constructor(_workbook: Workbook, _injector: Injector, _resourceLoaderService: IResourceLoaderService, _selectionManagerService: SheetsSelectionsService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _permissionService: IPermissionService, _logService: ILogService, _localeService: LocaleService, _definedNamesService: IDefinedNamesService);
21
- getWorkbook(): Workbook;
22
- private _eventRegistry;
23
- private _ensureEventRegistry;
24
21
  /**
25
- * Add an event listener
26
- * @param event key of event
27
- * @param callback callback when event triggered
28
- * @returns {Disposable} The Disposable instance, for remove the listener
22
+ * Get the Workbook instance.
23
+ * @returns {Workbook} The Workbook instance.
29
24
  * @example
30
25
  * ```ts
31
- * univerAPI.addEvent(univerAPI.event.UnitCreated, (params) => {
32
- * console.log('unit created', params);
33
- * });
34
- * ```
35
- */
36
- addEvent(event: keyof IEventParamConfig, callback: (params: IEventParamConfig[typeof event]) => void): IDisposable;
37
- /**
38
- * Fire an event, used in internal only.
39
- * @param event {string} key of event
40
- * @param params {any} params of event
41
- * @returns {boolean} should cancel
42
- * @example
43
- * ```ts
44
- * this.fireEvent(univerAPI.event.UnitCreated, params);
26
+ * // The code below gets the Workbook instance
27
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
28
+ * const workbook = activeSpreadsheet.getWorkbook();
45
29
  * ```
46
30
  */
47
- protected fireEvent<T extends keyof IEventParamConfig>(event: T, params: IEventParamConfig[T]): boolean | undefined;
48
- addUIEvent(event: keyof IEventParamConfig, _callback: (params: IEventParamConfig[typeof event]) => void): void;
49
- get Enum(): FEnum;
50
- /**
51
- * @returns {FEventName} The event name.
52
- */
53
- get Event(): FEventName;
31
+ getWorkbook(): Workbook;
54
32
  /**
55
33
  * Get the id of the workbook.
56
34
  * @returns {string} The id of the workbook.
@@ -76,6 +54,7 @@ export declare class FWorkbook extends FBaseInitialable {
76
54
  /**
77
55
  * Set the name of the workbook.
78
56
  * @param {string} name The new name of the workbook.
57
+ * @returns {void}
79
58
  * @example
80
59
  * ```ts
81
60
  * // The code below sets the name of the workbook
@@ -97,8 +76,14 @@ export declare class FWorkbook extends FBaseInitialable {
97
76
  save(): IWorkbookData;
98
77
  /**
99
78
  * @deprecated use 'save' instead.
100
- * @returns {*} {IWorkbookData} Workbook snapshot data
79
+ * @returns {IWorkbookData} Workbook snapshot data
101
80
  * @memberof FWorkbook
81
+ * @example
82
+ * ```ts
83
+ * // The code below saves the workbook snapshot data
84
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
85
+ * const snapshot = activeSpreadsheet.getSnapshot();
86
+ * ```
102
87
  */
103
88
  getSnapshot(): IWorkbookData;
104
89
  /**
@@ -125,10 +110,10 @@ export declare class FWorkbook extends FBaseInitialable {
125
110
  getSheets(): FWorksheet[];
126
111
  /**
127
112
  * Create a new worksheet and returns a handle to it.
128
- * @param name Name of the new sheet
129
- * @param rows How may rows would the new sheet have
130
- * @param column How many columns would the new sheet have
131
- * @returns The new created sheet
113
+ * @param {string} name Name of the new sheet
114
+ * @param {number} rows How many rows would the new sheet have
115
+ * @param {number} column How many columns would the new sheet have
116
+ * @returns {FWorksheet} The new created sheet
132
117
  * @example
133
118
  * ```ts
134
119
  * // The code below creates a new sheet
@@ -139,8 +124,8 @@ export declare class FWorkbook extends FBaseInitialable {
139
124
  create(name: string, rows: number, column: number): FWorksheet;
140
125
  /**
141
126
  * Get a worksheet by sheet id.
142
- * @param sheetId The id of the sheet to get.
143
- * @returns The worksheet with given sheet id
127
+ * @param {string} sheetId The id of the sheet to get.
128
+ * @returns {FWorksheet | null} The worksheet with given sheet id
144
129
  * @example
145
130
  * ```ts
146
131
  * // The code below gets a worksheet by sheet id
@@ -151,8 +136,8 @@ export declare class FWorkbook extends FBaseInitialable {
151
136
  getSheetBySheetId(sheetId: string): FWorksheet | null;
152
137
  /**
153
138
  * Get a worksheet by sheet name.
154
- * @param name The name of the sheet to get.
155
- * @returns The worksheet with given sheet name
139
+ * @param {string} name The name of the sheet to get.
140
+ * @returns {FWorksheet | null} The worksheet with given sheet name
156
141
  * @example
157
142
  * ```ts
158
143
  * // The code below gets a worksheet by sheet name
@@ -163,8 +148,8 @@ export declare class FWorkbook extends FBaseInitialable {
163
148
  getSheetByName(name: string): FWorksheet | null;
164
149
  /**
165
150
  * Sets the given worksheet to be the active worksheet in the workbook.
166
- * @param sheet The worksheet to set as the active worksheet.
167
- * @returns The active worksheet
151
+ * @param {FWorksheet | string} sheet The worksheet to set as the active worksheet.
152
+ * @returns {FWorksheet} The active worksheet
168
153
  * @example
169
154
  * ```ts
170
155
  * // The code below sets the given worksheet to be the active worksheet
@@ -173,12 +158,12 @@ export declare class FWorkbook extends FBaseInitialable {
173
158
  * activeSpreadsheet.setActiveSheet(sheet);
174
159
  * ```
175
160
  */
176
- setActiveSheet(sheet: FWorksheet): FWorksheet;
161
+ setActiveSheet(sheet: FWorksheet | string): FWorksheet;
177
162
  /**
178
163
  * Inserts a new worksheet into the workbook.
179
164
  * Using a default sheet name. The new sheet becomes the active sheet
180
- * @param sheetName - (optional) The name of the new sheet
181
- * @returns The new sheet
165
+ * @param {string} [sheetName] The name of the new sheet
166
+ * @returns {FWorksheet} The new sheet
182
167
  * @example
183
168
  * ```ts
184
169
  * // The code below inserts a new sheet into the workbook
@@ -193,7 +178,7 @@ export declare class FWorkbook extends FBaseInitialable {
193
178
  insertSheet(sheetName?: string): FWorksheet;
194
179
  /**
195
180
  * Deletes the specified worksheet.
196
- * @param sheet The worksheet to delete.
181
+ * @param {FWorksheet | string} sheet The worksheet to delete.
197
182
  * @returns {boolean} True if the worksheet was deleted, false otherwise.
198
183
  * @example
199
184
  * ```ts
@@ -203,7 +188,7 @@ export declare class FWorkbook extends FBaseInitialable {
203
188
  * activeSpreadsheet.deleteSheet(sheet);
204
189
  * ```
205
190
  */
206
- deleteSheet(sheet: FWorksheet): boolean;
191
+ deleteSheet(sheet: FWorksheet | string): boolean;
207
192
  /**
208
193
  * Undo the last action.
209
194
  * @returns {FWorkbook} A promise that resolves to true if the undo was successful, false otherwise.
@@ -217,7 +202,7 @@ export declare class FWorkbook extends FBaseInitialable {
217
202
  undo(): FWorkbook;
218
203
  /**
219
204
  * Redo the last undone action.
220
- * @returns A promise that resolves to true if the redo was successful, false otherwise.
205
+ * @returns {FWorkbook} A promise that resolves to true if the redo was successful, false otherwise.
221
206
  * @example
222
207
  * ```ts
223
208
  * // The code below redoes the last undone action
@@ -234,7 +219,7 @@ export declare class FWorkbook extends FBaseInitialable {
234
219
  /**
235
220
  * Register a callback that will be triggered before invoking a command targeting the Univer sheet.
236
221
  * @param {onBeforeCommandExecuteCallback} callback the callback.
237
- * @returns A function to dispose the listening.
222
+ * @returns {IDisposable} A function to dispose the listening.
238
223
  * @example
239
224
  * ```ts
240
225
  * // The code below registers a callback that will be triggered before invoking a command targeting the Univer sheet
@@ -253,7 +238,7 @@ export declare class FWorkbook extends FBaseInitialable {
253
238
  /**
254
239
  * Register a callback that will be triggered when a command is invoked targeting the Univer sheet.
255
240
  * @param {onCommandExecutedCallback} callback the callback.
256
- * @returns A function to dispose the listening.
241
+ * @returns {IDisposable} A function to dispose the listening.
257
242
  * @example
258
243
  * ```ts
259
244
  * // The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheet
@@ -261,6 +246,7 @@ export declare class FWorkbook extends FBaseInitialable {
261
246
  * activeSpreadsheet.onCommandExecuted((command) => {
262
247
  * console.log('Command executed:', command);
263
248
  * });
249
+ * ```
264
250
  */
265
251
  onCommandExecuted(callback: CommandListener): IDisposable;
266
252
  /**
@@ -271,7 +257,7 @@ export declare class FWorkbook extends FBaseInitialable {
271
257
  /**
272
258
  * Register a callback that will be triggered when the selection changes.
273
259
  * @param {onSelectionChangeCallback} callback The callback.
274
- * @returns A function to dispose the listening
260
+ * @returns {IDisposable} A function to dispose the listening
275
261
  */
276
262
  onSelectionChange(callback: (selections: IRange[]) => void): IDisposable;
277
263
  /**
@@ -282,13 +268,13 @@ export declare class FWorkbook extends FBaseInitialable {
282
268
  setEditable(value: boolean): FWorkbook;
283
269
  /**
284
270
  * Sets the selection region for active sheet.
285
- * @param range The range to set as the active selection.
271
+ * @param {FRange} range The range to set as the active selection.
286
272
  * @returns {FWorkbook} FWorkbook instance
287
273
  */
288
274
  setActiveRange(range: FRange): FWorkbook;
289
275
  /**
290
276
  * Returns the selected range in the active sheet, or null if there is no active range.
291
- * @returns the active range
277
+ * @returns {FRange | null} The active range
292
278
  */
293
279
  getActiveRange(): FRange | null;
294
280
  /**
@@ -320,7 +306,6 @@ export declare class FWorkbook extends FBaseInitialable {
320
306
  * @returns {FWorksheet} The duplicated worksheet
321
307
  * @example
322
308
  * ```ts
323
- * // The code below duplicates the active sheet
324
309
  * const activeSpreadsheet = univerAPI.getActiveWorkbook();
325
310
  * activeSpreadsheet.duplicateActiveSheet();
326
311
  * ```
@@ -328,7 +313,7 @@ export declare class FWorkbook extends FBaseInitialable {
328
313
  duplicateActiveSheet(): FWorksheet;
329
314
  /**
330
315
  * Get the number of sheets in the workbook.
331
- * @returns The number of sheets in the workbook
316
+ * @returns {number} The number of sheets in the workbook
332
317
  * @example
333
318
  * ```ts
334
319
  * // The code below gets the number of sheets in the workbook
@@ -458,6 +443,7 @@ export declare class FWorkbook extends FBaseInitialable {
458
443
  /**
459
444
  * Insert a defined name by builder param.
460
445
  * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
446
+ * @returns {void}
461
447
  * @example
462
448
  * ```ts
463
449
  * // The code below inserts a defined name by builder param
@@ -471,6 +457,7 @@ export declare class FWorkbook extends FBaseInitialable {
471
457
  /**
472
458
  * Update the defined name with the given name.
473
459
  * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
460
+ * @returns {void}
474
461
  * @example
475
462
  * ```ts
476
463
  * // The code below updates the defined name with the given name
@@ -495,7 +482,8 @@ export declare class FWorkbook extends FBaseInitialable {
495
482
  getRegisteredRangeThemes(): string[];
496
483
  /**
497
484
  * Register a custom range theme style.
498
- * @param rangeThemeStyle
485
+ * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register
486
+ * @returns {void}
499
487
  * @example
500
488
  * ```ts
501
489
  * // import {RangeThemeStyle} from '@univerjs/sheets';
@@ -512,7 +500,8 @@ export declare class FWorkbook extends FBaseInitialable {
512
500
  registerRangeTheme(rangeThemeStyle: RangeThemeStyle): void;
513
501
  /**
514
502
  * Unregister a custom range theme style.
515
- * @param themeName
503
+ * @param {string} themeName The name of the theme to unregister
504
+ * @returns {void}
516
505
  * @example
517
506
  * ```ts
518
507
  * const fWorkbook = univerAPI.getActiveWorkbook();