@univerjs/core 0.5.2 → 0.5.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.
@@ -5,6 +5,7 @@ export declare enum InterceptorEffectEnum {
5
5
  Value = 2
6
6
  }
7
7
  export interface IInterceptor<M, C> {
8
+ id?: string;
8
9
  priority?: number;
9
10
  handler: InterceptorHandler<M, C>;
10
11
  }
@@ -26,7 +27,14 @@ export declare class InterceptorManager<P extends Record<string, IInterceptor<an
26
27
  private _interceptorsByName;
27
28
  private _interceptorPoints;
28
29
  constructor(interceptorPoints: P);
29
- fetchThroughInterceptors<T, C>(name: IInterceptor<T, C>): (initValue: Nullable<T>, initContext: C) => Nullable<T>;
30
+ /**
31
+ * Get the interceptors.
32
+ * @param name Name of the intercepted point.
33
+ * @param filter A callback function to filter the interceptors.
34
+ * @returns It will return a composed interceptor function. If you will perform the interceptor repeatedly,
35
+ * you should cache the result instead of calling this function multiple times.
36
+ */
37
+ fetchThroughInterceptors<T, C>(name: IInterceptor<T, C>, filter?: (interceptor: IInterceptor<any, any>) => boolean): (initValue: Nullable<T>, initContext: C) => Nullable<T>;
30
38
  intercept<T extends IInterceptor<any, any>>(name: T, interceptor: T): () => boolean;
31
39
  getInterceptPoints(): P;
32
40
  dispose(): void;
@@ -47,7 +55,14 @@ export declare class AsyncInterceptorManager<P extends Record<string, IAsyncInte
47
55
  private _asyncInterceptorsByName;
48
56
  private _asyncInterceptorPoints;
49
57
  constructor(asyncInterceptorPoints: P);
50
- fetchThroughAsyncInterceptors<T, C>(name: IAsyncInterceptor<T, C>): (initialValue: Nullable<T>, context: C) => Promise<Nullable<T>>;
58
+ /**
59
+ * Get the interceptors.
60
+ * @param name Name of the intercepted point.
61
+ * @param filter A callback function to filter the interceptors.
62
+ * @returns It will return a composed interceptor function. If you will perform the interceptor repeatedly,
63
+ * you should cache the result instead of calling this function multiple times.
64
+ */
65
+ fetchThroughAsyncInterceptors<T, C>(name: IAsyncInterceptor<T, C>, filter?: (interceptor: IAsyncInterceptor<any, any>) => boolean): (initialValue: Nullable<T>, context: C) => Promise<Nullable<T>>;
51
66
  interceptAsync<T extends IAsyncInterceptor<any, any>>(name: T, interceptor: T): Promise<() => boolean>;
52
67
  getInterceptPoints(): P;
53
68
  dispose(): void;
@@ -1,26 +1,19 @@
1
- /**
2
- * Copyright 2023-present DreamNum Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
1
+ import { Injector } from '@wendellhu/redi';
2
+ import { Disposable } from '../shared';
16
3
  /**
17
4
  * `FBase` is a base class for all facade classes.
18
5
  * It provides a way to extend classes with static and instance methods.
19
6
  * The `_initialize` as a special method that will be called after the constructor. You should never call it directly.
20
7
  */
