@univerjs/core 0.3.0 → 0.4.0-alpha.0

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,17 +1,15 @@
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 { Dependency, DependencyIdentifier, Injector } from '@wendellhu/redi';
16
2
  export * from '@wendellhu/redi';
17
3
  export * from '@wendellhu/redi/react-bindings';
4
+ /**
5
+ * Register the dependencies to the injector.
6
+ * @param injector The injector to register the dependencies.
7
+ * @param dependencies The dependencies to register.
8
+ */
9
+ export declare function registerDependencies(injector: Injector, dependencies: Dependency[]): void;
10
+ /**
11
+ * Touch a group of dependencies to ensure they are instantiated.
12
+ * @param injector The injector to touch the dependencies.
13
+ * @param dependencies The dependencies to touch.
14
+ */
15
+ export declare function touchDependencies(injector: Injector, dependencies: [DependencyIdentifier<unknown>][]): void;
@@ -25,6 +25,7 @@ export declare class BuildTextUtils {
25
25
  static transform: {
26
26
  getPlainText: (dataStream: string) => string;
27
27
  fromPlainText: (text: string) => import('../../../..').IDocumentBody;
28
+ isEmptyDocument: (dataStream?: string) => boolean;
28
29
  };
29
30
  }
30
31
  export type { IAddCustomRangeTextXParam, IDeleteCustomRangeParam, IReplaceSelectionTextXParams } from './text-x-utils';
@@ -1,3 +1,4 @@
1
1
  import { IDocumentBody } from '../../../../types/interfaces';
2
2
  export declare const getPlainText: (dataStream: string) => string;
3
+ export declare const isEmptyDocument: (dataStream?: string) => boolean;
3
4
  export declare const fromPlainText: (text: string) => IDocumentBody;
@@ -1,15 +1,18 @@
1
1
  import { IAccessor } from '@wendellhu/redi';
2
- import { TextX } from '../text-x';
3
2
  import { Nullable } from '../../../../shared';
4
3
  import { ITextRange, ITextRangeParam } from '../../../../sheets/typedef';
5
4
  import { CustomRangeType, IDocumentBody } from '../../../../types/interfaces';
6
5
  import { DocumentDataModel } from '../../document-data-model';
7
6
  import { IDeleteAction, IRetainAction } from '../action-types';
7
+ import { TextX } from '../text-x';
8
8
  export interface IDeleteCustomRangeParam {
9
9
  rangeId: string;
10
10
  segmentId?: string;
11
11
  documentDataModel: DocumentDataModel;
12
12
  insert?: Nullable<IDocumentBody>;
13
+ textRange?: {
14
+ index: number;
15
+ };
13
16
  }
14
17
  export declare function deleteCustomRangeTextX(accessor: IAccessor, params: IDeleteCustomRangeParam): false | TextX;
