@univerjs/core 0.1.1 → 0.1.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.
Files changed (44) hide show
  1. package/README.md +22 -2
  2. package/lib/cjs/index.js +8 -6
  3. package/lib/es/index.js +2262 -1685
  4. package/lib/types/common/__tests__/array.spec.d.ts +16 -0
  5. package/lib/types/common/array.d.ts +8 -0
  6. package/lib/types/common/interceptor.d.ts +1 -1
  7. package/lib/types/docs/data-model/__tests__/replacement.spec.d.ts +16 -0
  8. package/lib/types/docs/data-model/replacement.d.ts +17 -0
  9. package/lib/types/docs/data-model/text-x/text-x.d.ts +3 -3
  10. package/lib/types/index.d.ts +14 -1
  11. package/lib/types/services/command/command.service.d.ts +4 -4
  12. package/lib/types/services/context/context.d.ts +1 -0
  13. package/lib/types/services/instance/instance.service.d.ts +1 -1
  14. package/lib/types/services/locale/locale.service.d.ts +4 -2
  15. package/lib/types/services/log/context.d.ts +18 -0
  16. package/lib/types/services/snapshot/__tests__/snapshot-mock.d.ts +37 -0
  17. package/lib/types/services/snapshot/__tests__/snapshot-transform.spec.d.ts +16 -0
  18. package/lib/types/services/snapshot/snapshot-server.service.d.ts +57 -0
  19. package/lib/types/services/snapshot/snapshot-transform.d.ts +43 -0
  20. package/lib/types/services/snapshot/snapshot-utils.d.ts +34 -0
  21. package/lib/types/services/undoredo/undoredo.service.d.ts +20 -7
  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/debounce.d.ts +18 -0
  26. package/lib/types/shared/generate.d.ts +1 -1
  27. package/lib/types/shared/index.d.ts +2 -1
  28. package/lib/types/shared/locale.d.ts +2 -1
  29. package/lib/types/shared/object-matrix.d.ts +3 -0
  30. package/lib/types/shared/rxjs.d.ts +20 -0
  31. package/lib/types/shared/tools.d.ts +1 -1
  32. package/lib/types/sheets/__tests__/create-core-test-bed.d.ts +1 -2
  33. package/lib/types/sheets/__tests__/worksheet.spec.d.ts +16 -0
  34. package/lib/types/sheets/row-manager.d.ts +0 -2
  35. package/lib/types/sheets/workbook.d.ts +1 -0
  36. package/lib/types/sheets/worksheet.d.ts +29 -9
  37. package/lib/types/types/interfaces/i-cell-data.d.ts +6 -0
  38. package/lib/types/types/interfaces/i-column-data.d.ts +2 -2
  39. package/lib/types/types/interfaces/i-document-data.d.ts +3 -2
  40. package/lib/types/types/interfaces/i-range.d.ts +5 -0
  41. package/lib/types/types/interfaces/i-row-data.d.ts +2 -2
  42. package/lib/types/types/interfaces/i-selection-data.d.ts +6 -0
  43. package/lib/umd/index.js +8 -6
  44. package/package.json +8 -6
