@univerjs/sheets 0.5.4 → 0.5.5-experimental.20250122-3362a4a

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.
Files changed (52) hide show
  1. package/lib/cjs/facade.js +1 -1
  2. package/lib/cjs/index.js +3 -3
  3. package/lib/cjs/locale/en-US.js +1 -1
  4. package/lib/cjs/locale/fa-IR.js +1 -1
  5. package/lib/cjs/locale/fr-FR.js +1 -1
  6. package/lib/cjs/locale/ru-RU.js +1 -1
  7. package/lib/cjs/locale/vi-VN.js +1 -1
  8. package/lib/cjs/locale/zh-CN.js +1 -1
  9. package/lib/cjs/locale/zh-TW.js +1 -1
  10. package/lib/es/facade.js +2465 -1429
  11. package/lib/es/index.js +9099 -8683
  12. package/lib/es/locale/en-US.js +2 -2
  13. package/lib/es/locale/fa-IR.js +2 -2
  14. package/lib/es/locale/fr-FR.js +2 -2
  15. package/lib/es/locale/ru-RU.js +2 -2
  16. package/lib/es/locale/vi-VN.js +2 -2
  17. package/lib/es/locale/zh-CN.js +2 -2
  18. package/lib/es/locale/zh-TW.js +2 -2
  19. package/lib/types/basics/const/command-listener-const.d.ts +149 -13
  20. package/lib/types/commands/commands/remove-sheet.command.d.ts +1 -1
  21. package/lib/types/commands/commands/split-text-to-columns.command.d.ts +1 -1
  22. package/lib/types/commands/operations/selection.operation.d.ts +1 -0
  23. package/lib/types/commands/utils/selection-command-util.d.ts +1 -1
  24. package/lib/types/controllers/config.schema.d.ts +4 -0
  25. package/lib/types/facade/f-defined-name.d.ts +6 -0
  26. package/lib/types/facade/f-enum.d.ts +21 -0
  27. package/lib/types/facade/f-event.d.ts +470 -21
  28. package/lib/types/facade/f-permission.d.ts +3 -0
  29. package/lib/types/facade/f-range.d.ts +366 -51
  30. package/lib/types/facade/f-selection.d.ts +25 -0
  31. package/lib/types/facade/f-sheet-hooks.d.ts +3 -0
  32. package/lib/types/facade/f-univer.d.ts +33 -0
  33. package/lib/types/facade/f-workbook.d.ts +49 -56
  34. package/lib/types/facade/f-worksheet.d.ts +653 -208
  35. package/lib/types/facade/index.d.ts +2 -0
  36. package/lib/types/index.d.ts +2 -1
  37. package/lib/types/model/range-theme-util.d.ts +3 -3
  38. package/lib/types/services/permission/range-permission/range-protection.ref-range.d.ts +1 -1
  39. package/lib/types/services/permission/range-permission/range-protection.service.d.ts +1 -1
  40. package/lib/types/services/selections/selection-data-model.d.ts +7 -7
  41. package/lib/types/services/selections/selection.service.d.ts +4 -0
  42. package/lib/umd/facade.js +1 -1
  43. package/lib/umd/index.js +3 -3
  44. package/lib/umd/locale/en-US.js +1 -1
  45. package/lib/umd/locale/fa-IR.js +1 -1
  46. package/lib/umd/locale/fr-FR.js +1 -1
  47. package/lib/umd/locale/ru-RU.js +1 -1
  48. package/lib/umd/locale/vi-VN.js +1 -1
  49. package/lib/umd/locale/zh-CN.js +1 -1
  50. package/lib/umd/locale/zh-TW.js +1 -1
  51. package/package.json +6 -6
  52. package/LICENSE +0 -176
@@ -12,6 +12,7 @@ import { FWorksheet } from './f-worksheet';
12
12
  * const activeRange = fSelection.getActiveRange();
13
13
  * console.log(activeRange);
