@univerjs/sheets 0.21.0 → 0.21.1
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 +110 -88
- package/lib/cjs/index.js +161 -115
- package/lib/es/facade.js +113 -91
- package/lib/es/index.js +161 -116
- package/lib/facade.js +113 -91
- package/lib/index.js +161 -116
- package/lib/types/basics/defined-name-utils.d.ts +28 -0
- package/lib/types/commands/commands/clear-selection-all.command.d.ts +1 -1
- package/lib/types/commands/commands/clear-selection-content.command.d.ts +1 -1
- package/lib/types/commands/commands/clear-selection-format.command.d.ts +1 -1
- package/lib/types/commands/commands/set-defined-name.command.d.ts +2 -4
- package/lib/types/facade/f-defined-name.d.ts +30 -30
- package/lib/types/facade/f-univer.d.ts +0 -17
- package/lib/types/facade/f-workbook.d.ts +38 -26
- package/lib/types/facade/permission/f-range-protection-rule.d.ts +2 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/services/auto-fill/tools.d.ts +4 -6
- package/lib/types/skeleton/skeleton.service.d.ts +3 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +8 -8
package/lib/es/facade.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BooleanNumber, CanceledError, DEFAULT_STYLES, Dimension, Direction, HorizontalAlign, IAuthzIoService, ICommandService, ILogService, IPermissionService, IResourceLoaderService, IUniverInstanceService, Inject, Injector, LocaleService, ObjectMatrix,
|
|
1
|
+
import { BooleanNumber, CanceledError, DEFAULT_STYLES, Dimension, Direction, HorizontalAlign, IAuthzIoService, ICommandService, ILogService, IPermissionService, IResourceLoaderService, IUniverInstanceService, Inject, Injector, LocaleService, ObjectMatrix, RANGE_TYPE, Rectangle, RedoCommand, RichTextValue, TextStyleValue, Tools, UndoCommand, UniverInstanceType, VerticalAlign, WrapStrategy, cellToRange, covertCellValue, covertCellValues, generateIntervalsByPoints, generateRandomId, isNullCell, mergeWorksheetSnapshotWithDefault, toDisposable } from "@univerjs/core";
|
|
2
2
|
import { FBase, FBaseInitialable, FEnum, FEventName, FUniver } from "@univerjs/core/facade";
|
|
3
|
-
import { AddRangeProtectionMutation, AddWorksheetProtectionMutation, AppendRowCommand, AutoFillCommand, COMMAND_LISTENER_VALUE_CHANGE, CancelFrozenCommand, ClearSelectionAllCommand, ClearSelectionContentCommand, ClearSelectionFormatCommand, CopySheetCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeleteRangeProtectionMutation, DeleteWorksheetProtectionMutation, DeleteWorksheetRangeThemeStyleCommand, EditStateEnum, InsertColByRangeCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowByRangeCommand, InsertSheetCommand, MoveColsCommand, MoveRowsCommand, RangeProtectionPermissionDeleteProtectionPoint, RangeProtectionPermissionEditPoint, RangeProtectionPermissionManageCollaPoint, RangeProtectionPermissionViewPoint, RangeProtectionRuleModel, RangeThemeStyle, RegisterWorksheetRangeThemeStyleCommand, RemoveColByRangeCommand, RemoveDefinedNameCommand, RemoveRowByRangeCommand, RemoveSheetCommand, RemoveWorksheetMergeCommand, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetBorderBasicCommand, SetColDataCommand, SetColHiddenCommand, SetColWidthCommand, SetDefinedNameCommand, SetFrozenCommand, SetGridlinesColorCommand, SetHorizontalTextAlignCommand, SetRangeCustomMetadataCommand, SetRangeProtectionMutation, SetRangeValuesCommand, SetRangeValuesMutation, SetRowDataCommand, SetRowHeightCommand, SetRowHiddenCommand, SetSelectionsOperation, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetStyleCommand, SetTabColorCommand, SetTabColorMutation, SetTextRotationCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorkbookNameCommand, SetWorksheetActiveOperation, SetWorksheetColumnCountCommand, SetWorksheetDefaultStyleMutation, SetWorksheetHideCommand, SetWorksheetHideMutation, SetWorksheetNameCommand, SetWorksheetOrderCommand, SetWorksheetOrderMutation, SetWorksheetRangeThemeStyleCommand, SetWorksheetRowCountCommand, SetWorksheetRowIsAutoHeightCommand, SetWorksheetRowIsAutoHeightMutation, SetWorksheetShowCommand, SheetRangeThemeService, SheetSkeletonChangeType, SheetValueChangeType, SheetsFreezeSyncController, SheetsSelectionsService, SplitDelimiterEnum, SplitTextToColumnsCommand, ToggleGridlinesCommand, UnitObject, UnregisterWorksheetRangeThemeStyleCommand, ViewStateEnum, WorkbookCommentPermission, WorkbookCopyPermission, WorkbookCopySheetPermission, WorkbookCreateProtectPermission, WorkbookCreateSheetPermission, WorkbookDeleteColumnPermission, WorkbookDeleteRowPermission, WorkbookDeleteSheetPermission, WorkbookDuplicatePermission, WorkbookEditablePermission, WorkbookExportPermission, WorkbookHideSheetPermission, WorkbookInsertColumnPermission, WorkbookInsertRowPermission, WorkbookManageCollaboratorPermission, WorkbookMoveSheetPermission, WorkbookPrintPermission, WorkbookRecoverHistoryPermission, WorkbookRenameSheetPermission, WorkbookSharePermission, WorkbookViewHistoryPermission, WorkbookViewPermission, WorksheetCopyPermission, WorksheetDeleteColumnPermission, WorksheetDeleteProtectionPermission, WorksheetDeleteRowPermission, WorksheetEditExtraObjectPermission, WorksheetEditPermission, WorksheetFilterPermission, WorksheetInsertColumnPermission, WorksheetInsertHyperlinkPermission, WorksheetInsertRowPermission, WorksheetManageCollaboratorPermission, WorksheetPivotTablePermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetSelectProtectedCellsPermission, WorksheetSelectUnProtectedCellsPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission, WorksheetSetColumnStylePermission, WorksheetSetRowStylePermission, WorksheetSortPermission, WorksheetViewPermission, addMergeCellsUtil, copyRangeStyles, getAddMergeMutationRangeByType, getAllWorksheetPermissionPoint, getAllWorksheetPermissionPointByPointPanel, getNextPrimaryCell, getPrimaryForRange, getValueChangedEffectedRange } from "@univerjs/sheets";
|
|
4
|
-
import { FormulaDataModel, IDefinedNamesService, deserializeRangeWithSheet, serializeRange, serializeRangeWithSheet } from "@univerjs/engine-formula";
|
|
3
|
+
import { AddRangeProtectionMutation, AddWorksheetProtectionMutation, AppendRowCommand, AutoFillCommand, COMMAND_LISTENER_VALUE_CHANGE, CancelFrozenCommand, ClearSelectionAllCommand, ClearSelectionContentCommand, ClearSelectionFormatCommand, CopySheetCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeleteRangeProtectionMutation, DeleteWorksheetProtectionMutation, DeleteWorksheetRangeThemeStyleCommand, EditStateEnum, InsertColByRangeCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowByRangeCommand, InsertSheetCommand, MoveColsCommand, MoveRowsCommand, RangeProtectionPermissionDeleteProtectionPoint, RangeProtectionPermissionEditPoint, RangeProtectionPermissionManageCollaPoint, RangeProtectionPermissionViewPoint, RangeProtectionRuleModel, RangeThemeStyle, RegisterWorksheetRangeThemeStyleCommand, RemoveColByRangeCommand, RemoveDefinedNameCommand, RemoveRowByRangeCommand, RemoveSheetCommand, RemoveWorksheetMergeCommand, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetBorderBasicCommand, SetColDataCommand, SetColHiddenCommand, SetColWidthCommand, SetDefinedNameCommand, SetFrozenCommand, SetGridlinesColorCommand, SetHorizontalTextAlignCommand, SetRangeCustomMetadataCommand, SetRangeProtectionMutation, SetRangeValuesCommand, SetRangeValuesMutation, SetRowDataCommand, SetRowHeightCommand, SetRowHiddenCommand, SetSelectionsOperation, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetStyleCommand, SetTabColorCommand, SetTabColorMutation, SetTextRotationCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorkbookNameCommand, SetWorksheetActiveOperation, SetWorksheetColumnCountCommand, SetWorksheetDefaultStyleMutation, SetWorksheetHideCommand, SetWorksheetHideMutation, SetWorksheetNameCommand, SetWorksheetOrderCommand, SetWorksheetOrderMutation, SetWorksheetRangeThemeStyleCommand, SetWorksheetRowCountCommand, SetWorksheetRowIsAutoHeightCommand, SetWorksheetRowIsAutoHeightMutation, SetWorksheetShowCommand, SheetRangeThemeService, SheetSkeletonChangeType, SheetValueChangeType, SheetsFreezeSyncController, SheetsSelectionsService, SplitDelimiterEnum, SplitTextToColumnsCommand, ToggleGridlinesCommand, UnitObject, UnregisterWorksheetRangeThemeStyleCommand, ViewStateEnum, WorkbookCommentPermission, WorkbookCopyPermission, WorkbookCopySheetPermission, WorkbookCreateProtectPermission, WorkbookCreateSheetPermission, WorkbookDeleteColumnPermission, WorkbookDeleteRowPermission, WorkbookDeleteSheetPermission, WorkbookDuplicatePermission, WorkbookEditablePermission, WorkbookExportPermission, WorkbookHideSheetPermission, WorkbookInsertColumnPermission, WorkbookInsertRowPermission, WorkbookManageCollaboratorPermission, WorkbookMoveSheetPermission, WorkbookPrintPermission, WorkbookRecoverHistoryPermission, WorkbookRenameSheetPermission, WorkbookSharePermission, WorkbookViewHistoryPermission, WorkbookViewPermission, WorksheetCopyPermission, WorksheetDeleteColumnPermission, WorksheetDeleteProtectionPermission, WorksheetDeleteRowPermission, WorksheetEditExtraObjectPermission, WorksheetEditPermission, WorksheetFilterPermission, WorksheetInsertColumnPermission, WorksheetInsertHyperlinkPermission, WorksheetInsertRowPermission, WorksheetManageCollaboratorPermission, WorksheetPivotTablePermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetSelectProtectedCellsPermission, WorksheetSelectUnProtectedCellsPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission, WorksheetSetColumnStylePermission, WorksheetSetRowStylePermission, WorksheetSortPermission, WorksheetViewPermission, addMergeCellsUtil, copyRangeStyles, getAddMergeMutationRangeByType, getAllWorksheetPermissionPoint, getAllWorksheetPermissionPointByPointPanel, getNextPrimaryCell, getPrimaryForRange, getValueChangedEffectedRange, validateDefinedName } from "@univerjs/sheets";
|
|
4
|
+
import { FormulaDataModel, IDefinedNamesService, IFunctionService, ISuperTableService, deserializeRangeWithSheet, serializeRange, serializeRangeWithSheet } from "@univerjs/engine-formula";
|
|
5
5
|
import { ObjectScope, UnitAction, UnitObject as UnitObject$1, UnitRole } from "@univerjs/protocol";
|
|
6
6
|
|
|
7
7
|
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
@@ -84,15 +84,14 @@ function getDefinedNameFieldName(unitId, localeService, definedNamesService) {
|
|
|
84
84
|
i++;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
constructor() {
|
|
87
|
+
let FDefinedNameBuilder = class FDefinedNameBuilder {
|
|
88
|
+
constructor(unitId, _injector) {
|
|
89
|
+
this.unitId = unitId;
|
|
90
|
+
this._injector = _injector;
|
|
92
91
|
_defineProperty(this, "_definedNameParam", void 0);
|
|
93
92
|
this._definedNameParam = {
|
|
94
93
|
id: generateRandomId(10),
|
|
95
|
-
unitId
|
|
94
|
+
unitId,
|
|
96
95
|
name: "",
|
|
97
96
|
formulaOrRefString: "",
|
|
98
97
|
localSheetId: SCOPE_WORKBOOK_VALUE_DEFINED_NAME
|
|
@@ -105,11 +104,11 @@ var FDefinedNameBuilder = class {
|
|
|
105
104
|
* @example
|
|
106
105
|
* ```ts
|
|
107
106
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
108
|
-
* const
|
|
107
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
109
108
|
* .setName('MyDefinedName')
|
|
110
109
|
* .setRef('Sheet1!$A$1')
|
|
111
110
|
* .build();
|
|
112
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
111
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
113
112
|
* ```
|
|
114
113
|
*/
|
|
115
114
|
setName(name) {
|
|
@@ -123,11 +122,11 @@ var FDefinedNameBuilder = class {
|
|
|
123
122
|
* @example
|
|
124
123
|
* ```ts
|
|
125
124
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
126
|
-
* const
|
|
125
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
127
126
|
* .setName('MyDefinedName')
|
|
128
127
|
* .setFormula('SUM(Sheet1!$A$1)')
|
|
129
128
|
* .build();
|
|
130
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
129
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
131
130
|
* ```
|
|
132
131
|
*/
|
|
133
132
|
setFormula(formula) {
|
|
@@ -141,11 +140,11 @@ var FDefinedNameBuilder = class {
|
|
|
141
140
|
* @example
|
|
142
141
|
* ```ts
|
|
143
142
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
144
|
-
* const
|
|
143
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
145
144
|
* .setName('MyDefinedName')
|
|
146
145
|
* .setRef('Sheet1!$A$1')
|
|
147
146
|
* .build();
|
|
148
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
147
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
149
148
|
* ```
|
|
150
149
|
*/
|
|
151
150
|
setRef(a1Notation) {
|
|
@@ -162,11 +161,11 @@ var FDefinedNameBuilder = class {
|
|
|
162
161
|
* @example
|
|
163
162
|
* ```ts
|
|
164
163
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
165
|
-
* const
|
|
164
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
166
165
|
* .setName('MyDefinedName')
|
|
167
166
|
* .setRefByRange(1, 3, 2, 5) // D2:H3
|
|
168
167
|
* .build();
|
|
169
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
168
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
170
169
|
* ```
|
|
171
170
|
*/
|
|
172
171
|
setRefByRange(row, column, numRows, numColumns) {
|
|
@@ -185,12 +184,12 @@ var FDefinedNameBuilder = class {
|
|
|
185
184
|
* @example
|
|
186
185
|
* ```ts
|
|
187
186
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
188
|
-
* const
|
|
187
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
189
188
|
* .setName('MyDefinedName')
|
|
190
189
|
* .setRef('Sheet1!$A$1')
|
|
191
190
|
* .setComment('A reference to A1 cell in Sheet1')
|
|
192
191
|
* .build();
|
|
193
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
192
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
194
193
|
* ```
|
|
195
194
|
*/
|
|
196
195
|
setComment(comment) {
|
|
@@ -207,12 +206,12 @@ var FDefinedNameBuilder = class {
|
|
|
207
206
|
* const sheets = fWorkbook.getSheets();
|
|
208
207
|
*
|
|
209
208
|
* // Create a defined name and make it available only in the second worksheet
|
|
210
|
-
* const
|
|
209
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
211
210
|
* .setName('MyDefinedName')
|
|
212
211
|
* .setRef('Sheet1!$A$1')
|
|
213
212
|
* .setScopeToWorksheet(sheets[1])
|
|
214
213
|
* .build();
|
|
215
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
214
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
216
215
|
* ```
|
|
217
216
|
*/
|
|
218
217
|
setScopeToWorksheet(worksheet) {
|
|
@@ -227,12 +226,12 @@ var FDefinedNameBuilder = class {
|
|
|
227
226
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
228
227
|
*
|
|
229
228
|
* // Create a defined name and make it available in the entire workbook
|
|
230
|
-
* const
|
|
229
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
231
230
|
* .setName('MyDefinedName')
|
|
232
231
|
* .setRef('Sheet1!$A$1')
|
|
233
232
|
* .setScopeToWorkbook()
|
|
234
233
|
* .build();
|
|
235
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
234
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
236
235
|
* ```
|
|
237
236
|
*/
|
|
238
237
|
setScopeToWorkbook() {
|
|
@@ -246,12 +245,12 @@ var FDefinedNameBuilder = class {
|
|
|
246
245
|
* @example
|
|
247
246
|
* ```ts
|
|
248
247
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
249
|
-
* const
|
|
248
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
250
249
|
* .setName('MyDefinedName')
|
|
251
250
|
* .setRef('Sheet1!$A$1')
|
|
252
251
|
* .setHidden(true)
|
|
253
252
|
* .build();
|
|
254
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
253
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
255
254
|
* ```
|
|
256
255
|
*/
|
|
257
256
|
setHidden(hidden) {
|
|
@@ -264,15 +263,26 @@ var FDefinedNameBuilder = class {
|
|
|
264
263
|
* @example
|
|
265
264
|
* ```ts
|
|
266
265
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
267
|
-
* const
|
|
266
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
268
267
|
* .setName('MyDefinedName')
|
|
269
268
|
* .setRef('Sheet1!$A$1')
|
|
270
269
|
* .setComment('A reference to A1 cell in Sheet1')
|
|
271
270
|
* .build();
|
|
272
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
271
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
273
272
|
* ```
|
|
274
273
|
*/
|
|
275
274
|
build() {
|
|
275
|
+
const { unitId, name, formulaOrRefString, id } = this._definedNameParam;
|
|
276
|
+
const validationResult = validateDefinedName(name, {
|
|
277
|
+
unitId,
|
|
278
|
+
formulaOrRefString,
|
|
279
|
+
univerInstanceService: this._injector.get(IUniverInstanceService),
|
|
280
|
+
definedNamesService: this._injector.get(IDefinedNamesService),
|
|
281
|
+
superTableService: this._injector.get(ISuperTableService),
|
|
282
|
+
functionService: this._injector.get(IFunctionService),
|
|
283
|
+
id
|
|
284
|
+
});
|
|
285
|
+
if (typeof validationResult === "string") throw new TypeError(this._injector.get(LocaleService).t(validationResult));
|
|
276
286
|
return this._definedNameParam;
|
|
277
287
|
}
|
|
278
288
|
/**
|
|
@@ -282,23 +292,25 @@ var FDefinedNameBuilder = class {
|
|
|
282
292
|
* @example
|
|
283
293
|
* ```ts
|
|
284
294
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
285
|
-
* const definedNameParam =
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
* const definedNameBuilder = univerAPI.newDefinedName()
|
|
292
|
-
* .load(definedNameParam)
|
|
295
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
296
|
+
* .load({
|
|
297
|
+
* id: '4TMPceoqg8',
|
|
298
|
+
* name: 'MyDefinedName',
|
|
299
|
+
* formulaOrRefString: 'Sheet1!$A$1',
|
|
300
|
+
* })
|
|
293
301
|
* .build();
|
|
294
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
302
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
295
303
|
* ```
|
|
296
304
|
*/
|
|
297
305
|
load(param) {
|
|
298
|
-
this._definedNameParam =
|
|
306
|
+
this._definedNameParam = {
|
|
307
|
+
...this._definedNameParam,
|
|
308
|
+
...param
|
|
309
|
+
};
|
|
299
310
|
return this;
|
|
300
311
|
}
|
|
301
312
|
};
|
|
313
|
+
FDefinedNameBuilder = __decorate([__decorateParam(1, Inject(Injector))], FDefinedNameBuilder);
|
|
302
314
|
let FDefinedName = class FDefinedName extends FBase {
|
|
303
315
|
constructor(_definedNameParam, _injector, _commandService, _permissionService, _worksheetProtectionRuleModel, _rangeProtectionRuleModel, _worksheetProtectionPointRuleModel, _authzIoService, _localeService, _definedNamesService) {
|
|
304
316
|
super();
|
|
@@ -524,15 +536,16 @@ let FDefinedName = class FDefinedName extends FBase {
|
|
|
524
536
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
525
537
|
* const definedName = fWorkbook.getDefinedNames()[0];
|
|
526
538
|
* if (!definedName) return;
|
|
527
|
-
* const
|
|
539
|
+
* const definedNameParam = definedName
|
|
528
540
|
* .toBuilder()
|
|
529
541
|
* .setName('NewDefinedName')
|
|
530
542
|
* .setFormula('SUM(Sheet1!$A$1)')
|
|
531
543
|
* .build();
|
|
532
|
-
* fWorkbook.updateDefinedNameBuilder(
|
|
544
|
+
* fWorkbook.updateDefinedNameBuilder(definedNameParam);
|
|
533
545
|
* ```
|
|
534
546
|
*/
|
|
535
547
|
toBuilder() {
|
|
548
|
+
if (!this._definedNameParam.unitId) throw new Error("unitId is required to convert to FDefinedNameBuilder");
|
|
536
549
|
const builder = this._injector.createInstance(FDefinedNameBuilder);
|
|
537
550
|
builder.load(this._definedNameParam);
|
|
538
551
|
return builder;
|
|
@@ -944,7 +957,7 @@ function determineScope(editState, viewState) {
|
|
|
944
957
|
function handleWorksheetRangePermissionIsEmpty(injector, unitId, subUnitId) {
|
|
945
958
|
const rangeProtectionRuleModel = injector.get(RangeProtectionRuleModel);
|
|
946
959
|
const worksheetProtectionPointModel = injector.get(WorksheetProtectionPointModel);
|
|
947
|
-
const permissionService = injector.get(
|
|
960
|
+
const permissionService = injector.get(IPermissionService);
|
|
948
961
|
if (rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId).length > 0) return;
|
|
949
962
|
worksheetProtectionPointModel.deleteRule(unitId, subUnitId);
|
|
950
963
|
[...getAllWorksheetPermissionPointByPointPanel()].forEach((F) => {
|
|
@@ -993,7 +1006,7 @@ async function getListRangeProtectionRules(injector, unitId, subUnitId, options)
|
|
|
993
1006
|
//#endregion
|
|
994
1007
|
//#region src/facade/permission/f-range-protection-rule.ts
|
|
995
1008
|
let FRangeProtectionRule = class FRangeProtectionRule {
|
|
996
|
-
constructor(_unitId, _subUnitId, _ruleId, _permissionId, _ranges, _options, _injector,
|
|
1009
|
+
constructor(_unitId, _subUnitId, _ruleId, _permissionId, _ranges, _options, _injector, _permissionService, _authzIoService, _commandService, _rangeProtectionRuleModel) {
|
|
997
1010
|
this._unitId = _unitId;
|
|
998
1011
|
this._subUnitId = _subUnitId;
|
|
999
1012
|
this._ruleId = _ruleId;
|
|
@@ -1001,9 +1014,9 @@ let FRangeProtectionRule = class FRangeProtectionRule {
|
|
|
1001
1014
|
this._ranges = _ranges;
|
|
1002
1015
|
this._options = _options;
|
|
1003
1016
|
this._injector = _injector;
|
|
1004
|
-
this._commandService = _commandService;
|
|
1005
1017
|
this._permissionService = _permissionService;
|
|
1006
1018
|
this._authzIoService = _authzIoService;
|
|
1019
|
+
this._commandService = _commandService;
|
|
1007
1020
|
this._rangeProtectionRuleModel = _rangeProtectionRuleModel;
|
|
1008
1021
|
}
|
|
1009
1022
|
/**
|
|
@@ -1269,9 +1282,9 @@ let FRangeProtectionRule = class FRangeProtectionRule {
|
|
|
1269
1282
|
};
|
|
1270
1283
|
FRangeProtectionRule = __decorate([
|
|
1271
1284
|
__decorateParam(6, Inject(Injector)),
|
|
1272
|
-
__decorateParam(7,
|
|
1273
|
-
__decorateParam(8,
|
|
1274
|
-
__decorateParam(9,
|
|
1285
|
+
__decorateParam(7, IPermissionService),
|
|
1286
|
+
__decorateParam(8, IAuthzIoService),
|
|
1287
|
+
__decorateParam(9, ICommandService),
|
|
1275
1288
|
__decorateParam(10, Inject(RangeProtectionRuleModel))
|
|
1276
1289
|
], FRangeProtectionRule);
|
|
1277
1290
|
|
|
@@ -3900,9 +3913,8 @@ let FWorksheet = _FWorksheet = class FWorksheet extends FBaseInitialable {
|
|
|
3900
3913
|
* ```
|
|
3901
3914
|
*/
|
|
3902
3915
|
insertDefinedName(name, formulaOrRefString) {
|
|
3903
|
-
const
|
|
3904
|
-
|
|
3905
|
-
this._fWorkbook.insertDefinedNameBuilder(param);
|
|
3916
|
+
const definedNameParam = this._injector.createInstance(FDefinedNameBuilder, this._fWorkbook.getId()).setName(name).setRef(formulaOrRefString).setScopeToWorksheet(this).build();
|
|
3917
|
+
this._fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
3906
3918
|
}
|
|
3907
3919
|
/**
|
|
3908
3920
|
* Get all the defined names in the worksheet.
|
|
@@ -7509,10 +7521,6 @@ let FWorkbook = class FWorkbook extends FBaseInitialable {
|
|
|
7509
7521
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
7510
7522
|
* const definedName = fWorkbook.getDefinedName('MyDefinedName');
|
|
7511
7523
|
* console.log(definedName?.getFormulaOrRefString());
|
|
7512
|
-
*
|
|
7513
|
-
* if (definedName) {
|
|
7514
|
-
* definedName.setName('NewDefinedName');
|
|
7515
|
-
* }
|
|
7516
7524
|
* ```
|
|
7517
7525
|
*/
|
|
7518
7526
|
getDefinedName(name) {
|
|
@@ -7545,41 +7553,22 @@ let FWorkbook = class FWorkbook extends FBaseInitialable {
|
|
|
7545
7553
|
});
|
|
7546
7554
|
}
|
|
7547
7555
|
/**
|
|
7548
|
-
*
|
|
7549
|
-
* @
|
|
7550
|
-
* @param {string} formulaOrRefString The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
|
|
7551
|
-
* @returns {FWorkbook} The current FWorkbook instance
|
|
7556
|
+
* Create a new defined name builder.
|
|
7557
|
+
* @returns {FDefinedNameBuilder} - The defined name builder.
|
|
7552
7558
|
* @example
|
|
7553
7559
|
* ```ts
|
|
7554
|
-
* // The code below inserts a defined name
|
|
7555
7560
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
7556
|
-
* fWorkbook.
|
|
7561
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
7562
|
+
* .setRef('Sheet1!$A$1')
|
|
7563
|
+
* .setName('MyDefinedName')
|
|
7564
|
+
* .setComment('This is a comment');
|
|
7565
|
+
* .build();
|
|
7566
|
+
* console.log(definedNameParam);
|
|
7567
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
7557
7568
|
* ```
|
|
7558
7569
|
*/
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
param.localSheetId = SCOPE_WORKBOOK_VALUE_DEFINED_NAME;
|
|
7562
|
-
this.insertDefinedNameBuilder(param);
|
|
7563
|
-
return this;
|
|
7564
|
-
}
|
|
7565
|
-
/**
|
|
7566
|
-
* Delete the defined name with the given name.
|
|
7567
|
-
* @param {string} name The name of the defined name to delete
|
|
7568
|
-
* @returns {boolean} true if the defined name was deleted, false otherwise
|
|
7569
|
-
* @example
|
|
7570
|
-
* ```ts
|
|
7571
|
-
* // The code below deletes the defined name with the given name
|
|
7572
|
-
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
7573
|
-
* fWorkbook.deleteDefinedName('MyDefinedName');
|
|
7574
|
-
* ```
|
|
7575
|
-
*/
|
|
7576
|
-
deleteDefinedName(name) {
|
|
7577
|
-
const definedName = this.getDefinedName(name);
|
|
7578
|
-
if (definedName) {
|
|
7579
|
-
definedName.delete();
|
|
7580
|
-
return true;
|
|
7581
|
-
}
|
|
7582
|
-
return false;
|
|
7570
|
+
newDefinedNameBuilder() {
|
|
7571
|
+
return this._injector.createInstance(FDefinedNameBuilder, this.id);
|
|
7583
7572
|
}
|
|
7584
7573
|
/**
|
|
7585
7574
|
* Insert a defined name by builder param.
|
|
@@ -7589,16 +7578,15 @@ let FWorkbook = class FWorkbook extends FBaseInitialable {
|
|
|
7589
7578
|
* ```ts
|
|
7590
7579
|
* // The code below inserts a defined name by builder param
|
|
7591
7580
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
7592
|
-
* const
|
|
7581
|
+
* const definedNameParam = fWorkbook.newDefinedNameBuilder()
|
|
7593
7582
|
* .setRef('Sheet1!$A$1')
|
|
7594
7583
|
* .setName('MyDefinedName')
|
|
7595
7584
|
* .setComment('This is a comment')
|
|
7596
7585
|
* .build();
|
|
7597
|
-
* fWorkbook.insertDefinedNameBuilder(
|
|
7586
|
+
* fWorkbook.insertDefinedNameBuilder(definedNameParam);
|
|
7598
7587
|
* ```
|
|
7599
7588
|
*/
|
|
7600
7589
|
insertDefinedNameBuilder(param) {
|
|
7601
|
-
param.unitId = this.getId();
|
|
7602
7590
|
this._commandService.syncExecuteCommand(SetDefinedNameCommand.id, param);
|
|
7603
7591
|
}
|
|
7604
7592
|
/**
|
|
@@ -7626,6 +7614,42 @@ let FWorkbook = class FWorkbook extends FBaseInitialable {
|
|
|
7626
7614
|
this._commandService.syncExecuteCommand(SetDefinedNameCommand.id, param);
|
|
7627
7615
|
}
|
|
7628
7616
|
/**
|
|
7617
|
+
* Insert a defined name.
|
|
7618
|
+
* @param {string} name The name of the defined name to insert
|
|
7619
|
+
* @param {string} formulaOrRefString The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
|
|
7620
|
+
* @returns {FWorkbook} The current FWorkbook instance
|
|
7621
|
+
* @example
|
|
7622
|
+
* ```ts
|
|
7623
|
+
* // The code below inserts a defined name
|
|
7624
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
7625
|
+
* fWorkbook.insertDefinedName('MyDefinedName', 'Sheet1!$A$1');
|
|
7626
|
+
* ```
|
|
7627
|
+
*/
|
|
7628
|
+
insertDefinedName(name, formulaOrRefString) {
|
|
7629
|
+
const definedNameParam = this.newDefinedNameBuilder().setName(name).setRef(formulaOrRefString).setScopeToWorkbook().build();
|
|
7630
|
+
this.insertDefinedNameBuilder(definedNameParam);
|
|
7631
|
+
return this;
|
|
7632
|
+
}
|
|
7633
|
+
/**
|
|
7634
|
+
* Delete the defined name with the given name.
|
|
7635
|
+
* @param {string} name The name of the defined name to delete
|
|
7636
|
+
* @returns {boolean} true if the defined name was deleted, false otherwise
|
|
7637
|
+
* @example
|
|
7638
|
+
* ```ts
|
|
7639
|
+
* // The code below deletes the defined name with the given name
|
|
7640
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
7641
|
+
* fWorkbook.deleteDefinedName('MyDefinedName');
|
|
7642
|
+
* ```
|
|
7643
|
+
*/
|
|
7644
|
+
deleteDefinedName(name) {
|
|
7645
|
+
const definedName = this.getDefinedName(name);
|
|
7646
|
+
if (definedName) {
|
|
7647
|
+
definedName.delete();
|
|
7648
|
+
return true;
|
|
7649
|
+
}
|
|
7650
|
+
return false;
|
|
7651
|
+
}
|
|
7652
|
+
/**
|
|
7629
7653
|
* Gets the registered range themes.
|
|
7630
7654
|
* @returns {string[]} The name list of registered range themes.
|
|
7631
7655
|
* @example
|
|
@@ -7853,7 +7877,8 @@ var FUniverSheetsMixin = class extends FUniver {
|
|
|
7853
7877
|
this.fireEvent(this.Event.WorkbookDisposed, eventParams);
|
|
7854
7878
|
}
|
|
7855
7879
|
})));
|
|
7856
|
-
this.disposeWithMe(this.registerEventHandler(this.Event.WorkbookCreated, () => univerInstanceService.unitAdded$.subscribe((
|
|
7880
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.WorkbookCreated, () => univerInstanceService.unitAdded$.subscribe((event) => {
|
|
7881
|
+
const { unit } = event;
|
|
7857
7882
|
if (unit.type === UniverInstanceType.UNIVER_SHEET) {
|
|
7858
7883
|
const workbook = unit;
|
|
7859
7884
|
const workbookUnit = injector.createInstance(FWorkbook, workbook);
|
|
@@ -8154,13 +8179,10 @@ var FUniverSheetsMixin = class extends FUniver {
|
|
|
8154
8179
|
return this.getUniverSheet(id);
|
|
8155
8180
|
}
|
|
8156
8181
|
onUniverSheetCreated(callback) {
|
|
8157
|
-
return toDisposable(this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_SHEET).subscribe((
|
|
8158
|
-
callback(this._injector.createInstance(FWorkbook,
|
|
8182
|
+
return toDisposable(this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_SHEET).subscribe((event) => {
|
|
8183
|
+
callback(this._injector.createInstance(FWorkbook, event.unit));
|
|
8159
8184
|
}));
|
|
8160
8185
|
}
|
|
8161
|
-
newDefinedName() {
|
|
8162
|
-
return this._injector.createInstance(FDefinedNameBuilder);
|
|
8163
|
-
}
|
|
8164
8186
|
getActiveSheet() {
|
|
8165
8187
|
const workbook = this.getActiveWorkbook();
|
|
8166
8188
|
if (!workbook) return null;
|