@univerjs/sheets 1.1.0 → 1.3.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/index.js +349 -178
- package/lib/es/index.js +350 -179
- package/lib/index.js +350 -179
- package/lib/types/controllers/auto-fill.controller.d.ts +3 -0
- package/lib/types/controllers/permission/sheet-permission-check.controller.d.ts +10 -4
- package/lib/types/models/range-theme-model.d.ts +4 -2
- package/lib/types/services/auto-fill/auto-fill.service.d.ts +3 -3
- package/lib/types/services/auto-fill/type.d.ts +8 -1
- package/lib/umd/index.js +2 -2
- package/package.json +9 -9
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AUTO_HEIGHT_FOR_MERGED_CELLS, BORDER_KEYS, BORDER_STYLE_KEYS, BooleanNumber, BorderStyleTypes, BorderType, BuildTextUtils, COLOR_STYLE_KEYS, CellModeEnum, CellValueType, CommandType, CustomCommandExecutionError, DependentOn, Dimension, Direction, Disposable, DisposableCollection, DocumentDataModel, ErrorService, FontItalic, FontWeight, HorizontalAlign, IAuthzIoService, ICommandService, IConfigService, IConfirmService, IContextService, ILogService, IPermissionService, IResourceManagerService, IS_ROW_STYLE_PRECEDE_COLUMN_STYLE, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, InterceptorManager, LRUMap, LocaleService, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, PADDING_KEYS, PermissionStatus, Plugin, RANGE_TYPE, RTree, Range, Rectangle, RxDisposable, SHEET_TEXT_LINE_GAP, STYLE_KEYS, Styles, TEXT_DECORATION_KEYS, TEXT_ROTATION_KEYS, TextX, Tools, UniverInstanceType, UserManagerService, WorksheetHiddenState, WrapStrategy, cellToRange, cloneWorksheetData, composeInterceptors, concatMatrixArray, createIdentifier, createInterceptorKey, createRowColIter, generateRandomId, getArrayLength, getIntersectRange, getNumfmtLocaleTag, getNumfmtParseValueFilter, isBooleanString, isDefaultFormat, isFormulaId, isFormulaString, isICellData, isRealNum, isSafeNumeric, isTextFormat, mapObjectMatrix, merge, mergeIntervals, mergeOverrideWithDependencies, mergeWorksheetSnapshotWithDefault, moveMatrixArray, normalizeTextRuns, normalizeWorkbookCalculationSettings, numfmt, regexp, registerDependencies, remove, selectionToArray, sequenceExecute, sliceMatrixArray, spliceArray, throttle, toDisposable, touchDependencies, willLoseNumericPrecision } from "@univerjs/core";
|
|
1
|
+
import { AUTO_HEIGHT_FOR_MERGED_CELLS, BORDER_KEYS, BORDER_STYLE_KEYS, BooleanNumber, BorderStyleTypes, BorderType, BuildTextUtils, COLOR_STYLE_KEYS, CellModeEnum, CellValueType, CommandType, CustomCommandExecutionError, DependentOn, Dimension, Direction, Disposable, DisposableCollection, DocumentDataModel, ErrorService, FontItalic, FontWeight, HorizontalAlign, IAuthzIoService, ICommandService, IConfigService, IConfirmService, IContextService, ILogService, IPermissionService, IResourceManagerService, IS_ROW_STYLE_PRECEDE_COLUMN_STYLE, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, InterceptorManager, LRUMap, LocaleService, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, PADDING_KEYS, PermissionStatus, Plugin, RANGE_TYPE, RTree, Range, Rectangle, RxDisposable, SHEET_TEXT_LINE_GAP, STYLE_KEYS, Styles, TEXT_DECORATION_KEYS, TEXT_ROTATION_KEYS, TextX, Tools, UniverInstanceType, UserManagerService, WorksheetHiddenState, WrapStrategy, cellToRange, cloneWorksheetData, composeInterceptors, concatMatrixArray, createIdentifier, createInterceptorKey, createRowColIter, generateRandomId, getArrayLength, getIntersectRange, getNumfmtLocaleTag, getNumfmtParseValueFilter, isBooleanString, isDefaultFormat, isFormulaId, isFormulaString, isICellData, isRealNum, isSafeNumeric, isTextFormat, isValidColumnDimensions, isValidRowDimensions, isValidSheetDimension, mapObjectMatrix, merge, mergeIntervals, mergeOverrideWithDependencies, mergeWorksheetSnapshotWithDefault, moveMatrixArray, moveRangeByOffset, normalizeTextRuns, normalizeWorkbookCalculationSettings, numfmt, regexp, registerDependencies, remove, selectionToArray, sequenceExecute, sliceMatrixArray, spliceArray, throttle, toDisposable, touchDependencies, willLoseNumericPrecision } from "@univerjs/core";
|
|
2
|
+
import { FormulaDataModel, IDefinedNamesService, IFunctionService, ISheetRowFilteredService, LexerTreeBuilder, RemoveDefinedNameMutation, SetDefinedNameMutation, SetDefinedNameMutationFactory, SetFormulaCalculationResultMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheetWithCache, handleNumfmtInCell, handleRefStringInfo, isReferenceStringWithEffectiveColumn, matchToken, normalizeFormulaUnitName, operatorToken, sequenceNodeType, stripErrorMargin } from "@univerjs/engine-formula";
|
|
2
3
|
import { BehaviorSubject, Subject, distinctUntilChanged, filter, map, merge as merge$1, of, share, shareReplay, skip, switchMap, take, takeUntil } from "rxjs";
|
|
3
|
-
import { IDefinedNamesService, LexerTreeBuilder, RemoveDefinedNameMutation, SetDefinedNameMutation, SetDefinedNameMutationFactory, SetFormulaCalculationResultMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, handleNumfmtInCell, isReferenceStringWithEffectiveColumn, operatorToken, sequenceNodeType, stripErrorMargin } from "@univerjs/engine-formula";
|
|
4
4
|
import { SpreadsheetSkeleton, cjk, precisionTo } from "@univerjs/engine-render";
|
|
5
5
|
import { UnitAction, UnitObject } from "@univerjs/protocol";
|
|
6
6
|
import { filter as filter$1, map as map$1, takeUntil as takeUntil$1 } from "rxjs/operators";
|
|
@@ -1200,11 +1200,12 @@ var ZebraCrossingCache = class {
|
|
|
1200
1200
|
//#region src/models/range-theme-model.ts
|
|
1201
1201
|
const SHEET_RANGE_THEME_MODEL_PLUGIN = "SHEET_RANGE_THEME_MODEL_PLUGIN";
|
|
1202
1202
|
let SheetRangeThemeModel = class SheetRangeThemeModel extends Disposable {
|
|
1203
|
-
constructor(_sheetInterceptorService, _resourceManagerService, _univerInstanceService) {
|
|
1203
|
+
constructor(_sheetInterceptorService, _resourceManagerService, _univerInstanceService, _sheetRowFilteredService) {
|
|
1204
1204
|
super();
|
|
1205
1205
|
this._sheetInterceptorService = _sheetInterceptorService;
|
|
1206
1206
|
this._resourceManagerService = _resourceManagerService;
|
|
1207
1207
|
this._univerInstanceService = _univerInstanceService;
|
|
1208
|
+
this._sheetRowFilteredService = _sheetRowFilteredService;
|
|
1208
1209
|
_defineProperty(this, "_rangeThemeStyleMap", /* @__PURE__ */ new Map());
|
|
1209
1210
|
_defineProperty(this, "_rangeThemeStyleRuleMap", /* @__PURE__ */ new Map());
|
|
1210
1211
|
_defineProperty(this, "_rTreeCollection", /* @__PURE__ */ new Map());
|
|
@@ -1259,8 +1260,11 @@ let SheetRangeThemeModel = class SheetRangeThemeModel extends Disposable {
|
|
|
1259
1260
|
if (sheet) {
|
|
1260
1261
|
const rowCount = sheet.getRowCount();
|
|
1261
1262
|
const rowManager = sheet.getRowManager();
|
|
1262
|
-
for (let i =
|
|
1263
|
-
else
|
|
1263
|
+
for (let i = 0; i < rowCount; i++) if (!sheet.getRowVisible(i)) set.add(i);
|
|
1264
|
+
else {
|
|
1265
|
+
var _this$_sheetRowFilter;
|
|
1266
|
+
if (rowManager.getRowHeight(i) === 0 || ((_this$_sheetRowFilter = this._sheetRowFilteredService) === null || _this$_sheetRowFilter === void 0 ? void 0 : _this$_sheetRowFilter.getRowFiltered(unitId, subUnitId, i))) set.add(i);
|
|
1267
|
+
}
|
|
1264
1268
|
}
|
|
1265
1269
|
}
|
|
1266
1270
|
}
|
|
@@ -1426,8 +1430,11 @@ let SheetRangeThemeModel = class SheetRangeThemeModel extends Disposable {
|
|
|
1426
1430
|
const offsetRow = row - rangeInfo.range.startRow;
|
|
1427
1431
|
const offsetCol = col - rangeInfo.range.startColumn;
|
|
1428
1432
|
const theme = this.getRangeThemeStyle(unitId, themeName);
|
|
1433
|
+
let lastVisibleRow = rangeInfo.range.endRow;
|
|
1434
|
+
const hiddenRows = this._getSheetRowVisibleFuncSet(unitId, subUnitId);
|
|
1435
|
+
while (lastVisibleRow >= rangeInfo.range.startRow && hiddenRows.has(lastVisibleRow)) lastVisibleRow--;
|
|
1429
1436
|
const isToggled = this._ensureZebraCrossingCache(unitId, subUnitId, themes[0]).getIsToggled(row);
|
|
1430
|
-
if (theme) return theme.getStyle(offsetRow, offsetCol, row ===
|
|
1437
|
+
if (theme) return theme.getStyle(offsetRow, offsetCol, row === lastVisibleRow, col === rangeInfo.range.endColumn, isToggled);
|
|
1431
1438
|
}
|
|
1432
1439
|
}
|
|
1433
1440
|
}
|
|
@@ -1526,7 +1533,8 @@ let SheetRangeThemeModel = class SheetRangeThemeModel extends Disposable {
|
|
|
1526
1533
|
SheetRangeThemeModel = __decorate([
|
|
1527
1534
|
__decorateParam(0, Inject(SheetInterceptorService)),
|
|
1528
1535
|
__decorateParam(1, Inject(IResourceManagerService)),
|
|
1529
|
-
__decorateParam(2, Inject(IUniverInstanceService))
|
|
1536
|
+
__decorateParam(2, Inject(IUniverInstanceService)),
|
|
1537
|
+
__decorateParam(3, Optional(ISheetRowFilteredService))
|
|
1530
1538
|
], SheetRangeThemeModel);
|
|
1531
1539
|
|
|
1532
1540
|
//#endregion
|
|
@@ -1606,6 +1614,7 @@ const InsertRowMutation = {
|
|
|
1606
1614
|
const { worksheet } = target;
|
|
1607
1615
|
const rowManager = worksheet.getRowManager();
|
|
1608
1616
|
const { range, rowInfo } = params;
|
|
1617
|
+
if (rowInfo && !Object.values(rowInfo).every(isValidRowDimensions)) return false;
|
|
1609
1618
|
const { startRow, endRow } = range;
|
|
1610
1619
|
rowManager.insertRowsWithData(startRow, endRow, rowInfo);
|
|
1611
1620
|
const insertedRowCount = endRow - startRow + 1;
|
|
@@ -1631,6 +1640,7 @@ const InsertColMutation = {
|
|
|
1631
1640
|
const { worksheet } = target;
|
|
1632
1641
|
const columnManager = worksheet.getColumnManager();
|
|
1633
1642
|
const { range, colInfo } = params;
|
|
1643
|
+
if (colInfo && !Object.values(colInfo).every(isValidColumnDimensions)) return false;
|
|
1634
1644
|
const { startColumn, endColumn } = range;
|
|
1635
1645
|
columnManager.insertColumnsWithData(startColumn, endColumn, colInfo);
|
|
1636
1646
|
const insertedColumnCount = endColumn - startColumn + 1;
|
|
@@ -1965,6 +1975,7 @@ const SetColDataMutation = {
|
|
|
1965
1975
|
type: CommandType.MUTATION,
|
|
1966
1976
|
handler: (accessor, params) => {
|
|
1967
1977
|
const { columnData } = params;
|
|
1978
|
+
if (!Object.values(columnData).every(isValidColumnDimensions)) return false;
|
|
1968
1979
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1969
1980
|
const target = getSheetCommandTarget(univerInstanceService, params);
|
|
1970
1981
|
if (!target) return false;
|
|
@@ -2406,7 +2417,10 @@ const overwriteCellPropertiesSet = /* @__PURE__ */ new Set([
|
|
|
2406
2417
|
"fd"
|
|
2407
2418
|
]);
|
|
2408
2419
|
function mergeCellData(newValue, oldValue, styles, isOverrideStyle = false) {
|
|
2409
|
-
|
|
2420
|
+
var _previousStyle$n, _styles$getStyleByCel;
|
|
2421
|
+
const canPreserveValue = newValue.v === void 0 && newValue.t === void 0 && oldValue.t != null;
|
|
2422
|
+
const previousStyle = canPreserveValue ? styles.getStyleByCell(oldValue) : void 0;
|
|
2423
|
+
const type = canPreserveValue ? oldValue.t : getCellType(styles, newValue, oldValue);
|
|
2410
2424
|
Object.keys(newValue).forEach((key) => {
|
|
2411
2425
|
const cellPropertyKey = key;
|
|
2412
2426
|
if (overwriteCellPropertiesSet.has(cellPropertyKey)) {
|
|
@@ -2423,9 +2437,14 @@ function mergeCellData(newValue, oldValue, styles, isOverrideStyle = false) {
|
|
|
2423
2437
|
delete oldValue.ft;
|
|
2424
2438
|
delete oldValue.fd;
|
|
2425
2439
|
}
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2440
|
+
const numberFormatChanged = canPreserveValue && (previousStyle === null || previousStyle === void 0 || (_previousStyle$n = previousStyle.n) === null || _previousStyle$n === void 0 ? void 0 : _previousStyle$n.pattern) !== ((_styles$getStyleByCel = styles.getStyleByCell(oldValue)) === null || _styles$getStyleByCel === void 0 || (_styles$getStyleByCel = _styles$getStyleByCel.n) === null || _styles$getStyleByCel === void 0 ? void 0 : _styles$getStyleByCel.pattern);
|
|
2441
|
+
if (oldValue.v !== void 0 && (!canPreserveValue || numberFormatChanged)) {
|
|
2442
|
+
const nextType = numberFormatChanged ? getCellType(styles, newValue, {
|
|
2443
|
+
...oldValue,
|
|
2444
|
+
s: previousStyle
|
|
2445
|
+
}) : type;
|
|
2446
|
+
oldValue.t = nextType;
|
|
2447
|
+
oldValue.v = getCellValue(nextType, oldValue);
|
|
2429
2448
|
}
|
|
2430
2449
|
if (oldValue.v === null) {
|
|
2431
2450
|
delete oldValue.t;
|
|
@@ -2472,6 +2491,7 @@ const SetRowDataMutation = {
|
|
|
2472
2491
|
type: CommandType.MUTATION,
|
|
2473
2492
|
handler: (accessor, params) => {
|
|
2474
2493
|
const { rowData } = params;
|
|
2494
|
+
if (!Object.values(rowData).every(isValidRowDimensions)) return false;
|
|
2475
2495
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
2476
2496
|
const target = getSheetCommandTarget(univerInstanceService, params);
|
|
2477
2497
|
if (!target) return false;
|
|
@@ -2576,6 +2596,8 @@ const SetWorksheetColWidthMutation = {
|
|
|
2576
2596
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
2577
2597
|
const target = getSheetCommandTarget(univerInstanceService, params);
|
|
2578
2598
|
if (!target) return false;
|
|
2599
|
+
const dimensions = params.colWidth;
|
|
2600
|
+
if (typeof dimensions === "number" ? !isValidSheetDimension(dimensions) : dimensions == null || typeof dimensions !== "object" || Object.values(dimensions).some((value) => value != null && !isValidSheetDimension(value))) return false;
|
|
2579
2601
|
const { worksheet } = target;
|
|
2580
2602
|
const manager = worksheet.getColumnManager();
|
|
2581
2603
|
const ranges = params.ranges;
|
|
@@ -2720,6 +2742,8 @@ const SetWorksheetRowHeightMutation = {
|
|
|
2720
2742
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
2721
2743
|
const target = getSheetCommandTarget(univerInstanceService, params);
|
|
2722
2744
|
if (!target) return false;
|
|
2745
|
+
const dimensions = params.rowHeight;
|
|
2746
|
+
if (typeof dimensions === "number" ? !isValidSheetDimension(dimensions) : dimensions == null || typeof dimensions !== "object" || Object.values(dimensions).some((value) => value != null && !isValidSheetDimension(value))) return false;
|
|
2723
2747
|
const { worksheet } = target;
|
|
2724
2748
|
const manager = worksheet.getRowManager();
|
|
2725
2749
|
for (const { startRow, endRow } of ranges) for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) if (typeof rowHeight === "number") manager.setRowHeight(rowIndex, rowHeight);
|
|
@@ -2749,6 +2773,7 @@ const SetWorksheetRowAutoHeightMutation = {
|
|
|
2749
2773
|
type: CommandType.MUTATION,
|
|
2750
2774
|
handler: (accessor, params) => {
|
|
2751
2775
|
const { rowsAutoHeightInfo } = params;
|
|
2776
|
+
if (rowsAutoHeightInfo.some(({ autoHeight }) => autoHeight != null && !isValidSheetDimension(autoHeight))) return false;
|
|
2752
2777
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
2753
2778
|
const target = getSheetCommandTarget(univerInstanceService, params);
|
|
2754
2779
|
if (!target) return false;
|
|
@@ -11971,6 +11996,7 @@ let AutoFillService = class AutoFillService extends Disposable {
|
|
|
11971
11996
|
direction = Direction.RIGHT;
|
|
11972
11997
|
target.startColumn = source.endColumn + 1;
|
|
11973
11998
|
} else return false;
|
|
11999
|
+
this.setShowMenu(false);
|
|
11974
12000
|
this.direction = direction;
|
|
11975
12001
|
const autoFillSource = this._injector.invoke((accessor) => rangeToDiscreteRange(source, accessor, unitId, subUnitId));
|
|
11976
12002
|
const autoFillTarget = this._injector.invoke((accessor) => rangeToDiscreteRange(target, accessor, unitId, subUnitId));
|
|
@@ -12023,7 +12049,7 @@ let AutoFillService = class AutoFillService extends Disposable {
|
|
|
12023
12049
|
getAllHooks() {
|
|
12024
12050
|
return this._hooks;
|
|
12025
12051
|
}
|
|
12026
|
-
getActiveHooks() {
|
|
12052
|
+
getActiveHooks(applyType = this.applyType) {
|
|
12027
12053
|
const { source, target, unitId, subUnitId } = this.autoFillLocation || {};
|
|
12028
12054
|
if (!source || !target || !unitId || !subUnitId) return [];
|
|
12029
12055
|
const enabledHooks = this._hooks.filter((h) => {
|
|
@@ -12033,7 +12059,7 @@ let AutoFillService = class AutoFillService extends Disposable {
|
|
|
12033
12059
|
target,
|
|
12034
12060
|
unitId,
|
|
12035
12061
|
subUnitId
|
|
12036
|
-
}, this._direction,
|
|
12062
|
+
}, this._direction, applyType)) === true;
|
|
12037
12063
|
});
|
|
12038
12064
|
const onlyHooks = enabledHooks.filter((h) => h.type === "ONLY");
|
|
12039
12065
|
if (onlyHooks.length > 0) return this._getOneByPriority(onlyHooks);
|
|
@@ -12082,7 +12108,6 @@ let AutoFillService = class AutoFillService extends Disposable {
|
|
|
12082
12108
|
}
|
|
12083
12109
|
fillData(applyType) {
|
|
12084
12110
|
var _activeWorkbook$getAc;
|
|
12085
|
-
this.applyType = applyType;
|
|
12086
12111
|
const activeWorkbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
12087
12112
|
const activeUnitId = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId();
|
|
12088
12113
|
const activeSubUnitId = activeWorkbook === null || activeWorkbook === void 0 || (_activeWorkbook$getAc = activeWorkbook.getActiveSheet()) === null || _activeWorkbook$getAc === void 0 ? void 0 : _activeWorkbook$getAc.getSheetId();
|
|
@@ -12093,12 +12118,30 @@ let AutoFillService = class AutoFillService extends Disposable {
|
|
|
12093
12118
|
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
12094
12119
|
if (!worksheet) return false;
|
|
12095
12120
|
const direction = this.direction;
|
|
12121
|
+
const activeHooks = this.getActiveHooks(applyType);
|
|
12122
|
+
const fillCallbacks = activeHooks.map((hook) => {
|
|
12123
|
+
var _hook$onPrepareFillDa;
|
|
12124
|
+
return ((_hook$onPrepareFillDa = hook.onPrepareFillData) === null || _hook$onPrepareFillDa === void 0 ? void 0 : _hook$onPrepareFillDa.call(hook, {
|
|
12125
|
+
source,
|
|
12126
|
+
target,
|
|
12127
|
+
unitId,
|
|
12128
|
+
subUnitId
|
|
12129
|
+
}, direction, applyType)) ?? (() => {
|
|
12130
|
+
var _hook$onFillData;
|
|
12131
|
+
return (_hook$onFillData = hook.onFillData) === null || _hook$onFillData === void 0 ? void 0 : _hook$onFillData.call(hook, {
|
|
12132
|
+
source,
|
|
12133
|
+
target,
|
|
12134
|
+
unitId,
|
|
12135
|
+
subUnitId
|
|
12136
|
+
}, direction, applyType);
|
|
12137
|
+
});
|
|
12138
|
+
});
|
|
12139
|
+
this.applyType = applyType;
|
|
12096
12140
|
if (this._prevUndos.length > 0) this._prevUndos.forEach((undo) => {
|
|
12097
12141
|
this._commandService.syncExecuteCommand(undo.id, undo.params);
|
|
12098
12142
|
});
|
|
12099
12143
|
this._prevUndos = [];
|
|
12100
12144
|
const selection = Rectangle.union(discreteRangeToRange(source), discreteRangeToRange(target));
|
|
12101
|
-
const activeHooks = this.getActiveHooks();
|
|
12102
12145
|
if (unitId === activeUnitId && subUnitId === activeSubUnitId) this._commandService.syncExecuteCommand(SetSelectionsOperation.id, {
|
|
12103
12146
|
selections: [{
|
|
12104
12147
|
primary: getPrimaryForRange({
|
|
@@ -12117,14 +12160,8 @@ let AutoFillService = class AutoFillService extends Disposable {
|
|
|
12117
12160
|
});
|
|
12118
12161
|
const undos = [];
|
|
12119
12162
|
const redos = [];
|
|
12120
|
-
|
|
12121
|
-
|
|
12122
|
-
const { undos: hookUndos, redos: hookRedos } = ((_hook$onFillData = hook.onFillData) === null || _hook$onFillData === void 0 ? void 0 : _hook$onFillData.call(hook, {
|
|
12123
|
-
source,
|
|
12124
|
-
target,
|
|
12125
|
-
unitId,
|
|
12126
|
-
subUnitId
|
|
12127
|
-
}, direction, applyType)) || {};
|
|
12163
|
+
fillCallbacks.forEach((fill) => {
|
|
12164
|
+
const { undos: hookUndos, redos: hookRedos } = fill() || {};
|
|
12128
12165
|
if (hookUndos) undos.push(...hookUndos);
|
|
12129
12166
|
if (hookRedos) redos.push(...hookRedos);
|
|
12130
12167
|
});
|
|
@@ -13663,10 +13700,36 @@ const SetSpecificColsVisibleCommand = {
|
|
|
13663
13700
|
});
|
|
13664
13701
|
if (!target) return false;
|
|
13665
13702
|
const { worksheet } = target;
|
|
13703
|
+
const zeroWidthRanges = [];
|
|
13704
|
+
for (const range of ranges) for (let column = range.startColumn; column <= range.endColumn; column++) if (worksheet.getColVisible(column) && worksheet.getColumnWidth(column) === 0) zeroWidthRanges.push({
|
|
13705
|
+
...range,
|
|
13706
|
+
startColumn: column,
|
|
13707
|
+
endColumn: column
|
|
13708
|
+
});
|
|
13709
|
+
const widthRanges = Rectangle.mergeRanges(zeroWidthRanges);
|
|
13710
|
+
const visibilityRanges = widthRanges.length ? getHiddenColRanges(worksheet, ranges) : ranges;
|
|
13711
|
+
const widthRedos = [];
|
|
13712
|
+
const widthUndos = [];
|
|
13713
|
+
if (widthRanges.length) {
|
|
13714
|
+
const widthParams = {
|
|
13715
|
+
unitId,
|
|
13716
|
+
subUnitId,
|
|
13717
|
+
ranges: widthRanges,
|
|
13718
|
+
colWidth: worksheet.getConfig().defaultColumnWidth
|
|
13719
|
+
};
|
|
13720
|
+
widthRedos.push({
|
|
13721
|
+
id: SetWorksheetColWidthMutation.id,
|
|
13722
|
+
params: widthParams
|
|
13723
|
+
});
|
|
13724
|
+
widthUndos.push({
|
|
13725
|
+
id: SetWorksheetColWidthMutation.id,
|
|
13726
|
+
params: SetWorksheetColWidthMutationFactory(widthParams, worksheet)
|
|
13727
|
+
});
|
|
13728
|
+
}
|
|
13666
13729
|
const redoMutationParams = {
|
|
13667
13730
|
unitId,
|
|
13668
13731
|
subUnitId,
|
|
13669
|
-
ranges
|
|
13732
|
+
ranges: visibilityRanges
|
|
13670
13733
|
};
|
|
13671
13734
|
const setSelectionOperationParams = {
|
|
13672
13735
|
unitId,
|
|
@@ -13688,13 +13751,23 @@ const SetSpecificColsVisibleCommand = {
|
|
|
13688
13751
|
style: null
|
|
13689
13752
|
}))
|
|
13690
13753
|
};
|
|
13691
|
-
const
|
|
13754
|
+
const visibilityRedos = visibilityRanges.length ? [{
|
|
13692
13755
|
id: SetColVisibleMutation.id,
|
|
13693
13756
|
params: redoMutationParams
|
|
13694
|
-
}
|
|
13695
|
-
|
|
13696
|
-
|
|
13697
|
-
|
|
13757
|
+
}] : [];
|
|
13758
|
+
const visibilityUndos = visibilityRanges.length ? [{
|
|
13759
|
+
id: SetColHiddenMutation.id,
|
|
13760
|
+
params: undoMutationParams
|
|
13761
|
+
}] : [];
|
|
13762
|
+
const result = sequenceExecute([
|
|
13763
|
+
...visibilityRedos,
|
|
13764
|
+
...widthRedos,
|
|
13765
|
+
{
|
|
13766
|
+
id: SetSelectionsOperation.id,
|
|
13767
|
+
params: setSelectionOperationParams
|
|
13768
|
+
}
|
|
13769
|
+
], commandService);
|
|
13770
|
+
if (!result.result) return false;
|
|
13698
13771
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
13699
13772
|
id: SetSpecificColsVisibleCommand.id,
|
|
13700
13773
|
params
|
|
@@ -13709,10 +13782,8 @@ const SetSpecificColsVisibleCommand = {
|
|
|
13709
13782
|
accessor.get(IUndoRedoService).pushUndoRedo({
|
|
13710
13783
|
unitID: unitId,
|
|
13711
13784
|
undoMutations: [
|
|
13712
|
-
|
|
13713
|
-
|
|
13714
|
-
params: undoMutationParams
|
|
13715
|
-
},
|
|
13785
|
+
...widthUndos,
|
|
13786
|
+
...visibilityUndos,
|
|
13716
13787
|
{
|
|
13717
13788
|
id: SetSelectionsOperation.id,
|
|
13718
13789
|
params: undoSetSelectionsOperationParams
|
|
@@ -13722,10 +13793,8 @@ const SetSpecificColsVisibleCommand = {
|
|
|
13722
13793
|
],
|
|
13723
13794
|
redoMutations: [
|
|
13724
13795
|
...intercepted.preRedos ?? [],
|
|
13725
|
-
|
|
13726
|
-
|
|
13727
|
-
params: redoMutationParams
|
|
13728
|
-
},
|
|
13796
|
+
...visibilityRedos,
|
|
13797
|
+
...widthRedos,
|
|
13729
13798
|
{
|
|
13730
13799
|
id: SetSelectionsOperation.id,
|
|
13731
13800
|
params: setSelectionOperationParams
|
|
@@ -14395,10 +14464,36 @@ const SetSpecificRowsVisibleCommand = {
|
|
|
14395
14464
|
});
|
|
14396
14465
|
if (!target) return false;
|
|
14397
14466
|
const { worksheet } = target;
|
|
14467
|
+
const zeroHeightRanges = [];
|
|
14468
|
+
for (const range of ranges) for (let row = range.startRow; row <= range.endRow; row++) if (worksheet.getRowVisible(row) && worksheet.getRowHeight(row) === 0) zeroHeightRanges.push({
|
|
14469
|
+
...range,
|
|
14470
|
+
startRow: row,
|
|
14471
|
+
endRow: row
|
|
14472
|
+
});
|
|
14473
|
+
const heightRanges = Rectangle.mergeRanges(zeroHeightRanges);
|
|
14474
|
+
const visibilityRanges = heightRanges.length ? getHiddenRowRanges(worksheet, ranges) : ranges;
|
|
14475
|
+
const heightRedos = [];
|
|
14476
|
+
const heightUndos = [];
|
|
14477
|
+
if (heightRanges.length) {
|
|
14478
|
+
const heightParams = {
|
|
14479
|
+
unitId,
|
|
14480
|
+
subUnitId,
|
|
14481
|
+
ranges: heightRanges,
|
|
14482
|
+
rowHeight: worksheet.getConfig().defaultRowHeight
|
|
14483
|
+
};
|
|
14484
|
+
heightRedos.push({
|
|
14485
|
+
id: SetWorksheetRowHeightMutation.id,
|
|
14486
|
+
params: heightParams
|
|
14487
|
+
});
|
|
14488
|
+
heightUndos.push({
|
|
14489
|
+
id: SetWorksheetRowHeightMutation.id,
|
|
14490
|
+
params: SetWorksheetRowHeightMutationFactory(heightParams, worksheet)
|
|
14491
|
+
});
|
|
14492
|
+
}
|
|
14398
14493
|
const redoMutationParams = {
|
|
14399
14494
|
unitId,
|
|
14400
14495
|
subUnitId,
|
|
14401
|
-
ranges
|
|
14496
|
+
ranges: visibilityRanges
|
|
14402
14497
|
};
|
|
14403
14498
|
const setSelectionOperationParams = {
|
|
14404
14499
|
unitId,
|
|
@@ -14420,13 +14515,23 @@ const SetSpecificRowsVisibleCommand = {
|
|
|
14420
14515
|
style: null
|
|
14421
14516
|
}))
|
|
14422
14517
|
};
|
|
14423
|
-
const
|
|
14518
|
+
const visibilityRedos = visibilityRanges.length ? [{
|
|
14424
14519
|
id: SetRowVisibleMutation.id,
|
|
14425
14520
|
params: redoMutationParams
|
|
14426
|
-
}
|
|
14427
|
-
|
|
14428
|
-
|
|
14429
|
-
|
|
14521
|
+
}] : [];
|
|
14522
|
+
const visibilityUndos = visibilityRanges.length ? [{
|
|
14523
|
+
id: SetRowHiddenMutation.id,
|
|
14524
|
+
params: undoMutationParams
|
|
14525
|
+
}] : [];
|
|
14526
|
+
const result = sequenceExecute([
|
|
14527
|
+
...visibilityRedos,
|
|
14528
|
+
...heightRedos,
|
|
14529
|
+
{
|
|
14530
|
+
id: SetSelectionsOperation.id,
|
|
14531
|
+
params: setSelectionOperationParams
|
|
14532
|
+
}
|
|
14533
|
+
], commandService);
|
|
14534
|
+
if (!result.result) return false;
|
|
14430
14535
|
const intercepted = sheetInterceptorService.onCommandExecute({
|
|
14431
14536
|
id: SetSpecificRowsVisibleCommand.id,
|
|
14432
14537
|
params
|
|
@@ -14442,10 +14547,8 @@ const SetSpecificRowsVisibleCommand = {
|
|
|
14442
14547
|
unitID: unitId,
|
|
14443
14548
|
undoMutations: [
|
|
14444
14549
|
...intercepted.preUndos ?? [],
|
|
14445
|
-
|
|
14446
|
-
|
|
14447
|
-
params: undoMutationParams
|
|
14448
|
-
},
|
|
14550
|
+
...heightUndos,
|
|
14551
|
+
...visibilityUndos,
|
|
14449
14552
|
{
|
|
14450
14553
|
id: SetSelectionsOperation.id,
|
|
14451
14554
|
params: undoSetSelectionsOperationParams
|
|
@@ -14455,10 +14558,8 @@ const SetSpecificRowsVisibleCommand = {
|
|
|
14455
14558
|
],
|
|
14456
14559
|
redoMutations: [
|
|
14457
14560
|
...intercepted.preRedos ?? [],
|
|
14458
|
-
|
|
14459
|
-
|
|
14460
|
-
params: redoMutationParams
|
|
14461
|
-
},
|
|
14561
|
+
...visibilityRedos,
|
|
14562
|
+
...heightRedos,
|
|
14462
14563
|
{
|
|
14463
14564
|
id: SetSelectionsOperation.id,
|
|
14464
14565
|
params: setSelectionOperationParams
|
|
@@ -14869,6 +14970,7 @@ const DeltaColumnWidthCommand = {
|
|
|
14869
14970
|
const { worksheet, unitId, subUnitId } = target;
|
|
14870
14971
|
const { anchorCol, deltaX } = params;
|
|
14871
14972
|
const destColumnWidth = worksheet.getColumnWidth(anchorCol) + deltaX;
|
|
14973
|
+
if (!isValidSheetDimension(destColumnWidth)) return false;
|
|
14872
14974
|
const isAllSheetRange = selections.length === 1 && selections[0].range.rangeType === RANGE_TYPE.ALL;
|
|
14873
14975
|
const colSelections = selections.filter((s) => s.range.rangeType === RANGE_TYPE.COLUMN);
|
|
14874
14976
|
const rangeType = isAllSheetRange ? RANGE_TYPE.ALL : colSelections.some(({ range }) => {
|
|
@@ -14964,6 +15066,7 @@ const SetColWidthCommand = {
|
|
|
14964
15066
|
id: "sheet.command.set-worksheet-col-width",
|
|
14965
15067
|
handler: (accessor, params) => {
|
|
14966
15068
|
var _params$ranges, _selectionManagerServ;
|
|
15069
|
+
if (!isValidSheetDimension(params === null || params === void 0 ? void 0 : params.value)) return false;
|
|
14967
15070
|
const selectionManagerService = accessor.get(SheetsSelectionsService);
|
|
14968
15071
|
const commandService = accessor.get(ICommandService);
|
|
14969
15072
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
@@ -16624,6 +16727,7 @@ const DeltaRowHeightCommand = {
|
|
|
16624
16727
|
const { worksheet, subUnitId, unitId } = target;
|
|
16625
16728
|
const { anchorRow, deltaY } = params;
|
|
16626
16729
|
const destRowHeight = worksheet.getRowHeight(anchorRow) + deltaY;
|
|
16730
|
+
if (!isValidSheetDimension(destRowHeight)) return false;
|
|
16627
16731
|
const isAllSheetRange = selections.length === 1 && selections[0].range.rangeType === RANGE_TYPE.ALL;
|
|
16628
16732
|
const rowSelections = selections.filter((s) => s.range.rangeType === RANGE_TYPE.ROW);
|
|
16629
16733
|
const rangeType = isAllSheetRange ? RANGE_TYPE.ALL : rowSelections.some(({ range }) => {
|
|
@@ -16728,6 +16832,7 @@ const SetRowHeightCommand = {
|
|
|
16728
16832
|
id: "sheet.command.set-row-height",
|
|
16729
16833
|
handler: (accessor, params) => {
|
|
16730
16834
|
var _params$ranges, _selectionManagerServ;
|
|
16835
|
+
if (!isValidSheetDimension(params === null || params === void 0 ? void 0 : params.value)) return false;
|
|
16731
16836
|
const selectionManagerService = accessor.get(SheetsSelectionsService);
|
|
16732
16837
|
const commandService = accessor.get(ICommandService);
|
|
16733
16838
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
@@ -17472,8 +17577,9 @@ let AutoFillController = class AutoFillController extends Disposable {
|
|
|
17472
17577
|
onBeforeFillData: (location, direction) => {
|
|
17473
17578
|
return this._presetAndCacheData(location, direction);
|
|
17474
17579
|
},
|
|
17475
|
-
|
|
17476
|
-
|
|
17580
|
+
onPrepareFillData: (location, direction, applyType) => {
|
|
17581
|
+
const prepared = this._prepareFillData(location, direction, applyType);
|
|
17582
|
+
return () => this._fillData(location, direction, applyType, prepared);
|
|
17477
17583
|
}
|
|
17478
17584
|
}));
|
|
17479
17585
|
}
|
|
@@ -17522,7 +17628,7 @@ let AutoFillController = class AutoFillController extends Disposable {
|
|
|
17522
17628
|
const arrData = this._applyFunctions(copySquad, len, direction, applyType, customApplyFunctions, copyDataPiece, location);
|
|
17523
17629
|
const arrIndex = getDataIndex(csLen, asLen, copySquad.index);
|
|
17524
17630
|
applyDataInTypes[type].push({
|
|
17525
|
-
data: arrData,
|
|
17631
|
+
data: arrData ?? [],
|
|
17526
17632
|
index: arrIndex
|
|
17527
17633
|
});
|
|
17528
17634
|
});
|
|
@@ -17681,28 +17787,9 @@ let AutoFillController = class AutoFillController extends Disposable {
|
|
|
17681
17787
|
}
|
|
17682
17788
|
return applyMergeRanges;
|
|
17683
17789
|
}
|
|
17684
|
-
|
|
17685
|
-
|
|
17686
|
-
const
|
|
17687
|
-
const redos = [];
|
|
17688
|
-
let hasStyle = true;
|
|
17689
|
-
if (applyType === "NO_FORMAT") {
|
|
17690
|
-
hasStyle = false;
|
|
17691
|
-
applyType = "SERIES";
|
|
17692
|
-
}
|
|
17693
|
-
const { source, target, unitId, subUnitId } = location;
|
|
17694
|
-
if (!source || !target || direction == null) return {
|
|
17695
|
-
undos,
|
|
17696
|
-
redos
|
|
17697
|
-
};
|
|
17698
|
-
const sourceRange = discreteRangeToRange(source);
|
|
17699
|
-
const targetRange = discreteRangeToRange(target);
|
|
17700
|
-
const { cols: targetCols, rows: targetRows } = target;
|
|
17701
|
-
const { cols: sourceCols, rows: sourceRows } = source;
|
|
17702
|
-
const copyData = this._copyData;
|
|
17703
|
-
let csLen;
|
|
17704
|
-
if (direction === Direction.DOWN || direction === Direction.UP) csLen = sourceRows.length;
|
|
17705
|
-
else csLen = sourceCols.length;
|
|
17790
|
+
_getFillCells(location, direction, applyType, hasStyle, csLen) {
|
|
17791
|
+
const { rows: targetRows, cols: targetCols } = location.target;
|
|
17792
|
+
const copyData = Tools.deepClone(this._copyData);
|
|
17706
17793
|
const applyDatas = [];
|
|
17707
17794
|
if (direction === Direction.DOWN || direction === Direction.UP) {
|
|
17708
17795
|
const asLen = targetRows.length;
|
|
@@ -17733,20 +17820,26 @@ let AutoFillController = class AutoFillController extends Disposable {
|
|
|
17733
17820
|
applyDatas.push(row);
|
|
17734
17821
|
});
|
|
17735
17822
|
}
|
|
17736
|
-
|
|
17823
|
+
return applyDatas;
|
|
17824
|
+
}
|
|
17825
|
+
_prepareFillData(location, direction, applyType) {
|
|
17826
|
+
var _this$_univerInstance4;
|
|
17827
|
+
const hasStyle = applyType !== "NO_FORMAT";
|
|
17828
|
+
const effectiveApplyType = hasStyle ? applyType : "SERIES";
|
|
17829
|
+
const { source, target, unitId } = location;
|
|
17830
|
+
const sourceRange = discreteRangeToRange(source);
|
|
17831
|
+
const targetRange = discreteRangeToRange(target);
|
|
17832
|
+
const { cols: targetCols, rows: targetRows } = target;
|
|
17833
|
+
const { cols: sourceCols, rows: sourceRows } = source;
|
|
17834
|
+
let csLen;
|
|
17835
|
+
if (direction === Direction.DOWN || direction === Direction.UP) csLen = sourceRows.length;
|
|
17836
|
+
else csLen = sourceCols.length;
|
|
17837
|
+
const applyDatas = this._getFillCells(location, direction, effectiveApplyType, hasStyle, csLen);
|
|
17838
|
+
const applyMergeRanges = hasStyle ? this._getMergeApplyData(sourceRange, targetRange, direction, csLen, location) : [];
|
|
17737
17839
|
const style = (_this$_univerInstance4 = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance4 === void 0 ? void 0 : _this$_univerInstance4.getStyles();
|
|
17738
|
-
|
|
17739
|
-
applyMergeRanges = this._getMergeApplyData(sourceRange, targetRange, direction, csLen, location);
|
|
17740
|
-
applyDatas.forEach((row) => {
|
|
17741
|
-
row.forEach((cellData) => {
|
|
17742
|
-
if (cellData && style) {
|
|
17743
|
-
if (style) cellData.s = style.getStyleByCell(cellData);
|
|
17744
|
-
}
|
|
17745
|
-
});
|
|
17746
|
-
});
|
|
17747
|
-
} else applyDatas.forEach((row, rowIndex) => {
|
|
17840
|
+
applyDatas.forEach((row, rowIndex) => {
|
|
17748
17841
|
row.forEach((cellData, colIndex) => {
|
|
17749
|
-
if (cellData && style) cellData.s = style.getStyleByCell(this._beforeApplyData[rowIndex][colIndex]) || null;
|
|
17842
|
+
if (cellData && style) cellData.s = hasStyle ? style.getStyleByCell(cellData) : style.getStyleByCell(this._beforeApplyData[rowIndex][colIndex]) || null;
|
|
17750
17843
|
});
|
|
17751
17844
|
});
|
|
17752
17845
|
if (applyType === "ONLY_FORMAT") applyDatas.forEach((row, rowIndex) => {
|
|
@@ -17762,30 +17855,59 @@ let AutoFillController = class AutoFillController extends Disposable {
|
|
|
17762
17855
|
}
|
|
17763
17856
|
});
|
|
17764
17857
|
});
|
|
17765
|
-
|
|
17766
|
-
|
|
17767
|
-
|
|
17768
|
-
|
|
17769
|
-
|
|
17770
|
-
|
|
17858
|
+
const cellValue = new ObjectMatrix();
|
|
17859
|
+
targetRows.forEach((row, rowIndex) => {
|
|
17860
|
+
targetCols.forEach((col, colIndex) => {
|
|
17861
|
+
const cell = applyDatas[rowIndex][colIndex];
|
|
17862
|
+
if (cell) cellValue.setValue(row, col, cell);
|
|
17863
|
+
});
|
|
17864
|
+
});
|
|
17865
|
+
const cellValueMatrix = cellValue.getMatrix();
|
|
17866
|
+
this._autoFillService.getActiveHooks(applyType).forEach((hook) => {
|
|
17867
|
+
var _hook$onValidateFillD;
|
|
17868
|
+
(_hook$onValidateFillD = hook.onValidateFillData) === null || _hook$onValidateFillD === void 0 || _hook$onValidateFillD.call(hook, location, direction, applyType, cellValueMatrix);
|
|
17869
|
+
});
|
|
17870
|
+
return {
|
|
17871
|
+
cellValue: cellValueMatrix,
|
|
17872
|
+
applyMergeRanges,
|
|
17873
|
+
hasStyle
|
|
17874
|
+
};
|
|
17875
|
+
}
|
|
17876
|
+
_getRemoveMergeMutations(location) {
|
|
17877
|
+
var _this$_univerInstance5;
|
|
17878
|
+
const { unitId, subUnitId, target } = location;
|
|
17879
|
+
const targetRange = discreteRangeToRange(target);
|
|
17880
|
+
const undos = [];
|
|
17881
|
+
const redos = [];
|
|
17882
|
+
const deleteMergeRanges = ((_this$_univerInstance5 = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance5 === void 0 || (_this$_univerInstance5 = _this$_univerInstance5.getSheetBySheetId(subUnitId)) === null || _this$_univerInstance5 === void 0 ? void 0 : _this$_univerInstance5.getMergeData().filter((merge) => Rectangle.intersects(merge, targetRange))) ?? [];
|
|
17883
|
+
if (deleteMergeRanges.length) {
|
|
17884
|
+
const removeMergeMutationParams = {
|
|
17885
|
+
unitId,
|
|
17886
|
+
subUnitId,
|
|
17887
|
+
ranges: deleteMergeRanges
|
|
17888
|
+
};
|
|
17889
|
+
const undoRemoveMergeMutationParams = this._injector.invoke(RemoveMergeUndoMutationFactory, removeMergeMutationParams);
|
|
17890
|
+
redos.push({
|
|
17891
|
+
id: RemoveWorksheetMergeMutation.id,
|
|
17892
|
+
params: removeMergeMutationParams
|
|
17893
|
+
});
|
|
17894
|
+
undos.unshift({
|
|
17895
|
+
id: AddWorksheetMergeMutation.id,
|
|
17896
|
+
params: undoRemoveMergeMutationParams
|
|
17771
17897
|
});
|
|
17772
|
-
if (deleteMergeRanges.length) {
|
|
17773
|
-
const removeMergeMutationParams = {
|
|
17774
|
-
unitId,
|
|
17775
|
-
subUnitId,
|
|
17776
|
-
ranges: deleteMergeRanges
|
|
17777
|
-
};
|
|
17778
|
-
const undoRemoveMergeMutationParams = this._injector.invoke(RemoveMergeUndoMutationFactory, removeMergeMutationParams);
|
|
17779
|
-
redos.push({
|
|
17780
|
-
id: RemoveWorksheetMergeMutation.id,
|
|
17781
|
-
params: removeMergeMutationParams
|
|
17782
|
-
});
|
|
17783
|
-
undos.unshift({
|
|
17784
|
-
id: AddWorksheetMergeMutation.id,
|
|
17785
|
-
params: undoRemoveMergeMutationParams
|
|
17786
|
-
});
|
|
17787
|
-
}
|
|
17788
17898
|
}
|
|
17899
|
+
return {
|
|
17900
|
+
undos,
|
|
17901
|
+
redos
|
|
17902
|
+
};
|
|
17903
|
+
}
|
|
17904
|
+
_fillData(location, direction, applyType, prepared) {
|
|
17905
|
+
const { target, unitId, subUnitId } = location;
|
|
17906
|
+
const { cellValue, applyMergeRanges, hasStyle } = prepared;
|
|
17907
|
+
const { undos, redos } = hasStyle ? this._getRemoveMergeMutations(location) : {
|
|
17908
|
+
undos: [],
|
|
17909
|
+
redos: []
|
|
17910
|
+
};
|
|
17789
17911
|
const clearMutationParams = {
|
|
17790
17912
|
subUnitId,
|
|
17791
17913
|
unitId,
|
|
@@ -17800,22 +17922,15 @@ let AutoFillController = class AutoFillController extends Disposable {
|
|
|
17800
17922
|
id: SetRangeValuesMutation.id,
|
|
17801
17923
|
params: undoClearMutationParams
|
|
17802
17924
|
});
|
|
17803
|
-
const cellValue = new ObjectMatrix();
|
|
17804
|
-
targetRows.forEach((row, rowIndex) => {
|
|
17805
|
-
targetCols.forEach((col, colIndex) => {
|
|
17806
|
-
if (applyDatas[rowIndex][colIndex]) cellValue.setValue(row, col, applyDatas[rowIndex][colIndex]);
|
|
17807
|
-
});
|
|
17808
|
-
});
|
|
17809
|
-
const cellValueMatrix = cellValue.getMatrix();
|
|
17810
17925
|
const setRangeValuesMutationParams = {
|
|
17811
17926
|
subUnitId,
|
|
17812
17927
|
unitId,
|
|
17813
|
-
cellValue
|
|
17928
|
+
cellValue
|
|
17814
17929
|
};
|
|
17815
17930
|
const undoSetRangeValuesMutationParams = this._injector.invoke(SetRangeValuesUndoMutationFactory, setRangeValuesMutationParams);
|
|
17816
|
-
this._autoFillService.getActiveHooks().forEach((hook) => {
|
|
17931
|
+
this._autoFillService.getActiveHooks(applyType).forEach((hook) => {
|
|
17817
17932
|
var _hook$onBeforeSubmit;
|
|
17818
|
-
(_hook$onBeforeSubmit = hook.onBeforeSubmit) === null || _hook$onBeforeSubmit === void 0 || _hook$onBeforeSubmit.call(hook, location, direction, applyType,
|
|
17933
|
+
(_hook$onBeforeSubmit = hook.onBeforeSubmit) === null || _hook$onBeforeSubmit === void 0 || _hook$onBeforeSubmit.call(hook, location, direction, applyType, cellValue);
|
|
17819
17934
|
});
|
|
17820
17935
|
undos.unshift({
|
|
17821
17936
|
id: SetRangeValuesMutation.id,
|
|
@@ -18172,7 +18287,7 @@ SheetsFreezeSyncController = __decorate([
|
|
|
18172
18287
|
//#endregion
|
|
18173
18288
|
//#region src/controllers/permission/sheet-permission-check.controller.ts
|
|
18174
18289
|
let SheetPermissionCheckController = class SheetPermissionCheckController extends Disposable {
|
|
18175
|
-
constructor(_commandService, _univerInstanceService, _permissionService, _selectionManagerService, _rangeProtectionRuleModel, _worksheetProtectionRuleModel, _localeService, _lexerTreeBuilder, _definedNamesService) {
|
|
18290
|
+
constructor(_commandService, _univerInstanceService, _permissionService, _selectionManagerService, _rangeProtectionRuleModel, _worksheetProtectionRuleModel, _localeService, _lexerTreeBuilder, _definedNamesService, _autoFillService, _formulaDataModel, _functionService) {
|
|
18176
18291
|
super();
|
|
18177
18292
|
this._commandService = _commandService;
|
|
18178
18293
|
this._univerInstanceService = _univerInstanceService;
|
|
@@ -18183,6 +18298,9 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18183
18298
|
this._localeService = _localeService;
|
|
18184
18299
|
this._lexerTreeBuilder = _lexerTreeBuilder;
|
|
18185
18300
|
this._definedNamesService = _definedNamesService;
|
|
18301
|
+
this._autoFillService = _autoFillService;
|
|
18302
|
+
this._formulaDataModel = _formulaDataModel;
|
|
18303
|
+
this._functionService = _functionService;
|
|
18186
18304
|
_defineProperty(this, "disposableCollection", new DisposableCollection());
|
|
18187
18305
|
_defineProperty(this, "_triggerPermissionUIEvent$", new Subject());
|
|
18188
18306
|
_defineProperty(this, "triggerPermissionUIEvent$", this._triggerPermissionUIEvent$.asObservable());
|
|
@@ -18190,6 +18308,29 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18190
18308
|
}
|
|
18191
18309
|
_initialize() {
|
|
18192
18310
|
this._commandExecutedListener();
|
|
18311
|
+
this.disposeWithMe(this._autoFillService.addHook({
|
|
18312
|
+
id: "permission-check",
|
|
18313
|
+
onValidateFillData: ({ unitId, subUnitId }, _direction, applyType, cellValue) => {
|
|
18314
|
+
if (applyType === "ONLY_FORMAT") return;
|
|
18315
|
+
const formulas = new ObjectMatrix(this._formulaDataModel.updateFormulaData(unitId, subUnitId, cellValue));
|
|
18316
|
+
new ObjectMatrix(cellValue).forValue((row, column) => {
|
|
18317
|
+
const formula = formulas.getValue(row, column);
|
|
18318
|
+
if (!(formula === null || formula === void 0 ? void 0 : formula.f)) return;
|
|
18319
|
+
const formulaString = this._lexerTreeBuilder.moveFormulaRefOffset(formula.f, formula.x ?? 0, formula.y ?? 0);
|
|
18320
|
+
if (!this._permissionCheckWithFormula({
|
|
18321
|
+
unitId,
|
|
18322
|
+
subUnitId,
|
|
18323
|
+
range: {
|
|
18324
|
+
startRow: row,
|
|
18325
|
+
endRow: row,
|
|
18326
|
+
startColumn: column,
|
|
18327
|
+
endColumn: column
|
|
18328
|
+
},
|
|
18329
|
+
value: { f: formulaString }
|
|
18330
|
+
})) this.blockExecuteWithoutPermission(this._localeService.t("sheets.permission.dialog.formulaErr"));
|
|
18331
|
+
});
|
|
18332
|
+
}
|
|
18333
|
+
}));
|
|
18193
18334
|
}
|
|
18194
18335
|
_commandExecutedListener() {
|
|
18195
18336
|
this.disposeWithMe(this._commandService.beforeCommandExecuted((commandInfo) => {
|
|
@@ -18514,61 +18655,18 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18514
18655
|
_permissionCheckWithFormula(params) {
|
|
18515
18656
|
const target = getSheetCommandTarget(this._univerInstanceService, params);
|
|
18516
18657
|
if (!target) return false;
|
|
18517
|
-
const {
|
|
18658
|
+
const { unitId, subUnitId } = target;
|
|
18518
18659
|
const formulaString = params.value.f;
|
|
18519
18660
|
if (formulaString) {
|
|
18520
|
-
|
|
18521
|
-
const
|
|
18522
|
-
|
|
18523
|
-
|
|
18524
|
-
|
|
18525
|
-
|
|
18526
|
-
|
|
18527
|
-
|
|
18528
|
-
|
|
18529
|
-
if (sheetName) {
|
|
18530
|
-
const targetSheet = workbook.getSheetBySheetName(sheetName);
|
|
18531
|
-
if (!targetSheet) return true;
|
|
18532
|
-
const { startRow, endRow, startColumn, endColumn } = range;
|
|
18533
|
-
for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
|
|
18534
|
-
var _cell$selectionProtec2;
|
|
18535
|
-
const cell = targetSheet.getCell(r, c);
|
|
18536
|
-
const permission = cell === null || cell === void 0 || (_cell$selectionProtec2 = cell.selectionProtection) === null || _cell$selectionProtec2 === void 0 ? void 0 : _cell$selectionProtec2[0];
|
|
18537
|
-
if ((permission === null || permission === void 0 ? void 0 : permission[UnitAction.View]) === false) return false;
|
|
18538
|
-
}
|
|
18539
|
-
}
|
|
18540
|
-
}
|
|
18541
|
-
return true;
|
|
18542
|
-
} else {
|
|
18543
|
-
const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
|
|
18544
|
-
if (!sequenceNodes) return true;
|
|
18545
|
-
for (let i = 0; i < sequenceNodes.length; i++) {
|
|
18546
|
-
const node = sequenceNodes[i];
|
|
18547
|
-
if (typeof node === "string" || node.nodeType !== sequenceNodeType.REFERENCE) continue;
|
|
18548
|
-
const { token } = node;
|
|
18549
|
-
const { unitId: sequenceGridUnitId, sheetName, range } = deserializeRangeWithSheetWithCache(token);
|
|
18550
|
-
let sequenceGridWorkbook = workbook;
|
|
18551
|
-
if (sequenceGridUnitId && sequenceGridUnitId !== unitId) {
|
|
18552
|
-
const _sequenceGridWorkbook = this._univerInstanceService.getUnit(sequenceGridUnitId, UniverInstanceType.UNIVER_SHEET);
|
|
18553
|
-
if (!_sequenceGridWorkbook) return true;
|
|
18554
|
-
sequenceGridWorkbook = _sequenceGridWorkbook;
|
|
18555
|
-
}
|
|
18556
|
-
const sequenceGridWorksheet = sheetName ? sequenceGridWorkbook.getSheetBySheetName(sheetName) : sequenceGridWorkbook.getActiveSheet();
|
|
18557
|
-
if (!sequenceGridWorksheet) return true;
|
|
18558
|
-
if (sheetName) {
|
|
18559
|
-
const viewPermission = this._permissionService.getPermissionPoint(new WorksheetViewPermission(sequenceGridWorkbook.getUnitId(), sequenceGridWorksheet.getSheetId()).id);
|
|
18560
|
-
if (!viewPermission || viewPermission.value === false) return false;
|
|
18561
|
-
}
|
|
18562
|
-
const { startRow, endRow, startColumn, endColumn } = range;
|
|
18563
|
-
for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
|
|
18564
|
-
var _cell$selectionProtec3;
|
|
18565
|
-
const cell = sequenceGridWorksheet.getCell(r, c);
|
|
18566
|
-
const permission = cell === null || cell === void 0 || (_cell$selectionProtec3 = cell.selectionProtection) === null || _cell$selectionProtec3 === void 0 ? void 0 : _cell$selectionProtec3[0];
|
|
18567
|
-
if ((permission === null || permission === void 0 ? void 0 : permission[UnitAction.View]) === false) return false;
|
|
18568
|
-
}
|
|
18569
|
-
}
|
|
18570
|
-
return true;
|
|
18571
|
-
}
|
|
18661
|
+
var _this$_selectionManag3;
|
|
18662
|
+
const ranges = params.range ? [params.range] : ((_this$_selectionManag3 = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag3 === void 0 ? void 0 : _this$_selectionManag3.map((selection) => selection.range)) ?? [];
|
|
18663
|
+
for (const range of ranges) for (let row = range.startRow; row <= range.endRow; row++) for (let column = range.startColumn; column <= range.endColumn; column++) if (!this._permissionCheckFormulaReferences(formulaString, {
|
|
18664
|
+
unitId,
|
|
18665
|
+
subUnitId,
|
|
18666
|
+
row,
|
|
18667
|
+
column
|
|
18668
|
+
})) return false;
|
|
18669
|
+
return true;
|
|
18572
18670
|
}
|
|
18573
18671
|
const { range } = params;
|
|
18574
18672
|
if (range) {
|
|
@@ -18579,6 +18677,73 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18579
18677
|
}
|
|
18580
18678
|
return true;
|
|
18581
18679
|
}
|
|
18680
|
+
_getFormulaReferenceWorkbook(unitId, qualifier) {
|
|
18681
|
+
const workbook = this._univerInstanceService.getUnit(qualifier || unitId, UniverInstanceType.UNIVER_SHEET);
|
|
18682
|
+
if (workbook || !qualifier) return workbook;
|
|
18683
|
+
const workbooks = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET).filter((item) => item.getSnapshot().name.length > 0);
|
|
18684
|
+
const exactMatches = workbooks.filter((item) => item.getSnapshot().name.toLowerCase() === qualifier.toLowerCase());
|
|
18685
|
+
const matches = exactMatches.length > 0 ? exactMatches : workbooks.filter((item) => normalizeFormulaUnitName(item.getSnapshot().name) === normalizeFormulaUnitName(qualifier));
|
|
18686
|
+
return matches.length === 1 ? matches[0] : null;
|
|
18687
|
+
}
|
|
18688
|
+
_permissionCheckFormulaReferences(formulaString, context, visitingNames = /* @__PURE__ */ new Set(), referenceOffset) {
|
|
18689
|
+
const { unitId, subUnitId, row, column } = context;
|
|
18690
|
+
const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString) ?? [];
|
|
18691
|
+
for (let index = 0; index < sequenceNodes.length; index++) {
|
|
18692
|
+
const node = sequenceNodes[index];
|
|
18693
|
+
if (typeof node === "string" || node.nodeType !== sequenceNodeType.REFERENCE && node.nodeType !== sequenceNodeType.FUNCTION) continue;
|
|
18694
|
+
const nextNode = sequenceNodes[index + 1];
|
|
18695
|
+
if (node.nodeType === sequenceNodeType.FUNCTION && typeof nextNode === "string" && nextNode.trim() === matchToken.OPEN_BRACKET && this._functionService.hasExecutor(node.token.trim().toUpperCase())) continue;
|
|
18696
|
+
let nameToken = node.token.trim();
|
|
18697
|
+
if (node.nodeType === sequenceNodeType.FUNCTION) {
|
|
18698
|
+
const parts = nameToken.split("!");
|
|
18699
|
+
if (parts.length === 2) {
|
|
18700
|
+
var _this$_univerInstance;
|
|
18701
|
+
const unqualifiedName = parts[1].trim();
|
|
18702
|
+
const unscopedName = this._definedNamesService.getValueByName(unitId, unqualifiedName);
|
|
18703
|
+
const localSheetId = unscopedName === null || unscopedName === void 0 ? void 0 : unscopedName.localSheetId;
|
|
18704
|
+
const localSheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(localSheetId ?? "");
|
|
18705
|
+
if (unscopedName && (localSheetId == null || localSheetId === "AllDefaultWorkbook" || (localSheet === null || localSheet === void 0 ? void 0 : localSheet.getName()) === parts[0])) nameToken = unqualifiedName;
|
|
18706
|
+
}
|
|
18707
|
+
}
|
|
18708
|
+
const definedName = this._definedNamesService.getValueByName(unitId, nameToken, subUnitId);
|
|
18709
|
+
if (definedName) {
|
|
18710
|
+
const nameKey = `${unitId}:${definedName.id}`;
|
|
18711
|
+
if (visitingNames.has(nameKey)) continue;
|
|
18712
|
+
visitingNames.add(nameKey);
|
|
18713
|
+
const definition = definedName.formulaOrRefString;
|
|
18714
|
+
const isFormula = definition.startsWith(operatorToken.EQUALS);
|
|
18715
|
+
const offset = isFormula ? void 0 : {
|
|
18716
|
+
x: column - (definedName.localSheetId === "AllDefaultWorkbook" ? 1 : 0),
|
|
18717
|
+
y: row
|
|
18718
|
+
};
|
|
18719
|
+
const permitted = this._permissionCheckFormulaReferences(isFormula ? definition : `${operatorToken.EQUALS}${definition}`, context, visitingNames, offset);
|
|
18720
|
+
visitingNames.delete(nameKey);
|
|
18721
|
+
if (!permitted) return false;
|
|
18722
|
+
continue;
|
|
18723
|
+
}
|
|
18724
|
+
if (node.nodeType !== sequenceNodeType.REFERENCE) continue;
|
|
18725
|
+
const { unitQualifier, sheetName } = handleRefStringInfo(node.token.trim());
|
|
18726
|
+
const referenceWorkbook = this._getFormulaReferenceWorkbook(unitId, unitQualifier);
|
|
18727
|
+
const referenceWorksheet = sheetName ? referenceWorkbook === null || referenceWorkbook === void 0 ? void 0 : referenceWorkbook.getSheetBySheetName(sheetName) : referenceWorkbook === null || referenceWorkbook === void 0 ? void 0 : referenceWorkbook.getSheetBySheetId(subUnitId);
|
|
18728
|
+
if (!referenceWorkbook || !referenceWorksheet) continue;
|
|
18729
|
+
const referenceUnitId = referenceWorkbook.getUnitId();
|
|
18730
|
+
const referenceSheetId = referenceWorksheet.getSheetId();
|
|
18731
|
+
const { range } = deserializeRangeWithSheetWithCache(node.token);
|
|
18732
|
+
const referenceRange = referenceOffset ? moveRangeByOffset({ ...range }, referenceOffset.x, referenceOffset.y) : range;
|
|
18733
|
+
if (referenceOffset) {
|
|
18734
|
+
const wrap = (value, limit) => (value % limit + limit) % limit;
|
|
18735
|
+
referenceRange.startRow = wrap(referenceRange.startRow, MAX_ROW_COUNT);
|
|
18736
|
+
referenceRange.endRow = wrap(referenceRange.endRow, MAX_ROW_COUNT);
|
|
18737
|
+
referenceRange.startColumn = wrap(referenceRange.startColumn, MAX_COLUMN_COUNT);
|
|
18738
|
+
referenceRange.endColumn = wrap(referenceRange.endColumn, MAX_COLUMN_COUNT);
|
|
18739
|
+
}
|
|
18740
|
+
if (!this.permissionCheckWithRanges({
|
|
18741
|
+
worksheetTypes: [WorksheetViewPermission],
|
|
18742
|
+
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
18743
|
+
}, [referenceRange], referenceUnitId, referenceSheetId)) return false;
|
|
18744
|
+
}
|
|
18745
|
+
return true;
|
|
18746
|
+
}
|
|
18582
18747
|
_permissionCheckBySetRangeValue(permissionTypes, params) {
|
|
18583
18748
|
const { unitId, subUnitId, value, range } = params;
|
|
18584
18749
|
let ranges = [];
|
|
@@ -18674,11 +18839,11 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18674
18839
|
return true;
|
|
18675
18840
|
}
|
|
18676
18841
|
_permissionCheckWithInsertOrDeleteMoveRange(direction, params) {
|
|
18677
|
-
var _this$
|
|
18842
|
+
var _this$_selectionManag4;
|
|
18678
18843
|
const target = getSheetCommandTarget(this._univerInstanceService);
|
|
18679
18844
|
if (!target) return false;
|
|
18680
18845
|
const { worksheet, unitId, subUnitId } = target;
|
|
18681
|
-
const range = (params === null || params === void 0 ? void 0 : params.range) ?? ((_this$
|
|
18846
|
+
const range = (params === null || params === void 0 ? void 0 : params.range) ?? ((_this$_selectionManag4 = this._selectionManagerService.getCurrentLastSelection()) === null || _this$_selectionManag4 === void 0 ? void 0 : _this$_selectionManag4.range);
|
|
18682
18847
|
if (!range) return false;
|
|
18683
18848
|
if (!this.permissionCheckWithRanges({
|
|
18684
18849
|
workbookTypes: [WorkbookEditablePermission],
|
|
@@ -18703,7 +18868,10 @@ SheetPermissionCheckController = __decorate([
|
|
|
18703
18868
|
__decorateParam(5, Inject(WorksheetProtectionRuleModel)),
|
|
18704
18869
|
__decorateParam(6, Inject(LocaleService)),
|
|
18705
18870
|
__decorateParam(7, Inject(LexerTreeBuilder)),
|
|
18706
|
-
__decorateParam(8, IDefinedNamesService)
|
|
18871
|
+
__decorateParam(8, IDefinedNamesService),
|
|
18872
|
+
__decorateParam(9, IAutoFillService),
|
|
18873
|
+
__decorateParam(10, Inject(FormulaDataModel)),
|
|
18874
|
+
__decorateParam(11, IFunctionService)
|
|
18707
18875
|
], SheetPermissionCheckController);
|
|
18708
18876
|
|
|
18709
18877
|
//#endregion
|
|
@@ -19569,7 +19737,7 @@ RangeProtectionCache = __decorate([
|
|
|
19569
19737
|
//#endregion
|
|
19570
19738
|
//#region package.json
|
|
19571
19739
|
var name = "@univerjs/sheets";
|
|
19572
|
-
var version = "1.
|
|
19740
|
+
var version = "1.3.0";
|
|
19573
19741
|
|
|
19574
19742
|
//#endregion
|
|
19575
19743
|
//#region src/controllers/active-worksheet.controller.ts
|
|
@@ -21499,7 +21667,10 @@ function convertPositionCellToSheetOverGrid(unitId, subUnitId, cellOverGridPosit
|
|
|
21499
21667
|
});
|
|
21500
21668
|
const left = precisionTo(startSelectionX + fromColumnOffset, 1);
|
|
21501
21669
|
const top = precisionTo(startSelectionY + fromRowOffset, 1);
|
|
21502
|
-
const endSelectionCell = skeleton.getCellIndexAndOffsetByPosition(left + width, top + height
|
|
21670
|
+
const endSelectionCell = skeleton.getCellIndexAndOffsetByPosition(left + width, top + height, 1, 1, {
|
|
21671
|
+
x: 0,
|
|
21672
|
+
y: 0
|
|
21673
|
+
});
|
|
21503
21674
|
return {
|
|
21504
21675
|
unitId,
|
|
21505
21676
|
subUnitId,
|