@univerjs/sheets 0.5.3 → 0.5.4-experimental.20250114-7c09c35

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,39 +1,43 @@
1
- import { IDisposable, Injector, IWorkbookData, FUniver } from '@univerjs/core';
1
+ import { ICommandInfo, IDisposable, Injector, IWorkbookData, Nullable, FUniver } from '@univerjs/core';
2
+ import { FWorksheet } from './f-worksheet';
2
3
  import { FDefinedNameBuilder } from './f-defined-name';
3
4
  import { FPermission } from './f-permission';
4
5
  import { FWorkbook } from './f-workbook';
5
6
  export interface IFUniverSheetsMixin {
7
+ /**
8
+ * @deprecated use `univerAPI.createWorkbook` instead.
9
+ */
10
+ createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;
6
11
  /**
7
12
  * Create a new spreadsheet and get the API handler of that spreadsheet.
8
- *
9
13
  * @param {Partial<IWorkbookData>} data The snapshot of the spreadsheet.
10
14
  * @returns {FWorkbook} FWorkbook API instance.
11
15
  * @example
12
16
  * ```ts
13
- * univerAPI.createUniverSheet({ id: 'Sheet1', name: 'Sheet1' });
17
+ * univerAPI.createWorkbook({ id: 'Sheet1', name: 'Sheet1' });
14
18
  * ```
15
19
  */
16
- createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;
20
+ createWorkbook(data: Partial<IWorkbookData>): FWorkbook;
17
21
  /**
18
22
  * Get the currently focused Univer spreadsheet.
19
23
  * @returns {FWorkbook | null} The currently focused Univer spreadsheet.
20
24
  * @example
21
25
  * ```ts
22
- * univerAPI.getActiveUniverSheet();
26
+ * univerAPI.getActiveWorkbook();
23
27
  * ```
24
28
  */
25
- getActiveUniverSheet(): FWorkbook | null;
29
+ getActiveWorkbook(): FWorkbook | null;
26
30
  /**
27
- * @deprecated use `getActiveUniverSheet` as instead.
31
+ * @deprecated use `univerAPI.getActiveWorkbook` instead
28
32
  */
29
- getActiveWorkbook(): FWorkbook | null;
33
+ getActiveUniverSheet(): FWorkbook | null;
30
34
  /**
31
35
  * Get the spreadsheet API handler by the spreadsheet id.
32
- *
33
36
  * @param {string} id The spreadsheet id.
34
37
  * @returns {FWorkbook | null} The spreadsheet API instance.
35
38
  */
36
39
  getUniverSheet(id: string): FWorkbook | null;
40
+ getWorkbook(id: string): FWorkbook | null;
37
41
  /**
38
42
  * Get the PermissionInstance.
39
43
  * @deprecated This function is deprecated and will be removed in version 0.6.0. Please use the function with the same name on the `FWorkbook` instance instead.
@@ -46,20 +50,61 @@ export interface IFUniverSheetsMixin {
46
50
  /**
47
51
  * Create a new defined name builder.
48
52
  * @returns {FDefinedNameBuilder} - The defined name builder.
49
- *
50
53
  * @example
51
54
  * ```ts
52
55
  * univerAPI.newDefinedName();
53
56
  * ```
54
57
  */
55
58
  newDefinedName(): FDefinedNameBuilder;
59
+ /**
60
+ * Get the target of the sheet.
61
+ * @param {string} unitId - The unitId of the sheet.
62
+ * @param {string} subUnitId - The subUnitId of the sheet.
63
+ * @returns {Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>} - The target of the sheet.
64
+ * @example
65
+ * ```ts
66
+ * univerAPI.getSheetTarget('unitId', 'subUnitId');
67
+ * ```
68
+ */
69
+ getSheetTarget(unitId: string, subUnitId: string): Nullable<{
70
+ workbook: FWorkbook;
71
+ worksheet: FWorksheet;
72
+ }>;
73
+ /**
74
+ * Get the target of the sheet.
75
+ * @param {ICommandInfo<object>} commandInfo - The commandInfo of the command.
76
+ * @returns {Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>} - The target of the sheet.
77
+ * @example
78
+ * ```ts
79
+ * univerAPI.addEvent(univerAPI.event.CommandExecuted, (commandInfo) => {
80
+ * const target = univerAPI.getCommandSheetTarget(commandInfo);
81
+ * if (!target) return;
82
+ * const { workbook, worksheet } = target;
83
+ * });
84
+ * ```
85
+ */
86
+ getCommandSheetTarget(commandInfo: ICommandInfo<object>): Nullable<{
87
+ workbook: FWorkbook;
88
+ worksheet: FWorksheet;
89
+ }>;
56
90
  }
