@univerjs/core 0.1.2 → 0.1.4

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 (43) hide show
  1. package/lib/cjs/index.js +8 -5
  2. package/lib/es/index.js +2273 -1732
  3. package/lib/types/basics/univer-slide.d.ts +2 -2
  4. package/lib/types/basics/univer.d.ts +3 -3
  5. package/lib/types/common/__tests__/array.spec.d.ts +16 -0
  6. package/lib/types/common/array.d.ts +8 -0
  7. package/lib/types/common/interceptor.d.ts +1 -1
  8. package/lib/types/docs/data-model/empty-snapshot.d.ts +18 -0
  9. package/lib/types/index.d.ts +11 -2
  10. package/lib/types/services/command/command.service.d.ts +4 -4
  11. package/lib/types/services/context/context.d.ts +2 -1
  12. package/lib/types/services/instance/instance.service.d.ts +21 -21
  13. package/lib/types/services/locale/locale.service.d.ts +4 -2
  14. package/lib/types/services/log/context.d.ts +18 -0
  15. package/lib/types/services/snapshot/__tests__/snapshot-mock.d.ts +37 -0
  16. package/lib/types/services/snapshot/__tests__/snapshot-transform.spec.d.ts +16 -0
  17. package/lib/types/services/snapshot/snapshot-server.service.d.ts +57 -0
  18. package/lib/types/services/snapshot/snapshot-transform.d.ts +43 -0
  19. package/lib/types/services/snapshot/snapshot-utils.d.ts +34 -0
  20. package/lib/types/services/undoredo/undoredo.service.d.ts +20 -7
  21. package/lib/types/shared/__test__/rectangle.spec.d.ts +16 -0
  22. package/lib/types/shared/coder.d.ts +17 -0
  23. package/lib/types/shared/color/color-kit.d.ts +3 -1
  24. package/lib/types/shared/compare.d.ts +1 -0
  25. package/lib/types/shared/index.d.ts +1 -1
  26. package/lib/types/shared/locale.d.ts +2 -1
  27. package/lib/types/shared/object-matrix.d.ts +3 -0
  28. package/lib/types/shared/rxjs.d.ts +20 -0
  29. package/lib/types/shared/tools.d.ts +1 -1
  30. package/lib/types/sheets/__tests__/create-core-test-bed.d.ts +1 -2
  31. package/lib/types/sheets/row-manager.d.ts +0 -2
  32. package/lib/types/sheets/workbook.d.ts +1 -0
  33. package/lib/types/sheets/worksheet.d.ts +7 -9
  34. package/lib/types/slides/domain/slide-model.d.ts +3 -1
  35. package/lib/types/types/interfaces/i-cell-data.d.ts +6 -0
  36. package/lib/types/types/interfaces/i-column-data.d.ts +2 -2
  37. package/lib/types/types/interfaces/i-document-data.d.ts +3 -1
  38. package/lib/types/types/interfaces/i-range.d.ts +5 -0
  39. package/lib/types/types/interfaces/i-row-data.d.ts +2 -2
  40. package/lib/types/types/interfaces/i-selection-data.d.ts +6 -0
  41. package/lib/types/types/interfaces/i-slide-data.d.ts +2 -1
  42. package/lib/umd/index.js +8 -5
  43. package/package.json +12 -8
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { Injector } from '@wendellhu/redi';
17
17
  import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';
18
- import { Slide } from '../slides/domain/slide-model';
18
+ import { SlideDataModel } from '../slides/domain/slide-model';
19
19
  import type { ISlideData } from '../types/interfaces/i-slide-data';
20
20
  import { PluginHolder } from './plugin-holder';
21
21
  /**
@@ -26,5 +26,5 @@ export declare class UniverSlide extends PluginHolder {
26
26
  protected readonly _lifecycleService: LifecycleService;
27
27
  protected readonly _lifecycleInitializerService: LifecycleInitializerService;
28
28
  constructor(_injector: Injector, _lifecycleService: LifecycleService, _lifecycleInitializerService: LifecycleInitializerService);
29
- createSlide(data: Partial<ISlideData>): Slide;
29
+ createSlide(data: Partial<ISlideData>): SlideDataModel;
30
30
  }
@@ -18,7 +18,7 @@ import type { DocumentDataModel } from '../docs/data-model/document-data-model';
18
18
  import type { Plugin, PluginCtor } from '../plugin/plugin';
19
19
  import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';
20
20
  import type { Workbook } from '../sheets/workbook';
21
- import type { Slide } from '../slides/domain/slide-model';
21
+ import type { SlideDataModel } from '../slides/domain/slide-model';
22
22
  import type { LocaleType } from '../types/enum/locale-type';
23
23
  import type { IDocumentData, ISlideData, IUniverData, IWorkbookData } from '../types/interfaces';
24
24
  import { PluginHolder } from './plugin-holder';
@@ -41,7 +41,7 @@ export declare class Univer extends PluginHolder {
41
41
  */