21
- export declare abstract class FBase {
22
- private static _constructorQueue;
23
- constructor();
24
- _initialize(): void;
8
+ export declare abstract class FBase extends Disposable {
9
+ static extend(source: any): void;
10
+ }
11
+ declare const InitializerSymbol: unique symbol;
12
+ export declare class FBaseInitialable extends Disposable {
13
+ protected _injector: Injector;
14
+ private [InitializerSymbol];
15
+ constructor(_injector: Injector);
16
+ _initialize(injector: Injector): void;
25
17
  static extend(source: any): void;
26
18
  }
19
+ export {};
@@ -0,0 +1,20 @@
1
+ import { UniverInstanceType } from '../common/unit';
2
+ import { LifecycleStages } from '../services/lifecycle/lifecycle';
3
+ import { DataValidationErrorStyle } from '../types/enum/data-validation-error-style';
4
+ import { DataValidationOperator } from '../types/enum/data-validation-operator';
5
+ import { DataValidationRenderMode } from '../types/enum/data-validation-render-mode';
6
+ import { DataValidationStatus } from '../types/enum/data-validation-status';
7
+ import { DataValidationType } from '../types/enum/data-validation-type';
8
+ export declare class FEnum {
9
+ static _instance: FEnum | null;
10
+ static get(): FEnum;
11
+ static extend(source: any): void;
12
+ constructor();
13
+ get UniverInstanceType(): typeof UniverInstanceType;
14
+ get LifecycleStages(): typeof LifecycleStages;
15
+ get DataValidationType(): typeof DataValidationType;
16
+ get DataValidationErrorStyle(): typeof DataValidationErrorStyle;
17
+ get DataValidationRenderMode(): typeof DataValidationRenderMode;
18
+ get DataValidationOperator(): typeof DataValidationOperator;
19
+ get DataValidationStatus(): typeof DataValidationStatus;
20
+ }
@@ -0,0 +1,33 @@
1
+ import { UniverInstanceType } from '../common/unit';
2
+ import { LifecycleStages } from '../services/lifecycle/lifecycle';
3
+ import { IWorkbookData } from '../sheets/typedef';
4
+ import { IDocumentData } from '../types/interfaces';
5
+ export interface ISheetCreateParam {
6
+ unitId: string;
7
+ type: UniverInstanceType.UNIVER_SHEET;
8
+ data: IWorkbookData;
9
+ }
10
+ export interface IDocumentCreateParam {
11
+ unitId: string;
12
+ type: UniverInstanceType.UNIVER_DOC;
13
+ data: IDocumentData;
14
+ }
15
+ export interface ILifeCycleChangedParam {
16
+ stage: LifecycleStages;
17
+ }
18
+ export interface IEventBase {
19
+ cancel?: boolean;
20
+ }
21
+ export type IUnitCreateEvent = IEventBase & (ISheetCreateParam | IDocumentCreateParam);
22
+ export type ILifeCycleChangedEvent = IEventBase & ILifeCycleChangedParam;
23
+ export declare class FEventName {
24
+ static _instance: FEventName | null;
25
+ static get(): FEventName;
26
+ static extend(source: any): void;
27
+ constructor();
28
+ get UnitCreated(): "UnitCreated";
29
+ get LifeCycleChanged(): "LifeCycleChanged";
30
+ }
31
+ export interface IEventParamConfig {
32
+ LifeCycleChanged: ILifeCycleChangedEvent;
33
+ }
@@ -1,16 +1,21 @@
1
1
  import { IDisposable, Injector } from '../common/di';
2
2
  import { CommandListener, IExecutionOptions, ICommandService } from '../services/command/command.service';
3
3
  import { LifecycleStages } from '../services/lifecycle/lifecycle';
4
+ import { IEventParamConfig, FEventName } from './f-event';
4
5
  import { IUniverInstanceService } from '../services/instance/instance.service';
6
+ import { LifecycleService } from '../services/lifecycle/lifecycle.service';
7
+ import { ColorBuilder } from '../shared';
5
8
  import { Univer } from '../univer';
6
- import { FBase } from './f-base';
9
+ import { FBaseInitialable } from './f-base';
7
10
  import { FBlob } from './f-blob';
11
+ import { FEnum } from './f-enum';
8
12
  import { FHooks } from './f-hooks';
9
13
  import { FUserManager } from './f-usermanager';
10
- export declare class FUniver extends FBase {
14
+ export declare class FUniver extends FBaseInitialable {
11
15
  protected readonly _injector: Injector;
12
16
  protected readonly _commandService: ICommandService;
13
17
  protected readonly _univerInstanceService: IUniverInstanceService;
18
+ protected readonly _lifecycleService: LifecycleService;
14
19
  /**
15
20
  * Create an FUniver instance, if the injector is not provided, it will create a new Univer instance.
16
21
  *
@@ -20,7 +25,9 @@ export declare class FUniver extends FBase {
20
25
  * @returns {FUniver} - The FUniver instance.
21
26
  */
22
27
  static newAPI(wrapped: Univer | Injector): FUniver;
23
- constructor(_injector: Injector, _commandService: ICommandService, _univerInstanceService: IUniverInstanceService);
28
+ private _eventRegistry;
29
+ private _ensureEventRegistry;
30
+ constructor(_injector: Injector, _commandService: ICommandService, _univerInstanceService: IUniverInstanceService, _lifecycleService: LifecycleService);
24
31
  /**
25
32
  * Dispose the UniverSheet by the `unitId`. The UniverSheet would be unload from the application.
26
33
  *
@@ -48,14 +55,14 @@ export declare class FUniver extends FBase {
48
55
  redo(): Promise<boolean>;
49
56
  /**
50
57
  * Register a callback that will be triggered before invoking a command.
51
- *
58
+ * @deprecated use `addEvent(univerAPI.event.BeforeCommandExecute, () => {})` instead.
52
59
  * @param {CommandListener} callback The callback.
53
60
  * @returns {IDisposable} The disposable instance.
54
61
  */
55
62
  onBeforeCommandExecute(callback: CommandListener): IDisposable;
56
63
  /**
57
64
  * Register a callback that will be triggered when a command is invoked.
58
- *
65
+ * @deprecated use `addEvent(univerAPI.event.CommandExecuted, () => {})` instead.
59
66
  * @param {CommandListener} callback The callback.
60
67
  * @returns {IDisposable} The disposable instance.
61
68
  */
@@ -78,7 +85,7 @@ export declare class FUniver extends FBase {
78
85
  syncExecuteCommand<P extends object = object, R = boolean>(id: string, params?: P, options?: IExecutionOptions): R;
79
86
  /**
80
87
  * Get hooks.
81
- *
88
+ * @deprecated use `addEvent` instead.
82
89
  * @returns {FHooks} FHooks instance
83
90
  */
84
91
  getHooks(): FHooks;
@@ -92,5 +99,32 @@ export declare class FUniver extends FBase {
92
99
  * ```
93
100
  */
94
101
  newBlob(): FBlob;
102
+ newColor(): ColorBuilder;
103
+ get Enum(): FEnum;
104
+ get Event(): FEventName;
105
+ /**
106
+ * Add an event listener
107
+ * @param event key of event
108
+ * @param callback callback when event triggered
109
+ * @returns {Disposable} The Disposable instance, for remove the listener
110
+ * @example
111
+ * ```ts
112
+ * univerAPI.addEvent(univerAPI.event.UnitCreated, (params) => {
113
+ * console.log('unit created', params);
114
+ * });
115
+ * ```
116
+ */
117
+ addEvent(event: keyof IEventParamConfig, callback: (params: IEventParamConfig[typeof event]) => void): IDisposable;
118
+ /**
119
+ * Fire an event, used in internal only.
120
+ * @param event {string} key of event
121
+ * @param params {any} parmas of event
122
+ * @returns {boolean} should cancel
123
+ * @example
124
+ * ```ts
125
+ * this.fireEvent(univerAPI.event.UnitCreated, params);
126
+ * ```
127
+ */
128
+ protected fireEvent<T extends keyof IEventParamConfig>(event: T, params: IEventParamConfig[T]): boolean | undefined;
95
129
  getUserManager(): FUserManager;
96
130
  }
@@ -8,7 +8,9 @@ export declare class FUserManager extends FBase {
8
8
  /**
9
9
  * Get current user info
10
10
  * @example
11
- * `univerAPI.getUserManager().getCurrentUser()`
11
+ * ```
12
+ * univerAPI.getUserManager().getCurrentUser()
13
+ * ```
12
14
  */
13
15
  getCurrentUser(): IUser;
14
16
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export declare class FUtil {
17
+ static Range: {
18
+ new (): Range;
19
+ prototype: Range;
20
+ readonly START_TO_START: 0;
21
+ readonly START_TO_END: 1;
22
+ readonly END_TO_END: 2;
23
+ readonly END_TO_START: 3;
24
+ };
25
+ }
@@ -27,10 +27,12 @@ export { AsyncInterceptorManager, composeInterceptors, createAsyncInterceptorKey
27
27
  export type { Serializable } from './common/json';
28
28
  export { MemoryCursor } from './common/memory-cursor';
29
29
  export { mixinClass } from './common/mixin';
30
- export { FBase } from './facade/f-base';
30
+ export { FBase, FBaseInitialable } from './facade/f-base';
31
31
  export { FUniver } from './facade/f-univer';
32
32
  export { FHooks } from './facade/f-hooks';
33
33
  export { FBlob, type IFBlobSource } from './facade/f-blob';
34
+ export { FEventName, type IEventBase, type IEventParamConfig } from './facade/f-event';
35
+ export { FEnum } from './facade/f-enum';
34
36
  export { isNumeric, isSafeNumeric } from './common/number';
35
37
  export { Registry, RegistryAsMap } from './common/registry';
36
38
  export { requestImmediateMacroTask } from './common/request-immediate-macro-task';
@@ -55,14 +55,14 @@ export declare const UndoCommandId = "univer.command.undo";
55
55
  export declare const UndoCommand: {
56
56
  readonly type: CommandType.COMMAND;
57
57
  readonly id: "univer.command.undo";
58
- handler(accessor: IAccessor): Promise<boolean>;
58
+ handler(accessor: IAccessor): boolean;
59
59
  dispose(): void;
60
60
  dispatchToHandlers(): Promise<boolean>;
61
61
  };
62
62
  export declare const RedoCommand: {
63
63
  readonly type: CommandType.COMMAND;
64
64
  readonly id: "univer.command.redo";
65
- handler(accessor: IAccessor): Promise<boolean>;
65
+ handler(accessor: IAccessor): boolean;
66
66
  dispose(): void;
67
67
  dispatchToHandlers(): Promise<boolean>;
68
68
  };
@@ -210,6 +210,13 @@ export interface ICellMarks {
210
210
  br?: ICellMarksStyle;
211
211
  isSkip?: boolean;
212
212
  }
213
+ export interface IFontRenderExtension {
214
+ leftOffset?: number;
215
+ rightOffset?: number;
216
+ topOffset?: number;
217
+ downOffset?: number;
218
+ isSkip?: boolean;
219
+ }
213
220
  export interface ICellDataForSheetInterceptor extends ICellData {
214
221
  interceptorStyle?: Nullable<IStyleData>;
215
222
  isInArrayFormulaRange?: Nullable<boolean>;
@@ -223,22 +230,29 @@ export interface ICellDataForSheetInterceptor extends ICellData {
223
230
  coverable?: boolean;
224
231
  linkUrl?: string;
225
232
  linkId?: string;
226
- fontRenderExtension?: {
227
- leftOffset?: number;
228
- rightOffset?: number;
229
- topOffset?: number;
230
- downOffset?: number;
231
- isSkip?: boolean;
232
- };
233
+ fontRenderExtension?: IFontRenderExtension;
234
+ themeStyle?: Nullable<IStyleData>;
233
235
  }
234
236
  export declare function isICellData(value: any): value is ICellData;
235
237
  export declare function getCellValueType(cell: ICellData): CellValueType | null | undefined;
236
238
  export declare function isNullCell(cell: Nullable<ICellData>): boolean;
237
239
  export declare function isCellV(cell: Nullable<ICellData | CellValue>): cell is string | number | boolean;
238
240
  export interface IFreeze {
241
+ /**
242
+ * count of fixed cols
243
+ */
239
244
  xSplit: number;
245
+ /**
246
+ * count of fixed rows
247
+ */
240
248
  ySplit: number;
249
+ /**
250
+ * scrollable start row
251
+ */
241
252
  startRow: number;
253
+ /**
254
+ * scrollable start column
255
+ */
242
256
  startColumn: number;
243
257
  }
244
258
  export declare enum RANGE_TYPE {
@@ -1,26 +1,15 @@
1
1
  import { IDisposable } from '../common/di';
2
+ import { IInterceptor, InterceptorEffectEnum } from '../common/interceptor';
2
3
  import { Nullable } from '../shared/types';
3
4
  import { ICellData, ICellDataForSheetInterceptor } from './typedef';
4
- import { InterceptorEffectEnum } from '../common/interceptor';
5
5
  import { Disposable } from '../shared/lifecycle';
6
6
  /**
7
+ * A cell content interceptor is used to intercept the cell content. It can change or completely replace the cell content.
8
+ *
7
9
  * @internal
8
10
  */
9
11
  export interface ICellContentInterceptor {
10
- getCell: (row: number, col: number, effect: InterceptorEffectEnum) => Nullable<ICellDataForSheetInterceptor>;
11
- }
12
- export interface IRowFilteredInterceptor {
13
- }
14
- export interface IRowVisibleInterceptor {
15
- }
16
- export interface IColVisibleInterceptor {
17
- }
18
- export interface ISheetViewModel {
19
- registerCellContentInterceptor: (interceptor: ICellContentInterceptor) => IDisposable;
20
- registerRowFilteredInterceptor: (interceptor: IRowFilteredInterceptor) => IDisposable;
21
- registerRowVisibleInterceptor: (interceptor: IRowVisibleInterceptor) => IDisposable;
22
- registerColVisibleInterceptor: (interceptor: IColVisibleInterceptor) => IDisposable;
23
- getCell: (row: number, col: number) => Nullable<ICellDataForSheetInterceptor>;
12
+ getCell: (row: number, col: number, effect: InterceptorEffectEnum, key?: string, filter?: (interceptor: IInterceptor<any, any>) => boolean) => Nullable<ICellDataForSheetInterceptor>;
24
13
  }
25
14
  /**
26
15
  * @internal
@@ -28,6 +17,12 @@ export interface ISheetViewModel {
28
17
  export interface IRowFilteredInterceptor {
29
18
  getRowFiltered(row: number): boolean;
30
19
  }
20
+ export interface IRowFilteredInterceptor {
21
+ }
22
+ export interface IRowVisibleInterceptor {
23
+ }
24
+ export interface IColVisibleInterceptor {
25
+ }
31
26
  /**
32
27
  * @internal
33
28
  */
@@ -38,6 +33,7 @@ export declare class SheetViewModel extends Disposable {
38
33
  constructor(getRawCell: (row: number, col: number) => Nullable<ICellData>);
39
34
  dispose(): void;
40
35
  getCell(row: number, col: number): Nullable<ICellDataForSheetInterceptor>;
36
+ getCell(row: number, col: number, key: string, filter: (interceptor: IInterceptor<any, any>) => boolean): Nullable<ICellDataForSheetInterceptor>;
41
37
  getCellValueOnly(row: number, col: number): Nullable<ICellDataForSheetInterceptor>;
42
38
  getCellStyleOnly(row: number, col: number): Nullable<ICellDataForSheetInterceptor>;
43
39
  getRowFiltered(row: number): boolean;
@@ -1,3 +1,4 @@
1
+ import { IInterceptor } from '../common/interceptor';
1
2
  import { Nullable, ObjectMatrix } from '../shared';
2
3
  import { IPaddingData, IStyleData, ITextRotation } from '../types/interfaces';
3
4
  import { Styles } from './styles';
@@ -228,6 +229,7 @@ export declare class Worksheet {
228
229
  */
229
230
  getCellStyleOnly(row: number, col: number): Nullable<ICellDataForSheetInterceptor>;
230
231
  getCellRaw(row: number, col: number): Nullable<ICellData>;
232
+ getCellWithFilteredInterceptors(row: number, col: number, key: string, filter: (interceptor: IInterceptor<any, any>) => boolean): Nullable<ICellDataForSheetInterceptor>;
231
233
  getRowFiltered(row: number): boolean;
232
234
  /**
233
235
  * Get cell matrix from a given range and pick out non-first cells of merged cells.