57
91
  export declare class FUniverSheetsMixin extends FUniver implements IFUniverSheetsMixin {
92
+ getCommandSheetTarget(commandInfo: ICommandInfo<object>): Nullable<{
93
+ workbook: FWorkbook;
94
+ worksheet: FWorksheet;
95
+ }>;
96
+ getSheetTarget(unitId: string, subUnitId: string): Nullable<{
97
+ workbook: FWorkbook;
98
+ worksheet: FWorksheet;
99
+ }>;
100
+ private _initWorkbookEvent;
58
101
  _initialize(injector: Injector): void;
59
102
  createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;
60
- getActiveUniverSheet(): FWorkbook | null;
103
+ createWorkbook(data: Partial<IWorkbookData>): FWorkbook;
61
104
  getActiveWorkbook(): FWorkbook | null;
105
+ getActiveUniverSheet(): FWorkbook | null;
62
106
  getUniverSheet(id: string): FWorkbook | null;
107
+ getWorkbook(id: string): FWorkbook | null;
63
108
  getPermission(): FPermission;
64
109
  onUniverSheetCreated(callback: (workbook: FWorkbook) => void): IDisposable;
65
110
  newDefinedName(): FDefinedNameBuilder;
@@ -1,9 +1,9 @@
1
- import { CommandListener, IDisposable, IRange, IWorkbookData, LocaleType, Workbook, FBaseInitialable, ICommandService, ILogService, Injector, IPermissionService, IResourceLoaderService, IUniverInstanceService, LocaleService } from '@univerjs/core';
1
+ import { CommandListener, CustomData, IDisposable, IEventParamConfig, IRange, IWorkbookData, LocaleType, Workbook, FBaseInitialable, FEnum, FEventName, 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
+ import { FontLine as _FontLine, FRange } from './f-range';
4
5
  import { FDefinedName } from './f-defined-name';
5
6
  import { FPermission } from './f-permission';
6
- import { FRange } from './f-range';
7
7
  import { FWorksheet } from './f-worksheet';
8
8
  export declare class FWorkbook extends FBaseInitialable {
9
9
  protected readonly _workbook: Workbook;
@@ -18,6 +18,39 @@ 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
+ /**
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
29
+ * @example
30
+ * ```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);
45
+ * ```
46
+ */
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;
21
54
  /**
22
55
  * Get the id of the workbook.
23
56
  * @returns {string} The id of the workbook.
@@ -52,8 +85,8 @@ export declare class FWorkbook extends FBaseInitialable {
52
85
  */
53
86
  setName(name: string): void;
54
87
  /**
55
- * save workbook snapshot data, including conditional formatting, data validation, and other plugin data.
56
- * @return Workbook snapshot data
88
+ * Save workbook snapshot data, including conditional formatting, data validation, and other plugin data.
89
+ * @returns {IWorkbookData} Workbook snapshot data
57
90
  * @example
58
91
  * ```ts
59
92
  * // The code below saves the workbook snapshot data
@@ -64,13 +97,13 @@ export declare class FWorkbook extends FBaseInitialable {
64
97
  save(): IWorkbookData;
65
98
  /**
66
99
  * @deprecated use 'save' instead.
67
- * @return {*} {IWorkbookData} Workbook snapshot data
100
+ * @returns {*} {IWorkbookData} Workbook snapshot data
68
101
  * @memberof FWorkbook
69
102
  */
70
103
  getSnapshot(): IWorkbookData;
71
104
  /**
72
105
  * Get the active sheet of the workbook.
73
- * @returns The active sheet of the workbook
106
+ * @returns {FWorksheet} The active sheet of the workbook
74
107
  * @example
75
108
  * ```ts
76
109
  * // The code below gets the active sheet of the workbook
@@ -81,7 +114,7 @@ export declare class FWorkbook extends FBaseInitialable {
81
114
  getActiveSheet(): FWorksheet;
82
115
  /**
83
116
  * Gets all the worksheets in this workbook
84
- * @returns An array of all the worksheets in the workbook
117
+ * @returns {FWorksheet[]} An array of all the worksheets in the workbook
85
118
  * @example
86
119
  * ```ts
87
120
  * // The code below gets all the worksheets in the workbook
@@ -107,7 +140,7 @@ export declare class FWorkbook extends FBaseInitialable {
107
140
  /**
108
141
  * Get a worksheet by sheet id.
109
142
  * @param sheetId The id of the sheet to get.
110
- * @return The worksheet with given sheet id
143
+ * @returns The worksheet with given sheet id
111
144
  * @example
112
145
  * ```ts
113
146
  * // The code below gets a worksheet by sheet id
@@ -161,6 +194,7 @@ export declare class FWorkbook extends FBaseInitialable {
161
194
  /**
162
195
  * Deletes the specified worksheet.
163
196
  * @param sheet The worksheet to delete.
197
+ * @returns {boolean} True if the worksheet was deleted, false otherwise.
164
198
  * @example
165
199
  * ```ts
166
200
  * // The code below deletes the specified worksheet
@@ -172,7 +206,7 @@ export declare class FWorkbook extends FBaseInitialable {
172
206
  deleteSheet(sheet: FWorksheet): boolean;
173
207
  /**
174
208
  * Undo the last action.
175
- * @returns A promise that resolves to true if the undo was successful, false otherwise.
209
+ * @returns {FWorkbook} A promise that resolves to true if the undo was successful, false otherwise.
176
210
  * @example
177
211
  * ```ts
178
212
  * // The code below undoes the last action
@@ -231,7 +265,6 @@ export declare class FWorkbook extends FBaseInitialable {
231
265
  onCommandExecuted(callback: CommandListener): IDisposable;
232
266
  /**
233
267
  * Callback for selection changes.
234
- *
235
268
  * @callback onSelectionChangeCallback
236
269
  * @param {IRange[]} selections The new selection.
237
270
  */
@@ -244,13 +277,15 @@ export declare class FWorkbook extends FBaseInitialable {
244
277
  /**
245
278
  * Used to modify the editing permissions of the workbook. When the value is false, editing is not allowed.
246
279
  * @param {boolean} value editable value want to set
280
+ * @returns {FWorkbook} FWorkbook instance
247
281
  */
248
- setEditable(value: boolean): void;
282
+ setEditable(value: boolean): FWorkbook;
249
283
  /**
250
- * Sets the active selection region for this sheet.
284
+ * Sets the selection region for active sheet.
251
285
  * @param range The range to set as the active selection.
286
+ * @returns {FWorkbook} FWorkbook instance
252
287
  */
253
- setActiveRange(range: FRange): void;
288
+ setActiveRange(range: FRange): FWorkbook;
254
289
  /**
255
290
  * Returns the selected range in the active sheet, or null if there is no active range.
256
291
  * @returns the active range
@@ -258,6 +293,7 @@ export declare class FWorkbook extends FBaseInitialable {
258
293
  getActiveRange(): FRange | null;
259
294
  /**
260
295
  * Deletes the currently active sheet.
296
+ * @returns {boolean} true if the sheet was deleted, false otherwise
261
297
  * @example
262
298
  * ```ts
263
299
  * // The code below deletes the currently active sheet and stores the new active
@@ -312,9 +348,15 @@ export declare class FWorkbook extends FBaseInitialable {
312
348
  * ```
313
349
  */
314
350
  getLocale(): LocaleType;
351
+ /**
352
+ * @deprecated use setSpreadsheetLocale instead.
353
+ * @param {LocaleType} locale - The locale to set
354
+ */
355
+ setLocale(locale: LocaleType): void;
315
356
  /**
316
357
  * Set the locale of the workbook.
317
358
  * @param {LocaleType} locale The locale to set
359
+ * @returns {FWorkbook} This workbook, for chaining
318
360
  * @example
319
361
  * ```ts
320
362
  * // The code below sets the locale of the workbook
@@ -322,7 +364,7 @@ export declare class FWorkbook extends FBaseInitialable {
322
364
  * activeSpreadsheet.setLocale(LocaleType.EN_US);
323
365
  * ```
324
366
  */
325
- setLocale(locale: LocaleType): void;
367
+ setSpreadsheetLocale(locale: LocaleType): FWorkbook;
326
368
  /**
327
369
  * Get the URL of the workbook.
328
370
  * @returns {string} The URL of the workbook
@@ -362,7 +404,6 @@ export declare class FWorkbook extends FBaseInitialable {
362
404
  moveActiveSheet(index: number): FWorkbook;
363
405
  /**
364
406
  * Get the PermissionInstance.
365
- *
366
407
  * @returns {FPermission} - The PermissionInstance.
367
408
  */
368
409
  getPermission(): FPermission;
@@ -393,6 +434,7 @@ export declare class FWorkbook extends FBaseInitialable {
393
434
  * Insert a defined name.
394
435
  * @param {string} name The name of the defined name to insert
395
436
  * @param {string} formulaOrRefString The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
437
+ * @returns {FWorkbook} The current FWorkbook instance
396
438
  * @example
397
439
  * ```ts
398
440
  * // The code below inserts a defined name
@@ -400,7 +442,7 @@ export declare class FWorkbook extends FBaseInitialable {
400
442
  * activeSpreadsheet.insertDefinedName('MyDefinedName', 'Sheet1!A1');
401
443
  * ```
402
444
  */
403
- insertDefinedName(name: string, formulaOrRefString: string): void;
445
+ insertDefinedName(name: string, formulaOrRefString: string): FWorkbook;
404
446
  /**
405
447
  * Delete the defined name with the given name.
406
448
  * @param {string} name The name of the defined name to delete
@@ -414,7 +456,7 @@ export declare class FWorkbook extends FBaseInitialable {
414
456
  */
415
457
  deleteDefinedName(name: string): boolean;
416
458
  /**
417
- * insert a defined name by builder param
459
+ * Insert a defined name by builder param.
418
460
  * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
419
461
  * @example
420
462
  * ```ts
@@ -453,6 +495,7 @@ export declare class FWorkbook extends FBaseInitialable {
453
495
  getRegisteredRangeThemes(): string[];
454
496
  /**
455
497
  * Register a custom range theme style.
498
+ * @param rangeThemeStyle
456
499
  * @example
457
500
  * ```ts
458
501
  * // import {RangeThemeStyle} from '@univerjs/sheets';
@@ -469,6 +512,7 @@ export declare class FWorkbook extends FBaseInitialable {
469
512
  registerRangeTheme(rangeThemeStyle: RangeThemeStyle): void;
470
513
  /**
471
514
  * Unregister a custom range theme style.
515
+ * @param themeName
472
516
  * @example
473
517
  * ```ts
474
518
  * const fWorkbook = univerAPI.getActiveWorkbook();
@@ -476,4 +520,30 @@ export declare class FWorkbook extends FBaseInitialable {
476
520
  * ```
477
521
  */
478
522
  unregisterRangeTheme(themeName: string): void;
523
+ /**
524
+ * Set custom metadata of workbook
525
+ * @param {CustomData | undefined} custom custom metadata
526
+ * @returns {FWorkbook} FWorkbook
527
+ * @example
528
+ * ```ts
529
+ * const fWorkbook = univerAPI.getActiveWorkbook();
530
+ * fWorkbook.setCustomMetadata({ key: 'value' });
531
+ * ```
532
+ */
533
+ setCustomMetadata(custom: CustomData | undefined): FWorkbook;
534
+ /**
535
+ * Get custom metadata of workbook
536
+ * @returns {CustomData | undefined} custom metadata
537
+ * @example
538
+ * ```ts
539
+ * const fWorkbook = univerAPI.getActiveWorkbook();
540
+ * const custom = fWorkbook.getCustomMetadata();
541
+ * ```
542
+ */
543
+ getCustomMetadata(): CustomData | undefined;
544
+ }
545
+ export declare namespace FWorkbook {
546
+ type FontLine = _FontLine;
547
+ type FontStyle = _FontLine;
548
+ type FontWeight = _FontLine;
479
549
  }