42
42
  createUniverSheet(config: Partial<IWorkbookData>): Workbook;
43
43
  createUniverDoc(config: Partial<IDocumentData>): DocumentDataModel;
44
- createUniverSlide(config: Partial<ISlideData>): Slide;
44
+ createUniverSlide(config: Partial<ISlideData>): SlideDataModel;
45
45
  private _initDependencies;
46
46
  /**
47
47
  * Initialize modules provided by Univer-type plugins.
@@ -49,7 +49,7 @@ export declare class Univer extends PluginHolder {
49
49
  private _tryProgressToStart;
50
50
  private _tryProgressToReady;
51
51
  /** Register a plugin into univer. */
52
- registerPlugin<T extends Plugin>(plugin: PluginCtor<T>, config?: any): void;
52
+ registerPlugin<T extends PluginCtor<Plugin>>(plugin: T, config?: ConstructorParameters<T>[0]): void;
53
53
  private _initLazyPluginsTimer?;
54
54
  private _scheduleInitPluginAfterStarted;
55
55
  private _flushLazyPlugins;
@@ -0,0 +1,16 @@
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 {};
@@ -21,3 +21,11 @@ export declare function remove<T>(arr: T[], item: T): boolean;
21
21
  */
22
22
  export declare function dedupe<T>(arr: T[]): T[];
23
23
  export declare function findLast<T>(arr: T[], callback: (item: T, index: number) => boolean): T | null;