14
14
  * ```
15
+ * @hideconstructor
15
16
  */
16
17
  export declare class FSelection {
17
18
  private readonly _workbook;
@@ -22,16 +23,40 @@ export declare class FSelection {
22
23
  /**
23
24
  * Represents the active selection in the sheet. Which means the selection contains the active cell.
24
25
  * @returns {FRange | null} The active selection.
26
+ * @example
27
+ * ```ts
28
+ * const fWorkbook = univerAPI.getActiveWorkbook();
29
+ * const fWorksheet = fWorkbook.getActiveSheet();
30
+ * const fSelection = fWorksheet.getSelection();
31
+ * const activeRange = fSelection.getActiveRange();
32
+ * console.log(activeRange);
33
+ * ```
25
34
  */
26
35
  getActiveRange(): FRange | null;
27
36
  /**
28
37
  * Represents the active selection list in the sheet.
29
38
  * @returns {FRange[]} The active selection list.
39
+ * @example
40
+ * ```ts
41
+ * const fWorkbook = univerAPI.getActiveWorkbook();
42
+ * const fWorksheet = fWorkbook.getActiveSheet();
43
+ * const fSelection = fWorksheet.getSelection();
44
+ * const activeRangeList = fSelection.getActiveRangeList();
45
+ * console.log(activeRangeList);
46
+ * ```
30
47
  */
31
48
  getActiveRangeList(): FRange[];
32
49
  /**
33
50
  * Represents the current select cell in the sheet.
34
51
  * @returns {ISelectionCell} The current select cell info.Pay attention to the type of the return value.
52
+ * @example
53
+ * ```ts
54
+ * const fWorkbook = univerAPI.getActiveWorkbook();
55
+ * const fWorksheet = fWorkbook.getActiveSheet();
56
+ * const fSelection = fWorksheet.getSelection();
57
+ * const currentCell = fSelection.getCurrentCell();
58
+ * console.log(currentCell);
59
+ * ```
35
60
  */
36
61
  getCurrentCell(): Nullable<ISelectionCell>;
37
62
  /**
@@ -1,4 +1,7 @@
1
1
  import { FBase, Injector } from '@univerjs/core';
2
+ /**
3
+ * @hideconstructor
4
+ */
2
5
  export declare class FSheetHooks extends FBase {
3
6
  protected readonly _injector: Injector;
4
7
  constructor(_injector: Injector);
@@ -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<{
@@ -98,6 +112,9 @@ export declare class FUniverSheetsMixin extends FUniver implements IFUniverSheet
98
112
  worksheet: FWorksheet;
99
113
  }>;
100
114
  private _initWorkbookEvent;
115
+ /**
116
+ * @ignore
117
+ */
101
118
  _initialize(injector: Injector): void;
102
119
  createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;
103
120
  createWorkbook(data: Partial<IWorkbookData>): FWorkbook;
@@ -108,6 +125,22 @@ export declare class FUniverSheetsMixin extends FUniver implements IFUniverSheet
108
125
  getPermission(): FPermission;
109
126
  onUniverSheetCreated(callback: (workbook: FWorkbook) => void): IDisposable;
110
127
  newDefinedName(): FDefinedNameBuilder;
128
+ getActiveSheet(): Nullable<{
129
+ workbook: FWorkbook;
130
+ worksheet: FWorksheet;
131
+ }>;
132
+ private _fireBeforeActiveSheetChange;
133
+ private _fireActiveSheetChanged;
134
+ private _fireBeforeSheetDelete;
135
+ private _fireSheetDeleted;
136
+ private _fireBeforeSheetMove;
137
+ private _fireSheetMoved;
138
+ private _fireBeforeSheetNameChange;
139
+ private _fireSheetNameChanged;
140
+ private _fireBeforeSheetTabColorChange;
141
+ private _fireSheetTabColorChanged;
142
+ private _fireBeforeSheetHideChange;
143
+ private _fireSheetHideChanged;
111
144
  }
112
145
  declare module '@univerjs/core' {
113
146
  interface FUniver extends IFUniverSheetsMixin {
@@ -1,10 +1,13 @@
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
- import { RangeThemeStyle, SheetsSelectionsService } from '@univerjs/sheets';
3
+ import { IRangeThemeStyleJSON, RangeThemeStyle, SheetsSelectionsService } from '@univerjs/sheets';
4
4
  import { FontLine as _FontLine, FRange } from './f-range';
5
5
  import { FDefinedName } from './f-defined-name';
6
6
  import { FPermission } from './f-permission';
7
7
  import { FWorksheet } from './f-worksheet';
8
+ /**
9
+ * @hideconstructor
10
+ */
8
11
  export declare class FWorkbook extends FBaseInitialable {
9
12
  protected readonly _workbook: Workbook;
10
13
  protected readonly _injector: Injector;
@@ -18,39 +21,17 @@ export declare class FWorkbook extends FBaseInitialable {
18
21
  protected readonly _definedNamesService: IDefinedNamesService;
19
22
  readonly id: string;
20
23
  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
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
25
+ * Get the Workbook instance.
26
+ * @returns {Workbook} The Workbook instance.
29
27
  * @example
30
28
  * ```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);