15
18
  export interface IAddCustomRangeTextXParam {
@@ -1,6 +1,6 @@
1
- import { UpdateDocsAttributeType } from '../../../shared/command-enum';
2
1
  import { ICustomDecoration, IDocumentBody } from '../../../types/interfaces/i-document-data';
3
2
  import { IRetainAction } from './action-types';
3
+ import { UpdateDocsAttributeType } from '../../../shared/command-enum';
4
4
  export declare enum SliceBodyType {
5
5
  copy = 0,
6
6
  cut = 1
@@ -57,9 +57,8 @@ export { ContextService, IContextService } from './services/context/context.serv
57
57
  export { ErrorService, type IError } from './services/error/error.service';
58
58
  export { IUniverInstanceService } from './services/instance/instance.service';
59
59
  export { UniverInstanceService } from './services/instance/instance.service';
60
- export { LifecycleStages, OnLifecycle, runOnLifecycle } from './services/lifecycle/lifecycle';
60
+ export { LifecycleStages } from './services/lifecycle/lifecycle';
61
61
  export { LifecycleService } from './services/lifecycle/lifecycle.service';
62
- export { LifecycleInitializerService } from './services/lifecycle/lifecycle.service';
63
62
  export { ILocalStorageService } from './services/local-storage/local-storage.service';
64
63
  export { LocaleService } from './services/locale/locale.service';
65
64
  export { DesktopLogService, ILogService, LogLevel } from './services/log/log.service';
@@ -83,6 +82,7 @@ export { type IUser, UserManagerService } from './services/user-manager/user-man
83
82
  export * from './shared';
84
83
  export { isBlackColor, isWhiteColor } from './shared/color/color-kit';
85
84
  export { cellToRange } from './shared/common';
85
+ export { getIntersectRange } from './shared/range';
86
86
  export { nameCharacterCheck } from './shared/name';
87
87
  export { fromCallback, takeAfter } from './shared/rxjs';
88
88
  export { awaitTime } from './shared/timer';
@@ -110,4 +110,5 @@ export * from './types/interfaces';
110
110
  export * from './types/interfaces';
111
111
  export type { ICellCustomRender, ICellRenderContext } from './types/interfaces/i-cell-custom-render';
112
112
  export type { IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleInfo, IDataValidationRuleOptions, ISheetDataValidationRule } from './types/interfaces/i-data-validation';
113
+ export { type IRTreeItem, RTree } from './shared/r-tree';
113
114
  export { Univer } from './univer';
@@ -1,4 +1,18 @@
1
- import { Ctor, DependencyIdentifier } from '../../common/di';
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
+ */
2
16
  /**
3
17
  * This enum defines multiple lifecycle stages in Univer SDK.
4
18
  */
@@ -27,44 +41,3 @@ export declare const LifecycleNameMap: {
27
41
  2: string;
28
42
  3: string;
29
43
  };
30
- export declare const LifecycleToModules: Map<LifecycleStages, DependencyIdentifier<unknown>[]>;
31
- /**
32
- * Register the decorated class to be automatically instantiated when Univer progresses to the certain lifecycle stage.
33
- *
34
- * @param lifecycleStage The lifecycle stage to instantiate this class.
35
- * @param identifier The dependency identifier of the class. Usually, it is the class itself unless you bind this class
36
- * with another injection identifier.
37
- *
38
- * @deprecated This API does not work as expected and will be removed in future versions. Please call
39
- * `this._injector.get(YourDependency)` in plugins' lifecycle hooks instead.
40
- *
41
- * @example
42
- * // Ignore the `\` below. This is JSDoc's bug.
43
- * \@OnLifecycle(LifecycleStages.Ready, MyService)
44
- * class MyService {
45
- * }
46
- *
47
- * @example
48
- * // Ignore the `\` below. This is JSDoc's bug.
49
- * \@OnLifecycle(LifecycleStages.Rendered, IMyService)
50
- * class MyService implements IMyService {
51
- * }
52
- */
53
- export declare function OnLifecycle(lifecycleStage: LifecycleStages, identifier: DependencyIdentifier<unknown>): (_: Ctor<unknown>) => void;
54
- /**
55
- * Register a dependency to be automatically instantiated when Univer progresses to the certain lifecycle stage.
56
- *
57
- * @param lifecycleStage The lifecycle stage to instantiate this dependency.
58
- * @param identifier The dependencies' identifier. **Beware** that if the dependency (e.g. a class) is bound to an
59
- * identifier, you should register the identifier instead of the dependency itself.
60
- *
61
- * @deprecated This API does not work as expected and will be removed in future versions. Please call
62
- * `this._injector.get(YourDependency)` in plugins' lifecycle hooks instead.
63
- *
64
- * @example
65
- * runOnLifecycle(LifecycleStages.Ready, MyService);
66
- *
67
- * @example
68
- * runOnLifecycle(LifecycleStages.Rendered, IMyService);
69
- */
70
- export declare function runOnLifecycle(lifecycleStage: LifecycleStages, identifier: DependencyIdentifier<unknown>): void;
@@ -1,5 +1,4 @@
1
1
  import { Observable } from 'rxjs';
2
- import { Injector } from '../../common/di';
3
2
  import { Disposable } from '../../shared/lifecycle';
4
3
  import { ILogService } from '../log/log.service';
5
4
  import { LifecycleStages } from './lifecycle';
@@ -25,16 +24,4 @@ export declare class LifecycleService extends Disposable {
25
24
  subscribeWithPrevious(): Observable<LifecycleStages>;
26
25
  private _reportProgress;
27
26
  }
28
- /**
29
- * This service is used to initialize modules on a certain lifecycle stage.
30
- * Refer to `runOnLifecycle` and `OnLifecycle` for more details.
31
- *
32
- * @internal
33
- */
34
- export declare class LifecycleInitializerService extends Disposable {
35
- private readonly _injector;
36
- private _seenTokens;
37
- constructor(_injector: Injector);
38
- initModulesOnStage(stage: LifecycleStages): void;
39
- }
40
27
  export declare function getLifecycleStagesAndBefore(lifecycleStage: LifecycleStages): Observable<LifecycleStages>;
@@ -1,6 +1,6 @@
1
1
  import { Observable, BehaviorSubject } from 'rxjs';
2
- import { Disposable } from '../../shared';
3
2
  import { IPermissionPoint, IPermissionService } from './type';
3
+ import { Disposable } from '../../shared';
4
4
  export declare class PermissionService extends Disposable implements IPermissionService {
5
5
  private _permissionPointMap;
6
6
  private _permissionPointUpdate$;
@@ -1,7 +1,7 @@
1
- import { BehaviorSubject, Observable } from 'rxjs';
2
1
  import { UnitAction, UnitObject } from '@univerjs/protocol';
3
- import { IRange } from '../../sheets/typedef';
2
+ import { BehaviorSubject, Observable } from 'rxjs';
4
3
  import { Nullable } from '../../shared/types';
4
+ import { IRange } from '../../sheets/typedef';
5
5
  export declare enum PermissionStatus {
6
6
  INIT = "init",
7
7
  FETCHING = "fetching",
@@ -1,6 +1,6 @@
1
1
  import { Ctor, Injector } from '../../common/di';
2
- import { Disposable } from '../../shared';
3
2
  import { UniverInstanceType } from '../../common/unit';
3
+ import { Disposable } from '../../shared';
4
4
  export declare const DependentOnSymbol: unique symbol;
5
5
  export type PluginCtor<T extends Plugin = Plugin> = Ctor<T> & {
6
6
  type: UniverInstanceType;
@@ -14,7 +14,7 @@ export declare abstract class Plugin extends Disposable {
14
14
  static pluginName: string;
15
15
  static type: UniverInstanceType;
16
16
  protected abstract _injector: Injector;
17
- onStarting(_injector?: Injector): void;
17
+ onStarting(): void;
18
18
  onReady(): void;
19
19
  onRendered(): void;
20
20
  onSteady(): void;
@@ -1,9 +1,9 @@
1
1
  import { IDisposable, Injector } from '../../common/di';
2
- import { Disposable } from '../../shared/lifecycle';
2
+ import { Plugin, PluginCtor, PluginRegistry, PluginStore } from './plugin';
3
3
  import { UniverInstanceType } from '../../common/unit';
4
- import { LifecycleInitializerService, LifecycleService } from '../lifecycle/lifecycle.service';
4
+ import { Disposable } from '../../shared/lifecycle';
5
+ import { LifecycleService } from '../lifecycle/lifecycle.service';
5
6
  import { ILogService } from '../log/log.service';
6
- import { Plugin, PluginCtor, PluginRegistry, PluginStore } from './plugin';
7
7
  /**
8
8
  * Use this decorator to declare dependencies among plugins. If a dependent plugin is not registered yet,
9
9
  * Univer will automatically register it with no configuration.
@@ -45,7 +45,6 @@ export declare class PluginHolder extends Disposable {
45
45
  protected readonly _logService: ILogService;
46
46
  protected readonly _injector: Injector;
47
47
  protected readonly _lifecycleService: LifecycleService;
48
- protected readonly _lifecycleInitializerService: LifecycleInitializerService;
49
48
  protected _started: boolean;
50
49
  get started(): boolean;
51
50
  private _warnedAboutOnStartingDeprecation;
@@ -53,8 +52,9 @@ export declare class PluginHolder extends Disposable {
53
52
  protected readonly _pluginRegistry: PluginRegistry;
54
53
  /** Stores initialized plugin instances. */
55
54
  protected readonly _pluginStore: PluginStore;
56
- private readonly _awaitingPlugins;
57
- constructor(_checkPluginRegistered: (pluginCtor: PluginCtor) => boolean, _registerPlugin: <T extends PluginCtor>(plugin: T, config?: ConstructorParameters<T>[0]) => void, _logService: ILogService, _injector: Injector, _lifecycleService: LifecycleService, _lifecycleInitializerService: LifecycleInitializerService);
55
+ /** Plugins instances as they are registered in batches. */
56
+ private readonly _pluginsInBatches;
57
+ constructor(_checkPluginRegistered: (pluginCtor: PluginCtor) => boolean, _registerPlugin: <T extends PluginCtor>(plugin: T, config?: ConstructorParameters<T>[0]) => void, _logService: ILogService, _injector: Injector, _lifecycleService: LifecycleService);
58
58
  dispose(): void;
59
59
  register<T extends PluginCtor<Plugin>>(pluginCtor: T, config?: ConstructorParameters<T>[0]): void;
60
60
  immediateInitPlugin<T extends Plugin>(plugin: PluginCtor<T>): void;
@@ -1,7 +1,7 @@
1
1
  import { IResources } from '../resource-manager/type';
2
+ export declare const IResourceLoaderService: import('@wendellhu/redi').IdentifierDecorator<IResourceLoaderService>;
2
3
  export interface IResourceLoaderService {
3
4
  saveUnit<T = object>(unitId: string): T & {
4
5
  resources: IResources;
5
6
  } | null;
6
7
  }
7
- export declare const IResourceLoaderService: import('@wendellhu/redi').IdentifierDecorator<IResourceLoaderService>;
@@ -1,5 +1,5 @@
1
- import { Observable } from 'rxjs';
2
1
  import { UniverInstanceType } from '@univerjs/core';
2
+ import { Observable } from 'rxjs';
3
3
  import { IDisposable } from '../../common/di';
4
4
  export type IResources = Array<{
5
5
  id?: string;
@@ -0,0 +1,29 @@
1
+ import { BBox, default as RBush } from 'rbush';
2
+ import { IUnitRange } from '../sheets/typedef';
3
+ export interface IRTreeItem extends IUnitRange {
4
+ id: string;
5
+ }
6
+ interface IRBushItem extends BBox {
7
+ id: string;
8
+ }
9
+ export interface IRTreeData {
10
+ [unitId: string]: {
11
+ [subUnitId: string]: IRTreeItem[];
12
+ };
13
+ }
14
+ export declare class RTree {
15
+ private _tree;
16
+ dispose(): void;
17
+ getTree(unitId: string, subUnitId: string): RBush<IRBushItem>;
18
+ insert(item: IRTreeItem): void;
19
+ bulkInsert(items: IRTreeItem[]): void;
20
+ search(search: IUnitRange): Map<string, IRTreeItem>;
21
+ bulkSearch(searchList: IUnitRange[]): Map<string, IRTreeItem>;
22
+ removeById(unitId: string, subUnitId?: string): void;
23
+ remove(search: IRTreeItem): void;
24
+ bulkRemove(searchList: IRTreeItem[]): void;
25
+ clear(): void;
26
+ toJSON(): IRTreeData;
27
+ fromJSON(data: IRTreeData): void;
28
+ }
29
+ export {};
@@ -1,4 +1,5 @@
1
1
  import { IRange } from '../sheets/typedef';
2
+ import { Nullable } from './types';
2
3
  export declare function moveRangeByOffset(range: IRange, refOffsetX: number, refOffsetY: number, ignoreAbsolute?: boolean): IRange;
3
4
  /**
4
5
  * Split ranges into aligned smaller ranges
@@ -25,3 +26,13 @@ export declare function mergeVerticalRanges(ranges: IRange[]): IRange[];
25
26
  */
26
27
  export declare function mergeRanges(ranges: IRange[]): IRange[];
27
28
  export declare function multiSubtractSingleRange(ranges: IRange[], toDelete: IRange): IRange[];
29
+ /**
30
+ * Computes the intersection of two ranges.
31
+ * If there is an overlap between the two ranges, returns a new range representing the intersection.
32
+ * If there is no overlap, returns null.
33
+ *
34
+ * @param src - The source range.
35
+ * @param target - The target range.
36
+ * @returns The intersected range or null if there is no intersection.
37
+ */
38
+ export declare function getIntersectRange(src: IRange, target: IRange): Nullable<IRange>;
@@ -1,5 +1,5 @@
1
- import { IRange, IRectLTRB } from '../sheets/typedef';
2
1
  import { Nullable } from './types';
2
+ import { IRange, IRectLTRB } from '../sheets/typedef';
3
3
  /**
4
4
  * This class provides a set of methods to calculate `IRange`.
5
5
  */
@@ -15,6 +15,10 @@ export declare class Rectangle {
15
15
  */
16
16
  static simpleRangesIntersect(rangeA: IRange, rangeB: IRange): boolean;
17
17
  static intersects(src: IRange, target: IRange): boolean;
18
+ /**
19
+ *
20
+ * @deprecated use `getIntersectRange` instead. This method does not handle NaN and does not return the correct rangeType
21
+ */
18
22
  static getIntersects(src: IRange, target: IRange): Nullable<IRange>;
19
23
  static contains(src: IRange, target: IRange): boolean;
20
24
  static realContain(src: IRange, target: IRange): boolean;
@@ -1,5 +1,5 @@
1
- import { ObjectMatrix, IObjectMatrixPrimitiveType, Nullable } from '../shared';
2
- import { BooleanNumber, FontItalic, FontWeight, WrapStrategy, HorizontalAlign, VerticalAlign } from '../types/enum';
1
+ import { IObjectMatrixPrimitiveType, Nullable, ObjectMatrix } from '../shared';
2
+ import { HorizontalAlign, VerticalAlign, BooleanNumber, FontItalic, FontWeight, WrapStrategy } from '../types/enum';
3
3
  import { IBorderData, IDocumentBody, IDocumentData, IStyleBase, IStyleData, ITextDecoration, ITextRotation } from '../types/interfaces';
4
4
  import { Styles } from './styles';
5
5
  import { ICellData, IRange } from './typedef';
@@ -1,5 +1,5 @@
1
- import { Disposable } from '../shared/lifecycle';
2
1
  import { IRange } from './typedef';
2
+ import { Disposable } from '../shared/lifecycle';
3
3
  export declare class SpanModel extends Disposable {
4
4
  /**
5
5
  * @property Cache for RANGE_TYPE.NORMAL
@@ -51,6 +51,13 @@ export declare class SpanModel extends Disposable {
51
51
  add(range: IRange): void;
52
52
  remove(row: number, column: number): void;
53
53
  getMergedCell(row: number, column: number): IRange | null;
54
+ /**
55
+ * Return index of merge data if (row,col) is in merge range. -1 means not in merge range.
56
+ * @param row
57
+ * @param column
58
+ * @returns {number} index of merge range.
59
+ */
60
+ getMergeDataIndex(row: number, column: number): number;
54
61
  isRowContainsMergedCell(row: number): boolean;
55
62
  isColumnContainsMergedCell(column: number): boolean;
56
63
  getMergedCellRange(startRow: number, startColumn: number, endRow: number, endColumn: number): IRange[];
@@ -1,10 +1,10 @@
1
1
  import { Observable } from 'rxjs';
2
+ import { Nullable } from '../shared';
3
+ import { IRangeType, IWorkbookData, IWorksheetData } from './typedef';
2
4
  import { UnitModel, UniverInstanceType } from '../common/unit';
3
5
  import { ILogService } from '../services/log/log.service';
4
6
  import { Styles } from './styles';
5
7
  import { Worksheet } from './worksheet';
6
- import { Nullable } from '../shared';
7
- import { IRangeType, IWorkbookData, IWorksheetData } from './typedef';
8
8
  export declare function getWorksheetUID(workbook: Workbook, worksheet: Worksheet): string;
9
9
  /**
10
10
  * Access and create Univer Sheets files
@@ -1,12 +1,12 @@
1
- import { ObjectMatrix, Nullable } from '../shared';
1
+ import { Nullable, ObjectMatrix } from '../shared';
2
+ import { Styles } from './styles';
3
+ import { ICellData, ICellDataForSheetInterceptor, IFreeze, IRange, ISelectionCell, IWorksheetData } from './typedef';
2
4
  import { BooleanNumber } from '../types/enum';
3
5
  import { ColumnManager } from './column-manager';
4
6
  import { Range } from './range';
5
7
  import { RowManager } from './row-manager';
6
8
  import { SpanModel } from './span-model';
7
9
  import { SheetViewModel } from './view-model';
8
- import { Styles } from './styles';
9
- import { ICellData, ICellDataForSheetInterceptor, IFreeze, IRange, ISelectionCell, IWorksheetData } from './typedef';
10
10
  /**
11
11
  * The model of a Worksheet.
12
12
  */
@@ -91,7 +91,7 @@ export declare class Worksheet {
91
91
  */
92
92
  getMergedCell(row: number, col: number): Nullable<IRange>;
93
93
  /**
94
- * Get the merged cell info list which has intersection with the given range.
94
+ * Get the merged cell info list which has intersection with the given range.
95
95
  * @param {number} startRow The start row index of the range
96
96
  * @param {number} startColumn The start column index of the range
97
97
  * @param {number} endRow The end row index of the range
@@ -21,5 +21,6 @@ export declare enum LocaleType {
21
21
  ZH_CN = "zhCN",
22
22
  RU_RU = "ruRU",
23
23
  ZH_TW = "zhTW",
24
- VI_VN = "viVN"
24
+ VI_VN = "viVN",
25
+ FA_IR = "faIR"
25
26
  }
@@ -1,7 +1,3 @@
1
- import { Injector } from './common/di';
2
- import { DocumentDataModel } from './docs/data-model/document-data-model';
3
- import { Workbook } from './sheets/workbook';
4
- import { SlideDataModel } from './slides/slide-model';
5
1
  import { UnitModel, UnitType } from './common/unit';
6
2
  import { LogLevel } from './services/log/log.service';
7
3
  import { Plugin, PluginCtor } from './services/plugin/plugin';
@@ -11,6 +7,10 @@ import { ILocales } from './shared';
11
7
  import { IWorkbookData } from './sheets/typedef';
12
8
  import { LocaleType } from './types/enum/locale-type';
13
9
  import { IDocumentData, ISlideData } from './types/interfaces';
10
+ import { Injector } from './common/di';
11
+ import { DocumentDataModel } from './docs/data-model/document-data-model';
12
+ import { Workbook } from './sheets/workbook';
13
+ import { SlideDataModel } from './slides/slide-model';
14
14
  export interface IUniverConfig {
15
15
  theme: IStyleSheet;
16
16
  locale: LocaleType;