24
+ /**
25
+ * Rotate an array without mutating the original array.
26
+ * @param arr the array to be rotated
27
+ * @param steps how many steps to rotate
28
+ * @returns the rotated array, it is another array, the original array is not mutated.
29
+ */
30
+ export declare function rotate<T>(arr: Readonly<T[]>, steps: number): readonly T[];
31
+ export declare function groupBy<T>(arr: Readonly<T[]>, keyFn: (v: T) => string): Map<string, T[]>;
@@ -24,7 +24,7 @@ export type IComposeInterceptors<T = any, C = any> = (interceptors: Array<IInter
24
24
  /**
25
25
  * A helper to compose a certain type of interceptors.
26
26
  */
27
- export declare const composeInterceptors: <T, C>(interceptors: IInterceptor<T, C>[]) => (initValue: Nullable<T>, initContext: C) => Nullable<T>;
27
+ export declare const composeInterceptors: <T, C>(interceptors: Array<IInterceptor<T, C>>) => (initValue: Nullable<T>, initContext: C) => Nullable<T>;
28
28
  export declare class InterceptorManager<P extends Record<string, IInterceptor<any, any>>> {
29
29
  private _interceptorsByName;
30
30
  private _interceptorPoints;
@@ -0,0 +1,18 @@
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
+ import { LocaleType } from '../../types/enum/locale-type';
17
+ import type { IDocumentData } from '../../types/interfaces';
18
+ export declare function getEmptySnapshot(unitID?: string, locale?: LocaleType, title?: string): IDocumentData;
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export * from './basics';
17
- export { dedupe, remove } from './common/array';
17
+ export { dedupe, remove, rotate, groupBy } from './common/array';
18
18
  export { DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, } from './common/const';
19
19
  export { throttle } from './common/function';
20
20
  export { MemoryCursor } from './common/memory-cursor';
@@ -48,6 +48,7 @@ export { IResourceManagerService, ISnapshotPersistenceService } from './services
48
48
  export { type IStyleSheet, ThemeService } from './services/theme/theme.service';
49
49
  export { type IUndoRedoCommandInfos, type IUndoRedoItem, IUndoRedoService, type IUndoRedoStatus, LocalUndoRedoService, RedoCommand, UndoCommand, RedoCommandId, UndoCommandId, } from './services/undoredo/undoredo.service';
50
50
  export * from './shared';
51
+ export { fromCallback } from './shared/rxjs';
51
52
  export type { IComposeInterceptors, IInterceptor, InterceptorHandler } from './common/interceptor';
52
53
  export { composeInterceptors, createInterceptorKey, InterceptorManager } from './common/interceptor';
53
54
  export { normalizeTextRuns } from './docs/data-model/apply-utils/common';
@@ -57,7 +58,7 @@ export { Styles } from './sheets/styles';
57
58
  export { DEFAULT_WORKSHEET_COLUMN_COUNT, DEFAULT_WORKSHEET_COLUMN_COUNT_KEY, DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT_KEY, DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY, DEFAULT_WORKSHEET_ROW_COUNT_KEY, DEFAULT_WORKSHEET_ROW_HEIGHT_KEY, DEFAULT_WORKSHEET_ROW_TITLE_WIDTH_KEY, DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT, DEFAULT_WORKSHEET_COLUMN_WIDTH, DEFAULT_WORKSHEET_ROW_COUNT, DEFAULT_WORKSHEET_ROW_HEIGHT, DEFAULT_WORKSHEET_ROW_TITLE_WIDTH, mergeWorksheetSnapshotWithDefault, } from './sheets/sheet-snapshot-utils';
58
59
  export { SheetViewModel } from './sheets/view-model';
59
60
  export { getWorksheetUID, Workbook } from './sheets/workbook';
60
- export { Worksheet } from './sheets/worksheet';
61
+ export { Worksheet, extractPureTextFromCell } from './sheets/worksheet';
61
62
  export * from './slides/domain';
62
63
  export * from './types/const';
63
64
  export * from './types/enum';
@@ -65,3 +66,11 @@ export * from './types/interfaces';
65
66
  export { UniverInstanceService } from './services/instance/instance.service';
66
67
  export { LifecycleInitializerService } from './services/lifecycle/lifecycle.service';
67
68
  export { ConfigService } from './services/config/config.service';
69
+ export { ISnapshotServerService } from './services/snapshot/snapshot-server.service';
70
+ export { transformSnapshotToWorkbookData, transformWorkbookDataToSnapshot, transformDocumentDataToSnapshot, transformSnapshotToDocumentData, generateTemporarySnap, } from './services/snapshot/snapshot-transform';
71
+ export { textEncoder, textDecoder } from './services/snapshot/snapshot-utils';
72
+ export { type ILogContext } from './services/log/context';
73
+ export { b64DecodeUnicode, b64EncodeUnicode } from './shared/coder';
74
+ export { ClientSnapshotServerService } from './services/snapshot/snapshot-server.service';
75
+ export { getSheetBlocksFromSnapshot } from './services/snapshot/snapshot-transform';
76
+ export { isBlackColor, isWhiteColor } from './shared/color/color-kit';
@@ -17,7 +17,7 @@ import type { IAccessor, IDisposable } from '@wendellhu/redi';
17
17
  import { Injector } from '@wendellhu/redi';
18
18
  import { IContextService } from '../context/context.service';
19
19
  import { ILogService } from '../log/log.service';
20
- export declare const enum CommandType {
20
+ export declare enum CommandType {
21
21
  /** Command could generate some operations or mutations. */
22
22
  COMMAND = 0,
23
23
  /** An operation that do not require conflict resolve. */
@@ -31,7 +31,7 @@ export interface ICommand<P extends object = object, R = boolean> {
31
31
  */
32
32
  readonly id: string;
33
33
  readonly type: CommandType;
34
- handler(accessor: IAccessor, params?: P): Promise<R> | R;
34
+ handler(accessor: IAccessor, params?: P, options?: IExecutionOptions): Promise<R> | R;
35
35
  /**
36
36
  * When this command is unregistered, this function would be called.
37
37
  *
@@ -103,8 +103,8 @@ export interface IExecutionOptions {
103
103
  }
104
104
  export type CommandListener = (commandInfo: Readonly<ICommandInfo>, options?: IExecutionOptions) => void;
105
105
  export interface ICommandService {
106
- registerCommand(command: ICommand): IDisposable;
107
- registerMultipleCommand(command: ICommand): IDisposable;
106
+ registerCommand(command: ICommand<object, unknown>): IDisposable;
107
+ registerMultipleCommand(command: ICommand<object, unknown>): IDisposable;
108
108
  executeCommand<P extends object = object, R = boolean>(id: string, params?: P, options?: IExecutionOptions): Promise<R>;
109
109
  syncExecuteCommand<P extends object = object, R = boolean>(id: string, params?: P, options?: IExecutionOptions): R;
110
110
  /**
@@ -22,4 +22,5 @@ export declare const EDITOR_ACTIVATED = "EDITOR_ACTIVATED";
22
22
  export declare const FOCUSING_EDITOR_INPUT_FORMULA = "FOCUSING_EDITOR_INPUT_FORMULA";
23
23
  export declare const FOCUSING_FORMULA_EDITOR = "FOCUSING_FORMULA_EDITOR";
24
24
  export declare const FOCUSING_UNIVER_EDITOR = "FOCUSING_UNIVER_EDITOR";
25
- export declare const FOCUSING_UNIVER_EDITOR_SINGLE_MODE = "FOCUSING_UNIVER_EDITOR_SINGLE_MODE";
25
+ export declare const FOCUSING_EDITOR_STANDALONE = "FOCUSING_EDITOR_INPUT_FORMULA";
26
+ export declare const FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE = "FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE";
@@ -18,10 +18,10 @@ import { DocumentDataModel } from '../../docs/data-model/document-data-model';
18
18
  import type { Nullable } from '../../shared';
19
19
  import { Disposable } from '../../shared/lifecycle';
20
20
  import { Workbook } from '../../sheets/workbook';
21
- import { Slide } from '../../slides/domain/slide-model';
21
+ import { SlideDataModel } from '../../slides/domain/slide-model';
22
22
  import type { IDocumentData, ISlideData, IWorkbookData } from '../../types/interfaces';
23
23
  import { IContextService } from '../context/context.service';
24
- export declare const enum UniverInstanceType {
24
+ export declare enum UniverInstanceType {
25
25
  UNKNOWN = 0,
26
26
  DOC = 1,
27
27
  SHEET = 2,
@@ -30,7 +30,7 @@ export declare const enum UniverInstanceType {
30
30
  export interface IUniverHandler {
31
31
  createUniverDoc(data: Partial<IDocumentData>): DocumentDataModel;
32
32
  createUniverSheet(data: Partial<IWorkbookData>): Workbook;
33
- createUniverSlide(data: Partial<ISlideData>): Slide;
33
+ createUniverSlide(data: Partial<ISlideData>): SlideDataModel;
34
34
  }
35
35
  /**
36
36
  * IUniverInstanceService holds all the current univer instances. And it also manages
@@ -40,34 +40,34 @@ export interface IUniverInstanceService {
40
40
  focused$: Observable<Nullable<string>>;
41
41
  currentSheet$: Observable<Nullable<Workbook>>;
42
42
  currentDoc$: Observable<Nullable<DocumentDataModel>>;
43
- currentSlide$: Observable<Nullable<Slide>>;
43
+ currentSlide$: Observable<Nullable<SlideDataModel>>;
44
44
  sheetAdded$: Observable<Workbook>;
45
45
  docAdded$: Observable<DocumentDataModel>;
46
- slideAdded$: Observable<Slide>;
46
+ slideAdded$: Observable<SlideDataModel>;
47
47
  sheetDisposed$: Observable<Workbook>;
48
48
  docDisposed$: Observable<DocumentDataModel>;
49
- slideDisposed$: Observable<Slide>;
49
+ slideDisposed$: Observable<SlideDataModel>;
50
50
  focusUniverInstance(id: string | null): void;
51
- getFocusedUniverInstance(): Workbook | DocumentDataModel | Slide | null;
51
+ getFocusedUniverInstance(): Nullable<Workbook | DocumentDataModel | SlideDataModel>;
52
52
  createDoc(data: Partial<IDocumentData>): DocumentDataModel;
53
53
  createSheet(data: Partial<IWorkbookData>): Workbook;
54
- createSlide(data: Partial<ISlideData>): Slide;
54
+ createSlide(data: Partial<ISlideData>): SlideDataModel;
55
55
  changeDoc(unitId: string, doc: DocumentDataModel): void;
56
56
  addDoc(doc: DocumentDataModel): void;
57
57
  addSheet(sheet: Workbook): void;
58
- addSlide(slide: Slide): void;
58
+ addSlide(slide: SlideDataModel): void;
59
59
  getUniverSheetInstance(id: string): Nullable<Workbook>;
60
60
  getUniverDocInstance(id: string): Nullable<DocumentDataModel>;
61
- getUniverSlideInstance(id: string): Nullable<Slide>;
61
+ getUniverSlideInstance(id: string): Nullable<SlideDataModel>;
62
62
  getCurrentUniverSheetInstance(): Workbook;
63
63
  getCurrentUniverDocInstance(): DocumentDataModel;
64
- getCurrentUniverSlideInstance(): Slide;
64
+ getCurrentUniverSlideInstance(): SlideDataModel;
65
65
  setCurrentUniverSheetInstance(id: string): void;
66
66
  setCurrentUniverDocInstance(id: string): void;
67
67
  setCurrentUniverSlideInstance(id: string): void;
68
68
  getAllUniverSheetsInstance(): Workbook[];
69
69
  getAllUniverDocsInstance(): DocumentDataModel[];
70
- getAllUniverSlidesInstance(): Slide[];
70
+ getAllUniverSlidesInstance(): SlideDataModel[];
71
71
  getDocumentType(unitId: string): UniverInstanceType;
72
72
  disposeDocument(unitId: string): boolean;
73
73
  }
@@ -83,19 +83,19 @@ export declare class UniverInstanceService extends Disposable implements IUniver
83
83
  private readonly _currentDoc$;
84
84
  readonly currentDoc$: Observable<Nullable<DocumentDataModel>>;
85
85
  private readonly _currentSlide$;
86
- readonly currentSlide$: Observable<Nullable<Slide>>;
86
+ readonly currentSlide$: Observable<Nullable<SlideDataModel>>;
87
87
  private readonly _sheetAdded$;
88
88
  readonly sheetAdded$: Observable<Workbook>;
89
89
  private readonly _docAdded$;
90
90
  readonly docAdded$: Observable<DocumentDataModel>;
91
91
  private readonly _slideAdded$;
92
- readonly slideAdded$: Observable<Slide>;
92
+ readonly slideAdded$: Observable<SlideDataModel>;
93
93
  private readonly _sheetDisposed$;
94
94
  readonly sheetDisposed$: Observable<Workbook>;
95
95
  private readonly _docDisposed$;
96
96
  readonly docDisposed$: Observable<DocumentDataModel>;
97
97
  private readonly _slideDisposed$;
98
- readonly slideDisposed$: Observable<Slide>;
98
+ readonly slideDisposed$: Observable<SlideDataModel>;
99
99
  private readonly _sheets;
100
100
  private readonly _docs;
101
101
  private readonly _slides;
@@ -103,25 +103,25 @@ export declare class UniverInstanceService extends Disposable implements IUniver
103
103
  dispose(): void;
104
104
  createDoc(data: Partial<IDocumentData>): DocumentDataModel;
105
105
  createSheet(data: Partial<IWorkbookData>): Workbook;
106
- createSlide(data: Partial<ISlideData>): Slide;
106
+ createSlide(data: Partial<ISlideData>): SlideDataModel;
107
107
  addSheet(sheet: Workbook): void;
108
108
  changeDoc(unitId: string, doc: DocumentDataModel): void;
109
109
  addDoc(doc: DocumentDataModel): void;
110
- addSlide(slide: Slide): void;
110
+ addSlide(slide: SlideDataModel): void;
111
111
  getUniverSheetInstance(id: string): Nullable<Workbook>;
112
112
  getUniverDocInstance(id: string): Nullable<DocumentDataModel>;
113
- getUniverSlideInstance(id: string): Nullable<Slide>;
113
+ getUniverSlideInstance(id: string): Nullable<SlideDataModel>;
114
114
  getAllUniverSheetsInstance(): Workbook[];
115
115
  getAllUniverDocsInstance(): DocumentDataModel[];
116
- getAllUniverSlidesInstance(): Slide[];
116
+ getAllUniverSlidesInstance(): SlideDataModel[];
117
117
  setCurrentUniverSheetInstance(id: string): void;
118
118
  setCurrentUniverSlideInstance(id: string): void;
119
119
  setCurrentUniverDocInstance(id: string): void;
120
120
  getCurrentUniverSheetInstance(): Workbook;
121
121
  getCurrentUniverDocInstance(): DocumentDataModel;
122
- getCurrentUniverSlideInstance(): Slide;
122
+ getCurrentUniverSlideInstance(): SlideDataModel;
123
123
  focusUniverInstance(id: string | null): void;
124
- getFocusedUniverInstance(): Workbook | DocumentDataModel | Slide | null;
124
+ getFocusedUniverInstance(): Nullable<Workbook | DocumentDataModel | SlideDataModel>;
125
125
  getDocumentType(unitId: string): UniverInstanceType;
126
126
  disposeDocument(unitId: string): boolean;
127
127
  }
@@ -26,17 +26,18 @@ export declare class LocaleService extends Disposable {
26
26
  localeChanged$: Subject<void>;
27
27
  constructor();
28
28
  /**
29
- * Load more locales after init
29
+ * Load more locales after init.
30
30
  *
31
31
  * @param locales - Locale object
32
- *
33
32
  */
34
33
  load(locales: ILocales): void;
35
34
  /**
36
35
  * Translate a key to the current locale
36
+ *
37
37
  * @param {string} key the key to translate
38
38
  * @param {string[]} args optional arguments to replace in the translated string
39
39
  * @returns {string} the translated string
40
+ *
40
41
  * @example
41
42
  * const locales = {
42
43
  * [LocaleType.EN_US]: {
@@ -58,4 +59,5 @@ export declare class LocaleService extends Disposable {
58
59
  t: (key: string, ...args: string[]) => string;
59
60
  setLocale(locale: LocaleType): void;
60
61
  getLocales(): ILanguagePack | undefined;
62
+ getCurrentLocale(): LocaleType;
61
63
  }
@@ -0,0 +1,18 @@
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 interface ILogContext {
17
+ metadata?: Record<string, string>;
18
+ }
@@ -0,0 +1,37 @@
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
+ import type { IFetchMissingChangesetsRequest, IFetchMissingChangesetsResponse, IGetResourcesRequest, IGetResourcesResponse, IGetSheetBlockRequest, IGetSheetBlockResponse, IGetUnitOnRevRequest, IGetUnitOnRevResponse, ISaveChangesetRequest, ISaveChangesetResponse, ISaveSheetBlockRequest, ISaveSheetBlockResponse, ISaveSnapshotRequest, ISaveSnapshotResponse, ISheetBlock, ISnapshot } from '@univerjs/protocol';
17
+ import type { IWorkbookData } from '../../../types/interfaces/i-workbook-data';
18
+ import type { ILogContext } from '../../log/context';
19
+ import type { ISnapshotServerService } from '../snapshot-server.service';
20
+ export declare const testSnapshot: () => ISnapshot;
21
+ export declare const testSheetBlocks: () => ISheetBlock[];
22
+ export declare const testWorkbookData: () => IWorkbookData;
23
+ export declare class MockSnapshotServerService implements ISnapshotServerService {
24
+ /** Load snapshot from a database. */
25
+ getUnitOnRev(context: ILogContext, params: IGetUnitOnRevRequest): Promise<IGetUnitOnRevResponse>;
26
+ /** Load sheet block from a database. */
27
+ getSheetBlock(context: ILogContext, params: IGetSheetBlockRequest): Promise<IGetSheetBlockResponse>;
28
+ /** Fetch missing changeset */
29
+ fetchMissingChangesets(context: ILogContext, params: IFetchMissingChangesetsRequest): Promise<IFetchMissingChangesetsResponse>;
30
+ getResourcesRequest(context: ILogContext, params: IGetResourcesRequest): Promise<IGetResourcesResponse>;
31
+ /** Save snapshot to a database. */
32
+ saveSnapshot(context: ILogContext, params: ISaveSnapshotRequest): Promise<ISaveSnapshotResponse>;
33
+ /** Save sheet block to a database. */
34
+ saveSheetBlock(context: ILogContext, params: ISaveSheetBlockRequest): Promise<ISaveSheetBlockResponse>;
35
+ /** Save changeset to a database. */
36
+ saveChangeset(context: ILogContext, params: ISaveChangesetRequest): Promise<ISaveChangesetResponse>;
37
+ }
@@ -0,0 +1,16 @@
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 {};
@@ -0,0 +1,57 @@
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
+ import type { IFetchMissingChangesetsRequest, IFetchMissingChangesetsResponse, IGetResourcesRequest, IGetResourcesResponse, IGetSheetBlockRequest, IGetSheetBlockResponse, IGetUnitOnRevRequest, IGetUnitOnRevResponse, ISaveChangesetRequest, ISaveChangesetResponse, ISaveSheetBlockRequest, ISaveSheetBlockResponse, ISaveSnapshotRequest, ISaveSnapshotResponse } from '@univerjs/protocol';
17
+ import type { ILogContext } from '../log/context';
18
+ /**
19
+ * It provides implementations for server side controllers to load or save
20
+ * or load snapshots. This service should be implemented by the host environment.
21
+ * And it shouldn't contain any business logic.
22
+ */
23
+ export declare const ISnapshotServerService: import("@wendellhu/redi").IdentifierDecorator<ISnapshotServerService>;
24
+ export interface ISnapshotServerService {
25
+ /** Load snapshot from a database. */
26
+ getUnitOnRev: (context: ILogContext, params: IGetUnitOnRevRequest) => Promise<IGetUnitOnRevResponse>;
27
+ /** Load sheet block from a database. */
28
+ getSheetBlock: (context: ILogContext, params: IGetSheetBlockRequest) => Promise<IGetSheetBlockResponse>;
29
+ /** Fetch missing changeset */
30
+ fetchMissingChangesets: (context: ILogContext, params: IFetchMissingChangesetsRequest) => Promise<IFetchMissingChangesetsResponse>;
31
+ getResourcesRequest: (context: ILogContext, params: IGetResourcesRequest) => Promise<IGetResourcesResponse>;
32
+ /** Save snapshot to a database. */
33
+ saveSnapshot: (context: ILogContext, params: ISaveSnapshotRequest) => Promise<ISaveSnapshotResponse>;
34
+ /** Save sheet block to a database. */
35
+ saveSheetBlock: (context: ILogContext, params: ISaveSheetBlockRequest) => Promise<ISaveSheetBlockResponse>;
36
+ /** Save changeset to a database. */
37
+ saveChangeset: (context: ILogContext, params: ISaveChangesetRequest) => Promise<ISaveChangesetResponse>;
38
+ }
39
+ /**
40
+ * The server needs to fully implement all interfaces, but when used by the client, use saveSheetBlock to cache the sheet block locally, and use getSheetBlock to obtain the sheet block.
41
+ */
42
+ export declare class ClientSnapshotServerService implements ISnapshotServerService {
43
+ private _sheetBlockCache;
44
+ /** Load snapshot from a database. */
45
+ getUnitOnRev(context: ILogContext, params: IGetUnitOnRevRequest): Promise<IGetUnitOnRevResponse>;
46
+ /** Load sheet block from a database. */
47
+ getSheetBlock(context: ILogContext, params: IGetSheetBlockRequest): Promise<IGetSheetBlockResponse>;
48
+ /** Fetch missing changeset */
49
+ fetchMissingChangesets(context: ILogContext, params: IFetchMissingChangesetsRequest): Promise<IFetchMissingChangesetsResponse>;
50
+ getResourcesRequest(context: ILogContext, params: IGetResourcesRequest): Promise<IGetResourcesResponse>;
51
+ /** Save snapshot to a database. */
52
+ saveSnapshot(context: ILogContext, params: ISaveSnapshotRequest): Promise<ISaveSnapshotResponse>;
53
+ /** Save sheet block to a database. */
54
+ saveSheetBlock(context: ILogContext, params: ISaveSheetBlockRequest): Promise<ISaveSheetBlockResponse>;
55
+ /** Save changeset to a database. */
56
+ saveChangeset(context: ILogContext, params: ISaveChangesetRequest): Promise<ISaveChangesetResponse>;
57
+ }
@@ -0,0 +1,43 @@
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
+ import type { ISheetBlock, ISnapshot } from '@univerjs/protocol';
17
+ import type { ILogContext } from '../log/context';
18
+ import type { IWorkbookData } from '../../types/interfaces/i-workbook-data';
19
+ import type { IDocumentData } from '../../types/interfaces/i-document-data';
20
+ import type { ISnapshotServerService } from './snapshot-server.service';
21
+ export declare function generateTemporarySnap(context: ILogContext, workbook: IWorkbookData, unitID: string, rev: number, snapshotService: ISnapshotServerService): Promise<{
22
+ snapshotRes: ISnapshot;
23
+ }>;
24
+ export declare function transformWorkbookDataToSnapshot(context: ILogContext, workbook: IWorkbookData, unitID: string, rev: number, snapshotService: ISnapshotServerService): Promise<{
25
+ snapshot: ISnapshot;
26
+ }>;
27
+ /**
28
+ * Assemble a snapshot to a workbook.
29
+ * @param snapshot
30
+ * @param sheetBlocks
31
+ */
32
+ export declare function transformSnapshotToWorkbookData(snapshot: ISnapshot, sheetBlocks: ISheetBlock[], _context?: ILogContext): IWorkbookData;
33
+ export declare function transformSnapshotToDocumentData(snapshot: ISnapshot): IDocumentData;
34
+ export declare function transformDocumentDataToSnapshot(context: ILogContext, document: IDocumentData, unitID: string, rev: number, snapshotService: ISnapshotServerService): Promise<{
35
+ snapshot: ISnapshot;
36
+ }>;
37
+ /**
38
+ *
39
+ * @param snapshot
40
+ * @param snapshotService
41
+ * @returns
42
+ */
43
+ export declare function getSheetBlocksFromSnapshot(snapshot: ISnapshot, snapshotService: ISnapshotServerService): Promise<ISheetBlock[]>;
@@ -0,0 +1,34 @@
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
+ import type { ISheetBlock } from '@univerjs/protocol';
17
+ import type { IWorksheetData } from '../../types/interfaces/i-worksheet-data';
18
+ import type { IWorkbookData } from '../../types/interfaces/i-workbook-data';
19
+ import type { IDocumentData } from '../../types/interfaces/i-document-data';
20
+ import type { ICellData } from '../../types/interfaces/i-cell-data';
21
+ import type { IObjectMatrixPrimitiveType } from '../../shared/object-matrix';
22
+ export declare const textEncoder: TextEncoder;
23
+ export declare const textDecoder: TextDecoder;
24
+ /**
25
+ * @param worksheet
26
+ */
27
+ export declare function encodeWorksheetOtherMetas(worksheet: Partial<IWorksheetData>): Uint8Array;
28
+ export declare function encodeWorkbookOtherMetas(workbook: IWorkbookData): Uint8Array;
29
+ export declare function encodeDocOriginalMeta(document: IDocumentData): Uint8Array;
30
+ export declare function decodeWorksheetOtherMetas(buffer: Uint8Array): Partial<IWorksheetData>;
31
+ export declare function decodeWorkbookOtherMetas(buffer: Uint8Array): Partial<IWorkbookData>;
32
+ export declare function decodePartOfCellData(buffer: Uint8Array | string): IObjectMatrixPrimitiveType<ICellData>;
33
+ export declare function decodeDocOriginalMeta(buffer: Uint8Array | string): Partial<IDocumentData>;
34
+ export declare function splitCellDataToBlocks(cellData: IObjectMatrixPrimitiveType<ICellData>, maxColumn: number): ISheetBlock[];
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { IAccessor } from '@wendellhu/redi';
16
+ import type { IAccessor, IDisposable } from '@wendellhu/redi';
17
17
  import type { Observable } from 'rxjs';
18
18
  import { BehaviorSubject } from 'rxjs';
19
19
  import { Disposable } from '../../shared/lifecycle';
@@ -21,22 +21,30 @@ import type { IMutationInfo } from '../command/command.service';
21
21
  import { CommandType, ICommandService } from '../command/command.service';
22
22
  import { IContextService } from '../context/context.service';
23
23
  import { IUniverInstanceService } from '../instance/instance.service';
24
+ import type { Nullable } from '../../common/type-utils';
24
25
  export interface IUndoRedoItem {
25
26
  /** unitID maps to unitId for UniverSheet / UniverDoc / UniverSlide */
26
27
  unitID: string;
27
28
  undoMutations: IMutationInfo[];
28
29
  redoMutations: IMutationInfo[];
29
- undo?(mutations: IMutationInfo[]): Promise<boolean> | boolean;
30
- redo?(mutations: IMutationInfo[]): Promise<boolean> | boolean;
31
30
  }
32
31
  export interface IUndoRedoService {
33
32
  undoRedoStatus$: Observable<IUndoRedoStatus>;
34
33
  pushUndoRedo(item: IUndoRedoItem): void;
35
- pitchTopUndoElement(): IUndoRedoItem | null;
36
- pitchTopRedoElement(): IUndoRedoItem | null;
34
+ /** Pitch the top redo element of the currently focused Univer document instance. */
35
+ pitchTopUndoElement(): Nullable<IUndoRedoItem>;
36
+ /** Pitch the top undo element of the currently focused Univer document instance. */
37
+ pitchTopRedoElement(): Nullable<IUndoRedoItem>;
37
38
  popUndoToRedo(): void;
38
39
  popRedoToUndo(): void;
39
40
  clearUndoRedo(unitID: string): void;
41
+ /**
42
+ * Batch undo redo elements into a single `IUndoRedoItem` util the returned `IDisposable` is called.
43
+ *
44
+ * @deprecated This is a temporary solution. We are going to refactor the undo redo service shortly.
45
+ * @returns a disposable to cancel batching undo redo elements
46
+ */
47
+ __tempBatchingUndoRedo(unitId: string): IDisposable;
40
48
  }
41
49
  export interface IUndoRedoCommandInfos {
42
50
  undos: IMutationInfo[];
@@ -77,13 +85,17 @@ export declare class LocalUndoRedoService extends Disposable implements IUndoRed
77
85
  }>;
78
86
  protected readonly _undoStacks: Map<string, IUndoRedoItem[]>;
79
87
  protected readonly _redoStacks: Map<string, IUndoRedoItem[]>;
88
+ private _batchingStatus;
80
89
  constructor(_univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _contextService: IContextService);
81
90
  pushUndoRedo(item: IUndoRedoItem): void;
82
91
  clearUndoRedo(unitID: string): void;
83
- pitchTopUndoElement(): IUndoRedoItem | null;
84
- pitchTopRedoElement(): IUndoRedoItem | null;
92
+ pitchTopUndoElement(): Nullable<IUndoRedoItem>;
93
+ pitchTopRedoElement(): Nullable<IUndoRedoItem>;
94
+ private _pitchUndoElement;
95
+ private _pitchRedoElement;
85
96
  popUndoToRedo(): void;
86
97
  popRedoToUndo(): void;
98
+ __tempBatchingUndoRedo(unitId: string): IDisposable;
87
99
  protected _updateStatus(): void;
88
100
  protected _getUndoStack(unitId: string): IUndoRedoItem[] | null;
89
101
  protected _getUndoStack(unitId: string, createAsNeeded: true): IUndoRedoItem[];
@@ -91,5 +103,6 @@ export declare class LocalUndoRedoService extends Disposable implements IUndoRed
91
103
  protected _getRedoStack(unitId: string, createAsNeeded: true): IUndoRedoItem[];
92
104
  protected _getUndoStackForFocused(): IUndoRedoItem[];
93
105
  protected _getRedoStackForFocused(): IUndoRedoItem[];
106
+ private _tryBatchingElements;
94
107
  private _getFocusedUniverInstanceId;
95
108
  }
@@ -0,0 +1,16 @@
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 {};