29
+ * // The code below gets the Workbook instance
30
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
31
+ * const workbook = activeSpreadsheet.getWorkbook();
45
32
  * ```
46
33
  */
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;
34
+ getWorkbook(): Workbook;
54
35
  /**
55
36
  * Get the id of the workbook.
56
37
  * @returns {string} The id of the workbook.
@@ -76,6 +57,7 @@ export declare class FWorkbook extends FBaseInitialable {
76
57
  /**
77
58
  * Set the name of the workbook.
78
59
  * @param {string} name The new name of the workbook.
60
+ * @returns {void}
79
61
  * @example
80
62
  * ```ts
81
63
  * // The code below sets the name of the workbook
@@ -97,8 +79,14 @@ export declare class FWorkbook extends FBaseInitialable {
97
79
  save(): IWorkbookData;
98
80
  /**
99
81
  * @deprecated use 'save' instead.
100
- * @returns {*} {IWorkbookData} Workbook snapshot data
82
+ * @returns {IWorkbookData} Workbook snapshot data
101
83
  * @memberof FWorkbook
84
+ * @example
85
+ * ```ts
86
+ * // The code below saves the workbook snapshot data
87
+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();
88
+ * const snapshot = activeSpreadsheet.getSnapshot();
89
+ * ```
102
90
  */
103
91
  getSnapshot(): IWorkbookData;
104
92
  /**
@@ -125,10 +113,10 @@ export declare class FWorkbook extends FBaseInitialable {
125
113
  getSheets(): FWorksheet[];
126
114
  /**
127
115
  * 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
116
+ * @param {string} name Name of the new sheet
117
+ * @param {number} rows How many rows would the new sheet have
118
+ * @param {number} column How many columns would the new sheet have
119
+ * @returns {FWorksheet} The new created sheet
132
120
  * @example
133
121
  * ```ts
134
122
  * // The code below creates a new sheet
@@ -139,8 +127,8 @@ export declare class FWorkbook extends FBaseInitialable {
139
127
  create(name: string, rows: number, column: number): FWorksheet;
140
128
  /**
141
129
  * Get a worksheet by sheet id.
142
- * @param sheetId The id of the sheet to get.
143
- * @returns The worksheet with given sheet id
130
+ * @param {string} sheetId The id of the sheet to get.
131
+ * @returns {FWorksheet | null} The worksheet with given sheet id
144
132
  * @example
145
133
  * ```ts
146
134
  * // The code below gets a worksheet by sheet id
@@ -151,8 +139,8 @@ export declare class FWorkbook extends FBaseInitialable {
151
139
  getSheetBySheetId(sheetId: string): FWorksheet | null;
152
140
  /**
153
141
  * Get a worksheet by sheet name.
154
- * @param name The name of the sheet to get.
155
- * @returns The worksheet with given sheet name
142
+ * @param {string} name The name of the sheet to get.
143
+ * @returns {FWorksheet | null} The worksheet with given sheet name
156
144
  * @example
157
145
  * ```ts
158
146
  * // The code below gets a worksheet by sheet name
@@ -163,8 +151,8 @@ export declare class FWorkbook extends FBaseInitialable {
163
151
  getSheetByName(name: string): FWorksheet | null;
164
152
  /**
165
153
  * 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
154
+ * @param {FWorksheet | string} sheet The worksheet to set as the active worksheet.
155
+ * @returns {FWorksheet} The active worksheet
168
156
  * @example
169
157
  * ```ts
170
158
  * // The code below sets the given worksheet to be the active worksheet
@@ -173,12 +161,12 @@ export declare class FWorkbook extends FBaseInitialable {
173
161
  * activeSpreadsheet.setActiveSheet(sheet);
174
162
  * ```
175
163
  */
176
- setActiveSheet(sheet: FWorksheet): FWorksheet;
164
+ setActiveSheet(sheet: FWorksheet | string): FWorksheet;
177
165
  /**
178
166
  * Inserts a new worksheet into the workbook.
179
167
  * 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
168
+ * @param {string} [sheetName] The name of the new sheet
169
+ * @returns {FWorksheet} The new sheet
182
170
  * @example
183
171
  * ```ts
184
172
  * // The code below inserts a new sheet into the workbook
@@ -193,7 +181,7 @@ export declare class FWorkbook extends FBaseInitialable {
193
181
  insertSheet(sheetName?: string): FWorksheet;
194
182
  /**
195
183
  * Deletes the specified worksheet.
196
- * @param sheet The worksheet to delete.
184
+ * @param {FWorksheet | string} sheet The worksheet to delete.
197
185
  * @returns {boolean} True if the worksheet was deleted, false otherwise.
198
186
  * @example
199
187
  * ```ts
@@ -203,7 +191,7 @@ export declare class FWorkbook extends FBaseInitialable {
203
191
  * activeSpreadsheet.deleteSheet(sheet);
204
192
  * ```
205
193
  */
206
- deleteSheet(sheet: FWorksheet): boolean;
194
+ deleteSheet(sheet: FWorksheet | string): boolean;
207
195
  /**
208
196
  * Undo the last action.
209
197
  * @returns {FWorkbook} A promise that resolves to true if the undo was successful, false otherwise.
@@ -217,7 +205,7 @@ export declare class FWorkbook extends FBaseInitialable {
217
205
  undo(): FWorkbook;
218
206
  /**
219
207
  * Redo the last undone action.
220
- * @returns A promise that resolves to true if the redo was successful, false otherwise.
208
+ * @returns {FWorkbook} A promise that resolves to true if the redo was successful, false otherwise.
221
209
  * @example
222
210
  * ```ts
223
211
  * // The code below redoes the last undone action
@@ -234,7 +222,7 @@ export declare class FWorkbook extends FBaseInitialable {
234
222
  /**
235
223
  * Register a callback that will be triggered before invoking a command targeting the Univer sheet.
236
224
  * @param {onBeforeCommandExecuteCallback} callback the callback.
237
- * @returns A function to dispose the listening.
225
+ * @returns {IDisposable} A function to dispose the listening.
238
226
  * @example
239
227
  * ```ts
240
228
  * // The code below registers a callback that will be triggered before invoking a command targeting the Univer sheet
@@ -253,7 +241,7 @@ export declare class FWorkbook extends FBaseInitialable {
253
241
  /**
254
242
  * Register a callback that will be triggered when a command is invoked targeting the Univer sheet.
255
243
  * @param {onCommandExecutedCallback} callback the callback.
256
- * @returns A function to dispose the listening.
244
+ * @returns {IDisposable} A function to dispose the listening.
257
245
  * @example
258
246
  * ```ts
259
247
  * // The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheet
@@ -261,6 +249,7 @@ export declare class FWorkbook extends FBaseInitialable {
261
249
  * activeSpreadsheet.onCommandExecuted((command) => {
262
250
  * console.log('Command executed:', command);
263
251
  * });
252
+ * ```
264
253
  */
265
254
  onCommandExecuted(callback: CommandListener): IDisposable;
266
255
  /**
@@ -271,7 +260,7 @@ export declare class FWorkbook extends FBaseInitialable {
271
260
  /**
272
261
  * Register a callback that will be triggered when the selection changes.
273
262
  * @param {onSelectionChangeCallback} callback The callback.
274
- * @returns A function to dispose the listening
263
+ * @returns {IDisposable} A function to dispose the listening
275
264
  */
276
265
  onSelectionChange(callback: (selections: IRange[]) => void): IDisposable;
277
266
  /**
@@ -282,13 +271,13 @@ export declare class FWorkbook extends FBaseInitialable {
282
271
  setEditable(value: boolean): FWorkbook;
283
272
  /**
284
273
  * Sets the selection region for active sheet.
285
- * @param range The range to set as the active selection.
274
+ * @param {FRange} range The range to set as the active selection.
286
275
  * @returns {FWorkbook} FWorkbook instance
287
276
  */
288
277
  setActiveRange(range: FRange): FWorkbook;
289
278
  /**
290
279
  * Returns the selected range in the active sheet, or null if there is no active range.
291
- * @returns the active range
280
+ * @returns {FRange | null} The active range
292
281
  */
293
282
  getActiveRange(): FRange | null;
294
283
  /**
@@ -320,7 +309,6 @@ export declare class FWorkbook extends FBaseInitialable {
320
309
  * @returns {FWorksheet} The duplicated worksheet
321
310
  * @example
322
311
  * ```ts
323
- * // The code below duplicates the active sheet
324
312
  * const activeSpreadsheet = univerAPI.getActiveWorkbook();
325
313
  * activeSpreadsheet.duplicateActiveSheet();
326
314
  * ```
@@ -328,7 +316,7 @@ export declare class FWorkbook extends FBaseInitialable {
328
316
  duplicateActiveSheet(): FWorksheet;
329
317
  /**
330
318
  * Get the number of sheets in the workbook.
331
- * @returns The number of sheets in the workbook
319
+ * @returns {number} The number of sheets in the workbook
332
320
  * @example
333
321
  * ```ts
334
322
  * // The code below gets the number of sheets in the workbook
@@ -458,6 +446,7 @@ export declare class FWorkbook extends FBaseInitialable {
458
446
  /**
459
447
  * Insert a defined name by builder param.
460
448
  * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
449
+ * @returns {void}
461
450
  * @example
462
451
  * ```ts
463
452
  * // The code below inserts a defined name by builder param
@@ -471,6 +460,7 @@ export declare class FWorkbook extends FBaseInitialable {
471
460
  /**
472
461
  * Update the defined name with the given name.
473
462
  * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
463
+ * @returns {void}
474
464
  * @example
475
465
  * ```ts
476
466
  * // The code below updates the defined name with the given name
@@ -495,7 +485,8 @@ export declare class FWorkbook extends FBaseInitialable {
495
485
  getRegisteredRangeThemes(): string[];
496
486
  /**
497
487
  * Register a custom range theme style.
498
- * @param rangeThemeStyle
488
+ * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register
489
+ * @returns {void}
499
490
  * @example
500
491
  * ```ts
501
492
  * // import {RangeThemeStyle} from '@univerjs/sheets';
@@ -512,7 +503,8 @@ export declare class FWorkbook extends FBaseInitialable {
512
503
  registerRangeTheme(rangeThemeStyle: RangeThemeStyle): void;
513
504
  /**
514
505
  * Unregister a custom range theme style.
515
- * @param themeName
506
+ * @param {string} themeName The name of the theme to unregister
507
+ * @returns {void}
516
508
  * @example
517
509
  * ```ts
518
510
  * const fWorkbook = univerAPI.getActiveWorkbook();
@@ -520,6 +512,7 @@ export declare class FWorkbook extends FBaseInitialable {
520
512
  * ```
521
513
  */
522
514
  unregisterRangeTheme(themeName: string): void;
515
+ createRangeThemeStyle(themeName: string, themeStyleJson?: Omit<IRangeThemeStyleJSON, 'name'>): RangeThemeStyle;
523
516
  /**
524
517
  * Set custom metadata of workbook
525
518
  * @param {CustomData | undefined} custom custom metadata