@univerjs/sheets 0.4.2 → 0.5.0-beta.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.
- package/lib/cjs/facade.js +1 -0
- package/lib/cjs/index.js +3 -3
- package/lib/cjs/locale/en-US.js +1 -0
- package/lib/cjs/locale/fa-IR.js +1 -0
- package/lib/cjs/locale/ru-RU.js +1 -0
- package/lib/cjs/locale/vi-VN.js +1 -0
- package/lib/cjs/locale/zh-CN.js +1 -0
- package/lib/cjs/locale/zh-TW.js +1 -0
- package/lib/es/facade.js +1806 -0
- package/lib/es/index.js +7694 -7605
- package/lib/es/locale/en-US.js +17 -0
- package/lib/es/locale/fa-IR.js +17 -0
- package/lib/es/locale/ru-RU.js +17 -0
- package/lib/es/locale/vi-VN.js +17 -0
- package/lib/es/locale/zh-CN.js +17 -0
- package/lib/es/locale/zh-TW.js +17 -0
- package/lib/types/basics/selection.d.ts +31 -20
- package/lib/types/commands/commands/add-worksheet-protection.command.d.ts +7 -0
- package/lib/types/commands/commands/delete-worksheet-protection.command.d.ts +8 -0
- package/lib/types/commands/commands/set-frozen.command.d.ts +13 -0
- package/lib/types/commands/commands/set-protection.command.d.ts +13 -0
- package/lib/types/commands/commands/set-worksheet-protection.command.d.ts +8 -0
- package/lib/types/commands/mutations/reorder-range.mutation.d.ts +1 -1
- package/lib/types/commands/operations/selection.operation.d.ts +4 -1
- package/lib/types/facade/__tests__/utils.spec.d.ts +16 -0
- package/lib/types/facade/f-permission.d.ts +106 -0
- package/lib/types/facade/f-range.d.ts +193 -0
- package/lib/types/facade/f-selection.d.ts +11 -0
- package/lib/types/facade/f-univer.d.ts +36 -0
- package/lib/types/facade/f-workbook.d.ts +105 -0
- package/lib/types/facade/f-worksheet.d.ts +408 -0
- package/lib/types/facade/index.d.ts +22 -0
- package/lib/types/facade/utils.d.ts +24 -0
- package/lib/types/index.d.ts +11 -9
- package/lib/types/model/range-protection-rule.model.d.ts +10 -1
- package/lib/types/services/permission/type.d.ts +3 -1
- package/lib/types/services/permission/worksheet-permission/worksheet-permission.service.d.ts +3 -2
- package/lib/types/services/ref-range/util.d.ts +12 -4
- package/lib/types/services/selections/index.d.ts +19 -0
- package/lib/types/services/selections/selection-data-model.d.ts +57 -0
- package/lib/types/services/selections/selection-manager.service.d.ts +15 -61
- package/lib/types/services/selections/type.d.ts +28 -0
- package/lib/types/services/sheet-interceptor/sheet-interceptor.service.d.ts +38 -7
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +3 -3
- package/lib/umd/locale/en-US.js +1 -0
- package/lib/umd/locale/fa-IR.js +1 -0
- package/lib/umd/locale/ru-RU.js +1 -0
- package/lib/umd/locale/vi-VN.js +1 -0
- package/lib/umd/locale/zh-CN.js +1 -0
- package/lib/umd/locale/zh-TW.js +1 -0
- package/package.json +36 -18
- package/lib/locale/en-US.json +0 -14
- package/lib/locale/fa-IR.json +0 -14
- package/lib/locale/ru-RU.json +0 -14
- package/lib/locale/vi-VN.json +0 -14
- package/lib/locale/zh-CN.json +0 -14
- package/lib/locale/zh-TW.json +0 -14
- package/lib/types/commands/commands/set-frozen-cancel.command.d.ts +0 -2
- package/lib/types/commands/commands/set-range-protection.command.d.ts +0 -8
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { UnitObject } from '@univerjs/protocol';
|
|
2
|
+
import { EditStateEnum, ViewStateEnum } from '../../model/range-protection-rule.model';
|
|
2
3
|
export interface IWorksheetProtectionRule {
|
|
3
4
|
permissionId: string;
|
|
4
5
|
description?: string;
|
|
5
6
|
unitType: UnitObject;
|
|
6
7
|
unitId: string;
|
|
7
8
|
subUnitId: string;
|
|
8
|
-
|
|
9
|
+
viewState: ViewStateEnum;
|
|
10
|
+
editState: EditStateEnum;
|
|
9
11
|
}
|
|
10
12
|
export interface IWorksheetProtectionPointRule {
|
|
11
13
|
unitId: string;
|
package/lib/types/services/permission/worksheet-permission/worksheet-permission.service.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Injector, IPermissionService, IResourceManagerService, IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
1
|
+
import { ILogService, Injector, IPermissionService, IResourceManagerService, IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
2
2
|
import { RangeProtectionRuleModel } from '../../../model/range-protection-rule.model';
|
|
3
3
|
import { WorksheetProtectionPointModel } from './worksheet-permission-point.model';
|
|
4
4
|
import { WorksheetProtectionRuleModel } from './worksheet-permission-rule.model';
|
|
@@ -12,7 +12,8 @@ export declare class WorksheetPermissionService extends RxDisposable {
|
|
|
12
12
|
private _worksheetProtectionPointRuleModel;
|
|
13
13
|
private _resourceManagerService;
|
|
14
14
|
private _rangeProtectionRuleModel;
|
|
15
|
-
|
|
15
|
+
private _logService;
|
|
16
|
+
constructor(_permissionService: IPermissionService, _univerInstanceService: IUniverInstanceService, _injector: Injector, _worksheetProtectionRuleModel: WorksheetProtectionRuleModel, _worksheetProtectionPointRuleModel: WorksheetProtectionPointModel, _resourceManagerService: IResourceManagerService, _rangeProtectionRuleModel: RangeProtectionRuleModel, _logService: ILogService);
|
|
16
17
|
private _init;
|
|
17
18
|
private _initRuleChange;
|
|
18
19
|
private _initRuleSnapshot;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IMoveRangeMutationParams } from '../../commands/mutations/move-range.mutation';
|
|
3
|
-
import { IMoveColumnsMutationParams, IMoveRowsMutationParams } from '../../commands/mutations/move-rows-cols.mutation';
|
|
1
|
+
import { IAccessor, ICommandInfo, IMutationInfo, IRange, Nullable, RANGE_TYPE } from '@univerjs/core';
|
|
4
2
|
import { IInsertColMutationParams, IInsertRowMutationParams, IRemoveColMutationParams, IRemoveRowsMutationParams, IRemoveSheetMutationParams } from '../../basics';
|
|
3
|
+
import { IInsertColCommandParams, IInsertRowCommandParams } from '../../commands/commands/insert-row-col.command';
|
|
5
4
|
import { IRemoveRowColCommandInterceptParams } from '../../commands/commands/remove-row-col.command';
|
|
6
5
|
import { ISheetCommandSharedParams } from '../../commands/utils/interface';
|
|
7
|
-
import { SheetsSelectionsService } from '../selections/selection-manager.service';
|
|
8
6
|
import { EffectRefRangeParams, IDeleteRangeMoveLeftCommand, IDeleteRangeMoveUpCommand, IInsertColCommand, IInsertRangeMoveDownCommand, IInsertRangeMoveRightCommand, IInsertRowCommand, IMoveColsCommand, IMoveRangeCommand, IMoveRowsCommand, IOperator, IRemoveRowColCommand, IReorderRangeCommand } from './type';
|
|
7
|
+
import { IMoveRangeMutationParams } from '../../commands/mutations/move-range.mutation';
|
|
8
|
+
import { IMoveColumnsMutationParams, IMoveRowsMutationParams } from '../../commands/mutations/move-rows-cols.mutation';
|
|
9
|
+
import { SheetsSelectionsService } from '../selections/selection-manager.service';
|
|
9
10
|
export declare const handleRangeTypeInput: (range: IRange) => {
|
|
10
11
|
rangeType?: RANGE_TYPE;
|
|
11
12
|
startAbsoluteRefType?: import('@univerjs/core').AbsoluteRefType;
|
|
@@ -69,6 +70,8 @@ export declare const handleDeleteRangeMoveLeftCommon: (param: IDeleteRangeMoveLe
|
|
|
69
70
|
export declare const handleDeleteRangeMoveUp: (param: IDeleteRangeMoveUpCommand, targetRange: IRange) => IOperator[];
|
|
70
71
|
export declare const handleDeleteRangeMoveUpCommon: (param: IDeleteRangeMoveUpCommand, targetRange: IRange) => IRange[];
|
|
71
72
|
export declare const handleRemoveRowCommon: (param: IRemoveRowColCommandInterceptParams, targetRange: IRange) => IRange[];
|
|
73
|
+
export declare const handleInsertRowCommon: (info: ICommandInfo<IInsertRowCommandParams>, targetRange: IRange) => IRange[];
|
|
74
|
+
export declare const handleInsertColCommon: (info: ICommandInfo<IInsertColCommandParams>, targetRange: IRange) => IRange[];
|
|
72
75
|
export declare const runRefRangeMutations: (operators: IOperator[], range: IRange) => IRange | null;
|
|
73
76
|
export declare const handleDefaultRangeChangeWithEffectRefCommands: (range: IRange, commandInfo: ICommandInfo) => IRange | null;
|
|
74
77
|
export declare const handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests: (range: IRange, commandInfo: ICommandInfo, deps: {
|
|
@@ -92,4 +95,9 @@ export declare function getEffectedRangesOnCommand(command: EffectRefRangeParams
|
|
|
92
95
|
selectionManagerService: SheetsSelectionsService;
|
|
93
96
|
}): IRange[];
|
|
94
97
|
export declare function getEffectedRangesOnMutation(mutation: IMutationInfo<MutationsAffectRange>): IRange[] | undefined;
|
|
98
|
+
export declare function getSeparateEffectedRangesOnCommand(accessor: IAccessor, command: EffectRefRangeParams): {
|
|
99
|
+
unitId: string;
|
|
100
|
+
subUnitId: string;
|
|
101
|
+
ranges: IRange[];
|
|
102
|
+
};
|
|
95
103
|
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export { IRefSelectionsService, RefSelectionsService } from './ref-selections.service';
|
|
17
|
+
export { WorkbookSelectionModel } from './selection-data-model';
|
|
18
|
+
export { DISABLE_NORMAL_SELECTIONS, SheetsSelectionsService } from './selection-manager.service';
|
|
19
|
+
export { type ISelectionManagerSearchParam, SelectionMoveType } from './type';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ISelectionCell, Nullable, Workbook, Disposable } from '@univerjs/core';
|
|
2
|
+
import { ISelectionWithStyle } from '../../basics/selection';
|
|
3
|
+
import { BehaviorSubject } from 'rxjs';
|
|
4
|
+
import { SelectionMoveType } from './type';
|
|
5
|
+
/**
|
|
6
|
+
* Origin name: WorkbookSelections
|
|
7
|
+
* NOT Same as @univerjs/sheets-ui.SelectionRenderModel, that's data for SelectionControl in rendering.
|
|
8
|
+
*/
|
|
9
|
+
export declare class WorkbookSelectionModel extends Disposable {
|
|
10
|
+
private readonly _workbook;
|
|
11
|
+
/**
|
|
12
|
+
* Selection data model for each worksheet.
|
|
13
|
+
*/
|
|
14
|
+
private _worksheetSelections;
|
|
15
|
+
private readonly _selectionMoveStart$;
|
|
16
|
+
readonly selectionMoveStart$: import('rxjs').Observable<Nullable<ISelectionWithStyle[]>>;
|
|
17
|
+
private readonly _selectionMoving$;
|
|
18
|
+
readonly selectionMoving$: import('rxjs').Observable<Nullable<ISelectionWithStyle[]>>;
|
|
19
|
+
readonly _selectionMoveEnd$: BehaviorSubject<ISelectionWithStyle[]>;
|
|
20
|
+
readonly selectionMoveEnd$: import('rxjs').Observable<ISelectionWithStyle[]>;
|
|
21
|
+
private readonly _selectionSet$;
|
|
22
|
+
readonly selectionSet$: import('rxjs').Observable<ISelectionWithStyle[]>;
|
|
23
|
+
private readonly _beforeSelectionMoveEnd$;
|
|
24
|
+
readonly beforeSelectionMoveEnd$: import('rxjs').Observable<ISelectionWithStyle[]>;
|
|
25
|
+
constructor(_workbook: Workbook);
|
|
26
|
+
dispose(): void;
|
|
27
|
+
/** Clear all selections in this workbook. */
|
|
28
|
+
clear(): void;
|
|
29
|
+
addSelections(sheetId: string, selectionDatas: ISelectionWithStyle[]): void;
|
|
30
|
+
/**
|
|
31
|
+
* Set selectionDatas to _worksheetSelections, and emit selectionDatas by type.
|
|
32
|
+
* @param sheetId
|
|
33
|
+
* @param selectionDatas
|
|
34
|
+
* @param type
|
|
35
|
+
*/
|
|
36
|
+
setSelections(sheetId: string, selectionDatas: ISelectionWithStyle[] | undefined, type: SelectionMoveType): void;
|
|
37
|
+
getCurrentSelections(): Readonly<ISelectionWithStyle[]>;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated use `getSelectionsOfWorksheet` instead.
|
|
40
|
+
* @param sheetId
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
getSelectionOfWorksheet(sheetId: string): ISelectionWithStyle[];
|
|
44
|
+
getSelectionsOfWorksheet(sheetId: string): ISelectionWithStyle[];
|
|
45
|
+
private _getCurrentSelections;
|
|
46
|
+
getCurrentLastSelection(): Readonly<Nullable<ISelectionWithStyle & {
|
|
47
|
+
primary: ISelectionCell;
|
|
48
|
+
}>>;
|
|
49
|
+
/**
|
|
50
|
+
* Same method as getSelectionsOfWorksheet.
|
|
51
|
+
* @param sheetId
|
|
52
|
+
* @returns this._worksheetSelections
|
|
53
|
+
*/
|
|
54
|
+
private _ensureSheetSelection;
|
|
55
|
+
deleteSheetSelection(sheetId: string): void;
|
|
56
|
+
private _emitOnEnd;
|
|
57
|
+
}
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import { DeepReadonly, ISelectionCell, Nullable,
|
|
2
|
-
import { Observable
|
|
1
|
+
import { DeepReadonly, ISelectionCell, Nullable, IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
3
|
import { ISelectionWithStyle } from '../../basics/selection';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
sheetId: string;
|
|
7
|
-
}
|
|
8
|
-
export declare enum SelectionMoveType {
|
|
9
|
-
MOVE_START = 0,
|
|
10
|
-
MOVING = 1,
|
|
11
|
-
MOVE_END = 2,
|
|
12
|
-
/**
|
|
13
|
-
* Events are not triggered by the API
|
|
14
|
-
*/
|
|
15
|
-
ONLY_SET = 3
|
|
16
|
-
}
|
|
4
|
+
import { ISelectionManagerSearchParam, SelectionMoveType } from './type';
|
|
5
|
+
import { WorkbookSelectionModel } from './selection-data-model';
|
|
17
6
|
export declare class SheetsSelectionsService extends RxDisposable {
|
|
18
7
|
protected readonly _instanceSrv: IUniverInstanceService;
|
|
19
8
|
private get _currentSelectionPos();
|
|
@@ -34,6 +23,14 @@ export declare class SheetsSelectionsService extends RxDisposable {
|
|
|
34
23
|
}>>;
|
|
35
24
|
addSelections(selectionsData: ISelectionWithStyle[]): void;
|
|
36
25
|
addSelections(unitId: string, worksheetId: string, selectionDatas: ISelectionWithStyle[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Set selection data to WorkbookSelectionModel.
|
|
28
|
+
* If type is not specified, this method would clear all existing selections.
|
|
29
|
+
* @param unitIdOrSelections
|
|
30
|
+
* @param worksheetIdOrType
|
|
31
|
+
* @param selectionDatas
|
|
32
|
+
* @param type
|
|
33
|
+
*/
|
|
37
34
|
setSelections(selectionDatas: ISelectionWithStyle[], type?: SelectionMoveType): void;
|
|
38
35
|
setSelections(unitId: string, worksheetId: string, selectionDatas: ISelectionWithStyle[], type?: SelectionMoveType): void;
|
|
39
36
|
clearCurrentSelections(): void;
|
|
@@ -44,53 +41,10 @@ export declare class SheetsSelectionsService extends RxDisposable {
|
|
|
44
41
|
*/
|
|
45
42
|
isOverlapping(): boolean;
|
|
46
43
|
protected _getCurrentSelections(): ISelectionWithStyle[];
|
|
47
|
-
getWorkbookSelections(unitId: string):
|
|
48
|
-
protected _workbookSelections: Map<string,
|
|
49
|
-
protected _ensureWorkbookSelection(unitId: string):
|
|
44
|
+
getWorkbookSelections(unitId: string): WorkbookSelectionModel;
|
|
45
|
+
protected _workbookSelections: Map<string, WorkbookSelectionModel>;
|
|
46
|
+
protected _ensureWorkbookSelection(unitId: string): WorkbookSelectionModel;
|
|
50
47
|
protected _removeWorkbookSelection(unitId: string): void;
|
|
51
48
|
}
|
|
52
|
-
/**
|
|
53
|
-
* This class manages selections in a single workbook.
|
|
54
|
-
*/
|
|
55
|
-
export declare class WorkbookSelections extends Disposable {
|
|
56
|
-
private readonly _workbook;
|
|
57
|
-
private readonly _selectionMoveStart$;
|
|
58
|
-
readonly selectionMoveStart$: Observable<Nullable<ISelectionWithStyle[]>>;
|
|
59
|
-
private readonly _selectionMoving$;
|
|
60
|
-
readonly selectionMoving$: Observable<Nullable<ISelectionWithStyle[]>>;
|
|
61
|
-
readonly _selectionMoveEnd$: BehaviorSubject<ISelectionWithStyle[]>;
|
|
62
|
-
readonly selectionMoveEnd$: Observable<ISelectionWithStyle[]>;
|
|
63
|
-
private readonly _selectionSet$;
|
|
64
|
-
readonly selectionSet$: Observable<ISelectionWithStyle[]>;
|
|
65
|
-
private readonly _beforeSelectionMoveEnd$;
|
|
66
|
-
readonly beforeSelectionMoveEnd$: Observable<ISelectionWithStyle[]>;
|
|
67
|
-
constructor(_workbook: Workbook);
|
|
68
|
-
dispose(): void;
|
|
69
|
-
/** Clear all selections in this workbook. */
|
|
70
|
-
clear(): void;
|
|
71
|
-
addSelections(sheetId: string, selectionDatas: ISelectionWithStyle[]): void;
|
|
72
|
-
/**
|
|
73
|
-
* Set selectionDatas to _worksheetSelections, and emit selectionDatas by type.
|
|
74
|
-
* If type is not specfied, this method would clear all existing selections.
|
|
75
|
-
* @param sheetId
|
|
76
|
-
* @param selectionDatas
|
|
77
|
-
* @param type
|
|
78
|
-
*/
|
|
79
|
-
setSelections(sheetId: string, selectionDatas: ISelectionWithStyle[] | undefined, type: SelectionMoveType): void;
|
|
80
|
-
getCurrentSelections(): Readonly<ISelectionWithStyle[]>;
|
|
81
|
-
getSelectionOfWorksheet(sheetId: string): ISelectionWithStyle[];
|
|
82
|
-
private _getCurrentSelections;
|
|
83
|
-
getCurrentLastSelection(): Readonly<Nullable<ISelectionWithStyle & {
|
|
84
|
-
primary: ISelectionCell;
|
|
85
|
-
}>>;
|
|
86
|
-
private _worksheetSelections;
|
|
87
|
-
/**
|
|
88
|
-
* Same as _getCurrentSelections(which return this._worksheetSelections), but this method would set [] if no selection.
|
|
89
|
-
* @param sheetId
|
|
90
|
-
* @returns this._worksheetSelections
|
|
91
|
-
*/
|
|
92
|
-
private _ensureSheetSelection;
|
|
93
|
-
private _emitOnEnd;
|
|
94
|
-
}
|
|
95
49
|
/** An context key to disable normal selections if its value is set to `true`. */
|
|
96
50
|
export declare const DISABLE_NORMAL_SELECTIONS = "DISABLE_NORMAL_SELECTIONS";
|
|
@@ -0,0 +1,28 @@
|
|
|
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 ISelectionManagerSearchParam {
|
|
17
|
+
unitId: string;
|
|
18
|
+
sheetId: string;
|
|
19
|
+
}
|
|
20
|
+
export declare enum SelectionMoveType {
|
|
21
|
+
MOVE_START = 0,
|
|
22
|
+
MOVING = 1,
|
|
23
|
+
MOVE_END = 2,
|
|
24
|
+
/**
|
|
25
|
+
* Events are not triggered by cursor movement
|
|
26
|
+
*/
|
|
27
|
+
ONLY_SET = 3
|
|
28
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ICommandInfo, IDisposable, IInterceptor, IRange, IUndoRedoCommandInfosByInterceptor, Nullable, Disposable, InterceptorEffectEnum, IUniverInstanceService } from '@univerjs/core';
|
|
1
|
+
import { ICellData, ICellDataForSheetInterceptor, ICommandInfo, IDisposable, IInterceptor, IRange, IUndoRedoCommandInfosByInterceptor, Nullable, Workbook, Worksheet, Disposable, InterceptorEffectEnum, InterceptorManager, IUniverInstanceService } from '@univerjs/core';
|
|
2
|
+
import { ISheetLocation } from './utils/interceptor';
|
|
2
3
|
export interface IBeforeCommandInterceptor {
|
|
3
4
|
priority?: number;
|
|
4
5
|
performCheck(info: ICommandInfo): Promise<boolean>;
|
|
@@ -16,6 +17,12 @@ export interface IRangeInterceptors {
|
|
|
16
17
|
priority?: number;
|
|
17
18
|
getMutations(rangesInfo: IRangesInfo): IUndoRedoCommandInfosByInterceptor;
|
|
18
19
|
}
|
|
20
|
+
interface ISheetLocationForEditor extends ISheetLocation {
|
|
21
|
+
origin: Nullable<ICellData>;
|
|
22
|
+
}
|
|
23
|
+
export declare const BEFORE_CELL_EDIT: IInterceptor<ICellDataForSheetInterceptor, ISheetLocationForEditor>;
|
|
24
|
+
export declare const AFTER_CELL_EDIT: IInterceptor<ICellDataForSheetInterceptor, ISheetLocationForEditor>;
|
|
25
|
+
export declare const AFTER_CELL_EDIT_ASYNC: IInterceptor<Promise<Nullable<ICellDataForSheetInterceptor>>, ISheetLocationForEditor>;
|
|
19
26
|
/**
|
|
20
27
|
* This class expose methods for sheet features to inject code to sheet underlying logic.
|
|
21
28
|
*/
|
|
@@ -27,10 +34,38 @@ export declare class SheetInterceptorService extends Disposable {
|
|
|
27
34
|
private _beforeCommandInterceptor;
|
|
28
35
|
private readonly _workbookDisposables;
|
|
29
36
|
private readonly _worksheetDisposables;
|
|
37
|
+
readonly writeCellInterceptor: InterceptorManager<{
|
|
38
|
+
BEFORE_CELL_EDIT: IInterceptor<ICellDataForSheetInterceptor, ISheetLocationForEditor>;
|
|
39
|
+
AFTER_CELL_EDIT: IInterceptor<ICellDataForSheetInterceptor, ISheetLocationForEditor>;
|
|
40
|
+
AFTER_CELL_EDIT_ASYNC: IInterceptor<Promise<Nullable<ICellDataForSheetInterceptor>>, ISheetLocationForEditor>;
|
|
41
|
+
}>;
|
|
30
42
|
/** @ignore */
|
|
31
43
|
constructor(_univerInstanceService: IUniverInstanceService);
|
|
32
44
|
dispose(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Add a listener function to a specific command to add affiliated mutations. It should be called in controllers.
|
|
47
|
+
*
|
|
48
|
+
* Pairs with {@link onCommandExecute}.
|
|
49
|
+
*
|
|
50
|
+
* @param interceptor
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
33
53
|
interceptCommand(interceptor: ICommandInterceptor): IDisposable;
|
|
54
|
+
/**
|
|
55
|
+
* When command is executing, call this method to gether undo redo mutations from upper features.
|
|
56
|
+
* @param command
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
onCommandExecute(info: ICommandInfo): IUndoRedoCommandInfosByInterceptor;
|
|
60
|
+
/**
|
|
61
|
+
* Add a listener function to a specific command to deteminte if the command can execute mutations. It should be
|
|
62
|
+
* called in controllers.
|
|
63
|
+
*
|
|
64
|
+
* Pairs with {@link beforeCommandExecute}.
|
|
65
|
+
*
|
|
66
|
+
* @param interceptor
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
34
69
|
interceptBeforeCommand(interceptor: IBeforeCommandInterceptor): IDisposable;
|
|
35
70
|
/**
|
|
36
71
|
* before command execute, call this method to get the flag of whether it can be executed the command,
|
|
@@ -44,16 +79,12 @@ export declare class SheetInterceptorService extends Disposable {
|
|
|
44
79
|
* @returns IDisposable
|
|
45
80
|
*/
|
|
46
81
|
interceptRanges(interceptor: IRangeInterceptors): IDisposable;
|
|
47
|
-
/**
|
|
48
|
-
* When command is executing, call this method to gether undo redo mutations from upper features.
|
|
49
|
-
* @param command
|
|
50
|
-
* @returns
|
|
51
|
-
*/
|
|
52
|
-
onCommandExecute(info: ICommandInfo): IUndoRedoCommandInfosByInterceptor;
|
|
53
82
|
generateMutationsByRanges(info: IRangesInfo): IUndoRedoCommandInfosByInterceptor;
|
|
83
|
+
onWriteCell(workbook: Workbook, worksheet: Worksheet, row: number, col: number, cellData: ICellData): Promise<Nullable<ICellDataForSheetInterceptor>>;
|
|
54
84
|
intercept<T extends IInterceptor<any, any>>(name: T, interceptor: T): IDisposable;
|
|
55
85
|
fetchThroughInterceptors<T, C>(name: IInterceptor<T, C>, effect?: InterceptorEffectEnum): (initValue: Nullable<T>, initContext: C) => Nullable<T>;
|
|
56
86
|
private _interceptWorkbook;
|
|
57
87
|
private _disposeWorkbookInterceptor;
|
|
58
88
|
private _disposeSheetInterceptor;
|
|
59
89
|
}
|
|
90
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(u,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-formula"],r):(u=typeof globalThis<"u"?globalThis:u||self,r(u.UniverSheetsFacade={},u.UniverCore,u.UniverSheets,u.UniverEngineFormula))})(this,function(u,r,a,f){"use strict";var q=Object.defineProperty;var J=(u,r,a)=>r in u?q(u,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):u[r]=a;var b=(u,r,a)=>J(u,typeof r!="symbol"?r+"":r,a);var P=Object.defineProperty,p=Object.getOwnPropertyDescriptor,U=(d,o,e,t)=>{for(var n=t>1?void 0:t?p(o,e):o,i=d.length-1,s;i>=0;i--)(s=d[i])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&P(o,e,n),n},_=(d,o)=>(e,t)=>o(e,t,d);u.FPermission=class extends r.FBase{constructor(o,e,t,n,i,s,h){super(),this._injector=o,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=n,this._rangeProtectionRuleModel=i,this._worksheetProtectionPointRuleModel=s,this._authzIoService=h}setWorkbookPermissionPoint(o,e,t){const n=new e(o);this._permissionService.getPermissionPoint(n.id)||this._permissionService.addPermissionPoint(n),this._permissionService.updatePermissionPoint(n.id,t)}setWorkbookEditPermission(o,e){this.setWorkbookPermissionPoint(o,a.WorkbookEditablePermission,e)}async addWorksheetBasePermission(o,e){if(this._rangeProtectionRuleModel.getSubunitRuleList(o,e).length>0)throw new Error("sheet protection cannot intersect with range protection");const n=await this._authzIoService.create({objectType:a.UnitObject.Worksheet});if(this._commandService.syncExecuteCommand(a.AddWorksheetProtectionMutation.id,{unitId:o,subUnitId:e,rule:{permissionId:n,unitType:a.UnitObject.Worksheet,unitId:o,subUnitId:e}}))return n}removeWorksheetPermission(o,e){this._commandService.syncExecuteCommand(a.DeleteWorksheetProtectionMutation.id,{unitId:o,subUnitId:e}),[...a.getAllWorksheetPermissionPoint(),...a.getAllWorksheetPermissionPointByPointPanel()].forEach(t=>{const n=new t(o,e);this._permissionService.updatePermissionPoint(n.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(o,e)}async setWorksheetPermissionPoint(o,e,t,n){const i=this._worksheetProtectionRuleModel.getRule(o,e);let s;if(t===a.WorksheetEditPermission||t===a.WorksheetViewPermission)if(i)s=i.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(o,e).length>0)throw new Error("sheet protection cannot intersect with range protection");s=await this.addWorksheetBasePermission(o,e)}else{const m=this._worksheetProtectionPointRuleModel.getRule(o,e);m?s=m.permissionId:(s=await this._authzIoService.create({objectType:a.UnitObject.Worksheet}),this._commandService.executeCommand(a.SetWorksheetPermissionPointsMutation.id,{unitId:o,subUnitId:e,permissionId:s}))}const c=new t(o,e);return this._permissionService.getPermissionPoint(c.id)||this._permissionService.addPermissionPoint(c),this._permissionService.updatePermissionPoint(c.id,n),s}async addRangeBaseProtection(o,e,t){const n=await this._authzIoService.create({objectType:a.UnitObject.SelectRange}),i=`ruleId_${r.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(o,e))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(o,e).some(m=>m.ranges.some(g=>t.some(v=>r.Rectangle.intersects(v,g)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,{unitId:o,subUnitId:e,rules:[{permissionId:n,unitType:a.UnitObject.SelectRange,unitId:o,subUnitId:e,ranges:t,id:i}]}))return{permissionId:n,ruleId:i}}removeRangeProtection(o,e,t){this._commandService.syncExecuteCommand(a.DeleteRangeProtectionMutation.id,{unitId:o,subUnitId:e,ruleIds:t})&&this._rangeProtectionRuleModel.getSubunitRuleList(o,e).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(o,e),[...a.getAllWorksheetPermissionPointByPointPanel()].forEach(s=>{const h=new s(o,e);this._permissionService.updatePermissionPoint(h.id,h.value)}))}setRangeProtectionPermissionPoint(o,e,t,n,i){const s=new n(o,e,t);this._permissionService.getPermissionPoint(s.id)||this._permissionService.addPermissionPoint(s),this._permissionService.updatePermissionPoint(s.id,i)}setRangeProtectionRanges(o,e,t,n){const i=this._rangeProtectionRuleModel.getRule(o,e,t);if(i){if(this._rangeProtectionRuleModel.getSubunitRuleList(o,e).filter(c=>c.id!==t).some(c=>c.ranges.some(l=>n.some(m=>r.Rectangle.intersects(m,l)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:o,subUnitId:e,ruleId:t,rule:{...i,ranges:n}})}}},u.FPermission=U([_(0,r.Inject(r.Injector)),_(1,r.ICommandService),_(2,r.IPermissionService),_(3,r.Inject(a.WorksheetProtectionRuleModel)),_(4,r.Inject(a.RangeProtectionRuleModel)),_(5,r.Inject(a.WorksheetProtectionPointModel)),_(6,r.Inject(r.IAuthzIoService))],u.FPermission);function E(d){switch(d){case"left":return r.HorizontalAlign.LEFT;case"center":return r.HorizontalAlign.CENTER;case"normal":return r.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${d}`)}}function F(d){switch(d){case r.HorizontalAlign.LEFT:return"left";case r.HorizontalAlign.CENTER:return"center";case r.HorizontalAlign.RIGHT:return"normal";default:throw new Error(`Invalid horizontal alignment: ${d}`)}}function M(d){switch(d){case"top":return r.VerticalAlign.TOP;case"middle":return r.VerticalAlign.MIDDLE;case"bottom":return r.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${d}`)}}function j(d){switch(d){case r.VerticalAlign.TOP:return"top";case r.VerticalAlign.MIDDLE:return"middle";case r.VerticalAlign.BOTTOM:return"bottom";default:throw new Error(`Invalid vertical alignment: ${d}`)}}function S(d){return r.isFormulaString(d)?{f:d}:r.isCellV(d)?{v:d}:(r.isICellData(d),d)}function A(d,o){const e=new r.ObjectMatrix,{startRow:t,startColumn:n,endRow:i,endColumn:s}=o;if(r.Tools.isArray(d))for(let h=0;h<=i-t;h++)for(let c=0;c<=s-n;c++)e.setValue(h+t,c+n,S(d[h][c]));else new r.ObjectMatrix(d).forValue((c,l,m)=>{e.setValue(c,l,S(m))});return e.getMatrix()}function k(d,o){return{startRow:d.startRow,endRow:d.endRow,startColumn:0,endColumn:o.getColumnCount()-1,rangeType:r.RANGE_TYPE.ROW}}function C(d,o){return{startRow:0,endRow:o.getRowCount()-1,startColumn:d.startColumn,endColumn:d.endColumn,rangeType:r.RANGE_TYPE.COLUMN}}var W=Object.defineProperty,T=Object.getOwnPropertyDescriptor,x=(d,o,e,t)=>{for(var n=t>1?void 0:t?T(o,e):o,i=d.length-1,s;i>=0;i--)(s=d[i])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&W(o,e,n),n},I=(d,o)=>(e,t)=>o(e,t,d);u.FRange=class extends r.FBase{constructor(o,e,t,n,i,s){super(),this._workbook=o,this._worksheet=e,this._range=t,this._injector=n,this._commandService=i,this._formulaDataModel=s}getUnitId(){return this._workbook.getUnitId()}getSheetName(){return this._worksheet.getName()}getRange(){return this._range}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}getCellData(){var o;return(o=this._worksheet.getCell(this._range.startRow,this._range.startColumn))!=null?o:null}isMerged(){const{startColumn:o,startRow:e,endColumn:t,endRow:n}=this._range;return this._worksheet.getMergedCellRange(e,o,n,t).some(s=>r.Rectangle.equals(s,this._range))}getCellStyleData(){var t;const o=this.getCellData(),e=this._workbook.getStyles();return o&&e&&(t=e.getStyleByCell(o))!=null?t:null}getValue(){var o,e;return(e=(o=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:o.v)!=null?e:null}getValues(){var s,h;const{startRow:o,endRow:e,startColumn:t,endColumn:n}=this._range,i=[];for(let c=o;c<=e;c++){const l=[];for(let m=t;m<=n;m++)l.push((h=(s=this._worksheet.getCell(c,m))==null?void 0:s.v)!=null?h:null);i.push(l)}return i}getCellDataGrid(){const{startRow:o,endRow:e,startColumn:t,endColumn:n}=this._range,i=[];for(let s=o;s<=e;s++){const h=[];for(let c=t;c<=n;c++)h.push(this._worksheet.getCellRaw(s,c));i.push(h)}return i}getFormulas(){const o=[],{startRow:e,endRow:t,startColumn:n,endColumn:i}=this._range,s=this._worksheet.getSheetId(),h=this._workbook.getUnitId();for(let c=e;c<=t;c++){const l=[];for(let m=n;m<=i;m++){const g=this._formulaDataModel.getFormulaStringByCell(c,m,s,h);l.push(g||"")}o.push(l)}return o}getWrap(){return this._worksheet.getRange(this._range).getWrap()===r.BooleanNumber.TRUE}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){return F(this._worksheet.getRange(this._range).getHorizontalAlignment())}getVerticalAlignment(){return j(this._worksheet.getRange(this._range).getVerticalAlignment())}setBackgroundColor(o){return this._commandService.executeCommand(a.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:o}}})}setValue(o){const e=S(o);if(!e)throw new Error("Invalid value");return this._commandService.executeCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e})}setWrap(o){return this._commandService.executeCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:o?r.WrapStrategy.WRAP:r.WrapStrategy.UNSPECIFIED})}setWrapStrategy(o){return this._commandService.executeCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:o})}setVerticalAlignment(o){return this._commandService.executeCommand(a.SetVerticalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:M(o)})}setHorizontalAlignment(o){return this._commandService.executeCommand(a.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:E(o)})}setValues(o){const e=A(o,this._range);return this._commandService.executeCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e})}setFontWeight(o){let e;if(o==="bold")e=r.BooleanNumber.TRUE;else if(o==="normal")e=r.BooleanNumber.FALSE;else if(o===null)e=null;else throw new Error("Invalid fontWeight");const t={type:"bl",value:e},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.executeCommand(a.SetStyleCommand.id,n),this}setFontStyle(o){let e;if(o==="italic")e=r.BooleanNumber.TRUE;else if(o==="normal")e=r.BooleanNumber.FALSE;else if(o===null)e=null;else throw new Error("Invalid fontStyle");const t={type:"it",value:e},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.executeCommand(a.SetStyleCommand.id,n),this}setFontLine(o){if(o==="underline")this._setFontUnderline({s:r.BooleanNumber.TRUE});else if(o==="line-through")this._setFontStrikethrough({s:r.BooleanNumber.TRUE});else if(o==="none")this._setFontUnderline({s:r.BooleanNumber.FALSE}),this._setFontStrikethrough({s:r.BooleanNumber.FALSE});else if(o===null)this._setFontUnderline(null),this._setFontStrikethrough(null);else throw new Error("Invalid fontLine");return this}_setFontUnderline(o){const e={type:"ul",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.executeCommand(a.SetStyleCommand.id,t)}_setFontStrikethrough(o){const e={type:"st",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.executeCommand(a.SetStyleCommand.id,t)}setFontFamily(o){const e={type:"ff",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.executeCommand(a.SetStyleCommand.id,t),this}setFontSize(o){const e={type:"fs",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.executeCommand(a.SetStyleCommand.id,t),this}setFontColor(o){const t={type:"cl",value:o===null?null:{rgb:o}},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.executeCommand(a.SetStyleCommand.id,n),this}async merge(){const o=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return await a.addMergeCellsUtil(this._injector,o,e,[this._range]),this}async mergeAcross(){const o=a.getAddMergeMutationRangeByType([this._range],r.Dimension.ROWS),e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return await a.addMergeCellsUtil(this._injector,e,t,o),this}async mergeVertically(){const o=a.getAddMergeMutationRangeByType([this._range],r.Dimension.COLUMNS),e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return await a.addMergeCellsUtil(this._injector,e,t,o),this}isPartOfMerge(){const{startRow:o,startColumn:e,endRow:t,endColumn:n}=this._range;return this._worksheet.getMergedCellRange(o,e,t,n).length>0}breakApart(){return this._commandService.executeCommand(a.RemoveWorksheetMergeCommand.id,{ranges:[this._range]}),this}forEach(o){const{startColumn:e,startRow:t,endColumn:n,endRow:i}=this._range;this._worksheet.getMatrixWithMergedCells(t,e,i,n).forValue((s,h,c)=>{o(s,h,c)})}},u.FRange=x([I(3,r.Inject(r.Injector)),I(4,r.ICommandService),I(5,r.Inject(f.FormulaDataModel))],u.FRange);var D=Object.defineProperty,O=Object.getOwnPropertyDescriptor,N=(d,o,e,t)=>{for(var n=t>1?void 0:t?O(o,e):o,i=d.length-1,s;i>=0;i--)(s=d[i])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&D(o,e,n),n},B=(d,o)=>(e,t)=>o(e,t,d);u.FSelection=class{constructor(o,e,t,n){this._workbook=o,this._worksheet=e,this._selections=t,this._injector=n}getActiveRange(){const o=this._selections.find(e=>!!e.primary);return o?this._injector.createInstance(u.FRange,this._workbook,this._worksheet,o.range):null}},u.FSelection=N([B(3,r.Inject(r.Injector))],u.FSelection);var V=Object.defineProperty,z=Object.getOwnPropertyDescriptor,H=(d,o,e,t)=>{for(var n=t>1?void 0:t?z(o,e):o,i=d.length-1,s;i>=0;i--)(s=d[i])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&V(o,e,n),n},R=(d,o)=>(e,t)=>o(e,t,d);u.FWorksheet=class extends r.FBase{constructor(e,t,n,i,s,h){super();b(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=n,this._injector=i,this._selectionManagerService=s,this._commandService=h}getInject(){return this._injector}getWorkbook(){return this._workbook}getSheetId(){return this._worksheet.getSheetId()}getSheetName(){return this._worksheet.getName()}getSelection(){const e=this._selectionManagerService.getCurrentSelections();return e?this._injector.createInstance(u.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return this._worksheet.getRowStyle(e,t)}getColumnDefaultStyle(e,t=!1){return this._worksheet.getColumnStyle(e,t)}async setDefaultStyle(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return await this._commandService.executeCommand(a.SetWorksheetDefaultStyleMutation.id,{unitId:t,subUnitId:n,defaultStyle:e}),this._worksheet.setDefaultCellStyle(e),this}async setColumnDefaultStyle(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s={unitId:n,subUnitId:i,columnData:{[e]:{s:t}}};return await this._commandService.executeCommand(a.SetColDataCommand.id,s),this}async setRowDefaultStyle(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s={unitId:n,subUnitId:i,rowData:{[e]:{s:t}}};return await this._commandService.executeCommand(a.SetRowDataCommand.id,s),this}getRange(e,t,n,i){let s,h;if(typeof e=="string"){const{range:c,sheetName:l}=f.deserializeRangeWithSheet(e),m=l?this._workbook.getSheetBySheetName(l):this._worksheet;if(!m)throw new Error("Range not found");h=m,s={...c,unitId:this._workbook.getUnitId(),sheetId:h.getSheetId(),rangeType:r.RANGE_TYPE.NORMAL,startRow:c.rangeType===r.RANGE_TYPE.COLUMN?0:c.startRow,endRow:c.rangeType===r.RANGE_TYPE.COLUMN?h.getMaxRows()-1:c.endRow,startColumn:c.rangeType===r.RANGE_TYPE.ROW?0:c.startColumn,endColumn:c.rangeType===r.RANGE_TYPE.ROW?h.getMaxColumns()-1:c.endColumn}}else if(typeof e=="number"&&t!==void 0)h=this._worksheet,s={startRow:e,endRow:e+(n!=null?n:1)-1,startColumn:t,endColumn:t+(i!=null?i:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(u.FRange,this._workbook,h,s)}getMaxColumns(){return this._worksheet.getMaxColumns()}getMaxRows(){return this._worksheet.getMaxRows()}async insertRowAfter(e){return this.insertRowsAfter(e,1)}async insertRowBefore(e){return this.insertRowsBefore(e,1)}async insertRows(e,t=1){return this.insertRowsBefore(e,t)}async insertRowsAfter(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s=r.Direction.DOWN,h=e+1,c=e+t,l=0,m=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,c,l,m,!0,e);return await this._commandService.executeCommand(a.InsertRowCommand.id,{unitId:n,subUnitId:i,direction:s,range:{startRow:h,endRow:c,startColumn:l,endColumn:m},cellValue:g}),this}async insertRowsBefore(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s=r.Direction.UP,h=e,c=e+t-1,l=0,m=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,c,l,m,!0,e-1);return await this._commandService.executeCommand(a.InsertRowCommand.id,{unitId:n,subUnitId:i,direction:s,range:{startRow:h,endRow:c,startColumn:l,endColumn:m},cellValue:g}),this}async deleteRow(e){return this.deleteRows(e,1)}async deleteRows(e,t){const n={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return await this._commandService.executeCommand(a.RemoveRowCommand.id,{range:n}),this}async moveRows(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s=k(e.getRange(),this._worksheet),h=s,c={startRow:t,endRow:t,startColumn:s.startColumn,endColumn:s.endColumn};return await this._commandService.executeCommand(a.MoveRowsCommand.id,{unitId:n,subUnitId:i,range:s,fromRange:h,toRange:c}),this}async hideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=k(e.getRange(),this._worksheet);return await this._commandService.executeCommand(a.SetRowHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}async hideRows(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:r.RANGE_TYPE.ROW};return await this._commandService.executeCommand(a.SetRowHiddenCommand.id,{unitId:n,subUnitId:i,ranges:[s]}),this}async unhideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=k(e.getRange(),this._worksheet);return await this._commandService.executeCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}async showRows(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:r.RANGE_TYPE.ROW};return await this._commandService.executeCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:n,subUnitId:i,ranges:[s]}),this}async setRowHeight(e,t){return this.setRowHeights(e,1,t)}async setRowHeights(e,t,n){var m;const i=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),h=this._worksheet.getRowManager(),c=[],l=[];for(let g=e;g<e+t;g++){const v=((m=h.getRow(g))==null?void 0:m.ah)||this._worksheet.getConfig().defaultRowHeight,y={startRow:g,endRow:g,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};n<=v?c.push(y):l.push(y)}return l.length>0&&await this._commandService.executeCommand(a.SetRowHeightCommand.id,{unitId:i,subUnitId:s,ranges:l,value:n}),c.length>0&&await this._commandService.executeCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:i,subUnitId:s,ranges:c}),this}async setRowHeightsForced(e,t,n){const i=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),h=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return await this._commandService.executeCommand(a.SetRowHeightCommand.id,{unitId:i,subUnitId:s,ranges:h,value:n}),this}async setRowCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i={};for(const[h,c]of Object.entries(e))i[Number(h)]={custom:c};const s={unitId:t,subUnitId:n,rowData:i};return await this._commandService.executeCommand(a.SetRowDataCommand.id,s),this}async insertColumnAfter(e){return this.insertColumnsAfter(e,1)}async insertColumnBefore(e){return this.insertColumnsBefore(e,1)}async insertColumns(e,t=1){return this.insertColumnsBefore(e,t)}async insertColumnsAfter(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s=r.Direction.RIGHT,h=0,c=this._worksheet.getRowCount()-1,l=e+1,m=e+t,g=a.copyRangeStyles(this._worksheet,h,c,l,m,!1,e);return await this._commandService.executeCommand(a.InsertColCommand.id,{unitId:n,subUnitId:i,direction:s,range:{startRow:h,endRow:c,startColumn:l,endColumn:m},cellValue:g}),this}async insertColumnsBefore(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s=r.Direction.LEFT,h=0,c=this._worksheet.getRowCount()-1,l=e,m=e+t-1,g=a.copyRangeStyles(this._worksheet,h,c,l,m,!1,e-1);return await this._commandService.executeCommand(a.InsertColCommand.id,{unitId:n,subUnitId:i,direction:s,range:{startRow:h,endRow:c,startColumn:l,endColumn:m},cellValue:g}),this}async deleteColumn(e){return this.deleteColumns(e,1)}async deleteColumns(e,t){const n={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1};return await this._commandService.executeCommand(a.RemoveColCommand.id,{range:n}),this}async moveColumns(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s=C(e.getRange(),this._worksheet),h=s,c={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return await this._commandService.executeCommand(a.MoveColsCommand.id,{unitId:n,subUnitId:i,range:s,fromRange:h,toRange:c}),this}async hideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=C(e.getRange(),this._worksheet);return await this._commandService.executeCommand(a.SetColHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}async hideColumns(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:r.RANGE_TYPE.COLUMN};return await this._commandService.executeCommand(a.SetColHiddenCommand.id,{unitId:n,subUnitId:i,ranges:[s]}),this}async unhideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=C(e.getRange(),this._worksheet);return await this._commandService.executeCommand(a.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}async showColumns(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:r.RANGE_TYPE.COLUMN};return await this._commandService.executeCommand(a.SetSpecificColsVisibleCommand.id,{unitId:n,subUnitId:i,ranges:[s]}),this}async setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}async setColumnWidths(e,t,n){const i=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),h=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return await this._commandService.executeCommand(a.SetColWidthCommand.id,{unitId:i,subUnitId:s,ranges:h,value:n}),this}async setColumnCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i={};for(const[h,c]of Object.entries(e))i[Number(h)]={custom:c};const s={unitId:t,subUnitId:n,columnData:i};return await this._commandService.executeCommand(a.SetColDataCommand.id,s),this}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(u.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const i=this._worksheet.getMergedCell(e,t);if(i)return this._injector.createInstance(u.FRange,this._workbook,this._worksheet,i)}getActiveRange(){return this._fWorkbook.getActiveRange()}setActiveRange(e){const{unitId:t,sheetId:n}=e.getRange();if(t!==this._workbook.getUnitId()||n!==this._worksheet.getSheetId())throw new Error("Specified range must be part of the sheet.");this._fWorkbook.setActiveRange(e)}setFreeze(e){return this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{...e,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}cancelFreeze(){return this._commandService.syncExecuteCommand(a.CancelFrozenCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}getFreeze(){return this._worksheet.getFreeze()}setFrozenColumns(e){const t=this.getFreeze();this.setFreeze({...t,startColumn:e>0?e:-1,xSplit:e})}setFrozenRows(e){const t=this.getFreeze();this.setFreeze({...t,startRow:e>0?e:-1,ySplit:e})}getFrozenColumns(){const e=this.getFreeze();return e.startColumn===-1?0:e.startColumn}getFrozenRows(){const e=this.getFreeze();return e.startRow===-1?0:e.startRow}hasHiddenGridLines(){return this._worksheet.getConfig().showGridlines===r.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.executeCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?r.BooleanNumber.FALSE:r.BooleanNumber.TRUE})}onCellDataChange(e){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const i=n.params;i.unitId===this._workbook.getUnitId()&&i.subUnitId===this._worksheet.getSheetId()&&i.cellValue&&e(new r.ObjectMatrix(i.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(r.ICommandService).beforeCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const i=n.params;i.unitId===this._workbook.getUnitId()&&i.subUnitId===this._worksheet.getSheetId()&&i.cellValue&&e(new r.ObjectMatrix(i.cellValue))}})}},u.FWorksheet=H([R(3,r.Inject(r.Injector)),R(4,r.Inject(a.SheetsSelectionsService)),R(5,r.ICommandService)],u.FWorksheet);var L=Object.defineProperty,$=Object.getOwnPropertyDescriptor,G=(d,o,e,t)=>{for(var n=t>1?void 0:t?$(o,e):o,i=d.length-1,s;i>=0;i--)(s=d[i])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&L(o,e,n),n},w=(d,o)=>(e,t)=>o(e,t,d);u.FWorkbook=class extends r.FBase{constructor(e,t,n,i,s,h,c,l){super();b(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=n,this._selectionManagerService=i,this._univerInstanceService=s,this._commandService=h,this._permissionService=c,this._logService=l,this.id=this._workbook.getUnitId()}getId(){return this.id}getName(){return this._workbook.getName()}save(){return this._resourceLoaderService.saveUnit(this._workbook.getUnitId())}getSnapshot(){return this._logService.warn("use 'save' instead of 'getSnapshot'"),this.save()}getActiveSheet(){const e=this._workbook.getActiveSheet();return this._injector.createInstance(u.FWorksheet,this,this._workbook,e)}getSheets(){return this._workbook.getSheets().map(e=>this._injector.createInstance(u.FWorksheet,this,this._workbook,e))}create(e,t,n){const i=r.mergeWorksheetSnapshotWithDefault({});i.rowCount=t,i.columnCount=n,i.name=e,i.id=e.toLowerCase().replace(/ /g,"-"),this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:this._workbook.getSheets().length,sheet:i}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId()});const s=this._workbook.getActiveSheet();if(!s)throw new Error("No active sheet found");return this._injector.createInstance(u.FWorksheet,this,this._workbook,s)}getSheetBySheetId(e){const t=this._workbook.getSheetBySheetId(e);return t?this._injector.createInstance(u.FWorksheet,this,this._workbook,t):null}getSheetByName(e){const t=this._workbook.getSheetBySheetName(e);return t?this._injector.createInstance(u.FWorksheet,this,this._workbook,t):null}setActiveSheet(e){return this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:e.getSheetId()}),e}insertSheet(){this._commandService.syncExecuteCommand(a.InsertSheetCommand.id);const e=this.id,t=this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId();this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:t});const n=this._workbook.getActiveSheet();if(!n)throw new Error("No active sheet found");return this._injector.createInstance(u.FWorksheet,this,this._workbook,n)}deleteSheet(e){const t=this.id,n=e.getSheetId();this._commandService.executeCommand(a.RemoveSheetCommand.id,{unitId:t,subUnitId:n})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(r.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(r.RedoCommand.id)}onBeforeCommandExecute(e){return this._commandService.beforeCommandExecuted(t=>{var n;((n=t.params)==null?void 0:n.unitId)===this.id&&e(t)})}onCommandExecuted(e){return this._commandService.onCommandExecuted(t=>{var n;((n=t.params)==null?void 0:n.unitId)===this.id&&e(t)})}onSelectionChange(e){return r.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET).getUnitId()===this.id&&(t!=null&&t.length?e(t.map(n=>n.range)):e([]))}))}setEditable(e){const t=new a.WorkbookEditablePermission(this._workbook.getUnitId());this._permissionService.getPermissionPoint(t.id)||this._permissionService.addPermissionPoint(t),this._permissionService.updatePermissionPoint(t.id,e)}setActiveRange(e){const t=this.getActiveSheet(),n=e.getRange().sheetId||t.getSheetId(),i=n?this._workbook.getSheetBySheetId(n):this._workbook.getActiveSheet(!0);if(!i)throw new Error("No active sheet found");i.getSheetId()!==t.getSheetId()&&this.setActiveSheet(this._injector.createInstance(u.FWorksheet,this,this._workbook,i));const s={unitId:this.getId(),subUnitId:n,selections:[e].map(h=>({range:h.getRange(),primary:a.getPrimaryForRange(h.getRange(),i),style:null}))};this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,s)}getActiveRange(){const e=this._workbook.getActiveSheet(),n=this._selectionManagerService.getCurrentSelections().find(i=>!!i.primary);return n?this._injector.createInstance(u.FRange,this._workbook,e,n.range):null}},u.FWorkbook=G([w(1,r.Inject(r.Injector)),w(2,r.Inject(r.IResourceLoaderService)),w(3,r.Inject(a.SheetsSelectionsService)),w(4,r.IUniverInstanceService),w(5,r.ICommandService),w(6,r.IPermissionService),w(7,r.ILogService)],u.FWorkbook);class Y extends r.FUniver{createUniverSheet(o){const t=this._injector.get(r.IUniverInstanceService).createUnit(r.UniverInstanceType.UNIVER_SHEET,o);return this._injector.createInstance(u.FWorkbook,t)}getActiveWorkbook(){const o=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);return o?this._injector.createInstance(u.FWorkbook,o):null}getPermission(){return this._injector.createInstance(u.FPermission)}}r.FUniver.extend(Y),Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|