@@ -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,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,17 @@
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 { IDocumentBody } from '../../types/interfaces/i-document-data';
17
+ export declare function replaceInDocumentBody(body: IDocumentBody, query: string, target: string): IDocumentBody;
@@ -19,9 +19,9 @@ import { type TextXAction } from '../action-types';
19
19
  export declare class TextX {
20
20
  static compose(thisActions: TextXAction[], otherActions: TextXAction[]): TextXAction[];
21
21
  private _actions;
22
- insert(len: number, body: IDocumentBody, segmentId: string): this;
23
- retain(len: number, segmentId: string, body?: IDocumentBody, coverType?: UpdateDocsAttributeType): this;
24
- delete(len: number, segmentId: string): this;
22
+ insert(len: number, body: IDocumentBody, segmentId?: string): this;
23
+ retain(len: number, segmentId?: string, body?: IDocumentBody, coverType?: UpdateDocsAttributeType): this;
24
+ delete(len: number, segmentId?: string): this;
25
25
  serialize(): TextXAction[];
26
26
  push(...args: TextXAction[]): this;
27
27
  trimEndUselessRetainAction(): this;
@@ -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';
@@ -25,6 +25,7 @@ export { TextXActionType, type TextXAction, type IDeleteAction, type IInsertActi
25
25
  export { ActionIterator } from './docs/data-model/text-x/action-iterator';
26
26
  export { getBodySlice, composeBody } from './docs/data-model/text-x/utils';
27
27
  export { TextX } from './docs/data-model/text-x/text-x';
28
+ export { replaceInDocumentBody } from './docs/data-model/replacement';
28
29
  export * from './observer';
29
30
  export { Plugin, PluginType } from './plugin/plugin';
30
31
  export { type CommandListener, CommandService, CommandType, type ICommand, type ICommandInfo, ICommandService, type IExecutionOptions, type IMultiCommand, type IMutation, type IMutationCommonParams, type IMutationInfo, type IOperation, type IOperationInfo, NilCommand, sequenceExecute, sequenceExecuteAsync, } from './services/command/command.service';
@@ -47,6 +48,7 @@ export { IResourceManagerService, ISnapshotPersistenceService } from './services
47
48
  export { type IStyleSheet, ThemeService } from './services/theme/theme.service';
48
49
  export { type IUndoRedoCommandInfos, type IUndoRedoItem, IUndoRedoService, type IUndoRedoStatus, LocalUndoRedoService, RedoCommand, UndoCommand, RedoCommandId, UndoCommandId, } from './services/undoredo/undoredo.service';
49
50
  export * from './shared';
51
+ export { fromCallback } from './shared/rxjs';
50
52
  export type { IComposeInterceptors, IInterceptor, InterceptorHandler } from './common/interceptor';
51
53
  export { composeInterceptors, createInterceptorKey, InterceptorManager } from './common/interceptor';
52
54
  export { normalizeTextRuns } from './docs/data-model/apply-utils/common';
@@ -61,3 +63,14 @@ export * from './slides/domain';
61
63
  export * from './types/const';
62
64
  export * from './types/enum';
63
65
  export * from './types/interfaces';
66
+ export { UniverInstanceService } from './services/instance/instance.service';
67
+ export { LifecycleInitializerService } from './services/lifecycle/lifecycle.service';
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,3 +22,4 @@ 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";
@@ -21,7 +21,7 @@ import { Workbook } from '../../sheets/workbook';
21
21
  import { Slide } 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,
@@ -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,17 @@
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 function b64EncodeUnicode(str: string): string;
17
+ export declare function b64DecodeUnicode(str: string): string;
@@ -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
- interface IRgbColor {
16
+ export interface IRgbColor {
17
17
  b: number;
18
18
  g: number;
19
19
  r: number;
@@ -61,4 +61,6 @@ export declare class ColorKit {
61
61
  isLight(): boolean;
62
62
  private _setNullColor;
63
63
  }
64
+ export declare function isBlackColor(color: string): boolean;
65
+ export declare function isWhiteColor(color: string): boolean;
64
66
  export {};
@@ -19,4 +19,5 @@ interface AnyObject {
19
19
  }
20
20
  export declare function deepCompare(arg1: AnyObject, arg2: AnyObject): boolean;
21
21
  export declare function isSameStyleTextRun(tr1: ITextRun, tr2: ITextRun): boolean;
22
+ export declare function checkForSubstrings(searchString: string, substrings: string[]): boolean;
22
23
  export {};
@@ -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
+ type debounceFn<T extends (...args: any[]) => any> = (this: ThisParameterType<T>, ...args: Parameters<T>) => void;
17
+ export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): debounceFn<T>;
18
+ export {};
@@ -18,4 +18,4 @@
18
18
  * @param val The number or string to be judged
19
19
  * @returns Result
20
20
  */
21
- export declare function isRealNum(val: string | number): boolean;
21
+ export declare function isRealNum(val: string | number | boolean): boolean;
@@ -16,7 +16,7 @@
16
16
  export * from './array-search';
17
17
  export * from './blob';
18
18
  export * from './color/color';
19
- export { ColorKit, COLORS, RGB_PAREN, RGBA_PAREN } from './color/color-kit';
19
+ export { ColorKit, COLORS, RGB_PAREN, RGBA_PAREN, type IRgbColor } from './color/color-kit';
20
20
  export * from './command-enum';
21
21
  export * from './common';
22
22
  export * from './compare';
@@ -35,3 +35,4 @@ export * from './sequence';
35
35
  export * from './sort-rules';
36
36
  export * from './tools';
37
37
  export * from './types';
38
+ export * from './debounce';
@@ -13,8 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ export type LanguageValue = string | string[] | ILanguagePack | ILanguagePack[] | boolean;
16
17
  export interface ILanguagePack {
17
- [key: string]: string | ILanguagePack | ILanguagePack[];
18
+ [key: string]: LanguageValue;
18
19
  }
19
20
  export interface ILocales {
20
21
  [key: string]: ILanguagePack;
@@ -42,6 +42,9 @@ export declare class ObjectMatrix<T> {
42
42
  getMatrix(): IObjectMatrixPrimitiveType<T>;
43
43
  forEach(callback: (row: number, objectArray: IObjectArrayPrimitiveType<T>) => Nullable<boolean>): ObjectMatrix<T>;
44
44
  forRow(callback: (row: number, cols: number[]) => Nullable<boolean>): ObjectMatrix<T>;
45
+ /**
46
+ * Iterate the object matrix with row priority, which means it scan the whole range row by row.
47
+ */
45
48
  forValue(callback: (row: number, col: number, value: T) => Nullable<boolean>): ObjectMatrix<T>;
46
49
  swapRow(src: number, target: number): void;
47
50
  getRow(rowIndex: number): Nullable<IObjectArrayPrimitiveType<T>>;
@@ -0,0 +1,20 @@
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 { IDisposable } from '@wendellhu/redi';
17
+ import { Observable } from 'rxjs';
18
+ type CallbackFn<T extends readonly unknown[]> = (cb: (...args: T) => void) => IDisposable;
19
+ export declare function fromCallback<T extends readonly unknown[]>(callback: CallbackFn<T>): Observable<T>;
20
+ export {};
@@ -23,7 +23,7 @@ export declare class Tools {
23
23
  static deleteBlank(value?: string): string | undefined;
24
24
  static getSystemType(): string;
25
25
  static getBrowserType(): string;
26
- static generateRandomId(n?: number): string;
26
+ static generateRandomId(n?: number, alphabet?: string): string;
27
27
  static getClassName(instance: object): string;
28
28
  static deepMerge(target: any, ...sources: any[]): any;
29
29
  static numberFixed(value: number, digit: number): number;